blob: a91c83b83c592dc1a7a853068909e677d7407dc9 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
Nico Huber247adf32017-06-12 14:39:11 +02002-- Copyright (C) 2015-2017 secunet Security Networks AG
Nico Huber194e57e2017-07-15 21:15:46 +02003-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
Nico Huber83693c82016-10-08 22:17:55 +02004--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02007-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02009--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-- GNU General Public License for more details.
14--
15
Nico Huber194e57e2017-07-15 21:15:46 +020016with HW.Config;
Nico Huber83693c82016-10-08 22:17:55 +020017with HW.Time;
18with HW.Port_IO;
19
20package HW.GFX.GMA
21with
22 Abstract_State =>
23 (State,
24 Init_State,
25 Config_State,
26 (Device_State with External)),
27 Initializes =>
28 (Init_State,
29 Config_State)
30is
31
32 type CPU_Type is
33 (Ironlake,
34 Sandybridge,
35 Ivybridge,
36 Haswell,
37 Broadwell,
Nico Huber21da5742017-01-20 14:00:53 +010038 Broxton,
Nico Huber83693c82016-10-08 22:17:55 +020039 Skylake);
40
41 type CPU_Variant is (Normal, ULT);
42
43 type Port_Type is
44 (Disabled,
45 Internal,
46 DP1,
47 DP2,
48 DP3,
Nico Huber0d454cd2016-11-21 13:33:43 +010049 HDMI1, -- or DVI
50 HDMI2, -- or DVI
51 HDMI3, -- or DVI
Nico Huber83693c82016-10-08 22:17:55 +020052 Analog);
Nico Huber83693c82016-10-08 22:17:55 +020053
Nico Huber99f10f32016-11-20 00:34:05 +010054 type Pipe_Config is record
Nico Huber83693c82016-10-08 22:17:55 +020055 Port : Port_Type;
56 Framebuffer : Framebuffer_Type;
57 Mode : Mode_Type;
58 end record;
Nico Huber99f10f32016-11-20 00:34:05 +010059 type Pipe_Index is (Primary, Secondary, Tertiary);
60 type Pipe_Configs is array (Pipe_Index) of Pipe_Config;
Nico Huber83693c82016-10-08 22:17:55 +020061
Nico Huber3675db52016-11-04 16:27:29 +010062 -- Special framebuffer offset to indicate legacy VGA plane.
63 -- Only valid on primary pipe.
64 VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#;
65
Nico Huberbebca132017-06-12 23:04:46 +020066 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
67 Reason => "Write_Delay is used for debugging only");
Nico Huber83693c82016-10-08 22:17:55 +020068 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +020069 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +010070 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +020071 Success : out Boolean)
72 with
73 Global =>
74 (In_Out => (Config_State, Device_State, Port_IO.State),
75 Output => (State, Init_State),
76 Input => (Time.State)),
77 Post => Success = Is_Initialized;
78 function Is_Initialized return Boolean
79 with
80 Global => (Input => Init_State);
Nico Huberbebca132017-06-12 23:04:46 +020081 pragma Warnings (GNATprove, On, "unused variable ""Write_Delay""");
Nico Huber83693c82016-10-08 22:17:55 +020082
Nico Huber99f10f32016-11-20 00:34:05 +010083 procedure Update_Outputs (Configs : Pipe_Configs);
Nico Huber83693c82016-10-08 22:17:55 +020084
85 pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect",
86 Reason => "It's only used for debugging");
Nico Huber99f10f32016-11-20 00:34:05 +010087 procedure Dump_Configs (Configs : Pipe_Configs);
Nico Huber83693c82016-10-08 22:17:55 +020088
Nico Huber194e57e2017-07-15 21:15:46 +020089 GTT_Page_Size : constant := 4096;
Nico Huber83693c82016-10-08 22:17:55 +020090 type GTT_Address_Type is mod 2 ** 39;
Nico Huber194e57e2017-07-15 21:15:46 +020091 subtype GTT_Range is Natural range 0 .. 16#8_0000# - 1;
Nico Huber83693c82016-10-08 22:17:55 +020092 procedure Write_GTT
93 (GTT_Page : GTT_Range;
94 Device_Address : GTT_Address_Type;
95 Valid : Boolean);
96
Nico Huber194e57e2017-07-15 21:15:46 +020097 ----------------------------------------------------------------------------
98
99 function FB_First_Page (FB : Framebuffer_Type) return Natural is
100 (Natural (FB.Offset / GTT_Page_Size));
101 function FB_Pages (FB : Framebuffer_Type) return Natural is
102 (Natural (Div_Round_Up (FB_Size (FB), GTT_Page_Size)));
103 function FB_Last_Page (FB : Framebuffer_Type) return Natural is
104 (FB_First_Page (FB) + FB_Pages (FB) - 1);
105
106 -- Check basics and that it fits in GTT
107 function Valid_FB (FB : Framebuffer_Type) return Boolean is
108 (FB.Width <= FB.Stride and FB_Last_Page (FB) <= GTT_Range'Last);
109
110 -- Also check that we don't overflow the GTT's 39-bit space
111 -- (always true with a 32-bit base)
112 function Valid_Phys_FB (FB : Framebuffer_Type; Phys_Base : Word32)
113 return Boolean is
114 (Valid_FB (FB) and
115 Int64 (Phys_Base) + Int64 (FB.Offset) + Int64 (FB_Size (FB)) <=
116 Int64 (GTT_Address_Type'Last))
117 with
118 Ghost;
119
120 procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_Base : Word32)
121 with
122 Pre => Is_Initialized and Valid_Phys_FB (FB, Phys_Base);
Nico Huber83693c82016-10-08 22:17:55 +0200123
124private
125
Nico Huber8c45bcf2016-11-20 17:30:57 +0100126 ----------------------------------------------------------------------------
127 -- State tracking for the currently configured pipes
128
129 Cur_Configs : Pipe_Configs with Part_Of => State;
130
131 ----------------------------------------------------------------------------
132 -- Internal representation of a single pipe's configuration
133
134 subtype Active_Port_Type is Port_Type
135 range Port_Type'Succ (Disabled) .. Port_Type'Last;
136
Nico Huber83693c82016-10-08 22:17:55 +0200137 type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E);
138
139 subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
140
141 type PCH_Port is
142 (PCH_DAC, PCH_LVDS,
143 PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D,
144 PCH_DP_B, PCH_DP_C, PCH_DP_D);
145
146 subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D;
147 subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D;
148
Nico Huber83693c82016-10-08 22:17:55 +0200149 type Port_Config is
150 record
151 Port : GPU_Port;
152 PCH_Port : GMA.PCH_Port;
153 Display : Display_Type;
154 Mode : Mode_Type;
155 Is_FDI : Boolean;
156 FDI : DP_Link;
157 DP : DP_Link;
158 end record;
159
160 type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training);
161
162 ----------------------------------------------------------------------------
163
164 type DP_Port is (DP_A, DP_B, DP_C, DP_D);
165
Nico Huber247adf32017-06-12 14:39:11 +0200166 ----------------------------------------------------------------------------
167
168 subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
169
Nico Huber83693c82016-10-08 22:17:55 +0200170end HW.GFX.GMA;