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