All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/ppc/ppc4xx: Only accept (combination of) pow2 DDR sizes
@ 2020-06-29 20:02 Philippe Mathieu-Daudé
  2020-06-30  1:03 ` BALATON Zoltan
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-29 20:02 UTC (permalink / raw)
  To: qemu-devel, BALATON Zoltan
  Cc: Igor Mammedov, Philippe Mathieu-Daudé,
	qemu-ppc, Markus Armbruster, David Gibson

Use popcount instruction to count the number of bits set in
the RAM size. Allow at most 1 bit for each bank. This avoid
using invalid hardware configurations.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/ppc/ppc4xx_devs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/ppc/ppc4xx_devs.c b/hw/ppc/ppc4xx_devs.c
index f1651e04d9..c2484a5695 100644
--- a/hw/ppc/ppc4xx_devs.c
+++ b/hw/ppc/ppc4xx_devs.c
@@ -687,6 +687,15 @@ void ppc4xx_sdram_banks(MemoryRegion *ram, int nr_banks,
     int i;
     int j;
 
+    if (ctpop64(size_left) > nr_banks) {
+        if (nr_banks) {
+            error_report("RAM size must be a power of 2");
+        } else {
+            error_report("RAM size must be the combination of %d powers of 2",
+                         nr_banks);
+        }
+        exit(1);
+    }
     for (i = 0; i < nr_banks; i++) {
         for (j = 0; sdram_bank_sizes[j] != 0; j++) {
             bank_size = sdram_bank_sizes[j];
-- 
2.21.3



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-08 23:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 20:02 [PATCH] hw/ppc/ppc4xx: Only accept (combination of) pow2 DDR sizes Philippe Mathieu-Daudé
2020-06-30  1:03 ` BALATON Zoltan
2020-07-08  7:16   ` Markus Armbruster

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.