6335 lines
179 KiB
C
6335 lines
179 KiB
C
/*++
|
||
|
||
Copyright (c) 1992-1996 Microsoft Corporation
|
||
|
||
Module Name:
|
||
|
||
vga.c
|
||
|
||
Abstract:
|
||
|
||
This is the miniport driver for the VGA card.
|
||
|
||
Environment:
|
||
|
||
kernel mode only
|
||
|
||
Notes:
|
||
|
||
Revision History:
|
||
|
||
--*/
|
||
|
||
#include "dderror.h"
|
||
#include "devioctl.h"
|
||
#include "miniport.h"
|
||
|
||
#include "ntddvdeo.h"
|
||
#include "video.h"
|
||
#include "wdvga.h"
|
||
|
||
extern USHORT Reset[];
|
||
|
||
|
||
//
|
||
// Function declarations
|
||
//
|
||
// Functions that start with 'VGA' are entry points for the OS port driver.
|
||
//
|
||
|
||
VP_STATUS
|
||
VgaFindAdapter(
|
||
PVOID HwDeviceExtension,
|
||
PVOID HwContext,
|
||
PWSTR ArgumentString,
|
||
PVIDEO_PORT_CONFIG_INFO ConfigInfo,
|
||
PUCHAR Again
|
||
);
|
||
|
||
BOOLEAN
|
||
VgaInitialize(
|
||
PVOID HwDeviceExtension
|
||
);
|
||
|
||
BOOLEAN
|
||
VgaStartIO(
|
||
PVOID HwDeviceExtension,
|
||
PVIDEO_REQUEST_PACKET RequestPacket
|
||
);
|
||
|
||
//
|
||
// Private function prototypes.
|
||
//
|
||
|
||
VP_STATUS
|
||
VgaQueryAvailableModes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_MODE_INFORMATION ModeInformation,
|
||
ULONG ModeInformationSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaQueryNumberOfAvailableModes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_NUM_MODES NumModes,
|
||
ULONG NumModesSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaQueryCurrentMode(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_MODE_INFORMATION ModeInformation,
|
||
ULONG ModeInformationSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSetMode(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_MODE Mode,
|
||
ULONG ModeSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaLoadAndSetFont(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_LOAD_FONT_INFORMATION FontInformation,
|
||
ULONG FontInformationSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaQueryCursorPosition(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_POSITION CursorPosition,
|
||
ULONG CursorPositionSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSetCursorPosition(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_POSITION CursorPosition,
|
||
ULONG CursorPositionSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaQueryCursorAttributes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
||
ULONG CursorAttributesSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSetCursorAttributes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
||
ULONG CursorAttributesSize
|
||
);
|
||
|
||
BOOLEAN
|
||
VgaIsPresent(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
);
|
||
|
||
BOOLEAN
|
||
WdIsPresent(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
);
|
||
|
||
VOID
|
||
VgaSizeMemory(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
);
|
||
|
||
VOID
|
||
VgaInterpretCmdStream(
|
||
PVOID HwDeviceExtension,
|
||
PUSHORT pusCmdStream
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSetPaletteReg(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_PALETTE_DATA PaletteBuffer,
|
||
ULONG PaletteBufferSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSetColorLookup(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CLUT ClutBuffer,
|
||
ULONG ClutBufferSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaRestoreHardwareState(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_HARDWARE_STATE HardwareState,
|
||
ULONG HardwareStateSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaSaveHardwareState(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_HARDWARE_STATE HardwareState,
|
||
ULONG HardwareStateSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VP_STATUS
|
||
VgaGetBankSelectCode(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_BANK_SELECT BankSelect,
|
||
ULONG BankSelectSize,
|
||
PULONG OutputSize
|
||
);
|
||
|
||
VOID
|
||
VgaValidateModes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
);
|
||
|
||
VOID
|
||
vBankMap(
|
||
ULONG iBankRead,
|
||
ULONG iBankWrite,
|
||
PVOID pvContext
|
||
);
|
||
|
||
VOID
|
||
GetPanelType(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
);
|
||
|
||
BOOLEAN
|
||
WdResetHw(
|
||
PVOID HwDeviceExtension,
|
||
ULONG Columns,
|
||
ULONG Rows
|
||
);
|
||
|
||
//
|
||
// New entry points added for NT 5.0.
|
||
//
|
||
|
||
#if (_WIN32_WINNT >= 500)
|
||
|
||
//
|
||
// Routine to set a desired DPMS power management state.
|
||
//
|
||
VP_STATUS
|
||
VGASetPower50(
|
||
PHW_DEVICE_EXTENSION phwDeviceExtension,
|
||
ULONG HwDeviceId,
|
||
PVIDEO_POWER_MANAGEMENT pVideoPowerMgmt
|
||
);
|
||
|
||
//
|
||
// Routine to retrieve possible DPMS power management states.
|
||
//
|
||
VP_STATUS
|
||
VGAGetPower50(
|
||
PHW_DEVICE_EXTENSION phwDeviceExtension,
|
||
ULONG HwDeviceId,
|
||
PVIDEO_POWER_MANAGEMENT pVideoPowerMgmt
|
||
);
|
||
|
||
//
|
||
// Routine to retrieve the Enhanced Display ID structure via DDC
|
||
//
|
||
ULONG
|
||
VGAGetVideoChildDescriptor(
|
||
PVOID HwDeviceExtension,
|
||
PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
|
||
PVIDEO_CHILD_TYPE pChildType,
|
||
PVOID pvChildDescriptor,
|
||
PULONG pHwId,
|
||
PULONG pUnused
|
||
);
|
||
#endif // _WIN32_WINNT >= 500
|
||
|
||
|
||
#if defined(ALLOC_PRAGMA)
|
||
#pragma alloc_text(PAGE,DriverEntry)
|
||
#pragma alloc_text(PAGE,VgaFindAdapter)
|
||
#pragma alloc_text(PAGE,VgaInitialize)
|
||
#pragma alloc_text(PAGE,VgaStartIO)
|
||
#pragma alloc_text(PAGE,VgaLoadAndSetFont)
|
||
#pragma alloc_text(PAGE,VgaQueryCursorPosition)
|
||
#pragma alloc_text(PAGE,VgaSetCursorPosition)
|
||
#pragma alloc_text(PAGE,VgaQueryCursorAttributes)
|
||
#pragma alloc_text(PAGE,VgaSetCursorAttributes)
|
||
#pragma alloc_text(PAGE,VgaIsPresent)
|
||
#pragma alloc_text(PAGE,WdIsPresent)
|
||
#pragma alloc_text(PAGE,VgaSizeMemory)
|
||
#pragma alloc_text(PAGE,VgaSetPaletteReg)
|
||
#pragma alloc_text(PAGE,VgaSetColorLookup)
|
||
#pragma alloc_text(PAGE,VgaRestoreHardwareState)
|
||
#pragma alloc_text(PAGE,VgaSaveHardwareState)
|
||
#pragma alloc_text(PAGE,VgaGetBankSelectCode)
|
||
|
||
#pragma alloc_text(PAGE,VgaValidatorUcharEntry)
|
||
#pragma alloc_text(PAGE,VgaValidatorUshortEntry)
|
||
#pragma alloc_text(PAGE,VgaValidatorUlongEntry)
|
||
#pragma alloc_text(PAGE,GetPanelType)
|
||
#if (_WIN32_WINNT >= 500)
|
||
#pragma alloc_text(PAGE_COM, VGASetPower50)
|
||
#pragma alloc_text(PAGE_COM, VGAGetPower50)
|
||
#pragma alloc_text(PAGE_COM, VGAGetVideoChildDescriptor)
|
||
#endif // _WIN32_WINNT >= 500
|
||
|
||
#endif
|
||
|
||
|
||
ULONG
|
||
DriverEntry(
|
||
PVOID Context1,
|
||
PVOID Context2
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Installable driver initialization entry point.
|
||
This entry point is called directly by the I/O system.
|
||
|
||
Arguments:
|
||
|
||
Context1 - First context value passed by the operating system. This is
|
||
the value with which the miniport driver calls VideoPortInitialize().
|
||
|
||
Context2 - Second context value passed by the operating system. This is
|
||
the value with which the miniport driver calls VideoPortInitialize().
|
||
|
||
Return Value:
|
||
|
||
Status from VideoPortInitialize()
|
||
|
||
--*/
|
||
|
||
{
|
||
|
||
VIDEO_HW_INITIALIZATION_DATA hwInitData;
|
||
ULONG status;
|
||
ULONG initializationStatus;
|
||
|
||
//
|
||
// Zero out structure.
|
||
//
|
||
|
||
VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));
|
||
|
||
//
|
||
// Specify sizes of structure and extension.
|
||
//
|
||
|
||
hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
|
||
|
||
//
|
||
// Set entry points.
|
||
//
|
||
|
||
hwInitData.HwFindAdapter = VgaFindAdapter;
|
||
hwInitData.HwInitialize = VgaInitialize;
|
||
hwInitData.HwInterrupt = NULL;
|
||
hwInitData.HwStartIO = VgaStartIO;
|
||
hwInitData.HwResetHw = WdResetHw;
|
||
|
||
#if (_WIN32_WINNT >= 500)
|
||
|
||
//
|
||
// Set new entry points added for NT 5.0.
|
||
//
|
||
|
||
hwInitData.HwSetPowerState = VGASetPower50;
|
||
hwInitData.HwGetPowerState = VGAGetPower50;
|
||
hwInitData.HwGetVideoChildDescriptor = VGAGetVideoChildDescriptor;
|
||
|
||
#endif // _WIN32_WINNT >= 500
|
||
|
||
|
||
//
|
||
// Determine the size we require for the device extension.
|
||
//
|
||
|
||
hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
|
||
|
||
//
|
||
// Always start with parameters for device0 in this case.
|
||
// We can leave it like this since we know we will only ever find one
|
||
// VGA type adapter in a machine.
|
||
//
|
||
|
||
// hwInitData.StartingDeviceNumber = 0;
|
||
|
||
//
|
||
// Once all the relevant information has been stored, call the video
|
||
// port driver to do the initialization.
|
||
// For this device we will repeat this call three times, for ISA, EISA
|
||
// and MCA.
|
||
// We will return the minimum of all return values.
|
||
//
|
||
|
||
hwInitData.AdapterInterfaceType = Isa;
|
||
|
||
initializationStatus = VideoPortInitialize(Context1,
|
||
Context2,
|
||
&hwInitData,
|
||
NULL);
|
||
|
||
hwInitData.AdapterInterfaceType = Eisa;
|
||
|
||
status = VideoPortInitialize(Context1,
|
||
Context2,
|
||
&hwInitData,
|
||
NULL);
|
||
|
||
if (initializationStatus > status) {
|
||
initializationStatus = status;
|
||
}
|
||
|
||
hwInitData.AdapterInterfaceType = MicroChannel;
|
||
|
||
status = VideoPortInitialize(Context1,
|
||
Context2,
|
||
&hwInitData,
|
||
NULL);
|
||
|
||
if (initializationStatus > status) {
|
||
initializationStatus = status;
|
||
}
|
||
|
||
return initializationStatus;
|
||
|
||
} // end DriverEntry()
|
||
|
||
VP_STATUS
|
||
VgaFindAdapter(
|
||
PVOID HwDeviceExtension,
|
||
PVOID HwContext,
|
||
PWSTR ArgumentString,
|
||
PVIDEO_PORT_CONFIG_INFO ConfigInfo,
|
||
PUCHAR Again
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine is called to determine if the adapter for this driver
|
||
is present in the system.
|
||
If it is present, the function fills out some information describing
|
||
the adapter.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Supplies the miniport driver's adapter storage. This
|
||
storage is initialized to zero before this call.
|
||
|
||
HwContext - Supplies the context value which was passed to
|
||
VideoPortInitialize(). Must be NULL for PnP drivers.
|
||
|
||
ArgumentString - Supplies a NULL terminated ASCII string. This string
|
||
originates from the user.
|
||
|
||
ConfigInfo - Returns the configuration information structure which is
|
||
filled by the miniport driver. This structure is initialized with
|
||
any known configuration information (such as SystemIoBusNumber) by
|
||
the port driver. Where possible, drivers should have one set of
|
||
defaults which do not require any supplied configuration information.
|
||
|
||
Again - Indicates if the miniport driver wants the port driver to call
|
||
its VIDEO_HW_FIND_ADAPTER function again with a new device extension
|
||
and the same config info. This is used by the miniport drivers which
|
||
can search for several adapters on a bus.
|
||
|
||
Return Value:
|
||
|
||
This routine must return:
|
||
|
||
NO_ERROR - Indicates a host adapter was found and the
|
||
configuration information was successfully determined.
|
||
|
||
ERROR_INVALID_PARAMETER - Indicates an adapter was found but there was an
|
||
error obtaining the configuration information. If possible an error
|
||
should be logged.
|
||
|
||
ERROR_DEV_NOT_EXIST - Indicates no host adapter was found for the
|
||
supplied configuration information.
|
||
|
||
--*/
|
||
|
||
{
|
||
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
||
VP_STATUS status;
|
||
|
||
//
|
||
// Make sure the size of the structure is at least as large as what we
|
||
// are expecting (check version of the config info structure).
|
||
//
|
||
|
||
if (ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// No interrupt information is necessary.
|
||
//
|
||
|
||
//
|
||
// Check to see if there is a hardware resource conflict.
|
||
// Start by including the exted register. If that fails, then only use
|
||
// the normal registers.
|
||
//
|
||
|
||
hwDeviceExtension->ExtendedRegisters = EXTENDED_AND_FLAT_PANEL_REGISTERS;
|
||
|
||
status = VideoPortVerifyAccessRanges(hwDeviceExtension,
|
||
NUM_ALL_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
if (status != NO_ERROR)
|
||
{
|
||
hwDeviceExtension->ExtendedRegisters = EXTENDED_REGISTERS;
|
||
|
||
status = VideoPortVerifyAccessRanges(hwDeviceExtension,
|
||
NUM_WD_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
if (status != NO_ERROR) {
|
||
|
||
hwDeviceExtension->ExtendedRegisters = NO_EXTENDED_REGISTERS;
|
||
|
||
status = VideoPortVerifyAccessRanges(hwDeviceExtension,
|
||
NUM_VGA_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
if (status != NO_ERROR) {
|
||
|
||
return status;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
//
|
||
// Get logical IO port addresses.
|
||
//
|
||
|
||
if ( (hwDeviceExtension->IOAddress =
|
||
VideoPortGetDeviceBase(hwDeviceExtension,
|
||
VgaAccessRange->RangeStart,
|
||
VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1,
|
||
TRUE)) == NULL) {
|
||
|
||
VideoDebugPrint((2, "VgaFindAdapter - Fail to get io address\n"));
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Determine whether a VGA is present.
|
||
//
|
||
|
||
if (!VgaIsPresent(hwDeviceExtension)) {
|
||
|
||
return ERROR_DEV_NOT_EXIST;
|
||
|
||
}
|
||
|
||
//
|
||
// Determine whether a WDVGA chipset is present.
|
||
//
|
||
|
||
if (!WdIsPresent(hwDeviceExtension)) {
|
||
|
||
return ERROR_DEV_NOT_EXIST;
|
||
|
||
}
|
||
|
||
//
|
||
// Pass a pointer to the emulator range we are using.
|
||
//
|
||
|
||
ConfigInfo->NumEmulatorAccessEntries = VGA_NUM_EMULATOR_ACCESS_ENTRIES;
|
||
ConfigInfo->EmulatorAccessEntries = VgaEmulatorAccessEntries;
|
||
ConfigInfo->EmulatorAccessEntriesContext = (ULONG) hwDeviceExtension;
|
||
|
||
ConfigInfo->VdmPhysicalVideoMemoryAddress.LowPart = MEM_VGA;
|
||
ConfigInfo->VdmPhysicalVideoMemoryAddress.HighPart = 0x00000000;
|
||
ConfigInfo->VdmPhysicalVideoMemoryLength = MEM_VGA_SIZE;
|
||
|
||
//
|
||
// Minimum size of the buffer required to store the hardware state
|
||
// information returned by IOCTL_VIDEO_SAVE_HARDWARE_STATE.
|
||
//
|
||
|
||
ConfigInfo->HardwareStateSize = VGA_TOTAL_STATE_SIZE;
|
||
|
||
//
|
||
// Video memory information
|
||
//
|
||
|
||
hwDeviceExtension->PhysicalVideoMemoryBase.HighPart = 0x00000000;
|
||
hwDeviceExtension->PhysicalVideoMemoryBase.LowPart = MEM_VGA;
|
||
hwDeviceExtension->PhysicalVideoMemoryLength = MEM_VGA_SIZE;
|
||
|
||
//
|
||
// Map the video memory into the system virtual address space so we can
|
||
// clear it out and use it for save and restore.
|
||
//
|
||
|
||
if ( (hwDeviceExtension->VideoMemoryAddress =
|
||
VideoPortGetDeviceBase(hwDeviceExtension,
|
||
hwDeviceExtension->PhysicalVideoMemoryBase,
|
||
hwDeviceExtension->PhysicalVideoMemoryLength, FALSE)) == NULL) {
|
||
|
||
VideoDebugPrint((1, "VgaFindAdapter - Fail to get memory address\n"));
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Indicate we do not wish to be called again for another initialization.
|
||
//
|
||
|
||
*Again = 0;
|
||
|
||
//
|
||
// Indicate a successful completion status.
|
||
//
|
||
|
||
return NO_ERROR;
|
||
|
||
} // VgaFindAdapter()
|
||
|
||
BOOLEAN
|
||
VgaInitialize(
|
||
PVOID HwDeviceExtension
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine does one time initialization of the device.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's adapter information.
|
||
|
||
Return Value:
|
||
|
||
None.
|
||
|
||
--*/
|
||
|
||
{
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
||
VIDEO_X86_BIOS_ARGUMENTS biosArguments;
|
||
|
||
//
|
||
// set up the default cursor position and type.
|
||
//
|
||
|
||
hwDeviceExtension->CursorPosition.Column = 0;
|
||
hwDeviceExtension->CursorPosition.Row = 0;
|
||
hwDeviceExtension->CursorTopScanLine = 0;
|
||
hwDeviceExtension->CursorBottomScanLine = 31;
|
||
hwDeviceExtension->CursorEnable = TRUE;
|
||
|
||
//
|
||
// Assume no BIOS for now
|
||
//
|
||
|
||
hwDeviceExtension->SVGABios = FALSE;
|
||
|
||
#ifdef INT10_MODE_SET
|
||
|
||
//
|
||
// Make sure we unlock extended registers since the BIOS on some machines
|
||
// does not do it properly.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), 0x050F);
|
||
|
||
//
|
||
// Mode set block that can be repeated.
|
||
//
|
||
|
||
//
|
||
// Lets try to check and see what level of SVGA Bios
|
||
// support we have.
|
||
//
|
||
|
||
if (hwDeviceExtension->BoardID == WD90C24A)
|
||
{
|
||
//
|
||
// IsIBM is set during detection
|
||
//
|
||
|
||
if (hwDeviceExtension->IsIBM == TRUE)
|
||
{
|
||
ULONG Modes[3] = {0x5f, 0x5c, 0x60};
|
||
ULONG SVGASupport[3] = {LIMITED_SVGA_BIOS,
|
||
LIMITED_SVGA_BIOS,
|
||
FULL_SVGA_BIOS};
|
||
ULONG i;
|
||
|
||
hwDeviceExtension->SVGABios = NO_SVGA_BIOS;
|
||
|
||
for(i=0; i<3; i++)
|
||
{
|
||
VideoPortZeroMemory(&biosArguments,
|
||
sizeof(VIDEO_X86_BIOS_ARGUMENTS));
|
||
|
||
biosArguments.Eax = Modes[i];
|
||
VideoPortInt10(hwDeviceExtension, &biosArguments);
|
||
|
||
//
|
||
// now lets see if the modeset worked
|
||
//
|
||
|
||
biosArguments.Eax = 0x0f00;
|
||
VideoPortInt10(hwDeviceExtension, &biosArguments);
|
||
|
||
if ((biosArguments.Eax & 0xff) == Modes[i])
|
||
{
|
||
hwDeviceExtension->SVGABios = SVGASupport[i];
|
||
}
|
||
}
|
||
|
||
//
|
||
// IMPORTANT NOTE:
|
||
//
|
||
// The 750 Thinkpad has an STN panel. However, we detect it
|
||
// as an TFT 800x600 panel. So, if we detect this type of
|
||
// panel, but no SVGA support, we'll reset the panel type
|
||
// to STN_MONO_LCD.
|
||
//
|
||
|
||
if ((hwDeviceExtension->SVGABios == NO_SVGA_BIOS) &&
|
||
(hwDeviceExtension->DisplayType & IBM_F8532))
|
||
{
|
||
hwDeviceExtension->DisplayType &= ~IBM_F8532;
|
||
hwDeviceExtension->DisplayType |= STN_MONO_LCD;
|
||
}
|
||
|
||
//
|
||
// On IBM machines, we will use the Thinkpad System
|
||
// Management API. We call LCDInit to initialize.
|
||
//
|
||
|
||
LCDInit();
|
||
}
|
||
else
|
||
{
|
||
//
|
||
// If this is not an IBM machine, then we will
|
||
// simply assume that it has a SVGA Bios.
|
||
//
|
||
// The reason we do this is because I know of no
|
||
// non-IBM machines which do not have an SVGA Bios.
|
||
// Also, some of these machines BIOS's do not
|
||
// do the mode set into high res modes if the LCD
|
||
// is enabled. Therefore, it looks like it does
|
||
// not have an SVGA when it really does.
|
||
//
|
||
|
||
hwDeviceExtension->SVGABios = FULL_SVGA_BIOS;
|
||
}
|
||
}
|
||
|
||
if (hwDeviceExtension->BoardID == WD90C24A)
|
||
{
|
||
|
||
//
|
||
// Check to see if an external monitor is present.
|
||
//
|
||
// Note: Do not check for an external monitor, if the panel
|
||
// type is STN_MONO_LCD. This check may corrupt the
|
||
// display.
|
||
//
|
||
|
||
if (!(hwDeviceExtension->DisplayType & STN_MONO_LCD))
|
||
{
|
||
VideoPortSynchronizeExecution(hwDeviceExtension,
|
||
VpHighPriority,
|
||
(PMINIPORT_SYNCHRONIZE_ROUTINE) ExternalMonitorPresent,
|
||
hwDeviceExtension);
|
||
|
||
VideoDebugPrint((1, "\nHwDeviceExtension->DisplayType = 0x%x\n\n",
|
||
hwDeviceExtension->DisplayType));
|
||
}
|
||
else
|
||
{
|
||
//
|
||
// We'll have to assume that no external monitor is connected.
|
||
//
|
||
|
||
hwDeviceExtension->DisplayType &= ~MONITOR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
hwDeviceExtension->DisplayType |= MONITOR;
|
||
}
|
||
|
||
#endif
|
||
|
||
return TRUE;
|
||
|
||
} // VgaInitialize()
|
||
|
||
BOOLEAN
|
||
VgaStartIO(
|
||
PVOID HwDeviceExtension,
|
||
PVIDEO_REQUEST_PACKET RequestPacket
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine is the main execution routine for the miniport driver. It
|
||
acceptss a Video Request Packet, performs the request, and then returns
|
||
with the appropriate status.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's adapter information.
|
||
|
||
RequestPacket - Pointer to the video request packet. This structure
|
||
contains all the parameters passed to the VideoIoControl function.
|
||
|
||
Return Value:
|
||
|
||
This routine will return error codes from the various support routines
|
||
and will also return ERROR_INSUFFICIENT_BUFFER for incorrectly sized
|
||
buffers and ERROR_INVALID_FUNCTION for unsupported functions.
|
||
|
||
--*/
|
||
|
||
{
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
||
VP_STATUS status;
|
||
VIDEO_MODE videoMode;
|
||
PVIDEO_MEMORY_INFORMATION memoryInformation;
|
||
ULONG inIoSpace;
|
||
|
||
PVIDEO_SHARE_MEMORY pShareMemory;
|
||
PVIDEO_SHARE_MEMORY_INFORMATION pShareMemoryInformation;
|
||
PHYSICAL_ADDRESS shareAddress;
|
||
PVOID virtualAddress;
|
||
ULONG sharedViewSize;
|
||
ULONG ulBankSize;
|
||
|
||
VOID (*pfnBank)(ULONG,ULONG,PVOID);
|
||
|
||
//
|
||
// Switch on the IoContolCode in the RequestPacket. It indicates which
|
||
// function must be performed by the driver.
|
||
//
|
||
|
||
switch (RequestPacket->IoControlCode) {
|
||
|
||
|
||
case IOCTL_VIDEO_SHARE_VIDEO_MEMORY:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - ShareVideoMemory\n"));
|
||
|
||
if ( (RequestPacket->OutputBufferLength < sizeof(VIDEO_SHARE_MEMORY_INFORMATION)) ||
|
||
(RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) ) {
|
||
|
||
status = ERROR_INSUFFICIENT_BUFFER;
|
||
VideoDebugPrint((1, "VgaStartIO - ShareVideoMemory - ERROR_INSUFFICIENT_BUFFER\n"));
|
||
break;
|
||
|
||
}
|
||
|
||
pShareMemory = RequestPacket->InputBuffer;
|
||
|
||
if ( (pShareMemory->ViewOffset > hwDeviceExtension->AdapterMemorySize) ||
|
||
((pShareMemory->ViewOffset + pShareMemory->ViewSize) >
|
||
hwDeviceExtension->AdapterMemorySize) ) {
|
||
|
||
status = ERROR_INVALID_PARAMETER;
|
||
VideoDebugPrint((1, "VgaStartIO - ShareVideoMemory - ERROR_INVALID_PARAMETER\n"));
|
||
break;
|
||
|
||
}
|
||
|
||
RequestPacket->StatusBlock->Information =
|
||
sizeof(VIDEO_SHARE_MEMORY_INFORMATION);
|
||
|
||
//
|
||
// Beware: the input buffer and the output buffer are the same
|
||
// buffer, and therefore data should not be copied from one to the
|
||
// other
|
||
//
|
||
|
||
virtualAddress = pShareMemory->ProcessHandle;
|
||
sharedViewSize = pShareMemory->ViewSize;
|
||
|
||
inIoSpace = 0;
|
||
|
||
//
|
||
// NOTE: we are ignoring ViewOffset
|
||
//
|
||
|
||
shareAddress.QuadPart =
|
||
hwDeviceExtension->PhysicalFrameBase.QuadPart;
|
||
|
||
|
||
pfnBank = vBankMap;
|
||
ulBankSize = 0x10000; // 64K banks
|
||
|
||
status = VideoPortMapBankedMemory(hwDeviceExtension,
|
||
shareAddress,
|
||
&sharedViewSize,
|
||
&inIoSpace,
|
||
&virtualAddress,
|
||
ulBankSize, // bank size
|
||
FALSE, // we have separate read/write
|
||
pfnBank,
|
||
(PVOID)hwDeviceExtension);
|
||
|
||
pShareMemoryInformation = RequestPacket->OutputBuffer;
|
||
|
||
pShareMemoryInformation->SharedViewOffset = pShareMemory->ViewOffset;
|
||
pShareMemoryInformation->VirtualAddress = virtualAddress;
|
||
pShareMemoryInformation->SharedViewSize = sharedViewSize;
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_UNSHARE_VIDEO_MEMORY:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - UnshareVideoMemory\n"));
|
||
|
||
if (RequestPacket->InputBufferLength < sizeof(VIDEO_SHARE_MEMORY)) {
|
||
|
||
status = ERROR_INSUFFICIENT_BUFFER;
|
||
break;
|
||
|
||
}
|
||
|
||
pShareMemory = RequestPacket->InputBuffer;
|
||
|
||
status = VideoPortUnmapMemory(hwDeviceExtension,
|
||
pShareMemory->RequestedVirtualAddress,
|
||
pShareMemory->ProcessHandle);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_MAP_VIDEO_MEMORY:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - MapVideoMemory\n"));
|
||
|
||
if ( (RequestPacket->OutputBufferLength <
|
||
(RequestPacket->StatusBlock->Information =
|
||
sizeof(VIDEO_MEMORY_INFORMATION))) ||
|
||
(RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) ) {
|
||
|
||
status = ERROR_INSUFFICIENT_BUFFER;
|
||
}
|
||
|
||
memoryInformation = RequestPacket->OutputBuffer;
|
||
|
||
memoryInformation->VideoRamBase = ((PVIDEO_MEMORY)
|
||
(RequestPacket->InputBuffer))->RequestedVirtualAddress;
|
||
|
||
memoryInformation->VideoRamLength =
|
||
hwDeviceExtension->PhysicalVideoMemoryLength;
|
||
|
||
inIoSpace = 0;
|
||
|
||
status = VideoPortMapMemory(hwDeviceExtension,
|
||
hwDeviceExtension->PhysicalVideoMemoryBase,
|
||
&(memoryInformation->VideoRamLength),
|
||
&inIoSpace,
|
||
&(memoryInformation->VideoRamBase));
|
||
|
||
memoryInformation->FrameBufferBase =
|
||
((PUCHAR) (memoryInformation->VideoRamBase)) +
|
||
(hwDeviceExtension->PhysicalFrameBase.LowPart -
|
||
hwDeviceExtension->PhysicalVideoMemoryBase.LowPart);
|
||
|
||
memoryInformation->FrameBufferLength =
|
||
hwDeviceExtension->PhysicalFrameLength;
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_UNMAP_VIDEO_MEMORY:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - UnMapVideoMemory\n"));
|
||
|
||
if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) {
|
||
|
||
status = ERROR_INSUFFICIENT_BUFFER;
|
||
}
|
||
|
||
status = VideoPortUnmapMemory(hwDeviceExtension,
|
||
((PVIDEO_MEMORY)
|
||
(RequestPacket->InputBuffer))->
|
||
RequestedVirtualAddress,
|
||
0);
|
||
|
||
break;
|
||
|
||
case IOCTL_VIDEO_QUERY_AVAIL_MODES:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - QueryAvailableModes\n"));
|
||
|
||
status = VgaQueryAvailableModes(HwDeviceExtension,
|
||
(PVIDEO_MODE_INFORMATION)
|
||
RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - QueryNumAvailableModes\n"));
|
||
|
||
status = VgaQueryNumberOfAvailableModes(HwDeviceExtension,
|
||
(PVIDEO_NUM_MODES)
|
||
RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_QUERY_CURRENT_MODE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - QueryCurrentMode\n"));
|
||
|
||
status = VgaQueryCurrentMode(HwDeviceExtension,
|
||
(PVIDEO_MODE_INFORMATION) RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SET_CURRENT_MODE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SetCurrentModes\n"));
|
||
|
||
status = VgaSetMode(HwDeviceExtension,
|
||
(PVIDEO_MODE) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_RESET_DEVICE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - Reset Device\n"));
|
||
|
||
//
|
||
// If we are running on an IBM machine with a VGA
|
||
// chip, then we need to execute some special reset code.
|
||
//
|
||
|
||
WdResetHw(HwDeviceExtension, 0, 0);
|
||
|
||
videoMode.RequestedMode = DEFAULT_MODE;
|
||
|
||
status = VgaSetMode(HwDeviceExtension,
|
||
(PVIDEO_MODE) &videoMode,
|
||
sizeof(videoMode));
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_LOAD_AND_SET_FONT:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - LoadAndSetFont\n"));
|
||
|
||
status = VgaLoadAndSetFont(HwDeviceExtension,
|
||
(PVIDEO_LOAD_FONT_INFORMATION) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_QUERY_CURSOR_POSITION:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - QueryCursorPosition\n"));
|
||
|
||
status = VgaQueryCursorPosition(HwDeviceExtension,
|
||
(PVIDEO_CURSOR_POSITION) RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SET_CURSOR_POSITION:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SetCursorPosition\n"));
|
||
|
||
status = VgaSetCursorPosition(HwDeviceExtension,
|
||
(PVIDEO_CURSOR_POSITION)
|
||
RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_QUERY_CURSOR_ATTR:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - QueryCursorAttributes\n"));
|
||
|
||
status = VgaQueryCursorAttributes(HwDeviceExtension,
|
||
(PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SET_CURSOR_ATTR:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SetCursorAttributes\n"));
|
||
|
||
status = VgaSetCursorAttributes(HwDeviceExtension,
|
||
(PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SET_PALETTE_REGISTERS:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SetPaletteRegs\n"));
|
||
|
||
status = VgaSetPaletteReg(HwDeviceExtension,
|
||
(PVIDEO_PALETTE_DATA) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SET_COLOR_REGISTERS:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SetColorRegs\n"));
|
||
|
||
status = VgaSetColorLookup(HwDeviceExtension,
|
||
(PVIDEO_CLUT) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_ENABLE_VDM:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - EnableVDM\n"));
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 0;
|
||
hwDeviceExtension->SequencerAddressValue = 0;
|
||
|
||
hwDeviceExtension->CurrentNumVdmAccessRanges =
|
||
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE;
|
||
hwDeviceExtension->CurrentVdmAccessRange =
|
||
MinimalVgaValidatorAccessRange;
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
hwDeviceExtension->CurrentNumVdmAccessRanges,
|
||
hwDeviceExtension->CurrentVdmAccessRange);
|
||
|
||
status = NO_ERROR;
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_RESTORE_HARDWARE_STATE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - RestoreHardwareState\n"));
|
||
|
||
status = VgaRestoreHardwareState(HwDeviceExtension,
|
||
(PVIDEO_HARDWARE_STATE) RequestPacket->InputBuffer,
|
||
RequestPacket->InputBufferLength);
|
||
|
||
break;
|
||
|
||
|
||
case IOCTL_VIDEO_SAVE_HARDWARE_STATE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - SaveHardwareState\n"));
|
||
|
||
status = VgaSaveHardwareState(HwDeviceExtension,
|
||
(PVIDEO_HARDWARE_STATE) RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
case IOCTL_VIDEO_GET_BANK_SELECT_CODE:
|
||
|
||
VideoDebugPrint((2, "VgaStartIO - GetBankSelectCode\n"));
|
||
|
||
status = VgaGetBankSelectCode(HwDeviceExtension,
|
||
(PVIDEO_BANK_SELECT) RequestPacket->OutputBuffer,
|
||
RequestPacket->OutputBufferLength,
|
||
&RequestPacket->StatusBlock->Information);
|
||
|
||
break;
|
||
|
||
|
||
//
|
||
// if we get here, an invalid IoControlCode was specified.
|
||
//
|
||
|
||
default:
|
||
|
||
VideoDebugPrint((1, "Fell through vga startIO routine - invalid command\n"));
|
||
|
||
status = ERROR_INVALID_FUNCTION;
|
||
|
||
break;
|
||
|
||
}
|
||
|
||
RequestPacket->StatusBlock->Status = status;
|
||
|
||
return TRUE;
|
||
|
||
} // VgaStartIO()
|
||
|
||
//
|
||
// private routines
|
||
//
|
||
|
||
VP_STATUS
|
||
VgaLoadAndSetFont(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_LOAD_FONT_INFORMATION FontInformation,
|
||
ULONG FontInformationSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Takes a buffer containing a user-defined font and loads it into the
|
||
VGA soft font memory and programs the VGA to the appropriate character
|
||
cell size.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
FontInformation - Pointer to the structure containing the information
|
||
about the loadable ROM font to be set.
|
||
|
||
FontInformationSize - Length of the input buffer supplied by the user.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode
|
||
|
||
--*/
|
||
|
||
{
|
||
PUCHAR destination;
|
||
PUCHAR source;
|
||
USHORT width;
|
||
ULONG i;
|
||
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// Text mode only; If we are in a graphics mode, return an error
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough
|
||
// and that it contains all the data.
|
||
//
|
||
|
||
if ( (FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION)) ||
|
||
(FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION) +
|
||
sizeof(UCHAR) * (FontInformation->FontSize - 1)) ) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check for the width and height of the font
|
||
//
|
||
|
||
if ( ((FontInformation->WidthInPixels != 8) &&
|
||
(FontInformation->WidthInPixels != 9)) ||
|
||
(FontInformation->HeightInPixels > 32) ) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check the size of the font buffer is the right size for the size
|
||
// font being passed down.
|
||
//
|
||
|
||
if (FontInformation->FontSize < FontInformation->HeightInPixels * 256 *
|
||
sizeof(UCHAR) ) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Since the font parameters are valid, store the parameters in the
|
||
// device extension and load the font.
|
||
//
|
||
|
||
HwDeviceExtension->FontPelRows = FontInformation->HeightInPixels;
|
||
HwDeviceExtension->FontPelColumns = FontInformation->WidthInPixels;
|
||
|
||
HwDeviceExtension->CurrentMode->row =
|
||
HwDeviceExtension->CurrentMode->vres / HwDeviceExtension->FontPelRows;
|
||
|
||
width =
|
||
HwDeviceExtension->CurrentMode->hres / HwDeviceExtension->FontPelColumns;
|
||
|
||
if (width < (USHORT)HwDeviceExtension->CurrentMode->col) {
|
||
|
||
HwDeviceExtension->CurrentMode->col = width;
|
||
|
||
}
|
||
|
||
source = &(FontInformation->Font[0]);
|
||
|
||
//
|
||
// Set up the destination and source pointers for the font
|
||
//
|
||
|
||
destination = (PUCHAR)HwDeviceExtension->VideoMemoryAddress;
|
||
|
||
//
|
||
// Map font buffer at A0000
|
||
//
|
||
|
||
VgaInterpretCmdStream(HwDeviceExtension, EnableA000Data);
|
||
|
||
//
|
||
// Move the font to its destination
|
||
//
|
||
|
||
for (i = 1; i <= 256; i++) {
|
||
|
||
VideoPortWriteRegisterBufferUchar(destination,
|
||
source,
|
||
FontInformation->HeightInPixels);
|
||
|
||
destination += 32;
|
||
source += FontInformation->HeightInPixels;
|
||
|
||
}
|
||
|
||
VgaInterpretCmdStream(HwDeviceExtension, DisableA000Color);
|
||
|
||
//
|
||
// Restore to a text mode.
|
||
//
|
||
|
||
//
|
||
// Set Height of font.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x9);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR,
|
||
(UCHAR)(FontInformation->HeightInPixels - 1));
|
||
|
||
//
|
||
// Set Width of font.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x12);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR,
|
||
(UCHAR)(((USHORT)FontInformation->HeightInPixels *
|
||
(USHORT)HwDeviceExtension->CurrentMode->row) - 1));
|
||
|
||
i = HwDeviceExtension->CurrentMode->vres /
|
||
HwDeviceExtension->CurrentMode->row;
|
||
|
||
//
|
||
// Set Cursor End
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0xb);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR, (UCHAR)--i);
|
||
|
||
//
|
||
// Set Cursor Statr
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0xa);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR, (UCHAR)--i);
|
||
|
||
return NO_ERROR;
|
||
|
||
} //end VgaLoadAndSetFont()
|
||
|
||
VP_STATUS
|
||
VgaQueryCursorPosition(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_POSITION CursorPosition,
|
||
ULONG CursorPositionSize,
|
||
PULONG OutputSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine returns the row and column of the cursor.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
CursorPosition - Pointer to the output buffer supplied by the user. This
|
||
is where the cursor position is stored.
|
||
|
||
CursorPositionSize - Length of the output buffer supplied by the user.
|
||
|
||
OutputSize - Pointer to a buffer in which to return the actual size of
|
||
the data in the buffer. If the buffer was not large enough, this
|
||
contains the minimum required buffer size.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
||
any useful data
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode
|
||
|
||
--*/
|
||
|
||
{
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// Text mode only; If we are in a graphics mode, return an error
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
||
|
||
*OutputSize = 0;
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// If the buffer passed in is not large enough return an
|
||
// appropriate error code.
|
||
//
|
||
|
||
if (CursorPositionSize < (*OutputSize = sizeof(VIDEO_CURSOR_POSITION)) ) {
|
||
|
||
*OutputSize = 0;
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Store the postition of the cursor into the buffer.
|
||
//
|
||
|
||
CursorPosition->Column = HwDeviceExtension->CursorPosition.Column;
|
||
CursorPosition->Row = HwDeviceExtension->CursorPosition.Row;
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaQueryCursorPosition()
|
||
|
||
VP_STATUS
|
||
VgaSetCursorPosition(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_POSITION CursorPosition,
|
||
ULONG CursorPositionSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine verifies that the requested cursor position is within
|
||
the row and column bounds of the current mode and font. If valid, then
|
||
it sets the row and column of the cursor.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
CursorPosition - Pointer to the structure containing the cursor position.
|
||
|
||
CursorPositionSize - Length of the input buffer supplied by the user.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode
|
||
|
||
--*/
|
||
|
||
{
|
||
USHORT position;
|
||
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// Text mode only; If we are in a graphics mode, return an error
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough.
|
||
//
|
||
|
||
if (CursorPositionSize < sizeof(VIDEO_CURSOR_POSITION)) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check if the new values for the cursor positions are in the valid
|
||
// bounds for the screen.
|
||
//
|
||
|
||
if ((CursorPosition->Column >= HwDeviceExtension->CurrentMode->col) ||
|
||
(CursorPosition->Row >= HwDeviceExtension->CurrentMode->row)) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Store these new values in the device extension so we can use them in
|
||
// a QUERY.
|
||
//
|
||
|
||
HwDeviceExtension->CursorPosition.Column = CursorPosition->Column;
|
||
HwDeviceExtension->CursorPosition.Row = CursorPosition->Row;
|
||
|
||
//
|
||
// Calculate the position on the screen at which the cursor must be
|
||
// be displayed
|
||
//
|
||
|
||
position = (USHORT) (HwDeviceExtension->CurrentMode->col *
|
||
CursorPosition->Row + CursorPosition->Column);
|
||
|
||
|
||
//
|
||
// Address Cursor Location Low Register in CRT Controller Registers
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, IND_CURSOR_LOW_LOC);
|
||
|
||
//
|
||
// Set Cursor Location Low Register
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR, (UCHAR) (position & 0x00FF));
|
||
|
||
//
|
||
// Address Cursor Location High Register in CRT Controller Registers
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, IND_CURSOR_HIGH_LOC);
|
||
|
||
//
|
||
// Set Cursor Location High Register
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR, (UCHAR) (position >> 8));
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaSetCursorPosition()
|
||
|
||
VP_STATUS
|
||
VgaQueryCursorAttributes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
||
ULONG CursorAttributesSize,
|
||
PULONG OutputSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine returns information about the height and visibility of the
|
||
cursor.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
CursorAttributes - Pointer to the output buffer supplied by the user.
|
||
This is where the cursor type is stored.
|
||
|
||
CursorAttributesSize - Length of the output buffer supplied by the user.
|
||
|
||
OutputSize - Pointer to a buffer in which to return the actual size of
|
||
the data in the buffer. If the buffer was not large enough, this
|
||
contains the minimum required buffer size.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
||
any useful data
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode
|
||
|
||
--*/
|
||
|
||
{
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// Text mode only; If we are in a graphics mode, return an error
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
||
|
||
*OutputSize = 0;
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Find out the size of the data to be put in the the buffer and return
|
||
// that in the status information (whether or not the information is
|
||
// there). If the buffer passed in is not large enough return an
|
||
// appropriate error code.
|
||
//
|
||
|
||
if (CursorAttributesSize < (*OutputSize =
|
||
sizeof(VIDEO_CURSOR_ATTRIBUTES)) ) {
|
||
|
||
*OutputSize = 0;
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Store the cursor information into the buffer.
|
||
//
|
||
|
||
CursorAttributes->Height = (USHORT) HwDeviceExtension->CursorTopScanLine;
|
||
CursorAttributes->Width = (USHORT) HwDeviceExtension->CursorBottomScanLine;
|
||
CursorAttributes->Enable = HwDeviceExtension->CursorEnable;
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaQueryCursorAttributes()
|
||
|
||
VP_STATUS
|
||
VgaSetCursorAttributes(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
||
ULONG CursorAttributesSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine verifies that the requested cursor height is within the
|
||
bounds of the character cell. If valid, then it sets the new
|
||
visibility and height of the cursor.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
CursorType - Pointer to the structure containing the cursor information.
|
||
|
||
CursorTypeSize - Length of the input buffer supplied by the user.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode
|
||
|
||
--*/
|
||
|
||
{
|
||
UCHAR cursorLine;
|
||
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// Text mode only; If we are in a graphics mode, return an error
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough.
|
||
//
|
||
|
||
if (CursorAttributesSize < sizeof(VIDEO_CURSOR_ATTRIBUTES)) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check if the new values for the cursor type are in the valid range.
|
||
//
|
||
|
||
if ((CursorAttributes->Height >= HwDeviceExtension->FontPelRows) ||
|
||
(CursorAttributes->Width > 31)) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Store the cursor information in the device extension so we can use
|
||
// them in a QUERY.
|
||
//
|
||
|
||
HwDeviceExtension->CursorTopScanLine = (UCHAR) CursorAttributes->Height;
|
||
HwDeviceExtension->CursorBottomScanLine = (UCHAR) CursorAttributes->Width;
|
||
HwDeviceExtension->CursorEnable = CursorAttributes->Enable;
|
||
|
||
//
|
||
// Address Cursor Start Register in CRT Controller Registers
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR,
|
||
IND_CURSOR_START);
|
||
|
||
//
|
||
// Set Cursor Start Register by writting to CRTCtl Data Register
|
||
// Preserve the high three bits of this register.
|
||
//
|
||
// Only the Five low bits are used for the cursor height.
|
||
// Bit 5 is cursor enable, bit 6 and 7 preserved.
|
||
//
|
||
|
||
cursorLine = (UCHAR) CursorAttributes->Height & 0x1F;
|
||
|
||
cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR) & 0xC0;
|
||
|
||
if (!CursorAttributes->Enable) {
|
||
|
||
cursorLine |= 0x20; // Flip cursor off bit
|
||
|
||
}
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + CRTC_DATA_PORT_COLOR,
|
||
cursorLine);
|
||
|
||
//
|
||
// Address Cursor End Register in CRT Controller Registers
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR,
|
||
IND_CURSOR_END);
|
||
|
||
//
|
||
// Set Cursor End Register. Preserve the high three bits of this
|
||
// register.
|
||
//
|
||
|
||
cursorLine =
|
||
(CursorAttributes->Width < (USHORT)(HwDeviceExtension->FontPelRows - 1)) ?
|
||
CursorAttributes->Width : (HwDeviceExtension->FontPelRows - 1);
|
||
|
||
cursorLine &= 0x1f;
|
||
|
||
cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR) & 0xE0;
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + CRTC_DATA_PORT_COLOR,
|
||
cursorLine);
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaSetCursorAttributes()
|
||
|
||
BOOLEAN
|
||
VgaIsPresent(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine returns TRUE if a VGA is present. Determining whether a VGA
|
||
is present is a two-step process. First, this routine walks bits through
|
||
the Bit Mask register, to establish that there are readable indexed
|
||
registers (EGAs normally don't have readable registers, and other adapters
|
||
are unlikely to have indexed registers). This test is done first because
|
||
it's a non-destructive EGA rejection test (correctly rejects EGAs, but
|
||
doesn't potentially mess up the screen or the accessibility of display
|
||
memory). Normally, this would be an adequate test, but some EGAs have
|
||
readable registers, so next, we check for the existence of the Chain4 bit
|
||
in the Memory Mode register; this bit doesn't exist in EGAs. It's
|
||
conceivable that there are EGAs with readable registers and a register bit
|
||
where Chain4 is stored, although I don't know of any; if a better test yet
|
||
is needed, memory could be written to in Chain4 mode, and then examined
|
||
plane by plane in non-Chain4 mode to make sure the Chain4 bit did what it's
|
||
supposed to do. However, the current test should be adequate to eliminate
|
||
just about all EGAs, and 100% of everything else.
|
||
|
||
If this function fails to find a VGA, it attempts to undo any damage it
|
||
may have inadvertently done while testing. The underlying assumption for
|
||
the damage control is that if there's any non-VGA adapter at the tested
|
||
ports, it's an EGA or an enhanced EGA, because: a) I don't know of any
|
||
other adapters that use 3C4/5 or 3CE/F, and b), if there are other
|
||
adapters, I certainly don't know how to restore their original states. So
|
||
all error recovery is oriented toward putting an EGA back in a writable
|
||
state, so that error messages are visible. The EGA's state on entry is
|
||
assumed to be text mode, so the Memory Mode register is restored to the
|
||
default state for text mode.
|
||
|
||
If a VGA is found, the VGA is returned to its original state after
|
||
testing is finished.
|
||
|
||
Arguments:
|
||
|
||
None.
|
||
|
||
Return Value:
|
||
|
||
TRUE if a VGA is present, FALSE if not.
|
||
|
||
--*/
|
||
|
||
{
|
||
UCHAR originalGCAddr;
|
||
UCHAR originalSCAddr;
|
||
UCHAR originalBitMask;
|
||
UCHAR originalReadMap;
|
||
UCHAR originalMemoryMode;
|
||
UCHAR testMask;
|
||
BOOLEAN returnStatus;
|
||
|
||
//
|
||
// Remember the original state of the Graphics Controller Address register.
|
||
//
|
||
|
||
originalGCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT);
|
||
|
||
//
|
||
// Write the Read Map register with a known state so we can verify
|
||
// that it isn't changed after we fool with the Bit Mask. This ensures
|
||
// that we're dealing with indexed registers, since both the Read Map and
|
||
// the Bit Mask are addressed at GRAPH_DATA_PORT.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
|
||
//
|
||
// If we can't read back the Graphics Address register setting we just
|
||
// performed, it's not readable and this isn't a VGA.
|
||
//
|
||
|
||
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_READ_MAP) {
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
//
|
||
// Set the Read Map register to a known state.
|
||
//
|
||
|
||
originalReadMap = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, READ_MAP_TEST_SETTING);
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
|
||
|
||
//
|
||
// The Read Map setting we just performed can't be read back; not a
|
||
// VGA. Restore the default Read Map state.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
//
|
||
// Remember the original setting of the Bit Mask register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
||
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_BIT_MASK) {
|
||
|
||
//
|
||
// The Graphics Address register setting we just made can't be read
|
||
// back; not a VGA. Restore the default Read Map state.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
originalBitMask = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
|
||
//
|
||
// Set up the initial test mask we'll write to and read from the Bit Mask.
|
||
//
|
||
|
||
testMask = 0xBB;
|
||
|
||
do {
|
||
|
||
//
|
||
// Write the test mask to the Bit Mask.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, testMask);
|
||
|
||
//
|
||
// Make sure the Bit Mask remembered the value.
|
||
//
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) != testMask) {
|
||
|
||
//
|
||
// The Bit Mask is not properly writable and readable; not a VGA.
|
||
// Restore the Bit Mask and Read Map to their default states.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
//
|
||
// Cycle the mask for next time.
|
||
//
|
||
|
||
testMask >>= 1;
|
||
|
||
} while (testMask != 0);
|
||
|
||
//
|
||
// There's something readable at GRAPH_DATA_PORT; now switch back and
|
||
// make sure that the Read Map register hasn't changed, to verify that
|
||
// we're dealing with indexed registers.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
|
||
|
||
//
|
||
// The Read Map is not properly writable and readable; not a VGA.
|
||
// Restore the Bit Mask and Read Map to their default states, in case
|
||
// this is an EGA, so subsequent writes to the screen aren't garbled.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
//
|
||
// We've pretty surely verified the existence of the Bit Mask register.
|
||
// Put the Graphics Controller back to the original state.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, originalReadMap);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, originalBitMask);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, originalGCAddr);
|
||
|
||
//
|
||
// Now, check for the existence of the Chain4 bit.
|
||
//
|
||
|
||
//
|
||
// Remember the original states of the Sequencer Address and Memory Mode
|
||
// registers.
|
||
//
|
||
|
||
originalSCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
||
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT) & SEQ_ADDR_MASK) != IND_MEMORY_MODE) {
|
||
|
||
//
|
||
// Couldn't read back the Sequencer Address register setting we just
|
||
// performed.
|
||
//
|
||
|
||
return FALSE;
|
||
}
|
||
originalMemoryMode = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
//
|
||
// Toggle the Chain4 bit and read back the result. This must be done during
|
||
// sync reset, since we're changing the chaining state.
|
||
//
|
||
|
||
//
|
||
// Begin sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Toggle the Chain4 bit.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, (UCHAR)(originalMemoryMode ^ CHAIN4_MASK));
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT) != (UCHAR) (originalMemoryMode ^ CHAIN4_MASK)) {
|
||
|
||
//
|
||
// Chain4 bit not there; not a VGA.
|
||
// Set text mode default for Memory Mode register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, MEMORY_MODE_TEXT_DEFAULT);
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
||
|
||
returnStatus = FALSE;
|
||
|
||
} else {
|
||
|
||
//
|
||
// It's a VGA.
|
||
//
|
||
|
||
//
|
||
// Restore the original Memory Mode setting.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, originalMemoryMode);
|
||
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT)(IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Restore the original Sequencer Address setting.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, originalSCAddr);
|
||
|
||
returnStatus = TRUE;
|
||
}
|
||
|
||
return returnStatus;
|
||
|
||
} // VgaIsPresent()
|
||
|
||
BOOLEAN
|
||
WdIsPresent(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine returns TRUE if an WDVGA is present. It assumes that it's
|
||
already been established that a VGA is present. It performs the Western
|
||
Digital recommended ID test. If all this works, then this is indeed an
|
||
chip from Western Digital.
|
||
|
||
All the registers will be preserved either this function fails to find a
|
||
WD vga or a WD vga is found.
|
||
|
||
Arguments:
|
||
|
||
None.
|
||
|
||
Return Value:
|
||
|
||
TRUE if a WDVGA is present, FALSE if not.
|
||
|
||
--*/
|
||
|
||
{
|
||
#define MAX_ROM_SCAN 4096
|
||
|
||
UCHAR *pRomAddr;
|
||
PHYSICAL_ADDRESS paRom = {0x000C0000,0x00000000};
|
||
|
||
UCHAR GraphSave0c;
|
||
UCHAR GraphSave0f;
|
||
UCHAR temp1, temp2;
|
||
|
||
BOOLEAN status = TRUE;
|
||
PWSTR pwszChipString;
|
||
ULONG cbChipString;
|
||
|
||
//
|
||
// write 3ce.0c
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0c);
|
||
GraphSave0c = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
temp1 = GraphSave0c & 0xbf;
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, temp1);
|
||
|
||
//
|
||
// write 3ce.0f
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0f);
|
||
GraphSave0f = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, 0x0);
|
||
|
||
//
|
||
// write 3ce.09
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x09);
|
||
temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)(temp1+1));
|
||
temp2 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, temp1);
|
||
|
||
if ((temp1+1) == temp2) {
|
||
|
||
status = FALSE;
|
||
goto NOT_WDVGA;
|
||
|
||
}
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), 0x050f);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x09);
|
||
temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)(temp1+1));
|
||
temp2 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, temp1);
|
||
|
||
if ((temp1+1) != temp2) {
|
||
|
||
status = FALSE;
|
||
goto NOT_WDVGA;
|
||
|
||
}
|
||
|
||
//
|
||
// it *is* a WDVGA!
|
||
//
|
||
|
||
//
|
||
// Assume a 90c30
|
||
//
|
||
|
||
HwDeviceExtension->BoardID = WD90C30;
|
||
pwszChipString = L"WD 90C30";
|
||
cbChipString = sizeof(L"WD 90C30");
|
||
|
||
//
|
||
// Look for extended regsiters that are only in WD90C31 and over
|
||
//
|
||
|
||
if (HwDeviceExtension->ExtendedRegisters) {
|
||
|
||
UCHAR save;
|
||
PUCHAR ExtendedIOAddress;
|
||
|
||
//
|
||
// Get WDC31 extended port base address.
|
||
//
|
||
|
||
if ((ExtendedIOAddress =
|
||
VideoPortGetDeviceBase(HwDeviceExtension,
|
||
VgaAccessRange[3].RangeStart,
|
||
VgaAccessRange[3].RangeLength,
|
||
VgaAccessRange[3].RangeInIoSpace)) == NULL) {
|
||
|
||
VideoDebugPrint((2, "WDVGAIsPresent - Fail to get ext. io address\n"));
|
||
status = FALSE;
|
||
goto NOT_WDVGA;
|
||
|
||
}
|
||
|
||
save = VideoPortReadPortUchar(ExtendedIOAddress);
|
||
|
||
VideoPortWritePortUchar(ExtendedIOAddress, 0x02);
|
||
|
||
temp1 = VideoPortReadPortUchar(ExtendedIOAddress);
|
||
|
||
if (temp1 == 0x02)
|
||
{
|
||
UCHAR temp, pr72;
|
||
BOOLEAN IsVGA = FALSE;
|
||
|
||
//
|
||
// Assume we have a WD90C31
|
||
//
|
||
|
||
HwDeviceExtension->BoardID = WD90C31;
|
||
pwszChipString = L"WD 90C31";
|
||
cbChipString = sizeof(L"WD 90C31");
|
||
|
||
//
|
||
// The following code was derived from IBM's
|
||
// VESA TSR for the WDVGA. This code
|
||
// detects the presence of a VGA chip.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
0x4806);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT,
|
||
0x35);
|
||
temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
if (temp == 0x35)
|
||
{
|
||
//
|
||
// We don't know if it is a VGA yet or not,
|
||
// but we have passed our first test.
|
||
//
|
||
|
||
pr72 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT,
|
||
0x70);
|
||
temp = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT,
|
||
pr72);
|
||
|
||
if (temp == 0x70)
|
||
{
|
||
IsVGA = TRUE;
|
||
}
|
||
}
|
||
|
||
if (IsVGA)
|
||
{
|
||
//
|
||
// VGA
|
||
//
|
||
|
||
HwDeviceExtension->BoardID = WD90C24A;
|
||
pwszChipString = L"Western Digital 90C24A";
|
||
cbChipString = sizeof(L"Western Digital 90C24A");
|
||
|
||
//
|
||
// H/W cursor off for initial phase. Probably enabled after
|
||
// pointer related IOControl calling.
|
||
// This is not required if the HAL display initialization code
|
||
// has already done this. For most of Intel machines this code
|
||
// is not required because no codes enable this hardware cursor
|
||
// but the PowerPC firmware did it.
|
||
//
|
||
|
||
VideoPortWritePortUchar(ExtendedIOAddress+0, 0x02);
|
||
VideoPortWritePortUchar(ExtendedIOAddress+1, 0x00);
|
||
VideoPortWritePortUchar(ExtendedIOAddress+2, 0x00);
|
||
VideoPortWritePortUchar(ExtendedIOAddress+3, 0x00);
|
||
VideoPortWritePortUchar(ExtendedIOAddress+0, 0x00);
|
||
|
||
//
|
||
// Now that we know we have a VGA chip, lets
|
||
// see if we are on an IBM machine. We'll check
|
||
// this by looking at address 0xf000:0xe00e. This
|
||
// address should contain the ANSI string IBM if
|
||
// we are running on an IBM machine.
|
||
//
|
||
// Well have to map this range in to examine it.
|
||
//
|
||
|
||
{
|
||
PHYSICAL_ADDRESS ID_String;
|
||
PVOID VirtualAddress;
|
||
|
||
//
|
||
// This is the address in the machine ROM
|
||
// where the string "IBM" should appear, if
|
||
// the machine is an IBM machine.
|
||
//
|
||
|
||
ID_String.HighPart = 0;
|
||
ID_String.LowPart = 0xF0016;
|
||
|
||
VirtualAddress =
|
||
VideoPortGetDeviceBase(HwDeviceExtension,
|
||
ID_String,
|
||
sizeof("IBM"),
|
||
FALSE);
|
||
|
||
HwDeviceExtension->IsIBM = FALSE;
|
||
|
||
if (VirtualAddress != NULL)
|
||
{
|
||
//
|
||
// check to see if the string IBM is at the location
|
||
// we are examining.
|
||
//
|
||
// NOTE: sizeof("IBM") = 4, but we only want to look
|
||
// at the first 3 characters. (There won't be a NULL
|
||
// terminator.)
|
||
//
|
||
|
||
if (VideoPortCompareMemory(VirtualAddress,
|
||
"IBM",
|
||
sizeof("IBM")-1) ==
|
||
sizeof("IBM")-1)
|
||
{
|
||
VP_STATUS status;
|
||
|
||
HwDeviceExtension->IsIBM = TRUE;
|
||
|
||
VideoDebugPrint((1, "Machine Type detected as IBM\n"));
|
||
|
||
//
|
||
// If this is an IBM machine, we need to verify another
|
||
// access range so that we can use IBMs System
|
||
// Management API.
|
||
//
|
||
|
||
status = VideoPortVerifyAccessRanges(HwDeviceExtension,
|
||
NUM_IBM_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
if (status != NO_ERROR)
|
||
{
|
||
//
|
||
// We can't load if we don't get this access range.
|
||
//
|
||
|
||
VideoDebugPrint((1, "Couldn't reserve additional access "
|
||
"range required by IBM Thinkpad.\n"));
|
||
|
||
goto NOT_WDVGA;
|
||
}
|
||
|
||
}
|
||
|
||
//
|
||
// Free the memory we got...
|
||
//
|
||
|
||
VideoPortFreeDeviceBase(HwDeviceExtension,
|
||
VirtualAddress);
|
||
}
|
||
}
|
||
|
||
//
|
||
// get the panel type
|
||
//
|
||
|
||
GetPanelType(HwDeviceExtension);
|
||
|
||
}
|
||
else
|
||
{
|
||
//
|
||
// we aren't a VGA, so lets release our
|
||
// our claim on the the panel detection registers.
|
||
//
|
||
|
||
VideoPortVerifyAccessRanges(HwDeviceExtension,
|
||
NUM_WD_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
HwDeviceExtension->ExtendedRegisters = EXTENDED_REGISTERS;
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
//
|
||
// Release the extended registers since they don't
|
||
// exist on this chip.
|
||
//
|
||
|
||
VideoPortVerifyAccessRanges(HwDeviceExtension,
|
||
NUM_VGA_ACCESS_RANGES,
|
||
VgaAccessRange);
|
||
|
||
HwDeviceExtension->ExtendedRegisters = NO_EXTENDED_REGISTERS;
|
||
}
|
||
|
||
VideoPortWritePortUchar(ExtendedIOAddress, save);
|
||
|
||
VideoPortFreeDeviceBase(HwDeviceExtension,
|
||
ExtendedIOAddress);
|
||
|
||
}
|
||
|
||
//
|
||
// If it is a WD, always unlock the extended sequencer register, since
|
||
// in some cases the cirrus will cause them to get locked.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
||
0x06);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_DATA_PORT,
|
||
0x48);
|
||
|
||
//
|
||
// Get chip type to determine if we have a 90c30 or 90c00
|
||
//
|
||
|
||
if (HwDeviceExtension->BoardID < WD90C31) {
|
||
|
||
UCHAR SeqSave08;
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, 0x08);
|
||
SeqSave08 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, 0x5A);
|
||
temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
if ( temp1 != 0x5A ) {
|
||
|
||
//
|
||
// old chip, can't support 1R1W banking
|
||
//
|
||
|
||
HwDeviceExtension->BoardID = WD90C00;
|
||
pwszChipString = L"WD 90C00 / 90C10";
|
||
cbChipString = sizeof(L"WD 90C00 / 90C10");
|
||
}
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, 0x08);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, SeqSave08);
|
||
|
||
}
|
||
|
||
//
|
||
// Detect a Speestart 90c31 board.
|
||
//
|
||
// Map in the ROM address space at 0xc000:0
|
||
//
|
||
|
||
pRomAddr = VideoPortGetDeviceBase(HwDeviceExtension,
|
||
paRom,
|
||
(ULONG)0x00008000,
|
||
FALSE);
|
||
|
||
if (pRomAddr) { // Valid ROM address?
|
||
|
||
PWSTR pwszDeviceString;
|
||
ULONG cbDeviceString;
|
||
|
||
//
|
||
// Look for brand name signatures (from DIAMOND) in the ROM.
|
||
//
|
||
|
||
//
|
||
// We will try to recognize a few boards.
|
||
// make sure we are looking at a bios!
|
||
//
|
||
|
||
pwszDeviceString = L"Western Digital";
|
||
cbDeviceString = sizeof(L"Western Digital");
|
||
|
||
if (*((PUSHORT) pRomAddr) == 0xAA55) {
|
||
|
||
if (VideoPortScanRom(HwDeviceExtension,
|
||
pRomAddr,
|
||
MAX_ROM_SCAN,
|
||
" SpeedStar 24X")) {
|
||
|
||
pwszDeviceString = L"Diamond Speedstar 24X";
|
||
cbDeviceString = sizeof(L"Diamond Speedstar 24X");
|
||
|
||
if (HwDeviceExtension->BoardID == WD90C31) {
|
||
|
||
HwDeviceExtension->BoardID = SPEEDSTAR31;
|
||
|
||
} else if (HwDeviceExtension->BoardID == WD90C30) {
|
||
|
||
HwDeviceExtension->BoardID = SPEEDSTAR30;
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
VideoPortFreeDeviceBase(HwDeviceExtension,
|
||
pRomAddr);
|
||
|
||
VideoPortSetRegistryParameters(HwDeviceExtension,
|
||
L"HardwareInformation.AdapterString",
|
||
pwszDeviceString,
|
||
cbDeviceString);
|
||
|
||
}
|
||
|
||
//
|
||
// Get the memory size.
|
||
//
|
||
|
||
VgaSizeMemory(HwDeviceExtension);
|
||
|
||
VideoPortSetRegistryParameters(HwDeviceExtension,
|
||
L"HardwareInformation.ChipType",
|
||
pwszChipString,
|
||
cbChipString);
|
||
|
||
VideoPortSetRegistryParameters(HwDeviceExtension,
|
||
L"HardwareInformation.MemorySize",
|
||
&HwDeviceExtension->AdapterMemorySize,
|
||
sizeof(ULONG));
|
||
|
||
NOT_WDVGA:
|
||
|
||
//
|
||
// Restore registers to what they were.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0c);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, GraphSave0c);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0f);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, GraphSave0f);
|
||
|
||
return status;
|
||
|
||
} // end WdIsPresent()
|
||
|
||
|
||
VOID
|
||
VgaSizeMemory(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine determines the amount of VideoMemory on the adapter.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
Return Value:
|
||
|
||
None.
|
||
|
||
--*/
|
||
{
|
||
|
||
UCHAR data;
|
||
|
||
if (HwDeviceExtension->BoardID == WD90C24A) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x29);
|
||
|
||
data = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR,
|
||
(UCHAR)((data & (UCHAR)0x077) | (UCHAR)0x080));
|
||
// unlock PR11 3d4.2a
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x2a);
|
||
|
||
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR) & 0x020) == 0x020)
|
||
{
|
||
|
||
HwDeviceExtension->AdapterMemorySize = 0x00080000;
|
||
|
||
} else {
|
||
|
||
HwDeviceExtension->AdapterMemorySize = 0x00100000;
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
//
|
||
// Use 3CF.B to determine memory size on other WD's
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0B);
|
||
|
||
data = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
|
||
switch ( data & 0xC0 ) {
|
||
|
||
case 0x00:
|
||
case 0x40:
|
||
|
||
HwDeviceExtension->AdapterMemorySize = 0x00040000;
|
||
break;
|
||
|
||
case 0x80:
|
||
|
||
HwDeviceExtension->AdapterMemorySize = 0x00080000;
|
||
break;
|
||
|
||
case 0xC0:
|
||
|
||
HwDeviceExtension->AdapterMemorySize = 0x00100000;
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
}
|
||
} // end VgaSizeMemory();
|
||
|
||
|
||
VP_STATUS
|
||
VgaSetPaletteReg(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_PALETTE_DATA PaletteBuffer,
|
||
ULONG PaletteBufferSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine sets a specified portion of the EGA (not DAC) palette
|
||
registers.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
PaletteBuffer - Pointer to the structure containing the palette data.
|
||
|
||
PaletteBufferSize - Length of the input buffer supplied by the user.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
||
|
||
ERROR_INVALID_PARAMETER - invalid palette size.
|
||
|
||
--*/
|
||
|
||
{
|
||
USHORT i;
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough.
|
||
//
|
||
|
||
if ((PaletteBufferSize) < (sizeof(VIDEO_PALETTE_DATA)) ||
|
||
(PaletteBufferSize < (sizeof(VIDEO_PALETTE_DATA) +
|
||
(sizeof(USHORT) * (PaletteBuffer->NumEntries -1)) ))) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check to see if the parameters are valid.
|
||
//
|
||
|
||
if ( (PaletteBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER ) ||
|
||
(PaletteBuffer->NumEntries == 0) ||
|
||
(PaletteBuffer->FirstEntry + PaletteBuffer->NumEntries >
|
||
VIDEO_MAX_PALETTE_REGISTER + 1 ) ) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Reset ATC to index mode
|
||
//
|
||
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_INITIALIZE_PORT_COLOR);
|
||
|
||
//
|
||
// Blast out our palette values.
|
||
//
|
||
|
||
for (i = 0; i < PaletteBuffer->NumEntries; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
|
||
(UCHAR)(i+PaletteBuffer->FirstEntry));
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_DATA_WRITE_PORT,
|
||
(UCHAR)PaletteBuffer->Colors[i]);
|
||
}
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
|
||
VIDEO_ENABLE);
|
||
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaSetPaletteReg()
|
||
|
||
|
||
VP_STATUS
|
||
VgaSetColorLookup(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_CLUT ClutBuffer,
|
||
ULONG ClutBufferSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine sets a specified portion of the DAC color lookup table
|
||
settings.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
ClutBufferSize - Length of the input buffer supplied by the user.
|
||
|
||
ClutBuffer - Pointer to the structure containing the color lookup table.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
||
|
||
ERROR_INVALID_PARAMETER - invalid clut size.
|
||
|
||
--*/
|
||
|
||
{
|
||
ULONG i;
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough.
|
||
//
|
||
|
||
if ( (ClutBufferSize < sizeof(VIDEO_CLUT) - sizeof(ULONG)) ||
|
||
(ClutBufferSize < sizeof(VIDEO_CLUT) +
|
||
(sizeof(ULONG) * (ClutBuffer->NumEntries - 1)) ) ) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Check to see if the parameters are valid.
|
||
//
|
||
|
||
if ( (ClutBuffer->NumEntries == 0) ||
|
||
(ClutBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER) ||
|
||
(ClutBuffer->FirstEntry + ClutBuffer->NumEntries >
|
||
VIDEO_MAX_COLOR_REGISTER + 1) ) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Set CLUT registers directly on the hardware
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT, (UCHAR) ClutBuffer->FirstEntry);
|
||
|
||
for (i = 0; i < ClutBuffer->NumEntries; i++) {
|
||
|
||
VideoPortWritePortBufferUchar((PUCHAR)HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT,
|
||
&(ClutBuffer->LookupTable[i].RgbArray.Red),
|
||
0x03);
|
||
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaSetColorLookup()
|
||
|
||
VP_STATUS
|
||
VgaRestoreHardwareState(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_HARDWARE_STATE HardwareState,
|
||
ULONG HardwareStateSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Restores all registers and memory of the VGA.
|
||
|
||
Note: HardwareState points to the actual buffer from which the state
|
||
is to be restored. This buffer will always be big enough (we specified
|
||
the required size at DriverEntry).
|
||
|
||
Note: The offset in the hardware state header from which each general
|
||
register is restored is the offset of the write address of that register
|
||
from the base I/O address of the VGA.
|
||
|
||
|
||
!!! NOTE
|
||
We assume the miniport and the display driver have UNLOCKED the extended
|
||
registers so we can READ and WRITE them.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
HardwareState - Pointer to a structure from which the saved state is to be
|
||
restored (actually only info about and a pointer to the actual save
|
||
buffer).
|
||
|
||
HardwareStateSize - Length of the input buffer supplied by the user.
|
||
(Actually only the size of the HardwareState structure, not the
|
||
buffer it points to from which the state is actually restored. The
|
||
pointed-to buffer is assumed to be big enough.)
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - restore performed successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough to provide data
|
||
|
||
--*/
|
||
|
||
{
|
||
PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
|
||
ULONG i;
|
||
UCHAR dummy;
|
||
PUCHAR pScreen;
|
||
PUCHAR pucLatch;
|
||
PULONG pulBuffer;
|
||
PUCHAR port;
|
||
PUCHAR portValue;
|
||
PUCHAR portValueDAC;
|
||
ULONG bIsColor;
|
||
|
||
|
||
//
|
||
// Check if the size of the data in the input buffer is large enough.
|
||
//
|
||
|
||
if ((HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE)) ||
|
||
(HardwareState->StateLength < VGA_TOTAL_STATE_SIZE)) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Point to the buffer where the restore data is actually stored.
|
||
//
|
||
|
||
hardwareStateHeader = HardwareState->StateHeader;
|
||
|
||
//
|
||
// Make sure the offset are in the structure ...
|
||
//
|
||
|
||
if ((hardwareStateHeader->BasicSequencerOffset + VGA_NUM_SEQUENCER_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->BasicCrtContOffset + VGA_NUM_CRTC_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->BasicGraphContOffset + VGA_NUM_GRAPH_CONT_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->BasicAttribContOffset + VGA_NUM_ATTRIB_CONT_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->BasicDacOffset + (3 * VGA_NUM_DAC_ENTRIES) >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->BasicLatchesOffset + 4 >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->ExtendedSequencerOffset + EXT_NUM_SEQUENCER_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->ExtendedCrtContOffset + EXT_NUM_CRTC_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->ExtendedGraphContOffset + EXT_NUM_GRAPH_CONT_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->ExtendedAttribContOffset + EXT_NUM_ATTRIB_CONT_PORTS >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->ExtendedDacOffset + (4 * EXT_NUM_DAC_ENTRIES) >
|
||
HardwareState->StateLength) ||
|
||
|
||
//
|
||
// Only check the validator state offset if there is unemulated data.
|
||
//
|
||
|
||
((hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) &&
|
||
(hardwareStateHeader->ExtendedValidatorStateOffset + VGA_VALIDATOR_AREA_SIZE >
|
||
HardwareState->StateLength)) ||
|
||
|
||
(hardwareStateHeader->ExtendedMiscDataOffset + VGA_MISC_DATA_AREA_OFFSET >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->Plane1Offset + hardwareStateHeader->PlaneLength >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->Plane2Offset + hardwareStateHeader->PlaneLength >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->Plane3Offset + hardwareStateHeader->PlaneLength >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->Plane4Offset + hardwareStateHeader->PlaneLength >
|
||
HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->DIBOffset +
|
||
hardwareStateHeader->DIBBitsPerPixel / 8 *
|
||
hardwareStateHeader->DIBXResolution *
|
||
hardwareStateHeader->DIBYResolution > HardwareState->StateLength) ||
|
||
|
||
(hardwareStateHeader->DIBXlatOffset + hardwareStateHeader->DIBXlatLength >
|
||
HardwareState->StateLength)) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Set DAC register 0 to display black.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
|
||
//
|
||
// Set the DAC mask register to force DAC register 0 to display all the
|
||
// time (this is the register we just set to display black). From now on,
|
||
// nothing but black will show up on the screen.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_PIXEL_MASK_PORT, 0);
|
||
|
||
|
||
//
|
||
// Restore the latches and the contents of display memory.
|
||
//
|
||
// Set up the VGA's hardware to allow us to copy to each plane in turn.
|
||
//
|
||
// Begin sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Turn off Chain mode and map display memory at A0000 for 64K.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR) ((VideoPortReadPortUchar(
|
||
HwDeviceExtension->IOAddress + GRAPH_DATA_PORT) & 0xF1) | 0x04));
|
||
|
||
//
|
||
// Turn off Chain4 mode and odd/even.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT,
|
||
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT) & 0xF3) | 0x04));
|
||
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Set the write mode to 0, the read mode to 0, and turn off odd/even.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT,
|
||
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) & 0xE4) | 0x00));
|
||
|
||
//
|
||
// Set the Bit Mask to 0xFF to allow all CPU bits through.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), (USHORT) (IND_BIT_MASK + (0xFF << 8)));
|
||
|
||
//
|
||
// Set the Data Rotation and Logical Function fields to 0 to allow CPU
|
||
// data through unmodified.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), (USHORT) (IND_DATA_ROTATE + (0 << 8)));
|
||
|
||
//
|
||
// Set Set/Reset Enable to 0 to select CPU data for all planes.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), (USHORT) (IND_SET_RESET_ENABLE + (0 << 8)));
|
||
|
||
//
|
||
// Point the Sequencer Index to the Map Mask register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, IND_MAP_MASK);
|
||
|
||
//
|
||
// Restore the latches.
|
||
//
|
||
// Point to the saved data for the first latch.
|
||
//
|
||
|
||
pucLatch = ((PUCHAR) (hardwareStateHeader)) +
|
||
hardwareStateHeader->BasicLatchesOffset;
|
||
|
||
//
|
||
// Point to first byte of display memory.
|
||
//
|
||
|
||
pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress;
|
||
|
||
//
|
||
// Write the contents to be restored to each of the four latches in turn.
|
||
//
|
||
|
||
for (i = 0; i < 4; i++) {
|
||
|
||
//
|
||
// Set the Map Mask to select the plane we want to restore next.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, (UCHAR)(1<<i));
|
||
|
||
//
|
||
// Write this plane's latch.
|
||
//
|
||
|
||
VideoPortWriteRegisterUchar(pScreen, *pucLatch++);
|
||
|
||
}
|
||
|
||
//
|
||
// Read the latched data into the latches, and the latches are set.
|
||
//
|
||
|
||
dummy = VideoPortReadRegisterUchar(pScreen);
|
||
|
||
|
||
//
|
||
// Point to the offset of the saved data for the first plane.
|
||
//
|
||
|
||
pulBuffer = &(hardwareStateHeader->Plane1Offset);
|
||
|
||
//
|
||
// Restore each of the four planes in turn.
|
||
//
|
||
|
||
for (i = 0; i < 4; i++) {
|
||
|
||
//
|
||
// Set the Map Mask to select the plane we want to restore next.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT, (UCHAR)(1<<i));
|
||
|
||
//
|
||
// Restore this plane from the buffer.
|
||
//
|
||
|
||
VideoPortMoveMemory((PUCHAR) HwDeviceExtension->VideoMemoryAddress,
|
||
((PUCHAR) (hardwareStateHeader)) + *pulBuffer,
|
||
hardwareStateHeader->PlaneLength);
|
||
|
||
pulBuffer++;
|
||
|
||
}
|
||
|
||
//
|
||
// If we have some unemulated data, put it back into the buffer
|
||
//
|
||
|
||
if (hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) {
|
||
|
||
if (!hardwareStateHeader->ExtendedValidatorStateOffset) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
//
|
||
// Get the right offset in the struct and save all the data associated
|
||
// with the trapped validator data.
|
||
//
|
||
|
||
VideoPortMoveMemory(&(HwDeviceExtension->TrappedValidatorCount),
|
||
((PUCHAR) (hardwareStateHeader)) +
|
||
hardwareStateHeader->ExtendedValidatorStateOffset,
|
||
VGA_VALIDATOR_AREA_SIZE);
|
||
|
||
//
|
||
// Check to see if this is an appropriate access range.
|
||
// We are trapping - so we must have the trapping access range enabled.
|
||
//
|
||
|
||
if (((HwDeviceExtension->CurrentVdmAccessRange != FullVgaValidatorAccessRange) ||
|
||
(HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE)) &&
|
||
((HwDeviceExtension->CurrentVdmAccessRange != MinimalVgaValidatorAccessRange) ||
|
||
(HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE))) {
|
||
|
||
return ERROR_INVALID_PARAMETER;
|
||
|
||
}
|
||
|
||
VideoPortSetTrappedEmulatorPorts(HwDeviceExtension,
|
||
HwDeviceExtension->CurrentNumVdmAccessRanges,
|
||
HwDeviceExtension->CurrentVdmAccessRange);
|
||
|
||
}
|
||
|
||
//
|
||
// Set the critical registers (clock and timing states) during sync reset.
|
||
//
|
||
// Begin sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
||
(START_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Restore the Miscellaneous Output register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
MISC_OUTPUT_REG_WRITE_PORT,
|
||
(UCHAR) (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] & 0xF7));
|
||
|
||
//
|
||
// Restore all Sequencer registers except the Sync Reset register, which
|
||
// is always not in reset (except when we send out a batched sync reset
|
||
// register set, but that can't be interrupted, so we know we're never in
|
||
// sync reset at save/restore time).
|
||
//
|
||
|
||
portValue = ((PUCHAR) hardwareStateHeader) +
|
||
hardwareStateHeader->BasicSequencerOffset + 1;
|
||
|
||
for (i = 1; i < VGA_NUM_SEQUENCER_PORTS; i++) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)) );
|
||
|
||
}
|
||
|
||
//
|
||
// Restore extended sequencer registers
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
if (hardwareStateHeader->ExtendedSequencerOffset) {
|
||
|
||
portValue = ((PUCHAR) hardwareStateHeader) +
|
||
hardwareStateHeader->ExtendedSequencerOffset;
|
||
|
||
for (i = WD_SEQUENCER_EXT_START; i <= WD_SEQUENCER_EXT_END; i++) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (i + ((*portValue++) << 8)) );
|
||
|
||
}
|
||
|
||
//
|
||
// Restore the second set of sequencer registers.
|
||
//
|
||
|
||
for (i = WD_SEQUENCER_1_EXT_START; i <= WD_SEQUENCER_1_EXT_END; i++) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (i + ((*portValue++) << 8)) );
|
||
|
||
}
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// Restore the Graphics Controller Miscellaneous register, which contains
|
||
// the Chain bit.
|
||
//
|
||
|
||
portValue = ((PUCHAR) hardwareStateHeader) +
|
||
hardwareStateHeader->BasicGraphContOffset + IND_GRAPH_MISC;
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), (USHORT)(IND_GRAPH_MISC + (*portValue << 8)));
|
||
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Figure out if color/mono switchable registers are at 3BX or 3DX.
|
||
// At the same time, save the state of the Miscellaneous Output register
|
||
// which is read from 3CC but written at 3C2.
|
||
//
|
||
|
||
if (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] & 0x01) {
|
||
bIsColor = TRUE;
|
||
} else {
|
||
bIsColor = FALSE;
|
||
}
|
||
|
||
|
||
//
|
||
// Restore the CRT Controller indexed registers.
|
||
//
|
||
// Unlock CRTC registers 0-7.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicCrtContOffset;
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR), (USHORT) (IND_CRTC_PROTECT +
|
||
(((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO), (USHORT) (IND_CRTC_PROTECT +
|
||
(((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
|
||
|
||
}
|
||
|
||
|
||
|
||
//
|
||
// Restore extended crtc registers.
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
if (hardwareStateHeader->ExtendedCrtContOffset) {
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->ExtendedCrtContOffset;
|
||
|
||
for (i = WD_CRTC_EXT_START; i <= WD_CRTC_EXT_END; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
}
|
||
}
|
||
|
||
//
|
||
// Second set of crtc registers
|
||
//
|
||
|
||
for (i = WD_CRTC_1_EXT_START; i <= WD_CRTC_1_EXT_END; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// Now restore the CRTC registers.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicCrtContOffset;
|
||
|
||
for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore the Graphics Controller indexed registers.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicGraphContOffset;
|
||
|
||
for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore extended graphics controller registers.
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
//
|
||
// The extended lock register (index 0x0F) will be restored last, so we do
|
||
// not need to do anything special with it.
|
||
//
|
||
|
||
if (hardwareStateHeader->ExtendedGraphContOffset) {
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->ExtendedGraphContOffset;
|
||
|
||
for (i = WD_GRAPH_EXT_START; i <= WD_GRAPH_EXT_END; i++) {
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT),
|
||
(USHORT) (i + ((*portValue++) << 8)));
|
||
|
||
}
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// Restore the Attribute Controller indexed registers.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicAttribContOffset;
|
||
|
||
//
|
||
// Reset the AC index/data toggle, then blast out all the register
|
||
// settings.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
INPUT_STATUS_1_COLOR);
|
||
} else {
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
INPUT_STATUS_1_MONO);
|
||
}
|
||
|
||
for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT, (UCHAR)i);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_DATA_WRITE_PORT, *portValue++);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore DAC registers 1 through 255. We'll do register 0, the DAC Mask,
|
||
// and the index registers later.
|
||
// Set the DAC address port Index, then write out the DAC Data registers.
|
||
// Each three reads get Red, Green, and Blue components for that register.
|
||
//
|
||
// Write them one at a time due to problems on local bus machines.
|
||
//
|
||
|
||
portValueDAC = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicDacOffset + 3;
|
||
|
||
for (i = 1; i < VGA_NUM_DAC_ENTRIES; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT, (UCHAR)i);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
|
||
}
|
||
|
||
//
|
||
// Extended registers are not CURRENTLY supported in this driver.
|
||
//
|
||
|
||
|
||
//
|
||
// Restore the Feature Control register.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
FEAT_CTRL_WRITE_PORT_COLOR,
|
||
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR]);
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
FEAT_CTRL_WRITE_PORT_MONO,
|
||
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO]);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore the Sequencer Index.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT,
|
||
hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT]);
|
||
|
||
//
|
||
// Restore the CRT Controller Index.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR,
|
||
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR]);
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO,
|
||
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO]);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore the Graphics Controller Index.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT,
|
||
hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT]);
|
||
|
||
|
||
//
|
||
// Restore the Attribute Controller Index and index/data toggle state.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
|
||
} else {
|
||
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
|
||
}
|
||
|
||
VideoPortReadPortUchar(port); // reset the toggle to Index state
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT, // restore the AC Index
|
||
hardwareStateHeader->PortValue[ATT_ADDRESS_PORT]);
|
||
|
||
//
|
||
// If the toggle should be in Data state, we're all set. If it should be in
|
||
// Index state, reset it to that condition.
|
||
//
|
||
|
||
if (hardwareStateHeader->AttribIndexDataState == 0) {
|
||
|
||
//
|
||
// Reset the toggle to Index state.
|
||
//
|
||
|
||
VideoPortReadPortUchar(port);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Restore DAC register 0 and the DAC Mask, to unblank the screen.
|
||
//
|
||
|
||
portValueDAC = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicDacOffset;
|
||
|
||
//
|
||
// Restore the DAC Mask register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_PIXEL_MASK_PORT,
|
||
hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT]);
|
||
|
||
//
|
||
// Restore DAC register 0.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
|
||
|
||
//
|
||
// Restore the read/write state and the current index of the DAC.
|
||
//
|
||
// See whether the Read or Write Index was written to most recently.
|
||
// (The upper nibble stored at DAC_STATE_PORT is the # of reads/writes
|
||
// for the current index.)
|
||
//
|
||
|
||
if ((hardwareStateHeader->PortValue[DAC_STATE_PORT] & 0x0F) == 3) {
|
||
|
||
//
|
||
// The DAC Read Index was written to last. Restore the DAC by setting
|
||
// up to read from the saved index - 1, because the way the Read
|
||
// Index works is that it autoincrements after reading, so you actually
|
||
// end up reading the data for the index you read at the DAC Write
|
||
// Mask register - 1.
|
||
//
|
||
// Set the Read Index to the index we read, minus 1, accounting for
|
||
// wrap from 255 back to 0. The DAC hardware immediately reads this
|
||
// register into a temporary buffer, then adds 1 to the index.
|
||
//
|
||
|
||
if (hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] == 0) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_READ_PORT, 255);
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_READ_PORT, (UCHAR)
|
||
(hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] -
|
||
1));
|
||
|
||
}
|
||
|
||
//
|
||
// Now read the hardware however many times are required to get to
|
||
// the partial read state we saved.
|
||
//
|
||
|
||
for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT] >> 4;
|
||
i > 0; i--) {
|
||
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
//
|
||
// The DAC Write Index was written to last. Set the Write Index to the
|
||
// index value we read out of the DAC. Then, if a partial write
|
||
// (partway through an RGB triplet) was in place, write the partial
|
||
// values, which we obtained by writing them to the current DAC
|
||
// register. This DAC register will be wrong until the write is
|
||
// completed, but at least the values will be right once the write is
|
||
// finished, and most importantly we won't have messed up the sequence
|
||
// of RGB writes (which can be as long as 768 in a row).
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT,
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]);
|
||
|
||
//
|
||
// Now write to the hardware however many times are required to get to
|
||
// the partial write state we saved (if any).
|
||
//
|
||
// Point to the saved value for the DAC register that was in the
|
||
// process of being written to; we wrote the partial value out, so now
|
||
// we can restore it.
|
||
//
|
||
|
||
portValueDAC = (PUCHAR) hardwareStateHeader +
|
||
hardwareStateHeader->BasicDacOffset +
|
||
(hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] * 3);
|
||
|
||
for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT] >> 4;
|
||
i > 0; i--) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, *portValueDAC++);
|
||
|
||
}
|
||
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaRestoreHardwareState()
|
||
|
||
VP_STATUS
|
||
VgaSaveHardwareState(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_HARDWARE_STATE HardwareState,
|
||
ULONG HardwareStateSize,
|
||
PULONG OutputSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Saves all registers and memory of the VGA.
|
||
|
||
Note: HardwareState points to the actual buffer in which the state
|
||
is saved. This buffer will always be big enough (we specified
|
||
the required size at DriverEntry).
|
||
|
||
Note: This routine leaves registers in any state it cares to, except
|
||
that it will not mess with any of the CRT or Sequencer parameters that
|
||
might make the monitor unhappy. It leaves the screen blanked by setting
|
||
the DAC Mask and DAC register 0 to all zero values. The next video
|
||
operation we expect after this is a mode set to take us back to Win32.
|
||
|
||
Note: The offset in the hardware state header in which each general
|
||
register is saved is the offset of the write address of that register from
|
||
the base I/O address of the VGA.
|
||
|
||
!!! NOTE
|
||
We must force the extended registers to be unlocked.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
HardwareState - Pointer to a structure in which the saved state will be
|
||
returned (actually only info about and a pointer to the actual save
|
||
buffer).
|
||
|
||
HardwareStateSize - Length of the output buffer supplied by the user.
|
||
(Actually only the size of the HardwareState structure, not the
|
||
buffer it points to where the state is actually saved. The pointed-
|
||
to buffer is assumed to be big enough.)
|
||
|
||
OutputSize - Pointer to a buffer in which to return the actual size of
|
||
the data returned in the buffer.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
||
any useful data
|
||
|
||
--*/
|
||
|
||
{
|
||
PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
|
||
PUCHAR pScreen;
|
||
PUCHAR portValue;
|
||
PUCHAR portValueDAC;
|
||
PUCHAR bufferPointer;
|
||
ULONG i;
|
||
UCHAR dummy, originalACIndex, originalACData;
|
||
UCHAR ucCRTC03;
|
||
ULONG bIsColor;
|
||
|
||
|
||
//
|
||
// See if the buffer is big enough to hold the hardware state structure.
|
||
// (This is only the HardwareState structure itself, not the buffer it
|
||
// points to.)
|
||
//
|
||
|
||
if (HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE) ) {
|
||
|
||
*OutputSize = 0; // nothing returned
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Amount of data we're going to return in the output buffer.
|
||
// (The VIDEO_HARDWARE_STATE in the output buffer points to the actual
|
||
// buffer in which the state is stored, which is assumed to be large
|
||
// enough.)
|
||
//
|
||
|
||
*OutputSize = sizeof(VIDEO_HARDWARE_STATE);
|
||
|
||
//
|
||
// Indicate the size of the full state save info.
|
||
//
|
||
|
||
HardwareState->StateLength = VGA_TOTAL_STATE_SIZE;
|
||
|
||
//
|
||
// hardwareStateHeader is a structure of offsets at the start of the
|
||
// actual save area that indicates the locations in which various VGA
|
||
// register and memory components are saved.
|
||
//
|
||
|
||
hardwareStateHeader = HardwareState->StateHeader;
|
||
|
||
//
|
||
// Zero out the structure.
|
||
//
|
||
|
||
VideoPortZeroMemory(hardwareStateHeader, sizeof(VIDEO_HARDWARE_STATE_HEADER));
|
||
|
||
//
|
||
// Set the Length field, which is basically a version ID.
|
||
//
|
||
|
||
hardwareStateHeader->Length = sizeof(VIDEO_HARDWARE_STATE_HEADER);
|
||
|
||
//
|
||
// Set the basic register offsets properly.
|
||
//
|
||
|
||
hardwareStateHeader->BasicSequencerOffset = VGA_BASIC_SEQUENCER_OFFSET;
|
||
hardwareStateHeader->BasicCrtContOffset = VGA_BASIC_CRTC_OFFSET;
|
||
hardwareStateHeader->BasicGraphContOffset = VGA_BASIC_GRAPH_CONT_OFFSET;
|
||
hardwareStateHeader->BasicAttribContOffset = VGA_BASIC_ATTRIB_CONT_OFFSET;
|
||
hardwareStateHeader->BasicDacOffset = VGA_BASIC_DAC_OFFSET;
|
||
hardwareStateHeader->BasicLatchesOffset = VGA_BASIC_LATCHES_OFFSET;
|
||
|
||
//
|
||
// Set the entended register offsets properly.
|
||
//
|
||
|
||
hardwareStateHeader->ExtendedSequencerOffset = VGA_EXT_SEQUENCER_OFFSET;
|
||
hardwareStateHeader->ExtendedCrtContOffset = VGA_EXT_CRTC_OFFSET;
|
||
hardwareStateHeader->ExtendedGraphContOffset = VGA_EXT_GRAPH_CONT_OFFSET;
|
||
hardwareStateHeader->ExtendedAttribContOffset = VGA_EXT_ATTRIB_CONT_OFFSET;
|
||
hardwareStateHeader->ExtendedDacOffset = VGA_EXT_DAC_OFFSET;
|
||
|
||
//
|
||
// Figure out if color/mono switchable registers are at 3BX or 3DX.
|
||
// At the same time, save the state of the Miscellaneous Output register
|
||
// which is read from 3CC but written at 3C2.
|
||
//
|
||
|
||
if ((hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
MISC_OUTPUT_REG_READ_PORT))
|
||
& 0x01) {
|
||
bIsColor = TRUE;
|
||
} else {
|
||
bIsColor = FALSE;
|
||
}
|
||
|
||
//
|
||
// Force the video subsystem enable state to enabled.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
VIDEO_SUBSYSTEM_ENABLE_PORT, 1);
|
||
|
||
//
|
||
// Save the DAC state first, so we can set the DAC to blank the screen
|
||
// so nothing after this shows up at all.
|
||
//
|
||
// Save the DAC Mask register.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_PIXEL_MASK_PORT);
|
||
|
||
//
|
||
// Save the DAC Index register. Note that there is actually only one DAC
|
||
// Index register, which functions as either the Read Index or the Write
|
||
// Index as needed.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT);
|
||
|
||
//
|
||
// Save the DAC read/write state. We determine if the DAC has been written
|
||
// to or read from at the current index 0, 1, or 2 times (the application
|
||
// is in the middle of reading or writing a DAC register triplet if the
|
||
// count is 1 or 2), and save enough info so we can restore things
|
||
// properly. The only hole is if the application writes to the Write Index,
|
||
// then reads from instead of writes to the Data register, or vice-versa,
|
||
// or if they do a partial read write, then never finish it.
|
||
// This is fairly ridiculous behavior, however, and anyway there's nothing
|
||
// we can do about it.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_STATE_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_STATE_PORT);
|
||
|
||
if (hardwareStateHeader->PortValue[DAC_STATE_PORT] == 3) {
|
||
|
||
//
|
||
// The DAC Read Index was written to last. Figure out how many reads
|
||
// have been done from the current index. We'll restart this on restore
|
||
// by setting the Read Index to the current index - 1 (the read index
|
||
// is one greater than the index being read), then doing the proper
|
||
// number of reads.
|
||
//
|
||
// Read the Data register once, and see if the index changes.
|
||
//
|
||
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT) !=
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
||
|
||
//
|
||
// The DAC Index changed, so two reads had already been done from
|
||
// the current index. Store the count "2" in the upper nibble of
|
||
// the read/write state field.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x20;
|
||
|
||
} else {
|
||
|
||
//
|
||
// Read the Data register again, and see if the index changes.
|
||
//
|
||
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT) !=
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
||
|
||
//
|
||
// The DAC Index changed, so one read had already been done
|
||
// from the current index. Store the count "1" in the upper
|
||
// nibble of the read/write state field.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x10;
|
||
}
|
||
|
||
//
|
||
// If neither 2 nor 1 reads had been done from the current index,
|
||
// then 0 reads were done, and we're all set, since the upper
|
||
// nibble of the read/write state field is already 0.
|
||
//
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
//
|
||
// The DAC Write Index was written to last. Figure out how many writes
|
||
// have been done to the current index. We'll restart this on restore
|
||
// by setting the Write Index to the proper index, then doing the
|
||
// proper number of writes. When we do the DAC register save, we'll
|
||
// read out the value that gets written (if there was a partial write
|
||
// in progress), so we can restore the proper data later. This will
|
||
// cause this current DAC location to be briefly wrong in the 1- and
|
||
// 2-bytes-written case (until the app finishes the write), but that's
|
||
// better than having the wrong DAC values written for good.
|
||
//
|
||
// Write the Data register once, and see if the index changes.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT) !=
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
||
|
||
//
|
||
// The DAC Index changed, so two writes had already been done to
|
||
// the current index. Store the count "2" in the upper nibble of
|
||
// the read/write state field.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x20;
|
||
|
||
} else {
|
||
|
||
//
|
||
// Write the Data register again, and see if the index changes.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT) !=
|
||
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
||
|
||
//
|
||
// The DAC Index changed, so one write had already been done
|
||
// to the current index. Store the count "1" in the upper
|
||
// nibble of the read/write state field.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x10;
|
||
}
|
||
|
||
//
|
||
// If neither 2 nor 1 writes had been done to the current index,
|
||
// then 0 writes were done, and we're all set.
|
||
//
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Now, read out the 256 18-bit DAC palette registers (256 RGB triplets),
|
||
// and blank the screen.
|
||
//
|
||
|
||
portValueDAC = (PUCHAR) hardwareStateHeader + VGA_BASIC_DAC_OFFSET;
|
||
|
||
//
|
||
// Read out DAC register 0, so we can set it to black.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_READ_PORT, 0);
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
//
|
||
// Set DAC register 0 to display black.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_WRITE_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT, 0);
|
||
|
||
//
|
||
// Set the DAC mask register to force DAC register 0 to display all the
|
||
// time (this is the register we just set to display black). From now on,
|
||
// nothing but black will show up on the screen.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_PIXEL_MASK_PORT, 0);
|
||
|
||
//
|
||
// Wait until we've gotten the Attribute Controller toggle state to save
|
||
// the rest of the DAC registers, so we can wait for vertical sync.
|
||
//
|
||
|
||
|
||
//
|
||
// Read out the Attribute Controller Index state, and deduce the Index/Data
|
||
// toggle state at the same time.
|
||
//
|
||
// Save the state of the Attribute Controller, both Index and Data,
|
||
// so we can test in which state the toggle currently is.
|
||
//
|
||
|
||
originalACIndex = hardwareStateHeader->PortValue[ATT_ADDRESS_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT);
|
||
originalACData = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_DATA_READ_PORT);
|
||
|
||
//
|
||
// Sequencer Index.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
|
||
//
|
||
// Begin sync reset, just in case this is an SVGA and the currently
|
||
// indexed Attribute Controller register controls clocking stuff (a
|
||
// normal VGA won't require this).
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Now, write a different Index setting to the Attribute Controller, and
|
||
// see if the Index changes.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT, (UCHAR) (originalACIndex ^ 0x10));
|
||
|
||
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT) == originalACIndex) {
|
||
|
||
//
|
||
// The Index didn't change, so the toggle was in the Data state.
|
||
//
|
||
|
||
hardwareStateHeader->AttribIndexDataState = 1;
|
||
|
||
//
|
||
// Restore the original Data state; we just corrupted it, and we need
|
||
// to read it out later; also, it may glitch the screen if not
|
||
// corrected. The toggle is already in the Index state.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT, originalACIndex);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_DATA_WRITE_PORT, originalACData);
|
||
|
||
} else {
|
||
|
||
//
|
||
// The Index did change, so the toggle was in the Index state.
|
||
// No need to restore anything, because the Data register didn't
|
||
// change, and we've already read out the Index register.
|
||
//
|
||
|
||
hardwareStateHeader->AttribIndexDataState = 0;
|
||
|
||
}
|
||
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
||
|
||
|
||
|
||
//
|
||
// Save the rest of the DAC registers.
|
||
// Set the DAC address port Index, then read out the DAC Data registers.
|
||
// Each three reads get Red, Green, and Blue components for that register.
|
||
//
|
||
// Read them one at a time due to problems on local bus machines.
|
||
//
|
||
|
||
for (i = 1; i < VGA_NUM_DAC_ENTRIES; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_ADDRESS_READ_PORT, (UCHAR)i);
|
||
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
DAC_DATA_REG_PORT);
|
||
|
||
}
|
||
|
||
//
|
||
// The Feature Control register is read from 3CA but written at 3BA/3DA.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
|
||
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
FEAT_CTRL_READ_PORT);
|
||
|
||
} else {
|
||
|
||
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
FEAT_CTRL_READ_PORT);
|
||
|
||
}
|
||
|
||
|
||
|
||
//
|
||
// CRT Controller Index.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
|
||
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR);
|
||
|
||
} else {
|
||
|
||
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Graphics Controller Index.
|
||
//
|
||
|
||
hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT] =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT);
|
||
|
||
|
||
//
|
||
// Graphics Controller indexed registers.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_GRAPH_CONT_OFFSET;
|
||
|
||
for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, (UCHAR)i);
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
|
||
}
|
||
|
||
//
|
||
// Save extended graphics controller registers.
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
//
|
||
// Read the lock register (index 0x0F) value and save that.
|
||
//
|
||
|
||
*(((PUCHAR) hardwareStateHeader) + VGA_EXT_GRAPH_CONT_OFFSET +
|
||
(WD_GRAPH_EXT_END - WD_GRAPH_EXT_START)) =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress + 0x0F);
|
||
|
||
//
|
||
// Unlock all extended registers so they can be read or written.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + 0x0F, 0x05);
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_EXT_GRAPH_CONT_OFFSET;
|
||
|
||
for (i = WD_GRAPH_EXT_START; i <= WD_GRAPH_EXT_END -1; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, (UCHAR)i);
|
||
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT);
|
||
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// Sequencer indexed registers.
|
||
//
|
||
|
||
portValue = ((PUCHAR) hardwareStateHeader) + VGA_BASIC_SEQUENCER_OFFSET;
|
||
|
||
for (i = 0; i < VGA_NUM_SEQUENCER_PORTS; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, (UCHAR)i);
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
}
|
||
|
||
|
||
//
|
||
// Save extended sequencer registers.
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
portValue = ((PUCHAR) hardwareStateHeader) + VGA_EXT_SEQUENCER_OFFSET;
|
||
|
||
for (i = WD_SEQUENCER_EXT_START; i <= WD_SEQUENCER_EXT_END; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, (UCHAR)i);
|
||
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
}
|
||
|
||
//
|
||
// Second set of sequencer registers
|
||
//
|
||
|
||
for (i = WD_SEQUENCER_1_EXT_START; i <= WD_SEQUENCER_1_EXT_END; i++) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, (UCHAR)i);
|
||
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT);
|
||
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// CRT Controller indexed registers.
|
||
//
|
||
|
||
//
|
||
// Remember the state of CRTC register 3, then force bit 7
|
||
// to 1 so we will read back the Vertical Retrace start and
|
||
// end registers rather than the light pen info.
|
||
//
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 3);
|
||
ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR, (UCHAR) (ucCRTC03 | 0x80));
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO, 3);
|
||
ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_MONO);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_MONO, (UCHAR) (ucCRTC03 | 0x80));
|
||
}
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
|
||
|
||
for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR);
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_MONO);
|
||
}
|
||
|
||
}
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
|
||
portValue[3] = ucCRTC03;
|
||
|
||
|
||
//
|
||
// Save extended crtc registers.
|
||
//
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_EXT_CRTC_OFFSET;
|
||
|
||
for (i = WD_CRTC_EXT_START; i <= WD_CRTC_EXT_END; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
|
||
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR);
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
|
||
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_MONO);
|
||
}
|
||
}
|
||
|
||
//
|
||
// Save second set of crtc registers.
|
||
//
|
||
|
||
for (i = WD_CRTC_1_EXT_START; i <= WD_CRTC_1_EXT_END; i++) {
|
||
|
||
if (bIsColor) {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
|
||
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR);
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
|
||
|
||
*portValue++ =
|
||
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_MONO);
|
||
}
|
||
}
|
||
|
||
#endif
|
||
|
||
//
|
||
// Attribute Controller indexed registers.
|
||
//
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_ATTRIB_CONT_OFFSET;
|
||
|
||
//
|
||
// For each indexed AC register, reset the flip-flop for reading the
|
||
// attribute register, then write the desired index to the AC Index,
|
||
// then read the value of the indexed register from the AC Data register.
|
||
//
|
||
|
||
for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
|
||
|
||
if (bIsColor) {
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
INPUT_STATUS_1_COLOR);
|
||
} else {
|
||
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
INPUT_STATUS_1_MONO);
|
||
}
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_ADDRESS_PORT, (UCHAR)i);
|
||
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
ATT_DATA_READ_PORT);
|
||
|
||
}
|
||
|
||
//
|
||
// Save the latches. This destroys one byte of display memory in each
|
||
// plane, which is unfortunate but unavoidable. Chips that provide
|
||
// a way to read back the latches can avoid this problem.
|
||
//
|
||
// Set up the VGA's hardware so we can write the latches, then read them
|
||
// back.
|
||
//
|
||
|
||
//
|
||
// Begin sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Set the Miscellaneous register to make sure we can access video RAM.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
MISC_OUTPUT_REG_WRITE_PORT, (UCHAR)(
|
||
hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] |
|
||
0x02));
|
||
|
||
//
|
||
// Turn off Chain mode and map display memory at A0000 for 64K.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT,
|
||
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) & 0xF1) | 0x04));
|
||
|
||
//
|
||
// Turn off Chain4 mode and odd/even.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT,
|
||
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
SEQ_DATA_PORT) & 0xF3) | 0x04));
|
||
|
||
//
|
||
// End sync reset.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
||
|
||
//
|
||
// Set the Map Mask to write to all planes.
|
||
//
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT), (USHORT) (IND_MAP_MASK + (0x0F << 8)));
|
||
|
||
//
|
||
// Set the write mode to 0, the read mode to 0, and turn off odd/even.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT,
|
||
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT) & 0xE4) | 0x01));
|
||
|
||
//
|
||
// Point to the last byte of display memory.
|
||
//
|
||
|
||
pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress +
|
||
VGA_PLANE_SIZE - 1;
|
||
|
||
//
|
||
// Write the latches to the last byte of display memory.
|
||
//
|
||
|
||
VideoPortWriteRegisterUchar(pScreen, 0);
|
||
|
||
//
|
||
// Cycle through the four planes, reading the latch data from each plane.
|
||
//
|
||
|
||
//
|
||
// Point the Graphics Controller Index to the Read Map register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
|
||
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_LATCHES_OFFSET;
|
||
|
||
for (i=0; i<4; i++) {
|
||
|
||
//
|
||
// Set the Read Map for the current plane.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)i);
|
||
|
||
//
|
||
// Read the latched data we've written to memory.
|
||
//
|
||
|
||
*portValue++ = VideoPortReadRegisterUchar(pScreen);
|
||
|
||
}
|
||
|
||
//
|
||
// Set the VDM flags
|
||
// We are a standard VGA, and then check if we have unemulated state.
|
||
//
|
||
|
||
hardwareStateHeader->VGAStateFlags = 0;
|
||
|
||
#ifdef EXTENDED_REGISTER_SAVE_RESTORE
|
||
|
||
hardwareStateHeader->VGAStateFlags |= VIDEO_STATE_NON_STANDARD_VGA;
|
||
|
||
#endif
|
||
|
||
if (HwDeviceExtension->TrappedValidatorCount) {
|
||
|
||
hardwareStateHeader->VGAStateFlags |= VIDEO_STATE_UNEMULATED_VGA_STATE;
|
||
|
||
//
|
||
// Save the VDM Emulator data
|
||
// No need to save the state of the seuencer port register for our
|
||
// emulated data since it may change when we come back. It will be
|
||
// recomputed.
|
||
//
|
||
|
||
hardwareStateHeader->ExtendedValidatorStateOffset = VGA_VALIDATOR_OFFSET;
|
||
|
||
VideoPortMoveMemory(((PUCHAR) (hardwareStateHeader)) +
|
||
hardwareStateHeader->ExtendedValidatorStateOffset,
|
||
&(HwDeviceExtension->TrappedValidatorCount),
|
||
VGA_VALIDATOR_AREA_SIZE);
|
||
|
||
} else {
|
||
|
||
hardwareStateHeader->ExtendedValidatorStateOffset = 0;
|
||
|
||
}
|
||
|
||
//
|
||
// Set the size of each plane.
|
||
//
|
||
|
||
hardwareStateHeader->PlaneLength = VGA_PLANE_SIZE;
|
||
|
||
//
|
||
// Store all the offsets for the planes in the structure.
|
||
//
|
||
|
||
hardwareStateHeader->Plane1Offset = VGA_PLANE_0_OFFSET;
|
||
hardwareStateHeader->Plane2Offset = VGA_PLANE_1_OFFSET;
|
||
hardwareStateHeader->Plane3Offset = VGA_PLANE_2_OFFSET;
|
||
hardwareStateHeader->Plane4Offset = VGA_PLANE_3_OFFSET;
|
||
|
||
//
|
||
// Now copy the contents of video VRAM into the buffer.
|
||
//
|
||
// The VGA hardware is already set up so that video memory is readable;
|
||
// we already turned off Chain mode, mapped in at A0000, turned off Chain4,
|
||
// turned off odd/even, and set read mode 0 when we saved the latches.
|
||
//
|
||
// Point the Graphics Controller Index to the Read Map register.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
||
|
||
//
|
||
// Point to the save area for the first plane.
|
||
//
|
||
|
||
bufferPointer = ((PUCHAR) (hardwareStateHeader)) +
|
||
hardwareStateHeader->Plane1Offset;
|
||
|
||
//
|
||
// Save the four planes consecutively.
|
||
//
|
||
|
||
for (i = 0; i < 4; i++) {
|
||
|
||
//
|
||
// Set the Read Map to select the plane we want to save next.
|
||
//
|
||
|
||
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)i);
|
||
|
||
//
|
||
// Copy this plane into the buffer.
|
||
//
|
||
|
||
VideoPortMoveMemory(bufferPointer,
|
||
(PUCHAR) HwDeviceExtension->VideoMemoryAddress,
|
||
VGA_PLANE_SIZE);
|
||
//
|
||
// Point to the next plane's save area.
|
||
//
|
||
|
||
bufferPointer += VGA_PLANE_SIZE;
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaSaveHardwareState()
|
||
|
||
VP_STATUS
|
||
VgaGetBankSelectCode(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
||
PVIDEO_BANK_SELECT BankSelect,
|
||
ULONG BankSelectSize,
|
||
PULONG OutputSize
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Returns information needed in order for caller to implement bank
|
||
management.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
BankSelect - Pointer to a VIDEO_BANK_SELECT structure in which the bank
|
||
select data will be returned (output buffer).
|
||
|
||
BankSelectSize - Length of the output buffer supplied by the user.
|
||
|
||
OutputSize - Pointer to a variable in which to return the actual size of
|
||
the data returned in the output buffer.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR - information returned successfully
|
||
|
||
ERROR_MORE_DATA - output buffer not large enough to hold all info (but
|
||
Size is returned, so caller can tell how large a buffer to allocate)
|
||
|
||
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
||
any useful data
|
||
|
||
ERROR_INVALID_PARAMETER - invalid video mode selection
|
||
|
||
--*/
|
||
|
||
{
|
||
ULONG codeSize;
|
||
PUCHAR pCodeDest;
|
||
PUCHAR pCodeBank;
|
||
|
||
PVIDEOMODE pMode = HwDeviceExtension->CurrentMode;
|
||
|
||
//
|
||
// check if a mode has been set
|
||
//
|
||
|
||
if (HwDeviceExtension->CurrentMode == NULL) {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
|
||
}
|
||
|
||
//
|
||
// The minimum passed buffer size is a VIDEO_BANK_SELECT
|
||
// structure, so that we can return the required size; we can't do
|
||
// anything if we don't have at least that much buffer.
|
||
//
|
||
|
||
if (BankSelectSize < sizeof(VIDEO_BANK_SELECT)) {
|
||
|
||
return ERROR_INSUFFICIENT_BUFFER;
|
||
|
||
}
|
||
|
||
//
|
||
// Determine the banking type, and set whether any banking is actually
|
||
// supported in this mode.
|
||
//
|
||
|
||
BankSelect->BankingFlags = 0;
|
||
codeSize = 0;
|
||
pCodeBank = NULL;
|
||
|
||
switch(pMode->banktype) {
|
||
|
||
case NoBanking:
|
||
|
||
BankSelect->BankingType = VideoNotBanked;
|
||
BankSelect->Granularity = 0;
|
||
|
||
break;
|
||
|
||
case PlanarHCBanking:
|
||
|
||
VideoDebugPrint((1, "Unsupported planarHC banking\n"));
|
||
|
||
//
|
||
// Fall through to NormalBanking...
|
||
//
|
||
|
||
case NormalBanking:
|
||
|
||
//
|
||
// The WDVGA supports independent 64K read and write banks except
|
||
// for the older ships that only have 1RW
|
||
//
|
||
|
||
if (HwDeviceExtension->BoardID <= WD90C00) {
|
||
|
||
BankSelect->BankingType = VideoBanked1RW;
|
||
|
||
} else {
|
||
|
||
BankSelect->BankingType = VideoBanked1R1W;
|
||
|
||
}
|
||
|
||
BankSelect->Granularity = 0x10000; // 64K bank start adjustment
|
||
|
||
pCodeBank = &BankSwitchStart;
|
||
codeSize = ((ULONG)&BankSwitchEnd) - ((ULONG)&BankSwitchStart);
|
||
|
||
break;
|
||
|
||
}
|
||
|
||
//
|
||
// Size of banking info.
|
||
//
|
||
|
||
BankSelect->Size = sizeof(VIDEO_BANK_SELECT) + codeSize;
|
||
|
||
//
|
||
// This serves an a ID for the version of the structure we're using.
|
||
//
|
||
|
||
BankSelect->Length = sizeof(VIDEO_BANK_SELECT);
|
||
|
||
//
|
||
// If the buffer isn't big enough to hold all info, just return
|
||
// ERROR_MORE_DATA; Size is already set.
|
||
//
|
||
|
||
if (BankSelectSize < BankSelect->Size ) {
|
||
|
||
//
|
||
// We're returning only the VIDEO_BANK_SELECT structure.
|
||
//
|
||
|
||
*OutputSize = sizeof(VIDEO_BANK_SELECT);
|
||
return ERROR_MORE_DATA;
|
||
}
|
||
|
||
//
|
||
// There's room enough for everything, so fill in all fields in
|
||
// VIDEO_BANK_SELECT. (All fields are always returned; the caller can
|
||
// just choose to ignore them, based on BankingFlags and BankingType.)
|
||
//
|
||
|
||
BankSelect->BitmapWidthInBytes = pMode->wbytes;
|
||
BankSelect->BitmapSize = pMode->sbytes;
|
||
|
||
//
|
||
// Copy all banking code into the output buffer.
|
||
//
|
||
|
||
pCodeDest = (PUCHAR)BankSelect + sizeof(VIDEO_BANK_SELECT);
|
||
|
||
if (pCodeBank != NULL) {
|
||
|
||
BankSelect->CodeOffset = pCodeDest - (PUCHAR)BankSelect;
|
||
VideoPortMoveMemory(pCodeDest, pCodeBank, codeSize);
|
||
pCodeDest += codeSize;
|
||
}
|
||
|
||
//
|
||
// Number of bytes we're returning is the full banking info size.
|
||
//
|
||
|
||
*OutputSize = BankSelect->Size;
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaGetBankSelectCode()
|
||
|
||
VP_STATUS
|
||
VgaValidatorUcharEntry(
|
||
ULONG Context,
|
||
ULONG Port,
|
||
UCHAR AccessMode,
|
||
PUCHAR Data
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Entry point into the validator for byte I/O operations.
|
||
|
||
The entry point will be called whenever a byte operation was performed
|
||
by a DOS application on one of the specified Video ports. The kernel
|
||
emulator will forward these requests.
|
||
|
||
Arguments:
|
||
|
||
Context - Context value that is passed to each call made to the validator
|
||
function. This is the value the miniport driver specified in the
|
||
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
||
|
||
Port - Port on which the operation is to be performed.
|
||
|
||
AccessMode - Determines if it is a read or write operation.
|
||
|
||
Data - Pointer to a variable containing the data to be written or a
|
||
variable into which the read data should be stored.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR.
|
||
|
||
--*/
|
||
|
||
{
|
||
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
||
ULONG endEmulation;
|
||
UCHAR temp;
|
||
|
||
Port -= VGA_BASE_IO_PORT;
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount) {
|
||
|
||
//
|
||
// If we are processing a WRITE instruction, then store it in the
|
||
// playback buffer. If the buffer is full, then play it back right
|
||
// away, end sync reset and reinitialize the buffer with a sync
|
||
// reset instruction.
|
||
//
|
||
// If we have a READ, we must flush the buffer (which has the side
|
||
// effect of starting SyncReset), perform the read operation, stop
|
||
// sync reset, and put back a sync reset instruction in the buffer
|
||
// so we can go on appropriately
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
||
// If it is 1 it could select a non-existent clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
*Data &= 0xF7;
|
||
|
||
}
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = Port;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_UCHAR_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = *Data;
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
//
|
||
// Check to see if this instruction was ending sync reset.
|
||
// If it did, we must flush the buffer and reset the trapped
|
||
// IO ports to the minimal set.
|
||
//
|
||
|
||
if ( (Port == SEQ_DATA_PORT) &&
|
||
((*Data & END_SYNC_RESET_VALUE) == END_SYNC_RESET_VALUE) &&
|
||
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
||
|
||
endEmulation = 1;
|
||
|
||
} else {
|
||
|
||
//
|
||
// If we are accessing the seq address port, keep track of the
|
||
// data value
|
||
//
|
||
|
||
if (Port == SEQ_ADDRESS_PORT) {
|
||
|
||
hwDeviceExtension->SequencerAddressValue = *Data;
|
||
|
||
}
|
||
|
||
//
|
||
// If the buffer is not full, then just return right away.
|
||
//
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount <
|
||
VGA_MAX_VALIDATOR_DATA - 1) {
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
endEmulation = 0;
|
||
}
|
||
}
|
||
|
||
//
|
||
// We are either in a READ path or a WRITE path that caused a
|
||
// a full buffer. So flush the buffer either way.
|
||
//
|
||
// To do this put an END_SYNC_RESET at the end since we want to make
|
||
// the buffer is ended sync reset ended.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8));
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
VideoPortSynchronizeExecution(hwDeviceExtension,
|
||
VpHighPriority,
|
||
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
||
VgaPlaybackValidatorData,
|
||
hwDeviceExtension);
|
||
|
||
//
|
||
// Write back the real value of the sequencer address port.
|
||
//
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT,
|
||
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
||
|
||
//
|
||
// If we are in a READ path, read the data
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_READ_ACCESS) {
|
||
|
||
*Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
|
||
|
||
endEmulation = 0;
|
||
|
||
}
|
||
|
||
//
|
||
// If we are ending emulation, reset trapping to the minimal amount
|
||
// and exit.
|
||
//
|
||
|
||
if (endEmulation) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
MinimalVgaValidatorAccessRange);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
//
|
||
// For both cases, put back a START_SYNC_RESET in the buffer.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data =
|
||
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
||
|
||
} else {
|
||
|
||
//
|
||
// Nothing trapped.
|
||
// Lets check is the IO is trying to do something that would require
|
||
// us to stop trapping
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
||
// If it is 1 it could select a non-existant clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(START_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + Port,
|
||
(UCHAR) (*Data & 0xF7) );
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT,
|
||
temp);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
//
|
||
// If we get an access to the sequencer register, start trapping.
|
||
//
|
||
|
||
if ( (Port == SEQ_DATA_PORT) &&
|
||
((*Data & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
||
(VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT) == IND_SYNC_RESET)) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
FullVgaValidatorAccessRange);
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_UCHAR_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
||
|
||
//
|
||
// Start keeping track of the state of the sequencer port.
|
||
//
|
||
|
||
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + Port,
|
||
*Data);
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
*Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
|
||
|
||
}
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaValidatorUcharEntry()
|
||
|
||
VP_STATUS
|
||
VgaValidatorUshortEntry(
|
||
ULONG Context,
|
||
ULONG Port,
|
||
UCHAR AccessMode,
|
||
PUSHORT Data
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Entry point into the validator for word I/O operations.
|
||
|
||
The entry point will be called whenever a byte operation was performed
|
||
by a DOS application on one of the specified Video ports. The kernel
|
||
emulator will forward these requests.
|
||
|
||
Arguments:
|
||
|
||
Context - Context value that is passed to each call made to the validator
|
||
function. This is the value the miniport driver specified in the
|
||
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
||
|
||
Port - Port on which the operation is to be performed.
|
||
|
||
AccessMode - Determines if it is a read or write operation.
|
||
|
||
Data - Pointer to a variable containing the data to be written or a
|
||
variable into which the read data should be stored.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR.
|
||
|
||
--*/
|
||
|
||
{
|
||
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
||
ULONG endEmulation;
|
||
UCHAR temp;
|
||
|
||
Port -= VGA_BASE_IO_PORT;
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount) {
|
||
|
||
//
|
||
// If we are processing a WRITE instruction, then store it in the
|
||
// playback buffer. If the buffer is full, then play it back right
|
||
// away, end sync reset and reinitialize the buffer with a sync
|
||
// reset instruction.
|
||
//
|
||
// If we have a READ, we must flush the buffer (which has the side
|
||
// effect of starting SyncReset), perform the read operation, stop
|
||
// sync reset, and put back a sync reset instruction in the buffer
|
||
// so we can go on appropriately
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
||
// If it is 1 it could select a non-existent clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
*Data &= 0xFFF7;
|
||
|
||
}
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = Port;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = *Data;
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
//
|
||
// Check to see if this instruction was ending sync reset.
|
||
// If it did, we must flush the buffer and reset the trapped
|
||
// IO ports to the minimal set.
|
||
//
|
||
|
||
if (Port == SEQ_ADDRESS_PORT) {
|
||
|
||
//
|
||
// If we are accessing the seq address port, keep track of its
|
||
// value
|
||
//
|
||
|
||
hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
|
||
|
||
}
|
||
|
||
if ((Port == SEQ_ADDRESS_PORT) &&
|
||
( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
|
||
END_SYNC_RESET_VALUE) &&
|
||
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
||
|
||
endEmulation = 1;
|
||
|
||
} else {
|
||
|
||
//
|
||
// If the buffer is not full, then just return right away.
|
||
//
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount <
|
||
VGA_MAX_VALIDATOR_DATA - 1) {
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
endEmulation = 0;
|
||
}
|
||
}
|
||
|
||
//
|
||
// We are either in a READ path or a WRITE path that caused a
|
||
// a full buffer. So flush the buffer either way.
|
||
//
|
||
// To do this put an END_SYNC_RESET at the end since we want to make
|
||
// the buffer is ended sync reset ended.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8));
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
VideoPortSynchronizeExecution(hwDeviceExtension,
|
||
VpHighPriority,
|
||
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
||
VgaPlaybackValidatorData,
|
||
hwDeviceExtension);
|
||
|
||
//
|
||
// Write back the real value of the sequencer address port.
|
||
//
|
||
|
||
VideoPortWritePortUchar((PUCHAR) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
||
|
||
//
|
||
// If we are in a READ path, read the data
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_READ_ACCESS) {
|
||
|
||
*Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress
|
||
+ Port));
|
||
|
||
endEmulation = 0;
|
||
|
||
}
|
||
|
||
//
|
||
// If we are ending emulation, reset trapping to the minimal amount
|
||
// and exit.
|
||
//
|
||
|
||
if (endEmulation) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
MinimalVgaValidatorAccessRange);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
//
|
||
// For both cases, put back a START_SYNC_RESET in the buffer.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data =
|
||
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
||
|
||
} else {
|
||
|
||
//
|
||
// Nothing trapped.
|
||
// Lets check is the IO is trying to do something that would require
|
||
// us to stop trapping
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
||
// If it is 1 it could select a non-existant clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(START_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
(ULONG)Port),
|
||
(USHORT) (*Data & 0xFFF7) );
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
||
temp);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
if ( (Port == SEQ_ADDRESS_PORT) &&
|
||
(((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
||
((*Data & 0xFF) == IND_SYNC_RESET)) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
FullVgaValidatorAccessRange);
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
||
|
||
//
|
||
// Start keeping track of the state of the sequencer port.
|
||
//
|
||
|
||
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
|
||
Port),
|
||
*Data);
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
*Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
|
||
Port));
|
||
|
||
}
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaValidatorUshortEntry()
|
||
|
||
VP_STATUS
|
||
VgaValidatorUlongEntry(
|
||
ULONG Context,
|
||
ULONG Port,
|
||
UCHAR AccessMode,
|
||
PULONG Data
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Entry point into the validator for dword I/O operations.
|
||
|
||
The entry point will be called whenever a byte operation was performed
|
||
by a DOS application on one of the specified Video ports. The kernel
|
||
emulator will forward these requests.
|
||
|
||
Arguments:
|
||
|
||
Context - Context value that is passed to each call made to the validator
|
||
function. This is the value the miniport driver specified in the
|
||
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
||
|
||
Port - Port on which the operation is to be performed.
|
||
|
||
AccessMode - Determines if it is a read or write operation.
|
||
|
||
Data - Pointer to a variable containing the data to be written or a
|
||
variable into which the read data should be stored.
|
||
|
||
Return Value:
|
||
|
||
NO_ERROR.
|
||
|
||
--*/
|
||
|
||
{
|
||
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
||
ULONG endEmulation;
|
||
UCHAR temp;
|
||
|
||
Port -= VGA_BASE_IO_PORT;
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount) {
|
||
|
||
//
|
||
// If we are processing a WRITE instruction, then store it in the
|
||
// playback buffer. If the buffer is full, then play it back right
|
||
// away, end sync reset and reinitialize the buffer with a sync
|
||
// reset instruction.
|
||
//
|
||
// If we have a READ, we must flush the buffer (which has the side
|
||
// effect of starting SyncReset), perform the read operation, stop
|
||
// sync reset, and put back a sync reset instruction in the buffer
|
||
// so we can go on appropriately
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
||
// If it is 1 it could select a non-existent clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
*Data &= 0xFFFFFFF7;
|
||
|
||
}
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = Port;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_ULONG_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = *Data;
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
//
|
||
// Check to see if this instruction was ending sync reset.
|
||
// If it did, we must flush the buffer and reset the trapped
|
||
// IO ports to the minimal set.
|
||
//
|
||
|
||
if (Port == SEQ_ADDRESS_PORT) {
|
||
|
||
//
|
||
// If we are accessing the seq address port, keep track of its
|
||
// value
|
||
//
|
||
|
||
hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
|
||
|
||
}
|
||
|
||
if ((Port == SEQ_ADDRESS_PORT) &&
|
||
( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
|
||
END_SYNC_RESET_VALUE) &&
|
||
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
||
|
||
endEmulation = 1;
|
||
|
||
} else {
|
||
|
||
//
|
||
// If the buffer is not full, then just return right away.
|
||
//
|
||
|
||
if (hwDeviceExtension->TrappedValidatorCount <
|
||
VGA_MAX_VALIDATOR_DATA - 1) {
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
endEmulation = 0;
|
||
}
|
||
}
|
||
|
||
//
|
||
// We are either in a READ path or a WRITE path that caused a
|
||
// a full buffer. So flush the buffer either way.
|
||
//
|
||
// To do this put an END_SYNC_RESET at the end since we want to make
|
||
// the buffer is ended sync reset ended.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
||
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8));
|
||
|
||
hwDeviceExtension->TrappedValidatorCount++;
|
||
|
||
VideoPortSynchronizeExecution(hwDeviceExtension,
|
||
VpHighPriority,
|
||
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
||
VgaPlaybackValidatorData,
|
||
hwDeviceExtension);
|
||
|
||
//
|
||
// Write back the real value of the sequencer address port.
|
||
//
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT,
|
||
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
||
|
||
//
|
||
// If we are in a READ path, read the data
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_READ_ACCESS) {
|
||
|
||
*Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
||
Port));
|
||
|
||
endEmulation = 0;
|
||
|
||
}
|
||
|
||
//
|
||
// If we are ending emulation, reset trapping to the minimal amount
|
||
// and exit.
|
||
//
|
||
|
||
if (endEmulation) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
MinimalVgaValidatorAccessRange);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
//
|
||
// For both cases, put back a START_SYNC_RESET in the buffer.
|
||
//
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_USHORT_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data =
|
||
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
||
|
||
} else {
|
||
|
||
//
|
||
// Nothing trapped.
|
||
// Lets check is the IO is trying to do something that would require
|
||
// us to stop trapping
|
||
//
|
||
|
||
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
||
|
||
//
|
||
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
||
// If it is 1 it could select a non-existant clock, and kill the
|
||
// system
|
||
//
|
||
|
||
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
||
|
||
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT);
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(START_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
||
Port),
|
||
(ULONG) (*Data & 0xFFFFFFF7) );
|
||
|
||
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
||
SEQ_ADDRESS_PORT),
|
||
(USHORT) (IND_SYNC_RESET +
|
||
(END_SYNC_RESET_VALUE << 8)));
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
||
temp);
|
||
|
||
return NO_ERROR;
|
||
|
||
}
|
||
|
||
if ( (Port == SEQ_ADDRESS_PORT) &&
|
||
(((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
||
((*Data & 0xFF) == IND_SYNC_RESET)) {
|
||
|
||
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
||
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
||
FullVgaValidatorAccessRange);
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 1;
|
||
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
||
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
||
VGA_VALIDATOR_ULONG_ACCESS;
|
||
|
||
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
||
|
||
//
|
||
// Start keeping track of the state of the sequencer port.
|
||
//
|
||
|
||
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
||
|
||
} else {
|
||
|
||
VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
||
Port),
|
||
*Data);
|
||
|
||
}
|
||
|
||
} else {
|
||
|
||
*Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
||
Port));
|
||
|
||
}
|
||
}
|
||
|
||
return NO_ERROR;
|
||
|
||
} // end VgaValidatorUlongEntry()
|
||
|
||
|
||
BOOLEAN
|
||
VgaPlaybackValidatorData(
|
||
PVOID Context
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
Performs all the DOS apps IO port accesses that were trapped by the
|
||
validator. Only IO accesses that can be processed are WRITEs
|
||
|
||
The number of outstanding IO access in deviceExtension is set to
|
||
zero as a side effect.
|
||
|
||
This function must be called via a call to VideoPortSynchronizeRoutine.
|
||
|
||
Arguments:
|
||
|
||
Context - Context parameter passed to the synchronized routine.
|
||
Must be a pointer to the miniport driver's device extension.
|
||
|
||
Return Value:
|
||
|
||
TRUE.
|
||
|
||
--*/
|
||
|
||
{
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = Context;
|
||
ULONG ioBaseAddress = (ULONG) hwDeviceExtension->IOAddress;
|
||
UCHAR i;
|
||
PVGA_VALIDATOR_DATA validatorData = hwDeviceExtension->TrappedValidatorData;
|
||
|
||
//
|
||
// Loop through the array of data and do instructions one by one.
|
||
//
|
||
|
||
for (i = 0; i < hwDeviceExtension->TrappedValidatorCount;
|
||
i++, validatorData++) {
|
||
|
||
//
|
||
// Calculate base address first
|
||
//
|
||
|
||
ioBaseAddress = (ULONG)hwDeviceExtension->IOAddress +
|
||
validatorData->Port;
|
||
|
||
|
||
//
|
||
// This is a write operation. We will automatically stop when the
|
||
// buffer is empty.
|
||
//
|
||
|
||
switch (validatorData->AccessType) {
|
||
|
||
case VGA_VALIDATOR_UCHAR_ACCESS :
|
||
|
||
VideoPortWritePortUchar((PUCHAR)ioBaseAddress,
|
||
(UCHAR) validatorData->Data);
|
||
|
||
break;
|
||
|
||
case VGA_VALIDATOR_USHORT_ACCESS :
|
||
|
||
VideoPortWritePortUshort((PUSHORT)ioBaseAddress,
|
||
(USHORT) validatorData->Data);
|
||
|
||
break;
|
||
|
||
case VGA_VALIDATOR_ULONG_ACCESS :
|
||
|
||
VideoPortWritePortUlong((PULONG)ioBaseAddress,
|
||
(ULONG) validatorData->Data);
|
||
|
||
break;
|
||
|
||
default:
|
||
|
||
VideoDebugPrint((1, "InvalidValidatorAccessType\n" ));
|
||
|
||
}
|
||
}
|
||
|
||
hwDeviceExtension->TrappedValidatorCount = 0;
|
||
|
||
return TRUE;
|
||
|
||
} // end VgaPlaybackValidatorData()
|
||
|
||
//---------------------------------------------------------------------------
|
||
//
|
||
// The memory manager needs a "C" interface to the banking function
|
||
//
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This function is a "C" callable interface to the ASM banking
|
||
function. It is NON paged because it is called from the
|
||
Memory Manager during some page faults.
|
||
|
||
Arguments:
|
||
|
||
iBankRead - Index of bank we want mapped in to read from.
|
||
iBankWrite - Index of bank we want mapped in to write to.
|
||
|
||
Return Value:
|
||
|
||
None.
|
||
|
||
--*/
|
||
|
||
|
||
VOID
|
||
vBankMap(
|
||
ULONG iBankRead,
|
||
ULONG iBankWrite,
|
||
PVOID pvContext
|
||
)
|
||
{
|
||
VideoDebugPrint((1, "vBankMap(%d,%d) - enter\n",iBankRead,iBankWrite));
|
||
#ifdef _X86_
|
||
_asm {
|
||
mov eax,iBankRead
|
||
mov edx,iBankWrite
|
||
lea ebx,BankSwitchStart
|
||
call ebx
|
||
}
|
||
#endif
|
||
VideoDebugPrint((1, "vBankMap - exit\n"));
|
||
}
|
||
|
||
//
|
||
// This routines was taken from the VGA miniport sources for
|
||
// the PPC thinkpad. We need this driver to be generic, and
|
||
// to work with any portable with a WD90C24 chip. The addresses
|
||
// used below to test for the panel type (0x102, 0xD00, 0xD01)
|
||
// may be exclusive to Thinkpad's only. I have tested this routine
|
||
// on a non-ibm machine, and all seemed to work, but it would be
|
||
// nice to determine exactly what these registers are, and how
|
||
// they are used.
|
||
//
|
||
|
||
VOID
|
||
GetPanelType(
|
||
PHW_DEVICE_EXTENSION HwDeviceExtension
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine get the type of attached LCD display.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
||
|
||
Return Value:
|
||
|
||
None.
|
||
|
||
--*/
|
||
{
|
||
UCHAR i;
|
||
PUCHAR VAddress[2];
|
||
|
||
//
|
||
// Assume CRT only mode
|
||
//
|
||
|
||
HwDeviceExtension->DisplayType = MONITOR;
|
||
|
||
//
|
||
// if we weren't able to claim the address ranges for the panel
|
||
// detection registers, then we can't try to detect the panel
|
||
// type.
|
||
//
|
||
|
||
if (HwDeviceExtension->ExtendedRegisters !=
|
||
EXTENDED_AND_FLAT_PANEL_REGISTERS)
|
||
{
|
||
return;
|
||
}
|
||
|
||
for (i = 0; i < 2; i++) {
|
||
|
||
if ((VAddress[i] =
|
||
VideoPortGetDeviceBase(HwDeviceExtension,
|
||
VgaAccessRange[i+4].RangeStart,
|
||
VgaAccessRange[i+4].RangeLength,
|
||
VgaAccessRange[i+4].RangeInIoSpace)) == NULL) {
|
||
|
||
VideoDebugPrint((1, "GetPanelType - Fail to get address\n"));
|
||
return;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
VideoPortWritePortUchar(VAddress[0], 0x01);
|
||
VideoPortWritePortUchar(VAddress[1], 0xff);
|
||
|
||
#if 0
|
||
{
|
||
UCHAR temp;
|
||
|
||
temp = VideoPortReadPortUchar(VAddress[1] + 1);
|
||
|
||
VideoDebugPrint((1, "Pre Panel type = 0x%x\n", temp));
|
||
}
|
||
#endif
|
||
|
||
switch (VideoPortReadPortUchar(VAddress[1] + 1) & 0x0f) {
|
||
case 0x0e : HwDeviceExtension->DisplayType |= IBM_F8515;
|
||
break;
|
||
case 0x0c : HwDeviceExtension->DisplayType |= IBM_F8532;
|
||
break;
|
||
case 0x0d : HwDeviceExtension->DisplayType |= TOSHIBA_DSTNC;
|
||
break;
|
||
default : HwDeviceExtension->DisplayType |= UNKNOWN_LCD;
|
||
break;
|
||
}
|
||
|
||
VideoDebugPrint((2, "GetPanelType - PanelID = %d\n",HwDeviceExtension->DisplayType & 0x0e));
|
||
|
||
for (i = 0; i < 2; i++) {
|
||
|
||
VideoPortFreeDeviceBase(HwDeviceExtension,VAddress[i]);
|
||
|
||
}
|
||
}
|
||
|
||
BOOLEAN
|
||
WdResetHw(
|
||
PVOID HwDeviceExtension,
|
||
ULONG Columns,
|
||
ULONG Rows
|
||
)
|
||
|
||
/*++
|
||
|
||
Routine Description:
|
||
|
||
This routine preps the Wd card for return to a VGA mode.
|
||
|
||
This routine is called during system shutdown. By returning
|
||
a FALSE we inform the HAL to do an int 10 to go into text
|
||
mode before shutting down. Shutdown would fail with some Wd
|
||
cards without this.
|
||
|
||
We do some clean up before returning so that the int 10
|
||
will work.
|
||
|
||
Arguments:
|
||
|
||
HwDeviceExtension - Supplies a pointer to the miniport's device extension.
|
||
|
||
Return Value:
|
||
|
||
The return value of FALSE informs the hal to go into text mode.
|
||
|
||
--*/
|
||
|
||
{
|
||
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
||
|
||
UNREFERENCED_PARAMETER(Columns);
|
||
UNREFERENCED_PARAMETER(Rows);
|
||
|
||
if ((hwDeviceExtension->BoardID == WD90C24A) &&
|
||
(hwDeviceExtension->IsIBM == TRUE))
|
||
{
|
||
BOOLEAN bLCD=FALSE;
|
||
|
||
VgaInterpretCmdStream(HwDeviceExtension, Reset);
|
||
|
||
//
|
||
// If the LCD is enabled we also need to SET bit 0
|
||
// of PR2.
|
||
//
|
||
// We will check to see if the LCD is enabled by
|
||
// checking bit 2 of CRTC register 0x31, and bit
|
||
// 4 of CRTC register 0x32. If either of these
|
||
// is set, then we'll assume an LCD is enabled.
|
||
//
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x31);
|
||
if (VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR) & 0x04)
|
||
{
|
||
bLCD = TRUE;
|
||
}
|
||
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
CRTC_ADDRESS_PORT_COLOR, 0x32);
|
||
if (VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
||
CRTC_DATA_PORT_COLOR) & 0x10)
|
||
{
|
||
bLCD = TRUE;
|
||
}
|
||
|
||
if (bLCD == TRUE)
|
||
{
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0c);
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)0x01);
|
||
}
|
||
else
|
||
{
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
GRAPH_ADDRESS_PORT, 0x0c);
|
||
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
||
GRAPH_DATA_PORT, (UCHAR)0x00);
|
||
}
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
//
|
||
// Routine to set a desired DPMS power management state.
|
||
//
|
||
VP_STATUS
|
||
VGASetPower50(
|
||
PHW_DEVICE_EXTENSION phwDeviceExtension,
|
||
ULONG HwDeviceId,
|
||
PVIDEO_POWER_MANAGEMENT pVideoPowerMgmt
|
||
)
|
||
{
|
||
if ((pVideoPowerMgmt->PowerState == VideoPowerOn) ||
|
||
(pVideoPowerMgmt->PowerState == VideoPowerHibernate)) {
|
||
|
||
return NO_ERROR;
|
||
|
||
} else {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Routine to retrieve possible DPMS power management states.
|
||
//
|
||
VP_STATUS
|
||
VGAGetPower50(
|
||
PHW_DEVICE_EXTENSION phwDeviceExtension,
|
||
ULONG HwDeviceId,
|
||
PVIDEO_POWER_MANAGEMENT pVideoPowerMgmt
|
||
)
|
||
{
|
||
if ((pVideoPowerMgmt->PowerState == VideoPowerOn) ||
|
||
(pVideoPowerMgmt->PowerState == VideoPowerHibernate)) {
|
||
|
||
return NO_ERROR;
|
||
|
||
} else {
|
||
|
||
return ERROR_INVALID_FUNCTION;
|
||
}
|
||
}
|
||
|
||
|
||
//
|
||
// Routine to retrieve the Enhanced Display ID structure via DDC
|
||
//
|
||
ULONG
|
||
VGAGetVideoChildDescriptor(
|
||
PVOID HwDeviceExtension,
|
||
PVIDEO_CHILD_ENUM_INFO ChildEnumInfo,
|
||
PVIDEO_CHILD_TYPE pChildType,
|
||
PVOID pvChildDescriptor,
|
||
PULONG pHwId,
|
||
PULONG pUnused
|
||
)
|
||
{
|
||
PHW_DEVICE_EXTENSION pHwDeviceExtension = HwDeviceExtension;
|
||
ULONG Status;
|
||
|
||
ASSERT(pHwDeviceExtension != NULL && pMoreChildren != NULL);
|
||
|
||
VideoDebugPrint((2, "WDVGA VGAGetVideoChildDescriptor: *** Entry point ***\n"));
|
||
|
||
//
|
||
// Determine if the graphics adapter in the system supports
|
||
// DDC2 (our miniport only supports DDC2, not DDC1). This has
|
||
// the side effect (assuming both monitor and card support
|
||
// DDC2) of switching the monitor from DDC1 mode (repeated
|
||
// "blind" broadcast of EDID clocked by the vertical sync
|
||
// signal) to DDC2 mode (query/response not using any of the
|
||
// normal video lines - can transfer information rapidly
|
||
// without first disrupting the screen by switching into
|
||
// a pseudo-mode with a high vertical sync frequency).
|
||
//
|
||
// Since we must support hot-plugging of monitors, and our
|
||
// routine to obtain the EDID structure via DDC2 assumes that
|
||
// the monitor is in DDC2 mode, we must make this test each
|
||
// time this entry point is called.
|
||
//
|
||
|
||
switch (ChildEnumInfo->ChildIndex) {
|
||
case 0:
|
||
|
||
//
|
||
// Case 0 is used to enumerate devices found by the ACPI firmware.
|
||
//
|
||
// Since we do not support ACPI devices yet, we must return failure.
|
||
//
|
||
|
||
Status = ERROR_NO_MORE_DEVICES;
|
||
break;
|
||
|
||
case 1:
|
||
|
||
//
|
||
// We do not support monitor enumeration
|
||
//
|
||
|
||
Status = ERROR_NO_MORE_DEVICES;
|
||
break;
|
||
|
||
case DISPLAY_ADAPTER_HW_ID:
|
||
{
|
||
|
||
PUSHORT pPnpDeviceDescription = NULL;
|
||
ULONG stringSize = sizeof(L"*PNPXXXX");
|
||
|
||
|
||
//
|
||
// Special ID to handle return legacy PnP IDs for root enumerated
|
||
// devices.
|
||
//
|
||
|
||
*pChildType = VideoChip;
|
||
*pHwId = DISPLAY_ADAPTER_HW_ID;
|
||
|
||
//
|
||
// Figure out which card type and set pPnpDeviceDescription at
|
||
// associated string.
|
||
//
|
||
|
||
//
|
||
// [Mfg.Diamond]
|
||
// %SpeedStar24X%=WD,, *PNP0907
|
||
//
|
||
// [Mfg.DFI]
|
||
// %WG6000%=WD,, *PNP0907
|
||
//
|
||
// [Mfg.IBM]
|
||
// %TP755CX%=TP755CX,MSDisp_TP755CX, *PNP0907
|
||
//
|
||
// [Mfg.Paradise]
|
||
// %PortsOCall%=WD,, *PNP0907
|
||
// %AccelVL%=WD,, *PNP0907
|
||
// %ParaSVGA%=WD,, *PNP0907
|
||
//
|
||
// [Mfg.WD]
|
||
// %*PNP0907.DeviceDesc%=WD, *PNP0907
|
||
// %*PNP0907.DeviceDesc%=WD, *PNP0908 BUGBUG
|
||
// %WD512%=WD512,, *PNP0907, *PNP0908 BUGBUG
|
||
//
|
||
|
||
if ((pHwDeviceExtension->BoardID == WD90C24A))
|
||
pPnpDeviceDescription = L"*PNP0907";
|
||
|
||
else if (pHwDeviceExtension->BoardID == SPEEDSTAR30)
|
||
pPnpDeviceDescription = L"*PNP0908";
|
||
else
|
||
pPnpDeviceDescription = L"*PNP0908";
|
||
|
||
//
|
||
// Now just copy the string into memory provided.
|
||
//
|
||
|
||
memcpy(pvChildDescriptor, pPnpDeviceDescription, stringSize);
|
||
|
||
Status = ERROR_MORE_DATA;
|
||
break;
|
||
}
|
||
|
||
default:
|
||
|
||
Status = ERROR_NO_MORE_DEVICES;
|
||
break;
|
||
}
|
||
|
||
return Status;
|
||
}
|