cpu-system.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * QEMU CPU model (system specific)
  3. *
  4. * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see
  18. * <http://www.gnu.org/licenses/gpl-2.0.html>
  19. */
  20. #include "qemu/osdep.h"
  21. #include "qapi/error.h"
  22. #include "exec/address-spaces.h"
  23. #include "exec/memory.h"
  24. #include "exec/tswap.h"
  25. #include "hw/qdev-core.h"
  26. #include "hw/qdev-properties.h"
  27. #include "hw/core/sysemu-cpu-ops.h"
  28. bool cpu_paging_enabled(const CPUState *cpu)
  29. {
  30. CPUClass *cc = CPU_GET_CLASS(cpu);
  31. if (cc->sysemu_ops->get_paging_enabled) {
  32. return cc->sysemu_ops->get_paging_enabled(cpu);
  33. }
  34. return false;
  35. }
  36. bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
  37. Error **errp)
  38. {
  39. CPUClass *cc = CPU_GET_CLASS(cpu);
  40. if (cc->sysemu_ops->get_memory_mapping) {
  41. return cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
  42. }
  43. error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
  44. return false;
  45. }
  46. hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
  47. MemTxAttrs *attrs)
  48. {
  49. CPUClass *cc = CPU_GET_CLASS(cpu);
  50. hwaddr paddr;
  51. if (cc->sysemu_ops->get_phys_page_attrs_debug) {
  52. paddr = cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
  53. } else {
  54. /* Fallback for CPUs which don't implement the _attrs_ hook */
  55. *attrs = MEMTXATTRS_UNSPECIFIED;
  56. paddr = cc->sysemu_ops->get_phys_page_debug(cpu, addr);
  57. }
  58. /* Indicate that this is a debug access. */
  59. attrs->debug = 1;
  60. return paddr;
  61. }
  62. hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
  63. {
  64. MemTxAttrs attrs = {};
  65. return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
  66. }
  67. int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
  68. {
  69. int ret = 0;
  70. if (cpu->cc->sysemu_ops->asidx_from_attrs) {
  71. ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
  72. assert(ret < cpu->num_ases && ret >= 0);
  73. }
  74. return ret;
  75. }
  76. int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  77. void *opaque)
  78. {
  79. CPUClass *cc = CPU_GET_CLASS(cpu);
  80. if (!cc->sysemu_ops->write_elf32_qemunote) {
  81. return 0;
  82. }
  83. return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
  84. }
  85. int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
  86. int cpuid, void *opaque)
  87. {
  88. CPUClass *cc = CPU_GET_CLASS(cpu);
  89. if (!cc->sysemu_ops->write_elf32_note) {
  90. return -1;
  91. }
  92. return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
  93. }
  94. int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  95. void *opaque)
  96. {
  97. CPUClass *cc = CPU_GET_CLASS(cpu);
  98. if (!cc->sysemu_ops->write_elf64_qemunote) {
  99. return 0;
  100. }
  101. return (*cc->sysemu_ops->write_elf64_qemunote)(f, cpu, opaque);
  102. }
  103. int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
  104. int cpuid, void *opaque)
  105. {
  106. CPUClass *cc = CPU_GET_CLASS(cpu);
  107. if (!cc->sysemu_ops->write_elf64_note) {
  108. return -1;
  109. }
  110. return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
  111. }
  112. bool cpu_virtio_is_big_endian(CPUState *cpu)
  113. {
  114. CPUClass *cc = CPU_GET_CLASS(cpu);
  115. if (cc->sysemu_ops->virtio_is_big_endian) {
  116. return cc->sysemu_ops->virtio_is_big_endian(cpu);
  117. }
  118. return target_words_bigendian();
  119. }
  120. GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
  121. {
  122. CPUClass *cc = CPU_GET_CLASS(cpu);
  123. GuestPanicInformation *res = NULL;
  124. if (cc->sysemu_ops->get_crash_info) {
  125. res = cc->sysemu_ops->get_crash_info(cpu);
  126. }
  127. return res;
  128. }
  129. static const Property cpu_system_props[] = {
  130. /*
  131. * Create a memory property for system CPU object, so users can
  132. * wire up its memory. The default if no link is set up is to use
  133. * the system address space.
  134. */
  135. DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
  136. MemoryRegion *),
  137. };
  138. static bool cpu_get_start_powered_off(Object *obj, Error **errp)
  139. {
  140. CPUState *cpu = CPU(obj);
  141. return cpu->start_powered_off;
  142. }
  143. static void cpu_set_start_powered_off(Object *obj, bool value, Error **errp)
  144. {
  145. CPUState *cpu = CPU(obj);
  146. cpu->start_powered_off = value;
  147. }
  148. void cpu_class_init_props(DeviceClass *dc)
  149. {
  150. ObjectClass *oc = OBJECT_CLASS(dc);
  151. /*
  152. * We can't use DEFINE_PROP_BOOL in the Property array for this
  153. * property, because we want this to be settable after realize.
  154. */
  155. object_class_property_add_bool(oc, "start-powered-off",
  156. cpu_get_start_powered_off,
  157. cpu_set_start_powered_off);
  158. device_class_set_props(dc, cpu_system_props);
  159. }
  160. void cpu_exec_initfn(CPUState *cpu)
  161. {
  162. cpu->memory = get_system_memory();
  163. object_ref(OBJECT(cpu->memory));
  164. }