如何在QEMU源代码中添加新设备? [英] How to add a new device in QEMU source code?
问题描述
使用QOM方法在qemu
中模拟/添加新设备的逐步方法是什么?
What could be the step wise approach to emulate/add a new device in qemu
using QOM approach?
关于DeviceState/BusState和其他属性的更改在哪里?
What and where could be the changes with respect to DeviceState/BusState and other properties?
推荐答案
edu
树内教育PCI设备
edu
in-tree educational PCI device
- https://github.com/qemu/qemu/blob/v2.7.0/hw/misc/edu.c
- https://github.com/qemu/qemu/blob/v2.7.0/docs/specs/edu.txt
- https://github.com/qemu/qemu/blob/v2.7.0/hw/misc/edu.c
- https://github.com/qemu/qemu/blob/v2.7.0/docs/specs/edu.txt
它很容易理解和有据可查,因此我建议您学习它.
It is very easy to understand and well documented, so I recommend that you study it.
它公开了最小的PCI设备,具有基本的IO,中断生成和DMA.
It exposes a minimal PCI device, with basic IO, interrupt generation, and DMA.
我已经编写了一个最小的Linux内核模块+用户环境测试,可以在以下位置使用它:
I've written a minimal Linux kernel module + userland tests to play with it at:
- https://github.com/cirosantilli/linux-kernel-module-cheat/blob/6788a577c394a2fc512d8f3df0806d84dc09f355/rootfs_overlay/pci.sh
- https://github.com/cirosantilli/linux-kernel-module-cheat/blob/6788a577c394a2fc512d8f3df0806d84dc09f355/kernel_module/pci.c
- https://github.com/cirosantilli/linux-kernel-module-cheat/blob/6788a577c394a2fc512d8f3df0806d84dc09f355/rootfs_overlay/pci.sh
- https://github.com/cirosantilli/linux-kernel-module-cheat/blob/6788a577c394a2fc512d8f3df0806d84dc09f355/kernel_module/pci.c
最小PCI设备
我将edu最小化到QEMU分支的四分之一: https://github.com/cirosantilli/qemu/blob/22e7e210d6fbe54c35a5ae32450a4419df25a13b/hw/misc/lkmc_pci_min.c 没有DMA.
I've minimized edu even further to a quarter of the size on my QEMU fork: https://github.com/cirosantilli/qemu/blob/22e7e210d6fbe54c35a5ae32450a4419df25a13b/hw/misc/lkmc_pci_min.c No DMA.
我的Buildroot包装器已经将QEMU fork与一个子模块集成在一起,只需克隆和./run
.
My Buildroot wrapper already integrates the QEMU fork with a submodule, just clone and ./run
.
ARM平台设备TYPE_SYS_BUS_DEVICE
ARM platform device TYPE_SYS_BUS_DEVICE
SoC-land可以在芯片中而不是PCI上烘烤大多数设备,这是一个最小的可运行示例:
SoC-land bakes most devices in the silicon instead of PCI, here is a minimal runnable example:
- QEMU前叉:
- 设备 https://github.com/cirosantilli/qemu /blob/144ea94d710c666babd06ed733007377e132ed4a/hw/misc/lkmc_platform_device.c
- 将设备插入
-M versatilepb
: https://github.com/cirosantilli/qemu/blob/144ea94d710c666babd06ed733007377e132ed4a/hw/arm/versatilepb.c#L302 使用sysbus_create_simple
,它期望使用类型为TYPE_SYS_BUS_DEVICE
的设备.
- QEMU fork:
- device https://github.com/cirosantilli/qemu/blob/144ea94d710c666babd06ed733007377e132ed4a/hw/misc/lkmc_platform_device.c
- insert device into
-M versatilepb
: https://github.com/cirosantilli/qemu/blob/144ea94d710c666babd06ed733007377e132ed4a/hw/arm/versatilepb.c#L302 Usessysbus_create_simple
, which expects a device of typeTYPE_SYS_BUS_DEVICE
.
- 通知内核寄存器和IRQ所在的位置,并与QEMU的
versatilepb.c
中的参数匹配
-
compatible
与内核模块中的platform_driver.name
匹配,并通知内核哪个模块将处理此设备. - 通过
-dtb
传递到QEMU的固件
- Informs the kernel where the registers and IRQs are located, and matches the parameters in QEMU's
versatilepb.c
compatible
matches theplatform_driver.name
in the kernel module, and informs the kernel which module will handle this device.- passed to QEMU's firmware with
-dtb
具有DTC修改的Linux分支是Buildroot包装器存储库的子模块,因此只需克隆和
./run -a arm
.The Linux fork with the DTC modification is a submodule of the Buildroot wrapper repo, so just clone and
./run -a arm
.树外设备
I asked if it is possible to make out-of-tree devices at: How to create out-of-tree QEMU devices? but it does not look like it.
这篇关于如何在QEMU源代码中添加新设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!