vdev_register_factory()

https://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.hypervisor.vdev.api/topic/vdev_register_factory.html

如 qnx 官网资料介绍,vdev_register_factory() 方法将 vdev 工厂添加到可用的vdevs 工厂列表中.

#include <qvm/vdev-core.h>void vdev_register_factory(struct vdev_factory *factory,unsigned abi_version)参数:
factoryThe virtual device factory structure to be added. This structure must have a static lifetime. abi_versionThe ABI version, checked against QVM_VDEV_ABI. 

该函数通常由构造 vdev 的例程调用,通常在vdev由带有__attribute__((constructor))的函数加载时调用。

当您调用这个函数时,您将一个指针传递给 vdev_factory 结构。在 vdev 的生命周期中,这是惟一一次传递这个指针。

vdev_factory

#include <qvm/vdev-core.h>struct vdev_factory {struct vdev_factory* next;int (*control)(vdev_t *vdev, unsigned ctrl, const char *arg);enum vdev_ref_status (*vread)(vdev_t *vdev, unsigned cookie, const struct qvm_state_block *vopnd,const struct qvm_state_block *oopnd,struct guest_cpu *gcp);enum vdev_ref_status (*vwrite)(vdev_t *vdev, unsigned cookie, const struct qvm_state_block *vopnd,const struct qvm_state_block *oopnd,struct guest_cpu *gcp);int (*pulse)(vdev_t *vdev, int8_t code);void (*timer)(vdev_t *vdev, void *data,const struct guest_timer_data *tdp, struct guest_cpu *gcp);const struct vdev_pic_functions* pic;const char *const * option_list;const char* name;unsigned factory_flags;unsigned acc_sizes;unsigned extra_space;unsigned safety;
} ;Data:struct vdev_factory* nextA pointer to next entry in a linked list of structures Initialized by qvm.
int (*control)(vdev_t *vdev, unsigned ctrl, const char *arg)Required function to perform various operations on the vdev (see VDEV_CTRL_* macros)
enum vdev_ref_status (*vread)(vdev_t *vdev, unsigned cookie, const struct qvm_state_block *vopnd, const struct qvm_state_block *oopnd, struct guest_cpu *gcp)Optional function to handle a read from the vdev. If you don't handle this request, behavior is as specified by the unsupported option in the VM configuration (see the unsupported option in the QHS 2.0 User's Guide).
enum vdev_ref_status (*vwrite)(vdev_t *vdev, unsigned cookie, const struct qvm_state_block *vopnd, const struct qvm_state_block *oopnd, struct guest_cpu *gcp)Optional function to handle a write to the vdev. If you don't handle this request, behavior is as specified by the unsupported option in the VM configuration (see the unsupported option in the QHS 2.0 User's Guide).
int (*pulse)(vdev_t *vdev, int8_t code)Optional function to handle a pulse delivery for the vdev. Optional: if you send pulse to yourself, you need this vdev, or you'll get a crash.
void (*timer)(vdev_t *vdev, void *data, const struct guest_timer_data *tdp, struct guest_cpu *gcp)Optional function to handle a timer or trigger notification for the vdev. If you use guest_timer_notify(), you need this, or you'll get a crash.
const struct vdev_pic_functions* picPIC-specific operations. See vdev_pic_functions.
const char *const * option_listA pointer to an array of vdev-specific options (Optional: VDEV_CTRL_FIRST_OPTIDX).
const char* nameThe name of the vdev type. If NULL, the name is filled in with the name of the shared object the factory is in. This should typically be NULL. The qvm process adds the vdev- prefix and the .so suffix.
unsigned factory_flagsBit set of vdev_factory_flags values to control parsing and creation of the device. See above.
unsigned acc_sizesBit set of (1u << byte_size) values for a list of allowed access sizes.
unsigned extra_spaceThe number of additional bytes to allocate in the vdev_s structure for the device-specific state. A pointer to that space is stored in the vdev_s structure's v_device member.
unsigned safetySpecify if this is the safety version of the vdev; if this is the safety version, you should use VDEV_SAFETY_SELECTED.

vdev 驱动例子

其中 "__attribute__((constructor))" ,这个扩展和C++的构造函数很像,它会在main函数之前由程序加载器自动调用,与之相对的是destructor,它会在main函数执行结束或者exit的时候自动调用,由于两个扩展是一对。

它有如下规则

  • 构造函数先于main函数而执行
  • 不同构造函数如果在同一个文件中,则先出现的函数后执行
  • 对于不同文件中的构造函数,编译命令中后出现的.c文件的构造函数先执行

vdev_factory 对应的成员变量,如函数指针要自行进行实现。

static void __attribute__((constructor)) vio_i2c_register(void)
{static const char * const vio_i2c_options[] = { "verbose", "device", NULL };static struct vdev_factory vio_i2c_factory = {.next = NULL, // patched.control = vio_i2c_control,.vread = vio_i2c_vread,.vwrite = vio_i2c_vwrite,.option_list = vio_i2c_options,.name = NULL, // patched.factory_flags = VFF_NONE,.acc_sizes = 1u << sizeof(uint32_t),.extra_space = sizeof(vio_i2c_dev_t),.safety = VDEV_SAFETY_SELECTED,};vdev_register_factory(&vio_i2c_factory, QVM_VDEV_ABI);
}

QNX vdev 创建驱动程序流程相关推荐

  1. 【JVM】Java对象创建的流程步骤

    · 本文摘要 · 罗列Java创建对象的各种方式: · 讲解Java对象创建的流程步骤: 一.Java创建对象的各种方式 · 1. 用关键字new,老少皆知的方法:StringBuffer sb = ...

  2. Perforce使用之创建DEPOT流程

    Perforce 创建Depot流程 1.  创建Depot存储目录 #mkdir newdepot <?xml:namespace prefix = v ns = "urn:sche ...

  3. 2018-04-07进程创建学习流程

    进程创建的流程学习博客 http://gityuan.com/2016/03/26/app-process-create/ 转载于:https://www.cnblogs.com/buder-cp/p ...

  4. SylixOS线程创建的流程分析

    概述 本文档的主要内容是分析SylixOS线程创建的流程,详细介绍了SylixOS的线程创建函数API_ThreadCreate. 环境和参数检查 在SylixOS中,线程的创建函数不能在中断中调用. ...

  5. 【高级PDF库】上海道宁为您提供先进的.Net库,完全控制您的PDF创建工作流程,在WEB或任何服务器系统上创建动态PDF

    Pdfium.Net SDK是 先进的.Net library 用于生成.操作和查看 可移植文档格式的文件 道宁专注于软件工具经销 为您带来高级PDF库 可完全控制您的PDF创建工作流程 提供高级c# ...

  6. Vue脚手架创建项目流程

    Vue脚手架创建项目流程 图形化创建 在创建文件的文件夹打开cmd, 按住shift右键打开黑窗口,或者直接在文件夹上面路径上面输入cmd 输入vue ui 会自己在浏览器打开 点击创建项目 项目文件 ...

  7. mysql收货地址表_收货地址表结构 以及创建修改流程

    创建收货地址的过程中, 一共涉及到三张表 一张为PostalAddress  contact_mech    party_contact_mech 创建的流程  调用createPartyPostal ...

  8. linux中lv的详细创建流程【化分区-pv-vg-lv创建整套流程】,centos中lv脚本创建vg-pv-lv,-bash: lvs: command not found处理方法

    文章目录 lv的创建流程说明 -bash: lvs: command not found处理方法 lv的创建.删除.使用及增减容量 硬盘分区设置或查看 pv操作 创建pv 删除pv vg操作 vg详细 ...

  9. PVE虚拟化平台之创建虚拟机流程

    PVE虚拟化平台之创建虚拟机流程 一.PVE介绍今天,2022 年 11 月 17 日,有236篇文章可用. 二.登录PVE平台 三.登录PVE系统检查环境 1.进入PVE底层系统的shell命令终端 ...

最新文章

  1. [Android]ListView中分割线的设置
  2. 南邮计算机图形学水不水,南邮计算机图形学实验报告(修正版)….doc
  3. Json和XML之间的对比
  4. asp按时间自动递增编号_Java秒杀系统实战系列-分布式唯一ID生成订单编号
  5. 神经网络如何学习的?
  6. 阻塞(Block)和非阻塞(Non-Block)
  7. C小项目 —— 学生选课系统
  8. HTTP的基本原理----爬虫基础
  9. Spring组合注解与元注解
  10. 博文视点读书节第七日丨IT大咖来荐书,CS提升分享今晚开播,晒单赢福袋活动上线!
  11. crontrigger java_Java触发器CronTrigger
  12. ug录入属性_ug表格属性
  13. 耳机常用降噪技术分析
  14. android 夜间模式功能,Android 夜间模式的三种实现
  15. 学习记录,linux使用wget命令实现整站下载
  16. 途志分享几个抖音短视频拍摄技巧
  17. Docker基础讲解狂神笔记(1/2)
  18. <RTL设计的艺术> DDR带宽计算公式
  19. java绘制五子棋_java绘制五子棋棋盘
  20. Linux网络与进程管理

热门文章

  1. 【操作系统】-- 先来先服务算法(FCFS)、短作业优先算法(SJF)、高响应比调度算法(HRRN)
  2. js获取当前周和时间
  3. 计算机共享的users,win10关闭共享,详细教您win10怎么关闭user共享
  4. 华为优秀员工的16项标准让你的职场之路更顺利
  5. 苏山博士《双向免疫管理》 - 如果继续提升他们的免疫,等同于火上浇油
  6. k8s学习笔记——基础知识
  7. “虎”力全开 | Smartbi收获20+感谢信,豪情满怀迎新春
  8. 如何保证投票公平_举办微信投票活动如何确保公平、公正
  9. 新浪分享 Insufficient app permissions!
  10. 产品经理书籍推荐(二)