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