Fixed potential issues to release resources when error occurs.
[mirror_edk2.git] / OptionRomPkg / CirrusLogic5430Dxe / CirrusLogic5430.c
1 /** @file
2 Cirrus Logic 5430 Controller Driver.
3 This driver is a sample implementation of the UGA Draw and Graphics Output
4 Protocols for the Cirrus Logic 5430 family of PCI video controllers.
5 This driver is only usable in the EFI pre-boot environment.
6 This sample is intended to show how the UGA Draw and Graphics output Protocol
7 is able to function.
8 The UGA I/O Protocol is not implemented in this sample.
9 A fully compliant EFI UGA driver requires both
10 the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's
11 documentation on UGA for details on how to write a UGA driver that is able
12 to function both in the EFI pre-boot environment and from the OS runtime.
13
14 Copyright (c) 2006, Intel Corporation
15 All rights reserved. This program and the accompanying materials
16 are licensed and made available under the terms and conditions of the BSD License
17 which accompanies this distribution. The full text of the license may be found at
18 http://opensource.org/licenses/bsd-license.php
19
20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
21 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22
23 **/
24
25 //
26 // Cirrus Logic 5430 Controller Driver
27 //
28 #include "CirrusLogic5430.h"
29
30 EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding = {
31 CirrusLogic5430ControllerDriverSupported,
32 CirrusLogic5430ControllerDriverStart,
33 CirrusLogic5430ControllerDriverStop,
34 0x10,
35 NULL,
36 NULL
37 };
38
39 ///
40 /// Generic Attribute Controller Register Settings
41 ///
42 UINT8 AttributeController[21] = {
43 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
44 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
45 0x41, 0x00, 0x0F, 0x00, 0x00
46 };
47
48 ///
49 /// Generic Graphics Controller Register Settings
50 ///
51 UINT8 GraphicsController[9] = {
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF
53 };
54
55 //
56 // 640 x 480 x 256 color @ 60 Hertz
57 //
58 UINT8 Crtc_640_480_256_60[28] = {
59 0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e,
60 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3,
62 0xff, 0x00, 0x00, 0x22
63 };
64
65 UINT16 Seq_640_480_256_60[15] = {
66 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
67 0x5b0c, 0x450d, 0x7e0e, 0x2b1b, 0x2f1c, 0x301d, 0x331e
68 };
69
70 //
71 // 800 x 600 x 256 color @ 60 Hertz
72 //
73 UINT8 Crtc_800_600_256_60[28] = {
74 0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0,
75 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3,
77 0xFF, 0x00, 0x00, 0x22
78 };
79
80 UINT16 Seq_800_600_256_60[15] = {
81 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
82 0x5b0c, 0x450d, 0x510e, 0x2b1b, 0x2f1c, 0x301d, 0x3a1e
83 };
84
85 //
86 // 1024 x 768 x 256 color @ 60 Hertz
87 //
88 UINT8 Crtc_1024_768_256_60[28] = {
89 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD,
90 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3,
92 0xFF, 0x4A, 0x00, 0x22
93 };
94
95 UINT16 Seq_1024_768_256_60[15] = {
96 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
97 0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e
98 };
99
100 ///
101 /// Table of supported video modes
102 ///
103 CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = {
104 { 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 },
105 { 800, 600, 8, 60, Crtc_800_600_256_60, Seq_800_600_256_60, 0xef },
106 { 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef }
107 };
108
109 /**
110 CirrusLogic5430ControllerDriverSupported
111
112 TODO: This - add argument and description to function comment
113 TODO: Controller - add argument and description to function comment
114 TODO: RemainingDevicePath - add argument and description to function comment
115 **/
116 EFI_STATUS
117 EFIAPI
118 CirrusLogic5430ControllerDriverSupported (
119 IN EFI_DRIVER_BINDING_PROTOCOL *This,
120 IN EFI_HANDLE Controller,
121 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
122 )
123 {
124 EFI_STATUS Status;
125 EFI_PCI_IO_PROTOCOL *PciIo;
126 PCI_TYPE00 Pci;
127
128 //
129 // Open the PCI I/O Protocol
130 //
131 Status = gBS->OpenProtocol (
132 Controller,
133 &gEfiPciIoProtocolGuid,
134 (VOID **) &PciIo,
135 This->DriverBindingHandle,
136 Controller,
137 EFI_OPEN_PROTOCOL_BY_DRIVER
138 );
139 if (EFI_ERROR (Status)) {
140 return Status;
141 }
142
143 //
144 // Read the PCI Configuration Header from the PCI Device
145 //
146 Status = PciIo->Pci.Read (
147 PciIo,
148 EfiPciIoWidthUint32,
149 0,
150 sizeof (Pci) / sizeof (UINT32),
151 &Pci
152 );
153 if (EFI_ERROR (Status)) {
154 goto Done;
155 }
156
157 Status = EFI_UNSUPPORTED;
158 //
159 // See if the I/O enable is on. Most systems only allow one VGA device to be turned on
160 // at a time, so see if this is one that is turned on.
161 //
162 // if (((Pci.Hdr.Command & 0x01) == 0x01)) {
163 //
164 // See if this is a Cirrus Logic PCI controller
165 //
166 if (Pci.Hdr.VendorId == CIRRUS_LOGIC_VENDOR_ID) {
167 //
168 // See if this is a 5430 or a 5446 PCI controller
169 //
170 if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_DEVICE_ID) {
171 Status = EFI_SUCCESS;
172 }
173
174 if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID) {
175 Status = EFI_SUCCESS;
176 }
177
178 if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5446_DEVICE_ID) {
179 Status = EFI_SUCCESS;
180 }
181 }
182
183 Done:
184 //
185 // Close the PCI I/O Protocol
186 //
187 gBS->CloseProtocol (
188 Controller,
189 &gEfiPciIoProtocolGuid,
190 This->DriverBindingHandle,
191 Controller
192 );
193
194 return Status;
195 }
196
197 /**
198 CirrusLogic5430ControllerDriverStart
199
200 TODO: This - add argument and description to function comment
201 TODO: Controller - add argument and description to function comment
202 TODO: RemainingDevicePath - add argument and description to function comment
203 **/
204 EFI_STATUS
205 EFIAPI
206 CirrusLogic5430ControllerDriverStart (
207 IN EFI_DRIVER_BINDING_PROTOCOL *This,
208 IN EFI_HANDLE Controller,
209 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
210 )
211 {
212 EFI_STATUS Status;
213 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
214 BOOLEAN PciAttributesSaved;
215
216 PciAttributesSaved = FALSE;
217 //
218 // Allocate Private context data for UGA Draw inteface.
219 //
220 Private = AllocateZeroPool (sizeof (CIRRUS_LOGIC_5430_PRIVATE_DATA));
221 if (Private == NULL) {
222 Status = EFI_OUT_OF_RESOURCES;
223 goto Error;
224 }
225
226 //
227 // Set up context record
228 //
229 Private->Signature = CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE;
230 Private->Handle = Controller;
231
232 //
233 // Open PCI I/O Protocol
234 //
235 Status = gBS->OpenProtocol (
236 Private->Handle,
237 &gEfiPciIoProtocolGuid,
238 (VOID **) &Private->PciIo,
239 This->DriverBindingHandle,
240 Private->Handle,
241 EFI_OPEN_PROTOCOL_BY_DRIVER
242 );
243 if (EFI_ERROR (Status)) {
244 goto Error;
245 }
246
247 //
248 // Save original PCI attributes
249 //
250 Status = Private->PciIo->Attributes (
251 Private->PciIo,
252 EfiPciIoAttributeOperationGet,
253 0,
254 &Private->OriginalPciAttributes
255 );
256
257 if (EFI_ERROR (Status)) {
258 goto Error;
259 }
260 PciAttributesSaved = TRUE;
261
262 Status = Private->PciIo->Attributes (
263 Private->PciIo,
264 EfiPciIoAttributeOperationEnable,
265 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,
266 NULL
267 );
268 if (EFI_ERROR (Status)) {
269 goto Error;
270 }
271
272 if (FeaturePcdGet (PcdSupportUga)) {
273 //
274 // Start the UGA Draw software stack.
275 //
276 Status = CirrusLogic5430UgaDrawConstructor (Private);
277 ASSERT_EFI_ERROR (Status);
278 if (FeaturePcdGet (PcdSupportGop)) {
279 Status = CirrusLogic5430GraphicsOutputConstructor (Private);
280 ASSERT_EFI_ERROR (Status);
281
282 Status = gBS->InstallMultipleProtocolInterfaces (
283 &Private->Handle,
284 &gEfiUgaDrawProtocolGuid,
285 &Private->UgaDraw,
286 &gEfiGraphicsOutputProtocolGuid,
287 &Private->GraphicsOutput,
288 NULL
289 );
290 } else {
291 Status = gBS->InstallMultipleProtocolInterfaces (
292 &Private->Handle,
293 &gEfiUgaDrawProtocolGuid,
294 &Private->UgaDraw,
295 NULL
296 );
297
298 }
299 } else {
300 if (FeaturePcdGet (PcdSupportGop)) {
301 Status = CirrusLogic5430GraphicsOutputConstructor (Private);
302 ASSERT_EFI_ERROR (Status);
303
304 Status = gBS->InstallMultipleProtocolInterfaces (
305 &Private->Handle,
306 &gEfiGraphicsOutputProtocolGuid,
307 &Private->GraphicsOutput,
308 NULL
309 );
310
311 } else {
312 //
313 // This driver must support eithor GOP or UGA or both.
314 //
315 ASSERT (FALSE);
316 Status = EFI_UNSUPPORTED;
317 }
318 }
319
320
321 Error:
322 if (EFI_ERROR (Status)) {
323 if (Private) {
324 if (Private->PciIo) {
325 if (PciAttributesSaved == TRUE) {
326 //
327 // Restore original PCI attributes
328 //
329 Private->PciIo->Attributes (
330 Private->PciIo,
331 EfiPciIoAttributeOperationSet,
332 Private->OriginalPciAttributes,
333 NULL
334 );
335 }
336 //
337 // Close the PCI I/O Protocol
338 //
339 gBS->CloseProtocol (
340 Private->Handle,
341 &gEfiPciIoProtocolGuid,
342 This->DriverBindingHandle,
343 Private->Handle
344 );
345 }
346
347 gBS->FreePool (Private);
348 }
349 }
350
351 return Status;
352 }
353
354 /**
355 CirrusLogic5430ControllerDriverStop
356
357 TODO: This - add argument and description to function comment
358 TODO: Controller - add argument and description to function comment
359 TODO: NumberOfChildren - add argument and description to function comment
360 TODO: ChildHandleBuffer - add argument and description to function comment
361 TODO: EFI_SUCCESS - add return value to function comment
362 **/
363 EFI_STATUS
364 EFIAPI
365 CirrusLogic5430ControllerDriverStop (
366 IN EFI_DRIVER_BINDING_PROTOCOL *This,
367 IN EFI_HANDLE Controller,
368 IN UINTN NumberOfChildren,
369 IN EFI_HANDLE *ChildHandleBuffer
370 )
371 {
372 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
373 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
374
375 EFI_STATUS Status;
376 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
377
378 if (FeaturePcdGet (PcdSupportUga)) {
379 Status = gBS->OpenProtocol (
380 Controller,
381 &gEfiUgaDrawProtocolGuid,
382 (VOID **) &UgaDraw,
383 This->DriverBindingHandle,
384 Controller,
385 EFI_OPEN_PROTOCOL_GET_PROTOCOL
386 );
387 if (EFI_ERROR (Status)) {
388 return Status;
389 }
390 //
391 // Get our private context information
392 //
393 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw);
394 CirrusLogic5430UgaDrawDestructor (Private);
395
396 if (FeaturePcdGet (PcdSupportGop)) {
397 CirrusLogic5430GraphicsOutputDestructor (Private);
398 //
399 // Remove the UGA and GOP protocol interface from the system
400 //
401 Status = gBS->UninstallMultipleProtocolInterfaces (
402 Private->Handle,
403 &gEfiUgaDrawProtocolGuid,
404 &Private->UgaDraw,
405 &gEfiGraphicsOutputProtocolGuid,
406 &Private->GraphicsOutput,
407 NULL
408 );
409 } else {
410 //
411 // Remove the UGA Draw interface from the system
412 //
413 Status = gBS->UninstallMultipleProtocolInterfaces (
414 Private->Handle,
415 &gEfiUgaDrawProtocolGuid,
416 &Private->UgaDraw,
417 NULL
418 );
419 }
420 } else {
421 Status = gBS->OpenProtocol (
422 Controller,
423 &gEfiGraphicsOutputProtocolGuid,
424 (VOID **) &GraphicsOutput,
425 This->DriverBindingHandle,
426 Controller,
427 EFI_OPEN_PROTOCOL_GET_PROTOCOL
428 );
429 if (EFI_ERROR (Status)) {
430 return Status;
431 }
432
433 //
434 // Get our private context information
435 //
436 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);
437
438 CirrusLogic5430GraphicsOutputDestructor (Private);
439 //
440 // Remove the GOP protocol interface from the system
441 //
442 Status = gBS->UninstallMultipleProtocolInterfaces (
443 Private->Handle,
444 &gEfiUgaDrawProtocolGuid,
445 &Private->UgaDraw,
446 &gEfiGraphicsOutputProtocolGuid,
447 &Private->GraphicsOutput,
448 NULL
449 );
450 }
451
452 if (EFI_ERROR (Status)) {
453 return Status;
454 }
455
456 //
457 // Restore original PCI attributes
458 //
459 Private->PciIo->Attributes (
460 Private->PciIo,
461 EfiPciIoAttributeOperationSet,
462 Private->OriginalPciAttributes,
463 NULL
464 );
465
466 //
467 // Close the PCI I/O Protocol
468 //
469 gBS->CloseProtocol (
470 Controller,
471 &gEfiPciIoProtocolGuid,
472 This->DriverBindingHandle,
473 Controller
474 );
475
476 //
477 // Free our instance data
478 //
479 gBS->FreePool (Private);
480
481 return EFI_SUCCESS;
482 }
483
484 /**
485 CirrusLogic5430UgaDrawDestructor
486
487 TODO: Private - add argument and description to function comment
488 TODO: EFI_SUCCESS - add return value to function comment
489 **/
490 EFI_STATUS
491 CirrusLogic5430UgaDrawDestructor (
492 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
493 )
494 {
495 return EFI_SUCCESS;
496 }
497
498 /**
499 TODO: Add function description
500
501 @param Private TODO: add argument description
502 @param Address TODO: add argument description
503 @param Data TODO: add argument description
504
505 TODO: add return values
506
507 **/
508 VOID
509 outb (
510 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
511 UINTN Address,
512 UINT8 Data
513 )
514 {
515 Private->PciIo->Io.Write (
516 Private->PciIo,
517 EfiPciIoWidthUint8,
518 EFI_PCI_IO_PASS_THROUGH_BAR,
519 Address,
520 1,
521 &Data
522 );
523 }
524
525 /**
526 TODO: Add function description
527
528 @param Private TODO: add argument description
529 @param Address TODO: add argument description
530 @param Data TODO: add argument description
531
532 TODO: add return values
533
534 **/
535 VOID
536 outw (
537 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
538 UINTN Address,
539 UINT16 Data
540 )
541 {
542 Private->PciIo->Io.Write (
543 Private->PciIo,
544 EfiPciIoWidthUint16,
545 EFI_PCI_IO_PASS_THROUGH_BAR,
546 Address,
547 1,
548 &Data
549 );
550 }
551
552 /**
553 TODO: Add function description
554
555 @param Private TODO: add argument description
556 @param Address TODO: add argument description
557
558 TODO: add return values
559
560 **/
561 UINT8
562 inb (
563 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
564 UINTN Address
565 )
566 {
567 UINT8 Data;
568
569 Private->PciIo->Io.Read (
570 Private->PciIo,
571 EfiPciIoWidthUint8,
572 EFI_PCI_IO_PASS_THROUGH_BAR,
573 Address,
574 1,
575 &Data
576 );
577 return Data;
578 }
579
580 /**
581 TODO: Add function description
582
583 @param Private TODO: add argument description
584 @param Address TODO: add argument description
585
586 TODO: add return values
587
588 **/
589 UINT16
590 inw (
591 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
592 UINTN Address
593 )
594 {
595 UINT16 Data;
596
597 Private->PciIo->Io.Read (
598 Private->PciIo,
599 EfiPciIoWidthUint16,
600 EFI_PCI_IO_PASS_THROUGH_BAR,
601 Address,
602 1,
603 &Data
604 );
605 return Data;
606 }
607
608 /**
609 TODO: Add function description
610
611 @param Private TODO: add argument description
612 @param Index TODO: add argument description
613 @param Red TODO: add argument description
614 @param Green TODO: add argument description
615 @param Blue TODO: add argument description
616
617 TODO: add return values
618
619 **/
620 VOID
621 SetPaletteColor (
622 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
623 UINTN Index,
624 UINT8 Red,
625 UINT8 Green,
626 UINT8 Blue
627 )
628 {
629 outb (Private, PALETTE_INDEX_REGISTER, (UINT8) Index);
630 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));
631 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));
632 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));
633 }
634
635 /**
636 TODO: Add function description
637
638 @param Private TODO: add argument description
639
640 TODO: add return values
641
642 **/
643 VOID
644 SetDefaultPalette (
645 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
646 )
647 {
648 UINTN Index;
649 UINTN RedIndex;
650 UINTN GreenIndex;
651 UINTN BlueIndex;
652
653 Index = 0;
654 for (RedIndex = 0; RedIndex < 8; RedIndex++) {
655 for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {
656 for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {
657 SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));
658 Index++;
659 }
660 }
661 }
662 }
663
664 /**
665 TODO: Add function description
666
667 @param Private TODO: add argument description
668
669 TODO: add return values
670
671 **/
672 STATIC
673 VOID
674 ClearScreen (
675 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
676 )
677 {
678 UINT32 Color;
679
680 Color = 0;
681 Private->PciIo->Mem.Write (
682 Private->PciIo,
683 EfiPciIoWidthFillUint32,
684 0,
685 0,
686 0x100000 >> 2,
687 &Color
688 );
689 }
690
691 /**
692 TODO: Add function description
693
694 @param Private TODO: add argument description
695
696 TODO: add return values
697
698 **/
699 VOID
700 DrawLogo (
701 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
702 UINTN ScreenWidth,
703 UINTN ScreenHeight
704 )
705 {
706 UINTN Offset;
707 UINTN X;
708 UINTN Y;
709 UINT8 Color;
710
711 Offset = 0;
712 for (Y = 0; Y < ScreenHeight; Y++) {
713 for (X = 0; X < ScreenWidth; X++) {
714 Color = (UINT8) (256 * (X + Y) / (ScreenWidth + ScreenHeight));
715 Private->LineBuffer[X] = Color;
716 }
717
718 Private->PciIo->Mem.Write (
719 Private->PciIo,
720 EfiPciIoWidthUint32,
721 0,
722 Offset + (Y * ScreenWidth),
723 ScreenWidth >> 2,
724 Private->LineBuffer
725 );
726 }
727 }
728
729 /**
730 TODO: Add function description
731
732 @param Private TODO: add argument description
733 @param ModeData TODO: add argument description
734
735 TODO: add return values
736
737 **/
738 VOID
739 InitializeGraphicsMode (
740 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
741 CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData
742 )
743 {
744 UINT8 Byte;
745 UINTN Index;
746
747 outw (Private, SEQ_ADDRESS_REGISTER, 0x1206);
748 outw (Private, SEQ_ADDRESS_REGISTER, 0x0012);
749
750 for (Index = 0; Index < 15; Index++) {
751 outw (Private, SEQ_ADDRESS_REGISTER, ModeData->SeqSettings[Index]);
752 }
753
754 outb (Private, SEQ_ADDRESS_REGISTER, 0x0f);
755 Byte = (UINT8) ((inb (Private, SEQ_DATA_REGISTER) & 0xc7) ^ 0x30);
756 outb (Private, SEQ_DATA_REGISTER, Byte);
757
758 outb (Private, MISC_OUTPUT_REGISTER, ModeData->MiscSetting);
759 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0506);
760 outw (Private, SEQ_ADDRESS_REGISTER, 0x0300);
761 outw (Private, CRTC_ADDRESS_REGISTER, 0x2011);
762
763 for (Index = 0; Index < 28; Index++) {
764 outw (Private, CRTC_ADDRESS_REGISTER, (UINT16) ((ModeData->CrtcSettings[Index] << 8) | Index));
765 }
766
767 for (Index = 0; Index < 9; Index++) {
768 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((GraphicsController[Index] << 8) | Index));
769 }
770
771 inb (Private, INPUT_STATUS_1_REGISTER);
772
773 for (Index = 0; Index < 21; Index++) {
774 outb (Private, ATT_ADDRESS_REGISTER, (UINT8) Index);
775 outb (Private, ATT_ADDRESS_REGISTER, AttributeController[Index]);
776 }
777
778 outb (Private, ATT_ADDRESS_REGISTER, 0x20);
779
780 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0009);
781 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000a);
782 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000b);
783 outb (Private, DAC_PIXEL_MASK_REGISTER, 0xff);
784
785 SetDefaultPalette (Private);
786 ClearScreen (Private);
787 }
788
789 EFI_STATUS
790 EFIAPI
791 InitializeCirrusLogic5430 (
792 IN EFI_HANDLE ImageHandle,
793 IN EFI_SYSTEM_TABLE *SystemTable
794 )
795 {
796 EFI_STATUS Status;
797
798 Status = EfiLibInstallDriverBindingComponentName2 (
799 ImageHandle,
800 SystemTable,
801 &gCirrusLogic5430DriverBinding,
802 ImageHandle,
803 &gCirrusLogic5430ComponentName,
804 &gCirrusLogic5430ComponentName2
805 );
806 ASSERT_EFI_ERROR (Status);
807
808 //
809 // Install EFI Driver Supported EFI Version Protocol required for
810 // EFI drivers that are on PCI and other plug in cards.
811 //
812 gCirrusLogic5430DriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion);
813 Status = gBS->InstallMultipleProtocolInterfaces (
814 &ImageHandle,
815 &gEfiDriverSupportedEfiVersionProtocolGuid,
816 &gCirrusLogic5430DriverSupportedEfiVersion,
817 NULL
818 );
819 ASSERT_EFI_ERROR (Status);
820
821 return Status;
822 }