From patchwork Wed Feb 25 18:52:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 45103 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 13D0620502 for ; Wed, 25 Feb 2015 18:55:40 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf4905979wib.2 for ; Wed, 25 Feb 2015 10:55:39 -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=9A4aUVUS8Ensam9yquz6tvNDN45jcsXxh8FW9C36MVw=; b=RLFPzbKzkAV8Z0rR0vjFnPX/9sHosxRN9CJqYONt1oadkWG6UGiBxFdzJ5Rrwfpvy2 T5G8TM9ci6AQmpPr4aG3R6N2YnPU3Ce2WpZt5Edz/BQ4FsYuoMOlvJMR2Mova7BAFvK/ 6GZbT+NFK9NepYqlN95UeP9Hwp4BL1F5DPq3nVWHJCAAzLEt3eMFVrXidSw5xT9NyrHq ACS+bmOKtaGe31suLHm+WERG0cerivnc+fM8I5IzIpLzzuXcOSj+MEYS0CzBbrQ8xMHh XKR5Ud2Qf0Rqbdi0xXj20sZQbWwmUHzrnxo1/UdxQaImCjRLNQ5VE/rrBJXIR2BWUpaJ LecA== X-Gm-Message-State: ALoCoQke1MQeoIub5O1yZd7D33x1S6EWoMVeMYD3cX/exZB4Paa/5bvZLC22RDwYRgQEkN40WWxg X-Received: by 10.112.214.234 with SMTP id od10mr714816lbc.3.1424890539398; Wed, 25 Feb 2015 10:55:39 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.200 with SMTP id la8ls856515lac.90.gmail; Wed, 25 Feb 2015 10:55:39 -0800 (PST) X-Received: by 10.112.118.211 with SMTP id ko19mr4211943lbb.19.1424890539085; Wed, 25 Feb 2015 10:55:39 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id mt5si31515493lbb.59.2015.02.25.10.55.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 10:55:39 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labhs14 with SMTP id hs14so6030645lab.1 for ; Wed, 25 Feb 2015 10:55:39 -0800 (PST) X-Received: by 10.112.167.36 with SMTP id zl4mr4386288lbb.32.1424890538840; Wed, 25 Feb 2015 10:55:38 -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 h5csp2819926lbj; Wed, 25 Feb 2015 10:55:37 -0800 (PST) X-Received: by 10.140.237.6 with SMTP id i6mr10255387qhc.32.1424890537206; Wed, 25 Feb 2015 10:55:37 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 192si12173391qhh.34.2015.02.25.10.55.36 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Feb 2015 10:55:37 -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 1YQh5X-0005qF-4N; Wed, 25 Feb 2015 18:53:39 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQh5V-0005pO-2R for xen-devel@lists.xenproject.org; Wed, 25 Feb 2015 18:53:37 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 2D/58-02898-03A1EE45; Wed, 25 Feb 2015 18:53:36 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-15.tower-31.messagelabs.com!1424890415!10872825!1 X-Originating-IP: [74.125.82.53] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4748 invoked from network); 25 Feb 2015 18:53:35 -0000 Received: from mail-wg0-f53.google.com (HELO mail-wg0-f53.google.com) (74.125.82.53) by server-15.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 25 Feb 2015 18:53:35 -0000 Received: by wghb13 with SMTP id b13so5610648wgh.0 for ; Wed, 25 Feb 2015 10:53:35 -0800 (PST) X-Received: by 10.180.104.66 with SMTP id gc2mr33454474wib.34.1424890414927; Wed, 25 Feb 2015 10:53:34 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id kr5sm61071839wjc.1.2015.02.25.10.53.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Feb 2015 10:53:33 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 25 Feb 2015 18:52:55 +0000 Message-Id: <1424890381-4225-3-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424890381-4225-1-git-send-email-julien.grall@linaro.org> References: <1424890381-4225-1-git-send-email-julien.grall@linaro.org> Cc: Keir Fraser , ian.campbell@citrix.com, Stefano Stabellini , Andrew Cooper , manish.jaggi@caviumnetworks.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v4 2/8] 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.46 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 Acked-by: Jan Beulich Acked-by: Stefano Stabellini CC: Keir Fraser CC: Andrew Cooper --- Changes in v4: - Add Jan and Stefano's ack - Typoes 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..1cedd49 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 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 index 0000000..f2acc7e --- /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 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: + */ 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 /*