| 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 | |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 52 | PLANE_COLOR_CTL_PLANE_GAMMA_DISABLE : constant := 1 * 2 ** 13; |
| 53 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 54 | PLANE_CTL_PLANE_ENABLE : constant := 1 * 2 ** 31; |
| 55 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 : constant := 4 * 2 ** 24; |
| 56 | PLANE_CTL_PLANE_GAMMA_DISABLE : constant := 1 * 2 ** 13; |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 57 | PLANE_CTL_TILED_SURFACE_MASK : constant := 7 * 2 ** 10; |
| 58 | PLANE_CTL_TILED_SURFACE_LINEAR : constant := 0 * 2 ** 10; |
| 59 | PLANE_CTL_TILED_SURFACE_X_TILED : constant := 1 * 2 ** 10; |
| 60 | PLANE_CTL_TILED_SURFACE_Y_TILED : constant := 4 * 2 ** 10; |
| 61 | PLANE_CTL_TILED_SURFACE_YF_TILED : constant := 5 * 2 ** 10; |
| 62 | |
| 63 | PLANE_CTL_TILED_SURFACE : constant array (Tiling_Type) of Word32 := |
| 64 | (Linear => PLANE_CTL_TILED_SURFACE_LINEAR, |
| 65 | X_Tiled => PLANE_CTL_TILED_SURFACE_X_TILED, |
| 66 | Y_Tiled => PLANE_CTL_TILED_SURFACE_Y_TILED); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 67 | |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 68 | PLANE_CTL_PLANE_ROTATION_MASK : constant := 3 * 2 ** 0; |
| 69 | PLANE_CTL_PLANE_ROTATION : constant array (Rotation_Type) of Word32 := |
| 70 | (No_Rotation => 0 * 2 ** 0, |
| 71 | Rotated_90 => 1 * 2 ** 0, |
| 72 | Rotated_180 => 2 * 2 ** 0, |
| 73 | Rotated_270 => 3 * 2 ** 0); |
| 74 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 75 | PLANE_WM_ENABLE : constant := 1 * 2 ** 31; |
| 76 | PLANE_WM_LINES_SHIFT : constant := 14; |
| 77 | PLANE_WM_LINES_MASK : constant := 16#001f# * 2 ** 14; |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 78 | PLANE_WM_BLOCKS_MASK : constant := |
| 79 | (if Config.Has_Wide_Watermarks then 16#7ff# else 16#3ff#); |
| 80 | |
| 81 | PIPEMISC_HDR_MODE_PRECISION : constant := 1 * 2 ** 23; |
| 82 | PIPEMISC_PIXEL_ROUNDING_TRUNC : constant := 1 * 2 ** 8; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 83 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 84 | VGA_SR_INDEX : constant := 16#03c4#; |
| 85 | VGA_SR_DATA : constant := 16#03c5#; |
| 86 | VGA_SR01 : constant := 16#01#; |
| 87 | VGA_SR01_SCREEN_OFF : constant := 1 * 2 ** 5; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 88 | |
| 89 | VGA_CONTROL_VGA_DISPLAY_DISABLE : constant := 1 * 2 ** 31; |
| 90 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK : constant := 16#0003# * 2 ** 6; |
| 91 | VGA_CONTROL_BLINK_DUTY_CYCLE_50 : constant := 2 * 2 ** 6; |
| 92 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK : constant := 16#003f# * 2 ** 0; |
| 93 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 94 | CUR_CTL_PIPE_SELECT : constant array (Pipe_Index) of Word32 := |
| 95 | (Primary => 0 * 2 ** 28, |
| 96 | Secondary => 1 * 2 ** 28, |
| 97 | Tertiary => 2 * 2 ** 28); |
| 98 | CUR_CTL_MODE : constant array (Cursor_Mode, Cursor_Size) of Word32 := |
| 99 | (No_Cursor => (others => 16#00#), |
| 100 | ARGB_Cursor => |
| 101 | (Cursor_64x64 => 16#27#, |
| 102 | Cursor_128x128 => 16#22#, |
| 103 | Cursor_256x256 => 16#23#)); |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 104 | subtype ARB_Slots is Natural range 0 .. 7; |
| 105 | function MCURSOR_ARB_SLOTS (N : ARB_Slots) return Word32 is |
| 106 | (Shift_Left (Word32 (N), 28)); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 107 | |
| 108 | function CUR_POS_Y (Y : Int32) return Word32 is |
| 109 | ((if Y >= 0 then 0 else 1 * 2 ** 31) or Shift_Left (Word32 (abs Y), 16)) |
| 110 | with |
| 111 | Pre => Y > Int32'First; |
| 112 | function CUR_POS_X (X : Int32) return Word32 is |
| 113 | ((if X >= 0 then 0 else 1 * 2 ** 15) or Word32 (abs X)) |
| 114 | with |
| 115 | Pre => X > Int32'First; |
| 116 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 117 | subtype VGA_Cycle_Count is Pos32 range 2 .. 128; |
| 118 | function VGA_CONTROL_VSYNC_BLINK_RATE |
| 119 | (Cycles : VGA_Cycle_Count) |
| 120 | return Word32 |
| 121 | is |
| 122 | begin |
| 123 | return Word32 (Cycles) / 2 - 1; |
| 124 | end VGA_CONTROL_VSYNC_BLINK_RATE; |
| 125 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 126 | PF_CTRL_ENABLE : constant := 1 * 2 ** 31; |
| 127 | PF_CTRL_PIPE_SELECT_MASK : constant := 3 * 2 ** 29; |
| 128 | PF_CTRL_FILTER_MED : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 129 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 130 | PS_CTRL_ENABLE_SCALER : constant := 1 * 2 ** 31; |
| 131 | PS_CTRL_SCALER_MODE_7X5_EXTENDED : constant := 1 * 2 ** 28; |
| 132 | PS_CTRL_FILTER_SELECT_MEDIUM_2 : constant := 1 * 2 ** 23; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 133 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 134 | GMCH_PFIT_CONTROL_SELECT_MASK : constant := 3 * 2 ** 29; |
| 135 | GMCH_PFIT_CONTROL_SELECT_PIPE_A : constant := 0 * 2 ** 29; |
| 136 | GMCH_PFIT_CONTROL_SELECT_PIPE_B : constant := 1 * 2 ** 29; |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 137 | GMCH_PFIT_CONTROL_SCALING_MASK : constant := 3 * 2 ** 26; |
| 138 | GMCH_PFIT_CONTROL_SCALING : constant array (Scaling_Aspect) of Word32 := |
| 139 | (Uniform => 0 * 2 ** 26, |
| 140 | Pillarbox => 2 * 2 ** 26, |
| 141 | Letterbox => 3 * 2 ** 26); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 142 | |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 143 | VGACNTRL_REG : constant Registers.Registers_Index := |
| 144 | (if Config.Has_GMCH_VGACNTRL then |
| 145 | Registers.GMCH_VGACNTRL |
| 146 | else Registers.CPU_VGACNTRL); |
| 147 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 148 | --------------------------------------------------------------------------- |
| 149 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 150 | function PLANE_WM_LINES (Lines : Natural) return Word32 is |
| 151 | begin |
| 152 | return Shift_Left (Word32 (Lines), PLANE_WM_LINES_SHIFT) |
| 153 | and PLANE_WM_LINES_MASK; |
| 154 | end PLANE_WM_LINES; |
| 155 | |
| 156 | function PLANE_WM_BLOCKS (Blocks : Natural) return Word32 is |
| 157 | begin |
| 158 | return Word32 (Blocks) and PLANE_WM_BLOCKS_MASK; |
| 159 | end PLANE_WM_BLOCKS; |
| 160 | |
| 161 | --------------------------------------------------------------------------- |
| 162 | |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 163 | subtype Source_Size is Width_Type; |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 164 | |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 165 | function Encode_Size (LSW, MSW : Source_Size) return Word32 |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 166 | is |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 167 | (Shift_Left (Word32 (MSW) - 1, 16) or (Word32 (LSW) - 1)); |
| 168 | |
| 169 | function Source_Width (FB : Framebuffer_Type) return Source_Size |
| 170 | is |
| 171 | (if Config.Needs_Even_Source_Width and then Rotated_Width (FB) > 2 then |
| 172 | Rotated_Width (FB) - Rotated_Width (FB) mod 2 |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 173 | else |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 174 | Rotated_Width (FB)); |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 175 | |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 176 | function Source_Height (FB : Framebuffer_Type) return Source_Size |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 177 | is |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 178 | (Rotated_Height (FB)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 179 | |
| 180 | ---------------------------------------------------------------------------- |
| 181 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 182 | procedure Clear_Watermarks (Controller : Controller_Type) is |
| 183 | begin |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 184 | Registers.Write (Controller.CUR_BUF_CFG, 16#0000_0000#); |
| 185 | for Level in WM_Levels loop |
| 186 | Registers.Write (Controller.CUR_WM (Level), 16#0000_0000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 187 | end loop; |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 188 | Registers.Write (Controller.PLANE_2_BUF_CFG, 16#0000_0000#); |
| 189 | for Level in WM_Levels loop |
| 190 | Registers.Write (Controller.PLANE_2_WM (Level), 16#0000_0000#); |
| 191 | end loop; |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 192 | Registers.Write (Controller.PLANE_BUF_CFG, 16#0000_0000#); |
| 193 | for Level in WM_Levels loop |
| 194 | Registers.Write (Controller.PLANE_WM (Level), 16#0000_0000#); |
| 195 | end loop; |
| 196 | Registers.Write (Controller.WM_LINETIME, 16#0000_0000#); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 197 | end Clear_Watermarks; |
| 198 | |
| 199 | procedure Setup_Watermarks (Controller : Controller_Type) |
| 200 | is |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 201 | subtype Buffer_Count is Natural range 1 .. 508; |
| 202 | subtype Buffer_Index is Natural range 0 .. Buffer_Count'Last - 1; |
| 203 | |
| 204 | function Encode_Buffers (Start : Buffer_Index; Count : Buffer_Count) |
| 205 | return Word32 |
| 206 | is |
| 207 | (Shift_Left (Word32 (Start + Count - 1), 16) or Word32 (Start)); |
| 208 | |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 209 | type Per_Plane_Buffer_Range is array (Pipe_Index) of Word32; |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 210 | Plane_1_Buffer_Range : constant Per_Plane_Buffer_Range := |
| 211 | (Primary => Encode_Buffers ( 0, 150), |
| 212 | Secondary => Encode_Buffers (169, 150), |
| 213 | Tertiary => Encode_Buffers (338, 150)); |
| 214 | Plane_2_Buffer_Range : constant Per_Plane_Buffer_Range := |
| 215 | (Primary => Encode_Buffers (150, 11), |
| 216 | Secondary => Encode_Buffers (319, 11), |
| 217 | Tertiary => Encode_Buffers (488, 11)); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 218 | Cur_Buffer_Range : constant Per_Plane_Buffer_Range := |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 219 | (Primary => Encode_Buffers (161, 8), |
| 220 | Secondary => Encode_Buffers (330, 8), |
| 221 | Tertiary => Encode_Buffers (499, 8)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 222 | begin |
| 223 | Registers.Write |
| 224 | (Register => Controller.PLANE_BUF_CFG, |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 225 | Value => Plane_1_Buffer_Range (Controller.Pipe)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 226 | Registers.Write |
| 227 | (Register => Controller.PLANE_WM (0), |
| 228 | Value => PLANE_WM_ENABLE or |
| 229 | PLANE_WM_LINES (2) or |
| Nico Huber | 9e78dda | 2020-10-01 15:30:54 +0200 | [diff] [blame] | 230 | PLANE_WM_BLOCKS (150)); |
| 231 | Registers.Write |
| 232 | (Register => Controller.PLANE_2_BUF_CFG, |
| 233 | Value => Plane_2_Buffer_Range (Controller.Pipe)); |
| 234 | Registers.Write |
| 235 | (Register => Controller.PLANE_2_WM (0), |
| 236 | Value => PLANE_WM_ENABLE or |
| 237 | PLANE_WM_LINES (2) or |
| 238 | PLANE_WM_BLOCKS (11)); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 239 | Registers.Write |
| 240 | (Register => Controller.CUR_BUF_CFG, |
| 241 | Value => Cur_Buffer_Range (Controller.Pipe)); |
| 242 | Registers.Write |
| 243 | (Register => Controller.CUR_WM (0), |
| 244 | Value => PLANE_WM_ENABLE or |
| 245 | PLANE_WM_LINES (2) or |
| 246 | PLANE_WM_BLOCKS (8)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 247 | end Setup_Watermarks; |
| 248 | |
| 249 | ---------------------------------------------------------------------------- |
| 250 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 251 | procedure Setup_Hires_Plane |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 252 | (Controller : Controller_Type; |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 253 | FB : HW.GFX.Framebuffer_Type) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 254 | with |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 255 | Pre => FB.Height + FB.Start_Y <= FB.V_Stride |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 256 | is |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 257 | Width : constant Source_Size := Source_Width (FB); |
| 258 | Height : constant Source_Size := Source_Height (FB); |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 259 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 260 | -- FIXME: setup correct format, based on framebuffer RGB format |
| 261 | Format : constant Word32 := 6 * 2 ** 26; |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 262 | PRI : Word32 := Format; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 263 | begin |
| 264 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 265 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 266 | if Config.Has_Plane_Control then |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 267 | declare |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 268 | Stride, Offset : Word32; |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 269 | |
| 270 | function PLANE_CTL_ARB_SLOTS (N : Word32) return Word32 is |
| 271 | (if Config.Need_Pipe_Arb_Slots then Shift_Left (N, 28) else 0); |
| 272 | |
| 273 | -- TODO: Hard coded format and arbitration slots for now, |
| 274 | -- for 4B-per-pixel XRGB, just like `Format` above. |
| 275 | -- ARB_SLOTS(1) matches the 4B per pixel. |
| 276 | Plane_Ctl : constant Word32 := |
| 277 | PLANE_CTL_PLANE_ENABLE or |
| 278 | PLANE_CTL_TILED_SURFACE (FB.Tiling) or |
| 279 | PLANE_CTL_PLANE_ROTATION (FB.Rotation) or |
| 280 | PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 or |
| 281 | PLANE_CTL_ARB_SLOTS (1) or |
| 282 | (if not Config.Has_Plane_Color_Control |
| 283 | then PLANE_CTL_PLANE_GAMMA_DISABLE |
| 284 | else 0); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 285 | begin |
| 286 | if Rotation_90 (FB) then |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 287 | Stride := Word32 (FB_Pitch (FB.V_Stride, FB)); |
| 288 | Offset := Shift_Left (Word32 (FB.Start_X), 16) or |
| 289 | Word32 (FB.V_Stride - FB.Height - FB.Start_Y); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 290 | else |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 291 | Stride := Word32 (FB_Pitch (FB.Stride, FB)); |
| 292 | Offset := Shift_Left (Word32 (FB.Start_Y), 16) or |
| 293 | Word32 (FB.Start_X); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 294 | end if; |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 295 | |
| 296 | if Config.Has_Plane_Color_Control then |
| 297 | Registers.Write |
| 298 | (Register => Controller.PLANE_COLOR_CTL, |
| 299 | Value => PLANE_COLOR_CTL_PLANE_GAMMA_DISABLE); |
| 300 | end if; |
| 301 | Registers.Write (Controller.PLANE_AUX_DIST, 0); |
| 302 | Registers.Write (Controller.PLANE_CTL, Plane_Ctl); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 303 | Registers.Write (Controller.PLANE_OFFSET, Offset); |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 304 | Registers.Write (Controller.PLANE_SIZE, Encode_Size (Width, Height)); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 305 | Registers.Write (Controller.PLANE_STRIDE, Stride); |
| 306 | Registers.Write (Controller.PLANE_POS, 16#0000_0000#); |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 307 | Registers.Write (Controller.PLANE_SURF, FB.Offset and 16#ffff_f000#); |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 308 | end; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 309 | else |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 310 | if Config.Has_DSPCNTR_Pipe_Select then |
| 311 | PRI := PRI or DSPCNTR_PIPE_SEL (Controller.Pipe); |
| 312 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 313 | if Config.Disable_Trickle_Feed then |
| 314 | PRI := PRI or DSPCNTR_DISABLE_TRICKLE_FEED; |
| 315 | end if; |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 316 | |
| 317 | -- Write DSPCNTR *without* the enable bit first. On pre-SKL |
| 318 | -- hardware the control register self-arms when the plane |
| 319 | -- transitions from disabled to enabled, latching whatever |
| 320 | -- stride/size/offset values happen to be in the registers at |
| 321 | -- that moment. Programming format, pipe-select, and trickle- |
| 322 | -- feed now avoids a glitch with stale geometry values. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 323 | Registers.Unset_And_Set_Mask |
| 324 | (Register => Controller.DSPCNTR, |
| 325 | Mask_Unset => DSPCNTR_MASK, |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 326 | Mask_Set => PRI or DSPCNTR_TILED_SURFACE (FB.Tiling)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 327 | |
| Nico Huber | 0164b02 | 2017-08-24 15:12:51 +0200 | [diff] [blame] | 328 | Registers.Write |
| 329 | (Controller.DSPSTRIDE, Word32 (Pixel_To_Bytes (FB.Stride, FB))); |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 330 | |
| 331 | -- Gen3 (i945): program DSPSIZE and DSPPOS before the surface |
| 332 | -- address write that arms the double-buffered plane registers. |
| 333 | if Config.Gen_I945 then |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 334 | Registers.Write (Controller.DSPSIZE, Encode_Size (Width, Height)); |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 335 | Registers.Write (Controller.DSPPOS, 16#0000_0000#); |
| 336 | end if; |
| 337 | |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 338 | if Config.Has_DSP_Linoff and then FB.Tiling = Linear then |
| Arthur Heymans | 3f37cce | 2026-03-03 18:52:12 +0100 | [diff] [blame] | 339 | pragma Assert_And_Cut |
| 340 | (FB.Start_Y * FB.Stride + FB.Start_X in Pixel_Type); |
| Nico Huber | d49b56b | 2018-06-18 17:19:15 +0200 | [diff] [blame] | 341 | declare |
| 342 | Linear_Offset : constant Pixel_Type := |
| 343 | FB.Start_Y * FB.Stride + FB.Start_X; |
| 344 | begin |
| 345 | Registers.Write |
| 346 | (Register => Controller.DSPLINOFF, |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 347 | Value => (if Config.Has_DSPSURF |
| 348 | then Word32 (Pixel_To_Bytes (Linear_Offset, FB)) |
| 349 | else (FB.Offset and 16#ffff_f000#) or |
| 350 | Word32 (Pixel_To_Bytes (Linear_Offset, FB)))); |
| Nico Huber | d49b56b | 2018-06-18 17:19:15 +0200 | [diff] [blame] | 351 | Registers.Write (Controller.DSPTILEOFF, 0); |
| 352 | end; |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 353 | else |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 354 | if Config.Has_DSP_Linoff then |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 355 | Registers.Write (Controller.DSPLINOFF, |
| 356 | (if Config.Has_DSPSURF then 0 |
| 357 | else FB.Offset and 16#ffff_f000#)); |
| Nico Huber | ab69e36 | 2018-05-29 21:20:30 +0200 | [diff] [blame] | 358 | end if; |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 359 | Registers.Write |
| 360 | (Register => Controller.DSPTILEOFF, |
| 361 | Value => Shift_Left (Word32 (FB.Start_Y), 16) or |
| 362 | Word32 (FB.Start_X)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 363 | end if; |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 364 | if Config.Has_DSPSURF then |
| 365 | Registers.Write (Controller.DSPSURF, FB.Offset and 16#ffff_f000#); |
| 366 | end if; |
| 367 | |
| 368 | -- Now enable the plane. All geometry registers are in place, |
| 369 | -- so the self-arm latches correct values. |
| 370 | Registers.Write |
| 371 | (Register => Controller.DSPCNTR, |
| 372 | Value => DSPCNTR_ENABLE or PRI or |
| 373 | DSPCNTR_TILED_SURFACE (FB.Tiling)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 374 | end if; |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 375 | end Setup_Hires_Plane; |
| 376 | |
| 377 | procedure Setup_Display |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 378 | (Controller : Controller_Type; |
| 379 | Framebuffer : Framebuffer_Type; |
| 380 | Dither_BPC : BPC_Type; |
| 381 | Dither : Boolean) |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 382 | with |
| Nico Huber | 9b47941 | 2017-08-27 11:55:56 +0200 | [diff] [blame] | 383 | Pre => |
| 384 | Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET or |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 385 | Framebuffer.Height + Framebuffer.Start_Y <= Framebuffer.V_Stride |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 386 | is |
| 387 | use type Word8; |
| 388 | |
| 389 | Reg8 : Word8; |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 390 | |
| 391 | type BW_Credit is new Natural range 0 .. 3; |
| 392 | function MBUS_DBOX_BW_CREDIT (C : BW_Credit) return Word32 is |
| 393 | (Shift_Left (Word32 (C), 14)); |
| 394 | |
| 395 | type B_Credit is new Natural range 0 .. 31; |
| 396 | function MBUS_DBOX_B_CREDIT (C : B_Credit) return Word32 is |
| 397 | (Shift_Left (Word32 (C), 8)); |
| 398 | |
| 399 | type A_Credit is new Natural range 0 .. 15; |
| 400 | function MBUS_DBOX_A_CREDIT (C : A_Credit) return Word32 is |
| 401 | (Word32 (C)); |
| 402 | |
| 403 | type B2B_Trans_Max is new Natural range 0 .. 31; |
| 404 | function MBUS_DBOX_B2B_TRANSACTIONS_MAX (B : B2B_Trans_Max) return Word32 is |
| 405 | (Shift_Left (Word32 (B), 20)); |
| 406 | |
| 407 | type B2B_Trans_Delay is new Natural range 0 .. 7; |
| 408 | function MBUS_DBOX_B2B_TRANSACTIONS_DELAY (B : B2B_Trans_Delay) return Word32 is |
| 409 | (Shift_Left (Word32 (B), 17)); |
| 410 | MBUS_DBOX_REGULATE_B2B_TRANSACTIONS_EN : constant := 1 * 2 ** 16; |
| 411 | |
| 412 | procedure Program_Mbus_Dbox_Credits is |
| 413 | Tmp : Word32; |
| 414 | begin |
| 415 | Tmp := MBUS_DBOX_B2B_TRANSACTIONS_MAX (16) or |
| 416 | MBUS_DBOX_B2B_TRANSACTIONS_DELAY (1) or |
| 417 | MBUS_DBOX_REGULATE_B2B_TRANSACTIONS_EN; |
| 418 | |
| 419 | if Config.Has_New_Mbus_Dbox_Credits then |
| 420 | Tmp := Tmp or MBUS_DBOX_BW_CREDIT (2) or |
| 421 | MBUS_DBOX_B_CREDIT (8) or |
| 422 | MBUS_DBOX_A_CREDIT (4); -- No joined MBus support, |
| 423 | -- hence always use 4 for now. |
| 424 | else |
| 425 | Tmp := Tmp or MBUS_DBOX_BW_CREDIT (2) or |
| 426 | MBUS_DBOX_B_CREDIT (12) or |
| 427 | MBUS_DBOX_A_CREDIT (2); |
| 428 | end if; |
| 429 | |
| 430 | Registers.Write |
| 431 | (Register => Controller.MBUS_DBOX_CTL, |
| 432 | Value => Tmp); |
| 433 | end Program_Mbus_Dbox_Credits; |
| 434 | |
| 435 | -- Display WA # 1605353570: icl |
| 436 | -- Set the pixel rounding bit to 1 for allowing |
| 437 | -- passthrough of Frame buffer pixels unmodified |
| 438 | -- across pipe |
| 439 | PIXEL_ROUNDING_TRUNC_FB_PASSTHRU : constant := 1 * 2 ** 15; |
| 440 | |
| 441 | -- Display WA #1153: icl |
| 442 | -- enable hardware to bypass the alpha math |
| 443 | -- and rounding for per-pixel values 00 and 0xff |
| 444 | PER_PIXEL_ALPHA_BYPASS_EN : constant := 1 * 2 ** 7; |
| 445 | |
| 446 | -- ADL_P requires that we disable underrun recovery when |
| 447 | -- downscaling (or using the scaler for YUV420 pipe output), |
| 448 | -- using DSC, or using PSR2. |
| 449 | -- i915 always disables underrun recovery for gen 13+. |
| 450 | UNDERRUN_RECOVERY_DISABLE : constant := 1 * 2 ** 30; |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 451 | |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 452 | Width : constant Source_Size := Source_Width (Framebuffer); |
| 453 | Height : constant Source_Size := Source_Height (Framebuffer); |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 454 | begin |
| 455 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 456 | |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 457 | if Config.Has_Type_C_Ports then |
| 458 | Registers.Set_Mask |
| 459 | (Register => Controller.PIPE_CHICKEN, |
| 460 | Mask => PER_PIXEL_ALPHA_BYPASS_EN or |
| 461 | PIXEL_ROUNDING_TRUNC_FB_PASSTHRU or |
| 462 | (if Config.Need_Underrun_Rec_Disable |
| 463 | then UNDERRUN_RECOVERY_DISABLE |
| 464 | else 0)); |
| 465 | end if; |
| 466 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 467 | if Config.Has_Plane_Control then |
| 468 | Setup_Watermarks (Controller); |
| 469 | end if; |
| 470 | |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 471 | if Config.Has_Mbus_Dbox_Credits then |
| 472 | Program_Mbus_Dbox_Credits; |
| 473 | end if; |
| 474 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 475 | if Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| Nico Huber | fbb4220 | 2016-11-07 15:08:26 +0100 | [diff] [blame] | 476 | if Config.VGA_Plane_Workaround then |
| 477 | Registers.Unset_And_Set_Mask |
| 478 | (Register => Registers.ILK_DISPLAY_CHICKEN1, |
| 479 | Mask_Unset => ILK_DISPLAY_CHICKEN1_VGA_MASK, |
| 480 | Mask_Set => ILK_DISPLAY_CHICKEN1_VGA_ENABLE); |
| 481 | Registers.Unset_And_Set_Mask |
| 482 | (Register => Registers.ILK_DISPLAY_CHICKEN2, |
| 483 | Mask_Unset => ILK_DISPLAY_CHICKEN2_VGA_MASK, |
| 484 | Mask_Set => ILK_DISPLAY_CHICKEN2_VGA_ENABLE); |
| 485 | end if; |
| 486 | |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 487 | Registers.Unset_And_Set_Mask |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 488 | (Register => VGACNTRL_REG, |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 489 | Mask_Unset => VGA_CONTROL_VGA_DISPLAY_DISABLE or |
| 490 | VGA_CONTROL_BLINK_DUTY_CYCLE_MASK or |
| 491 | VGA_CONTROL_VSYNC_BLINK_RATE_MASK, |
| 492 | Mask_Set => VGA_CONTROL_BLINK_DUTY_CYCLE_50 or |
| 493 | VGA_CONTROL_VSYNC_BLINK_RATE (30)); |
| 494 | |
| 495 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 496 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 497 | Port_IO.OutB (VGA_SR_DATA, Reg8 and not (VGA_SR01_SCREEN_OFF)); |
| 498 | else |
| Nico Huber | 6a4dfc8 | 2016-11-04 15:50:58 +0100 | [diff] [blame] | 499 | Setup_Hires_Plane (Controller, Framebuffer); |
| Nico Huber | 3675db5 | 2016-11-04 16:27:29 +0100 | [diff] [blame] | 500 | end if; |
| 501 | |
| 502 | Registers.Write |
| 503 | (Register => Controller.PIPESRC, |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 504 | Value => Encode_Size (Height, Width)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 505 | |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 506 | if Config.Has_Pipeconf_Misc then |
| 507 | Registers.Write |
| 508 | (Register => Controller.PIPEMISC, |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 509 | Value => Transcoder.BPC_Conf (Dither_BPC, Dither) or |
| 510 | -- FIXME: Should we set these at all? |
| 511 | (if Config.Has_Plane_Color_Control then |
| 512 | (PIPEMISC_PIXEL_ROUNDING_TRUNC or PIPEMISC_HDR_MODE_PRECISION) else 0)); |
| Nico Huber | 113a14b | 2016-12-06 21:59:15 +0100 | [diff] [blame] | 513 | end if; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 514 | end Setup_Display; |
| 515 | |
| 516 | ---------------------------------------------------------------------------- |
| 517 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 518 | procedure Update_Cursor |
| 519 | (Pipe : Pipe_Index; |
| 520 | FB : Framebuffer_Type; |
| 521 | Cursor : Cursor_Type) |
| 522 | is |
| 523 | begin |
| 524 | -- on some platforms writing CUR_CTL disables self-arming of CUR_POS |
| 525 | -- so keep it first |
| 526 | Registers.Write |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 527 | (Register => Cursors (Pipe).CTL, |
| Tim Wawrzynczak | 0da761a | 2022-09-09 10:42:36 -0600 | [diff] [blame] | 528 | Value => CUR_CTL_MODE (Cursor.Mode, Cursor.Size) or |
| 529 | (if Config.Need_Pipe_Arb_Slots |
| 530 | then MCURSOR_ARB_SLOTS (1) |
| 531 | else CUR_CTL_PIPE_SELECT (Pipe))); |
| Nico Huber | 1dae220 | 2020-10-05 13:31:25 +0200 | [diff] [blame^] | 532 | Place_Cursor (Pipe, FB, Cursor, (Cursor.Center_X, Cursor.Center_Y)); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 533 | end Update_Cursor; |
| 534 | |
| 535 | procedure Place_Cursor |
| 536 | (Pipe : Pipe_Index; |
| 537 | FB : Framebuffer_Type; |
| Nico Huber | 1dae220 | 2020-10-05 13:31:25 +0200 | [diff] [blame^] | 538 | Cursor : Cursor_Type; |
| 539 | Center : Cursor_Coord) |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 540 | is |
| 541 | Width : constant Width_Type := Cursor_Width (Cursor.Size); |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 542 | |
| 543 | -- The cursor's coordinates are on the framebuffer surface |
| 544 | -- but we need to place it on the physical screen: |
| 545 | Center_X : constant Int32 := |
| 546 | (case FB.Rotation is |
| Nico Huber | 1dae220 | 2020-10-05 13:31:25 +0200 | [diff] [blame^] | 547 | when No_Rotation => Center.X, |
| 548 | when Rotated_90 => FB.Height - 1 - Center.Y, |
| 549 | when Rotated_180 => FB.Width - 1 - Center.X, |
| 550 | when Rotated_270 => Center.Y); |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 551 | Center_Y : constant Int32 := |
| 552 | (case FB.Rotation is |
| Nico Huber | 1dae220 | 2020-10-05 13:31:25 +0200 | [diff] [blame^] | 553 | when No_Rotation => Center.Y, |
| 554 | when Rotated_90 => Center.X, |
| 555 | when Rotated_180 => FB.Height - 1 - Center.Y, |
| 556 | when Rotated_270 => FB.Width - 1 - Center.X); |
| Nico Huber | 3d7c33f | 2020-10-01 15:14:38 +0200 | [diff] [blame] | 557 | |
| 558 | X : Int32 := Center_X - Width / 2; |
| 559 | Y : Int32 := Center_Y - Width / 2; |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 560 | begin |
| 561 | -- off-screen cursor needs special care |
| 562 | if X <= -Width or Y <= -Width or |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 563 | X >= Source_Width (FB) or Y >= Source_Height (FB) or |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 564 | X > Config.Maximum_Cursor_X or Y > Config.Maximum_Cursor_Y |
| 565 | then |
| 566 | X := -Width; |
| 567 | Y := -Width; |
| 568 | end if; |
| 569 | Registers.Write |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 570 | (Register => Cursors (Pipe).POS, |
| Nico Huber | aae8a35 | 2020-06-15 13:09:29 +0200 | [diff] [blame] | 571 | Value => CUR_POS_Y (Y) or CUR_POS_X (X), |
| 572 | Verbose => False); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 573 | -- write to CUR_BASE always arms other CUR_* registers |
| 574 | Registers.Write |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 575 | (Register => Cursors (Pipe).BASE, |
| Nico Huber | aae8a35 | 2020-06-15 13:09:29 +0200 | [diff] [blame] | 576 | Value => Shift_Left (Word32 (Cursor.GTT_Offset), 12), |
| 577 | Verbose => False); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 578 | end Place_Cursor; |
| 579 | |
| 580 | ---------------------------------------------------------------------------- |
| 581 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 582 | procedure Scale_Keep_Aspect |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 583 | (Width : out Width_Type; |
| 584 | Height : out Height_Type; |
| 585 | Max_Width : in Width_Type; |
| 586 | Max_Height : in Height_Type; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 587 | Framebuffer : in Framebuffer_Type) |
| 588 | with |
| 589 | Pre => |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 590 | Source_Width (Framebuffer) <= Max_Width and |
| 591 | Source_Height (Framebuffer) <= Max_Height, |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 592 | Post => |
| 593 | Width <= Max_Width and Height <= Max_Height |
| 594 | is |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 595 | Src_Width : constant Width_Type := Source_Width (Framebuffer); |
| 596 | Src_Height : constant Height_Type := Source_Height (Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 597 | begin |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 598 | case Scaling_Type (Src_Width, Src_Height, Max_Width, Max_Height) is |
| 599 | when Letterbox => |
| Nico Huber | 99200fe | 2026-04-14 16:37:45 +0200 | [diff] [blame] | 600 | Height := (Src_Height * Max_Width) / Src_Width; |
| 601 | pragma Assert (Height <= Max_Height); |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 602 | Width := Max_Width; |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 603 | when Pillarbox => |
| Nico Huber | 99200fe | 2026-04-14 16:37:45 +0200 | [diff] [blame] | 604 | Width := (Src_Width * Max_Height) / Src_Height; |
| 605 | pragma Assert (Max_Height * Src_Width < Max_Width * Src_Height); |
| 606 | pragma Assert ((Max_Height * Src_Width) / Src_Height < Max_Width); |
| 607 | pragma Assert (Width <= Max_Width); |
| Nico Huber | da1185e | 2018-06-03 01:07:46 +0200 | [diff] [blame] | 608 | Height := Max_Height; |
| 609 | when Uniform => |
| 610 | Width := Max_Width; |
| 611 | Height := Max_Height; |
| 612 | end case; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 613 | end Scale_Keep_Aspect; |
| 614 | |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 615 | procedure Scale |
| 616 | (Width : out Width_Type; |
| 617 | Height : out Height_Type; |
| 618 | Scaling : in GMA.Scaling; |
| 619 | Max_Width : in Width_Type; |
| 620 | Max_Height : in Height_Type; |
| 621 | Framebuffer : in Framebuffer_Type) |
| 622 | with |
| 623 | Pre => |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 624 | Source_Width (Framebuffer) <= Max_Width and |
| 625 | Source_Height (Framebuffer) <= Max_Height, |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 626 | Post => |
| 627 | Width <= Max_Width and Height <= Max_Height |
| 628 | is |
| 629 | begin |
| 630 | case Scaling is |
| 631 | when None => |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 632 | Width := Source_Width (Framebuffer); |
| 633 | Height := Source_Height (Framebuffer); |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 634 | when Fit => |
| 635 | Scale_Keep_Aspect (Width, Height, Max_Width, Max_Height, Framebuffer); |
| 636 | when Stretch => |
| 637 | Width := Max_Width; |
| 638 | Height := Max_Height; |
| 639 | end case; |
| 640 | end Scale; |
| 641 | |
| 642 | procedure Align_Framebuffer |
| 643 | (Pos_X : out Position_Type; |
| 644 | Pos_Y : out Position_Type; |
| 645 | Align : in Alignment; |
| 646 | Width : in Width_Type; |
| 647 | Height : in Height_Type; |
| 648 | Mode : in Mode_Type) |
| 649 | with |
| 650 | Pre => Width <= Mode.H_Visible and Height <= Mode.V_Visible |
| 651 | is |
| 652 | Gap_X : constant Position_Type := Mode.H_Visible - Width; |
| 653 | Gap_Y : constant Position_Type := Mode.V_Visible - Height; |
| 654 | begin |
| 655 | case Align is |
| 656 | when Top_Left => Pos_X := 0; Pos_Y := 0; |
| 657 | when Top => Pos_X := Gap_X / 2; Pos_Y := 0; |
| 658 | when Top_Right => Pos_X := Gap_X; Pos_Y := 0; |
| 659 | when Left => Pos_X := 0; Pos_Y := Gap_Y / 2; |
| 660 | when Center => Pos_X := Gap_X / 2; Pos_Y := Gap_Y / 2; |
| 661 | when Right => Pos_X := Gap_X; Pos_Y := Gap_Y / 2; |
| 662 | when Bottom_Left => Pos_X := 0; Pos_Y := Gap_Y; |
| 663 | when Bottom => Pos_X := Gap_X / 2; Pos_Y := Gap_Y; |
| 664 | when Bottom_Right => Pos_X := Gap_X; Pos_Y := Gap_Y; |
| 665 | end case; |
| 666 | end Align_Framebuffer; |
| 667 | |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 668 | type Pipe_Scaler_Limit_Config is record |
| 669 | Control : Word32; |
| 670 | Horizontal : Pos32; |
| 671 | Vertical : Pos32; |
| 672 | end record; |
| 673 | |
| 674 | function Skylake_Scaler_Limits |
| 675 | (Controller : Controller_Type; |
| 676 | Width : Width_Type; |
| 677 | Height : Height_Type) |
| 678 | return Pipe_Scaler_Limit_Config |
| 679 | with |
| 680 | Post => Skylake_Scaler_Limits'Result.Horizontal >= Width |
| 681 | and Skylake_Scaler_Limits'Result.Vertical >= Height |
| 682 | is |
| 683 | use type Registers.Registers_Invalid_Index; |
| 684 | |
| 685 | -- Enable 7x5 extended mode where possible: |
| 686 | Scaler_Mode : constant Word32 := |
| 687 | (if Controller.PS_CTRL_2 /= Registers.Invalid_Register then |
| 688 | PS_CTRL_SCALER_MODE_7X5_EXTENDED else 0); |
| 689 | |
| 690 | -- We can scale up to 2.99x horizontally: |
| 691 | Horizontal_Limit : constant Pos32 := (Width * 299) / 100; |
| 692 | -- The third scaler is limited to 1.99x |
| 693 | -- vertical scaling for source widths > 2048: |
| 694 | Vertical_Limit : constant Pos32 := |
| 695 | (Height * |
| 696 | (if Controller.PS_CTRL_2 = Registers.Invalid_Register and |
| 697 | Width > 2048 |
| 698 | then |
| 699 | 199 |
| 700 | else |
| 701 | 299)) / 100; |
| 702 | begin |
| 703 | return (Scaler_Mode, Horizontal_Limit, Vertical_Limit); |
| 704 | end Skylake_Scaler_Limits; |
| 705 | |
| 706 | function Tigerlake_Scaler_Limits |
| 707 | (Width : Width_Type; |
| 708 | Height : Height_Type) |
| 709 | return Pipe_Scaler_Limit_Config |
| 710 | with |
| 711 | Post => Tigerlake_Scaler_Limits'Result.Horizontal >= Width |
| 712 | and Tigerlake_Scaler_Limits'Result.Vertical >= Height |
| 713 | is |
| 714 | Scaling : constant := 32_000; -- PRM says: Scaling * 2**15 >= 1.0 |
| 715 | -- so virtually unlimited |
| 716 | begin |
| 717 | return (Control => 0, Horizontal => Width * Scaling, Vertical => Height * Scaling); |
| 718 | end Tigerlake_Scaler_Limits; |
| 719 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 720 | procedure Setup_Skylake_Pipe_Scaler |
| 721 | (Controller : in Controller_Type; |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 722 | Pipe_Cfg : in Pipe_Config; |
| 723 | Mode : in HW.GFX.Mode_Type) |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 724 | with |
| 725 | Pre => |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 726 | Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and |
| 727 | Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 728 | is |
| Nico Huber | a7e1cd3 | 2026-07-03 09:23:24 +0000 | [diff] [blame] | 729 | Width_In : constant Width_Type := Source_Width (Pipe_Cfg.Framebuffer); |
| 730 | Height_In : constant Height_Type := Source_Height (Pipe_Cfg.Framebuffer); |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 731 | Limits : constant Pipe_Scaler_Limit_Config := |
| 732 | (if Config.Has_Skylake_Scaler_Limits then |
| 733 | Skylake_Scaler_Limits (Controller, Width_In, Height_In) |
| 734 | else |
| 735 | Tigerlake_Scaler_Limits (Width_In, Height_In)); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 736 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 737 | Width : Width_Type; |
| 738 | Height : Height_Type; |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 739 | Pos_X, Pos_Y : Position_Type; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 740 | begin |
| 741 | -- Writes to WIN_SZ arm the PS registers. |
| 742 | |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 743 | Scale |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 744 | (Width => Width, |
| 745 | Height => Height, |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 746 | Scaling => Pipe_Cfg.Scaling, |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 747 | Max_Width => Pos32'Min (Limits.Horizontal, Mode.H_Visible), |
| 748 | Max_Height => Pos32'Min (Limits.Vertical, Mode.V_Visible), |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 749 | Framebuffer => Pipe_Cfg.Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 750 | |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 751 | Align_Framebuffer |
| 752 | (Pos_X => Pos_X, |
| 753 | Pos_Y => Pos_Y, |
| 754 | Align => Pipe_Cfg.Alignment, |
| 755 | Width => Width, |
| 756 | Height => Height, |
| 757 | Mode => Mode); |
| 758 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 759 | Registers.Write |
| 760 | (Register => Controller.PS_CTRL_1, |
| Nico Huber | fb6dbad | 2026-04-10 16:23:39 +0000 | [diff] [blame] | 761 | Value => PS_CTRL_ENABLE_SCALER or Limits.Control); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 762 | Registers.Write |
| 763 | (Register => Controller.PS_WIN_POS_1, |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 764 | Value => Shift_Left (Word32 (Pos_X), 16) or Word32 (Pos_Y)); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 765 | Registers.Write |
| 766 | (Register => Controller.PS_WIN_SZ_1, |
| 767 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 768 | end Setup_Skylake_Pipe_Scaler; |
| 769 | |
| 770 | procedure Setup_Ironlake_Panel_Fitter |
| 771 | (Controller : in Controller_Type; |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 772 | Pipe_Cfg : in Pipe_Config; |
| 773 | Mode : in HW.GFX.Mode_Type) |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 774 | with |
| 775 | Pre => |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 776 | Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and |
| 777 | Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 778 | is |
| 779 | -- Force 1:1 mapping of panel fitter:pipe |
| 780 | PF_Ctrl_Pipe_Sel : constant Word32 := |
| 781 | (if Config.Has_PF_Pipe_Select then |
| 782 | (case Controller.PF_CTRL is |
| 783 | when Registers.PFA_CTL_1 => 0 * 2 ** 29, |
| 784 | when Registers.PFB_CTL_1 => 1 * 2 ** 29, |
| 785 | when Registers.PFC_CTL_1 => 2 * 2 ** 29, |
| 786 | when others => 0) else 0); |
| 787 | |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 788 | Width : Width_Type; |
| 789 | Height : Height_Type; |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 790 | Pos_X, Pos_Y : Position_Type; |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 791 | begin |
| 792 | -- Writes to WIN_SZ arm the PF registers. |
| 793 | |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 794 | Scale |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 795 | (Width => Width, |
| 796 | Height => Height, |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 797 | Scaling => Pipe_Cfg.Scaling, |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 798 | Max_Width => Mode.H_Visible, |
| 799 | Max_Height => Mode.V_Visible, |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 800 | Framebuffer => Pipe_Cfg.Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 801 | |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 802 | -- 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] | 803 | if Width < Mode.H_Visible and Width mod 2 = 1 then |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 804 | Width := Width + 1; |
| 805 | end if; |
| Nico Huber | b3b9fa3 | 2018-06-18 16:16:41 +0200 | [diff] [blame] | 806 | -- Do not scale to odd height (at least Sandy Bridge makes trouble). |
| 807 | if Height < Mode.V_Visible and Height mod 2 = 1 then |
| 808 | Height := Height + 1; |
| 809 | end if; |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 810 | |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 811 | Align_Framebuffer |
| 812 | (Pos_X => Pos_X, |
| 813 | Pos_Y => Pos_Y, |
| 814 | Align => Pipe_Cfg.Alignment, |
| 815 | Width => Width, |
| 816 | Height => Height, |
| 817 | Mode => Mode); |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 818 | |
| 819 | -- Hardware is picky about minimal horizontal gaps. |
| Nico Huber | c5c767a | 2018-06-03 01:09:04 +0200 | [diff] [blame] | 820 | if Mode.H_Visible - Width <= 3 then |
| 821 | Width := Mode.H_Visible; |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 822 | Pos_X := 0; |
| Nico Huber | fdb0df1 | 2018-02-07 14:30:34 +0100 | [diff] [blame] | 823 | end if; |
| 824 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 825 | Registers.Write |
| 826 | (Register => Controller.PF_CTRL, |
| 827 | Value => PF_CTRL_ENABLE or PF_Ctrl_Pipe_Sel or PF_CTRL_FILTER_MED); |
| 828 | Registers.Write |
| 829 | (Register => Controller.PF_WIN_POS, |
| Nico Huber | ba84df2 | 2026-06-23 13:29:29 +0000 | [diff] [blame] | 830 | Value => Shift_Left (Word32 (Pos_X), 16) or Word32 (Pos_Y)); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 831 | Registers.Write |
| 832 | (Register => Controller.PF_WIN_SZ, |
| 833 | Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); |
| 834 | end Setup_Ironlake_Panel_Fitter; |
| 835 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 836 | procedure Setup_Gmch_Panel_Fitter |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 837 | (Controller : in Controller_Type; |
| 838 | Mode : in HW.GFX.Mode_Type; |
| 839 | Framebuffer : in HW.GFX.Framebuffer_Type) |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 840 | is |
| 841 | PF_Ctrl_Pipe_Sel : constant Word32 := |
| 842 | (case Controller.Pipe is |
| 843 | when Primary => GMCH_PFIT_CONTROL_SELECT_PIPE_A, |
| 844 | when Secondary => GMCH_PFIT_CONTROL_SELECT_PIPE_B, |
| 845 | when others => 0); |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 846 | |
| Arthur Heymans | f70edda | 2018-08-21 18:37:00 +0200 | [diff] [blame] | 847 | -- Work around a quirk: |
| 848 | -- In legacy VGA mode Pillarbox fails to display anything so just force |
| 849 | -- 'auto' mode on all displays, which will the output stretched to |
| 850 | -- fullscreen . |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 851 | PF_Ctrl_Scaling : constant Word32 := |
| Arthur Heymans | f70edda | 2018-08-21 18:37:00 +0200 | [diff] [blame] | 852 | (if Framebuffer.Offset = VGA_PLANE_FRAMEBUFFER_OFFSET then |
| 853 | GMCH_PFIT_CONTROL_SCALING (Uniform) |
| 854 | else |
| 855 | GMCH_PFIT_CONTROL_SCALING (Scaling_Type (Framebuffer, Mode))); |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 856 | |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 857 | In_Use : Boolean; |
| 858 | begin |
| 859 | Registers.Is_Set_Mask |
| 860 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 861 | Mask => PF_CTRL_ENABLE, |
| 862 | Result => In_Use); |
| 863 | |
| 864 | if not In_Use then |
| 865 | Registers.Write |
| 866 | (Register => Registers.GMCH_PFIT_CONTROL, |
| Nico Huber | 958c564 | 2018-06-02 16:59:31 +0200 | [diff] [blame] | 867 | 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] | 868 | else |
| Nico Huber | 7ba7bd6 | 2018-06-06 12:27:09 +0200 | [diff] [blame] | 869 | pragma Debug (Debug.Put_Line |
| 870 | ("GMCH Pannel fitter already in use, skipping...")); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 871 | end if; |
| 872 | end Setup_Gmch_Panel_Fitter; |
| 873 | |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 874 | procedure Gmch_Panel_Fitter_Pipe (Pipe : out Pipe_Index) |
| 875 | is |
| 876 | Used_For_Secondary : Boolean; |
| 877 | begin |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 878 | if Config.Gen_I945 then |
| 879 | -- Gen3: panel fitter is hardwired to Pipe B (Secondary). |
| 880 | -- The PFIT_PIPE field (bits 30:29) does not exist on Gen3. |
| 881 | Pipe := Secondary; |
| 882 | else |
| 883 | Registers.Is_Set_Mask |
| 884 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 885 | Mask => GMCH_PFIT_CONTROL_SELECT_PIPE_B, |
| 886 | Result => Used_For_Secondary); |
| 887 | Pipe := (if Used_For_Secondary then Secondary else Primary); |
| 888 | end if; |
| Nico Huber | ac2a141 | 2026-07-02 10:41:59 +0200 | [diff] [blame] | 889 | end Gmch_Panel_Fitter_Pipe; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 890 | |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 891 | procedure Panel_Fitter_Off (Controller : Controller_Type) |
| 892 | is |
| 893 | use type HW.GFX.GMA.Registers.Registers_Invalid_Index; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 894 | Pipe_Using_PF : Pipe_Index; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 895 | begin |
| 896 | -- Writes to WIN_SZ arm the PS/PF registers. |
| 897 | if Config.Has_Plane_Control then |
| 898 | Registers.Unset_Mask (Controller.PS_CTRL_1, PS_CTRL_ENABLE_SCALER); |
| 899 | Registers.Write (Controller.PS_WIN_SZ_1, 16#0000_0000#); |
| 900 | if Controller.PS_CTRL_2 /= Registers.Invalid_Register and |
| 901 | Controller.PS_WIN_SZ_2 /= Registers.Invalid_Register |
| 902 | then |
| 903 | Registers.Unset_Mask (Controller.PS_CTRL_2, PS_CTRL_ENABLE_SCALER); |
| 904 | Registers.Write (Controller.PS_WIN_SZ_2, 16#0000_0000#); |
| 905 | end if; |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 906 | elsif Config.Has_GMCH_PFIT_CONTROL then |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 907 | Gmch_Panel_Fitter_Pipe (Pipe_Using_PF); |
| 908 | if Pipe_Using_PF = Controller.Pipe then |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 909 | -- Write 0 to clear all bits (enable, scaling mode, auto-scale, |
| 910 | -- interpolation). Just clearing the enable bit can leave stale |
| 911 | -- Gen3 auto-scale bits that confuse the hardware. |
| 912 | Registers.Write (Registers.GMCH_PFIT_CONTROL, 16#0000_0000#); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 913 | end if; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 914 | else |
| 915 | Registers.Unset_Mask (Controller.PF_CTRL, PF_CTRL_ENABLE); |
| 916 | Registers.Write (Controller.PF_WIN_SZ, 16#0000_0000#); |
| 917 | end if; |
| 918 | end Panel_Fitter_Off; |
| 919 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 920 | procedure Setup_Scaling |
| 921 | (Controller : in Controller_Type; |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 922 | Pipe_Cfg : in Pipe_Config; |
| 923 | Mode : in HW.GFX.Mode_Type) |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 924 | with |
| 925 | Pre => |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 926 | Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and |
| 927 | Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 928 | is |
| 929 | begin |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 930 | if Requires_Scaling (Pipe_Cfg.Framebuffer, Mode) then |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 931 | if Config.Has_Plane_Control then |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 932 | Setup_Skylake_Pipe_Scaler (Controller, Pipe_Cfg, Mode); |
| Arthur Heymans | d519844 | 2018-03-28 17:05:12 +0200 | [diff] [blame] | 933 | elsif Config.Has_GMCH_PFIT_CONTROL then |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 934 | Setup_Gmch_Panel_Fitter (Controller, Mode, Pipe_Cfg.Framebuffer); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 935 | else |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 936 | Setup_Ironlake_Panel_Fitter (Controller, Pipe_Cfg, Mode); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 937 | end if; |
| Nico Huber | b4b7279 | 2018-01-02 13:45:41 +0100 | [diff] [blame] | 938 | else |
| 939 | Panel_Fitter_Off (Controller); |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 940 | end if; |
| 941 | end Setup_Scaling; |
| 942 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 943 | procedure Reserve_Scaler |
| 944 | (Success : out Boolean; |
| 945 | Reservation : in out Scaler_Reservation; |
| 946 | Pipe : in Pipe_Index) |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 947 | is |
| 948 | Pipe_Using_PF : Pipe_Index := Pipe_Index'First; |
| 949 | PF_Enabled : Boolean; |
| 950 | begin |
| 951 | if Config.Has_GMCH_PFIT_CONTROL then |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 952 | if Reservation.Reserved then |
| 953 | Success := Reservation.Pipe = Pipe; |
| 954 | return; |
| 955 | end if; |
| 956 | |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 957 | Registers.Is_Set_Mask |
| 958 | (Register => Registers.GMCH_PFIT_CONTROL, |
| 959 | Mask => PF_CTRL_ENABLE, |
| 960 | Result => PF_Enabled); |
| 961 | if PF_Enabled then |
| 962 | Gmch_Panel_Fitter_Pipe (Pipe_Using_PF); |
| 963 | end if; |
| 964 | |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 965 | Success := not PF_Enabled or Pipe_Using_PF = Pipe; |
| 966 | if Success then |
| 967 | Reservation.Reserved := True; |
| 968 | Reservation.Pipe := Pipe; |
| 969 | end if; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 970 | else |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 971 | Success := True; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 972 | end if; |
| Nico Huber | 9a4c4c3 | 2019-09-16 22:05:11 +0200 | [diff] [blame] | 973 | end Reserve_Scaler; |
| Nico Huber | f361ec8 | 2018-06-02 18:01:45 +0200 | [diff] [blame] | 974 | |
| Nico Huber | 4916e34 | 2016-11-04 14:37:53 +0100 | [diff] [blame] | 975 | ---------------------------------------------------------------------------- |
| 976 | |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 977 | procedure Setup_FB |
| 978 | (Pipe : Pipe_Index; |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 979 | Pipe_Cfg : Pipe_Config; |
| 980 | Mode : Mode_Type) |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 981 | is |
| 982 | -- Enable dithering if framebuffer BPC differs from port BPC, |
| 983 | -- as smooth gradients look really bad without. |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 984 | Dither : constant Boolean := Pipe_Cfg.Framebuffer.BPC /= Mode.BPC; |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 985 | begin |
| 986 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 987 | |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 988 | -- Disable the cursor first. |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 989 | Update_Cursor (Pipe, Pipe_Cfg.Framebuffer, Default_Cursor); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 990 | |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 991 | Setup_Display (Controllers (Pipe), Pipe_Cfg.Framebuffer, Mode.BPC, Dither); |
| 992 | Setup_Scaling (Controllers (Pipe), Pipe_Cfg, Mode); |
| Nico Huber | f7f537e | 2018-01-02 14:15:43 +0100 | [diff] [blame] | 993 | end Setup_FB; |
| 994 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 995 | procedure On |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 996 | (Pipe : Pipe_Index; |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 997 | Pipe_Cfg : Pipe_Config; |
| 998 | Port_Cfg : Port_Config) |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 999 | is |
| 1000 | begin |
| 1001 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 1002 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1003 | Transcoder.Setup (Pipe, Port_Cfg); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1004 | |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 1005 | Setup_FB (Pipe, Pipe_Cfg, Port_Cfg.Mode); |
| 1006 | Update_Cursor (Pipe, Pipe_Cfg.Framebuffer, Pipe_Cfg.Cursor); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1007 | |
| Nico Huber | abb16d9 | 2018-05-29 01:44:26 +0200 | [diff] [blame] | 1008 | Transcoder.On |
| 1009 | (Pipe => Pipe, |
| 1010 | Port_Cfg => Port_Cfg, |
| Nico Huber | 4d592b4 | 2026-06-23 12:21:37 +0000 | [diff] [blame] | 1011 | Dither => Pipe_Cfg.Framebuffer.BPC /= Port_Cfg.Mode.BPC, |
| 1012 | Scale => Requires_Scaling (Pipe_Cfg.Framebuffer, Port_Cfg.Mode)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1013 | end On; |
| 1014 | |
| 1015 | ---------------------------------------------------------------------------- |
| 1016 | |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 1017 | procedure Planes_Off (Controller : Controller_Type; CUR : Cursor_Regs) |
| 1018 | is |
| 1019 | use type Registers.Registers_Invalid_Index; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1020 | begin |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 1021 | Registers.Write (CUR.CTL, 16#0000_0000#); |
| 1022 | if CUR.FBC_CTL /= Registers.Invalid_Register then |
| 1023 | Registers.Write (CUR.FBC_CTL, 16#0000_0000#); |
| Nico Huber | 4dc4c61 | 2018-01-10 15:55:09 +0100 | [diff] [blame] | 1024 | end if; |
| Nico Huber | 07aab5a | 2020-10-01 15:06:53 +0200 | [diff] [blame] | 1025 | Registers.Unset_Mask (Controller.PLANE_2_CTL, DSPCNTR_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1026 | if Config.Has_Plane_Control then |
| 1027 | Clear_Watermarks (Controller); |
| 1028 | Registers.Unset_Mask (Controller.PLANE_CTL, PLANE_CTL_PLANE_ENABLE); |
| 1029 | Registers.Write (Controller.PLANE_SURF, 16#0000_0000#); |
| 1030 | else |
| 1031 | Registers.Unset_Mask (Controller.DSPCNTR, DSPCNTR_ENABLE); |
| 1032 | end if; |
| 1033 | end Planes_Off; |
| 1034 | |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1035 | procedure Off (Pipe : Pipe_Index) |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 1036 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1037 | begin |
| 1038 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 1039 | |
| Nico Huber | 75a707f | 2018-06-18 16:28:33 +0200 | [diff] [blame] | 1040 | Planes_Off (Controllers (Pipe), Cursors (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1041 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 1042 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1043 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1044 | end Off; |
| 1045 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 1046 | procedure Legacy_VGA_Off |
| 1047 | is |
| 1048 | use type HW.Word8; |
| 1049 | Reg8 : Word8; |
| 1050 | begin |
| 1051 | Port_IO.OutB (VGA_SR_INDEX, VGA_SR01); |
| 1052 | Port_IO.InB (Reg8, VGA_SR_DATA); |
| 1053 | Port_IO.OutB (VGA_SR_DATA, Reg8 or VGA_SR01_SCREEN_OFF); |
| 1054 | Time.U_Delay (100); -- PRM says 100us, Linux does 300 |
| Arthur Heymans | dfcdd77 | 2018-03-28 16:42:50 +0200 | [diff] [blame] | 1055 | Registers.Set_Mask (VGACNTRL_REG, VGA_CONTROL_VGA_DISPLAY_DISABLE); |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 1056 | end Legacy_VGA_Off; |
| 1057 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1058 | procedure All_Off |
| 1059 | is |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1060 | begin |
| 1061 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 1062 | |
| Nico Huber | 33912aa | 2016-12-06 20:36:23 +0100 | [diff] [blame] | 1063 | Legacy_VGA_Off; |
| 1064 | |
| Arthur Heymans | 960e239 | 2026-03-03 19:45:24 +0100 | [diff] [blame] | 1065 | 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] | 1066 | Planes_Off (Controllers (Pipe), Cursors (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1067 | Transcoder.Off (Pipe); |
| Nico Huber | f3e2366 | 2016-12-05 21:33:03 +0100 | [diff] [blame] | 1068 | Panel_Fitter_Off (Controllers (Pipe)); |
| Nico Huber | 7ad2d65 | 2016-12-07 15:19:32 +0100 | [diff] [blame] | 1069 | Transcoder.Clk_Off (Pipe); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1070 | end loop; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1071 | end All_Off; |
| 1072 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1073 | end HW.GFX.GMA.Pipe_Setup; |