Qemu: How to create the bridge device, bus, and pci device.

How to create bridge device, bus, and pci device.

As we all know, the "device and bus" architecture in qemu is that, a pci
device should attach to a pci bus, and a pci bus should add to a bridge
device, and the bridge device should link to main-system-bus.

To realize this, four important functions are introduced:
1. qdev_bridge_create() to create a bridge device named "s390-bridge-dev".
2. qbus_create() to create a pci bus named "s390-pci-bus" and attach
   "s390-pci-bus" to "s390-bridge-dev".
3. s390_pci_bus_init() is used by coder to assign a bridge device and a pci bus,
   it will call qdev_bridge_create() and qbus_create().
4. qdev_device_add() to create a pci device and attach it to designated bus.

The following codes are telling how to realize this in detail.

I. Define TypeInfo in test_pci.c file.

static void s390_pci_dev_class_init(ObjectClass *kclass, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(kclass);

    dc->bus_type = TYPE_S390_PCI_BUS;
}

static const TypeInfo s390_bridge_dev_info = {
    .name       = TYPE_S390_BRIDGE_DEV,
    .parent     = TYPE_SYS_BUS_DEVICE,
    .class_init = s390_bridge_dev_class_init,
}

static const TypeInfo s390_pci_bus_info = {
    .name       = TYPE_S390_PCI_BUS,
    .parent     = TYPE_BUS,
}

static const TypeInfo s390_pci_dev_info = {
    .name       = TYPE_S390_PCI_DEV,
    .parent     = TYPE_DEVICE,
    .class_init = s390_pci_dev_class_init,
};

II. Define macro in test_pci.h file.

#define TYPE_S390_BRIDGE_DEV  "s390-bridge-dev"
#d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值