blob: 3804cd4a0c09583d78677a8254a2670c84a0289a [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
Nico Huber3d06de82018-05-29 01:35:04 +02002-- Copyright (C) 2015-2018 secunet Security Networks AG
Nico Huber194e57e2017-07-15 21:15:46 +02003-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
Nico Huber83693c82016-10-08 22:17:55 +02004--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02007-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02009--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-- GNU General Public License for more details.
14--
15
Nico Huber194e57e2017-07-15 21:15:46 +020016with HW.Config;
Nico Huber83693c82016-10-08 22:17:55 +020017with HW.Time;
18with HW.Port_IO;
Nico Hubercf88f3d2018-06-05 13:27:34 +020019with HW.GFX.Framebuffer_Filler;
Nico Huber83693c82016-10-08 22:17:55 +020020
21package HW.GFX.GMA
22with
23 Abstract_State =>
24 (State,
25 Init_State,
26 Config_State,
27 (Device_State with External)),
Nico Huber27088aa2018-06-10 13:28:05 +020028 Initializes => Init_State
Nico Huber83693c82016-10-08 22:17:55 +020029is
30
Nico Hubera02b2c62018-01-09 15:58:34 +010031 GTT_Page_Size : constant := 4096;
32 type GTT_Address_Type is mod 2 ** 39;
33 subtype GTT_Range is Natural range 0 .. 16#8_0000# - 1;
34 GTT_Rotation_Offset : constant GTT_Range := GTT_Range'Last / 2 + 1;
35
Nico Huber6621a142018-06-07 23:56:54 +020036 type Generation is (G45, Ironlake, Haswell, Broxton, Skylake);
37
Nico Huber83693c82016-10-08 22:17:55 +020038 type CPU_Type is
Arthur Heymans73ea0322018-03-28 17:17:07 +020039 (G45,
40 Ironlake,
Nico Huber83693c82016-10-08 22:17:55 +020041 Sandybridge,
42 Ivybridge,
43 Haswell,
44 Broadwell,
Nico Huber21da5742017-01-20 14:00:53 +010045 Broxton,
Nico Huber83693c82016-10-08 22:17:55 +020046 Skylake);
47
48 type CPU_Variant is (Normal, ULT);
49
50 type Port_Type is
51 (Disabled,
52 Internal,
53 DP1,
54 DP2,
55 DP3,
Nico Huber0d454cd2016-11-21 13:33:43 +010056 HDMI1, -- or DVI
57 HDMI2, -- or DVI
58 HDMI3, -- or DVI
Nico Huber83693c82016-10-08 22:17:55 +020059 Analog);
Nico Huber83693c82016-10-08 22:17:55 +020060
Nico Hubera02b2c62018-01-09 15:58:34 +010061 type Cursor_Mode is (No_Cursor, ARGB_Cursor);
62 type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
63 Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256);
64
65 subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2;
66
67 type Cursor_Type is record
68 Mode : Cursor_Mode;
69 Size : Cursor_Size;
70 Center_X : Cursor_Pos;
71 Center_Y : Cursor_Pos;
72 GTT_Offset : GTT_Range;
73 end record;
74 Default_Cursor : constant Cursor_Type :=
75 (Mode => No_Cursor,
76 Size => Cursor_Size'First,
77 Center_X => 0,
78 Center_Y => 0,
79 GTT_Offset => 0);
80
Nico Huber99f10f32016-11-20 00:34:05 +010081 type Pipe_Config is record
Nico Huber83693c82016-10-08 22:17:55 +020082 Port : Port_Type;
83 Framebuffer : Framebuffer_Type;
Nico Hubera02b2c62018-01-09 15:58:34 +010084 Cursor : Cursor_Type;
Nico Huber83693c82016-10-08 22:17:55 +020085 Mode : Mode_Type;
86 end record;
Nico Huber99f10f32016-11-20 00:34:05 +010087 type Pipe_Index is (Primary, Secondary, Tertiary);
88 type Pipe_Configs is array (Pipe_Index) of Pipe_Config;
Nico Huber83693c82016-10-08 22:17:55 +020089
Nico Huber3675db52016-11-04 16:27:29 +010090 -- Special framebuffer offset to indicate legacy VGA plane.
91 -- Only valid on primary pipe.
92 VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#;
93
Nico Huberbebca132017-06-12 23:04:46 +020094 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
95 Reason => "Write_Delay is used for debugging only");
Nico Huber83693c82016-10-08 22:17:55 +020096 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +020097 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +010098 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +020099 Success : out Boolean)
100 with
101 Global =>
Nico Huber27088aa2018-06-10 13:28:05 +0200102 (In_Out => (Device_State, Port_IO.State),
103 Output => (State, Init_State, Config_State),
Nico Huber83693c82016-10-08 22:17:55 +0200104 Input => (Time.State)),
105 Post => Success = Is_Initialized;
106 function Is_Initialized return Boolean
107 with
108 Global => (Input => Init_State);
Nico Huberbebca132017-06-12 23:04:46 +0200109 pragma Warnings (GNATprove, On, "unused variable ""Write_Delay""");
Nico Huber83693c82016-10-08 22:17:55 +0200110
Nico Huber42fb2d02017-09-01 17:01:51 +0200111 procedure Power_Up_VGA
112 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200113 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200114 (Input => (State, Config_State, Time.State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200115 In_Out => (Device_State),
116 Proof_In => (Init_State)),
Nico Huber42fb2d02017-09-01 17:01:51 +0200117 Pre => Is_Initialized;
118
Nico Hubercf88f3d2018-06-05 13:27:34 +0200119 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200120
Nico Hubercf88f3d2018-06-05 13:27:34 +0200121 procedure Update_Outputs (Configs : Pipe_Configs)
122 with
123 Global =>
124 (Input => (Config_State, Time.State),
125 In_Out => (State, Device_State, Port_IO.State),
126 Proof_In => (Init_State)),
127 Pre => Is_Initialized;
128
129 procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type)
130 with
131 Global =>
132 (In_Out => (State, Device_State),
133 Proof_In => (Init_State)),
134 Pre => Is_Initialized;
135
Nico Huber15ffc4f2018-01-11 14:44:43 +0100136 procedure Place_Cursor
137 (Pipe : Pipe_Index;
138 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200139 Y : Cursor_Pos)
140 with
141 Global =>
142 (In_Out => (State, Device_State),
143 Proof_In => (Init_State)),
144 Pre => Is_Initialized;
145
Nico Huber15ffc4f2018-01-11 14:44:43 +0100146 procedure Move_Cursor
147 (Pipe : Pipe_Index;
148 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200149 Y : Cursor_Pos)
150 with
151 Global =>
152 (In_Out => (State, Device_State),
153 Proof_In => (Init_State)),
154 Pre => Is_Initialized;
Nico Huber15ffc4f2018-01-11 14:44:43 +0100155
Nico Hubercf88f3d2018-06-05 13:27:34 +0200156 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200157
Nico Huber83693c82016-10-08 22:17:55 +0200158 procedure Write_GTT
159 (GTT_Page : GTT_Range;
160 Device_Address : GTT_Address_Type;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200161 Valid : Boolean)
162 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200163 Global =>
164 (Input => Config_State,
165 In_Out => Device_State, Proof_In => Init_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200166 Pre => Is_Initialized;
Nico Huber83693c82016-10-08 22:17:55 +0200167
Nico Huberceda17d2018-06-09 22:00:29 +0200168 procedure Read_GTT
169 (Device_Address : out GTT_Address_Type;
170 Valid : out Boolean;
171 GTT_Page : in GTT_Range)
172 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200173 Global =>
174 (Input => Config_State,
175 In_Out => Device_State, Proof_In => Init_State),
Nico Huberceda17d2018-06-09 22:00:29 +0200176 Pre => Is_Initialized;
177
Nico Huber5374c3a2017-07-15 21:48:06 +0200178 procedure Setup_Default_FB
179 (FB : in Framebuffer_Type;
180 Clear : in Boolean := True;
181 Success : out Boolean)
Nico Huber194e57e2017-07-15 21:15:46 +0200182 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200183 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200184 (Input => Config_State,
185 In_Out =>
Nico Hubercf88f3d2018-06-05 13:27:34 +0200186 (State, Device_State,
187 Framebuffer_Filler.State, Framebuffer_Filler.Base_Address),
188 Proof_In => (Init_State)),
Nico Huber5374c3a2017-07-15 21:48:06 +0200189 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
Nico Huber83693c82016-10-08 22:17:55 +0200190
Nico Huberadfe11f2018-06-10 14:59:04 +0200191 pragma Warnings (GNATprove, Off, "no check message justified by this",
192 Reason => "see Annotate aspects.");
Nico Huberc3f66f62017-07-16 21:39:54 +0200193 procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type)
194 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200195 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200196 (Input => Config_State,
197 In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200198 Proof_In => (Init_State)),
Nico Huberadfe11f2018-06-10 14:59:04 +0200199 Pre => Is_Initialized and HW.Config.Dynamic_MMIO,
200 Annotate =>
201 (GNATprove, Intentional,
202 "global input ""GMA.Config_State"" of ""Map_Linear_FB"" not read",
203 "Reading of Config_State depends on the platform configuration.");
204 pragma Warnings (GNATprove, On, "no check message justified by this");
Nico Huberc3f66f62017-07-16 21:39:54 +0200205
Nico Hubercf88f3d2018-06-05 13:27:34 +0200206 ----------------------------------------------------------------------------
207
208 pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect",
209 Reason => "It's only used for debugging");
210 procedure Dump_Configs (Configs : Pipe_Configs);
211
Nico Huber83693c82016-10-08 22:17:55 +0200212private
213
Nico Huber3299ad52018-06-02 16:53:39 +0200214 -- For the default framebuffer setup (see below) with 90 degree rotations,
215 -- we expect the offset which is used for the final scanout to be above
216 -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for
217 -- the physical memory location and aperture mapping.
218 function Phys_Offset (FB : Framebuffer_Type) return Word32 is
219 (if Rotation_90 (FB)
220 then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size
221 else FB.Offset);
222
Nico Huber8c45bcf2016-11-20 17:30:57 +0100223 ----------------------------------------------------------------------------
224 -- State tracking for the currently configured pipes
225
226 Cur_Configs : Pipe_Configs with Part_Of => State;
227
Nico Huber3d06de82018-05-29 01:35:04 +0200228 function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is
229 (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
230
Nico Huberb217ece2018-06-02 16:56:35 +0200231 function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is
232 (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
233
Nico Huber8c45bcf2016-11-20 17:30:57 +0100234 ----------------------------------------------------------------------------
235 -- Internal representation of a single pipe's configuration
236
237 subtype Active_Port_Type is Port_Type
238 range Port_Type'Succ (Disabled) .. Port_Type'Last;
239
Arthur Heymans5d08a932018-03-28 17:00:18 +0200240 type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA);
Nico Huber83693c82016-10-08 22:17:55 +0200241
242 subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
Arthur Heymans5d08a932018-03-28 17:00:18 +0200243 subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D;
244 subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C;
Nico Huber83693c82016-10-08 22:17:55 +0200245
246 type PCH_Port is
247 (PCH_DAC, PCH_LVDS,
248 PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D,
249 PCH_DP_B, PCH_DP_C, PCH_DP_D);
250
251 subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D;
252 subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D;
253
Nico Huber83693c82016-10-08 22:17:55 +0200254 type Port_Config is
255 record
256 Port : GPU_Port;
257 PCH_Port : GMA.PCH_Port;
258 Display : Display_Type;
259 Mode : Mode_Type;
260 Is_FDI : Boolean;
261 FDI : DP_Link;
262 DP : DP_Link;
263 end record;
264
265 type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training);
266
267 ----------------------------------------------------------------------------
268
269 type DP_Port is (DP_A, DP_B, DP_C, DP_D);
270
Nico Huber247adf32017-06-12 14:39:11 +0200271 ----------------------------------------------------------------------------
272
273 subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
274
Nico Huber0164b022017-08-24 15:12:51 +0200275 ----------------------------------------------------------------------------
276
Nico Huberc5c767a2018-06-03 01:09:04 +0200277 Tile_Width : constant array (Tiling_Type) of Width_Type :=
Nico Huber0164b022017-08-24 15:12:51 +0200278 (Linear => 16, X_Tiled => 128, Y_Tiled => 32);
Nico Huberc5c767a2018-06-03 01:09:04 +0200279 Tile_Rows : constant array (Tiling_Type) of Height_Type :=
Nico Huber9b479412017-08-27 11:55:56 +0200280 (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
Nico Huber0164b022017-08-24 15:12:51 +0200281
Nico Huber5ef4d602017-12-13 13:56:47 +0100282 function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural
283 is (Natural (Div_Round_Up
284 (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4)));
Nico Huber0164b022017-08-24 15:12:51 +0200285
286 function Valid_Stride (FB : Framebuffer_Type) return Boolean is
Nico Huber5ef4d602017-12-13 13:56:47 +0100287 (FB.Width + FB.Start_X <= FB.Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200288 Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and
Nico Huber5ef4d602017-12-13 13:56:47 +0100289 FB.Height + FB.Start_Y <= FB.V_Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200290 FB.V_Stride mod Tile_Rows (FB.Tiling) = 0);
Nico Huber0164b022017-08-24 15:12:51 +0200291
Nico Huber83693c82016-10-08 22:17:55 +0200292end HW.GFX.GMA;