From patchwork Tue Oct 27 11:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11859989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43CEBC388F9 for ; Tue, 27 Oct 2020 11:29:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B30952072D for ; Tue, 27 Oct 2020 11:29:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WItC99Xd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B30952072D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=maMIGfuW8vPUKdM2naduPerYGHhAyVwPFBQ4w2BCwos=; b=WItC99Xdt2IRbkrQBmeo4Kmhc L0Z7iAG6UuIgmHloocaKLX/I+zweNBvNxHLYQYK526Debjt4w9u9lroX6l6TvKMZ5XD67QwA5DjQh e5OP75K5rztHgc/baxQoVJizXXL3qPuNW+1bdN/JA02vFUxcME81vtC1kig2921nmhgSWKikL61Xr JVzc78WSjC1R6HjYvErinh7TtqzTq1lT6VH2Nzj3K7YziwjCS51bm0hqCtNTFK3ya8YSmw4mT64nm gmI8REIHCkBY6cVrhx/8utHj5Olvco29+Kwsj0VHY9TwAMusvQHsl9mF0eQfXPIkB+ZComAcq2qFM TMvtGUvTQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9r-0001t2-4a; Tue, 27 Oct 2020 11:28:55 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9E-0001Zm-8Q for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 11:28:21 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CL8Zt1Yshz6wN3; Tue, 27 Oct 2020 19:28:06 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.15) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 19:27:54 +0800 From: Shameer Kolothum To: , , , Subject: [RFC PATCH 1/4] ACPICA: IORT: Update for revision E Date: Tue, 27 Oct 2020 11:26:43 +0000 Message-ID: <20201027112646.44680-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> References: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.15] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_072816_721387_A40B5588 X-CRM114-Status: GOOD ( 11.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, joro@8bytes.org, jonathan.cameron@huawei.com, linuxarm@huawei.com, guohanjun@huawei.com, robin.murphy@arm.com, wanghuiqiang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org IORT revision E contains a few additions like,     -Added an identifier field in the node descriptors to aid table      cross-referencing.     -Introduced the Reserved Memory Range(RMR) node. This is used     to describe memory ranges that are used by endpoints and requires     a unity mapping in SMMU. -Introduced a flag in the RC node to express support for PRI. Signed-off-by: Shameer Kolothum --- -This should be updated through acpica git. I have sent out a pull request for the same here, https://github.com/acpica/acpica/pull/638 Please help to review. --- include/acpi/actbl2.h | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index ec66779cb193..274fce7b5c01 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -68,7 +68,7 @@ * IORT - IO Remapping Table * * Conforms to "IO Remapping Table System Software on ARM Platforms", - * Document number: ARM DEN 0049D, March 2018 + * Document number: ARM DEN 0049E, June 2020 * ******************************************************************************/ @@ -86,7 +86,8 @@ struct acpi_iort_node { u8 type; u16 length; u8 revision; - u32 reserved; + u16 reserved; + u16 identifier; u32 mapping_count; u32 mapping_offset; char node_data[1]; @@ -100,7 +101,8 @@ enum acpi_iort_node_type { ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02, ACPI_IORT_NODE_SMMU = 0x03, ACPI_IORT_NODE_SMMU_V3 = 0x04, - ACPI_IORT_NODE_PMCG = 0x05 + ACPI_IORT_NODE_PMCG = 0x05, + ACPI_IORT_NODE_RMR = 0x06, }; struct acpi_iort_id_mapping { @@ -167,10 +169,10 @@ struct acpi_iort_root_complex { u8 reserved[3]; /* Reserved, must be zero */ }; -/* Values for ats_attribute field above */ +/* Masks for ats_attribute field above */ -#define ACPI_IORT_ATS_SUPPORTED 0x00000001 /* The root complex supports ATS */ -#define ACPI_IORT_ATS_UNSUPPORTED 0x00000000 /* The root complex doesn't support ATS */ +#define ACPI_IORT_ATS_SUPPORTED (1) /* The root complex supports ATS */ +#define ACPI_IORT_PRI_SUPPORTED (1<<1) /* The root complex supports PRI */ struct acpi_iort_smmu { u64 base_address; /* SMMU base address */ @@ -241,6 +243,17 @@ struct acpi_iort_pmcg { u64 page1_base_address; }; +struct acpi_iort_rmr { + u32 rmr_count; + u32 rmr_offset; +}; + +struct acpi_iort_rmr_desc { + u64 base_address; + u64 length; + u32 reserved; +}; + /******************************************************************************* * * IVRS - I/O Virtualization Reporting Structure From patchwork Tue Oct 27 11:26:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11859967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43F41C55178 for ; Tue, 27 Oct 2020 11:29:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C26F32072D for ; Tue, 27 Oct 2020 11:29:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ybv0mlS6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C26F32072D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KMIyYGHcu8zUL0libMIPGc72DOOB6v9O7gxagCErQ9w=; b=Ybv0mlS6pzJ71+/FVmqpxpgTF XeUTU1atCqy9KrASve72sIA8G+K17HvsWLTVj42CS/lesaeY1NOFJfrbP8TDIjeFIz6s+6iXAiA/X mDqCEMJ+anK8a8ZY4hvsgvTK95PknGOOdZbf1HGPhiazhhBT318q9R/7V1xr/bIDLpEvZNn83z7jC WoDBgMv9UmEXIiMop4ZL1Dyosj50L5J2FkajTWfLCZp+EYho34qgYMlUvXyRKFmf0UlakWJtGWHgm hCOTxpoed/K++mAD2SVpBx/M8m0xecnOoHrauKI9byW3gmAXX2pUnQtH7Iz53tnmyIpXoveC9t3VL JsHE3FJrQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9K-0001h6-AG; Tue, 27 Oct 2020 11:28:22 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9C-0001aR-DC for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 11:28:17 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CL8Zz4nPpzhcP9; Tue, 27 Oct 2020 19:28:11 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.15) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 19:27:59 +0800 From: Shameer Kolothum To: , , , Subject: [RFC PATCH 2/4] ACPI/IORT: Add support for RMR node parsing Date: Tue, 27 Oct 2020 11:26:44 +0000 Message-ID: <20201027112646.44680-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> References: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.15] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_072815_569959_9AD3BC56 X-CRM114-Status: GOOD ( 17.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, joro@8bytes.org, jonathan.cameron@huawei.com, linuxarm@huawei.com, guohanjun@huawei.com, robin.murphy@arm.com, wanghuiqiang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for parsing RMR node information from ACPI. Find associated stream ids and smmu node info from the RMR node and populate a linked list with RMR memory descriptors. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 119 +++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 9929ff50c0c0..b32cd53cca08 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -40,6 +40,25 @@ struct iort_fwnode { static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); +struct iort_rmr_id { + u32 sid; + struct acpi_iort_node *smmu; +}; + +/* + * One entry for IORT RMR. + */ +struct iort_rmr_entry { + struct list_head list; + + unsigned int rmr_ids_num; + struct iort_rmr_id *rmr_ids; + + struct acpi_iort_rmr_desc *rmr_desc; +}; + +static LIST_HEAD(iort_rmr_list); /* list of RMR regions from ACPI */ + /** * iort_set_fwnode() - Create iort_fwnode and use it to register * iommu data in the iort_fwnode_list @@ -393,7 +412,8 @@ static struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX || node->type == ACPI_IORT_NODE_SMMU_V3 || - node->type == ACPI_IORT_NODE_PMCG) { + node->type == ACPI_IORT_NODE_PMCG || + node->type == ACPI_IORT_NODE_RMR) { *id_out = map->output_base; return parent; } @@ -1647,6 +1667,100 @@ static void __init iort_enable_acs(struct acpi_iort_node *iort_node) #else static inline void iort_enable_acs(struct acpi_iort_node *iort_node) { } #endif +static int iort_rmr_desc_valid(struct acpi_iort_rmr_desc *desc) +{ + struct iort_rmr_entry *e; + u64 end, start = desc->base_address, length = desc->length; + + if ((!IS_ALIGNED(start, SZ_64K)) || (length % SZ_64K != 0)) + return -EINVAL; + + end = start + length - 1; + + /* Check for address overlap */ + list_for_each_entry(e, &iort_rmr_list, list) { + u64 e_start = e->rmr_desc->base_address; + u64 e_end = e_start + e->rmr_desc->length - 1; + + if (start <= e_end && end >= e_start) + return -EINVAL; + } + + return 0; +} + +static int __init iort_parse_rmr(struct acpi_iort_node *iort_node) +{ + struct iort_rmr_id *rmr_ids, *ids; + struct iort_rmr_entry *e; + struct acpi_iort_rmr *rmr; + struct acpi_iort_rmr_desc *rmr_desc; + u32 map_count = iort_node->mapping_count; + int i, ret = 0, desc_count = 0; + + if (iort_node->type != ACPI_IORT_NODE_RMR) + return 0; + + if (!iort_node->mapping_offset || !map_count) { + pr_err(FW_BUG "Invalid ID mapping, skipping RMR node %p\n", + iort_node); + return -EINVAL; + } + + rmr_ids = kmalloc(sizeof(*rmr_ids) * map_count, GFP_KERNEL); + if (!rmr_ids) + return -ENOMEM; + + /* Retrieve associated smmu and stream id */ + ids = rmr_ids; + for (i = 0; i < map_count; i++, ids++) { + ids->smmu = iort_node_get_id(iort_node, &ids->sid, i); + if (!ids->smmu) { + pr_err(FW_BUG "Invalid SMMU reference, skipping RMR node %p\n", + iort_node); + ret = -EINVAL; + goto out; + } + } + + /* Retrieve RMR data */ + rmr = (struct acpi_iort_rmr *)iort_node->node_data; + if (!rmr->rmr_offset || !rmr->rmr_count) { + pr_err(FW_BUG "Invalid RMR descriptor array, skipping RMR node %p\n", + iort_node); + ret = -EINVAL; + goto out; + } + + rmr_desc = ACPI_ADD_PTR(struct acpi_iort_rmr_desc, iort_node, + rmr->rmr_offset); + + for (i = 0; i < rmr->rmr_count; i++, rmr_desc++) { + ret = iort_rmr_desc_valid(rmr_desc); + if (ret) { + pr_err(FW_BUG "Invalid RMR descriptor[%d] for node %p, skipping...\n", + i, iort_node); + goto out; + } + + e = kmalloc(sizeof(*e), GFP_KERNEL); + if (!e) + goto out; + e->rmr_ids_num = map_count; + e->rmr_ids = rmr_ids; + e->rmr_desc = rmr_desc; + + list_add_tail(&e->list, &iort_rmr_list); + desc_count++; + } + + return 0; + +out: + if (!desc_count) + kfree(rmr_ids); + return ret; +} static void __init iort_init_platform_devices(void) { @@ -1676,6 +1790,9 @@ static void __init iort_init_platform_devices(void) iort_enable_acs(iort_node); + if (iort_table->revision == 1) + iort_parse_rmr(iort_node); + ops = iort_get_dev_cfg(iort_node); if (ops) { fwnode = acpi_alloc_fwnode_static(); From patchwork Tue Oct 27 11:26:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11859991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F870C388F9 for ; Tue, 27 Oct 2020 11:30:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BEABF22258 for ; Tue, 27 Oct 2020 11:30:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="z3D+bMfy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEABF22258 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mK4fAlvxgZ/+/7QV13A5DmsncgMgDv4cKjJBh3VIfgI=; b=z3D+bMfyO8fifcn07sdmBONV6 l1gVk3D6uB2OIFUO2uySoVpe6K8eGVo836t1dOaET+p/HaBffnTNxltOcrjgi2Xkamft5RdpWcpTw olo4QF0jNpANtyDlUFMbbiJO10q7A+fAG79c+stSS43o+tnmS7EEBLK/ngfYEdqPhVxG2rnaPQhwa n4ymdxBPbx1kZ6ry/fIv53WZCTm7gdvLg5WE8CVowf2VexdjFN8HmvfH+xz7v2YX1iUk29+ZnYcP6 vsolP+oM65SLZ2thzeirWKLIW8kEu3qs/SUii7djWO++5oCiVKrYWN5x7VFB+C61caB5+1vfVvpfN j8vymO+pQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9T-0001kZ-KW; Tue, 27 Oct 2020 11:28:31 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9D-0001c6-5I for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 11:28:20 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CL8b36LVczkZs1; Tue, 27 Oct 2020 19:28:15 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.15) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 19:28:05 +0800 From: Shameer Kolothum To: , , , Subject: [RFC PATCH 3/4] ACPI/IORT: Add RMR memory regions reservation helper Date: Tue, 27 Oct 2020 11:26:45 +0000 Message-ID: <20201027112646.44680-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> References: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.15] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_072815_937442_8676FA2F X-CRM114-Status: GOOD ( 14.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, joro@8bytes.org, jonathan.cameron@huawei.com, linuxarm@huawei.com, guohanjun@huawei.com, robin.murphy@arm.com, wanghuiqiang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a helper function that retrieves RMR memory descriptors associated with a given endpoint dev. These memory regions should have a unity mapping in the SMMU. So reserve them as IOMMU_RESV_DIRECT. Signed-off-by: Shameer Kolothum --- drivers/acpi/arm64/iort.c | 56 +++++++++++++++++++++++++++++++++++++++ include/linux/acpi_iort.h | 4 +++ 2 files changed, 60 insertions(+) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index b32cd53cca08..c0700149e60b 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -842,6 +842,60 @@ static inline int iort_add_device_replay(struct device *dev) return err; } +static bool iort_dev_has_rmr(struct device *dev, struct iort_rmr_entry *e) +{ + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct acpi_iort_node *iommu; + struct iort_rmr_id *rmr_ids = e->rmr_ids; + int i, j; + + iommu = iort_get_iort_node(fwspec->iommu_fwnode); + + for (i = 0; i < e->rmr_ids_num; i++, rmr_ids++) { + for (j = 0; j < fwspec->num_ids; j++) { + if (rmr_ids->sid == fwspec->ids[j] && + rmr_ids->smmu == iommu) + return true; + } + } + + return false; +} + +/** + * iort_dev_rmr_get_resv_regions - RMR Reserved region driver helper + * @dev: Device from iommu_get_resv_regions() + * @head: Reserved region list from iommu_get_resv_regions() + * + * Returns: 0 on success, <0 failure + */ +int iort_dev_rmr_get_resv_regions(struct device *dev, struct list_head *head) +{ + struct iort_rmr_entry *e; + + list_for_each_entry(e, &iort_rmr_list, list) { + struct iommu_resv_region *region; + struct acpi_iort_rmr_desc *rmr; + int prot = IOMMU_READ | IOMMU_WRITE | + IOMMU_NOEXEC | IOMMU_MMIO; + + if (!iort_dev_has_rmr(dev, e)) + continue; + + rmr = e->rmr_desc; + region = iommu_alloc_resv_region(rmr->base_address, + rmr->length, prot, + IOMMU_RESV_DIRECT); + if (!region) { + dev_err(dev, "Out of memory allocating RMR regions\n"); + return -ENOMEM; + } + list_add_tail(®ion->list, head); + } + + return 0; +} + /** * iort_iommu_msi_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() @@ -1112,6 +1166,8 @@ int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return NULL; } +int iort_dev_rmr_get_resv_regions(struct device *dev, struct list_head *head) +{ return 0; } #endif static int nc_dma_get_range(struct device *dev, u64 *size) diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 20a32120bb88..6dd89faf340c 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -38,6 +38,7 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size); const struct iommu_ops *iort_iommu_configure_id(struct device *dev, const u32 *id_in); int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); +int iort_dev_rmr_get_resv_regions(struct device *dev, struct list_head *head); #else static inline void acpi_iort_init(void) { } static inline u32 iort_msi_map_id(struct device *dev, u32 id) @@ -55,6 +56,9 @@ static inline const struct iommu_ops *iort_iommu_configure_id( static inline int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) { return 0; } +static inline +int iort_dev_rmr_get_resv_regions(struct device *dev, struct list_head *head) +{ return 0; } #endif #endif /* __ACPI_IORT_H__ */ From patchwork Tue Oct 27 11:26:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 11860025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A662C55179 for ; Tue, 27 Oct 2020 11:31:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1BBC722284 for ; Tue, 27 Oct 2020 11:31:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cp+nhiGK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1BBC722284 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SRsxBTpXXLv+IiKwrfTCiNuYqK3Sa/DLtFeNT7W9fCk=; b=cp+nhiGKw/evKaU/5e6/ghRK3 64Qo+PsVqB4IUMklNBeq3Vz0cQssTWlBHRUwRyDrAO6AnSltbcXywtt3bOTs4shVlFg+yKxlBh3iT KS17HLgxLc+IbR97321EmJM7+C6rLkpyXIHyoP/jFf58TyYXhq/RNs1HMjOcEPcnsyNSbyYgjru3o 0+wtcgGuPX21yK7KwCziNX+SqjoYJmYlb89dsEXTnx0CFNgZH63ueEwMjy7BpJbndoyql4qo4ZUuG 0eUFYNBIUCRACf5Wp2lneVsMR47zdRTtx+EIZoGm/6iupUNMSS3CoYaU26h5MYJcW35WBNlLaBZcV 0HaGwiRqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXNAB-000208-JW; Tue, 27 Oct 2020 11:29:15 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXN9H-0001fk-3f for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 11:28:21 +0000 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CL8b93CqPz6wlp; Tue, 27 Oct 2020 19:28:21 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.47.24.15) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 19:28:10 +0800 From: Shameer Kolothum To: , , , Subject: [RFC PATCH 4/4] iommu/dma: Reserve any RMR regions associated with a dev Date: Tue, 27 Oct 2020 11:26:46 +0000 Message-ID: <20201027112646.44680-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> References: <20201027112646.44680-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.24.15] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_072819_484671_3A01BB3F X-CRM114-Status: GOOD ( 10.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, joro@8bytes.org, jonathan.cameron@huawei.com, linuxarm@huawei.com, guohanjun@huawei.com, robin.murphy@arm.com, wanghuiqiang@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Added support to get RMR regions associated with a dev reserved so that there is a unity mapping for them in SMMU. Signed-off-by: Shameer Kolothum --- drivers/iommu/dma-iommu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 0cbcd3fc3e7e..31eec16f2af8 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -153,15 +153,19 @@ EXPORT_SYMBOL(iommu_put_dma_cookie); * @list: Reserved region list from iommu_get_resv_regions() * * IOMMU drivers can use this to implement their .get_resv_regions callback - * for general non-IOMMU-specific reservations. Currently, this covers GICv3 - * ITS region reservation on ACPI based ARM platforms that may require HW MSI - * reservation. + * for general non-IOMMU-specific reservations. Currently this covers, + * - GICv3 ITS region reservation on ACPI based ARM platforms that may + * require HW MSI reservation. + * - ACPI IORT RMR memory range reservations that require a unity mapping + * in the SMMU for a given endpoint device. */ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) { - if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) + if (!is_of_node(dev_iommu_fwspec_get(dev)->iommu_fwnode)) { iort_iommu_msi_get_resv_regions(dev, list); + iort_dev_rmr_get_resv_regions(dev, list); + } } EXPORT_SYMBOL(iommu_dma_get_resv_regions);