Compare commits

...
Author SHA1 Message Date
osy f2387eb326 hvf: arm: support TSO on macOS 15 2024-10-03 21:47:47 -07:00
osy 849e1db096 hvf: arm: disable debug features for iOS 2024-10-02 12:14:10 -07:00
osy 81cf7a0723 hvf: arm: fix compile issue for iOS 2024-10-02 12:13:54 -07:00
osy 847a5380a1 tcg/optimize: disable fold_setcond_zmask for TCTI 2024-10-01 10:03:23 -07:00
osy 6a233bbe9f tcg: disable HAVE_CMPXCHG128 for TCTI 2024-10-01 10:03:23 -07:00
osy f0866dd714 tcg/optimize: disable env memory folding for TCTI 2024-10-01 10:03:23 -07:00
osy b65c350e24 tcg/tcti: update code gen for latest TCG changes 2024-10-01 10:03:22 -07:00
osy 52dbd298e5 tcg/tcti: bring back movcond 2024-09-30 12:58:11 -07:00
osy 254bd0efa3 tcg/tcti: move gadgets generation to library 2024-09-30 12:56:33 -07:00
osy 361d160a68 roms: replace BIOS with UTM variants 2024-09-30 12:51:20 -07:00
osy f940d8d684 Merge remote-tracking branch 'mcayland/screamer-v9.1.0' into HEAD 2024-09-30 12:51:20 -07:00
osy ce02743156 screamer: remove old screamer code 2024-09-30 12:51:20 -07:00
Alexander Graf aea06209c4 hw/intc/arm_gicv3: Bump ITT entry size to 16
Some Operating Systems (like Windows) can only deal with ITT entry sizes
that are a power of 2. While the spec allows arbitrarily sized ITT entry
sizes, in practice all hardware will use power of 2 because that
simplifies offset calculation and ensures that a power of 2 sized region
can hold a set of entries without gap at the end.

So let's just bump the entry size to 16. That gives us enough space for
the 12 bytes of data that we want to have in each ITT entry and makes
QEMU look a bit more like real hardware.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
2024-09-29 12:06:36 -07:00
Alexander Graf 888bb9e3bf hw/intc/arm_gicv3: Make ITT entry size configurable
An ITT entry is opaque to the OS. The only thing it does get told by HW is
its size. In theory, that size can be any byte aligned number, in practice
HW will always use power of 2s to simplify offset calculation. We currently
expose the size as 12, which is not a power of 2.

To prepare for a future where we expose power of 2 sized entry sizes, let's
make the size itself configurable. We only need to watch out that we don't
have an entry be smaller than the fields we want to access inside. Bigger
is always fine.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Joelle van Dyne <[email protected]>
2024-09-29 12:06:36 -07:00
osy 59cc5b96e2 tpm-crb: fix page size for macs 2024-09-29 12:06:36 -07:00
Mark Cave-Ayland 1c47688ed6 WIP: remove byte swap implementation
- Fixes OS X 10.1 and 10.2 crackling
- Clearly this register does something different than I expect...
2024-09-23 23:18:55 +01:00
Mark Cave-Ayland 3c1a7a3265 WIP: more updates, current status:
-M mac99, OS 9.0 - boots, but silent
-M mac99, OS 9.2 - works
-M mac99,via=pmu, OS 9.2 - works
-M mac99 - OS X 10.2 - works
-M mac99,via=pmu, OS X 10.2 - patchy noise (incorrect timer?)
2024-09-23 23:18:55 +01:00
Mark Cave-Ayland 66a5df7c15 WIP: update 2024-09-23 23:18:55 +01:00
Mark Cave-Ayland 39858ec734 WIP: Add OpenBIOS with screamer support 2024-09-23 23:18:52 +01:00
Mark Cave-Ayland 89f1a628cf WIP: update DBDMA status after FLUSH 2024-09-23 21:31:57 +01:00
Mark Cave-Ayland 9b649c3e9f WIP: working sound in MacOS 9.1/9.2 2024-09-23 21:31:57 +01:00
Mark Cave-Ayland 4ed9ad7f1b WIP: screamer now able to play on Debian Linux/snd_powermac 2024-09-23 21:31:56 +01:00
Mark Cave-Ayland ef29d0dadd WIP: wire up to new world machine 2024-09-23 21:31:56 +01:00
Mark Cave-Ayland 36d2758b9d WIP: basic DMA functionality for screamer 2024-09-23 21:31:56 +01:00
Mark Cave-Ayland 4431f3f2aa screamer: some basic reg work, plus basic DMA wire-up 2024-09-23 21:31:56 +01:00
Mark Cave-Ayland 44036c8eb7 macio: basic AWACS/screamer hookup
Signed-off-by: Mark Cave-Ayland <[email protected]>
2024-09-23 21:31:56 +01:00
Mark Cave-Ayland c3af08a16e audio: add dummy screamer device
Signed-off-by: Mark Cave-Ayland <[email protected]>
2024-09-23 21:31:56 +01:00
osy 903085638b sysbus-fdt: falsely claim TPM CRB device is TPM TIS
OVMF firmware is hard coded to recognize a TPM TIS device. If we lie,
the code will properly detect that it is a CRB device. In Linux, this
will cause the device to be not recognized properly but the separate
ACPI device will cause it to work regardless.
2024-09-15 05:15:32 -07:00
osy 11b4067b9e Merge tag 'patchew/[email protected]' into utm-edition-v9.1.0 2024-09-15 05:15:32 -07:00
osy d6441003a3 Merge tag 'v9.1.0' into utm-edition
v9.1.0 release
2024-09-10 03:13:24 -07:00
Joelle van Dyne 6e95fc98a5 tests: add TPM-CRB sysbus tests for aarch64
- Factor out common test code from tpm-crb-test.c -> tpm-tests.c
- Store device addr in `tpm_device_base_addr` (unify with TIS tests)
- Add new tests for aarch64

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:41 +00:00
Joelle van Dyne 6744c812b4 tests: acpi: updated expected blobs for TPM CRB
Signed-off-by: Joelle van Dyne <[email protected]>
Tested-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:41 +00:00
Joelle van Dyne a1658ba0df tests: acpi: implement TPM CRB tests for ARM virt
Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:41 +00:00
Joelle van Dyne 4653477a12 tpm_crb_sysbus: introduce TPM CRB SysBus device
This SysBus variant of the CRB interface supports dynamically locating
the MMIO interface so that Virt machines can use it. This interface
is currently the only one supported by QEMU that works on Windows 11
ARM64 as 'tpm-tis-device' does not work with current Windows drivers.
We largely follow that device as a template.

To try out this device with Windows 11 before OVMF is updated, you
will need to modify `sysbus-fdt.c` and change the added line from:

```c
    TYPE_BINDING(TYPE_TPM_CRB_SYSBUS, no_fdt_node),
```

to

```c
    TYPE_BINDING(TYPE_TPM_CRB_SYSBUS, add_tpm_tis_fdt_node),
```

This change was not included because it can confuse Linux (although
from testing, it seems like Linux is able to properly ignore the
device from the TPM TIS driver and recognize it from the ACPI device
in the TPM CRB driver). A proper fix would require OVMF to recognize
the ACPI device and not depend on the FDT node for recognizing TPM.

The command line to try out this device with SWTPM is:

```
$ qemu-system-aarch64 \
    -chardev socket,id=chrtpm0,path=tpm.sock \
    -tpmdev emulator,id=tpm0,chardev=chrtpm0 \
    -device tpm-crb-device,tpmdev=tpm0
```

along with SWTPM:

```
$ swtpm \
    --ctrl type=unixio,path=tpm.sock,terminate \
    --tpmstate backend-uri=file://tpm.data \
    --tpm2
```

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:41 +00:00
Joelle van Dyne 61819be7f1 tests: acpi: prepare for TPM CRB tests
Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 3f0d5bac18 tpm_tis_sysbus: move DSDT AML generation to device
This reduces redundant code in different machine types with ACPI table
generation. Additionally, this will allow us to support different TPM
interfaces with the same AML logic. Finally, this matches up with the
TPM TIS ISA implementation.

Ideally, we would be able to call `qbus_build_aml` and avoid any TPM
specific code in the ACPI table generation. However, currently we
still have to call `build_tpm2` anyways and it does not look like
most other ACPI devices support the `ACPI_DEV_AML_IF` interface.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 323c2b9a2e hw/loongarch/virt: connect TPM to platform bus
Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 3e3a3d6370 hw/arm/virt: connect TPM to platform bus
Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 8c7c8c1be9 tpm-sysbus: add plug handler for TPM on SysBus
TPM needs to know its own base address in order to generate its DSDT
device entry.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne f94d1bb04f tpm_crb: move ACPI table building to device interface
This logic is similar to TPM TIS ISA device. Since TPM CRB can only
support TPM 2.0 backends, we check for this in realize.

Signed-off-by: Joelle van Dyne <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 156a7df98f tpm_crb: use a single read-as-mem/write-as-mmio mapping
On Apple Silicon, when Windows performs a LDP on the CRB MMIO space,
the exception is not decoded by hardware and we cannot trap the MMIO
read. This led to the idea from @agraf to use the same mapping type as
ROM devices: namely that reads should be seen as memory type and
writes should trap as MMIO.

Once that was done, the second memory mapping of the command buffer
region was redundent and was removed.

A note about the removal of the read trap for `CRB_LOC_STATE`:
The only usage was to return the most up-to-date value for
`tpmEstablished`. However, `tpmEstablished` is only cleared when a
TPM2_HashStart operation is called which only exists for locality 4.
We do not handle locality 4. Indeed, the comment for the write handler
of `CRB_LOC_CTRL` makes the same argument for why it is not calling
the backend to reset the `tpmEstablished` bit (to 1).
As this bit is unused, we do not need to worry about updating it for
reads.

In order to maintain migration compatibility with older versions of
QEMU, we store a copy of the register data and command data which is
used only during save/restore.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne c1bd61b8ec tpm_ppi: refactor memory space initialization
Instead of calling `memory_region_add_subregion` directly, we defer to
the caller to do it. This allows us to re-use the code for a SysBus
device.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne c24b94f4d3 tpm_crb: CTRL_RSP_ADDR is 64-bits wide
The register is actually 64-bits but in order to make this more clear
than the specification, we define two 32-bit registers:
CTRL_RSP_LADDR and CTRL_RSP_HADDR to match the CTRL_CMD_* naming. This
deviates from the specs but is way more clear.

Previously, the only CRB device uses a fixed system address so this
was not an issue. However, once we support SysBus CRB device, the
address can be anywhere in 64-bit space.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
Joelle van Dyne 32f32b3918 tpm_crb: refactor common code
In preparation for the SysBus variant, we move common code styled
after the TPM TIS devices.

To maintain compatibility, we do not rename the existing tpm-crb
device.

Signed-off-by: Joelle van Dyne <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Message-Id: <[email protected]>
2023-11-14 15:49:40 +00:00
osy 8eb68166a7 edk2: add secure boot variant to aarch64 firmware 2023-07-08 14:41:16 -07:00
osy 2bbbeb0eaf Merge tag 'v8.0.2' into utm-edition
v8.0.2 release
2023-07-02 22:32:38 -05:00
Michael Tokarev f7f686b61c Update version for 8.0.2 release
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-30 14:59:47 +03:00
Kevin Wolf bea933e430 block/export: Fix null pointer dereference in error path
There are some error paths in blk_exp_add() that jump to 'fail:' before
'exp' is even created. So we can't just unconditionally access exp->blk.

Add a NULL check, and switch from exp->blk to blk, which is available
earlier, just to be extra sure that we really cover all cases where
BlockDevOps could have been set for it (in practice, this only happens
in drv->create() today, so this part of the change isn't strictly
necessary).

Fixes: Coverity CID 1509238
Fixes: de79b52604
Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Tested-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit a184563778)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-30 00:16:58 +03:00
Michael Tokarev dabb4183d1 Update version for 8.0.1 release
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-29 18:19:22 +03:00
Paolo Bonzini ff692a15bb virtio: qmp: fix memory leak
The VirtioInfoList is already allocated by QAPI_LIST_PREPEND and
need not be allocated by the caller.

Fixes Coverity CID 1508724.

Reviewed-by: Daniel P. Berrangé <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 0bfd14149b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-27 12:54:07 +03:00
Igor Mammedov 134253a4fe machine: do not crash if default RAM backend name has been stolen
QEMU aborts when default RAM backend should be used (i.e. no
explicit '-machine memory-backend=' specified) but user
has created an object which 'id' equals to default RAM backend
name used by board.

 $QEMU -machine pc \
       -object memory-backend-ram,id=pc.ram,size=4294967296

 Actual results:
 QEMU 7.2.0 monitor - type 'help' for more information
 (qemu) Unexpected error in object_property_try_add() at ../qom/object.c:1239:
 qemu-kvm: attempt to add duplicate property 'pc.ram' to object (type 'container')
 Aborted (core dumped)

Instead of abort, check for the conflicting 'id' and exit with
an error, suggesting how to remedy the issue.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2207886
Signed-off-by: Igor Mammedov <[email protected]>
Message-Id: <[email protected]>
Tested-by: Thomas Huth <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Shaoqin Huang <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit a37531f238)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-26 19:46:01 +03:00
Thomas Huth e49884a909 hw/scsi/lsi53c895a: Fix reentrancy issues in the LSI controller (CVE-2023-0330)
We cannot use the generic reentrancy guard in the LSI code, so
we have to manually prevent endless reentrancy here. The problematic
lsi_execute_script() function has already a way to detect whether
too many instructions have been executed - we just have to slightly
change the logic here that it also takes into account if the function
has been called too often in a reentrant way.

The code in fuzz-lsi53c895a-test.c has been taken from an earlier
patch by Mauro Matteo Cascella.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1563
Message-Id: <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Alexander Bulekov <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit b987718bbb)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-26 18:56:39 +03:00
Paolo Bonzini 9d622451fd usb/ohci: Set pad to 0 after frame update
When the OHCI controller's framenumber is incremented, HccaPad1 register
should be set to zero (Ref OHCI Spec 4.4)

ReactOS uses hccaPad1 to determine if the OHCI hardware is running,
consequently it fails this check in current qemu master.

Signed-off-by: Ryan Wendland <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1048
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 6301460ce9)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-26 10:49:10 +03:00
Akihiko Odaki 668aeea0ec util/vfio-helpers: Use g_file_read_link()
When _FORTIFY_SOURCE=2, glibc version is 2.35, and GCC version is
12.1.0, the compiler complains as follows:

In file included from /usr/include/features.h:490,
                 from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdint.h:26,
                 from /usr/lib/gcc/aarch64-unknown-linux-gnu/12.1.0/include/stdint.h:9,
                 from /home/alarm/q/var/qemu/include/qemu/osdep.h:94,
                 from ../util/vfio-helpers.c:13:
In function 'readlink',
    inlined from 'sysfs_find_group_file' at ../util/vfio-helpers.c:116:9,
    inlined from 'qemu_vfio_init_pci' at ../util/vfio-helpers.c:326:18,
    inlined from 'qemu_vfio_open_pci' at ../util/vfio-helpers.c:517:9:
/usr/include/bits/unistd.h:119:10: error: argument 2 is null but the corresponding size argument 3 value is 4095 [-Werror=nonnull]
  119 |   return __glibc_fortify (readlink, __len, sizeof (char),
      |          ^~~~~~~~~~~~~~~

This error implies the allocated buffer can be NULL. Use
g_file_read_link(), which allocates buffer automatically to avoid the
error.

Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Cédric Le Goater <[email protected]>
Signed-off-by: Cédric Le Goater <[email protected]>
(cherry picked from commit dbdea0dbfe)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-26 10:47:30 +03:00
Stefan Hajnoczi fae9449998 rtl8139: fix large_send_mss divide-by-zero
If the driver sets large_send_mss to 0 then a divide-by-zero occurs.
Even if the division wasn't a problem, the for loop that emits MSS-sized
packets would never terminate.

Solve these issues by skipping offloading when large_send_mss=0.

This issue was found by OSS-Fuzz as part of Alexander Bulekov's device
fuzzing work. The reproducer is:

  $ cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest, -m \
  512M,slots=1,maxmem=0xffff000000000000 -machine q35 -nodefaults -device \
  rtl8139,netdev=net0 -netdev user,id=net0 -device \
  pc-dimm,id=nv1,memdev=mem1,addr=0xb800a64602800000 -object \
  memory-backend-ram,id=mem1,size=2M  -qtest stdio
  outl 0xcf8 0x80000814
  outl 0xcfc 0xe0000000
  outl 0xcf8 0x80000804
  outw 0xcfc 0x06
  write 0xe0000037 0x1 0x04
  write 0xe00000e0 0x2 0x01
  write 0x1 0x1 0x04
  write 0x3 0x1 0x98
  write 0xa 0x1 0x8c
  write 0xb 0x1 0x02
  write 0xc 0x1 0x46
  write 0xd 0x1 0xa6
  write 0xf 0x1 0xb8
  write 0xb800a646028c000c 0x1 0x08
  write 0xb800a646028c000e 0x1 0x47
  write 0xb800a646028c0010 0x1 0x02
  write 0xb800a646028c0017 0x1 0x06
  write 0xb800a646028c0036 0x1 0x80
  write 0xe00000d9 0x1 0x40
  EOF

Buglink: https://gitlab.com/qemu-project/qemu/-/issues/1582
Closes: https://gitlab.com/qemu-project/qemu/-/issues/1582
Cc: [email protected]
Cc: Peter Maydell <[email protected]>
Fixes: 6d71357a3b ("rtl8139: honor large send MSS value")
Reported-by: Alexander Bulekov <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Tested-by: Alexander Bulekov <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit 792676c165)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 18:07:21 +03:00
Akihiko Odaki 02bd13ae3a igb: Always copy ethernet header
igb_receive_internal() used to check the iov length to determine
copy the iovs to a contiguous buffer, but the check is flawed in two
ways:
- It does not ensure that iovcnt > 0.
- It does not take virtio-net header into consideration.

The size of this copy is just 22 octets, which can be even less than
the code size required for checks. This (wrong) optimization is probably
not worth so just remove it. Removing this also allows igb to assume
aligned accesses for the ethernet header.

Fixes: 3a977deebe ("Intrdocue igb device emulation")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit dc9ef1bf45)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:37:48 +03:00
Akihiko Odaki c84bcff3d3 e1000e: Always copy ethernet header
e1000e_receive_internal() used to check the iov length to determine
copy the iovs to a contiguous buffer, but the check is flawed in two
ways:
- It does not ensure that iovcnt > 0.
- It does not take virtio-net header into consideration.

The size of this copy is just 18 octets, which can be even less than
the code size required for checks. This (wrong) optimization is probably
not worth so just remove it.

Fixes: 6f3fbe4ed0 ("net: Introduce e1000e device emulation")
Signed-off-by: Akihiko Odaki <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit 310a128eae)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:35:30 +03:00
Akihiko Odaki 5c4f2f1b60 net/net_rx_pkt: Use iovec for net_rx_pkt_set_protocols()
igb does not properly ensure the buffer passed to
net_rx_pkt_set_protocols() is contiguous for the entire L2/L3/L4 header.
Allow it to pass scattered data to net_rx_pkt_set_protocols().

Fixes: 3a977deebe ("Intrdocue igb device emulation")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit 2f0fa232b8)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:34:46 +03:00
Akihiko Odaki ba3c7bf178 igb: Clear IMS bits when committing ICR access
The datasheet says contradicting statements regarding ICR accesses so it
is not reliable to determine the behavior of ICR accesses. However,
e1000e does clear IMS bits when reading ICR accesses and Linux also
expects ICR accesses will clear IMS bits according to:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/intel/igb/igb_main.c?h=v6.2#n8048

Fixes: 3a977deebe ("Intrdocue igb device emulation")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit f0b1df5c45)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:34:28 +03:00
Akihiko Odaki 6e260100d0 igb: Do not require CTRL.VME for tx VLAN tagging
While the datasheet of e1000e says it checks CTRL.VME for tx VLAN
tagging, igb's datasheet has no such statements. It also says for
"CTRL.VLE":
> This register only affects the VLAN Strip in Rx it does not have any
> influence in the Tx path in the 82576.
(Appendix A. Changes from the 82575)

There is no "CTRL.VLE" so it is more likely that it is a mistake of
CTRL.VME.

Fixes: fba7c3b788 ("igb: respect VMVIR and VMOLR for VLAN")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit e209716749)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:34:04 +03:00
Akihiko Odaki 9ff3fe63fc igb: Fix Rx packet type encoding
igb's advanced descriptor uses a packet type encoding different from
one used in e1000e's extended descriptor. Fix the logic to encode
Rx packet type accordingly.

Fixes: 3a977deebe ("Intrdocue igb device emulation")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit ed447c60b3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:33:54 +03:00
Akihiko Odaki 0f7ca2bf2c e1000x: Fix BPRC and MPRC
Before this change, e1000 and the common code updated BPRC and MPRC
depending on the matched filter, but e1000e and igb decided to update
those counters by deriving the packet type independently. This
inconsistency caused a multicast packet to be counted twice.

Updating BPRC and MPRC depending on are fundamentally flawed anyway as
a filter can be used for different types of packets. For example, it is
possible to filter broadcast packets with MTA.

Always determine what counters to update by inspecting the packets.

Fixes: 3b27430177 ("e1000: Implementing various counters")
Signed-off-by: Akihiko Odaki <[email protected]>
Reviewed-by: Sriram Yagnaraman <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit f3f9b726af)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-24 16:31:45 +03:00
[email protected] eb134d1d58 e1000e: Fix tx/rx counters
The bytes and packets counter registers are cleared on read.

Copying the "total counter" registers to the "good counter" registers has
side effects.
If the "total" register is never read by the OS, it only gets incremented.
This leads to exponential growth of the "good" register.

This commit increments the counters individually to avoid this.

Signed-off-by: Timothée Cocault <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
(cherry picked from commit 8d689f6aae)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-23 22:07:47 +03:00
Kevin Wolf a7002f15c8 nbd/server: Fix drained_poll to wake coroutine in right AioContext
nbd_drained_poll() generally runs in the main thread, not whatever
iothread the NBD server coroutine is meant to run in, so it can't
directly reenter the coroutines to wake them up.

The code seems to have the right intention, it specifies the correct
AioContext when it calls qemu_aio_coroutine_enter(). However, this
functions doesn't schedule the coroutine to run in that AioContext, but
it assumes it is already called in the home thread of the AioContext.

To fix this, add a new thread-safe qio_channel_wake_read() that can be
called in the main thread to wake up the coroutine in its AioContext,
and use this in nbd_drained_poll().

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 7c1f51bf38)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 20:54:40 +03:00
Kevin Wolf d001f222e3 graph-lock: Disable locking for now
In QEMU 8.0, we've been seeing deadlocks in bdrv_graph_wrlock(). They
come from callers that hold an AioContext lock, which is not allowed
during polling. In theory, we could temporarily release the lock, but
callers are inconsistent about whether they hold a lock, and if they do,
some are also confused about which one they hold. While all of this is
fixable, it's not trivial, and the best course of action for 8.0.1 is
probably just disabling the graph locking code temporarily.

We don't currently rely on graph locking yet. It is supposed to replace
the AioContext lock eventually to enable multiqueue support, but as long
as we still have the AioContext lock, it is sufficient without the graph
lock. Once the AioContext lock goes away, the deadlock doesn't exist any
more either and this commit can be reverted. (Of course, it can also be
reverted while the AioContext lock still exists if the callers have been
fixed.)

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 80fc5d2600)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 20:54:40 +03:00
Stefan Hajnoczi 84d839e499 block: compile out assert_bdrv_graph_readable() by default
reader_count() is a performance bottleneck because the global
aio_context_list_lock mutex causes thread contention. Put this debugging
assertion behind a new ./configure --enable-debug-graph-lock option and
disable it by default.

The --enable-debug-graph-lock option is also enabled by the more general
--enable-debug option.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 58a2e3f5c3)
Signed-off-by: Michael Tokarev <[email protected]>
(Mjt: pick this one up so the next patch which disables this applies cleanly)
2023-05-22 20:53:40 +03:00
Stefan Hajnoczi a0b89ba845 tested: add test for nested aio_poll() in poll handlers
Cc: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
[kwolf: Restrict to CONFIG_POSIX, Windows doesn't support polling]
Tested-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 844a12a63e)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 19:38:44 +03:00
Stefan Hajnoczi a91defe16b aio-posix: do not nest poll handlers
QEMU's event loop supports nesting, which means that event handler
functions may themselves call aio_poll(). The condition that triggered a
handler must be reset before the nested aio_poll() call, otherwise the
same handler will be called and immediately re-enter aio_poll. This
leads to an infinite loop and stack exhaustion.

Poll handlers are especially prone to this issue, because they typically
reset their condition by finishing the processing of pending work.
Unfortunately it is during the processing of pending work that nested
aio_poll() calls typically occur and the condition has not yet been
reset.

Disable a poll handler during ->io_poll_ready() so that a nested
aio_poll() call cannot invoke ->io_poll_ready() again. As a result, the
disabled poll handler and its associated fd handler do not run during
the nested aio_poll(). Calling aio_set_fd_handler() from inside nested
aio_poll() could cause it to run again. If the fd handler is pending
inside nested aio_poll(), then it will also run again.

In theory fd handlers can be affected by the same issue, but they are
more likely to reset the condition before calling nested aio_poll().

This is a special case and it's somewhat complex, but I don't see a way
around it as long as nested aio_poll() is supported.

Cc: [email protected]
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2186181
Fixes: c382706925 ("block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK")
Cc: Kevin Wolf <[email protected]>
Cc: Emanuele Giuseppe Esposito <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 6d740fb01b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 19:38:44 +03:00
Mauro Matteo Cascella 81d13aa5e0 virtio-crypto: fix NULL pointer dereference in virtio_crypto_free_request
Ensure op_info is not NULL in case of QCRYPTODEV_BACKEND_ALG_SYM algtype.

Fixes: 0e660a6f90 ("crypto: Introduce RSA algorithm")
Signed-off-by: Mauro Matteo Cascella <[email protected]>
Reported-by: Yiming Tao <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Gonglei <[email protected]>
Reviewed-by: zhenwei pi<[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 3e69908907)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 19:38:44 +03:00
Eugenio Pérez 302ac06ab9 virtio-net: not enable vq reset feature unconditionally
The commit 93a97dc520 ("virtio-net: enable vq reset feature") enables
unconditionally vq reset feature as long as the device is emulated.
This makes impossible to actually disable the feature, and it causes
migration problems from qemu version previous than 7.2.

The entire final commit is unneeded as device system already enable or
disable the feature properly.

This reverts commit 93a97dc520.
Fixes: 93a97dc520 ("virtio-net: enable vq reset feature")
Signed-off-by: Eugenio Pérez <[email protected]>

Message-Id: <[email protected]>
Reviewed-by: Xuan Zhuo <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 1fac00f70b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 19:38:44 +03:00
Leonardo Bras adc49750d2 hw/pci: Disable PCI_ERR_UNCOR_MASK register for machine type < 8.0
Since it's implementation on v8.0.0-rc0, having the PCI_ERR_UNCOR_MASK
set for machine types < 8.0 will cause migration to fail if the target
QEMU version is < 8.0.0 :

qemu-system-x86_64: get_pci_config_device: Bad config data: i=0x10a read: 40 device: 0 cmask: ff wmask: 0 w1cmask:0
qemu-system-x86_64: Failed to load PCIDevice:config
qemu-system-x86_64: Failed to load e1000e:parent_obj
qemu-system-x86_64: error while loading state for instance 0x0 of device '0000:00:02.0/e1000e'
qemu-system-x86_64: load of migration failed: Invalid argument

The above test migrated a 7.2 machine type from QEMU master to QEMU 7.2.0,
with this cmdline:

./qemu-system-x86_64 -M pc-q35-7.2 [-incoming XXX]

In order to fix this, property x-pcie-err-unc-mask was introduced to
control when PCI_ERR_UNCOR_MASK is enabled. This property is enabled by
default, but is disabled if machine type <= 7.2.

Fixes: 010746ae1d ("hw/pci/aer: Implement PCI_ERR_UNCOR_MASK register")
Suggested-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Leonardo Bras <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Jonathan Cameron <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1576
Tested-by: Fiona Ebner <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 5ed3dabe57)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-22 19:38:44 +03:00
Hawkins Jiawei a9144eed6c vhost: fix possible wrap in SVQ descriptor ring
QEMU invokes vhost_svq_add() when adding a guest's element
into SVQ. In vhost_svq_add(), it uses vhost_svq_available_slots()
to check whether QEMU can add the element into SVQ. If there is
enough space, then QEMU combines some out descriptors and some
in descriptors into one descriptor chain, and adds it into
`svq->vring.desc` by vhost_svq_vring_write_descs().

Yet the problem is that, `svq->shadow_avail_idx - svq->shadow_used_idx`
in vhost_svq_available_slots() returns the number of occupied elements,
or the number of descriptor chains, instead of the number of occupied
descriptors, which may cause wrapping in SVQ descriptor ring.

Here is an example. In vhost_handle_guest_kick(), QEMU forwards
as many available buffers to device by virtqueue_pop() and
vhost_svq_add_element(). virtqueue_pop() returns a guest's element,
and then this element is added into SVQ by vhost_svq_add_element(),
a wrapper to vhost_svq_add(). If QEMU invokes virtqueue_pop() and
vhost_svq_add_element() `svq->vring.num` times,
vhost_svq_available_slots() thinks QEMU just ran out of slots and
everything should work fine. But in fact, virtqueue_pop() returns
`svq->vring.num` elements or descriptor chains, more than
`svq->vring.num` descriptors due to guest memory fragmentation,
and this causes wrapping in SVQ descriptor ring.

This bug is valid even before marking the descriptors used.
If the guest memory is fragmented, SVQ must add chains
so it can try to add more descriptors than possible.

This patch solves it by adding `num_free` field in
VhostShadowVirtqueue structure and updating this field
in vhost_svq_add() and vhost_svq_get_buf(), to record
the number of free descriptors.

Fixes: 100890f7ca ("vhost: Shadow virtqueue buffers forwarding")
Signed-off-by: Hawkins Jiawei <[email protected]>
Acked-by: Eugenio Pérez <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Lei Yang <[email protected]>
(cherry picked from commit 5d410557de)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-19 23:23:50 +03:00
Xinyu Li 0de5117819 target/i386: fix avx2 instructions vzeroall and vpermdq
vzeroall: xmm_regs should be used instead of xmm_t0
vpermdq: bit 3 and 7 of imm should be considered

Signed-off-by: Xinyu Li <[email protected]>
Message-Id: <[email protected]>
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 056d649007)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 20:46:55 +03:00
Paolo Bonzini db8051ad59 target/i386: fix operand size for VCOMI/VUCOMI instructions
Compared to other SSE instructions, VUCOMISx and VCOMISx are different:
the single and double precision versions are distinguished through a
prefix, however they use no-prefix and 0x66 for SS and SD respectively.
Scalar values usually are associated with 0xF2 and 0xF3.

Because of these, they incorrectly perform a 128-bit memory load instead
of a 32- or 64-bit load.  Fix this by writing a custom decoding function.

I tested that the reproducer is fixed and the test-avx output does not
change.

Reported-by: Gabriele Svelto <[email protected]>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1637
Fixes: f8d19eec0d ("target/i386: reimplement 0x0f 0x28-0x2f, add AVX", 2022-10-18)
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 2b55e479e6)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 20:46:47 +03:00
Paolo Bonzini 1e029102e6 scsi-generic: fix buffer overflow on block limits inquiry
Using linux 6.x guest, at boot time, an inquiry on a scsi-generic
device makes qemu crash.  This is caused by a buffer overflow when
scsi-generic patches the block limits VPD page.

Do the operations on a temporary on-stack buffer that is guaranteed
to be large enough.

Reported-by: Théo Maillart <[email protected]>
Analyzed-by: Théo Maillart <[email protected]>
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 9bd634b2f5)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 20:46:29 +03:00
Richard Henderson c283a4bc76 target/arm: Fix vd == vm overlap in sve_ldff1_z
If vd == vm, copy vm to scratch, so that we can pre-zero
the output and still access the gather indicies.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1612
Signed-off-by: Richard Henderson <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit a6771f2f5c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 17:56:51 +03:00
Eric Blake c0ad2a9191 migration: Attempt disk reactivation in more failure scenarios
Commit fe904ea824 added a fail_inactivate label, which tries to
reactivate disks on the source after a failure while s->state ==
MIGRATION_STATUS_ACTIVE, but didn't actually use the label if
qemu_savevm_state_complete_precopy() failed.  This failure to
reactivate is also present in commit 6039dd5b1c (also covering the new
s->state == MIGRATION_STATUS_DEVICE state) and 403d18ae (ensuring
s->block_inactive is set more reliably).

Consolidate the two labels back into one - no matter HOW migration is
failed, if there is any chance we can reach vm_start() after having
attempted inactivation, it is essential that we have tried to restart
disks before then.  This also makes the cleanup more like
migrate_fd_cancel().

Suggested-by: Kevin Wolf <[email protected]>
Signed-off-by: Eric Blake <[email protected]>
Message-Id: <[email protected]>
Acked-by: Peter Xu <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 6dab4c93ec)
Signed-off-by: Michael Tokarev <[email protected]>
(Mjt: minor context tweak near added comment in migration/migration.c)
2023-05-18 16:59:30 +03:00
Eric Blake d2a811dd7d migration: Minor control flow simplification
No need to declare a temporary variable.

Suggested-by: Juan Quintela <[email protected]>
Fixes: 1df36e8c6289 ("migration: Handle block device inactivation failures better")
Signed-off-by: Eric Blake <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
(cherry picked from commit 5d39f44d7a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 16:57:44 +03:00
Eric Blake cb898262a4 migration: Handle block device inactivation failures better
Consider what happens when performing a migration between two host
machines connected to an NFS server serving multiple block devices to
the guest, when the NFS server becomes unavailable.  The migration
attempts to inactivate all block devices on the source (a necessary
step before the destination can take over); but if the NFS server is
non-responsive, the attempt to inactivate can itself fail.  When that
happens, the destination fails to get the migrated guest (good,
because the source wasn't able to flush everything properly):

  (qemu) qemu-kvm: load of migration failed: Input/output error

at which point, our only hope for the guest is for the source to take
back control.  With the current code base, the host outputs a message, but then appears to resume:

  (qemu) qemu-kvm: qemu_savevm_state_complete_precopy_non_iterable: bdrv_inactivate_all() failed (-1)

  (src qemu)info status
   VM status: running

but a second migration attempt now asserts:

  (src qemu) qemu-kvm: ../block.c:6738: int bdrv_inactivate_recurse(BlockDriverState *): Assertion `!(bs->open_flags & BDRV_O_INACTIVE)' failed.

Whether the guest is recoverable on the source after the first failure
is debatable, but what we do not want is to have qemu itself fail due
to an assertion.  It looks like the problem is as follows:

In migration.c:migration_completion(), the source sets 'inactivate' to
true (since COLO is not enabled), then tries
savevm.c:qemu_savevm_state_complete_precopy() with a request to
inactivate block devices.  In turn, this calls
block.c:bdrv_inactivate_all(), which fails when flushing runs up
against the non-responsive NFS server.  With savevm failing, we are
now left in a state where some, but not all, of the block devices have
been inactivated; but migration_completion() then jumps to 'fail'
rather than 'fail_invalidate' and skips an attempt to reclaim those
those disks by calling bdrv_activate_all().  Even if we do attempt to
reclaim disks, we aren't taking note of failure there, either.

Thus, we have reached a state where the migration engine has forgotten
all state about whether a block device is inactive, because we did not
set s->block_inactive in enough places; so migration allows the source
to reach vm_start() and resume execution, violating the block layer
invariant that the guest CPUs should not be restarted while a device
is inactive.  Note that the code in migration.c:migrate_fd_cancel()
will also try to reactivate all block devices if s->block_inactive was
set, but because we failed to set that flag after the first failure,
the source assumes it has reclaimed all devices, even though it still
has remaining inactivated devices and does not try again.  Normally,
qmp_cont() will also try to reactivate all disks (or correctly fail if
the disks are not reclaimable because NFS is not yet back up), but the
auto-resumption of the source after a migration failure does not go
through qmp_cont().  And because we have left the block layer in an
inconsistent state with devices still inactivated, the later migration
attempt is hitting the assertion failure.

Since it is important to not resume the source with inactive disks,
this patch marks s->block_inactive before attempting inactivation,
rather than after succeeding, in order to prevent any vm_start() until
it has successfully reactivated all devices.

See also https://bugzilla.redhat.com/show_bug.cgi?id=2058982

Signed-off-by: Eric Blake <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Acked-by: Lukas Straub <[email protected]>
Tested-by: Lukas Straub <[email protected]>
Signed-off-by: Juan Quintela <[email protected]>
(cherry picked from commit 403d18ae38)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 16:57:30 +03:00
Michael Tokarev 45a67df841 linux-user: fix getgroups/setgroups allocations
linux-user getgroups(), setgroups(), getgroups32() and setgroups32()
used alloca() to allocate grouplist arrays, with unchecked gidsetsize
coming from the "guest".  With NGROUPS_MAX being 65536 (linux, and it
is common for an application to allocate NGROUPS_MAX for getgroups()),
this means a typical allocation is half the megabyte on the stack.
Which just overflows stack, which leads to immediate SIGSEGV in actual
system getgroups() implementation.

An example of such issue is aptitude, eg
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=811087#72

Cap gidsetsize to NGROUPS_MAX (return EINVAL if it is larger than that),
and use heap allocation for grouplist instead of alloca().  While at it,
fix coding style and make all 4 implementations identical.

Try to not impose random limits - for example, allow gidsetsize to be
negative for getgroups() - just do not allocate negative-sized grouplist
in this case but still do actual getgroups() call.  But do not allow
negative gidsetsize for setgroups() since its argument is unsigned.

Capping by NGROUPS_MAX seems a bit arbitrary, - we can do more, it is
not an error if set size will be NGROUPS_MAX+1. But we should not allow
integer overflow for the array being allocated. Maybe it is enough to
just call g_try_new() and return ENOMEM if it fails.

Maybe there's also no need to convert setgroups() since this one is
usually smaller and known beforehand (KERN_NGROUPS_MAX is actually 63, -
this is apparently a kernel-imposed limit for runtime group set).

The patch fixes aptitude segfault mentioned above.

Signed-off-by: Michael Tokarev <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit 1e35d32789)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 14:44:13 +03:00
Daniil Kovalev 69a6ea7c4b linux-user: Fix mips fp64 executables loading
If a program requires fr1, we should set the FR bit of CP0 control status
register and add F64 hardware flag. The corresponding `else if` branch
statement is copied from the linux kernel sources (see `arch_check_elf` function
in linux/arch/mips/kernel/elf.c).

Signed-off-by: Daniil Kovalev <[email protected]>
Reviewed-by: Jiaxun Yang <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
(cherry picked from commit a0f8d2701b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 14:44:13 +03:00
Alex Bennée 0b1b5a4204 tests/docker: bump the xtensa base to debian:11-slim
Stretch is going out of support so things like security updates will
fail. As the toolchain itself is binary it hopefully won't mind the
underlying OS being updated.

Message-Id: <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Juan Quintela <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reported-by: Richard Henderson <[email protected]>
(cherry picked from commit 3217b84f3c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-18 14:44:13 +03:00
Lizhi Yang eb82a80f51 docs/about/emulation: fix typo
Duplicated word "are".

Signed-off-by: Lizhi Yang <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit c70bb9a771)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-17 12:27:58 +03:00
Claudio Imbrenda 8ad637881f util/async-teardown: wire up query-command-line-options
Add new -run-with option with an async-teardown=on|off parameter. It is
visible in the output of query-command-line-options QMP command, so it
can be discovered and used by libvirt.

The option -async-teardown is now redundant, deprecate it.

Reported-by: Boris Fiuczynski <[email protected]>
Fixes: c891c24b1a ("os-posix: asynchronous teardown for shutdown on Linux")
Signed-off-by: Claudio Imbrenda <[email protected]>
Message-Id: <[email protected]>
[thuth: Add curly braces to fix error with GCC 8.5, fix bug in deprecated.rst]
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 80bd81cadd)
Signed-off-by: Michael Tokarev <[email protected]>
(Mjt: context tweak in docs/about/deprecated.rst)
2023-05-17 12:27:58 +03:00
Claudio Imbrenda 21b54a683d s390x/pv: Fix spurious warning with asynchronous teardown
Kernel commit 292a7d6fca33 ("KVM: s390: pv: fix asynchronous teardown
for small VMs") causes the KVM_PV_ASYNC_CLEANUP_PREPARE ioctl to fail
if the VM is not larger than 2GiB. QEMU would attempt it and fail,
print an error message, and then proceed with a normal teardown.

Avoid attempting to use asynchronous teardown altogether when the VM is
not larger than 2 GiB. This will avoid triggering the error message and
also avoid pointless overhead; normal teardown is fast enough for small
VMs.

Reported-by: Marc Hartmayer <[email protected]>
Fixes: c3a073c610 ("s390x/pv: Add support for asynchronous teardown for reboot")
Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Claudio Imbrenda <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
[thuth: Fix inline function parameter in pv.h]
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 88693ab2a5)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-17 12:27:58 +03:00
Richard Henderson 36cd9bc8e2 tcg/i386: Set P_REXW in tcg_out_addi_ptr
The REXW bit must be set to produce a 64-bit pointer result; the
bit is disabled in 32-bit mode, so we can do this unconditionally.

Fixes: 7d9e1ee424 ("tcg/i386: Adjust assert in tcg_out_addi_ptr")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1592
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1642
Signed-off-by: Richard Henderson <[email protected]>
(cherry picked from commit 988998503b)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-17 12:27:58 +03:00
Jason Andryuk 117f33c9a7 9pfs/xen: Fix segfault on shutdown
xen_9pfs_free can't use gnttabdev since it is already closed and NULL-ed
out when free is called.  Do the teardown in _disconnect().  This
matches the setup done in _connect().

trace-events are also added for the XenDevOps functions.

Signed-off-by: Jason Andryuk <[email protected]>
Reviewed-by: Stefano Stabellini <[email protected]>
Message-Id: <[email protected]>
[C.S.: - Remove redundant return in xen_9pfs_free().
       - Add comment to trace-events. ]
Signed-off-by: Christian Schoenebeck <[email protected]>
(cherry picked from commit 92e667f6fd)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-17 12:27:58 +03:00
Ilya Leoshkevich e347aa89dd s390x/tcg: Fix LDER instruction format
It's RRE, not RXE.

Found by running valgrind's none/tests/s390x/bfp-2.

Fixes: 86b59624c4 ("s390x/tcg: Implement LOAD LENGTHENED short HFP to long HFP")
Reviewed-by: David Hildenbrand <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit 970641de01)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-17 12:27:58 +03:00
Ilya Leoshkevich b858c53ef6 target/s390x: Fix EXECUTE of relative branches
Fix a problem similar to the one fixed by commit 703d03a4aa
("target/s390x: Fix EXECUTE of relative long instructions"), but now
for relative branches.

Reported-by: Nina Schoetterl-Glausch <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
(cherry picked from commit e8ecdfeb30)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-16 19:08:39 +03:00
Shivaprasad G Bhat 7ceebe3f90 tcg: ppc64: Fix mask generation for vextractdm
In function do_extractm() the mask is calculated as
dup_const(1 << (element_width - 1)). '1' being signed int
works fine for MO_8,16,32. For MO_64, on PPC64 host
this ends up becoming 0 on compilation. The vextractdm
uses MO_64, and it ends up having mask as 0.

Explicitly use 1ULL instead of signed int 1 like its
used everywhere else.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1536
Signed-off-by: Shivaprasad G Bhat <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Lucas Mateus Castro <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Reviewed-by: Cédric Le Goater <[email protected]>
Message-Id: <168319292809.1159309.5817546227121323288.stgit@ltc-boston1.aus.stglabs.ibm.com>
Signed-off-by: Daniel Henrique Barboza <[email protected]>
(cherry picked from commit 6a5d81b172)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-15 18:42:50 +03:00
Cédric Le Goater 950882af67 async: Suppress GCC13 false positive in aio_bh_poll()
GCC13 reports an error :

../util/async.c: In function ‘aio_bh_poll’:
include/qemu/queue.h:303:22: error: storing the address of local variable ‘slice’ in ‘*ctx.bh_slice_list.sqh_last’ [-Werror=dangling-pointer=]
  303 |     (head)->sqh_last = &(elm)->field.sqe_next;                          \
      |     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../util/async.c:169:5: note: in expansion of macro ‘QSIMPLEQ_INSERT_TAIL’
  169 |     QSIMPLEQ_INSERT_TAIL(&ctx->bh_slice_list, &slice, next);
      |     ^~~~~~~~~~~~~~~~~~~~
../util/async.c:161:17: note: ‘slice’ declared here
  161 |     BHListSlice slice;
      |                 ^~~~~
../util/async.c:161:17: note: ‘ctx’ declared here

But the local variable 'slice' is removed from the global context list
in following loop of the same routine. Add a pragma to silent GCC.

Cc: Stefan Hajnoczi <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Daniel P. Berrangé <[email protected]>
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Tested-by: Daniel Henrique Barboza <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit d66ba6dc1c)
Signed-off-by: Michael Tokarev <[email protected]>
(Mjt: cherry-picked to stable-8.0 to eliminate CI failures on win*)
2023-05-15 18:03:51 +03:00
Peter Maydell e09f912550 target/arm: Correct AArch64.S2MinTxSZ 32-bit EL1 input size check
In check_s2_mmu_setup() we have a check that is attempting to
implement the part of AArch64.S2MinTxSZ that is specific to when EL1
is AArch32:

    if !s1aarch64 then
        // EL1 is AArch32
        min_txsz = Min(min_txsz, 24);

Unfortunately we got this wrong in two ways:

(1) The minimum txsz corresponds to a maximum inputsize, but we got
the sense of the comparison wrong and were faulting for all
inputsizes less than 40 bits

(2) We try to implement this as an extra check that happens after
we've done the same txsz checks we would do for an AArch64 EL1, but
in fact the pseudocode is *loosening* the requirements, so that txsz
values that would fault for an AArch64 EL1 do not fault for AArch32
EL1, because it does Min(old_min, 24), not Max(old_min, 24).

You can see this also in the text of the Arm ARM in table D8-8, which
shows that where the implemented PA size is less than 40 bits an
AArch32 EL1 is still OK with a configured stage2 T0SZ for a 40 bit
IPA, whereas if EL1 is AArch64 then the T0SZ must be big enough to
constrain the IPA to the implemented PA size.

Because of part (2), we can't do this as a separate check, but
have to integrate it into aa64_va_parameters(). Add a new argument
to that function to indicate that EL1 is 32-bit. All the existing
callsites except the one in get_phys_addr_lpae() can pass 'false',
because they are either doing a lookup for a stage 1 regime or
else they don't care about the tsz/tsz_oob fields.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1627
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-id: [email protected]
(cherry picked from commit 478dccbb99)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-14 11:25:57 +03:00
Peter Maydell 80a2c1b5fe ui: Fix pixel colour channel order for PNG screenshots
When we take a PNG screenshot the ordering of the colour channels in
the data is not correct, resulting in the image having weird
colouring compared to the actual display.  (Specifically, on a
little-endian host the blue and red channels are swapped; on
big-endian everything is wrong.)

This happens because the pixman idea of the pixel data and the libpng
idea differ.  PIXMAN_a8r8g8b8 defines that pixels are 32-bit values,
with A in bits 24-31, R in bits 16-23, G in bits 8-15 and B in bits
0-7.  This means that on little-endian systems the bytes in memory
are
   B G R A
and on big-endian systems they are
   A R G B

libpng, on the other hand, thinks of pixels as being a series of
values for each channel, so its format PNG_COLOR_TYPE_RGB_ALPHA
always wants bytes in the order
   R G B A

This isn't the same as the pixman order for either big or little
endian hosts.

The alpha channel is also unnecessary bulk in the output PNG file,
because there is no alpha information in a screenshot.

To handle the endianness issue, we already define in ui/qemu-pixman.h
various PIXMAN_BE_* and PIXMAN_LE_* values that give consistent
byte-order pixel channel formats.  So we can use PIXMAN_BE_r8g8b8 and
PNG_COLOR_TYPE_RGB, which both have an in-memory byte order of
    R G B
and 3 bytes per pixel.

(PPM format screenshots get this right; they already use the
PIXMAN_BE_r8g8b8 format.)

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1622
Fixes: 9a0a119a38 ("Added parameter to take screenshot with screendump as PNG")
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-id: [email protected]
(cherry picked from commit cd22a0f520)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-14 11:24:05 +03:00
Peter Maydell 3148fe1ac8 target/arm: Fix handling of SW and NSW bits for stage 2 walks
We currently don't correctly handle the VSTCR_EL2.SW and VTCR_EL2.NSW
configuration bits.  These allow configuration of whether the stage 2
page table walks for Secure IPA and NonSecure IPA should do their
descriptor reads from Secure or NonSecure physical addresses. (This
is separate from how the translation table base address and other
parameters are set: an NS IPA always uses VTTBR_EL2 and VTCR_EL2
for its base address and walk parameters, regardless of the NSW bit,
and similarly for Secure.)

Provide a new function ptw_idx_for_stage_2() which returns the
MMU index to use for descriptor reads, and use it to set up
the .in_ptw_idx wherever we call get_phys_addr_lpae().

For a stage 2 walk, wherever we call get_phys_addr_lpae():
 * .in_ptw_idx should be ptw_idx_for_stage_2() of the .in_mmu_idx
 * .in_secure should be true if .in_mmu_idx is Stage2_S

This allows us to correct S1_ptw_translate() so that it consistently
always sets its (out_secure, out_phys) to the result it gets from the
S2 walk (either by calling get_phys_addr_lpae() or by TLB lookup).
This makes better conceptual sense because the S2 walk should return
us an (address space, address) tuple, not an address that we then
randomly assign to S or NS.

Our previous handling of SW and NSW was broken, so guest code
trying to use these bits to put the s2 page tables in the "other"
address space wouldn't work correctly.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1600
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-id: [email protected]
(cherry picked from commit fcc0b0418f)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-14 11:23:49 +03:00
Richard Henderson 4b59b5bd14 accel/tcg: Fix atomic_mmu_lookup for reads
A copy-paste bug had us looking at the victim cache for writes.

Cc: [email protected]
Reported-by: Peter Maydell <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Fixes: 08dff435e2 ("tcg: Probe the proper permissions for atomic ops")
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit 8c313254e6)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-11 15:40:16 +03:00
Jonathan Cameron 488ad8b302 hw/pci-bridge: pci_expander_bridge fix type in pxb_cxl_dev_reset()
Reproduce issue with

configure --enable-qom-cast-debug ...

qemu-system-x86_64 -display none -machine q35,cxl=on -device pxb-cxl,bus=pcie.0

  hw/pci-bridge/pci_expander_bridge.c:54:PXB_DEV: Object 0x5570e0b1ada0 is not an instance of type pxb
  Aborted

The type conversion results in the right state structure, but PXB_DEV is
not a parent of PXB_CXL_DEV hence the error. Rather than directly
cleaning up the inheritance, this is the minimal fix which will be
followed by the cleanup.

Fixes: 154070eaf6 ("hw/pxb-cxl: Support passthrough HDM Decoders unless overridden")
Reported-by: Peter Maydell <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Cc: [email protected]
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
(cherry picked from commit 9136f661c7)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Bin Meng f91d0db71e target/riscv: Restore the predicate() NULL check behavior
When reading a non-existent CSR QEMU should raise illegal instruction
exception, but currently it just exits due to the g_assert() check.

This actually reverts commit 0ee342256a.
Some comments are also added to indicate that predicate() must be
provided for an implemented CSR.

Reported-by: Fei Wu <[email protected]>
Signed-off-by: Bin Meng <[email protected]>
Reviewed-by: Daniel Henrique Barboza <[email protected]>
Reviewed-by: Weiwei Li <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
Reviewed-by: LIU Zhiwei <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit eae04c4c13)
(mjt: context edit after ce3af0bbbc "target/riscv: add support for Zcmt extension")
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
LIU Zhiwei f5301431e8 target/riscv: Fix itrigger when icount is used
When I boot a ubuntu image, QEMU output a "Bad icount read" message and exit.
The reason is that when execute helper_mret or helper_sret, it will
cause a call to icount_get_raw_locked (), which needs set can_do_io flag
on cpustate.

Thus we setting this flag when execute these two instructions.

Signed-off-by: LIU Zhiwei <[email protected]>
Reviewed-by: Weiwei Li <[email protected]>
Acked-by: Alistair Francis <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alistair Francis <[email protected]>
(cherry picked from commit df3ac6da47)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Kevin Wolf 3b02d0db4a block: Don't call no_coroutine_fns in qmp_block_resize()
This QMP handler runs in a coroutine, so it must use the corresponding
no_co_wrappers instead.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2185688
Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 0c7d204f50)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Kevin Wolf e0deae4f49 block: bdrv/blk_co_unref() for calls in coroutine context
These functions must not be called in coroutine context, because they
need write access to the graph.

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit b2ab5f545f)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Kevin Wolf 38a598aee3 block: Consistently call bdrv_activate() outside coroutine
Migration code can call bdrv_activate() in coroutine context, whereas
other callers call it outside of coroutines. As it calls other code that
is not supposed to run in coroutines, standardise on running outside of
coroutines.

This adds a no_co_wrapper to switch to the main loop before calling
bdrv_activate().

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit da4afaff07)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Kevin Wolf 2197a94cb4 block: Fix use after free in blockdev_mark_auto_del()
job_cancel_locked() drops the job list lock temporarily and it may call
aio_poll(). We must assume that the list has changed after this call.
Also, with unlucky timing, it can end up freeing the job during
job_completed_txn_abort_locked(), making the job pointer invalid, too.

For both reasons, we can't just continue at block_job_next_locked(job).
Instead, start at the head of the list again after job_cancel_locked()
and skip those jobs that we already cancelled (or that are completing
anyway).

Cc: [email protected]
Signed-off-by: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit e2626874a3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Paolo Bonzini 8322e5300f meson: leave unnecessary modules out of the build
meson.build files choose whether to build modules based on foo.found()
expressions.  If a feature is enabled (e.g. --enable-gtk), these expressions
are true even if the code is not used by any emulator, and this results
in an unexpected difference between modular and non-modular builds.

For non-modular builds, the files are not included in any binary, and
therefore the source files are never processed.  For modular builds,
however, all .so files are unconditionally built by default, and therefore
a normal "make" tries to build them.  However, the corresponding trace-*.h
files are absent due to this conditional:

if have_system
  trace_events_subdirs += [
    ...
    'ui',
    ...
  ]
endif

which was added to avoid wasting time running tracetool on unused trace-events
files.  This causes a compilation failure; fix it by skipping module builds
entirely if (depending on the module directory) have_block or have_system
are false.

Reported-by: Michael Tokarev <[email protected]>
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit ef709860ea)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Shivaprasad G Bhat 4dc5df865c softfloat: Fix the incorrect computation in float32_exp2
The float32_exp2 function is computing wrong exponent of 2.

For example, with the following set of values {0.1, 2.0, 2.0, -1.0},
the expected output would be {1.071773, 4.000000, 4.000000, 0.500000}.
Instead, the function is computing {1.119102, 3.382044, 3.382044, -0.191022}

Looking at the code, the float32_exp2() attempts to do this

                  2     3     4     5           n
  x        x     x     x     x     x           x
 e  = 1 + --- + --- + --- + --- + --- + ... + --- + ...
           1!    2!    3!    4!    5!          n!

But because of the typo it ends up doing

  x        x     x     x     x     x           x
 e  = 1 + --- + --- + --- + --- + --- + ... + --- + ...
           1!    2!    3!    4!    5!          n!

This is because instead of the xnp which holds the numerator, parts_muladd
is using the xp which is just 'x'.  Commit '572c4d862ff2' refactored this
function, and mistakenly used xp instead of xnp.

Cc: [email protected]
Fixes: 572c4d862f "softfloat: Convert float32_exp2 to FloatParts"
Partially-Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1623
Reported-By: Luca Barbato (https://gitlab.com/lu-zero)
Signed-off-by: Shivaprasad G Bhat <[email protected]>
Signed-off-by: Vaibhav Jain <[email protected]>
Message-Id: <168304110865.537992.13059030916325018670.stgit@localhost.localdomain>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
(cherry picked from commit 1098cc3fcf)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Stefan Hajnoczi a458252c16 block/export: call blk_set_dev_ops(blk, NULL, NULL)
Most export types install BlockDeviceOps pointers. It is easy to forget
to remove them because that happens automatically via the "drive" qdev
property in hw/ but not block/export/.

Put blk_set_dev_ops(blk, NULL, NULL) calls in the core export.c code so
the export types don't need to remember.

This fixes the nbd and vhost-user-blk export types.

Fixes: fd6afc501a ("nbd/server: Use drained block ops to quiesce the server")
Fixes: ca858a5fe9 ("vhost-user-blk-server: notify client about disk resize")
Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Eric Blake <[email protected]>
(cherry picked from commit de79b52604)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell f6227dd60d hw/net/allwinner-sun8i-emac: Correctly byteswap descriptor fields
In allwinner-sun8i-emac we just read directly from guest memory into
a host FrameDescriptor struct and back.  This only works on
little-endian hosts.  Reading and writing of descriptors is already
abstracted into functions; make those functions also handle the
byte-swapping so that TransferDescriptor structs as seen by the rest
of the code are always in host-order, and fix two places that were
doing ad-hoc descriptor reading without using the functions.

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit a4ae17e5ec)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell 2daa9e4d7e hw/sd/allwinner-sdhost: Correctly byteswap descriptor fields
In allwinner_sdhost_process_desc() we just read directly from
guest memory into a host TransferDescriptor struct and back.
This only works on little-endian hosts. Abstract the reading
and writing of descriptors into functions that handle the
byte-swapping so that TransferDescriptor structs as seen by
the rest of the code are always in host-order.

This fixes a failure of one of the avocado tests on s390.

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit 3e20d90824)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell 6944823a6f target/arm: Define and use new load_cpu_field_low32()
In several places in the 32-bit Arm translate.c, we try to use
load_cpu_field() to load from a CPUARMState field into a TCGv_i32
where the field is actually 64-bit. This works on little-endian
hosts, but gives the wrong half of the register on big-endian.

Add a new load_cpu_field_low32() which loads the low 32 bits
of a 64-bit field into a TCGv_i32. The new macro includes a
compile-time check against accidentally using it on a field
of the wrong size. Use it to fix the two places in the code
where we were using load_cpu_field() on a 64-bit field.

This fixes a bug where on big-endian hosts the guest would
crash after executing an ERET instruction, and a more corner
case one where some UNDEFs for attempted accesses to MSR
banked registers from Secure EL1 might go to the wrong EL.

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-id: [email protected]
(cherry picked from commit 7f3a3d3dc4)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell af08c70ef5 hw/intc/allwinner-a10-pic: Don't use set_bit()/clear_bit()
The Allwinner PIC model uses set_bit() and clear_bit() to update the
values in its irq_pending[] array when an interrupt arrives.  However
it is using these functions wrongly: they work on an array of type
'long', and it is passing an array of type 'uint32_t'.  Because the
code manually figures out the right array element, this works on
little-endian hosts and on 32-bit big-endian hosts, where bits 0..31
in a 'long' are in the same place as they are in a 'uint32_t'.
However it breaks on 64-bit big-endian hosts.

Remove the use of set_bit() and clear_bit() in favour of using
deposit32() on the array element.  This fixes a bug where on
big-endian 64-bit hosts the guest kernel would hang early on in
bootup.

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit 2c5fa0778c)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell 975f12aa52 hw/arm/raspi: Use arm_write_bootloader() to write boot code
When writing the secondary-CPU stub boot loader code to the guest,
use arm_write_bootloader() instead of directly calling
rom_add_blob_fixed().  This fixes a bug on big-endian hosts, because
arm_write_bootloader() will correctly byte-swap the host-byte-order
array values into the guest-byte-order to write into the guest
memory.

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Tested-by: Cédric Le Goater <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
(cherry picked from commit 0acbdb4c4a)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Cédric Le Goater 5477a21350 hw/arm/aspeed: Use arm_write_bootloader() to write the bootloader
When writing the secondary-CPU stub boot loader code to the guest,
use arm_write_bootloader() instead of directly calling
rom_add_blob_fixed().  This fixes a bug on big-endian hosts, because
arm_write_bootloader() will correctly byte-swap the host-byte-order
array values into the guest-byte-order to write into the guest
memory.

Cc: [email protected]
Signed-off-by: Cédric Le Goater <[email protected]>
Tested-by: Cédric Le Goater <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Message-id: [email protected]
[PMM: Moved the "make arm_write_bootloader() function public" part
 to its own patch; updated commit message to note that this fixes
 an actual bug; adjust to the API changes noted in previous commit]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 902bba549f)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Cédric Le Goater 168f193c5b hw/arm/boot: Make write_bootloader() public as arm_write_bootloader()
The arm boot.c code includes a utility function write_bootloader()
which assists in writing a boot-code fragment into guest memory,
including handling endianness and fixing it up with entry point
addresses and similar things.  This is useful not just for the boot.c
code but also in board model code, so rename it to
arm_write_bootloader() and make it globally visible.

Since we are making it public, make its API a little neater: move the
AddressSpace* argument to be next to the hwaddr argument, and allow
the fixupcontext array to be const, since we never modify it in this
function.

Cc: [email protected]
Signed-off-by: Cédric Le Goater <[email protected]>
Tested-by: Cédric Le Goater <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
Message-id: [email protected]
[PMM: Split out from another patch by Cédric, added doc comment]
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 0fe43f0abf)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell 61ef050639 hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc()
The msf2-emac ethernet controller has functions emac_load_desc() and
emac_store_desc() which read and write the in-memory descriptor
blocks and handle conversion between guest and host endianness.

As currently written, emac_store_desc() does the endianness
conversion in-place; this means that it effectively consumes the
input EmacDesc struct, because on a big-endian host the fields will
be overwritten with the little-endian versions of their values.
Unfortunately, in all the callsites the code continues to access
fields in the EmacDesc struct after it has called emac_store_desc()
-- specifically, it looks at the d.next field.

The effect of this is that on a big-endian host networking doesn't
work because the address of the next descriptor is corrupted.

We could fix this by making the callsite avoid using the struct; but
it's more robust to have emac_store_desc() leave its input alone.

(emac_load_desc() also does an in-place conversion, but here this is
fine, because the function is supposed to be initializing the
struct.)

Cc: [email protected]
Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Message-id: [email protected]
(cherry picked from commit d565f58b38)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Akihiko Odaki f0c5a78029 target/arm: Initialize debug capabilities only once
kvm_arm_init_debug() used to be called several times on a SMP system as
kvm_arch_init_vcpu() calls it. Move the call to kvm_arch_init() to make
sure it will be called only once; otherwise it will overwrite pointers
to memory allocated with the previous call and leak it.

Fixes: e4482ab7e3 ("target-arm: kvm - add support for HW assisted debug")
Suggested-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Akihiko Odaki <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit ad5c6ddea3)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Peter Maydell 9448a0fa11 docs/about/deprecated.rst: Add "since 7.1" tag to dtb-kaslr-seed deprecation
In commit 5242876f37 we deprecated the dtb-kaslr-seed property of
the virt board, but forgot the "since n.n" tag in the documentation
of this in deprecated.rst.

This deprecation note first appeared in the 7.1 release, so
retrospectively add the correct "since 7.1" annotation to it.

Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>
Message-id: [email protected]
(cherry picked from commit ac64ebbecf)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Alex Bennée 8c3cf36260 qemu-options: finesse the recommendations around -blockdev
We are a bit premature in recommending -blockdev/-device as the best
way to configure block devices. It seems there are times the more
human friendly -drive still makes sense especially when -snapshot is
involved.

Improve the language to hopefully make things clearer.

Suggested-by: Michael Tokarev <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Cc: Markus Armbruster <[email protected]>
Cc: Kevin Wolf <[email protected]>
Message-Id: <[email protected]>
(cherry picked from commit c1654c3e37)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Wang Liang f528cfc3fa block/monitor: Fix crash when executing HMP commit
hmp_commit() calls blk_is_available() from a non-coroutine context (and
in the main loop). blk_is_available() is a co_wrapper_mixed_bdrv_rdlock
function, and in the non-coroutine context it calls AIO_WAIT_WHILE(),
which crashes if the aio_context lock is not taken before.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1615
Signed-off-by: Wang Liang <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Emanuele Giuseppe Esposito <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
(cherry picked from commit 8c1e8fb2e7)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
Igor Mammedov bb47b5bc2e acpi: pcihp: allow repeating hot-unplug requests
with Q35 using ACPI PCI hotplug by default, user's request to unplug
device is ignored when it's issued before guest OS has been booted.
And any additional attempt to request device hot-unplug afterwards
results in following error:

  "Device XYZ is already in the process of unplug"

arguably it can be considered as a regression introduced by [2],
before which it was possible to issue unplug request multiple
times.

Accept new uplug requests after timeout (1ms). This brings ACPI PCI
hotplug on par with native PCIe unplug behavior [1] and allows user
to repeat unplug requests at propper times.
Set expire timeout to arbitrary 1msec so user won't be able to
flood guest with SCI interrupts by calling device_del in tight loop.

PS:
ACPI spec doesn't mandate what OSPM can do with GPEx.status
bits set before it's booted => it's impl. depended.
Status bits may be retained (I tested with one Windows version)
or cleared (Linux since 2.6 kernel times) during guest's ACPI
subsystem initialization.
Clearing status bits (though not wrong per se) hides the unplug
event from guest, and it's upto user to repeat device_del later
when guest is able to handle unplug requests.

1) 18416c62e3 ("pcie: expire pending delete")
2)
Fixes: cce8944cc9 ("qdev-monitor: Forbid repeated device_del")
Signed-off-by: Igor Mammedov <[email protected]>
Acked-by: Gerd Hoffmann <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
Message-Id: <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Ani Sinha <[email protected]>
(cherry picked from commit 0f689cf5ad)
Signed-off-by: Michael Tokarev <[email protected]>
2023-05-10 20:50:38 +03:00
osy 689c8fd77a Merge tag 'v8.0.0' into utm-edition
v8.0.0 release
2023-04-30 20:14:13 -07:00
Axel Heider 134a1a3320 hw/timer/imx_epit: fix limit check
Fix the limit check. If the limit is less than the compare value,
the timer can never reach this value, thus it will never fire.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1491
Signed-off-by: Axel Heider <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 25d758175d)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-27 08:51:16 +03:00
Axel Heider ac7f07ebc8 hw/timer/imx_epit: don't shadow variable
Fix issue reported by Coverity.

Signed-off-by: Axel Heider <[email protected]>
Message-id: [email protected]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
(cherry picked from commit 542fd43d79)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-27 08:51:16 +03:00
Yang Zhong 3ed99d232c target/i386: Change wrong XFRM value in SGX CPUID leaf
The previous patch wrongly replaced FEAT_XSAVE_XCR0_{LO|HI} with
FEAT_XSAVE_XSS_{LO|HI} in CPUID(EAX=12,ECX=1):{ECX,EDX}.  As a result,
SGX enclaves only supported SSE and x87 feature (xfrm=0x3).

Fixes: 301e90675c ("target/i386: Enable support for XSAVES based features")
Signed-off-by: Yang Zhong <[email protected]>
Reviewed-by: Yang Weijiang <[email protected]>
Reviewed-by: Kai Huang <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 72497cff89)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-27 08:51:16 +03:00
Paolo Bonzini 6f7b9f7b6f vnc: avoid underflow when accessing user-provided address
If hostlen is zero, there is a possibility that addrstr[hostlen - 1]
underflows and, if a closing bracked is there, hostlen - 2 is passed
to g_strndup() on the next line.  If websocket==false then
addrstr[0] would be a colon, but if websocket==true this could in
principle happen.

Fix it by checking hostlen.

Reported by Coverity.

Signed-off-by: Paolo Bonzini <[email protected]>
(cherry picked from commit 3f9c41c5df)
Signed-off-by: Michael Tokarev <[email protected]>
2023-04-26 18:17:51 +03:00
osy bd2fc471e7 Merge branch 'with_tcti_vectors' into utm-edition 2023-03-06 15:23:31 -08:00
Katherine Temkin 550af33ef5 meson tweaks for building with and _without_ JIT 2023-03-06 10:10:05 -08:00
osy 80c0e3099f vmnet: stop recieving events when VM is stopped
When the VM is stopped using the HMP command "stop", soon the handler will
stop reading from the vmnet interface. This causes a flood of
`VMNET_INTERFACE_PACKETS_AVAILABLE` events to arrive and puts the host CPU
at 100%. We fix this by removing the event handler from vmnet when the VM
is no longer in a running state and restore it when we return to a running
state.
2023-01-01 16:51:56 -08:00
osy c874e68e5a tcti: disable TARGET_TB_PCREL for TCTI
It is currently not supported.
2022-12-30 20:24:00 -08:00
osy 531da34587 hvf: support TSO mode (private feature)
Apple Silicon supports TSO mode which can be used for emulating strong
memory ordering in the guest. This feature requires the private entitlement
`com.apple.private.hypervisor` as well as a private function to modify
ACTLR_EL1 not exposed by the public Hypervisor framework.
2022-12-29 00:26:07 -08:00
osy 34b035535e spice-display: remove redundant glBindTexture 2022-12-24 17:08:52 -08:00
osy bb5c41eb13 spice-display: fix memory leak issues
1) Some of the error cases did not free GL memory.
2) Remove some unneeded logic and simplify the code.
3) Add a `eglMakeCurrent` to `spice_iosurface_destroy` to make sure we are
   freeing objects in the right context.
2022-12-20 15:56:07 -08:00
osy b3cf3579f5 Merge tag 'v7.2.0' into utm-edition
v7.2.0 release
2022-12-17 22:29:34 -08:00
osy 96e76ff0a1 Revert "egl-helpers: update EGL client version to 3.0"
This reverts commit f357b925b3.
2022-12-17 15:04:19 -08:00
osy 3ef0f0db05 Merge tag 'v7.1.0' into utm-edition
v7.1.0 release
2022-10-29 17:33:45 -07:00
osy f129a2b8db usbredir: avoid queuing hello packet on snapshot restore
When launching QEMU with "-loadvm", usbredir_create_parser() should avoid
setting up the hello packet (just as with "-incoming". On the latest version
of libusbredir, usbredirparser_unserialize() will return error if the parser
is not "pristine."
2022-08-08 16:13:20 -07:00
osy 6e9f737fcc vl: on -loadvm set run state to "restore-vm"
This allows us to differentiate between a fresh boot and a restore boot.
2022-08-08 16:11:21 -07:00
osy 51a16884c3 Revert "usbredir: avoid queuing hello packet on snapshot restore"
Run state is also in RUN_STATE_PRELAUNCH while "-S" is used.

This reverts commit 12d182898a.
2022-08-08 14:44:10 -07:00
osy 6626058f22 net/vmnet: use availability check at runtime
MAC_OS_X_VERSION_MIN_REQUIRED is set at compile time so this means that when
we target an older macOS version, it disables the newer features. With a
runtime check, we can selectively disable newer API features.
2022-05-17 19:48:48 -07:00
osy 0fbf694119 ui/cocoa: fix compile issues after merge 2022-05-11 16:34:54 -07:00
osy 12d182898a usbredir: avoid queuing hello packet on snapshot restore
When launching QEMU with "-loadvm", usbredir_create_parser() should avoid
setting up the hello packet (just as with "-incoming". On the latest version
of libusbredir, usbredirparser_unserialize() will return error if the parser
is not "pristine."
2022-05-06 21:09:31 -07:00
osy 25dfefc810 hw/arm/virt: revert old behaviour of highmem=off
On < macOS 12.4, a kernel panic is triggered for highmem=on and an error
is shown for highmem=off. We workaround this by inhibiting the error so
older versions of macOS can still use highmem=off.
2022-04-29 10:50:45 -07:00
osy 397bb125e1 Merge tag 'v7.0.0' into utm-edition
v7.0.0 release
2022-04-22 11:38:37 -07:00
osy 355b0824c6 Merge remote-tracking branch 'akihikodaki/macos' into utm-edition 2022-04-22 11:38:17 -07:00
Akihiko Odaki 84641e7ceb coreaudio: Initialize the buffer for device change
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:12:13 +09:00
Akihiko Odaki 1716a3f189 ui/cocoa: Use qemu_add_mouse_change_notifier
This eliminates the polling in cocoa_refresh and implements the
propagation of the mouse mode change from absolute to relative.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:12:08 +09:00
Gustavo Noronha Silva aac64f9286 ui/cocoa: handle mouse grab properly on window being key changes
Being key is similar to being focused on other platforms. When the
window loses focus at the moment it will still keep the mouse grabbed
unless it is using an absolute pointing device like a USB tablet.

That may happen in several ways as Mac OS does not let Qemu handle some
of the events even when it has a grab. Command-Tab will switch applications
if full-grab is off, and even if it is on you can still switch away from
by using 3-finger gestures on the trackpad to change spaces or open
Mission Control, for instance.

That behaviour is not ideal, as even though Qemu still believes it is
getting all the events, Mac OS has effectively released the mouse.
And it is worse with full-grab turned on, as it will still capture
the key events, making you unable to use the keyboard on the Mac OS
environment.

This change makes Qemu properly release the grab when Mac OS effectively
does it. In addition, it properly automatically regrabs the mouse when
the window becomes key and is fullscreen. While it makes sense to wait
for a click on a non-fullscreen window, as the user may just be moving
the window around, for instance, when it's fullscreen there is no point.

Signed-off-by: Gustavo Noronha Silva <[email protected]>
2022-03-25 16:12:02 +09:00
Akihiko Odaki 85af432691 ui/cocoa: Divide ui/cocoa.m 2022-03-25 16:11:56 +09:00
Akihiko Odaki a0167d013f ui/cocoa: Isolate fragments with preprocessor 2022-03-25 16:11:48 +09:00
Akihiko Odaki 3acd8e70ba ui/cocoa: Define types early 2022-03-25 16:11:42 +09:00
Akihiko Odaki e0af80866a Use virgl_renderer_borrow_texture_for_scanout
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:35 +09:00
Akihiko Odaki b3ebe68e23 ui/cocoa: Update cursor
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:28 +09:00
Akihiko Odaki 9e45375602 ui/cocoa: Take refresh rate into account
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:22 +09:00
Akihiko Odaki bdf261c858 Support Virgil 3D renderer on macOS
Virgil 3D renderer will be available with ui/cocoa on macOS.

The OpenGL backend is NSOpenGLContext for core profile, and
EGL (in particular, ANGLE) for ES profile.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:15 +09:00
Akihiko Odaki ad2fe378fe ui/cocoa: Do not scale UI without "Zoom To Fit"
Cocoa scales UI for high-resolution display like Retina, but we do not
need it since we now have our own "Zoom To Fit" work well also for
windows, and the guest is aware of the resolution thanks to UI
information. This change reverts the scaling.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:10 +09:00
Akihiko Odaki 3f620296d8 ui/curses: Do not use console_select
ui/curses is the only user of console_select. Move the implementation
to ui/curses.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:11:03 +09:00
Akihiko Odaki f2098f2c30 ui/cocoa: Do not use console_select
ui/cocoa needs to update the UI info when switching the console.
The behavior was implemented in cocoa_switch which was used to be called
by console_select. The function was however to switch the DisplaySurface
and overloaded. Have its own implementation of console_select and
update the UI info with it.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:57 +09:00
Akihiko Odaki 7dfd20c7e8 ui/vnc: Do not use console_select
console_select is shared by other displays and switching in one of them
triggers switching also in ui/vnc, circumventing key state
reinitialization specific to ui/vnc. Use its internal state to track
the current active console instead.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:48 +09:00
Akihiko Odaki 41eb76f5bf ui/vnc: Respect bound console
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:40 +09:00
Akihiko Odaki 99ac5e48e4 ui/console: Check console before emitting GL event
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 16:10:09 +09:00
Akihiko Odaki 67876f074e ui/cocoa: Respect left-command-key option
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:32 +09:00
Akihiko Odaki 781a23afc7 audio/mixeng: Do not declare unused variables
The unused variables when FLOAT_MIXENG is defined caused warnings on
Apple clang version 13.1.6 (clang-1316.0.21.2).

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:24 +09:00
Akihiko Odaki 1f24abea06 ui/cocoa: Use qemu_input_map_osx_to_qcode
ui/cocoa used to have a conversion table from macOS keycode to QKeyCode.
It is an unnecessary redundancy as ui/input-keymap.c already has such a
table. Worse, I added an incorrect mapping of kVK_JIS_Eisu and
kVK_JIS_Kana with commit 708b72557f.
According to the following documentations, the definitions in
ui/keycodemapdb/keymaps.csv, which ui/input-keymap.c uses, are correct:
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang1?language=objc
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang2?language=objc
https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/keyboard-japan-ime

Use qemu_input_map_osx_to_qcode to eliminate the redundancy and
incorrect mappings.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:17 +09:00
Akihiko Odaki de8f1b03d0 block/file-posix: Use O_RDWR for locking on macOS
qemu_lock_fd_test always returns 0 when fd is not open for writing and
exclusive is true on macOS 11.3.1.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:11 +09:00
Akihiko Odaki 66553a8213 ui/cocoa: Use NSWindow's ability to resize
This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
  provided by the platform. (The left-top green button.)

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:04:04 +09:00
Akihiko Odaki 4214699f96 coreaudio: Commit the result of init in the end
init_out_device may only commit some part of the result and leave the
state inconsistent when it encounters an error. Commit the result in
the end of the function so that it commits the result iif it sees no
error.

With this change, handle_voice_change can rely on core->outputDeviceID
to know whether the output device is initialized after calling
init_out_device.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:58 +09:00
Akihiko Odaki 401a81844b ui/cocoa: Do not raise keys before QEMU resigns active
ui/cocoa used to raise all keys before it resigns active to prevent a
stuck key problem caused by key up events it does not see while it is
inactive. The problem is solved by checking -[NSEvent modifierFlags] in
commit 6d73bb643a, which is better
because it handles the case that key *down* events are missed while it
is inactive.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:53 +09:00
Akihiko Odaki 129127242d virtio-gpu: Respect UI refresh rate for EDID
This change adds a new member, refresh_rate to QemuUIInfo in
include/ui/console.h. It represents the refresh rate of the
physical display backend, and it is more appropriate than
GUI update interval as the refresh rate which the emulated device
reports:
- sdl may set GUI update interval shorter than the refresh rate
  of the physical display to respond to user-generated events.
- sdl and vnc aggressively changes GUI update interval, but
  a guests is typically not designed to respond to frequent
  refresh rate changes, or frequent "display mode" changes in
  general. The frequency of refresh rate changes of the physical
  display backend matches better to the guest's expectation.

QemuUIInfo also has other members representing "display mode",
which makes it suitable for refresh rate representation. It has
a throttling of update notifications, and prevents frequent changes
of the display mode.

Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:03:47 +09:00
Akihiko Odaki c146fe8095 ui/cocoa: Initialize before setting UID and GID
Signed-off-by: Akihiko Odaki <[email protected]>
2022-03-25 13:02:50 +09:00
Akihiko Odaki e6441f8683 Merge tag 'patchew/[email protected]' 2022-03-18 18:20:45 +09:00
Vladislav Yaroshchuk 7135bae71b net/vmnet: update hmp-commands.hx
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk c9eb230657 net/vmnet: update qemu-options.hx
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk ee9a9b425f net/vmnet: implement bridged mode (vmnet-bridged)
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk 5286a192c8 net/vmnet: implement host mode (vmnet-host)
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk f854a87eeb net/vmnet: implement shared mode (vmnet-shared)
Interaction with vmnet.framework in different modes
differs only on configuration stage, so we can create
common `send`, `receive`, etc. procedures and reuse them.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk 1699eb16a7 net/vmnet: add vmnet backends to qapi/net
Create separate netdevs for each vmnet operating mode:
- vmnet-host
- vmnet-shared
- vmnet-bridged

Acked-by: Markus Armbruster <[email protected]>
Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Vladislav Yaroshchuk d1792ff228 net/vmnet: add vmnet dependency and customizable option
vmnet.framework dependency is added with 'vmnet' option
to enable or disable it. Default value is 'auto'.

used vmnet features are available since macOS 11.0,
but new backend can be built and work properly with
subset of them on 10.15 too.

Signed-off-by: Vladislav Yaroshchuk <[email protected]>
Message-Id: <[email protected]>
2022-03-17 17:36:38 +00:00
Paolo Bonzini cd85cb5abe ui/cocoa: run qemu_init in the main thread
Simplify the initialization dance by running qemu_init() in the main
thread before the Cocoa event loop starts.  The cocoa_display_init()
code that is post-applicationDidFinishLaunching: moves to the
application delegate itself, and the secondary thread only runs
the rest of qemu_main(), namely qemu_main_loop() and qemu_cleanup().

This fixes a case where addRemovableDevicesMenuItems() calls
qmp_query_block() while expecting the main thread to still hold
the BQL.  The newly-introduced assertions in the block layer
complain about this.

Signed-off-by: Paolo Bonzini <[email protected]>
Message-Id: <[email protected]>
[PMD: Fixed trivial build failures & rebased]
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2022-03-17 13:01:51 +00:00
Philippe Mathieu-Daudé c94e174af8 ui/cocoa: Code movement
Pure code movement in preparation for the next commit.

Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
2022-03-17 13:01:51 +00:00
osy 8f1617b581 pc: add option to disable PS/2 mouse/keyboard
On some older software like Windows 7 installer, having both a PS/2
mouse and USB mouse results in only one device working property (which
might be a different device each boot). While the workaround to not use
a USB mouse with such software is valid, it creates an inconsistent
experience if the user wishes to always use a USB mouse.

This introduces a new machine property to inhibit the creation of the
i8042 PS/2 controller.
2022-02-27 12:48:07 -08:00
osy fc43b65e06 rcu: do not register constructor thread if shared library
On iOS 15, the constructor can run on a new thread that is destroyed
after construction is finished in dyld. When this happens the TLS gets
freed and causes use-after-free when QEMU is built in shared library
mode. This moves the rcu_register_thread() call to qemu_init()
2022-02-25 23:57:19 -08:00
osy 6409730ff9 spice-display: reduce race in sending IOSurface
There is a kernel bug detailed in
https://github.com/utmapp/UTM/issues/2743#issuecomment-1047175257
which results in a race whenever IOSurfaceGetID/IOSurfaceLookup is used.
As a result, we need a way to "indicate" to the receiver that the
surface id in the pipe is now stale and should not be used. To do this
we send POLLHUP to poll() by closing the write FD when the surface is
about to be deallocated.

Note this does not fix the race completely as there is still a small
chance that the race happens between the close() and the CFRelease() but
the chance of that is small and the whole FD passing surface ID system
is a hack anyways that should be replaced with a proper set of SPICE
APIs one day...
2022-02-21 18:04:32 -08:00
osy cc24c9b7cb meson: build qemu-img as shared library 2022-01-10 15:35:44 -08:00
Alexander Graf 0d24c5332f HACK: hvf: arm: Always treat SMC as enabled conduit
The Windows 10 and 11 for ARM boot code implicitly assumes that SMC is a valid
SMCCC conduit to call for an OEM SMCCC call.

This patch forces HVF to treat SMC as an always active conduit, even when the
user has configured HVC. That way, the OEM SMCCC call gets handled as an
unimplemented SMCCC function (return -1) rather than an invalid conduit (inject
undefined instruction exception) which crashes Windows.

With this patch applied, I can successfully boot Windows for ARM Insider
Previews.

Signed-off-by: Alexander Graf <[email protected]>
2021-12-30 08:33:01 -08:00
osy 44cfb32e24 Merge tag 'v6.2.0' into utm-edition
v6.2.0 release
2021-12-29 11:44:40 -08:00
osy e73864e11d shaders: support byte swapping of pixels
Some EGL implementations do not support GL_BGRA_EXT so we always use
a surface format of GL_RGBA and then swap the bytes with a fragment
shader.
2021-09-08 20:03:21 -07:00
osy 2b73a7937d virtio-ramfb: break out GL supported device
This follows the same convention as other devices.
2021-09-07 01:36:59 -07:00
osy 753fffe1ea spice-display: support GL_TEXTURE_RECTANGLE_ANGLE
On macOS with CGL rendering backend, IOSurface only supports rectangle
texture targets. On iOS, EAGL, and Metal rendering backends IOSurface
only supports 2D texture targets.
2021-08-25 15:46:30 -07:00
osy e19e3cb9b5 Merge tag 'v6.1.0' into utm-edition
v6.1.0 release
2021-08-25 14:23:36 -07:00
osy 26324b7d94 Merge tag 'v6.1.0-rc4' into utm-edition
v6.1.0-rc4 release
2021-08-23 20:01:14 -07:00
osy 929b3859bd spice-display: send IOSurfaceID through pipe
This is still a hacky workaround to using mach ports but should support
different processes on macOS.
2021-08-08 12:18:33 -07:00
osy fdd3d1d3a0 virtio-ramfb: enable GL if supported 2021-08-08 12:18:33 -07:00
osy 345ec3279b tcti: fix build after latest TCG changes 2021-08-08 12:18:33 -07:00
osy e8f8220618 spice-display: fix crash in destroy texture with IOSurface 2021-08-02 11:27:44 -07:00
osy f275f433af Merge tag 'v6.1.0-rc1' into utm-edition
v6.1.0-rc1 release
2021-08-02 11:26:27 -07:00
osy f384e2c7eb spice-display: initial support for IOSurface rendering
In both surface and scanout mode, we blit the texture to a ANGLE texture
backed pbuffer using IOSurface. This IOSurface can be shared with a
separate process.

What needs to be done:
1) Handing of IOSurfaceRef through mach ports (Unix sockets are not
   supported. This implementation hacks in by passing the pointer through
   a file descriptor but this will fail if client is running in a separate
   process).
2) Cursor handling through QEMU (currently, the SPICE client will handle
   it).
2021-08-01 22:24:02 -07:00
osy dc386f9eb0 spice-display: support ANGLE backend
Add support for creating a pbuffer surface and setup from SPICE.
2021-08-01 22:22:14 -07:00
osy 1adb9ff17d spice-display: make GBM conditional 2021-08-01 22:17:23 -07:00
osy ce01739e6d egl-headless: fix compile without GBM 2021-08-01 22:13:51 -07:00
osy f357b925b3 egl-helpers: update EGL client version to 3.0
Required for Metal ANGLE to work on iOS
2021-08-01 22:13:11 -07:00
Akihiko Odaki edba23a4d4 egl-headless: Allow to test with Mesa on macOS
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-26 14:38:10 -07:00
osy 3428101c02 configure: disable plugins for shared_lib builds 2021-07-26 14:32:44 -07:00
osy 1e8db1949d file-posix: fix holepunch build on iOS 2021-07-26 14:32:28 -07:00
osy e91d59cbea Merge branch 'utm-edition-v6.0.0' into utm-edition-v6.1.0-rc0 2021-07-26 14:30:35 -07:00
osy eace1c8c9f Merge branch 'virgl-support' into utm-edition-v6.1.0-rc0 2021-07-25 19:11:11 -07:00
Akihiko Odaki c800dbb61e block/file-posix: Use O_RDWR for locking on macOS
qemu_lock_fd_test always returns 0 when fd is not open for writing and
exclusive is true on macOS 11.3.1.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:55:03 +09:00
Akihiko Odaki b3a305701e ui: update keycodemapdb submodule commit
The change of ui/keycodemapdb effective on QEMU is only commit
d21009b1c9f94b740ea66be8e48a1d8ad8124023, which adds mappings for key
codes added in commit d7696ff884.

d21009b1c9f94b740ea66be8e48a1d8ad8124023 Add QEMU QKeyCode "lang1" and "lang2"
320f92c36a80bfafc5d57834592a7be5fd79f104 rust: fix cargo clippy
e62d42f0fd76f7bb8bf78385a83c060e66ff52b0 tests: add rust test
3e25e1ca1772fc3f2039f739f8f920450dc68e50 gen: add --lang rust
9133a0b8022d1fb063a81cc2ba3b627c14ccdfd1 tests: fix argument order

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:59 +09:00
Akihiko Odaki 21954ae12a coreaudio: Commit the result of init in the end
init_out_device may only commit some part of the result and leave the
state inconsistent when it encounters an error. Commit the result in
the end of the function so that it commits the result iif it sees no
error.

With this change, handle_voice_change can rely on core->outputDeviceID
to know whether the output device is initialized after calling
init_out_device.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:51 +09:00
Akihiko Odaki 61f5befa07 virtio-gpu: Call Virgl only in the main thread
Virgl relies on callbacks provided by the OpenGL display, and such a
display may rely on eglMakeCurrent. eglMakeCurrent will fail if the
given context is current to some other thread. The easiest way to avoid
such a failure is to call the OpenGL display in a single thread. As all
operations except virtio_gpu_virgl_reset happens in the main thread,
this change makes virtio_gpu_virgl_reset happen only in the main thread.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:45 +09:00
Gustavo Noronha Silva 45c171c238 ui/cocoa: handle mouse grab properly on window being key changes
Being key is similar to being focused on other platforms. When the
window loses focus at the moment it will still keep the mouse grabbed
unless it is using an absolute pointing device like a USB tablet.

That may happen in several ways as Mac OS does not let Qemu handle some
of the events even when it has a grab. Command-Tab will switch applications
if full-grab is off, and even if it is on you can still switch away from
by using 3-finger gestures on the trackpad to change spaces or open
Mission Control, for instance.

That behaviour is not ideal, as even though Qemu still believes it is
getting all the events, Mac OS has effectively released the mouse.
And it is worse with full-grab turned on, as it will still capture
the key events, making you unable to use the keyboard on the Mac OS
environment.

This change makes Qemu properly release the grab when Mac OS effectively
does it. In addition, it properly automatically regrabs the mouse when
the window becomes key and is fullscreen. While it makes sense to wait
for a click on a non-fullscreen window, as the user may just be moving
the window around, for instance, when it's fullscreen there is no point.

Signed-off-by: Gustavo Noronha Silva <[email protected]>
2021-07-14 14:54:37 +09:00
Phillip Tennen 1b10cab21a net/macos: implement vmnet-based netdev
This patch implements a new netdev device, reachable via -netdev
vmnet-macos, that’s backed by macOS’s vmnet framework.

The vmnet framework provides native bridging support, and its usage in
this patch is intended as a replacement for attempts to use a tap device
via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
never would have worked in the first place, as QEMU interacts with the
tap device via poll(), and macOS does not support polling device files.

vmnet requires either a special entitlement, granted via a provisioning
profile, or root access. Otherwise attempts to create the virtual
interface will fail with a “generic error” status code. QEMU may not
currently be signed with an entitlement granted in a provisioning
profile, as this would necessitate pre-signed binary build distribution,
rather than source-code distribution. As such, using this netdev
currently requires that qemu be run with root access. I’ve opened a
feedback report with Apple to allow the use of the relevant entitlement
with this use case:
https://openradar.appspot.com/radar?id=5007417364447232

vmnet offers three operating modes, all of which are supported by this
patch via the “mode=host|shared|bridge” option:

* "Host" mode: Allows the vmnet interface to communicate with other
* vmnet
interfaces that are in host mode and also with the native host.
* "Shared" mode: Allows traffic originating from the vmnet interface to
reach the Internet through a NAT. The vmnet interface can also
communicate with the native host.
* "Bridged" mode: Bridges the vmnet interface with a physical network
interface.

Each of these modes also provide some extra configuration that’s
supported by this patch:

* "Bridged" mode: The user may specify the physical interface to bridge
with. Defaults to en0.
* "Host" mode / "Shared" mode: The user may specify the DHCP range and
subnet. Allocated by vmnet if not provided.

vmnet also offers some extra configuration options that are not
supported by this patch:

* Enable isolation from other VMs using vmnet
* Port forwarding rules
* Enabling TCP segmentation offload
* Only applicable in "shared" mode: specifying the NAT IPv6 prefix
* Only available in "host" mode: specifying the IP address for the VM
within an isolated network

Note that this patch requires macOS 10.15 as a minimum, as this is when
bridging support was implemented in vmnet.framework.

Rebased to commit 9aef095419 by Akihiko
Odaki.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
2021-07-14 14:54:30 +09:00
Akihiko Odaki c61c853e1f ui/cocoa: Divide ui/cocoa.m 2021-07-14 14:54:25 +09:00
Akihiko Odaki 8681835e66 ui/cocoa: Isolate fragments with preprocessor 2021-07-14 14:54:19 +09:00
Akihiko Odaki adaef950b5 ui/cocoa: Define types early 2021-07-14 14:54:14 +09:00
Akihiko Odaki a1cbf10708 ui/cocoa: Use qemu_input_map_osx_to_qcode
ui/cocoa used to have a conversion table from macOS keycode to QKeyCode.
It is an unnecessary redundancy as ui/input-keymap.c already has such a
table. Worse, I added an incorrect mapping of kVK_JIS_Eisu and
kVK_JIS_Kana with commit 708b72557f.
According to the following documentations, the definitions in
ui/keycodemapdb/keymaps.csv, which ui/input-keymap.c uses, are correct:
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang1?language=objc
https://developer.apple.com/documentation/uikit/uikeyboardhidusage/uikeyboardhidusagekeyboardlang2?language=objc
https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/keyboard-japan-ime

Use qemu_input_map_osx_to_qcode to eliminate the redundancy and
incorrect mappings.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:08 +09:00
Akihiko Odaki d0c0d66796 ui/cocoa: Do not raise keys before QEMU resigns active
ui/cocoa used to raise all keys before it resigns active to prevent a
stuck key problem caused by key up events it does not see while it is
inactive. The problem is solved by checking -[NSEvent modifierFlags] in
commit 6d73bb643a, which is better
because it handles the case that key *down* events are missed while it
is inactive.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:54:04 +09:00
Akihiko Odaki 920d2875a0 Use virgl_renderer_borrow_texture_for_scanout
virgl_renderer_borrow_texture_for_scanout is a replacement of
virgl_renderer_resource_get_info and performs configurations such as
swizzle and sRGB decode.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:59 +09:00
Akihiko Odaki 5ba17fba6e ui/cocoa: Update cursor
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:53 +09:00
Akihiko Odaki 51f8c2e5b8 ui/cocoa: Take refresh rate into account
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:48 +09:00
Akihiko Odaki 3184f37bbe Support Virgil 3D renderer on macOS
Virgil 3D renderer will be available with ui/cocoa on macOS.

The OpenGL backend is NSOpenGLContext for core profile, and
EGL (in particular, ANGLE) for ES profile.

As a notable change, CONFIG_OPENGL_DMABUF is replaced with the
combination of CONFIG_EGL and CONFIG_GBM. In fact, the old
detection of DMA-BUF in configure script was not working
because EGL_MESA_image_dma_buf_export is always defined in
<epoxy/egl.h>. Therefore, the new combination should
behave in the same way.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:43 +09:00
Akihiko Odaki 110dbe7e89 ui/spice: Use HAVE_SPICE_GL for OpenGL checks
Some code in ui/spice used CONFIG_OPENGL for OpenGL conditionals, but
SPICE also depends on CONFIG_GBM and SPICE server whose version is
0.13.1 or later for OpenGL. Always use HAVE_SPICE_GL, which defines the
precise condition.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:29 +09:00
Akihiko Odaki 2565eea22b ui/egl-headless: Remove a check for CONFIG_OPENGL
ui/egl-headless is only built when CONFIG_OPENGL is defined because it
depends on CONFIG_OPENGL without condition. Remove a redundant
conditonal in ui/egl-headless.c

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 14:53:17 +09:00
Akihiko Odaki 8c2f5eff66 virtio-gpu: Respect UI refresh rate for EDID
This change adds a new member, refresh_rate to QemuUIInfo in
include/ui/console.h. It represents the refresh rate of the
physical display backend, and it is more appropriate than
GUI update interval as the refresh rate which the emulated device
reports:
- sdl may set GUI update interval shorter than the refresh rate
  of the physical display to respond to user-generated events.
- sdl and vnc aggressively changes GUI update interval, but
  a guests is typically not designed to respond to frequent
  refresh rate changes, or frequent "display mode" changes in
  general. The frequency of refresh rate changes of the physical
  display backend matches better to the guest's expectation.

QemuUIInfo also has other members representing "display mode",
which makes it suitable for refresh rate representation. It has
a throttling of update notifications, and prevents frequent changes
of the display mode.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:46 +09:00
Akihiko Odaki db430377c0 ui/cocoa: Do not scale UI without "Zoom To Fit"
Cocoa scales UI for high-resolution display like Retina, but we do not
need it since we now have our own "Zoom To Fit" work well also for
windows, and the guest is aware of the resolution thanks to UI
information. This change reverts the scaling.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:30 +09:00
Akihiko Odaki b2708c4684 ui/cocoa: Use the standard about panel
This provides standard look and feel for the about panel and reduces
code.

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:23 +09:00
Akihiko Odaki 9ea8f7a804 ui/cocoa: Do not perform unsafe cast of argv
Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:15:10 +09:00
Akihiko Odaki 6a1e678f5b ui/cocoa: Use NSWindow's ability to resize
This change brings two new features:
- The window will be resizable if "Zoom To Fit" is eanbled
- The window can be made full screen by clicking full screen button
  provided by the platform. (The left-top green button.)

Signed-off-by: Akihiko Odaki <[email protected]>
2021-07-14 12:14:21 +09:00
Akihiko Odaki 902616b2f0 Merge tag 'patchew/[email protected]' 2021-07-14 12:02:33 +09:00
Gustavo Noronha Silva bc73e87997 ui/cocoa: add option to swap Option and Command
On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change
swaps them around so that Alt is the key closer to the space bar and Meta/Super
is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Acked-by: Markus Armbruster <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected]>
Signed-off-by: Gustavo Noronha Silva <[email protected]>
Message-Id: <[email protected]>
2021-07-13 23:00:52 +00:00
Gustavo Noronha Silva 7292f1fc18 ui/cocoa: capture all keys and combos when mouse is grabbed
Applications such as Gnome may use Alt-Tab and Super-Tab for different
purposes, some use Ctrl-arrows so we want to allow qemu to handle
everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows
at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the
mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Acked-by: Markus Armbruster <[email protected]>
Reviewed-by: Akihiko Odaki <[email protected]>
Signed-off-by: Gustavo Noronha Silva <[email protected]>
Message-Id: <[email protected]>
2021-07-13 23:00:52 +00:00
Yasuo Kuwahara 2ee6330b9e tcg/aarch64: Fix tcg_out_rotl
The last argument of tcg_out_extr() must be in the range 0-31 if ext==0.
Before the fix, when m==0 it becomes 32 and it crashes with an Illegal
instruction on Apple Silicon.  After the fix, it will be 0.  If m is in
the range 1-31, it is the same as before.

Signed-off-by: Yasuo Kuwahara <[email protected]>
Message-Id: <CAHfJ0vSXnmnTLmT0kR=a8ACRdw_UsLYOhStzUzgVEHoH8U-7sA@mail.gmail.com>
Signed-off-by: Richard Henderson <[email protected]>
2021-07-09 13:36:27 -07:00
Alexander Graf a0db5bfa90 hvf: arm: Handle Windows 10 SMC call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this patch applied I can successfully boot the current Windows 10
Insider Preview in HVF.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:14 +00:00
Alexander Graf 998320a3da arm: Enable Windows 10 trusted SMCCC boot call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this and -M virt,virtualization=on I can successfully boot the current
Windows 10 Insider Preview in TCG.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 8137225fde arm: Add Hypervisor.framework build target
Now that we have all logic in place that we need to handle Hypervisor.framework
on Apple Silicon systems, let's add CONFIG_HVF for aarch64 as well so that we
can build it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]> (x86 only)

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 3f09807e7f hvf: arm: Implement PSCI handling
We need to handle PSCI calls. Most of the TCG code works for us,
but we can simplify it to only handle aa64 mode and we need to
handle SUSPEND differently.

This patch takes the TCG code as template and duplicates it in HVF.

To tell the guest that we support PSCI 0.2 now, update the check in
arm_cpu_initfn() as well.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Alexander Graf 17d38dc6d9 hvf: arm: Implement -cpu host
Now that we have working system register sync, we push more target CPU
properties into the virtual machine. That might be useful in some
situations, but is not the typical case that users want.

So let's add a -cpu host option that allows them to explicitly pass all
CPU capabilities of their host CPU into the guest.

Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:13 +00:00
Peter Collingbourne 66c71d88ed arm/hvf: Add a WFI handler
Sleep on WFI until the VTIMER is due but allow ourselves to be woken
up on IPI.

In this implementation IPI is blocked on the CPU thread at startup and
pselect() is used to atomically unblock the signal and begin sleeping.
The signal is sent unconditionally so there's no need to worry about
races between actually sleeping and the "we think we're sleeping"
state. It may lead to an extra wakeup but that's better than missing
it entirely.

Signed-off-by: Peter Collingbourne <[email protected]>
[agraf: Remove unused 'set' variable, always advance PC on WFX trap]
Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 30adfa9b1d hvf: Add Apple Silicon support
With Apple Silicon available to the masses, it's a good time to add support
for driving its virtualization extensions from QEMU.

This patch adds all necessary architecture specific code to get basic VMs
working. It's still pretty raw, but definitely functional.

Known limitations:

  - Vtimer acknowledgement is hacky
  - Should implement more sysregs and fault on invalid ones then
  - WFI handling is missing, need to marry it with vtimer

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 3bf12f1f40 hvf: Simplify post reset/init/loadvm hooks
The hooks we have that call us after reset, init and loadvm really all
just want to say "The reference of all register state is in the QEMU
vcpu struct, please push it".

We already have a working pushing mechanism though called cpu->vcpu_dirty,
so we can just reuse that for all of the above, syncing state properly the
next time we actually execute a vCPU.

This fixes PSCI resets on ARM, as they modify CPU state even after the
post init call has completed, but before we execute the vCPU again.

To also make the scheme work for x86, we have to make sure we don't
move stale eflags into our env when the vcpu state is dirty.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 4c82b50085 hvf: Introduce hvf vcpu struct
We will need more than a single field for hvf going forward. To keep
the global vcpu struct uncluttered, let's allocate a special hvf vcpu
struct, similar to how hax does it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>

Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf f3b4506f14 hvf: Remove hvf-accel-ops.h
We can move the definition of hvf_vcpu_exec() into our internal
hvf header, obsoleting the need for hvf-accel-ops.h.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:12 +00:00
Alexander Graf 056bdd9a51 hvf: Make synchronize functions static
The hvf accel synchronize functions are only used as input for local
callback functions, so we can make them static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 0bc7389a8e hvf: Use cpu_synchronize_state()
There is no reason to call the hvf specific hvf_cpu_synchronize_state()
when we can just use the generic cpu_synchronize_state() instead. This
allows us to have less dependency on internal function definitions and
allows us to make hvf_cpu_synchronize_state() static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 9517f7e873 hvf: Split out common code on vcpu init and destroy
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch splits the vcpu init and destroy functions into a generic and
an architecture specific portion. This also allows us to move the generic
functions into the generic hvf code, removing exported functions.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf 30c2f78449 hvf: Remove use of hv_uvaddr_t and hv_gpaddr_t
The ARM version of Hypervisor.framework no longer defines these two
types, so let's just revert to standard ones.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:11 +00:00
Alexander Graf ea9f45cec5 hvf: Make hvf_set_phys_mem() static
The hvf_set_phys_mem() function is only called within the same file.
Make it static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf 82e6e2bdff hvf: Move hvf internal definitions into common header
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves a few internal struct and constant defines over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf ffb51175ba hvf: Move cpu functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves CPU and memory operations over. While at it, make sure
the code is consumable on non-i386 systems.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf a13fec6c17 hvf: Move vcpu thread functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves the vCPU thread loop over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:10 +00:00
Alexander Graf cf664b3a04 hvf: Move assert_hvf_ok() into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves assert_hvf_ok() and introduces generic build infrastructure.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-27 12:30:09 +00:00
John Arbuckle 5897229105 Implement the Screamer sound chip for the mac99 machine type
This patch enables the playback of audio on a Mac OS 9 or Mac OS X guest.

Signed-off-by: John Arbuckle <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:30:23 -07:00
osy d35954d3c9 tcti: mark gadgets static to reduce symbol size in shared library builds 2021-05-23 20:30:23 -07:00
Kate Temkin 64dcc3969b TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-05-23 20:30:23 -07:00
Phillip Tennen 06962e1aaa net/macos: implement vmnet-based netdev
This patch implements a new netdev device, reachable via -netdev
vmnet-macos, that’s backed by macOS’s vmnet framework.

The vmnet framework provides native bridging support, and its usage in
this patch is intended as a replacement for attempts to use a tap device
via the tuntaposx kernel extension. Notably, the tap/tuntaposx approach
never would have worked in the first place, as QEMU interacts with the
tap device via poll(), and macOS does not support polling device files.

vmnet requires either a special entitlement, granted via a provisioning
profile, or root access. Otherwise attempts to create the virtual
interface will fail with a “generic error” status code. QEMU may not
currently be signed with an entitlement granted in a provisioning
profile, as this would necessitate pre-signed binary build distribution,
rather than source-code distribution. As such, using this netdev
currently requires that qemu be run with root access. I’ve opened a
feedback report with Apple to allow the use of the relevant entitlement
with this use case:
https://openradar.appspot.com/radar?id=5007417364447232

vmnet offers three operating modes, all of which are supported by this
patch via the “mode=host|shared|bridge” option:

* "Host" mode: Allows the vmnet interface to communicate with other
* vmnet
interfaces that are in host mode and also with the native host.
* "Shared" mode: Allows traffic originating from the vmnet interface to
reach the Internet through a NAT. The vmnet interface can also
communicate with the native host.
* "Bridged" mode: Bridges the vmnet interface with a physical network
interface.

Each of these modes also provide some extra configuration that’s
supported by this patch:

* "Bridged" mode: The user may specify the physical interface to bridge
with. Defaults to en0.
* "Host" mode / "Shared" mode: The user may specify the DHCP range and
subnet. Allocated by vmnet if not provided.

vmnet also offers some extra configuration options that are not
supported by this patch:

* Enable isolation from other VMs using vmnet
* Port forwarding rules
* Enabling TCP segmentation offload
* Only applicable in "shared" mode: specifying the NAT IPv6 prefix
* Only available in "host" mode: specifying the IP address for the VM
within an isolated network

Note that this patch requires macOS 10.15 as a minimum, as this is when
bridging support was implemented in vmnet.framework.

Rebased to commit 571d413b5d by Akihiko
Odaki.

Signed-off-by: Phillip Tennen <[email protected]>
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:30:23 -07:00
osy ec151f4659 Merge branch 'hvf-aarch64-patch-v8' into utm-edition-v6.0.0 2021-05-23 20:28:47 -07:00
Alexander Graf 9d9ca24b72 hvf: arm: Handle Windows 10 SMC call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this patch applied I can successfully boot the current Windows 10
Insider Preview in HVF.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf fe1b754eab arm: Enable Windows 10 trusted SMCCC boot call
Windows 10 calls an SMCCC call via SMC unconditionally on boot. It lives
in the trusted application call number space, but its purpose is unknown.

In our current SMC implementation, we inject a UDEF for unknown SMC calls,
including this one. However, Windows breaks on boot when we do this. Instead,
let's return an error code.

With this and -M virt,virtualization=on I can successfully boot the current
Windows 10 Insider Preview in TCG.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 6d6e43ebce arm: Add Hypervisor.framework build target
Now that we have all logic in place that we need to handle Hypervisor.framework
on Apple Silicon systems, let's add CONFIG_HVF for aarch64 as well so that we
can build it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]> (x86 only)

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf f479e7eacd hvf: arm: Implement PSCI handling
We need to handle PSCI calls. Most of the TCG code works for us,
but we can simplify it to only handle aa64 mode and we need to
handle SUSPEND differently.

This patch takes the TCG code as template and duplicates it in HVF.

To tell the guest that we support PSCI 0.2 now, update the check in
arm_cpu_initfn() as well.

Signed-off-by: Alexander Graf <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf dbbbd13bf6 hvf: arm: Implement -cpu host
Now that we have working system register sync, we push more target CPU
properties into the virtual machine. That might be useful in some
situations, but is not the typical case that users want.

So let's add a -cpu host option that allows them to explicitly pass all
CPU capabilities of their host CPU into the guest.

Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Peter Collingbourne dc32fd2d89 arm/hvf: Add a WFI handler
Sleep on WFI until the VTIMER is due but allow ourselves to be woken
up on IPI.

In this implementation IPI is blocked on the CPU thread at startup and
pselect() is used to atomically unblock the signal and begin sleeping.
The signal is sent unconditionally so there's no need to worry about
races between actually sleeping and the "we think we're sleeping"
state. It may lead to an extra wakeup but that's better than missing
it entirely.

Signed-off-by: Peter Collingbourne <[email protected]>
[agraf: Remove unused 'set' variable, always advance PC on WFX trap]
Signed-off-by: Alexander Graf <[email protected]>
Acked-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 3354c800ac hvf: Add Apple Silicon support
With Apple Silicon available to the masses, it's a good time to add support
for driving its virtualization extensions from QEMU.

This patch adds all necessary architecture specific code to get basic VMs
working. It's still pretty raw, but definitely functional.

Known limitations:

  - Vtimer acknowledgement is hacky
  - Should implement more sysregs and fault on invalid ones then
  - WFI handling is missing, need to marry it with vtimer

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 365294d55a hvf: Simplify post reset/init/loadvm hooks
The hooks we have that call us after reset, init and loadvm really all
just want to say "The reference of all register state is in the QEMU
vcpu struct, please push it".

We already have a working pushing mechanism though called cpu->vcpu_dirty,
so we can just reuse that for all of the above, syncing state properly the
next time we actually execute a vCPU.

This fixes PSCI resets on ARM, as they modify CPU state even after the
post init call has completed, but before we execute the vCPU again.

To also make the scheme work for x86, we have to make sure we don't
move stale eflags into our env when the vcpu state is dirty.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf a6bff5ccc8 hvf: Introduce hvf vcpu struct
We will need more than a single field for hvf going forward. To keep
the global vcpu struct uncluttered, let's allocate a special hvf vcpu
struct, similar to how hax does it.

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Tested-by: Roman Bolshakov <[email protected]>
Reviewed-by: Alex Bennée <[email protected]>

Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf c803fc9d7d hvf: Remove hvf-accel-ops.h
We can move the definition of hvf_vcpu_exec() into our internal
hvf header, obsoleting the need for hvf-accel-ops.h.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 653cc15628 hvf: Make synchronize functions static
The hvf accel synchronize functions are only used as input for local
callback functions, so we can make them static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:29 -07:00
Alexander Graf 2e77c788d8 hvf: Use cpu_synchronize_state()
There is no reason to call the hvf specific hvf_cpu_synchronize_state()
when we can just use the generic cpu_synchronize_state() instead. This
allows us to have less dependency on internal function definitions and
allows us to make hvf_cpu_synchronize_state() static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 1534c4fe04 hvf: Split out common code on vcpu init and destroy
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch splits the vcpu init and destroy functions into a generic and
an architecture specific portion. This also allows us to move the generic
functions into the generic hvf code, removing exported functions.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 3a513c9db4 hvf: Remove use of hv_uvaddr_t and hv_gpaddr_t
The ARM version of Hypervisor.framework no longer defines these two
types, so let's just revert to standard ones.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf e27df17c9c hvf: Make hvf_set_phys_mem() static
The hvf_set_phys_mem() function is only called within the same file.
Make it static.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf aa7ebf9a77 hvf: Move hvf internal definitions into common header
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves a few internal struct and constant defines over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf be54898fd5 hvf: Move cpu functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves CPU and memory operations over. While at it, make sure
the code is consumable on non-i386 systems.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 7a64de81ce hvf: Move vcpu thread functions into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves the vCPU thread loop over.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Alexander Graf 71f21b796f hvf: Move assert_hvf_ok() into common directory
Until now, Hypervisor.framework has only been available on x86_64 systems.
With Apple Silicon shipping now, it extends its reach to aarch64. To
prepare for support for multiple architectures, let's start moving common
code out into its own accel directory.

This patch moves assert_hvf_ok() and introduces generic build infrastructure.

Signed-off-by: Alexander Graf <[email protected]>
Message-Id: <[email protected]>
2021-05-23 20:26:28 -07:00
Kate Temkin 13c9a7c820 TCTI: expand vector support to all ops 2021-05-06 16:58:56 -06:00
Kate Temkin 21ad741c1c TCTI: add initial vector instruction support 2021-05-06 08:53:59 -06:00
Kate Temkin 671b3cefcc TCTI: add remaining scalar ops 2021-05-04 08:02:19 -06:00
Kate Temkin 026956a474 TCTI: minor gadget optimizations 2021-05-04 06:19:41 -06:00
Kate Temkin 919856f02e Merge branch 'with_tcti_modular' into with_tcti 2021-04-30 11:44:01 -06:00
Kate Temkin cd4b5da233 TCTI: optimize I/O operation and helper call speeds 2021-04-30 11:40:17 -06:00
Joelle van Dyne 4e70afa94d coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-04-29 23:29:35 -07:00
osy 36195a781c tcg: custom APRR implementation 2021-04-29 23:29:35 -07:00
Marc-André Lureau 2541dde936 build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-29 23:29:35 -07:00
Marc-André Lureau ecc067a3ba slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-29 23:29:35 -07:00
Gerd Hoffmann 819b2c2984 hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-04-29 23:29:35 -07:00
osy 8ed0f7cb4d meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-04-29 23:29:35 -07:00
Joelle van Dyne d1bf1e28b6 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-04-29 23:29:35 -07:00
Joelle van DyneandWarner Losh 47cd50d3d2 block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-04-29 23:29:35 -07:00
Joelle van Dyne 324cef19f8 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-04-29 23:29:35 -07:00
Joelle van Dyne e252078b6e block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-04-29 23:29:35 -07:00
Kate Temkin 69c9fe3f2e TCTI: modularize things more for fast clang 2021-04-29 04:23:23 -06:00
Kate Temkin 6764fe306f TCTI: more modular hacks 2021-04-28 05:37:42 -06:00
Kate Temkin 744075b9ee TCTI: dramatically speed up build & reduce footprint 2021-04-28 03:29:08 +00:00
Kate Temkin c77bed1d5c split gadgets into multiple files 2021-04-27 13:47:14 -06:00
Kate Temkin 1e4d72b004 TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-04-27 13:21:48 -06:00
Kate Temkin 6c39f9e99b get building for an iOS target, as well 2021-04-27 13:21:47 -06:00
Joelle van Dyne ad73633ab3 coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-04-27 13:21:20 -06:00
osy a6b59f6dee tcg: custom APRR implementation 2021-04-27 13:21:20 -06:00
Roman Bolshakov 5db66c67b9 util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
There's a change in mprotect() behaviour [1] in the latest macOS on M1
and it's not yet clear if it's going to be fixed by Apple. For now we
can avoid unsupported mprotect() calls. QEMU and qtests work fine
without it.

1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
Apple-Feedback: FB8994773
Signed-off-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Marc-André Lureau c78951da1b build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Marc-André Lureau 138287176b slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-04-27 13:21:20 -06:00
Gerd Hoffmann 17ebce776d hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-04-27 13:21:20 -06:00
osy e034ab0b4d meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-04-27 13:21:20 -06:00
Joelle van Dyne d4e9108ef1 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-04-27 13:21:18 -06:00
Joelle van DyneandWarner Losh 36c2febd7f block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-04-27 13:20:46 -06:00
Joelle van Dyne 1913d4d2a7 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-04-27 13:20:46 -06:00
Joelle van Dyne 4f59dc2db0 block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-04-27 13:20:46 -06:00
Kate Temkin 4de86e6de1 TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64 2021-04-07 10:34:23 -06:00
Kate Temkin e16a18d2d9 get building for an iOS target, as well 2021-03-27 15:46:31 -06:00
Joelle van Dyne 4373fc4514 coroutine: add libucontext as external library
iOS does not support ucontext natively for aarch64 and the sigaltstack is
also unsupported (even worse, it fails silently, see:
https://openradar.appspot.com/13002712 )

As a workaround we include a library implementation of ucontext and add it
as a build option.
2021-03-08 17:28:49 -08:00
osy 37aa4a1894 tcg: custom APRR implementation 2021-03-08 17:28:49 -08:00
Roman Bolshakov cf8a85ad18 util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
There's a change in mprotect() behaviour [1] in the latest macOS on M1
and it's not yet clear if it's going to be fixed by Apple. For now we
can avoid unsupported mprotect() calls. QEMU and qtests work fine
without it.

1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
Apple-Feedback: FB8994773
Signed-off-by: Roman Bolshakov <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Marc-André Lureau da1d34255c build-sys: make libslirp a meson subproject
Remove the manual build.

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Marc-André Lureau ff51693eef slirp: update to git master
git cherry-diff:

Commits on bacb71f1c3ed5f40e393afd8be81bedfba13a401 branch that is not on 8f43a99191afb47ca3f3c6972f6306209f367ece branch
+ 1021b0dc38d39f1dc95a296fe3e05a24a087cdc6 disable_dns option
+ 0f94ceec752592e4ac632a24e3c64a97dd09bf4c limit vnameserver_addr to port 53
+ b57bafa852ef16b133907a13678ec69e9531f177 libslirp.h: fix SlirpConfig v3 documentation
+ 1abf18b2b5edb462797629ed47ad4515a195686e Update CHANGELOG
+ ff4ecf9b6c6542b24b4ac6ea178be9d44e159f79 Release v4.3.0
+ 21f1d933050a40d62612c6274c32de60b811d9ea changelog: post-release
+ 376187c4b14c795763d472214812826eebe7e9c2 Release v4.3.1
+ 73336e08902a7e826f7d960453df037380266186 changelog: post-release
+ 5c1c9d43be61571608e9b14615045b67b830daf5 udp, udp6, icmp: handle TTL value
+ 73ed49ab71998d4288e71e954ef6214b70f23d79 icmp, icmp6: Add icmp_forward_error and icmp6_forward_error
+ 7a4840a57ec7dbc37cca1ab96f058a9610b26950 udp, udp6, icmp, icmp6: Enable forwarding errors on Linux
+ e9b2bc19ae652a2907f247e621b2e4773bdd2aab TCPIPHDR_DELTA: Fix potential negative value
+ 39f9a363eec082f04513413046321abd04163148 .gitlab-ci: add a Coverity stage
+ 1b0093b973cfa0dc041522e5d4e6f576b2df642e sosendoob: better document what urgc is used for
+ 5b9ad89ebbb8afa50162c9156fabd5fc56291088 Add G_GNUC_PRINTF to local function slirp_vsnprintf
+ 8a808aa493980e212b4d5f5465330905c8294e59 meson: remove meson-dist script
+ 0b669b5fbe4d3c25a682a67f1059d8633c963b3d meson: support compiling as subproject
+ 9f82a47b81f2864422b82c1e40e51a2ed9c6ac32 Add DNS resolving for iOS
+ c0eac03e8ce1b9a743231f2fe21e7cb579fc9339 Remove the QEMU-special make build-system
+ 1bfd4d9368f9fa2e4f0731e1266bec05bbc83a80 socket: consume empty packets
+ 92413be68914f8cae2f5bad4bf3ab8491dcbc5d7 Release v4.4.0
+ 07e8cfac69766081871ab620d9f16a630543d302 changelog: post-release
+ 4c4e035813313d02b63fdeb920d56fb2fdc0a5b1 Remove some needless (void)casts
+ eee9db9d115d91aa82f33685c4e76d656db92976 fork_exec_child_setup: improve signal handling
+ 216f434a018b3af182a4f31bbe5a00daee170343 Fix unused variables

Signed-off-by: Marc-André Lureau <[email protected]>
Message-Id: <[email protected]>
2021-03-08 17:28:49 -08:00
Gerd Hoffmann 4ef61a5fd7 hw/display: add virtio-ramfb device
Like virtio-vga, but using ramfb instead of legacy vga.
Useful for booting from OVMF into Windows ARM which expects a linear FB.
2021-03-08 17:28:49 -08:00
osy bcdcc525e4 meson: option to build as shared library
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
2021-03-08 17:28:49 -08:00
Joelle van Dyne 69819144f1 slirp: feature detection for smbd
Replace Windows specific macro with a more generic feature detection
macro. Allows slirp smb feature to be disabled manually as well.
2021-03-08 16:24:07 -08:00
Joelle van DyneandWarner Losh f314014422 block: detect DKIOCGETBLOCKCOUNT/SIZE before use
iOS hosts do not have these defined so we fallback to the
default behaviour.

Co-authored-by: Warner Losh <[email protected]>
2021-03-07 18:42:43 -08:00
Joelle van Dyne e0a033d9d4 block: check for sys/disk.h
Some BSD platforms do not have this header.
2021-03-07 18:42:20 -08:00
Joelle van Dyne 0272e162b7 block: feature detection for host block support
On Darwin (iOS), there are no system level APIs for directly accessing
host block devices. We detect this at configure time.
2021-03-07 16:52:13 -08:00
145 changed files with 8004 additions and 735 deletions

No files matched your search

+24 -5
View File
@@ -58,12 +58,10 @@
#include "sysemu/hvf_int.h"
#include "sysemu/runstate.h"
#include "qemu/guest-random.h"
#include "hw/boards.h"
HVFState *hvf_state;
#ifdef __aarch64__
#define HV_VM_DEFAULT NULL
#endif
bool hvf_tso_mode = 0;
/* Memory slots */
@@ -324,7 +322,7 @@ static int hvf_accel_init(MachineState *ms)
hv_return_t ret;
HVFState *s;
ret = hv_vm_create(HV_VM_DEFAULT);
ret = hvf_arch_vm_create();
assert_hvf_ok(ret);
s = g_new0(HVFState, 1);
@@ -343,6 +341,20 @@ static int hvf_accel_init(MachineState *ms)
return hvf_arch_init();
}
#if defined(__aarch64__)
static bool hvf_get_tso(Object *obj, Error **errp)
{
return hvf_tso_mode;
}
static void hvf_set_tso(Object *obj, bool value, Error **errp)
{
hvf_tso_mode = value;
}
#endif
static inline int hvf_gdbstub_sstep_flags(void)
{
return SSTEP_ENABLE | SSTEP_NOIRQ;
@@ -355,6 +367,13 @@ static void hvf_accel_class_init(ObjectClass *oc, void *data)
ac->init_machine = hvf_accel_init;
ac->allowed = &hvf_allowed;
ac->gdbstub_supported_sstep_flags = hvf_gdbstub_sstep_flags;
#if defined(__aarch64__)
object_class_property_add_bool(oc, "tso",
hvf_get_tso, hvf_set_tso);
object_class_property_set_description(oc, "tso",
"Set on/off to enable/disable total store ordering mode");
#endif
}
static const TypeInfo hvf_accel_type = {
+1
View File
@@ -26,6 +26,7 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "qemu/atomic.h"
#include "qemu/rcu.h"
#include "exec/log.h"
+2 -1
View File
@@ -2882,7 +2882,8 @@ static void do_st16_mmu(CPUState *cpu, vaddr addr, Int128 val,
#include "atomic_template.h"
#endif
#if defined(CONFIG_ATOMIC128) || HAVE_CMPXCHG128
/* FIXME: this doesn't work in TCTI */
#if (defined(CONFIG_ATOMIC128) && !defined(CONFIG_TCG_THREADED_INTERPRETER)) || HAVE_CMPXCHG128
#define DATA_SIZE 16
#include "atomic_template.h"
#endif
+1
View File
@@ -28,6 +28,7 @@
#include "exec/translate-all.h"
#include "sysemu/tcg.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#include "tb-hash.h"
#include "tb-context.h"
#include "internal-common.h"
+5
View File
@@ -62,6 +62,11 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel)
cflags |= parallel ? CF_PARALLEL : 0;
cflags |= icount_enabled() ? CF_USE_ICOUNT : 0;
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
// GOTO_PTR is too complex to emit a simple gadget for.
// We'll let C handle it, since the overhead is similar.
cflags |= CF_NO_GOTO_PTR;
#endif
tcg_cflags_set(cpu, cflags);
}
+1
View File
@@ -23,6 +23,7 @@
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "tcg/tcg.h"
#include "tcg/tcg-apple-jit.h"
#if defined(CONFIG_USER_ONLY)
#include "qemu.h"
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+24 -6
View File
@@ -1407,12 +1407,21 @@ void audio_run(AudioState *s, const char *msg)
#endif
}
void audio_generic_initialize_buffer_in(HWVoiceIn *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
void audio_generic_run_buffer_in(HWVoiceIn *hw)
{
if (unlikely(!hw->buf_emul)) {
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
audio_generic_initialize_buffer_in(hw);
}
while (hw->pending_emul < hw->size_emul) {
@@ -1446,6 +1455,17 @@ void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
hw->pending_emul -= size;
}
void audio_generic_initialize_buffer_out(HWVoiceOut *hw)
{
if (hw->buf_emul) {
g_free(hw->buf_emul);
}
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
}
size_t audio_generic_buffer_get_free(HWVoiceOut *hw)
{
if (hw->buf_emul) {
@@ -1477,9 +1497,7 @@ void audio_generic_run_buffer_out(HWVoiceOut *hw)
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size)
{
if (unlikely(!hw->buf_emul)) {
hw->size_emul = hw->samples * hw->info.bytes_per_frame;
hw->buf_emul = g_malloc(hw->size_emul);
hw->pos_emul = hw->pending_emul = 0;
audio_generic_initialize_buffer_out(hw);
}
*size = MIN(hw->size_emul - hw->pending_emul,
+2
View File
@@ -187,9 +187,11 @@ struct audio_pcm_ops {
void (*volume_in)(HWVoiceIn *hw, Volume *vol);
};
void audio_generic_initialize_buffer_in(HWVoiceIn *hw);
void audio_generic_run_buffer_in(HWVoiceIn *hw);
void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
void audio_generic_initialize_buffer_out(HWVoiceOut *hw);
void audio_generic_run_buffer_out(HWVoiceOut *hw);
size_t audio_generic_buffer_get_free(HWVoiceOut *hw);
void *audio_generic_get_buffer_out(HWVoiceOut *hw, size_t *size);
+28 -22
View File
@@ -355,7 +355,10 @@ static OSStatus audioDeviceIOProc(
static OSStatus init_out_device(coreaudioVoiceOut *core)
{
OSStatus status;
AudioDeviceID deviceID;
AudioValueRange frameRange;
UInt32 audioDevicePropertyBufferFrameSize;
AudioDeviceIOProcID ioprocid;
AudioStreamBasicDescription streamBasicDescription = {
.mBitsPerChannel = core->hw.info.bits,
@@ -368,20 +371,19 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
.mSampleRate = core->hw.info.freq
};
status = coreaudio_get_voice(&core->outputDeviceID);
status = coreaudio_get_voice(&deviceID);
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not get default output Device\n");
return status;
}
if (core->outputDeviceID == kAudioDeviceUnknown) {
if (deviceID == kAudioDeviceUnknown) {
dolog ("Could not initialize playback - Unknown Audiodevice\n");
return status;
}
/* get minimum and maximum buffer frame sizes */
status = coreaudio_get_framesizerange(core->outputDeviceID,
&frameRange);
status = coreaudio_get_framesizerange(deviceID, &frameRange);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -392,31 +394,31 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
}
if (frameRange.mMinimum > core->frameSizeSetting) {
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
} else if (frameRange.mMaximum < core->frameSizeSetting) {
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
} else {
core->audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
audioDevicePropertyBufferFrameSize = core->frameSizeSetting;
}
/* set Buffer Frame Size */
status = coreaudio_set_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
status = coreaudio_set_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
if (status != kAudioHardwareNoError) {
coreaudio_playback_logerr (status,
"Could not set device buffer frame size %" PRIu32 "\n",
(uint32_t)core->audioDevicePropertyBufferFrameSize);
(uint32_t)audioDevicePropertyBufferFrameSize);
return status;
}
/* get Buffer Frame Size */
status = coreaudio_get_framesize(core->outputDeviceID,
&core->audioDevicePropertyBufferFrameSize);
status = coreaudio_get_framesize(deviceID,
&audioDevicePropertyBufferFrameSize);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -425,11 +427,9 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
"Could not get device buffer frame size\n");
return status;
}
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
/* set Samplerate */
status = coreaudio_set_streamformat(core->outputDeviceID,
&streamBasicDescription);
status = coreaudio_set_streamformat(deviceID, &streamBasicDescription);
if (status == kAudioHardwareBadObjectError) {
return 0;
}
@@ -437,7 +437,6 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
coreaudio_playback_logerr (status,
"Could not set samplerate %lf\n",
streamBasicDescription.mSampleRate);
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
@@ -451,20 +450,25 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
* Therefore, the specified callback must be designed to avoid a deadlock
* with the callers of AudioObjectGetPropertyData.
*/
core->ioprocid = NULL;
status = AudioDeviceCreateIOProcID(core->outputDeviceID,
ioprocid = NULL;
status = AudioDeviceCreateIOProcID(deviceID,
audioDeviceIOProc,
&core->hw,
&core->ioprocid);
&ioprocid);
if (status == kAudioHardwareBadDeviceError) {
return 0;
}
if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
if (status != kAudioHardwareNoError || ioprocid == NULL) {
coreaudio_playback_logerr (status, "Could not set IOProc\n");
core->outputDeviceID = kAudioDeviceUnknown;
return status;
}
core->outputDeviceID = deviceID;
core->audioDevicePropertyBufferFrameSize = audioDevicePropertyBufferFrameSize;
core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
audio_generic_initialize_buffer_out(&core->hw);
core->ioprocid = ioprocid;
return 0;
}
@@ -548,7 +552,9 @@ static OSStatus handle_voice_change(
fini_out_device(core);
}
if (!init_out_device(core)) {
init_out_device(core);
if (core->outputDeviceID) {
update_device_playback_state(core);
}
+23 -2
View File
@@ -44,10 +44,10 @@
#if defined(__APPLE__) && (__MACH__)
#include <sys/ioctl.h>
#if defined(HAVE_HOST_BLOCK_DEVICE)
#include <paths.h>
#include <sys/param.h>
#include <sys/mount.h>
#if defined(HAVE_HOST_BLOCK_DEVICE)
#include <paths.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOBSD.h>
#include <IOKit/storage/IOMediaBSDClient.h>
@@ -284,6 +284,13 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
}
#endif
#if defined(CONFIG_IOS)
static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
{
return -ENOTSUP; /* not supported on iOS */
}
#else /* CONFIG_IOS */
/*
* Get logical block size via ioctl. On success store it in @sector_size_p.
*/
@@ -317,6 +324,8 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
return success ? 0 : -errno;
}
#endif
/**
* Get physical block size of @fd.
* On success, store it in @blk_size and return 0.
@@ -1657,12 +1666,24 @@ static bool preadv_present = true;
static ssize_t
qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
{
#ifdef CONFIG_DARWIN /* preadv introduced in macOS 11 */
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
preadv_present = false;
return -ENOSYS;
} else
#endif
return preadv(fd, iov, nr_iov, offset);
}
static ssize_t
qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
{
#ifdef CONFIG_DARWIN /* pwritev introduced in macOS 11 */
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
preadv_present = false;
return -ENOSYS;
} else
#endif
return pwritev(fd, iov, nr_iov, offset);
}
+2 -2
View File
@@ -334,7 +334,7 @@ virgl_get_resource_info_modifiers(uint32_t resource_id,
*info = info_ext.base;
*modifiers = info_ext.modifiers;
#else
ret = virgl_renderer_resource_get_info(resource_id, info);
ret = virgl_renderer_borrow_texture_for_scanout(resource_id, info);
if (ret) {
return ret;
}
@@ -354,7 +354,7 @@ virgl_cmd_set_scanout(VuGpu *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
struct virgl_renderer_resource_info info;
struct virgl_renderer_texture_info info;
int ret;
VUGPU_FILL_CMD(ss);
+2
View File
@@ -47,6 +47,8 @@ operating system.
QEMU files related to TPM CRB interface:
- ``hw/tpm/tpm_crb.c``
- ``hw/tpm/tpm_crb_common.c``
- ``hw/tpm/tpm_crb_sysbus.c``
SPAPR interface
---------------
+2 -1
View File
@@ -11,7 +11,8 @@
#ifndef HOST_ATOMIC128_CAS_H
#define HOST_ATOMIC128_CAS_H
#if defined(CONFIG_ATOMIC128)
/* FIXME: this doesn't work in TCTI */
#if defined(CONFIG_ATOMIC128) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
static inline Int128 ATTRIBUTE_ATOMIC128_OPT
atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
{
+6 -1
View File
@@ -31,6 +31,7 @@
#include "hw/pci/pci_bus.h"
#include "hw/pci/pci_bridge.h"
#include "qemu/cutils.h"
#include "qom/object.h"
static GArray *build_alloc_array(void)
{
@@ -2271,7 +2272,7 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
{
uint8_t start_method_params[12] = {};
unsigned log_addr_offset;
uint64_t control_area_start_address;
uint64_t baseaddr, control_area_start_address;
TPMIf *tpmif = tpm_find();
uint32_t start_method;
AcpiTable table = { .sig = "TPM2", .rev = 4,
@@ -2289,6 +2290,10 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
} else if (TPM_IS_CRB(tpmif)) {
control_area_start_address = TPM_CRB_ADDR_CTRL;
start_method = TPM2_START_METHOD_CRB;
} else if (TPM_IS_CRB_SYSBUS(tpmif)) {
baseaddr = object_property_get_uint(OBJECT(tpmif), "x-baseaddr", NULL);
control_area_start_address = baseaddr + A_CRB_CTRL_REQ;
start_method = TPM2_START_METHOD_CRB;
} else {
g_assert_not_reached();
}
+1
View File
@@ -7,6 +7,7 @@ config ARM_VIRT
imply VFIO_AMD_XGBE
imply VFIO_PLATFORM
imply VFIO_XGMAC
imply TPM_CRB_SYSBUS
imply TPM_TIS_SYSBUS
imply TPM_TIS_I2C
imply NVDIMM
+2 -36
View File
@@ -34,6 +34,7 @@
#include "hw/core/cpu.h"
#include "hw/acpi/acpi-defs.h"
#include "hw/acpi/acpi.h"
#include "hw/acpi/acpi_aml_interface.h"
#include "hw/nvram/fw_cfg_acpi.h"
#include "hw/acpi/bios-linker-loader.h"
#include "hw/acpi/aml-build.h"
@@ -169,41 +170,6 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,
aml_append(scope, dev);
}
#ifdef CONFIG_TPM
static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
{
PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
MemoryRegion *sbdev_mr;
hwaddr tpm_base;
if (!sbdev) {
return;
}
tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
assert(tpm_base != -1);
tpm_base += pbus_base;
sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
Aml *dev = aml_device("TPM0");
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
Aml *crs = aml_resource_template();
aml_append(crs,
aml_memory32_fixed(tpm_base,
(uint32_t)memory_region_size(sbdev_mr),
AML_READ_WRITE));
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(scope, dev);
}
#endif
#define ID_MAPPING_ENTRY_SIZE 20
#define SMMU_V3_ENTRY_SIZE 68
#define ROOT_COMPLEX_ENTRY_SIZE 36
@@ -859,7 +825,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
acpi_dsdt_add_power_button(scope);
#ifdef CONFIG_TPM
acpi_dsdt_add_tpm(scope, vms);
call_dev_aml_func(DEVICE(tpm_find()), scope);
#endif
aml_append(dsdt, scope);
+12
View File
@@ -1849,7 +1849,11 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
* irrespective of the underlying capabilities of the HW.
*/
if (!vms->highmem) {
#ifdef CONFIG_DARWIN
pa_bits = 36;
#else
pa_bits = 32;
#endif
}
/*
@@ -2907,6 +2911,13 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
vms->virtio_iommu_bdf = pci_get_bdf(pdev);
create_virtio_iommu_dt_bindings(vms);
}
#ifdef CONFIG_TPM
if (object_dynamic_cast(OBJECT(dev), TYPE_TPM_IF)) {
tpm_sysbus_plug(TPM_IF(dev), OBJECT(vms->platform_bus_dev),
vms->memmap[VIRT_PLATFORM_BUS].base);
}
#endif
}
static void virt_dimm_unplug_request(HotplugHandler *hotplug_dev,
@@ -3070,6 +3081,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM);
#ifdef CONFIG_TPM
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_CRB_SYSBUS);
#endif
mc->block_default_type = IF_VIRTIO;
mc->no_cdrom = 1;
+6
View File
@@ -55,3 +55,9 @@ config VIRTIO_SND
bool
default y
depends on VIRTIO
config MARVELL_88W8618
bool
config SCREAMER
bool
+1
View File
@@ -11,6 +11,7 @@ system_ss.add(when: 'CONFIG_MARVELL_88W8618', if_true: files('marvell_88w8618.c'
system_ss.add(when: 'CONFIG_PCSPK', if_true: files('pcspk.c'))
system_ss.add(when: 'CONFIG_PL041', if_true: files('pl041.c', 'lm4549.c'))
system_ss.add(when: 'CONFIG_SB16', if_true: files('sb16.c'))
system_ss.add(when: 'CONFIG_SCREAMER', if_true: files('screamer.c'))
system_ss.add(when: 'CONFIG_VT82C686', if_true: files('via-ac97.c'))
system_ss.add(when: 'CONFIG_WM8750', if_true: files('wm8750.c'))
system_ss.add(when: ['CONFIG_VIRTIO_SND', 'CONFIG_VIRTIO'], if_true: files('virtio-snd.c'))
+480
View File
@@ -0,0 +1,480 @@
/*
* QEMU PowerMac Awacs Screamer device support
*
* Copyright (c) 2016 Mark Cave-Ayland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
#include "audio/audio.h"
#include "hw/hw.h"
#include "hw/irq.h"
#include "audio/audio.h"
#include "hw/audio/screamer.h"
#include "hw/qdev-properties.h"
#include "qemu/timer.h"
#include "hw/ppc/mac_dbdma.h"
#include "sysemu/sysemu.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
#include "qemu/typedefs.h"
/* debug screamer */
//#define DEBUG_SCREAMER
#ifdef DEBUG_SCREAMER
#define SCREAMER_DPRINTF(fmt, ...) \
do { printf("SCREAMER: " fmt , ## __VA_ARGS__); } while (0)
#else
#define SCREAMER_DPRINTF(fmt, ...)
#endif
/* chip registers */
#define SND_CTRL_REG 0x0
#define CODEC_CTRL_REG 0x1
#define CODEC_STAT_REG 0x2
#define CLIP_CNT_REG 0x3
#define BYTE_SWAP_REG 0x4
#define FRAME_CNT_REG 0x5
#define CODEC_CTRL_MASKECMD (0x1 << 24)
#define CODEC_CTRL1_RECALIBRATE 0x4
#define CODEC_STAT_MANUFACTURER_CRYSTAL 0x100
#define CODEC_STAT_AWACS_REVISION 0x3000
#define CODEC_STAT_MASK_VALID (0x1 << 22)
/* Audio */
static const char *s_spk = "screamer";
static void pmac_screamer_tx_transfer(ScreamerState *s)
{
DBDMA_io *io = &s->io;
int samples;
samples = MIN(io->len >> s->shift, s->samples - s->wpos);
dma_memory_read(&address_space_memory, io->addr,
&s->mixbuf[s->wpos << s->shift], samples << s->shift,
MEMTXATTRS_UNSPECIFIED);
SCREAMER_DPRINTF("DMA actually transferred 0x%x, wpos is %d\n", samples << s->shift, s->wpos);
io->addr += (samples << s->shift);
io->len -= (samples << s->shift);
s->wpos += samples;
/* Continue DBDMA if we have completed the transfer, otherwise defer */
if (io->len == 0) {
SCREAMER_DPRINTF("-> End of transfer\n");
io->dma_end(io);
}
}
static void pmac_screamer_tx(DBDMA_io *io)
{
ScreamerState *s = io->opaque;
SCREAMER_DPRINTF("DMA TX transfer: addr %" HWADDR_PRIx
" len: %x\n", io->addr, io->len);
memcpy(&s->io, io, sizeof(DBDMA_io));
//if (s->wpos + (s->io.len >> s->shift) > s->samples) {
// return;
//}
pmac_screamer_tx_transfer(s);
}
static void pmac_screamer_tx_flush(DBDMA_io *io)
{
DBDMA_channel *ch = io->channel;
dbdma_cmd *current = &ch->current;
uint16_t cmd;
SCREAMER_DPRINTF("DMA TX flush!\n");
#if 0
cmd = le16_to_cpu(current->command) & COMMAND_MASK;
if (cmd == OUTPUT_MORE || cmd == OUTPUT_LAST ||
cmd == INPUT_MORE || cmd == INPUT_LAST) {
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
current->res_count = cpu_to_le16(io->len);
dma_memory_write(&address_space_memory, ch->regs[DBDMA_CMDPTR_LO],
&ch->current, sizeof(dbdma_cmd),
MEMTXATTRS_UNSPECIFIED);
}
#endif
ch->io.processing = false;
cmd = le16_to_cpu(current->command) & COMMAND_MASK;
if (cmd == INPUT_MORE || cmd == INPUT_LAST) {
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
current->res_count = cpu_to_le16(io->len);
dma_memory_write(&address_space_memory, ch->regs[DBDMA_CMDPTR_LO],
&ch->current, sizeof(dbdma_cmd),
MEMTXATTRS_UNSPECIFIED);
}
}
static void pmac_screamer_rx(DBDMA_io *io)
{
SCREAMER_DPRINTF("DMA RX transfer: addr %" HWADDR_PRIx
" len: %x\n", io->addr, io->len);
//ScreamerState *s = io->opaque;
DBDMA_channel *ch = io->channel;
/* FIXME: stop channel after updating with status to stop MacOS 9 freezing */
ch->regs[DBDMA_STATUS] &= ~RUN;
io->dma_end(io);
}
static void pmac_screamer_rx_flush(DBDMA_io *io)
{
DBDMA_channel *ch = io->channel;
dbdma_cmd *current = &ch->current;
uint16_t cmd;
SCREAMER_DPRINTF("DMA RX flush!\n");
#if 1
cmd = le16_to_cpu(current->command) & COMMAND_MASK;
if (cmd == INPUT_MORE || cmd == INPUT_LAST) {
current->xfer_status = cpu_to_le16(ch->regs[DBDMA_STATUS]);
current->res_count = cpu_to_le16(io->len);
dma_memory_write(&address_space_memory, ch->regs[DBDMA_CMDPTR_LO],
&ch->current, sizeof(dbdma_cmd),
MEMTXATTRS_UNSPECIFIED);
}
#endif
}
void macio_screamer_register_dma(ScreamerState *s, void *dbdma, int txchannel, int rxchannel)
{
s->dbdma = dbdma;
DBDMA_register_channel(dbdma, txchannel, s->dma_tx_irq,
pmac_screamer_tx, pmac_screamer_tx_flush, s);
DBDMA_register_channel(dbdma, rxchannel, s->dma_rx_irq,
pmac_screamer_rx, pmac_screamer_rx_flush, s);
}
static void screamerspk_callback(void *opaque, int free_b)
{
ScreamerState *s = opaque;
DBDMA_io *io = &s->io;
int samples, generated;
if (free_b == 0) {
return;
}
if (s->wpos - s->rpos == 0) {
return;
}
samples = MIN(s->samples, free_b >> s->shift);
generated = MIN(samples, s->wpos - s->rpos);
AUD_write(s->voice, s->mixbuf + (uintptr_t)(s->rpos << s->shift),
generated << s->shift);
SCREAMER_DPRINTF(" - generated %d, wpos %d, rpos %d\n", generated, s->wpos, s->rpos);
s->regs[FRAME_CNT_REG] += generated;
s->rpos += generated;
if (s->rpos < s->wpos) {
return;
}
s->wpos = 0;
s->rpos = 0;
if (io->len) {
DBDMA_channel *ch = io->channel;
uint32_t status = ch->regs[DBDMA_STATUS];
SCREAMER_DPRINTF("Continue deferred transfer\n");
/* Disable channel so we only complete the current transfer */
ch->regs[DBDMA_STATUS] &= ~RUN;
/* Perform deferred transfer */
pmac_screamer_tx_transfer(s);
/* Re-enable channel */
ch->regs[DBDMA_STATUS] = status;
/* Kick channel to continue */
DBDMA_kick(container_of(ch, DBDMAState, channels[ch->channel]));
}
}
static void screamer_update_settings(ScreamerState *s)
{
struct audsettings as = { s->rate, 2, AUDIO_FORMAT_S16,
1 };
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, screamerspk_callback, &as);
if (!s->voice) {
AUD_log(s_spk, "Could not open voice\n");
return;
}
s->shift = 2;
s->samples = AUD_get_buffer_size_out(s->voice) >> s->shift;
s->mixbuf = g_malloc0(s->samples << s->shift);
AUD_set_active_out(s->voice, true);
}
static void screamer_update_volume(ScreamerState *s)
{
uint8_t muted = s->codec_ctrl_regs[0x1] & 0x80 ? 1 : 0;
uint8_t att_left = (s->codec_ctrl_regs[0x4] & 0xf);
uint8_t att_right = (s->codec_ctrl_regs[0x4] & 0x3c0) >> 6;
SCREAMER_DPRINTF("setting mute: %d, attenuation L: %d R: %d\n",
muted, att_left, att_right);
AUD_set_volume_out(s->voice, muted, (0xf - att_left) << 4,
(0xf - att_right) << 4);
}
static void screamer_reset(DeviceState *dev)
{
ScreamerState *s = SCREAMER(dev);
memset(s->regs, 0, sizeof(s->regs));
memset(s->codec_ctrl_regs, 0, sizeof(s->codec_ctrl_regs));
memset(&s->io, 0, sizeof(DBDMA_io));
s->rate = 44100;
screamer_update_settings(s);
s->bpos = 0;
s->ppos = 0;
return;
}
static void screamer_realizefn(DeviceState *dev, Error **errp)
{
ScreamerState *s = SCREAMER(dev);
if (!AUD_register_card(s_spk, &s->card, errp)) {
return;
}
s->rate = 44100;
screamer_update_settings(s);
}
static void screamer_control_write(ScreamerState *s, uint32_t val)
{
SCREAMER_DPRINTF("%s: val %" PRId32 "\n", __func__, val);
/* Basic rate selection */
switch ((val & 0x700) >> 8) {
case 0x00:
s->rate = 44100;
break;
case 0x1:
s->rate = 29400;
break;
case 0x2:
s->rate = 22050;
break;
case 0x3:
s->rate = 17640;
break;
case 0x4:
s->rate = 14700;
break;
case 0x5:
s->rate = 11025;
break;
case 0x6:
s->rate = 8820;
break;
case 0x7:
s->rate = 7350;
break;
}
SCREAMER_DPRINTF("basic rate: %d\n", s->rate);
screamer_update_settings(s);
s->regs[0] = val;
}
static void screamer_codec_write(ScreamerState *s, hwaddr addr, uint64_t val)
{
//SCREAMER_DPRINTF("%s: addr " HWADDR_PRIx " val %" PRIx64 "\n", __func__, addr, val);
switch (addr) {
case 0x1:
/* Clear recalibrate if set */
val = val & ~CODEC_CTRL1_RECALIBRATE;
/* Update volume in case mute set */
screamer_update_volume(s);
break;
case 0x4:
/* Speaker attenuation */
screamer_update_volume(s);
break;
}
s->codec_ctrl_regs[addr] = val;
}
static uint64_t screamer_read(void *opaque, hwaddr addr, unsigned size)
{
ScreamerState *s = opaque;
uint32_t val;
addr = addr >> 4;
switch (addr) {
case SND_CTRL_REG:
val = s->regs[addr];
break;
case CODEC_CTRL_REG:
val = s->regs[addr] & ~CODEC_CTRL_MASKECMD;
break;
case CODEC_STAT_REG:
if (s->codec_ctrl_regs[7] & 1) {
/* Read back mode */
val = s->codec_ctrl_regs[(s->codec_ctrl_regs[7] >> 1) & 0xe];
} else {
/* Return status register */
val = s->regs[addr] & ~0xff00;
val |= CODEC_STAT_MANUFACTURER_CRYSTAL | CODEC_STAT_AWACS_REVISION |
CODEC_STAT_MASK_VALID;
}
break;
case CLIP_CNT_REG:
case BYTE_SWAP_REG:
case FRAME_CNT_REG:
val = s->regs[addr];
break;
default:
qemu_log_mask(LOG_UNIMP,
"screamer: Unimplemented register read "
"reg 0x%" HWADDR_PRIx " size 0x%x\n",
addr, size);
val = 0;
break;
}
SCREAMER_DPRINTF("%s: addr " HWADDR_FMT_plx " -> %x\n", __func__, addr, val);
return val;
}
static void screamer_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
ScreamerState *s = opaque;
uint32_t codec_addr;
addr = addr >> 4;
SCREAMER_DPRINTF("%s: addr " HWADDR_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
switch (addr) {
case SND_CTRL_REG:
screamer_control_write(s, val & 0xffffffff);
break;
case CODEC_CTRL_REG:
s->regs[addr] = val & 0xffffffff;
codec_addr = (val & 0x7fff) >> 12;
screamer_codec_write(s, codec_addr, val & 0xfff);
break;
case CODEC_STAT_REG:
case CLIP_CNT_REG:
case BYTE_SWAP_REG:
s->regs[addr] = val & 0xffffffff;
break;
default:
qemu_log_mask(LOG_UNIMP,
"screamer: Unimplemented register write "
"reg 0x%" HWADDR_PRIx " size 0x%x value 0x%" PRIx64 "\n",
addr, size, val);
break;
}
return;
}
static const MemoryRegionOps screamer_ops = {
.read = screamer_read,
.write = screamer_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 4,
.max_access_size = 4,
}
};
static void screamer_initfn(Object *obj)
{
SysBusDevice *d = SYS_BUS_DEVICE(obj);
ScreamerState *s = SCREAMER(obj);
memory_region_init_io(&s->mem, obj, &screamer_ops, s, "screamer", 0x1000);
sysbus_init_mmio(d, &s->mem);
sysbus_init_irq(d, &s->irq);
sysbus_init_irq(d, &s->dma_tx_irq);
sysbus_init_irq(d, &s->dma_rx_irq);
}
static Property screamer_properties[] = {
DEFINE_AUDIO_PROPERTIES(ScreamerState, card),
DEFINE_PROP_END_OF_LIST()
};
static void screamer_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
dc->realize = screamer_realizefn;
dc->reset = screamer_reset;
device_class_set_props(dc, screamer_properties);
}
static const TypeInfo screamer_type_info = {
.name = TYPE_SCREAMER,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(ScreamerState),
.instance_init = screamer_initfn,
.class_init = screamer_class_init,
};
static void screamer_register_types(void)
{
type_register_static(&screamer_type_info);
}
type_init(screamer_register_types)
+1
View File
@@ -74,6 +74,7 @@ GlobalProperty hw_compat_7_2[] = {
{ "virtio-mem", "x-early-migration", "false" },
{ "migration", "x-preempt-pre-7-2", "true" },
{ TYPE_PCI_DEVICE, "x-pcie-err-unc-mask", "off" },
{ "arm-gicv3-its", "itt-entry-size", "12" },
};
const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
+1
View File
@@ -493,6 +493,7 @@ static const BindingEntry bindings[] = {
#endif
#ifdef CONFIG_TPM
TYPE_BINDING(TYPE_TPM_TIS_SYSBUS, add_tpm_tis_fdt_node),
TYPE_BINDING(TYPE_TPM_CRB_SYSBUS, add_tpm_tis_fdt_node),
#endif
TYPE_BINDING(TYPE_RAMFB_DEVICE, no_fdt_node),
TYPE_BINDING("", NULL), /* last element */
+10
View File
@@ -93,6 +93,16 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
endif
endif
if config_all_devices.has_key('CONFIG_FW_CFG_DMA')
virtio_ramfb_ss = ss.source_set()
virtio_ramfb_ss.add(when: 'CONFIG_FW_CFG_DMA', if_true: files('virtio-ramfb.c'))
hw_display_modules += {'virtio-ramfb': virtio_ramfb_ss}
virtio_ramfb_gl_ss = ss.source_set()
virtio_ramfb_gl_ss.add(when: ['CONFIG_FW_CFG_DMA', virgl, opengl],
if_true: files('virtio-ramfb-gl.c'))
hw_display_modules += {'virtio-ramfb-gl': virtio_ramfb_gl_ss}
endif
if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
virtio_gpu_pci_ss = ss.source_set()
virtio_gpu_pci_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI'],
+82 -23
View File
@@ -149,11 +149,87 @@ static void virgl_cmd_resource_flush(VirtIOGPU *g,
}
}
static GLuint virgl_borrow_texture_for_scanout(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height,
void **d3d_tex2d)
{
struct virgl_renderer_texture_info info;
int ret;
memset(&info, 0, sizeof(info));
ret = virgl_renderer_borrow_texture_for_scanout(id, &info);
if (ret == -1) {
return 0;
}
if (y_0_top) {
*y_0_top = info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
}
if (width) {
*width = info.width;
}
if (height) {
*height = info.height;
}
if (d3d_tex2d) {
*d3d_tex2d = NULL;
}
return info.tex_id;
}
#ifdef HAVE_VIRGL_D3D_INFO_EXT
static GLuint virgl_borrow_d3d_info_for_scanout(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height,
void **d3d_tex2d)
{
int ret;
struct virgl_renderer_resource_info info;
struct virgl_renderer_resource_info_ext ext;
void *d3d_tex2d = NULL;
memset(&ext, 0, sizeof(ext));
ret = virgl_renderer_resource_get_info_ext(id, &ext);
info = ext.base;
d3d_tex2d = ext.d3d_tex2d;
if (ret) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: illegal resource specified %d\n",
__func__, id);
return 0;
}
if (y_0_top) {
*y_0_top = info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP;
}
if (width) {
*width = info.width;
}
if (height) {
*height = info.height;
}
if (d3d_tex2d) {
*d3d_tex2d = ext.d3d_tex2d;
}
return info.tex_id;
}
#endif
static void virgl_cmd_set_scanout(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
struct virtio_gpu_set_scanout ss;
int ret;
VIRTIO_GPU_FILL_CMD(ss);
trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id,
@@ -168,35 +244,18 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
g->parent_obj.enable = 1;
if (ss.resource_id && ss.r.width && ss.r.height) {
struct virgl_renderer_resource_info info;
void *d3d_tex2d = NULL;
DisplayGLTextureBorrower borrower;
#ifdef HAVE_VIRGL_D3D_INFO_EXT
struct virgl_renderer_resource_info_ext ext;
memset(&ext, 0, sizeof(ext));
ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
info = ext.base;
d3d_tex2d = ext.d3d_tex2d;
borrower = virgl_borrow_d3d_info_for_scanout;
#else
memset(&info, 0, sizeof(info));
ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
borrower = virgl_borrow_texture_for_scanout;
#endif
if (ret) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: illegal resource specified %d\n",
__func__, ss.resource_id);
cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
return;
}
qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con,
ss.r.width, ss.r.height);
virgl_renderer_force_ctx_0();
dpy_gl_scanout_texture(
g->parent_obj.scanout[ss.scanout_id].con, info.tex_id,
info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
info.width, info.height,
ss.r.x, ss.r.y, ss.r.width, ss.r.height,
d3d_tex2d);
g->parent_obj.scanout[ss.scanout_id].con, ss.resource_id,
borrower, ss.r.x, ss.r.y, ss.r.width, ss.r.height);
} else {
dpy_gfx_replace_surface(
g->parent_obj.scanout[ss.scanout_id].con, NULL);
+50
View File
@@ -0,0 +1,50 @@
#include "qemu/osdep.h"
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "hw/virtio/virtio-gpu.h"
#include "hw/display/vga.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "virtio-ramfb.h"
#include "qom/object.h"
#define TYPE_VIRTIO_RAMFB_GL "virtio-ramfb-gl"
typedef struct VirtIORAMFBGL VirtIORAMFBGL;
DECLARE_INSTANCE_CHECKER(VirtIORAMFBGL, VIRTIO_RAMFB_GL,
TYPE_VIRTIO_RAMFB_GL)
struct VirtIORAMFBGL {
VirtIORAMFBBase parent_obj;
VirtIOGPUGL vdev;
};
static void virtio_ramfb_gl_inst_initfn(Object *obj)
{
VirtIORAMFBGL *dev = VIRTIO_RAMFB_GL(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU_GL);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_gl_info = {
.generic_name = TYPE_VIRTIO_RAMFB_GL,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFBGL),
.instance_init = virtio_ramfb_gl_inst_initfn,
};
module_obj(TYPE_VIRTIO_RAMFB_GL);
static void virtio_ramfb_register_types(void)
{
if (have_vga) {
virtio_pci_types_register(&virtio_ramfb_gl_info);
}
}
type_init(virtio_ramfb_register_types)
module_dep("hw-display-virtio-ramfb");
+191
View File
@@ -0,0 +1,191 @@
#include "qemu/osdep.h"
#include "sysemu/sysemu.h"
#include "hw/pci/pci.h"
#include "ui/console.h"
#include "hw/qdev-properties.h"
#include "virtio-ramfb.h"
#include "qapi/error.h"
#include "qom/object.h"
static int virtio_ramfb_get_flags(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->get_flags) {
return g->hw_ops->get_flags(g);
} else {
return 0;
}
}
static void virtio_ramfb_invalidate_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->invalidate(g);
}
}
static void virtio_ramfb_text_update(void *opaque, console_ch_t *chardata)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->text_update) {
g->hw_ops->text_update(g, chardata);
}
}
static void virtio_ramfb_update_display(void *opaque)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->enable) {
g->hw_ops->gfx_update(g);
} else {
ramfb_display_update(g->scanout[0].con, vramfb->ramfb);
}
}
static void virtio_ramfb_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->ui_info) {
g->hw_ops->ui_info(g, idx, info);
}
}
static void virtio_ramfb_gl_block(void *opaque, bool block)
{
VirtIORAMFBBase *vramfb = opaque;
VirtIOGPUBase *g = vramfb->vgpu;
if (g->hw_ops->gl_block) {
g->hw_ops->gl_block(g, block);
}
}
static const GraphicHwOps virtio_ramfb_ops = {
.get_flags = virtio_ramfb_get_flags,
.invalidate = virtio_ramfb_invalidate_display,
.gfx_update = virtio_ramfb_update_display,
.text_update = virtio_ramfb_text_update,
.ui_info = virtio_ramfb_ui_info,
.gl_block = virtio_ramfb_gl_block,
};
static const VMStateDescription vmstate_virtio_ramfb = {
.name = "virtio-ramfb",
.version_id = 2,
.minimum_version_id = 2,
.fields = (VMStateField[]) {
/* no pci stuff here, saving the virtio device will handle that */
/* FIXME */
VMSTATE_END_OF_LIST()
}
};
/* RAMFB device wrapper around PCI device around virtio GPU */
static void virtio_ramfb_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
{
VirtIORAMFBBase *vramfb = VIRTIO_RAMFB_BASE(vpci_dev);
VirtIOGPUBase *g = vramfb->vgpu;
int i;
/* init virtio bits */
virtio_pci_force_virtio_1(vpci_dev);
if (!qdev_realize(DEVICE(g), BUS(&vpci_dev->bus), errp)) {
return;
}
/* init ramfb */
vramfb->ramfb = ramfb_setup(errp);
graphic_console_set_hwops(g->scanout[0].con, &virtio_ramfb_ops, vramfb);
for (i = 0; i < g->conf.max_outputs; i++) {
object_property_set_link(OBJECT(g->scanout[i].con), "device",
OBJECT(vpci_dev), &error_abort);
}
}
static void virtio_ramfb_reset(DeviceState *dev)
{
VirtIORAMFBBaseClass *klass = VIRTIO_RAMFB_BASE_GET_CLASS(dev);
/* reset virtio-gpu */
klass->parent_reset(dev);
}
static Property virtio_ramfb_base_properties[] = {
DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
DEFINE_PROP_END_OF_LIST(),
};
static void virtio_ramfb_base_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
VirtIORAMFBBaseClass *v = VIRTIO_RAMFB_BASE_CLASS(klass);
PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
device_class_set_props(dc, virtio_ramfb_base_properties);
dc->vmsd = &vmstate_virtio_ramfb;
dc->hotpluggable = false;
device_class_set_parent_reset(dc, virtio_ramfb_reset,
&v->parent_reset);
k->realize = virtio_ramfb_realize;
pcidev_k->class_id = PCI_CLASS_DISPLAY_OTHER;
}
static const TypeInfo virtio_ramfb_base_info = {
.name = TYPE_VIRTIO_RAMFB_BASE,
.parent = TYPE_VIRTIO_PCI,
.instance_size = sizeof(VirtIORAMFBBase),
.class_size = sizeof(VirtIORAMFBBaseClass),
.class_init = virtio_ramfb_base_class_init,
.abstract = true,
};
#define TYPE_VIRTIO_RAMFB "virtio-ramfb"
typedef struct VirtIORAMFB VirtIORAMFB;
DECLARE_INSTANCE_CHECKER(VirtIORAMFB, VIRTIO_RAMFB,
TYPE_VIRTIO_RAMFB)
struct VirtIORAMFB {
VirtIORAMFBBase parent_obj;
VirtIOGPU vdev;
};
static void virtio_ramfb_inst_initfn(Object *obj)
{
VirtIORAMFB *dev = VIRTIO_RAMFB(obj);
virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
TYPE_VIRTIO_GPU);
VIRTIO_RAMFB_BASE(dev)->vgpu = VIRTIO_GPU_BASE(&dev->vdev);
}
static VirtioPCIDeviceTypeInfo virtio_ramfb_info = {
.generic_name = TYPE_VIRTIO_RAMFB,
.parent = TYPE_VIRTIO_RAMFB_BASE,
.instance_size = sizeof(VirtIORAMFB),
.instance_init = virtio_ramfb_inst_initfn,
};
static void virtio_ramfb_register_types(void)
{
type_register_static(&virtio_ramfb_base_info);
virtio_pci_types_register(&virtio_ramfb_info);
}
type_init(virtio_ramfb_register_types)
+28
View File
@@ -0,0 +1,28 @@
#ifndef VIRTIO_RAMFB_H
#define VIRTIO_RAMFB_H
#include "hw/virtio/virtio-gpu-pci.h"
#include "hw/display/ramfb.h"
#include "qom/object.h"
/*
* virtio-ramfb-base: This extends VirtioPCIProxy.
*/
#define TYPE_VIRTIO_RAMFB_BASE "virtio-ramfb-base"
OBJECT_DECLARE_TYPE(VirtIORAMFBBase, VirtIORAMFBBaseClass,
VIRTIO_RAMFB_BASE)
struct VirtIORAMFBBase {
VirtIOPCIProxy parent_obj;
VirtIOGPUBase *vgpu;
RAMFBState *ramfb;
};
struct VirtIORAMFBBaseClass {
VirtioPCIClass parent_class;
DeviceReset parent_reset;
};
#endif /* VIRTIO_RAMFB_H */
+1 -15
View File
@@ -1783,21 +1783,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
#ifdef CONFIG_TPM
if (TPM_IS_CRB(tpm)) {
dev = aml_device("TPM");
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
aml_append(dev, aml_name_decl("_STR",
aml_string("TPM 2.0 Device")));
crs = aml_resource_template();
aml_append(crs, aml_memory32_fixed(TPM_CRB_ADDR_BASE,
TPM_CRB_ADDR_SIZE, AML_READ_WRITE));
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(dev, aml_name_decl("_STA", aml_int(0xf)));
aml_append(dev, aml_name_decl("_UID", aml_int(1)));
tpm_build_ppi_acpi(tpm, dev);
aml_append(sb_scope, dev);
call_dev_aml_func(DEVICE(tpm), scope);
}
#endif
+10 -3
View File
@@ -215,7 +215,7 @@ static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte,
{
AddressSpace *as = &s->gicv3->dma_as;
MemTxResult res = MEMTX_OK;
hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE;
hwaddr iteaddr = dte->ittaddr + eventid * s->itt_entry_size;
uint64_t itel = 0;
uint32_t iteh = 0;
@@ -253,7 +253,7 @@ static MemTxResult get_ite(GICv3ITSState *s, uint32_t eventid,
MemTxResult res = MEMTX_OK;
uint64_t itel;
uint32_t iteh;
hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE;
hwaddr iteaddr = dte->ittaddr + eventid * s->itt_entry_size;
itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, &res);
if (res != MEMTX_OK) {
@@ -1931,6 +1931,12 @@ static void gicv3_arm_its_realize(DeviceState *dev, Error **errp)
}
}
if (s->itt_entry_size < MIN_ITS_ITT_ENTRY_SIZE) {
error_setg(errp, "ITT entry size must be at least %d",
MIN_ITS_ITT_ENTRY_SIZE);
return;
}
gicv3_add_its(s->gicv3, dev);
gicv3_its_init_mmio(s, &gicv3_its_control_ops, &gicv3_its_translation_ops);
@@ -1938,7 +1944,7 @@ static void gicv3_arm_its_realize(DeviceState *dev, Error **errp)
/* set the ITS default features supported */
s->typer = FIELD_DP64(s->typer, GITS_TYPER, PHYSICAL, 1);
s->typer = FIELD_DP64(s->typer, GITS_TYPER, ITT_ENTRY_SIZE,
ITS_ITT_ENTRY_SIZE - 1);
s->itt_entry_size - 1);
s->typer = FIELD_DP64(s->typer, GITS_TYPER, IDBITS, ITS_IDBITS);
s->typer = FIELD_DP64(s->typer, GITS_TYPER, DEVBITS, ITS_DEVBITS);
s->typer = FIELD_DP64(s->typer, GITS_TYPER, CIL, 1);
@@ -2005,6 +2011,7 @@ static void gicv3_its_post_load(GICv3ITSState *s)
static Property gicv3_its_props[] = {
DEFINE_PROP_LINK("parent-gicv3", GICv3ITSState, gicv3, "arm-gicv3",
GICv3State *),
DEFINE_PROP_UINT8("itt-entry-size", GICv3ITSState, itt_entry_size, 16),
DEFINE_PROP_END_OF_LIST(),
};
+1 -1
View File
@@ -462,7 +462,7 @@ FIELD(VINVALL_1, VPEID, 32, 16)
* the value of that field in memory cannot be relied upon -- older
* versions of QEMU did not correctly write to that memory.)
*/
#define ITS_ITT_ENTRY_SIZE 0xC
#define MIN_ITS_ITT_ENTRY_SIZE 0xC
FIELD(ITE_L, VALID, 0, 1)
FIELD(ITE_L, INTTYPE, 1, 1)
+1
View File
@@ -9,6 +9,7 @@ config LOONGARCH_VIRT
imply PCI_DEVICES
imply NVDIMM
imply TPM_TIS_SYSBUS
imply TPM_CRB_SYSBUS
select SERIAL
select VIRTIO_PCI
select PLATFORM_BUS
+2 -36
View File
@@ -14,6 +14,7 @@
#include "target/loongarch/cpu.h"
#include "hw/acpi/acpi-defs.h"
#include "hw/acpi/acpi.h"
#include "hw/acpi/acpi_aml_interface.h"
#include "hw/nvram/fw_cfg.h"
#include "hw/acpi/bios-linker-loader.h"
#include "migration/vmstate.h"
@@ -362,41 +363,6 @@ static void build_flash_aml(Aml *scope, LoongArchVirtMachineState *lvms)
aml_append(scope, dev);
}
#ifdef CONFIG_TPM
static void acpi_dsdt_add_tpm(Aml *scope, LoongArchVirtMachineState *vms)
{
PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
hwaddr pbus_base = VIRT_PLATFORM_BUS_BASEADDRESS;
SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
MemoryRegion *sbdev_mr;
hwaddr tpm_base;
if (!sbdev) {
return;
}
tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
assert(tpm_base != -1);
tpm_base += pbus_base;
sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
Aml *dev = aml_device("TPM0");
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
Aml *crs = aml_resource_template();
aml_append(crs,
aml_memory32_fixed(tpm_base,
(uint32_t)memory_region_size(sbdev_mr),
AML_READ_WRITE));
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(scope, dev);
}
#endif
/* build DSDT */
static void
build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
@@ -413,7 +379,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
build_la_ged_aml(dsdt, machine);
build_flash_aml(dsdt, lvms);
#ifdef CONFIG_TPM
acpi_dsdt_add_tpm(dsdt, lvms);
call_dev_aml_func(DEVICE(tpm_find()), dsdt);
#endif
/* System State Package */
scope = aml_scope("\\");
+8
View File
@@ -1316,6 +1316,13 @@ static void virt_device_plug_cb(HotplugHandler *hotplug_dev,
} else if (memhp_type_supported(dev)) {
virt_mem_plug(hotplug_dev, dev, errp);
}
#ifdef CONFIG_TPM
if (object_dynamic_cast(OBJECT(dev), TYPE_TPM_IF)) {
tpm_sysbus_plug(TPM_IF(dev), OBJECT(lvms->platform_bus_dev),
VIRT_PLATFORM_BUS_BASEADDRESS);
}
#endif
}
static HotplugHandler *virt_get_hotplug_handler(MachineState *machine,
@@ -1422,6 +1429,7 @@ static void virt_class_init(ObjectClass *oc, void *data)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
#ifdef CONFIG_TPM
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_CRB_SYSBUS);
#endif
}
+23 -1
View File
@@ -102,6 +102,13 @@ static bool macio_common_realize(PCIDevice *d, Error **errp)
memory_region_add_subregion(&s->bar, 0x08000,
sysbus_mmio_get_region(sbd, 0));
if (!qdev_realize(DEVICE(&s->screamer), BUS(&s->macio_bus), errp)) {
return false;
}
sbd = SYS_BUS_DEVICE(&s->screamer);
memory_region_add_subregion(&s->bar, 0x14000,
sysbus_mmio_get_region(sbd, 0));
qdev_prop_set_uint32(DEVICE(&s->escc), "disabled", 0);
qdev_prop_set_uint32(DEVICE(&s->escc), "frequency", ESCC_CLOCK);
qdev_prop_set_uint32(DEVICE(&s->escc), "it_shift", 4);
@@ -110,7 +117,6 @@ static bool macio_common_realize(PCIDevice *d, Error **errp)
if (!qdev_realize(DEVICE(&s->escc), BUS(&s->macio_bus), errp)) {
return false;
}
macio_bar_setup(s);
pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar);
@@ -191,6 +197,13 @@ static void macio_oldworld_realize(PCIDevice *d, Error **errp)
0x1a, errp)) {
return;
}
/* Screamer */
sbd = SYS_BUS_DEVICE(&s->screamer);
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(pic_dev, OLDWORLD_SCREAMER_TX_IRQ));
sysbus_connect_irq(sbd, 1, qdev_get_gpio_in(pic_dev, OLDWORLD_SCREAMER_TX_DMA_IRQ));
sysbus_connect_irq(sbd, 1, qdev_get_gpio_in(pic_dev, OLDWORLD_SCREAMER_RX_IRQ));
macio_screamer_register_dma(SCREAMER(sbd), &s->dbdma, 0x10, 0x12);
}
static void macio_init_ide(MacIOState *s, MACIOIDEState *ide, int index)
@@ -344,6 +357,13 @@ static void macio_newworld_realize(PCIDevice *d, Error **errp)
memory_region_add_subregion(&s->bar, 0x16000,
sysbus_mmio_get_region(sbd, 0));
}
/* Screamer */
sbd = SYS_BUS_DEVICE(&s->screamer);
sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(pic_dev, NEWWORLD_SCREAMER_IRQ));
sysbus_connect_irq(sbd, 1, qdev_get_gpio_in(pic_dev, NEWWORLD_SCREAMER_DMA_IRQ));
sysbus_connect_irq(sbd, 2, qdev_get_gpio_in(pic_dev, NEWWORLD_SCREAMER_RX_IRQ));
macio_screamer_register_dma(SCREAMER(sbd), &s->dbdma, 0x10, 0x12);
}
static void macio_newworld_init(Object *obj)
@@ -373,6 +393,8 @@ static void macio_instance_init(Object *obj)
object_initialize_child(obj, "dbdma", &s->dbdma, TYPE_MAC_DBDMA);
object_initialize_child(obj, "escc", &s->escc, TYPE_ESCC);
object_initialize_child(obj, "screamer", &s->screamer, TYPE_SCREAMER);
}
static const VMStateDescription vmstate_macio_oldworld = {
+2
View File
@@ -136,6 +136,7 @@ config MAC_OLDWORLD
select HEATHROW_PIC
select MACIO
select FW_CFG_PPC
select SCREAMER
config MAC_NEWWORLD
bool
@@ -151,6 +152,7 @@ config MAC_NEWWORLD
select MAC_PMU
select UNIN_PCI
select FW_CFG_PPC
select SCREAMER
config E500
bool
+1
View File
@@ -37,6 +37,7 @@ config RISCV_VIRT
imply PCI_DEVICES
imply VIRTIO_VGA
imply TEST_DEVICES
imply TPM_CRB_SYSBUS
imply TPM_TIS_SYSBUS
select DEVICE_TREE
select RISCV_NUMA
+1
View File
@@ -1790,6 +1790,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
#ifdef CONFIG_TPM
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_CRB_SYSBUS);
#endif
object_class_property_add_bool(oc, "aclint", virt_get_aclint,
+5
View File
@@ -25,6 +25,11 @@ config TPM_CRB
depends on TPM && PC
select TPM_BACKEND
config TPM_CRB_SYSBUS
bool
depends on TPM
select TPM_BACKEND
config TPM_SPAPR
bool
default y
+5
View File
@@ -1,8 +1,13 @@
system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_tis_common.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_ISA', if_true: files('tpm_tis_isa.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm_tis_sysbus.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_SYSBUS', if_true: files('tpm-sysbus.c'))
system_ss.add(when: 'CONFIG_TPM_TIS_I2C', if_true: files('tpm_tis_i2c.c'))
system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb.c'))
system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_crb_common.c'))
system_ss.add(when: 'CONFIG_TPM_CRB_SYSBUS', if_true: files('tpm_crb_sysbus.c'))
system_ss.add(when: 'CONFIG_TPM_CRB_SYSBUS', if_true: files('tpm_crb_common.c'))
system_ss.add(when: 'CONFIG_TPM_CRB_SYSBUS', if_true: files('tpm-sysbus.c'))
system_ss.add(when: 'CONFIG_TPM_TIS', if_true: files('tpm_ppi.c'))
system_ss.add(when: 'CONFIG_TPM_CRB', if_true: files('tpm_ppi.c'))
+47
View File
@@ -0,0 +1,47 @@
/*
* tpm-sysbus.c - Support functions for SysBus TPM devices
*
* Copyright (c) 2023 QEMU contributors
*
* Authors:
* Joelle van Dyne <j@getutm.app>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "sysemu/tpm.h"
#include "hw/platform-bus.h"
#include "hw/sysbus.h"
#include "qapi/error.h"
/**
* Called from a machine's pre_plug handler to set the device's physical addr.
*/
void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base)
{
PlatformBusDevice *pbusdev = PLATFORM_BUS_DEVICE(pbus);
SysBusDevice *sbdev = SYS_BUS_DEVICE(tpmif);
MemoryRegion *sbdev_mr;
hwaddr tpm_base;
uint64_t tpm_size;
/* exit early if TPM is not a sysbus device */
if (!object_dynamic_cast(OBJECT(tpmif), TYPE_SYS_BUS_DEVICE)) {
return;
}
assert(object_dynamic_cast(pbus, TYPE_PLATFORM_BUS_DEVICE));
tpm_base = platform_bus_get_mmio_addr(pbusdev, sbdev, 0);
assert(tpm_base != -1);
tpm_base += pbus_base;
sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
tpm_size = memory_region_size(sbdev_mr);
object_property_set_uint(OBJECT(sbdev), "x-baseaddr",
tpm_base, &error_abort);
object_property_set_uint(OBJECT(sbdev), "x-size",
tpm_size, &error_abort);
}
+74 -232
View File
@@ -19,6 +19,8 @@
#include "qemu/module.h"
#include "qapi/error.h"
#include "exec/address-spaces.h"
#include "hw/acpi/acpi_aml_interface.h"
#include "hw/acpi/tpm.h"
#include "hw/qdev-properties.h"
#include "hw/pci/pci_ids.h"
#include "hw/acpi/tpm.h"
@@ -31,257 +33,84 @@
#include "tpm_ppi.h"
#include "trace.h"
#include "qom/object.h"
#include "tpm_crb.h"
struct CRBState {
DeviceState parent_obj;
TPMBackend *tpmbe;
TPMBackendCmd cmd;
uint32_t regs[TPM_CRB_R_MAX];
MemoryRegion mmio;
MemoryRegion cmdmem;
TPMCRBState state;
size_t be_buffer_size;
bool ppi_enabled;
TPMPPI ppi;
/* These states are only for migration */
uint32_t saved_regs[TPM_CRB_R_MAX];
MemoryRegion saved_cmdmem;
};
typedef struct CRBState CRBState;
DECLARE_INSTANCE_CHECKER(CRBState, CRB,
TYPE_TPM_CRB)
#define CRB_INTF_TYPE_CRB_ACTIVE 0b1
#define CRB_INTF_VERSION_CRB 0b1
#define CRB_INTF_CAP_LOCALITY_0_ONLY 0b0
#define CRB_INTF_CAP_IDLE_FAST 0b0
#define CRB_INTF_CAP_XFER_SIZE_64 0b11
#define CRB_INTF_CAP_FIFO_NOT_SUPPORTED 0b0
#define CRB_INTF_CAP_CRB_SUPPORTED 0b1
#define CRB_INTF_IF_SELECTOR_CRB 0b1
#define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - A_CRB_DATA_BUFFER)
enum crb_loc_ctrl {
CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0),
CRB_LOC_CTRL_RELINQUISH = BIT(1),
CRB_LOC_CTRL_SEIZE = BIT(2),
CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT = BIT(3),
};
enum crb_ctrl_req {
CRB_CTRL_REQ_CMD_READY = BIT(0),
CRB_CTRL_REQ_GO_IDLE = BIT(1),
};
enum crb_start {
CRB_START_INVOKE = BIT(0),
};
enum crb_cancel {
CRB_CANCEL_INVOKE = BIT(0),
};
#define TPM_CRB_NO_LOCALITY 0xff
static uint64_t tpm_crb_mmio_read(void *opaque, hwaddr addr,
unsigned size)
{
CRBState *s = CRB(opaque);
void *regs = (void *)&s->regs + (addr & ~3);
unsigned offset = addr & 3;
uint32_t val = *(uint32_t *)regs >> (8 * offset);
switch (addr) {
case A_CRB_LOC_STATE:
val |= !tpm_backend_get_tpm_established_flag(s->tpmbe);
break;
}
trace_tpm_crb_mmio_read(addr, size, val);
return val;
}
static uint8_t tpm_crb_get_active_locty(CRBState *s)
{
if (!ARRAY_FIELD_EX32(s->regs, CRB_LOC_STATE, locAssigned)) {
return TPM_CRB_NO_LOCALITY;
}
return ARRAY_FIELD_EX32(s->regs, CRB_LOC_STATE, activeLocality);
}
static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
CRBState *s = CRB(opaque);
uint8_t locty = addr >> 12;
trace_tpm_crb_mmio_write(addr, size, val);
switch (addr) {
case A_CRB_CTRL_REQ:
switch (val) {
case CRB_CTRL_REQ_CMD_READY:
ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
tpmIdle, 0);
break;
case CRB_CTRL_REQ_GO_IDLE:
ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
tpmIdle, 1);
break;
}
break;
case A_CRB_CTRL_CANCEL:
if (val == CRB_CANCEL_INVOKE &&
s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) {
tpm_backend_cancel_cmd(s->tpmbe);
}
break;
case A_CRB_CTRL_START:
if (val == CRB_START_INVOKE &&
!(s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) &&
tpm_crb_get_active_locty(s) == locty) {
void *mem = memory_region_get_ram_ptr(&s->cmdmem);
s->regs[R_CRB_CTRL_START] |= CRB_START_INVOKE;
s->cmd = (TPMBackendCmd) {
.in = mem,
.in_len = MIN(tpm_cmd_get_size(mem), s->be_buffer_size),
.out = mem,
.out_len = s->be_buffer_size,
};
tpm_backend_deliver_request(s->tpmbe, &s->cmd);
}
break;
case A_CRB_LOC_CTRL:
switch (val) {
case CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT:
/* not loc 3 or 4 */
break;
case CRB_LOC_CTRL_RELINQUISH:
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
locAssigned, 0);
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS,
Granted, 0);
break;
case CRB_LOC_CTRL_REQUEST_ACCESS:
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS,
Granted, 1);
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS,
beenSeized, 0);
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
locAssigned, 1);
break;
}
break;
}
}
static const MemoryRegionOps tpm_crb_memory_ops = {
.read = tpm_crb_mmio_read,
.write = tpm_crb_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 1,
.max_access_size = 4,
},
};
static void tpm_crb_request_completed(TPMIf *ti, int ret)
static void tpm_crb_none_request_completed(TPMIf *ti, int ret)
{
CRBState *s = CRB(ti);
s->regs[R_CRB_CTRL_START] &= ~CRB_START_INVOKE;
if (ret != 0) {
ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
tpmSts, 1); /* fatal error */
}
memory_region_set_dirty(&s->cmdmem, 0, CRB_CTRL_CMD_SIZE);
tpm_crb_request_completed(&s->state, ret);
}
static enum TPMVersion tpm_crb_get_version(TPMIf *ti)
static enum TPMVersion tpm_crb_none_get_version(TPMIf *ti)
{
CRBState *s = CRB(ti);
return tpm_backend_get_tpm_version(s->tpmbe);
return tpm_crb_get_version(&s->state);
}
static int tpm_crb_pre_save(void *opaque)
/**
* For migrating to an older version of QEMU
*/
static int tpm_crb_none_pre_save(void *opaque)
{
CRBState *s = opaque;
void *saved_cmdmem = memory_region_get_ram_ptr(&s->saved_cmdmem);
tpm_backend_finish_sync(s->tpmbe);
tpm_crb_mem_save(&s->state, s->saved_regs, saved_cmdmem);
return tpm_crb_pre_save(&s->state);
}
/**
* For migrating from an older version of QEMU
*/
static int tpm_crb_none_post_load(void *opaque, int version_id)
{
CRBState *s = opaque;
void *saved_cmdmem = memory_region_get_ram_ptr(&s->saved_cmdmem);
tpm_crb_mem_load(&s->state, s->saved_regs, saved_cmdmem);
return 0;
}
static const VMStateDescription vmstate_tpm_crb = {
static const VMStateDescription vmstate_tpm_crb_none = {
.name = "tpm-crb",
.pre_save = tpm_crb_pre_save,
.pre_save = tpm_crb_none_pre_save,
.post_load = tpm_crb_none_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT32_ARRAY(regs, CRBState, TPM_CRB_R_MAX),
VMSTATE_UINT32_ARRAY(saved_regs, CRBState, TPM_CRB_R_MAX),
VMSTATE_END_OF_LIST(),
}
};
static Property tpm_crb_properties[] = {
DEFINE_PROP_TPMBE("tpmdev", CRBState, tpmbe),
DEFINE_PROP_BOOL("ppi", CRBState, ppi_enabled, true),
static Property tpm_crb_none_properties[] = {
DEFINE_PROP_TPMBE("tpmdev", CRBState, state.tpmbe),
DEFINE_PROP_BOOL("ppi", CRBState, state.ppi_enabled, true),
DEFINE_PROP_END_OF_LIST(),
};
static void tpm_crb_reset(void *dev)
static void tpm_crb_none_reset(void *dev)
{
CRBState *s = CRB(dev);
if (s->ppi_enabled) {
tpm_ppi_reset(&s->ppi);
}
tpm_backend_reset(s->tpmbe);
memset(s->regs, 0, sizeof(s->regs));
ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
tpmRegValidSts, 1);
ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
tpmIdle, 1);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
InterfaceType, CRB_INTF_TYPE_CRB_ACTIVE);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
InterfaceVersion, CRB_INTF_VERSION_CRB);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
CapLocality, CRB_INTF_CAP_LOCALITY_0_ONLY);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
CapCRBIdleBypass, CRB_INTF_CAP_IDLE_FAST);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
CapDataXferSizeSupport, CRB_INTF_CAP_XFER_SIZE_64);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
CapFIFO, CRB_INTF_CAP_FIFO_NOT_SUPPORTED);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
CapCRB, CRB_INTF_CAP_CRB_SUPPORTED);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
InterfaceSelector, CRB_INTF_IF_SELECTOR_CRB);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
RID, 0b0000);
ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID2,
VID, PCI_VENDOR_ID_IBM);
s->regs[R_CRB_CTRL_CMD_SIZE] = CRB_CTRL_CMD_SIZE;
s->regs[R_CRB_CTRL_CMD_LADDR] = TPM_CRB_ADDR_BASE + A_CRB_DATA_BUFFER;
s->regs[R_CRB_CTRL_RSP_SIZE] = CRB_CTRL_CMD_SIZE;
s->regs[R_CRB_CTRL_RSP_ADDR] = TPM_CRB_ADDR_BASE + A_CRB_DATA_BUFFER;
s->be_buffer_size = MIN(tpm_backend_get_buffer_size(s->tpmbe),
CRB_CTRL_CMD_SIZE);
if (tpm_backend_startup_tpm(s->tpmbe, s->be_buffer_size) < 0) {
exit(1);
}
return tpm_crb_reset(&s->state, TPM_CRB_ADDR_BASE);
}
static void tpm_crb_realize(DeviceState *dev, Error **errp)
static void tpm_crb_none_realize(DeviceState *dev, Error **errp)
{
CRBState *s = CRB(dev);
@@ -289,64 +118,77 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp)
error_setg(errp, "at most one TPM device is permitted");
return;
}
if (!s->tpmbe) {
if (!s->state.tpmbe) {
error_setg(errp, "'tpmdev' property is required");
return;
}
memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s,
"tpm-crb-mmio", sizeof(s->regs));
memory_region_init_ram(&s->cmdmem, OBJECT(s),
if (tpm_crb_none_get_version(TPM_IF(s)) != TPM_VERSION_2_0) {
error_setg(errp, "TPM CRB only supports TPM 2.0 backends");
return;
}
tpm_crb_init_memory(OBJECT(s), &s->state, errp);
/* only used for migration */
memory_region_init_ram(&s->saved_cmdmem, OBJECT(s),
"tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp);
memory_region_add_subregion(get_system_memory(),
TPM_CRB_ADDR_BASE, &s->mmio);
memory_region_add_subregion(get_system_memory(),
TPM_CRB_ADDR_BASE + sizeof(s->regs), &s->cmdmem);
TPM_CRB_ADDR_BASE, &s->state.mmio);
if (s->ppi_enabled) {
tpm_ppi_init(&s->ppi, get_system_memory(),
TPM_PPI_ADDR_BASE, OBJECT(s));
if (s->state.ppi_enabled) {
memory_region_add_subregion(get_system_memory(),
TPM_PPI_ADDR_BASE, &s->state.ppi.ram);
}
if (xen_enabled()) {
tpm_crb_reset(dev);
tpm_crb_none_reset(dev);
} else {
qemu_register_reset(tpm_crb_reset, dev);
qemu_register_reset(tpm_crb_none_reset, dev);
}
}
static void tpm_crb_class_init(ObjectClass *klass, void *data)
static void build_tpm_crb_none_aml(AcpiDevAmlIf *adev, Aml *scope)
{
tpm_crb_build_aml(TPM_IF(adev), scope, TPM_CRB_ADDR_BASE, TPM_CRB_ADDR_SIZE,
true);
}
static void tpm_crb_none_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
TPMIfClass *tc = TPM_IF_CLASS(klass);
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
dc->realize = tpm_crb_realize;
device_class_set_props(dc, tpm_crb_properties);
dc->vmsd = &vmstate_tpm_crb;
dc->realize = tpm_crb_none_realize;
device_class_set_props(dc, tpm_crb_none_properties);
dc->vmsd = &vmstate_tpm_crb_none;
dc->user_creatable = true;
tc->model = TPM_MODEL_TPM_CRB;
tc->get_version = tpm_crb_get_version;
tc->request_completed = tpm_crb_request_completed;
tc->get_version = tpm_crb_none_get_version;
tc->request_completed = tpm_crb_none_request_completed;
adevc->build_dev_aml = build_tpm_crb_none_aml;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
}
static const TypeInfo tpm_crb_info = {
static const TypeInfo tpm_crb_none_info = {
.name = TYPE_TPM_CRB,
/* could be TYPE_SYS_BUS_DEVICE (or LPC etc) */
.parent = TYPE_DEVICE,
.instance_size = sizeof(CRBState),
.class_init = tpm_crb_class_init,
.class_init = tpm_crb_none_class_init,
.interfaces = (InterfaceInfo[]) {
{ TYPE_TPM_IF },
{ TYPE_ACPI_DEV_AML_IF },
{ }
}
};
static void tpm_crb_register(void)
static void tpm_crb_none_register(void)
{
type_register_static(&tpm_crb_info);
type_register_static(&tpm_crb_none_info);
}
type_init(tpm_crb_register)
type_init(tpm_crb_none_register)
+79
View File
@@ -0,0 +1,79 @@
/*
* tpm_crb.h - QEMU's TPM CRB interface emulator
*
* Copyright (c) 2018 Red Hat, Inc.
*
* Authors:
* Marc-André Lureau <marcandre.lureau@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
* tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface
* as defined in TCG PC Client Platform TPM Profile (PTP) Specification
* Family “2.0” Level 00 Revision 01.03 v22
*/
#ifndef TPM_TPM_CRB_H
#define TPM_TPM_CRB_H
#include "exec/memory.h"
#include "hw/acpi/tpm.h"
#include "sysemu/tpm_backend.h"
#include "tpm_ppi.h"
#define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - A_CRB_DATA_BUFFER)
typedef struct TPMCRBState {
TPMBackend *tpmbe;
TPMBackendCmd cmd;
MemoryRegion mmio;
size_t be_buffer_size;
bool ppi_enabled;
TPMPPI ppi;
} TPMCRBState;
#define CRB_INTF_TYPE_CRB_ACTIVE 0b1
#define CRB_INTF_VERSION_CRB 0b1
#define CRB_INTF_CAP_LOCALITY_0_ONLY 0b0
#define CRB_INTF_CAP_IDLE_FAST 0b0
#define CRB_INTF_CAP_XFER_SIZE_64 0b11
#define CRB_INTF_CAP_FIFO_NOT_SUPPORTED 0b0
#define CRB_INTF_CAP_CRB_SUPPORTED 0b1
#define CRB_INTF_IF_SELECTOR_CRB 0b1
enum crb_loc_ctrl {
CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0),
CRB_LOC_CTRL_RELINQUISH = BIT(1),
CRB_LOC_CTRL_SEIZE = BIT(2),
CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT = BIT(3),
};
enum crb_ctrl_req {
CRB_CTRL_REQ_CMD_READY = BIT(0),
CRB_CTRL_REQ_GO_IDLE = BIT(1),
};
enum crb_start {
CRB_START_INVOKE = BIT(0),
};
enum crb_cancel {
CRB_CANCEL_INVOKE = BIT(0),
};
#define TPM_CRB_NO_LOCALITY 0xff
void tpm_crb_request_completed(TPMCRBState *s, int ret);
enum TPMVersion tpm_crb_get_version(TPMCRBState *s);
int tpm_crb_pre_save(TPMCRBState *s);
void tpm_crb_reset(TPMCRBState *s, uint64_t baseaddr);
void tpm_crb_init_memory(Object *obj, TPMCRBState *s, Error **errp);
void tpm_crb_mem_save(TPMCRBState *s, uint32_t *saved_regs, void *saved_cmdmem);
void tpm_crb_mem_load(TPMCRBState *s, const uint32_t *saved_regs,
const void *saved_cmdmem);
void tpm_crb_build_aml(TPMIf *ti, Aml *scope, uint32_t baseaddr, uint32_t size,
bool build_ppi);
#endif /* TPM_TPM_CRB_H */
+264
View File
@@ -0,0 +1,264 @@
/*
* tpm_crb.c - QEMU's TPM CRB interface emulator
*
* Copyright (c) 2018 Red Hat, Inc.
*
* Authors:
* Marc-André Lureau <marcandre.lureau@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
* tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface
* as defined in TCG PC Client Platform TPM Profile (PTP) Specification
* Family “2.0” Level 00 Revision 01.03 v22
*/
#include "qemu/osdep.h"
#include "qemu/module.h"
#include "qapi/error.h"
#include "exec/address-spaces.h"
#include "hw/qdev-properties.h"
#include "hw/pci/pci_ids.h"
#include "hw/acpi/tpm.h"
#include "migration/vmstate.h"
#include "sysemu/tpm_backend.h"
#include "sysemu/tpm_util.h"
#include "tpm_prop.h"
#include "tpm_ppi.h"
#include "trace.h"
#include "qom/object.h"
#include "tpm_crb.h"
static uint8_t tpm_crb_get_active_locty(TPMCRBState *s, uint32_t *regs)
{
if (!ARRAY_FIELD_EX32(regs, CRB_LOC_STATE, locAssigned)) {
return TPM_CRB_NO_LOCALITY;
}
return ARRAY_FIELD_EX32(regs, CRB_LOC_STATE, activeLocality);
}
static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
TPMCRBState *s = opaque;
uint8_t locty = addr >> 12;
uint32_t *regs;
void *mem;
trace_tpm_crb_mmio_write(addr, size, val);
regs = memory_region_get_ram_ptr(&s->mmio);
mem = &regs[R_CRB_DATA_BUFFER];
assert(regs);
/* receive TPM command bytes in DATA_BUFFER */
if (addr >= A_CRB_DATA_BUFFER) {
assert(addr + size <= TPM_CRB_ADDR_SIZE);
assert(size <= sizeof(val));
memcpy(mem + addr - A_CRB_DATA_BUFFER, &val, size);
memory_region_set_dirty(&s->mmio, addr, size);
return;
}
/* otherwise we are doing MMIO writes */
switch (addr) {
case A_CRB_CTRL_REQ:
switch (val) {
case CRB_CTRL_REQ_CMD_READY:
ARRAY_FIELD_DP32(regs, CRB_CTRL_STS,
tpmIdle, 0);
break;
case CRB_CTRL_REQ_GO_IDLE:
ARRAY_FIELD_DP32(regs, CRB_CTRL_STS,
tpmIdle, 1);
break;
}
break;
case A_CRB_CTRL_CANCEL:
if (val == CRB_CANCEL_INVOKE &&
regs[R_CRB_CTRL_START] & CRB_START_INVOKE) {
tpm_backend_cancel_cmd(s->tpmbe);
}
break;
case A_CRB_CTRL_START:
if (val == CRB_START_INVOKE &&
!(regs[R_CRB_CTRL_START] & CRB_START_INVOKE) &&
tpm_crb_get_active_locty(s, regs) == locty) {
regs[R_CRB_CTRL_START] |= CRB_START_INVOKE;
s->cmd = (TPMBackendCmd) {
.in = mem,
.in_len = MIN(tpm_cmd_get_size(mem), s->be_buffer_size),
.out = mem,
.out_len = s->be_buffer_size,
};
tpm_backend_deliver_request(s->tpmbe, &s->cmd);
}
break;
case A_CRB_LOC_CTRL:
switch (val) {
case CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT:
/* not loc 3 or 4 */
break;
case CRB_LOC_CTRL_RELINQUISH:
ARRAY_FIELD_DP32(regs, CRB_LOC_STATE,
locAssigned, 0);
ARRAY_FIELD_DP32(regs, CRB_LOC_STS,
Granted, 0);
break;
case CRB_LOC_CTRL_REQUEST_ACCESS:
ARRAY_FIELD_DP32(regs, CRB_LOC_STS,
Granted, 1);
ARRAY_FIELD_DP32(regs, CRB_LOC_STS,
beenSeized, 0);
ARRAY_FIELD_DP32(regs, CRB_LOC_STATE,
locAssigned, 1);
break;
}
break;
}
memory_region_set_dirty(&s->mmio, 0, A_CRB_DATA_BUFFER);
}
const MemoryRegionOps tpm_crb_memory_ops = {
.write = tpm_crb_mmio_write,
.endianness = DEVICE_LITTLE_ENDIAN,
.valid = {
.min_access_size = 1,
.max_access_size = 4,
},
};
void tpm_crb_request_completed(TPMCRBState *s, int ret)
{
uint32_t *regs = memory_region_get_ram_ptr(&s->mmio);
assert(regs);
regs[R_CRB_CTRL_START] &= ~CRB_START_INVOKE;
if (ret != 0) {
ARRAY_FIELD_DP32(regs, CRB_CTRL_STS,
tpmSts, 1); /* fatal error */
}
memory_region_set_dirty(&s->mmio, 0, TPM_CRB_ADDR_SIZE);
}
enum TPMVersion tpm_crb_get_version(TPMCRBState *s)
{
return tpm_backend_get_tpm_version(s->tpmbe);
}
int tpm_crb_pre_save(TPMCRBState *s)
{
tpm_backend_finish_sync(s->tpmbe);
return 0;
}
void tpm_crb_reset(TPMCRBState *s, uint64_t baseaddr)
{
uint32_t *regs = memory_region_get_ram_ptr(&s->mmio);
assert(regs);
if (s->ppi_enabled) {
tpm_ppi_reset(&s->ppi);
}
tpm_backend_reset(s->tpmbe);
memset(regs, 0, TPM_CRB_ADDR_SIZE);
ARRAY_FIELD_DP32(regs, CRB_LOC_STATE,
tpmRegValidSts, 1);
ARRAY_FIELD_DP32(regs, CRB_LOC_STATE,
tpmEstablished, 1);
ARRAY_FIELD_DP32(regs, CRB_CTRL_STS,
tpmIdle, 1);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
InterfaceType, CRB_INTF_TYPE_CRB_ACTIVE);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
InterfaceVersion, CRB_INTF_VERSION_CRB);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
CapLocality, CRB_INTF_CAP_LOCALITY_0_ONLY);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
CapCRBIdleBypass, CRB_INTF_CAP_IDLE_FAST);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
CapDataXferSizeSupport, CRB_INTF_CAP_XFER_SIZE_64);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
CapFIFO, CRB_INTF_CAP_FIFO_NOT_SUPPORTED);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
CapCRB, CRB_INTF_CAP_CRB_SUPPORTED);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
InterfaceSelector, CRB_INTF_IF_SELECTOR_CRB);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID,
RID, 0b0000);
ARRAY_FIELD_DP32(regs, CRB_INTF_ID2,
VID, PCI_VENDOR_ID_IBM);
baseaddr += A_CRB_DATA_BUFFER;
regs[R_CRB_CTRL_CMD_SIZE] = CRB_CTRL_CMD_SIZE;
regs[R_CRB_CTRL_CMD_LADDR] = (uint32_t)baseaddr;
regs[R_CRB_CTRL_CMD_HADDR] = (uint32_t)(baseaddr >> 32);
regs[R_CRB_CTRL_RSP_SIZE] = CRB_CTRL_CMD_SIZE;
regs[R_CRB_CTRL_RSP_LADDR] = (uint32_t)baseaddr;
regs[R_CRB_CTRL_RSP_HADDR] = (uint32_t)(baseaddr >> 32);
s->be_buffer_size = MIN(tpm_backend_get_buffer_size(s->tpmbe),
CRB_CTRL_CMD_SIZE);
if (tpm_backend_startup_tpm(s->tpmbe, s->be_buffer_size) < 0) {
exit(1);
}
memory_region_rom_device_set_romd(&s->mmio, true);
memory_region_set_dirty(&s->mmio, 0, TPM_CRB_ADDR_SIZE);
}
void tpm_crb_init_memory(Object *obj, TPMCRBState *s, Error **errp)
{
uint64_t page_size = qemu_real_host_page_size();
memory_region_init_rom_device_nomigrate(&s->mmio, obj, &tpm_crb_memory_ops,
s, "tpm-crb-mem", ROUND_UP(TPM_CRB_ADDR_SIZE, page_size), errp);
if (s->ppi_enabled) {
tpm_ppi_init_memory(&s->ppi, obj);
}
}
void tpm_crb_mem_save(TPMCRBState *s, uint32_t *saved_regs, void *saved_cmdmem)
{
uint32_t *regs = memory_region_get_ram_ptr(&s->mmio);
memcpy(saved_regs, regs, A_CRB_DATA_BUFFER);
memcpy(saved_cmdmem, &regs[R_CRB_DATA_BUFFER], CRB_CTRL_CMD_SIZE);
}
void tpm_crb_mem_load(TPMCRBState *s, const uint32_t *saved_regs,
const void *saved_cmdmem)
{
uint32_t *regs = memory_region_get_ram_ptr(&s->mmio);
memcpy(regs, saved_regs, A_CRB_DATA_BUFFER);
memcpy(&regs[R_CRB_DATA_BUFFER], saved_cmdmem, CRB_CTRL_CMD_SIZE);
}
void tpm_crb_build_aml(TPMIf *ti, Aml *scope, uint32_t baseaddr, uint32_t size,
bool build_ppi)
{
Aml *dev, *crs;
dev = aml_device("TPM");
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
aml_append(dev, aml_name_decl("_UID", aml_int(1)));
aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
crs = aml_resource_template();
aml_append(crs, aml_memory32_fixed(baseaddr, size, AML_READ_WRITE));
aml_append(dev, aml_name_decl("_CRS", crs));
if (build_ppi) {
tpm_build_ppi_acpi(ti, dev);
}
aml_append(scope, dev);
}
+162
View File
@@ -0,0 +1,162 @@
/*
* tpm_crb_sysbus.c - QEMU's TPM CRB interface emulator
*
* Copyright (c) 2018 Red Hat, Inc.
*
* Authors:
* Marc-André Lureau <marcandre.lureau@redhat.com>
* Joelle van Dyne <j@getutm.app>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*
* tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface
* as defined in TCG PC Client Platform TPM Profile (PTP) Specification
* Family “2.0” Level 00 Revision 01.03 v22
*/
#include "qemu/osdep.h"
#include "hw/acpi/acpi_aml_interface.h"
#include "hw/acpi/tpm.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "tpm_prop.h"
#include "hw/sysbus.h"
#include "qapi/visitor.h"
#include "qom/object.h"
#include "sysemu/tpm_util.h"
#include "trace.h"
#include "tpm_crb.h"
struct TPMCRBStateSysBus {
/*< private >*/
SysBusDevice parent_obj;
/*< public >*/
TPMCRBState state;
uint64_t baseaddr;
uint64_t size;
};
OBJECT_DECLARE_SIMPLE_TYPE(TPMCRBStateSysBus, TPM_CRB_SYSBUS)
static void tpm_crb_sysbus_request_completed(TPMIf *ti, int ret)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(ti);
return tpm_crb_request_completed(&s->state, ret);
}
static enum TPMVersion tpm_crb_sysbus_get_tpm_version(TPMIf *ti)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(ti);
return tpm_crb_get_version(&s->state);
}
static int tpm_crb_sysbus_pre_save(void *opaque)
{
TPMCRBStateSysBus *s = opaque;
return tpm_crb_pre_save(&s->state);
}
static const VMStateDescription vmstate_tpm_crb_sysbus = {
.name = "tpm-crb-sysbus",
.pre_save = tpm_crb_sysbus_pre_save,
.fields = (const VMStateField[]) {
VMSTATE_END_OF_LIST(),
}
};
static Property tpm_crb_sysbus_properties[] = {
DEFINE_PROP_TPMBE("tpmdev", TPMCRBStateSysBus, state.tpmbe),
DEFINE_PROP_UINT64("x-baseaddr", TPMCRBStateSysBus,
baseaddr, TPM_CRB_ADDR_BASE),
DEFINE_PROP_UINT64("x-size", TPMCRBStateSysBus,
size, TPM_CRB_ADDR_SIZE),
DEFINE_PROP_END_OF_LIST(),
};
static void tpm_crb_sysbus_initfn(Object *obj)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(obj);
tpm_crb_init_memory(obj, &s->state, NULL);
vmstate_register_ram(&s->state.mmio, DEVICE(obj));
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->state.mmio);
}
static void tpm_crb_sysbus_reset(DeviceState *dev)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(dev);
return tpm_crb_reset(&s->state, s->baseaddr);
}
static void tpm_crb_sysbus_realizefn(DeviceState *dev, Error **errp)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(dev);
if (!tpm_find()) {
error_setg(errp, "at most one TPM device is permitted");
return;
}
if (!s->state.tpmbe) {
error_setg(errp, "'tpmdev' property is required");
return;
}
if (tpm_crb_sysbus_get_tpm_version(TPM_IF(s)) != TPM_VERSION_2_0) {
error_setg(errp, "TPM CRB only supports TPM 2.0 backends");
return;
}
}
static void build_tpm_crb_sysbus_aml(AcpiDevAmlIf *adev, Aml *scope)
{
TPMCRBStateSysBus *s = TPM_CRB_SYSBUS(adev);
tpm_crb_build_aml(TPM_IF(adev), scope, s->baseaddr, s->size, false);
}
static void tpm_crb_sysbus_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
TPMIfClass *tc = TPM_IF_CLASS(klass);
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
device_class_set_props(dc, tpm_crb_sysbus_properties);
dc->vmsd = &vmstate_tpm_crb_sysbus;
tc->model = TPM_MODEL_TPM_CRB;
dc->realize = tpm_crb_sysbus_realizefn;
dc->user_creatable = true;
dc->reset = tpm_crb_sysbus_reset;
tc->request_completed = tpm_crb_sysbus_request_completed;
tc->get_version = tpm_crb_sysbus_get_tpm_version;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
adevc->build_dev_aml = build_tpm_crb_sysbus_aml;
}
static const TypeInfo tpm_crb_sysbus_info = {
.name = TYPE_TPM_CRB_SYSBUS,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(TPMCRBStateSysBus),
.instance_init = tpm_crb_sysbus_initfn,
.class_init = tpm_crb_sysbus_class_init,
.interfaces = (InterfaceInfo[]) {
{ TYPE_TPM_IF },
{ TYPE_ACPI_DEV_AML_IF },
{ }
}
};
static void tpm_crb_sysbus_register(void)
{
type_register_static(&tpm_crb_sysbus_info);
}
type_init(tpm_crb_sysbus_register)
+1 -4
View File
@@ -44,8 +44,7 @@ void tpm_ppi_reset(TPMPPI *tpmppi)
}
}
void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
hwaddr addr, Object *obj)
void tpm_ppi_init_memory(TPMPPI *tpmppi, Object *obj)
{
size_t host_page_size = qemu_real_host_page_size();
@@ -54,6 +53,4 @@ void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
memory_region_init_ram_device_ptr(&tpmppi->ram, obj, "tpm-ppi",
TPM_PPI_ADDR_SIZE, tpmppi->buf);
vmstate_register_ram(&tpmppi->ram, DEVICE(obj));
memory_region_add_subregion(m, addr, &tpmppi->ram);
}
+3 -7
View File
@@ -20,17 +20,13 @@ typedef struct TPMPPI {
} TPMPPI;
/**
* tpm_ppi_init:
* tpm_ppi_init_memory:
* @tpmppi: a TPMPPI
* @m: the address-space / MemoryRegion to use
* @addr: the address of the PPI region
* @obj: the owner object
*
* Register the TPM PPI memory region at @addr on the given address
* space for the object @obj.
* Creates the TPM PPI memory region.
**/
void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
hwaddr addr, Object *obj);
void tpm_ppi_init_memory(TPMPPI *tpmppi, Object *obj);
/**
* tpm_ppi_reset:
+3 -2
View File
@@ -134,8 +134,9 @@ static void tpm_tis_isa_realizefn(DeviceState *dev, Error **errp)
TPM_TIS_ADDR_BASE, &s->mmio);
if (s->ppi_enabled) {
tpm_ppi_init(&s->ppi, isa_address_space(ISA_DEVICE(dev)),
TPM_PPI_ADDR_BASE, OBJECT(dev));
tpm_ppi_init_memory(&s->ppi, OBJECT(dev));
memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)),
TPM_PPI_ADDR_BASE, &s->ppi.ram);
}
}
+37
View File
@@ -30,6 +30,7 @@
#include "hw/sysbus.h"
#include "tpm_tis.h"
#include "qom/object.h"
#include "hw/acpi/acpi_aml_interface.h"
struct TPMStateSysBus {
/*< private >*/
@@ -37,6 +38,8 @@ struct TPMStateSysBus {
/*< public >*/
TPMState state; /* not a QOM object */
uint64_t baseaddr;
uint64_t size;
};
OBJECT_DECLARE_SIMPLE_TYPE(TPMStateSysBus, TPM_TIS_SYSBUS)
@@ -93,6 +96,10 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)
static Property tpm_tis_sysbus_properties[] = {
DEFINE_PROP_UINT32("irq", TPMStateSysBus, state.irq_num, TPM_TIS_IRQ),
DEFINE_PROP_TPMBE("tpmdev", TPMStateSysBus, state.be_driver),
DEFINE_PROP_UINT64("x-baseaddr", TPMStateSysBus, baseaddr,
TPM_TIS_ADDR_BASE),
DEFINE_PROP_UINT64("x-size", TPMStateSysBus, size,
TPM_TIS_ADDR_SIZE),
DEFINE_PROP_END_OF_LIST(),
};
@@ -125,10 +132,38 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)
}
}
static void build_tpm_tis_sysbus_aml(AcpiDevAmlIf *adev, Aml *scope)
{
Aml *dev, *crs;
TPMStateSysBus *sbdev = TPM_TIS_SYSBUS(adev);
TPMIf *ti = TPM_IF(sbdev);
dev = aml_device("TPM");
if (tpm_tis_sysbus_get_tpm_version(ti) == TPM_VERSION_2_0) {
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
} else {
aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31")));
}
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
crs = aml_resource_template();
aml_append(crs, aml_memory32_fixed(sbdev->baseaddr, sbdev->size,
AML_READ_WRITE));
/*
* FIXME: TPM_TIS_IRQ=5 conflicts with PNP0C0F irqs,
* fix default TPM_TIS_IRQ value there to use some unused IRQ
*/
/* aml_append(crs, aml_irq_no_flags(sbdev->state.irq_num)); */
aml_append(dev, aml_name_decl("_CRS", crs));
aml_append(scope, dev);
}
static void tpm_tis_sysbus_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
TPMIfClass *tc = TPM_IF_CLASS(klass);
AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
device_class_set_props(dc, tpm_tis_sysbus_properties);
dc->vmsd = &vmstate_tpm_tis_sysbus;
@@ -139,6 +174,7 @@ static void tpm_tis_sysbus_class_init(ObjectClass *klass, void *data)
tc->request_completed = tpm_tis_sysbus_request_completed;
tc->get_version = tpm_tis_sysbus_get_tpm_version;
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
adevc->build_dev_aml = build_tpm_tis_sysbus_aml;
}
static const TypeInfo tpm_tis_sysbus_info = {
@@ -149,6 +185,7 @@ static const TypeInfo tpm_tis_sysbus_info = {
.class_init = tpm_tis_sysbus_class_init,
.interfaces = (InterfaceInfo[]) {
{ TYPE_TPM_IF },
{ TYPE_ACPI_DEV_AML_IF },
{ }
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
# See docs/devel/tracing.rst for syntax documentation.
# tpm_crb.c
# tpm_crb_common.c
tpm_crb_mmio_read(uint64_t addr, unsigned size, uint32_t val) "CRB read 0x%016" PRIx64 " len:%u val: 0x%" PRIx32
tpm_crb_mmio_write(uint64_t addr, unsigned size, uint32_t val) "CRB write 0x%016" PRIx64 " len:%u val: 0x%" PRIx32
+2 -1
View File
@@ -1280,7 +1280,8 @@ static void usbredir_create_parser(USBRedirDevice *dev)
}
#endif
if (runstate_check(RUN_STATE_INMIGRATE)) {
if (runstate_check(RUN_STATE_INMIGRATE) ||
runstate_check(RUN_STATE_RESTORE_VM)) {
flags |= usbredirparser_fl_no_hello;
}
usbredirparser_init(dev->parser, VERSION, caps, USB_REDIR_CAPS_SIZE,
+1
View File
@@ -416,6 +416,7 @@ typedef struct disassemble_info {
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);
int print_insn_tci(bfd_vma, disassemble_info*);
int print_insn_tcti(bfd_vma, disassemble_info*);
int print_insn_big_mips (bfd_vma, disassemble_info*);
int print_insn_little_mips (bfd_vma, disassemble_info*);
int print_insn_nanomips (bfd_vma, disassemble_info*);
+4
View File
@@ -457,7 +457,11 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
#if defined(CONFIG_TCG_INTERPRETER)
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
extern __thread uintptr_t tcti_call_return_address;
# define GETPC() tcti_call_return_address
#else
/* Note that this is correct for TCTI also; whose gadget behaves like native code. */
# define GETPC() \
((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
#endif
+2 -1
View File
@@ -174,7 +174,8 @@ REG32(CRB_CTRL_CMD_SIZE, 0x58)
REG32(CRB_CTRL_CMD_LADDR, 0x5C)
REG32(CRB_CTRL_CMD_HADDR, 0x60)
REG32(CRB_CTRL_RSP_SIZE, 0x64)
REG32(CRB_CTRL_RSP_ADDR, 0x68)
REG32(CRB_CTRL_RSP_LADDR, 0x68)
REG32(CRB_CTRL_RSP_HADDR, 0x6C)
REG32(CRB_DATA_BUFFER, 0x80)
#define TPM_CRB_ADDR_BASE 0xFED40000
+69
View File
@@ -0,0 +1,69 @@
/*
* QEMU PowerMac Awacs Screamer device support
*
* Copyright (c) 2016 Mark Cave-Ayland
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef HW_AUDIO_SCREAMER_H
#define HW_AUDIO_SCREAMER_H
#include "qemu/osdep.h"
#include "hw/sysbus.h"
#include "hw/ppc/mac_dbdma.h"
#include "audio/audio.h"
#define TYPE_SCREAMER "screamer"
OBJECT_DECLARE_SIMPLE_TYPE(ScreamerState, SCREAMER)
#define SCREAMER_BUFFER_SIZE 0x4000
struct ScreamerState {
/*< private >*/
SysBusDevice parent_obj;
/*< public >*/
MemoryRegion mem;
qemu_irq irq;
void *dbdma;
qemu_irq dma_tx_irq;
qemu_irq dma_rx_irq;
QEMUSoundCard card;
SWVoiceOut *voice;
uint8_t *mixbuf;
int samples;
int shift;
uint32_t wpos;
uint32_t rpos;
uint32_t bpos;
uint32_t ppos;
uint32_t rate;
DBDMA_io io;
uint32_t regs[6];
uint32_t codec_ctrl_regs[8];
};
void macio_screamer_register_dma(ScreamerState *s, void *dbdma, int txchannel, int rxchannel);
#endif
+1
View File
@@ -66,6 +66,7 @@ struct GICv3ITSState {
int dev_fd; /* kvm device fd if backed by kvm vgic support */
uint64_t gits_translater_gpa;
bool translater_gpa_known;
uint8_t itt_entry_size;
/* Registers */
uint32_t ctlr;
+9
View File
@@ -36,6 +36,7 @@
#include "hw/nvram/mac_nvram.h"
#include "hw/ppc/mac_dbdma.h"
#include "hw/ppc/openpic.h"
#include "hw/audio/screamer.h"
#include "qom/object.h"
/* Old World IRQs */
@@ -46,6 +47,9 @@
#define OLDWORLD_IDE0_DMA_IRQ 0x2
#define OLDWORLD_IDE1_IRQ 0xe
#define OLDWORLD_IDE1_DMA_IRQ 0x3
#define OLDWORLD_SCREAMER_TX_IRQ 0x11
#define OLDWORLD_SCREAMER_TX_DMA_IRQ 0x08
#define OLDWORLD_SCREAMER_RX_IRQ 0x09
/* New World IRQs */
#define NEWWORLD_CUDA_IRQ 0x19
@@ -58,6 +62,9 @@
#define NEWWORLD_IDE1_DMA_IRQ 0x3
#define NEWWORLD_EXTING_GPIO1 0x2f
#define NEWWORLD_EXTING_GPIO9 0x37
#define NEWWORLD_SCREAMER_IRQ 0x18
#define NEWWORLD_SCREAMER_DMA_IRQ 0x09
#define NEWWORLD_SCREAMER_RX_IRQ 0x0a
/* MacIO virtual bus */
#define TYPE_MACIO_BUS "macio-bus"
@@ -112,6 +119,7 @@ struct MacIOState {
PMUState pmu;
DBDMAState dbdma;
ESCCState escc;
ScreamerState screamer;
uint64_t frequency;
};
@@ -140,6 +148,7 @@ struct NewWorldMacIOState {
bool has_pmu;
bool has_adb;
OpenPICState pic;
MACIOIDEState ide[2];
MacIOGPIOState gpio;
};
+1 -20
View File
@@ -793,29 +793,10 @@ int qemu_msync(void *addr, size_t length, int fd);
*/
size_t qemu_get_host_physmem(void);
/*
* Toggle write/execute on the pages marked MAP_JIT
* for the current thread.
*/
#ifdef __APPLE__
static inline void qemu_thread_jit_execute(void)
{
pthread_jit_write_protect_np(true);
}
static inline void qemu_thread_jit_write(void)
{
pthread_jit_write_protect_np(false);
}
#else
static inline void qemu_thread_jit_write(void) {}
static inline void qemu_thread_jit_execute(void) {}
#endif
/**
* Platforms which do not support system() return ENOSYS
*/
#ifndef HAVE_SYSTEM_FUNCTION
#if !defined(HAVE_SYSTEM_FUNCTION) || defined(CONFIG_IOS)
#define system platform_does_not_support_system
static inline int platform_does_not_support_system(const char *command)
{
+13
View File
@@ -19,6 +19,17 @@ typedef hv_vcpu_t hvf_vcpuid;
typedef hv_vcpuid_t hvf_vcpuid;
#endif
#if defined(CONFIG_HVF_PRIVATE)
extern hv_return_t _hv_vm_config_set_isa(hv_vm_config_t config, uint32_t isa);
extern hv_return_t _hv_vcpu_get_actlr(hv_vcpu_t vcpu, uint64_t* value);
extern hv_return_t _hv_vcpu_set_actlr(hv_vcpu_t vcpu, uint64_t value);
#endif
#if defined(__aarch64__)
#define HV_VM_CONFIG_ISA_PRIVATE (3)
#define ACTLR_EL1_TSO_ENABLE_MASK ((1 << 1) | (1 << 9))
#endif
/* hvf_slot flags */
#define HVF_SLOT_LOG (1 << 0)
@@ -50,6 +61,7 @@ struct HVFState {
QTAILQ_HEAD(, hvf_sw_breakpoint) hvf_sw_breakpoints;
};
extern HVFState *hvf_state;
extern bool hvf_tso_mode;
struct AccelCPUState {
hvf_vcpuid fd;
@@ -63,6 +75,7 @@ struct AccelCPUState {
void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
const char *exp);
#define assert_hvf_ok(EX) assert_hvf_ok_impl((EX), __FILE__, __LINE__, #EX)
hv_return_t hvf_arch_vm_create(void);
const char *hvf_return_string(hv_return_t ret);
int hvf_arch_init(void);
int hvf_arch_init_vcpu(CPUState *cpu);
+7
View File
@@ -12,6 +12,8 @@
#ifndef QEMU_TPM_H
#define QEMU_TPM_H
#include "qemu/osdep.h"
#include "exec/hwaddr.h"
#include "qapi/qapi-types-tpm.h"
#include "qom/object.h"
@@ -47,6 +49,7 @@ struct TPMIfClass {
#define TYPE_TPM_TIS_ISA "tpm-tis"
#define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"
#define TYPE_TPM_CRB "tpm-crb"
#define TYPE_TPM_CRB_SYSBUS "tpm-crb-device"
#define TYPE_TPM_SPAPR "tpm-spapr"
#define TYPE_TPM_TIS_I2C "tpm-tis-i2c"
@@ -56,6 +59,8 @@ struct TPMIfClass {
object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
#define TPM_IS_CRB(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
#define TPM_IS_CRB_SYSBUS(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB_SYSBUS)
#define TPM_IS_SPAPR(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)
#define TPM_IS_TIS_I2C(chr) \
@@ -78,6 +83,8 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
return TPM_IF_GET_CLASS(ti)->get_version(ti);
}
void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
#else /* CONFIG_TPM */
#define tpm_init() (0)
+100
View File
@@ -0,0 +1,100 @@
/*
* Apple Silicon functions for JIT handling
*
* Copyright (c) 2020 osy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TCG_APPLE_JIT_H
#define TCG_APPLE_JIT_H
/*
* APRR handling
* Credits to: https://siguza.github.io/APRR/
* Reversed from /usr/lib/system/libsystem_pthread.dylib
*/
#if defined(__aarch64__) && defined(CONFIG_DARWIN)
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
return aprr_support > 0;
}
/* write protect enable = write disable */
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
/* Access shared kernel page at fixed memory location. */
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
if (aprr_support == 0 || aprr_support > 3) {
return;
} else if (aprr_support == 1) {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_4_c15_c2_7, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
} else {
__asm__ __volatile__ (
"mov x0, %0\n"
"ldr x0, [x0]\n"
"msr S3_6_c15_c1_5, x0\n"
"isb sy\n"
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
: _COMM_PAGE_APPR_WRITE_ENABLE)
: "memory", "x0"
);
}
}
#else /* defined(__aarch64__) && defined(CONFIG_DARWIN) */
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
{
return false;
}
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
{
}
#endif
static inline void qemu_thread_jit_execute(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(true);
}
}
static inline void qemu_thread_jit_write(void)
{
if (jit_write_protect_supported()) {
jit_write_protect(false);
}
}
#endif /* define TCG_APPLE_JIT_H */
+12
View File
@@ -47,7 +47,11 @@ DEF(mb, 0, 0, 1, 0)
DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT)
DEF(setcond_i32, 1, 2, 1, 0)
DEF(negsetcond_i32, 1, 2, 1, IMPL(TCG_TARGET_HAS_negsetcond_i32))
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
DEF(movcond_i32, 1, 4, 1, TCG_OPF_NOT_PRESENT)
#else
DEF(movcond_i32, 1, 4, 1, 0)
#endif
/* load/store */
DEF(ld8u_i32, 1, 1, 1, 0)
DEF(ld8s_i32, 1, 1, 1, 0)
@@ -113,7 +117,11 @@ DEF(ctpop_i32, 1, 1, 0, IMPL(TCG_TARGET_HAS_ctpop_i32))
DEF(mov_i64, 1, 1, 0, TCG_OPF_64BIT | TCG_OPF_NOT_PRESENT)
DEF(setcond_i64, 1, 2, 1, IMPL64)
DEF(negsetcond_i64, 1, 2, 1, IMPL64 | IMPL(TCG_TARGET_HAS_negsetcond_i64))
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
DEF(movcond_i64, 1, 4, 1, IMPL64 | TCG_OPF_NOT_PRESENT)
#else
DEF(movcond_i64, 1, 4, 1, IMPL64)
#endif
/* load/store */
DEF(ld8u_i64, 1, 1, 1, IMPL64)
DEF(ld8s_i64, 1, 1, 1, IMPL64)
@@ -195,7 +203,11 @@ DEF(insn_start, 0, 0, DATA64_ARGS, TCG_OPF_NOT_PRESENT)
DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#if defined(CONFIG_TCG_THREADED_INTERPRETER)
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END | TCG_OPF_NOT_PRESENT)
#else
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
#endif
DEF(plugin_cb, 0, 0, 1, TCG_OPF_NOT_PRESENT)
DEF(plugin_mem_cb, 0, 1, 1, TCG_OPF_NOT_PRESENT)
+1 -1
View File
@@ -1024,7 +1024,7 @@ static inline size_t tcg_current_code_size(TCGContext *s)
#define TB_EXIT_IDXMAX 1
#define TB_EXIT_REQUESTED 3
#ifdef CONFIG_TCG_INTERPRETER
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
+11 -14
View File
@@ -133,16 +133,18 @@ struct QemuConsoleClass {
ObjectClass parent_class;
};
typedef uint32_t (* DisplayGLTextureBorrower)(uint32_t id, bool *y_0_top,
uint32_t *width,
uint32_t *height,
void **d3d_tex2d);
typedef struct ScanoutTexture {
uint32_t backing_id;
bool backing_y_0_top;
uint32_t backing_width;
uint32_t backing_height;
DisplayGLTextureBorrower backing_borrow;
uint32_t x;
uint32_t y;
uint32_t width;
uint32_t height;
void *d3d_tex2d;
} ScanoutTexture;
typedef struct QemuUIInfo {
@@ -243,12 +245,9 @@ typedef struct DisplayChangeListenerOps {
/* required if GL */
void (*dpy_gl_scanout_texture)(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h,
void *d3d_tex2d);
uint32_t w, uint32_t h);
/* optional (default to true if has dpy_gl_scanout_dmabuf) */
bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
/* optional */
@@ -328,11 +327,9 @@ bool dpy_gfx_check_format(QemuConsole *con,
pixman_format_code_t format);
void dpy_gl_scanout_disable(QemuConsole *con);
void dpy_gl_scanout_texture(QemuConsole *con,
uint32_t backing_id, bool backing_y_0_top,
uint32_t backing_width, uint32_t backing_height,
uint32_t x, uint32_t y, uint32_t w, uint32_t h,
void *d3d_tex2d);
void dpy_gl_scanout_texture(QemuConsole *con, uint32_t backing_id,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
void dpy_gl_scanout_dmabuf(QemuConsole *con,
QemuDmaBuf *dmabuf);
void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
+18 -2
View File
@@ -6,6 +6,9 @@
#ifdef CONFIG_GBM
#include <gbm.h>
#endif
#ifdef CONFIG_ANGLE
#include <EGL/eglext_angle.h>
#endif
#include "ui/console.h"
#include "ui/shader.h"
@@ -18,6 +21,7 @@ typedef struct egl_fb {
int width;
int height;
GLuint texture;
GLenum texture_target;
GLuint framebuffer;
bool delete_texture;
QemuDmaBuf *dmabuf;
@@ -27,16 +31,19 @@ typedef struct egl_fb {
void egl_fb_destroy(egl_fb *fb);
void egl_fb_setup_default(egl_fb *fb, int width, int height);
void egl_fb_setup_for_tex_target(egl_fb *fb, int width, int height,
GLuint texture, GLenum target, bool delete);
void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
GLuint texture, bool delete);
void egl_fb_setup_new_tex_target(egl_fb *fb, int width, int height, GLenum target);
void egl_fb_setup_new_tex(egl_fb *fb, int width, int height);
void egl_fb_blit(egl_fb *dst, egl_fb *src, bool flip);
void egl_fb_read(DisplaySurface *dst, egl_fb *src);
void egl_fb_read_rect(DisplaySurface *dst, egl_fb *src, int x, int y, int w, int h);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip);
void egl_texture_blit(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip, bool swap);
void egl_texture_blend(QemuGLShader *gls, egl_fb *dst, egl_fb *src, bool flip,
int x, int y, double scale_x, double scale_y);
bool swap, int x, int y, double scale_x, double scale_y);
extern EGLContext qemu_egl_rn_ctx;
@@ -57,6 +64,11 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
#endif
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
EGLSurface qemu_egl_init_buffer_surface(EGLContext ectx, EGLenum buftype,
EGLClientBuffer buffer, const EGLint *attrib_list);
bool qemu_egl_destroy_surface(EGLSurface surface);
int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode);
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
@@ -69,6 +81,10 @@ int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode);
int qemu_egl_init_dpy_win32(EGLNativeDisplayType dpy, DisplayGLMode mode);
#endif
#if defined(CONFIG_ANGLE)
int qemu_egl_init_dpy_angle(DisplayGLMode mode);
#endif
EGLContext qemu_egl_init_ctx(void);
bool qemu_egl_has_dmabuf(void);
+4 -10
View File
@@ -171,12 +171,9 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
void gd_egl_scanout_disable(DisplayChangeListener *dcl);
void gd_egl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h,
void *d3d_tex2d);
uint32_t w, uint32_t h);
void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf);
void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
@@ -208,12 +205,9 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf);
void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h,
void *d3d_tex2d);
uint32_t w, uint32_t h);
void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
+2 -5
View File
@@ -86,12 +86,9 @@ int sdl2_gl_make_context_current(DisplayGLCtx *dgc,
void sdl2_gl_scanout_disable(DisplayChangeListener *dcl);
void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
uint32_t backing_id,
bool backing_y_0_top,
uint32_t backing_width,
uint32_t backing_height,
DisplayGLTextureBorrower backing_borrow,
uint32_t x, uint32_t y,
uint32_t w, uint32_t h,
void *d3d_tex2d);
uint32_t w, uint32_t h);
void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
+1 -1
View File
@@ -5,7 +5,7 @@
typedef struct QemuGLShader QemuGLShader;
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip);
void qemu_gl_run_texture_blit(QemuGLShader *gls, bool flip, bool swapped);
QemuGLShader *qemu_gl_init_shader(void);
void qemu_gl_fini_shader(QemuGLShader *gls);
+18 -1
View File
@@ -27,7 +27,12 @@
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM)
#if defined(CONFIG_IOSURFACE)
#include <CoreFoundation/CoreFoundation.h>
#include <IOSurface/IOSurfaceRef.h>
#endif
#if defined(CONFIG_OPENGL)
# define HAVE_SPICE_GL 1
# include "ui/egl-helpers.h"
# include "ui/egl-context.h"
@@ -125,8 +130,20 @@ struct SimpleSpiceDisplay {
bool have_scanout;
bool have_surface;
#if defined(CONFIG_GBM)
QemuDmaBuf *guest_dmabuf;
bool guest_dmabuf_refresh;
#endif
#if defined(CONFIG_IOSURFACE)
IOSurfaceRef iosurface;
int surface_send_fd;
#endif
#if defined(CONFIG_ANGLE)
EGLSurface esurface;
egl_fb iosurface_fb;
DisplayGLTextureBorrower backing_borrow;
uint32_t backing_id;
#endif
bool render_cursor;
egl_fb guest_fb;
+1
View File
@@ -22,6 +22,7 @@ typedef struct DisplaySurface {
GLenum glformat;
GLenum gltype;
GLuint texture;
bool glswapped;
#endif
#ifdef WIN32
HANDLE handle;
+75 -6
View File
@@ -47,6 +47,7 @@ bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
tcti_supported_cpus = ['aarch64']
cpu = host_machine.cpu_family()
@@ -438,6 +439,12 @@ ucontext_probe = '''
# For POSIX prefer ucontext, but it's not always possible. The fallback
# is sigcontext.
supported_backends = []
ucontext = dependency('libucontext', required : false)
if ucontext.found() or get_option('ucontext').enabled()
supported_backends += ['libucontext']
endif
if host_os == 'windows'
supported_backends += ['windows']
else
@@ -454,6 +461,10 @@ elif coroutine_backend not in supported_backends
.format(coroutine_backend, ', '.join(supported_backends)))
endif
if coroutine_backend == 'libucontext'
coroutine_backend = 'ucontext'
endif
# Compiles if SafeStack *not* enabled
safe_stack_probe = '''
int main(void)
@@ -727,6 +738,7 @@ socket = []
version_res = []
coref = []
iokit = []
iosurface = not_found
emulator_link_args = []
midl = not_found
widl = not_found
@@ -747,6 +759,7 @@ if host_os == 'windows'
elif host_os == 'darwin'
coref = dependency('appleframeworks', modules: 'CoreFoundation')
iokit = dependency('appleframeworks', modules: 'IOKit', required: false)
iosurface = dependency('appleframeworks', modules: 'IOSurface', required: false)
host_dsosuf = '.dylib'
elif host_os == 'sunos'
socket = [cc.find_library('socket'),
@@ -763,6 +776,13 @@ elif host_os == 'openbsd'
endif
endif
if not ucontext.found() and get_option('ucontext').enabled()
libucontext_proj = subproject('libucontext',
default_options: ['default_library=static',
'freestanding=true'])
ucontext = libucontext_proj.get_variable('libucontext_dep')
endif
###############################################
# Host-specific configuration of accelerators #
###############################################
@@ -813,6 +833,13 @@ if get_option('tcg').allowed()
endif
if get_option('tcg_interpreter')
tcg_arch = 'tci'
elif get_option('tcg_threaded_interpreter')
if cpu not in tcti_supported_cpus
error('Unsupported CPU @0@ for TCTI, try --enable-tcg-interpreter'.format(cpu))
else
warning('TCTI is extremely experimental and incomplete! Things might break!')
tcg_arch = '@0@-tcti'.format(cpu)
endif
elif host_arch == 'x86_64'
tcg_arch = 'i386'
elif host_arch == 'ppc64'
@@ -2284,6 +2311,10 @@ if get_option('kvm').allowed() and host_os == 'linux'
endif
config_host_data.set('CONFIG_KVM_TARGETS', kvm_targets_c)
if get_option('hvf').allowed() and hvf.found()
config_host_data.set('CONFIG_HVF_PRIVATE', get_option('hvf_private'))
endif
if get_option('module_upgrades') and not enable_modules
error('Cannot enable module-upgrades as modules are not enabled')
endif
@@ -2362,11 +2393,13 @@ if seccomp.found()
endif
config_host_data.set('CONFIG_PIXMAN', pixman.found())
config_host_data.set('CONFIG_SLIRP', slirp.found())
config_host_data.set('CONFIG_LIBUCONTEXT', ucontext.found())
config_host_data.set('CONFIG_SNAPPY', snappy.found())
config_host_data.set('CONFIG_SOLARIS', host_os == 'sunos')
if get_option('tcg').allowed()
config_host_data.set('CONFIG_TCG', 1)
config_host_data.set('CONFIG_TCG_INTERPRETER', tcg_arch == 'tci')
config_host_data.set('CONFIG_TCG_THREADED_INTERPRETER', tcg_arch.endswith('tcti'))
endif
config_host_data.set('CONFIG_TPM', have_tpm)
config_host_data.set('CONFIG_TSAN', get_option('tsan'))
@@ -2424,6 +2457,7 @@ config_host_data.set('CONFIG_SPICE', spice.found())
config_host_data.set('CONFIG_X11', x11.found())
config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display)
config_host_data.set('CONFIG_CFI', get_option('cfi'))
config_host_data.set('CONFIG_IOSURFACE', iosurface.found())
config_host_data.set('CONFIG_SELINUX', selinux.found())
config_host_data.set('CONFIG_XEN_BACKEND', xen.found())
config_host_data.set('CONFIG_LIBDW', libdw.found())
@@ -2439,6 +2473,7 @@ config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
config_host_data.set('QEMU_VERSION_MICRO', meson.project_version().split('.')[2])
config_host_data.set('CONFIG_SHARED_LIBRARY_BUILD', get_option('shared_lib'))
config_host_data.set_quoted('CONFIG_HOST_DSOSUF', host_dsosuf)
config_host_data.set('HAVE_HOST_BLOCK_DEVICE', have_host_block_device)
@@ -2469,6 +2504,7 @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h'))
config_host_data.set('HAVE_SYS_DISK_H', cc.has_header('sys/disk.h'))
config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h'))
config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h'))
config_host_data.set('CONFIG_ANGLE', cc.has_header('EGL/eglext_angle.h'))
if host_os == 'windows'
config_host_data.set('HAVE_AFUNIX_H', cc.has_header('afunix.h'))
endif
@@ -3535,7 +3571,7 @@ util_ss = util_ss.apply({})
libqemuutil = static_library('qemuutil',
build_by_default: false,
sources: util_ss.sources() + stub_ss.sources() + genh,
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc])
dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, ucontext])
qemuutil = declare_dependency(link_with: libqemuutil,
sources: genh + version_res,
dependencies: [event_loop_base])
@@ -3962,13 +3998,30 @@ foreach target : target_dirs
lib_deps += dep.partial_dependency(compile_args: true, includes: true)
endforeach
lib = static_library('qemu-' + target,
if get_option('shared_lib')
build_lib_args = {
'target_type': 'shared_library',
'install': true,
'dependencies': arch_deps,
'link_depends': [block_syms, qemu_syms],
'link_args': link_args,
'gnu_symbol_visibility': 'default'
}
else
build_lib_args = {
'target_type': 'static_library',
'install': false,
'dependencies': lib_deps
}
endif
lib = build_target('qemu-' + target,
sources: arch_srcs + genh,
dependencies: lib_deps,
objects: objects,
include_directories: target_inc,
c_args: c_args,
build_by_default: false)
build_by_default: false,
kwargs: build_lib_args)
if target.endswith('-softmmu')
execs = [{
@@ -4008,11 +4061,19 @@ foreach target : target_dirs
exe_name += '-unsigned'
endif
if get_option('shared_lib')
exe_deps = [declare_dependency(link_with: lib)]
exe_objs = []
else
exe_deps = arch_deps
exe_objs = lib.extract_all_objects(recursive: true)
endif
emulator = executable(exe_name, exe['sources'],
install: true,
c_args: c_args,
dependencies: arch_deps + exe['dependencies'],
objects: lib.extract_all_objects(recursive: true),
dependencies: exe_deps + exe['dependencies'],
objects: exe_objs,
link_depends: [block_syms, qemu_syms],
link_args: link_args,
win_subsystem: exe['win_subsystem'])
@@ -4073,6 +4134,10 @@ if xkbcommon.found()
endif
if have_tools
if get_option('shared_lib')
qemu_img_lib = shared_library('qemu-img', [files('qemu-img.c'), hxdep],
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
endif
qemu_img = executable('qemu-img', [files('qemu-img.c'), hxdep],
link_args: '@block.syms', link_depends: block_syms,
dependencies: [authz, block, crypto, io, qom, qemuutil], install: true)
@@ -4225,6 +4290,7 @@ summary(summary_info, bool_yn: true, section: 'Directories')
# Host binaries
summary_info = {}
summary_info += {'build shared lib': get_option('shared_lib')}
summary_info += {'python': '@0@ (version: @1@)'.format(python.full_path(), python.language_version())}
summary_info += {'sphinx-build': sphinx_build}
@@ -4371,6 +4437,8 @@ summary_info += {'TCG support': config_all_accel.has_key('CONFIG_TCG')}
if config_all_accel.has_key('CONFIG_TCG')
if get_option('tcg_interpreter')
summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, slow)'}
elif get_option('tcg_threaded_interpreter')
summary_info += {'TCG backend': 'TCTI (TCG with threaded-dispatch bytecode interpreter, experimental and slow; but faster than TCI)'}
else
summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
endif
@@ -4390,6 +4458,7 @@ summary(summary_info, bool_yn: true, section: 'Targets and accelerators')
# Block layer
summary_info = {}
summary_info += {'libucontext support': ucontext.found()}
summary_info += {'coroutine backend': coroutine_backend}
summary_info += {'coroutine pool': have_coroutine_pool}
if have_block
+9 -1
View File
@@ -32,7 +32,7 @@ option('fuzzing_engine', type : 'string', value : '',
option('trace_file', type: 'string', value: 'trace',
description: 'Trace file prefix for simple backend')
option('coroutine_backend', type: 'combo',
choices: ['ucontext', 'sigaltstack', 'windows', 'auto'],
choices: ['libucontext', 'ucontext', 'sigaltstack', 'windows', 'auto'],
value: 'auto', description: 'coroutine backend to use')
# Everything else can be set via --enable/--disable-* option
@@ -61,6 +61,8 @@ option('tools', type : 'feature', value : 'auto',
description: 'build support utilities that come with QEMU')
option('qga_vss', type : 'feature', value: 'auto',
description: 'build QGA VSS support (broken with MinGW)')
option('shared_lib', type: 'boolean', value: false,
description: 'Build QEMU as a shared library')
option('malloc_trim', type : 'feature', value : 'auto',
description: 'enable libc malloc_trim() for memory optimization')
@@ -73,6 +75,8 @@ option('whpx', type: 'feature', value: 'auto',
description: 'WHPX acceleration support')
option('hvf', type: 'feature', value: 'auto',
description: 'HVF acceleration support')
option('hvf_private', type: 'boolean', value: 'false',
description: 'HVF private features (entitlements required)')
option('nvmm', type: 'feature', value: 'auto',
description: 'NVMM acceleration support')
option('xen', type: 'feature', value: 'auto',
@@ -89,6 +93,8 @@ option('debug_remap', type: 'boolean', value: false,
description: 'syscall buffer debugging support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (slow)')
option('tcg_threaded_interpreter', type: 'boolean', value: false,
description: 'TCG with threaded-dispatch bytecode interpreter (experimental and slow, but less slow than TCI)')
option('safe_stack', type: 'boolean', value: false,
description: 'SafeStack Stack Smash Protection (requires clang/llvm and coroutine backend ucontext)')
option('sanitizers', type: 'boolean', value: false,
@@ -265,6 +271,8 @@ option('fuse', type: 'feature', value: 'auto',
description: 'FUSE block device export')
option('fuse_lseek', type : 'feature', value : 'auto',
description: 'SEEK_HOLE/SEEK_DATA support for FUSE exports')
option('ucontext', type : 'feature', value : 'disabled',
description: 'libucontext support')
option('trace_backends', type: 'array', value: ['log'],
choices: ['dtrace', 'ftrace', 'log', 'nop', 'simple', 'syslog', 'ust'],
+15 -3
View File
@@ -88,6 +88,16 @@ static bool validate_options(const Netdev *netdev, Error **errp)
return false;
}
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-bridged.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
return true;
}
@@ -106,9 +116,11 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_shared_interface_name_key,
options->ifname);
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
}
return if_desc;
}
+32 -14
View File
@@ -21,12 +21,28 @@
static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host);
QemuUUID net_uuid;
if (options->net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
if (__builtin_available(macOS 11, *)) {
QemuUUID net_uuid;
if (options->net_uuid &&
qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
error_setg(errp, "Invalid UUID provided in 'net-uuid'");
return false;
}
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-host.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
if (options->net_uuid) {
error_setg(errp,
"vmnet-host.net-uuid feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
if ((options->start_address ||
@@ -53,16 +69,18 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_operation_mode_key,
VMNET_HOST_MODE);
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(if_desc,
vmnet_enable_isolation_key,
options->isolated);
QemuUUID net_uuid;
if (options->net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
QemuUUID net_uuid;
if (options->net_uuid) {
qemu_uuid_parse(options->net_uuid, &net_uuid);
xpc_dictionary_set_uuid(if_desc,
vmnet_network_identifier_key,
net_uuid.data);
}
}
if (options->start_address) {
+18 -5
View File
@@ -21,6 +21,17 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared);
if (__builtin_available(macOS 11, *)) {
// clang requires a true branch
} else {
if (options->has_isolated) {
error_setg(errp,
"vmnet-shared.isolated feature is "
"unavailable: outdated vmnet.framework API");
return false;
}
}
if ((options->start_address ||
options->end_address ||
options->subnet_mask) &&
@@ -66,11 +77,13 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
options->subnet_mask);
}
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
if (__builtin_available(macOS 11, *)) {
xpc_dictionary_set_bool(
if_desc,
vmnet_enable_isolation_key,
options->isolated
);
}
return if_desc;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -2,6 +2,7 @@ roms = []
if unpack_edk2_blobs
fds = [
'edk2-aarch64-code.fd',
'edk2-aarch64-secure-code.fd',
'edk2-arm-code.fd',
'edk2-arm-vars.fd',
'edk2-riscv-code.fd',
Binary file not shown.
+17 -3
View File
@@ -37,6 +37,7 @@ meson_options_help() {
printf "%s\n" ' (choices: auto/disabled/enabled/internal/system)'
printf "%s\n" ' --enable-fuzzing build fuzzing targets'
printf "%s\n" ' --enable-gcov Enable coverage tracking.'
printf "%s\n" ' --enable-hvf-private HVF private features (entitlements required)'
printf "%s\n" ' --enable-lto Use link time optimization'
printf "%s\n" ' --enable-malloc=CHOICE choose memory allocator to use [system] (choices:'
printf "%s\n" ' jemalloc/system/tcmalloc)'
@@ -47,8 +48,12 @@ meson_options_help() {
printf "%s\n" ' --enable-safe-stack SafeStack Stack Smash Protection (requires'
printf "%s\n" ' clang/llvm and coroutine backend ucontext)'
printf "%s\n" ' --enable-sanitizers enable default sanitizers'
printf "%s\n" ' --enable-shared-lib Build QEMU as a shared library'
printf "%s\n" ' --enable-strip Strip targets on install'
printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter (slow)'
printf "%s\n" ' --enable-tcg-threaded-interpreter'
printf "%s\n" ' TCG with threaded-dispatch bytecode interpreter'
printf "%s\n" ' (experimental and slow, but less slow than TCI)'
printf "%s\n" ' --enable-trace-backends=CHOICES'
printf "%s\n" ' Set available tracing backends [log] (choices:'
printf "%s\n" ' dtrace/ftrace/log/nop/simple/syslog/ust)'
@@ -62,9 +67,9 @@ meson_options_help() {
printf "%s\n" ' --libdir=VALUE Library directory [system default]'
printf "%s\n" ' --libexecdir=VALUE Library executable directory [libexec]'
printf "%s\n" ' --localedir=VALUE Locale data directory [share/locale]'
printf "%s\n" ' --localstatedir=VALUE Localstate data directory [/var/local]'
printf "%s\n" ' --localstatedir=VALUE Localstate data directory [var]'
printf "%s\n" ' --mandir=VALUE Manual page directory [share/man]'
printf "%s\n" ' --prefix=VALUE Installation prefix [/usr/local]'
printf "%s\n" ' --prefix=VALUE Installation prefix [/opt/homebrew]'
printf "%s\n" ' --qemu-ga-distro=VALUE second path element in qemu-ga registry entries'
printf "%s\n" ' [Linux]'
printf "%s\n" ' --qemu-ga-manufacturer=VALUE'
@@ -76,7 +81,7 @@ meson_options_help() {
printf "%s\n" ' --tls-priority=VALUE Default TLS protocol/cipher priority string'
printf "%s\n" ' [NORMAL]'
printf "%s\n" ' --with-coroutine=CHOICE coroutine backend to use (choices:'
printf "%s\n" ' auto/sigaltstack/ucontext/windows)'
printf "%s\n" ' auto/libucontext/sigaltstack/ucontext/windows)'
printf "%s\n" ' --with-pkgversion=VALUE use specified string as sub-version of the'
printf "%s\n" ' package'
printf "%s\n" ' --with-suffix=VALUE Suffix for QEMU data/modules/config directories'
@@ -189,6 +194,7 @@ meson_options_help() {
printf "%s\n" ' tpm TPM support'
printf "%s\n" ' u2f U2F emulation support'
printf "%s\n" ' uadk UADK Library support'
printf "%s\n" ' ucontext libucontext support'
printf "%s\n" ' usb-redir libusbredir support'
printf "%s\n" ' vde vde network backend support'
printf "%s\n" ' vdi vdi image format support'
@@ -340,6 +346,8 @@ _meson_option_parse() {
--disable-hv-balloon) printf "%s" -Dhv_balloon=disabled ;;
--enable-hvf) printf "%s" -Dhvf=enabled ;;
--disable-hvf) printf "%s" -Dhvf=disabled ;;
--enable-hvf-private) printf "%s" -Dhvf_private=true ;;
--disable-hvf-private) printf "%s" -Dhvf_private=false ;;
--iasl=*) quote_sh "-Diasl=$2" ;;
--enable-iconv) printf "%s" -Diconv=enabled ;;
--disable-iconv) printf "%s" -Diconv=disabled ;;
@@ -466,6 +474,8 @@ _meson_option_parse() {
--disable-seccomp) printf "%s" -Dseccomp=disabled ;;
--enable-selinux) printf "%s" -Dselinux=enabled ;;
--disable-selinux) printf "%s" -Dselinux=disabled ;;
--enable-shared-lib) printf "%s" -Dshared_lib=true ;;
--disable-shared-lib) printf "%s" -Dshared_lib=false ;;
--enable-slirp) printf "%s" -Dslirp=enabled ;;
--disable-slirp) printf "%s" -Dslirp=disabled ;;
--enable-slirp-smbd) printf "%s" -Dslirp_smbd=enabled ;;
@@ -492,6 +502,8 @@ _meson_option_parse() {
--disable-tcg) printf "%s" -Dtcg=disabled ;;
--enable-tcg-interpreter) printf "%s" -Dtcg_interpreter=true ;;
--disable-tcg-interpreter) printf "%s" -Dtcg_interpreter=false ;;
--enable-tcg-threaded-interpreter) printf "%s" -Dtcg_threaded_interpreter=true ;;
--disable-tcg-threaded-interpreter) printf "%s" -Dtcg_threaded_interpreter=false ;;
--tls-priority=*) quote_sh "-Dtls_priority=$2" ;;
--enable-tools) printf "%s" -Dtools=enabled ;;
--disable-tools) printf "%s" -Dtools=disabled ;;
@@ -505,6 +517,8 @@ _meson_option_parse() {
--disable-u2f) printf "%s" -Du2f=disabled ;;
--enable-uadk) printf "%s" -Duadk=enabled ;;
--disable-uadk) printf "%s" -Duadk=disabled ;;
--enable-ucontext) printf "%s" -Ducontext=enabled ;;
--disable-ucontext) printf "%s" -Ducontext=disabled ;;
--enable-usb-redir) printf "%s" -Dusb_redir=enabled ;;
--disable-usb-redir) printf "%s" -Dusb_redir=disabled ;;
--enable-vde) printf "%s" -Dvde=enabled ;;
+3
View File
@@ -0,0 +1,3 @@
[wrap-git]
url = https://github.com/utmapp/libucontext.git
revision = 9b1d8f01a6e99166f9808c79966abe10786de8b6
+14
View File
@@ -38,3 +38,17 @@ system_ss.add(when: 'CONFIG_DEVICE_TREE',
if host_os == 'linux'
system_ss.add(files('async-teardown.c'))
endif
# Export symbols for shared lib build
if get_option('shared_lib')
if host_os == 'darwin'
configure_file(
input: files('qemu.symbols'),
output: 'qemu-ld64.symbols',
capture: true,
command: ['sed', '-ne', 's/^[[:space:]]*\\(qemu_.*\\);/_\\1/p', '@INPUT@'])
emulator_link_args += ['-Wl,-exported_symbols_list,system/qemu-ld64.symbols']
else
emulator_link_args += ['-Xlinker', '--dynamic-list=' + (meson.project_source_root() / 'system/qemu.symbols')]
endif
endif
+5
View File
@@ -0,0 +1,5 @@
{
qemu_init;
qemu_main_loop;
qemu_cleanup;
};
+4
View File
@@ -2758,6 +2758,10 @@ void qemu_init(int argc, char **argv)
bool userconfig = true;
FILE *vmstate_dump_file = NULL;
/* in non-library builds this is done in a constructor */
#ifdef CONFIG_SHARED_LIBRARY_BUILD
rcu_register_thread();
#endif
qemu_add_opts(&qemu_drive_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
qemu_add_drive_opts(&qemu_common_drive_opts);
+103 -1
View File
@@ -37,6 +37,7 @@
#define MDSCR_EL1_SS_SHIFT 0
#define MDSCR_EL1_MDE_SHIFT 15
#define HV_VM_DEFAULT NULL
static const uint16_t dbgbcr_regs[] = {
HV_SYS_REG_DBGBCR0_EL1,
@@ -114,6 +115,8 @@ static const uint16_t dbgwvr_regs[] = {
HV_SYS_REG_DBGWVR15_EL1,
};
#if !defined(CONFIG_HVF_PRIVATE)
static inline int hvf_arm_num_brps(hv_vcpu_config_t config)
{
uint64_t val;
@@ -148,6 +151,8 @@ void hvf_arm_init_debug(void)
g_array_sized_new(true, true, sizeof(HWWatchpoint), max_hw_wps);
}
#endif
#define HVF_SYSREG(crn, crm, op0, op1, op2) \
ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2)
@@ -295,6 +300,8 @@ void hvf_arm_init_debug(void)
#define TMR_CTL_IMASK (1 << 1)
#define TMR_CTL_ISTATUS (1 << 2)
static const bool windows_workaround_enabled = true;
static void hvf_wfi(CPUState *cpu);
typedef struct HVFVTimer {
@@ -904,6 +911,33 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
return r == HV_SUCCESS;
}
static hv_return_t hvf_vcpu_get_actlr(hv_vcpu_t vcpu, uint64_t* value)
{
#if defined(CONFIG_HVF_PRIVATE)
return _hv_vcpu_get_actlr(vcpu, value);
#else
if (__builtin_available(macOS 15, *)) {
return hv_vcpu_get_sys_reg(vcpu, HV_SYS_REG_ACTLR_EL1, value);
} else {
return HV_UNSUPPORTED;
}
#endif
}
static hv_return_t hvf_vcpu_set_actlr(hv_vcpu_t vcpu, uint64_t value)
{
#if defined(CONFIG_HVF_PRIVATE)
return _hv_vcpu_set_actlr(vcpu, value);
#else
if (__builtin_available(macOS 15, *)) {
return hv_vcpu_set_sys_reg(vcpu, HV_SYS_REG_ACTLR_EL1, value);
} else {
return HV_UNSUPPORTED;
}
#endif
}
void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
{
if (!arm_host_cpu_features.dtb_compatible) {
@@ -995,6 +1029,16 @@ int hvf_arch_init_vcpu(CPUState *cpu)
&arm_cpu->isar.id_aa64mmfr0);
assert_hvf_ok(ret);
/* enable TSO mode */
if (hvf_tso_mode) {
uint64_t actlr;
ret = hvf_vcpu_get_actlr(cpu->accel->fd, &actlr);
assert_hvf_ok(ret);
actlr |= ACTLR_EL1_TSO_ENABLE_MASK;
ret = hvf_vcpu_set_actlr(cpu->accel->fd, actlr);
assert_hvf_ok(ret);
}
return 0;
}
@@ -1980,7 +2024,8 @@ int hvf_vcpu_exec(CPUState *cpu)
break;
case EC_AA64_SMC:
cpu_synchronize_state(cpu);
if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) {
if (windows_workaround_enabled ||
arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) {
advance_pc = true;
if (!hvf_handle_psci_call(cpu)) {
@@ -2043,17 +2088,37 @@ static void hvf_vm_state_change(void *opaque, bool running, RunState state)
}
}
hv_return_t hvf_arch_vm_create(void)
{
#if defined(CONFIG_HVF_PRIVATE)
hv_return_t ret;
hv_vm_config_t config = hv_vm_config_create();
if (hvf_tso_mode) {
_hv_vm_config_set_isa(config, HV_VM_CONFIG_ISA_PRIVATE);
}
ret = hv_vm_create(config);
os_release(config);
return ret;
#else
return hv_vm_create(HV_VM_DEFAULT);
#endif
}
int hvf_arch_init(void)
{
hvf_state->vtimer_offset = mach_absolute_time();
vmstate_register(NULL, 0, &vmstate_hvf_vtimer, &vtimer);
qemu_add_vm_change_state_handler(hvf_vm_state_change, &vtimer);
#if !defined(CONFIG_HVF_PRIVATE)
hvf_arm_init_debug();
#endif
return 0;
}
#if !defined(CONFIG_HVF_PRIVATE)
static const uint32_t brk_insn = 0xd4200000;
int hvf_arch_insert_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp)
@@ -2258,3 +2323,40 @@ bool hvf_arch_supports_guest_debug(void)
{
return true;
}
#else
int hvf_arch_insert_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp)
{
return -ENOSYS;
}
int hvf_arch_remove_sw_breakpoint(CPUState *cpu, struct hvf_sw_breakpoint *bp)
{
return -ENOSYS;
}
int hvf_arch_insert_hw_breakpoint(vaddr addr, vaddr len, int type)
{
return -ENOSYS;
}
int hvf_arch_remove_hw_breakpoint(vaddr addr, vaddr len, int type)
{
return -ENOSYS;
}
void hvf_arch_remove_all_hw_breakpoints(void)
{
}
void hvf_arch_update_guest_debug(CPUState *cpu)
{
}
bool hvf_arch_supports_guest_debug(void)
{
return false;
}
#endif
+5
View File
@@ -218,6 +218,11 @@ void hvf_kick_vcpu_thread(CPUState *cpu)
hv_vcpu_interrupt(&cpu->accel->fd, 1);
}
hv_return_t hvf_arch_vm_create(void)
{
return hv_vm_create(HV_VM_DEFAULT);
}
int hvf_arch_init(void)
{
return 0;
File diff suppressed because it is too large. Load diff
+32
View File
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: MIT */
/*
* TCI target-specific constraint sets.
* Copyright (c) 2021 Linaro
*/
/*
* C_On_Im(...) defines a constraint set with <n> outputs and <m> inputs.
* Each operand should be a sequence of constraint letters as defined by
* tcg-target-con-str.h; the constraint combination is inclusive or.
*/
// Simple register functions.
C_O0_I1(r)
C_O0_I2(r, r)
C_O0_I3(r, r, r)
//C_O0_I4(r, r, r, r)
C_O1_I1(r, r)
C_O1_I2(r, r, r)
//C_O1_I4(r, r, r, r, r)
//C_O2_I1(r, r, r)
//C_O2_I2(r, r, r, r)
//C_O2_I4(r, r, r, r, r, r)
// Vector functions.
C_O1_I1(w, w)
C_O1_I1(w, r)
C_O0_I2(w, r)
C_O1_I1(w, wr)
C_O1_I2(w, w, w)
C_O1_I3(w, w, w, w)
C_O1_I2(w, 0, w)
+20
View File
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: MIT */
/*
* Define TCI target-specific operand constraints.
* Copyright (c) 2021 Linaro
*/
/*
* Define constraint letters for register sets:
* REGS(letter, register_mask)
*/
REGS('r', TCG_MASK_GP_REGISTERS)
REGS('w', TCG_MASK_VECTOR_REGISTERS)
/*
* Define constraint letters for constants:
* CONST(letter, TCG_CT_CONST_* bit set)
*/
// Simple 64-bit immediates.
CONST('I', 0xFFFFFFFFFFFFFFFF)
+16
View File
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: MIT */
/*
* Define target-specific register size
* Copyright (c) 2009, 2011 Stefan Weil
*/
#ifndef TCG_TARGET_REG_BITS_H
#define TCG_TARGET_REG_BITS_H
#if UINTPTR_MAX == UINT64_MAX
# define TCG_TARGET_REG_BITS 64
#else
# error Unknown pointer size for tci target
#endif
#endif
File diff suppressed because it is too large. Load diff
+246
View File
@@ -0,0 +1,246 @@
/*
* Tiny Code Generator for QEMU
*
* Copyright (c) 2009, 2011 Stefan Weil
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* This code implements a TCG which does not generate machine code for some
* real target machine but which generates virtual machine code for an
* interpreter. Interpreted pseudo code is slow, but it works on any host.
*
* Some remarks might help in understanding the code:
*
* "target" or "TCG target" is the machine which runs the generated code.
* This is different to the usual meaning in QEMU where "target" is the
* emulated machine. So normally QEMU host is identical to TCG target.
* Here the TCG target is a virtual machine, but this virtual machine must
* use the same word size like the real machine.
* Therefore, we need both 32 and 64 bit virtual machines (interpreter).
*/
#ifndef TCG_TARGET_H
#define TCG_TARGET_H
#define TCG_TARGET_INSN_UNIT_SIZE 1
#define MAX_CODE_GEN_BUFFER_SIZE ((size_t)-1)
// We're an interpreted target; even if we're JIT-compiling to our interpreter's
// weird psuedo-native bytecode. We'll indicate that we're intepreted.
#define TCG_TARGET_INTERPRETER 1
//
// Supported optional scalar instructions.
//
// Divs.
#define TCG_TARGET_HAS_div_i32 1
#define TCG_TARGET_HAS_rem_i32 1
#define TCG_TARGET_HAS_div_i64 1
#define TCG_TARGET_HAS_rem_i64 1
// Extends.
#define TCG_TARGET_HAS_ext8s_i32 1
#define TCG_TARGET_HAS_ext16s_i32 1
#define TCG_TARGET_HAS_ext8u_i32 1
#define TCG_TARGET_HAS_ext16u_i32 1
#define TCG_TARGET_HAS_ext8s_i64 1
#define TCG_TARGET_HAS_ext16s_i64 1
#define TCG_TARGET_HAS_ext32s_i64 1
#define TCG_TARGET_HAS_ext8u_i64 1
#define TCG_TARGET_HAS_ext16u_i64 1
#define TCG_TARGET_HAS_ext32u_i64 1
#define TCG_TARGET_HAS_extr_i64_i32 0
// Register extractions.
#define TCG_TARGET_HAS_extrl_i64_i32 1
#define TCG_TARGET_HAS_extrh_i64_i32 1
// Negations.
#define TCG_TARGET_HAS_not_i32 1
#define TCG_TARGET_HAS_not_i64 1
// Logicals.
#define TCG_TARGET_HAS_andc_i32 1
#define TCG_TARGET_HAS_orc_i32 1
#define TCG_TARGET_HAS_eqv_i32 1
#define TCG_TARGET_HAS_rot_i32 1
#define TCG_TARGET_HAS_negsetcond_i32 0
#define TCG_TARGET_HAS_negsetcond_i64 0
#define TCG_TARGET_HAS_nand_i32 1
#define TCG_TARGET_HAS_nor_i32 1
#define TCG_TARGET_HAS_andc_i64 1
#define TCG_TARGET_HAS_eqv_i64 1
#define TCG_TARGET_HAS_orc_i64 1
#define TCG_TARGET_HAS_rot_i64 1
#define TCG_TARGET_HAS_nor_i64 1
#define TCG_TARGET_HAS_nand_i64 1
// Bitwise operations.
#define TCG_TARGET_HAS_clz_i32 1
#define TCG_TARGET_HAS_ctz_i32 1
#define TCG_TARGET_HAS_clz_i64 1
#define TCG_TARGET_HAS_ctz_i64 1
#define TCG_TARGET_HAS_tst 0
// Swaps.
#define TCG_TARGET_HAS_bswap16_i32 1
#define TCG_TARGET_HAS_bswap32_i32 1
#define TCG_TARGET_HAS_bswap16_i64 1
#define TCG_TARGET_HAS_bswap32_i64 1
#define TCG_TARGET_HAS_bswap64_i64 1
//
// Supported optional vector instructions.
//
#define TCG_TARGET_HAS_v64 1
#define TCG_TARGET_HAS_v128 1
#define TCG_TARGET_HAS_v256 0
#define TCG_TARGET_HAS_andc_vec 1
#define TCG_TARGET_HAS_orc_vec 1
#define TCG_TARGET_HAS_nand_vec 0
#define TCG_TARGET_HAS_nor_vec 0
#define TCG_TARGET_HAS_eqv_vec 0
#define TCG_TARGET_HAS_not_vec 1
#define TCG_TARGET_HAS_neg_vec 1
#define TCG_TARGET_HAS_abs_vec 1
#define TCG_TARGET_HAS_roti_vec 0
#define TCG_TARGET_HAS_rots_vec 0
#define TCG_TARGET_HAS_rotv_vec 0
#define TCG_TARGET_HAS_shi_vec 0
#define TCG_TARGET_HAS_shs_vec 0
#define TCG_TARGET_HAS_shv_vec 1
#define TCG_TARGET_HAS_mul_vec 1
#define TCG_TARGET_HAS_sat_vec 1
#define TCG_TARGET_HAS_minmax_vec 1
#define TCG_TARGET_HAS_bitsel_vec 1
#define TCG_TARGET_HAS_cmpsel_vec 0
#define TCG_TARGET_HAS_tst_vec 0
//
// Unsupported instructions.
//
// There's no direct instruction with which to count the number of ones,
// so we'll leave this implemented as other instructions.
#define TCG_TARGET_HAS_ctpop_i32 0
#define TCG_TARGET_HAS_ctpop_i64 0
// We don't currently support gadgets with more than three arguments,
// so we can't yet create movcond, deposit, or extract gadgets.
#define TCG_TARGET_HAS_deposit_i32 0
#define TCG_TARGET_HAS_deposit_i64 0
#define TCG_TARGET_HAS_extract_i32 0
#define TCG_TARGET_HAS_sextract_i32 0
#define TCG_TARGET_HAS_extract_i64 0
#define TCG_TARGET_HAS_sextract_i64 0
// This operation exists specifically to allow us to provide differing register
// constraints for 8-bit loads and stores. We don't need to do so, so we'll leave
// this unimplemented, as we gain nothing by it.
#define TCG_TARGET_HAS_qemu_st8_i32 0
#define TCG_TARGET_HAS_qemu_ldst_i128 0
// These should always be zero on our 64B platform.
#define TCG_TARGET_HAS_muls2_i64 0
#define TCG_TARGET_HAS_add2_i32 0
#define TCG_TARGET_HAS_sub2_i32 0
#define TCG_TARGET_HAS_mulu2_i32 0
#define TCG_TARGET_HAS_add2_i64 0
#define TCG_TARGET_HAS_sub2_i64 0
#define TCG_TARGET_HAS_mulu2_i64 0
#define TCG_TARGET_HAS_muluh_i64 0
#define TCG_TARGET_HAS_mulsh_i64 0
#define TCG_TARGET_HAS_extract2_i32 0
#define TCG_TARGET_HAS_muls2_i32 0
#define TCG_TARGET_HAS_muluh_i32 0
#define TCG_TARGET_HAS_mulsh_i32 0
#define TCG_TARGET_HAS_extract2_i64 0
//
// Platform metadata.
//
// Number of registers available.
#define TCG_TARGET_NB_REGS 64
// Number of general purpose registers.
#define TCG_TARGET_GP_REGS 16
/* List of registers which are used by TCG. */
typedef enum {
// General purpose registers.
// Note that we name every _host_ register here; but don't
// necessarily use them; that's determined by the allocation order
// and the number of registers setting above. These just give us the ability
// to refer to these by name.
TCG_REG_R0, TCG_REG_R1, TCG_REG_R2, TCG_REG_R3,
TCG_REG_R4, TCG_REG_R5, TCG_REG_R6, TCG_REG_R7,
TCG_REG_R8, TCG_REG_R9, TCG_REG_R10, TCG_REG_R11,
TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15,
TCG_REG_R16, TCG_REG_R17, TCG_REG_R18, TCG_REG_R19,
TCG_REG_R20, TCG_REG_R21, TCG_REG_R22, TCG_REG_R23,
TCG_REG_R24, TCG_REG_R25, TCG_REG_R26, TCG_REG_R27,
TCG_REG_R28, TCG_REG_R29, TCG_REG_R30, TCG_REG_R31,
// Register aliases.
TCG_AREG0 = TCG_REG_R14,
TCG_REG_CALL_STACK = TCG_REG_R15,
// Mask that refers to the GP registers.
TCG_MASK_GP_REGISTERS = 0xFFFFul,
// Vector registers.
TCG_REG_V0 = 32, TCG_REG_V1, TCG_REG_V2, TCG_REG_V3,
TCG_REG_V4, TCG_REG_V5, TCG_REG_V6, TCG_REG_V7,
TCG_REG_V8, TCG_REG_V9, TCG_REG_V10, TCG_REG_V11,
TCG_REG_V12, TCG_REG_V13, TCG_REG_V14, TCG_REG_V15,
TCG_REG_V16, TCG_REG_V17, TCG_REG_V18, TCG_REG_V19,
TCG_REG_V20, TCG_REG_V21, TCG_REG_V22, TCG_REG_V23,
TCG_REG_V24, TCG_REG_V25, TCG_REG_V26, TCG_REG_V27,
TCG_REG_V28, TCG_REG_V29, TCG_REG_V30, TCG_REG_V31,
// Mask that refers to the vector registers.
TCG_MASK_VECTOR_REGISTERS = 0xFFFF000000000000ul,
} TCGReg;
// Specify the shape of the stack our runtime will use.
#define TCG_TARGET_CALL_STACK_OFFSET 0
#define TCG_TARGET_STACK_ALIGN 16
#define TCG_TARGET_CALL_ARG_I32 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_ARG_I64 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_ARG_I128 TCG_CALL_ARG_NORMAL
#define TCG_TARGET_CALL_RET_I128 TCG_CALL_RET_NORMAL
// We're interpreted, so we'll use our own code to run TB_EXEC.
#define HAVE_TCG_QEMU_TB_EXEC
// We'll need to enforce memory ordering with barriers.
#define TCG_TARGET_DEFAULT_MO (0)
void tci_disas(uint8_t opc);
#endif /* TCG_TARGET_H */
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 Linaro
*
* This work is licensed under the terms of the GNU GPL, version 2 or
* (at your option) any later version.
*
* See the COPYING file in the top-level directory for details.
*
* Target-specific opcodes for host vector expansion. These will be
* emitted by tcg_expand_vec_op. For those familiar with GCC internals,
* consider these to be UNSPEC with names.
*/
DEF(aa64_sshl_vec, 1, 2, 0, IMPLVEC)
+1137
View File
File diff suppressed because it is too large. Load diff
+69 -2
View File
@@ -27,11 +27,78 @@ if host_os == 'linux'
tcg_ss.add(files('perf.c'))
endif
if get_option('tcg_threaded_interpreter')
# Tell our compiler how to generate our TCTI gadgets.
gadget_generator = '@0@/tcti-gadget-gen.py'.format(tcg_arch)
tcti_sources = [
'tcti_gadgets.h',
'tcti_misc_gadgets.c',
'tcti_misc_gadgets.h',
'tcti_setcond_gadgets.c',
'tcti_setcond_gadgets.h',
'tcti_brcond_gadgets.c',
'tcti_brcond_gadgets.h',
'tcti_mov_gadgets.c',
'tcti_mov_gadgets.h',
'tcti_load_signed_gadgets.c',
'tcti_load_signed_gadgets.h',
'tcti_load_unsigned_gadgets.c',
'tcti_load_unsigned_gadgets.h',
'tcti_store_gadgets.c',
'tcti_store_gadgets.h',
'tcti_arithmetic_gadgets.c',
'tcti_arithmetic_gadgets.h',
'tcti_logical_gadgets.c',
'tcti_logical_gadgets.h',
'tcti_extension_gadgets.c',
'tcti_extension_gadgets.h',
'tcti_bitwise_gadgets.c',
'tcti_bitwise_gadgets.h',
'tcti_byteswap_gadgets.c',
'tcti_byteswap_gadgets.h',
'tcti_qemu_ld_aligned_signed_le_gadgets.c',
'tcti_qemu_ld_aligned_signed_le_gadgets.h',
'tcti_qemu_ld_unaligned_signed_le_gadgets.c',
'tcti_qemu_ld_unaligned_signed_le_gadgets.h',
'tcti_qemu_ld_slowpath_signed_le_gadgets.c',
'tcti_qemu_ld_slowpath_signed_le_gadgets.h',
'tcti_qemu_ld_aligned_unsigned_le_gadgets.c',
'tcti_qemu_ld_aligned_unsigned_le_gadgets.h',
'tcti_qemu_ld_unaligned_unsigned_le_gadgets.c',
'tcti_qemu_ld_unaligned_unsigned_le_gadgets.h',
'tcti_qemu_ld_slowpath_unsigned_le_gadgets.c',
'tcti_qemu_ld_slowpath_unsigned_le_gadgets.h',
'tcti_qemu_st_aligned_le_gadgets.c',
'tcti_qemu_st_aligned_le_gadgets.h',
'tcti_qemu_st_unaligned_le_gadgets.c',
'tcti_qemu_st_unaligned_le_gadgets.h',
'tcti_qemu_st_slowpath_le_gadgets.c',
'tcti_qemu_st_slowpath_le_gadgets.h',
'tcti_simd_base_gadgets.c',
'tcti_simd_base_gadgets.h',
'tcti_simd_arithmetic_gadgets.c',
'tcti_simd_arithmetic_gadgets.h',
'tcti_simd_logical_gadgets.c',
'tcti_simd_logical_gadgets.h',
'tcti_simd_immediate_gadgets.c',
'tcti_simd_immediate_gadgets.h',
]
tcti_gadgets = custom_target('tcti-gadgets.h',
output: tcti_sources,
input: gadget_generator,
command: [find_program(gadget_generator)],
build_by_default: false,
build_always_stale: false)
tcti_gadgets = declare_dependency(sources: tcti_gadgets)
else
tcti_gadgets = []
endif
tcg_ss = tcg_ss.apply({})
libtcg_user = static_library('tcg_user',
tcg_ss.sources() + genh,
dependencies: tcg_ss.dependencies(),
dependencies: tcg_ss.dependencies() + tcti_gadgets,
c_args: '-DCONFIG_USER_ONLY',
build_by_default: false)
@@ -41,7 +108,7 @@ user_ss.add(tcg_user)
libtcg_system = static_library('tcg_system',
tcg_ss.sources() + genh,
dependencies: tcg_ss.dependencies(),
dependencies: tcg_ss.dependencies() + tcti_gadgets,
c_args: '-DCONFIG_SOFTMMU',
build_by_default: false)
Loaded 100 of 145 files, more files were not shown because too many files have changed in this diff. Show more