From: Sascha Hauer <s.hauer@pengutronix.de>
To: Michael Tretter <m.tretter@pengutronix.de>
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>,
Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: Re: [PATCH v2 04/10] arm: socfpga: iossm: store size in bytes
Date: Mon, 13 Apr 2026 09:27:48 +0200 [thread overview]
Message-ID: <adya9HnyJ7sYlJdr@pengutronix.de> (raw)
In-Reply-To: <adjnyOYr0g4d-st9@pengutronix.de>
On Fri, Apr 10, 2026 at 02:06:32PM +0200, Michael Tretter wrote:
> On Fri, 10 Apr 2026 10:37:09 +0200, Ahmad Fatoum wrote:
> > On 4/10/26 10:31 AM, Michael Tretter wrote:
> > > On Fri, 10 Apr 2026 10:13:41 +0200, Ahmad Fatoum wrote:
> > >> On 4/9/26 3:52 PM, Michael Tretter wrote:
> > >>> The mem_width_info is the memory size in gigabits. Convert it to bytes
> > >>> before storing it for each bank to have a more convenient format and
> > >>> simplify the conversion when reading the value.
> > >>>
> > >>> Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
> > >>> ---
> > >>> Changes in v2:
> > >>>
> > >>> - Change memory_size in io96b_mb_ctrl to phys_size_t to prevent overflow
> > >>
> > >> Thanks for addressing the concern. I looked it over and there's still a
> > >> chance for overflow.
> > >>
> > >>> diff --git a/arch/arm/mach-socfpga/iossm_mailbox.c b/arch/arm/mach-socfpga/iossm_mailbox.c
> > >>> index 9299fee71e0b..042ea4a99e5c 100644
> > >>> --- a/arch/arm/mach-socfpga/iossm_mailbox.c
> > >>> +++ b/arch/arm/mach-socfpga/iossm_mailbox.c
> > >>> @@ -9,6 +9,7 @@
> > >>> #include <common.h>
> > >>> #include <io.h>
> > >>> #include <linux/bitfield.h>
> > >>> +#include <linux/sizes.h>
> > >>> #include "iossm_mailbox.h"
> > >>> #include <mach/socfpga/generic.h>
> > >>> #include <mach/socfpga/soc64-regs.h>
> > >>> @@ -404,21 +405,25 @@ int io96b_get_mem_width_info(struct io96b_info *io96b_ctrl)
> > >>> struct io96b_mb_resp usr_resp;
> > >>> struct io96b_mb_ctrl *mb_ctrl;
> > >>> int i, j;
> > >>> - u16 memory_size;
> > >>> - u16 total_memory_size = 0;
> > >>> + phys_size_t memory_size;
> > >>> + u32 mem_width_info;
> > >>> + phys_size_t total_memory_size = 0;
> > >>>
> > >>> /* Get all memory interface(s) total memory size on all instance(s) */
> > >>> for (i = 0; i < io96b_ctrl->num_instance; i++) {
> > >>> mb_ctrl = &io96b_ctrl->io96b[i].mb_ctrl;
> > >>> memory_size = 0;
> > >>> +
> > >>> for (j = 0; j < mb_ctrl->num_mem_interface; j++) {
> > >>> io96b_mb_req_no_param(io96b_ctrl->io96b[i].io96b_csr_addr,
> > >>> mb_ctrl->ip_type[j],
> > >>> mb_ctrl->ip_instance_id[j],
> > >>> CMD_GET_MEM_INFO, GET_MEM_WIDTH_INFO, &usr_resp);
> > >>> + mem_width_info = usr_resp.cmd_resp_data[1] & GENMASK(7, 0);
> > >>
> > >> I assume this is the RAM memory width in bytes, e.g. 2 or 4 bytes, but
> > >> the mask allows it to be up to 255.
> > >
> > > mem_width_info is in Giga bits.
> >
> > Uh, is memory width here not the number of bits transferred per clock
> > cycle..?
>
> Maybe I'm confused, but I understand that it's not the bits transferred
> per clock cycle (the memory bus interface width), but information about
> the memory geometry under the assumption of a memory depth of 1 Giga
> bits. My understanding could be wrong, though.
>
> >
> > >
> > >>
> > >>>
> > >>> - memory_size = memory_size +
> > >>> - (usr_resp.cmd_resp_data[1] & GENMASK(7, 0));
> > >>> + mb_ctrl->memory_size[j] = mem_width_info * (SZ_1G / SZ_8);
> > >>
> > >> SZ_4G / (SZ_1G / 8) = 32
> > >>
> > >> So the maximum value permitted in mem_width_info without overflowing is
> > >> 31, but the code accepts up to 255. As all types on the left hand side
> > >> are 32-bit only.
> > >
> > > This driver is only available on Agilex5, which is arm64 and selects
> > > PHYS_ADDR_T_64BIT. Thus, phys_size_t has 64 bits and doesn't result in
> > > an overflow.
> >
> > Sorry, left-right confusion. The right had size is all 32-bit integers,
> > so they may wrap around and are truncated before assignment to the
> > 64-bit left hand side.
>
> Ah, indeed. I'll add the necessary cast to the right hand side.
Added a cast to phys_size_t to the right hand side while applying.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2026-04-13 7:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 13:52 [PATCH v2 00/10] arm: socfpga: iossm: add support for mailbox v1 Michael Tretter
2026-04-09 13:52 ` [PATCH v2 01/10] arm: socfpga: iossm: remove uninitialized variable Michael Tretter
2026-04-09 13:52 ` [PATCH v2 02/10] arm: socfpga: iossm: add version check Michael Tretter
2026-04-10 8:18 ` Ahmad Fatoum
2026-04-10 13:24 ` Michael Tretter
2026-04-09 13:52 ` [PATCH v2 03/10] arm: socfpga: iossm: use local mb_ctrl variable Michael Tretter
2026-04-09 13:52 ` [PATCH v2 04/10] arm: socfpga: iossm: store size in bytes Michael Tretter
2026-04-10 8:13 ` Ahmad Fatoum
2026-04-10 8:31 ` Michael Tretter
2026-04-10 8:37 ` Ahmad Fatoum
2026-04-10 12:06 ` Michael Tretter
2026-04-13 7:27 ` Sascha Hauer [this message]
2026-04-09 13:52 ` [PATCH v2 05/10] arm: socfpga: iossm: refactor io96b_mb_init Michael Tretter
2026-04-09 13:52 ` [PATCH v2 06/10] arm: socfpga: iossm: refactor return value handling Michael Tretter
2026-04-09 13:52 ` [PATCH v2 07/10] arm: socfgpa: iossm: extract poll_bist_mem_init_status Michael Tretter
2026-04-09 13:52 ` [PATCH v2 08/10] arm: socfgpa: iossm: extract initialization of one interface Michael Tretter
2026-04-15 6:12 ` Sascha Hauer
2026-04-15 8:29 ` Michael Tretter
2026-04-15 10:31 ` Sascha Hauer
2026-04-15 10:56 ` [PATCH] fixup! " Michael Tretter
2026-04-15 11:48 ` Sascha Hauer
2026-04-09 13:52 ` [PATCH v2 09/10] arm: socfpga: iossm: add memory initialization with inline ecc Michael Tretter
2026-04-09 13:52 ` [PATCH v2 10/10] arm: socfpga: iossm: add support for mailbox v1 Michael Tretter
2026-04-10 8:19 ` [PATCH v2 00/10] " Ahmad Fatoum
2026-04-13 7:26 ` Sascha Hauer
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=adya9HnyJ7sYlJdr@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.tretter@pengutronix.de \
--cc=s.trumtrar@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox