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