machine.c 57 KB

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