| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 2 | -- Copyright (C) 2014-2017 secunet Security Networks AG |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- 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] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 15 | with HW.GFX.GMA.Config; |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 16 | with HW.GFX.GMA.Config_Helpers; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 17 | with HW.GFX.GMA.Registers; |
| 18 | with HW.GFX.GMA.Power_And_Clocks; |
| 19 | with HW.GFX.GMA.Panel; |
| 20 | with HW.GFX.GMA.PLLs; |
| 21 | with HW.GFX.GMA.Port_Detect; |
| 22 | with HW.GFX.GMA.Connectors; |
| 23 | with HW.GFX.GMA.Connector_Info; |
| 24 | with HW.GFX.GMA.Pipe_Setup; |
| 25 | |
| 26 | with System; |
| 27 | |
| 28 | with HW.Debug; |
| 29 | with GNAT.Source_Info; |
| 30 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 31 | use type HW.Int32; |
| 32 | |
| 33 | package body HW.GFX.GMA |
| 34 | with Refined_State => |
| 35 | (State => |
| 36 | (Registers.Address_State, |
| 37 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 38 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 39 | HPD_Delay, Wait_For_HPD), |
| 40 | Init_State => Initialized, |
| 41 | Config_State => Config.Valid_Port_GPU, |
| 42 | Device_State => |
| 43 | (Registers.Register_State, Registers.GTT_State)) |
| 44 | is |
| 45 | |
| 46 | subtype Port_Name is String (1 .. 8); |
| 47 | type Port_Name_Array is array (Port_Type) of Port_Name; |
| 48 | Port_Names : constant Port_Name_Array := |
| 49 | (Disabled => "Disabled", |
| 50 | Internal => "Internal", |
| 51 | DP1 => "DP1 ", |
| 52 | DP2 => "DP2 ", |
| 53 | DP3 => "DP3 ", |
| Nico Huber | 0d454cd | 2016-11-21 13:33:43 +0100 | [diff] [blame] | 54 | HDMI1 => "HDMI1 ", |
| 55 | HDMI2 => "HDMI2 ", |
| 56 | HDMI3 => "HDMI3 ", |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 57 | Analog => "Analog "); |
| 58 | |
| 59 | package Display_Controller renames Pipe_Setup; |
| 60 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 61 | type PLLs_Type is array (Pipe_Index) of PLLs.T; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 62 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 63 | type HPD_Type is array (Port_Type) of Boolean; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 64 | type HPD_Delay_Type is array (Active_Port_Type) of Time.T; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 65 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 66 | Allocated_PLLs : PLLs_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 67 | HPD_Delay : HPD_Delay_Type; |
| 68 | Wait_For_HPD : HPD_Type; |
| 69 | Initialized : Boolean := False; |
| 70 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 71 | ---------------------------------------------------------------------------- |
| 72 | |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 73 | PCH_RAWCLK_FREQ_MASK : constant := 16#3ff# * 2 ** 0; |
| 74 | |
| 75 | function PCH_RAWCLK_FREQ (Freq : Frequency_Type) return Word32 |
| 76 | is |
| 77 | begin |
| 78 | return Word32 (Freq / 1_000_000); |
| 79 | end PCH_RAWCLK_FREQ; |
| 80 | |
| 81 | ---------------------------------------------------------------------------- |
| 82 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 83 | procedure Enable_Output |
| 84 | (Pipe : in Pipe_Index; |
| 85 | Pipe_Cfg : in Pipe_Config; |
| 86 | Success : out Boolean) |
| 87 | is |
| 88 | Port_Cfg : Port_Config; |
| 89 | begin |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 90 | pragma Debug (Debug.New_Line); |
| 91 | pragma Debug (Debug.Put_Line |
| 92 | ("Trying to enable port " & Port_Names (Pipe_Cfg.Port))); |
| 93 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 94 | Config_Helpers.Fill_Port_Config |
| 95 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 96 | |
| 97 | if Success then |
| 98 | Success := Config_Helpers.Validate_Config |
| 99 | (Pipe_Cfg.Framebuffer, Port_Cfg, Pipe); |
| 100 | end if; |
| 101 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 102 | if Success then |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 103 | Connector_Info.Preferred_Link_Setting (Port_Cfg, Success); |
| 104 | end if; |
| 105 | |
| 106 | -- loop over all possible DP-lane configurations |
| 107 | -- (non-DP ports use a single fake configuration) |
| 108 | while Success loop |
| 109 | pragma Loop_Invariant |
| 110 | (Pipe_Cfg.Port in Active_Port_Type and |
| 111 | Port_Cfg.Mode = Port_Cfg.Mode'Loop_Entry); |
| 112 | |
| 113 | PLLs.Alloc |
| 114 | (Port_Cfg => Port_Cfg, |
| 115 | PLL => Allocated_PLLs (Pipe), |
| 116 | Success => Success); |
| 117 | |
| 118 | if Success then |
| 119 | -- try each DP-lane configuration twice |
| 120 | for Try in 1 .. 2 loop |
| 121 | pragma Loop_Invariant |
| 122 | (Pipe_Cfg.Port in Active_Port_Type); |
| 123 | |
| Nico Huber | 4798c66 | 2017-01-11 12:44:48 +0100 | [diff] [blame] | 124 | -- Clear pending hot-plug events before every try |
| 125 | Port_Detect.Clear_Hotplug_Detect (Pipe_Cfg.Port); |
| 126 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 127 | Connectors.Pre_On |
| 128 | (Pipe => Pipe, |
| 129 | Port_Cfg => Port_Cfg, |
| 130 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 131 | Success => Success); |
| 132 | |
| 133 | if Success then |
| 134 | Display_Controller.On |
| 135 | (Pipe => Pipe, |
| 136 | Port_Cfg => Port_Cfg, |
| 137 | Framebuffer => Pipe_Cfg.Framebuffer); |
| 138 | |
| 139 | Connectors.Post_On |
| 140 | (Port_Cfg => Port_Cfg, |
| 141 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 142 | Success => Success); |
| 143 | |
| 144 | if not Success then |
| 145 | Display_Controller.Off (Pipe); |
| 146 | Connectors.Post_Off (Port_Cfg); |
| 147 | end if; |
| 148 | end if; |
| 149 | |
| 150 | exit when Success; |
| 151 | end loop; |
| 152 | exit when Success; -- connection established => stop loop |
| 153 | |
| 154 | -- connection failed |
| 155 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 156 | end if; |
| 157 | |
| 158 | Connector_Info.Next_Link_Setting (Port_Cfg, Success); |
| 159 | end loop; |
| 160 | |
| 161 | if Success then |
| 162 | pragma Debug (Debug.Put_Line |
| 163 | ("Enabled port " & Port_Names (Pipe_Cfg.Port))); |
| 164 | else |
| 165 | Wait_For_HPD (Pipe_Cfg.Port) := True; |
| 166 | if Pipe_Cfg.Port = Internal then |
| 167 | Panel.Off; |
| 168 | end if; |
| 169 | end if; |
| 170 | end Enable_Output; |
| 171 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 172 | procedure Disable_Output (Pipe : Pipe_Index; Pipe_Cfg : Pipe_Config) |
| 173 | is |
| 174 | Port_Cfg : Port_Config; |
| 175 | Success : Boolean; |
| 176 | begin |
| 177 | Config_Helpers.Fill_Port_Config |
| 178 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 179 | if Success then |
| 180 | pragma Debug (Debug.New_Line); |
| 181 | pragma Debug (Debug.Put_Line |
| 182 | ("Disabling port " & Port_Names (Pipe_Cfg.Port))); |
| 183 | pragma Debug (Debug.New_Line); |
| 184 | |
| 185 | Connectors.Pre_Off (Port_Cfg); |
| 186 | Display_Controller.Off (Pipe); |
| 187 | Connectors.Post_Off (Port_Cfg); |
| 188 | |
| 189 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 190 | end if; |
| 191 | end Disable_Output; |
| 192 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 193 | procedure Update_Outputs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 194 | is |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 195 | procedure Check_HPD (Port : in Active_Port_Type; Detected : out Boolean) |
| 196 | is |
| 197 | HPD_Delay_Over : constant Boolean := Time.Timed_Out (HPD_Delay (Port)); |
| 198 | begin |
| 199 | if HPD_Delay_Over then |
| 200 | Port_Detect.Hotplug_Detect (Port, Detected); |
| 201 | HPD_Delay (Port) := Time.MS_From_Now (333); |
| 202 | else |
| 203 | Detected := False; |
| 204 | end if; |
| 205 | end Check_HPD; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 206 | |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 207 | Power_Changed : Boolean := False; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 208 | Old_Configs : Pipe_Configs; |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 209 | |
| 210 | -- Only called when we actually tried to change something |
| 211 | -- so we don't congest the log with unnecessary messages. |
| 212 | procedure Update_Power |
| 213 | is |
| 214 | begin |
| 215 | if not Power_Changed then |
| 216 | Power_And_Clocks.Power_Up (Old_Configs, Configs); |
| 217 | Power_Changed := True; |
| 218 | end if; |
| 219 | end Update_Power; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 220 | begin |
| 221 | Old_Configs := Cur_Configs; |
| 222 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 223 | -- disable all pipes that changed or had a hot-plug event |
| 224 | for Pipe in Pipe_Index loop |
| 225 | declare |
| 226 | Unplug_Detected : Boolean; |
| 227 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| 228 | New_Config : Pipe_Config renames Configs (Pipe); |
| 229 | begin |
| 230 | if Cur_Config.Port /= Disabled then |
| 231 | Check_HPD (Cur_Config.Port, Unplug_Detected); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 232 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 233 | if Cur_Config.Port /= New_Config.Port or |
| 234 | Cur_Config.Mode /= New_Config.Mode or |
| 235 | Unplug_Detected |
| 236 | then |
| 237 | Disable_Output (Pipe, Cur_Config); |
| 238 | Cur_Config.Port := Disabled; |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 239 | Update_Power; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 240 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 241 | end if; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 242 | end; |
| 243 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 244 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 245 | -- enable all pipes that changed and should be active |
| 246 | for Pipe in Pipe_Index loop |
| 247 | declare |
| 248 | Success : Boolean; |
| 249 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| 250 | New_Config : Pipe_Config renames Configs (Pipe); |
| 251 | begin |
| 252 | if New_Config.Port /= Disabled and then |
| 253 | (Cur_Config.Port /= New_Config.Port or |
| 254 | Cur_Config.Mode /= New_Config.Mode) |
| 255 | then |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 256 | if Wait_For_HPD (New_Config.Port) then |
| 257 | Check_HPD (New_Config.Port, Success); |
| 258 | Wait_For_HPD (New_Config.Port) := not Success; |
| 259 | else |
| 260 | Success := True; |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 261 | end if; |
| Nico Huber | c7a4fee | 2016-11-03 18:18:03 +0100 | [diff] [blame] | 262 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 263 | if Success then |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 264 | Update_Power; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 265 | Enable_Output (Pipe, New_Config, Success); |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 266 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 267 | |
| 268 | if Success then |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 269 | Cur_Config := New_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 270 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 271 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 272 | -- update framebuffer offset only |
| 273 | elsif New_Config.Port /= Disabled and |
| 274 | Cur_Config.Framebuffer /= New_Config.Framebuffer |
| 275 | then |
| 276 | Display_Controller.Update_Offset (Pipe, New_Config.Framebuffer); |
| 277 | Cur_Config := New_Config; |
| 278 | end if; |
| 279 | end; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 280 | end loop; |
| 281 | |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 282 | if Power_Changed then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 283 | Power_And_Clocks.Power_Down (Old_Configs, Configs, Cur_Configs); |
| 284 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 285 | end Update_Outputs; |
| 286 | |
| 287 | ---------------------------------------------------------------------------- |
| 288 | |
| 289 | procedure Initialize |
| 290 | (MMIO_Base : in Word64 := 0; |
| 291 | Write_Delay : in Word64 := 0; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 292 | Clean_State : in Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 293 | Success : out Boolean) |
| 294 | with |
| 295 | Refined_Global => |
| 296 | (In_Out => |
| 297 | (Config.Valid_Port_GPU, |
| 298 | Registers.Register_State, Port_IO.State), |
| 299 | Input => |
| 300 | (Time.State), |
| 301 | Output => |
| 302 | (Registers.Address_State, |
| 303 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 304 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 305 | HPD_Delay, Wait_For_HPD, Initialized)) |
| 306 | is |
| 307 | use type HW.Word64; |
| 308 | |
| 309 | Now : constant Time.T := Time.Now; |
| 310 | |
| 311 | procedure Check_Platform (Success : out Boolean) |
| 312 | is |
| 313 | Audio_VID_DID : Word32; |
| 314 | begin |
| 315 | case Config.CPU is |
| 316 | when Haswell .. Skylake => |
| 317 | Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID); |
| 318 | when Ironlake .. Ivybridge => |
| 319 | Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID); |
| 320 | end case; |
| 321 | Success := |
| 322 | (case Config.CPU is |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 323 | when Broxton => Audio_VID_DID = 16#8086_280a#, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 324 | when Skylake => Audio_VID_DID = 16#8086_2809#, |
| 325 | when Broadwell => Audio_VID_DID = 16#8086_2808#, |
| 326 | when Haswell => Audio_VID_DID = 16#8086_2807#, |
| 327 | when Ivybridge | |
| 328 | Sandybridge => Audio_VID_DID = 16#8086_2806# or |
| 329 | Audio_VID_DID = 16#8086_2805#, |
| Nico Huber | eeb5a39 | 2016-10-09 19:28:30 +0200 | [diff] [blame] | 330 | when Ironlake => Audio_VID_DID = 16#0000_0000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 331 | end Check_Platform; |
| 332 | begin |
| 333 | pragma Warnings (GNATprove, Off, "unused variable ""Write_Delay""", |
| 334 | Reason => "Write_Delay is used for debugging only"); |
| 335 | |
| 336 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 337 | |
| 338 | pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay)); |
| 339 | |
| 340 | Wait_For_HPD := HPD_Type'(others => False); |
| 341 | HPD_Delay := HPD_Delay_Type'(others => Now); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 342 | Allocated_PLLs := (others => PLLs.Invalid); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 343 | Cur_Configs := Pipe_Configs' |
| 344 | (others => Pipe_Config' |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 345 | (Port => Disabled, |
| 346 | Framebuffer => HW.GFX.Default_FB, |
| 347 | Mode => HW.GFX.Invalid_Mode)); |
| 348 | Registers.Set_Register_Base |
| 349 | (if MMIO_Base /= 0 then |
| 350 | MMIO_Base |
| 351 | else |
| 352 | Config.Default_MMIO_Base); |
| 353 | PLLs.Initialize; |
| 354 | |
| 355 | Check_Platform (Success); |
| 356 | if not Success then |
| 357 | pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH.")); |
| 358 | |
| 359 | Panel.Static_Init; -- for flow analysis |
| 360 | |
| 361 | Initialized := False; |
| 362 | return; |
| 363 | end if; |
| 364 | |
| 365 | Panel.Setup_PP_Sequencer; |
| 366 | Port_Detect.Initialize; |
| 367 | |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 368 | if Clean_State then |
| 369 | Power_And_Clocks.Pre_All_Off; |
| 370 | Connectors.Pre_All_Off; |
| 371 | Display_Controller.All_Off; |
| 372 | Connectors.Post_All_Off; |
| 373 | PLLs.All_Off; |
| 374 | Power_And_Clocks.Post_All_Off; |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 375 | else |
| 376 | -- According to PRMs, VGA plane is the only thing |
| 377 | -- that's enabled by default after reset. |
| 378 | Display_Controller.Legacy_VGA_Off; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 379 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 380 | |
| 381 | -------------------- Now restart from a clean state --------------------- |
| 382 | Power_And_Clocks.Initialize; |
| 383 | |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 384 | if Config.Has_PCH then |
| 385 | Registers.Unset_And_Set_Mask |
| 386 | (Register => Registers.PCH_RAWCLK_FREQ, |
| 387 | Mask_Unset => PCH_RAWCLK_FREQ_MASK, |
| 388 | Mask_Set => PCH_RAWCLK_FREQ (Config.Default_RawClk_Freq)); |
| 389 | end if; |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 390 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 391 | Initialized := True; |
| 392 | |
| 393 | end Initialize; |
| 394 | |
| 395 | function Is_Initialized return Boolean |
| 396 | with |
| 397 | Refined_Post => Is_Initialized'Result = Initialized |
| 398 | is |
| 399 | begin |
| 400 | return Initialized; |
| 401 | end Is_Initialized; |
| 402 | |
| 403 | ---------------------------------------------------------------------------- |
| 404 | |
| 405 | procedure Write_GTT |
| 406 | (GTT_Page : GTT_Range; |
| 407 | Device_Address : GTT_Address_Type; |
| 408 | Valid : Boolean) is |
| 409 | begin |
| 410 | Registers.Write_GTT (GTT_Page, Device_Address, Valid); |
| 411 | end Write_GTT; |
| 412 | |
| 413 | procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_FB : Word32) |
| 414 | is |
| 415 | FB_Size : constant Pos32 := |
| 416 | FB.Stride * FB.Height * Pos32 (((FB.BPC * 4) / 8)); |
| 417 | Phys_Addr : GTT_Address_Type := GTT_Address_Type (Phys_FB); |
| 418 | begin |
| 419 | for Idx in GTT_Range range 0 .. GTT_Range (((FB_Size + 4095) / 4096) - 1) |
| 420 | loop |
| 421 | Registers.Write_GTT |
| 422 | (GTT_Page => Idx, |
| 423 | Device_Address => Phys_Addr, |
| 424 | Valid => True); |
| 425 | Phys_Addr := Phys_Addr + 4096; |
| 426 | end loop; |
| 427 | end Setup_Default_GTT; |
| 428 | |
| 429 | ---------------------------------------------------------------------------- |
| 430 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 431 | procedure Dump_Configs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 432 | is |
| 433 | subtype Pipe_Name is String (1 .. 9); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 434 | type Pipe_Name_Array is array (Pipe_Index) of Pipe_Name; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 435 | Pipe_Names : constant Pipe_Name_Array := |
| 436 | (Primary => "Primary ", |
| 437 | Secondary => "Secondary", |
| 438 | Tertiary => "Tertiary "); |
| 439 | begin |
| 440 | Debug.New_Line; |
| Paul Menzel | b83107c | 2017-05-04 09:02:33 +0200 | [diff] [blame] | 441 | Debug.Put_Line ("CONFIG =>"); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 442 | for Pipe in Pipe_Index loop |
| 443 | if Pipe = Pipe_Index'First then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 444 | Debug.Put (" ("); |
| 445 | else |
| 446 | Debug.Put (" "); |
| 447 | end if; |
| 448 | Debug.Put_Line (Pipe_Names (Pipe) & " =>"); |
| 449 | Debug.Put_Line |
| 450 | (" (Port => " & Port_Names (Configs (Pipe).Port) & ","); |
| 451 | Debug.Put_Line (" Framebuffer =>"); |
| 452 | Debug.Put (" (Width => "); |
| 453 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width); |
| 454 | Debug.Put_Line (","); |
| 455 | Debug.Put (" Height => "); |
| 456 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height); |
| 457 | Debug.Put_Line (","); |
| 458 | Debug.Put (" Stride => "); |
| 459 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride); |
| 460 | Debug.Put_Line (","); |
| 461 | Debug.Put (" Offset => "); |
| 462 | Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset); |
| 463 | Debug.Put_Line (","); |
| 464 | Debug.Put (" BPC => "); |
| 465 | Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC); |
| 466 | Debug.Put_Line ("),"); |
| 467 | Debug.Put_Line (" Mode =>"); |
| 468 | Debug.Put (" (Dotclock => "); |
| 469 | Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock); |
| 470 | Debug.Put_Line (","); |
| 471 | Debug.Put (" H_Visible => "); |
| 472 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible); |
| 473 | Debug.Put_Line (","); |
| 474 | Debug.Put (" H_Sync_Begin => "); |
| 475 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin); |
| 476 | Debug.Put_Line (","); |
| 477 | Debug.Put (" H_Sync_End => "); |
| 478 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End); |
| 479 | Debug.Put_Line (","); |
| 480 | Debug.Put (" H_Total => "); |
| 481 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Total); |
| 482 | Debug.Put_Line (","); |
| 483 | Debug.Put (" V_Visible => "); |
| 484 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible); |
| 485 | Debug.Put_Line (","); |
| 486 | Debug.Put (" V_Sync_Begin => "); |
| 487 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin); |
| 488 | Debug.Put_Line (","); |
| 489 | Debug.Put (" V_Sync_End => "); |
| 490 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End); |
| 491 | Debug.Put_Line (","); |
| 492 | Debug.Put (" V_Total => "); |
| 493 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Total); |
| 494 | Debug.Put_Line (","); |
| 495 | Debug.Put_Line (" H_Sync_Active_High => " & |
| 496 | (if Configs (Pipe).Mode.H_Sync_Active_High |
| 497 | then "True," |
| 498 | else "False,")); |
| 499 | Debug.Put_Line (" V_Sync_Active_High => " & |
| 500 | (if Configs (Pipe).Mode.V_Sync_Active_High |
| 501 | then "True," |
| 502 | else "False,")); |
| 503 | Debug.Put (" BPC => "); |
| 504 | Debug.Put_Int64 (Configs (Pipe).Mode.BPC); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 505 | if Pipe /= Pipe_Index'Last then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 506 | Debug.Put_Line (")),"); |
| 507 | else |
| 508 | Debug.Put_Line (")));"); |
| 509 | end if; |
| 510 | end loop; |
| 511 | end Dump_Configs; |
| 512 | |
| 513 | end HW.GFX.GMA; |