blob: f047a6444d85924a4fa9b03e1657632a662c90a7 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2015-2016 secunet Security Networks AG
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 Huber125a29e2016-10-18 00:23:54 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02008--
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
Nico Huber75a707f2018-06-18 16:28:33 +020015with HW.GFX.GMA.Config;
Nico Huber9e96a452019-09-22 20:25:17 +020016with HW.GFX.GMA.Config_Helpers;
Nico Huber83693c82016-10-08 22:17:55 +020017with HW.GFX.GMA.Registers;
18
Nico Huber47ff0692016-11-04 14:29:39 +010019
Nico Huber83693c82016-10-08 22:17:55 +020020private package HW.GFX.GMA.Pipe_Setup
21is
22
Nico Huber83693c82016-10-08 22:17:55 +020023 procedure On
Nico Huberf3e23662016-12-05 21:33:03 +010024 (Pipe : Pipe_Index;
Nico Huber83693c82016-10-08 22:17:55 +020025 Port_Cfg : Port_Config;
Nico Huber4dc4c612018-01-10 15:55:09 +010026 Framebuffer : Framebuffer_Type;
27 Cursor : Cursor_Type)
Nico Huber47ff0692016-11-04 14:29:39 +010028 with
Nico Huber9e96a452019-09-22 20:25:17 +020029 Pre => Config_Helpers.Valid_FB (Framebuffer, Port_Cfg.Mode);
Nico Huber83693c82016-10-08 22:17:55 +020030
Nico Huber7ad2d652016-12-07 15:19:32 +010031 procedure Off (Pipe : Pipe_Index);
Nico Huber83693c82016-10-08 22:17:55 +020032
Nico Huber33912aa2016-12-06 20:36:23 +010033 procedure Legacy_VGA_Off;
34
Nico Huber83693c82016-10-08 22:17:55 +020035 procedure All_Off;
36
Nico Huberf7f537e2018-01-02 14:15:43 +010037 procedure Setup_FB
38 (Pipe : Pipe_Index;
39 Mode : Mode_Type;
40 Framebuffer : Framebuffer_Type)
41 with
Nico Huber9e96a452019-09-22 20:25:17 +020042 Pre => Config_Helpers.Valid_FB (Framebuffer, Mode);
Nico Huber83693c82016-10-08 22:17:55 +020043
Nico Huber4dc4c612018-01-10 15:55:09 +010044 procedure Update_Cursor
45 (Pipe : Pipe_Index;
46 FB : Framebuffer_Type;
47 Cursor : Cursor_Type);
48 procedure Place_Cursor
49 (Pipe : Pipe_Index;
50 FB : Framebuffer_Type;
51 Cursor : Cursor_Type);
52
Nico Huber9a4c4c32019-09-16 22:05:11 +020053 type Scaler_Reservation is private;
54 Null_Scaler_Reservation : constant Scaler_Reservation;
55 procedure Reserve_Scaler
56 (Success : out Boolean;
57 Reservation : in out Scaler_Reservation;
58 Pipe : in Pipe_Index);
Nico Huberf361ec82018-06-02 18:01:45 +020059
Nico Huber83693c82016-10-08 22:17:55 +020060private
61
Nico Huber9a4c4c32019-09-16 22:05:11 +020062 type Scaler_Reservation is record
63 Reserved : Boolean;
64 Pipe : Pipe_Index;
65 end record;
66 Null_Scaler_Reservation : constant Scaler_Reservation :=
67 (Reserved => False, Pipe => Pipe_Index'First);
68
Nico Huber83693c82016-10-08 22:17:55 +020069 subtype WM_Levels is Natural range 0 .. 7;
70 type PLANE_WM_Type is array (WM_Levels) of Registers.Registers_Index;
71
72 type Controller_Type is
73 record
Nico Huberf3e23662016-12-05 21:33:03 +010074 Pipe : Pipe_Index;
Nico Huber83693c82016-10-08 22:17:55 +020075 PIPESRC : Registers.Registers_Index;
76 PIPEMISC : Registers.Registers_Index;
Nico Huber4916e342016-11-04 14:37:53 +010077 PF_CTRL : Registers.Registers_Index;
Nico Huber83693c82016-10-08 22:17:55 +020078 PF_WIN_POS : Registers.Registers_Index;
79 PF_WIN_SZ : Registers.Registers_Index;
80 DSPCNTR : Registers.Registers_Index;
81 DSPLINOFF : Registers.Registers_Index;
82 DSPSTRIDE : Registers.Registers_Index;
83 DSPSURF : Registers.Registers_Index;
84 DSPTILEOFF : Registers.Registers_Index;
Arthur Heymans960e2392026-03-03 19:45:24 +010085 DSPSIZE : Registers.Registers_Index;
86 DSPPOS : Registers.Registers_Index;
Nico Huber83693c82016-10-08 22:17:55 +020087 SPCNTR : Registers.Registers_Index;
Nico Huber83693c82016-10-08 22:17:55 +020088 -- Skylake registers (partially aliased)
89 PLANE_CTL : Registers.Registers_Index;
90 PLANE_OFFSET : Registers.Registers_Index;
91 PLANE_POS : Registers.Registers_Index;
92 PLANE_SIZE : Registers.Registers_Index;
93 PLANE_STRIDE : Registers.Registers_Index;
94 PLANE_SURF : Registers.Registers_Index;
95 PS_CTRL_1 : Registers.Registers_Index;
Nico Huber4916e342016-11-04 14:37:53 +010096 PS_WIN_POS_1 : Registers.Registers_Index;
Nico Huber83693c82016-10-08 22:17:55 +020097 PS_WIN_SZ_1 : Registers.Registers_Index;
Nico Huber4916e342016-11-04 14:37:53 +010098 PS_CTRL_2 : Registers.Registers_Invalid_Index;
Nico Huber83693c82016-10-08 22:17:55 +020099 PS_WIN_SZ_2 : Registers.Registers_Invalid_Index;
100 WM_LINETIME : Registers.Registers_Index;
101 PLANE_BUF_CFG : Registers.Registers_Index;
102 PLANE_WM : PLANE_WM_Type;
Nico Huber4dc4c612018-01-10 15:55:09 +0100103 CUR_BUF_CFG : Registers.Registers_Index;
104 CUR_WM : PLANE_WM_Type;
Nico Huber83693c82016-10-08 22:17:55 +0200105 end record;
106
Nico Huberf3e23662016-12-05 21:33:03 +0100107 type Controller_Array is array (Pipe_Index) of Controller_Type;
108
Arthur Heymans960e2392026-03-03 19:45:24 +0100109 -- On Gen3 (i945), FBC only works with Plane A, but LVDS and the
110 -- panel fitter are hooked to Pipe B. Hence we want Plane A feeding
111 -- Pipe B, which means swapping the plane register assignments:
112 -- Primary (Pipe A) gets Plane B, Secondary (Pipe B) gets Plane A.
113
Nico Huberf3e23662016-12-05 21:33:03 +0100114 Controllers : constant Controller_Array :=
115 (Primary => Controller_Type'
116 (Pipe => Primary,
Nico Huber83693c82016-10-08 22:17:55 +0200117 PIPESRC => Registers.PIPEASRC,
118 PIPEMISC => Registers.PIPEAMISC,
Nico Huber4916e342016-11-04 14:37:53 +0100119 PF_CTRL => Registers.PFA_CTL_1,
Nico Huber83693c82016-10-08 22:17:55 +0200120 PF_WIN_POS => Registers.PFA_WIN_POS,
121 PF_WIN_SZ => Registers.PFA_WIN_SZ,
Arthur Heymans960e2392026-03-03 19:45:24 +0100122 DSPCNTR =>
123 (if Config.Planes_Pipes_Swapped
124 then Registers.DSPBCNTR else Registers.DSPACNTR),
125 DSPLINOFF =>
126 (if Config.Planes_Pipes_Swapped
127 then Registers.DSPBLINOFF else Registers.DSPALINOFF),
128 DSPSTRIDE =>
129 (if Config.Planes_Pipes_Swapped
130 then Registers.DSPBSTRIDE else Registers.DSPASTRIDE),
131 DSPSURF =>
132 (if Config.Planes_Pipes_Swapped
133 then Registers.DSPBSURF else Registers.DSPASURF),
134 DSPTILEOFF =>
135 (if Config.Planes_Pipes_Swapped
136 then Registers.DSPBTILEOFF else Registers.DSPATILEOFF),
137 DSPSIZE =>
138 (if Config.Planes_Pipes_Swapped
139 then Registers.PLANE_SIZE_1_B else Registers.PLANE_SIZE_1_A),
140 DSPPOS =>
141 (if Config.Planes_Pipes_Swapped
142 then Registers.PLANE_POS_1_B else Registers.PLANE_POS_1_A),
Nico Huber83693c82016-10-08 22:17:55 +0200143 SPCNTR => Registers.SPACNTR,
Nico Huber83693c82016-10-08 22:17:55 +0200144 PLANE_CTL => Registers.DSPACNTR,
145 PLANE_OFFSET => Registers.DSPATILEOFF,
146 PLANE_POS => Registers.PLANE_POS_1_A,
147 PLANE_SIZE => Registers.PLANE_SIZE_1_A,
148 PLANE_STRIDE => Registers.DSPASTRIDE,
149 PLANE_SURF => Registers.DSPASURF,
150 PS_CTRL_1 => Registers.PS_CTRL_1_A,
Nico Huber4916e342016-11-04 14:37:53 +0100151 PS_WIN_POS_1 => Registers.PS_WIN_POS_1_A,
Nico Huber83693c82016-10-08 22:17:55 +0200152 PS_WIN_SZ_1 => Registers.PS_WIN_SZ_1_A,
Nico Huber4916e342016-11-04 14:37:53 +0100153 PS_CTRL_2 => Registers.PS_CTRL_2_A,
Nico Huber83693c82016-10-08 22:17:55 +0200154 PS_WIN_SZ_2 => Registers.PS_WIN_SZ_2_A,
155 WM_LINETIME => Registers.WM_LINETIME_A,
156 PLANE_BUF_CFG => Registers.PLANE_BUF_CFG_1_A,
157 PLANE_WM => PLANE_WM_Type'(
158 Registers.PLANE_WM_1_A_0,
159 Registers.PLANE_WM_1_A_1,
160 Registers.PLANE_WM_1_A_2,
161 Registers.PLANE_WM_1_A_3,
162 Registers.PLANE_WM_1_A_4,
163 Registers.PLANE_WM_1_A_5,
164 Registers.PLANE_WM_1_A_6,
Nico Huber4dc4c612018-01-10 15:55:09 +0100165 Registers.PLANE_WM_1_A_7),
166 CUR_BUF_CFG => Registers.CUR_BUF_CFG_A,
167 CUR_WM => PLANE_WM_Type'(
168 Registers.CUR_WM_A_0,
169 Registers.CUR_WM_A_1,
170 Registers.CUR_WM_A_2,
171 Registers.CUR_WM_A_3,
172 Registers.CUR_WM_A_4,
173 Registers.CUR_WM_A_5,
174 Registers.CUR_WM_A_6,
175 Registers.CUR_WM_A_7)),
Nico Huberf3e23662016-12-05 21:33:03 +0100176 Secondary => Controller_Type'
177 (Pipe => Secondary,
Nico Huber83693c82016-10-08 22:17:55 +0200178 PIPESRC => Registers.PIPEBSRC,
179 PIPEMISC => Registers.PIPEBMISC,
Nico Huber4916e342016-11-04 14:37:53 +0100180 PF_CTRL => Registers.PFB_CTL_1,
Nico Huber83693c82016-10-08 22:17:55 +0200181 PF_WIN_POS => Registers.PFB_WIN_POS,
182 PF_WIN_SZ => Registers.PFB_WIN_SZ,
Arthur Heymans960e2392026-03-03 19:45:24 +0100183 DSPCNTR =>
184 (if Config.Planes_Pipes_Swapped
185 then Registers.DSPACNTR else Registers.DSPBCNTR),
186 DSPLINOFF =>
187 (if Config.Planes_Pipes_Swapped
188 then Registers.DSPALINOFF else Registers.DSPBLINOFF),
189 DSPSTRIDE =>
190 (if Config.Planes_Pipes_Swapped
191 then Registers.DSPASTRIDE else Registers.DSPBSTRIDE),
192 DSPSURF =>
193 (if Config.Planes_Pipes_Swapped
194 then Registers.DSPASURF else Registers.DSPBSURF),
195 DSPTILEOFF =>
196 (if Config.Planes_Pipes_Swapped
197 then Registers.DSPATILEOFF else Registers.DSPBTILEOFF),
198 DSPSIZE =>
199 (if Config.Planes_Pipes_Swapped
200 then Registers.PLANE_SIZE_1_A else Registers.PLANE_SIZE_1_B),
201 DSPPOS =>
202 (if Config.Planes_Pipes_Swapped
203 then Registers.PLANE_POS_1_A else Registers.PLANE_POS_1_B),
Nico Huber83693c82016-10-08 22:17:55 +0200204 SPCNTR => Registers.SPBCNTR,
Nico Huber83693c82016-10-08 22:17:55 +0200205 PLANE_CTL => Registers.DSPBCNTR,
206 PLANE_OFFSET => Registers.DSPBTILEOFF,
207 PLANE_POS => Registers.PLANE_POS_1_B,
208 PLANE_SIZE => Registers.PLANE_SIZE_1_B,
209 PLANE_STRIDE => Registers.DSPBSTRIDE,
210 PLANE_SURF => Registers.DSPBSURF,
211 PS_CTRL_1 => Registers.PS_CTRL_1_B,
Nico Huber4916e342016-11-04 14:37:53 +0100212 PS_WIN_POS_1 => Registers.PS_WIN_POS_1_B,
Nico Huber83693c82016-10-08 22:17:55 +0200213 PS_WIN_SZ_1 => Registers.PS_WIN_SZ_1_B,
Nico Huber4916e342016-11-04 14:37:53 +0100214 PS_CTRL_2 => Registers.PS_CTRL_2_B,
Nico Huber83693c82016-10-08 22:17:55 +0200215 PS_WIN_SZ_2 => Registers.PS_WIN_SZ_2_B,
216 WM_LINETIME => Registers.WM_LINETIME_B,
217 PLANE_BUF_CFG => Registers.PLANE_BUF_CFG_1_B,
218 PLANE_WM => PLANE_WM_Type'(
219 Registers.PLANE_WM_1_B_0,
220 Registers.PLANE_WM_1_B_1,
221 Registers.PLANE_WM_1_B_2,
222 Registers.PLANE_WM_1_B_3,
223 Registers.PLANE_WM_1_B_4,
224 Registers.PLANE_WM_1_B_5,
225 Registers.PLANE_WM_1_B_6,
Nico Huber4dc4c612018-01-10 15:55:09 +0100226 Registers.PLANE_WM_1_B_7),
227 CUR_BUF_CFG => Registers.CUR_BUF_CFG_B,
228 CUR_WM => PLANE_WM_Type'(
229 Registers.CUR_WM_B_0,
230 Registers.CUR_WM_B_1,
231 Registers.CUR_WM_B_2,
232 Registers.CUR_WM_B_3,
233 Registers.CUR_WM_B_4,
234 Registers.CUR_WM_B_5,
235 Registers.CUR_WM_B_6,
236 Registers.CUR_WM_B_7)),
Nico Huberf3e23662016-12-05 21:33:03 +0100237 Tertiary => Controller_Type'
238 (Pipe => Tertiary,
Nico Huber83693c82016-10-08 22:17:55 +0200239 PIPESRC => Registers.PIPECSRC,
240 PIPEMISC => Registers.PIPECMISC,
Nico Huber4916e342016-11-04 14:37:53 +0100241 PF_CTRL => Registers.PFC_CTL_1,
Nico Huber83693c82016-10-08 22:17:55 +0200242 PF_WIN_POS => Registers.PFC_WIN_POS,
243 PF_WIN_SZ => Registers.PFC_WIN_SZ,
244 DSPCNTR => Registers.DSPCCNTR,
245 DSPLINOFF => Registers.DSPCLINOFF,
246 DSPSTRIDE => Registers.DSPCSTRIDE,
247 DSPSURF => Registers.DSPCSURF,
248 DSPTILEOFF => Registers.DSPCTILEOFF,
Arthur Heymans960e2392026-03-03 19:45:24 +0100249 DSPSIZE => Registers.PLANE_SIZE_1_C,
250 DSPPOS => Registers.PLANE_POS_1_C,
Nico Huber83693c82016-10-08 22:17:55 +0200251 SPCNTR => Registers.SPCCNTR,
Nico Huber83693c82016-10-08 22:17:55 +0200252 PLANE_CTL => Registers.DSPCCNTR,
253 PLANE_OFFSET => Registers.DSPCTILEOFF,
254 PLANE_POS => Registers.PLANE_POS_1_C,
255 PLANE_SIZE => Registers.PLANE_SIZE_1_C,
256 PLANE_STRIDE => Registers.DSPCSTRIDE,
257 PLANE_SURF => Registers.DSPCSURF,
258 PS_CTRL_1 => Registers.PS_CTRL_1_C,
Nico Huber4916e342016-11-04 14:37:53 +0100259 PS_WIN_POS_1 => Registers.PS_WIN_POS_1_C,
Nico Huber83693c82016-10-08 22:17:55 +0200260 PS_WIN_SZ_1 => Registers.PS_WIN_SZ_1_C,
Nico Huber4916e342016-11-04 14:37:53 +0100261 PS_CTRL_2 => Registers.Invalid_Register,
Nico Huber83693c82016-10-08 22:17:55 +0200262 PS_WIN_SZ_2 => Registers.Invalid_Register,
263 WM_LINETIME => Registers.WM_LINETIME_C,
264 PLANE_BUF_CFG => Registers.PLANE_BUF_CFG_1_C,
265 PLANE_WM => PLANE_WM_Type'(
266 Registers.PLANE_WM_1_C_0,
267 Registers.PLANE_WM_1_C_1,
268 Registers.PLANE_WM_1_C_2,
269 Registers.PLANE_WM_1_C_3,
270 Registers.PLANE_WM_1_C_4,
271 Registers.PLANE_WM_1_C_5,
272 Registers.PLANE_WM_1_C_6,
Nico Huber4dc4c612018-01-10 15:55:09 +0100273 Registers.PLANE_WM_1_C_7),
274 CUR_BUF_CFG => Registers.CUR_BUF_CFG_C,
275 CUR_WM => PLANE_WM_Type'(
276 Registers.CUR_WM_C_0,
277 Registers.CUR_WM_C_1,
278 Registers.CUR_WM_C_2,
279 Registers.CUR_WM_C_3,
280 Registers.CUR_WM_C_4,
281 Registers.CUR_WM_C_5,
282 Registers.CUR_WM_C_6,
283 Registers.CUR_WM_C_7)));
Nico Huber83693c82016-10-08 22:17:55 +0200284
Nico Huber75a707f2018-06-18 16:28:33 +0200285 type Cursor_Regs is record
286 CTL : Registers.Registers_Index;
287 BASE : Registers.Registers_Index;
288 POS : Registers.Registers_Index;
289 FBC_CTL : Registers.Registers_Invalid_Index;
290 end record;
291
292 function Cursors (Pipe : Pipe_Index) return Cursor_Regs is
293 (if not Config.Has_Ivybridge_Cursors then
294 (if Pipe = Primary then
295 (CTL => Registers.CURACNTR,
296 BASE => Registers.CURABASE,
297 POS => Registers.CURAPOS,
298 FBC_CTL => Registers.Invalid_Register)
299 else
300 (CTL => Registers.CURBCNTR,
301 BASE => Registers.CURBBASE,
302 POS => Registers.CURBPOS,
303 FBC_CTL => Registers.Invalid_Register))
304 else
305 (if Pipe = Primary then
306 (CTL => Registers.CUR_CTL_A,
307 BASE => Registers.CUR_BASE_A,
308 POS => Registers.CUR_POS_A,
309 FBC_CTL => Registers.CUR_FBC_CTL_A)
310 elsif Pipe = Secondary then
311 (CTL => Registers.CUR_CTL_B,
312 BASE => Registers.CUR_BASE_B,
313 POS => Registers.CUR_POS_B,
314 FBC_CTL => Registers.CUR_FBC_CTL_B)
315 else
316 (CTL => Registers.CUR_CTL_C,
317 BASE => Registers.CUR_BASE_C,
318 POS => Registers.CUR_POS_C,
319 FBC_CTL => Registers.CUR_FBC_CTL_C)));
320
Nico Huber83693c82016-10-08 22:17:55 +0200321end HW.GFX.GMA.Pipe_Setup;