From patchwork Tue Dec 16 20:08:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 42361 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0DC5825E25 for ; Tue, 16 Dec 2014 20:12:30 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id hs14sf9158041lab.5 for ; Tue, 16 Dec 2014 12:12:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=TZZrJmNh60n7cq0aGXkMpinZvUAK36lLvHjrfvlOvhY=; b=KOmqXYOZGzvYp2/2oQtgEq/7ORkJhAcfcRU6ufh4uS8yoOUh0iX0QsHFfu42Ryfm8s HTQw7G8Hw6NQKvIVUdp/hKvXYYUbZPxttVmdrqQdtq9pq+C+FQ1BX/XXTYSQnh9xXvk7 cdDbrDLim9h6OyW8NbwnhA4LD6/6A6T2y4hhcgExyS7GLTG+pix0oGHNZp3+9NqzuDFq +R+DWgHIQXmIrpZuZEECtPEHDw16Zd4oKVlvmHli1Euhs7iI+36UzW2Tx5EJHymtU1wa wUedTAhZbfVrbdtxDnCpev0hHRGgKSSoc1RAP6MkD7a3yv/MFE+LcPoqf6bnUOQB0/pk ZlcA== X-Gm-Message-State: ALoCoQnjgGS2KxO+qhJ/u+a2/UvR2STScdEyi3u4ulTtuOkYPy3uy5+eljqO+gBhCbYFU8t+3l4G X-Received: by 10.112.42.104 with SMTP id n8mr4694lbl.19.1418760748989; Tue, 16 Dec 2014 12:12:28 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.11.163 with SMTP id ej3ls892053lad.94.gmail; Tue, 16 Dec 2014 12:12:28 -0800 (PST) X-Received: by 10.152.170.194 with SMTP id ao2mr38184339lac.12.1418760748848; Tue, 16 Dec 2014 12:12:28 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id kl8si1742985lac.120.2014.12.16.12.12.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 12:12:28 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id z11so11463454lbi.38 for ; Tue, 16 Dec 2014 12:12:28 -0800 (PST) X-Received: by 10.112.135.197 with SMTP id pu5mr37155860lbb.22.1418760748708; Tue, 16 Dec 2014 12:12:28 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1149202lbb; Tue, 16 Dec 2014 12:12:27 -0800 (PST) X-Received: by 10.220.3.71 with SMTP id 7mr23700128vcm.56.1418760746903; Tue, 16 Dec 2014 12:12:26 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ib1si651893vdb.0.2014.12.16.12.12.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 12:12:26 -0800 (PST) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y0yR3-0004oV-BV; Tue, 16 Dec 2014 20:09:33 +0000 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: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 46/90-22777-A7190945; Tue, 16 Dec 2014 20:09:30 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-11.tower-206.messagelabs.com!1418760569!9589699!1 X-Originating-IP: [209.85.212.171] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3568 invoked from network); 16 Dec 2014 20:09:29 -0000 Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 Dec 2014 20:09:29 -0000 Received: by mail-wi0-f171.google.com with SMTP id bs8so13488122wib.4 for ; Tue, 16 Dec 2014 12:09:29 -0800 (PST) X-Received: by 10.180.77.7 with SMTP id o7mr7549763wiw.81.1418760569099; Tue, 16 Dec 2014 12:09:29 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id b10sm3382705wiw.9.2014.12.16.12.09.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 12:09:27 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 16 Dec 2014 20:08:48 +0000 Message-Id: <1418760534-18163-8-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> References: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> Cc: Keir Fraser , ian.campbell@citrix.com, manish.jaggi@caviumnetworks.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH for 4.6 07/13] xen: Introduce a generic way to describe device X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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)