Weitere ähnliche Inhalte Ähnlich wie Project ACRN Device Model architecture introduction (20) Mehr von Project ACRN (19) Kürzlich hochgeladen (20) Project ACRN Device Model architecture introduction1. ACRN Device Model Architecture Introduction
Yuan LIU
Liu, Yuan1 <yuan1.liu@intel.com>
03/25/2020
3. Device Model Framework
ACRN Device Model (DM) is a
QEMU-like application in SOS
and it is responsible for
creating a UOS VM and then
performing devices emulation
based on command line
configurations.
4. Device Model Configuration
acrn-dm -A
-m 2048M
-s 0:0,hostbridge
-s 2,pci-gvt -G "64 448 8“
-s 5,virtio-blk,/home/clear/uos/uos.img
-s 6,virtio-net,tap0
-s 7,passthru,0/15/1
--ovmf /usr/share/acrn/bios/OVMF.fd
vm1
acrn-hypervisor/devicemodel/samples
https://projectacrn.github.io/latest/user-guides/acrn-dm-parameters.html#acrn-dm-parameters
6. Device Model Booting Flow
Start DM Parse Option Create VM
Setup IO
Request Buffer
Setup
Memory
Virtual
Devices Init
ACPI InitSW Load
Start VM
Loop
Start
Mevent Loop
OVMF
EFI
bzImage
vSBL
UOS memory is
allocated from
SOS memory
Huge TLB
Open /dev/vhm
IC_CREATE_VM
vm_id
Create I/O
request client
Handle IO
Request
VM Name
UOS Memory Size
Virtual Devices
…
Micro event
Asynchronous
message
mechanism
based on Linux
epoll
A page buffer
allocated by DM,
shared between
DM, VHM service
and HV.
Build guest ACPI
table
Full tables
RSDP, RSDT, XSDT,
MADT, FADT, HPET,
MCFG
All emulated
devices
initialization
7. Virtual Device Initialization
vISA Device
Init
vPCI Device
Init
Monitor Init
MMIO Init
PIO Init
vPIRQ Init
PIO Handler Register
struct inout_port {
const char *name;
int port;
int size;
int flags;
inout_func_t handler;
void *arg;
};
int register_inout(struct inout_port *iop);
int unregister_inout(struct inout_port *iop);
#define INOUT_PORT(name, port, flags, handler)
MMIO Handler Register
struct mem_range {
const char *name;
int flags;
mem_func_t handler;
void *arg1;
long arg2;
uint64_t base;
uint64_t size;
};
int register_mem(struct mem_range *memp);
int unregister_mem(struct mem_range *memp);
8. Default Guest Memory Layout
2G
0
3.5G
4G
64-bit PCI Hole
RAM
5G
32-bit PCI Hole
Low memory
High memory
RAM
ACPI
MMCFG
IOAPIC
HPET
LAPCI
acrn-hypervisor/devicemodel/core/sw_load_common.c
10. Device Emulation
⚫ Device Register
• PCI Configuration Space
• PORT IO
• Memory Mapped IO
⚫ Interrupt
• MSI/MSIX
• INTX
⚫ Function Emulation
11. __set_pci_vdev_ops_set_sym_pci_ops_ahci
Virtual PCI Device Registration
set_pci_vdev_ops_set Section
struct pci_vdev_ops pci_ops_xhci = {
.class_name = "xhci",
.vdev_init = pci_xhci_init,
.vdev_deinit = pci_xhci_deinit,
.vdev_barwrite = pci_xhci_write,
.vdev_barread = pci_xhci_read
};
DEFINE_PCI_DEVTYPE(pci_ops_xhci);
struct pci_vdev_ops pci_ops_wdt = {
.class_name = "wdt-i6300esb",
.vdev_init = pci_wdt_init,
.vdev_deinit = pci_wdt_deinit,
.vdev_cfgwrite = pci_wdt_cfg_write,
.vdev_cfgread = pci_wdt_cfg_read,
.vdev_barwrite = pci_wdt_bar_write,
.vdev_barread = pci_wdt_bar_read
};
DEFINE_PCI_DEVTYPE(pci_ops_wdt);
__set_pci_vdev_ops_set_sym_pci_ops_wdt
…
.interp Section
set_logger_dev_op Section
…
…
acrn-dm Section Headers
12. Virtual PCI Device Operations
struct pci_vdev_ops {
char *class_name; /* Name of device class */
/* instance creation */
int (*vdev_init)(struct vmctx *, struct pci_vdev *, char *opts);
/* instance deinit */
void (*vdev_deinit)(struct vmctx *, struct pci_vdev *, char *opts);
/* ACPI DSDT enumeration */
void (*vdev_write_dsdt)(struct pci_vdev *);
/* ops related to physical resources */
void (*vdev_phys_access)(struct vmctx *ctx, struct pci_vdev *dev);
/* config space read/write callbacks */
int (*vdev_cfgwrite)(struct vmctx *ctx, int vcpu, struct pci_vdev *pi, int offset, int bytes, uint32_t val);
int (*vdev_cfgread)(struct vmctx *ctx, int vcpu, struct pci_vdev *pi, int offset, int bytes, uint32_t *retval);
/* BAR read/write callbacks */
void (*vdev_barwrite)(struct vmctx *ctx, int vcpu, struct pci_vdev *pi, int baridx, uint64_t offset, int size, uint64_t value);
uint64_t (*vdev_barread)(struct vmctx *ctx, int vcpu, struct pci_vdev *pi, int baridx, uint64_t offset, int size);
};
13. Virtual PCI Device Configuration Space
Virtual PCI device
PCI Capability
pci_set_cfgdata8
pci_set_cfgdata16
pci_set_cfgdata32
pci_emul_add_capability
pci_emul_add_msicap
pci_emul_add_msixcap
pci_emul_alloc_bar
pci_lintr_request
15. Port I/O Emulation Flow
MMIO access flow is similar except for a VM exit reason of EPT violation.
8
17. ACPI - Advanced Configuration
and Power Interface
Functions implemented by ACPI include:
• System/Device/Processor power management
• Device/Processor performance management
• Configuration / Plug and Play
• System event
• Battery management
• Thermal management