]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Bus/Pci/CirrusLogic/Dxe/CirrusLogic5430UgaDraw.c
Make EdkModulePkg pass Intel IPF compiler with /W4 /WX switches, solving warning...
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / CirrusLogic / Dxe / CirrusLogic5430UgaDraw.c
CommitLineData
ed72955c 1/** @file\r
878ddf1f 2 This file produces the graphics abstration of UGA Draw. It is called by \r
3 CirrusLogic5430.c file which deals with the EFI 1.1 driver model. \r
4 This file just does graphics.\r
5\r
ed72955c 6 Copyright (c) 2006, Intel Corporation \r
7 All rights reserved. This program and the accompanying materials \r
8 are licensed and made available under the terms and conditions of the BSD License \r
9 which accompanies this distribution. The full text of the license may be found at \r
10 http://opensource.org/licenses/bsd-license.php \r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
14\r
15**/\r
878ddf1f 16\r
17#include "CirrusLogic5430.h"\r
18\r
92dda53e 19STATIC\r
20VOID\r
21ClearScreen (\r
22 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
23 );\r
878ddf1f 24\r
ed72955c 25///\r
26/// Generic Attribute Controller Register Settings\r
27///\r
878ddf1f 28static UINT8 AttributeController[21] = {\r
29 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \r
30 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, \r
31 0x41, 0x00, 0x0F, 0x00, 0x00\r
32};\r
33\r
ed72955c 34///\r
35/// Generic Graphics Controller Register Settings\r
36///\r
878ddf1f 37static UINT8 GraphicsController[9] = {\r
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xFF\r
39};\r
40\r
41//\r
42// 640 x 480 x 256 color @ 60 Hertz\r
43//\r
44static UINT8 Crtc_640_480_256_60[28] = {\r
45 0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e,\r
46 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
47 0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3,\r
48 0xff, 0x00, 0x00, 0x22\r
49};\r
50\r
51static UINT16 Seq_640_480_256_60[15] = {\r
52 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, \r
53 0x5b0c, 0x450d, 0x7e0e, 0x2b1b, 0x2f1c, 0x301d, 0x331e\r
54};\r
55\r
56//\r
57// 800 x 600 x 256 color @ 60 Hertz\r
58//\r
59static UINT8 Crtc_800_600_256_60[28] = {\r
60 0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0, \r
61 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
62 0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3,\r
63 0xFF, 0x00, 0x00, 0x22\r
64};\r
65\r
66static UINT16 Seq_800_600_256_60[15] = {\r
67 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, \r
68 0x5b0c, 0x450d, 0x510e, 0x2b1b, 0x2f1c, 0x301d, 0x3a1e\r
69};\r
70\r
71//\r
72// 1024 x 768 x 256 color @ 60 Hertz\r
73//\r
74static UINT8 Crtc_1024_768_256_60[28] = {\r
75 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD, \r
76 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \r
77 0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3,\r
78 0xFF, 0x4A, 0x00, 0x22\r
79};\r
80\r
81static UINT16 Seq_1024_768_256_60[15] = {\r
82 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, \r
83 0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e\r
84};\r
85\r
ed72955c 86///\r
87/// Table of supported video modes\r
88///\r
878ddf1f 89static CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = {\r
90 { 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 },\r
91 { 800, 600, 8, 60, Crtc_800_600_256_60, Seq_800_600_256_60, 0xef }, \r
92 { 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef } \r
93};\r
94\r
878ddf1f 95//\r
96// UGA Draw Protocol Member Functions\r
97//\r
ed72955c 98/**\r
99 TODO: Add function description\r
100\r
101 @param This TODO: add argument description\r
102 @param HorizontalResolution TODO: add argument description\r
103 @param VerticalResolution TODO: add argument description\r
104 @param ColorDepth TODO: add argument description\r
105 @param RefreshRate TODO: add argument description\r
106\r
107 @retval EFI_NOT_STARTED TODO: Add description for return value\r
108 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
109 @retval EFI_SUCCESS TODO: Add description for return value\r
110\r
111**/\r
1cc8ee78 112STATIC\r
878ddf1f 113EFI_STATUS\r
114EFIAPI\r
115CirrusLogic5430UgaDrawGetMode (\r
116 IN EFI_UGA_DRAW_PROTOCOL *This,\r
117 OUT UINT32 *HorizontalResolution,\r
118 OUT UINT32 *VerticalResolution,\r
119 OUT UINT32 *ColorDepth,\r
120 OUT UINT32 *RefreshRate\r
121 )\r
878ddf1f 122{\r
123 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r
124\r
125 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);\r
126\r
127 if (Private->HardwareNeedsStarting) {\r
128 return EFI_NOT_STARTED;\r
129 }\r
130\r
131 if ((HorizontalResolution == NULL) ||\r
132 (VerticalResolution == NULL) ||\r
133 (ColorDepth == NULL) ||\r
134 (RefreshRate == NULL)) {\r
135 return EFI_INVALID_PARAMETER;\r
136 }\r
137\r
138 *HorizontalResolution = Private->ModeData[Private->CurrentMode].HorizontalResolution;\r
139 *VerticalResolution = Private->ModeData[Private->CurrentMode].VerticalResolution;\r
140 *ColorDepth = Private->ModeData[Private->CurrentMode].ColorDepth;\r
141 *RefreshRate = Private->ModeData[Private->CurrentMode].RefreshRate;\r
142\r
143 return EFI_SUCCESS;\r
144}\r
145\r
ed72955c 146/**\r
147 TODO: Add function description\r
148\r
149 @param This TODO: add argument description\r
150 @param HorizontalResolution TODO: add argument description\r
151 @param VerticalResolution TODO: add argument description\r
152 @param ColorDepth TODO: add argument description\r
153 @param RefreshRate TODO: add argument description\r
154\r
155 @retval EFI_OUT_OF_RESOURCES TODO: Add description for return value\r
156 @retval EFI_SUCCESS TODO: Add description for return value\r
157 @retval EFI_NOT_FOUND TODO: Add description for return value\r
158\r
159**/\r
1cc8ee78 160STATIC\r
878ddf1f 161EFI_STATUS\r
162EFIAPI\r
163CirrusLogic5430UgaDrawSetMode (\r
164 IN EFI_UGA_DRAW_PROTOCOL *This,\r
165 IN UINT32 HorizontalResolution,\r
166 IN UINT32 VerticalResolution,\r
167 IN UINT32 ColorDepth,\r
168 IN UINT32 RefreshRate\r
169 )\r
878ddf1f 170{\r
171 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r
172 UINTN Index;\r
173\r
174 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);\r
175\r
176 for (Index = 0; Index < Private->MaxMode; Index++) {\r
177\r
178 if (HorizontalResolution != Private->ModeData[Index].HorizontalResolution) {\r
179 continue;\r
180 }\r
181\r
182 if (VerticalResolution != Private->ModeData[Index].VerticalResolution) {\r
183 continue;\r
184 }\r
185\r
186 if (ColorDepth != Private->ModeData[Index].ColorDepth) {\r
187 continue;\r
188 }\r
189\r
190 if (RefreshRate != Private->ModeData[Index].RefreshRate) {\r
191 continue;\r
192 }\r
193\r
194 if (Private->LineBuffer) {\r
195 gBS->FreePool (Private->LineBuffer);\r
196 }\r
197\r
198 Private->LineBuffer = NULL;\r
199 Private->LineBuffer = AllocatePool (HorizontalResolution);\r
200 if (Private->LineBuffer == NULL) {\r
201 return EFI_OUT_OF_RESOURCES;\r
202 }\r
203\r
204 InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[Index]);\r
205\r
206 Private->CurrentMode = Index;\r
207\r
208 Private->HardwareNeedsStarting = FALSE;\r
209\r
210 return EFI_SUCCESS;\r
211 }\r
212\r
213 return EFI_NOT_FOUND;\r
214}\r
215\r
ed72955c 216/**\r
217 TODO: Add function description\r
218\r
219 @param This TODO: add argument description\r
220 @param BltBuffer TODO: add argument description\r
221 @param BltOperation TODO: add argument description\r
222 @param SourceX TODO: add argument description\r
223 @param SourceY TODO: add argument description\r
224 @param DestinationX TODO: add argument description\r
225 @param DestinationY TODO: add argument description\r
226 @param Width TODO: add argument description\r
227 @param Height TODO: add argument description\r
228 @param Delta TODO: add argument description\r
229\r
230 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
231 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
232 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
233 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
234 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
235 @retval EFI_INVALID_PARAMETER TODO: Add description for return value\r
236 @retval EFI_SUCCESS TODO: Add description for return value\r
237\r
238**/\r
1cc8ee78 239STATIC\r
878ddf1f 240EFI_STATUS\r
241EFIAPI\r
242CirrusLogic5430UgaDrawBlt (\r
243 IN EFI_UGA_DRAW_PROTOCOL *This,\r
244 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL\r
245 IN EFI_UGA_BLT_OPERATION BltOperation,\r
246 IN UINTN SourceX,\r
247 IN UINTN SourceY,\r
248 IN UINTN DestinationX,\r
249 IN UINTN DestinationY,\r
250 IN UINTN Width,\r
251 IN UINTN Height,\r
252 IN UINTN Delta\r
253 )\r
878ddf1f 254{\r
255 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r
256 EFI_TPL OriginalTPL;\r
257 UINTN DstY;\r
258 UINTN SrcY;\r
259 EFI_UGA_PIXEL *Blt;\r
260 UINTN X;\r
261 UINT8 Pixel;\r
262 UINT32 WidePixel;\r
263 UINTN ScreenWidth;\r
264 UINTN Offset;\r
265 UINTN SourceOffset;\r
266\r
267 Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (This);\r
268\r
269 if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) {\r
270 return EFI_INVALID_PARAMETER;\r
271 }\r
272\r
273 if (Width == 0 || Height == 0) {\r
274 return EFI_INVALID_PARAMETER;\r
275 }\r
276\r
277 //\r
278 // If Delta is zero, then the entire BltBuffer is being used, so Delta\r
279 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,\r
280 // the number of bytes in each row can be computed.\r
281 //\r
282 if (Delta == 0) {\r
283 Delta = Width * sizeof (EFI_UGA_PIXEL);\r
284 }\r
285\r
286 //\r
287 // We need to fill the Virtual Screen buffer with the blt data.\r
288 // The virtual screen is upside down, as the first row is the bootom row of\r
289 // the image.\r
290 //\r
291\r
292 //\r
293 // Make sure the SourceX, SourceY, DestinationX, DestinationY, Width, and Height parameters\r
294 // are valid for the operation and the current screen geometry.\r
295 //\r
296 if (BltOperation == EfiUgaVideoToBltBuffer) {\r
297 //\r
298 // Video to BltBuffer: Source is Video, destination is BltBuffer\r
299 //\r
300 if (SourceY + Height > Private->ModeData[Private->CurrentMode].VerticalResolution) {\r
301 return EFI_INVALID_PARAMETER;\r
302 }\r
303\r
304 if (SourceX + Width > Private->ModeData[Private->CurrentMode].HorizontalResolution) {\r
305 return EFI_INVALID_PARAMETER;\r
306 }\r
307 } else {\r
308 //\r
309 // BltBuffer to Video: Source is BltBuffer, destination is Video\r
310 //\r
311 if (DestinationY + Height > Private->ModeData[Private->CurrentMode].VerticalResolution) {\r
312 return EFI_INVALID_PARAMETER;\r
313 }\r
314\r
315 if (DestinationX + Width > Private->ModeData[Private->CurrentMode].HorizontalResolution) {\r
316 return EFI_INVALID_PARAMETER;\r
317 }\r
318 }\r
319 //\r
320 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.\r
321 // We would not want a timer based event (Cursor, ...) to come in while we are\r
322 // doing this operation.\r
323 //\r
324 OriginalTPL = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
325\r
326 switch (BltOperation) {\r
327 case EfiUgaVideoToBltBuffer:\r
328 //\r
329 // Video to BltBuffer: Source is Video, destination is BltBuffer\r
330 //\r
331 for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {\r
332\r
333 Offset = (SrcY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + SourceX;\r
334 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {\r
335 Private->PciIo->Mem.Read (\r
336 Private->PciIo,\r
337 EfiPciIoWidthUint32,\r
338 0,\r
339 Offset,\r
340 Width >> 2,\r
341 Private->LineBuffer\r
342 );\r
343 } else {\r
344 Private->PciIo->Mem.Read (\r
345 Private->PciIo,\r
346 EfiPciIoWidthUint8,\r
347 0,\r
348 Offset,\r
349 Width,\r
350 Private->LineBuffer\r
351 );\r
352 }\r
353\r
354 for (X = 0; X < Width; X++) {\r
355 Blt = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_UGA_PIXEL));\r
356\r
357 Blt->Red = (UINT8) (Private->LineBuffer[X] & 0xe0);\r
358 Blt->Green = (UINT8) ((Private->LineBuffer[X] & 0x1c) << 3);\r
359 Blt->Blue = (UINT8) ((Private->LineBuffer[X] & 0x03) << 6);\r
360 }\r
361 }\r
362 break;\r
363\r
364 case EfiUgaVideoToVideo:\r
365 //\r
366 // Perform hardware acceleration for Video to Video operations\r
367 //\r
368 ScreenWidth = Private->ModeData[Private->CurrentMode].HorizontalResolution;\r
369 SourceOffset = (SourceY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + (SourceX);\r
370 Offset = (DestinationY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + (DestinationX);\r
371\r
372 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0000);\r
373 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0010);\r
374 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0012);\r
375 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0014);\r
376\r
377 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0001);\r
378 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0011);\r
379 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0013);\r
380 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0015);\r
381\r
382 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Width << 8) & 0xff00) | 0x20));\r
383 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Width & 0xff00) | 0x21));\r
384 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Height << 8) & 0xff00) | 0x22));\r
385 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Height & 0xff00) | 0x23));\r
386 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x24));\r
387 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x25));\r
388 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x26));\r
389 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x27));\r
390 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) << 8) & 0xff00) | 0x28));\r
391 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 0) & 0xff00) | 0x29));\r
392 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 8) & 0xff00) | 0x2a));\r
393 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) << 8) & 0xff00) | 0x2c));\r
394 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 0) & 0xff00) | 0x2d));\r
395 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 8) & 0xff00) | 0x2e));\r
396 outw (Private, GRAPH_ADDRESS_REGISTER, 0x002f);\r
397 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0030);\r
398 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0d32);\r
399 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0033);\r
400 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0034);\r
401 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0035);\r
402\r
403 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0231);\r
404\r
405 outb (Private, GRAPH_ADDRESS_REGISTER, 0x31);\r
406 while ((inb (Private, GRAPH_DATA_REGISTER) & 0x01) == 0x01)\r
407 ;\r
408 break;\r
409\r
410 case EfiUgaVideoFill:\r
411 Blt = BltBuffer;\r
412 Pixel = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));\r
413 WidePixel = (Pixel << 8) | Pixel;\r
414 WidePixel = (WidePixel << 16) | WidePixel;\r
415\r
416 if (DestinationX == 0 && Width == Private->ModeData[Private->CurrentMode].HorizontalResolution) {\r
417 Offset = DestinationY * Private->ModeData[Private->CurrentMode].HorizontalResolution;\r
418 if (((Offset & 0x03) == 0) && (((Width * Height) & 0x03) == 0)) {\r
419 Private->PciIo->Mem.Write (\r
420 Private->PciIo,\r
421 EfiPciIoWidthFillUint32,\r
422 0,\r
423 Offset,\r
424 (Width * Height) >> 2,\r
425 &WidePixel\r
426 );\r
427 } else {\r
428 Private->PciIo->Mem.Write (\r
429 Private->PciIo,\r
430 EfiPciIoWidthFillUint8,\r
431 0,\r
432 Offset,\r
433 Width * Height,\r
434 &Pixel\r
435 );\r
436 }\r
437 } else {\r
438 for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {\r
439 Offset = (DstY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + DestinationX;\r
440 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {\r
441 Private->PciIo->Mem.Write (\r
442 Private->PciIo,\r
443 EfiPciIoWidthFillUint32,\r
444 0,\r
445 Offset,\r
446 Width >> 2,\r
447 &WidePixel\r
448 );\r
449 } else {\r
450 Private->PciIo->Mem.Write (\r
451 Private->PciIo,\r
452 EfiPciIoWidthFillUint8,\r
453 0,\r
454 Offset,\r
455 Width,\r
456 &Pixel\r
457 );\r
458 }\r
459 }\r
460 }\r
461 break;\r
462\r
463 case EfiUgaBltBufferToVideo:\r
464 for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {\r
465\r
466 for (X = 0; X < Width; X++) {\r
467 Blt = (EFI_UGA_PIXEL *) ((UINT8 *) BltBuffer + (SrcY * Delta) + (SourceX + X) * sizeof (EFI_UGA_PIXEL));\r
468 Private->LineBuffer[X] = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));\r
469 }\r
470\r
471 Offset = (DstY * Private->ModeData[Private->CurrentMode].HorizontalResolution) + DestinationX;\r
472\r
473 if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {\r
474 Private->PciIo->Mem.Write (\r
475 Private->PciIo,\r
476 EfiPciIoWidthUint32,\r
477 0,\r
478 Offset,\r
479 Width >> 2,\r
480 Private->LineBuffer\r
481 );\r
482 } else {\r
483 Private->PciIo->Mem.Write (\r
484 Private->PciIo,\r
485 EfiPciIoWidthUint8,\r
486 0,\r
487 Offset,\r
488 Width,\r
489 Private->LineBuffer\r
490 );\r
491 }\r
492 }\r
493 break;\r
494\r
495 default:\r
496 break;\r
497 }\r
498\r
499 gBS->RestoreTPL (OriginalTPL);\r
500\r
501 return EFI_SUCCESS;\r
502}\r
503\r
504//\r
505// Construction and Destruction functions\r
506//\r
507\r
ed72955c 508/**\r
509 CirrusLogic5430UgaDrawConstructor\r
510\r
511 TODO: Private - add argument and description to function comment\r
512 TODO: EFI_SUCCESS - add return value to function comment\r
513**/\r
878ddf1f 514EFI_STATUS\r
515CirrusLogic5430UgaDrawConstructor (\r
516 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
517 )\r
878ddf1f 518{\r
519 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
520 UINTN Index;\r
521\r
522 //\r
523 // Fill in Private->UgaDraw protocol\r
524 //\r
525 UgaDraw = &Private->UgaDraw;\r
526\r
527 UgaDraw->GetMode = CirrusLogic5430UgaDrawGetMode;\r
528 UgaDraw->SetMode = CirrusLogic5430UgaDrawSetMode;\r
529 UgaDraw->Blt = CirrusLogic5430UgaDrawBlt;\r
530\r
531 //\r
532 // Initialize the private data\r
533 //\r
534 Private->MaxMode = CIRRUS_LOGIC_5430_UGA_DRAW_MODE_COUNT;\r
535 Private->CurrentMode = 0;\r
536 for (Index = 0; Index < Private->MaxMode; Index++) {\r
537 Private->ModeData[Index].HorizontalResolution = CirrusLogic5430VideoModes[Index].Width;\r
538 Private->ModeData[Index].VerticalResolution = CirrusLogic5430VideoModes[Index].Height;\r
539 Private->ModeData[Index].ColorDepth = 32;\r
540 Private->ModeData[Index].RefreshRate = CirrusLogic5430VideoModes[Index].RefreshRate;\r
541 }\r
542\r
543 Private->HardwareNeedsStarting = TRUE;\r
544 Private->LineBuffer = NULL;\r
545\r
546 //\r
547 // Initialize the hardware\r
548 //\r
549 UgaDraw->SetMode (\r
550 UgaDraw,\r
551 Private->ModeData[Private->CurrentMode].HorizontalResolution,\r
552 Private->ModeData[Private->CurrentMode].VerticalResolution,\r
553 Private->ModeData[Private->CurrentMode].ColorDepth,\r
554 Private->ModeData[Private->CurrentMode].RefreshRate\r
555 );\r
556 DrawLogo (Private);\r
557\r
558 return EFI_SUCCESS;\r
559}\r
560\r
ed72955c 561/**\r
562 CirrusLogic5430UgaDrawDestructor\r
563\r
564 TODO: Private - add argument and description to function comment\r
565 TODO: EFI_SUCCESS - add return value to function comment\r
566**/\r
878ddf1f 567EFI_STATUS\r
568CirrusLogic5430UgaDrawDestructor (\r
569 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
570 )\r
878ddf1f 571{\r
572 return EFI_SUCCESS;\r
573}\r
574\r
ed72955c 575/**\r
576 TODO: Add function description\r
577\r
578 @param Private TODO: add argument description\r
579 @param Address TODO: add argument description\r
580 @param Data TODO: add argument description\r
581\r
582 TODO: add return values\r
583\r
584**/\r
878ddf1f 585VOID\r
586outb (\r
587 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
588 UINTN Address,\r
589 UINT8 Data\r
590 )\r
878ddf1f 591{\r
592 Private->PciIo->Io.Write (\r
593 Private->PciIo,\r
594 EfiPciIoWidthUint8,\r
595 EFI_PCI_IO_PASS_THROUGH_BAR,\r
596 Address,\r
597 1,\r
598 &Data\r
599 );\r
600}\r
601\r
ed72955c 602/**\r
603 TODO: Add function description\r
604\r
605 @param Private TODO: add argument description\r
606 @param Address TODO: add argument description\r
607 @param Data TODO: add argument description\r
608\r
609 TODO: add return values\r
610\r
611**/\r
878ddf1f 612VOID\r
613outw (\r
614 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
615 UINTN Address,\r
616 UINT16 Data\r
617 )\r
878ddf1f 618{\r
619 Private->PciIo->Io.Write (\r
620 Private->PciIo,\r
621 EfiPciIoWidthUint16,\r
622 EFI_PCI_IO_PASS_THROUGH_BAR,\r
623 Address,\r
624 1,\r
625 &Data\r
626 );\r
627}\r
628\r
ed72955c 629/**\r
878ddf1f 630 TODO: Add function description\r
631\r
ed72955c 632 @param Private TODO: add argument description\r
633 @param Address TODO: add argument description\r
878ddf1f 634\r
635 TODO: add return values\r
636\r
ed72955c 637**/\r
638UINT8\r
639inb (\r
640 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
641 UINTN Address\r
642 )\r
878ddf1f 643{\r
644 UINT8 Data;\r
645\r
646 Private->PciIo->Io.Read (\r
647 Private->PciIo,\r
648 EfiPciIoWidthUint8,\r
649 EFI_PCI_IO_PASS_THROUGH_BAR,\r
650 Address,\r
651 1,\r
652 &Data\r
653 );\r
654 return Data;\r
655}\r
656\r
ed72955c 657/**\r
878ddf1f 658 TODO: Add function description\r
659\r
ed72955c 660 @param Private TODO: add argument description\r
661 @param Address TODO: add argument description\r
878ddf1f 662\r
663 TODO: add return values\r
664\r
ed72955c 665**/\r
666UINT16\r
667inw (\r
668 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
669 UINTN Address\r
670 )\r
878ddf1f 671{\r
672 UINT16 Data;\r
673\r
674 Private->PciIo->Io.Read (\r
675 Private->PciIo,\r
676 EfiPciIoWidthUint16,\r
677 EFI_PCI_IO_PASS_THROUGH_BAR,\r
678 Address,\r
679 1,\r
680 &Data\r
681 );\r
682 return Data;\r
683}\r
684\r
ed72955c 685/**\r
686 TODO: Add function description\r
687\r
688 @param Private TODO: add argument description\r
689 @param Index TODO: add argument description\r
690 @param Red TODO: add argument description\r
691 @param Green TODO: add argument description\r
692 @param Blue TODO: add argument description\r
693\r
694 TODO: add return values\r
695\r
696**/\r
878ddf1f 697VOID\r
698SetPaletteColor (\r
699 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
700 UINTN Index,\r
701 UINT8 Red,\r
702 UINT8 Green,\r
703 UINT8 Blue\r
704 )\r
878ddf1f 705{\r
706 outb (Private, PALETTE_INDEX_REGISTER, (UINT8) Index);\r
707 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));\r
708 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));\r
709 outb (Private, PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));\r
710}\r
711\r
ed72955c 712/**\r
878ddf1f 713 TODO: Add function description\r
714\r
ed72955c 715 @param Private TODO: add argument description\r
878ddf1f 716\r
717 TODO: add return values\r
718\r
ed72955c 719**/\r
720VOID\r
721SetDefaultPalette (\r
722 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
723 )\r
878ddf1f 724{\r
725 UINTN Index;\r
726 UINTN RedIndex;\r
727 UINTN GreenIndex;\r
728 UINTN BlueIndex;\r
729\r
730 Index = 0;\r
731 for (RedIndex = 0; RedIndex < 8; RedIndex++) {\r
732 for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {\r
733 for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {\r
734 SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));\r
735 Index++;\r
736 }\r
737 }\r
738 }\r
739}\r
740\r
ed72955c 741/**\r
878ddf1f 742 TODO: Add function description\r
743\r
ed72955c 744 @param Private TODO: add argument description\r
878ddf1f 745\r
746 TODO: add return values\r
747\r
ed72955c 748**/\r
749STATIC\r
750VOID\r
751ClearScreen (\r
752 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
753 )\r
878ddf1f 754{\r
755 UINT32 Color;\r
756\r
757 Color = 0;\r
758 Private->PciIo->Mem.Write (\r
759 Private->PciIo,\r
760 EfiPciIoWidthFillUint32,\r
761 0,\r
762 0,\r
763 0x100000 >> 2,\r
764 &Color\r
765 );\r
766}\r
767\r
ed72955c 768/**\r
878ddf1f 769 TODO: Add function description\r
770\r
ed72955c 771 @param Private TODO: add argument description\r
878ddf1f 772\r
773 TODO: add return values\r
774\r
ed72955c 775**/\r
776VOID\r
777DrawLogo (\r
778 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private\r
779 )\r
878ddf1f 780{\r
781 UINTN Offset;\r
782 UINTN X;\r
783 UINTN Y;\r
784 UINTN ScreenWidth;\r
785 UINTN ScreenHeight;\r
786 UINT8 Color;\r
787\r
788 ScreenWidth = Private->ModeData[Private->CurrentMode].HorizontalResolution;\r
789 ScreenHeight = Private->ModeData[Private->CurrentMode].VerticalResolution;\r
790\r
791 Offset = 0;\r
792 for (Y = 0; Y < ScreenHeight; Y++) {\r
793 for (X = 0; X < ScreenWidth; X++) {\r
794 Color = (UINT8) (256 * (X + Y) / (ScreenWidth + ScreenHeight));\r
795 Private->LineBuffer[X] = Color;\r
796 }\r
797\r
798 Private->PciIo->Mem.Write (\r
799 Private->PciIo,\r
800 EfiPciIoWidthUint32,\r
801 0,\r
802 Offset + (Y * ScreenWidth),\r
803 ScreenWidth >> 2,\r
804 Private->LineBuffer\r
805 );\r
806 }\r
807}\r
808\r
ed72955c 809/**\r
878ddf1f 810 TODO: Add function description\r
811\r
ed72955c 812 @param Private TODO: add argument description\r
813 @param ModeData TODO: add argument description\r
878ddf1f 814\r
815 TODO: add return values\r
816\r
ed72955c 817**/\r
818VOID\r
819InitializeGraphicsMode (\r
820 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,\r
821 CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData\r
822 )\r
878ddf1f 823{\r
824 UINT8 Byte;\r
825 UINTN Index;\r
826\r
827 outw (Private, SEQ_ADDRESS_REGISTER, 0x1206);\r
828 outw (Private, SEQ_ADDRESS_REGISTER, 0x0012);\r
829\r
830 for (Index = 0; Index < 15; Index++) {\r
831 outw (Private, SEQ_ADDRESS_REGISTER, ModeData->SeqSettings[Index]);\r
832 }\r
833\r
834 outb (Private, SEQ_ADDRESS_REGISTER, 0x0f);\r
835 Byte = (UINT8) ((inb (Private, SEQ_DATA_REGISTER) & 0xc7) ^ 0x30);\r
836 outb (Private, SEQ_DATA_REGISTER, Byte);\r
837\r
838 outb (Private, MISC_OUTPUT_REGISTER, ModeData->MiscSetting);\r
839 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0506);\r
840 outw (Private, SEQ_ADDRESS_REGISTER, 0x0300);\r
841 outw (Private, CRTC_ADDRESS_REGISTER, 0x2011);\r
842\r
843 for (Index = 0; Index < 28; Index++) {\r
844 outw (Private, CRTC_ADDRESS_REGISTER, (UINT16) ((ModeData->CrtcSettings[Index] << 8) | Index));\r
845 }\r
846\r
847 for (Index = 0; Index < 9; Index++) {\r
848 outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((GraphicsController[Index] << 8) | Index));\r
849 }\r
850\r
851 inb (Private, INPUT_STATUS_1_REGISTER);\r
852\r
853 for (Index = 0; Index < 21; Index++) {\r
854 outb (Private, ATT_ADDRESS_REGISTER, (UINT8) Index);\r
855 outb (Private, ATT_ADDRESS_REGISTER, AttributeController[Index]);\r
856 }\r
857\r
858 outb (Private, ATT_ADDRESS_REGISTER, 0x20);\r
859\r
860 outw (Private, GRAPH_ADDRESS_REGISTER, 0x0009);\r
861 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000a);\r
862 outw (Private, GRAPH_ADDRESS_REGISTER, 0x000b);\r
863 outb (Private, DAC_PIXEL_MASK_REGISTER, 0xff);\r
864\r
865 SetDefaultPalette (Private);\r
866 ClearScreen (Private);\r
867}\r