]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Bus/Pci/CirrusLogic/Dxe/CirrusLogic5430UgaDraw.c
Add some definitions for efi event in Uefi/UefiSpec.h to follow spec.
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / CirrusLogic / Dxe / CirrusLogic5430UgaDraw.c
1 /** @file
2 This file produces the graphics abstration of UGA Draw. It is called by
3 CirrusLogic5430.c file which deals with the EFI 1.1 driver model.
4 This file just does graphics.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #include "CirrusLogic5430.h"
18
19 STATIC
20 VOID
21 ClearScreen (
22 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
23 );
24
25 ///
26 /// Generic Attribute Controller Register Settings
27 ///
28 static UINT8 AttributeController[21] = {
29 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
30 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
31 0x41, 0x00, 0x0F, 0x00, 0x00
32 };
33
34 ///
35 /// Generic Graphics Controller Register Settings
36 ///
37 static UINT8 GraphicsController[9] = {
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF
39 };
40
41 //
42 // 640 x 480 x 256 color @ 60 Hertz
43 //
44 static UINT8 Crtc_640_480_256_60[28] = {
45 0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e,
46 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3,
48 0xff, 0x00, 0x00, 0x22
49 };
50
51 static UINT16 Seq_640_480_256_60[15] = {
52 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
53 0x5b0c, 0x450d, 0x7e0e, 0x2b1b, 0x2f1c, 0x301d, 0x331e
54 };
55
56 //
57 // 800 x 600 x 256 color @ 60 Hertz
58 //
59 static UINT8 Crtc_800_600_256_60[28] = {
60 0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0,
61 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3,
63 0xFF, 0x00, 0x00, 0x22
64 };
65
66 static UINT16 Seq_800_600_256_60[15] = {
67 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
68 0x5b0c, 0x450d, 0x510e, 0x2b1b, 0x2f1c, 0x301d, 0x3a1e
69 };
70
71 //
72 // 1024 x 768 x 256 color @ 60 Hertz
73 //
74 static UINT8 Crtc_1024_768_256_60[28] = {
75 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD,
76 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3,
78 0xFF, 0x4A, 0x00, 0x22
79 };
80
81 static UINT16 Seq_1024_768_256_60[15] = {
82 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
83 0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e
84 };
85
86 ///
87 /// Table of supported video modes
88 ///
89 static CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = {
90 { 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 },
91 { 800, 600, 8, 60, Crtc_800_600_256_60, Seq_800_600_256_60, 0xef },
92 { 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef }
93 };
94
95 //
96 // UGA Draw Protocol Member Functions
97 //
98 /**
99 TODO: Add function description
100
101 @param This TODO: add argument description
102 @param HorizontalResolution TODO: add argument description
103 @param VerticalResolution TODO: add argument description
104 @param ColorDepth TODO: add argument description
105 @param RefreshRate TODO: add argument description
106
107 @retval EFI_NOT_STARTED TODO: Add description for return value
108 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
109 @retval EFI_SUCCESS TODO: Add description for return value
110
111 **/
112 STATIC
113 EFI_STATUS
114 EFIAPI
115 CirrusLogic5430UgaDrawGetMode (
116 IN EFI_UGA_DRAW_PROTOCOL *This,
117 OUT UINT32 *HorizontalResolution,
118 OUT UINT32 *VerticalResolution,
119 OUT UINT32 *ColorDepth,
120 OUT UINT32 *RefreshRate
121 )
122 {
123 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
124
125 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);
126
127 if (Private->HardwareNeedsStarting) {
128 return EFI_NOT_STARTED;
129 }
130
131 if ((HorizontalResolution == NULL) ||
132 (VerticalResolution == NULL) ||
133 (ColorDepth == NULL) ||
134 (RefreshRate == NULL)) {
135 return EFI_INVALID_PARAMETER;
136 }
137
138 *HorizontalResolution = Private->ModeData[Private->CurrentMode].HorizontalResolution;
139 *VerticalResolution = Private->ModeData[Private->CurrentMode].VerticalResolution;
140 *ColorDepth = Private->ModeData[Private->CurrentMode].ColorDepth;
141 *RefreshRate = Private->ModeData[Private->CurrentMode].RefreshRate;
142
143 return EFI_SUCCESS;
144 }
145
146 /**
147 TODO: Add function description
148
149 @param This TODO: add argument description
150 @param HorizontalResolution TODO: add argument description
151 @param VerticalResolution TODO: add argument description
152 @param ColorDepth TODO: add argument description
153 @param RefreshRate TODO: add argument description
154
155 @retval EFI_OUT_OF_RESOURCES TODO: Add description for return value
156 @retval EFI_SUCCESS TODO: Add description for return value
157 @retval EFI_NOT_FOUND TODO: Add description for return value
158
159 **/
160 STATIC
161 EFI_STATUS
162 EFIAPI
163 CirrusLogic5430UgaDrawSetMode (
164 IN EFI_UGA_DRAW_PROTOCOL *This,
165 IN UINT32 HorizontalResolution,
166 IN UINT32 VerticalResolution,
167 IN UINT32 ColorDepth,
168 IN UINT32 RefreshRate
169 )
170 {
171 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
172 UINTN Index;
173
174 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);
175
176 for (Index = 0; Index < Private->MaxMode; Index++) {
177
178 if (HorizontalResolution != Private->ModeData[Index].HorizontalResolution) {
179 continue;
180 }
181
182 if (VerticalResolution != Private->ModeData[Index].VerticalResolution) {
183 continue;
184 }
185
186 if (ColorDepth != Private->ModeData[Index].ColorDepth) {
187 continue;
188 }
189
190 if (RefreshRate != Private->ModeData[Index].RefreshRate) {
191 continue;
192 }
193
194 if (Private->LineBuffer) {
195 gBS->FreePool (Private->LineBuffer);
196 }
197
198 Private->LineBuffer = NULL;
199 Private->LineBuffer = AllocatePool (HorizontalResolution);
200 if (Private->LineBuffer == NULL) {
201 return EFI_OUT_OF_RESOURCES;
202 }
203
204 InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[Index]);
205
206 Private->CurrentMode = Index;
207
208 Private->HardwareNeedsStarting = FALSE;
209
210 return EFI_SUCCESS;
211 }
212
213 return EFI_NOT_FOUND;
214 }
215
216 /**
217 TODO: Add function description
218
219 @param This TODO: add argument description
220 @param BltBuffer TODO: add argument description
221 @param BltOperation TODO: add argument description
222 @param SourceX TODO: add argument description
223 @param SourceY TODO: add argument description
224 @param DestinationX TODO: add argument description
225 @param DestinationY TODO: add argument description
226 @param Width TODO: add argument description
227 @param Height TODO: add argument description
228 @param Delta TODO: add argument description
229
230 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
231 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
232 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
233 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
234 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
235 @retval EFI_INVALID_PARAMETER TODO: Add description for return value
236 @retval EFI_SUCCESS TODO: Add description for return value
237
238 **/
239 STATIC
240 EFI_STATUS
241 EFIAPI
242 CirrusLogic5430UgaDrawBlt (
243 IN EFI_UGA_DRAW_PROTOCOL *This,
244 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
245 IN EFI_UGA_BLT_OPERATION BltOperation,
246 IN UINTN SourceX,
247 IN UINTN SourceY,
248 IN UINTN DestinationX,
249 IN UINTN DestinationY,
250 IN UINTN Width,
251 IN UINTN Height,
252 IN UINTN Delta
253 )
254 {
255 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
256 EFI_TPL OriginalTPL;
257 UINTN DstY;
258 UINTN SrcY;
259 EFI_UGA_PIXEL *Blt;
260 UINTN X;
261 UINT8 Pixel;
262 UINT32 WidePixel;
263 UINTN ScreenWidth;
264 UINTN Offset;
265 UINTN SourceOffset;
266
267 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);
268
269 if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) {
270 return EFI_INVALID_PARAMETER;
271 }
272
273 if (Width == 0 || Height == 0) {
274 return EFI_INVALID_PARAMETER;
275 }
276
277 //
278 // If Delta is zero, then the entire BltBuffer is being used, so Delta
279 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
280 // the number of bytes in each row can be computed.
281 //
282 if (Delta == 0) {
283 Delta = Width * sizeof (EFI_UGA_PIXEL);
284 }
285
286 //
287 // We need to fill the Virtual Screen buffer with the blt data.
288 // The virtual screen is upside down, as the first row is the bootom row of
289 // the image.
290 //
291
292 //
293 // Make sure the SourceX, SourceY, DestinationX, DestinationY, Width, and Height parameters
294 // are valid for the operation and the current screen geometry.
295 //
296 if (BltOperation == EfiUgaVideoToBltBuffer) {
297 //
298 // Video to BltBuffer: Source is Video, destination is BltBuffer
299 //
300 if (SourceY + Height > Private->ModeData[Private->CurrentMode].VerticalResolution) {
301 return EFI_INVALID_PARAMETER;
302 }
303
304 if (SourceX + Width > Private->ModeData[Private->CurrentMode].HorizontalResolution) {
305 return EFI_INVALID_PARAMETER;
306 }
307 } else {
308 //
309 // BltBuffer to Video: Source is BltBuffer, destination is Video
310 //
311 if (DestinationY + Height > Private->ModeData[Private->CurrentMode].VerticalResolution) {
312 return EFI_INVALID_PARAMETER;
313 }
314
315 if (DestinationX + Width > Private->ModeData[Private->CurrentMode].HorizontalResolution) {
316 return EFI_INVALID_PARAMETER;
317 }
318 }
319 //
320 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
321 // We would not want a timer based event (Cursor, ...) to come in while we are
322 // doing this operation.
323 //
324 OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
325
326 switch (BltOperation) {
327 case EfiUgaVideoToBltBuffer:
328 //
329 // Video to BltBuffer: Source is Video, destination is BltBuffer
330 //
331 for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {
332
333 Offset = (SrcY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + SourceX;
334 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
335 Private->PciIo->Mem.Read (
336 Private->PciIo,
337 EfiPciIoWidthUint32,
338 0,
339 Offset,
340 Width >> 2,
341 Private->LineBuffer
342 );
343 } else {
344 Private->PciIo->Mem.Read (
345 Private->PciIo,
346 EfiPciIoWidthUint8,
347 0,
348 Offset,
349 Width,
350 Private->LineBuffer
351 );
352 }
353
354 for (X = 0; X < Width; X++) {
355 Blt = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_UGA_PIXEL));
356
357 Blt->Red = (UINT8) (Private->LineBuffer[X] & 0xe0);
358 Blt->Green = (UINT8) ((Private->LineBuffer[X] & 0x1c) << 3);
359 Blt->Blue = (UINT8) ((Private->LineBuffer[X] & 0x03) << 6);
360 }
361 }
362 break;
363
364 case EfiUgaVideoToVideo:
365 //
366 // Perform hardware acceleration for Video to Video operations
367 //
368 ScreenWidth = Private->ModeData[Private->CurrentMode].HorizontalResolution;
369 SourceOffset = (SourceY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + (SourceX);
370 Offset = (DestinationY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + (DestinationX);
371
372 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0000);
373 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0010);
374 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0012);
375 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0014);
376
377 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0001);
378 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0011);
379 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0013);
380 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0015);
381
382 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Width << 8) & 0xff00) | 0x20));
383 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Width & 0xff00) | 0x21));
384 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Height << 8) & 0xff00) | 0x22));
385 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Height & 0xff00) | 0x23));
386 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x24));
387 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x25));
388 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x26));
389 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x27));
390 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) << 8) & 0xff00) | 0x28));
391 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 0) & 0xff00) | 0x29));
392 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 8) & 0xff00) | 0x2a));
393 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) << 8) & 0xff00) | 0x2c));
394 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 0) & 0xff00) | 0x2d));
395 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 8) & 0xff00) | 0x2e));
396 outw (Private, GRAPH_ADDRESS_REGISTER, 0x002f);
397 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0030);
398 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0d32);
399 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0033);
400 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0034);
401 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0035);
402
403 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0231);
404
405 outb (Private, GRAPH_ADDRESS_REGISTER, 0x31);
406 while ((inb (Private, GRAPH_DATA_REGISTER) & 0x01) == 0x01)
407 ;
408 break;
409
410 case EfiUgaVideoFill:
411 Blt = BltBuffer;
412 Pixel = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));
413 WidePixel = (Pixel << 8) | Pixel;
414 WidePixel = (WidePixel << 16) | WidePixel;
415
416 if (DestinationX == 0 && Width == Private->ModeData[Private->CurrentMode].HorizontalResolution) {
417 Offset = DestinationY * Private->ModeData[Private->CurrentMode].HorizontalResolution;
418 if (((Offset & 0x03) == 0) && (((Width * Height) & 0x03) == 0)) {
419 Private->PciIo->Mem.Write (
420 Private->PciIo,
421 EfiPciIoWidthFillUint32,
422 0,
423 Offset,
424 (Width * Height) >> 2,
425 &WidePixel
426 );
427 } else {
428 Private->PciIo->Mem.Write (
429 Private->PciIo,
430 EfiPciIoWidthFillUint8,
431 0,
432 Offset,
433 Width * Height,
434 &Pixel
435 );
436 }
437 } else {
438 for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
439 Offset = (DstY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + DestinationX;
440 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
441 Private->PciIo->Mem.Write (
442 Private->PciIo,
443 EfiPciIoWidthFillUint32,
444 0,
445 Offset,
446 Width >> 2,
447 &WidePixel
448 );
449 } else {
450 Private->PciIo->Mem.Write (
451 Private->PciIo,
452 EfiPciIoWidthFillUint8,
453 0,
454 Offset,
455 Width,
456 &Pixel
457 );
458 }
459 }
460 }
461 break;
462
463 case EfiUgaBltBufferToVideo:
464 for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
465
466 for (X = 0; X < Width; X++) {
467 Blt = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + (SrcY * Delta) + (SourceX + X) * sizeof (EFI_UGA_PIXEL));
468 Private->LineBuffer[X] = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));
469 }
470
471 Offset = (DstY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + DestinationX;
472
473 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
474 Private->PciIo->Mem.Write (
475 Private->PciIo,
476 EfiPciIoWidthUint32,
477 0,
478 Offset,
479 Width >> 2,
480 Private->LineBuffer
481 );
482 } else {
483 Private->PciIo->Mem.Write (
484 Private->PciIo,
485 EfiPciIoWidthUint8,
486 0,
487 Offset,
488 Width,
489 Private->LineBuffer
490 );
491 }
492 }
493 break;
494
495 default:
496 break;
497 }
498
499 gBS->RestoreTPL (OriginalTPL);
500
501 return EFI_SUCCESS;
502 }
503
504 //
505 // Construction and Destruction functions
506 //
507
508 /**
509 CirrusLogic5430UgaDrawConstructor
510
511 TODO: Private - add argument and description to function comment
512 TODO: EFI_SUCCESS - add return value to function comment
513 **/
514 EFI_STATUS
515 CirrusLogic5430UgaDrawConstructor (
516 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
517 )
518 {
519 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
520 UINTN Index;
521
522 //
523 // Fill in Private->UgaDraw protocol
524 //
525 UgaDraw = &Private->UgaDraw;
526
527 UgaDraw->GetMode = CirrusLogic5430UgaDrawGetMode;
528 UgaDraw->SetMode = CirrusLogic5430UgaDrawSetMode;
529 UgaDraw->Blt = CirrusLogic5430UgaDrawBlt;
530
531 //
532 // Initialize the private data
533 //
534 Private->MaxMode = CIRRUS_LOGIC_5430_UGA_DRAW_MODE_COUNT;
535 Private->CurrentMode = 0;
536 for (Index = 0; Index < Private->MaxMode; Index++) {
537 Private->ModeData[Index].HorizontalResolution = CirrusLogic5430VideoModes[Index].Width;
538 Private->ModeData[Index].VerticalResolution = CirrusLogic5430VideoModes[Index].Height;
539 Private->ModeData[Index].ColorDepth = 32;
540 Private->ModeData[Index].RefreshRate = CirrusLogic5430VideoModes[Index].RefreshRate;
541 }
542
543 Private->HardwareNeedsStarting = TRUE;
544 Private->LineBuffer = NULL;
545
546 //
547 // Initialize the hardware
548 //
549 UgaDraw->SetMode (
550 UgaDraw,
551 Private->ModeData[Private->CurrentMode].HorizontalResolution,
552 Private->ModeData[Private->CurrentMode].VerticalResolution,
553 Private->ModeData[Private->CurrentMode].ColorDepth,
554 Private->ModeData[Private->CurrentMode].RefreshRate
555 );
556 DrawLogo (Private);
557
558 return EFI_SUCCESS;
559 }
560
561 /**
562 CirrusLogic5430UgaDrawDestructor
563
564 TODO: Private - add argument and description to function comment
565 TODO: EFI_SUCCESS - add return value to function comment
566 **/
567 EFI_STATUS
568 CirrusLogic5430UgaDrawDestructor (
569 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
570 )
571 {
572 return EFI_SUCCESS;
573 }
574
575 /**
576 TODO: Add function description
577
578 @param Private TODO: add argument description
579 @param Address TODO: add argument description
580 @param Data TODO: add argument description
581
582 TODO: add return values
583
584 **/
585 VOID
586 outb (
587 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
588 UINTN Address,
589 UINT8 Data
590 )
591 {
592 Private->PciIo->Io.Write (
593 Private->PciIo,
594 EfiPciIoWidthUint8,
595 EFI_PCI_IO_PASS_THROUGH_BAR,
596 Address,
597 1,
598 &Data
599 );
600 }
601
602 /**
603 TODO: Add function description
604
605 @param Private TODO: add argument description
606 @param Address TODO: add argument description
607 @param Data TODO: add argument description
608
609 TODO: add return values
610
611 **/
612 VOID
613 outw (
614 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
615 UINTN Address,
616 UINT16 Data
617 )
618 {
619 Private->PciIo->Io.Write (
620 Private->PciIo,
621 EfiPciIoWidthUint16,
622 EFI_PCI_IO_PASS_THROUGH_BAR,
623 Address,
624 1,
625 &Data
626 );
627 }
628
629 /**
630 TODO: Add function description
631
632 @param Private TODO: add argument description
633 @param Address TODO: add argument description
634
635 TODO: add return values
636
637 **/
638 UINT8
639 inb (
640 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
641 UINTN Address
642 )
643 {
644 UINT8 Data;
645
646 Private->PciIo->Io.Read (
647 Private->PciIo,
648 EfiPciIoWidthUint8,
649 EFI_PCI_IO_PASS_THROUGH_BAR,
650 Address,
651 1,
652 &Data
653 );
654 return Data;
655 }
656
657 /**
658 TODO: Add function description
659
660 @param Private TODO: add argument description
661 @param Address TODO: add argument description
662
663 TODO: add return values
664
665 **/
666 UINT16
667 inw (
668 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
669 UINTN Address
670 )
671 {
672 UINT16 Data;
673
674 Private->PciIo->Io.Read (
675 Private->PciIo,
676 EfiPciIoWidthUint16,
677 EFI_PCI_IO_PASS_THROUGH_BAR,
678 Address,
679 1,
680 &Data
681 );
682 return Data;
683 }
684
685 /**
686 TODO: Add function description
687
688 @param Private TODO: add argument description
689 @param Index TODO: add argument description
690 @param Red TODO: add argument description
691 @param Green TODO: add argument description
692 @param Blue TODO: add argument description
693
694 TODO: add return values
695
696 **/
697 VOID
698 SetPaletteColor (
699 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
700 UINTN Index,
701 UINT8 Red,
702 UINT8 Green,
703 UINT8 Blue
704 )
705 {
706 outb (Private, PALETTE_INDEX_REGISTER, (UINT8) Index);
707 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));
708 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));
709 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));
710 }
711
712 /**
713 TODO: Add function description
714
715 @param Private TODO: add argument description
716
717 TODO: add return values
718
719 **/
720 VOID
721 SetDefaultPalette (
722 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
723 )
724 {
725 UINTN Index;
726 UINTN RedIndex;
727 UINTN GreenIndex;
728 UINTN BlueIndex;
729
730 Index = 0;
731 for (RedIndex = 0; RedIndex < 8; RedIndex++) {
732 for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {
733 for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {
734 SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));
735 Index++;
736 }
737 }
738 }
739 }
740
741 /**
742 TODO: Add function description
743
744 @param Private TODO: add argument description
745
746 TODO: add return values
747
748 **/
749 STATIC
750 VOID
751 ClearScreen (
752 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
753 )
754 {
755 UINT32 Color;
756
757 Color = 0;
758 Private->PciIo->Mem.Write (
759 Private->PciIo,
760 EfiPciIoWidthFillUint32,
761 0,
762 0,
763 0x100000 >> 2,
764 &Color
765 );
766 }
767
768 /**
769 TODO: Add function description
770
771 @param Private TODO: add argument description
772
773 TODO: add return values
774
775 **/
776 VOID
777 DrawLogo (
778 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
779 )
780 {
781 UINTN Offset;
782 UINTN X;
783 UINTN Y;
784 UINTN ScreenWidth;
785 UINTN ScreenHeight;
786 UINT8 Color;
787
788 ScreenWidth = Private->ModeData[Private->CurrentMode].HorizontalResolution;
789 ScreenHeight = Private->ModeData[Private->CurrentMode].VerticalResolution;
790
791 Offset = 0;
792 for (Y = 0; Y < ScreenHeight; Y++) {
793 for (X = 0; X < ScreenWidth; X++) {
794 Color = (UINT8) (256 * (X + Y) / (ScreenWidth + ScreenHeight));
795 Private->LineBuffer[X] = Color;
796 }
797
798 Private->PciIo->Mem.Write (
799 Private->PciIo,
800 EfiPciIoWidthUint32,
801 0,
802 Offset + (Y * ScreenWidth),
803 ScreenWidth >> 2,
804 Private->LineBuffer
805 );
806 }
807 }
808
809 /**
810 TODO: Add function description
811
812 @param Private TODO: add argument description
813 @param ModeData TODO: add argument description
814
815 TODO: add return values
816
817 **/
818 VOID
819 InitializeGraphicsMode (
820 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
821 CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData
822 )
823 {
824 UINT8 Byte;
825 UINTN Index;
826
827 outw (Private, SEQ_ADDRESS_REGISTER, 0x1206);
828 outw (Private, SEQ_ADDRESS_REGISTER, 0x0012);
829
830 for (Index = 0; Index < 15; Index++) {
831 outw (Private, SEQ_ADDRESS_REGISTER, ModeData->SeqSettings[Index]);
832 }
833
834 outb (Private, SEQ_ADDRESS_REGISTER, 0x0f);
835 Byte = (UINT8) ((inb (Private, SEQ_DATA_REGISTER) & 0xc7) ^ 0x30);
836 outb (Private, SEQ_DATA_REGISTER, Byte);
837
838 outb (Private, MISC_OUTPUT_REGISTER, ModeData->MiscSetting);
839 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0506);
840 outw (Private, SEQ_ADDRESS_REGISTER, 0x0300);
841 outw (Private, CRTC_ADDRESS_REGISTER, 0x2011);
842
843 for (Index = 0; Index < 28; Index++) {
844 outw (Private, CRTC_ADDRESS_REGISTER, (UINT16) ((ModeData->CrtcSettings[Index] << 8) | Index));
845 }
846
847 for (Index = 0; Index < 9; Index++) {
848 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((GraphicsController[Index] << 8) | Index));
849 }
850
851 inb (Private, INPUT_STATUS_1_REGISTER);
852
853 for (Index = 0; Index < 21; Index++) {
854 outb (Private, ATT_ADDRESS_REGISTER, (UINT8) Index);
855 outb (Private, ATT_ADDRESS_REGISTER, AttributeController[Index]);
856 }
857
858 outb (Private, ATT_ADDRESS_REGISTER, 0x20);
859
860 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0009);
861 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000a);
862 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000b);
863 outb (Private, DAC_PIXEL_MASK_REGISTER, 0xff);
864
865 SetDefaultPalette (Private);
866 ClearScreen (Private);
867 }