video.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. video.c
  5. Abstract:
  6. This module implements support for the ARM Integrator/CP.
  7. Author:
  8. Evan Green 7-Apr-2014
  9. Environment:
  10. Firmware
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <uefifw.h>
  16. #include <minoca/uefi/protocol/graphout.h>
  17. #include "integfw.h"
  18. #include "dev/pl110.h"
  19. //
  20. // --------------------------------------------------------------------- Macros
  21. //
  22. //
  23. // ---------------------------------------------------------------- Definitions
  24. //
  25. #define EFI_INTEGRATOR_VIDEO_DEVICE_GUID \
  26. { \
  27. 0x19EEE1EB, 0x8F2A, 0x4DFA, \
  28. {0xB0, 0xF9, 0xB1, 0x0B, 0xD5, 0xB8, 0x71, 0x05} \
  29. }
  30. #define EFI_INTEGRATOR_VIDEO_DEVICE_MAGIC 0x4969564F // 'diVI'
  31. //
  32. // Define the default mode to initialize in.
  33. //
  34. #define EFI_INTEGRATOR_VIDEO_DEFAULT_MODE 0
  35. #define EFI_INTEGRATOR_VIDEO_MODE_COUNT \
  36. (sizeof(EfiIntegratorVideoModes) / sizeof(EfiIntegratorVideoModes[0]))
  37. //
  38. // Define the size of the frame buffer to allocate, which should be large
  39. // enough to support the largest resolution.
  40. //
  41. #define EFI_INTEGRATOR_FRAME_BUFFER_SIZE (1024 * 768 * sizeof(UINT32))
  42. //
  43. // ------------------------------------------------------ Data Type Definitions
  44. //
  45. /*++
  46. Structure Description:
  47. This structure stores the integrator graphics output mode information.
  48. Members:
  49. Information - Stores the information structure.
  50. --*/
  51. typedef struct _EFI_INTEGRATOR_VIDEO_MODE {
  52. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Information;
  53. } EFI_INTEGRATOR_VIDEO_MODE, *PEFI_INTEGRATOR_VIDEO_MODE;
  54. /*++
  55. Structure Description:
  56. This structure stores the structure of an Integrator video device path.
  57. Members:
  58. VendorPath - Stores the vendor path portion of the device path.
  59. End - Stores the end device path node.
  60. --*/
  61. typedef struct _EFI_INTEGRATOR_VIDEO_DEVICE_PATH {
  62. VENDOR_DEVICE_PATH VendorPath;
  63. EFI_DEVICE_PATH_PROTOCOL End;
  64. } EFI_INTEGRATOR_VIDEO_DEVICE_PATH, *PEFI_INTEGRATOR_VIDEO_DEVICE_PATH;
  65. /*++
  66. Structure Description:
  67. This structure stores the internal context for an OMAP4 video device.
  68. Members:
  69. Magic - Stores the constant magic value EFI_INTEGRATOR_VIDEO_DEVICE_MAGIC.
  70. Handle - Stores the graphics out handle.
  71. GraphicsOut - Stores the graphics output protocol.
  72. GraphicsOutMode - Stores the graphics output protocol mode.
  73. --*/
  74. typedef struct _EFI_INTEGRATOR_VIDEO_DEVICE {
  75. UINT32 Magic;
  76. EFI_HANDLE Handle;
  77. EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOut;
  78. EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GraphicsOutMode;
  79. } EFI_INTEGRATOR_VIDEO_DEVICE, *PEFI_INTEGRATOR_VIDEO_DEVICE;
  80. //
  81. // ----------------------------------------------- Internal Function Prototypes
  82. //
  83. EFIAPI
  84. EFI_STATUS
  85. EfipIntegratorGraphicsQueryMode (
  86. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  87. UINT32 ModeNumber,
  88. UINTN *SizeOfInfo,
  89. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
  90. );
  91. EFIAPI
  92. EFI_STATUS
  93. EfipIntegratorGraphicsSetMode (
  94. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  95. UINT32 ModeNumber
  96. );
  97. EFIAPI
  98. EFI_STATUS
  99. EfipIntegratorGraphicsBlt (
  100. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  101. EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  102. EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  103. UINTN SourceX,
  104. UINTN SourceY,
  105. UINTN DestinationX,
  106. UINTN DestinationY,
  107. UINTN Width,
  108. UINTN Height,
  109. UINTN Delta
  110. );
  111. //
  112. // -------------------------------------------------------------------- Globals
  113. //
  114. EFI_PHYSICAL_ADDRESS EfiIntegratorFrameBuffer;
  115. //
  116. // Store the device path of the video controller.
  117. //
  118. EFI_INTEGRATOR_VIDEO_DEVICE_PATH EfiIntegratorVideoDevicePathTemplate = {
  119. {
  120. {
  121. HARDWARE_DEVICE_PATH,
  122. HW_VENDOR_DP,
  123. sizeof(VENDOR_DEVICE_PATH)
  124. },
  125. EFI_INTEGRATOR_VIDEO_DEVICE_GUID,
  126. },
  127. {
  128. END_DEVICE_PATH_TYPE,
  129. END_ENTIRE_DEVICE_PATH_SUBTYPE,
  130. END_DEVICE_PATH_LENGTH
  131. }
  132. };
  133. //
  134. // Define the supported video modes.
  135. //
  136. EFI_INTEGRATOR_VIDEO_MODE EfiIntegratorVideoModes[] = {
  137. {
  138. {
  139. 0,
  140. 1024,
  141. 768,
  142. PixelBitMask,
  143. {
  144. 0x00FF0000,
  145. 0x0000FF00,
  146. 0x000000FF,
  147. 0xFF000000
  148. },
  149. 1024
  150. },
  151. },
  152. };
  153. //
  154. // ------------------------------------------------------------------ Functions
  155. //
  156. EFI_STATUS
  157. EfipIntegratorEnumerateVideo (
  158. VOID
  159. )
  160. /*++
  161. Routine Description:
  162. This routine enumerates the display on the Integrator/CP.
  163. Arguments:
  164. None.
  165. Return Value:
  166. EFI status code.
  167. --*/
  168. {
  169. PEFI_INTEGRATOR_VIDEO_DEVICE Device;
  170. EFI_PHYSICAL_ADDRESS FrameBufferBase;
  171. PEFI_INTEGRATOR_VIDEO_MODE Mode;
  172. EFI_STATUS Status;
  173. FrameBufferBase = -1;
  174. Device = NULL;
  175. Mode = &(EfiIntegratorVideoModes[EFI_INTEGRATOR_VIDEO_DEFAULT_MODE]);
  176. //
  177. // Allocate space for the frame buffer.
  178. //
  179. Status = EfiAllocatePages(
  180. AllocateAnyPages,
  181. EfiMemoryMappedIO,
  182. EFI_SIZE_TO_PAGES(EFI_INTEGRATOR_FRAME_BUFFER_SIZE),
  183. &FrameBufferBase);
  184. if (EFI_ERROR(Status)) {
  185. return Status;
  186. }
  187. Status = EfipPl110Initialize(INTEGRATOR_PL110_BASE,
  188. FrameBufferBase,
  189. Mode->Information.HorizontalResolution,
  190. Mode->Information.VerticalResolution);
  191. if (EFI_ERROR(Status)) {
  192. goto EnumerateVideoEnd;
  193. }
  194. //
  195. // Everything's all set up, create the graphics output protocol.
  196. //
  197. Status = EfiAllocatePool(EfiBootServicesData,
  198. sizeof(EFI_INTEGRATOR_VIDEO_DEVICE),
  199. (VOID **)&Device);
  200. if (EFI_ERROR(Status)) {
  201. goto EnumerateVideoEnd;
  202. }
  203. EfiSetMem(Device, sizeof(EFI_INTEGRATOR_VIDEO_DEVICE), 0);
  204. Device->Magic = EFI_INTEGRATOR_VIDEO_DEVICE_MAGIC;
  205. EfiIntegratorFrameBuffer = FrameBufferBase;
  206. Device->GraphicsOut.QueryMode = EfipIntegratorGraphicsQueryMode;
  207. Device->GraphicsOut.SetMode = EfipIntegratorGraphicsSetMode;
  208. Device->GraphicsOut.Blt = EfipIntegratorGraphicsBlt;
  209. Device->GraphicsOut.Mode = &(Device->GraphicsOutMode);
  210. Device->GraphicsOutMode.MaxMode = EFI_INTEGRATOR_VIDEO_MODE_COUNT;
  211. Device->GraphicsOutMode.Mode = EFI_INTEGRATOR_VIDEO_DEFAULT_MODE;
  212. Device->GraphicsOutMode.Info = &(Mode->Information);
  213. Device->GraphicsOutMode.SizeOfInfo =
  214. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  215. Device->GraphicsOutMode.FrameBufferBase = FrameBufferBase;
  216. Device->GraphicsOutMode.FrameBufferSize = EFI_INTEGRATOR_FRAME_BUFFER_SIZE;
  217. Status = EfiInstallMultipleProtocolInterfaces(
  218. &(Device->Handle),
  219. &EfiGraphicsOutputProtocolGuid,
  220. &(Device->GraphicsOut),
  221. &EfiDevicePathProtocolGuid,
  222. &EfiIntegratorVideoDevicePathTemplate,
  223. NULL);
  224. if (EFI_ERROR(Status)) {
  225. goto EnumerateVideoEnd;
  226. }
  227. EnumerateVideoEnd:
  228. if (EFI_ERROR(Status)) {
  229. if (FrameBufferBase != -1) {
  230. EfiFreePages(FrameBufferBase,
  231. EFI_SIZE_TO_PAGES(EFI_INTEGRATOR_FRAME_BUFFER_SIZE));
  232. }
  233. if (Device != NULL) {
  234. EfiFreePool(Device);
  235. }
  236. }
  237. return Status;
  238. }
  239. //
  240. // --------------------------------------------------------- Internal Functions
  241. //
  242. EFIAPI
  243. EFI_STATUS
  244. EfipIntegratorGraphicsQueryMode (
  245. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  246. UINT32 ModeNumber,
  247. UINTN *SizeOfInfo,
  248. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
  249. )
  250. /*++
  251. Routine Description:
  252. This routine returns information about available graphics modes that the
  253. graphics device and set of active video output devices support.
  254. Arguments:
  255. This - Supplies a pointer to the protocol instance.
  256. ModeNumber - Supplies the mode number to return information about.
  257. SizeOfInfo - Supplies a pointer that on input contains the size in bytes of
  258. the information buffer.
  259. Info - Supplies a pointer where a callee-allocated buffer will be returned
  260. containing information about the mode. The caller is responsible for
  261. calling FreePool to free this data.
  262. Return Value:
  263. EFI_SUCCESS on success.
  264. EFI_DEVICE_ERROR if a hardware error occurred trying to retrieve the video
  265. mode.
  266. EFI_INVALID_PARAMETER if the mode number is not valid.
  267. --*/
  268. {
  269. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Information;
  270. EFI_STATUS Status;
  271. if ((ModeNumber >= EFI_INTEGRATOR_VIDEO_MODE_COUNT) ||
  272. (SizeOfInfo == NULL)) {
  273. return EFI_INVALID_PARAMETER;
  274. }
  275. Status = EfiAllocatePool(EfiBootServicesData,
  276. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
  277. (VOID **)&Information);
  278. if (EFI_ERROR(Status)) {
  279. return Status;
  280. }
  281. EfiCopyMem(Information,
  282. &(EfiIntegratorVideoModes[ModeNumber].Information),
  283. sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
  284. *Info = Information;
  285. *SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  286. return EFI_SUCCESS;
  287. }
  288. EFIAPI
  289. EFI_STATUS
  290. EfipIntegratorGraphicsSetMode (
  291. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  292. UINT32 ModeNumber
  293. )
  294. /*++
  295. Routine Description:
  296. This routine sets the video device into the specified mode and clears the
  297. visible portions of the output display to black.
  298. Arguments:
  299. This - Supplies a pointer to the protocol instance.
  300. ModeNumber - Supplies the mode number to set.
  301. Return Value:
  302. EFI_SUCCESS on success.
  303. EFI_DEVICE_ERROR if a hardware error occurred trying to set the video mode.
  304. EFI_UNSUPPORTED if the mode number is not supported by this device.
  305. --*/
  306. {
  307. PEFI_INTEGRATOR_VIDEO_MODE Mode;
  308. EFI_STATUS Status;
  309. if (ModeNumber >= EFI_INTEGRATOR_VIDEO_MODE_COUNT) {
  310. return EFI_UNSUPPORTED;
  311. }
  312. Mode = &(EfiIntegratorVideoModes[ModeNumber]);
  313. Status = EfipPl110Initialize(INTEGRATOR_PL110_BASE,
  314. EfiIntegratorFrameBuffer,
  315. Mode->Information.HorizontalResolution,
  316. Mode->Information.VerticalResolution);
  317. if (EFI_ERROR(Status)) {
  318. return Status;
  319. }
  320. This->Mode->Info = &(Mode->Information);
  321. This->Mode->Mode = ModeNumber;
  322. This->Mode->SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
  323. return Status;
  324. }
  325. EFIAPI
  326. EFI_STATUS
  327. EfipIntegratorGraphicsBlt (
  328. EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  329. EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  330. EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  331. UINTN SourceX,
  332. UINTN SourceY,
  333. UINTN DestinationX,
  334. UINTN DestinationY,
  335. UINTN Width,
  336. UINTN Height,
  337. UINTN Delta
  338. )
  339. /*++
  340. Routine Description:
  341. This routine performs a Blt (copy) operation of pixels on the graphics
  342. screen. Blt stands for Block Transfer for those not up on their video lingo.
  343. Arguments:
  344. This - Supplies a pointer to the protocol instance.
  345. BltBuffer - Supplies an optional pointer to the data to transfer to the
  346. graphics screen. The size must be at least width * height *
  347. sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL).
  348. BltOperation - Supplies the operation to perform when copying the buffer to
  349. the screen.
  350. SourceX - Supplies the X coordinate of the source of the operation.
  351. SourceY - Supplies the Y coordinate of the source of the operation.
  352. DestinationX - Supplies the X coordinate of the destination of the
  353. operation.
  354. DestinationY - Supplies the Y coordinate of the destination of the
  355. operation.
  356. Width - Supplies the width of the rectangle in pixels.
  357. Height - Supplies the height of the rectangle in pixels.
  358. Delta - Supplies an optional number of bytes in a row of the given buffer.
  359. If a delta of zero is used, the entire buffer is being operated on.
  360. This is not used for EfiBltVideoFill or EfiBltVideoToVideo operations.
  361. Return Value:
  362. EFI_SUCCESS on success.
  363. EFI_INVALID_PARAMETER if the operation was not valid.
  364. EFI_DEVICE_ERROR if a hardware error occurred and the request could not be
  365. completed.
  366. --*/
  367. {
  368. return EFI_UNSUPPORTED;
  369. }