| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 2 | -- Copyright (C) 2014-2019 secunet Security Networks AG |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +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 | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 16 | with HW.MMIO_Range; |
| 17 | pragma Elaborate_All (HW.MMIO_Range); |
| 18 | with HW.PCI.Dev; |
| 19 | pragma Elaborate_All (HW.PCI.Dev); |
| 20 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 21 | with HW.GFX.GMA.Config; |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 22 | with HW.GFX.GMA.Config_Helpers; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 23 | with HW.GFX.GMA.Registers; |
| Nico Huber | 312433c | 2019-09-28 03:15:48 +0200 | [diff] [blame] | 24 | with HW.GFX.GMA.PCode; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 25 | with HW.GFX.GMA.Power_And_Clocks; |
| 26 | with HW.GFX.GMA.Panel; |
| 27 | with HW.GFX.GMA.PLLs; |
| 28 | with HW.GFX.GMA.Port_Detect; |
| 29 | with HW.GFX.GMA.Connectors; |
| 30 | with HW.GFX.GMA.Connector_Info; |
| 31 | with HW.GFX.GMA.Pipe_Setup; |
| 32 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 33 | with HW.Debug; |
| 34 | with GNAT.Source_Info; |
| 35 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 36 | |
| 37 | package body HW.GFX.GMA |
| 38 | with Refined_State => |
| 39 | (State => |
| Nico Huber | e317e9c | 2019-09-29 03:03:18 +0200 | [diff] [blame] | 40 | (Config.Variable, |
| 41 | PCI_Usable, |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 42 | Dev.Address_State, |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 43 | Registers.Address_State, |
| Nico Huber | 312433c | 2019-09-28 03:15:48 +0200 | [diff] [blame] | 44 | PCode.Mailbox_Ready, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 45 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 46 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 47 | HPD_Delay, Wait_For_HPD, |
| 48 | Linear_FB_Base), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 49 | Init_State => Initialized, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 50 | Device_State => |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 51 | (Dev.PCI_State, Registers.Register_State, Registers.GTT_State)) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 52 | is |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 53 | pragma Disable_Atomic_Synchronization; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 54 | |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 55 | subtype Port_Name is String (1 .. 10); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 56 | type Port_Name_Array is array (Port_Type) of Port_Name; |
| 57 | Port_Names : constant Port_Name_Array := |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 58 | (Disabled => "Disabled ", |
| 59 | LVDS => "LVDS ", |
| 60 | eDP => "eDP ", |
| 61 | DP1 => "DP1 ", |
| 62 | DP2 => "DP2 ", |
| 63 | DP3 => "DP3 ", |
| 64 | HDMI1 => "HDMI1 ", |
| 65 | HDMI2 => "HDMI2 ", |
| 66 | HDMI3 => "HDMI3 ", |
| 67 | Analog => "Analog ", |
| 68 | USBC1_DP => "USBC1-DP ", |
| 69 | USBC2_DP => "USBC2-DP ", |
| 70 | USBC3_DP => "USBC3-DP ", |
| 71 | USBC4_DP => "USBC4-DP ", |
| 72 | USBC5_DP => "USBC5-DP ", |
| 73 | USBC6_DP => "USBC6-DP ", |
| 74 | USBC1_HDMI => "USBC1-HDMI", |
| 75 | USBC2_HDMI => "USBC2-HDMI", |
| 76 | USBC3_HDMI => "USBC3-HDMI", |
| 77 | USBC4_HDMI => "USBC4-HDMI", |
| 78 | USBC5_HDMI => "USBC5-HDMI", |
| 79 | USBC6_HDMI => "USBC6-HDMI"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 80 | |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 81 | package Dev is new HW.PCI.Dev (PCI.Address'(0, 2, 0)); |
| 82 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 83 | package Display_Controller renames Pipe_Setup; |
| 84 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 85 | type PLLs_Type is array (Pipe_Index) of PLLs.T; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 86 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 87 | type HPD_Type is array (Port_Type) of Boolean; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 88 | type HPD_Delay_Type is array (Active_Port_Type) of Time.T; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 89 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 90 | Allocated_PLLs : PLLs_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 91 | HPD_Delay : HPD_Delay_Type; |
| 92 | Wait_For_HPD : HPD_Type; |
| 93 | Initialized : Boolean := False; |
| 94 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 95 | Linear_FB_Base : Word64; |
| 96 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 97 | ---------------------------------------------------------------------------- |
| 98 | |
| Tim Wawrzynczak | fc49b60 | 2022-09-09 10:29:24 -0600 | [diff] [blame] | 99 | ICP_RAWCLK_NUM : constant := 1 * 2 ** 11; |
| 100 | |
| 101 | function PCH_RAWCLK_FREQ_MASK return Word32 is |
| 102 | Mask : Word32; |
| 103 | begin |
| 104 | if Config.Need_Rawclk_Numerator then |
| 105 | Mask := 16#ffff_ffff#; |
| 106 | elsif Config.Has_Fractional_RawClk then |
| 107 | Mask := 16#3fff# * 2 ** 16; |
| 108 | else |
| 109 | Mask := 16#3ff# * 2 ** 0; |
| 110 | end if; |
| 111 | return Mask; |
| 112 | end PCH_RAWCLK_FREQ_MASK; |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 113 | |
| 114 | function PCH_RAWCLK_FREQ (Freq : Frequency_Type) return Word32 |
| 115 | is |
| 116 | begin |
| Nico Huber | dde0630 | 2020-12-20 02:18:30 +0100 | [diff] [blame] | 117 | if Config.Has_Fractional_RawClk then |
| 118 | declare |
| 119 | Fraction_K : constant Int64 := Freq / 1_000 mod 1_000; |
| 120 | Freq32 : Word32 := Shift_Left (Word32 (Freq / 1_000_000), 16); |
| 121 | begin |
| 122 | if Fraction_K /= 0 then |
| 123 | Freq32 := Freq32 or Shift_Left |
| 124 | (Word32 (Div_Round_Closest (1_000, Fraction_K) - 1), 26); |
| 125 | end if; |
| Tim Wawrzynczak | fc49b60 | 2022-09-09 10:29:24 -0600 | [diff] [blame] | 126 | |
| 127 | if Config.Need_Rawclk_Numerator then |
| 128 | Freq32 := Freq32 or ICP_RAWCLK_NUM; |
| 129 | end if; |
| Nico Huber | dde0630 | 2020-12-20 02:18:30 +0100 | [diff] [blame] | 130 | return Freq32; |
| 131 | end; |
| 132 | else |
| 133 | return Word32 (Freq / 1_000_000); |
| 134 | end if; |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 135 | end PCH_RAWCLK_FREQ; |
| 136 | |
| 137 | ---------------------------------------------------------------------------- |
| 138 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 139 | procedure Enable_Output |
| 140 | (Pipe : in Pipe_Index; |
| 141 | Pipe_Cfg : in Pipe_Config; |
| 142 | Success : out Boolean) |
| Nico Huber | 8a5a3b5 | 2018-06-04 14:42:13 +0200 | [diff] [blame] | 143 | with |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 144 | Pre => |
| 145 | Pipe_Cfg.Port in Active_Port_Type and |
| 146 | Config_Helpers.Valid_FB (Pipe_Cfg.Framebuffer, Pipe_Cfg.Mode) |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 147 | is |
| 148 | Port_Cfg : Port_Config; |
| 149 | begin |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 150 | pragma Debug (Debug.New_Line); |
| 151 | pragma Debug (Debug.Put_Line |
| 152 | ("Trying to enable port " & Port_Names (Pipe_Cfg.Port))); |
| 153 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 154 | Config_Helpers.Fill_Port_Config |
| 155 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 156 | |
| 157 | if Success then |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 158 | Connector_Info.Preferred_Link_Setting (Port_Cfg, Success); |
| 159 | end if; |
| 160 | |
| 161 | -- loop over all possible DP-lane configurations |
| 162 | -- (non-DP ports use a single fake configuration) |
| 163 | while Success loop |
| 164 | pragma Loop_Invariant |
| 165 | (Pipe_Cfg.Port in Active_Port_Type and |
| 166 | Port_Cfg.Mode = Port_Cfg.Mode'Loop_Entry); |
| 167 | |
| 168 | PLLs.Alloc |
| 169 | (Port_Cfg => Port_Cfg, |
| 170 | PLL => Allocated_PLLs (Pipe), |
| 171 | Success => Success); |
| 172 | |
| 173 | if Success then |
| 174 | -- try each DP-lane configuration twice |
| 175 | for Try in 1 .. 2 loop |
| 176 | pragma Loop_Invariant |
| 177 | (Pipe_Cfg.Port in Active_Port_Type); |
| 178 | |
| Nico Huber | 4798c66 | 2017-01-11 12:44:48 +0100 | [diff] [blame] | 179 | -- Clear pending hot-plug events before every try |
| 180 | Port_Detect.Clear_Hotplug_Detect (Pipe_Cfg.Port); |
| 181 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 182 | Connectors.Pre_On |
| 183 | (Pipe => Pipe, |
| 184 | Port_Cfg => Port_Cfg, |
| 185 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 186 | Success => Success); |
| 187 | |
| 188 | if Success then |
| 189 | Display_Controller.On |
| 190 | (Pipe => Pipe, |
| 191 | Port_Cfg => Port_Cfg, |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 192 | Framebuffer => Pipe_Cfg.Framebuffer, |
| 193 | Cursor => Pipe_Cfg.Cursor); |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 194 | |
| 195 | Connectors.Post_On |
| Arthur Heymans | 60d0e5f | 2018-03-28 17:08:27 +0200 | [diff] [blame] | 196 | (Pipe => Pipe, |
| 197 | Port_Cfg => Port_Cfg, |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 198 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 199 | Success => Success); |
| 200 | |
| 201 | if not Success then |
| 202 | Display_Controller.Off (Pipe); |
| 203 | Connectors.Post_Off (Port_Cfg); |
| 204 | end if; |
| 205 | end if; |
| 206 | |
| 207 | exit when Success; |
| 208 | end loop; |
| 209 | exit when Success; -- connection established => stop loop |
| 210 | |
| 211 | -- connection failed |
| 212 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 213 | end if; |
| 214 | |
| 215 | Connector_Info.Next_Link_Setting (Port_Cfg, Success); |
| 216 | end loop; |
| 217 | |
| 218 | if Success then |
| 219 | pragma Debug (Debug.Put_Line |
| 220 | ("Enabled port " & Port_Names (Pipe_Cfg.Port))); |
| 221 | else |
| 222 | Wait_For_HPD (Pipe_Cfg.Port) := True; |
| Nico Huber | 2bbd6e7 | 2020-01-07 18:22:59 +0100 | [diff] [blame] | 223 | Panel.Off (Config_Helpers.To_Panel (Pipe_Cfg.Port)); |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 224 | end if; |
| 225 | end Enable_Output; |
| 226 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 227 | procedure Disable_Output (Pipe : Pipe_Index; Pipe_Cfg : Pipe_Config) |
| 228 | is |
| 229 | Port_Cfg : Port_Config; |
| 230 | Success : Boolean; |
| 231 | begin |
| 232 | Config_Helpers.Fill_Port_Config |
| 233 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 234 | if Success then |
| 235 | pragma Debug (Debug.New_Line); |
| 236 | pragma Debug (Debug.Put_Line |
| 237 | ("Disabling port " & Port_Names (Pipe_Cfg.Port))); |
| 238 | pragma Debug (Debug.New_Line); |
| 239 | |
| Jeremy Compostella | fe80fbb | 2023-01-11 14:05:42 -0700 | [diff] [blame] | 240 | if Pipe_Cfg.Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| 241 | Display_Controller.Legacy_VGA_Off; |
| 242 | end if; |
| 243 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 244 | Connectors.Pre_Off (Port_Cfg); |
| 245 | Display_Controller.Off (Pipe); |
| 246 | Connectors.Post_Off (Port_Cfg); |
| 247 | |
| 248 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 249 | end if; |
| 250 | end Disable_Output; |
| 251 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 252 | procedure Update_Outputs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 253 | is |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 254 | procedure Check_HPD (Port : in Active_Port_Type; Detected : out Boolean) |
| 255 | is |
| 256 | HPD_Delay_Over : constant Boolean := Time.Timed_Out (HPD_Delay (Port)); |
| 257 | begin |
| 258 | if HPD_Delay_Over then |
| 259 | Port_Detect.Hotplug_Detect (Port, Detected); |
| 260 | HPD_Delay (Port) := Time.MS_From_Now (333); |
| 261 | else |
| 262 | Detected := False; |
| 263 | end if; |
| 264 | end Check_HPD; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 265 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 266 | Scaler_Reservation : Display_Controller.Scaler_Reservation := |
| 267 | Display_Controller.Null_Scaler_Reservation; |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 268 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 269 | Update_Power : Boolean := False; |
| Nico Huber | b0bbdbc | 2019-09-27 22:32:21 +0200 | [diff] [blame] | 270 | Update_CDClk : Boolean; |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 271 | Old_Configs, |
| 272 | New_Configs : Pipe_Configs; |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 273 | |
| 274 | function Full_Update (Cur_Config, New_Config : Pipe_Config) return Boolean |
| 275 | is |
| 276 | begin |
| 277 | return |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 278 | Cur_Config.Port /= New_Config.Port |
| 279 | or else |
| 280 | Cur_Config.Mode /= New_Config.Mode |
| 281 | or else |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 282 | (Config.Use_PDW_For_EDP_Scaling and then |
| Nico Huber | 8beafd7 | 2020-01-07 14:59:44 +0100 | [diff] [blame] | 283 | (Cur_Config.Port = eDP and |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 284 | Requires_Scaling (Cur_Config) /= Requires_Scaling (New_Config))) |
| 285 | or else |
| 286 | (Config.Has_GMCH_PFIT_CONTROL and then |
| 287 | (Requires_Scaling (Cur_Config) /= Requires_Scaling (New_Config) or |
| 288 | Scaling_Type (Cur_Config) /= Scaling_Type (New_Config))); |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 289 | end Full_Update; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 290 | begin |
| 291 | Old_Configs := Cur_Configs; |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 292 | New_Configs := Configs; |
| 293 | |
| 294 | -- validate new configs, filter invalid configs and those waiting for HPD |
| 295 | for Pipe in Pipe_Index loop |
| 296 | declare |
| 297 | Success : Boolean := True; |
| 298 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| 299 | New_Config : Pipe_Config renames New_Configs (Pipe); |
| 300 | begin |
| 301 | if New_Config.Port /= Disabled then |
| 302 | if Wait_For_HPD (New_Config.Port) then |
| 303 | Check_HPD (New_Config.Port, Success); |
| 304 | Wait_For_HPD (New_Config.Port) := not Success; |
| 305 | end if; |
| 306 | |
| 307 | Success := Success and then |
| 308 | Config_Helpers.Validate_Config |
| 309 | (New_Config.Framebuffer, New_Config.Mode, Pipe); |
| 310 | |
| 311 | if Success and then Requires_Scaling (New_Config) then |
| 312 | Display_Controller.Reserve_Scaler |
| 313 | (Success, Scaler_Reservation, Pipe); |
| 314 | end if; |
| 315 | |
| 316 | if not Success then |
| 317 | New_Config.Port := Disabled; |
| 318 | end if; |
| 319 | end if; |
| 320 | end; |
| 321 | pragma Loop_Invariant |
| 322 | (for all P in Pipe_Index'First .. Pipe => |
| 323 | New_Configs (P).Port = Disabled or |
| 324 | Config_Helpers.Valid_FB |
| 325 | (New_Configs (P).Framebuffer, New_Configs (P).Mode)); |
| 326 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 327 | |
| Nico Huber | b0bbdbc | 2019-09-27 22:32:21 +0200 | [diff] [blame] | 328 | -- limit dotclocks to maximum CDClk, if we are about |
| 329 | -- to switch CDClk, all pipes have to be disabled |
| 330 | Power_And_Clocks.Limit_Dotclocks (New_Configs, Update_CDClk); |
| 331 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 332 | -- disable all pipes that changed or had a hot-plug event |
| 333 | for Pipe in Pipe_Index loop |
| 334 | declare |
| 335 | Unplug_Detected : Boolean; |
| 336 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 337 | New_Config : Pipe_Config renames New_Configs (Pipe); |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 338 | begin |
| 339 | if Cur_Config.Port /= Disabled then |
| 340 | Check_HPD (Cur_Config.Port, Unplug_Detected); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 341 | |
| Nico Huber | b0bbdbc | 2019-09-27 22:32:21 +0200 | [diff] [blame] | 342 | if Update_CDClk or |
| 343 | Unplug_Detected or |
| 344 | Full_Update (Cur_Config, New_Config) |
| 345 | then |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 346 | Disable_Output (Pipe, Cur_Config); |
| 347 | Cur_Config.Port := Disabled; |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 348 | Update_Power := True; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 349 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 350 | end if; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 351 | end; |
| 352 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 353 | |
| Nico Huber | b0bbdbc | 2019-09-27 22:32:21 +0200 | [diff] [blame] | 354 | -- switch CDClk if necessary and possible, limit dotclocks accordingly |
| 355 | if Update_CDClk then |
| 356 | Power_And_Clocks.Update_CDClk (New_Configs); |
| 357 | end if; |
| 358 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 359 | -- enable all pipes that changed and should be active |
| 360 | for Pipe in Pipe_Index loop |
| 361 | declare |
| 362 | Success : Boolean; |
| 363 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 364 | New_Config : Pipe_Config renames New_Configs (Pipe); |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 365 | begin |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 366 | -- full update |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 367 | if New_Config.Port /= Disabled and |
| 368 | Full_Update (Cur_Config, New_Config) |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 369 | then |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 370 | Power_And_Clocks.Power_Up (Old_Configs, New_Configs); |
| 371 | Update_Power := True; |
| Nico Huber | c7a4fee | 2016-11-03 18:18:03 +0100 | [diff] [blame] | 372 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 373 | Enable_Output (Pipe, New_Config, Success); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 374 | if Success then |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 375 | Cur_Config := New_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 376 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 377 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 378 | -- update framebuffer offset only |
| 379 | elsif New_Config.Port /= Disabled and |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 380 | Cur_Config.Framebuffer /= New_Config.Framebuffer |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 381 | then |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 382 | Display_Controller.Setup_FB |
| 383 | (Pipe, New_Config.Mode, New_Config.Framebuffer); |
| 384 | Display_Controller.Update_Cursor |
| 385 | (Pipe, New_Config.Framebuffer, New_Config.Cursor); |
| 386 | Cur_Config := New_Config; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 387 | end if; |
| 388 | end; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 389 | end loop; |
| 390 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 391 | if Update_Power then |
| 392 | Power_And_Clocks.Power_Down (Old_Configs, New_Configs, Cur_Configs); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 393 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 394 | end Update_Outputs; |
| 395 | |
| 396 | ---------------------------------------------------------------------------- |
| 397 | |
| Nico Huber | 15ffc4f | 2018-01-11 14:44:43 +0100 | [diff] [blame] | 398 | procedure Update_Cursor (Pipe : Pipe_Index; Cursor : Cursor_Type) |
| 399 | is |
| 400 | begin |
| 401 | Cur_Configs (Pipe).Cursor := Cursor; |
| 402 | Display_Controller.Update_Cursor |
| 403 | (Pipe, Cur_Configs (Pipe).Framebuffer, Cur_Configs (Pipe).Cursor); |
| 404 | end Update_Cursor; |
| 405 | |
| 406 | procedure Place_Cursor |
| 407 | (Pipe : Pipe_Index; |
| 408 | X : Cursor_Pos; |
| 409 | Y : Cursor_Pos) |
| 410 | is |
| 411 | begin |
| 412 | Cur_Configs (Pipe).Cursor.Center_X := X; |
| 413 | Cur_Configs (Pipe).Cursor.Center_Y := Y; |
| 414 | Display_Controller.Place_Cursor |
| 415 | (Pipe, Cur_Configs (Pipe).Framebuffer, Cur_Configs (Pipe).Cursor); |
| 416 | end Place_Cursor; |
| 417 | |
| 418 | procedure Move_Cursor |
| 419 | (Pipe : Pipe_Index; |
| 420 | X : Cursor_Pos; |
| 421 | Y : Cursor_Pos) |
| 422 | is |
| 423 | function Cap_Add (A, B : Cursor_Pos) return Cursor_Pos is |
| 424 | (if A + B < 0 |
| 425 | then Int32'Max (Cursor_Pos'First, A + B) |
| 426 | else Int32'Min (Cursor_Pos'Last, A + B)); |
| 427 | begin |
| 428 | Place_Cursor |
| 429 | (Pipe => Pipe, |
| 430 | X => Cap_Add (Cur_Configs (Pipe).Cursor.Center_X, X), |
| 431 | Y => Cap_Add (Cur_Configs (Pipe).Cursor.Center_Y, Y)); |
| 432 | end Move_Cursor; |
| 433 | |
| 434 | ---------------------------------------------------------------------------- |
| 435 | |
| Nico Huber | bc0588e | 2020-07-21 12:17:19 +0200 | [diff] [blame] | 436 | procedure Backlight_On (Port : Active_Port_Type) |
| 437 | with |
| 438 | Refined_Global => (In_Out => Registers.Register_State) |
| 439 | is |
| 440 | begin |
| 441 | Panel.Backlight_On (Config_Helpers.To_Panel (Port)); |
| 442 | end Backlight_On; |
| 443 | |
| 444 | procedure Backlight_Off (Port : Active_Port_Type) |
| 445 | with |
| 446 | Refined_Global => (In_Out => Registers.Register_State) |
| 447 | is |
| 448 | begin |
| 449 | Panel.Backlight_Off (Config_Helpers.To_Panel (Port)); |
| 450 | end Backlight_Off; |
| 451 | |
| 452 | procedure Set_Brightness (Port : Active_Port_Type; Level : Word32) |
| 453 | with |
| 454 | Refined_Global => (In_Out => Registers.Register_State) |
| 455 | is |
| 456 | begin |
| 457 | Panel.Set_Backlight (Config_Helpers.To_Panel (Port), Level); |
| 458 | end Set_Brightness; |
| 459 | |
| 460 | procedure Get_Max_Brightness (Port : Active_Port_Type; Level : out Word32) |
| 461 | with |
| 462 | Refined_Global => (In_Out => Registers.Register_State) |
| 463 | is |
| 464 | begin |
| 465 | Panel.Get_Max_Backlight (Config_Helpers.To_Panel (Port), Level); |
| 466 | end Get_Max_Brightness; |
| 467 | |
| 468 | ---------------------------------------------------------------------------- |
| 469 | |
| Nico Huber | 793f4f8 | 2022-09-04 14:24:00 +0000 | [diff] [blame] | 470 | pragma Warnings |
| 471 | (GNATprove, Off, """Registers.GTT_State"" * is not modified*", |
| 472 | Reason => "The whole, abstract Device_State is modified in certain configurations."); |
| 473 | pragma Warnings |
| 474 | (GNATprove, Off, "no check message justified*", Reason => "see below"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 475 | procedure Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 476 | (Write_Delay : in Word64 := 0; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 477 | Clean_State : in Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 478 | Success : out Boolean) |
| 479 | with |
| 480 | Refined_Global => |
| Nico Huber | 27088aa | 2018-06-10 13:28:05 +0200 | [diff] [blame] | 481 | (Input => (Time.State), |
| Nico Huber | 793f4f8 | 2022-09-04 14:24:00 +0000 | [diff] [blame] | 482 | In_Out => |
| 483 | (Dev.PCI_State, Port_IO.State, |
| 484 | Registers.Register_State, Registers.GTT_State), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 485 | Output => |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 486 | (PCI_Usable, |
| 487 | Config.Variable, |
| Nico Huber | 27088aa | 2018-06-10 13:28:05 +0200 | [diff] [blame] | 488 | Dev.Address_State, |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 489 | Registers.Address_State, |
| Nico Huber | 312433c | 2019-09-28 03:15:48 +0200 | [diff] [blame] | 490 | PCode.Mailbox_Ready, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 491 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 492 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 493 | HPD_Delay, Wait_For_HPD, |
| 494 | Linear_FB_Base, Initialized)) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 495 | is |
| 496 | use type HW.Word64; |
| 497 | |
| Nico Huber | 0b2329a | 2018-06-09 21:14:27 +0200 | [diff] [blame] | 498 | function MMIO_GTT_Offset return Natural is |
| 499 | (if Config.Has_64bit_GTT |
| 500 | then Registers.MMIO_GTT_64_Offset |
| 501 | else Registers.MMIO_GTT_32_Offset); |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 502 | PCI_MMIO_Base, PCI_GTT_Base : Word64; |
| 503 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 504 | Now : constant Time.T := Time.Now; |
| 505 | |
| 506 | procedure Check_Platform (Success : out Boolean) |
| 507 | is |
| 508 | Audio_VID_DID : Word32; |
| 509 | begin |
| Nico Huber | 6621a14 | 2018-06-07 23:56:54 +0200 | [diff] [blame] | 510 | case Config.Gen is |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 511 | when G45 => |
| 512 | Registers.Read (Registers.G4X_AUD_VID_DID, Audio_VID_DID); |
| Nico Huber | 6621a14 | 2018-06-07 23:56:54 +0200 | [diff] [blame] | 513 | when Ironlake => |
| 514 | Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID); |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 515 | when Haswell .. Tigerlake => |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 516 | Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 517 | end case; |
| 518 | Success := |
| Nico Huber | 998ee2b | 2018-06-12 23:02:17 +0200 | [diff] [blame] | 519 | ((Config.Gen_Broxton and Audio_VID_DID = 16#8086_280a#) or |
| Nico Huber | 88badbe | 2018-09-27 16:36:47 +0200 | [diff] [blame] | 520 | (Config.CPU_Kabylake and Audio_VID_DID = 16#8086_280b#) or |
| 521 | (Config.CPU_Skylake and Audio_VID_DID = 16#8086_2809#) or |
| Nico Huber | 998ee2b | 2018-06-12 23:02:17 +0200 | [diff] [blame] | 522 | (Config.CPU_Broadwell and Audio_VID_DID = 16#8086_2808#) or |
| 523 | (Config.CPU_Haswell and Audio_VID_DID = 16#8086_2807#) or |
| 524 | ((Config.CPU_Ivybridge or |
| 525 | Config.CPU_Sandybridge) and (Audio_VID_DID = 16#8086_2806# or |
| 526 | Audio_VID_DID = 16#8086_2805#)) or |
| 527 | (Config.CPU_Ironlake and Audio_VID_DID = 16#0000_0000#) or |
| 528 | (Config.Gen_G45 and (Audio_VID_DID = 16#8086_2801# or |
| 529 | Audio_VID_DID = 16#8086_2802# or |
| Tim Wawrzynczak | 605660b | 2022-06-08 12:48:19 -0600 | [diff] [blame] | 530 | Audio_VID_DID = 16#8086_2803#)) or |
| 531 | (Config.CPU_Tigerlake and (Audio_VID_DID = 16#8086_2812#))); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 532 | end Check_Platform; |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 533 | |
| 534 | procedure Check_Platform_PCI (Success : out Boolean) |
| 535 | is |
| 536 | use type HW.Word16; |
| 537 | Vendor, Device : Word16; |
| 538 | begin |
| 539 | Dev.Read16 (Vendor, PCI.Vendor_Id); |
| 540 | Dev.Read16 (Device, PCI.Device_Id); |
| 541 | |
| Nico Huber | 6a996dc | 2018-06-17 16:30:33 +0200 | [diff] [blame] | 542 | Config.Detect_CPU (Device); |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 543 | Success := Vendor = 16#8086# and Config.Compatible_GPU (Device); |
| 544 | end Check_Platform_PCI; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 545 | begin |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 546 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 547 | |
| 548 | pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay)); |
| 549 | |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 550 | PCI_Usable := False; |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 551 | Linear_FB_Base := 0; |
| Nico Huber | 312433c | 2019-09-28 03:15:48 +0200 | [diff] [blame] | 552 | PCode.Mailbox_Ready := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 553 | Wait_For_HPD := HPD_Type'(others => False); |
| 554 | HPD_Delay := HPD_Delay_Type'(others => Now); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 555 | Allocated_PLLs := (others => PLLs.Invalid); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 556 | Cur_Configs := Pipe_Configs' |
| 557 | (others => Pipe_Config' |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 558 | (Port => Disabled, |
| 559 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 560 | Cursor => Default_Cursor, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 561 | Mode => HW.GFX.Invalid_Mode)); |
| Nico Huber | 27088aa | 2018-06-10 13:28:05 +0200 | [diff] [blame] | 562 | Config.Variable := Config.Initial_Settings; |
| Nico Huber | 6a996dc | 2018-06-17 16:30:33 +0200 | [diff] [blame] | 563 | Registers.Set_Register_Base (Config.Default_MMIO_Base); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 564 | PLLs.Initialize; |
| 565 | |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 566 | Dev.Initialize (Success); |
| 567 | |
| 568 | if Success then |
| Nico Huber | 6a996dc | 2018-06-17 16:30:33 +0200 | [diff] [blame] | 569 | Check_Platform_PCI (Success); |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 570 | if Success then |
| Nico Huber | 6a996dc | 2018-06-17 16:30:33 +0200 | [diff] [blame] | 571 | Dev.Map (PCI_MMIO_Base, PCI.Res0, Length => MMIO_GTT_Offset); |
| 572 | Dev.Map (PCI_GTT_Base, PCI.Res0, Offset => MMIO_GTT_Offset); |
| 573 | if PCI_MMIO_Base /= 0 and PCI_GTT_Base /= 0 then |
| 574 | Registers.Set_Register_Base (PCI_MMIO_Base, PCI_GTT_Base); |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 575 | PCI_Usable := True; |
| Nico Huber | 6a996dc | 2018-06-17 16:30:33 +0200 | [diff] [blame] | 576 | else |
| 577 | pragma Debug (Debug.Put_Line |
| 578 | ("ERROR: Couldn't map resoure0.")); |
| 579 | Success := Config.Default_MMIO_Base_Set; |
| 580 | end if; |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 581 | end if; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 582 | else |
| 583 | pragma Debug (Debug.Put_Line |
| 584 | ("WARNING: Couldn't initialize PCI dev.")); |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 585 | Success := Config.Default_MMIO_Base_Set; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 586 | |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 587 | if Success then |
| 588 | Check_Platform (Success); |
| 589 | end if; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 590 | end if; |
| 591 | |
| Nico Huber | 5dbaf4b | 2020-01-08 17:24:58 +0100 | [diff] [blame] | 592 | Panel.Static_Init; -- early for flow analysis |
| 593 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 594 | if not Success then |
| 595 | pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH.")); |
| 596 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 597 | Initialized := False; |
| 598 | return; |
| 599 | end if; |
| 600 | |
| 601 | Panel.Setup_PP_Sequencer; |
| 602 | Port_Detect.Initialize; |
| Nico Huber | 0923b79 | 2017-06-09 15:28:41 +0200 | [diff] [blame] | 603 | Connectors.Initialize; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 604 | |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 605 | if Clean_State then |
| 606 | Power_And_Clocks.Pre_All_Off; |
| 607 | Connectors.Pre_All_Off; |
| 608 | Display_Controller.All_Off; |
| 609 | Connectors.Post_All_Off; |
| 610 | PLLs.All_Off; |
| 611 | Power_And_Clocks.Post_All_Off; |
| Nico Huber | 17d64b6 | 2017-07-15 20:51:25 +0200 | [diff] [blame] | 612 | Registers.Clear_Fences; |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 613 | else |
| 614 | -- According to PRMs, VGA plane is the only thing |
| Nico Huber | 3a0e2a0 | 2017-07-19 14:41:46 +0200 | [diff] [blame] | 615 | -- that's enabled by default after reset... |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 616 | Display_Controller.Legacy_VGA_Off; |
| Nico Huber | 3a0e2a0 | 2017-07-19 14:41:46 +0200 | [diff] [blame] | 617 | -- ... along with some DDI port bits since Skylake. |
| 618 | Connectors.Post_Reset_Off; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 619 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 620 | |
| 621 | -------------------- Now restart from a clean state --------------------- |
| 622 | Power_And_Clocks.Initialize; |
| 623 | |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 624 | if Config.Has_PCH then |
| 625 | Registers.Unset_And_Set_Mask |
| 626 | (Register => Registers.PCH_RAWCLK_FREQ, |
| 627 | Mask_Unset => PCH_RAWCLK_FREQ_MASK, |
| Nico Huber | c9ad9de | 2020-12-20 02:34:37 +0100 | [diff] [blame] | 628 | Mask_Set => PCH_RAWCLK_FREQ (Config.Raw_Clock)); |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 629 | end if; |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 630 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 631 | Initialized := True; |
| 632 | |
| 633 | end Initialize; |
| Nico Huber | 793f4f8 | 2022-09-04 14:24:00 +0000 | [diff] [blame] | 634 | pragma Annotate |
| 635 | (GNATprove, Intentional, "unused global", |
| 636 | "The whole, abstract Device_State is modified in certain configurations."); |
| 637 | pragma Warnings (GNATprove, On, "no check message justified*"); |
| 638 | pragma Warnings |
| 639 | (GNATprove, On, """Registers.GTT_State"" * is not modified*"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 640 | |
| 641 | function Is_Initialized return Boolean |
| 642 | with |
| 643 | Refined_Post => Is_Initialized'Result = Initialized |
| 644 | is |
| 645 | begin |
| 646 | return Initialized; |
| 647 | end Is_Initialized; |
| 648 | |
| 649 | ---------------------------------------------------------------------------- |
| 650 | |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 651 | pragma Warnings |
| 652 | (GNATprove, Off, """Registers.Register_State"" * is not modified*", |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 653 | Reason => "Power_Up_VGA is only effective in certain configurations."); |
| Nico Huber | 17b513e | 2022-09-04 13:36:02 +0200 | [diff] [blame] | 654 | pragma Warnings |
| 655 | (GNATprove, Off, "no check message justified*", Reason => "see below"); |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 656 | procedure Power_Up_VGA |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 657 | with |
| 658 | Refined_Global => |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 659 | (Input => (Cur_Configs, Config.Variable, Time.State), |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 660 | In_Out => (Registers.Register_State), |
| 661 | Proof_In => (Initialized)) |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 662 | is |
| 663 | Fake_Config : constant Pipe_Configs := |
| 664 | (Primary => |
| 665 | (Port => Analog, |
| 666 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 667 | Cursor => Default_Cursor, |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 668 | Mode => HW.GFX.Invalid_Mode), |
| 669 | others => |
| 670 | (Port => Disabled, |
| 671 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame] | 672 | Cursor => Default_Cursor, |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 673 | Mode => HW.GFX.Invalid_Mode)); |
| 674 | begin |
| 675 | Power_And_Clocks.Power_Up (Cur_Configs, Fake_Config); |
| 676 | end Power_Up_VGA; |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 677 | pragma Annotate |
| 678 | (GNATprove, Intentional, "unused global", |
| Nico Huber | adfe11f | 2018-06-10 14:59:04 +0200 | [diff] [blame] | 679 | "Power_Up_VGA is only effective in certain configurations."); |
| Nico Huber | cf88f3d | 2018-06-05 13:27:34 +0200 | [diff] [blame] | 680 | pragma Warnings (GNATprove, On, "no check message justified*"); |
| 681 | pragma Warnings |
| 682 | (GNATprove, On, """Registers.Register_State"" * is not modified*"); |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 683 | |
| 684 | ---------------------------------------------------------------------------- |
| 685 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 686 | function FB_First_Page (FB : Framebuffer_Type) return Natural is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 687 | (Natural (Phys_Offset (FB) / GTT_Page_Size)); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 688 | function FB_Pages (FB : Framebuffer_Type) return Natural is |
| 689 | (Natural (Div_Round_Up (FB_Size (FB), GTT_Page_Size))); |
| 690 | function FB_Last_Page (FB : Framebuffer_Type) return Natural is |
| 691 | (FB_First_Page (FB) + FB_Pages (FB) - 1); |
| 692 | |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 693 | -- Check basics and that it fits in GTT. For 90 degree rotations, |
| 694 | -- the Offset should be above GTT_Rotation_Offset. The latter will |
| 695 | -- be subtracted for the aperture mapping. |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 696 | function Valid_FB (FB : Framebuffer_Type) return Boolean is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 697 | (Valid_Stride (FB) and |
| 698 | FB_First_Page (FB) in GTT_Range and |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 699 | FB_Last_Page (FB) + 128 in GTT_Range and |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 700 | (not Rotation_90 (FB) or |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 701 | (FB_First_Page (FB) mod 64 = 0 and |
| 702 | FB_Last_Page (FB) + 128 + GTT_Rotation_Offset in GTT_Range and |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 703 | FB.Offset >= Word32 (GTT_Rotation_Offset) * GTT_Page_Size))); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 704 | |
| 705 | -- Also check that we don't overflow the GTT's 39-bit space |
| 706 | -- (always true with a 32-bit base) |
| 707 | function Valid_Phys_FB (FB : Framebuffer_Type; Phys_Base : Word32) |
| 708 | return Boolean is |
| 709 | (Valid_FB (FB) and |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 710 | Int64 (Phys_Base) + Int64 (Phys_Offset (FB)) + Int64 (FB_Size (FB)) <= |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 711 | Int64 (GTT_Address_Type'Last)) |
| 712 | with |
| 713 | Ghost; |
| 714 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 715 | procedure Write_GTT |
| 716 | (GTT_Page : GTT_Range; |
| 717 | Device_Address : GTT_Address_Type; |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 718 | Valid : Boolean) |
| 719 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 720 | begin |
| 721 | Registers.Write_GTT (GTT_Page, Device_Address, Valid); |
| 722 | end Write_GTT; |
| 723 | |
| Nico Huber | ceda17d | 2018-06-09 22:00:29 +0200 | [diff] [blame] | 724 | procedure Read_GTT |
| 725 | (Device_Address : out GTT_Address_Type; |
| 726 | Valid : out Boolean; |
| 727 | GTT_Page : in GTT_Range) |
| 728 | is |
| 729 | begin |
| 730 | Registers.Read_GTT (Device_Address, Valid, GTT_Page); |
| 731 | end Read_GTT; |
| 732 | |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 733 | procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_Base : Word32) |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 734 | with |
| 735 | Pre => Is_Initialized and Valid_Phys_FB (FB, Phys_Base) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 736 | is |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 737 | Phys_Addr : GTT_Address_Type := |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 738 | GTT_Address_Type (Phys_Base) + GTT_Address_Type (Phys_Offset (FB)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 739 | begin |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 740 | for Idx in FB_First_Page (FB) .. FB_Last_Page (FB) loop |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 741 | Registers.Write_GTT |
| 742 | (GTT_Page => Idx, |
| 743 | Device_Address => Phys_Addr, |
| 744 | Valid => True); |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 745 | Phys_Addr := Phys_Addr + GTT_Page_Size; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 746 | end loop; |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 747 | -- Add another 128 dummy pages to work around buggy VT-d |
| 748 | for Idx in FB_Last_Page (FB) + 1 .. FB_Last_Page (FB) + 128 loop |
| 749 | Registers.Write_GTT (Idx, Phys_Addr, True); |
| 750 | end loop; |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 751 | |
| 752 | if Rotation_90 (FB) and FB.Tiling = Y_Tiled and FB.V_Stride >= 32 then |
| 753 | declare |
| 754 | V_Pages : constant Natural := Natural (FB.V_Stride) / 32; |
| 755 | Bytes_Per_Row : constant GTT_Address_Type := |
| 756 | GTT_Address_Type (Pixel_To_Bytes (32 * FB.Stride, FB)); |
| 757 | begin |
| 758 | Phys_Addr := GTT_Address_Type (Phys_Base) + |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 759 | GTT_Address_Type (Phys_Offset (FB)) + |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 760 | GTT_Address_Type (FB_Size (FB)); |
| 761 | for Page in FB_First_Page (FB) .. FB_Last_Page (FB) loop |
| 762 | Phys_Addr := Phys_Addr - Bytes_Per_Row; |
| 763 | Registers.Write_GTT |
| 764 | (GTT_Page => GTT_Rotation_Offset + Page, |
| 765 | Device_Address => Phys_Addr, |
| 766 | Valid => True); |
| 767 | |
| 768 | if (Page - FB_First_Page (FB) + 1) mod V_Pages = 0 then |
| 769 | Phys_Addr := Phys_Addr + GTT_Page_Size + |
| 770 | GTT_Address_Type (V_Pages) * Bytes_Per_Row; |
| 771 | end if; |
| 772 | end loop; |
| 773 | end; |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 774 | -- Add another 128 dummy pages to work around buggy VT-d |
| 775 | for Idx in FB_Last_Page (FB) + 1 .. FB_Last_Page (FB) + 128 loop |
| 776 | Registers.Write_GTT (GTT_Rotation_Offset + Idx, Phys_Addr, True); |
| 777 | end loop; |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 778 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 779 | end Setup_Default_GTT; |
| 780 | |
| 781 | ---------------------------------------------------------------------------- |
| 782 | |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 783 | use type HW.Word16; |
| 784 | subtype Stolen_Size_Range is Int64 range 0 .. 2 ** 33; |
| 785 | |
| 786 | function GGMS_Gen4 (GGC : Word16) return Natural is |
| 787 | (Natural (Shift_Right (GGC, 8) and 16#07#)); |
| 788 | function GTT_Size_Gen4 (GGC : Word16) return Natural is |
| 789 | (if GGMS_Gen4 (GGC) in 1 .. 3 then |
| 790 | (GGMS_Gen4 (GGC) + 1) * 2 ** 19 else 0); |
| 791 | |
| 792 | function GMS_Gen4 (GGC : Word16) return Natural is |
| 793 | (Natural (Shift_Right (GGC, 4) and 16#0f#)); |
| 794 | Valid_Stolen_Size_Gen4 : constant |
| 795 | array (Natural range 1 .. 13) of Stolen_Size_Range := |
| 796 | (1, 4, 8, 16, 32, 48, 64, 128, 256, 96, 160, 224, 352); |
| 797 | function Stolen_Size_Gen4 (GGC : Word16) return Stolen_Size_Range is |
| 798 | (if GMS_Gen4 (GGC) in Valid_Stolen_Size_Gen4'Range then |
| Arthur Heymans | 5fd9a31 | 2017-09-12 12:45:18 +0200 | [diff] [blame] | 799 | Valid_Stolen_Size_Gen4 (GMS_Gen4 (GGC)) * 2 ** 20 else 0); |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 800 | |
| 801 | function GTT_Size_Gen6 (GGC : Word16) return Natural is |
| 802 | (Natural (Shift_Right (GGC, 8) and 16#03#) * 2 ** 20); |
| 803 | |
| 804 | function Stolen_Size_Gen6 (GGC : Word16) return Stolen_Size_Range is |
| 805 | (Stolen_Size_Range (Shift_Right (GGC, 3) and 16#1f#) * 32 * 2 ** 20); |
| 806 | |
| Nico Huber | fe7985f | 2019-10-12 22:19:24 +0200 | [diff] [blame] | 807 | function GGMS_Gen8 (GGC : Word16) return Natural is |
| 808 | (Natural (Shift_Right (GGC, 6) and 16#03#)); |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 809 | function GTT_Size_Gen8 (GGC : Word16) return Natural is |
| Nico Huber | fe7985f | 2019-10-12 22:19:24 +0200 | [diff] [blame] | 810 | (if GGMS_Gen8 (GGC) /= 0 then |
| 811 | Natural (Shift_Left (Word32'(1), 20 + GGMS_Gen8 (GGC))) else 0); |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 812 | |
| 813 | function GMS_Gen8 (GGC : Word16) return Stolen_Size_Range is |
| 814 | (Stolen_Size_Range (Shift_Right (GGC, 8) and 16#ff#)); |
| 815 | function Stolen_Size_Gen8 (GGC : Word16) return Stolen_Size_Range is |
| 816 | (GMS_Gen8 (GGC) * 32 * 2 ** 20); |
| 817 | |
| 818 | function Stolen_Size_Gen9 (GGC : Word16) return Stolen_Size_Range is |
| 819 | (if GMS_Gen8 (GGC) < 16#f0# then |
| 820 | Stolen_Size_Gen8 (GGC) |
| 821 | else |
| 822 | (GMS_Gen8 (GGC) - 16#f0# + 1) * 4 * 2 ** 20); |
| 823 | |
| 824 | procedure Decode_Stolen |
| 825 | (GTT_Size : out Natural; |
| 826 | Stolen_Size : out Stolen_Size_Range) |
| 827 | with |
| 828 | Pre => Is_Initialized |
| 829 | is |
| Nico Huber | 63ec836 | 2018-06-09 17:42:19 +0200 | [diff] [blame] | 830 | GGC_Reg : constant PCI.Index := |
| Nico Huber | 998ee2b | 2018-06-12 23:02:17 +0200 | [diff] [blame] | 831 | (if Config.Gen_G45 or Config.CPU_Ironlake then 16#52# else 16#50#); |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 832 | GGC : Word16; |
| 833 | begin |
| 834 | Dev.Read16 (GGC, GGC_Reg); |
| Nico Huber | 998ee2b | 2018-06-12 23:02:17 +0200 | [diff] [blame] | 835 | if Config.Gen_G45 or Config.CPU_Ironlake then |
| 836 | GTT_Size := GTT_Size_Gen4 (GGC); |
| 837 | Stolen_Size := Stolen_Size_Gen4 (GGC); |
| 838 | elsif Config.CPU_Sandybridge or Config.CPU_Ivybridge or Config.CPU_Haswell |
| 839 | then |
| 840 | GTT_Size := GTT_Size_Gen6 (GGC); |
| 841 | Stolen_Size := Stolen_Size_Gen6 (GGC); |
| 842 | elsif Config.CPU_Broadwell then |
| 843 | GTT_Size := GTT_Size_Gen8 (GGC); |
| 844 | Stolen_Size := Stolen_Size_Gen8 (GGC); |
| 845 | else |
| 846 | GTT_Size := GTT_Size_Gen8 (GGC); |
| 847 | Stolen_Size := Stolen_Size_Gen9 (GGC); |
| 848 | end if; |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 849 | end Decode_Stolen; |
| 850 | |
| 851 | -- Additional runtime validation that FB fits stolen memory and aperture. |
| 852 | procedure Validate_FB (FB : Framebuffer_Type; Valid : out Boolean) |
| 853 | with |
| 854 | Pre => Is_Initialized, |
| 855 | Post => (if Valid then Valid_FB (FB)) |
| 856 | is |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 857 | GTT_Off : constant Natural := |
| 858 | (if Rotation_90 (FB) then GTT_Rotation_Offset else 0); |
| 859 | |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 860 | GTT_Size, Aperture_Size : Natural; |
| 861 | Stolen_Size : Stolen_Size_Range; |
| 862 | begin |
| 863 | Valid := Valid_FB (FB); |
| 864 | |
| 865 | if Valid then |
| 866 | Decode_Stolen (GTT_Size, Stolen_Size); |
| 867 | Dev.Resource_Size (Aperture_Size, PCI.Res2); |
| 868 | Valid := |
| Nico Huber | 2e87c0d | 2020-04-18 00:46:39 +0200 | [diff] [blame] | 869 | FB_Last_Page (FB) + 128 + GTT_Off < GTT_Size / Config.GTT_PTE_Size |
| 870 | and |
| 871 | FB_Last_Page (FB) < Natural (Stolen_Size / GTT_Page_Size) |
| 872 | and |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 873 | FB_Last_Page (FB) < Aperture_Size / GTT_Page_Size; |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 874 | pragma Debug (not Valid, Debug.Put_Line |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 875 | ("Stolen memory too small to hold framebuffer.")); |
| 876 | end if; |
| 877 | end Validate_FB; |
| 878 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 879 | procedure Setup_Default_FB |
| 880 | (FB : in Framebuffer_Type; |
| 881 | Clear : in Boolean := True; |
| 882 | Success : out Boolean) |
| 883 | is |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 884 | GMA_Phys_Base_Mask : constant := 16#fff0_0000#; |
| 885 | |
| 886 | Phys_Base : Word32; |
| 887 | begin |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 888 | Validate_FB (FB, Success); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 889 | |
| 890 | if Success then |
| Tim Wawrzynczak | 1b65b84 | 2022-09-09 10:23:06 -0600 | [diff] [blame] | 891 | if Config.GMA_Base_Is_64bit then |
| 892 | Dev.Read32 (Phys_Base, Config.GMA_Phys_Base_Index + 4); |
| 893 | if Phys_Base /= 0 then |
| 894 | pragma Debug (Debug.Put_Line ("Cannot handle 64-bit DSM yet.")); |
| 895 | Success := False; |
| 896 | return; |
| 897 | end if; |
| 898 | end if; |
| 899 | |
| 900 | Dev.Read32 (Phys_Base, Config.GMA_Phys_Base_Index); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 901 | Phys_Base := Phys_Base and GMA_Phys_Base_Mask; |
| 902 | Success := Phys_Base /= GMA_Phys_Base_Mask and Phys_Base /= 0; |
| 903 | pragma Debug (not Success, Debug.Put_Line |
| 904 | ("Failed to read stolen memory base.")); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 905 | |
| 906 | if Success then |
| 907 | if FB.Tiling in XY_Tiling then |
| 908 | Registers.Add_Fence |
| 909 | (First_Page => FB_First_Page (FB), |
| 910 | Last_Page => FB_Last_Page (FB), |
| 911 | Tiling => FB.Tiling, |
| 912 | Pitch => FB_Pitch (FB.Stride, FB), |
| 913 | Success => Success); |
| 914 | end if; |
| 915 | pragma Debug (not Success, Debug.Put_Line |
| 916 | ("Tiled framebuffer but no fence regs available.")); |
| 917 | end if; |
| 918 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 919 | if Success then |
| 920 | Setup_Default_GTT (FB, Phys_Base); |
| 921 | end if; |
| 922 | end if; |
| 923 | |
| 924 | if Success and then Clear then |
| 925 | declare |
| 926 | use type HW.Word64; |
| 927 | Linear_FB : Word64; |
| 928 | begin |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 929 | Map_Linear_FB (Linear_FB, FB); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 930 | if Linear_FB /= 0 then |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 931 | Framebuffer_Filler.Fill (Linear_FB, FB); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 932 | end if; |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 933 | end; |
| 934 | end if; |
| 935 | end Setup_Default_FB; |
| 936 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 937 | procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type) |
| 938 | is |
| 939 | use type HW.Word64; |
| 940 | |
| 941 | Valid : Boolean; |
| 942 | begin |
| 943 | Linear_FB := 0; |
| 944 | |
| 945 | if Linear_FB_Base = 0 then |
| 946 | Dev.Map (Linear_FB_Base, PCI.Res2); |
| 947 | pragma Debug |
| 948 | (Linear_FB_Base = 0, Debug.Put_Line ("Failed to map resource2.")); |
| 949 | end if; |
| 950 | |
| 951 | if Linear_FB_Base /= 0 then |
| 952 | Validate_FB (FB, Valid); |
| 953 | if Valid then |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 954 | Linear_FB := Linear_FB_Base + Word64 (Phys_Offset (FB)); |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 955 | end if; |
| 956 | end if; |
| 957 | end Map_Linear_FB; |
| 958 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 959 | ---------------------------------------------------------------------------- |
| 960 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 961 | procedure Dump_Configs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 962 | is |
| 963 | subtype Pipe_Name is String (1 .. 9); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 964 | type Pipe_Name_Array is array (Pipe_Index) of Pipe_Name; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 965 | Pipe_Names : constant Pipe_Name_Array := |
| 966 | (Primary => "Primary ", |
| 967 | Secondary => "Secondary", |
| 968 | Tertiary => "Tertiary "); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 969 | |
| 970 | subtype Tiling_Name is String (1 .. 7); |
| 971 | type Tiling_Name_Array is array (Tiling_Type) of Tiling_Name; |
| 972 | Tilings : constant Tiling_Name_Array := |
| 973 | (Linear => "Linear ", |
| 974 | X_Tiled => "X_Tiled", |
| 975 | Y_Tiled => "Y_Tiled"); |
| 976 | |
| 977 | subtype Rotation_Name is String (1 .. 11); |
| 978 | type Rotation_Name_Array is array (Rotation_Type) of Rotation_Name; |
| 979 | Rotations : constant Rotation_Name_Array := |
| 980 | (No_Rotation => "No_Rotation", |
| 981 | Rotated_90 => "Rotated_90 ", |
| 982 | Rotated_180 => "Rotated_180", |
| 983 | Rotated_270 => "Rotated_270"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 984 | begin |
| 985 | Debug.New_Line; |
| Paul Menzel | b83107c | 2017-05-04 09:02:33 +0200 | [diff] [blame] | 986 | Debug.Put_Line ("CONFIG =>"); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 987 | for Pipe in Pipe_Index loop |
| 988 | if Pipe = Pipe_Index'First then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 989 | Debug.Put (" ("); |
| 990 | else |
| 991 | Debug.Put (" "); |
| 992 | end if; |
| 993 | Debug.Put_Line (Pipe_Names (Pipe) & " =>"); |
| 994 | Debug.Put_Line |
| 995 | (" (Port => " & Port_Names (Configs (Pipe).Port) & ","); |
| 996 | Debug.Put_Line (" Framebuffer =>"); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 997 | Debug.Put (" (Width => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 998 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width); |
| 999 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 1000 | Debug.Put (" Height => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1001 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height); |
| 1002 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 1003 | Debug.Put (" Start_X => "); |
| 1004 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_X); |
| 1005 | Debug.Put_Line (","); |
| 1006 | Debug.Put (" Start_Y => "); |
| 1007 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_Y); |
| 1008 | Debug.Put_Line (","); |
| 1009 | Debug.Put (" Stride => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1010 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride); |
| 1011 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 1012 | Debug.Put (" V_Stride => "); |
| 1013 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.V_Stride); |
| 1014 | Debug.Put_Line (","); |
| 1015 | Debug.Put (" Tiling => "); |
| 1016 | Debug.Put_Line (Tilings (Configs (Pipe).Framebuffer.Tiling) & ","); |
| 1017 | Debug.Put (" Rotation => "); |
| 1018 | Debug.Put_Line (Rotations (Configs (Pipe).Framebuffer.Rotation) & ","); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1019 | Debug.Put (" Offset => "); |
| 1020 | Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset); |
| 1021 | Debug.Put_Line (","); |
| 1022 | Debug.Put (" BPC => "); |
| 1023 | Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC); |
| 1024 | Debug.Put_Line ("),"); |
| 1025 | Debug.Put_Line (" Mode =>"); |
| 1026 | Debug.Put (" (Dotclock => "); |
| 1027 | Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock); |
| 1028 | Debug.Put_Line (","); |
| 1029 | Debug.Put (" H_Visible => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1030 | Debug.Put_Int32 (Configs (Pipe).Mode.H_Visible); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1031 | Debug.Put_Line (","); |
| 1032 | Debug.Put (" H_Sync_Begin => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1033 | Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_Begin); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1034 | Debug.Put_Line (","); |
| 1035 | Debug.Put (" H_Sync_End => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1036 | Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_End); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1037 | Debug.Put_Line (","); |
| 1038 | Debug.Put (" H_Total => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1039 | Debug.Put_Int32 (Configs (Pipe).Mode.H_Total); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1040 | Debug.Put_Line (","); |
| 1041 | Debug.Put (" V_Visible => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1042 | Debug.Put_Int32 (Configs (Pipe).Mode.V_Visible); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1043 | Debug.Put_Line (","); |
| 1044 | Debug.Put (" V_Sync_Begin => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1045 | Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_Begin); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1046 | Debug.Put_Line (","); |
| 1047 | Debug.Put (" V_Sync_End => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1048 | Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_End); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1049 | Debug.Put_Line (","); |
| 1050 | Debug.Put (" V_Total => "); |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 1051 | Debug.Put_Int32 (Configs (Pipe).Mode.V_Total); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1052 | Debug.Put_Line (","); |
| 1053 | Debug.Put_Line (" H_Sync_Active_High => " & |
| 1054 | (if Configs (Pipe).Mode.H_Sync_Active_High |
| 1055 | then "True," |
| 1056 | else "False,")); |
| 1057 | Debug.Put_Line (" V_Sync_Active_High => " & |
| 1058 | (if Configs (Pipe).Mode.V_Sync_Active_High |
| 1059 | then "True," |
| 1060 | else "False,")); |
| 1061 | Debug.Put (" BPC => "); |
| 1062 | Debug.Put_Int64 (Configs (Pipe).Mode.BPC); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 1063 | if Pipe /= Pipe_Index'Last then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1064 | Debug.Put_Line (")),"); |
| 1065 | else |
| 1066 | Debug.Put_Line (")));"); |
| 1067 | end if; |
| 1068 | end loop; |
| 1069 | end Dump_Configs; |
| 1070 | |
| Nico Huber | c5c66ec | 2019-09-28 23:59:45 +0200 | [diff] [blame] | 1071 | ---------------------------------------------------------------------------- |
| 1072 | |
| 1073 | procedure PCI_Read16 (Value : out Word16; Offset : HW.PCI.Index) is |
| 1074 | begin |
| 1075 | Dev.Read16 (Value, Offset); |
| 1076 | end PCI_Read16; |
| 1077 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1078 | end HW.GFX.GMA; |