| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2015-2016 secunet Security Networks AG |
| 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| Nico Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | with HW.Debug; |
| 16 | with GNAT.Source_Info; |
| 17 | |
| 18 | with HW.GFX.GMA.Config; |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 19 | with HW.GFX.GMA.Transcoder; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 20 | |
| 21 | package body HW.GFX.GMA.Pipe_Setup is |
| 22 | |
| Nico Huber | fbb4220 | 2016-11-07 15:08:26 +0100 | [diff] [blame] | 23 | ILK_DISPLAY_CHICKEN1_VGA_MASK : constant := 7 * 2 ** 29; |
| 24 | ILK_DISPLAY_CHICKEN1_VGA_ENABLE : constant := 5 * 2 ** 29; |
| 25 | ILK_DISPLAY_CHICKEN2_VGA_MASK : constant := 1 * 2 ** 25; |
| 26 | ILK_DISPLAY_CHICKEN2_VGA_ENABLE : constant := 0 * 2 ** 25; |
| 27 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 28 | DSPCNTR_ENABLE : constant := 1 * 2 ** 31; |
| 29 | DSPCNTR_GAMMA_CORRECTION : constant := 1 * 2 ** 30; |
| 30 | DSPCNTR_DISABLE_TRICKLE_FEED : constant := 1 * 2 ** 14; |
| 31 | DSPCNTR_FORMAT_MASK : constant := 15 * 2 ** 26; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 32 | |
| 33 | DSPCNTR_MASK : constant Word32 := |
| 34 | DSPCNTR_ENABLE or |
| 35 | DSPCNTR_GAMMA_CORRECTION or |
| 36 | DSPCNTR_FORMAT_MASK or |
| 37 | DSPCNTR_DISABLE_TRICKLE_FEED; |
| 38 | |
| 39 | PLANE_CTL_PLANE_ENABLE : constant := 1 * 2 ** 31; |
| 40 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 : constant := 4 * 2 ** 24; |
| 41 | PLANE_CTL_PLANE_GAMMA_DISABLE : constant := 1 * 2 ** 13; |
| 42 | |
| 43 | PLANE_WM_ENABLE : constant := 1 * 2 ** 31; |
| 44 | PLANE_WM_LINES_SHIFT : constant := 14; |
| 45 | PLANE_WM_LINES_MASK : constant := 16#001f# * 2 ** 14; |
| 46 | PLANE_WM_BLOCKS_MASK : constant := 16#03ff# * 2 ** 0; |
| 47 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 48 | VGA_SR_INDEX : constant := 16#03c4#; |
| 49 | VGA_SR_DATA : constant := 16#03c5#; |
| 50 | VGA_SR01 : constant := 16#01#; |
| 51 | VGA_SR01_SCREEN_OFF : constant := 1 * 2 ** 5; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 52 | |
| 53 | VGA_CONTROL_VGA_DISPLAY_DISABLE : constant := 1 * 2 ** 31; |
| 54 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK : constant := 16#0003# * 2 ** 6; |
| 55 | VGA_CONTROL_BLINK_DUTY_CYCLE_50 : constant := 2 * 2 ** 6; |
| 56 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK : constant := 16#003f# * 2 ** 0; |
| 57 | |
| 58 | subtype VGA_Cycle_Count is Pos32 range 2 .. 128; |
| 59 | function VGA_CONTROL_VSYNC_BLINK_RATE |
| 60 | (Cycles : VGA_Cycle_Count) |
| 61 | return Word32 |
| 62 | is |
| 63 | begin |
| 64 | return Word32 (Cycles) / 2 - 1; |
| 65 | end VGA_CONTROL_VSYNC_BLINK_RATE; |
| 66 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 67 | PF_CTRL_ENABLE : constant := 1 * 2 ** 31; |
| 68 | PF_CTRL_PIPE_SELECT_MASK : constant := 3 * 2 ** 29; |
| 69 | PF_CTRL_FILTER_MED : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 70 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 71 | PS_CTRL_ENABLE_SCALER : constant := 1 * 2 ** 31; |
| 72 | PS_CTRL_SCALER_MODE_7X5_EXTENDED : constant := 1 * 2 ** 28; |
| 73 | PS_CTRL_FILTER_SELECT_MEDIUM_2 : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 74 | |
| 75 | --------------------------------------------------------------------------- |
| 76 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 77 | function PLANE_WM_LINES (Lines : Natural) return Word32 is |
| 78 | begin |
| 79 | return Shift_Left (Word32 (Lines), PLANE_WM_LINES_SHIFT) |
| 80 | and PLANE_WM_LINES_MASK; |
| 81 | end PLANE_WM_LINES; |
| 82 | |
| 83 | function PLANE_WM_BLOCKS (Blocks : Natural) return Word32 is |
| 84 | begin |
| 85 | return Word32 (Blocks) and PLANE_WM_BLOCKS_MASK; |
| 86 | end PLANE_WM_BLOCKS; |
| 87 | |
| 88 | --------------------------------------------------------------------------- |
| 89 | |
| 90 | function Encode (LSW, MSW : Pos16) return Word32 is |
| 91 | begin |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 92 | return Shift_Left (Word32 (MSW) - 1, 16) or (Word32 (LSW) - 1); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 93 | end Encode; |
| 94 | |
| 95 | ---------------------------------------------------------------------------- |
| 96 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 97 | procedure Clear_Watermarks (Controller : Controller_Type) is |
| 98 | begin |
| 99 | Registers.Write |
| 100 | (Register => Controller.PLANE_BUF_CFG, |
| 101 | Value => 16#0000_0000#); |
| 102 | for Level in WM_Levels range 0 .. WM_Levels'Last loop |
| 103 | Registers.Write |
| 104 | (Register => Controller.PLANE_WM (Level), |
| 105 | Value => 16#0000_0000#); |
| 106 | end loop; |
| 107 | Registers.Write |
| 108 | (Register => Controller.WM_LINETIME, |
| 109 | Value => 16#0000_0000#); |
| 110 | end Clear_Watermarks; |
| 111 | |
| 112 | procedure Setup_Watermarks (Controller : Controller_Type) |
| 113 | is |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 114 | type Per_Plane_Buffer_Range is array (Pipe_Index) of Word32; |
| 115 | Buffer_Range : constant Per_Plane_Buffer_Range := |
| 116 | (Primary => Shift_Left (159, 16) or 0, |
| 117 | Secondary => Shift_Left (319, 16) or 160, |
| 118 | Tertiary => Shift_Left (479, 16) or 320); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 119 | begin |
| 120 | Registers.Write |
| 121 | (Register => Controller.PLANE_BUF_CFG, |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 122 | Value => Buffer_Range (Controller.Pipe)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 123 | Registers.Write |
| 124 | (Register => Controller.PLANE_WM (0), |
| 125 | Value => PLANE_WM_ENABLE or |
| 126 | PLANE_WM_LINES (2) or |
| 127 | PLANE_WM_BLOCKS (160)); |
| 128 | end Setup_Watermarks; |
| 129 | |
| 130 | ---------------------------------------------------------------------------- |
| 131 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 132 | procedure Setup_Hires_Plane |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 133 | (Controller : Controller_Type; |
| 134 | Framebuffer : HW.GFX.Framebuffer_Type) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 135 | with |
| 136 | Global => (In_Out => Registers.Register_State), |
| 137 | Depends => |
| 138 | (Registers.Register_State |
| 139 | =>+ |
| 140 | (Registers.Register_State, |
| 141 | Controller, |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 142 | Framebuffer)) |
| 143 | is |
| 144 | -- FIXME: setup correct format, based on framebuffer RGB format |
| 145 | Format : constant Word32 := 6 * 2 ** 26; |
| 146 | PRI : Word32 := DSPCNTR_ENABLE or Format; |
| 147 | |
| 148 | function To_Bytes (Pixels : Width_Type) return Word32 |
| 149 | with |
| 150 | Pre => (Word32 (Pixels) <= Word32'Last / 4 / Word32 (BPC_Type'Last) * 8) |
| 151 | is |
| 152 | begin |
| 153 | return Word32 (Pos64 (Pixels) * 4 * Framebuffer.BPC / 8); |
| 154 | end To_Bytes; |
| 155 | begin |
| 156 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 157 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 158 | if Config.Has_Plane_Control then |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 159 | Registers.Write |
| 160 | (Register => Controller.PLANE_CTL, |
| 161 | Value => PLANE_CTL_PLANE_ENABLE or |
| 162 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 or |
| 163 | PLANE_CTL_PLANE_GAMMA_DISABLE); |
| 164 | Registers.Write (Controller.PLANE_OFFSET, 16#0000_0000#); |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 165 | Registers.Write |
| 166 | (Controller.PLANE_SIZE, |
| 167 | Encode (Pos16 (Framebuffer.Width), Pos16 (Framebuffer.Height))); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 168 | Registers.Write (Controller.PLANE_STRIDE, To_Bytes (Framebuffer.Stride) / 64); |
| 169 | Registers.Write (Controller.PLANE_POS, 16#0000_0000#); |
| 170 | Registers.Write (Controller.PLANE_SURF, Framebuffer.Offset and 16#ffff_f000#); |
| 171 | else |
| 172 | if Config.Disable_Trickle_Feed then |
| 173 | PRI := PRI or DSPCNTR_DISABLE_TRICKLE_FEED; |
| 174 | end if; |
| 175 | -- for now, just disable gamma LUT (can't do anything |
| 176 | -- useful without colorimetry information from display) |
| 177 | Registers.Unset_And_Set_Mask |
| 178 | (Register => Controller.DSPCNTR, |
| 179 | Mask_Unset => DSPCNTR_MASK, |
| 180 | Mask_Set => PRI); |
| 181 | |
| 182 | Registers.Write (Controller.DSPSTRIDE, To_Bytes (Framebuffer.Stride)); |
| 183 | Registers.Write (Controller.DSPSURF, Framebuffer.Offset and 16#ffff_f000#); |
| 184 | if Config.Has_DSP_Linoff then |
| 185 | Registers.Write (Controller.DSPLINOFF, 0); |
| 186 | end if; |
| 187 | Registers.Write (Controller.DSPTILEOFF, 0); |
| 188 | end if; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 189 | end Setup_Hires_Plane; |
| 190 | |
| 191 | procedure Setup_Display |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 192 | (Controller : Controller_Type; |
| 193 | Framebuffer : Framebuffer_Type; |
| 194 | Dither_BPC : BPC_Type; |
| 195 | Dither : Boolean) |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 196 | with |
| 197 | Global => (In_Out => (Registers.Register_State, Port_IO.State)), |
| 198 | Depends => |
| 199 | (Registers.Register_State |
| 200 | =>+ |
| 201 | (Registers.Register_State, |
| 202 | Controller, |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 203 | Framebuffer, |
| 204 | Dither_BPC, |
| 205 | Dither), |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 206 | Port_IO.State |
| 207 | =>+ |
| 208 | (Framebuffer)) |
| 209 | is |
| 210 | use type Word8; |
| 211 | |
| 212 | Reg8 : Word8; |
| 213 | begin |
| 214 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 215 | |
| 216 | if Config.Has_Plane_Control then |
| 217 | Setup_Watermarks (Controller); |
| 218 | end if; |
| 219 | |
| 220 | if Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| Nico Huber | fbb4220 | 2016-11-07 15:08:26 +0100 | [diff] [blame] | 221 | if Config.VGA_Plane_Workaround then |
| 222 | Registers.Unset_And_Set_Mask |
| 223 | (Register => Registers.ILK_DISPLAY_CHICKEN1, |
| 224 | Mask_Unset => ILK_DISPLAY_CHICKEN1_VGA_MASK, |
| 225 | Mask_Set => ILK_DISPLAY_CHICKEN1_VGA_ENABLE); |
| 226 | Registers.Unset_And_Set_Mask |
| 227 | (Register => Registers.ILK_DISPLAY_CHICKEN2, |
| 228 | Mask_Unset => ILK_DISPLAY_CHICKEN2_VGA_MASK, |
| 229 | Mask_Set => ILK_DISPLAY_CHICKEN2_VGA_ENABLE); |
| 230 | end if; |
| 231 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 232 | Registers.Unset_And_Set_Mask |
| 233 | (Register => Registers.VGACNTRL, |
| 234 | Mask_Unset => VGA_CONTROL_VGA_DISPLAY_DISABLE or |
| 235 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK or |
| 236 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK, |
| 237 | Mask_Set => VGA_CONTROL_BLINK_DUTY_CYCLE_50 or |
| 238 | VGA_CONTROL_VSYNC_BLINK_RATE (30)); |
| 239 | |
| 240 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 241 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 242 | Port_IO.OutB (VGA_SR_DATA, Reg8 and not (VGA_SR01_SCREEN_OFF)); |
| 243 | else |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 244 | Setup_Hires_Plane (Controller, Framebuffer); |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 245 | end if; |
| 246 | |
| 247 | Registers.Write |
| 248 | (Register => Controller.PIPESRC, |
| 249 | Value => Encode |
| 250 | (Pos16 (Framebuffer.Height), Pos16 (Framebuffer.Width))); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 251 | |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 252 | if Config.Has_Pipeconf_Misc then |
| 253 | Registers.Write |
| 254 | (Register => Controller.PIPEMISC, |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 255 | Value => Transcoder.BPC_Conf (Dither_BPC, Dither)); |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 256 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 257 | end Setup_Display; |
| 258 | |
| 259 | ---------------------------------------------------------------------------- |
| 260 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 261 | procedure Scale_Keep_Aspect |
| 262 | (Width : out Pos32; |
| 263 | Height : out Pos32; |
| 264 | Max_Width : in Pos32; |
| 265 | Max_Height : in Pos32; |
| 266 | Framebuffer : in Framebuffer_Type) |
| 267 | with |
| 268 | Pre => |
| 269 | Max_Width <= Pos32 (Pos16'Last) and |
| 270 | Max_Height <= Pos32 (Pos16'Last) and |
| 271 | Framebuffer.Width <= Max_Width and |
| 272 | Framebuffer.Height <= Max_Height, |
| 273 | Post => |
| 274 | Width <= Max_Width and Height <= Max_Height |
| 275 | is |
| 276 | begin |
| 277 | if (Max_Width * Framebuffer.Height) / Framebuffer.Width <= Max_Height then |
| 278 | Width := Max_Width; |
| 279 | Height := (Max_Width * Framebuffer.Height) / Framebuffer.Width; |
| 280 | else |
| 281 | Height := Max_Height; |
| 282 | Width := Pos32'Min (Max_Width, -- could prove, it's <= Max_Width |
| 283 | (Max_Height * Framebuffer.Width) / Framebuffer.Height); |
| 284 | end if; |
| 285 | end Scale_Keep_Aspect; |
| 286 | |
| 287 | procedure Setup_Skylake_Pipe_Scaler |
| 288 | (Controller : in Controller_Type; |
| 289 | Mode : in HW.GFX.Mode_Type; |
| 290 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 291 | with |
| 292 | Pre => |
| 293 | Framebuffer.Width <= Pos32 (Mode.H_Visible) and |
| 294 | Framebuffer.Height <= Pos32 (Mode.V_Visible) |
| 295 | is |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 296 | use type Registers.Registers_Invalid_Index; |
| 297 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 298 | -- Enable 7x5 extended mode where possible: |
| 299 | Scaler_Mode : constant Word32 := |
| 300 | (if Controller.PS_CTRL_2 /= Registers.Invalid_Register then |
| 301 | PS_CTRL_SCALER_MODE_7X5_EXTENDED else 0); |
| 302 | |
| 303 | -- We can scale up to 2.99x horizontally: |
| 304 | Horizontal_Limit : constant Pos32 := ((Framebuffer.Width * 299) / 100); |
| 305 | -- The third scaler is limited to 1.99x |
| 306 | -- vertical scaling for source widths > 2048: |
| 307 | Vertical_Limit : constant Pos32 := |
| 308 | (Framebuffer.Height * |
| 309 | (if Controller.PS_CTRL_2 = Registers.Invalid_Register and |
| 310 | Framebuffer.Width > 2048 |
| 311 | then |
| 312 | 199 |
| 313 | else |
| 314 | 299)) / 100; |
| 315 | |
| 316 | Width, Height : Pos32; |
| 317 | begin |
| 318 | -- Writes to WIN_SZ arm the PS registers. |
| 319 | |
| 320 | Scale_Keep_Aspect |
| 321 | (Width => Width, |
| 322 | Height => Height, |
| 323 | Max_Width => Pos32'Min (Horizontal_Limit, Pos32 (Mode.H_Visible)), |
| 324 | Max_Height => Pos32'Min (Vertical_Limit, Pos32 (Mode.V_Visible)), |
| 325 | Framebuffer => Framebuffer); |
| 326 | |
| 327 | Registers.Write |
| 328 | (Register => Controller.PS_CTRL_1, |
| 329 | Value => PS_CTRL_ENABLE_SCALER or Scaler_Mode); |
| 330 | Registers.Write |
| 331 | (Register => Controller.PS_WIN_POS_1, |
| 332 | Value => |
| 333 | Shift_Left (Word32 (Pos32 (Mode.H_Visible) - Width) / 2, 16) or |
| 334 | Word32 (Pos32 (Mode.V_Visible) - Height) / 2); |
| 335 | Registers.Write |
| 336 | (Register => Controller.PS_WIN_SZ_1, |
| 337 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 338 | end Setup_Skylake_Pipe_Scaler; |
| 339 | |
| 340 | procedure Setup_Ironlake_Panel_Fitter |
| 341 | (Controller : in Controller_Type; |
| 342 | Mode : in HW.GFX.Mode_Type; |
| 343 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 344 | with |
| 345 | Pre => |
| 346 | Framebuffer.Width <= Pos32 (Mode.H_Visible) and |
| 347 | Framebuffer.Height <= Pos32 (Mode.V_Visible) |
| 348 | is |
| 349 | -- Force 1:1 mapping of panel fitter:pipe |
| 350 | PF_Ctrl_Pipe_Sel : constant Word32 := |
| 351 | (if Config.Has_PF_Pipe_Select then |
| 352 | (case Controller.PF_CTRL is |
| 353 | when Registers.PFA_CTL_1 => 0 * 2 ** 29, |
| 354 | when Registers.PFB_CTL_1 => 1 * 2 ** 29, |
| 355 | when Registers.PFC_CTL_1 => 2 * 2 ** 29, |
| 356 | when others => 0) else 0); |
| 357 | |
| 358 | Width, Height : Pos32; |
| 359 | begin |
| 360 | -- Writes to WIN_SZ arm the PF registers. |
| 361 | |
| 362 | Scale_Keep_Aspect |
| 363 | (Width => Width, |
| 364 | Height => Height, |
| 365 | Max_Width => Pos32 (Mode.H_Visible), |
| 366 | Max_Height => Pos32 (Mode.V_Visible), |
| 367 | Framebuffer => Framebuffer); |
| 368 | |
| 369 | Registers.Write |
| 370 | (Register => Controller.PF_CTRL, |
| 371 | Value => PF_CTRL_ENABLE or PF_Ctrl_Pipe_Sel or PF_CTRL_FILTER_MED); |
| 372 | Registers.Write |
| 373 | (Register => Controller.PF_WIN_POS, |
| 374 | Value => |
| 375 | Shift_Left (Word32 (Pos32 (Mode.H_Visible) - Width) / 2, 16) or |
| 376 | Word32 (Pos32 (Mode.V_Visible) - Height) / 2); |
| 377 | Registers.Write |
| 378 | (Register => Controller.PF_WIN_SZ, |
| 379 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 380 | end Setup_Ironlake_Panel_Fitter; |
| 381 | |
| 382 | procedure Setup_Scaling |
| 383 | (Controller : in Controller_Type; |
| 384 | Mode : in HW.GFX.Mode_Type; |
| 385 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 386 | with |
| 387 | Pre => |
| 388 | Framebuffer.Width <= Pos32 (Mode.H_Visible) and |
| 389 | Framebuffer.Height <= Pos32 (Mode.V_Visible) |
| 390 | is |
| 391 | begin |
| 392 | if Framebuffer.Width /= Pos32 (Mode.H_Visible) or |
| 393 | Framebuffer.Height /= Pos32 (Mode.V_Visible) |
| 394 | then |
| 395 | if Config.Has_Plane_Control then |
| 396 | Setup_Skylake_Pipe_Scaler (Controller, Mode, Framebuffer); |
| 397 | else |
| 398 | Setup_Ironlake_Panel_Fitter (Controller, Mode, Framebuffer); |
| 399 | end if; |
| 400 | end if; |
| 401 | end Setup_Scaling; |
| 402 | |
| 403 | ---------------------------------------------------------------------------- |
| 404 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 405 | procedure On |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 406 | (Pipe : Pipe_Index; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 407 | Port_Cfg : Port_Config; |
| 408 | Framebuffer : Framebuffer_Type) |
| 409 | is |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 410 | -- Enable dithering if framebuffer BPC differs from port BPC, |
| 411 | -- as smooth gradients look really bad without. |
| 412 | Dither : constant Boolean := Framebuffer.BPC /= Port_Cfg.Mode.BPC; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 413 | begin |
| 414 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 415 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 416 | Transcoder.Setup (Pipe, Port_Cfg); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 417 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 418 | Setup_Display |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 419 | (Controllers (Pipe), Framebuffer, Port_Cfg.Mode.BPC, Dither); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 420 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 421 | Setup_Scaling (Controllers (Pipe), Port_Cfg.Mode, Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 422 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 423 | Transcoder.On (Pipe, Port_Cfg, Dither); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 424 | end On; |
| 425 | |
| 426 | ---------------------------------------------------------------------------- |
| 427 | |
| 428 | procedure Planes_Off (Controller : Controller_Type) is |
| 429 | begin |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 430 | Registers.Unset_Mask (Controller.SPCNTR, DSPCNTR_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 431 | if Config.Has_Plane_Control then |
| 432 | Clear_Watermarks (Controller); |
| 433 | Registers.Unset_Mask (Controller.PLANE_CTL, PLANE_CTL_PLANE_ENABLE); |
| 434 | Registers.Write (Controller.PLANE_SURF, 16#0000_0000#); |
| 435 | else |
| 436 | Registers.Unset_Mask (Controller.DSPCNTR, DSPCNTR_ENABLE); |
| 437 | end if; |
| 438 | end Planes_Off; |
| 439 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 440 | procedure Panel_Fitter_Off (Controller : Controller_Type) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 441 | is |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 442 | use type HW.GFX.GMA.Registers.Registers_Invalid_Index; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 443 | begin |
| 444 | -- Writes to WIN_SZ arm the PS/PF registers. |
| 445 | if Config.Has_Plane_Control then |
| 446 | Registers.Unset_Mask (Controller.PS_CTRL_1, PS_CTRL_ENABLE_SCALER); |
| 447 | Registers.Write (Controller.PS_WIN_SZ_1, 16#0000_0000#); |
| 448 | if Controller.PS_CTRL_2 /= Registers.Invalid_Register and |
| 449 | Controller.PS_WIN_SZ_2 /= Registers.Invalid_Register |
| 450 | then |
| 451 | Registers.Unset_Mask (Controller.PS_CTRL_2, PS_CTRL_ENABLE_SCALER); |
| 452 | Registers.Write (Controller.PS_WIN_SZ_2, 16#0000_0000#); |
| 453 | end if; |
| 454 | else |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 455 | Registers.Unset_Mask (Controller.PF_CTRL, PF_CTRL_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 456 | Registers.Write (Controller.PF_WIN_SZ, 16#0000_0000#); |
| 457 | end if; |
| 458 | end Panel_Fitter_Off; |
| 459 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 460 | procedure Off (Pipe : Pipe_Index) |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 461 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 462 | begin |
| 463 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 464 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 465 | Planes_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 466 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 467 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 468 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 469 | end Off; |
| 470 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 471 | procedure Legacy_VGA_Off |
| 472 | is |
| 473 | use type HW.Word8; |
| 474 | Reg8 : Word8; |
| 475 | begin |
| 476 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 477 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 478 | Port_IO.OutB (VGA_SR_DATA, Reg8 or VGA_SR01_SCREEN_OFF); |
| 479 | Time.U_Delay (100); -- PRM says 100us, Linux does 300 |
| 480 | Registers.Set_Mask (Registers.VGACNTRL, VGA_CONTROL_VGA_DISPLAY_DISABLE); |
| 481 | end Legacy_VGA_Off; |
| 482 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 483 | procedure All_Off |
| 484 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 485 | begin |
| 486 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 487 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 488 | Legacy_VGA_Off; |
| 489 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 490 | for Pipe in Pipe_Index loop |
| 491 | Planes_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 492 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 493 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame^] | 494 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 495 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 496 | end All_Off; |
| 497 | |
| 498 | ---------------------------------------------------------------------------- |
| 499 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 500 | procedure Update_Offset (Pipe : Pipe_Index; Framebuffer : Framebuffer_Type) |
| 501 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 502 | begin |
| 503 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 504 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 505 | Registers.Write |
| 506 | (Controllers (Pipe).DSPSURF, Framebuffer.Offset and 16#ffff_f000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 507 | end Update_Offset; |
| 508 | |
| 509 | ---------------------------------------------------------------------------- |
| 510 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 511 | function Get_Pipe_Hint (Pipe : Pipe_Index) return Word32 |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 512 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 513 | begin |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 514 | return |
| 515 | (case Pipe is |
| 516 | when Primary => 0, |
| 517 | when Secondary => 1, |
| 518 | when Tertiary => 2); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 519 | end Get_Pipe_Hint; |
| 520 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 521 | end HW.GFX.GMA.Pipe_Setup; |