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 |
94b73c24 |
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 |
87f8ccbe |
19 | \r |
94b73c24 |
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 |
87f8ccbe |
22 | \r |
23 | **/\r |
24 | \r |
25 | //\r |
26 | // Cirrus Logic 5430 Controller Driver\r |
27 | //\r |
28 | #include "CirrusLogic5430.h"\r |
29 | \r |
30 | EFI_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 |
42 | UINT8 AttributeController[21] = {\r |
94b73c24 |
43 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\r |
44 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,\r |
87f8ccbe |
45 | 0x41, 0x00, 0x0F, 0x00, 0x00\r |
46 | };\r |
47 | \r |
48 | ///\r |
49 | /// Generic Graphics Controller Register Settings\r |
50 | ///\r |
51 | UINT8 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 |
58 | UINT8 Crtc_640_480_256_60[28] = {\r |
59 | 0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e,\r |
94b73c24 |
60 | 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r |
87f8ccbe |
61 | 0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3,\r |
62 | 0xff, 0x00, 0x00, 0x22\r |
63 | };\r |
64 | \r |
65 | UINT16 Seq_640_480_256_60[15] = {\r |
94b73c24 |
66 | 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,\r |
87f8ccbe |
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 |
73 | UINT8 Crtc_800_600_256_60[28] = {\r |
94b73c24 |
74 | 0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0,\r |
75 | 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r |
87f8ccbe |
76 | 0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3,\r |
77 | 0xFF, 0x00, 0x00, 0x22\r |
78 | };\r |
79 | \r |
80 | UINT16 Seq_800_600_256_60[15] = {\r |
94b73c24 |
81 | 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,\r |
87f8ccbe |
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 |
88 | UINT8 Crtc_1024_768_256_60[28] = {\r |
94b73c24 |
89 | 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD,\r |
90 | 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r |
87f8ccbe |
91 | 0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3,\r |
92 | 0xFF, 0x4A, 0x00, 0x22\r |
93 | };\r |
94 | \r |
95 | UINT16 Seq_1024_768_256_60[15] = {\r |
94b73c24 |
96 | 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,\r |
87f8ccbe |
97 | 0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e\r |
98 | };\r |
99 | \r |
100 | ///\r |
101 | /// Table of supported video modes\r |
102 | ///\r |
103 | CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = {\r |
104 | { 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 },\r |
94b73c24 |
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 |
87f8ccbe |
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 |
116 | EFI_STATUS\r |
117 | EFIAPI\r |
118 | CirrusLogic5430ControllerDriverSupported (\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 |
183 | Done:\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 |
204 | EFI_STATUS\r |
205 | EFIAPI\r |
206 | CirrusLogic5430ControllerDriverStart (\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 |
94b73c24 |
245 | //\r |
246 | // Save original PCI attributes\r |
247 | //\r |
248 | Status = Private->PciIo->Attributes (\r |
249 | Private->PciIo,\r |
250 | EfiPciIoAttributeOperationGet,\r |
251 | 0,\r |
252 | &Private->OriginalPciAttributes\r |
253 | );\r |
254 | \r |
255 | if (EFI_ERROR (Status)) {\r |
256 | goto Error;\r |
257 | }\r |
258 | \r |
87f8ccbe |
259 | Status = Private->PciIo->Attributes (\r |
260 | Private->PciIo,\r |
261 | EfiPciIoAttributeOperationEnable,\r |
262 | EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,\r |
263 | NULL\r |
264 | );\r |
265 | if (EFI_ERROR (Status)) {\r |
266 | goto Error;\r |
267 | }\r |
268 | \r |
269 | if (FeaturePcdGet (PcdSupportUga)) {\r |
270 | //\r |
271 | // Start the UGA Draw software stack.\r |
272 | //\r |
273 | Status = CirrusLogic5430UgaDrawConstructor (Private);\r |
274 | ASSERT_EFI_ERROR (Status);\r |
275 | if (FeaturePcdGet (PcdSupportGop)) {\r |
276 | Status = CirrusLogic5430GraphicsOutputConstructor (Private);\r |
277 | ASSERT_EFI_ERROR (Status);\r |
278 | \r |
279 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
280 | &Private->Handle,\r |
281 | &gEfiUgaDrawProtocolGuid,\r |
282 | &Private->UgaDraw,\r |
283 | &gEfiGraphicsOutputProtocolGuid,\r |
284 | &Private->GraphicsOutput,\r |
285 | NULL\r |
286 | );\r |
287 | } else {\r |
288 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
289 | &Private->Handle,\r |
290 | &gEfiUgaDrawProtocolGuid,\r |
291 | &Private->UgaDraw,\r |
292 | NULL\r |
293 | );\r |
294 | \r |
295 | }\r |
296 | } else {\r |
297 | if (FeaturePcdGet (PcdSupportGop)) {\r |
298 | Status = CirrusLogic5430GraphicsOutputConstructor (Private);\r |
299 | ASSERT_EFI_ERROR (Status);\r |
300 | \r |
301 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
302 | &Private->Handle,\r |
303 | &gEfiGraphicsOutputProtocolGuid,\r |
304 | &Private->GraphicsOutput,\r |
305 | NULL\r |
306 | );\r |
94b73c24 |
307 | \r |
87f8ccbe |
308 | } else {\r |
309 | //\r |
310 | // This driver must support eithor GOP or UGA or both.\r |
94b73c24 |
311 | //\r |
87f8ccbe |
312 | ASSERT (FALSE);\r |
313 | Status = EFI_UNSUPPORTED;\r |
314 | }\r |
315 | }\r |
94b73c24 |
316 | \r |
87f8ccbe |
317 | \r |
318 | Error:\r |
319 | if (EFI_ERROR (Status)) {\r |
320 | if (Private) {\r |
321 | if (Private->PciIo) {\r |
94b73c24 |
322 | //\r |
323 | // Restore original PCI attributes\r |
324 | //\r |
87f8ccbe |
325 | Private->PciIo->Attributes (\r |
94b73c24 |
326 | Private->PciIo,\r |
327 | EfiPciIoAttributeOperationSet,\r |
328 | Private->OriginalPciAttributes,\r |
329 | NULL\r |
330 | );\r |
331 | \r |
332 | //\r |
333 | // Close the PCI I/O Protocol\r |
334 | //\r |
335 | gBS->CloseProtocol (\r |
336 | Private->Handle,\r |
337 | &gEfiPciIoProtocolGuid,\r |
338 | This->DriverBindingHandle,\r |
339 | Private->Handle\r |
340 | );\r |
87f8ccbe |
341 | }\r |
87f8ccbe |
342 | \r |
87f8ccbe |
343 | gBS->FreePool (Private);\r |
344 | }\r |
345 | }\r |
346 | \r |
347 | return Status;\r |
348 | }\r |
349 | \r |
350 | /**\r |
351 | CirrusLogic5430ControllerDriverStop\r |
352 | \r |
353 | TODO: This - add argument and description to function comment\r |
354 | TODO: Controller - add argument and description to function comment\r |
355 | TODO: NumberOfChildren - add argument and description to function comment\r |
356 | TODO: ChildHandleBuffer - add argument and description to function comment\r |
357 | TODO: EFI_SUCCESS - add return value to function comment\r |
358 | **/\r |
359 | EFI_STATUS\r |
360 | EFIAPI\r |
361 | CirrusLogic5430ControllerDriverStop (\r |
362 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
363 | IN EFI_HANDLE Controller,\r |
364 | IN UINTN NumberOfChildren,\r |
365 | IN EFI_HANDLE *ChildHandleBuffer\r |
366 | )\r |
367 | {\r |
368 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r |
369 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r |
370 | \r |
371 | EFI_STATUS Status;\r |
372 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r |
373 | \r |
374 | if (FeaturePcdGet (PcdSupportUga)) {\r |
375 | Status = gBS->OpenProtocol (\r |
376 | Controller,\r |
377 | &gEfiUgaDrawProtocolGuid,\r |
378 | (VOID **) &UgaDraw,\r |
379 | This->DriverBindingHandle,\r |
380 | Controller,\r |
381 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
382 | );\r |
383 | if (EFI_ERROR (Status)) {\r |
384 | return Status;\r |
385 | }\r |
386 | //\r |
387 | // Get our private context information\r |
388 | //\r |
389 | Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw);\r |
390 | CirrusLogic5430UgaDrawDestructor (Private);\r |
391 | \r |
392 | if (FeaturePcdGet (PcdSupportGop)) {\r |
393 | CirrusLogic5430GraphicsOutputDestructor (Private);\r |
394 | //\r |
395 | // Remove the UGA and GOP protocol interface from the system\r |
396 | //\r |
397 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
398 | Private->Handle,\r |
399 | &gEfiUgaDrawProtocolGuid,\r |
400 | &Private->UgaDraw,\r |
401 | &gEfiGraphicsOutputProtocolGuid,\r |
402 | &Private->GraphicsOutput,\r |
403 | NULL\r |
404 | );\r |
405 | } else {\r |
406 | //\r |
407 | // Remove the UGA Draw interface from the system\r |
408 | //\r |
409 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
410 | Private->Handle,\r |
411 | &gEfiUgaDrawProtocolGuid,\r |
412 | &Private->UgaDraw,\r |
413 | NULL\r |
414 | );\r |
415 | }\r |
416 | } else {\r |
417 | Status = gBS->OpenProtocol (\r |
418 | Controller,\r |
419 | &gEfiGraphicsOutputProtocolGuid,\r |
420 | (VOID **) &GraphicsOutput,\r |
421 | This->DriverBindingHandle,\r |
422 | Controller,\r |
423 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
424 | );\r |
425 | if (EFI_ERROR (Status)) {\r |
426 | return Status;\r |
427 | }\r |
428 | \r |
429 | //\r |
430 | // Get our private context information\r |
431 | //\r |
432 | Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);\r |
433 | \r |
434 | CirrusLogic5430GraphicsOutputDestructor (Private);\r |
435 | //\r |
436 | // Remove the GOP protocol interface from the system\r |
437 | //\r |
438 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
439 | Private->Handle,\r |
440 | &gEfiUgaDrawProtocolGuid,\r |
441 | &Private->UgaDraw,\r |
442 | &gEfiGraphicsOutputProtocolGuid,\r |
443 | &Private->GraphicsOutput,\r |
444 | NULL\r |
445 | );\r |
446 | }\r |
447 | \r |
448 | if (EFI_ERROR (Status)) {\r |
449 | return Status;\r |
450 | }\r |
451 | \r |
87f8ccbe |
452 | //\r |
94b73c24 |
453 | // Restore original PCI attributes\r |
87f8ccbe |
454 | //\r |
455 | Private->PciIo->Attributes (\r |
94b73c24 |
456 | Private->PciIo,\r |
457 | EfiPciIoAttributeOperationSet,\r |
458 | Private->OriginalPciAttributes,\r |
459 | NULL\r |
460 | );\r |
87f8ccbe |
461 | \r |
462 | //\r |
463 | // Close the PCI I/O Protocol\r |
464 | //\r |
465 | gBS->CloseProtocol (\r |
466 | Controller,\r |
467 | &gEfiPciIoProtocolGuid,\r |
468 | This->DriverBindingHandle,\r |
469 | Controller\r |
470 | );\r |
471 | \r |
472 | //\r |
473 | // Free our instance data\r |
474 | //\r |
475 | gBS->FreePool (Private);\r |
476 | \r |
477 | return EFI_SUCCESS;\r |
478 | }\r |
479 | \r |
480 | /**\r |
481 | CirrusLogic5430UgaDrawDestructor\r |
482 | \r |
483 | TODO: Private - add argument and description to function comment\r |
484 | TODO: EFI_SUCCESS - add return value to function comment\r |
485 | **/\r |
486 | EFI_STATUS\r |
487 | CirrusLogic5430UgaDrawDestructor (\r |
488 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r |
489 | )\r |
490 | {\r |
491 | return EFI_SUCCESS;\r |
492 | }\r |
493 | \r |
494 | /**\r |
495 | TODO: Add function description\r |
496 | \r |
497 | @param Private TODO: add argument description\r |
498 | @param Address TODO: add argument description\r |
499 | @param Data TODO: add argument description\r |
500 | \r |
501 | TODO: add return values\r |
502 | \r |
503 | **/\r |
504 | VOID\r |
505 | outb (\r |
506 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
507 | UINTN Address,\r |
508 | UINT8 Data\r |
509 | )\r |
510 | {\r |
511 | Private->PciIo->Io.Write (\r |
512 | Private->PciIo,\r |
513 | EfiPciIoWidthUint8,\r |
514 | EFI_PCI_IO_PASS_THROUGH_BAR,\r |
515 | Address,\r |
516 | 1,\r |
517 | &Data\r |
518 | );\r |
519 | }\r |
520 | \r |
521 | /**\r |
522 | TODO: Add function description\r |
523 | \r |
524 | @param Private TODO: add argument description\r |
525 | @param Address TODO: add argument description\r |
526 | @param Data TODO: add argument description\r |
527 | \r |
528 | TODO: add return values\r |
529 | \r |
530 | **/\r |
531 | VOID\r |
532 | outw (\r |
533 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
534 | UINTN Address,\r |
535 | UINT16 Data\r |
536 | )\r |
537 | {\r |
538 | Private->PciIo->Io.Write (\r |
539 | Private->PciIo,\r |
540 | EfiPciIoWidthUint16,\r |
541 | EFI_PCI_IO_PASS_THROUGH_BAR,\r |
542 | Address,\r |
543 | 1,\r |
544 | &Data\r |
545 | );\r |
546 | }\r |
547 | \r |
548 | /**\r |
549 | TODO: Add function description\r |
550 | \r |
551 | @param Private TODO: add argument description\r |
552 | @param Address TODO: add argument description\r |
553 | \r |
554 | TODO: add return values\r |
555 | \r |
556 | **/\r |
557 | UINT8\r |
558 | inb (\r |
559 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
560 | UINTN Address\r |
561 | )\r |
562 | {\r |
563 | UINT8 Data;\r |
564 | \r |
565 | Private->PciIo->Io.Read (\r |
566 | Private->PciIo,\r |
567 | EfiPciIoWidthUint8,\r |
568 | EFI_PCI_IO_PASS_THROUGH_BAR,\r |
569 | Address,\r |
570 | 1,\r |
571 | &Data\r |
572 | );\r |
573 | return Data;\r |
574 | }\r |
575 | \r |
576 | /**\r |
577 | TODO: Add function description\r |
578 | \r |
579 | @param Private TODO: add argument description\r |
580 | @param Address TODO: add argument description\r |
581 | \r |
582 | TODO: add return values\r |
583 | \r |
584 | **/\r |
585 | UINT16\r |
586 | inw (\r |
587 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
588 | UINTN Address\r |
589 | )\r |
590 | {\r |
591 | UINT16 Data;\r |
592 | \r |
593 | Private->PciIo->Io.Read (\r |
594 | Private->PciIo,\r |
595 | EfiPciIoWidthUint16,\r |
596 | EFI_PCI_IO_PASS_THROUGH_BAR,\r |
597 | Address,\r |
598 | 1,\r |
599 | &Data\r |
600 | );\r |
601 | return Data;\r |
602 | }\r |
603 | \r |
604 | /**\r |
605 | TODO: Add function description\r |
606 | \r |
607 | @param Private TODO: add argument description\r |
608 | @param Index TODO: add argument description\r |
609 | @param Red TODO: add argument description\r |
610 | @param Green TODO: add argument description\r |
611 | @param Blue TODO: add argument description\r |
612 | \r |
613 | TODO: add return values\r |
614 | \r |
615 | **/\r |
616 | VOID\r |
617 | SetPaletteColor (\r |
618 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
619 | UINTN Index,\r |
620 | UINT8 Red,\r |
621 | UINT8 Green,\r |
622 | UINT8 Blue\r |
623 | )\r |
624 | {\r |
625 | outb (Private, PALETTE_INDEX_REGISTER, (UINT8) Index);\r |
626 | outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));\r |
627 | outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));\r |
628 | outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));\r |
629 | }\r |
630 | \r |
631 | /**\r |
632 | TODO: Add function description\r |
633 | \r |
634 | @param Private TODO: add argument description\r |
635 | \r |
636 | TODO: add return values\r |
637 | \r |
638 | **/\r |
639 | VOID\r |
640 | SetDefaultPalette (\r |
641 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r |
642 | )\r |
643 | {\r |
644 | UINTN Index;\r |
645 | UINTN RedIndex;\r |
646 | UINTN GreenIndex;\r |
647 | UINTN BlueIndex;\r |
648 | \r |
649 | Index = 0;\r |
650 | for (RedIndex = 0; RedIndex < 8; RedIndex++) {\r |
651 | for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {\r |
652 | for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {\r |
653 | SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));\r |
654 | Index++;\r |
655 | }\r |
656 | }\r |
657 | }\r |
658 | }\r |
659 | \r |
660 | /**\r |
661 | TODO: Add function description\r |
662 | \r |
663 | @param Private TODO: add argument description\r |
664 | \r |
665 | TODO: add return values\r |
666 | \r |
667 | **/\r |
668 | STATIC\r |
669 | VOID\r |
670 | ClearScreen (\r |
671 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r |
672 | )\r |
673 | {\r |
674 | UINT32 Color;\r |
675 | \r |
676 | Color = 0;\r |
677 | Private->PciIo->Mem.Write (\r |
678 | Private->PciIo,\r |
679 | EfiPciIoWidthFillUint32,\r |
680 | 0,\r |
681 | 0,\r |
682 | 0x100000 >> 2,\r |
683 | &Color\r |
684 | );\r |
685 | }\r |
686 | \r |
687 | /**\r |
688 | TODO: Add function description\r |
689 | \r |
690 | @param Private TODO: add argument description\r |
691 | \r |
692 | TODO: add return values\r |
693 | \r |
694 | **/\r |
695 | VOID\r |
696 | DrawLogo (\r |
697 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
698 | UINTN ScreenWidth,\r |
699 | UINTN ScreenHeight\r |
700 | )\r |
701 | {\r |
702 | UINTN Offset;\r |
703 | UINTN X;\r |
704 | UINTN Y;\r |
705 | UINT8 Color;\r |
706 | \r |
707 | Offset = 0;\r |
708 | for (Y = 0; Y < ScreenHeight; Y++) {\r |
709 | for (X = 0; X < ScreenWidth; X++) {\r |
710 | Color = (UINT8) (256 * (X + Y) / (ScreenWidth + ScreenHeight));\r |
711 | Private->LineBuffer[X] = Color;\r |
712 | }\r |
713 | \r |
714 | Private->PciIo->Mem.Write (\r |
715 | Private->PciIo,\r |
716 | EfiPciIoWidthUint32,\r |
717 | 0,\r |
718 | Offset + (Y * ScreenWidth),\r |
719 | ScreenWidth >> 2,\r |
720 | Private->LineBuffer\r |
721 | );\r |
722 | }\r |
723 | }\r |
724 | \r |
725 | /**\r |
726 | TODO: Add function description\r |
727 | \r |
728 | @param Private TODO: add argument description\r |
729 | @param ModeData TODO: add argument description\r |
730 | \r |
731 | TODO: add return values\r |
732 | \r |
733 | **/\r |
734 | VOID\r |
735 | InitializeGraphicsMode (\r |
736 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r |
737 | CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData\r |
738 | )\r |
739 | {\r |
740 | UINT8 Byte;\r |
741 | UINTN Index;\r |
742 | \r |
743 | outw (Private, SEQ_ADDRESS_REGISTER, 0x1206);\r |
744 | outw (Private, SEQ_ADDRESS_REGISTER, 0x0012);\r |
745 | \r |
746 | for (Index = 0; Index < 15; Index++) {\r |
747 | outw (Private, SEQ_ADDRESS_REGISTER, ModeData->SeqSettings[Index]);\r |
748 | }\r |
749 | \r |
750 | outb (Private, SEQ_ADDRESS_REGISTER, 0x0f);\r |
751 | Byte = (UINT8) ((inb (Private, SEQ_DATA_REGISTER) & 0xc7) ^ 0x30);\r |
752 | outb (Private, SEQ_DATA_REGISTER, Byte);\r |
753 | \r |
754 | outb (Private, MISC_OUTPUT_REGISTER, ModeData->MiscSetting);\r |
755 | outw (Private, GRAPH_ADDRESS_REGISTER, 0x0506);\r |
756 | outw (Private, SEQ_ADDRESS_REGISTER, 0x0300);\r |
757 | outw (Private, CRTC_ADDRESS_REGISTER, 0x2011);\r |
758 | \r |
759 | for (Index = 0; Index < 28; Index++) {\r |
760 | outw (Private, CRTC_ADDRESS_REGISTER, (UINT16) ((ModeData->CrtcSettings[Index] << 8) | Index));\r |
761 | }\r |
762 | \r |
763 | for (Index = 0; Index < 9; Index++) {\r |
764 | outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((GraphicsController[Index] << 8) | Index));\r |
765 | }\r |
766 | \r |
767 | inb (Private, INPUT_STATUS_1_REGISTER);\r |
768 | \r |
769 | for (Index = 0; Index < 21; Index++) {\r |
770 | outb (Private, ATT_ADDRESS_REGISTER, (UINT8) Index);\r |
771 | outb (Private, ATT_ADDRESS_REGISTER, AttributeController[Index]);\r |
772 | }\r |
773 | \r |
774 | outb (Private, ATT_ADDRESS_REGISTER, 0x20);\r |
775 | \r |
776 | outw (Private, GRAPH_ADDRESS_REGISTER, 0x0009);\r |
777 | outw (Private, GRAPH_ADDRESS_REGISTER, 0x000a);\r |
778 | outw (Private, GRAPH_ADDRESS_REGISTER, 0x000b);\r |
779 | outb (Private, DAC_PIXEL_MASK_REGISTER, 0xff);\r |
780 | \r |
781 | SetDefaultPalette (Private);\r |
782 | ClearScreen (Private);\r |
783 | }\r |
784 | \r |
785 | EFI_STATUS\r |
786 | EFIAPI\r |
787 | InitializeCirrusLogic5430 (\r |
788 | IN EFI_HANDLE ImageHandle,\r |
789 | IN EFI_SYSTEM_TABLE *SystemTable\r |
790 | )\r |
791 | {\r |
792 | EFI_STATUS Status;\r |
793 | \r |
794 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
795 | ImageHandle,\r |
796 | SystemTable,\r |
797 | &gCirrusLogic5430DriverBinding,\r |
798 | ImageHandle,\r |
799 | &gCirrusLogic5430ComponentName,\r |
800 | &gCirrusLogic5430ComponentName2\r |
801 | );\r |
802 | ASSERT_EFI_ERROR (Status);\r |
803 | \r |
804 | //\r |
94b73c24 |
805 | // Install EFI Driver Supported EFI Version Protocol required for\r |
87f8ccbe |
806 | // EFI drivers that are on PCI and other plug in cards.\r |
807 | //\r |
808 | gCirrusLogic5430DriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion);\r |
809 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
810 | &ImageHandle,\r |
811 | &gEfiDriverSupportedEfiVersionProtocolGuid,\r |
812 | &gCirrusLogic5430DriverSupportedEfiVersion,\r |
813 | NULL\r |
814 | );\r |
815 | ASSERT_EFI_ERROR (Status);\r |
816 | \r |
817 | return Status;\r |
818 | }\r |