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