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