... | ... | ||
---|---|---|---|
31 | hosts only because ParavirtualizedGraphics.framework is a black box | 31 | hosts only because ParavirtualizedGraphics.framework is a black box |
32 | implementing most of the logic behind the apple-gfx device.) | 32 | implementing most of the logic behind the apple-gfx device.) |
33 | * PCI devices use legacy IRQs, not MSI/MSI-X. As far as I can tell, | 33 | * PCI devices use legacy IRQs, not MSI/MSI-X. As far as I can tell, |
34 | we'd need to include the GICv3 ITS, but it's unclear to me what | 34 | we'd need to include the GICv3 ITS, but it's unclear to me what |
35 | exactly needs wiring up. | 35 | exactly needs wiring up. |
36 | * Due to lack of MSI(-X), event delivery from USB devices to the guest | 36 | * Due to a quirk (bug?) in the macOS XHCI driver when MSI-X is not |
37 | macOS isn't working correctly. My current conclusion is that the | 37 | available, correct functioning of the USB controller (and thus |
38 | OS's XHCI driver simply was never designed to work with legacy IRQs. | 38 | keyboard/tablet) requires a small workaround in the XHCI controller |
39 | The upshot is that keyboard and mouse/tablet input is very laggy. | 39 | device. This is part of another patch series: |
40 | The solution would be to implement MSI(-X) support or figure out how | 40 | https://patchew.org/QEMU/20241208191646.64857-1-phil@philjordan.eu/ |
41 | to make hcd-xhci-sysbus work with the macOS guest, if at all possible. | ||
42 | (EHCI and UHCI/OHCI controllers are not an option as the VMAPPLE | ||
43 | guest kernel does not include drivers for these.) | ||
44 | * The guest OS must first be provisioned using Virtualization.framework; | 41 | * The guest OS must first be provisioned using Virtualization.framework; |
45 | the disk images can subsequently be used in Qemu. (See docs.) | 42 | the disk images can subsequently be used in Qemu. (See docs.) |
46 | 43 | ||
47 | The apple-gfx device can be used independently from the vmapple machine | 44 | The apple-gfx device can be used independently from the vmapple machine |
48 | type, at least in the PCI variant. It mainly targets x86-64 macOS guests | 45 | type, at least in the PCI variant. It mainly targets x86-64 macOS guests |
... | ... | ||
69 | CPU-based drawing. For maximum efficiency, the Metal texture | 66 | CPU-based drawing. For maximum efficiency, the Metal texture |
70 | containing the guest framebuffer could be drawn directly to | 67 | containing the guest framebuffer could be drawn directly to |
71 | a Metal view in the host window, staying on the GPU. (Similar | 68 | a Metal view in the host window, staying on the GPU. (Similar |
72 | to the OpenGL/virgl render path on other platforms.) | 69 | to the OpenGL/virgl render path on other platforms.) |
73 | 70 | ||
74 | My part of this work has been sponsored by Sauce Labs Inc. | 71 | Some of my part of this work has been sponsored by Sauce Labs Inc. |
75 | 72 | ||
76 | --- | 73 | --- |
77 | 74 | ||
78 | v2 -> v3: | 75 | v2 -> v3: |
79 | 76 | ||
... | ... | ||
114 | with g_free. (Optional) | 111 | with g_free. (Optional) |
115 | * Various smaller changes following comments in v3 code review in | 112 | * Various smaller changes following comments in v3 code review in |
116 | apple-gfx, aes, cfg, bdif, virtio-blk-vmapple, and the vmapple | 113 | apple-gfx, aes, cfg, bdif, virtio-blk-vmapple, and the vmapple |
117 | machine type itself. See patch-specific v4 change notes for details. | 114 | machine type itself. See patch-specific v4 change notes for details. |
118 | 115 | ||
116 | v4 -> v5: | ||
117 | |||
118 | * Simplified the main thread runloop mechanism. Back to setting | ||
119 | qemu_main directly, but narrowing the scope of what it needs to do, | ||
120 | and it can now be NULL. (Meaning run the QEMU main event loop on | ||
121 | the main thread as is traditional.) | ||
122 | * hw/display/apple-gfx: Further improvements to the BH based job code bridging | ||
123 | the libdispatch & QEMU thread synchronisation impedance mismatch. | ||
124 | * hw/display/apple-gfx: Thread safety and object lifetime improvements. | ||
125 | * hw/display/apple-gfx-*: Better buffer and error handling in display mode | ||
126 | property setters and getters. | ||
127 | * hw/vmapple/aes: More consistent and safer logging/tracing | ||
128 | * hw/vmapple/cfg: Better error reporting on overlong property strings. | ||
129 | * hw/vmapple/virtio-blk: Fixed theoretically-unaligned write to config buffer. | ||
130 | * vmapple machine type: Moved ecam region into machine state, improved device | ||
131 | property setting error handling, improved ECID/UUID extraction script and | ||
132 | docs. | ||
133 | * Various smaller fixes in apple-gfx/-mmio, apple-gfx-pci, vmapple/aes, | ||
134 | vmapple/cfg, vmapple/virtio-blk, and vmapple machine type. | ||
135 | * Added SPDX license identifiers where they were missing. | ||
136 | |||
137 | v5 -> v6: | ||
138 | |||
139 | * 01/15 (main/Cocoa/runloop): Combined functions, fixed whitespace | ||
140 | * 02/15 (apple-gfx): Further refinement of PVG threading: reduced some callback | ||
141 | tasks from BHs to merely acquiring RCU read lock; replaced some libdispatch | ||
142 | tasks with BHs; last remaining synchronous BH now uses emphemeral | ||
143 | QemuSemaphore. | ||
144 | * 02/15 (apple-gfx): Readability improvements and other smaller tweaks | ||
145 | (see patch change notes for details) | ||
146 | * 04/15 (display modes): Replaced use of alloca() with NSMutableArray. | ||
147 | |||
148 | v6 -> v7: | ||
149 | |||
150 | * 02/15 (apple-gfx): Use g_ptr_array_find() helper function, coding style tweak | ||
151 | * 03/15 (apple-gfx-pci): Removed an unused function parameter | ||
152 | * 04/15 (apple-gfx display mode property): Simplified error handling in | ||
153 | property parsing. | ||
154 | * 10/15 (vmapple/aes): Coding style tweaks. | ||
155 | * 12/15 (vmapple/cfg): Changed error messages for overrun of properties with | ||
156 | fixed-length strings to be more useful to users than developers. | ||
157 | * 15/15 (vmapple machine type): Tiny error handling fix, un-inlined function | ||
158 | |||
159 | v7 -> v8: | ||
160 | |||
161 | * 02/15 (apple-gfx): Naming and type use improvements, fixes for a bug and a | ||
162 | leak. | ||
163 | * 04/15 (apple-gfx display mode property): Type use improvement | ||
164 | * 10/15 (vmapple/aes): Guest error logging tweaks. | ||
165 | * 11/15 (vmapple/bdif): Replaced uses of cpu_physical_memory_read with | ||
166 | dma_memory_read, and a g_free call with g_autofree. | ||
167 | * 12/15 (vmapple/cfg): Macro hygiene fix: consistently enclosing arguments in | ||
168 | parens. | ||
169 | * 15/15 (vmapple machine type): Use less verbose pattern for defining uuid | ||
170 | property. | ||
171 | |||
172 | v8 -> v9: | ||
173 | |||
174 | * 01/16 (ui & main loop): Set qemu_main to NULL for GTK UI as well. | ||
175 | * 02/16 (apple-gfx): Pass device pointer to graphic_console_init(), various | ||
176 | non-functional changes. | ||
177 | * 03/16 (apple-gfx-pci): Fixup of changed common call, whitespace and comment | ||
178 | formatting tweaks. | ||
179 | * 04/16 (apple-gfx display modes): Re-ordered type definitions so we can drop | ||
180 | a 'struct' keyword. | ||
181 | * 10/16 (vmapple/aes): Replaced a use of cpu_physical_memory_write with | ||
182 | dma_memory_write, minor style tweak. | ||
183 | * 11/16 (vmapple/bdif): Replaced uses of cpu_physical_memory_write with | ||
184 | dma_memory_write. | ||
185 | * 13/16 (vmapple/virtio-blk): Correctly specify class_size for | ||
186 | VMAppleVirtIOBlkClass. | ||
187 | * 15/16 (vmapple machine type): Documentation improvements, fixed variable | ||
188 | name and struct field used during pvpanic device creation. | ||
189 | * 16/16 (NEW/RFC vmapple/virtio-blk): Proposed change to replace type hierarchy | ||
190 | with a variant property. This seems cleaner and less confusing than the | ||
191 | original approach to me, but I'm not sure if it warrants creation of a new | ||
192 | QAPI enum and property type definition. | ||
193 | |||
194 | v9 -> v10: | ||
195 | |||
196 | * 01/15 (ui & main loop): Added comments to qemu_main declaration and GTK. | ||
197 | * 02/15 (apple-gfx): Reworked the way frame rendering code is threaded to use | ||
198 | BHs for sections requiring BQL. | ||
199 | * 02/15 (apple-gfx): Fixed ./configure error on non-macOS platforms. | ||
200 | * 10/15 (vmapple/aes): Code style and comment improvements. | ||
201 | * 12/15 (vmapple/cfg): Slightly tidier error reporting for overlong property | ||
202 | values. | ||
203 | * 13/15 (vmapple/virtio-blk): Folded v9 patch 16/16 into this one, changing | ||
204 | the device type design to provide a single device type with a variant | ||
205 | property instead of 2 different subtypes for aux and root volumes. | ||
206 | * 15/15 (vmapple machine type): Documentation fixup for changed virtio-blk | ||
207 | device type; small improvements to shell commands in documentation; | ||
208 | improved propagation of errors during cfg device instantiation. | ||
209 | |||
210 | v10 -> v11: | ||
211 | |||
212 | * 01/15 (ui & main loop): Simplified main.c, better comments & commit message | ||
213 | * 02/15 (apple-gfx): Give each PV display instance a unique serial number. | ||
214 | * 02 & 03/15 (apple-gfx, -pci): Formatting/style tweaks | ||
215 | * 15/15 (vmapple machine type): Improvements to shell code in docs | ||
216 | |||
217 | v11 -> v12: | ||
218 | |||
219 | * 01/15 (ui & main loop): More precise wording of code comments. | ||
220 | * 02/15 (apple-gfx): Fixed memory management regressions introduced in v10; | ||
221 | improved error handling; various more conmetic code adjustments | ||
222 | * 09/15 (GPEX): Fixed uses of deleted GPEX_NUM_IRQS constant that have been | ||
223 | added to QEMU since this patch was originally written. | ||
224 | |||
225 | v12 -> v13 | ||
226 | |||
227 | * 15/15 (vmapple machine type): Bumped the machine type version from 9.2 | ||
228 | to 10.0. | ||
229 | * All patches in the series now have been positively reviewed and received | ||
230 | corresponding reviewed-by tags. | ||
231 | |||
119 | Alexander Graf (9): | 232 | Alexander Graf (9): |
120 | hw: Add vmapple subdir | 233 | hw: Add vmapple subdir |
121 | hw/misc/pvpanic: Add MMIO interface | 234 | hw/misc/pvpanic: Add MMIO interface |
122 | hvf: arm: Ignore writes to CNTP_CTL_EL0 | 235 | hvf: arm: Ignore writes to CNTP_CTL_EL0 |
123 | gpex: Allow more than 4 legacy IRQs | 236 | gpex: Allow more than 4 legacy IRQs |
... | ... | ||
134 | hw/display/apple-gfx: Adds PCI implementation | 247 | hw/display/apple-gfx: Adds PCI implementation |
135 | hw/display/apple-gfx: Adds configurable mode list | 248 | hw/display/apple-gfx: Adds configurable mode list |
136 | MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF | 249 | MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF |
137 | hw/block/virtio-blk: Replaces request free function with g_free | 250 | hw/block/virtio-blk: Replaces request free function with g_free |
138 | 251 | ||
139 | MAINTAINERS | 15 + | 252 | MAINTAINERS | 15 + |
140 | docs/system/arm/vmapple.rst | 63 +++ | 253 | contrib/vmapple/uuid.sh | 9 + |
141 | docs/system/target-arm.rst | 1 + | 254 | docs/system/arm/vmapple.rst | 63 ++ |
142 | hw/Kconfig | 1 + | 255 | docs/system/target-arm.rst | 1 + |
143 | hw/arm/sbsa-ref.c | 2 +- | 256 | hw/Kconfig | 1 + |
144 | hw/arm/virt.c | 2 +- | 257 | hw/arm/sbsa-ref.c | 2 +- |
145 | hw/block/virtio-blk.c | 58 +-- | 258 | hw/arm/virt.c | 2 +- |
146 | hw/display/Kconfig | 13 + | 259 | hw/block/virtio-blk.c | 58 +- |
147 | hw/display/apple-gfx-mmio.m | 292 ++++++++++++ | 260 | hw/core/qdev-properties-system.c | 8 + |
148 | hw/display/apple-gfx-pci.m | 159 +++++++ | 261 | hw/display/Kconfig | 13 + |
149 | hw/display/apple-gfx.h | 70 +++ | 262 | hw/display/apple-gfx-mmio.m | 289 +++++++++ |
150 | hw/display/apple-gfx.m | 816 +++++++++++++++++++++++++++++++++ | 263 | hw/display/apple-gfx-pci.m | 157 +++++ |
151 | hw/display/meson.build | 5 + | 264 | hw/display/apple-gfx.h | 77 +++ |
152 | hw/display/trace-events | 28 ++ | 265 | hw/display/apple-gfx.m | 880 ++++++++++++++++++++++++++++ |
153 | hw/i386/microvm.c | 2 +- | 266 | hw/display/meson.build | 7 + |
154 | hw/loongarch/virt.c | 2 +- | 267 | hw/display/trace-events | 30 + |
155 | hw/meson.build | 1 + | 268 | hw/i386/microvm.c | 2 +- |
156 | hw/mips/loongson3_virt.c | 2 +- | 269 | hw/loongarch/virt.c | 12 +- |
157 | hw/misc/Kconfig | 4 + | 270 | hw/meson.build | 1 + |
158 | hw/misc/meson.build | 1 + | 271 | hw/mips/loongson3_virt.c | 2 +- |
159 | hw/misc/pvpanic-mmio.c | 61 +++ | 272 | hw/misc/Kconfig | 4 + |
160 | hw/openrisc/virt.c | 12 +- | 273 | hw/misc/meson.build | 1 + |
161 | hw/pci-host/gpex.c | 43 +- | 274 | hw/misc/pvpanic-mmio.c | 61 ++ |
162 | hw/riscv/virt.c | 12 +- | 275 | hw/openrisc/virt.c | 12 +- |
163 | hw/vmapple/Kconfig | 32 ++ | 276 | hw/pci-host/gpex.c | 43 +- |
164 | hw/vmapple/aes.c | 572 +++++++++++++++++++++++ | 277 | hw/riscv/virt.c | 12 +- |
165 | hw/vmapple/bdif.c | 259 +++++++++++ | 278 | hw/vmapple/Kconfig | 32 + |
166 | hw/vmapple/cfg.c | 197 ++++++++ | 279 | hw/vmapple/aes.c | 581 ++++++++++++++++++ |
167 | hw/vmapple/meson.build | 5 + | 280 | hw/vmapple/bdif.c | 275 +++++++++ |
168 | hw/vmapple/trace-events | 23 + | 281 | hw/vmapple/cfg.c | 196 +++++++ |
169 | hw/vmapple/trace.h | 1 + | 282 | hw/vmapple/meson.build | 5 + |
170 | hw/vmapple/virtio-blk.c | 233 ++++++++++ | 283 | hw/vmapple/trace-events | 21 + |
171 | hw/vmapple/vmapple.c | 652 ++++++++++++++++++++++++++ | 284 | hw/vmapple/trace.h | 1 + |
172 | hw/xtensa/virt.c | 2 +- | 285 | hw/vmapple/virtio-blk.c | 205 +++++++ |
173 | include/hw/misc/pvpanic.h | 1 + | 286 | hw/vmapple/vmapple.c | 646 ++++++++++++++++++++ |
174 | include/hw/pci-host/gpex.h | 7 +- | 287 | hw/xen/xen-pvh-common.c | 2 +- |
175 | include/hw/pci/pci_ids.h | 1 + | 288 | hw/xtensa/virt.c | 2 +- |
176 | include/hw/virtio/virtio-blk.h | 11 +- | 289 | include/hw/misc/pvpanic.h | 1 + |
177 | include/hw/vmapple/vmapple.h | 21 + | 290 | include/hw/pci-host/gpex.h | 7 +- |
178 | include/qemu-main.h | 3 +- | 291 | include/hw/pci/pci_ids.h | 1 + |
179 | include/qemu/cutils.h | 15 + | 292 | include/hw/qdev-properties-system.h | 5 + |
180 | include/qemu/typedefs.h | 1 + | 293 | include/hw/virtio/virtio-blk.h | 11 +- |
181 | include/sysemu/os-posix.h | 2 + | 294 | include/hw/vmapple/vmapple.h | 23 + |
182 | include/sysemu/os-win32.h | 2 + | 295 | include/qemu-main.h | 14 +- |
183 | include/ui/console.h | 12 + | 296 | include/qemu/cutils.h | 15 + |
184 | meson.build | 5 + | 297 | meson.build | 5 + |
185 | os-posix.c | 20 + | 298 | qapi/virtio.json | 14 + |
186 | system/main.c | 45 +- | 299 | system/main.c | 37 +- |
187 | system/vl.c | 2 + | 300 | target/arm/hvf/hvf.c | 9 + |
188 | target/arm/hvf/hvf.c | 9 + | 301 | ui/cocoa.m | 54 +- |
189 | ui/cocoa.m | 55 +-- | 302 | ui/gtk.c | 4 + |
190 | ui/console.c | 32 +- | 303 | ui/sdl2.c | 4 + |
191 | ui/sdl2.c | 2 + | 304 | util/hexdump.c | 18 + |
192 | ui/trace-events | 1 + | 305 | 53 files changed, 3840 insertions(+), 110 deletions(-) |
193 | util/hexdump.c | 14 + | 306 | create mode 100755 contrib/vmapple/uuid.sh |
194 | 55 files changed, 3790 insertions(+), 112 deletions(-) | ||
195 | create mode 100644 docs/system/arm/vmapple.rst | 307 | create mode 100644 docs/system/arm/vmapple.rst |
196 | create mode 100644 hw/display/apple-gfx-mmio.m | 308 | create mode 100644 hw/display/apple-gfx-mmio.m |
197 | create mode 100644 hw/display/apple-gfx-pci.m | 309 | create mode 100644 hw/display/apple-gfx-pci.m |
198 | create mode 100644 hw/display/apple-gfx.h | 310 | create mode 100644 hw/display/apple-gfx.h |
199 | create mode 100644 hw/display/apple-gfx.m | 311 | create mode 100644 hw/display/apple-gfx.m |
... | ... | ||
208 | create mode 100644 hw/vmapple/virtio-blk.c | 320 | create mode 100644 hw/vmapple/virtio-blk.c |
209 | create mode 100644 hw/vmapple/vmapple.c | 321 | create mode 100644 hw/vmapple/vmapple.c |
210 | create mode 100644 include/hw/vmapple/vmapple.h | 322 | create mode 100644 include/hw/vmapple/vmapple.h |
211 | 323 | ||
212 | -- | 324 | -- |
213 | 2.39.3 (Apple Git-145) | 325 | 2.39.5 (Apple Git-154) |
326 | |||
327 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
19 | using either the Cocoa or the SDL UI. However, it does not when running | 19 | using either the Cocoa or the SDL UI. However, it does not when running |
20 | headless. Moreover, any attempt to install a similar scheme to the | 20 | headless. Moreover, any attempt to install a similar scheme to the |
21 | Cocoa UI's main thread replacement fails when combined with the SDL | 21 | Cocoa UI's main thread replacement fails when combined with the SDL |
22 | UI. | 22 | UI. |
23 | 23 | ||
24 | This change formalises main thread handling. UI (Display) and OS | 24 | This change tidies up main thread management to be more flexible. |
25 | platform implementations can declare requirements or preferences: | 25 | |
26 | 26 | * The qemu_main global function pointer is a custom function for the | |
27 | * The Cocoa UI specifies that Qemu's main loop must run on a | 27 | main thread, and it may now be NULL. When it is, the main thread |
28 | background thread and provides a function to run on the main thread | 28 | runs the main Qemu loop. This represents the traditional setup. |
29 | which runs the NSApplication event handling runloop. | 29 | * When non-null, spawning the main Qemu event loop on a separate |
30 | * The SDL UI specifies that Qemu's main loop must run on the main | 30 | thread is now done centrally rather than inside the Cocoa UI code. |
31 | * For most platforms, qemu_main is indeed NULL by default, but on | ||
32 | Darwin, it defaults to a function that runs the CFRunLoop. | ||
33 | * The Cocoa UI sets qemu_main to a function which runs the | ||
34 | NSApplication event handling runloop, as is usual for a Cocoa app. | ||
35 | * The SDL UI overrides the qemu_main function to NULL, thus | ||
36 | specifying that Qemu's main loop must run on the main | ||
31 | thread. | 37 | thread. |
38 | * The GTK UI also overrides the qemu_main function to NULL. | ||
32 | * For other UIs, or in the absence of UIs, the platform's default | 39 | * For other UIs, or in the absence of UIs, the platform's default |
33 | behaviour is followed. | 40 | behaviour is followed. |
34 | * The Darwin platform provides a default function to run on the | ||
35 | main thread, which runs the main CFRunLoop. | ||
36 | * Other OSes do not provide their own default main function and thus | ||
37 | fall back to running Qemu's main loop on the main thread, as usual. | ||
38 | 41 | ||
39 | This means that on macOS, the platform's runloop events are always | 42 | This means that on macOS, the platform's runloop events are always |
40 | handled, regardless of chosen UI. The new PV graphics device will | 43 | handled, regardless of chosen UI. The new PV graphics device will |
41 | thus work in all configurations. | 44 | thus work in all configurations. There is no functional change on other |
45 | operating systems. | ||
46 | |||
47 | Implementing this via a global function pointer variable is a bit | ||
48 | ugly, but it's probably worth investigating the existing UI thread rule | ||
49 | violations in the SDL (e.g. #2537) and GTK+ back-ends. Fixing those | ||
50 | issues might precipitate requirements similar but not identical to those | ||
51 | of the Cocoa UI; hopefully we'll see some kind of pattern emerge, which | ||
52 | can then be used as a basis for an overhaul. (In fact, it may turn | ||
53 | out to be simplest to split the UI/native platform event thread from the | ||
54 | QEMU main event loop on all platforms, with any UI or even none at all.) | ||
42 | 55 | ||
43 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 56 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
57 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
58 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
44 | --- | 59 | --- |
45 | include/qemu-main.h | 3 +-- | 60 | |
46 | include/qemu/typedefs.h | 1 + | 61 | v5: |
47 | include/sysemu/os-posix.h | 2 ++ | 62 | |
48 | include/sysemu/os-win32.h | 2 ++ | 63 | * Simplified the way of setting/clearing the main loop by going back |
49 | include/ui/console.h | 12 +++++++++ | 64 | to setting qemu_main directly, but narrowing the scope of what it |
50 | os-posix.c | 20 ++++++++++++++ | 65 | needs to do, and it can now be NULL. |
51 | system/main.c | 45 +++++++++++++++++++++++++++----- | 66 | |
52 | system/vl.c | 2 ++ | 67 | v6: |
53 | ui/cocoa.m | 55 +++++++++------------------------------ | 68 | |
54 | ui/console.c | 32 +++++++++++++++++++++-- | 69 | * Folded function qemu_run_default_main_on_new_thread's code into |
55 | ui/sdl2.c | 2 ++ | 70 | main() |
56 | ui/trace-events | 1 + | 71 | * Removed whitespace changes left over on lines near code removed |
57 | 12 files changed, 123 insertions(+), 54 deletions(-) | 72 | between v4 and v5 |
73 | |||
74 | v9: | ||
75 | |||
76 | * Set qemu_main to NULL for GTK UI as well. | ||
77 | |||
78 | v10: | ||
79 | |||
80 | * Added comments clarifying the functionality and purpose of qemu_main. | ||
81 | |||
82 | v11: | ||
83 | |||
84 | * Removed the qemu_main_fn typedef again. | ||
85 | * Consolidation of main, qemu_default_main, and call_qemu_default_main | ||
86 | so that the latter has been eliminated altogether. | ||
87 | * Reinstated the #include <SDL.h> directive, added comment saying | ||
88 | why it's needed. | ||
89 | * Improved the comment on the qemu_main global variable. | ||
90 | * Expanded the commit message. | ||
91 | |||
92 | v12: | ||
93 | |||
94 | * More precise wording of code comments. | ||
95 | |||
96 | include/qemu-main.h | 14 +++++++++++- | ||
97 | system/main.c | 37 +++++++++++++++++++++++++++---- | ||
98 | ui/cocoa.m | 54 +++++++++++---------------------------------- | ||
99 | ui/gtk.c | 4 ++++ | ||
100 | ui/sdl2.c | 4 ++++ | ||
101 | 5 files changed, 67 insertions(+), 46 deletions(-) | ||
58 | 102 | ||
59 | diff --git a/include/qemu-main.h b/include/qemu-main.h | 103 | diff --git a/include/qemu-main.h b/include/qemu-main.h |
60 | index XXXXXXX..XXXXXXX 100644 | 104 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/include/qemu-main.h | 105 | --- a/include/qemu-main.h |
62 | +++ b/include/qemu-main.h | 106 | +++ b/include/qemu-main.h |
63 | @@ -XXX,XX +XXX,XX @@ | 107 | @@ -XXX,XX +XXX,XX @@ |
64 | #ifndef QEMU_MAIN_H | 108 | #ifndef QEMU_MAIN_H |
65 | #define QEMU_MAIN_H | 109 | #define QEMU_MAIN_H |
66 | 110 | ||
67 | -int qemu_default_main(void); | 111 | -int qemu_default_main(void); |
68 | -extern int (*qemu_main)(void); | 112 | +/* |
69 | +extern qemu_main_fn qemu_main; | 113 | + * The function to run on the main (initial) thread of the process. |
114 | + * NULL means QEMU's main event loop. | ||
115 | + * When non-NULL, QEMU's main event loop will run on a purposely created | ||
116 | + * thread, after which the provided function pointer will be invoked on | ||
117 | + * the initial thread. | ||
118 | + * This is useful on platforms which treat the main thread as special | ||
119 | + * (macOS/Darwin) and/or require all UI API calls to occur from the main | ||
120 | + * thread. Those platforms can initialise it to a specific function, | ||
121 | + * while UI implementations may reset it to NULL during their init if they | ||
122 | + * will handle system and UI events on the main thread via QEMU's own main | ||
123 | + * event loop. | ||
124 | + */ | ||
125 | extern int (*qemu_main)(void); | ||
70 | 126 | ||
71 | #endif /* QEMU_MAIN_H */ | 127 | #endif /* QEMU_MAIN_H */ |
72 | diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h | 128 | diff --git a/system/main.c b/system/main.c |
73 | index XXXXXXX..XXXXXXX 100644 | 129 | index XXXXXXX..XXXXXXX 100644 |
74 | --- a/include/qemu/typedefs.h | 130 | --- a/system/main.c |
75 | +++ b/include/qemu/typedefs.h | 131 | +++ b/system/main.c |
76 | @@ -XXX,XX +XXX,XX @@ typedef struct IRQState *qemu_irq; | 132 | @@ -XXX,XX +XXX,XX @@ |
77 | * Function types | 133 | |
78 | */ | 134 | #include "qemu/osdep.h" |
79 | typedef void (*qemu_irq_handler)(void *opaque, int n, int level); | 135 | #include "qemu-main.h" |
80 | +typedef int (*qemu_main_fn)(void); | 136 | +#include "qemu/main-loop.h" |
81 | 137 | #include "sysemu/sysemu.h" | |
82 | #endif /* QEMU_TYPEDEFS_H */ | 138 | |
83 | diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h | 139 | #ifdef CONFIG_SDL |
84 | index XXXXXXX..XXXXXXX 100644 | 140 | +/* |
85 | --- a/include/sysemu/os-posix.h | 141 | + * SDL insists on wrapping the main() function with its own implementation on |
86 | +++ b/include/sysemu/os-posix.h | 142 | + * some platforms; it does so via a macro that renames our main function, so |
87 | @@ -XXX,XX +XXX,XX @@ | 143 | + * <SDL.h> must be #included here even with no SDL code called from this file. |
88 | #ifndef QEMU_OS_POSIX_H | 144 | + */ |
89 | #define QEMU_OS_POSIX_H | 145 | #include <SDL.h> |
90 | 146 | #endif | |
91 | +#include "qemu/typedefs.h" | 147 | |
92 | #include <sys/mman.h> | 148 | -int qemu_default_main(void) |
93 | #include <sys/socket.h> | 149 | +#ifdef CONFIG_DARWIN |
94 | #include <netinet/in.h> | ||
95 | @@ -XXX,XX +XXX,XX @@ void os_set_chroot(const char *path); | ||
96 | void os_setup_limits(void); | ||
97 | void os_setup_post(void); | ||
98 | int os_mlock(void); | ||
99 | +qemu_main_fn os_non_loop_main_thread_fn(void); | ||
100 | |||
101 | /** | ||
102 | * qemu_alloc_stack: | ||
103 | diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/include/sysemu/os-win32.h | ||
106 | +++ b/include/sysemu/os-win32.h | ||
107 | @@ -XXX,XX +XXX,XX @@ | ||
108 | #ifndef QEMU_OS_WIN32_H | ||
109 | #define QEMU_OS_WIN32_H | ||
110 | |||
111 | +#include "qemu/typedefs.h" | ||
112 | #include <winsock2.h> | ||
113 | #include <windows.h> | ||
114 | #include <ws2tcpip.h> | ||
115 | @@ -XXX,XX +XXX,XX @@ void os_set_line_buffering(void); | ||
116 | void os_setup_early_signal_handling(void); | ||
117 | |||
118 | int getpagesize(void); | ||
119 | +static inline qemu_main_fn os_non_loop_main_thread_fn(void) { return NULL; } | ||
120 | |||
121 | #if !defined(EPROTONOSUPPORT) | ||
122 | # define EPROTONOSUPPORT EINVAL | ||
123 | diff --git a/include/ui/console.h b/include/ui/console.h | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/include/ui/console.h | ||
126 | +++ b/include/ui/console.h | ||
127 | @@ -XXX,XX +XXX,XX @@ typedef struct QemuDisplay QemuDisplay; | ||
128 | |||
129 | struct QemuDisplay { | ||
130 | DisplayType type; | ||
131 | + /* | ||
132 | + * Some UIs have special requirements, for the qemu_main event loop running | ||
133 | + * on either the process's initial (main) thread ('Off'), or on an | ||
134 | + * explicitly created background thread ('On') because of platform-specific | ||
135 | + * event handling. | ||
136 | + * The default, 'Auto', indicates the display will work with both setups. | ||
137 | + * If 'On', either a qemu_main_thread_fn must be supplied, or it must be | ||
138 | + * ensured that all applicable host OS platforms supply a default main. | ||
139 | + * (via os_non_loop_main_thread_fn()) | ||
140 | + */ | ||
141 | + OnOffAuto qemu_main_on_bg_thread; | ||
142 | + qemu_main_fn qemu_main_thread_fn; | ||
143 | void (*early_init)(DisplayOptions *opts); | ||
144 | void (*init)(DisplayState *ds, DisplayOptions *opts); | ||
145 | const char *vc; | ||
146 | diff --git a/os-posix.c b/os-posix.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/os-posix.c | ||
149 | +++ b/os-posix.c | ||
150 | @@ -XXX,XX +XXX,XX @@ | ||
151 | |||
152 | #ifdef CONFIG_LINUX | ||
153 | #include <sys/prctl.h> | ||
154 | +#elif defined(CONFIG_DARWIN) | ||
155 | +#include <CoreFoundation/CoreFoundation.h> | 150 | +#include <CoreFoundation/CoreFoundation.h> |
156 | #endif | 151 | +#endif |
157 | 152 | + | |
158 | 153 | +static void *qemu_default_main(void *opaque) | |
159 | @@ -XXX,XX +XXX,XX @@ int os_mlock(void) | 154 | { |
160 | return -ENOSYS; | 155 | int status; |
161 | #endif | 156 | |
162 | } | 157 | + bql_lock(); |
158 | status = qemu_main_loop(); | ||
159 | qemu_cleanup(status); | ||
160 | + bql_unlock(); | ||
161 | |||
162 | - return status; | ||
163 | + exit(status); | ||
164 | } | ||
165 | |||
166 | -int (*qemu_main)(void) = qemu_default_main; | ||
167 | +int (*qemu_main)(void); | ||
163 | + | 168 | + |
164 | +#ifdef CONFIG_DARWIN | 169 | +#ifdef CONFIG_DARWIN |
165 | +static int os_darwin_cfrunloop_main(void) | 170 | +static int os_darwin_cfrunloop_main(void) |
166 | +{ | 171 | +{ |
167 | + CFRunLoopRun(); | 172 | + CFRunLoopRun(); |
168 | + abort(); | 173 | + g_assert_not_reached(); |
169 | +} | 174 | +} |
175 | +int (*qemu_main)(void) = os_darwin_cfrunloop_main; | ||
170 | +#endif | 176 | +#endif |
171 | + | ||
172 | +qemu_main_fn os_non_loop_main_thread_fn(void) | ||
173 | +{ | ||
174 | +#ifdef CONFIG_DARWIN | ||
175 | + /* By default, run the OS's event runloop on the main thread. */ | ||
176 | + return os_darwin_cfrunloop_main; | ||
177 | +#else | ||
178 | + return NULL; | ||
179 | +#endif | ||
180 | +} | ||
181 | diff --git a/system/main.c b/system/main.c | ||
182 | index XXXXXXX..XXXXXXX 100644 | ||
183 | --- a/system/main.c | ||
184 | +++ b/system/main.c | ||
185 | @@ -XXX,XX +XXX,XX @@ | ||
186 | |||
187 | #include "qemu/osdep.h" | ||
188 | #include "qemu-main.h" | ||
189 | +#include "qemu/main-loop.h" | ||
190 | #include "sysemu/sysemu.h" | ||
191 | |||
192 | -#ifdef CONFIG_SDL | ||
193 | -#include <SDL.h> | ||
194 | -#endif | ||
195 | - | ||
196 | -int qemu_default_main(void) | ||
197 | +static int qemu_default_main(void) | ||
198 | { | ||
199 | int status; | ||
200 | |||
201 | @@ -XXX,XX +XXX,XX @@ int qemu_default_main(void) | ||
202 | return status; | ||
203 | } | ||
204 | |||
205 | -int (*qemu_main)(void) = qemu_default_main; | ||
206 | +/* | ||
207 | + * Various macOS system libraries, including the Cocoa UI and anything using | ||
208 | + * libdispatch, such as ParavirtualizedGraphics.framework, requires that the | ||
209 | + * main runloop, on the main (initial) thread be running or at least regularly | ||
210 | + * polled for events. A special mode is therefore supported, where the QEMU | ||
211 | + * main loop runs on a separate thread and the main thread handles the | ||
212 | + * CF/Cocoa runloop. | ||
213 | + */ | ||
214 | + | ||
215 | +static void *call_qemu_default_main(void *opaque) | ||
216 | +{ | ||
217 | + int status; | ||
218 | + | ||
219 | + bql_lock(); | ||
220 | + status = qemu_default_main(); | ||
221 | + bql_unlock(); | ||
222 | + | ||
223 | + exit(status); | ||
224 | +} | ||
225 | + | ||
226 | +static void qemu_run_default_main_on_new_thread(void) | ||
227 | +{ | ||
228 | + QemuThread thread; | ||
229 | + | ||
230 | + qemu_thread_create(&thread, "qemu_main", call_qemu_default_main, | ||
231 | + NULL, QEMU_THREAD_DETACHED); | ||
232 | +} | ||
233 | + | ||
234 | +qemu_main_fn qemu_main; | ||
235 | 177 | ||
236 | int main(int argc, char **argv) | 178 | int main(int argc, char **argv) |
237 | { | 179 | { |
238 | qemu_init(argc, argv); | 180 | qemu_init(argc, argv); |
239 | - return qemu_main(); | 181 | - return qemu_main(); |
182 | + bql_unlock(); | ||
240 | + if (qemu_main) { | 183 | + if (qemu_main) { |
241 | + qemu_run_default_main_on_new_thread(); | 184 | + QemuThread main_loop_thread; |
242 | + bql_unlock(); | 185 | + qemu_thread_create(&main_loop_thread, "qemu_main", |
186 | + qemu_default_main, NULL, QEMU_THREAD_DETACHED); | ||
243 | + return qemu_main(); | 187 | + return qemu_main(); |
244 | + } else { | 188 | + } else { |
245 | + qemu_default_main(); | 189 | + qemu_default_main(NULL); |
246 | + } | 190 | + } |
247 | } | 191 | } |
248 | diff --git a/system/vl.c b/system/vl.c | ||
249 | index XXXXXXX..XXXXXXX 100644 | ||
250 | --- a/system/vl.c | ||
251 | +++ b/system/vl.c | ||
252 | @@ -XXX,XX +XXX,XX @@ | ||
253 | #include "sysemu/iothread.h" | ||
254 | #include "qemu/guest-random.h" | ||
255 | #include "qemu/keyval.h" | ||
256 | +#include "qemu-main.h" | ||
257 | |||
258 | #define MAX_VIRTIO_CONSOLES 1 | ||
259 | |||
260 | @@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv) | ||
261 | trace_init_file(); | ||
262 | |||
263 | qemu_init_main_loop(&error_fatal); | ||
264 | + qemu_main = os_non_loop_main_thread_fn(); | ||
265 | cpu_timers_init(); | ||
266 | |||
267 | user_register_global_props(); | ||
268 | diff --git a/ui/cocoa.m b/ui/cocoa.m | 192 | diff --git a/ui/cocoa.m b/ui/cocoa.m |
269 | index XXXXXXX..XXXXXXX 100644 | 193 | index XXXXXXX..XXXXXXX 100644 |
270 | --- a/ui/cocoa.m | 194 | --- a/ui/cocoa.m |
271 | +++ b/ui/cocoa.m | 195 | +++ b/ui/cocoa.m |
272 | @@ -XXX,XX +XXX,XX @@ | 196 | @@ -XXX,XX +XXX,XX @@ |
... | ... | ||
360 | - | 284 | - |
361 | // Pull this console process up to being a fully-fledged graphical | 285 | // Pull this console process up to being a fully-fledged graphical |
362 | // app with a menubar and Dock icon | 286 | // app with a menubar and Dock icon |
363 | ProcessSerialNumber psn = { 0, kCurrentProcess }; | 287 | ProcessSerialNumber psn = { 0, kCurrentProcess }; |
364 | @@ -XXX,XX +XXX,XX @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) | 288 | @@ -XXX,XX +XXX,XX @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) |
365 | } | 289 | qemu_clipboard_peer_register(&cbpeer); |
290 | |||
291 | [pool release]; | ||
292 | + | ||
293 | + /* | ||
294 | + * The Cocoa UI will run the NSApplication runloop on the main thread | ||
295 | + * rather than the default Core Foundation one. | ||
296 | + */ | ||
297 | + qemu_main = cocoa_main; | ||
298 | } | ||
366 | 299 | ||
367 | static QemuDisplay qemu_display_cocoa = { | 300 | static QemuDisplay qemu_display_cocoa = { |
368 | - .type = DISPLAY_TYPE_COCOA, | 301 | diff --git a/ui/gtk.c b/ui/gtk.c |
369 | - .init = cocoa_display_init, | 302 | index XXXXXXX..XXXXXXX 100644 |
370 | + .type = DISPLAY_TYPE_COCOA, | 303 | --- a/ui/gtk.c |
371 | + .init = cocoa_display_init, | 304 | +++ b/ui/gtk.c |
372 | + /* The Cocoa UI will run the NSApplication runloop on the main thread.*/ | 305 | @@ -XXX,XX +XXX,XX @@ |
373 | + .qemu_main_on_bg_thread = ON_OFF_AUTO_ON, | 306 | #include "qemu/cutils.h" |
374 | + .qemu_main_thread_fn = cocoa_main, | 307 | #include "qemu/error-report.h" |
375 | }; | ||
376 | |||
377 | static void register_cocoa(void) | ||
378 | diff --git a/ui/console.c b/ui/console.c | ||
379 | index XXXXXXX..XXXXXXX 100644 | ||
380 | --- a/ui/console.c | ||
381 | +++ b/ui/console.c | ||
382 | @@ -XXX,XX +XXX,XX @@ | ||
383 | #include "qemu/main-loop.h" | 308 | #include "qemu/main-loop.h" |
384 | #include "qemu/module.h" | ||
385 | #include "qemu/option.h" | ||
386 | +#include "qemu-main.h" | 309 | +#include "qemu-main.h" |
387 | #include "chardev/char.h" | 310 | |
388 | #include "trace.h" | 311 | #include "ui/console.h" |
389 | #include "exec/memory.h" | 312 | #include "ui/gtk.h" |
390 | @@ -XXX,XX +XXX,XX @@ void qemu_display_early_init(DisplayOptions *opts) | 313 | @@ -XXX,XX +XXX,XX @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) |
391 | 314 | #ifdef CONFIG_GTK_CLIPBOARD | |
392 | void qemu_display_init(DisplayState *ds, DisplayOptions *opts) | 315 | gd_clipboard_init(s); |
393 | { | 316 | #endif /* CONFIG_GTK_CLIPBOARD */ |
394 | + QemuDisplay *display; | 317 | + |
395 | + bool bg_main_loop; | 318 | + /* GTK's event polling must happen on the main thread. */ |
396 | + | 319 | + qemu_main = NULL; |
397 | assert(opts->type < DISPLAY_TYPE__MAX); | 320 | } |
398 | if (opts->type == DISPLAY_TYPE_NONE) { | 321 | |
399 | return; | 322 | static void early_gtk_display_init(DisplayOptions *opts) |
400 | } | ||
401 | - assert(dpys[opts->type] != NULL); | ||
402 | - dpys[opts->type]->init(ds, opts); | ||
403 | + display = dpys[opts->type]; | ||
404 | + assert(display != NULL); | ||
405 | + display->init(ds, opts); | ||
406 | + | ||
407 | + switch (display->qemu_main_on_bg_thread) { | ||
408 | + case ON_OFF_AUTO_OFF: | ||
409 | + bg_main_loop = false; | ||
410 | + qemu_main = NULL; | ||
411 | + break; | ||
412 | + case ON_OFF_AUTO_ON: | ||
413 | + bg_main_loop = true; | ||
414 | + break; | ||
415 | + case ON_OFF_AUTO_AUTO: | ||
416 | + default: | ||
417 | + bg_main_loop = qemu_main; | ||
418 | + break; | ||
419 | + } | ||
420 | + | ||
421 | + trace_qemu_display_init_main_thread( | ||
422 | + DisplayType_str(display->type), display->qemu_main_thread_fn, qemu_main, | ||
423 | + OnOffAuto_lookup.array[display->qemu_main_on_bg_thread], | ||
424 | + display->qemu_main_on_bg_thread, bg_main_loop); | ||
425 | + if (bg_main_loop && display->qemu_main_thread_fn) { | ||
426 | + qemu_main = display->qemu_main_thread_fn; | ||
427 | + } | ||
428 | + assert(!bg_main_loop || qemu_main); | ||
429 | } | ||
430 | |||
431 | const char *qemu_display_get_vc(DisplayOptions *opts) | ||
432 | diff --git a/ui/sdl2.c b/ui/sdl2.c | 323 | diff --git a/ui/sdl2.c b/ui/sdl2.c |
433 | index XXXXXXX..XXXXXXX 100644 | 324 | index XXXXXXX..XXXXXXX 100644 |
434 | --- a/ui/sdl2.c | 325 | --- a/ui/sdl2.c |
435 | +++ b/ui/sdl2.c | 326 | +++ b/ui/sdl2.c |
436 | @@ -XXX,XX +XXX,XX @@ static QemuDisplay qemu_display_sdl2 = { | 327 | @@ -XXX,XX +XXX,XX @@ |
437 | .type = DISPLAY_TYPE_SDL, | 328 | #include "sysemu/sysemu.h" |
438 | .early_init = sdl2_display_early_init, | 329 | #include "ui/win32-kbd-hook.h" |
439 | .init = sdl2_display_init, | 330 | #include "qemu/log.h" |
440 | + /* SDL must poll for events (via dpy_refresh) on main thread */ | 331 | +#include "qemu-main.h" |
441 | + .qemu_main_on_bg_thread = ON_OFF_AUTO_OFF, | 332 | |
442 | }; | 333 | static int sdl2_num_outputs; |
443 | 334 | static struct sdl2_console *sdl2_console; | |
444 | static void register_sdl1(void) | 335 | @@ -XXX,XX +XXX,XX @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o) |
445 | diff --git a/ui/trace-events b/ui/trace-events | 336 | } |
446 | index XXXXXXX..XXXXXXX 100644 | 337 | |
447 | --- a/ui/trace-events | 338 | atexit(sdl_cleanup); |
448 | +++ b/ui/trace-events | 339 | + |
449 | @@ -XXX,XX +XXX,XX @@ displaysurface_free(void *display_surface) "surface=%p" | 340 | + /* SDL's event polling (in dpy_refresh) must happen on the main thread. */ |
450 | displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" | 341 | + qemu_main = NULL; |
451 | displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]" | 342 | } |
452 | ppm_save(int fd, void *image) "fd=%d image=%p" | 343 | |
453 | +qemu_display_init_main_thread(const char *display_name, bool qemu_display_sets_main_fn, bool qemu_main_is_set, const char *display_bg_main_loop_preference, int preference, bool bg_main_loop) "display '%s': sets main thread function: %d, platform provides main function: %d, display background main loop preference: %s (%d); main loop will run on background thread: %d" | 344 | static QemuDisplay qemu_display_sdl2 = { |
454 | |||
455 | # gtk-egl.c | ||
456 | # gtk-gl-area.c | ||
457 | -- | 345 | -- |
458 | 2.39.3 (Apple Git-145) | 346 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
19 | * Asynchronous rendering. | 19 | * Asynchronous rendering. |
20 | * Memory and object lifetime fixes. | 20 | * Memory and object lifetime fixes. |
21 | * Refactoring to split generic and (vmapple) MMIO variant specific | 21 | * Refactoring to split generic and (vmapple) MMIO variant specific |
22 | code. | 22 | code. |
23 | 23 | ||
24 | Implementation wise, most of the complexity lies in the differing threading | ||
25 | models of ParavirtualizedGraphics.framework, which uses libdispatch and | ||
26 | internal locks, versus QEMU, which heavily uses the BQL, especially during | ||
27 | memory-mapped device I/O. Great care has therefore been taken to prevent | ||
28 | deadlocks by never calling into PVG methods while holding the BQL, and | ||
29 | similarly never acquiring the BQL in a callback from PVG. Different strategies | ||
30 | have been used (libdispatch, blocking and non-blocking BHs, RCU, etc.) | ||
31 | depending on the specific requirements at each framework entry and exit point. | ||
32 | |||
24 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 33 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
34 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
35 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
25 | --- | 36 | --- |
26 | 37 | ||
27 | v2: | 38 | v2: |
28 | 39 | ||
29 | * Cherry-pick/rebase conflict fixes | 40 | * Cherry-pick/rebase conflict fixes |
... | ... | ||
70 | * Addressed smaller code review notes such as: function naming, object type | 81 | * Addressed smaller code review notes such as: function naming, object type |
71 | declarations, type names/declarations/casts, code formatting, #include | 82 | declarations, type names/declarations/casts, code formatting, #include |
72 | order, over-cautious ObjC retain/release, what goes in init vs realize, | 83 | order, over-cautious ObjC retain/release, what goes in init vs realize, |
73 | etc. | 84 | etc. |
74 | 85 | ||
86 | v5: | ||
87 | |||
88 | * Smaller non-functional fixes in response to review comments, such as using | ||
89 | NULL for the AIO_WAIT_WHILE context argument, type name formatting, | ||
90 | deleting leftover debug code, logging improvements, state struct field | ||
91 | order and documentation improvements, etc. | ||
92 | * Instead of a single condition variable for all synchronous BH job types, | ||
93 | there is now one for each callback block. This reduces the number | ||
94 | of threads being awoken unnecessarily to near zero. | ||
95 | * MMIO device variant: Unified the BH job for raising interrupts. | ||
96 | * Use DMA APIs for PVG framework's guest memory read requests. | ||
97 | * Thread safety improvements: ensure mutable AppleGFXState fields are not | ||
98 | accessed outside the appropriate lock. Added dedicated mutex for the task | ||
99 | list. | ||
100 | * Retain references to MemoryRegions for which there exist mappings in each | ||
101 | PGTask, and for IOSurface mappings. | ||
102 | |||
103 | v6: | ||
104 | |||
105 | * Switched PGTask_s's' mapped_regions from GPtrArray to GArray | ||
106 | * Allow DisplaySurface to manage its own vram now that texture -> vram copy | ||
107 | occurs under BQL. | ||
108 | * Memory mapping operations now use RCU_READ_LOCK_GUARD() where possible | ||
109 | instead of a heavy-weight BH job to acquire the BQL. | ||
110 | * Changed PVG cursor and mode setting callbacks to kick off BHs instead of | ||
111 | libdispatch tasks which then locked the BQL explicitly. | ||
112 | * The single remaining callback which must wait for a BH to complete now | ||
113 | creates an ephemeral QemuSemaphore to await completion. | ||
114 | * Re-removed tracking of mapped surface manager memory regions. Just look up | ||
115 | and ref/unref the memory regions in the map/unmap callbacks. | ||
116 | * Re-ordered functions in apple-gfx.m to group them by area of functionality. | ||
117 | * Improved comments and tweaked some names. | ||
118 | |||
119 | v7: | ||
120 | |||
121 | * Use g_ptr_array_find() helper function | ||
122 | * Error handling coding style tweak | ||
123 | |||
124 | v8: | ||
125 | |||
126 | * Renamed apple_gfx_host_address_for_gpa_range() to | ||
127 | apple_gfx_host_ptr_for_gpa_range(), and made it return a void* instead of | ||
128 | uintptr_t. Fixed up callers and related code. | ||
129 | * Some adjustments to types used. | ||
130 | * Variable naming tweaks for better clarity. | ||
131 | * Fixed leak in unlikely realize error case. | ||
132 | * Fixed typo in unmap call. | ||
133 | * Don't bother with dummy argument for g_ptr_array_find(), NULL works too. | ||
134 | |||
135 | v9: | ||
136 | |||
137 | * Pass device pointer to graphic_console_init(). | ||
138 | * Slightly re-ordered initialisation code. | ||
139 | * Simplified error handling during realize(). | ||
140 | * Simplified code without functional changes, adjusted code & comment | ||
141 | formatting. | ||
142 | |||
143 | v10: | ||
144 | |||
145 | * Reworked the way frame rendering code is threaded to use BHs for sections | ||
146 | requiring BQL. | ||
147 | * Fix for ./configure error on non-macOS platforms. | ||
148 | * Code formatting tweaks. | ||
149 | |||
150 | v11: | ||
151 | |||
152 | * Generate unique display serial number for each apple-gfx device instance. | ||
153 | * Dropped redundant local variable initialisation. | ||
154 | |||
155 | v12: | ||
156 | |||
157 | * Removed 2 redundant variable initialisations. | ||
158 | * Removed dedicated rendering dispatch_queue, use global queue instead. | ||
159 | * Fixed an object leak regression introduced in v10. Solved by placing | ||
160 | @autoreleasepool blocks around the relevant Objective-C code in the BH | ||
161 | functions replacing the dispatch_async tasks. (dispatch_async implicitly | ||
162 | cleaned up autoreleased objects.) | ||
163 | * Fixed missing retain/release of command buffers when handing off to a | ||
164 | non-BH thread. (Problem masked at runtime by above leak.) | ||
165 | * Better handling of render command encoding errors. | ||
166 | * Re-arranged positions of static variables in the file. | ||
75 | 167 | ||
76 | hw/display/Kconfig | 9 + | 168 | hw/display/Kconfig | 9 + |
77 | hw/display/apple-gfx-mmio.m | 284 ++++++++++++++ | 169 | hw/display/apple-gfx-mmio.m | 281 +++++++++++++ |
78 | hw/display/apple-gfx.h | 58 +++ | 170 | hw/display/apple-gfx.h | 66 +++ |
79 | hw/display/apple-gfx.m | 713 ++++++++++++++++++++++++++++++++++++ | 171 | hw/display/apple-gfx.m | 783 ++++++++++++++++++++++++++++++++++++ |
80 | hw/display/meson.build | 4 + | 172 | hw/display/meson.build | 6 + |
81 | hw/display/trace-events | 26 ++ | 173 | hw/display/trace-events | 28 ++ |
82 | meson.build | 4 + | 174 | meson.build | 4 + |
83 | 7 files changed, 1098 insertions(+) | 175 | 7 files changed, 1177 insertions(+) |
84 | create mode 100644 hw/display/apple-gfx-mmio.m | 176 | create mode 100644 hw/display/apple-gfx-mmio.m |
85 | create mode 100644 hw/display/apple-gfx.h | 177 | create mode 100644 hw/display/apple-gfx.h |
86 | create mode 100644 hw/display/apple-gfx.m | 178 | create mode 100644 hw/display/apple-gfx.m |
87 | 179 | ||
88 | diff --git a/hw/display/Kconfig b/hw/display/Kconfig | 180 | diff --git a/hw/display/Kconfig b/hw/display/Kconfig |
... | ... | ||
114 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 206 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
115 | + * | 207 | + * |
116 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 208 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
117 | + * See the COPYING file in the top-level directory. | 209 | + * See the COPYING file in the top-level directory. |
118 | + * | 210 | + * |
211 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
212 | + * | ||
119 | + * ParavirtualizedGraphics.framework is a set of libraries that macOS provides | 213 | + * ParavirtualizedGraphics.framework is a set of libraries that macOS provides |
120 | + * which implements 3d graphics passthrough to the host as well as a | 214 | + * which implements 3d graphics passthrough to the host as well as a |
121 | + * proprietary guest communication channel to drive it. This device model | 215 | + * proprietary guest communication channel to drive it. This device model |
122 | + * implements support to drive that library from within QEMU as an MMIO-based | 216 | + * implements support to drive that library from within QEMU as an MMIO-based |
123 | + * system device for macOS on arm64 VMs. | 217 | + * system device for macOS on arm64 VMs. |
... | ... | ||
128 | +#include "apple-gfx.h" | 222 | +#include "apple-gfx.h" |
129 | +#include "monitor/monitor.h" | 223 | +#include "monitor/monitor.h" |
130 | +#include "hw/sysbus.h" | 224 | +#include "hw/sysbus.h" |
131 | +#include "hw/irq.h" | 225 | +#include "hw/irq.h" |
132 | +#include "trace.h" | 226 | +#include "trace.h" |
227 | +#include "qemu/log.h" | ||
133 | + | 228 | + |
134 | +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXMMIOState, APPLE_GFX_MMIO) | 229 | +OBJECT_DECLARE_SIMPLE_TYPE(AppleGFXMMIOState, APPLE_GFX_MMIO) |
135 | + | 230 | + |
136 | +/* | 231 | +/* |
137 | + * ParavirtualizedGraphics.Framework only ships header files for the PCI | 232 | + * ParavirtualizedGraphics.Framework only ships header files for the PCI |
... | ... | ||
193 | + AppleGFXMMIOJob job = { | 288 | + AppleGFXMMIOJob job = { |
194 | + .state = opaque, | 289 | + .state = opaque, |
195 | + .offset = offset, | 290 | + .offset = offset, |
196 | + .completed = false, | 291 | + .completed = false, |
197 | + }; | 292 | + }; |
198 | + AioContext *context = qemu_get_aio_context(); | 293 | + dispatch_queue_t queue = |
199 | + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | 294 | + dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
200 | + | 295 | + |
201 | + dispatch_async_f(queue, &job, iosfc_do_read); | 296 | + dispatch_async_f(queue, &job, iosfc_do_read); |
202 | + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); | 297 | + AIO_WAIT_WHILE(NULL, !qatomic_read(&job.completed)); |
203 | + | 298 | + |
204 | + trace_apple_gfx_mmio_iosfc_read(offset, job.value); | 299 | + trace_apple_gfx_mmio_iosfc_read(offset, job.value); |
205 | + return job.value; | 300 | + return job.value; |
206 | +} | 301 | +} |
207 | + | 302 | + |
... | ... | ||
220 | + .state = opaque, | 315 | + .state = opaque, |
221 | + .offset = offset, | 316 | + .offset = offset, |
222 | + .value = val, | 317 | + .value = val, |
223 | + .completed = false, | 318 | + .completed = false, |
224 | + }; | 319 | + }; |
225 | + AioContext *context = qemu_get_aio_context(); | 320 | + dispatch_queue_t queue = |
226 | + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | 321 | + dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
227 | + | 322 | + |
228 | + dispatch_async_f(queue, &job, iosfc_do_write); | 323 | + dispatch_async_f(queue, &job, iosfc_do_write); |
229 | + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); | 324 | + AIO_WAIT_WHILE(NULL, !qatomic_read(&job.completed)); |
230 | + | 325 | + |
231 | + trace_apple_gfx_mmio_iosfc_write(offset, val); | 326 | + trace_apple_gfx_mmio_iosfc_write(offset, val); |
232 | +} | 327 | +} |
233 | + | 328 | + |
234 | +static const MemoryRegionOps apple_iosfc_ops = { | 329 | +static const MemoryRegionOps apple_iosfc_ops = { |
... | ... | ||
243 | + .min_access_size = 4, | 338 | + .min_access_size = 4, |
244 | + .max_access_size = 8, | 339 | + .max_access_size = 8, |
245 | + }, | 340 | + }, |
246 | +}; | 341 | +}; |
247 | + | 342 | + |
248 | +static void raise_iosfc_irq(void *opaque) | 343 | +static void raise_irq_bh(void *opaque) |
249 | +{ | 344 | +{ |
250 | + AppleGFXMMIOState *s = opaque; | 345 | + qemu_irq *irq = opaque; |
251 | + | 346 | + |
252 | + qemu_irq_pulse(s->irq_iosfc); | 347 | + qemu_irq_pulse(*irq); |
253 | +} | 348 | +} |
254 | + | 349 | + |
255 | +typedef struct AppleGFXMapSurfaceMemoryJob { | 350 | +static void *apple_gfx_mmio_map_surface_memory(uint64_t guest_physical_address, |
256 | + uint64_t guest_physical_address; | 351 | + uint64_t length, bool read_only) |
257 | + uint64_t guest_physical_length; | 352 | +{ |
258 | + void *result_mem; | 353 | + void *mem; |
259 | + AppleGFXMMIOState *state; | 354 | + MemoryRegion *region = NULL; |
260 | + bool read_only; | 355 | + |
261 | + bool success; | 356 | + RCU_READ_LOCK_GUARD(); |
262 | + bool done; | 357 | + mem = apple_gfx_host_ptr_for_gpa_range(guest_physical_address, |
263 | +} AppleGFXMapSurfaceMemoryJob; | 358 | + length, read_only, ®ion); |
264 | + | 359 | + if (mem) { |
265 | +static void apple_gfx_mmio_map_surface_memory(void *opaque) | 360 | + memory_region_ref(region); |
266 | +{ | 361 | + } |
267 | + AppleGFXMapSurfaceMemoryJob *job = opaque; | 362 | + return mem; |
268 | + AppleGFXMMIOState *s = job->state; | 363 | +} |
269 | + mach_vm_address_t mem; | 364 | + |
270 | + | 365 | +static bool apple_gfx_mmio_unmap_surface_memory(void *ptr) |
271 | + mem = apple_gfx_host_address_for_gpa_range(job->guest_physical_address, | 366 | +{ |
272 | + job->guest_physical_length, | 367 | + MemoryRegion *region; |
273 | + job->read_only); | 368 | + ram_addr_t offset = 0; |
274 | + | 369 | + |
275 | + qemu_mutex_lock(&s->common.job_mutex); | 370 | + RCU_READ_LOCK_GUARD(); |
276 | + job->result_mem = (void*)mem; | 371 | + region = memory_region_from_host(ptr, &offset); |
277 | + job->success = mem != 0; | 372 | + if (!region) { |
278 | + job->done = true; | 373 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: memory at %p to be unmapped not " |
279 | + qemu_cond_broadcast(&s->common.job_cond); | 374 | + "found.\n", |
280 | + qemu_mutex_unlock(&s->common.job_mutex); | 375 | + __func__, ptr); |
376 | + return false; | ||
377 | + } | ||
378 | + | ||
379 | + trace_apple_gfx_iosfc_unmap_memory_region(ptr, region); | ||
380 | + memory_region_unref(region); | ||
381 | + return true; | ||
281 | +} | 382 | +} |
282 | + | 383 | + |
283 | +static PGIOSurfaceHostDevice *apple_gfx_prepare_iosurface_host_device( | 384 | +static PGIOSurfaceHostDevice *apple_gfx_prepare_iosurface_host_device( |
284 | + AppleGFXMMIOState *s) | 385 | + AppleGFXMMIOState *s) |
285 | +{ | 386 | +{ |
286 | + PGIOSurfaceHostDeviceDescriptor *iosfc_desc = | 387 | + PGIOSurfaceHostDeviceDescriptor *iosfc_desc = |
287 | + [PGIOSurfaceHostDeviceDescriptor new]; | 388 | + [PGIOSurfaceHostDeviceDescriptor new]; |
288 | + PGIOSurfaceHostDevice *iosfc_host_dev = nil; | 389 | + PGIOSurfaceHostDevice *iosfc_host_dev; |
289 | + | 390 | + |
290 | + iosfc_desc.mapMemory = | 391 | + iosfc_desc.mapMemory = |
291 | + ^bool(uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *f) { | 392 | + ^bool(uint64_t phys, uint64_t len, bool ro, void **va, void *e, void *f) { |
292 | + AppleGFXMapSurfaceMemoryJob job = { | 393 | + *va = apple_gfx_mmio_map_surface_memory(phys, len, ro); |
293 | + .guest_physical_address = phys, .guest_physical_length = len, | 394 | + |
294 | + .read_only = ro, .state = s, | 395 | + trace_apple_gfx_iosfc_map_memory(phys, len, ro, va, e, f, *va); |
295 | + }; | 396 | + |
296 | + | 397 | + return *va != NULL; |
297 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
298 | + apple_gfx_mmio_map_surface_memory, &job); | ||
299 | + apple_gfx_await_bh_job(&s->common, &job.done); | ||
300 | + | ||
301 | + *va = job.result_mem; | ||
302 | + | ||
303 | + trace_apple_gfx_iosfc_map_memory(phys, len, ro, va, e, f, *va, | ||
304 | + job.success); | ||
305 | + | ||
306 | + return job.success; | ||
307 | + }; | 398 | + }; |
308 | + | 399 | + |
309 | + iosfc_desc.unmapMemory = | 400 | + iosfc_desc.unmapMemory = |
310 | + ^bool(void *a, void *b, void *c, void *d, void *e, void *f) { | 401 | + ^bool(void *va, void *b, void *c, void *d, void *e, void *f) { |
311 | + trace_apple_gfx_iosfc_unmap_memory(a, b, c, d, e, f); | 402 | + return apple_gfx_mmio_unmap_surface_memory(va); |
312 | + return true; | ||
313 | + }; | 403 | + }; |
314 | + | 404 | + |
315 | + iosfc_desc.raiseInterrupt = ^bool(uint32_t vector) { | 405 | + iosfc_desc.raiseInterrupt = ^bool(uint32_t vector) { |
316 | + trace_apple_gfx_iosfc_raise_irq(vector); | 406 | + trace_apple_gfx_iosfc_raise_irq(vector); |
317 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), raise_iosfc_irq, s); | 407 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), |
408 | + raise_irq_bh, &s->irq_iosfc); | ||
318 | + return true; | 409 | + return true; |
319 | + }; | 410 | + }; |
320 | + | 411 | + |
321 | + iosfc_host_dev = | 412 | + iosfc_host_dev = |
322 | + [[PGIOSurfaceHostDevice alloc] initWithDescriptor:iosfc_desc]; | 413 | + [[PGIOSurfaceHostDevice alloc] initWithDescriptor:iosfc_desc]; |
323 | + [iosfc_desc release]; | 414 | + [iosfc_desc release]; |
324 | + return iosfc_host_dev; | 415 | + return iosfc_host_dev; |
325 | +} | 416 | +} |
326 | + | 417 | + |
327 | +static void raise_gfx_irq(void *opaque) | ||
328 | +{ | ||
329 | + AppleGFXMMIOState *s = opaque; | ||
330 | + | ||
331 | + qemu_irq_pulse(s->irq_gfx); | ||
332 | +} | ||
333 | + | ||
334 | +static void apple_gfx_mmio_realize(DeviceState *dev, Error **errp) | 418 | +static void apple_gfx_mmio_realize(DeviceState *dev, Error **errp) |
335 | +{ | 419 | +{ |
336 | + @autoreleasepool { | 420 | + @autoreleasepool { |
337 | + AppleGFXMMIOState *s = APPLE_GFX_MMIO(dev); | 421 | + AppleGFXMMIOState *s = APPLE_GFX_MMIO(dev); |
338 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; | 422 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; |
339 | + | 423 | + |
340 | + desc.raiseInterrupt = ^(uint32_t vector) { | 424 | + desc.raiseInterrupt = ^(uint32_t vector) { |
341 | + trace_apple_gfx_raise_irq(vector); | 425 | + trace_apple_gfx_raise_irq(vector); |
342 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), raise_gfx_irq, s); | 426 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), |
427 | + raise_irq_bh, &s->irq_gfx); | ||
343 | + }; | 428 | + }; |
344 | + | 429 | + |
345 | + desc.usingIOSurfaceMapper = true; | 430 | + desc.usingIOSurfaceMapper = true; |
346 | + s->pgiosfc = apple_gfx_prepare_iosurface_host_device(s); | 431 | + s->pgiosfc = apple_gfx_prepare_iosurface_host_device(s); |
347 | + | 432 | + |
348 | + apple_gfx_common_realize(&s->common, desc, errp); | 433 | + if (!apple_gfx_common_realize(&s->common, dev, desc, errp)) { |
434 | + [s->pgiosfc release]; | ||
435 | + s->pgiosfc = nil; | ||
436 | + } | ||
437 | + | ||
349 | + [desc release]; | 438 | + [desc release]; |
350 | + desc = nil; | 439 | + desc = nil; |
351 | + } | 440 | + } |
352 | +} | 441 | +} |
353 | + | 442 | + |
... | ... | ||
396 | new file mode 100644 | 485 | new file mode 100644 |
397 | index XXXXXXX..XXXXXXX | 486 | index XXXXXXX..XXXXXXX |
398 | --- /dev/null | 487 | --- /dev/null |
399 | +++ b/hw/display/apple-gfx.h | 488 | +++ b/hw/display/apple-gfx.h |
400 | @@ -XXX,XX +XXX,XX @@ | 489 | @@ -XXX,XX +XXX,XX @@ |
490 | +/* | ||
491 | + * Data structures and functions shared between variants of the macOS | ||
492 | + * ParavirtualizedGraphics.framework based apple-gfx display adapter. | ||
493 | + * | ||
494 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
495 | + */ | ||
496 | + | ||
401 | +#ifndef QEMU_APPLE_GFX_H | 497 | +#ifndef QEMU_APPLE_GFX_H |
402 | +#define QEMU_APPLE_GFX_H | 498 | +#define QEMU_APPLE_GFX_H |
403 | + | 499 | + |
404 | +#define TYPE_APPLE_GFX_MMIO "apple-gfx-mmio" | 500 | +#define TYPE_APPLE_GFX_MMIO "apple-gfx-mmio" |
405 | +#define TYPE_APPLE_GFX_PCI "apple-gfx-pci" | 501 | +#define TYPE_APPLE_GFX_PCI "apple-gfx-pci" |
... | ... | ||
418 | +@protocol MTLTexture; | 514 | +@protocol MTLTexture; |
419 | +@protocol MTLCommandQueue; | 515 | +@protocol MTLCommandQueue; |
420 | + | 516 | + |
421 | +typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; | 517 | +typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; |
422 | + | 518 | + |
423 | +struct AppleGFXMapMemoryJob; | ||
424 | +typedef struct AppleGFXState { | 519 | +typedef struct AppleGFXState { |
520 | + /* Initialised on init/realize() */ | ||
425 | + MemoryRegion iomem_gfx; | 521 | + MemoryRegion iomem_gfx; |
426 | + id<PGDevice> pgdev; | 522 | + id<PGDevice> pgdev; |
427 | + id<PGDisplay> pgdisp; | 523 | + id<PGDisplay> pgdisp; |
428 | + PGTaskList tasks; | ||
429 | + QemuConsole *con; | 524 | + QemuConsole *con; |
430 | + id<MTLDevice> mtl; | 525 | + id<MTLDevice> mtl; |
431 | + id<MTLCommandQueue> mtl_queue; | 526 | + id<MTLCommandQueue> mtl_queue; |
432 | + bool cursor_show; | 527 | + |
528 | + /* List `tasks` is protected by task_mutex */ | ||
529 | + QemuMutex task_mutex; | ||
530 | + PGTaskList tasks; | ||
531 | + | ||
532 | + /* Mutable state (BQL protected) */ | ||
433 | + QEMUCursor *cursor; | 533 | + QEMUCursor *cursor; |
434 | + | ||
435 | + /* For running PVG memory-mapping requests in the AIO context */ | ||
436 | + QemuCond job_cond; | ||
437 | + QemuMutex job_mutex; | ||
438 | + | ||
439 | + dispatch_queue_t render_queue; | ||
440 | + /* The following fields should only be accessed from the BQL: */ | ||
441 | + bool gfx_update_requested; | ||
442 | + bool new_frame_ready; | ||
443 | + bool using_managed_texture_storage; | ||
444 | + int32_t pending_frames; | ||
445 | + void *vram; | ||
446 | + DisplaySurface *surface; | 534 | + DisplaySurface *surface; |
447 | + id<MTLTexture> texture; | 535 | + id<MTLTexture> texture; |
536 | + int8_t pending_frames; /* # guest frames in the rendering pipeline */ | ||
537 | + bool gfx_update_requested; /* QEMU display system wants a new frame */ | ||
538 | + bool new_frame_ready; /* Guest has rendered a frame, ready to be used */ | ||
539 | + bool using_managed_texture_storage; | ||
540 | + uint32_t rendering_frame_width; | ||
541 | + uint32_t rendering_frame_height; | ||
542 | + | ||
543 | + /* Mutable state (atomic) */ | ||
544 | + bool cursor_show; | ||
448 | +} AppleGFXState; | 545 | +} AppleGFXState; |
449 | + | 546 | + |
450 | +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name); | 547 | +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name); |
451 | +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, | 548 | +bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, |
452 | + Error **errp); | 549 | + PGDeviceDescriptor *desc, Error **errp); |
453 | +uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t guest_physical, | 550 | +void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical, |
454 | + uint64_t length, bool read_only); | 551 | + uint64_t length, bool read_only, |
455 | +void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag); | 552 | + MemoryRegion **mapping_in_region); |
456 | + | 553 | + |
457 | +#endif | 554 | +#endif |
458 | + | 555 | + |
459 | diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m | 556 | diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m |
460 | new file mode 100644 | 557 | new file mode 100644 |
... | ... | ||
468 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 565 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
469 | + * | 566 | + * |
470 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 567 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
471 | + * See the COPYING file in the top-level directory. | 568 | + * See the COPYING file in the top-level directory. |
472 | + * | 569 | + * |
570 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
571 | + * | ||
473 | + * ParavirtualizedGraphics.framework is a set of libraries that macOS provides | 572 | + * ParavirtualizedGraphics.framework is a set of libraries that macOS provides |
474 | + * which implements 3d graphics passthrough to the host as well as a | 573 | + * which implements 3d graphics passthrough to the host as well as a |
475 | + * proprietary guest communication channel to drive it. This device model | 574 | + * proprietary guest communication channel to drive it. This device model |
476 | + * implements support to drive that library from within QEMU. | 575 | + * implements support to drive that library from within QEMU. |
477 | + */ | 576 | + */ |
... | ... | ||
488 | +#include "qemu/main-loop.h" | 587 | +#include "qemu/main-loop.h" |
489 | +#include "qemu/cutils.h" | 588 | +#include "qemu/cutils.h" |
490 | +#include "qemu/log.h" | 589 | +#include "qemu/log.h" |
491 | +#include "qapi/visitor.h" | 590 | +#include "qapi/visitor.h" |
492 | +#include "qapi/error.h" | 591 | +#include "qapi/error.h" |
592 | +#include "sysemu/dma.h" | ||
493 | +#include "ui/console.h" | 593 | +#include "ui/console.h" |
494 | + | 594 | + |
495 | +static const PGDisplayCoord_t apple_gfx_modes[] = { | 595 | +static const PGDisplayCoord_t apple_gfx_modes[] = { |
496 | + { .x = 1440, .y = 1080 }, | 596 | + { .x = 1440, .y = 1080 }, |
497 | + { .x = 1280, .y = 1024 }, | 597 | + { .x = 1280, .y = 1024 }, |
498 | +}; | 598 | +}; |
499 | + | 599 | + |
500 | +/* This implements a type defined in <ParavirtualizedGraphics/PGDevice.h> | 600 | +static Error *apple_gfx_mig_blocker; |
501 | + * which is opaque from the framework's point of view. Typedef PGTask_t already | 601 | +static uint32_t next_pgdisplay_serial_num = 1; |
502 | + * exists in the framework headers. */ | 602 | + |
603 | +static dispatch_queue_t get_background_queue(void) | ||
604 | +{ | ||
605 | + return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | ||
606 | +} | ||
607 | + | ||
608 | +/* ------ PGTask and task operations: new/destroy/map/unmap ------ */ | ||
609 | + | ||
610 | +/* | ||
611 | + * This implements the type declared in <ParavirtualizedGraphics/PGDevice.h> | ||
612 | + * which is opaque from the framework's point of view. It is used in callbacks | ||
613 | + * in the form of its typedef PGTask_t, which also already exists in the | ||
614 | + * framework headers. | ||
615 | + * | ||
616 | + * A "task" in PVG terminology represents a host-virtual contiguous address | ||
617 | + * range which is reserved in a large chunk on task creation. The mapMemory | ||
618 | + * callback then requests ranges of guest system memory (identified by their | ||
619 | + * GPA) to be mapped into subranges of this reserved address space. | ||
620 | + * This type of operation isn't well-supported by QEMU's memory subsystem, | ||
621 | + * but it is fortunately trivial to achieve with Darwin's mach_vm_remap() call, | ||
622 | + * which allows us to refer to the same backing memory via multiple virtual | ||
623 | + * address ranges. The Mach VM APIs are therefore used throughout for managing | ||
624 | + * task memory. | ||
625 | + */ | ||
503 | +struct PGTask_s { | 626 | +struct PGTask_s { |
504 | + QTAILQ_ENTRY(PGTask_s) node; | 627 | + QTAILQ_ENTRY(PGTask_s) node; |
628 | + AppleGFXState *s; | ||
505 | + mach_vm_address_t address; | 629 | + mach_vm_address_t address; |
506 | + uint64_t len; | 630 | + uint64_t len; |
631 | + /* | ||
632 | + * All unique MemoryRegions for which a mapping has been created in in this | ||
633 | + * task, and on which we have thus called memory_region_ref(). There are | ||
634 | + * usually very few regions of system RAM in total, so we expect this array | ||
635 | + * to be very short. Therefore, no need for sorting or fancy search | ||
636 | + * algorithms, linear search will do. | ||
637 | + * Protected by AppleGFXState's task_mutex. | ||
638 | + */ | ||
639 | + GPtrArray *mapped_regions; | ||
507 | +}; | 640 | +}; |
508 | + | ||
509 | +static Error *apple_gfx_mig_blocker; | ||
510 | + | ||
511 | +static void apple_gfx_render_frame_completed(AppleGFXState *s, | ||
512 | + uint32_t width, uint32_t height); | ||
513 | + | ||
514 | +static inline dispatch_queue_t get_background_queue(void) | ||
515 | +{ | ||
516 | + return dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | ||
517 | +} | ||
518 | + | 641 | + |
519 | +static PGTask_t *apple_gfx_new_task(AppleGFXState *s, uint64_t len) | 642 | +static PGTask_t *apple_gfx_new_task(AppleGFXState *s, uint64_t len) |
520 | +{ | 643 | +{ |
521 | + mach_vm_address_t task_mem; | 644 | + mach_vm_address_t task_mem; |
522 | + PGTask_t *task; | 645 | + PGTask_t *task; |
523 | + kern_return_t r; | 646 | + kern_return_t r; |
524 | + | 647 | + |
525 | + r = mach_vm_allocate(mach_task_self(), &task_mem, len, VM_FLAGS_ANYWHERE); | 648 | + r = mach_vm_allocate(mach_task_self(), &task_mem, len, VM_FLAGS_ANYWHERE); |
526 | + if (r != KERN_SUCCESS || task_mem == 0) { | 649 | + if (r != KERN_SUCCESS) { |
527 | + return NULL; | 650 | + return NULL; |
528 | + } | 651 | + } |
529 | + | 652 | + |
530 | + task = g_new0(PGTask_t, 1); | 653 | + task = g_new0(PGTask_t, 1); |
531 | + | 654 | + task->s = s; |
532 | + task->address = task_mem; | 655 | + task->address = task_mem; |
533 | + task->len = len; | 656 | + task->len = len; |
657 | + task->mapped_regions = g_ptr_array_sized_new(2 /* Usually enough */); | ||
658 | + | ||
659 | + QEMU_LOCK_GUARD(&s->task_mutex); | ||
534 | + QTAILQ_INSERT_TAIL(&s->tasks, task, node); | 660 | + QTAILQ_INSERT_TAIL(&s->tasks, task, node); |
535 | + | 661 | + |
536 | + return task; | 662 | + return task; |
537 | +} | 663 | +} |
664 | + | ||
665 | +static void apple_gfx_destroy_task(AppleGFXState *s, PGTask_t *task) | ||
666 | +{ | ||
667 | + GPtrArray *regions = task->mapped_regions; | ||
668 | + MemoryRegion *region; | ||
669 | + size_t i; | ||
670 | + | ||
671 | + for (i = 0; i < regions->len; ++i) { | ||
672 | + region = g_ptr_array_index(regions, i); | ||
673 | + memory_region_unref(region); | ||
674 | + } | ||
675 | + g_ptr_array_unref(regions); | ||
676 | + | ||
677 | + mach_vm_deallocate(mach_task_self(), task->address, task->len); | ||
678 | + | ||
679 | + QEMU_LOCK_GUARD(&s->task_mutex); | ||
680 | + QTAILQ_REMOVE(&s->tasks, task, node); | ||
681 | + g_free(task); | ||
682 | +} | ||
683 | + | ||
684 | +void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical, | ||
685 | + uint64_t length, bool read_only, | ||
686 | + MemoryRegion **mapping_in_region) | ||
687 | +{ | ||
688 | + MemoryRegion *ram_region; | ||
689 | + char *host_ptr; | ||
690 | + hwaddr ram_region_offset = 0; | ||
691 | + hwaddr ram_region_length = length; | ||
692 | + | ||
693 | + ram_region = address_space_translate(&address_space_memory, | ||
694 | + guest_physical, | ||
695 | + &ram_region_offset, | ||
696 | + &ram_region_length, !read_only, | ||
697 | + MEMTXATTRS_UNSPECIFIED); | ||
698 | + | ||
699 | + if (!ram_region || ram_region_length < length || | ||
700 | + !memory_access_is_direct(ram_region, !read_only)) { | ||
701 | + return NULL; | ||
702 | + } | ||
703 | + | ||
704 | + host_ptr = memory_region_get_ram_ptr(ram_region); | ||
705 | + if (!host_ptr) { | ||
706 | + return NULL; | ||
707 | + } | ||
708 | + host_ptr += ram_region_offset; | ||
709 | + *mapping_in_region = ram_region; | ||
710 | + return host_ptr; | ||
711 | +} | ||
712 | + | ||
713 | +static bool apple_gfx_task_map_memory(AppleGFXState *s, PGTask_t *task, | ||
714 | + uint64_t virtual_offset, | ||
715 | + PGPhysicalMemoryRange_t *ranges, | ||
716 | + uint32_t range_count, bool read_only) | ||
717 | +{ | ||
718 | + kern_return_t r; | ||
719 | + void *source_ptr; | ||
720 | + mach_vm_address_t target; | ||
721 | + vm_prot_t cur_protection, max_protection; | ||
722 | + bool success = true; | ||
723 | + MemoryRegion *region; | ||
724 | + | ||
725 | + RCU_READ_LOCK_GUARD(); | ||
726 | + QEMU_LOCK_GUARD(&s->task_mutex); | ||
727 | + | ||
728 | + trace_apple_gfx_map_memory(task, range_count, virtual_offset, read_only); | ||
729 | + for (int i = 0; i < range_count; i++) { | ||
730 | + PGPhysicalMemoryRange_t *range = &ranges[i]; | ||
731 | + | ||
732 | + target = task->address + virtual_offset; | ||
733 | + virtual_offset += range->physicalLength; | ||
734 | + | ||
735 | + trace_apple_gfx_map_memory_range(i, range->physicalAddress, | ||
736 | + range->physicalLength); | ||
737 | + | ||
738 | + region = NULL; | ||
739 | + source_ptr = apple_gfx_host_ptr_for_gpa_range(range->physicalAddress, | ||
740 | + range->physicalLength, | ||
741 | + read_only, ®ion); | ||
742 | + if (!source_ptr) { | ||
743 | + success = false; | ||
744 | + continue; | ||
745 | + } | ||
746 | + | ||
747 | + if (!g_ptr_array_find(task->mapped_regions, region, NULL)) { | ||
748 | + g_ptr_array_add(task->mapped_regions, region); | ||
749 | + memory_region_ref(region); | ||
750 | + } | ||
751 | + | ||
752 | + cur_protection = 0; | ||
753 | + max_protection = 0; | ||
754 | + /* Map guest RAM at range->physicalAddress into PG task memory range */ | ||
755 | + r = mach_vm_remap(mach_task_self(), | ||
756 | + &target, range->physicalLength, vm_page_size - 1, | ||
757 | + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE, | ||
758 | + mach_task_self(), (mach_vm_address_t)source_ptr, | ||
759 | + false /* shared mapping, no copy */, | ||
760 | + &cur_protection, &max_protection, | ||
761 | + VM_INHERIT_COPY); | ||
762 | + trace_apple_gfx_remap(r, source_ptr, target); | ||
763 | + g_assert(r == KERN_SUCCESS); | ||
764 | + } | ||
765 | + | ||
766 | + return success; | ||
767 | +} | ||
768 | + | ||
769 | +static void apple_gfx_task_unmap_memory(AppleGFXState *s, PGTask_t *task, | ||
770 | + uint64_t virtual_offset, uint64_t length) | ||
771 | +{ | ||
772 | + kern_return_t r; | ||
773 | + mach_vm_address_t range_address; | ||
774 | + | ||
775 | + trace_apple_gfx_unmap_memory(task, virtual_offset, length); | ||
776 | + | ||
777 | + /* | ||
778 | + * Replace task memory range with fresh 0 pages, undoing the mapping | ||
779 | + * from guest RAM. | ||
780 | + */ | ||
781 | + range_address = task->address + virtual_offset; | ||
782 | + r = mach_vm_allocate(mach_task_self(), &range_address, length, | ||
783 | + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE); | ||
784 | + g_assert(r == KERN_SUCCESS); | ||
785 | +} | ||
786 | + | ||
787 | +/* ------ Rendering and frame management ------ */ | ||
788 | + | ||
789 | +static void apple_gfx_render_frame_completed_bh(void *opaque); | ||
790 | + | ||
791 | +static void apple_gfx_render_new_frame(AppleGFXState *s) | ||
792 | +{ | ||
793 | + bool managed_texture = s->using_managed_texture_storage; | ||
794 | + uint32_t width = surface_width(s->surface); | ||
795 | + uint32_t height = surface_height(s->surface); | ||
796 | + MTLRegion region = MTLRegionMake2D(0, 0, width, height); | ||
797 | + id<MTLCommandBuffer> command_buffer = [s->mtl_queue commandBuffer]; | ||
798 | + id<MTLTexture> texture = s->texture; | ||
799 | + | ||
800 | + assert(bql_locked()); | ||
801 | + [texture retain]; | ||
802 | + [command_buffer retain]; | ||
803 | + | ||
804 | + s->rendering_frame_width = width; | ||
805 | + s->rendering_frame_height = height; | ||
806 | + | ||
807 | + dispatch_async(get_background_queue(), ^{ | ||
808 | + /* | ||
809 | + * This is not safe to call from the BQL/BH due to PVG-internal locks | ||
810 | + * causing deadlocks. | ||
811 | + */ | ||
812 | + bool r = [s->pgdisp encodeCurrentFrameToCommandBuffer:command_buffer | ||
813 | + texture:texture | ||
814 | + region:region]; | ||
815 | + if (!r) { | ||
816 | + [texture release]; | ||
817 | + [command_buffer release]; | ||
818 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
819 | + "%s: encodeCurrentFrameToCommandBuffer:texture:region: " | ||
820 | + "failed\n", __func__); | ||
821 | + bql_lock(); | ||
822 | + --s->pending_frames; | ||
823 | + if (s->pending_frames > 0) { | ||
824 | + apple_gfx_render_new_frame(s); | ||
825 | + } | ||
826 | + bql_unlock(); | ||
827 | + return; | ||
828 | + } | ||
829 | + | ||
830 | + if (managed_texture) { | ||
831 | + /* "Managed" textures exist in both VRAM and RAM and must be synced. */ | ||
832 | + id<MTLBlitCommandEncoder> blit = [command_buffer blitCommandEncoder]; | ||
833 | + [blit synchronizeResource:texture]; | ||
834 | + [blit endEncoding]; | ||
835 | + } | ||
836 | + [texture release]; | ||
837 | + [command_buffer addCompletedHandler: | ||
838 | + ^(id<MTLCommandBuffer> cb) | ||
839 | + { | ||
840 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
841 | + apple_gfx_render_frame_completed_bh, s); | ||
842 | + }]; | ||
843 | + [command_buffer commit]; | ||
844 | + [command_buffer release]; | ||
845 | + }); | ||
846 | +} | ||
847 | + | ||
848 | +static void copy_mtl_texture_to_surface_mem(id<MTLTexture> texture, void *vram) | ||
849 | +{ | ||
850 | + /* | ||
851 | + * TODO: Skip this entirely on a pure Metal or headless/guest-only | ||
852 | + * rendering path, else use a blit command encoder? Needs careful | ||
853 | + * (double?) buffering design. | ||
854 | + */ | ||
855 | + size_t width = texture.width, height = texture.height; | ||
856 | + MTLRegion region = MTLRegionMake2D(0, 0, width, height); | ||
857 | + [texture getBytes:vram | ||
858 | + bytesPerRow:(width * 4) | ||
859 | + bytesPerImage:(width * height * 4) | ||
860 | + fromRegion:region | ||
861 | + mipmapLevel:0 | ||
862 | + slice:0]; | ||
863 | +} | ||
864 | + | ||
865 | +static void apple_gfx_render_frame_completed_bh(void *opaque) | ||
866 | +{ | ||
867 | + AppleGFXState *s = opaque; | ||
868 | + | ||
869 | + @autoreleasepool { | ||
870 | + --s->pending_frames; | ||
871 | + assert(s->pending_frames >= 0); | ||
872 | + | ||
873 | + /* Only update display if mode hasn't changed since we started rendering. */ | ||
874 | + if (s->rendering_frame_width == surface_width(s->surface) && | ||
875 | + s->rendering_frame_height == surface_height(s->surface)) { | ||
876 | + copy_mtl_texture_to_surface_mem(s->texture, surface_data(s->surface)); | ||
877 | + if (s->gfx_update_requested) { | ||
878 | + s->gfx_update_requested = false; | ||
879 | + dpy_gfx_update_full(s->con); | ||
880 | + graphic_hw_update_done(s->con); | ||
881 | + s->new_frame_ready = false; | ||
882 | + } else { | ||
883 | + s->new_frame_ready = true; | ||
884 | + } | ||
885 | + } | ||
886 | + if (s->pending_frames > 0) { | ||
887 | + apple_gfx_render_new_frame(s); | ||
888 | + } | ||
889 | + } | ||
890 | +} | ||
891 | + | ||
892 | +static void apple_gfx_fb_update_display(void *opaque) | ||
893 | +{ | ||
894 | + AppleGFXState *s = opaque; | ||
895 | + | ||
896 | + assert(bql_locked()); | ||
897 | + if (s->new_frame_ready) { | ||
898 | + dpy_gfx_update_full(s->con); | ||
899 | + s->new_frame_ready = false; | ||
900 | + graphic_hw_update_done(s->con); | ||
901 | + } else if (s->pending_frames > 0) { | ||
902 | + s->gfx_update_requested = true; | ||
903 | + } else { | ||
904 | + graphic_hw_update_done(s->con); | ||
905 | + } | ||
906 | +} | ||
907 | + | ||
908 | +static const GraphicHwOps apple_gfx_fb_ops = { | ||
909 | + .gfx_update = apple_gfx_fb_update_display, | ||
910 | + .gfx_update_async = true, | ||
911 | +}; | ||
912 | + | ||
913 | +/* ------ Mouse cursor and display mode setting ------ */ | ||
914 | + | ||
915 | +static void set_mode(AppleGFXState *s, uint32_t width, uint32_t height) | ||
916 | +{ | ||
917 | + MTLTextureDescriptor *textureDescriptor; | ||
918 | + | ||
919 | + if (s->surface && | ||
920 | + width == surface_width(s->surface) && | ||
921 | + height == surface_height(s->surface)) { | ||
922 | + return; | ||
923 | + } | ||
924 | + | ||
925 | + [s->texture release]; | ||
926 | + | ||
927 | + s->surface = qemu_create_displaysurface(width, height); | ||
928 | + | ||
929 | + @autoreleasepool { | ||
930 | + textureDescriptor = | ||
931 | + [MTLTextureDescriptor | ||
932 | + texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm | ||
933 | + width:width | ||
934 | + height:height | ||
935 | + mipmapped:NO]; | ||
936 | + textureDescriptor.usage = s->pgdisp.minimumTextureUsage; | ||
937 | + s->texture = [s->mtl newTextureWithDescriptor:textureDescriptor]; | ||
938 | + s->using_managed_texture_storage = | ||
939 | + (s->texture.storageMode == MTLStorageModeManaged); | ||
940 | + } | ||
941 | + | ||
942 | + dpy_gfx_replace_surface(s->con, s->surface); | ||
943 | +} | ||
944 | + | ||
945 | +static void update_cursor(AppleGFXState *s) | ||
946 | +{ | ||
947 | + assert(bql_locked()); | ||
948 | + dpy_mouse_set(s->con, s->pgdisp.cursorPosition.x, | ||
949 | + s->pgdisp.cursorPosition.y, qatomic_read(&s->cursor_show)); | ||
950 | +} | ||
951 | + | ||
952 | +static void update_cursor_bh(void *opaque) | ||
953 | +{ | ||
954 | + AppleGFXState *s = opaque; | ||
955 | + update_cursor(s); | ||
956 | +} | ||
957 | + | ||
958 | +typedef struct AppleGFXSetCursorGlyphJob { | ||
959 | + AppleGFXState *s; | ||
960 | + NSBitmapImageRep *glyph; | ||
961 | + PGDisplayCoord_t hotspot; | ||
962 | +} AppleGFXSetCursorGlyphJob; | ||
963 | + | ||
964 | +static void set_cursor_glyph(void *opaque) | ||
965 | +{ | ||
966 | + AppleGFXSetCursorGlyphJob *job = opaque; | ||
967 | + AppleGFXState *s = job->s; | ||
968 | + NSBitmapImageRep *glyph = job->glyph; | ||
969 | + uint32_t bpp = glyph.bitsPerPixel; | ||
970 | + size_t width = glyph.pixelsWide; | ||
971 | + size_t height = glyph.pixelsHigh; | ||
972 | + size_t padding_bytes_per_row = glyph.bytesPerRow - width * 4; | ||
973 | + const uint8_t* px_data = glyph.bitmapData; | ||
974 | + | ||
975 | + trace_apple_gfx_cursor_set(bpp, width, height); | ||
976 | + | ||
977 | + if (s->cursor) { | ||
978 | + cursor_unref(s->cursor); | ||
979 | + s->cursor = NULL; | ||
980 | + } | ||
981 | + | ||
982 | + if (bpp == 32) { /* Shouldn't be anything else, but just to be safe...*/ | ||
983 | + s->cursor = cursor_alloc(width, height); | ||
984 | + s->cursor->hot_x = job->hotspot.x; | ||
985 | + s->cursor->hot_y = job->hotspot.y; | ||
986 | + | ||
987 | + uint32_t *dest_px = s->cursor->data; | ||
988 | + | ||
989 | + for (size_t y = 0; y < height; ++y) { | ||
990 | + for (size_t x = 0; x < width; ++x) { | ||
991 | + /* | ||
992 | + * NSBitmapImageRep's red & blue channels are swapped | ||
993 | + * compared to QEMUCursor's. | ||
994 | + */ | ||
995 | + *dest_px = | ||
996 | + (px_data[0] << 16u) | | ||
997 | + (px_data[1] << 8u) | | ||
998 | + (px_data[2] << 0u) | | ||
999 | + (px_data[3] << 24u); | ||
1000 | + ++dest_px; | ||
1001 | + px_data += 4; | ||
1002 | + } | ||
1003 | + px_data += padding_bytes_per_row; | ||
1004 | + } | ||
1005 | + dpy_cursor_define(s->con, s->cursor); | ||
1006 | + update_cursor(s); | ||
1007 | + } | ||
1008 | + [glyph release]; | ||
1009 | + | ||
1010 | + g_free(job); | ||
1011 | +} | ||
1012 | + | ||
1013 | +/* ------ DMA (device reading system memory) ------ */ | ||
1014 | + | ||
1015 | +typedef struct AppleGFXReadMemoryJob { | ||
1016 | + QemuSemaphore sem; | ||
1017 | + hwaddr physical_address; | ||
1018 | + uint64_t length; | ||
1019 | + void *dst; | ||
1020 | + bool success; | ||
1021 | +} AppleGFXReadMemoryJob; | ||
1022 | + | ||
1023 | +static void apple_gfx_do_read_memory(void *opaque) | ||
1024 | +{ | ||
1025 | + AppleGFXReadMemoryJob *job = opaque; | ||
1026 | + MemTxResult r; | ||
1027 | + | ||
1028 | + r = dma_memory_read(&address_space_memory, job->physical_address, | ||
1029 | + job->dst, job->length, MEMTXATTRS_UNSPECIFIED); | ||
1030 | + job->success = r == MEMTX_OK; | ||
1031 | + | ||
1032 | + qemu_sem_post(&job->sem); | ||
1033 | +} | ||
1034 | + | ||
1035 | +static bool apple_gfx_read_memory(AppleGFXState *s, hwaddr physical_address, | ||
1036 | + uint64_t length, void *dst) | ||
1037 | +{ | ||
1038 | + AppleGFXReadMemoryJob job = { | ||
1039 | + .physical_address = physical_address, .length = length, .dst = dst | ||
1040 | + }; | ||
1041 | + | ||
1042 | + trace_apple_gfx_read_memory(physical_address, length, dst); | ||
1043 | + | ||
1044 | + /* Performing DMA requires BQL, so do it in a BH. */ | ||
1045 | + qemu_sem_init(&job.sem, 0); | ||
1046 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
1047 | + apple_gfx_do_read_memory, &job); | ||
1048 | + qemu_sem_wait(&job.sem); | ||
1049 | + qemu_sem_destroy(&job.sem); | ||
1050 | + return job.success; | ||
1051 | +} | ||
1052 | + | ||
1053 | +/* ------ Memory-mapped device I/O operations ------ */ | ||
538 | + | 1054 | + |
539 | +typedef struct AppleGFXIOJob { | 1055 | +typedef struct AppleGFXIOJob { |
540 | + AppleGFXState *state; | 1056 | + AppleGFXState *state; |
541 | + uint64_t offset; | 1057 | + uint64_t offset; |
542 | + uint64_t value; | 1058 | + uint64_t value; |
... | ... | ||
556 | + AppleGFXIOJob job = { | 1072 | + AppleGFXIOJob job = { |
557 | + .state = opaque, | 1073 | + .state = opaque, |
558 | + .offset = offset, | 1074 | + .offset = offset, |
559 | + .completed = false, | 1075 | + .completed = false, |
560 | + }; | 1076 | + }; |
561 | + AioContext *context = qemu_get_aio_context(); | ||
562 | + dispatch_queue_t queue = get_background_queue(); | 1077 | + dispatch_queue_t queue = get_background_queue(); |
563 | + | 1078 | + |
564 | + dispatch_async_f(queue, &job, apple_gfx_do_read); | 1079 | + dispatch_async_f(queue, &job, apple_gfx_do_read); |
565 | + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); | 1080 | + AIO_WAIT_WHILE(NULL, !qatomic_read(&job.completed)); |
566 | + | 1081 | + |
567 | + trace_apple_gfx_read(offset, job.value); | 1082 | + trace_apple_gfx_read(offset, job.value); |
568 | + return job.value; | 1083 | + return job.value; |
569 | +} | 1084 | +} |
570 | + | 1085 | + |
... | ... | ||
577 | +} | 1092 | +} |
578 | + | 1093 | + |
579 | +static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val, | 1094 | +static void apple_gfx_write(void *opaque, hwaddr offset, uint64_t val, |
580 | + unsigned size) | 1095 | + unsigned size) |
581 | +{ | 1096 | +{ |
582 | + /* The methods mmioReadAtOffset: and especially mmioWriteAtOffset: can | 1097 | + /* |
583 | + * trigger and block on operations on other dispatch queues, which in turn | 1098 | + * The methods mmioReadAtOffset: and especially mmioWriteAtOffset: can |
1099 | + * trigger synchronous operations on other dispatch queues, which in turn | ||
584 | + * may call back out on one or more of the callback blocks. For this reason, | 1100 | + * may call back out on one or more of the callback blocks. For this reason, |
585 | + * and as we are holding the BQL, we invoke the I/O methods on a pool | 1101 | + * and as we are holding the BQL, we invoke the I/O methods on a pool |
586 | + * thread and handle AIO tasks while we wait. Any work in the callbacks | 1102 | + * thread and handle AIO tasks while we wait. Any work in the callbacks |
587 | + * requiring the BQL will in turn schedule BHs which this thread will | 1103 | + * requiring the BQL will in turn schedule BHs which this thread will |
588 | + * process while waiting. */ | 1104 | + * process while waiting. |
1105 | + */ | ||
589 | + AppleGFXIOJob job = { | 1106 | + AppleGFXIOJob job = { |
590 | + .state = opaque, | 1107 | + .state = opaque, |
591 | + .offset = offset, | 1108 | + .offset = offset, |
592 | + .value = val, | 1109 | + .value = val, |
593 | + .completed = false, | 1110 | + .completed = false, |
594 | + }; | 1111 | + }; |
595 | + AioContext *context = qemu_get_current_aio_context(); | ||
596 | + dispatch_queue_t queue = get_background_queue(); | 1112 | + dispatch_queue_t queue = get_background_queue(); |
597 | + | 1113 | + |
598 | + dispatch_async_f(queue, &job, apple_gfx_do_write); | 1114 | + dispatch_async_f(queue, &job, apple_gfx_do_write); |
599 | + AIO_WAIT_WHILE(context, !qatomic_read(&job.completed)); | 1115 | + AIO_WAIT_WHILE(NULL, !qatomic_read(&job.completed)); |
600 | + | 1116 | + |
601 | + trace_apple_gfx_write(offset, val); | 1117 | + trace_apple_gfx_write(offset, val); |
602 | +} | 1118 | +} |
603 | + | 1119 | + |
604 | +static const MemoryRegionOps apple_gfx_ops = { | 1120 | +static const MemoryRegionOps apple_gfx_ops = { |
... | ... | ||
613 | + .min_access_size = 4, | 1129 | + .min_access_size = 4, |
614 | + .max_access_size = 4, | 1130 | + .max_access_size = 4, |
615 | + }, | 1131 | + }, |
616 | +}; | 1132 | +}; |
617 | + | 1133 | + |
618 | +static void apple_gfx_render_new_frame_bql_unlock(AppleGFXState *s) | ||
619 | +{ | ||
620 | + BOOL r; | ||
621 | + uint32_t width = surface_width(s->surface); | ||
622 | + uint32_t height = surface_height(s->surface); | ||
623 | + MTLRegion region = MTLRegionMake2D(0, 0, width, height); | ||
624 | + id<MTLCommandBuffer> command_buffer = [s->mtl_queue commandBuffer]; | ||
625 | + id<MTLTexture> texture = s->texture; | ||
626 | + | ||
627 | + assert(bql_locked()); | ||
628 | + [texture retain]; | ||
629 | + | ||
630 | + bql_unlock(); | ||
631 | + | ||
632 | + /* This is not safe to call from the BQL due to PVG-internal locks causing | ||
633 | + * deadlocks. */ | ||
634 | + r = [s->pgdisp encodeCurrentFrameToCommandBuffer:command_buffer | ||
635 | + texture:texture | ||
636 | + region:region]; | ||
637 | + if (!r) { | ||
638 | + [texture release]; | ||
639 | + bql_lock(); | ||
640 | + --s->pending_frames; | ||
641 | + bql_unlock(); | ||
642 | + qemu_log_mask(LOG_GUEST_ERROR, "apple_gfx_render_new_frame_bql_unlock: " | ||
643 | + "encodeCurrentFrameToCommandBuffer:texture:region: failed\n"); | ||
644 | + return; | ||
645 | + } | ||
646 | + | ||
647 | + if (s->using_managed_texture_storage) { | ||
648 | + /* "Managed" textures exist in both VRAM and RAM and must be synced. */ | ||
649 | + id<MTLBlitCommandEncoder> blit = [command_buffer blitCommandEncoder]; | ||
650 | + [blit synchronizeResource:texture]; | ||
651 | + [blit endEncoding]; | ||
652 | + } | ||
653 | + [texture release]; | ||
654 | + [command_buffer addCompletedHandler: | ||
655 | + ^(id<MTLCommandBuffer> cb) | ||
656 | + { | ||
657 | + dispatch_async(s->render_queue, ^{ | ||
658 | + apple_gfx_render_frame_completed(s, width, height); | ||
659 | + }); | ||
660 | + }]; | ||
661 | + [command_buffer commit]; | ||
662 | +} | ||
663 | + | ||
664 | +static void copy_mtl_texture_to_surface_mem(id<MTLTexture> texture, void *vram) | ||
665 | +{ | ||
666 | + /* TODO: Skip this entirely on a pure Metal or headless/guest-only | ||
667 | + * rendering path, else use a blit command encoder? Needs careful | ||
668 | + * (double?) buffering design. */ | ||
669 | + size_t width = texture.width, height = texture.height; | ||
670 | + MTLRegion region = MTLRegionMake2D(0, 0, width, height); | ||
671 | + [texture getBytes:vram | ||
672 | + bytesPerRow:(width * 4) | ||
673 | + bytesPerImage:(width * height * 4) | ||
674 | + fromRegion:region | ||
675 | + mipmapLevel:0 | ||
676 | + slice:0]; | ||
677 | +} | ||
678 | + | ||
679 | +static void apple_gfx_render_frame_completed(AppleGFXState *s, | ||
680 | + uint32_t width, uint32_t height) | ||
681 | +{ | ||
682 | + bql_lock(); | ||
683 | + --s->pending_frames; | ||
684 | + assert(s->pending_frames >= 0); | ||
685 | + | ||
686 | + /* Only update display if mode hasn't changed since we started rendering. */ | ||
687 | + if (width == surface_width(s->surface) && | ||
688 | + height == surface_height(s->surface)) { | ||
689 | + copy_mtl_texture_to_surface_mem(s->texture, s->vram); | ||
690 | + if (s->gfx_update_requested) { | ||
691 | + s->gfx_update_requested = false; | ||
692 | + dpy_gfx_update_full(s->con); | ||
693 | + graphic_hw_update_done(s->con); | ||
694 | + s->new_frame_ready = false; | ||
695 | + } else { | ||
696 | + s->new_frame_ready = true; | ||
697 | + } | ||
698 | + } | ||
699 | + if (s->pending_frames > 0) { | ||
700 | + apple_gfx_render_new_frame_bql_unlock(s); | ||
701 | + } else { | ||
702 | + bql_unlock(); | ||
703 | + } | ||
704 | +} | ||
705 | + | ||
706 | +static void apple_gfx_fb_update_display(void *opaque) | ||
707 | +{ | ||
708 | + AppleGFXState *s = opaque; | ||
709 | + | ||
710 | + assert(bql_locked()); | ||
711 | + if (s->new_frame_ready) { | ||
712 | + dpy_gfx_update_full(s->con); | ||
713 | + s->new_frame_ready = false; | ||
714 | + graphic_hw_update_done(s->con); | ||
715 | + } else if (s->pending_frames > 0) { | ||
716 | + s->gfx_update_requested = true; | ||
717 | + } else { | ||
718 | + graphic_hw_update_done(s->con); | ||
719 | + } | ||
720 | +} | ||
721 | + | ||
722 | +static const GraphicHwOps apple_gfx_fb_ops = { | ||
723 | + .gfx_update = apple_gfx_fb_update_display, | ||
724 | + .gfx_update_async = true, | ||
725 | +}; | ||
726 | + | ||
727 | +static void update_cursor(AppleGFXState *s) | ||
728 | +{ | ||
729 | + assert(bql_locked()); | ||
730 | + dpy_mouse_set(s->con, s->pgdisp.cursorPosition.x, | ||
731 | + s->pgdisp.cursorPosition.y, s->cursor_show); | ||
732 | +} | ||
733 | + | ||
734 | +static void set_mode(AppleGFXState *s, uint32_t width, uint32_t height) | ||
735 | +{ | ||
736 | + MTLTextureDescriptor *textureDescriptor; | ||
737 | + | ||
738 | + if (s->surface && | ||
739 | + width == surface_width(s->surface) && | ||
740 | + height == surface_height(s->surface)) { | ||
741 | + return; | ||
742 | + } | ||
743 | + | ||
744 | + g_free(s->vram); | ||
745 | + [s->texture release]; | ||
746 | + | ||
747 | + s->vram = g_malloc0_n(width * height, 4); | ||
748 | + s->surface = qemu_create_displaysurface_from(width, height, PIXMAN_LE_a8r8g8b8, | ||
749 | + width * 4, s->vram); | ||
750 | + | ||
751 | + @autoreleasepool { | ||
752 | + textureDescriptor = | ||
753 | + [MTLTextureDescriptor | ||
754 | + texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm | ||
755 | + width:width | ||
756 | + height:height | ||
757 | + mipmapped:NO]; | ||
758 | + textureDescriptor.usage = s->pgdisp.minimumTextureUsage; | ||
759 | + s->texture = [s->mtl newTextureWithDescriptor:textureDescriptor]; | ||
760 | + } | ||
761 | + | ||
762 | + s->using_managed_texture_storage = | ||
763 | + (s->texture.storageMode == MTLStorageModeManaged); | ||
764 | + dpy_gfx_replace_surface(s->con, s->surface); | ||
765 | +} | ||
766 | + | ||
767 | +static void create_fb(AppleGFXState *s) | ||
768 | +{ | ||
769 | + s->con = graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); | ||
770 | + set_mode(s, 1440, 1080); | ||
771 | + | ||
772 | + s->cursor_show = true; | ||
773 | +} | ||
774 | + | ||
775 | +static size_t apple_gfx_get_default_mmio_range_size(void) | 1134 | +static size_t apple_gfx_get_default_mmio_range_size(void) |
776 | +{ | 1135 | +{ |
777 | + size_t mmio_range_size; | 1136 | + size_t mmio_range_size; |
778 | + @autoreleasepool { | 1137 | + @autoreleasepool { |
779 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; | 1138 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; |
780 | + mmio_range_size = desc.mmioLength; | 1139 | + mmio_range_size = desc.mmioLength; |
781 | + [desc release]; | 1140 | + [desc release]; |
782 | + } | 1141 | + } |
783 | + return mmio_range_size; | 1142 | + return mmio_range_size; |
784 | +} | 1143 | +} |
785 | + | 1144 | + |
1145 | +/* ------ Initialisation and startup ------ */ | ||
1146 | + | ||
786 | +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name) | 1147 | +void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name) |
787 | +{ | 1148 | +{ |
788 | + size_t mmio_range_size = apple_gfx_get_default_mmio_range_size(); | 1149 | + size_t mmio_range_size = apple_gfx_get_default_mmio_range_size(); |
789 | + | 1150 | + |
790 | + trace_apple_gfx_common_init(obj_name, mmio_range_size); | 1151 | + trace_apple_gfx_common_init(obj_name, mmio_range_size); |
791 | + memory_region_init_io(&s->iomem_gfx, obj, &apple_gfx_ops, s, obj_name, | 1152 | + memory_region_init_io(&s->iomem_gfx, obj, &apple_gfx_ops, s, obj_name, |
792 | + mmio_range_size); | 1153 | + mmio_range_size); |
793 | + | 1154 | + |
794 | + /* TODO: PVG framework supports serialising device state: integrate it! */ | 1155 | + /* TODO: PVG framework supports serialising device state: integrate it! */ |
795 | +} | ||
796 | + | ||
797 | +typedef struct AppleGFXMapMemoryJob { | ||
798 | + AppleGFXState *state; | ||
799 | + PGTask_t *task; | ||
800 | + uint64_t virtual_offset; | ||
801 | + PGPhysicalMemoryRange_t *ranges; | ||
802 | + uint32_t range_count; | ||
803 | + bool read_only; | ||
804 | + bool success; | ||
805 | + bool done; | ||
806 | +} AppleGFXMapMemoryJob; | ||
807 | + | ||
808 | +uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t guest_physical, | ||
809 | + uint64_t length, bool read_only) | ||
810 | +{ | ||
811 | + MemoryRegion *ram_region; | ||
812 | + uintptr_t host_address; | ||
813 | + hwaddr ram_region_offset = 0; | ||
814 | + hwaddr ram_region_length = length; | ||
815 | + | ||
816 | + ram_region = address_space_translate(&address_space_memory, | ||
817 | + guest_physical, | ||
818 | + &ram_region_offset, | ||
819 | + &ram_region_length, !read_only, | ||
820 | + MEMTXATTRS_UNSPECIFIED); | ||
821 | + | ||
822 | + if (!ram_region || ram_region_length < length || | ||
823 | + !memory_access_is_direct(ram_region, !read_only)) { | ||
824 | + return 0; | ||
825 | + } | ||
826 | + | ||
827 | + host_address = (mach_vm_address_t)memory_region_get_ram_ptr(ram_region); | ||
828 | + if (host_address == 0) { | ||
829 | + return 0; | ||
830 | + } | ||
831 | + host_address += ram_region_offset; | ||
832 | + | ||
833 | + return host_address; | ||
834 | +} | ||
835 | + | ||
836 | +static void apple_gfx_map_memory(void *opaque) | ||
837 | +{ | ||
838 | + AppleGFXMapMemoryJob *job = opaque; | ||
839 | + AppleGFXState *s = job->state; | ||
840 | + PGTask_t *task = job->task; | ||
841 | + uint32_t range_count = job->range_count; | ||
842 | + uint64_t virtual_offset = job->virtual_offset; | ||
843 | + PGPhysicalMemoryRange_t *ranges = job->ranges; | ||
844 | + bool read_only = job->read_only; | ||
845 | + kern_return_t r; | ||
846 | + mach_vm_address_t target, source; | ||
847 | + vm_prot_t cur_protection, max_protection; | ||
848 | + bool success = true; | ||
849 | + | ||
850 | + g_assert(bql_locked()); | ||
851 | + | ||
852 | + trace_apple_gfx_map_memory(task, range_count, virtual_offset, read_only); | ||
853 | + for (int i = 0; i < range_count; i++) { | ||
854 | + PGPhysicalMemoryRange_t *range = &ranges[i]; | ||
855 | + | ||
856 | + target = task->address + virtual_offset; | ||
857 | + virtual_offset += range->physicalLength; | ||
858 | + | ||
859 | + trace_apple_gfx_map_memory_range(i, range->physicalAddress, | ||
860 | + range->physicalLength); | ||
861 | + | ||
862 | + source = apple_gfx_host_address_for_gpa_range(range->physicalAddress, | ||
863 | + range->physicalLength, | ||
864 | + read_only); | ||
865 | + if (source == 0) { | ||
866 | + success = false; | ||
867 | + continue; | ||
868 | + } | ||
869 | + | ||
870 | + MemoryRegion* alt_mr = NULL; | ||
871 | + mach_vm_address_t alt_source = (mach_vm_address_t)gpa2hva(&alt_mr, range->physicalAddress, range->physicalLength, NULL); | ||
872 | + g_assert(alt_source == source); | ||
873 | + | ||
874 | + cur_protection = 0; | ||
875 | + max_protection = 0; | ||
876 | + // Map guest RAM at range->physicalAddress into PG task memory range | ||
877 | + r = mach_vm_remap(mach_task_self(), | ||
878 | + &target, range->physicalLength, vm_page_size - 1, | ||
879 | + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE, | ||
880 | + mach_task_self(), | ||
881 | + source, false /* shared mapping, no copy */, | ||
882 | + &cur_protection, &max_protection, | ||
883 | + VM_INHERIT_COPY); | ||
884 | + trace_apple_gfx_remap(r, source, target); | ||
885 | + g_assert(r == KERN_SUCCESS); | ||
886 | + } | ||
887 | + | ||
888 | + qemu_mutex_lock(&s->job_mutex); | ||
889 | + job->success = success; | ||
890 | + job->done = true; | ||
891 | + qemu_cond_broadcast(&s->job_cond); | ||
892 | + qemu_mutex_unlock(&s->job_mutex); | ||
893 | +} | ||
894 | + | ||
895 | +void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag) | ||
896 | +{ | ||
897 | + qemu_mutex_lock(&s->job_mutex); | ||
898 | + while (!*job_done_flag) { | ||
899 | + qemu_cond_wait(&s->job_cond, &s->job_mutex); | ||
900 | + } | ||
901 | + qemu_mutex_unlock(&s->job_mutex); | ||
902 | +} | ||
903 | + | ||
904 | +typedef struct AppleGFXReadMemoryJob { | ||
905 | + AppleGFXState *s; | ||
906 | + hwaddr physical_address; | ||
907 | + uint64_t length; | ||
908 | + void *dst; | ||
909 | + bool done; | ||
910 | +} AppleGFXReadMemoryJob; | ||
911 | + | ||
912 | +static void apple_gfx_do_read_memory(void *opaque) | ||
913 | +{ | ||
914 | + AppleGFXReadMemoryJob *job = opaque; | ||
915 | + AppleGFXState *s = job->s; | ||
916 | + | ||
917 | + cpu_physical_memory_read(job->physical_address, job->dst, job->length); | ||
918 | + | ||
919 | + qemu_mutex_lock(&s->job_mutex); | ||
920 | + job->done = true; | ||
921 | + qemu_cond_broadcast(&s->job_cond); | ||
922 | + qemu_mutex_unlock(&s->job_mutex); | ||
923 | +} | ||
924 | + | ||
925 | +static void apple_gfx_read_memory(AppleGFXState *s, hwaddr physical_address, | ||
926 | + uint64_t length, void *dst) | ||
927 | +{ | ||
928 | + AppleGFXReadMemoryJob job = { | ||
929 | + s, physical_address, length, dst | ||
930 | + }; | ||
931 | + | ||
932 | + trace_apple_gfx_read_memory(physical_address, length, dst); | ||
933 | + | ||
934 | + /* Traversing the memory map requires RCU/BQL, so do it in a BH. */ | ||
935 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), apple_gfx_do_read_memory, | ||
936 | + &job); | ||
937 | + apple_gfx_await_bh_job(s, &job.done); | ||
938 | +} | 1156 | +} |
939 | + | 1157 | + |
940 | +static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, | 1158 | +static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, |
941 | + PGDeviceDescriptor *desc) | 1159 | + PGDeviceDescriptor *desc) |
942 | +{ | 1160 | +{ |
... | ... | ||
946 | + trace_apple_gfx_create_task(vmSize, *baseAddress); | 1164 | + trace_apple_gfx_create_task(vmSize, *baseAddress); |
947 | + return task; | 1165 | + return task; |
948 | + }; | 1166 | + }; |
949 | + | 1167 | + |
950 | + desc.destroyTask = ^(PGTask_t * _Nonnull task) { | 1168 | + desc.destroyTask = ^(PGTask_t * _Nonnull task) { |
951 | + trace_apple_gfx_destroy_task(task); | 1169 | + trace_apple_gfx_destroy_task(task, task->mapped_regions->len); |
952 | + QTAILQ_REMOVE(&s->tasks, task, node); | 1170 | + |
953 | + mach_vm_deallocate(mach_task_self(), task->address, task->len); | 1171 | + apple_gfx_destroy_task(s, task); |
954 | + g_free(task); | ||
955 | + }; | 1172 | + }; |
956 | + | 1173 | + |
957 | + desc.mapMemory = ^bool(PGTask_t * _Nonnull task, uint32_t range_count, | 1174 | + desc.mapMemory = ^bool(PGTask_t * _Nonnull task, uint32_t range_count, |
958 | + uint64_t virtual_offset, bool read_only, | 1175 | + uint64_t virtual_offset, bool read_only, |
959 | + PGPhysicalMemoryRange_t * _Nonnull ranges) { | 1176 | + PGPhysicalMemoryRange_t * _Nonnull ranges) { |
960 | + AppleGFXMapMemoryJob job = { | 1177 | + return apple_gfx_task_map_memory(s, task, virtual_offset, |
961 | + .state = s, | 1178 | + ranges, range_count, read_only); |
962 | + .task = task, .ranges = ranges, .range_count = range_count, | 1179 | + }; |
963 | + .read_only = read_only, .virtual_offset = virtual_offset, | 1180 | + |
964 | + .done = false, .success = true, | 1181 | + desc.unmapMemory = ^bool(PGTask_t * _Nonnull task, uint64_t virtual_offset, |
965 | + }; | 1182 | + uint64_t length) { |
966 | + if (range_count > 0) { | 1183 | + apple_gfx_task_unmap_memory(s, task, virtual_offset, length); |
967 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
968 | + apple_gfx_map_memory, &job); | ||
969 | + apple_gfx_await_bh_job(s, &job.done); | ||
970 | + } | ||
971 | + return job.success; | ||
972 | + }; | ||
973 | + | ||
974 | + desc.unmapMemory = ^bool(PGTask_t * _Nonnull task, uint64_t virtualOffset, | ||
975 | + uint64_t length) { | ||
976 | + kern_return_t r; | ||
977 | + mach_vm_address_t range_address; | ||
978 | + | ||
979 | + trace_apple_gfx_unmap_memory(task, virtualOffset, length); | ||
980 | + | ||
981 | + /* Replace task memory range with fresh pages, undoing the mapping | ||
982 | + * from guest RAM. */ | ||
983 | + range_address = task->address + virtualOffset; | ||
984 | + r = mach_vm_allocate(mach_task_self(), &range_address, length, | ||
985 | + VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE); | ||
986 | + g_assert(r == KERN_SUCCESS); | ||
987 | + | ||
988 | + return true; | 1184 | + return true; |
989 | + }; | 1185 | + }; |
990 | + | 1186 | + |
991 | + desc.readMemory = ^bool(uint64_t physical_address, uint64_t length, | 1187 | + desc.readMemory = ^bool(uint64_t physical_address, uint64_t length, |
992 | + void * _Nonnull dst) { | 1188 | + void * _Nonnull dst) { |
993 | + apple_gfx_read_memory(s, physical_address, length, dst); | 1189 | + return apple_gfx_read_memory(s, physical_address, length, dst); |
994 | + return true; | 1190 | + }; |
995 | + }; | 1191 | +} |
1192 | + | ||
1193 | +static void new_frame_handler_bh(void *opaque) | ||
1194 | +{ | ||
1195 | + AppleGFXState *s = opaque; | ||
1196 | + | ||
1197 | + /* Drop frames if guest gets too far ahead. */ | ||
1198 | + if (s->pending_frames >= 2) { | ||
1199 | + return; | ||
1200 | + } | ||
1201 | + ++s->pending_frames; | ||
1202 | + if (s->pending_frames > 1) { | ||
1203 | + return; | ||
1204 | + } | ||
1205 | + | ||
1206 | + @autoreleasepool { | ||
1207 | + apple_gfx_render_new_frame(s); | ||
1208 | + } | ||
996 | +} | 1209 | +} |
997 | + | 1210 | + |
998 | +static PGDisplayDescriptor *apple_gfx_prepare_display_descriptor(AppleGFXState *s) | 1211 | +static PGDisplayDescriptor *apple_gfx_prepare_display_descriptor(AppleGFXState *s) |
999 | +{ | 1212 | +{ |
1000 | + PGDisplayDescriptor *disp_desc = [PGDisplayDescriptor new]; | 1213 | + PGDisplayDescriptor *disp_desc = [PGDisplayDescriptor new]; |
1001 | + | 1214 | + |
1002 | + disp_desc.name = @"QEMU display"; | 1215 | + disp_desc.name = @"QEMU display"; |
1003 | + disp_desc.sizeInMillimeters = NSMakeSize(400., 300.); /* A 20" display */ | 1216 | + disp_desc.sizeInMillimeters = NSMakeSize(400., 300.); /* A 20" display */ |
1004 | + disp_desc.queue = dispatch_get_main_queue(); | 1217 | + disp_desc.queue = dispatch_get_main_queue(); |
1005 | + disp_desc.newFrameEventHandler = ^(void) { | 1218 | + disp_desc.newFrameEventHandler = ^(void) { |
1006 | + trace_apple_gfx_new_frame(); | 1219 | + trace_apple_gfx_new_frame(); |
1007 | + dispatch_async(s->render_queue, ^{ | 1220 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), new_frame_handler_bh, s); |
1008 | + /* Drop frames if we get too far ahead. */ | ||
1009 | + bql_lock(); | ||
1010 | + if (s->pending_frames >= 2) { | ||
1011 | + bql_unlock(); | ||
1012 | + return; | ||
1013 | + } | ||
1014 | + ++s->pending_frames; | ||
1015 | + if (s->pending_frames > 1) { | ||
1016 | + bql_unlock(); | ||
1017 | + return; | ||
1018 | + } | ||
1019 | + @autoreleasepool { | ||
1020 | + apple_gfx_render_new_frame_bql_unlock(s); | ||
1021 | + } | ||
1022 | + }); | ||
1023 | + }; | 1221 | + }; |
1024 | + disp_desc.modeChangeHandler = ^(PGDisplayCoord_t sizeInPixels, | 1222 | + disp_desc.modeChangeHandler = ^(PGDisplayCoord_t sizeInPixels, |
1025 | + OSType pixelFormat) { | 1223 | + OSType pixelFormat) { |
1026 | + trace_apple_gfx_mode_change(sizeInPixels.x, sizeInPixels.y); | 1224 | + trace_apple_gfx_mode_change(sizeInPixels.x, sizeInPixels.y); |
1027 | + | 1225 | + |
1028 | + BQL_LOCK_GUARD(); | 1226 | + BQL_LOCK_GUARD(); |
1029 | + set_mode(s, sizeInPixels.x, sizeInPixels.y); | 1227 | + set_mode(s, sizeInPixels.x, sizeInPixels.y); |
1030 | + }; | 1228 | + }; |
1031 | + disp_desc.cursorGlyphHandler = ^(NSBitmapImageRep *glyph, | 1229 | + disp_desc.cursorGlyphHandler = ^(NSBitmapImageRep *glyph, |
1032 | + PGDisplayCoord_t hotSpot) { | 1230 | + PGDisplayCoord_t hotspot) { |
1231 | + AppleGFXSetCursorGlyphJob *job = g_malloc0(sizeof(*job)); | ||
1232 | + job->s = s; | ||
1233 | + job->glyph = glyph; | ||
1234 | + job->hotspot = hotspot; | ||
1033 | + [glyph retain]; | 1235 | + [glyph retain]; |
1034 | + dispatch_async(get_background_queue(), ^{ | 1236 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), |
1035 | + BQL_LOCK_GUARD(); | 1237 | + set_cursor_glyph, job); |
1036 | + uint32_t bpp = glyph.bitsPerPixel; | ||
1037 | + size_t width = glyph.pixelsWide; | ||
1038 | + size_t height = glyph.pixelsHigh; | ||
1039 | + size_t padding_bytes_per_row = glyph.bytesPerRow - width * 4; | ||
1040 | + const uint8_t* px_data = glyph.bitmapData; | ||
1041 | + | ||
1042 | + trace_apple_gfx_cursor_set(bpp, width, height); | ||
1043 | + | ||
1044 | + if (s->cursor) { | ||
1045 | + cursor_unref(s->cursor); | ||
1046 | + s->cursor = NULL; | ||
1047 | + } | ||
1048 | + | ||
1049 | + if (bpp == 32) { /* Shouldn't be anything else, but just to be safe...*/ | ||
1050 | + s->cursor = cursor_alloc(width, height); | ||
1051 | + s->cursor->hot_x = hotSpot.x; | ||
1052 | + s->cursor->hot_y = hotSpot.y; | ||
1053 | + | ||
1054 | + uint32_t *dest_px = s->cursor->data; | ||
1055 | + | ||
1056 | + for (size_t y = 0; y < height; ++y) { | ||
1057 | + for (size_t x = 0; x < width; ++x) { | ||
1058 | + /* NSBitmapImageRep's red & blue channels are swapped | ||
1059 | + * compared to QEMUCursor's. */ | ||
1060 | + *dest_px = | ||
1061 | + (px_data[0] << 16u) | | ||
1062 | + (px_data[1] << 8u) | | ||
1063 | + (px_data[2] << 0u) | | ||
1064 | + (px_data[3] << 24u); | ||
1065 | + ++dest_px; | ||
1066 | + px_data += 4; | ||
1067 | + } | ||
1068 | + px_data += padding_bytes_per_row; | ||
1069 | + } | ||
1070 | + dpy_cursor_define(s->con, s->cursor); | ||
1071 | + update_cursor(s); | ||
1072 | + } | ||
1073 | + [glyph release]; | ||
1074 | + }); | ||
1075 | + }; | 1238 | + }; |
1076 | + disp_desc.cursorShowHandler = ^(BOOL show) { | 1239 | + disp_desc.cursorShowHandler = ^(BOOL show) { |
1077 | + dispatch_async(get_background_queue(), ^{ | 1240 | + trace_apple_gfx_cursor_show(show); |
1078 | + BQL_LOCK_GUARD(); | 1241 | + qatomic_set(&s->cursor_show, show); |
1079 | + trace_apple_gfx_cursor_show(show); | 1242 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), |
1080 | + s->cursor_show = show; | 1243 | + update_cursor_bh, s); |
1081 | + update_cursor(s); | ||
1082 | + }); | ||
1083 | + }; | 1244 | + }; |
1084 | + disp_desc.cursorMoveHandler = ^(void) { | 1245 | + disp_desc.cursorMoveHandler = ^(void) { |
1085 | + dispatch_async(get_background_queue(), ^{ | 1246 | + trace_apple_gfx_cursor_move(); |
1086 | + BQL_LOCK_GUARD(); | 1247 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), |
1087 | + trace_apple_gfx_cursor_move(); | 1248 | + update_cursor_bh, s); |
1088 | + update_cursor(s); | ||
1089 | + }); | ||
1090 | + }; | 1249 | + }; |
1091 | + | 1250 | + |
1092 | + return disp_desc; | 1251 | + return disp_desc; |
1093 | +} | 1252 | +} |
1094 | + | 1253 | + |
1095 | +static NSArray<PGDisplayMode*>* apple_gfx_prepare_display_mode_array(void) | 1254 | +static NSArray<PGDisplayMode*>* apple_gfx_prepare_display_mode_array(void) |
1096 | +{ | 1255 | +{ |
1097 | + PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; | 1256 | + PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; |
1098 | + NSArray<PGDisplayMode*>* mode_array = nil; | 1257 | + NSArray<PGDisplayMode*>* mode_array; |
1099 | + int i; | 1258 | + int i; |
1100 | + | 1259 | + |
1101 | + for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { | 1260 | + for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { |
1102 | + modes[i] = | 1261 | + modes[i] = |
1103 | + [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i] refreshRateInHz:60.]; | 1262 | + [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i] refreshRateInHz:60.]; |
... | ... | ||
1137 | + [devs release]; | 1296 | + [devs release]; |
1138 | + | 1297 | + |
1139 | + return dev; | 1298 | + return dev; |
1140 | +} | 1299 | +} |
1141 | + | 1300 | + |
1142 | +void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, | 1301 | +bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, |
1143 | + Error **errp) | 1302 | + PGDeviceDescriptor *desc, Error **errp) |
1144 | +{ | 1303 | +{ |
1145 | + PGDisplayDescriptor *disp_desc = nil; | 1304 | + PGDisplayDescriptor *disp_desc; |
1146 | + | 1305 | + |
1147 | + if (apple_gfx_mig_blocker == NULL) { | 1306 | + if (apple_gfx_mig_blocker == NULL) { |
1148 | + error_setg(&apple_gfx_mig_blocker, | 1307 | + error_setg(&apple_gfx_mig_blocker, |
1149 | + "Migration state blocked by apple-gfx display device"); | 1308 | + "Migration state blocked by apple-gfx display device"); |
1150 | + if (migrate_add_blocker(&apple_gfx_mig_blocker, errp) < 0) { | 1309 | + if (migrate_add_blocker(&apple_gfx_mig_blocker, errp) < 0) { |
1151 | + return; | 1310 | + return false; |
1152 | + } | 1311 | + } |
1153 | + } | 1312 | + } |
1154 | + | 1313 | + |
1314 | + qemu_mutex_init(&s->task_mutex); | ||
1155 | + QTAILQ_INIT(&s->tasks); | 1315 | + QTAILQ_INIT(&s->tasks); |
1156 | + s->render_queue = dispatch_queue_create("apple-gfx.render", | ||
1157 | + DISPATCH_QUEUE_SERIAL); | ||
1158 | + s->mtl = copy_suitable_metal_device(); | 1316 | + s->mtl = copy_suitable_metal_device(); |
1159 | + s->mtl_queue = [s->mtl newCommandQueue]; | 1317 | + s->mtl_queue = [s->mtl newCommandQueue]; |
1160 | + | 1318 | + |
1161 | + desc.device = s->mtl; | 1319 | + desc.device = s->mtl; |
1162 | + | 1320 | + |
1163 | + apple_gfx_register_task_mapping_handlers(s, desc); | 1321 | + apple_gfx_register_task_mapping_handlers(s, desc); |
1164 | + | 1322 | + |
1323 | + s->cursor_show = true; | ||
1324 | + | ||
1165 | + s->pgdev = PGNewDeviceWithDescriptor(desc); | 1325 | + s->pgdev = PGNewDeviceWithDescriptor(desc); |
1166 | + | 1326 | + |
1167 | + disp_desc = apple_gfx_prepare_display_descriptor(s); | 1327 | + disp_desc = apple_gfx_prepare_display_descriptor(s); |
1328 | + /* | ||
1329 | + * Although the framework does, this integration currently does not support | ||
1330 | + * multiple virtual displays connected to a single PV graphics device. | ||
1331 | + * It is however possible to create | ||
1332 | + * more than one instance of the device, each with one display. The macOS | ||
1333 | + * guest will ignore these displays if they share the same serial number, | ||
1334 | + * so ensure each instance gets a unique one. | ||
1335 | + */ | ||
1168 | + s->pgdisp = [s->pgdev newDisplayWithDescriptor:disp_desc | 1336 | + s->pgdisp = [s->pgdev newDisplayWithDescriptor:disp_desc |
1169 | + port:0 serialNum:1234]; | 1337 | + port:0 |
1338 | + serialNum:next_pgdisplay_serial_num++]; | ||
1170 | + [disp_desc release]; | 1339 | + [disp_desc release]; |
1171 | + s->pgdisp.modeList = apple_gfx_prepare_display_mode_array(); | 1340 | + s->pgdisp.modeList = apple_gfx_prepare_display_mode_array(); |
1172 | + | 1341 | + |
1173 | + create_fb(s); | 1342 | + s->con = graphic_console_init(dev, 0, &apple_gfx_fb_ops, s); |
1174 | + | 1343 | + return true; |
1175 | + qemu_mutex_init(&s->job_mutex); | ||
1176 | + qemu_cond_init(&s->job_cond); | ||
1177 | +} | 1344 | +} |
1178 | diff --git a/hw/display/meson.build b/hw/display/meson.build | 1345 | diff --git a/hw/display/meson.build b/hw/display/meson.build |
1179 | index XXXXXXX..XXXXXXX 100644 | 1346 | index XXXXXXX..XXXXXXX 100644 |
1180 | --- a/hw/display/meson.build | 1347 | --- a/hw/display/meson.build |
1181 | +++ b/hw/display/meson.build | 1348 | +++ b/hw/display/meson.build |
1182 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('artist.c')) | 1349 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_ARTIST', if_true: files('artist.c')) |
1183 | 1350 | ||
1184 | system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c', 'ati_dbg.c'), pixman]) | 1351 | system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c', 'ati_dbg.c'), pixman]) |
1185 | 1352 | ||
1186 | +system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m'), pvg, metal]) | 1353 | +if host_os == 'darwin' |
1187 | +if cpu == 'aarch64' | 1354 | + system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m'), pvg, metal]) |
1188 | + system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-mmio.m'), pvg, metal]) | 1355 | + if cpu == 'aarch64' |
1356 | + system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-mmio.m'), pvg, metal]) | ||
1357 | + endif | ||
1189 | +endif | 1358 | +endif |
1190 | 1359 | ||
1191 | if config_all_devices.has_key('CONFIG_VIRTIO_GPU') | 1360 | if config_all_devices.has_key('CONFIG_VIRTIO_GPU') |
1192 | virtio_gpu_ss = ss.source_set() | 1361 | virtio_gpu_ss = ss.source_set() |
1193 | diff --git a/hw/display/trace-events b/hw/display/trace-events | 1362 | diff --git a/hw/display/trace-events b/hw/display/trace-events |
... | ... | ||
1201 | + | 1370 | + |
1202 | +# apple-gfx.m | 1371 | +# apple-gfx.m |
1203 | +apple_gfx_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 | 1372 | +apple_gfx_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 |
1204 | +apple_gfx_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 | 1373 | +apple_gfx_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 |
1205 | +apple_gfx_create_task(uint32_t vm_size, void *va) "vm_size=0x%x base_addr=%p" | 1374 | +apple_gfx_create_task(uint32_t vm_size, void *va) "vm_size=0x%x base_addr=%p" |
1206 | +apple_gfx_destroy_task(void *task) "task=%p" | 1375 | +apple_gfx_destroy_task(void *task, unsigned int num_mapped_regions) "task=%p, task->mapped_regions->len=%u" |
1207 | +apple_gfx_map_memory(void *task, uint32_t range_count, uint64_t virtual_offset, uint32_t read_only) "task=%p range_count=0x%x virtual_offset=0x%"PRIx64" read_only=%d" | 1376 | +apple_gfx_map_memory(void *task, uint32_t range_count, uint64_t virtual_offset, uint32_t read_only) "task=%p range_count=0x%x virtual_offset=0x%"PRIx64" read_only=%d" |
1208 | +apple_gfx_map_memory_range(uint32_t i, uint64_t phys_addr, uint64_t phys_len) "[%d] phys_addr=0x%"PRIx64" phys_len=0x%"PRIx64 | 1377 | +apple_gfx_map_memory_range(uint32_t i, uint64_t phys_addr, uint64_t phys_len) "[%d] phys_addr=0x%"PRIx64" phys_len=0x%"PRIx64 |
1209 | +apple_gfx_remap(uint64_t retval, uint64_t source, uint64_t target) "retval=%"PRId64" source=0x%"PRIx64" target=0x%"PRIx64 | 1378 | +apple_gfx_remap(uint64_t retval, void *source_ptr, uint64_t target) "retval=%"PRId64" source=%p target=0x%"PRIx64 |
1210 | +apple_gfx_unmap_memory(void *task, uint64_t virtual_offset, uint64_t length) "task=%p virtual_offset=0x%"PRIx64" length=0x%"PRIx64 | 1379 | +apple_gfx_unmap_memory(void *task, uint64_t virtual_offset, uint64_t length) "task=%p virtual_offset=0x%"PRIx64" length=0x%"PRIx64 |
1211 | +apple_gfx_read_memory(uint64_t phys_address, uint64_t length, void *dst) "phys_addr=0x%"PRIx64" length=0x%"PRIx64" dest=%p" | 1380 | +apple_gfx_read_memory(uint64_t phys_address, uint64_t length, void *dst) "phys_addr=0x%"PRIx64" length=0x%"PRIx64" dest=%p" |
1212 | +apple_gfx_raise_irq(uint32_t vector) "vector=0x%x" | 1381 | +apple_gfx_raise_irq(uint32_t vector) "vector=0x%x" |
1213 | +apple_gfx_new_frame(void) "" | 1382 | +apple_gfx_new_frame(void) "" |
1214 | +apple_gfx_mode_change(uint64_t x, uint64_t y) "x=%"PRId64" y=%"PRId64 | 1383 | +apple_gfx_mode_change(uint64_t x, uint64_t y) "x=%"PRId64" y=%"PRId64 |
... | ... | ||
1218 | +apple_gfx_common_init(const char *device_name, size_t mmio_size) "device: %s; MMIO size: %zu bytes" | 1387 | +apple_gfx_common_init(const char *device_name, size_t mmio_size) "device: %s; MMIO size: %zu bytes" |
1219 | + | 1388 | + |
1220 | +# apple-gfx-mmio.m | 1389 | +# apple-gfx-mmio.m |
1221 | +apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 | 1390 | +apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 |
1222 | +apple_gfx_mmio_iosfc_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 | 1391 | +apple_gfx_mmio_iosfc_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 |
1223 | +apple_gfx_iosfc_map_memory(uint64_t phys, uint64_t len, uint32_t ro, void *va, void *e, void *f, void* va_result, int success) "phys=0x%"PRIx64" len=0x%"PRIx64" ro=%d va=%p e=%p f=%p -> *va=%p, success = %d" | 1392 | +apple_gfx_iosfc_map_memory(uint64_t phys, uint64_t len, uint32_t ro, void *va, void *e, void *f, void* va_result) "phys=0x%"PRIx64" len=0x%"PRIx64" ro=%d va=%p e=%p f=%p -> *va=%p" |
1393 | +apple_gfx_iosfc_map_memory_new_region(size_t i, void *region, uint64_t start, uint64_t end) "index=%zu, region=%p, 0x%"PRIx64"-0x%"PRIx64 | ||
1224 | +apple_gfx_iosfc_unmap_memory(void *a, void *b, void *c, void *d, void *e, void *f) "a=%p b=%p c=%p d=%p e=%p f=%p" | 1394 | +apple_gfx_iosfc_unmap_memory(void *a, void *b, void *c, void *d, void *e, void *f) "a=%p b=%p c=%p d=%p e=%p f=%p" |
1395 | +apple_gfx_iosfc_unmap_memory_region(void* mem, void *region) "unmapping @ %p from memory region %p" | ||
1225 | +apple_gfx_iosfc_raise_irq(uint32_t vector) "vector=0x%x" | 1396 | +apple_gfx_iosfc_raise_irq(uint32_t vector) "vector=0x%x" |
1226 | + | 1397 | + |
1227 | diff --git a/meson.build b/meson.build | 1398 | diff --git a/meson.build b/meson.build |
1228 | index XXXXXXX..XXXXXXX 100644 | 1399 | index XXXXXXX..XXXXXXX 100644 |
1229 | --- a/meson.build | 1400 | --- a/meson.build |
1230 | +++ b/meson.build | 1401 | +++ b/meson.build |
1231 | @@ -XXX,XX +XXX,XX @@ socket = [] | 1402 | @@ -XXX,XX +XXX,XX @@ socket = [] |
1232 | version_res = [] | 1403 | version_res = [] |
1233 | coref = [] | 1404 | coref = [] |
1234 | iokit = [] | 1405 | iokit = [] |
1235 | +pvg = [] | 1406 | +pvg = not_found |
1236 | +metal = [] | 1407 | +metal = [] |
1237 | emulator_link_args = [] | 1408 | emulator_link_args = [] |
1238 | midl = not_found | 1409 | midl = not_found |
1239 | widl = not_found | 1410 | widl = not_found |
1240 | @@ -XXX,XX +XXX,XX @@ elif host_os == 'darwin' | 1411 | @@ -XXX,XX +XXX,XX @@ elif host_os == 'darwin' |
... | ... | ||
1245 | + metal = dependency('appleframeworks', modules: 'Metal') | 1416 | + metal = dependency('appleframeworks', modules: 'Metal') |
1246 | elif host_os == 'sunos' | 1417 | elif host_os == 'sunos' |
1247 | socket = [cc.find_library('socket'), | 1418 | socket = [cc.find_library('socket'), |
1248 | cc.find_library('nsl'), | 1419 | cc.find_library('nsl'), |
1249 | -- | 1420 | -- |
1250 | 2.39.3 (Apple Git-145) | 1421 | 2.39.5 (Apple Git-154) |
1251 | 1422 | ||
1252 | 1423 | diff view generated by jsdifflib |
1 | This change wires up the PCI variant of the paravirtualised | 1 | This change wires up the PCI variant of the paravirtualised |
---|---|---|---|
2 | graphics device, mainly useful for x86-64 macOS guests, implemented | 2 | graphics device, mainly useful for x86-64 macOS guests, implemented |
3 | by macOS's ParavirtualizedGraphics.framework. It builds on code | 3 | by macOS's ParavirtualizedGraphics.framework. It builds on code |
4 | shared with the vmapple/mmio variant of the PVG device. | 4 | shared with the vmapple/mmio variant of the PVG device. |
5 | 5 | ||
6 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 6 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
7 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
7 | --- | 8 | --- |
8 | 9 | ||
9 | v4: | 10 | v4: |
10 | 11 | ||
11 | * Threading improvements analogous to those in common apple-gfx code | 12 | * Threading improvements analogous to those in common apple-gfx code |
12 | and mmio device variant. | 13 | and mmio device variant. |
13 | * Smaller code review issues addressed. | 14 | * Smaller code review issues addressed. |
14 | 15 | ||
16 | v5: | ||
17 | |||
18 | * Minor error handling improvement. | ||
19 | |||
20 | v6: | ||
21 | |||
22 | * Removed an unused function parameter. | ||
23 | |||
24 | v9: | ||
25 | |||
26 | * Fixup of changed common call. | ||
27 | * Whitespace and comment formatting tweaks. | ||
28 | |||
29 | v11: | ||
30 | |||
31 | * Comment formatting fix. | ||
32 | |||
15 | hw/display/Kconfig | 4 + | 33 | hw/display/Kconfig | 4 + |
16 | hw/display/apple-gfx-pci.m | 152 +++++++++++++++++++++++++++++++++++++ | 34 | hw/display/apple-gfx-pci.m | 150 +++++++++++++++++++++++++++++++++++++ |
17 | hw/display/meson.build | 1 + | 35 | hw/display/meson.build | 1 + |
18 | 3 files changed, 157 insertions(+) | 36 | 3 files changed, 155 insertions(+) |
19 | create mode 100644 hw/display/apple-gfx-pci.m | 37 | create mode 100644 hw/display/apple-gfx-pci.m |
20 | 38 | ||
21 | diff --git a/hw/display/Kconfig b/hw/display/Kconfig | 39 | diff --git a/hw/display/Kconfig b/hw/display/Kconfig |
22 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/display/Kconfig | 41 | --- a/hw/display/Kconfig |
... | ... | ||
78 | +static void apple_gfx_pci_init(Object *obj) | 96 | +static void apple_gfx_pci_init(Object *obj) |
79 | +{ | 97 | +{ |
80 | + AppleGFXPCIState *s = APPLE_GFX_PCI(obj); | 98 | + AppleGFXPCIState *s = APPLE_GFX_PCI(obj); |
81 | + | 99 | + |
82 | + if (!apple_gfx_pci_option_rom_path) { | 100 | + if (!apple_gfx_pci_option_rom_path) { |
83 | + /* The following is done on device not class init to avoid running | 101 | + /* |
84 | + * ObjC code before fork() in -daemonize mode. */ | 102 | + * The following is done on device not class init to avoid running |
103 | + * ObjC code before fork() in -daemonize mode. | ||
104 | + */ | ||
85 | + PCIDeviceClass *pci = PCI_DEVICE_CLASS(object_get_class(obj)); | 105 | + PCIDeviceClass *pci = PCI_DEVICE_CLASS(object_get_class(obj)); |
86 | + apple_gfx_init_option_rom_path(); | 106 | + apple_gfx_init_option_rom_path(); |
87 | + pci->romfile = apple_gfx_pci_option_rom_path; | 107 | + pci->romfile = apple_gfx_pci_option_rom_path; |
88 | + } | 108 | + } |
89 | + | 109 | + |
... | ... | ||
103 | + msi_notify(job->device, job->vector); | 123 | + msi_notify(job->device, job->vector); |
104 | + } | 124 | + } |
105 | + g_free(job); | 125 | + g_free(job); |
106 | +} | 126 | +} |
107 | + | 127 | + |
108 | +static void apple_gfx_pci_interrupt(PCIDevice *dev, AppleGFXPCIState *s, | 128 | +static void apple_gfx_pci_interrupt(PCIDevice *dev, uint32_t vector) |
109 | + uint32_t vector) | ||
110 | +{ | 129 | +{ |
111 | + AppleGFXPCIInterruptJob *job; | 130 | + AppleGFXPCIInterruptJob *job; |
112 | + | 131 | + |
113 | + trace_apple_gfx_raise_irq(vector); | 132 | + trace_apple_gfx_raise_irq(vector); |
114 | + job = g_malloc0(sizeof(*job)); | 133 | + job = g_malloc0(sizeof(*job)); |
... | ... | ||
119 | +} | 138 | +} |
120 | + | 139 | + |
121 | +static void apple_gfx_pci_realize(PCIDevice *dev, Error **errp) | 140 | +static void apple_gfx_pci_realize(PCIDevice *dev, Error **errp) |
122 | +{ | 141 | +{ |
123 | + AppleGFXPCIState *s = APPLE_GFX_PCI(dev); | 142 | + AppleGFXPCIState *s = APPLE_GFX_PCI(dev); |
124 | + Error *err = NULL; | ||
125 | + int ret; | 143 | + int ret; |
126 | + | 144 | + |
127 | + pci_register_bar(dev, PG_PCI_BAR_MMIO, | 145 | + pci_register_bar(dev, PG_PCI_BAR_MMIO, |
128 | + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->common.iomem_gfx); | 146 | + PCI_BASE_ADDRESS_SPACE_MEMORY, &s->common.iomem_gfx); |
129 | + | 147 | + |
130 | + ret = msi_init(dev, 0x0 /* config offset; 0 = find space */, | 148 | + ret = msi_init(dev, 0x0 /* config offset; 0 = find space */, |
131 | + PG_PCI_MAX_MSI_VECTORS, true /* msi64bit */, | 149 | + PG_PCI_MAX_MSI_VECTORS, true /* msi64bit */, |
132 | + false /*msi_per_vector_mask*/, &err); | 150 | + false /* msi_per_vector_mask */, errp); |
133 | + if (ret != 0) { | 151 | + if (ret != 0) { |
134 | + error_propagate(errp, err); | ||
135 | + return; | 152 | + return; |
136 | + } | 153 | + } |
137 | + | 154 | + |
138 | + @autoreleasepool { | 155 | + @autoreleasepool { |
139 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; | 156 | + PGDeviceDescriptor *desc = [PGDeviceDescriptor new]; |
140 | + desc.raiseInterrupt = ^(uint32_t vector) { | 157 | + desc.raiseInterrupt = ^(uint32_t vector) { |
141 | + apple_gfx_pci_interrupt(dev, s, vector); | 158 | + apple_gfx_pci_interrupt(dev, vector); |
142 | + }; | 159 | + }; |
143 | + | 160 | + |
144 | + apple_gfx_common_realize(&s->common, desc, errp); | 161 | + apple_gfx_common_realize(&s->common, DEVICE(dev), desc, errp); |
145 | + [desc release]; | 162 | + [desc release]; |
146 | + desc = nil; | 163 | + desc = nil; |
147 | + } | 164 | + } |
148 | +} | 165 | +} |
149 | + | 166 | + |
... | ... | ||
157 | +{ | 174 | +{ |
158 | + DeviceClass *dc = DEVICE_CLASS(klass); | 175 | + DeviceClass *dc = DEVICE_CLASS(klass); |
159 | + PCIDeviceClass *pci = PCI_DEVICE_CLASS(klass); | 176 | + PCIDeviceClass *pci = PCI_DEVICE_CLASS(klass); |
160 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | 177 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
161 | + | 178 | + |
162 | + assert(rc->phases.hold == NULL); | ||
163 | + rc->phases.hold = apple_gfx_pci_reset; | 179 | + rc->phases.hold = apple_gfx_pci_reset; |
164 | + dc->desc = "macOS Paravirtualized Graphics PCI Display Controller"; | 180 | + dc->desc = "macOS Paravirtualized Graphics PCI Display Controller"; |
165 | + dc->hotpluggable = false; | 181 | + dc->hotpluggable = false; |
166 | + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | 182 | + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); |
167 | + | 183 | + |
168 | + pci->vendor_id = PG_PCI_VENDOR_ID; | 184 | + pci->vendor_id = PG_PCI_VENDOR_ID; |
169 | + pci->device_id = PG_PCI_DEVICE_ID; | 185 | + pci->device_id = PG_PCI_DEVICE_ID; |
170 | + pci->class_id = PCI_CLASS_DISPLAY_OTHER; | 186 | + pci->class_id = PCI_CLASS_DISPLAY_OTHER; |
171 | + pci->realize = apple_gfx_pci_realize; | 187 | + pci->realize = apple_gfx_pci_realize; |
172 | + | 188 | + |
173 | + // TODO: Property for setting mode list | 189 | + /* TODO: Property for setting mode list */ |
174 | +} | 190 | +} |
175 | + | 191 | + |
176 | +static TypeInfo apple_gfx_pci_types[] = { | 192 | +static TypeInfo apple_gfx_pci_types[] = { |
177 | + { | 193 | + { |
178 | + .name = TYPE_APPLE_GFX_PCI, | 194 | + .name = TYPE_APPLE_GFX_PCI, |
... | ... | ||
190 | + | 206 | + |
191 | diff --git a/hw/display/meson.build b/hw/display/meson.build | 207 | diff --git a/hw/display/meson.build b/hw/display/meson.build |
192 | index XXXXXXX..XXXXXXX 100644 | 208 | index XXXXXXX..XXXXXXX 100644 |
193 | --- a/hw/display/meson.build | 209 | --- a/hw/display/meson.build |
194 | +++ b/hw/display/meson.build | 210 | +++ b/hw/display/meson.build |
195 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m'), pv | 211 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_ATI_VGA', if_true: [files('ati.c', 'ati_2d.c', 'ati_ |
196 | if cpu == 'aarch64' | 212 | |
197 | system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-mmio.m'), pvg, metal]) | 213 | if host_os == 'darwin' |
198 | endif | 214 | system_ss.add(when: 'CONFIG_MAC_PVG', if_true: [files('apple-gfx.m'), pvg, metal]) |
199 | +system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx-pci.m'), pvg, metal]) | 215 | + system_ss.add(when: 'CONFIG_MAC_PVG_PCI', if_true: [files('apple-gfx-pci.m'), pvg, metal]) |
200 | 216 | if cpu == 'aarch64' | |
201 | if config_all_devices.has_key('CONFIG_VIRTIO_GPU') | 217 | system_ss.add(when: 'CONFIG_MAC_PVG_MMIO', if_true: [files('apple-gfx-mmio.m'), pvg, metal]) |
202 | virtio_gpu_ss = ss.source_set() | 218 | endif |
203 | -- | 219 | -- |
204 | 2.39.3 (Apple Git-145) | 220 | 2.39.5 (Apple Git-154) |
205 | 221 | ||
206 | 222 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
6 | less awkward to use, for example: | 6 | less awkward to use, for example: |
7 | 7 | ||
8 | -device '{"driver":"apple-gfx-pci", "display-modes":["1920x1080@60", "3840x2160@60"]}' | 8 | -device '{"driver":"apple-gfx-pci", "display-modes":["1920x1080@60", "3840x2160@60"]}' |
9 | 9 | ||
10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
11 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
12 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
11 | --- | 13 | --- |
12 | 14 | ||
13 | v4: | 15 | v4: |
14 | 16 | ||
15 | * Switched to the native array property type, which recently gained | 17 | * Switched to the native array property type, which recently gained |
16 | command line support. | 18 | command line support. |
17 | * The property has also been added to the -mmio variant. | 19 | * The property has also been added to the -mmio variant. |
18 | * Tidied up the code a little. | 20 | * Tidied up the code a little. |
19 | 21 | ||
22 | v5: | ||
23 | |||
24 | * Better error handling and buffer management in property parsing and | ||
25 | output. | ||
26 | |||
27 | v6: | ||
28 | |||
29 | * Switched to using NSMutableArray for the mode list to avoid need for | ||
30 | allocating a temporary array - previously done with alloca. | ||
31 | |||
32 | v7: | ||
33 | |||
34 | * Simplified error handling in property parsing | ||
35 | |||
36 | v8: | ||
37 | |||
38 | * More consistent integer variable types. | ||
39 | |||
40 | v9: | ||
41 | |||
42 | * Re-ordered type definitions so we can drop a 'struct' keyword. | ||
43 | |||
20 | hw/display/apple-gfx-mmio.m | 8 +++ | 44 | hw/display/apple-gfx-mmio.m | 8 +++ |
21 | hw/display/apple-gfx-pci.m | 9 ++- | 45 | hw/display/apple-gfx-pci.m | 9 ++- |
22 | hw/display/apple-gfx.h | 12 ++++ | 46 | hw/display/apple-gfx.h | 11 +++ |
23 | hw/display/apple-gfx.m | 127 ++++++++++++++++++++++++++++++++---- | 47 | hw/display/apple-gfx.m | 135 +++++++++++++++++++++++++++++++----- |
24 | hw/display/trace-events | 2 + | 48 | hw/display/trace-events | 2 + |
25 | 5 files changed, 145 insertions(+), 13 deletions(-) | 49 | 5 files changed, 145 insertions(+), 20 deletions(-) |
26 | 50 | ||
27 | diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m | 51 | diff --git a/hw/display/apple-gfx-mmio.m b/hw/display/apple-gfx-mmio.m |
28 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/hw/display/apple-gfx-mmio.m | 53 | --- a/hw/display/apple-gfx-mmio.m |
30 | +++ b/hw/display/apple-gfx-mmio.m | 54 | +++ b/hw/display/apple-gfx-mmio.m |
... | ... | ||
70 | DeviceClass *dc = DEVICE_CLASS(klass); | 94 | DeviceClass *dc = DEVICE_CLASS(klass); |
71 | @@ -XXX,XX +XXX,XX @@ static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) | 95 | @@ -XXX,XX +XXX,XX @@ static void apple_gfx_pci_class_init(ObjectClass *klass, void *data) |
72 | pci->class_id = PCI_CLASS_DISPLAY_OTHER; | 96 | pci->class_id = PCI_CLASS_DISPLAY_OTHER; |
73 | pci->realize = apple_gfx_pci_realize; | 97 | pci->realize = apple_gfx_pci_realize; |
74 | 98 | ||
75 | - // TODO: Property for setting mode list | 99 | - /* TODO: Property for setting mode list */ |
76 | + device_class_set_props(dc, apple_gfx_pci_properties); | 100 | + device_class_set_props(dc, apple_gfx_pci_properties); |
77 | } | 101 | } |
78 | 102 | ||
79 | static TypeInfo apple_gfx_pci_types[] = { | 103 | static TypeInfo apple_gfx_pci_types[] = { |
80 | diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h | 104 | diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h |
... | ... | ||
90 | 114 | ||
91 | @class PGDeviceDescriptor; | 115 | @class PGDeviceDescriptor; |
92 | @@ -XXX,XX +XXX,XX @@ | 116 | @@ -XXX,XX +XXX,XX @@ |
93 | 117 | ||
94 | typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; | 118 | typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; |
95 | |||
96 | +struct AppleGFXDisplayMode; | ||
97 | struct AppleGFXMapMemoryJob; | ||
98 | typedef struct AppleGFXState { | ||
99 | MemoryRegion iomem_gfx; | ||
100 | @@ -XXX,XX +XXX,XX @@ typedef struct AppleGFXState { | ||
101 | id<MTLCommandQueue> mtl_queue; | ||
102 | bool cursor_show; | ||
103 | QEMUCursor *cursor; | ||
104 | + struct AppleGFXDisplayMode *display_modes; | ||
105 | + uint32_t num_display_modes; | ||
106 | |||
107 | /* For running PVG memory-mapping requests in the AIO context */ | ||
108 | QemuCond job_cond; | ||
109 | @@ -XXX,XX +XXX,XX @@ typedef struct AppleGFXState { | ||
110 | id<MTLTexture> texture; | ||
111 | } AppleGFXState; | ||
112 | 119 | ||
113 | +typedef struct AppleGFXDisplayMode { | 120 | +typedef struct AppleGFXDisplayMode { |
114 | + uint16_t width_px; | 121 | + uint16_t width_px; |
115 | + uint16_t height_px; | 122 | + uint16_t height_px; |
116 | + uint16_t refresh_rate_hz; | 123 | + uint16_t refresh_rate_hz; |
117 | +} AppleGFXDisplayMode; | 124 | +} AppleGFXDisplayMode; |
118 | + | 125 | + |
119 | void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name); | 126 | typedef struct AppleGFXState { |
120 | void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, | 127 | /* Initialised on init/realize() */ |
121 | Error **errp); | 128 | MemoryRegion iomem_gfx; |
122 | @@ -XXX,XX +XXX,XX @@ uintptr_t apple_gfx_host_address_for_gpa_range(uint64_t guest_physical, | 129 | @@ -XXX,XX +XXX,XX @@ typedef struct AppleGFXState { |
123 | uint64_t length, bool read_only); | 130 | QemuConsole *con; |
124 | void apple_gfx_await_bh_job(AppleGFXState *s, bool *job_done_flag); | 131 | id<MTLDevice> mtl; |
132 | id<MTLCommandQueue> mtl_queue; | ||
133 | + AppleGFXDisplayMode *display_modes; | ||
134 | + uint32_t num_display_modes; | ||
135 | |||
136 | /* List `tasks` is protected by task_mutex */ | ||
137 | QemuMutex task_mutex; | ||
138 | @@ -XXX,XX +XXX,XX @@ void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical, | ||
139 | uint64_t length, bool read_only, | ||
140 | MemoryRegion **mapping_in_region); | ||
125 | 141 | ||
126 | +extern const PropertyInfo qdev_prop_display_mode; | 142 | +extern const PropertyInfo qdev_prop_display_mode; |
127 | + | 143 | + |
128 | #endif | 144 | #endif |
129 | 145 | ||
130 | diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m | 146 | diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m |
131 | index XXXXXXX..XXXXXXX 100644 | 147 | index XXXXXXX..XXXXXXX 100644 |
132 | --- a/hw/display/apple-gfx.m | 148 | --- a/hw/display/apple-gfx.m |
133 | +++ b/hw/display/apple-gfx.m | 149 | +++ b/hw/display/apple-gfx.m |
134 | @@ -XXX,XX +XXX,XX @@ | 150 | @@ -XXX,XX +XXX,XX @@ |
135 | #include "qapi/error.h" | 151 | #include "sysemu/dma.h" |
136 | #include "ui/console.h" | 152 | #include "ui/console.h" |
137 | 153 | ||
138 | -static const PGDisplayCoord_t apple_gfx_modes[] = { | 154 | -static const PGDisplayCoord_t apple_gfx_modes[] = { |
139 | - { .x = 1440, .y = 1080 }, | 155 | - { .x = 1440, .y = 1080 }, |
140 | - { .x = 1280, .y = 1024 }, | 156 | - { .x = 1280, .y = 1024 }, |
141 | +static const AppleGFXDisplayMode apple_gfx_default_modes[] = { | 157 | +static const AppleGFXDisplayMode apple_gfx_default_modes[] = { |
142 | + { 1920, 1080, 60 }, | 158 | + { 1920, 1080, 60 }, |
143 | + { 1440, 1080, 60 }, | 159 | + { 1440, 1080, 60 }, |
144 | + { 1280, 1024, 60 }, | 160 | + { 1280, 1024, 60 }, |
145 | }; | 161 | }; |
146 | 162 | ||
147 | /* This implements a type defined in <ParavirtualizedGraphics/PGDevice.h> | 163 | static Error *apple_gfx_mig_blocker; |
148 | @@ -XXX,XX +XXX,XX @@ static void set_mode(AppleGFXState *s, uint32_t width, uint32_t height) | 164 | @@ -XXX,XX +XXX,XX @@ static void new_frame_handler_bh(void *opaque) |
149 | static void create_fb(AppleGFXState *s) | ||
150 | { | ||
151 | s->con = graphic_console_init(NULL, 0, &apple_gfx_fb_ops, s); | ||
152 | - set_mode(s, 1440, 1080); | ||
153 | |||
154 | s->cursor_show = true; | ||
155 | } | ||
156 | @@ -XXX,XX +XXX,XX @@ static void apple_gfx_register_task_mapping_handlers(AppleGFXState *s, | ||
157 | return disp_desc; | 165 | return disp_desc; |
158 | } | 166 | } |
159 | 167 | ||
160 | -static NSArray<PGDisplayMode*>* apple_gfx_prepare_display_mode_array(void) | 168 | -static NSArray<PGDisplayMode*>* apple_gfx_prepare_display_mode_array(void) |
161 | +static NSArray<PGDisplayMode*>* apple_gfx_create_display_mode_array( | 169 | +static NSArray<PGDisplayMode *> *apple_gfx_create_display_mode_array( |
162 | + const AppleGFXDisplayMode display_modes[], uint32_t display_mode_count) | 170 | + const AppleGFXDisplayMode display_modes[], uint32_t display_mode_count) |
163 | { | 171 | { |
164 | - PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; | 172 | - PGDisplayMode *modes[ARRAY_SIZE(apple_gfx_modes)]; |
165 | + PGDisplayMode **modes = alloca(sizeof(modes[0]) * display_mode_count); | 173 | - NSArray<PGDisplayMode*>* mode_array; |
166 | NSArray<PGDisplayMode*>* mode_array = nil; | ||
167 | - int i; | 174 | - int i; |
175 | - | ||
176 | - for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { | ||
177 | - modes[i] = | ||
178 | - [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i] refreshRateInHz:60.]; | ||
179 | - } | ||
180 | - | ||
181 | - mode_array = [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_gfx_modes)]; | ||
182 | - | ||
183 | - for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { | ||
184 | - [modes[i] release]; | ||
185 | - modes[i] = nil; | ||
168 | + uint32_t i; | 186 | + uint32_t i; |
169 | 187 | + PGDisplayMode *mode_obj; | |
170 | - for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { | 188 | + NSMutableArray<PGDisplayMode *> *mode_array = |
189 | + [[NSMutableArray alloc] initWithCapacity:display_mode_count]; | ||
190 | + | ||
171 | + for (i = 0; i < display_mode_count; i++) { | 191 | + for (i = 0; i < display_mode_count; i++) { |
172 | + const AppleGFXDisplayMode *mode = &display_modes[i]; | 192 | + const AppleGFXDisplayMode *mode = &display_modes[i]; |
173 | + trace_apple_gfx_display_mode(i, mode->width_px, mode->height_px); | 193 | + trace_apple_gfx_display_mode(i, mode->width_px, mode->height_px); |
174 | + PGDisplayCoord_t mode_size = { mode->width_px, mode->height_px }; | 194 | + PGDisplayCoord_t mode_size = { mode->width_px, mode->height_px }; |
175 | modes[i] = | 195 | + |
176 | - [[PGDisplayMode alloc] initWithSizeInPixels:apple_gfx_modes[i] refreshRateInHz:60.]; | 196 | + mode_obj = |
177 | + [[PGDisplayMode alloc] initWithSizeInPixels:mode_size | 197 | + [[PGDisplayMode alloc] initWithSizeInPixels:mode_size |
178 | + refreshRateInHz:mode->refresh_rate_hz]; | 198 | + refreshRateInHz:mode->refresh_rate_hz]; |
199 | + [mode_array addObject:mode_obj]; | ||
200 | + [mode_obj release]; | ||
179 | } | 201 | } |
180 | 202 | ||
181 | - mode_array = [NSArray arrayWithObjects:modes count:ARRAY_SIZE(apple_gfx_modes)]; | 203 | return mode_array; |
182 | + mode_array = [NSArray arrayWithObjects:modes count:display_mode_count]; | 204 | @@ -XXX,XX +XXX,XX @@ bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, |
183 | 205 | PGDeviceDescriptor *desc, Error **errp) | |
184 | - for (i = 0; i < ARRAY_SIZE(apple_gfx_modes); i++) { | ||
185 | + for (i = 0; i < display_mode_count; i++) { | ||
186 | [modes[i] release]; | ||
187 | modes[i] = nil; | ||
188 | } | ||
189 | @@ -XXX,XX +XXX,XX @@ void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, | ||
190 | Error **errp) | ||
191 | { | 206 | { |
192 | PGDisplayDescriptor *disp_desc = nil; | 207 | PGDisplayDescriptor *disp_desc; |
193 | + const AppleGFXDisplayMode *display_modes = apple_gfx_default_modes; | 208 | + const AppleGFXDisplayMode *display_modes = apple_gfx_default_modes; |
194 | + int num_display_modes = ARRAY_SIZE(apple_gfx_default_modes); | 209 | + uint32_t num_display_modes = ARRAY_SIZE(apple_gfx_default_modes); |
210 | + NSArray<PGDisplayMode *> *mode_array; | ||
195 | 211 | ||
196 | if (apple_gfx_mig_blocker == NULL) { | 212 | if (apple_gfx_mig_blocker == NULL) { |
197 | error_setg(&apple_gfx_mig_blocker, | 213 | error_setg(&apple_gfx_mig_blocker, |
198 | @@ -XXX,XX +XXX,XX @@ void apple_gfx_common_realize(AppleGFXState *s, PGDeviceDescriptor *desc, | 214 | @@ -XXX,XX +XXX,XX @@ bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, |
199 | s->pgdisp = [s->pgdev newDisplayWithDescriptor:disp_desc | 215 | port:0 |
200 | port:0 serialNum:1234]; | 216 | serialNum:next_pgdisplay_serial_num++]; |
201 | [disp_desc release]; | 217 | [disp_desc release]; |
202 | - s->pgdisp.modeList = apple_gfx_prepare_display_mode_array(); | 218 | - s->pgdisp.modeList = apple_gfx_prepare_display_mode_array(); |
203 | + | 219 | + |
204 | + if (s->display_modes != NULL && s->num_display_modes > 0) { | 220 | + if (s->display_modes != NULL && s->num_display_modes > 0) { |
205 | + trace_apple_gfx_common_realize_modes_property(s->num_display_modes); | 221 | + trace_apple_gfx_common_realize_modes_property(s->num_display_modes); |
206 | + display_modes = s->display_modes; | 222 | + display_modes = s->display_modes; |
207 | + num_display_modes = s->num_display_modes; | 223 | + num_display_modes = s->num_display_modes; |
208 | + } | 224 | + } |
209 | + s->pgdisp.modeList = | 225 | + s->pgdisp.modeList = mode_array = |
210 | + apple_gfx_create_display_mode_array(display_modes, num_display_modes); | 226 | + apple_gfx_create_display_mode_array(display_modes, num_display_modes); |
211 | 227 | + [mode_array release]; | |
212 | create_fb(s); | 228 | |
213 | 229 | s->con = graphic_console_init(dev, 0, &apple_gfx_fb_ops, s); | |
214 | qemu_mutex_init(&s->job_mutex); | 230 | return true; |
215 | qemu_cond_init(&s->job_cond); | 231 | } |
216 | } | 232 | + |
233 | +/* ------ Display mode list device property ------ */ | ||
217 | + | 234 | + |
218 | +static void apple_gfx_get_display_mode(Object *obj, Visitor *v, | 235 | +static void apple_gfx_get_display_mode(Object *obj, Visitor *v, |
219 | + const char *name, void *opaque, | 236 | + const char *name, void *opaque, |
220 | + Error **errp) | 237 | + Error **errp) |
221 | +{ | 238 | +{ |
222 | + Property *prop = opaque; | 239 | + Property *prop = opaque; |
223 | + AppleGFXDisplayMode *mode = object_field_prop_ptr(obj, prop); | 240 | + AppleGFXDisplayMode *mode = object_field_prop_ptr(obj, prop); |
224 | + /* 3 uint16s (max 5 digits) and 2 separator characters + nul. */ | 241 | + /* 3 uint16s (max 5 digits) + 2 separator characters + nul. */ |
225 | + static const size_t buffer_size = 5 * 3 + 2 + 1; | 242 | + char buffer[5 * 3 + 2 + 1]; |
226 | + | ||
227 | + char buffer[buffer_size]; | ||
228 | + char *pos = buffer; | 243 | + char *pos = buffer; |
229 | + | 244 | + |
230 | + int rc = snprintf(buffer, buffer_size, | 245 | + int rc = snprintf(buffer, sizeof(buffer), |
231 | + "%"PRIu16"x%"PRIu16"@%"PRIu16, | 246 | + "%"PRIu16"x%"PRIu16"@%"PRIu16, |
232 | + mode->width_px, mode->height_px, | 247 | + mode->width_px, mode->height_px, |
233 | + mode->refresh_rate_hz); | 248 | + mode->refresh_rate_hz); |
234 | + assert(rc < buffer_size); | 249 | + assert(rc < sizeof(buffer)); |
235 | + | 250 | + |
236 | + visit_type_str(v, name, &pos, errp); | 251 | + visit_type_str(v, name, &pos, errp); |
237 | +} | 252 | +} |
238 | + | 253 | + |
239 | +static void apple_gfx_set_display_mode(Object *obj, Visitor *v, | 254 | +static void apple_gfx_set_display_mode(Object *obj, Visitor *v, |
240 | + const char *name, void *opaque, | 255 | + const char *name, void *opaque, |
241 | + Error **errp) | 256 | + Error **errp) |
242 | +{ | 257 | +{ |
243 | + Property *prop = opaque; | 258 | + Property *prop = opaque; |
244 | + AppleGFXDisplayMode *mode = object_field_prop_ptr(obj, prop); | 259 | + AppleGFXDisplayMode *mode = object_field_prop_ptr(obj, prop); |
245 | + Error *local_err = NULL; | ||
246 | + const char *endptr; | 260 | + const char *endptr; |
247 | + char *str; | 261 | + g_autofree char *str = NULL; |
248 | + int ret; | 262 | + int ret; |
249 | + unsigned int val; | 263 | + int val; |
250 | + | 264 | + |
251 | + visit_type_str(v, name, &str, &local_err); | 265 | + if (!visit_type_str(v, name, &str, errp)) { |
252 | + if (local_err) { | ||
253 | + error_propagate(errp, local_err); | ||
254 | + return; | 266 | + return; |
255 | + } | 267 | + } |
256 | + | 268 | + |
257 | + endptr = str; | 269 | + endptr = str; |
258 | + | 270 | + |
259 | + ret = qemu_strtoui(endptr, &endptr, 10, &val); | 271 | + ret = qemu_strtoi(endptr, &endptr, 10, &val); |
260 | + if (ret || val > UINT16_MAX || val == 0) { | 272 | + if (ret || val > UINT16_MAX || val <= 0) { |
261 | + error_setg(errp, "width in '%s' must be a decimal integer number " | 273 | + error_setg(errp, "width in '%s' must be a decimal integer number " |
262 | + "of pixels in the range 1..65535", name); | 274 | + "of pixels in the range 1..65535", name); |
263 | + goto out; | 275 | + return; |
264 | + } | 276 | + } |
265 | + mode->width_px = val; | 277 | + mode->width_px = val; |
266 | + if (*endptr != 'x') { | 278 | + if (*endptr != 'x') { |
267 | + goto separator_error; | 279 | + goto separator_error; |
268 | + } | 280 | + } |
269 | + | 281 | + |
270 | + ret = qemu_strtoui(endptr + 1, &endptr, 10, &val); | 282 | + ret = qemu_strtoi(endptr + 1, &endptr, 10, &val); |
271 | + if (ret || val > UINT16_MAX || val == 0) { | 283 | + if (ret || val > UINT16_MAX || val <= 0) { |
272 | + error_setg(errp, "height in '%s' must be a decimal integer number " | 284 | + error_setg(errp, "height in '%s' must be a decimal integer number " |
273 | + "of pixels in the range 1..65535", name); | 285 | + "of pixels in the range 1..65535", name); |
274 | + goto out; | 286 | + return; |
275 | + } | 287 | + } |
276 | + mode->height_px = val; | 288 | + mode->height_px = val; |
277 | + if (*endptr != '@') { | 289 | + if (*endptr != '@') { |
278 | + goto separator_error; | 290 | + goto separator_error; |
279 | + } | 291 | + } |
280 | + | 292 | + |
281 | + ret = qemu_strtoui(endptr + 1, &endptr, 10, &val); | 293 | + ret = qemu_strtoi(endptr + 1, &endptr, 10, &val); |
282 | + if (ret) { | 294 | + if (ret || val > UINT16_MAX || val <= 0) { |
283 | + error_setg(errp, "refresh rate in '%s'" | 295 | + error_setg(errp, "refresh rate in '%s'" |
284 | + " must be a non-negative decimal integer (Hertz)", name); | 296 | + " must be a positive decimal integer (Hertz)", name); |
297 | + return; | ||
285 | + } | 298 | + } |
286 | + mode->refresh_rate_hz = val; | 299 | + mode->refresh_rate_hz = val; |
287 | + | 300 | + return; |
288 | + goto out; | ||
289 | + | 301 | + |
290 | +separator_error: | 302 | +separator_error: |
291 | + error_setg(errp, "Each display mode takes the format " | 303 | + error_setg(errp, "Each display mode takes the format " |
292 | + "'<width>x<height>@<rate>'"); | 304 | + "'<width>x<height>@<rate>'"); |
293 | +out: | ||
294 | + g_free(str); | ||
295 | + return; | ||
296 | +} | 305 | +} |
297 | + | 306 | + |
298 | +const PropertyInfo qdev_prop_display_mode = { | 307 | +const PropertyInfo qdev_prop_display_mode = { |
299 | + .name = "display_mode", | 308 | + .name = "display_mode", |
300 | + .description = | 309 | + .description = |
... | ... | ||
315 | +apple_gfx_display_mode(uint32_t mode_idx, uint16_t width_px, uint16_t height_px) "mode %2"PRIu32": %4"PRIu16"x%4"PRIu16 | 324 | +apple_gfx_display_mode(uint32_t mode_idx, uint16_t width_px, uint16_t height_px) "mode %2"PRIu32": %4"PRIu16"x%4"PRIu16 |
316 | 325 | ||
317 | # apple-gfx-mmio.m | 326 | # apple-gfx-mmio.m |
318 | apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 | 327 | apple_gfx_mmio_iosfc_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 |
319 | -- | 328 | -- |
320 | 2.39.3 (Apple Git-145) | 329 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
9 | apple-gfx should be relatively minor and manageable in my spare time | 9 | apple-gfx should be relatively minor and manageable in my spare time |
10 | beyond that. I may have to remove myself from more general HVF duties | 10 | beyond that. I may have to remove myself from more general HVF duties |
11 | once the contract runs out if it's more than I can manage. | 11 | once the contract runs out if it's more than I can manage. |
12 | 12 | ||
13 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 13 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
14 | Reviewed-by: Roman Bolshakov <rbolshakov@ddn.com> | ||
14 | --- | 15 | --- |
15 | MAINTAINERS | 7 +++++++ | 16 | MAINTAINERS | 7 +++++++ |
16 | 1 file changed, 7 insertions(+) | 17 | 1 file changed, 7 insertions(+) |
17 | 18 | ||
18 | diff --git a/MAINTAINERS b/MAINTAINERS | 19 | diff --git a/MAINTAINERS b/MAINTAINERS |
... | ... | ||
46 | + | 47 | + |
47 | PIIX4 South Bridge (i82371AB) | 48 | PIIX4 South Bridge (i82371AB) |
48 | M: Hervé Poussineau <hpoussin@reactos.org> | 49 | M: Hervé Poussineau <hpoussin@reactos.org> |
49 | M: Philippe Mathieu-Daudé <philmd@linaro.org> | 50 | M: Philippe Mathieu-Daudé <philmd@linaro.org> |
50 | -- | 51 | -- |
51 | 2.39.3 (Apple Git-145) | 52 | 2.39.5 (Apple Git-154) |
52 | 53 | ||
53 | 54 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
5 | a single target directory. | 5 | a single target directory. |
6 | 6 | ||
7 | Signed-off-by: Alexander Graf <graf@amazon.com> | 7 | Signed-off-by: Alexander Graf <graf@amazon.com> |
8 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 8 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
9 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | 9 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> |
10 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
10 | --- | 11 | --- |
11 | MAINTAINERS | 7 +++++++ | 12 | MAINTAINERS | 7 +++++++ |
12 | hw/Kconfig | 1 + | 13 | hw/Kconfig | 1 + |
13 | hw/meson.build | 1 + | 14 | hw/meson.build | 1 + |
14 | hw/vmapple/Kconfig | 1 + | 15 | hw/vmapple/Kconfig | 1 + |
... | ... | ||
100 | + 'hw/vmapple', | 101 | + 'hw/vmapple', |
101 | 'hw/watchdog', | 102 | 'hw/watchdog', |
102 | 'hw/xen', | 103 | 'hw/xen', |
103 | 'hw/gpio', | 104 | 'hw/gpio', |
104 | -- | 105 | -- |
105 | 2.39.3 (Apple Git-145) | 106 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
6 | Signed-off-by: Alexander Graf <graf@amazon.com> | 6 | Signed-off-by: Alexander Graf <graf@amazon.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 8 | Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
9 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 9 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
10 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | 10 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> |
11 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
11 | --- | 12 | --- |
13 | |||
14 | v3: | ||
15 | * Rebased on upstream, updated a header path | ||
16 | |||
12 | hw/misc/Kconfig | 4 +++ | 17 | hw/misc/Kconfig | 4 +++ |
13 | hw/misc/meson.build | 1 + | 18 | hw/misc/meson.build | 1 + |
14 | hw/misc/pvpanic-mmio.c | 61 +++++++++++++++++++++++++++++++++++++++ | 19 | hw/misc/pvpanic-mmio.c | 61 +++++++++++++++++++++++++++++++++++++++ |
15 | include/hw/misc/pvpanic.h | 1 + | 20 | include/hw/misc/pvpanic.h | 1 + |
16 | 4 files changed, 67 insertions(+) | 21 | 4 files changed, 67 insertions(+) |
... | ... | ||
121 | +#define TYPE_PVPANIC_MMIO_DEVICE "pvpanic-mmio" | 126 | +#define TYPE_PVPANIC_MMIO_DEVICE "pvpanic-mmio" |
122 | 127 | ||
123 | #define PVPANIC_IOPORT_PROP "ioport" | 128 | #define PVPANIC_IOPORT_PROP "ioport" |
124 | 129 | ||
125 | -- | 130 | -- |
126 | 2.39.3 (Apple Git-145) | 131 | 2.39.5 (Apple Git-154) |
127 | 132 | ||
128 | 133 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
5 | a full physical timer emulation, so let's just ignore those writes. | 5 | a full physical timer emulation, so let's just ignore those writes. |
6 | 6 | ||
7 | Signed-off-by: Alexander Graf <graf@amazon.com> | 7 | Signed-off-by: Alexander Graf <graf@amazon.com> |
8 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 8 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
9 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | 9 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> |
10 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
10 | --- | 11 | --- |
11 | target/arm/hvf/hvf.c | 9 +++++++++ | 12 | target/arm/hvf/hvf.c | 9 +++++++++ |
12 | 1 file changed, 9 insertions(+) | 13 | 1 file changed, 9 insertions(+) |
13 | 14 | ||
14 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | 15 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c |
... | ... | ||
44 | + return 0; | 45 | + return 0; |
45 | case SYSREG_OSDLR_EL1: | 46 | case SYSREG_OSDLR_EL1: |
46 | /* Dummy register */ | 47 | /* Dummy register */ |
47 | return 0; | 48 | return 0; |
48 | -- | 49 | -- |
49 | 2.39.3 (Apple Git-145) | 50 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
6 | "nr_irqs" property they can use to support more than 4 legacy IRQ lines. | 6 | "nr_irqs" property they can use to support more than 4 legacy IRQ lines. |
7 | In this mode, GPEX will export more IRQ lines, one for each device. | 7 | In this mode, GPEX will export more IRQ lines, one for each device. |
8 | 8 | ||
9 | Signed-off-by: Alexander Graf <graf@amazon.com> | 9 | Signed-off-by: Alexander Graf <graf@amazon.com> |
10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
11 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
12 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
11 | --- | 13 | --- |
12 | 14 | ||
13 | v4: | 15 | v4: |
14 | 16 | ||
15 | * Turned pair of IRQ arrays into array of structs. | 17 | * Turned pair of IRQ arrays into array of structs. |
16 | * Simplified swizzling logic selection. | 18 | * Simplified swizzling logic selection. |
19 | |||
20 | v12: | ||
21 | |||
22 | * Fixed uses of deleted GPEX_NUM_IRQS constant that have been | ||
23 | added to QEMU since this patch was originally written. | ||
17 | 24 | ||
18 | hw/arm/sbsa-ref.c | 2 +- | 25 | hw/arm/sbsa-ref.c | 2 +- |
19 | hw/arm/virt.c | 2 +- | 26 | hw/arm/virt.c | 2 +- |
20 | hw/i386/microvm.c | 2 +- | 27 | hw/i386/microvm.c | 2 +- |
21 | hw/loongarch/virt.c | 2 +- | 28 | hw/loongarch/virt.c | 12 +++++------ |
22 | hw/mips/loongson3_virt.c | 2 +- | 29 | hw/mips/loongson3_virt.c | 2 +- |
23 | hw/openrisc/virt.c | 12 +++++------ | 30 | hw/openrisc/virt.c | 12 +++++------ |
24 | hw/pci-host/gpex.c | 43 ++++++++++++++++++++++++++++++-------- | 31 | hw/pci-host/gpex.c | 43 ++++++++++++++++++++++++++++++-------- |
25 | hw/riscv/virt.c | 12 +++++------ | 32 | hw/riscv/virt.c | 12 +++++------ |
33 | hw/xen/xen-pvh-common.c | 2 +- | ||
26 | hw/xtensa/virt.c | 2 +- | 34 | hw/xtensa/virt.c | 2 +- |
27 | include/hw/pci-host/gpex.h | 7 +++---- | 35 | include/hw/pci-host/gpex.h | 7 +++---- |
28 | 10 files changed, 55 insertions(+), 31 deletions(-) | 36 | 11 files changed, 61 insertions(+), 37 deletions(-) |
29 | 37 | ||
30 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c | 38 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c |
31 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/hw/arm/sbsa-ref.c | 40 | --- a/hw/arm/sbsa-ref.c |
33 | +++ b/hw/arm/sbsa-ref.c | 41 | +++ b/hw/arm/sbsa-ref.c |
... | ... | ||
68 | } | 76 | } |
69 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 77 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c |
70 | index XXXXXXX..XXXXXXX 100644 | 78 | index XXXXXXX..XXXXXXX 100644 |
71 | --- a/hw/loongarch/virt.c | 79 | --- a/hw/loongarch/virt.c |
72 | +++ b/hw/loongarch/virt.c | 80 | +++ b/hw/loongarch/virt.c |
81 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_irq_map_node(const LoongArchVirtMachineState *lvms, | ||
82 | { | ||
83 | int pin, dev; | ||
84 | uint32_t irq_map_stride = 0; | ||
85 | - uint32_t full_irq_map[GPEX_NUM_IRQS *GPEX_NUM_IRQS * 10] = {}; | ||
86 | + uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * 10] = {}; | ||
87 | uint32_t *irq_map = full_irq_map; | ||
88 | const MachineState *ms = MACHINE(lvms); | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_irq_map_node(const LoongArchVirtMachineState *lvms, | ||
91 | * to wrap to any number of devices. | ||
92 | */ | ||
93 | |||
94 | - for (dev = 0; dev < GPEX_NUM_IRQS; dev++) { | ||
95 | + for (dev = 0; dev < PCI_NUM_PINS; dev++) { | ||
96 | int devfn = dev * 0x8; | ||
97 | |||
98 | - for (pin = 0; pin < GPEX_NUM_IRQS; pin++) { | ||
99 | - int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS); | ||
100 | + for (pin = 0; pin < PCI_NUM_PINS; pin++) { | ||
101 | + int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % PCI_NUM_PINS); | ||
102 | int i = 0; | ||
103 | |||
104 | /* Fill PCI address cells */ | ||
105 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_irq_map_node(const LoongArchVirtMachineState *lvms, | ||
106 | |||
107 | |||
108 | qemu_fdt_setprop(ms->fdt, nodename, "interrupt-map", full_irq_map, | ||
109 | - GPEX_NUM_IRQS * GPEX_NUM_IRQS * | ||
110 | + PCI_NUM_PINS * PCI_NUM_PINS * | ||
111 | irq_map_stride * sizeof(uint32_t)); | ||
112 | qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupt-map-mask", | ||
113 | 0x1800, 0, 0, 0x7); | ||
73 | @@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic, | 114 | @@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic, |
74 | memory_region_add_subregion(get_system_memory(), VIRT_PCI_IO_BASE, | 115 | memory_region_add_subregion(get_system_memory(), VIRT_PCI_IO_BASE, |
75 | pio_alias); | 116 | pio_alias); |
76 | 117 | ||
77 | - for (i = 0; i < GPEX_NUM_IRQS; i++) { | 118 | - for (i = 0; i < GPEX_NUM_IRQS; i++) { |
... | ... | ||
302 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); | 343 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); |
303 | 344 | ||
304 | - for (i = 0; i < GPEX_NUM_IRQS; i++) { | 345 | - for (i = 0; i < GPEX_NUM_IRQS; i++) { |
305 | + for (i = 0; i < PCI_NUM_PINS; i++) { | 346 | + for (i = 0; i < PCI_NUM_PINS; i++) { |
306 | irq = qdev_get_gpio_in(irqchip, PCIE_IRQ + i); | 347 | irq = qdev_get_gpio_in(irqchip, PCIE_IRQ + i); |
348 | |||
349 | sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); | ||
350 | diff --git a/hw/xen/xen-pvh-common.c b/hw/xen/xen-pvh-common.c | ||
351 | index XXXXXXX..XXXXXXX 100644 | ||
352 | --- a/hw/xen/xen-pvh-common.c | ||
353 | +++ b/hw/xen/xen-pvh-common.c | ||
354 | @@ -XXX,XX +XXX,XX @@ static inline void xenpvh_gpex_init(XenPVHMachineState *s, | ||
355 | */ | ||
356 | assert(xpc->set_pci_intx_irq); | ||
357 | |||
358 | - for (i = 0; i < GPEX_NUM_IRQS; i++) { | ||
359 | + for (i = 0; i < PCI_NUM_PINS; i++) { | ||
360 | qemu_irq irq = qemu_allocate_irq(xpc->set_pci_intx_irq, s, i); | ||
307 | 361 | ||
308 | sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); | 362 | sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); |
309 | diff --git a/hw/xtensa/virt.c b/hw/xtensa/virt.c | 363 | diff --git a/hw/xtensa/virt.c b/hw/xtensa/virt.c |
310 | index XXXXXXX..XXXXXXX 100644 | 364 | index XXXXXXX..XXXXXXX 100644 |
311 | --- a/hw/xtensa/virt.c | 365 | --- a/hw/xtensa/virt.c |
... | ... | ||
350 | + uint8_t num_irqs; | 404 | + uint8_t num_irqs; |
351 | 405 | ||
352 | bool allow_unmapped_accesses; | 406 | bool allow_unmapped_accesses; |
353 | 407 | ||
354 | -- | 408 | -- |
355 | 2.39.3 (Apple Git-145) | 409 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
6 | 6 | ||
7 | Add device emulation for this device model. | 7 | Add device emulation for this device model. |
8 | 8 | ||
9 | Signed-off-by: Alexander Graf <graf@amazon.com> | 9 | Signed-off-by: Alexander Graf <graf@amazon.com> |
10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 10 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
11 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
12 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
11 | --- | 13 | --- |
14 | |||
12 | v3: | 15 | v3: |
13 | 16 | ||
14 | * Rebased on latest upstream and fixed minor breakages. | 17 | * Rebased on latest upstream and fixed minor breakages. |
15 | * Replaced legacy device reset method with Resettable method | 18 | * Replaced legacy device reset method with Resettable method |
16 | 19 | ||
17 | v4: | 20 | v4: |
18 | 21 | ||
19 | * Improved logging of unimplemented functions and guest errors. | 22 | * Improved logging of unimplemented functions and guest errors. |
20 | * Better adherence to naming and coding conventions. | 23 | * Better adherence to naming and coding conventions. |
21 | * Cleaner error handling and recovery, including using g_autoptr | 24 | * Cleaner error handling and recovery, including using g_autoptr |
22 | 25 | ||
23 | hw/vmapple/Kconfig | 2 + | 26 | v5: |
24 | hw/vmapple/aes.c | 572 ++++++++++++++++++++++++++++++++++++++++ | 27 | |
25 | hw/vmapple/meson.build | 1 + | 28 | * More logging improvements |
26 | hw/vmapple/trace-events | 16 ++ | 29 | * Use xxx64_overflow() functions for hexdump buffer size calculations. |
27 | include/qemu/cutils.h | 15 ++ | 30 | |
28 | util/hexdump.c | 14 + | 31 | v7: |
29 | 6 files changed, 620 insertions(+) | 32 | |
33 | * Coding style tweaks. | ||
34 | |||
35 | v8: | ||
36 | |||
37 | * Further improved logging of guest errors. | ||
38 | |||
39 | v9: | ||
40 | |||
41 | * Replaced a use of cpu_physical_memory_write with dma_memory_write. | ||
42 | * Dropped unnecessary use of ternary operator for bool -> 0/1. | ||
43 | |||
44 | v10: | ||
45 | |||
46 | * Code style and comment improvements. | ||
47 | |||
48 | hw/vmapple/Kconfig | 2 + | ||
49 | hw/vmapple/aes.c | 581 +++++++++++++++++++++++++++++++++++ | ||
50 | hw/vmapple/meson.build | 1 + | ||
51 | hw/vmapple/trace-events | 14 + | ||
52 | include/hw/vmapple/vmapple.h | 17 + | ||
53 | include/qemu/cutils.h | 15 + | ||
54 | util/hexdump.c | 18 ++ | ||
55 | 7 files changed, 648 insertions(+) | ||
30 | create mode 100644 hw/vmapple/aes.c | 56 | create mode 100644 hw/vmapple/aes.c |
57 | create mode 100644 include/hw/vmapple/vmapple.h | ||
31 | 58 | ||
32 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig | 59 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig |
33 | index XXXXXXX..XXXXXXX 100644 | 60 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/hw/vmapple/Kconfig | 61 | --- a/hw/vmapple/Kconfig |
35 | +++ b/hw/vmapple/Kconfig | 62 | +++ b/hw/vmapple/Kconfig |
... | ... | ||
48 | + * | 75 | + * |
49 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 76 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
50 | + * | 77 | + * |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 78 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
52 | + * See the COPYING file in the top-level directory. | 79 | + * See the COPYING file in the top-level directory. |
80 | + * | ||
81 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
53 | + */ | 82 | + */ |
54 | + | 83 | + |
55 | +#include "qemu/osdep.h" | 84 | +#include "qemu/osdep.h" |
56 | +#include "trace.h" | 85 | +#include "trace.h" |
57 | +#include "crypto/hash.h" | 86 | +#include "crypto/hash.h" |
58 | +#include "crypto/aes.h" | 87 | +#include "crypto/aes.h" |
59 | +#include "crypto/cipher.h" | 88 | +#include "crypto/cipher.h" |
60 | +#include "hw/irq.h" | 89 | +#include "hw/irq.h" |
61 | +#include "hw/sysbus.h" | 90 | +#include "hw/sysbus.h" |
91 | +#include "hw/vmapple/vmapple.h" | ||
62 | +#include "migration/vmstate.h" | 92 | +#include "migration/vmstate.h" |
63 | +#include "qemu/cutils.h" | 93 | +#include "qemu/cutils.h" |
64 | +#include "qemu/log.h" | 94 | +#include "qemu/log.h" |
65 | +#include "qemu/module.h" | 95 | +#include "qemu/module.h" |
66 | +#include "sysemu/dma.h" | 96 | +#include "sysemu/dma.h" |
67 | + | 97 | + |
68 | +#define TYPE_AES "apple-aes" | 98 | +OBJECT_DECLARE_SIMPLE_TYPE(AESState, APPLE_AES) |
69 | +OBJECT_DECLARE_SIMPLE_TYPE(AESState, AES) | ||
70 | + | 99 | + |
71 | +#define MAX_FIFO_SIZE 9 | 100 | +#define MAX_FIFO_SIZE 9 |
72 | + | 101 | + |
73 | +#define CMD_KEY 0x1 | 102 | +#define CMD_KEY 0x1 |
74 | +#define CMD_KEY_CONTEXT_SHIFT 27 | 103 | +#define CMD_KEY_CONTEXT_SHIFT 27 |
... | ... | ||
229 | + s->fifo[s->fifo_idx++] = val; | 258 | + s->fifo[s->fifo_idx++] = val; |
230 | +} | 259 | +} |
231 | + | 260 | + |
232 | +static bool has_payload(AESState *s, uint32_t elems) | 261 | +static bool has_payload(AESState *s, uint32_t elems) |
233 | +{ | 262 | +{ |
234 | + return s->fifo_idx >= (elems + 1); | 263 | + return s->fifo_idx >= elems + 1; |
235 | +} | 264 | +} |
236 | + | 265 | + |
237 | +static bool cmd_key(AESState *s) | 266 | +static bool cmd_key(AESState *s) |
238 | +{ | 267 | +{ |
239 | + uint32_t cmd = s->fifo[0]; | 268 | + uint32_t cmd = s->fifo[0]; |
... | ... | ||
251 | + default: | 280 | + default: |
252 | + return false; | 281 | + return false; |
253 | + } | 282 | + } |
254 | + | 283 | + |
255 | + s->is_encrypt = cmd & CMD_KEY_ENCRYPT_MASK; | 284 | + s->is_encrypt = cmd & CMD_KEY_ENCRYPT_MASK; |
256 | + key_len = key_lens[((cmd & CMD_KEY_KEY_LEN_MASK) >> CMD_KEY_KEY_LEN_SHIFT)]; | 285 | + key_len = key_lens[(cmd & CMD_KEY_KEY_LEN_MASK) >> CMD_KEY_KEY_LEN_SHIFT]; |
257 | + | 286 | + |
258 | + if (key_select) { | 287 | + if (key_select) { |
259 | + trace_aes_cmd_key_select_builtin(ctxt, key_select, | 288 | + trace_aes_cmd_key_select_builtin(ctxt, key_select, |
260 | + s->is_encrypt ? "en" : "de", | 289 | + s->is_encrypt ? "en" : "de", |
261 | + QCryptoCipherMode_str(s->block_mode)); | 290 | + QCryptoCipherMode_str(s->block_mode)); |
... | ... | ||
332 | + return false; | 361 | + return false; |
333 | + } | 362 | + } |
334 | + | 363 | + |
335 | + if (ctxt_key >= ARRAY_SIZE(s->key) || | 364 | + if (ctxt_key >= ARRAY_SIZE(s->key) || |
336 | + ctxt_iv >= ARRAY_SIZE(s->iv)) { | 365 | + ctxt_iv >= ARRAY_SIZE(s->iv)) { |
337 | + /* Invalid input */ | ||
338 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid key or iv\n", __func__); | 366 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid key or iv\n", __func__); |
339 | + return false; | 367 | + return false; |
340 | + } | 368 | + } |
341 | + | 369 | + |
342 | + src = g_byte_array_sized_new(len); | 370 | + src = g_byte_array_sized_new(len); |
... | ... | ||
410 | +static bool cmd_store_iv(AESState *s) | 438 | +static bool cmd_store_iv(AESState *s) |
411 | +{ | 439 | +{ |
412 | + uint32_t cmd = s->fifo[0]; | 440 | + uint32_t cmd = s->fifo[0]; |
413 | + uint32_t ctxt = (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; | 441 | + uint32_t ctxt = (cmd & CMD_IV_CONTEXT_MASK) >> CMD_IV_CONTEXT_SHIFT; |
414 | + uint64_t addr = s->fifo[1]; | 442 | + uint64_t addr = s->fifo[1]; |
443 | + MemTxResult dma_result; | ||
415 | + | 444 | + |
416 | + if (!has_payload(s, 1)) { | 445 | + if (!has_payload(s, 1)) { |
417 | + /* wait for payload */ | ||
418 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: No payload\n", __func__); | 446 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: No payload\n", __func__); |
419 | + return false; | 447 | + return false; |
420 | + } | 448 | + } |
421 | + | 449 | + |
422 | + if (ctxt >= ARRAY_SIZE(s->iv)) { | 450 | + if (ctxt >= ARRAY_SIZE(s->iv)) { |
423 | + /* Invalid context selected */ | 451 | + qemu_log_mask(LOG_GUEST_ERROR, |
452 | + "%s: Invalid context. ctxt = %u, allowed: 0..%zu\n", | ||
453 | + __func__, ctxt, ARRAY_SIZE(s->iv) - 1); | ||
424 | + return false; | 454 | + return false; |
425 | + } | 455 | + } |
426 | + | 456 | + |
427 | + addr |= ((uint64_t)cmd << 32) & 0xff00000000ULL; | 457 | + addr |= ((uint64_t)cmd << 32) & 0xff00000000ULL; |
428 | + cpu_physical_memory_write(addr, &s->iv[ctxt].iv, sizeof(s->iv[ctxt].iv)); | 458 | + dma_result = dma_memory_write(&address_space_memory, addr, |
459 | + &s->iv[ctxt].iv, sizeof(s->iv[ctxt].iv), | ||
460 | + MEMTXATTRS_UNSPECIFIED); | ||
429 | + | 461 | + |
430 | + trace_aes_cmd_store_iv(ctxt, addr, s->iv[ctxt].iv[0], s->iv[ctxt].iv[1], | 462 | + trace_aes_cmd_store_iv(ctxt, addr, s->iv[ctxt].iv[0], s->iv[ctxt].iv[1], |
431 | + s->iv[ctxt].iv[2], s->iv[ctxt].iv[3]); | 463 | + s->iv[ctxt].iv[2], s->iv[ctxt].iv[3]); |
432 | + | 464 | + |
433 | + return true; | 465 | + return dma_result == MEMTX_OK; |
434 | +} | 466 | +} |
435 | + | 467 | + |
436 | +static bool cmd_flag(AESState *s) | 468 | +static bool cmd_flag(AESState *s) |
437 | +{ | 469 | +{ |
438 | + uint32_t cmd = s->fifo[0]; | 470 | + uint32_t cmd = s->fifo[0]; |
... | ... | ||
482 | + | 514 | + |
483 | + if (success) { | 515 | + if (success) { |
484 | + s->fifo_idx = 0; | 516 | + s->fifo_idx = 0; |
485 | + } | 517 | + } |
486 | + | 518 | + |
487 | + trace_aes_fifo_process(cmd, success ? 1 : 0); | 519 | + trace_aes_fifo_process(cmd, success); |
488 | +} | 520 | +} |
489 | + | 521 | + |
490 | +static void aes1_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) | 522 | +static void aes1_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) |
491 | +{ | 523 | +{ |
492 | + AESState *s = opaque; | 524 | + AESState *s = opaque; |
... | ... | ||
535 | + switch (offset) { | 567 | + switch (offset) { |
536 | + case 0: | 568 | + case 0: |
537 | + res = 0; | 569 | + res = 0; |
538 | + break; | 570 | + break; |
539 | + default: | 571 | + default: |
540 | + trace_aes_2_read_unknown(offset); | 572 | + qemu_log_mask(LOG_UNIMP, |
573 | + "%s: Unknown AES MMIO 2 offset %"PRIx64"\n", | ||
574 | + __func__, offset); | ||
541 | + break; | 575 | + break; |
542 | + } | 576 | + } |
543 | + | 577 | + |
544 | + trace_aes_2_read(offset, res); | 578 | + trace_aes_2_read(offset, res); |
545 | + | 579 | + |
... | ... | ||
550 | +{ | 584 | +{ |
551 | + trace_aes_2_write(offset, val); | 585 | + trace_aes_2_write(offset, val); |
552 | + | 586 | + |
553 | + switch (offset) { | 587 | + switch (offset) { |
554 | + default: | 588 | + default: |
555 | + trace_aes_2_write_unknown(offset); | 589 | + qemu_log_mask(LOG_UNIMP, |
590 | + "%s: Unknown AES MMIO 2 offset %"PRIx64", data %"PRIx64"\n", | ||
591 | + __func__, offset, val); | ||
556 | + return; | 592 | + return; |
557 | + } | 593 | + } |
558 | +} | 594 | +} |
559 | + | 595 | + |
560 | +static const MemoryRegionOps aes2_ops = { | 596 | +static const MemoryRegionOps aes2_ops = { |
... | ... | ||
571 | + }, | 607 | + }, |
572 | +}; | 608 | +}; |
573 | + | 609 | + |
574 | +static void aes_reset(Object *obj, ResetType type) | 610 | +static void aes_reset(Object *obj, ResetType type) |
575 | +{ | 611 | +{ |
576 | + AESState *s = AES(obj); | 612 | + AESState *s = APPLE_AES(obj); |
577 | + | 613 | + |
578 | + s->status = 0x3f80; | 614 | + s->status = 0x3f80; |
579 | + s->q_status = 2; | 615 | + s->q_status = 2; |
580 | + s->irq_status = 0; | 616 | + s->irq_status = 0; |
581 | + s->irq_enable = 0; | 617 | + s->irq_enable = 0; |
582 | + s->watermark = 0; | 618 | + s->watermark = 0; |
583 | +} | 619 | +} |
584 | + | 620 | + |
585 | +static void aes_init(Object *obj) | 621 | +static void aes_init(Object *obj) |
586 | +{ | 622 | +{ |
587 | + AESState *s = AES(obj); | 623 | + AESState *s = APPLE_AES(obj); |
588 | + | 624 | + |
589 | + memory_region_init_io(&s->iomem1, obj, &aes1_ops, s, TYPE_AES, 0x4000); | 625 | + memory_region_init_io(&s->iomem1, obj, &aes1_ops, s, TYPE_APPLE_AES, 0x4000); |
590 | + memory_region_init_io(&s->iomem2, obj, &aes2_ops, s, TYPE_AES, 0x4000); | 626 | + memory_region_init_io(&s->iomem2, obj, &aes2_ops, s, TYPE_APPLE_AES, 0x4000); |
591 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem1); | 627 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem1); |
592 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem2); | 628 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem2); |
593 | + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq); | 629 | + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq); |
594 | + s->as = &address_space_memory; | 630 | + s->as = &address_space_memory; |
595 | +} | 631 | +} |
... | ... | ||
600 | + | 636 | + |
601 | + rc->phases.hold = aes_reset; | 637 | + rc->phases.hold = aes_reset; |
602 | +} | 638 | +} |
603 | + | 639 | + |
604 | +static const TypeInfo aes_info = { | 640 | +static const TypeInfo aes_info = { |
605 | + .name = TYPE_AES, | 641 | + .name = TYPE_APPLE_AES, |
606 | + .parent = TYPE_SYS_BUS_DEVICE, | 642 | + .parent = TYPE_SYS_BUS_DEVICE, |
607 | + .instance_size = sizeof(AESState), | 643 | + .instance_size = sizeof(AESState), |
608 | + .class_init = aes_class_init, | 644 | + .class_init = aes_class_init, |
609 | + .instance_init = aes_init, | 645 | + .instance_init = aes_init, |
610 | +}; | 646 | +}; |
... | ... | ||
634 | +aes_cmd_key_select_new(uint32_t ctx, uint32_t key_len, const char *direction, const char *cipher) "[%d] Selecting new key size=%d to %scrypt with %s" | 670 | +aes_cmd_key_select_new(uint32_t ctx, uint32_t key_len, const char *direction, const char *cipher) "[%d] Selecting new key size=%d to %scrypt with %s" |
635 | +aes_cmd_iv(uint32_t ctx, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] 0x%08x 0x%08x 0x%08x 0x%08x" | 671 | +aes_cmd_iv(uint32_t ctx, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] 0x%08x 0x%08x 0x%08x 0x%08x" |
636 | +aes_cmd_data(uint32_t key, uint32_t iv, uint64_t src, uint64_t dst, uint32_t len) "[key=%d iv=%d] src=0x%"PRIx64" dst=0x%"PRIx64" len=0x%x" | 672 | +aes_cmd_data(uint32_t key, uint32_t iv, uint64_t src, uint64_t dst, uint32_t len) "[key=%d iv=%d] src=0x%"PRIx64" dst=0x%"PRIx64" len=0x%x" |
637 | +aes_cmd_store_iv(uint32_t ctx, uint64_t addr, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] addr=0x%"PRIx64"x -> 0x%08x 0x%08x 0x%08x 0x%08x" | 673 | +aes_cmd_store_iv(uint32_t ctx, uint64_t addr, uint32_t iv0, uint32_t iv1, uint32_t iv2, uint32_t iv3) "[%d] addr=0x%"PRIx64"x -> 0x%08x 0x%08x 0x%08x 0x%08x" |
638 | +aes_cmd_flag(uint32_t raise, uint32_t flag_info) "raise=%d flag_info=0x%x" | 674 | +aes_cmd_flag(uint32_t raise, uint32_t flag_info) "raise=%d flag_info=0x%x" |
639 | +aes_fifo_process(uint32_t cmd, uint32_t success) "cmd=%d success=%d" | 675 | +aes_fifo_process(uint32_t cmd, bool success) "cmd=%d success=%d" |
640 | +aes_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 | 676 | +aes_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 |
641 | +aes_2_read_unknown(uint64_t offset) "offset=0x%"PRIx64 | ||
642 | +aes_2_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 | 677 | +aes_2_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 |
643 | +aes_2_write_unknown(uint64_t offset) "offset=0x%"PRIx64 | ||
644 | +aes_2_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 | 678 | +aes_2_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 |
645 | +aes_dump_data(const char *desc, const char *hex) "%s%s" | 679 | +aes_dump_data(const char *desc, const char *hex) "%s%s" |
646 | + | 680 | + |
681 | diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h | ||
682 | new file mode 100644 | ||
683 | index XXXXXXX..XXXXXXX | ||
684 | --- /dev/null | ||
685 | +++ b/include/hw/vmapple/vmapple.h | ||
686 | @@ -XXX,XX +XXX,XX @@ | ||
687 | +/* | ||
688 | + * Devices specific to the VMApple machine type | ||
689 | + * | ||
690 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
691 | + * | ||
692 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
693 | + * See the COPYING file in the top-level directory. | ||
694 | + * | ||
695 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
696 | + */ | ||
697 | + | ||
698 | +#ifndef HW_VMAPPLE_VMAPPLE_H | ||
699 | +#define HW_VMAPPLE_VMAPPLE_H | ||
700 | + | ||
701 | +#define TYPE_APPLE_AES "apple-aes" | ||
702 | + | ||
703 | +#endif /* HW_VMAPPLE_VMAPPLE_H */ | ||
647 | diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h | 704 | diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h |
648 | index XXXXXXX..XXXXXXX 100644 | 705 | index XXXXXXX..XXXXXXX 100644 |
649 | --- a/include/qemu/cutils.h | 706 | --- a/include/qemu/cutils.h |
650 | +++ b/include/qemu/cutils.h | 707 | +++ b/include/qemu/cutils.h |
651 | @@ -XXX,XX +XXX,XX @@ GString *qemu_hexdump_line(GString *str, const void *buf, size_t len, | 708 | @@ -XXX,XX +XXX,XX @@ GString *qemu_hexdump_line(GString *str, const void *buf, size_t len, |
... | ... | ||
670 | #endif | 727 | #endif |
671 | diff --git a/util/hexdump.c b/util/hexdump.c | 728 | diff --git a/util/hexdump.c b/util/hexdump.c |
672 | index XXXXXXX..XXXXXXX 100644 | 729 | index XXXXXXX..XXXXXXX 100644 |
673 | --- a/util/hexdump.c | 730 | --- a/util/hexdump.c |
674 | +++ b/util/hexdump.c | 731 | +++ b/util/hexdump.c |
732 | @@ -XXX,XX +XXX,XX @@ | ||
733 | |||
734 | #include "qemu/osdep.h" | ||
735 | #include "qemu/cutils.h" | ||
736 | +#include "qemu/host-utils.h" | ||
737 | |||
738 | static inline char hexdump_nibble(unsigned x) | ||
739 | { | ||
675 | @@ -XXX,XX +XXX,XX @@ void qemu_hexdump(FILE *fp, const char *prefix, | 740 | @@ -XXX,XX +XXX,XX @@ void qemu_hexdump(FILE *fp, const char *prefix, |
676 | } | 741 | } |
677 | 742 | ||
678 | } | 743 | } |
679 | + | 744 | + |
680 | +void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size, | 745 | +void qemu_hexdump_to_buffer(char *restrict buffer, size_t buffer_size, |
681 | + const uint8_t *restrict data, size_t data_size) | 746 | + const uint8_t *restrict data, size_t data_size) |
682 | +{ | 747 | +{ |
683 | + size_t i; | 748 | + size_t i; |
684 | + | 749 | + uint64_t required_buffer_size; |
685 | + assert(buffer_size >= data_size * 2 + 1 && buffer_size > data_size); | 750 | + bool overflow = umul64_overflow(data_size, 2, &required_buffer_size); |
751 | + overflow |= uadd64_overflow(required_buffer_size, 1, &required_buffer_size); | ||
752 | + assert(!overflow && buffer_size >= required_buffer_size); | ||
753 | + | ||
686 | + for (i = 0; i < data_size; i++) { | 754 | + for (i = 0; i < data_size; i++) { |
687 | + uint8_t val = data[i]; | 755 | + uint8_t val = data[i]; |
688 | + *(buffer++) = hexdump_nibble(val >> 4); | 756 | + *(buffer++) = hexdump_nibble(val >> 4); |
689 | + *(buffer++) = hexdump_nibble(val & 0xf); | 757 | + *(buffer++) = hexdump_nibble(val & 0xf); |
690 | + } | 758 | + } |
691 | + *buffer = '\0'; | 759 | + *buffer = '\0'; |
692 | +} | 760 | +} |
693 | -- | 761 | -- |
694 | 2.39.3 (Apple Git-145) | 762 | 2.39.5 (Apple Git-154) |
695 | 763 | ||
696 | 764 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
8 | understanding. I left out any USB OTG parts; they're only needed for | 8 | understanding. I left out any USB OTG parts; they're only needed for |
9 | guest recovery and I don't understand the protocol yet. | 9 | guest recovery and I don't understand the protocol yet. |
10 | 10 | ||
11 | Signed-off-by: Alexander Graf <graf@amazon.com> | 11 | Signed-off-by: Alexander Graf <graf@amazon.com> |
12 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 12 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
13 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
14 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
13 | --- | 15 | --- |
16 | |||
14 | v4: | 17 | v4: |
15 | 18 | ||
16 | * Moved most header code to .c, rest to vmapple.h | 19 | * Moved most header code to .c, rest to vmapple.h |
17 | * Better compliance with coding, naming, and formatting conventions. | 20 | * Better compliance with coding, naming, and formatting conventions. |
18 | 21 | ||
22 | v8: | ||
23 | |||
24 | * Replaced uses of cpu_physical_memory_read with dma_memory_read. | ||
25 | * Replaced an instance of g_free with g_autofree. | ||
26 | |||
27 | v9: | ||
28 | |||
29 | * Replaced uses of cpu_physical_memory_write with dma_memory_write. | ||
30 | |||
19 | hw/vmapple/Kconfig | 3 + | 31 | hw/vmapple/Kconfig | 3 + |
20 | hw/vmapple/bdif.c | 259 +++++++++++++++++++++++++++++++++++ | 32 | hw/vmapple/bdif.c | 275 +++++++++++++++++++++++++++++++++++ |
21 | hw/vmapple/meson.build | 1 + | 33 | hw/vmapple/meson.build | 1 + |
22 | hw/vmapple/trace-events | 5 + | 34 | hw/vmapple/trace-events | 5 + |
23 | include/hw/vmapple/vmapple.h | 15 ++ | 35 | include/hw/vmapple/vmapple.h | 2 + |
24 | 5 files changed, 283 insertions(+) | 36 | 5 files changed, 286 insertions(+) |
25 | create mode 100644 hw/vmapple/bdif.c | 37 | create mode 100644 hw/vmapple/bdif.c |
26 | create mode 100644 include/hw/vmapple/vmapple.h | ||
27 | 38 | ||
28 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig | 39 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig |
29 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/vmapple/Kconfig | 41 | --- a/hw/vmapple/Kconfig |
31 | +++ b/hw/vmapple/Kconfig | 42 | +++ b/hw/vmapple/Kconfig |
... | ... | ||
47 | + * | 58 | + * |
48 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 59 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
49 | + * | 60 | + * |
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 61 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
51 | + * See the COPYING file in the top-level directory. | 62 | + * See the COPYING file in the top-level directory. |
63 | + * | ||
64 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
52 | + */ | 65 | + */ |
53 | + | 66 | + |
54 | +#include "qemu/osdep.h" | 67 | +#include "qemu/osdep.h" |
55 | +#include "qemu/units.h" | 68 | +#include "qemu/units.h" |
56 | +#include "qemu/log.h" | 69 | +#include "qemu/log.h" |
... | ... | ||
59 | +#include "hw/vmapple/vmapple.h" | 72 | +#include "hw/vmapple/vmapple.h" |
60 | +#include "hw/sysbus.h" | 73 | +#include "hw/sysbus.h" |
61 | +#include "hw/block/block.h" | 74 | +#include "hw/block/block.h" |
62 | +#include "qapi/error.h" | 75 | +#include "qapi/error.h" |
63 | +#include "sysemu/block-backend.h" | 76 | +#include "sysemu/block-backend.h" |
77 | +#include "sysemu/dma.h" | ||
64 | + | 78 | + |
65 | +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleBdifState, VMAPPLE_BDIF) | 79 | +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleBdifState, VMAPPLE_BDIF) |
66 | + | 80 | + |
67 | +struct VMAppleBdifState { | 81 | +struct VMAppleBdifState { |
68 | + SysBusDevice parent_obj; | 82 | + SysBusDevice parent_obj; |
... | ... | ||
173 | + le2cpu_reqcmd(&req->sector); | 187 | + le2cpu_reqcmd(&req->sector); |
174 | + le2cpu_reqcmd(&req->data); | 188 | + le2cpu_reqcmd(&req->data); |
175 | + le2cpu_reqcmd(&req->retval); | 189 | + le2cpu_reqcmd(&req->retval); |
176 | +} | 190 | +} |
177 | + | 191 | + |
178 | +static void vblk_cmd(uint64_t devid, BlockBackend *blk, uint64_t value, | 192 | +static void vblk_cmd(uint64_t devid, BlockBackend *blk, uint64_t gp_addr, |
179 | + uint64_t static_off) | 193 | + uint64_t static_off) |
180 | +{ | 194 | +{ |
181 | + VblkReq req; | 195 | + VblkReq req; |
182 | + VblkSector sector; | 196 | + VblkSector sector; |
183 | + uint64_t off = 0; | 197 | + uint64_t off = 0; |
184 | + char *buf = NULL; | 198 | + g_autofree char *buf = NULL; |
185 | + uint8_t ret = VBLK_RET_FAILED; | 199 | + uint8_t ret = VBLK_RET_FAILED; |
186 | + int r; | 200 | + int r; |
187 | + | 201 | + MemTxResult dma_result; |
188 | + cpu_physical_memory_read(value, &req, sizeof(req)); | 202 | + |
203 | + dma_result = dma_memory_read(&address_space_memory, gp_addr, | ||
204 | + &req, sizeof(req), MEMTXATTRS_UNSPECIFIED); | ||
205 | + if (dma_result != MEMTX_OK) { | ||
206 | + goto out; | ||
207 | + } | ||
208 | + | ||
189 | + le2cpu_req(&req); | 209 | + le2cpu_req(&req); |
190 | + | 210 | + |
191 | + if (req.sector.len != sizeof(sector)) { | 211 | + if (req.sector.len != sizeof(sector)) { |
192 | + ret = VBLK_RET_FAILED; | ||
193 | + goto out; | 212 | + goto out; |
194 | + } | 213 | + } |
195 | + | 214 | + |
196 | + /* Read the vblk command */ | 215 | + /* Read the vblk command */ |
197 | + cpu_physical_memory_read(req.sector.addr, §or, sizeof(sector)); | 216 | + dma_result = dma_memory_read(&address_space_memory, req.sector.addr, |
217 | + §or, sizeof(sector), | ||
218 | + MEMTXATTRS_UNSPECIFIED); | ||
219 | + if (dma_result != MEMTX_OK) { | ||
220 | + goto out; | ||
221 | + } | ||
198 | + le2cpu_sector(§or); | 222 | + le2cpu_sector(§or); |
199 | + | 223 | + |
200 | + off = sector.sector * 512ULL + static_off; | 224 | + off = sector.sector * 512ULL + static_off; |
201 | + | 225 | + |
202 | + /* Sanity check that we're not allocating bogus sizes */ | 226 | + /* Sanity check that we're not allocating bogus sizes */ |
... | ... | ||
211 | + trace_bdif_vblk_read(devid == DEVID_AUX ? "aux" : "root", | 235 | + trace_bdif_vblk_read(devid == DEVID_AUX ? "aux" : "root", |
212 | + req.data.addr, off, req.data.len, r); | 236 | + req.data.addr, off, req.data.len, r); |
213 | + if (r < 0) { | 237 | + if (r < 0) { |
214 | + goto out; | 238 | + goto out; |
215 | + } | 239 | + } |
216 | + cpu_physical_memory_write(req.data.addr, buf, req.data.len); | 240 | + dma_result = dma_memory_write(&address_space_memory, req.data.addr, buf, |
217 | + ret = VBLK_RET_SUCCESS; | 241 | + req.data.len, MEMTXATTRS_UNSPECIFIED); |
242 | + if (dma_result == MEMTX_OK) { | ||
243 | + ret = VBLK_RET_SUCCESS; | ||
244 | + } | ||
218 | + break; | 245 | + break; |
219 | + case VBLK_DATA_FLAGS_WRITE: | 246 | + case VBLK_DATA_FLAGS_WRITE: |
220 | + /* Not needed, iBoot only reads */ | 247 | + /* Not needed, iBoot only reads */ |
221 | + break; | 248 | + break; |
222 | + default: | 249 | + default: |
223 | + break; | 250 | + break; |
224 | + } | 251 | + } |
225 | + | 252 | + |
226 | +out: | 253 | +out: |
227 | + g_free(buf); | 254 | + dma_memory_write(&address_space_memory, req.retval.addr, &ret, 1, |
228 | + cpu_physical_memory_write(req.retval.addr, &ret, 1); | 255 | + MEMTXATTRS_UNSPECIFIED); |
229 | +} | 256 | +} |
230 | + | 257 | + |
231 | +static void bdif_write(void *opaque, hwaddr offset, | 258 | +static void bdif_write(void *opaque, hwaddr offset, |
232 | + uint64_t value, unsigned size) | 259 | + uint64_t value, unsigned size) |
233 | +{ | 260 | +{ |
... | ... | ||
310 | +system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) | 337 | +system_ss.add(when: 'CONFIG_VMAPPLE_BDIF', if_true: files('bdif.c')) |
311 | diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events | 338 | diff --git a/hw/vmapple/trace-events b/hw/vmapple/trace-events |
312 | index XXXXXXX..XXXXXXX 100644 | 339 | index XXXXXXX..XXXXXXX 100644 |
313 | --- a/hw/vmapple/trace-events | 340 | --- a/hw/vmapple/trace-events |
314 | +++ b/hw/vmapple/trace-events | 341 | +++ b/hw/vmapple/trace-events |
315 | @@ -XXX,XX +XXX,XX @@ aes_2_write_unknown(uint64_t offset) "offset=0x%"PRIx64 | 342 | @@ -XXX,XX +XXX,XX @@ aes_2_read(uint64_t offset, uint64_t res) "offset=0x%"PRIx64" res=0x%"PRIx64 |
316 | aes_2_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 | 343 | aes_2_write(uint64_t offset, uint64_t val) "offset=0x%"PRIx64" val=0x%"PRIx64 |
317 | aes_dump_data(const char *desc, const char *hex) "%s%s" | 344 | aes_dump_data(const char *desc, const char *hex) "%s%s" |
318 | 345 | ||
319 | +# bdif.c | 346 | +# bdif.c |
320 | +bdif_read(uint64_t offset, uint32_t size, uint64_t value) "offset=0x%"PRIx64" size=0x%x value=0x%"PRIx64 | 347 | +bdif_read(uint64_t offset, uint32_t size, uint64_t value) "offset=0x%"PRIx64" size=0x%x value=0x%"PRIx64 |
321 | +bdif_write(uint64_t offset, uint32_t size, uint64_t value) "offset=0x%"PRIx64" size=0x%x value=0x%"PRIx64 | 348 | +bdif_write(uint64_t offset, uint32_t size, uint64_t value) "offset=0x%"PRIx64" size=0x%x value=0x%"PRIx64 |
322 | +bdif_vblk_read(const char *dev, uint64_t addr, uint64_t offset, uint32_t len, int r) "dev=%s addr=0x%"PRIx64" off=0x%"PRIx64" size=0x%x r=%d" | 349 | +bdif_vblk_read(const char *dev, uint64_t addr, uint64_t offset, uint32_t len, int r) "dev=%s addr=0x%"PRIx64" off=0x%"PRIx64" size=0x%x r=%d" |
323 | + | 350 | + |
324 | diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h | 351 | diff --git a/include/hw/vmapple/vmapple.h b/include/hw/vmapple/vmapple.h |
325 | new file mode 100644 | 352 | index XXXXXXX..XXXXXXX 100644 |
326 | index XXXXXXX..XXXXXXX | 353 | --- a/include/hw/vmapple/vmapple.h |
327 | --- /dev/null | ||
328 | +++ b/include/hw/vmapple/vmapple.h | 354 | +++ b/include/hw/vmapple/vmapple.h |
329 | @@ -XXX,XX +XXX,XX @@ | 355 | @@ -XXX,XX +XXX,XX @@ |
330 | +/* | 356 | |
331 | + * Devices specific to the VMApple machine type | 357 | #define TYPE_APPLE_AES "apple-aes" |
332 | + * | 358 | |
333 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
334 | + * | ||
335 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
336 | + * See the COPYING file in the top-level directory. | ||
337 | + */ | ||
338 | + | ||
339 | +#ifndef HW_VMAPPLE_VMAPPLE_H | ||
340 | +#define HW_VMAPPLE_VMAPPLE_H | ||
341 | + | ||
342 | +#define TYPE_VMAPPLE_BDIF "vmapple-bdif" | 359 | +#define TYPE_VMAPPLE_BDIF "vmapple-bdif" |
343 | + | 360 | + |
344 | +#endif /* HW_VMAPPLE_VMAPPLE_H */ | 361 | #endif /* HW_VMAPPLE_VMAPPLE_H */ |
345 | -- | 362 | -- |
346 | 2.39.3 (Apple Git-145) | 363 | 2.39.5 (Apple Git-154) |
347 | 364 | ||
348 | 365 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
8 | then map at the fixed location in the address space. That way, we can | 8 | then map at the fixed location in the address space. That way, we can |
9 | influence and annotate all configuration fields easily. | 9 | influence and annotate all configuration fields easily. |
10 | 10 | ||
11 | Signed-off-by: Alexander Graf <graf@amazon.com> | 11 | Signed-off-by: Alexander Graf <graf@amazon.com> |
12 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 12 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
13 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
14 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
13 | --- | 15 | --- |
16 | |||
14 | v3: | 17 | v3: |
15 | 18 | ||
16 | * Replaced legacy device reset method with Resettable method | 19 | * Replaced legacy device reset method with Resettable method |
17 | 20 | ||
18 | v4: | 21 | v4: |
19 | 22 | ||
20 | * Fixed initialisation of default values for properties | 23 | * Fixed initialisation of default values for properties |
21 | * Dropped superfluous endianness conversions | 24 | * Dropped superfluous endianness conversions |
22 | * Moved most header code to .c, device name #define goes in vmapple.h | 25 | * Moved most header code to .c, device name #define goes in vmapple.h |
23 | 26 | ||
27 | v5: | ||
28 | |||
29 | * Improved error reporting in case of string property buffer overflow. | ||
30 | |||
31 | v7: | ||
32 | |||
33 | * Changed error messages for overrun of properties with | ||
34 | fixed-length strings to be more useful to users than developers. | ||
35 | |||
36 | v8: | ||
37 | |||
38 | * Consistent parenthesising of macro arguments for better safety. | ||
39 | |||
40 | v10: | ||
41 | |||
42 | * Slightly tidier error reporting for overlong property values. | ||
43 | |||
24 | hw/vmapple/Kconfig | 3 + | 44 | hw/vmapple/Kconfig | 3 + |
25 | hw/vmapple/cfg.c | 197 +++++++++++++++++++++++++++++++++++ | 45 | hw/vmapple/cfg.c | 196 +++++++++++++++++++++++++++++++++++ |
26 | hw/vmapple/meson.build | 1 + | 46 | hw/vmapple/meson.build | 1 + |
27 | include/hw/vmapple/vmapple.h | 2 + | 47 | include/hw/vmapple/vmapple.h | 2 + |
28 | 4 files changed, 203 insertions(+) | 48 | 4 files changed, 202 insertions(+) |
29 | create mode 100644 hw/vmapple/cfg.c | 49 | create mode 100644 hw/vmapple/cfg.c |
30 | 50 | ||
31 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig | 51 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig |
32 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/vmapple/Kconfig | 53 | --- a/hw/vmapple/Kconfig |
... | ... | ||
47 | @@ -XXX,XX +XXX,XX @@ | 67 | @@ -XXX,XX +XXX,XX @@ |
48 | +/* | 68 | +/* |
49 | + * VMApple Configuration Region | 69 | + * VMApple Configuration Region |
50 | + * | 70 | + * |
51 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 71 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
72 | + * | ||
73 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
52 | + * | 74 | + * |
53 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 75 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
54 | + * See the COPYING file in the top-level directory. | 76 | + * See the COPYING file in the top-level directory. |
55 | + */ | 77 | + */ |
56 | + | 78 | + |
... | ... | ||
114 | +{ | 136 | +{ |
115 | + VMAppleCfgState *s = VMAPPLE_CFG(obj); | 137 | + VMAppleCfgState *s = VMAPPLE_CFG(obj); |
116 | + VMAppleCfg *cfg; | 138 | + VMAppleCfg *cfg; |
117 | + | 139 | + |
118 | + cfg = memory_region_get_ram_ptr(&s->mem); | 140 | + cfg = memory_region_get_ram_ptr(&s->mem); |
119 | + memset((void *)cfg, 0, VMAPPLE_CFG_SIZE); | 141 | + memset(cfg, 0, VMAPPLE_CFG_SIZE); |
120 | + *cfg = s->cfg; | 142 | + *cfg = s->cfg; |
121 | +} | 143 | +} |
122 | + | 144 | + |
123 | +static bool strlcpy_set_error(char *restrict dst, const char *restrict src, | 145 | +static bool set_fixlen_property_or_error(char *restrict dst, |
124 | + size_t dst_size, Error **errp, | 146 | + const char *restrict src, |
125 | + const char *parent_func, const char *location, | 147 | + size_t dst_size, Error **errp, |
126 | + const char *buffer_name) | 148 | + const char *property_name) |
127 | +{ | 149 | +{ |
150 | + ERRP_GUARD(); | ||
128 | + size_t len; | 151 | + size_t len; |
129 | + | 152 | + |
130 | + len = g_strlcpy(dst, src, dst_size); | 153 | + len = g_strlcpy(dst, src, dst_size); |
131 | + if (len < dst_size) { /* len does not count nul terminator */ | 154 | + if (len < dst_size) { /* len does not count nul terminator */ |
132 | + return true; | 155 | + return true; |
133 | + } | 156 | + } |
134 | + | 157 | + |
135 | + error_setg(errp, | 158 | + error_setg(errp, "Provided value too long for property '%s'", property_name); |
136 | + "strlcpy_set_error: %s (%s): Destination buffer %s too small " | 159 | + error_append_hint(errp, "length (%zu) exceeds maximum of %zu\n", |
137 | + "(need %zu, have %zu)", | 160 | + len, dst_size - 1); |
138 | + parent_func, location, buffer_name, len + 1, dst_size); | ||
139 | + return false; | 161 | + return false; |
140 | +} | 162 | +} |
141 | + | 163 | + |
142 | +/* | 164 | +#define set_fixlen_property_or_return(dst_array, src, errp, property_name) \ |
143 | + * String copying wrapper that returns and reports a runtime error in | ||
144 | + * case of truncation due to insufficient destination buffer space. | ||
145 | + */ | ||
146 | +#define strlcpy_array_return_error(dst_array, src, errp) \ | ||
147 | + do { \ | 165 | + do { \ |
148 | + if (!strlcpy_set_error((dst_array), (src), ARRAY_SIZE(dst_array), (errp),\ | 166 | + if (!set_fixlen_property_or_error((dst_array), (src), \ |
149 | + __func__, stringify(__LINE__), # dst_array)) { \ | 167 | + ARRAY_SIZE(dst_array), \ |
168 | + (errp), (property_name))) { \ | ||
150 | + return; \ | 169 | + return; \ |
151 | + } \ | 170 | + } \ |
152 | + } while (0) | 171 | + } while (0) |
153 | + | 172 | + |
154 | +static void vmapple_cfg_realize(DeviceState *dev, Error **errp) | 173 | +static void vmapple_cfg_realize(DeviceState *dev, Error **errp) |
... | ... | ||
164 | + } | 183 | + } |
165 | + if (!s->soc_name) { | 184 | + if (!s->soc_name) { |
166 | + s->soc_name = g_strdup("Apple M1 (Virtual)"); | 185 | + s->soc_name = g_strdup("Apple M1 (Virtual)"); |
167 | + } | 186 | + } |
168 | + | 187 | + |
169 | + strlcpy_array_return_error(s->cfg.serial, s->serial, errp); | 188 | + set_fixlen_property_or_return(s->cfg.serial, s->serial, errp, "serial"); |
170 | + strlcpy_array_return_error(s->cfg.model, s->model, errp); | 189 | + set_fixlen_property_or_return(s->cfg.model, s->model, errp, "model"); |
171 | + strlcpy_array_return_error(s->cfg.soc_name, s->soc_name, errp); | 190 | + set_fixlen_property_or_return(s->cfg.soc_name, s->soc_name, errp, "soc_name"); |
172 | + strlcpy_array_return_error(s->cfg.unk8, "D/A", errp); | 191 | + set_fixlen_property_or_return(s->cfg.unk8, "D/A", errp, "unk8"); |
173 | + s->cfg.version = 2; | 192 | + s->cfg.version = 2; |
174 | + s->cfg.unk1 = 1; | 193 | + s->cfg.unk1 = 1; |
175 | + s->cfg.unk2 = 1; | 194 | + s->cfg.unk2 = 1; |
176 | + s->cfg.unk3 = 0x20; | 195 | + s->cfg.unk3 = 0x20; |
177 | + s->cfg.unk4 = 0; | 196 | + s->cfg.unk4 = 0; |
... | ... | ||
260 | 279 | ||
261 | +#define TYPE_VMAPPLE_CFG "vmapple-cfg" | 280 | +#define TYPE_VMAPPLE_CFG "vmapple-cfg" |
262 | + | 281 | + |
263 | #endif /* HW_VMAPPLE_VMAPPLE_H */ | 282 | #endif /* HW_VMAPPLE_VMAPPLE_H */ |
264 | -- | 283 | -- |
265 | 2.39.3 (Apple Git-145) | 284 | 2.39.5 (Apple Git-154) |
266 | 285 | ||
267 | 286 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
8 | This patch first creates a mechanism for virtio-blk downstream classes to | 8 | This patch first creates a mechanism for virtio-blk downstream classes to |
9 | handle unknown commands. It then creates such a downstream class and a new | 9 | handle unknown commands. It then creates such a downstream class and a new |
10 | vmapple-virtio-blk-pci class which support the additional apple type config | 10 | vmapple-virtio-blk-pci class which support the additional apple type config |
11 | identifier as well as the barrier command. | 11 | identifier as well as the barrier command. |
12 | 12 | ||
13 | It then exposes 2 subclasses from that that we can use to expose root and | 13 | The 'aux' or 'root' device type are selected using the 'variant' property. |
14 | aux virtio-blk devices: "vmapple-virtio-root" and "vmapple-virtio-aux". | ||
15 | 14 | ||
16 | Signed-off-by: Alexander Graf <graf@amazon.com> | 15 | Signed-off-by: Alexander Graf <graf@amazon.com> |
17 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 16 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
17 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
18 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
18 | --- | 19 | --- |
20 | |||
19 | v4: | 21 | v4: |
20 | 22 | ||
21 | * Use recommended object type declaration pattern. | 23 | * Use recommended object type declaration pattern. |
22 | * Correctly log unimplemented code paths. | 24 | * Correctly log unimplemented code paths. |
23 | * Most header code moved to .c, type name #defines moved to vmapple.h | 25 | * Most header code moved to .c, type name #defines moved to vmapple.h |
24 | 26 | ||
25 | hw/block/virtio-blk.c | 19 ++- | 27 | v5: |
26 | hw/vmapple/Kconfig | 3 + | 28 | |
27 | hw/vmapple/meson.build | 1 + | 29 | * Corrected handling of potentially unaligned writes to virtio config area. |
28 | hw/vmapple/virtio-blk.c | 233 +++++++++++++++++++++++++++++++++ | 30 | * Simplified passing through device variant type to subobject. |
29 | include/hw/pci/pci_ids.h | 1 + | 31 | |
30 | include/hw/virtio/virtio-blk.h | 12 +- | 32 | v9: |
31 | include/hw/vmapple/vmapple.h | 4 + | 33 | |
32 | 7 files changed, 268 insertions(+), 5 deletions(-) | 34 | * Correctly specify class_size for VMAppleVirtIOBlkClass |
35 | |||
36 | v10: | ||
37 | |||
38 | * Folded v9 patch 16/16 into this one, changing the device type design to | ||
39 | provide a single device type with a variant property instead of 2 different | ||
40 | subtypes for aux and root volumes. | ||
41 | * Tidied up error reporting for the variant property. | ||
42 | |||
43 | hw/block/virtio-blk.c | 19 ++- | ||
44 | hw/core/qdev-properties-system.c | 8 ++ | ||
45 | hw/vmapple/Kconfig | 3 + | ||
46 | hw/vmapple/meson.build | 1 + | ||
47 | hw/vmapple/virtio-blk.c | 205 ++++++++++++++++++++++++++++ | ||
48 | include/hw/pci/pci_ids.h | 1 + | ||
49 | include/hw/qdev-properties-system.h | 5 + | ||
50 | include/hw/virtio/virtio-blk.h | 12 +- | ||
51 | include/hw/vmapple/vmapple.h | 2 + | ||
52 | qapi/virtio.json | 14 ++ | ||
53 | 10 files changed, 265 insertions(+), 5 deletions(-) | ||
33 | create mode 100644 hw/vmapple/virtio-blk.c | 54 | create mode 100644 hw/vmapple/virtio-blk.c |
34 | 55 | ||
35 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 56 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
36 | index XXXXXXX..XXXXXXX 100644 | 57 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/hw/block/virtio-blk.c | 58 | --- a/hw/block/virtio-blk.c |
... | ... | ||
78 | .class_init = virtio_blk_class_init, | 99 | .class_init = virtio_blk_class_init, |
79 | + .class_size = sizeof(VirtIOBlkClass), | 100 | + .class_size = sizeof(VirtIOBlkClass), |
80 | }; | 101 | }; |
81 | 102 | ||
82 | static void virtio_register_types(void) | 103 | static void virtio_register_types(void) |
104 | diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/hw/core/qdev-properties-system.c | ||
107 | +++ b/hw/core/qdev-properties-system.c | ||
108 | @@ -XXX,XX +XXX,XX @@ const PropertyInfo qdev_prop_iothread_vq_mapping_list = { | ||
109 | .set = set_iothread_vq_mapping_list, | ||
110 | .release = release_iothread_vq_mapping_list, | ||
111 | }; | ||
112 | + | ||
113 | +const PropertyInfo qdev_prop_vmapple_virtio_blk_variant = { | ||
114 | + .name = "VMAppleVirtioBlkVariant", | ||
115 | + .enum_table = &VMAppleVirtioBlkVariant_lookup, | ||
116 | + .get = qdev_propinfo_get_enum, | ||
117 | + .set = qdev_propinfo_set_enum, | ||
118 | + .set_default_value = qdev_propinfo_set_default_value_enum, | ||
119 | +}; | ||
83 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig | 120 | diff --git a/hw/vmapple/Kconfig b/hw/vmapple/Kconfig |
84 | index XXXXXXX..XXXXXXX 100644 | 121 | index XXXXXXX..XXXXXXX 100644 |
85 | --- a/hw/vmapple/Kconfig | 122 | --- a/hw/vmapple/Kconfig |
86 | +++ b/hw/vmapple/Kconfig | 123 | +++ b/hw/vmapple/Kconfig |
87 | @@ -XXX,XX +XXX,XX @@ config VMAPPLE_BDIF | 124 | @@ -XXX,XX +XXX,XX @@ config VMAPPLE_BDIF |
... | ... | ||
112 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 149 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
113 | + * | 150 | + * |
114 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 151 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
115 | + * See the COPYING file in the top-level directory. | 152 | + * See the COPYING file in the top-level directory. |
116 | + * | 153 | + * |
154 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
155 | + * | ||
117 | + * VMApple uses almost standard VirtIO Block, but with a few key differences: | 156 | + * VMApple uses almost standard VirtIO Block, but with a few key differences: |
118 | + * | 157 | + * |
119 | + * - Different PCI device/vendor ID | 158 | + * - Different PCI device/vendor ID |
120 | + * - An additional "type" identifier to differentiate AUX and Root volumes | 159 | + * - An additional "type" identifier to differentiate AUX and Root volumes |
121 | + * - An additional BARRIER command | 160 | + * - An additional BARRIER command |
122 | + */ | 161 | + */ |
123 | + | 162 | + |
124 | +#include "qemu/osdep.h" | 163 | +#include "qemu/osdep.h" |
125 | +#include "hw/vmapple/vmapple.h" | 164 | +#include "hw/vmapple/vmapple.h" |
126 | +#include "hw/virtio/virtio-blk.h" | 165 | +#include "hw/virtio/virtio-blk.h" |
127 | +#include "hw/virtio/virtio-pci.h" | 166 | +#include "hw/virtio/virtio-pci.h" |
167 | +#include "qemu/bswap.h" | ||
128 | +#include "qemu/log.h" | 168 | +#include "qemu/log.h" |
129 | +#include "qemu/module.h" | 169 | +#include "qemu/module.h" |
130 | +#include "qapi/error.h" | 170 | +#include "qapi/error.h" |
131 | + | 171 | + |
172 | +#define TYPE_VMAPPLE_VIRTIO_BLK "vmapple-virtio-blk" | ||
132 | +OBJECT_DECLARE_TYPE(VMAppleVirtIOBlk, VMAppleVirtIOBlkClass, VMAPPLE_VIRTIO_BLK) | 173 | +OBJECT_DECLARE_TYPE(VMAppleVirtIOBlk, VMAppleVirtIOBlkClass, VMAPPLE_VIRTIO_BLK) |
133 | + | 174 | + |
134 | +typedef struct VMAppleVirtIOBlkClass { | 175 | +typedef struct VMAppleVirtIOBlkClass { |
135 | + /*< private >*/ | ||
136 | + VirtIOBlkClass parent; | 176 | + VirtIOBlkClass parent; |
137 | + /*< public >*/ | 177 | + |
138 | + void (*get_config)(VirtIODevice *vdev, uint8_t *config); | 178 | + void (*get_config)(VirtIODevice *vdev, uint8_t *config); |
139 | +} VMAppleVirtIOBlkClass; | 179 | +} VMAppleVirtIOBlkClass; |
140 | + | 180 | + |
141 | +typedef struct VMAppleVirtIOBlk { | 181 | +typedef struct VMAppleVirtIOBlk { |
142 | + /* <private> */ | ||
143 | + VirtIOBlock parent_obj; | 182 | + VirtIOBlock parent_obj; |
144 | + | 183 | + |
145 | + /* <public> */ | ||
146 | + uint32_t apple_type; | 184 | + uint32_t apple_type; |
147 | +} VMAppleVirtIOBlk; | 185 | +} VMAppleVirtIOBlk; |
148 | + | 186 | + |
149 | +/* | 187 | +/* |
150 | + * vmapple-virtio-blk-pci: This extends VirtioPCIProxy. | 188 | + * vmapple-virtio-blk-pci: This extends VirtioPCIProxy. |
151 | + */ | 189 | + */ |
152 | +#define TYPE_VMAPPLE_VIRTIO_BLK_PCI "vmapple-virtio-blk-pci-base" | ||
153 | +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleVirtIOBlkPCI, VMAPPLE_VIRTIO_BLK_PCI) | 190 | +OBJECT_DECLARE_SIMPLE_TYPE(VMAppleVirtIOBlkPCI, VMAPPLE_VIRTIO_BLK_PCI) |
154 | + | 191 | + |
155 | +#define VIRTIO_BLK_T_APPLE_BARRIER 0x10000 | 192 | +#define VIRTIO_BLK_T_APPLE_BARRIER 0x10000 |
156 | + | ||
157 | +#define VIRTIO_APPLE_TYPE_ROOT 1 | ||
158 | +#define VIRTIO_APPLE_TYPE_AUX 2 | ||
159 | + | 193 | + |
160 | +static bool vmapple_virtio_blk_handle_unknown_request(VirtIOBlockReq *req, | 194 | +static bool vmapple_virtio_blk_handle_unknown_request(VirtIOBlockReq *req, |
161 | + MultiReqBuffer *mrb, | 195 | + MultiReqBuffer *mrb, |
162 | + uint32_t type) | 196 | + uint32_t type) |
163 | +{ | 197 | +{ |
... | ... | ||
188 | + vvbk->get_config(vdev, config); | 222 | + vvbk->get_config(vdev, config); |
189 | + | 223 | + |
190 | + g_assert(dev->parent_obj.config_size >= endof(struct virtio_blk_config, zoned)); | 224 | + g_assert(dev->parent_obj.config_size >= endof(struct virtio_blk_config, zoned)); |
191 | + | 225 | + |
192 | + /* Apple abuses the field for max_secure_erase_sectors as type id */ | 226 | + /* Apple abuses the field for max_secure_erase_sectors as type id */ |
193 | + blkcfg->max_secure_erase_sectors = dev->apple_type; | 227 | + stl_he_p(&blkcfg->max_secure_erase_sectors, dev->apple_type); |
194 | +} | 228 | +} |
195 | + | ||
196 | +static Property vmapple_virtio_blk_properties[] = { | ||
197 | + DEFINE_PROP_UINT32("apple-type", VMAppleVirtIOBlk, apple_type, 0), | ||
198 | + DEFINE_PROP_END_OF_LIST(), | ||
199 | +}; | ||
200 | + | 229 | + |
201 | +static void vmapple_virtio_blk_class_init(ObjectClass *klass, void *data) | 230 | +static void vmapple_virtio_blk_class_init(ObjectClass *klass, void *data) |
202 | +{ | 231 | +{ |
203 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
204 | + VirtIOBlkClass *vbk = VIRTIO_BLK_CLASS(klass); | 232 | + VirtIOBlkClass *vbk = VIRTIO_BLK_CLASS(klass); |
205 | + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); | 233 | + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); |
206 | + VMAppleVirtIOBlkClass *vvbk = VMAPPLE_VIRTIO_BLK_CLASS(klass); | 234 | + VMAppleVirtIOBlkClass *vvbk = VMAPPLE_VIRTIO_BLK_CLASS(klass); |
207 | + | 235 | + |
208 | + vbk->handle_unknown_request = vmapple_virtio_blk_handle_unknown_request; | 236 | + vbk->handle_unknown_request = vmapple_virtio_blk_handle_unknown_request; |
209 | + vvbk->get_config = vdc->get_config; | 237 | + vvbk->get_config = vdc->get_config; |
210 | + vdc->get_config = vmapple_virtio_blk_get_config; | 238 | + vdc->get_config = vmapple_virtio_blk_get_config; |
211 | + device_class_set_props(dc, vmapple_virtio_blk_properties); | ||
212 | +} | 239 | +} |
213 | + | 240 | + |
214 | +static const TypeInfo vmapple_virtio_blk_info = { | 241 | +static const TypeInfo vmapple_virtio_blk_info = { |
215 | + .name = TYPE_VMAPPLE_VIRTIO_BLK, | 242 | + .name = TYPE_VMAPPLE_VIRTIO_BLK, |
216 | + .parent = TYPE_VIRTIO_BLK, | 243 | + .parent = TYPE_VIRTIO_BLK, |
217 | + .instance_size = sizeof(VMAppleVirtIOBlk), | 244 | + .instance_size = sizeof(VMAppleVirtIOBlk), |
245 | + .class_size = sizeof(VMAppleVirtIOBlkClass), | ||
218 | + .class_init = vmapple_virtio_blk_class_init, | 246 | + .class_init = vmapple_virtio_blk_class_init, |
219 | +}; | 247 | +}; |
220 | + | 248 | + |
221 | +/* PCI Devices */ | 249 | +/* PCI Devices */ |
222 | + | 250 | + |
223 | +struct VMAppleVirtIOBlkPCI { | 251 | +struct VMAppleVirtIOBlkPCI { |
224 | + VirtIOPCIProxy parent_obj; | 252 | + VirtIOPCIProxy parent_obj; |
225 | + VMAppleVirtIOBlk vdev; | 253 | + VMAppleVirtIOBlk vdev; |
226 | + uint32_t apple_type; | 254 | + VMAppleVirtioBlkVariant variant; |
227 | +}; | 255 | +}; |
228 | + | 256 | + |
229 | + | 257 | + |
230 | +static Property vmapple_virtio_blk_pci_properties[] = { | 258 | +static Property vmapple_virtio_blk_pci_properties[] = { |
231 | + DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), | 259 | + DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0), |
232 | + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, | 260 | + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, |
233 | + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), | 261 | + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), |
234 | + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, | 262 | + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, |
235 | + DEV_NVECTORS_UNSPECIFIED), | 263 | + DEV_NVECTORS_UNSPECIFIED), |
264 | + DEFINE_PROP_VMAPPLE_VIRTIO_BLK_VARIANT("variant", VMAppleVirtIOBlkPCI, variant, | ||
265 | + VM_APPLE_VIRTIO_BLK_VARIANT_UNSPECIFIED), | ||
236 | + DEFINE_PROP_END_OF_LIST(), | 266 | + DEFINE_PROP_END_OF_LIST(), |
237 | +}; | 267 | +}; |
238 | + | 268 | + |
239 | +static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | 269 | +static void vmapple_virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) |
240 | +{ | 270 | +{ |
271 | + ERRP_GUARD(); | ||
241 | + VMAppleVirtIOBlkPCI *dev = VMAPPLE_VIRTIO_BLK_PCI(vpci_dev); | 272 | + VMAppleVirtIOBlkPCI *dev = VMAPPLE_VIRTIO_BLK_PCI(vpci_dev); |
242 | + DeviceState *vdev = DEVICE(&dev->vdev); | 273 | + DeviceState *vdev = DEVICE(&dev->vdev); |
243 | + VirtIOBlkConf *conf = &dev->vdev.parent_obj.conf; | 274 | + VirtIOBlkConf *conf = &dev->vdev.parent_obj.conf; |
275 | + | ||
276 | + if (dev->variant == VM_APPLE_VIRTIO_BLK_VARIANT_UNSPECIFIED) { | ||
277 | + error_setg(errp, "vmapple virtio block device variant unspecified"); | ||
278 | + error_append_hint(errp, | ||
279 | + "Variant property must be set to 'aux' or 'root'.\n" | ||
280 | + "Use a regular virtio-blk-pci device instead when " | ||
281 | + "neither is applicaple.\n"); | ||
282 | + return; | ||
283 | + } | ||
244 | + | 284 | + |
245 | + if (conf->num_queues == VIRTIO_BLK_AUTO_NUM_QUEUES) { | 285 | + if (conf->num_queues == VIRTIO_BLK_AUTO_NUM_QUEUES) { |
246 | + conf->num_queues = virtio_pci_optimal_num_queues(0); | 286 | + conf->num_queues = virtio_pci_optimal_num_queues(0); |
247 | + } | 287 | + } |
248 | + | 288 | + |
... | ... | ||
255 | + * Let's just expose the feature so the rest of the virtio-blk logic | 295 | + * Let's just expose the feature so the rest of the virtio-blk logic |
256 | + * allocates enough space for us. The guest will ignore zones anyway. | 296 | + * allocates enough space for us. The guest will ignore zones anyway. |
257 | + */ | 297 | + */ |
258 | + virtio_add_feature(&dev->vdev.parent_obj.host_features, VIRTIO_BLK_F_ZONED); | 298 | + virtio_add_feature(&dev->vdev.parent_obj.host_features, VIRTIO_BLK_F_ZONED); |
259 | + /* Propagate the apple type down to the virtio-blk device */ | 299 | + /* Propagate the apple type down to the virtio-blk device */ |
260 | + qdev_prop_set_uint32(DEVICE(&dev->vdev), "apple-type", dev->apple_type); | 300 | + dev->vdev.apple_type = dev->variant; |
261 | + /* and spawn the virtio-blk device */ | 301 | + /* and spawn the virtio-blk device */ |
262 | + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); | 302 | + qdev_realize(vdev, BUS(&vpci_dev->bus), errp); |
263 | + | 303 | + |
264 | + /* | 304 | + /* |
265 | + * The virtio-pci machinery adjusts its vendor/device ID based on whether | 305 | + * The virtio-pci machinery adjusts its vendor/device ID based on whether |
... | ... | ||
293 | + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), | 333 | + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), |
294 | + TYPE_VMAPPLE_VIRTIO_BLK); | 334 | + TYPE_VMAPPLE_VIRTIO_BLK); |
295 | +} | 335 | +} |
296 | + | 336 | + |
297 | +static const VirtioPCIDeviceTypeInfo vmapple_virtio_blk_pci_info = { | 337 | +static const VirtioPCIDeviceTypeInfo vmapple_virtio_blk_pci_info = { |
298 | + .base_name = TYPE_VMAPPLE_VIRTIO_BLK_PCI, | 338 | + .generic_name = TYPE_VMAPPLE_VIRTIO_BLK_PCI, |
299 | + .generic_name = "vmapple-virtio-blk-pci", | ||
300 | + .instance_size = sizeof(VMAppleVirtIOBlkPCI), | 339 | + .instance_size = sizeof(VMAppleVirtIOBlkPCI), |
301 | + .instance_init = vmapple_virtio_blk_pci_instance_init, | 340 | + .instance_init = vmapple_virtio_blk_pci_instance_init, |
302 | + .class_init = vmapple_virtio_blk_pci_class_init, | 341 | + .class_init = vmapple_virtio_blk_pci_class_init, |
303 | +}; | 342 | +}; |
304 | + | 343 | + |
305 | +static void vmapple_virtio_root_instance_init(Object *obj) | ||
306 | +{ | ||
307 | + VMAppleVirtIOBlkPCI *dev = VMAPPLE_VIRTIO_BLK_PCI(obj); | ||
308 | + | ||
309 | + dev->apple_type = VIRTIO_APPLE_TYPE_ROOT; | ||
310 | +} | ||
311 | + | ||
312 | +static const TypeInfo vmapple_virtio_root_info = { | ||
313 | + .name = TYPE_VMAPPLE_VIRTIO_ROOT, | ||
314 | + .parent = "vmapple-virtio-blk-pci", | ||
315 | + .instance_size = sizeof(VMAppleVirtIOBlkPCI), | ||
316 | + .instance_init = vmapple_virtio_root_instance_init, | ||
317 | +}; | ||
318 | + | ||
319 | +static void vmapple_virtio_aux_instance_init(Object *obj) | ||
320 | +{ | ||
321 | + VMAppleVirtIOBlkPCI *dev = VMAPPLE_VIRTIO_BLK_PCI(obj); | ||
322 | + | ||
323 | + dev->apple_type = VIRTIO_APPLE_TYPE_AUX; | ||
324 | +} | ||
325 | + | ||
326 | +static const TypeInfo vmapple_virtio_aux_info = { | ||
327 | + .name = TYPE_VMAPPLE_VIRTIO_AUX, | ||
328 | + .parent = "vmapple-virtio-blk-pci", | ||
329 | + .instance_size = sizeof(VMAppleVirtIOBlkPCI), | ||
330 | + .instance_init = vmapple_virtio_aux_instance_init, | ||
331 | +}; | ||
332 | + | ||
333 | +static void vmapple_virtio_blk_register_types(void) | 344 | +static void vmapple_virtio_blk_register_types(void) |
334 | +{ | 345 | +{ |
335 | + type_register_static(&vmapple_virtio_blk_info); | 346 | + type_register_static(&vmapple_virtio_blk_info); |
336 | + virtio_pci_types_register(&vmapple_virtio_blk_pci_info); | 347 | + virtio_pci_types_register(&vmapple_virtio_blk_pci_info); |
337 | + type_register_static(&vmapple_virtio_root_info); | ||
338 | + type_register_static(&vmapple_virtio_aux_info); | ||
339 | +} | 348 | +} |
340 | + | 349 | + |
341 | +type_init(vmapple_virtio_blk_register_types) | 350 | +type_init(vmapple_virtio_blk_register_types) |
342 | diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h | 351 | diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h |
343 | index XXXXXXX..XXXXXXX 100644 | 352 | index XXXXXXX..XXXXXXX 100644 |
... | ... | ||
349 | #define PCI_DEVICE_ID_APPLE_UNI_N_GMAC 0x0021 | 358 | #define PCI_DEVICE_ID_APPLE_UNI_N_GMAC 0x0021 |
350 | +#define PCI_DEVICE_ID_APPLE_VIRTIO_BLK 0x1a00 | 359 | +#define PCI_DEVICE_ID_APPLE_VIRTIO_BLK 0x1a00 |
351 | 360 | ||
352 | #define PCI_VENDOR_ID_SUN 0x108e | 361 | #define PCI_VENDOR_ID_SUN 0x108e |
353 | #define PCI_DEVICE_ID_SUN_EBUS 0x1000 | 362 | #define PCI_DEVICE_ID_SUN_EBUS 0x1000 |
363 | diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-system.h | ||
364 | index XXXXXXX..XXXXXXX 100644 | ||
365 | --- a/include/hw/qdev-properties-system.h | ||
366 | +++ b/include/hw/qdev-properties-system.h | ||
367 | @@ -XXX,XX +XXX,XX @@ extern const PropertyInfo qdev_prop_pcie_link_speed; | ||
368 | extern const PropertyInfo qdev_prop_pcie_link_width; | ||
369 | extern const PropertyInfo qdev_prop_cpus390entitlement; | ||
370 | extern const PropertyInfo qdev_prop_iothread_vq_mapping_list; | ||
371 | +extern const PropertyInfo qdev_prop_vmapple_virtio_blk_variant; | ||
372 | |||
373 | #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ | ||
374 | DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t) | ||
375 | @@ -XXX,XX +XXX,XX @@ extern const PropertyInfo qdev_prop_iothread_vq_mapping_list; | ||
376 | DEFINE_PROP(_name, _state, _field, qdev_prop_iothread_vq_mapping_list, \ | ||
377 | IOThreadVirtQueueMappingList *) | ||
378 | |||
379 | +#define DEFINE_PROP_VMAPPLE_VIRTIO_BLK_VARIANT(_n, _s, _f, _d) \ | ||
380 | + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_vmapple_virtio_blk_variant, \ | ||
381 | + VMAppleVirtioBlkVariant) | ||
382 | + | ||
383 | #endif | ||
354 | diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h | 384 | diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h |
355 | index XXXXXXX..XXXXXXX 100644 | 385 | index XXXXXXX..XXXXXXX 100644 |
356 | --- a/include/hw/virtio/virtio-blk.h | 386 | --- a/include/hw/virtio/virtio-blk.h |
357 | +++ b/include/hw/virtio/virtio-blk.h | 387 | +++ b/include/hw/virtio/virtio-blk.h |
358 | @@ -XXX,XX +XXX,XX @@ | 388 | @@ -XXX,XX +XXX,XX @@ |
... | ... | ||
387 | +++ b/include/hw/vmapple/vmapple.h | 417 | +++ b/include/hw/vmapple/vmapple.h |
388 | @@ -XXX,XX +XXX,XX @@ | 418 | @@ -XXX,XX +XXX,XX @@ |
389 | 419 | ||
390 | #define TYPE_VMAPPLE_CFG "vmapple-cfg" | 420 | #define TYPE_VMAPPLE_CFG "vmapple-cfg" |
391 | 421 | ||
392 | +#define TYPE_VMAPPLE_VIRTIO_BLK "vmapple-virtio-blk" | 422 | +#define TYPE_VMAPPLE_VIRTIO_BLK_PCI "vmapple-virtio-blk-pci" |
393 | +#define TYPE_VMAPPLE_VIRTIO_ROOT "vmapple-virtio-root" | ||
394 | +#define TYPE_VMAPPLE_VIRTIO_AUX "vmapple-virtio-aux" | ||
395 | + | 423 | + |
396 | #endif /* HW_VMAPPLE_VMAPPLE_H */ | 424 | #endif /* HW_VMAPPLE_VMAPPLE_H */ |
425 | diff --git a/qapi/virtio.json b/qapi/virtio.json | ||
426 | index XXXXXXX..XXXXXXX 100644 | ||
427 | --- a/qapi/virtio.json | ||
428 | +++ b/qapi/virtio.json | ||
429 | @@ -XXX,XX +XXX,XX @@ | ||
430 | ## | ||
431 | { 'enum': 'GranuleMode', | ||
432 | 'data': [ '4k', '8k', '16k', '64k', 'host' ] } | ||
433 | + | ||
434 | +## | ||
435 | +# @VMAppleVirtioBlkVariant: | ||
436 | +# | ||
437 | +# @unspecified: The default, not a valid setting. | ||
438 | +# | ||
439 | +# @root: Block device holding the root volume | ||
440 | +# | ||
441 | +# @aux: Block device holding auxiliary data required for boot | ||
442 | +# | ||
443 | +# Since: 9.2 | ||
444 | +## | ||
445 | +{ 'enum': 'VMAppleVirtioBlkVariant', | ||
446 | + 'data': [ 'unspecified', 'root', 'aux' ] } | ||
397 | -- | 447 | -- |
398 | 2.39.3 (Apple Git-145) | 448 | 2.39.5 (Apple Git-154) |
399 | 449 | ||
400 | 450 | diff view generated by jsdifflib |
1 | The virtio_blk_free_request() function has been a 1-liner forwarding | 1 | The virtio_blk_free_request() function has been a 1-liner forwarding |
---|---|---|---|
2 | to g_free() for a while now. We may as well call g_free on the request | 2 | to g_free() for a while now. We may as well call g_free on the request |
3 | pointer directly. | 3 | pointer directly. |
4 | 4 | ||
5 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 5 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
6 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
7 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
6 | --- | 8 | --- |
7 | hw/block/virtio-blk.c | 43 +++++++++++++++------------------- | 9 | hw/block/virtio-blk.c | 43 +++++++++++++++------------------- |
8 | hw/vmapple/virtio-blk.c | 2 +- | 10 | hw/vmapple/virtio-blk.c | 2 +- |
9 | include/hw/virtio/virtio-blk.h | 1 - | 11 | include/hw/virtio/virtio-blk.h | 1 - |
10 | 3 files changed, 20 insertions(+), 26 deletions(-) | 12 | 3 files changed, 20 insertions(+), 26 deletions(-) |
... | ... | ||
220 | -void virtio_blk_free_request(VirtIOBlockReq *req); | 222 | -void virtio_blk_free_request(VirtIOBlockReq *req); |
221 | void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status); | 223 | void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status); |
222 | 224 | ||
223 | #endif | 225 | #endif |
224 | -- | 226 | -- |
225 | 2.39.3 (Apple Git-145) | 227 | 2.39.5 (Apple Git-154) | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
15 | $ qemu-system-aarch64 -accel hvf -M vmapple,uuid=0x1234 -m 4G \ | 15 | $ qemu-system-aarch64 -accel hvf -M vmapple,uuid=0x1234 -m 4G \ |
16 | -bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin | 16 | -bios /System/Library/Frameworks/Virtualization.framework/Versions/A/Resources/AVPBooter.vmapple2.bin |
17 | -drive file=aux,if=pflash,format=raw \ | 17 | -drive file=aux,if=pflash,format=raw \ |
18 | -drive file=root,if=pflash,format=raw \ | 18 | -drive file=root,if=pflash,format=raw \ |
19 | -drive file=aux,if=none,id=aux,format=raw \ | 19 | -drive file=aux,if=none,id=aux,format=raw \ |
20 | -device vmapple-virtio-aux,drive=aux \ | 20 | -device vmapple-virtio-blk-pci,variant=aux,drive=aux \ |
21 | -drive file=root,if=none,id=root,format=raw \ | 21 | -drive file=root,if=none,id=root,format=raw \ |
22 | -device vmapple-virtio-root,drive=root | 22 | -device vmapple-virtio-blk-pci,variant=root,drive=root |
23 | 23 | ||
24 | With all these in place, you should be able to see macOS booting | 24 | With all these in place, you should be able to see macOS booting |
25 | successfully. | 25 | successfully. |
26 | 26 | ||
27 | Known issues: | 27 | Known issues: |
28 | - Keyboard and mouse/tablet input is laggy. The reason for this is | 28 | - Keyboard and mouse/tablet input is laggy. The reason is a quirk/bug |
29 | either that macOS's XHCI driver is broken when the device/platform | 29 | in macOS's XHCI driver when using pin-based interrupts instead of |
30 | does not support MSI/MSI-X, or there's some unfortunate interplay | 30 | MSI-X. A workaround is in the works. |
31 | with Qemu's XHCI implementation in this scenario. | ||
32 | - Currently only macOS 12 guests are supported. The boot process for | 31 | - Currently only macOS 12 guests are supported. The boot process for |
33 | 13+ will need further investigation and adjustment. | 32 | 13+ will need further investigation and adjustment. |
34 | 33 | ||
35 | Signed-off-by: Alexander Graf <graf@amazon.com> | 34 | Signed-off-by: Alexander Graf <graf@amazon.com> |
36 | Co-authored-by: Phil Dennis-Jordan <phil@philjordan.eu> | 35 | Co-authored-by: Phil Dennis-Jordan <phil@philjordan.eu> |
37 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> | 36 | Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu> |
37 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
38 | Tested-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
38 | --- | 39 | --- |
40 | |||
39 | v3: | 41 | v3: |
40 | * Rebased on latest upstream, updated affinity and NIC creation | 42 | * Rebased on latest upstream, updated affinity and NIC creation |
41 | API usage | 43 | API usage |
42 | * Included Apple-variant virtio-blk in build dependency | 44 | * Included Apple-variant virtio-blk in build dependency |
43 | * Updated API usage for setting 'redist-region-count' array-typed property on GIC. | 45 | * Updated API usage for setting 'redist-region-count' array-typed property on GIC. |
44 | * Switched from virtio HID devices (for which macOS 12 does not contain drivers) to an XHCI USB controller and USB HID devices. | 46 | * Switched from virtio HID devices (for which macOS 12 does not contain |
47 | drivers) to an XHCI USB controller and USB HID devices. | ||
45 | 48 | ||
46 | v4: | 49 | v4: |
47 | * Fixups for v4 changes to the other patches in the set. | 50 | * Fixups for v4 changes to the other patches in the set. |
48 | * Corrected the assert macro to use | 51 | * Corrected the assert macro to use |
49 | * Removed superfluous endian conversions corresponding to cfg's. | 52 | * Removed superfluous endian conversions corresponding to cfg's. |
50 | * Init error handling improvement. | 53 | * Init error handling improvement. |
51 | * No need to select CPU type on TCG, as only HVF is supported. | 54 | * No need to select CPU type on TCG, as only HVF is supported. |
52 | * Machine type version bumped to 9.2 | 55 | * Machine type version bumped to 9.2 |
53 | * #include order improved | 56 | * #include order improved |
54 | 57 | ||
58 | v5: | ||
59 | * Fixed memory reservation for ecam alias region. | ||
60 | * Better error handling setting properties on devices. | ||
61 | * Simplified the machine ECID/UUID extraction script and actually created a | ||
62 | file for it rather than quoting its code in documentation. | ||
63 | |||
64 | v7: | ||
65 | * Tiny error handling fix, un-inlined function. | ||
66 | |||
67 | v8: | ||
68 | * Use object_property_add_uint64_ptr rather than defining custom UUID | ||
69 | property get/set functions. | ||
70 | |||
71 | v9: | ||
72 | * Documentation improvements | ||
73 | * Fixed variable name and struct field used during pvpanic device creation. | ||
74 | |||
75 | v10: | ||
76 | * Documentation fixup for changed virtio-blk device type. | ||
77 | * Small improvements to shell commands in documentation. | ||
78 | * Improved propagation of errors during cfg device instantiation. | ||
79 | |||
80 | v11: | ||
81 | * Quoted more strings in the documentation's shell script code. | ||
82 | |||
83 | v13: | ||
84 | * Bumped the machine type version from 9.2 to 10.0. | ||
85 | |||
55 | MAINTAINERS | 1 + | 86 | MAINTAINERS | 1 + |
87 | contrib/vmapple/uuid.sh | 9 + | ||
56 | docs/system/arm/vmapple.rst | 63 ++++ | 88 | docs/system/arm/vmapple.rst | 63 ++++ |
57 | docs/system/target-arm.rst | 1 + | 89 | docs/system/target-arm.rst | 1 + |
58 | hw/vmapple/Kconfig | 20 ++ | 90 | hw/vmapple/Kconfig | 20 ++ |
59 | hw/vmapple/meson.build | 1 + | 91 | hw/vmapple/meson.build | 1 + |
60 | hw/vmapple/vmapple.c | 652 ++++++++++++++++++++++++++++++++++++ | 92 | hw/vmapple/vmapple.c | 646 ++++++++++++++++++++++++++++++++++++ |
61 | 6 files changed, 738 insertions(+) | 93 | 7 files changed, 741 insertions(+) |
94 | create mode 100755 contrib/vmapple/uuid.sh | ||
62 | create mode 100644 docs/system/arm/vmapple.rst | 95 | create mode 100644 docs/system/arm/vmapple.rst |
63 | create mode 100644 hw/vmapple/vmapple.c | 96 | create mode 100644 hw/vmapple/vmapple.c |
64 | 97 | ||
65 | diff --git a/MAINTAINERS b/MAINTAINERS | 98 | diff --git a/MAINTAINERS b/MAINTAINERS |
66 | index XXXXXXX..XXXXXXX 100644 | 99 | index XXXXXXX..XXXXXXX 100644 |
... | ... | ||
72 | F: include/hw/vmapple/* | 105 | F: include/hw/vmapple/* |
73 | +F: docs/system/arm/vmapple.rst | 106 | +F: docs/system/arm/vmapple.rst |
74 | 107 | ||
75 | Subsystems | 108 | Subsystems |
76 | ---------- | 109 | ---------- |
110 | diff --git a/contrib/vmapple/uuid.sh b/contrib/vmapple/uuid.sh | ||
111 | new file mode 100755 | ||
112 | index XXXXXXX..XXXXXXX | ||
113 | --- /dev/null | ||
114 | +++ b/contrib/vmapple/uuid.sh | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | +#!/bin/sh | ||
117 | +# Used for converting a guest provisioned using Virtualization.framework | ||
118 | +# for use with the QEMU 'vmapple' aarch64 machine type. | ||
119 | +# | ||
120 | +# Extracts the Machine UUID from Virtualization.framework VM JSON file. | ||
121 | +# (as produced by 'macosvm', passed as command line argument) | ||
122 | + | ||
123 | +plutil -extract machineId raw "$1" | base64 -d | plutil -extract ECID raw - | ||
124 | + | ||
77 | diff --git a/docs/system/arm/vmapple.rst b/docs/system/arm/vmapple.rst | 125 | diff --git a/docs/system/arm/vmapple.rst b/docs/system/arm/vmapple.rst |
78 | new file mode 100644 | 126 | new file mode 100644 |
79 | index XXXXXXX..XXXXXXX | 127 | index XXXXXXX..XXXXXXX |
80 | --- /dev/null | 128 | --- /dev/null |
81 | +++ b/docs/system/arm/vmapple.rst | 129 | +++ b/docs/system/arm/vmapple.rst |
... | ... | ||
92 | + | 140 | + |
93 | +To run the vmapple machine model, you need to | 141 | +To run the vmapple machine model, you need to |
94 | + | 142 | + |
95 | + * Run on Apple Silicon | 143 | + * Run on Apple Silicon |
96 | + * Run on macOS 12.0 or above | 144 | + * Run on macOS 12.0 or above |
97 | + * Have an already installed copy of a Virtualization.Framework macOS 12 virtual machine. I will | 145 | + * Have an already installed copy of a Virtualization.Framework macOS 12 virtual |
98 | + assume that you installed it using the macosvm CLI. | 146 | + machine. Note that newer versions than 12.x are currently NOT supported on |
147 | + the guest side. I will assume that you installed it using the | ||
148 | + `macosvm <https://github.com/s-u/macosvm>` CLI. | ||
99 | + | 149 | + |
100 | +First, we need to extract the UUID from the virtual machine that you installed. You can do this | 150 | +First, we need to extract the UUID from the virtual machine that you installed. You can do this |
101 | +by running the following shell script: | 151 | +by running the shell script in contrib/vmapple/uuid.sh on the macosvm.json file. |
102 | + | 152 | + |
103 | +.. code-block:: bash | 153 | +.. code-block:: bash |
104 | + :caption: uuid.sh script to extract the UUID from a macosvm.json file | 154 | + :caption: uuid.sh script to extract the UUID from a macosvm.json file |
105 | + | 155 | + |
106 | + #!/bin/bash | 156 | + $ contrib/vmapple/uuid.sh "path/to/macosvm.json" |
107 | + | ||
108 | + MID=$(cat "$1" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["machineId"]);') | ||
109 | + echo "$MID" | base64 -d | plutil -extract ECID raw - | ||
110 | + | 157 | + |
111 | +Now we also need to trim the aux partition. It contains metadata that we can just discard: | 158 | +Now we also need to trim the aux partition. It contains metadata that we can just discard: |
112 | + | 159 | + |
113 | +.. code-block:: bash | 160 | +.. code-block:: bash |
114 | + :caption: Command to trim the aux file | 161 | + :caption: Command to trim the aux file |
... | ... | ||
123 | +to get better interactive access into the target system: | 170 | +to get better interactive access into the target system: |
124 | + | 171 | + |
125 | +.. code-block:: bash | 172 | +.. code-block:: bash |
126 | + :caption: Example execution command line | 173 | + :caption: Example execution command line |
127 | + | 174 | + |
128 | + $ UUID=$(uuid.sh macosvm.json) | 175 | + $ UUID="$(contrib/vmapple/uuid.sh 'macosvm.json')" |
129 | + $ AVPBOOTER=/System/Library/Frameworks/Virtualization.framework/Resources/AVPBooter.vmapple2.bin | 176 | + $ AVPBOOTER="/System/Library/Frameworks/Virtualization.framework/Resources/AVPBooter.vmapple2.bin" |
130 | + $ AUX=aux.img.trimmed | 177 | + $ AUX="aux.img.trimmed" |
131 | + $ DISK=disk.img | 178 | + $ DISK="disk.img" |
132 | + $ qemu-system-aarch64 \ | 179 | + $ qemu-system-aarch64 \ |
133 | + -serial mon:stdio \ | 180 | + -serial mon:stdio \ |
134 | + -m 4G \ | 181 | + -m 4G \ |
135 | + -accel hvf \ | 182 | + -accel hvf \ |
136 | + -M vmapple,uuid=$UUID \ | 183 | + -M vmapple,uuid="$UUID" \ |
137 | + -bios $AVPBOOTER \ | 184 | + -bios "$AVPBOOTER" \ |
138 | + -drive file="$AUX",if=pflash,format=raw \ | 185 | + -drive file="$AUX",if=pflash,format=raw \ |
139 | + -drive file="$DISK",if=pflash,format=raw \ | 186 | + -drive file="$DISK",if=pflash,format=raw \ |
140 | + -drive file="$AUX",if=none,id=aux,format=raw \ | 187 | + -drive file="$AUX",if=none,id=aux,format=raw \ |
141 | + -drive file="$DISK",if=none,id=root,format=raw \ | 188 | + -drive file="$DISK",if=none,id=root,format=raw \ |
142 | + -device vmapple-virtio-aux,drive=aux \ | 189 | + -device vmapple-virtio-blk-pci,variant=aux,drive=aux \ |
143 | + -device vmapple-virtio-root,drive=root \ | 190 | + -device vmapple-virtio-blk-pci,variant=root,drive=root \ |
144 | + -net user,ipv6=off,hostfwd=tcp::2222-:22,hostfwd=tcp::5901-:5900 \ | 191 | + -netdev user,id=net0,ipv6=off,hostfwd=tcp::2222-:22,hostfwd=tcp::5901-:5900 \ |
145 | + -net nic,model=virtio-net-pci \ | 192 | + -device virtio-net-pci,netdev=net0 |
193 | + | ||
146 | diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst | 194 | diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst |
147 | index XXXXXXX..XXXXXXX 100644 | 195 | index XXXXXXX..XXXXXXX 100644 |
148 | --- a/docs/system/target-arm.rst | 196 | --- a/docs/system/target-arm.rst |
149 | +++ b/docs/system/target-arm.rst | 197 | +++ b/docs/system/target-arm.rst |
150 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | 198 | @@ -XXX,XX +XXX,XX @@ Board-specific documentation |
151 | arm/stellaris | 199 | arm/stellaris |
152 | arm/stm32 | 200 | arm/stm32 |
153 | arm/virt | 201 | arm/virt |
154 | + arm/vmapple | 202 | + arm/vmapple |
155 | arm/xenpvh | 203 | arm/xenpvh |
... | ... | ||
204 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | 252 | + * Copyright © 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
205 | + * | 253 | + * |
206 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 254 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
207 | + * See the COPYING file in the top-level directory. | 255 | + * See the COPYING file in the top-level directory. |
208 | + * | 256 | + * |
257 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
258 | + * | ||
209 | + * VMApple is the device model that the macOS built-in hypervisor called | 259 | + * VMApple is the device model that the macOS built-in hypervisor called |
210 | + * "Virtualization.framework" exposes to Apple Silicon macOS guests. The | 260 | + * "Virtualization.framework" exposes to Apple Silicon macOS guests. The |
211 | + * machine model in this file implements the same device model in QEMU, but | 261 | + * machine model in this file implements the same device model in QEMU, but |
212 | + * does not use any code from Virtualization.Framework. | 262 | + * does not use any code from Virtualization.Framework. |
213 | + */ | 263 | + */ |
... | ... | ||
264 | + struct arm_boot_info bootinfo; | 314 | + struct arm_boot_info bootinfo; |
265 | + MemMapEntry *memmap; | 315 | + MemMapEntry *memmap; |
266 | + const int *irqmap; | 316 | + const int *irqmap; |
267 | + DeviceState *gic; | 317 | + DeviceState *gic; |
268 | + DeviceState *cfg; | 318 | + DeviceState *cfg; |
319 | + DeviceState *pvpanic; | ||
269 | + Notifier powerdown_notifier; | 320 | + Notifier powerdown_notifier; |
270 | + PCIBus *bus; | 321 | + PCIBus *bus; |
271 | + MemoryRegion fw_mr; | 322 | + MemoryRegion fw_mr; |
323 | + MemoryRegion ecam_alias; | ||
272 | + uint64_t uuid; | 324 | + uint64_t uuid; |
273 | +}; | 325 | +}; |
274 | + | 326 | + |
275 | +#define DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, latest) \ | 327 | +#define DEFINE_VMAPPLE_MACHINE_LATEST(major, minor, latest) \ |
276 | + static void vmapple##major##_##minor##_class_init(ObjectClass *oc, \ | 328 | + static void vmapple##major##_##minor##_class_init(ObjectClass *oc, \ |
... | ... | ||
394 | + sysbus_realize_and_unref(bdif_sb, &error_fatal); | 446 | + sysbus_realize_and_unref(bdif_sb, &error_fatal); |
395 | +} | 447 | +} |
396 | + | 448 | + |
397 | +static void create_pvpanic(VMAppleMachineState *vms, MemoryRegion *mem) | 449 | +static void create_pvpanic(VMAppleMachineState *vms, MemoryRegion *mem) |
398 | +{ | 450 | +{ |
399 | + SysBusDevice *cfg; | 451 | + SysBusDevice *pvpanic; |
400 | + | 452 | + |
401 | + vms->cfg = qdev_new(TYPE_PVPANIC_MMIO_DEVICE); | 453 | + vms->pvpanic = qdev_new(TYPE_PVPANIC_MMIO_DEVICE); |
402 | + cfg = SYS_BUS_DEVICE(vms->cfg); | 454 | + pvpanic = SYS_BUS_DEVICE(vms->pvpanic); |
403 | + sysbus_mmio_map(cfg, 0, vms->memmap[VMAPPLE_PVPANIC].base); | 455 | + sysbus_mmio_map(pvpanic, 0, vms->memmap[VMAPPLE_PVPANIC].base); |
404 | + | 456 | + |
405 | + sysbus_realize_and_unref(cfg, &error_fatal); | 457 | + sysbus_realize_and_unref(pvpanic, &error_fatal); |
406 | +} | 458 | +} |
407 | + | 459 | + |
408 | +static void create_cfg(VMAppleMachineState *vms, MemoryRegion *mem) | 460 | +static bool create_cfg(VMAppleMachineState *vms, MemoryRegion *mem, |
409 | +{ | 461 | + Error **errp) |
462 | +{ | ||
463 | + ERRP_GUARD(); | ||
410 | + SysBusDevice *cfg; | 464 | + SysBusDevice *cfg; |
411 | + MachineState *machine = MACHINE(vms); | 465 | + MachineState *machine = MACHINE(vms); |
412 | + uint32_t rnd = 1; | 466 | + uint32_t rnd = 1; |
413 | + | 467 | + |
414 | + vms->cfg = qdev_new(TYPE_VMAPPLE_CFG); | 468 | + vms->cfg = qdev_new(TYPE_VMAPPLE_CFG); |
... | ... | ||
420 | + qdev_prop_set_uint32(vms->cfg, "nr-cpus", machine->smp.cpus); | 474 | + qdev_prop_set_uint32(vms->cfg, "nr-cpus", machine->smp.cpus); |
421 | + qdev_prop_set_uint64(vms->cfg, "ecid", vms->uuid); | 475 | + qdev_prop_set_uint64(vms->cfg, "ecid", vms->uuid); |
422 | + qdev_prop_set_uint64(vms->cfg, "ram-size", machine->ram_size); | 476 | + qdev_prop_set_uint64(vms->cfg, "ram-size", machine->ram_size); |
423 | + qdev_prop_set_uint32(vms->cfg, "rnd", rnd); | 477 | + qdev_prop_set_uint32(vms->cfg, "rnd", rnd); |
424 | + | 478 | + |
425 | + sysbus_realize_and_unref(cfg, &error_fatal); | 479 | + if (!sysbus_realize_and_unref(cfg, errp)) { |
480 | + error_prepend(errp, "Error creating vmapple cfg device: "); | ||
481 | + return false; | ||
482 | + } | ||
483 | + | ||
484 | + return true; | ||
426 | +} | 485 | +} |
427 | + | 486 | + |
428 | +static void create_gfx(VMAppleMachineState *vms, MemoryRegion *mem) | 487 | +static void create_gfx(VMAppleMachineState *vms, MemoryRegion *mem) |
429 | +{ | 488 | +{ |
430 | + int irq_gfx = vms->irqmap[VMAPPLE_APV_GFX]; | 489 | + int irq_gfx = vms->irqmap[VMAPPLE_APV_GFX]; |
431 | + int irq_iosfc = vms->irqmap[VMAPPLE_APV_IOSFC]; | 490 | + int irq_iosfc = vms->irqmap[VMAPPLE_APV_IOSFC]; |
432 | + SysBusDevice *aes; | 491 | + SysBusDevice *gfx; |
433 | + | 492 | + |
434 | + aes = SYS_BUS_DEVICE(qdev_new("apple-gfx-mmio")); | 493 | + gfx = SYS_BUS_DEVICE(qdev_new("apple-gfx-mmio")); |
435 | + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_APV_GFX].base); | 494 | + sysbus_mmio_map(gfx, 0, vms->memmap[VMAPPLE_APV_GFX].base); |
436 | + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_APV_IOSFC].base); | 495 | + sysbus_mmio_map(gfx, 1, vms->memmap[VMAPPLE_APV_IOSFC].base); |
437 | + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq_gfx)); | 496 | + sysbus_connect_irq(gfx, 0, qdev_get_gpio_in(vms->gic, irq_gfx)); |
438 | + sysbus_connect_irq(aes, 1, qdev_get_gpio_in(vms->gic, irq_iosfc)); | 497 | + sysbus_connect_irq(gfx, 1, qdev_get_gpio_in(vms->gic, irq_iosfc)); |
439 | + sysbus_realize_and_unref(aes, &error_fatal); | 498 | + sysbus_realize_and_unref(gfx, &error_fatal); |
440 | +} | 499 | +} |
441 | + | 500 | + |
442 | +static void create_aes(VMAppleMachineState *vms, MemoryRegion *mem) | 501 | +static void create_aes(VMAppleMachineState *vms, MemoryRegion *mem) |
443 | +{ | 502 | +{ |
444 | + int irq = vms->irqmap[VMAPPLE_AES_1]; | 503 | + int irq = vms->irqmap[VMAPPLE_AES_1]; |
445 | + SysBusDevice *aes; | 504 | + SysBusDevice *aes; |
446 | + | 505 | + |
447 | + aes = SYS_BUS_DEVICE(qdev_new("apple-aes")); | 506 | + aes = SYS_BUS_DEVICE(qdev_new(TYPE_APPLE_AES)); |
448 | + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_AES_1].base); | 507 | + sysbus_mmio_map(aes, 0, vms->memmap[VMAPPLE_AES_1].base); |
449 | + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_AES_2].base); | 508 | + sysbus_mmio_map(aes, 1, vms->memmap[VMAPPLE_AES_2].base); |
450 | + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq)); | 509 | + sysbus_connect_irq(aes, 0, qdev_get_gpio_in(vms->gic, irq)); |
451 | + sysbus_realize_and_unref(aes, &error_fatal); | 510 | + sysbus_realize_and_unref(aes, &error_fatal); |
452 | +} | 511 | +} |
453 | + | 512 | + |
454 | +static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) | 513 | +static int arm_gic_ppi_index(int cpu_nr, int ppi_index) |
455 | +{ | 514 | +{ |
456 | + return NUM_IRQS + cpu_nr * GIC_INTERNAL + ppi_index; | 515 | + return NUM_IRQS + cpu_nr * GIC_INTERNAL + ppi_index; |
457 | +} | 516 | +} |
458 | + | 517 | + |
459 | +static void create_gic(VMAppleMachineState *vms, MemoryRegion *mem) | 518 | +static void create_gic(VMAppleMachineState *vms, MemoryRegion *mem) |
... | ... | ||
597 | + hwaddr base_ecam = vms->memmap[VMAPPLE_PCIE_ECAM].base; | 656 | + hwaddr base_ecam = vms->memmap[VMAPPLE_PCIE_ECAM].base; |
598 | + hwaddr size_ecam = vms->memmap[VMAPPLE_PCIE_ECAM].size; | 657 | + hwaddr size_ecam = vms->memmap[VMAPPLE_PCIE_ECAM].size; |
599 | + int irq = vms->irqmap[VMAPPLE_PCIE]; | 658 | + int irq = vms->irqmap[VMAPPLE_PCIE]; |
600 | + MemoryRegion *mmio_alias; | 659 | + MemoryRegion *mmio_alias; |
601 | + MemoryRegion *mmio_reg; | 660 | + MemoryRegion *mmio_reg; |
602 | + MemoryRegion *ecam_alias; | ||
603 | + MemoryRegion *ecam_reg; | 661 | + MemoryRegion *ecam_reg; |
604 | + DeviceState *dev; | 662 | + DeviceState *dev; |
605 | + int i; | 663 | + int i; |
606 | + PCIHostState *pci; | 664 | + PCIHostState *pci; |
607 | + DeviceState *usb_controller; | 665 | + DeviceState *usb_controller; |
... | ... | ||
610 | + dev = qdev_new(TYPE_GPEX_HOST); | 668 | + dev = qdev_new(TYPE_GPEX_HOST); |
611 | + qdev_prop_set_uint32(dev, "num-irqs", GPEX_NUM_IRQS); | 669 | + qdev_prop_set_uint32(dev, "num-irqs", GPEX_NUM_IRQS); |
612 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | 670 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
613 | + | 671 | + |
614 | + /* Map only the first size_ecam bytes of ECAM space */ | 672 | + /* Map only the first size_ecam bytes of ECAM space */ |
615 | + ecam_alias = g_new0(MemoryRegion, 1); | ||
616 | + ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); | 673 | + ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); |
617 | + memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam", | 674 | + memory_region_init_alias(&vms->ecam_alias, OBJECT(dev), "pcie-ecam", |
618 | + ecam_reg, 0, size_ecam); | 675 | + ecam_reg, 0, size_ecam); |
619 | + memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias); | 676 | + memory_region_add_subregion(get_system_memory(), base_ecam, |
677 | + &vms->ecam_alias); | ||
620 | + | 678 | + |
621 | + /* | 679 | + /* |
622 | + * Map the MMIO window from [0x50000000-0x7fff0000] in PCI space into | 680 | + * Map the MMIO window from [0x50000000-0x7fff0000] in PCI space into |
623 | + * system address space at [0x50000000-0x7fff0000]. | 681 | + * system address space at [0x50000000-0x7fff0000]. |
624 | + */ | 682 | + */ |
... | ... | ||
682 | + break; | 740 | + break; |
683 | + } | 741 | + } |
684 | + | 742 | + |
685 | + cpu = object_new(possible_cpus->cpus[n].type); | 743 | + cpu = object_new(possible_cpus->cpus[n].type); |
686 | + object_property_set_int(cpu, "mp-affinity", | 744 | + object_property_set_int(cpu, "mp-affinity", |
687 | + possible_cpus->cpus[n].arch_id, NULL); | 745 | + possible_cpus->cpus[n].arch_id, &error_fatal); |
688 | + | 746 | + |
689 | + cs = CPU(cpu); | 747 | + cs = CPU(cpu); |
690 | + cs->cpu_index = n; | 748 | + cs->cpu_index = n; |
691 | + | 749 | + |
692 | + numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpu), | 750 | + numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpu), |
693 | + &error_fatal); | 751 | + &error_fatal); |
694 | + | 752 | + |
695 | + object_property_set_bool(cpu, "has_el3", false, NULL); | 753 | + if (object_property_find(cpu, "has_el3")) { |
696 | + object_property_set_bool(cpu, "has_el2", false, NULL); | 754 | + object_property_set_bool(cpu, "has_el3", false, &error_fatal); |
755 | + } | ||
756 | + if (object_property_find(cpu, "has_el2")) { | ||
757 | + object_property_set_bool(cpu, "has_el2", false, &error_fatal); | ||
758 | + } | ||
697 | + object_property_set_int(cpu, "psci-conduit", QEMU_PSCI_CONDUIT_HVC, | 759 | + object_property_set_int(cpu, "psci-conduit", QEMU_PSCI_CONDUIT_HVC, |
698 | + NULL); | 760 | + &error_fatal); |
699 | + | 761 | + |
700 | + /* Secondary CPUs start in PSCI powered-down state */ | 762 | + /* Secondary CPUs start in PSCI powered-down state */ |
701 | + if (n > 0) { | 763 | + if (n > 0) { |
702 | + object_property_set_bool(cpu, "start-powered-off", true, NULL); | 764 | + object_property_set_bool(cpu, "start-powered-off", true, |
765 | + &error_fatal); | ||
703 | + } | 766 | + } |
704 | + | 767 | + |
705 | + object_property_set_link(cpu, "memory", OBJECT(sysmem), &error_abort); | 768 | + object_property_set_link(cpu, "memory", OBJECT(sysmem), &error_abort); |
706 | + qdev_realize(DEVICE(cpu), NULL, &error_fatal); | 769 | + qdev_realize(DEVICE(cpu), NULL, &error_fatal); |
707 | + object_unref(cpu); | 770 | + object_unref(cpu); |
... | ... | ||
720 | + create_pcie(vms); | 783 | + create_pcie(vms); |
721 | + | 784 | + |
722 | + create_gpio_devices(vms, VMAPPLE_GPIO, sysmem); | 785 | + create_gpio_devices(vms, VMAPPLE_GPIO, sysmem); |
723 | + | 786 | + |
724 | + vmapple_firmware_init(vms, sysmem); | 787 | + vmapple_firmware_init(vms, sysmem); |
725 | + create_cfg(vms, sysmem); | 788 | + create_cfg(vms, sysmem, &error_fatal); |
726 | + | 789 | + |
727 | + /* connect powerdown request */ | 790 | + /* connect powerdown request */ |
728 | + vms->powerdown_notifier.notify = vmapple_powerdown_req; | 791 | + vms->powerdown_notifier.notify = vmapple_powerdown_req; |
729 | + qemu_register_powerdown_notifier(&vms->powerdown_notifier); | 792 | + qemu_register_powerdown_notifier(&vms->powerdown_notifier); |
730 | + | 793 | + |
... | ... | ||
773 | + arm_build_mp_affinity(n, GICV3_TARGETLIST_BITS); | 836 | + arm_build_mp_affinity(n, GICV3_TARGETLIST_BITS); |
774 | + ms->possible_cpus->cpus[n].props.has_thread_id = true; | 837 | + ms->possible_cpus->cpus[n].props.has_thread_id = true; |
775 | + ms->possible_cpus->cpus[n].props.thread_id = n; | 838 | + ms->possible_cpus->cpus[n].props.thread_id = n; |
776 | + } | 839 | + } |
777 | + return ms->possible_cpus; | 840 | + return ms->possible_cpus; |
778 | +} | ||
779 | + | ||
780 | +static void vmapple_get_uuid(Object *obj, Visitor *v, const char *name, | ||
781 | + void *opaque, Error **errp) | ||
782 | +{ | ||
783 | + VMAppleMachineState *vms = VMAPPLE_MACHINE(obj); | ||
784 | + | ||
785 | + visit_type_uint64(v, name, &vms->uuid, errp); | ||
786 | +} | ||
787 | + | ||
788 | +static void vmapple_set_uuid(Object *obj, Visitor *v, const char *name, | ||
789 | + void *opaque, Error **errp) | ||
790 | +{ | ||
791 | + VMAppleMachineState *vms = VMAPPLE_MACHINE(obj); | ||
792 | + Error *error = NULL; | ||
793 | + | ||
794 | + visit_type_uint64(v, name, &vms->uuid, &error); | ||
795 | + if (error) { | ||
796 | + error_propagate(errp, error); | ||
797 | + return; | ||
798 | + } | ||
799 | +} | 841 | +} |
800 | + | 842 | + |
801 | +static void vmapple_machine_class_init(ObjectClass *oc, void *data) | 843 | +static void vmapple_machine_class_init(ObjectClass *oc, void *data) |
802 | +{ | 844 | +{ |
803 | + MachineClass *mc = MACHINE_CLASS(oc); | 845 | + MachineClass *mc = MACHINE_CLASS(oc); |
... | ... | ||
814 | + mc->get_default_cpu_node_id = vmapple_get_default_cpu_node_id; | 856 | + mc->get_default_cpu_node_id = vmapple_get_default_cpu_node_id; |
815 | + mc->default_ram_id = "mach-vmapple.ram"; | 857 | + mc->default_ram_id = "mach-vmapple.ram"; |
816 | + | 858 | + |
817 | + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", | 859 | + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", |
818 | + "on", true); | 860 | + "on", true); |
819 | + | ||
820 | + object_class_property_add(oc, "uuid", "uint64", vmapple_get_uuid, | ||
821 | + vmapple_set_uuid, NULL, NULL); | ||
822 | + object_class_property_set_description(oc, "uuid", "Machine UUID (SDOM)"); | ||
823 | +} | 861 | +} |
824 | + | 862 | + |
825 | +static void vmapple_instance_init(Object *obj) | 863 | +static void vmapple_instance_init(Object *obj) |
826 | +{ | 864 | +{ |
827 | + VMAppleMachineState *vms = VMAPPLE_MACHINE(obj); | 865 | + VMAppleMachineState *vms = VMAPPLE_MACHINE(obj); |
828 | + | 866 | + |
829 | + vms->irqmap = irqmap; | 867 | + vms->irqmap = irqmap; |
868 | + | ||
869 | + object_property_add_uint64_ptr(obj, "uuid", &vms->uuid, | ||
870 | + OBJ_PROP_FLAG_READWRITE); | ||
871 | + object_property_set_description(obj, "uuid", "Machine UUID (SDOM)"); | ||
830 | +} | 872 | +} |
831 | + | 873 | + |
832 | +static const TypeInfo vmapple_machine_info = { | 874 | +static const TypeInfo vmapple_machine_info = { |
833 | + .name = TYPE_VMAPPLE_MACHINE, | 875 | + .name = TYPE_VMAPPLE_MACHINE, |
834 | + .parent = TYPE_MACHINE, | 876 | + .parent = TYPE_MACHINE, |
... | ... | ||
843 | +{ | 885 | +{ |
844 | + type_register_static(&vmapple_machine_info); | 886 | + type_register_static(&vmapple_machine_info); |
845 | +} | 887 | +} |
846 | +type_init(machvmapple_machine_init); | 888 | +type_init(machvmapple_machine_init); |
847 | + | 889 | + |
848 | +static void vmapple_machine_9_2_options(MachineClass *mc) | 890 | +static void vmapple_machine_10_0_options(MachineClass *mc) |
849 | +{ | 891 | +{ |
850 | +} | 892 | +} |
851 | +DEFINE_VMAPPLE_MACHINE_AS_LATEST(9, 2) | 893 | +DEFINE_VMAPPLE_MACHINE_AS_LATEST(10, 0) |
852 | + | 894 | + |
853 | -- | 895 | -- |
854 | 2.39.3 (Apple Git-145) | 896 | 2.39.5 (Apple Git-154) |
855 | 897 | ||
856 | 898 | diff view generated by jsdifflib |