2 * PROJECT: ReactOS VGA Miniport Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/drivers/video/miniport/vga/vbe.c
5 * PURPOSE: Main VESA VBE 1.02+ SVGA Miniport Handling Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
13 /* GLOBALS ********************************************************************/
15 static const PCHAR Nv11Board
= "NV11 (GeForce2) Board";
16 static const PCHAR Nv11Chip
= "Chip Rev B2";
17 static const PCHAR Nv11Vendor
= "NVidia Corporation";
18 static const PCHAR IntelBrookdale
= "Brookdale-G Graphics Controller";
19 static const PCHAR BrokenVesaBiosList
[] =
31 BOOLEAN g_bIntelBrookdaleBIOS
;
33 /* FUNCTIONS ******************************************************************/
37 IsVesaBiosOk(IN PVIDEO_PORT_INT10_INTERFACE Interface
,
46 /* If the broken VESA bios found, turn VESA off */
47 VideoPortDebugPrint(0, "Vendor: %s Product: %s Revision: %s (%lx)\n", Vendor
, Product
, Revision
, OemRevision
);
48 for (i
= 0; i
< (sizeof(BrokenVesaBiosList
) / sizeof(PCHAR
)); i
++)
50 if (!strncmp(Product
, BrokenVesaBiosList
[i
], sizeof(BrokenVesaBiosList
[i
]))) return FALSE
;
53 /* For Brookdale-G (Intel), special hack used */
54 g_bIntelBrookdaleBIOS
= !strncmp(Product
, IntelBrookdale
, sizeof(IntelBrookdale
));
56 /* For NVIDIA make sure */
57 if (!(strncmp(Vendor
, Nv11Vendor
, sizeof(Nv11Vendor
))) &&
58 !(strncmp(Product
, Nv11Board
, sizeof(Nv11Board
))) &&
59 !(strncmp(Revision
, Nv11Chip
, sizeof(Nv11Chip
))) &&
60 (OemRevision
== 0x311))
63 if (Interface
->Int10ReadMemory(Interface
->Context
,
67 sizeof(Version
))) return FALSE
;
68 if (!strncmp(Version
, "Version 3.11.01.24N16", sizeof(Version
))) return FALSE
;
72 //VideoPortDebugPrint(0, "Vesa ok\n");
78 ValidateVbeInfo(IN PHW_DEVICE_EXTENSION VgaExtension
,
83 CHAR ProductRevision
[80];
91 Context
= VgaExtension
->Int10Interface
.Context
;
93 /* Check magic and version */
94 if (strncmp(VbeInfo
->Info
.Signature
, "VESA", 4)) return VesaBiosOk
;
95 if (VbeInfo
->Info
.Version
< 0x102) return VesaBiosOk
;
98 Status
= VgaExtension
->Int10Interface
.Int10ReadMemory(Context
,
99 HIWORD(VbeInfo
->Info
.OemStringPtr
),
100 LOWORD(VbeInfo
->Info
.OemStringPtr
),
103 if (Status
!= NO_ERROR
) return VesaBiosOk
;
104 Status
= VgaExtension
->Int10Interface
.Int10ReadMemory(Context
,
105 HIWORD(VbeInfo
->Info
.OemVendorNamePtr
),
106 LOWORD(VbeInfo
->Info
.OemVendorNamePtr
),
109 if (Status
!= NO_ERROR
) return VesaBiosOk
;
110 Status
= VgaExtension
->Int10Interface
.Int10ReadMemory(Context
,
111 HIWORD(VbeInfo
->Info
.OemProductNamePtr
),
112 LOWORD(VbeInfo
->Info
.OemProductNamePtr
),
114 sizeof(ProductName
));
115 if (Status
!= NO_ERROR
) return VesaBiosOk
;
116 Status
= VgaExtension
->Int10Interface
.Int10ReadMemory(Context
,
117 HIWORD(VbeInfo
->Info
.OemProductRevPtr
),
118 LOWORD(VbeInfo
->Info
.OemProductRevPtr
),
120 sizeof(ProductRevision
));
121 if (Status
!= NO_ERROR
) return VesaBiosOk
;
123 /* Null-terminate strings */
124 VendorName
[sizeof(OemString
) - 1] = ANSI_NULL
;
125 ProductName
[sizeof(OemString
) - 1] = ANSI_NULL
;
126 ProductRevision
[sizeof(OemString
) - 1] = ANSI_NULL
;
127 OemString
[sizeof(OemString
) - 1] = ANSI_NULL
;
129 /* Check for known bad BIOS */
130 VesaBiosOk
= IsVesaBiosOk(&VgaExtension
->Int10Interface
,
131 VbeInfo
->Info
.OemSoftwareRevision
,
135 VgaExtension
->VesaBiosOk
= VesaBiosOk
;
141 VbeSetColorLookup(IN PHW_DEVICE_EXTENSION VgaExtension
,
142 IN PVIDEO_CLUT ClutBuffer
)
144 PVBE_COLOR_REGISTER VesaClut
;
145 INT10_BIOS_ARGUMENTS BiosArguments
;
148 ULONG BufferSize
= 4 * 1024;
149 USHORT TrampolineMemorySegment
, TrampolineMemoryOffset
;
153 Entries
= ClutBuffer
->NumEntries
;
155 /* Allocate INT10 context/buffer */
156 VesaClut
= VideoPortAllocatePool(VgaExtension
, 1, sizeof(ULONG
) * Entries
, 0x20616756u
);
157 if (!VesaClut
) return ERROR_INVALID_PARAMETER
;
158 if (!VgaExtension
->Int10Interface
.Size
) return ERROR_INVALID_PARAMETER
;
159 Context
= VgaExtension
->Int10Interface
.Context
;
160 Status
= VgaExtension
->Int10Interface
.Int10AllocateBuffer(Context
,
161 &TrampolineMemorySegment
,
162 &TrampolineMemoryOffset
,
164 if (Status
!= NO_ERROR
) return ERROR_INVALID_PARAMETER
;
166 /* VESA has color registers backward! */
167 for (i
= 0; i
< Entries
; i
++)
169 VesaClut
[i
].Blue
= ClutBuffer
->LookupTable
[i
].RgbArray
.Blue
;
170 VesaClut
[i
].Green
= ClutBuffer
->LookupTable
[i
].RgbArray
.Green
;
171 VesaClut
[i
].Red
= ClutBuffer
->LookupTable
[i
].RgbArray
.Red
;
174 Status
= VgaExtension
->Int10Interface
.Int10WriteMemory(Context
,
175 TrampolineMemorySegment
,
176 TrampolineMemoryOffset
,
178 Entries
* sizeof(ULONG
));
179 if (Status
!= NO_ERROR
) return ERROR_INVALID_PARAMETER
;
181 /* Write new palette */
182 BiosArguments
.Ebx
= 0;
183 BiosArguments
.Ecx
= Entries
;
184 BiosArguments
.Edx
= ClutBuffer
->FirstEntry
;
185 BiosArguments
.Edi
= TrampolineMemoryOffset
;
186 BiosArguments
.SegEs
= TrampolineMemorySegment
;
187 BiosArguments
.Eax
= VBE_SET_GET_PALETTE_DATA
;
188 Status
= VgaExtension
->Int10Interface
.Int10CallBios(Context
, &BiosArguments
);
189 if (Status
!= NO_ERROR
) return ERROR_INVALID_PARAMETER
;
190 VideoPortFreePool(VgaExtension
, VesaClut
);
191 VideoPortDebugPrint(Error
, "VBE Status: %lx\n", BiosArguments
.Eax
);
192 if (BiosArguments
.Eax
== VBE_SUCCESS
) return NO_ERROR
;
193 return ERROR_INVALID_PARAMETER
;