From patchwork Tue Jan 2 09:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123102 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755112qgn; Tue, 2 Jan 2018 01:31:13 -0800 (PST) X-Google-Smtp-Source: ACJfBouWH/kpujcrJB8dAyk+nyXlCAZRn2Yruz7Xp8wESn+G/gleoWf7RpzFl1m/KuHkQoCPOqBK X-Received: by 10.36.204.85 with SMTP id x82mr56991496itf.95.1514885473752; Tue, 02 Jan 2018 01:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885473; cv=none; d=google.com; s=arc-20160816; b=b+UGjigZjXuHh4keK2cFG5AuriwGxORDyahBW1VBy1NOFgC4oMgiz0ZyLwTGKZDAu3 xSm4bUeQ//p11JHmAgpuW7UBC/5FBDS3tCOD1yaC3CrxK+muB2/HP4tsMV96mmqehbc2 26JYJmj7qz4fvOKBlfSrYTAD6GuXb5NtBt9xXRfwcx0Mxg+fFOb7/bOS27aIH1rU1NjO urGIFfLUo5+m066n+UN0OR16hPevL05Y4YWqka3Ce0FvuuXb7mUpsJG1gTeMco8mOqJc +DKm4C8PjmZ0D3WKmqoAK+KP2noyLKbdpOAp+OH6o18iRGN40G7GIkWsjjhEV5XWCjUY OY3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=F3ppg/2NpeDgiigi9Nn3pNqjcXvptg1LowVouPP88M4=; b=ZLSGsZ0r3tu+XHUllWF1ZspK5+gJU6v6ky91hZhLLCxe/T6OGb67nZjJqUcViY58PC Bz8+TdM74NvKD0160VtAGCITMAiAEDj/DN2wJS3T+3969l/kp9lf6tukXhVOMJoxcpnu 96assHiEWCWV4moHLczwvqxvQ8+L/dtaCwLg1CXxqbVLwGXcBFsIk46tpHZBfpnHbnVx ops6D8sSBhsmYh+eqelO10QhOr8MR90JzQWfR3Ja7BVkI8MBWUGN3XnQn7uUIK8DN52k DXvD+3BOUzP++PvgPt74KYRwZ3t4FYYS6PiSA4IoxpBCEC8mlfrXX7xUpe94/FjoKZaj sNaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7kISlrg; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id d12si13309311iob.58.2018.01.02.01.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7kISlrg; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsR-0002ZR-HC; Tue, 02 Jan 2018 09:28:55 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsQ-0002Yj-2g for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:54 +0000 X-Inumbo-ID: 31480fd7-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x244.google.com (unknown [2607:f8b0:400e:c01::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 31480fd7-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:46 +0100 (CET) Received: by mail-pl0-x244.google.com with SMTP id d21so28337428pll.1 for ; Tue, 02 Jan 2018 01:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e46ZA+vudQcYWtehhJpe9tH+mRvYgBkITiwOt+Mgcjo=; b=D7kISlrgE3nPFoAwY7FFCxrE/WniPhjk8F5dcdisXZMOtDK286+7TIhOLqtjrqR3U0 21OcCgUrETLqVusWhXJ4OFBk5gl6Ejpn8KrbkieTzpvJKHSABuJsOKe+CSqqFR24Thji VP6KSLLMv5vFvZsRwrrnZ9IKeF6UAss8ZeV7k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e46ZA+vudQcYWtehhJpe9tH+mRvYgBkITiwOt+Mgcjo=; b=LbEMYJfCCGb69y8w+autvy7RbVSvwnS7avDd9porAKRPPIiWt5btq8ojdXQt1VYGsW l1Qf8o5eRgXn94Kj3dWj4EMliRqvaeJPmIFnnrx4+v93oyA7YMcxewy8G+XT5TF+ZjJC JdzHmRnXANMibJUzPVzlPNkZsx34IfJH9jBleFhInz5Z0r4v5NbcIndimVbJVXYflf10 HUKPqgDiUfZFZiEP1PxAu1s5hcqVYnPp8lDNuwK8wpl+HKKcbtVDWn14qWfcQ/F8AHff Fb2PK46RjCEdqLDfTol0UtDDwxQyMWx4V4C0xXoLOjL2glWeXhQu37n7w9xZA6KJ+Oem 8/AQ== X-Gm-Message-State: AKGB3mI+SurVL0vIL8oV6F7jwKjrnBOEIcc/t5DK07S+FLwrKFFcL2nu Veflxee/S2FEJ1mdjCgneUoFdWEerPA= X-Received: by 10.84.173.1 with SMTP id o1mr45691220plb.135.1514885331945; Tue, 02 Jan 2018 01:28:51 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:51 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:04 +0530 Message-Id: <20180102092809.1841-7-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 06/11] fwnode xen spacific changes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Merge few more changes from linux kernel code (v4.14) into iommu.c Modify code specifc to xen. Signed-off-by: Manish Jaggi --- xen/drivers/passthrough/iommu.c | 75 +++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 11 ++++-- xen/include/xen/iommu.h | 22 ++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 1aecf7cf34..408f44106d 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -507,6 +508,80 @@ static void iommu_dump_p2m_table(unsigned char key) } } +/** + * fwnode_handle_put - Drop reference to a device node + * @fwnode: Pointer to the device node to drop the reference to. + * + * This has to be used when terminating device_for_each_child_node() iteration + * with break or return to prevent stale device node references from being left + * behind. + */ +void fwnode_handle_put(struct fwnode_handle *fwnode) +{ + fwnode_call_void_op(fwnode, put); +} + +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) +{ + return iommu_get_ops(); +} + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) + return ops == fwspec->ops ? 0 : -EINVAL; + + fwspec = kzalloc(sizeof(*fwspec), GFP_KERNEL); + if (!fwspec) + return -ENOMEM; +#if 0 + of_node_get(to_of_node(iommu_fwnode)); +#endif + fwspec->iommu_fwnode = iommu_fwnode; + fwspec->ops = ops; + dev->iommu_fwspec = fwspec; + return 0; +} + +void iommu_fwspec_free(struct device *dev) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) { + fwnode_handle_put(fwspec->iommu_fwnode); + kfree(fwspec); + dev->iommu_fwspec = NULL; + } +} + +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + size_t size; + int i; + + if (!fwspec) + return -EINVAL; + + size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]); + if (size > sizeof(*fwspec)) { + //TBD: fwspec = krealloc(dev->iommu_fwspec, size, GFP_KERNEL); + if (!fwspec) + return -ENOMEM; + + dev->iommu_fwspec = fwspec; + } + + for (i = 0; i < num_ids; i++) + fwspec->ids[fwspec->num_ids + i] = ids[i]; + + fwspec->num_ids += num_ids; + return 0; + +} /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 6734ae8efd..f78482ca0c 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -6,6 +6,8 @@ enum device_type { DEV_DT, + DEV_ACPI, + DEV_PCI, }; struct dev_archdata { @@ -18,8 +20,13 @@ struct device enum device_type type; #ifdef CONFIG_HAS_DEVICE_TREE struct dt_device_node *of_node; /* Used by drivers imported from Linux */ +#endif +#ifdef CONFIG_ACPI + void *acpi_node; #endif struct dev_archdata archdata; + struct fwnode_handle *fwnode; /* firmware device node */ + struct iommu_fwspec *iommu_fwspec; }; typedef struct device device_t; @@ -27,8 +34,8 @@ 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) +#define dev_is_pci(dev) (dev->type == DEV_PCI) +#define dev_is_dt(dev) (dev->type == DEV_DT) enum device_class { diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 33c8b221dc..56b169bae9 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -208,4 +208,26 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb); extern struct spinlock iommu_pt_cleanup_lock; extern struct page_list_head iommu_pt_cleanup_list; +/** + * struct iommu_fwspec - per-device IOMMU instance data + * @ops: ops for this device's IOMMU + * @iommu_fwnode: firmware handle for this device's IOMMU + * @iommu_priv: IOMMU driver private data for this device + * @num_ids: number of associated device IDs + * @ids: IDs which this device may present to the IOMMU + */ +struct iommu_fwspec { + const struct iommu_ops *ops; + struct fwnode_handle *iommu_fwnode; + void *iommu_priv; + unsigned int num_ids; + u32 ids[1]; +}; + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops); +void iommu_fwspec_free(struct device *dev); +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); + #endif /* _IOMMU_H_ */