| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 2 | -- Copyright (C) 2014-2018 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 | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 21 | with HW.GFX.Framebuffer_Filler; |
| 22 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 23 | with HW.GFX.GMA.Config; |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 24 | with HW.GFX.GMA.Config_Helpers; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 25 | with HW.GFX.GMA.Registers; |
| 26 | with HW.GFX.GMA.Power_And_Clocks; |
| 27 | with HW.GFX.GMA.Panel; |
| 28 | with HW.GFX.GMA.PLLs; |
| 29 | with HW.GFX.GMA.Port_Detect; |
| 30 | with HW.GFX.GMA.Connectors; |
| 31 | with HW.GFX.GMA.Connector_Info; |
| 32 | with HW.GFX.GMA.Pipe_Setup; |
| 33 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 34 | with HW.Debug; |
| 35 | with GNAT.Source_Info; |
| 36 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 37 | use type HW.Int32; |
| 38 | |
| 39 | package body HW.GFX.GMA |
| 40 | with Refined_State => |
| 41 | (State => |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 42 | (Dev.Address_State, |
| 43 | Registers.Address_State, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 44 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 45 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 46 | HPD_Delay, Wait_For_HPD, |
| 47 | Linear_FB_Base), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 48 | Init_State => Initialized, |
| Arthur Heymans | d1988d1 | 2018-03-28 16:27:57 +0200 | [diff] [blame] | 49 | Config_State => (Config.Valid_Port_GPU, Config.Raw_Clock), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 50 | Device_State => |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 51 | (Dev.PCI_State, Registers.Register_State, Registers.GTT_State)) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 52 | is |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 53 | pragma Disable_Atomic_Synchronization; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 54 | |
| 55 | subtype Port_Name is String (1 .. 8); |
| 56 | type Port_Name_Array is array (Port_Type) of Port_Name; |
| 57 | Port_Names : constant Port_Name_Array := |
| 58 | (Disabled => "Disabled", |
| 59 | Internal => "Internal", |
| 60 | DP1 => "DP1 ", |
| 61 | DP2 => "DP2 ", |
| 62 | DP3 => "DP3 ", |
| Nico Huber | 0d454cd | 2016-11-21 13:33:43 +0100 | [diff] [blame] | 63 | HDMI1 => "HDMI1 ", |
| 64 | HDMI2 => "HDMI2 ", |
| 65 | HDMI3 => "HDMI3 ", |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 66 | Analog => "Analog "); |
| 67 | |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 68 | package Dev is new HW.PCI.Dev (PCI.Address'(0, 2, 0)); |
| 69 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 70 | package Display_Controller renames Pipe_Setup; |
| 71 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 72 | type PLLs_Type is array (Pipe_Index) of PLLs.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 | type HPD_Type is array (Port_Type) of Boolean; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 75 | type HPD_Delay_Type is array (Active_Port_Type) of Time.T; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 76 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 77 | Allocated_PLLs : PLLs_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 78 | HPD_Delay : HPD_Delay_Type; |
| 79 | Wait_For_HPD : HPD_Type; |
| 80 | Initialized : Boolean := False; |
| 81 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 82 | Linear_FB_Base : Word64; |
| 83 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 84 | ---------------------------------------------------------------------------- |
| 85 | |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 86 | PCH_RAWCLK_FREQ_MASK : constant := 16#3ff# * 2 ** 0; |
| 87 | |
| 88 | function PCH_RAWCLK_FREQ (Freq : Frequency_Type) return Word32 |
| 89 | is |
| 90 | begin |
| 91 | return Word32 (Freq / 1_000_000); |
| 92 | end PCH_RAWCLK_FREQ; |
| 93 | |
| 94 | ---------------------------------------------------------------------------- |
| 95 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 96 | procedure Enable_Output |
| 97 | (Pipe : in Pipe_Index; |
| 98 | Pipe_Cfg : in Pipe_Config; |
| 99 | Success : out Boolean) |
| 100 | is |
| 101 | Port_Cfg : Port_Config; |
| 102 | begin |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 103 | pragma Debug (Debug.New_Line); |
| 104 | pragma Debug (Debug.Put_Line |
| 105 | ("Trying to enable port " & Port_Names (Pipe_Cfg.Port))); |
| 106 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 107 | Config_Helpers.Fill_Port_Config |
| 108 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 109 | |
| 110 | if Success then |
| 111 | Success := Config_Helpers.Validate_Config |
| Nico Huber | cbbaade | 2018-01-02 13:59:36 +0100 | [diff] [blame] | 112 | (Pipe_Cfg.Framebuffer, Port_Cfg.Mode, Pipe); |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 113 | end if; |
| 114 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 115 | if Success then |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 116 | Connector_Info.Preferred_Link_Setting (Port_Cfg, Success); |
| 117 | end if; |
| 118 | |
| 119 | -- loop over all possible DP-lane configurations |
| 120 | -- (non-DP ports use a single fake configuration) |
| 121 | while Success loop |
| 122 | pragma Loop_Invariant |
| 123 | (Pipe_Cfg.Port in Active_Port_Type and |
| 124 | Port_Cfg.Mode = Port_Cfg.Mode'Loop_Entry); |
| 125 | |
| 126 | PLLs.Alloc |
| 127 | (Port_Cfg => Port_Cfg, |
| 128 | PLL => Allocated_PLLs (Pipe), |
| 129 | Success => Success); |
| 130 | |
| 131 | if Success then |
| 132 | -- try each DP-lane configuration twice |
| 133 | for Try in 1 .. 2 loop |
| 134 | pragma Loop_Invariant |
| 135 | (Pipe_Cfg.Port in Active_Port_Type); |
| 136 | |
| Nico Huber | 4798c66 | 2017-01-11 12:44:48 +0100 | [diff] [blame] | 137 | -- Clear pending hot-plug events before every try |
| 138 | Port_Detect.Clear_Hotplug_Detect (Pipe_Cfg.Port); |
| 139 | |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 140 | Connectors.Pre_On |
| 141 | (Pipe => Pipe, |
| 142 | Port_Cfg => Port_Cfg, |
| 143 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 144 | Success => Success); |
| 145 | |
| 146 | if Success then |
| 147 | Display_Controller.On |
| 148 | (Pipe => Pipe, |
| 149 | Port_Cfg => Port_Cfg, |
| 150 | Framebuffer => Pipe_Cfg.Framebuffer); |
| 151 | |
| 152 | Connectors.Post_On |
| Arthur Heymans | 60d0e5f | 2018-03-28 17:08:27 +0200 | [diff] [blame] | 153 | (Pipe => Pipe, |
| 154 | Port_Cfg => Port_Cfg, |
| Nico Huber | 43370ba | 2017-01-09 15:26:19 +0100 | [diff] [blame] | 155 | PLL_Hint => PLLs.Register_Value (Allocated_PLLs (Pipe)), |
| 156 | Success => Success); |
| 157 | |
| 158 | if not Success then |
| 159 | Display_Controller.Off (Pipe); |
| 160 | Connectors.Post_Off (Port_Cfg); |
| 161 | end if; |
| 162 | end if; |
| 163 | |
| 164 | exit when Success; |
| 165 | end loop; |
| 166 | exit when Success; -- connection established => stop loop |
| 167 | |
| 168 | -- connection failed |
| 169 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 170 | end if; |
| 171 | |
| 172 | Connector_Info.Next_Link_Setting (Port_Cfg, Success); |
| 173 | end loop; |
| 174 | |
| 175 | if Success then |
| 176 | pragma Debug (Debug.Put_Line |
| 177 | ("Enabled port " & Port_Names (Pipe_Cfg.Port))); |
| 178 | else |
| 179 | Wait_For_HPD (Pipe_Cfg.Port) := True; |
| 180 | if Pipe_Cfg.Port = Internal then |
| 181 | Panel.Off; |
| 182 | end if; |
| 183 | end if; |
| 184 | end Enable_Output; |
| 185 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 186 | procedure Disable_Output (Pipe : Pipe_Index; Pipe_Cfg : Pipe_Config) |
| 187 | is |
| 188 | Port_Cfg : Port_Config; |
| 189 | Success : Boolean; |
| 190 | begin |
| 191 | Config_Helpers.Fill_Port_Config |
| 192 | (Port_Cfg, Pipe, Pipe_Cfg.Port, Pipe_Cfg.Mode, Success); |
| 193 | if Success then |
| 194 | pragma Debug (Debug.New_Line); |
| 195 | pragma Debug (Debug.Put_Line |
| 196 | ("Disabling port " & Port_Names (Pipe_Cfg.Port))); |
| 197 | pragma Debug (Debug.New_Line); |
| 198 | |
| 199 | Connectors.Pre_Off (Port_Cfg); |
| 200 | Display_Controller.Off (Pipe); |
| 201 | Connectors.Post_Off (Port_Cfg); |
| 202 | |
| 203 | PLLs.Free (Allocated_PLLs (Pipe)); |
| 204 | end if; |
| 205 | end Disable_Output; |
| 206 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 207 | procedure Update_Outputs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 208 | is |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 209 | procedure Check_HPD (Port : in Active_Port_Type; Detected : out Boolean) |
| 210 | is |
| 211 | HPD_Delay_Over : constant Boolean := Time.Timed_Out (HPD_Delay (Port)); |
| 212 | begin |
| 213 | if HPD_Delay_Over then |
| 214 | Port_Detect.Hotplug_Detect (Port, Detected); |
| 215 | HPD_Delay (Port) := Time.MS_From_Now (333); |
| 216 | else |
| 217 | Detected := False; |
| 218 | end if; |
| 219 | end Check_HPD; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 220 | |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 221 | Power_Changed : Boolean := False; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 222 | Old_Configs : Pipe_Configs; |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 223 | |
| 224 | -- Only called when we actually tried to change something |
| 225 | -- so we don't congest the log with unnecessary messages. |
| 226 | procedure Update_Power |
| 227 | is |
| 228 | begin |
| 229 | if not Power_Changed then |
| 230 | Power_And_Clocks.Power_Up (Old_Configs, Configs); |
| 231 | Power_Changed := True; |
| 232 | end if; |
| 233 | end Update_Power; |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 234 | |
| 235 | function Full_Update (Cur_Config, New_Config : Pipe_Config) return Boolean |
| 236 | is |
| 237 | begin |
| 238 | return |
| 239 | Cur_Config.Port /= New_Config.Port or else |
| 240 | Cur_Config.Mode /= New_Config.Mode or else |
| 241 | (Config.Use_PDW_For_EDP_Scaling and then |
| 242 | (Cur_Config.Port = Internal and |
| 243 | Requires_Scaling (Cur_Config) /= Requires_Scaling (New_Config))); |
| 244 | end Full_Update; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 245 | begin |
| 246 | Old_Configs := Cur_Configs; |
| 247 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 248 | -- disable all pipes that changed or had a hot-plug event |
| 249 | for Pipe in Pipe_Index loop |
| 250 | declare |
| 251 | Unplug_Detected : Boolean; |
| 252 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| 253 | New_Config : Pipe_Config renames Configs (Pipe); |
| 254 | begin |
| 255 | if Cur_Config.Port /= Disabled then |
| 256 | Check_HPD (Cur_Config.Port, Unplug_Detected); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 257 | |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 258 | if Full_Update (Cur_Config, New_Config) or Unplug_Detected then |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 259 | Disable_Output (Pipe, Cur_Config); |
| 260 | Cur_Config.Port := Disabled; |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 261 | Update_Power; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 262 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 263 | end if; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 264 | end; |
| 265 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 266 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 267 | -- enable all pipes that changed and should be active |
| 268 | for Pipe in Pipe_Index loop |
| 269 | declare |
| 270 | Success : Boolean; |
| 271 | Cur_Config : Pipe_Config renames Cur_Configs (Pipe); |
| 272 | New_Config : Pipe_Config renames Configs (Pipe); |
| 273 | begin |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 274 | if New_Config.Port /= Disabled and |
| 275 | Full_Update (Cur_Config, New_Config) |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 276 | then |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 277 | if Wait_For_HPD (New_Config.Port) then |
| 278 | Check_HPD (New_Config.Port, Success); |
| 279 | Wait_For_HPD (New_Config.Port) := not Success; |
| 280 | else |
| 281 | Success := True; |
| Nico Huber | 8c45bcf | 2016-11-20 17:30:57 +0100 | [diff] [blame] | 282 | end if; |
| Nico Huber | c7a4fee | 2016-11-03 18:18:03 +0100 | [diff] [blame] | 283 | |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 284 | if Success then |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 285 | Update_Power; |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 286 | Enable_Output (Pipe, New_Config, Success); |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 287 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 288 | |
| 289 | if Success then |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 290 | Cur_Config := New_Config; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 291 | end if; |
| Nico Huber | 3be61d4 | 2017-01-09 13:58:18 +0100 | [diff] [blame] | 292 | |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 293 | -- update framebuffer offset only |
| 294 | elsif New_Config.Port /= Disabled and |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 295 | Cur_Config.Framebuffer /= New_Config.Framebuffer and |
| 296 | Config_Helpers.Validate_Config |
| 297 | (New_Config.Framebuffer, New_Config.Mode, Pipe) |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 298 | then |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 299 | Display_Controller.Setup_FB |
| 300 | (Pipe, New_Config.Mode, New_Config.Framebuffer); |
| Nico Huber | b56b9c5 | 2017-01-11 15:12:23 +0100 | [diff] [blame] | 301 | Cur_Config := New_Config; |
| 302 | end if; |
| 303 | end; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 304 | end loop; |
| 305 | |
| Nico Huber | 564103f | 2017-01-11 15:33:07 +0100 | [diff] [blame] | 306 | if Power_Changed then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 307 | Power_And_Clocks.Power_Down (Old_Configs, Configs, Cur_Configs); |
| 308 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 309 | end Update_Outputs; |
| 310 | |
| 311 | ---------------------------------------------------------------------------- |
| 312 | |
| 313 | procedure Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 314 | (Write_Delay : in Word64 := 0; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 315 | Clean_State : in Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 316 | Success : out Boolean) |
| 317 | with |
| 318 | Refined_Global => |
| 319 | (In_Out => |
| Nico Huber | e015e82 | 2017-08-25 20:12:09 +0200 | [diff] [blame] | 320 | (Config.Valid_Port_GPU, Dev.PCI_State, |
| Arthur Heymans | d1988d1 | 2018-03-28 16:27:57 +0200 | [diff] [blame] | 321 | Registers.Register_State, Port_IO.State, |
| 322 | Config.Raw_Clock), |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 323 | Input => |
| 324 | (Time.State), |
| 325 | Output => |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 326 | (Dev.Address_State, |
| 327 | Registers.Address_State, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 328 | PLLs.State, Panel.Panel_State, |
| Nico Huber | 1a712d3 | 2017-01-09 15:11:04 +0100 | [diff] [blame] | 329 | Cur_Configs, Allocated_PLLs, |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 330 | HPD_Delay, Wait_For_HPD, |
| 331 | Linear_FB_Base, Initialized)) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 332 | is |
| 333 | use type HW.Word64; |
| 334 | |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 335 | PCI_MMIO_Base, PCI_GTT_Base : Word64; |
| 336 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 337 | Now : constant Time.T := Time.Now; |
| 338 | |
| 339 | procedure Check_Platform (Success : out Boolean) |
| 340 | is |
| 341 | Audio_VID_DID : Word32; |
| 342 | begin |
| 343 | case Config.CPU is |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 344 | when G45 => |
| 345 | Registers.Read (Registers.G4X_AUD_VID_DID, Audio_VID_DID); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 346 | when Haswell .. Skylake => |
| 347 | Registers.Read (Registers.AUD_VID_DID, Audio_VID_DID); |
| 348 | when Ironlake .. Ivybridge => |
| 349 | Registers.Read (Registers.PCH_AUD_VID_DID, Audio_VID_DID); |
| 350 | end case; |
| 351 | Success := |
| 352 | (case Config.CPU is |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 353 | when Broxton => Audio_VID_DID = 16#8086_280a#, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 354 | when Skylake => Audio_VID_DID = 16#8086_2809#, |
| 355 | when Broadwell => Audio_VID_DID = 16#8086_2808#, |
| 356 | when Haswell => Audio_VID_DID = 16#8086_2807#, |
| 357 | when Ivybridge | |
| 358 | Sandybridge => Audio_VID_DID = 16#8086_2806# or |
| 359 | Audio_VID_DID = 16#8086_2805#, |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 360 | when Ironlake => Audio_VID_DID = 16#0000_0000#, |
| 361 | when G45 => Audio_VID_DID = 16#8086_2801# or |
| 362 | Audio_VID_DID = 16#8086_2802# or |
| 363 | Audio_VID_DID = 16#8086_2803#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 364 | end Check_Platform; |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 365 | |
| 366 | procedure Check_Platform_PCI (Success : out Boolean) |
| 367 | is |
| 368 | use type HW.Word16; |
| 369 | Vendor, Device : Word16; |
| 370 | begin |
| 371 | Dev.Read16 (Vendor, PCI.Vendor_Id); |
| 372 | Dev.Read16 (Device, PCI.Device_Id); |
| 373 | |
| 374 | Success := Vendor = 16#8086# and Config.Compatible_GPU (Device); |
| 375 | end Check_Platform_PCI; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 376 | begin |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 377 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 378 | |
| 379 | pragma Debug (Debug.Set_Register_Write_Delay (Write_Delay)); |
| 380 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 381 | Linear_FB_Base := 0; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 382 | Wait_For_HPD := HPD_Type'(others => False); |
| 383 | HPD_Delay := HPD_Delay_Type'(others => Now); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 384 | Allocated_PLLs := (others => PLLs.Invalid); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 385 | Cur_Configs := Pipe_Configs' |
| 386 | (others => Pipe_Config' |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 387 | (Port => Disabled, |
| 388 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame^] | 389 | Cursor => Default_Cursor, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 390 | Mode => HW.GFX.Invalid_Mode)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 391 | PLLs.Initialize; |
| 392 | |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 393 | Dev.Initialize (Success); |
| 394 | |
| 395 | if Success then |
| 396 | Dev.Map (PCI_MMIO_Base, PCI.Res0, Length => Config.GTT_Offset); |
| 397 | Dev.Map (PCI_GTT_Base, PCI.Res0, Offset => Config.GTT_Offset); |
| 398 | if PCI_MMIO_Base /= 0 and PCI_GTT_Base /= 0 then |
| 399 | Registers.Set_Register_Base (PCI_MMIO_Base, PCI_GTT_Base); |
| 400 | else |
| 401 | pragma Debug (Debug.Put_Line |
| 402 | ("ERROR: Couldn't map resoure0.")); |
| 403 | Registers.Set_Register_Base (Config.Default_MMIO_Base); |
| 404 | Success := Config.Default_MMIO_Base_Set; |
| 405 | end if; |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 406 | |
| 407 | if Success then |
| 408 | Check_Platform_PCI (Success); |
| 409 | end if; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 410 | else |
| 411 | pragma Debug (Debug.Put_Line |
| 412 | ("WARNING: Couldn't initialize PCI dev.")); |
| 413 | Registers.Set_Register_Base (Config.Default_MMIO_Base); |
| 414 | Success := Config.Default_MMIO_Base_Set; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 415 | |
| Nico Huber | e7ac6eb | 2017-09-04 23:54:13 +0200 | [diff] [blame] | 416 | if Success then |
| 417 | Check_Platform (Success); |
| 418 | end if; |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 419 | end if; |
| 420 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 421 | if not Success then |
| 422 | pragma Debug (Debug.Put_Line ("ERROR: Incompatible CPU or PCH.")); |
| 423 | |
| 424 | Panel.Static_Init; -- for flow analysis |
| 425 | |
| 426 | Initialized := False; |
| 427 | return; |
| 428 | end if; |
| 429 | |
| 430 | Panel.Setup_PP_Sequencer; |
| 431 | Port_Detect.Initialize; |
| Nico Huber | 0923b79 | 2017-06-09 15:28:41 +0200 | [diff] [blame] | 432 | Connectors.Initialize; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 433 | |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 434 | if Clean_State then |
| 435 | Power_And_Clocks.Pre_All_Off; |
| 436 | Connectors.Pre_All_Off; |
| 437 | Display_Controller.All_Off; |
| 438 | Connectors.Post_All_Off; |
| 439 | PLLs.All_Off; |
| 440 | Power_And_Clocks.Post_All_Off; |
| Nico Huber | 17d64b6 | 2017-07-15 20:51:25 +0200 | [diff] [blame] | 441 | Registers.Clear_Fences; |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 442 | else |
| 443 | -- According to PRMs, VGA plane is the only thing |
| Nico Huber | 3a0e2a0 | 2017-07-19 14:41:46 +0200 | [diff] [blame] | 444 | -- that's enabled by default after reset... |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 445 | Display_Controller.Legacy_VGA_Off; |
| Nico Huber | 3a0e2a0 | 2017-07-19 14:41:46 +0200 | [diff] [blame] | 446 | -- ... along with some DDI port bits since Skylake. |
| 447 | Connectors.Post_Reset_Off; |
| Nico Huber | 793a8d4 | 2016-11-21 18:57:03 +0100 | [diff] [blame] | 448 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 449 | |
| 450 | -------------------- Now restart from a clean state --------------------- |
| 451 | Power_And_Clocks.Initialize; |
| 452 | |
| Nico Huber | 1c3b928 | 2017-02-09 13:57:04 +0100 | [diff] [blame] | 453 | if Config.Has_PCH then |
| 454 | Registers.Unset_And_Set_Mask |
| 455 | (Register => Registers.PCH_RAWCLK_FREQ, |
| 456 | Mask_Unset => PCH_RAWCLK_FREQ_MASK, |
| 457 | Mask_Set => PCH_RAWCLK_FREQ (Config.Default_RawClk_Freq)); |
| 458 | end if; |
| Nico Huber | f54d096 | 2016-10-20 14:17:18 +0200 | [diff] [blame] | 459 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 460 | Initialized := True; |
| 461 | |
| 462 | end Initialize; |
| 463 | |
| 464 | function Is_Initialized return Boolean |
| 465 | with |
| 466 | Refined_Post => Is_Initialized'Result = Initialized |
| 467 | is |
| 468 | begin |
| 469 | return Initialized; |
| 470 | end Is_Initialized; |
| 471 | |
| 472 | ---------------------------------------------------------------------------- |
| 473 | |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 474 | procedure Power_Up_VGA |
| 475 | is |
| 476 | Fake_Config : constant Pipe_Configs := |
| 477 | (Primary => |
| 478 | (Port => Analog, |
| 479 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame^] | 480 | Cursor => Default_Cursor, |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 481 | Mode => HW.GFX.Invalid_Mode), |
| 482 | others => |
| 483 | (Port => Disabled, |
| 484 | Framebuffer => HW.GFX.Default_FB, |
| Nico Huber | a02b2c6 | 2018-01-09 15:58:34 +0100 | [diff] [blame^] | 485 | Cursor => Default_Cursor, |
| Nico Huber | 42fb2d0 | 2017-09-01 17:01:51 +0200 | [diff] [blame] | 486 | Mode => HW.GFX.Invalid_Mode)); |
| 487 | begin |
| 488 | Power_And_Clocks.Power_Up (Cur_Configs, Fake_Config); |
| 489 | end Power_Up_VGA; |
| 490 | |
| 491 | ---------------------------------------------------------------------------- |
| 492 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 493 | function FB_First_Page (FB : Framebuffer_Type) return Natural is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 494 | (Natural (Phys_Offset (FB) / GTT_Page_Size)); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 495 | function FB_Pages (FB : Framebuffer_Type) return Natural is |
| 496 | (Natural (Div_Round_Up (FB_Size (FB), GTT_Page_Size))); |
| 497 | function FB_Last_Page (FB : Framebuffer_Type) return Natural is |
| 498 | (FB_First_Page (FB) + FB_Pages (FB) - 1); |
| 499 | |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 500 | -- Check basics and that it fits in GTT. For 90 degree rotations, |
| 501 | -- the Offset should be above GTT_Rotation_Offset. The latter will |
| 502 | -- be subtracted for the aperture mapping. |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 503 | function Valid_FB (FB : Framebuffer_Type) return Boolean is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 504 | (Valid_Stride (FB) and |
| 505 | FB_First_Page (FB) in GTT_Range and |
| 506 | FB_Last_Page (FB) in GTT_Range and |
| 507 | (not Rotation_90 (FB) or |
| 508 | (FB_Last_Page (FB) + GTT_Rotation_Offset in GTT_Range and |
| 509 | FB.Offset >= Word32 (GTT_Rotation_Offset) * GTT_Page_Size))); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 510 | |
| 511 | -- Also check that we don't overflow the GTT's 39-bit space |
| 512 | -- (always true with a 32-bit base) |
| 513 | function Valid_Phys_FB (FB : Framebuffer_Type; Phys_Base : Word32) |
| 514 | return Boolean is |
| 515 | (Valid_FB (FB) and |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 516 | Int64 (Phys_Base) + Int64 (Phys_Offset (FB)) + Int64 (FB_Size (FB)) <= |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 517 | Int64 (GTT_Address_Type'Last)) |
| 518 | with |
| 519 | Ghost; |
| 520 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 521 | procedure Write_GTT |
| 522 | (GTT_Page : GTT_Range; |
| 523 | Device_Address : GTT_Address_Type; |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 524 | Valid : Boolean) |
| 525 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 526 | begin |
| 527 | Registers.Write_GTT (GTT_Page, Device_Address, Valid); |
| 528 | end Write_GTT; |
| 529 | |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 530 | procedure Setup_Default_GTT (FB : Framebuffer_Type; Phys_Base : Word32) |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 531 | with |
| 532 | Pre => Is_Initialized and Valid_Phys_FB (FB, Phys_Base) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 533 | is |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 534 | Phys_Addr : GTT_Address_Type := |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 535 | GTT_Address_Type (Phys_Base) + GTT_Address_Type (Phys_Offset (FB)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 536 | begin |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 537 | for Idx in FB_First_Page (FB) .. FB_Last_Page (FB) loop |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 538 | Registers.Write_GTT |
| 539 | (GTT_Page => Idx, |
| 540 | Device_Address => Phys_Addr, |
| 541 | Valid => True); |
| Nico Huber | 194e57e | 2017-07-15 21:15:46 +0200 | [diff] [blame] | 542 | Phys_Addr := Phys_Addr + GTT_Page_Size; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 543 | end loop; |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 544 | |
| 545 | if Rotation_90 (FB) and FB.Tiling = Y_Tiled and FB.V_Stride >= 32 then |
| 546 | declare |
| 547 | V_Pages : constant Natural := Natural (FB.V_Stride) / 32; |
| 548 | Bytes_Per_Row : constant GTT_Address_Type := |
| 549 | GTT_Address_Type (Pixel_To_Bytes (32 * FB.Stride, FB)); |
| 550 | begin |
| 551 | Phys_Addr := GTT_Address_Type (Phys_Base) + |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 552 | GTT_Address_Type (Phys_Offset (FB)) + |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 553 | GTT_Address_Type (FB_Size (FB)); |
| 554 | for Page in FB_First_Page (FB) .. FB_Last_Page (FB) loop |
| 555 | Phys_Addr := Phys_Addr - Bytes_Per_Row; |
| 556 | Registers.Write_GTT |
| 557 | (GTT_Page => GTT_Rotation_Offset + Page, |
| 558 | Device_Address => Phys_Addr, |
| 559 | Valid => True); |
| 560 | |
| 561 | if (Page - FB_First_Page (FB) + 1) mod V_Pages = 0 then |
| 562 | Phys_Addr := Phys_Addr + GTT_Page_Size + |
| 563 | GTT_Address_Type (V_Pages) * Bytes_Per_Row; |
| 564 | end if; |
| 565 | end loop; |
| 566 | end; |
| 567 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 568 | end Setup_Default_GTT; |
| 569 | |
| 570 | ---------------------------------------------------------------------------- |
| 571 | |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 572 | use type HW.Word16; |
| 573 | subtype Stolen_Size_Range is Int64 range 0 .. 2 ** 33; |
| 574 | |
| 575 | function GGMS_Gen4 (GGC : Word16) return Natural is |
| 576 | (Natural (Shift_Right (GGC, 8) and 16#07#)); |
| 577 | function GTT_Size_Gen4 (GGC : Word16) return Natural is |
| 578 | (if GGMS_Gen4 (GGC) in 1 .. 3 then |
| 579 | (GGMS_Gen4 (GGC) + 1) * 2 ** 19 else 0); |
| 580 | |
| 581 | function GMS_Gen4 (GGC : Word16) return Natural is |
| 582 | (Natural (Shift_Right (GGC, 4) and 16#0f#)); |
| 583 | Valid_Stolen_Size_Gen4 : constant |
| 584 | array (Natural range 1 .. 13) of Stolen_Size_Range := |
| 585 | (1, 4, 8, 16, 32, 48, 64, 128, 256, 96, 160, 224, 352); |
| 586 | function Stolen_Size_Gen4 (GGC : Word16) return Stolen_Size_Range is |
| 587 | (if GMS_Gen4 (GGC) in Valid_Stolen_Size_Gen4'Range then |
| Arthur Heymans | 5fd9a31 | 2017-09-12 12:45:18 +0200 | [diff] [blame] | 588 | Valid_Stolen_Size_Gen4 (GMS_Gen4 (GGC)) * 2 ** 20 else 0); |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 589 | |
| 590 | function GTT_Size_Gen6 (GGC : Word16) return Natural is |
| 591 | (Natural (Shift_Right (GGC, 8) and 16#03#) * 2 ** 20); |
| 592 | |
| 593 | function Stolen_Size_Gen6 (GGC : Word16) return Stolen_Size_Range is |
| 594 | (Stolen_Size_Range (Shift_Right (GGC, 3) and 16#1f#) * 32 * 2 ** 20); |
| 595 | |
| 596 | function GTT_Size_Gen8 (GGC : Word16) return Natural is |
| 597 | (Natural (Shift_Right (GGC, 6) and 16#03#) * 2 ** 20); |
| 598 | |
| 599 | function GMS_Gen8 (GGC : Word16) return Stolen_Size_Range is |
| 600 | (Stolen_Size_Range (Shift_Right (GGC, 8) and 16#ff#)); |
| 601 | function Stolen_Size_Gen8 (GGC : Word16) return Stolen_Size_Range is |
| 602 | (GMS_Gen8 (GGC) * 32 * 2 ** 20); |
| 603 | |
| 604 | function Stolen_Size_Gen9 (GGC : Word16) return Stolen_Size_Range is |
| 605 | (if GMS_Gen8 (GGC) < 16#f0# then |
| 606 | Stolen_Size_Gen8 (GGC) |
| 607 | else |
| 608 | (GMS_Gen8 (GGC) - 16#f0# + 1) * 4 * 2 ** 20); |
| 609 | |
| 610 | procedure Decode_Stolen |
| 611 | (GTT_Size : out Natural; |
| 612 | Stolen_Size : out Stolen_Size_Range) |
| 613 | with |
| 614 | Pre => Is_Initialized |
| 615 | is |
| 616 | GGC_Reg : constant := |
| 617 | (case Config.CPU is |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 618 | when G45 | Ironlake => 16#52#, |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 619 | when Sandybridge .. Skylake => 16#50#); |
| 620 | GGC : Word16; |
| 621 | begin |
| 622 | Dev.Read16 (GGC, GGC_Reg); |
| 623 | case Config.CPU is |
| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +0200 | [diff] [blame] | 624 | when G45 | Ironlake => |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 625 | GTT_Size := GTT_Size_Gen4 (GGC); |
| 626 | Stolen_Size := Stolen_Size_Gen4 (GGC); |
| 627 | when Sandybridge .. Haswell => |
| 628 | GTT_Size := GTT_Size_Gen6 (GGC); |
| 629 | Stolen_Size := Stolen_Size_Gen6 (GGC); |
| 630 | when Broadwell => |
| 631 | GTT_Size := GTT_Size_Gen8 (GGC); |
| 632 | Stolen_Size := Stolen_Size_Gen8 (GGC); |
| 633 | when Broxton .. Skylake => |
| 634 | GTT_Size := GTT_Size_Gen8 (GGC); |
| 635 | Stolen_Size := Stolen_Size_Gen9 (GGC); |
| 636 | end case; |
| 637 | end Decode_Stolen; |
| 638 | |
| 639 | -- Additional runtime validation that FB fits stolen memory and aperture. |
| 640 | procedure Validate_FB (FB : Framebuffer_Type; Valid : out Boolean) |
| 641 | with |
| 642 | Pre => Is_Initialized, |
| 643 | Post => (if Valid then Valid_FB (FB)) |
| 644 | is |
| 645 | GTT_Size, Aperture_Size : Natural; |
| 646 | Stolen_Size : Stolen_Size_Range; |
| 647 | begin |
| 648 | Valid := Valid_FB (FB); |
| 649 | |
| 650 | if Valid then |
| 651 | Decode_Stolen (GTT_Size, Stolen_Size); |
| 652 | Dev.Resource_Size (Aperture_Size, PCI.Res2); |
| 653 | Valid := |
| 654 | FB_Last_Page (FB) < GTT_Size / Config.GTT_PTE_Size and |
| 655 | FB_Last_Page (FB) < Natural (Stolen_Size / GTT_Page_Size) and |
| 656 | FB_Last_Page (FB) < Aperture_Size / GTT_Page_Size; |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 657 | pragma Debug (not Valid, Debug.Put_Line |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 658 | ("Stolen memory too small to hold framebuffer.")); |
| 659 | end if; |
| 660 | end Validate_FB; |
| 661 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 662 | procedure Setup_Default_FB |
| 663 | (FB : in Framebuffer_Type; |
| 664 | Clear : in Boolean := True; |
| 665 | Success : out Boolean) |
| 666 | is |
| 667 | GMA_Phys_Base : constant PCI.Index := 16#5c#; |
| 668 | GMA_Phys_Base_Mask : constant := 16#fff0_0000#; |
| 669 | |
| 670 | Phys_Base : Word32; |
| 671 | begin |
| Nico Huber | eedde88 | 2017-07-16 02:54:39 +0200 | [diff] [blame] | 672 | Validate_FB (FB, Success); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 673 | |
| 674 | if Success then |
| 675 | Dev.Read32 (Phys_Base, GMA_Phys_Base); |
| 676 | Phys_Base := Phys_Base and GMA_Phys_Base_Mask; |
| 677 | Success := Phys_Base /= GMA_Phys_Base_Mask and Phys_Base /= 0; |
| 678 | pragma Debug (not Success, Debug.Put_Line |
| 679 | ("Failed to read stolen memory base.")); |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 680 | |
| 681 | if Success then |
| 682 | if FB.Tiling in XY_Tiling then |
| 683 | Registers.Add_Fence |
| 684 | (First_Page => FB_First_Page (FB), |
| 685 | Last_Page => FB_Last_Page (FB), |
| 686 | Tiling => FB.Tiling, |
| 687 | Pitch => FB_Pitch (FB.Stride, FB), |
| 688 | Success => Success); |
| 689 | end if; |
| 690 | pragma Debug (not Success, Debug.Put_Line |
| 691 | ("Tiled framebuffer but no fence regs available.")); |
| 692 | end if; |
| 693 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 694 | if Success then |
| 695 | Setup_Default_GTT (FB, Phys_Base); |
| 696 | end if; |
| 697 | end if; |
| 698 | |
| 699 | if Success and then Clear then |
| 700 | declare |
| 701 | use type HW.Word64; |
| 702 | Linear_FB : Word64; |
| 703 | begin |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 704 | Map_Linear_FB (Linear_FB, FB); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 705 | if Linear_FB /= 0 then |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 706 | Framebuffer_Filler.Fill (Linear_FB, FB); |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 707 | end if; |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 708 | end; |
| 709 | end if; |
| 710 | end Setup_Default_FB; |
| 711 | |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 712 | procedure Map_Linear_FB (Linear_FB : out Word64; FB : in Framebuffer_Type) |
| 713 | is |
| 714 | use type HW.Word64; |
| 715 | |
| 716 | Valid : Boolean; |
| 717 | begin |
| 718 | Linear_FB := 0; |
| 719 | |
| 720 | if Linear_FB_Base = 0 then |
| 721 | Dev.Map (Linear_FB_Base, PCI.Res2); |
| 722 | pragma Debug |
| 723 | (Linear_FB_Base = 0, Debug.Put_Line ("Failed to map resource2.")); |
| 724 | end if; |
| 725 | |
| 726 | if Linear_FB_Base /= 0 then |
| 727 | Validate_FB (FB, Valid); |
| 728 | if Valid then |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 729 | Linear_FB := Linear_FB_Base + Word64 (Phys_Offset (FB)); |
| Nico Huber | c3f66f6 | 2017-07-16 21:39:54 +0200 | [diff] [blame] | 730 | end if; |
| 731 | end if; |
| 732 | end Map_Linear_FB; |
| 733 | |
| Nico Huber | 5374c3a | 2017-07-15 21:48:06 +0200 | [diff] [blame] | 734 | ---------------------------------------------------------------------------- |
| 735 | |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 736 | procedure Dump_Configs (Configs : Pipe_Configs) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 737 | is |
| 738 | subtype Pipe_Name is String (1 .. 9); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 739 | type Pipe_Name_Array is array (Pipe_Index) of Pipe_Name; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 740 | Pipe_Names : constant Pipe_Name_Array := |
| 741 | (Primary => "Primary ", |
| 742 | Secondary => "Secondary", |
| 743 | Tertiary => "Tertiary "); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 744 | |
| 745 | subtype Tiling_Name is String (1 .. 7); |
| 746 | type Tiling_Name_Array is array (Tiling_Type) of Tiling_Name; |
| 747 | Tilings : constant Tiling_Name_Array := |
| 748 | (Linear => "Linear ", |
| 749 | X_Tiled => "X_Tiled", |
| 750 | Y_Tiled => "Y_Tiled"); |
| 751 | |
| 752 | subtype Rotation_Name is String (1 .. 11); |
| 753 | type Rotation_Name_Array is array (Rotation_Type) of Rotation_Name; |
| 754 | Rotations : constant Rotation_Name_Array := |
| 755 | (No_Rotation => "No_Rotation", |
| 756 | Rotated_90 => "Rotated_90 ", |
| 757 | Rotated_180 => "Rotated_180", |
| 758 | Rotated_270 => "Rotated_270"); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 759 | begin |
| 760 | Debug.New_Line; |
| Paul Menzel | b83107c | 2017-05-04 09:02:33 +0200 | [diff] [blame] | 761 | Debug.Put_Line ("CONFIG =>"); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 762 | for Pipe in Pipe_Index loop |
| 763 | if Pipe = Pipe_Index'First then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 764 | Debug.Put (" ("); |
| 765 | else |
| 766 | Debug.Put (" "); |
| 767 | end if; |
| 768 | Debug.Put_Line (Pipe_Names (Pipe) & " =>"); |
| 769 | Debug.Put_Line |
| 770 | (" (Port => " & Port_Names (Configs (Pipe).Port) & ","); |
| 771 | Debug.Put_Line (" Framebuffer =>"); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 772 | Debug.Put (" (Width => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 773 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Width); |
| 774 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 775 | Debug.Put (" Height => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 776 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Height); |
| 777 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 778 | Debug.Put (" Start_X => "); |
| 779 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_X); |
| 780 | Debug.Put_Line (","); |
| 781 | Debug.Put (" Start_Y => "); |
| 782 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Start_Y); |
| 783 | Debug.Put_Line (","); |
| 784 | Debug.Put (" Stride => "); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 785 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.Stride); |
| 786 | Debug.Put_Line (","); |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 787 | Debug.Put (" V_Stride => "); |
| 788 | Debug.Put_Int32 (Configs (Pipe).Framebuffer.V_Stride); |
| 789 | Debug.Put_Line (","); |
| 790 | Debug.Put (" Tiling => "); |
| 791 | Debug.Put_Line (Tilings (Configs (Pipe).Framebuffer.Tiling) & ","); |
| 792 | Debug.Put (" Rotation => "); |
| 793 | Debug.Put_Line (Rotations (Configs (Pipe).Framebuffer.Rotation) & ","); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 794 | Debug.Put (" Offset => "); |
| 795 | Debug.Put_Word32 (Configs (Pipe).Framebuffer.Offset); |
| 796 | Debug.Put_Line (","); |
| 797 | Debug.Put (" BPC => "); |
| 798 | Debug.Put_Int64 (Configs (Pipe).Framebuffer.BPC); |
| 799 | Debug.Put_Line ("),"); |
| 800 | Debug.Put_Line (" Mode =>"); |
| 801 | Debug.Put (" (Dotclock => "); |
| 802 | Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock); |
| 803 | Debug.Put_Line (","); |
| 804 | Debug.Put (" H_Visible => "); |
| 805 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible); |
| 806 | Debug.Put_Line (","); |
| 807 | Debug.Put (" H_Sync_Begin => "); |
| 808 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin); |
| 809 | Debug.Put_Line (","); |
| 810 | Debug.Put (" H_Sync_End => "); |
| 811 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End); |
| 812 | Debug.Put_Line (","); |
| 813 | Debug.Put (" H_Total => "); |
| 814 | Debug.Put_Int16 (Configs (Pipe).Mode.H_Total); |
| 815 | Debug.Put_Line (","); |
| 816 | Debug.Put (" V_Visible => "); |
| 817 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible); |
| 818 | Debug.Put_Line (","); |
| 819 | Debug.Put (" V_Sync_Begin => "); |
| 820 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin); |
| 821 | Debug.Put_Line (","); |
| 822 | Debug.Put (" V_Sync_End => "); |
| 823 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End); |
| 824 | Debug.Put_Line (","); |
| 825 | Debug.Put (" V_Total => "); |
| 826 | Debug.Put_Int16 (Configs (Pipe).Mode.V_Total); |
| 827 | Debug.Put_Line (","); |
| 828 | Debug.Put_Line (" H_Sync_Active_High => " & |
| 829 | (if Configs (Pipe).Mode.H_Sync_Active_High |
| 830 | then "True," |
| 831 | else "False,")); |
| 832 | Debug.Put_Line (" V_Sync_Active_High => " & |
| 833 | (if Configs (Pipe).Mode.V_Sync_Active_High |
| 834 | then "True," |
| 835 | else "False,")); |
| 836 | Debug.Put (" BPC => "); |
| 837 | Debug.Put_Int64 (Configs (Pipe).Mode.BPC); |
| Nico Huber | 99f10f3 | 2016-11-20 00:34:05 +0100 | [diff] [blame] | 838 | if Pipe /= Pipe_Index'Last then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 839 | Debug.Put_Line (")),"); |
| 840 | else |
| 841 | Debug.Put_Line (")));"); |
| 842 | end if; |
| 843 | end loop; |
| 844 | end Dump_Configs; |
| 845 | |
| 846 | end HW.GFX.GMA; |