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