内核关键函数KernelIoControl分析-非常好,很详细

ARM DSU(DynamIQ Shared Unit)概述 DSU (DynamIQ Shared Unit)的组成和功能:DSU 包括 L3 内存系统、控制逻辑和外部接口,用于支持 DynamIQ集群。DynamIQ集群微体系结构整合了一个或多个核心与 DSU,形成一个的集群。在宏单元实施过程中,可以core。 阅读详情

KernelIoControl和OEMIoControl的分析和使用


作者:wogoyixikexie@gliet 2008-12-18

 

    对于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 这个函数============================

C:/WINCE500/PLATFORM/COMMON/SRC/COMMON/IOCTL/ioctl.c(45)://  Function:  OEMIoControl

//  File:  ioctl.c
//
//  File implements OEMIoControl function.
//
#include <windows.h>
#include <oal.h>   //这个很关键,不然oal_ioctl_tab.h设置就没有办法传递进来。

//------------------------------------------------------------------------------
//
//  Global:  g_ioctlState;
//
//  This state variable contains critical section used to serialize IOCTL
//  calls.
//
static struct {
    BOOL postInit;
    CRITICAL_SECTION cs;
} g_ioctlState = { FALSE };

//------------------------------------------------------------------------------
//
//  Include: intioctl.c
//
//  This include file is used to add internal testing IOCTL hadlers.
//
#ifdef OAL_HAL_INTERNAL_TESTING
#include "intioctl.c"
#endif


//------------------------------------------------------------------------------
//
//  Function:  OEMIoControl
//
//  The function is called by kernel a device driver or application calls 
//  KernelIoControl. The system is fully preemtible when this function is 
//  called. The kernel does no processing of this API. It is provided to 
//  allow an OEM device driver to communicate with kernel mode code.
//
BOOL OEMIoControl(
    DWORD code, VOID *pInBuffer, DWORD inSize, VOID *pOutBuffer, DWORD outSize,
    DWORD *pOutSize
) {
    BOOL rc = FALSE;
    UINT32 i;

    OALMSG(OAL_IOCTL&&OAL_FUNC, (
        L"+OEMIoControl(0x%x, 0x%x, %d, 0x%x, %d, 0x%x)/r/n", 
        code, pInBuffer, inSize, pOutBuffer, outSize, pOutSize
    ));

    // Search the IOCTL table for the requested code.
    for (i = 0; g_oalIoCtlTable.pfnHandler != NULL; i++) {
        if (g_oalIoCtlTable.code == code) break;
    }

    // Indicate unsupported code
    if (g_oalIoCtlTable.pfnHandler == NULL) {
#ifdef OAL_HAL_INTERNAL_TESTING
        rc = InternalHalTesting(
            code, pInBuffer, inSize, pOutBuffer, outSize, pOutSize
        );
#else
        NKSetLastError(ERROR_NOT_SUPPORTED);
        OALMSG(OAL_WARN, (
            L"OEMIoControl: Unsupported Code 0x%x - device 0x%04x func %d/r/n", 
            code, code >> 16, (code >> 2)
        ));
#endif
        goto cleanUp;
    }        

    // Take critical section if required (after postinit & no flag)
    if (
        g_ioctlState.postInit && 
        (g_oalIoCtlTable.flags & OAL_IOCTL_FLAG_NOCS) == 0
    ) {
        // Take critical section            
        EnterCriticalSection(&g_ioctlState.cs);
    }

    // Execute the handler 调用函数指针,用来实现相应功能
    rc = g_oalIoCtlTable.pfnHandler(
        code, pInBuffer, inSize, pOutBuffer, outSize, pOutSize
    );

    // Release critical section if it was taken above
    if (
        g_ioctlState.postInit && 
        (g_oalIoCtlTable.flags & OAL_IOCTL_FLAG_NOCS) == 0
    ) {
        // Take critical section            
        LeaveCriticalSection(&g_ioctlState.cs);
    } else if (!g_ioctlState.postInit && code == IOCTL_HAL_POSTINIT) {
        // Initialize critical section
        InitializeCriticalSection(&g_ioctlState.cs);
        g_ioctlState.postInit = TRUE;
    }                

cleanUp:
    OALMSG(OAL_IOCTL&&OAL_FUNC, (L"-OEMIoControl(rc = %d)/r/n", rc ));
    return rc;
}

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

——再来看oal_ioctl.h

//------------------------------------------------------------------------------
//
//  File:  oal_ioctl.h
//
//  This header file defines IO Control OAL module. This module implements
//  OEMIoControl function which is used to call kernel functions from user
//  space.
//
#ifndef __OAL_IOCTL_H
#define __OAL_IOCTL_H

#if __cplusplus
extern "C" {
#endif

//------------------------------------------------------------------------------
//
//  Definition: OAL_IOCTL_FLAG_xxx
//
//  This definition specifies flag codes for IOCTL table. When NOCS flag is
//  set handler function will be called in deserialized mode (so no critical
//  section will be taken/release before/after handler is called).
//
#define OAL_IOCTL_FLAG_NOCS     (1 << 0)

//------------------------------------------------------------------------------
//
//  Type: IOCTL_HANDLER    
//
//  This type defines the procedure to be called for an IOCTL code. The
//  global g_oalIoctlTable is an array of these types.
//
typedef struct {
    UINT32  code;
    UINT32  flags;
    BOOL    (*pfnHandler)(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
} OAL_IOCTL_HANDLER, *POAL_IOCTL_HANDLER;

//------------------------------------------------------------------------------
//
//  Extern: g_oalIoCtlPlatformType/OEM
//
//  Platform Type/OEM
//
extern LPCWSTR g_oalIoCtlPlatformType;
extern LPCWSTR g_oalIoCtlPlatformOEM;

//------------------------------------------------------------------------------
//
//  Global: g_oalIoCtlProcessorVendor/Name/Core
//
//  Processor information
//
extern LPCWSTR g_oalIoCtlProcessorVendor;
extern LPCWSTR g_oalIoCtlProcessorName;
extern LPCWSTR g_oalIoCtlProcessorCore;

//------------------------------------------------------------------------------
//
//  Global:  g_oalIoCtlInstructionSet/g_oalIoCtlClockSpeed
//
//  Processor instruction set identifier and clock speed
//

extern UINT32 g_oalIoCtlInstructionSet;
extern UINT32 g_oalIoCtlClockSpeed;

//------------------------------------------------------------------------------
//
//  Globaal:  g_oalIoctlTable
//
//  This extern references the global IOCTL table that is defined in
//  the platform code.
//
extern const OAL_IOCTL_HANDLER g_oalIoCtlTable[];

//------------------------------------------------------------------------------
//
//  Function: OALIoCtlXxx
//
//  This functions implement basic IOCTL code handlers.
//  这些函数在哪里实现的呢?功能好强大
BOOL OALIoCtlHalGetDeviceId(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
BOOL OALIoCtlHalGetDeviceInfo(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
BOOL OALIoCtlProcessorInfo(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
BOOL OALIoCtlHalInitRegistry(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
BOOL OALIoCtlHalReboot(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);
BOOL OALIoCtlHalGetUUID (UINT32, VOID *, UINT32, VOID *, UINT32, UINT32 *);

//------------------------------------------------------------------------------
//
//  Function: OALIoCtlHalDDIXxx
//
//  This functions implement IOCTL code handler used by HAL flat display
//  driver.
//
BOOL OALIoCtlHalDDI(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*);

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


#if __cplusplus
}
#endif

#endif // __OAL_IOCTL_H
    再看oal_ioctl_tab.h

//------------------------------------------------------------------------------
//  这个头文件很关键,只要在这里填入相应的IOCTL_XXXXX以及相应的函数
// (在别的地方实现这个函数)就大功告成了。
//  File:  oal_ioctl_tab.h
//
//  This file contains part of global IOCTL handler table for codes which
//  must (or should) be implemented on all platforms. Table in platform
//  will usually include this file.
//
//  This file is included by the platform's IOCTL table, g_oalIoCtlTable[].
//  Therefore, this file may ONLY define OAL_IOCTL_HANDLER entries. 
//
// IOCTL CODE,                          Flags   Handler Function
//------------------------------------------------------------------------------

{ IOCTL_HAL_TRANSLATE_IRQ,                  0,  OALIoCtlHalRequestSysIntr   },
{ IOCTL_HAL_REQUEST_SYSINTR,                0,  OALIoCtlHalRequestSysIntr   },
{ IOCTL_HAL_RELEASE_SYSINTR,                0,  OALIoCtlHalReleaseSysIntr   },
{ IOCTL_HAL_REQUEST_IRQ,                    0,  OALIoCtlHalRequestIrq       },

{ IOCTL_HAL_INITREGISTRY,                   0,  OALIoCtlHalInitRegistry     },
{ IOCTL_HAL_INIT_RTC,                       0,  OALIoCtlHalInitRTC          },
{ IOCTL_HAL_REBOOT,                         0,  OALIoCtlHalReboot           },

{ IOCTL_HAL_DDK_CALL,                       0,  OALIoCtlHalDdkCall          },

{ IOCTL_HAL_DISABLE_WAKE,                   0,  OALIoCtlHalDisableWake      },
{ IOCTL_HAL_ENABLE_WAKE,                    0,  OALIoCtlHalEnableWake       },
{ IOCTL_HAL_GET_WAKE_SOURCE,                0,  OALIoCtlHalGetWakeSource    },

{ IOCTL_HAL_GET_CACHE_INFO,                 0,  OALIoCtlHalGetCacheInfo     },
{ IOCTL_HAL_GET_DEVICEID,                   0,  OALIoCtlHalGetDeviceId      },
{ IOCTL_HAL_GET_DEVICE_INFO,                0,  OALIoCtlHalGetDeviceInfo    },
{ IOCTL_HAL_GET_UUID,                       0,  OALIoCtlHalGetUUID          },
{ IOCTL_PROCESSOR_INFORMATION,              0,  OALIoCtlProcessorInfo       },

{ IOCTL_VBRIDGE_802_3_MULTICAST_LIST,       0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_ADD_MAC,                    0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_CURRENT_PACKET_FILTER,      0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_GET_ETHERNET_MAC,           0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_GET_RX_PACKET,              0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_GET_RX_PACKET_COMPLETE,     0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_GET_TX_PACKET,              0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_GET_TX_PACKET_COMPLETE,     0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_SHARED_ETHERNET,            0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_WILD_CARD,                  0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_WILD_CARD_RESET_BUFFER,     0,  OALIoCtlVBridge             },
{ IOCTL_VBRIDGE_WILD_CARD_VB_INITIALIZED,   0,  OALIoCtlVBridge             },

在初始化阶段内核就会调用KernelIoControl来和OAL通信,其实就是通过调用KernelIoControl来执行OEMIoControl

很神奇吧。申请中断什么的,都在这里弄好了。牛B!

==============================例子:重启

如何在程序中关闭、重起和硬起动Pocket PC?

--------------------------------------------------------------------------------

时间:2003-2-28 18:18:44 来源:BIPLIP.com 作者:Daric 阅读210次


关闭(suspend)
方法1:
//虚拟关机键
::keybd_event(VK_OFF, 0, 0, 0);
::keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);
方法2:
//调用未公开函数PowerOffSystem()
extern "C" __declspec(dllimport) void PowerOffSystem();
重起(soft reset)
//Soft reset the device
#include
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
extern "C" __declspec(dllimport) BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned);
BOOL ResetPocketPC()
{
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
硬起动(hard reset)
//注意!!!使用此段代码会将您的Pocket PC的用户数据全部清空,
//请勿非法使用,用者后果自负.
#include
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
extern "C" __declspec(dllimport)void SetCleanRebootFlag(void);
extern "C" __declspec(dllimport) BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned);
BOOL HardResetPocketPC()
{
SetCleanRebootFlag();
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}


【OpenVINO】在 Intel Ultra AI PC 设备上使用 OpenVINO C# API本地部署YOLOv11与YOLOv12 将使用英特尔® 酷睿 Ultra 处理器AI PC设备,结合OpenVINO C# API 使用最新发布的OpenVINO 2025.0 部署YOLOv11 和 YOLOv12 目标检测模型,并在AIPC设备上,进行速度测试。 阅读详情

相关推荐

Ubuntu系统中基于Docker的OpenVINO开发环境搭建指南

概要 OpenVINO是英特尔推出的一套免费的开发套件,旨在帮助开发者和数据科学家们加速他们在视觉计算以及深度学习的推理和部署方面的工作。OpenVINO通过异构计算可以充分发挥英特尔硬件平台(包括CPU,GPU,Intel® FPGA以及Intel® Movidius VPU)的强大性能,在深度学习推理方面可以带来多大19倍的性能提升。OpenVINO自带的推理引擎(IE)通过一套统一的...

weixin_43841298的博客 2829

【西窗】2019杭州交通限行规定(最新地图详情)

版本日期 1.0.20190517 ▶杭州市的交通限行规定比较复杂,网上现存的许多内都是东拼西凑的,质量很低,甚至会出现错误。于是我就自己写了这篇文章,希望能帮到大家。 ▶简而言之,杭州市的限行规定,是由以下三个部分(原则)组成的: ▼1 最新杭州市工作日“错峰限行”的规定(本地[浙A]牌照) (可点击放大看高清图) ▼限行车辆 ▷[浙A]普通牌照车辆(含个性化牌照与临时牌照) ▷[浙A]新能源...

思律效容 Silvxr 1万+

1788445834680.apk

1788445834680.apk

外星人笔记本自带壁纸_科普丨AlienFX?外星人定制灯,你的情绪担当

“游戏过程中灯有那么重要吗?”“操作能力明明比那些魔幻跑马灯更有意义!“经常出现这一类的疑问而灯作为游戏中最有感染力的部分之一它的视觉冲击与沉浸感更是有着举足轻重的地位想来一场超燃超畅爽的厮杀和游戏深度联动怎么能少了灯的联动?点击图片开启AlienFX外星人定制灯纵观整个“灯届”,AlienFX外星人定制灯在许多玩家心中是荣誉殿堂般的存在,有了它就可以让ALIENWARE的主机、显...

weixin_39679091的博客 4208

【OpenVINO】在C#中使用 OpenVINO 部署 YOLOv10 模型实现目标

最近YOLO家族又添新成员:YOLOv10,YOLOv10 提出了一种一致的双任务方法,用于无nms训练的YOLOs,它同时带来了具有竞争力的性能和较低的推理延迟。此外,还介绍了整体率-精度驱动的模型设计策略,从率和精度两个角度对YOLOs的各个组成部分进行了全面优化,大大降低了计算开销,增强了性能。在本文中,我们将结合OpenVINO C# API 使用最新发布的OpenVINO 2024.1部署YOLOv10 目标检测模型

grape_yan的博客 2548

索尼 toio 应用创意开发征文|toio儿童互动企鹅小游戏

我是一个父亲,我认为利用toio 核心 Q 宝可以设计一款小企鹅儿童玩具,小企鹅儿童玩具可以通过孩子的说话指令进行移动、发出叫声,并且可以利用toio 的灯光来改变小企鹅的表情颜色锻炼孩子的专注力,还可以使用Python来编写代码,控制小企鹅移动的速度和发声的频率,实现个性化的创作体验,我希望为我的孩子设置独一无二的游戏体验。

阿Q的小窝 4752

部署到 Adreno GPU

​Adreno 是由高通开发并用于许多 SoC 的图形处理单元(GPU)半导体 IP 核系列。Adreno GPU 可以加速复杂几何图形的渲染,在提供高性能图形和丰富的用户体验的同时拥有很低的功耗。TVM 使用 TVM 的原生 OpenCL 后端 和 OpenCLML 后端以支持加速 Adreno GPU 上的深度学习。TVM 的原生 OpenCL 后端通过结合纹理内存使用和 Adreno 友好布局来改进 Adreno

HyperAI超神经 1334

Intel OpenVINO 携手ComfyUI提升AI创作

Intel OpenVINO工具套件(https://openvino.ai/)以其在Intel硬件上优化和部署AI模型的能力而闻名,近日与AI工作流平台ComfyUI  (https://www.comfy.org/ )达成合作:通过最近合并的OpenVINO node拉取请求(PR),将OpenVINO的强大功能集成到ComfyUI中,为使用Intel硬件的创作者带来了显著的工作率提升。

英特尔开发人员专区 2304

Semtech ClearEdge technology的理解

EML(External Cavity Laser)外腔激光DML(Distributed Feedback Laser)分布式反馈激光EML激光器,即光电调制激光器,其工作原理基于光电应。通过在半导体材料上施加电压来调制激光的振幅和相位,从而实现高速光调制。EML激光器具有高速、高率、低噪声等优点,在光纤通信、光学成像、光学传感等领域有着广泛的应用。**DML激光器,即直接调制激光器,其工作原理是基于半导体材料中的载流子浓度变化来调制激光的振幅和相位。

卤煮小鱼的博客 1864

双立柱油脂加注机.rar

双立柱油脂加注机.rar

食品包装礼品包装设备.rar

食品包装礼品包装设备.rar

全自动iphone贴膜机3.rar

全自动iphone贴膜机3.rar

运动员运动表现纵向数据集

纵向运动员运动表现数据集包含250名运动员10000条训练会话重复观测记录,涵盖篮球、排球、足球、跑步、游泳和无损伤跑步者六个运动类别。包括速度、加速度、反应时间、准确性、耐力、力量、敏捷性等表现变量,以及训练负荷、疲劳、恢复和训练成指标。用于研究和实验分析。

曲轴箱加工专机.rar

曲轴箱加工专机.rar

MATLAB中读写Zarr文件的接口。Zarr是一种用于科学数据的文件格式(类似于HDF5和netCDF),在云存储和并行计算环境中进行了优化.rar

MATLAB中读写Zarr文件的接口。Zarr是一种用于科学数据的文件格式(类似于HDF5和netCDF),在云存储和并行计算环境中进行了优化.rar

YOLO算法人像特写场景手势目标检测数据集-106张-包含 VOC 和 Yolo 格式标签-支持多种算法训练模型.zip

下拉可见数据集可视化果示意。 YOLO人像特写场景手势目标检测数据集 目标类别:['peace', 'shaka', 'thumbsup'] 中文类别:['和平手势', '夏威夷手势', '竖起大拇指'] 训练集:79 张 验证集:16 张 测试集:11 张 总计:106 张 该数据集提供了data.yaml文件,内如下: train: ../train/images val: ../valid/images test: ../test/images nc: 3 names: ['peace', 'shaka', 'thumbsup']

切线机.rar

切线机.rar

上一篇: platform builder的Catalog中项目前的符号的意义解读
下一篇: input 输入子系统架构-非常好了
linucos
博客等级 码龄17年 38粉丝 43原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值