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