From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1973C433F5 for ; Thu, 18 Nov 2021 18:14:01 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 627996115B for ; Thu, 18 Nov 2021 18:14:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 627996115B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Hw7Gb5lfMz3cnK for ; Fri, 19 Nov 2021 05:13:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=209.85.210.52; helo=mail-ot1-f52.google.com; envelope-from=robherring2@gmail.com; receiver=) Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Hw7Dl5kBXz2yP3 for ; Fri, 19 Nov 2021 05:12:23 +1100 (AEDT) Received: by mail-ot1-f52.google.com with SMTP id u18-20020a9d7212000000b00560cb1dc10bso12329350otj.11 for ; Thu, 18 Nov 2021 10:12:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lKjGmeKxePzD70fPeVNX3iOZlAphvR/tEc1cbLf20w4=; b=BGA+hwi3J6utvi7lZPm8LOyK9h30zK7usweAnSeFX+6V9nGfG1XUPWyFMu0nOW4tul EIdW/Zdi/hg875gptV5FDUNFwaL1gsBpENM8SEL4oe3wgv5EiR/hsVQFNfnN42RCHgFq 8tPMuGbtMfwhubDZtGEsabwnHvBiKMY+g6CCxv5hyiMALiQLAYefuzv1uWO0K9CkvmCQ wwr3kpLIHAdjOO7ieG7AnARAHqiZTcj9+vRsrfwwxVrDhzqY5GK7ioewTwINMG9K8uVZ hDCxDBm1tZL+cIJxDZVk/M9jjJWgXOGDnnj/YMblz1kLMKc+j+aNARdJjcULtY7ng7l3 U3+g== X-Gm-Message-State: AOAM530R4mY+OjYawWntYkEG65f1v/ql/DEm7l0btg815dceJjqd1z9C PziiOSzCzpA7s4u5HrFssQ== X-Google-Smtp-Source: ABdhPJxhAvBxb/0cxPU/ID9tNSxww6OwM8HW6DSbRf+ew+ITysWoNTRD9+PHgOYNwmYeZDuZ7NkSoQ== X-Received: by 2002:a05:6830:4185:: with SMTP id r5mr23064102otu.50.1637259141449; Thu, 18 Nov 2021 10:12:21 -0800 (PST) Received: from xps15.herring.priv (66-90-148-213.dyn.grandenetworks.net. [66.90.148.213]) by smtp.googlemail.com with ESMTPSA id n20sm99339ooe.7.2021.11.18.10.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 10:12:20 -0800 (PST) From: Rob Herring To: Benjamin Herrenschmidt , Frank Rowand , John Crispin , Michael Ellerman , Paul Mackerras , Thomas Bogendoerfer Subject: [PATCH 3/3] of/fdt: Rework early_init_dt_scan_memory() to call directly Date: Thu, 18 Nov 2021 12:12:12 -0600 Message-Id: <20211118181213.1433346-4-robh@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211118181213.1433346-1-robh@kernel.org> References: <20211118181213.1433346-1-robh@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Use of the of_scan_flat_dt() function predates libfdt and is discouraged as libfdt provides a nicer set of APIs. Rework early_init_dt_scan_memory() to be called directly and use libfdt. Cc: John Crispin Cc: Thomas Bogendoerfer Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Frank Rowand Cc: linux-mips@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Rob Herring --- arch/mips/ralink/of.c | 16 ++------- arch/powerpc/kernel/prom.c | 16 ++++----- drivers/of/fdt.c | 68 ++++++++++++++++++++------------------ include/linux/of_fdt.h | 3 +- 4 files changed, 47 insertions(+), 56 deletions(-) diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c index 0135376c5de5..e1d79523343a 100644 --- a/arch/mips/ralink/of.c +++ b/arch/mips/ralink/of.c @@ -53,17 +53,6 @@ void __init device_tree_init(void) unflatten_and_copy_device_tree(); } -static int memory_dtb; - -static int __init early_init_dt_find_memory(unsigned long node, - const char *uname, int depth, void *data) -{ - if (depth == 1 && !strcmp(uname, "memory@0")) - memory_dtb = 1; - - return 0; -} - void __init plat_mem_setup(void) { void *dtb; @@ -77,9 +66,8 @@ void __init plat_mem_setup(void) dtb = get_fdt(); __dt_setup_arch(dtb); - of_scan_flat_dt(early_init_dt_find_memory, NULL); - if (memory_dtb) - of_scan_flat_dt(early_init_dt_scan_memory, NULL); + if (!early_init_dt_scan_memory()) + return; else if (soc_info.mem_detect) soc_info.mem_detect(); else if (soc_info.mem_size) diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 6e1a106f02eb..63762a3b75e8 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -532,19 +532,19 @@ static int __init early_init_drmem_lmb(struct drmem_lmb *lmb, } #endif /* CONFIG_PPC_PSERIES */ -static int __init early_init_dt_scan_memory_ppc(unsigned long node, - const char *uname, - int depth, void *data) +static int __init early_init_dt_scan_memory_ppc(void) { #ifdef CONFIG_PPC_PSERIES - if (depth == 1 && - strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) { + const void *fdt = initial_boot_params; + int node = fdt_path_offset(fdt, "/ibm,dynamic-reconfiguration-memory"); + + if (node > 0) { walk_drmem_lmbs_early(node, NULL, early_init_drmem_lmb); return 0; } #endif - return early_init_dt_scan_memory(node, uname, depth, data); + return early_init_dt_scan_memory(); } /* @@ -749,7 +749,7 @@ void __init early_init_devtree(void *params) /* Scan memory nodes and rebuild MEMBLOCKs */ early_init_dt_scan_root(); - of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + early_init_dt_scan_memory_ppc(); parse_early_param(); @@ -858,7 +858,7 @@ void __init early_get_first_memblock_info(void *params, phys_addr_t *size) */ add_mem_to_memblock = 0; early_init_dt_scan_root(); - of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + early_init_dt_scan_memory_ppc(); add_mem_to_memblock = 1; if (size) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 5e216555fe4f..a799117886f4 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1078,49 +1078,53 @@ u64 __init dt_mem_next_cell(int s, const __be32 **cellp) /* * early_init_dt_scan_memory - Look for and parse memory nodes */ -int __init early_init_dt_scan_memory(unsigned long node, const char *uname, - int depth, void *data) +int __init early_init_dt_scan_memory(void) { - const char *type = of_get_flat_dt_prop(node, "device_type", NULL); - const __be32 *reg, *endp; - int l; - bool hotpluggable; + int node; + const void *fdt = initial_boot_params; - /* We are scanning "memory" nodes only */ - if (type == NULL || strcmp(type, "memory") != 0) - return 0; + fdt_for_each_subnode(node, fdt, 0) { + const char *type = of_get_flat_dt_prop(node, "device_type", NULL); + const __be32 *reg, *endp; + int l; + bool hotpluggable; - reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); - if (reg == NULL) - reg = of_get_flat_dt_prop(node, "reg", &l); - if (reg == NULL) - return 0; + /* We are scanning "memory" nodes only */ + if (type == NULL || strcmp(type, "memory") != 0) + continue; - endp = reg + (l / sizeof(__be32)); - hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL); + reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); + if (reg == NULL) + reg = of_get_flat_dt_prop(node, "reg", &l); + if (reg == NULL) + return 0; - pr_debug("memory scan node %s, reg size %d,\n", uname, l); + endp = reg + (l / sizeof(__be32)); + hotpluggable = of_get_flat_dt_prop(node, "hotpluggable", NULL); - while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { - u64 base, size; + pr_debug("memory scan node %s, reg size %d,\n", + fdt_get_name(fdt, node, NULL), l); - base = dt_mem_next_cell(dt_root_addr_cells, ®); - size = dt_mem_next_cell(dt_root_size_cells, ®); + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { + u64 base, size; - if (size == 0) - continue; - pr_debug(" - %llx, %llx\n", base, size); + base = dt_mem_next_cell(dt_root_addr_cells, ®); + size = dt_mem_next_cell(dt_root_size_cells, ®); - early_init_dt_add_memory_arch(base, size); + if (size == 0) + continue; + pr_debug(" - %llx, %llx\n", base, size); - if (!hotpluggable) - continue; + early_init_dt_add_memory_arch(base, size); - if (memblock_mark_hotplug(base, size)) - pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", - base, base + size); - } + if (!hotpluggable) + continue; + if (memblock_mark_hotplug(base, size)) + pr_warn("failed to mark hotplug range 0x%llx - 0x%llx\n", + base, base + size); + } + } return 0; } @@ -1271,7 +1275,7 @@ void __init early_init_dt_scan_nodes(void) pr_warn("No chosen node found, continuing without\n"); /* Setup memory, calling early_init_dt_add_memory_arch */ - of_scan_flat_dt(early_init_dt_scan_memory, NULL); + early_init_dt_scan_memory(); /* Handle linux,usable-memory-range property */ memblock_cap_memory_range(cap_mem_addr, cap_mem_size); diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index df3d31926c3c..914739f3c192 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -59,8 +59,7 @@ extern unsigned long of_get_flat_dt_root(void); extern uint32_t of_get_flat_dt_phandle(unsigned long node); extern int early_init_dt_scan_chosen(char *cmdline); -extern int early_init_dt_scan_memory(unsigned long node, const char *uname, - int depth, void *data); +extern int early_init_dt_scan_memory(void); extern int early_init_dt_scan_chosen_stdout(void); extern void early_init_fdt_scan_reserved_mem(void); extern void early_init_fdt_reserve_self(void); -- 2.32.0