From 6010818c30ce9c796b4e22fd261fc6fea1cecbfc Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Thu, 3 Jul 2014 13:10:05 +1000 Subject: [PATCH] spapr: Split memory nodes to power-of-two blocks Linux kernel expects nodes to have power-of-two size and does WARN_ON if this is not the case: [ 0.041456] WARNING: at drivers/base/memory.c:115 which is: === /* Validate blk_sz is a power of 2 and not less than section size */ if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) { WARN_ON(1); block_sz = MIN_MEMORY_BLOCK_SIZE; } === This splits memory nodes into set of smaller blocks with a size which is a power of two. This makes sure the start address of every node is aligned to the node size. Signed-off-by: Alexey Kardashevskiy [agraf: squash windows compile fix in] Signed-off-by: Alexander Graf --- hw/ppc/spapr.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 718a201d88..f2fa11e951 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -691,8 +691,18 @@ static int spapr_populate_memory(sPAPREnvironment *spapr, void *fdt) mem_start += spapr->rma_size; node_size -= spapr->rma_size; } - spapr_populate_memory_node(fdt, i, mem_start, node_size); - mem_start += node_size; + for ( ; node_size; ) { + hwaddr sizetmp = pow2floor(node_size); + + /* mem_start != 0 here */ + if (ctzl(mem_start) < ctzl(sizetmp)) { + sizetmp = 1ULL << ctzl(mem_start); + } + + spapr_populate_memory_node(fdt, i, mem_start, sizetmp); + node_size -= sizetmp; + mem_start += sizetmp; + } } return 0;