| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 2 | -- Copyright (C) 2015-2018 secunet Security Networks AG |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 3 | -- Copyright (C) 2017 Nico Huber <nico.h@gmx.de> |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 4 | -- |
| 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 Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 7 | -- the Free Software Foundation; either version 2 of the License, or |
| 8 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 9 | -- |
| 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 Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 16 | with HW.Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 17 | with HW.Time; |
| 18 | with HW.Port_IO; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 19 | with HW.GFX.Framebuffer_Filler; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 20 | |
| 21 | package HW.GFX.GMA |
| 22 | with |
| 23 | Abstract_State => |
| 24 | (State, |
| 25 | Init_State, |
| 26 | Config_State, |
| 27 | (Device_State with External)), |
| 28 | Initializes => |
| 29 | (Init_State, |
| 30 | Config_State) |
| 31 | is |
| 32 | |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 33 | GTT_Page_Size : constant := 4096; |
| 34 | type GTT_Address_Type is mod 2 ** 39; |
| 35 | subtype GTT_Range is Natural range 0 .. 16#8_0000# - 1; |
| 36 | GTT_Rotation_Offset : constant GTT_Range := GTT_Range'Last / 2 + 1; |
| 37 | |
| Nico Huber | 6621a14 | 2018-06-07 23:56:54 +0200 | [diff] [blame] | 38 | type Generation is (G45, Ironlake, Haswell, Broxton, Skylake); |
| 39 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 40 | type CPU_Type is |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 41 | (G45, |
| 42 | Ironlake, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 43 | Sandybridge, |
| 44 | Ivybridge, |
| 45 | Haswell, |
| 46 | Broadwell, |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 47 | Broxton, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 48 | Skylake); |
| 49 | |
| 50 | type CPU_Variant is (Normal, ULT); |
| 51 | |
| 52 | type Port_Type is |
| 53 | (Disabled, |
| 54 | Internal, |
| 55 | DP1, |
| 56 | DP2, |
| 57 | DP3, |
| Nico Huber | 0d454cd | 2016-11-21 13:33:43 +0100 | [diff] [blame] | 58 | HDMI1, -- or DVI |
| 59 | HDMI2, -- or DVI |
| 60 | HDMI3, -- or DVI |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 61 | Analog); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 62 | |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 63 | type Cursor_Mode is (No_Cursor, ARGB_Cursor); |
| 64 | type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256); |
| 65 | Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256); |
| 66 | |
| 67 | subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2; |
| 68 | |
| 69 | type Cursor_Type is record |
| 70 | Mode : Cursor_Mode; |
| 71 | Size : Cursor_Size; |
| 72 | Center_X : Cursor_Pos; |
| 73 | Center_Y : Cursor_Pos; |
| 74 | GTT_Offset : GTT_Range; |
| 75 | end record; |
| 76 | Default_Cursor : constant Cursor_Type := |
| 77 | (Mode => No_Cursor, |
| 78 | Size => Cursor_Size'First, |
| 79 | Center_X => 0, |
| 80 | Center_Y => 0, |
| 81 | GTT_Offset => 0); |
| 82 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 83 | type Pipe_Config is record |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 84 | Port : Port_Type; |
| 85 | Framebuffer : Framebuffer_Type; |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 86 | Cursor : Cursor_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 87 | Mode : Mode_Type; |
| 88 | end record; |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 89 | type Pipe_Index is (Primary, Secondary, Tertiary); |
| 90 | type Pipe_Configs is array (Pipe_Index) of Pipe_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 91 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 92 | -- Special framebuffer offset to indicate legacy VGA plane. |
| 93 | -- Only valid on primary pipe. |
| 94 | VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#; |
| 95 | |
| Nico Huber | bebca13 | 2017-06-12 23:04:46 +0200 | [diff] [blame] | 96 | pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""", |
| 97 | Reason => "Write_Delay is used for debugging only"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 98 | procedure Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 99 | (Write_Delay : in Word64 := 0; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 100 | Clean_State : in Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 101 | Success : out Boolean) |
| 102 | with |
| 103 | Global => |
| 104 | (In_Out => (Config_State, Device_State, Port_IO.State), |
| 105 | Output => (State, Init_State), |
| 106 | Input => (Time.State)), |
| 107 | Post => Success = Is_Initialized; |
| 108 | function Is_Initialized return Boolean |
| 109 | with |
| 110 | Global => (Input => Init_State); |
| Nico Huber | bebca13 | 2017-06-12 23:04:46 +0200 | [diff] [blame] | 111 | pragma Warnings (GNATprove, On, "unused variable ""Write_Delay"""); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 112 | |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 113 | procedure Power_Up_VGA |
| 114 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 115 | Global => |
| 116 | (Input => (State, Time.State), |
| 117 | In_Out => (Device_State), |
| 118 | Proof_In => (Init_State)), |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 119 | Pre => Is_Initialized; |
| 120 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 121 | ---------------------------------------------------------------------------- |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 122 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 123 | procedure Update_Outputs (Configs : Pipe_Configs) |
| 124 | with |
| 125 | Global => |
| 126 | (Input => (Config_State, Time.State), |
| 127 | In_Out => (State, Device_State, Port_IO.State), |
| 128 | Proof_In => (Init_State)), |
| 129 | Pre => Is_Initialized; |
| 130 | |
| 131 | procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type) |
| 132 | with |
| 133 | Global => |
| 134 | (In_Out => (State, Device_State), |
| 135 | Proof_In => (Init_State)), |
| 136 | Pre => Is_Initialized; |
| 137 | |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 138 | procedure Place_Cursor |
| 139 | (Pipe : Pipe_Index; |
| 140 | X : Cursor_Pos; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 141 | Y : Cursor_Pos) |
| 142 | with |
| 143 | Global => |
| 144 | (In_Out => (State, Device_State), |
| 145 | Proof_In => (Init_State)), |
| 146 | Pre => Is_Initialized; |
| 147 | |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 148 | procedure Move_Cursor |
| 149 | (Pipe : Pipe_Index; |
| 150 | X : Cursor_Pos; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 151 | Y : Cursor_Pos) |
| 152 | with |
| 153 | Global => |
| 154 | (In_Out => (State, Device_State), |
| 155 | Proof_In => (Init_State)), |
| 156 | Pre => Is_Initialized; |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 157 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 158 | ---------------------------------------------------------------------------- |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 159 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 160 | procedure Write_GTT |
| 161 | (GTT_Page : GTT_Range; |
| 162 | Device_Address : GTT_Address_Type; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 163 | Valid : Boolean) |
| 164 | with |
| 165 | Global => (In_Out => Device_State, Proof_In => Init_State), |
| 166 | Pre => Is_Initialized; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 167 | |
| Nico Huber | ceda17d | 2018-06-09 22:00:29 +0200 | [diff] [blame] | 168 | procedure Read_GTT |
| 169 | (Device_Address : out GTT_Address_Type; |
| 170 | Valid : out Boolean; |
| 171 | GTT_Page : in GTT_Range) |
| 172 | with |
| 173 | Global => (In_Out => Device_State, Proof_In => Init_State), |
| 174 | Pre => Is_Initialized; |
| 175 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 176 | procedure Setup_Default_FB |
| 177 | (FB : in Framebuffer_Type; |
| 178 | Clear : in Boolean := True; |
| 179 | Success : out Boolean) |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 180 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 181 | Global => |
| 182 | (In_Out => |
| 183 | (State, Device_State, |
| 184 | Framebuffer_Filler.State, Framebuffer_Filler.Base_Address), |
| 185 | Proof_In => (Init_State)), |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 186 | Pre => Is_Initialized and HW.Config.Dynamic_MMIO; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 187 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 188 | procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type) |
| 189 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 190 | Global => |
| 191 | (In_Out => (State, Device_State), |
| 192 | Proof_In => (Init_State)), |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 193 | Pre => Is_Initialized and HW.Config.Dynamic_MMIO; |
| 194 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 195 | ---------------------------------------------------------------------------- |
| 196 | |
| 197 | pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect", |
| 198 | Reason => "It's only used for debugging"); |
| 199 | procedure Dump_Configs (Configs : Pipe_Configs); |
| 200 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 201 | private |
| 202 | |
| Nico Huber | 3299ad5 | 2018-06-02 16:53:39 +0200 | [diff] [blame] | 203 | -- For the default framebuffer setup (see below) with 90 degree rotations, |
| 204 | -- we expect the offset which is used for the final scanout to be above |
| 205 | -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for |
| 206 | -- the physical memory location and aperture mapping. |
| 207 | function Phys_Offset (FB : Framebuffer_Type) return Word32 is |
| 208 | (if Rotation_90 (FB) |
| 209 | then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size |
| 210 | else FB.Offset); |
| 211 | |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 212 | ---------------------------------------------------------------------------- |
| 213 | -- State tracking for the currently configured pipes |
| 214 | |
| 215 | Cur_Configs : Pipe_Configs with Part_Of => State; |
| 216 | |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 217 | function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is |
| 218 | (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode)); |
| 219 | |
| Nico Huber | b217ece | 2018-06-02 16:56:35 +0200 | [diff] [blame] | 220 | function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is |
| 221 | (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode)); |
| 222 | |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 223 | ---------------------------------------------------------------------------- |
| 224 | -- Internal representation of a single pipe's configuration |
| 225 | |
| 226 | subtype Active_Port_Type is Port_Type |
| 227 | range Port_Type'Succ (Disabled) .. Port_Type'Last; |
| 228 | |
| Arthur Heymans | 5d08a93 | 2018-03-28 17:00:18 +0200 | [diff] [blame] | 229 | type GPU_Port is (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, LVDS, VGA); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 230 | |
| 231 | subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E; |
| Arthur Heymans | 5d08a93 | 2018-03-28 17:00:18 +0200 | [diff] [blame] | 232 | subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D; |
| 233 | subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 234 | |
| 235 | type PCH_Port is |
| 236 | (PCH_DAC, PCH_LVDS, |
| 237 | PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D, |
| 238 | PCH_DP_B, PCH_DP_C, PCH_DP_D); |
| 239 | |
| 240 | subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_B .. PCH_HDMI_D; |
| 241 | subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D; |
| 242 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 243 | type Port_Config is |
| 244 | record |
| 245 | Port : GPU_Port; |
| 246 | PCH_Port : GMA.PCH_Port; |
| 247 | Display : Display_Type; |
| 248 | Mode : Mode_Type; |
| 249 | Is_FDI : Boolean; |
| 250 | FDI : DP_Link; |
| 251 | DP : DP_Link; |
| 252 | end record; |
| 253 | |
| 254 | type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training); |
| 255 | |
| 256 | ---------------------------------------------------------------------------- |
| 257 | |
| 258 | type DP_Port is (DP_A, DP_B, DP_C, DP_D); |
| 259 | |
| Nico Huber | 247adf3 | 2017-06-12 14:39:11 +0200 | [diff] [blame] | 260 | ---------------------------------------------------------------------------- |
| 261 | |
| 262 | subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11; |
| 263 | |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 264 | ---------------------------------------------------------------------------- |
| 265 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 266 | Tile_Width : constant array (Tiling_Type) of Width_Type := |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 267 | (Linear => 16, X_Tiled => 128, Y_Tiled => 32); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 268 | Tile_Rows : constant array (Tiling_Type) of Height_Type := |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 269 | (Linear => 1, X_Tiled => 8, Y_Tiled => 32); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 270 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 271 | function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural |
| 272 | is (Natural (Div_Round_Up |
| 273 | (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4))); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 274 | |
| 275 | function Valid_Stride (FB : Framebuffer_Type) return Boolean is |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 276 | (FB.Width + FB.Start_X <= FB.Stride and |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 277 | Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 278 | FB.Height + FB.Start_Y <= FB.V_Stride and |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 279 | FB.V_Stride mod Tile_Rows (FB.Tiling) = 0); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 280 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 281 | end HW.GFX.GMA; |