From nobody Mon Feb 9 09:52:32 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1566324709; cv=none; d=zoho.com; s=zohoarc; b=l/4L2EdQwP6qCt4l9wimYnPCnMU5fJ15KaGI16KZ96XxxQHs6A5vpR/xvRjxzctqvuBk1ZloC+eiwY7Xg4wi5TuezBsRKvXB+EhGV1WY9WFw9jnFWaIM2ZL0W6AU2nXXbZWq/+CZnI0k9pR4FFk8Bw3pdfl4bdCZoKVZtK8LWu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566324709; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mLjpToMI8eltCKARhGSigbuPyUXbe+tvIUlV99IPE0I=; b=DrfpOWbGvgnxMbr7Z8MP6uKH9WodJ4JP0r9yE+YUHAwkgSSWO5By0r3YeMFNRF131MrEa8XSJ4X/h/bnCy4wnlBzl7p1WbxJn7Wy2ScFI0NbBig45DUz4VqMX4bchHnTVnHQts3zjVuW0HM3vkjUxv9udQSm0iSqbZdOQhE6Etc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1566324709798856.861720120977; Tue, 20 Aug 2019 11:11:49 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i08aZ-0006Bk-0M; Tue, 20 Aug 2019 18:10:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i08aY-0006BN-1F for xen-devel@lists.xenproject.org; Tue, 20 Aug 2019 18:10:34 +0000 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c11d7b68-c375-11e9-9a4a-bc764e2007e4; Tue, 20 Aug 2019 18:10:13 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id b29so4845313lfq.1 for ; Tue, 20 Aug 2019 11:10:13 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id f6sm2900642lja.16.2019.08.20.11.10.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Aug 2019 11:10:11 -0700 (PDT) X-Inumbo-ID: c11d7b68-c375-11e9-9a4a-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GAgFw36gC429acSBqct8LFinzu2sDTtm3GCzrKesNfY=; b=U9lKusa5b6l8i31SXujZLTZm70HnKan8FM3+wteqam1S4CTHvCVNY+yUoFAOwhagUS Ew0+zjzGRGnS8aJd27+OJgrW6Q2oUyzZmNhhTYC6wG3amGLGXyttV0eY9SP/dteqUR06 Z1W+Gg+Ram65xPi5LWVEzDgoiZBkqMqh7WVG5g1NX4er7urVUNwwI32NqZyjm1SNXe0U tPKXiCd6g522j/yC91/HVfMwUxFFClpgXdBdbk9nynsHsEk+iUPXbFmWRZBbW6a9Kuhs MRcovF83BHZ5Nnkuaxh9HgrN87k8mzd4rzKY0mzP5ZDgWc8kUf737odvB0G/UUzPu+h9 i5Fg== 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=GAgFw36gC429acSBqct8LFinzu2sDTtm3GCzrKesNfY=; b=YZAZWdGnBgkfooQvPo/u0zRxhZiKMfBDiFdmADDRMFhOw+1MWBGU6jmSU6fxT/cicL S1bP0ZUnMVVwiiyYkCXMprhu7Ucdph21LpKa9ZZUHSg2DD33IH5KY7T2X2vKr5oU+yZD glaWsaIXaceHSb20EHERuAnli5QsmSF/FdFhxK0sROK8Dir65TlsYtkDNqODG08p1Na/ iVkJ9gPUKziRdFxwoiXhu2DfUfXjrjRKBRFOvfzsVMIiUbzp/JiVhnWJZre7EDtHBmth 21/IEuWq3KKJXT4p+AOS9pKlC2ZZSBPLs9Fyj4XY77A/pj1zarm7/EONkNtWx/gYamlZ 7Eyg== X-Gm-Message-State: APjAAAW+xx1H4NT93ipKN0e/iecg//8vuh/fouEb7sRNgjtlh2zfIUUh BbcO6O8kgDZnXmNBtvj3gwBWYUlA X-Google-Smtp-Source: APXvYqxe8zKknAvvewRip0aqjs3rjpp7Uk2pyiDktc3mK58q4zGm/xg7XIGpi4efZiRgCLBblGPV4w== X-Received: by 2002:a05:6512:1da:: with SMTP id f26mr16171776lfp.129.1566324612364; Tue, 20 Aug 2019 11:10:12 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 20 Aug 2019 21:09:44 +0300 Message-Id: <1566324587-3442-6-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1566324587-3442-1-git-send-email-olekstysh@gmail.com> References: <1566324587-3442-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V3 5/8] iommu/arm: Add lightweight iommu_fwspec support X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Oleksandr Tyshchenko We need to have some abstract way to add new device to the IOMMU based on the generic IOMMU DT bindings [1] which can be used for both DT (right now) and ACPI (in future). For that reason we can borrow the idea used in Linux these days called "iommu_fwspec". Having this in, it will be possible to configure IOMMU master interfaces of the device (device IDs) from a single common place and avoid keeping almost identical look-up implementations in each IOMMU driver. There is no need to port the whole implementation of "iommu_fwspec" to Xen, we could, probably, end up with a much simpler solution, some "stripped down" version which fits our requirements. So, this patch adds the following: 1. A common structure "iommu_fwspec" to hold the the per-device firmware data 2. New member "iommu_fwspec" of struct device 3. Functions/helpers to deal with "dev->iommu_fwspec" It should be noted that in comparing with original "iommu_fwspec" Xen's variant doesn't contain some fields, which are not really needed at the moment (ops, flag) and "iommu_fwnode" field was replaced by "iommu_dev" to avoid porting a lot of code (to support "fwnode_handle") with little benefit. Subsequent patches will use of that support. [1] https://www.kernel.org/doc/Documentation/devicetree/bindings/iommu/iomm= u.txt Signed-off-by: Oleksandr Tyshchenko CC: Julien Grall --- Changes V2 -> V3: - added Copyright from Linux - ordered the headers alphabetically - removed check for not a NULL before calling xfree() - used unsigned for variables which can't be negative - removed #include from iommu.h - added check to iommu_fwspec_init() to not allow overriding - clarified comments in code - modified iommu_fwspec_add_ids() to use type-safe xrealloc_flex_struct= () --- xen/drivers/passthrough/arm/Makefile | 2 +- xen/drivers/passthrough/arm/iommu_fwspec.c | 94 ++++++++++++++++++++++++++= ++++ xen/include/asm-arm/device.h | 1 + xen/include/asm-arm/iommu_fwspec.h | 68 +++++++++++++++++++++ 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 xen/drivers/passthrough/arm/iommu_fwspec.c create mode 100644 xen/include/asm-arm/iommu_fwspec.h diff --git a/xen/drivers/passthrough/arm/Makefile b/xen/drivers/passthrough= /arm/Makefile index 4abb87a..5fbad45 100644 --- a/xen/drivers/passthrough/arm/Makefile +++ b/xen/drivers/passthrough/arm/Makefile @@ -1,2 +1,2 @@ -obj-y +=3D iommu.o iommu_helpers.o +obj-y +=3D iommu.o iommu_helpers.o iommu_fwspec.o obj-$(CONFIG_ARM_SMMU) +=3D smmu.o diff --git a/xen/drivers/passthrough/arm/iommu_fwspec.c b/xen/drivers/passt= hrough/arm/iommu_fwspec.c new file mode 100644 index 0000000..12b8bae --- /dev/null +++ b/xen/drivers/passthrough/arm/iommu_fwspec.c @@ -0,0 +1,94 @@ +/* + * xen/drivers/passthrough/arm/iommu_fwspec.c + * + * Contains functions to maintain per-device firmware data + * + * Based on Linux's iommu_fwspec support you can find at: + * drivers/iommu/iommu.c + * + * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. + * + * Copyright (C) 2019 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#include +#include + +#include +#include + +int iommu_fwspec_init(struct device *dev, struct device *iommu_dev) +{ + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + + if ( fwspec ) + { + /* We expect the device to be protected by only one IOMMU. */ + if ( fwspec->iommu_dev !=3D iommu_dev ) + return -EINVAL; + + return 0; + } + + fwspec =3D xzalloc(struct iommu_fwspec); + if ( !fwspec ) + return -ENOMEM; + + fwspec->iommu_dev =3D iommu_dev; + dev_iommu_fwspec_set(dev, fwspec); + + return 0; +} + +void iommu_fwspec_free(struct device *dev) +{ + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + + xfree(fwspec); + dev_iommu_fwspec_set(dev, NULL); +} + +int iommu_fwspec_add_ids(struct device *dev, uint32_t *ids, + unsigned int num_ids) +{ + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + unsigned int i; + + if ( !fwspec ) + return -EINVAL; + + fwspec =3D xrealloc_flex_struct(fwspec, struct iommu_fwspec, ids, + fwspec->num_ids + num_ids); + if ( !fwspec ) + return -ENOMEM; + + dev_iommu_fwspec_set(dev, fwspec); + + for ( i =3D 0; i < num_ids; i++ ) + fwspec->ids[fwspec->num_ids + i] =3D ids[i]; + + fwspec->num_ids +=3D num_ids; + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index ee1c3bc..ee7cff2 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -18,6 +18,7 @@ struct device struct dt_device_node *of_node; /* Used by drivers imported from Linux= */ #endif struct dev_archdata archdata; + struct iommu_fwspec *iommu_fwspec; /* per-device IOMMU instance data */ }; =20 typedef struct device device_t; diff --git a/xen/include/asm-arm/iommu_fwspec.h b/xen/include/asm-arm/iommu= _fwspec.h new file mode 100644 index 0000000..8ce4da1 --- /dev/null +++ b/xen/include/asm-arm/iommu_fwspec.h @@ -0,0 +1,68 @@ +/* + * xen/include/asm-arm/iommu_fwspec.h + * + * Contains a common structure to hold the per-device firmware data and + * declaration of functions used to maintain that data + * + * Based on Linux's iommu_fwspec support you can find at: + * include/linux/iommu.h + * + * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. + * + * Copyright (C) 2019 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#ifndef __ARCH_ARM_IOMMU_FWSPEC_H__ +#define __ARCH_ARM_IOMMU_FWSPEC_H__ + +/* per-device IOMMU instance data */ +struct iommu_fwspec { + /* this device's IOMMU */ + struct device *iommu_dev; + /* IOMMU driver private data for this device */ + void *iommu_priv; + /* number of associated device IDs */ + unsigned int num_ids; + /* IDs which this device may present to the IOMMU */ + uint32_t ids[1]; +}; + +int iommu_fwspec_init(struct device *dev, struct device *iommu_dev); +void iommu_fwspec_free(struct device *dev); +int iommu_fwspec_add_ids(struct device *dev, uint32_t *ids, + unsigned int num_ids); + +static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev) +{ + return dev->iommu_fwspec; +} + +static inline void dev_iommu_fwspec_set(struct device *dev, + struct iommu_fwspec *fwspec) +{ + dev->iommu_fwspec =3D fwspec; +} + +#endif /* __ARCH_ARM_IOMMU_FWSPEC_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel