CirrusLogic5430.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /** @file
  2. Cirrus Logic 5430 Controller Driver
  3. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. //
  7. // Cirrus Logic 5430 Controller Driver
  8. //
  9. #ifndef _CIRRUS_LOGIC_5430_H_
  10. #define _CIRRUS_LOGIC_5430_H_
  11. #include <Uefi.h>
  12. #include <Protocol/UgaDraw.h>
  13. #include <Protocol/GraphicsOutput.h>
  14. #include <Protocol/PciIo.h>
  15. #include <Protocol/DriverSupportedEfiVersion.h>
  16. #include <Protocol/EdidOverride.h>
  17. #include <Protocol/EdidDiscovered.h>
  18. #include <Protocol/EdidActive.h>
  19. #include <Protocol/DevicePath.h>
  20. #include <Library/DebugLib.h>
  21. #include <Library/UefiDriverEntryPoint.h>
  22. #include <Library/UefiLib.h>
  23. #include <Library/PcdLib.h>
  24. #include <Library/MemoryAllocationLib.h>
  25. #include <Library/UefiBootServicesTableLib.h>
  26. #include <Library/BaseMemoryLib.h>
  27. #include <Library/DevicePathLib.h>
  28. #include <Library/TimerLib.h>
  29. #include <IndustryStandard/Pci.h>
  30. //
  31. // Cirrus Logic 5430 PCI Configuration Header values
  32. //
  33. #define CIRRUS_LOGIC_VENDOR_ID 0x1013
  34. #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
  35. #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
  36. #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
  37. //
  38. // Cirrus Logic Graphical Mode Data
  39. //
  40. #define CIRRUS_LOGIC_5430_MODE_COUNT 3
  41. typedef struct {
  42. UINT32 ModeNumber;
  43. UINT32 HorizontalResolution;
  44. UINT32 VerticalResolution;
  45. UINT32 ColorDepth;
  46. UINT32 RefreshRate;
  47. } CIRRUS_LOGIC_5430_MODE_DATA;
  48. #define PIXEL_RED_SHIFT 0
  49. #define PIXEL_GREEN_SHIFT 3
  50. #define PIXEL_BLUE_SHIFT 6
  51. #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
  52. #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
  53. #define PIXEL_BLUE_MASK (BIT1 | BIT0)
  54. #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
  55. #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
  56. #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
  57. #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
  58. #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
  59. (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
  60. (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
  61. (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
  62. #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
  63. //
  64. // Cirrus Logic 5440 Private Data Structure
  65. //
  66. #define CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'L', '5', '4')
  67. typedef struct {
  68. UINT64 Signature;
  69. EFI_HANDLE Handle;
  70. EFI_PCI_IO_PROTOCOL *PciIo;
  71. UINT64 OriginalPciAttributes;
  72. EFI_UGA_DRAW_PROTOCOL UgaDraw;
  73. EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
  74. EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
  75. EFI_EDID_ACTIVE_PROTOCOL EdidActive;
  76. EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
  77. EFI_DEVICE_PATH_PROTOCOL *UgaDevicePath;
  78. UINTN CurrentMode;
  79. UINTN MaxMode;
  80. CIRRUS_LOGIC_5430_MODE_DATA ModeData[CIRRUS_LOGIC_5430_MODE_COUNT];
  81. UINT8 *LineBuffer;
  82. BOOLEAN HardwareNeedsStarting;
  83. } CIRRUS_LOGIC_5430_PRIVATE_DATA;
  84. ///
  85. /// Video Mode structure
  86. ///
  87. typedef struct {
  88. UINT32 Width;
  89. UINT32 Height;
  90. UINT32 ColorDepth;
  91. UINT32 RefreshRate;
  92. UINT8 *CrtcSettings;
  93. UINT16 *SeqSettings;
  94. UINT8 MiscSetting;
  95. } CIRRUS_LOGIC_5430_VIDEO_MODES;
  96. #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS(a) \
  97. CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, UgaDraw, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
  98. #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
  99. CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, GraphicsOutput, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
  100. //
  101. // Global Variables
  102. //
  103. extern UINT8 AttributeController[];
  104. extern UINT8 GraphicsController[];
  105. extern UINT8 Crtc_640_480_256_60[];
  106. extern UINT16 Seq_640_480_256_60[];
  107. extern UINT8 Crtc_800_600_256_60[];
  108. extern UINT16 Seq_800_600_256_60[];
  109. extern UINT8 Crtc_1024_768_256_60[];
  110. extern UINT16 Seq_1024_768_256_60[];
  111. extern CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[];
  112. extern EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding;
  113. extern EFI_COMPONENT_NAME_PROTOCOL gCirrusLogic5430ComponentName;
  114. extern EFI_COMPONENT_NAME2_PROTOCOL gCirrusLogic5430ComponentName2;
  115. extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gCirrusLogic5430DriverSupportedEfiVersion;
  116. //
  117. // Io Registers defined by VGA
  118. //
  119. #define CRTC_ADDRESS_REGISTER 0x3d4
  120. #define CRTC_DATA_REGISTER 0x3d5
  121. #define SEQ_ADDRESS_REGISTER 0x3c4
  122. #define SEQ_DATA_REGISTER 0x3c5
  123. #define GRAPH_ADDRESS_REGISTER 0x3ce
  124. #define GRAPH_DATA_REGISTER 0x3cf
  125. #define ATT_ADDRESS_REGISTER 0x3c0
  126. #define MISC_OUTPUT_REGISTER 0x3c2
  127. #define INPUT_STATUS_1_REGISTER 0x3da
  128. #define DAC_PIXEL_MASK_REGISTER 0x3c6
  129. #define PALETTE_INDEX_REGISTER 0x3c8
  130. #define PALETTE_DATA_REGISTER 0x3c9
  131. //
  132. // UGA Draw Hardware abstraction internal worker functions
  133. //
  134. EFI_STATUS
  135. CirrusLogic5430UgaDrawConstructor (
  136. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  137. );
  138. EFI_STATUS
  139. CirrusLogic5430UgaDrawDestructor (
  140. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  141. );
  142. //
  143. // Graphics Output Hardware abstraction internal worker functions
  144. //
  145. EFI_STATUS
  146. CirrusLogic5430GraphicsOutputConstructor (
  147. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  148. );
  149. EFI_STATUS
  150. CirrusLogic5430GraphicsOutputDestructor (
  151. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  152. );
  153. //
  154. // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
  155. //
  156. /**
  157. TODO: Add function description
  158. @param This TODO: add argument description
  159. @param Controller TODO: add argument description
  160. @param RemainingDevicePath TODO: add argument description
  161. TODO: add return values
  162. **/
  163. EFI_STATUS
  164. EFIAPI
  165. CirrusLogic5430ControllerDriverSupported (
  166. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  167. IN EFI_HANDLE Controller,
  168. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  169. );
  170. /**
  171. TODO: Add function description
  172. @param This TODO: add argument description
  173. @param Controller TODO: add argument description
  174. @param RemainingDevicePath TODO: add argument description
  175. TODO: add return values
  176. **/
  177. EFI_STATUS
  178. EFIAPI
  179. CirrusLogic5430ControllerDriverStart (
  180. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  181. IN EFI_HANDLE Controller,
  182. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  183. );
  184. /**
  185. TODO: Add function description
  186. @param This TODO: add argument description
  187. @param Controller TODO: add argument description
  188. @param NumberOfChildren TODO: add argument description
  189. @param ChildHandleBuffer TODO: add argument description
  190. TODO: add return values
  191. **/
  192. EFI_STATUS
  193. EFIAPI
  194. CirrusLogic5430ControllerDriverStop (
  195. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  196. IN EFI_HANDLE Controller,
  197. IN UINTN NumberOfChildren,
  198. IN EFI_HANDLE *ChildHandleBuffer
  199. );
  200. //
  201. // EFI Component Name Functions
  202. //
  203. /**
  204. Retrieves a Unicode string that is the user readable name of the driver.
  205. This function retrieves the user readable name of a driver in the form of a
  206. Unicode string. If the driver specified by This has a user readable name in
  207. the language specified by Language, then a pointer to the driver name is
  208. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  209. by This does not support the language specified by Language,
  210. then EFI_UNSUPPORTED is returned.
  211. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  212. EFI_COMPONENT_NAME_PROTOCOL instance.
  213. @param Language[in] A pointer to a Null-terminated ASCII string
  214. array indicating the language. This is the
  215. language of the driver name that the caller is
  216. requesting, and it must match one of the
  217. languages specified in SupportedLanguages. The
  218. number of languages supported by a driver is up
  219. to the driver writer. Language is specified
  220. in RFC 4646 or ISO 639-2 language code format.
  221. @param DriverName[out] A pointer to the Unicode string to return.
  222. This Unicode string is the name of the
  223. driver specified by This in the language
  224. specified by Language.
  225. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  226. This and the language specified by Language was
  227. returned in DriverName.
  228. @retval EFI_INVALID_PARAMETER Language is NULL.
  229. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  230. @retval EFI_UNSUPPORTED The driver specified by This does not support
  231. the language specified by Language.
  232. **/
  233. EFI_STATUS
  234. EFIAPI
  235. CirrusLogic5430ComponentNameGetDriverName (
  236. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  237. IN CHAR8 *Language,
  238. OUT CHAR16 **DriverName
  239. );
  240. /**
  241. Retrieves a Unicode string that is the user readable name of the controller
  242. that is being managed by a driver.
  243. This function retrieves the user readable name of the controller specified by
  244. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  245. driver specified by This has a user readable name in the language specified by
  246. Language, then a pointer to the controller name is returned in ControllerName,
  247. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  248. managing the controller specified by ControllerHandle and ChildHandle,
  249. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  250. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  251. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  252. EFI_COMPONENT_NAME_PROTOCOL instance.
  253. @param ControllerHandle[in] The handle of a controller that the driver
  254. specified by This is managing. This handle
  255. specifies the controller whose name is to be
  256. returned.
  257. @param ChildHandle[in] The handle of the child controller to retrieve
  258. the name of. This is an optional parameter that
  259. may be NULL. It will be NULL for device
  260. drivers. It will also be NULL for a bus drivers
  261. that wish to retrieve the name of the bus
  262. controller. It will not be NULL for a bus
  263. driver that wishes to retrieve the name of a
  264. child controller.
  265. @param Language[in] A pointer to a Null-terminated ASCII string
  266. array indicating the language. This is the
  267. language of the driver name that the caller is
  268. requesting, and it must match one of the
  269. languages specified in SupportedLanguages. The
  270. number of languages supported by a driver is up
  271. to the driver writer. Language is specified in
  272. RFC 4646 or ISO 639-2 language code format.
  273. @param ControllerName[out] A pointer to the Unicode string to return.
  274. This Unicode string is the name of the
  275. controller specified by ControllerHandle and
  276. ChildHandle in the language specified by
  277. Language from the point of view of the driver
  278. specified by This.
  279. @retval EFI_SUCCESS The Unicode string for the user readable name in
  280. the language specified by Language for the
  281. driver specified by This was returned in
  282. DriverName.
  283. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  284. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  285. EFI_HANDLE.
  286. @retval EFI_INVALID_PARAMETER Language is NULL.
  287. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  288. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  289. managing the controller specified by
  290. ControllerHandle and ChildHandle.
  291. @retval EFI_UNSUPPORTED The driver specified by This does not support
  292. the language specified by Language.
  293. **/
  294. EFI_STATUS
  295. EFIAPI
  296. CirrusLogic5430ComponentNameGetControllerName (
  297. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  298. IN EFI_HANDLE ControllerHandle,
  299. IN EFI_HANDLE ChildHandle OPTIONAL,
  300. IN CHAR8 *Language,
  301. OUT CHAR16 **ControllerName
  302. );
  303. //
  304. // Local Function Prototypes
  305. //
  306. VOID
  307. InitializeGraphicsMode (
  308. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  309. CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData
  310. );
  311. VOID
  312. SetPaletteColor (
  313. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  314. UINTN Index,
  315. UINT8 Red,
  316. UINT8 Green,
  317. UINT8 Blue
  318. );
  319. VOID
  320. SetDefaultPalette (
  321. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  322. );
  323. VOID
  324. DrawLogo (
  325. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  326. UINTN ScreenWidth,
  327. UINTN ScreenHeight
  328. );
  329. VOID
  330. outb (
  331. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  332. UINTN Address,
  333. UINT8 Data
  334. );
  335. VOID
  336. outw (
  337. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  338. UINTN Address,
  339. UINT16 Data
  340. );
  341. UINT8
  342. inb (
  343. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  344. UINTN Address
  345. );
  346. UINT16
  347. inw (
  348. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
  349. UINTN Address
  350. );
  351. EFI_STATUS
  352. CirrusLogic5430VideoModeSetup (
  353. CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
  354. );
  355. #endif