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