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