BiosVideo.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /** @file
  2. Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #ifndef _BIOS_GRAPHICS_OUTPUT_H_
  6. #define _BIOS_GRAPHICS_OUTPUT_H_
  7. #include <FrameworkDxe.h>
  8. #include <Protocol/PciIo.h>
  9. #include <Protocol/EdidActive.h>
  10. #include <Protocol/DevicePath.h>
  11. #include <Protocol/EdidDiscovered.h>
  12. #include <Protocol/LegacyBios.h>
  13. #include <Protocol/VgaMiniPort.h>
  14. #include <Protocol/GraphicsOutput.h>
  15. #include <Protocol/EdidOverride.h>
  16. #include <Guid/StatusCodeDataTypeId.h>
  17. #include <Guid/LegacyBios.h>
  18. #include <Guid/EventGroup.h>
  19. #include <Library/PcdLib.h>
  20. #include <Library/DebugLib.h>
  21. #include <Library/ReportStatusCodeLib.h>
  22. #include <Library/BaseMemoryLib.h>
  23. #include <Library/UefiDriverEntryPoint.h>
  24. #include <Library/UefiBootServicesTableLib.h>
  25. #include <Library/UefiLib.h>
  26. #include <Library/DevicePathLib.h>
  27. #include <Library/MemoryAllocationLib.h>
  28. #include <IndustryStandard/Pci.h>
  29. #include "VesaBiosExtensions.h"
  30. //
  31. // Packed format support: The number of bits reserved for each of the colors and the actual
  32. // position of RGB in the frame buffer is specified in the VBE Mode information
  33. //
  34. typedef struct {
  35. UINT8 Position; // Position of the color
  36. UINT8 Mask; // The number of bits expressed as a mask
  37. } BIOS_VIDEO_COLOR_PLACEMENT;
  38. //
  39. // BIOS Graphics Output Graphical Mode Data
  40. //
  41. typedef struct {
  42. UINT16 VbeModeNumber;
  43. UINT16 BytesPerScanLine;
  44. VOID *LinearFrameBuffer;
  45. UINTN FrameBufferSize;
  46. UINT32 HorizontalResolution;
  47. UINT32 VerticalResolution;
  48. UINT32 ColorDepth;
  49. UINT32 RefreshRate;
  50. UINT32 BitsPerPixel;
  51. BIOS_VIDEO_COLOR_PLACEMENT Red;
  52. BIOS_VIDEO_COLOR_PLACEMENT Green;
  53. BIOS_VIDEO_COLOR_PLACEMENT Blue;
  54. BIOS_VIDEO_COLOR_PLACEMENT Reserved;
  55. EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  56. EFI_PIXEL_BITMASK PixelBitMask;
  57. } BIOS_VIDEO_MODE_DATA;
  58. //
  59. // BIOS video child handle private data Structure
  60. //
  61. #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
  62. typedef struct {
  63. UINTN Signature;
  64. EFI_HANDLE Handle;
  65. //
  66. // Consumed Protocols
  67. //
  68. EFI_PCI_IO_PROTOCOL *PciIo;
  69. EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
  70. //
  71. // Produced Protocols
  72. //
  73. EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
  74. EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
  75. EFI_EDID_ACTIVE_PROTOCOL EdidActive;
  76. EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
  77. //
  78. // General fields
  79. //
  80. BOOLEAN VgaCompatible;
  81. BOOLEAN ProduceGraphicsOutput;
  82. //
  83. // Graphics Output Protocol related fields
  84. //
  85. BOOLEAN HardwareNeedsStarting;
  86. UINTN CurrentMode;
  87. UINTN MaxMode;
  88. BIOS_VIDEO_MODE_DATA *ModeData;
  89. UINT8 *LineBuffer;
  90. EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
  91. UINT8 *VgaFrameBuffer;
  92. //
  93. // VESA Bios Extensions related fields
  94. //
  95. UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
  96. EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
  97. VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
  98. VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
  99. VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
  100. VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
  101. UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
  102. EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
  103. //
  104. // Status code
  105. //
  106. EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
  107. EFI_EVENT ExitBootServicesEvent;
  108. } BIOS_VIDEO_DEV;
  109. #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
  110. #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
  111. #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
  112. #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
  113. //
  114. // Global Variables
  115. //
  116. extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
  117. extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
  118. extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
  119. //
  120. // Driver Binding Protocol functions
  121. //
  122. /**
  123. Supported.
  124. @param This Pointer to driver binding protocol
  125. @param Controller Controller handle to connect
  126. @param RemainingDevicePath A pointer to the remaining portion of a device
  127. path
  128. @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
  129. driver, Otherwise, this controller cannot be
  130. managed by this driver
  131. **/
  132. EFI_STATUS
  133. EFIAPI
  134. BiosVideoDriverBindingSupported (
  135. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  136. IN EFI_HANDLE Controller,
  137. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  138. );
  139. /**
  140. Install Graphics Output Protocol onto VGA device handles.
  141. @param This Pointer to driver binding protocol
  142. @param Controller Controller handle to connect
  143. @param RemainingDevicePath A pointer to the remaining portion of a device
  144. path
  145. @return EFI_STATUS
  146. **/
  147. EFI_STATUS
  148. EFIAPI
  149. BiosVideoDriverBindingStart (
  150. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  151. IN EFI_HANDLE Controller,
  152. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  153. );
  154. /**
  155. Stop.
  156. @param This Pointer to driver binding protocol
  157. @param Controller Controller handle to connect
  158. @param NumberOfChildren Number of children handle created by this driver
  159. @param ChildHandleBuffer Buffer containing child handle created
  160. @retval EFI_SUCCESS Driver disconnected successfully from controller
  161. @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
  162. **/
  163. EFI_STATUS
  164. EFIAPI
  165. BiosVideoDriverBindingStop (
  166. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  167. IN EFI_HANDLE Controller,
  168. IN UINTN NumberOfChildren,
  169. IN EFI_HANDLE *ChildHandleBuffer
  170. );
  171. //
  172. // Private worker functions
  173. //
  174. /**
  175. Check for VBE device.
  176. @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
  177. @retval EFI_SUCCESS VBE device found
  178. **/
  179. EFI_STATUS
  180. BiosVideoCheckForVbe (
  181. IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
  182. );
  183. /**
  184. Check for VGA device.
  185. @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
  186. @retval EFI_SUCCESS Standard VGA device found
  187. **/
  188. EFI_STATUS
  189. BiosVideoCheckForVga (
  190. IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
  191. );
  192. /**
  193. Release resource for BIOS video instance.
  194. @param BiosVideoPrivate Video child device private data structure
  195. **/
  196. VOID
  197. BiosVideoDeviceReleaseResource (
  198. BIOS_VIDEO_DEV *BiosVideoPrivate
  199. );
  200. //
  201. // BIOS Graphics Output Protocol functions
  202. //
  203. /**
  204. Graphics Output protocol interface to get video mode.
  205. @param This Protocol instance pointer.
  206. @param ModeNumber The mode number to return information on.
  207. @param SizeOfInfo A pointer to the size, in bytes, of the Info
  208. buffer.
  209. @param Info Caller allocated buffer that returns information
  210. about ModeNumber.
  211. @retval EFI_SUCCESS Mode information returned.
  212. @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
  213. @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
  214. video mode.
  215. @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
  216. @retval EFI_INVALID_PARAMETER One of the input args was NULL.
  217. **/
  218. EFI_STATUS
  219. EFIAPI
  220. BiosVideoGraphicsOutputQueryMode (
  221. IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  222. IN UINT32 ModeNumber,
  223. OUT UINTN *SizeOfInfo,
  224. OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
  225. );
  226. /**
  227. Graphics Output protocol interface to set video mode.
  228. @param This Protocol instance pointer.
  229. @param ModeNumber The mode number to be set.
  230. @retval EFI_SUCCESS Graphics mode was changed.
  231. @retval EFI_DEVICE_ERROR The device had an error and could not complete the
  232. request.
  233. @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
  234. **/
  235. EFI_STATUS
  236. EFIAPI
  237. BiosVideoGraphicsOutputSetMode (
  238. IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  239. IN UINT32 ModeNumber
  240. );
  241. /**
  242. Graphics Output protocol instance to block transfer for VBE device.
  243. @param This Pointer to Graphics Output protocol instance
  244. @param BltBuffer The data to transfer to screen
  245. @param BltOperation The operation to perform
  246. @param SourceX The X coordinate of the source for BltOperation
  247. @param SourceY The Y coordinate of the source for BltOperation
  248. @param DestinationX The X coordinate of the destination for
  249. BltOperation
  250. @param DestinationY The Y coordinate of the destination for
  251. BltOperation
  252. @param Width The width of a rectangle in the blt rectangle in
  253. pixels
  254. @param Height The height of a rectangle in the blt rectangle in
  255. pixels
  256. @param Delta Not used for EfiBltVideoFill and
  257. EfiBltVideoToVideo operation. If a Delta of 0 is
  258. used, the entire BltBuffer will be operated on. If
  259. a subrectangle of the BltBuffer is used, then
  260. Delta represents the number of bytes in a row of
  261. the BltBuffer.
  262. @retval EFI_INVALID_PARAMETER Invalid parameter passed in
  263. @retval EFI_SUCCESS Blt operation success
  264. **/
  265. EFI_STATUS
  266. EFIAPI
  267. BiosVideoGraphicsOutputVbeBlt (
  268. IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  269. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
  270. IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  271. IN UINTN SourceX,
  272. IN UINTN SourceY,
  273. IN UINTN DestinationX,
  274. IN UINTN DestinationY,
  275. IN UINTN Width,
  276. IN UINTN Height,
  277. IN UINTN Delta
  278. );
  279. /**
  280. Graphics Output protocol instance to block transfer for VGA device.
  281. @param This Pointer to Graphics Output protocol instance
  282. @param BltBuffer The data to transfer to screen
  283. @param BltOperation The operation to perform
  284. @param SourceX The X coordinate of the source for BltOperation
  285. @param SourceY The Y coordinate of the source for BltOperation
  286. @param DestinationX The X coordinate of the destination for
  287. BltOperation
  288. @param DestinationY The Y coordinate of the destination for
  289. BltOperation
  290. @param Width The width of a rectangle in the blt rectangle in
  291. pixels
  292. @param Height The height of a rectangle in the blt rectangle in
  293. pixels
  294. @param Delta Not used for EfiBltVideoFill and
  295. EfiBltVideoToVideo operation. If a Delta of 0 is
  296. used, the entire BltBuffer will be operated on. If
  297. a subrectangle of the BltBuffer is used, then
  298. Delta represents the number of bytes in a row of
  299. the BltBuffer.
  300. @retval EFI_INVALID_PARAMETER Invalid parameter passed in
  301. @retval EFI_SUCCESS Blt operation success
  302. **/
  303. EFI_STATUS
  304. EFIAPI
  305. BiosVideoGraphicsOutputVgaBlt (
  306. IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
  307. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
  308. IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  309. IN UINTN SourceX,
  310. IN UINTN SourceY,
  311. IN UINTN DestinationX,
  312. IN UINTN DestinationY,
  313. IN UINTN Width,
  314. IN UINTN Height,
  315. IN UINTN Delta
  316. );
  317. //
  318. // BIOS VGA Mini Port Protocol functions
  319. //
  320. /**
  321. VgaMiniPort protocol interface to set mode.
  322. @param This Pointer to VgaMiniPort protocol instance
  323. @param ModeNumber The index of the mode
  324. @retval EFI_UNSUPPORTED The requested mode is not supported
  325. @retval EFI_SUCCESS The requested mode is set successfully
  326. **/
  327. EFI_STATUS
  328. EFIAPI
  329. BiosVideoVgaMiniPortSetMode (
  330. IN EFI_VGA_MINI_PORT_PROTOCOL *This,
  331. IN UINTN ModeNumber
  332. );
  333. /**
  334. Event handler for Exit Boot Service.
  335. @param Event The event that be signalled when exiting boot service.
  336. @param Context Pointer to instance of BIOS_VIDEO_DEV.
  337. **/
  338. VOID
  339. EFIAPI
  340. BiosVideoNotifyExitBootServices (
  341. IN EFI_EVENT Event,
  342. IN VOID *Context
  343. );
  344. //
  345. // Standard VGA Definitions
  346. //
  347. #define VGA_HORIZONTAL_RESOLUTION 640
  348. #define VGA_VERTICAL_RESOLUTION 480
  349. #define VGA_NUMBER_OF_BIT_PLANES 4
  350. #define VGA_PIXELS_PER_BYTE 8
  351. #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
  352. #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
  353. #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
  354. #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
  355. #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
  356. #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
  357. #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
  358. #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
  359. #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
  360. #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
  361. #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
  362. #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
  363. #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
  364. #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
  365. #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
  366. #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
  367. #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
  368. #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
  369. #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
  370. #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
  371. #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
  372. #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
  373. #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
  374. /**
  375. Install child handles if the Handle supports MBR format.
  376. @param This Calling context.
  377. @param ParentHandle Parent Handle
  378. @param ParentPciIo Parent PciIo interface
  379. @param ParentLegacyBios Parent LegacyBios interface
  380. @param ParentDevicePath Parent Device Path
  381. @param RemainingDevicePath Remaining Device Path
  382. @retval EFI_SUCCESS If a child handle was added
  383. @retval other A child handle was not added
  384. **/
  385. EFI_STATUS
  386. BiosVideoChildHandleInstall (
  387. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  388. IN EFI_HANDLE ParentHandle,
  389. IN EFI_PCI_IO_PROTOCOL *ParentPciIo,
  390. IN EFI_LEGACY_BIOS_PROTOCOL *ParentLegacyBios,
  391. IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
  392. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  393. );
  394. /**
  395. Deregister an video child handle and free resources.
  396. @param This Protocol instance pointer.
  397. @param Controller Video controller handle
  398. @param Handle Video child handle
  399. @return EFI_STATUS
  400. **/
  401. EFI_STATUS
  402. BiosVideoChildHandleUninstall (
  403. EFI_DRIVER_BINDING_PROTOCOL *This,
  404. EFI_HANDLE Controller,
  405. EFI_HANDLE Handle
  406. );
  407. /**
  408. Release resource for BIOS video instance.
  409. @param BiosVideoPrivate Video child device private data structure
  410. **/
  411. VOID
  412. BiosVideoDeviceReleaseResource (
  413. BIOS_VIDEO_DEV *BiosVideoPrivate
  414. );
  415. /**
  416. Check if all video child handles have been uninstalled.
  417. @param Controller Video controller handle
  418. @return TRUE Child handles exist.
  419. @return FALSE All video child handles have been uninstalled.
  420. **/
  421. BOOLEAN
  422. HasChildHandle (
  423. IN EFI_HANDLE Controller
  424. );
  425. #endif