TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmMaliDp.c
Go to the documentation of this file.
1
11#include <Library/DebugLib.h>
12#include <Library/IoLib.h>
13#include <Library/LcdHwLib.h>
16
17#include "ArmMaliDp.h"
18
19// CORE_ID of the MALI DP
20STATIC UINT32 mDpDeviceId;
21
27VOID
29 VOID
30 )
31{
32 MmioAnd32 (DP_BASE + DP_DE_LG_CONTROL, ~DP_DE_LG_ENABLE);
33}
34
40VOID
42 VOID
43 )
44{
45 MmioOr32 (DP_BASE + DP_DE_LG_CONTROL, DP_DE_LG_ENABLE);
46}
47
54VOID
56 IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress
57 )
58{
59 // Disable the graphics layer.
61
62 // Set up memory address of the data buffer for graphics layer.
63 // write lower bits of the address.
65 DP_BASE + DP_DE_LG_PTR_LOW,
66 DP_DE_LG_PTR_LOW_MASK & FrameBaseAddress
67 );
68
69 // Write higher bits of the address.
71 DP_BASE + DP_DE_LG_PTR_HIGH,
72 (UINT32)(FrameBaseAddress >> DP_DE_LG_PTR_HIGH_SHIFT)
73 );
74
75 // Enable the graphics layer.
77}
78
89VOID
91 IN CONST EFI_GRAPHICS_PIXEL_FORMAT UefiGfxPixelFormat,
92 IN CONST UINT32 HRes,
93 IN CONST UINT32 VRes
94 )
95{
96 UINT32 PixelFormat;
97
98 // Disable the graphics layer before configuring any settings.
100
101 // Setup graphics layer size.
102 MmioWrite32 (DP_BASE + DP_DE_LG_IN_SIZE, FRAME_IN_SIZE (HRes, VRes));
103
104 // Setup graphics layer composition size.
105 MmioWrite32 (DP_BASE + DP_DE_LG_CMP_SIZE, FRAME_CMP_SIZE (HRes, VRes));
106
107 // Setup memory stride (total visible pixels on a line * 4).
108 MmioWrite32 (DP_BASE + DP_DE_LG_H_STRIDE, (HRes * sizeof (UINT32)));
109
110 // Set the format.
111
112 // In PixelBlueGreenRedReserved8BitPerColor format, byte 0 represents blue,
113 // byte 1 represents green, byte 2 represents red, and byte 3 is reserved
114 // which is equivalent to XRGB format of the DP500/DP550/DP650. Whereas
115 // PixelRedGreenBlueReserved8BitPerColor is equivalent to XBGR of the
116 // DP500/DP550/DP650.
117 if (UefiGfxPixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
118 PixelFormat = (mDpDeviceId == MALIDP_500) ? DP_PIXEL_FORMAT_DP500_XRGB_8888
119 : DP_PIXEL_FORMAT_XRGB_8888;
120 } else {
121 PixelFormat = (mDpDeviceId == MALIDP_500) ? DP_PIXEL_FORMAT_DP500_XBGR_8888
122 : DP_PIXEL_FORMAT_XBGR_8888;
123 }
124
125 MmioWrite32 (DP_BASE + DP_DE_LG_FORMAT, PixelFormat);
126
127 // Enable graphics layer.
129}
130
138STATIC
139VOID
141 IN CONST SCAN_TIMINGS *CONST Horizontal,
142 IN CONST SCAN_TIMINGS *CONST Vertical
143 )
144{
145 UINTN RegHIntervals;
146 UINTN RegVIntervals;
147 UINTN RegSyncControl;
148 UINTN RegHVActiveSize;
149
150 if (mDpDeviceId == MALIDP_500) {
151 // MALI DP500 timing registers.
152 RegHIntervals = DP_BASE + DP_DE_DP500_H_INTERVALS;
153 RegVIntervals = DP_BASE + DP_DE_DP500_V_INTERVALS;
154 RegSyncControl = DP_BASE + DP_DE_DP500_SYNC_CONTROL;
155 RegHVActiveSize = DP_BASE + DP_DE_DP500_HV_ACTIVESIZE;
156 } else {
157 // MALI DP550/DP650 timing registers.
158 RegHIntervals = DP_BASE + DP_DE_H_INTERVALS;
159 RegVIntervals = DP_BASE + DP_DE_V_INTERVALS;
160 RegSyncControl = DP_BASE + DP_DE_SYNC_CONTROL;
161 RegHVActiveSize = DP_BASE + DP_DE_HV_ACTIVESIZE;
162 }
163
164 // Horizontal back porch and front porch.
166 RegHIntervals,
167 H_INTERVALS (Horizontal->FrontPorch, Horizontal->BackPorch)
168 );
169
170 // Vertical back porch and front porch.
172 RegVIntervals,
173 V_INTERVALS (Vertical->FrontPorch, Vertical->BackPorch)
174 );
175
176 // Sync control, Horizontal and Vertical sync.
178 RegSyncControl,
179 SYNC_WIDTH (Horizontal->Sync, Vertical->Sync)
180 );
181
182 // Set up Horizontal and Vertical area size.
184 RegHVActiveSize,
185 HV_ACTIVE (Horizontal->Resolution, Vertical->Resolution)
186 );
187}
188
196STATIC
197UINT32
199 )
200{
201 UINT32 DpCoreId;
202
203 // First check for DP500 as register offset for DP550/DP650 CORE_ID
204 // is beyond 3K/4K register space of the DP500.
205 DpCoreId = MmioRead32 (DP_BASE + DP_DE_DP500_CORE_ID);
206 DpCoreId >>= DP_DE_DP500_CORE_ID_SHIFT;
207
208 if (DpCoreId == MALIDP_500) {
209 return DpCoreId;
210 }
211
212 // Check for DP550 or DP650.
213 DpCoreId = MmioRead32 (DP_BASE + DP_DC_CORE_ID);
214 DpCoreId >>= DP_DC_CORE_ID_SHIFT;
215
216 if ((DpCoreId == MALIDP_550) || (DpCoreId == MALIDP_650)) {
217 return DpCoreId;
218 }
219
220 return MALIDP_NOT_PRESENT;
221}
222
235 VOID
236 )
237{
238 DEBUG ((
239 DEBUG_WARN,
240 "Probing ARM Mali DP500/DP550/DP650 at base address 0x%p\n",
241 DP_BASE
242 ));
243
244 if (mDpDeviceId == 0) {
245 mDpDeviceId = ArmMaliDpGetCoreId ();
246 }
247
248 if (mDpDeviceId == MALIDP_NOT_PRESENT) {
249 DEBUG ((DEBUG_WARN, "ARM Mali DP not found...\n"));
250 return EFI_NOT_FOUND;
251 }
252
253 DEBUG ((DEBUG_WARN, "Found ARM Mali DP %x\n", mDpDeviceId));
254 return EFI_SUCCESS;
255}
256
266 IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress
267 )
268{
269 DEBUG ((DEBUG_WARN, "Framebuffer base address = %p\n", FrameBaseAddress));
270
271 if (mDpDeviceId == 0) {
272 mDpDeviceId = ArmMaliDpGetCoreId ();
273 }
274
275 if (mDpDeviceId == MALIDP_NOT_PRESENT) {
276 DEBUG ((
277 DEBUG_ERROR,
278 "ARM Mali DP initialization failed,"
279 "no ARM Mali DP present\n"
280 ));
281 return EFI_NOT_FOUND;
282 }
283
284 // We are using graphics layer of the Mali DP as a main framebuffer.
285 LayerGraphicsSetFrame (FrameBaseAddress);
286
287 return EFI_SUCCESS;
288}
289
296STATIC
297VOID
299 VOID
300 )
301{
302 // Request configuration Mode.
303 if (mDpDeviceId == MALIDP_500) {
304 MmioOr32 (DP_BASE + DP_DE_DP500_CONTROL, DP_DE_DP500_CONTROL_CONFIG_REQ);
305 } else {
306 MmioOr32 (DP_BASE + DP_DC_CONTROL, DP_DC_CONTROL_CM_ACTIVE);
307 }
308}
309
316STATIC
317VOID
319 VOID
320 )
321{
322 // Disable configuration Mode.
323 if (mDpDeviceId == MALIDP_500) {
324 MmioAnd32 (DP_BASE + DP_DE_DP500_CONTROL, ~DP_DE_DP500_CONTROL_CONFIG_REQ);
325 } else {
326 MmioAnd32 (DP_BASE + DP_DC_CONTROL, ~DP_DC_CONTROL_CM_ACTIVE);
327 }
328}
329
336STATIC
337VOID
339 VOID
340 )
341{
342 if (mDpDeviceId == MALIDP_500) {
343 MmioOr32 (DP_BASE + DP_DP500_CONFIG_VALID, DP_DC_CONFIG_VALID);
344 } else {
345 MmioOr32 (DP_BASE + DP_DC_CONFIG_VALID, DP_DC_CONFIG_VALID);
346 }
347}
348
358 IN CONST UINT32 ModeNumber
359 )
360{
361 EFI_STATUS Status;
362 SCAN_TIMINGS *Horizontal;
363 SCAN_TIMINGS *Vertical;
364
366
367 // Get the display mode timings and other relevant information.
368 Status = LcdPlatformGetTimings (
369 ModeNumber,
370 &Horizontal,
371 &Vertical
372 );
373 if (EFI_ERROR (Status)) {
374 ASSERT_EFI_ERROR (Status);
375 return Status;
376 }
377
378 ASSERT (Horizontal != NULL);
379 ASSERT (Vertical != NULL);
380
381 // Get the pixel format information.
382 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
383 if (EFI_ERROR (Status)) {
384 ASSERT_EFI_ERROR (Status);
385 return Status;
386 }
387
388 // Request configuration mode.
390
391 // Configure the graphics layer.
393 ModeInfo.PixelFormat,
394 Horizontal->Resolution,
395 Vertical->Resolution
396 );
397
398 // Set the display engine timings.
399 SetDisplayEngineTiming (Horizontal, Vertical);
400
401 // After configuration, set Mali DP in normal mode.
402 SetNormalMode ();
403
404 // Any parameters written to the display engine are not activated until
405 // CONFIG_VALID is set.
407
408 return EFI_SUCCESS;
409}
410
414VOID
416 VOID
417 )
418{
419 // Disable graphics layer.
421}
UINT64 UINTN
EFI_STATUS LcdInitialize(IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress)
Definition: ArmMaliDp.c:265
STATIC VOID SetConfigurationMode(VOID)
Definition: ArmMaliDp.c:298
STATIC VOID LayerGraphicsConfig(IN CONST EFI_GRAPHICS_PIXEL_FORMAT UefiGfxPixelFormat, IN CONST UINT32 HRes, IN CONST UINT32 VRes)
Definition: ArmMaliDp.c:90
STATIC VOID SetDisplayEngineTiming(IN CONST SCAN_TIMINGS *CONST Horizontal, IN CONST SCAN_TIMINGS *CONST Vertical)
Definition: ArmMaliDp.c:140
STATIC VOID SetNormalMode(VOID)
Definition: ArmMaliDp.c:318
VOID LcdShutdown(VOID)
Definition: ArmMaliDp.c:415
STATIC VOID LayerGraphicsEnable(VOID)
Definition: ArmMaliDp.c:41
STATIC VOID LayerGraphicsSetFrame(IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress)
Definition: ArmMaliDp.c:55
STATIC VOID SetConfigValid(VOID)
Definition: ArmMaliDp.c:338
EFI_STATUS LcdIdentify(VOID)
Definition: ArmMaliDp.c:234
STATIC UINT32 ArmMaliDpGetCoreId()
Definition: ArmMaliDp.c:198
EFI_STATUS LcdSetMode(IN CONST UINT32 ModeNumber)
Definition: ArmMaliDp.c:357
STATIC VOID LayerGraphicsDisable(VOID)
Definition: ArmMaliDp.c:28
UINT32 EFIAPI MmioAnd32(IN UINTN Address, IN UINT32 AndData)
Definition: IoHighLevel.c:1814
UINT32 EFIAPI MmioOr32(IN UINTN Address, IN UINT32 OrData)
Definition: IoHighLevel.c:1785
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
EFI_STATUS LcdPlatformQueryMode(IN UINT32 ModeNumber, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info)
EFI_STATUS LcdPlatformGetTimings(IN UINT32 ModeNumber, OUT SCAN_TIMINGS **Horizontal, OUT SCAN_TIMINGS **Vertical)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_GRAPHICS_PIXEL_FORMAT
@ PixelBlueGreenRedReserved8BitPerColor
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat