blob: 1315c781f8a4e16ba4a09b1d26b1484c49906d59 [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
6-- the Free Software Foundation; version 2 of the License.
7--
8-- This program is distributed in the hope that it will be useful,
9-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11-- GNU General Public License for more details.
12--
13
14with HW.Debug;
15with GNAT.Source_Info;
16
17with HW.GFX.GMA.Config;
18with HW.GFX.GMA.DP_Info;
19with HW.GFX.GMA.Registers;
20
21use type HW.Word64;
22use type HW.Pos16;
23use type HW.Int32;
24use type HW.GFX.GMA.Registers.Registers_Invalid_Index;
25
26package body HW.GFX.GMA.Pipe_Setup is
27
28 DSPCNTR_ENABLE : constant := 1 * 2 ** 31;
29 DSPCNTR_GAMMA_CORRECTION : constant := 1 * 2 ** 30;
30 DSPCNTR_DISABLE_TRICKLE_FEED : constant := 1 * 2 ** 14;
31 DSPCNTR_FORMAT_MASK : constant := 15 * 2 ** 26;
32
33 DSPCNTR_MASK : constant Word32 :=
34 DSPCNTR_ENABLE or
35 DSPCNTR_GAMMA_CORRECTION or
36 DSPCNTR_FORMAT_MASK or
37 DSPCNTR_DISABLE_TRICKLE_FEED;
38
39 PLANE_CTL_PLANE_ENABLE : constant := 1 * 2 ** 31;
40 PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 : constant := 4 * 2 ** 24;
41 PLANE_CTL_PLANE_GAMMA_DISABLE : constant := 1 * 2 ** 13;
42
43 PLANE_WM_ENABLE : constant := 1 * 2 ** 31;
44 PLANE_WM_LINES_SHIFT : constant := 14;
45 PLANE_WM_LINES_MASK : constant := 16#001f# * 2 ** 14;
46 PLANE_WM_BLOCKS_MASK : constant := 16#03ff# * 2 ** 0;
47
48 SPCNTR_ENABLE : constant := 1 * 2 ** 31;
49
50 TRANS_CLK_SEL_PORT_NONE : constant := 0 * 2 ** 29;
51
52 type TRANS_CLK_SEL_PORT_Array is
53 array (Digital_Port) of Word32;
54 TRANS_CLK_SEL_PORT : constant TRANS_CLK_SEL_PORT_Array :=
55 TRANS_CLK_SEL_PORT_Array'
56 (DIGI_A => 0 * 2 ** 29, -- DDI A is not selectable
57 DIGI_B => 2 * 2 ** 29,
58 DIGI_C => 3 * 2 ** 29,
59 DIGI_D => 4 * 2 ** 29,
60 DIGI_E => 5 * 2 ** 29);
61
62 PIPECONF_ENABLE : constant := 1 * 2 ** 31;
63 PIPECONF_ENABLED_STATUS : constant := 1 * 2 ** 30;
64 PIPECONF_ENABLE_DITHER : constant := 1 * 2 ** 4;
65 PIPECONF_DITHER_TEMPORAL : constant := 1 * 2 ** 2;
66
67 PF_CTL_1_ENABLE : constant Word32 := 1 * 2 ** 31;
68
69 PS_CTRL_ENABLE_SCALER : constant Word32 := 1 * 2 ** 31;
70 PS_CTRL_SCALER_MODE_7X5_EXTENDED : constant Word32 := 1 * 2 ** 28;
71 PS_CTRL_FILTER_SELECT_MEDIUM_2 : constant Word32 := 1 * 2 ** 23;
72
73 PIPE_DDI_FUNC_CTL_ENABLE : constant := 1 * 2 ** 31;
74 PIPE_DDI_FUNC_CTL_DDI_SELECT_MASK : constant := 7 * 2 ** 28;
75 PIPE_DDI_FUNC_CTL_DDI_SELECT_NONE : constant := 0 * 2 ** 28;
76 PIPE_DDI_FUNC_CTL_DDI_SELECT_B : constant := 1 * 2 ** 28;
77 PIPE_DDI_FUNC_CTL_DDI_SELECT_C : constant := 2 * 2 ** 28;
78 PIPE_DDI_FUNC_CTL_DDI_SELECT_D : constant := 3 * 2 ** 28;
79 PIPE_DDI_FUNC_CTL_DDI_SELECT_E : constant := 4 * 2 ** 28;
80 PIPE_DDI_FUNC_CTL_MODE_SELECT_MASK : constant := 7 * 2 ** 24;
81 PIPE_DDI_FUNC_CTL_MODE_SELECT_HDMI : constant := 0 * 2 ** 24;
82 PIPE_DDI_FUNC_CTL_MODE_SELECT_DVI : constant := 1 * 2 ** 24;
83 PIPE_DDI_FUNC_CTL_MODE_SELECT_DP_SST : constant := 2 * 2 ** 24;
84 PIPE_DDI_FUNC_CTL_MODE_SELECT_DP_MST : constant := 3 * 2 ** 24;
85 PIPE_DDI_FUNC_CTL_MODE_SELECT_FDI : constant := 4 * 2 ** 24;
86 PIPE_DDI_FUNC_CTL_BPC_MASK : constant := 7 * 2 ** 20;
87 PIPE_DDI_FUNC_CTL_BPC_8BITS : constant := 0 * 2 ** 20;
88 PIPE_DDI_FUNC_CTL_BPC_10BITS : constant := 1 * 2 ** 20;
89 PIPE_DDI_FUNC_CTL_BPC_6BITS : constant := 2 * 2 ** 20;
90 PIPE_DDI_FUNC_CTL_BPC_12BITS : constant := 3 * 2 ** 20;
91 PIPE_DDI_FUNC_CTL_VSYNC_ACTIVE_LOW : constant := 0 * 2 ** 17;
92 PIPE_DDI_FUNC_CTL_VSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 17;
93 PIPE_DDI_FUNC_CTL_HSYNC_ACTIVE_LOW : constant := 0 * 2 ** 16;
94 PIPE_DDI_FUNC_CTL_HSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 16;
95 PIPE_DDI_FUNC_CTL_EDP_SELECT_MASK : constant := 7 * 2 ** 12;
96 PIPE_DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON : constant := 0 * 2 ** 12;
97 PIPE_DDI_FUNC_CTL_EDP_SELECT_A : constant := 4 * 2 ** 12;
98 PIPE_DDI_FUNC_CTL_EDP_SELECT_B : constant := 5 * 2 ** 12;
99 PIPE_DDI_FUNC_CTL_EDP_SELECT_C : constant := 6 * 2 ** 12;
100 PIPE_DDI_FUNC_CTL_DP_VC_PAYLOAD_ALLOC : constant := 1 * 2 ** 8;
101 PIPE_DDI_FUNC_CTL_BFI_ENABLE : constant := 1 * 2 ** 4;
102 PIPE_DDI_FUNC_CTL_PORT_WIDTH_MASK : constant := 7 * 2 ** 1;
103 PIPE_DDI_FUNC_CTL_PORT_WIDTH_1_LANE : constant := 0 * 2 ** 1;
104 PIPE_DDI_FUNC_CTL_PORT_WIDTH_2_LANES : constant := 1 * 2 ** 1;
105 PIPE_DDI_FUNC_CTL_PORT_WIDTH_4_LANES : constant := 3 * 2 ** 1;
106
107 type DDI_Select_Array is array (Digital_Port) of Word32;
108 PIPE_DDI_FUNC_CTL_DDI_SELECT : constant DDI_Select_Array :=
109 DDI_Select_Array'
110 (DIGI_A => PIPE_DDI_FUNC_CTL_DDI_SELECT_NONE,
111 DIGI_B => PIPE_DDI_FUNC_CTL_DDI_SELECT_B,
112 DIGI_C => PIPE_DDI_FUNC_CTL_DDI_SELECT_C,
113 DIGI_D => PIPE_DDI_FUNC_CTL_DDI_SELECT_D,
114 DIGI_E => PIPE_DDI_FUNC_CTL_DDI_SELECT_E);
115
116 type DDI_Mode_Array is array (Display_Type) of Word32;
117 PIPE_DDI_FUNC_CTL_MODE_SELECT : constant DDI_Mode_Array :=
118 DDI_Mode_Array'
119 (VGA => PIPE_DDI_FUNC_CTL_MODE_SELECT_FDI,
120 HDMI => PIPE_DDI_FUNC_CTL_MODE_SELECT_DVI,
121 DP => PIPE_DDI_FUNC_CTL_MODE_SELECT_DP_SST,
122 others => 0);
123
124 type HV_Sync_Array is array (Boolean) of Word32;
125 PIPE_DDI_FUNC_CTL_VSYNC : constant HV_Sync_Array := HV_Sync_Array'
126 (False => PIPE_DDI_FUNC_CTL_VSYNC_ACTIVE_LOW,
127 True => PIPE_DDI_FUNC_CTL_VSYNC_ACTIVE_HIGH);
128 PIPE_DDI_FUNC_CTL_HSYNC : constant HV_Sync_Array := HV_Sync_Array'
129 (False => PIPE_DDI_FUNC_CTL_HSYNC_ACTIVE_LOW,
130 True => PIPE_DDI_FUNC_CTL_HSYNC_ACTIVE_HIGH);
131
132 type EDP_Select_Array is array (Controller_Kind) of Word32;
133 PIPE_DDI_FUNC_CTL_EDP_SELECT : constant EDP_Select_Array :=
134 EDP_Select_Array'
135 (A => PIPE_DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON, -- we never use panel fitter
136 B => PIPE_DDI_FUNC_CTL_EDP_SELECT_B,
137 C => PIPE_DDI_FUNC_CTL_EDP_SELECT_C);
138 PIPE_DDI_FUNC_CTL_EDP_SELECT_ONOFF : constant EDP_Select_Array :=
139 EDP_Select_Array'
140 (A => PIPE_DDI_FUNC_CTL_EDP_SELECT_A,
141 B => PIPE_DDI_FUNC_CTL_EDP_SELECT_B,
142 C => PIPE_DDI_FUNC_CTL_EDP_SELECT_C);
143
144 type Port_Width_Array is array (HW.GFX.DP_Lane_Count) of Word32;
145 PIPE_DDI_FUNC_CTL_PORT_WIDTH : constant Port_Width_Array :=
146 Port_Width_Array'
147 (HW.GFX.DP_Lane_Count_1 => PIPE_DDI_FUNC_CTL_PORT_WIDTH_1_LANE,
148 HW.GFX.DP_Lane_Count_2 => PIPE_DDI_FUNC_CTL_PORT_WIDTH_2_LANES,
149 HW.GFX.DP_Lane_Count_4 => PIPE_DDI_FUNC_CTL_PORT_WIDTH_4_LANES);
150
151 function PIPE_DDI_FUNC_CTL_BPC (BPC : HW.GFX.BPC_Type) return Word32
152 is
153 Result : Word32;
154 begin
155 case BPC is
156 when 6 => Result := PIPE_DDI_FUNC_CTL_BPC_6BITS;
157 when 8 => Result := PIPE_DDI_FUNC_CTL_BPC_8BITS;
158 when 10 => Result := PIPE_DDI_FUNC_CTL_BPC_10BITS;
159 when 12 => Result := PIPE_DDI_FUNC_CTL_BPC_12BITS;
160 when others => Result := PIPE_DDI_FUNC_CTL_BPC_8BITS;
161 end case;
162 return Result;
163 end PIPE_DDI_FUNC_CTL_BPC;
164
165 function PIPE_DATA_M_TU (Transfer_Unit : Positive) return Word32 is
166 begin
167 return Shift_Left (Word32 (Transfer_Unit - 1), 25);
168 end PIPE_DATA_M_TU;
169
170 PIPE_MSA_MISC_SYNC_CLK : constant := 1 * 2 ** 0;
171 PIPE_MSA_MISC_BPC_6BITS : constant := 0 * 2 ** 5;
172 PIPE_MSA_MISC_BPC_8BITS : constant := 1 * 2 ** 5;
173 PIPE_MSA_MISC_BPC_10BITS : constant := 2 * 2 ** 5;
174 PIPE_MSA_MISC_BPC_12BITS : constant := 3 * 2 ** 5;
175 PIPE_MSA_MISC_BPC_16BITS : constant := 4 * 2 ** 5;
176
177 function PIPE_MSA_MISC_BPC (BPC : HW.GFX.BPC_Type) return Word32 is
178 Result : Word32;
179 begin
180 case BPC is
181 when 6 => Result := PIPE_MSA_MISC_BPC_6BITS;
182 when 8 => Result := PIPE_MSA_MISC_BPC_8BITS;
183 when 10 => Result := PIPE_MSA_MISC_BPC_10BITS;
184 when 12 => Result := PIPE_MSA_MISC_BPC_12BITS;
185 --when 16 => Result := PIPE_MSA_MISC_BPC_16BITS;
186 when others => Result := PIPE_MSA_MISC_BPC_8BITS;
187 end case;
188 return Result;
189 end PIPE_MSA_MISC_BPC;
190
191 ---------------------------------------------------------------------------
192
193 function PIPECONF_BPC_MAP (Bits_Per_Color : HW.GFX.BPC_Type) return Word32
194 is
195 Result : Word32;
196 begin
197 if Bits_Per_Color = 6 then
198 Result := 2 * 2 ** 5;
199 elsif Bits_Per_Color = 10 then
200 Result := 1 * 2 ** 5;
201 elsif Bits_Per_Color = 12 then
202 Result := 3 * 2 ** 5;
203 else
204 Result := 0;
205 end if;
206 return Result;
207 end PIPECONF_BPC_MAP;
208
209 ---------------------------------------------------------------------------
210
211 function PLANE_WM_LINES (Lines : Natural) return Word32 is
212 begin
213 return Shift_Left (Word32 (Lines), PLANE_WM_LINES_SHIFT)
214 and PLANE_WM_LINES_MASK;
215 end PLANE_WM_LINES;
216
217 function PLANE_WM_BLOCKS (Blocks : Natural) return Word32 is
218 begin
219 return Word32 (Blocks) and PLANE_WM_BLOCKS_MASK;
220 end PLANE_WM_BLOCKS;
221
222 ---------------------------------------------------------------------------
223
224 function Encode (LSW, MSW : Pos16) return Word32 is
225 begin
226 return Shift_Left (Word32 (MSW - 1), 16) or Word32 (LSW - 1);
227 end Encode;
228
229 ----------------------------------------------------------------------------
230
231 procedure Setup_Link
232 (Head : Head_Type;
233 Link : DP_Link;
234 Mode : Mode_Type)
235 with
236 Global => (In_Out => Registers.Register_State),
237 Depends => (Registers.Register_State =>+ (Head, Link, Mode))
238 is
239 Data_M, Link_M : DP_Info.M_Type;
240 Data_N, Link_N : DP_Info.N_Type;
241 begin
242 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
243
244 DP_Info.Calculate_M_N
245 (Link => Link,
246 Mode => Mode,
247 Data_M => Data_M,
248 Data_N => Data_N,
249 Link_M => Link_M,
250 Link_N => Link_N);
251
252 Registers.Write
253 (Register => Head.PIPE_DATA_M1,
254 Value => PIPE_DATA_M_TU (64) or
255 Word32 (Data_M));
256 Registers.Write
257 (Register => Head.PIPE_DATA_N1,
258 Value => Word32 (Data_N));
259
260 Registers.Write
261 (Register => Head.PIPE_LINK_M1,
262 Value => Word32 (Link_M));
263 Registers.Write
264 (Register => Head.PIPE_LINK_N1,
265 Value => Word32 (Link_N));
266
267 if Config.Has_Pipe_MSA_Misc then
268 Registers.Write
269 (Register => Head.PIPE_MSA_MISC,
270 Value => PIPE_MSA_MISC_SYNC_CLK or
271 PIPE_MSA_MISC_BPC (Mode.BPC));
272 end if;
273 end Setup_Link;
274
275 ----------------------------------------------------------------------------
276
277 procedure Clear_Watermarks (Controller : Controller_Type) is
278 begin
279 Registers.Write
280 (Register => Controller.PLANE_BUF_CFG,
281 Value => 16#0000_0000#);
282 for Level in WM_Levels range 0 .. WM_Levels'Last loop
283 Registers.Write
284 (Register => Controller.PLANE_WM (Level),
285 Value => 16#0000_0000#);
286 end loop;
287 Registers.Write
288 (Register => Controller.WM_LINETIME,
289 Value => 16#0000_0000#);
290 end Clear_Watermarks;
291
292 procedure Setup_Watermarks (Controller : Controller_Type)
293 is
294 type Per_Plane_Buffer_Range is array (Controller_Kind) of Word32;
295 Buffer_Range : constant Per_Plane_Buffer_Range := Per_Plane_Buffer_Range'
296 (A => Shift_Left (159, 16) or 0,
297 B => Shift_Left (319, 16) or 160,
298 C => Shift_Left (479, 16) or 320);
299 begin
300 Registers.Write
301 (Register => Controller.PLANE_BUF_CFG,
302 Value => Buffer_Range (Controller.Kind));
303 Registers.Write
304 (Register => Controller.PLANE_WM (0),
305 Value => PLANE_WM_ENABLE or
306 PLANE_WM_LINES (2) or
307 PLANE_WM_BLOCKS (160));
308 end Setup_Watermarks;
309
310 ----------------------------------------------------------------------------
311
312 procedure Setup_Display
313 (Controller : in Controller_Type;
314 Head : in Head_Type;
315 Mode : in HW.GFX.Mode_Type;
316 Framebuffer : in HW.GFX.Framebuffer_Type)
317 with
318 Global => (In_Out => Registers.Register_State),
319 Depends =>
320 (Registers.Register_State
321 =>+
322 (Registers.Register_State,
323 Controller,
324 Head,
325 Mode,
326 Framebuffer))
327 is
328 -- FIXME: setup correct format, based on framebuffer RGB format
329 Format : constant Word32 := 6 * 2 ** 26;
330 PRI : Word32 := DSPCNTR_ENABLE or Format;
331
332 function To_Bytes (Pixels : Width_Type) return Word32
333 with
334 Pre => (Word32 (Pixels) <= Word32'Last / 4 / Word32 (BPC_Type'Last) * 8)
335 is
336 begin
337 return Word32 (Pos64 (Pixels) * 4 * Framebuffer.BPC / 8);
338 end To_Bytes;
339 begin
340 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
341
342 Registers.Write (Controller.PIPESRC, Encode (Mode.V_Visible, Mode.H_Visible));
343
344 if Config.Has_Plane_Control then
345 Setup_Watermarks (Controller);
346 Registers.Write
347 (Register => Controller.PLANE_CTL,
348 Value => PLANE_CTL_PLANE_ENABLE or
349 PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 or
350 PLANE_CTL_PLANE_GAMMA_DISABLE);
351 Registers.Write (Controller.PLANE_OFFSET, 16#0000_0000#);
352 Registers.Write (Controller.PLANE_SIZE, Encode (Mode.H_Visible, Mode.V_Visible));
353 Registers.Write (Controller.PLANE_STRIDE, To_Bytes (Framebuffer.Stride) / 64);
354 Registers.Write (Controller.PLANE_POS, 16#0000_0000#);
355 Registers.Write (Controller.PLANE_SURF, Framebuffer.Offset and 16#ffff_f000#);
356 else
357 if Config.Disable_Trickle_Feed then
358 PRI := PRI or DSPCNTR_DISABLE_TRICKLE_FEED;
359 end if;
360 -- for now, just disable gamma LUT (can't do anything
361 -- useful without colorimetry information from display)
362 Registers.Unset_And_Set_Mask
363 (Register => Controller.DSPCNTR,
364 Mask_Unset => DSPCNTR_MASK,
365 Mask_Set => PRI);
366
367 Registers.Write (Controller.DSPSTRIDE, To_Bytes (Framebuffer.Stride));
368 Registers.Write (Controller.DSPSURF, Framebuffer.Offset and 16#ffff_f000#);
369 if Config.Has_DSP_Linoff then
370 Registers.Write (Controller.DSPLINOFF, 0);
371 end if;
372 Registers.Write (Controller.DSPTILEOFF, 0);
373 end if;
374
375 Registers.Write (Head.HTOTAL, Encode (Mode.H_Visible, Mode.H_Total));
376 Registers.Write (Head.HBLANK, Encode (Mode.H_Visible, Mode.H_Total));
377 Registers.Write (Head.HSYNC, Encode (Mode.H_Sync_Begin, Mode.H_Sync_End));
378 Registers.Write (Head.VTOTAL, Encode (Mode.V_Visible, Mode.V_Total));
379 Registers.Write (Head.VBLANK, Encode (Mode.V_Visible, Mode.V_Total));
380 Registers.Write (Head.VSYNC, Encode (Mode.V_Sync_Begin, Mode.V_Sync_End));
381 end Setup_Display;
382
383 ----------------------------------------------------------------------------
384
385 procedure Setup_Head
386 (Controller : Controller_Type;
387 Head : Head_Type;
388 Port_Cfg : Port_Config;
389 Framebuffer : Framebuffer_Type)
390 is
391 PIPECONF_Options : Word32 := 0;
392 begin
393 if Config.Has_Pipe_DDI_Func then
394 Registers.Write
395 (Register => Head.PIPE_DDI_FUNC_CTL,
396 Value => PIPE_DDI_FUNC_CTL_ENABLE or
397 PIPE_DDI_FUNC_CTL_DDI_SELECT (Port_Cfg.Port) or
398 PIPE_DDI_FUNC_CTL_MODE_SELECT (Port_Cfg.Display) or
399 PIPE_DDI_FUNC_CTL_BPC (Port_Cfg.Mode.BPC) or
400 PIPE_DDI_FUNC_CTL_VSYNC (Port_Cfg.Mode.V_Sync_Active_High) or
401 PIPE_DDI_FUNC_CTL_HSYNC (Port_Cfg.Mode.H_Sync_Active_High) or
402 PIPE_DDI_FUNC_CTL_EDP_SELECT (Controller.Kind) or
403 PIPE_DDI_FUNC_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count));
404 end if;
405
406 if Config.Has_Pipeconf_BPC then
407 PIPECONF_Options := PIPECONF_BPC_MAP (Port_Cfg.Mode.BPC);
408 end if;
409
410 -- Enable dithering if framebuffer BPC differs from connector BPC,
411 -- as smooth gradients look really bad without
412 if Framebuffer.BPC /= Port_Cfg.Mode.BPC then
413 PIPECONF_Options := PIPECONF_Options or PIPECONF_ENABLE_DITHER;
414 end if;
415
416 if not Config.Has_Pipeconf_Misc then
417 Registers.Write
418 (Register => Head.PIPECONF,
419 Value => PIPECONF_ENABLE or PIPECONF_Options);
420 else
421 Registers.Write
422 (Register => Controller.PIPEMISC,
423 Value => PIPECONF_Options);
424 Registers.Write
425 (Register => Head.PIPECONF,
426 Value => PIPECONF_ENABLE);
427 end if;
428 Registers.Posting_Read (Head.PIPECONF);
429 end Setup_Head;
430
431 ----------------------------------------------------------------------------
432
433 procedure On
434 (Controller : Controller_Type;
435 Head : Head_Type;
436 Port_Cfg : Port_Config;
437 Framebuffer : Framebuffer_Type)
438 is
439 begin
440 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
441
442 if Config.Has_Trans_Clk_Sel then
443 Registers.Write
444 (Register => Controller.TRANS_CLK_SEL,
445 Value => TRANS_CLK_SEL_PORT (Port_Cfg.Port));
446 end if;
447
448 if Port_Cfg.Is_FDI then
449 Setup_Link (Head, Port_Cfg.FDI, Port_Cfg.Mode);
450 elsif Port_Cfg.Display = DP then
451 Setup_Link (Head, Port_Cfg.DP, Port_Cfg.Mode);
452 end if;
453
454 Setup_Display (Controller, Head, Port_Cfg.Mode, Framebuffer);
455
456 Setup_Head (Controller, Head, Port_Cfg, Framebuffer);
457 end On;
458
459 ----------------------------------------------------------------------------
460
461 procedure Planes_Off (Controller : Controller_Type) is
462 begin
463 Registers.Unset_Mask (Controller.SPCNTR, SPCNTR_ENABLE);
464 if Config.Has_Plane_Control then
465 Clear_Watermarks (Controller);
466 Registers.Unset_Mask (Controller.PLANE_CTL, PLANE_CTL_PLANE_ENABLE);
467 Registers.Write (Controller.PLANE_SURF, 16#0000_0000#);
468 else
469 Registers.Unset_Mask (Controller.DSPCNTR, DSPCNTR_ENABLE);
470 end if;
471 end Planes_Off;
472
473 procedure Head_Off (Head : Head_Type)
474 is
475 Enabled : Boolean;
476 begin
477 Registers.Is_Set_Mask (Head.PIPECONF, PIPECONF_ENABLE, Enabled);
478
479 if Enabled then
480 Registers.Unset_Mask (Head.PIPECONF, PIPECONF_ENABLE);
481 end if;
482
483 -- Workaround for Broadwell:
484 -- Status may be wrong if pipe hasn't been enabled since reset.
485 if not Config.Pipe_Enabled_Workaround or else Enabled then
486 -- synchronously wait until pipe is truly off
487 Registers.Wait_Unset_Mask
488 (Register => Head.PIPECONF,
489 Mask => PIPECONF_ENABLED_STATUS,
490 TOut_MS => 40);
491 end if;
492
493 if Config.Has_Pipe_DDI_Func then
494 Registers.Write (Head.PIPE_DDI_FUNC_CTL, 0);
495 end if;
496 end Head_Off;
497
498 procedure Panel_Fitter_Off (Controller : Controller_Type) is
499 begin
500 -- Writes to WIN_SZ arm the PS/PF registers.
501 if Config.Has_Plane_Control then
502 Registers.Unset_Mask (Controller.PS_CTRL_1, PS_CTRL_ENABLE_SCALER);
503 Registers.Write (Controller.PS_WIN_SZ_1, 16#0000_0000#);
504 if Controller.PS_CTRL_2 /= Registers.Invalid_Register and
505 Controller.PS_WIN_SZ_2 /= Registers.Invalid_Register
506 then
507 Registers.Unset_Mask (Controller.PS_CTRL_2, PS_CTRL_ENABLE_SCALER);
508 Registers.Write (Controller.PS_WIN_SZ_2, 16#0000_0000#);
509 end if;
510 else
511 Registers.Unset_Mask (Controller.PF_CTL_1, PF_CTL_1_ENABLE);
512 Registers.Write (Controller.PF_WIN_SZ, 16#0000_0000#);
513 end if;
514 end Panel_Fitter_Off;
515
516 procedure Trans_Clk_Off (Controller : Controller_Type) is
517 begin
518 if Config.Has_Trans_Clk_Sel then
519 Registers.Write (Controller.TRANS_CLK_SEL, TRANS_CLK_SEL_PORT_NONE);
520 end if;
521 end Trans_Clk_Off;
522
523 procedure Off (Controller : Controller_Type; Head : Head_Type) is
524 begin
525 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
526
527 Planes_Off (Controller);
528 Head_Off (Head);
529 Panel_Fitter_Off (Controller);
530 Trans_Clk_Off (Controller);
531 end Off;
532
533 procedure All_Off
534 is
535 EDP_Enabled, EDP_Piped : Boolean;
536
537 procedure EDP_Piped_To (Kind : Controller_Kind; Piped_To : out Boolean)
538 is
539 Pipe_DDI_Func_Ctl : Word32;
540 begin
541 Registers.Read (Registers.PIPE_EDP_DDI_FUNC_CTL, Pipe_DDI_Func_Ctl);
542 Pipe_DDI_Func_Ctl :=
543 Pipe_DDI_Func_Ctl and PIPE_DDI_FUNC_CTL_EDP_SELECT_MASK;
544
545 Piped_To := (Kind = A and Pipe_DDI_Func_Ctl = PIPE_DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON) or
546 Pipe_DDI_Func_Ctl = PIPE_DDI_FUNC_CTL_EDP_SELECT_ONOFF (Kind);
547 end EDP_Piped_To;
548 begin
549 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
550
551 if Config.Has_EDP_Pipe then
552 Registers.Is_Set_Mask
553 (Registers.PIPE_EDP_CONF, PIPECONF_ENABLE, EDP_Enabled);
554 else
555 EDP_Enabled := False;
556 end if;
557
558 for Kind in Controller_Kind loop
559 Planes_Off (Controllers (Kind));
560 if EDP_Enabled then
561 EDP_Piped_To (Kind, EDP_Piped);
562 if EDP_Piped then
563 Head_Off (Heads (Head_EDP));
564 EDP_Enabled := False;
565 end if;
566 end if;
567 Head_Off (Default_Pipe_Head (Kind));
568 Panel_Fitter_Off (Controllers (Kind));
569 Trans_Clk_Off (Controllers (Kind));
570 end loop;
571
572 if EDP_Enabled then
573 Head_Off (Heads (Head_EDP));
574 end if;
575 end All_Off;
576
577 ----------------------------------------------------------------------------
578
579 procedure Update_Offset
580 (Controller : Controller_Type;
581 Framebuffer : HW.GFX.Framebuffer_Type) is
582 begin
583 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
584
585 Registers.Write (Controller.DSPSURF, Framebuffer.Offset and 16#ffff_f000#);
586 end Update_Offset;
587
588 ----------------------------------------------------------------------------
589
590 function Get_Pipe_Hint (Head : Head_Type) return Word32
591 is
592 type Pipe_Hint_Array is array (Pipe_Head) of Word32;
593 Pipe_Hint : constant Pipe_Hint_Array := Pipe_Hint_Array'
594 (Head_EDP => 0, Head_A => 0, Head_B => 1, Head_C => 2);
595 begin
596 return Pipe_Hint (Head.Head);
597 end Get_Pipe_Hint;
598
599 ----------------------------------------------------------------------------
600
601 function Default_Pipe_Head (Kind : Controller_Kind) return Head_Type
602 is
603 type Default_Head_Array is array (Controller_Kind) of Head_Type;
604 Default_Head : constant Default_Head_Array := Default_Head_Array'
605 (A => Heads (Head_A), B => Heads (Head_B), C => Heads (Head_C));
606 begin
607 return Default_Head (Kind);
608 end Default_Pipe_Head;
609
610end HW.GFX.GMA.Pipe_Setup;