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