From: Sumit Garg <sumit.garg@kernel.org>
To: Casey Connolly <casey.connolly@linaro.org>
Cc: u-boot@lists.denx.de, u-boot-qcom@groups.io,
Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Peng Fan <peng.fan@nxp.com>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
Alice Guo <alice.guo@nxp.com>,
Quentin Schulz <quentin.schulz@cherry.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Kuan-Wei Chiu <visitorckw@gmail.com>,
Raymond Mao <raymond.mao@riscstar.com>,
Stefan Roese <stefan.roese@mailbox.org>,
Philip Molloy <philip.molloy@analog.com>,
Jerome Forissier <jerome.forissier@arm.com>,
Marek Vasut <marek.vasut@mailbox.org>,
Varadarajan Narayanan <varadarajan.narayanan@oss.qualcomm.com>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Aswin Murugan <aswin.murugan@oss.qualcomm.com>,
Rasmus Villemoes <ravi@prevas.dk>,
Heiko Schocher <hs@nabladev.com>,
Michal Simek <michal.simek@amd.com>,
Sughosh Ganu <sughosh.ganu@arm.com>,
Antony Kurniawan Soemardi <linux@smankusors.com>,
Luca Weiss <luca.weiss@fairphone.com>,
Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Subject: Re: [PATCH v2 12/15] mach-snapdragon: move memory parsing to its own file
Date: Mon, 18 May 2026 18:24:26 +0530 [thread overview]
Message-ID: <agsMAjyc7npwsbpt@sumit-xelite> (raw)
In-Reply-To: <20260504-b4-modernise-smem-v2-12-c01ec2ff3886@linaro.org>
On Mon, May 04, 2026 at 08:57:40PM +0200, Casey Connolly wrote:
> This code is getting a bit complicated, split it out to try and keep
> things a bit better organised as we're going to be supporting populating
> the memory layout from various other sources.
>
> Signed-off-by: Casey Connolly <casey.connolly@linaro.org>
> ---
> arch/arm/mach-snapdragon/Makefile | 2 +-
> arch/arm/mach-snapdragon/board.c | 115 -------------------------------
> arch/arm/mach-snapdragon/dram.c | 127 +++++++++++++++++++++++++++++++++++
> arch/arm/mach-snapdragon/qcom-priv.h | 2 +
> 4 files changed, 130 insertions(+), 116 deletions(-)
Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
-Sumit
>
> diff --git a/arch/arm/mach-snapdragon/Makefile b/arch/arm/mach-snapdragon/Makefile
> index 343e825c6fdd..e481e4f26e5c 100644
> --- a/arch/arm/mach-snapdragon/Makefile
> +++ b/arch/arm/mach-snapdragon/Makefile
> @@ -1,7 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0+
> #
> # (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
>
> -obj-y += board.o
> +obj-y += board.o dram.o
> obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += capsule_update.o
> obj-$(CONFIG_OF_LIVE) += of_fixup.o
> diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
> index e12d3d00caa4..a2d97ad77910 100644
> --- a/arch/arm/mach-snapdragon/board.c
> +++ b/arch/arm/mach-snapdragon/board.c
> @@ -42,123 +42,8 @@ enum qcom_boot_source qcom_boot_source __section(".data") = 0;
> static struct mm_region rbx_mem_map[CONFIG_NR_DRAM_BANKS + 2] = { { 0 } };
>
> struct mm_region *mem_map = rbx_mem_map;
>
> -static struct {
> - phys_addr_t start;
> - phys_size_t size;
> -} prevbl_ddr_banks[CONFIG_NR_DRAM_BANKS] __section(".data") = { 0 };
> -
> -int dram_init(void)
> -{
> - /*
> - * gd->ram_base / ram_size have been setup already
> - * in qcom_parse_memory().
> - */
> - return 0;
> -}
> -
> -static int ddr_bank_cmp(const void *v1, const void *v2)
> -{
> - const struct {
> - phys_addr_t start;
> - phys_size_t size;
> - } *res1 = v1, *res2 = v2;
> -
> - if (!res1->size)
> - return 1;
> - if (!res2->size)
> - return -1;
> -
> - return (res1->start >> 24) - (res2->start >> 24);
> -}
> -
> -/* This has to be done post-relocation since gd->bd isn't preserved */
> -static void qcom_configure_bi_dram(void)
> -{
> - int i;
> -
> - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> - gd->bd->bi_dram[i].start = prevbl_ddr_banks[i].start;
> - gd->bd->bi_dram[i].size = prevbl_ddr_banks[i].size;
> - }
> -}
> -
> -int dram_init_banksize(void)
> -{
> - qcom_configure_bi_dram();
> -
> - return 0;
> -}
> -
> -/**
> - * The generic memory parsing code in U-Boot lacks a few things that we
> - * need on Qualcomm:
> - *
> - * 1. It sets gd->ram_size and gd->ram_base to represent a single memory block
> - * 2. setup_dest_addr() later relocates U-Boot to ram_base + ram_size, the end
> - * of that first memory block.
> - *
> - * This results in all memory beyond U-Boot being unusable in Linux when booting
> - * with EFI.
> - *
> - * Since the ranges in the memory node may be out of order, the only way for us
> - * to correctly determine the relocation address for U-Boot is to parse all
> - * memory regions and find the highest valid address.
> - *
> - * We can't use fdtdec_setup_memory_banksize() since it stores the result in
> - * gd->bd, which is not yet allocated.
> - *
> - * @fdt: FDT blob to parse /memory node from
> - *
> - * Return: 0 on success or -ENODATA if /memory node is missing or incomplete
> - */
> -static int qcom_parse_memory(const void *fdt)
> -{
> - int offset;
> - const fdt64_t *memory;
> - int memsize;
> - phys_addr_t ram_end = 0;
> - int i, j, banks;
> -
> - offset = fdt_path_offset(fdt, "/memory");
> - if (offset < 0)
> - return -ENODATA;
> -
> - memory = fdt_getprop(fdt, offset, "reg", &memsize);
> - if (!memory)
> - return -ENODATA;
> -
> - banks = min(memsize / (2 * sizeof(u64)), (ulong)CONFIG_NR_DRAM_BANKS);
> -
> - if (memsize / sizeof(u64) > CONFIG_NR_DRAM_BANKS * 2)
> - log_err("Provided more than the max of %d memory banks\n", CONFIG_NR_DRAM_BANKS);
> -
> - if (banks > CONFIG_NR_DRAM_BANKS)
> - log_err("Provided more memory banks than we can handle\n");
> -
> - for (i = 0, j = 0; i < banks * 2; i += 2, j++) {
> - prevbl_ddr_banks[j].start = get_unaligned_be64(&memory[i]);
> - prevbl_ddr_banks[j].size = get_unaligned_be64(&memory[i + 1]);
> - if (!prevbl_ddr_banks[j].size) {
> - j--;
> - continue;
> - }
> - ram_end = max(ram_end, prevbl_ddr_banks[j].start + prevbl_ddr_banks[j].size);
> - }
> -
> - if (!banks || !prevbl_ddr_banks[0].size)
> - return -ENODATA;
> -
> - /* Sort our RAM banks -_- */
> - qsort(prevbl_ddr_banks, banks, sizeof(prevbl_ddr_banks[0]), ddr_bank_cmp);
> -
> - gd->ram_base = prevbl_ddr_banks[0].start;
> - gd->ram_size = ram_end - gd->ram_base;
> -
> - return 0;
> -}
> -
> static void show_psci_version(void)
> {
> struct arm_smccc_res res;
>
> diff --git a/arch/arm/mach-snapdragon/dram.c b/arch/arm/mach-snapdragon/dram.c
> new file mode 100644
> index 000000000000..ad73b685a935
> --- /dev/null
> +++ b/arch/arm/mach-snapdragon/dram.c
> @@ -0,0 +1,127 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Memory layout parsing for Qualcomm.
> + */
> +
> +#define LOG_CATEGORY LOGC_BOARD
> +#define pr_fmt(fmt) "QCOM-DRAM: " fmt
> +
> +#include <asm-generic/unaligned.h>
> +#include <dm.h>
> +#include <log.h>
> +#include <sort.h>
> +
> +static struct {
> + phys_addr_t start;
> + phys_size_t size;
> +} prevbl_ddr_banks[CONFIG_NR_DRAM_BANKS] __section(".data") = { 0 };
> +
> +int dram_init(void)
> +{
> + /*
> + * gd->ram_base / ram_size have been setup already
> + * in qcom_parse_memory().
> + */
> + return 0;
> +}
> +
> +static int ddr_bank_cmp(const void *v1, const void *v2)
> +{
> + const struct {
> + phys_addr_t start;
> + phys_size_t size;
> + } *res1 = v1, *res2 = v2;
> +
> + if (!res1->size)
> + return 1;
> + if (!res2->size)
> + return -1;
> +
> + return (res1->start >> 24) - (res2->start >> 24);
> +}
> +
> +/* This has to be done post-relocation since gd->bd isn't preserved */
> +static void qcom_configure_bi_dram(void)
> +{
> + int i;
> +
> + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
> + gd->bd->bi_dram[i].start = prevbl_ddr_banks[i].start;
> + gd->bd->bi_dram[i].size = prevbl_ddr_banks[i].size;
> + }
> +}
> +
> +int dram_init_banksize(void)
> +{
> + qcom_configure_bi_dram();
> +
> + return 0;
> +}
> +
> +/**
> + * The generic memory parsing code in U-Boot lacks a few things that we
> + * need on Qualcomm:
> + *
> + * 1. It sets gd->ram_size and gd->ram_base to represent a single memory block
> + * 2. setup_dest_addr() later relocates U-Boot to ram_base + ram_size, the end
> + * of that first memory block.
> + *
> + * This results in all memory beyond U-Boot being unusable in Linux when booting
> + * with EFI.
> + *
> + * Since the ranges in the memory node may be out of order, the only way for us
> + * to correctly determine the relocation address for U-Boot is to parse all
> + * memory regions and find the highest valid address.
> + *
> + * We can't use fdtdec_setup_memory_banksize() since it stores the result in
> + * gd->bd, which is not yet allocated.
> + *
> + * @fdt: FDT blob to parse /memory node from
> + *
> + * Return: 0 on success or -ENODATA if /memory node is missing or incomplete
> + */
> +int qcom_parse_memory(const void *fdt)
> +{
> + int offset;
> + const fdt64_t *memory;
> + int memsize;
> + phys_addr_t ram_end = 0;
> + int i, j, banks;
> +
> + offset = fdt_path_offset(fdt, "/memory");
> + if (offset < 0)
> + return -ENODATA;
> +
> + memory = fdt_getprop(fdt, offset, "reg", &memsize);
> + if (!memory)
> + return -ENODATA;
> +
> + banks = min(memsize / (2 * sizeof(u64)), (ulong)CONFIG_NR_DRAM_BANKS);
> +
> + if (memsize / sizeof(u64) > CONFIG_NR_DRAM_BANKS * 2)
> + log_err("Provided more than the max of %d memory banks\n", CONFIG_NR_DRAM_BANKS);
> +
> + if (banks > CONFIG_NR_DRAM_BANKS)
> + log_err("Provided more memory banks than we can handle\n");
> +
> + for (i = 0, j = 0; i < banks * 2; i += 2, j++) {
> + prevbl_ddr_banks[j].start = get_unaligned_be64(&memory[i]);
> + prevbl_ddr_banks[j].size = get_unaligned_be64(&memory[i + 1]);
> + if (!prevbl_ddr_banks[j].size) {
> + j--;
> + continue;
> + }
> + ram_end = max(ram_end, prevbl_ddr_banks[j].start + prevbl_ddr_banks[j].size);
> + }
> +
> + if (!banks || !prevbl_ddr_banks[0].size)
> + return -ENODATA;
> +
> + /* Sort our RAM banks -_- */
> + qsort(prevbl_ddr_banks, banks, sizeof(prevbl_ddr_banks[0]), ddr_bank_cmp);
> +
> + gd->ram_base = prevbl_ddr_banks[0].start;
> + gd->ram_size = ram_end - gd->ram_base;
> +
> + return 0;
> +}
> diff --git a/arch/arm/mach-snapdragon/qcom-priv.h b/arch/arm/mach-snapdragon/qcom-priv.h
> index b8bf574e8bbb..ce409314a98b 100644
> --- a/arch/arm/mach-snapdragon/qcom-priv.h
> +++ b/arch/arm/mach-snapdragon/qcom-priv.h
> @@ -22,5 +22,7 @@ void qcom_configure_capsule_updates(void);
> #else
> void qcom_configure_capsule_updates(void) {}
> #endif /* EFI_HAVE_CAPSULE_SUPPORT */
>
> +int qcom_parse_memory(const void *fdt);
> +
> #endif /* __QCOM_PRIV_H__ */
>
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-05-18 12:54 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 18:57 [PATCH v2 00/15] qcom: smem: modernize SMEM in U-Boot Casey Connolly
2026-05-04 18:57 ` [PATCH v2 01/15] Revert "dm: SMEM (Shared memory) uclass" Casey Connolly
2026-05-05 10:15 ` Sumit Garg
2026-05-07 15:31 ` Simon Glass
2026-05-07 20:05 ` Casey Connolly
2026-05-18 14:34 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 02/15] smem: drop drivers/smem Casey Connolly
2026-05-18 14:34 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 03/15] Revert "test: smem: add basic smem test" Casey Connolly
2026-05-05 10:26 ` Sumit Garg
2026-05-18 14:34 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 04/15] Revert "drivers: smem: sandbox" Casey Connolly
2026-05-05 10:26 ` Sumit Garg
2026-05-18 14:34 ` Neil Armstrong
2026-05-18 15:51 ` Fabio Estevam
2026-05-04 18:57 ` [PATCH v2 05/15] mach-snapdragon: fix reserved memory carveout Casey Connolly
2026-05-05 12:25 ` Sumit Garg
2026-05-05 12:39 ` Casey Connolly
2026-05-07 7:45 ` Sumit Garg
2026-05-07 20:29 ` Casey Connolly
2026-05-04 18:57 ` [PATCH v2 06/15] soc: qcom: import smem from Linux 6.11-rc2 Casey Connolly
2026-05-05 12:40 ` Sumit Garg
2026-05-05 12:45 ` Casey Connolly
2026-05-18 14:36 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 07/15] soc: qcom: smem: adjust headers for U-Boot Casey Connolly
2026-05-05 12:43 ` Sumit Garg
2026-05-18 14:36 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 08/15] soc: qcom: smem: adjust " Casey Connolly
2026-05-08 10:43 ` Aswin Murugan
2026-05-11 12:22 ` Casey Connolly
2026-05-18 11:03 ` Sumit Garg
2026-05-04 18:57 ` [PATCH v2 09/15] soc: qcom: smem: get serial number from socinfo Casey Connolly
2026-05-18 12:49 ` Sumit Garg
2026-05-04 18:57 ` [PATCH v2 10/15] soc: qcom: smem: stub functions Casey Connolly
2026-05-18 14:37 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 11/15] soc: qcom: smem: add build infra Casey Connolly
2026-05-18 12:53 ` Sumit Garg
2026-05-18 14:38 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 12/15] mach-snapdragon: move memory parsing to its own file Casey Connolly
2026-05-18 12:54 ` Sumit Garg [this message]
2026-05-18 14:40 ` Neil Armstrong
2026-05-04 18:57 ` [PATCH v2 13/15] mach-snapdragon: support parsing memory map from SMEM Casey Connolly
2026-05-18 14:48 ` Neil Armstrong
2026-05-21 13:36 ` Stephan Gerhold
2026-05-04 18:57 ` [PATCH v2 14/15] mach-snapdragon: fetch serial# " Casey Connolly
2026-05-18 13:15 ` Sumit Garg
2026-05-04 18:57 ` [PATCH v2 15/15] configs: add qcom_sm8650_defconfig and debug fragment Casey Connolly
2026-05-05 6:45 ` Luca Weiss
2026-05-05 10:11 ` [PATCH v2 00/15] qcom: smem: modernize SMEM in U-Boot Sumit Garg
2026-05-05 12:25 ` Casey Connolly
2026-05-05 12:35 ` Sumit Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=agsMAjyc7npwsbpt@sumit-xelite \
--to=sumit.garg@kernel.org \
--cc=alice.guo@nxp.com \
--cc=aswin.murugan@oss.qualcomm.com \
--cc=balaji.selvanathan@oss.qualcomm.com \
--cc=casey.connolly@linaro.org \
--cc=hs@nabladev.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jerome.forissier@arm.com \
--cc=linux@smankusors.com \
--cc=luca.weiss@fairphone.com \
--cc=marek.vasut+renesas@mailbox.org \
--cc=marek.vasut@mailbox.org \
--cc=michal.simek@amd.com \
--cc=mkorpershoek@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=patrice.chotard@foss.st.com \
--cc=peng.fan@nxp.com \
--cc=philip.molloy@analog.com \
--cc=quentin.schulz@cherry.de \
--cc=ravi@prevas.dk \
--cc=raymond.mao@riscstar.com \
--cc=sjg@chromium.org \
--cc=stefan.roese@mailbox.org \
--cc=sughosh.ganu@arm.com \
--cc=trini@konsulko.com \
--cc=u-boot-qcom@groups.io \
--cc=u-boot@lists.denx.de \
--cc=varadarajan.narayanan@oss.qualcomm.com \
--cc=visitorckw@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.