blob: b6c491fee3524f15098a9bfa51cab2d0114b2e32 [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;
Nico Huberc5c66ec2019-09-28 23:59:45 +020018with HW.PCI;
Nico Huber83693c82016-10-08 22:17:55 +020019with HW.Port_IO;
Nico Hubercf88f3d2018-06-05 13:27:34 +020020with HW.GFX.Framebuffer_Filler;
Nico Huber83693c82016-10-08 22:17:55 +020021
22package HW.GFX.GMA
23with
24 Abstract_State =>
25 (State,
26 Init_State,
Nico Huber83693c82016-10-08 22:17:55 +020027 (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
Nico Hubere79babd2020-12-20 01:33:26 +010052 type PCH_Type is
53 (No_PCH,
54 Ibex_Peak,
55 Cougar_Point, -- Panther Point compatible
56 Lynx_Point, -- Wildcat Point compatible
57 Sunrise_Point); -- Union Point compatible
58
Nico Huber83693c82016-10-08 22:17:55 +020059 type Port_Type is
60 (Disabled,
Nico Huber8beafd72020-01-07 14:59:44 +010061 LVDS,
62 eDP,
Nico Huber83693c82016-10-08 22:17:55 +020063 DP1,
64 DP2,
65 DP3,
Nico Huber0d454cd2016-11-21 13:33:43 +010066 HDMI1, -- or DVI
67 HDMI2, -- or DVI
68 HDMI3, -- or DVI
Nico Huber83693c82016-10-08 22:17:55 +020069 Analog);
Nico Huber040d9b62019-02-18 00:52:00 +010070 subtype Active_Port_Type is Port_Type
71 range Port_Type'Succ (Disabled) .. Port_Type'Last;
Nico Huber8beafd72020-01-07 14:59:44 +010072 subtype Internal_Port_Type is Port_Type range LVDS .. eDP;
Nico Huber83693c82016-10-08 22:17:55 +020073
Nico Hubera02b2c62018-01-09 15:58:34 +010074 type Cursor_Mode is (No_Cursor, ARGB_Cursor);
75 type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
76 Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256);
77
78 subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2;
79
80 type Cursor_Type is record
81 Mode : Cursor_Mode;
82 Size : Cursor_Size;
83 Center_X : Cursor_Pos;
84 Center_Y : Cursor_Pos;
85 GTT_Offset : GTT_Range;
86 end record;
87 Default_Cursor : constant Cursor_Type :=
88 (Mode => No_Cursor,
89 Size => Cursor_Size'First,
90 Center_X => 0,
91 Center_Y => 0,
92 GTT_Offset => 0);
93
Nico Huber99f10f32016-11-20 00:34:05 +010094 type Pipe_Config is record
Nico Huber83693c82016-10-08 22:17:55 +020095 Port : Port_Type;
96 Framebuffer : Framebuffer_Type;
Nico Hubera02b2c62018-01-09 15:58:34 +010097 Cursor : Cursor_Type;
Nico Huber83693c82016-10-08 22:17:55 +020098 Mode : Mode_Type;
99 end record;
Nico Huber99f10f32016-11-20 00:34:05 +0100100 type Pipe_Index is (Primary, Secondary, Tertiary);
101 type Pipe_Configs is array (Pipe_Index) of Pipe_Config;
Nico Huber83693c82016-10-08 22:17:55 +0200102
Nico Huber3675db52016-11-04 16:27:29 +0100103 -- Special framebuffer offset to indicate legacy VGA plane.
104 -- Only valid on primary pipe.
105 VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#;
106
Nico Huberbebca132017-06-12 23:04:46 +0200107 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
108 Reason => "Write_Delay is used for debugging only");
Nico Huber83693c82016-10-08 22:17:55 +0200109 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +0200110 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +0100111 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +0200112 Success : out Boolean)
113 with
114 Global =>
Nico Huber27088aa2018-06-10 13:28:05 +0200115 (In_Out => (Device_State, Port_IO.State),
Nico Hubere317e9c2019-09-29 03:03:18 +0200116 Output => (State, Init_State),
Nico Huber83693c82016-10-08 22:17:55 +0200117 Input => (Time.State)),
118 Post => Success = Is_Initialized;
119 function Is_Initialized return Boolean
120 with
121 Global => (Input => Init_State);
Nico Huberbebca132017-06-12 23:04:46 +0200122 pragma Warnings (GNATprove, On, "unused variable ""Write_Delay""");
Nico Huber83693c82016-10-08 22:17:55 +0200123
Nico Huber42fb2d02017-09-01 17:01:51 +0200124 procedure Power_Up_VGA
125 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200126 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200127 (Input => (State, Time.State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200128 In_Out => (Device_State),
129 Proof_In => (Init_State)),
Nico Huber42fb2d02017-09-01 17:01:51 +0200130 Pre => Is_Initialized;
131
Nico Hubercf88f3d2018-06-05 13:27:34 +0200132 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200133
Nico Hubercf88f3d2018-06-05 13:27:34 +0200134 procedure Update_Outputs (Configs : Pipe_Configs)
135 with
136 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200137 (Input => (Time.State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200138 In_Out => (State, Device_State, Port_IO.State),
139 Proof_In => (Init_State)),
140 Pre => Is_Initialized;
141
142 procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type)
143 with
144 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200145 (In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200146 Proof_In => (Init_State)),
Nico Hubere317e9c2019-09-29 03:03:18 +0200147 Pre => Is_Initialized;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200148
Nico Huber15ffc4f2018-01-11 14:44:43 +0100149 procedure Place_Cursor
150 (Pipe : Pipe_Index;
151 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200152 Y : Cursor_Pos)
153 with
154 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200155 (In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200156 Proof_In => (Init_State)),
Nico Hubere317e9c2019-09-29 03:03:18 +0200157 Pre => Is_Initialized;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200158
Nico Huber15ffc4f2018-01-11 14:44:43 +0100159 procedure Move_Cursor
160 (Pipe : Pipe_Index;
161 X : Cursor_Pos;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200162 Y : Cursor_Pos)
163 with
164 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200165 (In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200166 Proof_In => (Init_State)),
Nico Hubere317e9c2019-09-29 03:03:18 +0200167 Pre => Is_Initialized;
Nico Huber15ffc4f2018-01-11 14:44:43 +0100168
Nico Hubercf88f3d2018-06-05 13:27:34 +0200169 ----------------------------------------------------------------------------
Nico Huber83693c82016-10-08 22:17:55 +0200170
Nico Huber83693c82016-10-08 22:17:55 +0200171 procedure Write_GTT
172 (GTT_Page : GTT_Range;
173 Device_Address : GTT_Address_Type;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200174 Valid : Boolean)
175 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200176 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200177 (Input => State,
Nico Huberadfe11f2018-06-10 14:59:04 +0200178 In_Out => Device_State, Proof_In => Init_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200179 Pre => Is_Initialized;
Nico Huber83693c82016-10-08 22:17:55 +0200180
Nico Huberceda17d2018-06-09 22:00:29 +0200181 procedure Read_GTT
182 (Device_Address : out GTT_Address_Type;
183 Valid : out Boolean;
184 GTT_Page : in GTT_Range)
185 with
Nico Huberadfe11f2018-06-10 14:59:04 +0200186 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200187 (Input => State,
Nico Huberadfe11f2018-06-10 14:59:04 +0200188 In_Out => Device_State, Proof_In => Init_State),
Nico Huberceda17d2018-06-09 22:00:29 +0200189 Pre => Is_Initialized;
190
Nico Huber5374c3a2017-07-15 21:48:06 +0200191 procedure Setup_Default_FB
192 (FB : in Framebuffer_Type;
193 Clear : in Boolean := True;
194 Success : out Boolean)
Nico Huber194e57e2017-07-15 21:15:46 +0200195 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200196 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200197 (In_Out =>
Nico Hubercf88f3d2018-06-05 13:27:34 +0200198 (State, Device_State,
199 Framebuffer_Filler.State, Framebuffer_Filler.Base_Address),
200 Proof_In => (Init_State)),
Nico Huber5374c3a2017-07-15 21:48:06 +0200201 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
Nico Huber83693c82016-10-08 22:17:55 +0200202
Nico Huberc3f66f62017-07-16 21:39:54 +0200203 procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type)
204 with
Nico Hubercf88f3d2018-06-05 13:27:34 +0200205 Global =>
Nico Hubere317e9c2019-09-29 03:03:18 +0200206 (In_Out => (State, Device_State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200207 Proof_In => (Init_State)),
Nico Hubere317e9c2019-09-29 03:03:18 +0200208 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
Nico Huberc3f66f62017-07-16 21:39:54 +0200209
Nico Hubercf88f3d2018-06-05 13:27:34 +0200210 ----------------------------------------------------------------------------
211
212 pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect",
213 Reason => "It's only used for debugging");
214 procedure Dump_Configs (Configs : Pipe_Configs);
215
Nico Huber83693c82016-10-08 22:17:55 +0200216private
217
Nico Huberc5c66ec2019-09-28 23:59:45 +0200218 PCI_Usable : Boolean with Part_Of => State;
219 use type HW.PCI.Index;
220 procedure PCI_Read16 (Value : out Word16; Offset : HW.PCI.Index)
221 with
222 Pre => PCI_Usable and Offset mod 2 = 0;
223
224 ----------------------------------------------------------------------------
225
Nico Huber3299ad52018-06-02 16:53:39 +0200226 -- For the default framebuffer setup (see below) with 90 degree rotations,
227 -- we expect the offset which is used for the final scanout to be above
228 -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for
229 -- the physical memory location and aperture mapping.
230 function Phys_Offset (FB : Framebuffer_Type) return Word32 is
231 (if Rotation_90 (FB)
232 then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size
233 else FB.Offset);
234
Nico Huber8c45bcf2016-11-20 17:30:57 +0100235 ----------------------------------------------------------------------------
236 -- State tracking for the currently configured pipes
237
238 Cur_Configs : Pipe_Configs with Part_Of => State;
239
Nico Huber3d06de82018-05-29 01:35:04 +0200240 function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is
241 (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
242
Nico Huberb217ece2018-06-02 16:56:35 +0200243 function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is
244 (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
245
Nico Huber8c45bcf2016-11-20 17:30:57 +0100246 ----------------------------------------------------------------------------
247 -- Internal representation of a single pipe's configuration
248
Arthur Heymans5d08a932018-03-28 17:00:18 +0200249 type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA);
Nico Huber83693c82016-10-08 22:17:55 +0200250
251 subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
Arthur Heymans5d08a932018-03-28 17:00:18 +0200252 subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D;
253 subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C;
Nico Huber83693c82016-10-08 22:17:55 +0200254
255 type PCH_Port is
256 (PCH_DAC, PCH_LVDS,
257 PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D,
258 PCH_DP_B, PCH_DP_C, PCH_DP_D);
259
260 subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D;
261 subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D;
262
Nico Huber5dbaf4b2020-01-08 17:24:58 +0100263 type Panel_Control is (No_Panel, Panel_1, Panel_2);
264 subtype Valid_Panels is Panel_Control range Panel_1 .. Panel_2;
Nico Huber2bbd6e72020-01-07 18:22:59 +0100265
Nico Huber83693c82016-10-08 22:17:55 +0200266 type Port_Config is
267 record
268 Port : GPU_Port;
269 PCH_Port : GMA.PCH_Port;
270 Display : Display_Type;
Nico Huber2bbd6e72020-01-07 18:22:59 +0100271 Panel : Panel_Control;
Nico Huber83693c82016-10-08 22:17:55 +0200272 Mode : Mode_Type;
273 Is_FDI : Boolean;
274 FDI : DP_Link;
275 DP : DP_Link;
276 end record;
277
278 type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training);
279
280 ----------------------------------------------------------------------------
281
282 type DP_Port is (DP_A, DP_B, DP_C, DP_D);
283
Nico Huber247adf32017-06-12 14:39:11 +0200284 ----------------------------------------------------------------------------
285
286 subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
287
Nico Huber0164b022017-08-24 15:12:51 +0200288 ----------------------------------------------------------------------------
289
Nico Huberc5c767a2018-06-03 01:09:04 +0200290 Tile_Width : constant array (Tiling_Type) of Width_Type :=
Nico Huber0164b022017-08-24 15:12:51 +0200291 (Linear => 16, X_Tiled => 128, Y_Tiled => 32);
Nico Huberc5c767a2018-06-03 01:09:04 +0200292 Tile_Rows : constant array (Tiling_Type) of Height_Type :=
Nico Huber9b479412017-08-27 11:55:56 +0200293 (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
Nico Huber0164b022017-08-24 15:12:51 +0200294
Nico Huber5ef4d602017-12-13 13:56:47 +0100295 function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural
296 is (Natural (Div_Round_Up
297 (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4)));
Nico Huber0164b022017-08-24 15:12:51 +0200298
299 function Valid_Stride (FB : Framebuffer_Type) return Boolean is
Nico Huber5ef4d602017-12-13 13:56:47 +0100300 (FB.Width + FB.Start_X <= FB.Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200301 Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and
Nico Huber5ef4d602017-12-13 13:56:47 +0100302 FB.Height + FB.Start_Y <= FB.V_Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200303 FB.V_Stride mod Tile_Rows (FB.Tiling) = 0);
Nico Huber0164b022017-08-24 15:12:51 +0200304
Nico Huber83693c82016-10-08 22:17:55 +0200305end HW.GFX.GMA;