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