spapr: Move DT memory node rendering to a helper

This moves recurring bits of code related to memory@xxx nodes
creation to a helper.

This makes use of the new helper for node@0.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
spapr: Use DT memory node rendering helper for other nodes

This finishes refactoring by using the spapr_populate_memory_node helper
for all nodes and removing leftovers from spapr_populate_memory().

This is not a part of the previous patch because the patches look
nicer apart.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
spapr: Refactor spapr_populate_memory()

Current QEMU does not support memoryless NUMA nodes.
This prepares SPAPR for that.

This moves 2 calls of spapr_populate_memory_node() into
the existing loop which handles nodes other than than
the first one.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
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.041052] devtmpfs: initialized
[    0.041292] ------------[ cut here ]------------
[    0.041456] WARNING: at drivers/base/memory.c:115

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 <aik@ozlabs.ru>
spapr: Add a helper for node0_size calculation

In multiple places there is a node0_size variable calculation
which assumes that NUMA node #0 and memory node #0 are the same
things which they are not. Since we are going to change it and
do not want to change it in multiple places, let's make a helper.

This adds a spapr_node0_size() helper and makes use of it.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
spapr: Fix ibm,associativity for memory nodes

We want the associtivity lists of memory and CPU nodes to match but
memory nodes have incorrect domain#3 which is zero for CPU so they won't
match.

This clears domain#3 in the list to match CPUs associtivity lists.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
numa: Allow empty nodes

Currently NUMA nodes must go consequently and QEMU ignores nodes
with @nodeid bigger than the number of NUMA nodes in the command line.
This prevents us from creating memory-less nodes which is possible
situation in POWERPC under pHyp or Sapphire.

This makes nb_numa_nodes a total number of nodes or the biggest node
number + 1 whichever is greater.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>