KernelIoControl和OEMIoControl的分析和使用(作者:wogoyixikexie@gliet)

KernelIoControl和OEMIoControl的分析和使用(作者:wogoyixikexie@gliet)

对于KernelIoControl这个函数我们并不陌生,在2440 5.0BSP当中,这个函数在很多驱动中出现了,主要是用来申请中断,比如下面

BOOL RetVal = KernelIoControl( IOCTL_HAL_REQUEST_SYSINTR,
                                   &Irq,
                                   sizeof( Irq ),
                                   pSysIntr,
                                   sizeof( *pSysIntr ),
                                   NULL );

-------------------其实他的作用远远不止申请/释放中断那么简单,下面来看看PB的帮助文档。

This function provides the kernel with a generic I/O control for carrying out I/O operations.

BOOL KernelIoControl( DWORD dwIoControlCode,LPVOID lpInBuf,DWORD nInBufSize,LPVOID lpOutBuf,DWORD nOutBufSize,LPDWORD lpBytesReturned );

对于这个函数的参数,非常类似EVC中的DeviceIoControl,从说明可以了解参数的使用方法。

Parameters

dwIoControlCode
[in] I/O control code, which should support the OAL I/O controls. For a list of these I/O controls, see OAL IOCTLs.
lpInBuf
[out] Pointer to a buffer that contains the data required to perform the operation.

Set to NULL if the dwIoControlCode parameter specifies an operation that does not require input data.

nInBufSize
[in] Size, in bytes, of the buffer pointed to by lpInBuf.
lpOutBuf
[out] Pointer to a buffer that receives the output data for the operation.

Set to NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.

nOutBufSize
[in] Size, in bytes, of the buffer pointed to by lpOutBuf.
lpBytesReturned
[in] Long pointer to a variable that receives the size, in bytes, of the data stored in the buffer pointed to by lpOutBuf. Even when an operation produces no output data, and lpOutBuf is NULL, the KernelIoControl function uses the variable pointed to by lpBytesReturned. After such an operation, the value of the variable has no meaning.

Return Values

TRUE indicates success; FALSE indicates failure.

Remarks

The kernel calls the OEMIoControl function when a device driver or application calls the kernel function KernelIoControl and passes an I/O control code.

(当应用程序或者驱动调用KernelIoControl 的时候,KernelIoControl 就会调用OEMIoControl 去实现。)

This function is also called when the SystemParametersInfo function is called with SPI_GETOEMINFO or SPI_GETPLATFORMINFO.

The system is fully preemptible when this function is called. The kernel does no processing, but it passes all parameters directly to the function supplied by you. (当这个函数被调用的时候系统完全可能被抢占,内核没有处理,直接传递参数到你提供的函数。这个我觉得说的很别扭,估计是直接传递参数到OEMIoControl )

This function is provided solely to allow your device driver or application to communicate with an OAL and its specific functionality.

(该函数用来提供驱动/应用程序和OAL的通信)

Requirements

OS Versions: Windows CE 2.10 and later.
Header: Pkfuncs.h.(原来是个不开源的函数)
Link Library: Coredll.lib.

OEMIoControl
原文地址:https://www.cnblogs.com/gooogleman/p/1869749.html