From nobody Tue Feb 10 08:41:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1661182079900627.9780175114479; Mon, 22 Aug 2022 08:27:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.391471.629345 (Exim 4.92) (envelope-from ) id 1oQ9L0-00046Z-VR; Mon, 22 Aug 2022 15:27:38 +0000 Received: by outflank-mailman (output) from mailman id 391471.629345; Mon, 22 Aug 2022 15:27:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQ9L0-00045r-Pm; Mon, 22 Aug 2022 15:27:38 +0000 Received: by outflank-mailman (input) for mailman id 391471; Mon, 22 Aug 2022 15:27:37 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQ9Kz-0003iu-Ao for xen-devel@lists.xenproject.org; Mon, 22 Aug 2022 15:27:37 +0000 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f1599435-222e-11ed-9250-1f966e50362f; Mon, 22 Aug 2022 17:27:34 +0200 (CEST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 4190D3200A50; Mon, 22 Aug 2022 11:27:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 22 Aug 2022 11:27:32 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 22 Aug 2022 11:27:30 -0400 (EDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f1599435-222e-11ed-9250-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1661182051; x=1661268451; bh=MP94SeiKov HRK4tURowdKY0S3+uktUUWGY/VTPo7IQM=; b=rVpDZoD2EgVX+qb2vU7p3HE/9m XcT4UVqyjRZuGxqiSWPtxz68mY1eKv10MIdNIhUEXNv15BJsbJE63PrD1008ZN62 wI4RCJ+6hrscsRfkSomTmKqYB3Rqfu6htE4e09Gaq2SkXZmRepVIP9LEG9QLFQwv 7bK8hoqnIkmQa5JJgxyNKI37xLzxhdr5VxhkHvKJG8eqAveK6NEQ9tOdlpPXF1tP +MAAPlwvZdPWT1zE+jVzXwXbdB0J8DG6eWZED8P7TlwXBMZPsAUfbnOUnf7x7uyd QIt2a5FFGOGVbE2XrPcuG8zGknhQfl/He9Yd2uDSJ+vQgA2zRAmrVltUPB2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1661182051; x= 1661268451; bh=MP94SeiKovHRK4tURowdKY0S3+uktUUWGY/VTPo7IQM=; b=v YYp6GZrJaYSmsY8/pPoywMyt2ZxSMjwhaI4DQ53g+gmUhjrIddgEvuQtXtF4SGsm QWGaqBTZM/UoeVWGLfU5XOIGW4XpB2a24o5epCKqbsuGPDfO6L71HiLKjZNkUi7R YaQXnFvJeJXhiNszjcCNuRlZzSs2WxffSzG3aIKOGHhvW8eENsRSRdEF281XQN+T 65TGENKlPbU03R9vP0lCq/vGIglxVjwhMvk396+HsLDuSRJti6CMIbt2sPie2DEv muI92oOA2j2BgZeN2TA0Nr9nyYGAcYn9WLnpx1ELBNAIRVRj8P3Bq7V2nBsYmEQP GYQrykhvtNqlcmT9Zxs6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdeijedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpefg ueduhefgvdefheehudejheefudevueeghfekhfehleegveduteeuiedugffgffenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgv khesihhnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhm X-ME-Proxy: Feedback-ID: i1568416f:Fastmail From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v5 3/9] IOMMU: add common API for device reserved memory Date: Mon, 22 Aug 2022 17:27:03 +0200 Message-Id: <3ee5187c066ad12e3717df6fed41de99172271b0.1661181584.git-series.marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1661182081919100009 Add API similar to rmrr=3D and ivmd=3D arguments, but in a common code. This will allow drivers to register reserved memory regardless of the IOMMU vendor. The direct reason for this API is xhci-dbc console driver (aka xue), that needs to use DMA. But future change may unify command line arguments for user-supplied reserved memory, and it may be useful for other drivers in the future too. This commit just introduces an API, subsequent patches will plug it in appropriate places. The reserved memory ranges needs to be saved locally, because at the point when they are collected, Xen doesn't know yet which IOMMU driver will be used. Signed-off-by: Marek Marczykowski-G=C3=B3recki Acked-by: Jan Beulich --- Changes in v5: - fix indentation, keep full "reserved_device_memory" for consistency with iommu_get_reserved_device_memory Changes in v4: - mark functions as __init - use pci_sbdf_t type Changes in v3: - adjust code style --- xen/drivers/passthrough/iommu.c | 46 ++++++++++++++++++++++++++++++++++- xen/include/xen/iommu.h | 14 ++++++++++- 2 files changed, 60 insertions(+) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 134cdb47e0dc..5e2a720d29b9 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -669,6 +669,52 @@ bool_t iommu_has_feature(struct domain *d, enum iommu_= feature feature) return is_iommu_enabled(d) && test_bit(feature, dom_iommu(d)->features= ); } =20 +#define MAX_EXTRA_RESERVED_RANGES 20 +struct extra_reserved_range { + unsigned long start; + unsigned long nr; + pci_sbdf_t sbdf; +}; +static unsigned int __initdata nr_extra_reserved_ranges; +static struct extra_reserved_range __initdata + extra_reserved_ranges[MAX_EXTRA_RESERVED_RANGES]; + +int __init iommu_add_extra_reserved_device_memory(unsigned long start, + unsigned long nr, + pci_sbdf_t sbdf) +{ + unsigned int idx; + + if ( nr_extra_reserved_ranges >=3D MAX_EXTRA_RESERVED_RANGES ) + return -ENOMEM; + + idx =3D nr_extra_reserved_ranges++; + extra_reserved_ranges[idx].start =3D start; + extra_reserved_ranges[idx].nr =3D nr; + extra_reserved_ranges[idx].sbdf =3D sbdf; + + return 0; +} + +int __init iommu_get_extra_reserved_device_memory(iommu_grdm_t *func, + void *ctxt) +{ + unsigned int idx; + int ret; + + for ( idx =3D 0; idx < nr_extra_reserved_ranges; idx++ ) + { + ret =3D func(extra_reserved_ranges[idx].start, + extra_reserved_ranges[idx].nr, + extra_reserved_ranges[idx].sbdf.sbdf, + ctxt); + if ( ret < 0 ) + return ret; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 1240d7762d99..4f22fc1bed55 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -304,6 +304,20 @@ struct iommu_ops { #endif }; =20 +/* + * To be called by Xen internally, to register extra RMRR/IVMD ranges. + * Needs to be called before IOMMU initialization. + */ +extern int iommu_add_extra_reserved_device_memory(unsigned long start, + unsigned long nr, + pci_sbdf_t sbdf); +/* + * To be called by specific IOMMU driver during initialization, + * to fetch ranges registered with iommu_add_extra_reserved_device_memory(= ). + */ +extern int iommu_get_extra_reserved_device_memory(iommu_grdm_t *func, + void *ctxt); + #include =20 #ifndef iommu_call --=20 git-series 0.9.1