⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddl.c

📁 此代码为WCE5.0下显示器的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
////////////////////////////////////////////////////////////////////////////////////////////
//
//  These are functions that used to be in the miniport but have 
//  now been ported to CE.
//
/////////////////////////////////////////////////////////////////////////////////////////////


#include <windows.h>
#include <ceddk.h>
#include <memory.h>
#include <string.h>
#include <Ndis.h>
 
#include "dal.h"
#include "ltcrt.h"
#include "ltlcd.h"
#include "rprocrtc.h"
#include "rprod.h"
#include "ddl.h"

#define	DRIVER_REGISTRY_STRING	(L"Drivers\\Display\\RageXL")  // also defined in ati.cpp

// Global Variables
PFNGDOENABLE pfnDisplayArray[MAX_NUMBER_DISPLAYS];
PFNGCOENABLE pfnControlArray[MAX_NUMBER_CONTROLLERS];



VOID DDLDebugPrint(ULONG ulDebugLevel, LPCHAR lpDebugMessage, ...)
{
    // Debug output is a pain in the butt in CE so we won't do it.
    return;
}


PFNGDOENABLE* DDLGetDisplayObjects(HDDL hDDL, LPULONG lpulTotalDisplayObjects)
//
//  DESCRIPTION:
//  DDLGetDisplayObjects returns an array of function pointers to the
//  GDOEnable functions of the graphics display objects.
//
//  PARAMETERS:
//  hDDL                    Points to the hardware device extension
//                          structure. This parameter is not used by the
//                          display abstraction layer, but is provided as
//                          a handle uniquely identifying the graphics
//                          adapter for device dependant layer.
//
//  lpulTotalDisplayObjects Pointer to the total number of graphics display
//                          objects.  This value corresponds directly to
//                          the number of GDOEnable function pointers in
//                          the array returned from the function.
//
//  RETURN VALUE:
//   DDLGetDisplayObjects returns an array of function pointers to the
//   GDOEnable functions of the graphics display objects available.  If the
//   function returns a NULL pointer, the DDL observed a fatal error, which
//   will prevent the system from loading successfully.
//
{
    *lpulTotalDisplayObjects = 2;

    // Since this driver is for RageXL only, just hard code the funciton pointers instead of detecting them.
    pfnDisplayArray[0] = CRTEnable;
    pfnDisplayArray[1] = LCDEnable;
    
    return (&(pfnDisplayArray[0]));

}   // DDLGetDisplayObjects()


PFNGCOENABLE*
DDLGetControllerObjects(
    HDDL hDDL,
    LPULONG lpulTotalControllerObjects
    )
//
// DESCRIPTION:
//  DDLGetControllerObjects returns an array of function pointers to the
//  GDOEnable functions of the graphics controller objects.
//
// PARAMETERS:
//  hDDL                    Points to the hardware device extension
//                          structure.  This parameter is not used by the
//                          display abstraction layer, but is provided as
//                          a handle uniquely identifying the graphics
//                          adapter for device dependant layer.
//  lpulTotalControllerObjects  Pointer to the total number of graphics controller
//                          objects.  This value corresponds directly to
//                          the number of GCOEnable function pointers in
//                          the array returned from the function.
//
// RETURN VALUE:
//  DDLGetControllerObjects returns an array of function pointers to the
//  GCOEnable functions of the graphics controller objects available.  If the
//  function returns a NULL pointer, the DDL observed a fatal error, which
//  will prevent the system from loading successfully.
//
{
    // We only return one GCO object.
    *lpulTotalControllerObjects = 1;

    // Fill in the function pointer array.
    pfnControlArray[0] = RageProEnable;

    return (&(pfnControlArray[0]));

}   // DDLGetControllerObjects()


VOID
DDLGetHwAsicID(
    HDDL hDDL,
    LPHW_ASIC_ID lpHwAsicID
    )
//
// DESCRIPTION:
//  Prints the specified debug message.
//
// PARAMETERS:
//  hDDL            Points to the hardware device extension structure.
//                  This parameter is not used by the display abstraction
//                  layer, but is provided as a handle uniquely
//                  identifying the graphics adapter for device dependant
//                  layer.
//
// RETURN VALUE:
//  HW_ASIC_ID structure which includes the ASIC ID, a pointer to IO space,
//  and a pointer to MM space.
//
{
    lpHwAsicID->ulChipFamily         = FAMILY_RAGE_XL;
    lpHwAsicID->ulChipID             = pHwDeviceExtension[gdwMMIndex]->ulConfigChipId;
    lpHwAsicID->ulVRamInstalled      = pHwDeviceExtension[gdwMMIndex]->ulVideoRamSizeInstalled;
    lpHwAsicID->lpIO                 = pHwDeviceExtension[gdwMMIndex]->pvIoBaseAddress;
    lpHwAsicID->lpMMR                = pHwDeviceExtension[gdwMMIndex]->pvAuxBaseAddress;
    lpHwAsicID->lpRomBaseAddress     = pHwDeviceExtension[gdwMMIndex]->pvRomBaseAddress;
    lpHwAsicID->lpFrameBuffer        = (LPVOID)pHwDeviceExtension[gdwMMIndex]->lfbPhysicalAddress.QuadPart;
    lpHwAsicID->ulReferenceFrequency = DDLGetReferenceFreq(hDDL);
}   // DDLGetHwAsicID()


ULONG FAR
DDLGetReferenceFreq(
    HDDL hDDL
    )
//
// DESCRIPTION:
//  Gets the reference frequency out of the BIOS tables.
//
// PARAMETERS:
//  hDDL                Points to the hardware device extension structure.
//
// RETURN VALUE:
//  Reference frequency.
//
{
    MP_BIOS_INFO_TABLE     BiosInfoTable;
    USHORT  usOffset2LpInfoTable;
    //UCHAR   ucIndex;
    ULONG   ulOffset, ulBitSignature;

    if (ReadRomImage(&usOffset2LpInfoTable,
                     BIOS_INFO_TABLE_OFFSET,
                     sizeof(USHORT)) != NO_ERROR)
    {
        goto FAIL_FREQREAD;
    }
	
    //[espiritu] EPR#38035 - Change sizeof from USHORT to ULONG to correct black screen boot in Win2K. 
    if (ReadRomImage(&ulOffset,
                     (ULONG) usOffset2LpInfoTable,
                     sizeof(ULONG)) != NO_ERROR)
    {
        goto FAIL_FREQREAD;
    }

    // This scheme to get Ref Freq is supported in the following ASIC
    ulBitSignature = RAGEXL_BIOS_INFO_TABLE_SIGNATURE;

    if (ulOffset != ulBitSignature)
    {
        return (2950); // Not the right version of bios.
                       // Hard code default reference frequence: 2950.
    }

    if (ReadRomImage(&BiosInfoTable,
                     (ULONG) usOffset2LpInfoTable,
                     sizeof(MP_BIOS_INFO_TABLE)) != NO_ERROR)
    {
        goto FAIL_FREQREAD;
    }

    return ((ULONG)BiosInfoTable.usRefFreq);

FAIL_FREQREAD:
        return (2950); // Not the right version of bios.
                       // Hard code default reference frequence: 2950.
}  // DDLGetReferenceFreq()


DWORD
ReadRomImage(
    PVOID pvDestination,
    ULONG ulRomOffset,
    ULONG ulLength
    )
//
// DESCRIPTION:
//  Searches for a specified string in the video ROM image.
//
// PARAMETERS:
//  pvDestination       Buffer in system memory to store ROM image data.
//  ulRomOffset         Offset into ROM image where we should start reading.
//  ulLength            Number of byte to copy from ROM image.
//
// RETURN VALUE:
//  NO_ERROR    OK.
//
// NOTE:
//  We have to distinguish between VGA-enabled and VGA-disabled adapters (NT 5.0 only).
//  For VGA-enabled adapters ROM image is mapped sparse on Alpha - we must use
//  VideoPortReadRegisterBufferUchar(). For VGA-disabled (NT 5.0 only) the ROM image is in
//  the system memory (mapped dense) - we must dereference pointers directly to have this
//  working on Alpha.
//
{
    MMBAREADBUFFER((PUCHAR)(pHwDeviceExtension[gdwMMIndex]->pvRomBaseAddress), ulRomOffset, pvDestination, ulLength);

    return NO_ERROR;
}   // ReadRomImage()



VOID FAR
DDLSbcToDbc(
    HDDL hDDL,
    LPUCHAR pStringName,
    LPUCHAR lpDoubleByte
    )
//
// DESCRIPTION:
//  Converts a single-byte-character into a double-byte-character.
//
// PARAMETERS:
//  hDDL                Points to the hardware device extension structure.
//
{
    ULONG  i;

    i = 0;
    while (pStringName[i] != 0)
    {
        lpDoubleByte[i<<1] = pStringName[i];
        lpDoubleByte[(i<<1)+1] = 0;
        i++;
    }
    lpDoubleByte[i<<1] = 0;
    lpDoubleByte[(i<<1)+1] = 0;
}  // DDLSbcToDbc()


BOOL
DDLGetRegistryParameters(
    HDDL hDDL,
    LPUCHAR pValueName,
    PVOID pValueData,
    PULONG pulValueLength
    )
//
// DESCRIPTION:
//  DDLGetRegistryParameters reads information from the registry in the
//  DDL specific key.
//
// PARAMETERS:
//  hDDL            Points to the hardware device extension structure.
//                  This parameter is not used by the display abstraction
//                  layer, but is provided as a handle uniquely
//                  identifying the graphics adapter for device dependant
//                  layer.
//  pValueName      Points to a buffer containing a zero-terminated Unicode
//                  string that names the value entry for which data is
//                  being read from the registry.
//  pValueData      Points to a buffer to receive the values from the
//                  registry for the pValueName entry.
//  pulValueLength  Points to the size of the pValueData buffer on input,
//                  and returns the size of the data in pValueData.
//
// RETURN VALUE:
//  The return value is TRUE if the was read from the registry successfully
//  and sufficient buffer space was available in pValueData to return the
//  key value.
//  Otherwise it is FALSE.
//
{
    HKEY hkGDI = NULL;
    DWORD dwSize, dwVal;
    DWORD dwStatus, dwType;
    WCHAR aucDoubleByte[256];

    
    DDLSbcToDbc(hDDL, pValueName, (LPUCHAR)aucDoubleByte);

    dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, DRIVER_REGISTRY_STRING,
                                              0, 0, &hkGDI);
    if (dwStatus != ERROR_SUCCESS)
    {
        hkGDI = NULL;
        return FALSE;
    }
    else
    {
        dwSize = sizeof(DWORD);
        dwStatus = RegQueryValueEx(hkGDI, (PWSTR)aucDoubleByte, NULL, &dwType,
                                                  (LPBYTE)&dwVal, &dwSize);
        if (dwStatus == ERROR_SUCCESS)
        {
            *((LPBYTE)pValueData) = (BYTE)dwVal;
            pulValueLength = &dwSize;
            RegCloseKey(hkGDI);
            return TRUE;
        }
        else
        {
            RegCloseKey(hkGDI);
            return FALSE;
        }
    }
    
}   // DDLGetRegistryParameters()


BOOL
DDLSetRegistryParameters(
    HDDL hDDL,
    LPUCHAR pValueName,
    PVOID pValueData,
    ULONG ulValueLength)
//
// DESCRIPTION:
//  DDLSetRegistryParameters writes information to the registry in the
//  DDL specific key.
//
// PARAMETERS:
//  hDDL            Points to the hardware device extension structure.
//                  This parameter is not used by the display abstraction
//                  layer, but is provided as a handle uniquely
//                  identifying the graphics adapter for device dependant
//                  layer.
//  pValueName      Points to a buffer containing a zero-terminated Unicode
//                  string that names the value entry for which data is
//                  being read from the registry.
//  pValueData      Points to a buffer containing the values to be written
//                  for the pValueName entry.
//  pValueLength    Points to the size of the data to be written to the
//                  registry.
//
// RETURN VALUE:
//  The return value is TRUE if the was data was written to the registry

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -