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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6B22C433F5 for ; Tue, 30 Nov 2021 00:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EdKv58aZfOF9qqsf7SDy9pIklfhPwM0XHBwdDYfgkt0=; b=sBppEkHg2NGRcs 3awXu5AgHMK/Y9fTV89boXo434c3RZmF9yjOXvtKxlN9jHztvRjrYwkDMUiXmjOXgu+AwGb3+x3aE +15Sd2QQDHxa2R8K8n0rG89c9XdKa7mn1eKiDBryCaR7yo0y2UsyuoHShGeAVOALPwePUK4ONR2s9 +xyU2/c/kByQignT6pL9+y7ZIxW33zwlX86Hq0H2LT0/ZxjE/+TwZDskWsaCjxYDGOa1Y0C2Hpzf/ 75PYe5Mjz+h7hrQGCgIxibKpETzzkuuUkIzMIAOEkm0wUBL3xGUdZhnPQ7FmrqpekpLfeGFZ5h9Lf YproEQDFreD10ZdycXYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrqax-003AM7-IY; Tue, 30 Nov 2021 00:02:03 +0000 Received: from mail-ot1-f48.google.com ([209.85.210.48]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrqat-003AJG-Bu; Tue, 30 Nov 2021 00:02:02 +0000 Received: by mail-ot1-f48.google.com with SMTP id x19-20020a9d7053000000b0055c8b39420bso27844994otj.1; Mon, 29 Nov 2021 16:01:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aV2EodJh346t+Wbm3YErslm1vIVsKkg3za0JyncYukQ=; b=K+dX24H4FFmg70ytqb+7o/uVYw3AyW72Ys2AcSfUeZCxnUMuiw5AiJA5/p1n0vfuKR rMbufpUANxX7ReWF4cMYpGPvX3Xzv5/MUK/IIaSFuO/KD+y7pfeCVAs4Ooy7EeE4kDKQ jt7crYIxqfowetQB03IL6eNRMtNNJZvwnzLPGVTnIjXQXE8EWakDVlI3ECxA3OV5SBH4 X6LCzt+D45lqFZpzTEeuQWUij0E3pzB97eg6DjVEfCRc6k4WsJDErUjB7VDFXu9SNHSZ 5CZS03ODBOdKnP+Hnl0875CDMD2Rhe1AIEC4cRoUG9CSIcucqyEGCbGJehi4i0zDYfag 2DvQ== X-Gm-Message-State: AOAM531n7UfOca+3lPHexelbuVolel3njLVOwVWbhbow8x39cMC/6YF2 R3FWbIPDWJg7B7Qpu6iOIw== X-Google-Smtp-Source: ABdhPJxGmP7W+hR5b8+EQ325tbSTlD38AnnrDu+nyHVAQB1cJ7/x12F1fry2XTHV2cl6Sy01eQGOWA== X-Received: by 2002:a05:6830:4389:: with SMTP id s9mr47068865otv.97.1638230514850; Mon, 29 Nov 2021 16:01:54 -0800 (PST) Received: from robh.at.kernel.org (66-90-148-213.dyn.grandenetworks.net. [66.90.148.213]) by smtp.gmail.com with ESMTPSA id s17sm2465101ooj.42.2021.11.29.16.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 16:01:53 -0800 (PST) Received: (nullmailer pid 855745 invoked by uid 1000); Tue, 30 Nov 2021 00:01:51 -0000 Date: Mon, 29 Nov 2021 18:01:50 -0600 From: Rob Herring To: Calvin Zhang Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Yoshinori Sato , Thomas Bogendoerfer , Nick Hu , Greentime Hu , Vincent Chen , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Rich Felker , Chris Zankel , Max Filippov , Frank Rowand , Mike Rapoport , Andrew Morton , David Hildenbrand , Kefeng Wang , Vladimir Isaev , Arnd Bergmann , "Russell King (Oracle)" , Wolfram Sang , Guenter Roeck , Marc Zyngier , David Brazdil , Mark Rutland , Andrey Konovalov , Anshuman Khandual , Souptick Joarder , Jinyang He , Alexander Sverdlin , Serge Semin , Geert Uytterhoeven , Ley Foon Tan , Andreas Oetken , Randy Dunlap , Christophe JAILLET , Christophe Leroy , Andy Shevchenko , Zhang Yunkai , Markus Elfring , Ganesh Goudar , "Aneesh Kumar K.V" , Atish Patra , Anup Patel , Nick Kossifidis , Alexandre Ghiti , Vitaly Wool , "Rafael J. Wysocki" , Guo Ren , Tiezhu Yang , Mauri Sandberg , Palmer Dabbelt , linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, devicetree@vger.kernel.org Subject: Re: [PATCH 1/2] of: Sort reserved_mem related code Message-ID: References: <20211119075844.2902592-1-calvinzhang.cool@gmail.com> <20211119075844.2902592-2-calvinzhang.cool@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211119075844.2902592-2-calvinzhang.cool@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211129_160159_457933_D3D1D754 X-CRM114-Status: GOOD ( 36.66 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org On Fri, Nov 19, 2021 at 03:58:18PM +0800, Calvin Zhang wrote: > Move code about parsing /reserved-memory and initializing of > reserved_mems array to of_reserved_mem.c for better modularity. > > Rename array name from reserved_mem to reserved_mems to distinguish > from type definition. > > Signed-off-by: Calvin Zhang > --- > drivers/of/fdt.c | 108 +-------------------- > drivers/of/of_private.h | 12 ++- > drivers/of/of_reserved_mem.c | 163 ++++++++++++++++++++++++++------ > include/linux/of_reserved_mem.h | 4 + > 4 files changed, 149 insertions(+), 138 deletions(-) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index bdca35284ceb..445af4e69300 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -80,7 +80,7 @@ void __init of_fdt_limit_memory(int limit) > } > } > > -static bool of_fdt_device_is_available(const void *blob, unsigned long node) > +bool of_fdt_device_is_available(const void *blob, unsigned long node) > { > const char *status = fdt_getprop(blob, node, "status", NULL); > > @@ -476,7 +476,7 @@ void *initial_boot_params __ro_after_init; > > static u32 of_fdt_crc32; > > -static int __init early_init_dt_reserve_memory_arch(phys_addr_t base, > +int __init early_init_dt_reserve_memory_arch(phys_addr_t base, > phys_addr_t size, bool nomap) I think you can move this function too if you change the nomap==false callers to just call memblock_reserve directly. > { > if (nomap) { > @@ -492,108 +492,6 @@ static int __init early_init_dt_reserve_memory_arch(phys_addr_t base, > return memblock_reserve(base, size); > } > > -/* > - * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property > - */ > -static int __init __reserved_mem_reserve_reg(unsigned long node, > - const char *uname) > -{ > - int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); > - phys_addr_t base, size; > - int len; > - const __be32 *prop; > - int first = 1; > - bool nomap; > - > - prop = of_get_flat_dt_prop(node, "reg", &len); > - if (!prop) > - return -ENOENT; > - > - if (len && len % t_len != 0) { > - pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", > - uname); > - return -EINVAL; > - } > - > - nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; > - > - while (len >= t_len) { > - base = dt_mem_next_cell(dt_root_addr_cells, &prop); > - size = dt_mem_next_cell(dt_root_size_cells, &prop); > - > - if (size && > - early_init_dt_reserve_memory_arch(base, size, nomap) == 0) > - pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n", > - uname, &base, (unsigned long)(size / SZ_1M)); > - else > - pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n", > - uname, &base, (unsigned long)(size / SZ_1M)); > - > - len -= t_len; > - if (first) { > - fdt_reserved_mem_save_node(node, uname, base, size); > - first = 0; > - } > - } > - return 0; > -} > - > -/* > - * __reserved_mem_check_root() - check if #size-cells, #address-cells provided > - * in /reserved-memory matches the values supported by the current implementation, > - * also check if ranges property has been provided > - */ > -static int __init __reserved_mem_check_root(unsigned long node) > -{ > - const __be32 *prop; > - > - prop = of_get_flat_dt_prop(node, "#size-cells", NULL); > - if (!prop || be32_to_cpup(prop) != dt_root_size_cells) > - return -EINVAL; > - > - prop = of_get_flat_dt_prop(node, "#address-cells", NULL); > - if (!prop || be32_to_cpup(prop) != dt_root_addr_cells) > - return -EINVAL; > - > - prop = of_get_flat_dt_prop(node, "ranges", NULL); > - if (!prop) > - return -EINVAL; > - return 0; > -} > - > -/* > - * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory > - */ > -static int __init fdt_scan_reserved_mem(void) > -{ > - int node, child; > - const void *fdt = initial_boot_params; > - > - node = fdt_path_offset(fdt, "/reserved-memory"); > - if (node < 0) > - return -ENODEV; > - > - if (__reserved_mem_check_root(node) != 0) { > - pr_err("Reserved memory: unsupported node format, ignoring\n"); > - return -EINVAL; > - } > - > - fdt_for_each_subnode(child, fdt, node) { > - const char *uname; > - int err; > - > - if (!of_fdt_device_is_available(fdt, child)) > - continue; > - > - uname = fdt_get_name(fdt, child, NULL); > - > - err = __reserved_mem_reserve_reg(child, uname); > - if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) > - fdt_reserved_mem_save_node(child, uname, 0, 0); > - } > - return 0; > -} > - > /* > * fdt_reserve_elfcorehdr() - reserves memory for elf core header > * > @@ -642,7 +540,7 @@ void __init early_init_fdt_scan_reserved_mem(void) > } > > fdt_scan_reserved_mem(); > - fdt_init_reserved_mem(); > + of_reserved_mem_init(); > fdt_reserve_elfcorehdr(); > } > > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > index 9324483397f6..88b67f8ed698 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,8 +163,14 @@ static inline int of_dma_get_range(struct device_node *np, > } > #endif > > -void fdt_init_reserved_mem(void); > -void fdt_reserved_mem_save_node(unsigned long node, const char *uname, > - phys_addr_t base, phys_addr_t size); > +bool of_fdt_device_is_available(const void *blob, unsigned long node); > +int early_init_dt_reserve_memory_arch(phys_addr_t base, > + phys_addr_t size, bool nomap); > +#ifdef CONFIG_OF_RESERVED_MEM > +int fdt_scan_reserved_mem(void); > +#else > +static inline int fdt_scan_reserved_mem(void) { } > +#endif > + > > #endif /* _LINUX_OF_PRIVATE_H */ > diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c > index 9c0fb962c22b..784cfc5cd251 100644 > --- a/drivers/of/of_reserved_mem.c > +++ b/drivers/of/of_reserved_mem.c > @@ -20,13 +20,14 @@ > #include > #include > #include > +#include > #include > #include > > #include "of_private.h" > > #define MAX_RESERVED_REGIONS 64 > -static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; > +static struct reserved_mem reserved_mems[MAX_RESERVED_REGIONS]; Would be a bit easier to review without the rename. > static int reserved_mem_count; > > static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, > @@ -56,12 +57,12 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, > /* > * fdt_reserved_mem_save_node() - save fdt node for second pass initialization > */ > -void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, > +static void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, > phys_addr_t base, phys_addr_t size) > { > - struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; > + struct reserved_mem *rmem = &reserved_mems[reserved_mem_count]; > > - if (reserved_mem_count == ARRAY_SIZE(reserved_mem)) { > + if (reserved_mem_count == ARRAY_SIZE(reserved_mems)) { > pr_err("not enough space for all defined regions.\n"); > return; > } > @@ -173,29 +174,105 @@ static const struct of_device_id __rmem_of_table_sentinel > __used __section("__reservedmem_of_table_end"); > > /* > - * __reserved_mem_init_node() - call region specific reserved memory init code > + * __reserved_mem_check_root() - check if #size-cells, #address-cells provided > + * in /reserved-memory matches the values supported by the current implementation, > + * also check if ranges property has been provided > */ > -static int __init __reserved_mem_init_node(struct reserved_mem *rmem) > +static int __init __reserved_mem_check_root(unsigned long node) > { > - extern const struct of_device_id __reservedmem_of_table[]; > - const struct of_device_id *i; > - int ret = -ENOENT; > + const __be32 *prop; > > - for (i = __reservedmem_of_table; i < &__rmem_of_table_sentinel; i++) { > - reservedmem_of_init_fn initfn = i->data; > - const char *compat = i->compatible; > + prop = of_get_flat_dt_prop(node, "#size-cells", NULL); > + if (!prop || be32_to_cpup(prop) != dt_root_size_cells) > + return -EINVAL; > > - if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) > - continue; > + prop = of_get_flat_dt_prop(node, "#address-cells", NULL); > + if (!prop || be32_to_cpup(prop) != dt_root_addr_cells) > + return -EINVAL; > > - ret = initfn(rmem); > - if (ret == 0) { > - pr_info("initialized node %s, compatible id %s\n", > - rmem->name, compat); > - break; > + prop = of_get_flat_dt_prop(node, "ranges", NULL); > + if (!prop) > + return -EINVAL; > + return 0; > +} > + > +/* > + * __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property > + */ > +static int __init __reserved_mem_reserve_reg(unsigned long node, > + const char *uname) > +{ > + int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); > + phys_addr_t base, size; > + int len; > + const __be32 *prop; > + int first = 1; > + bool nomap; > + > + prop = of_get_flat_dt_prop(node, "reg", &len); > + if (!prop) > + return -ENOENT; > + > + if (len && len % t_len != 0) { > + pr_err("Reserved memory: invalid reg property in '%s', skipping node.\n", > + uname); > + return -EINVAL; > + } > + > + nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; > + > + while (len >= t_len) { > + base = dt_mem_next_cell(dt_root_addr_cells, &prop); > + size = dt_mem_next_cell(dt_root_size_cells, &prop); > + > + if (size && > + early_init_dt_reserve_memory_arch(base, size, nomap) == 0) > + pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n", > + uname, &base, (unsigned long)(size / SZ_1M)); > + else > + pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n", > + uname, &base, (unsigned long)(size / SZ_1M)); > + > + len -= t_len; > + if (first) { > + fdt_reserved_mem_save_node(node, uname, base, size); > + first = 0; > } > } > - return ret; > + return 0; > +} > + > +/* > + * fdt_scan_reserved_mem() - scan a single FDT node for reserved memory > + */ > +int __init fdt_scan_reserved_mem(void) > +{ > + int node, child; > + const void *fdt = initial_boot_params; > + > + node = fdt_path_offset(fdt, "/reserved-memory"); > + if (node < 0) > + return -ENODEV; > + > + if (__reserved_mem_check_root(node) != 0) { > + pr_err("Reserved memory: unsupported node format, ignoring\n"); > + return -EINVAL; > + } > + > + fdt_for_each_subnode(child, fdt, node) { > + const char *uname; > + int err; > + > + if (!of_fdt_device_is_available(fdt, child)) > + continue; > + > + uname = fdt_get_name(fdt, child, NULL); > + > + err = __reserved_mem_reserve_reg(child, uname); > + if (err == -ENOENT && of_get_flat_dt_prop(child, "size", NULL)) > + fdt_reserved_mem_save_node(child, uname, 0, 0); > + } > + return 0; > } > > static int __init __rmem_cmp(const void *a, const void *b) > @@ -228,13 +305,13 @@ static void __init __rmem_check_for_overlap(void) > if (reserved_mem_count < 2) > return; > > - sort(reserved_mem, reserved_mem_count, sizeof(reserved_mem[0]), > + sort(reserved_mems, reserved_mem_count, sizeof(reserved_mems[0]), > __rmem_cmp, NULL); > for (i = 0; i < reserved_mem_count - 1; i++) { > struct reserved_mem *this, *next; > > - this = &reserved_mem[i]; > - next = &reserved_mem[i + 1]; > + this = &reserved_mems[i]; > + next = &reserved_mems[i + 1]; > > if (this->base + this->size > next->base) { > phys_addr_t this_end, next_end; > @@ -248,10 +325,36 @@ static void __init __rmem_check_for_overlap(void) > } > } > > +/* > + * __reserved_mem_init_node() - call region specific reserved memory init code > + */ > +static int __init __reserved_mem_init_node(struct reserved_mem *rmem) > +{ > + extern const struct of_device_id __reservedmem_of_table[]; > + const struct of_device_id *i; > + int ret = -ENOENT; > + > + for (i = __reservedmem_of_table; i < &__rmem_of_table_sentinel; i++) { > + reservedmem_of_init_fn initfn = i->data; > + const char *compat = i->compatible; > + > + if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) > + continue; > + > + ret = initfn(rmem); > + if (ret == 0) { > + pr_info("initialized node %s, compatible id %s\n", > + rmem->name, compat); > + break; > + } > + } > + return ret; > +} > + > /** > - * fdt_init_reserved_mem() - allocate and init all saved reserved memory regions > + * of_reserved_mem_init() - allocate and init all saved reserved memory regions > */ > -void __init fdt_init_reserved_mem(void) > +void __init of_reserved_mem_init(void) > { > int i; > > @@ -259,7 +362,7 @@ void __init fdt_init_reserved_mem(void) > __rmem_check_for_overlap(); > > for (i = 0; i < reserved_mem_count; i++) { > - struct reserved_mem *rmem = &reserved_mem[i]; > + struct reserved_mem *rmem = &reserved_mems[i]; > unsigned long node = rmem->fdt_node; > int len; > const __be32 *prop; > @@ -299,8 +402,8 @@ static inline struct reserved_mem *__find_rmem(struct device_node *node) > return NULL; > > for (i = 0; i < reserved_mem_count; i++) > - if (reserved_mem[i].phandle == node->phandle) > - return &reserved_mem[i]; > + if (reserved_mems[i].phandle == node->phandle) > + return &reserved_mems[i]; > return NULL; > } > > @@ -442,8 +545,8 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) > > name = kbasename(np->full_name); > for (i = 0; i < reserved_mem_count; i++) > - if (!strcmp(reserved_mem[i].name, name)) > - return &reserved_mem[i]; > + if (!strcmp(reserved_mems[i].name, name)) > + return &reserved_mems[i]; > > return NULL; > } > diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h > index 4de2a24cadc9..34e134bec606 100644 > --- a/include/linux/of_reserved_mem.h > +++ b/include/linux/of_reserved_mem.h > @@ -32,6 +32,8 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem); > #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ > _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) > > +void of_reserved_mem_init(void); > + > int of_reserved_mem_device_init_by_idx(struct device *dev, > struct device_node *np, int idx); > int of_reserved_mem_device_init_by_name(struct device *dev, > @@ -45,6 +47,8 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); > #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ > _OF_DECLARE_STUB(reservedmem, name, compat, init, reservedmem_of_init_fn) > > +static inline void of_reserved_mem_init(void) { } > + > static inline int of_reserved_mem_device_init_by_idx(struct device *dev, > struct device_node *np, int idx) > { > -- > 2.30.2 > > _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc