From patchwork Thu Nov 19 12:11: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: 328401 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp361480ils; Thu, 19 Nov 2020 04:13:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPIXGzXc/pUHLB/Lu8dairRuF825+Moff/9LDgYDIAcb4kr2A13CtQCYoxxGZxk80wJgN5 X-Received: by 2002:a05:6402:14cf:: with SMTP id f15mr29803203edx.18.1605788031785; Thu, 19 Nov 2020 04:13:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605788031; cv=none; d=google.com; s=arc-20160816; b=AzGKyEYywU33hxuze3+R5Ev5Weul8FAqBmkVJ0lzBaJ7SjomHg8hGqefh3+gr3VYCy DY7VU89nKB4uTt6ykhOMvssuvwZzpe7toa6jXHdXBbY5dJrF6eUe2DIT3sHsLxFYC1tE o49deVveWNFY3sIxeX7ljN0vmm3nJVm6PqW8nFPe0DTgZR7u03GcdXiNjWe1b0T3JRTa xk9uUYcSsQtiNtPF4bIPHPNUMnt3YcMRMZVXsklifif5zzRfG4P/3kWuKUWCvd5Tvqyk GVpF7WUvLEq4y5W34pEv875QEWKiTjL8oo9qNp7ZqFBbalhUYZaM+4iNjCbKzgB5lgir LGFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qma9EmGJanhEMidTo22Oa2pciz5Y3GPxkmcWGw8wP2Y=; b=rg+iwYwxL3JgpsSb6yP0qVEw1AL37s0rrrhVmiw/3ngc8YNne1LKvGZXI06Crz8Se6 Dq2nT1hqnva7juARbrPxjm6RCYmEFVDoZMEp3Mt1fMJRTZKAE3QTuRbtumKwqtl9vRfU Nh7nmKAyONEm1m+NnEMB02ixlyKPxDBgPa+ASVdP8Ckx7S3lCa4AQngDdnXjC94ijHcv 2fu7EylQH3hDlVGVGVFWp5ygYxXgv8KXeBU8Q7N43VGCjFGm0qPi8ekQSiJ3KeS5LasB AxfU5zEgvXfs6saKIVJNtmGffgIrkKRrjdzBT5TasVriZz+QDg98oEdW1X4Zu8D6D5K7 BTrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc4si16705640ejb.188.2020.11.19.04.13.51; Thu, 19 Nov 2020 04:13:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-acpi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbgKSMMm (ORCPT + 5 others); Thu, 19 Nov 2020 07:12:42 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8119 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgKSMMm (ORCPT ); Thu, 19 Nov 2020 07:12:42 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CcJTJ1kRJzLqQB; Thu, 19 Nov 2020 20:12:20 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.210.168.73) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 19 Nov 2020 20:12:32 +0800 From: Shameer Kolothum To: , , , CC: , , , , , , , , Subject: [RFC PATCH v2 2/8] ACPI/IORT: Add support for RMR node parsing Date: Thu, 19 Nov 2020 12:11:44 +0000 Message-ID: <20201119121150.3316-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> References: <20201119121150.3316-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.210.168.73] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.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 | 122 +++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 9929ff50c0c0..a9705aa35028 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,103 @@ 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) || !IS_ALIGNED(length, SZ_64K)) + 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) { + ret = -ENOMEM; + 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 +1793,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();