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