1 | Since v1: | 1 | This is a resend of the series: |
---|---|---|---|
2 | |||
3 | https://lore.kernel.org/qemu-devel/20240222222218.2261956-1-gustavo.romero@linaro.org/ | ||
4 | |||
5 | rebased on the current master. The series was sent about 9 months ago and | ||
6 | remains relevant. Besides addressing the longstanding issue: | ||
7 | |||
8 | https://gitlab.com/qemu-project/qemu/-/issues/1134 | ||
9 | |||
10 | it has generated interest in the community at least twice since its last | ||
11 | version, from different contexts: | ||
12 | |||
13 | https://lists.nongnu.org/archive/html/qemu-discuss/2024-05/msg00003.html | ||
14 | https://lists.nongnu.org/archive/html/qemu-devel/2024-09/msg00374.html | ||
15 | |||
16 | This suggests the series is being used out-of-tree in various contexts, such | ||
17 | as experiments with heterogeneous architectures. | ||
18 | |||
19 | But due to the fact it relies on sysbus, which is marked for future removal, | ||
20 | some maintainers objected to accepting the patchset, causing it to be held in | ||
21 | the ML. However, given the ongoing community interest and since currently there | ||
22 | isn't a better way on QEMU than using sysbus for the wiring needs of this | ||
23 | device (e.g. to wire the device to a CPU IRQ input line), I'd kindly like to ask | ||
24 | maintainers to reconsider its acceptance. | ||
25 | |||
26 | I've kept the sysbus wiring part self-contained in patch: | ||
27 | |||
28 | "hw/misc/ivshmem-flat: Allow device to wire itself on sysbus" | ||
29 | |||
30 | and, as I said in the QEMU/KVM Developers Conference call last week I can commit | ||
31 | to updating the API when the time comes to deprecate the sysbus API. | ||
32 | |||
33 | In essence, this patchset introduces a new device, named ivshmem-flat, which is | ||
34 | similar to the current ivshmem device but does not require a PCI bus. | ||
35 | |||
36 | It implements the ivshmem status and control registers as MMRs and the shared | ||
37 | memory as a directly accessible memory region in the VM memory layout. It's | ||
38 | meant to be used on machines like those with Cortex-M MCUs, which usually lack | ||
39 | a PCI bus, e.g., lm3s6965evb and mps2-an385. Additionally, it has the benefit of | ||
40 | requiring a tiny 'device driver,' which is helpful on some RTOSes, like Zephyr, | ||
41 | that run on memory-constrained resource targets. | ||
42 | |||
43 | The patchset includes a QTest for the ivshmem-flat device, which can be run | ||
44 | with: | ||
45 | |||
46 | $ make -C ./build check-qtest-arm -j 32 | ||
47 | |||
48 | provided QEMU was built with support for target "arm-softmmu": | ||
49 | |||
50 | $ ../configure --target-list=arm-softmmu [...] | ||
51 | |||
52 | Nonetheless, it's also possible to experiment with it in two more interesting | ||
53 | ways: | ||
54 | |||
55 | (a) using two Cortex-M VMs running Zephyr; or | ||
56 | (b) using one aarch64 VM running Linux with the ivshmem PCI device and another | ||
57 | arm (Cortex-M) VM running Zephyr with the new ivshmem-flat device. | ||
58 | |||
59 | To experiment with (a), clone this Zephyr repo [0], set the Zephyr build | ||
60 | environment [1], and follow the instructions in the 'ivshmem' sample main.c [2]. | ||
61 | |||
62 | [0] https://github.com/gromero/zephyr/tree/ivshmem | ||
63 | [1] https://docs.zephyrproject.org/latest/develop/getting_started/index.html | ||
64 | [2] https://github.com/gromero/zephyr/commit/73fbd481e352b25ae5483ba5048a2182b90b7f00#diff-16fa1f481a49b995d0d1a62da37b9f33033f5ee477035e73465e7208521ddbe0R9-R70 | ||
65 | [3] https://lore.kernel.org/qemu-devel/20231127052024.435743-1-gustavo.romero@linaro.org/ | ||
66 | |||
67 | To experiment with (b): | ||
68 | |||
69 | $ git clone -b uio_ivshmem --single-branch https://github.com/gromero/linux.git | ||
70 | $ cd linux | ||
71 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/arm64_uio_ivshmem.config -O .config | ||
72 | |||
73 | If in an x86_64 machine, cross compile the kernel, for instance: | ||
74 | |||
75 | $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 36 | ||
76 | |||
77 | Install image in some directory, let's say, in ~/linux: | ||
78 | |||
79 | $ mkdir ~/linux | ||
80 | $ export INSTALL_PATH=~/linux | ||
81 | $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 36 install | ||
82 | |||
83 | or, if you prefer, download the compiled image from: | ||
84 | |||
85 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/vmlinuz-6.6.0-rc1-g28f3f88ee261 | ||
86 | |||
87 | ... and then the rootfs: | ||
88 | |||
89 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/rootfs.qcow2 | ||
90 | |||
91 | Now, build QEMU with this patchset applied: | ||
92 | |||
93 | $ mkdir build && cd build | ||
94 | $ ../configure --target-list=arm-softmmu,aarch64-softmmu | ||
95 | $ make -j 36 | ||
96 | |||
97 | Start the ivshmem server: | ||
98 | |||
99 | $ contrib/ivshmem-server/ivshmem-server -F | ||
100 | |||
101 | Start the aarch64 VM + Linux + ivshmem PCI device: | ||
102 | |||
103 | $ ./qemu-system-aarch64 -kernel ~/linux/vmlinuz-6.6.0-rc1-g28f3f88ee261 -append "root=/dev/vda initrd=/bin/bash console=ttyAMA0,115200" -drive file=~/linux/rootfs.qcow2,media=disk,if=virtio -machine virt-6.2 -nographic -accel tcg -cpu cortex-a57 -m 8192 -netdev bridge,id=hostnet0,br=virbr0,helper=/usr/lib/qemu/qemu-bridge-helper -device pcie-root-port,port=8,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x1 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:d9:d1:12,bus=pci.1,addr=0x0 -device ivshmem-doorbell,vectors=2,chardev=ivshmem -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem | ||
104 | |||
105 | Log into the VM with user/pass: root/abc123 | ||
106 | |||
107 | should show: | ||
108 | |||
109 | [ 2.656367] uio_ivshmem 0000:00:02.0: ivshmem-mmr at 0x0000000010203000, size 0x0000000000001000 | ||
110 | [ 2.656931] uio_ivshmem 0000:00:02.0: ivshmem-shmem at 0x0000008000000000, size 0x0000000000400000 | ||
111 | [ 2.662554] uio_ivshmem 0000:00:02.0: module successfully loaded | ||
112 | |||
113 | In another console, clone and build Zephyr image from 'uio_ivhsmem' branch: | ||
114 | |||
115 | $ git clone -b uio_ivshmem --single-branch https://github.com/gromero/zephyr | ||
116 | $ west -v --verbose build -p always -b qemu_cortex_m3 ./samples/uio_ivshmem/ | ||
117 | |||
118 | ... and then start the arm VM + Zephyr image + ivshmem-flat device: | ||
119 | |||
120 | $ ./qemu-system-arm -machine lm3s6965evb -nographic -net none -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem_flat -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/unattached/device[1]/nvic/unnamed-gpio-in[0]',x-bus-qompath='/sysbus' -kernel ~/zephyrproject/zephyr/build/qemu_cortex_m3/uio_ivshmem/zephyr/zephyr.elf | ||
121 | |||
122 | You should see something like: | ||
123 | |||
124 | *** Booting Zephyr OS build zephyr-v3.3.0-8350-gfb003e583600 *** | ||
125 | *** Board: qemu_cortex_m3 | ||
126 | *** Installing direct IRQ handler for external IRQ0 (Exception #16)... | ||
127 | *** Enabling IRQ0 in the NVIC logic... | ||
128 | *** Received IVSHMEM PEER ID: 7 | ||
129 | *** Waiting notification from peers to start... | ||
130 | |||
131 | Now, from the Linux terminal, notify the arm VM from the aarch64 VM | ||
132 | (use the "IVSHMEM PEER ID" reported by Zephyr as the third argument, in this example: 7): | ||
133 | |||
134 | $ ./uio_ivshmem_test /dev/uio0 7 | ||
135 | |||
136 | MMRs mapped at 0xffff8fb28000 in VMA. | ||
137 | shmem mapped at 0xffff8f728000 in VMA. | ||
138 | mmr0: 0 0 | ||
139 | mmr1: 0 0 | ||
140 | mmr2: 6 6 | ||
141 | mmr3: 0 0 | ||
142 | Data ok. 4194304 byte(s) checked. | ||
143 | |||
144 | The arm VM should report something like: | ||
145 | |||
146 | *** Got interrupt at vector 0! | ||
147 | *** Writting constant 0xb5b5b5b5 to shmem... done! | ||
148 | *** Notifying back peer ID 6 at vector 0... | ||
149 | |||
150 | -- | ||
151 | |||
152 | v2: | ||
2 | - Correct code style | 153 | - Correct code style |
3 | - Correct trace event format strings | 154 | - Correct trace event format strings |
4 | - Include minimum headers in ivshmem-flat.h | 155 | - Include minimum headers in ivshmem-flat.h |
5 | - Allow ivshmem_flat_recv_msg() take NULL | 156 | - Allow ivshmem_flat_recv_msg() take NULL |
6 | - Factored ivshmem_flat_connect_server() out | 157 | - Factored ivshmem_flat_connect_server() out |
7 | - Split sysbus-auto-wire controversial code in different patch | 158 | - Split sysbus-auto-wire controversial code in different patch |
8 | - Document QDev interface | 159 | - Document QDev interface |
9 | 160 | ||
10 | Since v2: | 161 | v3: |
11 | - Addressed all comments from Thomas Huth about qtest: | 162 | - Addressed all comments from Thomas Huth about qtest: |
12 | 1) Use of g_usleep + number of attemps for timeout | 163 | 1) Use of g_usleep + number of attemps for timeout |
13 | 2) Use of g_get_tmp_dir instead of hard-coded /tmp | 164 | 2) Use of g_get_tmp_dir instead of hard-coded /tmp |
14 | 3) Test if machine lm3s6965evb is available, if not skip test | 165 | 3) Test if machine lm3s6965evb is available, if not skip test |
15 | - Use of qemu_irq_pulse instead of 2x qemu_set_irq | 166 | - Use of qemu_irq_pulse instead of 2x qemu_set_irq |
16 | - Fixed all tests for new device options and IRQ name change | 167 | - Fixed all tests for new device options and IRQ name change |
17 | - Updated doc and commit messages regarding new/deleted device options | 168 | - Updated doc and commit messages regarding new/deleted device options |
18 | - Turned device options 'x-bus-address-iomem' and 'x-bus-address-shmem' mandatory | 169 | - Turned device options 'x-bus-address-iomem' and 'x-bus-address-shmem' |
19 | 170 | mandatory | |
20 | -- | 171 | |
21 | |||
22 | This patchset introduces a new device, ivshmem-flat, which is similar to the | ||
23 | current ivshmem device but does not require a PCI bus. It implements the ivshmem | ||
24 | status and control registers as MMRs and the shared memory as a directly | ||
25 | accessible memory region in the VM memory layout. It's meant to be used on | ||
26 | machines like those with Cortex-M MCUs, which usually lack a PCI bus, e.g., | ||
27 | lm3s6965evb and mps2-an385. Additionally, it has the benefit of requiring a tiny | ||
28 | 'device driver,' which is helpful on some RTOSes, like Zephyr, that run on | ||
29 | memory-constrained resource targets. | ||
30 | |||
31 | The patchset includes a QTest for the ivshmem-flat device, however, it's also | ||
32 | possible to experiment with it in two ways: | ||
33 | |||
34 | (a) using two Cortex-M VMs running Zephyr; or | ||
35 | (b) using one aarch64 VM running Linux with the ivshmem PCI device and another | ||
36 | arm (Cortex-M) VM running Zephyr with the new ivshmem-flat device. | ||
37 | |||
38 | Please note that for running the ivshmem-flat QTests the following patch, which | ||
39 | is not committed to the tree yet, must be applied: | ||
40 | |||
41 | https://lists.nongnu.org/archive/html/qemu-devel/2023-11/msg03176.html | ||
42 | |||
43 | -- | ||
44 | |||
45 | To experiment with (a), clone this Zephyr repo [0], set the Zephyr build | ||
46 | environment [1], and follow the instructions in the 'ivshmem' sample main.c [2]. | ||
47 | |||
48 | [0] https://github.com/gromero/zephyr/tree/ivshmem | ||
49 | [1] https://docs.zephyrproject.org/latest/develop/getting_started/index.html | ||
50 | [2] https://github.com/gromero/zephyr/commit/73fbd481e352b25ae5483ba5048a2182b90b7f00#diff-16fa1f481a49b995d0d1a62da37b9f33033f5ee477035e73465e7208521ddbe0R9-R70 | ||
51 | [3] https://lore.kernel.org/qemu-devel/20231127052024.435743-1-gustavo.romero@linaro.org/ | ||
52 | |||
53 | To experiment with (b): | ||
54 | |||
55 | $ git clone -b uio_ivshmem --single-branch https://github.com/gromero/linux.git | ||
56 | $ cd linux | ||
57 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/arm64_uio_ivshmem.config -O .config | ||
58 | |||
59 | If in an x86_64 machine, cross compile the kernel, for instance: | ||
60 | |||
61 | $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 36 | ||
62 | |||
63 | Install image in some directory, let's say, in ~/linux: | ||
64 | |||
65 | $ mkdir ~/linux | ||
66 | $ export INSTALL_PATH=~/linux | ||
67 | $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j 36 install | ||
68 | |||
69 | or, if you prefer, download the compiled image from: | ||
70 | |||
71 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/vmlinuz-6.6.0-rc1-g28f3f88ee261 | ||
72 | |||
73 | ... and then the rootfs: | ||
74 | |||
75 | $ wget https://people.linaro.org/~gustavo.romero/ivshmem/rootfs.qcow2 | ||
76 | |||
77 | Now, build QEMU with this patchset applied: | ||
78 | |||
79 | $ mkdir build && cd build | ||
80 | $ ../configure --target-list=arm-softmmu,aarch64-softmmu | ||
81 | $ make -j 36 | ||
82 | |||
83 | Start the ivshmem server: | ||
84 | |||
85 | $ contrib/ivshmem-server/ivshmem-server -F | ||
86 | |||
87 | Start the aarch64 VM + Linux + ivshmem PCI device: | ||
88 | |||
89 | $ ./qemu-system-aarch64 -kernel ~/linux/vmlinuz-6.6.0-rc1-g28f3f88ee261 -append "root=/dev/vda initrd=/bin/bash console=ttyAMA0,115200" -drive file=~/linux/rootfs.qcow2,media=disk,if=virtio -machine virt-6.2 -nographic -accel tcg -cpu cortex-a57 -m 8192 -netdev bridge,id=hostnet0,br=virbr0,helper=/usr/lib/qemu/qemu-bridge-helper -device pcie-root-port,port=8,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x1 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:d9:d1:12,bus=pci.1,addr=0x0 -device ivshmem-doorbell,vectors=2,chardev=ivshmem -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem | ||
90 | |||
91 | Log into the VM with user/pass: root/abc123 | ||
92 | |||
93 | should show: | ||
94 | |||
95 | [ 2.656367] uio_ivshmem 0000:00:02.0: ivshmem-mmr at 0x0000000010203000, size 0x0000000000001000 | ||
96 | [ 2.656931] uio_ivshmem 0000:00:02.0: ivshmem-shmem at 0x0000008000000000, size 0x0000000000400000 | ||
97 | [ 2.662554] uio_ivshmem 0000:00:02.0: module successfully loaded | ||
98 | |||
99 | In another console, clone and build Zephyr image from 'uio_ivhsmem' branch: | ||
100 | |||
101 | $ git clone -b uio_ivshmem --single-branch https://github.com/gromero/zephyr | ||
102 | $ west -v --verbose build -p always -b qemu_cortex_m3 ./samples/uio_ivshmem/ | ||
103 | |||
104 | ... and then start the arm VM + Zephyr image + ivshmem-flat device: | ||
105 | |||
106 | $ ./qemu-system-arm -machine lm3s6965evb -nographic -net none -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem_flat -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/unattached/device[1]/nvic/unnamed-gpio-in[0]',x-bus-qompath='/sysbus' -kernel ~/zephyrproject/zephyr/build/qemu_cortex_m3/uio_ivshmem/zephyr/zephyr.elf | ||
107 | |||
108 | You should see something like: | ||
109 | |||
110 | *** Booting Zephyr OS build zephyr-v3.3.0-8350-gfb003e583600 *** | ||
111 | *** Board: qemu_cortex_m3 | ||
112 | *** Installing direct IRQ handler for external IRQ0 (Exception #16)... | ||
113 | *** Enabling IRQ0 in the NVIC logic... | ||
114 | *** Received IVSHMEM PEER ID: 7 | ||
115 | *** Waiting notification from peers to start... | ||
116 | |||
117 | Now, from the Linux terminal, notify the arm VM (use the "IVSHMEM PEER ID" | ||
118 | reported by Zephyr as the third arg, in this example: 7): | ||
119 | |||
120 | MMRs mapped at 0xffff8fb28000 in VMA. | ||
121 | shmem mapped at 0xffff8f728000 in VMA. | ||
122 | mmr0: 0 0 | ||
123 | mmr1: 0 0 | ||
124 | mmr2: 6 6 | ||
125 | mmr3: 0 0 | ||
126 | Data ok. 4194304 byte(s) checked. | ||
127 | |||
128 | The arm VM should report something like: | ||
129 | |||
130 | *** Got interrupt at vector 0! | ||
131 | *** Writting constant 0xb5b5b5b5 to shmem... done! | ||
132 | *** Notifying back peer ID 6 at vector 0... | ||
133 | 172 | ||
134 | Cheers, | 173 | Cheers, |
135 | Gustavo | 174 | Gustavo |
136 | 175 | ||
137 | Gustavo Romero (6): | 176 | Gustavo Romero (7): |
138 | hw/misc/ivshmem: Add ivshmem-flat device | 177 | hw/misc/ivshmem-flat: Add ivshmem-flat device |
139 | hw/misc/ivshmem-flat: Allow device to wire itself on sysbus | 178 | hw/misc/ivshmem-flat: Allow device to wire itself on sysbus |
140 | hw/arm: Allow some machines to use the ivshmem-flat device | 179 | hw/arm: Allow some machines to use the ivshmem-flat device |
141 | hw/misc/ivshmem: Rename ivshmem to ivshmem-pci | 180 | hw/misc/ivshmem: Rename ivshmem to ivshmem-pci |
142 | tests/qtest: Reorganize common code in ivshmem-test | 181 | tests/qtest: Reorganize common code in ivshmem-test |
182 | tests/qtest: Add API functions to capture IRQ toggling | ||
143 | tests/qtest: Add ivshmem-flat test | 183 | tests/qtest: Add ivshmem-flat test |
144 | 184 | ||
145 | docs/system/devices/ivshmem-flat.rst | 90 +++++ | 185 | docs/system/devices/ivshmem-flat.rst | 90 +++++ |
146 | hw/arm/mps2.c | 3 + | 186 | hw/arm/mps2.c | 3 + |
147 | hw/arm/stellaris.c | 3 + | 187 | hw/arm/stellaris.c | 3 + |
148 | hw/arm/virt.c | 2 + | 188 | hw/arm/virt.c | 2 + |
149 | hw/core/sysbus-fdt.c | 2 + | 189 | hw/core/sysbus-fdt.c | 2 + |
150 | hw/misc/Kconfig | 5 + | 190 | hw/misc/Kconfig | 5 + |
151 | hw/misc/ivshmem-flat.c | 531 +++++++++++++++++++++++++++ | 191 | hw/misc/ivshmem-flat.c | 531 +++++++++++++++++++++++++++ |
152 | hw/misc/{ivshmem.c => ivshmem-pci.c} | 0 | 192 | hw/misc/{ivshmem.c => ivshmem-pci.c} | 0 |
153 | hw/misc/meson.build | 4 +- | 193 | hw/misc/meson.build | 4 +- |
154 | hw/misc/trace-events | 17 + | 194 | hw/misc/trace-events | 16 + |
155 | include/hw/misc/ivshmem-flat.h | 94 +++++ | 195 | include/hw/misc/ivshmem-flat.h | 94 +++++ |
156 | tests/qtest/ivshmem-flat-test.c | 338 +++++++++++++++++ | 196 | tests/qtest/ivshmem-flat-test.c | 338 +++++++++++++++++ |
157 | tests/qtest/ivshmem-test.c | 113 +----- | 197 | tests/qtest/ivshmem-test.c | 113 +----- |
158 | tests/qtest/ivshmem-utils.c | 156 ++++++++ | 198 | tests/qtest/ivshmem-utils.c | 156 ++++++++ |
159 | tests/qtest/ivshmem-utils.h | 56 +++ | 199 | tests/qtest/ivshmem-utils.h | 56 +++ |
160 | tests/qtest/meson.build | 8 +- | 200 | tests/qtest/libqtest.c | 24 ++ |
161 | 16 files changed, 1312 insertions(+), 110 deletions(-) | 201 | tests/qtest/libqtest.h | 28 ++ |
202 | tests/qtest/meson.build | 6 +- | ||
203 | 18 files changed, 1362 insertions(+), 109 deletions(-) | ||
162 | create mode 100644 docs/system/devices/ivshmem-flat.rst | 204 | create mode 100644 docs/system/devices/ivshmem-flat.rst |
163 | create mode 100644 hw/misc/ivshmem-flat.c | 205 | create mode 100644 hw/misc/ivshmem-flat.c |
164 | rename hw/misc/{ivshmem.c => ivshmem-pci.c} (100%) | 206 | rename hw/misc/{ivshmem.c => ivshmem-pci.c} (100%) |
165 | create mode 100644 include/hw/misc/ivshmem-flat.h | 207 | create mode 100644 include/hw/misc/ivshmem-flat.h |
166 | create mode 100644 tests/qtest/ivshmem-flat-test.c | 208 | create mode 100644 tests/qtest/ivshmem-flat-test.c |
167 | create mode 100644 tests/qtest/ivshmem-utils.c | 209 | create mode 100644 tests/qtest/ivshmem-utils.c |
168 | create mode 100644 tests/qtest/ivshmem-utils.h | 210 | create mode 100644 tests/qtest/ivshmem-utils.h |
169 | 211 | ||
170 | -- | 212 | -- |
171 | 2.34.1 | 213 | 2.34.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
19 | --- | 19 | --- |
20 | docs/system/devices/ivshmem-flat.rst | 33 ++ | 20 | docs/system/devices/ivshmem-flat.rst | 33 ++ |
21 | hw/misc/Kconfig | 5 + | 21 | hw/misc/Kconfig | 5 + |
22 | hw/misc/ivshmem-flat.c | 463 +++++++++++++++++++++++++++ | 22 | hw/misc/ivshmem-flat.c | 463 +++++++++++++++++++++++++++ |
23 | hw/misc/meson.build | 2 + | 23 | hw/misc/meson.build | 2 + |
24 | hw/misc/trace-events | 17 + | 24 | hw/misc/trace-events | 16 + |
25 | include/hw/misc/ivshmem-flat.h | 85 +++++ | 25 | include/hw/misc/ivshmem-flat.h | 85 +++++ |
26 | 6 files changed, 605 insertions(+) | 26 | 6 files changed, 604 insertions(+) |
27 | create mode 100644 docs/system/devices/ivshmem-flat.rst | 27 | create mode 100644 docs/system/devices/ivshmem-flat.rst |
28 | create mode 100644 hw/misc/ivshmem-flat.c | 28 | create mode 100644 hw/misc/ivshmem-flat.c |
29 | create mode 100644 include/hw/misc/ivshmem-flat.h | 29 | create mode 100644 include/hw/misc/ivshmem-flat.h |
30 | 30 | ||
31 | diff --git a/docs/system/devices/ivshmem-flat.rst b/docs/system/devices/ivshmem-flat.rst | 31 | diff --git a/docs/system/devices/ivshmem-flat.rst b/docs/system/devices/ivshmem-flat.rst |
... | ... | ||
80 | + default y | 80 | + default y |
81 | + depends on LINUX && IVSHMEM | 81 | + depends on LINUX && IVSHMEM |
82 | + | 82 | + |
83 | config ECCMEMCTL | 83 | config ECCMEMCTL |
84 | bool | 84 | bool |
85 | select ECC | 85 | |
86 | diff --git a/hw/misc/ivshmem-flat.c b/hw/misc/ivshmem-flat.c | 86 | diff --git a/hw/misc/ivshmem-flat.c b/hw/misc/ivshmem-flat.c |
87 | new file mode 100644 | 87 | new file mode 100644 |
88 | index XXXXXXX..XXXXXXX | 88 | index XXXXXXX..XXXXXXX |
89 | --- /dev/null | 89 | --- /dev/null |
90 | +++ b/hw/misc/ivshmem-flat.c | 90 | +++ b/hw/misc/ivshmem-flat.c |
... | ... | ||
568 | system_ss.add(when: 'CONFIG_ALLWINNER_A10_CCM', if_true: files('allwinner-a10-ccm.c')) | 568 | system_ss.add(when: 'CONFIG_ALLWINNER_A10_CCM', if_true: files('allwinner-a10-ccm.c')) |
569 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 569 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events |
570 | index XXXXXXX..XXXXXXX 100644 | 570 | index XXXXXXX..XXXXXXX 100644 |
571 | --- a/hw/misc/trace-events | 571 | --- a/hw/misc/trace-events |
572 | +++ b/hw/misc/trace-events | 572 | +++ b/hw/misc/trace-events |
573 | @@ -XXX,XX +XXX,XX @@ djmemc_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRI | 573 | @@ -XXX,XX +XXX,XX @@ aspeed_sli_read(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx |
574 | # iosb.c | 574 | aspeed_sliio_write(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 |
575 | iosb_read(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" | 575 | aspeed_sliio_read(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 |
576 | iosb_write(int reg, uint64_t value, unsigned int size) "reg=0x%x value=0x%"PRIx64" size=%u" | 576 | |
577 | + | ||
578 | +# ivshmem-flat.c | 577 | +# ivshmem-flat.c |
579 | +ivshmem_flat_irq_handler(uint16_t vector_id) "Caught interrupt request: vector %d" | 578 | +ivshmem_flat_irq_handler(uint16_t vector_id) "Caught interrupt request: vector %d" |
580 | +ivshmem_flat_new_peer(uint16_t peer_id) "New peer ID: %d" | 579 | +ivshmem_flat_new_peer(uint16_t peer_id) "New peer ID: %d" |
581 | +ivshmem_flat_add_vector_failure(uint16_t vector_id, uint32_t vector_fd, uint16_t peer_id) "Failed to add vector %u (fd = %u) to peer ID %u, maximum number of vectors reached" | 580 | +ivshmem_flat_add_vector_failure(uint16_t vector_id, uint32_t vector_fd, uint16_t peer_id) "Failed to add vector %u (fd = %u) to peer ID %u, maximum number of vectors reached" |
582 | +ivshmem_flat_add_vector_success(uint16_t vector_id, uint32_t vector_fd, uint16_t peer_id) "Successful addition of vector %u (fd = %u) to peer ID %u" | 581 | +ivshmem_flat_add_vector_success(uint16_t vector_id, uint32_t vector_fd, uint16_t peer_id) "Successful addition of vector %u (fd = %u) to peer ID %u" |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
16 | -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/soc/v7m/nvic/unnamed-gpio-in[0]',x-bus-address-iomem=0x400FF000,x-bus-address-shmem=0x40100000 | 16 | -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/soc/v7m/nvic/unnamed-gpio-in[0]',x-bus-address-iomem=0x400FF000,x-bus-address-shmem=0x40100000 |
17 | -kernel zephyr_kernel.elf | 17 | -kernel zephyr_kernel.elf |
18 | 18 | ||
19 | The IRQ QOM path option for the target machine can be determined by | 19 | The IRQ QOM path option for the target machine can be determined by |
20 | creating the VM without the ivshmem-flat device, going to the QEMU | 20 | creating the VM without the ivshmem-flat device, going to the QEMU |
21 | console and listing the QOM nodes with 'info qom-tree'. In the Stellaris | 21 | monitor and listing the QOM nodes with 'info qom-tree'. In the Stellaris |
22 | example above the input IRQ is in the machine's NVIC Interrupt | 22 | example above the input IRQ is in the machine's NVIC Interrupt |
23 | Controller. | 23 | Controller. |
24 | 24 | ||
25 | If 'x-irq-qompath' is not provided the device won't be able to be | 25 | If 'x-irq-qompath' is not provided the device won't be able to be |
26 | interrupted by other VMs (peers) and only the shared memory (shmem) | 26 | interrupted by other VMs (peers) and only the shared memory (shmem) |
... | ... | ||
68 | + |qemu-system-arm| -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem_flat -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/soc/v7m/nvic/unnamed-gpio-in[0]',x-bus-address-iomem=0x400FF000,x-bus-address-shmem=0x40100000 | 68 | + |qemu-system-arm| -chardev socket,path=/tmp/ivshmem_socket,id=ivshmem_flat -device ivshmem-flat,chardev=ivshmem_flat,x-irq-qompath='/machine/soc/v7m/nvic/unnamed-gpio-in[0]',x-bus-address-iomem=0x400FF000,x-bus-address-shmem=0x40100000 |
69 | + | 69 | + |
70 | +The other option, ``x-irq-qompath=``, is not required if the user doesn't want | 70 | +The other option, ``x-irq-qompath=``, is not required if the user doesn't want |
71 | +the device supporting notifications. | 71 | +the device supporting notifications. |
72 | + | 72 | + |
73 | +``x-irq-qompath``. Used to inform the device which IRQ input line it can attach | 73 | +``x-irq-qompath``. Used to inform the device what IRQ input line it can attach |
74 | +to enable the notification mechanism (IRQ). The ivshmem-flat device currently | 74 | +to to enable the notification mechanism (IRQ). The ivshmem-flat device currently |
75 | +only supports notification via vector 0. Notifications via other vectors are | 75 | +only supports notification via vector 0. Notification via other vectors are |
76 | +ignored. (optional) | 76 | +ignored. (optional) |
77 | + | 77 | + |
78 | +Two examples for different machines follow. | 78 | +Two examples for different machines follow. |
79 | + | 79 | + |
80 | +Stellaris machine (``- machine lm3s6965evb``): | 80 | +Stellaris machine (``-machine lm3s6965evb``): |
81 | + | 81 | + |
82 | +:: | 82 | +:: |
83 | + | 83 | + |
84 | + x-irq-qompath=/machine/soc/v7m/nvic/unnamed-gpio-in[0] | 84 | + x-irq-qompath=/machine/soc/v7m/nvic/unnamed-gpio-in[0] |
85 | + | 85 | + |
... | ... | ||
88 | +:: | 88 | +:: |
89 | + | 89 | + |
90 | + x-irq-qompath=/machine/armv7m/nvic/unnamed-gpio-in[0] | 90 | + x-irq-qompath=/machine/armv7m/nvic/unnamed-gpio-in[0] |
91 | + | 91 | + |
92 | +The available IRQ input lines on a given VM that the ivshmem-flat device can be | 92 | +The available IRQ input lines on a given VM that the ivshmem-flat device can be |
93 | +attached to can be found from the QEMU monitor (Ctrl-a + c) with: | 93 | +attached should be found using the QEMU monitor (Ctrl-a + c) with: |
94 | + | 94 | + |
95 | +(qemu) info qom-tree | 95 | +(qemu) info qom-tree |
96 | + | 96 | + |
97 | +``x-bus-address-iomem``. Allows changing the address where the MMRs are mapped | 97 | +``x-bus-address-iomem``. Allows changing the address where the MMRs are mapped |
98 | +into the VM memory layout. (required) | 98 | +into the VM memory layout. (required) |
... | ... | ||
101 | +region is mapped into the VM memory layout. (required) | 101 | +region is mapped into the VM memory layout. (required) |
102 | + | 102 | + |
103 | +``shmem-size``. Allows changing the size (in bytes) of shared memory region. | 103 | +``shmem-size``. Allows changing the size (in bytes) of shared memory region. |
104 | +Default is 4 MiB, which is the same default used by the ivshmem server, so | 104 | +Default is 4 MiB, which is the same default used by the ivshmem server, so |
105 | +usually it's not necessary to change it. The size must match the size of the | 105 | +usually it's not necessary to change it. The size must match the size of the |
106 | +shared memory reserverd and informed by the ivshmem server, otherwise device | 106 | +shared memory reserved and informed by the ivshmem server, otherwise the device |
107 | +creation fails. (optional) | 107 | +creation fails. (optional) |
108 | diff --git a/hw/core/sysbus-fdt.c b/hw/core/sysbus-fdt.c | 108 | diff --git a/hw/core/sysbus-fdt.c b/hw/core/sysbus-fdt.c |
109 | index XXXXXXX..XXXXXXX 100644 | 109 | index XXXXXXX..XXXXXXX 100644 |
110 | --- a/hw/core/sysbus-fdt.c | 110 | --- a/hw/core/sysbus-fdt.c |
111 | +++ b/hw/core/sysbus-fdt.c | 111 | +++ b/hw/core/sysbus-fdt.c |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
60 | #include "hw/virtio/virtio-iommu.h" | 60 | #include "hw/virtio/virtio-iommu.h" |
61 | #include "hw/char/pl011.h" | 61 | #include "hw/char/pl011.h" |
62 | #include "qemu/guest-random.h" | 62 | #include "qemu/guest-random.h" |
63 | +#include "hw/misc/ivshmem-flat.h" | 63 | +#include "hw/misc/ivshmem-flat.h" |
64 | 64 | ||
65 | #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ | 65 | static GlobalProperty arm_virt_compat[] = { |
66 | static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ | 66 | { TYPE_VIRTIO_IOMMU_PCI, "aw-bits", "48" }, |
67 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | 67 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) |
68 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE); | 68 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE); |
69 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | 69 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); |
70 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM); | 70 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM); |
71 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_IVSHMEM_FLAT); | 71 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_IVSHMEM_FLAT); |
... | ... | diff view generated by jsdifflib |
1 | Because now there is also an MMIO ivshmem device (ivshmem-flat.c), and | 1 | Because now there is also an MMIO ivshmem device (ivshmem-flat.c), and |
---|---|---|---|
2 | ivshmem.c is a PCI specific implementation, rename it to ivshmem-pci.c. | 2 | ivshmem.c is a PCI specific implementation, rename it to ivshmem-pci.c. |
3 | 3 | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-ID: <20231127052024.435743-5-gustavo.romero@linaro.org> | 5 | Message-ID: <20231127052024.435743-5-gustavo.romero@linaro.org> |
6 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> | 6 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> |
7 | --- | 7 | --- |
8 | hw/misc/{ivshmem.c => ivshmem-pci.c} | 0 | 8 | hw/misc/{ivshmem.c => ivshmem-pci.c} | 0 |
9 | hw/misc/meson.build | 2 +- | 9 | hw/misc/meson.build | 2 +- |
10 | 2 files changed, 1 insertion(+), 1 deletion(-) | 10 | 2 files changed, 1 insertion(+), 1 deletion(-) |
11 | rename hw/misc/{ivshmem.c => ivshmem-pci.c} (100%) | 11 | rename hw/misc/{ivshmem.c => ivshmem-pci.c} (100%) |
12 | 12 | ||
13 | diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem-pci.c | 13 | diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem-pci.c |
14 | similarity index 100% | 14 | similarity index 100% |
15 | rename from hw/misc/ivshmem.c | 15 | rename from hw/misc/ivshmem.c |
16 | rename to hw/misc/ivshmem-pci.c | 16 | rename to hw/misc/ivshmem-pci.c |
17 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 17 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build |
18 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/misc/meson.build | 19 | --- a/hw/misc/meson.build |
20 | +++ b/hw/misc/meson.build | 20 | +++ b/hw/misc/meson.build |
21 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) | 21 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) |
22 | subdir('macio') | 22 | subdir('macio') |
23 | 23 | ||
24 | # ivshmem devices | 24 | # ivshmem devices |
25 | -system_ss.add(when: 'CONFIG_IVSHMEM_DEVICE', if_true: files('ivshmem.c')) | 25 | -system_ss.add(when: 'CONFIG_IVSHMEM_DEVICE', if_true: files('ivshmem.c')) |
26 | +system_ss.add(when: 'CONFIG_IVSHMEM_DEVICE', if_true: files('ivshmem-pci.c')) | 26 | +system_ss.add(when: 'CONFIG_IVSHMEM_DEVICE', if_true: files('ivshmem-pci.c')) |
27 | system_ss.add(when: 'CONFIG_IVSHMEM_FLAT_DEVICE', if_true: files('ivshmem-flat.c')) | 27 | system_ss.add(when: 'CONFIG_IVSHMEM_FLAT_DEVICE', if_true: files('ivshmem-flat.c')) |
28 | 28 | ||
29 | system_ss.add(when: 'CONFIG_ALLWINNER_SRAMC', if_true: files('allwinner-sramc.c')) | 29 | system_ss.add(when: 'CONFIG_ALLWINNER_SRAMC', if_true: files('allwinner-sramc.c')) |
30 | -- | 30 | -- |
31 | 2.34.1 | 31 | 2.34.1 |
32 | 32 | ||
33 | 33 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
28 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> | 28 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> |
29 | --- | 29 | --- |
30 | tests/qtest/ivshmem-test.c | 113 ++------------------------ | 30 | tests/qtest/ivshmem-test.c | 113 ++------------------------ |
31 | tests/qtest/ivshmem-utils.c | 156 ++++++++++++++++++++++++++++++++++++ | 31 | tests/qtest/ivshmem-utils.c | 156 ++++++++++++++++++++++++++++++++++++ |
32 | tests/qtest/ivshmem-utils.h | 56 +++++++++++++ | 32 | tests/qtest/ivshmem-utils.h | 56 +++++++++++++ |
33 | tests/qtest/meson.build | 6 +- | 33 | tests/qtest/meson.build | 4 +- |
34 | 4 files changed, 222 insertions(+), 109 deletions(-) | 34 | 4 files changed, 221 insertions(+), 108 deletions(-) |
35 | create mode 100644 tests/qtest/ivshmem-utils.c | 35 | create mode 100644 tests/qtest/ivshmem-utils.c |
36 | create mode 100644 tests/qtest/ivshmem-utils.h | 36 | create mode 100644 tests/qtest/ivshmem-utils.h |
37 | 37 | ||
38 | diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c | 38 | diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c |
39 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
... | ... | ||
442 | (config_all_devices.has_key('CONFIG_PVPANIC_PCI') ? ['pvpanic-pci-test'] : []) + \ | 442 | (config_all_devices.has_key('CONFIG_PVPANIC_PCI') ? ['pvpanic-pci-test'] : []) + \ |
443 | (config_all_devices.has_key('CONFIG_HDA') ? ['intel-hda-test'] : []) + \ | 443 | (config_all_devices.has_key('CONFIG_HDA') ? ['intel-hda-test'] : []) + \ |
444 | - (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ | 444 | - (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ |
445 | + (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ | 445 | + (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ |
446 | (config_all_devices.has_key('CONFIG_IOH3420') ? ['ioh3420-test'] : []) + \ | 446 | (config_all_devices.has_key('CONFIG_IOH3420') ? ['ioh3420-test'] : []) + \ |
447 | - (config_all_devices.has_key('CONFIG_LPC_ICH9') ? ['lpc-ich9-test'] : []) + \ | 447 | (config_all_devices.has_key('CONFIG_LPC_ICH9') ? ['lpc-ich9-test'] : []) + \ |
448 | + (config_all_devices.has_key('CONFIG_LPC_ICH9') ? ['lpc-ich9-test'] : []) + \ | 448 | (config_all_devices.has_key('CONFIG_MC146818RTC') ? ['rtc-test'] : []) + \ |
449 | (config_all_devices.has_key('CONFIG_USB_UHCI') ? ['usb-hcd-uhci-test'] : []) + \ | ||
450 | (config_all_devices.has_key('CONFIG_USB_UHCI') and \ | ||
451 | config_all_devices.has_key('CONFIG_USB_EHCI') ? ['usb-hcd-ehci-test'] : []) + \ | ||
452 | @@ -XXX,XX +XXX,XX @@ qtests = { | 449 | @@ -XXX,XX +XXX,XX @@ qtests = { |
453 | 'cdrom-test': files('boot-sector.c'), | 450 | 'dbus-vmstate-test': files('migration/migration-qmp.c', |
454 | 'dbus-vmstate-test': files('migration-helpers.c') + dbus_vmstate1, | 451 | 'migration/migration-util.c') + dbus_vmstate1, |
455 | 'erst-test': files('erst-test.c'), | 452 | 'erst-test': files('erst-test.c'), |
456 | - 'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'], | 453 | - 'ivshmem-test': [rt, '../../contrib/ivshmem-server/ivshmem-server.c'], |
457 | + 'ivshmem-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], | 454 | + 'ivshmem-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], |
458 | 'migration-test': migration_files, | 455 | 'migration-test': migration_files + migration_tls_files, |
459 | 'pxe-test': files('boot-sector.c'), | 456 | 'pxe-test': files('boot-sector.c'), |
460 | 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], | 457 | 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c'), |
461 | -- | 458 | -- |
462 | 2.34.1 | 459 | 2.34.1 |
463 | 460 | ||
464 | 461 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently, the QTest API does not provide a function to capture when an | ||
2 | IRQ line is raised or lowered, although the QTest Protocol already | ||
3 | reports such IRQ transitions. As a consequence, it is also not possible | ||
4 | to capture when an IRQ line is toggled. Functions like qtest_get_irq() | ||
5 | only read the current state of the intercepted IRQ lines, which is | ||
6 | already high (or low) when the function is called if the IRQ line is | ||
7 | toggled. Therefore, these functions miss the IRQ line state transitions. | ||
1 | 8 | ||
9 | This commit introduces two new API functions: | ||
10 | qtest_get_irq_raised_counter() and qtest_get_irq_lowered_counter(). | ||
11 | These functions allow capturing the number of times an observed IRQ line | ||
12 | transitioned from low to high state or from high to low state, | ||
13 | respectively. | ||
14 | |||
15 | When used together, these new API functions then allow checking if one | ||
16 | or more pulses were generated (indicating if the IRQ line was toggled). | ||
17 | |||
18 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> | ||
19 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
20 | Acked-by: Thomas Huth <thuth@redhat.com> | ||
21 | --- | ||
22 | tests/qtest/libqtest.c | 24 ++++++++++++++++++++++++ | ||
23 | tests/qtest/libqtest.h | 28 ++++++++++++++++++++++++++++ | ||
24 | 2 files changed, 52 insertions(+) | ||
25 | |||
26 | diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/tests/qtest/libqtest.c | ||
29 | +++ b/tests/qtest/libqtest.c | ||
30 | @@ -XXX,XX +XXX,XX @@ struct QTestState | ||
31 | int expected_status; | ||
32 | bool big_endian; | ||
33 | bool irq_level[MAX_IRQ]; | ||
34 | + uint64_t irq_raised_counter[MAX_IRQ]; | ||
35 | + uint64_t irq_lowered_counter[MAX_IRQ]; | ||
36 | GString *rx; | ||
37 | QTestTransportOps ops; | ||
38 | GList *pending_events; | ||
39 | @@ -XXX,XX +XXX,XX @@ static QTestState *qtest_init_internal(const char *qemu_bin, | ||
40 | s->rx = g_string_new(""); | ||
41 | for (i = 0; i < MAX_IRQ; i++) { | ||
42 | s->irq_level[i] = false; | ||
43 | + s->irq_raised_counter[i] = 0; | ||
44 | + s->irq_lowered_counter[i] = 0; | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | @@ -XXX,XX +XXX,XX @@ redo: | ||
49 | g_assert_cmpint(irq, <, MAX_IRQ); | ||
50 | |||
51 | if (strcmp(words[1], "raise") == 0) { | ||
52 | + s->irq_raised_counter[irq]++; | ||
53 | s->irq_level[irq] = true; | ||
54 | } else { | ||
55 | + s->irq_lowered_counter[irq]++; | ||
56 | s->irq_level[irq] = false; | ||
57 | } | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ bool qtest_get_irq(QTestState *s, int num) | ||
60 | return s->irq_level[num]; | ||
61 | } | ||
62 | |||
63 | +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num) | ||
64 | +{ | ||
65 | + /* dummy operation in order to make sure irq is up to date */ | ||
66 | + qtest_inb(s, 0); | ||
67 | + | ||
68 | + return s->irq_raised_counter[num]; | ||
69 | +} | ||
70 | + | ||
71 | +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num) | ||
72 | +{ | ||
73 | + /* dummy operation in order to make sure irq is up to date */ | ||
74 | + qtest_inb(s, 0); | ||
75 | + | ||
76 | + return s->irq_lowered_counter[num]; | ||
77 | +} | ||
78 | + | ||
79 | void qtest_module_load(QTestState *s, const char *prefix, const char *libname) | ||
80 | { | ||
81 | qtest_sendf(s, "module_load %s %s\n", prefix, libname); | ||
82 | @@ -XXX,XX +XXX,XX @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch, | ||
83 | qts->wstatus = 0; | ||
84 | for (int i = 0; i < MAX_IRQ; i++) { | ||
85 | qts->irq_level[i] = false; | ||
86 | + qts->irq_raised_counter[i] = 0; | ||
87 | + qts->irq_lowered_counter[i] = 0; | ||
88 | } | ||
89 | |||
90 | qtest_client_set_rx_handler(qts, qtest_client_inproc_recv_line); | ||
91 | diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h | ||
92 | index XXXXXXX..XXXXXXX 100644 | ||
93 | --- a/tests/qtest/libqtest.h | ||
94 | +++ b/tests/qtest/libqtest.h | ||
95 | @@ -XXX,XX +XXX,XX @@ void qtest_module_load(QTestState *s, const char *prefix, const char *libname); | ||
96 | */ | ||
97 | bool qtest_get_irq(QTestState *s, int num); | ||
98 | |||
99 | +/** | ||
100 | + * qtest_get_irq_raised_counter: | ||
101 | + * @s: #QTestState instance to operate on. | ||
102 | + * @num: Interrupt to observe. | ||
103 | + * | ||
104 | + * This function can be used in conjunction with the | ||
105 | + * qtest_get_irq_lowered_counter() to check if one or more pulses where | ||
106 | + * generated on the observed interrupt. | ||
107 | + * | ||
108 | + * Returns: The number of times IRQ @num was raised, i.e., transitioned from | ||
109 | + * a low state (false) to a high state (true). | ||
110 | + */ | ||
111 | +uint64_t qtest_get_irq_raised_counter(QTestState *s, int num); | ||
112 | + | ||
113 | +/** | ||
114 | + * qtest_get_irq_lowered_counter: | ||
115 | + * @s: #QTestState instance to operate on. | ||
116 | + * @num: Interrupt to observe. | ||
117 | + * | ||
118 | + * This function can be used in conjunction with the | ||
119 | + * qtest_get_irq_raised_counter() to check if one or more pulses where | ||
120 | + * generated on the observed interrupt. | ||
121 | + * | ||
122 | + * Returns: The number of times IRQ @num was lowered, i.e., transitioned from | ||
123 | + * a high state (true) to a low state (false). | ||
124 | + */ | ||
125 | +uint64_t qtest_get_irq_lowered_counter(QTestState *s, int num); | ||
126 | + | ||
127 | /** | ||
128 | * qtest_irq_intercept_in: | ||
129 | * @s: #QTestState instance to operate on. | ||
130 | -- | ||
131 | 2.34.1 | ||
132 | |||
133 | diff view generated by jsdifflib |
1 | This commit adds a qtest for the ivshmem-flat device to test memory | 1 | This commit adds a qtest for the ivshmem-flat device to test memory |
---|---|---|---|
2 | sharing, IRQ triggering, and the memory mapped registers in the device. | 2 | sharing, IRQ triggering, and the memory mapped registers in the device. |
3 | 3 | ||
4 | Based-on: https://lists.gnu.org/archive/html/qemu-devel/2023-11/msg03176.html | ||
5 | Message-ID: <20231127052024.435743-4-gustavo.romero@linaro.org> | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 4 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> | 5 | Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> |
8 | --- | 6 | --- |
9 | tests/qtest/ivshmem-flat-test.c | 338 ++++++++++++++++++++++++++++++++ | 7 | tests/qtest/ivshmem-flat-test.c | 338 ++++++++++++++++++++++++++++++++ |
10 | tests/qtest/meson.build | 2 + | 8 | tests/qtest/meson.build | 2 + |
... | ... | ||
358 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 356 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
359 | index XXXXXXX..XXXXXXX 100644 | 357 | index XXXXXXX..XXXXXXX 100644 |
360 | --- a/tests/qtest/meson.build | 358 | --- a/tests/qtest/meson.build |
361 | +++ b/tests/qtest/meson.build | 359 | +++ b/tests/qtest/meson.build |
362 | @@ -XXX,XX +XXX,XX @@ qtests_stm32l4x5 = \ | 360 | @@ -XXX,XX +XXX,XX @@ qtests_stm32l4x5 = \ |
363 | 'stm32l4x5_syscfg-test'] | 361 | 'stm32l4x5_usart-test'] |
364 | 362 | ||
365 | qtests_arm = \ | 363 | qtests_arm = \ |
366 | + (config_all_devices.has_key('CONFIG_IVSHMEM_FLAT_DEVICE') ? ['ivshmem-flat-test'] : []) + \ | 364 | + (config_all_devices.has_key('CONFIG_IVSHMEM_FLAT_DEVICE') ? ['ivshmem-flat-test'] : []) + \ |
367 | (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \ | 365 | (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \ |
368 | (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ | 366 | (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ |
369 | (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ | 367 | (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ |
370 | @@ -XXX,XX +XXX,XX @@ qtests = { | 368 | @@ -XXX,XX +XXX,XX @@ qtests = { |
371 | 'dbus-vmstate-test': files('migration-helpers.c') + dbus_vmstate1, | 369 | 'migration/migration-util.c') + dbus_vmstate1, |
372 | 'erst-test': files('erst-test.c'), | 370 | 'erst-test': files('erst-test.c'), |
373 | 'ivshmem-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], | 371 | 'ivshmem-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], |
374 | + 'ivshmem-flat-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], | 372 | + 'ivshmem-flat-test': ['ivshmem-utils.c', '../../contrib/ivshmem-server/ivshmem-server.c'], |
375 | 'migration-test': migration_files, | 373 | 'migration-test': migration_files + migration_tls_files, |
376 | 'pxe-test': files('boot-sector.c'), | 374 | 'pxe-test': files('boot-sector.c'), |
377 | 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], | 375 | 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c'), |
378 | -- | 376 | -- |
379 | 2.34.1 | 377 | 2.34.1 |
380 | 378 | ||
381 | 379 | diff view generated by jsdifflib |