From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: [PATCH for 4.6 07/13] xen: Introduce a generic way to describe device Date: Tue, 16 Dec 2014 20:08:48 +0000 Message-ID: <1418760534-18163-8-git-send-email-julien.grall@linaro.org> References: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y0yR1-0004nM-6c for xen-devel@lists.xenproject.org; Tue, 16 Dec 2014 20:09:32 +0000 Received: by mail-wi0-f171.google.com with SMTP id bs8so13488122wib.4 for ; Tue, 16 Dec 2014 12:09:29 -0800 (PST) In-Reply-To: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Keir Fraser , ian.campbell@citrix.com, manish.jaggi@caviumnetworks.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich List-Id: xen-devel@lists.xenproject.org Currently, Xen is supporting PCI and Platform device (based on Device Tree). While we don't support both at the same time: platform device for ARM and PCI for x86, ARM will gain support on 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. At the same time replace any use of asm/device.h by xen/device.h. This is required to be able to compile ARM correctly. Signed-off-by: Julien Grall CC: Jan Beulich CC: Keir Fraser --- xen/arch/arm/device.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v2.c | 3 +-- xen/arch/arm/gic-v3.c | 2 +- xen/arch/arm/gic.c | 2 +- xen/common/Makefile | 1 + xen/common/device.c | 21 +++++++++++++++++++ xen/common/device_tree.c | 1 + xen/drivers/char/dt-uart.c | 4 ++-- xen/drivers/char/exynos4210-uart.c | 2 +- xen/drivers/char/ns16550.c | 2 +- xen/drivers/char/omap-uart.c | 2 +- xen/drivers/char/pl011.c | 2 +- xen/drivers/passthrough/arm/iommu.c | 2 +- xen/drivers/passthrough/pci.c | 2 ++ xen/include/asm-arm/device.h | 3 ++- xen/include/asm-x86/device.h | 17 ++++++++++++++++ xen/include/xen/device.h | 40 +++++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 13 ++++++++++++ xen/include/xen/pci.h | 12 +++++++++++ 20 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 xen/common/device.c create mode 100644 xen/include/asm-x86/device.h create mode 100644 xen/include/xen/device.h diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 693b9af..de702ff 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -17,7 +17,7 @@ * GNU General Public License for more details. */ -#include +#include #include #include diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index de180d8..b701a2f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -9,10 +9,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index f149e09..048350b 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -27,12 +27,11 @@ #include #include #include +#include #include #include #include #include -#include - #include #include diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index 076aa62..c6d1876 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -31,12 +31,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index e7a1af5..d1ab6b5 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -27,10 +27,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/xen/common/Makefile b/xen/common/Makefile index 8391246..03ed719 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -2,6 +2,7 @@ obj-y += bitmap.o obj-y += core_parking.o obj-y += cpu.o obj-y += cpupool.o +obj-y += device.o obj-$(HAS_DEVICE_TREE) += device_tree.o obj-y += domctl.o obj-y += domain.o diff --git a/xen/common/device.c b/xen/common/device.c new file mode 100644 index 0000000..3450f20 --- /dev/null +++ b/xen/common/device.c @@ -0,0 +1,21 @@ +#include +#include + +void device_initialize(struct device *dev, enum device_type type) +{ + dev->type = type; + +#ifdef HAS_DEVICE_TREE + if ( type == DEV_DT ) + dev->of_node = dev_to_dt(dev); +#endif +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 34a1b9e..f471008 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1450,6 +1450,7 @@ static unsigned long __init unflatten_dt_node(const void *fdt, prev_pp = &pp->next; #endif np->name = pp->value; + device_initialize(&np->dev, DEV_DT); memcpy(pp->value, ps, sz - 1); ((char *)pp->value)[sz - 1] = 0; dt_dprintk("fixed up name for %s -> %s\n", pathp, diff --git a/xen/drivers/char/dt-uart.c b/xen/drivers/char/dt-uart.c index fa92b5c..01eced1 100644 --- a/xen/drivers/char/dt-uart.c +++ b/xen/drivers/char/dt-uart.c @@ -17,11 +17,11 @@ * GNU General Public License for more details. */ -#include -#include +#include #include #include #include +#include /* * Configure UART port with a string: diff --git a/xen/drivers/char/exynos4210-uart.c b/xen/drivers/char/exynos4210-uart.c index cba8729..75246e1 100644 --- a/xen/drivers/char/exynos4210-uart.c +++ b/xen/drivers/char/exynos4210-uart.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include diff --git a/xen/drivers/char/ns16550.c b/xen/drivers/char/ns16550.c index 161b251..6df3f95 100644 --- a/xen/drivers/char/ns16550.c +++ b/xen/drivers/char/ns16550.c @@ -25,7 +25,7 @@ #include #include #ifdef HAS_DEVICE_TREE -#include +#include #endif #ifdef CONFIG_X86 #include diff --git a/xen/drivers/char/omap-uart.c b/xen/drivers/char/omap-uart.c index 16d1454..c4cd442 100644 --- a/xen/drivers/char/omap-uart.c +++ b/xen/drivers/char/omap-uart.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/drivers/char/pl011.c b/xen/drivers/char/pl011.c index dd19ce8..cc91224 100644 --- a/xen/drivers/char/pl011.c +++ b/xen/drivers/char/pl011.c @@ -23,8 +23,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 3007b99..3e9303a 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include static const struct iommu_ops *iommu_ops; diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 78c6977..9fbd2a2 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -278,6 +278,8 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) if ( !pdev ) return NULL; + device_initialize(&pdev->dev, DEV_PCI); + *(u16*) &pdev->seg = pseg->nr; *((u8*) &pdev->bus) = bus; *((u8*) &pdev->devfn) = devfn; diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 72a9028..fdcd097 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -2,7 +2,8 @@ #define __ASM_ARM_DEVICE_H #include -#include + +struct dt_device_node; enum device_match { diff --git a/xen/include/asm-x86/device.h b/xen/include/asm-x86/device.h new file mode 100644 index 0000000..9d4c352 --- /dev/null +++ b/xen/include/asm-x86/device.h @@ -0,0 +1,17 @@ +#ifndef __ASM_X86_DEVICE_H +#define __ASM_X86_DEVICE_H + +struct dev_archdata { + /* No device specific arch data */ +}; + +#endif /* __ASM_X86_DEVICE_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/device.h b/xen/include/xen/device.h new file mode 100644 index 0000000..a9e20ad --- /dev/null +++ b/xen/include/xen/device.h @@ -0,0 +1,40 @@ +#ifndef __XEN_DEVICE_H__ +#define __XEN_DEVICE_H__ + +#include + +enum device_type +{ + DEV_PCI, + DEV_DT, +}; + +/* 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; +}; + +#define dev_is_pci(dev) ((dev)->type == DEV_PCI) +#define dev_is_dt(dev) ((dev->type == DEV_DT) + +#ifdef HAS_DEVICE_TREE +#include +#endif + +void device_initialize(struct device *dev, enum device_type type); + +#endif /* __XEN_DEVICE_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 6502369..890d356 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include #include @@ -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; diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 5f295f3..6ace79d 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -13,6 +13,7 @@ #include #include #include +#include #include /* @@ -75,8 +76,19 @@ struct pci_dev { #define PT_FAULT_THRESHOLD 10 } fault; u64 vf_rlen[6]; + + struct device dev; }; +#define pci_to_dev(pcidev) (&(pcidev)->dev) + +static inline struct pci_dev *dev_to_pci(struct device *dev) +{ + ASSERT(dev->type == DEV_PCI); + + return container_of(dev, struct pci_dev, dev); +} + #define for_each_pdev(domain, pdev) \ list_for_each_entry(pdev, &(domain->arch.pdev_list), domain_list) -- 2.1.3