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