]> xenbits.xensource.com Git - people/gdunlap/xen.git/commitdiff
xen/arm: Introduce a generic way to describe device
authorJulien Grall <julien.grall@linaro.org>
Wed, 25 Feb 2015 18:52:55 +0000 (18:52 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 2 Mar 2015 13:55:23 +0000 (13:55 +0000)
Currently, Xen is supporting PCI and Platform device (based on Device Tree).

While Xen only supports Platform device on ARM, Xen will gain support of
PCI soon.

Some drivers, such as IOMMU drivers, may handle PCI and platform device in
the same way. Only few lines of code differs.

Rather than requesting to provide 2 set of functions (one for PCI and
one for platform device), introduce a generic structure "device" which
is embedded in each specialized device.

As x86 only supports PCI, introduce a new type device_t which will be an
alias to pci_dev for this architecture. It will avoid to add a new field
for this place.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Andrew Cooper <andrew.cooper3@citrix.com>
xen/common/device_tree.c
xen/include/asm-arm/device.h
xen/include/asm-x86/device.h [new file with mode: 0644]
xen/include/xen/device_tree.h
xen/include/xen/iommu.h
xen/include/xen/pci.h

index 34a1b9e645a5588bc9008edb207de813548f2c65..d1c716f2e9f1365c92638ab3d63329b658a1f8aa 100644 (file)
@@ -1454,6 +1454,9 @@ static unsigned long __init unflatten_dt_node(const void *fdt,
             ((char *)pp->value)[sz - 1] = 0;
             dt_dprintk("fixed up name for %s -> %s\n", pathp,
                        (char *)pp->value);
+            /* Generic device initialization */
+            np->dev.type = DEV_DT;
+            np->dev.of_node = np;
         }
     }
     if ( allnextpp )
index b6b32bceafa27c73d7ec4698afb3c479ce0bbafb..1cedd4994b2b3083af23e77f428653849066a41c 100644 (file)
@@ -2,8 +2,34 @@
 #define __ASM_ARM_DEVICE_H
 
 #include <xen/init.h>
+
+enum device_type
+{
+    DEV_DT,
+};
+
+struct dev_archdata {
+    void *iommu;    /* IOMMU private data */
+};
+
+/* struct device - The basic device structure */
+struct device
+{
+    enum device_type type;
+#ifdef HAS_DEVICE_TREE
+    struct dt_device_node *of_node; /* Used by drivers imported from Linux */
+#endif
+    struct dev_archdata archdata;
+};
+
+typedef struct device device_t;
+
 #include <xen/device_tree.h>
 
+/* TODO: Correctly implement dev_is_pci when PCI is supported on ARM */
+#define dev_is_pci(dev) ((void)(dev), 0)
+#define dev_is_dt(dev)  ((dev->type == DEV_DT)
+
 enum device_class
 {
     DEVICE_SERIAL,
diff --git a/xen/include/asm-x86/device.h b/xen/include/asm-x86/device.h
new file mode 100644 (file)
index 0000000..f2acc7e
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __ASM_X86_DEVICE_H
+#define __ASM_X86_DEVICE_H
+
+#include <xen/pci.h>
+
+/*
+ * x86 only supports PCI. Therefore it's possible to directly use
+ * pci_dev to avoid adding new field.
+ */
+
+typedef struct pci_dev device_t;
+
+#define dev_is_pci(dev) ((void)(dev), 1)
+#define pci_to_dev(pci) (pci)
+
+#endif /* __ASM_X86_DEVICE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 65023694079f0bd76b6a76518ec2b88105811fef..c8a037508c6dc9406939e6ba9b4ae4db6b292650 100644 (file)
@@ -11,7 +11,9 @@
 #define __XEN_DEVICE_TREE_H__
 
 #include <asm/byteorder.h>
+#include <asm/device.h>
 #include <public/xen.h>
+#include <xen/kernel.h>
 #include <xen/init.h>
 #include <xen/string.h>
 #include <xen/types.h>
@@ -80,8 +82,19 @@ struct dt_device_node {
     /* IOMMU specific fields */
     bool is_protected;
     struct list_head domain_list;
+
+    struct device dev;
 };
 
+#define dt_to_dev(dt_node)  (&(dt_node)->dev)
+
+static inline struct dt_device_node *dev_to_dt(struct device *dev)
+{
+    ASSERT(dev->type == DEV_DT);
+
+    return container_of(dev, struct dt_device_node, dev);
+}
+
 #define MAX_PHANDLE_ARGS 16
 struct dt_phandle_args {
     struct dt_device_node *np;
index 8eb764a001c2f6ed3e1db824022fd456dc07daee..ecb26270e7cf1bfef9c32f5e5a4806c870f1d026 100644 (file)
@@ -25,6 +25,7 @@
 #include <xen/pci.h>
 #include <public/hvm/ioreq.h>
 #include <public/domctl.h>
+#include <asm/device.h>
 #include <asm/iommu.h>
 
 extern bool_t iommu_enable, iommu_enabled;
index 5f295f318259bd972bdb4148a2e58debe65feebb..3988ee6894a7140c6c6f064209299e98ba0f2260 100644 (file)
@@ -13,6 +13,7 @@
 #include <xen/irq.h>
 #include <xen/pci_regs.h>
 #include <xen/pfn.h>
+#include <asm/device.h>
 #include <asm/pci.h>
 
 /*