1*1370a723SSascha Wildner /** @file
2*1370a723SSascha Wildner   Graphics Output Protocol from the UEFI 2.0 specification.
3*1370a723SSascha Wildner 
4*1370a723SSascha Wildner   Abstraction of a very simple graphics device.
5*1370a723SSascha Wildner 
6*1370a723SSascha Wildner   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
7*1370a723SSascha Wildner   SPDX-License-Identifier: BSD-2-Clause-Patent
8*1370a723SSascha Wildner 
9*1370a723SSascha Wildner **/
10*1370a723SSascha Wildner 
11*1370a723SSascha Wildner #ifndef __GRAPHICS_OUTPUT_H__
12*1370a723SSascha Wildner #define __GRAPHICS_OUTPUT_H__
13*1370a723SSascha Wildner 
14*1370a723SSascha Wildner #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
15*1370a723SSascha Wildner   { \
16*1370a723SSascha Wildner     0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } \
17*1370a723SSascha Wildner   }
18*1370a723SSascha Wildner 
19*1370a723SSascha Wildner typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;
20*1370a723SSascha Wildner 
21*1370a723SSascha Wildner typedef struct {
22*1370a723SSascha Wildner   UINT32            RedMask;
23*1370a723SSascha Wildner   UINT32            GreenMask;
24*1370a723SSascha Wildner   UINT32            BlueMask;
25*1370a723SSascha Wildner   UINT32            ReservedMask;
26*1370a723SSascha Wildner } EFI_PIXEL_BITMASK;
27*1370a723SSascha Wildner 
28*1370a723SSascha Wildner typedef enum {
29*1370a723SSascha Wildner   ///
30*1370a723SSascha Wildner   /// A pixel is 32-bits and byte zero represents red, byte one represents green,
31*1370a723SSascha Wildner   /// byte two represents blue, and byte three is reserved. This is the definition
32*1370a723SSascha Wildner   /// for the physical frame buffer. The byte values for the red, green, and blue
33*1370a723SSascha Wildner   /// components represent the color intensity. This color intensity value range
34*1370a723SSascha Wildner   /// from a minimum intensity of 0 to maximum intensity of 255.
35*1370a723SSascha Wildner   ///
36*1370a723SSascha Wildner   PixelRedGreenBlueReserved8BitPerColor,
37*1370a723SSascha Wildner   ///
38*1370a723SSascha Wildner   /// A pixel is 32-bits and byte zero represents blue, byte one represents green,
39*1370a723SSascha Wildner   /// byte two represents red, and byte three is reserved. This is the definition
40*1370a723SSascha Wildner   /// for the physical frame buffer. The byte values for the red, green, and blue
41*1370a723SSascha Wildner   /// components represent the color intensity. This color intensity value range
42*1370a723SSascha Wildner   /// from a minimum intensity of 0 to maximum intensity of 255.
43*1370a723SSascha Wildner   ///
44*1370a723SSascha Wildner   PixelBlueGreenRedReserved8BitPerColor,
45*1370a723SSascha Wildner   ///
46*1370a723SSascha Wildner   /// The Pixel definition of the physical frame buffer.
47*1370a723SSascha Wildner   ///
48*1370a723SSascha Wildner   PixelBitMask,
49*1370a723SSascha Wildner   ///
50*1370a723SSascha Wildner   /// This mode does not support a physical frame buffer.
51*1370a723SSascha Wildner   ///
52*1370a723SSascha Wildner   PixelBltOnly,
53*1370a723SSascha Wildner   ///
54*1370a723SSascha Wildner   /// Valid EFI_GRAPHICS_PIXEL_FORMAT enum values are less than this value.
55*1370a723SSascha Wildner   ///
56*1370a723SSascha Wildner   PixelFormatMax
57*1370a723SSascha Wildner } EFI_GRAPHICS_PIXEL_FORMAT;
58*1370a723SSascha Wildner 
59*1370a723SSascha Wildner typedef struct {
60*1370a723SSascha Wildner   ///
61*1370a723SSascha Wildner   /// The version of this data structure. A value of zero represents the
62*1370a723SSascha Wildner   /// EFI_GRAPHICS_OUTPUT_MODE_INFORMATION structure as defined in this specification.
63*1370a723SSascha Wildner   ///
64*1370a723SSascha Wildner   UINT32                     Version;
65*1370a723SSascha Wildner   ///
66*1370a723SSascha Wildner   /// The size of video screen in pixels in the X dimension.
67*1370a723SSascha Wildner   ///
68*1370a723SSascha Wildner   UINT32                     HorizontalResolution;
69*1370a723SSascha Wildner   ///
70*1370a723SSascha Wildner   /// The size of video screen in pixels in the Y dimension.
71*1370a723SSascha Wildner   ///
72*1370a723SSascha Wildner   UINT32                     VerticalResolution;
73*1370a723SSascha Wildner   ///
74*1370a723SSascha Wildner   /// Enumeration that defines the physical format of the pixel. A value of PixelBltOnly
75*1370a723SSascha Wildner   /// implies that a linear frame buffer is not available for this mode.
76*1370a723SSascha Wildner   ///
77*1370a723SSascha Wildner   EFI_GRAPHICS_PIXEL_FORMAT  PixelFormat;
78*1370a723SSascha Wildner   ///
79*1370a723SSascha Wildner   /// This bit-mask is only valid if PixelFormat is set to PixelPixelBitMask.
80*1370a723SSascha Wildner   /// A bit being set defines what bits are used for what purpose such as Red, Green, Blue, or Reserved.
81*1370a723SSascha Wildner   ///
82*1370a723SSascha Wildner   EFI_PIXEL_BITMASK          PixelInformation;
83*1370a723SSascha Wildner   ///
84*1370a723SSascha Wildner   /// Defines the number of pixel elements per video memory line.
85*1370a723SSascha Wildner   ///
86*1370a723SSascha Wildner   UINT32                     PixelsPerScanLine;
87*1370a723SSascha Wildner } EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;
88*1370a723SSascha Wildner 
89*1370a723SSascha Wildner /**
90*1370a723SSascha Wildner   Returns information for an available graphics mode that the graphics device
91*1370a723SSascha Wildner   and the set of active video output devices supports.
92*1370a723SSascha Wildner 
93*1370a723SSascha Wildner   @param  This                  The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
94*1370a723SSascha Wildner   @param  ModeNumber            The mode number to return information on.
95*1370a723SSascha Wildner   @param  SizeOfInfo            A pointer to the size, in bytes, of the Info buffer.
96*1370a723SSascha Wildner   @param  Info                  A pointer to callee allocated buffer that returns information about ModeNumber.
97*1370a723SSascha Wildner 
98*1370a723SSascha Wildner   @retval EFI_SUCCESS           Valid mode information was returned.
99*1370a723SSascha Wildner   @retval EFI_DEVICE_ERROR      A hardware error occurred trying to retrieve the video mode.
100*1370a723SSascha Wildner   @retval EFI_INVALID_PARAMETER ModeNumber is not valid.
101*1370a723SSascha Wildner 
102*1370a723SSascha Wildner **/
103*1370a723SSascha Wildner typedef
104*1370a723SSascha Wildner EFI_STATUS
105*1370a723SSascha Wildner (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
106*1370a723SSascha Wildner   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL          *This,
107*1370a723SSascha Wildner   IN  UINT32                                ModeNumber,
108*1370a723SSascha Wildner   OUT UINTN                                 *SizeOfInfo,
109*1370a723SSascha Wildner   OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  **Info
110*1370a723SSascha Wildner   );
111*1370a723SSascha Wildner 
112*1370a723SSascha Wildner /**
113*1370a723SSascha Wildner   Set the video device into the specified mode and clears the visible portions of
114*1370a723SSascha Wildner   the output display to black.
115*1370a723SSascha Wildner 
116*1370a723SSascha Wildner   @param  This              The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
117*1370a723SSascha Wildner   @param  ModeNumber        Abstraction that defines the current video mode.
118*1370a723SSascha Wildner 
119*1370a723SSascha Wildner   @retval EFI_SUCCESS       The graphics mode specified by ModeNumber was selected.
120*1370a723SSascha Wildner   @retval EFI_DEVICE_ERROR  The device had an error and could not complete the request.
121*1370a723SSascha Wildner   @retval EFI_UNSUPPORTED   ModeNumber is not supported by this device.
122*1370a723SSascha Wildner 
123*1370a723SSascha Wildner **/
124*1370a723SSascha Wildner typedef
125*1370a723SSascha Wildner EFI_STATUS
126*1370a723SSascha Wildner (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
127*1370a723SSascha Wildner   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
128*1370a723SSascha Wildner   IN  UINT32                       ModeNumber
129*1370a723SSascha Wildner   );
130*1370a723SSascha Wildner 
131*1370a723SSascha Wildner typedef struct {
132*1370a723SSascha Wildner   UINT8 Blue;
133*1370a723SSascha Wildner   UINT8 Green;
134*1370a723SSascha Wildner   UINT8 Red;
135*1370a723SSascha Wildner   UINT8 Reserved;
136*1370a723SSascha Wildner } EFI_GRAPHICS_OUTPUT_BLT_PIXEL;
137*1370a723SSascha Wildner 
138*1370a723SSascha Wildner typedef union {
139*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_BLT_PIXEL Pixel;
140*1370a723SSascha Wildner   UINT32                        Raw;
141*1370a723SSascha Wildner } EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION;
142*1370a723SSascha Wildner 
143*1370a723SSascha Wildner ///
144*1370a723SSascha Wildner /// actions for BltOperations
145*1370a723SSascha Wildner ///
146*1370a723SSascha Wildner typedef enum {
147*1370a723SSascha Wildner   ///
148*1370a723SSascha Wildner   /// Write data from the BltBuffer pixel (0, 0)
149*1370a723SSascha Wildner   /// directly to every pixel of the video display rectangle
150*1370a723SSascha Wildner   /// (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height).
151*1370a723SSascha Wildner   /// Only one pixel will be used from the BltBuffer. Delta is NOT used.
152*1370a723SSascha Wildner   ///
153*1370a723SSascha Wildner   EfiBltVideoFill,
154*1370a723SSascha Wildner 
155*1370a723SSascha Wildner   ///
156*1370a723SSascha Wildner   /// Read data from the video display rectangle
157*1370a723SSascha Wildner   /// (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
158*1370a723SSascha Wildner   /// the BltBuffer rectangle (DestinationX, DestinationY )
159*1370a723SSascha Wildner   /// (DestinationX + Width, DestinationY + Height). If DestinationX or
160*1370a723SSascha Wildner   /// DestinationY is not zero then Delta must be set to the length in bytes
161*1370a723SSascha Wildner   /// of a row in the BltBuffer.
162*1370a723SSascha Wildner   ///
163*1370a723SSascha Wildner   EfiBltVideoToBltBuffer,
164*1370a723SSascha Wildner 
165*1370a723SSascha Wildner   ///
166*1370a723SSascha Wildner   /// Write data from the BltBuffer rectangle
167*1370a723SSascha Wildner   /// (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
168*1370a723SSascha Wildner   /// video display rectangle (DestinationX, DestinationY)
169*1370a723SSascha Wildner   /// (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
170*1370a723SSascha Wildner   /// not zero then Delta must be set to the length in bytes of a row in the
171*1370a723SSascha Wildner   /// BltBuffer.
172*1370a723SSascha Wildner   ///
173*1370a723SSascha Wildner   EfiBltBufferToVideo,
174*1370a723SSascha Wildner 
175*1370a723SSascha Wildner   ///
176*1370a723SSascha Wildner   /// Copy from the video display rectangle (SourceX, SourceY)
177*1370a723SSascha Wildner   /// (SourceX + Width, SourceY + Height) to the video display rectangle
178*1370a723SSascha Wildner   /// (DestinationX, DestinationY) (DestinationX + Width, DestinationY + Height).
179*1370a723SSascha Wildner   /// The BltBuffer and Delta are not used in this mode.
180*1370a723SSascha Wildner   ///
181*1370a723SSascha Wildner   EfiBltVideoToVideo,
182*1370a723SSascha Wildner 
183*1370a723SSascha Wildner   EfiGraphicsOutputBltOperationMax
184*1370a723SSascha Wildner } EFI_GRAPHICS_OUTPUT_BLT_OPERATION;
185*1370a723SSascha Wildner 
186*1370a723SSascha Wildner /**
187*1370a723SSascha Wildner   Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
188*1370a723SSascha Wildner 
189*1370a723SSascha Wildner   @param  This         Protocol instance pointer.
190*1370a723SSascha Wildner   @param  BltBuffer    The data to transfer to the graphics screen.
191*1370a723SSascha Wildner                        Size is at least Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL).
192*1370a723SSascha Wildner   @param  BltOperation The operation to perform when copying BltBuffer on to the graphics screen.
193*1370a723SSascha Wildner   @param  SourceX      The X coordinate of source for the BltOperation.
194*1370a723SSascha Wildner   @param  SourceY      The Y coordinate of source for the BltOperation.
195*1370a723SSascha Wildner   @param  DestinationX The X coordinate of destination for the BltOperation.
196*1370a723SSascha Wildner   @param  DestinationY The Y coordinate of destination for the BltOperation.
197*1370a723SSascha Wildner   @param  Width        The width of a rectangle in the blt rectangle in pixels.
198*1370a723SSascha Wildner   @param  Height       The height of a rectangle in the blt rectangle in pixels.
199*1370a723SSascha Wildner   @param  Delta        Not used for EfiBltVideoFill or the EfiBltVideoToVideo operation.
200*1370a723SSascha Wildner                        If a Delta of zero is used, the entire BltBuffer is being operated on.
201*1370a723SSascha Wildner                        If a subrectangle of the BltBuffer is being used then Delta
202*1370a723SSascha Wildner                        represents the number of bytes in a row of the BltBuffer.
203*1370a723SSascha Wildner 
204*1370a723SSascha Wildner   @retval EFI_SUCCESS           BltBuffer was drawn to the graphics screen.
205*1370a723SSascha Wildner   @retval EFI_INVALID_PARAMETER BltOperation is not valid.
206*1370a723SSascha Wildner   @retval EFI_DEVICE_ERROR      The device had an error and could not complete the request.
207*1370a723SSascha Wildner 
208*1370a723SSascha Wildner **/
209*1370a723SSascha Wildner typedef
210*1370a723SSascha Wildner EFI_STATUS
211*1370a723SSascha Wildner (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
212*1370a723SSascha Wildner   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL            *This,
213*1370a723SSascha Wildner   IN  EFI_GRAPHICS_OUTPUT_BLT_PIXEL           *BltBuffer    OPTIONAL,
214*1370a723SSascha Wildner   IN  EFI_GRAPHICS_OUTPUT_BLT_OPERATION       BltOperation,
215*1370a723SSascha Wildner   IN  UINTN                                   SourceX,
216*1370a723SSascha Wildner   IN  UINTN                                   SourceY,
217*1370a723SSascha Wildner   IN  UINTN                                   DestinationX,
218*1370a723SSascha Wildner   IN  UINTN                                   DestinationY,
219*1370a723SSascha Wildner   IN  UINTN                                   Width,
220*1370a723SSascha Wildner   IN  UINTN                                   Height,
221*1370a723SSascha Wildner   IN  UINTN                                   Delta         OPTIONAL
222*1370a723SSascha Wildner   );
223*1370a723SSascha Wildner 
224*1370a723SSascha Wildner typedef struct {
225*1370a723SSascha Wildner   ///
226*1370a723SSascha Wildner   /// The number of modes supported by QueryMode() and SetMode().
227*1370a723SSascha Wildner   ///
228*1370a723SSascha Wildner   UINT32                                 MaxMode;
229*1370a723SSascha Wildner   ///
230*1370a723SSascha Wildner   /// Current Mode of the graphics device. Valid mode numbers are 0 to MaxMode -1.
231*1370a723SSascha Wildner   ///
232*1370a723SSascha Wildner   UINT32                                 Mode;
233*1370a723SSascha Wildner   ///
234*1370a723SSascha Wildner   /// Pointer to read-only EFI_GRAPHICS_OUTPUT_MODE_INFORMATION data.
235*1370a723SSascha Wildner   ///
236*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION   *Info;
237*1370a723SSascha Wildner   ///
238*1370a723SSascha Wildner   /// Size of Info structure in bytes.
239*1370a723SSascha Wildner   ///
240*1370a723SSascha Wildner   UINTN                                  SizeOfInfo;
241*1370a723SSascha Wildner   ///
242*1370a723SSascha Wildner   /// Base address of graphics linear frame buffer.
243*1370a723SSascha Wildner   /// Offset zero in FrameBufferBase represents the upper left pixel of the display.
244*1370a723SSascha Wildner   ///
245*1370a723SSascha Wildner   EFI_PHYSICAL_ADDRESS                   FrameBufferBase;
246*1370a723SSascha Wildner   ///
247*1370a723SSascha Wildner   /// Amount of frame buffer needed to support the active mode as defined by
248*1370a723SSascha Wildner   /// PixelsPerScanLine xVerticalResolution x PixelElementSize.
249*1370a723SSascha Wildner   ///
250*1370a723SSascha Wildner   UINTN                                  FrameBufferSize;
251*1370a723SSascha Wildner } EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;
252*1370a723SSascha Wildner 
253*1370a723SSascha Wildner ///
254*1370a723SSascha Wildner /// Provides a basic abstraction to set video modes and copy pixels to and from
255*1370a723SSascha Wildner /// the graphics controller's frame buffer. The linear address of the hardware
256*1370a723SSascha Wildner /// frame buffer is also exposed so software can write directly to the video hardware.
257*1370a723SSascha Wildner ///
258*1370a723SSascha Wildner struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
259*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE  QueryMode;
260*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE    SetMode;
261*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT         Blt;
262*1370a723SSascha Wildner   ///
263*1370a723SSascha Wildner   /// Pointer to EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE data.
264*1370a723SSascha Wildner   ///
265*1370a723SSascha Wildner   EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE        *Mode;
266*1370a723SSascha Wildner };
267*1370a723SSascha Wildner 
268*1370a723SSascha Wildner extern EFI_GUID gEfiGraphicsOutputProtocolGuid;
269*1370a723SSascha Wildner 
270*1370a723SSascha Wildner #endif
271