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