| 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; |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 18 | with HW.PCI; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 19 | with HW.Port_IO; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 20 | with HW.GFX.Framebuffer_Filler; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 21 | |
| Elyes Haouas | 066e52e | 2022-09-26 12:48:47 +0200 | [diff] [blame] | 22 | use type HW.Word32; |
| 23 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 24 | package HW.GFX.GMA |
| 25 | with |
| 26 | Abstract_State => |
| 27 | (State, |
| 28 | Init_State, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 29 | (Device_State with External)), |
| Nico Huber | 27088aa | 2018-06-10 13:28:05 +0200 | [diff] [blame] | 30 | Initializes => Init_State |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 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 | |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 38 | type Generation is (I945, G45, Ironlake, Haswell, Broxton, Skylake, Tigerlake); |
| Nico Huber | 6621a14 | 2018-06-07 23:56:54 +0200 | [diff] [blame] | 39 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 40 | type CPU_Type is |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 41 | (I945G, |
| 42 | I945GM, |
| 43 | G45, |
| Nico Huber | 7f3e280 | 2019-09-28 20:40:55 +0200 | [diff] [blame] | 44 | GM45, |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 45 | Ironlake, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 46 | Sandybridge, |
| 47 | Ivybridge, |
| 48 | Haswell, |
| 49 | Broadwell, |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 50 | Broxton, |
| Nico Huber | 88badbe | 2018-09-27 16:36:47 +0200 | [diff] [blame] | 51 | Skylake, |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 52 | Kabylake, |
| Tim Wawrzynczak | e9631d8 | 2022-09-09 12:26:32 -0600 | [diff] [blame] | 53 | Tigerlake, |
| 54 | Alderlake); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 55 | |
| Nico Huber | 25fdb15 | 2019-02-17 15:54:39 +0100 | [diff] [blame] | 56 | type CPU_Variant is (Normal, ULT, ULX); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 57 | |
| Nico Huber | e79babd | 2020-12-20 01:33:26 +0100 | [diff] [blame] | 58 | type PCH_Type is |
| 59 | (No_PCH, |
| 60 | Ibex_Peak, |
| 61 | Cougar_Point, -- Panther Point compatible |
| 62 | Lynx_Point, -- Wildcat Point compatible |
| Nico Huber | dde0630 | 2020-12-20 02:18:30 +0100 | [diff] [blame] | 63 | Sunrise_Point, -- Union Point compatible |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 64 | Cannon_Point, |
| Tim Wawrzynczak | e9631d8 | 2022-09-09 12:26:32 -0600 | [diff] [blame] | 65 | Tiger_Point, |
| 66 | Alder_Point); |
| Nico Huber | e79babd | 2020-12-20 01:33:26 +0100 | [diff] [blame] | 67 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 68 | type Port_Type is |
| 69 | (Disabled, |
| Nico Huber | 8beafd7 | 2020-01-07 14:59:44 +0100 | [diff] [blame] | 70 | LVDS, |
| 71 | eDP, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 72 | DP1, |
| 73 | DP2, |
| 74 | DP3, |
| Nico Huber | ad09609 | 2024-07-02 18:45:44 +0200 | [diff] [blame] | 75 | DP_TC1, -- DP_TC ports use Type-C lanes to |
| 76 | DP_TC2, -- implement physical DP or DP++ ports. |
| 77 | DP_TC3, |
| 78 | DP_TC4, |
| 79 | HDMI1, -- HDMI ports share lanes with their DP siblings. |
| 80 | HDMI2, -- They can also be implemented as DVI. |
| 81 | HDMI3, |
| 82 | HDMI_TC1, -- HDMI_TC use Type-C lanes to implement |
| 83 | HDMI_TC2, -- physical HDMI, DVI or the HDMI part of DP++. |
| 84 | HDMI_TC3, |
| 85 | HDMI_TC4, |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 86 | Analog, |
| Nico Huber | ad09609 | 2024-07-02 18:45:44 +0200 | [diff] [blame] | 87 | USBC1, -- Type-C lanes used to implement |
| 88 | USBC2, -- physical USB-C ports with DP Alt Mode. |
| 89 | USBC3, |
| 90 | USBC4); |
| Nico Huber | 040d9b6 | 2019-02-18 00:52:00 +0100 | [diff] [blame] | 91 | subtype Active_Port_Type is Port_Type |
| 92 | range Port_Type'Succ (Disabled) .. Port_Type'Last; |
| Nico Huber | 8beafd7 | 2020-01-07 14:59:44 +0100 | [diff] [blame] | 93 | subtype Internal_Port_Type is Port_Type range LVDS .. eDP; |
| Nico Huber | ad09609 | 2024-07-02 18:45:44 +0200 | [diff] [blame] | 94 | subtype Physical_DP_Ports is Port_Type range DP1 .. DP_TC4; |
| 95 | subtype Physical_HDMI_Ports is Port_Type range HDMI1 .. HDMI_TC4; |
| 96 | subtype Physical_USBC_Ports is Port_Type range USBC1 .. USBC4; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 97 | |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 98 | type Cursor_Mode is (No_Cursor, ARGB_Cursor); |
| 99 | type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256); |
| 100 | Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256); |
| 101 | |
| 102 | subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2; |
| 103 | |
| 104 | type Cursor_Type is record |
| 105 | Mode : Cursor_Mode; |
| 106 | Size : Cursor_Size; |
| 107 | Center_X : Cursor_Pos; |
| 108 | Center_Y : Cursor_Pos; |
| 109 | GTT_Offset : GTT_Range; |
| 110 | end record; |
| 111 | Default_Cursor : constant Cursor_Type := |
| 112 | (Mode => No_Cursor, |
| 113 | Size => Cursor_Size'First, |
| 114 | Center_X => 0, |
| 115 | Center_Y => 0, |
| 116 | GTT_Offset => 0); |
| 117 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 118 | type Pipe_Config is record |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 119 | Port : Port_Type; |
| 120 | Framebuffer : Framebuffer_Type; |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 121 | Cursor : Cursor_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 122 | Mode : Mode_Type; |
| 123 | end record; |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 124 | type Pipe_Index is (Primary, Secondary, Tertiary); |
| 125 | type Pipe_Configs is array (Pipe_Index) of Pipe_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 126 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 127 | -- Special framebuffer offset to indicate legacy VGA plane. |
| 128 | -- Only valid on primary pipe. |
| 129 | VGA_PLANE_FRAMEBUFFER_OFFSET : constant := 16#ffff_ffff#; |
| 130 | |
| Nico Huber | bebca13 | 2017-06-12 23:04:46 +0200 | [diff] [blame] | 131 | pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""", |
| 132 | Reason => "Write_Delay is used for debugging only"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 133 | procedure Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 134 | (Write_Delay : in Word64 := 0; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 135 | Clean_State : in Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 136 | Success : out Boolean) |
| 137 | with |
| 138 | Global => |
| Nico Huber | 27088aa | 2018-06-10 13:28:05 +0200 | [diff] [blame] | 139 | (In_Out => (Device_State, Port_IO.State), |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 140 | Output => (State, Init_State), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 141 | Input => (Time.State)), |
| 142 | Post => Success = Is_Initialized; |
| 143 | function Is_Initialized return Boolean |
| 144 | with |
| 145 | Global => (Input => Init_State); |
| Nico Huber | bebca13 | 2017-06-12 23:04:46 +0200 | [diff] [blame] | 146 | pragma Warnings (GNATprove, On, "unused variable ""Write_Delay"""); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 147 | |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 148 | procedure Power_Up_VGA |
| 149 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 150 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 151 | (Input => (State, Time.State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 152 | In_Out => (Device_State), |
| 153 | Proof_In => (Init_State)), |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 154 | Pre => Is_Initialized; |
| 155 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 156 | ---------------------------------------------------------------------------- |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 157 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 158 | procedure Update_Outputs (Configs : Pipe_Configs) |
| 159 | with |
| 160 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 161 | (Input => (Time.State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 162 | In_Out => (State, Device_State, Port_IO.State), |
| 163 | Proof_In => (Init_State)), |
| 164 | Pre => Is_Initialized; |
| 165 | |
| 166 | procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type) |
| 167 | with |
| 168 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 169 | (In_Out => (State, Device_State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 170 | Proof_In => (Init_State)), |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 171 | Pre => Is_Initialized; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 172 | |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 173 | procedure Place_Cursor |
| 174 | (Pipe : Pipe_Index; |
| 175 | X : Cursor_Pos; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 176 | Y : Cursor_Pos) |
| 177 | with |
| 178 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 179 | (In_Out => (State, Device_State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 180 | Proof_In => (Init_State)), |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 181 | Pre => Is_Initialized; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 182 | |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 183 | procedure Move_Cursor |
| 184 | (Pipe : Pipe_Index; |
| 185 | X : Cursor_Pos; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 186 | Y : Cursor_Pos) |
| 187 | with |
| 188 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 189 | (In_Out => (State, Device_State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 190 | Proof_In => (Init_State)), |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 191 | Pre => Is_Initialized; |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 192 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 193 | ---------------------------------------------------------------------------- |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 194 | |
| Nico Huber | bc0588e | 2020-07-21 12:17:19 +0200 | [diff] [blame] | 195 | procedure Backlight_On (Port : Active_Port_Type) |
| 196 | with |
| 197 | Global => (In_Out => Device_State); |
| 198 | |
| 199 | procedure Backlight_Off (Port : Active_Port_Type) |
| 200 | with |
| 201 | Global => (In_Out => Device_State); |
| 202 | |
| 203 | procedure Set_Brightness (Port : Active_Port_Type; Level : Word32) |
| 204 | with |
| 205 | Global => (In_Out => Device_State); |
| 206 | |
| 207 | procedure Get_Max_Brightness (Port : Active_Port_Type; Level : out Word32) |
| 208 | with |
| 209 | Global => (In_Out => Device_State); |
| 210 | |
| 211 | ---------------------------------------------------------------------------- |
| 212 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 213 | procedure Write_GTT |
| 214 | (GTT_Page : GTT_Range; |
| 215 | Device_Address : GTT_Address_Type; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 216 | Valid : Boolean) |
| 217 | with |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 218 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 219 | (Input => State, |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 220 | In_Out => Device_State, Proof_In => Init_State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 221 | Pre => Is_Initialized; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 222 | |
| Nico Huber | ceda17d | 2018-06-09 22:00:29 +0200 | [diff] [blame] | 223 | procedure Read_GTT |
| 224 | (Device_Address : out GTT_Address_Type; |
| 225 | Valid : out Boolean; |
| 226 | GTT_Page : in GTT_Range) |
| 227 | with |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 228 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 229 | (Input => State, |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 230 | In_Out => Device_State, Proof_In => Init_State), |
| Nico Huber | ceda17d | 2018-06-09 22:00:29 +0200 | [diff] [blame] | 231 | Pre => Is_Initialized; |
| 232 | |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 233 | procedure GTT_Entry_Count (Count : out Natural) |
| 234 | with |
| 235 | Global => |
| 236 | (Input => State, |
| 237 | In_Out => Device_State, Proof_In => Init_State), |
| 238 | Pre => Is_Initialized and HW.Config.Dynamic_MMIO; |
| 239 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 240 | procedure Setup_Default_FB |
| 241 | (FB : in Framebuffer_Type; |
| 242 | Clear : in Boolean := True; |
| 243 | Success : out Boolean) |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 244 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 245 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 246 | (In_Out => |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 247 | (State, Device_State, |
| 248 | Framebuffer_Filler.State, Framebuffer_Filler.Base_Address), |
| 249 | Proof_In => (Init_State)), |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 250 | Pre => Is_Initialized and HW.Config.Dynamic_MMIO; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 251 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 252 | procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type) |
| 253 | with |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 254 | Global => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 255 | (In_Out => (State, Device_State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 256 | Proof_In => (Init_State)), |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 257 | Pre => Is_Initialized and HW.Config.Dynamic_MMIO; |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 258 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 259 | ---------------------------------------------------------------------------- |
| 260 | |
| 261 | pragma Warnings (GNATprove, Off, "subprogram ""Dump_Configs"" has no effect", |
| 262 | Reason => "It's only used for debugging"); |
| 263 | procedure Dump_Configs (Configs : Pipe_Configs); |
| 264 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 265 | private |
| 266 | |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 267 | PCI_Usable : Boolean with Part_Of => State; |
| 268 | use type HW.PCI.Index; |
| 269 | procedure PCI_Read16 (Value : out Word16; Offset : HW.PCI.Index) |
| 270 | with |
| 271 | Pre => PCI_Usable and Offset mod 2 = 0; |
| 272 | |
| 273 | ---------------------------------------------------------------------------- |
| 274 | |
| Nico Huber | 3299ad5 | 2018-06-02 16:53:39 +0200 | [diff] [blame] | 275 | -- For the default framebuffer setup (see below) with 90 degree rotations, |
| 276 | -- we expect the offset which is used for the final scanout to be above |
| 277 | -- `GTT_Rotation_Offset`. So we can use `Offset - GTT_Rotation_Offset` for |
| 278 | -- the physical memory location and aperture mapping. |
| 279 | function Phys_Offset (FB : Framebuffer_Type) return Word32 is |
| 280 | (if Rotation_90 (FB) |
| 281 | then FB.Offset - Word32 (GTT_Rotation_Offset) * GTT_Page_Size |
| 282 | else FB.Offset); |
| 283 | |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 284 | ---------------------------------------------------------------------------- |
| 285 | -- State tracking for the currently configured pipes |
| 286 | |
| 287 | Cur_Configs : Pipe_Configs with Part_Of => State; |
| 288 | |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 289 | function Requires_Scaling (Pipe_Cfg : Pipe_Config) return Boolean is |
| 290 | (Requires_Scaling (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode)); |
| 291 | |
| Nico Huber | b217ece | 2018-06-02 16:56:35 +0200 | [diff] [blame] | 292 | function Scaling_Type (Pipe_Cfg : Pipe_Config) return Scaling_Aspect is |
| 293 | (Scaling_Type (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode)); |
| 294 | |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 295 | ---------------------------------------------------------------------------- |
| 296 | -- Internal representation of a single pipe's configuration |
| 297 | |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 298 | type GPU_Port is |
| 299 | (DIGI_A, DIGI_B, DIGI_C, DIGI_D, DIGI_E, |
| 300 | DDI_TC1, DDI_TC2, DDI_TC3, DDI_TC4, DDI_TC5, DDI_TC6, |
| 301 | LVDS, VGA); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 302 | |
| 303 | subtype Digital_Port is GPU_Port range DIGI_A .. DIGI_E; |
| Arthur Heymans | 5d08a93 | 2018-03-28 17:00:18 +0200 | [diff] [blame] | 304 | subtype GMCH_DP_Port is GPU_Port range DIGI_B .. DIGI_D; |
| 305 | subtype GMCH_HDMI_Port is GPU_Port range DIGI_B .. DIGI_C; |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 306 | subtype Combo_Port is GPU_Port range DIGI_A .. DIGI_C; |
| 307 | subtype USBC_Port is GPU_Port range DDI_TC1 .. DDI_TC6; |
| 308 | subtype TGL_Digital_Port is GPU_Port range DIGI_A .. DDI_TC6; |
| 309 | |
| 310 | function Is_Digital_Port (Port : GPU_Port) return Boolean is |
| 311 | (Port in Digital_Port or Port in TGL_Digital_Port); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 312 | |
| 313 | type PCH_Port is |
| 314 | (PCH_DAC, PCH_LVDS, |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 315 | PCH_HDMI_A, PCH_HDMI_B, PCH_HDMI_C, PCH_HDMI_D, |
| 316 | PCH_DP_B, PCH_DP_C, PCH_DP_D, |
| 317 | PCH_TC1, PCH_TC2, PCH_TC3, PCH_TC4, PCH_TC5, PCH_TC6); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 318 | |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 319 | subtype PCH_HDMI_Port is PCH_Port range PCH_HDMI_A .. PCH_HDMI_D; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 320 | subtype PCH_DP_Port is PCH_Port range PCH_DP_B .. PCH_DP_D; |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 321 | subtype PCH_TC_Port is PCH_Port range PCH_TC1 .. PCH_TC6; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 322 | |
| Nico Huber | 5dbaf4b | 2020-01-08 17:24:58 +0100 | [diff] [blame] | 323 | type Panel_Control is (No_Panel, Panel_1, Panel_2); |
| 324 | subtype Valid_Panels is Panel_Control range Panel_1 .. Panel_2; |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 325 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 326 | type Port_Config is |
| 327 | record |
| 328 | Port : GPU_Port; |
| 329 | PCH_Port : GMA.PCH_Port; |
| 330 | Display : Display_Type; |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 331 | Panel : Panel_Control; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 332 | Mode : Mode_Type; |
| 333 | Is_FDI : Boolean; |
| 334 | FDI : DP_Link; |
| 335 | DP : DP_Link; |
| 336 | end record; |
| 337 | |
| 338 | type FDI_Training_Type is (Simple_Training, Full_Training, Auto_Training); |
| 339 | |
| 340 | ---------------------------------------------------------------------------- |
| 341 | |
| Tim Wawrzynczak | 24748f3 | 2022-09-09 10:54:05 -0600 | [diff] [blame] | 342 | type DP_Port is (DP_A, DP_B, DP_C, DP_D, DP_E, DP_F, DP_G, DP_H, DP_I); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 343 | |
| Nico Huber | 247adf3 | 2017-06-12 14:39:11 +0200 | [diff] [blame] | 344 | ---------------------------------------------------------------------------- |
| 345 | |
| 346 | subtype DDI_HDMI_Buf_Trans_Range is Integer range 0 .. 11; |
| 347 | |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 348 | ---------------------------------------------------------------------------- |
| 349 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 350 | Tile_Width : constant array (Tiling_Type) of Width_Type := |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 351 | (Linear => 16, X_Tiled => 128, Y_Tiled => 32); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 352 | Tile_Rows : constant array (Tiling_Type) of Height_Type := |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 353 | (Linear => 1, X_Tiled => 8, Y_Tiled => 32); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 354 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 355 | function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural |
| 356 | is (Natural (Div_Round_Up |
| 357 | (Pixel_To_Bytes (Px, FB), Tile_Width (FB.Tiling) * 4))); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 358 | |
| 359 | function Valid_Stride (FB : Framebuffer_Type) return Boolean is |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 360 | (FB.Width + FB.Start_X <= FB.Stride and |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 361 | 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] | 362 | FB.Height + FB.Start_Y <= FB.V_Stride and |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 363 | FB.V_Stride mod Tile_Rows (FB.Tiling) = 0); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 364 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 365 | end HW.GFX.GMA; |