📄 ioctl.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 OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
// File: ioctl.c
//
// This file implements the OEM's IO Control (IOCTL) functions and declares
// global variables used by the IOCTL component.
//
#include <bsp.h>
#include <partdrv.h>
#include <pcf50606.h>
#include <power_i2c.h>
//------------------------------------------------------------------------------
//
// Global: g_oalIoctlPlatformType/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 Plato platform.
// Since there is no hardware support for a reset functionality on Plato,
// Reboot is acheived by powering off the system after setting it to power
// back on 5 seconds later (using the PCF50606 RTC)
//
BOOL OALIoCtlHalReboot(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize)
{
UINT8 seconds;
UCHAR RTCRegs[7] = {0};
UCHAR RTCAlarmRegs[7] = {0};
OALMSGS(1, (TEXT("OALIoCtlHalReboot.\r\n")));
if (!PI2CInit())
{
OALMSGS(1, (TEXT("OALIoCtlHalReboot: Failed to initialize Pi2c communication.\r\n")));
return FALSE;
}
// Read the RTC seconds register first
RTCRegs[0] = ReadPI2CRegister(RTCSC);
seconds = BCDTODEC(RTCRegs[0]);
while (seconds > 54)
{
// wait 6 seconds and let the roll over happen
OALStall(6000000);
// Read RTC seconds register again to get the rolled over time.
RTCRegs[0] = ReadPI2CRegister(RTCSC);
seconds = BCDTODEC(RTCRegs[0]);
}
// Add 5 seconds to the current RTC time. This is when we want
// the RTC to issue an alarm interrupt which will power the device
// back on
seconds += 5;
RTCRegs[0] = DECTOBCD(seconds);
// Read the remaining RTC registers
RTCRegs[1] = ReadPI2CRegister(RTCMN);
RTCRegs[2] = ReadPI2CRegister(RTCHR);
RTCRegs[3] = ReadPI2CRegister(RTCWD);
RTCRegs[4] = ReadPI2CRegister(RTCDT);
RTCRegs[5] = ReadPI2CRegister(RTCMT);
RTCRegs[6] = ReadPI2CRegister(RTCYR);
// Write the adjusted time to the RTC Alarm registers
WritePI2CRegister(RTCSCA, RTCRegs[0]);
WritePI2CRegister(RTCMNA, RTCRegs[1]);
WritePI2CRegister(RTCHRA, RTCRegs[2]);
WritePI2CRegister(RTCWDA, RTCRegs[3]);
WritePI2CRegister(RTCDTA, RTCRegs[4]);
WritePI2CRegister(RTCMTA, RTCRegs[5]);
WritePI2CRegister(RTCYRA, RTCRegs[6]);
// Issue the standby command with RTC Alarm wake enabled.
// This will make the PCF50606 go to Standby mode where it will shut off
// power to the device.
WritePI2CRegister(OOCC1, OOCC1_GOSTDBY | OOCC1_RTCWAK | OOCC1_CHGWAK);
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 and 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 + -