From patchwork Fri Jan 30 18:49:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 44056 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D8A7320CA8 for ; Fri, 30 Jan 2015 18:52:34 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id l4sf2822593lbv.1 for ; Fri, 30 Jan 2015 10:52:33 -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=A7qBe2BPo7p1926dzZGw/rGHg8Br82ZsTCoH9Z5i0Gw=; b=L/aw3R9Ezh5c4bKoVwLcipuhKmWf+q96CORaIWlZf++IjeN9T6bgjicyNNlyh9FaUK SlN8zEhYr9XqlEcwCt+bSSprlJyoSQx6TNRmaDqqYMoo2WkS4PLZKD9r/NX+ELMltJgf f40gQ15hGkrre4FMR22Yf5PqMfgA+SPzZuebF7P81CsQ3Map1n4v3rBdtdAiwjKBNGXn xSBlNYhA7BpD439CrcRdZuI9IIYsT0B6M2HSLds4LqxrPjv2snBa4xexTedzBbJRU+XF Ty8O5DX4aM96yszR2By9b5/cqw19OoJQhmMxn/0lV7gcWyBChfoV72pM5vmPCscKwdr9 Q/ZA== X-Gm-Message-State: ALoCoQmlAuyWDCJpW4vv8qys8kVWcJBaPKhHHomKAbTjTcqV+pEyQPtiC1WOKH7v0hf0iKF2cUz7 X-Received: by 10.112.131.106 with SMTP id ol10mr1047904lbb.20.1422643953803; Fri, 30 Jan 2015 10:52:33 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.137 with SMTP id t9ls436969lag.44.gmail; Fri, 30 Jan 2015 10:52:33 -0800 (PST) X-Received: by 10.112.199.69 with SMTP id ji5mr7954856lbc.45.1422643953397; Fri, 30 Jan 2015 10:52:33 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id o6si6034844lao.25.2015.01.30.10.52.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 10:52:33 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id ms9so25295054lab.1 for ; Fri, 30 Jan 2015 10:52:33 -0800 (PST) X-Received: by 10.152.44.228 with SMTP id h4mr2410469lam.31.1422643953300; Fri, 30 Jan 2015 10:52:33 -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.35.133 with SMTP id h5csp377812lbj; Fri, 30 Jan 2015 10:52:32 -0800 (PST) X-Received: by 10.140.81.74 with SMTP id e68mr10898481qgd.41.1422643950596; Fri, 30 Jan 2015 10:52:30 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z1si15100671qar.33.2015.01.30.10.52.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 10:52:30 -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 1YHGdx-0007EM-Pe; Fri, 30 Jan 2015 18:50:13 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YHGdw-0007DE-9n for xen-devel@lists.xenproject.org; Fri, 30 Jan 2015 18:50:12 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id DA/4C-02749-362DBC45; Fri, 30 Jan 2015 18:50:11 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-21.messagelabs.com!1422643810!13606284!1 X-Originating-IP: [74.125.82.182] 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 24073 invoked from network); 30 Jan 2015 18:50:10 -0000 Received: from mail-we0-f182.google.com (HELO mail-we0-f182.google.com) (74.125.82.182) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 30 Jan 2015 18:50:10 -0000 Received: by mail-we0-f182.google.com with SMTP id l61so28719529wev.13 for ; Fri, 30 Jan 2015 10:50:10 -0800 (PST) X-Received: by 10.194.191.227 with SMTP id hb3mr15043578wjc.79.1422643808633; Fri, 30 Jan 2015 10:50:08 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id n1sm169040wib.11.2015.01.30.10.50.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jan 2015 10:50:07 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 30 Jan 2015 18:49:21 +0000 Message-Id: <1422643768-23614-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1422643768-23614-1-git-send-email-julien.grall@linaro.org> References: <1422643768-23614-1-git-send-email-julien.grall@linaro.org> Cc: Keir Fraser , ian.campbell@citrix.com, Andrew Cooper , Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v3 06/13] xen/arm: 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.215.42 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 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 CC: Jan Beulich CC: Keir Fraser CC: Andrew Cooper --- Changes in v3: - Drop common/device.c as it wasn't used after v1 Changes in v2: - As x86 will only support PCI, only introduce the generic device on ARM - Introduce a typedef device_t to be used in common code - Drop the PCI code for ARM for now. It will be reintroduced when PCI support will be added - s#asm/device.h#xen/device.h# is not anymore needed --- xen/common/device_tree.c | 3 +++ xen/include/asm-arm/device.h | 26 ++++++++++++++++++++++++++ xen/include/asm-x86/device.h | 25 +++++++++++++++++++++++++ xen/include/xen/device_tree.h | 13 +++++++++++++ xen/include/xen/iommu.h | 1 + xen/include/xen/pci.h | 1 + 6 files changed, 69 insertions(+) create mode 100644 xen/include/asm-x86/device.h diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 34a1b9e..d1c716f 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -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 ) diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index b6b32bc..a3d45dd 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -2,8 +2,34 @@ #define __ASM_ARM_DEVICE_H #include + +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 +/* TODO: Correctly implement dev_is_pci when PCI will be 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 index 0000000..a016112 --- /dev/null +++ b/xen/include/asm-x86/device.h @@ -0,0 +1,25 @@ +#ifndef __ASM_X86_DEVICE_H +#define __ASM_X86_DEVICE_H + +#include + +/* + * x86 is only supported 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: + */ diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 6502369..c8a0375 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -11,7 +11,9 @@ #define __XEN_DEVICE_TREE_H__ #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/iommu.h b/xen/include/xen/iommu.h index 8eb764a..ecb2627 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -25,6 +25,7 @@ #include #include #include +#include #include extern bool_t iommu_enable, iommu_enabled; diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 5f295f3..3988ee68 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -13,6 +13,7 @@ #include #include #include +#include #include /*