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