[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device. |
Date: |
Tue, 8 Jan 2013 17:54:50 +0000 |
On 7 January 2013 18:40, <address@hidden> wrote:
> From: KONRAD Frederic <address@hidden>
>
> Create the virtio-pci device. This transport device will create a
> virtio-pci-bus, so one VirtIODevice can be connected.
>
> Signed-off-by: KONRAD Frederic <address@hidden>
> ---
> hw/virtio-pci.c | 127
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-pci.h | 18 ++++++++
> 2 files changed, 145 insertions(+)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 5ff03e8..1f0ecbe 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1163,6 +1163,130 @@ static TypeInfo virtio_scsi_info = {
> .class_init = virtio_scsi_class_init,
> };
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
"has"
> + */
> +
> +/* This is called by virtio-bus just after the device is plugged. */
> +static void virtio_pci_device_plugged(DeviceState *d)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
> + VirtioBusState *bus = proxy->bus;
> + uint8_t *config;
> + uint32_t size;
> +
> + /* Put the PCI IDs */
> + switch (virtio_device_get_id(proxy->bus)) {
> +
> +
> + default:
> + error_report("unknown device id\n");
> + break;
> +
> + }
This doesn't have any code in it yet (it gets added in later patches) but
the final result looks very repetitive. I think you'd be better off just having
some arrays:
uint16_t virtio_pci_device_id[] = {
[VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
[VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
(etc)
};
similarly for the class. Then you can just drop the switch statement.
In fact I think you might as well put in the array entries for all
the virtio devices in this patch rather than adding one in each of the
"add virtio-foo device" patches; it will do no harm for them to be
there early and it makes the later patches a little smaller.
> +
> + proxy->vdev = proxy->bus->vdev;
> +
> + config = proxy->pci_dev.config;
> + if (proxy->class_code) {
> + pci_config_set_class(config, proxy->class_code);
> + }
> + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> + pci_get_word(config + PCI_VENDOR_ID));
> + pci_set_word(config + PCI_SUBSYSTEM_ID,
> virtio_device_get_id(proxy->bus));
> + config[PCI_INTERRUPT_PIN] = 1;
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -45,6 +45,22 @@ typedef struct {
> unsigned int users;
> } VirtIOIRQFD;
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
"has"
> + */
-- PMM
[Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the new API., fred . konrad, 2013/01/07