| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 2 | -- Copyright (C) 2015-2018 secunet Security Networks AG |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 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; |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 30 | DSPCNTR_FORMAT_MASK : constant := 15 * 2 ** 26; |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 31 | DSPCNTR_DISABLE_TRICKLE_FEED : constant := 1 * 2 ** 14; |
| 32 | DSPCNTR_TILED_SURFACE_LINEAR : constant := 0 * 2 ** 10; |
| 33 | DSPCNTR_TILED_SURFACE_X_TILED : constant := 1 * 2 ** 10; |
| 34 | |
| 35 | DSPCNTR_TILED_SURFACE : constant array (Tiling_Type) of Word32 := |
| 36 | (Linear => DSPCNTR_TILED_SURFACE_LINEAR, |
| 37 | X_Tiled => DSPCNTR_TILED_SURFACE_X_TILED, |
| 38 | Y_Tiled => 0); -- unsupported |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 39 | |
| 40 | DSPCNTR_MASK : constant Word32 := |
| 41 | DSPCNTR_ENABLE or |
| 42 | DSPCNTR_GAMMA_CORRECTION or |
| 43 | DSPCNTR_FORMAT_MASK or |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 44 | DSPCNTR_DISABLE_TRICKLE_FEED or |
| 45 | DSPCNTR_TILED_SURFACE_X_TILED; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 46 | |
| 47 | PLANE_CTL_PLANE_ENABLE : constant := 1 * 2 ** 31; |
| 48 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 : constant := 4 * 2 ** 24; |
| 49 | PLANE_CTL_PLANE_GAMMA_DISABLE : constant := 1 * 2 ** 13; |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 50 | PLANE_CTL_TILED_SURFACE_MASK : constant := 7 * 2 ** 10; |
| 51 | PLANE_CTL_TILED_SURFACE_LINEAR : constant := 0 * 2 ** 10; |
| 52 | PLANE_CTL_TILED_SURFACE_X_TILED : constant := 1 * 2 ** 10; |
| 53 | PLANE_CTL_TILED_SURFACE_Y_TILED : constant := 4 * 2 ** 10; |
| 54 | PLANE_CTL_TILED_SURFACE_YF_TILED : constant := 5 * 2 ** 10; |
| 55 | |
| 56 | PLANE_CTL_TILED_SURFACE : constant array (Tiling_Type) of Word32 := |
| 57 | (Linear => PLANE_CTL_TILED_SURFACE_LINEAR, |
| 58 | X_Tiled => PLANE_CTL_TILED_SURFACE_X_TILED, |
| 59 | Y_Tiled => PLANE_CTL_TILED_SURFACE_Y_TILED); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 60 | |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 61 | PLANE_CTL_PLANE_ROTATION_MASK : constant := 3 * 2 ** 0; |
| 62 | PLANE_CTL_PLANE_ROTATION : constant array (Rotation_Type) of Word32 := |
| 63 | (No_Rotation => 0 * 2 ** 0, |
| 64 | Rotated_90 => 1 * 2 ** 0, |
| 65 | Rotated_180 => 2 * 2 ** 0, |
| 66 | Rotated_270 => 3 * 2 ** 0); |
| 67 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 68 | PLANE_WM_ENABLE : constant := 1 * 2 ** 31; |
| 69 | PLANE_WM_LINES_SHIFT : constant := 14; |
| 70 | PLANE_WM_LINES_MASK : constant := 16#001f# * 2 ** 14; |
| 71 | PLANE_WM_BLOCKS_MASK : constant := 16#03ff# * 2 ** 0; |
| 72 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 73 | VGA_SR_INDEX : constant := 16#03c4#; |
| 74 | VGA_SR_DATA : constant := 16#03c5#; |
| 75 | VGA_SR01 : constant := 16#01#; |
| 76 | VGA_SR01_SCREEN_OFF : constant := 1 * 2 ** 5; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 77 | |
| 78 | VGA_CONTROL_VGA_DISPLAY_DISABLE : constant := 1 * 2 ** 31; |
| 79 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK : constant := 16#0003# * 2 ** 6; |
| 80 | VGA_CONTROL_BLINK_DUTY_CYCLE_50 : constant := 2 * 2 ** 6; |
| 81 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK : constant := 16#003f# * 2 ** 0; |
| 82 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 83 | CUR_CTL_PIPE_SELECT : constant array (Pipe_Index) of Word32 := |
| 84 | (Primary => 0 * 2 ** 28, |
| 85 | Secondary => 1 * 2 ** 28, |
| 86 | Tertiary => 2 * 2 ** 28); |
| 87 | CUR_CTL_MODE : constant array (Cursor_Mode, Cursor_Size) of Word32 := |
| 88 | (No_Cursor => (others => 16#00#), |
| 89 | ARGB_Cursor => |
| 90 | (Cursor_64x64 => 16#27#, |
| 91 | Cursor_128x128 => 16#22#, |
| 92 | Cursor_256x256 => 16#23#)); |
| 93 | |
| 94 | function CUR_POS_Y (Y : Int32) return Word32 is |
| 95 | ((if Y >= 0 then 0 else 1 * 2 ** 31) or Shift_Left (Word32 (abs Y), 16)) |
| 96 | with |
| 97 | Pre => Y > Int32'First; |
| 98 | function CUR_POS_X (X : Int32) return Word32 is |
| 99 | ((if X >= 0 then 0 else 1 * 2 ** 15) or Word32 (abs X)) |
| 100 | with |
| 101 | Pre => X > Int32'First; |
| 102 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 103 | subtype VGA_Cycle_Count is Pos32 range 2 .. 128; |
| 104 | function VGA_CONTROL_VSYNC_BLINK_RATE |
| 105 | (Cycles : VGA_Cycle_Count) |
| 106 | return Word32 |
| 107 | is |
| 108 | begin |
| 109 | return Word32 (Cycles) / 2 - 1; |
| 110 | end VGA_CONTROL_VSYNC_BLINK_RATE; |
| 111 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 112 | PF_CTRL_ENABLE : constant := 1 * 2 ** 31; |
| 113 | PF_CTRL_PIPE_SELECT_MASK : constant := 3 * 2 ** 29; |
| 114 | PF_CTRL_FILTER_MED : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 115 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 116 | PS_CTRL_ENABLE_SCALER : constant := 1 * 2 ** 31; |
| 117 | PS_CTRL_SCALER_MODE_7X5_EXTENDED : constant := 1 * 2 ** 28; |
| 118 | PS_CTRL_FILTER_SELECT_MEDIUM_2 : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 119 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 120 | GMCH_PFIT_CONTROL_SELECT_MASK : constant := 3 * 2 ** 29; |
| 121 | GMCH_PFIT_CONTROL_SELECT_PIPE_A : constant := 0 * 2 ** 29; |
| 122 | GMCH_PFIT_CONTROL_SELECT_PIPE_B : constant := 1 * 2 ** 29; |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 123 | GMCH_PFIT_CONTROL_SCALING_MASK : constant := 3 * 2 ** 26; |
| 124 | GMCH_PFIT_CONTROL_SCALING : constant array (Scaling_Aspect) of Word32 := |
| 125 | (Uniform => 0 * 2 ** 26, |
| 126 | Pillarbox => 2 * 2 ** 26, |
| 127 | Letterbox => 3 * 2 ** 26); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 128 | |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 129 | VGACNTRL_REG : constant Registers.Registers_Index := |
| 130 | (if Config.Has_GMCH_VGACNTRL then |
| 131 | Registers.GMCH_VGACNTRL |
| 132 | else Registers.CPU_VGACNTRL); |
| 133 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 134 | --------------------------------------------------------------------------- |
| 135 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 136 | function PLANE_WM_LINES (Lines : Natural) return Word32 is |
| 137 | begin |
| 138 | return Shift_Left (Word32 (Lines), PLANE_WM_LINES_SHIFT) |
| 139 | and PLANE_WM_LINES_MASK; |
| 140 | end PLANE_WM_LINES; |
| 141 | |
| 142 | function PLANE_WM_BLOCKS (Blocks : Natural) return Word32 is |
| 143 | begin |
| 144 | return Word32 (Blocks) and PLANE_WM_BLOCKS_MASK; |
| 145 | end PLANE_WM_BLOCKS; |
| 146 | |
| 147 | --------------------------------------------------------------------------- |
| 148 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 149 | function Encode (LSW, MSW : Pos32) return Word32 is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 150 | begin |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 151 | return Shift_Left (Word32 (MSW) - 1, 16) or (Word32 (LSW) - 1); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 152 | end Encode; |
| 153 | |
| 154 | ---------------------------------------------------------------------------- |
| 155 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 156 | procedure Clear_Watermarks (Controller : Controller_Type) is |
| 157 | begin |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 158 | Registers.Write (Controller.CUR_BUF_CFG, 16#0000_0000#); |
| 159 | for Level in WM_Levels loop |
| 160 | Registers.Write (Controller.CUR_WM (Level), 16#0000_0000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 161 | end loop; |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 162 | Registers.Write (Controller.PLANE_BUF_CFG, 16#0000_0000#); |
| 163 | for Level in WM_Levels loop |
| 164 | Registers.Write (Controller.PLANE_WM (Level), 16#0000_0000#); |
| 165 | end loop; |
| 166 | Registers.Write (Controller.WM_LINETIME, 16#0000_0000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 167 | end Clear_Watermarks; |
| 168 | |
| 169 | procedure Setup_Watermarks (Controller : Controller_Type) |
| 170 | is |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 171 | type Per_Plane_Buffer_Range is array (Pipe_Index) of Word32; |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 172 | Cur_Buffer_Range : constant Per_Plane_Buffer_Range := |
| 173 | (Primary => Shift_Left ( 7, 16) or 0, |
| 174 | Secondary => Shift_Left (167, 16) or 160, |
| 175 | Tertiary => Shift_Left (327, 16) or 320); |
| 176 | Plane_Buffer_Range : constant Per_Plane_Buffer_Range := |
| 177 | (Primary => Shift_Left (159, 16) or 8, |
| 178 | Secondary => Shift_Left (319, 16) or 168, |
| 179 | Tertiary => Shift_Left (479, 16) or 328); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 180 | begin |
| 181 | Registers.Write |
| 182 | (Register => Controller.PLANE_BUF_CFG, |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 183 | Value => Plane_Buffer_Range (Controller.Pipe)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 184 | Registers.Write |
| 185 | (Register => Controller.PLANE_WM (0), |
| 186 | Value => PLANE_WM_ENABLE or |
| 187 | PLANE_WM_LINES (2) or |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 188 | PLANE_WM_BLOCKS (152)); |
| 189 | Registers.Write |
| 190 | (Register => Controller.CUR_BUF_CFG, |
| 191 | Value => Cur_Buffer_Range (Controller.Pipe)); |
| 192 | Registers.Write |
| 193 | (Register => Controller.CUR_WM (0), |
| 194 | Value => PLANE_WM_ENABLE or |
| 195 | PLANE_WM_LINES (2) or |
| 196 | PLANE_WM_BLOCKS (8)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 197 | end Setup_Watermarks; |
| 198 | |
| 199 | ---------------------------------------------------------------------------- |
| 200 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 201 | procedure Setup_Hires_Plane |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 202 | (Controller : Controller_Type; |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 203 | FB : HW.GFX.Framebuffer_Type) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 204 | with |
| 205 | Global => (In_Out => Registers.Register_State), |
| 206 | Depends => |
| 207 | (Registers.Register_State |
| 208 | =>+ |
| 209 | (Registers.Register_State, |
| 210 | Controller, |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 211 | FB)), |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 212 | Pre => FB.Height + FB.Start_Y <= FB.V_Stride |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 213 | is |
| 214 | -- FIXME: setup correct format, based on framebuffer RGB format |
| 215 | Format : constant Word32 := 6 * 2 ** 26; |
| 216 | PRI : Word32 := DSPCNTR_ENABLE or Format; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 217 | begin |
| 218 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 219 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 220 | if Config.Has_Plane_Control then |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 221 | declare |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 222 | Stride, Offset : Word32; |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 223 | Width : constant Width_Type := Rotated_Width (FB); |
| 224 | Height : constant Width_Type := Rotated_Height (FB); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 225 | begin |
| 226 | if Rotation_90 (FB) then |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 227 | Stride := Word32 (FB_Pitch (FB.V_Stride, FB)); |
| 228 | Offset := Shift_Left (Word32 (FB.Start_X), 16) or |
| 229 | Word32 (FB.V_Stride - FB.Height - FB.Start_Y); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 230 | else |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 231 | Stride := Word32 (FB_Pitch (FB.Stride, FB)); |
| 232 | Offset := Shift_Left (Word32 (FB.Start_Y), 16) or |
| 233 | Word32 (FB.Start_X); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 234 | end if; |
| 235 | Registers.Write |
| 236 | (Register => Controller.PLANE_CTL, |
| 237 | Value => PLANE_CTL_PLANE_ENABLE or |
| 238 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 or |
| 239 | PLANE_CTL_PLANE_GAMMA_DISABLE or |
| 240 | PLANE_CTL_TILED_SURFACE (FB.Tiling) or |
| 241 | PLANE_CTL_PLANE_ROTATION (FB.Rotation)); |
| 242 | Registers.Write (Controller.PLANE_OFFSET, Offset); |
| 243 | Registers.Write (Controller.PLANE_SIZE, Encode (Width, Height)); |
| 244 | Registers.Write (Controller.PLANE_STRIDE, Stride); |
| 245 | Registers.Write (Controller.PLANE_POS, 16#0000_0000#); |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 246 | Registers.Write (Controller.PLANE_SURF, FB.Offset and 16#ffff_f000#); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 247 | end; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 248 | else |
| 249 | if Config.Disable_Trickle_Feed then |
| 250 | PRI := PRI or DSPCNTR_DISABLE_TRICKLE_FEED; |
| 251 | end if; |
| 252 | -- for now, just disable gamma LUT (can't do anything |
| 253 | -- useful without colorimetry information from display) |
| 254 | Registers.Unset_And_Set_Mask |
| 255 | (Register => Controller.DSPCNTR, |
| 256 | Mask_Unset => DSPCNTR_MASK, |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 257 | Mask_Set => PRI or DSPCNTR_TILED_SURFACE (FB.Tiling)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 258 | |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 259 | Registers.Write |
| 260 | (Controller.DSPSTRIDE, Word32 (Pixel_To_Bytes (FB.Stride, FB))); |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 261 | if Config.Has_DSP_Linoff and then FB.Tiling = Linear then |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 262 | Registers.Write |
| 263 | (Register => Controller.DSPLINOFF, |
| 264 | Value => Word32 (Pixel_To_Bytes |
| 265 | (FB.Start_Y * FB.Stride + FB.Start_X, FB))); |
| 266 | Registers.Write (Controller.DSPTILEOFF, 0); |
| 267 | else |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 268 | if Config.Has_DSP_Linoff then |
| 269 | Registers.Write (Controller.DSPLINOFF, 0); |
| 270 | end if; |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 271 | Registers.Write |
| 272 | (Register => Controller.DSPTILEOFF, |
| 273 | Value => Shift_Left (Word32 (FB.Start_Y), 16) or |
| 274 | Word32 (FB.Start_X)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 275 | end if; |
| Nico Huber | 8fd92a1 | 2018-01-02 14:02:59 +0100 | [diff] [blame] | 276 | Registers.Write (Controller.DSPSURF, FB.Offset and 16#ffff_f000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 277 | end if; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 278 | end Setup_Hires_Plane; |
| 279 | |
| 280 | procedure Setup_Display |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 281 | (Controller : Controller_Type; |
| 282 | Framebuffer : Framebuffer_Type; |
| 283 | Dither_BPC : BPC_Type; |
| 284 | Dither : Boolean) |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 285 | with |
| 286 | Global => (In_Out => (Registers.Register_State, Port_IO.State)), |
| 287 | Depends => |
| 288 | (Registers.Register_State |
| 289 | =>+ |
| 290 | (Registers.Register_State, |
| 291 | Controller, |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 292 | Framebuffer, |
| 293 | Dither_BPC, |
| 294 | Dither), |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 295 | Port_IO.State |
| 296 | =>+ |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 297 | (Framebuffer)), |
| 298 | Pre => |
| 299 | Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET or |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 300 | Framebuffer.Height + Framebuffer.Start_Y <= Framebuffer.V_Stride |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 301 | is |
| 302 | use type Word8; |
| 303 | |
| 304 | Reg8 : Word8; |
| 305 | begin |
| 306 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 307 | |
| 308 | if Config.Has_Plane_Control then |
| 309 | Setup_Watermarks (Controller); |
| 310 | end if; |
| 311 | |
| 312 | if Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| Nico Huber | fbb4220 | 2016-11-07 15:08:26 +0100 | [diff] [blame] | 313 | if Config.VGA_Plane_Workaround then |
| 314 | Registers.Unset_And_Set_Mask |
| 315 | (Register => Registers.ILK_DISPLAY_CHICKEN1, |
| 316 | Mask_Unset => ILK_DISPLAY_CHICKEN1_VGA_MASK, |
| 317 | Mask_Set => ILK_DISPLAY_CHICKEN1_VGA_ENABLE); |
| 318 | Registers.Unset_And_Set_Mask |
| 319 | (Register => Registers.ILK_DISPLAY_CHICKEN2, |
| 320 | Mask_Unset => ILK_DISPLAY_CHICKEN2_VGA_MASK, |
| 321 | Mask_Set => ILK_DISPLAY_CHICKEN2_VGA_ENABLE); |
| 322 | end if; |
| 323 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 324 | Registers.Unset_And_Set_Mask |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 325 | (Register => VGACNTRL_REG, |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 326 | Mask_Unset => VGA_CONTROL_VGA_DISPLAY_DISABLE or |
| 327 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK or |
| 328 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK, |
| 329 | Mask_Set => VGA_CONTROL_BLINK_DUTY_CYCLE_50 or |
| 330 | VGA_CONTROL_VSYNC_BLINK_RATE (30)); |
| 331 | |
| 332 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 333 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 334 | Port_IO.OutB (VGA_SR_DATA, Reg8 and not (VGA_SR01_SCREEN_OFF)); |
| 335 | else |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 336 | Setup_Hires_Plane (Controller, Framebuffer); |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 337 | end if; |
| 338 | |
| 339 | Registers.Write |
| 340 | (Register => Controller.PIPESRC, |
| 341 | Value => Encode |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 342 | (Rotated_Height (Framebuffer), Rotated_Width (Framebuffer))); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 343 | |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 344 | if Config.Has_Pipeconf_Misc then |
| 345 | Registers.Write |
| 346 | (Register => Controller.PIPEMISC, |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 347 | Value => Transcoder.BPC_Conf (Dither_BPC, Dither)); |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 348 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 349 | end Setup_Display; |
| 350 | |
| 351 | ---------------------------------------------------------------------------- |
| 352 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 353 | procedure Update_Cursor |
| 354 | (Pipe : Pipe_Index; |
| 355 | FB : Framebuffer_Type; |
| 356 | Cursor : Cursor_Type) |
| 357 | is |
| 358 | begin |
| 359 | -- on some platforms writing CUR_CTL disables self-arming of CUR_POS |
| 360 | -- so keep it first |
| 361 | Registers.Write |
| 362 | (Register => Controllers (Pipe).CUR_CTL, |
| 363 | Value => CUR_CTL_PIPE_SELECT (Pipe) or |
| 364 | CUR_CTL_MODE (Cursor.Mode, Cursor.Size)); |
| 365 | Place_Cursor (Pipe, FB, Cursor); |
| 366 | end Update_Cursor; |
| 367 | |
| 368 | procedure Place_Cursor |
| 369 | (Pipe : Pipe_Index; |
| 370 | FB : Framebuffer_Type; |
| 371 | Cursor : Cursor_Type) |
| 372 | is |
| 373 | Width : constant Width_Type := Cursor_Width (Cursor.Size); |
| 374 | X : Int32 := Cursor.Center_X - Width / 2; |
| 375 | Y : Int32 := Cursor.Center_Y - Width / 2; |
| 376 | begin |
| 377 | -- off-screen cursor needs special care |
| 378 | if X <= -Width or Y <= -Width or |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 379 | X >= Rotated_Width (FB) or Y >= Rotated_Height (FB) or |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 380 | X > Config.Maximum_Cursor_X or Y > Config.Maximum_Cursor_Y |
| 381 | then |
| 382 | X := -Width; |
| 383 | Y := -Width; |
| 384 | end if; |
| 385 | Registers.Write |
| 386 | (Register => Controllers (Pipe).CUR_POS, |
| 387 | Value => CUR_POS_Y (Y) or CUR_POS_X (X)); |
| 388 | -- write to CUR_BASE always arms other CUR_* registers |
| 389 | Registers.Write |
| 390 | (Register => Controllers (Pipe).CUR_BASE, |
| 391 | Value => Shift_Left (Word32 (Cursor.GTT_Offset), 12)); |
| 392 | end Place_Cursor; |
| 393 | |
| 394 | ---------------------------------------------------------------------------- |
| 395 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 396 | function Scale (Val, Max, Num, Denom : Width_Type) |
| 397 | return Width_Type is ((Val * Num) / Denom) |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 398 | with |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 399 | Pre => Denom <= Num and Val * Num < Max * Denom, |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 400 | Post => Scale'Result < Max; |
| 401 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 402 | procedure Scale_Keep_Aspect |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 403 | (Width : out Width_Type; |
| 404 | Height : out Height_Type; |
| 405 | Max_Width : in Width_Type; |
| 406 | Max_Height : in Height_Type; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 407 | Framebuffer : in Framebuffer_Type) |
| 408 | with |
| 409 | Pre => |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 410 | Rotated_Width (Framebuffer) <= Max_Width and |
| 411 | Rotated_Height (Framebuffer) <= Max_Height, |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 412 | Post => |
| 413 | Width <= Max_Width and Height <= Max_Height |
| 414 | is |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 415 | Src_Width : constant Width_Type := Rotated_Width (Framebuffer); |
| 416 | Src_Height : constant Height_Type := Rotated_Height (Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 417 | begin |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 418 | case Scaling_Type (Src_Width, Src_Height, Max_Width, Max_Height) is |
| 419 | when Letterbox => |
| 420 | Width := Max_Width; |
| 421 | Height := Scale (Src_Height, Max_Height, Max_Width, Src_Width); |
| 422 | when Pillarbox => |
| 423 | Width := Scale (Src_Width, Max_Width, Max_Height, Src_Height); |
| 424 | Height := Max_Height; |
| 425 | when Uniform => |
| 426 | Width := Max_Width; |
| 427 | Height := Max_Height; |
| 428 | end case; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 429 | end Scale_Keep_Aspect; |
| 430 | |
| 431 | procedure Setup_Skylake_Pipe_Scaler |
| 432 | (Controller : in Controller_Type; |
| 433 | Mode : in HW.GFX.Mode_Type; |
| 434 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 435 | with |
| 436 | Pre => |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 437 | Rotated_Width (Framebuffer) <= Mode.H_Visible and |
| 438 | Rotated_Height (Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 439 | is |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 440 | use type Registers.Registers_Invalid_Index; |
| 441 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 442 | -- Enable 7x5 extended mode where possible: |
| 443 | Scaler_Mode : constant Word32 := |
| 444 | (if Controller.PS_CTRL_2 /= Registers.Invalid_Register then |
| 445 | PS_CTRL_SCALER_MODE_7X5_EXTENDED else 0); |
| 446 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 447 | Width_In : constant Width_Type := Rotated_Width (Framebuffer); |
| 448 | Height_In : constant Height_Type := Rotated_Height (Framebuffer); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 449 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 450 | -- We can scale up to 2.99x horizontally: |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 451 | Horizontal_Limit : constant Pos32 := (Width_In * 299) / 100; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 452 | -- The third scaler is limited to 1.99x |
| 453 | -- vertical scaling for source widths > 2048: |
| 454 | Vertical_Limit : constant Pos32 := |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 455 | (Height_In * |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 456 | (if Controller.PS_CTRL_2 = Registers.Invalid_Register and |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 457 | Width_In > 2048 |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 458 | then |
| 459 | 199 |
| 460 | else |
| 461 | 299)) / 100; |
| 462 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 463 | Width : Width_Type; |
| 464 | Height : Height_Type; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 465 | begin |
| 466 | -- Writes to WIN_SZ arm the PS registers. |
| 467 | |
| 468 | Scale_Keep_Aspect |
| 469 | (Width => Width, |
| 470 | Height => Height, |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 471 | Max_Width => Pos32'Min (Horizontal_Limit, Mode.H_Visible), |
| 472 | Max_Height => Pos32'Min (Vertical_Limit, Mode.V_Visible), |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 473 | Framebuffer => Framebuffer); |
| 474 | |
| 475 | Registers.Write |
| 476 | (Register => Controller.PS_CTRL_1, |
| 477 | Value => PS_CTRL_ENABLE_SCALER or Scaler_Mode); |
| 478 | Registers.Write |
| 479 | (Register => Controller.PS_WIN_POS_1, |
| 480 | Value => |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 481 | Shift_Left (Word32 (Mode.H_Visible - Width) / 2, 16) or |
| 482 | Word32 (Mode.V_Visible - Height) / 2); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 483 | Registers.Write |
| 484 | (Register => Controller.PS_WIN_SZ_1, |
| 485 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 486 | end Setup_Skylake_Pipe_Scaler; |
| 487 | |
| 488 | procedure Setup_Ironlake_Panel_Fitter |
| 489 | (Controller : in Controller_Type; |
| 490 | Mode : in HW.GFX.Mode_Type; |
| 491 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 492 | with |
| 493 | Pre => |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 494 | Rotated_Width (Framebuffer) <= Mode.H_Visible and |
| 495 | Rotated_Height (Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 496 | is |
| 497 | -- Force 1:1 mapping of panel fitter:pipe |
| 498 | PF_Ctrl_Pipe_Sel : constant Word32 := |
| 499 | (if Config.Has_PF_Pipe_Select then |
| 500 | (case Controller.PF_CTRL is |
| 501 | when Registers.PFA_CTL_1 => 0 * 2 ** 29, |
| 502 | when Registers.PFB_CTL_1 => 1 * 2 ** 29, |
| 503 | when Registers.PFC_CTL_1 => 2 * 2 ** 29, |
| 504 | when others => 0) else 0); |
| 505 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 506 | Width : Width_Type; |
| 507 | Height : Height_Type; |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 508 | X, Y : Int32; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 509 | begin |
| 510 | -- Writes to WIN_SZ arm the PF registers. |
| 511 | |
| 512 | Scale_Keep_Aspect |
| 513 | (Width => Width, |
| 514 | Height => Height, |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 515 | Max_Width => Mode.H_Visible, |
| 516 | Max_Height => Mode.V_Visible, |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 517 | Framebuffer => Framebuffer); |
| 518 | |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 519 | -- Do not scale to odd width (at least Haswell has trouble with this). |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 520 | if Width < Mode.H_Visible and Width mod 2 = 1 then |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 521 | Width := Width + 1; |
| 522 | end if; |
| 523 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 524 | X := (Mode.H_Visible - Width) / 2; |
| 525 | Y := (Mode.V_Visible - Height) / 2; |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 526 | |
| 527 | -- Hardware is picky about minimal horizontal gaps. |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 528 | if Mode.H_Visible - Width <= 3 then |
| 529 | Width := Mode.H_Visible; |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 530 | X := 0; |
| 531 | end if; |
| 532 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 533 | Registers.Write |
| 534 | (Register => Controller.PF_CTRL, |
| 535 | Value => PF_CTRL_ENABLE or PF_Ctrl_Pipe_Sel or PF_CTRL_FILTER_MED); |
| 536 | Registers.Write |
| 537 | (Register => Controller.PF_WIN_POS, |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 538 | Value => Shift_Left (Word32 (X), 16) or Word32 (Y)); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 539 | Registers.Write |
| 540 | (Register => Controller.PF_WIN_SZ, |
| 541 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 542 | end Setup_Ironlake_Panel_Fitter; |
| 543 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 544 | procedure Setup_Gmch_Panel_Fitter |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 545 | (Controller : in Controller_Type; |
| 546 | Mode : in HW.GFX.Mode_Type; |
| 547 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 548 | is |
| 549 | PF_Ctrl_Pipe_Sel : constant Word32 := |
| 550 | (case Controller.Pipe is |
| 551 | when Primary => GMCH_PFIT_CONTROL_SELECT_PIPE_A, |
| 552 | when Secondary => GMCH_PFIT_CONTROL_SELECT_PIPE_B, |
| 553 | when others => 0); |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 554 | |
| Arthur Heymans | f70edda | 2018-08-21 18:37:00 +0200 | [diff] [blame] | 555 | -- Work around a quirk: |
| 556 | -- In legacy VGA mode Pillarbox fails to display anything so just force |
| 557 | -- 'auto' mode on all displays, which will the output stretched to |
| 558 | -- fullscreen . |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 559 | PF_Ctrl_Scaling : constant Word32 := |
| Arthur Heymans | f70edda | 2018-08-21 18:37:00 +0200 | [diff] [blame] | 560 | (if Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| 561 | GMCH_PFIT_CONTROL_SCALING (Uniform) |
| 562 | else |
| 563 | GMCH_PFIT_CONTROL_SCALING (Scaling_Type (Framebuffer, Mode))); |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 564 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 565 | In_Use : Boolean; |
| 566 | begin |
| 567 | Registers.Is_Set_Mask |
| 568 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 569 | Mask => PF_CTRL_ENABLE, |
| 570 | Result => In_Use); |
| 571 | |
| 572 | if not In_Use then |
| 573 | Registers.Write |
| 574 | (Register => Registers.GMCH_PFIT_CONTROL, |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 575 | Value => PF_CTRL_ENABLE or PF_Ctrl_Pipe_Sel or PF_Ctrl_Scaling); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 576 | else |
| Nico Huber | 7ba7bd6 | 2018-06-06 12:27:09 +0200 | [diff] [blame] | 577 | pragma Debug (Debug.Put_Line |
| 578 | ("GMCH Pannel fitter already in use, skipping...")); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 579 | end if; |
| 580 | end Setup_Gmch_Panel_Fitter; |
| 581 | |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 582 | procedure Gmch_Panel_Fitter_Pipe (Pipe : out Pipe_Index) |
| 583 | is |
| 584 | Used_For_Secondary : Boolean; |
| 585 | begin |
| 586 | Registers.Is_Set_Mask |
| 587 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 588 | Mask => GMCH_PFIT_CONTROL_SELECT_PIPE_B, |
| 589 | Result => Used_For_Secondary); |
| 590 | Pipe := (if Used_For_Secondary then Secondary else Primary); |
| 591 | end; |
| 592 | |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 593 | procedure Panel_Fitter_Off (Controller : Controller_Type) |
| 594 | is |
| 595 | use type HW.GFX.GMA.Registers.Registers_Invalid_Index; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 596 | Pipe_Using_PF : Pipe_Index; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 597 | begin |
| 598 | -- Writes to WIN_SZ arm the PS/PF registers. |
| 599 | if Config.Has_Plane_Control then |
| 600 | Registers.Unset_Mask (Controller.PS_CTRL_1, PS_CTRL_ENABLE_SCALER); |
| 601 | Registers.Write (Controller.PS_WIN_SZ_1, 16#0000_0000#); |
| 602 | if Controller.PS_CTRL_2 /= Registers.Invalid_Register and |
| 603 | Controller.PS_WIN_SZ_2 /= Registers.Invalid_Register |
| 604 | then |
| 605 | Registers.Unset_Mask (Controller.PS_CTRL_2, PS_CTRL_ENABLE_SCALER); |
| 606 | Registers.Write (Controller.PS_WIN_SZ_2, 16#0000_0000#); |
| 607 | end if; |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 608 | elsif Config.Has_GMCH_PFIT_CONTROL then |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 609 | Gmch_Panel_Fitter_Pipe (Pipe_Using_PF); |
| 610 | if Pipe_Using_PF = Controller.Pipe then |
| 611 | Registers.Unset_Mask (Registers.GMCH_PFIT_CONTROL, PF_CTRL_ENABLE); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 612 | end if; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 613 | else |
| 614 | Registers.Unset_Mask (Controller.PF_CTRL, PF_CTRL_ENABLE); |
| 615 | Registers.Write (Controller.PF_WIN_SZ, 16#0000_0000#); |
| 616 | end if; |
| 617 | end Panel_Fitter_Off; |
| 618 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 619 | procedure Setup_Scaling |
| 620 | (Controller : in Controller_Type; |
| 621 | Mode : in HW.GFX.Mode_Type; |
| 622 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| 623 | with |
| 624 | Pre => |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 625 | Rotated_Width (Framebuffer) <= Mode.H_Visible and |
| 626 | Rotated_Height (Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 627 | is |
| 628 | begin |
| Nico Huber | 3d06de8 | 2018-05-29 01:35:04 +0200 | [diff] [blame] | 629 | if Requires_Scaling (Framebuffer, Mode) then |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 630 | if Config.Has_Plane_Control then |
| 631 | Setup_Skylake_Pipe_Scaler (Controller, Mode, Framebuffer); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 632 | elsif Config.Has_GMCH_PFIT_CONTROL then |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 633 | Setup_Gmch_Panel_Fitter (Controller, Mode, Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 634 | else |
| 635 | Setup_Ironlake_Panel_Fitter (Controller, Mode, Framebuffer); |
| 636 | end if; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 637 | else |
| 638 | Panel_Fitter_Off (Controller); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 639 | end if; |
| 640 | end Setup_Scaling; |
| 641 | |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 642 | procedure Scaler_Available (Available : out Boolean; Pipe : Pipe_Index) |
| 643 | is |
| 644 | Pipe_Using_PF : Pipe_Index := Pipe_Index'First; |
| 645 | PF_Enabled : Boolean; |
| 646 | begin |
| 647 | if Config.Has_GMCH_PFIT_CONTROL then |
| 648 | Registers.Is_Set_Mask |
| 649 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 650 | Mask => PF_CTRL_ENABLE, |
| 651 | Result => PF_Enabled); |
| 652 | if PF_Enabled then |
| 653 | Gmch_Panel_Fitter_Pipe (Pipe_Using_PF); |
| 654 | end if; |
| 655 | |
| 656 | Available := not PF_Enabled or Pipe_Using_PF = Pipe; |
| 657 | else |
| 658 | Available := True; |
| 659 | end if; |
| 660 | end Scaler_Available; |
| 661 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 662 | ---------------------------------------------------------------------------- |
| 663 | |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 664 | procedure Setup_FB |
| 665 | (Pipe : Pipe_Index; |
| 666 | Mode : Mode_Type; |
| 667 | Framebuffer : Framebuffer_Type) |
| 668 | is |
| 669 | -- Enable dithering if framebuffer BPC differs from port BPC, |
| 670 | -- as smooth gradients look really bad without. |
| 671 | Dither : constant Boolean := Framebuffer.BPC /= Mode.BPC; |
| 672 | begin |
| 673 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 674 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 675 | -- Disable the cursor first. |
| 676 | Update_Cursor (Pipe, Framebuffer, Default_Cursor); |
| 677 | |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 678 | Setup_Display (Controllers (Pipe), Framebuffer, Mode.BPC, Dither); |
| 679 | Setup_Scaling (Controllers (Pipe), Mode, Framebuffer); |
| 680 | end Setup_FB; |
| 681 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 682 | procedure On |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 683 | (Pipe : Pipe_Index; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 684 | Port_Cfg : Port_Config; |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 685 | Framebuffer : Framebuffer_Type; |
| 686 | Cursor : Cursor_Type) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 687 | is |
| 688 | begin |
| 689 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 690 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 691 | Transcoder.Setup (Pipe, Port_Cfg); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 692 | |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 693 | Setup_FB (Pipe, Port_Cfg.Mode, Framebuffer); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 694 | Update_Cursor (Pipe, Framebuffer, Cursor); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 695 | |
| Nico Huber | abb16d9 | 2018-05-29 01:44:26 +0200 | [diff] [blame] | 696 | Transcoder.On |
| 697 | (Pipe => Pipe, |
| 698 | Port_Cfg => Port_Cfg, |
| 699 | Dither => Framebuffer.BPC /= Port_Cfg.Mode.BPC, |
| 700 | Scale => Requires_Scaling (Framebuffer, Port_Cfg.Mode)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 701 | end On; |
| 702 | |
| 703 | ---------------------------------------------------------------------------- |
| 704 | |
| 705 | procedure Planes_Off (Controller : Controller_Type) is |
| 706 | begin |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 707 | Registers.Write (Controller.CUR_CTL, 16#0000_0000#); |
| 708 | if Config.Has_Cursor_FBC_Control then |
| 709 | Registers.Write (Controller.CUR_FBC_CTL, 16#0000_0000#); |
| 710 | end if; |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 711 | Registers.Unset_Mask (Controller.SPCNTR, DSPCNTR_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 712 | if Config.Has_Plane_Control then |
| 713 | Clear_Watermarks (Controller); |
| 714 | Registers.Unset_Mask (Controller.PLANE_CTL, PLANE_CTL_PLANE_ENABLE); |
| 715 | Registers.Write (Controller.PLANE_SURF, 16#0000_0000#); |
| 716 | else |
| 717 | Registers.Unset_Mask (Controller.DSPCNTR, DSPCNTR_ENABLE); |
| 718 | end if; |
| 719 | end Planes_Off; |
| 720 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 721 | procedure Off (Pipe : Pipe_Index) |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 722 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 723 | begin |
| 724 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 725 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 726 | Planes_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 727 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 728 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 729 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 730 | end Off; |
| 731 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 732 | procedure Legacy_VGA_Off |
| 733 | is |
| 734 | use type HW.Word8; |
| 735 | Reg8 : Word8; |
| 736 | begin |
| 737 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 738 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 739 | Port_IO.OutB (VGA_SR_DATA, Reg8 or VGA_SR01_SCREEN_OFF); |
| 740 | Time.U_Delay (100); -- PRM says 100us, Linux does 300 |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 741 | Registers.Set_Mask (VGACNTRL_REG, VGA_CONTROL_VGA_DISPLAY_DISABLE); |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 742 | end Legacy_VGA_Off; |
| 743 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 744 | procedure All_Off |
| 745 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 746 | begin |
| 747 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 748 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 749 | Legacy_VGA_Off; |
| 750 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 751 | for Pipe in Pipe_Index loop |
| 752 | Planes_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 753 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 754 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 755 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 756 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 757 | end All_Off; |
| 758 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 759 | end HW.GFX.GMA.Pipe_Setup; |