cpu-common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef CPU_COMMON_H
  2. #define CPU_COMMON_H
  3. /* CPU interfaces that are target independent. */
  4. #ifndef CONFIG_USER_ONLY
  5. #include "exec/hwaddr.h"
  6. #endif
  7. /**
  8. * vaddr:
  9. * Type wide enough to contain any #target_ulong virtual address.
  10. */
  11. typedef uint64_t vaddr;
  12. #define VADDR_PRId PRId64
  13. #define VADDR_PRIu PRIu64
  14. #define VADDR_PRIo PRIo64
  15. #define VADDR_PRIx PRIx64
  16. #define VADDR_PRIX PRIX64
  17. #define VADDR_MAX UINT64_MAX
  18. void cpu_exec_init_all(void);
  19. void cpu_exec_step_atomic(CPUState *cpu);
  20. /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
  21. * when intptr_t is 32-bit and we are aligning a long long.
  22. */
  23. extern uintptr_t qemu_host_page_size;
  24. extern intptr_t qemu_host_page_mask;
  25. #define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
  26. #define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size())
  27. /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
  28. void qemu_init_cpu_list(void);
  29. void cpu_list_lock(void);
  30. void cpu_list_unlock(void);
  31. unsigned int cpu_list_generation_id_get(void);
  32. void tcg_flush_softmmu_tlb(CPUState *cs);
  33. void tcg_iommu_init_notifier_list(CPUState *cpu);
  34. void tcg_iommu_free_notifier_list(CPUState *cpu);
  35. #if !defined(CONFIG_USER_ONLY)
  36. enum device_endian {
  37. DEVICE_NATIVE_ENDIAN,
  38. DEVICE_BIG_ENDIAN,
  39. DEVICE_LITTLE_ENDIAN,
  40. };
  41. #if HOST_BIG_ENDIAN
  42. #define DEVICE_HOST_ENDIAN DEVICE_BIG_ENDIAN
  43. #else
  44. #define DEVICE_HOST_ENDIAN DEVICE_LITTLE_ENDIAN
  45. #endif
  46. /* address in the RAM (different from a physical address) */
  47. #if defined(CONFIG_XEN_BACKEND)
  48. typedef uint64_t ram_addr_t;
  49. # define RAM_ADDR_MAX UINT64_MAX
  50. # define RAM_ADDR_FMT "%" PRIx64
  51. #else
  52. typedef uintptr_t ram_addr_t;
  53. # define RAM_ADDR_MAX UINTPTR_MAX
  54. # define RAM_ADDR_FMT "%" PRIxPTR
  55. #endif
  56. /* memory API */
  57. void qemu_ram_remap(ram_addr_t addr, ram_addr_t length);
  58. /* This should not be used by devices. */
  59. ram_addr_t qemu_ram_addr_from_host(void *ptr);
  60. RAMBlock *qemu_ram_block_by_name(const char *name);
  61. RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
  62. ram_addr_t *offset);
  63. ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host);
  64. void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
  65. void qemu_ram_unset_idstr(RAMBlock *block);
  66. const char *qemu_ram_get_idstr(RAMBlock *rb);
  67. void *qemu_ram_get_host_addr(RAMBlock *rb);
  68. ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
  69. ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
  70. ram_addr_t qemu_ram_get_max_length(RAMBlock *rb);
  71. bool qemu_ram_is_shared(RAMBlock *rb);
  72. bool qemu_ram_is_noreserve(RAMBlock *rb);
  73. bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
  74. void qemu_ram_set_uf_zeroable(RAMBlock *rb);
  75. bool qemu_ram_is_migratable(RAMBlock *rb);
  76. void qemu_ram_set_migratable(RAMBlock *rb);
  77. void qemu_ram_unset_migratable(RAMBlock *rb);
  78. size_t qemu_ram_pagesize(RAMBlock *block);
  79. size_t qemu_ram_pagesize_largest(void);
  80. /**
  81. * cpu_address_space_init:
  82. * @cpu: CPU to add this address space to
  83. * @asidx: integer index of this address space
  84. * @prefix: prefix to be used as name of address space
  85. * @mr: the root memory region of address space
  86. *
  87. * Add the specified address space to the CPU's cpu_ases list.
  88. * The address space added with @asidx 0 is the one used for the
  89. * convenience pointer cpu->as.
  90. * The target-specific code which registers ASes is responsible
  91. * for defining what semantics address space 0, 1, 2, etc have.
  92. *
  93. * Before the first call to this function, the caller must set
  94. * cpu->num_ases to the total number of address spaces it needs
  95. * to support.
  96. *
  97. * Note that with KVM only one address space is supported.
  98. */
  99. void cpu_address_space_init(CPUState *cpu, int asidx,
  100. const char *prefix, MemoryRegion *mr);
  101. void cpu_physical_memory_rw(hwaddr addr, void *buf,
  102. hwaddr len, bool is_write);
  103. static inline void cpu_physical_memory_read(hwaddr addr,
  104. void *buf, hwaddr len)
  105. {
  106. cpu_physical_memory_rw(addr, buf, len, false);
  107. }
  108. static inline void cpu_physical_memory_write(hwaddr addr,
  109. const void *buf, hwaddr len)
  110. {
  111. cpu_physical_memory_rw(addr, (void *)buf, len, true);
  112. }
  113. void cpu_reloading_memory_map(void);
  114. void *cpu_physical_memory_map(hwaddr addr,
  115. hwaddr *plen,
  116. bool is_write);
  117. void cpu_physical_memory_unmap(void *buffer, hwaddr len,
  118. bool is_write, hwaddr access_len);
  119. void cpu_register_map_client(QEMUBH *bh);
  120. void cpu_unregister_map_client(QEMUBH *bh);
  121. bool cpu_physical_memory_is_io(hwaddr phys_addr);
  122. /* Coalesced MMIO regions are areas where write operations can be reordered.
  123. * This usually implies that write operations are side-effect free. This allows
  124. * batching which can make a major impact on performance when using
  125. * virtualization.
  126. */
  127. void qemu_flush_coalesced_mmio_buffer(void);
  128. void cpu_flush_icache_range(hwaddr start, hwaddr len);
  129. typedef int (RAMBlockIterFunc)(RAMBlock *rb, void *opaque);
  130. int qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
  131. int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
  132. #endif
  133. /* Returns: 0 on success, -1 on error */
  134. int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
  135. void *ptr, size_t len, bool is_write);
  136. /* vl.c */
  137. extern int singlestep;
  138. void list_cpus(const char *optarg);
  139. #endif /* CPU_COMMON_H */