From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, groug@kaod.org,
clg@kaod.org, lvivier@redhat.com, spopovyc@redhat.com,
BALATON Zoltan <balaton@eik.bme.hu>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PULL 06/37] ppc4xx: Pass array index to function instead of pointer into the array
Date: Mon, 4 Feb 2019 20:00:53 +1100 [thread overview]
Message-ID: <20190204090124.26191-7-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20190204090124.26191-1-david@gibson.dropbear.id.au>
From: BALATON Zoltan <balaton@eik.bme.hu>
The sdram_set_bcr() function in ppc440_uc.c takes a pointer into an
array then calculates its index from that. It's simpler and easier to
just pass the index which simplifies both the function and its callers.
Do similar cleanup in ppc4xx_devs.c to similar function.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
hw/ppc/ppc440_uc.c | 36 ++++++++++++++++--------------------
hw/ppc/ppc4xx_devs.c | 44 ++++++++++++++++++++------------------------
2 files changed, 36 insertions(+), 44 deletions(-)
diff --git a/hw/ppc/ppc440_uc.c b/hw/ppc/ppc440_uc.c
index e46f59fba8..60dbb35eee 100644
--- a/hw/ppc/ppc440_uc.c
+++ b/hw/ppc/ppc440_uc.c
@@ -564,28 +564,26 @@ static target_ulong sdram_size(uint32_t bcr)
return size;
}
-static void sdram_set_bcr(ppc440_sdram_t *sdram,
- uint32_t *bcrp, uint32_t bcr, int enabled)
+static void sdram_set_bcr(ppc440_sdram_t *sdram, int i,
+ uint32_t bcr, int enabled)
{
- unsigned n = bcrp - sdram->bcr;
-
- if (*bcrp & 1) {
- /* Unmap RAM */
+ if (sdram->bcr[i] & 1) {
+ /* First unmap RAM if enabled */
memory_region_del_subregion(get_system_memory(),
- &sdram->containers[n]);
- memory_region_del_subregion(&sdram->containers[n],
- &sdram->ram_memories[n]);
- object_unparent(OBJECT(&sdram->containers[n]));
+ &sdram->containers[i]);
+ memory_region_del_subregion(&sdram->containers[i],
+ &sdram->ram_memories[i]);
+ object_unparent(OBJECT(&sdram->containers[i]));
}
- *bcrp = bcr & 0xFFDEE001;
+ sdram->bcr[i] = bcr & 0xFFDEE001;
if (enabled && (bcr & 1)) {
- memory_region_init(&sdram->containers[n], NULL, "sdram-containers",
+ memory_region_init(&sdram->containers[i], NULL, "sdram-containers",
sdram_size(bcr));
- memory_region_add_subregion(&sdram->containers[n], 0,
- &sdram->ram_memories[n]);
+ memory_region_add_subregion(&sdram->containers[i], 0,
+ &sdram->ram_memories[i]);
memory_region_add_subregion(get_system_memory(),
sdram_base(bcr),
- &sdram->containers[n]);
+ &sdram->containers[i]);
}
}
@@ -595,12 +593,10 @@ static void sdram_map_bcr(ppc440_sdram_t *sdram)
for (i = 0; i < sdram->nbanks; i++) {
if (sdram->ram_sizes[i] != 0) {
- sdram_set_bcr(sdram,
- &sdram->bcr[i],
- sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]),
- 1);
+ sdram_set_bcr(sdram, i, sdram_bcr(sdram->ram_bases[i],
+ sdram->ram_sizes[i]), 1);
} else {
- sdram_set_bcr(sdram, &sdram->bcr[i], 0, 0);
+ sdram_set_bcr(sdram, i, 0, 0);
}
}
}
diff --git a/hw/ppc/ppc4xx_devs.c b/hw/ppc/ppc4xx_devs.c
index 9418478575..fdfeb67e65 100644
--- a/hw/ppc/ppc4xx_devs.c
+++ b/hw/ppc/ppc4xx_devs.c
@@ -405,36 +405,34 @@ static target_ulong sdram_size (uint32_t bcr)
return size;
}
-static void sdram_set_bcr(ppc4xx_sdram_t *sdram,
- uint32_t *bcrp, uint32_t bcr, int enabled)
+static void sdram_set_bcr(ppc4xx_sdram_t *sdram, int i,
+ uint32_t bcr, int enabled)
{
- unsigned n = bcrp - sdram->bcr;
-
- if (*bcrp & 0x00000001) {
+ if (sdram->bcr[i] & 0x00000001) {
/* Unmap RAM */
#ifdef DEBUG_SDRAM
printf("%s: unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
- __func__, sdram_base(*bcrp), sdram_size(*bcrp));
+ __func__, sdram_base(sdram->bcr[i]), sdram_size(sdram->bcr[i]));
#endif
memory_region_del_subregion(get_system_memory(),
- &sdram->containers[n]);
- memory_region_del_subregion(&sdram->containers[n],
- &sdram->ram_memories[n]);
- object_unparent(OBJECT(&sdram->containers[n]));
+ &sdram->containers[i]);
+ memory_region_del_subregion(&sdram->containers[i],
+ &sdram->ram_memories[i]);
+ object_unparent(OBJECT(&sdram->containers[i]));
}
- *bcrp = bcr & 0xFFDEE001;
+ sdram->bcr[i] = bcr & 0xFFDEE001;
if (enabled && (bcr & 0x00000001)) {
#ifdef DEBUG_SDRAM
printf("%s: Map RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n",
__func__, sdram_base(bcr), sdram_size(bcr));
#endif
- memory_region_init(&sdram->containers[n], NULL, "sdram-containers",
+ memory_region_init(&sdram->containers[i], NULL, "sdram-containers",
sdram_size(bcr));
- memory_region_add_subregion(&sdram->containers[n], 0,
- &sdram->ram_memories[n]);
+ memory_region_add_subregion(&sdram->containers[i], 0,
+ &sdram->ram_memories[i]);
memory_region_add_subregion(get_system_memory(),
sdram_base(bcr),
- &sdram->containers[n]);
+ &sdram->containers[i]);
}
}
@@ -444,12 +442,10 @@ static void sdram_map_bcr (ppc4xx_sdram_t *sdram)
for (i = 0; i < sdram->nbanks; i++) {
if (sdram->ram_sizes[i] != 0) {
- sdram_set_bcr(sdram,
- &sdram->bcr[i],
- sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]),
- 1);
+ sdram_set_bcr(sdram, i, sdram_bcr(sdram->ram_bases[i],
+ sdram->ram_sizes[i]), 1);
} else {
- sdram_set_bcr(sdram, &sdram->bcr[i], 0x00000000, 0);
+ sdram_set_bcr(sdram, i, 0x00000000, 0);
}
}
}
@@ -589,16 +585,16 @@ static void dcr_write_sdram (void *opaque, int dcrn, uint32_t val)
sdram->pmit = (val & 0xF8000000) | 0x07C00000;
break;
case 0x40: /* SDRAM_B0CR */
- sdram_set_bcr(sdram, &sdram->bcr[0], val, sdram->cfg & 0x80000000);
+ sdram_set_bcr(sdram, 0, val, sdram->cfg & 0x80000000);
break;
case 0x44: /* SDRAM_B1CR */
- sdram_set_bcr(sdram, &sdram->bcr[1], val, sdram->cfg & 0x80000000);
+ sdram_set_bcr(sdram, 1, val, sdram->cfg & 0x80000000);
break;
case 0x48: /* SDRAM_B2CR */
- sdram_set_bcr(sdram, &sdram->bcr[2], val, sdram->cfg & 0x80000000);
+ sdram_set_bcr(sdram, 2, val, sdram->cfg & 0x80000000);
break;
case 0x4C: /* SDRAM_B3CR */
- sdram_set_bcr(sdram, &sdram->bcr[3], val, sdram->cfg & 0x80000000);
+ sdram_set_bcr(sdram, 3, val, sdram->cfg & 0x80000000);
break;
case 0x80: /* SDRAM_TR */
sdram->tr = val & 0x018FC01F;
--
2.20.1
next prev parent reply other threads:[~2019-02-04 9:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 9:00 [Qemu-devel] [PULL 00/37] ppc-for-4.0 queue 20190204 David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 01/37] pseries: Update SLOF firmware image David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 02/37] smbus: Add a helper to generate SPD EEPROM data David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 03/37] sam460ex: Clean up SPD EEPROM creation David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 04/37] ppc4xx: Use ram_addr_t in ppc4xx_sdram_adjust() David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 05/37] ppc4xx: Rename ppc4xx_sdram_t in ppc440_uc.c to ppc440_sdram_t David Gibson
2019-02-04 9:00 ` David Gibson [this message]
2019-02-04 9:00 ` [Qemu-devel] [PULL 07/37] sam460ex: Fix support for memory larger than 1GB David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 08/37] ppc/xive: fix remaining XiveFabric names David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 09/37] target/ppc/kvm: Drop useless include directive David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 10/37] ppc440: Avoid reporting error when reading non-existent RAM slot David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 11/37] spapr/vio: remove the "irq" property" David Gibson
2019-02-04 9:00 ` [Qemu-devel] [PULL 12/37] hw/ppc/spapr: Encode the SCSI channel (bus) in the SRP LUNs David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 13/37] spapr: Forbid setting ic-mode for old machine types David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 14/37] spapr/pci: Fix primary bus number for PCI bridges David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 15/37] xive: add a get_tctx() method to the XiveRouter David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 16/37] ppc/pnv: introduce a CPU machine_data David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 17/37] spapr: move the interrupt presenters under machine_data David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 18/37] target/ppc: implement complete set of Vsr* macros David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 19/37] ppc: remove the interrupt presenters from under PowerPCCPU David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 20/37] hw/ppc: Move ppc40x_*reset() functions from ppc405_uc.c to ppc.c David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 21/37] MAINTAINERS: XIVE is an interrupt controller, not a machine David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 22/37] MAINTAINERS: Merge the two e500 sections David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 23/37] spapr: Drop unused parameters from fdt building helper David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 24/37] MAINTAINERS: add myself as maintainer for Mac Old World and New World machines David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 25/37] QemuMacDrivers: update qemu_vga.ndrv to 90c488d built from submodule David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 26/37] hw/ppc/spapr: Add support for "-vga cirrus" David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 27/37] target/ppc: rework vmrg{l, h}{b, h, w} instructions to use Vsr* macros David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 28/37] target/ppc: rework vmul{e, o}{s, u}{b, " David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 29/37] target/ppc: eliminate use of HI_IDX and LO_IDX macros from int_helper.c David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 30/37] target/ppc: eliminate use of EL_IDX " David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 31/37] target/ppc: simplify VEXT_SIGNED macro in int_helper.c David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 32/37] target/ppc: remove ROTRu32 and ROTRu64 macros from int_helper.c David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 33/37] target/ppc: remove various HOST_WORDS_BIGENDIAN hacks in int_helper.c David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 34/37] spapr_pci: Fix endianness in assigned-addresses property David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 35/37] hw/ppc: Don't include m48t59.h if it is not necessary David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 36/37] mmap-alloc: unfold qemu_ram_mmap() David Gibson
2019-02-04 9:01 ` [Qemu-devel] [PULL 37/37] mmap-alloc: fix hugetlbfs misaligned length in ppc64 David Gibson
2019-02-04 12:56 ` [Qemu-devel] [PULL 00/37] ppc-for-4.0 queue 20190204 Peter Maydell
2019-02-05 11:46 ` [Qemu-devel] [Qemu-ppc] " BALATON Zoltan
2019-02-05 12:24 ` Philippe Mathieu-Daudé
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=20190204090124.26191-7-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=balaton@eik.bme.hu \
--cc=clg@kaod.org \
--cc=groug@kaod.org \
--cc=lvivier@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=spopovyc@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).