machine.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. /*
  2. * QEMU Machine
  3. *
  4. * Copyright (C) 2014 Red Hat Inc
  5. *
  6. * Authors:
  7. * Marcel Apfelbaum <marcel.a@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qemu/units.h"
  14. #include "qemu/accel.h"
  15. #include "system/replay.h"
  16. #include "hw/boards.h"
  17. #include "hw/loader.h"
  18. #include "qemu/error-report.h"
  19. #include "qapi/error.h"
  20. #include "qapi/qapi-visit-machine.h"
  21. #include "qapi/qapi-commands-machine.h"
  22. #include "qemu/madvise.h"
  23. #include "qom/object_interfaces.h"
  24. #include "system/cpus.h"
  25. #include "system/system.h"
  26. #include "system/reset.h"
  27. #include "system/runstate.h"
  28. #include "system/xen.h"
  29. #include "system/qtest.h"
  30. #include "hw/pci/pci_bridge.h"
  31. #include "hw/mem/nvdimm.h"
  32. #include "migration/global_state.h"
  33. #include "system/confidential-guest-support.h"
  34. #include "hw/virtio/virtio-pci.h"
  35. #include "hw/virtio/virtio-net.h"
  36. #include "hw/virtio/virtio-iommu.h"
  37. #include "audio/audio.h"
  38. GlobalProperty hw_compat_9_2[] = {
  39. {"arm-cpu", "backcompat-pauth-default-use-qarma5", "true"},
  40. { "virtio-balloon-pci", "vectors", "0" },
  41. { "virtio-balloon-pci-transitional", "vectors", "0" },
  42. { "virtio-balloon-pci-non-transitional", "vectors", "0" },
  43. { "virtio-mem-pci", "vectors", "0" },
  44. { "migration", "multifd-clean-tls-termination", "false" },
  45. { "migration", "send-switchover-start", "off"},
  46. { "vfio-pci", "x-migration-multifd-transfer", "off" },
  47. };
  48. const size_t hw_compat_9_2_len = G_N_ELEMENTS(hw_compat_9_2);
  49. GlobalProperty hw_compat_9_1[] = {
  50. { TYPE_PCI_DEVICE, "x-pcie-ext-tag", "false" },
  51. };
  52. const size_t hw_compat_9_1_len = G_N_ELEMENTS(hw_compat_9_1);
  53. GlobalProperty hw_compat_9_0[] = {
  54. {"arm-cpu", "backcompat-cntfrq", "true" },
  55. { "scsi-hd", "migrate-emulated-scsi-request", "false" },
  56. { "scsi-cd", "migrate-emulated-scsi-request", "false" },
  57. {"vfio-pci", "skip-vsc-check", "false" },
  58. { "virtio-pci", "x-pcie-pm-no-soft-reset", "off" },
  59. {"sd-card", "spec_version", "2" },
  60. };
  61. const size_t hw_compat_9_0_len = G_N_ELEMENTS(hw_compat_9_0);
  62. GlobalProperty hw_compat_8_2[] = {
  63. { "migration", "zero-page-detection", "legacy"},
  64. { TYPE_VIRTIO_IOMMU_PCI, "granule", "4k" },
  65. { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "64" },
  66. { "virtio-gpu-device", "x-scanout-vmstate-version", "1" },
  67. };
  68. const size_t hw_compat_8_2_len = G_N_ELEMENTS(hw_compat_8_2);
  69. GlobalProperty hw_compat_8_1[] = {
  70. { TYPE_PCI_BRIDGE, "x-pci-express-writeable-slt-bug", "true" },
  71. { "ramfb", "x-migrate", "off" },
  72. { "vfio-pci-nohotplug", "x-ramfb-migrate", "off" },
  73. { "igb", "x-pcie-flr-init", "off" },
  74. { TYPE_VIRTIO_NET, "host_uso", "off"},
  75. { TYPE_VIRTIO_NET, "guest_uso4", "off"},
  76. { TYPE_VIRTIO_NET, "guest_uso6", "off"},
  77. };
  78. const size_t hw_compat_8_1_len = G_N_ELEMENTS(hw_compat_8_1);
  79. GlobalProperty hw_compat_8_0[] = {
  80. { "migration", "multifd-flush-after-each-section", "on"},
  81. { TYPE_PCI_DEVICE, "x-pcie-ari-nextfn-1", "on" },
  82. };
  83. const size_t hw_compat_8_0_len = G_N_ELEMENTS(hw_compat_8_0);
  84. GlobalProperty hw_compat_7_2[] = {
  85. { "e1000e", "migrate-timadj", "off" },
  86. { "virtio-mem", "x-early-migration", "false" },
  87. { "migration", "x-preempt-pre-7-2", "true" },
  88. { TYPE_PCI_DEVICE, "x-pcie-err-unc-mask", "off" },
  89. };
  90. const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
  91. GlobalProperty hw_compat_7_1[] = {
  92. { "virtio-device", "queue_reset", "false" },
  93. { "virtio-rng-pci", "vectors", "0" },
  94. { "virtio-rng-pci-transitional", "vectors", "0" },
  95. { "virtio-rng-pci-non-transitional", "vectors", "0" },
  96. };
  97. const size_t hw_compat_7_1_len = G_N_ELEMENTS(hw_compat_7_1);
  98. GlobalProperty hw_compat_7_0[] = {
  99. { "arm-gicv3-common", "force-8-bit-prio", "on" },
  100. { "nvme-ns", "eui64-default", "on"},
  101. };
  102. const size_t hw_compat_7_0_len = G_N_ELEMENTS(hw_compat_7_0);
  103. GlobalProperty hw_compat_6_2[] = {
  104. { "PIIX4_PM", "x-not-migrate-acpi-index", "on"},
  105. };
  106. const size_t hw_compat_6_2_len = G_N_ELEMENTS(hw_compat_6_2);
  107. GlobalProperty hw_compat_6_1[] = {
  108. { "vhost-user-vsock-device", "seqpacket", "off" },
  109. { "nvme-ns", "shared", "off" },
  110. };
  111. const size_t hw_compat_6_1_len = G_N_ELEMENTS(hw_compat_6_1);
  112. GlobalProperty hw_compat_6_0[] = {
  113. { "gpex-pcihost", "allow-unmapped-accesses", "false" },
  114. { "i8042", "extended-state", "false"},
  115. { "nvme-ns", "eui64-default", "off"},
  116. { "e1000", "init-vet", "off" },
  117. { "e1000e", "init-vet", "off" },
  118. { "vhost-vsock-device", "seqpacket", "off" },
  119. };
  120. const size_t hw_compat_6_0_len = G_N_ELEMENTS(hw_compat_6_0);
  121. GlobalProperty hw_compat_5_2[] = {
  122. { "ICH9-LPC", "smm-compat", "on"},
  123. { "PIIX4_PM", "smm-compat", "on"},
  124. { "virtio-blk-device", "report-discard-granularity", "off" },
  125. { "virtio-net-pci-base", "vectors", "3"},
  126. { "nvme", "msix-exclusive-bar", "on"},
  127. };
  128. const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2);
  129. GlobalProperty hw_compat_5_1[] = {
  130. { "vhost-scsi", "num_queues", "1"},
  131. { "vhost-user-blk", "num-queues", "1"},
  132. { "vhost-user-scsi", "num_queues", "1"},
  133. { "virtio-blk-device", "num-queues", "1"},
  134. { "virtio-scsi-device", "num_queues", "1"},
  135. { "nvme", "use-intel-id", "on"},
  136. { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */
  137. { "pl011", "migrate-clk", "off" },
  138. { "virtio-pci", "x-ats-page-aligned", "off"},
  139. };
  140. const size_t hw_compat_5_1_len = G_N_ELEMENTS(hw_compat_5_1);
  141. GlobalProperty hw_compat_5_0[] = {
  142. { "pci-host-bridge", "x-config-reg-migration-enabled", "off" },
  143. { "virtio-balloon-device", "page-poison", "false" },
  144. { "vmport", "x-read-set-eax", "off" },
  145. { "vmport", "x-signal-unsupported-cmd", "off" },
  146. { "vmport", "x-report-vmx-type", "off" },
  147. { "vmport", "x-cmds-v2", "off" },
  148. { "virtio-device", "x-disable-legacy-check", "true" },
  149. };
  150. const size_t hw_compat_5_0_len = G_N_ELEMENTS(hw_compat_5_0);
  151. GlobalProperty hw_compat_4_2[] = {
  152. { "virtio-blk-device", "queue-size", "128"},
  153. { "virtio-scsi-device", "virtqueue_size", "128"},
  154. { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
  155. { "virtio-blk-device", "seg-max-adjust", "off"},
  156. { "virtio-scsi-device", "seg_max_adjust", "off"},
  157. { "vhost-blk-device", "seg_max_adjust", "off"},
  158. { "usb-host", "suppress-remote-wake", "off" },
  159. { "usb-redir", "suppress-remote-wake", "off" },
  160. { "qxl", "revision", "4" },
  161. { "qxl-vga", "revision", "4" },
  162. { "fw_cfg", "acpi-mr-restore", "false" },
  163. { "virtio-device", "use-disabled-flag", "false" },
  164. };
  165. const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
  166. GlobalProperty hw_compat_4_1[] = {
  167. { "virtio-pci", "x-pcie-flr-init", "off" },
  168. };
  169. const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1);
  170. GlobalProperty hw_compat_4_0[] = {
  171. { "VGA", "edid", "false" },
  172. { "secondary-vga", "edid", "false" },
  173. { "bochs-display", "edid", "false" },
  174. { "virtio-vga", "edid", "false" },
  175. { "virtio-gpu-device", "edid", "false" },
  176. { "virtio-device", "use-started", "false" },
  177. { "virtio-balloon-device", "qemu-4-0-config-size", "true" },
  178. { "pl031", "migrate-tick-offset", "false" },
  179. };
  180. const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0);
  181. GlobalProperty hw_compat_3_1[] = {
  182. { "pcie-root-port", "x-speed", "2_5" },
  183. { "pcie-root-port", "x-width", "1" },
  184. { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
  185. { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
  186. { "tpm-crb", "ppi", "false" },
  187. { "tpm-tis", "ppi", "false" },
  188. { "usb-kbd", "serial", "42" },
  189. { "usb-mouse", "serial", "42" },
  190. { "usb-tablet", "serial", "42" },
  191. { "virtio-blk-device", "discard", "false" },
  192. { "virtio-blk-device", "write-zeroes", "false" },
  193. { "virtio-balloon-device", "qemu-4-0-config-size", "false" },
  194. { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */
  195. };
  196. const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
  197. GlobalProperty hw_compat_3_0[] = {};
  198. const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0);
  199. GlobalProperty hw_compat_2_12[] = {
  200. { "hda-audio", "use-timer", "false" },
  201. { "cirrus-vga", "global-vmstate", "true" },
  202. { "VGA", "global-vmstate", "true" },
  203. { "vmware-svga", "global-vmstate", "true" },
  204. { "qxl-vga", "global-vmstate", "true" },
  205. };
  206. const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12);
  207. GlobalProperty hw_compat_2_11[] = {
  208. { "hpet", "hpet-offset-saved", "false" },
  209. { "virtio-blk-pci", "vectors", "2" },
  210. { "vhost-user-blk-pci", "vectors", "2" },
  211. { "e1000", "migrate_tso_props", "off" },
  212. };
  213. const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11);
  214. GlobalProperty hw_compat_2_10[] = {
  215. { "virtio-mouse-device", "wheel-axis", "false" },
  216. { "virtio-tablet-device", "wheel-axis", "false" },
  217. };
  218. const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10);
  219. GlobalProperty hw_compat_2_9[] = {
  220. { "pci-bridge", "shpc", "off" },
  221. { "intel-iommu", "pt", "off" },
  222. { "virtio-net-device", "x-mtu-bypass-backend", "off" },
  223. { "pcie-root-port", "x-migrate-msix", "false" },
  224. };
  225. const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9);
  226. GlobalProperty hw_compat_2_8[] = {
  227. { "fw_cfg_mem", "x-file-slots", "0x10" },
  228. { "fw_cfg_io", "x-file-slots", "0x10" },
  229. { "pflash_cfi01", "old-multiple-chip-handling", "on" },
  230. { "pci-bridge", "shpc", "on" },
  231. { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" },
  232. { "virtio-pci", "x-pcie-deverr-init", "off" },
  233. { "virtio-pci", "x-pcie-lnkctl-init", "off" },
  234. { "virtio-pci", "x-pcie-pm-init", "off" },
  235. { "cirrus-vga", "vgamem_mb", "8" },
  236. { "isa-cirrus-vga", "vgamem_mb", "8" },
  237. };
  238. const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8);
  239. GlobalProperty hw_compat_2_7[] = {
  240. { "virtio-pci", "page-per-vq", "on" },
  241. { "virtio-serial-device", "emergency-write", "off" },
  242. { "ioapic", "version", "0x11" },
  243. { "intel-iommu", "x-buggy-eim", "true" },
  244. { "virtio-pci", "x-ignore-backend-features", "on" },
  245. };
  246. const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
  247. GlobalProperty hw_compat_2_6[] = {
  248. { "virtio-mmio", "format_transport_address", "off" },
  249. /* Optional because not all virtio-pci devices support legacy mode */
  250. { "virtio-pci", "disable-modern", "on", .optional = true },
  251. { "virtio-pci", "disable-legacy", "off", .optional = true },
  252. };
  253. const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
  254. GlobalProperty hw_compat_2_5[] = {
  255. { "isa-fdc", "fallback", "144" },
  256. { "pvscsi", "x-old-pci-configuration", "on" },
  257. { "pvscsi", "x-disable-pcie", "on" },
  258. { "vmxnet3", "x-old-msi-offsets", "on" },
  259. { "vmxnet3", "x-disable-pcie", "on" },
  260. };
  261. const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5);
  262. GlobalProperty hw_compat_2_4[] = {
  263. { "e1000", "extra_mac_registers", "off" },
  264. { "virtio-pci", "x-disable-pcie", "on" },
  265. { "virtio-pci", "migrate-extra", "off" },
  266. { "fw_cfg_mem", "dma_enabled", "off" },
  267. { "fw_cfg_io", "dma_enabled", "off" }
  268. };
  269. const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4);
  270. MachineState *current_machine;
  271. static char *machine_get_kernel(Object *obj, Error **errp)
  272. {
  273. MachineState *ms = MACHINE(obj);
  274. return g_strdup(ms->kernel_filename);
  275. }
  276. static void machine_set_kernel(Object *obj, const char *value, Error **errp)
  277. {
  278. MachineState *ms = MACHINE(obj);
  279. g_free(ms->kernel_filename);
  280. ms->kernel_filename = g_strdup(value);
  281. }
  282. static char *machine_get_shim(Object *obj, Error **errp)
  283. {
  284. MachineState *ms = MACHINE(obj);
  285. return g_strdup(ms->shim_filename);
  286. }
  287. static void machine_set_shim(Object *obj, const char *value, Error **errp)
  288. {
  289. MachineState *ms = MACHINE(obj);
  290. g_free(ms->shim_filename);
  291. ms->shim_filename = g_strdup(value);
  292. }
  293. static char *machine_get_initrd(Object *obj, Error **errp)
  294. {
  295. MachineState *ms = MACHINE(obj);
  296. return g_strdup(ms->initrd_filename);
  297. }
  298. static void machine_set_initrd(Object *obj, const char *value, Error **errp)
  299. {
  300. MachineState *ms = MACHINE(obj);
  301. g_free(ms->initrd_filename);
  302. ms->initrd_filename = g_strdup(value);
  303. }
  304. static char *machine_get_append(Object *obj, Error **errp)
  305. {
  306. MachineState *ms = MACHINE(obj);
  307. return g_strdup(ms->kernel_cmdline);
  308. }
  309. static void machine_set_append(Object *obj, const char *value, Error **errp)
  310. {
  311. MachineState *ms = MACHINE(obj);
  312. g_free(ms->kernel_cmdline);
  313. ms->kernel_cmdline = g_strdup(value);
  314. }
  315. static char *machine_get_dtb(Object *obj, Error **errp)
  316. {
  317. MachineState *ms = MACHINE(obj);
  318. return g_strdup(ms->dtb);
  319. }
  320. static void machine_set_dtb(Object *obj, const char *value, Error **errp)
  321. {
  322. MachineState *ms = MACHINE(obj);
  323. g_free(ms->dtb);
  324. ms->dtb = g_strdup(value);
  325. }
  326. static char *machine_get_dumpdtb(Object *obj, Error **errp)
  327. {
  328. MachineState *ms = MACHINE(obj);
  329. return g_strdup(ms->dumpdtb);
  330. }
  331. static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
  332. {
  333. MachineState *ms = MACHINE(obj);
  334. g_free(ms->dumpdtb);
  335. ms->dumpdtb = g_strdup(value);
  336. }
  337. static void machine_get_phandle_start(Object *obj, Visitor *v,
  338. const char *name, void *opaque,
  339. Error **errp)
  340. {
  341. MachineState *ms = MACHINE(obj);
  342. int64_t value = ms->phandle_start;
  343. visit_type_int(v, name, &value, errp);
  344. }
  345. static void machine_set_phandle_start(Object *obj, Visitor *v,
  346. const char *name, void *opaque,
  347. Error **errp)
  348. {
  349. MachineState *ms = MACHINE(obj);
  350. int64_t value;
  351. if (!visit_type_int(v, name, &value, errp)) {
  352. return;
  353. }
  354. ms->phandle_start = value;
  355. }
  356. static char *machine_get_dt_compatible(Object *obj, Error **errp)
  357. {
  358. MachineState *ms = MACHINE(obj);
  359. return g_strdup(ms->dt_compatible);
  360. }
  361. static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
  362. {
  363. MachineState *ms = MACHINE(obj);
  364. g_free(ms->dt_compatible);
  365. ms->dt_compatible = g_strdup(value);
  366. }
  367. static bool machine_get_dump_guest_core(Object *obj, Error **errp)
  368. {
  369. MachineState *ms = MACHINE(obj);
  370. return ms->dump_guest_core;
  371. }
  372. static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
  373. {
  374. MachineState *ms = MACHINE(obj);
  375. if (!value && QEMU_MADV_DONTDUMP == QEMU_MADV_INVALID) {
  376. error_setg(errp, "Dumping guest memory cannot be disabled on this host");
  377. return;
  378. }
  379. ms->dump_guest_core = value;
  380. }
  381. static bool machine_get_mem_merge(Object *obj, Error **errp)
  382. {
  383. MachineState *ms = MACHINE(obj);
  384. return ms->mem_merge;
  385. }
  386. static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
  387. {
  388. MachineState *ms = MACHINE(obj);
  389. if (value && QEMU_MADV_MERGEABLE == QEMU_MADV_INVALID) {
  390. error_setg(errp, "Memory merging is not supported on this host");
  391. return;
  392. }
  393. ms->mem_merge = value;
  394. }
  395. #ifdef CONFIG_POSIX
  396. static bool machine_get_aux_ram_share(Object *obj, Error **errp)
  397. {
  398. MachineState *ms = MACHINE(obj);
  399. return ms->aux_ram_share;
  400. }
  401. static void machine_set_aux_ram_share(Object *obj, bool value, Error **errp)
  402. {
  403. MachineState *ms = MACHINE(obj);
  404. ms->aux_ram_share = value;
  405. }
  406. #endif
  407. static bool machine_get_usb(Object *obj, Error **errp)
  408. {
  409. MachineState *ms = MACHINE(obj);
  410. return ms->usb;
  411. }
  412. static void machine_set_usb(Object *obj, bool value, Error **errp)
  413. {
  414. MachineState *ms = MACHINE(obj);
  415. ms->usb = value;
  416. ms->usb_disabled = !value;
  417. }
  418. static bool machine_get_graphics(Object *obj, Error **errp)
  419. {
  420. MachineState *ms = MACHINE(obj);
  421. return ms->enable_graphics;
  422. }
  423. static void machine_set_graphics(Object *obj, bool value, Error **errp)
  424. {
  425. MachineState *ms = MACHINE(obj);
  426. ms->enable_graphics = value;
  427. }
  428. static char *machine_get_firmware(Object *obj, Error **errp)
  429. {
  430. MachineState *ms = MACHINE(obj);
  431. return g_strdup(ms->firmware);
  432. }
  433. static void machine_set_firmware(Object *obj, const char *value, Error **errp)
  434. {
  435. MachineState *ms = MACHINE(obj);
  436. g_free(ms->firmware);
  437. ms->firmware = g_strdup(value);
  438. }
  439. static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
  440. {
  441. MachineState *ms = MACHINE(obj);
  442. ms->suppress_vmdesc = value;
  443. }
  444. static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
  445. {
  446. MachineState *ms = MACHINE(obj);
  447. return ms->suppress_vmdesc;
  448. }
  449. static char *machine_get_memory_encryption(Object *obj, Error **errp)
  450. {
  451. MachineState *ms = MACHINE(obj);
  452. if (ms->cgs) {
  453. return g_strdup(object_get_canonical_path_component(OBJECT(ms->cgs)));
  454. }
  455. return NULL;
  456. }
  457. static void machine_set_memory_encryption(Object *obj, const char *value,
  458. Error **errp)
  459. {
  460. Object *cgs =
  461. object_resolve_path_component(object_get_objects_root(), value);
  462. if (!cgs) {
  463. error_setg(errp, "No such memory encryption object '%s'", value);
  464. return;
  465. }
  466. object_property_set_link(obj, "confidential-guest-support", cgs, errp);
  467. }
  468. static void machine_check_confidential_guest_support(const Object *obj,
  469. const char *name,
  470. Object *new_target,
  471. Error **errp)
  472. {
  473. /*
  474. * So far the only constraint is that the target has the
  475. * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked
  476. * by the QOM core
  477. */
  478. }
  479. static bool machine_get_nvdimm(Object *obj, Error **errp)
  480. {
  481. MachineState *ms = MACHINE(obj);
  482. return ms->nvdimms_state->is_enabled;
  483. }
  484. static void machine_set_nvdimm(Object *obj, bool value, Error **errp)
  485. {
  486. MachineState *ms = MACHINE(obj);
  487. ms->nvdimms_state->is_enabled = value;
  488. }
  489. static bool machine_get_hmat(Object *obj, Error **errp)
  490. {
  491. MachineState *ms = MACHINE(obj);
  492. return ms->numa_state->hmat_enabled;
  493. }
  494. static void machine_set_hmat(Object *obj, bool value, Error **errp)
  495. {
  496. MachineState *ms = MACHINE(obj);
  497. ms->numa_state->hmat_enabled = value;
  498. }
  499. static void machine_get_mem(Object *obj, Visitor *v, const char *name,
  500. void *opaque, Error **errp)
  501. {
  502. MachineState *ms = MACHINE(obj);
  503. MemorySizeConfiguration mem = {
  504. .has_size = true,
  505. .size = ms->ram_size,
  506. .has_max_size = !!ms->ram_slots,
  507. .max_size = ms->maxram_size,
  508. .has_slots = !!ms->ram_slots,
  509. .slots = ms->ram_slots,
  510. };
  511. MemorySizeConfiguration *p_mem = &mem;
  512. visit_type_MemorySizeConfiguration(v, name, &p_mem, &error_abort);
  513. }
  514. static void machine_set_mem(Object *obj, Visitor *v, const char *name,
  515. void *opaque, Error **errp)
  516. {
  517. ERRP_GUARD();
  518. MachineState *ms = MACHINE(obj);
  519. MachineClass *mc = MACHINE_GET_CLASS(obj);
  520. MemorySizeConfiguration *mem;
  521. if (!visit_type_MemorySizeConfiguration(v, name, &mem, errp)) {
  522. return;
  523. }
  524. if (!mem->has_size) {
  525. mem->has_size = true;
  526. mem->size = mc->default_ram_size;
  527. }
  528. mem->size = QEMU_ALIGN_UP(mem->size, 8192);
  529. if (mc->fixup_ram_size) {
  530. mem->size = mc->fixup_ram_size(mem->size);
  531. }
  532. if ((ram_addr_t)mem->size != mem->size) {
  533. error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
  534. (unsigned long long)mem->size,
  535. (unsigned long long)RAM_ADDR_MAX);
  536. goto out_free;
  537. }
  538. if (mem->has_max_size) {
  539. if ((ram_addr_t)mem->max_size != mem->max_size) {
  540. error_setg(errp, "ram size %llu exceeds permitted maximum %llu",
  541. (unsigned long long)mem->max_size,
  542. (unsigned long long)RAM_ADDR_MAX);
  543. goto out_free;
  544. }
  545. if (mem->max_size < mem->size) {
  546. error_setg(errp, "invalid value of maxmem: "
  547. "maximum memory size (0x%" PRIx64 ") must be at least "
  548. "the initial memory size (0x%" PRIx64 ")",
  549. mem->max_size, mem->size);
  550. goto out_free;
  551. }
  552. if (mem->has_slots && mem->slots && mem->max_size == mem->size) {
  553. error_setg(errp, "invalid value of maxmem: "
  554. "memory slots were specified but maximum memory size "
  555. "(0x%" PRIx64 ") is equal to the initial memory size "
  556. "(0x%" PRIx64 ")", mem->max_size, mem->size);
  557. goto out_free;
  558. }
  559. ms->maxram_size = mem->max_size;
  560. } else {
  561. if (mem->has_slots) {
  562. error_setg(errp, "slots specified but no max-size");
  563. goto out_free;
  564. }
  565. ms->maxram_size = mem->size;
  566. }
  567. ms->ram_size = mem->size;
  568. ms->ram_slots = mem->has_slots ? mem->slots : 0;
  569. out_free:
  570. qapi_free_MemorySizeConfiguration(mem);
  571. }
  572. static char *machine_get_nvdimm_persistence(Object *obj, Error **errp)
  573. {
  574. MachineState *ms = MACHINE(obj);
  575. return g_strdup(ms->nvdimms_state->persistence_string);
  576. }
  577. static void machine_set_nvdimm_persistence(Object *obj, const char *value,
  578. Error **errp)
  579. {
  580. MachineState *ms = MACHINE(obj);
  581. NVDIMMState *nvdimms_state = ms->nvdimms_state;
  582. if (strcmp(value, "cpu") == 0) {
  583. nvdimms_state->persistence = 3;
  584. } else if (strcmp(value, "mem-ctrl") == 0) {
  585. nvdimms_state->persistence = 2;
  586. } else {
  587. error_setg(errp, "-machine nvdimm-persistence=%s: unsupported option",
  588. value);
  589. return;
  590. }
  591. g_free(nvdimms_state->persistence_string);
  592. nvdimms_state->persistence_string = g_strdup(value);
  593. }
  594. void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
  595. {
  596. QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type));
  597. }
  598. bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev)
  599. {
  600. Object *obj = OBJECT(dev);
  601. if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) {
  602. return false;
  603. }
  604. return device_type_is_dynamic_sysbus(mc, object_get_typename(obj));
  605. }
  606. bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type)
  607. {
  608. bool allowed = false;
  609. strList *wl;
  610. ObjectClass *klass = object_class_by_name(type);
  611. for (wl = mc->allowed_dynamic_sysbus_devices;
  612. !allowed && wl;
  613. wl = wl->next) {
  614. allowed |= !!object_class_dynamic_cast(klass, wl->value);
  615. }
  616. return allowed;
  617. }
  618. static char *machine_get_audiodev(Object *obj, Error **errp)
  619. {
  620. MachineState *ms = MACHINE(obj);
  621. return g_strdup(ms->audiodev);
  622. }
  623. static void machine_set_audiodev(Object *obj, const char *value,
  624. Error **errp)
  625. {
  626. MachineState *ms = MACHINE(obj);
  627. if (!audio_state_by_name(value, errp)) {
  628. return;
  629. }
  630. g_free(ms->audiodev);
  631. ms->audiodev = g_strdup(value);
  632. }
  633. HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
  634. {
  635. int i;
  636. HotpluggableCPUList *head = NULL;
  637. MachineClass *mc = MACHINE_GET_CLASS(machine);
  638. /* force board to initialize possible_cpus if it hasn't been done yet */
  639. mc->possible_cpu_arch_ids(machine);
  640. for (i = 0; i < machine->possible_cpus->len; i++) {
  641. CPUState *cpu;
  642. HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
  643. cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
  644. cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
  645. cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
  646. sizeof(*cpu_item->props));
  647. cpu = machine->possible_cpus->cpus[i].cpu;
  648. if (cpu) {
  649. cpu_item->qom_path = object_get_canonical_path(OBJECT(cpu));
  650. }
  651. QAPI_LIST_PREPEND(head, cpu_item);
  652. }
  653. return head;
  654. }
  655. /**
  656. * machine_set_cpu_numa_node:
  657. * @machine: machine object to modify
  658. * @props: specifies which cpu objects to assign to
  659. * numa node specified by @props.node_id
  660. * @errp: if an error occurs, a pointer to an area to store the error
  661. *
  662. * Associate NUMA node specified by @props.node_id with cpu slots that
  663. * match socket/core/thread-ids specified by @props. It's recommended to use
  664. * query-hotpluggable-cpus.props values to specify affected cpu slots,
  665. * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
  666. *
  667. * However for CLI convenience it's possible to pass in subset of properties,
  668. * which would affect all cpu slots that match it.
  669. * Ex for pc machine:
  670. * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
  671. * -numa cpu,node-id=0,socket_id=0 \
  672. * -numa cpu,node-id=1,socket_id=1
  673. * will assign all child cores of socket 0 to node 0 and
  674. * of socket 1 to node 1.
  675. *
  676. * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
  677. * return error.
  678. * Empty subset is disallowed and function will return with error in this case.
  679. */
  680. void machine_set_cpu_numa_node(MachineState *machine,
  681. const CpuInstanceProperties *props, Error **errp)
  682. {
  683. MachineClass *mc = MACHINE_GET_CLASS(machine);
  684. NodeInfo *numa_info = machine->numa_state->nodes;
  685. bool match = false;
  686. int i;
  687. if (!mc->possible_cpu_arch_ids) {
  688. error_setg(errp, "mapping of CPUs to NUMA node is not supported");
  689. return;
  690. }
  691. /* disabling node mapping is not supported, forbid it */
  692. assert(props->has_node_id);
  693. /* force board to initialize possible_cpus if it hasn't been done yet */
  694. mc->possible_cpu_arch_ids(machine);
  695. for (i = 0; i < machine->possible_cpus->len; i++) {
  696. CPUArchId *slot = &machine->possible_cpus->cpus[i];
  697. /* reject unsupported by board properties */
  698. if (props->has_thread_id && !slot->props.has_thread_id) {
  699. error_setg(errp, "thread-id is not supported");
  700. return;
  701. }
  702. if (props->has_core_id && !slot->props.has_core_id) {
  703. error_setg(errp, "core-id is not supported");
  704. return;
  705. }
  706. if (props->has_module_id && !slot->props.has_module_id) {
  707. error_setg(errp, "module-id is not supported");
  708. return;
  709. }
  710. if (props->has_cluster_id && !slot->props.has_cluster_id) {
  711. error_setg(errp, "cluster-id is not supported");
  712. return;
  713. }
  714. if (props->has_socket_id && !slot->props.has_socket_id) {
  715. error_setg(errp, "socket-id is not supported");
  716. return;
  717. }
  718. if (props->has_die_id && !slot->props.has_die_id) {
  719. error_setg(errp, "die-id is not supported");
  720. return;
  721. }
  722. /* skip slots with explicit mismatch */
  723. if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
  724. continue;
  725. }
  726. if (props->has_core_id && props->core_id != slot->props.core_id) {
  727. continue;
  728. }
  729. if (props->has_module_id &&
  730. props->module_id != slot->props.module_id) {
  731. continue;
  732. }
  733. if (props->has_cluster_id &&
  734. props->cluster_id != slot->props.cluster_id) {
  735. continue;
  736. }
  737. if (props->has_die_id && props->die_id != slot->props.die_id) {
  738. continue;
  739. }
  740. if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
  741. continue;
  742. }
  743. /* reject assignment if slot is already assigned, for compatibility
  744. * of legacy cpu_index mapping with SPAPR core based mapping do not
  745. * error out if cpu thread and matched core have the same node-id */
  746. if (slot->props.has_node_id &&
  747. slot->props.node_id != props->node_id) {
  748. error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
  749. slot->props.node_id);
  750. return;
  751. }
  752. /* assign slot to node as it's matched '-numa cpu' key */
  753. match = true;
  754. slot->props.node_id = props->node_id;
  755. slot->props.has_node_id = props->has_node_id;
  756. if (machine->numa_state->hmat_enabled) {
  757. if ((numa_info[props->node_id].initiator < MAX_NODES) &&
  758. (props->node_id != numa_info[props->node_id].initiator)) {
  759. error_setg(errp, "The initiator of CPU NUMA node %" PRId64
  760. " should be itself (got %" PRIu16 ")",
  761. props->node_id, numa_info[props->node_id].initiator);
  762. return;
  763. }
  764. numa_info[props->node_id].has_cpu = true;
  765. numa_info[props->node_id].initiator = props->node_id;
  766. }
  767. }
  768. if (!match) {
  769. error_setg(errp, "no match found");
  770. }
  771. }
  772. static void machine_get_smp(Object *obj, Visitor *v, const char *name,
  773. void *opaque, Error **errp)
  774. {
  775. MachineState *ms = MACHINE(obj);
  776. SMPConfiguration *config = &(SMPConfiguration){
  777. .has_cpus = true, .cpus = ms->smp.cpus,
  778. .has_drawers = true, .drawers = ms->smp.drawers,
  779. .has_books = true, .books = ms->smp.books,
  780. .has_sockets = true, .sockets = ms->smp.sockets,
  781. .has_dies = true, .dies = ms->smp.dies,
  782. .has_clusters = true, .clusters = ms->smp.clusters,
  783. .has_modules = true, .modules = ms->smp.modules,
  784. .has_cores = true, .cores = ms->smp.cores,
  785. .has_threads = true, .threads = ms->smp.threads,
  786. .has_maxcpus = true, .maxcpus = ms->smp.max_cpus,
  787. };
  788. if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) {
  789. return;
  790. }
  791. }
  792. static void machine_set_smp(Object *obj, Visitor *v, const char *name,
  793. void *opaque, Error **errp)
  794. {
  795. MachineState *ms = MACHINE(obj);
  796. g_autoptr(SMPConfiguration) config = NULL;
  797. if (!visit_type_SMPConfiguration(v, name, &config, errp)) {
  798. return;
  799. }
  800. machine_parse_smp_config(ms, config, errp);
  801. }
  802. static void machine_get_smp_cache(Object *obj, Visitor *v, const char *name,
  803. void *opaque, Error **errp)
  804. {
  805. MachineState *ms = MACHINE(obj);
  806. SmpCache *cache = &ms->smp_cache;
  807. SmpCachePropertiesList *head = NULL;
  808. SmpCachePropertiesList **tail = &head;
  809. for (int i = 0; i < CACHE_LEVEL_AND_TYPE__MAX; i++) {
  810. SmpCacheProperties *node = g_new(SmpCacheProperties, 1);
  811. node->cache = cache->props[i].cache;
  812. node->topology = cache->props[i].topology;
  813. QAPI_LIST_APPEND(tail, node);
  814. }
  815. visit_type_SmpCachePropertiesList(v, name, &head, errp);
  816. qapi_free_SmpCachePropertiesList(head);
  817. }
  818. static void machine_set_smp_cache(Object *obj, Visitor *v, const char *name,
  819. void *opaque, Error **errp)
  820. {
  821. MachineState *ms = MACHINE(obj);
  822. SmpCachePropertiesList *caches;
  823. if (!visit_type_SmpCachePropertiesList(v, name, &caches, errp)) {
  824. return;
  825. }
  826. machine_parse_smp_cache(ms, caches, errp);
  827. qapi_free_SmpCachePropertiesList(caches);
  828. }
  829. static void machine_get_boot(Object *obj, Visitor *v, const char *name,
  830. void *opaque, Error **errp)
  831. {
  832. MachineState *ms = MACHINE(obj);
  833. BootConfiguration *config = &ms->boot_config;
  834. visit_type_BootConfiguration(v, name, &config, &error_abort);
  835. }
  836. static void machine_free_boot_config(MachineState *ms)
  837. {
  838. g_free(ms->boot_config.order);
  839. g_free(ms->boot_config.once);
  840. g_free(ms->boot_config.splash);
  841. }
  842. static void machine_copy_boot_config(MachineState *ms, BootConfiguration *config)
  843. {
  844. MachineClass *machine_class = MACHINE_GET_CLASS(ms);
  845. machine_free_boot_config(ms);
  846. ms->boot_config = *config;
  847. if (!config->order) {
  848. ms->boot_config.order = g_strdup(machine_class->default_boot_order);
  849. }
  850. }
  851. static void machine_set_boot(Object *obj, Visitor *v, const char *name,
  852. void *opaque, Error **errp)
  853. {
  854. ERRP_GUARD();
  855. MachineState *ms = MACHINE(obj);
  856. BootConfiguration *config = NULL;
  857. if (!visit_type_BootConfiguration(v, name, &config, errp)) {
  858. return;
  859. }
  860. if (config->order) {
  861. validate_bootdevices(config->order, errp);
  862. if (*errp) {
  863. goto out_free;
  864. }
  865. }
  866. if (config->once) {
  867. validate_bootdevices(config->once, errp);
  868. if (*errp) {
  869. goto out_free;
  870. }
  871. }
  872. machine_copy_boot_config(ms, config);
  873. /* Strings live in ms->boot_config. */
  874. free(config);
  875. return;
  876. out_free:
  877. qapi_free_BootConfiguration(config);
  878. }
  879. void machine_add_audiodev_property(MachineClass *mc)
  880. {
  881. ObjectClass *oc = OBJECT_CLASS(mc);
  882. object_class_property_add_str(oc, "audiodev",
  883. machine_get_audiodev,
  884. machine_set_audiodev);
  885. object_class_property_set_description(oc, "audiodev",
  886. "Audiodev to use for default machine devices");
  887. }
  888. static bool create_default_memdev(MachineState *ms, const char *path,
  889. Error **errp)
  890. {
  891. Object *obj;
  892. MachineClass *mc = MACHINE_GET_CLASS(ms);
  893. bool r = false;
  894. obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM);
  895. if (path) {
  896. if (!object_property_set_str(obj, "mem-path", path, errp)) {
  897. goto out;
  898. }
  899. }
  900. if (!object_property_set_int(obj, "size", ms->ram_size, errp)) {
  901. goto out;
  902. }
  903. object_property_add_child(object_get_objects_root(), mc->default_ram_id,
  904. obj);
  905. /* Ensure backend's memory region name is equal to mc->default_ram_id */
  906. if (!object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id",
  907. false, errp)) {
  908. goto out;
  909. }
  910. if (!user_creatable_complete(USER_CREATABLE(obj), errp)) {
  911. goto out;
  912. }
  913. r = object_property_set_link(OBJECT(ms), "memory-backend", obj, errp);
  914. out:
  915. object_unref(obj);
  916. return r;
  917. }
  918. static void machine_class_init(ObjectClass *oc, void *data)
  919. {
  920. MachineClass *mc = MACHINE_CLASS(oc);
  921. /* Default 128 MB as guest ram size */
  922. mc->default_ram_size = 128 * MiB;
  923. mc->rom_file_has_mr = true;
  924. /*
  925. * SMBIOS 3.1.0 7.18.5 Memory Device — Extended Size
  926. * use max possible value that could be encoded into
  927. * 'Extended Size' field (2047Tb).
  928. */
  929. mc->smbios_memory_device_size = 2047 * TiB;
  930. /* numa node memory size aligned on 8MB by default.
  931. * On Linux, each node's border has to be 8MB aligned
  932. */
  933. mc->numa_mem_align_shift = 23;
  934. mc->create_default_memdev = create_default_memdev;
  935. object_class_property_add_str(oc, "kernel",
  936. machine_get_kernel, machine_set_kernel);
  937. object_class_property_set_description(oc, "kernel",
  938. "Linux kernel image file");
  939. object_class_property_add_str(oc, "shim",
  940. machine_get_shim, machine_set_shim);
  941. object_class_property_set_description(oc, "shim",
  942. "shim.efi file");
  943. object_class_property_add_str(oc, "initrd",
  944. machine_get_initrd, machine_set_initrd);
  945. object_class_property_set_description(oc, "initrd",
  946. "Linux initial ramdisk file");
  947. object_class_property_add_str(oc, "append",
  948. machine_get_append, machine_set_append);
  949. object_class_property_set_description(oc, "append",
  950. "Linux kernel command line");
  951. object_class_property_add_str(oc, "dtb",
  952. machine_get_dtb, machine_set_dtb);
  953. object_class_property_set_description(oc, "dtb",
  954. "Linux kernel device tree file");
  955. object_class_property_add_str(oc, "dumpdtb",
  956. machine_get_dumpdtb, machine_set_dumpdtb);
  957. object_class_property_set_description(oc, "dumpdtb",
  958. "Dump current dtb to a file and quit");
  959. object_class_property_add(oc, "boot", "BootConfiguration",
  960. machine_get_boot, machine_set_boot,
  961. NULL, NULL);
  962. object_class_property_set_description(oc, "boot",
  963. "Boot configuration");
  964. object_class_property_add(oc, "smp", "SMPConfiguration",
  965. machine_get_smp, machine_set_smp,
  966. NULL, NULL);
  967. object_class_property_set_description(oc, "smp",
  968. "CPU topology");
  969. object_class_property_add(oc, "smp-cache", "SmpCachePropertiesWrapper",
  970. machine_get_smp_cache, machine_set_smp_cache, NULL, NULL);
  971. object_class_property_set_description(oc, "smp-cache",
  972. "Cache properties list for SMP machine");
  973. object_class_property_add(oc, "phandle-start", "int",
  974. machine_get_phandle_start, machine_set_phandle_start,
  975. NULL, NULL);
  976. object_class_property_set_description(oc, "phandle-start",
  977. "The first phandle ID we may generate dynamically");
  978. object_class_property_add_str(oc, "dt-compatible",
  979. machine_get_dt_compatible, machine_set_dt_compatible);
  980. object_class_property_set_description(oc, "dt-compatible",
  981. "Overrides the \"compatible\" property of the dt root node");
  982. object_class_property_add_bool(oc, "dump-guest-core",
  983. machine_get_dump_guest_core, machine_set_dump_guest_core);
  984. object_class_property_set_description(oc, "dump-guest-core",
  985. "Include guest memory in a core dump");
  986. object_class_property_add_bool(oc, "mem-merge",
  987. machine_get_mem_merge, machine_set_mem_merge);
  988. object_class_property_set_description(oc, "mem-merge",
  989. "Enable/disable memory merge support");
  990. #ifdef CONFIG_POSIX
  991. object_class_property_add_bool(oc, "aux-ram-share",
  992. machine_get_aux_ram_share,
  993. machine_set_aux_ram_share);
  994. #endif
  995. object_class_property_add_bool(oc, "usb",
  996. machine_get_usb, machine_set_usb);
  997. object_class_property_set_description(oc, "usb",
  998. "Set on/off to enable/disable usb");
  999. object_class_property_add_bool(oc, "graphics",
  1000. machine_get_graphics, machine_set_graphics);
  1001. object_class_property_set_description(oc, "graphics",
  1002. "Set on/off to enable/disable graphics emulation");
  1003. object_class_property_add_str(oc, "firmware",
  1004. machine_get_firmware, machine_set_firmware);
  1005. object_class_property_set_description(oc, "firmware",
  1006. "Firmware image");
  1007. object_class_property_add_bool(oc, "suppress-vmdesc",
  1008. machine_get_suppress_vmdesc, machine_set_suppress_vmdesc);
  1009. object_class_property_set_description(oc, "suppress-vmdesc",
  1010. "Set on to disable self-describing migration");
  1011. object_class_property_add_link(oc, "confidential-guest-support",
  1012. TYPE_CONFIDENTIAL_GUEST_SUPPORT,
  1013. offsetof(MachineState, cgs),
  1014. machine_check_confidential_guest_support,
  1015. OBJ_PROP_LINK_STRONG);
  1016. object_class_property_set_description(oc, "confidential-guest-support",
  1017. "Set confidential guest scheme to support");
  1018. /* For compatibility */
  1019. object_class_property_add_str(oc, "memory-encryption",
  1020. machine_get_memory_encryption, machine_set_memory_encryption);
  1021. object_class_property_set_description(oc, "memory-encryption",
  1022. "Set memory encryption object to use");
  1023. object_class_property_add_link(oc, "memory-backend", TYPE_MEMORY_BACKEND,
  1024. offsetof(MachineState, memdev), object_property_allow_set_link,
  1025. OBJ_PROP_LINK_STRONG);
  1026. object_class_property_set_description(oc, "memory-backend",
  1027. "Set RAM backend"
  1028. "Valid value is ID of hostmem based backend");
  1029. object_class_property_add(oc, "memory", "MemorySizeConfiguration",
  1030. machine_get_mem, machine_set_mem,
  1031. NULL, NULL);
  1032. object_class_property_set_description(oc, "memory",
  1033. "Memory size configuration");
  1034. }
  1035. static void machine_class_base_init(ObjectClass *oc, void *data)
  1036. {
  1037. MachineClass *mc = MACHINE_CLASS(oc);
  1038. mc->max_cpus = mc->max_cpus ?: 1;
  1039. mc->min_cpus = mc->min_cpus ?: 1;
  1040. mc->default_cpus = mc->default_cpus ?: 1;
  1041. if (!object_class_is_abstract(oc)) {
  1042. const char *cname = object_class_get_name(oc);
  1043. assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
  1044. mc->name = g_strndup(cname,
  1045. strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
  1046. mc->compat_props = g_ptr_array_new();
  1047. }
  1048. }
  1049. static void machine_initfn(Object *obj)
  1050. {
  1051. MachineState *ms = MACHINE(obj);
  1052. MachineClass *mc = MACHINE_GET_CLASS(obj);
  1053. ms->dump_guest_core = true;
  1054. ms->mem_merge = (QEMU_MADV_MERGEABLE != QEMU_MADV_INVALID);
  1055. ms->enable_graphics = true;
  1056. ms->kernel_cmdline = g_strdup("");
  1057. ms->ram_size = mc->default_ram_size;
  1058. ms->maxram_size = mc->default_ram_size;
  1059. if (mc->nvdimm_supported) {
  1060. ms->nvdimms_state = g_new0(NVDIMMState, 1);
  1061. object_property_add_bool(obj, "nvdimm",
  1062. machine_get_nvdimm, machine_set_nvdimm);
  1063. object_property_set_description(obj, "nvdimm",
  1064. "Set on/off to enable/disable "
  1065. "NVDIMM instantiation");
  1066. object_property_add_str(obj, "nvdimm-persistence",
  1067. machine_get_nvdimm_persistence,
  1068. machine_set_nvdimm_persistence);
  1069. object_property_set_description(obj, "nvdimm-persistence",
  1070. "Set NVDIMM persistence"
  1071. "Valid values are cpu, mem-ctrl");
  1072. }
  1073. if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) {
  1074. ms->numa_state = g_new0(NumaState, 1);
  1075. object_property_add_bool(obj, "hmat",
  1076. machine_get_hmat, machine_set_hmat);
  1077. object_property_set_description(obj, "hmat",
  1078. "Set on/off to enable/disable "
  1079. "ACPI Heterogeneous Memory Attribute "
  1080. "Table (HMAT)");
  1081. }
  1082. /* default to mc->default_cpus */
  1083. ms->smp.cpus = mc->default_cpus;
  1084. ms->smp.max_cpus = mc->default_cpus;
  1085. ms->smp.drawers = 1;
  1086. ms->smp.books = 1;
  1087. ms->smp.sockets = 1;
  1088. ms->smp.dies = 1;
  1089. ms->smp.clusters = 1;
  1090. ms->smp.modules = 1;
  1091. ms->smp.cores = 1;
  1092. ms->smp.threads = 1;
  1093. for (int i = 0; i < CACHE_LEVEL_AND_TYPE__MAX; i++) {
  1094. ms->smp_cache.props[i].cache = (CacheLevelAndType)i;
  1095. ms->smp_cache.props[i].topology = CPU_TOPOLOGY_LEVEL_DEFAULT;
  1096. }
  1097. machine_copy_boot_config(ms, &(BootConfiguration){ 0 });
  1098. }
  1099. static void machine_finalize(Object *obj)
  1100. {
  1101. MachineState *ms = MACHINE(obj);
  1102. machine_free_boot_config(ms);
  1103. g_free(ms->kernel_filename);
  1104. g_free(ms->initrd_filename);
  1105. g_free(ms->kernel_cmdline);
  1106. g_free(ms->dtb);
  1107. g_free(ms->dumpdtb);
  1108. g_free(ms->dt_compatible);
  1109. g_free(ms->firmware);
  1110. g_free(ms->device_memory);
  1111. g_free(ms->nvdimms_state);
  1112. g_free(ms->numa_state);
  1113. g_free(ms->audiodev);
  1114. }
  1115. bool machine_usb(MachineState *machine)
  1116. {
  1117. return machine->usb;
  1118. }
  1119. int machine_phandle_start(MachineState *machine)
  1120. {
  1121. return machine->phandle_start;
  1122. }
  1123. bool machine_dump_guest_core(MachineState *machine)
  1124. {
  1125. return machine->dump_guest_core;
  1126. }
  1127. bool machine_mem_merge(MachineState *machine)
  1128. {
  1129. return machine->mem_merge;
  1130. }
  1131. bool machine_require_guest_memfd(MachineState *machine)
  1132. {
  1133. return machine->cgs && machine->cgs->require_guest_memfd;
  1134. }
  1135. static char *cpu_slot_to_string(const CPUArchId *cpu)
  1136. {
  1137. GString *s = g_string_new(NULL);
  1138. if (cpu->props.has_socket_id) {
  1139. g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
  1140. }
  1141. if (cpu->props.has_die_id) {
  1142. if (s->len) {
  1143. g_string_append_printf(s, ", ");
  1144. }
  1145. g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id);
  1146. }
  1147. if (cpu->props.has_cluster_id) {
  1148. if (s->len) {
  1149. g_string_append_printf(s, ", ");
  1150. }
  1151. g_string_append_printf(s, "cluster-id: %"PRId64, cpu->props.cluster_id);
  1152. }
  1153. if (cpu->props.has_module_id) {
  1154. if (s->len) {
  1155. g_string_append_printf(s, ", ");
  1156. }
  1157. g_string_append_printf(s, "module-id: %"PRId64, cpu->props.module_id);
  1158. }
  1159. if (cpu->props.has_core_id) {
  1160. if (s->len) {
  1161. g_string_append_printf(s, ", ");
  1162. }
  1163. g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
  1164. }
  1165. if (cpu->props.has_thread_id) {
  1166. if (s->len) {
  1167. g_string_append_printf(s, ", ");
  1168. }
  1169. g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
  1170. }
  1171. return g_string_free(s, false);
  1172. }
  1173. static void numa_validate_initiator(NumaState *numa_state)
  1174. {
  1175. int i;
  1176. NodeInfo *numa_info = numa_state->nodes;
  1177. for (i = 0; i < numa_state->num_nodes; i++) {
  1178. if (numa_info[i].initiator == MAX_NODES) {
  1179. continue;
  1180. }
  1181. if (!numa_info[numa_info[i].initiator].present) {
  1182. error_report("NUMA node %" PRIu16 " is missing, use "
  1183. "'-numa node' option to declare it first",
  1184. numa_info[i].initiator);
  1185. exit(1);
  1186. }
  1187. if (!numa_info[numa_info[i].initiator].has_cpu) {
  1188. error_report("The initiator of NUMA node %d is invalid", i);
  1189. exit(1);
  1190. }
  1191. }
  1192. }
  1193. static void machine_numa_finish_cpu_init(MachineState *machine)
  1194. {
  1195. int i;
  1196. bool default_mapping;
  1197. GString *s = g_string_new(NULL);
  1198. MachineClass *mc = MACHINE_GET_CLASS(machine);
  1199. const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
  1200. assert(machine->numa_state->num_nodes);
  1201. for (i = 0; i < possible_cpus->len; i++) {
  1202. if (possible_cpus->cpus[i].props.has_node_id) {
  1203. break;
  1204. }
  1205. }
  1206. default_mapping = (i == possible_cpus->len);
  1207. for (i = 0; i < possible_cpus->len; i++) {
  1208. const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
  1209. if (!cpu_slot->props.has_node_id) {
  1210. /* fetch default mapping from board and enable it */
  1211. CpuInstanceProperties props = cpu_slot->props;
  1212. props.node_id = mc->get_default_cpu_node_id(machine, i);
  1213. if (!default_mapping) {
  1214. /* record slots with not set mapping,
  1215. * TODO: make it hard error in future */
  1216. char *cpu_str = cpu_slot_to_string(cpu_slot);
  1217. g_string_append_printf(s, "%sCPU %d [%s]",
  1218. s->len ? ", " : "", i, cpu_str);
  1219. g_free(cpu_str);
  1220. /* non mapped cpus used to fallback to node 0 */
  1221. props.node_id = 0;
  1222. }
  1223. props.has_node_id = true;
  1224. machine_set_cpu_numa_node(machine, &props, &error_fatal);
  1225. }
  1226. }
  1227. if (machine->numa_state->hmat_enabled) {
  1228. numa_validate_initiator(machine->numa_state);
  1229. }
  1230. if (s->len && !qtest_enabled()) {
  1231. warn_report("CPU(s) not present in any NUMA nodes: %s",
  1232. s->str);
  1233. warn_report("All CPU(s) up to maxcpus should be described "
  1234. "in NUMA config, ability to start up with partial NUMA "
  1235. "mappings is obsoleted and will be removed in future");
  1236. }
  1237. g_string_free(s, true);
  1238. }
  1239. static void validate_cpu_cluster_to_numa_boundary(MachineState *ms)
  1240. {
  1241. MachineClass *mc = MACHINE_GET_CLASS(ms);
  1242. NumaState *state = ms->numa_state;
  1243. const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
  1244. const CPUArchId *cpus = possible_cpus->cpus;
  1245. int i, j;
  1246. if (qtest_enabled() || state->num_nodes <= 1 || possible_cpus->len <= 1) {
  1247. return;
  1248. }
  1249. /*
  1250. * The Linux scheduling domain can't be parsed when the multiple CPUs
  1251. * in one cluster have been associated with different NUMA nodes. However,
  1252. * it's fine to associate one NUMA node with CPUs in different clusters.
  1253. */
  1254. for (i = 0; i < possible_cpus->len; i++) {
  1255. for (j = i + 1; j < possible_cpus->len; j++) {
  1256. if (cpus[i].props.has_socket_id &&
  1257. cpus[i].props.has_cluster_id &&
  1258. cpus[i].props.has_node_id &&
  1259. cpus[j].props.has_socket_id &&
  1260. cpus[j].props.has_cluster_id &&
  1261. cpus[j].props.has_node_id &&
  1262. cpus[i].props.socket_id == cpus[j].props.socket_id &&
  1263. cpus[i].props.cluster_id == cpus[j].props.cluster_id &&
  1264. cpus[i].props.node_id != cpus[j].props.node_id) {
  1265. warn_report("CPU-%d and CPU-%d in socket-%" PRId64 "-cluster-%" PRId64
  1266. " have been associated with node-%" PRId64 " and node-%" PRId64
  1267. " respectively. It can cause OSes like Linux to"
  1268. " misbehave", i, j, cpus[i].props.socket_id,
  1269. cpus[i].props.cluster_id, cpus[i].props.node_id,
  1270. cpus[j].props.node_id);
  1271. }
  1272. }
  1273. }
  1274. }
  1275. MemoryRegion *machine_consume_memdev(MachineState *machine,
  1276. HostMemoryBackend *backend)
  1277. {
  1278. MemoryRegion *ret = host_memory_backend_get_memory(backend);
  1279. if (host_memory_backend_is_mapped(backend)) {
  1280. error_report("memory backend %s can't be used multiple times.",
  1281. object_get_canonical_path_component(OBJECT(backend)));
  1282. exit(EXIT_FAILURE);
  1283. }
  1284. host_memory_backend_set_mapped(backend, true);
  1285. vmstate_register_ram_global(ret);
  1286. return ret;
  1287. }
  1288. const char *machine_class_default_cpu_type(MachineClass *mc)
  1289. {
  1290. if (mc->valid_cpu_types && !mc->valid_cpu_types[1]) {
  1291. /* Only a single CPU type allowed: use it as default. */
  1292. return mc->valid_cpu_types[0];
  1293. }
  1294. return mc->default_cpu_type;
  1295. }
  1296. static bool is_cpu_type_supported(const MachineState *machine, Error **errp)
  1297. {
  1298. MachineClass *mc = MACHINE_GET_CLASS(machine);
  1299. ObjectClass *oc = object_class_by_name(machine->cpu_type);
  1300. CPUClass *cc;
  1301. int i;
  1302. /*
  1303. * Check if the user specified CPU type is supported when the valid
  1304. * CPU types have been determined. Note that the user specified CPU
  1305. * type is provided through '-cpu' option.
  1306. */
  1307. if (mc->valid_cpu_types) {
  1308. assert(mc->valid_cpu_types[0] != NULL);
  1309. for (i = 0; mc->valid_cpu_types[i]; i++) {
  1310. if (object_class_dynamic_cast(oc, mc->valid_cpu_types[i])) {
  1311. break;
  1312. }
  1313. }
  1314. /* The user specified CPU type isn't valid */
  1315. if (!mc->valid_cpu_types[i]) {
  1316. g_autofree char *requested = cpu_model_from_type(machine->cpu_type);
  1317. error_setg(errp, "Invalid CPU model: %s", requested);
  1318. if (!mc->valid_cpu_types[1]) {
  1319. g_autofree char *model = cpu_model_from_type(
  1320. mc->valid_cpu_types[0]);
  1321. error_append_hint(errp, "The only valid type is: %s\n", model);
  1322. } else {
  1323. error_append_hint(errp, "The valid models are: ");
  1324. for (i = 0; mc->valid_cpu_types[i]; i++) {
  1325. g_autofree char *model = cpu_model_from_type(
  1326. mc->valid_cpu_types[i]);
  1327. error_append_hint(errp, "%s%s",
  1328. model,
  1329. mc->valid_cpu_types[i + 1] ? ", " : "");
  1330. }
  1331. error_append_hint(errp, "\n");
  1332. }
  1333. return false;
  1334. }
  1335. }
  1336. /* Check if CPU type is deprecated and warn if so */
  1337. cc = CPU_CLASS(oc);
  1338. assert(cc != NULL);
  1339. if (cc->deprecation_note) {
  1340. warn_report("CPU model %s is deprecated -- %s",
  1341. machine->cpu_type, cc->deprecation_note);
  1342. }
  1343. return true;
  1344. }
  1345. void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp)
  1346. {
  1347. ERRP_GUARD();
  1348. MachineClass *machine_class = MACHINE_GET_CLASS(machine);
  1349. /* This checkpoint is required by replay to separate prior clock
  1350. reading from the other reads, because timer polling functions query
  1351. clock values from the log. */
  1352. replay_checkpoint(CHECKPOINT_INIT);
  1353. if (!xen_enabled()) {
  1354. /* On 32-bit hosts, QEMU is limited by virtual address space */
  1355. if (machine->ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
  1356. error_setg(errp, "at most 2047 MB RAM can be simulated");
  1357. return;
  1358. }
  1359. }
  1360. if (machine->memdev) {
  1361. ram_addr_t backend_size = object_property_get_uint(OBJECT(machine->memdev),
  1362. "size", &error_abort);
  1363. if (backend_size != machine->ram_size) {
  1364. error_setg(errp, "Machine memory size does not match the size of the memory backend");
  1365. return;
  1366. }
  1367. } else if (machine_class->default_ram_id && machine->ram_size &&
  1368. numa_uses_legacy_mem()) {
  1369. if (object_property_find(object_get_objects_root(),
  1370. machine_class->default_ram_id)) {
  1371. error_setg(errp, "object's id '%s' is reserved for the default"
  1372. " RAM backend, it can't be used for any other purposes",
  1373. machine_class->default_ram_id);
  1374. error_append_hint(errp,
  1375. "Change the object's 'id' to something else or disable"
  1376. " automatic creation of the default RAM backend by setting"
  1377. " 'memory-backend=%s' with '-machine'.\n",
  1378. machine_class->default_ram_id);
  1379. return;
  1380. }
  1381. if (!machine_class->create_default_memdev(current_machine, mem_path,
  1382. errp)) {
  1383. return;
  1384. }
  1385. }
  1386. if (machine->numa_state) {
  1387. numa_complete_configuration(machine);
  1388. if (machine->numa_state->num_nodes) {
  1389. machine_numa_finish_cpu_init(machine);
  1390. if (machine_class->cpu_cluster_has_numa_boundary) {
  1391. validate_cpu_cluster_to_numa_boundary(machine);
  1392. }
  1393. }
  1394. }
  1395. if (!machine->ram && machine->memdev) {
  1396. machine->ram = machine_consume_memdev(machine, machine->memdev);
  1397. }
  1398. /* Check if the CPU type is supported */
  1399. if (machine->cpu_type && !is_cpu_type_supported(machine, errp)) {
  1400. return;
  1401. }
  1402. if (machine->cgs) {
  1403. /*
  1404. * With confidential guests, the host can't see the real
  1405. * contents of RAM, so there's no point in it trying to merge
  1406. * areas.
  1407. */
  1408. machine_set_mem_merge(OBJECT(machine), false, &error_abort);
  1409. /*
  1410. * Virtio devices can't count on directly accessing guest
  1411. * memory, so they need iommu_platform=on to use normal DMA
  1412. * mechanisms. That requires also disabling legacy virtio
  1413. * support for those virtio pci devices which allow it.
  1414. */
  1415. object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy",
  1416. "on", true);
  1417. object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform",
  1418. "on", false);
  1419. }
  1420. accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator));
  1421. machine_class->init(machine);
  1422. phase_advance(PHASE_MACHINE_INITIALIZED);
  1423. }
  1424. static NotifierList machine_init_done_notifiers =
  1425. NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
  1426. void qemu_add_machine_init_done_notifier(Notifier *notify)
  1427. {
  1428. notifier_list_add(&machine_init_done_notifiers, notify);
  1429. if (phase_check(PHASE_MACHINE_READY)) {
  1430. notify->notify(notify, NULL);
  1431. }
  1432. }
  1433. void qemu_remove_machine_init_done_notifier(Notifier *notify)
  1434. {
  1435. notifier_remove(notify);
  1436. }
  1437. static void handle_machine_dumpdtb(MachineState *ms)
  1438. {
  1439. if (!ms->dumpdtb) {
  1440. return;
  1441. }
  1442. #ifdef CONFIG_FDT
  1443. qmp_dumpdtb(ms->dumpdtb, &error_fatal);
  1444. exit(0);
  1445. #else
  1446. error_report("This machine doesn't have an FDT");
  1447. error_printf("(this machine type definitely doesn't use FDT, and "
  1448. "this QEMU doesn't have FDT support compiled in)\n");
  1449. exit(1);
  1450. #endif
  1451. }
  1452. void qdev_machine_creation_done(void)
  1453. {
  1454. cpu_synchronize_all_post_init();
  1455. if (current_machine->boot_config.once) {
  1456. qemu_boot_set(current_machine->boot_config.once, &error_fatal);
  1457. qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_config.order));
  1458. }
  1459. /*
  1460. * ok, initial machine setup is done, starting from now we can
  1461. * only create hotpluggable devices
  1462. */
  1463. phase_advance(PHASE_MACHINE_READY);
  1464. qdev_assert_realized_properly();
  1465. /* TODO: once all bus devices are qdevified, this should be done
  1466. * when bus is created by qdev.c */
  1467. /*
  1468. * This is where we arrange for the sysbus to be reset when the
  1469. * whole simulation is reset. In turn, resetting the sysbus will cause
  1470. * all devices hanging off it (and all their child buses, recursively)
  1471. * to be reset. Note that this will *not* reset any Device objects
  1472. * which are not attached to some part of the qbus tree!
  1473. */
  1474. qemu_register_resettable(OBJECT(sysbus_get_default()));
  1475. notifier_list_notify(&machine_init_done_notifiers, NULL);
  1476. /*
  1477. * If the user used -machine dumpdtb=file.dtb to request that we
  1478. * dump the DTB to a file, do it now, and exit.
  1479. */
  1480. handle_machine_dumpdtb(current_machine);
  1481. if (rom_check_and_register_reset() != 0) {
  1482. exit(1);
  1483. }
  1484. replay_start();
  1485. /* This checkpoint is required by replay to separate prior clock
  1486. reading from the other reads, because timer polling functions query
  1487. clock values from the log. */
  1488. replay_checkpoint(CHECKPOINT_RESET);
  1489. qemu_system_reset(SHUTDOWN_CAUSE_NONE);
  1490. register_global_state();
  1491. }
  1492. static const TypeInfo machine_info = {
  1493. .name = TYPE_MACHINE,
  1494. .parent = TYPE_OBJECT,
  1495. .abstract = true,
  1496. .class_size = sizeof(MachineClass),
  1497. .class_init = machine_class_init,
  1498. .class_base_init = machine_class_base_init,
  1499. .instance_size = sizeof(MachineState),
  1500. .instance_init = machine_initfn,
  1501. .instance_finalize = machine_finalize,
  1502. };
  1503. static void machine_register_types(void)
  1504. {
  1505. type_register_static(&machine_info);
  1506. }
  1507. type_init(machine_register_types)