target_page.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Target page sizes and friends for non target files
  3. *
  4. * Copyright (c) 2017 Red Hat Inc
  5. *
  6. * Authors:
  7. * David Alan Gilbert <dgilbert@redhat.com>
  8. * Juan Quintela <quintela@redhat.com>
  9. *
  10. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  11. * See the COPYING file in the top-level directory.
  12. */
  13. #ifndef EXEC_TARGET_PAGE_H
  14. #define EXEC_TARGET_PAGE_H
  15. /*
  16. * If compiling per-target, get the real values.
  17. * For generic code, reuse the mechanism for variable page size.
  18. */
  19. #ifdef COMPILING_PER_TARGET
  20. #include "cpu-param.h"
  21. #include "exec/target_long.h"
  22. #define TARGET_PAGE_TYPE target_long
  23. #else
  24. #define TARGET_PAGE_BITS_VARY
  25. #define TARGET_PAGE_TYPE int
  26. #endif
  27. #ifdef TARGET_PAGE_BITS_VARY
  28. # include "exec/page-vary.h"
  29. extern const TargetPageBits target_page;
  30. # ifdef CONFIG_DEBUG_TCG
  31. # define TARGET_PAGE_BITS ({ assert(target_page.decided); \
  32. target_page.bits; })
  33. # define TARGET_PAGE_MASK ({ assert(target_page.decided); \
  34. (TARGET_PAGE_TYPE)target_page.mask; })
  35. # else
  36. # define TARGET_PAGE_BITS target_page.bits
  37. # define TARGET_PAGE_MASK ((TARGET_PAGE_TYPE)target_page.mask)
  38. # endif
  39. # define TARGET_PAGE_SIZE (-(int)TARGET_PAGE_MASK)
  40. #else
  41. # define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS
  42. # define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
  43. # define TARGET_PAGE_MASK ((TARGET_PAGE_TYPE)-1 << TARGET_PAGE_BITS)
  44. #endif
  45. #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
  46. static inline size_t qemu_target_page_size(void)
  47. {
  48. return TARGET_PAGE_SIZE;
  49. }
  50. static inline int qemu_target_page_mask(void)
  51. {
  52. return TARGET_PAGE_MASK;
  53. }
  54. static inline int qemu_target_page_bits(void)
  55. {
  56. return TARGET_PAGE_BITS;
  57. }
  58. int qemu_target_page_bits_min(void);
  59. size_t qemu_target_pages_to_MiB(size_t pages);
  60. #endif