fdt.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "qemu/osdep.h"
  10. #include "target/ppc/cpu.h"
  11. #include "target/ppc/mmu-hash64.h"
  12. #include "hw/ppc/fdt.h"
  13. #if defined(TARGET_PPC64)
  14. size_t ppc_create_page_sizes_prop(PowerPCCPU *cpu, uint32_t *prop,
  15. size_t maxsize)
  16. {
  17. size_t maxcells = maxsize / sizeof(uint32_t);
  18. int i, j, count;
  19. uint32_t *p = prop;
  20. for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
  21. PPCHash64SegmentPageSizes *sps = &cpu->hash64_opts->sps[i];
  22. if (!sps->page_shift) {
  23. break;
  24. }
  25. for (count = 0; count < PPC_PAGE_SIZES_MAX_SZ; count++) {
  26. if (sps->enc[count].page_shift == 0) {
  27. break;
  28. }
  29. }
  30. if ((p - prop) >= (maxcells - 3 - count * 2)) {
  31. break;
  32. }
  33. *(p++) = cpu_to_be32(sps->page_shift);
  34. *(p++) = cpu_to_be32(sps->slb_enc);
  35. *(p++) = cpu_to_be32(count);
  36. for (j = 0; j < count; j++) {
  37. *(p++) = cpu_to_be32(sps->enc[j].page_shift);
  38. *(p++) = cpu_to_be32(sps->enc[j].pte_enc);
  39. }
  40. }
  41. return (p - prop) * sizeof(uint32_t);
  42. }
  43. #endif