]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c
Move SmmLib from IntelFrameworkPkg to MdePkg because this library is useful to both...
[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 - 2009, 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 /**
111 CirrusLogic5430ControllerDriverSupported
112
113 TODO: This - add argument and description to function comment
114 TODO: Controller - add argument and description to function comment
115 TODO: RemainingDevicePath - add argument and description to function comment
116 **/
117 EFI_STATUS
118 EFIAPI
119 CirrusLogic5430ControllerDriverSupported (
120 IN EFI_DRIVER_BINDING_PROTOCOL *This,
121 IN EFI_HANDLE Controller,
122 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
123 )
124 {
125 EFI_STATUS Status;
126 EFI_PCI_IO_PROTOCOL *PciIo;
127 PCI_TYPE00 Pci;
128 EFI_DEV_PATH *Node;
129
130 //
131 // Open the PCI I/O Protocol
132 //
133 Status = gBS->OpenProtocol (
134 Controller,
135 &gEfiPciIoProtocolGuid,
136 (VOID **) &PciIo,
137 This->DriverBindingHandle,
138 Controller,
139 EFI_OPEN_PROTOCOL_BY_DRIVER
140 );
141 if (EFI_ERROR (Status)) {
142 return Status;
143 }
144
145 //
146 // Read the PCI Configuration Header from the PCI Device
147 //
148 Status = PciIo->Pci.Read (
149 PciIo,
150 EfiPciIoWidthUint32,
151 0,
152 sizeof (Pci) / sizeof (UINT32),
153 &Pci
154 );
155 if (EFI_ERROR (Status)) {
156 goto Done;
157 }
158
159 Status = EFI_UNSUPPORTED;
160 //
161 // See if the I/O enable is on. Most systems only allow one VGA device to be turned on
162 // at a time, so see if this is one that is turned on.
163 //
164 // if (((Pci.Hdr.Command & 0x01) == 0x01)) {
165 //
166 // See if this is a Cirrus Logic PCI controller
167 //
168 if (Pci.Hdr.VendorId == CIRRUS_LOGIC_VENDOR_ID) {
169 //
170 // See if this is a 5430 or a 5446 PCI controller
171 //
172 if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_DEVICE_ID ||
173 Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID ||
174 Pci.Hdr.DeviceId == CIRRUS_LOGIC_5446_DEVICE_ID) {
175
176 Status = EFI_SUCCESS;
177 //
178 // If this is an Intel 945 graphics controller,
179 // go further check RemainingDevicePath validation
180 //
181 if (RemainingDevicePath != NULL) {
182 Node = (EFI_DEV_PATH *) RemainingDevicePath;
183 //
184 // Check if RemainingDevicePath is the End of Device Path Node,
185 // if yes, return EFI_SUCCESS
186 //
187 if (!IsDevicePathEnd (Node)) {
188 //
189 // If RemainingDevicePath isn't the End of Device Path Node,
190 // check its validation
191 //
192 if (Node->DevPath.Type != ACPI_DEVICE_PATH ||
193 Node->DevPath.SubType != ACPI_ADR_DP ||
194 DevicePathNodeLength(&Node->DevPath) != sizeof(ACPI_ADR_DEVICE_PATH)) {
195 Status = EFI_UNSUPPORTED;
196 }
197 }
198 }
199 }
200 }
201
202 Done:
203 //
204 // Close the PCI I/O Protocol
205 //
206 gBS->CloseProtocol (
207 Controller,
208 &gEfiPciIoProtocolGuid,
209 This->DriverBindingHandle,
210 Controller
211 );
212
213 return Status;
214 }
215
216 /**
217 CirrusLogic5430ControllerDriverStart
218
219 TODO: This - add argument and description to function comment
220 TODO: Controller - add argument and description to function comment
221 TODO: RemainingDevicePath - add argument and description to function comment
222 **/
223 EFI_STATUS
224 EFIAPI
225 CirrusLogic5430ControllerDriverStart (
226 IN EFI_DRIVER_BINDING_PROTOCOL *This,
227 IN EFI_HANDLE Controller,
228 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
229 )
230 {
231 EFI_STATUS Status;
232 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
233 BOOLEAN PciAttributesSaved;
234 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
235 ACPI_ADR_DEVICE_PATH AcpiDeviceNode;
236
237 PciAttributesSaved = FALSE;
238 //
239 // Allocate Private context data for UGA Draw inteface.
240 //
241 Private = AllocateZeroPool (sizeof (CIRRUS_LOGIC_5430_PRIVATE_DATA));
242 if (Private == NULL) {
243 Status = EFI_OUT_OF_RESOURCES;
244 goto Error;
245 }
246
247 //
248 // Set up context record
249 //
250 Private->Signature = CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE;
251 Private->Handle = NULL;
252
253 //
254 // Open PCI I/O Protocol
255 //
256 Status = gBS->OpenProtocol (
257 Controller,
258 &gEfiPciIoProtocolGuid,
259 (VOID **) &Private->PciIo,
260 This->DriverBindingHandle,
261 Controller,
262 EFI_OPEN_PROTOCOL_BY_DRIVER
263 );
264 if (EFI_ERROR (Status)) {
265 goto Error;
266 }
267
268 //
269 // Save original PCI attributes
270 //
271 Status = Private->PciIo->Attributes (
272 Private->PciIo,
273 EfiPciIoAttributeOperationGet,
274 0,
275 &Private->OriginalPciAttributes
276 );
277
278 if (EFI_ERROR (Status)) {
279 goto Error;
280 }
281 PciAttributesSaved = TRUE;
282
283 Status = Private->PciIo->Attributes (
284 Private->PciIo,
285 EfiPciIoAttributeOperationEnable,
286 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,
287 NULL
288 );
289 if (EFI_ERROR (Status)) {
290 goto Error;
291 }
292
293 //
294 // Get ParentDevicePath
295 //
296 Status = gBS->HandleProtocol (
297 Controller,
298 &gEfiDevicePathProtocolGuid,
299 (VOID **) &ParentDevicePath
300 );
301 if (EFI_ERROR (Status)) {
302 goto Error;
303 }
304
305 if (FeaturePcdGet (PcdSupportGop)) {
306 //
307 // Set Gop Device Path
308 //
309 if (RemainingDevicePath == NULL) {
310 ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));
311 AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
312 AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
313 AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);
314 SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));
315
316 Private->GopDevicePath = AppendDevicePathNode (
317 ParentDevicePath,
318 (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode
319 );
320 } else if (!IsDevicePathEnd (RemainingDevicePath)) {
321 //
322 // If RemainingDevicePath isn't the End of Device Path Node,
323 // only scan the specified device by RemainingDevicePath
324 //
325 Private->GopDevicePath = AppendDevicePathNode (ParentDevicePath, RemainingDevicePath);
326 } else {
327 //
328 // If RemainingDevicePath is the End of Device Path Node,
329 // don't create child device and return EFI_SUCCESS
330 //
331 Private->GopDevicePath = NULL;
332 }
333
334 if (Private->GopDevicePath != NULL) {
335 //
336 // Creat child handle and device path protocol firstly
337 //
338 Private->Handle = NULL;
339 Status = gBS->InstallMultipleProtocolInterfaces (
340 &Private->Handle,
341 &gEfiDevicePathProtocolGuid,
342 Private->GopDevicePath,
343 NULL
344 );
345 }
346 }
347
348 //
349 // Construct video mode buffer
350 //
351 Status = CirrusLogic5430VideoModeSetup (Private);
352 if (EFI_ERROR (Status)) {
353 goto Error;
354 }
355
356 if (FeaturePcdGet (PcdSupportUga)) {
357 //
358 // Start the UGA Draw software stack.
359 //
360 Status = CirrusLogic5430UgaDrawConstructor (Private);
361 ASSERT_EFI_ERROR (Status);
362
363 Private->UgaDevicePath = ParentDevicePath;
364 Status = gBS->InstallMultipleProtocolInterfaces (
365 &Controller,
366 &gEfiUgaDrawProtocolGuid,
367 &Private->UgaDraw,
368 &gEfiDevicePathProtocolGuid,
369 Private->UgaDevicePath,
370 NULL
371 );
372
373 } else if (FeaturePcdGet (PcdSupportGop)) {
374 if (Private->GopDevicePath == NULL) {
375 //
376 // If RemainingDevicePath is the End of Device Path Node,
377 // don't create child device and return EFI_SUCCESS
378 //
379 Status = EFI_SUCCESS;
380 } else {
381
382 //
383 // Start the GOP software stack.
384 //
385 Status = CirrusLogic5430GraphicsOutputConstructor (Private);
386 ASSERT_EFI_ERROR (Status);
387
388 Status = gBS->InstallMultipleProtocolInterfaces (
389 &Private->Handle,
390 &gEfiGraphicsOutputProtocolGuid,
391 &Private->GraphicsOutput,
392 &gEfiEdidDiscoveredProtocolGuid,
393 &Private->EdidDiscovered,
394 &gEfiEdidActiveProtocolGuid,
395 &Private->EdidActive,
396 NULL
397 );
398 }
399 } else {
400 //
401 // This driver must support eithor GOP or UGA or both.
402 //
403 ASSERT (FALSE);
404 Status = EFI_UNSUPPORTED;
405 }
406
407
408 Error:
409 if (EFI_ERROR (Status)) {
410 if (Private) {
411 if (Private->PciIo) {
412 if (PciAttributesSaved == TRUE) {
413 //
414 // Restore original PCI attributes
415 //
416 Private->PciIo->Attributes (
417 Private->PciIo,
418 EfiPciIoAttributeOperationSet,
419 Private->OriginalPciAttributes,
420 NULL
421 );
422 }
423 //
424 // Close the PCI I/O Protocol
425 //
426 gBS->CloseProtocol (
427 Private->Handle,
428 &gEfiPciIoProtocolGuid,
429 This->DriverBindingHandle,
430 Private->Handle
431 );
432 }
433
434 gBS->FreePool (Private);
435 }
436 }
437
438 return Status;
439 }
440
441 /**
442 CirrusLogic5430ControllerDriverStop
443
444 TODO: This - add argument and description to function comment
445 TODO: Controller - add argument and description to function comment
446 TODO: NumberOfChildren - add argument and description to function comment
447 TODO: ChildHandleBuffer - add argument and description to function comment
448 TODO: EFI_SUCCESS - add return value to function comment
449 **/
450 EFI_STATUS
451 EFIAPI
452 CirrusLogic5430ControllerDriverStop (
453 IN EFI_DRIVER_BINDING_PROTOCOL *This,
454 IN EFI_HANDLE Controller,
455 IN UINTN NumberOfChildren,
456 IN EFI_HANDLE *ChildHandleBuffer
457 )
458 {
459 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
460 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
461
462 EFI_STATUS Status;
463 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
464
465 if (FeaturePcdGet (PcdSupportUga)) {
466 Status = gBS->OpenProtocol (
467 Controller,
468 &gEfiUgaDrawProtocolGuid,
469 (VOID **) &UgaDraw,
470 This->DriverBindingHandle,
471 Controller,
472 EFI_OPEN_PROTOCOL_GET_PROTOCOL
473 );
474 if (EFI_ERROR (Status)) {
475 return Status;
476 }
477 //
478 // Get our private context information
479 //
480 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw);
481 CirrusLogic5430UgaDrawDestructor (Private);
482
483 if (FeaturePcdGet (PcdSupportGop)) {
484 CirrusLogic5430GraphicsOutputDestructor (Private);
485 //
486 // Remove the UGA and GOP protocol interface from the system
487 //
488 Status = gBS->UninstallMultipleProtocolInterfaces (
489 Private->Handle,
490 &gEfiUgaDrawProtocolGuid,
491 &Private->UgaDraw,
492 &gEfiGraphicsOutputProtocolGuid,
493 &Private->GraphicsOutput,
494 NULL
495 );
496 } else {
497 //
498 // Remove the UGA Draw interface from the system
499 //
500 Status = gBS->UninstallMultipleProtocolInterfaces (
501 Private->Handle,
502 &gEfiUgaDrawProtocolGuid,
503 &Private->UgaDraw,
504 NULL
505 );
506 }
507 } else {
508 Status = gBS->OpenProtocol (
509 Controller,
510 &gEfiGraphicsOutputProtocolGuid,
511 (VOID **) &GraphicsOutput,
512 This->DriverBindingHandle,
513 Controller,
514 EFI_OPEN_PROTOCOL_GET_PROTOCOL
515 );
516 if (EFI_ERROR (Status)) {
517 return Status;
518 }
519
520 //
521 // Get our private context information
522 //
523 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);
524
525 CirrusLogic5430GraphicsOutputDestructor (Private);
526 //
527 // Remove the GOP protocol interface from the system
528 //
529 Status = gBS->UninstallMultipleProtocolInterfaces (
530 Private->Handle,
531 &gEfiUgaDrawProtocolGuid,
532 &Private->UgaDraw,
533 &gEfiGraphicsOutputProtocolGuid,
534 &Private->GraphicsOutput,
535 NULL
536 );
537 }
538
539 if (EFI_ERROR (Status)) {
540 return Status;
541 }
542
543 //
544 // Restore original PCI attributes
545 //
546 Private->PciIo->Attributes (
547 Private->PciIo,
548 EfiPciIoAttributeOperationSet,
549 Private->OriginalPciAttributes,
550 NULL
551 );
552
553 //
554 // Close the PCI I/O Protocol
555 //
556 gBS->CloseProtocol (
557 Controller,
558 &gEfiPciIoProtocolGuid,
559 This->DriverBindingHandle,
560 Controller
561 );
562
563 //
564 // Free our instance data
565 //
566 gBS->FreePool (Private);
567
568 return EFI_SUCCESS;
569 }
570
571 /**
572 CirrusLogic5430UgaDrawDestructor
573
574 TODO: Private - add argument and description to function comment
575 TODO: EFI_SUCCESS - add return value to function comment
576 **/
577 EFI_STATUS
578 CirrusLogic5430UgaDrawDestructor (
579 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
580 )
581 {
582 return EFI_SUCCESS;
583 }
584
585 /**
586 TODO: Add function description
587
588 @param Private TODO: add argument description
589 @param Address TODO: add argument description
590 @param Data TODO: add argument description
591
592 TODO: add return values
593
594 **/
595 VOID
596 outb (
597 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
598 UINTN Address,
599 UINT8 Data
600 )
601 {
602 Private->PciIo->Io.Write (
603 Private->PciIo,
604 EfiPciIoWidthUint8,
605 EFI_PCI_IO_PASS_THROUGH_BAR,
606 Address,
607 1,
608 &Data
609 );
610 }
611
612 /**
613 TODO: Add function description
614
615 @param Private TODO: add argument description
616 @param Address TODO: add argument description
617 @param Data TODO: add argument description
618
619 TODO: add return values
620
621 **/
622 VOID
623 outw (
624 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
625 UINTN Address,
626 UINT16 Data
627 )
628 {
629 Private->PciIo->Io.Write (
630 Private->PciIo,
631 EfiPciIoWidthUint16,
632 EFI_PCI_IO_PASS_THROUGH_BAR,
633 Address,
634 1,
635 &Data
636 );
637 }
638
639 /**
640 TODO: Add function description
641
642 @param Private TODO: add argument description
643 @param Address TODO: add argument description
644
645 TODO: add return values
646
647 **/
648 UINT8
649 inb (
650 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
651 UINTN Address
652 )
653 {
654 UINT8 Data;
655
656 Private->PciIo->Io.Read (
657 Private->PciIo,
658 EfiPciIoWidthUint8,
659 EFI_PCI_IO_PASS_THROUGH_BAR,
660 Address,
661 1,
662 &Data
663 );
664 return Data;
665 }
666
667 /**
668 TODO: Add function description
669
670 @param Private TODO: add argument description
671 @param Address TODO: add argument description
672
673 TODO: add return values
674
675 **/
676 UINT16
677 inw (
678 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
679 UINTN Address
680 )
681 {
682 UINT16 Data;
683
684 Private->PciIo->Io.Read (
685 Private->PciIo,
686 EfiPciIoWidthUint16,
687 EFI_PCI_IO_PASS_THROUGH_BAR,
688 Address,
689 1,
690 &Data
691 );
692 return Data;
693 }
694
695 /**
696 TODO: Add function description
697
698 @param Private TODO: add argument description
699 @param Index TODO: add argument description
700 @param Red TODO: add argument description
701 @param Green TODO: add argument description
702 @param Blue TODO: add argument description
703
704 TODO: add return values
705
706 **/
707 VOID
708 SetPaletteColor (
709 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
710 UINTN Index,
711 UINT8 Red,
712 UINT8 Green,
713 UINT8 Blue
714 )
715 {
716 outb (Private, PALETTE_INDEX_REGISTER, (UINT8) Index);
717 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));
718 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));
719 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));
720 }
721
722 /**
723 TODO: Add function description
724
725 @param Private TODO: add argument description
726
727 TODO: add return values
728
729 **/
730 VOID
731 SetDefaultPalette (
732 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
733 )
734 {
735 UINTN Index;
736 UINTN RedIndex;
737 UINTN GreenIndex;
738 UINTN BlueIndex;
739
740 Index = 0;
741 for (RedIndex = 0; RedIndex < 8; RedIndex++) {
742 for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {
743 for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {
744 SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));
745 Index++;
746 }
747 }
748 }
749 }
750
751 /**
752 TODO: Add function description
753
754 @param Private TODO: add argument description
755
756 TODO: add return values
757
758 **/
759 VOID
760 ClearScreen (
761 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
762 )
763 {
764 UINT32 Color;
765
766 Color = 0;
767 Private->PciIo->Mem.Write (
768 Private->PciIo,
769 EfiPciIoWidthFillUint32,
770 0,
771 0,
772 0x100000 >> 2,
773 &Color
774 );
775 }
776
777 /**
778 TODO: Add function description
779
780 @param Private TODO: add argument description
781
782 TODO: add return values
783
784 **/
785 VOID
786 DrawLogo (
787 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
788 UINTN ScreenWidth,
789 UINTN ScreenHeight
790 )
791 {
792 }
793
794 /**
795 TODO: Add function description
796
797 @param Private TODO: add argument description
798 @param ModeData TODO: add argument description
799
800 TODO: add return values
801
802 **/
803 VOID
804 InitializeGraphicsMode (
805 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
806 CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData
807 )
808 {
809 UINT8 Byte;
810 UINTN Index;
811 UINT16 DeviceId;
812 EFI_STATUS Status;
813
814 Status = Private->PciIo->Pci.Read (
815 Private->PciIo,
816 EfiPciIoWidthUint16,
817 PCI_DEVICE_ID_OFFSET,
818 1,
819 &DeviceId
820 );
821 //
822 // Read the PCI Configuration Header from the PCI Device
823 //
824 ASSERT_EFI_ERROR (Status);
825
826 outw (Private, SEQ_ADDRESS_REGISTER, 0x1206);
827 outw (Private, SEQ_ADDRESS_REGISTER, 0x0012);
828
829 for (Index = 0; Index < 15; Index++) {
830 outw (Private, SEQ_ADDRESS_REGISTER, ModeData->SeqSettings[Index]);
831 }
832
833 if (DeviceId != CIRRUS_LOGIC_5446_DEVICE_ID) {
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
839 outb (Private, MISC_OUTPUT_REGISTER, ModeData->MiscSetting);
840 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0506);
841 outw (Private, SEQ_ADDRESS_REGISTER, 0x0300);
842 outw (Private, CRTC_ADDRESS_REGISTER, 0x2011);
843
844 for (Index = 0; Index < 28; Index++) {
845 outw (Private, CRTC_ADDRESS_REGISTER, (UINT16) ((ModeData->CrtcSettings[Index] << 8) | Index));
846 }
847
848 for (Index = 0; Index < 9; Index++) {
849 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((GraphicsController[Index] << 8) | Index));
850 }
851
852 inb (Private, INPUT_STATUS_1_REGISTER);
853
854 for (Index = 0; Index < 21; Index++) {
855 outb (Private, ATT_ADDRESS_REGISTER, (UINT8) Index);
856 outb (Private, ATT_ADDRESS_REGISTER, AttributeController[Index]);
857 }
858
859 outb (Private, ATT_ADDRESS_REGISTER, 0x20);
860
861 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0009);
862 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000a);
863 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000b);
864 outb (Private, DAC_PIXEL_MASK_REGISTER, 0xff);
865
866 SetDefaultPalette (Private);
867 ClearScreen (Private);
868 }
869
870 EFI_STATUS
871 EFIAPI
872 InitializeCirrusLogic5430 (
873 IN EFI_HANDLE ImageHandle,
874 IN EFI_SYSTEM_TABLE *SystemTable
875 )
876 {
877 EFI_STATUS Status;
878
879 Status = EfiLibInstallDriverBindingComponentName2 (
880 ImageHandle,
881 SystemTable,
882 &gCirrusLogic5430DriverBinding,
883 ImageHandle,
884 &gCirrusLogic5430ComponentName,
885 &gCirrusLogic5430ComponentName2
886 );
887 ASSERT_EFI_ERROR (Status);
888
889 //
890 // Install EFI Driver Supported EFI Version Protocol required for
891 // EFI drivers that are on PCI and other plug in cards.
892 //
893 gCirrusLogic5430DriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion);
894 Status = gBS->InstallMultipleProtocolInterfaces (
895 &ImageHandle,
896 &gEfiDriverSupportedEfiVersionProtocolGuid,
897 &gCirrusLogic5430DriverSupportedEfiVersion,
898 NULL
899 );
900 ASSERT_EFI_ERROR (Status);
901
902 return Status;
903 }