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