machine.c 57 KB

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