blob: 8352e1c45fc4f35a8cf2c18d70283d6ce31adc1e [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
Nico Huber9a4c4c32019-09-16 22:05:11 +02002-- Copyright (C) 2014-2019 secunet Security Networks AG
Nico Huber2b6f6992017-07-09 18:11:34 +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 Huber2b6f6992017-07-09 18:11:34 +020016with HW.MMIO_Range;
17pragma Elaborate_All (HW.MMIO_Range);
18with HW.PCI.Dev;
19pragma Elaborate_All (HW.PCI.Dev);
20
Nico Huber83693c82016-10-08 22:17:55 +020021with HW.GFX.GMA.Config;
Nico Huber8c45bcf2016-11-20 17:30:57 +010022with HW.GFX.GMA.Config_Helpers;
Nico Huber83693c82016-10-08 22:17:55 +020023with HW.GFX.GMA.Registers;
Nico Huber312433c2019-09-28 03:15:48 +020024with HW.GFX.GMA.PCode;
Nico Huber83693c82016-10-08 22:17:55 +020025with HW.GFX.GMA.Power_And_Clocks;
26with HW.GFX.GMA.Panel;
27with HW.GFX.GMA.PLLs;
28with HW.GFX.GMA.Port_Detect;
29with HW.GFX.GMA.Connectors;
30with HW.GFX.GMA.Connector_Info;
31with HW.GFX.GMA.Pipe_Setup;
32
Nico Huber83693c82016-10-08 22:17:55 +020033with HW.Debug;
34with GNAT.Source_Info;
35
Nico Huber83693c82016-10-08 22:17:55 +020036use type HW.Int32;
37
38package body HW.GFX.GMA
39 with Refined_State =>
40 (State =>
Nico Huberc5c66ec2019-09-28 23:59:45 +020041 (PCI_Usable,
42 Dev.Address_State,
Nico Huber2b6f6992017-07-09 18:11:34 +020043 Registers.Address_State,
Nico Huber312433c2019-09-28 03:15:48 +020044 PCode.Mailbox_Ready,
Nico Huber83693c82016-10-08 22:17:55 +020045 PLLs.State, Panel.Panel_State,
Nico Huber1a712d32017-01-09 15:11:04 +010046 Cur_Configs, Allocated_PLLs,
Nico Huberc3f66f62017-07-16 21:39:54 +020047 HPD_Delay, Wait_For_HPD,
48 Linear_FB_Base),
Nico Huber83693c82016-10-08 22:17:55 +020049 Init_State => Initialized,
Nico Huber30e84082018-06-10 13:28:05 +020050 Config_State => (Config.Variable),
Nico Huber83693c82016-10-08 22:17:55 +020051 Device_State =>
Nico Huber2b6f6992017-07-09 18:11:34 +020052 (Dev.PCI_State, Registers.Register_State, Registers.GTT_State))
Nico Huber83693c82016-10-08 22:17:55 +020053is
Nico Huber2b6f6992017-07-09 18:11:34 +020054 pragma Disable_Atomic_Synchronization;
Nico Huber83693c82016-10-08 22:17:55 +020055
56 subtype Port_Name is String (1 .. 8);
57 type Port_Name_Array is array (Port_Type) of Port_Name;
58 Port_Names : constant Port_Name_Array :=
59 (Disabled => "Disabled",
60 Internal => "Internal",
61 DP1 => "DP1 ",
62 DP2 => "DP2 ",
63 DP3 => "DP3 ",
Nico Huber0d454cd2016-11-21 13:33:43 +010064 HDMI1 => "HDMI1 ",
65 HDMI2 => "HDMI2 ",
66 HDMI3 => "HDMI3 ",
Nico Huber83693c82016-10-08 22:17:55 +020067 Analog => "Analog ");
68
Nico Huber2b6f6992017-07-09 18:11:34 +020069 package Dev is new HW.PCI.Dev (PCI.Address'(0, 2, 0));
70
Nico Huber83693c82016-10-08 22:17:55 +020071 package Display_Controller renames Pipe_Setup;
72
Nico Huber99f10f32016-11-20 00:34:05 +010073 type PLLs_Type is array (Pipe_Index) of PLLs.T;
Nico Huber83693c82016-10-08 22:17:55 +020074
Nico Huber83693c82016-10-08 22:17:55 +020075 type HPD_Type is array (Port_Type) of Boolean;
Nico Huber3be61d42017-01-09 13:58:18 +010076 type HPD_Delay_Type is array (Active_Port_Type) of Time.T;
Nico Huber83693c82016-10-08 22:17:55 +020077
Nico Huber83693c82016-10-08 22:17:55 +020078 Allocated_PLLs : PLLs_Type;
Nico Huber83693c82016-10-08 22:17:55 +020079 HPD_Delay : HPD_Delay_Type;
80 Wait_For_HPD : HPD_Type;
81 Initialized : Boolean := False;
82
Nico Huberc3f66f62017-07-16 21:39:54 +020083 Linear_FB_Base : Word64;
84
Nico Huber83693c82016-10-08 22:17:55 +020085 ----------------------------------------------------------------------------
86
Nico Huberf54d0962016-10-20 14:17:18 +020087 PCH_RAWCLK_FREQ_MASK : constant := 16#3ff# * 2 ** 0;
88
89 function PCH_RAWCLK_FREQ (Freq : Frequency_Type) return Word32
90 is
91 begin
92 return Word32 (Freq / 1_000_000);
93 end PCH_RAWCLK_FREQ;
94
95 ----------------------------------------------------------------------------
96
Nico Huber43370ba2017-01-09 15:26:19 +010097 procedure Enable_Output
98 (Pipe : in Pipe_Index;
99 Pipe_Cfg : in Pipe_Config;
100 Success : out Boolean)
Nico Huber8a5a3b52018-06-04 14:42:13 +0200101 with
Nico Huber9a4c4c32019-09-16 22:05:11 +0200102 Pre =>
103 Pipe_Cfg.Port in Active_Port_Type and
104 Config_Helpers.Valid_FB (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode)
Nico Huber43370ba2017-01-09 15:26:19 +0100105 is
106 Port_Cfg : Port_Config;
107 begin
Nico Huber3be61d42017-01-09 13:58:18 +0100108 pragma Debug (Debug.New_Line);
109 pragma Debug (Debug.Put_Line
110 ("Trying to enable port " & Port_Names (Pipe_Cfg.Port)));
111
Nico Huber43370ba2017-01-09 15:26:19 +0100112 Config_Helpers.Fill_Port_Config
113 (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success);
114
115 if Success then
Nico Huber43370ba2017-01-09 15:26:19 +0100116 Connector_Info.Preferred_Link_Setting (Port_Cfg, Success);
117 end if;
118
119 -- loop over all possible DP-lane configurations
120 -- (non-DP ports use a single fake configuration)
121 while Success loop
122 pragma Loop_Invariant
123 (Pipe_Cfg.Port in Active_Port_Type and
124 Port_Cfg.Mode = Port_Cfg.Mode'Loop_Entry);
125
126 PLLs.Alloc
127 (Port_Cfg => Port_Cfg,
128 PLL => Allocated_PLLs (Pipe),
129 Success => Success);
130
131 if Success then
132 -- try each DP-lane configuration twice
133 for Try in 1 .. 2 loop
134 pragma Loop_Invariant
135 (Pipe_Cfg.Port in Active_Port_Type);
136
Nico Huber4798c662017-01-11 12:44:48 +0100137 -- Clear pending hot-plug events before every try
138 Port_Detect.Clear_Hotplug_Detect (Pipe_Cfg.Port);
139
Nico Huber43370ba2017-01-09 15:26:19 +0100140 Connectors.Pre_On
141 (Pipe => Pipe,
142 Port_Cfg => Port_Cfg,
143 PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)),
144 Success => Success);
145
146 if Success then
147 Display_Controller.On
148 (Pipe => Pipe,
149 Port_Cfg => Port_Cfg,
Nico Huber4dc4c612018-01-10 15:55:09 +0100150 Framebuffer => Pipe_Cfg.Framebuffer,
151 Cursor => Pipe_Cfg.Cursor);
Nico Huber43370ba2017-01-09 15:26:19 +0100152
153 Connectors.Post_On
Arthur Heymans60d0e5f2018-03-28 17:08:27 +0200154 (Pipe => Pipe,
155 Port_Cfg => Port_Cfg,
Nico Huber43370ba2017-01-09 15:26:19 +0100156 PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)),
157 Success => Success);
158
159 if not Success then
160 Display_Controller.Off (Pipe);
161 Connectors.Post_Off (Port_Cfg);
162 end if;
163 end if;
164
165 exit when Success;
166 end loop;
167 exit when Success; -- connection established => stop loop
168
169 -- connection failed
170 PLLs.Free (Allocated_PLLs (Pipe));
171 end if;
172
173 Connector_Info.Next_Link_Setting (Port_Cfg, Success);
174 end loop;
175
176 if Success then
177 pragma Debug (Debug.Put_Line
178 ("Enabled port " & Port_Names (Pipe_Cfg.Port)));
179 else
180 Wait_For_HPD (Pipe_Cfg.Port) := True;
181 if Pipe_Cfg.Port = Internal then
182 Panel.Off;
183 end if;
184 end if;
185 end Enable_Output;
186
Nico Huber3be61d42017-01-09 13:58:18 +0100187 procedure Disable_Output (Pipe : Pipe_Index; Pipe_Cfg : Pipe_Config)
188 is
189 Port_Cfg : Port_Config;
190 Success : Boolean;
191 begin
192 Config_Helpers.Fill_Port_Config
193 (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success);
194 if Success then
195 pragma Debug (Debug.New_Line);
196 pragma Debug (Debug.Put_Line
197 ("Disabling port " & Port_Names (Pipe_Cfg.Port)));
198 pragma Debug (Debug.New_Line);
199
200 Connectors.Pre_Off (Port_Cfg);
201 Display_Controller.Off (Pipe);
202 Connectors.Post_Off (Port_Cfg);
203
204 PLLs.Free (Allocated_PLLs (Pipe));
205 end if;
206 end Disable_Output;
207
Nico Huber99f10f32016-11-20 00:34:05 +0100208 procedure Update_Outputs (Configs : Pipe_Configs)
Nico Huber83693c82016-10-08 22:17:55 +0200209 is
Nico Huber3be61d42017-01-09 13:58:18 +0100210 procedure Check_HPD (Port : in Active_Port_Type; Detected : out Boolean)
211 is
212 HPD_Delay_Over : constant Boolean := Time.Timed_Out (HPD_Delay (Port));
213 begin
214 if HPD_Delay_Over then
215 Port_Detect.Hotplug_Detect (Port, Detected);
216 HPD_Delay (Port) := Time.MS_From_Now (333);
217 else
218 Detected := False;
219 end if;
220 end Check_HPD;
Nico Huberb56b9c52017-01-11 15:12:23 +0100221
Nico Huber9a4c4c32019-09-16 22:05:11 +0200222 Scaler_Reservation : Display_Controller.Scaler_Reservation :=
223 Display_Controller.Null_Scaler_Reservation;
Nico Huber564103f2017-01-11 15:33:07 +0100224
Nico Huber9a4c4c32019-09-16 22:05:11 +0200225 Update_Power : Boolean := False;
226 Old_Configs,
227 New_Configs : Pipe_Configs;
Nico Huber3d06de82018-05-29 01:35:04 +0200228
229 function Full_Update (Cur_Config, New_Config : Pipe_Config) return Boolean
230 is
231 begin
232 return
Nico Huber958c5642018-06-02 16:59:31 +0200233 Cur_Config.Port /= New_Config.Port
234 or else
235 Cur_Config.Mode /= New_Config.Mode
236 or else
Nico Huber3d06de82018-05-29 01:35:04 +0200237 (Config.Use_PDW_For_EDP_Scaling and then
238 (Cur_Config.Port = Internal and
Nico Huber958c5642018-06-02 16:59:31 +0200239 Requires_Scaling (Cur_Config) /= Requires_Scaling (New_Config)))
240 or else
241 (Config.Has_GMCH_PFIT_CONTROL and then
242 (Requires_Scaling (Cur_Config) /= Requires_Scaling (New_Config) or
243 Scaling_Type (Cur_Config) /= Scaling_Type (New_Config)));
Nico Huber3d06de82018-05-29 01:35:04 +0200244 end Full_Update;
Nico Huber83693c82016-10-08 22:17:55 +0200245 begin
246 Old_Configs := Cur_Configs;
Nico Huber9a4c4c32019-09-16 22:05:11 +0200247 New_Configs := Configs;
248
249 -- validate new configs, filter invalid configs and those waiting for HPD
250 for Pipe in Pipe_Index loop
251 declare
252 Success : Boolean := True;
253 Cur_Config : Pipe_Config renames Cur_Configs (Pipe);
254 New_Config : Pipe_Config renames New_Configs (Pipe);
255 begin
256 if New_Config.Port /= Disabled then
257 if Wait_For_HPD (New_Config.Port) then
258 Check_HPD (New_Config.Port, Success);
259 Wait_For_HPD (New_Config.Port) := not Success;
260 end if;
261
262 Success := Success and then
263 Config_Helpers.Validate_Config
264 (New_Config.Framebuffer, New_Config.Mode, Pipe);
265
266 if Success and then Requires_Scaling (New_Config) then
267 Display_Controller.Reserve_Scaler
268 (Success, Scaler_Reservation, Pipe);
269 end if;
270
271 if not Success then
272 New_Config.Port := Disabled;
273 end if;
274 end if;
275 end;
276 pragma Loop_Invariant
277 (for all P in Pipe_Index'First .. Pipe =>
278 New_Configs (P).Port = Disabled or
279 Config_Helpers.Valid_FB
280 (New_Configs (P).Framebuffer, New_Configs (P).Mode));
281 end loop;
Nico Huber83693c82016-10-08 22:17:55 +0200282
Nico Huberb56b9c52017-01-11 15:12:23 +0100283 -- disable all pipes that changed or had a hot-plug event
284 for Pipe in Pipe_Index loop
285 declare
286 Unplug_Detected : Boolean;
287 Cur_Config : Pipe_Config renames Cur_Configs (Pipe);
Nico Huber9a4c4c32019-09-16 22:05:11 +0200288 New_Config : Pipe_Config renames New_Configs (Pipe);
Nico Huberb56b9c52017-01-11 15:12:23 +0100289 begin
290 if Cur_Config.Port /= Disabled then
291 Check_HPD (Cur_Config.Port, Unplug_Detected);
Nico Huber83693c82016-10-08 22:17:55 +0200292
Nico Huber3d06de82018-05-29 01:35:04 +0200293 if Full_Update (Cur_Config, New_Config) or Unplug_Detected then
Nico Huberb56b9c52017-01-11 15:12:23 +0100294 Disable_Output (Pipe, Cur_Config);
295 Cur_Config.Port := Disabled;
Nico Huber9a4c4c32019-09-16 22:05:11 +0200296 Update_Power := True;
Nico Huberb56b9c52017-01-11 15:12:23 +0100297 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200298 end if;
Nico Huberb56b9c52017-01-11 15:12:23 +0100299 end;
300 end loop;
Nico Huber83693c82016-10-08 22:17:55 +0200301
Nico Huberb56b9c52017-01-11 15:12:23 +0100302 -- enable all pipes that changed and should be active
303 for Pipe in Pipe_Index loop
304 declare
305 Success : Boolean;
306 Cur_Config : Pipe_Config renames Cur_Configs (Pipe);
Nico Huber9a4c4c32019-09-16 22:05:11 +0200307 New_Config : Pipe_Config renames New_Configs (Pipe);
Nico Huberb56b9c52017-01-11 15:12:23 +0100308 begin
Nico Huber9a4c4c32019-09-16 22:05:11 +0200309 -- full update
Nico Huber3d06de82018-05-29 01:35:04 +0200310 if New_Config.Port /= Disabled and
311 Full_Update (Cur_Config, New_Config)
Nico Huberb56b9c52017-01-11 15:12:23 +0100312 then
Nico Huber9a4c4c32019-09-16 22:05:11 +0200313 Power_And_Clocks.Power_Up (Old_Configs, New_Configs);
314 Update_Power := True;
Nico Huberc7a4fee2016-11-03 18:18:03 +0100315
Nico Huber9a4c4c32019-09-16 22:05:11 +0200316 Enable_Output (Pipe, New_Config, Success);
Nico Huber83693c82016-10-08 22:17:55 +0200317 if Success then
Nico Huberb56b9c52017-01-11 15:12:23 +0100318 Cur_Config := New_Config;
Nico Huber83693c82016-10-08 22:17:55 +0200319 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100320
Nico Huberb56b9c52017-01-11 15:12:23 +0100321 -- update framebuffer offset only
322 elsif New_Config.Port /= Disabled and
Nico Huberf361ec82018-06-02 18:01:45 +0200323 Cur_Config.Framebuffer /= New_Config.Framebuffer
Nico Huberb56b9c52017-01-11 15:12:23 +0100324 then
Nico Huber9a4c4c32019-09-16 22:05:11 +0200325 Display_Controller.Setup_FB
326 (Pipe, New_Config.Mode, New_Config.Framebuffer);
327 Display_Controller.Update_Cursor
328 (Pipe, New_Config.Framebuffer, New_Config.Cursor);
329 Cur_Config := New_Config;
Nico Huberb56b9c52017-01-11 15:12:23 +0100330 end if;
331 end;
Nico Huber83693c82016-10-08 22:17:55 +0200332 end loop;
333
Nico Huber9a4c4c32019-09-16 22:05:11 +0200334 if Update_Power then
335 Power_And_Clocks.Power_Down (Old_Configs, New_Configs, Cur_Configs);
Nico Huber83693c82016-10-08 22:17:55 +0200336 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200337 end Update_Outputs;
338
339 ----------------------------------------------------------------------------
340
Nico Huber15ffc4f2018-01-11 14:44:43 +0100341 procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type)
342 is
343 begin
344 Cur_Configs (Pipe).Cursor := Cursor;
345 Display_Controller.Update_Cursor
346 (Pipe, Cur_Configs (Pipe).Framebuffer, Cur_Configs (Pipe).Cursor);
347 end Update_Cursor;
348
349 procedure Place_Cursor
350 (Pipe : Pipe_Index;
351 X : Cursor_Pos;
352 Y : Cursor_Pos)
353 is
354 begin
355 Cur_Configs (Pipe).Cursor.Center_X := X;
356 Cur_Configs (Pipe).Cursor.Center_Y := Y;
357 Display_Controller.Place_Cursor
358 (Pipe, Cur_Configs (Pipe).Framebuffer, Cur_Configs (Pipe).Cursor);
359 end Place_Cursor;
360
361 procedure Move_Cursor
362 (Pipe : Pipe_Index;
363 X : Cursor_Pos;
364 Y : Cursor_Pos)
365 is
366 function Cap_Add (A, B : Cursor_Pos) return Cursor_Pos is
367 (if A + B < 0
368 then Int32'Max (Cursor_Pos'First, A + B)
369 else Int32'Min (Cursor_Pos'Last, A + B));
370 begin
371 Place_Cursor
372 (Pipe => Pipe,
373 X => Cap_Add (Cur_Configs (Pipe).Cursor.Center_X, X),
374 Y => Cap_Add (Cur_Configs (Pipe).Cursor.Center_Y, Y));
375 end Move_Cursor;
376
377 ----------------------------------------------------------------------------
378
Nico Huber83693c82016-10-08 22:17:55 +0200379 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +0200380 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +0100381 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +0200382 Success : out Boolean)
383 with
384 Refined_Global =>
Nico Huber27088aa2018-06-10 13:28:05 +0200385 (Input => (Time.State),
386 In_Out => (Dev.PCI_State, Registers.Register_State, Port_IO.State),
Nico Huber83693c82016-10-08 22:17:55 +0200387 Output =>
Nico Huberc5c66ec2019-09-28 23:59:45 +0200388 (PCI_Usable,
389 Config.Variable,
Nico Huber27088aa2018-06-10 13:28:05 +0200390 Dev.Address_State,
Nico Huber2b6f6992017-07-09 18:11:34 +0200391 Registers.Address_State,
Nico Huber312433c2019-09-28 03:15:48 +0200392 PCode.Mailbox_Ready,
Nico Huber83693c82016-10-08 22:17:55 +0200393 PLLs.State, Panel.Panel_State,
Nico Huber1a712d32017-01-09 15:11:04 +0100394 Cur_Configs, Allocated_PLLs,
Nico Huberc3f66f62017-07-16 21:39:54 +0200395 HPD_Delay, Wait_For_HPD,
396 Linear_FB_Base, Initialized))
Nico Huber83693c82016-10-08 22:17:55 +0200397 is
398 use type HW.Word64;
399
Nico Huber0b2329a2018-06-09 21:14:27 +0200400 function MMIO_GTT_Offset return Natural is
401 (if Config.Has_64bit_GTT
402 then Registers.MMIO_GTT_64_Offset
403 else Registers.MMIO_GTT_32_Offset);
Nico Huber2b6f6992017-07-09 18:11:34 +0200404 PCI_MMIO_Base, PCI_GTT_Base : Word64;
405
Nico Huber83693c82016-10-08 22:17:55 +0200406 Now : constant Time.T := Time.Now;
407
408 procedure Check_Platform (Success : out Boolean)
409 is
410 Audio_VID_DID : Word32;
411 begin
Nico Huber6621a142018-06-07 23:56:54 +0200412 case Config.Gen is
Arthur Heymans73ea0322018-03-28 17:17:07 +0200413 when G45 =>
414 Registers.Read (Registers.G4X_AUD_VID_DID, Audio_VID_DID);
Nico Huber6621a142018-06-07 23:56:54 +0200415 when Ironlake =>
416 Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID);
Nico Huber83693c82016-10-08 22:17:55 +0200417 when Haswell .. Skylake =>
418 Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID);
Nico Huber83693c82016-10-08 22:17:55 +0200419 end case;
420 Success :=
Nico Huber998ee2b2018-06-12 23:02:17 +0200421 ((Config.Gen_Broxton and Audio_VID_DID = 16#8086_280a#) or
Nico Huber88badbe2018-09-27 16:36:47 +0200422 (Config.CPU_Kabylake and Audio_VID_DID = 16#8086_280b#) or
423 (Config.CPU_Skylake and Audio_VID_DID = 16#8086_2809#) or
Nico Huber998ee2b2018-06-12 23:02:17 +0200424 (Config.CPU_Broadwell and Audio_VID_DID = 16#8086_2808#) or
425 (Config.CPU_Haswell and Audio_VID_DID = 16#8086_2807#) or
426 ((Config.CPU_Ivybridge or
427 Config.CPU_Sandybridge) and (Audio_VID_DID = 16#8086_2806# or
428 Audio_VID_DID = 16#8086_2805#)) or
429 (Config.CPU_Ironlake and Audio_VID_DID = 16#0000_0000#) or
430 (Config.Gen_G45 and (Audio_VID_DID = 16#8086_2801# or
431 Audio_VID_DID = 16#8086_2802# or
432 Audio_VID_DID = 16#8086_2803#)));
Nico Huber83693c82016-10-08 22:17:55 +0200433 end Check_Platform;
Nico Hubere7ac6eb2017-09-04 23:54:13 +0200434
435 procedure Check_Platform_PCI (Success : out Boolean)
436 is
437 use type HW.Word16;
438 Vendor, Device : Word16;
439 begin
440 Dev.Read16 (Vendor, PCI.Vendor_Id);
441 Dev.Read16 (Device, PCI.Device_Id);
442
Nico Huber6a996dc2018-06-17 16:30:33 +0200443 Config.Detect_CPU (Device);
Nico Hubere7ac6eb2017-09-04 23:54:13 +0200444 Success := Vendor = 16#8086# and Config.Compatible_GPU (Device);
445 end Check_Platform_PCI;
Nico Huber83693c82016-10-08 22:17:55 +0200446 begin
Nico Huber83693c82016-10-08 22:17:55 +0200447 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
448
449 pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay));
450
Nico Huberc5c66ec2019-09-28 23:59:45 +0200451 PCI_Usable := False;
Nico Huberc3f66f62017-07-16 21:39:54 +0200452 Linear_FB_Base := 0;
Nico Huber312433c2019-09-28 03:15:48 +0200453 PCode.Mailbox_Ready := False;
Nico Huber83693c82016-10-08 22:17:55 +0200454 Wait_For_HPD := HPD_Type'(others => False);
455 HPD_Delay := HPD_Delay_Type'(others => Now);
Nico Huber83693c82016-10-08 22:17:55 +0200456 Allocated_PLLs := (others => PLLs.Invalid);
Nico Huber99f10f32016-11-20 00:34:05 +0100457 Cur_Configs := Pipe_Configs'
458 (others => Pipe_Config'
Nico Huber83693c82016-10-08 22:17:55 +0200459 (Port => Disabled,
460 Framebuffer => HW.GFX.Default_FB,
Nico Hubera02b2c62018-01-09 15:58:34 +0100461 Cursor => Default_Cursor,
Nico Huber83693c82016-10-08 22:17:55 +0200462 Mode => HW.GFX.Invalid_Mode));
Nico Huber27088aa2018-06-10 13:28:05 +0200463 Config.Variable := Config.Initial_Settings;
Nico Huber6a996dc2018-06-17 16:30:33 +0200464 Registers.Set_Register_Base (Config.Default_MMIO_Base);
Nico Huber83693c82016-10-08 22:17:55 +0200465 PLLs.Initialize;
466
Nico Huber2b6f6992017-07-09 18:11:34 +0200467 Dev.Initialize (Success);
468
469 if Success then
Nico Huber6a996dc2018-06-17 16:30:33 +0200470 Check_Platform_PCI (Success);
Nico Hubere7ac6eb2017-09-04 23:54:13 +0200471 if Success then
Nico Huber6a996dc2018-06-17 16:30:33 +0200472 Dev.Map (PCI_MMIO_Base, PCI.Res0, Length => MMIO_GTT_Offset);
473 Dev.Map (PCI_GTT_Base, PCI.Res0, Offset => MMIO_GTT_Offset);
474 if PCI_MMIO_Base /= 0 and PCI_GTT_Base /= 0 then
475 Registers.Set_Register_Base (PCI_MMIO_Base, PCI_GTT_Base);
Nico Huberc5c66ec2019-09-28 23:59:45 +0200476 PCI_Usable := True;
Nico Huber6a996dc2018-06-17 16:30:33 +0200477 else
478 pragma Debug (Debug.Put_Line
479 ("ERROR: Couldn't map resoure0."));
480 Success := Config.Default_MMIO_Base_Set;
481 end if;
Nico Hubere7ac6eb2017-09-04 23:54:13 +0200482 end if;
Nico Huber2b6f6992017-07-09 18:11:34 +0200483 else
484 pragma Debug (Debug.Put_Line
485 ("WARNING: Couldn't initialize PCI dev."));
Nico Huber2b6f6992017-07-09 18:11:34 +0200486 Success := Config.Default_MMIO_Base_Set;
Nico Huber2b6f6992017-07-09 18:11:34 +0200487
Nico Hubere7ac6eb2017-09-04 23:54:13 +0200488 if Success then
489 Check_Platform (Success);
490 end if;
Nico Huber2b6f6992017-07-09 18:11:34 +0200491 end if;
492
Nico Huber83693c82016-10-08 22:17:55 +0200493 if not Success then
494 pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH."));
495
496 Panel.Static_Init; -- for flow analysis
497
498 Initialized := False;
499 return;
500 end if;
501
502 Panel.Setup_PP_Sequencer;
503 Port_Detect.Initialize;
Nico Huber0923b792017-06-09 15:28:41 +0200504 Connectors.Initialize;
Nico Huber83693c82016-10-08 22:17:55 +0200505
Nico Huber793a8d42016-11-21 18:57:03 +0100506 if Clean_State then
507 Power_And_Clocks.Pre_All_Off;
508 Connectors.Pre_All_Off;
509 Display_Controller.All_Off;
510 Connectors.Post_All_Off;
511 PLLs.All_Off;
512 Power_And_Clocks.Post_All_Off;
Nico Huber17d64b62017-07-15 20:51:25 +0200513 Registers.Clear_Fences;
Nico Huber33912aa2016-12-06 20:36:23 +0100514 else
515 -- According to PRMs, VGA plane is the only thing
Nico Huber3a0e2a02017-07-19 14:41:46 +0200516 -- that's enabled by default after reset...
Nico Huber33912aa2016-12-06 20:36:23 +0100517 Display_Controller.Legacy_VGA_Off;
Nico Huber3a0e2a02017-07-19 14:41:46 +0200518 -- ... along with some DDI port bits since Skylake.
519 Connectors.Post_Reset_Off;
Nico Huber793a8d42016-11-21 18:57:03 +0100520 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200521
522 -------------------- Now restart from a clean state ---------------------
523 Power_And_Clocks.Initialize;
524
Nico Huber1c3b9282017-02-09 13:57:04 +0100525 if Config.Has_PCH then
526 Registers.Unset_And_Set_Mask
527 (Register => Registers.PCH_RAWCLK_FREQ,
528 Mask_Unset => PCH_RAWCLK_FREQ_MASK,
529 Mask_Set => PCH_RAWCLK_FREQ (Config.Default_RawClk_Freq));
530 end if;
Nico Huberf54d0962016-10-20 14:17:18 +0200531
Nico Huber83693c82016-10-08 22:17:55 +0200532 Initialized := True;
533
534 end Initialize;
535
536 function Is_Initialized return Boolean
537 with
538 Refined_Post => Is_Initialized'Result = Initialized
539 is
540 begin
541 return Initialized;
542 end Is_Initialized;
543
544 ----------------------------------------------------------------------------
545
Nico Hubercf88f3d2018-06-05 13:27:34 +0200546 pragma Warnings
547 (GNATprove, Off, """Registers.Register_State"" * is not modified*",
Nico Huberadfe11f2018-06-10 14:59:04 +0200548 Reason => "Power_Up_VGA is only effective in certain configurations.");
Nico Huber42fb2d02017-09-01 17:01:51 +0200549 procedure Power_Up_VGA
Nico Hubercf88f3d2018-06-05 13:27:34 +0200550 with
551 Refined_Global =>
Nico Huberadfe11f2018-06-10 14:59:04 +0200552 (Input => (Cur_Configs, Config.Variable, Time.State),
Nico Hubercf88f3d2018-06-05 13:27:34 +0200553 In_Out => (Registers.Register_State),
554 Proof_In => (Initialized))
Nico Huber42fb2d02017-09-01 17:01:51 +0200555 is
556 Fake_Config : constant Pipe_Configs :=
557 (Primary =>
558 (Port => Analog,
559 Framebuffer => HW.GFX.Default_FB,
Nico Hubera02b2c62018-01-09 15:58:34 +0100560 Cursor => Default_Cursor,
Nico Huber42fb2d02017-09-01 17:01:51 +0200561 Mode => HW.GFX.Invalid_Mode),
562 others =>
563 (Port => Disabled,
564 Framebuffer => HW.GFX.Default_FB,
Nico Hubera02b2c62018-01-09 15:58:34 +0100565 Cursor => Default_Cursor,
Nico Huber42fb2d02017-09-01 17:01:51 +0200566 Mode => HW.GFX.Invalid_Mode));
567 begin
568 Power_And_Clocks.Power_Up (Cur_Configs, Fake_Config);
569 end Power_Up_VGA;
Nico Hubercf88f3d2018-06-05 13:27:34 +0200570 pragma Warnings
571 (GNATprove, Off, "no check message justified*", Reason => "see below");
572 pragma Annotate
573 (GNATprove, Intentional, "unused global",
Nico Huberadfe11f2018-06-10 14:59:04 +0200574 "Power_Up_VGA is only effective in certain configurations.");
Nico Hubercf88f3d2018-06-05 13:27:34 +0200575 pragma Warnings (GNATprove, On, "no check message justified*");
576 pragma Warnings
577 (GNATprove, On, """Registers.Register_State"" * is not modified*");
Nico Huber42fb2d02017-09-01 17:01:51 +0200578
579 ----------------------------------------------------------------------------
580
Nico Huber5374c3a2017-07-15 21:48:06 +0200581 function FB_First_Page (FB : Framebuffer_Type) return Natural is
Nico Huber34be6542017-12-13 09:26:24 +0100582 (Natural (Phys_Offset (FB) / GTT_Page_Size));
Nico Huber5374c3a2017-07-15 21:48:06 +0200583 function FB_Pages (FB : Framebuffer_Type) return Natural is
584 (Natural (Div_Round_Up (FB_Size (FB), GTT_Page_Size)));
585 function FB_Last_Page (FB : Framebuffer_Type) return Natural is
586 (FB_First_Page (FB) + FB_Pages (FB) - 1);
587
Nico Huber34be6542017-12-13 09:26:24 +0100588 -- Check basics and that it fits in GTT. For 90 degree rotations,
589 -- the Offset should be above GTT_Rotation_Offset. The latter will
590 -- be subtracted for the aperture mapping.
Nico Huber5374c3a2017-07-15 21:48:06 +0200591 function Valid_FB (FB : Framebuffer_Type) return Boolean is
Nico Huber34be6542017-12-13 09:26:24 +0100592 (Valid_Stride (FB) and
593 FB_First_Page (FB) in GTT_Range and
594 FB_Last_Page (FB) in GTT_Range and
595 (not Rotation_90 (FB) or
596 (FB_Last_Page (FB) + GTT_Rotation_Offset in GTT_Range and
597 FB.Offset >= Word32 (GTT_Rotation_Offset) * GTT_Page_Size)));
Nico Huber5374c3a2017-07-15 21:48:06 +0200598
599 -- Also check that we don't overflow the GTT's 39-bit space
600 -- (always true with a 32-bit base)
601 function Valid_Phys_FB (FB : Framebuffer_Type; Phys_Base : Word32)
602 return Boolean is
603 (Valid_FB (FB) and
Nico Huber34be6542017-12-13 09:26:24 +0100604 Int64 (Phys_Base) + Int64 (Phys_Offset (FB)) + Int64 (FB_Size (FB)) <=
Nico Huber5374c3a2017-07-15 21:48:06 +0200605 Int64 (GTT_Address_Type'Last))
606 with
607 Ghost;
608
Nico Huber83693c82016-10-08 22:17:55 +0200609 procedure Write_GTT
610 (GTT_Page : GTT_Range;
611 Device_Address : GTT_Address_Type;
Nico Huber5374c3a2017-07-15 21:48:06 +0200612 Valid : Boolean)
613 is
Nico Huber83693c82016-10-08 22:17:55 +0200614 begin
615 Registers.Write_GTT (GTT_Page, Device_Address, Valid);
616 end Write_GTT;
617
Nico Huberceda17d2018-06-09 22:00:29 +0200618 procedure Read_GTT
619 (Device_Address : out GTT_Address_Type;
620 Valid : out Boolean;
621 GTT_Page : in GTT_Range)
622 is
623 begin
624 Registers.Read_GTT (Device_Address, Valid, GTT_Page);
625 end Read_GTT;
626
Nico Huber194e57e2017-07-15 21:15:46 +0200627 procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_Base : Word32)
Nico Huber5374c3a2017-07-15 21:48:06 +0200628 with
629 Pre => Is_Initialized and Valid_Phys_FB (FB, Phys_Base)
Nico Huber83693c82016-10-08 22:17:55 +0200630 is
Nico Huber194e57e2017-07-15 21:15:46 +0200631 Phys_Addr : GTT_Address_Type :=
Nico Huber34be6542017-12-13 09:26:24 +0100632 GTT_Address_Type (Phys_Base) + GTT_Address_Type (Phys_Offset (FB));
Nico Huber83693c82016-10-08 22:17:55 +0200633 begin
Nico Huber194e57e2017-07-15 21:15:46 +0200634 for Idx in FB_First_Page (FB) .. FB_Last_Page (FB) loop
Nico Huber83693c82016-10-08 22:17:55 +0200635 Registers.Write_GTT
636 (GTT_Page => Idx,
637 Device_Address => Phys_Addr,
638 Valid => True);
Nico Huber194e57e2017-07-15 21:15:46 +0200639 Phys_Addr := Phys_Addr + GTT_Page_Size;
Nico Huber83693c82016-10-08 22:17:55 +0200640 end loop;
Nico Huber9b479412017-08-27 11:55:56 +0200641
642 if Rotation_90 (FB) and FB.Tiling = Y_Tiled and FB.V_Stride >= 32 then
643 declare
644 V_Pages : constant Natural := Natural (FB.V_Stride) / 32;
645 Bytes_Per_Row : constant GTT_Address_Type :=
646 GTT_Address_Type (Pixel_To_Bytes (32 * FB.Stride, FB));
647 begin
648 Phys_Addr := GTT_Address_Type (Phys_Base) +
Nico Huber34be6542017-12-13 09:26:24 +0100649 GTT_Address_Type (Phys_Offset (FB)) +
Nico Huber9b479412017-08-27 11:55:56 +0200650 GTT_Address_Type (FB_Size (FB));
651 for Page in FB_First_Page (FB) .. FB_Last_Page (FB) loop
652 Phys_Addr := Phys_Addr - Bytes_Per_Row;
653 Registers.Write_GTT
654 (GTT_Page => GTT_Rotation_Offset + Page,
655 Device_Address => Phys_Addr,
656 Valid => True);
657
658 if (Page - FB_First_Page (FB) + 1) mod V_Pages = 0 then
659 Phys_Addr := Phys_Addr + GTT_Page_Size +
660 GTT_Address_Type (V_Pages) * Bytes_Per_Row;
661 end if;
662 end loop;
663 end;
664 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200665 end Setup_Default_GTT;
666
667 ----------------------------------------------------------------------------
668
Nico Hubereedde882017-07-16 02:54:39 +0200669 use type HW.Word16;
670 subtype Stolen_Size_Range is Int64 range 0 .. 2 ** 33;
671
672 function GGMS_Gen4 (GGC : Word16) return Natural is
673 (Natural (Shift_Right (GGC, 8) and 16#07#));
674 function GTT_Size_Gen4 (GGC : Word16) return Natural is
675 (if GGMS_Gen4 (GGC) in 1 .. 3 then
676 (GGMS_Gen4 (GGC) + 1) * 2 ** 19 else 0);
677
678 function GMS_Gen4 (GGC : Word16) return Natural is
679 (Natural (Shift_Right (GGC, 4) and 16#0f#));
680 Valid_Stolen_Size_Gen4 : constant
681 array (Natural range 1 .. 13) of Stolen_Size_Range :=
682 (1, 4, 8, 16, 32, 48, 64, 128, 256, 96, 160, 224, 352);
683 function Stolen_Size_Gen4 (GGC : Word16) return Stolen_Size_Range is
684 (if GMS_Gen4 (GGC) in Valid_Stolen_Size_Gen4'Range then
Arthur Heymans5fd9a312017-09-12 12:45:18 +0200685 Valid_Stolen_Size_Gen4 (GMS_Gen4 (GGC)) * 2 ** 20 else 0);
Nico Hubereedde882017-07-16 02:54:39 +0200686
687 function GTT_Size_Gen6 (GGC : Word16) return Natural is
688 (Natural (Shift_Right (GGC, 8) and 16#03#) * 2 ** 20);
689
690 function Stolen_Size_Gen6 (GGC : Word16) return Stolen_Size_Range is
691 (Stolen_Size_Range (Shift_Right (GGC, 3) and 16#1f#) * 32 * 2 ** 20);
692
693 function GTT_Size_Gen8 (GGC : Word16) return Natural is
694 (Natural (Shift_Right (GGC, 6) and 16#03#) * 2 ** 20);
695
696 function GMS_Gen8 (GGC : Word16) return Stolen_Size_Range is
697 (Stolen_Size_Range (Shift_Right (GGC, 8) and 16#ff#));
698 function Stolen_Size_Gen8 (GGC : Word16) return Stolen_Size_Range is
699 (GMS_Gen8 (GGC) * 32 * 2 ** 20);
700
701 function Stolen_Size_Gen9 (GGC : Word16) return Stolen_Size_Range is
702 (if GMS_Gen8 (GGC) < 16#f0# then
703 Stolen_Size_Gen8 (GGC)
704 else
705 (GMS_Gen8 (GGC) - 16#f0# + 1) * 4 * 2 ** 20);
706
707 procedure Decode_Stolen
708 (GTT_Size : out Natural;
709 Stolen_Size : out Stolen_Size_Range)
710 with
711 Pre => Is_Initialized
712 is
Nico Huber63ec8362018-06-09 17:42:19 +0200713 GGC_Reg : constant PCI.Index :=
Nico Huber998ee2b2018-06-12 23:02:17 +0200714 (if Config.Gen_G45 or Config.CPU_Ironlake then 16#52# else 16#50#);
Nico Hubereedde882017-07-16 02:54:39 +0200715 GGC : Word16;
716 begin
717 Dev.Read16 (GGC, GGC_Reg);
Nico Huber998ee2b2018-06-12 23:02:17 +0200718 if Config.Gen_G45 or Config.CPU_Ironlake then
719 GTT_Size := GTT_Size_Gen4 (GGC);
720 Stolen_Size := Stolen_Size_Gen4 (GGC);
721 elsif Config.CPU_Sandybridge or Config.CPU_Ivybridge or Config.CPU_Haswell
722 then
723 GTT_Size := GTT_Size_Gen6 (GGC);
724 Stolen_Size := Stolen_Size_Gen6 (GGC);
725 elsif Config.CPU_Broadwell then
726 GTT_Size := GTT_Size_Gen8 (GGC);
727 Stolen_Size := Stolen_Size_Gen8 (GGC);
728 else
729 GTT_Size := GTT_Size_Gen8 (GGC);
730 Stolen_Size := Stolen_Size_Gen9 (GGC);
731 end if;
Nico Hubereedde882017-07-16 02:54:39 +0200732 end Decode_Stolen;
733
734 -- Additional runtime validation that FB fits stolen memory and aperture.
735 procedure Validate_FB (FB : Framebuffer_Type; Valid : out Boolean)
736 with
737 Pre => Is_Initialized,
738 Post => (if Valid then Valid_FB (FB))
739 is
740 GTT_Size, Aperture_Size : Natural;
741 Stolen_Size : Stolen_Size_Range;
742 begin
743 Valid := Valid_FB (FB);
744
745 if Valid then
746 Decode_Stolen (GTT_Size, Stolen_Size);
747 Dev.Resource_Size (Aperture_Size, PCI.Res2);
748 Valid :=
749 FB_Last_Page (FB) < GTT_Size / Config.GTT_PTE_Size and
750 FB_Last_Page (FB) < Natural (Stolen_Size / GTT_Page_Size) and
751 FB_Last_Page (FB) < Aperture_Size / GTT_Page_Size;
Nico Huber34be6542017-12-13 09:26:24 +0100752 pragma Debug (not Valid, Debug.Put_Line
Nico Hubereedde882017-07-16 02:54:39 +0200753 ("Stolen memory too small to hold framebuffer."));
754 end if;
755 end Validate_FB;
756
Nico Huber5374c3a2017-07-15 21:48:06 +0200757 procedure Setup_Default_FB
758 (FB : in Framebuffer_Type;
759 Clear : in Boolean := True;
760 Success : out Boolean)
761 is
762 GMA_Phys_Base : constant PCI.Index := 16#5c#;
763 GMA_Phys_Base_Mask : constant := 16#fff0_0000#;
764
765 Phys_Base : Word32;
766 begin
Nico Hubereedde882017-07-16 02:54:39 +0200767 Validate_FB (FB, Success);
Nico Huber5374c3a2017-07-15 21:48:06 +0200768
769 if Success then
770 Dev.Read32 (Phys_Base, GMA_Phys_Base);
771 Phys_Base := Phys_Base and GMA_Phys_Base_Mask;
772 Success := Phys_Base /= GMA_Phys_Base_Mask and Phys_Base /= 0;
773 pragma Debug (not Success, Debug.Put_Line
774 ("Failed to read stolen memory base."));
Nico Huber0164b022017-08-24 15:12:51 +0200775
776 if Success then
777 if FB.Tiling in XY_Tiling then
778 Registers.Add_Fence
779 (First_Page => FB_First_Page (FB),
780 Last_Page => FB_Last_Page (FB),
781 Tiling => FB.Tiling,
782 Pitch => FB_Pitch (FB.Stride, FB),
783 Success => Success);
784 end if;
785 pragma Debug (not Success, Debug.Put_Line
786 ("Tiled framebuffer but no fence regs available."));
787 end if;
788
Nico Huber5374c3a2017-07-15 21:48:06 +0200789 if Success then
790 Setup_Default_GTT (FB, Phys_Base);
791 end if;
792 end if;
793
794 if Success and then Clear then
795 declare
796 use type HW.Word64;
797 Linear_FB : Word64;
798 begin
Nico Huberc3f66f62017-07-16 21:39:54 +0200799 Map_Linear_FB (Linear_FB, FB);
Nico Huber5374c3a2017-07-15 21:48:06 +0200800 if Linear_FB /= 0 then
Nico Huberc3f66f62017-07-16 21:39:54 +0200801 Framebuffer_Filler.Fill (Linear_FB, FB);
Nico Huber5374c3a2017-07-15 21:48:06 +0200802 end if;
Nico Huber5374c3a2017-07-15 21:48:06 +0200803 end;
804 end if;
805 end Setup_Default_FB;
806
Nico Huberc3f66f62017-07-16 21:39:54 +0200807 procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type)
808 is
809 use type HW.Word64;
810
811 Valid : Boolean;
812 begin
813 Linear_FB := 0;
814
815 if Linear_FB_Base = 0 then
816 Dev.Map (Linear_FB_Base, PCI.Res2);
817 pragma Debug
818 (Linear_FB_Base = 0, Debug.Put_Line ("Failed to map resource2."));
819 end if;
820
821 if Linear_FB_Base /= 0 then
822 Validate_FB (FB, Valid);
823 if Valid then
Nico Huber34be6542017-12-13 09:26:24 +0100824 Linear_FB := Linear_FB_Base + Word64 (Phys_Offset (FB));
Nico Huberc3f66f62017-07-16 21:39:54 +0200825 end if;
826 end if;
827 end Map_Linear_FB;
828
Nico Huber5374c3a2017-07-15 21:48:06 +0200829 ----------------------------------------------------------------------------
830
Nico Huber99f10f32016-11-20 00:34:05 +0100831 procedure Dump_Configs (Configs : Pipe_Configs)
Nico Huber83693c82016-10-08 22:17:55 +0200832 is
833 subtype Pipe_Name is String (1 .. 9);
Nico Huber99f10f32016-11-20 00:34:05 +0100834 type Pipe_Name_Array is array (Pipe_Index) of Pipe_Name;
Nico Huber83693c82016-10-08 22:17:55 +0200835 Pipe_Names : constant Pipe_Name_Array :=
836 (Primary => "Primary ",
837 Secondary => "Secondary",
838 Tertiary => "Tertiary ");
Nico Huber5ef4d602017-12-13 13:56:47 +0100839
840 subtype Tiling_Name is String (1 .. 7);
841 type Tiling_Name_Array is array (Tiling_Type) of Tiling_Name;
842 Tilings : constant Tiling_Name_Array :=
843 (Linear => "Linear ",
844 X_Tiled => "X_Tiled",
845 Y_Tiled => "Y_Tiled");
846
847 subtype Rotation_Name is String (1 .. 11);
848 type Rotation_Name_Array is array (Rotation_Type) of Rotation_Name;
849 Rotations : constant Rotation_Name_Array :=
850 (No_Rotation => "No_Rotation",
851 Rotated_90 => "Rotated_90 ",
852 Rotated_180 => "Rotated_180",
853 Rotated_270 => "Rotated_270");
Nico Huber83693c82016-10-08 22:17:55 +0200854 begin
855 Debug.New_Line;
Paul Menzelb83107c2017-05-04 09:02:33 +0200856 Debug.Put_Line ("CONFIG =>");
Nico Huber99f10f32016-11-20 00:34:05 +0100857 for Pipe in Pipe_Index loop
858 if Pipe = Pipe_Index'First then
Nico Huber83693c82016-10-08 22:17:55 +0200859 Debug.Put (" (");
860 else
861 Debug.Put (" ");
862 end if;
863 Debug.Put_Line (Pipe_Names (Pipe) & " =>");
864 Debug.Put_Line
865 (" (Port => " & Port_Names (Configs (Pipe).Port) & ",");
866 Debug.Put_Line (" Framebuffer =>");
Nico Huber5ef4d602017-12-13 13:56:47 +0100867 Debug.Put (" (Width => ");
Nico Huber83693c82016-10-08 22:17:55 +0200868 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width);
869 Debug.Put_Line (",");
Nico Huber5ef4d602017-12-13 13:56:47 +0100870 Debug.Put (" Height => ");
Nico Huber83693c82016-10-08 22:17:55 +0200871 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height);
872 Debug.Put_Line (",");
Nico Huber5ef4d602017-12-13 13:56:47 +0100873 Debug.Put (" Start_X => ");
874 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_X);
875 Debug.Put_Line (",");
876 Debug.Put (" Start_Y => ");
877 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_Y);
878 Debug.Put_Line (",");
879 Debug.Put (" Stride => ");
Nico Huber83693c82016-10-08 22:17:55 +0200880 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride);
881 Debug.Put_Line (",");
Nico Huber5ef4d602017-12-13 13:56:47 +0100882 Debug.Put (" V_Stride => ");
883 Debug.Put_Int32 (Configs (Pipe).Framebuffer.V_Stride);
884 Debug.Put_Line (",");
885 Debug.Put (" Tiling => ");
886 Debug.Put_Line (Tilings (Configs (Pipe).Framebuffer.Tiling) & ",");
887 Debug.Put (" Rotation => ");
888 Debug.Put_Line (Rotations (Configs (Pipe).Framebuffer.Rotation) & ",");
Nico Huber83693c82016-10-08 22:17:55 +0200889 Debug.Put (" Offset => ");
890 Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset);
891 Debug.Put_Line (",");
892 Debug.Put (" BPC => ");
893 Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC);
894 Debug.Put_Line ("),");
895 Debug.Put_Line (" Mode =>");
896 Debug.Put (" (Dotclock => ");
897 Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock);
898 Debug.Put_Line (",");
899 Debug.Put (" H_Visible => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200900 Debug.Put_Int32 (Configs (Pipe).Mode.H_Visible);
Nico Huber83693c82016-10-08 22:17:55 +0200901 Debug.Put_Line (",");
902 Debug.Put (" H_Sync_Begin => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200903 Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_Begin);
Nico Huber83693c82016-10-08 22:17:55 +0200904 Debug.Put_Line (",");
905 Debug.Put (" H_Sync_End => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200906 Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_End);
Nico Huber83693c82016-10-08 22:17:55 +0200907 Debug.Put_Line (",");
908 Debug.Put (" H_Total => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200909 Debug.Put_Int32 (Configs (Pipe).Mode.H_Total);
Nico Huber83693c82016-10-08 22:17:55 +0200910 Debug.Put_Line (",");
911 Debug.Put (" V_Visible => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200912 Debug.Put_Int32 (Configs (Pipe).Mode.V_Visible);
Nico Huber83693c82016-10-08 22:17:55 +0200913 Debug.Put_Line (",");
914 Debug.Put (" V_Sync_Begin => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200915 Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_Begin);
Nico Huber83693c82016-10-08 22:17:55 +0200916 Debug.Put_Line (",");
917 Debug.Put (" V_Sync_End => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200918 Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_End);
Nico Huber83693c82016-10-08 22:17:55 +0200919 Debug.Put_Line (",");
920 Debug.Put (" V_Total => ");
Nico Huberc5c767a2018-06-03 01:09:04 +0200921 Debug.Put_Int32 (Configs (Pipe).Mode.V_Total);
Nico Huber83693c82016-10-08 22:17:55 +0200922 Debug.Put_Line (",");
923 Debug.Put_Line (" H_Sync_Active_High => " &
924 (if Configs (Pipe).Mode.H_Sync_Active_High
925 then "True,"
926 else "False,"));
927 Debug.Put_Line (" V_Sync_Active_High => " &
928 (if Configs (Pipe).Mode.V_Sync_Active_High
929 then "True,"
930 else "False,"));
931 Debug.Put (" BPC => ");
932 Debug.Put_Int64 (Configs (Pipe).Mode.BPC);
Nico Huber99f10f32016-11-20 00:34:05 +0100933 if Pipe /= Pipe_Index'Last then
Nico Huber83693c82016-10-08 22:17:55 +0200934 Debug.Put_Line (")),");
935 else
936 Debug.Put_Line (")));");
937 end if;
938 end loop;
939 end Dump_Configs;
940
Nico Huberc5c66ec2019-09-28 23:59:45 +0200941 ----------------------------------------------------------------------------
942
943 procedure PCI_Read16 (Value : out Word16; Offset : HW.PCI.Index) is
944 begin
945 Dev.Read16 (Value, Offset);
946 end PCI_Read16;
947
Nico Huber83693c82016-10-08 22:17:55 +0200948end HW.GFX.GMA;