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