1 | The following changes since commit 7e7eb9f852a46b51a71ae9d82590b2e4d28827ee: | 1 | Another go at the v8.5-MemTag linux-user support, plus a |
---|---|---|---|
2 | couple more npcm7xx devices. | ||
2 | 3 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-01-28' into staging (2021-01-28 22:43:18 +0000) | 4 | -- PMM |
5 | |||
6 | The following changes since commit 8ba4bca570ace1e60614a0808631a517cf5df67a: | ||
7 | |||
8 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-02-15 17:13:57 +0000) | ||
4 | 9 | ||
5 | are available in the Git repository at: | 10 | are available in the Git repository at: |
6 | 11 | ||
7 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210129 | 12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210216 |
8 | 13 | ||
9 | for you to fetch changes up to 11749122e1a86866591306d43603d2795a3dea1a: | 14 | for you to fetch changes up to 64fd5bddf3b71d1b92b55382ab39768bd87ecfbd: |
10 | 15 | ||
11 | hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS (2021-01-29 10:47:29 +0000) | 16 | tests/qtests: Add npcm7xx emc model test (2021-02-16 14:27:05 +0000) |
12 | 17 | ||
13 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
14 | target-arm queue: | 19 | target-arm queue: |
15 | * Implement ID_PFR2 | 20 | * Support ARMv8.5-MemTag for linux-user |
16 | * Conditionalize DBGDIDR | 21 | * ncpm7xx: Support SMBus, EMC ethernet devices |
17 | * rename xlnx-zcu102.canbusN properties | 22 | * MAINTAINERS: add section for Clock framework |
18 | * provide powerdown/reset mechanism for secure firmware on 'virt' board | ||
19 | * hw/misc: Fix arith overflow in NPCM7XX PWM module | ||
20 | * target/arm: Replace magic value by MMU_DATA_LOAD definition | ||
21 | * configure: fix preadv errors on Catalina macOS with new XCode | ||
22 | * Various configure and other cleanups in preparation for iOS support | ||
23 | * hvf: Add hypervisor entitlement to output binaries (needed for Big Sur) | ||
24 | * Implement pvpanic-pci device | ||
25 | * Convert the CMSDK timer devices to the Clock framework | ||
26 | 23 | ||
27 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
28 | Alexander Graf (1): | 25 | Doug Evans (3): |
29 | hvf: Add hypervisor entitlement to output binaries | 26 | hw/net: Add npcm7xx emc model |
27 | hw/arm: Add npcm7xx emc model | ||
28 | tests/qtests: Add npcm7xx emc model test | ||
30 | 29 | ||
31 | Hao Wu (1): | 30 | Hao Wu (5): |
32 | hw/misc: Fix arith overflow in NPCM7XX PWM module | 31 | hw/i2c: Implement NPCM7XX SMBus Module Single Mode |
32 | hw/arm: Add I2C sensors for NPCM750 eval board | ||
33 | hw/arm: Add I2C sensors and EEPROM for GSJ machine | ||
34 | hw/i2c: Add a QTest for NPCM7XX SMBus Device | ||
35 | hw/i2c: Implement NPCM7XX SMBus Module FIFO Mode | ||
33 | 36 | ||
34 | Joelle van Dyne (7): | 37 | Luc Michel (1): |
35 | configure: cross-compiling with empty cross_prefix | 38 | MAINTAINERS: add myself maintainer for the clock framework |
36 | osdep: build with non-working system() function | ||
37 | darwin: remove redundant dependency declaration | ||
38 | darwin: fix cross-compiling for Darwin | ||
39 | configure: cross compile should use x86_64 cpu_family | ||
40 | darwin: detect CoreAudio for build | ||
41 | darwin: remove 64-bit build detection on 32-bit OS | ||
42 | 39 | ||
43 | Maxim Uvarov (3): | 40 | Richard Henderson (31): |
44 | hw: gpio: implement gpio-pwr driver for qemu reset/poweroff | 41 | tcg: Introduce target-specific page data for user-only |
45 | arm-virt: refactor gpios creation | 42 | linux-user: Introduce PAGE_ANON |
46 | arm-virt: add secure pl061 for reset/power down | 43 | exec: Use uintptr_t for guest_base |
44 | exec: Use uintptr_t in cpu_ldst.h | ||
45 | exec: Improve types for guest_addr_valid | ||
46 | linux-user: Check for overflow in access_ok | ||
47 | linux-user: Tidy VERIFY_READ/VERIFY_WRITE | ||
48 | bsd-user: Tidy VERIFY_READ/VERIFY_WRITE | ||
49 | linux-user: Do not use guest_addr_valid for h2g_valid | ||
50 | linux-user: Fix guest_addr_valid vs reserved_va | ||
51 | exec: Introduce cpu_untagged_addr | ||
52 | exec: Use cpu_untagged_addr in g2h; split out g2h_untagged | ||
53 | linux-user: Explicitly untag memory management syscalls | ||
54 | linux-user: Use guest_range_valid in access_ok | ||
55 | exec: Rename guest_{addr,range}_valid to *_untagged | ||
56 | linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged | ||
57 | linux-user: Move lock_user et al out of line | ||
58 | linux-user: Fix types in uaccess.c | ||
59 | linux-user: Handle tags in lock_user/unlock_user | ||
60 | linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE | ||
61 | target/arm: Improve gen_top_byte_ignore | ||
62 | target/arm: Use the proper TBI settings for linux-user | ||
63 | linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG | ||
64 | linux-user/aarch64: Implement PROT_MTE | ||
65 | target/arm: Split out syndrome.h from internals.h | ||
66 | linux-user/aarch64: Pass syndrome to EXC_*_ABORT | ||
67 | linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault | ||
68 | linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error | ||
69 | target/arm: Add allocation tag storage for user mode | ||
70 | target/arm: Enable MTE for user-only | ||
71 | tests/tcg/aarch64: Add mte smoke tests | ||
47 | 72 | ||
48 | Mihai Carabas (4): | 73 | docs/system/arm/nuvoton.rst | 5 +- |
49 | hw/misc/pvpanic: split-out generic and bus dependent code | 74 | bsd-user/qemu.h | 17 +- |
50 | hw/misc/pvpanic: add PCI interface support | 75 | include/exec/cpu-all.h | 47 +- |
51 | pvpanic : update pvpanic spec document | 76 | include/exec/cpu_ldst.h | 39 +- |
52 | tests/qtest: add a test case for pvpanic-pci | 77 | include/exec/exec-all.h | 2 +- |
78 | include/hw/arm/npcm7xx.h | 4 + | ||
79 | include/hw/i2c/npcm7xx_smbus.h | 113 ++++ | ||
80 | include/hw/net/npcm7xx_emc.h | 286 +++++++++ | ||
81 | linux-user/aarch64/target_signal.h | 3 + | ||
82 | linux-user/aarch64/target_syscall.h | 13 + | ||
83 | linux-user/qemu.h | 76 +-- | ||
84 | linux-user/syscall_defs.h | 1 + | ||
85 | target/arm/cpu-param.h | 3 + | ||
86 | target/arm/cpu.h | 32 + | ||
87 | target/arm/internals.h | 249 +------- | ||
88 | target/arm/syndrome.h | 273 +++++++++ | ||
89 | tests/tcg/aarch64/mte.h | 60 ++ | ||
90 | accel/tcg/translate-all.c | 32 +- | ||
91 | accel/tcg/user-exec.c | 51 +- | ||
92 | bsd-user/elfload.c | 2 +- | ||
93 | bsd-user/main.c | 8 +- | ||
94 | bsd-user/mmap.c | 23 +- | ||
95 | hw/arm/npcm7xx.c | 118 +++- | ||
96 | hw/arm/npcm7xx_boards.c | 46 ++ | ||
97 | hw/i2c/npcm7xx_smbus.c | 1099 +++++++++++++++++++++++++++++++++++ | ||
98 | hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++ | ||
99 | linux-user/aarch64/cpu_loop.c | 38 +- | ||
100 | linux-user/elfload.c | 18 +- | ||
101 | linux-user/flatload.c | 2 +- | ||
102 | linux-user/hppa/cpu_loop.c | 39 +- | ||
103 | linux-user/i386/cpu_loop.c | 6 +- | ||
104 | linux-user/i386/signal.c | 5 +- | ||
105 | linux-user/main.c | 4 +- | ||
106 | linux-user/mmap.c | 88 +-- | ||
107 | linux-user/ppc/signal.c | 4 +- | ||
108 | linux-user/syscall.c | 165 ++++-- | ||
109 | linux-user/uaccess.c | 82 ++- | ||
110 | target/arm/cpu.c | 25 +- | ||
111 | target/arm/helper-a64.c | 4 +- | ||
112 | target/arm/mte_helper.c | 39 +- | ||
113 | target/arm/tlb_helper.c | 15 +- | ||
114 | target/arm/translate-a64.c | 25 +- | ||
115 | target/hppa/op_helper.c | 2 +- | ||
116 | target/i386/tcg/mem_helper.c | 2 +- | ||
117 | target/s390x/mem_helper.c | 4 +- | ||
118 | tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++ | ||
119 | tests/qtest/npcm7xx_smbus-test.c | 495 ++++++++++++++++ | ||
120 | tests/tcg/aarch64/mte-1.c | 28 + | ||
121 | tests/tcg/aarch64/mte-2.c | 45 ++ | ||
122 | tests/tcg/aarch64/mte-3.c | 51 ++ | ||
123 | tests/tcg/aarch64/mte-4.c | 45 ++ | ||
124 | tests/tcg/aarch64/pauth-2.c | 1 - | ||
125 | MAINTAINERS | 11 + | ||
126 | hw/arm/Kconfig | 1 + | ||
127 | hw/i2c/meson.build | 1 + | ||
128 | hw/i2c/trace-events | 12 + | ||
129 | hw/net/meson.build | 1 + | ||
130 | hw/net/trace-events | 17 + | ||
131 | tests/qtest/meson.build | 2 + | ||
132 | tests/tcg/aarch64/Makefile.target | 6 + | ||
133 | tests/tcg/configure.sh | 4 + | ||
134 | 61 files changed, 5052 insertions(+), 556 deletions(-) | ||
135 | create mode 100644 include/hw/i2c/npcm7xx_smbus.h | ||
136 | create mode 100644 include/hw/net/npcm7xx_emc.h | ||
137 | create mode 100644 target/arm/syndrome.h | ||
138 | create mode 100644 tests/tcg/aarch64/mte.h | ||
139 | create mode 100644 hw/i2c/npcm7xx_smbus.c | ||
140 | create mode 100644 hw/net/npcm7xx_emc.c | ||
141 | create mode 100644 tests/qtest/npcm7xx_emc-test.c | ||
142 | create mode 100644 tests/qtest/npcm7xx_smbus-test.c | ||
143 | create mode 100644 tests/tcg/aarch64/mte-1.c | ||
144 | create mode 100644 tests/tcg/aarch64/mte-2.c | ||
145 | create mode 100644 tests/tcg/aarch64/mte-3.c | ||
146 | create mode 100644 tests/tcg/aarch64/mte-4.c | ||
53 | 147 | ||
54 | Paolo Bonzini (1): | ||
55 | arm: rename xlnx-zcu102.canbusN properties | ||
56 | |||
57 | Peter Maydell (26): | ||
58 | configure: Move preadv check to meson.build | ||
59 | ptimer: Add new ptimer_set_period_from_clock() function | ||
60 | clock: Add new clock_has_source() function | ||
61 | tests: Add a simple test of the CMSDK APB timer | ||
62 | tests: Add a simple test of the CMSDK APB watchdog | ||
63 | tests: Add a simple test of the CMSDK APB dual timer | ||
64 | hw/timer/cmsdk-apb-timer: Rename CMSDKAPBTIMER struct to CMSDKAPBTimer | ||
65 | hw/timer/cmsdk-apb-timer: Add Clock input | ||
66 | hw/timer/cmsdk-apb-dualtimer: Add Clock input | ||
67 | hw/watchdog/cmsdk-apb-watchdog: Add Clock input | ||
68 | hw/arm/armsse: Rename "MAINCLK" property to "MAINCLK_FRQ" | ||
69 | hw/arm/armsse: Wire up clocks | ||
70 | hw/arm/mps2: Inline CMSDK_APB_TIMER creation | ||
71 | hw/arm/mps2: Create and connect SYSCLK Clock | ||
72 | hw/arm/mps2-tz: Create and connect ARMSSE Clocks | ||
73 | hw/arm/musca: Create and connect ARMSSE Clocks | ||
74 | hw/arm/stellaris: Convert SSYS to QOM device | ||
75 | hw/arm/stellaris: Create Clock input for watchdog | ||
76 | hw/timer/cmsdk-apb-timer: Convert to use Clock input | ||
77 | hw/timer/cmsdk-apb-dualtimer: Convert to use Clock input | ||
78 | hw/watchdog/cmsdk-apb-watchdog: Convert to use Clock input | ||
79 | tests/qtest/cmsdk-apb-watchdog-test: Test clock changes | ||
80 | hw/arm/armsse: Use Clock to set system_clock_scale | ||
81 | arm: Don't set freq properties on CMSDK timer, dualtimer, watchdog, ARMSSE | ||
82 | arm: Remove frq properties on CMSDK timer, dualtimer, watchdog, ARMSSE | ||
83 | hw/arm/stellaris: Remove board-creation reset of STELLARIS_SYS | ||
84 | |||
85 | Philippe Mathieu-Daudé (1): | ||
86 | target/arm: Replace magic value by MMU_DATA_LOAD definition | ||
87 | |||
88 | Richard Henderson (2): | ||
89 | target/arm: Implement ID_PFR2 | ||
90 | target/arm: Conditionalize DBGDIDR | ||
91 | |||
92 | docs/devel/clocks.rst | 16 +++ | ||
93 | docs/specs/pci-ids.txt | 1 + | ||
94 | docs/specs/pvpanic.txt | 13 ++- | ||
95 | docs/system/arm/virt.rst | 2 + | ||
96 | configure | 78 ++++++++------ | ||
97 | meson.build | 34 ++++++- | ||
98 | include/hw/arm/armsse.h | 14 ++- | ||
99 | include/hw/arm/virt.h | 2 + | ||
100 | include/hw/clock.h | 15 +++ | ||
101 | include/hw/misc/pvpanic.h | 24 ++++- | ||
102 | include/hw/pci/pci.h | 1 + | ||
103 | include/hw/ptimer.h | 22 ++++ | ||
104 | include/hw/timer/cmsdk-apb-dualtimer.h | 5 +- | ||
105 | include/hw/timer/cmsdk-apb-timer.h | 34 ++----- | ||
106 | include/hw/watchdog/cmsdk-apb-watchdog.h | 5 +- | ||
107 | include/qemu/osdep.h | 12 +++ | ||
108 | include/qemu/typedefs.h | 1 + | ||
109 | target/arm/cpu.h | 1 + | ||
110 | hw/arm/armsse.c | 48 ++++++--- | ||
111 | hw/arm/mps2-tz.c | 14 ++- | ||
112 | hw/arm/mps2.c | 28 ++++- | ||
113 | hw/arm/musca.c | 13 ++- | ||
114 | hw/arm/stellaris.c | 170 +++++++++++++++++++++++-------- | ||
115 | hw/arm/virt.c | 111 ++++++++++++++++---- | ||
116 | hw/arm/xlnx-zcu102.c | 4 +- | ||
117 | hw/core/ptimer.c | 34 +++++++ | ||
118 | hw/gpio/gpio_pwr.c | 70 +++++++++++++ | ||
119 | hw/misc/npcm7xx_pwm.c | 23 ++++- | ||
120 | hw/misc/pvpanic-isa.c | 94 +++++++++++++++++ | ||
121 | hw/misc/pvpanic-pci.c | 94 +++++++++++++++++ | ||
122 | hw/misc/pvpanic.c | 85 ++-------------- | ||
123 | hw/timer/cmsdk-apb-dualtimer.c | 53 +++++++--- | ||
124 | hw/timer/cmsdk-apb-timer.c | 55 +++++----- | ||
125 | hw/watchdog/cmsdk-apb-watchdog.c | 29 ++++-- | ||
126 | target/arm/helper.c | 27 +++-- | ||
127 | target/arm/kvm64.c | 2 + | ||
128 | tests/qtest/cmsdk-apb-dualtimer-test.c | 130 +++++++++++++++++++++++ | ||
129 | tests/qtest/cmsdk-apb-timer-test.c | 75 ++++++++++++++ | ||
130 | tests/qtest/cmsdk-apb-watchdog-test.c | 131 ++++++++++++++++++++++++ | ||
131 | tests/qtest/npcm7xx_pwm-test.c | 4 +- | ||
132 | tests/qtest/pvpanic-pci-test.c | 94 +++++++++++++++++ | ||
133 | tests/qtest/xlnx-can-test.c | 30 +++--- | ||
134 | MAINTAINERS | 3 + | ||
135 | accel/hvf/entitlements.plist | 8 ++ | ||
136 | hw/arm/Kconfig | 1 + | ||
137 | hw/gpio/Kconfig | 3 + | ||
138 | hw/gpio/meson.build | 1 + | ||
139 | hw/i386/Kconfig | 2 +- | ||
140 | hw/misc/Kconfig | 12 ++- | ||
141 | hw/misc/meson.build | 4 +- | ||
142 | scripts/entitlement.sh | 13 +++ | ||
143 | tests/qtest/meson.build | 6 +- | ||
144 | 52 files changed, 1432 insertions(+), 319 deletions(-) | ||
145 | create mode 100644 hw/gpio/gpio_pwr.c | ||
146 | create mode 100644 hw/misc/pvpanic-isa.c | ||
147 | create mode 100644 hw/misc/pvpanic-pci.c | ||
148 | create mode 100644 tests/qtest/cmsdk-apb-dualtimer-test.c | ||
149 | create mode 100644 tests/qtest/cmsdk-apb-timer-test.c | ||
150 | create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c | ||
151 | create mode 100644 tests/qtest/pvpanic-pci-test.c | ||
152 | create mode 100644 accel/hvf/entitlements.plist | ||
153 | create mode 100755 scripts/entitlement.sh | ||
154 | diff view generated by jsdifflib |
1 | From: Maxim Uvarov <maxim.uvarov@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | No functional change. Just refactor code to better | 3 | This data can be allocated by page_alloc_target_data() and |
4 | support secure and normal world gpios. | 4 | released by page_set_flags(start, end, prot | PAGE_RESET). |
5 | 5 | ||
6 | Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> | 6 | This data will be used to hold tag memory for AArch64 MTE. |
7 | Reviewed-by: Andrew Jones <drjones@redhat.com> | 7 | |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20210212184902.1251044-2-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 12 | --- |
10 | hw/arm/virt.c | 57 ++++++++++++++++++++++++++++++++------------------- | 13 | include/exec/cpu-all.h | 42 +++++++++++++++++++++++++++++++++------ |
11 | 1 file changed, 36 insertions(+), 21 deletions(-) | 14 | accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++ |
15 | linux-user/mmap.c | 4 +++- | ||
16 | linux-user/syscall.c | 4 ++-- | ||
17 | 4 files changed, 69 insertions(+), 9 deletions(-) | ||
12 | 18 | ||
13 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | 19 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/arm/virt.c | 21 | --- a/include/exec/cpu-all.h |
16 | +++ b/hw/arm/virt.c | 22 | +++ b/include/exec/cpu-all.h |
17 | @@ -XXX,XX +XXX,XX @@ static void virt_powerdown_req(Notifier *n, void *opaque) | 23 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
24 | #define PAGE_EXEC 0x0004 | ||
25 | #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC) | ||
26 | #define PAGE_VALID 0x0008 | ||
27 | -/* original state of the write flag (used when tracking self-modifying | ||
28 | - code */ | ||
29 | +/* | ||
30 | + * Original state of the write flag (used when tracking self-modifying code) | ||
31 | + */ | ||
32 | #define PAGE_WRITE_ORG 0x0010 | ||
33 | -/* Invalidate the TLB entry immediately, helpful for s390x | ||
34 | - * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() */ | ||
35 | -#define PAGE_WRITE_INV 0x0040 | ||
36 | +/* | ||
37 | + * Invalidate the TLB entry immediately, helpful for s390x | ||
38 | + * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() | ||
39 | + */ | ||
40 | +#define PAGE_WRITE_INV 0x0020 | ||
41 | +/* For use with page_set_flags: page is being replaced; target_data cleared. */ | ||
42 | +#define PAGE_RESET 0x0040 | ||
43 | + | ||
44 | #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) | ||
45 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ | ||
46 | -#define PAGE_RESERVED 0x0020 | ||
47 | +#define PAGE_RESERVED 0x0100 | ||
48 | #endif | ||
49 | /* Target-specific bits that will be used via page_get_flags(). */ | ||
50 | #define PAGE_TARGET_1 0x0080 | ||
51 | @@ -XXX,XX +XXX,XX @@ int walk_memory_regions(void *, walk_memory_regions_fn); | ||
52 | int page_get_flags(target_ulong address); | ||
53 | void page_set_flags(target_ulong start, target_ulong end, int flags); | ||
54 | int page_check_range(target_ulong start, target_ulong len, int flags); | ||
55 | + | ||
56 | +/** | ||
57 | + * page_alloc_target_data(address, size) | ||
58 | + * @address: guest virtual address | ||
59 | + * @size: size of data to allocate | ||
60 | + * | ||
61 | + * Allocate @size bytes of out-of-band data to associate with the | ||
62 | + * guest page at @address. If the page is not mapped, NULL will | ||
63 | + * be returned. If there is existing data associated with @address, | ||
64 | + * no new memory will be allocated. | ||
65 | + * | ||
66 | + * The memory will be freed when the guest page is deallocated, | ||
67 | + * e.g. with the munmap system call. | ||
68 | + */ | ||
69 | +void *page_alloc_target_data(target_ulong address, size_t size); | ||
70 | + | ||
71 | +/** | ||
72 | + * page_get_target_data(address) | ||
73 | + * @address: guest virtual address | ||
74 | + * | ||
75 | + * Return any out-of-bound memory assocated with the guest page | ||
76 | + * at @address, as per page_alloc_target_data. | ||
77 | + */ | ||
78 | +void *page_get_target_data(target_ulong address); | ||
79 | #endif | ||
80 | |||
81 | CPUArchState *cpu_copy(CPUArchState *env); | ||
82 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/accel/tcg/translate-all.c | ||
85 | +++ b/accel/tcg/translate-all.c | ||
86 | @@ -XXX,XX +XXX,XX @@ typedef struct PageDesc { | ||
87 | unsigned int code_write_count; | ||
88 | #else | ||
89 | unsigned long flags; | ||
90 | + void *target_data; | ||
91 | #endif | ||
92 | #ifndef CONFIG_USER_ONLY | ||
93 | QemuSpin lock; | ||
94 | @@ -XXX,XX +XXX,XX @@ int page_get_flags(target_ulong address) | ||
95 | void page_set_flags(target_ulong start, target_ulong end, int flags) | ||
96 | { | ||
97 | target_ulong addr, len; | ||
98 | + bool reset_target_data; | ||
99 | |||
100 | /* This function should never be called with addresses outside the | ||
101 | guest address space. If this assert fires, it probably indicates | ||
102 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) | ||
103 | if (flags & PAGE_WRITE) { | ||
104 | flags |= PAGE_WRITE_ORG; | ||
105 | } | ||
106 | + reset_target_data = !(flags & PAGE_VALID) || (flags & PAGE_RESET); | ||
107 | + flags &= ~PAGE_RESET; | ||
108 | |||
109 | for (addr = start, len = end - start; | ||
110 | len != 0; | ||
111 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) | ||
112 | p->first_tb) { | ||
113 | tb_invalidate_phys_page(addr, 0); | ||
114 | } | ||
115 | + if (reset_target_data && p->target_data) { | ||
116 | + g_free(p->target_data); | ||
117 | + p->target_data = NULL; | ||
118 | + } | ||
119 | p->flags = flags; | ||
18 | } | 120 | } |
19 | } | 121 | } |
20 | 122 | ||
21 | -static void create_gpio(const VirtMachineState *vms) | 123 | +void *page_get_target_data(target_ulong address) |
22 | +static void create_gpio_keys(const VirtMachineState *vms, | ||
23 | + DeviceState *pl061_dev, | ||
24 | + uint32_t phandle) | ||
25 | +{ | 124 | +{ |
26 | + gpio_key_dev = sysbus_create_simple("gpio-key", -1, | 125 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); |
27 | + qdev_get_gpio_in(pl061_dev, 3)); | 126 | + return p ? p->target_data : NULL; |
28 | + | ||
29 | + qemu_fdt_add_subnode(vms->fdt, "/gpio-keys"); | ||
30 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-keys", "compatible", "gpio-keys"); | ||
31 | + qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#size-cells", 0); | ||
32 | + qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1); | ||
33 | + | ||
34 | + qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff"); | ||
35 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff", | ||
36 | + "label", "GPIO Key Poweroff"); | ||
37 | + qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code", | ||
38 | + KEY_POWER); | ||
39 | + qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff", | ||
40 | + "gpios", phandle, 3, 0); | ||
41 | +} | 127 | +} |
42 | + | 128 | + |
43 | +static void create_gpio_devices(const VirtMachineState *vms, int gpio, | 129 | +void *page_alloc_target_data(target_ulong address, size_t size) |
44 | + MemoryRegion *mem) | 130 | +{ |
131 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); | ||
132 | + void *ret = NULL; | ||
133 | + | ||
134 | + if (p->flags & PAGE_VALID) { | ||
135 | + ret = p->target_data; | ||
136 | + if (!ret) { | ||
137 | + p->target_data = ret = g_malloc0(size); | ||
138 | + } | ||
139 | + } | ||
140 | + return ret; | ||
141 | +} | ||
142 | + | ||
143 | int page_check_range(target_ulong start, target_ulong len, int flags) | ||
45 | { | 144 | { |
46 | char *nodename; | 145 | PageDesc *p; |
47 | DeviceState *pl061_dev; | 146 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
48 | - hwaddr base = vms->memmap[VIRT_GPIO].base; | 147 | index XXXXXXX..XXXXXXX 100644 |
49 | - hwaddr size = vms->memmap[VIRT_GPIO].size; | 148 | --- a/linux-user/mmap.c |
50 | - int irq = vms->irqmap[VIRT_GPIO]; | 149 | +++ b/linux-user/mmap.c |
51 | + hwaddr base = vms->memmap[gpio].base; | 150 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
52 | + hwaddr size = vms->memmap[gpio].size; | 151 | } |
53 | + int irq = vms->irqmap[gpio]; | ||
54 | const char compat[] = "arm,pl061\0arm,primecell"; | ||
55 | + SysBusDevice *s; | ||
56 | |||
57 | - pl061_dev = sysbus_create_simple("pl061", base, | ||
58 | - qdev_get_gpio_in(vms->gic, irq)); | ||
59 | + pl061_dev = qdev_new("pl061"); | ||
60 | + s = SYS_BUS_DEVICE(pl061_dev); | ||
61 | + sysbus_realize_and_unref(s, &error_fatal); | ||
62 | + memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0)); | ||
63 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); | ||
64 | |||
65 | uint32_t phandle = qemu_fdt_alloc_phandle(vms->fdt); | ||
66 | nodename = g_strdup_printf("/pl061@%" PRIx64, base); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void create_gpio(const VirtMachineState *vms) | ||
68 | qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk"); | ||
69 | qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle); | ||
70 | |||
71 | - gpio_key_dev = sysbus_create_simple("gpio-key", -1, | ||
72 | - qdev_get_gpio_in(pl061_dev, 3)); | ||
73 | - qemu_fdt_add_subnode(vms->fdt, "/gpio-keys"); | ||
74 | - qemu_fdt_setprop_string(vms->fdt, "/gpio-keys", "compatible", "gpio-keys"); | ||
75 | - qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#size-cells", 0); | ||
76 | - qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1); | ||
77 | - | ||
78 | - qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff"); | ||
79 | - qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff", | ||
80 | - "label", "GPIO Key Poweroff"); | ||
81 | - qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code", | ||
82 | - KEY_POWER); | ||
83 | - qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff", | ||
84 | - "gpios", phandle, 3, 0); | ||
85 | g_free(nodename); | ||
86 | + | ||
87 | + /* Child gpio devices */ | ||
88 | + create_gpio_keys(vms, pl061_dev, phandle); | ||
89 | } | ||
90 | |||
91 | static void create_virtio_devices(const VirtMachineState *vms) | ||
92 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | ||
93 | if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) { | ||
94 | vms->acpi_dev = create_acpi_ged(vms); | ||
95 | } else { | ||
96 | - create_gpio(vms); | ||
97 | + create_gpio_devices(vms, VIRT_GPIO, sysmem); | ||
98 | } | 152 | } |
99 | 153 | the_end1: | |
100 | /* connect powerdown request */ | 154 | + page_flags |= PAGE_RESET; |
155 | page_set_flags(start, start + len, page_flags); | ||
156 | the_end: | ||
157 | trace_target_mmap_complete(start); | ||
158 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
159 | new_addr = h2g(host_addr); | ||
160 | prot = page_get_flags(old_addr); | ||
161 | page_set_flags(old_addr, old_addr + old_size, 0); | ||
162 | - page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); | ||
163 | + page_set_flags(new_addr, new_addr + new_size, | ||
164 | + prot | PAGE_VALID | PAGE_RESET); | ||
165 | } | ||
166 | tb_invalidate_phys_range(new_addr, new_addr + new_size); | ||
167 | mmap_unlock(); | ||
168 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
169 | index XXXXXXX..XXXXXXX 100644 | ||
170 | --- a/linux-user/syscall.c | ||
171 | +++ b/linux-user/syscall.c | ||
172 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
173 | raddr=h2g((unsigned long)host_raddr); | ||
174 | |||
175 | page_set_flags(raddr, raddr + shm_info.shm_segsz, | ||
176 | - PAGE_VALID | PAGE_READ | | ||
177 | - ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); | ||
178 | + PAGE_VALID | PAGE_RESET | PAGE_READ | | ||
179 | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); | ||
180 | |||
181 | for (i = 0; i < N_SHM_REGIONS; i++) { | ||
182 | if (!shm_regions[i].in_use) { | ||
101 | -- | 183 | -- |
102 | 2.20.1 | 184 | 2.20.1 |
103 | 185 | ||
104 | 186 | diff view generated by jsdifflib |
1 | Now that the watchdog device uses its Clock input rather than being | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | passed the value of system_clock_scale at creation time, we can | ||
3 | remove the hack where we reset the STELLARIS_SYS at board creation | ||
4 | time to force it to set system_clock_scale. Instead it will be reset | ||
5 | at the usual point in startup and will inform the watchdog of the | ||
6 | clock frequency at that point. | ||
7 | 2 | ||
3 | Record whether the backing page is anonymous, or if it has file | ||
4 | backing. This will allow us to get close to the Linux AArch64 | ||
5 | ABI for MTE, which allows tag memory only on ram-backed VMAs. | ||
6 | |||
7 | The real ABI allows tag memory on files, when those files are | ||
8 | on ram-backed filesystems, such as tmpfs. We will not be able | ||
9 | to implement that in QEMU linux-user. | ||
10 | |||
11 | Thankfully, anonymous memory for malloc arenas is the primary | ||
12 | consumer of this feature, so this restricted version should | ||
13 | still be of use. | ||
14 | |||
15 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Message-id: 20210212184902.1251044-3-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
10 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Message-id: 20210128114145.20536-26-peter.maydell@linaro.org | ||
13 | Message-id: 20210121190622.22000-26-peter.maydell@linaro.org | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | --- | 19 | --- |
16 | hw/arm/stellaris.c | 10 ---------- | 20 | include/exec/cpu-all.h | 2 ++ |
17 | 1 file changed, 10 deletions(-) | 21 | linux-user/mmap.c | 3 +++ |
22 | 2 files changed, 5 insertions(+) | ||
18 | 23 | ||
19 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | 24 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/arm/stellaris.c | 26 | --- a/include/exec/cpu-all.h |
22 | +++ b/hw/arm/stellaris.c | 27 | +++ b/include/exec/cpu-all.h |
23 | @@ -XXX,XX +XXX,XX @@ static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq, | 28 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
24 | sysbus_mmio_map(sbd, 0, base); | 29 | #define PAGE_WRITE_INV 0x0020 |
25 | sysbus_connect_irq(sbd, 0, irq); | 30 | /* For use with page_set_flags: page is being replaced; target_data cleared. */ |
26 | 31 | #define PAGE_RESET 0x0040 | |
27 | - /* | 32 | +/* For linux-user, indicates that the page is MAP_ANON. */ |
28 | - * Normally we should not be resetting devices like this during | 33 | +#define PAGE_ANON 0x0080 |
29 | - * board creation. For the moment we need to do so, because | 34 | |
30 | - * system_clock_scale will only get set when the STELLARIS_SYS | 35 | #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) |
31 | - * device is reset, and we need its initial value to pass to | 36 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ |
32 | - * the watchdog device. This hack can be removed once the | 37 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
33 | - * watchdog has been converted to use a Clock input instead. | 38 | index XXXXXXX..XXXXXXX 100644 |
34 | - */ | 39 | --- a/linux-user/mmap.c |
35 | - device_cold_reset(dev); | 40 | +++ b/linux-user/mmap.c |
36 | - | 41 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
37 | return dev; | 42 | } |
38 | } | 43 | } |
39 | 44 | the_end1: | |
45 | + if (flags & MAP_ANONYMOUS) { | ||
46 | + page_flags |= PAGE_ANON; | ||
47 | + } | ||
48 | page_flags |= PAGE_RESET; | ||
49 | page_set_flags(start, start + len, page_flags); | ||
50 | the_end: | ||
40 | -- | 51 | -- |
41 | 2.20.1 | 52 | 2.20.1 |
42 | 53 | ||
43 | 54 | diff view generated by jsdifflib |
1 | Create a fixed-frequency Clock object to be the SYSCLK, and wire it | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | up to the devices that require it. | ||
3 | 2 | ||
3 | This is more descriptive than 'unsigned long'. | ||
4 | No functional change, since these match on all linux+bsd hosts. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 20210212184902.1251044-4-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-14-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-14-peter.maydell@linaro.org | ||
10 | --- | 11 | --- |
11 | hw/arm/mps2.c | 9 +++++++++ | 12 | include/exec/cpu-all.h | 2 +- |
12 | 1 file changed, 9 insertions(+) | 13 | bsd-user/main.c | 4 ++-- |
14 | linux-user/elfload.c | 4 ++-- | ||
15 | linux-user/main.c | 4 ++-- | ||
16 | 4 files changed, 7 insertions(+), 7 deletions(-) | ||
13 | 17 | ||
14 | diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c | 18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
15 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/mps2.c | 20 | --- a/include/exec/cpu-all.h |
17 | +++ b/hw/arm/mps2.c | 21 | +++ b/include/exec/cpu-all.h |
22 | @@ -XXX,XX +XXX,XX @@ static inline void tswap64s(uint64_t *s) | ||
23 | /* On some host systems the guest address space is reserved on the host. | ||
24 | * This allows the guest address space to be offset to a convenient location. | ||
25 | */ | ||
26 | -extern unsigned long guest_base; | ||
27 | +extern uintptr_t guest_base; | ||
28 | extern bool have_guest_base; | ||
29 | extern unsigned long reserved_va; | ||
30 | |||
31 | diff --git a/bsd-user/main.c b/bsd-user/main.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/bsd-user/main.c | ||
34 | +++ b/bsd-user/main.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | 35 | @@ -XXX,XX +XXX,XX @@ |
19 | #include "hw/net/lan9118.h" | 36 | |
20 | #include "net/net.h" | 37 | int singlestep; |
21 | #include "hw/watchdog/cmsdk-apb-watchdog.h" | 38 | unsigned long mmap_min_addr; |
22 | +#include "hw/qdev-clock.h" | 39 | -unsigned long guest_base; |
23 | #include "qom/object.h" | 40 | +uintptr_t guest_base; |
24 | 41 | bool have_guest_base; | |
25 | typedef enum MPS2FPGAType { | 42 | unsigned long reserved_va; |
26 | @@ -XXX,XX +XXX,XX @@ struct MPS2MachineState { | 43 | |
27 | CMSDKAPBDualTimer dualtimer; | 44 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
28 | CMSDKAPBWatchdog watchdog; | 45 | g_free(target_environ); |
29 | CMSDKAPBTimer timer[2]; | 46 | |
30 | + Clock *sysclk; | 47 | if (qemu_loglevel_mask(CPU_LOG_PAGE)) { |
31 | }; | 48 | - qemu_log("guest_base 0x%lx\n", guest_base); |
32 | 49 | + qemu_log("guest_base %p\n", (void *)guest_base); | |
33 | #define TYPE_MPS2_MACHINE "mps2" | 50 | log_page_dump("binary load"); |
34 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | 51 | |
52 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); | ||
53 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/linux-user/elfload.c | ||
56 | +++ b/linux-user/elfload.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, | ||
58 | void *addr, *test; | ||
59 | |||
60 | if (!QEMU_IS_ALIGNED(guest_base, align)) { | ||
61 | - fprintf(stderr, "Requested guest base 0x%lx does not satisfy " | ||
62 | + fprintf(stderr, "Requested guest base %p does not satisfy " | ||
63 | "host minimum alignment (0x%lx)\n", | ||
64 | - guest_base, align); | ||
65 | + (void *)guest_base, align); | ||
35 | exit(EXIT_FAILURE); | 66 | exit(EXIT_FAILURE); |
36 | } | 67 | } |
37 | 68 | ||
38 | + /* This clock doesn't need migration because it is fixed-frequency */ | 69 | diff --git a/linux-user/main.c b/linux-user/main.c |
39 | + mms->sysclk = clock_new(OBJECT(machine), "SYSCLK"); | 70 | index XXXXXXX..XXXXXXX 100644 |
40 | + clock_set_hz(mms->sysclk, SYSCLK_FRQ); | 71 | --- a/linux-user/main.c |
41 | + | 72 | +++ b/linux-user/main.c |
42 | /* The FPGA images have an odd combination of different RAMs, | 73 | @@ -XXX,XX +XXX,XX @@ static const char *cpu_model; |
43 | * because in hardware they are different implementations and | 74 | static const char *cpu_type; |
44 | * connected to different buses, giving varying performance/size | 75 | static const char *seed_optarg; |
45 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | 76 | unsigned long mmap_min_addr; |
46 | TYPE_CMSDK_APB_TIMER); | 77 | -unsigned long guest_base; |
47 | sbd = SYS_BUS_DEVICE(&mms->timer[i]); | 78 | +uintptr_t guest_base; |
48 | qdev_prop_set_uint32(DEVICE(&mms->timer[i]), "pclk-frq", SYSCLK_FRQ); | 79 | bool have_guest_base; |
49 | + qdev_connect_clock_in(DEVICE(&mms->timer[i]), "pclk", mms->sysclk); | 80 | |
50 | sysbus_realize_and_unref(sbd, &error_fatal); | 81 | /* |
51 | sysbus_mmio_map(sbd, 0, base); | 82 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) |
52 | sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(armv7m, irqno)); | 83 | g_free(target_environ); |
53 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | 84 | |
54 | object_initialize_child(OBJECT(mms), "dualtimer", &mms->dualtimer, | 85 | if (qemu_loglevel_mask(CPU_LOG_PAGE)) { |
55 | TYPE_CMSDK_APB_DUALTIMER); | 86 | - qemu_log("guest_base 0x%lx\n", guest_base); |
56 | qdev_prop_set_uint32(DEVICE(&mms->dualtimer), "pclk-frq", SYSCLK_FRQ); | 87 | + qemu_log("guest_base %p\n", (void *)guest_base); |
57 | + qdev_connect_clock_in(DEVICE(&mms->dualtimer), "TIMCLK", mms->sysclk); | 88 | log_page_dump("binary load"); |
58 | sysbus_realize(SYS_BUS_DEVICE(&mms->dualtimer), &error_fatal); | 89 | |
59 | sysbus_connect_irq(SYS_BUS_DEVICE(&mms->dualtimer), 0, | 90 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); |
60 | qdev_get_gpio_in(armv7m, 10)); | ||
61 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
62 | object_initialize_child(OBJECT(mms), "watchdog", &mms->watchdog, | ||
63 | TYPE_CMSDK_APB_WATCHDOG); | ||
64 | qdev_prop_set_uint32(DEVICE(&mms->watchdog), "wdogclk-frq", SYSCLK_FRQ); | ||
65 | + qdev_connect_clock_in(DEVICE(&mms->watchdog), "WDOGCLK", mms->sysclk); | ||
66 | sysbus_realize(SYS_BUS_DEVICE(&mms->watchdog), &error_fatal); | ||
67 | sysbus_connect_irq(SYS_BUS_DEVICE(&mms->watchdog), 0, | ||
68 | qdev_get_gpio_in_named(armv7m, "NMI", 0)); | ||
69 | -- | 91 | -- |
70 | 2.20.1 | 92 | 2.20.1 |
71 | 93 | ||
72 | 94 | diff view generated by jsdifflib |
1 | Now that the CMSDK APB watchdog uses its Clock input, it will | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | correctly respond when the system clock frequency is changed using | ||
3 | the RCC register on in the Stellaris board system registers. Test | ||
4 | that when the RCC register is written it causes the watchdog timer to | ||
5 | change speed. | ||
6 | 2 | ||
3 | This is more descriptive than 'unsigned long'. | ||
4 | No functional change, since these match on all linux+bsd hosts. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 20210212184902.1251044-5-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
10 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20210128114145.20536-22-peter.maydell@linaro.org | ||
12 | Message-id: 20210121190622.22000-22-peter.maydell@linaro.org | ||
13 | --- | 11 | --- |
14 | tests/qtest/cmsdk-apb-watchdog-test.c | 52 +++++++++++++++++++++++++++ | 12 | include/exec/cpu_ldst.h | 6 +++--- |
15 | 1 file changed, 52 insertions(+) | 13 | 1 file changed, 3 insertions(+), 3 deletions(-) |
16 | 14 | ||
17 | diff --git a/tests/qtest/cmsdk-apb-watchdog-test.c b/tests/qtest/cmsdk-apb-watchdog-test.c | 15 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tests/qtest/cmsdk-apb-watchdog-test.c | 17 | --- a/include/exec/cpu_ldst.h |
20 | +++ b/tests/qtest/cmsdk-apb-watchdog-test.c | 18 | +++ b/include/exec/cpu_ldst.h |
21 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
22 | */ | 20 | #endif |
23 | 21 | ||
24 | #include "qemu/osdep.h" | 22 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
25 | +#include "qemu/bitops.h" | 23 | -#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) |
26 | #include "libqtest-single.h" | 24 | +#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
27 | 25 | ||
28 | /* | 26 | #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
29 | @@ -XXX,XX +XXX,XX @@ | 27 | #define guest_addr_valid(x) (1) |
30 | #define WDOGMIS 0x14 | 28 | #else |
31 | #define WDOGLOCK 0xc00 | 29 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
32 | 30 | #endif | |
33 | +#define SSYS_BASE 0x400fe000 | 31 | -#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) |
34 | +#define RCC 0x60 | 32 | +#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) |
35 | +#define SYSDIV_SHIFT 23 | 33 | |
36 | +#define SYSDIV_LENGTH 4 | 34 | static inline int guest_range_valid(unsigned long start, unsigned long len) |
37 | + | ||
38 | static void test_watchdog(void) | ||
39 | { | 35 | { |
40 | g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | 36 | @@ -XXX,XX +XXX,XX @@ static inline int guest_range_valid(unsigned long start, unsigned long len) |
41 | @@ -XXX,XX +XXX,XX @@ static void test_watchdog(void) | ||
42 | g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | ||
43 | } | 37 | } |
44 | 38 | ||
45 | +static void test_clock_change(void) | 39 | #define h2g_nocheck(x) ({ \ |
46 | +{ | 40 | - unsigned long __ret = (unsigned long)(x) - guest_base; \ |
47 | + uint32_t rcc; | 41 | + uintptr_t __ret = (uintptr_t)(x) - guest_base; \ |
48 | + | 42 | (abi_ptr)__ret; \ |
49 | + /* | 43 | }) |
50 | + * Test that writing to the stellaris board's RCC register to | ||
51 | + * change the system clock frequency causes the watchdog | ||
52 | + * to change the speed it counts at. | ||
53 | + */ | ||
54 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | ||
55 | + | ||
56 | + writel(WDOG_BASE + WDOGCONTROL, 1); | ||
57 | + writel(WDOG_BASE + WDOGLOAD, 1000); | ||
58 | + | ||
59 | + /* Step to just past the 500th tick */ | ||
60 | + clock_step(80 * 500 + 1); | ||
61 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | ||
62 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); | ||
63 | + | ||
64 | + /* Rewrite RCC.SYSDIV from 16 to 8, so the clock is now 40ns per tick */ | ||
65 | + rcc = readl(SSYS_BASE + RCC); | ||
66 | + g_assert_cmpuint(extract32(rcc, SYSDIV_SHIFT, SYSDIV_LENGTH), ==, 0xf); | ||
67 | + rcc = deposit32(rcc, SYSDIV_SHIFT, SYSDIV_LENGTH, 7); | ||
68 | + writel(SSYS_BASE + RCC, rcc); | ||
69 | + | ||
70 | + /* Just past the 1000th tick: timer should have fired */ | ||
71 | + clock_step(40 * 500); | ||
72 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); | ||
73 | + | ||
74 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); | ||
75 | + | ||
76 | + /* VALUE reloads at following tick */ | ||
77 | + clock_step(41); | ||
78 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); | ||
79 | + | ||
80 | + /* Writing any value to WDOGINTCLR clears the interrupt and reloads */ | ||
81 | + clock_step(40 * 500); | ||
82 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); | ||
83 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); | ||
84 | + writel(WDOG_BASE + WDOGINTCLR, 0); | ||
85 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); | ||
86 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | ||
87 | +} | ||
88 | + | ||
89 | int main(int argc, char **argv) | ||
90 | { | ||
91 | int r; | ||
92 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
93 | qtest_start("-machine lm3s811evb"); | ||
94 | |||
95 | qtest_add_func("/cmsdk-apb-watchdog/watchdog", test_watchdog); | ||
96 | + qtest_add_func("/cmsdk-apb-watchdog/watchdog_clock_change", | ||
97 | + test_clock_change); | ||
98 | |||
99 | r = g_test_run(); | ||
100 | 44 | ||
101 | -- | 45 | -- |
102 | 2.20.1 | 46 | 2.20.1 |
103 | 47 | ||
104 | 48 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | cpu_get_phys_page_debug() uses 'DATA LOAD' MMU access type. | 3 | Return bool not int; pass abi_ulong not 'unsigned long'. |
4 | All callers use abi_ulong already, so the change in type | ||
5 | has no effect. | ||
4 | 6 | ||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Message-id: 20210127232822.3530782-1-f4bug@amsat.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 20210212184902.1251044-6-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 12 | --- |
10 | target/arm/helper.c | 2 +- | 13 | include/exec/cpu_ldst.h | 2 +- |
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | 15 | ||
13 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 16 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.c | 18 | --- a/include/exec/cpu_ldst.h |
16 | +++ b/target/arm/helper.c | 19 | +++ b/include/exec/cpu_ldst.h |
17 | @@ -XXX,XX +XXX,XX @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, | 20 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
18 | 21 | #endif | |
19 | *attrs = (MemTxAttrs) {}; | 22 | #define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) |
20 | 23 | ||
21 | - ret = get_phys_addr(env, addr, 0, mmu_idx, &phys_addr, | 24 | -static inline int guest_range_valid(unsigned long start, unsigned long len) |
22 | + ret = get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &phys_addr, | 25 | +static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
23 | attrs, &prot, &page_size, &fi, &cacheattrs); | 26 | { |
24 | 27 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; | |
25 | if (ret) { | 28 | } |
26 | -- | 29 | -- |
27 | 2.20.1 | 30 | 2.20.1 |
28 | 31 | ||
29 | 32 | diff view generated by jsdifflib |
1 | Now no users are setting the frq properties on the CMSDK timer, | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | dualtimer, watchdog or ARMSSE SoC devices, we can remove the | ||
3 | properties and the struct fields that back them. | ||
4 | 2 | ||
3 | Verify that addr + size - 1 does not wrap around. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20210212184902.1251044-7-richard.henderson@linaro.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 20210128114145.20536-25-peter.maydell@linaro.org | ||
10 | Message-id: 20210121190622.22000-25-peter.maydell@linaro.org | ||
11 | --- | 9 | --- |
12 | include/hw/arm/armsse.h | 2 -- | 10 | linux-user/qemu.h | 17 ++++++++++++----- |
13 | include/hw/timer/cmsdk-apb-dualtimer.h | 2 -- | 11 | 1 file changed, 12 insertions(+), 5 deletions(-) |
14 | include/hw/timer/cmsdk-apb-timer.h | 2 -- | ||
15 | include/hw/watchdog/cmsdk-apb-watchdog.h | 2 -- | ||
16 | hw/arm/armsse.c | 2 -- | ||
17 | hw/timer/cmsdk-apb-dualtimer.c | 6 ------ | ||
18 | hw/timer/cmsdk-apb-timer.c | 6 ------ | ||
19 | hw/watchdog/cmsdk-apb-watchdog.c | 6 ------ | ||
20 | 8 files changed, 28 deletions(-) | ||
21 | 12 | ||
22 | diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h | 13 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
23 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/arm/armsse.h | 15 | --- a/linux-user/qemu.h |
25 | +++ b/include/hw/arm/armsse.h | 16 | +++ b/linux-user/qemu.h |
26 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
27 | * + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals | 18 | #define VERIFY_READ 0 |
28 | * + QOM property "memory" is a MemoryRegion containing the devices provided | 19 | #define VERIFY_WRITE 1 /* implies read access */ |
29 | * by the board model. | 20 | |
30 | - * + QOM property "MAINCLK_FRQ" is the frequency of the main system clock | 21 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) |
31 | * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. | 22 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
32 | * (In hardware, the SSE-200 permits the number of expansion interrupts | ||
33 | * for the two CPUs to be configured separately, but we restrict it to | ||
34 | @@ -XXX,XX +XXX,XX @@ struct ARMSSE { | ||
35 | /* Properties */ | ||
36 | MemoryRegion *board_memory; | ||
37 | uint32_t exp_numirq; | ||
38 | - uint32_t mainclk_frq; | ||
39 | uint32_t sram_addr_width; | ||
40 | uint32_t init_svtor; | ||
41 | bool cpu_fpu[SSE_MAX_CPUS]; | ||
42 | diff --git a/include/hw/timer/cmsdk-apb-dualtimer.h b/include/hw/timer/cmsdk-apb-dualtimer.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/include/hw/timer/cmsdk-apb-dualtimer.h | ||
45 | +++ b/include/hw/timer/cmsdk-apb-dualtimer.h | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | * https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit | ||
48 | * | ||
49 | * QEMU interface: | ||
50 | - * + QOM property "pclk-frq": frequency at which the timer is clocked | ||
51 | * + Clock input "TIMCLK": clock (for both timers) | ||
52 | * + sysbus MMIO region 0: the register bank | ||
53 | * + sysbus IRQ 0: combined timer interrupt TIMINTC | ||
54 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBDualTimer { | ||
55 | /*< public >*/ | ||
56 | MemoryRegion iomem; | ||
57 | qemu_irq timerintc; | ||
58 | - uint32_t pclk_frq; | ||
59 | Clock *timclk; | ||
60 | |||
61 | CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES]; | ||
62 | diff --git a/include/hw/timer/cmsdk-apb-timer.h b/include/hw/timer/cmsdk-apb-timer.h | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/include/hw/timer/cmsdk-apb-timer.h | ||
65 | +++ b/include/hw/timer/cmsdk-apb-timer.h | ||
66 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER) | ||
67 | |||
68 | /* | ||
69 | * QEMU interface: | ||
70 | - * + QOM property "pclk-frq": frequency at which the timer is clocked | ||
71 | * + Clock input "pclk": clock for the timer | ||
72 | * + sysbus MMIO region 0: the register bank | ||
73 | * + sysbus IRQ 0: timer interrupt TIMERINT | ||
74 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBTimer { | ||
75 | /*< public >*/ | ||
76 | MemoryRegion iomem; | ||
77 | qemu_irq timerint; | ||
78 | - uint32_t pclk_frq; | ||
79 | struct ptimer_state *timer; | ||
80 | Clock *pclk; | ||
81 | |||
82 | diff --git a/include/hw/watchdog/cmsdk-apb-watchdog.h b/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
85 | +++ b/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | * https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit | ||
88 | * | ||
89 | * QEMU interface: | ||
90 | - * + QOM property "wdogclk-frq": frequency at which the watchdog is clocked | ||
91 | * + Clock input "WDOGCLK": clock for the watchdog's timer | ||
92 | * + sysbus MMIO region 0: the register bank | ||
93 | * + sysbus IRQ 0: watchdog interrupt | ||
94 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBWatchdog { | ||
95 | /*< public >*/ | ||
96 | MemoryRegion iomem; | ||
97 | qemu_irq wdogint; | ||
98 | - uint32_t wdogclk_frq; | ||
99 | bool is_luminary; | ||
100 | struct ptimer_state *timer; | ||
101 | Clock *wdogclk; | ||
102 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/hw/arm/armsse.c | ||
105 | +++ b/hw/arm/armsse.c | ||
106 | @@ -XXX,XX +XXX,XX @@ static Property iotkit_properties[] = { | ||
107 | DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION, | ||
108 | MemoryRegion *), | ||
109 | DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64), | ||
110 | - DEFINE_PROP_UINT32("MAINCLK_FRQ", ARMSSE, mainclk_frq, 0), | ||
111 | DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15), | ||
112 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
113 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true), | ||
114 | @@ -XXX,XX +XXX,XX @@ static Property armsse_properties[] = { | ||
115 | DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION, | ||
116 | MemoryRegion *), | ||
117 | DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64), | ||
118 | - DEFINE_PROP_UINT32("MAINCLK_FRQ", ARMSSE, mainclk_frq, 0), | ||
119 | DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15), | ||
120 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
121 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false), | ||
122 | diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/hw/timer/cmsdk-apb-dualtimer.c | ||
125 | +++ b/hw/timer/cmsdk-apb-dualtimer.c | ||
126 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { | ||
127 | } | ||
128 | }; | ||
129 | |||
130 | -static Property cmsdk_apb_dualtimer_properties[] = { | ||
131 | - DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBDualTimer, pclk_frq, 0), | ||
132 | - DEFINE_PROP_END_OF_LIST(), | ||
133 | -}; | ||
134 | - | ||
135 | static void cmsdk_apb_dualtimer_class_init(ObjectClass *klass, void *data) | ||
136 | { | 23 | { |
137 | DeviceClass *dc = DEVICE_CLASS(klass); | 24 | - return guest_addr_valid(addr) && |
138 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_class_init(ObjectClass *klass, void *data) | 25 | - (size == 0 || guest_addr_valid(addr + size - 1)) && |
139 | dc->realize = cmsdk_apb_dualtimer_realize; | 26 | - page_check_range((target_ulong)addr, size, |
140 | dc->vmsd = &cmsdk_apb_dualtimer_vmstate; | 27 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; |
141 | dc->reset = cmsdk_apb_dualtimer_reset; | 28 | + if (!guest_addr_valid(addr)) { |
142 | - device_class_set_props(dc, cmsdk_apb_dualtimer_properties); | 29 | + return false; |
30 | + } | ||
31 | + if (size != 0 && | ||
32 | + (addr + size - 1 < addr || | ||
33 | + !guest_addr_valid(addr + size - 1))) { | ||
34 | + return false; | ||
35 | + } | ||
36 | + return page_check_range((target_ulong)addr, size, | ||
37 | + (type == VERIFY_READ) ? PAGE_READ : | ||
38 | + (PAGE_READ | PAGE_WRITE)) == 0; | ||
143 | } | 39 | } |
144 | 40 | ||
145 | static const TypeInfo cmsdk_apb_dualtimer_info = { | 41 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
146 | diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/hw/timer/cmsdk-apb-timer.c | ||
149 | +++ b/hw/timer/cmsdk-apb-timer.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { | ||
151 | } | ||
152 | }; | ||
153 | |||
154 | -static Property cmsdk_apb_timer_properties[] = { | ||
155 | - DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBTimer, pclk_frq, 0), | ||
156 | - DEFINE_PROP_END_OF_LIST(), | ||
157 | -}; | ||
158 | - | ||
159 | static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) | ||
160 | { | ||
161 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
162 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) | ||
163 | dc->realize = cmsdk_apb_timer_realize; | ||
164 | dc->vmsd = &cmsdk_apb_timer_vmstate; | ||
165 | dc->reset = cmsdk_apb_timer_reset; | ||
166 | - device_class_set_props(dc, cmsdk_apb_timer_properties); | ||
167 | } | ||
168 | |||
169 | static const TypeInfo cmsdk_apb_timer_info = { | ||
170 | diff --git a/hw/watchdog/cmsdk-apb-watchdog.c b/hw/watchdog/cmsdk-apb-watchdog.c | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/hw/watchdog/cmsdk-apb-watchdog.c | ||
173 | +++ b/hw/watchdog/cmsdk-apb-watchdog.c | ||
174 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription cmsdk_apb_watchdog_vmstate = { | ||
175 | } | ||
176 | }; | ||
177 | |||
178 | -static Property cmsdk_apb_watchdog_properties[] = { | ||
179 | - DEFINE_PROP_UINT32("wdogclk-frq", CMSDKAPBWatchdog, wdogclk_frq, 0), | ||
180 | - DEFINE_PROP_END_OF_LIST(), | ||
181 | -}; | ||
182 | - | ||
183 | static void cmsdk_apb_watchdog_class_init(ObjectClass *klass, void *data) | ||
184 | { | ||
185 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
186 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_class_init(ObjectClass *klass, void *data) | ||
187 | dc->realize = cmsdk_apb_watchdog_realize; | ||
188 | dc->vmsd = &cmsdk_apb_watchdog_vmstate; | ||
189 | dc->reset = cmsdk_apb_watchdog_reset; | ||
190 | - device_class_set_props(dc, cmsdk_apb_watchdog_properties); | ||
191 | } | ||
192 | |||
193 | static const TypeInfo cmsdk_apb_watchdog_info = { | ||
194 | -- | 42 | -- |
195 | 2.20.1 | 43 | 2.20.1 |
196 | 44 | ||
197 | 45 | diff view generated by jsdifflib |
1 | As the first step in converting the CMSDK_APB_DUALTIMER device to the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | Clock framework, add a Clock input. For the moment we do nothing | ||
3 | with this clock; we will change the behaviour from using the pclk-frq | ||
4 | property to using the Clock once all the users of this device have | ||
5 | been converted to wire up the Clock. | ||
6 | 2 | ||
7 | We take the opportunity to correct the name of the clock input to | 3 | These constants are only ever used with access_ok, and friends. |
8 | match the hardware -- the dual timer names the clock which drives the | 4 | Rather than translating them to PAGE_* bits, let them equal |
9 | timers TIMCLK. (It does also have a 'pclk' input, which is used only | 5 | the PAGE_* bits to begin. |
10 | for the register and APB bus logic; on the SSE-200 these clocks are | ||
11 | both connected together.) | ||
12 | 6 | ||
13 | This is a migration compatibility break for machines mps2-an385, | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
14 | mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | musca-b1. | 9 | Message-id: 20210212184902.1251044-8-richard.henderson@linaro.org |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | linux-user/qemu.h | 8 +++----- | ||
13 | 1 file changed, 3 insertions(+), 5 deletions(-) | ||
16 | 14 | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
20 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
21 | Message-id: 20210128114145.20536-9-peter.maydell@linaro.org | ||
22 | Message-id: 20210121190622.22000-9-peter.maydell@linaro.org | ||
23 | --- | ||
24 | include/hw/timer/cmsdk-apb-dualtimer.h | 3 +++ | ||
25 | hw/timer/cmsdk-apb-dualtimer.c | 7 +++++-- | ||
26 | 2 files changed, 8 insertions(+), 2 deletions(-) | ||
27 | |||
28 | diff --git a/include/hw/timer/cmsdk-apb-dualtimer.h b/include/hw/timer/cmsdk-apb-dualtimer.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/include/hw/timer/cmsdk-apb-dualtimer.h | 17 | --- a/linux-user/qemu.h |
31 | +++ b/include/hw/timer/cmsdk-apb-dualtimer.h | 18 | +++ b/linux-user/qemu.h |
32 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
33 | * | 20 | |
34 | * QEMU interface: | 21 | /* user access */ |
35 | * + QOM property "pclk-frq": frequency at which the timer is clocked | 22 | |
36 | + * + Clock input "TIMCLK": clock (for both timers) | 23 | -#define VERIFY_READ 0 |
37 | * + sysbus MMIO region 0: the register bank | 24 | -#define VERIFY_WRITE 1 /* implies read access */ |
38 | * + sysbus IRQ 0: combined timer interrupt TIMINTC | 25 | +#define VERIFY_READ PAGE_READ |
39 | * + sysbus IRO 1: timer block 1 interrupt TIMINT1 | 26 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
40 | @@ -XXX,XX +XXX,XX @@ | 27 | |
41 | 28 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | |
42 | #include "hw/sysbus.h" | 29 | { |
43 | #include "hw/ptimer.h" | 30 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
44 | +#include "hw/clock.h" | 31 | !guest_addr_valid(addr + size - 1))) { |
45 | #include "qom/object.h" | 32 | return false; |
46 | |||
47 | #define TYPE_CMSDK_APB_DUALTIMER "cmsdk-apb-dualtimer" | ||
48 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBDualTimer { | ||
49 | MemoryRegion iomem; | ||
50 | qemu_irq timerintc; | ||
51 | uint32_t pclk_frq; | ||
52 | + Clock *timclk; | ||
53 | |||
54 | CMSDKAPBDualTimerModule timermod[CMSDK_APB_DUALTIMER_NUM_MODULES]; | ||
55 | uint32_t timeritcr; | ||
56 | diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/hw/timer/cmsdk-apb-dualtimer.c | ||
59 | +++ b/hw/timer/cmsdk-apb-dualtimer.c | ||
60 | @@ -XXX,XX +XXX,XX @@ | ||
61 | #include "hw/irq.h" | ||
62 | #include "hw/qdev-properties.h" | ||
63 | #include "hw/registerfields.h" | ||
64 | +#include "hw/qdev-clock.h" | ||
65 | #include "hw/timer/cmsdk-apb-dualtimer.h" | ||
66 | #include "migration/vmstate.h" | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_init(Object *obj) | ||
69 | for (i = 0; i < ARRAY_SIZE(s->timermod); i++) { | ||
70 | sysbus_init_irq(sbd, &s->timermod[i].timerint); | ||
71 | } | 33 | } |
72 | + s->timclk = qdev_init_clock_in(DEVICE(s), "TIMCLK", NULL, NULL); | 34 | - return page_check_range((target_ulong)addr, size, |
35 | - (type == VERIFY_READ) ? PAGE_READ : | ||
36 | - (PAGE_READ | PAGE_WRITE)) == 0; | ||
37 | + return page_check_range((target_ulong)addr, size, type) == 0; | ||
73 | } | 38 | } |
74 | 39 | ||
75 | static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp) | 40 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
76 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription cmsdk_dualtimermod_vmstate = { | ||
77 | |||
78 | static const VMStateDescription cmsdk_apb_dualtimer_vmstate = { | ||
79 | .name = "cmsdk-apb-dualtimer", | ||
80 | - .version_id = 1, | ||
81 | - .minimum_version_id = 1, | ||
82 | + .version_id = 2, | ||
83 | + .minimum_version_id = 2, | ||
84 | .fields = (VMStateField[]) { | ||
85 | + VMSTATE_CLOCK(timclk, CMSDKAPBDualTimer), | ||
86 | VMSTATE_STRUCT_ARRAY(timermod, CMSDKAPBDualTimer, | ||
87 | CMSDK_APB_DUALTIMER_NUM_MODULES, | ||
88 | 1, cmsdk_dualtimermod_vmstate, | ||
89 | -- | 41 | -- |
90 | 2.20.1 | 42 | 2.20.1 |
91 | 43 | ||
92 | 44 | diff view generated by jsdifflib |
1 | As the first step in converting the CMSDK_APB_TIMER device to the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | Clock framework, add a Clock input. For the moment we do nothing | ||
3 | with this clock; we will change the behaviour from using the pclk-frq | ||
4 | property to using the Clock once all the users of this device have | ||
5 | been converted to wire up the Clock. | ||
6 | 2 | ||
7 | Since the device doesn't already have a doc comment for its "QEMU | 3 | These constants are only ever used with access_ok, and friends. |
8 | interface", we add one including the new Clock. | 4 | Rather than translating them to PAGE_* bits, let them equal |
5 | the PAGE_* bits to begin. | ||
9 | 6 | ||
10 | This is a migration compatibility break for machines mps2-an505, | 7 | Reviewed-by: Warner Losh <imp@bsdimp.com> |
11 | mps2-an521, musca-a, musca-b1. | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20210212184902.1251044-9-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | bsd-user/qemu.h | 9 ++++----- | ||
14 | 1 file changed, 4 insertions(+), 5 deletions(-) | ||
12 | 15 | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h |
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
16 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Message-id: 20210128114145.20536-8-peter.maydell@linaro.org | ||
18 | Message-id: 20210121190622.22000-8-peter.maydell@linaro.org | ||
19 | --- | ||
20 | include/hw/timer/cmsdk-apb-timer.h | 9 +++++++++ | ||
21 | hw/timer/cmsdk-apb-timer.c | 7 +++++-- | ||
22 | 2 files changed, 14 insertions(+), 2 deletions(-) | ||
23 | |||
24 | diff --git a/include/hw/timer/cmsdk-apb-timer.h b/include/hw/timer/cmsdk-apb-timer.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/include/hw/timer/cmsdk-apb-timer.h | 18 | --- a/bsd-user/qemu.h |
27 | +++ b/include/hw/timer/cmsdk-apb-timer.h | 19 | +++ b/bsd-user/qemu.h |
28 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ extern unsigned long x86_stack_size; |
29 | #include "hw/qdev-properties.h" | 21 | |
30 | #include "hw/sysbus.h" | 22 | /* user access */ |
31 | #include "hw/ptimer.h" | 23 | |
32 | +#include "hw/clock.h" | 24 | -#define VERIFY_READ 0 |
33 | #include "qom/object.h" | 25 | -#define VERIFY_WRITE 1 /* implies read access */ |
34 | 26 | +#define VERIFY_READ PAGE_READ | |
35 | #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" | 27 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
36 | OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER) | 28 | |
37 | 29 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) | |
38 | +/* | 30 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
39 | + * QEMU interface: | 31 | { |
40 | + * + QOM property "pclk-frq": frequency at which the timer is clocked | 32 | - return page_check_range((target_ulong)addr, size, |
41 | + * + Clock input "pclk": clock for the timer | 33 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; |
42 | + * + sysbus MMIO region 0: the register bank | 34 | + return page_check_range((target_ulong)addr, size, type) == 0; |
43 | + * + sysbus IRQ 0: timer interrupt TIMERINT | ||
44 | + */ | ||
45 | struct CMSDKAPBTimer { | ||
46 | /*< private >*/ | ||
47 | SysBusDevice parent_obj; | ||
48 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBTimer { | ||
49 | qemu_irq timerint; | ||
50 | uint32_t pclk_frq; | ||
51 | struct ptimer_state *timer; | ||
52 | + Clock *pclk; | ||
53 | |||
54 | uint32_t ctrl; | ||
55 | uint32_t value; | ||
56 | diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/hw/timer/cmsdk-apb-timer.c | ||
59 | +++ b/hw/timer/cmsdk-apb-timer.c | ||
60 | @@ -XXX,XX +XXX,XX @@ | ||
61 | #include "hw/sysbus.h" | ||
62 | #include "hw/irq.h" | ||
63 | #include "hw/registerfields.h" | ||
64 | +#include "hw/qdev-clock.h" | ||
65 | #include "hw/timer/cmsdk-apb-timer.h" | ||
66 | #include "migration/vmstate.h" | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_init(Object *obj) | ||
69 | s, "cmsdk-apb-timer", 0x1000); | ||
70 | sysbus_init_mmio(sbd, &s->iomem); | ||
71 | sysbus_init_irq(sbd, &s->timerint); | ||
72 | + s->pclk = qdev_init_clock_in(DEVICE(s), "pclk", NULL, NULL); | ||
73 | } | 35 | } |
74 | 36 | ||
75 | static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) | 37 | /* NOTE __get_user and __put_user use host pointers and don't check access. */ |
76 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) | ||
77 | |||
78 | static const VMStateDescription cmsdk_apb_timer_vmstate = { | ||
79 | .name = "cmsdk-apb-timer", | ||
80 | - .version_id = 1, | ||
81 | - .minimum_version_id = 1, | ||
82 | + .version_id = 2, | ||
83 | + .minimum_version_id = 2, | ||
84 | .fields = (VMStateField[]) { | ||
85 | VMSTATE_PTIMER(timer, CMSDKAPBTimer), | ||
86 | + VMSTATE_CLOCK(pclk, CMSDKAPBTimer), | ||
87 | VMSTATE_UINT32(ctrl, CMSDKAPBTimer), | ||
88 | VMSTATE_UINT32(value, CMSDKAPBTimer), | ||
89 | VMSTATE_UINT32(reload, CMSDKAPBTimer), | ||
90 | -- | 38 | -- |
91 | 2.20.1 | 39 | 2.20.1 |
92 | 40 | ||
93 | 41 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 3 | This is the only use of guest_addr_valid that does not begin |
4 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 4 | with a guest address, but a host address being transformed to |
5 | Message-id: 20210126012457.39046-9-j@getutm.app | 5 | a guest address. |
6 | |||
7 | We will shortly adjust guest_addr_valid to handle guest memory | ||
8 | tags, and the host address should not be subjected to that. | ||
9 | |||
10 | Move h2g_valid adjacent to the other h2g macros. | ||
11 | |||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20210212184902.1251044-10-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 16 | --- |
8 | configure | 5 ++++- | 17 | include/exec/cpu_ldst.h | 5 ++++- |
9 | 1 file changed, 4 insertions(+), 1 deletion(-) | 18 | 1 file changed, 4 insertions(+), 1 deletion(-) |
10 | 19 | ||
11 | diff --git a/configure b/configure | 20 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
12 | index XXXXXXX..XXXXXXX 100755 | 21 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/configure | 22 | --- a/include/exec/cpu_ldst.h |
14 | +++ b/configure | 23 | +++ b/include/exec/cpu_ldst.h |
15 | @@ -XXX,XX +XXX,XX @@ if test "$cross_compile" = "yes"; then | 24 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
16 | echo "system = 'darwin'" >> $cross | 25 | #else |
17 | fi | 26 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
18 | case "$ARCH" in | 27 | #endif |
19 | - i386|x86_64) | 28 | -#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) |
20 | + i386) | 29 | |
21 | echo "cpu_family = 'x86'" >> $cross | 30 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
22 | ;; | 31 | { |
23 | + x86_64) | 32 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
24 | + echo "cpu_family = 'x86_64'" >> $cross | 33 | } |
25 | + ;; | 34 | |
26 | ppc64le) | 35 | +#define h2g_valid(x) \ |
27 | echo "cpu_family = 'ppc64'" >> $cross | 36 | + (HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS || \ |
28 | ;; | 37 | + (uintptr_t)(x) - guest_base <= GUEST_ADDR_MAX) |
38 | + | ||
39 | #define h2g_nocheck(x) ({ \ | ||
40 | uintptr_t __ret = (uintptr_t)(x) - guest_base; \ | ||
41 | (abi_ptr)__ret; \ | ||
29 | -- | 42 | -- |
30 | 2.20.1 | 43 | 2.20.1 |
31 | 44 | ||
32 | 45 | diff view generated by jsdifflib |
1 | The ptimer API currently provides two methods for setting the period: | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | ptimer_set_period(), which takes a period in nanoseconds, and | ||
3 | ptimer_set_freq(), which takes a frequency in Hz. Neither of these | ||
4 | lines up nicely with the Clock API, because although both the Clock | ||
5 | and the ptimer track the frequency using a representation of whole | ||
6 | and fractional nanoseconds, conversion via either period-in-ns or | ||
7 | frequency-in-Hz will introduce a rounding error. | ||
8 | 2 | ||
9 | Add a new function ptimer_set_period_from_clock() which takes the | 3 | We must always use GUEST_ADDR_MAX, because even 32-bit hosts can |
10 | Clock object directly to avoid the rounding issues. This includes a | 4 | use -R <reserved_va> to restrict the memory address of the guest. |
11 | facility for the user to specify that there is a frequency divider | ||
12 | between the Clock proper and the timer, as some timer devices like | ||
13 | the CMSDK APB dualtimer need this. | ||
14 | 5 | ||
15 | To avoid having to drag in clock.h from ptimer.h we add the Clock | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
16 | type to typedefs.h. | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20210212184902.1251044-11-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | include/exec/cpu_ldst.h | 9 ++++----- | ||
12 | 1 file changed, 4 insertions(+), 5 deletions(-) | ||
17 | 13 | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
19 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
20 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
22 | Message-id: 20210128114145.20536-2-peter.maydell@linaro.org | ||
23 | Message-id: 20210121190622.22000-2-peter.maydell@linaro.org | ||
24 | --- | ||
25 | include/hw/ptimer.h | 22 ++++++++++++++++++++++ | ||
26 | include/qemu/typedefs.h | 1 + | ||
27 | hw/core/ptimer.c | 34 ++++++++++++++++++++++++++++++++++ | ||
28 | 3 files changed, 57 insertions(+) | ||
29 | |||
30 | diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/include/hw/ptimer.h | 16 | --- a/include/exec/cpu_ldst.h |
33 | +++ b/include/hw/ptimer.h | 17 | +++ b/include/exec/cpu_ldst.h |
34 | @@ -XXX,XX +XXX,XX @@ void ptimer_transaction_commit(ptimer_state *s); | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
35 | */ | 19 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
36 | void ptimer_set_period(ptimer_state *s, int64_t period); | 20 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
37 | 21 | ||
38 | +/** | 22 | -#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
39 | + * ptimer_set_period_from_clock - Set counter increment from a Clock | 23 | -#define guest_addr_valid(x) (1) |
40 | + * @s: ptimer to configure | 24 | -#else |
41 | + * @clk: pointer to Clock object to take period from | 25 | -#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
42 | + * @divisor: value to scale the clock frequency down by | 26 | -#endif |
43 | + * | 27 | +static inline bool guest_addr_valid(abi_ulong x) |
44 | + * If the ptimer is being driven from a Clock, this is the preferred | ||
45 | + * way to tell the ptimer about the period, because it avoids any | ||
46 | + * possible rounding errors that might happen if the internal | ||
47 | + * representation of the Clock period was converted to either a period | ||
48 | + * in ns or a frequency in Hz. | ||
49 | + * | ||
50 | + * If the ptimer should run at the same frequency as the clock, | ||
51 | + * pass 1 as the @divisor; if the ptimer should run at half the | ||
52 | + * frequency, pass 2, and so on. | ||
53 | + * | ||
54 | + * This function will assert if it is called outside a | ||
55 | + * ptimer_transaction_begin/commit block. | ||
56 | + */ | ||
57 | +void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clock, | ||
58 | + unsigned int divisor); | ||
59 | + | ||
60 | /** | ||
61 | * ptimer_set_freq - Set counter frequency in Hz | ||
62 | * @s: ptimer to configure | ||
63 | diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/include/qemu/typedefs.h | ||
66 | +++ b/include/qemu/typedefs.h | ||
67 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockDriverState BlockDriverState; | ||
68 | typedef struct BusClass BusClass; | ||
69 | typedef struct BusState BusState; | ||
70 | typedef struct Chardev Chardev; | ||
71 | +typedef struct Clock Clock; | ||
72 | typedef struct CompatProperty CompatProperty; | ||
73 | typedef struct CoMutex CoMutex; | ||
74 | typedef struct CPUAddressSpace CPUAddressSpace; | ||
75 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/hw/core/ptimer.c | ||
78 | +++ b/hw/core/ptimer.c | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | #include "sysemu/qtest.h" | ||
81 | #include "block/aio.h" | ||
82 | #include "sysemu/cpus.h" | ||
83 | +#include "hw/clock.h" | ||
84 | |||
85 | #define DELTA_ADJUST 1 | ||
86 | #define DELTA_NO_ADJUST -1 | ||
87 | @@ -XXX,XX +XXX,XX @@ void ptimer_set_period(ptimer_state *s, int64_t period) | ||
88 | } | ||
89 | } | ||
90 | |||
91 | +/* Set counter increment interval from a Clock */ | ||
92 | +void ptimer_set_period_from_clock(ptimer_state *s, const Clock *clk, | ||
93 | + unsigned int divisor) | ||
94 | +{ | 28 | +{ |
95 | + /* | 29 | + return x <= GUEST_ADDR_MAX; |
96 | + * The raw clock period is a 64-bit value in units of 2^-32 ns; | ||
97 | + * put another way it's a 32.32 fixed-point ns value. Our internal | ||
98 | + * representation of the period is 64.32 fixed point ns, so | ||
99 | + * the conversion is simple. | ||
100 | + */ | ||
101 | + uint64_t raw_period = clock_get(clk); | ||
102 | + uint64_t period_frac; | ||
103 | + | ||
104 | + assert(s->in_transaction); | ||
105 | + s->delta = ptimer_get_count(s); | ||
106 | + s->period = extract64(raw_period, 32, 32); | ||
107 | + period_frac = extract64(raw_period, 0, 32); | ||
108 | + /* | ||
109 | + * divisor specifies a possible frequency divisor between the | ||
110 | + * clock and the timer, so it is a multiplier on the period. | ||
111 | + * We do the multiply after splitting the raw period out into | ||
112 | + * period and frac to avoid having to do a 32*64->96 multiply. | ||
113 | + */ | ||
114 | + s->period *= divisor; | ||
115 | + period_frac *= divisor; | ||
116 | + s->period += extract64(period_frac, 32, 32); | ||
117 | + s->period_frac = (uint32_t)period_frac; | ||
118 | + | ||
119 | + if (s->enabled) { | ||
120 | + s->need_reload = true; | ||
121 | + } | ||
122 | +} | 30 | +} |
123 | + | 31 | |
124 | /* Set counter frequency in Hz. */ | 32 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
125 | void ptimer_set_freq(ptimer_state *s, uint32_t freq) | ||
126 | { | 33 | { |
127 | -- | 34 | -- |
128 | 2.20.1 | 35 | 2.20.1 |
129 | 36 | ||
130 | 37 | diff view generated by jsdifflib |
1 | From: Mihai Carabas <mihai.carabas@oracle.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add pvpanic PCI device support details in docs/specs/pvpanic.txt. | 3 | Provide an identity fallback for target that do not |
4 | use tagged addresses. | ||
4 | 5 | ||
5 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-12-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 10 | --- |
9 | docs/specs/pvpanic.txt | 13 ++++++++++++- | 11 | include/exec/cpu_ldst.h | 7 +++++++ |
10 | 1 file changed, 12 insertions(+), 1 deletion(-) | 12 | 1 file changed, 7 insertions(+) |
11 | 13 | ||
12 | diff --git a/docs/specs/pvpanic.txt b/docs/specs/pvpanic.txt | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/docs/specs/pvpanic.txt | 16 | --- a/include/exec/cpu_ldst.h |
15 | +++ b/docs/specs/pvpanic.txt | 17 | +++ b/include/exec/cpu_ldst.h |
16 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
17 | PVPANIC DEVICE | 19 | #define TARGET_ABI_FMT_ptr "%"PRIx64 |
18 | ============== | 20 | #endif |
19 | 21 | ||
20 | -pvpanic device is a simulated ISA device, through which a guest panic | 22 | +#ifndef TARGET_TAGGED_ADDRESSES |
21 | +pvpanic device is a simulated device, through which a guest panic | 23 | +static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) |
22 | event is sent to qemu, and a QMP event is generated. This allows | 24 | +{ |
23 | management apps (e.g. libvirt) to be notified and respond to the event. | 25 | + return x; |
24 | 26 | +} | |
25 | @@ -XXX,XX +XXX,XX @@ The management app has the option of waiting for GUEST_PANICKED events, | 27 | +#endif |
26 | and/or polling for guest-panicked RunState, to learn when the pvpanic | ||
27 | device has fired a panic event. | ||
28 | |||
29 | +The pvpanic device can be implemented as an ISA device (using IOPORT) or as a | ||
30 | +PCI device. | ||
31 | + | 28 | + |
32 | ISA Interface | 29 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
33 | ------------- | 30 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
34 | |||
35 | @@ -XXX,XX +XXX,XX @@ bit 1: a guest panic has happened and will be handled by the guest; | ||
36 | the host should record it or report it, but should not affect | ||
37 | the execution of the guest. | ||
38 | |||
39 | +PCI Interface | ||
40 | +------------- | ||
41 | + | ||
42 | +The PCI interface is similar to the ISA interface except that it uses an MMIO | ||
43 | +address space provided by its BAR0, 1 byte long. Any machine with a PCI bus | ||
44 | +can enable a pvpanic device by adding '-device pvpanic-pci' to the command | ||
45 | +line. | ||
46 | + | ||
47 | ACPI Interface | ||
48 | -------------- | ||
49 | 31 | ||
50 | -- | 32 | -- |
51 | 2.20.1 | 33 | 2.20.1 |
52 | 34 | ||
53 | 35 | diff view generated by jsdifflib |
1 | Convert the SSYS code in the Stellaris boards (which encapsulates the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | system registers) to a proper QOM device. This will provide us with | ||
3 | somewhere to put the output Clock whose frequency depends on the | ||
4 | setting of the PLL configuration registers. | ||
5 | 2 | ||
6 | This is a migration compatibility break for lm3s811evb, lm3s6965evb. | 3 | Use g2h_untagged in contexts that have no cpu, e.g. the binary |
4 | loaders that operate before the primary cpu is created. As a | ||
5 | colollary, target_mmap and friends must use untagged addresses, | ||
6 | since they are used by the loaders. | ||
7 | 7 | ||
8 | We use 3-phase reset here because the Clock will need to propagate | 8 | Use g2h_untagged on values returned from target_mmap, as the |
9 | its value in the hold phase. | 9 | kernel never applies a tag itself. |
10 | 10 | ||
11 | For the moment we reset the device during the board creation so that | 11 | Use g2h_untagged on all pc values. The only current user of |
12 | the system_clock_scale global gets set; this will be removed in a | 12 | tags, aarch64, removes tags from code addresses upon branch, |
13 | subsequent commit. | 13 | so "pc" is always untagged. |
14 | 14 | ||
15 | Use g2h with the cpu context on hand wherever possible. | ||
16 | |||
17 | Use g2h_untagged in lock_user, which will be updated soon. | ||
18 | |||
19 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Message-id: 20210128114145.20536-17-peter.maydell@linaro.org | ||
20 | Message-id: 20210121190622.22000-17-peter.maydell@linaro.org | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
22 | --- | 23 | --- |
23 | hw/arm/stellaris.c | 132 ++++++++++++++++++++++++++++++++++++--------- | 24 | bsd-user/qemu.h | 8 ++-- |
24 | 1 file changed, 107 insertions(+), 25 deletions(-) | 25 | include/exec/cpu_ldst.h | 12 +++++- |
26 | include/exec/exec-all.h | 2 +- | ||
27 | linux-user/qemu.h | 6 +-- | ||
28 | accel/tcg/translate-all.c | 4 +- | ||
29 | accel/tcg/user-exec.c | 48 ++++++++++++------------ | ||
30 | bsd-user/elfload.c | 2 +- | ||
31 | bsd-user/main.c | 4 +- | ||
32 | bsd-user/mmap.c | 23 ++++++------ | ||
33 | linux-user/elfload.c | 12 +++--- | ||
34 | linux-user/flatload.c | 2 +- | ||
35 | linux-user/hppa/cpu_loop.c | 31 ++++++++-------- | ||
36 | linux-user/i386/cpu_loop.c | 4 +- | ||
37 | linux-user/mmap.c | 45 +++++++++++----------- | ||
38 | linux-user/ppc/signal.c | 4 +- | ||
39 | linux-user/syscall.c | 72 +++++++++++++++++++----------------- | ||
40 | target/arm/helper-a64.c | 4 +- | ||
41 | target/hppa/op_helper.c | 2 +- | ||
42 | target/i386/tcg/mem_helper.c | 2 +- | ||
43 | target/s390x/mem_helper.c | 4 +- | ||
44 | 20 files changed, 154 insertions(+), 137 deletions(-) | ||
25 | 45 | ||
26 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | 46 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h |
27 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/arm/stellaris.c | 48 | --- a/bsd-user/qemu.h |
29 | +++ b/hw/arm/stellaris.c | 49 | +++ b/bsd-user/qemu.h |
30 | @@ -XXX,XX +XXX,XX @@ static void stellaris_gptm_realize(DeviceState *dev, Error **errp) | 50 | @@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy |
31 | 51 | void *addr; | |
32 | /* System controller. */ | 52 | addr = g_malloc(len); |
33 | 53 | if (copy) | |
34 | -typedef struct { | 54 | - memcpy(addr, g2h(guest_addr), len); |
35 | +#define TYPE_STELLARIS_SYS "stellaris-sys" | 55 | + memcpy(addr, g2h_untagged(guest_addr), len); |
36 | +OBJECT_DECLARE_SIMPLE_TYPE(ssys_state, STELLARIS_SYS) | 56 | else |
37 | + | 57 | memset(addr, 0, len); |
38 | +struct ssys_state { | 58 | return addr; |
39 | + SysBusDevice parent_obj; | 59 | } |
40 | + | 60 | #else |
41 | MemoryRegion iomem; | 61 | - return g2h(guest_addr); |
42 | uint32_t pborctl; | 62 | + return g2h_untagged(guest_addr); |
43 | uint32_t ldopctl; | 63 | #endif |
44 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 64 | } |
45 | uint32_t dcgc[3]; | 65 | |
46 | uint32_t clkvclr; | 66 | @@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, |
47 | uint32_t ldoarst; | 67 | #ifdef DEBUG_REMAP |
48 | + qemu_irq irq; | 68 | if (!host_ptr) |
49 | + /* Properties (all read-only registers) */ | 69 | return; |
50 | uint32_t user0; | 70 | - if (host_ptr == g2h(guest_addr)) |
51 | uint32_t user1; | 71 | + if (host_ptr == g2h_untagged(guest_addr)) |
52 | - qemu_irq irq; | 72 | return; |
53 | - stellaris_board_info *board; | 73 | if (len > 0) |
54 | -} ssys_state; | 74 | - memcpy(g2h(guest_addr), host_ptr, len); |
55 | + uint32_t did0; | 75 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); |
56 | + uint32_t did1; | 76 | g_free(host_ptr); |
57 | + uint32_t dc0; | 77 | #endif |
58 | + uint32_t dc1; | 78 | } |
59 | + uint32_t dc2; | 79 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
60 | + uint32_t dc3; | 80 | index XXXXXXX..XXXXXXX 100644 |
61 | + uint32_t dc4; | 81 | --- a/include/exec/cpu_ldst.h |
62 | +}; | 82 | +++ b/include/exec/cpu_ldst.h |
63 | 83 | @@ -XXX,XX +XXX,XX @@ static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) | |
64 | static void ssys_update(ssys_state *s) | 84 | #endif |
65 | { | 85 | |
66 | @@ -XXX,XX +XXX,XX @@ static uint32_t pllcfg_fury[16] = { | 86 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
67 | 87 | -#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) | |
68 | static int ssys_board_class(const ssys_state *s) | 88 | +static inline void *g2h_untagged(abi_ptr x) |
69 | { | 89 | +{ |
70 | - uint32_t did0 = s->board->did0; | 90 | + return (void *)((uintptr_t)(x) + guest_base); |
71 | + uint32_t did0 = s->did0; | ||
72 | switch (did0 & DID0_VER_MASK) { | ||
73 | case DID0_VER_0: | ||
74 | return DID0_CLASS_SANDSTORM; | ||
75 | @@ -XXX,XX +XXX,XX @@ static uint64_t ssys_read(void *opaque, hwaddr offset, | ||
76 | |||
77 | switch (offset) { | ||
78 | case 0x000: /* DID0 */ | ||
79 | - return s->board->did0; | ||
80 | + return s->did0; | ||
81 | case 0x004: /* DID1 */ | ||
82 | - return s->board->did1; | ||
83 | + return s->did1; | ||
84 | case 0x008: /* DC0 */ | ||
85 | - return s->board->dc0; | ||
86 | + return s->dc0; | ||
87 | case 0x010: /* DC1 */ | ||
88 | - return s->board->dc1; | ||
89 | + return s->dc1; | ||
90 | case 0x014: /* DC2 */ | ||
91 | - return s->board->dc2; | ||
92 | + return s->dc2; | ||
93 | case 0x018: /* DC3 */ | ||
94 | - return s->board->dc3; | ||
95 | + return s->dc3; | ||
96 | case 0x01c: /* DC4 */ | ||
97 | - return s->board->dc4; | ||
98 | + return s->dc4; | ||
99 | case 0x030: /* PBORCTL */ | ||
100 | return s->pborctl; | ||
101 | case 0x034: /* LDOPCTL */ | ||
102 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps ssys_ops = { | ||
103 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
104 | }; | ||
105 | |||
106 | -static void ssys_reset(void *opaque) | ||
107 | +static void stellaris_sys_reset_enter(Object *obj, ResetType type) | ||
108 | { | ||
109 | - ssys_state *s = (ssys_state *)opaque; | ||
110 | + ssys_state *s = STELLARIS_SYS(obj); | ||
111 | |||
112 | s->pborctl = 0x7ffd; | ||
113 | s->rcc = 0x078e3ac0; | ||
114 | @@ -XXX,XX +XXX,XX @@ static void ssys_reset(void *opaque) | ||
115 | s->rcgc[0] = 1; | ||
116 | s->scgc[0] = 1; | ||
117 | s->dcgc[0] = 1; | ||
118 | +} | 91 | +} |
119 | + | 92 | + |
120 | +static void stellaris_sys_reset_hold(Object *obj) | 93 | +static inline void *g2h(CPUState *cs, abi_ptr x) |
121 | +{ | 94 | +{ |
122 | + ssys_state *s = STELLARIS_SYS(obj); | 95 | + return g2h_untagged(cpu_untagged_addr(cs, x)); |
123 | + | ||
124 | ssys_calculate_system_clock(s); | ||
125 | } | ||
126 | |||
127 | +static void stellaris_sys_reset_exit(Object *obj) | ||
128 | +{ | ||
129 | +} | 96 | +} |
130 | + | 97 | |
131 | static int stellaris_sys_post_load(void *opaque, int version_id) | 98 | static inline bool guest_addr_valid(abi_ulong x) |
132 | { | 99 | { |
133 | ssys_state *s = opaque; | 100 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_ldsw_code(CPUArchState *env, abi_ptr addr) |
134 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_stellaris_sys = { | 101 | static inline void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, |
135 | } | 102 | MMUAccessType access_type, int mmu_idx) |
136 | }; | ||
137 | |||
138 | +static Property stellaris_sys_properties[] = { | ||
139 | + DEFINE_PROP_UINT32("user0", ssys_state, user0, 0), | ||
140 | + DEFINE_PROP_UINT32("user1", ssys_state, user1, 0), | ||
141 | + DEFINE_PROP_UINT32("did0", ssys_state, did0, 0), | ||
142 | + DEFINE_PROP_UINT32("did1", ssys_state, did1, 0), | ||
143 | + DEFINE_PROP_UINT32("dc0", ssys_state, dc0, 0), | ||
144 | + DEFINE_PROP_UINT32("dc1", ssys_state, dc1, 0), | ||
145 | + DEFINE_PROP_UINT32("dc2", ssys_state, dc2, 0), | ||
146 | + DEFINE_PROP_UINT32("dc3", ssys_state, dc3, 0), | ||
147 | + DEFINE_PROP_UINT32("dc4", ssys_state, dc4, 0), | ||
148 | + DEFINE_PROP_END_OF_LIST() | ||
149 | +}; | ||
150 | + | ||
151 | +static void stellaris_sys_instance_init(Object *obj) | ||
152 | +{ | ||
153 | + ssys_state *s = STELLARIS_SYS(obj); | ||
154 | + SysBusDevice *sbd = SYS_BUS_DEVICE(s); | ||
155 | + | ||
156 | + memory_region_init_io(&s->iomem, obj, &ssys_ops, s, "ssys", 0x00001000); | ||
157 | + sysbus_init_mmio(sbd, &s->iomem); | ||
158 | + sysbus_init_irq(sbd, &s->irq); | ||
159 | +} | ||
160 | + | ||
161 | static int stellaris_sys_init(uint32_t base, qemu_irq irq, | ||
162 | stellaris_board_info * board, | ||
163 | uint8_t *macaddr) | ||
164 | { | 103 | { |
165 | - ssys_state *s; | 104 | - return g2h(addr); |
166 | + DeviceState *dev = qdev_new(TYPE_STELLARIS_SYS); | 105 | + return g2h(env_cpu(env), addr); |
167 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | 106 | } |
168 | 107 | #else | |
169 | - s = g_new0(ssys_state, 1); | 108 | void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, |
170 | - s->irq = irq; | 109 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
171 | - s->board = board; | 110 | index XXXXXXX..XXXXXXX 100644 |
172 | /* Most devices come preprogrammed with a MAC address in the user data. */ | 111 | --- a/include/exec/exec-all.h |
173 | - s->user0 = macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16); | 112 | +++ b/include/exec/exec-all.h |
174 | - s->user1 = macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16); | 113 | @@ -XXX,XX +XXX,XX @@ static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, |
175 | + qdev_prop_set_uint32(dev, "user0", | 114 | void **hostp) |
176 | + macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16)); | 115 | { |
177 | + qdev_prop_set_uint32(dev, "user1", | 116 | if (hostp) { |
178 | + macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16)); | 117 | - *hostp = g2h(addr); |
179 | + qdev_prop_set_uint32(dev, "did0", board->did0); | 118 | + *hostp = g2h_untagged(addr); |
180 | + qdev_prop_set_uint32(dev, "did1", board->did1); | 119 | } |
181 | + qdev_prop_set_uint32(dev, "dc0", board->dc0); | 120 | return addr; |
182 | + qdev_prop_set_uint32(dev, "dc1", board->dc1); | 121 | } |
183 | + qdev_prop_set_uint32(dev, "dc2", board->dc2); | 122 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
184 | + qdev_prop_set_uint32(dev, "dc3", board->dc3); | 123 | index XXXXXXX..XXXXXXX 100644 |
185 | + qdev_prop_set_uint32(dev, "dc4", board->dc4); | 124 | --- a/linux-user/qemu.h |
186 | + | 125 | +++ b/linux-user/qemu.h |
187 | + sysbus_realize_and_unref(sbd, &error_fatal); | 126 | @@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy |
188 | + sysbus_mmio_map(sbd, 0, base); | 127 | return addr; |
189 | + sysbus_connect_irq(sbd, 0, irq); | 128 | } |
190 | + | 129 | #else |
191 | + /* | 130 | - return g2h(guest_addr); |
192 | + * Normally we should not be resetting devices like this during | 131 | + return g2h_untagged(guest_addr); |
193 | + * board creation. For the moment we need to do so, because | 132 | #endif |
194 | + * system_clock_scale will only get set when the STELLARIS_SYS | 133 | } |
195 | + * device is reset, and we need its initial value to pass to | 134 | |
196 | + * the watchdog device. This hack can be removed once the | 135 | @@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, |
197 | + * watchdog has been converted to use a Clock input instead. | 136 | #ifdef DEBUG_REMAP |
198 | + */ | 137 | if (!host_ptr) |
199 | + device_cold_reset(dev); | 138 | return; |
200 | 139 | - if (host_ptr == g2h(guest_addr)) | |
201 | - memory_region_init_io(&s->iomem, NULL, &ssys_ops, s, "ssys", 0x00001000); | 140 | + if (host_ptr == g2h_untagged(guest_addr)) |
202 | - memory_region_add_subregion(get_system_memory(), base, &s->iomem); | 141 | return; |
203 | - ssys_reset(s); | 142 | if (len > 0) |
204 | - vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_stellaris_sys, s); | 143 | - memcpy(g2h(guest_addr), host_ptr, len); |
144 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
145 | g_free(host_ptr); | ||
146 | #endif | ||
147 | } | ||
148 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/accel/tcg/translate-all.c | ||
151 | +++ b/accel/tcg/translate-all.c | ||
152 | @@ -XXX,XX +XXX,XX @@ static inline void tb_page_add(PageDesc *p, TranslationBlock *tb, | ||
153 | prot |= p2->flags; | ||
154 | p2->flags &= ~PAGE_WRITE; | ||
155 | } | ||
156 | - mprotect(g2h(page_addr), qemu_host_page_size, | ||
157 | + mprotect(g2h_untagged(page_addr), qemu_host_page_size, | ||
158 | (prot & PAGE_BITS) & ~PAGE_WRITE); | ||
159 | if (DEBUG_TB_INVALIDATE_GATE) { | ||
160 | printf("protecting code page: 0x" TB_PAGE_ADDR_FMT "\n", page_addr); | ||
161 | @@ -XXX,XX +XXX,XX @@ int page_unprotect(target_ulong address, uintptr_t pc) | ||
162 | } | ||
163 | #endif | ||
164 | } | ||
165 | - mprotect((void *)g2h(host_start), qemu_host_page_size, | ||
166 | + mprotect((void *)g2h_untagged(host_start), qemu_host_page_size, | ||
167 | prot & PAGE_BITS); | ||
168 | } | ||
169 | mmap_unlock(); | ||
170 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/accel/tcg/user-exec.c | ||
173 | +++ b/accel/tcg/user-exec.c | ||
174 | @@ -XXX,XX +XXX,XX @@ int probe_access_flags(CPUArchState *env, target_ulong addr, | ||
175 | int flags; | ||
176 | |||
177 | flags = probe_access_internal(env, addr, 0, access_type, nonfault, ra); | ||
178 | - *phost = flags ? NULL : g2h(addr); | ||
179 | + *phost = flags ? NULL : g2h(env_cpu(env), addr); | ||
180 | return flags; | ||
181 | } | ||
182 | |||
183 | @@ -XXX,XX +XXX,XX @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, | ||
184 | flags = probe_access_internal(env, addr, size, access_type, false, ra); | ||
185 | g_assert(flags == 0); | ||
186 | |||
187 | - return size ? g2h(addr) : NULL; | ||
188 | + return size ? g2h(env_cpu(env), addr) : NULL; | ||
189 | } | ||
190 | |||
191 | #if defined(__i386__) | ||
192 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldub_data(CPUArchState *env, abi_ptr ptr) | ||
193 | uint16_t meminfo = trace_mem_get_info(MO_UB, MMU_USER_IDX, false); | ||
194 | |||
195 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
196 | - ret = ldub_p(g2h(ptr)); | ||
197 | + ret = ldub_p(g2h(env_cpu(env), ptr)); | ||
198 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
199 | return ret; | ||
200 | } | ||
201 | @@ -XXX,XX +XXX,XX @@ int cpu_ldsb_data(CPUArchState *env, abi_ptr ptr) | ||
202 | uint16_t meminfo = trace_mem_get_info(MO_SB, MMU_USER_IDX, false); | ||
203 | |||
204 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
205 | - ret = ldsb_p(g2h(ptr)); | ||
206 | + ret = ldsb_p(g2h(env_cpu(env), ptr)); | ||
207 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
208 | return ret; | ||
209 | } | ||
210 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_be_data(CPUArchState *env, abi_ptr ptr) | ||
211 | uint16_t meminfo = trace_mem_get_info(MO_BEUW, MMU_USER_IDX, false); | ||
212 | |||
213 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
214 | - ret = lduw_be_p(g2h(ptr)); | ||
215 | + ret = lduw_be_p(g2h(env_cpu(env), ptr)); | ||
216 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
217 | return ret; | ||
218 | } | ||
219 | @@ -XXX,XX +XXX,XX @@ int cpu_ldsw_be_data(CPUArchState *env, abi_ptr ptr) | ||
220 | uint16_t meminfo = trace_mem_get_info(MO_BESW, MMU_USER_IDX, false); | ||
221 | |||
222 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
223 | - ret = ldsw_be_p(g2h(ptr)); | ||
224 | + ret = ldsw_be_p(g2h(env_cpu(env), ptr)); | ||
225 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
226 | return ret; | ||
227 | } | ||
228 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_be_data(CPUArchState *env, abi_ptr ptr) | ||
229 | uint16_t meminfo = trace_mem_get_info(MO_BEUL, MMU_USER_IDX, false); | ||
230 | |||
231 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
232 | - ret = ldl_be_p(g2h(ptr)); | ||
233 | + ret = ldl_be_p(g2h(env_cpu(env), ptr)); | ||
234 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
235 | return ret; | ||
236 | } | ||
237 | @@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_be_data(CPUArchState *env, abi_ptr ptr) | ||
238 | uint16_t meminfo = trace_mem_get_info(MO_BEQ, MMU_USER_IDX, false); | ||
239 | |||
240 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
241 | - ret = ldq_be_p(g2h(ptr)); | ||
242 | + ret = ldq_be_p(g2h(env_cpu(env), ptr)); | ||
243 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
244 | return ret; | ||
245 | } | ||
246 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_le_data(CPUArchState *env, abi_ptr ptr) | ||
247 | uint16_t meminfo = trace_mem_get_info(MO_LEUW, MMU_USER_IDX, false); | ||
248 | |||
249 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
250 | - ret = lduw_le_p(g2h(ptr)); | ||
251 | + ret = lduw_le_p(g2h(env_cpu(env), ptr)); | ||
252 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
253 | return ret; | ||
254 | } | ||
255 | @@ -XXX,XX +XXX,XX @@ int cpu_ldsw_le_data(CPUArchState *env, abi_ptr ptr) | ||
256 | uint16_t meminfo = trace_mem_get_info(MO_LESW, MMU_USER_IDX, false); | ||
257 | |||
258 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
259 | - ret = ldsw_le_p(g2h(ptr)); | ||
260 | + ret = ldsw_le_p(g2h(env_cpu(env), ptr)); | ||
261 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
262 | return ret; | ||
263 | } | ||
264 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_le_data(CPUArchState *env, abi_ptr ptr) | ||
265 | uint16_t meminfo = trace_mem_get_info(MO_LEUL, MMU_USER_IDX, false); | ||
266 | |||
267 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
268 | - ret = ldl_le_p(g2h(ptr)); | ||
269 | + ret = ldl_le_p(g2h(env_cpu(env), ptr)); | ||
270 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
271 | return ret; | ||
272 | } | ||
273 | @@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_le_data(CPUArchState *env, abi_ptr ptr) | ||
274 | uint16_t meminfo = trace_mem_get_info(MO_LEQ, MMU_USER_IDX, false); | ||
275 | |||
276 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
277 | - ret = ldq_le_p(g2h(ptr)); | ||
278 | + ret = ldq_le_p(g2h(env_cpu(env), ptr)); | ||
279 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
280 | return ret; | ||
281 | } | ||
282 | @@ -XXX,XX +XXX,XX @@ void cpu_stb_data(CPUArchState *env, abi_ptr ptr, uint32_t val) | ||
283 | uint16_t meminfo = trace_mem_get_info(MO_UB, MMU_USER_IDX, true); | ||
284 | |||
285 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
286 | - stb_p(g2h(ptr), val); | ||
287 | + stb_p(g2h(env_cpu(env), ptr), val); | ||
288 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
289 | } | ||
290 | |||
291 | @@ -XXX,XX +XXX,XX @@ void cpu_stw_be_data(CPUArchState *env, abi_ptr ptr, uint32_t val) | ||
292 | uint16_t meminfo = trace_mem_get_info(MO_BEUW, MMU_USER_IDX, true); | ||
293 | |||
294 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
295 | - stw_be_p(g2h(ptr), val); | ||
296 | + stw_be_p(g2h(env_cpu(env), ptr), val); | ||
297 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
298 | } | ||
299 | |||
300 | @@ -XXX,XX +XXX,XX @@ void cpu_stl_be_data(CPUArchState *env, abi_ptr ptr, uint32_t val) | ||
301 | uint16_t meminfo = trace_mem_get_info(MO_BEUL, MMU_USER_IDX, true); | ||
302 | |||
303 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
304 | - stl_be_p(g2h(ptr), val); | ||
305 | + stl_be_p(g2h(env_cpu(env), ptr), val); | ||
306 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
307 | } | ||
308 | |||
309 | @@ -XXX,XX +XXX,XX @@ void cpu_stq_be_data(CPUArchState *env, abi_ptr ptr, uint64_t val) | ||
310 | uint16_t meminfo = trace_mem_get_info(MO_BEQ, MMU_USER_IDX, true); | ||
311 | |||
312 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
313 | - stq_be_p(g2h(ptr), val); | ||
314 | + stq_be_p(g2h(env_cpu(env), ptr), val); | ||
315 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
316 | } | ||
317 | |||
318 | @@ -XXX,XX +XXX,XX @@ void cpu_stw_le_data(CPUArchState *env, abi_ptr ptr, uint32_t val) | ||
319 | uint16_t meminfo = trace_mem_get_info(MO_LEUW, MMU_USER_IDX, true); | ||
320 | |||
321 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
322 | - stw_le_p(g2h(ptr), val); | ||
323 | + stw_le_p(g2h(env_cpu(env), ptr), val); | ||
324 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
325 | } | ||
326 | |||
327 | @@ -XXX,XX +XXX,XX @@ void cpu_stl_le_data(CPUArchState *env, abi_ptr ptr, uint32_t val) | ||
328 | uint16_t meminfo = trace_mem_get_info(MO_LEUL, MMU_USER_IDX, true); | ||
329 | |||
330 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
331 | - stl_le_p(g2h(ptr), val); | ||
332 | + stl_le_p(g2h(env_cpu(env), ptr), val); | ||
333 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
334 | } | ||
335 | |||
336 | @@ -XXX,XX +XXX,XX @@ void cpu_stq_le_data(CPUArchState *env, abi_ptr ptr, uint64_t val) | ||
337 | uint16_t meminfo = trace_mem_get_info(MO_LEQ, MMU_USER_IDX, true); | ||
338 | |||
339 | trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo); | ||
340 | - stq_le_p(g2h(ptr), val); | ||
341 | + stq_le_p(g2h(env_cpu(env), ptr), val); | ||
342 | qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo); | ||
343 | } | ||
344 | |||
345 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldub_code(CPUArchState *env, abi_ptr ptr) | ||
346 | uint32_t ret; | ||
347 | |||
348 | set_helper_retaddr(1); | ||
349 | - ret = ldub_p(g2h(ptr)); | ||
350 | + ret = ldub_p(g2h_untagged(ptr)); | ||
351 | clear_helper_retaddr(); | ||
352 | return ret; | ||
353 | } | ||
354 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_code(CPUArchState *env, abi_ptr ptr) | ||
355 | uint32_t ret; | ||
356 | |||
357 | set_helper_retaddr(1); | ||
358 | - ret = lduw_p(g2h(ptr)); | ||
359 | + ret = lduw_p(g2h_untagged(ptr)); | ||
360 | clear_helper_retaddr(); | ||
361 | return ret; | ||
362 | } | ||
363 | @@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_code(CPUArchState *env, abi_ptr ptr) | ||
364 | uint32_t ret; | ||
365 | |||
366 | set_helper_retaddr(1); | ||
367 | - ret = ldl_p(g2h(ptr)); | ||
368 | + ret = ldl_p(g2h_untagged(ptr)); | ||
369 | clear_helper_retaddr(); | ||
370 | return ret; | ||
371 | } | ||
372 | @@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr) | ||
373 | uint64_t ret; | ||
374 | |||
375 | set_helper_retaddr(1); | ||
376 | - ret = ldq_p(g2h(ptr)); | ||
377 | + ret = ldq_p(g2h_untagged(ptr)); | ||
378 | clear_helper_retaddr(); | ||
379 | return ret; | ||
380 | } | ||
381 | @@ -XXX,XX +XXX,XX @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr, | ||
382 | if (unlikely(addr & (size - 1))) { | ||
383 | cpu_loop_exit_atomic(env_cpu(env), retaddr); | ||
384 | } | ||
385 | - void *ret = g2h(addr); | ||
386 | + void *ret = g2h(env_cpu(env), addr); | ||
387 | set_helper_retaddr(retaddr); | ||
388 | return ret; | ||
389 | } | ||
390 | diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c | ||
391 | index XXXXXXX..XXXXXXX 100644 | ||
392 | --- a/bsd-user/elfload.c | ||
393 | +++ b/bsd-user/elfload.c | ||
394 | @@ -XXX,XX +XXX,XX @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss) | ||
395 | end_addr1 = REAL_HOST_PAGE_ALIGN(elf_bss); | ||
396 | end_addr = HOST_PAGE_ALIGN(elf_bss); | ||
397 | if (end_addr1 < end_addr) { | ||
398 | - mmap((void *)g2h(end_addr1), end_addr - end_addr1, | ||
399 | + mmap((void *)g2h_untagged(end_addr1), end_addr - end_addr1, | ||
400 | PROT_READ|PROT_WRITE|PROT_EXEC, | ||
401 | MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0); | ||
402 | } | ||
403 | diff --git a/bsd-user/main.c b/bsd-user/main.c | ||
404 | index XXXXXXX..XXXXXXX 100644 | ||
405 | --- a/bsd-user/main.c | ||
406 | +++ b/bsd-user/main.c | ||
407 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
408 | env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), | ||
409 | PROT_READ|PROT_WRITE, | ||
410 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
411 | - idt_table = g2h(env->idt.base); | ||
412 | + idt_table = g2h_untagged(env->idt.base); | ||
413 | set_idt(0, 0); | ||
414 | set_idt(1, 0); | ||
415 | set_idt(2, 0); | ||
416 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
417 | PROT_READ|PROT_WRITE, | ||
418 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
419 | env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; | ||
420 | - gdt_table = g2h(env->gdt.base); | ||
421 | + gdt_table = g2h_untagged(env->gdt.base); | ||
422 | #ifdef TARGET_ABI32 | ||
423 | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, | ||
424 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | | ||
425 | diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c | ||
426 | index XXXXXXX..XXXXXXX 100644 | ||
427 | --- a/bsd-user/mmap.c | ||
428 | +++ b/bsd-user/mmap.c | ||
429 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) | ||
430 | } | ||
431 | end = host_end; | ||
432 | } | ||
433 | - ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS); | ||
434 | + ret = mprotect(g2h_untagged(host_start), | ||
435 | + qemu_host_page_size, prot1 & PAGE_BITS); | ||
436 | if (ret != 0) | ||
437 | goto error; | ||
438 | host_start += qemu_host_page_size; | ||
439 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) | ||
440 | for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { | ||
441 | prot1 |= page_get_flags(addr); | ||
442 | } | ||
443 | - ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size, | ||
444 | - prot1 & PAGE_BITS); | ||
445 | + ret = mprotect(g2h_untagged(host_end - qemu_host_page_size), | ||
446 | + qemu_host_page_size, prot1 & PAGE_BITS); | ||
447 | if (ret != 0) | ||
448 | goto error; | ||
449 | host_end -= qemu_host_page_size; | ||
450 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) | ||
451 | |||
452 | /* handle the pages in the middle */ | ||
453 | if (host_start < host_end) { | ||
454 | - ret = mprotect(g2h(host_start), host_end - host_start, prot); | ||
455 | + ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot); | ||
456 | if (ret != 0) | ||
457 | goto error; | ||
458 | } | ||
459 | @@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start, | ||
460 | int prot1, prot_new; | ||
461 | |||
462 | real_end = real_start + qemu_host_page_size; | ||
463 | - host_start = g2h(real_start); | ||
464 | + host_start = g2h_untagged(real_start); | ||
465 | |||
466 | /* get the protection of the target pages outside the mapping */ | ||
467 | prot1 = 0; | ||
468 | @@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start, | ||
469 | mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); | ||
470 | |||
471 | /* read the corresponding file data */ | ||
472 | - pread(fd, g2h(start), end - start, offset); | ||
473 | + pread(fd, g2h_untagged(start), end - start, offset); | ||
474 | |||
475 | /* put final protection */ | ||
476 | if (prot_new != (prot1 | PROT_WRITE)) | ||
477 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, | ||
478 | /* Note: we prefer to control the mapping address. It is | ||
479 | especially important if qemu_host_page_size > | ||
480 | qemu_real_host_page_size */ | ||
481 | - p = mmap(g2h(mmap_start), | ||
482 | + p = mmap(g2h_untagged(mmap_start), | ||
483 | host_len, prot, flags | MAP_FIXED, fd, host_offset); | ||
484 | if (p == MAP_FAILED) | ||
485 | goto fail; | ||
486 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, | ||
487 | -1, 0); | ||
488 | if (retaddr == -1) | ||
489 | goto fail; | ||
490 | - pread(fd, g2h(start), len, offset); | ||
491 | + pread(fd, g2h_untagged(start), len, offset); | ||
492 | if (!(prot & PROT_WRITE)) { | ||
493 | ret = target_mprotect(start, len, prot); | ||
494 | if (ret != 0) { | ||
495 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, | ||
496 | offset1 = 0; | ||
497 | else | ||
498 | offset1 = offset + real_start - start; | ||
499 | - p = mmap(g2h(real_start), real_end - real_start, | ||
500 | + p = mmap(g2h_untagged(real_start), real_end - real_start, | ||
501 | prot, flags, fd, offset1); | ||
502 | if (p == MAP_FAILED) | ||
503 | goto fail; | ||
504 | @@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len) | ||
505 | ret = 0; | ||
506 | /* unmap what we can */ | ||
507 | if (real_start < real_end) { | ||
508 | - ret = munmap(g2h(real_start), real_end - real_start); | ||
509 | + ret = munmap(g2h_untagged(real_start), real_end - real_start); | ||
510 | } | ||
511 | |||
512 | if (ret == 0) | ||
513 | @@ -XXX,XX +XXX,XX @@ int target_msync(abi_ulong start, abi_ulong len, int flags) | ||
514 | return 0; | ||
515 | |||
516 | start &= qemu_host_page_mask; | ||
517 | - return msync(g2h(start), end - start, flags); | ||
518 | + return msync(g2h_untagged(start), end - start, flags); | ||
519 | } | ||
520 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
521 | index XXXXXXX..XXXXXXX 100644 | ||
522 | --- a/linux-user/elfload.c | ||
523 | +++ b/linux-user/elfload.c | ||
524 | @@ -XXX,XX +XXX,XX @@ enum { | ||
525 | |||
526 | static bool init_guest_commpage(void) | ||
527 | { | ||
528 | - void *want = g2h(ARM_COMMPAGE & -qemu_host_page_size); | ||
529 | + void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size); | ||
530 | void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, | ||
531 | MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); | ||
532 | |||
533 | @@ -XXX,XX +XXX,XX @@ static bool init_guest_commpage(void) | ||
534 | } | ||
535 | |||
536 | /* Set kernel helper versions; rest of page is 0. */ | ||
537 | - __put_user(5, (uint32_t *)g2h(0xffff0ffcu)); | ||
538 | + __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); | ||
539 | |||
540 | if (mprotect(addr, qemu_host_page_size, PROT_READ)) { | ||
541 | perror("Protecting guest commpage"); | ||
542 | @@ -XXX,XX +XXX,XX @@ static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) | ||
543 | here is still actually needed. For now, continue with it, | ||
544 | but merge it with the "normal" mmap that would allocate the bss. */ | ||
545 | |||
546 | - host_start = (uintptr_t) g2h(elf_bss); | ||
547 | - host_end = (uintptr_t) g2h(last_bss); | ||
548 | + host_start = (uintptr_t) g2h_untagged(elf_bss); | ||
549 | + host_end = (uintptr_t) g2h_untagged(last_bss); | ||
550 | host_map_start = REAL_HOST_PAGE_ALIGN(host_start); | ||
551 | |||
552 | if (host_map_start < host_end) { | ||
553 | @@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, | ||
554 | } | ||
555 | |||
556 | /* Reserve the address space for the binary, or reserved_va. */ | ||
557 | - test = g2h(guest_loaddr); | ||
558 | + test = g2h_untagged(guest_loaddr); | ||
559 | addr = mmap(test, guest_hiaddr - guest_loaddr, PROT_NONE, flags, -1, 0); | ||
560 | if (test != addr) { | ||
561 | pgb_fail_in_use(image_name); | ||
562 | @@ -XXX,XX +XXX,XX @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, | ||
563 | |||
564 | /* Reserve the memory on the host. */ | ||
565 | assert(guest_base != 0); | ||
566 | - test = g2h(0); | ||
567 | + test = g2h_untagged(0); | ||
568 | addr = mmap(test, reserved_va, PROT_NONE, flags, -1, 0); | ||
569 | if (addr == MAP_FAILED || addr != test) { | ||
570 | error_report("Unable to reserve 0x%lx bytes of virtual address " | ||
571 | diff --git a/linux-user/flatload.c b/linux-user/flatload.c | ||
572 | index XXXXXXX..XXXXXXX 100644 | ||
573 | --- a/linux-user/flatload.c | ||
574 | +++ b/linux-user/flatload.c | ||
575 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
576 | } | ||
577 | |||
578 | /* zero the BSS. */ | ||
579 | - memset(g2h(datapos + data_len), 0, bss_len); | ||
580 | + memset(g2h_untagged(datapos + data_len), 0, bss_len); | ||
581 | |||
205 | return 0; | 582 | return 0; |
206 | } | 583 | } |
207 | 584 | diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c | |
208 | - | 585 | index XXXXXXX..XXXXXXX 100644 |
209 | /* I2C controller. */ | 586 | --- a/linux-user/hppa/cpu_loop.c |
210 | 587 | +++ b/linux-user/hppa/cpu_loop.c | |
211 | #define TYPE_STELLARIS_I2C "stellaris-i2c" | 588 | @@ -XXX,XX +XXX,XX @@ |
212 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo stellaris_adc_info = { | 589 | |
213 | .class_init = stellaris_adc_class_init, | 590 | static abi_ulong hppa_lws(CPUHPPAState *env) |
214 | }; | ||
215 | |||
216 | +static void stellaris_sys_class_init(ObjectClass *klass, void *data) | ||
217 | +{ | ||
218 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
219 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
220 | + | ||
221 | + dc->vmsd = &vmstate_stellaris_sys; | ||
222 | + rc->phases.enter = stellaris_sys_reset_enter; | ||
223 | + rc->phases.hold = stellaris_sys_reset_hold; | ||
224 | + rc->phases.exit = stellaris_sys_reset_exit; | ||
225 | + device_class_set_props(dc, stellaris_sys_properties); | ||
226 | +} | ||
227 | + | ||
228 | +static const TypeInfo stellaris_sys_info = { | ||
229 | + .name = TYPE_STELLARIS_SYS, | ||
230 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
231 | + .instance_size = sizeof(ssys_state), | ||
232 | + .instance_init = stellaris_sys_instance_init, | ||
233 | + .class_init = stellaris_sys_class_init, | ||
234 | +}; | ||
235 | + | ||
236 | static void stellaris_register_types(void) | ||
237 | { | 591 | { |
238 | type_register_static(&stellaris_i2c_info); | 592 | + CPUState *cs = env_cpu(env); |
239 | type_register_static(&stellaris_gptm_info); | 593 | uint32_t which = env->gr[20]; |
240 | type_register_static(&stellaris_adc_info); | 594 | abi_ulong addr = env->gr[26]; |
241 | + type_register_static(&stellaris_sys_info); | 595 | abi_ulong old = env->gr[25]; |
242 | } | 596 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) |
243 | 597 | } | |
244 | type_init(stellaris_register_types) | 598 | old = tswap32(old); |
599 | new = tswap32(new); | ||
600 | - ret = qatomic_cmpxchg((uint32_t *)g2h(addr), old, new); | ||
601 | + ret = qatomic_cmpxchg((uint32_t *)g2h(cs, addr), old, new); | ||
602 | ret = tswap32(ret); | ||
603 | break; | ||
604 | |||
605 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
606 | can be host-endian as well. */ | ||
607 | switch (size) { | ||
608 | case 0: | ||
609 | - old = *(uint8_t *)g2h(old); | ||
610 | - new = *(uint8_t *)g2h(new); | ||
611 | - ret = qatomic_cmpxchg((uint8_t *)g2h(addr), old, new); | ||
612 | + old = *(uint8_t *)g2h(cs, old); | ||
613 | + new = *(uint8_t *)g2h(cs, new); | ||
614 | + ret = qatomic_cmpxchg((uint8_t *)g2h(cs, addr), old, new); | ||
615 | ret = ret != old; | ||
616 | break; | ||
617 | case 1: | ||
618 | - old = *(uint16_t *)g2h(old); | ||
619 | - new = *(uint16_t *)g2h(new); | ||
620 | - ret = qatomic_cmpxchg((uint16_t *)g2h(addr), old, new); | ||
621 | + old = *(uint16_t *)g2h(cs, old); | ||
622 | + new = *(uint16_t *)g2h(cs, new); | ||
623 | + ret = qatomic_cmpxchg((uint16_t *)g2h(cs, addr), old, new); | ||
624 | ret = ret != old; | ||
625 | break; | ||
626 | case 2: | ||
627 | - old = *(uint32_t *)g2h(old); | ||
628 | - new = *(uint32_t *)g2h(new); | ||
629 | - ret = qatomic_cmpxchg((uint32_t *)g2h(addr), old, new); | ||
630 | + old = *(uint32_t *)g2h(cs, old); | ||
631 | + new = *(uint32_t *)g2h(cs, new); | ||
632 | + ret = qatomic_cmpxchg((uint32_t *)g2h(cs, addr), old, new); | ||
633 | ret = ret != old; | ||
634 | break; | ||
635 | case 3: | ||
636 | { | ||
637 | uint64_t o64, n64, r64; | ||
638 | - o64 = *(uint64_t *)g2h(old); | ||
639 | - n64 = *(uint64_t *)g2h(new); | ||
640 | + o64 = *(uint64_t *)g2h(cs, old); | ||
641 | + n64 = *(uint64_t *)g2h(cs, new); | ||
642 | #ifdef CONFIG_ATOMIC64 | ||
643 | - r64 = qatomic_cmpxchg__nocheck((uint64_t *)g2h(addr), | ||
644 | + r64 = qatomic_cmpxchg__nocheck((uint64_t *)g2h(cs, addr), | ||
645 | o64, n64); | ||
646 | ret = r64 != o64; | ||
647 | #else | ||
648 | start_exclusive(); | ||
649 | - r64 = *(uint64_t *)g2h(addr); | ||
650 | + r64 = *(uint64_t *)g2h(cs, addr); | ||
651 | ret = 1; | ||
652 | if (r64 == o64) { | ||
653 | - *(uint64_t *)g2h(addr) = n64; | ||
654 | + *(uint64_t *)g2h(cs, addr) = n64; | ||
655 | ret = 0; | ||
656 | } | ||
657 | end_exclusive(); | ||
658 | diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c | ||
659 | index XXXXXXX..XXXXXXX 100644 | ||
660 | --- a/linux-user/i386/cpu_loop.c | ||
661 | +++ b/linux-user/i386/cpu_loop.c | ||
662 | @@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) | ||
663 | env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), | ||
664 | PROT_READ|PROT_WRITE, | ||
665 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
666 | - idt_table = g2h(env->idt.base); | ||
667 | + idt_table = g2h_untagged(env->idt.base); | ||
668 | set_idt(0, 0); | ||
669 | set_idt(1, 0); | ||
670 | set_idt(2, 0); | ||
671 | @@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) | ||
672 | PROT_READ|PROT_WRITE, | ||
673 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
674 | env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; | ||
675 | - gdt_table = g2h(env->gdt.base); | ||
676 | + gdt_table = g2h_untagged(env->gdt.base); | ||
677 | #ifdef TARGET_ABI32 | ||
678 | write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, | ||
679 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | | ||
680 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | ||
681 | index XXXXXXX..XXXXXXX 100644 | ||
682 | --- a/linux-user/mmap.c | ||
683 | +++ b/linux-user/mmap.c | ||
684 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) | ||
685 | } | ||
686 | end = host_end; | ||
687 | } | ||
688 | - ret = mprotect(g2h(host_start), qemu_host_page_size, | ||
689 | + ret = mprotect(g2h_untagged(host_start), qemu_host_page_size, | ||
690 | prot1 & PAGE_BITS); | ||
691 | if (ret != 0) { | ||
692 | goto error; | ||
693 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) | ||
694 | for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { | ||
695 | prot1 |= page_get_flags(addr); | ||
696 | } | ||
697 | - ret = mprotect(g2h(host_end - qemu_host_page_size), | ||
698 | + ret = mprotect(g2h_untagged(host_end - qemu_host_page_size), | ||
699 | qemu_host_page_size, prot1 & PAGE_BITS); | ||
700 | if (ret != 0) { | ||
701 | goto error; | ||
702 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) | ||
703 | |||
704 | /* handle the pages in the middle */ | ||
705 | if (host_start < host_end) { | ||
706 | - ret = mprotect(g2h(host_start), host_end - host_start, host_prot); | ||
707 | + ret = mprotect(g2h_untagged(host_start), | ||
708 | + host_end - host_start, host_prot); | ||
709 | if (ret != 0) { | ||
710 | goto error; | ||
711 | } | ||
712 | @@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start, | ||
713 | int prot1, prot_new; | ||
714 | |||
715 | real_end = real_start + qemu_host_page_size; | ||
716 | - host_start = g2h(real_start); | ||
717 | + host_start = g2h_untagged(real_start); | ||
718 | |||
719 | /* get the protection of the target pages outside the mapping */ | ||
720 | prot1 = 0; | ||
721 | @@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start, | ||
722 | mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); | ||
723 | |||
724 | /* read the corresponding file data */ | ||
725 | - if (pread(fd, g2h(start), end - start, offset) == -1) | ||
726 | + if (pread(fd, g2h_untagged(start), end - start, offset) == -1) | ||
727 | return -1; | ||
728 | |||
729 | /* put final protection */ | ||
730 | @@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start, | ||
731 | mprotect(host_start, qemu_host_page_size, prot_new); | ||
732 | } | ||
733 | if (prot_new & PROT_WRITE) { | ||
734 | - memset(g2h(start), 0, end - start); | ||
735 | + memset(g2h_untagged(start), 0, end - start); | ||
736 | } | ||
737 | } | ||
738 | return 0; | ||
739 | @@ -XXX,XX +XXX,XX @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) | ||
740 | * - mremap() with MREMAP_FIXED flag | ||
741 | * - shmat() with SHM_REMAP flag | ||
742 | */ | ||
743 | - ptr = mmap(g2h(addr), size, PROT_NONE, | ||
744 | + ptr = mmap(g2h_untagged(addr), size, PROT_NONE, | ||
745 | MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0); | ||
746 | |||
747 | /* ENOMEM, if host address space has no memory */ | ||
748 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, | ||
749 | /* Note: we prefer to control the mapping address. It is | ||
750 | especially important if qemu_host_page_size > | ||
751 | qemu_real_host_page_size */ | ||
752 | - p = mmap(g2h(start), host_len, host_prot, | ||
753 | + p = mmap(g2h_untagged(start), host_len, host_prot, | ||
754 | flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); | ||
755 | if (p == MAP_FAILED) { | ||
756 | goto fail; | ||
757 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, | ||
758 | /* update start so that it points to the file position at 'offset' */ | ||
759 | host_start = (unsigned long)p; | ||
760 | if (!(flags & MAP_ANONYMOUS)) { | ||
761 | - p = mmap(g2h(start), len, host_prot, | ||
762 | + p = mmap(g2h_untagged(start), len, host_prot, | ||
763 | flags | MAP_FIXED, fd, host_offset); | ||
764 | if (p == MAP_FAILED) { | ||
765 | - munmap(g2h(start), host_len); | ||
766 | + munmap(g2h_untagged(start), host_len); | ||
767 | goto fail; | ||
768 | } | ||
769 | host_start += offset - host_offset; | ||
770 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, | ||
771 | -1, 0); | ||
772 | if (retaddr == -1) | ||
773 | goto fail; | ||
774 | - if (pread(fd, g2h(start), len, offset) == -1) | ||
775 | + if (pread(fd, g2h_untagged(start), len, offset) == -1) | ||
776 | goto fail; | ||
777 | if (!(host_prot & PROT_WRITE)) { | ||
778 | ret = target_mprotect(start, len, target_prot); | ||
779 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, | ||
780 | offset1 = 0; | ||
781 | else | ||
782 | offset1 = offset + real_start - start; | ||
783 | - p = mmap(g2h(real_start), real_end - real_start, | ||
784 | + p = mmap(g2h_untagged(real_start), real_end - real_start, | ||
785 | host_prot, flags, fd, offset1); | ||
786 | if (p == MAP_FAILED) | ||
787 | goto fail; | ||
788 | @@ -XXX,XX +XXX,XX @@ static void mmap_reserve(abi_ulong start, abi_ulong size) | ||
789 | real_end -= qemu_host_page_size; | ||
790 | } | ||
791 | if (real_start != real_end) { | ||
792 | - mmap(g2h(real_start), real_end - real_start, PROT_NONE, | ||
793 | + mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, | ||
794 | MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, | ||
795 | -1, 0); | ||
796 | } | ||
797 | @@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len) | ||
798 | if (reserved_va) { | ||
799 | mmap_reserve(real_start, real_end - real_start); | ||
800 | } else { | ||
801 | - ret = munmap(g2h(real_start), real_end - real_start); | ||
802 | + ret = munmap(g2h_untagged(real_start), real_end - real_start); | ||
803 | } | ||
804 | } | ||
805 | |||
806 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
807 | mmap_lock(); | ||
808 | |||
809 | if (flags & MREMAP_FIXED) { | ||
810 | - host_addr = mremap(g2h(old_addr), old_size, new_size, | ||
811 | - flags, g2h(new_addr)); | ||
812 | + host_addr = mremap(g2h_untagged(old_addr), old_size, new_size, | ||
813 | + flags, g2h_untagged(new_addr)); | ||
814 | |||
815 | if (reserved_va && host_addr != MAP_FAILED) { | ||
816 | /* If new and old addresses overlap then the above mremap will | ||
817 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
818 | errno = ENOMEM; | ||
819 | host_addr = MAP_FAILED; | ||
820 | } else { | ||
821 | - host_addr = mremap(g2h(old_addr), old_size, new_size, | ||
822 | - flags | MREMAP_FIXED, g2h(mmap_start)); | ||
823 | + host_addr = mremap(g2h_untagged(old_addr), old_size, new_size, | ||
824 | + flags | MREMAP_FIXED, | ||
825 | + g2h_untagged(mmap_start)); | ||
826 | if (reserved_va) { | ||
827 | mmap_reserve(old_addr, old_size); | ||
828 | } | ||
829 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
830 | } | ||
831 | } | ||
832 | if (prot == 0) { | ||
833 | - host_addr = mremap(g2h(old_addr), old_size, new_size, flags); | ||
834 | + host_addr = mremap(g2h_untagged(old_addr), | ||
835 | + old_size, new_size, flags); | ||
836 | |||
837 | if (host_addr != MAP_FAILED) { | ||
838 | /* Check if address fits target address space */ | ||
839 | if (!guest_range_valid(h2g(host_addr), new_size)) { | ||
840 | /* Revert mremap() changes */ | ||
841 | - host_addr = mremap(g2h(old_addr), new_size, old_size, | ||
842 | - flags); | ||
843 | + host_addr = mremap(g2h_untagged(old_addr), | ||
844 | + new_size, old_size, flags); | ||
845 | errno = ENOMEM; | ||
846 | host_addr = MAP_FAILED; | ||
847 | } else if (reserved_va && old_size > new_size) { | ||
848 | diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c | ||
849 | index XXXXXXX..XXXXXXX 100644 | ||
850 | --- a/linux-user/ppc/signal.c | ||
851 | +++ b/linux-user/ppc/signal.c | ||
852 | @@ -XXX,XX +XXX,XX @@ static void restore_user_regs(CPUPPCState *env, | ||
853 | uint64_t v_addr; | ||
854 | /* 64-bit needs to recover the pointer to the vectors from the frame */ | ||
855 | __get_user(v_addr, &frame->v_regs); | ||
856 | - v_regs = g2h(v_addr); | ||
857 | + v_regs = g2h(env_cpu(env), v_addr); | ||
858 | #else | ||
859 | v_regs = (ppc_avr_t *)frame->mc_vregs.altivec; | ||
860 | #endif | ||
861 | @@ -XXX,XX +XXX,XX @@ void setup_rt_frame(int sig, struct target_sigaction *ka, | ||
862 | if (get_ppc64_abi(image) < 2) { | ||
863 | /* ELFv1 PPC64 function pointers are pointers to OPD entries. */ | ||
864 | struct target_func_ptr *handler = | ||
865 | - (struct target_func_ptr *)g2h(ka->_sa_handler); | ||
866 | + (struct target_func_ptr *)g2h(env_cpu(env), ka->_sa_handler); | ||
867 | env->nip = tswapl(handler->entry); | ||
868 | env->gpr[2] = tswapl(handler->toc); | ||
869 | } else { | ||
870 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
871 | index XXXXXXX..XXXXXXX 100644 | ||
872 | --- a/linux-user/syscall.c | ||
873 | +++ b/linux-user/syscall.c | ||
874 | @@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk) | ||
875 | /* Heap contents are initialized to zero, as for anonymous | ||
876 | * mapped pages. */ | ||
877 | if (new_brk > target_brk) { | ||
878 | - memset(g2h(target_brk), 0, new_brk - target_brk); | ||
879 | + memset(g2h_untagged(target_brk), 0, new_brk - target_brk); | ||
880 | } | ||
881 | target_brk = new_brk; | ||
882 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk); | ||
883 | @@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk) | ||
884 | * come from the remaining part of the previous page: it may | ||
885 | * contains garbage data due to a previous heap usage (grown | ||
886 | * then shrunken). */ | ||
887 | - memset(g2h(target_brk), 0, brk_page - target_brk); | ||
888 | + memset(g2h_untagged(target_brk), 0, brk_page - target_brk); | ||
889 | |||
890 | target_brk = new_brk; | ||
891 | brk_page = HOST_PAGE_ALIGN(target_brk); | ||
892 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
893 | mmap_lock(); | ||
894 | |||
895 | if (shmaddr) | ||
896 | - host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg); | ||
897 | + host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg); | ||
898 | else { | ||
899 | abi_ulong mmap_start; | ||
900 | |||
901 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
902 | errno = ENOMEM; | ||
903 | host_raddr = (void *)-1; | ||
904 | } else | ||
905 | - host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP); | ||
906 | + host_raddr = shmat(shmid, g2h_untagged(mmap_start), | ||
907 | + shmflg | SHM_REMAP); | ||
908 | } | ||
909 | |||
910 | if (host_raddr == (void *)-1) { | ||
911 | @@ -XXX,XX +XXX,XX @@ static inline abi_long do_shmdt(abi_ulong shmaddr) | ||
912 | break; | ||
913 | } | ||
914 | } | ||
915 | - rv = get_errno(shmdt(g2h(shmaddr))); | ||
916 | + rv = get_errno(shmdt(g2h_untagged(shmaddr))); | ||
917 | |||
918 | mmap_unlock(); | ||
919 | |||
920 | @@ -XXX,XX +XXX,XX @@ static abi_long write_ldt(CPUX86State *env, | ||
921 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
922 | if (env->ldt.base == -1) | ||
923 | return -TARGET_ENOMEM; | ||
924 | - memset(g2h(env->ldt.base), 0, | ||
925 | + memset(g2h_untagged(env->ldt.base), 0, | ||
926 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); | ||
927 | env->ldt.limit = 0xffff; | ||
928 | - ldt_table = g2h(env->ldt.base); | ||
929 | + ldt_table = g2h_untagged(env->ldt.base); | ||
930 | } | ||
931 | |||
932 | /* NOTE: same code as Linux kernel */ | ||
933 | @@ -XXX,XX +XXX,XX @@ static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr, | ||
934 | #if defined(TARGET_ABI32) | ||
935 | abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr) | ||
936 | { | ||
937 | - uint64_t *gdt_table = g2h(env->gdt.base); | ||
938 | + uint64_t *gdt_table = g2h_untagged(env->gdt.base); | ||
939 | struct target_modify_ldt_ldt_s ldt_info; | ||
940 | struct target_modify_ldt_ldt_s *target_ldt_info; | ||
941 | int seg_32bit, contents, read_exec_only, limit_in_pages; | ||
942 | @@ -XXX,XX +XXX,XX @@ install: | ||
943 | static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr) | ||
944 | { | ||
945 | struct target_modify_ldt_ldt_s *target_ldt_info; | ||
946 | - uint64_t *gdt_table = g2h(env->gdt.base); | ||
947 | + uint64_t *gdt_table = g2h_untagged(env->gdt.base); | ||
948 | uint32_t base_addr, limit, flags; | ||
949 | int seg_32bit, contents, read_exec_only, limit_in_pages, idx; | ||
950 | int seg_not_present, useable, lm; | ||
951 | @@ -XXX,XX +XXX,XX @@ static int do_safe_futex(int *uaddr, int op, int val, | ||
952 | tricky. However they're probably useless because guest atomic | ||
953 | operations won't work either. */ | ||
954 | #if defined(TARGET_NR_futex) | ||
955 | -static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, | ||
956 | - target_ulong uaddr2, int val3) | ||
957 | +static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val, | ||
958 | + target_ulong timeout, target_ulong uaddr2, int val3) | ||
959 | { | ||
960 | struct timespec ts, *pts; | ||
961 | int base_op; | ||
962 | @@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, | ||
963 | } else { | ||
964 | pts = NULL; | ||
965 | } | ||
966 | - return do_safe_futex(g2h(uaddr), op, tswap32(val), pts, NULL, val3); | ||
967 | + return do_safe_futex(g2h(cpu, uaddr), | ||
968 | + op, tswap32(val), pts, NULL, val3); | ||
969 | case FUTEX_WAKE: | ||
970 | - return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0); | ||
971 | + return do_safe_futex(g2h(cpu, uaddr), | ||
972 | + op, val, NULL, NULL, 0); | ||
973 | case FUTEX_FD: | ||
974 | - return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0); | ||
975 | + return do_safe_futex(g2h(cpu, uaddr), | ||
976 | + op, val, NULL, NULL, 0); | ||
977 | case FUTEX_REQUEUE: | ||
978 | case FUTEX_CMP_REQUEUE: | ||
979 | case FUTEX_WAKE_OP: | ||
980 | @@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, | ||
981 | to satisfy the compiler. We do not need to tswap TIMEOUT | ||
982 | since it's not compared to guest memory. */ | ||
983 | pts = (struct timespec *)(uintptr_t) timeout; | ||
984 | - return do_safe_futex(g2h(uaddr), op, val, pts, g2h(uaddr2), | ||
985 | + return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2), | ||
986 | (base_op == FUTEX_CMP_REQUEUE | ||
987 | - ? tswap32(val3) | ||
988 | - : val3)); | ||
989 | + ? tswap32(val3) : val3)); | ||
990 | default: | ||
991 | return -TARGET_ENOSYS; | ||
992 | } | ||
993 | @@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, | ||
994 | #endif | ||
995 | |||
996 | #if defined(TARGET_NR_futex_time64) | ||
997 | -static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong timeout, | ||
998 | +static int do_futex_time64(CPUState *cpu, target_ulong uaddr, int op, | ||
999 | + int val, target_ulong timeout, | ||
1000 | target_ulong uaddr2, int val3) | ||
1001 | { | ||
1002 | struct timespec ts, *pts; | ||
1003 | @@ -XXX,XX +XXX,XX @@ static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong tim | ||
1004 | } else { | ||
1005 | pts = NULL; | ||
1006 | } | ||
1007 | - return do_safe_futex(g2h(uaddr), op, tswap32(val), pts, NULL, val3); | ||
1008 | + return do_safe_futex(g2h(cpu, uaddr), op, | ||
1009 | + tswap32(val), pts, NULL, val3); | ||
1010 | case FUTEX_WAKE: | ||
1011 | - return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0); | ||
1012 | + return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0); | ||
1013 | case FUTEX_FD: | ||
1014 | - return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0); | ||
1015 | + return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0); | ||
1016 | case FUTEX_REQUEUE: | ||
1017 | case FUTEX_CMP_REQUEUE: | ||
1018 | case FUTEX_WAKE_OP: | ||
1019 | @@ -XXX,XX +XXX,XX @@ static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong tim | ||
1020 | to satisfy the compiler. We do not need to tswap TIMEOUT | ||
1021 | since it's not compared to guest memory. */ | ||
1022 | pts = (struct timespec *)(uintptr_t) timeout; | ||
1023 | - return do_safe_futex(g2h(uaddr), op, val, pts, g2h(uaddr2), | ||
1024 | + return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2), | ||
1025 | (base_op == FUTEX_CMP_REQUEUE | ||
1026 | - ? tswap32(val3) | ||
1027 | - : val3)); | ||
1028 | + ? tswap32(val3) : val3)); | ||
1029 | default: | ||
1030 | return -TARGET_ENOSYS; | ||
1031 | } | ||
1032 | @@ -XXX,XX +XXX,XX @@ static int open_self_maps(void *cpu_env, int fd) | ||
1033 | const char *path; | ||
1034 | |||
1035 | max = h2g_valid(max - 1) ? | ||
1036 | - max : (uintptr_t) g2h(GUEST_ADDR_MAX) + 1; | ||
1037 | + max : (uintptr_t) g2h_untagged(GUEST_ADDR_MAX) + 1; | ||
1038 | |||
1039 | if (page_check_range(h2g(min), max - min, flags) == -1) { | ||
1040 | continue; | ||
1041 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
1042 | |||
1043 | if (ts->child_tidptr) { | ||
1044 | put_user_u32(0, ts->child_tidptr); | ||
1045 | - do_sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, | ||
1046 | - NULL, NULL, 0); | ||
1047 | + do_sys_futex(g2h(cpu, ts->child_tidptr), | ||
1048 | + FUTEX_WAKE, INT_MAX, NULL, NULL, 0); | ||
1049 | } | ||
1050 | thread_cpu = NULL; | ||
1051 | g_free(ts); | ||
1052 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
1053 | if (!arg5) { | ||
1054 | ret = mount(p, p2, p3, (unsigned long)arg4, NULL); | ||
1055 | } else { | ||
1056 | - ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)); | ||
1057 | + ret = mount(p, p2, p3, (unsigned long)arg4, g2h(cpu, arg5)); | ||
1058 | } | ||
1059 | ret = get_errno(ret); | ||
1060 | |||
1061 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
1062 | /* ??? msync/mlock/munlock are broken for softmmu. */ | ||
1063 | #ifdef TARGET_NR_msync | ||
1064 | case TARGET_NR_msync: | ||
1065 | - return get_errno(msync(g2h(arg1), arg2, arg3)); | ||
1066 | + return get_errno(msync(g2h(cpu, arg1), arg2, arg3)); | ||
1067 | #endif | ||
1068 | #ifdef TARGET_NR_mlock | ||
1069 | case TARGET_NR_mlock: | ||
1070 | - return get_errno(mlock(g2h(arg1), arg2)); | ||
1071 | + return get_errno(mlock(g2h(cpu, arg1), arg2)); | ||
1072 | #endif | ||
1073 | #ifdef TARGET_NR_munlock | ||
1074 | case TARGET_NR_munlock: | ||
1075 | - return get_errno(munlock(g2h(arg1), arg2)); | ||
1076 | + return get_errno(munlock(g2h(cpu, arg1), arg2)); | ||
1077 | #endif | ||
1078 | #ifdef TARGET_NR_mlockall | ||
1079 | case TARGET_NR_mlockall: | ||
1080 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
1081 | |||
1082 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) | ||
1083 | case TARGET_NR_set_tid_address: | ||
1084 | - return get_errno(set_tid_address((int *)g2h(arg1))); | ||
1085 | + return get_errno(set_tid_address((int *)g2h(cpu, arg1))); | ||
1086 | #endif | ||
1087 | |||
1088 | case TARGET_NR_tkill: | ||
1089 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
1090 | #endif | ||
1091 | #ifdef TARGET_NR_futex | ||
1092 | case TARGET_NR_futex: | ||
1093 | - return do_futex(arg1, arg2, arg3, arg4, arg5, arg6); | ||
1094 | + return do_futex(cpu, arg1, arg2, arg3, arg4, arg5, arg6); | ||
1095 | #endif | ||
1096 | #ifdef TARGET_NR_futex_time64 | ||
1097 | case TARGET_NR_futex_time64: | ||
1098 | - return do_futex_time64(arg1, arg2, arg3, arg4, arg5, arg6); | ||
1099 | + return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6); | ||
1100 | #endif | ||
1101 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) | ||
1102 | case TARGET_NR_inotify_init: | ||
1103 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c | ||
1104 | index XXXXXXX..XXXXXXX 100644 | ||
1105 | --- a/target/arm/helper-a64.c | ||
1106 | +++ b/target/arm/helper-a64.c | ||
1107 | @@ -XXX,XX +XXX,XX @@ uint64_t HELPER(paired_cmpxchg64_le)(CPUARMState *env, uint64_t addr, | ||
1108 | |||
1109 | #ifdef CONFIG_USER_ONLY | ||
1110 | /* ??? Enforce alignment. */ | ||
1111 | - uint64_t *haddr = g2h(addr); | ||
1112 | + uint64_t *haddr = g2h(env_cpu(env), addr); | ||
1113 | |||
1114 | set_helper_retaddr(ra); | ||
1115 | o0 = ldq_le_p(haddr + 0); | ||
1116 | @@ -XXX,XX +XXX,XX @@ uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr, | ||
1117 | |||
1118 | #ifdef CONFIG_USER_ONLY | ||
1119 | /* ??? Enforce alignment. */ | ||
1120 | - uint64_t *haddr = g2h(addr); | ||
1121 | + uint64_t *haddr = g2h(env_cpu(env), addr); | ||
1122 | |||
1123 | set_helper_retaddr(ra); | ||
1124 | o1 = ldq_be_p(haddr + 0); | ||
1125 | diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c | ||
1126 | index XXXXXXX..XXXXXXX 100644 | ||
1127 | --- a/target/hppa/op_helper.c | ||
1128 | +++ b/target/hppa/op_helper.c | ||
1129 | @@ -XXX,XX +XXX,XX @@ static void atomic_store_3(CPUHPPAState *env, target_ulong addr, uint32_t val, | ||
1130 | #ifdef CONFIG_USER_ONLY | ||
1131 | uint32_t old, new, cmp; | ||
1132 | |||
1133 | - uint32_t *haddr = g2h(addr - 1); | ||
1134 | + uint32_t *haddr = g2h(env_cpu(env), addr - 1); | ||
1135 | old = *haddr; | ||
1136 | while (1) { | ||
1137 | new = (old & ~mask) | (val & mask); | ||
1138 | diff --git a/target/i386/tcg/mem_helper.c b/target/i386/tcg/mem_helper.c | ||
1139 | index XXXXXXX..XXXXXXX 100644 | ||
1140 | --- a/target/i386/tcg/mem_helper.c | ||
1141 | +++ b/target/i386/tcg/mem_helper.c | ||
1142 | @@ -XXX,XX +XXX,XX @@ void helper_cmpxchg8b(CPUX86State *env, target_ulong a0) | ||
1143 | |||
1144 | #ifdef CONFIG_USER_ONLY | ||
1145 | { | ||
1146 | - uint64_t *haddr = g2h(a0); | ||
1147 | + uint64_t *haddr = g2h(env_cpu(env), a0); | ||
1148 | cmpv = cpu_to_le64(cmpv); | ||
1149 | newv = cpu_to_le64(newv); | ||
1150 | oldv = qatomic_cmpxchg__nocheck(haddr, cmpv, newv); | ||
1151 | diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c | ||
1152 | index XXXXXXX..XXXXXXX 100644 | ||
1153 | --- a/target/s390x/mem_helper.c | ||
1154 | +++ b/target/s390x/mem_helper.c | ||
1155 | @@ -XXX,XX +XXX,XX @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, | ||
1156 | |||
1157 | if (parallel) { | ||
1158 | #ifdef CONFIG_USER_ONLY | ||
1159 | - uint32_t *haddr = g2h(a1); | ||
1160 | + uint32_t *haddr = g2h(env_cpu(env), a1); | ||
1161 | ov = qatomic_cmpxchg__nocheck(haddr, cv, nv); | ||
1162 | #else | ||
1163 | TCGMemOpIdx oi = make_memop_idx(MO_TEUL | MO_ALIGN, mem_idx); | ||
1164 | @@ -XXX,XX +XXX,XX @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1, | ||
1165 | if (parallel) { | ||
1166 | #ifdef CONFIG_ATOMIC64 | ||
1167 | # ifdef CONFIG_USER_ONLY | ||
1168 | - uint64_t *haddr = g2h(a1); | ||
1169 | + uint64_t *haddr = g2h(env_cpu(env), a1); | ||
1170 | ov = qatomic_cmpxchg__nocheck(haddr, cv, nv); | ||
1171 | # else | ||
1172 | TCGMemOpIdx oi = make_memop_idx(MO_TEQ | MO_ALIGN, mem_idx); | ||
245 | -- | 1173 | -- |
246 | 2.20.1 | 1174 | 2.20.1 |
247 | 1175 | ||
248 | 1176 | diff view generated by jsdifflib |
1 | From: Alexander Graf <agraf@csgraf.de> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | In macOS 11, QEMU only gets access to Hypervisor.framework if it has the | 3 | We define target_mmap et al as untagged, so that they can be |
4 | respective entitlement. Add an entitlement template and automatically self | 4 | used from the binary loaders. Explicitly call cpu_untagged_addr |
5 | sign and apply the entitlement in the build. | 5 | for munmap, mprotect, mremap syscall entry points. |
6 | 6 | ||
7 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | 7 | Add a few comments for the syscalls that are exempted by the |
8 | Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com> | 8 | kernel's tagged-address-abi.rst. |
9 | Tested-by: Roman Bolshakov <r.bolshakov@yadro.com> | 9 | |
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20210212184902.1251044-14-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 14 | --- |
12 | meson.build | 29 +++++++++++++++++++++++++---- | 15 | linux-user/syscall.c | 11 +++++++++++ |
13 | accel/hvf/entitlements.plist | 8 ++++++++ | 16 | 1 file changed, 11 insertions(+) |
14 | scripts/entitlement.sh | 13 +++++++++++++ | ||
15 | 3 files changed, 46 insertions(+), 4 deletions(-) | ||
16 | create mode 100644 accel/hvf/entitlements.plist | ||
17 | create mode 100755 scripts/entitlement.sh | ||
18 | 17 | ||
19 | diff --git a/meson.build b/meson.build | 18 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
20 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/meson.build | 20 | --- a/linux-user/syscall.c |
22 | +++ b/meson.build | 21 | +++ b/linux-user/syscall.c |
23 | @@ -XXX,XX +XXX,XX @@ foreach target : target_dirs | 22 | @@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk) |
24 | }] | 23 | abi_long mapped_addr; |
25 | endif | 24 | abi_ulong new_alloc_size; |
26 | foreach exe: execs | 25 | |
27 | - emulators += {exe['name']: | 26 | + /* brk pointers are always untagged */ |
28 | - executable(exe['name'], exe['sources'], | ||
29 | - install: true, | ||
30 | + exe_name = exe['name'] | ||
31 | + exe_sign = 'CONFIG_HVF' in config_target | ||
32 | + if exe_sign | ||
33 | + exe_name += '-unsigned' | ||
34 | + endif | ||
35 | + | 27 | + |
36 | + emulator = executable(exe_name, exe['sources'], | 28 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); |
37 | + install: not exe_sign, | 29 | |
38 | c_args: c_args, | 30 | if (!new_brk) { |
39 | dependencies: arch_deps + deps + exe['dependencies'], | 31 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, |
40 | objects: lib.extract_all_objects(recursive: true), | 32 | int i,ret; |
41 | @@ -XXX,XX +XXX,XX @@ foreach target : target_dirs | 33 | abi_ulong shmlba; |
42 | link_depends: [block_syms, qemu_syms] + exe.get('link_depends', []), | 34 | |
43 | link_args: link_args, | 35 | + /* shmat pointers are always untagged */ |
44 | gui_app: exe['gui']) | ||
45 | - } | ||
46 | + | 36 | + |
47 | + if exe_sign | 37 | /* find out the length of the shared memory segment */ |
48 | + emulators += {exe['name'] : custom_target(exe['name'], | 38 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); |
49 | + install: true, | 39 | if (is_error(ret)) { |
50 | + install_dir: get_option('bindir'), | 40 | @@ -XXX,XX +XXX,XX @@ static inline abi_long do_shmdt(abi_ulong shmaddr) |
51 | + depends: emulator, | 41 | int i; |
52 | + output: exe['name'], | 42 | abi_long rv; |
53 | + command: [ | 43 | |
54 | + meson.current_source_dir() / 'scripts/entitlement.sh', | 44 | + /* shmdt pointers are always untagged */ |
55 | + meson.current_build_dir() / exe_name, | ||
56 | + meson.current_build_dir() / exe['name'], | ||
57 | + meson.current_source_dir() / 'accel/hvf/entitlements.plist' | ||
58 | + ]) | ||
59 | + } | ||
60 | + else | ||
61 | + emulators += {exe['name']: emulator} | ||
62 | + endif | ||
63 | |||
64 | if 'CONFIG_TRACE_SYSTEMTAP' in config_host | ||
65 | foreach stp: [ | ||
66 | diff --git a/accel/hvf/entitlements.plist b/accel/hvf/entitlements.plist | ||
67 | new file mode 100644 | ||
68 | index XXXXXXX..XXXXXXX | ||
69 | --- /dev/null | ||
70 | +++ b/accel/hvf/entitlements.plist | ||
71 | @@ -XXX,XX +XXX,XX @@ | ||
72 | +<?xml version="1.0" encoding="UTF-8"?> | ||
73 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
74 | +<plist version="1.0"> | ||
75 | +<dict> | ||
76 | + <key>com.apple.security.hypervisor</key> | ||
77 | + <true/> | ||
78 | +</dict> | ||
79 | +</plist> | ||
80 | diff --git a/scripts/entitlement.sh b/scripts/entitlement.sh | ||
81 | new file mode 100755 | ||
82 | index XXXXXXX..XXXXXXX | ||
83 | --- /dev/null | ||
84 | +++ b/scripts/entitlement.sh | ||
85 | @@ -XXX,XX +XXX,XX @@ | ||
86 | +#!/bin/sh -e | ||
87 | +# | ||
88 | +# Helper script for the build process to apply entitlements | ||
89 | + | 45 | + |
90 | +SRC="$1" | 46 | mmap_lock(); |
91 | +DST="$2" | 47 | |
92 | +ENTITLEMENT="$3" | 48 | for (i = 0; i < N_SHM_REGIONS; ++i) { |
93 | + | 49 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
94 | +trap 'rm "$DST.tmp"' exit | 50 | v5, v6)); |
95 | +cp -af "$SRC" "$DST.tmp" | 51 | } |
96 | +codesign --entitlements "$ENTITLEMENT" --force -s - "$DST.tmp" | 52 | #else |
97 | +mv "$DST.tmp" "$DST" | 53 | + /* mmap pointers are always untagged */ |
98 | +trap '' exit | 54 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
55 | target_to_host_bitmask(arg4, mmap_flags_tbl), | ||
56 | arg5, | ||
57 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
58 | return get_errno(ret); | ||
59 | #endif | ||
60 | case TARGET_NR_munmap: | ||
61 | + arg1 = cpu_untagged_addr(cpu, arg1); | ||
62 | return get_errno(target_munmap(arg1, arg2)); | ||
63 | case TARGET_NR_mprotect: | ||
64 | + arg1 = cpu_untagged_addr(cpu, arg1); | ||
65 | { | ||
66 | TaskState *ts = cpu->opaque; | ||
67 | /* Special hack to detect libc making the stack executable. */ | ||
68 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
69 | return get_errno(target_mprotect(arg1, arg2, arg3)); | ||
70 | #ifdef TARGET_NR_mremap | ||
71 | case TARGET_NR_mremap: | ||
72 | + arg1 = cpu_untagged_addr(cpu, arg1); | ||
73 | + /* mremap new_addr (arg5) is always untagged */ | ||
74 | return get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); | ||
75 | #endif | ||
76 | /* ??? msync/mlock/munlock are broken for softmmu. */ | ||
99 | -- | 77 | -- |
100 | 2.20.1 | 78 | 2.20.1 |
101 | 79 | ||
102 | 80 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | A workaround added in early days of 64-bit OSX forced x86_64 if the | 3 | We're currently open-coding the range check in access_ok; |
4 | host machine had 64-bit support. This creates issues when cross- | 4 | use guest_range_valid when size != 0. |
5 | compiling for ARM64. Additionally, the user can always use --cpu=* to | ||
6 | manually set the host CPU and therefore this workaround should be | ||
7 | removed. | ||
8 | 5 | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Message-id: 20210126012457.39046-12-j@getutm.app | 8 | Message-id: 20210212184902.1251044-15-richard.henderson@linaro.org |
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 10 | --- |
14 | configure | 11 ----------- | 11 | linux-user/qemu.h | 9 +++------ |
15 | 1 file changed, 11 deletions(-) | 12 | 1 file changed, 3 insertions(+), 6 deletions(-) |
16 | 13 | ||
17 | diff --git a/configure b/configure | 14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
18 | index XXXXXXX..XXXXXXX 100755 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/configure | 16 | --- a/linux-user/qemu.h |
20 | +++ b/configure | 17 | +++ b/linux-user/qemu.h |
21 | @@ -XXX,XX +XXX,XX @@ fi | 18 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
22 | # the correct CPU with the --cpu option. | 19 | |
23 | case $targetos in | 20 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
24 | Darwin) | 21 | { |
25 | - # on Leopard most of the system is 32-bit, so we have to ask the kernel if we can | 22 | - if (!guest_addr_valid(addr)) { |
26 | - # run 64-bit userspace code. | 23 | - return false; |
27 | - # If the user didn't specify a CPU explicitly and the kernel says this is | 24 | - } |
28 | - # 64 bit hw, then assume x86_64. Otherwise fall through to the usual detection code. | 25 | - if (size != 0 && |
29 | - if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then | 26 | - (addr + size - 1 < addr || |
30 | - cpu="x86_64" | 27 | - !guest_addr_valid(addr + size - 1))) { |
31 | - fi | 28 | + if (size == 0 |
32 | HOST_DSOSUF=".dylib" | 29 | + ? !guest_addr_valid(addr) |
33 | ;; | 30 | + : !guest_range_valid(addr, size)) { |
34 | SunOS) | 31 | return false; |
35 | @@ -XXX,XX +XXX,XX @@ OpenBSD) | 32 | } |
36 | Darwin) | 33 | return page_check_range((target_ulong)addr, size, type) == 0; |
37 | bsd="yes" | ||
38 | darwin="yes" | ||
39 | - if [ "$cpu" = "x86_64" ] ; then | ||
40 | - QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS" | ||
41 | - QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS" | ||
42 | - fi | ||
43 | audio_drv_list="try-coreaudio try-sdl" | ||
44 | audio_possible_drivers="coreaudio sdl" | ||
45 | # Disable attempts to use ObjectiveC features in os/object.h since they | ||
46 | -- | 34 | -- |
47 | 2.20.1 | 35 | 2.20.1 |
48 | 36 | ||
49 | 37 | diff view generated by jsdifflib |
1 | Switch the CMSDK APB timer device over to using its Clock input; the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | pclk-frq property is now ignored. | ||
3 | 2 | ||
3 | The places that use these are better off using untagged | ||
4 | addresses, so do not provide a tagged versions. Rename | ||
5 | to make it clear about the address type. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20210212184902.1251044-16-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-19-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-19-peter.maydell@linaro.org | ||
10 | --- | 11 | --- |
11 | hw/timer/cmsdk-apb-timer.c | 18 ++++++++++++++---- | 12 | include/exec/cpu_ldst.h | 4 ++-- |
12 | 1 file changed, 14 insertions(+), 4 deletions(-) | 13 | linux-user/qemu.h | 4 ++-- |
14 | accel/tcg/user-exec.c | 3 ++- | ||
15 | linux-user/mmap.c | 14 +++++++------- | ||
16 | linux-user/syscall.c | 2 +- | ||
17 | 5 files changed, 14 insertions(+), 13 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c | 19 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/timer/cmsdk-apb-timer.c | 21 | --- a/include/exec/cpu_ldst.h |
17 | +++ b/hw/timer/cmsdk-apb-timer.c | 22 | +++ b/include/exec/cpu_ldst.h |
18 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_reset(DeviceState *dev) | 23 | @@ -XXX,XX +XXX,XX @@ static inline void *g2h(CPUState *cs, abi_ptr x) |
19 | ptimer_transaction_commit(s->timer); | 24 | return g2h_untagged(cpu_untagged_addr(cs, x)); |
20 | } | 25 | } |
21 | 26 | ||
22 | +static void cmsdk_apb_timer_clk_update(void *opaque) | 27 | -static inline bool guest_addr_valid(abi_ulong x) |
23 | +{ | 28 | +static inline bool guest_addr_valid_untagged(abi_ulong x) |
24 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(opaque); | ||
25 | + | ||
26 | + ptimer_transaction_begin(s->timer); | ||
27 | + ptimer_set_period_from_clock(s->timer, s->pclk, 1); | ||
28 | + ptimer_transaction_commit(s->timer); | ||
29 | +} | ||
30 | + | ||
31 | static void cmsdk_apb_timer_init(Object *obj) | ||
32 | { | 29 | { |
33 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 30 | return x <= GUEST_ADDR_MAX; |
34 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_init(Object *obj) | ||
35 | s, "cmsdk-apb-timer", 0x1000); | ||
36 | sysbus_init_mmio(sbd, &s->iomem); | ||
37 | sysbus_init_irq(sbd, &s->timerint); | ||
38 | - s->pclk = qdev_init_clock_in(DEVICE(s), "pclk", NULL, NULL); | ||
39 | + s->pclk = qdev_init_clock_in(DEVICE(s), "pclk", | ||
40 | + cmsdk_apb_timer_clk_update, s); | ||
41 | } | 31 | } |
42 | 32 | ||
43 | static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) | 33 | -static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
34 | +static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len) | ||
44 | { | 35 | { |
45 | CMSDKAPBTimer *s = CMSDK_APB_TIMER(dev); | 36 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
46 | 37 | } | |
47 | - if (s->pclk_frq == 0) { | 38 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
48 | - error_setg(errp, "CMSDK APB timer: pclk-frq property must be set"); | 39 | index XXXXXXX..XXXXXXX 100644 |
49 | + if (!clock_has_source(s->pclk)) { | 40 | --- a/linux-user/qemu.h |
50 | + error_setg(errp, "CMSDK APB timer: pclk clock must be connected"); | 41 | +++ b/linux-user/qemu.h |
51 | return; | 42 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
43 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
44 | { | ||
45 | if (size == 0 | ||
46 | - ? !guest_addr_valid(addr) | ||
47 | - : !guest_range_valid(addr, size)) { | ||
48 | + ? !guest_addr_valid_untagged(addr) | ||
49 | + : !guest_range_valid_untagged(addr, size)) { | ||
50 | return false; | ||
52 | } | 51 | } |
53 | 52 | return page_check_range((target_ulong)addr, size, type) == 0; | |
54 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) | 53 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c |
55 | PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); | 54 | index XXXXXXX..XXXXXXX 100644 |
56 | 55 | --- a/accel/tcg/user-exec.c | |
57 | ptimer_transaction_begin(s->timer); | 56 | +++ b/accel/tcg/user-exec.c |
58 | - ptimer_set_freq(s->timer, s->pclk_frq); | 57 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, |
59 | + ptimer_set_period_from_clock(s->timer, s->pclk, 1); | 58 | g_assert_not_reached(); |
60 | ptimer_transaction_commit(s->timer); | 59 | } |
61 | } | 60 | |
61 | - if (!guest_addr_valid(addr) || page_check_range(addr, 1, flags) < 0) { | ||
62 | + if (!guest_addr_valid_untagged(addr) || | ||
63 | + page_check_range(addr, 1, flags) < 0) { | ||
64 | if (nonfault) { | ||
65 | return TLB_INVALID_MASK; | ||
66 | } else { | ||
67 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/linux-user/mmap.c | ||
70 | +++ b/linux-user/mmap.c | ||
71 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) | ||
72 | } | ||
73 | len = TARGET_PAGE_ALIGN(len); | ||
74 | end = start + len; | ||
75 | - if (!guest_range_valid(start, len)) { | ||
76 | + if (!guest_range_valid_untagged(start, len)) { | ||
77 | return -TARGET_ENOMEM; | ||
78 | } | ||
79 | if (len == 0) { | ||
80 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, | ||
81 | * It can fail only on 64-bit host with 32-bit target. | ||
82 | * On any other target/host host mmap() handles this error correctly. | ||
83 | */ | ||
84 | - if (end < start || !guest_range_valid(start, len)) { | ||
85 | + if (end < start || !guest_range_valid_untagged(start, len)) { | ||
86 | errno = ENOMEM; | ||
87 | goto fail; | ||
88 | } | ||
89 | @@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len) | ||
90 | if (start & ~TARGET_PAGE_MASK) | ||
91 | return -TARGET_EINVAL; | ||
92 | len = TARGET_PAGE_ALIGN(len); | ||
93 | - if (len == 0 || !guest_range_valid(start, len)) { | ||
94 | + if (len == 0 || !guest_range_valid_untagged(start, len)) { | ||
95 | return -TARGET_EINVAL; | ||
96 | } | ||
97 | |||
98 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
99 | int prot; | ||
100 | void *host_addr; | ||
101 | |||
102 | - if (!guest_range_valid(old_addr, old_size) || | ||
103 | + if (!guest_range_valid_untagged(old_addr, old_size) || | ||
104 | ((flags & MREMAP_FIXED) && | ||
105 | - !guest_range_valid(new_addr, new_size)) || | ||
106 | + !guest_range_valid_untagged(new_addr, new_size)) || | ||
107 | ((flags & MREMAP_MAYMOVE) == 0 && | ||
108 | - !guest_range_valid(old_addr, new_size))) { | ||
109 | + !guest_range_valid_untagged(old_addr, new_size))) { | ||
110 | errno = ENOMEM; | ||
111 | return -1; | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
114 | |||
115 | if (host_addr != MAP_FAILED) { | ||
116 | /* Check if address fits target address space */ | ||
117 | - if (!guest_range_valid(h2g(host_addr), new_size)) { | ||
118 | + if (!guest_range_valid_untagged(h2g(host_addr), new_size)) { | ||
119 | /* Revert mremap() changes */ | ||
120 | host_addr = mremap(g2h_untagged(old_addr), | ||
121 | new_size, old_size, flags); | ||
122 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/linux-user/syscall.c | ||
125 | +++ b/linux-user/syscall.c | ||
126 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
127 | return -TARGET_EINVAL; | ||
128 | } | ||
129 | } | ||
130 | - if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) { | ||
131 | + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { | ||
132 | return -TARGET_EINVAL; | ||
133 | } | ||
62 | 134 | ||
63 | -- | 135 | -- |
64 | 2.20.1 | 136 | 2.20.1 |
65 | 137 | ||
66 | 138 | diff view generated by jsdifflib |
1 | Use the MAINCLK Clock input to set the system_clock_scale variable | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | rather than using the mainclk_frq property. | ||
3 | 2 | ||
3 | Provide both tagged and untagged versions of access_ok. | ||
4 | In a few places use thread_cpu, as the user is several | ||
5 | callees removed from do_syscall1. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20210212184902.1251044-17-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
8 | Message-id: 20210128114145.20536-23-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-23-peter.maydell@linaro.org | ||
10 | --- | 11 | --- |
11 | hw/arm/armsse.c | 24 +++++++++++++++++++----- | 12 | linux-user/qemu.h | 11 +++++++++-- |
12 | 1 file changed, 19 insertions(+), 5 deletions(-) | 13 | linux-user/elfload.c | 2 +- |
14 | linux-user/hppa/cpu_loop.c | 8 ++++---- | ||
15 | linux-user/i386/cpu_loop.c | 2 +- | ||
16 | linux-user/i386/signal.c | 5 +++-- | ||
17 | linux-user/syscall.c | 9 ++++++--- | ||
18 | 6 files changed, 24 insertions(+), 13 deletions(-) | ||
13 | 19 | ||
14 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | 20 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/armsse.c | 22 | --- a/linux-user/qemu.h |
17 | +++ b/hw/arm/armsse.c | 23 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s) | 24 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
19 | qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in); | 25 | #define VERIFY_READ PAGE_READ |
26 | #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) | ||
27 | |||
28 | -static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
29 | +static inline bool access_ok_untagged(int type, abi_ulong addr, abi_ulong size) | ||
30 | { | ||
31 | if (size == 0 | ||
32 | ? !guest_addr_valid_untagged(addr) | ||
33 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
34 | return page_check_range((target_ulong)addr, size, type) == 0; | ||
20 | } | 35 | } |
21 | 36 | ||
22 | +static void armsse_mainclk_update(void *opaque) | 37 | +static inline bool access_ok(CPUState *cpu, int type, |
38 | + abi_ulong addr, abi_ulong size) | ||
23 | +{ | 39 | +{ |
24 | + ARMSSE *s = ARM_SSE(opaque); | 40 | + return access_ok_untagged(type, cpu_untagged_addr(cpu, addr), size); |
25 | + /* | ||
26 | + * Set system_clock_scale from our Clock input; this is what | ||
27 | + * controls the tick rate of the CPU SysTick timer. | ||
28 | + */ | ||
29 | + system_clock_scale = clock_ticks_to_ns(s->mainclk, 1); | ||
30 | +} | 41 | +} |
31 | + | 42 | + |
32 | static void armsse_init(Object *obj) | 43 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
44 | These are usually used to access struct data members once the struct has | ||
45 | been locked - usually with lock_user_struct. */ | ||
46 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | ||
47 | host area will have the same contents as the guest. */ | ||
48 | static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
33 | { | 49 | { |
34 | ARMSSE *s = ARM_SSE(obj); | 50 | - if (!access_ok(type, guest_addr, len)) |
35 | @@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj) | 51 | + if (!access_ok_untagged(type, guest_addr, len)) { |
36 | assert(info->sram_banks <= MAX_SRAM_BANKS); | 52 | return NULL; |
37 | assert(info->num_cpus <= SSE_MAX_CPUS); | 53 | + } |
38 | 54 | #ifdef DEBUG_REMAP | |
39 | - s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", NULL, NULL); | 55 | { |
40 | + s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", | 56 | void *addr; |
41 | + armsse_mainclk_update, s); | 57 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
42 | s->s32kclk = qdev_init_clock_in(DEVICE(s), "S32KCLK", NULL, NULL); | 58 | index XXXXXXX..XXXXXXX 100644 |
43 | 59 | --- a/linux-user/elfload.c | |
44 | memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX); | 60 | +++ b/linux-user/elfload.c |
45 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | 61 | @@ -XXX,XX +XXX,XX @@ static int vma_get_mapping_count(const struct mm_struct *mm) |
46 | return; | 62 | static abi_ulong vma_dump_size(const struct vm_area_struct *vma) |
63 | { | ||
64 | /* if we cannot even read the first page, skip it */ | ||
65 | - if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) | ||
66 | + if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) | ||
67 | return (0); | ||
68 | |||
69 | /* | ||
70 | diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/linux-user/hppa/cpu_loop.c | ||
73 | +++ b/linux-user/hppa/cpu_loop.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
75 | return -TARGET_ENOSYS; | ||
76 | |||
77 | case 0: /* elf32 atomic 32bit cmpxchg */ | ||
78 | - if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) { | ||
79 | + if ((addr & 3) || !access_ok(cs, VERIFY_WRITE, addr, 4)) { | ||
80 | return -TARGET_EFAULT; | ||
81 | } | ||
82 | old = tswap32(old); | ||
83 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
84 | return -TARGET_ENOSYS; | ||
85 | } | ||
86 | if (((addr | old | new) & ((1 << size) - 1)) | ||
87 | - || !access_ok(VERIFY_WRITE, addr, 1 << size) | ||
88 | - || !access_ok(VERIFY_READ, old, 1 << size) | ||
89 | - || !access_ok(VERIFY_READ, new, 1 << size)) { | ||
90 | + || !access_ok(cs, VERIFY_WRITE, addr, 1 << size) | ||
91 | + || !access_ok(cs, VERIFY_READ, old, 1 << size) | ||
92 | + || !access_ok(cs, VERIFY_READ, new, 1 << size)) { | ||
93 | return -TARGET_EFAULT; | ||
94 | } | ||
95 | /* Note that below we use host-endian loads so that the cmpxchg | ||
96 | diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/linux-user/i386/cpu_loop.c | ||
99 | +++ b/linux-user/i386/cpu_loop.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len) | ||
101 | * For all the vsyscalls, NULL means "don't write anything" not | ||
102 | * "write it at address 0". | ||
103 | */ | ||
104 | - if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) { | ||
105 | + if (addr == 0 || access_ok(env_cpu(env), VERIFY_WRITE, addr, len)) { | ||
106 | return true; | ||
47 | } | 107 | } |
48 | 108 | ||
49 | - if (!s->mainclk_frq) { | 109 | diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c |
50 | - error_setg(errp, "MAINCLK_FRQ property was not set"); | 110 | index XXXXXXX..XXXXXXX 100644 |
51 | - return; | 111 | --- a/linux-user/i386/signal.c |
52 | + if (!clock_has_source(s->mainclk)) { | 112 | +++ b/linux-user/i386/signal.c |
53 | + error_setg(errp, "MAINCLK clock was not connected"); | 113 | @@ -XXX,XX +XXX,XX @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) |
114 | |||
115 | fpstate_addr = tswapl(sc->fpstate); | ||
116 | if (fpstate_addr != 0) { | ||
117 | - if (!access_ok(VERIFY_READ, fpstate_addr, | ||
118 | - sizeof(struct target_fpstate))) | ||
119 | + if (!access_ok(env_cpu(env), VERIFY_READ, fpstate_addr, | ||
120 | + sizeof(struct target_fpstate))) { | ||
121 | goto badframe; | ||
122 | + } | ||
123 | #ifndef TARGET_X86_64 | ||
124 | cpu_x86_frstor(env, fpstate_addr, 1); | ||
125 | #else | ||
126 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/linux-user/syscall.c | ||
129 | +++ b/linux-user/syscall.c | ||
130 | @@ -XXX,XX +XXX,XX @@ static abi_long do_accept4(int fd, abi_ulong target_addr, | ||
131 | return -TARGET_EINVAL; | ||
132 | } | ||
133 | |||
134 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) | ||
135 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { | ||
136 | return -TARGET_EFAULT; | ||
54 | + } | 137 | + } |
55 | + if (!clock_has_source(s->s32kclk)) { | 138 | |
56 | + error_setg(errp, "S32KCLK clock was not connected"); | 139 | addr = alloca(addrlen); |
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, | ||
142 | return -TARGET_EINVAL; | ||
57 | } | 143 | } |
58 | 144 | ||
59 | assert(info->num_cpus <= SSE_MAX_CPUS); | 145 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
60 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | 146 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { |
61 | */ | 147 | return -TARGET_EFAULT; |
62 | sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->container); | 148 | + } |
63 | 149 | ||
64 | - system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq; | 150 | addr = alloca(addrlen); |
65 | + /* Set initial system_clock_scale from MAINCLK */ | 151 | |
66 | + armsse_mainclk_update(s); | 152 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, |
67 | } | 153 | return -TARGET_EINVAL; |
68 | 154 | } | |
69 | static void armsse_idau_check(IDAUInterface *ii, uint32_t address, | 155 | |
156 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) | ||
157 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { | ||
158 | return -TARGET_EFAULT; | ||
159 | + } | ||
160 | |||
161 | addr = alloca(addrlen); | ||
162 | |||
70 | -- | 163 | -- |
71 | 2.20.1 | 164 | 2.20.1 |
72 | 165 | ||
73 | 166 | diff view generated by jsdifflib |
1 | From: Mihai Carabas <mihai.carabas@oracle.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add a test case for pvpanic-pci device. The scenario is the same as pvpanic | 3 | These functions are not small, except for unlock_user |
4 | ISA device, but is using the PCI bus. | 4 | without debugging enabled. Move them out of line, and |
5 | add missing braces on the way. | ||
5 | 6 | ||
6 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | ||
7 | Acked-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 20210212184902.1251044-18-richard.henderson@linaro.org | ||
11 | [PMM: fixed the sense of an ifdef test in qemu.h] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 13 | --- |
12 | tests/qtest/pvpanic-pci-test.c | 94 ++++++++++++++++++++++++++++++++++ | 14 | linux-user/qemu.h | 47 +++++++------------------------------------- |
13 | tests/qtest/meson.build | 1 + | 15 | linux-user/uaccess.c | 46 +++++++++++++++++++++++++++++++++++++++++++ |
14 | 2 files changed, 95 insertions(+) | 16 | 2 files changed, 53 insertions(+), 40 deletions(-) |
15 | create mode 100644 tests/qtest/pvpanic-pci-test.c | ||
16 | 17 | ||
17 | diff --git a/tests/qtest/pvpanic-pci-test.c b/tests/qtest/pvpanic-pci-test.c | 18 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
18 | new file mode 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
19 | index XXXXXXX..XXXXXXX | 20 | --- a/linux-user/qemu.h |
20 | --- /dev/null | 21 | +++ b/linux-user/qemu.h |
21 | +++ b/tests/qtest/pvpanic-pci-test.c | 22 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
23 | |||
24 | /* Lock an area of guest memory into the host. If copy is true then the | ||
25 | host area will have the same contents as the guest. */ | ||
26 | -static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
27 | -{ | ||
28 | - if (!access_ok_untagged(type, guest_addr, len)) { | ||
29 | - return NULL; | ||
30 | - } | ||
31 | -#ifdef DEBUG_REMAP | ||
32 | - { | ||
33 | - void *addr; | ||
34 | - addr = g_malloc(len); | ||
35 | - if (copy) | ||
36 | - memcpy(addr, g2h(guest_addr), len); | ||
37 | - else | ||
38 | - memset(addr, 0, len); | ||
39 | - return addr; | ||
40 | - } | ||
41 | -#else | ||
42 | - return g2h_untagged(guest_addr); | ||
43 | -#endif | ||
44 | -} | ||
45 | +void *lock_user(int type, abi_ulong guest_addr, long len, int copy); | ||
46 | |||
47 | /* Unlock an area of guest memory. The first LEN bytes must be | ||
48 | flushed back to guest memory. host_ptr = NULL is explicitly | ||
49 | allowed and does nothing. */ | ||
50 | -static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, | ||
51 | - long len) | ||
52 | -{ | ||
53 | - | ||
54 | -#ifdef DEBUG_REMAP | ||
55 | - if (!host_ptr) | ||
56 | - return; | ||
57 | - if (host_ptr == g2h_untagged(guest_addr)) | ||
58 | - return; | ||
59 | - if (len > 0) | ||
60 | - memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
61 | - g_free(host_ptr); | ||
62 | +#ifndef DEBUG_REMAP | ||
63 | +static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len) | ||
64 | +{ } | ||
65 | +#else | ||
66 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
67 | #endif | ||
68 | -} | ||
69 | |||
70 | /* Return the length of a string in target memory or -TARGET_EFAULT if | ||
71 | access error. */ | ||
72 | abi_long target_strlen(abi_ulong gaddr); | ||
73 | |||
74 | /* Like lock_user but for null terminated strings. */ | ||
75 | -static inline void *lock_user_string(abi_ulong guest_addr) | ||
76 | -{ | ||
77 | - abi_long len; | ||
78 | - len = target_strlen(guest_addr); | ||
79 | - if (len < 0) | ||
80 | - return NULL; | ||
81 | - return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); | ||
82 | -} | ||
83 | +void *lock_user_string(abi_ulong guest_addr); | ||
84 | |||
85 | /* Helper macros for locking/unlocking a target struct. */ | ||
86 | #define lock_user_struct(type, host_ptr, guest_addr, copy) \ | ||
87 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/linux-user/uaccess.c | ||
90 | +++ b/linux-user/uaccess.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | 91 | @@ -XXX,XX +XXX,XX @@ |
23 | +/* | 92 | |
24 | + * QTest testcase for PV Panic PCI device | 93 | #include "qemu.h" |
25 | + * | 94 | |
26 | + * Copyright (C) 2020 Oracle | 95 | +void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
27 | + * | ||
28 | + * Authors: | ||
29 | + * Mihai Carabas <mihai.carabas@oracle.com> | ||
30 | + * | ||
31 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
32 | + * See the COPYING file in the top-level directory. | ||
33 | + * | ||
34 | + */ | ||
35 | + | ||
36 | +#include "qemu/osdep.h" | ||
37 | +#include "libqos/libqtest.h" | ||
38 | +#include "qapi/qmp/qdict.h" | ||
39 | +#include "libqos/pci.h" | ||
40 | +#include "libqos/pci-pc.h" | ||
41 | +#include "hw/pci/pci_regs.h" | ||
42 | + | ||
43 | +static void test_panic_nopause(void) | ||
44 | +{ | 96 | +{ |
45 | + uint8_t val; | 97 | + if (!access_ok_untagged(type, guest_addr, len)) { |
46 | + QDict *response, *data; | 98 | + return NULL; |
47 | + QTestState *qts; | 99 | + } |
48 | + QPCIBus *pcibus; | 100 | +#ifdef DEBUG_REMAP |
49 | + QPCIDevice *dev; | 101 | + { |
50 | + QPCIBar bar; | 102 | + void *addr; |
51 | + | 103 | + addr = g_malloc(len); |
52 | + qts = qtest_init("-device pvpanic-pci,addr=04.0 -action panic=none"); | 104 | + if (copy) { |
53 | + pcibus = qpci_new_pc(qts, NULL); | 105 | + memcpy(addr, g2h(guest_addr), len); |
54 | + dev = qpci_device_find(pcibus, QPCI_DEVFN(0x4, 0x0)); | 106 | + } else { |
55 | + qpci_device_enable(dev); | 107 | + memset(addr, 0, len); |
56 | + bar = qpci_iomap(dev, 0, NULL); | 108 | + } |
57 | + | 109 | + return addr; |
58 | + qpci_memread(dev, bar, 0, &val, sizeof(val)); | 110 | + } |
59 | + g_assert_cmpuint(val, ==, 3); | 111 | +#else |
60 | + | 112 | + return g2h_untagged(guest_addr); |
61 | + val = 1; | 113 | +#endif |
62 | + qpci_memwrite(dev, bar, 0, &val, sizeof(val)); | ||
63 | + | ||
64 | + response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); | ||
65 | + g_assert(qdict_haskey(response, "data")); | ||
66 | + data = qdict_get_qdict(response, "data"); | ||
67 | + g_assert(qdict_haskey(data, "action")); | ||
68 | + g_assert_cmpstr(qdict_get_str(data, "action"), ==, "run"); | ||
69 | + qobject_unref(response); | ||
70 | + | ||
71 | + qtest_quit(qts); | ||
72 | +} | 114 | +} |
73 | + | 115 | + |
74 | +static void test_panic(void) | 116 | +#ifdef DEBUG_REMAP |
117 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
75 | +{ | 118 | +{ |
76 | + uint8_t val; | 119 | + if (!host_ptr) { |
77 | + QDict *response, *data; | 120 | + return; |
78 | + QTestState *qts; | 121 | + } |
79 | + QPCIBus *pcibus; | 122 | + if (host_ptr == g2h_untagged(guest_addr)) { |
80 | + QPCIDevice *dev; | 123 | + return; |
81 | + QPCIBar bar; | 124 | + } |
125 | + if (len > 0) { | ||
126 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
127 | + } | ||
128 | + g_free(host_ptr); | ||
129 | +} | ||
130 | +#endif | ||
82 | + | 131 | + |
83 | + qts = qtest_init("-device pvpanic-pci,addr=04.0 -action panic=pause"); | 132 | +void *lock_user_string(abi_ulong guest_addr) |
84 | + pcibus = qpci_new_pc(qts, NULL); | 133 | +{ |
85 | + dev = qpci_device_find(pcibus, QPCI_DEVFN(0x4, 0x0)); | 134 | + abi_long len = target_strlen(guest_addr); |
86 | + qpci_device_enable(dev); | 135 | + if (len < 0) { |
87 | + bar = qpci_iomap(dev, 0, NULL); | 136 | + return NULL; |
88 | + | 137 | + } |
89 | + qpci_memread(dev, bar, 0, &val, sizeof(val)); | 138 | + return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
90 | + g_assert_cmpuint(val, ==, 3); | ||
91 | + | ||
92 | + val = 1; | ||
93 | + qpci_memwrite(dev, bar, 0, &val, sizeof(val)); | ||
94 | + | ||
95 | + response = qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); | ||
96 | + g_assert(qdict_haskey(response, "data")); | ||
97 | + data = qdict_get_qdict(response, "data"); | ||
98 | + g_assert(qdict_haskey(data, "action")); | ||
99 | + g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause"); | ||
100 | + qobject_unref(response); | ||
101 | + | ||
102 | + qtest_quit(qts); | ||
103 | +} | 139 | +} |
104 | + | 140 | + |
105 | +int main(int argc, char **argv) | 141 | /* copy_from_user() and copy_to_user() are usually used to copy data |
106 | +{ | 142 | * buffers between the target and host. These internally perform |
107 | + int ret; | 143 | * locking/unlocking of the memory. |
108 | + | ||
109 | + g_test_init(&argc, &argv, NULL); | ||
110 | + qtest_add_func("/pvpanic-pci/panic", test_panic); | ||
111 | + qtest_add_func("/pvpanic-pci/panic-nopause", test_panic_nopause); | ||
112 | + | ||
113 | + ret = g_test_run(); | ||
114 | + | ||
115 | + return ret; | ||
116 | +} | ||
117 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/tests/qtest/meson.build | ||
120 | +++ b/tests/qtest/meson.build | ||
121 | @@ -XXX,XX +XXX,XX @@ qtests_i386 = \ | ||
122 | config_all_devices.has_key('CONFIG_ISA_IPMI_BT') ? ['ipmi-bt-test'] : []) + \ | ||
123 | (config_all_devices.has_key('CONFIG_WDT_IB700') ? ['wdt_ib700-test'] : []) + \ | ||
124 | (config_all_devices.has_key('CONFIG_PVPANIC_ISA') ? ['pvpanic-test'] : []) + \ | ||
125 | + (config_all_devices.has_key('CONFIG_PVPANIC_PCI') ? ['pvpanic-pci-test'] : []) + \ | ||
126 | (config_all_devices.has_key('CONFIG_HDA') ? ['intel-hda-test'] : []) + \ | ||
127 | (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ | ||
128 | (config_all_devices.has_key('CONFIG_IOH3420') ? ['ioh3420-test'] : []) + \ | ||
129 | -- | 144 | -- |
130 | 2.20.1 | 145 | 2.20.1 |
131 | 146 | ||
132 | 147 | diff view generated by jsdifflib |
1 | Switch the CMSDK APB watchdog device over to using its Clock input; | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | the wdogclk_frq property is now ignored. | ||
3 | 2 | ||
3 | For copy_*_user, only 0 and -TARGET_EFAULT are returned; no need | ||
4 | to involve abi_long. Use size_t for lengths. Use bool for the | ||
5 | lock_user copy argument. Use ssize_t for target_strlen, because | ||
6 | we can't overflow the host memory space. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20210212184902.1251044-19-richard.henderson@linaro.org | ||
12 | [PMM: moved fix for ifdef error to previous commit] | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-21-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-21-peter.maydell@linaro.org | ||
10 | --- | 14 | --- |
11 | hw/watchdog/cmsdk-apb-watchdog.c | 18 ++++++++++++++---- | 15 | linux-user/qemu.h | 12 +++++------- |
12 | 1 file changed, 14 insertions(+), 4 deletions(-) | 16 | linux-user/uaccess.c | 45 ++++++++++++++++++++++---------------------- |
17 | 2 files changed, 28 insertions(+), 29 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/hw/watchdog/cmsdk-apb-watchdog.c b/hw/watchdog/cmsdk-apb-watchdog.c | 19 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/watchdog/cmsdk-apb-watchdog.c | 21 | --- a/linux-user/qemu.h |
17 | +++ b/hw/watchdog/cmsdk-apb-watchdog.c | 22 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev) | 23 | @@ -XXX,XX +XXX,XX @@ |
19 | ptimer_transaction_commit(s->timer); | 24 | #include "exec/cpu_ldst.h" |
25 | |||
26 | #undef DEBUG_REMAP | ||
27 | -#ifdef DEBUG_REMAP | ||
28 | -#endif /* DEBUG_REMAP */ | ||
29 | |||
30 | #include "exec/user/abitypes.h" | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(CPUState *cpu, int type, | ||
33 | * buffers between the target and host. These internally perform | ||
34 | * locking/unlocking of the memory. | ||
35 | */ | ||
36 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len); | ||
37 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | ||
38 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len); | ||
39 | +int copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | ||
40 | |||
41 | /* Functions for accessing guest memory. The tget and tput functions | ||
42 | read/write single values, byteswapping as necessary. The lock_user function | ||
43 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | ||
44 | |||
45 | /* Lock an area of guest memory into the host. If copy is true then the | ||
46 | host area will have the same contents as the guest. */ | ||
47 | -void *lock_user(int type, abi_ulong guest_addr, long len, int copy); | ||
48 | +void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy); | ||
49 | |||
50 | /* Unlock an area of guest memory. The first LEN bytes must be | ||
51 | flushed back to guest memory. host_ptr = NULL is explicitly | ||
52 | allowed and does nothing. */ | ||
53 | #ifndef DEBUG_REMAP | ||
54 | -static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len) | ||
55 | +static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len) | ||
56 | { } | ||
57 | #else | ||
58 | void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
59 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
60 | |||
61 | /* Return the length of a string in target memory or -TARGET_EFAULT if | ||
62 | access error. */ | ||
63 | -abi_long target_strlen(abi_ulong gaddr); | ||
64 | +ssize_t target_strlen(abi_ulong gaddr); | ||
65 | |||
66 | /* Like lock_user but for null terminated strings. */ | ||
67 | void *lock_user_string(abi_ulong guest_addr); | ||
68 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/linux-user/uaccess.c | ||
71 | +++ b/linux-user/uaccess.c | ||
72 | @@ -XXX,XX +XXX,XX @@ | ||
73 | |||
74 | #include "qemu.h" | ||
75 | |||
76 | -void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
77 | +void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) | ||
78 | { | ||
79 | if (!access_ok_untagged(type, guest_addr, len)) { | ||
80 | return NULL; | ||
81 | @@ -XXX,XX +XXX,XX @@ void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
20 | } | 82 | } |
21 | 83 | ||
22 | +static void cmsdk_apb_watchdog_clk_update(void *opaque) | 84 | #ifdef DEBUG_REMAP |
23 | +{ | 85 | -void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
24 | + CMSDKAPBWatchdog *s = CMSDK_APB_WATCHDOG(opaque); | 86 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); |
25 | + | ||
26 | + ptimer_transaction_begin(s->timer); | ||
27 | + ptimer_set_period_from_clock(s->timer, s->wdogclk, 1); | ||
28 | + ptimer_transaction_commit(s->timer); | ||
29 | +} | ||
30 | + | ||
31 | static void cmsdk_apb_watchdog_init(Object *obj) | ||
32 | { | 87 | { |
33 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 88 | if (!host_ptr) { |
34 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_init(Object *obj) | 89 | return; |
35 | s, "cmsdk-apb-watchdog", 0x1000); | 90 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
36 | sysbus_init_mmio(sbd, &s->iomem); | 91 | if (host_ptr == g2h_untagged(guest_addr)) { |
37 | sysbus_init_irq(sbd, &s->wdogint); | ||
38 | - s->wdogclk = qdev_init_clock_in(DEVICE(s), "WDOGCLK", NULL, NULL); | ||
39 | + s->wdogclk = qdev_init_clock_in(DEVICE(s), "WDOGCLK", | ||
40 | + cmsdk_apb_watchdog_clk_update, s); | ||
41 | |||
42 | s->is_luminary = false; | ||
43 | s->id = cmsdk_apb_watchdog_id; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) | ||
45 | { | ||
46 | CMSDKAPBWatchdog *s = CMSDK_APB_WATCHDOG(dev); | ||
47 | |||
48 | - if (s->wdogclk_frq == 0) { | ||
49 | + if (!clock_has_source(s->wdogclk)) { | ||
50 | error_setg(errp, | ||
51 | - "CMSDK APB watchdog: wdogclk-frq property must be set"); | ||
52 | + "CMSDK APB watchdog: WDOGCLK clock must be connected"); | ||
53 | return; | 92 | return; |
54 | } | 93 | } |
55 | 94 | - if (len > 0) { | |
56 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) | 95 | + if (len != 0) { |
57 | PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); | 96 | memcpy(g2h_untagged(guest_addr), host_ptr, len); |
58 | 97 | } | |
59 | ptimer_transaction_begin(s->timer); | 98 | g_free(host_ptr); |
60 | - ptimer_set_freq(s->timer, s->wdogclk_frq); | 99 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
61 | + ptimer_set_period_from_clock(s->timer, s->wdogclk, 1); | 100 | |
62 | ptimer_transaction_commit(s->timer); | 101 | void *lock_user_string(abi_ulong guest_addr) |
102 | { | ||
103 | - abi_long len = target_strlen(guest_addr); | ||
104 | + ssize_t len = target_strlen(guest_addr); | ||
105 | if (len < 0) { | ||
106 | return NULL; | ||
107 | } | ||
108 | - return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); | ||
109 | + return lock_user(VERIFY_READ, guest_addr, (size_t)len + 1, 1); | ||
63 | } | 110 | } |
64 | 111 | ||
112 | /* copy_from_user() and copy_to_user() are usually used to copy data | ||
113 | * buffers between the target and host. These internally perform | ||
114 | * locking/unlocking of the memory. | ||
115 | */ | ||
116 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len) | ||
117 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len) | ||
118 | { | ||
119 | - abi_long ret = 0; | ||
120 | - void *ghptr; | ||
121 | + int ret = 0; | ||
122 | + void *ghptr = lock_user(VERIFY_READ, gaddr, len, 1); | ||
123 | |||
124 | - if ((ghptr = lock_user(VERIFY_READ, gaddr, len, 1))) { | ||
125 | + if (ghptr) { | ||
126 | memcpy(hptr, ghptr, len); | ||
127 | unlock_user(ghptr, gaddr, 0); | ||
128 | - } else | ||
129 | + } else { | ||
130 | ret = -TARGET_EFAULT; | ||
131 | - | ||
132 | + } | ||
133 | return ret; | ||
134 | } | ||
135 | |||
136 | - | ||
137 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len) | ||
138 | +int copy_to_user(abi_ulong gaddr, void *hptr, size_t len) | ||
139 | { | ||
140 | - abi_long ret = 0; | ||
141 | - void *ghptr; | ||
142 | + int ret = 0; | ||
143 | + void *ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0); | ||
144 | |||
145 | - if ((ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0))) { | ||
146 | + if (ghptr) { | ||
147 | memcpy(ghptr, hptr, len); | ||
148 | unlock_user(ghptr, gaddr, len); | ||
149 | - } else | ||
150 | + } else { | ||
151 | ret = -TARGET_EFAULT; | ||
152 | + } | ||
153 | |||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | /* Return the length of a string in target memory or -TARGET_EFAULT if | ||
158 | access error */ | ||
159 | -abi_long target_strlen(abi_ulong guest_addr1) | ||
160 | +ssize_t target_strlen(abi_ulong guest_addr1) | ||
161 | { | ||
162 | uint8_t *ptr; | ||
163 | abi_ulong guest_addr; | ||
164 | - int max_len, len; | ||
165 | + size_t max_len, len; | ||
166 | |||
167 | guest_addr = guest_addr1; | ||
168 | for(;;) { | ||
169 | @@ -XXX,XX +XXX,XX @@ abi_long target_strlen(abi_ulong guest_addr1) | ||
170 | unlock_user(ptr, guest_addr, 0); | ||
171 | guest_addr += len; | ||
172 | /* we don't allow wrapping or integer overflow */ | ||
173 | - if (guest_addr == 0 || | ||
174 | - (guest_addr - guest_addr1) > 0x7fffffff) | ||
175 | + if (guest_addr == 0 || (guest_addr - guest_addr1) > 0x7fffffff) { | ||
176 | return -TARGET_EFAULT; | ||
177 | - if (len != max_len) | ||
178 | + } | ||
179 | + if (len != max_len) { | ||
180 | break; | ||
181 | + } | ||
182 | } | ||
183 | return guest_addr - guest_addr1; | ||
184 | } | ||
65 | -- | 185 | -- |
66 | 2.20.1 | 186 | 2.20.1 |
67 | 187 | ||
68 | 188 | diff view generated by jsdifflib |
1 | Create two input clocks on the ARMSSE devices, one for the normal | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | MAINCLK, and one for the 32KHz S32KCLK, and wire these up to the | ||
3 | appropriate devices. The old property-based clock frequency setting | ||
4 | will remain in place until conversion is complete. | ||
5 | 2 | ||
6 | This is a migration compatibility break for machines mps2-an505, | 3 | Resolve the untagged address once, using thread_cpu. |
7 | mps2-an521, musca-a, musca-b1. | 4 | Tidy the DEBUG_REMAP code using glib routines. |
8 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-20-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
12 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-id: 20210128114145.20536-12-peter.maydell@linaro.org | ||
14 | Message-id: 20210121190622.22000-12-peter.maydell@linaro.org | ||
15 | --- | 10 | --- |
16 | include/hw/arm/armsse.h | 6 ++++++ | 11 | linux-user/uaccess.c | 27 ++++++++++++++------------- |
17 | hw/arm/armsse.c | 17 +++++++++++++++-- | 12 | 1 file changed, 14 insertions(+), 13 deletions(-) |
18 | 2 files changed, 21 insertions(+), 2 deletions(-) | ||
19 | 13 | ||
20 | diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h | 14 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c |
21 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/include/hw/arm/armsse.h | 16 | --- a/linux-user/uaccess.c |
23 | +++ b/include/hw/arm/armsse.h | 17 | +++ b/linux-user/uaccess.c |
24 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ |
25 | * per-CPU identity and control register blocks | 19 | |
26 | * | 20 | void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) |
27 | * QEMU interface: | 21 | { |
28 | + * + Clock input "MAINCLK": clock for CPUs and most peripherals | 22 | + void *host_addr; |
29 | + * + Clock input "S32KCLK": slow 32KHz clock used for a few peripherals | ||
30 | * + QOM property "memory" is a MemoryRegion containing the devices provided | ||
31 | * by the board model. | ||
32 | * + QOM property "MAINCLK_FRQ" is the frequency of the main system clock | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | #include "hw/misc/armsse-mhu.h" | ||
35 | #include "hw/misc/unimp.h" | ||
36 | #include "hw/or-irq.h" | ||
37 | +#include "hw/clock.h" | ||
38 | #include "hw/core/split-irq.h" | ||
39 | #include "hw/cpu/cluster.h" | ||
40 | #include "qom/object.h" | ||
41 | @@ -XXX,XX +XXX,XX @@ struct ARMSSE { | ||
42 | |||
43 | uint32_t nsccfg; | ||
44 | |||
45 | + Clock *mainclk; | ||
46 | + Clock *s32kclk; | ||
47 | + | 23 | + |
48 | /* Properties */ | 24 | + guest_addr = cpu_untagged_addr(thread_cpu, guest_addr); |
49 | MemoryRegion *board_memory; | 25 | if (!access_ok_untagged(type, guest_addr, len)) { |
50 | uint32_t exp_numirq; | 26 | return NULL; |
51 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | 27 | } |
52 | index XXXXXXX..XXXXXXX 100644 | 28 | + host_addr = g2h_untagged(guest_addr); |
53 | --- a/hw/arm/armsse.c | 29 | #ifdef DEBUG_REMAP |
54 | +++ b/hw/arm/armsse.c | 30 | - { |
55 | @@ -XXX,XX +XXX,XX @@ | 31 | - void *addr; |
56 | #include "hw/arm/armsse.h" | 32 | - addr = g_malloc(len); |
57 | #include "hw/arm/boot.h" | 33 | - if (copy) { |
58 | #include "hw/irq.h" | 34 | - memcpy(addr, g2h(guest_addr), len); |
59 | +#include "hw/qdev-clock.h" | 35 | - } else { |
60 | 36 | - memset(addr, 0, len); | |
61 | /* Format of the System Information block SYS_CONFIG register */ | 37 | - } |
62 | typedef enum SysConfigFormat { | 38 | - return addr; |
63 | @@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj) | 39 | + if (copy) { |
64 | assert(info->sram_banks <= MAX_SRAM_BANKS); | 40 | + host_addr = g_memdup(host_addr, len); |
65 | assert(info->num_cpus <= SSE_MAX_CPUS); | 41 | + } else { |
66 | 42 | + host_addr = g_malloc0(len); | |
67 | + s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", NULL, NULL); | 43 | } |
68 | + s->s32kclk = qdev_init_clock_in(DEVICE(s), "S32KCLK", NULL, NULL); | 44 | -#else |
45 | - return g2h_untagged(guest_addr); | ||
46 | #endif | ||
47 | + return host_addr; | ||
48 | } | ||
49 | |||
50 | #ifdef DEBUG_REMAP | ||
51 | void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); | ||
52 | { | ||
53 | + void *host_ptr_conv; | ||
69 | + | 54 | + |
70 | memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX); | 55 | if (!host_ptr) { |
71 | |||
72 | for (i = 0; i < info->num_cpus; i++) { | ||
73 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
74 | * map its upstream ends to the right place in the container. | ||
75 | */ | ||
76 | qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq); | ||
77 | + qdev_connect_clock_in(DEVICE(&s->timer0), "pclk", s->mainclk); | ||
78 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer0), errp)) { | ||
79 | return; | 56 | return; |
80 | } | 57 | } |
81 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | 58 | - if (host_ptr == g2h_untagged(guest_addr)) { |
82 | &error_abort); | 59 | + host_ptr_conv = g2h(thread_cpu, guest_addr); |
83 | 60 | + if (host_ptr == host_ptr_conv) { | |
84 | qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq); | ||
85 | + qdev_connect_clock_in(DEVICE(&s->timer1), "pclk", s->mainclk); | ||
86 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer1), errp)) { | ||
87 | return; | 61 | return; |
88 | } | 62 | } |
89 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | 63 | if (len != 0) { |
90 | &error_abort); | 64 | - memcpy(g2h_untagged(guest_addr), host_ptr, len); |
91 | 65 | + memcpy(host_ptr_conv, host_ptr, len); | |
92 | qdev_prop_set_uint32(DEVICE(&s->dualtimer), "pclk-frq", s->mainclk_frq); | ||
93 | + qdev_connect_clock_in(DEVICE(&s->dualtimer), "TIMCLK", s->mainclk); | ||
94 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->dualtimer), errp)) { | ||
95 | return; | ||
96 | } | 66 | } |
97 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | 67 | g_free(host_ptr); |
98 | * 0x4002f000: S32K timer | 68 | } |
99 | */ | ||
100 | qdev_prop_set_uint32(DEVICE(&s->s32ktimer), "pclk-frq", S32KCLK); | ||
101 | + qdev_connect_clock_in(DEVICE(&s->s32ktimer), "pclk", s->s32kclk); | ||
102 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->s32ktimer), errp)) { | ||
103 | return; | ||
104 | } | ||
105 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
106 | qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0)); | ||
107 | |||
108 | qdev_prop_set_uint32(DEVICE(&s->s32kwatchdog), "wdogclk-frq", S32KCLK); | ||
109 | + qdev_connect_clock_in(DEVICE(&s->s32kwatchdog), "WDOGCLK", s->s32kclk); | ||
110 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->s32kwatchdog), errp)) { | ||
111 | return; | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
114 | /* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ | ||
115 | |||
116 | qdev_prop_set_uint32(DEVICE(&s->nswatchdog), "wdogclk-frq", s->mainclk_frq); | ||
117 | + qdev_connect_clock_in(DEVICE(&s->nswatchdog), "WDOGCLK", s->mainclk); | ||
118 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->nswatchdog), errp)) { | ||
119 | return; | ||
120 | } | ||
121 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->nswatchdog), 0, 0x40081000); | ||
123 | |||
124 | qdev_prop_set_uint32(DEVICE(&s->swatchdog), "wdogclk-frq", s->mainclk_frq); | ||
125 | + qdev_connect_clock_in(DEVICE(&s->swatchdog), "WDOGCLK", s->mainclk); | ||
126 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->swatchdog), errp)) { | ||
127 | return; | ||
128 | } | ||
129 | @@ -XXX,XX +XXX,XX @@ static void armsse_idau_check(IDAUInterface *ii, uint32_t address, | ||
130 | |||
131 | static const VMStateDescription armsse_vmstate = { | ||
132 | .name = "iotkit", | ||
133 | - .version_id = 1, | ||
134 | - .minimum_version_id = 1, | ||
135 | + .version_id = 2, | ||
136 | + .minimum_version_id = 2, | ||
137 | .fields = (VMStateField[]) { | ||
138 | + VMSTATE_CLOCK(mainclk, ARMSSE), | ||
139 | + VMSTATE_CLOCK(s32kclk, ARMSSE), | ||
140 | VMSTATE_UINT32(nsccfg, ARMSSE), | ||
141 | VMSTATE_END_OF_LIST() | ||
142 | } | ||
143 | -- | 69 | -- |
144 | 2.20.1 | 70 | 2.20.1 |
145 | 71 | ||
146 | 72 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This was defined at some point before ARMv8.4, and will | 3 | This is the prctl bit that controls whether syscalls accept tagged |
4 | shortly be used by new processor descriptions. | 4 | addresses. See Documentation/arm64/tagged-address-abi.rst in the |
5 | linux kernel. | ||
5 | 6 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20210120204400.1056582-1-richard.henderson@linaro.org | 9 | Message-id: 20210212184902.1251044-21-richard.henderson@linaro.org |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 11 | --- |
11 | target/arm/cpu.h | 1 + | 12 | linux-user/aarch64/target_syscall.h | 4 ++++ |
12 | target/arm/helper.c | 4 ++-- | 13 | target/arm/cpu-param.h | 3 +++ |
13 | target/arm/kvm64.c | 2 ++ | 14 | target/arm/cpu.h | 31 +++++++++++++++++++++++++++++ |
14 | 3 files changed, 5 insertions(+), 2 deletions(-) | 15 | linux-user/syscall.c | 24 ++++++++++++++++++++++ |
16 | 4 files changed, 62 insertions(+) | ||
15 | 17 | ||
18 | diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/linux-user/aarch64/target_syscall.h | ||
21 | +++ b/linux-user/aarch64/target_syscall.h | ||
22 | @@ -XXX,XX +XXX,XX @@ struct target_pt_regs { | ||
23 | # define TARGET_PR_PAC_APDBKEY (1 << 3) | ||
24 | # define TARGET_PR_PAC_APGAKEY (1 << 4) | ||
25 | |||
26 | +#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 | ||
27 | +#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 | ||
28 | +# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) | ||
29 | + | ||
30 | #endif /* AARCH64_TARGET_SYSCALL_H */ | ||
31 | diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/arm/cpu-param.h | ||
34 | +++ b/target/arm/cpu-param.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | |||
37 | #ifdef CONFIG_USER_ONLY | ||
38 | #define TARGET_PAGE_BITS 12 | ||
39 | +# ifdef TARGET_AARCH64 | ||
40 | +# define TARGET_TAGGED_ADDRESSES | ||
41 | +# endif | ||
42 | #else | ||
43 | /* | ||
44 | * ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 45 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
17 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 47 | --- a/target/arm/cpu.h |
19 | +++ b/target/arm/cpu.h | 48 | +++ b/target/arm/cpu.h |
20 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 49 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { |
21 | uint32_t id_mmfr4; | 50 | const struct arm_boot_info *boot_info; |
22 | uint32_t id_pfr0; | 51 | /* Store GICv3CPUState to access from this struct */ |
23 | uint32_t id_pfr1; | 52 | void *gicv3state; |
24 | + uint32_t id_pfr2; | 53 | + |
25 | uint32_t mvfr0; | 54 | +#ifdef TARGET_TAGGED_ADDRESSES |
26 | uint32_t mvfr1; | 55 | + /* Linux syscall tagged address support */ |
27 | uint32_t mvfr2; | 56 | + bool tagged_addr_enable; |
28 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 57 | +#endif |
58 | } CPUARMState; | ||
59 | |||
60 | static inline void set_feature(CPUARMState *env, int feature) | ||
61 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) | ||
62 | */ | ||
63 | #define PAGE_BTI PAGE_TARGET_1 | ||
64 | |||
65 | +#ifdef TARGET_TAGGED_ADDRESSES | ||
66 | +/** | ||
67 | + * cpu_untagged_addr: | ||
68 | + * @cs: CPU context | ||
69 | + * @x: tagged address | ||
70 | + * | ||
71 | + * Remove any address tag from @x. This is explicitly related to the | ||
72 | + * linux syscall TIF_TAGGED_ADDR setting, not TBI in general. | ||
73 | + * | ||
74 | + * There should be a better place to put this, but we need this in | ||
75 | + * include/exec/cpu_ldst.h, and not some place linux-user specific. | ||
76 | + */ | ||
77 | +static inline target_ulong cpu_untagged_addr(CPUState *cs, target_ulong x) | ||
78 | +{ | ||
79 | + ARMCPU *cpu = ARM_CPU(cs); | ||
80 | + if (cpu->env.tagged_addr_enable) { | ||
81 | + /* | ||
82 | + * TBI is enabled for userspace but not kernelspace addresses. | ||
83 | + * Only clear the tag if bit 55 is clear. | ||
84 | + */ | ||
85 | + x &= sextract64(x, 0, 56); | ||
86 | + } | ||
87 | + return x; | ||
88 | +} | ||
89 | +#endif | ||
90 | + | ||
91 | /* | ||
92 | * Naming convention for isar_feature functions: | ||
93 | * Functions which test 32-bit ID registers should have _aa32_ in | ||
94 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 95 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/helper.c | 96 | --- a/linux-user/syscall.c |
31 | +++ b/target/arm/helper.c | 97 | +++ b/linux-user/syscall.c |
32 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | 98 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
33 | .access = PL1_R, .type = ARM_CP_CONST, | 99 | } |
34 | .accessfn = access_aa64_tid3, | 100 | } |
35 | .resetvalue = 0 }, | 101 | return -TARGET_EINVAL; |
36 | - { .name = "MVFR4_EL1_RESERVED", .state = ARM_CP_STATE_AA64, | 102 | + case TARGET_PR_SET_TAGGED_ADDR_CTRL: |
37 | + { .name = "ID_PFR2", .state = ARM_CP_STATE_BOTH, | 103 | + { |
38 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 4, | 104 | + abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; |
39 | .access = PL1_R, .type = ARM_CP_CONST, | 105 | + CPUARMState *env = cpu_env; |
40 | .accessfn = access_aa64_tid3, | 106 | + |
41 | - .resetvalue = 0 }, | 107 | + if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { |
42 | + .resetvalue = cpu->isar.id_pfr2 }, | 108 | + return -TARGET_EINVAL; |
43 | { .name = "MVFR5_EL1_RESERVED", .state = ARM_CP_STATE_AA64, | 109 | + } |
44 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 5, | 110 | + env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE; |
45 | .access = PL1_R, .type = ARM_CP_CONST, | 111 | + return 0; |
46 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | 112 | + } |
47 | index XXXXXXX..XXXXXXX 100644 | 113 | + case TARGET_PR_GET_TAGGED_ADDR_CTRL: |
48 | --- a/target/arm/kvm64.c | 114 | + { |
49 | +++ b/target/arm/kvm64.c | 115 | + abi_long ret = 0; |
50 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) | 116 | + CPUARMState *env = cpu_env; |
51 | ARM64_SYS_REG(3, 0, 0, 1, 0)); | 117 | + |
52 | err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_pfr1, | 118 | + if (arg2 || arg3 || arg4 || arg5) { |
53 | ARM64_SYS_REG(3, 0, 0, 1, 1)); | 119 | + return -TARGET_EINVAL; |
54 | + err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_pfr2, | 120 | + } |
55 | + ARM64_SYS_REG(3, 0, 0, 3, 4)); | 121 | + if (env->tagged_addr_enable) { |
56 | err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_dfr0, | 122 | + ret |= TARGET_PR_TAGGED_ADDR_ENABLE; |
57 | ARM64_SYS_REG(3, 0, 0, 1, 2)); | 123 | + } |
58 | err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr0, | 124 | + return ret; |
125 | + } | ||
126 | #endif /* AARCH64 */ | ||
127 | case PR_GET_SECCOMP: | ||
128 | case PR_SET_SECCOMP: | ||
59 | -- | 129 | -- |
60 | 2.20.1 | 130 | 2.20.1 |
61 | 131 | ||
62 | 132 | diff view generated by jsdifflib |
1 | Create and connect the Clock input for the watchdog device on the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | Stellaris boards. Because the Stellaris boards model the ability to | ||
3 | change the clock rate by programming PLL registers, we have to create | ||
4 | an output Clock on the ssys_state device and wire it up to the | ||
5 | watchdog. | ||
6 | 2 | ||
7 | Note that the old comment on ssys_calculate_system_clock() got the | 3 | Use simple arithmetic instead of a conditional |
8 | units wrong -- system_clock_scale is in nanoseconds, not | 4 | move when tbi0 != tbi1. |
9 | milliseconds. Improve the commentary to clarify how we are | ||
10 | calculating the period. | ||
11 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-22-richard.henderson@linaro.org | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
16 | Message-id: 20210128114145.20536-18-peter.maydell@linaro.org | ||
17 | Message-id: 20210121190622.22000-18-peter.maydell@linaro.org | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | --- | 10 | --- |
20 | hw/arm/stellaris.c | 43 +++++++++++++++++++++++++++++++------------ | 11 | target/arm/translate-a64.c | 25 ++++++++++++++----------- |
21 | 1 file changed, 31 insertions(+), 12 deletions(-) | 12 | 1 file changed, 14 insertions(+), 11 deletions(-) |
22 | 13 | ||
23 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | 14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
24 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/hw/arm/stellaris.c | 16 | --- a/target/arm/translate-a64.c |
26 | +++ b/hw/arm/stellaris.c | 17 | +++ b/target/arm/translate-a64.c |
27 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst, |
28 | #include "hw/watchdog/cmsdk-apb-watchdog.h" | 19 | /* Sign-extend from bit 55. */ |
29 | #include "migration/vmstate.h" | 20 | tcg_gen_sextract_i64(dst, src, 0, 56); |
30 | #include "hw/misc/unimp.h" | 21 | |
31 | +#include "hw/qdev-clock.h" | 22 | - if (tbi != 3) { |
32 | #include "cpu.h" | 23 | - TCGv_i64 tcg_zero = tcg_const_i64(0); |
33 | #include "qom/object.h" | 24 | - |
34 | 25 | - /* | |
35 | @@ -XXX,XX +XXX,XX @@ struct ssys_state { | 26 | - * The two TBI bits differ. |
36 | uint32_t clkvclr; | 27 | - * If tbi0, then !tbi1: only use the extension if positive. |
37 | uint32_t ldoarst; | 28 | - * if !tbi0, then tbi1: only use the extension if negative. |
38 | qemu_irq irq; | 29 | - */ |
39 | + Clock *sysclk; | 30 | - tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, |
40 | /* Properties (all read-only registers) */ | 31 | - dst, dst, tcg_zero, dst, src); |
41 | uint32_t user0; | 32 | - tcg_temp_free_i64(tcg_zero); |
42 | uint32_t user1; | 33 | + switch (tbi) { |
43 | @@ -XXX,XX +XXX,XX @@ static bool ssys_use_rcc2(ssys_state *s) | 34 | + case 1: |
44 | } | 35 | + /* tbi0 but !tbi1: only use the extension if positive */ |
45 | 36 | + tcg_gen_and_i64(dst, dst, src); | |
46 | /* | 37 | + break; |
47 | - * Caculate the sys. clock period in ms. | 38 | + case 2: |
48 | + * Calculate the system clock period. We only want to propagate | 39 | + /* !tbi0 but tbi1: only use the extension if negative */ |
49 | + * this change to the rest of the system if we're not being called | 40 | + tcg_gen_or_i64(dst, dst, src); |
50 | + * from migration post-load. | 41 | + break; |
51 | */ | 42 | + case 3: |
52 | -static void ssys_calculate_system_clock(ssys_state *s) | 43 | + /* tbi0 and tbi1: always use the extension */ |
53 | +static void ssys_calculate_system_clock(ssys_state *s, bool propagate_clock) | 44 | + break; |
54 | { | 45 | + default: |
55 | + /* | 46 | + g_assert_not_reached(); |
56 | + * SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input | ||
57 | + * clock is 200MHz, which is a period of 5 ns. Dividing the clock | ||
58 | + * frequency by X is the same as multiplying the period by X. | ||
59 | + */ | ||
60 | if (ssys_use_rcc2(s)) { | ||
61 | system_clock_scale = 5 * (((s->rcc2 >> 23) & 0x3f) + 1); | ||
62 | } else { | ||
63 | system_clock_scale = 5 * (((s->rcc >> 23) & 0xf) + 1); | ||
64 | } | ||
65 | + clock_set_ns(s->sysclk, system_clock_scale); | ||
66 | + if (propagate_clock) { | ||
67 | + clock_propagate(s->sysclk); | ||
68 | + } | ||
69 | } | ||
70 | |||
71 | static void ssys_write(void *opaque, hwaddr offset, | ||
72 | @@ -XXX,XX +XXX,XX @@ static void ssys_write(void *opaque, hwaddr offset, | ||
73 | s->int_status |= (1 << 6); | ||
74 | } | ||
75 | s->rcc = value; | ||
76 | - ssys_calculate_system_clock(s); | ||
77 | + ssys_calculate_system_clock(s, true); | ||
78 | break; | ||
79 | case 0x070: /* RCC2 */ | ||
80 | if (ssys_board_class(s) == DID0_CLASS_SANDSTORM) { | ||
81 | @@ -XXX,XX +XXX,XX @@ static void ssys_write(void *opaque, hwaddr offset, | ||
82 | s->int_status |= (1 << 6); | ||
83 | } | ||
84 | s->rcc2 = value; | ||
85 | - ssys_calculate_system_clock(s); | ||
86 | + ssys_calculate_system_clock(s, true); | ||
87 | break; | ||
88 | case 0x100: /* RCGC0 */ | ||
89 | s->rcgc[0] = value; | ||
90 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_reset_hold(Object *obj) | ||
91 | { | ||
92 | ssys_state *s = STELLARIS_SYS(obj); | ||
93 | |||
94 | - ssys_calculate_system_clock(s); | ||
95 | + /* OK to propagate clocks from the hold phase */ | ||
96 | + ssys_calculate_system_clock(s, true); | ||
97 | } | ||
98 | |||
99 | static void stellaris_sys_reset_exit(Object *obj) | ||
100 | @@ -XXX,XX +XXX,XX @@ static int stellaris_sys_post_load(void *opaque, int version_id) | ||
101 | { | ||
102 | ssys_state *s = opaque; | ||
103 | |||
104 | - ssys_calculate_system_clock(s); | ||
105 | + ssys_calculate_system_clock(s, false); | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_stellaris_sys = { | ||
110 | VMSTATE_UINT32_ARRAY(dcgc, ssys_state, 3), | ||
111 | VMSTATE_UINT32(clkvclr, ssys_state), | ||
112 | VMSTATE_UINT32(ldoarst, ssys_state), | ||
113 | + /* No field for sysclk -- handled in post-load instead */ | ||
114 | VMSTATE_END_OF_LIST() | ||
115 | } | ||
116 | }; | ||
117 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_instance_init(Object *obj) | ||
118 | memory_region_init_io(&s->iomem, obj, &ssys_ops, s, "ssys", 0x00001000); | ||
119 | sysbus_init_mmio(sbd, &s->iomem); | ||
120 | sysbus_init_irq(sbd, &s->irq); | ||
121 | + s->sysclk = qdev_init_clock_out(DEVICE(s), "SYSCLK"); | ||
122 | } | ||
123 | |||
124 | -static int stellaris_sys_init(uint32_t base, qemu_irq irq, | ||
125 | - stellaris_board_info * board, | ||
126 | - uint8_t *macaddr) | ||
127 | +static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq, | ||
128 | + stellaris_board_info *board, | ||
129 | + uint8_t *macaddr) | ||
130 | { | ||
131 | DeviceState *dev = qdev_new(TYPE_STELLARIS_SYS); | ||
132 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
133 | @@ -XXX,XX +XXX,XX @@ static int stellaris_sys_init(uint32_t base, qemu_irq irq, | ||
134 | */ | ||
135 | device_cold_reset(dev); | ||
136 | |||
137 | - return 0; | ||
138 | + return dev; | ||
139 | } | ||
140 | |||
141 | /* I2C controller. */ | ||
142 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
143 | int flash_size; | ||
144 | I2CBus *i2c; | ||
145 | DeviceState *dev; | ||
146 | + DeviceState *ssys_dev; | ||
147 | int i; | ||
148 | int j; | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
151 | } | 47 | } |
152 | } | 48 | } |
153 | 49 | } | |
154 | - stellaris_sys_init(0x400fe000, qdev_get_gpio_in(nvic, 28), | ||
155 | - board, nd_table[0].macaddr.a); | ||
156 | + ssys_dev = stellaris_sys_init(0x400fe000, qdev_get_gpio_in(nvic, 28), | ||
157 | + board, nd_table[0].macaddr.a); | ||
158 | |||
159 | |||
160 | if (board->dc1 & (1 << 3)) { /* watchdog present */ | ||
161 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
162 | /* system_clock_scale is valid now */ | ||
163 | uint32_t mainclk = NANOSECONDS_PER_SECOND / system_clock_scale; | ||
164 | qdev_prop_set_uint32(dev, "wdogclk-frq", mainclk); | ||
165 | + qdev_connect_clock_in(dev, "WDOGCLK", | ||
166 | + qdev_get_clock_out(ssys_dev, "SYSCLK")); | ||
167 | |||
168 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
169 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), | ||
170 | -- | 50 | -- |
171 | 2.20.1 | 51 | 2.20.1 |
172 | 52 | ||
173 | 53 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | On iOS there is no CoreAudio, so we should not assume Darwin always | 3 | We were fudging TBI1 enabled to speed up the generated code. |
4 | has it. | 4 | Now that we've improved the code generation, remove this. |
5 | Also, tidy the comment to reflect the current code. | ||
5 | 6 | ||
6 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 7 | The pauth test was testing a kernel address (-1) and making |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | incorrect assumptions about TBI1; stick to userland addresses. |
8 | Message-id: 20210126012457.39046-11-j@getutm.app | 9 | |
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20210212184902.1251044-23-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 14 | --- |
11 | configure | 35 +++++++++++++++++++++++++++++++++-- | 15 | target/arm/internals.h | 4 ++-- |
12 | 1 file changed, 33 insertions(+), 2 deletions(-) | 16 | target/arm/cpu.c | 10 +++------- |
17 | tests/tcg/aarch64/pauth-2.c | 1 - | ||
18 | 3 files changed, 5 insertions(+), 10 deletions(-) | ||
13 | 19 | ||
14 | diff --git a/configure b/configure | 20 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
15 | index XXXXXXX..XXXXXXX 100755 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/configure | 22 | --- a/target/arm/internals.h |
17 | +++ b/configure | 23 | +++ b/target/arm/internals.h |
18 | @@ -XXX,XX +XXX,XX @@ fdt="auto" | 24 | @@ -XXX,XX +XXX,XX @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag) |
19 | netmap="no" | 25 | */ |
20 | sdl="auto" | 26 | static inline uint64_t useronly_clean_ptr(uint64_t ptr) |
21 | sdl_image="auto" | 27 | { |
22 | +coreaudio="auto" | 28 | - /* TBI is known to be enabled. */ |
23 | virtiofsd="auto" | 29 | #ifdef CONFIG_USER_ONLY |
24 | virtfs="auto" | 30 | - ptr = sextract64(ptr, 0, 56); |
25 | libudev="auto" | 31 | + /* TBI0 is known to be enabled, while TBI1 is disabled. */ |
26 | @@ -XXX,XX +XXX,XX @@ Darwin) | 32 | + ptr &= sextract64(ptr, 0, 56); |
27 | QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS" | 33 | #endif |
28 | QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS" | 34 | return ptr; |
29 | fi | 35 | } |
30 | - audio_drv_list="coreaudio try-sdl" | 36 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
31 | + audio_drv_list="try-coreaudio try-sdl" | 37 | index XXXXXXX..XXXXXXX 100644 |
32 | audio_possible_drivers="coreaudio sdl" | 38 | --- a/target/arm/cpu.c |
33 | # Disable attempts to use ObjectiveC features in os/object.h since they | 39 | +++ b/target/arm/cpu.c |
34 | # won't work when we're compiling with gcc as a C compiler. | 40 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
35 | @@ -XXX,XX +XXX,XX @@ EOF | 41 | env->vfp.zcr_el[1] = MIN(cpu->sve_max_vq - 1, 3); |
36 | fi | 42 | } |
37 | fi | 43 | /* |
38 | 44 | - * Enable TBI0 and TBI1. While the real kernel only enables TBI0, | |
39 | +########################################## | 45 | - * turning on both here will produce smaller code and otherwise |
40 | +# detect CoreAudio | 46 | - * make no difference to the user-level emulation. |
41 | +if test "$coreaudio" != "no" ; then | 47 | - * |
42 | + coreaudio_libs="-framework CoreAudio" | 48 | - * In sve_probe_page, we assume that this is set. |
43 | + cat > $TMPC << EOF | 49 | - * Do not modify this without other changes. |
44 | +#include <CoreAudio/CoreAudio.h> | 50 | + * Enable TBI0 but not TBI1. |
45 | +int main(void) | 51 | + * Note that this must match useronly_clean_ptr. |
46 | +{ | 52 | */ |
47 | + return (int)AudioGetCurrentHostTime(); | 53 | - env->cp15.tcr_el[1].raw_tcr = (3ULL << 37); |
48 | +} | 54 | + env->cp15.tcr_el[1].raw_tcr = (1ULL << 37); |
49 | +EOF | 55 | #else |
50 | + if compile_prog "" "$coreaudio_libs" ; then | 56 | /* Reset into the highest available EL */ |
51 | + coreaudio=yes | 57 | if (arm_feature(env, ARM_FEATURE_EL3)) { |
52 | + else | 58 | diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c |
53 | + coreaudio=no | 59 | index XXXXXXX..XXXXXXX 100644 |
54 | + fi | 60 | --- a/tests/tcg/aarch64/pauth-2.c |
55 | +fi | 61 | +++ b/tests/tcg/aarch64/pauth-2.c |
56 | + | 62 | @@ -XXX,XX +XXX,XX @@ void do_test(uint64_t value) |
57 | ########################################## | 63 | int main() |
58 | # Sound support libraries probe | 64 | { |
59 | 65 | do_test(0); | |
60 | @@ -XXX,XX +XXX,XX @@ for drv in $audio_drv_list; do | 66 | - do_test(-1); |
61 | fi | 67 | do_test(0xda004acedeadbeefull); |
62 | ;; | 68 | return 0; |
63 | 69 | } | |
64 | - coreaudio) | ||
65 | + coreaudio | try-coreaudio) | ||
66 | + if test "$coreaudio" = "no"; then | ||
67 | + if test "$drv" = "try-coreaudio"; then | ||
68 | + audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio//') | ||
69 | + else | ||
70 | + error_exit "$drv check failed" \ | ||
71 | + "Make sure to have the $drv is available." | ||
72 | + fi | ||
73 | + else | ||
74 | coreaudio_libs="-framework CoreAudio" | ||
75 | + if test "$drv" = "try-coreaudio"; then | ||
76 | + audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-coreaudio/coreaudio/') | ||
77 | + fi | ||
78 | + fi | ||
79 | ;; | ||
80 | |||
81 | dsound) | ||
82 | -- | 70 | -- |
83 | 2.20.1 | 71 | 2.20.1 |
84 | 72 | ||
85 | 73 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add objc to the Meson cross file as well as detection of Darwin. | 3 | These prctl fields are required for the function of MTE. |
4 | 4 | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Message-id: 20210212184902.1251044-24-richard.henderson@linaro.org |
8 | Message-id: 20210126012457.39046-8-j@getutm.app | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 9 | --- |
11 | configure | 4 ++++ | 10 | linux-user/aarch64/target_syscall.h | 9 ++++++ |
12 | 1 file changed, 4 insertions(+) | 11 | linux-user/syscall.c | 43 +++++++++++++++++++++++++++++ |
12 | 2 files changed, 52 insertions(+) | ||
13 | 13 | ||
14 | diff --git a/configure b/configure | 14 | diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h |
15 | index XXXXXXX..XXXXXXX 100755 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/configure | 16 | --- a/linux-user/aarch64/target_syscall.h |
17 | +++ b/configure | 17 | +++ b/linux-user/aarch64/target_syscall.h |
18 | @@ -XXX,XX +XXX,XX @@ echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross | 18 | @@ -XXX,XX +XXX,XX @@ struct target_pt_regs { |
19 | echo "[binaries]" >> $cross | 19 | #define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 |
20 | echo "c = [$(meson_quote $cc)]" >> $cross | 20 | #define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 |
21 | test -n "$cxx" && echo "cpp = [$(meson_quote $cxx)]" >> $cross | 21 | # define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) |
22 | +test -n "$objcc" && echo "objc = [$(meson_quote $objcc)]" >> $cross | 22 | +/* MTE tag check fault modes */ |
23 | echo "ar = [$(meson_quote $ar)]" >> $cross | 23 | +# define TARGET_PR_MTE_TCF_SHIFT 1 |
24 | echo "nm = [$(meson_quote $nm)]" >> $cross | 24 | +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) |
25 | echo "pkgconfig = [$(meson_quote $pkg_config_exe)]" >> $cross | 25 | +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) |
26 | @@ -XXX,XX +XXX,XX @@ if test "$cross_compile" = "yes"; then | 26 | +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) |
27 | if test "$linux" = "yes" ; then | 27 | +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) |
28 | echo "system = 'linux'" >> $cross | 28 | +/* MTE tag inclusion mask */ |
29 | fi | 29 | +# define TARGET_PR_MTE_TAG_SHIFT 3 |
30 | + if test "$darwin" = "yes" ; then | 30 | +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT) |
31 | + echo "system = 'darwin'" >> $cross | 31 | |
32 | + fi | 32 | #endif /* AARCH64_TARGET_SYSCALL_H */ |
33 | case "$ARCH" in | 33 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
34 | i386|x86_64) | 34 | index XXXXXXX..XXXXXXX 100644 |
35 | echo "cpu_family = 'x86'" >> $cross | 35 | --- a/linux-user/syscall.c |
36 | +++ b/linux-user/syscall.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
38 | { | ||
39 | abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; | ||
40 | CPUARMState *env = cpu_env; | ||
41 | + ARMCPU *cpu = env_archcpu(env); | ||
42 | + | ||
43 | + if (cpu_isar_feature(aa64_mte, cpu)) { | ||
44 | + valid_mask |= TARGET_PR_MTE_TCF_MASK; | ||
45 | + valid_mask |= TARGET_PR_MTE_TAG_MASK; | ||
46 | + } | ||
47 | |||
48 | if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { | ||
49 | return -TARGET_EINVAL; | ||
50 | } | ||
51 | env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE; | ||
52 | + | ||
53 | + if (cpu_isar_feature(aa64_mte, cpu)) { | ||
54 | + switch (arg2 & TARGET_PR_MTE_TCF_MASK) { | ||
55 | + case TARGET_PR_MTE_TCF_NONE: | ||
56 | + case TARGET_PR_MTE_TCF_SYNC: | ||
57 | + case TARGET_PR_MTE_TCF_ASYNC: | ||
58 | + break; | ||
59 | + default: | ||
60 | + return -EINVAL; | ||
61 | + } | ||
62 | + | ||
63 | + /* | ||
64 | + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. | ||
65 | + * Note that the syscall values are consistent with hw. | ||
66 | + */ | ||
67 | + env->cp15.sctlr_el[1] = | ||
68 | + deposit64(env->cp15.sctlr_el[1], 38, 2, | ||
69 | + arg2 >> TARGET_PR_MTE_TCF_SHIFT); | ||
70 | + | ||
71 | + /* | ||
72 | + * Write PR_MTE_TAG to GCR_EL1[Exclude]. | ||
73 | + * Note that the syscall uses an include mask, | ||
74 | + * and hardware uses an exclude mask -- invert. | ||
75 | + */ | ||
76 | + env->cp15.gcr_el1 = | ||
77 | + deposit64(env->cp15.gcr_el1, 0, 16, | ||
78 | + ~arg2 >> TARGET_PR_MTE_TAG_SHIFT); | ||
79 | + arm_rebuild_hflags(env); | ||
80 | + } | ||
81 | return 0; | ||
82 | } | ||
83 | case TARGET_PR_GET_TAGGED_ADDR_CTRL: | ||
84 | { | ||
85 | abi_long ret = 0; | ||
86 | CPUARMState *env = cpu_env; | ||
87 | + ARMCPU *cpu = env_archcpu(env); | ||
88 | |||
89 | if (arg2 || arg3 || arg4 || arg5) { | ||
90 | return -TARGET_EINVAL; | ||
91 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
92 | if (env->tagged_addr_enable) { | ||
93 | ret |= TARGET_PR_TAGGED_ADDR_ENABLE; | ||
94 | } | ||
95 | + if (cpu_isar_feature(aa64_mte, cpu)) { | ||
96 | + /* See above. */ | ||
97 | + ret |= (extract64(env->cp15.sctlr_el[1], 38, 2) | ||
98 | + << TARGET_PR_MTE_TCF_SHIFT); | ||
99 | + ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16, | ||
100 | + ~env->cp15.gcr_el1); | ||
101 | + } | ||
102 | return ret; | ||
103 | } | ||
104 | #endif /* AARCH64 */ | ||
36 | -- | 105 | -- |
37 | 2.20.1 | 106 | 2.20.1 |
38 | 107 | ||
39 | 108 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Build without error on hosts without a working system(). If system() | 3 | Remember the PROT_MTE bit as PAGE_MTE/PAGE_TARGET_2. |
4 | is called, return -1 with ENOSYS. | 4 | Otherwise this does not yet have effect. |
5 | 5 | ||
6 | Signed-off-by: Joelle van Dyne <j@getutm.app> | ||
7 | Message-id: 20210126012457.39046-6-j@getutm.app | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-25-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 10 | --- |
11 | meson.build | 1 + | 11 | include/exec/cpu-all.h | 1 + |
12 | include/qemu/osdep.h | 12 ++++++++++++ | 12 | linux-user/syscall_defs.h | 1 + |
13 | 2 files changed, 13 insertions(+) | 13 | target/arm/cpu.h | 1 + |
14 | linux-user/mmap.c | 22 ++++++++++++++-------- | ||
15 | 4 files changed, 17 insertions(+), 8 deletions(-) | ||
14 | 16 | ||
15 | diff --git a/meson.build b/meson.build | 17 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/meson.build | 19 | --- a/include/exec/cpu-all.h |
18 | +++ b/meson.build | 20 | +++ b/include/exec/cpu-all.h |
19 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h')) | 21 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
20 | config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h')) | 22 | #endif |
21 | config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h')) | 23 | /* Target-specific bits that will be used via page_get_flags(). */ |
22 | config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h')) | 24 | #define PAGE_TARGET_1 0x0080 |
23 | +config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>')) | 25 | +#define PAGE_TARGET_2 0x0200 |
24 | 26 | ||
25 | config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>')) | 27 | #if defined(CONFIG_USER_ONLY) |
26 | 28 | void page_dump(FILE *f); | |
27 | diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h | 29 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h |
28 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/qemu/osdep.h | 31 | --- a/linux-user/syscall_defs.h |
30 | +++ b/include/qemu/osdep.h | 32 | +++ b/linux-user/syscall_defs.h |
31 | @@ -XXX,XX +XXX,XX @@ static inline void qemu_thread_jit_write(void) {} | 33 | @@ -XXX,XX +XXX,XX @@ struct target_winsize { |
32 | static inline void qemu_thread_jit_execute(void) {} | 34 | |
35 | #ifdef TARGET_AARCH64 | ||
36 | #define TARGET_PROT_BTI 0x10 | ||
37 | +#define TARGET_PROT_MTE 0x20 | ||
33 | #endif | 38 | #endif |
34 | 39 | ||
35 | +/** | 40 | /* Common */ |
36 | + * Platforms which do not support system() return ENOSYS | 41 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
37 | + */ | 42 | index XXXXXXX..XXXXXXX 100644 |
38 | +#ifndef HAVE_SYSTEM_FUNCTION | 43 | --- a/target/arm/cpu.h |
39 | +#define system platform_does_not_support_system | 44 | +++ b/target/arm/cpu.h |
40 | +static inline int platform_does_not_support_system(const char *command) | 45 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
41 | +{ | 46 | * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
42 | + errno = ENOSYS; | 47 | */ |
43 | + return -1; | 48 | #define PAGE_BTI PAGE_TARGET_1 |
44 | +} | 49 | +#define PAGE_MTE PAGE_TARGET_2 |
45 | +#endif /* !HAVE_SYSTEM_FUNCTION */ | 50 | |
51 | #ifdef TARGET_TAGGED_ADDRESSES | ||
52 | /** | ||
53 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/linux-user/mmap.c | ||
56 | +++ b/linux-user/mmap.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | ||
58 | | (prot & PROT_EXEC ? PROT_READ : 0); | ||
59 | |||
60 | #ifdef TARGET_AARCH64 | ||
61 | - /* | ||
62 | - * The PROT_BTI bit is only accepted if the cpu supports the feature. | ||
63 | - * Since this is the unusual case, don't bother checking unless | ||
64 | - * the bit has been requested. If set and valid, record the bit | ||
65 | - * within QEMU's page_flags. | ||
66 | - */ | ||
67 | - if (prot & TARGET_PROT_BTI) { | ||
68 | + { | ||
69 | ARMCPU *cpu = ARM_CPU(thread_cpu); | ||
70 | - if (cpu_isar_feature(aa64_bti, cpu)) { | ||
46 | + | 71 | + |
72 | + /* | ||
73 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. | ||
74 | + * Since this is the unusual case, don't bother checking unless | ||
75 | + * the bit has been requested. If set and valid, record the bit | ||
76 | + * within QEMU's page_flags. | ||
77 | + */ | ||
78 | + if ((prot & TARGET_PROT_BTI) && cpu_isar_feature(aa64_bti, cpu)) { | ||
79 | valid |= TARGET_PROT_BTI; | ||
80 | page_flags |= PAGE_BTI; | ||
81 | } | ||
82 | + /* Similarly for the PROT_MTE bit. */ | ||
83 | + if ((prot & TARGET_PROT_MTE) && cpu_isar_feature(aa64_mte, cpu)) { | ||
84 | + valid |= TARGET_PROT_MTE; | ||
85 | + page_flags |= PAGE_MTE; | ||
86 | + } | ||
87 | } | ||
47 | #endif | 88 | #endif |
89 | |||
48 | -- | 90 | -- |
49 | 2.20.1 | 91 | 2.20.1 |
50 | 92 | ||
51 | 93 | diff view generated by jsdifflib |
1 | From: Mihai Carabas <mihai.carabas@oracle.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add PCI interface support for PVPANIC device. Create a new file pvpanic-pci.c | 3 | Move everything related to syndromes to a new file, |
4 | where the PCI specific routines reside and update the build system with the new | 4 | which can be shared with linux-user. |
5 | files and config structure. | ||
6 | 5 | ||
7 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | ||
8 | Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 20210212184902.1251044-26-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 11 | --- |
13 | docs/specs/pci-ids.txt | 1 + | 12 | target/arm/internals.h | 245 +----------------------------------- |
14 | include/hw/misc/pvpanic.h | 1 + | 13 | target/arm/syndrome.h | 273 +++++++++++++++++++++++++++++++++++++++++ |
15 | include/hw/pci/pci.h | 1 + | 14 | 2 files changed, 274 insertions(+), 244 deletions(-) |
16 | hw/misc/pvpanic-pci.c | 94 +++++++++++++++++++++++++++++++++++++++ | 15 | create mode 100644 target/arm/syndrome.h |
17 | hw/misc/Kconfig | 6 +++ | ||
18 | hw/misc/meson.build | 1 + | ||
19 | 6 files changed, 104 insertions(+) | ||
20 | create mode 100644 hw/misc/pvpanic-pci.c | ||
21 | 16 | ||
22 | diff --git a/docs/specs/pci-ids.txt b/docs/specs/pci-ids.txt | 17 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
23 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/docs/specs/pci-ids.txt | 19 | --- a/target/arm/internals.h |
25 | +++ b/docs/specs/pci-ids.txt | 20 | +++ b/target/arm/internals.h |
26 | @@ -XXX,XX +XXX,XX @@ PCI devices (other than virtio): | ||
27 | 1b36:000d PCI xhci usb host adapter | ||
28 | 1b36:000f mdpy (mdev sample device), linux/samples/vfio-mdev/mdpy.c | ||
29 | 1b36:0010 PCIe NVMe device (-device nvme) | ||
30 | +1b36:0011 PCI PVPanic device (-device pvpanic-pci) | ||
31 | |||
32 | All these devices are documented in docs/specs. | ||
33 | |||
34 | diff --git a/include/hw/misc/pvpanic.h b/include/hw/misc/pvpanic.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/hw/misc/pvpanic.h | ||
37 | +++ b/include/hw/misc/pvpanic.h | ||
38 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ |
39 | #include "qom/object.h" | 22 | #define TARGET_ARM_INTERNALS_H |
40 | 23 | ||
41 | #define TYPE_PVPANIC_ISA_DEVICE "pvpanic" | 24 | #include "hw/registerfields.h" |
42 | +#define TYPE_PVPANIC_PCI_DEVICE "pvpanic-pci" | 25 | +#include "syndrome.h" |
43 | 26 | ||
44 | #define PVPANIC_IOPORT_PROP "ioport" | 27 | /* register banks for CPU modes */ |
45 | 28 | #define BANK_USRSYS 0 | |
46 | diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h | 29 | @@ -XXX,XX +XXX,XX @@ static inline bool extended_addresses_enabled(CPUARMState *env) |
47 | index XXXXXXX..XXXXXXX 100644 | 30 | (arm_feature(env, ARM_FEATURE_LPAE) && (tcr->raw_tcr & TTBCR_EAE)); |
48 | --- a/include/hw/pci/pci.h | 31 | } |
49 | +++ b/include/hw/pci/pci.h | 32 | |
50 | @@ -XXX,XX +XXX,XX @@ extern bool pci_available; | 33 | -/* Valid Syndrome Register EC field values */ |
51 | #define PCI_DEVICE_ID_REDHAT_PCIE_BRIDGE 0x000e | 34 | -enum arm_exception_class { |
52 | #define PCI_DEVICE_ID_REDHAT_MDPY 0x000f | 35 | - EC_UNCATEGORIZED = 0x00, |
53 | #define PCI_DEVICE_ID_REDHAT_NVME 0x0010 | 36 | - EC_WFX_TRAP = 0x01, |
54 | +#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0011 | 37 | - EC_CP15RTTRAP = 0x03, |
55 | #define PCI_DEVICE_ID_REDHAT_QXL 0x0100 | 38 | - EC_CP15RRTTRAP = 0x04, |
56 | 39 | - EC_CP14RTTRAP = 0x05, | |
57 | #define FMT_PCIBUS PRIx64 | 40 | - EC_CP14DTTRAP = 0x06, |
58 | diff --git a/hw/misc/pvpanic-pci.c b/hw/misc/pvpanic-pci.c | 41 | - EC_ADVSIMDFPACCESSTRAP = 0x07, |
42 | - EC_FPIDTRAP = 0x08, | ||
43 | - EC_PACTRAP = 0x09, | ||
44 | - EC_CP14RRTTRAP = 0x0c, | ||
45 | - EC_BTITRAP = 0x0d, | ||
46 | - EC_ILLEGALSTATE = 0x0e, | ||
47 | - EC_AA32_SVC = 0x11, | ||
48 | - EC_AA32_HVC = 0x12, | ||
49 | - EC_AA32_SMC = 0x13, | ||
50 | - EC_AA64_SVC = 0x15, | ||
51 | - EC_AA64_HVC = 0x16, | ||
52 | - EC_AA64_SMC = 0x17, | ||
53 | - EC_SYSTEMREGISTERTRAP = 0x18, | ||
54 | - EC_SVEACCESSTRAP = 0x19, | ||
55 | - EC_INSNABORT = 0x20, | ||
56 | - EC_INSNABORT_SAME_EL = 0x21, | ||
57 | - EC_PCALIGNMENT = 0x22, | ||
58 | - EC_DATAABORT = 0x24, | ||
59 | - EC_DATAABORT_SAME_EL = 0x25, | ||
60 | - EC_SPALIGNMENT = 0x26, | ||
61 | - EC_AA32_FPTRAP = 0x28, | ||
62 | - EC_AA64_FPTRAP = 0x2c, | ||
63 | - EC_SERROR = 0x2f, | ||
64 | - EC_BREAKPOINT = 0x30, | ||
65 | - EC_BREAKPOINT_SAME_EL = 0x31, | ||
66 | - EC_SOFTWARESTEP = 0x32, | ||
67 | - EC_SOFTWARESTEP_SAME_EL = 0x33, | ||
68 | - EC_WATCHPOINT = 0x34, | ||
69 | - EC_WATCHPOINT_SAME_EL = 0x35, | ||
70 | - EC_AA32_BKPT = 0x38, | ||
71 | - EC_VECTORCATCH = 0x3a, | ||
72 | - EC_AA64_BKPT = 0x3c, | ||
73 | -}; | ||
74 | - | ||
75 | -#define ARM_EL_EC_SHIFT 26 | ||
76 | -#define ARM_EL_IL_SHIFT 25 | ||
77 | -#define ARM_EL_ISV_SHIFT 24 | ||
78 | -#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) | ||
79 | -#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) | ||
80 | - | ||
81 | -static inline uint32_t syn_get_ec(uint32_t syn) | ||
82 | -{ | ||
83 | - return syn >> ARM_EL_EC_SHIFT; | ||
84 | -} | ||
85 | - | ||
86 | -/* Utility functions for constructing various kinds of syndrome value. | ||
87 | - * Note that in general we follow the AArch64 syndrome values; in a | ||
88 | - * few cases the value in HSR for exceptions taken to AArch32 Hyp | ||
89 | - * mode differs slightly, and we fix this up when populating HSR in | ||
90 | - * arm_cpu_do_interrupt_aarch32_hyp(). | ||
91 | - * The exception is FP/SIMD access traps -- these report extra information | ||
92 | - * when taking an exception to AArch32. For those we include the extra coproc | ||
93 | - * and TA fields, and mask them out when taking the exception to AArch64. | ||
94 | - */ | ||
95 | -static inline uint32_t syn_uncategorized(void) | ||
96 | -{ | ||
97 | - return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL; | ||
98 | -} | ||
99 | - | ||
100 | -static inline uint32_t syn_aa64_svc(uint32_t imm16) | ||
101 | -{ | ||
102 | - return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); | ||
103 | -} | ||
104 | - | ||
105 | -static inline uint32_t syn_aa64_hvc(uint32_t imm16) | ||
106 | -{ | ||
107 | - return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); | ||
108 | -} | ||
109 | - | ||
110 | -static inline uint32_t syn_aa64_smc(uint32_t imm16) | ||
111 | -{ | ||
112 | - return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); | ||
113 | -} | ||
114 | - | ||
115 | -static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit) | ||
116 | -{ | ||
117 | - return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) | ||
118 | - | (is_16bit ? 0 : ARM_EL_IL); | ||
119 | -} | ||
120 | - | ||
121 | -static inline uint32_t syn_aa32_hvc(uint32_t imm16) | ||
122 | -{ | ||
123 | - return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); | ||
124 | -} | ||
125 | - | ||
126 | -static inline uint32_t syn_aa32_smc(void) | ||
127 | -{ | ||
128 | - return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL; | ||
129 | -} | ||
130 | - | ||
131 | -static inline uint32_t syn_aa64_bkpt(uint32_t imm16) | ||
132 | -{ | ||
133 | - return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); | ||
134 | -} | ||
135 | - | ||
136 | -static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit) | ||
137 | -{ | ||
138 | - return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) | ||
139 | - | (is_16bit ? 0 : ARM_EL_IL); | ||
140 | -} | ||
141 | - | ||
142 | -static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2, | ||
143 | - int crn, int crm, int rt, | ||
144 | - int isread) | ||
145 | -{ | ||
146 | - return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL | ||
147 | - | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5) | ||
148 | - | (crm << 1) | isread; | ||
149 | -} | ||
150 | - | ||
151 | -static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2, | ||
152 | - int crn, int crm, int rt, int isread, | ||
153 | - bool is_16bit) | ||
154 | -{ | ||
155 | - return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT) | ||
156 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
157 | - | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) | ||
158 | - | (crn << 10) | (rt << 5) | (crm << 1) | isread; | ||
159 | -} | ||
160 | - | ||
161 | -static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2, | ||
162 | - int crn, int crm, int rt, int isread, | ||
163 | - bool is_16bit) | ||
164 | -{ | ||
165 | - return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT) | ||
166 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
167 | - | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) | ||
168 | - | (crn << 10) | (rt << 5) | (crm << 1) | isread; | ||
169 | -} | ||
170 | - | ||
171 | -static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm, | ||
172 | - int rt, int rt2, int isread, | ||
173 | - bool is_16bit) | ||
174 | -{ | ||
175 | - return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT) | ||
176 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
177 | - | (cv << 24) | (cond << 20) | (opc1 << 16) | ||
178 | - | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; | ||
179 | -} | ||
180 | - | ||
181 | -static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm, | ||
182 | - int rt, int rt2, int isread, | ||
183 | - bool is_16bit) | ||
184 | -{ | ||
185 | - return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT) | ||
186 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
187 | - | (cv << 24) | (cond << 20) | (opc1 << 16) | ||
188 | - | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; | ||
189 | -} | ||
190 | - | ||
191 | -static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit) | ||
192 | -{ | ||
193 | - /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */ | ||
194 | - return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | ||
195 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
196 | - | (cv << 24) | (cond << 20) | 0xa; | ||
197 | -} | ||
198 | - | ||
199 | -static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit) | ||
200 | -{ | ||
201 | - /* AArch32 SIMD trap: TA == 1 coproc == 0 */ | ||
202 | - return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | ||
203 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
204 | - | (cv << 24) | (cond << 20) | (1 << 5); | ||
205 | -} | ||
206 | - | ||
207 | -static inline uint32_t syn_sve_access_trap(void) | ||
208 | -{ | ||
209 | - return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; | ||
210 | -} | ||
211 | - | ||
212 | -static inline uint32_t syn_pactrap(void) | ||
213 | -{ | ||
214 | - return EC_PACTRAP << ARM_EL_EC_SHIFT; | ||
215 | -} | ||
216 | - | ||
217 | -static inline uint32_t syn_btitrap(int btype) | ||
218 | -{ | ||
219 | - return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype; | ||
220 | -} | ||
221 | - | ||
222 | -static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) | ||
223 | -{ | ||
224 | - return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
225 | - | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc; | ||
226 | -} | ||
227 | - | ||
228 | -static inline uint32_t syn_data_abort_no_iss(int same_el, int fnv, | ||
229 | - int ea, int cm, int s1ptw, | ||
230 | - int wnr, int fsc) | ||
231 | -{ | ||
232 | - return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
233 | - | ARM_EL_IL | ||
234 | - | (fnv << 10) | (ea << 9) | (cm << 8) | (s1ptw << 7) | ||
235 | - | (wnr << 6) | fsc; | ||
236 | -} | ||
237 | - | ||
238 | -static inline uint32_t syn_data_abort_with_iss(int same_el, | ||
239 | - int sas, int sse, int srt, | ||
240 | - int sf, int ar, | ||
241 | - int ea, int cm, int s1ptw, | ||
242 | - int wnr, int fsc, | ||
243 | - bool is_16bit) | ||
244 | -{ | ||
245 | - return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
246 | - | (is_16bit ? 0 : ARM_EL_IL) | ||
247 | - | ARM_EL_ISV | (sas << 22) | (sse << 21) | (srt << 16) | ||
248 | - | (sf << 15) | (ar << 14) | ||
249 | - | (ea << 9) | (cm << 8) | (s1ptw << 7) | (wnr << 6) | fsc; | ||
250 | -} | ||
251 | - | ||
252 | -static inline uint32_t syn_swstep(int same_el, int isv, int ex) | ||
253 | -{ | ||
254 | - return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
255 | - | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22; | ||
256 | -} | ||
257 | - | ||
258 | -static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr) | ||
259 | -{ | ||
260 | - return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
261 | - | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22; | ||
262 | -} | ||
263 | - | ||
264 | -static inline uint32_t syn_breakpoint(int same_el) | ||
265 | -{ | ||
266 | - return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
267 | - | ARM_EL_IL | 0x22; | ||
268 | -} | ||
269 | - | ||
270 | -static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit) | ||
271 | -{ | ||
272 | - return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) | | ||
273 | - (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) | | ||
274 | - (cv << 24) | (cond << 20) | ti; | ||
275 | -} | ||
276 | - | ||
277 | /* Update a QEMU watchpoint based on the information the guest has set in the | ||
278 | * DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers. | ||
279 | */ | ||
280 | diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h | ||
59 | new file mode 100644 | 281 | new file mode 100644 |
60 | index XXXXXXX..XXXXXXX | 282 | index XXXXXXX..XXXXXXX |
61 | --- /dev/null | 283 | --- /dev/null |
62 | +++ b/hw/misc/pvpanic-pci.c | 284 | +++ b/target/arm/syndrome.h |
63 | @@ -XXX,XX +XXX,XX @@ | 285 | @@ -XXX,XX +XXX,XX @@ |
64 | +/* | 286 | +/* |
65 | + * QEMU simulated PCI pvpanic device. | 287 | + * QEMU ARM CPU -- syndrome functions and types |
66 | + * | 288 | + * |
67 | + * Copyright (C) 2020 Oracle | 289 | + * Copyright (c) 2014 Linaro Ltd |
68 | + * | 290 | + * |
69 | + * Authors: | 291 | + * This program is free software; you can redistribute it and/or |
70 | + * Mihai Carabas <mihai.carabas@oracle.com> | 292 | + * modify it under the terms of the GNU General Public License |
293 | + * as published by the Free Software Foundation; either version 2 | ||
294 | + * of the License, or (at your option) any later version. | ||
71 | + * | 295 | + * |
72 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 296 | + * This program is distributed in the hope that it will be useful, |
73 | + * See the COPYING file in the top-level directory. | 297 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
298 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
299 | + * GNU General Public License for more details. | ||
74 | + * | 300 | + * |
301 | + * You should have received a copy of the GNU General Public License | ||
302 | + * along with this program; if not, see | ||
303 | + * <http://www.gnu.org/licenses/gpl-2.0.html> | ||
304 | + * | ||
305 | + * This header defines functions, types, etc which need to be shared | ||
306 | + * between different source files within target/arm/ but which are | ||
307 | + * private to it and not required by the rest of QEMU. | ||
75 | + */ | 308 | + */ |
76 | + | 309 | + |
77 | +#include "qemu/osdep.h" | 310 | +#ifndef TARGET_ARM_SYNDROME_H |
78 | +#include "qemu/log.h" | 311 | +#define TARGET_ARM_SYNDROME_H |
79 | +#include "qemu/module.h" | 312 | + |
80 | +#include "sysemu/runstate.h" | 313 | +/* Valid Syndrome Register EC field values */ |
81 | + | 314 | +enum arm_exception_class { |
82 | +#include "hw/nvram/fw_cfg.h" | 315 | + EC_UNCATEGORIZED = 0x00, |
83 | +#include "hw/qdev-properties.h" | 316 | + EC_WFX_TRAP = 0x01, |
84 | +#include "migration/vmstate.h" | 317 | + EC_CP15RTTRAP = 0x03, |
85 | +#include "hw/misc/pvpanic.h" | 318 | + EC_CP15RRTTRAP = 0x04, |
86 | +#include "qom/object.h" | 319 | + EC_CP14RTTRAP = 0x05, |
87 | +#include "hw/pci/pci.h" | 320 | + EC_CP14DTTRAP = 0x06, |
88 | + | 321 | + EC_ADVSIMDFPACCESSTRAP = 0x07, |
89 | +OBJECT_DECLARE_SIMPLE_TYPE(PVPanicPCIState, PVPANIC_PCI_DEVICE) | 322 | + EC_FPIDTRAP = 0x08, |
323 | + EC_PACTRAP = 0x09, | ||
324 | + EC_CP14RRTTRAP = 0x0c, | ||
325 | + EC_BTITRAP = 0x0d, | ||
326 | + EC_ILLEGALSTATE = 0x0e, | ||
327 | + EC_AA32_SVC = 0x11, | ||
328 | + EC_AA32_HVC = 0x12, | ||
329 | + EC_AA32_SMC = 0x13, | ||
330 | + EC_AA64_SVC = 0x15, | ||
331 | + EC_AA64_HVC = 0x16, | ||
332 | + EC_AA64_SMC = 0x17, | ||
333 | + EC_SYSTEMREGISTERTRAP = 0x18, | ||
334 | + EC_SVEACCESSTRAP = 0x19, | ||
335 | + EC_INSNABORT = 0x20, | ||
336 | + EC_INSNABORT_SAME_EL = 0x21, | ||
337 | + EC_PCALIGNMENT = 0x22, | ||
338 | + EC_DATAABORT = 0x24, | ||
339 | + EC_DATAABORT_SAME_EL = 0x25, | ||
340 | + EC_SPALIGNMENT = 0x26, | ||
341 | + EC_AA32_FPTRAP = 0x28, | ||
342 | + EC_AA64_FPTRAP = 0x2c, | ||
343 | + EC_SERROR = 0x2f, | ||
344 | + EC_BREAKPOINT = 0x30, | ||
345 | + EC_BREAKPOINT_SAME_EL = 0x31, | ||
346 | + EC_SOFTWARESTEP = 0x32, | ||
347 | + EC_SOFTWARESTEP_SAME_EL = 0x33, | ||
348 | + EC_WATCHPOINT = 0x34, | ||
349 | + EC_WATCHPOINT_SAME_EL = 0x35, | ||
350 | + EC_AA32_BKPT = 0x38, | ||
351 | + EC_VECTORCATCH = 0x3a, | ||
352 | + EC_AA64_BKPT = 0x3c, | ||
353 | +}; | ||
354 | + | ||
355 | +#define ARM_EL_EC_SHIFT 26 | ||
356 | +#define ARM_EL_IL_SHIFT 25 | ||
357 | +#define ARM_EL_ISV_SHIFT 24 | ||
358 | +#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) | ||
359 | +#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) | ||
360 | + | ||
361 | +static inline uint32_t syn_get_ec(uint32_t syn) | ||
362 | +{ | ||
363 | + return syn >> ARM_EL_EC_SHIFT; | ||
364 | +} | ||
90 | + | 365 | + |
91 | +/* | 366 | +/* |
92 | + * PVPanicPCIState for PCI device | 367 | + * Utility functions for constructing various kinds of syndrome value. |
368 | + * Note that in general we follow the AArch64 syndrome values; in a | ||
369 | + * few cases the value in HSR for exceptions taken to AArch32 Hyp | ||
370 | + * mode differs slightly, and we fix this up when populating HSR in | ||
371 | + * arm_cpu_do_interrupt_aarch32_hyp(). | ||
372 | + * The exception is FP/SIMD access traps -- these report extra information | ||
373 | + * when taking an exception to AArch32. For those we include the extra coproc | ||
374 | + * and TA fields, and mask them out when taking the exception to AArch64. | ||
93 | + */ | 375 | + */ |
94 | +typedef struct PVPanicPCIState { | 376 | +static inline uint32_t syn_uncategorized(void) |
95 | + PCIDevice dev; | 377 | +{ |
96 | + PVPanicState pvpanic; | 378 | + return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
97 | +} PVPanicPCIState; | 379 | +} |
98 | + | 380 | + |
99 | +static const VMStateDescription vmstate_pvpanic_pci = { | 381 | +static inline uint32_t syn_aa64_svc(uint32_t imm16) |
100 | + .name = "pvpanic-pci", | 382 | +{ |
101 | + .version_id = 1, | 383 | + return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
102 | + .minimum_version_id = 1, | 384 | +} |
103 | + .fields = (VMStateField[]) { | 385 | + |
104 | + VMSTATE_PCI_DEVICE(dev, PVPanicPCIState), | 386 | +static inline uint32_t syn_aa64_hvc(uint32_t imm16) |
105 | + VMSTATE_END_OF_LIST() | 387 | +{ |
106 | + } | 388 | + return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
107 | +}; | 389 | +} |
108 | + | 390 | + |
109 | +static void pvpanic_pci_realizefn(PCIDevice *dev, Error **errp) | 391 | +static inline uint32_t syn_aa64_smc(uint32_t imm16) |
110 | +{ | 392 | +{ |
111 | + PVPanicPCIState *s = PVPANIC_PCI_DEVICE(dev); | 393 | + return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
112 | + PVPanicState *ps = &s->pvpanic; | 394 | +} |
113 | + | 395 | + |
114 | + pvpanic_setup_io(&s->pvpanic, DEVICE(s), 2); | 396 | +static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit) |
115 | + | 397 | +{ |
116 | + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &ps->mr); | 398 | + return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
117 | +} | 399 | + | (is_16bit ? 0 : ARM_EL_IL); |
118 | + | 400 | +} |
119 | +static Property pvpanic_pci_properties[] = { | 401 | + |
120 | + DEFINE_PROP_UINT8("events", PVPanicPCIState, pvpanic.events, PVPANIC_PANICKED | PVPANIC_CRASHLOADED), | 402 | +static inline uint32_t syn_aa32_hvc(uint32_t imm16) |
121 | + DEFINE_PROP_END_OF_LIST(), | 403 | +{ |
122 | +}; | 404 | + return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
123 | + | 405 | +} |
124 | +static void pvpanic_pci_class_init(ObjectClass *klass, void *data) | 406 | + |
125 | +{ | 407 | +static inline uint32_t syn_aa32_smc(void) |
126 | + DeviceClass *dc = DEVICE_CLASS(klass); | 408 | +{ |
127 | + PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass); | 409 | + return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
128 | + | 410 | +} |
129 | + device_class_set_props(dc, pvpanic_pci_properties); | 411 | + |
130 | + | 412 | +static inline uint32_t syn_aa64_bkpt(uint32_t imm16) |
131 | + pc->realize = pvpanic_pci_realizefn; | 413 | +{ |
132 | + pc->vendor_id = PCI_VENDOR_ID_REDHAT; | 414 | + return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
133 | + pc->device_id = PCI_DEVICE_ID_REDHAT_PVPANIC; | 415 | +} |
134 | + pc->revision = 1; | 416 | + |
135 | + pc->class_id = PCI_CLASS_SYSTEM_OTHER; | 417 | +static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit) |
136 | + dc->vmsd = &vmstate_pvpanic_pci; | 418 | +{ |
137 | + | 419 | + return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
138 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 420 | + | (is_16bit ? 0 : ARM_EL_IL); |
139 | +} | 421 | +} |
140 | + | 422 | + |
141 | +static TypeInfo pvpanic_pci_info = { | 423 | +static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2, |
142 | + .name = TYPE_PVPANIC_PCI_DEVICE, | 424 | + int crn, int crm, int rt, |
143 | + .parent = TYPE_PCI_DEVICE, | 425 | + int isread) |
144 | + .instance_size = sizeof(PVPanicPCIState), | 426 | +{ |
145 | + .class_init = pvpanic_pci_class_init, | 427 | + return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL |
146 | + .interfaces = (InterfaceInfo[]) { | 428 | + | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5) |
147 | + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, | 429 | + | (crm << 1) | isread; |
148 | + { } | 430 | +} |
149 | + } | 431 | + |
150 | +}; | 432 | +static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2, |
151 | + | 433 | + int crn, int crm, int rt, int isread, |
152 | +static void pvpanic_register_types(void) | 434 | + bool is_16bit) |
153 | +{ | 435 | +{ |
154 | + type_register_static(&pvpanic_pci_info); | 436 | + return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT) |
155 | +} | 437 | + | (is_16bit ? 0 : ARM_EL_IL) |
156 | + | 438 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) |
157 | +type_init(pvpanic_register_types); | 439 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; |
158 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | 440 | +} |
159 | index XXXXXXX..XXXXXXX 100644 | 441 | + |
160 | --- a/hw/misc/Kconfig | 442 | +static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2, |
161 | +++ b/hw/misc/Kconfig | 443 | + int crn, int crm, int rt, int isread, |
162 | @@ -XXX,XX +XXX,XX @@ config IOTKIT_SYSINFO | 444 | + bool is_16bit) |
163 | config PVPANIC_COMMON | 445 | +{ |
164 | bool | 446 | + return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT) |
165 | 447 | + | (is_16bit ? 0 : ARM_EL_IL) | |
166 | +config PVPANIC_PCI | 448 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) |
167 | + bool | 449 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; |
168 | + default y if PCI_DEVICES | 450 | +} |
169 | + depends on PCI | 451 | + |
170 | + select PVPANIC_COMMON | 452 | +static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm, |
171 | + | 453 | + int rt, int rt2, int isread, |
172 | config PVPANIC_ISA | 454 | + bool is_16bit) |
173 | bool | 455 | +{ |
174 | depends on ISA_BUS | 456 | + return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT) |
175 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 457 | + | (is_16bit ? 0 : ARM_EL_IL) |
176 | index XXXXXXX..XXXXXXX 100644 | 458 | + | (cv << 24) | (cond << 20) | (opc1 << 16) |
177 | --- a/hw/misc/meson.build | 459 | + | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; |
178 | +++ b/hw/misc/meson.build | 460 | +} |
179 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ARMSSE_CPUID', if_true: files('armsse-cpuid.c')) | 461 | + |
180 | softmmu_ss.add(when: 'CONFIG_ARMSSE_MHU', if_true: files('armsse-mhu.c')) | 462 | +static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm, |
181 | 463 | + int rt, int rt2, int isread, | |
182 | softmmu_ss.add(when: 'CONFIG_PVPANIC_ISA', if_true: files('pvpanic-isa.c')) | 464 | + bool is_16bit) |
183 | +softmmu_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c')) | 465 | +{ |
184 | softmmu_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) | 466 | + return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT) |
185 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_scu.c', 'aspeed_sdmc.c', 'aspeed_xdma.c')) | 467 | + | (is_16bit ? 0 : ARM_EL_IL) |
186 | softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-sysreg.c')) | 468 | + | (cv << 24) | (cond << 20) | (opc1 << 16) |
469 | + | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; | ||
470 | +} | ||
471 | + | ||
472 | +static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit) | ||
473 | +{ | ||
474 | + /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */ | ||
475 | + return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | ||
476 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
477 | + | (cv << 24) | (cond << 20) | 0xa; | ||
478 | +} | ||
479 | + | ||
480 | +static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit) | ||
481 | +{ | ||
482 | + /* AArch32 SIMD trap: TA == 1 coproc == 0 */ | ||
483 | + return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | ||
484 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
485 | + | (cv << 24) | (cond << 20) | (1 << 5); | ||
486 | +} | ||
487 | + | ||
488 | +static inline uint32_t syn_sve_access_trap(void) | ||
489 | +{ | ||
490 | + return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; | ||
491 | +} | ||
492 | + | ||
493 | +static inline uint32_t syn_pactrap(void) | ||
494 | +{ | ||
495 | + return EC_PACTRAP << ARM_EL_EC_SHIFT; | ||
496 | +} | ||
497 | + | ||
498 | +static inline uint32_t syn_btitrap(int btype) | ||
499 | +{ | ||
500 | + return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype; | ||
501 | +} | ||
502 | + | ||
503 | +static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) | ||
504 | +{ | ||
505 | + return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
506 | + | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc; | ||
507 | +} | ||
508 | + | ||
509 | +static inline uint32_t syn_data_abort_no_iss(int same_el, int fnv, | ||
510 | + int ea, int cm, int s1ptw, | ||
511 | + int wnr, int fsc) | ||
512 | +{ | ||
513 | + return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
514 | + | ARM_EL_IL | ||
515 | + | (fnv << 10) | (ea << 9) | (cm << 8) | (s1ptw << 7) | ||
516 | + | (wnr << 6) | fsc; | ||
517 | +} | ||
518 | + | ||
519 | +static inline uint32_t syn_data_abort_with_iss(int same_el, | ||
520 | + int sas, int sse, int srt, | ||
521 | + int sf, int ar, | ||
522 | + int ea, int cm, int s1ptw, | ||
523 | + int wnr, int fsc, | ||
524 | + bool is_16bit) | ||
525 | +{ | ||
526 | + return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
527 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
528 | + | ARM_EL_ISV | (sas << 22) | (sse << 21) | (srt << 16) | ||
529 | + | (sf << 15) | (ar << 14) | ||
530 | + | (ea << 9) | (cm << 8) | (s1ptw << 7) | (wnr << 6) | fsc; | ||
531 | +} | ||
532 | + | ||
533 | +static inline uint32_t syn_swstep(int same_el, int isv, int ex) | ||
534 | +{ | ||
535 | + return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
536 | + | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22; | ||
537 | +} | ||
538 | + | ||
539 | +static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr) | ||
540 | +{ | ||
541 | + return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
542 | + | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22; | ||
543 | +} | ||
544 | + | ||
545 | +static inline uint32_t syn_breakpoint(int same_el) | ||
546 | +{ | ||
547 | + return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
548 | + | ARM_EL_IL | 0x22; | ||
549 | +} | ||
550 | + | ||
551 | +static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit) | ||
552 | +{ | ||
553 | + return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) | | ||
554 | + (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) | | ||
555 | + (cv << 24) | (cond << 20) | ti; | ||
556 | +} | ||
557 | + | ||
558 | +#endif /* TARGET_ARM_SYNDROME_H */ | ||
187 | -- | 559 | -- |
188 | 2.20.1 | 560 | 2.20.1 |
189 | 561 | ||
190 | 562 | diff view generated by jsdifflib |
1 | Create and connect the two clocks needed by the ARMSSE. | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | A proper syndrome is required to fill in the proper si_code. | ||
4 | Use page_get_flags to determine permission vs translation for user-only. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-27-richard.henderson@linaro.org | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Message-id: 20210128114145.20536-15-peter.maydell@linaro.org | ||
8 | Message-id: 20210121190622.22000-15-peter.maydell@linaro.org | ||
9 | --- | 10 | --- |
10 | hw/arm/mps2-tz.c | 13 +++++++++++++ | 11 | linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++--- |
11 | 1 file changed, 13 insertions(+) | 12 | target/arm/tlb_helper.c | 15 +++++++++------ |
13 | 2 files changed, 30 insertions(+), 9 deletions(-) | ||
12 | 14 | ||
13 | diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c | 15 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/arm/mps2-tz.c | 17 | --- a/linux-user/aarch64/cpu_loop.c |
16 | +++ b/hw/arm/mps2-tz.c | 18 | +++ b/linux-user/aarch64/cpu_loop.c |
17 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
18 | #include "hw/net/lan9118.h" | 20 | #include "cpu_loop-common.h" |
19 | #include "net/net.h" | 21 | #include "qemu/guest-random.h" |
20 | #include "hw/core/split-irq.h" | 22 | #include "hw/semihosting/common-semi.h" |
21 | +#include "hw/qdev-clock.h" | 23 | +#include "target/arm/syndrome.h" |
22 | #include "qom/object.h" | 24 | |
23 | 25 | #define get_user_code_u32(x, gaddr, env) \ | |
24 | #define MPS2TZ_NUMIRQ 92 | 26 | ({ abi_long __r = get_user_u32((x), (gaddr)); \ |
25 | @@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState { | 27 | @@ -XXX,XX +XXX,XX @@ |
26 | qemu_or_irq uart_irq_orgate; | 28 | void cpu_loop(CPUARMState *env) |
27 | DeviceState *lan9118; | 29 | { |
28 | SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ]; | 30 | CPUState *cs = env_cpu(env); |
29 | + Clock *sysclk; | 31 | - int trapnr; |
30 | + Clock *s32kclk; | 32 | + int trapnr, ec, fsc; |
31 | }; | 33 | abi_long ret; |
32 | 34 | target_siginfo_t info; | |
33 | #define TYPE_MPS2TZ_MACHINE "mps2tz" | 35 | |
34 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE) | 36 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) |
35 | 37 | case EXCP_DATA_ABORT: | |
36 | /* Main SYSCLK frequency in Hz */ | 38 | info.si_signo = TARGET_SIGSEGV; |
37 | #define SYSCLK_FRQ 20000000 | 39 | info.si_errno = 0; |
38 | +/* Slow 32Khz S32KCLK frequency in Hz */ | 40 | - /* XXX: check env->error_code */ |
39 | +#define S32KCLK_FRQ (32 * 1000) | 41 | - info.si_code = TARGET_SEGV_MAPERR; |
40 | 42 | info._sifields._sigfault._addr = env->exception.vaddress; | |
41 | /* Create an alias of an entire original MemoryRegion @orig | 43 | + |
42 | * located at @base in the memory map. | 44 | + /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ |
43 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine) | 45 | + ec = syn_get_ec(env->exception.syndrome); |
44 | exit(EXIT_FAILURE); | 46 | + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); |
47 | + | ||
48 | + /* Both EC have the same format for FSC, or close enough. */ | ||
49 | + fsc = extract32(env->exception.syndrome, 0, 6); | ||
50 | + switch (fsc) { | ||
51 | + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ | ||
52 | + info.si_code = TARGET_SEGV_MAPERR; | ||
53 | + break; | ||
54 | + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ | ||
55 | + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ | ||
56 | + info.si_code = TARGET_SEGV_ACCERR; | ||
57 | + break; | ||
58 | + default: | ||
59 | + g_assert_not_reached(); | ||
60 | + } | ||
61 | + | ||
62 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | ||
63 | break; | ||
64 | case EXCP_DEBUG: | ||
65 | diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/arm/tlb_helper.c | ||
68 | +++ b/target/arm/tlb_helper.c | ||
69 | @@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
70 | bool probe, uintptr_t retaddr) | ||
71 | { | ||
72 | ARMCPU *cpu = ARM_CPU(cs); | ||
73 | + ARMMMUFaultInfo fi = {}; | ||
74 | |||
75 | #ifdef CONFIG_USER_ONLY | ||
76 | - cpu->env.exception.vaddress = address; | ||
77 | - if (access_type == MMU_INST_FETCH) { | ||
78 | - cs->exception_index = EXCP_PREFETCH_ABORT; | ||
79 | + int flags = page_get_flags(useronly_clean_ptr(address)); | ||
80 | + if (flags & PAGE_VALID) { | ||
81 | + fi.type = ARMFault_Permission; | ||
82 | } else { | ||
83 | - cs->exception_index = EXCP_DATA_ABORT; | ||
84 | + fi.type = ARMFault_Translation; | ||
45 | } | 85 | } |
46 | 86 | - cpu_loop_exit_restore(cs, retaddr); | |
47 | + /* These clocks don't need migration because they are fixed-frequency */ | ||
48 | + mms->sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
49 | + clock_set_hz(mms->sysclk, SYSCLK_FRQ); | ||
50 | + mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK"); | ||
51 | + clock_set_hz(mms->s32kclk, S32KCLK_FRQ); | ||
52 | + | 87 | + |
53 | object_initialize_child(OBJECT(machine), TYPE_IOTKIT, &mms->iotkit, | 88 | + /* now we have a real cpu fault */ |
54 | mmc->armsse_type); | 89 | + cpu_restore_state(cs, retaddr, true); |
55 | iotkitdev = DEVICE(&mms->iotkit); | 90 | + arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi); |
56 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine) | 91 | #else |
57 | OBJECT(system_memory), &error_abort); | 92 | hwaddr phys_addr; |
58 | qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ); | 93 | target_ulong page_size; |
59 | qdev_prop_set_uint32(iotkitdev, "MAINCLK_FRQ", SYSCLK_FRQ); | 94 | int prot, ret; |
60 | + qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk); | 95 | MemTxAttrs attrs = {}; |
61 | + qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk); | 96 | - ARMMMUFaultInfo fi = {}; |
62 | sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal); | 97 | ARMCacheAttrs cacheattrs = {}; |
63 | 98 | ||
64 | /* | 99 | /* |
65 | -- | 100 | -- |
66 | 2.20.1 | 101 | 2.20.1 |
67 | 102 | ||
68 | 103 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | |||
3 | Meson will find CoreFoundation, IOKit, and Cocoa as needed. | ||
4 | 2 | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20210126012457.39046-7-j@getutm.app | 5 | Message-id: 20210212184902.1251044-28-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 7 | --- |
10 | configure | 1 - | 8 | linux-user/aarch64/target_signal.h | 2 ++ |
11 | 1 file changed, 1 deletion(-) | 9 | linux-user/aarch64/cpu_loop.c | 3 +++ |
10 | 2 files changed, 5 insertions(+) | ||
12 | 11 | ||
13 | diff --git a/configure b/configure | 12 | diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h |
14 | index XXXXXXX..XXXXXXX 100755 | 13 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/configure | 14 | --- a/linux-user/aarch64/target_signal.h |
16 | +++ b/configure | 15 | +++ b/linux-user/aarch64/target_signal.h |
17 | @@ -XXX,XX +XXX,XX @@ Darwin) | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
18 | fi | 17 | |
19 | audio_drv_list="coreaudio try-sdl" | 18 | #include "../generic/signal.h" |
20 | audio_possible_drivers="coreaudio sdl" | 19 | |
21 | - QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS" | 20 | +#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
22 | # Disable attempts to use ObjectiveC features in os/object.h since they | 21 | + |
23 | # won't work when we're compiling with gcc as a C compiler. | 22 | #define TARGET_ARCH_HAS_SETUP_FRAME |
24 | QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" | 23 | #endif /* AARCH64_TARGET_SIGNAL_H */ |
24 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/linux-user/aarch64/cpu_loop.c | ||
27 | +++ b/linux-user/aarch64/cpu_loop.c | ||
28 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) | ||
29 | case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ | ||
30 | info.si_code = TARGET_SEGV_ACCERR; | ||
31 | break; | ||
32 | + case 0x11: /* Synchronous Tag Check Fault */ | ||
33 | + info.si_code = TARGET_SEGV_MTESERR; | ||
34 | + break; | ||
35 | default: | ||
36 | g_assert_not_reached(); | ||
37 | } | ||
25 | -- | 38 | -- |
26 | 2.20.1 | 39 | 2.20.1 |
27 | 40 | ||
28 | 41 | diff view generated by jsdifflib |
1 | From: Joelle van Dyne <j@getutm.app> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The iOS toolchain does not use the host prefix naming convention. So we | 3 | The real kernel collects _TIF_MTE_ASYNC_FAULT into the current thread's |
4 | need to enable cross-compile options while allowing the PREFIX to be | 4 | state on any kernel entry (interrupt, exception etc), and then delivers |
5 | blank. | 5 | the signal in advance of resuming the thread. |
6 | 6 | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | This means that while the signal won't be delivered immediately, it will |
8 | Signed-off-by: Joelle van Dyne <j@getutm.app> | 8 | not be delayed forever -- at minimum it will be delivered after the next |
9 | Message-id: 20210126012457.39046-3-j@getutm.app | 9 | clock interrupt. |
10 | |||
11 | We don't have a clock interrupt in linux-user, so we issue a cpu_kick | ||
12 | to signal a return to the main loop at the end of the current TB. | ||
13 | |||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20210212184902.1251044-29-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 18 | --- |
12 | configure | 6 ++++-- | 19 | linux-user/aarch64/target_signal.h | 1 + |
13 | 1 file changed, 4 insertions(+), 2 deletions(-) | 20 | linux-user/aarch64/cpu_loop.c | 11 +++++++++++ |
21 | target/arm/mte_helper.c | 10 ++++++++++ | ||
22 | 3 files changed, 22 insertions(+) | ||
14 | 23 | ||
15 | diff --git a/configure b/configure | 24 | diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h |
16 | index XXXXXXX..XXXXXXX 100755 | 25 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/configure | 26 | --- a/linux-user/aarch64/target_signal.h |
18 | +++ b/configure | 27 | +++ b/linux-user/aarch64/target_signal.h |
19 | @@ -XXX,XX +XXX,XX @@ cpu="" | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
20 | iasl="iasl" | 29 | |
21 | interp_prefix="/usr/gnemul/qemu-%M" | 30 | #include "../generic/signal.h" |
22 | static="no" | 31 | |
23 | +cross_compile="no" | 32 | +#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */ |
24 | cross_prefix="" | 33 | #define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
25 | audio_drv_list="" | 34 | |
26 | block_drv_rw_whitelist="" | 35 | #define TARGET_ARCH_HAS_SETUP_FRAME |
27 | @@ -XXX,XX +XXX,XX @@ for opt do | 36 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
28 | optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') | 37 | index XXXXXXX..XXXXXXX 100644 |
29 | case "$opt" in | 38 | --- a/linux-user/aarch64/cpu_loop.c |
30 | --cross-prefix=*) cross_prefix="$optarg" | 39 | +++ b/linux-user/aarch64/cpu_loop.c |
31 | + cross_compile="yes" | 40 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) |
32 | ;; | 41 | EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); |
33 | --cc=*) CC="$optarg" | 42 | abort(); |
34 | ;; | 43 | } |
35 | @@ -XXX,XX +XXX,XX @@ $(echo Deprecated targets: $deprecated_targets_list | \ | 44 | + |
36 | --target-list-exclude=LIST exclude a set of targets from the default target-list | 45 | + /* Check for MTE asynchronous faults */ |
37 | 46 | + if (unlikely(env->cp15.tfsr_el[0])) { | |
38 | Advanced options (experts only): | 47 | + env->cp15.tfsr_el[0] = 0; |
39 | - --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix] | 48 | + info.si_signo = TARGET_SIGSEGV; |
40 | + --cross-prefix=PREFIX use PREFIX for compile tools, PREFIX can be blank [$cross_prefix] | 49 | + info.si_errno = 0; |
41 | --cc=CC use C compiler CC [$cc] | 50 | + info._sifields._sigfault._addr = 0; |
42 | --iasl=IASL use ACPI compiler IASL [$iasl] | 51 | + info.si_code = TARGET_SEGV_MTEAERR; |
43 | --host-cc=CC use C compiler CC [$host_cc] for code run at | 52 | + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); |
44 | @@ -XXX,XX +XXX,XX @@ if has $sdl2_config; then | 53 | + } |
45 | fi | 54 | + |
46 | echo "strip = [$(meson_quote $strip)]" >> $cross | 55 | process_pending_signals(env); |
47 | echo "windres = [$(meson_quote $windres)]" >> $cross | 56 | /* Exception return on AArch64 always clears the exclusive monitor, |
48 | -if test -n "$cross_prefix"; then | 57 | * so any return to running guest code implies this. |
49 | +if test "$cross_compile" = "yes"; then | 58 | diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c |
50 | cross_arg="--cross-file config-meson.cross" | 59 | index XXXXXXX..XXXXXXX 100644 |
51 | echo "[host_machine]" >> $cross | 60 | --- a/target/arm/mte_helper.c |
52 | if test "$mingw32" = "yes" ; then | 61 | +++ b/target/arm/mte_helper.c |
62 | @@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, | ||
63 | select = 0; | ||
64 | } | ||
65 | env->cp15.tfsr_el[el] |= 1 << select; | ||
66 | +#ifdef CONFIG_USER_ONLY | ||
67 | + /* | ||
68 | + * Stand in for a timer irq, setting _TIF_MTE_ASYNC_FAULT, | ||
69 | + * which then sends a SIGSEGV when the thread is next scheduled. | ||
70 | + * This cpu will return to the main loop at the end of the TB, | ||
71 | + * which is rather sooner than "normal". But the alternative | ||
72 | + * is waiting until the next syscall. | ||
73 | + */ | ||
74 | + qemu_cpu_kick(env_cpu(env)); | ||
75 | +#endif | ||
76 | break; | ||
77 | |||
78 | default: | ||
53 | -- | 79 | -- |
54 | 2.20.1 | 80 | 2.20.1 |
55 | 81 | ||
56 | 82 | diff view generated by jsdifflib |
1 | The old-style convenience function cmsdk_apb_timer_create() for | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | creating CMSDK_APB_TIMER objects is used in only two places in | ||
3 | mps2.c. Most of the rest of the code in that file uses the new | ||
4 | "initialize in place" coding style. | ||
5 | 2 | ||
6 | We want to connect up a Clock object which should be done between the | 3 | Use the now-saved PAGE_ANON and PAGE_MTE bits, |
7 | object creation and realization; rather than adding a Clock* argument | 4 | and the per-page saved data. |
8 | to the convenience function, convert the timer creation code in | ||
9 | mps2.c to the same style as is used already for the watchdog, | ||
10 | dualtimer and other devices, and delete the now-unused convenience | ||
11 | function. | ||
12 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210212184902.1251044-30-richard.henderson@linaro.org | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
16 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Message-id: 20210128114145.20536-13-peter.maydell@linaro.org | ||
18 | Message-id: 20210121190622.22000-13-peter.maydell@linaro.org | ||
19 | --- | 10 | --- |
20 | include/hw/timer/cmsdk-apb-timer.h | 21 --------------------- | 11 | target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++-- |
21 | hw/arm/mps2.c | 18 ++++++++++++++++-- | 12 | 1 file changed, 27 insertions(+), 2 deletions(-) |
22 | 2 files changed, 16 insertions(+), 23 deletions(-) | ||
23 | 13 | ||
24 | diff --git a/include/hw/timer/cmsdk-apb-timer.h b/include/hw/timer/cmsdk-apb-timer.h | 14 | diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c |
25 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/include/hw/timer/cmsdk-apb-timer.h | 16 | --- a/target/arm/mte_helper.c |
27 | +++ b/include/hw/timer/cmsdk-apb-timer.h | 17 | +++ b/target/arm/mte_helper.c |
28 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBTimer { | 18 | @@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, |
29 | uint32_t intstatus; | 19 | int tag_size, uintptr_t ra) |
30 | }; | 20 | { |
31 | 21 | #ifdef CONFIG_USER_ONLY | |
32 | -/** | 22 | - /* Tag storage not implemented. */ |
33 | - * cmsdk_apb_timer_create - convenience function to create TYPE_CMSDK_APB_TIMER | 23 | - return NULL; |
34 | - * @addr: location in system memory to map registers | 24 | + uint64_t clean_ptr = useronly_clean_ptr(ptr); |
35 | - * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud rate) | 25 | + int flags = page_get_flags(clean_ptr); |
36 | - */ | 26 | + uint8_t *tags; |
37 | -static inline DeviceState *cmsdk_apb_timer_create(hwaddr addr, | 27 | + uintptr_t index; |
38 | - qemu_irq timerint, | ||
39 | - uint32_t pclk_frq) | ||
40 | -{ | ||
41 | - DeviceState *dev; | ||
42 | - SysBusDevice *s; | ||
43 | - | ||
44 | - dev = qdev_new(TYPE_CMSDK_APB_TIMER); | ||
45 | - s = SYS_BUS_DEVICE(dev); | ||
46 | - qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq); | ||
47 | - sysbus_realize_and_unref(s, &error_fatal); | ||
48 | - sysbus_mmio_map(s, 0, addr); | ||
49 | - sysbus_connect_irq(s, 0, timerint); | ||
50 | - return dev; | ||
51 | -} | ||
52 | - | ||
53 | #endif | ||
54 | diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/arm/mps2.c | ||
57 | +++ b/hw/arm/mps2.c | ||
58 | @@ -XXX,XX +XXX,XX @@ struct MPS2MachineState { | ||
59 | /* CMSDK APB subsystem */ | ||
60 | CMSDKAPBDualTimer dualtimer; | ||
61 | CMSDKAPBWatchdog watchdog; | ||
62 | + CMSDKAPBTimer timer[2]; | ||
63 | }; | ||
64 | |||
65 | #define TYPE_MPS2_MACHINE "mps2" | ||
66 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
67 | } | ||
68 | |||
69 | /* CMSDK APB subsystem */ | ||
70 | - cmsdk_apb_timer_create(0x40000000, qdev_get_gpio_in(armv7m, 8), SYSCLK_FRQ); | ||
71 | - cmsdk_apb_timer_create(0x40001000, qdev_get_gpio_in(armv7m, 9), SYSCLK_FRQ); | ||
72 | + for (i = 0; i < ARRAY_SIZE(mms->timer); i++) { | ||
73 | + g_autofree char *name = g_strdup_printf("timer%d", i); | ||
74 | + hwaddr base = 0x40000000 + i * 0x1000; | ||
75 | + int irqno = 8 + i; | ||
76 | + SysBusDevice *sbd; | ||
77 | + | 28 | + |
78 | + object_initialize_child(OBJECT(mms), name, &mms->timer[i], | 29 | + if (!(flags & (ptr_access == MMU_DATA_STORE ? PAGE_WRITE : PAGE_READ))) { |
79 | + TYPE_CMSDK_APB_TIMER); | 30 | + /* SIGSEGV */ |
80 | + sbd = SYS_BUS_DEVICE(&mms->timer[i]); | 31 | + arm_cpu_tlb_fill(env_cpu(env), ptr, ptr_size, ptr_access, |
81 | + qdev_prop_set_uint32(DEVICE(&mms->timer[i]), "pclk-frq", SYSCLK_FRQ); | 32 | + ptr_mmu_idx, false, ra); |
82 | + sysbus_realize_and_unref(sbd, &error_fatal); | 33 | + g_assert_not_reached(); |
83 | + sysbus_mmio_map(sbd, 0, base); | ||
84 | + sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(armv7m, irqno)); | ||
85 | + } | 34 | + } |
86 | + | 35 | + |
87 | object_initialize_child(OBJECT(mms), "dualtimer", &mms->dualtimer, | 36 | + /* Require both MAP_ANON and PROT_MTE for the page. */ |
88 | TYPE_CMSDK_APB_DUALTIMER); | 37 | + if (!(flags & PAGE_ANON) || !(flags & PAGE_MTE)) { |
89 | qdev_prop_set_uint32(DEVICE(&mms->dualtimer), "pclk-frq", SYSCLK_FRQ); | 38 | + return NULL; |
39 | + } | ||
40 | + | ||
41 | + tags = page_get_target_data(clean_ptr); | ||
42 | + if (tags == NULL) { | ||
43 | + size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); | ||
44 | + tags = page_alloc_target_data(clean_ptr, alloc_size); | ||
45 | + assert(tags != NULL); | ||
46 | + } | ||
47 | + | ||
48 | + index = extract32(ptr, LOG2_TAG_GRANULE + 1, | ||
49 | + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); | ||
50 | + return tags + index; | ||
51 | #else | ||
52 | uintptr_t index; | ||
53 | CPUIOTLBEntry *iotlbentry; | ||
90 | -- | 54 | -- |
91 | 2.20.1 | 55 | 2.20.1 |
92 | 56 | ||
93 | 57 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Only define the register if it exists for the cpu. | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20210120031656.737646-1-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-31-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 7 | --- |
10 | target/arm/helper.c | 21 +++++++++++++++------ | 8 | target/arm/cpu.c | 15 +++++++++++++++ |
11 | 1 file changed, 15 insertions(+), 6 deletions(-) | 9 | 1 file changed, 15 insertions(+) |
12 | 10 | ||
13 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.c | 13 | --- a/target/arm/cpu.c |
16 | +++ b/target/arm/helper.c | 14 | +++ b/target/arm/cpu.c |
17 | @@ -XXX,XX +XXX,XX @@ static void define_debug_regs(ARMCPU *cpu) | 15 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
18 | */ | 16 | * Note that this must match useronly_clean_ptr. |
19 | int i; | 17 | */ |
20 | int wrps, brps, ctx_cmps; | 18 | env->cp15.tcr_el[1].raw_tcr = (1ULL << 37); |
21 | - ARMCPRegInfo dbgdidr = { | ||
22 | - .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 0, | ||
23 | - .access = PL0_R, .accessfn = access_tda, | ||
24 | - .type = ARM_CP_CONST, .resetvalue = cpu->isar.dbgdidr, | ||
25 | - }; | ||
26 | + | 19 | + |
27 | + /* | 20 | + /* Enable MTE */ |
28 | + * The Arm ARM says DBGDIDR is optional and deprecated if EL1 cannot | 21 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
29 | + * use AArch32. Given that bit 15 is RES1, if the value is 0 then | 22 | + /* Enable tag access, but leave TCF0 as No Effect (0). */ |
30 | + * the register must not exist for this cpu. | 23 | + env->cp15.sctlr_el[1] |= SCTLR_ATA0; |
31 | + */ | 24 | + /* |
32 | + if (cpu->isar.dbgdidr != 0) { | 25 | + * Exclude all tags, so that tag 0 is always used. |
33 | + ARMCPRegInfo dbgdidr = { | 26 | + * This corresponds to Linux current->thread.gcr_incl = 0. |
34 | + .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0, | 27 | + * |
35 | + .opc1 = 0, .opc2 = 0, | 28 | + * Set RRND, so that helper_irg() will generate a seed later. |
36 | + .access = PL0_R, .accessfn = access_tda, | 29 | + * Here in cpu_reset(), the crypto subsystem has not yet been |
37 | + .type = ARM_CP_CONST, .resetvalue = cpu->isar.dbgdidr, | 30 | + * initialized. |
38 | + }; | 31 | + */ |
39 | + define_one_arm_cp_reg(cpu, &dbgdidr); | 32 | + env->cp15.gcr_el1 = 0x1ffff; |
40 | + } | 33 | + } |
41 | 34 | #else | |
42 | /* Note that all these register fields hold "number of Xs minus 1". */ | 35 | /* Reset into the highest available EL */ |
43 | brps = arm_num_brps(cpu); | 36 | if (arm_feature(env, ARM_FEATURE_EL3)) { |
44 | @@ -XXX,XX +XXX,XX @@ static void define_debug_regs(ARMCPU *cpu) | ||
45 | |||
46 | assert(ctx_cmps <= brps); | ||
47 | |||
48 | - define_one_arm_cp_reg(cpu, &dbgdidr); | ||
49 | define_arm_cp_regs(cpu, debug_cp_reginfo); | ||
50 | |||
51 | if (arm_feature(&cpu->env, ARM_FEATURE_LPAE)) { | ||
52 | -- | 37 | -- |
53 | 2.20.1 | 38 | 2.20.1 |
54 | 39 | ||
55 | 40 | diff view generated by jsdifflib |
1 | From: Maxim Uvarov <maxim.uvarov@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Implement gpio-pwr driver to allow reboot and poweroff machine. | ||
4 | This is simple driver with just 2 gpios lines. Current use case | ||
5 | is to reboot and poweroff virt machine in secure mode. Secure | ||
6 | pl066 gpio chip is needed for that. | ||
7 | |||
8 | Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> | ||
9 | Reviewed-by: Hao Wu <wuhaotsh@google.com> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20210212184902.1251044-32-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 7 | --- |
13 | hw/gpio/gpio_pwr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ | 8 | tests/tcg/aarch64/mte.h | 60 +++++++++++++++++++++++++++++++ |
14 | hw/gpio/Kconfig | 3 ++ | 9 | tests/tcg/aarch64/mte-1.c | 28 +++++++++++++++ |
15 | hw/gpio/meson.build | 1 + | 10 | tests/tcg/aarch64/mte-2.c | 45 +++++++++++++++++++++++ |
16 | 3 files changed, 74 insertions(+) | 11 | tests/tcg/aarch64/mte-3.c | 51 ++++++++++++++++++++++++++ |
17 | create mode 100644 hw/gpio/gpio_pwr.c | 12 | tests/tcg/aarch64/mte-4.c | 45 +++++++++++++++++++++++ |
13 | tests/tcg/aarch64/Makefile.target | 6 ++++ | ||
14 | tests/tcg/configure.sh | 4 +++ | ||
15 | 7 files changed, 239 insertions(+) | ||
16 | create mode 100644 tests/tcg/aarch64/mte.h | ||
17 | create mode 100644 tests/tcg/aarch64/mte-1.c | ||
18 | create mode 100644 tests/tcg/aarch64/mte-2.c | ||
19 | create mode 100644 tests/tcg/aarch64/mte-3.c | ||
20 | create mode 100644 tests/tcg/aarch64/mte-4.c | ||
18 | 21 | ||
19 | diff --git a/hw/gpio/gpio_pwr.c b/hw/gpio/gpio_pwr.c | 22 | diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h |
20 | new file mode 100644 | 23 | new file mode 100644 |
21 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
22 | --- /dev/null | 25 | --- /dev/null |
23 | +++ b/hw/gpio/gpio_pwr.c | 26 | +++ b/tests/tcg/aarch64/mte.h |
24 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
25 | +/* | 28 | +/* |
26 | + * GPIO qemu power controller | 29 | + * Linux kernel fallback API definitions for MTE and test helpers. |
27 | + * | 30 | + * |
28 | + * Copyright (c) 2020 Linaro Limited | 31 | + * Copyright (c) 2021 Linaro Ltd |
29 | + * | 32 | + * SPDX-License-Identifier: GPL-2.0-or-later |
30 | + * Author: Maxim Uvarov <maxim.uvarov@linaro.org> | 33 | + */ |
31 | + * | 34 | + |
32 | + * Virtual gpio driver which can be used on top of pl061 | 35 | +#include <assert.h> |
33 | + * to reboot and shutdown qemu virtual machine. One of use | 36 | +#include <string.h> |
34 | + * case is gpio driver for secure world application (ARM | 37 | +#include <stdlib.h> |
35 | + * Trusted Firmware.). | 38 | +#include <stdio.h> |
36 | + * | 39 | +#include <unistd.h> |
37 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 40 | +#include <signal.h> |
38 | + * See the COPYING file in the top-level directory. | 41 | +#include <sys/mman.h> |
39 | + * SPDX-License-Identifier: GPL-2.0-or-later | 42 | +#include <sys/prctl.h> |
40 | + */ | 43 | + |
41 | + | 44 | +#ifndef PR_SET_TAGGED_ADDR_CTRL |
42 | +/* | 45 | +# define PR_SET_TAGGED_ADDR_CTRL 55 |
43 | + * QEMU interface: | 46 | +#endif |
44 | + * two named input GPIO lines: | 47 | +#ifndef PR_TAGGED_ADDR_ENABLE |
45 | + * 'reset' : when asserted, trigger system reset | 48 | +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) |
46 | + * 'shutdown' : when asserted, trigger system shutdown | 49 | +#endif |
47 | + */ | 50 | +#ifndef PR_MTE_TCF_SHIFT |
48 | + | 51 | +# define PR_MTE_TCF_SHIFT 1 |
49 | +#include "qemu/osdep.h" | 52 | +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) |
50 | +#include "hw/sysbus.h" | 53 | +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) |
51 | +#include "sysemu/runstate.h" | 54 | +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) |
52 | + | 55 | +# define PR_MTE_TAG_SHIFT 3 |
53 | +#define TYPE_GPIOPWR "gpio-pwr" | 56 | +#endif |
54 | +OBJECT_DECLARE_SIMPLE_TYPE(GPIO_PWR_State, GPIOPWR) | 57 | + |
55 | + | 58 | +#ifndef PROT_MTE |
56 | +struct GPIO_PWR_State { | 59 | +# define PROT_MTE 0x20 |
57 | + SysBusDevice parent_obj; | 60 | +#endif |
58 | +}; | 61 | + |
59 | + | 62 | +#ifndef SEGV_MTEAERR |
60 | +static void gpio_pwr_reset(void *opaque, int n, int level) | 63 | +# define SEGV_MTEAERR 8 |
61 | +{ | 64 | +# define SEGV_MTESERR 9 |
62 | + if (level) { | 65 | +#endif |
63 | + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | 66 | + |
67 | +static void enable_mte(int tcf) | ||
68 | +{ | ||
69 | + int r = prctl(PR_SET_TAGGED_ADDR_CTRL, | ||
70 | + PR_TAGGED_ADDR_ENABLE | tcf | (0xfffe << PR_MTE_TAG_SHIFT), | ||
71 | + 0, 0, 0); | ||
72 | + if (r < 0) { | ||
73 | + perror("PR_SET_TAGGED_ADDR_CTRL"); | ||
74 | + exit(2); | ||
64 | + } | 75 | + } |
65 | +} | 76 | +} |
66 | + | 77 | + |
67 | +static void gpio_pwr_shutdown(void *opaque, int n, int level) | 78 | +static void *alloc_mte_mem(size_t size) |
68 | +{ | 79 | +{ |
69 | + if (level) { | 80 | + void *p = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_MTE, |
70 | + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | 81 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
82 | + if (p == MAP_FAILED) { | ||
83 | + perror("mmap PROT_MTE"); | ||
84 | + exit(2); | ||
71 | + } | 85 | + } |
72 | +} | 86 | + return p; |
73 | + | 87 | +} |
74 | +static void gpio_pwr_init(Object *obj) | 88 | diff --git a/tests/tcg/aarch64/mte-1.c b/tests/tcg/aarch64/mte-1.c |
75 | +{ | 89 | new file mode 100644 |
76 | + DeviceState *dev = DEVICE(obj); | 90 | index XXXXXXX..XXXXXXX |
77 | + | 91 | --- /dev/null |
78 | + qdev_init_gpio_in_named(dev, gpio_pwr_reset, "reset", 1); | 92 | +++ b/tests/tcg/aarch64/mte-1.c |
79 | + qdev_init_gpio_in_named(dev, gpio_pwr_shutdown, "shutdown", 1); | 93 | @@ -XXX,XX +XXX,XX @@ |
80 | +} | 94 | +/* |
81 | + | 95 | + * Memory tagging, basic pass cases. |
82 | +static const TypeInfo gpio_pwr_info = { | 96 | + * |
83 | + .name = TYPE_GPIOPWR, | 97 | + * Copyright (c) 2021 Linaro Ltd |
84 | + .parent = TYPE_SYS_BUS_DEVICE, | 98 | + * SPDX-License-Identifier: GPL-2.0-or-later |
85 | + .instance_size = sizeof(GPIO_PWR_State), | 99 | + */ |
86 | + .instance_init = gpio_pwr_init, | 100 | + |
87 | +}; | 101 | +#include "mte.h" |
88 | + | 102 | + |
89 | +static void gpio_pwr_register_types(void) | 103 | +int main(int ac, char **av) |
90 | +{ | 104 | +{ |
91 | + type_register_static(&gpio_pwr_info); | 105 | + int *p0, *p1, *p2; |
92 | +} | 106 | + long c; |
93 | + | 107 | + |
94 | +type_init(gpio_pwr_register_types) | 108 | + enable_mte(PR_MTE_TCF_NONE); |
95 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig | 109 | + p0 = alloc_mte_mem(sizeof(*p0)); |
110 | + | ||
111 | + asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(1)); | ||
112 | + assert(p1 != p0); | ||
113 | + asm("subp %0,%1,%2" : "=r"(c) : "r"(p0), "r"(p1)); | ||
114 | + assert(c == 0); | ||
115 | + | ||
116 | + asm("stg %0, [%0]" : : "r"(p1)); | ||
117 | + asm("ldg %0, [%1]" : "=r"(p2) : "r"(p0), "0"(p0)); | ||
118 | + assert(p1 == p2); | ||
119 | + | ||
120 | + return 0; | ||
121 | +} | ||
122 | diff --git a/tests/tcg/aarch64/mte-2.c b/tests/tcg/aarch64/mte-2.c | ||
123 | new file mode 100644 | ||
124 | index XXXXXXX..XXXXXXX | ||
125 | --- /dev/null | ||
126 | +++ b/tests/tcg/aarch64/mte-2.c | ||
127 | @@ -XXX,XX +XXX,XX @@ | ||
128 | +/* | ||
129 | + * Memory tagging, basic fail cases, synchronous signals. | ||
130 | + * | ||
131 | + * Copyright (c) 2021 Linaro Ltd | ||
132 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
133 | + */ | ||
134 | + | ||
135 | +#include "mte.h" | ||
136 | + | ||
137 | +void pass(int sig, siginfo_t *info, void *uc) | ||
138 | +{ | ||
139 | + assert(info->si_code == SEGV_MTESERR); | ||
140 | + exit(0); | ||
141 | +} | ||
142 | + | ||
143 | +int main(int ac, char **av) | ||
144 | +{ | ||
145 | + struct sigaction sa; | ||
146 | + int *p0, *p1, *p2; | ||
147 | + long excl = 1; | ||
148 | + | ||
149 | + enable_mte(PR_MTE_TCF_SYNC); | ||
150 | + p0 = alloc_mte_mem(sizeof(*p0)); | ||
151 | + | ||
152 | + /* Create two differently tagged pointers. */ | ||
153 | + asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); | ||
154 | + asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1)); | ||
155 | + assert(excl != 1); | ||
156 | + asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl)); | ||
157 | + assert(p1 != p2); | ||
158 | + | ||
159 | + /* Store the tag from the first pointer. */ | ||
160 | + asm("stg %0, [%0]" : : "r"(p1)); | ||
161 | + | ||
162 | + *p1 = 0; | ||
163 | + | ||
164 | + memset(&sa, 0, sizeof(sa)); | ||
165 | + sa.sa_sigaction = pass; | ||
166 | + sa.sa_flags = SA_SIGINFO; | ||
167 | + sigaction(SIGSEGV, &sa, NULL); | ||
168 | + | ||
169 | + *p2 = 0; | ||
170 | + | ||
171 | + abort(); | ||
172 | +} | ||
173 | diff --git a/tests/tcg/aarch64/mte-3.c b/tests/tcg/aarch64/mte-3.c | ||
174 | new file mode 100644 | ||
175 | index XXXXXXX..XXXXXXX | ||
176 | --- /dev/null | ||
177 | +++ b/tests/tcg/aarch64/mte-3.c | ||
178 | @@ -XXX,XX +XXX,XX @@ | ||
179 | +/* | ||
180 | + * Memory tagging, basic fail cases, asynchronous signals. | ||
181 | + * | ||
182 | + * Copyright (c) 2021 Linaro Ltd | ||
183 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
184 | + */ | ||
185 | + | ||
186 | +#include "mte.h" | ||
187 | + | ||
188 | +void pass(int sig, siginfo_t *info, void *uc) | ||
189 | +{ | ||
190 | + assert(info->si_code == SEGV_MTEAERR); | ||
191 | + exit(0); | ||
192 | +} | ||
193 | + | ||
194 | +int main(int ac, char **av) | ||
195 | +{ | ||
196 | + struct sigaction sa; | ||
197 | + long *p0, *p1, *p2; | ||
198 | + long excl = 1; | ||
199 | + | ||
200 | + enable_mte(PR_MTE_TCF_ASYNC); | ||
201 | + p0 = alloc_mte_mem(sizeof(*p0)); | ||
202 | + | ||
203 | + /* Create two differently tagged pointers. */ | ||
204 | + asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); | ||
205 | + asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1)); | ||
206 | + assert(excl != 1); | ||
207 | + asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl)); | ||
208 | + assert(p1 != p2); | ||
209 | + | ||
210 | + /* Store the tag from the first pointer. */ | ||
211 | + asm("stg %0, [%0]" : : "r"(p1)); | ||
212 | + | ||
213 | + *p1 = 0; | ||
214 | + | ||
215 | + memset(&sa, 0, sizeof(sa)); | ||
216 | + sa.sa_sigaction = pass; | ||
217 | + sa.sa_flags = SA_SIGINFO; | ||
218 | + sigaction(SIGSEGV, &sa, NULL); | ||
219 | + | ||
220 | + /* | ||
221 | + * Signal for async error will happen eventually. | ||
222 | + * For a real kernel this should be after the next IRQ (e.g. timer). | ||
223 | + * For qemu linux-user, we kick the cpu and exit at the next TB. | ||
224 | + * In either case, loop until this happens (or killed by timeout). | ||
225 | + * For extra sauce, yield, producing EXCP_YIELD to cpu_loop(). | ||
226 | + */ | ||
227 | + asm("str %0, [%0]; yield" : : "r"(p2)); | ||
228 | + while (1); | ||
229 | +} | ||
230 | diff --git a/tests/tcg/aarch64/mte-4.c b/tests/tcg/aarch64/mte-4.c | ||
231 | new file mode 100644 | ||
232 | index XXXXXXX..XXXXXXX | ||
233 | --- /dev/null | ||
234 | +++ b/tests/tcg/aarch64/mte-4.c | ||
235 | @@ -XXX,XX +XXX,XX @@ | ||
236 | +/* | ||
237 | + * Memory tagging, re-reading tag checks. | ||
238 | + * | ||
239 | + * Copyright (c) 2021 Linaro Ltd | ||
240 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
241 | + */ | ||
242 | + | ||
243 | +#include "mte.h" | ||
244 | + | ||
245 | +void __attribute__((noinline)) tagset(void *p, size_t size) | ||
246 | +{ | ||
247 | + size_t i; | ||
248 | + for (i = 0; i < size; i += 16) { | ||
249 | + asm("stg %0, [%0]" : : "r"(p + i)); | ||
250 | + } | ||
251 | +} | ||
252 | + | ||
253 | +void __attribute__((noinline)) tagcheck(void *p, size_t size) | ||
254 | +{ | ||
255 | + size_t i; | ||
256 | + void *c; | ||
257 | + | ||
258 | + for (i = 0; i < size; i += 16) { | ||
259 | + asm("ldg %0, [%1]" : "=r"(c) : "r"(p + i), "0"(p)); | ||
260 | + assert(c == p); | ||
261 | + } | ||
262 | +} | ||
263 | + | ||
264 | +int main(int ac, char **av) | ||
265 | +{ | ||
266 | + size_t size = getpagesize() * 4; | ||
267 | + long excl = 1; | ||
268 | + int *p0, *p1; | ||
269 | + | ||
270 | + enable_mte(PR_MTE_TCF_ASYNC); | ||
271 | + p0 = alloc_mte_mem(size); | ||
272 | + | ||
273 | + /* Tag the pointer. */ | ||
274 | + asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); | ||
275 | + | ||
276 | + tagset(p1, size); | ||
277 | + tagcheck(p1, size); | ||
278 | + | ||
279 | + return 0; | ||
280 | +} | ||
281 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target | ||
96 | index XXXXXXX..XXXXXXX 100644 | 282 | index XXXXXXX..XXXXXXX 100644 |
97 | --- a/hw/gpio/Kconfig | 283 | --- a/tests/tcg/aarch64/Makefile.target |
98 | +++ b/hw/gpio/Kconfig | 284 | +++ b/tests/tcg/aarch64/Makefile.target |
99 | @@ -XXX,XX +XXX,XX @@ config PL061 | 285 | @@ -XXX,XX +XXX,XX @@ endif |
100 | config GPIO_KEY | 286 | # bti-2 tests PROT_BTI, so no special compiler support required. |
101 | bool | 287 | AARCH64_TESTS += bti-2 |
102 | 288 | ||
103 | +config GPIO_PWR | 289 | +# MTE Tests |
104 | + bool | 290 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),) |
105 | + | 291 | +AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 |
106 | config SIFIVE_GPIO | 292 | +mte-%: CFLAGS += -march=armv8.5-a+memtag |
107 | bool | 293 | +endif |
108 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | 294 | + |
109 | index XXXXXXX..XXXXXXX 100644 | 295 | # Semihosting smoke test for linux-user |
110 | --- a/hw/gpio/meson.build | 296 | AARCH64_TESTS += semihosting |
111 | +++ b/hw/gpio/meson.build | 297 | run-semihosting: semihosting |
112 | @@ -XXX,XX +XXX,XX @@ | 298 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
113 | softmmu_ss.add(when: 'CONFIG_E500', if_true: files('mpc8xxx.c')) | 299 | index XXXXXXX..XXXXXXX 100755 |
114 | softmmu_ss.add(when: 'CONFIG_GPIO_KEY', if_true: files('gpio_key.c')) | 300 | --- a/tests/tcg/configure.sh |
115 | +softmmu_ss.add(when: 'CONFIG_GPIO_PWR', if_true: files('gpio_pwr.c')) | 301 | +++ b/tests/tcg/configure.sh |
116 | softmmu_ss.add(when: 'CONFIG_MAX7310', if_true: files('max7310.c')) | 302 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do |
117 | softmmu_ss.add(when: 'CONFIG_PL061', if_true: files('pl061.c')) | 303 | -mbranch-protection=standard -o $TMPE $TMPC; then |
118 | softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c')) | 304 | echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak |
305 | fi | ||
306 | + if do_compiler "$target_compiler" $target_compiler_cflags \ | ||
307 | + -march=armv8.5-a+memtag -o $TMPE $TMPC; then | ||
308 | + echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak | ||
309 | + fi | ||
310 | ;; | ||
311 | esac | ||
312 | |||
119 | -- | 313 | -- |
120 | 2.20.1 | 314 | 2.20.1 |
121 | 315 | ||
122 | 316 | diff view generated by jsdifflib |
1 | Add a simple test of the CMSDK dual timer, since we're about to do | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | some refactoring of how it is clocked. | ||
3 | 2 | ||
3 | This commit implements the single-byte mode of the SMBus. | ||
4 | |||
5 | Each Nuvoton SoC has 16 System Management Bus (SMBus). These buses | ||
6 | compliant with SMBus and I2C protocol. | ||
7 | |||
8 | This patch implements the single-byte mode of the SMBus. In this mode, | ||
9 | the user sends or receives a byte each time. The SMBus device transmits | ||
10 | it to the underlying i2c device and sends an interrupt back to the QEMU | ||
11 | guest. | ||
12 | |||
13 | Reviewed-by: Doug Evans<dje@google.com> | ||
14 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> | ||
15 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
16 | Reviewed-by: Corey Minyard <cminyard@mvista.com> | ||
17 | Message-id: 20210210220426.3577804-2-wuhaotsh@google.com | ||
18 | Acked-by: Corey Minyard <cminyard@mvista.com> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
8 | Message-id: 20210128114145.20536-6-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-6-peter.maydell@linaro.org | ||
10 | --- | 20 | --- |
11 | tests/qtest/cmsdk-apb-dualtimer-test.c | 130 +++++++++++++++++++++++++ | 21 | docs/system/arm/nuvoton.rst | 2 +- |
12 | MAINTAINERS | 1 + | 22 | include/hw/arm/npcm7xx.h | 2 + |
13 | tests/qtest/meson.build | 1 + | 23 | include/hw/i2c/npcm7xx_smbus.h | 88 ++++ |
14 | 3 files changed, 132 insertions(+) | 24 | hw/arm/npcm7xx.c | 68 ++- |
15 | create mode 100644 tests/qtest/cmsdk-apb-dualtimer-test.c | 25 | hw/i2c/npcm7xx_smbus.c | 783 +++++++++++++++++++++++++++++++++ |
26 | hw/i2c/meson.build | 1 + | ||
27 | hw/i2c/trace-events | 11 + | ||
28 | 7 files changed, 938 insertions(+), 17 deletions(-) | ||
29 | create mode 100644 include/hw/i2c/npcm7xx_smbus.h | ||
30 | create mode 100644 hw/i2c/npcm7xx_smbus.c | ||
16 | 31 | ||
17 | diff --git a/tests/qtest/cmsdk-apb-dualtimer-test.c b/tests/qtest/cmsdk-apb-dualtimer-test.c | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/docs/system/arm/nuvoton.rst | ||
35 | +++ b/docs/system/arm/nuvoton.rst | ||
36 | @@ -XXX,XX +XXX,XX @@ Supported devices | ||
37 | * GPIO controller | ||
38 | * Analog to Digital Converter (ADC) | ||
39 | * Pulse Width Modulation (PWM) | ||
40 | + * SMBus controller (SMBF) | ||
41 | |||
42 | Missing devices | ||
43 | --------------- | ||
44 | @@ -XXX,XX +XXX,XX @@ Missing devices | ||
45 | |||
46 | * Ethernet controllers (GMAC and EMC) | ||
47 | * USB device (USBD) | ||
48 | - * SMBus controller (SMBF) | ||
49 | * Peripheral SPI controller (PSPI) | ||
50 | * SD/MMC host | ||
51 | * PECI interface | ||
52 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/include/hw/arm/npcm7xx.h | ||
55 | +++ b/include/hw/arm/npcm7xx.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
57 | #include "hw/adc/npcm7xx_adc.h" | ||
58 | #include "hw/cpu/a9mpcore.h" | ||
59 | #include "hw/gpio/npcm7xx_gpio.h" | ||
60 | +#include "hw/i2c/npcm7xx_smbus.h" | ||
61 | #include "hw/mem/npcm7xx_mc.h" | ||
62 | #include "hw/misc/npcm7xx_clk.h" | ||
63 | #include "hw/misc/npcm7xx_gcr.h" | ||
64 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | ||
65 | NPCM7xxMCState mc; | ||
66 | NPCM7xxRNGState rng; | ||
67 | NPCM7xxGPIOState gpio[8]; | ||
68 | + NPCM7xxSMBusState smbus[16]; | ||
69 | EHCISysBusState ehci; | ||
70 | OHCISysBusState ohci; | ||
71 | NPCM7xxFIUState fiu[2]; | ||
72 | diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h | ||
18 | new file mode 100644 | 73 | new file mode 100644 |
19 | index XXXXXXX..XXXXXXX | 74 | index XXXXXXX..XXXXXXX |
20 | --- /dev/null | 75 | --- /dev/null |
21 | +++ b/tests/qtest/cmsdk-apb-dualtimer-test.c | 76 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
22 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ |
23 | +/* | 78 | +/* |
24 | + * QTest testcase for the CMSDK APB dualtimer device | 79 | + * Nuvoton NPCM7xx SMBus Module. |
25 | + * | 80 | + * |
26 | + * Copyright (c) 2021 Linaro Limited | 81 | + * Copyright 2020 Google LLC |
27 | + * | 82 | + * |
28 | + * This program is free software; you can redistribute it and/or modify it | 83 | + * This program is free software; you can redistribute it and/or modify it |
29 | + * under the terms of the GNU General Public License as published by the | 84 | + * under the terms of the GNU General Public License as published by the |
30 | + * Free Software Foundation; either version 2 of the License, or | 85 | + * Free Software Foundation; either version 2 of the License, or |
31 | + * (at your option) any later version. | 86 | + * (at your option) any later version. |
32 | + * | 87 | + * |
33 | + * This program is distributed in the hope that it will be useful, but WITHOUT | 88 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
34 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 89 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
35 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 90 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
36 | + * for more details. | 91 | + * for more details. |
37 | + */ | 92 | + */ |
93 | +#ifndef NPCM7XX_SMBUS_H | ||
94 | +#define NPCM7XX_SMBUS_H | ||
95 | + | ||
96 | +#include "exec/memory.h" | ||
97 | +#include "hw/i2c/i2c.h" | ||
98 | +#include "hw/irq.h" | ||
99 | +#include "hw/sysbus.h" | ||
100 | + | ||
101 | +/* | ||
102 | + * Number of addresses this module contains. Do not change this without | ||
103 | + * incrementing the version_id in the vmstate. | ||
104 | + */ | ||
105 | +#define NPCM7XX_SMBUS_NR_ADDRS 10 | ||
106 | + | ||
107 | +typedef enum NPCM7xxSMBusStatus { | ||
108 | + NPCM7XX_SMBUS_STATUS_IDLE, | ||
109 | + NPCM7XX_SMBUS_STATUS_SENDING, | ||
110 | + NPCM7XX_SMBUS_STATUS_RECEIVING, | ||
111 | + NPCM7XX_SMBUS_STATUS_NEGACK, | ||
112 | + NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE, | ||
113 | + NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK, | ||
114 | +} NPCM7xxSMBusStatus; | ||
115 | + | ||
116 | +/* | ||
117 | + * struct NPCM7xxSMBusState - System Management Bus device state. | ||
118 | + * @bus: The underlying I2C Bus. | ||
119 | + * @irq: GIC interrupt line to fire on events (if enabled). | ||
120 | + * @sda: The serial data register. | ||
121 | + * @st: The status register. | ||
122 | + * @cst: The control status register. | ||
123 | + * @cst2: The control status register 2. | ||
124 | + * @cst3: The control status register 3. | ||
125 | + * @ctl1: The control register 1. | ||
126 | + * @ctl2: The control register 2. | ||
127 | + * @ctl3: The control register 3. | ||
128 | + * @ctl4: The control register 4. | ||
129 | + * @ctl5: The control register 5. | ||
130 | + * @addr: The SMBus module's own addresses on the I2C bus. | ||
131 | + * @scllt: The SCL low time register. | ||
132 | + * @sclht: The SCL high time register. | ||
133 | + * @status: The current status of the SMBus. | ||
134 | + */ | ||
135 | +typedef struct NPCM7xxSMBusState { | ||
136 | + SysBusDevice parent; | ||
137 | + | ||
138 | + MemoryRegion iomem; | ||
139 | + | ||
140 | + I2CBus *bus; | ||
141 | + qemu_irq irq; | ||
142 | + | ||
143 | + uint8_t sda; | ||
144 | + uint8_t st; | ||
145 | + uint8_t cst; | ||
146 | + uint8_t cst2; | ||
147 | + uint8_t cst3; | ||
148 | + uint8_t ctl1; | ||
149 | + uint8_t ctl2; | ||
150 | + uint8_t ctl3; | ||
151 | + uint8_t ctl4; | ||
152 | + uint8_t ctl5; | ||
153 | + uint8_t addr[NPCM7XX_SMBUS_NR_ADDRS]; | ||
154 | + | ||
155 | + uint8_t scllt; | ||
156 | + uint8_t sclht; | ||
157 | + | ||
158 | + NPCM7xxSMBusStatus status; | ||
159 | +} NPCM7xxSMBusState; | ||
160 | + | ||
161 | +#define TYPE_NPCM7XX_SMBUS "npcm7xx-smbus" | ||
162 | +#define NPCM7XX_SMBUS(obj) OBJECT_CHECK(NPCM7xxSMBusState, (obj), \ | ||
163 | + TYPE_NPCM7XX_SMBUS) | ||
164 | + | ||
165 | +#endif /* NPCM7XX_SMBUS_H */ | ||
166 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
167 | index XXXXXXX..XXXXXXX 100644 | ||
168 | --- a/hw/arm/npcm7xx.c | ||
169 | +++ b/hw/arm/npcm7xx.c | ||
170 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
171 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
172 | NPCM7XX_EHCI_IRQ = 61, | ||
173 | NPCM7XX_OHCI_IRQ = 62, | ||
174 | + NPCM7XX_SMBUS0_IRQ = 64, | ||
175 | + NPCM7XX_SMBUS1_IRQ, | ||
176 | + NPCM7XX_SMBUS2_IRQ, | ||
177 | + NPCM7XX_SMBUS3_IRQ, | ||
178 | + NPCM7XX_SMBUS4_IRQ, | ||
179 | + NPCM7XX_SMBUS5_IRQ, | ||
180 | + NPCM7XX_SMBUS6_IRQ, | ||
181 | + NPCM7XX_SMBUS7_IRQ, | ||
182 | + NPCM7XX_SMBUS8_IRQ, | ||
183 | + NPCM7XX_SMBUS9_IRQ, | ||
184 | + NPCM7XX_SMBUS10_IRQ, | ||
185 | + NPCM7XX_SMBUS11_IRQ, | ||
186 | + NPCM7XX_SMBUS12_IRQ, | ||
187 | + NPCM7XX_SMBUS13_IRQ, | ||
188 | + NPCM7XX_SMBUS14_IRQ, | ||
189 | + NPCM7XX_SMBUS15_IRQ, | ||
190 | NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ | ||
191 | NPCM7XX_PWM1_IRQ, /* PWM module 1 */ | ||
192 | NPCM7XX_GPIO0_IRQ = 116, | ||
193 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_pwm_addr[] = { | ||
194 | 0xf0104000, | ||
195 | }; | ||
196 | |||
197 | +/* Direct memory-mapped access to each SMBus Module. */ | ||
198 | +static const hwaddr npcm7xx_smbus_addr[] = { | ||
199 | + 0xf0080000, | ||
200 | + 0xf0081000, | ||
201 | + 0xf0082000, | ||
202 | + 0xf0083000, | ||
203 | + 0xf0084000, | ||
204 | + 0xf0085000, | ||
205 | + 0xf0086000, | ||
206 | + 0xf0087000, | ||
207 | + 0xf0088000, | ||
208 | + 0xf0089000, | ||
209 | + 0xf008a000, | ||
210 | + 0xf008b000, | ||
211 | + 0xf008c000, | ||
212 | + 0xf008d000, | ||
213 | + 0xf008e000, | ||
214 | + 0xf008f000, | ||
215 | +}; | ||
216 | + | ||
217 | static const struct { | ||
218 | hwaddr regs_addr; | ||
219 | uint32_t unconnected_pins; | ||
220 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
221 | object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); | ||
222 | } | ||
223 | |||
224 | + for (i = 0; i < ARRAY_SIZE(s->smbus); i++) { | ||
225 | + object_initialize_child(obj, "smbus[*]", &s->smbus[i], | ||
226 | + TYPE_NPCM7XX_SMBUS); | ||
227 | + } | ||
228 | + | ||
229 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
230 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
231 | |||
232 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
233 | npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i)); | ||
234 | } | ||
235 | |||
236 | + /* SMBus modules. Cannot fail. */ | ||
237 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_smbus_addr) != ARRAY_SIZE(s->smbus)); | ||
238 | + for (i = 0; i < ARRAY_SIZE(s->smbus); i++) { | ||
239 | + Object *obj = OBJECT(&s->smbus[i]); | ||
240 | + | ||
241 | + sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort); | ||
242 | + sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_smbus_addr[i]); | ||
243 | + sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, | ||
244 | + npcm7xx_irq(s, NPCM7XX_SMBUS0_IRQ + i)); | ||
245 | + } | ||
246 | + | ||
247 | /* USB Host */ | ||
248 | object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
249 | &error_abort); | ||
250 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
251 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | ||
252 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | ||
253 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | ||
254 | - create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB); | ||
255 | - create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * KiB); | ||
256 | - create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * KiB); | ||
257 | - create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * KiB); | ||
258 | - create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * KiB); | ||
259 | - create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * KiB); | ||
260 | - create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * KiB); | ||
261 | - create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * KiB); | ||
262 | - create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * KiB); | ||
263 | - create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * KiB); | ||
264 | - create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * KiB); | ||
265 | - create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * KiB); | ||
266 | - create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * KiB); | ||
267 | - create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * KiB); | ||
268 | - create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * KiB); | ||
269 | - create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * KiB); | ||
270 | create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * KiB); | ||
271 | create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB); | ||
272 | create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB); | ||
273 | diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c | ||
274 | new file mode 100644 | ||
275 | index XXXXXXX..XXXXXXX | ||
276 | --- /dev/null | ||
277 | +++ b/hw/i2c/npcm7xx_smbus.c | ||
278 | @@ -XXX,XX +XXX,XX @@ | ||
279 | +/* | ||
280 | + * Nuvoton NPCM7xx SMBus Module. | ||
281 | + * | ||
282 | + * Copyright 2020 Google LLC | ||
283 | + * | ||
284 | + * This program is free software; you can redistribute it and/or modify it | ||
285 | + * under the terms of the GNU General Public License as published by the | ||
286 | + * Free Software Foundation; either version 2 of the License, or | ||
287 | + * (at your option) any later version. | ||
288 | + * | ||
289 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
290 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
291 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
292 | + * for more details. | ||
293 | + */ | ||
38 | + | 294 | + |
39 | +#include "qemu/osdep.h" | 295 | +#include "qemu/osdep.h" |
40 | +#include "libqtest-single.h" | 296 | + |
41 | + | 297 | +#include "hw/i2c/npcm7xx_smbus.h" |
42 | +/* IoTKit/ARMSSE dualtimer; driven at 25MHz in mps2-an385, so 40ns per tick */ | 298 | +#include "migration/vmstate.h" |
43 | +#define TIMER_BASE 0x40002000 | 299 | +#include "qemu/bitops.h" |
44 | + | 300 | +#include "qemu/guest-random.h" |
45 | +#define TIMER1LOAD 0 | 301 | +#include "qemu/log.h" |
46 | +#define TIMER1VALUE 4 | 302 | +#include "qemu/module.h" |
47 | +#define TIMER1CONTROL 8 | 303 | +#include "qemu/units.h" |
48 | +#define TIMER1INTCLR 0xc | 304 | + |
49 | +#define TIMER1RIS 0x10 | 305 | +#include "trace.h" |
50 | +#define TIMER1MIS 0x14 | 306 | + |
51 | +#define TIMER1BGLOAD 0x18 | 307 | +enum NPCM7xxSMBusCommonRegister { |
52 | + | 308 | + NPCM7XX_SMB_SDA = 0x0, |
53 | +#define TIMER2LOAD 0x20 | 309 | + NPCM7XX_SMB_ST = 0x2, |
54 | +#define TIMER2VALUE 0x24 | 310 | + NPCM7XX_SMB_CST = 0x4, |
55 | +#define TIMER2CONTROL 0x28 | 311 | + NPCM7XX_SMB_CTL1 = 0x6, |
56 | +#define TIMER2INTCLR 0x2c | 312 | + NPCM7XX_SMB_ADDR1 = 0x8, |
57 | +#define TIMER2RIS 0x30 | 313 | + NPCM7XX_SMB_CTL2 = 0xa, |
58 | +#define TIMER2MIS 0x34 | 314 | + NPCM7XX_SMB_ADDR2 = 0xc, |
59 | +#define TIMER2BGLOAD 0x38 | 315 | + NPCM7XX_SMB_CTL3 = 0xe, |
60 | + | 316 | + NPCM7XX_SMB_CST2 = 0x18, |
61 | +#define CTRL_ENABLE (1 << 7) | 317 | + NPCM7XX_SMB_CST3 = 0x19, |
62 | +#define CTRL_PERIODIC (1 << 6) | 318 | + NPCM7XX_SMB_VER = 0x1f, |
63 | +#define CTRL_INTEN (1 << 5) | 319 | +}; |
64 | +#define CTRL_PRESCALE_1 (0 << 2) | 320 | + |
65 | +#define CTRL_PRESCALE_16 (1 << 2) | 321 | +enum NPCM7xxSMBusBank0Register { |
66 | +#define CTRL_PRESCALE_256 (2 << 2) | 322 | + NPCM7XX_SMB_ADDR3 = 0x10, |
67 | +#define CTRL_32BIT (1 << 1) | 323 | + NPCM7XX_SMB_ADDR7 = 0x11, |
68 | +#define CTRL_ONESHOT (1 << 0) | 324 | + NPCM7XX_SMB_ADDR4 = 0x12, |
69 | + | 325 | + NPCM7XX_SMB_ADDR8 = 0x13, |
70 | +static void test_dualtimer(void) | 326 | + NPCM7XX_SMB_ADDR5 = 0x14, |
71 | +{ | 327 | + NPCM7XX_SMB_ADDR9 = 0x15, |
72 | + g_assert_true(readl(TIMER_BASE + TIMER1RIS) == 0); | 328 | + NPCM7XX_SMB_ADDR6 = 0x16, |
73 | + | 329 | + NPCM7XX_SMB_ADDR10 = 0x17, |
74 | + /* Start timer: will fire after 40000 ns */ | 330 | + NPCM7XX_SMB_CTL4 = 0x1a, |
75 | + writel(TIMER_BASE + TIMER1LOAD, 1000); | 331 | + NPCM7XX_SMB_CTL5 = 0x1b, |
76 | + /* enable in free-running, wrapping, interrupt mode */ | 332 | + NPCM7XX_SMB_SCLLT = 0x1c, |
77 | + writel(TIMER_BASE + TIMER1CONTROL, CTRL_ENABLE | CTRL_INTEN); | 333 | + NPCM7XX_SMB_FIF_CTL = 0x1d, |
78 | + | 334 | + NPCM7XX_SMB_SCLHT = 0x1e, |
79 | + /* Step to just past the 500th tick and check VALUE */ | 335 | +}; |
80 | + clock_step(500 * 40 + 1); | 336 | + |
81 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); | 337 | +enum NPCM7xxSMBusBank1Register { |
82 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 500); | 338 | + NPCM7XX_SMB_FIF_CTS = 0x10, |
83 | + | 339 | + NPCM7XX_SMB_FAIR_PER = 0x11, |
84 | + /* Just past the 1000th tick: timer should have fired */ | 340 | + NPCM7XX_SMB_TXF_CTL = 0x12, |
85 | + clock_step(500 * 40); | 341 | + NPCM7XX_SMB_T_OUT = 0x14, |
86 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 1); | 342 | + NPCM7XX_SMB_TXF_STS = 0x1a, |
87 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0); | 343 | + NPCM7XX_SMB_RXF_STS = 0x1c, |
88 | + | 344 | + NPCM7XX_SMB_RXF_CTL = 0x1e, |
345 | +}; | ||
346 | + | ||
347 | +/* ST fields */ | ||
348 | +#define NPCM7XX_SMBST_STP BIT(7) | ||
349 | +#define NPCM7XX_SMBST_SDAST BIT(6) | ||
350 | +#define NPCM7XX_SMBST_BER BIT(5) | ||
351 | +#define NPCM7XX_SMBST_NEGACK BIT(4) | ||
352 | +#define NPCM7XX_SMBST_STASTR BIT(3) | ||
353 | +#define NPCM7XX_SMBST_NMATCH BIT(2) | ||
354 | +#define NPCM7XX_SMBST_MODE BIT(1) | ||
355 | +#define NPCM7XX_SMBST_XMIT BIT(0) | ||
356 | + | ||
357 | +/* CST fields */ | ||
358 | +#define NPCM7XX_SMBCST_ARPMATCH BIT(7) | ||
359 | +#define NPCM7XX_SMBCST_MATCHAF BIT(6) | ||
360 | +#define NPCM7XX_SMBCST_TGSCL BIT(5) | ||
361 | +#define NPCM7XX_SMBCST_TSDA BIT(4) | ||
362 | +#define NPCM7XX_SMBCST_GCMATCH BIT(3) | ||
363 | +#define NPCM7XX_SMBCST_MATCH BIT(2) | ||
364 | +#define NPCM7XX_SMBCST_BB BIT(1) | ||
365 | +#define NPCM7XX_SMBCST_BUSY BIT(0) | ||
366 | + | ||
367 | +/* CST2 fields */ | ||
368 | +#define NPCM7XX_SMBCST2_INTSTS BIT(7) | ||
369 | +#define NPCM7XX_SMBCST2_MATCH7F BIT(6) | ||
370 | +#define NPCM7XX_SMBCST2_MATCH6F BIT(5) | ||
371 | +#define NPCM7XX_SMBCST2_MATCH5F BIT(4) | ||
372 | +#define NPCM7XX_SMBCST2_MATCH4F BIT(3) | ||
373 | +#define NPCM7XX_SMBCST2_MATCH3F BIT(2) | ||
374 | +#define NPCM7XX_SMBCST2_MATCH2F BIT(1) | ||
375 | +#define NPCM7XX_SMBCST2_MATCH1F BIT(0) | ||
376 | + | ||
377 | +/* CST3 fields */ | ||
378 | +#define NPCM7XX_SMBCST3_EO_BUSY BIT(7) | ||
379 | +#define NPCM7XX_SMBCST3_MATCH10F BIT(2) | ||
380 | +#define NPCM7XX_SMBCST3_MATCH9F BIT(1) | ||
381 | +#define NPCM7XX_SMBCST3_MATCH8F BIT(0) | ||
382 | + | ||
383 | +/* CTL1 fields */ | ||
384 | +#define NPCM7XX_SMBCTL1_STASTRE BIT(7) | ||
385 | +#define NPCM7XX_SMBCTL1_NMINTE BIT(6) | ||
386 | +#define NPCM7XX_SMBCTL1_GCMEN BIT(5) | ||
387 | +#define NPCM7XX_SMBCTL1_ACK BIT(4) | ||
388 | +#define NPCM7XX_SMBCTL1_EOBINTE BIT(3) | ||
389 | +#define NPCM7XX_SMBCTL1_INTEN BIT(2) | ||
390 | +#define NPCM7XX_SMBCTL1_STOP BIT(1) | ||
391 | +#define NPCM7XX_SMBCTL1_START BIT(0) | ||
392 | + | ||
393 | +/* CTL2 fields */ | ||
394 | +#define NPCM7XX_SMBCTL2_SCLFRQ(rv) extract8((rv), 1, 6) | ||
395 | +#define NPCM7XX_SMBCTL2_ENABLE BIT(0) | ||
396 | + | ||
397 | +/* CTL3 fields */ | ||
398 | +#define NPCM7XX_SMBCTL3_SCL_LVL BIT(7) | ||
399 | +#define NPCM7XX_SMBCTL3_SDA_LVL BIT(6) | ||
400 | +#define NPCM7XX_SMBCTL3_BNK_SEL BIT(5) | ||
401 | +#define NPCM7XX_SMBCTL3_400K_MODE BIT(4) | ||
402 | +#define NPCM7XX_SMBCTL3_IDL_START BIT(3) | ||
403 | +#define NPCM7XX_SMBCTL3_ARPMEN BIT(2) | ||
404 | +#define NPCM7XX_SMBCTL3_SCLFRQ(rv) extract8((rv), 0, 2) | ||
405 | + | ||
406 | +/* ADDR fields */ | ||
407 | +#define NPCM7XX_ADDR_EN BIT(7) | ||
408 | +#define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6) | ||
409 | + | ||
410 | +#define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b))) | ||
411 | +#define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o)) | ||
412 | + | ||
413 | +#define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE) | ||
414 | + | ||
415 | +/* VERSION fields values, read-only. */ | ||
416 | +#define NPCM7XX_SMBUS_VERSION_NUMBER 1 | ||
417 | +#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0 | ||
418 | + | ||
419 | +/* Reset values */ | ||
420 | +#define NPCM7XX_SMB_ST_INIT_VAL 0x00 | ||
421 | +#define NPCM7XX_SMB_CST_INIT_VAL 0x10 | ||
422 | +#define NPCM7XX_SMB_CST2_INIT_VAL 0x00 | ||
423 | +#define NPCM7XX_SMB_CST3_INIT_VAL 0x00 | ||
424 | +#define NPCM7XX_SMB_CTL1_INIT_VAL 0x00 | ||
425 | +#define NPCM7XX_SMB_CTL2_INIT_VAL 0x00 | ||
426 | +#define NPCM7XX_SMB_CTL3_INIT_VAL 0xc0 | ||
427 | +#define NPCM7XX_SMB_CTL4_INIT_VAL 0x07 | ||
428 | +#define NPCM7XX_SMB_CTL5_INIT_VAL 0x00 | ||
429 | +#define NPCM7XX_SMB_ADDR_INIT_VAL 0x00 | ||
430 | +#define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00 | ||
431 | +#define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00 | ||
432 | + | ||
433 | +static uint8_t npcm7xx_smbus_get_version(void) | ||
434 | +{ | ||
435 | + return NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED << 7 | | ||
436 | + NPCM7XX_SMBUS_VERSION_NUMBER; | ||
437 | +} | ||
438 | + | ||
439 | +static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s) | ||
440 | +{ | ||
441 | + int level; | ||
442 | + | ||
443 | + if (s->ctl1 & NPCM7XX_SMBCTL1_INTEN) { | ||
444 | + level = !!((s->ctl1 & NPCM7XX_SMBCTL1_NMINTE && | ||
445 | + s->st & NPCM7XX_SMBST_NMATCH) || | ||
446 | + (s->st & NPCM7XX_SMBST_BER) || | ||
447 | + (s->st & NPCM7XX_SMBST_NEGACK) || | ||
448 | + (s->st & NPCM7XX_SMBST_SDAST) || | ||
449 | + (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE && | ||
450 | + s->st & NPCM7XX_SMBST_SDAST) || | ||
451 | + (s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE && | ||
452 | + s->cst3 & NPCM7XX_SMBCST3_EO_BUSY)); | ||
453 | + | ||
454 | + if (level) { | ||
455 | + s->cst2 |= NPCM7XX_SMBCST2_INTSTS; | ||
456 | + } else { | ||
457 | + s->cst2 &= ~NPCM7XX_SMBCST2_INTSTS; | ||
458 | + } | ||
459 | + qemu_set_irq(s->irq, level); | ||
460 | + } | ||
461 | +} | ||
462 | + | ||
463 | +static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s) | ||
464 | +{ | ||
465 | + s->st &= ~NPCM7XX_SMBST_SDAST; | ||
466 | + s->st |= NPCM7XX_SMBST_NEGACK; | ||
467 | + s->status = NPCM7XX_SMBUS_STATUS_NEGACK; | ||
468 | +} | ||
469 | + | ||
470 | +static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) | ||
471 | +{ | ||
472 | + int rv = i2c_send(s->bus, value); | ||
473 | + | ||
474 | + if (rv) { | ||
475 | + npcm7xx_smbus_nack(s); | ||
476 | + } else { | ||
477 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
478 | + } | ||
479 | + trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv); | ||
480 | + npcm7xx_smbus_update_irq(s); | ||
481 | +} | ||
482 | + | ||
483 | +static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s) | ||
484 | +{ | ||
485 | + s->sda = i2c_recv(s->bus); | ||
486 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
487 | + if (s->st & NPCM7XX_SMBCTL1_ACK) { | ||
488 | + trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path); | ||
489 | + i2c_nack(s->bus); | ||
490 | + s->st &= NPCM7XX_SMBCTL1_ACK; | ||
491 | + } | ||
492 | + trace_npcm7xx_smbus_recv_byte((DEVICE(s)->canonical_path), s->sda); | ||
493 | + npcm7xx_smbus_update_irq(s); | ||
494 | +} | ||
495 | + | ||
496 | +static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) | ||
497 | +{ | ||
89 | + /* | 498 | + /* |
90 | + * We are in free-running wrapping 16-bit mode, so on the following | 499 | + * We can start the bus if one of these is true: |
91 | + * tick VALUE should have wrapped round to 0xffff. | 500 | + * 1. The bus is idle (so we can request it) |
501 | + * 2. We are the occupier (it's a repeated start condition.) | ||
92 | + */ | 502 | + */ |
93 | + clock_step(40); | 503 | + int available = !i2c_bus_busy(s->bus) || |
94 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1VALUE), ==, 0xffff); | 504 | + s->status != NPCM7XX_SMBUS_STATUS_IDLE; |
95 | + | 505 | + |
96 | + /* Check that any write to INTCLR clears interrupt */ | 506 | + if (available) { |
97 | + writel(TIMER_BASE + TIMER1INTCLR, 1); | 507 | + s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST; |
98 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER1RIS), ==, 0); | 508 | + s->cst |= NPCM7XX_SMBCST_BUSY; |
99 | + | 509 | + } else { |
100 | + /* Turn off the timer */ | 510 | + s->st &= ~NPCM7XX_SMBST_MODE; |
101 | + writel(TIMER_BASE + TIMER1CONTROL, 0); | 511 | + s->cst &= ~NPCM7XX_SMBCST_BUSY; |
102 | +} | 512 | + s->st |= NPCM7XX_SMBST_BER; |
103 | + | 513 | + } |
104 | +static void test_prescale(void) | 514 | + |
105 | +{ | 515 | + trace_npcm7xx_smbus_start(DEVICE(s)->canonical_path, available); |
106 | + g_assert_true(readl(TIMER_BASE + TIMER2RIS) == 0); | 516 | + s->cst |= NPCM7XX_SMBCST_BB; |
107 | + | 517 | + s->status = NPCM7XX_SMBUS_STATUS_IDLE; |
108 | + /* Start timer: will fire after 40 * 256 * 1000 == 1024000 ns */ | 518 | + npcm7xx_smbus_update_irq(s); |
109 | + writel(TIMER_BASE + TIMER2LOAD, 1000); | 519 | +} |
110 | + /* enable in periodic, wrapping, interrupt mode, prescale 256 */ | 520 | + |
111 | + writel(TIMER_BASE + TIMER2CONTROL, | 521 | +static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value) |
112 | + CTRL_ENABLE | CTRL_INTEN | CTRL_PERIODIC | CTRL_PRESCALE_256); | 522 | +{ |
113 | + | 523 | + int recv; |
114 | + /* Step to just past the 500th tick and check VALUE */ | 524 | + int rv; |
115 | + clock_step(40 * 256 * 501); | 525 | + |
116 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); | 526 | + recv = value & BIT(0); |
117 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 500); | 527 | + rv = i2c_start_transfer(s->bus, value >> 1, recv); |
118 | + | 528 | + trace_npcm7xx_smbus_send_address(DEVICE(s)->canonical_path, |
119 | + /* Just past the 1000th tick: timer should have fired */ | 529 | + value >> 1, recv, !rv); |
120 | + clock_step(40 * 256 * 500); | 530 | + if (rv) { |
121 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 1); | 531 | + qemu_log_mask(LOG_GUEST_ERROR, |
122 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 0); | 532 | + "%s: requesting i2c bus for 0x%02x failed: %d\n", |
123 | + | 533 | + DEVICE(s)->canonical_path, value, rv); |
124 | + /* In periodic mode the tick VALUE now reloads */ | 534 | + /* Failed to start transfer. NACK to reject.*/ |
125 | + clock_step(40 * 256); | 535 | + if (recv) { |
126 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2VALUE), ==, 1000); | 536 | + s->st &= ~NPCM7XX_SMBST_XMIT; |
127 | + | 537 | + } else { |
128 | + /* Check that any write to INTCLR clears interrupt */ | 538 | + s->st |= NPCM7XX_SMBST_XMIT; |
129 | + writel(TIMER_BASE + TIMER2INTCLR, 1); | 539 | + } |
130 | + g_assert_cmpuint(readl(TIMER_BASE + TIMER2RIS), ==, 0); | 540 | + npcm7xx_smbus_nack(s); |
131 | + | 541 | + npcm7xx_smbus_update_irq(s); |
132 | + /* Turn off the timer */ | 542 | + return; |
133 | + writel(TIMER_BASE + TIMER2CONTROL, 0); | 543 | + } |
134 | +} | 544 | + |
135 | + | 545 | + s->st &= ~NPCM7XX_SMBST_NEGACK; |
136 | +int main(int argc, char **argv) | 546 | + if (recv) { |
137 | +{ | 547 | + s->status = NPCM7XX_SMBUS_STATUS_RECEIVING; |
138 | + int r; | 548 | + s->st &= ~NPCM7XX_SMBST_XMIT; |
139 | + | 549 | + } else { |
140 | + g_test_init(&argc, &argv, NULL); | 550 | + s->status = NPCM7XX_SMBUS_STATUS_SENDING; |
141 | + | 551 | + s->st |= NPCM7XX_SMBST_XMIT; |
142 | + qtest_start("-machine mps2-an385"); | 552 | + } |
143 | + | 553 | + |
144 | + qtest_add_func("/cmsdk-apb-dualtimer/dualtimer", test_dualtimer); | 554 | + if (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE) { |
145 | + qtest_add_func("/cmsdk-apb-dualtimer/prescale", test_prescale); | 555 | + s->st |= NPCM7XX_SMBST_STASTR; |
146 | + | 556 | + if (!recv) { |
147 | + r = g_test_run(); | 557 | + s->st |= NPCM7XX_SMBST_SDAST; |
148 | + | 558 | + } |
149 | + qtest_end(); | 559 | + } else if (recv) { |
150 | + | 560 | + npcm7xx_smbus_recv_byte(s); |
151 | + return r; | 561 | + } |
152 | +} | 562 | + npcm7xx_smbus_update_irq(s); |
153 | diff --git a/MAINTAINERS b/MAINTAINERS | 563 | +} |
564 | + | ||
565 | +static void npcm7xx_smbus_execute_stop(NPCM7xxSMBusState *s) | ||
566 | +{ | ||
567 | + i2c_end_transfer(s->bus); | ||
568 | + s->st = 0; | ||
569 | + s->cst = 0; | ||
570 | + s->status = NPCM7XX_SMBUS_STATUS_IDLE; | ||
571 | + s->cst3 |= NPCM7XX_SMBCST3_EO_BUSY; | ||
572 | + trace_npcm7xx_smbus_stop(DEVICE(s)->canonical_path); | ||
573 | + npcm7xx_smbus_update_irq(s); | ||
574 | +} | ||
575 | + | ||
576 | + | ||
577 | +static void npcm7xx_smbus_stop(NPCM7xxSMBusState *s) | ||
578 | +{ | ||
579 | + if (s->st & NPCM7XX_SMBST_MODE) { | ||
580 | + switch (s->status) { | ||
581 | + case NPCM7XX_SMBUS_STATUS_RECEIVING: | ||
582 | + case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE: | ||
583 | + s->status = NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE; | ||
584 | + break; | ||
585 | + | ||
586 | + case NPCM7XX_SMBUS_STATUS_NEGACK: | ||
587 | + s->status = NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK; | ||
588 | + break; | ||
589 | + | ||
590 | + default: | ||
591 | + npcm7xx_smbus_execute_stop(s); | ||
592 | + break; | ||
593 | + } | ||
594 | + } | ||
595 | +} | ||
596 | + | ||
597 | +static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s) | ||
598 | +{ | ||
599 | + uint8_t value = s->sda; | ||
600 | + | ||
601 | + switch (s->status) { | ||
602 | + case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE: | ||
603 | + npcm7xx_smbus_execute_stop(s); | ||
604 | + break; | ||
605 | + | ||
606 | + case NPCM7XX_SMBUS_STATUS_RECEIVING: | ||
607 | + npcm7xx_smbus_recv_byte(s); | ||
608 | + break; | ||
609 | + | ||
610 | + default: | ||
611 | + /* Do nothing */ | ||
612 | + break; | ||
613 | + } | ||
614 | + | ||
615 | + return value; | ||
616 | +} | ||
617 | + | ||
618 | +static void npcm7xx_smbus_write_sda(NPCM7xxSMBusState *s, uint8_t value) | ||
619 | +{ | ||
620 | + s->sda = value; | ||
621 | + if (s->st & NPCM7XX_SMBST_MODE) { | ||
622 | + switch (s->status) { | ||
623 | + case NPCM7XX_SMBUS_STATUS_IDLE: | ||
624 | + npcm7xx_smbus_send_address(s, value); | ||
625 | + break; | ||
626 | + case NPCM7XX_SMBUS_STATUS_SENDING: | ||
627 | + npcm7xx_smbus_send_byte(s, value); | ||
628 | + break; | ||
629 | + default: | ||
630 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
631 | + "%s: write to SDA in invalid status %d: %u\n", | ||
632 | + DEVICE(s)->canonical_path, s->status, value); | ||
633 | + break; | ||
634 | + } | ||
635 | + } | ||
636 | +} | ||
637 | + | ||
638 | +static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value) | ||
639 | +{ | ||
640 | + s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_STP); | ||
641 | + s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_BER); | ||
642 | + s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_STASTR); | ||
643 | + s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_NMATCH); | ||
644 | + | ||
645 | + if (value & NPCM7XX_SMBST_NEGACK) { | ||
646 | + s->st &= ~NPCM7XX_SMBST_NEGACK; | ||
647 | + if (s->status == NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK) { | ||
648 | + npcm7xx_smbus_execute_stop(s); | ||
649 | + } | ||
650 | + } | ||
651 | + | ||
652 | + if (value & NPCM7XX_SMBST_STASTR && | ||
653 | + s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
654 | + npcm7xx_smbus_recv_byte(s); | ||
655 | + } | ||
656 | + | ||
657 | + npcm7xx_smbus_update_irq(s); | ||
658 | +} | ||
659 | + | ||
660 | +static void npcm7xx_smbus_write_cst(NPCM7xxSMBusState *s, uint8_t value) | ||
661 | +{ | ||
662 | + uint8_t new_value = s->cst; | ||
663 | + | ||
664 | + s->cst = WRITE_ONE_CLEAR(new_value, value, NPCM7XX_SMBCST_BB); | ||
665 | + npcm7xx_smbus_update_irq(s); | ||
666 | +} | ||
667 | + | ||
668 | +static void npcm7xx_smbus_write_cst3(NPCM7xxSMBusState *s, uint8_t value) | ||
669 | +{ | ||
670 | + s->cst3 = WRITE_ONE_CLEAR(s->cst3, value, NPCM7XX_SMBCST3_EO_BUSY); | ||
671 | + npcm7xx_smbus_update_irq(s); | ||
672 | +} | ||
673 | + | ||
674 | +static void npcm7xx_smbus_write_ctl1(NPCM7xxSMBusState *s, uint8_t value) | ||
675 | +{ | ||
676 | + s->ctl1 = KEEP_OLD_BIT(s->ctl1, value, | ||
677 | + NPCM7XX_SMBCTL1_START | NPCM7XX_SMBCTL1_STOP | NPCM7XX_SMBCTL1_ACK); | ||
678 | + | ||
679 | + if (value & NPCM7XX_SMBCTL1_START) { | ||
680 | + npcm7xx_smbus_start(s); | ||
681 | + } | ||
682 | + | ||
683 | + if (value & NPCM7XX_SMBCTL1_STOP) { | ||
684 | + npcm7xx_smbus_stop(s); | ||
685 | + } | ||
686 | + | ||
687 | + npcm7xx_smbus_update_irq(s); | ||
688 | +} | ||
689 | + | ||
690 | +static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value) | ||
691 | +{ | ||
692 | + s->ctl2 = value; | ||
693 | + | ||
694 | + if (!NPCM7XX_SMBUS_ENABLED(s)) { | ||
695 | + /* Disable this SMBus module. */ | ||
696 | + s->ctl1 = 0; | ||
697 | + s->st = 0; | ||
698 | + s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY); | ||
699 | + s->cst = 0; | ||
700 | + } | ||
701 | +} | ||
702 | + | ||
703 | +static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value) | ||
704 | +{ | ||
705 | + uint8_t old_ctl3 = s->ctl3; | ||
706 | + | ||
707 | + /* Write to SDA and SCL bits are ignored. */ | ||
708 | + s->ctl3 = KEEP_OLD_BIT(old_ctl3, value, | ||
709 | + NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL); | ||
710 | +} | ||
711 | + | ||
712 | +static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
713 | +{ | ||
714 | + NPCM7xxSMBusState *s = opaque; | ||
715 | + uint64_t value = 0; | ||
716 | + uint8_t bank = s->ctl3 & NPCM7XX_SMBCTL3_BNK_SEL; | ||
717 | + | ||
718 | + /* The order of the registers are their order in memory. */ | ||
719 | + switch (offset) { | ||
720 | + case NPCM7XX_SMB_SDA: | ||
721 | + value = npcm7xx_smbus_read_sda(s); | ||
722 | + break; | ||
723 | + | ||
724 | + case NPCM7XX_SMB_ST: | ||
725 | + value = s->st; | ||
726 | + break; | ||
727 | + | ||
728 | + case NPCM7XX_SMB_CST: | ||
729 | + value = s->cst; | ||
730 | + break; | ||
731 | + | ||
732 | + case NPCM7XX_SMB_CTL1: | ||
733 | + value = s->ctl1; | ||
734 | + break; | ||
735 | + | ||
736 | + case NPCM7XX_SMB_ADDR1: | ||
737 | + value = s->addr[0]; | ||
738 | + break; | ||
739 | + | ||
740 | + case NPCM7XX_SMB_CTL2: | ||
741 | + value = s->ctl2; | ||
742 | + break; | ||
743 | + | ||
744 | + case NPCM7XX_SMB_ADDR2: | ||
745 | + value = s->addr[1]; | ||
746 | + break; | ||
747 | + | ||
748 | + case NPCM7XX_SMB_CTL3: | ||
749 | + value = s->ctl3; | ||
750 | + break; | ||
751 | + | ||
752 | + case NPCM7XX_SMB_CST2: | ||
753 | + value = s->cst2; | ||
754 | + break; | ||
755 | + | ||
756 | + case NPCM7XX_SMB_CST3: | ||
757 | + value = s->cst3; | ||
758 | + break; | ||
759 | + | ||
760 | + case NPCM7XX_SMB_VER: | ||
761 | + value = npcm7xx_smbus_get_version(); | ||
762 | + break; | ||
763 | + | ||
764 | + /* This register is either invalid or banked at this point. */ | ||
765 | + default: | ||
766 | + if (bank) { | ||
767 | + /* Bank 1 */ | ||
768 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
769 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
770 | + DEVICE(s)->canonical_path, offset); | ||
771 | + } else { | ||
772 | + /* Bank 0 */ | ||
773 | + switch (offset) { | ||
774 | + case NPCM7XX_SMB_ADDR3: | ||
775 | + value = s->addr[2]; | ||
776 | + break; | ||
777 | + | ||
778 | + case NPCM7XX_SMB_ADDR7: | ||
779 | + value = s->addr[6]; | ||
780 | + break; | ||
781 | + | ||
782 | + case NPCM7XX_SMB_ADDR4: | ||
783 | + value = s->addr[3]; | ||
784 | + break; | ||
785 | + | ||
786 | + case NPCM7XX_SMB_ADDR8: | ||
787 | + value = s->addr[7]; | ||
788 | + break; | ||
789 | + | ||
790 | + case NPCM7XX_SMB_ADDR5: | ||
791 | + value = s->addr[4]; | ||
792 | + break; | ||
793 | + | ||
794 | + case NPCM7XX_SMB_ADDR9: | ||
795 | + value = s->addr[8]; | ||
796 | + break; | ||
797 | + | ||
798 | + case NPCM7XX_SMB_ADDR6: | ||
799 | + value = s->addr[5]; | ||
800 | + break; | ||
801 | + | ||
802 | + case NPCM7XX_SMB_ADDR10: | ||
803 | + value = s->addr[9]; | ||
804 | + break; | ||
805 | + | ||
806 | + case NPCM7XX_SMB_CTL4: | ||
807 | + value = s->ctl4; | ||
808 | + break; | ||
809 | + | ||
810 | + case NPCM7XX_SMB_CTL5: | ||
811 | + value = s->ctl5; | ||
812 | + break; | ||
813 | + | ||
814 | + case NPCM7XX_SMB_SCLLT: | ||
815 | + value = s->scllt; | ||
816 | + break; | ||
817 | + | ||
818 | + case NPCM7XX_SMB_SCLHT: | ||
819 | + value = s->sclht; | ||
820 | + break; | ||
821 | + | ||
822 | + default: | ||
823 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
824 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
825 | + DEVICE(s)->canonical_path, offset); | ||
826 | + break; | ||
827 | + } | ||
828 | + } | ||
829 | + break; | ||
830 | + } | ||
831 | + | ||
832 | + trace_npcm7xx_smbus_read(DEVICE(s)->canonical_path, offset, value, size); | ||
833 | + | ||
834 | + return value; | ||
835 | +} | ||
836 | + | ||
837 | +static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value, | ||
838 | + unsigned size) | ||
839 | +{ | ||
840 | + NPCM7xxSMBusState *s = opaque; | ||
841 | + uint8_t bank = s->ctl3 & NPCM7XX_SMBCTL3_BNK_SEL; | ||
842 | + | ||
843 | + trace_npcm7xx_smbus_write(DEVICE(s)->canonical_path, offset, value, size); | ||
844 | + | ||
845 | + /* The order of the registers are their order in memory. */ | ||
846 | + switch (offset) { | ||
847 | + case NPCM7XX_SMB_SDA: | ||
848 | + npcm7xx_smbus_write_sda(s, value); | ||
849 | + break; | ||
850 | + | ||
851 | + case NPCM7XX_SMB_ST: | ||
852 | + npcm7xx_smbus_write_st(s, value); | ||
853 | + break; | ||
854 | + | ||
855 | + case NPCM7XX_SMB_CST: | ||
856 | + npcm7xx_smbus_write_cst(s, value); | ||
857 | + break; | ||
858 | + | ||
859 | + case NPCM7XX_SMB_CTL1: | ||
860 | + npcm7xx_smbus_write_ctl1(s, value); | ||
861 | + break; | ||
862 | + | ||
863 | + case NPCM7XX_SMB_ADDR1: | ||
864 | + s->addr[0] = value; | ||
865 | + break; | ||
866 | + | ||
867 | + case NPCM7XX_SMB_CTL2: | ||
868 | + npcm7xx_smbus_write_ctl2(s, value); | ||
869 | + break; | ||
870 | + | ||
871 | + case NPCM7XX_SMB_ADDR2: | ||
872 | + s->addr[1] = value; | ||
873 | + break; | ||
874 | + | ||
875 | + case NPCM7XX_SMB_CTL3: | ||
876 | + npcm7xx_smbus_write_ctl3(s, value); | ||
877 | + break; | ||
878 | + | ||
879 | + case NPCM7XX_SMB_CST2: | ||
880 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
881 | + "%s: write to read-only reg: offset 0x%" HWADDR_PRIx "\n", | ||
882 | + DEVICE(s)->canonical_path, offset); | ||
883 | + break; | ||
884 | + | ||
885 | + case NPCM7XX_SMB_CST3: | ||
886 | + npcm7xx_smbus_write_cst3(s, value); | ||
887 | + break; | ||
888 | + | ||
889 | + case NPCM7XX_SMB_VER: | ||
890 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
891 | + "%s: write to read-only reg: offset 0x%" HWADDR_PRIx "\n", | ||
892 | + DEVICE(s)->canonical_path, offset); | ||
893 | + break; | ||
894 | + | ||
895 | + /* This register is either invalid or banked at this point. */ | ||
896 | + default: | ||
897 | + if (bank) { | ||
898 | + /* Bank 1 */ | ||
899 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
900 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
901 | + DEVICE(s)->canonical_path, offset); | ||
902 | + } else { | ||
903 | + /* Bank 0 */ | ||
904 | + switch (offset) { | ||
905 | + case NPCM7XX_SMB_ADDR3: | ||
906 | + s->addr[2] = value; | ||
907 | + break; | ||
908 | + | ||
909 | + case NPCM7XX_SMB_ADDR7: | ||
910 | + s->addr[6] = value; | ||
911 | + break; | ||
912 | + | ||
913 | + case NPCM7XX_SMB_ADDR4: | ||
914 | + s->addr[3] = value; | ||
915 | + break; | ||
916 | + | ||
917 | + case NPCM7XX_SMB_ADDR8: | ||
918 | + s->addr[7] = value; | ||
919 | + break; | ||
920 | + | ||
921 | + case NPCM7XX_SMB_ADDR5: | ||
922 | + s->addr[4] = value; | ||
923 | + break; | ||
924 | + | ||
925 | + case NPCM7XX_SMB_ADDR9: | ||
926 | + s->addr[8] = value; | ||
927 | + break; | ||
928 | + | ||
929 | + case NPCM7XX_SMB_ADDR6: | ||
930 | + s->addr[5] = value; | ||
931 | + break; | ||
932 | + | ||
933 | + case NPCM7XX_SMB_ADDR10: | ||
934 | + s->addr[9] = value; | ||
935 | + break; | ||
936 | + | ||
937 | + case NPCM7XX_SMB_CTL4: | ||
938 | + s->ctl4 = value; | ||
939 | + break; | ||
940 | + | ||
941 | + case NPCM7XX_SMB_CTL5: | ||
942 | + s->ctl5 = value; | ||
943 | + break; | ||
944 | + | ||
945 | + case NPCM7XX_SMB_SCLLT: | ||
946 | + s->scllt = value; | ||
947 | + break; | ||
948 | + | ||
949 | + case NPCM7XX_SMB_SCLHT: | ||
950 | + s->sclht = value; | ||
951 | + break; | ||
952 | + | ||
953 | + default: | ||
954 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
955 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
956 | + DEVICE(s)->canonical_path, offset); | ||
957 | + break; | ||
958 | + } | ||
959 | + } | ||
960 | + break; | ||
961 | + } | ||
962 | +} | ||
963 | + | ||
964 | +static const MemoryRegionOps npcm7xx_smbus_ops = { | ||
965 | + .read = npcm7xx_smbus_read, | ||
966 | + .write = npcm7xx_smbus_write, | ||
967 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
968 | + .valid = { | ||
969 | + .min_access_size = 1, | ||
970 | + .max_access_size = 1, | ||
971 | + .unaligned = false, | ||
972 | + }, | ||
973 | +}; | ||
974 | + | ||
975 | +static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type) | ||
976 | +{ | ||
977 | + NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj); | ||
978 | + | ||
979 | + s->st = NPCM7XX_SMB_ST_INIT_VAL; | ||
980 | + s->cst = NPCM7XX_SMB_CST_INIT_VAL; | ||
981 | + s->cst2 = NPCM7XX_SMB_CST2_INIT_VAL; | ||
982 | + s->cst3 = NPCM7XX_SMB_CST3_INIT_VAL; | ||
983 | + s->ctl1 = NPCM7XX_SMB_CTL1_INIT_VAL; | ||
984 | + s->ctl2 = NPCM7XX_SMB_CTL2_INIT_VAL; | ||
985 | + s->ctl3 = NPCM7XX_SMB_CTL3_INIT_VAL; | ||
986 | + s->ctl4 = NPCM7XX_SMB_CTL4_INIT_VAL; | ||
987 | + s->ctl5 = NPCM7XX_SMB_CTL5_INIT_VAL; | ||
988 | + | ||
989 | + for (int i = 0; i < NPCM7XX_SMBUS_NR_ADDRS; ++i) { | ||
990 | + s->addr[i] = NPCM7XX_SMB_ADDR_INIT_VAL; | ||
991 | + } | ||
992 | + s->scllt = NPCM7XX_SMB_SCLLT_INIT_VAL; | ||
993 | + s->sclht = NPCM7XX_SMB_SCLHT_INIT_VAL; | ||
994 | + | ||
995 | + s->status = NPCM7XX_SMBUS_STATUS_IDLE; | ||
996 | +} | ||
997 | + | ||
998 | +static void npcm7xx_smbus_hold_reset(Object *obj) | ||
999 | +{ | ||
1000 | + NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj); | ||
1001 | + | ||
1002 | + qemu_irq_lower(s->irq); | ||
1003 | +} | ||
1004 | + | ||
1005 | +static void npcm7xx_smbus_init(Object *obj) | ||
1006 | +{ | ||
1007 | + NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj); | ||
1008 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
1009 | + | ||
1010 | + sysbus_init_irq(sbd, &s->irq); | ||
1011 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_smbus_ops, s, | ||
1012 | + "regs", 4 * KiB); | ||
1013 | + sysbus_init_mmio(sbd, &s->iomem); | ||
1014 | + | ||
1015 | + s->bus = i2c_init_bus(DEVICE(s), "i2c-bus"); | ||
1016 | + s->status = NPCM7XX_SMBUS_STATUS_IDLE; | ||
1017 | +} | ||
1018 | + | ||
1019 | +static const VMStateDescription vmstate_npcm7xx_smbus = { | ||
1020 | + .name = "npcm7xx-smbus", | ||
1021 | + .version_id = 0, | ||
1022 | + .minimum_version_id = 0, | ||
1023 | + .fields = (VMStateField[]) { | ||
1024 | + VMSTATE_UINT8(sda, NPCM7xxSMBusState), | ||
1025 | + VMSTATE_UINT8(st, NPCM7xxSMBusState), | ||
1026 | + VMSTATE_UINT8(cst, NPCM7xxSMBusState), | ||
1027 | + VMSTATE_UINT8(cst2, NPCM7xxSMBusState), | ||
1028 | + VMSTATE_UINT8(cst3, NPCM7xxSMBusState), | ||
1029 | + VMSTATE_UINT8(ctl1, NPCM7xxSMBusState), | ||
1030 | + VMSTATE_UINT8(ctl2, NPCM7xxSMBusState), | ||
1031 | + VMSTATE_UINT8(ctl3, NPCM7xxSMBusState), | ||
1032 | + VMSTATE_UINT8(ctl4, NPCM7xxSMBusState), | ||
1033 | + VMSTATE_UINT8(ctl5, NPCM7xxSMBusState), | ||
1034 | + VMSTATE_UINT8_ARRAY(addr, NPCM7xxSMBusState, NPCM7XX_SMBUS_NR_ADDRS), | ||
1035 | + VMSTATE_UINT8(scllt, NPCM7xxSMBusState), | ||
1036 | + VMSTATE_UINT8(sclht, NPCM7xxSMBusState), | ||
1037 | + VMSTATE_END_OF_LIST(), | ||
1038 | + }, | ||
1039 | +}; | ||
1040 | + | ||
1041 | +static void npcm7xx_smbus_class_init(ObjectClass *klass, void *data) | ||
1042 | +{ | ||
1043 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
1044 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
1045 | + | ||
1046 | + dc->desc = "NPCM7xx System Management Bus"; | ||
1047 | + dc->vmsd = &vmstate_npcm7xx_smbus; | ||
1048 | + rc->phases.enter = npcm7xx_smbus_enter_reset; | ||
1049 | + rc->phases.hold = npcm7xx_smbus_hold_reset; | ||
1050 | +} | ||
1051 | + | ||
1052 | +static const TypeInfo npcm7xx_smbus_types[] = { | ||
1053 | + { | ||
1054 | + .name = TYPE_NPCM7XX_SMBUS, | ||
1055 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
1056 | + .instance_size = sizeof(NPCM7xxSMBusState), | ||
1057 | + .class_init = npcm7xx_smbus_class_init, | ||
1058 | + .instance_init = npcm7xx_smbus_init, | ||
1059 | + }, | ||
1060 | +}; | ||
1061 | +DEFINE_TYPES(npcm7xx_smbus_types); | ||
1062 | diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build | ||
154 | index XXXXXXX..XXXXXXX 100644 | 1063 | index XXXXXXX..XXXXXXX 100644 |
155 | --- a/MAINTAINERS | 1064 | --- a/hw/i2c/meson.build |
156 | +++ b/MAINTAINERS | 1065 | +++ b/hw/i2c/meson.build |
157 | @@ -XXX,XX +XXX,XX @@ F: include/hw/timer/cmsdk-apb-timer.h | 1066 | @@ -XXX,XX +XXX,XX @@ i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) |
158 | F: tests/qtest/cmsdk-apb-timer-test.c | 1067 | i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c')) |
159 | F: hw/timer/cmsdk-apb-dualtimer.c | 1068 | i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) |
160 | F: include/hw/timer/cmsdk-apb-dualtimer.h | 1069 | i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) |
161 | +F: tests/qtest/cmsdk-apb-dualtimer-test.c | 1070 | +i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c')) |
162 | F: hw/char/cmsdk-apb-uart.c | 1071 | i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c')) |
163 | F: include/hw/char/cmsdk-apb-uart.h | 1072 | i2c_ss.add(when: 'CONFIG_VERSATILE_I2C', if_true: files('versatile_i2c.c')) |
164 | F: hw/watchdog/cmsdk-apb-watchdog.c | 1073 | i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c')) |
165 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 1074 | diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events |
166 | index XXXXXXX..XXXXXXX 100644 | 1075 | index XXXXXXX..XXXXXXX 100644 |
167 | --- a/tests/qtest/meson.build | 1076 | --- a/hw/i2c/trace-events |
168 | +++ b/tests/qtest/meson.build | 1077 | +++ b/hw/i2c/trace-events |
169 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ | 1078 | @@ -XXX,XX +XXX,XX @@ aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t val |
170 | 'npcm7xx_timer-test', | 1079 | aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 |
171 | 'npcm7xx_watchdog_timer-test'] | 1080 | aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" |
172 | qtests_arm = \ | 1081 | aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x" |
173 | + (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ | 1082 | + |
174 | (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ | 1083 | +# npcm7xx_smbus.c |
175 | (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ | 1084 | + |
176 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | 1085 | +npcm7xx_smbus_read(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" |
1086 | +npcm7xx_smbus_write(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | ||
1087 | +npcm7xx_smbus_start(const char *id, int success) "%s starting, success: %d" | ||
1088 | +npcm7xx_smbus_send_address(const char *id, uint8_t addr, int recv, int success) "%s sending address: 0x%02x, recv: %d, success: %d" | ||
1089 | +npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byte: 0x%02x, success: %d" | ||
1090 | +npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x" | ||
1091 | +npcm7xx_smbus_stop(const char *id) "%s stopping" | ||
1092 | +npcm7xx_smbus_nack(const char *id) "%s nacking" | ||
177 | -- | 1093 | -- |
178 | 2.20.1 | 1094 | 2.20.1 |
179 | 1095 | ||
180 | 1096 | diff view generated by jsdifflib |
1 | Switch the CMSDK APB dualtimer device over to using its Clock input; | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | the pclk-frq property is now ignored. | ||
3 | 2 | ||
3 | Add I2C temperature sensors for NPCM750 eval board. | ||
4 | |||
5 | Reviewed-by: Doug Evans<dje@google.com> | ||
6 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> | ||
7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20210210220426.3577804-3-wuhaotsh@google.com | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-20-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-20-peter.maydell@linaro.org | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | --- | 11 | --- |
12 | hw/timer/cmsdk-apb-dualtimer.c | 42 ++++++++++++++++++++++++++++++---- | 12 | hw/arm/npcm7xx_boards.c | 19 +++++++++++++++++++ |
13 | 1 file changed, 37 insertions(+), 5 deletions(-) | 13 | 1 file changed, 19 insertions(+) |
14 | 14 | ||
15 | diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c | 15 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/timer/cmsdk-apb-dualtimer.c | 17 | --- a/hw/arm/npcm7xx_boards.c |
18 | +++ b/hw/timer/cmsdk-apb-dualtimer.c | 18 | +++ b/hw/arm/npcm7xx_boards.c |
19 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_update(CMSDKAPBDualTimer *s) | 19 | @@ -XXX,XX +XXX,XX @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, |
20 | qemu_set_irq(s->timerintc, timintc); | 20 | return NPCM7XX(obj); |
21 | } | 21 | } |
22 | 22 | ||
23 | +static int cmsdk_dualtimermod_divisor(CMSDKAPBDualTimerModule *m) | 23 | +static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num) |
24 | +{ | 24 | +{ |
25 | + /* Return the divisor set by the current CONTROL.PRESCALE value */ | 25 | + g_assert(num < ARRAY_SIZE(soc->smbus)); |
26 | + switch (FIELD_EX32(m->control, CONTROL, PRESCALE)) { | 26 | + return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus")); |
27 | + case 0: | ||
28 | + return 1; | ||
29 | + case 1: | ||
30 | + return 16; | ||
31 | + case 2: | ||
32 | + case 3: /* UNDEFINED, we treat like 2 (and complained when it was set) */ | ||
33 | + return 256; | ||
34 | + default: | ||
35 | + g_assert_not_reached(); | ||
36 | + } | ||
37 | +} | 27 | +} |
38 | + | 28 | + |
39 | static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m, | 29 | +static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
40 | uint32_t newctrl) | ||
41 | { | ||
42 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m, | ||
43 | default: | ||
44 | g_assert_not_reached(); | ||
45 | } | ||
46 | - ptimer_set_freq(m->timer, m->parent->pclk_frq / divisor); | ||
47 | + ptimer_set_period_from_clock(m->timer, m->parent->timclk, divisor); | ||
48 | } | ||
49 | |||
50 | if (changed & R_CONTROL_MODE_MASK) { | ||
51 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m) | ||
52 | * limit must both be set to 0xffff, so we wrap at 16 bits. | ||
53 | */ | ||
54 | ptimer_set_limit(m->timer, 0xffff, 1); | ||
55 | - ptimer_set_freq(m->timer, m->parent->pclk_frq); | ||
56 | + ptimer_set_period_from_clock(m->timer, m->parent->timclk, | ||
57 | + cmsdk_dualtimermod_divisor(m)); | ||
58 | ptimer_transaction_commit(m->timer); | ||
59 | } | ||
60 | |||
61 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_reset(DeviceState *dev) | ||
62 | s->timeritop = 0; | ||
63 | } | ||
64 | |||
65 | +static void cmsdk_apb_dualtimer_clk_update(void *opaque) | ||
66 | +{ | 30 | +{ |
67 | + CMSDKAPBDualTimer *s = CMSDK_APB_DUALTIMER(opaque); | 31 | + /* lm75 temperature sensor on SVB, tmp105 is compatible */ |
68 | + int i; | 32 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48); |
69 | + | 33 | + /* lm75 temperature sensor on EB, tmp105 is compatible */ |
70 | + for (i = 0; i < ARRAY_SIZE(s->timermod); i++) { | 34 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48); |
71 | + CMSDKAPBDualTimerModule *m = &s->timermod[i]; | 35 | + /* tmp100 temperature sensor on EB, tmp105 is compatible */ |
72 | + ptimer_transaction_begin(m->timer); | 36 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48); |
73 | + ptimer_set_period_from_clock(m->timer, m->parent->timclk, | 37 | + /* tmp100 temperature sensor on SVB, tmp105 is compatible */ |
74 | + cmsdk_dualtimermod_divisor(m)); | 38 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); |
75 | + ptimer_transaction_commit(m->timer); | ||
76 | + } | ||
77 | +} | 39 | +} |
78 | + | 40 | + |
79 | static void cmsdk_apb_dualtimer_init(Object *obj) | 41 | static void npcm750_evb_init(MachineState *machine) |
80 | { | 42 | { |
81 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 43 | NPCM7xxState *soc; |
82 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_init(Object *obj) | 44 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine) |
83 | for (i = 0; i < ARRAY_SIZE(s->timermod); i++) { | 45 | |
84 | sysbus_init_irq(sbd, &s->timermod[i].timerint); | 46 | npcm7xx_load_bootrom(machine, soc); |
85 | } | 47 | npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0)); |
86 | - s->timclk = qdev_init_clock_in(DEVICE(s), "TIMCLK", NULL, NULL); | 48 | + npcm750_evb_i2c_init(soc); |
87 | + s->timclk = qdev_init_clock_in(DEVICE(s), "TIMCLK", | 49 | npcm7xx_load_kernel(machine, soc); |
88 | + cmsdk_apb_dualtimer_clk_update, s); | ||
89 | } | 50 | } |
90 | |||
91 | static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp) | ||
92 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp) | ||
93 | CMSDKAPBDualTimer *s = CMSDK_APB_DUALTIMER(dev); | ||
94 | int i; | ||
95 | |||
96 | - if (s->pclk_frq == 0) { | ||
97 | - error_setg(errp, "CMSDK APB timer: pclk-frq property must be set"); | ||
98 | + if (!clock_has_source(s->timclk)) { | ||
99 | + error_setg(errp, "CMSDK APB dualtimer: TIMCLK clock must be connected"); | ||
100 | return; | ||
101 | } | ||
102 | 51 | ||
103 | -- | 52 | -- |
104 | 2.20.1 | 53 | 2.20.1 |
105 | 54 | ||
106 | 55 | diff view generated by jsdifflib |
1 | From: Maxim Uvarov <maxim.uvarov@linaro.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Add secure pl061 for reset/power down machine from | 3 | Add AT24 EEPROM and temperature sensors for GSJ machine. |
4 | the secure world (Arm Trusted Firmware). Connect it | ||
5 | with gpio-pwr driver. | ||
6 | 4 | ||
7 | Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> | 5 | Reviewed-by: Doug Evans<dje@google.com> |
8 | Reviewed-by: Andrew Jones <drjones@redhat.com> | 6 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> |
9 | [PMM: Added mention of the new device to the documentation] | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
8 | Message-id: 20210210220426.3577804-4-wuhaotsh@google.com | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | docs/system/arm/virt.rst | 2 ++ | 12 | hw/arm/npcm7xx_boards.c | 27 +++++++++++++++++++++++++++ |
13 | include/hw/arm/virt.h | 2 ++ | 13 | hw/arm/Kconfig | 1 + |
14 | hw/arm/virt.c | 56 +++++++++++++++++++++++++++++++++++++++- | 14 | 2 files changed, 28 insertions(+) |
15 | hw/arm/Kconfig | 1 + | ||
16 | 4 files changed, 60 insertions(+), 1 deletion(-) | ||
17 | 15 | ||
18 | diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst | 16 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
19 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/docs/system/arm/virt.rst | 18 | --- a/hw/arm/npcm7xx_boards.c |
21 | +++ b/docs/system/arm/virt.rst | 19 | +++ b/hw/arm/npcm7xx_boards.c |
22 | @@ -XXX,XX +XXX,XX @@ The virt board supports: | 20 | @@ -XXX,XX +XXX,XX @@ |
23 | - Secure-World-only devices if the CPU has TrustZone: | 21 | #include "exec/address-spaces.h" |
24 | 22 | #include "hw/arm/npcm7xx.h" | |
25 | - A second PL011 UART | 23 | #include "hw/core/cpu.h" |
26 | + - A second PL061 GPIO controller, with GPIO lines for triggering | 24 | +#include "hw/i2c/smbus_eeprom.h" |
27 | + a system reset or system poweroff | 25 | #include "hw/loader.h" |
28 | - A secure flash memory | 26 | #include "hw/qdev-properties.h" |
29 | - 16MB of secure RAM | 27 | #include "qapi/error.h" |
30 | 28 | @@ -XXX,XX +XXX,XX @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num) | |
31 | diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h | 29 | return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus")); |
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/hw/arm/virt.h | ||
34 | +++ b/include/hw/arm/virt.h | ||
35 | @@ -XXX,XX +XXX,XX @@ enum { | ||
36 | VIRT_GPIO, | ||
37 | VIRT_SECURE_UART, | ||
38 | VIRT_SECURE_MEM, | ||
39 | + VIRT_SECURE_GPIO, | ||
40 | VIRT_PCDIMM_ACPI, | ||
41 | VIRT_ACPI_GED, | ||
42 | VIRT_NVDIMM_ACPI, | ||
43 | @@ -XXX,XX +XXX,XX @@ struct VirtMachineClass { | ||
44 | bool kvm_no_adjvtime; | ||
45 | bool no_kvm_steal_time; | ||
46 | bool acpi_expose_flash; | ||
47 | + bool no_secure_gpio; | ||
48 | }; | ||
49 | |||
50 | struct VirtMachineState { | ||
51 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/hw/arm/virt.c | ||
54 | +++ b/hw/arm/virt.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry base_memmap[] = { | ||
56 | [VIRT_ACPI_GED] = { 0x09080000, ACPI_GED_EVT_SEL_LEN }, | ||
57 | [VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN}, | ||
58 | [VIRT_PVTIME] = { 0x090a0000, 0x00010000 }, | ||
59 | + [VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 }, | ||
60 | [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, | ||
61 | /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ | ||
62 | [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 }, | ||
63 | @@ -XXX,XX +XXX,XX @@ static void create_gpio_keys(const VirtMachineState *vms, | ||
64 | "gpios", phandle, 3, 0); | ||
65 | } | 30 | } |
66 | 31 | ||
67 | +#define SECURE_GPIO_POWEROFF 0 | 32 | +static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr, |
68 | +#define SECURE_GPIO_RESET 1 | 33 | + uint32_t rsize) |
34 | +{ | ||
35 | + I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus); | ||
36 | + I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr); | ||
37 | + DeviceState *dev = DEVICE(i2c_dev); | ||
69 | + | 38 | + |
70 | +static void create_secure_gpio_pwr(const VirtMachineState *vms, | 39 | + qdev_prop_set_uint32(dev, "rom-size", rsize); |
71 | + DeviceState *pl061_dev, | 40 | + i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort); |
72 | + uint32_t phandle) | ||
73 | +{ | ||
74 | + DeviceState *gpio_pwr_dev; | ||
75 | + | ||
76 | + /* gpio-pwr */ | ||
77 | + gpio_pwr_dev = sysbus_create_simple("gpio-pwr", -1, NULL); | ||
78 | + | ||
79 | + /* connect secure pl061 to gpio-pwr */ | ||
80 | + qdev_connect_gpio_out(pl061_dev, SECURE_GPIO_RESET, | ||
81 | + qdev_get_gpio_in_named(gpio_pwr_dev, "reset", 0)); | ||
82 | + qdev_connect_gpio_out(pl061_dev, SECURE_GPIO_POWEROFF, | ||
83 | + qdev_get_gpio_in_named(gpio_pwr_dev, "shutdown", 0)); | ||
84 | + | ||
85 | + qemu_fdt_add_subnode(vms->fdt, "/gpio-poweroff"); | ||
86 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "compatible", | ||
87 | + "gpio-poweroff"); | ||
88 | + qemu_fdt_setprop_cells(vms->fdt, "/gpio-poweroff", | ||
89 | + "gpios", phandle, SECURE_GPIO_POWEROFF, 0); | ||
90 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "status", "disabled"); | ||
91 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-poweroff", "secure-status", | ||
92 | + "okay"); | ||
93 | + | ||
94 | + qemu_fdt_add_subnode(vms->fdt, "/gpio-restart"); | ||
95 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "compatible", | ||
96 | + "gpio-restart"); | ||
97 | + qemu_fdt_setprop_cells(vms->fdt, "/gpio-restart", | ||
98 | + "gpios", phandle, SECURE_GPIO_RESET, 0); | ||
99 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "status", "disabled"); | ||
100 | + qemu_fdt_setprop_string(vms->fdt, "/gpio-restart", "secure-status", | ||
101 | + "okay"); | ||
102 | +} | 41 | +} |
103 | + | 42 | + |
104 | static void create_gpio_devices(const VirtMachineState *vms, int gpio, | 43 | static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
105 | MemoryRegion *mem) | ||
106 | { | 44 | { |
107 | @@ -XXX,XX +XXX,XX @@ static void create_gpio_devices(const VirtMachineState *vms, int gpio, | 45 | /* lm75 temperature sensor on SVB, tmp105 is compatible */ |
108 | qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk"); | 46 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
109 | qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle); | 47 | i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); |
110 | |||
111 | + if (gpio != VIRT_GPIO) { | ||
112 | + /* Mark as not usable by the normal world */ | ||
113 | + qemu_fdt_setprop_string(vms->fdt, nodename, "status", "disabled"); | ||
114 | + qemu_fdt_setprop_string(vms->fdt, nodename, "secure-status", "okay"); | ||
115 | + } | ||
116 | g_free(nodename); | ||
117 | |||
118 | /* Child gpio devices */ | ||
119 | - create_gpio_keys(vms, pl061_dev, phandle); | ||
120 | + if (gpio == VIRT_GPIO) { | ||
121 | + create_gpio_keys(vms, pl061_dev, phandle); | ||
122 | + } else { | ||
123 | + create_secure_gpio_pwr(vms, pl061_dev, phandle); | ||
124 | + } | ||
125 | } | 48 | } |
126 | 49 | ||
127 | static void create_virtio_devices(const VirtMachineState *vms) | 50 | +static void quanta_gsj_i2c_init(NPCM7xxState *soc) |
128 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | 51 | +{ |
129 | create_gpio_devices(vms, VIRT_GPIO, sysmem); | 52 | + /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */ |
130 | } | 53 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x5c); |
131 | 54 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x5c); | |
132 | + if (vms->secure && !vmc->no_secure_gpio) { | 55 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c); |
133 | + create_gpio_devices(vms, VIRT_SECURE_GPIO, secure_sysmem); | 56 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c); |
134 | + } | ||
135 | + | 57 | + |
136 | /* connect powerdown request */ | 58 | + at24c_eeprom_init(soc, 9, 0x55, 8192); |
137 | vms->powerdown_notifier.notify = virt_powerdown_req; | 59 | + at24c_eeprom_init(soc, 10, 0x55, 8192); |
138 | qemu_register_powerdown_notifier(&vms->powerdown_notifier); | 60 | + |
139 | @@ -XXX,XX +XXX,XX @@ DEFINE_VIRT_MACHINE_AS_LATEST(6, 0) | 61 | + /* TODO: Add additional i2c devices. */ |
140 | 62 | +} | |
141 | static void virt_machine_5_2_options(MachineClass *mc) | 63 | + |
64 | static void npcm750_evb_init(MachineState *machine) | ||
142 | { | 65 | { |
143 | + VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); | 66 | NPCM7xxState *soc; |
144 | + | 67 | @@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine) |
145 | virt_machine_6_0_options(mc); | 68 | npcm7xx_load_bootrom(machine, soc); |
146 | compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len); | 69 | npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e", |
147 | + vmc->no_secure_gpio = true; | 70 | drive_get(IF_MTD, 0, 0)); |
71 | + quanta_gsj_i2c_init(soc); | ||
72 | npcm7xx_load_kernel(machine, soc); | ||
148 | } | 73 | } |
149 | DEFINE_VIRT_MACHINE(5, 2) | ||
150 | 74 | ||
151 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | 75 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
152 | index XXXXXXX..XXXXXXX 100644 | 76 | index XXXXXXX..XXXXXXX 100644 |
153 | --- a/hw/arm/Kconfig | 77 | --- a/hw/arm/Kconfig |
154 | +++ b/hw/arm/Kconfig | 78 | +++ b/hw/arm/Kconfig |
155 | @@ -XXX,XX +XXX,XX @@ config ARM_VIRT | 79 | @@ -XXX,XX +XXX,XX @@ config NPCM7XX |
156 | select PL011 # UART | 80 | bool |
157 | select PL031 # RTC | 81 | select A9MPCORE |
158 | select PL061 # GPIO | 82 | select ARM_GIC |
159 | + select GPIO_PWR | 83 | + select AT24C # EEPROM |
160 | select PLATFORM_BUS | 84 | select PL310 # cache controller |
161 | select SMBIOS | 85 | select SERIAL |
162 | select VIRTIO_MMIO | 86 | select SSI |
163 | -- | 87 | -- |
164 | 2.20.1 | 88 | 2.20.1 |
165 | 89 | ||
166 | 90 | diff view generated by jsdifflib |
1 | Add a simple test of the CMSDK APB timer, since we're about to do | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | some refactoring of how it is clocked. | 2 | |
3 | 3 | This patch adds a QTest for NPCM7XX SMBus's single byte mode. It sends a | |
4 | byte to a device in the evaluation board, and verify the retrieved value | ||
5 | is equivalent to the sent value. | ||
6 | |||
7 | Reviewed-by: Doug Evans<dje@google.com> | ||
8 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> | ||
9 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Message-id: 20210210220426.3577804-5-wuhaotsh@google.com | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-4-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-4-peter.maydell@linaro.org | ||
10 | --- | 13 | --- |
11 | tests/qtest/cmsdk-apb-timer-test.c | 75 ++++++++++++++++++++++++++++++ | 14 | tests/qtest/npcm7xx_smbus-test.c | 352 +++++++++++++++++++++++++++++++ |
12 | MAINTAINERS | 1 + | 15 | tests/qtest/meson.build | 1 + |
13 | tests/qtest/meson.build | 1 + | 16 | 2 files changed, 353 insertions(+) |
14 | 3 files changed, 77 insertions(+) | 17 | create mode 100644 tests/qtest/npcm7xx_smbus-test.c |
15 | create mode 100644 tests/qtest/cmsdk-apb-timer-test.c | 18 | |
16 | 19 | diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c | |
17 | diff --git a/tests/qtest/cmsdk-apb-timer-test.c b/tests/qtest/cmsdk-apb-timer-test.c | ||
18 | new file mode 100644 | 20 | new file mode 100644 |
19 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
20 | --- /dev/null | 22 | --- /dev/null |
21 | +++ b/tests/qtest/cmsdk-apb-timer-test.c | 23 | +++ b/tests/qtest/npcm7xx_smbus-test.c |
22 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
23 | +/* | 25 | +/* |
24 | + * QTest testcase for the CMSDK APB timer device | 26 | + * QTests for Nuvoton NPCM7xx SMBus Modules. |
25 | + * | 27 | + * |
26 | + * Copyright (c) 2021 Linaro Limited | 28 | + * Copyright 2020 Google LLC |
27 | + * | 29 | + * |
28 | + * This program is free software; you can redistribute it and/or modify it | 30 | + * This program is free software; you can redistribute it and/or modify it |
29 | + * under the terms of the GNU General Public License as published by the | 31 | + * under the terms of the GNU General Public License as published by the |
30 | + * Free Software Foundation; either version 2 of the License, or | 32 | + * Free Software Foundation; either version 2 of the License, or |
31 | + * (at your option) any later version. | 33 | + * (at your option) any later version. |
... | ... | ||
35 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 37 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
36 | + * for more details. | 38 | + * for more details. |
37 | + */ | 39 | + */ |
38 | + | 40 | + |
39 | +#include "qemu/osdep.h" | 41 | +#include "qemu/osdep.h" |
40 | +#include "libqtest-single.h" | 42 | +#include "qemu/bitops.h" |
41 | + | 43 | +#include "libqos/i2c.h" |
42 | +/* IoTKit/ARMSSE-200 timer0; driven at 25MHz in mps2-an385, so 40ns per tick */ | 44 | +#include "libqos/libqtest.h" |
43 | +#define TIMER_BASE 0x40000000 | 45 | +#include "hw/misc/tmp105_regs.h" |
44 | + | 46 | + |
45 | +#define CTRL 0 | 47 | +#define NR_SMBUS_DEVICES 16 |
46 | +#define VALUE 4 | 48 | +#define SMBUS_ADDR(x) (0xf0080000 + 0x1000 * (x)) |
47 | +#define RELOAD 8 | 49 | +#define SMBUS_IRQ(x) (64 + (x)) |
48 | +#define INTSTATUS 0xc | 50 | + |
49 | + | 51 | +#define EVB_DEVICE_ADDR 0x48 |
50 | +static void test_timer(void) | 52 | +#define INVALID_DEVICE_ADDR 0x01 |
51 | +{ | 53 | + |
52 | + g_assert_true(readl(TIMER_BASE + INTSTATUS) == 0); | 54 | +const int evb_bus_list[] = {0, 1, 2, 6}; |
53 | + | 55 | + |
54 | + /* Start timer: will fire after 40 * 1000 == 40000 ns */ | 56 | +/* Offsets */ |
55 | + writel(TIMER_BASE + RELOAD, 1000); | 57 | +enum CommonRegister { |
56 | + writel(TIMER_BASE + CTRL, 9); | 58 | + OFFSET_SDA = 0x0, |
57 | + | 59 | + OFFSET_ST = 0x2, |
58 | + /* Step to just past the 500th tick and check VALUE */ | 60 | + OFFSET_CST = 0x4, |
59 | + clock_step(40 * 500 + 1); | 61 | + OFFSET_CTL1 = 0x6, |
60 | + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); | 62 | + OFFSET_ADDR1 = 0x8, |
61 | + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 500); | 63 | + OFFSET_CTL2 = 0xa, |
62 | + | 64 | + OFFSET_ADDR2 = 0xc, |
63 | + /* Just past the 1000th tick: timer should have fired */ | 65 | + OFFSET_CTL3 = 0xe, |
64 | + clock_step(40 * 500); | 66 | + OFFSET_CST2 = 0x18, |
65 | + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); | 67 | + OFFSET_CST3 = 0x19, |
66 | + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 0); | 68 | +}; |
67 | + | 69 | + |
68 | + /* VALUE reloads at the following tick */ | 70 | +enum NPCM7xxSMBusBank0Register { |
69 | + clock_step(40); | 71 | + OFFSET_ADDR3 = 0x10, |
70 | + g_assert_cmpuint(readl(TIMER_BASE + VALUE), ==, 1000); | 72 | + OFFSET_ADDR7 = 0x11, |
71 | + | 73 | + OFFSET_ADDR4 = 0x12, |
72 | + /* Check write-1-to-clear behaviour of INTSTATUS */ | 74 | + OFFSET_ADDR8 = 0x13, |
73 | + writel(TIMER_BASE + INTSTATUS, 0); | 75 | + OFFSET_ADDR5 = 0x14, |
74 | + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 1); | 76 | + OFFSET_ADDR9 = 0x15, |
75 | + writel(TIMER_BASE + INTSTATUS, 1); | 77 | + OFFSET_ADDR6 = 0x16, |
76 | + g_assert_cmpuint(readl(TIMER_BASE + INTSTATUS), ==, 0); | 78 | + OFFSET_ADDR10 = 0x17, |
77 | + | 79 | + OFFSET_CTL4 = 0x1a, |
78 | + /* Turn off the timer */ | 80 | + OFFSET_CTL5 = 0x1b, |
79 | + writel(TIMER_BASE + CTRL, 0); | 81 | + OFFSET_SCLLT = 0x1c, |
80 | +} | 82 | + OFFSET_FIF_CTL = 0x1d, |
83 | + OFFSET_SCLHT = 0x1e, | ||
84 | +}; | ||
85 | + | ||
86 | +enum NPCM7xxSMBusBank1Register { | ||
87 | + OFFSET_FIF_CTS = 0x10, | ||
88 | + OFFSET_FAIR_PER = 0x11, | ||
89 | + OFFSET_TXF_CTL = 0x12, | ||
90 | + OFFSET_T_OUT = 0x14, | ||
91 | + OFFSET_TXF_STS = 0x1a, | ||
92 | + OFFSET_RXF_STS = 0x1c, | ||
93 | + OFFSET_RXF_CTL = 0x1e, | ||
94 | +}; | ||
95 | + | ||
96 | +/* ST fields */ | ||
97 | +#define ST_STP BIT(7) | ||
98 | +#define ST_SDAST BIT(6) | ||
99 | +#define ST_BER BIT(5) | ||
100 | +#define ST_NEGACK BIT(4) | ||
101 | +#define ST_STASTR BIT(3) | ||
102 | +#define ST_NMATCH BIT(2) | ||
103 | +#define ST_MODE BIT(1) | ||
104 | +#define ST_XMIT BIT(0) | ||
105 | + | ||
106 | +/* CST fields */ | ||
107 | +#define CST_ARPMATCH BIT(7) | ||
108 | +#define CST_MATCHAF BIT(6) | ||
109 | +#define CST_TGSCL BIT(5) | ||
110 | +#define CST_TSDA BIT(4) | ||
111 | +#define CST_GCMATCH BIT(3) | ||
112 | +#define CST_MATCH BIT(2) | ||
113 | +#define CST_BB BIT(1) | ||
114 | +#define CST_BUSY BIT(0) | ||
115 | + | ||
116 | +/* CST2 fields */ | ||
117 | +#define CST2_INSTTS BIT(7) | ||
118 | +#define CST2_MATCH7F BIT(6) | ||
119 | +#define CST2_MATCH6F BIT(5) | ||
120 | +#define CST2_MATCH5F BIT(4) | ||
121 | +#define CST2_MATCH4F BIT(3) | ||
122 | +#define CST2_MATCH3F BIT(2) | ||
123 | +#define CST2_MATCH2F BIT(1) | ||
124 | +#define CST2_MATCH1F BIT(0) | ||
125 | + | ||
126 | +/* CST3 fields */ | ||
127 | +#define CST3_EO_BUSY BIT(7) | ||
128 | +#define CST3_MATCH10F BIT(2) | ||
129 | +#define CST3_MATCH9F BIT(1) | ||
130 | +#define CST3_MATCH8F BIT(0) | ||
131 | + | ||
132 | +/* CTL1 fields */ | ||
133 | +#define CTL1_STASTRE BIT(7) | ||
134 | +#define CTL1_NMINTE BIT(6) | ||
135 | +#define CTL1_GCMEN BIT(5) | ||
136 | +#define CTL1_ACK BIT(4) | ||
137 | +#define CTL1_EOBINTE BIT(3) | ||
138 | +#define CTL1_INTEN BIT(2) | ||
139 | +#define CTL1_STOP BIT(1) | ||
140 | +#define CTL1_START BIT(0) | ||
141 | + | ||
142 | +/* CTL2 fields */ | ||
143 | +#define CTL2_SCLFRQ(rv) extract8((rv), 1, 6) | ||
144 | +#define CTL2_ENABLE BIT(0) | ||
145 | + | ||
146 | +/* CTL3 fields */ | ||
147 | +#define CTL3_SCL_LVL BIT(7) | ||
148 | +#define CTL3_SDA_LVL BIT(6) | ||
149 | +#define CTL3_BNK_SEL BIT(5) | ||
150 | +#define CTL3_400K_MODE BIT(4) | ||
151 | +#define CTL3_IDL_START BIT(3) | ||
152 | +#define CTL3_ARPMEN BIT(2) | ||
153 | +#define CTL3_SCLFRQ(rv) extract8((rv), 0, 2) | ||
154 | + | ||
155 | +/* ADDR fields */ | ||
156 | +#define ADDR_EN BIT(7) | ||
157 | +#define ADDR_A(rv) extract8((rv), 0, 6) | ||
158 | + | ||
159 | + | ||
160 | +static void check_running(QTestState *qts, uint64_t base_addr) | ||
161 | +{ | ||
162 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY); | ||
163 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB); | ||
164 | +} | ||
165 | + | ||
166 | +static void check_stopped(QTestState *qts, uint64_t base_addr) | ||
167 | +{ | ||
168 | + uint8_t cst3; | ||
169 | + | ||
170 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0); | ||
171 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY); | ||
172 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB); | ||
173 | + | ||
174 | + cst3 = qtest_readb(qts, base_addr + OFFSET_CST3); | ||
175 | + g_assert_true(cst3 & CST3_EO_BUSY); | ||
176 | + qtest_writeb(qts, base_addr + OFFSET_CST3, cst3); | ||
177 | + cst3 = qtest_readb(qts, base_addr + OFFSET_CST3); | ||
178 | + g_assert_false(cst3 & CST3_EO_BUSY); | ||
179 | +} | ||
180 | + | ||
181 | +static void enable_bus(QTestState *qts, uint64_t base_addr) | ||
182 | +{ | ||
183 | + uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2); | ||
184 | + | ||
185 | + ctl2 |= CTL2_ENABLE; | ||
186 | + qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2); | ||
187 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE); | ||
188 | +} | ||
189 | + | ||
190 | +static void disable_bus(QTestState *qts, uint64_t base_addr) | ||
191 | +{ | ||
192 | + uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2); | ||
193 | + | ||
194 | + ctl2 &= ~CTL2_ENABLE; | ||
195 | + qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2); | ||
196 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE); | ||
197 | +} | ||
198 | + | ||
199 | +static void start_transfer(QTestState *qts, uint64_t base_addr) | ||
200 | +{ | ||
201 | + uint8_t ctl1; | ||
202 | + | ||
203 | + ctl1 = CTL1_START | CTL1_INTEN | CTL1_STASTRE; | ||
204 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
205 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==, | ||
206 | + CTL1_INTEN | CTL1_STASTRE | CTL1_INTEN); | ||
207 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
208 | + ST_MODE | ST_XMIT | ST_SDAST); | ||
209 | + check_running(qts, base_addr); | ||
210 | +} | ||
211 | + | ||
212 | +static void stop_transfer(QTestState *qts, uint64_t base_addr) | ||
213 | +{ | ||
214 | + uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); | ||
215 | + | ||
216 | + ctl1 &= ~(CTL1_START | CTL1_ACK); | ||
217 | + ctl1 |= CTL1_STOP | CTL1_INTEN | CTL1_EOBINTE; | ||
218 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
219 | + ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); | ||
220 | + g_assert_false(ctl1 & CTL1_STOP); | ||
221 | +} | ||
222 | + | ||
223 | +static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte) | ||
224 | +{ | ||
225 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
226 | + ST_MODE | ST_XMIT | ST_SDAST); | ||
227 | + qtest_writeb(qts, base_addr + OFFSET_SDA, byte); | ||
228 | +} | ||
229 | + | ||
230 | +static uint8_t recv_byte(QTestState *qts, uint64_t base_addr) | ||
231 | +{ | ||
232 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
233 | + ST_MODE | ST_SDAST); | ||
234 | + return qtest_readb(qts, base_addr + OFFSET_SDA); | ||
235 | +} | ||
236 | + | ||
237 | +static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr, | ||
238 | + bool recv, bool valid) | ||
239 | +{ | ||
240 | + uint8_t encoded_addr = (addr << 1) | (recv ? 1 : 0); | ||
241 | + uint8_t st; | ||
242 | + | ||
243 | + qtest_writeb(qts, base_addr + OFFSET_SDA, encoded_addr); | ||
244 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
245 | + | ||
246 | + if (valid) { | ||
247 | + if (recv) { | ||
248 | + g_assert_cmphex(st, ==, ST_MODE | ST_SDAST | ST_STASTR); | ||
249 | + } else { | ||
250 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST | ST_STASTR); | ||
251 | + } | ||
252 | + | ||
253 | + qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR); | ||
254 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
255 | + if (recv) { | ||
256 | + g_assert_cmphex(st, ==, ST_MODE | ST_SDAST); | ||
257 | + } else { | ||
258 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST); | ||
259 | + } | ||
260 | + } else { | ||
261 | + if (recv) { | ||
262 | + g_assert_cmphex(st, ==, ST_MODE | ST_NEGACK); | ||
263 | + } else { | ||
264 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_NEGACK); | ||
265 | + } | ||
266 | + } | ||
267 | +} | ||
268 | + | ||
269 | +static void send_nack(QTestState *qts, uint64_t base_addr) | ||
270 | +{ | ||
271 | + uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); | ||
272 | + | ||
273 | + ctl1 &= ~(CTL1_START | CTL1_STOP); | ||
274 | + ctl1 |= CTL1_ACK | CTL1_INTEN; | ||
275 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
276 | +} | ||
277 | + | ||
278 | +/* Check the SMBus's status is set correctly when disabled. */ | ||
279 | +static void test_disable_bus(gconstpointer data) | ||
280 | +{ | ||
281 | + intptr_t index = (intptr_t)data; | ||
282 | + uint64_t base_addr = SMBUS_ADDR(index); | ||
283 | + QTestState *qts = qtest_init("-machine npcm750-evb"); | ||
284 | + | ||
285 | + disable_bus(qts, base_addr); | ||
286 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==, 0); | ||
287 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0); | ||
288 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST3) & CST3_EO_BUSY); | ||
289 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CST), ==, 0); | ||
290 | + qtest_quit(qts); | ||
291 | +} | ||
292 | + | ||
293 | +/* Check the SMBus returns a NACK for an invalid address. */ | ||
294 | +static void test_invalid_addr(gconstpointer data) | ||
295 | +{ | ||
296 | + intptr_t index = (intptr_t)data; | ||
297 | + uint64_t base_addr = SMBUS_ADDR(index); | ||
298 | + int irq = SMBUS_IRQ(index); | ||
299 | + QTestState *qts = qtest_init("-machine npcm750-evb"); | ||
300 | + | ||
301 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
302 | + enable_bus(qts, base_addr); | ||
303 | + g_assert_false(qtest_get_irq(qts, irq)); | ||
304 | + start_transfer(qts, base_addr); | ||
305 | + send_address(qts, base_addr, INVALID_DEVICE_ADDR, false, false); | ||
306 | + g_assert_true(qtest_get_irq(qts, irq)); | ||
307 | + stop_transfer(qts, base_addr); | ||
308 | + check_running(qts, base_addr); | ||
309 | + qtest_writeb(qts, base_addr + OFFSET_ST, ST_NEGACK); | ||
310 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_ST) & ST_NEGACK); | ||
311 | + check_stopped(qts, base_addr); | ||
312 | + qtest_quit(qts); | ||
313 | +} | ||
314 | + | ||
315 | +/* Check the SMBus can send and receive bytes to a device in single mode. */ | ||
316 | +static void test_single_mode(gconstpointer data) | ||
317 | +{ | ||
318 | + intptr_t index = (intptr_t)data; | ||
319 | + uint64_t base_addr = SMBUS_ADDR(index); | ||
320 | + int irq = SMBUS_IRQ(index); | ||
321 | + uint8_t value = 0x60; | ||
322 | + QTestState *qts = qtest_init("-machine npcm750-evb"); | ||
323 | + | ||
324 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
325 | + enable_bus(qts, base_addr); | ||
326 | + | ||
327 | + /* Sending */ | ||
328 | + g_assert_false(qtest_get_irq(qts, irq)); | ||
329 | + start_transfer(qts, base_addr); | ||
330 | + g_assert_true(qtest_get_irq(qts, irq)); | ||
331 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); | ||
332 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); | ||
333 | + send_byte(qts, base_addr, value); | ||
334 | + stop_transfer(qts, base_addr); | ||
335 | + check_stopped(qts, base_addr); | ||
336 | + | ||
337 | + /* Receiving */ | ||
338 | + start_transfer(qts, base_addr); | ||
339 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); | ||
340 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); | ||
341 | + start_transfer(qts, base_addr); | ||
342 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, true, true); | ||
343 | + send_nack(qts, base_addr); | ||
344 | + stop_transfer(qts, base_addr); | ||
345 | + check_running(qts, base_addr); | ||
346 | + g_assert_cmphex(recv_byte(qts, base_addr), ==, value); | ||
347 | + check_stopped(qts, base_addr); | ||
348 | + qtest_quit(qts); | ||
349 | +} | ||
350 | + | ||
351 | +static void smbus_add_test(const char *name, int index, GTestDataFunc fn) | ||
352 | +{ | ||
353 | + g_autofree char *full_name = g_strdup_printf( | ||
354 | + "npcm7xx_smbus[%d]/%s", index, name); | ||
355 | + qtest_add_data_func(full_name, (void *)(intptr_t)index, fn); | ||
356 | +} | ||
357 | +#define add_test(name, td) smbus_add_test(#name, td, test_##name) | ||
81 | + | 358 | + |
82 | +int main(int argc, char **argv) | 359 | +int main(int argc, char **argv) |
83 | +{ | 360 | +{ |
84 | + int r; | 361 | + int i; |
85 | + | 362 | + |
86 | + g_test_init(&argc, &argv, NULL); | 363 | + g_test_init(&argc, &argv, NULL); |
87 | + | 364 | + g_test_set_nonfatal_assertions(); |
88 | + qtest_start("-machine mps2-an385"); | 365 | + |
89 | + | 366 | + for (i = 0; i < NR_SMBUS_DEVICES; ++i) { |
90 | + qtest_add_func("/cmsdk-apb-timer/timer", test_timer); | 367 | + add_test(disable_bus, i); |
91 | + | 368 | + add_test(invalid_addr, i); |
92 | + r = g_test_run(); | 369 | + } |
93 | + | 370 | + |
94 | + qtest_end(); | 371 | + for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) { |
95 | + | 372 | + add_test(single_mode, evb_bus_list[i]); |
96 | + return r; | 373 | + } |
97 | +} | 374 | + |
98 | diff --git a/MAINTAINERS b/MAINTAINERS | 375 | + return g_test_run(); |
99 | index XXXXXXX..XXXXXXX 100644 | 376 | +} |
100 | --- a/MAINTAINERS | ||
101 | +++ b/MAINTAINERS | ||
102 | @@ -XXX,XX +XXX,XX @@ F: include/hw/rtc/pl031.h | ||
103 | F: include/hw/arm/primecell.h | ||
104 | F: hw/timer/cmsdk-apb-timer.c | ||
105 | F: include/hw/timer/cmsdk-apb-timer.h | ||
106 | +F: tests/qtest/cmsdk-apb-timer-test.c | ||
107 | F: hw/timer/cmsdk-apb-dualtimer.c | ||
108 | F: include/hw/timer/cmsdk-apb-dualtimer.h | ||
109 | F: hw/char/cmsdk-apb-uart.c | ||
110 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 377 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
111 | index XXXXXXX..XXXXXXX 100644 | 378 | index XXXXXXX..XXXXXXX 100644 |
112 | --- a/tests/qtest/meson.build | 379 | --- a/tests/qtest/meson.build |
113 | +++ b/tests/qtest/meson.build | 380 | +++ b/tests/qtest/meson.build |
114 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ | 381 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ |
382 | 'npcm7xx_gpio-test', | ||
383 | 'npcm7xx_pwm-test', | ||
384 | 'npcm7xx_rng-test', | ||
385 | + 'npcm7xx_smbus-test', | ||
115 | 'npcm7xx_timer-test', | 386 | 'npcm7xx_timer-test', |
116 | 'npcm7xx_watchdog_timer-test'] | 387 | 'npcm7xx_watchdog_timer-test'] |
117 | qtests_arm = \ | 388 | qtests_arm = \ |
118 | + (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ | ||
119 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | ||
120 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
121 | ['arm-cpu-features', | ||
122 | -- | 389 | -- |
123 | 2.20.1 | 390 | 2.20.1 |
124 | 391 | ||
125 | 392 | diff view generated by jsdifflib |
1 | From: Hao Wu <wuhaotsh@google.com> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Fix potential overflow problem when calculating pwm_duty. | 3 | This patch implements the FIFO mode of the SMBus module. In FIFO, the |
4 | 1. Ensure p->cmr and p->cnr to be from [0,65535], according to the | 4 | user transmits or receives at most 16 bytes at a time. The FIFO mode |
5 | hardware specification. | 5 | allows the module to transmit large amount of data faster than single |
6 | 2. Changed duty to uint32_t. However, since MAX_DUTY * (p->cmr+1) | 6 | byte mode. |
7 | can excceed UINT32_MAX, we convert them to uint64_t in computation | ||
8 | and converted them back to uint32_t. | ||
9 | (duty is guaranteed to be <= MAX_DUTY so it won't overflow.) | ||
10 | 7 | ||
11 | Fixes: CID 1442342 | 8 | Since we only added the device in a patch that is only a few commits |
12 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | 9 | away in the same patch set. We do not increase the VMstate version |
13 | Reviewed-by: Doug Evans <dje@google.com> | 10 | number in this special case. |
11 | |||
12 | Reviewed-by: Doug Evans<dje@google.com> | ||
13 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> | ||
14 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | 14 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
15 | Message-id: 20210127011142.2122790-1-wuhaotsh@google.com | 15 | Reviewed-by: Corey Minyard <cminyard@mvista.com> |
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Message-id: 20210210220426.3577804-6-wuhaotsh@google.com |
17 | Acked-by: Corey Minyard <cminyard@mvista.com> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 19 | --- |
19 | hw/misc/npcm7xx_pwm.c | 23 +++++++++++++++++++---- | 20 | include/hw/i2c/npcm7xx_smbus.h | 25 +++ |
20 | tests/qtest/npcm7xx_pwm-test.c | 4 ++-- | 21 | hw/i2c/npcm7xx_smbus.c | 342 +++++++++++++++++++++++++++++-- |
21 | 2 files changed, 21 insertions(+), 6 deletions(-) | 22 | tests/qtest/npcm7xx_smbus-test.c | 149 +++++++++++++- |
23 | hw/i2c/trace-events | 1 + | ||
24 | 4 files changed, 501 insertions(+), 16 deletions(-) | ||
22 | 25 | ||
23 | diff --git a/hw/misc/npcm7xx_pwm.c b/hw/misc/npcm7xx_pwm.c | 26 | diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h |
24 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/hw/misc/npcm7xx_pwm.c | 28 | --- a/include/hw/i2c/npcm7xx_smbus.h |
26 | +++ b/hw/misc/npcm7xx_pwm.c | 29 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
27 | @@ -XXX,XX +XXX,XX @@ REG32(NPCM7XX_PWM_PWDR3, 0x50); | 30 | @@ -XXX,XX +XXX,XX @@ |
28 | #define NPCM7XX_CH_INV BIT(2) | 31 | */ |
29 | #define NPCM7XX_CH_MOD BIT(3) | 32 | #define NPCM7XX_SMBUS_NR_ADDRS 10 |
30 | 33 | ||
31 | +#define NPCM7XX_MAX_CMR 65535 | 34 | +/* Size of the FIFO buffer. */ |
32 | +#define NPCM7XX_MAX_CNR 65535 | 35 | +#define NPCM7XX_SMBUS_FIFO_SIZE 16 |
33 | + | 36 | + |
34 | /* Offset of each PWM channel's prescaler in the PPR register. */ | 37 | typedef enum NPCM7xxSMBusStatus { |
35 | static const int npcm7xx_ppr_base[] = { 0, 0, 8, 8 }; | 38 | NPCM7XX_SMBUS_STATUS_IDLE, |
36 | /* Offset of each PWM channel's clock selector in the CSR register. */ | 39 | NPCM7XX_SMBUS_STATUS_SENDING, |
37 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_pwm_calculate_freq(NPCM7xxPWM *p) | 40 | @@ -XXX,XX +XXX,XX @@ typedef enum NPCM7xxSMBusStatus { |
38 | 41 | * @addr: The SMBus module's own addresses on the I2C bus. | |
39 | static uint32_t npcm7xx_pwm_calculate_duty(NPCM7xxPWM *p) | 42 | * @scllt: The SCL low time register. |
43 | * @sclht: The SCL high time register. | ||
44 | + * @fif_ctl: The FIFO control register. | ||
45 | + * @fif_cts: The FIFO control status register. | ||
46 | + * @fair_per: The fair preriod register. | ||
47 | + * @txf_ctl: The transmit FIFO control register. | ||
48 | + * @t_out: The SMBus timeout register. | ||
49 | + * @txf_sts: The transmit FIFO status register. | ||
50 | + * @rxf_sts: The receive FIFO status register. | ||
51 | + * @rxf_ctl: The receive FIFO control register. | ||
52 | + * @rx_fifo: The FIFO buffer for receiving in FIFO mode. | ||
53 | + * @rx_cur: The current position of rx_fifo. | ||
54 | * @status: The current status of the SMBus. | ||
55 | */ | ||
56 | typedef struct NPCM7xxSMBusState { | ||
57 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxSMBusState { | ||
58 | uint8_t scllt; | ||
59 | uint8_t sclht; | ||
60 | |||
61 | + uint8_t fif_ctl; | ||
62 | + uint8_t fif_cts; | ||
63 | + uint8_t fair_per; | ||
64 | + uint8_t txf_ctl; | ||
65 | + uint8_t t_out; | ||
66 | + uint8_t txf_sts; | ||
67 | + uint8_t rxf_sts; | ||
68 | + uint8_t rxf_ctl; | ||
69 | + | ||
70 | + uint8_t rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE]; | ||
71 | + uint8_t rx_cur; | ||
72 | + | ||
73 | NPCM7xxSMBusStatus status; | ||
74 | } NPCM7xxSMBusState; | ||
75 | |||
76 | diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/hw/i2c/npcm7xx_smbus.c | ||
79 | +++ b/hw/i2c/npcm7xx_smbus.c | ||
80 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
81 | #define NPCM7XX_ADDR_EN BIT(7) | ||
82 | #define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6) | ||
83 | |||
84 | +/* FIFO Mode Register Fields */ | ||
85 | +/* FIF_CTL fields */ | ||
86 | +#define NPCM7XX_SMBFIF_CTL_FIFO_EN BIT(4) | ||
87 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY_IE BIT(2) | ||
88 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY BIT(1) | ||
89 | +#define NPCM7XX_SMBFIF_CTL_FAIR_BUSY BIT(0) | ||
90 | +/* FIF_CTS fields */ | ||
91 | +#define NPCM7XX_SMBFIF_CTS_STR BIT(7) | ||
92 | +#define NPCM7XX_SMBFIF_CTS_CLR_FIFO BIT(6) | ||
93 | +#define NPCM7XX_SMBFIF_CTS_RFTE_IE BIT(3) | ||
94 | +#define NPCM7XX_SMBFIF_CTS_RXF_TXE BIT(1) | ||
95 | +/* TXF_CTL fields */ | ||
96 | +#define NPCM7XX_SMBTXF_CTL_THR_TXIE BIT(6) | ||
97 | +#define NPCM7XX_SMBTXF_CTL_TX_THR(rv) extract8((rv), 0, 5) | ||
98 | +/* T_OUT fields */ | ||
99 | +#define NPCM7XX_SMBT_OUT_ST BIT(7) | ||
100 | +#define NPCM7XX_SMBT_OUT_IE BIT(6) | ||
101 | +#define NPCM7XX_SMBT_OUT_CLKDIV(rv) extract8((rv), 0, 6) | ||
102 | +/* TXF_STS fields */ | ||
103 | +#define NPCM7XX_SMBTXF_STS_TX_THST BIT(6) | ||
104 | +#define NPCM7XX_SMBTXF_STS_TX_BYTES(rv) extract8((rv), 0, 5) | ||
105 | +/* RXF_STS fields */ | ||
106 | +#define NPCM7XX_SMBRXF_STS_RX_THST BIT(6) | ||
107 | +#define NPCM7XX_SMBRXF_STS_RX_BYTES(rv) extract8((rv), 0, 5) | ||
108 | +/* RXF_CTL fields */ | ||
109 | +#define NPCM7XX_SMBRXF_CTL_THR_RXIE BIT(6) | ||
110 | +#define NPCM7XX_SMBRXF_CTL_LAST BIT(5) | ||
111 | +#define NPCM7XX_SMBRXF_CTL_RX_THR(rv) extract8((rv), 0, 5) | ||
112 | + | ||
113 | #define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b))) | ||
114 | #define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o)) | ||
115 | |||
116 | #define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE) | ||
117 | +#define NPCM7XX_SMBUS_FIFO_ENABLED(s) ((s)->fif_ctl & \ | ||
118 | + NPCM7XX_SMBFIF_CTL_FIFO_EN) | ||
119 | |||
120 | /* VERSION fields values, read-only. */ | ||
121 | #define NPCM7XX_SMBUS_VERSION_NUMBER 1 | ||
122 | -#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0 | ||
123 | +#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 1 | ||
124 | |||
125 | /* Reset values */ | ||
126 | #define NPCM7XX_SMB_ST_INIT_VAL 0x00 | ||
127 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
128 | #define NPCM7XX_SMB_ADDR_INIT_VAL 0x00 | ||
129 | #define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00 | ||
130 | #define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00 | ||
131 | +#define NPCM7XX_SMB_FIF_CTL_INIT_VAL 0x00 | ||
132 | +#define NPCM7XX_SMB_FIF_CTS_INIT_VAL 0x00 | ||
133 | +#define NPCM7XX_SMB_FAIR_PER_INIT_VAL 0x00 | ||
134 | +#define NPCM7XX_SMB_TXF_CTL_INIT_VAL 0x00 | ||
135 | +#define NPCM7XX_SMB_T_OUT_INIT_VAL 0x3f | ||
136 | +#define NPCM7XX_SMB_TXF_STS_INIT_VAL 0x00 | ||
137 | +#define NPCM7XX_SMB_RXF_STS_INIT_VAL 0x00 | ||
138 | +#define NPCM7XX_SMB_RXF_CTL_INIT_VAL 0x01 | ||
139 | |||
140 | static uint8_t npcm7xx_smbus_get_version(void) | ||
40 | { | 141 | { |
41 | - uint64_t duty; | 142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s) |
42 | + uint32_t duty; | 143 | (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE && |
43 | 144 | s->st & NPCM7XX_SMBST_SDAST) || | |
44 | if (p->running) { | 145 | (s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE && |
45 | if (p->cnr == 0) { | 146 | - s->cst3 & NPCM7XX_SMBCST3_EO_BUSY)); |
46 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_pwm_calculate_duty(NPCM7xxPWM *p) | 147 | + s->cst3 & NPCM7XX_SMBCST3_EO_BUSY) || |
47 | } else if (p->cmr >= p->cnr) { | 148 | + (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE && |
48 | duty = NPCM7XX_PWM_MAX_DUTY; | 149 | + s->rxf_sts & NPCM7XX_SMBRXF_STS_RX_THST) || |
150 | + (s->txf_ctl & NPCM7XX_SMBTXF_CTL_THR_TXIE && | ||
151 | + s->txf_sts & NPCM7XX_SMBTXF_STS_TX_THST) || | ||
152 | + (s->fif_cts & NPCM7XX_SMBFIF_CTS_RFTE_IE && | ||
153 | + s->fif_cts & NPCM7XX_SMBFIF_CTS_RXF_TXE)); | ||
154 | |||
155 | if (level) { | ||
156 | s->cst2 |= NPCM7XX_SMBCST2_INTSTS; | ||
157 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s) | ||
158 | s->status = NPCM7XX_SMBUS_STATUS_NEGACK; | ||
159 | } | ||
160 | |||
161 | +static void npcm7xx_smbus_clear_buffer(NPCM7xxSMBusState *s) | ||
162 | +{ | ||
163 | + s->fif_cts &= ~NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
164 | + s->txf_sts = 0; | ||
165 | + s->rxf_sts = 0; | ||
166 | +} | ||
167 | + | ||
168 | static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) | ||
169 | { | ||
170 | int rv = i2c_send(s->bus, value); | ||
171 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) | ||
172 | npcm7xx_smbus_nack(s); | ||
173 | } else { | ||
174 | s->st |= NPCM7XX_SMBST_SDAST; | ||
175 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
176 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
177 | + if (NPCM7XX_SMBTXF_STS_TX_BYTES(s->txf_sts) == | ||
178 | + NPCM7XX_SMBTXF_CTL_TX_THR(s->txf_ctl)) { | ||
179 | + s->txf_sts = NPCM7XX_SMBTXF_STS_TX_THST; | ||
180 | + } else { | ||
181 | + s->txf_sts = 0; | ||
182 | + } | ||
183 | + } | ||
184 | } | ||
185 | trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv); | ||
186 | npcm7xx_smbus_update_irq(s); | ||
187 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s) | ||
188 | npcm7xx_smbus_update_irq(s); | ||
189 | } | ||
190 | |||
191 | +static void npcm7xx_smbus_recv_fifo(NPCM7xxSMBusState *s) | ||
192 | +{ | ||
193 | + uint8_t expected_bytes = NPCM7XX_SMBRXF_CTL_RX_THR(s->rxf_ctl); | ||
194 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); | ||
195 | + uint8_t pos; | ||
196 | + | ||
197 | + if (received_bytes == expected_bytes) { | ||
198 | + return; | ||
199 | + } | ||
200 | + | ||
201 | + while (received_bytes < expected_bytes && | ||
202 | + received_bytes < NPCM7XX_SMBUS_FIFO_SIZE) { | ||
203 | + pos = (s->rx_cur + received_bytes) % NPCM7XX_SMBUS_FIFO_SIZE; | ||
204 | + s->rx_fifo[pos] = i2c_recv(s->bus); | ||
205 | + trace_npcm7xx_smbus_recv_byte((DEVICE(s)->canonical_path), | ||
206 | + s->rx_fifo[pos]); | ||
207 | + ++received_bytes; | ||
208 | + } | ||
209 | + | ||
210 | + trace_npcm7xx_smbus_recv_fifo((DEVICE(s)->canonical_path), | ||
211 | + received_bytes, expected_bytes); | ||
212 | + s->rxf_sts = received_bytes; | ||
213 | + if (unlikely(received_bytes < expected_bytes)) { | ||
214 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
215 | + "%s: invalid rx_thr value: 0x%02x\n", | ||
216 | + DEVICE(s)->canonical_path, expected_bytes); | ||
217 | + return; | ||
218 | + } | ||
219 | + | ||
220 | + s->rxf_sts |= NPCM7XX_SMBRXF_STS_RX_THST; | ||
221 | + if (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_LAST) { | ||
222 | + trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path); | ||
223 | + i2c_nack(s->bus); | ||
224 | + s->rxf_ctl &= ~NPCM7XX_SMBRXF_CTL_LAST; | ||
225 | + } | ||
226 | + if (received_bytes == NPCM7XX_SMBUS_FIFO_SIZE) { | ||
227 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
228 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
229 | + } else if (!(s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE)) { | ||
230 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
231 | + } else { | ||
232 | + s->st &= ~NPCM7XX_SMBST_SDAST; | ||
233 | + } | ||
234 | + npcm7xx_smbus_update_irq(s); | ||
235 | +} | ||
236 | + | ||
237 | +static void npcm7xx_smbus_read_byte_fifo(NPCM7xxSMBusState *s) | ||
238 | +{ | ||
239 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); | ||
240 | + | ||
241 | + if (received_bytes == 0) { | ||
242 | + npcm7xx_smbus_recv_fifo(s); | ||
243 | + return; | ||
244 | + } | ||
245 | + | ||
246 | + s->sda = s->rx_fifo[s->rx_cur]; | ||
247 | + s->rx_cur = (s->rx_cur + 1u) % NPCM7XX_SMBUS_FIFO_SIZE; | ||
248 | + --s->rxf_sts; | ||
249 | + npcm7xx_smbus_update_irq(s); | ||
250 | +} | ||
251 | + | ||
252 | static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) | ||
253 | { | ||
254 | /* | ||
255 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) | ||
256 | if (available) { | ||
257 | s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST; | ||
258 | s->cst |= NPCM7XX_SMBCST_BUSY; | ||
259 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
260 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
261 | + } | ||
262 | } else { | ||
263 | s->st &= ~NPCM7XX_SMBST_MODE; | ||
264 | s->cst &= ~NPCM7XX_SMBCST_BUSY; | ||
265 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value) | ||
266 | s->st |= NPCM7XX_SMBST_SDAST; | ||
267 | } | ||
268 | } else if (recv) { | ||
269 | - npcm7xx_smbus_recv_byte(s); | ||
270 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
271 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
272 | + npcm7xx_smbus_recv_fifo(s); | ||
273 | + } else { | ||
274 | + npcm7xx_smbus_recv_byte(s); | ||
275 | + } | ||
276 | + } else if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
277 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
278 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
279 | } | ||
280 | npcm7xx_smbus_update_irq(s); | ||
281 | } | ||
282 | @@ -XXX,XX +XXX,XX @@ static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s) | ||
283 | |||
284 | switch (s->status) { | ||
285 | case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE: | ||
286 | - npcm7xx_smbus_execute_stop(s); | ||
287 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
288 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) <= 1) { | ||
289 | + npcm7xx_smbus_execute_stop(s); | ||
290 | + } | ||
291 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) == 0) { | ||
292 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
293 | + "%s: read to SDA with an empty rx-fifo buffer, " | ||
294 | + "result undefined: %u\n", | ||
295 | + DEVICE(s)->canonical_path, s->sda); | ||
296 | + break; | ||
297 | + } | ||
298 | + npcm7xx_smbus_read_byte_fifo(s); | ||
299 | + value = s->sda; | ||
300 | + } else { | ||
301 | + npcm7xx_smbus_execute_stop(s); | ||
302 | + } | ||
303 | break; | ||
304 | |||
305 | case NPCM7XX_SMBUS_STATUS_RECEIVING: | ||
306 | - npcm7xx_smbus_recv_byte(s); | ||
307 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
308 | + npcm7xx_smbus_read_byte_fifo(s); | ||
309 | + value = s->sda; | ||
310 | + } else { | ||
311 | + npcm7xx_smbus_recv_byte(s); | ||
312 | + } | ||
313 | break; | ||
314 | |||
315 | default: | ||
316 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value) | ||
317 | } | ||
318 | |||
319 | if (value & NPCM7XX_SMBST_STASTR && | ||
320 | - s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
321 | - npcm7xx_smbus_recv_byte(s); | ||
322 | + s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
323 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
324 | + npcm7xx_smbus_recv_fifo(s); | ||
325 | + } else { | ||
326 | + npcm7xx_smbus_recv_byte(s); | ||
327 | + } | ||
328 | } | ||
329 | |||
330 | npcm7xx_smbus_update_irq(s); | ||
331 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value) | ||
332 | s->st = 0; | ||
333 | s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY); | ||
334 | s->cst = 0; | ||
335 | + npcm7xx_smbus_clear_buffer(s); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value) | ||
340 | NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL); | ||
341 | } | ||
342 | |||
343 | +static void npcm7xx_smbus_write_fif_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
344 | +{ | ||
345 | + uint8_t new_ctl = value; | ||
346 | + | ||
347 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_RDY); | ||
348 | + new_ctl = WRITE_ONE_CLEAR(new_ctl, value, NPCM7XX_SMBFIF_CTL_FAIR_RDY); | ||
349 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_BUSY); | ||
350 | + s->fif_ctl = new_ctl; | ||
351 | +} | ||
352 | + | ||
353 | +static void npcm7xx_smbus_write_fif_cts(NPCM7xxSMBusState *s, uint8_t value) | ||
354 | +{ | ||
355 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_STR); | ||
356 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_RXF_TXE); | ||
357 | + s->fif_cts = KEEP_OLD_BIT(value, s->fif_cts, NPCM7XX_SMBFIF_CTS_RFTE_IE); | ||
358 | + | ||
359 | + if (value & NPCM7XX_SMBFIF_CTS_CLR_FIFO) { | ||
360 | + npcm7xx_smbus_clear_buffer(s); | ||
361 | + } | ||
362 | +} | ||
363 | + | ||
364 | +static void npcm7xx_smbus_write_txf_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
365 | +{ | ||
366 | + s->txf_ctl = value; | ||
367 | +} | ||
368 | + | ||
369 | +static void npcm7xx_smbus_write_t_out(NPCM7xxSMBusState *s, uint8_t value) | ||
370 | +{ | ||
371 | + uint8_t new_t_out = value; | ||
372 | + | ||
373 | + if ((value & NPCM7XX_SMBT_OUT_ST) || (!(s->t_out & NPCM7XX_SMBT_OUT_ST))) { | ||
374 | + new_t_out &= ~NPCM7XX_SMBT_OUT_ST; | ||
375 | + } else { | ||
376 | + new_t_out |= NPCM7XX_SMBT_OUT_ST; | ||
377 | + } | ||
378 | + | ||
379 | + s->t_out = new_t_out; | ||
380 | +} | ||
381 | + | ||
382 | +static void npcm7xx_smbus_write_txf_sts(NPCM7xxSMBusState *s, uint8_t value) | ||
383 | +{ | ||
384 | + s->txf_sts = WRITE_ONE_CLEAR(s->txf_sts, value, NPCM7XX_SMBTXF_STS_TX_THST); | ||
385 | +} | ||
386 | + | ||
387 | +static void npcm7xx_smbus_write_rxf_sts(NPCM7xxSMBusState *s, uint8_t value) | ||
388 | +{ | ||
389 | + if (value & NPCM7XX_SMBRXF_STS_RX_THST) { | ||
390 | + s->rxf_sts &= ~NPCM7XX_SMBRXF_STS_RX_THST; | ||
391 | + if (s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
392 | + npcm7xx_smbus_recv_fifo(s); | ||
393 | + } | ||
394 | + } | ||
395 | +} | ||
396 | + | ||
397 | +static void npcm7xx_smbus_write_rxf_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
398 | +{ | ||
399 | + uint8_t new_ctl = value; | ||
400 | + | ||
401 | + if (!(value & NPCM7XX_SMBRXF_CTL_LAST)) { | ||
402 | + new_ctl = KEEP_OLD_BIT(s->rxf_ctl, new_ctl, NPCM7XX_SMBRXF_CTL_LAST); | ||
403 | + } | ||
404 | + s->rxf_ctl = new_ctl; | ||
405 | +} | ||
406 | + | ||
407 | static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
408 | { | ||
409 | NPCM7xxSMBusState *s = opaque; | ||
410 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
411 | default: | ||
412 | if (bank) { | ||
413 | /* Bank 1 */ | ||
414 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
415 | - "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
416 | - DEVICE(s)->canonical_path, offset); | ||
417 | + switch (offset) { | ||
418 | + case NPCM7XX_SMB_FIF_CTS: | ||
419 | + value = s->fif_cts; | ||
420 | + break; | ||
421 | + | ||
422 | + case NPCM7XX_SMB_FAIR_PER: | ||
423 | + value = s->fair_per; | ||
424 | + break; | ||
425 | + | ||
426 | + case NPCM7XX_SMB_TXF_CTL: | ||
427 | + value = s->txf_ctl; | ||
428 | + break; | ||
429 | + | ||
430 | + case NPCM7XX_SMB_T_OUT: | ||
431 | + value = s->t_out; | ||
432 | + break; | ||
433 | + | ||
434 | + case NPCM7XX_SMB_TXF_STS: | ||
435 | + value = s->txf_sts; | ||
436 | + break; | ||
437 | + | ||
438 | + case NPCM7XX_SMB_RXF_STS: | ||
439 | + value = s->rxf_sts; | ||
440 | + break; | ||
441 | + | ||
442 | + case NPCM7XX_SMB_RXF_CTL: | ||
443 | + value = s->rxf_ctl; | ||
444 | + break; | ||
445 | + | ||
446 | + default: | ||
447 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
448 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
449 | + DEVICE(s)->canonical_path, offset); | ||
450 | + break; | ||
451 | + } | ||
49 | } else { | 452 | } else { |
50 | - duty = NPCM7XX_PWM_MAX_DUTY * (p->cmr + 1) / (p->cnr + 1); | 453 | /* Bank 0 */ |
51 | + duty = (uint64_t)NPCM7XX_PWM_MAX_DUTY * (p->cmr + 1) / (p->cnr + 1); | 454 | switch (offset) { |
455 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
456 | value = s->scllt; | ||
457 | break; | ||
458 | |||
459 | + case NPCM7XX_SMB_FIF_CTL: | ||
460 | + value = s->fif_ctl; | ||
461 | + break; | ||
462 | + | ||
463 | case NPCM7XX_SMB_SCLHT: | ||
464 | value = s->sclht; | ||
465 | break; | ||
466 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value, | ||
467 | default: | ||
468 | if (bank) { | ||
469 | /* Bank 1 */ | ||
470 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
471 | - "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
472 | - DEVICE(s)->canonical_path, offset); | ||
473 | + switch (offset) { | ||
474 | + case NPCM7XX_SMB_FIF_CTS: | ||
475 | + npcm7xx_smbus_write_fif_cts(s, value); | ||
476 | + break; | ||
477 | + | ||
478 | + case NPCM7XX_SMB_FAIR_PER: | ||
479 | + s->fair_per = value; | ||
480 | + break; | ||
481 | + | ||
482 | + case NPCM7XX_SMB_TXF_CTL: | ||
483 | + npcm7xx_smbus_write_txf_ctl(s, value); | ||
484 | + break; | ||
485 | + | ||
486 | + case NPCM7XX_SMB_T_OUT: | ||
487 | + npcm7xx_smbus_write_t_out(s, value); | ||
488 | + break; | ||
489 | + | ||
490 | + case NPCM7XX_SMB_TXF_STS: | ||
491 | + npcm7xx_smbus_write_txf_sts(s, value); | ||
492 | + break; | ||
493 | + | ||
494 | + case NPCM7XX_SMB_RXF_STS: | ||
495 | + npcm7xx_smbus_write_rxf_sts(s, value); | ||
496 | + break; | ||
497 | + | ||
498 | + case NPCM7XX_SMB_RXF_CTL: | ||
499 | + npcm7xx_smbus_write_rxf_ctl(s, value); | ||
500 | + break; | ||
501 | + | ||
502 | + default: | ||
503 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
504 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
505 | + DEVICE(s)->canonical_path, offset); | ||
506 | + break; | ||
507 | + } | ||
508 | } else { | ||
509 | /* Bank 0 */ | ||
510 | switch (offset) { | ||
511 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value, | ||
512 | s->scllt = value; | ||
513 | break; | ||
514 | |||
515 | + case NPCM7XX_SMB_FIF_CTL: | ||
516 | + npcm7xx_smbus_write_fif_ctl(s, value); | ||
517 | + break; | ||
518 | + | ||
519 | case NPCM7XX_SMB_SCLHT: | ||
520 | s->sclht = value; | ||
521 | break; | ||
522 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type) | ||
523 | s->scllt = NPCM7XX_SMB_SCLLT_INIT_VAL; | ||
524 | s->sclht = NPCM7XX_SMB_SCLHT_INIT_VAL; | ||
525 | |||
526 | + s->fif_ctl = NPCM7XX_SMB_FIF_CTL_INIT_VAL; | ||
527 | + s->fif_cts = NPCM7XX_SMB_FIF_CTS_INIT_VAL; | ||
528 | + s->fair_per = NPCM7XX_SMB_FAIR_PER_INIT_VAL; | ||
529 | + s->txf_ctl = NPCM7XX_SMB_TXF_CTL_INIT_VAL; | ||
530 | + s->t_out = NPCM7XX_SMB_T_OUT_INIT_VAL; | ||
531 | + s->txf_sts = NPCM7XX_SMB_TXF_STS_INIT_VAL; | ||
532 | + s->rxf_sts = NPCM7XX_SMB_RXF_STS_INIT_VAL; | ||
533 | + s->rxf_ctl = NPCM7XX_SMB_RXF_CTL_INIT_VAL; | ||
534 | + | ||
535 | + npcm7xx_smbus_clear_buffer(s); | ||
536 | s->status = NPCM7XX_SMBUS_STATUS_IDLE; | ||
537 | + s->rx_cur = 0; | ||
538 | } | ||
539 | |||
540 | static void npcm7xx_smbus_hold_reset(Object *obj) | ||
541 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_npcm7xx_smbus = { | ||
542 | VMSTATE_UINT8_ARRAY(addr, NPCM7xxSMBusState, NPCM7XX_SMBUS_NR_ADDRS), | ||
543 | VMSTATE_UINT8(scllt, NPCM7xxSMBusState), | ||
544 | VMSTATE_UINT8(sclht, NPCM7xxSMBusState), | ||
545 | + VMSTATE_UINT8(fif_ctl, NPCM7xxSMBusState), | ||
546 | + VMSTATE_UINT8(fif_cts, NPCM7xxSMBusState), | ||
547 | + VMSTATE_UINT8(fair_per, NPCM7xxSMBusState), | ||
548 | + VMSTATE_UINT8(txf_ctl, NPCM7xxSMBusState), | ||
549 | + VMSTATE_UINT8(t_out, NPCM7xxSMBusState), | ||
550 | + VMSTATE_UINT8(txf_sts, NPCM7xxSMBusState), | ||
551 | + VMSTATE_UINT8(rxf_sts, NPCM7xxSMBusState), | ||
552 | + VMSTATE_UINT8(rxf_ctl, NPCM7xxSMBusState), | ||
553 | + VMSTATE_UINT8_ARRAY(rx_fifo, NPCM7xxSMBusState, | ||
554 | + NPCM7XX_SMBUS_FIFO_SIZE), | ||
555 | + VMSTATE_UINT8(rx_cur, NPCM7xxSMBusState), | ||
556 | VMSTATE_END_OF_LIST(), | ||
557 | }, | ||
558 | }; | ||
559 | diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c | ||
560 | index XXXXXXX..XXXXXXX 100644 | ||
561 | --- a/tests/qtest/npcm7xx_smbus-test.c | ||
562 | +++ b/tests/qtest/npcm7xx_smbus-test.c | ||
563 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
564 | #define ADDR_EN BIT(7) | ||
565 | #define ADDR_A(rv) extract8((rv), 0, 6) | ||
566 | |||
567 | +/* FIF_CTL fields */ | ||
568 | +#define FIF_CTL_FIFO_EN BIT(4) | ||
569 | + | ||
570 | +/* FIF_CTS fields */ | ||
571 | +#define FIF_CTS_CLR_FIFO BIT(6) | ||
572 | +#define FIF_CTS_RFTE_IE BIT(3) | ||
573 | +#define FIF_CTS_RXF_TXE BIT(1) | ||
574 | + | ||
575 | +/* TXF_CTL fields */ | ||
576 | +#define TXF_CTL_THR_TXIE BIT(6) | ||
577 | +#define TXF_CTL_TX_THR(rv) extract8((rv), 0, 5) | ||
578 | + | ||
579 | +/* TXF_STS fields */ | ||
580 | +#define TXF_STS_TX_THST BIT(6) | ||
581 | +#define TXF_STS_TX_BYTES(rv) extract8((rv), 0, 5) | ||
582 | + | ||
583 | +/* RXF_CTL fields */ | ||
584 | +#define RXF_CTL_THR_RXIE BIT(6) | ||
585 | +#define RXF_CTL_LAST BIT(5) | ||
586 | +#define RXF_CTL_RX_THR(rv) extract8((rv), 0, 5) | ||
587 | + | ||
588 | +/* RXF_STS fields */ | ||
589 | +#define RXF_STS_RX_THST BIT(6) | ||
590 | +#define RXF_STS_RX_BYTES(rv) extract8((rv), 0, 5) | ||
591 | + | ||
592 | + | ||
593 | +static void choose_bank(QTestState *qts, uint64_t base_addr, uint8_t bank) | ||
594 | +{ | ||
595 | + uint8_t ctl3 = qtest_readb(qts, base_addr + OFFSET_CTL3); | ||
596 | + | ||
597 | + if (bank) { | ||
598 | + ctl3 |= CTL3_BNK_SEL; | ||
599 | + } else { | ||
600 | + ctl3 &= ~CTL3_BNK_SEL; | ||
601 | + } | ||
602 | + | ||
603 | + qtest_writeb(qts, base_addr + OFFSET_CTL3, ctl3); | ||
604 | +} | ||
605 | |||
606 | static void check_running(QTestState *qts, uint64_t base_addr) | ||
607 | { | ||
608 | @@ -XXX,XX +XXX,XX @@ static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte) | ||
609 | qtest_writeb(qts, base_addr + OFFSET_SDA, byte); | ||
610 | } | ||
611 | |||
612 | +static bool check_recv(QTestState *qts, uint64_t base_addr) | ||
613 | +{ | ||
614 | + uint8_t st, fif_ctl, rxf_ctl, rxf_sts; | ||
615 | + bool fifo; | ||
616 | + | ||
617 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
618 | + choose_bank(qts, base_addr, 0); | ||
619 | + fif_ctl = qtest_readb(qts, base_addr + OFFSET_FIF_CTL); | ||
620 | + fifo = fif_ctl & FIF_CTL_FIFO_EN; | ||
621 | + if (!fifo) { | ||
622 | + return st == (ST_MODE | ST_SDAST); | ||
623 | + } | ||
624 | + | ||
625 | + choose_bank(qts, base_addr, 1); | ||
626 | + rxf_ctl = qtest_readb(qts, base_addr + OFFSET_RXF_CTL); | ||
627 | + rxf_sts = qtest_readb(qts, base_addr + OFFSET_RXF_STS); | ||
628 | + | ||
629 | + if ((rxf_ctl & RXF_CTL_THR_RXIE) && RXF_STS_RX_BYTES(rxf_sts) < 16) { | ||
630 | + return st == ST_MODE; | ||
631 | + } else { | ||
632 | + return st == (ST_MODE | ST_SDAST); | ||
633 | + } | ||
634 | +} | ||
635 | + | ||
636 | static uint8_t recv_byte(QTestState *qts, uint64_t base_addr) | ||
637 | { | ||
638 | - g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
639 | - ST_MODE | ST_SDAST); | ||
640 | + g_assert_true(check_recv(qts, base_addr)); | ||
641 | return qtest_readb(qts, base_addr + OFFSET_SDA); | ||
642 | } | ||
643 | |||
644 | @@ -XXX,XX +XXX,XX @@ static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr, | ||
645 | qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR); | ||
646 | st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
647 | if (recv) { | ||
648 | - g_assert_cmphex(st, ==, ST_MODE | ST_SDAST); | ||
649 | + g_assert_true(check_recv(qts, base_addr)); | ||
650 | } else { | ||
651 | g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST); | ||
52 | } | 652 | } |
53 | } else { | 653 | @@ -XXX,XX +XXX,XX @@ static void send_nack(QTestState *qts, uint64_t base_addr) |
54 | duty = 0; | 654 | qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); |
55 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_pwm_write(void *opaque, hwaddr offset, | 655 | } |
56 | case A_NPCM7XX_PWM_CNR2: | 656 | |
57 | case A_NPCM7XX_PWM_CNR3: | 657 | +static void start_fifo_mode(QTestState *qts, uint64_t base_addr) |
58 | p = &s->pwm[npcm7xx_cnr_index(offset)]; | 658 | +{ |
59 | - p->cnr = value; | 659 | + choose_bank(qts, base_addr, 0); |
60 | + if (value > NPCM7XX_MAX_CNR) { | 660 | + qtest_writeb(qts, base_addr + OFFSET_FIF_CTL, FIF_CTL_FIFO_EN); |
61 | + qemu_log_mask(LOG_GUEST_ERROR, | 661 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTL) & |
62 | + "%s: invalid cnr value: %u", __func__, value); | 662 | + FIF_CTL_FIFO_EN); |
63 | + p->cnr = NPCM7XX_MAX_CNR; | 663 | + choose_bank(qts, base_addr, 1); |
64 | + } else { | 664 | + qtest_writeb(qts, base_addr + OFFSET_FIF_CTS, |
65 | + p->cnr = value; | 665 | + FIF_CTS_CLR_FIFO | FIF_CTS_RFTE_IE); |
66 | + } | 666 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_FIF_CTS), ==, |
67 | npcm7xx_pwm_update_output(p); | 667 | + FIF_CTS_RFTE_IE); |
68 | break; | 668 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_TXF_STS), ==, 0); |
69 | 669 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_RXF_STS), ==, 0); | |
70 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_pwm_write(void *opaque, hwaddr offset, | 670 | +} |
71 | case A_NPCM7XX_PWM_CMR2: | 671 | + |
72 | case A_NPCM7XX_PWM_CMR3: | 672 | +static void start_recv_fifo(QTestState *qts, uint64_t base_addr, uint8_t bytes) |
73 | p = &s->pwm[npcm7xx_cmr_index(offset)]; | 673 | +{ |
74 | - p->cmr = value; | 674 | + choose_bank(qts, base_addr, 1); |
75 | + if (value > NPCM7XX_MAX_CMR) { | 675 | + qtest_writeb(qts, base_addr + OFFSET_TXF_CTL, 0); |
76 | + qemu_log_mask(LOG_GUEST_ERROR, | 676 | + qtest_writeb(qts, base_addr + OFFSET_RXF_CTL, |
77 | + "%s: invalid cmr value: %u", __func__, value); | 677 | + RXF_CTL_THR_RXIE | RXF_CTL_LAST | bytes); |
78 | + p->cmr = NPCM7XX_MAX_CMR; | 678 | +} |
79 | + } else { | 679 | + |
80 | + p->cmr = value; | 680 | /* Check the SMBus's status is set correctly when disabled. */ |
81 | + } | 681 | static void test_disable_bus(gconstpointer data) |
82 | npcm7xx_pwm_update_output(p); | 682 | { |
83 | break; | 683 | @@ -XXX,XX +XXX,XX @@ static void test_single_mode(gconstpointer data) |
84 | 684 | qtest_quit(qts); | |
85 | diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c | 685 | } |
686 | |||
687 | +/* Check the SMBus can send and receive bytes in FIFO mode. */ | ||
688 | +static void test_fifo_mode(gconstpointer data) | ||
689 | +{ | ||
690 | + intptr_t index = (intptr_t)data; | ||
691 | + uint64_t base_addr = SMBUS_ADDR(index); | ||
692 | + int irq = SMBUS_IRQ(index); | ||
693 | + uint8_t value = 0x60; | ||
694 | + QTestState *qts = qtest_init("-machine npcm750-evb"); | ||
695 | + | ||
696 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
697 | + enable_bus(qts, base_addr); | ||
698 | + start_fifo_mode(qts, base_addr); | ||
699 | + g_assert_false(qtest_get_irq(qts, irq)); | ||
700 | + | ||
701 | + /* Sending */ | ||
702 | + start_transfer(qts, base_addr); | ||
703 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); | ||
704 | + choose_bank(qts, base_addr, 1); | ||
705 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) & | ||
706 | + FIF_CTS_RXF_TXE); | ||
707 | + qtest_writeb(qts, base_addr + OFFSET_TXF_CTL, TXF_CTL_THR_TXIE); | ||
708 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); | ||
709 | + send_byte(qts, base_addr, value); | ||
710 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) & | ||
711 | + FIF_CTS_RXF_TXE); | ||
712 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_TXF_STS) & | ||
713 | + TXF_STS_TX_THST); | ||
714 | + g_assert_cmpuint(TXF_STS_TX_BYTES( | ||
715 | + qtest_readb(qts, base_addr + OFFSET_TXF_STS)), ==, 0); | ||
716 | + g_assert_true(qtest_get_irq(qts, irq)); | ||
717 | + stop_transfer(qts, base_addr); | ||
718 | + check_stopped(qts, base_addr); | ||
719 | + | ||
720 | + /* Receiving */ | ||
721 | + start_fifo_mode(qts, base_addr); | ||
722 | + start_transfer(qts, base_addr); | ||
723 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); | ||
724 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); | ||
725 | + start_transfer(qts, base_addr); | ||
726 | + qtest_writeb(qts, base_addr + OFFSET_FIF_CTS, FIF_CTS_RXF_TXE); | ||
727 | + start_recv_fifo(qts, base_addr, 1); | ||
728 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, true, true); | ||
729 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) & | ||
730 | + FIF_CTS_RXF_TXE); | ||
731 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_RXF_STS) & | ||
732 | + RXF_STS_RX_THST); | ||
733 | + g_assert_cmpuint(RXF_STS_RX_BYTES( | ||
734 | + qtest_readb(qts, base_addr + OFFSET_RXF_STS)), ==, 1); | ||
735 | + send_nack(qts, base_addr); | ||
736 | + stop_transfer(qts, base_addr); | ||
737 | + check_running(qts, base_addr); | ||
738 | + g_assert_cmphex(recv_byte(qts, base_addr), ==, value); | ||
739 | + g_assert_cmpuint(RXF_STS_RX_BYTES( | ||
740 | + qtest_readb(qts, base_addr + OFFSET_RXF_STS)), ==, 0); | ||
741 | + check_stopped(qts, base_addr); | ||
742 | + qtest_quit(qts); | ||
743 | +} | ||
744 | + | ||
745 | static void smbus_add_test(const char *name, int index, GTestDataFunc fn) | ||
746 | { | ||
747 | g_autofree char *full_name = g_strdup_printf( | ||
748 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
749 | |||
750 | for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) { | ||
751 | add_test(single_mode, evb_bus_list[i]); | ||
752 | + add_test(fifo_mode, evb_bus_list[i]); | ||
753 | } | ||
754 | |||
755 | return g_test_run(); | ||
756 | diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events | ||
86 | index XXXXXXX..XXXXXXX 100644 | 757 | index XXXXXXX..XXXXXXX 100644 |
87 | --- a/tests/qtest/npcm7xx_pwm-test.c | 758 | --- a/hw/i2c/trace-events |
88 | +++ b/tests/qtest/npcm7xx_pwm-test.c | 759 | +++ b/hw/i2c/trace-events |
89 | @@ -XXX,XX +XXX,XX @@ static uint64_t pwm_compute_freq(QTestState *qts, uint32_t ppr, uint32_t csr, | 760 | @@ -XXX,XX +XXX,XX @@ npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byt |
90 | 761 | npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x" | |
91 | static uint64_t pwm_compute_duty(uint32_t cnr, uint32_t cmr, bool inverted) | 762 | npcm7xx_smbus_stop(const char *id) "%s stopping" |
92 | { | 763 | npcm7xx_smbus_nack(const char *id) "%s nacking" |
93 | - uint64_t duty; | 764 | +npcm7xx_smbus_recv_fifo(const char *id, uint8_t received, uint8_t expected) "%s recv fifo: received %u, expected %u" |
94 | + uint32_t duty; | ||
95 | |||
96 | if (cnr == 0) { | ||
97 | /* PWM is stopped. */ | ||
98 | @@ -XXX,XX +XXX,XX @@ static uint64_t pwm_compute_duty(uint32_t cnr, uint32_t cmr, bool inverted) | ||
99 | } else if (cmr >= cnr) { | ||
100 | duty = MAX_DUTY; | ||
101 | } else { | ||
102 | - duty = MAX_DUTY * (cmr + 1) / (cnr + 1); | ||
103 | + duty = (uint64_t)MAX_DUTY * (cmr + 1) / (cnr + 1); | ||
104 | } | ||
105 | |||
106 | if (inverted) { | ||
107 | -- | 765 | -- |
108 | 2.20.1 | 766 | 2.20.1 |
109 | 767 | ||
110 | 768 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | The properties to attach a CANBUS object to the xlnx-zcu102 machine have | 3 | Also add Damien as a reviewer. |
4 | a period in them. We want to use periods in properties for compound QAPI types, | ||
5 | and besides the "xlnx-zcu102." prefix is both unnecessary and different | ||
6 | from any other machine property name. Remove it. | ||
7 | 4 | ||
8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 5 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
9 | Message-id: 20210118162537.779542-1-pbonzini@redhat.com | 6 | Acked-by: Damien Hedde <damien.hedde@greensocs.com> |
10 | Reviewed-by: Vikram Garhwal <fnu.vikram@xilinx.com> | 7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Message-id: 20210211085318.2507-1-luc@lmichel.fr | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 10 | --- |
13 | hw/arm/xlnx-zcu102.c | 4 ++-- | 11 | MAINTAINERS | 11 +++++++++++ |
14 | tests/qtest/xlnx-can-test.c | 30 +++++++++++++++--------------- | 12 | 1 file changed, 11 insertions(+) |
15 | 2 files changed, 17 insertions(+), 17 deletions(-) | ||
16 | 13 | ||
17 | diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c | 14 | diff --git a/MAINTAINERS b/MAINTAINERS |
18 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/arm/xlnx-zcu102.c | 16 | --- a/MAINTAINERS |
20 | +++ b/hw/arm/xlnx-zcu102.c | 17 | +++ b/MAINTAINERS |
21 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_instance_init(Object *obj) | 18 | @@ -XXX,XX +XXX,XX @@ F: pc-bios/opensbi-* |
22 | s->secure = false; | 19 | F: .gitlab-ci.d/opensbi.yml |
23 | /* Default to virt (EL2) being disabled */ | 20 | F: .gitlab-ci.d/opensbi/ |
24 | s->virt = false; | 21 | |
25 | - object_property_add_link(obj, "xlnx-zcu102.canbus0", TYPE_CAN_BUS, | 22 | +Clock framework |
26 | + object_property_add_link(obj, "canbus0", TYPE_CAN_BUS, | 23 | +M: Luc Michel <luc@lmichel.fr> |
27 | (Object **)&s->canbus[0], | 24 | +R: Damien Hedde <damien.hedde@greensocs.com> |
28 | object_property_allow_set_link, | 25 | +S: Maintained |
29 | 0); | 26 | +F: include/hw/clock.h |
30 | 27 | +F: include/hw/qdev-clock.h | |
31 | - object_property_add_link(obj, "xlnx-zcu102.canbus1", TYPE_CAN_BUS, | 28 | +F: hw/core/clock.c |
32 | + object_property_add_link(obj, "canbus1", TYPE_CAN_BUS, | 29 | +F: hw/core/clock-vmstate.c |
33 | (Object **)&s->canbus[1], | 30 | +F: hw/core/qdev-clock.c |
34 | object_property_allow_set_link, | 31 | +F: docs/devel/clocks.rst |
35 | 0); | 32 | + |
36 | diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c | 33 | Usermode Emulation |
37 | index XXXXXXX..XXXXXXX 100644 | 34 | ------------------ |
38 | --- a/tests/qtest/xlnx-can-test.c | 35 | Overall usermode emulation |
39 | +++ b/tests/qtest/xlnx-can-test.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void test_can_bus(void) | ||
41 | uint8_t can_timestamp = 1; | ||
42 | |||
43 | QTestState *qts = qtest_init("-machine xlnx-zcu102" | ||
44 | - " -object can-bus,id=canbus0" | ||
45 | - " -machine xlnx-zcu102.canbus0=canbus0" | ||
46 | - " -machine xlnx-zcu102.canbus1=canbus0" | ||
47 | + " -object can-bus,id=canbus" | ||
48 | + " -machine canbus0=canbus" | ||
49 | + " -machine canbus1=canbus" | ||
50 | ); | ||
51 | |||
52 | /* Configure the CAN0 and CAN1. */ | ||
53 | @@ -XXX,XX +XXX,XX @@ static void test_can_loopback(void) | ||
54 | uint32_t status = 0; | ||
55 | |||
56 | QTestState *qts = qtest_init("-machine xlnx-zcu102" | ||
57 | - " -object can-bus,id=canbus0" | ||
58 | - " -machine xlnx-zcu102.canbus0=canbus0" | ||
59 | - " -machine xlnx-zcu102.canbus1=canbus0" | ||
60 | + " -object can-bus,id=canbus" | ||
61 | + " -machine canbus0=canbus" | ||
62 | + " -machine canbus1=canbus" | ||
63 | ); | ||
64 | |||
65 | /* Configure the CAN0 in loopback mode. */ | ||
66 | @@ -XXX,XX +XXX,XX @@ static void test_can_filter(void) | ||
67 | uint8_t can_timestamp = 1; | ||
68 | |||
69 | QTestState *qts = qtest_init("-machine xlnx-zcu102" | ||
70 | - " -object can-bus,id=canbus0" | ||
71 | - " -machine xlnx-zcu102.canbus0=canbus0" | ||
72 | - " -machine xlnx-zcu102.canbus1=canbus0" | ||
73 | + " -object can-bus,id=canbus" | ||
74 | + " -machine canbus0=canbus" | ||
75 | + " -machine canbus1=canbus" | ||
76 | ); | ||
77 | |||
78 | /* Configure the CAN0 and CAN1. */ | ||
79 | @@ -XXX,XX +XXX,XX @@ static void test_can_sleepmode(void) | ||
80 | uint8_t can_timestamp = 1; | ||
81 | |||
82 | QTestState *qts = qtest_init("-machine xlnx-zcu102" | ||
83 | - " -object can-bus,id=canbus0" | ||
84 | - " -machine xlnx-zcu102.canbus0=canbus0" | ||
85 | - " -machine xlnx-zcu102.canbus1=canbus0" | ||
86 | + " -object can-bus,id=canbus" | ||
87 | + " -machine canbus0=canbus" | ||
88 | + " -machine canbus1=canbus" | ||
89 | ); | ||
90 | |||
91 | /* Configure the CAN0. */ | ||
92 | @@ -XXX,XX +XXX,XX @@ static void test_can_snoopmode(void) | ||
93 | uint8_t can_timestamp = 1; | ||
94 | |||
95 | QTestState *qts = qtest_init("-machine xlnx-zcu102" | ||
96 | - " -object can-bus,id=canbus0" | ||
97 | - " -machine xlnx-zcu102.canbus0=canbus0" | ||
98 | - " -machine xlnx-zcu102.canbus1=canbus0" | ||
99 | + " -object can-bus,id=canbus" | ||
100 | + " -machine canbus0=canbus" | ||
101 | + " -machine canbus1=canbus" | ||
102 | ); | ||
103 | |||
104 | /* Configure the CAN0. */ | ||
105 | -- | 36 | -- |
106 | 2.20.1 | 37 | 2.20.1 |
107 | 38 | ||
108 | 39 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Move the preadv availability check to meson.build. This is what we | ||
2 | want to be doing for host-OS-feature-checks anyway, but it also fixes | ||
3 | a problem with building for macOS with the most recent XCode SDK on a | ||
4 | Catalina host. | ||
5 | 1 | ||
6 | On that configuration, 'preadv()' is provided as a weak symbol, so | ||
7 | that programs can be built with optional support for it and make a | ||
8 | runtime availability check to see whether the preadv() they have is a | ||
9 | working one or one which they must not call because it will | ||
10 | runtime-assert. QEMU's configure test passes (unless you're building | ||
11 | with --enable-werror) because the test program using preadv() | ||
12 | compiles, but then QEMU crashes at runtime when preadv() is called, | ||
13 | with errors like: | ||
14 | |||
15 | dyld: lazy symbol binding failed: Symbol not found: _preadv | ||
16 | Referenced from: /Users/pm215/src/qemu/./build/x86/tests/test-replication | ||
17 | Expected in: /usr/lib/libSystem.B.dylib | ||
18 | |||
19 | dyld: Symbol not found: _preadv | ||
20 | Referenced from: /Users/pm215/src/qemu/./build/x86/tests/test-replication | ||
21 | Expected in: /usr/lib/libSystem.B.dylib | ||
22 | |||
23 | Meson's own function availability check has a special case for macOS | ||
24 | which adds '-Wl,-no_weak_imports' to the compiler flags, which forces | ||
25 | the test to require the real function, not the macOS-version-too-old | ||
26 | stub. | ||
27 | |||
28 | So this commit fixes the bug where macOS builds on Catalina currently | ||
29 | require --disable-werror. | ||
30 | |||
31 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
32 | Acked-by: Paolo Bonzini <pbonzini@redhat.com> | ||
33 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
34 | Message-id: 20210126155846.17109-1-peter.maydell@linaro.org | ||
35 | --- | ||
36 | configure | 16 ---------------- | ||
37 | meson.build | 4 +++- | ||
38 | 2 files changed, 3 insertions(+), 17 deletions(-) | ||
39 | |||
40 | diff --git a/configure b/configure | ||
41 | index XXXXXXX..XXXXXXX 100755 | ||
42 | --- a/configure | ||
43 | +++ b/configure | ||
44 | @@ -XXX,XX +XXX,XX @@ if compile_prog "" "" ; then | ||
45 | iovec=yes | ||
46 | fi | ||
47 | |||
48 | -########################################## | ||
49 | -# preadv probe | ||
50 | -cat > $TMPC <<EOF | ||
51 | -#include <sys/types.h> | ||
52 | -#include <sys/uio.h> | ||
53 | -#include <unistd.h> | ||
54 | -int main(void) { return preadv(0, 0, 0, 0); } | ||
55 | -EOF | ||
56 | -preadv=no | ||
57 | -if compile_prog "" "" ; then | ||
58 | - preadv=yes | ||
59 | -fi | ||
60 | - | ||
61 | ########################################## | ||
62 | # fdt probe | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ fi | ||
65 | if test "$iovec" = "yes" ; then | ||
66 | echo "CONFIG_IOVEC=y" >> $config_host_mak | ||
67 | fi | ||
68 | -if test "$preadv" = "yes" ; then | ||
69 | - echo "CONFIG_PREADV=y" >> $config_host_mak | ||
70 | -fi | ||
71 | if test "$membarrier" = "yes" ; then | ||
72 | echo "CONFIG_MEMBARRIER=y" >> $config_host_mak | ||
73 | fi | ||
74 | diff --git a/meson.build b/meson.build | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/meson.build | ||
77 | +++ b/meson.build | ||
78 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('HAVE_PTY_H', cc.has_header('pty.h')) | ||
79 | config_host_data.set('HAVE_SYS_IOCCOM_H', cc.has_header('sys/ioccom.h')) | ||
80 | config_host_data.set('HAVE_SYS_KCOV_H', cc.has_header('sys/kcov.h')) | ||
81 | |||
82 | +config_host_data.set('CONFIG_PREADV', cc.has_function('preadv', prefix: '#include <sys/uio.h>')) | ||
83 | + | ||
84 | ignored = ['CONFIG_QEMU_INTERP_PREFIX'] # actually per-target | ||
85 | arrays = ['CONFIG_AUDIO_DRIVERS', 'CONFIG_BDRV_RW_WHITELIST', 'CONFIG_BDRV_RO_WHITELIST'] | ||
86 | strings = ['HOST_DSOSUF', 'CONFIG_IASL'] | ||
87 | @@ -XXX,XX +XXX,XX @@ summary_info += {'PIE': get_option('b_pie')} | ||
88 | summary_info += {'static build': config_host.has_key('CONFIG_STATIC')} | ||
89 | summary_info += {'malloc trim support': has_malloc_trim} | ||
90 | summary_info += {'membarrier': config_host.has_key('CONFIG_MEMBARRIER')} | ||
91 | -summary_info += {'preadv support': config_host.has_key('CONFIG_PREADV')} | ||
92 | +summary_info += {'preadv support': config_host_data.get('CONFIG_PREADV')} | ||
93 | summary_info += {'fdatasync': config_host.has_key('CONFIG_FDATASYNC')} | ||
94 | summary_info += {'madvise': config_host.has_key('CONFIG_MADVISE')} | ||
95 | summary_info += {'posix_madvise': config_host.has_key('CONFIG_POSIX_MADVISE')} | ||
96 | -- | ||
97 | 2.20.1 | ||
98 | |||
99 | diff view generated by jsdifflib |
1 | From: Mihai Carabas <mihai.carabas@oracle.com> | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | 2 | ||
3 | To ease the PCI device addition in next patches, split the code as follows: | 3 | This is a 10/100 ethernet device that has several features. |
4 | - generic code (read/write/setup) is being kept in pvpanic.c | 4 | Only the ones needed by the Linux driver have been implemented. |
5 | - ISA dependent code moved to pvpanic-isa.c | 5 | See npcm7xx_emc.c for a list of unimplemented features. |
6 | 6 | ||
7 | Also, rename: | 7 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
8 | - ISA_PVPANIC_DEVICE -> PVPANIC_ISA_DEVICE. | 8 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> |
9 | - TYPE_PVPANIC -> TYPE_PVPANIC_ISA. | ||
10 | - MemoryRegion io -> mr. | ||
11 | - pvpanic_ioport_* in pvpanic_*. | ||
12 | |||
13 | Update the build system with the new files and config structure. | ||
14 | |||
15 | Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Doug Evans <dje@google.com> | ||
11 | Message-id: 20210213002520.1374134-2-dje@google.com | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 13 | --- |
19 | include/hw/misc/pvpanic.h | 23 +++++++++- | 14 | include/hw/net/npcm7xx_emc.h | 286 ++++++++++++ |
20 | hw/misc/pvpanic-isa.c | 94 +++++++++++++++++++++++++++++++++++++++ | 15 | hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++ |
21 | hw/misc/pvpanic.c | 85 +++-------------------------------- | 16 | hw/net/meson.build | 1 + |
22 | hw/i386/Kconfig | 2 +- | 17 | hw/net/trace-events | 17 + |
23 | hw/misc/Kconfig | 6 ++- | 18 | 4 files changed, 1161 insertions(+) |
24 | hw/misc/meson.build | 3 +- | 19 | create mode 100644 include/hw/net/npcm7xx_emc.h |
25 | tests/qtest/meson.build | 2 +- | 20 | create mode 100644 hw/net/npcm7xx_emc.c |
26 | 7 files changed, 130 insertions(+), 85 deletions(-) | ||
27 | create mode 100644 hw/misc/pvpanic-isa.c | ||
28 | 21 | ||
29 | diff --git a/include/hw/misc/pvpanic.h b/include/hw/misc/pvpanic.h | 22 | diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h |
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/misc/pvpanic.h | ||
32 | +++ b/include/hw/misc/pvpanic.h | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | |||
35 | #include "qom/object.h" | ||
36 | |||
37 | -#define TYPE_PVPANIC "pvpanic" | ||
38 | +#define TYPE_PVPANIC_ISA_DEVICE "pvpanic" | ||
39 | |||
40 | #define PVPANIC_IOPORT_PROP "ioport" | ||
41 | |||
42 | +/* The bit of supported pv event, TODO: include uapi header and remove this */ | ||
43 | +#define PVPANIC_F_PANICKED 0 | ||
44 | +#define PVPANIC_F_CRASHLOADED 1 | ||
45 | + | ||
46 | +/* The pv event value */ | ||
47 | +#define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED) | ||
48 | +#define PVPANIC_CRASHLOADED (1 << PVPANIC_F_CRASHLOADED) | ||
49 | + | ||
50 | +/* | ||
51 | + * PVPanicState for any device type | ||
52 | + */ | ||
53 | +typedef struct PVPanicState PVPanicState; | ||
54 | +struct PVPanicState { | ||
55 | + MemoryRegion mr; | ||
56 | + uint8_t events; | ||
57 | +}; | ||
58 | + | ||
59 | +void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size); | ||
60 | + | ||
61 | static inline uint16_t pvpanic_port(void) | ||
62 | { | ||
63 | - Object *o = object_resolve_path_type("", TYPE_PVPANIC, NULL); | ||
64 | + Object *o = object_resolve_path_type("", TYPE_PVPANIC_ISA_DEVICE, NULL); | ||
65 | if (!o) { | ||
66 | return 0; | ||
67 | } | ||
68 | diff --git a/hw/misc/pvpanic-isa.c b/hw/misc/pvpanic-isa.c | ||
69 | new file mode 100644 | 23 | new file mode 100644 |
70 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
71 | --- /dev/null | 25 | --- /dev/null |
72 | +++ b/hw/misc/pvpanic-isa.c | 26 | +++ b/include/hw/net/npcm7xx_emc.h |
73 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
74 | +/* | 28 | +/* |
75 | + * QEMU simulated pvpanic device. | 29 | + * Nuvoton NPCM7xx EMC Module |
76 | + * | 30 | + * |
77 | + * Copyright Fujitsu, Corp. 2013 | 31 | + * Copyright 2020 Google LLC |
78 | + * | 32 | + * |
79 | + * Authors: | 33 | + * This program is free software; you can redistribute it and/or modify it |
80 | + * Wen Congyang <wency@cn.fujitsu.com> | 34 | + * under the terms of the GNU General Public License as published by the |
81 | + * Hu Tao <hutao@cn.fujitsu.com> | 35 | + * Free Software Foundation; either version 2 of the License, or |
36 | + * (at your option) any later version. | ||
82 | + * | 37 | + * |
83 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 38 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
84 | + * See the COPYING file in the top-level directory. | 39 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
40 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
41 | + * for more details. | ||
42 | + */ | ||
43 | + | ||
44 | +#ifndef NPCM7XX_EMC_H | ||
45 | +#define NPCM7XX_EMC_H | ||
46 | + | ||
47 | +#include "hw/irq.h" | ||
48 | +#include "hw/sysbus.h" | ||
49 | +#include "net/net.h" | ||
50 | + | ||
51 | +/* 32-bit register indices. */ | ||
52 | +enum NPCM7xxPWMRegister { | ||
53 | + /* Control registers. */ | ||
54 | + REG_CAMCMR, | ||
55 | + REG_CAMEN, | ||
56 | + | ||
57 | + /* There are 16 CAMn[ML] registers. */ | ||
58 | + REG_CAMM_BASE, | ||
59 | + REG_CAML_BASE, | ||
60 | + REG_CAMML_LAST = 0x21, | ||
61 | + | ||
62 | + REG_TXDLSA = 0x22, | ||
63 | + REG_RXDLSA, | ||
64 | + REG_MCMDR, | ||
65 | + REG_MIID, | ||
66 | + REG_MIIDA, | ||
67 | + REG_FFTCR, | ||
68 | + REG_TSDR, | ||
69 | + REG_RSDR, | ||
70 | + REG_DMARFC, | ||
71 | + REG_MIEN, | ||
72 | + | ||
73 | + /* Status registers. */ | ||
74 | + REG_MISTA, | ||
75 | + REG_MGSTA, | ||
76 | + REG_MPCNT, | ||
77 | + REG_MRPC, | ||
78 | + REG_MRPCC, | ||
79 | + REG_MREPC, | ||
80 | + REG_DMARFS, | ||
81 | + REG_CTXDSA, | ||
82 | + REG_CTXBSA, | ||
83 | + REG_CRXDSA, | ||
84 | + REG_CRXBSA, | ||
85 | + | ||
86 | + NPCM7XX_NUM_EMC_REGS, | ||
87 | +}; | ||
88 | + | ||
89 | +/* REG_CAMCMR fields */ | ||
90 | +/* Enable CAM Compare */ | ||
91 | +#define REG_CAMCMR_ECMP (1 << 4) | ||
92 | +/* Complement CAM Compare */ | ||
93 | +#define REG_CAMCMR_CCAM (1 << 3) | ||
94 | +/* Accept Broadcast Packet */ | ||
95 | +#define REG_CAMCMR_ABP (1 << 2) | ||
96 | +/* Accept Multicast Packet */ | ||
97 | +#define REG_CAMCMR_AMP (1 << 1) | ||
98 | +/* Accept Unicast Packet */ | ||
99 | +#define REG_CAMCMR_AUP (1 << 0) | ||
100 | + | ||
101 | +/* REG_MCMDR fields */ | ||
102 | +/* Software Reset */ | ||
103 | +#define REG_MCMDR_SWR (1 << 24) | ||
104 | +/* Internal Loopback Select */ | ||
105 | +#define REG_MCMDR_LBK (1 << 21) | ||
106 | +/* Operation Mode Select */ | ||
107 | +#define REG_MCMDR_OPMOD (1 << 20) | ||
108 | +/* Enable MDC Clock Generation */ | ||
109 | +#define REG_MCMDR_ENMDC (1 << 19) | ||
110 | +/* Full-Duplex Mode Select */ | ||
111 | +#define REG_MCMDR_FDUP (1 << 18) | ||
112 | +/* Enable SQE Checking */ | ||
113 | +#define REG_MCMDR_ENSEQ (1 << 17) | ||
114 | +/* Send PAUSE Frame */ | ||
115 | +#define REG_MCMDR_SDPZ (1 << 16) | ||
116 | +/* No Defer */ | ||
117 | +#define REG_MCMDR_NDEF (1 << 9) | ||
118 | +/* Frame Transmission On */ | ||
119 | +#define REG_MCMDR_TXON (1 << 8) | ||
120 | +/* Strip CRC Checksum */ | ||
121 | +#define REG_MCMDR_SPCRC (1 << 5) | ||
122 | +/* Accept CRC Error Packet */ | ||
123 | +#define REG_MCMDR_AEP (1 << 4) | ||
124 | +/* Accept Control Packet */ | ||
125 | +#define REG_MCMDR_ACP (1 << 3) | ||
126 | +/* Accept Runt Packet */ | ||
127 | +#define REG_MCMDR_ARP (1 << 2) | ||
128 | +/* Accept Long Packet */ | ||
129 | +#define REG_MCMDR_ALP (1 << 1) | ||
130 | +/* Frame Reception On */ | ||
131 | +#define REG_MCMDR_RXON (1 << 0) | ||
132 | + | ||
133 | +/* REG_MIEN fields */ | ||
134 | +/* Enable Transmit Descriptor Unavailable Interrupt */ | ||
135 | +#define REG_MIEN_ENTDU (1 << 23) | ||
136 | +/* Enable Transmit Completion Interrupt */ | ||
137 | +#define REG_MIEN_ENTXCP (1 << 18) | ||
138 | +/* Enable Transmit Interrupt */ | ||
139 | +#define REG_MIEN_ENTXINTR (1 << 16) | ||
140 | +/* Enable Receive Descriptor Unavailable Interrupt */ | ||
141 | +#define REG_MIEN_ENRDU (1 << 10) | ||
142 | +/* Enable Receive Good Interrupt */ | ||
143 | +#define REG_MIEN_ENRXGD (1 << 4) | ||
144 | +/* Enable Receive Interrupt */ | ||
145 | +#define REG_MIEN_ENRXINTR (1 << 0) | ||
146 | + | ||
147 | +/* REG_MISTA fields */ | ||
148 | +/* TODO: Add error fields and support simulated errors? */ | ||
149 | +/* Transmit Bus Error Interrupt */ | ||
150 | +#define REG_MISTA_TXBERR (1 << 24) | ||
151 | +/* Transmit Descriptor Unavailable Interrupt */ | ||
152 | +#define REG_MISTA_TDU (1 << 23) | ||
153 | +/* Transmit Completion Interrupt */ | ||
154 | +#define REG_MISTA_TXCP (1 << 18) | ||
155 | +/* Transmit Interrupt */ | ||
156 | +#define REG_MISTA_TXINTR (1 << 16) | ||
157 | +/* Receive Bus Error Interrupt */ | ||
158 | +#define REG_MISTA_RXBERR (1 << 11) | ||
159 | +/* Receive Descriptor Unavailable Interrupt */ | ||
160 | +#define REG_MISTA_RDU (1 << 10) | ||
161 | +/* DMA Early Notification Interrupt */ | ||
162 | +#define REG_MISTA_DENI (1 << 9) | ||
163 | +/* Maximum Frame Length Interrupt */ | ||
164 | +#define REG_MISTA_DFOI (1 << 8) | ||
165 | +/* Receive Good Interrupt */ | ||
166 | +#define REG_MISTA_RXGD (1 << 4) | ||
167 | +/* Packet Too Long Interrupt */ | ||
168 | +#define REG_MISTA_PTLE (1 << 3) | ||
169 | +/* Receive Interrupt */ | ||
170 | +#define REG_MISTA_RXINTR (1 << 0) | ||
171 | + | ||
172 | +/* REG_MGSTA fields */ | ||
173 | +/* Transmission Halted */ | ||
174 | +#define REG_MGSTA_TXHA (1 << 11) | ||
175 | +/* Receive Halted */ | ||
176 | +#define REG_MGSTA_RXHA (1 << 11) | ||
177 | + | ||
178 | +/* REG_DMARFC fields */ | ||
179 | +/* Maximum Receive Frame Length */ | ||
180 | +#define REG_DMARFC_RXMS(word) extract32((word), 0, 16) | ||
181 | + | ||
182 | +/* REG MIIDA fields */ | ||
183 | +/* Busy Bit */ | ||
184 | +#define REG_MIIDA_BUSY (1 << 17) | ||
185 | + | ||
186 | +/* Transmit and receive descriptors */ | ||
187 | +typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc; | ||
188 | +typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc; | ||
189 | + | ||
190 | +struct NPCM7xxEMCTxDesc { | ||
191 | + uint32_t flags; | ||
192 | + uint32_t txbsa; | ||
193 | + uint32_t status_and_length; | ||
194 | + uint32_t ntxdsa; | ||
195 | +}; | ||
196 | + | ||
197 | +struct NPCM7xxEMCRxDesc { | ||
198 | + uint32_t status_and_length; | ||
199 | + uint32_t rxbsa; | ||
200 | + uint32_t reserved; | ||
201 | + uint32_t nrxdsa; | ||
202 | +}; | ||
203 | + | ||
204 | +/* NPCM7xxEMCTxDesc.flags values */ | ||
205 | +/* Owner: 0 = cpu, 1 = emc */ | ||
206 | +#define TX_DESC_FLAG_OWNER_MASK (1 << 31) | ||
207 | +/* Transmit interrupt enable */ | ||
208 | +#define TX_DESC_FLAG_INTEN (1 << 2) | ||
209 | +/* CRC append */ | ||
210 | +#define TX_DESC_FLAG_CRCAPP (1 << 1) | ||
211 | +/* Padding enable */ | ||
212 | +#define TX_DESC_FLAG_PADEN (1 << 0) | ||
213 | + | ||
214 | +/* NPCM7xxEMCTxDesc.status_and_length values */ | ||
215 | +/* Collision count */ | ||
216 | +#define TX_DESC_STATUS_CCNT_SHIFT 28 | ||
217 | +#define TX_DESC_STATUS_CCNT_BITSIZE 4 | ||
218 | +/* SQE error */ | ||
219 | +#define TX_DESC_STATUS_SQE (1 << 26) | ||
220 | +/* Transmission paused */ | ||
221 | +#define TX_DESC_STATUS_PAU (1 << 25) | ||
222 | +/* P transmission halted */ | ||
223 | +#define TX_DESC_STATUS_TXHA (1 << 24) | ||
224 | +/* Late collision */ | ||
225 | +#define TX_DESC_STATUS_LC (1 << 23) | ||
226 | +/* Transmission abort */ | ||
227 | +#define TX_DESC_STATUS_TXABT (1 << 22) | ||
228 | +/* No carrier sense */ | ||
229 | +#define TX_DESC_STATUS_NCS (1 << 21) | ||
230 | +/* Defer exceed */ | ||
231 | +#define TX_DESC_STATUS_EXDEF (1 << 20) | ||
232 | +/* Transmission complete */ | ||
233 | +#define TX_DESC_STATUS_TXCP (1 << 19) | ||
234 | +/* Transmission deferred */ | ||
235 | +#define TX_DESC_STATUS_DEF (1 << 17) | ||
236 | +/* Transmit interrupt */ | ||
237 | +#define TX_DESC_STATUS_TXINTR (1 << 16) | ||
238 | + | ||
239 | +#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16) | ||
240 | + | ||
241 | +/* Transmit buffer start address */ | ||
242 | +#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u) | ||
243 | + | ||
244 | +/* Next transmit descriptor start address */ | ||
245 | +#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u) | ||
246 | + | ||
247 | +/* NPCM7xxEMCRxDesc.status_and_length values */ | ||
248 | +/* Owner: 0b00 = cpu, 0b01 = undefined, 0b10 = emc, 0b11 = undefined */ | ||
249 | +#define RX_DESC_STATUS_OWNER_SHIFT 30 | ||
250 | +#define RX_DESC_STATUS_OWNER_BITSIZE 2 | ||
251 | +#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT) | ||
252 | +/* Runt packet */ | ||
253 | +#define RX_DESC_STATUS_RP (1 << 22) | ||
254 | +/* Alignment error */ | ||
255 | +#define RX_DESC_STATUS_ALIE (1 << 21) | ||
256 | +/* Frame reception complete */ | ||
257 | +#define RX_DESC_STATUS_RXGD (1 << 20) | ||
258 | +/* Packet too long */ | ||
259 | +#define RX_DESC_STATUS_PTLE (1 << 19) | ||
260 | +/* CRC error */ | ||
261 | +#define RX_DESC_STATUS_CRCE (1 << 17) | ||
262 | +/* Receive interrupt */ | ||
263 | +#define RX_DESC_STATUS_RXINTR (1 << 16) | ||
264 | + | ||
265 | +#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16) | ||
266 | + | ||
267 | +/* Receive buffer start address */ | ||
268 | +#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u) | ||
269 | + | ||
270 | +/* Next receive descriptor start address */ | ||
271 | +#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u) | ||
272 | + | ||
273 | +/* Minimum packet length, when TX_DESC_FLAG_PADEN is set. */ | ||
274 | +#define MIN_PACKET_LENGTH 64 | ||
275 | + | ||
276 | +struct NPCM7xxEMCState { | ||
277 | + /*< private >*/ | ||
278 | + SysBusDevice parent; | ||
279 | + /*< public >*/ | ||
280 | + | ||
281 | + MemoryRegion iomem; | ||
282 | + | ||
283 | + qemu_irq tx_irq; | ||
284 | + qemu_irq rx_irq; | ||
285 | + | ||
286 | + NICState *nic; | ||
287 | + NICConf conf; | ||
288 | + | ||
289 | + /* 0 or 1, for log messages */ | ||
290 | + uint8_t emc_num; | ||
291 | + | ||
292 | + uint32_t regs[NPCM7XX_NUM_EMC_REGS]; | ||
293 | + | ||
294 | + /* | ||
295 | + * tx is active. Set to true by TSDR and then switches off when out of | ||
296 | + * descriptors. If the TXON bit in REG_MCMDR is off then this is off. | ||
297 | + */ | ||
298 | + bool tx_active; | ||
299 | + | ||
300 | + /* | ||
301 | + * rx is active. Set to true by RSDR and then switches off when out of | ||
302 | + * descriptors. If the RXON bit in REG_MCMDR is off then this is off. | ||
303 | + */ | ||
304 | + bool rx_active; | ||
305 | +}; | ||
306 | + | ||
307 | +typedef struct NPCM7xxEMCState NPCM7xxEMCState; | ||
308 | + | ||
309 | +#define TYPE_NPCM7XX_EMC "npcm7xx-emc" | ||
310 | +#define NPCM7XX_EMC(obj) \ | ||
311 | + OBJECT_CHECK(NPCM7xxEMCState, (obj), TYPE_NPCM7XX_EMC) | ||
312 | + | ||
313 | +#endif /* NPCM7XX_EMC_H */ | ||
314 | diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c | ||
315 | new file mode 100644 | ||
316 | index XXXXXXX..XXXXXXX | ||
317 | --- /dev/null | ||
318 | +++ b/hw/net/npcm7xx_emc.c | ||
319 | @@ -XXX,XX +XXX,XX @@ | ||
320 | +/* | ||
321 | + * Nuvoton NPCM7xx EMC Module | ||
85 | + * | 322 | + * |
323 | + * Copyright 2020 Google LLC | ||
324 | + * | ||
325 | + * This program is free software; you can redistribute it and/or modify it | ||
326 | + * under the terms of the GNU General Public License as published by the | ||
327 | + * Free Software Foundation; either version 2 of the License, or | ||
328 | + * (at your option) any later version. | ||
329 | + * | ||
330 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
331 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
332 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
333 | + * for more details. | ||
334 | + * | ||
335 | + * Unsupported/unimplemented features: | ||
336 | + * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported | ||
337 | + * - Only CAM0 is supported, CAM[1-15] are not | ||
338 | + * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes | ||
339 | + * - MII is not implemented, MIIDA.BUSY and MIID always return zero | ||
340 | + * - MCMDR.LBK is not implemented | ||
341 | + * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported | ||
342 | + * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored | ||
343 | + * - MGSTA.SQE is not supported | ||
344 | + * - pause and control frames are not implemented | ||
345 | + * - MGSTA.CCNT is not supported | ||
346 | + * - MPCNT, DMARFS are not implemented | ||
86 | + */ | 347 | + */ |
87 | + | 348 | + |
88 | +#include "qemu/osdep.h" | 349 | +#include "qemu/osdep.h" |
350 | + | ||
351 | +/* For crc32 */ | ||
352 | +#include <zlib.h> | ||
353 | + | ||
354 | +#include "qemu-common.h" | ||
355 | +#include "hw/irq.h" | ||
356 | +#include "hw/qdev-clock.h" | ||
357 | +#include "hw/qdev-properties.h" | ||
358 | +#include "hw/net/npcm7xx_emc.h" | ||
359 | +#include "net/eth.h" | ||
360 | +#include "migration/vmstate.h" | ||
361 | +#include "qemu/bitops.h" | ||
362 | +#include "qemu/error-report.h" | ||
89 | +#include "qemu/log.h" | 363 | +#include "qemu/log.h" |
90 | +#include "qemu/module.h" | 364 | +#include "qemu/module.h" |
91 | +#include "sysemu/runstate.h" | 365 | +#include "qemu/units.h" |
92 | + | 366 | +#include "sysemu/dma.h" |
93 | +#include "hw/nvram/fw_cfg.h" | 367 | +#include "trace.h" |
94 | +#include "hw/qdev-properties.h" | 368 | + |
95 | +#include "hw/misc/pvpanic.h" | 369 | +#define CRC_LENGTH 4 |
96 | +#include "qom/object.h" | ||
97 | +#include "hw/isa/isa.h" | ||
98 | + | ||
99 | +OBJECT_DECLARE_SIMPLE_TYPE(PVPanicISAState, PVPANIC_ISA_DEVICE) | ||
100 | + | 370 | + |
101 | +/* | 371 | +/* |
102 | + * PVPanicISAState for ISA device and | 372 | + * The maximum size of a (layer 2) ethernet frame as defined by 802.3. |
103 | + * use ioport. | 373 | + * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload) |
374 | + * This does not include an additional 4 for the vlan field (802.1q). | ||
104 | + */ | 375 | + */ |
105 | +struct PVPanicISAState { | 376 | +#define MAX_ETH_FRAME_SIZE 1518 |
106 | + ISADevice parent_obj; | 377 | + |
107 | + | 378 | +static const char *emc_reg_name(int regno) |
108 | + uint16_t ioport; | 379 | +{ |
109 | + PVPanicState pvpanic; | 380 | +#define REG(name) case REG_ ## name: return #name; |
381 | + switch (regno) { | ||
382 | + REG(CAMCMR) | ||
383 | + REG(CAMEN) | ||
384 | + REG(TXDLSA) | ||
385 | + REG(RXDLSA) | ||
386 | + REG(MCMDR) | ||
387 | + REG(MIID) | ||
388 | + REG(MIIDA) | ||
389 | + REG(FFTCR) | ||
390 | + REG(TSDR) | ||
391 | + REG(RSDR) | ||
392 | + REG(DMARFC) | ||
393 | + REG(MIEN) | ||
394 | + REG(MISTA) | ||
395 | + REG(MGSTA) | ||
396 | + REG(MPCNT) | ||
397 | + REG(MRPC) | ||
398 | + REG(MRPCC) | ||
399 | + REG(MREPC) | ||
400 | + REG(DMARFS) | ||
401 | + REG(CTXDSA) | ||
402 | + REG(CTXBSA) | ||
403 | + REG(CRXDSA) | ||
404 | + REG(CRXBSA) | ||
405 | + case REG_CAMM_BASE + 0: return "CAM0M"; | ||
406 | + case REG_CAML_BASE + 0: return "CAM0L"; | ||
407 | + case REG_CAMM_BASE + 2 ... REG_CAMML_LAST: | ||
408 | + /* Only CAM0 is supported, fold the others into something simple. */ | ||
409 | + if (regno & 1) { | ||
410 | + return "CAM<n>L"; | ||
411 | + } else { | ||
412 | + return "CAM<n>M"; | ||
413 | + } | ||
414 | + default: return "UNKNOWN"; | ||
415 | + } | ||
416 | +#undef REG | ||
417 | +} | ||
418 | + | ||
419 | +static void emc_reset(NPCM7xxEMCState *emc) | ||
420 | +{ | ||
421 | + trace_npcm7xx_emc_reset(emc->emc_num); | ||
422 | + | ||
423 | + memset(&emc->regs[0], 0, sizeof(emc->regs)); | ||
424 | + | ||
425 | + /* These regs have non-zero reset values. */ | ||
426 | + emc->regs[REG_TXDLSA] = 0xfffffffc; | ||
427 | + emc->regs[REG_RXDLSA] = 0xfffffffc; | ||
428 | + emc->regs[REG_MIIDA] = 0x00900000; | ||
429 | + emc->regs[REG_FFTCR] = 0x0101; | ||
430 | + emc->regs[REG_DMARFC] = 0x0800; | ||
431 | + emc->regs[REG_MPCNT] = 0x7fff; | ||
432 | + | ||
433 | + emc->tx_active = false; | ||
434 | + emc->rx_active = false; | ||
435 | +} | ||
436 | + | ||
437 | +static void npcm7xx_emc_reset(DeviceState *dev) | ||
438 | +{ | ||
439 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); | ||
440 | + emc_reset(emc); | ||
441 | +} | ||
442 | + | ||
443 | +static void emc_soft_reset(NPCM7xxEMCState *emc) | ||
444 | +{ | ||
445 | + /* | ||
446 | + * The docs say at least MCMDR.{LBK,OPMOD} bits are not changed during a | ||
447 | + * soft reset, but does not go into further detail. For now, KISS. | ||
448 | + */ | ||
449 | + uint32_t mcmdr = emc->regs[REG_MCMDR]; | ||
450 | + emc_reset(emc); | ||
451 | + emc->regs[REG_MCMDR] = mcmdr & (REG_MCMDR_LBK | REG_MCMDR_OPMOD); | ||
452 | + | ||
453 | + qemu_set_irq(emc->tx_irq, 0); | ||
454 | + qemu_set_irq(emc->rx_irq, 0); | ||
455 | +} | ||
456 | + | ||
457 | +static void emc_set_link(NetClientState *nc) | ||
458 | +{ | ||
459 | + /* Nothing to do yet. */ | ||
460 | +} | ||
461 | + | ||
462 | +/* MISTA.TXINTR is the union of the individual bits with their enables. */ | ||
463 | +static void emc_update_mista_txintr(NPCM7xxEMCState *emc) | ||
464 | +{ | ||
465 | + /* Only look at the bits we support. */ | ||
466 | + uint32_t mask = (REG_MISTA_TXBERR | | ||
467 | + REG_MISTA_TDU | | ||
468 | + REG_MISTA_TXCP); | ||
469 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) { | ||
470 | + emc->regs[REG_MISTA] |= REG_MISTA_TXINTR; | ||
471 | + } else { | ||
472 | + emc->regs[REG_MISTA] &= ~REG_MISTA_TXINTR; | ||
473 | + } | ||
474 | +} | ||
475 | + | ||
476 | +/* MISTA.RXINTR is the union of the individual bits with their enables. */ | ||
477 | +static void emc_update_mista_rxintr(NPCM7xxEMCState *emc) | ||
478 | +{ | ||
479 | + /* Only look at the bits we support. */ | ||
480 | + uint32_t mask = (REG_MISTA_RXBERR | | ||
481 | + REG_MISTA_RDU | | ||
482 | + REG_MISTA_RXGD); | ||
483 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) { | ||
484 | + emc->regs[REG_MISTA] |= REG_MISTA_RXINTR; | ||
485 | + } else { | ||
486 | + emc->regs[REG_MISTA] &= ~REG_MISTA_RXINTR; | ||
487 | + } | ||
488 | +} | ||
489 | + | ||
490 | +/* N.B. emc_update_mista_txintr must have already been called. */ | ||
491 | +static void emc_update_tx_irq(NPCM7xxEMCState *emc) | ||
492 | +{ | ||
493 | + int level = !!(emc->regs[REG_MISTA] & | ||
494 | + emc->regs[REG_MIEN] & | ||
495 | + REG_MISTA_TXINTR); | ||
496 | + trace_npcm7xx_emc_update_tx_irq(level); | ||
497 | + qemu_set_irq(emc->tx_irq, level); | ||
498 | +} | ||
499 | + | ||
500 | +/* N.B. emc_update_mista_rxintr must have already been called. */ | ||
501 | +static void emc_update_rx_irq(NPCM7xxEMCState *emc) | ||
502 | +{ | ||
503 | + int level = !!(emc->regs[REG_MISTA] & | ||
504 | + emc->regs[REG_MIEN] & | ||
505 | + REG_MISTA_RXINTR); | ||
506 | + trace_npcm7xx_emc_update_rx_irq(level); | ||
507 | + qemu_set_irq(emc->rx_irq, level); | ||
508 | +} | ||
509 | + | ||
510 | +/* Update IRQ states due to changes in MIEN,MISTA. */ | ||
511 | +static void emc_update_irq_from_reg_change(NPCM7xxEMCState *emc) | ||
512 | +{ | ||
513 | + emc_update_mista_txintr(emc); | ||
514 | + emc_update_tx_irq(emc); | ||
515 | + | ||
516 | + emc_update_mista_rxintr(emc); | ||
517 | + emc_update_rx_irq(emc); | ||
518 | +} | ||
519 | + | ||
520 | +static int emc_read_tx_desc(dma_addr_t addr, NPCM7xxEMCTxDesc *desc) | ||
521 | +{ | ||
522 | + if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) { | ||
523 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%" | ||
524 | + HWADDR_PRIx "\n", __func__, addr); | ||
525 | + return -1; | ||
526 | + } | ||
527 | + desc->flags = le32_to_cpu(desc->flags); | ||
528 | + desc->txbsa = le32_to_cpu(desc->txbsa); | ||
529 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
530 | + desc->ntxdsa = le32_to_cpu(desc->ntxdsa); | ||
531 | + return 0; | ||
532 | +} | ||
533 | + | ||
534 | +static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr) | ||
535 | +{ | ||
536 | + NPCM7xxEMCTxDesc le_desc; | ||
537 | + | ||
538 | + le_desc.flags = cpu_to_le32(desc->flags); | ||
539 | + le_desc.txbsa = cpu_to_le32(desc->txbsa); | ||
540 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
541 | + le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa); | ||
542 | + if (dma_memory_write(&address_space_memory, addr, &le_desc, | ||
543 | + sizeof(le_desc))) { | ||
544 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%" | ||
545 | + HWADDR_PRIx "\n", __func__, addr); | ||
546 | + return -1; | ||
547 | + } | ||
548 | + return 0; | ||
549 | +} | ||
550 | + | ||
551 | +static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc) | ||
552 | +{ | ||
553 | + if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) { | ||
554 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%" | ||
555 | + HWADDR_PRIx "\n", __func__, addr); | ||
556 | + return -1; | ||
557 | + } | ||
558 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
559 | + desc->rxbsa = le32_to_cpu(desc->rxbsa); | ||
560 | + desc->reserved = le32_to_cpu(desc->reserved); | ||
561 | + desc->nrxdsa = le32_to_cpu(desc->nrxdsa); | ||
562 | + return 0; | ||
563 | +} | ||
564 | + | ||
565 | +static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr) | ||
566 | +{ | ||
567 | + NPCM7xxEMCRxDesc le_desc; | ||
568 | + | ||
569 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
570 | + le_desc.rxbsa = cpu_to_le32(desc->rxbsa); | ||
571 | + le_desc.reserved = cpu_to_le32(desc->reserved); | ||
572 | + le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa); | ||
573 | + if (dma_memory_write(&address_space_memory, addr, &le_desc, | ||
574 | + sizeof(le_desc))) { | ||
575 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%" | ||
576 | + HWADDR_PRIx "\n", __func__, addr); | ||
577 | + return -1; | ||
578 | + } | ||
579 | + return 0; | ||
580 | +} | ||
581 | + | ||
582 | +static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags) | ||
583 | +{ | ||
584 | + trace_npcm7xx_emc_set_mista(flags); | ||
585 | + emc->regs[REG_MISTA] |= flags; | ||
586 | + if (extract32(flags, 16, 16)) { | ||
587 | + emc_update_mista_txintr(emc); | ||
588 | + } | ||
589 | + if (extract32(flags, 0, 16)) { | ||
590 | + emc_update_mista_rxintr(emc); | ||
591 | + } | ||
592 | +} | ||
593 | + | ||
594 | +static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag) | ||
595 | +{ | ||
596 | + emc->tx_active = false; | ||
597 | + emc_set_mista(emc, mista_flag); | ||
598 | +} | ||
599 | + | ||
600 | +static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag) | ||
601 | +{ | ||
602 | + emc->rx_active = false; | ||
603 | + emc_set_mista(emc, mista_flag); | ||
604 | +} | ||
605 | + | ||
606 | +static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc, | ||
607 | + const NPCM7xxEMCTxDesc *tx_desc, | ||
608 | + uint32_t desc_addr) | ||
609 | +{ | ||
610 | + /* Update the current descriptor, if only to reset the owner flag. */ | ||
611 | + if (emc_write_tx_desc(tx_desc, desc_addr)) { | ||
612 | + /* | ||
613 | + * We just read it so this shouldn't generally happen. | ||
614 | + * Error already reported. | ||
615 | + */ | ||
616 | + emc_set_mista(emc, REG_MISTA_TXBERR); | ||
617 | + } | ||
618 | + emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa); | ||
619 | +} | ||
620 | + | ||
621 | +static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc, | ||
622 | + const NPCM7xxEMCRxDesc *rx_desc, | ||
623 | + uint32_t desc_addr) | ||
624 | +{ | ||
625 | + /* Update the current descriptor, if only to reset the owner flag. */ | ||
626 | + if (emc_write_rx_desc(rx_desc, desc_addr)) { | ||
627 | + /* | ||
628 | + * We just read it so this shouldn't generally happen. | ||
629 | + * Error already reported. | ||
630 | + */ | ||
631 | + emc_set_mista(emc, REG_MISTA_RXBERR); | ||
632 | + } | ||
633 | + emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa); | ||
634 | +} | ||
635 | + | ||
636 | +static void emc_try_send_next_packet(NPCM7xxEMCState *emc) | ||
637 | +{ | ||
638 | + /* Working buffer for sending out packets. Most packets fit in this. */ | ||
639 | +#define TX_BUFFER_SIZE 2048 | ||
640 | + uint8_t tx_send_buffer[TX_BUFFER_SIZE]; | ||
641 | + uint32_t desc_addr = TX_DESC_NTXDSA(emc->regs[REG_CTXDSA]); | ||
642 | + NPCM7xxEMCTxDesc tx_desc; | ||
643 | + uint32_t next_buf_addr, length; | ||
644 | + uint8_t *buf; | ||
645 | + g_autofree uint8_t *malloced_buf = NULL; | ||
646 | + | ||
647 | + if (emc_read_tx_desc(desc_addr, &tx_desc)) { | ||
648 | + /* Error reading descriptor, already reported. */ | ||
649 | + emc_halt_tx(emc, REG_MISTA_TXBERR); | ||
650 | + emc_update_tx_irq(emc); | ||
651 | + return; | ||
652 | + } | ||
653 | + | ||
654 | + /* Nothing we can do if we don't own the descriptor. */ | ||
655 | + if (!(tx_desc.flags & TX_DESC_FLAG_OWNER_MASK)) { | ||
656 | + trace_npcm7xx_emc_cpu_owned_desc(desc_addr); | ||
657 | + emc_halt_tx(emc, REG_MISTA_TDU); | ||
658 | + emc_update_tx_irq(emc); | ||
659 | + return; | ||
660 | + } | ||
661 | + | ||
662 | + /* Give the descriptor back regardless of what happens. */ | ||
663 | + tx_desc.flags &= ~TX_DESC_FLAG_OWNER_MASK; | ||
664 | + tx_desc.status_and_length &= 0xffff; | ||
665 | + | ||
666 | + /* | ||
667 | + * Despite the h/w documentation saying the tx buffer is word aligned, | ||
668 | + * the linux driver does not word align the buffer. There is value in not | ||
669 | + * aligning the buffer: See the description of NET_IP_ALIGN in linux | ||
670 | + * kernel sources. | ||
671 | + */ | ||
672 | + next_buf_addr = tx_desc.txbsa; | ||
673 | + emc->regs[REG_CTXBSA] = next_buf_addr; | ||
674 | + length = TX_DESC_PKT_LEN(tx_desc.status_and_length); | ||
675 | + buf = &tx_send_buffer[0]; | ||
676 | + | ||
677 | + if (length > sizeof(tx_send_buffer)) { | ||
678 | + malloced_buf = g_malloc(length); | ||
679 | + buf = malloced_buf; | ||
680 | + } | ||
681 | + | ||
682 | + if (dma_memory_read(&address_space_memory, next_buf_addr, buf, length)) { | ||
683 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n", | ||
684 | + __func__, next_buf_addr); | ||
685 | + emc_set_mista(emc, REG_MISTA_TXBERR); | ||
686 | + emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr); | ||
687 | + emc_update_tx_irq(emc); | ||
688 | + trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]); | ||
689 | + return; | ||
690 | + } | ||
691 | + | ||
692 | + if ((tx_desc.flags & TX_DESC_FLAG_PADEN) && (length < MIN_PACKET_LENGTH)) { | ||
693 | + memset(buf + length, 0, MIN_PACKET_LENGTH - length); | ||
694 | + length = MIN_PACKET_LENGTH; | ||
695 | + } | ||
696 | + | ||
697 | + /* N.B. emc_receive can get called here. */ | ||
698 | + qemu_send_packet(qemu_get_queue(emc->nic), buf, length); | ||
699 | + trace_npcm7xx_emc_sent_packet(length); | ||
700 | + | ||
701 | + tx_desc.status_and_length |= TX_DESC_STATUS_TXCP; | ||
702 | + if (tx_desc.flags & TX_DESC_FLAG_INTEN) { | ||
703 | + emc_set_mista(emc, REG_MISTA_TXCP); | ||
704 | + } | ||
705 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_TXINTR) { | ||
706 | + tx_desc.status_and_length |= TX_DESC_STATUS_TXINTR; | ||
707 | + } | ||
708 | + | ||
709 | + emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr); | ||
710 | + emc_update_tx_irq(emc); | ||
711 | + trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]); | ||
712 | +} | ||
713 | + | ||
714 | +static bool emc_can_receive(NetClientState *nc) | ||
715 | +{ | ||
716 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc)); | ||
717 | + | ||
718 | + bool can_receive = emc->rx_active; | ||
719 | + trace_npcm7xx_emc_can_receive(can_receive); | ||
720 | + return can_receive; | ||
721 | +} | ||
722 | + | ||
723 | +/* If result is false then *fail_reason contains the reason. */ | ||
724 | +static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf, | ||
725 | + size_t len, const char **fail_reason) | ||
726 | +{ | ||
727 | + eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf)); | ||
728 | + | ||
729 | + switch (pkt_type) { | ||
730 | + case ETH_PKT_BCAST: | ||
731 | + if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) { | ||
732 | + return true; | ||
733 | + } else { | ||
734 | + *fail_reason = "Broadcast packet disabled"; | ||
735 | + return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_ABP); | ||
736 | + } | ||
737 | + case ETH_PKT_MCAST: | ||
738 | + if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) { | ||
739 | + return true; | ||
740 | + } else { | ||
741 | + *fail_reason = "Multicast packet disabled"; | ||
742 | + return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_AMP); | ||
743 | + } | ||
744 | + case ETH_PKT_UCAST: { | ||
745 | + bool matches; | ||
746 | + if (emc->regs[REG_CAMCMR] & REG_CAMCMR_AUP) { | ||
747 | + return true; | ||
748 | + } | ||
749 | + matches = ((emc->regs[REG_CAMCMR] & REG_CAMCMR_ECMP) && | ||
750 | + /* We only support one CAM register, CAM0. */ | ||
751 | + (emc->regs[REG_CAMEN] & (1 << 0)) && | ||
752 | + memcmp(buf, emc->conf.macaddr.a, ETH_ALEN) == 0); | ||
753 | + if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) { | ||
754 | + *fail_reason = "MACADDR matched, comparison complemented"; | ||
755 | + return !matches; | ||
756 | + } else { | ||
757 | + *fail_reason = "MACADDR didn't match"; | ||
758 | + return matches; | ||
759 | + } | ||
760 | + } | ||
761 | + default: | ||
762 | + g_assert_not_reached(); | ||
763 | + } | ||
764 | +} | ||
765 | + | ||
766 | +static bool emc_receive_filter(NPCM7xxEMCState *emc, const uint8_t *buf, | ||
767 | + size_t len) | ||
768 | +{ | ||
769 | + const char *fail_reason = NULL; | ||
770 | + bool ok = emc_receive_filter1(emc, buf, len, &fail_reason); | ||
771 | + if (!ok) { | ||
772 | + trace_npcm7xx_emc_packet_filtered_out(fail_reason); | ||
773 | + } | ||
774 | + return ok; | ||
775 | +} | ||
776 | + | ||
777 | +static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1) | ||
778 | +{ | ||
779 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc)); | ||
780 | + const uint32_t len = len1; | ||
781 | + size_t max_frame_len; | ||
782 | + bool long_frame; | ||
783 | + uint32_t desc_addr; | ||
784 | + NPCM7xxEMCRxDesc rx_desc; | ||
785 | + uint32_t crc; | ||
786 | + uint8_t *crc_ptr; | ||
787 | + uint32_t buf_addr; | ||
788 | + | ||
789 | + trace_npcm7xx_emc_receiving_packet(len); | ||
790 | + | ||
791 | + if (!emc_can_receive(nc)) { | ||
792 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Unexpected packet\n", __func__); | ||
793 | + return -1; | ||
794 | + } | ||
795 | + | ||
796 | + if (len < ETH_HLEN || | ||
797 | + /* Defensive programming: drop unsupportable large packets. */ | ||
798 | + len > 0xffff - CRC_LENGTH) { | ||
799 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Dropped frame of %u bytes\n", | ||
800 | + __func__, len); | ||
801 | + return len; | ||
802 | + } | ||
803 | + | ||
804 | + /* | ||
805 | + * DENI is set if EMC received the Length/Type field of the incoming | ||
806 | + * packet, so it will be set regardless of what happens next. | ||
807 | + */ | ||
808 | + emc_set_mista(emc, REG_MISTA_DENI); | ||
809 | + | ||
810 | + if (!emc_receive_filter(emc, buf, len)) { | ||
811 | + emc_update_rx_irq(emc); | ||
812 | + return len; | ||
813 | + } | ||
814 | + | ||
815 | + /* Huge frames (> DMARFC) are dropped. */ | ||
816 | + max_frame_len = REG_DMARFC_RXMS(emc->regs[REG_DMARFC]); | ||
817 | + if (len + CRC_LENGTH > max_frame_len) { | ||
818 | + trace_npcm7xx_emc_packet_dropped(len); | ||
819 | + emc_set_mista(emc, REG_MISTA_DFOI); | ||
820 | + emc_update_rx_irq(emc); | ||
821 | + return len; | ||
822 | + } | ||
823 | + | ||
824 | + /* | ||
825 | + * Long Frames (> MAX_ETH_FRAME_SIZE) are also dropped, unless MCMDR.ALP | ||
826 | + * is set. | ||
827 | + */ | ||
828 | + long_frame = false; | ||
829 | + if (len + CRC_LENGTH > MAX_ETH_FRAME_SIZE) { | ||
830 | + if (emc->regs[REG_MCMDR] & REG_MCMDR_ALP) { | ||
831 | + long_frame = true; | ||
832 | + } else { | ||
833 | + trace_npcm7xx_emc_packet_dropped(len); | ||
834 | + emc_set_mista(emc, REG_MISTA_PTLE); | ||
835 | + emc_update_rx_irq(emc); | ||
836 | + return len; | ||
837 | + } | ||
838 | + } | ||
839 | + | ||
840 | + desc_addr = RX_DESC_NRXDSA(emc->regs[REG_CRXDSA]); | ||
841 | + if (emc_read_rx_desc(desc_addr, &rx_desc)) { | ||
842 | + /* Error reading descriptor, already reported. */ | ||
843 | + emc_halt_rx(emc, REG_MISTA_RXBERR); | ||
844 | + emc_update_rx_irq(emc); | ||
845 | + return len; | ||
846 | + } | ||
847 | + | ||
848 | + /* Nothing we can do if we don't own the descriptor. */ | ||
849 | + if (!(rx_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK)) { | ||
850 | + trace_npcm7xx_emc_cpu_owned_desc(desc_addr); | ||
851 | + emc_halt_rx(emc, REG_MISTA_RDU); | ||
852 | + emc_update_rx_irq(emc); | ||
853 | + return len; | ||
854 | + } | ||
855 | + | ||
856 | + crc = 0; | ||
857 | + crc_ptr = (uint8_t *) &crc; | ||
858 | + if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) { | ||
859 | + crc = cpu_to_be32(crc32(~0, buf, len)); | ||
860 | + } | ||
861 | + | ||
862 | + /* Give the descriptor back regardless of what happens. */ | ||
863 | + rx_desc.status_and_length &= ~RX_DESC_STATUS_OWNER_MASK; | ||
864 | + | ||
865 | + buf_addr = rx_desc.rxbsa; | ||
866 | + emc->regs[REG_CRXBSA] = buf_addr; | ||
867 | + if (dma_memory_write(&address_space_memory, buf_addr, buf, len) || | ||
868 | + (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC) && | ||
869 | + dma_memory_write(&address_space_memory, buf_addr + len, crc_ptr, | ||
870 | + 4))) { | ||
871 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bus error writing packet\n", | ||
872 | + __func__); | ||
873 | + emc_set_mista(emc, REG_MISTA_RXBERR); | ||
874 | + emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr); | ||
875 | + emc_update_rx_irq(emc); | ||
876 | + trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]); | ||
877 | + return len; | ||
878 | + } | ||
879 | + | ||
880 | + trace_npcm7xx_emc_received_packet(len); | ||
881 | + | ||
882 | + /* Note: We've already verified len+4 <= 0xffff. */ | ||
883 | + rx_desc.status_and_length = len; | ||
884 | + if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) { | ||
885 | + rx_desc.status_and_length += 4; | ||
886 | + } | ||
887 | + rx_desc.status_and_length |= RX_DESC_STATUS_RXGD; | ||
888 | + emc_set_mista(emc, REG_MISTA_RXGD); | ||
889 | + | ||
890 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_RXINTR) { | ||
891 | + rx_desc.status_and_length |= RX_DESC_STATUS_RXINTR; | ||
892 | + } | ||
893 | + if (long_frame) { | ||
894 | + rx_desc.status_and_length |= RX_DESC_STATUS_PTLE; | ||
895 | + } | ||
896 | + | ||
897 | + emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr); | ||
898 | + emc_update_rx_irq(emc); | ||
899 | + trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]); | ||
900 | + return len; | ||
901 | +} | ||
902 | + | ||
903 | +static void emc_try_receive_next_packet(NPCM7xxEMCState *emc) | ||
904 | +{ | ||
905 | + if (emc_can_receive(qemu_get_queue(emc->nic))) { | ||
906 | + qemu_flush_queued_packets(qemu_get_queue(emc->nic)); | ||
907 | + } | ||
908 | +} | ||
909 | + | ||
910 | +static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsigned size) | ||
911 | +{ | ||
912 | + NPCM7xxEMCState *emc = opaque; | ||
913 | + uint32_t reg = offset / sizeof(uint32_t); | ||
914 | + uint32_t result; | ||
915 | + | ||
916 | + if (reg >= NPCM7XX_NUM_EMC_REGS) { | ||
917 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
918 | + "%s: Invalid offset 0x%04" HWADDR_PRIx "\n", | ||
919 | + __func__, offset); | ||
920 | + return 0; | ||
921 | + } | ||
922 | + | ||
923 | + switch (reg) { | ||
924 | + case REG_MIID: | ||
925 | + /* | ||
926 | + * We don't implement MII. For determinism, always return zero as | ||
927 | + * writes record the last value written for debugging purposes. | ||
928 | + */ | ||
929 | + qemu_log_mask(LOG_UNIMP, "%s: Read of MIID, returning 0\n", __func__); | ||
930 | + result = 0; | ||
931 | + break; | ||
932 | + case REG_TSDR: | ||
933 | + case REG_RSDR: | ||
934 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
935 | + "%s: Read of write-only reg, %s/%d\n", | ||
936 | + __func__, emc_reg_name(reg), reg); | ||
937 | + return 0; | ||
938 | + default: | ||
939 | + result = emc->regs[reg]; | ||
940 | + break; | ||
941 | + } | ||
942 | + | ||
943 | + trace_npcm7xx_emc_reg_read(emc->emc_num, result, emc_reg_name(reg), reg); | ||
944 | + return result; | ||
945 | +} | ||
946 | + | ||
947 | +static void npcm7xx_emc_write(void *opaque, hwaddr offset, | ||
948 | + uint64_t v, unsigned size) | ||
949 | +{ | ||
950 | + NPCM7xxEMCState *emc = opaque; | ||
951 | + uint32_t reg = offset / sizeof(uint32_t); | ||
952 | + uint32_t value = v; | ||
953 | + | ||
954 | + g_assert(size == sizeof(uint32_t)); | ||
955 | + | ||
956 | + if (reg >= NPCM7XX_NUM_EMC_REGS) { | ||
957 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
958 | + "%s: Invalid offset 0x%04" HWADDR_PRIx "\n", | ||
959 | + __func__, offset); | ||
960 | + return; | ||
961 | + } | ||
962 | + | ||
963 | + trace_npcm7xx_emc_reg_write(emc->emc_num, emc_reg_name(reg), reg, value); | ||
964 | + | ||
965 | + switch (reg) { | ||
966 | + case REG_CAMCMR: | ||
967 | + emc->regs[reg] = value; | ||
968 | + break; | ||
969 | + case REG_CAMEN: | ||
970 | + /* Only CAM0 is supported, don't pretend otherwise. */ | ||
971 | + if (value & ~1) { | ||
972 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
973 | + "%s: Only CAM0 is supported, cannot enable others" | ||
974 | + ": 0x%x\n", | ||
975 | + __func__, value); | ||
976 | + } | ||
977 | + emc->regs[reg] = value & 1; | ||
978 | + break; | ||
979 | + case REG_CAMM_BASE + 0: | ||
980 | + emc->regs[reg] = value; | ||
981 | + emc->conf.macaddr.a[0] = value >> 24; | ||
982 | + emc->conf.macaddr.a[1] = value >> 16; | ||
983 | + emc->conf.macaddr.a[2] = value >> 8; | ||
984 | + emc->conf.macaddr.a[3] = value >> 0; | ||
985 | + break; | ||
986 | + case REG_CAML_BASE + 0: | ||
987 | + emc->regs[reg] = value; | ||
988 | + emc->conf.macaddr.a[4] = value >> 24; | ||
989 | + emc->conf.macaddr.a[5] = value >> 16; | ||
990 | + break; | ||
991 | + case REG_MCMDR: { | ||
992 | + uint32_t prev; | ||
993 | + if (value & REG_MCMDR_SWR) { | ||
994 | + emc_soft_reset(emc); | ||
995 | + /* On h/w the reset happens over multiple cycles. For now KISS. */ | ||
996 | + break; | ||
997 | + } | ||
998 | + prev = emc->regs[reg]; | ||
999 | + emc->regs[reg] = value; | ||
1000 | + /* Update tx state. */ | ||
1001 | + if (!(prev & REG_MCMDR_TXON) && | ||
1002 | + (value & REG_MCMDR_TXON)) { | ||
1003 | + emc->regs[REG_CTXDSA] = emc->regs[REG_TXDLSA]; | ||
1004 | + /* | ||
1005 | + * Linux kernel turns TX on with CPU still holding descriptor, | ||
1006 | + * which suggests we should wait for a write to TSDR before trying | ||
1007 | + * to send a packet: so we don't send one here. | ||
1008 | + */ | ||
1009 | + } else if ((prev & REG_MCMDR_TXON) && | ||
1010 | + !(value & REG_MCMDR_TXON)) { | ||
1011 | + emc->regs[REG_MGSTA] |= REG_MGSTA_TXHA; | ||
1012 | + } | ||
1013 | + if (!(value & REG_MCMDR_TXON)) { | ||
1014 | + emc_halt_tx(emc, 0); | ||
1015 | + } | ||
1016 | + /* Update rx state. */ | ||
1017 | + if (!(prev & REG_MCMDR_RXON) && | ||
1018 | + (value & REG_MCMDR_RXON)) { | ||
1019 | + emc->regs[REG_CRXDSA] = emc->regs[REG_RXDLSA]; | ||
1020 | + } else if ((prev & REG_MCMDR_RXON) && | ||
1021 | + !(value & REG_MCMDR_RXON)) { | ||
1022 | + emc->regs[REG_MGSTA] |= REG_MGSTA_RXHA; | ||
1023 | + } | ||
1024 | + if (!(value & REG_MCMDR_RXON)) { | ||
1025 | + emc_halt_rx(emc, 0); | ||
1026 | + } | ||
1027 | + break; | ||
1028 | + } | ||
1029 | + case REG_TXDLSA: | ||
1030 | + case REG_RXDLSA: | ||
1031 | + case REG_DMARFC: | ||
1032 | + case REG_MIID: | ||
1033 | + emc->regs[reg] = value; | ||
1034 | + break; | ||
1035 | + case REG_MIEN: | ||
1036 | + emc->regs[reg] = value; | ||
1037 | + emc_update_irq_from_reg_change(emc); | ||
1038 | + break; | ||
1039 | + case REG_MISTA: | ||
1040 | + /* Clear the bits that have 1 in "value". */ | ||
1041 | + emc->regs[reg] &= ~value; | ||
1042 | + emc_update_irq_from_reg_change(emc); | ||
1043 | + break; | ||
1044 | + case REG_MGSTA: | ||
1045 | + /* Clear the bits that have 1 in "value". */ | ||
1046 | + emc->regs[reg] &= ~value; | ||
1047 | + break; | ||
1048 | + case REG_TSDR: | ||
1049 | + if (emc->regs[REG_MCMDR] & REG_MCMDR_TXON) { | ||
1050 | + emc->tx_active = true; | ||
1051 | + /* Keep trying to send packets until we run out. */ | ||
1052 | + while (emc->tx_active) { | ||
1053 | + emc_try_send_next_packet(emc); | ||
1054 | + } | ||
1055 | + } | ||
1056 | + break; | ||
1057 | + case REG_RSDR: | ||
1058 | + if (emc->regs[REG_MCMDR] & REG_MCMDR_RXON) { | ||
1059 | + emc->rx_active = true; | ||
1060 | + emc_try_receive_next_packet(emc); | ||
1061 | + } | ||
1062 | + break; | ||
1063 | + case REG_MIIDA: | ||
1064 | + emc->regs[reg] = value & ~REG_MIIDA_BUSY; | ||
1065 | + break; | ||
1066 | + case REG_MRPC: | ||
1067 | + case REG_MRPCC: | ||
1068 | + case REG_MREPC: | ||
1069 | + case REG_CTXDSA: | ||
1070 | + case REG_CTXBSA: | ||
1071 | + case REG_CRXDSA: | ||
1072 | + case REG_CRXBSA: | ||
1073 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
1074 | + "%s: Write to read-only reg %s/%d\n", | ||
1075 | + __func__, emc_reg_name(reg), reg); | ||
1076 | + break; | ||
1077 | + default: | ||
1078 | + qemu_log_mask(LOG_UNIMP, "%s: Write to unimplemented reg %s/%d\n", | ||
1079 | + __func__, emc_reg_name(reg), reg); | ||
1080 | + break; | ||
1081 | + } | ||
1082 | +} | ||
1083 | + | ||
1084 | +static const struct MemoryRegionOps npcm7xx_emc_ops = { | ||
1085 | + .read = npcm7xx_emc_read, | ||
1086 | + .write = npcm7xx_emc_write, | ||
1087 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
1088 | + .valid = { | ||
1089 | + .min_access_size = 4, | ||
1090 | + .max_access_size = 4, | ||
1091 | + .unaligned = false, | ||
1092 | + }, | ||
110 | +}; | 1093 | +}; |
111 | + | 1094 | + |
112 | +static void pvpanic_isa_initfn(Object *obj) | 1095 | +static void emc_cleanup(NetClientState *nc) |
113 | +{ | 1096 | +{ |
114 | + PVPanicISAState *s = PVPANIC_ISA_DEVICE(obj); | 1097 | + /* Nothing to do yet. */ |
115 | + | 1098 | +} |
116 | + pvpanic_setup_io(&s->pvpanic, DEVICE(s), 1); | 1099 | + |
117 | +} | 1100 | +static NetClientInfo net_npcm7xx_emc_info = { |
118 | + | 1101 | + .type = NET_CLIENT_DRIVER_NIC, |
119 | +static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) | 1102 | + .size = sizeof(NICState), |
120 | +{ | 1103 | + .can_receive = emc_can_receive, |
121 | + ISADevice *d = ISA_DEVICE(dev); | 1104 | + .receive = emc_receive, |
122 | + PVPanicISAState *s = PVPANIC_ISA_DEVICE(dev); | 1105 | + .cleanup = emc_cleanup, |
123 | + PVPanicState *ps = &s->pvpanic; | 1106 | + .link_status_changed = emc_set_link, |
124 | + FWCfgState *fw_cfg = fw_cfg_find(); | 1107 | +}; |
125 | + uint16_t *pvpanic_port; | 1108 | + |
126 | + | 1109 | +static void npcm7xx_emc_realize(DeviceState *dev, Error **errp) |
127 | + if (!fw_cfg) { | 1110 | +{ |
128 | + return; | 1111 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); |
129 | + } | 1112 | + SysBusDevice *sbd = SYS_BUS_DEVICE(emc); |
130 | + | 1113 | + |
131 | + pvpanic_port = g_malloc(sizeof(*pvpanic_port)); | 1114 | + memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc, |
132 | + *pvpanic_port = cpu_to_le16(s->ioport); | 1115 | + TYPE_NPCM7XX_EMC, 4 * KiB); |
133 | + fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port, | 1116 | + sysbus_init_mmio(sbd, &emc->iomem); |
134 | + sizeof(*pvpanic_port)); | 1117 | + sysbus_init_irq(sbd, &emc->tx_irq); |
135 | + | 1118 | + sysbus_init_irq(sbd, &emc->rx_irq); |
136 | + isa_register_ioport(d, &ps->mr, s->ioport); | 1119 | + |
137 | +} | 1120 | + qemu_macaddr_default_if_unset(&emc->conf.macaddr); |
138 | + | 1121 | + emc->nic = qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf, |
139 | +static Property pvpanic_isa_properties[] = { | 1122 | + object_get_typename(OBJECT(dev)), dev->id, emc); |
140 | + DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicISAState, ioport, 0x505), | 1123 | + qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a); |
141 | + DEFINE_PROP_UINT8("events", PVPanicISAState, pvpanic.events, PVPANIC_PANICKED | PVPANIC_CRASHLOADED), | 1124 | +} |
1125 | + | ||
1126 | +static void npcm7xx_emc_unrealize(DeviceState *dev) | ||
1127 | +{ | ||
1128 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); | ||
1129 | + | ||
1130 | + qemu_del_nic(emc->nic); | ||
1131 | +} | ||
1132 | + | ||
1133 | +static const VMStateDescription vmstate_npcm7xx_emc = { | ||
1134 | + .name = TYPE_NPCM7XX_EMC, | ||
1135 | + .version_id = 0, | ||
1136 | + .minimum_version_id = 0, | ||
1137 | + .fields = (VMStateField[]) { | ||
1138 | + VMSTATE_UINT8(emc_num, NPCM7xxEMCState), | ||
1139 | + VMSTATE_UINT32_ARRAY(regs, NPCM7xxEMCState, NPCM7XX_NUM_EMC_REGS), | ||
1140 | + VMSTATE_BOOL(tx_active, NPCM7xxEMCState), | ||
1141 | + VMSTATE_BOOL(rx_active, NPCM7xxEMCState), | ||
1142 | + VMSTATE_END_OF_LIST(), | ||
1143 | + }, | ||
1144 | +}; | ||
1145 | + | ||
1146 | +static Property npcm7xx_emc_properties[] = { | ||
1147 | + DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf), | ||
142 | + DEFINE_PROP_END_OF_LIST(), | 1148 | + DEFINE_PROP_END_OF_LIST(), |
143 | +}; | 1149 | +}; |
144 | + | 1150 | + |
145 | +static void pvpanic_isa_class_init(ObjectClass *klass, void *data) | 1151 | +static void npcm7xx_emc_class_init(ObjectClass *klass, void *data) |
146 | +{ | 1152 | +{ |
147 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1153 | + DeviceClass *dc = DEVICE_CLASS(klass); |
148 | + | 1154 | + |
149 | + dc->realize = pvpanic_isa_realizefn; | 1155 | + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); |
150 | + device_class_set_props(dc, pvpanic_isa_properties); | 1156 | + dc->desc = "NPCM7xx EMC Controller"; |
151 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 1157 | + dc->realize = npcm7xx_emc_realize; |
152 | +} | 1158 | + dc->unrealize = npcm7xx_emc_unrealize; |
153 | + | 1159 | + dc->reset = npcm7xx_emc_reset; |
154 | +static TypeInfo pvpanic_isa_info = { | 1160 | + dc->vmsd = &vmstate_npcm7xx_emc; |
155 | + .name = TYPE_PVPANIC_ISA_DEVICE, | 1161 | + device_class_set_props(dc, npcm7xx_emc_properties); |
156 | + .parent = TYPE_ISA_DEVICE, | 1162 | +} |
157 | + .instance_size = sizeof(PVPanicISAState), | 1163 | + |
158 | + .instance_init = pvpanic_isa_initfn, | 1164 | +static const TypeInfo npcm7xx_emc_info = { |
159 | + .class_init = pvpanic_isa_class_init, | 1165 | + .name = TYPE_NPCM7XX_EMC, |
1166 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
1167 | + .instance_size = sizeof(NPCM7xxEMCState), | ||
1168 | + .class_init = npcm7xx_emc_class_init, | ||
160 | +}; | 1169 | +}; |
161 | + | 1170 | + |
162 | +static void pvpanic_register_types(void) | 1171 | +static void npcm7xx_emc_register_type(void) |
163 | +{ | 1172 | +{ |
164 | + type_register_static(&pvpanic_isa_info); | 1173 | + type_register_static(&npcm7xx_emc_info); |
165 | +} | 1174 | +} |
166 | + | 1175 | + |
167 | +type_init(pvpanic_register_types) | 1176 | +type_init(npcm7xx_emc_register_type) |
168 | diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c | 1177 | diff --git a/hw/net/meson.build b/hw/net/meson.build |
169 | index XXXXXXX..XXXXXXX 100644 | 1178 | index XXXXXXX..XXXXXXX 100644 |
170 | --- a/hw/misc/pvpanic.c | 1179 | --- a/hw/net/meson.build |
171 | +++ b/hw/misc/pvpanic.c | 1180 | +++ b/hw/net/meson.build |
172 | @@ -XXX,XX +XXX,XX @@ | 1181 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c')) |
173 | #include "hw/misc/pvpanic.h" | 1182 | softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c')) |
174 | #include "qom/object.h" | 1183 | softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c')) |
175 | 1184 | softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c')) | |
176 | -/* The bit of supported pv event, TODO: include uapi header and remove this */ | 1185 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c')) |
177 | -#define PVPANIC_F_PANICKED 0 | 1186 | |
178 | -#define PVPANIC_F_CRASHLOADED 1 | 1187 | softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c')) |
179 | - | 1188 | softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c')) |
180 | -/* The pv event value */ | 1189 | diff --git a/hw/net/trace-events b/hw/net/trace-events |
181 | -#define PVPANIC_PANICKED (1 << PVPANIC_F_PANICKED) | ||
182 | -#define PVPANIC_CRASHLOADED (1 << PVPANIC_F_CRASHLOADED) | ||
183 | - | ||
184 | -typedef struct PVPanicState PVPanicState; | ||
185 | -DECLARE_INSTANCE_CHECKER(PVPanicState, ISA_PVPANIC_DEVICE, | ||
186 | - TYPE_PVPANIC) | ||
187 | - | ||
188 | static void handle_event(int event) | ||
189 | { | ||
190 | static bool logged; | ||
191 | @@ -XXX,XX +XXX,XX @@ static void handle_event(int event) | ||
192 | } | ||
193 | } | ||
194 | |||
195 | -#include "hw/isa/isa.h" | ||
196 | - | ||
197 | -struct PVPanicState { | ||
198 | - ISADevice parent_obj; | ||
199 | - | ||
200 | - MemoryRegion io; | ||
201 | - uint16_t ioport; | ||
202 | - uint8_t events; | ||
203 | -}; | ||
204 | - | ||
205 | /* return supported events on read */ | ||
206 | -static uint64_t pvpanic_ioport_read(void *opaque, hwaddr addr, unsigned size) | ||
207 | +static uint64_t pvpanic_read(void *opaque, hwaddr addr, unsigned size) | ||
208 | { | ||
209 | PVPanicState *pvp = opaque; | ||
210 | return pvp->events; | ||
211 | } | ||
212 | |||
213 | -static void pvpanic_ioport_write(void *opaque, hwaddr addr, uint64_t val, | ||
214 | +static void pvpanic_write(void *opaque, hwaddr addr, uint64_t val, | ||
215 | unsigned size) | ||
216 | { | ||
217 | handle_event(val); | ||
218 | } | ||
219 | |||
220 | static const MemoryRegionOps pvpanic_ops = { | ||
221 | - .read = pvpanic_ioport_read, | ||
222 | - .write = pvpanic_ioport_write, | ||
223 | + .read = pvpanic_read, | ||
224 | + .write = pvpanic_write, | ||
225 | .impl = { | ||
226 | .min_access_size = 1, | ||
227 | .max_access_size = 1, | ||
228 | }, | ||
229 | }; | ||
230 | |||
231 | -static void pvpanic_isa_initfn(Object *obj) | ||
232 | +void pvpanic_setup_io(PVPanicState *s, DeviceState *dev, unsigned size) | ||
233 | { | ||
234 | - PVPanicState *s = ISA_PVPANIC_DEVICE(obj); | ||
235 | - | ||
236 | - memory_region_init_io(&s->io, OBJECT(s), &pvpanic_ops, s, "pvpanic", 1); | ||
237 | + memory_region_init_io(&s->mr, OBJECT(dev), &pvpanic_ops, s, "pvpanic", size); | ||
238 | } | ||
239 | - | ||
240 | -static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp) | ||
241 | -{ | ||
242 | - ISADevice *d = ISA_DEVICE(dev); | ||
243 | - PVPanicState *s = ISA_PVPANIC_DEVICE(dev); | ||
244 | - FWCfgState *fw_cfg = fw_cfg_find(); | ||
245 | - uint16_t *pvpanic_port; | ||
246 | - | ||
247 | - if (!fw_cfg) { | ||
248 | - return; | ||
249 | - } | ||
250 | - | ||
251 | - pvpanic_port = g_malloc(sizeof(*pvpanic_port)); | ||
252 | - *pvpanic_port = cpu_to_le16(s->ioport); | ||
253 | - fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port, | ||
254 | - sizeof(*pvpanic_port)); | ||
255 | - | ||
256 | - isa_register_ioport(d, &s->io, s->ioport); | ||
257 | -} | ||
258 | - | ||
259 | -static Property pvpanic_isa_properties[] = { | ||
260 | - DEFINE_PROP_UINT16(PVPANIC_IOPORT_PROP, PVPanicState, ioport, 0x505), | ||
261 | - DEFINE_PROP_UINT8("events", PVPanicState, events, PVPANIC_PANICKED | PVPANIC_CRASHLOADED), | ||
262 | - DEFINE_PROP_END_OF_LIST(), | ||
263 | -}; | ||
264 | - | ||
265 | -static void pvpanic_isa_class_init(ObjectClass *klass, void *data) | ||
266 | -{ | ||
267 | - DeviceClass *dc = DEVICE_CLASS(klass); | ||
268 | - | ||
269 | - dc->realize = pvpanic_isa_realizefn; | ||
270 | - device_class_set_props(dc, pvpanic_isa_properties); | ||
271 | - set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
272 | -} | ||
273 | - | ||
274 | -static TypeInfo pvpanic_isa_info = { | ||
275 | - .name = TYPE_PVPANIC, | ||
276 | - .parent = TYPE_ISA_DEVICE, | ||
277 | - .instance_size = sizeof(PVPanicState), | ||
278 | - .instance_init = pvpanic_isa_initfn, | ||
279 | - .class_init = pvpanic_isa_class_init, | ||
280 | -}; | ||
281 | - | ||
282 | -static void pvpanic_register_types(void) | ||
283 | -{ | ||
284 | - type_register_static(&pvpanic_isa_info); | ||
285 | -} | ||
286 | - | ||
287 | -type_init(pvpanic_register_types) | ||
288 | diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig | ||
289 | index XXXXXXX..XXXXXXX 100644 | 1190 | index XXXXXXX..XXXXXXX 100644 |
290 | --- a/hw/i386/Kconfig | 1191 | --- a/hw/net/trace-events |
291 | +++ b/hw/i386/Kconfig | 1192 | +++ b/hw/net/trace-events |
292 | @@ -XXX,XX +XXX,XX @@ config PC | 1193 | @@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x" |
293 | imply ISA_DEBUG | 1194 | imx_enet_receive(size_t size) "len %zu" |
294 | imply PARALLEL | 1195 | imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d" |
295 | imply PCI_DEVICES | 1196 | imx_enet_receive_last(int last) "rx frame flags 0x%04x" |
296 | - imply PVPANIC | 1197 | + |
297 | + imply PVPANIC_ISA | 1198 | +# npcm7xx_emc.c |
298 | imply QXL | 1199 | +npcm7xx_emc_reset(int emc_num) "Resetting emc%d" |
299 | imply SEV | 1200 | +npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d" |
300 | imply SGA | 1201 | +npcm7xx_emc_update_rx_irq(int level) "Setting rx irq to %d" |
301 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | 1202 | +npcm7xx_emc_set_mista(uint32_t flags) "ORing 0x%x into MISTA" |
302 | index XXXXXXX..XXXXXXX 100644 | 1203 | +npcm7xx_emc_cpu_owned_desc(uint32_t addr) "Can't process cpu-owned descriptor @0x%x" |
303 | --- a/hw/misc/Kconfig | 1204 | +npcm7xx_emc_sent_packet(uint32_t len) "Sent %u byte packet" |
304 | +++ b/hw/misc/Kconfig | 1205 | +npcm7xx_emc_tx_done(uint32_t ctxdsa) "TX done, CTXDSA=0x%x" |
305 | @@ -XXX,XX +XXX,XX @@ config IOTKIT_SYSCTL | 1206 | +npcm7xx_emc_can_receive(int can_receive) "Can receive: %d" |
306 | config IOTKIT_SYSINFO | 1207 | +npcm7xx_emc_packet_filtered_out(const char* fail_reason) "Packet filtered out: %s" |
307 | bool | 1208 | +npcm7xx_emc_packet_dropped(uint32_t len) "%u byte packet dropped" |
308 | 1209 | +npcm7xx_emc_receiving_packet(uint32_t len) "Receiving %u byte packet" | |
309 | -config PVPANIC | 1210 | +npcm7xx_emc_received_packet(uint32_t len) "Received %u byte packet" |
310 | +config PVPANIC_COMMON | 1211 | +npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x" |
311 | + bool | 1212 | +npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]" |
312 | + | 1213 | +npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x" |
313 | +config PVPANIC_ISA | ||
314 | bool | ||
315 | depends on ISA_BUS | ||
316 | + select PVPANIC_COMMON | ||
317 | |||
318 | config AUX | ||
319 | bool | ||
320 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
321 | index XXXXXXX..XXXXXXX 100644 | ||
322 | --- a/hw/misc/meson.build | ||
323 | +++ b/hw/misc/meson.build | ||
324 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_EMC141X', if_true: files('emc141x.c')) | ||
325 | softmmu_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) | ||
326 | softmmu_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) | ||
327 | softmmu_ss.add(when: 'CONFIG_LED', if_true: files('led.c')) | ||
328 | +softmmu_ss.add(when: 'CONFIG_PVPANIC_COMMON', if_true: files('pvpanic.c')) | ||
329 | |||
330 | # ARM devices | ||
331 | softmmu_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c')) | ||
332 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IOTKIT_SYSINFO', if_true: files('iotkit-sysinfo.c') | ||
333 | softmmu_ss.add(when: 'CONFIG_ARMSSE_CPUID', if_true: files('armsse-cpuid.c')) | ||
334 | softmmu_ss.add(when: 'CONFIG_ARMSSE_MHU', if_true: files('armsse-mhu.c')) | ||
335 | |||
336 | -softmmu_ss.add(when: 'CONFIG_PVPANIC', if_true: files('pvpanic.c')) | ||
337 | +softmmu_ss.add(when: 'CONFIG_PVPANIC_ISA', if_true: files('pvpanic-isa.c')) | ||
338 | softmmu_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) | ||
339 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_scu.c', 'aspeed_sdmc.c', 'aspeed_xdma.c')) | ||
340 | softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-sysreg.c')) | ||
341 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
342 | index XXXXXXX..XXXXXXX 100644 | ||
343 | --- a/tests/qtest/meson.build | ||
344 | +++ b/tests/qtest/meson.build | ||
345 | @@ -XXX,XX +XXX,XX @@ qtests_i386 = \ | ||
346 | (config_host.has_key('CONFIG_LINUX') and \ | ||
347 | config_all_devices.has_key('CONFIG_ISA_IPMI_BT') ? ['ipmi-bt-test'] : []) + \ | ||
348 | (config_all_devices.has_key('CONFIG_WDT_IB700') ? ['wdt_ib700-test'] : []) + \ | ||
349 | - (config_all_devices.has_key('CONFIG_PVPANIC') ? ['pvpanic-test'] : []) + \ | ||
350 | + (config_all_devices.has_key('CONFIG_PVPANIC_ISA') ? ['pvpanic-test'] : []) + \ | ||
351 | (config_all_devices.has_key('CONFIG_HDA') ? ['intel-hda-test'] : []) + \ | ||
352 | (config_all_devices.has_key('CONFIG_I82801B11') ? ['i82801b11-test'] : []) + \ | ||
353 | (config_all_devices.has_key('CONFIG_IOH3420') ? ['ioh3420-test'] : []) + \ | ||
354 | -- | 1214 | -- |
355 | 2.20.1 | 1215 | 2.20.1 |
356 | 1216 | ||
357 | 1217 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Add a function for checking whether a clock has a source. This is | ||
2 | useful for devices which have input clocks that must be wired up by | ||
3 | the board as it allows them to fail in realize rather than ploughing | ||
4 | on with a zero-period clock. | ||
5 | 1 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 20210128114145.20536-3-peter.maydell@linaro.org | ||
11 | Message-id: 20210121190622.22000-3-peter.maydell@linaro.org | ||
12 | --- | ||
13 | docs/devel/clocks.rst | 16 ++++++++++++++++ | ||
14 | include/hw/clock.h | 15 +++++++++++++++ | ||
15 | 2 files changed, 31 insertions(+) | ||
16 | |||
17 | diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/docs/devel/clocks.rst | ||
20 | +++ b/docs/devel/clocks.rst | ||
21 | @@ -XXX,XX +XXX,XX @@ object during device instance init. For example: | ||
22 | /* set initial value to 10ns / 100MHz */ | ||
23 | clock_set_ns(clk, 10); | ||
24 | |||
25 | +To enforce that the clock is wired up by the board code, you can | ||
26 | +call ``clock_has_source()`` in your device's realize method: | ||
27 | + | ||
28 | +.. code-block:: c | ||
29 | + | ||
30 | + if (!clock_has_source(s->clk)) { | ||
31 | + error_setg(errp, "MyDevice: clk input must be connected"); | ||
32 | + return; | ||
33 | + } | ||
34 | + | ||
35 | +Note that this only checks that the clock has been wired up; it is | ||
36 | +still possible that the output clock connected to it is disabled | ||
37 | +or has not yet been configured, in which case the period will be | ||
38 | +zero. You should use the clock callback to find out when the clock | ||
39 | +period changes. | ||
40 | + | ||
41 | Fetching clock frequency/period | ||
42 | ------------------------------- | ||
43 | |||
44 | diff --git a/include/hw/clock.h b/include/hw/clock.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/include/hw/clock.h | ||
47 | +++ b/include/hw/clock.h | ||
48 | @@ -XXX,XX +XXX,XX @@ void clock_clear_callback(Clock *clk); | ||
49 | */ | ||
50 | void clock_set_source(Clock *clk, Clock *src); | ||
51 | |||
52 | +/** | ||
53 | + * clock_has_source: | ||
54 | + * @clk: the clock | ||
55 | + * | ||
56 | + * Returns true if the clock has a source clock connected to it. | ||
57 | + * This is useful for devices which have input clocks which must | ||
58 | + * be connected by the board/SoC code which creates them. The | ||
59 | + * device code can use this to check in its realize method that | ||
60 | + * the clock has been connected. | ||
61 | + */ | ||
62 | +static inline bool clock_has_source(const Clock *clk) | ||
63 | +{ | ||
64 | + return clk->source != NULL; | ||
65 | +} | ||
66 | + | ||
67 | /** | ||
68 | * clock_set: | ||
69 | * @clk: the clock to initialize. | ||
70 | -- | ||
71 | 2.20.1 | ||
72 | |||
73 | diff view generated by jsdifflib |
1 | The state struct for the CMSDK APB timer device doesn't follow our | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | usual naming convention of camelcase -- "CMSDK" and "APB" are both | ||
3 | acronyms, but "TIMER" is not so should not be all-uppercase. | ||
4 | Globally rename the struct to "CMSDKAPBTimer" (bringing it into line | ||
5 | with CMSDKAPBWatchdog and CMSDKAPBDualTimer; CMSDKAPBUART remains | ||
6 | as-is because "UART" is an acronym). | ||
7 | 2 | ||
8 | Commit created with: | 3 | This is a 10/100 ethernet device that has several features. |
9 | perl -p -i -e 's/CMSDKAPBTIMER/CMSDKAPBTimer/g' hw/timer/cmsdk-apb-timer.c include/hw/arm/armsse.h include/hw/timer/cmsdk-apb-timer.h | 4 | Only the ones needed by the Linux driver have been implemented. |
5 | See npcm7xx_emc.c for a list of unimplemented features. | ||
10 | 6 | ||
7 | Reviewed-by: Hao Wu <wuhaotsh@google.com> | ||
8 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Doug Evans <dje@google.com> | ||
11 | Message-id: 20210213002520.1374134-3-dje@google.com | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Message-id: 20210128114145.20536-7-peter.maydell@linaro.org | ||
16 | Message-id: 20210121190622.22000-7-peter.maydell@linaro.org | ||
17 | --- | 13 | --- |
18 | include/hw/arm/armsse.h | 6 +++--- | 14 | docs/system/arm/nuvoton.rst | 3 ++- |
19 | include/hw/timer/cmsdk-apb-timer.h | 4 ++-- | 15 | include/hw/arm/npcm7xx.h | 2 ++ |
20 | hw/timer/cmsdk-apb-timer.c | 28 ++++++++++++++-------------- | 16 | hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++-- |
21 | 3 files changed, 19 insertions(+), 19 deletions(-) | 17 | 3 files changed, 52 insertions(+), 3 deletions(-) |
22 | 18 | ||
23 | diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h | 19 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
24 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/arm/armsse.h | 21 | --- a/docs/system/arm/nuvoton.rst |
26 | +++ b/include/hw/arm/armsse.h | 22 | +++ b/docs/system/arm/nuvoton.rst |
27 | @@ -XXX,XX +XXX,XX @@ struct ARMSSE { | 23 | @@ -XXX,XX +XXX,XX @@ Supported devices |
28 | TZPPC apb_ppc0; | 24 | * Analog to Digital Converter (ADC) |
29 | TZPPC apb_ppc1; | 25 | * Pulse Width Modulation (PWM) |
30 | TZMPC mpc[IOTS_NUM_MPC]; | 26 | * SMBus controller (SMBF) |
31 | - CMSDKAPBTIMER timer0; | 27 | + * Ethernet controller (EMC) |
32 | - CMSDKAPBTIMER timer1; | 28 | |
33 | - CMSDKAPBTIMER s32ktimer; | 29 | Missing devices |
34 | + CMSDKAPBTimer timer0; | 30 | --------------- |
35 | + CMSDKAPBTimer timer1; | 31 | @@ -XXX,XX +XXX,XX @@ Missing devices |
36 | + CMSDKAPBTimer s32ktimer; | 32 | * Shared memory (SHM) |
37 | qemu_or_irq ppc_irq_orgate; | 33 | * eSPI slave interface |
38 | SplitIRQ sec_resp_splitter; | 34 | |
39 | SplitIRQ ppc_irq_splitter[NUM_PPCS]; | 35 | - * Ethernet controllers (GMAC and EMC) |
40 | diff --git a/include/hw/timer/cmsdk-apb-timer.h b/include/hw/timer/cmsdk-apb-timer.h | 36 | + * Ethernet controller (GMAC) |
37 | * USB device (USBD) | ||
38 | * Peripheral SPI controller (PSPI) | ||
39 | * SD/MMC host | ||
40 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/include/hw/timer/cmsdk-apb-timer.h | 42 | --- a/include/hw/arm/npcm7xx.h |
43 | +++ b/include/hw/timer/cmsdk-apb-timer.h | 43 | +++ b/include/hw/arm/npcm7xx.h |
44 | @@ -XXX,XX +XXX,XX @@ | 44 | @@ -XXX,XX +XXX,XX @@ |
45 | #include "qom/object.h" | 45 | #include "hw/misc/npcm7xx_gcr.h" |
46 | 46 | #include "hw/misc/npcm7xx_pwm.h" | |
47 | #define TYPE_CMSDK_APB_TIMER "cmsdk-apb-timer" | 47 | #include "hw/misc/npcm7xx_rng.h" |
48 | -OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTIMER, CMSDK_APB_TIMER) | 48 | +#include "hw/net/npcm7xx_emc.h" |
49 | +OBJECT_DECLARE_SIMPLE_TYPE(CMSDKAPBTimer, CMSDK_APB_TIMER) | 49 | #include "hw/nvram/npcm7xx_otp.h" |
50 | 50 | #include "hw/timer/npcm7xx_timer.h" | |
51 | -struct CMSDKAPBTIMER { | 51 | #include "hw/ssi/npcm7xx_fiu.h" |
52 | +struct CMSDKAPBTimer { | 52 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
53 | /*< private >*/ | 53 | EHCISysBusState ehci; |
54 | SysBusDevice parent_obj; | 54 | OHCISysBusState ohci; |
55 | 55 | NPCM7xxFIUState fiu[2]; | |
56 | diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c | 56 | + NPCM7xxEMCState emc[2]; |
57 | } NPCM7xxState; | ||
58 | |||
59 | #define TYPE_NPCM7XX "npcm7xx" | ||
60 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | 61 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/hw/timer/cmsdk-apb-timer.c | 62 | --- a/hw/arm/npcm7xx.c |
59 | +++ b/hw/timer/cmsdk-apb-timer.c | 63 | +++ b/hw/arm/npcm7xx.c |
60 | @@ -XXX,XX +XXX,XX @@ static const int timer_id[] = { | 64 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
61 | 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */ | 65 | NPCM7XX_UART1_IRQ, |
66 | NPCM7XX_UART2_IRQ, | ||
67 | NPCM7XX_UART3_IRQ, | ||
68 | + NPCM7XX_EMC1RX_IRQ = 15, | ||
69 | + NPCM7XX_EMC1TX_IRQ, | ||
70 | NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */ | ||
71 | NPCM7XX_TIMER1_IRQ, | ||
72 | NPCM7XX_TIMER2_IRQ, | ||
73 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
74 | NPCM7XX_SMBUS15_IRQ, | ||
75 | NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ | ||
76 | NPCM7XX_PWM1_IRQ, /* PWM module 1 */ | ||
77 | + NPCM7XX_EMC2RX_IRQ = 114, | ||
78 | + NPCM7XX_EMC2TX_IRQ, | ||
79 | NPCM7XX_GPIO0_IRQ = 116, | ||
80 | NPCM7XX_GPIO1_IRQ, | ||
81 | NPCM7XX_GPIO2_IRQ, | ||
82 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = { | ||
83 | 0xf008f000, | ||
62 | }; | 84 | }; |
63 | 85 | ||
64 | -static void cmsdk_apb_timer_update(CMSDKAPBTIMER *s) | 86 | +/* Register base address for each EMC Module */ |
65 | +static void cmsdk_apb_timer_update(CMSDKAPBTimer *s) | 87 | +static const hwaddr npcm7xx_emc_addr[] = { |
66 | { | 88 | + 0xf0825000, |
67 | qemu_set_irq(s->timerint, !!(s->intstatus & R_INTSTATUS_IRQ_MASK)); | 89 | + 0xf0826000, |
90 | +}; | ||
91 | + | ||
92 | static const struct { | ||
93 | hwaddr regs_addr; | ||
94 | uint32_t unconnected_pins; | ||
95 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
96 | for (i = 0; i < ARRAY_SIZE(s->pwm); i++) { | ||
97 | object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM); | ||
98 | } | ||
99 | + | ||
100 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { | ||
101 | + object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC); | ||
102 | + } | ||
68 | } | 103 | } |
69 | 104 | ||
70 | static uint64_t cmsdk_apb_timer_read(void *opaque, hwaddr offset, unsigned size) | 105 | static void npcm7xx_realize(DeviceState *dev, Error **errp) |
71 | { | 106 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
72 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); | 107 | sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i)); |
73 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(opaque); | ||
74 | uint64_t r; | ||
75 | |||
76 | switch (offset) { | ||
77 | @@ -XXX,XX +XXX,XX @@ static uint64_t cmsdk_apb_timer_read(void *opaque, hwaddr offset, unsigned size) | ||
78 | static void cmsdk_apb_timer_write(void *opaque, hwaddr offset, uint64_t value, | ||
79 | unsigned size) | ||
80 | { | ||
81 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); | ||
82 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(opaque); | ||
83 | |||
84 | trace_cmsdk_apb_timer_write(offset, value, size); | ||
85 | |||
86 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cmsdk_apb_timer_ops = { | ||
87 | |||
88 | static void cmsdk_apb_timer_tick(void *opaque) | ||
89 | { | ||
90 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(opaque); | ||
91 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(opaque); | ||
92 | |||
93 | if (s->ctrl & R_CTRL_IRQEN_MASK) { | ||
94 | s->intstatus |= R_INTSTATUS_IRQ_MASK; | ||
95 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_tick(void *opaque) | ||
96 | |||
97 | static void cmsdk_apb_timer_reset(DeviceState *dev) | ||
98 | { | ||
99 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(dev); | ||
100 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(dev); | ||
101 | |||
102 | trace_cmsdk_apb_timer_reset(); | ||
103 | s->ctrl = 0; | ||
104 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_reset(DeviceState *dev) | ||
105 | static void cmsdk_apb_timer_init(Object *obj) | ||
106 | { | ||
107 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
108 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(obj); | ||
109 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(obj); | ||
110 | |||
111 | memory_region_init_io(&s->iomem, obj, &cmsdk_apb_timer_ops, | ||
112 | s, "cmsdk-apb-timer", 0x1000); | ||
113 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_init(Object *obj) | ||
114 | |||
115 | static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp) | ||
116 | { | ||
117 | - CMSDKAPBTIMER *s = CMSDK_APB_TIMER(dev); | ||
118 | + CMSDKAPBTimer *s = CMSDK_APB_TIMER(dev); | ||
119 | |||
120 | if (s->pclk_frq == 0) { | ||
121 | error_setg(errp, "CMSDK APB timer: pclk-frq property must be set"); | ||
122 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription cmsdk_apb_timer_vmstate = { | ||
123 | .version_id = 1, | ||
124 | .minimum_version_id = 1, | ||
125 | .fields = (VMStateField[]) { | ||
126 | - VMSTATE_PTIMER(timer, CMSDKAPBTIMER), | ||
127 | - VMSTATE_UINT32(ctrl, CMSDKAPBTIMER), | ||
128 | - VMSTATE_UINT32(value, CMSDKAPBTIMER), | ||
129 | - VMSTATE_UINT32(reload, CMSDKAPBTIMER), | ||
130 | - VMSTATE_UINT32(intstatus, CMSDKAPBTIMER), | ||
131 | + VMSTATE_PTIMER(timer, CMSDKAPBTimer), | ||
132 | + VMSTATE_UINT32(ctrl, CMSDKAPBTimer), | ||
133 | + VMSTATE_UINT32(value, CMSDKAPBTimer), | ||
134 | + VMSTATE_UINT32(reload, CMSDKAPBTimer), | ||
135 | + VMSTATE_UINT32(intstatus, CMSDKAPBTimer), | ||
136 | VMSTATE_END_OF_LIST() | ||
137 | } | 108 | } |
138 | }; | 109 | |
139 | 110 | + /* | |
140 | static Property cmsdk_apb_timer_properties[] = { | 111 | + * EMC Modules. Cannot fail. |
141 | - DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBTIMER, pclk_frq, 0), | 112 | + * The mapping of the device to its netdev backend works as follows: |
142 | + DEFINE_PROP_UINT32("pclk-frq", CMSDKAPBTimer, pclk_frq, 0), | 113 | + * emc[i] = nd_table[i] |
143 | DEFINE_PROP_END_OF_LIST(), | 114 | + * This works around the inability to specify the netdev property for the |
144 | }; | 115 | + * emc device: it's not pluggable and thus the -device option can't be |
145 | 116 | + * used. | |
146 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_class_init(ObjectClass *klass, void *data) | 117 | + */ |
147 | static const TypeInfo cmsdk_apb_timer_info = { | 118 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc)); |
148 | .name = TYPE_CMSDK_APB_TIMER, | 119 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2); |
149 | .parent = TYPE_SYS_BUS_DEVICE, | 120 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { |
150 | - .instance_size = sizeof(CMSDKAPBTIMER), | 121 | + s->emc[i].emc_num = i; |
151 | + .instance_size = sizeof(CMSDKAPBTimer), | 122 | + SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]); |
152 | .instance_init = cmsdk_apb_timer_init, | 123 | + if (nd_table[i].used) { |
153 | .class_init = cmsdk_apb_timer_class_init, | 124 | + qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC); |
154 | }; | 125 | + qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]); |
126 | + } | ||
127 | + /* | ||
128 | + * The device exists regardless of whether it's connected to a QEMU | ||
129 | + * netdev backend. So always instantiate it even if there is no | ||
130 | + * backend. | ||
131 | + */ | ||
132 | + sysbus_realize(sbd, &error_abort); | ||
133 | + sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]); | ||
134 | + int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ; | ||
135 | + int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ; | ||
136 | + /* | ||
137 | + * N.B. The values for the second argument sysbus_connect_irq are | ||
138 | + * chosen to match the registration order in npcm7xx_emc_realize. | ||
139 | + */ | ||
140 | + sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq)); | ||
141 | + sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq)); | ||
142 | + } | ||
143 | + | ||
144 | /* | ||
145 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | ||
146 | * specified, but this is a programming error. | ||
147 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
148 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); | ||
150 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); | ||
151 | - create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB); | ||
152 | - create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB); | ||
153 | create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB); | ||
154 | create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB); | ||
155 | create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB); | ||
155 | -- | 156 | -- |
156 | 2.20.1 | 157 | 2.20.1 |
157 | 158 | ||
158 | 159 | diff view generated by jsdifflib |
1 | Add a simple test of the CMSDK watchdog, since we're about to do some | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | refactoring of how it is clocked. | ||
3 | 2 | ||
3 | Reviewed-by: Hao Wu <wuhaotsh@google.com> | ||
4 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Doug Evans <dje@google.com> | ||
7 | Message-id: 20210213002520.1374134-4-dje@google.com | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210128114145.20536-5-peter.maydell@linaro.org | ||
9 | Message-id: 20210121190622.22000-5-peter.maydell@linaro.org | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | --- | 9 | --- |
12 | tests/qtest/cmsdk-apb-watchdog-test.c | 79 +++++++++++++++++++++++++++ | 10 | tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++ |
13 | MAINTAINERS | 1 + | 11 | tests/qtest/meson.build | 1 + |
14 | tests/qtest/meson.build | 1 + | 12 | 2 files changed, 863 insertions(+) |
15 | 3 files changed, 81 insertions(+) | 13 | create mode 100644 tests/qtest/npcm7xx_emc-test.c |
16 | create mode 100644 tests/qtest/cmsdk-apb-watchdog-test.c | ||
17 | 14 | ||
18 | diff --git a/tests/qtest/cmsdk-apb-watchdog-test.c b/tests/qtest/cmsdk-apb-watchdog-test.c | 15 | diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c |
19 | new file mode 100644 | 16 | new file mode 100644 |
20 | index XXXXXXX..XXXXXXX | 17 | index XXXXXXX..XXXXXXX |
21 | --- /dev/null | 18 | --- /dev/null |
22 | +++ b/tests/qtest/cmsdk-apb-watchdog-test.c | 19 | +++ b/tests/qtest/npcm7xx_emc-test.c |
23 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ |
24 | +/* | 21 | +/* |
25 | + * QTest testcase for the CMSDK APB watchdog device | 22 | + * QTests for Nuvoton NPCM7xx EMC Modules. |
26 | + * | 23 | + * |
27 | + * Copyright (c) 2021 Linaro Limited | 24 | + * Copyright 2020 Google LLC |
28 | + * | 25 | + * |
29 | + * This program is free software; you can redistribute it and/or modify it | 26 | + * This program is free software; you can redistribute it and/or modify it |
30 | + * under the terms of the GNU General Public License as published by the | 27 | + * under the terms of the GNU General Public License as published by the |
31 | + * Free Software Foundation; either version 2 of the License, or | 28 | + * Free Software Foundation; either version 2 of the License, or |
32 | + * (at your option) any later version. | 29 | + * (at your option) any later version. |
... | ... | ||
36 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 33 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
37 | + * for more details. | 34 | + * for more details. |
38 | + */ | 35 | + */ |
39 | + | 36 | + |
40 | +#include "qemu/osdep.h" | 37 | +#include "qemu/osdep.h" |
41 | +#include "libqtest-single.h" | 38 | +#include "qemu-common.h" |
39 | +#include "libqos/libqos.h" | ||
40 | +#include "qapi/qmp/qdict.h" | ||
41 | +#include "qapi/qmp/qnum.h" | ||
42 | +#include "qemu/bitops.h" | ||
43 | +#include "qemu/iov.h" | ||
44 | + | ||
45 | +/* Name of the emc device. */ | ||
46 | +#define TYPE_NPCM7XX_EMC "npcm7xx-emc" | ||
47 | + | ||
48 | +/* Timeout for various operations, in seconds. */ | ||
49 | +#define TIMEOUT_SECONDS 10 | ||
50 | + | ||
51 | +/* Address in memory of the descriptor. */ | ||
52 | +#define DESC_ADDR (1 << 20) /* 1 MiB */ | ||
53 | + | ||
54 | +/* Address in memory of the data packet. */ | ||
55 | +#define DATA_ADDR (DESC_ADDR + 4096) | ||
56 | + | ||
57 | +#define CRC_LENGTH 4 | ||
58 | + | ||
59 | +#define NUM_TX_DESCRIPTORS 3 | ||
60 | +#define NUM_RX_DESCRIPTORS 2 | ||
61 | + | ||
62 | +/* Size of tx,rx test buffers. */ | ||
63 | +#define TX_DATA_LEN 64 | ||
64 | +#define RX_DATA_LEN 64 | ||
65 | + | ||
66 | +#define TX_STEP_COUNT 10000 | ||
67 | +#define RX_STEP_COUNT 10000 | ||
68 | + | ||
69 | +/* 32-bit register indices. */ | ||
70 | +typedef enum NPCM7xxPWMRegister { | ||
71 | + /* Control registers. */ | ||
72 | + REG_CAMCMR, | ||
73 | + REG_CAMEN, | ||
74 | + | ||
75 | + /* There are 16 CAMn[ML] registers. */ | ||
76 | + REG_CAMM_BASE, | ||
77 | + REG_CAML_BASE, | ||
78 | + | ||
79 | + REG_TXDLSA = 0x22, | ||
80 | + REG_RXDLSA, | ||
81 | + REG_MCMDR, | ||
82 | + REG_MIID, | ||
83 | + REG_MIIDA, | ||
84 | + REG_FFTCR, | ||
85 | + REG_TSDR, | ||
86 | + REG_RSDR, | ||
87 | + REG_DMARFC, | ||
88 | + REG_MIEN, | ||
89 | + | ||
90 | + /* Status registers. */ | ||
91 | + REG_MISTA, | ||
92 | + REG_MGSTA, | ||
93 | + REG_MPCNT, | ||
94 | + REG_MRPC, | ||
95 | + REG_MRPCC, | ||
96 | + REG_MREPC, | ||
97 | + REG_DMARFS, | ||
98 | + REG_CTXDSA, | ||
99 | + REG_CTXBSA, | ||
100 | + REG_CRXDSA, | ||
101 | + REG_CRXBSA, | ||
102 | + | ||
103 | + NPCM7XX_NUM_EMC_REGS, | ||
104 | +} NPCM7xxPWMRegister; | ||
105 | + | ||
106 | +enum { NUM_CAMML_REGS = 16 }; | ||
107 | + | ||
108 | +/* REG_CAMCMR fields */ | ||
109 | +/* Enable CAM Compare */ | ||
110 | +#define REG_CAMCMR_ECMP (1 << 4) | ||
111 | +/* Accept Unicast Packet */ | ||
112 | +#define REG_CAMCMR_AUP (1 << 0) | ||
113 | + | ||
114 | +/* REG_MCMDR fields */ | ||
115 | +/* Software Reset */ | ||
116 | +#define REG_MCMDR_SWR (1 << 24) | ||
117 | +/* Frame Transmission On */ | ||
118 | +#define REG_MCMDR_TXON (1 << 8) | ||
119 | +/* Accept Long Packet */ | ||
120 | +#define REG_MCMDR_ALP (1 << 1) | ||
121 | +/* Frame Reception On */ | ||
122 | +#define REG_MCMDR_RXON (1 << 0) | ||
123 | + | ||
124 | +/* REG_MIEN fields */ | ||
125 | +/* Enable Transmit Completion Interrupt */ | ||
126 | +#define REG_MIEN_ENTXCP (1 << 18) | ||
127 | +/* Enable Transmit Interrupt */ | ||
128 | +#define REG_MIEN_ENTXINTR (1 << 16) | ||
129 | +/* Enable Receive Good Interrupt */ | ||
130 | +#define REG_MIEN_ENRXGD (1 << 4) | ||
131 | +/* ENable Receive Interrupt */ | ||
132 | +#define REG_MIEN_ENRXINTR (1 << 0) | ||
133 | + | ||
134 | +/* REG_MISTA fields */ | ||
135 | +/* Transmit Bus Error Interrupt */ | ||
136 | +#define REG_MISTA_TXBERR (1 << 24) | ||
137 | +/* Transmit Descriptor Unavailable Interrupt */ | ||
138 | +#define REG_MISTA_TDU (1 << 23) | ||
139 | +/* Transmit Completion Interrupt */ | ||
140 | +#define REG_MISTA_TXCP (1 << 18) | ||
141 | +/* Transmit Interrupt */ | ||
142 | +#define REG_MISTA_TXINTR (1 << 16) | ||
143 | +/* Receive Bus Error Interrupt */ | ||
144 | +#define REG_MISTA_RXBERR (1 << 11) | ||
145 | +/* Receive Descriptor Unavailable Interrupt */ | ||
146 | +#define REG_MISTA_RDU (1 << 10) | ||
147 | +/* DMA Early Notification Interrupt */ | ||
148 | +#define REG_MISTA_DENI (1 << 9) | ||
149 | +/* Maximum Frame Length Interrupt */ | ||
150 | +#define REG_MISTA_DFOI (1 << 8) | ||
151 | +/* Receive Good Interrupt */ | ||
152 | +#define REG_MISTA_RXGD (1 << 4) | ||
153 | +/* Packet Too Long Interrupt */ | ||
154 | +#define REG_MISTA_PTLE (1 << 3) | ||
155 | +/* Receive Interrupt */ | ||
156 | +#define REG_MISTA_RXINTR (1 << 0) | ||
157 | + | ||
158 | +typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc; | ||
159 | +typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc; | ||
160 | + | ||
161 | +struct NPCM7xxEMCTxDesc { | ||
162 | + uint32_t flags; | ||
163 | + uint32_t txbsa; | ||
164 | + uint32_t status_and_length; | ||
165 | + uint32_t ntxdsa; | ||
166 | +}; | ||
167 | + | ||
168 | +struct NPCM7xxEMCRxDesc { | ||
169 | + uint32_t status_and_length; | ||
170 | + uint32_t rxbsa; | ||
171 | + uint32_t reserved; | ||
172 | + uint32_t nrxdsa; | ||
173 | +}; | ||
174 | + | ||
175 | +/* NPCM7xxEMCTxDesc.flags values */ | ||
176 | +/* Owner: 0 = cpu, 1 = emc */ | ||
177 | +#define TX_DESC_FLAG_OWNER_MASK (1 << 31) | ||
178 | +/* Transmit interrupt enable */ | ||
179 | +#define TX_DESC_FLAG_INTEN (1 << 2) | ||
180 | + | ||
181 | +/* NPCM7xxEMCTxDesc.status_and_length values */ | ||
182 | +/* Transmission complete */ | ||
183 | +#define TX_DESC_STATUS_TXCP (1 << 19) | ||
184 | +/* Transmit interrupt */ | ||
185 | +#define TX_DESC_STATUS_TXINTR (1 << 16) | ||
186 | + | ||
187 | +/* NPCM7xxEMCRxDesc.status_and_length values */ | ||
188 | +/* Owner: 0b00 = cpu, 0b10 = emc */ | ||
189 | +#define RX_DESC_STATUS_OWNER_SHIFT 30 | ||
190 | +#define RX_DESC_STATUS_OWNER_MASK 0xc0000000 | ||
191 | +/* Frame Reception Complete */ | ||
192 | +#define RX_DESC_STATUS_RXGD (1 << 20) | ||
193 | +/* Packet too long */ | ||
194 | +#define RX_DESC_STATUS_PTLE (1 << 19) | ||
195 | +/* Receive Interrupt */ | ||
196 | +#define RX_DESC_STATUS_RXINTR (1 << 16) | ||
197 | + | ||
198 | +#define RX_DESC_PKT_LEN(word) ((uint32_t) (word) & 0xffff) | ||
199 | + | ||
200 | +typedef struct EMCModule { | ||
201 | + int rx_irq; | ||
202 | + int tx_irq; | ||
203 | + uint64_t base_addr; | ||
204 | +} EMCModule; | ||
205 | + | ||
206 | +typedef struct TestData { | ||
207 | + const EMCModule *module; | ||
208 | +} TestData; | ||
209 | + | ||
210 | +static const EMCModule emc_module_list[] = { | ||
211 | + { | ||
212 | + .rx_irq = 15, | ||
213 | + .tx_irq = 16, | ||
214 | + .base_addr = 0xf0825000 | ||
215 | + }, | ||
216 | + { | ||
217 | + .rx_irq = 114, | ||
218 | + .tx_irq = 115, | ||
219 | + .base_addr = 0xf0826000 | ||
220 | + } | ||
221 | +}; | ||
222 | + | ||
223 | +/* Returns the index of the EMC module. */ | ||
224 | +static int emc_module_index(const EMCModule *mod) | ||
225 | +{ | ||
226 | + ptrdiff_t diff = mod - emc_module_list; | ||
227 | + | ||
228 | + g_assert_true(diff >= 0 && diff < ARRAY_SIZE(emc_module_list)); | ||
229 | + | ||
230 | + return diff; | ||
231 | +} | ||
232 | + | ||
233 | +static void packet_test_clear(void *sockets) | ||
234 | +{ | ||
235 | + int *test_sockets = sockets; | ||
236 | + | ||
237 | + close(test_sockets[0]); | ||
238 | + g_free(test_sockets); | ||
239 | +} | ||
240 | + | ||
241 | +static int *packet_test_init(int module_num, GString *cmd_line) | ||
242 | +{ | ||
243 | + int *test_sockets = g_new(int, 2); | ||
244 | + int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets); | ||
245 | + g_assert_cmpint(ret, != , -1); | ||
246 | + | ||
247 | + /* | ||
248 | + * KISS and use -nic. We specify two nics (both emc{0,1}) because there's | ||
249 | + * currently no way to specify only emc1: The driver implicitly relies on | ||
250 | + * emc[i] == nd_table[i]. | ||
251 | + */ | ||
252 | + if (module_num == 0) { | ||
253 | + g_string_append_printf(cmd_line, | ||
254 | + " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " " | ||
255 | + " -nic user,model=" TYPE_NPCM7XX_EMC " ", | ||
256 | + test_sockets[1]); | ||
257 | + } else { | ||
258 | + g_string_append_printf(cmd_line, | ||
259 | + " -nic user,model=" TYPE_NPCM7XX_EMC " " | ||
260 | + " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " ", | ||
261 | + test_sockets[1]); | ||
262 | + } | ||
263 | + | ||
264 | + g_test_queue_destroy(packet_test_clear, test_sockets); | ||
265 | + return test_sockets; | ||
266 | +} | ||
267 | + | ||
268 | +static uint32_t emc_read(QTestState *qts, const EMCModule *mod, | ||
269 | + NPCM7xxPWMRegister regno) | ||
270 | +{ | ||
271 | + return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t)); | ||
272 | +} | ||
273 | + | ||
274 | +static void emc_write(QTestState *qts, const EMCModule *mod, | ||
275 | + NPCM7xxPWMRegister regno, uint32_t value) | ||
276 | +{ | ||
277 | + qtest_writel(qts, mod->base_addr + regno * sizeof(uint32_t), value); | ||
278 | +} | ||
279 | + | ||
280 | +static void emc_read_tx_desc(QTestState *qts, uint32_t addr, | ||
281 | + NPCM7xxEMCTxDesc *desc) | ||
282 | +{ | ||
283 | + qtest_memread(qts, addr, desc, sizeof(*desc)); | ||
284 | + desc->flags = le32_to_cpu(desc->flags); | ||
285 | + desc->txbsa = le32_to_cpu(desc->txbsa); | ||
286 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
287 | + desc->ntxdsa = le32_to_cpu(desc->ntxdsa); | ||
288 | +} | ||
289 | + | ||
290 | +static void emc_write_tx_desc(QTestState *qts, const NPCM7xxEMCTxDesc *desc, | ||
291 | + uint32_t addr) | ||
292 | +{ | ||
293 | + NPCM7xxEMCTxDesc le_desc; | ||
294 | + | ||
295 | + le_desc.flags = cpu_to_le32(desc->flags); | ||
296 | + le_desc.txbsa = cpu_to_le32(desc->txbsa); | ||
297 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
298 | + le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa); | ||
299 | + qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc)); | ||
300 | +} | ||
301 | + | ||
302 | +static void emc_read_rx_desc(QTestState *qts, uint32_t addr, | ||
303 | + NPCM7xxEMCRxDesc *desc) | ||
304 | +{ | ||
305 | + qtest_memread(qts, addr, desc, sizeof(*desc)); | ||
306 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
307 | + desc->rxbsa = le32_to_cpu(desc->rxbsa); | ||
308 | + desc->reserved = le32_to_cpu(desc->reserved); | ||
309 | + desc->nrxdsa = le32_to_cpu(desc->nrxdsa); | ||
310 | +} | ||
311 | + | ||
312 | +static void emc_write_rx_desc(QTestState *qts, const NPCM7xxEMCRxDesc *desc, | ||
313 | + uint32_t addr) | ||
314 | +{ | ||
315 | + NPCM7xxEMCRxDesc le_desc; | ||
316 | + | ||
317 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
318 | + le_desc.rxbsa = cpu_to_le32(desc->rxbsa); | ||
319 | + le_desc.reserved = cpu_to_le32(desc->reserved); | ||
320 | + le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa); | ||
321 | + qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc)); | ||
322 | +} | ||
42 | + | 323 | + |
43 | +/* | 324 | +/* |
44 | + * lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, | 325 | + * Reset the EMC module. |
45 | + * which is 80ns per tick. | 326 | + * The module must be reset before, e.g., TXDLSA,RXDLSA are changed. |
46 | + */ | 327 | + */ |
47 | +#define WDOG_BASE 0x40000000 | 328 | +static bool emc_soft_reset(QTestState *qts, const EMCModule *mod) |
48 | + | 329 | +{ |
49 | +#define WDOGLOAD 0 | 330 | + uint32_t val; |
50 | +#define WDOGVALUE 4 | 331 | + uint64_t end_time; |
51 | +#define WDOGCONTROL 8 | 332 | + |
52 | +#define WDOGINTCLR 0xc | 333 | + emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR); |
53 | +#define WDOGRIS 0x10 | 334 | + |
54 | +#define WDOGMIS 0x14 | 335 | + /* |
55 | +#define WDOGLOCK 0xc00 | 336 | + * Wait for device to reset as the linux driver does. |
56 | + | 337 | + * During reset the AHB reads 0 for all registers. So first wait for |
57 | +static void test_watchdog(void) | 338 | + * something that resets to non-zero, and then wait for SWR becoming 0. |
58 | +{ | 339 | + */ |
59 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | 340 | + end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; |
60 | + | 341 | + |
61 | + writel(WDOG_BASE + WDOGCONTROL, 1); | 342 | + do { |
62 | + writel(WDOG_BASE + WDOGLOAD, 1000); | 343 | + qtest_clock_step(qts, 100); |
63 | + | 344 | + val = emc_read(qts, mod, REG_FFTCR); |
64 | + /* Step to just past the 500th tick */ | 345 | + } while (val == 0 && g_get_monotonic_time() < end_time); |
65 | + clock_step(500 * 80 + 1); | 346 | + if (val != 0) { |
66 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | 347 | + do { |
67 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); | 348 | + qtest_clock_step(qts, 100); |
68 | + | 349 | + val = emc_read(qts, mod, REG_MCMDR); |
69 | + /* Just past the 1000th tick: timer should have fired */ | 350 | + if ((val & REG_MCMDR_SWR) == 0) { |
70 | + clock_step(500 * 80); | 351 | + /* |
71 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); | 352 | + * N.B. The CAMs have been reset here, so macaddr matching of |
72 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); | 353 | + * incoming packets will not work. |
73 | + | 354 | + */ |
74 | + /* VALUE reloads at following tick */ | 355 | + return true; |
75 | + clock_step(80); | 356 | + } |
76 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); | 357 | + } while (g_get_monotonic_time() < end_time); |
77 | + | 358 | + } |
78 | + /* Writing any value to WDOGINTCLR clears the interrupt and reloads */ | 359 | + |
79 | + clock_step(500 * 80); | 360 | + g_message("%s: Timeout expired", __func__); |
80 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); | 361 | + return false; |
81 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); | 362 | +} |
82 | + writel(WDOG_BASE + WDOGINTCLR, 0); | 363 | + |
83 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); | 364 | +/* Check emc registers are reset to default value. */ |
84 | + g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); | 365 | +static void test_init(gconstpointer test_data) |
85 | +} | 366 | +{ |
367 | + const TestData *td = test_data; | ||
368 | + const EMCModule *mod = td->module; | ||
369 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
370 | + int i; | ||
371 | + | ||
372 | +#define CHECK_REG(regno, value) \ | ||
373 | + do { \ | ||
374 | + g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \ | ||
375 | + } while (0) | ||
376 | + | ||
377 | + CHECK_REG(REG_CAMCMR, 0); | ||
378 | + CHECK_REG(REG_CAMEN, 0); | ||
379 | + CHECK_REG(REG_TXDLSA, 0xfffffffc); | ||
380 | + CHECK_REG(REG_RXDLSA, 0xfffffffc); | ||
381 | + CHECK_REG(REG_MCMDR, 0); | ||
382 | + CHECK_REG(REG_MIID, 0); | ||
383 | + CHECK_REG(REG_MIIDA, 0x00900000); | ||
384 | + CHECK_REG(REG_FFTCR, 0x0101); | ||
385 | + CHECK_REG(REG_DMARFC, 0x0800); | ||
386 | + CHECK_REG(REG_MIEN, 0); | ||
387 | + CHECK_REG(REG_MISTA, 0); | ||
388 | + CHECK_REG(REG_MGSTA, 0); | ||
389 | + CHECK_REG(REG_MPCNT, 0x7fff); | ||
390 | + CHECK_REG(REG_MRPC, 0); | ||
391 | + CHECK_REG(REG_MRPCC, 0); | ||
392 | + CHECK_REG(REG_MREPC, 0); | ||
393 | + CHECK_REG(REG_DMARFS, 0); | ||
394 | + CHECK_REG(REG_CTXDSA, 0); | ||
395 | + CHECK_REG(REG_CTXBSA, 0); | ||
396 | + CHECK_REG(REG_CRXDSA, 0); | ||
397 | + CHECK_REG(REG_CRXBSA, 0); | ||
398 | + | ||
399 | +#undef CHECK_REG | ||
400 | + | ||
401 | + for (i = 0; i < NUM_CAMML_REGS; ++i) { | ||
402 | + g_assert_cmpuint(emc_read(qts, mod, REG_CAMM_BASE + i * 2), ==, | ||
403 | + 0); | ||
404 | + g_assert_cmpuint(emc_read(qts, mod, REG_CAML_BASE + i * 2), ==, | ||
405 | + 0); | ||
406 | + } | ||
407 | + | ||
408 | + qtest_quit(qts); | ||
409 | +} | ||
410 | + | ||
411 | +static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step, | ||
412 | + bool is_tx) | ||
413 | +{ | ||
414 | + uint64_t end_time = | ||
415 | + g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; | ||
416 | + | ||
417 | + do { | ||
418 | + if (qtest_get_irq(qts, is_tx ? mod->tx_irq : mod->rx_irq)) { | ||
419 | + return true; | ||
420 | + } | ||
421 | + qtest_clock_step(qts, step); | ||
422 | + } while (g_get_monotonic_time() < end_time); | ||
423 | + | ||
424 | + g_message("%s: Timeout expired", __func__); | ||
425 | + return false; | ||
426 | +} | ||
427 | + | ||
428 | +static bool emc_wait_mista(QTestState *qts, const EMCModule *mod, int step, | ||
429 | + uint32_t flag) | ||
430 | +{ | ||
431 | + uint64_t end_time = | ||
432 | + g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; | ||
433 | + | ||
434 | + do { | ||
435 | + uint32_t mista = emc_read(qts, mod, REG_MISTA); | ||
436 | + if (mista & flag) { | ||
437 | + return true; | ||
438 | + } | ||
439 | + qtest_clock_step(qts, step); | ||
440 | + } while (g_get_monotonic_time() < end_time); | ||
441 | + | ||
442 | + g_message("%s: Timeout expired", __func__); | ||
443 | + return false; | ||
444 | +} | ||
445 | + | ||
446 | +static bool wait_socket_readable(int fd) | ||
447 | +{ | ||
448 | + fd_set read_fds; | ||
449 | + struct timeval tv; | ||
450 | + int rv; | ||
451 | + | ||
452 | + FD_ZERO(&read_fds); | ||
453 | + FD_SET(fd, &read_fds); | ||
454 | + tv.tv_sec = TIMEOUT_SECONDS; | ||
455 | + tv.tv_usec = 0; | ||
456 | + rv = select(fd + 1, &read_fds, NULL, NULL, &tv); | ||
457 | + if (rv == -1) { | ||
458 | + perror("select"); | ||
459 | + } else if (rv == 0) { | ||
460 | + g_message("%s: Timeout expired", __func__); | ||
461 | + } | ||
462 | + return rv == 1; | ||
463 | +} | ||
464 | + | ||
465 | +/* Initialize *desc (in host endian format). */ | ||
466 | +static void init_tx_desc(NPCM7xxEMCTxDesc *desc, size_t count, | ||
467 | + uint32_t desc_addr) | ||
468 | +{ | ||
469 | + g_assert(count >= 2); | ||
470 | + memset(&desc[0], 0, sizeof(*desc) * count); | ||
471 | + /* Leave the last one alone, owned by the cpu -> stops transmission. */ | ||
472 | + for (size_t i = 0; i < count - 1; ++i) { | ||
473 | + desc[i].flags = | ||
474 | + (TX_DESC_FLAG_OWNER_MASK | /* owner = 1: emc */ | ||
475 | + TX_DESC_FLAG_INTEN | | ||
476 | + 0 | /* crc append = 0 */ | ||
477 | + 0 /* padding enable = 0 */); | ||
478 | + desc[i].status_and_length = | ||
479 | + (0 | /* collision count = 0 */ | ||
480 | + 0 | /* SQE = 0 */ | ||
481 | + 0 | /* PAU = 0 */ | ||
482 | + 0 | /* TXHA = 0 */ | ||
483 | + 0 | /* LC = 0 */ | ||
484 | + 0 | /* TXABT = 0 */ | ||
485 | + 0 | /* NCS = 0 */ | ||
486 | + 0 | /* EXDEF = 0 */ | ||
487 | + 0 | /* TXCP = 0 */ | ||
488 | + 0 | /* DEF = 0 */ | ||
489 | + 0 | /* TXINTR = 0 */ | ||
490 | + 0 /* length filled in later */); | ||
491 | + desc[i].ntxdsa = desc_addr + (i + 1) * sizeof(*desc); | ||
492 | + } | ||
493 | +} | ||
494 | + | ||
495 | +static void enable_tx(QTestState *qts, const EMCModule *mod, | ||
496 | + const NPCM7xxEMCTxDesc *desc, size_t count, | ||
497 | + uint32_t desc_addr, uint32_t mien_flags) | ||
498 | +{ | ||
499 | + /* Write the descriptors to guest memory. */ | ||
500 | + for (size_t i = 0; i < count; ++i) { | ||
501 | + emc_write_tx_desc(qts, desc + i, desc_addr + i * sizeof(*desc)); | ||
502 | + } | ||
503 | + | ||
504 | + /* Trigger sending the packet. */ | ||
505 | + /* The module must be reset before changing TXDLSA. */ | ||
506 | + g_assert(emc_soft_reset(qts, mod)); | ||
507 | + emc_write(qts, mod, REG_TXDLSA, desc_addr); | ||
508 | + emc_write(qts, mod, REG_CTXDSA, ~0); | ||
509 | + emc_write(qts, mod, REG_MIEN, REG_MIEN_ENTXCP | mien_flags); | ||
510 | + { | ||
511 | + uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR); | ||
512 | + mcmdr |= REG_MCMDR_TXON; | ||
513 | + emc_write(qts, mod, REG_MCMDR, mcmdr); | ||
514 | + } | ||
515 | + | ||
516 | + /* Prod the device to send the packet. */ | ||
517 | + emc_write(qts, mod, REG_TSDR, 1); | ||
518 | +} | ||
519 | + | ||
520 | +static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd, | ||
521 | + bool with_irq, uint32_t desc_addr, | ||
522 | + uint32_t next_desc_addr, | ||
523 | + const char *test_data, int test_size) | ||
524 | +{ | ||
525 | + NPCM7xxEMCTxDesc result_desc; | ||
526 | + uint32_t expected_mask, expected_value, recv_len; | ||
527 | + int ret; | ||
528 | + char buffer[TX_DATA_LEN]; | ||
529 | + | ||
530 | + g_assert(wait_socket_readable(fd)); | ||
531 | + | ||
532 | + /* Read the descriptor back. */ | ||
533 | + emc_read_tx_desc(qts, desc_addr, &result_desc); | ||
534 | + /* Descriptor should be owned by cpu now. */ | ||
535 | + g_assert((result_desc.flags & TX_DESC_FLAG_OWNER_MASK) == 0); | ||
536 | + /* Test the status bits, ignoring the length field. */ | ||
537 | + expected_mask = 0xffff << 16; | ||
538 | + expected_value = TX_DESC_STATUS_TXCP; | ||
539 | + if (with_irq) { | ||
540 | + expected_value |= TX_DESC_STATUS_TXINTR; | ||
541 | + } | ||
542 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, | ||
543 | + expected_value); | ||
544 | + | ||
545 | + /* Check data sent to the backend. */ | ||
546 | + recv_len = ~0; | ||
547 | + ret = qemu_recv(fd, &recv_len, sizeof(recv_len), MSG_DONTWAIT); | ||
548 | + g_assert_cmpint(ret, == , sizeof(recv_len)); | ||
549 | + | ||
550 | + g_assert(wait_socket_readable(fd)); | ||
551 | + memset(buffer, 0xff, sizeof(buffer)); | ||
552 | + ret = qemu_recv(fd, buffer, test_size, MSG_DONTWAIT); | ||
553 | + g_assert_cmpmem(buffer, ret, test_data, test_size); | ||
554 | +} | ||
555 | + | ||
556 | +static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd, | ||
557 | + bool with_irq) | ||
558 | +{ | ||
559 | + NPCM7xxEMCTxDesc desc[NUM_TX_DESCRIPTORS]; | ||
560 | + uint32_t desc_addr = DESC_ADDR; | ||
561 | + static const char test1_data[] = "TEST1"; | ||
562 | + static const char test2_data[] = "Testing 1 2 3 ..."; | ||
563 | + uint32_t data1_addr = DATA_ADDR; | ||
564 | + uint32_t data2_addr = data1_addr + sizeof(test1_data); | ||
565 | + bool got_tdu; | ||
566 | + uint32_t end_desc_addr; | ||
567 | + | ||
568 | + /* Prepare test data buffer. */ | ||
569 | + qtest_memwrite(qts, data1_addr, test1_data, sizeof(test1_data)); | ||
570 | + qtest_memwrite(qts, data2_addr, test2_data, sizeof(test2_data)); | ||
571 | + | ||
572 | + init_tx_desc(&desc[0], NUM_TX_DESCRIPTORS, desc_addr); | ||
573 | + desc[0].txbsa = data1_addr; | ||
574 | + desc[0].status_and_length |= sizeof(test1_data); | ||
575 | + desc[1].txbsa = data2_addr; | ||
576 | + desc[1].status_and_length |= sizeof(test2_data); | ||
577 | + | ||
578 | + enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr, | ||
579 | + with_irq ? REG_MIEN_ENTXINTR : 0); | ||
580 | + | ||
581 | + /* | ||
582 | + * It's problematic to observe the interrupt for each packet. | ||
583 | + * Instead just wait until all the packets go out. | ||
584 | + */ | ||
585 | + got_tdu = false; | ||
586 | + while (!got_tdu) { | ||
587 | + if (with_irq) { | ||
588 | + g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT, | ||
589 | + /*is_tx=*/true)); | ||
590 | + } else { | ||
591 | + g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT, | ||
592 | + REG_MISTA_TXINTR)); | ||
593 | + } | ||
594 | + got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU); | ||
595 | + /* If we don't have TDU yet, reset the interrupt. */ | ||
596 | + if (!got_tdu) { | ||
597 | + emc_write(qts, mod, REG_MISTA, | ||
598 | + emc_read(qts, mod, REG_MISTA) & 0xffff0000); | ||
599 | + } | ||
600 | + } | ||
601 | + | ||
602 | + end_desc_addr = desc_addr + 2 * sizeof(desc[0]); | ||
603 | + g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr); | ||
604 | + g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==, | ||
605 | + REG_MISTA_TXCP | REG_MISTA_TXINTR | REG_MISTA_TDU); | ||
606 | + | ||
607 | + emc_send_verify1(qts, mod, fd, with_irq, | ||
608 | + desc_addr, end_desc_addr, | ||
609 | + test1_data, sizeof(test1_data)); | ||
610 | + emc_send_verify1(qts, mod, fd, with_irq, | ||
611 | + desc_addr + sizeof(desc[0]), end_desc_addr, | ||
612 | + test2_data, sizeof(test2_data)); | ||
613 | +} | ||
614 | + | ||
615 | +/* Initialize *desc (in host endian format). */ | ||
616 | +static void init_rx_desc(NPCM7xxEMCRxDesc *desc, size_t count, | ||
617 | + uint32_t desc_addr, uint32_t data_addr) | ||
618 | +{ | ||
619 | + g_assert_true(count >= 2); | ||
620 | + memset(desc, 0, sizeof(*desc) * count); | ||
621 | + desc[0].rxbsa = data_addr; | ||
622 | + desc[0].status_and_length = | ||
623 | + (0b10 << RX_DESC_STATUS_OWNER_SHIFT | /* owner = 10: emc */ | ||
624 | + 0 | /* RP = 0 */ | ||
625 | + 0 | /* ALIE = 0 */ | ||
626 | + 0 | /* RXGD = 0 */ | ||
627 | + 0 | /* PTLE = 0 */ | ||
628 | + 0 | /* CRCE = 0 */ | ||
629 | + 0 | /* RXINTR = 0 */ | ||
630 | + 0 /* length (filled in later) */); | ||
631 | + /* Leave the last one alone, owned by the cpu -> stops transmission. */ | ||
632 | + desc[0].nrxdsa = desc_addr + sizeof(*desc); | ||
633 | +} | ||
634 | + | ||
635 | +static void enable_rx(QTestState *qts, const EMCModule *mod, | ||
636 | + const NPCM7xxEMCRxDesc *desc, size_t count, | ||
637 | + uint32_t desc_addr, uint32_t mien_flags, | ||
638 | + uint32_t mcmdr_flags) | ||
639 | +{ | ||
640 | + /* | ||
641 | + * Write the descriptor to guest memory. | ||
642 | + * FWIW, IWBN if the docs said the buffer needs to be at least DMARFC | ||
643 | + * bytes. | ||
644 | + */ | ||
645 | + for (size_t i = 0; i < count; ++i) { | ||
646 | + emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc)); | ||
647 | + } | ||
648 | + | ||
649 | + /* Trigger receiving the packet. */ | ||
650 | + /* The module must be reset before changing RXDLSA. */ | ||
651 | + g_assert(emc_soft_reset(qts, mod)); | ||
652 | + emc_write(qts, mod, REG_RXDLSA, desc_addr); | ||
653 | + emc_write(qts, mod, REG_MIEN, REG_MIEN_ENRXGD | mien_flags); | ||
654 | + | ||
655 | + /* | ||
656 | + * We don't know what the device's macaddr is, so just accept all | ||
657 | + * unicast packets (AUP). | ||
658 | + */ | ||
659 | + emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP); | ||
660 | + emc_write(qts, mod, REG_CAMEN, 1 << 0); | ||
661 | + { | ||
662 | + uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR); | ||
663 | + mcmdr |= REG_MCMDR_RXON | mcmdr_flags; | ||
664 | + emc_write(qts, mod, REG_MCMDR, mcmdr); | ||
665 | + } | ||
666 | + | ||
667 | + /* Prod the device to accept a packet. */ | ||
668 | + emc_write(qts, mod, REG_RSDR, 1); | ||
669 | +} | ||
670 | + | ||
671 | +static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd, | ||
672 | + bool with_irq) | ||
673 | +{ | ||
674 | + NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS]; | ||
675 | + uint32_t desc_addr = DESC_ADDR; | ||
676 | + uint32_t data_addr = DATA_ADDR; | ||
677 | + int ret; | ||
678 | + uint32_t expected_mask, expected_value; | ||
679 | + NPCM7xxEMCRxDesc result_desc; | ||
680 | + | ||
681 | + /* Prepare test data buffer. */ | ||
682 | + const char test[RX_DATA_LEN] = "TEST"; | ||
683 | + int len = htonl(sizeof(test)); | ||
684 | + const struct iovec iov[] = { | ||
685 | + { | ||
686 | + .iov_base = &len, | ||
687 | + .iov_len = sizeof(len), | ||
688 | + },{ | ||
689 | + .iov_base = (char *) test, | ||
690 | + .iov_len = sizeof(test), | ||
691 | + }, | ||
692 | + }; | ||
693 | + | ||
694 | + /* | ||
695 | + * Reset the device BEFORE sending a test packet, otherwise the packet | ||
696 | + * may get swallowed by an active device of an earlier test. | ||
697 | + */ | ||
698 | + init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr); | ||
699 | + enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr, | ||
700 | + with_irq ? REG_MIEN_ENRXINTR : 0, 0); | ||
701 | + | ||
702 | + /* Send test packet to device's socket. */ | ||
703 | + ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test)); | ||
704 | + g_assert_cmpint(ret, == , sizeof(test) + sizeof(len)); | ||
705 | + | ||
706 | + /* Wait for RX interrupt. */ | ||
707 | + if (with_irq) { | ||
708 | + g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false)); | ||
709 | + } else { | ||
710 | + g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD)); | ||
711 | + } | ||
712 | + | ||
713 | + g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==, | ||
714 | + desc_addr + sizeof(desc[0])); | ||
715 | + | ||
716 | + expected_mask = 0xffff; | ||
717 | + expected_value = (REG_MISTA_DENI | | ||
718 | + REG_MISTA_RXGD | | ||
719 | + REG_MISTA_RXINTR); | ||
720 | + g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask), | ||
721 | + ==, expected_value); | ||
722 | + | ||
723 | + /* Read the descriptor back. */ | ||
724 | + emc_read_rx_desc(qts, desc_addr, &result_desc); | ||
725 | + /* Descriptor should be owned by cpu now. */ | ||
726 | + g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0); | ||
727 | + /* Test the status bits, ignoring the length field. */ | ||
728 | + expected_mask = 0xffff << 16; | ||
729 | + expected_value = RX_DESC_STATUS_RXGD; | ||
730 | + if (with_irq) { | ||
731 | + expected_value |= RX_DESC_STATUS_RXINTR; | ||
732 | + } | ||
733 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, | ||
734 | + expected_value); | ||
735 | + g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==, | ||
736 | + RX_DATA_LEN + CRC_LENGTH); | ||
737 | + | ||
738 | + { | ||
739 | + char buffer[RX_DATA_LEN]; | ||
740 | + qtest_memread(qts, data_addr, buffer, sizeof(buffer)); | ||
741 | + g_assert_cmpstr(buffer, == , "TEST"); | ||
742 | + } | ||
743 | +} | ||
744 | + | ||
745 | +static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd) | ||
746 | +{ | ||
747 | + NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS]; | ||
748 | + uint32_t desc_addr = DESC_ADDR; | ||
749 | + uint32_t data_addr = DATA_ADDR; | ||
750 | + int ret; | ||
751 | + NPCM7xxEMCRxDesc result_desc; | ||
752 | + uint32_t expected_mask, expected_value; | ||
753 | + | ||
754 | + /* Prepare test data buffer. */ | ||
755 | +#define PTLE_DATA_LEN 1600 | ||
756 | + char test_data[PTLE_DATA_LEN]; | ||
757 | + int len = htonl(sizeof(test_data)); | ||
758 | + const struct iovec iov[] = { | ||
759 | + { | ||
760 | + .iov_base = &len, | ||
761 | + .iov_len = sizeof(len), | ||
762 | + },{ | ||
763 | + .iov_base = (char *) test_data, | ||
764 | + .iov_len = sizeof(test_data), | ||
765 | + }, | ||
766 | + }; | ||
767 | + memset(test_data, 42, sizeof(test_data)); | ||
768 | + | ||
769 | + /* | ||
770 | + * Reset the device BEFORE sending a test packet, otherwise the packet | ||
771 | + * may get swallowed by an active device of an earlier test. | ||
772 | + */ | ||
773 | + init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr); | ||
774 | + enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr, | ||
775 | + REG_MIEN_ENRXINTR, REG_MCMDR_ALP); | ||
776 | + | ||
777 | + /* Send test packet to device's socket. */ | ||
778 | + ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test_data)); | ||
779 | + g_assert_cmpint(ret, == , sizeof(test_data) + sizeof(len)); | ||
780 | + | ||
781 | + /* Wait for RX interrupt. */ | ||
782 | + g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false)); | ||
783 | + | ||
784 | + /* Read the descriptor back. */ | ||
785 | + emc_read_rx_desc(qts, desc_addr, &result_desc); | ||
786 | + /* Descriptor should be owned by cpu now. */ | ||
787 | + g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0); | ||
788 | + /* Test the status bits, ignoring the length field. */ | ||
789 | + expected_mask = 0xffff << 16; | ||
790 | + expected_value = (RX_DESC_STATUS_RXGD | | ||
791 | + RX_DESC_STATUS_PTLE | | ||
792 | + RX_DESC_STATUS_RXINTR); | ||
793 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, | ||
794 | + expected_value); | ||
795 | + g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==, | ||
796 | + PTLE_DATA_LEN + CRC_LENGTH); | ||
797 | + | ||
798 | + { | ||
799 | + char buffer[PTLE_DATA_LEN]; | ||
800 | + qtest_memread(qts, data_addr, buffer, sizeof(buffer)); | ||
801 | + g_assert(memcmp(buffer, test_data, PTLE_DATA_LEN) == 0); | ||
802 | + } | ||
803 | +} | ||
804 | + | ||
805 | +static void test_tx(gconstpointer test_data) | ||
806 | +{ | ||
807 | + const TestData *td = test_data; | ||
808 | + GString *cmd_line = g_string_new("-machine quanta-gsj"); | ||
809 | + int *test_sockets = packet_test_init(emc_module_index(td->module), | ||
810 | + cmd_line); | ||
811 | + QTestState *qts = qtest_init(cmd_line->str); | ||
812 | + | ||
813 | + /* | ||
814 | + * TODO: For pedantic correctness test_sockets[0] should be closed after | ||
815 | + * the fork and before the exec, but that will require some harness | ||
816 | + * improvements. | ||
817 | + */ | ||
818 | + close(test_sockets[1]); | ||
819 | + /* Defensive programming */ | ||
820 | + test_sockets[1] = -1; | ||
821 | + | ||
822 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
823 | + | ||
824 | + emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/false); | ||
825 | + emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/true); | ||
826 | + | ||
827 | + qtest_quit(qts); | ||
828 | +} | ||
829 | + | ||
830 | +static void test_rx(gconstpointer test_data) | ||
831 | +{ | ||
832 | + const TestData *td = test_data; | ||
833 | + GString *cmd_line = g_string_new("-machine quanta-gsj"); | ||
834 | + int *test_sockets = packet_test_init(emc_module_index(td->module), | ||
835 | + cmd_line); | ||
836 | + QTestState *qts = qtest_init(cmd_line->str); | ||
837 | + | ||
838 | + /* | ||
839 | + * TODO: For pedantic correctness test_sockets[0] should be closed after | ||
840 | + * the fork and before the exec, but that will require some harness | ||
841 | + * improvements. | ||
842 | + */ | ||
843 | + close(test_sockets[1]); | ||
844 | + /* Defensive programming */ | ||
845 | + test_sockets[1] = -1; | ||
846 | + | ||
847 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
848 | + | ||
849 | + emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false); | ||
850 | + emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true); | ||
851 | + emc_test_ptle(qts, td->module, test_sockets[0]); | ||
852 | + | ||
853 | + qtest_quit(qts); | ||
854 | +} | ||
855 | + | ||
856 | +static void emc_add_test(const char *name, const TestData* td, | ||
857 | + GTestDataFunc fn) | ||
858 | +{ | ||
859 | + g_autofree char *full_name = g_strdup_printf( | ||
860 | + "npcm7xx_emc/emc[%d]/%s", emc_module_index(td->module), name); | ||
861 | + qtest_add_data_func(full_name, td, fn); | ||
862 | +} | ||
863 | +#define add_test(name, td) emc_add_test(#name, td, test_##name) | ||
86 | + | 864 | + |
87 | +int main(int argc, char **argv) | 865 | +int main(int argc, char **argv) |
88 | +{ | 866 | +{ |
89 | + int r; | 867 | + TestData test_data_list[ARRAY_SIZE(emc_module_list)]; |
90 | + | 868 | + |
91 | + g_test_init(&argc, &argv, NULL); | 869 | + g_test_init(&argc, &argv, NULL); |
92 | + | 870 | + |
93 | + qtest_start("-machine lm3s811evb"); | 871 | + for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) { |
94 | + | 872 | + TestData *td = &test_data_list[i]; |
95 | + qtest_add_func("/cmsdk-apb-watchdog/watchdog", test_watchdog); | 873 | + |
96 | + | 874 | + td->module = &emc_module_list[i]; |
97 | + r = g_test_run(); | 875 | + |
98 | + | 876 | + add_test(init, td); |
99 | + qtest_end(); | 877 | + add_test(tx, td); |
100 | + | 878 | + add_test(rx, td); |
101 | + return r; | 879 | + } |
102 | +} | 880 | + |
103 | diff --git a/MAINTAINERS b/MAINTAINERS | 881 | + return g_test_run(); |
104 | index XXXXXXX..XXXXXXX 100644 | 882 | +} |
105 | --- a/MAINTAINERS | ||
106 | +++ b/MAINTAINERS | ||
107 | @@ -XXX,XX +XXX,XX @@ F: hw/char/cmsdk-apb-uart.c | ||
108 | F: include/hw/char/cmsdk-apb-uart.h | ||
109 | F: hw/watchdog/cmsdk-apb-watchdog.c | ||
110 | F: include/hw/watchdog/cmsdk-apb-watchdog.h | ||
111 | +F: tests/qtest/cmsdk-apb-watchdog-test.c | ||
112 | F: hw/misc/tz-ppc.c | ||
113 | F: include/hw/misc/tz-ppc.h | ||
114 | F: hw/misc/tz-mpc.c | ||
115 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 883 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
116 | index XXXXXXX..XXXXXXX 100644 | 884 | index XXXXXXX..XXXXXXX 100644 |
117 | --- a/tests/qtest/meson.build | 885 | --- a/tests/qtest/meson.build |
118 | +++ b/tests/qtest/meson.build | 886 | +++ b/tests/qtest/meson.build |
119 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ | 887 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ |
120 | 'npcm7xx_watchdog_timer-test'] | 888 | |
121 | qtests_arm = \ | 889 | qtests_npcm7xx = \ |
122 | (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ | 890 | ['npcm7xx_adc-test', |
123 | + (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ | 891 | + 'npcm7xx_emc-test', |
124 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | 892 | 'npcm7xx_gpio-test', |
125 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | 893 | 'npcm7xx_pwm-test', |
126 | ['arm-cpu-features', | 894 | 'npcm7xx_rng-test', |
127 | -- | 895 | -- |
128 | 2.20.1 | 896 | 2.20.1 |
129 | 897 | ||
130 | 898 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | As the first step in converting the CMSDK_APB_TIMER device to the | ||
2 | Clock framework, add a Clock input. For the moment we do nothing | ||
3 | with this clock; we will change the behaviour from using the | ||
4 | wdogclk-frq property to using the Clock once all the users of this | ||
5 | device have been converted to wire up the Clock. | ||
6 | 1 | ||
7 | This is a migration compatibility break for machines mps2-an385, | ||
8 | mps2-an386, mps2-an500, mps2-an511, mps2-an505, mps2-an521, musca-a, | ||
9 | musca-b1, lm3s811evb, lm3s6965evb. | ||
10 | |||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Message-id: 20210128114145.20536-10-peter.maydell@linaro.org | ||
16 | Message-id: 20210121190622.22000-10-peter.maydell@linaro.org | ||
17 | --- | ||
18 | include/hw/watchdog/cmsdk-apb-watchdog.h | 3 +++ | ||
19 | hw/watchdog/cmsdk-apb-watchdog.c | 7 +++++-- | ||
20 | 2 files changed, 8 insertions(+), 2 deletions(-) | ||
21 | |||
22 | diff --git a/include/hw/watchdog/cmsdk-apb-watchdog.h b/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
25 | +++ b/include/hw/watchdog/cmsdk-apb-watchdog.h | ||
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | * | ||
28 | * QEMU interface: | ||
29 | * + QOM property "wdogclk-frq": frequency at which the watchdog is clocked | ||
30 | + * + Clock input "WDOGCLK": clock for the watchdog's timer | ||
31 | * + sysbus MMIO region 0: the register bank | ||
32 | * + sysbus IRQ 0: watchdog interrupt | ||
33 | * | ||
34 | @@ -XXX,XX +XXX,XX @@ | ||
35 | |||
36 | #include "hw/sysbus.h" | ||
37 | #include "hw/ptimer.h" | ||
38 | +#include "hw/clock.h" | ||
39 | #include "qom/object.h" | ||
40 | |||
41 | #define TYPE_CMSDK_APB_WATCHDOG "cmsdk-apb-watchdog" | ||
42 | @@ -XXX,XX +XXX,XX @@ struct CMSDKAPBWatchdog { | ||
43 | uint32_t wdogclk_frq; | ||
44 | bool is_luminary; | ||
45 | struct ptimer_state *timer; | ||
46 | + Clock *wdogclk; | ||
47 | |||
48 | uint32_t control; | ||
49 | uint32_t intstatus; | ||
50 | diff --git a/hw/watchdog/cmsdk-apb-watchdog.c b/hw/watchdog/cmsdk-apb-watchdog.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/hw/watchdog/cmsdk-apb-watchdog.c | ||
53 | +++ b/hw/watchdog/cmsdk-apb-watchdog.c | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | #include "hw/irq.h" | ||
56 | #include "hw/qdev-properties.h" | ||
57 | #include "hw/registerfields.h" | ||
58 | +#include "hw/qdev-clock.h" | ||
59 | #include "hw/watchdog/cmsdk-apb-watchdog.h" | ||
60 | #include "migration/vmstate.h" | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_init(Object *obj) | ||
63 | s, "cmsdk-apb-watchdog", 0x1000); | ||
64 | sysbus_init_mmio(sbd, &s->iomem); | ||
65 | sysbus_init_irq(sbd, &s->wdogint); | ||
66 | + s->wdogclk = qdev_init_clock_in(DEVICE(s), "WDOGCLK", NULL, NULL); | ||
67 | |||
68 | s->is_luminary = false; | ||
69 | s->id = cmsdk_apb_watchdog_id; | ||
70 | @@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp) | ||
71 | |||
72 | static const VMStateDescription cmsdk_apb_watchdog_vmstate = { | ||
73 | .name = "cmsdk-apb-watchdog", | ||
74 | - .version_id = 1, | ||
75 | - .minimum_version_id = 1, | ||
76 | + .version_id = 2, | ||
77 | + .minimum_version_id = 2, | ||
78 | .fields = (VMStateField[]) { | ||
79 | + VMSTATE_CLOCK(wdogclk, CMSDKAPBWatchdog), | ||
80 | VMSTATE_PTIMER(timer, CMSDKAPBWatchdog), | ||
81 | VMSTATE_UINT32(control, CMSDKAPBWatchdog), | ||
82 | VMSTATE_UINT32(intstatus, CMSDKAPBWatchdog), | ||
83 | -- | ||
84 | 2.20.1 | ||
85 | |||
86 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | While we transition the ARMSSE code from integer properties | ||
2 | specifying clock frequencies to Clock objects, we want to have the | ||
3 | device provide both at once. We want the final name of the main | ||
4 | input Clock to be "MAINCLK", following the hardware name. | ||
5 | Unfortunately creating an input Clock with a name X creates an | ||
6 | under-the-hood QOM property X; for "MAINCLK" this clashes with the | ||
7 | existing UINT32 property of that name. | ||
8 | 1 | ||
9 | Rename the UINT32 property to MAINCLK_FRQ so it can coexist with the | ||
10 | MAINCLK Clock; once the transition is complete MAINCLK_FRQ will be | ||
11 | deleted. | ||
12 | |||
13 | Commit created with: | ||
14 | perl -p -i -e 's/MAINCLK/MAINCLK_FRQ/g' hw/arm/{armsse,mps2-tz,musca}.c include/hw/arm/armsse.h | ||
15 | |||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
19 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | Message-id: 20210128114145.20536-11-peter.maydell@linaro.org | ||
21 | Message-id: 20210121190622.22000-11-peter.maydell@linaro.org | ||
22 | --- | ||
23 | include/hw/arm/armsse.h | 2 +- | ||
24 | hw/arm/armsse.c | 6 +++--- | ||
25 | hw/arm/mps2-tz.c | 2 +- | ||
26 | hw/arm/musca.c | 2 +- | ||
27 | 4 files changed, 6 insertions(+), 6 deletions(-) | ||
28 | |||
29 | diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/arm/armsse.h | ||
32 | +++ b/include/hw/arm/armsse.h | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | * QEMU interface: | ||
35 | * + QOM property "memory" is a MemoryRegion containing the devices provided | ||
36 | * by the board model. | ||
37 | - * + QOM property "MAINCLK" is the frequency of the main system clock | ||
38 | + * + QOM property "MAINCLK_FRQ" is the frequency of the main system clock | ||
39 | * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts. | ||
40 | * (In hardware, the SSE-200 permits the number of expansion interrupts | ||
41 | * for the two CPUs to be configured separately, but we restrict it to | ||
42 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/arm/armsse.c | ||
45 | +++ b/hw/arm/armsse.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static Property iotkit_properties[] = { | ||
47 | DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION, | ||
48 | MemoryRegion *), | ||
49 | DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64), | ||
50 | - DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0), | ||
51 | + DEFINE_PROP_UINT32("MAINCLK_FRQ", ARMSSE, mainclk_frq, 0), | ||
52 | DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15), | ||
53 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
54 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true), | ||
55 | @@ -XXX,XX +XXX,XX @@ static Property armsse_properties[] = { | ||
56 | DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION, | ||
57 | MemoryRegion *), | ||
58 | DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64), | ||
59 | - DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0), | ||
60 | + DEFINE_PROP_UINT32("MAINCLK_FRQ", ARMSSE, mainclk_frq, 0), | ||
61 | DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15), | ||
62 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
63 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false), | ||
64 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
65 | } | ||
66 | |||
67 | if (!s->mainclk_frq) { | ||
68 | - error_setg(errp, "MAINCLK property was not set"); | ||
69 | + error_setg(errp, "MAINCLK_FRQ property was not set"); | ||
70 | return; | ||
71 | } | ||
72 | |||
73 | diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/hw/arm/mps2-tz.c | ||
76 | +++ b/hw/arm/mps2-tz.c | ||
77 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine) | ||
78 | object_property_set_link(OBJECT(&mms->iotkit), "memory", | ||
79 | OBJECT(system_memory), &error_abort); | ||
80 | qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ); | ||
81 | - qdev_prop_set_uint32(iotkitdev, "MAINCLK", SYSCLK_FRQ); | ||
82 | + qdev_prop_set_uint32(iotkitdev, "MAINCLK_FRQ", SYSCLK_FRQ); | ||
83 | sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal); | ||
84 | |||
85 | /* | ||
86 | diff --git a/hw/arm/musca.c b/hw/arm/musca.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/hw/arm/musca.c | ||
89 | +++ b/hw/arm/musca.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static void musca_init(MachineState *machine) | ||
91 | qdev_prop_set_uint32(ssedev, "EXP_NUMIRQ", mmc->num_irqs); | ||
92 | qdev_prop_set_uint32(ssedev, "init-svtor", mmc->init_svtor); | ||
93 | qdev_prop_set_uint32(ssedev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width); | ||
94 | - qdev_prop_set_uint32(ssedev, "MAINCLK", SYSCLK_FRQ); | ||
95 | + qdev_prop_set_uint32(ssedev, "MAINCLK_FRQ", SYSCLK_FRQ); | ||
96 | /* | ||
97 | * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for | ||
98 | * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0. | ||
99 | -- | ||
100 | 2.20.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Create and connect the two clocks needed by the ARMSSE. | ||
2 | 1 | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Message-id: 20210128114145.20536-16-peter.maydell@linaro.org | ||
8 | Message-id: 20210121190622.22000-16-peter.maydell@linaro.org | ||
9 | --- | ||
10 | hw/arm/musca.c | 12 ++++++++++++ | ||
11 | 1 file changed, 12 insertions(+) | ||
12 | |||
13 | diff --git a/hw/arm/musca.c b/hw/arm/musca.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/arm/musca.c | ||
16 | +++ b/hw/arm/musca.c | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | #include "hw/misc/tz-ppc.h" | ||
19 | #include "hw/misc/unimp.h" | ||
20 | #include "hw/rtc/pl031.h" | ||
21 | +#include "hw/qdev-clock.h" | ||
22 | #include "qom/object.h" | ||
23 | |||
24 | #define MUSCA_NUMIRQ_MAX 96 | ||
25 | @@ -XXX,XX +XXX,XX @@ struct MuscaMachineState { | ||
26 | UnimplementedDeviceState sdio; | ||
27 | UnimplementedDeviceState gpio; | ||
28 | UnimplementedDeviceState cryptoisland; | ||
29 | + Clock *sysclk; | ||
30 | + Clock *s32kclk; | ||
31 | }; | ||
32 | |||
33 | #define TYPE_MUSCA_MACHINE "musca" | ||
34 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MuscaMachineState, MuscaMachineClass, MUSCA_MACHINE) | ||
35 | * don't model that in our SSE-200 model yet. | ||
36 | */ | ||
37 | #define SYSCLK_FRQ 40000000 | ||
38 | +/* Slow 32Khz S32KCLK frequency in Hz */ | ||
39 | +#define S32KCLK_FRQ (32 * 1000) | ||
40 | |||
41 | static qemu_irq get_sse_irq_in(MuscaMachineState *mms, int irqno) | ||
42 | { | ||
43 | @@ -XXX,XX +XXX,XX @@ static void musca_init(MachineState *machine) | ||
44 | exit(1); | ||
45 | } | ||
46 | |||
47 | + mms->sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
48 | + clock_set_hz(mms->sysclk, SYSCLK_FRQ); | ||
49 | + mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK"); | ||
50 | + clock_set_hz(mms->s32kclk, S32KCLK_FRQ); | ||
51 | + | ||
52 | object_initialize_child(OBJECT(machine), "sse-200", &mms->sse, | ||
53 | TYPE_SSE200); | ||
54 | ssedev = DEVICE(&mms->sse); | ||
55 | @@ -XXX,XX +XXX,XX @@ static void musca_init(MachineState *machine) | ||
56 | qdev_prop_set_uint32(ssedev, "init-svtor", mmc->init_svtor); | ||
57 | qdev_prop_set_uint32(ssedev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width); | ||
58 | qdev_prop_set_uint32(ssedev, "MAINCLK_FRQ", SYSCLK_FRQ); | ||
59 | + qdev_connect_clock_in(ssedev, "MAINCLK", mms->sysclk); | ||
60 | + qdev_connect_clock_in(ssedev, "S32KCLK", mms->s32kclk); | ||
61 | /* | ||
62 | * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for | ||
63 | * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0. | ||
64 | -- | ||
65 | 2.20.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Remove all the code that sets frequency properties on the CMSDK | ||
2 | timer, dualtimer and watchdog devices and on the ARMSSE SoC device: | ||
3 | these properties are unused now that the devices rely on their Clock | ||
4 | inputs instead. | ||
5 | 1 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 20210128114145.20536-24-peter.maydell@linaro.org | ||
11 | Message-id: 20210121190622.22000-24-peter.maydell@linaro.org | ||
12 | --- | ||
13 | hw/arm/armsse.c | 7 ------- | ||
14 | hw/arm/mps2-tz.c | 1 - | ||
15 | hw/arm/mps2.c | 3 --- | ||
16 | hw/arm/musca.c | 1 - | ||
17 | hw/arm/stellaris.c | 3 --- | ||
18 | 5 files changed, 15 deletions(-) | ||
19 | |||
20 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/arm/armsse.c | ||
23 | +++ b/hw/arm/armsse.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
25 | * it to the appropriate PPC port; then we can realize the PPC and | ||
26 | * map its upstream ends to the right place in the container. | ||
27 | */ | ||
28 | - qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq); | ||
29 | qdev_connect_clock_in(DEVICE(&s->timer0), "pclk", s->mainclk); | ||
30 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer0), errp)) { | ||
31 | return; | ||
32 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
33 | object_property_set_link(OBJECT(&s->apb_ppc0), "port[0]", OBJECT(mr), | ||
34 | &error_abort); | ||
35 | |||
36 | - qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq); | ||
37 | qdev_connect_clock_in(DEVICE(&s->timer1), "pclk", s->mainclk); | ||
38 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer1), errp)) { | ||
39 | return; | ||
40 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
41 | object_property_set_link(OBJECT(&s->apb_ppc0), "port[1]", OBJECT(mr), | ||
42 | &error_abort); | ||
43 | |||
44 | - qdev_prop_set_uint32(DEVICE(&s->dualtimer), "pclk-frq", s->mainclk_frq); | ||
45 | qdev_connect_clock_in(DEVICE(&s->dualtimer), "TIMCLK", s->mainclk); | ||
46 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->dualtimer), errp)) { | ||
47 | return; | ||
48 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
49 | /* Devices behind APB PPC1: | ||
50 | * 0x4002f000: S32K timer | ||
51 | */ | ||
52 | - qdev_prop_set_uint32(DEVICE(&s->s32ktimer), "pclk-frq", S32KCLK); | ||
53 | qdev_connect_clock_in(DEVICE(&s->s32ktimer), "pclk", s->s32kclk); | ||
54 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->s32ktimer), errp)) { | ||
55 | return; | ||
56 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
57 | qdev_connect_gpio_out(DEVICE(&s->nmi_orgate), 0, | ||
58 | qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0)); | ||
59 | |||
60 | - qdev_prop_set_uint32(DEVICE(&s->s32kwatchdog), "wdogclk-frq", S32KCLK); | ||
61 | qdev_connect_clock_in(DEVICE(&s->s32kwatchdog), "WDOGCLK", s->s32kclk); | ||
62 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->s32kwatchdog), errp)) { | ||
63 | return; | ||
64 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
65 | |||
66 | /* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */ | ||
67 | |||
68 | - qdev_prop_set_uint32(DEVICE(&s->nswatchdog), "wdogclk-frq", s->mainclk_frq); | ||
69 | qdev_connect_clock_in(DEVICE(&s->nswatchdog), "WDOGCLK", s->mainclk); | ||
70 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->nswatchdog), errp)) { | ||
71 | return; | ||
72 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
73 | armsse_get_common_irq_in(s, 1)); | ||
74 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->nswatchdog), 0, 0x40081000); | ||
75 | |||
76 | - qdev_prop_set_uint32(DEVICE(&s->swatchdog), "wdogclk-frq", s->mainclk_frq); | ||
77 | qdev_connect_clock_in(DEVICE(&s->swatchdog), "WDOGCLK", s->mainclk); | ||
78 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->swatchdog), errp)) { | ||
79 | return; | ||
80 | diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/hw/arm/mps2-tz.c | ||
83 | +++ b/hw/arm/mps2-tz.c | ||
84 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine) | ||
85 | object_property_set_link(OBJECT(&mms->iotkit), "memory", | ||
86 | OBJECT(system_memory), &error_abort); | ||
87 | qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ); | ||
88 | - qdev_prop_set_uint32(iotkitdev, "MAINCLK_FRQ", SYSCLK_FRQ); | ||
89 | qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk); | ||
90 | qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk); | ||
91 | sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal); | ||
92 | diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/hw/arm/mps2.c | ||
95 | +++ b/hw/arm/mps2.c | ||
96 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
97 | object_initialize_child(OBJECT(mms), name, &mms->timer[i], | ||
98 | TYPE_CMSDK_APB_TIMER); | ||
99 | sbd = SYS_BUS_DEVICE(&mms->timer[i]); | ||
100 | - qdev_prop_set_uint32(DEVICE(&mms->timer[i]), "pclk-frq", SYSCLK_FRQ); | ||
101 | qdev_connect_clock_in(DEVICE(&mms->timer[i]), "pclk", mms->sysclk); | ||
102 | sysbus_realize_and_unref(sbd, &error_fatal); | ||
103 | sysbus_mmio_map(sbd, 0, base); | ||
104 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
105 | |||
106 | object_initialize_child(OBJECT(mms), "dualtimer", &mms->dualtimer, | ||
107 | TYPE_CMSDK_APB_DUALTIMER); | ||
108 | - qdev_prop_set_uint32(DEVICE(&mms->dualtimer), "pclk-frq", SYSCLK_FRQ); | ||
109 | qdev_connect_clock_in(DEVICE(&mms->dualtimer), "TIMCLK", mms->sysclk); | ||
110 | sysbus_realize(SYS_BUS_DEVICE(&mms->dualtimer), &error_fatal); | ||
111 | sysbus_connect_irq(SYS_BUS_DEVICE(&mms->dualtimer), 0, | ||
112 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
113 | sysbus_mmio_map(SYS_BUS_DEVICE(&mms->dualtimer), 0, 0x40002000); | ||
114 | object_initialize_child(OBJECT(mms), "watchdog", &mms->watchdog, | ||
115 | TYPE_CMSDK_APB_WATCHDOG); | ||
116 | - qdev_prop_set_uint32(DEVICE(&mms->watchdog), "wdogclk-frq", SYSCLK_FRQ); | ||
117 | qdev_connect_clock_in(DEVICE(&mms->watchdog), "WDOGCLK", mms->sysclk); | ||
118 | sysbus_realize(SYS_BUS_DEVICE(&mms->watchdog), &error_fatal); | ||
119 | sysbus_connect_irq(SYS_BUS_DEVICE(&mms->watchdog), 0, | ||
120 | diff --git a/hw/arm/musca.c b/hw/arm/musca.c | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/hw/arm/musca.c | ||
123 | +++ b/hw/arm/musca.c | ||
124 | @@ -XXX,XX +XXX,XX @@ static void musca_init(MachineState *machine) | ||
125 | qdev_prop_set_uint32(ssedev, "EXP_NUMIRQ", mmc->num_irqs); | ||
126 | qdev_prop_set_uint32(ssedev, "init-svtor", mmc->init_svtor); | ||
127 | qdev_prop_set_uint32(ssedev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width); | ||
128 | - qdev_prop_set_uint32(ssedev, "MAINCLK_FRQ", SYSCLK_FRQ); | ||
129 | qdev_connect_clock_in(ssedev, "MAINCLK", mms->sysclk); | ||
130 | qdev_connect_clock_in(ssedev, "S32KCLK", mms->s32kclk); | ||
131 | /* | ||
132 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/hw/arm/stellaris.c | ||
135 | +++ b/hw/arm/stellaris.c | ||
136 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
137 | if (board->dc1 & (1 << 3)) { /* watchdog present */ | ||
138 | dev = qdev_new(TYPE_LUMINARY_WATCHDOG); | ||
139 | |||
140 | - /* system_clock_scale is valid now */ | ||
141 | - uint32_t mainclk = NANOSECONDS_PER_SECOND / system_clock_scale; | ||
142 | - qdev_prop_set_uint32(dev, "wdogclk-frq", mainclk); | ||
143 | qdev_connect_clock_in(dev, "WDOGCLK", | ||
144 | qdev_get_clock_out(ssys_dev, "SYSCLK")); | ||
145 | |||
146 | -- | ||
147 | 2.20.1 | ||
148 | |||
149 | diff view generated by jsdifflib |