blob: 410f4111b6f5678adde37d56d1caa4c1adb1efc0 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
Nico Huber3d06de82018-05-29 01:35:04 +02002-- Copyright (C) 2015-2018 secunet Security Networks AG
Nico Huber194e57e2017-07-15 21:15:46 +02003-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
Nico Huber83693c82016-10-08 22:17:55 +02004--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02007-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02009--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-- GNU General Public License for more details.
14--
15
Nico Huber194e57e2017-07-15 21:15:46 +020016with HW.Config;
Nico Huber83693c82016-10-08 22:17:55 +020017with HW.Time;
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
Nico Hubera02b2c62018-01-09 15:58:34 +010032 GTT_Page_Size : constant := 4096;
33 type GTT_Address_Type is mod 2 ** 39;
34 subtype GTT_Range is Natural range 0 .. 16#8_0000# - 1;
35 GTT_Rotation_Offset : constant GTT_Range := GTT_Range'Last / 2 + 1;
36
Nico Huber83693c82016-10-08 22:17:55 +020037 type CPU_Type is
Arthur Heymans73ea0322018-03-28 17:17:07 +020038 (G45,
39 Ironlake,
Nico Huber83693c82016-10-08 22:17:55 +020040 Sandybridge,
41 Ivybridge,
42 Haswell,
43 Broadwell,
Nico Huber21da5742017-01-20 14:00:53 +010044 Broxton,
Nico Huber83693c82016-10-08 22:17:55 +020045 Skylake);
46
47 type CPU_Variant is (Normal, ULT);
48
49 type Port_Type is
50 (Disabled,
51 Internal,
52 DP1,
53 DP2,
54 DP3,
Nico Huber0d454cd2016-11-21 13:33:43 +010055 HDMI1, -- or DVI
56 HDMI2, -- or DVI
57 HDMI3, -- or DVI
Nico Huber83693c82016-10-08 22:17:55 +020058 Analog);
Nico Huber83693c82016-10-08 22:17:55 +020059
Nico Hubera02b2c62018-01-09 15:58:34 +010060 type Cursor_Mode is (No_Cursor, ARGB_Cursor);
61 type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
62 Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256);
63
64 subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2;
65
66 type Cursor_Type is record
67 Mode : Cursor_Mode;
68 Size : Cursor_Size;
69 Center_X : Cursor_Pos;
70 Center_Y : Cursor_Pos;
71 GTT_Offset : GTT_Range;
72 end record;
73 Default_Cursor : constant Cursor_Type :=
74 (Mode => No_Cursor,
75 Size => Cursor_Size'First,
76 Center_X => 0,
77 Center_Y => 0,
78 GTT_Offset => 0);
79
Nico Huber99f10f32016-11-20 00:34:05 +010080 type Pipe_Config is record
Nico Huber83693c82016-10-08 22:17:55 +020081 Port : Port_Type;
82 Framebuffer : Framebuffer_Type;
Nico Hubera02b2c62018-01-09 15:58:34 +010083 Cursor : Cursor_Type;
Nico Huber83693c82016-10-08 22:17:55 +020084 Mode : Mode_Type;
85 end record;
Nico Huber99f10f32016-11-20 00:34:05 +010086 type Pipe_Index is (Primary, Secondary, Tertiary);
87 type Pipe_Configs is array (Pipe_Index) of Pipe_Config;
Nico Huber83693c82016-10-08 22:17:55 +020088
Nico Huber3675db52016-11-04 16:27:29 +010089 -- Special framebuffer offset to indicate legacy VGA plane.
90 -- Only valid on primary pipe.
91 VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#;
92
Nico Huberbebca132017-06-12 23:04:46 +020093 pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""",
94 Reason => "Write_Delay is used for debugging only");
Nico Huber83693c82016-10-08 22:17:55 +020095 procedure Initialize
Nico Huber2b6f6992017-07-09 18:11:34 +020096 (Write_Delay : in Word64 := 0;
Nico Huber793a8d42016-11-21 18:57:03 +010097 Clean_State : in Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +020098 Success : out Boolean)
99 with
100 Global =>
101 (In_Out => (Config_State, Device_State, Port_IO.State),
102 Output => (State, Init_State),
103 Input => (Time.State)),
104 Post => Success = Is_Initialized;
105 function Is_Initialized return Boolean
106 with
107 Global => (Input => Init_State);
Nico Huberbebca132017-06-12 23:04:46 +0200108 pragma Warnings (GNATprove, On, "unused variable ""Write_Delay""");
Nico Huber83693c82016-10-08 22:17:55 +0200109
Nico Huber42fb2d02017-09-01 17:01:51 +0200110 pragma Warnings (GNATprove, Off, "subprogram ""Power_Up_VGA"" has no effect",
111 Reason => "Effect depends on the platform compiled for");
112 procedure Power_Up_VGA
113 with
114 Pre => Is_Initialized;
115
Nico Huber99f10f32016-11-20 00:34:05 +0100116 procedure Update_Outputs (Configs : Pipe_Configs);
Nico Huber83693c82016-10-08 22:17:55 +0200117
Nico Huber15ffc4f2018-01-11 14:44:43 +0100118 procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type);
119 procedure Place_Cursor
120 (Pipe : Pipe_Index;
121 X : Cursor_Pos;
122 Y : Cursor_Pos);
123 procedure Move_Cursor
124 (Pipe : Pipe_Index;
125 X : Cursor_Pos;
126 Y : Cursor_Pos);
127
Nico Huber83693c82016-10-08 22:17:55 +0200128 pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect",
129 Reason => "It's only used for debugging");
Nico Huber99f10f32016-11-20 00:34:05 +0100130 procedure Dump_Configs (Configs : Pipe_Configs);
Nico Huber83693c82016-10-08 22:17:55 +0200131
Nico Huber83693c82016-10-08 22:17:55 +0200132 procedure Write_GTT
133 (GTT_Page : GTT_Range;
134 Device_Address : GTT_Address_Type;
135 Valid : Boolean);
136
Nico Huber5374c3a2017-07-15 21:48:06 +0200137 procedure Setup_Default_FB
138 (FB : in Framebuffer_Type;
139 Clear : in Boolean := True;
140 Success : out Boolean)
Nico Huber194e57e2017-07-15 21:15:46 +0200141 with
Nico Huber5374c3a2017-07-15 21:48:06 +0200142 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
Nico Huber83693c82016-10-08 22:17:55 +0200143
Nico Huberc3f66f62017-07-16 21:39:54 +0200144 procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type)
145 with
146 Pre => Is_Initialized and HW.Config.Dynamic_MMIO;
147
Nico Huber83693c82016-10-08 22:17:55 +0200148private
149
Nico Huber3299ad52018-06-02 16:53:39 +0200150 -- For the default framebuffer setup (see below) with 90 degree rotations,
151 -- we expect the offset which is used for the final scanout to be above
152 -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for
153 -- the physical memory location and aperture mapping.
154 function Phys_Offset (FB : Framebuffer_Type) return Word32 is
155 (if Rotation_90 (FB)
156 then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size
157 else FB.Offset);
158
Nico Huber8c45bcf2016-11-20 17:30:57 +0100159 ----------------------------------------------------------------------------
160 -- State tracking for the currently configured pipes
161
162 Cur_Configs : Pipe_Configs with Part_Of => State;
163
Nico Huber3d06de82018-05-29 01:35:04 +0200164 function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is
165 (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
166
Nico Huberb217ece2018-06-02 16:56:35 +0200167 function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is
168 (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode));
169
Nico Huber8c45bcf2016-11-20 17:30:57 +0100170 ----------------------------------------------------------------------------
171 -- Internal representation of a single pipe's configuration
172
173 subtype Active_Port_Type is Port_Type
174 range Port_Type'Succ (Disabled) .. Port_Type'Last;
175
Arthur Heymans5d08a932018-03-28 17:00:18 +0200176 type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA);
Nico Huber83693c82016-10-08 22:17:55 +0200177
178 subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E;
Arthur Heymans5d08a932018-03-28 17:00:18 +0200179 subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D;
180 subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C;
Nico Huber83693c82016-10-08 22:17:55 +0200181
182 type PCH_Port is
183 (PCH_DAC, PCH_LVDS,
184 PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D,
185 PCH_DP_B, PCH_DP_C, PCH_DP_D);
186
187 subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D;
188 subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D;
189
Nico Huber83693c82016-10-08 22:17:55 +0200190 type Port_Config is
191 record
192 Port : GPU_Port;
193 PCH_Port : GMA.PCH_Port;
194 Display : Display_Type;
195 Mode : Mode_Type;
196 Is_FDI : Boolean;
197 FDI : DP_Link;
198 DP : DP_Link;
199 end record;
200
201 type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training);
202
203 ----------------------------------------------------------------------------
204
205 type DP_Port is (DP_A, DP_B, DP_C, DP_D);
206
Nico Huber247adf32017-06-12 14:39:11 +0200207 ----------------------------------------------------------------------------
208
209 subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11;
210
Nico Huber0164b022017-08-24 15:12:51 +0200211 ----------------------------------------------------------------------------
212
213 Tile_Width : constant array (Tiling_Type) of Pos32 :=
214 (Linear => 16, X_Tiled => 128, Y_Tiled => 32);
Nico Huber9b479412017-08-27 11:55:56 +0200215 Tile_Rows : constant array (Tiling_Type) of Pos32 :=
216 (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
Nico Huber0164b022017-08-24 15:12:51 +0200217
Nico Huber5ef4d602017-12-13 13:56:47 +0100218 function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural
219 is (Natural (Div_Round_Up
220 (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4)));
Nico Huber0164b022017-08-24 15:12:51 +0200221
222 function Valid_Stride (FB : Framebuffer_Type) return Boolean is
Nico Huber5ef4d602017-12-13 13:56:47 +0100223 (FB.Width + FB.Start_X <= FB.Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200224 Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and
Nico Huber5ef4d602017-12-13 13:56:47 +0100225 FB.Height + FB.Start_Y <= FB.V_Stride and
Nico Huber9b479412017-08-27 11:55:56 +0200226 FB.V_Stride mod Tile_Rows (FB.Tiling) = 0);
Nico Huber0164b022017-08-24 15:12:51 +0200227
Nico Huber83693c82016-10-08 22:17:55 +0200228end HW.GFX.GMA;