blob: 1c0919f9218c84b8eb1da8931fd0b0f8540bccc5 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2014-2016 secunet Security Networks AG
3--
4-- This program is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02008--
9-- This program is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14
15with HW.GFX.EDID;
16with HW.GFX.GMA.Config;
17with HW.GFX.GMA.DP_Info;
18with HW.GFX.GMA.Registers;
19with HW.GFX.GMA.Power_And_Clocks;
20with HW.GFX.GMA.Panel;
21with HW.GFX.GMA.PLLs;
22with HW.GFX.GMA.Port_Detect;
23with HW.GFX.GMA.Connectors;
24with HW.GFX.GMA.Connector_Info;
25with HW.GFX.GMA.Pipe_Setup;
26
27with System;
28
29with HW.Debug;
30with GNAT.Source_Info;
31
32use type HW.Word8;
33use type HW.Int32;
34
35package body HW.GFX.GMA
36 with Refined_State =>
37 (State =>
38 (Registers.Address_State,
39 PLLs.State, Panel.Panel_State,
40 Cur_Configs, Allocated_PLLs, DP_Links,
41 HPD_Delay, Wait_For_HPD),
42 Init_State => Initialized,
43 Config_State => Config.Valid_Port_GPU,
44 Device_State =>
45 (Registers.Register_State, Registers.GTT_State))
46is
47
48 subtype Port_Name is String (1 .. 8);
49 type Port_Name_Array is array (Port_Type) of Port_Name;
50 Port_Names : constant Port_Name_Array :=
51 (Disabled => "Disabled",
52 Internal => "Internal",
53 DP1 => "DP1 ",
54 DP2 => "DP2 ",
55 DP3 => "DP3 ",
56 Digital1 => "Digital1",
57 Digital2 => "Digital2",
58 Digital3 => "Digital3",
59 Analog => "Analog ");
60
61 package Display_Controller renames Pipe_Setup;
62
63 type PLLs_Type is array (Config_Index) of PLLs.T;
64
65 type Links_Type is array (Config_Index) of DP_Link;
66
67 type HPD_Type is array (Port_Type) of Boolean;
68 type HPD_Delay_Type is array (Port_Type) of Time.T;
69
70 Cur_Configs : Configs_Type;
71 Allocated_PLLs : PLLs_Type;
72 DP_Links : Links_Type;
73 HPD_Delay : HPD_Delay_Type;
74 Wait_For_HPD : HPD_Type;
75 Initialized : Boolean := False;
76
77 subtype Active_Port_Type is Port_Type range Port_Type'Succ (Disabled) .. Port_Type'Last;
78
79 ----------------------------------------------------------------------------
80
Nico Huberf54d0962016-10-20 14:17:18 +020081 PCH_RAWCLK_FREQ_MASK : constant := 16#3ff# * 2 ** 0;
82
83 function PCH_RAWCLK_FREQ (Freq : Frequency_Type) return Word32
84 is
85 begin
86 return Word32 (Freq / 1_000_000);
87 end PCH_RAWCLK_FREQ;
88
89 ----------------------------------------------------------------------------
90
Nico Huber83693c82016-10-08 22:17:55 +020091 function To_GPU_Port
92 (Configs : Configs_Type;
93 Idx : Config_Index)
94 return GPU_Port
95 is
96 begin
97 return
98 (case Config.CPU is
99 when Ironlake .. Ivybridge => -- everything but eDP through FDI/PCH
100 (if Config.Internal_Is_EDP and then Configs (Idx).Port = Internal
101 then
102 DIGI_A
103 else
104 (case Idx is
105 -- FDIs are fixed to the CPU pipe
106 when Primary => DIGI_B,
107 when Secondary => DIGI_C,
108 when Tertiary => DIGI_D)),
109 when Haswell .. Skylake => -- everything but VGA directly on CPU
110 (case Configs (Idx).Port is
111 when Disabled => GPU_Port'First,
112 when Internal => DIGI_A, -- LVDS not available
113 when Digital1 | DP1 => DIGI_B,
114 when Digital2 | DP2 => DIGI_C,
115 when Digital3 | DP3 => DIGI_D,
116 when Analog => DIGI_E));
117 end To_GPU_Port;
118
119 function To_PCH_Port (Port : Active_Port_Type) return PCH_Port
120 is
121 begin
122 return
123 (case Port is
124 when Internal => PCH_LVDS, -- will be ignored if Internal is DP
125 when Analog => PCH_DAC,
126 when Digital1 => PCH_HDMI_B,
127 when Digital2 => PCH_HDMI_C,
128 when Digital3 => PCH_HDMI_D,
129 when DP1 => PCH_DP_B,
130 when DP2 => PCH_DP_C,
131 when DP3 => PCH_DP_D);
132 end To_PCH_Port;
133
134 function To_Display_Type (Port : Active_Port_Type) return Display_Type
135 with Pre => True
136 is
137 begin
138 return
139 (case Port is
140 when Internal => Config.Internal_Display,
141 when Analog => VGA,
142 when Digital1 |
143 Digital2 |
144 Digital3 => HDMI,
145 when DP1 |
146 DP2 |
147 DP3 => DP);
148 end To_Display_Type;
149
150 procedure Configure_FDI_Link
151 (Port_Cfg : in out Port_Config;
152 Success : out Boolean)
153 with Pre => True
154 is
155 procedure Limit_Lane_Count
156 is
157 FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31;
158 Enabled : Boolean;
159 begin
160 -- if DIGI_D enabled: (FDI names are off by one)
161 Registers.Is_Set_Mask
162 (Register => Registers.FDI_TX_CTL_C,
163 Mask => FDI_TX_CTL_FDI_TX_ENABLE,
164 Result => Enabled);
165 if Enabled then
166 Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2;
167 end if;
168 end Limit_Lane_Count;
169 begin
170 Port_Cfg.FDI.Receiver_Caps.Max_Link_Rate := DP_Bandwidth_2_7;
171 Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count :=
172 Config.FDI_Lane_Count (Port_Cfg.Port);
173 Port_Cfg.FDI.Receiver_Caps.Enhanced_Framing := True;
174 if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_C then
175 Limit_Lane_Count;
176 end if;
177 DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success);
178 end Configure_FDI_Link;
179
Nico Huberc7a4fee2016-11-03 18:18:03 +0100180 function Validate_Config
181 (Framebuffer : Framebuffer_Type;
182 Port_Cfg : Port_Config)
183 return Boolean
184 with Global => null
185 is
186 begin
187 -- No downscaling
188 -- Only 32bpp RGB
189 -- Stride must be a multiple of 64
190 return
191 Framebuffer.Width <= Pos32 (Port_Cfg.Mode.H_Visible) and
192 Framebuffer.Height <= Pos32 (Port_Cfg.Mode.V_Visible) and
193 Framebuffer.BPC = 8 and
194 Framebuffer.Stride mod 64 = 0;
195 end Validate_Config;
196
Nico Huber83693c82016-10-08 22:17:55 +0200197 procedure Fill_Port_Config
198 (Port_Cfg : out Port_Config;
199 Configs : in Configs_Type;
200 Idx : in Config_Index;
201 Success : out Boolean)
202 with Pre => True
203 is
204 begin
205 Success :=
206 Config.Supported_Pipe (Idx) and then
207 Config.Valid_Port (Configs (Idx).Port) and then
208 Configs (Idx).Port /= Disabled;
209
210 if Success then
211 declare
212 Port : constant Port_Type := Configs (Idx).Port;
213 Mode : constant Mode_Type := Configs (Idx).Mode;
214 Link : constant DP_Link := DP_Links (Idx);
215 begin
216 Port_Cfg := Port_Config'
217 (Port => To_GPU_Port (Configs, Idx),
218 PCH_Port => To_PCH_Port (Port),
219 Display => To_Display_Type (Port),
220 Mode => Mode,
221 Is_FDI => Config.FDI_Port (To_GPU_Port (Configs, Idx)),
222 FDI => Default_DP,
223 DP => Link);
224 if Port_Cfg.Mode.BPC = Auto_BPC then
225 Port_Cfg.Mode.BPC := Connector_Info.Default_BPC (Port_Cfg);
226 end if;
227 end;
228 else
229 Port_Cfg := Port_Config'
230 (Port => GPU_Port'First,
231 PCH_Port => PCH_Port'First,
232 Display => Display_Type'First,
233 Mode => Invalid_Mode,
234 Is_FDI => False,
235 FDI => Default_DP,
236 DP => Default_DP);
237 end if;
238 end Fill_Port_Config;
239
240 ----------------------------------------------------------------------------
241
242 function To_Controller
243 (Dsp_Config : Config_Index) return Display_Controller.Controller_Type
244 is
245 Result : Display_Controller.Controller_Type;
246 begin
247 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
248
249 case Dsp_Config is
250 when Primary =>
251 Result := Display_Controller.Controllers (Display_Controller.A);
252 when Secondary =>
253 Result := Display_Controller.Controllers (Display_Controller.B);
254 when Tertiary =>
255 Result := Display_Controller.Controllers (Display_Controller.C);
256 end case;
257 return Result;
258 end To_Controller;
259
260 ----------------------------------------------------------------------------
261
262 function To_Head
263 (N_Config : Config_Index;
264 Port : Active_Port_Type)
265 return Display_Controller.Head_Type
266 is
267 Result : Display_Controller.Head_Type;
268 begin
269 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
270
271 if Config.Has_EDP_Pipe and then Port = Internal then
272 Result := Display_Controller.Heads (Display_Controller.Head_EDP);
273 else
274 case N_Config is
275 when Primary =>
276 Result := Display_Controller.Heads (Display_Controller.Head_A);
277 when Secondary =>
278 Result := Display_Controller.Heads (Display_Controller.Head_B);
279 when Tertiary =>
280 Result := Display_Controller.Heads (Display_Controller.Head_C);
281 end case;
282 end if;
283 return Result;
284 end To_Head;
285
286 ----------------------------------------------------------------------------
287
288 procedure Legacy_VGA_Off
289 is
290 Reg8 : Word8;
291 begin
292 -- disable legacy VGA plane, taking over control now
293 Port_IO.OutB (VGA_SR_INDEX, VGA_SR01);
294 Port_IO.InB (Reg8, VGA_SR_DATA);
295 Port_IO.OutB (VGA_SR_DATA, Reg8 or 1 * 2 ** 5);
296 Time.U_Delay (100); -- PRM says 100us, Linux does 300
297 Registers.Set_Mask (Registers.VGACNTRL, 1 * 2 ** 31);
298 end Legacy_VGA_Off;
299
300 ----------------------------------------------------------------------------
301
302 function Port_Configured
303 (Configs : Configs_Type;
304 Port : Port_Type)
305 return Boolean
306 with
307 Global => null
308 is
309 begin
310 return Configs (Primary).Port = Port or
311 Configs (Secondary).Port = Port or
312 Configs (Tertiary).Port = Port;
313 end Port_Configured;
314
315 procedure Scan_Ports
316 (Configs : out Configs_Type;
317 Ports : in Port_List)
318 is
319 Raw_EDID : EDID.Raw_EDID_Data := (others => 16#00#);
320 Port_Idx : Port_List_Range := Port_List_Range'First;
321 Port_Cfg : Port_Config;
322 Success : Boolean := False;
323 begin
324 Configs := (Config_Index =>
325 (Port => Disabled,
326 Mode => Invalid_Mode,
327 Framebuffer => Default_FB));
328
329 for Config_Idx in Config_Index loop
330 while Ports (Port_Idx) /= Disabled loop
331 if not Port_Configured (Configs, Ports (Port_Idx)) then
332 Configs (Config_Idx).Port := Ports (Port_Idx);
333 Fill_Port_Config (Port_Cfg, Configs, Config_Idx, Success);
334
335 if Success then
336 -- May need power to probe port
337 if Port_Cfg.Display = DP then
338 Power_And_Clocks.Power_Up (Cur_Configs, Configs);
339 end if;
340 if Ports (Port_Idx) = Internal then
341 Panel.On;
342 end if;
343
344 Connector_Info.Read_EDID (Raw_EDID, Port_Cfg, Success);
345 end if;
346
Nico Huber393aa8a2016-10-21 14:18:53 +0200347 if Success and then
348 (EDID.Compatible_Display (Raw_EDID, Port_Cfg.Display) and
349 EDID.Has_Preferred_Mode (Raw_EDID))
350 then
Nico Huber83693c82016-10-08 22:17:55 +0200351 Configs (Config_Idx).Mode := EDID.Preferred_Mode (Raw_EDID);
352 else
353 Configs (Config_Idx).Port := Disabled;
Nico Huber6a356672016-10-21 15:13:55 +0200354 Success := False;
Nico Huber83693c82016-10-08 22:17:55 +0200355
356 if Ports (Port_Idx) = Internal and
357 not Port_Configured (Cur_Configs, Internal)
358 then
359 Panel.Off;
360 end if;
361 end if;
362 end if;
363
364 exit when Port_Idx = Port_List_Range'Last;
365 Port_Idx := Port_List_Range'Succ (Port_Idx);
366
367 exit when Success;
368 end loop;
369 end loop;
370
371 Power_And_Clocks.Power_Set_To (Cur_Configs);
372 end Scan_Ports;
373
374 procedure Auto_Configure
375 (Configs : in out Configs_Type;
376 Keep_Power : in Boolean := False)
377 is
378 Raw_EDID : EDID.Raw_EDID_Data := (others => 16#00#);
379 Success : Boolean;
380
381 Config_Idx : Config_Index;
382 Port_Cfg : Port_Config;
383
384 function Free_Config return Boolean
385 with
386 Pre => True
387 is
388 begin
389 return Port_Configured (Configs, Disabled);
390 end Free_Config;
391
392 function First_Free_Config return Config_Index
393 with
394 Pre => Free_Config
395 is
396 begin
397 return (if Configs (Primary).Port = Disabled then Primary else
398 (if Configs (Secondary).Port = Disabled then Secondary
399 else Tertiary));
400 end First_Free_Config;
401 begin
402 -- TODO: Only check ports with hot-plug event?
403
404 if Config.Has_Internal_Display and then
405 not Keep_Power and then
406 not Port_Configured (Cur_Configs, Internal)
407 then
408 Panel.On (Wait => False);
409 end if;
410
411 -- Check if displays are still connected
412 for I in Config_Index loop
413 if Configs (I).Port /= Disabled then
414 Fill_Port_Config (Port_Cfg, Configs, I, Success);
415 if Success then
416 Connector_Info.Read_EDID
417 (Raw_EDID => Raw_EDID,
418 Port_Cfg => Port_Cfg,
419 Success => Success);
420 end if;
421 if not Success or else
422 not EDID.Has_Preferred_Mode (Raw_EDID) or else
423 Configs (I).Mode /= EDID.Preferred_Mode (Raw_EDID)
424 then
425 Configs (I).Port := Disabled;
426 end if;
427 end if;
428 end loop;
429
430 -- Add new displays as long as there is a free pipe config
431 for Port in Active_Port_Type loop
432 if Free_Config and then not Port_Configured (Configs, Port) then
433 Config_Idx := First_Free_Config;
434 Configs (Config_Idx).Port := Port;
435 Fill_Port_Config (Port_Cfg, Configs, Config_Idx, Success);
436
437 if Success then
438 -- Need power to probe port
439 if not Keep_Power and then To_Display_Type (Port) = DP then
440 Power_And_Clocks.Power_Up (Cur_Configs, Configs);
441 end if;
442 if not Keep_Power and then Port = Internal then
443 Panel.Wait_On;
444 end if;
445
446 Connector_Info.Read_EDID
447 (Raw_EDID => Raw_EDID,
448 Port_Cfg => Port_Cfg,
449 Success => Success);
450 end if;
451
Nico Huber393aa8a2016-10-21 14:18:53 +0200452 if Success and then
453 (EDID.Compatible_Display (Raw_EDID, Port_Cfg.Display) and
454 EDID.Has_Preferred_Mode (Raw_EDID))
455 then
Nico Huber83693c82016-10-08 22:17:55 +0200456 Configs (Config_Idx) := Config_Type'
457 (Port => Port,
458 Framebuffer => Configs (Config_Idx).Framebuffer,
459 Mode => EDID.Preferred_Mode (Raw_EDID));
460 else
461 Configs (Config_Idx).Port := Disabled;
462 end if;
463 end if;
464 end loop;
465
466 if not Keep_Power then
467 Power_And_Clocks.Power_Set_To (Cur_Configs);
468
469 if Config.Has_Internal_Display and then
470 not Port_Configured (Cur_Configs, Internal)
471 then
472 Panel.Off;
473 end if;
474 end if;
475 end Auto_Configure;
476
477 ----------------------------------------------------------------------------
478
479 procedure Update_Outputs (Configs : Configs_Type)
480 is
481 Did_Power_Up : Boolean := False;
482
483 HPD, HPD_Delay_Over, Success : Boolean;
484 Old_Config, New_Config : Config_Type;
485 Old_Configs : Configs_Type;
486 Port_Cfg : Port_Config;
487
488 procedure Check_HPD
489 (Port_Cfg : in Port_Config;
490 Port : in Port_Type;
491 Detected : out Boolean)
492 is
493 begin
494 HPD_Delay_Over := Time.Timed_Out (HPD_Delay (Port));
495 if HPD_Delay_Over then
496 Port_Detect.Hotplug_Detect (Port_Cfg, Detected);
497 HPD_Delay (Port) := Time.MS_From_Now (333);
498 else
499 Detected := False;
500 end if;
501 end Check_HPD;
502 begin
503 Old_Configs := Cur_Configs;
504
505 for I in Config_Index loop
506 HPD := False;
507
508 Old_Config := Cur_Configs (I);
509 New_Config := Configs (I);
510
511 Fill_Port_Config (Port_Cfg, Old_Configs, I, Success);
512 if Success then
513 Check_HPD (Port_Cfg, Old_Config.Port, HPD);
514 end if;
515
516 -- Connector changed?
517 if (Success and then HPD) or
518 Old_Config.Port /= New_Config.Port or
519 Old_Config.Mode /= New_Config.Mode
520 then
521 if Old_Config.Port /= Disabled then
522 if Success then
523 pragma Debug (Debug.New_Line);
524 pragma Debug (Debug.Put_Line
525 ("Disabling port " & Port_Names (Old_Config.Port)));
526
527 Connectors.Pre_Off (Port_Cfg);
528
529 Display_Controller.Off
530 (To_Controller (I), To_Head (I, Old_Config.Port));
531
532 Connectors.Post_Off (Port_Cfg);
533 end if;
534
535 -- Free PLL
536 PLLs.Free (Allocated_PLLs (I));
537
538 Cur_Configs (I).Port := Disabled;
539 end if;
540
541 if New_Config.Port /= Disabled then
542 Fill_Port_Config (Port_Cfg, Configs, I, Success);
543
Nico Huberc7a4fee2016-11-03 18:18:03 +0100544 Success := Success and then
545 Validate_Config (New_Config.Framebuffer, Port_Cfg);
546
Nico Huber83693c82016-10-08 22:17:55 +0200547 if Success and then Wait_For_HPD (New_Config.Port) then
548 Check_HPD (Port_Cfg, New_Config.Port, Success);
549 Wait_For_HPD (New_Config.Port) := not Success;
550 end if;
551
552 if Success then
553 pragma Debug (Debug.New_Line);
554 pragma Debug (Debug.Put_Line
555 ("Trying to enable port " & Port_Names (New_Config.Port)));
556
557 if not Did_Power_Up then
558 Power_And_Clocks.Power_Up (Old_Configs, Configs);
559 Did_Power_Up := True;
560 end if;
561
562 if Port_Cfg.Is_FDI then
563 Configure_FDI_Link (Port_Cfg, Success);
564 end if;
565 end if;
566
567 if Success then
568 Connector_Info.Preferred_Link_Setting
569 (Port_Cfg => Port_Cfg,
570 Success => Success);
571 end if;
572
573 while Success loop
574 pragma Loop_Invariant (New_Config.Port in Active_Port_Type);
575
576 PLLs.Alloc
577 (Port_Cfg => Port_Cfg,
578 PLL => Allocated_PLLs (I),
579 Success => Success);
580
581 if Success then
582 for Try in 1 .. 2 loop
583 pragma Loop_Invariant
584 (New_Config.Port in Active_Port_Type);
585
586 Connectors.Pre_On
587 (Port_Cfg => Port_Cfg,
588 PLL_Hint => PLLs.Register_Value
589 (Allocated_PLLs (I)),
590 Pipe_Hint => Display_Controller.Get_Pipe_Hint
591 (To_Head (I, New_Config.Port)),
592 Success => Success);
593
594 if Success then
595 Display_Controller.On
596 (Controller => To_Controller (I),
597 Head => To_Head (I, New_Config.Port),
598 Port_Cfg => Port_Cfg,
599 Framebuffer => New_Config.Framebuffer);
600
601 Connectors.Post_On
602 (Port_Cfg => Port_Cfg,
603 PLL_Hint => PLLs.Register_Value
604 (Allocated_PLLs (I)),
605 Success => Success);
606
607 if not Success then
608 Display_Controller.Off
609 (To_Controller (I),
610 To_Head (I, New_Config.Port));
611 Connectors.Post_Off (Port_Cfg);
612 end if;
613 end if;
614
615 exit when Success;
616 end loop;
617 exit when Success; -- connection established => stop loop
618
619 -- connection failed
620 PLLs.Free (Allocated_PLLs (I));
621 end if;
622
623 Connector_Info.Next_Link_Setting
624 (Port_Cfg => Port_Cfg,
625 Success => Success);
626 end loop;
627
628 if Success then
629 pragma Debug (Debug.Put_Line
630 ("Enabled port " & Port_Names (New_Config.Port)));
631 Cur_Configs (I) := New_Config;
632 DP_Links (I) := Port_Cfg.DP;
633 else
634 Wait_For_HPD (New_Config.Port) := True;
635 if New_Config.Port = Internal then
636 Panel.Off;
637 end if;
638 end if;
639 else
640 Cur_Configs (I) := New_Config;
641 end if;
642 elsif Old_Config.Framebuffer /= New_Config.Framebuffer and
643 Old_Config.Port /= Disabled
644 then
645 Display_Controller.Update_Offset
646 (Controller => To_Controller (I),
647 Framebuffer => New_Config.Framebuffer);
648 Cur_Configs (I) := New_Config;
649 end if;
650 end loop;
651
652 if Did_Power_Up then
653 Power_And_Clocks.Power_Down (Old_Configs, Configs, Cur_Configs);
654 end if;
655
656 end Update_Outputs;
657
658 ----------------------------------------------------------------------------
659
660 procedure Initialize
661 (MMIO_Base : in Word64 := 0;
662 Write_Delay : in Word64 := 0;
663 Success : out Boolean)
664 with
665 Refined_Global =>
666 (In_Out =>
667 (Config.Valid_Port_GPU,
668 Registers.Register_State, Port_IO.State),
669 Input =>
670 (Time.State),
671 Output =>
672 (Registers.Address_State,
673 PLLs.State, Panel.Panel_State,
674 Cur_Configs, Allocated_PLLs, DP_Links,
675 HPD_Delay, Wait_For_HPD, Initialized))
676 is
677 use type HW.Word64;
678
679 Now : constant Time.T := Time.Now;
680
681 procedure Check_Platform (Success : out Boolean)
682 is
683 Audio_VID_DID : Word32;
684 begin
685 case Config.CPU is
686 when Haswell .. Skylake =>
687 Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID);
688 when Ironlake .. Ivybridge =>
689 Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID);
690 end case;
691 Success :=
692 (case Config.CPU is
693 when Skylake => Audio_VID_DID = 16#8086_2809#,
694 when Broadwell => Audio_VID_DID = 16#8086_2808#,
695 when Haswell => Audio_VID_DID = 16#8086_2807#,
696 when Ivybridge |
697 Sandybridge => Audio_VID_DID = 16#8086_2806# or
698 Audio_VID_DID = 16#8086_2805#,
Nico Hubereeb5a392016-10-09 19:28:30 +0200699 when Ironlake => Audio_VID_DID = 16#0000_0000#);
Nico Huber83693c82016-10-08 22:17:55 +0200700 end Check_Platform;
701 begin
702 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
703 Reason => "Write_Delay is used for debugging only");
704
705 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
706
707 pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay));
708
709 Wait_For_HPD := HPD_Type'(others => False);
710 HPD_Delay := HPD_Delay_Type'(others => Now);
711 DP_Links := Links_Type'(others => HW.GFX.Default_DP);
712 Allocated_PLLs := (others => PLLs.Invalid);
713 Cur_Configs := Configs_Type'
714 (others => Config_Type'
715 (Port => Disabled,
716 Framebuffer => HW.GFX.Default_FB,
717 Mode => HW.GFX.Invalid_Mode));
718 Registers.Set_Register_Base
719 (if MMIO_Base /= 0 then
720 MMIO_Base
721 else
722 Config.Default_MMIO_Base);
723 PLLs.Initialize;
724
725 Check_Platform (Success);
726 if not Success then
727 pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH."));
728
729 Panel.Static_Init; -- for flow analysis
730
731 Initialized := False;
732 return;
733 end if;
734
735 Panel.Setup_PP_Sequencer;
736 Port_Detect.Initialize;
737
738 Power_And_Clocks.Pre_All_Off;
739
740 Legacy_VGA_Off;
741
742 Connectors.Pre_All_Off;
743 Display_Controller.All_Off;
744 Connectors.Post_All_Off;
745 PLLs.All_Off;
746
747 Power_And_Clocks.Post_All_Off;
748
749 -------------------- Now restart from a clean state ---------------------
750 Power_And_Clocks.Initialize;
751
Nico Huberf54d0962016-10-20 14:17:18 +0200752 Registers.Unset_And_Set_Mask
753 (Register => Registers.PCH_RAWCLK_FREQ,
754 Mask_Unset => PCH_RAWCLK_FREQ_MASK,
755 Mask_Set => PCH_RAWCLK_FREQ (Config.Default_RawClk_Freq));
756
Nico Huber83693c82016-10-08 22:17:55 +0200757 Initialized := True;
758
759 end Initialize;
760
761 function Is_Initialized return Boolean
762 with
763 Refined_Post => Is_Initialized'Result = Initialized
764 is
765 begin
766 return Initialized;
767 end Is_Initialized;
768
769 ----------------------------------------------------------------------------
770
771 procedure Write_GTT
772 (GTT_Page : GTT_Range;
773 Device_Address : GTT_Address_Type;
774 Valid : Boolean) is
775 begin
776 Registers.Write_GTT (GTT_Page, Device_Address, Valid);
777 end Write_GTT;
778
779 procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_FB : Word32)
780 is
781 FB_Size : constant Pos32 :=
782 FB.Stride * FB.Height * Pos32 (((FB.BPC * 4) / 8));
783 Phys_Addr : GTT_Address_Type := GTT_Address_Type (Phys_FB);
784 begin
785 for Idx in GTT_Range range 0 .. GTT_Range (((FB_Size + 4095) / 4096) - 1)
786 loop
787 Registers.Write_GTT
788 (GTT_Page => Idx,
789 Device_Address => Phys_Addr,
790 Valid => True);
791 Phys_Addr := Phys_Addr + 4096;
792 end loop;
793 end Setup_Default_GTT;
794
795 ----------------------------------------------------------------------------
796
797 procedure Dump_Configs (Configs : Configs_Type)
798 is
799 subtype Pipe_Name is String (1 .. 9);
800 type Pipe_Name_Array is array (Config_Index) of Pipe_Name;
801 Pipe_Names : constant Pipe_Name_Array :=
802 (Primary => "Primary ",
803 Secondary => "Secondary",
804 Tertiary => "Tertiary ");
805 begin
806 Debug.New_Line;
807 Debug.Put_Line ("CONFIG => ");
808 for Pipe in Config_Index loop
809 if Pipe = Config_Index'First then
810 Debug.Put (" (");
811 else
812 Debug.Put (" ");
813 end if;
814 Debug.Put_Line (Pipe_Names (Pipe) & " =>");
815 Debug.Put_Line
816 (" (Port => " & Port_Names (Configs (Pipe).Port) & ",");
817 Debug.Put_Line (" Framebuffer =>");
818 Debug.Put (" (Width => ");
819 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width);
820 Debug.Put_Line (",");
821 Debug.Put (" Height => ");
822 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height);
823 Debug.Put_Line (",");
824 Debug.Put (" Stride => ");
825 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride);
826 Debug.Put_Line (",");
827 Debug.Put (" Offset => ");
828 Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset);
829 Debug.Put_Line (",");
830 Debug.Put (" BPC => ");
831 Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC);
832 Debug.Put_Line ("),");
833 Debug.Put_Line (" Mode =>");
834 Debug.Put (" (Dotclock => ");
835 Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock);
836 Debug.Put_Line (",");
837 Debug.Put (" H_Visible => ");
838 Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible);
839 Debug.Put_Line (",");
840 Debug.Put (" H_Sync_Begin => ");
841 Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin);
842 Debug.Put_Line (",");
843 Debug.Put (" H_Sync_End => ");
844 Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End);
845 Debug.Put_Line (",");
846 Debug.Put (" H_Total => ");
847 Debug.Put_Int16 (Configs (Pipe).Mode.H_Total);
848 Debug.Put_Line (",");
849 Debug.Put (" V_Visible => ");
850 Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible);
851 Debug.Put_Line (",");
852 Debug.Put (" V_Sync_Begin => ");
853 Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin);
854 Debug.Put_Line (",");
855 Debug.Put (" V_Sync_End => ");
856 Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End);
857 Debug.Put_Line (",");
858 Debug.Put (" V_Total => ");
859 Debug.Put_Int16 (Configs (Pipe).Mode.V_Total);
860 Debug.Put_Line (",");
861 Debug.Put_Line (" H_Sync_Active_High => " &
862 (if Configs (Pipe).Mode.H_Sync_Active_High
863 then "True,"
864 else "False,"));
865 Debug.Put_Line (" V_Sync_Active_High => " &
866 (if Configs (Pipe).Mode.V_Sync_Active_High
867 then "True,"
868 else "False,"));
869 Debug.Put (" BPC => ");
870 Debug.Put_Int64 (Configs (Pipe).Mode.BPC);
871 if Pipe /= Config_Index'Last then
872 Debug.Put_Line (")),");
873 else
874 Debug.Put_Line (")));");
875 end if;
876 end loop;
877 end Dump_Configs;
878
879end HW.GFX.GMA;