xref: /openbmc/qemu/hw/ppc/fdt.c (revision 9cdd2a73)
1 /*
2  * QEMU PowerPC helper routines for the device tree.
3  *
4  * Copyright (C) 2016 IBM Corp.
5  *
6  * This code is licensed under the GPL version 2 or later. See the
7  * COPYING file in the top-level directory.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "target/ppc/cpu.h"
12 
13 #include "hw/ppc/fdt.h"
14 
15 #if defined(TARGET_PPC64)
16 size_t ppc_create_page_sizes_prop(CPUPPCState *env, uint32_t *prop,
17                                      size_t maxsize)
18 {
19     size_t maxcells = maxsize / sizeof(uint32_t);
20     int i, j, count;
21     uint32_t *p = prop;
22 
23     for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
24         struct ppc_one_seg_page_size *sps = &env->sps.sps[i];
25 
26         if (!sps->page_shift) {
27             break;
28         }
29         for (count = 0; count < PPC_PAGE_SIZES_MAX_SZ; count++) {
30             if (sps->enc[count].page_shift == 0) {
31                 break;
32             }
33         }
34         if ((p - prop) >= (maxcells - 3 - count * 2)) {
35             break;
36         }
37         *(p++) = cpu_to_be32(sps->page_shift);
38         *(p++) = cpu_to_be32(sps->slb_enc);
39         *(p++) = cpu_to_be32(count);
40         for (j = 0; j < count; j++) {
41             *(p++) = cpu_to_be32(sps->enc[j].page_shift);
42             *(p++) = cpu_to_be32(sps->enc[j].pte_enc);
43         }
44     }
45 
46     return (p - prop) * sizeof(uint32_t);
47 }
48 #endif
49