summaryrefslogtreecommitdiffstats
path: root/hw/ppc/fdt.c
diff options
context:
space:
mode:
authorCédric Le Goater2016-08-02 19:38:01 +0200
committerDavid Gibson2016-09-07 04:40:12 +0200
commit3654fa95bc29e72c2eef22f26eb621af1f86feec (patch)
tree8e69f523b29fa7b593aac6063cea5c23e8897668 /hw/ppc/fdt.c
parenthw/ppc: use error_report instead of fprintf (diff)
downloadqemu-3654fa95bc29e72c2eef22f26eb621af1f86feec.tar.gz
qemu-3654fa95bc29e72c2eef22f26eb621af1f86feec.tar.xz
qemu-3654fa95bc29e72c2eef22f26eb621af1f86feec.zip
hw/ppc: add a ppc_create_page_sizes_prop() helper routine
The exact same routine will be used in PowerNV. Signed-off-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'hw/ppc/fdt.c')
-rw-r--r--hw/ppc/fdt.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/hw/ppc/fdt.c b/hw/ppc/fdt.c
new file mode 100644
index 0000000000..e67d60d03c
--- /dev/null
+++ b/hw/ppc/fdt.c
@@ -0,0 +1,49 @@
+/*
+ * QEMU PowerPC helper routines for the device tree.
+ *
+ * Copyright (C) 2016 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later. See the
+ * COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "target-ppc/cpu.h"
+
+#include "hw/ppc/fdt.h"
+
+#if defined(TARGET_PPC64)
+size_t ppc_create_page_sizes_prop(CPUPPCState *env, uint32_t *prop,
+ size_t maxsize)
+{
+ size_t maxcells = maxsize / sizeof(uint32_t);
+ int i, j, count;
+ uint32_t *p = prop;
+
+ for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
+ struct ppc_one_seg_page_size *sps = &env->sps.sps[i];
+
+ if (!sps->page_shift) {
+ break;
+ }
+ for (count = 0; count < PPC_PAGE_SIZES_MAX_SZ; count++) {
+ if (sps->enc[count].page_shift == 0) {
+ break;
+ }
+ }
+ if ((p - prop) >= (maxcells - 3 - count * 2)) {
+ break;
+ }
+ *(p++) = cpu_to_be32(sps->page_shift);
+ *(p++) = cpu_to_be32(sps->slb_enc);
+ *(p++) = cpu_to_be32(count);
+ for (j = 0; j < count; j++) {
+ *(p++) = cpu_to_be32(sps->enc[j].page_shift);
+ *(p++) = cpu_to_be32(sps->enc[j].pte_enc);
+ }
+ }
+
+ return (p - prop) * sizeof(uint32_t);
+}
+#endif