CirrusLogic5430.c 26 KB

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