[XBOXVMP] Code formatting only

This commit is contained in:
Stanislav Motylkov 2019-09-01 22:30:09 +03:00 committed by Hermès BÉLUSCA - MAÏTO
parent 053bf17e8b
commit 816149e0c3
2 changed files with 514 additions and 443 deletions

View file

@ -1,23 +1,10 @@
/*
* ReactOS Xbox miniport video driver
* Copyright (C) 2004 van Geldorp
*
* Based on VBE miniport video driver
* Copyright (C) 2004 Filip Navara
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: ReactOS Xbox miniport video driver
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Simple framebuffer driver for NVIDIA NV2A XGPU
* COPYRIGHT: Copyright 2004 van Geldorp
* Copyright 2004 Filip Navara
* Copyright 2019 Stanislav Motylkov (x86corez@gmail.com)
*
* TODO:
* - Check input parameters everywhere.
@ -35,8 +22,11 @@
/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
ULONG NTAPI
DriverEntry(IN PVOID Context1, IN PVOID Context2)
ULONG
NTAPI
DriverEntry(
IN PVOID Context1,
IN PVOID Context2)
{
VIDEO_HW_INITIALIZATION_DATA InitData;
@ -60,7 +50,8 @@ DriverEntry(IN PVOID Context1, IN PVOID Context2)
* Detects the Xbox Nvidia display adapter.
*/
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpFindAdapter(
IN PVOID HwDeviceExtension,
IN PVOID HwContext,
@ -77,6 +68,7 @@ XboxVmpFindAdapter(
VideoPortDebugPrint(Trace, "XboxVmpFindAdapter\n");
XboxVmpDeviceExtension = (PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension;
Status = VideoPortGetAccessRanges(HwDeviceExtension, 0, NULL, 3, AccessRanges,
&VendorId, &DeviceId, NULL);
@ -97,8 +89,10 @@ XboxVmpFindAdapter(
* up control of the video hardware to the video port driver.
*/
BOOLEAN NTAPI
XboxVmpInitialize(PVOID HwDeviceExtension)
BOOLEAN
NTAPI
XboxVmpInitialize(
PVOID HwDeviceExtension)
{
PXBOXVMP_DEVICE_EXTENSION XboxVmpDeviceExtension;
ULONG inIoSpace = VIDEO_MEMORY_SPACE_MEMORY;
@ -110,14 +104,17 @@ XboxVmpInitialize(PVOID HwDeviceExtension)
Length = XboxVmpDeviceExtension->ControlLength;
XboxVmpDeviceExtension->VirtControlStart = NULL;
if (NO_ERROR != VideoPortMapMemory(HwDeviceExtension,
if (VideoPortMapMemory(HwDeviceExtension,
XboxVmpDeviceExtension->PhysControlStart,
&Length, &inIoSpace,
&XboxVmpDeviceExtension->VirtControlStart))
&Length,
&inIoSpace,
&XboxVmpDeviceExtension->VirtControlStart) != NO_ERROR)
{
VideoPortDebugPrint(Error, "Failed to map control memory\n");
return FALSE;
}
VideoPortDebugPrint(Info, "Mapped 0x%x bytes of control mem at 0x%x to virt addr 0x%x\n",
XboxVmpDeviceExtension->ControlLength,
XboxVmpDeviceExtension->PhysControlStart.u.LowPart,
@ -132,7 +129,8 @@ XboxVmpInitialize(PVOID HwDeviceExtension)
* Processes the specified Video Request Packet.
*/
BOOLEAN NTAPI
BOOLEAN
NTAPI
XboxVmpStartIO(
PVOID HwDeviceExtension,
PVIDEO_REQUEST_PACKET RequestPacket)
@ -144,97 +142,127 @@ XboxVmpStartIO(
switch (RequestPacket->IoControlCode)
{
case IOCTL_VIDEO_SET_CURRENT_MODE:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_SET_CURRENT_MODE\n");
if (RequestPacket->InputBufferLength < sizeof(VIDEO_MODE))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpSetCurrentMode(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_MODE)RequestPacket->InputBuffer,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_RESET_DEVICE:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_RESET_DEVICE\n");
Result = XboxVmpResetDevice(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_MAP_VIDEO_MEMORY:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_MAP_VIDEO_MEMORY\n");
if (RequestPacket->OutputBufferLength < sizeof(VIDEO_MEMORY_INFORMATION) ||
RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpMapVideoMemory(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_MEMORY)RequestPacket->InputBuffer,
(PVIDEO_MEMORY_INFORMATION)RequestPacket->OutputBuffer,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_UNMAP_VIDEO_MEMORY:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_UNMAP_VIDEO_MEMORY\n");
if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpUnmapVideoMemory(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_MEMORY)RequestPacket->InputBuffer,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES\n");
if (RequestPacket->OutputBufferLength < sizeof(VIDEO_NUM_MODES))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpQueryNumAvailModes(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_NUM_MODES)RequestPacket->OutputBuffer,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_QUERY_AVAIL_MODES:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_QUERY_AVAIL_MODES\n");
if (RequestPacket->OutputBufferLength < sizeof(VIDEO_MODE_INFORMATION))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpQueryAvailModes(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_MODE_INFORMATION)RequestPacket->OutputBuffer,
RequestPacket->StatusBlock);
break;
}
case IOCTL_VIDEO_QUERY_CURRENT_MODE:
{
VideoPortDebugPrint(Trace, "XboxVmpStartIO IOCTL_VIDEO_QUERY_CURRENT_MODE\n");
if (RequestPacket->OutputBufferLength < sizeof(VIDEO_MODE_INFORMATION))
{
RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
return TRUE;
}
Result = XboxVmpQueryCurrentMode(
(PXBOXVMP_DEVICE_EXTENSION)HwDeviceExtension,
(PVIDEO_MODE_INFORMATION)RequestPacket->OutputBuffer,
RequestPacket->StatusBlock);
break;
}
default:
{
VideoPortDebugPrint(Warn, "XboxVmpStartIO 0x%x not implemented\n");
RequestPacket->StatusBlock->Status = ERROR_INVALID_FUNCTION;
return FALSE;
}
}
if (Result)
{
@ -250,7 +278,8 @@ XboxVmpStartIO(
* This function is called to reset the hardware to a known state.
*/
BOOLEAN NTAPI
BOOLEAN
NTAPI
XboxVmpResetHw(
PVOID DeviceExtension,
ULONG Columns,
@ -272,7 +301,8 @@ XboxVmpResetHw(
* Queries whether the device can support the requested power state.
*/
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpGetPowerState(
PVOID HwDeviceExtension,
ULONG HwId,
@ -289,7 +319,8 @@ XboxVmpGetPowerState(
* Sets the power state of the specified device
*/
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpSetPowerState(
PVOID HwDeviceExtension,
ULONG HwId,
@ -306,19 +337,21 @@ XboxVmpSetPowerState(
* Sets the adapter to the specified operating mode.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpSetCurrentMode(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE RequestedMode,
PSTATUS_BLOCK StatusBlock)
{
if (0 != RequestedMode->RequestedMode)
if (RequestedMode->RequestedMode != 0)
{
return FALSE;
}
/* Nothing to do, really. We only support a single mode and we're already
in that mode */
* in that mode
*/
return TRUE;
}
@ -329,7 +362,8 @@ XboxVmpSetCurrentMode(
* at system boot.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpResetDevice(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PSTATUS_BLOCK StatusBlock)
@ -346,7 +380,8 @@ XboxVmpResetDevice(
* space of the requestor.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpMapVideoMemory(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MEMORY RequestedAddress,
@ -378,8 +413,12 @@ XboxVmpMapVideoMemory(
FrameBuffer.QuadPart += DeviceExtension->PhysFrameBufferStart.QuadPart;
MapInformation->VideoRamBase = RequestedAddress->RequestedVirtualAddress;
MapInformation->VideoRamLength = 4 * 1024 * 1024;
VideoPortMapMemory(DeviceExtension, FrameBuffer,
&MapInformation->VideoRamLength, &inIoSpace,
VideoPortMapMemory(
DeviceExtension,
FrameBuffer,
&MapInformation->VideoRamLength,
&inIoSpace,
&MapInformation->VideoRamBase);
MapInformation->FrameBufferBase = MapInformation->VideoRamBase;
@ -401,13 +440,16 @@ XboxVmpMapVideoMemory(
* frame buffer and video RAM.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpUnmapVideoMemory(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MEMORY VideoMemory,
PSTATUS_BLOCK StatusBlock)
{
VideoPortUnmapMemory(DeviceExtension, VideoMemory->RequestedVirtualAddress,
VideoPortUnmapMemory(
DeviceExtension,
VideoMemory->RequestedVirtualAddress,
NULL);
return TRUE;
@ -421,7 +463,8 @@ XboxVmpUnmapVideoMemory(
* buffer for an IOCTL_VIDEO_QUERY_AVAIL_MODES request.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryNumAvailModes(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_NUM_MODES Modes,
@ -433,17 +476,22 @@ XboxVmpQueryNumAvailModes(
return TRUE;
}
static BOOLEAN
ReadfromSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
static
BOOLEAN
ReadfromSMBus(
UCHAR Address,
UCHAR bRegister,
UCHAR Size,
ULONG *Data_to_smbus)
{
int nRetriesToLive = 50;
while (0 != (VideoPortReadPortUshort((PUSHORT) (I2C_IO_BASE + 0)) & 0x0800))
while ((VideoPortReadPortUshort((PUSHORT) (I2C_IO_BASE + 0)) & 0x0800) != 0)
{
; /* Franz's spin while bus busy with any master traffic */
}
while (0 != nRetriesToLive--)
while (nRetriesToLive-- != 0)
{
UCHAR b;
int temp;
@ -457,29 +505,36 @@ ReadfromSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
switch (Size)
{
case 4:
{
VideoPortWritePortUchar((PUCHAR) (I2C_IO_BASE + 2), 0x0d); /* DWORD modus ? */
break;
}
case 2:
{
VideoPortWritePortUchar((PUCHAR) (I2C_IO_BASE + 2), 0x0b); /* WORD modus */
break;
}
default:
VideoPortWritePortUchar((PUCHAR) (I2C_IO_BASE + 2), 0x0a); // BYTE
break;
{
VideoPortWritePortUchar((PUCHAR) (I2C_IO_BASE + 2), 0x0a); /* BYTE */
}
}
b = 0;
while (0 == (b & 0x36))
while ((b & 0x36) == 0)
{
b = VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 0));
}
if (0 != (b & 0x24))
if ((b & 0x24) != 0)
{
/* printf("I2CTransmitByteGetReturn error %x\n", b); */
}
if(0 == (b & 0x10))
if ((b & 0x10) == 0)
{
/* printf("I2CTransmitByteGetReturn no complete, retry\n"); */
}
@ -488,20 +543,26 @@ ReadfromSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
switch (Size)
{
case 4:
{
VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 6));
VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 9));
VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 9));
VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 9));
VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 9));
break;
}
case 2:
{
*Data_to_smbus = VideoPortReadPortUshort((PUSHORT) (I2C_IO_BASE + 6));
break;
default:
*Data_to_smbus = VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 6));
break;
}
default:
{
*Data_to_smbus = VideoPortReadPortUchar((PUCHAR) (I2C_IO_BASE + 6));
}
}
return TRUE;
}
@ -511,8 +572,12 @@ ReadfromSMBus(UCHAR Address, UCHAR bRegister, UCHAR Size, ULONG *Data_to_smbus)
}
static BOOLEAN
I2CTransmitByteGetReturn(UCHAR bPicAddressI2cFormat, UCHAR bDataToWrite, ULONG *Return)
static
BOOLEAN
I2CTransmitByteGetReturn(
UCHAR bPicAddressI2cFormat,
UCHAR bDataToWrite,
ULONG *Return)
{
return ReadfromSMBus(bPicAddressI2cFormat, bDataToWrite, 1, Return);
}
@ -523,7 +588,8 @@ I2CTransmitByteGetReturn(UCHAR bPicAddressI2cFormat, UCHAR bDataToWrite, ULONG *
* Returns information about each video mode supported by the adapter.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryAvailModes(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE_INFORMATION VideoMode,
@ -538,7 +604,8 @@ XboxVmpQueryAvailModes(
* Returns information about current video mode.
*/
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryCurrentMode(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE_INFORMATION VideoMode,
@ -548,9 +615,10 @@ XboxVmpQueryCurrentMode(
VideoMode->Length = sizeof(VIDEO_MODE_INFORMATION);
VideoMode->ModeIndex = 0;
if (I2CTransmitByteGetReturn(0x10, 0x04, &AvMode))
{
if (1 == AvMode) /* HDTV */
if (AvMode == 1) /* HDTV */
{
VideoMode->VisScreenWidth = 720;
}
@ -571,6 +639,7 @@ XboxVmpQueryCurrentMode(
{
VideoMode->VisScreenWidth = 640;
}
VideoMode->VisScreenHeight = 480;
VideoMode->ScreenStride = VideoMode->VisScreenWidth * 4;
VideoMode->NumberOfPlanes = 1;
@ -581,9 +650,9 @@ XboxVmpQueryCurrentMode(
VideoMode->NumberRedBits = 8;
VideoMode->NumberGreenBits = 8;
VideoMode->NumberBlueBits = 8;
VideoMode->RedMask = 0xff0000;
VideoMode->GreenMask = 0x00ff00;
VideoMode->BlueMask = 0x0000ff;
VideoMode->RedMask = 0xFF0000;
VideoMode->GreenMask = 0x00FF00;
VideoMode->BlueMask = 0x0000FF;
VideoMode->VideoMemoryBitmapWidth = VideoMode->VisScreenWidth;
VideoMode->VideoMemoryBitmapHeight = VideoMode->VisScreenHeight;
VideoMode->AttributeFlags = VIDEO_MODE_GRAPHICS | VIDEO_MODE_COLOR |

View file

@ -1,23 +1,10 @@
/*
* ReactOS Xbox miniport video driver
* Copyright (C) 2004 van Geldorp
*
* Based on VBE miniport video driver
* Copyright (C) 2004 Filip Navara
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* PROJECT: ReactOS Xbox miniport video driver
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Simple framebuffer driver for NVIDIA NV2A XGPU
* COPYRIGHT: Copyright 2004 Ge van Geldorp
* Copyright 2004 Filip Navara
* Copyright 2019 Stanislav Motylkov (x86corez@gmail.com)
*/
#pragma once
@ -65,7 +52,8 @@ typedef struct
PHYSICAL_ADDRESS PhysFrameBufferStart;
} XBOXVMP_DEVICE_EXTENSION, *PXBOXVMP_DEVICE_EXTENSION;
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpFindAdapter(
IN PVOID HwDeviceExtension,
IN PVOID HwContext,
@ -73,75 +61,89 @@ XboxVmpFindAdapter(
IN OUT PVIDEO_PORT_CONFIG_INFO ConfigInfo,
OUT PUCHAR Again);
BOOLEAN NTAPI
XboxVmpInitialize(PVOID HwDeviceExtension);
BOOLEAN
NTAPI
XboxVmpInitialize(
PVOID HwDeviceExtension);
BOOLEAN NTAPI
BOOLEAN
NTAPI
XboxVmpStartIO(
PVOID HwDeviceExtension,
PVIDEO_REQUEST_PACKET RequestPacket);
BOOLEAN NTAPI
BOOLEAN
NTAPI
XboxVmpResetHw(
PVOID DeviceExtension,
ULONG Columns,
ULONG Rows);
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpGetPowerState(
PVOID HwDeviceExtension,
ULONG HwId,
PVIDEO_POWER_MANAGEMENT VideoPowerControl);
VP_STATUS NTAPI
VP_STATUS
NTAPI
XboxVmpSetPowerState(
PVOID HwDeviceExtension,
ULONG HwId,
PVIDEO_POWER_MANAGEMENT VideoPowerControl);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpSetCurrentMode(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE RequestedMode,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpResetDevice(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpMapVideoMemory(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MEMORY RequestedAddress,
PVIDEO_MEMORY_INFORMATION MapInformation,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpUnmapVideoMemory(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MEMORY VideoMemory,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryNumAvailModes(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_NUM_MODES Modes,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryAvailModes(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE_INFORMATION ReturnedModes,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpQueryCurrentMode(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_MODE_INFORMATION VideoModeInfo,
PSTATUS_BLOCK StatusBlock);
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
XboxVmpSetColorRegisters(
PXBOXVMP_DEVICE_EXTENSION DeviceExtension,
PVIDEO_CLUT ColorLookUpTable,