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