- Added support IOCTRL_QUERY_PUBLIC_ACCESS_RANGES, IOCTRL_SET_PALETTE_REGISTERS,...
authorevb <evb@svn.reactos.org>
Thu, 11 Mar 2010 17:56:27 +0000 (17:56 +0000)
committerevb <evb@svn.reactos.org>
Thu, 11 Mar 2010 17:56:27 +0000 (17:56 +0000)
- Code from NT4 DDK Cirrus miniport with some mods by me.

svn path=/trunk/; revision=46106

reactos/drivers/video/miniport/vga_new/modeset.c
reactos/drivers/video/miniport/vga_new/vga.c

index 83c0001..abe1191 100644 (file)
@@ -41,6 +41,14 @@ VgaQueryNumberOfAvailableModes(
     PULONG OutputSize
     );
 
+VP_STATUS
+VgaQueryCurrentMode(
+    PHW_DEVICE_EXTENSION HwDeviceExtension,
+    PVIDEO_MODE_INFORMATION ModeInformation,
+    ULONG ModeInformationSize,
+    PULONG OutputSize
+    );
+
 VOID
 VgaZeroVideoMemory(
     PHW_DEVICE_EXTENSION HwDeviceExtension
@@ -697,6 +705,139 @@ Return Value:
 
 } // end VgaGetNumberOfAvailableModes()
 \f
+VP_STATUS
+VgaQueryCurrentMode(
+    PHW_DEVICE_EXTENSION HwDeviceExtension,
+    PVIDEO_MODE_INFORMATION ModeInformation,
+    ULONG ModeInformationSize,
+    PULONG OutputSize
+    )
+
+/*++
+
+Routine Description:
+
+    This routine returns a description of the current video mode.
+
+Arguments:
+
+    HwDeviceExtension - Pointer to the miniport driver's device extension.
+
+    ModeInformation - Pointer to the output buffer supplied by the user.
+        This is where the current mode information is stored.
+
+    ModeInformationSize - 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:
+
+    ERROR_INSUFFICIENT_BUFFER if the output buffer was not large enough
+        for the data being returned.
+
+    NO_ERROR if the operation completed successfully.
+
+--*/
+
+{
+    //
+    // check if a mode has been set
+    //
+
+    if (HwDeviceExtension->CurrentMode == NULL ) {
+
+        return ERROR_INVALID_FUNCTION;
+
+    }
+
+    //
+    // 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 (ModeInformationSize < (*OutputSize = sizeof(VIDEO_MODE_INFORMATION))) {
+
+        return ERROR_INSUFFICIENT_BUFFER;
+
+    }
+
+    //
+    // Store the characteristics of the current mode into the buffer.
+    //
+
+    ModeInformation->Length = sizeof(VIDEO_MODE_INFORMATION);
+    ModeInformation->ModeIndex = HwDeviceExtension->ModeIndex;
+    ModeInformation->VisScreenWidth = HwDeviceExtension->CurrentMode->hres;
+    ModeInformation->ScreenStride = HwDeviceExtension->CurrentMode->wbytes;
+    ModeInformation->VisScreenHeight = HwDeviceExtension->CurrentMode->vres;
+    ModeInformation->NumberOfPlanes = HwDeviceExtension->CurrentMode->numPlanes;
+    ModeInformation->BitsPerPlane = HwDeviceExtension->CurrentMode->bitsPerPlane;
+    ModeInformation->Frequency = HwDeviceExtension->CurrentMode->Frequency;
+    ModeInformation->XMillimeter = 320;        // temporary hardcoded constant
+    ModeInformation->YMillimeter = 240;        // temporary hardcoded constant
+
+    ModeInformation->AttributeFlags = HwDeviceExtension->CurrentMode->fbType;
+
+    if ((ModeInformation->BitsPerPlane == 32) ||
+        (ModeInformation->BitsPerPlane == 24))
+    {
+
+        ModeInformation->NumberRedBits = 8;
+        ModeInformation->NumberGreenBits = 8;
+        ModeInformation->NumberBlueBits = 8;
+        ModeInformation->RedMask = 0xff0000;
+        ModeInformation->GreenMask = 0x00ff00;
+        ModeInformation->BlueMask = 0x0000ff;
+
+    }
+    else if (ModeInformation->BitsPerPlane == 16)
+    {
+
+        ModeInformation->NumberRedBits = 6;
+        ModeInformation->NumberGreenBits = 6;
+        ModeInformation->NumberBlueBits = 6;
+        ModeInformation->RedMask = 0x1F << 11;
+        ModeInformation->GreenMask = 0x3F << 5;
+        ModeInformation->BlueMask = 0x1F;
+
+    }
+// eVb: 2.12 [VGA] - Add support for 15bpp modes, which Cirrus doesn't support
+    else if (ModeInformation->BitsPerPlane == 15)
+    {
+
+        ModeInformation->NumberRedBits = 6;
+        ModeInformation->NumberGreenBits = 6;
+        ModeInformation->NumberBlueBits = 6;
+        ModeInformation->RedMask = 0x3E << 9;
+        ModeInformation->GreenMask = 0x1F << 5;
+        ModeInformation->BlueMask = 0x1F;
+    }
+// eVb: 2.12 [END]
+    else
+    {
+
+        ModeInformation->NumberRedBits = 6;
+        ModeInformation->NumberGreenBits = 6;
+        ModeInformation->NumberBlueBits = 6;
+        ModeInformation->RedMask = 0;
+        ModeInformation->GreenMask = 0;
+        ModeInformation->BlueMask = 0;
+    }
+
+// eVb: 2.13 [VGA] - All modes are palette managed/driven, unlike Cirrus
+    ModeInformation->AttributeFlags |= VIDEO_MODE_PALETTE_DRIVEN |
+         VIDEO_MODE_MANAGED_PALETTE;
+// eVb: 2.13 [END]
+
+    return NO_ERROR;
+
+} // end VgaQueryCurrentMode()
+
+\f
 VOID
 VgaZeroVideoMemory(
     PHW_DEVICE_EXTENSION HwDeviceExtension
index 5b59b53..a97c64b 100644 (file)
@@ -58,6 +58,14 @@ VgaQueryNumberOfAvailableModes(
     PULONG OutputSize
     );
 
+VP_STATUS
+VgaQueryCurrentMode(
+    PHW_DEVICE_EXTENSION HwDeviceExtension,
+    PVIDEO_MODE_INFORMATION ModeInformation,
+    ULONG ModeInformationSize,
+    PULONG OutputSize
+    );
+
 VP_STATUS
 VgaSetMode(
     PHW_DEVICE_EXTENSION HwDeviceExtension,
@@ -79,6 +87,13 @@ VgaInterpretCmdStream(
     PUSHORT pusCmdStream
     );
 
+VP_STATUS
+VgaSetPaletteReg(
+    PHW_DEVICE_EXTENSION HwDeviceExtension,
+    PVIDEO_PALETTE_DATA PaletteBuffer,
+    ULONG PaletteBufferSize
+    );
+    
 VP_STATUS
 VgaSetColorLookup(
     PHW_DEVICE_EXTENSION HwDeviceExtension,
@@ -394,7 +409,7 @@ Return Value:
          VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1,
          VgaAccessRange->RangeInIoSpace)) == NULL)
     {
-        VideoDebugPrint((2, "VgaFindAdapter - Fail to get io address\n"));
+        VideoDebugPrint((0, "VgaFindAdapter - Fail to get io address\n"));
 
         return ERROR_INVALID_PARAMETER;
     }
@@ -445,7 +460,7 @@ Return Value:
                                      VgaAccessRange[2].RangeLength,
                                      FALSE)) == NULL)
     {
-        VideoDebugPrint((1, "VgaFindAdapter - Fail to get memory address\n"));
+        VideoDebugPrint((0, "VgaFindAdapter - Fail to get memory address\n"));
 
         return ERROR_INVALID_PARAMETER;
     }
@@ -681,7 +696,10 @@ Return Value:
 
         VideoDebugPrint((2, "VgaStartIO - QueryCurrentMode\n"));
 
-        status = ERROR_INVALID_FUNCTION;
+        status = VgaQueryCurrentMode(HwDeviceExtension,
+                                     (PVIDEO_MODE_INFORMATION) RequestPacket->OutputBuffer,
+                                     RequestPacket->OutputBufferLength,
+                                     &RequestPacket->StatusBlock->Information);
 
         break;
 
@@ -775,7 +793,9 @@ Return Value:
 
         VideoDebugPrint((2, "VgaStartIO - SetPaletteRegs\n"));
 
-        status = ERROR_INVALID_FUNCTION;
+        status = VgaSetPaletteReg(HwDeviceExtension,
+                                  (PVIDEO_PALETTE_DATA) RequestPacket->InputBuffer,
+                                  RequestPacket->InputBufferLength);
 
         break;
 
@@ -825,8 +845,53 @@ Return Value:
         break;
 
     case IOCTL_VIDEO_QUERY_PUBLIC_ACCESS_RANGES:
+        {
+            VideoDebugPrint((2, "VgaStartIO - Query Public Address Ranges\n"));
+        
+            PVIDEO_PUBLIC_ACCESS_RANGES portAccess;
+            ULONG physicalPortLength;
+
+            if (RequestPacket->OutputBufferLength <
+                sizeof(VIDEO_PUBLIC_ACCESS_RANGES))
+            {
+                status = ERROR_INSUFFICIENT_BUFFER;
+                break;
+            }
+
+            RequestPacket->StatusBlock->Information =
+                sizeof(VIDEO_PUBLIC_ACCESS_RANGES);
+
+            portAccess = RequestPacket->OutputBuffer;
+
+            //
+            // The first public access range is the IO ports.
+            //
+
+            portAccess->VirtualAddress  = (PVOID) NULL;
+            portAccess->InIoSpace       = TRUE;
+            portAccess->MappedInIoSpace = portAccess->InIoSpace;
+            physicalPortLength = VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1;
+
+            status =  VideoPortMapMemory(hwDeviceExtension,
+                                         VgaAccessRange->RangeStart,
+                                         &physicalPortLength,
+                                         &(portAccess->MappedInIoSpace),
+                                         &(portAccess->VirtualAddress));
+// eVb: 1.17 [GCG] - Fix lvalue error
+            portAccess->VirtualAddress = (PVOID)((ULONG_PTR)portAccess->VirtualAddress - VGA_BASE_IO_PORT);
+// eVb: 1.17 [END]
+            VideoDebugPrint((2, "VgaStartIO - mapping ports to (%x)\n", portAccess->VirtualAddress));
+        }
+        
+        break;
+
     case IOCTL_VIDEO_FREE_PUBLIC_ACCESS_RANGES:
 
+        VideoDebugPrint((2, "VgaStartIO - Free Public Access Ranges\n"));
+
+        status = ERROR_INVALID_FUNCTION;
+        break;
+        
     //
     // if we get here, an invalid IoControlCode was specified.
     //
@@ -1180,6 +1245,96 @@ Return Value:
 } // VgaIsPresent()
 \f
 
+//---------------------------------------------------------------------------
+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()
+
+\f
 //---------------------------------------------------------------------------
 VP_STATUS
 VgaSetColorLookup(