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