From patchwork Fri Jan 16 14:24:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 43240 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 624B1240D8 for ; Fri, 16 Jan 2015 14:26:05 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id k11sf11222777wes.2 for ; Fri, 16 Jan 2015 06:26:04 -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=qm97X7qS6Z5o1yMqP0JvpJdGz6SOer+N6pLj/xtpBr4=; b=DD3TO1CKCCvJdApRD2cyy+awNEyvWMEiGZEJ6qU2LAxtEghPAPq9I4tKwP4Nbw2tAO l0o4P4IhILnF6ekkwKA3A7nwyBzPQer4euGvYG1tYlcqH/ka/Uq5JGYaBSnNuNHwg/Tl Dk8a5WUGDeqLQuWjQ2DZffXNT6qcAE1stLm64xo5nulFZ7w2t5FBKL6hOALz5dFNU01k iIto0ezJ/MBqXHDjgdY2i/Ahwm48tMKv+ybhlU+l6g5VwsBwsS0lQ/MaLzN+Jx0WOSh4 vfRq33E7PM54pRbV06s8lB7UI5FmL0QfvOVfZImz7193HrKriYL52RzhSgFAyf6+9og1 pQJA== X-Gm-Message-State: ALoCoQmOVv2+u5DEmsMIePOMBRHwYXXefmwTq0M6OTmqGRjv4UNlRqxRaSB9mtAbebwzj/K4+YBg X-Received: by 10.194.77.1 with SMTP id o1mr2015270wjw.1.1421418364579; Fri, 16 Jan 2015 06:26:04 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.66 with SMTP id x2ls325670laa.88.gmail; Fri, 16 Jan 2015 06:26:04 -0800 (PST) X-Received: by 10.113.7.163 with SMTP id dd3mr15992953lbd.96.1421418364328; Fri, 16 Jan 2015 06:26:04 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id lt6si4569831lac.47.2015.01.16.06.26.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Jan 2015 06:26:04 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id w7so18746619lbi.2 for ; Fri, 16 Jan 2015 06:26:04 -0800 (PST) X-Received: by 10.112.26.135 with SMTP id l7mr15581275lbg.56.1421418364185; Fri, 16 Jan 2015 06:26:04 -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.9.200 with SMTP id c8csp325219lbb; Fri, 16 Jan 2015 06:26:03 -0800 (PST) X-Received: by 10.229.15.134 with SMTP id k6mr25191239qca.22.1421418362750; Fri, 16 Jan 2015 06:26:02 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id z110si6107564qgd.73.2015.01.16.06.26.02 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 Jan 2015 06:26:02 -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 1YC7pl-0004Nb-Mn; Fri, 16 Jan 2015 14:25:09 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YC7pk-0004Lx-7U for xen-devel@lists.xenproject.org; Fri, 16 Jan 2015 14:25:08 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id AF/99-25727-34F19B45; Fri, 16 Jan 2015 14:25:07 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-4.tower-31.messagelabs.com!1421418306!11249626!1 X-Originating-IP: [74.125.82.174] 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 17962 invoked from network); 16 Jan 2015 14:25:06 -0000 Received: from mail-we0-f174.google.com (HELO mail-we0-f174.google.com) (74.125.82.174) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jan 2015 14:25:06 -0000 Received: by mail-we0-f174.google.com with SMTP id k48so20522795wev.5 for ; Fri, 16 Jan 2015 06:25:06 -0800 (PST) X-Received: by 10.180.39.204 with SMTP id r12mr6646993wik.11.1421418301788; Fri, 16 Jan 2015 06:25:01 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id x6sm6270862wjf.24.2015.01.16.06.25.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Jan 2015 06:25:00 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 16 Jan 2015 14:24:01 +0000 Message-Id: <1421418247-30068-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421418247-30068-1-git-send-email-julien.grall@linaro.org> References: <1421418247-30068-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 v2 06/12] 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.217.171 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 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.c | 21 +++++++++++++++++++++ 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 + 7 files changed, 90 insertions(+) create mode 100644 xen/common/device.c create mode 100644 xen/include/asm-x86/device.h 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..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 72a9028..2fe4280 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_match { 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 /*