From nobody Fri Dec 19 19:40:51 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94F5113E404; Tue, 28 May 2024 22:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935846; cv=none; b=WbVVD3gzHMb659bCTWoD+xS64V8sQwqzRxKehhQk/vuVUwTHb8rTYsK2cJpqQB9HBRa5XoC/OpRvvt4tb6MiPmj7dzGI8P9MLWDkPkXUczKbPj4AJnVm/ZSwzXOyP1za3Lm/IEWWblzDeO4ALDEmoVtJ6LbLpy1kBXB8BCtcG14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935846; c=relaxed/simple; bh=blDQ4VKJZsvCJgTAq1HdIoEH4fQqa82gOAkhFVfh+jE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fsU1d/PiyUxGP3vSq2omFA9gwSOrvmtpkfBVzmAmgY09h1glFEH8cN81/0DKAhNEhFT97bKjOCjppeYrYw26I1mRVHGGiMBIrU+oNCaO2dOiIe2oPnqmKo98MFwIIMLSVRAo31RKxajFb5mgpZjfQ7AjDBJObj0zxXR1eoNdt8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=hzzgA9md; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="hzzgA9md" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SApKtB016256; Tue, 28 May 2024 22:37:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= n8phL+/iiUppOXLHIq1lKJqQfTen+tuP0L2Rk09N7Ak=; b=hzzgA9mdSdkdGKqN hZITW+l+vitiGC650rts21rmoa8OYMqT+1KRpggF1jDTAOUPKi7lncQxGOBRCu5q MNdy4oCfg8UtEAMmVGYY2MqgRL1xyiu+QMH1kJ2R+bv6FOAdXSI+kVD9yDujjSM5 PLKChH0++KXf67XyL5SG8hVuN7NbfKEt+D8UdVxYDYf01NC+GaBkVHpoEijAvoS0 pxnSzCRPKVIZPdbRDi2i36DfWe0X7C5Wf592tJ2hf3PEuxQe7hHoz/p0BeEUKOR+ yu56bLBT67mI3Go6rts1aWObeChldd2qbrA8fychkGaN3eSn6jXOYnLpV7Tj7tlc k9921Q== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2nffym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:07 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44SMb7WO012676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:07 GMT Received: from hu-obabatun-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 28 May 2024 15:37:03 -0700 From: Oreoluwa Babatunde To: , , , , , , CC: , , , , Oreoluwa Babatunde Subject: [PATCH v6 1/4] of: reserved_mem: Restruture how the reserved memory regions are processed Date: Tue, 28 May 2024 15:36:47 -0700 Message-ID: <20240528223650.619532-2-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528223650.619532-1-quic_obabatun@quicinc.com> References: <20240528223650.619532-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: pFWuLlTuchbqPkUcXIECaAB_6-MS76gr X-Proofpoint-GUID: pFWuLlTuchbqPkUcXIECaAB_6-MS76gr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_14,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280168 Content-Type: text/plain; charset="utf-8" The current implementation processes the reserved memory regions in two stages which are done with two separate functions within the early_init_fdt_scan_reserved_mem() function. Within the two stages of processing, the reserved memory regions are broken up into two groups which are processed differently: i) Statically-placed reserved memory regions i.e. regions defined with a static start address and size using the "reg" property in the DT. ii) Dynamically-placed reserved memory regions. i.e. regions defined by specifying a range of addresses where they can be placed in memory using the "alloc_ranges" and "size" properties in the DT. Stage 1: fdt_scan_reserved_mem() This stage of the reserved memory processing is used to scan through the reserved memory nodes defined in the devicetree and do the following on each of the nodes: 1) If the node represents a statically-placed reserved memory region, i.e. it is defined using the "reg" property: - Call memblock_reserve() or memblock_mark_nomap() as needed. - Add the information for the reserved region to the reserved_mem array. eg: fdt_reserved_mem_save_node(node, name, base, size); 2) If the node represents a dynamically-placed reserved memory region, i.e. it is defined using "alloc-ranges" and "size" properties: - Add the information for the region to the reserved_mem array with the starting address and size set to 0. eg: fdt_reserved_mem_save_node(node, name, 0, 0); Stage 2: fdt_init_reserved_mem() This stage of the reserved memory processing is used to iterate through the reserved_mem array which was populated in stage 1 and do the following on each of the entries: 1) If the entry represents a statically-placed reserved memory region: - Call the region specific init function. 2) If the entry represents a dynamically-placed reserved memory region: - Call __reserved_mem_alloc_size() which is used to allocate memory for the region using memblock_phys_alloc_range(), and call memblock_mark_nomap() on the allocated region if the region is specified as a no-map region. - Call the region specific init function. On architectures such as arm64, the dynamic allocation of the reserved_mem array needs to be done after the page tables have been setup because memblock allocated memory is not writable until then. This means that the reserved_mem array will not be available to store any reserved memory information until after the page tables have been setup. It is possible to call memblock_reserve() and memblock_mark_nomap() on the statically-placed reserved memory regions and not need to save them to the reserved_mem array until later. This is because all the information we need is present in the devicetree. Dynamically-placed reserved memory regions on the other hand get assigned a start address only at runtime, and since memblock_reserve() and memblock_mark_nomap() need to be called before the memory mappings are created, the allocation needs to happen before the page tables are setup. To make it easier to handle dynamically-placed reserved memory regions before the page tables are setup, this patch makes changes to the steps above to process the reserved memory regions in the following ways: Step 1: fdt_scan_reserved_mem() This stage of the reserved memory processing is used to scan through the reserved memory nodes defined in the devicetree and do the following on each of the nodes: 1) If the node represents a statically-placed reserved memory region, i.e. it is defined using the "reg" property: - Call memblock_reserve() or memblock_mark_nomap() as needed. 2) If the node represents a dynamically-placed reserved memory region, i.e. it is defined using "alloc-ranges" and "size" properties: - Call __reserved_mem_alloc_size() which will: i) Allocate memory for the reserved memory region. ii) Call memblock_mark_nomap() as needed. Note: There is no need to explicitly call memblock_reserve() here because it is already called by memblock when the memory for the region is being allocated. iii) Save the information for the region in the reserved_mem array. Step 2: fdt_init_reserved_mem() This stage of the reserved memory processing is used to: 1) Add the information for the statically-placed reserved memory into the reserved_mem array. 2) Iterate through all the entries in the array and call the region specific init function for each of them. fdt_init_reserved_mem() is also now called from within the unflatten_device_tree() function so that this step happens after the page tables have been setup. Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 5 +- drivers/of/of_private.h | 1 + drivers/of/of_reserved_mem.c | 134 +++++++++++++++++++++++++---------- 3 files changed, 100 insertions(+), 40 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index a8a04f27915b..527e6bc1c096 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -532,8 +532,6 @@ void __init early_init_fdt_scan_reserved_mem(void) break; memblock_reserve(base, size); } - - fdt_init_reserved_mem(); } =20 /** @@ -1259,6 +1257,9 @@ void __init unflatten_device_tree(void) of_alias_scan(early_init_dt_alloc_memory_arch); =20 unittest_unflatten_overlay_base(); + + /* initialize the reserved memory regions */ + fdt_init_reserved_mem(); } =20 /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 94fc0aa07af9..d889b8c17ca3 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -9,6 +9,7 @@ */ =20 #define FDT_ALIGN_SIZE 8 +#define MAX_RESERVED_REGIONS 64 =20 /** * struct alias_prop - Alias property in 'aliases' node diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 46e1c3fbc769..78ffc2635f11 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -27,7 +27,6 @@ =20 #include "of_private.h" =20 -#define MAX_RESERVED_REGIONS 64 static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; static int reserved_mem_count; =20 @@ -106,7 +105,6 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, phys_addr_t base, size; int len; const __be32 *prop; - int first =3D 1; bool nomap; =20 prop =3D of_get_flat_dt_prop(node, "reg", &len); @@ -134,10 +132,6 @@ static int __init __reserved_mem_reserve_reg(unsigned = long node, uname, &base, (unsigned long)(size / SZ_1M)); =20 len -=3D t_len; - if (first) { - fdt_reserved_mem_save_node(node, uname, base, size); - first =3D 0; - } } return 0; } @@ -165,12 +159,69 @@ static int __init __reserved_mem_check_root(unsigned = long node) return 0; } =20 +/** + * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined + * reserved memory regions. + * + * This function is used to scan through the DT and store the + * information for the reserved memory regions that are defined using + * the "reg" property. The region node number, name, base address, and + * size are all stored in the reserved_mem array by calling the + * fdt_reserved_mem_save_node() function. + */ +static void __init fdt_scan_reserved_mem_reg_nodes(void) +{ + int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); + const void *fdt =3D initial_boot_params; + phys_addr_t base, size; + const __be32 *prop; + int node, child; + int len; + + node =3D fdt_path_offset(fdt, "/reserved-memory"); + if (node < 0) { + pr_info("Reserved memory: No reserved-memory node in the DT\n"); + return; + } + + if (__reserved_mem_check_root(node)) { + pr_err("Reserved memory: unsupported node format, ignoring\n"); + return; + } + + fdt_for_each_subnode(child, fdt, node) { + const char *uname; + + prop =3D of_get_flat_dt_prop(child, "reg", &len); + if (!prop) + continue; + if (!of_fdt_device_is_available(fdt, child)) + continue; + + uname =3D fdt_get_name(fdt, child, NULL); + if (len && len % t_len !=3D 0) { + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n= ", + uname); + continue; + } + base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); + size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + + if (size) + fdt_reserved_mem_save_node(child, uname, base, size); + } +} + +static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname); + /* * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory */ int __init fdt_scan_reserved_mem(void) { int node, child; + int dynamic_nodes_cnt =3D 0; + int dynamic_nodes[MAX_RESERVED_REGIONS]; const void *fdt =3D initial_boot_params; =20 node =3D fdt_path_offset(fdt, "/reserved-memory"); @@ -192,8 +243,24 @@ int __init fdt_scan_reserved_mem(void) uname =3D fdt_get_name(fdt, child, NULL); =20 err =3D __reserved_mem_reserve_reg(child, uname); - if (err =3D=3D -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) - fdt_reserved_mem_save_node(child, uname, 0, 0); + /* + * Save the nodes for the dynamically-placed regions + * into an array which will be used for allocation right + * after all the statically-placed regions are reserved + * or marked as no-map. This is done to avoid dynamically + * allocating from one of the statically-placed regions. + */ + if (err =3D=3D -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) { + dynamic_nodes[dynamic_nodes_cnt] =3D child; + dynamic_nodes_cnt++; + } + } + for (int i =3D 0; i < dynamic_nodes_cnt; i++) { + const char *uname; + + child =3D dynamic_nodes[i]; + uname =3D fdt_get_name(fdt, child, NULL); + __reserved_mem_alloc_size(child, uname); } return 0; } @@ -253,8 +320,7 @@ static int __init __reserved_mem_alloc_in_range(phys_ad= dr_t size, * __reserved_mem_alloc_size() - allocate reserved memory described by * 'size', 'alignment' and 'alloc-ranges' properties. */ -static int __init __reserved_mem_alloc_size(unsigned long node, - const char *uname, phys_addr_t *res_base, phys_addr_t *res_size) +static int __init __reserved_mem_alloc_size(unsigned long node, const char= *uname) { int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); phys_addr_t start =3D 0, end =3D 0; @@ -333,10 +399,7 @@ static int __init __reserved_mem_alloc_size(unsigned l= ong node, uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - - *res_base =3D base; - *res_size =3D size; - + fdt_reserved_mem_save_node(node, uname, base, size); return 0; } =20 @@ -431,6 +494,8 @@ void __init fdt_init_reserved_mem(void) { int i; =20 + fdt_scan_reserved_mem_reg_nodes(); + /* check for overlapping reserved regions */ __rmem_check_for_overlap(); =20 @@ -442,30 +507,23 @@ void __init fdt_init_reserved_mem(void) =20 nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; =20 - if (rmem->size =3D=3D 0) - err =3D __reserved_mem_alloc_size(node, rmem->name, - &rmem->base, &rmem->size); - if (err =3D=3D 0) { - err =3D __reserved_mem_init_node(rmem); - if (err !=3D 0 && err !=3D -ENOENT) { - pr_info("node %s compatible matching fail\n", - rmem->name); - if (nomap) - memblock_clear_nomap(rmem->base, rmem->size); - else - memblock_phys_free(rmem->base, - rmem->size); - } else { - phys_addr_t end =3D rmem->base + rmem->size - 1; - bool reusable =3D - (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D NULL; - - pr_info("%pa..%pa (%lu KiB) %s %s %s\n", - &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), - nomap ? "nomap" : "map", - reusable ? "reusable" : "non-reusable", - rmem->name ? rmem->name : "unknown"); - } + err =3D __reserved_mem_init_node(rmem); + if (err !=3D 0 && err !=3D -ENOENT) { + pr_info("node %s compatible matching fail\n", rmem->name); + if (nomap) + memblock_clear_nomap(rmem->base, rmem->size); + else + memblock_phys_free(rmem->base, rmem->size); + } else { + phys_addr_t end =3D rmem->base + rmem->size - 1; + bool reusable =3D + (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D NULL; + + pr_info("%pa..%pa (%lu KiB) %s %s %s\n", + &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), + nomap ? "nomap" : "map", + reusable ? "reusable" : "non-reusable", + rmem->name ? rmem->name : "unknown"); } } } --=20 2.34.1 From nobody Fri Dec 19 19:40:51 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE2F913DDD2; Tue, 28 May 2024 22:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935844; cv=none; b=FhVKDVv9A51gqNwPBZQSjwYw0kYCtFtuMoHn9yi1oI0MOavE450QJ07XrGmXGpjt8+lSVZ4NXdLQwFRzYGMTTCmpK/ALf20v8XTjEC9Q5b+sPN9mP403A/mU86A0PKuKPvwaKI6nG8mDE/DwpHjaNWeMs8Wc+tXG6O75MPYzPUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935844; c=relaxed/simple; bh=UJv1CD8WbiI13h2HLlJ1I59Yi1cp3y58PBrUVCgUOgY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FhuV4+XIioCkajBmTIu9L9jiCwHE1QSD+DzKZ2dpdPC5eqK6tjCpaimG7eV2cVmlcw3tkyY/aX2C7dpIijEQG/ymJN1XuLpgJDKRb3b5wXTJD4fpr2BHKuOhR4HMwpLuer9Oyws19Y8tY1agHJpHqtCHtYRmheUI74bqy1IyAcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=o3X1zt02; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="o3X1zt02" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SAw9nS000379; Tue, 28 May 2024 22:37:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= S4ptlVoiRxy1U8psoznXLlkgymQEYIzekZdybqiOGko=; b=o3X1zt0255gLcp4s u0oxyAOQVUx1n84btXbWkqgVBUY15vysu0A8+TwKXrChxfgVKs/klKMwQsOfAlZa 0bV3wuuGyPpIFF2CshMN950Sk022bfORj24xIgVEzOACpPkEWzwUz/xn7NIrrUrz PzN4GS1jE/SWbTLv6OHjvW42Smx0pIPDzIgb1O9mK4Qga2sZTF4s3B4dcpZMSZz2 9xV2d28wZO2lEn7sRyxDk2+EKaxdsspGGgixG2EgTJgjG8Rl5yvVzXl9U5lCemzS hVjJgMGUyHn668MINF3QX8Zl+WTsyTBsGvkBmoEDlwOLD8gLU+iNCYSvJnZY31Yr mIP0VQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2h7ftr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:08 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44SMb7WQ012676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:07 GMT Received: from hu-obabatun-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 28 May 2024 15:37:03 -0700 From: Oreoluwa Babatunde To: , , , , , , CC: , , , , Oreoluwa Babatunde Subject: [PATCH v6 2/4] of: reserved_mem: Add code to dynamically allocate reserved_mem array Date: Tue, 28 May 2024 15:36:48 -0700 Message-ID: <20240528223650.619532-3-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528223650.619532-1-quic_obabatun@quicinc.com> References: <20240528223650.619532-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 2OzWrI-2HaUP-mlkaBa04kFh4qryhpOk X-Proofpoint-ORIG-GUID: 2OzWrI-2HaUP-mlkaBa04kFh4qryhpOk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_14,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 bulkscore=0 mlxscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280168 Content-Type: text/plain; charset="utf-8" The reserved_mem array is statically allocated with a size of MAX_RESERVED_REGIONS(64). Therefore, if the number of reserved_mem regions exceeds this size, there will not be enough space to store all the data. Hence, extend the use of the static array by introducing a dynamically allocated array based on the number of reserved memory regions specified in the DT. On architectures such as arm64, memblock allocated memory is not writable until after the page tables have been setup. Hence, the dynamic allocation of the reserved_mem array will need to be done only after the page tables have been setup. As a result, a temporary static array is still needed in the initial stages to store the information of the dynamically-placed reserved memory regions because the start address is selected only at run-time and is not stored anywhere else. It is not possible to wait until the reserved_mem array is allocated because this is done after the page tables are setup and the reserved memory regions need to be initialized before then. After the reserved_mem array is allocated, all entries from the static array is copied over to the new array, and the rest of the information for the statically-placed reserved memory regions are read in from the DT and stored in the new array as well. Once the init process is completed, the temporary static array is released back to the system because it is no longer needed. This is achieved by marking it as __initdata. Signed-off-by: Oreoluwa Babatunde --- drivers/of/of_reserved_mem.c | 58 +++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 78ffc2635f11..113d593ea031 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -27,7 +27,9 @@ =20 #include "of_private.h" =20 -static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; +static struct reserved_mem reserved_mem_array[MAX_RESERVED_REGIONS] __init= data; +static struct reserved_mem *reserved_mem __refdata =3D reserved_mem_array; +static int total_reserved_mem_cnt =3D MAX_RESERVED_REGIONS; static int reserved_mem_count; =20 static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t siz= e, @@ -55,6 +57,45 @@ static int __init early_init_dt_alloc_reserved_memory_ar= ch(phys_addr_t size, return err; } =20 +/* + * alloc_reserved_mem_array() - allocate memory for the reserved_mem + * array using memblock + * + * This function is used to allocate memory for the reserved_mem array + * according to the total number of reserved memory regions defined in + * the DT. + * After the new array is allocated, the information stored in the + * initial static array is copied over to this new array and the new + * array is used from this point on. + */ +static void __init alloc_reserved_mem_array(void) +{ + struct reserved_mem *new_array; + size_t alloc_size, copy_size, memset_size; + + alloc_size =3D array_size(total_reserved_mem_cnt, sizeof(*new_array)); + if (alloc_size =3D=3D SIZE_MAX) + pr_err("Failed to allocate memory for reserved_mem array with err: %d", = -EOVERFLOW); + + new_array =3D memblock_alloc(alloc_size, SMP_CACHE_BYTES); + if (!new_array) + pr_err("Failed to allocate memory for reserved_mem array with err: %d", = -ENOMEM); + + copy_size =3D array_size(reserved_mem_count, sizeof(*new_array)); + if (copy_size =3D=3D SIZE_MAX) { + memblock_free(new_array, alloc_size); + total_reserved_mem_cnt =3D MAX_RESERVED_REGIONS; + pr_err("Failed to allocate memory for reserved_mem array with err: %d", = -EOVERFLOW); + } + + memset_size =3D alloc_size - copy_size; + + memcpy(new_array, reserved_mem, copy_size); + memset(new_array + reserved_mem_count, 0, memset_size); + + reserved_mem =3D new_array; +} + /* * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion */ @@ -63,7 +104,7 @@ static void __init fdt_reserved_mem_save_node(unsigned l= ong node, const char *un { struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; =20 - if (reserved_mem_count =3D=3D ARRAY_SIZE(reserved_mem)) { + if (reserved_mem_count =3D=3D total_reserved_mem_cnt) { pr_err("not enough space for all defined regions.\n"); return; } @@ -220,7 +261,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam int __init fdt_scan_reserved_mem(void) { int node, child; - int dynamic_nodes_cnt =3D 0; + int dynamic_nodes_cnt =3D 0, count =3D 0; int dynamic_nodes[MAX_RESERVED_REGIONS]; const void *fdt =3D initial_boot_params; =20 @@ -243,6 +284,8 @@ int __init fdt_scan_reserved_mem(void) uname =3D fdt_get_name(fdt, child, NULL); =20 err =3D __reserved_mem_reserve_reg(child, uname); + if (!err) + count++; /* * Save the nodes for the dynamically-placed regions * into an array which will be used for allocation right @@ -257,11 +300,16 @@ int __init fdt_scan_reserved_mem(void) } for (int i =3D 0; i < dynamic_nodes_cnt; i++) { const char *uname; + int err; =20 child =3D dynamic_nodes[i]; uname =3D fdt_get_name(fdt, child, NULL); - __reserved_mem_alloc_size(child, uname); + + err =3D __reserved_mem_alloc_size(child, uname); + if (!err) + count++; } + total_reserved_mem_cnt =3D count++; return 0; } =20 @@ -494,6 +542,8 @@ void __init fdt_init_reserved_mem(void) { int i; =20 + alloc_reserved_mem_array(); + fdt_scan_reserved_mem_reg_nodes(); =20 /* check for overlapping reserved regions */ --=20 2.34.1 From nobody Fri Dec 19 19:40:51 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0713913E889; Tue, 28 May 2024 22:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935846; cv=none; b=sYd+ovFDVX61Izji0ASnC5SQBOuENFBEcH4ap4wRejeKp1e1iWoLDJWOnG73LLsKICmRgy708s5phAOiOqQIJfW49F0BFNWAvekTMev1VYPTwGFgiRIm2B/V3t4x+xDd2ytnBRHds88JTefyHuyfPFX0FoRe26Pv4JDebscCui0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935846; c=relaxed/simple; bh=3hxjq3n/Rbx1YoohrpPmBxlaS+/WENfm4yf4nBLd5q8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m31G3xFzYP17L0SzpCW+1F8kbIjFdwWLgKe3jueHviNCbsUjan2m16dSIiX6Kaju2P32o4mK0LftpC1GMm1zJaR8ty042HNxPMFKcb8wb58R/c5T88T4E+U6gGrMnSabStiTKgExHemepUQQ5EQ7PwlMSwgoLAUY5Msu/9XCSQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=PsBO5CCF; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="PsBO5CCF" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SL3iax003640; Tue, 28 May 2024 22:37:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Gz3XZZVJT4oGhs+9zgJTkY973qkuB93msz5Squ9jXMk=; b=PsBO5CCFINbPWaRT zisPU553DNU50CwB49EdYg+yq/R3DHSTb3ckr5qTD/vUjPJMUXOfNu6CJTV68EBo N10F869E016pgQW4Co4Dn9UUHCYsoFoXa8pQoq9YC2jKk98aPi3pKuSkI+P4kkAV 09WeamZ1h+7jYFzomwdx3px1MpuwfPiijLRH4XWAM387iSalEkOB696yKWrXUN+D drxVtDKKQDbvm5vvnWb+pNjE+OOkfsWLoW8W0zjgcLK+TkraKVcXDgmte1JFS8pw nB840YsIuho8aoX5kT2Uen/ZyWxMnpI3MK/2B6V68R8nzPzU0NfYXrUKb0TICmOP n5vLBA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba1k7fty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:08 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44SMb7WP012676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:07 GMT Received: from hu-obabatun-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 28 May 2024 15:37:04 -0700 From: Oreoluwa Babatunde To: , , , , , , CC: , , , , Oreoluwa Babatunde Subject: [PATCH v6 3/4] of: reserved_mem: Use unflatten_devicetree APIs to scan reserved memory nodes Date: Tue, 28 May 2024 15:36:49 -0700 Message-ID: <20240528223650.619532-4-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528223650.619532-1-quic_obabatun@quicinc.com> References: <20240528223650.619532-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 8RoWvymOaRXmz1GwYAHGsOyMqY08yRM5 X-Proofpoint-GUID: 8RoWvymOaRXmz1GwYAHGsOyMqY08yRM5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_14,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280168 Content-Type: text/plain; charset="utf-8" The unflatten_devicetree APIs have been setup and are available to be used by the time the fdt_init_reserved_mem() function is called. Since the unflatten_devicetree APIs are a more efficient way of scanning through the DT nodes, switch to using these APIs to facilitate the rest of the reserved memory processing. Signed-off-by: Oreoluwa Babatunde --- drivers/of/of_reserved_mem.c | 93 ++++++++++++++++++++------------- include/linux/of_reserved_mem.h | 2 +- kernel/dma/coherent.c | 10 ++-- kernel/dma/contiguous.c | 8 +-- kernel/dma/swiotlb.c | 10 ++-- 5 files changed, 72 insertions(+), 51 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 113d593ea031..05283cd24c3b 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,7 @@ static void __init alloc_reserved_mem_array(void) /* * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion */ -static void __init fdt_reserved_mem_save_node(unsigned long node, const ch= ar *uname, +static void __init fdt_reserved_mem_save_node(struct device_node *node, co= nst char *uname, phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; @@ -109,7 +110,7 @@ static void __init fdt_reserved_mem_save_node(unsigned = long node, const char *un return; } =20 - rmem->fdt_node =3D node; + rmem->dev_node =3D node; rmem->name =3D uname; rmem->base =3D base; rmem->size =3D size; @@ -178,11 +179,11 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, } =20 /* - * __reserved_mem_check_root() - check if #size-cells, #address-cells prov= ided + * __fdt_reserved_mem_check_root() - check if #size-cells, #address-cells = provided * in /reserved-memory matches the values supported by the current impleme= ntation, * also check if ranges property has been provided */ -static int __init __reserved_mem_check_root(unsigned long node) +static int __init __fdt_reserved_mem_check_root(unsigned long node) { const __be32 *prop; =20 @@ -200,6 +201,35 @@ static int __init __reserved_mem_check_root(unsigned l= ong node) return 0; } =20 +/* + * of_reserved_mem_check_root() - check if #size-cells, #address-cells pro= vided + * in /reserved-memory matches the values supported by the current impleme= ntation, + * also check if ranges property has been provided + */ +static int __init of_reserved_mem_check_root(struct device_node *node) +{ + u32 prop; + int ret; + + ret =3D of_property_read_u32(node, "#size-cells", &prop); + if (ret) + return ret; + + if (prop !=3D dt_root_size_cells) + return -EINVAL; + + ret =3D of_property_read_u32(node, "#address-cells", &prop); + if (ret) + return ret; + + if (prop !=3D dt_root_addr_cells) + return -EINVAL; + + if (!of_property_present(node, "ranges")) + return -EINVAL; + return 0; +} + /** * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. @@ -212,41 +242,40 @@ static int __init __reserved_mem_check_root(unsigned = long node) */ static void __init fdt_scan_reserved_mem_reg_nodes(void) { - int t_len =3D (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); - const void *fdt =3D initial_boot_params; + struct device_node *node, *child; phys_addr_t base, size; - const __be32 *prop; - int node, child; - int len; =20 - node =3D fdt_path_offset(fdt, "/reserved-memory"); - if (node < 0) { + node =3D of_find_node_by_path("/reserved-memory"); + if (!node) { pr_info("Reserved memory: No reserved-memory node in the DT\n"); return; } =20 - if (__reserved_mem_check_root(node)) { + if (of_reserved_mem_check_root(node)) { pr_err("Reserved memory: unsupported node format, ignoring\n"); return; } =20 - fdt_for_each_subnode(child, fdt, node) { + for_each_child_of_node(node, child) { + int ret =3D 0; const char *uname; + struct resource res; + struct reserved_mem *rmem; =20 - prop =3D of_get_flat_dt_prop(child, "reg", &len); - if (!prop) - continue; - if (!of_fdt_device_is_available(fdt, child)) + if (!of_device_is_available(child)) continue; =20 - uname =3D fdt_get_name(fdt, child, NULL); - if (len && len % t_len !=3D 0) { - pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n= ", - uname); + ret =3D of_address_to_resource(child, 0, &res); + if (ret) { + rmem =3D of_reserved_mem_lookup(child); + if (rmem) + rmem->dev_node =3D child; continue; } - base =3D dt_mem_next_cell(dt_root_addr_cells, &prop); - size =3D dt_mem_next_cell(dt_root_size_cells, &prop); + uname =3D of_node_full_name(child); + + base =3D res.start; + size =3D res.end - res.start + 1; =20 if (size) fdt_reserved_mem_save_node(child, uname, base, size); @@ -269,7 +298,7 @@ int __init fdt_scan_reserved_mem(void) if (node < 0) return -ENODEV; =20 - if (__reserved_mem_check_root(node) !=3D 0) { + if (__fdt_reserved_mem_check_root(node) !=3D 0) { pr_err("Reserved memory: unsupported node format, ignoring\n"); return -EINVAL; } @@ -447,7 +476,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - fdt_reserved_mem_save_node(node, uname, base, size); + fdt_reserved_mem_save_node(NULL, uname, base, size); return 0; } =20 @@ -467,7 +496,7 @@ static int __init __reserved_mem_init_node(struct reser= ved_mem *rmem) reservedmem_of_init_fn initfn =3D i->data; const char *compat =3D i->compatible; =20 - if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) + if (!of_device_is_compatible(rmem->dev_node, compat)) continue; =20 ret =3D initfn(rmem); @@ -500,11 +529,6 @@ static int __init __rmem_cmp(const void *a, const void= *b) if (ra->size > rb->size) return 1; =20 - if (ra->fdt_node < rb->fdt_node) - return -1; - if (ra->fdt_node > rb->fdt_node) - return 1; - return 0; } =20 @@ -551,11 +575,11 @@ void __init fdt_init_reserved_mem(void) =20 for (i =3D 0; i < reserved_mem_count; i++) { struct reserved_mem *rmem =3D &reserved_mem[i]; - unsigned long node =3D rmem->fdt_node; + struct device_node *node =3D rmem->dev_node; int err =3D 0; bool nomap; =20 - nomap =3D of_get_flat_dt_prop(node, "no-map", NULL) !=3D NULL; + nomap =3D of_property_present(node, "no-map"); =20 err =3D __reserved_mem_init_node(rmem); if (err !=3D 0 && err !=3D -ENOENT) { @@ -566,8 +590,7 @@ void __init fdt_init_reserved_mem(void) memblock_phys_free(rmem->base, rmem->size); } else { phys_addr_t end =3D rmem->base + rmem->size - 1; - bool reusable =3D - (of_get_flat_dt_prop(node, "reusable", NULL)) !=3D NULL; + bool reusable =3D of_property_present(node, "reusable"); =20 pr_info("%pa..%pa (%lu KiB) %s %s %s\n", &rmem->base, &end, (unsigned long)(rmem->size / SZ_1K), diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_me= m.h index e338282da652..769b8f67c8d3 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -10,7 +10,7 @@ struct reserved_mem_ops; =20 struct reserved_mem { const char *name; - unsigned long fdt_node; + struct device_node *dev_node; const struct reserved_mem_ops *ops; phys_addr_t base; phys_addr_t size; diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index ff5683a57f77..8f99586204fb 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -362,20 +362,18 @@ static const struct reserved_mem_ops rmem_dma_ops =3D= { =20 static int __init rmem_dma_setup(struct reserved_mem *rmem) { - unsigned long node =3D rmem->fdt_node; + struct device_node *node =3D rmem->dev_node; =20 - if (of_get_flat_dt_prop(node, "reusable", NULL)) + if (of_property_present(node, "reusable")) return -EINVAL; =20 -#ifdef CONFIG_ARM - if (!of_get_flat_dt_prop(node, "no-map", NULL)) { + if (IS_ENABLED(CONFIG_ARM) && !of_property_present(node, "no-map")) { pr_err("Reserved memory: regions without no-map are not yet supported\n"= ); return -EINVAL; } -#endif =20 #ifdef CONFIG_DMA_GLOBAL_POOL - if (of_get_flat_dt_prop(node, "linux,dma-default", NULL)) { + if (of_property_present(node, "linux,dma-default")) { WARN(dma_reserved_default_memory, "Reserved memory: region for default DMA coherent area is redefined= \n"); dma_reserved_default_memory =3D rmem; diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index 055da410ac71..450e9e4be79c 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -456,8 +456,8 @@ static const struct reserved_mem_ops rmem_cma_ops =3D { =20 static int __init rmem_cma_setup(struct reserved_mem *rmem) { - unsigned long node =3D rmem->fdt_node; - bool default_cma =3D of_get_flat_dt_prop(node, "linux,cma-default", NULL); + struct device_node *node =3D rmem->dev_node; + bool default_cma =3D of_property_read_bool(node, "linux,cma-default"); struct cma *cma; int err; =20 @@ -467,8 +467,8 @@ static int __init rmem_cma_setup(struct reserved_mem *r= mem) return -EBUSY; } =20 - if (!of_get_flat_dt_prop(node, "reusable", NULL) || - of_get_flat_dt_prop(node, "no-map", NULL)) + if (!of_property_present(node, "reusable") || + of_property_present(node, "no-map")) return -EINVAL; =20 if (!IS_ALIGNED(rmem->base | rmem->size, CMA_MIN_ALIGNMENT_BYTES)) { diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index fe1ccb53596f..9949ddc14272 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1859,12 +1859,12 @@ static const struct reserved_mem_ops rmem_swiotlb_o= ps =3D { =20 static int __init rmem_swiotlb_setup(struct reserved_mem *rmem) { - unsigned long node =3D rmem->fdt_node; + struct device_node *node =3D rmem->dev_node; =20 - if (of_get_flat_dt_prop(node, "reusable", NULL) || - of_get_flat_dt_prop(node, "linux,cma-default", NULL) || - of_get_flat_dt_prop(node, "linux,dma-default", NULL) || - of_get_flat_dt_prop(node, "no-map", NULL)) + if (of_property_present(node, "reusable") || + of_property_present(node, "linux,cma-default") || + of_property_present(node, "linux,dma-default") || + of_property_present(node, "no-map")) return -EINVAL; =20 rmem->ops =3D &rmem_swiotlb_ops; --=20 2.34.1 From nobody Fri Dec 19 19:40:51 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B626B13E028; Tue, 28 May 2024 22:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935844; cv=none; b=rp0TOrHzx0KlvHbo2nOct2rukoY72Y7sb5gsPlRKyXpGonXzFyQIJ2mU58kWIwjhKhlGYEQSKuakd6hs0yxrKoDQrZ76QoZuWWlbdH50U2Uc+wsLmYZaabNTvtwf+m0LlyYVkqoo6qTxb+FyCoGFHwe+9QPbMScCJG02HeUGLqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716935844; c=relaxed/simple; bh=f/wMmYi6UZRy8QxejzPHagMItqPx2bLrAyn1NdDAVOA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sY/DBeZK7DmIWJjCeYeT1/+cLq0L12Xq5zNOjGTpnDyVquMhdTXiZeWLssqjbNbcaDYmSh8ODJGeHrk1isi7ocLVZnxyIE0oqo15+89t8hm7riHinfFT16y/JEPghVJpsTq2mcY9Ms+yqbj36hd8e0WJYChL395ZLhyZRoPuRgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=WXl+ZJYg; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="WXl+ZJYg" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44SK210b023160; Tue, 28 May 2024 22:37:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= TYrVUge4E6wCMx/VszD8q2aUwvXf9s6S+k2yI28riOs=; b=WXl+ZJYgDwQTysNH +9rQc0HsxPPP64UOSj8cXWCj3GEccCCJbWezT1TeLw/y5vVs6nLJsKHBXzLjzDsY Ka8kwneJp9Wuvnf5Ztz6oS+sIamniGIOfiqpkbyW7M1RbymCKrBML+cSGPQ1Ca7R XVY4HjGGRoPh2xcv13RezdN35zmZb752M/YsX9mmDptc1l5HC0FGVcNNG62wrPhb 95L0Zj3Nc67agfEer7wESlBGpQN9q8vRckIGVpKZu3ZlOQUKrL6MlNzZoyIRllXa eTF7AKYJqmM0kF4g/ebSrrnhBckrRuk61q8nWD66qxpiGsgQxGfqZ03NaNieifka EH4q/g== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yba2pqgre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:08 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44SMb7WR012676 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 May 2024 22:37:07 GMT Received: from hu-obabatun-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 28 May 2024 15:37:04 -0700 From: Oreoluwa Babatunde To: , , , , , , CC: , , , , Oreoluwa Babatunde Subject: [PATCH v6 4/4] of: reserved_mem: Rename fdt_* functions to refelct the change from using fdt APIs Date: Tue, 28 May 2024 15:36:50 -0700 Message-ID: <20240528223650.619532-5-quic_obabatun@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528223650.619532-1-quic_obabatun@quicinc.com> References: <20240528223650.619532-1-quic_obabatun@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: wyv7XFpnzhLojwKF4wVgPuz5z9ucbnPR X-Proofpoint-ORIG-GUID: wyv7XFpnzhLojwKF4wVgPuz5z9ucbnPR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-28_14,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 adultscore=0 clxscore=1015 bulkscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405280167 Content-Type: text/plain; charset="utf-8" Rename the relevant reserved_mem functions to account for them no longer using the flattened devicetree (fdt) APIs. Signed-off-by: Oreoluwa Babatunde --- drivers/of/fdt.c | 2 +- drivers/of/of_private.h | 2 +- drivers/of/of_reserved_mem.c | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 527e6bc1c096..79b7348ea7a4 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1259,7 +1259,7 @@ void __init unflatten_device_tree(void) unittest_unflatten_overlay_base(); =20 /* initialize the reserved memory regions */ - fdt_init_reserved_mem(); + of_init_reserved_mem(); } =20 /** diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index d889b8c17ca3..7a744336084b 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -178,7 +178,7 @@ static inline struct device_node *__of_get_dma_parent(c= onst struct device_node * #endif =20 int fdt_scan_reserved_mem(void); -void fdt_init_reserved_mem(void); +void of_init_reserved_mem(void); =20 bool of_fdt_device_is_available(const void *blob, unsigned long node); =20 diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 05283cd24c3b..e326bbef0a13 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -98,10 +98,10 @@ static void __init alloc_reserved_mem_array(void) } =20 /* - * fdt_reserved_mem_save_node() - save fdt node for second pass initializa= tion + * of_reserved_mem_save_node() - save fdt node for second pass initializat= ion */ -static void __init fdt_reserved_mem_save_node(struct device_node *node, co= nst char *uname, - phys_addr_t base, phys_addr_t size) +static void __init of_reserved_mem_save_node(struct device_node *node, con= st char *uname, + phys_addr_t base, phys_addr_t size) { struct reserved_mem *rmem =3D &reserved_mem[reserved_mem_count]; =20 @@ -231,16 +231,16 @@ static int __init of_reserved_mem_check_root(struct d= evice_node *node) } =20 /** - * fdt_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined + * of_scan_reserved_mem_reg_nodes() - Store info for the "reg" defined * reserved memory regions. * * This function is used to scan through the DT and store the * information for the reserved memory regions that are defined using * the "reg" property. The region node number, name, base address, and * size are all stored in the reserved_mem array by calling the - * fdt_reserved_mem_save_node() function. + * of_reserved_mem_save_node() function. */ -static void __init fdt_scan_reserved_mem_reg_nodes(void) +static void __init of_scan_reserved_mem_reg_nodes(void) { struct device_node *node, *child; phys_addr_t base, size; @@ -278,7 +278,7 @@ static void __init fdt_scan_reserved_mem_reg_nodes(void) size =3D res.end - res.start + 1; =20 if (size) - fdt_reserved_mem_save_node(child, uname, base, size); + of_reserved_mem_save_node(child, uname, base, size); } } =20 @@ -476,7 +476,7 @@ static int __init __reserved_mem_alloc_size(unsigned lo= ng node, const char *unam uname, (unsigned long)(size / SZ_1M)); return -ENOMEM; } - fdt_reserved_mem_save_node(NULL, uname, base, size); + of_reserved_mem_save_node(NULL, uname, base, size); return 0; } =20 @@ -560,15 +560,15 @@ static void __init __rmem_check_for_overlap(void) } =20 /** - * fdt_init_reserved_mem() - allocate and init all saved reserved memory r= egions + * of_init_reserved_mem() - allocate and init all saved reserved memory re= gions */ -void __init fdt_init_reserved_mem(void) +void __init of_init_reserved_mem(void) { int i; =20 alloc_reserved_mem_array(); =20 - fdt_scan_reserved_mem_reg_nodes(); + of_scan_reserved_mem_reg_nodes(); =20 /* check for overlapping reserved regions */ __rmem_check_for_overlap(); --=20 2.34.1