blob: 416117b55ba0e55620a06e1b63879f1d96dc02d4 [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
180 procedure Fill_Port_Config
181 (Port_Cfg : out Port_Config;
182 Configs : in Configs_Type;
183 Idx : in Config_Index;
184 Success : out Boolean)
185 with Pre => True
186 is
187 begin
188 Success :=
189 Config.Supported_Pipe (Idx) and then
190 Config.Valid_Port (Configs (Idx).Port) and then
191 Configs (Idx).Port /= Disabled;
192
193 if Success then
194 declare
195 Port : constant Port_Type := Configs (Idx).Port;
196 Mode : constant Mode_Type := Configs (Idx).Mode;
197 Link : constant DP_Link := DP_Links (Idx);
198 begin
199 Port_Cfg := Port_Config'
200 (Port => To_GPU_Port (Configs, Idx),
201 PCH_Port => To_PCH_Port (Port),
202 Display => To_Display_Type (Port),
203 Mode => Mode,
204 Is_FDI => Config.FDI_Port (To_GPU_Port (Configs, Idx)),
205 FDI => Default_DP,
206 DP => Link);
207 if Port_Cfg.Mode.BPC = Auto_BPC then
208 Port_Cfg.Mode.BPC := Connector_Info.Default_BPC (Port_Cfg);
209 end if;
210 end;
211 else
212 Port_Cfg := Port_Config'
213 (Port => GPU_Port'First,
214 PCH_Port => PCH_Port'First,
215 Display => Display_Type'First,
216 Mode => Invalid_Mode,
217 Is_FDI => False,
218 FDI => Default_DP,
219 DP => Default_DP);
220 end if;
221 end Fill_Port_Config;
222
223 ----------------------------------------------------------------------------
224
225 function To_Controller
226 (Dsp_Config : Config_Index) return Display_Controller.Controller_Type
227 is
228 Result : Display_Controller.Controller_Type;
229 begin
230 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
231
232 case Dsp_Config is
233 when Primary =>
234 Result := Display_Controller.Controllers (Display_Controller.A);
235 when Secondary =>
236 Result := Display_Controller.Controllers (Display_Controller.B);
237 when Tertiary =>
238 Result := Display_Controller.Controllers (Display_Controller.C);
239 end case;
240 return Result;
241 end To_Controller;
242
243 ----------------------------------------------------------------------------
244
245 function To_Head
246 (N_Config : Config_Index;
247 Port : Active_Port_Type)
248 return Display_Controller.Head_Type
249 is
250 Result : Display_Controller.Head_Type;
251 begin
252 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
253
254 if Config.Has_EDP_Pipe and then Port = Internal then
255 Result := Display_Controller.Heads (Display_Controller.Head_EDP);
256 else
257 case N_Config is
258 when Primary =>
259 Result := Display_Controller.Heads (Display_Controller.Head_A);
260 when Secondary =>
261 Result := Display_Controller.Heads (Display_Controller.Head_B);
262 when Tertiary =>
263 Result := Display_Controller.Heads (Display_Controller.Head_C);
264 end case;
265 end if;
266 return Result;
267 end To_Head;
268
269 ----------------------------------------------------------------------------
270
271 procedure Legacy_VGA_Off
272 is
273 Reg8 : Word8;
274 begin
275 -- disable legacy VGA plane, taking over control now
276 Port_IO.OutB (VGA_SR_INDEX, VGA_SR01);
277 Port_IO.InB (Reg8, VGA_SR_DATA);
278 Port_IO.OutB (VGA_SR_DATA, Reg8 or 1 * 2 ** 5);
279 Time.U_Delay (100); -- PRM says 100us, Linux does 300
280 Registers.Set_Mask (Registers.VGACNTRL, 1 * 2 ** 31);
281 end Legacy_VGA_Off;
282
283 ----------------------------------------------------------------------------
284
285 function Port_Configured
286 (Configs : Configs_Type;
287 Port : Port_Type)
288 return Boolean
289 with
290 Global => null
291 is
292 begin
293 return Configs (Primary).Port = Port or
294 Configs (Secondary).Port = Port or
295 Configs (Tertiary).Port = Port;
296 end Port_Configured;
297
298 procedure Scan_Ports
299 (Configs : out Configs_Type;
300 Ports : in Port_List)
301 is
302 Raw_EDID : EDID.Raw_EDID_Data := (others => 16#00#);
303 Port_Idx : Port_List_Range := Port_List_Range'First;
304 Port_Cfg : Port_Config;
305 Success : Boolean := False;
306 begin
307 Configs := (Config_Index =>
308 (Port => Disabled,
309 Mode => Invalid_Mode,
310 Framebuffer => Default_FB));
311
312 for Config_Idx in Config_Index loop
313 while Ports (Port_Idx) /= Disabled loop
314 if not Port_Configured (Configs, Ports (Port_Idx)) then
315 Configs (Config_Idx).Port := Ports (Port_Idx);
316 Fill_Port_Config (Port_Cfg, Configs, Config_Idx, Success);
317
318 if Success then
319 -- May need power to probe port
320 if Port_Cfg.Display = DP then
321 Power_And_Clocks.Power_Up (Cur_Configs, Configs);
322 end if;
323 if Ports (Port_Idx) = Internal then
324 Panel.On;
325 end if;
326
327 Connector_Info.Read_EDID (Raw_EDID, Port_Cfg, Success);
328 end if;
329
330 if Success and then EDID.Has_Preferred_Mode (Raw_EDID) then
331 Configs (Config_Idx).Mode := EDID.Preferred_Mode (Raw_EDID);
332 else
333 Configs (Config_Idx).Port := Disabled;
334
335 if Ports (Port_Idx) = Internal and
336 not Port_Configured (Cur_Configs, Internal)
337 then
338 Panel.Off;
339 end if;
340 end if;
341 end if;
342
343 exit when Port_Idx = Port_List_Range'Last;
344 Port_Idx := Port_List_Range'Succ (Port_Idx);
345
346 exit when Success;
347 end loop;
348 end loop;
349
350 Power_And_Clocks.Power_Set_To (Cur_Configs);
351 end Scan_Ports;
352
353 procedure Auto_Configure
354 (Configs : in out Configs_Type;
355 Keep_Power : in Boolean := False)
356 is
357 Raw_EDID : EDID.Raw_EDID_Data := (others => 16#00#);
358 Success : Boolean;
359
360 Config_Idx : Config_Index;
361 Port_Cfg : Port_Config;
362
363 function Free_Config return Boolean
364 with
365 Pre => True
366 is
367 begin
368 return Port_Configured (Configs, Disabled);
369 end Free_Config;
370
371 function First_Free_Config return Config_Index
372 with
373 Pre => Free_Config
374 is
375 begin
376 return (if Configs (Primary).Port = Disabled then Primary else
377 (if Configs (Secondary).Port = Disabled then Secondary
378 else Tertiary));
379 end First_Free_Config;
380 begin
381 -- TODO: Only check ports with hot-plug event?
382
383 if Config.Has_Internal_Display and then
384 not Keep_Power and then
385 not Port_Configured (Cur_Configs, Internal)
386 then
387 Panel.On (Wait => False);
388 end if;
389
390 -- Check if displays are still connected
391 for I in Config_Index loop
392 if Configs (I).Port /= Disabled then
393 Fill_Port_Config (Port_Cfg, Configs, I, Success);
394 if Success then
395 Connector_Info.Read_EDID
396 (Raw_EDID => Raw_EDID,
397 Port_Cfg => Port_Cfg,
398 Success => Success);
399 end if;
400 if not Success or else
401 not EDID.Has_Preferred_Mode (Raw_EDID) or else
402 Configs (I).Mode /= EDID.Preferred_Mode (Raw_EDID)
403 then
404 Configs (I).Port := Disabled;
405 end if;
406 end if;
407 end loop;
408
409 -- Add new displays as long as there is a free pipe config
410 for Port in Active_Port_Type loop
411 if Free_Config and then not Port_Configured (Configs, Port) then
412 Config_Idx := First_Free_Config;
413 Configs (Config_Idx).Port := Port;
414 Fill_Port_Config (Port_Cfg, Configs, Config_Idx, Success);
415
416 if Success then
417 -- Need power to probe port
418 if not Keep_Power and then To_Display_Type (Port) = DP then
419 Power_And_Clocks.Power_Up (Cur_Configs, Configs);
420 end if;
421 if not Keep_Power and then Port = Internal then
422 Panel.Wait_On;
423 end if;
424
425 Connector_Info.Read_EDID
426 (Raw_EDID => Raw_EDID,
427 Port_Cfg => Port_Cfg,
428 Success => Success);
429 end if;
430
431 if Success and then EDID.Has_Preferred_Mode (Raw_EDID) then
432 Configs (Config_Idx) := Config_Type'
433 (Port => Port,
434 Framebuffer => Configs (Config_Idx).Framebuffer,
435 Mode => EDID.Preferred_Mode (Raw_EDID));
436 else
437 Configs (Config_Idx).Port := Disabled;
438 end if;
439 end if;
440 end loop;
441
442 if not Keep_Power then
443 Power_And_Clocks.Power_Set_To (Cur_Configs);
444
445 if Config.Has_Internal_Display and then
446 not Port_Configured (Cur_Configs, Internal)
447 then
448 Panel.Off;
449 end if;
450 end if;
451 end Auto_Configure;
452
453 ----------------------------------------------------------------------------
454
455 procedure Update_Outputs (Configs : Configs_Type)
456 is
457 Did_Power_Up : Boolean := False;
458
459 HPD, HPD_Delay_Over, Success : Boolean;
460 Old_Config, New_Config : Config_Type;
461 Old_Configs : Configs_Type;
462 Port_Cfg : Port_Config;
463
464 procedure Check_HPD
465 (Port_Cfg : in Port_Config;
466 Port : in Port_Type;
467 Detected : out Boolean)
468 is
469 begin
470 HPD_Delay_Over := Time.Timed_Out (HPD_Delay (Port));
471 if HPD_Delay_Over then
472 Port_Detect.Hotplug_Detect (Port_Cfg, Detected);
473 HPD_Delay (Port) := Time.MS_From_Now (333);
474 else
475 Detected := False;
476 end if;
477 end Check_HPD;
478 begin
479 Old_Configs := Cur_Configs;
480
481 for I in Config_Index loop
482 HPD := False;
483
484 Old_Config := Cur_Configs (I);
485 New_Config := Configs (I);
486
487 Fill_Port_Config (Port_Cfg, Old_Configs, I, Success);
488 if Success then
489 Check_HPD (Port_Cfg, Old_Config.Port, HPD);
490 end if;
491
492 -- Connector changed?
493 if (Success and then HPD) or
494 Old_Config.Port /= New_Config.Port or
495 Old_Config.Mode /= New_Config.Mode
496 then
497 if Old_Config.Port /= Disabled then
498 if Success then
499 pragma Debug (Debug.New_Line);
500 pragma Debug (Debug.Put_Line
501 ("Disabling port " & Port_Names (Old_Config.Port)));
502
503 Connectors.Pre_Off (Port_Cfg);
504
505 Display_Controller.Off
506 (To_Controller (I), To_Head (I, Old_Config.Port));
507
508 Connectors.Post_Off (Port_Cfg);
509 end if;
510
511 -- Free PLL
512 PLLs.Free (Allocated_PLLs (I));
513
514 Cur_Configs (I).Port := Disabled;
515 end if;
516
517 if New_Config.Port /= Disabled then
518 Fill_Port_Config (Port_Cfg, Configs, I, Success);
519
520 if Success and then Wait_For_HPD (New_Config.Port) then
521 Check_HPD (Port_Cfg, New_Config.Port, Success);
522 Wait_For_HPD (New_Config.Port) := not Success;
523 end if;
524
525 if Success then
526 pragma Debug (Debug.New_Line);
527 pragma Debug (Debug.Put_Line
528 ("Trying to enable port " & Port_Names (New_Config.Port)));
529
530 if not Did_Power_Up then
531 Power_And_Clocks.Power_Up (Old_Configs, Configs);
532 Did_Power_Up := True;
533 end if;
534
535 if Port_Cfg.Is_FDI then
536 Configure_FDI_Link (Port_Cfg, Success);
537 end if;
538 end if;
539
540 if Success then
541 Connector_Info.Preferred_Link_Setting
542 (Port_Cfg => Port_Cfg,
543 Success => Success);
544 end if;
545
546 while Success loop
547 pragma Loop_Invariant (New_Config.Port in Active_Port_Type);
548
549 PLLs.Alloc
550 (Port_Cfg => Port_Cfg,
551 PLL => Allocated_PLLs (I),
552 Success => Success);
553
554 if Success then
555 for Try in 1 .. 2 loop
556 pragma Loop_Invariant
557 (New_Config.Port in Active_Port_Type);
558
559 Connectors.Pre_On
560 (Port_Cfg => Port_Cfg,
561 PLL_Hint => PLLs.Register_Value
562 (Allocated_PLLs (I)),
563 Pipe_Hint => Display_Controller.Get_Pipe_Hint
564 (To_Head (I, New_Config.Port)),
565 Success => Success);
566
567 if Success then
568 Display_Controller.On
569 (Controller => To_Controller (I),
570 Head => To_Head (I, New_Config.Port),
571 Port_Cfg => Port_Cfg,
572 Framebuffer => New_Config.Framebuffer);
573
574 Connectors.Post_On
575 (Port_Cfg => Port_Cfg,
576 PLL_Hint => PLLs.Register_Value
577 (Allocated_PLLs (I)),
578 Success => Success);
579
580 if not Success then
581 Display_Controller.Off
582 (To_Controller (I),
583 To_Head (I, New_Config.Port));
584 Connectors.Post_Off (Port_Cfg);
585 end if;
586 end if;
587
588 exit when Success;
589 end loop;
590 exit when Success; -- connection established => stop loop
591
592 -- connection failed
593 PLLs.Free (Allocated_PLLs (I));
594 end if;
595
596 Connector_Info.Next_Link_Setting
597 (Port_Cfg => Port_Cfg,
598 Success => Success);
599 end loop;
600
601 if Success then
602 pragma Debug (Debug.Put_Line
603 ("Enabled port " & Port_Names (New_Config.Port)));
604 Cur_Configs (I) := New_Config;
605 DP_Links (I) := Port_Cfg.DP;
606 else
607 Wait_For_HPD (New_Config.Port) := True;
608 if New_Config.Port = Internal then
609 Panel.Off;
610 end if;
611 end if;
612 else
613 Cur_Configs (I) := New_Config;
614 end if;
615 elsif Old_Config.Framebuffer /= New_Config.Framebuffer and
616 Old_Config.Port /= Disabled
617 then
618 Display_Controller.Update_Offset
619 (Controller => To_Controller (I),
620 Framebuffer => New_Config.Framebuffer);
621 Cur_Configs (I) := New_Config;
622 end if;
623 end loop;
624
625 if Did_Power_Up then
626 Power_And_Clocks.Power_Down (Old_Configs, Configs, Cur_Configs);
627 end if;
628
629 end Update_Outputs;
630
631 ----------------------------------------------------------------------------
632
633 procedure Initialize
634 (MMIO_Base : in Word64 := 0;
635 Write_Delay : in Word64 := 0;
636 Success : out Boolean)
637 with
638 Refined_Global =>
639 (In_Out =>
640 (Config.Valid_Port_GPU,
641 Registers.Register_State, Port_IO.State),
642 Input =>
643 (Time.State),
644 Output =>
645 (Registers.Address_State,
646 PLLs.State, Panel.Panel_State,
647 Cur_Configs, Allocated_PLLs, DP_Links,
648 HPD_Delay, Wait_For_HPD, Initialized))
649 is
650 use type HW.Word64;
651
652 Now : constant Time.T := Time.Now;
653
654 procedure Check_Platform (Success : out Boolean)
655 is
656 Audio_VID_DID : Word32;
657 begin
658 case Config.CPU is
659 when Haswell .. Skylake =>
660 Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID);
661 when Ironlake .. Ivybridge =>
662 Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID);
663 end case;
664 Success :=
665 (case Config.CPU is
666 when Skylake => Audio_VID_DID = 16#8086_2809#,
667 when Broadwell => Audio_VID_DID = 16#8086_2808#,
668 when Haswell => Audio_VID_DID = 16#8086_2807#,
669 when Ivybridge |
670 Sandybridge => Audio_VID_DID = 16#8086_2806# or
671 Audio_VID_DID = 16#8086_2805#,
Nico Hubereeb5a392016-10-09 19:28:30 +0200672 when Ironlake => Audio_VID_DID = 16#0000_0000#);
Nico Huber83693c82016-10-08 22:17:55 +0200673 end Check_Platform;
674 begin
675 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
676 Reason => "Write_Delay is used for debugging only");
677
678 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
679
680 pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay));
681
682 Wait_For_HPD := HPD_Type'(others => False);
683 HPD_Delay := HPD_Delay_Type'(others => Now);
684 DP_Links := Links_Type'(others => HW.GFX.Default_DP);
685 Allocated_PLLs := (others => PLLs.Invalid);
686 Cur_Configs := Configs_Type'
687 (others => Config_Type'
688 (Port => Disabled,
689 Framebuffer => HW.GFX.Default_FB,
690 Mode => HW.GFX.Invalid_Mode));
691 Registers.Set_Register_Base
692 (if MMIO_Base /= 0 then
693 MMIO_Base
694 else
695 Config.Default_MMIO_Base);
696 PLLs.Initialize;
697
698 Check_Platform (Success);
699 if not Success then
700 pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH."));
701
702 Panel.Static_Init; -- for flow analysis
703
704 Initialized := False;
705 return;
706 end if;
707
708 Panel.Setup_PP_Sequencer;
709 Port_Detect.Initialize;
710
711 Power_And_Clocks.Pre_All_Off;
712
713 Legacy_VGA_Off;
714
715 Connectors.Pre_All_Off;
716 Display_Controller.All_Off;
717 Connectors.Post_All_Off;
718 PLLs.All_Off;
719
720 Power_And_Clocks.Post_All_Off;
721
722 -------------------- Now restart from a clean state ---------------------
723 Power_And_Clocks.Initialize;
724
Nico Huberf54d0962016-10-20 14:17:18 +0200725 Registers.Unset_And_Set_Mask
726 (Register => Registers.PCH_RAWCLK_FREQ,
727 Mask_Unset => PCH_RAWCLK_FREQ_MASK,
728 Mask_Set => PCH_RAWCLK_FREQ (Config.Default_RawClk_Freq));
729
Nico Huber83693c82016-10-08 22:17:55 +0200730 Initialized := True;
731
732 end Initialize;
733
734 function Is_Initialized return Boolean
735 with
736 Refined_Post => Is_Initialized'Result = Initialized
737 is
738 begin
739 return Initialized;
740 end Is_Initialized;
741
742 ----------------------------------------------------------------------------
743
744 procedure Write_GTT
745 (GTT_Page : GTT_Range;
746 Device_Address : GTT_Address_Type;
747 Valid : Boolean) is
748 begin
749 Registers.Write_GTT (GTT_Page, Device_Address, Valid);
750 end Write_GTT;
751
752 procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_FB : Word32)
753 is
754 FB_Size : constant Pos32 :=
755 FB.Stride * FB.Height * Pos32 (((FB.BPC * 4) / 8));
756 Phys_Addr : GTT_Address_Type := GTT_Address_Type (Phys_FB);
757 begin
758 for Idx in GTT_Range range 0 .. GTT_Range (((FB_Size + 4095) / 4096) - 1)
759 loop
760 Registers.Write_GTT
761 (GTT_Page => Idx,
762 Device_Address => Phys_Addr,
763 Valid => True);
764 Phys_Addr := Phys_Addr + 4096;
765 end loop;
766 end Setup_Default_GTT;
767
768 ----------------------------------------------------------------------------
769
770 procedure Dump_Configs (Configs : Configs_Type)
771 is
772 subtype Pipe_Name is String (1 .. 9);
773 type Pipe_Name_Array is array (Config_Index) of Pipe_Name;
774 Pipe_Names : constant Pipe_Name_Array :=
775 (Primary => "Primary ",
776 Secondary => "Secondary",
777 Tertiary => "Tertiary ");
778 begin
779 Debug.New_Line;
780 Debug.Put_Line ("CONFIG => ");
781 for Pipe in Config_Index loop
782 if Pipe = Config_Index'First then
783 Debug.Put (" (");
784 else
785 Debug.Put (" ");
786 end if;
787 Debug.Put_Line (Pipe_Names (Pipe) & " =>");
788 Debug.Put_Line
789 (" (Port => " & Port_Names (Configs (Pipe).Port) & ",");
790 Debug.Put_Line (" Framebuffer =>");
791 Debug.Put (" (Width => ");
792 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width);
793 Debug.Put_Line (",");
794 Debug.Put (" Height => ");
795 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height);
796 Debug.Put_Line (",");
797 Debug.Put (" Stride => ");
798 Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride);
799 Debug.Put_Line (",");
800 Debug.Put (" Offset => ");
801 Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset);
802 Debug.Put_Line (",");
803 Debug.Put (" BPC => ");
804 Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC);
805 Debug.Put_Line ("),");
806 Debug.Put_Line (" Mode =>");
807 Debug.Put (" (Dotclock => ");
808 Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock);
809 Debug.Put_Line (",");
810 Debug.Put (" H_Visible => ");
811 Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible);
812 Debug.Put_Line (",");
813 Debug.Put (" H_Sync_Begin => ");
814 Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin);
815 Debug.Put_Line (",");
816 Debug.Put (" H_Sync_End => ");
817 Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End);
818 Debug.Put_Line (",");
819 Debug.Put (" H_Total => ");
820 Debug.Put_Int16 (Configs (Pipe).Mode.H_Total);
821 Debug.Put_Line (",");
822 Debug.Put (" V_Visible => ");
823 Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible);
824 Debug.Put_Line (",");
825 Debug.Put (" V_Sync_Begin => ");
826 Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin);
827 Debug.Put_Line (",");
828 Debug.Put (" V_Sync_End => ");
829 Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End);
830 Debug.Put_Line (",");
831 Debug.Put (" V_Total => ");
832 Debug.Put_Int16 (Configs (Pipe).Mode.V_Total);
833 Debug.Put_Line (",");
834 Debug.Put_Line (" H_Sync_Active_High => " &
835 (if Configs (Pipe).Mode.H_Sync_Active_High
836 then "True,"
837 else "False,"));
838 Debug.Put_Line (" V_Sync_Active_High => " &
839 (if Configs (Pipe).Mode.V_Sync_Active_High
840 then "True,"
841 else "False,"));
842 Debug.Put (" BPC => ");
843 Debug.Put_Int64 (Configs (Pipe).Mode.BPC);
844 if Pipe /= Config_Index'Last then
845 Debug.Put_Line (")),");
846 else
847 Debug.Put_Line (")));");
848 end if;
849 end loop;
850 end Dump_Configs;
851
852end HW.GFX.GMA;