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