Cédric Le Goater | 3654fa9 | 2016-08-02 19:38:01 +0200 | [diff] [blame] | 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" |
Thomas Huth | fcf5ef2 | 2016-10-11 08:56:52 +0200 | [diff] [blame] | 11 | #include "target/ppc/cpu.h" |
David Gibson | b07c59f | 2018-03-23 13:31:52 +1100 | [diff] [blame] | 12 | #include "target/ppc/mmu-hash64.h" |
Cédric Le Goater | 3654fa9 | 2016-08-02 19:38:01 +0200 | [diff] [blame] | 13 | |
| 14 | #include "hw/ppc/fdt.h" |
| 15 | |
| 16 | #if defined(TARGET_PPC64) |
David Gibson | 644a2c9 | 2018-03-22 16:18:40 +1100 | [diff] [blame] | 17 | size_t ppc_create_page_sizes_prop(PowerPCCPU *cpu, uint32_t *prop, |
| 18 | size_t maxsize) |
Cédric Le Goater | 3654fa9 | 2016-08-02 19:38:01 +0200 | [diff] [blame] | 19 | { |
Cédric Le Goater | 3654fa9 | 2016-08-02 19:38:01 +0200 | [diff] [blame] | 20 | size_t maxcells = maxsize / sizeof(uint32_t); |
| 21 | int i, j, count; |
| 22 | uint32_t *p = prop; |
| 23 | |
| 24 | for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) { |
David Gibson | b07c59f | 2018-03-23 13:31:52 +1100 | [diff] [blame] | 25 | PPCHash64SegmentPageSizes *sps = &cpu->hash64_opts->sps[i]; |
Cédric Le Goater | 3654fa9 | 2016-08-02 19:38:01 +0200 | [diff] [blame] | 26 | |
| 27 | if (!sps->page_shift) { |
| 28 | break; |
| 29 | } |
| 30 | for (count = 0; count < PPC_PAGE_SIZES_MAX_SZ; count++) { |
| 31 | if (sps->enc[count].page_shift == 0) { |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | if ((p - prop) >= (maxcells - 3 - count * 2)) { |
| 36 | break; |
| 37 | } |
| 38 | *(p++) = cpu_to_be32(sps->page_shift); |
| 39 | *(p++) = cpu_to_be32(sps->slb_enc); |
| 40 | *(p++) = cpu_to_be32(count); |
| 41 | for (j = 0; j < count; j++) { |
| 42 | *(p++) = cpu_to_be32(sps->enc[j].page_shift); |
| 43 | *(p++) = cpu_to_be32(sps->enc[j].pte_enc); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return (p - prop) * sizeof(uint32_t); |
| 48 | } |
| 49 | #endif |