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

📄 ioctl.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File: ioctl.c           
//
//  This file implements the OEM's IO Control (IOCTL) functions and declares
//  global variables used by the IOCTL component.
//
#include <partdrv.h>
#include <bsp.h>

#ifdef USING_XSCALEBROWSER
#include <xdbioctl.h>
#endif

#ifdef USING_PMU
#include <pmuioctl.h>
#endif

//------------------------------------------------------------------------------
//
//  Global: g_oalIoctlPlatform/Type/OEM    
//
//  Platform Type/OEM
//
LPCWSTR g_oalIoCtlPlatformType = IOCTL_PLATFORM_TYPE;
LPCWSTR g_oalIoCtlPlatformOEM  = IOCTL_PLATFORM_OEM;

//------------------------------------------------------------------------------
//
//  Global: g_oalIoctlProcessorVendor/Name/Core
//
//  Processor information
//
LPCWSTR g_oalIoCtlProcessorVendor = IOCTL_PROCESSOR_VENDOR;
LPCWSTR g_oalIoCtlProcessorName   = IOCTL_PROCESSOR_NAME;
LPCWSTR g_oalIoCtlProcessorCore   = IOCTL_PROCESSOR_CORE;

//------------------------------------------------------------------------------
//
//  Global: g_oalIoctlInstructionSet
//
//  Processor instruction set identifier
//
UINT32 g_oalIoCtlInstructionSet = IOCTL_PROCESSOR_INSTRUCTION_SET;
UINT32 g_oalIoCtlClockSpeed     = IOCTL_PROCESSOR_CLOCK_SPEED;

//------------------------------------------------------------------------------
//
//  External: ARMCacheInfo
//
//  Processor cache information structure
//
extern const CacheInfo ARMCacheInfo;

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalGetCacheInfo
//
//  This function returns information about the CPU's instruction and data caches.
//
BOOL OALIoCtlHalGetCacheInfo(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
    UINT32 outSize, UINT32 *pOutSize)
{

    // Validate caller's arguments.
    //
    if (!pOutBuffer || (outSize < sizeof(CacheInfo)))
    {
        NKSetLastError(ERROR_INSUFFICIENT_BUFFER);
        return(FALSE);
    }

    // Copy the cache information into the caller's buffer.
    //
    memcpy(pOutBuffer, &ARMCacheInfo, sizeof(CacheInfo));
    if (pOutSize) *pOutSize = sizeof(CacheInfo);

    return(TRUE);
}

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalPostInit
//
//  This function is the next OAL routine called by the kernel after OEMInit and
//  provides a context for initializing other aspects of the device prior to
//  general boot.
//
BOOL OALIoCtlHalPostInit(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
    UINT32 outSize, UINT32 *pOutSize)
{
    
    // Do nothing for now.
    //
    return(TRUE);

}


//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalReboot
//
//  This function hardware-reboots the MainstoneII platform.
//
BOOL OALIoCtlHalReboot(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
    UINT32 outSize, UINT32 *pOutSize)
{
//    volatile MAINSTONEII_BLR_REGS *pBLRegs = (volatile MAINSTONEII_BLR_REGS *) OALPAtoVA(MAINSTONEII_BASE_REG_PA_FPGA, FALSE);    

    // For now, perform a hard reset - write to the FPGA system reset bit.
    while(TRUE)
    {
//        pBLRegs->misc_wr = 1;
    }

    return(TRUE);

}


//------------------------------------------------------------------------------
//

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalGetHiveCleanFlag
//
//  This function is used by Filesys.exe to query the OEM to determine if the registry hives
//  and user profiles should be deleted and recreated.
//
//  Notes: During a OS start up, Filesys.exe calls HIVECLEANFLAG_SYSTEM twice and followed by
//  HIVECLEANFLAG_USER. We'll clear the shared Args flag after that.
//
static BOOL OALIoCtlHalGetHiveCleanFlag(
    UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
    UINT32 nOutBufSize, UINT32 *pOutSize)
{
    BOOL bRet = FALSE;

    OALMSG(OAL_FUNC, (TEXT("OALIoCtlHalGetHiveCleanFlag\r\n")));

    if (!lpInBuf || (nInBufSize != sizeof(DWORD))
        || !lpOutBuf || (nOutBufSize != sizeof(BOOL)))
    {
      return FALSE;
    }
    else
    {
      DWORD *pdwFlags = (DWORD*)lpInBuf;
      BOOL  *pfClean  = (BOOL*)lpOutBuf;

      // This is the global shared Args flag
      BOOL *bHiveCleanFlag = (BOOL*) OALArgsQuery(BSP_ARGS_QUERY_HIVECLEAN);

      *pfClean = *bHiveCleanFlag;
      bRet = *bHiveCleanFlag;

      if (*pdwFlags == HIVECLEANFLAG_SYSTEM)
      {
        if(bRet)
        {
          OALMSG(1, (TEXT("OEM: Cleaning system hive\r\n")));
        }
        else
        {
          OALMSG(1, (TEXT("OEM: Not cleaning system hive\r\n")));
        }
      }
      else if (*pdwFlags == HIVECLEANFLAG_USERS)
      {
        if(bRet)
        {
          OALMSG(1, (TEXT("OEM: Cleaning user profiles\r\n")));
	}
        else
        {
          OALMSG(1, (TEXT("OEM: Not cleaning user profiles\r\n")));
        }

        // We are done checking HiveCleanFlag by now (system hive is checked before user hive).
        // Now is the time to clear the global shared Args flag if it is set by switch or software.
        *bHiveCleanFlag = FALSE;
      }
      else
      {
        OALMSG(OAL_ERROR, (TEXT("OEM: Unknown flag 0x%x\r\n"), *pdwFlags));
      }
    }

    return(bRet);
}



//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalGetHWEntropy
//
//  This function retrieves a 64-bit random number based upon an OEM-defined device hardware identifier.
//
static BOOL OALIoCtlHalGetHWEntropy(
    UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
    UINT32 nOutBufSize, UINT32 *pOutSize)
{
    if (lpInBuf || nInBufSize || !lpOutBuf || (nOutBufSize < 8)) {
      return (FALSE);
    }

    // use Ethnet MAC address as the unique number.
    {
      OAL_KITL_ARGS *pKITLArgs;
      UCHAR *cp = lpOutBuf;

      pKITLArgs   = (OAL_KITL_ARGS*) OALArgsQuery(OAL_ARGS_QUERY_KITL);

      memcpy(cp, "MS", 2);
      memcpy(cp+2, pKITLArgs->mac, 6);

      if(pOutSize)
      {
          *pOutSize = 8;
      }

      OALMSG(OAL_FUNC, (TEXT("OALIoCtlHalGetHWEntropy: %02x %02x %02x %02x %02x %02x %02x %02x\r\n"),
                 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]));

      return (TRUE);
    }
}

//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalGetImageSignedState
//
//
static BOOL OALIoCtlHalGetImageSignedState(
    UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
    UINT32 nOutBufSize, UINT32 *pOutSize)
{
    OALMSG(OAL_FUNC, (TEXT("OALIoCtlHalGetImageSignedState\r\n")));

    if (!lpInBuf || !nInBufSize
        || lpOutBuf || (nOutBufSize < sizeof(UINT32)))
    {
      return FALSE;
    }
    else
    {
      UINT32 *pState = (UINT32*) lpOutBuf;

      // This is the global shared Args flag
      UINT32 *pSignedState = (UINT32*) OALArgsQuery(BSP_ARGS_QUERY_SIGNEDSTATE);

      *pState = *pSignedState;

      OALMSG(1, (TEXT("OEM: Image signed state: %d\r\n"), *pState));
    }

    if(pOutSize)
    {
      *pOutSize = sizeof(UINT32);
    }

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalQueryFormatPartition
//
//  This function is called by Filesys.exe to allow an OEM to specify whether a specific
//  partition is to be formatted on mount. Before Filesys.exe calls this IOCTL, it checks
//  the CheckForFormat registry value in the storage profile for your block driver.
//
static BOOL OALIoCtlHalQueryFormatPartition(
    UINT32 code, VOID *lpInBuf, UINT32 nInBufSize, VOID *lpOutBuf,
    UINT32 nOutBufSize, UINT32 *pOutSize)
{
    OALMSG(OAL_FUNC, (TEXT("OALIoCtlHalFormatPartition\r\n")));

    if (!lpInBuf || (nInBufSize != sizeof(STORAGECONTEXT))
        || !lpOutBuf || (nOutBufSize < sizeof(BOOL)))
    {
      return FALSE;
    }
    else
    {
      STORAGECONTEXT *pStore = (STORAGECONTEXT *)lpInBuf;
      BOOL  *pfClean = (BOOL*)lpOutBuf;

      // This is the global shared Args flag
      BOOL *bFormatPartFlag = (BOOL*) OALArgsQuery(BSP_ARGS_QUERY_FORMATPART);

      OALMSG(OAL_VERBOSE, (TEXT("Store partition info:\r\n")));
      OALMSG(OAL_VERBOSE, (TEXT("\tszPartitionName=%s\r\n"), pStore->PartInfo.szPartitionName));
      OALMSG(OAL_VERBOSE, (TEXT("\tsnNumSectors=%d\r\n"), pStore->PartInfo.snNumSectors));
      OALMSG(OAL_VERBOSE, (TEXT("\tdwAttributes=0x%x\r\n"), pStore->PartInfo.dwAttributes));
      OALMSG(OAL_VERBOSE, (TEXT("\tbPartType=0x%x\r\n"), pStore->PartInfo.bPartType));

      // Set return value
      *pfClean = *bFormatPartFlag;

      // Clear the flag so that we don't do it again in next boot unless it is set again.
      *bFormatPartFlag = FALSE;

      if(*pfClean)
      {
        if(pStore->dwFlags & AFS_FLAG_BOOTABLE) 
        {
          OALMSG(1, (TEXT("OEM: Clearing storage registry hive\r\n")));
        }
        else
        {
          OALMSG(1, (TEXT("OEM: Clearing storage\r\n")));
        }
      }
      else
      {
        OALMSG(1, (TEXT("OEM: Not clearing storage\r\n")));
      }
    }

    if(pOutSize)
    {
      *pOutSize = sizeof(UINT32);
    }

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Global: g_oalIoCtlTable[]    
//
//  IOCTL handler table. This table includes the IOCTL code/handler pairs  
//  defined in the IOCTL configuration file. This global array is exported 
//  via oal_ioctl.h and is used by the OAL IOCTL component.
//
const OAL_IOCTL_HANDLER g_oalIoCtlTable[] = {
#include "ioctl_tab.h"
};

//------------------------------------------------------------------------------


⌨️ 快捷键说明

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