blob: 353ec4bc617ad707e0728e6dc70519c82b6aa713 [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,
Nico Huber7f3e2802019-09-28 20:40:55 +020040 GM45,
Arthur Heymans73ea0322018-03-28 17:17:07 +020041 Ironlake,
Nico Huber83693c82016-10-08 22:17:55 +020042 Sandybridge,
43 Ivybridge,
44 Haswell,
45 Broadwell,
Nico Huber21da5742017-01-20 14:00:53 +010046 Broxton,
Nico Huber88badbe2018-09-27 16:36:47 +020047 Skylake,
48 Kabylake);
Nico Huber83693c82016-10-08 22:17:55 +020049
Nico Huber25fdb152019-02-17 15:54:39 +010050 type CPU_Variant is (Normal, ULT, ULX);
Nico Huber83693c82016-10-08 22:17:55 +020051
52 type Port_Type is
53 (Disabled,
54 Internal,
55 DP1,
56 DP2,
57 DP3,
Nico Huber0d454cd2016-11-21 13:33:43 +010058 HDMI1, -- or DVI
59 HDMI2, -- or DVI
60 HDMI3, -- or DVI
Nico Huber83693c82016-10-08 22:17:55 +020061 Analog);
Nico Huber040d9b62019-02-18 00:52:00 +010062 subtype Active_Port_Type is Port_Type
63 range Port_Type'Succ (Disabled) .. Port_Type'Last;
Nico Huber83693c82016-10-08 22:17:55 +020064
Nico Hubera02b2c62018-01-09 15:58:34 +010065 type Cursor_Mode is (No_Cursor, ARGB_Cursor);
66 type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
67 Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256);
68
69 subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2;
70
71 type Cursor_Type is record
72 Mode : Cursor_Mode;
73 Size : Cursor_Size;
74 Center_X : Cursor_Pos;
75 Center_Y : Cursor_Pos;
76 GTT_Offset : GTT_Range;
77 end record;
78 Default_Cursor : constant Cursor_Type :=
79 (Mode => No_Cursor,
80 Size => Cursor_Size'First,
81 Center_X => 0,
82 Center_Y => 0,
83 GTT_Offset => 0);
84
Nico Huber99f10f32016-11-20 00:34:05 +010085 type Pipe_Config is record
Nico Huber83693c82016-10-08 22:17:55 +020086 Port : Port_Type;
87 Framebuffer : Framebuffer_Type;
Nico Hubera02b2c62018-01-09 15:58:34 +010088 Cursor : Cursor_Type;
Nico Huber83693c82016-10-08 22:17:55 +020089 Mode : Mode_Type;
90 end record;
Nico Huber99f10f32016-11-20 00:34:05 +010091 type Pipe_Index is (Primary, Secondary, Tertiary);
92 type Pipe_Configs is array (Pipe_Index) of Pipe_Config;
Nico Huber83693c82016-10-08 22:17:55 +020093
Nico Huber3675db52016-11-04 16:27:29 +010094 -- Special framebuffer offset to indicate legacy VGA plane.
95 -- Only valid on primary pipe.
96 VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#;
97
Nico Huberbebca132017-06-12 23:04:46 +020098 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
99 Reason => "Write_Delay is used for debugging only");
Nico Huber83693c82016-10-08 22:17:55 +0200100 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +0200101 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +0100102 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +0200103 Success : out Boolean)
104 with
105 Global =>
Nico Huber27088aa2018-06-10 13:28:05 +0200106 (In_Out => (Device_State, Port_IO.State),
107 Output => (State, Init_State, Config_State),
Nico Huber83693c82016-10-08 22:17:55 +0200108 Input => (Time.State)),
109 Post => Success = Is_Initialized;
110 function Is_Initialized return Boolean
111 with
112 Global => (Input => Init_State);
Nico Huberbebca132017-06-12 23:04:46 +0200113 pragma Warnings (GNATprove, On, "unused variable ""Write_Delay""");
Nico Huber83693c82016-10-08 22:17:55 +0200114
Nico Huber42fb2d02017-09-01 17:01:51 +0200115 procedure Power_Up_VGA
116 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200117 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200118 (Input => (State, Config_State, Time.State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200119 In_Out => (Device_State),
120 Proof_In => (Init_State)),
Nico Huber42fb2d02017-09-01 17:01:51 +0200121 Pre => Is_Initialized;
122
Nico Hubercf88f3d2018-06-05 13:27:34 +0200123 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200124
Nico Hubercf88f3d2018-06-05 13:27:34 +0200125 procedure Update_Outputs (Configs : Pipe_Configs)
126 with
127 Global =>
128 (Input => (Config_State, Time.State),
129 In_Out => (State, Device_State, Port_IO.State),
130 Proof_In => (Init_State)),
131 Pre => Is_Initialized;
132
Nico Huber75a707f2018-06-18 16:28:33 +0200133 pragma Warnings (GNATprove, Off, "no check message justified by this",
134 Reason => "see Annotate aspects.");
Nico Hubercf88f3d2018-06-05 13:27:34 +0200135 procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type)
136 with
137 Global =>
Nico Huber75a707f2018-06-18 16:28:33 +0200138 (Input => (Config_State),
139 In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200140 Proof_In => (Init_State)),
Nico Huber75a707f2018-06-18 16:28:33 +0200141 Pre => Is_Initialized,
142 Annotate =>
143 (GNATprove, Intentional,
144 "global input ""GMA.Config_State"" of ""Update_Cursor"" not read",
145 "Reading of Config_State depends on the platform configuration.");
Nico Hubercf88f3d2018-06-05 13:27:34 +0200146
Nico Huber15ffc4f2018-01-11 14:44:43 +0100147 procedure Place_Cursor
148 (Pipe : Pipe_Index;
149 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200150 Y : Cursor_Pos)
151 with
152 Global =>
Nico Huber75a707f2018-06-18 16:28:33 +0200153 (Input => (Config_State),
154 In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200155 Proof_In => (Init_State)),
Nico Huber75a707f2018-06-18 16:28:33 +0200156 Pre => Is_Initialized,
157 Annotate =>
158 (GNATprove, Intentional,
159 "global input ""GMA.Config_State"" of ""Place_Cursor"" not read",
160 "Reading of Config_State depends on the platform configuration.");
Nico Hubercf88f3d2018-06-05 13:27:34 +0200161
Nico Huber15ffc4f2018-01-11 14:44:43 +0100162 procedure Move_Cursor
163 (Pipe : Pipe_Index;
164 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200165 Y : Cursor_Pos)
166 with
167 Global =>
Nico Huber75a707f2018-06-18 16:28:33 +0200168 (Input => (Config_State),
169 In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200170 Proof_In => (Init_State)),
Nico Huber75a707f2018-06-18 16:28:33 +0200171 Pre => Is_Initialized,
172 Annotate =>
173 (GNATprove, Intentional,
174 "global input ""GMA.Config_State"" of ""Move_Cursor"" not read",
175 "Reading of Config_State depends on the platform configuration.");
Nico Huber15ffc4f2018-01-11 14:44:43 +0100176
Nico Hubercf88f3d2018-06-05 13:27:34 +0200177 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200178
Nico Huber83693c82016-10-08 22:17:55 +0200179 procedure Write_GTT
180 (GTT_Page : GTT_Range;
181 Device_Address : GTT_Address_Type;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200182 Valid : Boolean)
183 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200184 Global =>
185 (Input => Config_State,
186 In_Out => Device_State, Proof_In => Init_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200187 Pre => Is_Initialized;
Nico Huber83693c82016-10-08 22:17:55 +0200188
Nico Huberceda17d2018-06-09 22:00:29 +0200189 procedure Read_GTT
190 (Device_Address : out GTT_Address_Type;
191 Valid : out Boolean;
192 GTT_Page : in GTT_Range)
193 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200194 Global =>
195 (Input => Config_State,
196 In_Out => Device_State, Proof_In => Init_State),
Nico Huberceda17d2018-06-09 22:00:29 +0200197 Pre => Is_Initialized;
198
Nico Huber5374c3a2017-07-15 21:48:06 +0200199 procedure Setup_Default_FB
200 (FB : in Framebuffer_Type;
201 Clear : in Boolean := True;
202 Success : out Boolean)
Nico Huber194e57e2017-07-15 21:15:46 +0200203 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200204 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200205 (Input => Config_State,
206 In_Out =>
Nico Hubercf88f3d2018-06-05 13:27:34 +0200207 (State, Device_State,
208 Framebuffer_Filler.State, Framebuffer_Filler.Base_Address),
209 Proof_In => (Init_State)),
Nico Huber5374c3a2017-07-15 21:48:06 +0200210 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
Nico Huber83693c82016-10-08 22:17:55 +0200211
Nico Huberc3f66f62017-07-16 21:39:54 +0200212 procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type)
213 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200214 Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200215 (Input => Config_State,
216 In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200217 Proof_In => (Init_State)),
Nico Huberadfe11f2018-06-10 14:59:04 +0200218 Pre => Is_Initialized and HW.Config.Dynamic_MMIO,
219 Annotate =>
220 (GNATprove, Intentional,
221 "global input ""GMA.Config_State"" of ""Map_Linear_FB"" not read",
222 "Reading of Config_State depends on the platform configuration.");
223 pragma Warnings (GNATprove, On, "no check message justified by this");
Nico Huberc3f66f62017-07-16 21:39:54 +0200224
Nico Hubercf88f3d2018-06-05 13:27:34 +0200225 ----------------------------------------------------------------------------
226
227 pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect",
228 Reason => "It's only used for debugging");
229 procedure Dump_Configs (Configs : Pipe_Configs);
230
Nico Huber83693c82016-10-08 22:17:55 +0200231private
232
Nico Huber3299ad52018-06-02 16:53:39 +0200233 -- For the default framebuffer setup (see below) with 90 degree rotations,
234 -- we expect the offset which is used for the final scanout to be above
235 -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for
236 -- the physical memory location and aperture mapping.
237 function Phys_Offset (FB : Framebuffer_Type) return Word32 is
238 (if Rotation_90 (FB)
239 then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size
240 else FB.Offset);
241
Nico Huber8c45bcf2016-11-20 17:30:57 +0100242 ----------------------------------------------------------------------------
243 -- State tracking for the currently configured pipes
244
245 Cur_Configs : Pipe_Configs with Part_Of => State;
246
Nico Huber3d06de82018-05-29 01:35:04 +0200247 function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is
248 (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
249
Nico Huberb217ece2018-06-02 16:56:35 +0200250 function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is
251 (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
252
Nico Huber8c45bcf2016-11-20 17:30:57 +0100253 ----------------------------------------------------------------------------
254 -- Internal representation of a single pipe's configuration
255
Arthur Heymans5d08a932018-03-28 17:00:18 +0200256 type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA);
Nico Huber83693c82016-10-08 22:17:55 +0200257
258 subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
Arthur Heymans5d08a932018-03-28 17:00:18 +0200259 subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D;
260 subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C;
Nico Huber83693c82016-10-08 22:17:55 +0200261
262 type PCH_Port is
263 (PCH_DAC, PCH_LVDS,
264 PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D,
265 PCH_DP_B, PCH_DP_C, PCH_DP_D);
266
267 subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D;
268 subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D;
269
Nico Huber83693c82016-10-08 22:17:55 +0200270 type Port_Config is
271 record
272 Port : GPU_Port;
273 PCH_Port : GMA.PCH_Port;
274 Display : Display_Type;
275 Mode : Mode_Type;
276 Is_FDI : Boolean;
277 FDI : DP_Link;
278 DP : DP_Link;
279 end record;
280
281 type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training);
282
283 ----------------------------------------------------------------------------
284
285 type DP_Port is (DP_A, DP_B, DP_C, DP_D);
286
Nico Huber247adf32017-06-12 14:39:11 +0200287 ----------------------------------------------------------------------------
288
289 subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
290
Nico Huber0164b022017-08-24 15:12:51 +0200291 ----------------------------------------------------------------------------
292
Nico Huberc5c767a2018-06-03 01:09:04 +0200293 Tile_Width : constant array (Tiling_Type) of Width_Type :=
Nico Huber0164b022017-08-24 15:12:51 +0200294 (Linear => 16, X_Tiled => 128, Y_Tiled => 32);
Nico Huberc5c767a2018-06-03 01:09:04 +0200295 Tile_Rows : constant array (Tiling_Type) of Height_Type :=
Nico Huber9b479412017-08-27 11:55:56 +0200296 (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
Nico Huber0164b022017-08-24 15:12:51 +0200297
Nico Huber5ef4d602017-12-13 13:56:47 +0100298 function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural
299 is (Natural (Div_Round_Up
300 (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4)));
Nico Huber0164b022017-08-24 15:12:51 +0200301
302 function Valid_Stride (FB : Framebuffer_Type) return Boolean is
Nico Huber5ef4d602017-12-13 13:56:47 +0100303 (FB.Width + FB.Start_X <= FB.Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200304 Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and
Nico Huber5ef4d602017-12-13 13:56:47 +0100305 FB.Height + FB.Start_Y <= FB.V_Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200306 FB.V_Stride mod Tile_Rows (FB.Tiling) = 0);
Nico Huber0164b022017-08-24 15:12:51 +0200307
Nico Huber83693c82016-10-08 22:17:55 +0200308end HW.GFX.GMA;