aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2012-11-22 15:58:13 +0000
committerWill Deacon <will.deacon@arm.com>2015-06-01 16:39:53 +0100
commit21ff329de8997d20acba0da657ef17671eb861ab (patch)
tree1ba73d5384d244deb0db5ddafb518fc090de873f /include
parent13cf07d9e257e51cdbd4b18d32af02ff03ed212c (diff)
downloadkvmtool-21ff329de8997d20acba0da657ef17671eb861ab.tar.gz
kvm tools: add generic device registration mechanism
PCI devices are currently registered into the pci_devices array via the pci__register function, which can then be indexed later by architecture code to construct device tree nodes. For MMIO devices, there is no such utility. Rather than invent a similar mechanism for MMIO, this patch creates a global device registration mechanism, which allows the device type to be specified when registered or indexing a device. Current users of the pci registration code are migrated to the new infrastructure and virtio MMIO devices are registered at init time. As part of the device registration, allocation of the device number is moved out of irq__register_device and performed when adding the device header to the relevant bus tree, allowing us to maintain separate device numberspaces for each bus. Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/kvm/devices.h27
-rw-r--r--include/kvm/irq.h2
-rw-r--r--include/kvm/pci.h2
-rw-r--r--include/kvm/virtio-mmio.h1
-rw-r--r--include/kvm/virtio-pci.h2
5 files changed, 31 insertions, 3 deletions
diff --git a/include/kvm/devices.h b/include/kvm/devices.h
new file mode 100644
index 00000000..c5de3de2
--- /dev/null
+++ b/include/kvm/devices.h
@@ -0,0 +1,27 @@
+#ifndef KVM__DEVICES_H
+#define KVM__DEVICES_H
+
+#include <linux/rbtree.h>
+#include <linux/types.h>
+
+enum device_bus_type {
+ DEVICE_BUS_PCI,
+ DEVICE_BUS_MMIO,
+ DEVICE_BUS_MAX,
+};
+
+struct device_header {
+ enum device_bus_type bus_type;
+ void *data;
+ int dev_num;
+ struct rb_node node;
+};
+
+int device__register(struct device_header *dev);
+struct device_header *device__find_dev(enum device_bus_type bus_type,
+ u8 dev_num);
+
+struct device_header *device__first_dev(enum device_bus_type bus_type);
+struct device_header *device__next_dev(struct device_header *dev);
+
+#endif /* KVM__DEVICES_H */
diff --git a/include/kvm/irq.h b/include/kvm/irq.h
index 43fecaf5..5c1274b9 100644
--- a/include/kvm/irq.h
+++ b/include/kvm/irq.h
@@ -22,7 +22,7 @@ struct pci_dev {
struct list_head lines;
};
-int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line);
+int irq__register_device(u32 dev, u8 *pin, u8 *line);
struct rb_node *irq__get_pci_tree(void);
diff --git a/include/kvm/pci.h b/include/kvm/pci.h
index 26639b5a..3da38117 100644
--- a/include/kvm/pci.h
+++ b/include/kvm/pci.h
@@ -9,7 +9,6 @@
#include "kvm/kvm.h"
#include "kvm/msi.h"
-#define PCI_MAX_DEVICES 256
/*
* PCI Configuration Mechanism #1 I/O ports. See Section 3.7.4.1.
* ("Configuration Mechanism #1") of the PCI Local Bus Specification 2.1 for
@@ -86,7 +85,6 @@ struct pci_device_header {
int pci__init(struct kvm *kvm);
int pci__exit(struct kvm *kvm);
-int pci__register(struct pci_device_header *dev, u8 dev_num);
struct pci_device_header *pci__find_dev(u8 dev_num);
u32 pci_get_io_space_block(u32 size);
void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size);
diff --git a/include/kvm/virtio-mmio.h b/include/kvm/virtio-mmio.h
index e0ede3c6..983c8fc1 100644
--- a/include/kvm/virtio-mmio.h
+++ b/include/kvm/virtio-mmio.h
@@ -47,6 +47,7 @@ struct virtio_mmio {
struct kvm *kvm;
u8 irq;
struct virtio_mmio_hdr hdr;
+ struct device_header dev_hdr;
struct virtio_mmio_ioevent_param ioeventfds[VIRTIO_MMIO_MAX_VQ];
};
diff --git a/include/kvm/virtio-pci.h b/include/kvm/virtio-pci.h
index 44130e0c..6d9a5586 100644
--- a/include/kvm/virtio-pci.h
+++ b/include/kvm/virtio-pci.h
@@ -1,6 +1,7 @@
#ifndef KVM__VIRTIO_PCI_H
#define KVM__VIRTIO_PCI_H
+#include "kvm/devices.h"
#include "kvm/pci.h"
#include <linux/types.h>
@@ -19,6 +20,7 @@ struct virtio_pci_ioevent_param {
struct virtio_pci {
struct pci_device_header pci_hdr;
+ struct device_header dev_hdr;
void *dev;
u16 base_addr;