1 | Second pull request of the week; mostly RTH's support for some | 1 | Another go at the v8.5-MemTag linux-user support, plus a |
---|---|---|---|
2 | new-in-v8.1/v8.3 instructions, and my v8M board model. | 2 | couple more npcm7xx devices. |
3 | 3 | ||
4 | thanks | ||
5 | -- PMM | 4 | -- PMM |
6 | 5 | ||
7 | The following changes since commit 427cbc7e4136a061628cb4315cc8182ea36d772f: | 6 | The following changes since commit 8ba4bca570ace1e60614a0808631a517cf5df67a: |
8 | 7 | ||
9 | Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2018-03-01 18:46:41 +0000) | 8 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-02-15 17:13:57 +0000) |
10 | 9 | ||
11 | are available in the Git repository at: | 10 | are available in the Git repository at: |
12 | 11 | ||
13 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180302 | 12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210216 |
14 | 13 | ||
15 | for you to fetch changes up to e66a67bf28e1b4fce2e3d72a2610dbd48d9d3078: | 14 | for you to fetch changes up to 64fd5bddf3b71d1b92b55382ab39768bd87ecfbd: |
16 | 15 | ||
17 | target/arm: Enable ARM_FEATURE_V8_FCMA (2018-03-02 11:03:45 +0000) | 16 | tests/qtests: Add npcm7xx emc model test (2021-02-16 14:27:05 +0000) |
18 | 17 | ||
19 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
20 | target-arm queue: | 19 | target-arm queue: |
21 | * implement FCMA and RDM v8.1 and v8.3 instructions | 20 | * Support ARMv8.5-MemTag for linux-user |
22 | * enable Cortex-M33 v8M core, and provide new mps2-an505 board model | 21 | * ncpm7xx: Support SMBus, EMC ethernet devices |
23 | that uses it | 22 | * MAINTAINERS: add section for Clock framework |
24 | * decodetree: Propagate return value from translate subroutines | ||
25 | * xlnx-zynqmp: Implement the RTC device | ||
26 | 23 | ||
27 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
28 | Alistair Francis (3): | 25 | Doug Evans (3): |
29 | xlnx-zynqmp-rtc: Initial commit | 26 | hw/net: Add npcm7xx emc model |
30 | xlnx-zynqmp-rtc: Add basic time support | 27 | hw/arm: Add npcm7xx emc model |
31 | xlnx-zynqmp: Connect the RTC device | 28 | tests/qtests: Add npcm7xx emc model test |
32 | 29 | ||
33 | Peter Maydell (19): | 30 | Hao Wu (5): |
34 | loader: Add new load_ramdisk_as() | 31 | hw/i2c: Implement NPCM7XX SMBus Module Single Mode |
35 | hw/arm/boot: Honour CPU's address space for image loads | 32 | hw/arm: Add I2C sensors for NPCM750 eval board |
36 | hw/arm/armv7m: Honour CPU's address space for image loads | 33 | hw/arm: Add I2C sensors and EEPROM for GSJ machine |
37 | target/arm: Define an IDAU interface | 34 | hw/i2c: Add a QTest for NPCM7XX SMBus Device |
38 | armv7m: Forward idau property to CPU object | 35 | hw/i2c: Implement NPCM7XX SMBus Module FIFO Mode |
39 | target/arm: Define init-svtor property for the reset secure VTOR value | ||
40 | armv7m: Forward init-svtor property to CPU object | ||
41 | target/arm: Add Cortex-M33 | ||
42 | hw/misc/unimp: Move struct to header file | ||
43 | include/hw/or-irq.h: Add missing include guard | ||
44 | qdev: Add new qdev_init_gpio_in_named_with_opaque() | ||
45 | hw/core/split-irq: Device that splits IRQ lines | ||
46 | hw/misc/mps2-fpgaio: FPGA control block for MPS2 AN505 | ||
47 | hw/misc/tz-ppc: Model TrustZone peripheral protection controller | ||
48 | hw/misc/iotkit-secctl: Arm IoT Kit security controller initial skeleton | ||
49 | hw/misc/iotkit-secctl: Add handling for PPCs | ||
50 | hw/misc/iotkit-secctl: Add remaining simple registers | ||
51 | hw/arm/iotkit: Model Arm IOT Kit | ||
52 | mps2-an505: New board model: MPS2 with AN505 Cortex-M33 FPGA image | ||
53 | 36 | ||
54 | Richard Henderson (17): | 37 | Luc Michel (1): |
55 | decodetree: Propagate return value from translate subroutines | 38 | MAINTAINERS: add myself maintainer for the clock framework |
56 | target/arm: Add ARM_FEATURE_V8_RDM | ||
57 | target/arm: Refactor disas_simd_indexed decode | ||
58 | target/arm: Refactor disas_simd_indexed size checks | ||
59 | target/arm: Decode aa64 armv8.1 scalar three same extra | ||
60 | target/arm: Decode aa64 armv8.1 three same extra | ||
61 | target/arm: Decode aa64 armv8.1 scalar/vector x indexed element | ||
62 | target/arm: Decode aa32 armv8.1 three same | ||
63 | target/arm: Decode aa32 armv8.1 two reg and a scalar | ||
64 | target/arm: Enable ARM_FEATURE_V8_RDM | ||
65 | target/arm: Add ARM_FEATURE_V8_FCMA | ||
66 | target/arm: Decode aa64 armv8.3 fcadd | ||
67 | target/arm: Decode aa64 armv8.3 fcmla | ||
68 | target/arm: Decode aa32 armv8.3 3-same | ||
69 | target/arm: Decode aa32 armv8.3 2-reg-index | ||
70 | target/arm: Decode t32 simd 3reg and 2reg_scalar extension | ||
71 | target/arm: Enable ARM_FEATURE_V8_FCMA | ||
72 | 39 | ||
73 | hw/arm/Makefile.objs | 2 + | 40 | Richard Henderson (31): |
74 | hw/core/Makefile.objs | 1 + | 41 | tcg: Introduce target-specific page data for user-only |
75 | hw/misc/Makefile.objs | 4 + | 42 | linux-user: Introduce PAGE_ANON |
76 | hw/timer/Makefile.objs | 1 + | 43 | exec: Use uintptr_t for guest_base |
77 | target/arm/Makefile.objs | 2 +- | 44 | exec: Use uintptr_t in cpu_ldst.h |
78 | include/hw/arm/armv7m.h | 5 + | 45 | exec: Improve types for guest_addr_valid |
79 | include/hw/arm/iotkit.h | 109 ++++++ | 46 | linux-user: Check for overflow in access_ok |
80 | include/hw/arm/xlnx-zynqmp.h | 2 + | 47 | linux-user: Tidy VERIFY_READ/VERIFY_WRITE |
81 | include/hw/core/split-irq.h | 57 +++ | 48 | bsd-user: Tidy VERIFY_READ/VERIFY_WRITE |
82 | include/hw/irq.h | 4 +- | 49 | linux-user: Do not use guest_addr_valid for h2g_valid |
83 | include/hw/loader.h | 12 +- | 50 | linux-user: Fix guest_addr_valid vs reserved_va |
84 | include/hw/misc/iotkit-secctl.h | 103 ++++++ | 51 | exec: Introduce cpu_untagged_addr |
85 | include/hw/misc/mps2-fpgaio.h | 43 +++ | 52 | exec: Use cpu_untagged_addr in g2h; split out g2h_untagged |
86 | include/hw/misc/tz-ppc.h | 101 ++++++ | 53 | linux-user: Explicitly untag memory management syscalls |
87 | include/hw/misc/unimp.h | 10 + | 54 | linux-user: Use guest_range_valid in access_ok |
88 | include/hw/or-irq.h | 5 + | 55 | exec: Rename guest_{addr,range}_valid to *_untagged |
89 | include/hw/qdev-core.h | 30 +- | 56 | linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged |
90 | include/hw/timer/xlnx-zynqmp-rtc.h | 86 +++++ | 57 | linux-user: Move lock_user et al out of line |
91 | target/arm/cpu.h | 8 + | 58 | linux-user: Fix types in uaccess.c |
92 | target/arm/helper.h | 31 ++ | 59 | linux-user: Handle tags in lock_user/unlock_user |
93 | target/arm/idau.h | 61 ++++ | 60 | linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE |
94 | hw/arm/armv7m.c | 35 +- | 61 | target/arm: Improve gen_top_byte_ignore |
95 | hw/arm/boot.c | 119 ++++--- | 62 | target/arm: Use the proper TBI settings for linux-user |
96 | hw/arm/iotkit.c | 598 +++++++++++++++++++++++++++++++ | 63 | linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG |
97 | hw/arm/mps2-tz.c | 503 ++++++++++++++++++++++++++ | 64 | linux-user/aarch64: Implement PROT_MTE |
98 | hw/arm/xlnx-zynqmp.c | 14 + | 65 | target/arm: Split out syndrome.h from internals.h |
99 | hw/core/loader.c | 8 +- | 66 | linux-user/aarch64: Pass syndrome to EXC_*_ABORT |
100 | hw/core/qdev.c | 8 +- | 67 | linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault |
101 | hw/core/split-irq.c | 89 +++++ | 68 | linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error |
102 | hw/misc/iotkit-secctl.c | 704 +++++++++++++++++++++++++++++++++++++ | 69 | target/arm: Add allocation tag storage for user mode |
103 | hw/misc/mps2-fpgaio.c | 176 ++++++++++ | 70 | target/arm: Enable MTE for user-only |
104 | hw/misc/tz-ppc.c | 302 ++++++++++++++++ | 71 | tests/tcg/aarch64: Add mte smoke tests |
105 | hw/misc/unimp.c | 10 - | ||
106 | hw/timer/xlnx-zynqmp-rtc.c | 272 ++++++++++++++ | ||
107 | linux-user/elfload.c | 2 + | ||
108 | target/arm/cpu.c | 66 +++- | ||
109 | target/arm/cpu64.c | 2 + | ||
110 | target/arm/helper.c | 28 +- | ||
111 | target/arm/translate-a64.c | 514 +++++++++++++++++++++------ | ||
112 | target/arm/translate.c | 275 +++++++++++++-- | ||
113 | target/arm/vec_helper.c | 429 ++++++++++++++++++++++ | ||
114 | default-configs/arm-softmmu.mak | 5 + | ||
115 | hw/misc/trace-events | 24 ++ | ||
116 | hw/timer/trace-events | 3 + | ||
117 | scripts/decodetree.py | 5 +- | ||
118 | 45 files changed, 4668 insertions(+), 200 deletions(-) | ||
119 | create mode 100644 include/hw/arm/iotkit.h | ||
120 | create mode 100644 include/hw/core/split-irq.h | ||
121 | create mode 100644 include/hw/misc/iotkit-secctl.h | ||
122 | create mode 100644 include/hw/misc/mps2-fpgaio.h | ||
123 | create mode 100644 include/hw/misc/tz-ppc.h | ||
124 | create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h | ||
125 | create mode 100644 target/arm/idau.h | ||
126 | create mode 100644 hw/arm/iotkit.c | ||
127 | create mode 100644 hw/arm/mps2-tz.c | ||
128 | create mode 100644 hw/core/split-irq.c | ||
129 | create mode 100644 hw/misc/iotkit-secctl.c | ||
130 | create mode 100644 hw/misc/mps2-fpgaio.c | ||
131 | create mode 100644 hw/misc/tz-ppc.c | ||
132 | create mode 100644 hw/timer/xlnx-zynqmp-rtc.c | ||
133 | create mode 100644 target/arm/vec_helper.c | ||
134 | 72 | ||
73 | docs/system/arm/nuvoton.rst | 5 +- | ||
74 | bsd-user/qemu.h | 17 +- | ||
75 | include/exec/cpu-all.h | 47 +- | ||
76 | include/exec/cpu_ldst.h | 39 +- | ||
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 | ||
147 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | This data can be allocated by page_alloc_target_data() and |
4 | released by page_set_flags(start, end, prot | PAGE_RESET). | ||
5 | |||
6 | This data will be used to hold tag memory for AArch64 MTE. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-5-richard.henderson@linaro.org | 10 | Message-id: 20210212184902.1251044-2-richard.henderson@linaro.org |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 12 | --- |
8 | target/arm/Makefile.objs | 2 +- | 13 | include/exec/cpu-all.h | 42 +++++++++++++++++++++++++++++++++------ |
9 | target/arm/helper.h | 4 ++ | 14 | accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++ |
10 | target/arm/translate-a64.c | 84 ++++++++++++++++++++++++++++++++++ | 15 | linux-user/mmap.c | 4 +++- |
11 | target/arm/vec_helper.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ | 16 | linux-user/syscall.c | 4 ++-- |
12 | 4 files changed, 198 insertions(+), 1 deletion(-) | 17 | 4 files changed, 69 insertions(+), 9 deletions(-) |
13 | create mode 100644 target/arm/vec_helper.c | ||
14 | 18 | ||
15 | diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs | 19 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/Makefile.objs | 21 | --- a/include/exec/cpu-all.h |
18 | +++ b/target/arm/Makefile.objs | 22 | +++ b/include/exec/cpu-all.h |
19 | @@ -XXX,XX +XXX,XX @@ obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o | 23 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
20 | obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o | 24 | #define PAGE_EXEC 0x0004 |
21 | obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o | 25 | #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC) |
22 | obj-y += translate.o op_helper.o helper.o cpu.o | 26 | #define PAGE_VALID 0x0008 |
23 | -obj-y += neon_helper.o iwmmxt_helper.o | 27 | -/* original state of the write flag (used when tracking self-modifying |
24 | +obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o | 28 | - code */ |
25 | obj-y += gdbstub.o | 29 | +/* |
26 | obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o | 30 | + * Original state of the write flag (used when tracking self-modifying code) |
27 | obj-y += crypto_helper.o | 31 | + */ |
28 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 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 | ||
29 | index XXXXXXX..XXXXXXX 100644 | 83 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/helper.h | 84 | --- a/accel/tcg/translate-all.c |
31 | +++ b/target/arm/helper.h | 85 | +++ b/accel/tcg/translate-all.c |
32 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(neon_rbit_u8, TCG_CALL_NO_RWG_SE, i32, i32) | 86 | @@ -XXX,XX +XXX,XX @@ typedef struct PageDesc { |
33 | 87 | unsigned int code_write_count; | |
34 | DEF_HELPER_3(neon_qdmulh_s16, i32, env, i32, i32) | 88 | #else |
35 | DEF_HELPER_3(neon_qrdmulh_s16, i32, env, i32, i32) | 89 | unsigned long flags; |
36 | +DEF_HELPER_4(neon_qrdmlah_s16, i32, env, i32, i32, i32) | 90 | + void *target_data; |
37 | +DEF_HELPER_4(neon_qrdmlsh_s16, i32, env, i32, i32, i32) | 91 | #endif |
38 | DEF_HELPER_3(neon_qdmulh_s32, i32, env, i32, i32) | 92 | #ifndef CONFIG_USER_ONLY |
39 | DEF_HELPER_3(neon_qrdmulh_s32, i32, env, i32, i32) | 93 | QemuSpin lock; |
40 | +DEF_HELPER_4(neon_qrdmlah_s32, i32, env, s32, s32, s32) | 94 | @@ -XXX,XX +XXX,XX @@ int page_get_flags(target_ulong address) |
41 | +DEF_HELPER_4(neon_qrdmlsh_s32, i32, env, s32, s32, s32) | 95 | void page_set_flags(target_ulong start, target_ulong end, int flags) |
42 | 96 | { | |
43 | DEF_HELPER_1(neon_narrow_u8, i32, i64) | 97 | target_ulong addr, len; |
44 | DEF_HELPER_1(neon_narrow_u16, i32, i64) | 98 | + bool reset_target_data; |
45 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 99 | |
46 | index XXXXXXX..XXXXXXX 100644 | 100 | /* This function should never be called with addresses outside the |
47 | --- a/target/arm/translate-a64.c | 101 | guest address space. If this assert fires, it probably indicates |
48 | +++ b/target/arm/translate-a64.c | 102 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) |
49 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s, | 103 | if (flags & PAGE_WRITE) { |
50 | tcg_temp_free_ptr(fpst); | 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; | ||
120 | } | ||
51 | } | 121 | } |
52 | 122 | ||
53 | +/* AdvSIMD scalar three same extra | 123 | +void *page_get_target_data(target_ulong address) |
54 | + * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0 | ||
55 | + * +-----+---+-----------+------+---+------+---+--------+---+----+----+ | ||
56 | + * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd | | ||
57 | + * +-----+---+-----------+------+---+------+---+--------+---+----+----+ | ||
58 | + */ | ||
59 | +static void disas_simd_scalar_three_reg_same_extra(DisasContext *s, | ||
60 | + uint32_t insn) | ||
61 | +{ | 124 | +{ |
62 | + int rd = extract32(insn, 0, 5); | 125 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); |
63 | + int rn = extract32(insn, 5, 5); | 126 | + return p ? p->target_data : NULL; |
64 | + int opcode = extract32(insn, 11, 4); | ||
65 | + int rm = extract32(insn, 16, 5); | ||
66 | + int size = extract32(insn, 22, 2); | ||
67 | + bool u = extract32(insn, 29, 1); | ||
68 | + TCGv_i32 ele1, ele2, ele3; | ||
69 | + TCGv_i64 res; | ||
70 | + int feature; | ||
71 | + | ||
72 | + switch (u * 16 + opcode) { | ||
73 | + case 0x10: /* SQRDMLAH (vector) */ | ||
74 | + case 0x11: /* SQRDMLSH (vector) */ | ||
75 | + if (size != 1 && size != 2) { | ||
76 | + unallocated_encoding(s); | ||
77 | + return; | ||
78 | + } | ||
79 | + feature = ARM_FEATURE_V8_RDM; | ||
80 | + break; | ||
81 | + default: | ||
82 | + unallocated_encoding(s); | ||
83 | + return; | ||
84 | + } | ||
85 | + if (!arm_dc_feature(s, feature)) { | ||
86 | + unallocated_encoding(s); | ||
87 | + return; | ||
88 | + } | ||
89 | + if (!fp_access_check(s)) { | ||
90 | + return; | ||
91 | + } | ||
92 | + | ||
93 | + /* Do a single operation on the lowest element in the vector. | ||
94 | + * We use the standard Neon helpers and rely on 0 OP 0 == 0 | ||
95 | + * with no side effects for all these operations. | ||
96 | + * OPTME: special-purpose helpers would avoid doing some | ||
97 | + * unnecessary work in the helper for the 16 bit cases. | ||
98 | + */ | ||
99 | + ele1 = tcg_temp_new_i32(); | ||
100 | + ele2 = tcg_temp_new_i32(); | ||
101 | + ele3 = tcg_temp_new_i32(); | ||
102 | + | ||
103 | + read_vec_element_i32(s, ele1, rn, 0, size); | ||
104 | + read_vec_element_i32(s, ele2, rm, 0, size); | ||
105 | + read_vec_element_i32(s, ele3, rd, 0, size); | ||
106 | + | ||
107 | + switch (opcode) { | ||
108 | + case 0x0: /* SQRDMLAH */ | ||
109 | + if (size == 1) { | ||
110 | + gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3); | ||
111 | + } else { | ||
112 | + gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3); | ||
113 | + } | ||
114 | + break; | ||
115 | + case 0x1: /* SQRDMLSH */ | ||
116 | + if (size == 1) { | ||
117 | + gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3); | ||
118 | + } else { | ||
119 | + gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3); | ||
120 | + } | ||
121 | + break; | ||
122 | + default: | ||
123 | + g_assert_not_reached(); | ||
124 | + } | ||
125 | + tcg_temp_free_i32(ele1); | ||
126 | + tcg_temp_free_i32(ele2); | ||
127 | + | ||
128 | + res = tcg_temp_new_i64(); | ||
129 | + tcg_gen_extu_i32_i64(res, ele3); | ||
130 | + tcg_temp_free_i32(ele3); | ||
131 | + | ||
132 | + write_fp_dreg(s, rd, res); | ||
133 | + tcg_temp_free_i64(res); | ||
134 | +} | 127 | +} |
135 | + | 128 | + |
136 | static void handle_2misc_64(DisasContext *s, int opcode, bool u, | 129 | +void *page_alloc_target_data(target_ulong address, size_t size) |
137 | TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, | 130 | +{ |
138 | TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus) | 131 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); |
139 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | 132 | + void *ret = NULL; |
140 | { 0x0e000800, 0xbf208c00, disas_simd_zip_trn }, | ||
141 | { 0x2e000000, 0xbf208400, disas_simd_ext }, | ||
142 | { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same }, | ||
143 | + { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra }, | ||
144 | { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff }, | ||
145 | { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc }, | ||
146 | { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise }, | ||
147 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
148 | new file mode 100644 | ||
149 | index XXXXXXX..XXXXXXX | ||
150 | --- /dev/null | ||
151 | +++ b/target/arm/vec_helper.c | ||
152 | @@ -XXX,XX +XXX,XX @@ | ||
153 | +/* | ||
154 | + * ARM AdvSIMD / SVE Vector Operations | ||
155 | + * | ||
156 | + * Copyright (c) 2018 Linaro | ||
157 | + * | ||
158 | + * This library is free software; you can redistribute it and/or | ||
159 | + * modify it under the terms of the GNU Lesser General Public | ||
160 | + * License as published by the Free Software Foundation; either | ||
161 | + * version 2 of the License, or (at your option) any later version. | ||
162 | + * | ||
163 | + * This library is distributed in the hope that it will be useful, | ||
164 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
165 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
166 | + * Lesser General Public License for more details. | ||
167 | + * | ||
168 | + * You should have received a copy of the GNU Lesser General Public | ||
169 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
170 | + */ | ||
171 | + | 133 | + |
172 | +#include "qemu/osdep.h" | 134 | + if (p->flags & PAGE_VALID) { |
173 | +#include "cpu.h" | 135 | + ret = p->target_data; |
174 | +#include "exec/exec-all.h" | 136 | + if (!ret) { |
175 | +#include "exec/helper-proto.h" | 137 | + p->target_data = ret = g_malloc0(size); |
176 | +#include "tcg/tcg-gvec-desc.h" | 138 | + } |
177 | + | ||
178 | + | ||
179 | +#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q | ||
180 | + | ||
181 | +/* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */ | ||
182 | +static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1, | ||
183 | + int16_t src2, int16_t src3) | ||
184 | +{ | ||
185 | + /* Simplify: | ||
186 | + * = ((a3 << 16) + ((e1 * e2) << 1) + (1 << 15)) >> 16 | ||
187 | + * = ((a3 << 15) + (e1 * e2) + (1 << 14)) >> 15 | ||
188 | + */ | ||
189 | + int32_t ret = (int32_t)src1 * src2; | ||
190 | + ret = ((int32_t)src3 << 15) + ret + (1 << 14); | ||
191 | + ret >>= 15; | ||
192 | + if (ret != (int16_t)ret) { | ||
193 | + SET_QC(); | ||
194 | + ret = (ret < 0 ? -0x8000 : 0x7fff); | ||
195 | + } | 139 | + } |
196 | + return ret; | 140 | + return ret; |
197 | +} | 141 | +} |
198 | + | 142 | + |
199 | +uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1, | 143 | int page_check_range(target_ulong start, target_ulong len, int flags) |
200 | + uint32_t src2, uint32_t src3) | 144 | { |
201 | +{ | 145 | PageDesc *p; |
202 | + uint16_t e1 = inl_qrdmlah_s16(env, src1, src2, src3); | 146 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
203 | + uint16_t e2 = inl_qrdmlah_s16(env, src1 >> 16, src2 >> 16, src3 >> 16); | 147 | index XXXXXXX..XXXXXXX 100644 |
204 | + return deposit32(e1, 16, 16, e2); | 148 | --- a/linux-user/mmap.c |
205 | +} | 149 | +++ b/linux-user/mmap.c |
206 | + | 150 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
207 | +/* Signed saturating rounding doubling multiply-subtract high half, 16-bit */ | 151 | } |
208 | +static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1, | 152 | } |
209 | + int16_t src2, int16_t src3) | 153 | the_end1: |
210 | +{ | 154 | + page_flags |= PAGE_RESET; |
211 | + /* Similarly, using subtraction: | 155 | page_set_flags(start, start + len, page_flags); |
212 | + * = ((a3 << 16) - ((e1 * e2) << 1) + (1 << 15)) >> 16 | 156 | the_end: |
213 | + * = ((a3 << 15) - (e1 * e2) + (1 << 14)) >> 15 | 157 | trace_target_mmap_complete(start); |
214 | + */ | 158 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
215 | + int32_t ret = (int32_t)src1 * src2; | 159 | new_addr = h2g(host_addr); |
216 | + ret = ((int32_t)src3 << 15) - ret + (1 << 14); | 160 | prot = page_get_flags(old_addr); |
217 | + ret >>= 15; | 161 | page_set_flags(old_addr, old_addr + old_size, 0); |
218 | + if (ret != (int16_t)ret) { | 162 | - page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); |
219 | + SET_QC(); | 163 | + page_set_flags(new_addr, new_addr + new_size, |
220 | + ret = (ret < 0 ? -0x8000 : 0x7fff); | 164 | + prot | PAGE_VALID | PAGE_RESET); |
221 | + } | 165 | } |
222 | + return ret; | 166 | tb_invalidate_phys_range(new_addr, new_addr + new_size); |
223 | +} | 167 | mmap_unlock(); |
224 | + | 168 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
225 | +uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1, | 169 | index XXXXXXX..XXXXXXX 100644 |
226 | + uint32_t src2, uint32_t src3) | 170 | --- a/linux-user/syscall.c |
227 | +{ | 171 | +++ b/linux-user/syscall.c |
228 | + uint16_t e1 = inl_qrdmlsh_s16(env, src1, src2, src3); | 172 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, |
229 | + uint16_t e2 = inl_qrdmlsh_s16(env, src1 >> 16, src2 >> 16, src3 >> 16); | 173 | raddr=h2g((unsigned long)host_raddr); |
230 | + return deposit32(e1, 16, 16, e2); | 174 | |
231 | +} | 175 | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
232 | + | 176 | - PAGE_VALID | PAGE_READ | |
233 | +/* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */ | 177 | - ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); |
234 | +uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1, | 178 | + PAGE_VALID | PAGE_RESET | PAGE_READ | |
235 | + int32_t src2, int32_t src3) | 179 | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); |
236 | +{ | 180 | |
237 | + /* Simplify similarly to int_qrdmlah_s16 above. */ | 181 | for (i = 0; i < N_SHM_REGIONS; i++) { |
238 | + int64_t ret = (int64_t)src1 * src2; | 182 | if (!shm_regions[i].in_use) { |
239 | + ret = ((int64_t)src3 << 31) + ret + (1 << 30); | ||
240 | + ret >>= 31; | ||
241 | + if (ret != (int32_t)ret) { | ||
242 | + SET_QC(); | ||
243 | + ret = (ret < 0 ? INT32_MIN : INT32_MAX); | ||
244 | + } | ||
245 | + return ret; | ||
246 | +} | ||
247 | + | ||
248 | +/* Signed saturating rounding doubling multiply-subtract high half, 32-bit */ | ||
249 | +uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1, | ||
250 | + int32_t src2, int32_t src3) | ||
251 | +{ | ||
252 | + /* Simplify similarly to int_qrdmlsh_s16 above. */ | ||
253 | + int64_t ret = (int64_t)src1 * src2; | ||
254 | + ret = ((int64_t)src3 << 31) - ret + (1 << 30); | ||
255 | + ret >>= 31; | ||
256 | + if (ret != (int32_t)ret) { | ||
257 | + SET_QC(); | ||
258 | + ret = (ret < 0 ? INT32_MIN : INT32_MAX); | ||
259 | + } | ||
260 | + return ret; | ||
261 | +} | ||
262 | -- | 183 | -- |
263 | 2.16.2 | 184 | 2.20.1 |
264 | 185 | ||
265 | 186 | diff view generated by jsdifflib |
1 | Create an "init-svtor" property on the armv7m container | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | object which we can forward to the CPU object. | ||
3 | 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 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20180220180325.29818-8-peter.maydell@linaro.org | ||
7 | --- | 19 | --- |
8 | include/hw/arm/armv7m.h | 2 ++ | 20 | include/exec/cpu-all.h | 2 ++ |
9 | hw/arm/armv7m.c | 9 +++++++++ | 21 | linux-user/mmap.c | 3 +++ |
10 | 2 files changed, 11 insertions(+) | 22 | 2 files changed, 5 insertions(+) |
11 | 23 | ||
12 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h | 24 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
13 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/include/hw/arm/armv7m.h | 26 | --- a/include/exec/cpu-all.h |
15 | +++ b/include/hw/arm/armv7m.h | 27 | +++ b/include/exec/cpu-all.h |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 28 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
17 | * that CPU accesses see. (The NVIC, bitbanding and other CPU-internal | 29 | #define PAGE_WRITE_INV 0x0020 |
18 | * devices will be automatically layered on top of this view.) | 30 | /* For use with page_set_flags: page is being replaced; target_data cleared. */ |
19 | * + Property "idau": IDAU interface (forwarded to CPU object) | 31 | #define PAGE_RESET 0x0040 |
20 | + * + Property "init-svtor": secure VTOR reset value (forwarded to CPU object) | 32 | +/* For linux-user, indicates that the page is MAP_ANON. */ |
21 | */ | 33 | +#define PAGE_ANON 0x0080 |
22 | typedef struct ARMv7MState { | 34 | |
23 | /*< private >*/ | 35 | #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) |
24 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState { | 36 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ |
25 | /* MemoryRegion the board provides to us (with its devices, RAM, etc) */ | 37 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
26 | MemoryRegion *board_memory; | ||
27 | Object *idau; | ||
28 | + uint32_t init_svtor; | ||
29 | } ARMv7MState; | ||
30 | |||
31 | #endif | ||
32 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/hw/arm/armv7m.c | 39 | --- a/linux-user/mmap.c |
35 | +++ b/hw/arm/armv7m.c | 40 | +++ b/linux-user/mmap.c |
36 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | 41 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
37 | return; | ||
38 | } | 42 | } |
39 | } | 43 | } |
40 | + if (object_property_find(OBJECT(s->cpu), "init-svtor", NULL)) { | 44 | the_end1: |
41 | + object_property_set_uint(OBJECT(s->cpu), s->init_svtor, | 45 | + if (flags & MAP_ANONYMOUS) { |
42 | + "init-svtor", &err); | 46 | + page_flags |= PAGE_ANON; |
43 | + if (err != NULL) { | ||
44 | + error_propagate(errp, err); | ||
45 | + return; | ||
46 | + } | ||
47 | + } | 47 | + } |
48 | object_property_set_bool(OBJECT(s->cpu), true, "realized", &err); | 48 | page_flags |= PAGE_RESET; |
49 | if (err != NULL) { | 49 | page_set_flags(start, start + len, page_flags); |
50 | error_propagate(errp, err); | 50 | the_end: |
51 | @@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = { | ||
52 | DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION, | ||
53 | MemoryRegion *), | ||
54 | DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *), | ||
55 | + DEFINE_PROP_UINT32("init-svtor", ARMv7MState, init_svtor, 0), | ||
56 | DEFINE_PROP_END_OF_LIST(), | ||
57 | }; | ||
58 | |||
59 | -- | 51 | -- |
60 | 2.16.2 | 52 | 2.20.1 |
61 | 53 | ||
62 | 54 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The integer size check was already outside of the opcode switch; | 3 | This is more descriptive than 'unsigned long'. |
4 | move the floating-point size check outside as well. Unify the | 4 | No functional change, since these match on all linux+bsd hosts. |
5 | size vs index adjustment between fp and integer paths. | ||
6 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Message-id: 20180228193125.20577-4-richard.henderson@linaro.org | 9 | Message-id: 20210212184902.1251044-4-richard.henderson@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 | target/arm/translate-a64.c | 65 +++++++++++++++++++++++----------------------- | 12 | include/exec/cpu-all.h | 2 +- |
13 | 1 file changed, 32 insertions(+), 33 deletions(-) | 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(-) | ||
14 | 17 | ||
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
16 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 20 | --- a/include/exec/cpu-all.h |
18 | +++ b/target/arm/translate-a64.c | 21 | +++ b/include/exec/cpu-all.h |
19 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 22 | @@ -XXX,XX +XXX,XX @@ static inline void tswap64s(uint64_t *s) |
20 | case 0x05: /* FMLS */ | 23 | /* On some host systems the guest address space is reserved on the host. |
21 | case 0x09: /* FMUL */ | 24 | * This allows the guest address space to be offset to a convenient location. |
22 | case 0x19: /* FMULX */ | 25 | */ |
23 | - if (size == 1) { | 26 | -extern unsigned long guest_base; |
24 | - unallocated_encoding(s); | 27 | +extern uintptr_t guest_base; |
25 | - return; | 28 | extern bool have_guest_base; |
26 | - } | 29 | extern unsigned long reserved_va; |
27 | is_fp = true; | 30 | |
28 | break; | 31 | diff --git a/bsd-user/main.c b/bsd-user/main.c |
29 | default: | 32 | index XXXXXXX..XXXXXXX 100644 |
30 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 33 | --- a/bsd-user/main.c |
31 | if (is_fp) { | 34 | +++ b/bsd-user/main.c |
32 | /* convert insn encoded size to TCGMemOp size */ | 35 | @@ -XXX,XX +XXX,XX @@ |
33 | switch (size) { | 36 | |
34 | - case 2: /* single precision */ | 37 | int singlestep; |
35 | - size = MO_32; | 38 | unsigned long mmap_min_addr; |
36 | - index = h << 1 | l; | 39 | -unsigned long guest_base; |
37 | - rm |= (m << 4); | 40 | +uintptr_t guest_base; |
38 | - break; | 41 | bool have_guest_base; |
39 | - case 3: /* double precision */ | 42 | unsigned long reserved_va; |
40 | - size = MO_64; | 43 | |
41 | - if (l || !is_q) { | 44 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
42 | + case 0: /* half-precision */ | 45 | g_free(target_environ); |
43 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 46 | |
44 | unallocated_encoding(s); | 47 | if (qemu_loglevel_mask(CPU_LOG_PAGE)) { |
45 | return; | 48 | - qemu_log("guest_base 0x%lx\n", guest_base); |
46 | } | 49 | + qemu_log("guest_base %p\n", (void *)guest_base); |
47 | - index = h; | 50 | log_page_dump("binary load"); |
48 | - rm |= (m << 4); | 51 | |
49 | - break; | 52 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); |
50 | - case 0: /* half precision */ | 53 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
51 | size = MO_16; | 54 | index XXXXXXX..XXXXXXX 100644 |
52 | - index = h << 2 | l << 1 | m; | 55 | --- a/linux-user/elfload.c |
53 | - is_fp16 = true; | 56 | +++ b/linux-user/elfload.c |
54 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 57 | @@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, |
55 | - break; | 58 | void *addr, *test; |
56 | - } | 59 | |
57 | - /* fallthru */ | 60 | if (!QEMU_IS_ALIGNED(guest_base, align)) { |
58 | - default: /* unallocated */ | 61 | - fprintf(stderr, "Requested guest base 0x%lx does not satisfy " |
59 | - unallocated_encoding(s); | 62 | + fprintf(stderr, "Requested guest base %p does not satisfy " |
60 | - return; | 63 | "host minimum alignment (0x%lx)\n", |
61 | - } | 64 | - guest_base, align); |
62 | - } else { | 65 | + (void *)guest_base, align); |
63 | - switch (size) { | 66 | exit(EXIT_FAILURE); |
64 | - case 1: | ||
65 | - index = h << 2 | l << 1 | m; | ||
66 | break; | ||
67 | - case 2: | ||
68 | - index = h << 1 | l; | ||
69 | - rm |= (m << 4); | ||
70 | + case MO_32: /* single precision */ | ||
71 | + case MO_64: /* double precision */ | ||
72 | break; | ||
73 | default: | ||
74 | unallocated_encoding(s); | ||
75 | return; | ||
76 | } | ||
77 | + } else { | ||
78 | + switch (size) { | ||
79 | + case MO_8: | ||
80 | + case MO_64: | ||
81 | + unallocated_encoding(s); | ||
82 | + return; | ||
83 | + } | ||
84 | + } | ||
85 | + | ||
86 | + /* Given TCGMemOp size, adjust register and indexing. */ | ||
87 | + switch (size) { | ||
88 | + case MO_16: | ||
89 | + index = h << 2 | l << 1 | m; | ||
90 | + break; | ||
91 | + case MO_32: | ||
92 | + index = h << 1 | l; | ||
93 | + rm |= m << 4; | ||
94 | + break; | ||
95 | + case MO_64: | ||
96 | + if (l || !is_q) { | ||
97 | + unallocated_encoding(s); | ||
98 | + return; | ||
99 | + } | ||
100 | + index = h; | ||
101 | + rm |= m << 4; | ||
102 | + break; | ||
103 | + default: | ||
104 | + g_assert_not_reached(); | ||
105 | } | 67 | } |
106 | 68 | ||
107 | if (!fp_access_check(s)) { | 69 | diff --git a/linux-user/main.c b/linux-user/main.c |
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/linux-user/main.c | ||
72 | +++ b/linux-user/main.c | ||
73 | @@ -XXX,XX +XXX,XX @@ static const char *cpu_model; | ||
74 | static const char *cpu_type; | ||
75 | static const char *seed_optarg; | ||
76 | unsigned long mmap_min_addr; | ||
77 | -unsigned long guest_base; | ||
78 | +uintptr_t guest_base; | ||
79 | bool have_guest_base; | ||
80 | |||
81 | /* | ||
82 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
83 | g_free(target_environ); | ||
84 | |||
85 | if (qemu_loglevel_mask(CPU_LOG_PAGE)) { | ||
86 | - qemu_log("guest_base 0x%lx\n", guest_base); | ||
87 | + qemu_log("guest_base %p\n", (void *)guest_base); | ||
88 | log_page_dump("binary load"); | ||
89 | |||
90 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); | ||
108 | -- | 91 | -- |
109 | 2.16.2 | 92 | 2.20.1 |
110 | 93 | ||
111 | 94 | diff view generated by jsdifflib |
1 | Create an "idau" property on the armv7m container object which | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | we can forward to the CPU object. Annoyingly, we can't use | ||
3 | object_property_add_alias() because the CPU object we want to | ||
4 | forward to doesn't exist until the armv7m container is realized. | ||
5 | 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 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180220180325.29818-6-peter.maydell@linaro.org | ||
9 | --- | 11 | --- |
10 | include/hw/arm/armv7m.h | 3 +++ | 12 | include/exec/cpu_ldst.h | 6 +++--- |
11 | hw/arm/armv7m.c | 9 +++++++++ | 13 | 1 file changed, 3 insertions(+), 3 deletions(-) |
12 | 2 files changed, 12 insertions(+) | ||
13 | 14 | ||
14 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h | 15 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/hw/arm/armv7m.h | 17 | --- a/include/exec/cpu_ldst.h |
17 | +++ b/include/hw/arm/armv7m.h | 18 | +++ b/include/exec/cpu_ldst.h |
18 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
19 | |||
20 | #include "hw/sysbus.h" | ||
21 | #include "hw/intc/armv7m_nvic.h" | ||
22 | +#include "target/arm/idau.h" | ||
23 | |||
24 | #define TYPE_BITBAND "ARM,bitband-memory" | ||
25 | #define BITBAND(obj) OBJECT_CHECK(BitBandState, (obj), TYPE_BITBAND) | ||
26 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
27 | * + Property "memory": MemoryRegion defining the physical address space | ||
28 | * that CPU accesses see. (The NVIC, bitbanding and other CPU-internal | ||
29 | * devices will be automatically layered on top of this view.) | ||
30 | + * + Property "idau": IDAU interface (forwarded to CPU object) | ||
31 | */ | ||
32 | typedef struct ARMv7MState { | ||
33 | /*< private >*/ | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState { | ||
35 | char *cpu_type; | ||
36 | /* MemoryRegion the board provides to us (with its devices, RAM, etc) */ | ||
37 | MemoryRegion *board_memory; | ||
38 | + Object *idau; | ||
39 | } ARMv7MState; | ||
40 | |||
41 | #endif | 20 | #endif |
42 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | 21 | |
43 | index XXXXXXX..XXXXXXX 100644 | 22 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
44 | --- a/hw/arm/armv7m.c | 23 | -#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) |
45 | +++ b/hw/arm/armv7m.c | 24 | +#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
46 | @@ -XXX,XX +XXX,XX @@ | 25 | |
47 | #include "sysemu/qtest.h" | 26 | #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
48 | #include "qemu/error-report.h" | 27 | #define guest_addr_valid(x) (1) |
49 | #include "exec/address-spaces.h" | 28 | #else |
50 | +#include "target/arm/idau.h" | 29 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
51 | 30 | #endif | |
52 | /* Bitbanded IO. Each word corresponds to a single bit. */ | 31 | -#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) |
53 | 32 | +#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) | |
54 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | 33 | |
55 | 34 | static inline int guest_range_valid(unsigned long start, unsigned long len) | |
56 | object_property_set_link(OBJECT(s->cpu), OBJECT(&s->container), "memory", | 35 | { |
57 | &error_abort); | 36 | @@ -XXX,XX +XXX,XX @@ static inline int guest_range_valid(unsigned long start, unsigned long len) |
58 | + if (object_property_find(OBJECT(s->cpu), "idau", NULL)) { | 37 | } |
59 | + object_property_set_link(OBJECT(s->cpu), s->idau, "idau", &err); | 38 | |
60 | + if (err != NULL) { | 39 | #define h2g_nocheck(x) ({ \ |
61 | + error_propagate(errp, err); | 40 | - unsigned long __ret = (unsigned long)(x) - guest_base; \ |
62 | + return; | 41 | + uintptr_t __ret = (uintptr_t)(x) - guest_base; \ |
63 | + } | 42 | (abi_ptr)__ret; \ |
64 | + } | 43 | }) |
65 | object_property_set_bool(OBJECT(s->cpu), true, "realized", &err); | ||
66 | if (err != NULL) { | ||
67 | error_propagate(errp, err); | ||
68 | @@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = { | ||
69 | DEFINE_PROP_STRING("cpu-type", ARMv7MState, cpu_type), | ||
70 | DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION, | ||
71 | MemoryRegion *), | ||
72 | + DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *), | ||
73 | DEFINE_PROP_END_OF_LIST(), | ||
74 | }; | ||
75 | 44 | ||
76 | -- | 45 | -- |
77 | 2.16.2 | 46 | 2.20.1 |
78 | 47 | ||
79 | 48 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
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. | ||
6 | |||
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 | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | include/exec/cpu_ldst.h | 2 +- | ||
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/exec/cpu_ldst.h | ||
19 | +++ b/include/exec/cpu_ldst.h | ||
20 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; | ||
21 | #endif | ||
22 | #define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) | ||
23 | |||
24 | -static inline int guest_range_valid(unsigned long start, unsigned long len) | ||
25 | +static inline bool guest_range_valid(abi_ulong start, abi_ulong len) | ||
26 | { | ||
27 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; | ||
28 | } | ||
29 | -- | ||
30 | 2.20.1 | ||
31 | |||
32 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Verify that addr + size - 1 does not wrap around. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Message-id: 20180228193125.20577-15-richard.henderson@linaro.org | 7 | Message-id: 20210212184902.1251044-7-richard.henderson@linaro.org |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 9 | --- |
8 | target/arm/translate.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ | 10 | linux-user/qemu.h | 17 ++++++++++++----- |
9 | 1 file changed, 61 insertions(+) | 11 | 1 file changed, 12 insertions(+), 5 deletions(-) |
10 | 12 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 13 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
12 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 15 | --- a/linux-user/qemu.h |
14 | +++ b/target/arm/translate.c | 16 | +++ b/linux-user/qemu.h |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | 17 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
16 | return 0; | 18 | #define VERIFY_READ 0 |
19 | #define VERIFY_WRITE 1 /* implies read access */ | ||
20 | |||
21 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) | ||
22 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
23 | { | ||
24 | - return guest_addr_valid(addr) && | ||
25 | - (size == 0 || guest_addr_valid(addr + size - 1)) && | ||
26 | - page_check_range((target_ulong)addr, size, | ||
27 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; | ||
28 | + if (!guest_addr_valid(addr)) { | ||
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; | ||
17 | } | 39 | } |
18 | 40 | ||
19 | +/* Advanced SIMD two registers and a scalar extension. | 41 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
20 | + * 31 24 23 22 20 16 12 11 10 9 8 3 0 | ||
21 | + * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+ | ||
22 | + * | 1 1 1 1 1 1 1 0 | o1 | D | o2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm | | ||
23 | + * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+ | ||
24 | + * | ||
25 | + */ | ||
26 | + | ||
27 | +static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn) | ||
28 | +{ | ||
29 | + int rd, rn, rm, rot, size, opr_sz; | ||
30 | + TCGv_ptr fpst; | ||
31 | + bool q; | ||
32 | + | ||
33 | + q = extract32(insn, 6, 1); | ||
34 | + VFP_DREG_D(rd, insn); | ||
35 | + VFP_DREG_N(rn, insn); | ||
36 | + VFP_DREG_M(rm, insn); | ||
37 | + if ((rd | rn) & q) { | ||
38 | + return 1; | ||
39 | + } | ||
40 | + | ||
41 | + if ((insn & 0xff000f10) == 0xfe000800) { | ||
42 | + /* VCMLA (indexed) -- 1111 1110 S.RR .... .... 1000 ...0 .... */ | ||
43 | + rot = extract32(insn, 20, 2); | ||
44 | + size = extract32(insn, 23, 1); | ||
45 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA) | ||
46 | + || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
47 | + return 1; | ||
48 | + } | ||
49 | + } else { | ||
50 | + return 1; | ||
51 | + } | ||
52 | + | ||
53 | + if (s->fp_excp_el) { | ||
54 | + gen_exception_insn(s, 4, EXCP_UDEF, | ||
55 | + syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | ||
56 | + return 0; | ||
57 | + } | ||
58 | + if (!s->vfp_enabled) { | ||
59 | + return 1; | ||
60 | + } | ||
61 | + | ||
62 | + opr_sz = (1 + q) * 8; | ||
63 | + fpst = get_fpstatus_ptr(1); | ||
64 | + tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd), | ||
65 | + vfp_reg_offset(1, rn), | ||
66 | + vfp_reg_offset(1, rm), fpst, | ||
67 | + opr_sz, opr_sz, rot, | ||
68 | + size ? gen_helper_gvec_fcmlas_idx | ||
69 | + : gen_helper_gvec_fcmlah_idx); | ||
70 | + tcg_temp_free_ptr(fpst); | ||
71 | + return 0; | ||
72 | +} | ||
73 | + | ||
74 | static int disas_coproc_insn(DisasContext *s, uint32_t insn) | ||
75 | { | ||
76 | int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2; | ||
77 | @@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) | ||
78 | goto illegal_op; | ||
79 | } | ||
80 | return; | ||
81 | + } else if ((insn & 0x0f000a00) == 0x0e000800 | ||
82 | + && arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
83 | + if (disas_neon_insn_2reg_scalar_ext(s, insn)) { | ||
84 | + goto illegal_op; | ||
85 | + } | ||
86 | + return; | ||
87 | } else if ((insn & 0x0fe00000) == 0x0c400000) { | ||
88 | /* Coprocessor double register transfer. */ | ||
89 | ARCH(5TE); | ||
90 | -- | 42 | -- |
91 | 2.16.2 | 43 | 2.20.1 |
92 | 44 | ||
93 | 45 | diff view generated by jsdifflib |
1 | Add a function load_ramdisk_as() which behaves like the existing | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | load_ramdisk() but allows the caller to specify the AddressSpace | ||
3 | to use. This matches the pattern we have already for various | ||
4 | other loader functions. | ||
5 | 2 | ||
3 | These constants are only ever used with access_ok, and friends. | ||
4 | Rather than translating them to PAGE_* bits, let them equal | ||
5 | the PAGE_* bits to begin. | ||
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-8-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20180220180325.29818-2-peter.maydell@linaro.org | ||
10 | --- | 11 | --- |
11 | include/hw/loader.h | 12 +++++++++++- | 12 | linux-user/qemu.h | 8 +++----- |
12 | hw/core/loader.c | 8 +++++++- | 13 | 1 file changed, 3 insertions(+), 5 deletions(-) |
13 | 2 files changed, 18 insertions(+), 2 deletions(-) | ||
14 | 14 | ||
15 | diff --git a/include/hw/loader.h b/include/hw/loader.h | 15 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/hw/loader.h | 17 | --- a/linux-user/qemu.h |
18 | +++ b/include/hw/loader.h | 18 | +++ b/linux-user/qemu.h |
19 | @@ -XXX,XX +XXX,XX @@ int load_uimage(const char *filename, hwaddr *ep, | 19 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
20 | void *translate_opaque); | 20 | |
21 | 21 | /* user access */ | |
22 | /** | 22 | |
23 | - * load_ramdisk: | 23 | -#define VERIFY_READ 0 |
24 | + * load_ramdisk_as: | 24 | -#define VERIFY_WRITE 1 /* implies read access */ |
25 | * @filename: Path to the ramdisk image | 25 | +#define VERIFY_READ PAGE_READ |
26 | * @addr: Memory address to load the ramdisk to | 26 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
27 | * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks) | 27 | |
28 | + * @as: The AddressSpace to load the ELF to. The value of address_space_memory | 28 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
29 | + * is used if nothing is supplied here. | ||
30 | * | ||
31 | * Load a ramdisk image with U-Boot header to the specified memory | ||
32 | * address. | ||
33 | * | ||
34 | * Returns the size of the loaded image on success, -1 otherwise. | ||
35 | */ | ||
36 | +int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz, | ||
37 | + AddressSpace *as); | ||
38 | + | ||
39 | +/** | ||
40 | + * load_ramdisk: | ||
41 | + * Same as load_ramdisk_as(), but doesn't allow the caller to specify | ||
42 | + * an AddressSpace. | ||
43 | + */ | ||
44 | int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz); | ||
45 | |||
46 | ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen); | ||
47 | diff --git a/hw/core/loader.c b/hw/core/loader.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/core/loader.c | ||
50 | +++ b/hw/core/loader.c | ||
51 | @@ -XXX,XX +XXX,XX @@ int load_uimage_as(const char *filename, hwaddr *ep, hwaddr *loadaddr, | ||
52 | |||
53 | /* Load a ramdisk. */ | ||
54 | int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz) | ||
55 | +{ | ||
56 | + return load_ramdisk_as(filename, addr, max_sz, NULL); | ||
57 | +} | ||
58 | + | ||
59 | +int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz, | ||
60 | + AddressSpace *as) | ||
61 | { | 29 | { |
62 | return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK, | 30 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
63 | - NULL, NULL, NULL); | 31 | !guest_addr_valid(addr + size - 1))) { |
64 | + NULL, NULL, as); | 32 | return false; |
33 | } | ||
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; | ||
65 | } | 38 | } |
66 | 39 | ||
67 | /* Load a gzip-compressed kernel to a dynamically allocated buffer. */ | 40 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
68 | -- | 41 | -- |
69 | 2.16.2 | 42 | 2.20.1 |
70 | 43 | ||
71 | 44 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> | 3 | These constants are only ever used with access_ok, and friends. |
4 | Rather than translating them to PAGE_* bits, let them equal | ||
5 | the PAGE_* bits to begin. | ||
6 | |||
7 | Reviewed-by: Warner Losh <imp@bsdimp.com> | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Message-id: 20210212184902.1251044-9-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 12 | --- |
8 | include/hw/arm/xlnx-zynqmp.h | 2 ++ | 13 | bsd-user/qemu.h | 9 ++++----- |
9 | hw/arm/xlnx-zynqmp.c | 14 ++++++++++++++ | 14 | 1 file changed, 4 insertions(+), 5 deletions(-) |
10 | 2 files changed, 16 insertions(+) | ||
11 | 15 | ||
12 | diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h | 16 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h |
13 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/include/hw/arm/xlnx-zynqmp.h | 18 | --- a/bsd-user/qemu.h |
15 | +++ b/include/hw/arm/xlnx-zynqmp.h | 19 | +++ b/bsd-user/qemu.h |
16 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ extern unsigned long x86_stack_size; |
17 | #include "hw/dma/xlnx_dpdma.h" | 21 | |
18 | #include "hw/display/xlnx_dp.h" | 22 | /* user access */ |
19 | #include "hw/intc/xlnx-zynqmp-ipi.h" | 23 | |
20 | +#include "hw/timer/xlnx-zynqmp-rtc.h" | 24 | -#define VERIFY_READ 0 |
21 | 25 | -#define VERIFY_WRITE 1 /* implies read access */ | |
22 | #define TYPE_XLNX_ZYNQMP "xlnx,zynqmp" | 26 | +#define VERIFY_READ PAGE_READ |
23 | #define XLNX_ZYNQMP(obj) OBJECT_CHECK(XlnxZynqMPState, (obj), \ | 27 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
24 | @@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPState { | 28 | |
25 | XlnxDPState dp; | 29 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) |
26 | XlnxDPDMAState dpdma; | 30 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
27 | XlnxZynqMPIPI ipi; | 31 | { |
28 | + XlnxZynqMPRTC rtc; | 32 | - return page_check_range((target_ulong)addr, size, |
29 | 33 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; | |
30 | char *boot_cpu; | 34 | + return page_check_range((target_ulong)addr, size, type) == 0; |
31 | ARMCPU *boot_cpu_ptr; | ||
32 | diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/hw/arm/xlnx-zynqmp.c | ||
35 | +++ b/hw/arm/xlnx-zynqmp.c | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #define IPI_ADDR 0xFF300000 | ||
38 | #define IPI_IRQ 64 | ||
39 | |||
40 | +#define RTC_ADDR 0xffa60000 | ||
41 | +#define RTC_IRQ 26 | ||
42 | + | ||
43 | #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */ | ||
44 | |||
45 | static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = { | ||
46 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj) | ||
47 | |||
48 | object_initialize(&s->ipi, sizeof(s->ipi), TYPE_XLNX_ZYNQMP_IPI); | ||
49 | qdev_set_parent_bus(DEVICE(&s->ipi), sysbus_get_default()); | ||
50 | + | ||
51 | + object_initialize(&s->rtc, sizeof(s->rtc), TYPE_XLNX_ZYNQMP_RTC); | ||
52 | + qdev_set_parent_bus(DEVICE(&s->rtc), sysbus_get_default()); | ||
53 | } | 35 | } |
54 | 36 | ||
55 | static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) | 37 | /* NOTE __get_user and __put_user use host pointers and don't check access. */ |
56 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) | ||
57 | } | ||
58 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR); | ||
59 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]); | ||
60 | + | ||
61 | + object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err); | ||
62 | + if (err) { | ||
63 | + error_propagate(errp, err); | ||
64 | + return; | ||
65 | + } | ||
66 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR); | ||
67 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]); | ||
68 | } | ||
69 | |||
70 | static Property xlnx_zynqmp_props[] = { | ||
71 | -- | 38 | -- |
72 | 2.16.2 | 39 | 2.20.1 |
73 | 40 | ||
74 | 41 | diff view generated by jsdifflib |
1 | Add a Cortex-M33 definition. The M33 is an M profile CPU | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | which implements the ARM v8M architecture, including the | ||
3 | M profile Security Extension. | ||
4 | 2 | ||
3 | This is the only use of guest_addr_valid that does not begin | ||
4 | with a guest address, but a host address being transformed to | ||
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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20180220180325.29818-9-peter.maydell@linaro.org | ||
8 | --- | 16 | --- |
9 | target/arm/cpu.c | 31 +++++++++++++++++++++++++++++++ | 17 | include/exec/cpu_ldst.h | 5 ++++- |
10 | 1 file changed, 31 insertions(+) | 18 | 1 file changed, 4 insertions(+), 1 deletion(-) |
11 | 19 | ||
12 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 20 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
13 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/cpu.c | 22 | --- a/include/exec/cpu_ldst.h |
15 | +++ b/target/arm/cpu.c | 23 | +++ b/include/exec/cpu_ldst.h |
16 | @@ -XXX,XX +XXX,XX @@ static void cortex_m4_initfn(Object *obj) | 24 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
17 | cpu->id_isar5 = 0x00000000; | 25 | #else |
26 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) | ||
27 | #endif | ||
28 | -#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) | ||
29 | |||
30 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) | ||
31 | { | ||
32 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; | ||
18 | } | 33 | } |
19 | 34 | ||
20 | +static void cortex_m33_initfn(Object *obj) | 35 | +#define h2g_valid(x) \ |
21 | +{ | 36 | + (HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS || \ |
22 | + ARMCPU *cpu = ARM_CPU(obj); | 37 | + (uintptr_t)(x) - guest_base <= GUEST_ADDR_MAX) |
23 | + | 38 | + |
24 | + set_feature(&cpu->env, ARM_FEATURE_V8); | 39 | #define h2g_nocheck(x) ({ \ |
25 | + set_feature(&cpu->env, ARM_FEATURE_M); | 40 | uintptr_t __ret = (uintptr_t)(x) - guest_base; \ |
26 | + set_feature(&cpu->env, ARM_FEATURE_M_SECURITY); | 41 | (abi_ptr)__ret; \ |
27 | + set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
28 | + cpu->midr = 0x410fd213; /* r0p3 */ | ||
29 | + cpu->pmsav7_dregion = 16; | ||
30 | + cpu->sau_sregion = 8; | ||
31 | + cpu->id_pfr0 = 0x00000030; | ||
32 | + cpu->id_pfr1 = 0x00000210; | ||
33 | + cpu->id_dfr0 = 0x00200000; | ||
34 | + cpu->id_afr0 = 0x00000000; | ||
35 | + cpu->id_mmfr0 = 0x00101F40; | ||
36 | + cpu->id_mmfr1 = 0x00000000; | ||
37 | + cpu->id_mmfr2 = 0x01000000; | ||
38 | + cpu->id_mmfr3 = 0x00000000; | ||
39 | + cpu->id_isar0 = 0x01101110; | ||
40 | + cpu->id_isar1 = 0x02212000; | ||
41 | + cpu->id_isar2 = 0x20232232; | ||
42 | + cpu->id_isar3 = 0x01111131; | ||
43 | + cpu->id_isar4 = 0x01310132; | ||
44 | + cpu->id_isar5 = 0x00000000; | ||
45 | + cpu->clidr = 0x00000000; | ||
46 | + cpu->ctr = 0x8000c000; | ||
47 | +} | ||
48 | + | ||
49 | static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
50 | { | ||
51 | CPUClass *cc = CPU_CLASS(oc); | ||
52 | @@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_cpus[] = { | ||
53 | .class_init = arm_v7m_class_init }, | ||
54 | { .name = "cortex-m4", .initfn = cortex_m4_initfn, | ||
55 | .class_init = arm_v7m_class_init }, | ||
56 | + { .name = "cortex-m33", .initfn = cortex_m33_initfn, | ||
57 | + .class_init = arm_v7m_class_init }, | ||
58 | { .name = "cortex-r5", .initfn = cortex_r5_initfn }, | ||
59 | { .name = "cortex-a7", .initfn = cortex_a7_initfn }, | ||
60 | { .name = "cortex-a8", .initfn = cortex_a8_initfn }, | ||
61 | -- | 42 | -- |
62 | 2.16.2 | 43 | 2.20.1 |
63 | 44 | ||
64 | 45 | diff view generated by jsdifflib |
1 | The function qdev_init_gpio_in_named() passes the DeviceState pointer | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | as the opaque data pointor for the irq handler function. Usually | ||
3 | this is what you want, but in some cases it would be helpful to use | ||
4 | some other data pointer. | ||
5 | 2 | ||
6 | Add a new function qdev_init_gpio_in_named_with_opaque() which allows | 3 | We must always use GUEST_ADDR_MAX, because even 32-bit hosts can |
7 | the caller to specify the data pointer they want. | 4 | use -R <reserved_va> to restrict the memory address of the guest. |
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-11-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: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20180220180325.29818-12-peter.maydell@linaro.org | ||
13 | --- | 10 | --- |
14 | include/hw/qdev-core.h | 30 ++++++++++++++++++++++++++++-- | 11 | include/exec/cpu_ldst.h | 9 ++++----- |
15 | hw/core/qdev.c | 8 +++++--- | 12 | 1 file changed, 4 insertions(+), 5 deletions(-) |
16 | 2 files changed, 33 insertions(+), 5 deletions(-) | ||
17 | 13 | ||
18 | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/qdev-core.h | 16 | --- a/include/exec/cpu_ldst.h |
21 | +++ b/include/hw/qdev-core.h | 17 | +++ b/include/exec/cpu_ldst.h |
22 | @@ -XXX,XX +XXX,XX @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name); | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
23 | /* GPIO inputs also double as IRQ sinks. */ | 19 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
24 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); | 20 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
25 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | 21 | |
26 | -void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, | 22 | -#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
27 | - const char *name, int n); | 23 | -#define guest_addr_valid(x) (1) |
28 | void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, | 24 | -#else |
29 | const char *name, int n); | 25 | -#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
30 | +/** | 26 | -#endif |
31 | + * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines | 27 | +static inline bool guest_addr_valid(abi_ulong x) |
32 | + * for the specified device | ||
33 | + * | ||
34 | + * @dev: Device to create input GPIOs for | ||
35 | + * @handler: Function to call when GPIO line value is set | ||
36 | + * @opaque: Opaque data pointer to pass to @handler | ||
37 | + * @name: Name of the GPIO input (must be unique for this device) | ||
38 | + * @n: Number of GPIO lines in this input set | ||
39 | + */ | ||
40 | +void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, | ||
41 | + qemu_irq_handler handler, | ||
42 | + void *opaque, | ||
43 | + const char *name, int n); | ||
44 | + | ||
45 | +/** | ||
46 | + * qdev_init_gpio_in_named: create an array of input GPIO lines | ||
47 | + * for the specified device | ||
48 | + * | ||
49 | + * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer | ||
50 | + * passed to the handler is @dev (which is the most commonly desired behaviour). | ||
51 | + */ | ||
52 | +static inline void qdev_init_gpio_in_named(DeviceState *dev, | ||
53 | + qemu_irq_handler handler, | ||
54 | + const char *name, int n) | ||
55 | +{ | 28 | +{ |
56 | + qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n); | 29 | + return x <= GUEST_ADDR_MAX; |
57 | +} | 30 | +} |
58 | 31 | ||
59 | void qdev_pass_gpios(DeviceState *dev, DeviceState *container, | 32 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
60 | const char *name); | ||
61 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/hw/core/qdev.c | ||
64 | +++ b/hw/core/qdev.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev, | ||
66 | return ngl; | ||
67 | } | ||
68 | |||
69 | -void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, | ||
70 | - const char *name, int n) | ||
71 | +void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, | ||
72 | + qemu_irq_handler handler, | ||
73 | + void *opaque, | ||
74 | + const char *name, int n) | ||
75 | { | 33 | { |
76 | int i; | ||
77 | NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name); | ||
78 | |||
79 | assert(gpio_list->num_out == 0 || !name); | ||
80 | gpio_list->in = qemu_extend_irqs(gpio_list->in, gpio_list->num_in, handler, | ||
81 | - dev, n); | ||
82 | + opaque, n); | ||
83 | |||
84 | if (!name) { | ||
85 | name = "unnamed-gpio-in"; | ||
86 | -- | 34 | -- |
87 | 2.16.2 | 35 | 2.20.1 |
88 | 36 | ||
89 | 37 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Allow the translate subroutines to return false for invalid insns. | 3 | Provide an identity fallback for target that do not |
4 | use tagged addresses. | ||
4 | 5 | ||
5 | At present we can of course invoke an invalid insn exception from within | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | the translate subroutine, but in the short term this consolidates code. | ||
7 | In the long term it would allow the decodetree language to support | ||
8 | overlapping patterns for ISA extensions. | ||
9 | |||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Message-id: 20180227232618.2908-1-richard.henderson@linaro.org | 8 | Message-id: 20210212184902.1251044-12-richard.henderson@linaro.org |
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 10 | --- |
15 | scripts/decodetree.py | 5 ++--- | 11 | include/exec/cpu_ldst.h | 7 +++++++ |
16 | 1 file changed, 2 insertions(+), 3 deletions(-) | 12 | 1 file changed, 7 insertions(+) |
17 | 13 | ||
18 | diff --git a/scripts/decodetree.py b/scripts/decodetree.py | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
19 | index XXXXXXX..XXXXXXX 100755 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/scripts/decodetree.py | 16 | --- a/include/exec/cpu_ldst.h |
21 | +++ b/scripts/decodetree.py | 17 | +++ b/include/exec/cpu_ldst.h |
22 | @@ -XXX,XX +XXX,XX @@ class Pattern(General): | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
23 | global translate_prefix | 19 | #define TARGET_ABI_FMT_ptr "%"PRIx64 |
24 | output('typedef ', self.base.base.struct_name(), | 20 | #endif |
25 | ' arg_', self.name, ';\n') | 21 | |
26 | - output(translate_scope, 'void ', translate_prefix, '_', self.name, | 22 | +#ifndef TARGET_TAGGED_ADDRESSES |
27 | + output(translate_scope, 'bool ', translate_prefix, '_', self.name, | 23 | +static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) |
28 | '(DisasContext *ctx, arg_', self.name, | 24 | +{ |
29 | ' *a, ', insntype, ' insn);\n') | 25 | + return x; |
30 | 26 | +} | |
31 | @@ -XXX,XX +XXX,XX @@ class Pattern(General): | 27 | +#endif |
32 | output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n') | 28 | + |
33 | for n, f in self.fields.items(): | 29 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
34 | output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n') | 30 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
35 | - output(ind, translate_prefix, '_', self.name, | ||
36 | + output(ind, 'return ', translate_prefix, '_', self.name, | ||
37 | '(ctx, &u.f_', arg, ', insn);\n') | ||
38 | - output(ind, 'return true;\n') | ||
39 | # end Pattern | ||
40 | |||
41 | 31 | ||
42 | -- | 32 | -- |
43 | 2.16.2 | 33 | 2.20.1 |
44 | 34 | ||
45 | 35 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Not enabled anywhere yet. | 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. | ||
4 | 7 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Use g2h_untagged on values returned from target_mmap, as the |
9 | kernel never applies a tag itself. | ||
10 | |||
11 | Use g2h_untagged on all pc values. The only current user of | ||
12 | tags, aarch64, removes tags from code addresses upon branch, | ||
13 | so "pc" is always untagged. | ||
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> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 20 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20180228193125.20577-11-richard.henderson@linaro.org | 21 | Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 23 | --- |
10 | target/arm/cpu.h | 1 + | 24 | bsd-user/qemu.h | 8 ++-- |
11 | linux-user/elfload.c | 1 + | 25 | include/exec/cpu_ldst.h | 12 +++++- |
12 | 2 files changed, 2 insertions(+) | 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(-) | ||
13 | 45 | ||
14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 46 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.h | 48 | --- a/bsd-user/qemu.h |
17 | +++ b/target/arm/cpu.h | 49 | +++ b/bsd-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 50 | @@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy |
19 | ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | 51 | void *addr; |
20 | ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */ | 52 | addr = g_malloc(len); |
21 | ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | 53 | if (copy) |
22 | + ARM_FEATURE_V8_FCMA, /* has complex number part of v8.3 extensions. */ | 54 | - memcpy(addr, g2h(guest_addr), len); |
23 | }; | 55 | + memcpy(addr, g2h_untagged(guest_addr), len); |
24 | 56 | else | |
25 | static inline int arm_feature(CPUARMState *env, int feature) | 57 | memset(addr, 0, len); |
58 | return addr; | ||
59 | } | ||
60 | #else | ||
61 | - return g2h(guest_addr); | ||
62 | + return g2h_untagged(guest_addr); | ||
63 | #endif | ||
64 | } | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, | ||
67 | #ifdef DEBUG_REMAP | ||
68 | if (!host_ptr) | ||
69 | return; | ||
70 | - if (host_ptr == g2h(guest_addr)) | ||
71 | + if (host_ptr == g2h_untagged(guest_addr)) | ||
72 | return; | ||
73 | if (len > 0) | ||
74 | - memcpy(g2h(guest_addr), host_ptr, len); | ||
75 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
76 | g_free(host_ptr); | ||
77 | #endif | ||
78 | } | ||
79 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/include/exec/cpu_ldst.h | ||
82 | +++ b/include/exec/cpu_ldst.h | ||
83 | @@ -XXX,XX +XXX,XX @@ static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) | ||
84 | #endif | ||
85 | |||
86 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ | ||
87 | -#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) | ||
88 | +static inline void *g2h_untagged(abi_ptr x) | ||
89 | +{ | ||
90 | + return (void *)((uintptr_t)(x) + guest_base); | ||
91 | +} | ||
92 | + | ||
93 | +static inline void *g2h(CPUState *cs, abi_ptr x) | ||
94 | +{ | ||
95 | + return g2h_untagged(cpu_untagged_addr(cs, x)); | ||
96 | +} | ||
97 | |||
98 | static inline bool guest_addr_valid(abi_ulong x) | ||
99 | { | ||
100 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_ldsw_code(CPUArchState *env, abi_ptr addr) | ||
101 | static inline void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, | ||
102 | MMUAccessType access_type, int mmu_idx) | ||
103 | { | ||
104 | - return g2h(addr); | ||
105 | + return g2h(env_cpu(env), addr); | ||
106 | } | ||
107 | #else | ||
108 | void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, | ||
109 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/include/exec/exec-all.h | ||
112 | +++ b/include/exec/exec-all.h | ||
113 | @@ -XXX,XX +XXX,XX @@ static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, | ||
114 | void **hostp) | ||
115 | { | ||
116 | if (hostp) { | ||
117 | - *hostp = g2h(addr); | ||
118 | + *hostp = g2h_untagged(addr); | ||
119 | } | ||
120 | return addr; | ||
121 | } | ||
122 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/linux-user/qemu.h | ||
125 | +++ b/linux-user/qemu.h | ||
126 | @@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy | ||
127 | return addr; | ||
128 | } | ||
129 | #else | ||
130 | - return g2h(guest_addr); | ||
131 | + return g2h_untagged(guest_addr); | ||
132 | #endif | ||
133 | } | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, | ||
136 | #ifdef DEBUG_REMAP | ||
137 | if (!host_ptr) | ||
138 | return; | ||
139 | - if (host_ptr == g2h(guest_addr)) | ||
140 | + if (host_ptr == g2h_untagged(guest_addr)) | ||
141 | return; | ||
142 | if (len > 0) | ||
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 | } | ||
26 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 520 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
27 | index XXXXXXX..XXXXXXX 100644 | 521 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/linux-user/elfload.c | 522 | --- a/linux-user/elfload.c |
29 | +++ b/linux-user/elfload.c | 523 | +++ b/linux-user/elfload.c |
30 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 524 | @@ -XXX,XX +XXX,XX @@ enum { |
31 | GET_FEATURE(ARM_FEATURE_V8_FP16, | 525 | |
32 | ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); | 526 | static bool init_guest_commpage(void) |
33 | GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM); | 527 | { |
34 | + GET_FEATURE(ARM_FEATURE_V8_FCMA, ARM_HWCAP_A64_FCMA); | 528 | - void *want = g2h(ARM_COMMPAGE & -qemu_host_page_size); |
35 | #undef GET_FEATURE | 529 | + void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size); |
36 | 530 | void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, | |
37 | return hwcaps; | 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 | |||
582 | return 0; | ||
583 | } | ||
584 | diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c | ||
585 | index XXXXXXX..XXXXXXX 100644 | ||
586 | --- a/linux-user/hppa/cpu_loop.c | ||
587 | +++ b/linux-user/hppa/cpu_loop.c | ||
588 | @@ -XXX,XX +XXX,XX @@ | ||
589 | |||
590 | static abi_ulong hppa_lws(CPUHPPAState *env) | ||
591 | { | ||
592 | + CPUState *cs = env_cpu(env); | ||
593 | uint32_t which = env->gr[20]; | ||
594 | abi_ulong addr = env->gr[26]; | ||
595 | abi_ulong old = env->gr[25]; | ||
596 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
597 | } | ||
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); | ||
38 | -- | 1173 | -- |
39 | 2.16.2 | 1174 | 2.20.1 |
40 | 1175 | ||
41 | 1176 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Happily, the bits are in the same places compared to a32. | 3 | We define target_mmap et al as untagged, so that they can be |
4 | used from the binary loaders. Explicitly call cpu_untagged_addr | ||
5 | for munmap, mprotect, mremap syscall entry points. | ||
4 | 6 | ||
7 | Add a few comments for the syscalls that are exempted by the | ||
8 | kernel's tagged-address-abi.rst. | ||
9 | |||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20180228193125.20577-16-richard.henderson@linaro.org | 12 | Message-id: 20210212184902.1251044-14-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 14 | --- |
10 | target/arm/translate.c | 14 +++++++++++++- | 15 | linux-user/syscall.c | 11 +++++++++++ |
11 | 1 file changed, 13 insertions(+), 1 deletion(-) | 16 | 1 file changed, 11 insertions(+) |
12 | 17 | ||
13 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 18 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
14 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate.c | 20 | --- a/linux-user/syscall.c |
16 | +++ b/target/arm/translate.c | 21 | +++ b/linux-user/syscall.c |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | 22 | @@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk) |
18 | default_exception_el(s)); | 23 | abi_long mapped_addr; |
19 | break; | 24 | abi_ulong new_alloc_size; |
25 | |||
26 | + /* brk pointers are always untagged */ | ||
27 | + | ||
28 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); | ||
29 | |||
30 | if (!new_brk) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
32 | int i,ret; | ||
33 | abi_ulong shmlba; | ||
34 | |||
35 | + /* shmat pointers are always untagged */ | ||
36 | + | ||
37 | /* find out the length of the shared memory segment */ | ||
38 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); | ||
39 | if (is_error(ret)) { | ||
40 | @@ -XXX,XX +XXX,XX @@ static inline abi_long do_shmdt(abi_ulong shmaddr) | ||
41 | int i; | ||
42 | abi_long rv; | ||
43 | |||
44 | + /* shmdt pointers are always untagged */ | ||
45 | + | ||
46 | mmap_lock(); | ||
47 | |||
48 | for (i = 0; i < N_SHM_REGIONS; ++i) { | ||
49 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
50 | v5, v6)); | ||
20 | } | 51 | } |
21 | - if (((insn >> 24) & 3) == 3) { | 52 | #else |
22 | + if ((insn & 0xfe000a00) == 0xfc000800 | 53 | + /* mmap pointers are always untagged */ |
23 | + && arm_dc_feature(s, ARM_FEATURE_V8)) { | 54 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
24 | + /* The Thumb2 and ARM encodings are identical. */ | 55 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
25 | + if (disas_neon_insn_3same_ext(s, insn)) { | 56 | arg5, |
26 | + goto illegal_op; | 57 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
27 | + } | 58 | return get_errno(ret); |
28 | + } else if ((insn & 0xff000a00) == 0xfe000800 | 59 | #endif |
29 | + && arm_dc_feature(s, ARM_FEATURE_V8)) { | 60 | case TARGET_NR_munmap: |
30 | + /* The Thumb2 and ARM encodings are identical. */ | 61 | + arg1 = cpu_untagged_addr(cpu, arg1); |
31 | + if (disas_neon_insn_2reg_scalar_ext(s, insn)) { | 62 | return get_errno(target_munmap(arg1, arg2)); |
32 | + goto illegal_op; | 63 | case TARGET_NR_mprotect: |
33 | + } | 64 | + arg1 = cpu_untagged_addr(cpu, arg1); |
34 | + } else if (((insn >> 24) & 3) == 3) { | 65 | { |
35 | /* Translate into the equivalent ARM encoding. */ | 66 | TaskState *ts = cpu->opaque; |
36 | insn = (insn & 0xe2ffffff) | ((insn & (1 << 28)) >> 4) | (1 << 28); | 67 | /* Special hack to detect libc making the stack executable. */ |
37 | if (disas_neon_data_insn(s, insn)) { | 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. */ | ||
38 | -- | 77 | -- |
39 | 2.16.2 | 78 | 2.20.1 |
40 | 79 | ||
41 | 80 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | We're currently open-coding the range check in access_ok; |
4 | use guest_range_valid when size != 0. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-9-richard.henderson@linaro.org | 8 | Message-id: 20210212184902.1251044-15-richard.henderson@linaro.org |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- | 11 | linux-user/qemu.h | 9 +++------ |
9 | 1 file changed, 42 insertions(+), 4 deletions(-) | 12 | 1 file changed, 3 insertions(+), 6 deletions(-) |
10 | 13 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 16 | --- a/linux-user/qemu.h |
14 | +++ b/target/arm/translate.c | 17 | +++ b/linux-user/qemu.h |
15 | @@ -XXX,XX +XXX,XX @@ static const char *regnames[] = | 18 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
16 | { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | 19 | |
17 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" }; | 20 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
18 | |||
19 | +/* Function prototypes for gen_ functions calling Neon helpers. */ | ||
20 | +typedef void NeonGenThreeOpEnvFn(TCGv_i32, TCGv_env, TCGv_i32, | ||
21 | + TCGv_i32, TCGv_i32); | ||
22 | + | ||
23 | /* initialize TCG globals. */ | ||
24 | void arm_translate_init(void) | ||
25 | { | 21 | { |
26 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 22 | - if (!guest_addr_valid(addr)) { |
27 | } | 23 | - return false; |
28 | neon_store_reg64(cpu_V0, rd + pass); | 24 | - } |
29 | } | 25 | - if (size != 0 && |
30 | - | 26 | - (addr + size - 1 < addr || |
31 | - | 27 | - !guest_addr_valid(addr + size - 1))) { |
32 | break; | 28 | + if (size == 0 |
33 | - default: /* 14 and 15 are RESERVED */ | 29 | + ? !guest_addr_valid(addr) |
34 | - return 1; | 30 | + : !guest_range_valid(addr, size)) { |
35 | + case 14: /* VQRDMLAH scalar */ | 31 | return false; |
36 | + case 15: /* VQRDMLSH scalar */ | 32 | } |
37 | + { | 33 | return page_check_range((target_ulong)addr, size, type) == 0; |
38 | + NeonGenThreeOpEnvFn *fn; | ||
39 | + | ||
40 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | ||
41 | + return 1; | ||
42 | + } | ||
43 | + if (u && ((rd | rn) & 1)) { | ||
44 | + return 1; | ||
45 | + } | ||
46 | + if (op == 14) { | ||
47 | + if (size == 1) { | ||
48 | + fn = gen_helper_neon_qrdmlah_s16; | ||
49 | + } else { | ||
50 | + fn = gen_helper_neon_qrdmlah_s32; | ||
51 | + } | ||
52 | + } else { | ||
53 | + if (size == 1) { | ||
54 | + fn = gen_helper_neon_qrdmlsh_s16; | ||
55 | + } else { | ||
56 | + fn = gen_helper_neon_qrdmlsh_s32; | ||
57 | + } | ||
58 | + } | ||
59 | + | ||
60 | + tmp2 = neon_get_scalar(size, rm); | ||
61 | + for (pass = 0; pass < (u ? 4 : 2); pass++) { | ||
62 | + tmp = neon_load_reg(rn, pass); | ||
63 | + tmp3 = neon_load_reg(rd, pass); | ||
64 | + fn(tmp, cpu_env, tmp, tmp2, tmp3); | ||
65 | + tcg_temp_free_i32(tmp3); | ||
66 | + neon_store_reg(rd, pass, tmp); | ||
67 | + } | ||
68 | + tcg_temp_free_i32(tmp2); | ||
69 | + } | ||
70 | + break; | ||
71 | + default: | ||
72 | + g_assert_not_reached(); | ||
73 | } | ||
74 | } | ||
75 | } else { /* size == 3 */ | ||
76 | -- | 34 | -- |
77 | 2.16.2 | 35 | 2.20.1 |
78 | 36 | ||
79 | 37 | diff view generated by jsdifflib |
1 | Instead of loading kernels, device trees, and the like to | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | the system address space, use the CPU's address space. This | ||
3 | is important if we're trying to load the file to memory or | ||
4 | via an alias memory region that is provided by an SoC | ||
5 | object and thus not mapped into the system address space. | ||
6 | 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 | ||
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: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180220180325.29818-3-peter.maydell@linaro.org | ||
11 | --- | 11 | --- |
12 | hw/arm/boot.c | 119 +++++++++++++++++++++++++++++++++++++--------------------- | 12 | include/exec/cpu_ldst.h | 4 ++-- |
13 | 1 file changed, 76 insertions(+), 43 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(-) | ||
14 | 18 | ||
15 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | 19 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/arm/boot.c | 21 | --- a/include/exec/cpu_ldst.h |
18 | +++ b/hw/arm/boot.c | 22 | +++ b/include/exec/cpu_ldst.h |
19 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ static inline void *g2h(CPUState *cs, abi_ptr x) |
20 | #define ARM64_TEXT_OFFSET_OFFSET 8 | 24 | return g2h_untagged(cpu_untagged_addr(cs, x)); |
21 | #define ARM64_MAGIC_OFFSET 56 | 25 | } |
22 | 26 | ||
23 | +static AddressSpace *arm_boot_address_space(ARMCPU *cpu, | 27 | -static inline bool guest_addr_valid(abi_ulong x) |
24 | + const struct arm_boot_info *info) | 28 | +static inline bool guest_addr_valid_untagged(abi_ulong x) |
25 | +{ | ||
26 | + /* Return the address space to use for bootloader reads and writes. | ||
27 | + * We prefer the secure address space if the CPU has it and we're | ||
28 | + * going to boot the guest into it. | ||
29 | + */ | ||
30 | + int asidx; | ||
31 | + CPUState *cs = CPU(cpu); | ||
32 | + | ||
33 | + if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && info->secure_boot) { | ||
34 | + asidx = ARMASIdx_S; | ||
35 | + } else { | ||
36 | + asidx = ARMASIdx_NS; | ||
37 | + } | ||
38 | + | ||
39 | + return cpu_get_address_space(cs, asidx); | ||
40 | +} | ||
41 | + | ||
42 | typedef enum { | ||
43 | FIXUP_NONE = 0, /* do nothing */ | ||
44 | FIXUP_TERMINATOR, /* end of insns */ | ||
45 | @@ -XXX,XX +XXX,XX @@ static const ARMInsnFixup smpboot[] = { | ||
46 | }; | ||
47 | |||
48 | static void write_bootloader(const char *name, hwaddr addr, | ||
49 | - const ARMInsnFixup *insns, uint32_t *fixupcontext) | ||
50 | + const ARMInsnFixup *insns, uint32_t *fixupcontext, | ||
51 | + AddressSpace *as) | ||
52 | { | 29 | { |
53 | /* Fix up the specified bootloader fragment and write it into | 30 | return x <= GUEST_ADDR_MAX; |
54 | * guest memory using rom_add_blob_fixed(). fixupcontext is | 31 | } |
55 | @@ -XXX,XX +XXX,XX @@ static void write_bootloader(const char *name, hwaddr addr, | 32 | |
56 | code[i] = tswap32(insn); | 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) | ||
35 | { | ||
36 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; | ||
37 | } | ||
38 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/linux-user/qemu.h | ||
41 | +++ b/linux-user/qemu.h | ||
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; | ||
57 | } | 51 | } |
58 | 52 | return page_check_range((target_ulong)addr, size, type) == 0; | |
59 | - rom_add_blob_fixed(name, code, len * sizeof(uint32_t), addr); | 53 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c |
60 | + rom_add_blob_fixed_as(name, code, len * sizeof(uint32_t), addr, as); | 54 | index XXXXXXX..XXXXXXX 100644 |
61 | 55 | --- a/accel/tcg/user-exec.c | |
62 | g_free(code); | 56 | +++ b/accel/tcg/user-exec.c |
63 | } | 57 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, |
64 | @@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu, | 58 | g_assert_not_reached(); |
65 | const struct arm_boot_info *info) | ||
66 | { | ||
67 | uint32_t fixupcontext[FIXUP_MAX]; | ||
68 | + AddressSpace *as = arm_boot_address_space(cpu, info); | ||
69 | |||
70 | fixupcontext[FIXUP_GIC_CPU_IF] = info->gic_cpu_if_addr; | ||
71 | fixupcontext[FIXUP_BOOTREG] = info->smp_bootreg_addr; | ||
72 | @@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu, | ||
73 | } | 59 | } |
74 | 60 | ||
75 | write_bootloader("smpboot", info->smp_loader_start, | 61 | - if (!guest_addr_valid(addr) || page_check_range(addr, 1, flags) < 0) { |
76 | - smpboot, fixupcontext); | 62 | + if (!guest_addr_valid_untagged(addr) || |
77 | + smpboot, fixupcontext, as); | 63 | + page_check_range(addr, 1, flags) < 0) { |
78 | } | 64 | if (nonfault) { |
79 | 65 | return TLB_INVALID_MASK; | |
80 | void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, | 66 | } else { |
81 | const struct arm_boot_info *info, | 67 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
82 | hwaddr mvbar_addr) | 68 | index XXXXXXX..XXXXXXX 100644 |
83 | { | 69 | --- a/linux-user/mmap.c |
84 | + AddressSpace *as = arm_boot_address_space(cpu, info); | 70 | +++ b/linux-user/mmap.c |
85 | int n; | 71 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) |
86 | uint32_t mvbar_blob[] = { | ||
87 | /* mvbar_addr: secure monitor vectors | ||
88 | @@ -XXX,XX +XXX,XX @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, | ||
89 | for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) { | ||
90 | mvbar_blob[n] = tswap32(mvbar_blob[n]); | ||
91 | } | 72 | } |
92 | - rom_add_blob_fixed("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob), | 73 | len = TARGET_PAGE_ALIGN(len); |
93 | - mvbar_addr); | 74 | end = start + len; |
94 | + rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob), | 75 | - if (!guest_range_valid(start, len)) { |
95 | + mvbar_addr, as); | 76 | + if (!guest_range_valid_untagged(start, len)) { |
96 | 77 | return -TARGET_ENOMEM; | |
97 | for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) { | ||
98 | board_setup_blob[n] = tswap32(board_setup_blob[n]); | ||
99 | } | 78 | } |
100 | - rom_add_blob_fixed("board-setup", board_setup_blob, | 79 | if (len == 0) { |
101 | - sizeof(board_setup_blob), info->board_setup_addr); | 80 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
102 | + rom_add_blob_fixed_as("board-setup", board_setup_blob, | 81 | * It can fail only on 64-bit host with 32-bit target. |
103 | + sizeof(board_setup_blob), info->board_setup_addr, as); | 82 | * On any other target/host host mmap() handles this error correctly. |
104 | } | 83 | */ |
105 | 84 | - if (end < start || !guest_range_valid(start, len)) { | |
106 | static void default_reset_secondary(ARMCPU *cpu, | 85 | + if (end < start || !guest_range_valid_untagged(start, len)) { |
107 | const struct arm_boot_info *info) | 86 | errno = ENOMEM; |
108 | { | 87 | goto fail; |
109 | + AddressSpace *as = arm_boot_address_space(cpu, info); | 88 | } |
110 | CPUState *cs = CPU(cpu); | 89 | @@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len) |
111 | 90 | if (start & ~TARGET_PAGE_MASK) | |
112 | - address_space_stl_notdirty(&address_space_memory, info->smp_bootreg_addr, | 91 | return -TARGET_EINVAL; |
113 | + address_space_stl_notdirty(as, info->smp_bootreg_addr, | 92 | len = TARGET_PAGE_ALIGN(len); |
114 | 0, MEMTXATTRS_UNSPECIFIED, NULL); | 93 | - if (len == 0 || !guest_range_valid(start, len)) { |
115 | cpu_set_pc(cs, info->smp_loader_start); | 94 | + if (len == 0 || !guest_range_valid_untagged(start, len)) { |
116 | } | 95 | return -TARGET_EINVAL; |
117 | @@ -XXX,XX +XXX,XX @@ static inline bool have_dtb(const struct arm_boot_info *info) | ||
118 | } | ||
119 | |||
120 | #define WRITE_WORD(p, value) do { \ | ||
121 | - address_space_stl_notdirty(&address_space_memory, p, value, \ | ||
122 | + address_space_stl_notdirty(as, p, value, \ | ||
123 | MEMTXATTRS_UNSPECIFIED, NULL); \ | ||
124 | p += 4; \ | ||
125 | } while (0) | ||
126 | |||
127 | -static void set_kernel_args(const struct arm_boot_info *info) | ||
128 | +static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as) | ||
129 | { | ||
130 | int initrd_size = info->initrd_size; | ||
131 | hwaddr base = info->loader_start; | ||
132 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info) | ||
133 | int cmdline_size; | ||
134 | |||
135 | cmdline_size = strlen(info->kernel_cmdline); | ||
136 | - cpu_physical_memory_write(p + 8, info->kernel_cmdline, | ||
137 | - cmdline_size + 1); | ||
138 | + address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED, | ||
139 | + (const uint8_t *)info->kernel_cmdline, | ||
140 | + cmdline_size + 1); | ||
141 | cmdline_size = (cmdline_size >> 2) + 1; | ||
142 | WRITE_WORD(p, cmdline_size + 2); | ||
143 | WRITE_WORD(p, 0x54410009); | ||
144 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info) | ||
145 | atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3; | ||
146 | WRITE_WORD(p, (atag_board_len + 8) >> 2); | ||
147 | WRITE_WORD(p, 0x414f4d50); | ||
148 | - cpu_physical_memory_write(p, atag_board_buf, atag_board_len); | ||
149 | + address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, | ||
150 | + atag_board_buf, atag_board_len); | ||
151 | p += atag_board_len; | ||
152 | } | 96 | } |
153 | /* ATAG_END */ | 97 | |
154 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info) | 98 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
155 | WRITE_WORD(p, 0); | 99 | int prot; |
156 | } | 100 | void *host_addr; |
157 | 101 | ||
158 | -static void set_kernel_args_old(const struct arm_boot_info *info) | 102 | - if (!guest_range_valid(old_addr, old_size) || |
159 | +static void set_kernel_args_old(const struct arm_boot_info *info, | 103 | + if (!guest_range_valid_untagged(old_addr, old_size) || |
160 | + AddressSpace *as) | 104 | ((flags & MREMAP_FIXED) && |
161 | { | 105 | - !guest_range_valid(new_addr, new_size)) || |
162 | hwaddr p; | 106 | + !guest_range_valid_untagged(new_addr, new_size)) || |
163 | const char *s; | 107 | ((flags & MREMAP_MAYMOVE) == 0 && |
164 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info) | 108 | - !guest_range_valid(old_addr, new_size))) { |
109 | + !guest_range_valid_untagged(old_addr, new_size))) { | ||
110 | errno = ENOMEM; | ||
111 | return -1; | ||
165 | } | 112 | } |
166 | s = info->kernel_cmdline; | 113 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
167 | if (s) { | 114 | |
168 | - cpu_physical_memory_write(p, s, strlen(s) + 1); | 115 | if (host_addr != MAP_FAILED) { |
169 | + address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, | 116 | /* Check if address fits target address space */ |
170 | + (const uint8_t *)s, strlen(s) + 1); | 117 | - if (!guest_range_valid(h2g(host_addr), new_size)) { |
171 | } else { | 118 | + if (!guest_range_valid_untagged(h2g(host_addr), new_size)) { |
172 | WRITE_WORD(p, 0); | 119 | /* Revert mremap() changes */ |
173 | } | 120 | host_addr = mremap(g2h_untagged(old_addr), |
174 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt) | 121 | new_size, old_size, flags); |
175 | * @addr: the address to load the image at | 122 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
176 | * @binfo: struct describing the boot environment | 123 | index XXXXXXX..XXXXXXX 100644 |
177 | * @addr_limit: upper limit of the available memory area at @addr | 124 | --- a/linux-user/syscall.c |
178 | + * @as: address space to load image to | 125 | +++ b/linux-user/syscall.c |
179 | * | 126 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, |
180 | * Load a device tree supplied by the machine or by the user with the | 127 | return -TARGET_EINVAL; |
181 | * '-dtb' command line option, and put it at offset @addr in target | ||
182 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt) | ||
183 | * Note: Must not be called unless have_dtb(binfo) is true. | ||
184 | */ | ||
185 | static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
186 | - hwaddr addr_limit) | ||
187 | + hwaddr addr_limit, AddressSpace *as) | ||
188 | { | ||
189 | void *fdt = NULL; | ||
190 | int size, rc; | ||
191 | @@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
192 | /* Put the DTB into the memory map as a ROM image: this will ensure | ||
193 | * the DTB is copied again upon reset, even if addr points into RAM. | ||
194 | */ | ||
195 | - rom_add_blob_fixed("dtb", fdt, size, addr); | ||
196 | + rom_add_blob_fixed_as("dtb", fdt, size, addr, as); | ||
197 | |||
198 | g_free(fdt); | ||
199 | |||
200 | @@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque) | ||
201 | } | ||
202 | |||
203 | if (cs == first_cpu) { | ||
204 | + AddressSpace *as = arm_boot_address_space(cpu, info); | ||
205 | + | ||
206 | cpu_set_pc(cs, info->loader_start); | ||
207 | |||
208 | if (!have_dtb(info)) { | ||
209 | if (old_param) { | ||
210 | - set_kernel_args_old(info); | ||
211 | + set_kernel_args_old(info, as); | ||
212 | } else { | ||
213 | - set_kernel_args(info); | ||
214 | + set_kernel_args(info, as); | ||
215 | } | ||
216 | } | ||
217 | } else { | ||
218 | @@ -XXX,XX +XXX,XX @@ static int do_arm_linux_init(Object *obj, void *opaque) | ||
219 | |||
220 | static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, | ||
221 | uint64_t *lowaddr, uint64_t *highaddr, | ||
222 | - int elf_machine) | ||
223 | + int elf_machine, AddressSpace *as) | ||
224 | { | ||
225 | bool elf_is64; | ||
226 | union { | ||
227 | @@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, | ||
228 | } | 128 | } |
229 | } | 129 | } |
230 | 130 | - if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) { | |
231 | - ret = load_elf(info->kernel_filename, NULL, NULL, | 131 | + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { |
232 | - pentry, lowaddr, highaddr, big_endian, elf_machine, | 132 | return -TARGET_EINVAL; |
233 | - 1, data_swab); | ||
234 | + ret = load_elf_as(info->kernel_filename, NULL, NULL, | ||
235 | + pentry, lowaddr, highaddr, big_endian, elf_machine, | ||
236 | + 1, data_swab, as); | ||
237 | if (ret <= 0) { | ||
238 | /* The header loaded but the image didn't */ | ||
239 | exit(1); | ||
240 | @@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, | ||
241 | } | ||
242 | |||
243 | static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, | ||
244 | - hwaddr *entry) | ||
245 | + hwaddr *entry, AddressSpace *as) | ||
246 | { | ||
247 | hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR; | ||
248 | uint8_t *buffer; | ||
249 | @@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, | ||
250 | } | 133 | } |
251 | 134 | ||
252 | *entry = mem_base + kernel_load_offset; | ||
253 | - rom_add_blob_fixed(filename, buffer, size, *entry); | ||
254 | + rom_add_blob_fixed_as(filename, buffer, size, *entry, as); | ||
255 | |||
256 | g_free(buffer); | ||
257 | |||
258 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
259 | ARMCPU *cpu = n->cpu; | ||
260 | struct arm_boot_info *info = | ||
261 | container_of(n, struct arm_boot_info, load_kernel_notifier); | ||
262 | + AddressSpace *as = arm_boot_address_space(cpu, info); | ||
263 | |||
264 | /* The board code is not supposed to set secure_board_setup unless | ||
265 | * running its code in secure mode is actually possible, and KVM | ||
266 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
267 | * the kernel is supposed to be loaded by the bootloader), copy the | ||
268 | * DTB to the base of RAM for the bootloader to pick up. | ||
269 | */ | ||
270 | - if (load_dtb(info->loader_start, info, 0) < 0) { | ||
271 | + if (load_dtb(info->loader_start, info, 0, as) < 0) { | ||
272 | exit(1); | ||
273 | } | ||
274 | } | ||
275 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
276 | |||
277 | /* Assume that raw images are linux kernels, and ELF images are not. */ | ||
278 | kernel_size = arm_load_elf(info, &elf_entry, &elf_low_addr, | ||
279 | - &elf_high_addr, elf_machine); | ||
280 | + &elf_high_addr, elf_machine, as); | ||
281 | if (kernel_size > 0 && have_dtb(info)) { | ||
282 | /* If there is still some room left at the base of RAM, try and put | ||
283 | * the DTB there like we do for images loaded with -bios or -pflash. | ||
284 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
285 | if (elf_low_addr < info->loader_start) { | ||
286 | elf_low_addr = 0; | ||
287 | } | ||
288 | - if (load_dtb(info->loader_start, info, elf_low_addr) < 0) { | ||
289 | + if (load_dtb(info->loader_start, info, elf_low_addr, as) < 0) { | ||
290 | exit(1); | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | entry = elf_entry; | ||
295 | if (kernel_size < 0) { | ||
296 | - kernel_size = load_uimage(info->kernel_filename, &entry, NULL, | ||
297 | - &is_linux, NULL, NULL); | ||
298 | + kernel_size = load_uimage_as(info->kernel_filename, &entry, NULL, | ||
299 | + &is_linux, NULL, NULL, as); | ||
300 | } | ||
301 | if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) { | ||
302 | kernel_size = load_aarch64_image(info->kernel_filename, | ||
303 | - info->loader_start, &entry); | ||
304 | + info->loader_start, &entry, as); | ||
305 | is_linux = 1; | ||
306 | } else if (kernel_size < 0) { | ||
307 | /* 32-bit ARM */ | ||
308 | entry = info->loader_start + KERNEL_LOAD_ADDR; | ||
309 | - kernel_size = load_image_targphys(info->kernel_filename, entry, | ||
310 | - info->ram_size - KERNEL_LOAD_ADDR); | ||
311 | + kernel_size = load_image_targphys_as(info->kernel_filename, entry, | ||
312 | + info->ram_size - KERNEL_LOAD_ADDR, | ||
313 | + as); | ||
314 | is_linux = 1; | ||
315 | } | ||
316 | if (kernel_size < 0) { | ||
317 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
318 | uint32_t fixupcontext[FIXUP_MAX]; | ||
319 | |||
320 | if (info->initrd_filename) { | ||
321 | - initrd_size = load_ramdisk(info->initrd_filename, | ||
322 | - info->initrd_start, | ||
323 | - info->ram_size - | ||
324 | - info->initrd_start); | ||
325 | + initrd_size = load_ramdisk_as(info->initrd_filename, | ||
326 | + info->initrd_start, | ||
327 | + info->ram_size - info->initrd_start, | ||
328 | + as); | ||
329 | if (initrd_size < 0) { | ||
330 | - initrd_size = load_image_targphys(info->initrd_filename, | ||
331 | - info->initrd_start, | ||
332 | - info->ram_size - | ||
333 | - info->initrd_start); | ||
334 | + initrd_size = load_image_targphys_as(info->initrd_filename, | ||
335 | + info->initrd_start, | ||
336 | + info->ram_size - | ||
337 | + info->initrd_start, | ||
338 | + as); | ||
339 | } | ||
340 | if (initrd_size < 0) { | ||
341 | error_report("could not load initrd '%s'", | ||
342 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
343 | |||
344 | /* Place the DTB after the initrd in memory with alignment. */ | ||
345 | dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size, align); | ||
346 | - if (load_dtb(dtb_start, info, 0) < 0) { | ||
347 | + if (load_dtb(dtb_start, info, 0, as) < 0) { | ||
348 | exit(1); | ||
349 | } | ||
350 | fixupcontext[FIXUP_ARGPTR] = dtb_start; | ||
351 | @@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) | ||
352 | fixupcontext[FIXUP_ENTRYPOINT] = entry; | ||
353 | |||
354 | write_bootloader("bootloader", info->loader_start, | ||
355 | - primary_loader, fixupcontext); | ||
356 | + primary_loader, fixupcontext, as); | ||
357 | |||
358 | if (info->nb_cpus > 1) { | ||
359 | info->write_secondary_boot(cpu, info); | ||
360 | -- | 135 | -- |
361 | 2.16.2 | 136 | 2.20.1 |
362 | 137 | ||
363 | 138 | diff view generated by jsdifflib |
1 | Add remaining easy registers to iotkit-secctl: | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | * NSCCFG just routes its two bits out to external GPIO lines | ||
3 | * BRGINSTAT/BRGINTCLR/BRGINTEN can be dummies, because QEMU's | ||
4 | bus fabric can never report errors | ||
5 | 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 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Message-id: 20180220180325.29818-18-peter.maydell@linaro.org | ||
8 | --- | 11 | --- |
9 | include/hw/misc/iotkit-secctl.h | 4 ++++ | 12 | linux-user/qemu.h | 11 +++++++++-- |
10 | hw/misc/iotkit-secctl.c | 32 ++++++++++++++++++++++++++------ | 13 | linux-user/elfload.c | 2 +- |
11 | 2 files changed, 30 insertions(+), 6 deletions(-) | 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(-) | ||
12 | 19 | ||
13 | diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h | 20 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/misc/iotkit-secctl.h | 22 | --- a/linux-user/qemu.h |
16 | +++ b/include/hw/misc/iotkit-secctl.h | 23 | +++ b/linux-user/qemu.h |
17 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
18 | * + sysbus MMIO region 1 is the "non-secure privilege control block" registers | 25 | #define VERIFY_READ PAGE_READ |
19 | * + named GPIO output "sec_resp_cfg" indicating whether blocked accesses | 26 | #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
20 | * should RAZ/WI or bus error | 27 | |
21 | + * + named GPIO output "nsc_cfg" whose value tracks the NSCCFG register value | 28 | -static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
22 | * Controlling the 2 APB PPCs in the IoTKit: | 29 | +static inline bool access_ok_untagged(int type, abi_ulong addr, abi_ulong size) |
23 | * + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec | 30 | { |
24 | * + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap | 31 | if (size == 0 |
25 | @@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl { | 32 | ? !guest_addr_valid_untagged(addr) |
26 | 33 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | |
27 | /*< public >*/ | 34 | return page_check_range((target_ulong)addr, size, type) == 0; |
28 | qemu_irq sec_resp_cfg; | 35 | } |
29 | + qemu_irq nsc_cfg_irq; | 36 | |
30 | 37 | +static inline bool access_ok(CPUState *cpu, int type, | |
31 | MemoryRegion s_regs; | 38 | + abi_ulong addr, abi_ulong size) |
32 | MemoryRegion ns_regs; | 39 | +{ |
33 | @@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl { | 40 | + return access_ok_untagged(type, cpu_untagged_addr(cpu, addr), size); |
34 | uint32_t secppcintstat; | 41 | +} |
35 | uint32_t secppcinten; | 42 | + |
36 | uint32_t secrespcfg; | 43 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
37 | + uint32_t nsccfg; | 44 | These are usually used to access struct data members once the struct has |
38 | + uint32_t brginten; | 45 | been locked - usually with lock_user_struct. */ |
39 | 46 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | |
40 | IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC]; | 47 | host area will have the same contents as the guest. */ |
41 | IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC]; | 48 | static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
42 | diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c | 49 | { |
50 | - if (!access_ok(type, guest_addr, len)) | ||
51 | + if (!access_ok_untagged(type, guest_addr, len)) { | ||
52 | return NULL; | ||
53 | + } | ||
54 | #ifdef DEBUG_REMAP | ||
55 | { | ||
56 | void *addr; | ||
57 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | 58 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/hw/misc/iotkit-secctl.c | 59 | --- a/linux-user/elfload.c |
45 | +++ b/hw/misc/iotkit-secctl.c | 60 | +++ b/linux-user/elfload.c |
46 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | 61 | @@ -XXX,XX +XXX,XX @@ static int vma_get_mapping_count(const struct mm_struct *mm) |
47 | case A_SECRESPCFG: | 62 | static abi_ulong vma_dump_size(const struct vm_area_struct *vma) |
48 | r = s->secrespcfg; | 63 | { |
49 | break; | 64 | /* if we cannot even read the first page, skip it */ |
50 | + case A_NSCCFG: | 65 | - if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) |
51 | + r = s->nsccfg; | 66 | + if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) |
52 | + break; | 67 | return (0); |
53 | case A_SECPPCINTSTAT: | 68 | |
54 | r = s->secppcintstat; | 69 | /* |
55 | break; | 70 | diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c |
56 | case A_SECPPCINTEN: | 71 | index XXXXXXX..XXXXXXX 100644 |
57 | r = s->secppcinten; | 72 | --- a/linux-user/hppa/cpu_loop.c |
58 | break; | 73 | +++ b/linux-user/hppa/cpu_loop.c |
59 | + case A_BRGINTSTAT: | 74 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) |
60 | + /* QEMU's bus fabric can never report errors as it doesn't buffer | 75 | return -TARGET_ENOSYS; |
61 | + * writes, so we never report bridge interrupts. | 76 | |
62 | + */ | 77 | case 0: /* elf32 atomic 32bit cmpxchg */ |
63 | + r = 0; | 78 | - if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) { |
64 | + break; | 79 | + if ((addr & 3) || !access_ok(cs, VERIFY_WRITE, addr, 4)) { |
65 | + case A_BRGINTEN: | 80 | return -TARGET_EFAULT; |
66 | + r = s->brginten; | 81 | } |
67 | + break; | 82 | old = tswap32(old); |
68 | case A_AHBNSPPCEXP0: | 83 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) |
69 | case A_AHBNSPPCEXP1: | 84 | return -TARGET_ENOSYS; |
70 | case A_AHBNSPPCEXP2: | 85 | } |
71 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | 86 | if (((addr | old | new) & ((1 << size) - 1)) |
72 | case A_APBSPPPCEXP3: | 87 | - || !access_ok(VERIFY_WRITE, addr, 1 << size) |
73 | r = s->apbexp[offset_to_ppc_idx(offset)].sp; | 88 | - || !access_ok(VERIFY_READ, old, 1 << size) |
74 | break; | 89 | - || !access_ok(VERIFY_READ, new, 1 << size)) { |
75 | - case A_NSCCFG: | 90 | + || !access_ok(cs, VERIFY_WRITE, addr, 1 << size) |
76 | case A_SECMPCINTSTATUS: | 91 | + || !access_ok(cs, VERIFY_READ, old, 1 << size) |
77 | case A_SECMSCINTSTAT: | 92 | + || !access_ok(cs, VERIFY_READ, new, 1 << size)) { |
78 | case A_SECMSCINTEN: | 93 | return -TARGET_EFAULT; |
79 | - case A_BRGINTSTAT: | 94 | } |
80 | - case A_BRGINTEN: | 95 | /* Note that below we use host-endian loads so that the cmpxchg |
81 | case A_NSMSCEXP: | 96 | diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c |
82 | qemu_log_mask(LOG_UNIMP, | 97 | index XXXXXXX..XXXXXXX 100644 |
83 | "IoTKit SecCtl S block read: " | 98 | --- a/linux-user/i386/cpu_loop.c |
84 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | 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; | ||
85 | } | 107 | } |
86 | 108 | ||
87 | switch (offset) { | 109 | diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c |
88 | + case A_NSCCFG: | 110 | index XXXXXXX..XXXXXXX 100644 |
89 | + s->nsccfg = value & 3; | 111 | --- a/linux-user/i386/signal.c |
90 | + qemu_set_irq(s->nsc_cfg_irq, s->nsccfg); | 112 | +++ b/linux-user/i386/signal.c |
91 | + break; | 113 | @@ -XXX,XX +XXX,XX @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) |
92 | case A_SECRESPCFG: | 114 | |
93 | value &= 1; | 115 | fpstate_addr = tswapl(sc->fpstate); |
94 | s->secrespcfg = value; | 116 | if (fpstate_addr != 0) { |
95 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | 117 | - if (!access_ok(VERIFY_READ, fpstate_addr, |
96 | s->secppcinten = value & 0x00f000f3; | 118 | - sizeof(struct target_fpstate))) |
97 | foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable); | 119 | + if (!access_ok(env_cpu(env), VERIFY_READ, fpstate_addr, |
98 | break; | 120 | + sizeof(struct target_fpstate))) { |
99 | + case A_BRGINTCLR: | 121 | goto badframe; |
100 | + break; | 122 | + } |
101 | + case A_BRGINTEN: | 123 | #ifndef TARGET_X86_64 |
102 | + s->brginten = value & 0xffff0000; | 124 | cpu_x86_frstor(env, fpstate_addr, 1); |
103 | + break; | 125 | #else |
104 | case A_AHBNSPPCEXP0: | 126 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
105 | case A_AHBNSPPCEXP1: | 127 | index XXXXXXX..XXXXXXX 100644 |
106 | case A_AHBNSPPCEXP2: | 128 | --- a/linux-user/syscall.c |
107 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | 129 | +++ b/linux-user/syscall.c |
108 | ppc = &s->apbexp[offset_to_ppc_idx(offset)]; | 130 | @@ -XXX,XX +XXX,XX @@ static abi_long do_accept4(int fd, abi_ulong target_addr, |
109 | iotkit_secctl_ppc_sp_write(ppc, value); | 131 | return -TARGET_EINVAL; |
110 | break; | ||
111 | - case A_NSCCFG: | ||
112 | case A_SECMSCINTCLR: | ||
113 | case A_SECMSCINTEN: | ||
114 | - case A_BRGINTCLR: | ||
115 | - case A_BRGINTEN: | ||
116 | qemu_log_mask(LOG_UNIMP, | ||
117 | "IoTKit SecCtl S block write: " | ||
118 | "unimplemented offset 0x%x\n", offset); | ||
119 | @@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_reset(DeviceState *dev) | ||
120 | s->secppcintstat = 0; | ||
121 | s->secppcinten = 0; | ||
122 | s->secrespcfg = 0; | ||
123 | + s->nsccfg = 0; | ||
124 | + s->brginten = 0; | ||
125 | |||
126 | foreach_ppc(s, iotkit_secctl_reset_ppc); | ||
127 | } | ||
128 | @@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj) | ||
129 | } | 132 | } |
130 | 133 | ||
131 | qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1); | 134 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
132 | + qdev_init_gpio_out_named(dev, &s->nsc_cfg_irq, "nsc_cfg", 1); | 135 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { |
133 | 136 | return -TARGET_EFAULT; | |
134 | memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops, | 137 | + } |
135 | s, "iotkit-secctl-s-regs", 0x1000); | 138 | |
136 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription iotkit_secctl_vmstate = { | 139 | addr = alloca(addrlen); |
137 | VMSTATE_UINT32(secppcintstat, IoTKitSecCtl), | 140 | |
138 | VMSTATE_UINT32(secppcinten, IoTKitSecCtl), | 141 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, |
139 | VMSTATE_UINT32(secrespcfg, IoTKitSecCtl), | 142 | return -TARGET_EINVAL; |
140 | + VMSTATE_UINT32(nsccfg, IoTKitSecCtl), | 143 | } |
141 | + VMSTATE_UINT32(brginten, IoTKitSecCtl), | 144 | |
142 | VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1, | 145 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
143 | iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC), | 146 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { |
144 | VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1, | 147 | return -TARGET_EFAULT; |
148 | + } | ||
149 | |||
150 | addr = alloca(addrlen); | ||
151 | |||
152 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, | ||
153 | return -TARGET_EINVAL; | ||
154 | } | ||
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 | |||
145 | -- | 163 | -- |
146 | 2.16.2 | 164 | 2.20.1 |
147 | 165 | ||
148 | 166 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | These functions are not small, except for unlock_user |
4 | without debugging enabled. Move them out of line, and | ||
5 | add missing braces on the way. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-12-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] | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 13 | --- |
8 | target/arm/helper.h | 7 ++++ | 14 | linux-user/qemu.h | 47 +++++++------------------------------------- |
9 | target/arm/translate-a64.c | 48 ++++++++++++++++++++++- | 15 | linux-user/uaccess.c | 46 +++++++++++++++++++++++++++++++++++++++++++ |
10 | target/arm/vec_helper.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++ | 16 | 2 files changed, 53 insertions(+), 40 deletions(-) |
11 | 3 files changed, 151 insertions(+), 1 deletion(-) | ||
12 | 17 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 18 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 20 | --- a/linux-user/qemu.h |
16 | +++ b/target/arm/helper.h | 21 | +++ b/linux-user/qemu.h |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG, | 22 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
18 | DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG, | 23 | |
19 | void, ptr, ptr, ptr, ptr, i32) | 24 | /* Lock an area of guest memory into the host. If copy is true then the |
20 | 25 | host area will have the same contents as the guest. */ | |
21 | +DEF_HELPER_FLAGS_5(gvec_fcaddh, TCG_CALL_NO_RWG, | 26 | -static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
22 | + void, ptr, ptr, ptr, ptr, i32) | 27 | -{ |
23 | +DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG, | 28 | - if (!access_ok_untagged(type, guest_addr, len)) { |
24 | + void, ptr, ptr, ptr, ptr, i32) | 29 | - return NULL; |
25 | +DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG, | 30 | - } |
26 | + void, ptr, ptr, ptr, ptr, i32) | 31 | -#ifdef DEBUG_REMAP |
27 | + | 32 | - { |
28 | #ifdef TARGET_AARCH64 | 33 | - void *addr; |
29 | #include "helper-a64.h" | 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); | ||
30 | #endif | 67 | #endif |
31 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 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 | ||
32 | index XXXXXXX..XXXXXXX 100644 | 88 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/arm/translate-a64.c | 89 | --- a/linux-user/uaccess.c |
34 | +++ b/target/arm/translate-a64.c | 90 | +++ b/linux-user/uaccess.c |
35 | @@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd, | 91 | @@ -XXX,XX +XXX,XX @@ |
36 | is_q ? 16 : 8, vec_full_reg_size(s), 0, fn); | 92 | |
37 | } | 93 | #include "qemu.h" |
38 | 94 | ||
39 | +/* Expand a 3-operand + fpstatus pointer + simd data value operation using | 95 | +void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
40 | + * an out-of-line helper. | ||
41 | + */ | ||
42 | +static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn, | ||
43 | + int rm, bool is_fp16, int data, | ||
44 | + gen_helper_gvec_3_ptr *fn) | ||
45 | +{ | 96 | +{ |
46 | + TCGv_ptr fpst = get_fpstatus_ptr(is_fp16); | 97 | + if (!access_ok_untagged(type, guest_addr, len)) { |
47 | + tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd), | 98 | + return NULL; |
48 | + vec_full_reg_offset(s, rn), | 99 | + } |
49 | + vec_full_reg_offset(s, rm), fpst, | 100 | +#ifdef DEBUG_REMAP |
50 | + is_q ? 16 : 8, vec_full_reg_size(s), data, fn); | 101 | + { |
51 | + tcg_temp_free_ptr(fpst); | 102 | + void *addr; |
103 | + addr = g_malloc(len); | ||
104 | + if (copy) { | ||
105 | + memcpy(addr, g2h(guest_addr), len); | ||
106 | + } else { | ||
107 | + memset(addr, 0, len); | ||
108 | + } | ||
109 | + return addr; | ||
110 | + } | ||
111 | +#else | ||
112 | + return g2h_untagged(guest_addr); | ||
113 | +#endif | ||
52 | +} | 114 | +} |
53 | + | 115 | + |
54 | /* Set ZF and NF based on a 64 bit result. This is alas fiddlier | 116 | +#ifdef DEBUG_REMAP |
55 | * than the 32 bit equivalent. | 117 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
56 | */ | 118 | +{ |
57 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | 119 | + if (!host_ptr) { |
58 | int size = extract32(insn, 22, 2); | ||
59 | bool u = extract32(insn, 29, 1); | ||
60 | bool is_q = extract32(insn, 30, 1); | ||
61 | - int feature; | ||
62 | + int feature, rot; | ||
63 | |||
64 | switch (u * 16 + opcode) { | ||
65 | case 0x10: /* SQRDMLAH (vector) */ | ||
66 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
67 | } | ||
68 | feature = ARM_FEATURE_V8_RDM; | ||
69 | break; | ||
70 | + case 0xc: /* FCADD, #90 */ | ||
71 | + case 0xe: /* FCADD, #270 */ | ||
72 | + if (size == 0 | ||
73 | + || (size == 1 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) | ||
74 | + || (size == 3 && !is_q)) { | ||
75 | + unallocated_encoding(s); | ||
76 | + return; | ||
77 | + } | ||
78 | + feature = ARM_FEATURE_V8_FCMA; | ||
79 | + break; | ||
80 | default: | ||
81 | unallocated_encoding(s); | ||
82 | return; | ||
83 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
84 | } | ||
85 | return; | ||
86 | |||
87 | + case 0xc: /* FCADD, #90 */ | ||
88 | + case 0xe: /* FCADD, #270 */ | ||
89 | + rot = extract32(opcode, 1, 1); | ||
90 | + switch (size) { | ||
91 | + case 1: | ||
92 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot, | ||
93 | + gen_helper_gvec_fcaddh); | ||
94 | + break; | ||
95 | + case 2: | ||
96 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot, | ||
97 | + gen_helper_gvec_fcadds); | ||
98 | + break; | ||
99 | + case 3: | ||
100 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot, | ||
101 | + gen_helper_gvec_fcaddd); | ||
102 | + break; | ||
103 | + default: | ||
104 | + g_assert_not_reached(); | ||
105 | + } | ||
106 | + return; | 120 | + return; |
107 | + | 121 | + } |
108 | default: | 122 | + if (host_ptr == g2h_untagged(guest_addr)) { |
109 | g_assert_not_reached(); | 123 | + return; |
110 | } | 124 | + } |
111 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 125 | + if (len > 0) { |
112 | index XXXXXXX..XXXXXXX 100644 | 126 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); |
113 | --- a/target/arm/vec_helper.c | 127 | + } |
114 | +++ b/target/arm/vec_helper.c | 128 | + g_free(host_ptr); |
115 | @@ -XXX,XX +XXX,XX @@ | 129 | +} |
116 | #include "exec/exec-all.h" | ||
117 | #include "exec/helper-proto.h" | ||
118 | #include "tcg/tcg-gvec-desc.h" | ||
119 | +#include "fpu/softfloat.h" | ||
120 | |||
121 | |||
122 | +/* Note that vector data is stored in host-endian 64-bit chunks, | ||
123 | + so addressing units smaller than that needs a host-endian fixup. */ | ||
124 | +#ifdef HOST_WORDS_BIGENDIAN | ||
125 | +#define H1(x) ((x) ^ 7) | ||
126 | +#define H2(x) ((x) ^ 3) | ||
127 | +#define H4(x) ((x) ^ 1) | ||
128 | +#else | ||
129 | +#define H1(x) (x) | ||
130 | +#define H2(x) (x) | ||
131 | +#define H4(x) (x) | ||
132 | +#endif | 130 | +#endif |
133 | + | 131 | + |
134 | #define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q | 132 | +void *lock_user_string(abi_ulong guest_addr) |
135 | |||
136 | static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz) | ||
137 | @@ -XXX,XX +XXX,XX @@ void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm, | ||
138 | } | ||
139 | clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
140 | } | ||
141 | + | ||
142 | +void HELPER(gvec_fcaddh)(void *vd, void *vn, void *vm, | ||
143 | + void *vfpst, uint32_t desc) | ||
144 | +{ | 133 | +{ |
145 | + uintptr_t opr_sz = simd_oprsz(desc); | 134 | + abi_long len = target_strlen(guest_addr); |
146 | + float16 *d = vd; | 135 | + if (len < 0) { |
147 | + float16 *n = vn; | 136 | + return NULL; |
148 | + float16 *m = vm; | ||
149 | + float_status *fpst = vfpst; | ||
150 | + uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
151 | + uint32_t neg_imag = neg_real ^ 1; | ||
152 | + uintptr_t i; | ||
153 | + | ||
154 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
155 | + neg_real <<= 15; | ||
156 | + neg_imag <<= 15; | ||
157 | + | ||
158 | + for (i = 0; i < opr_sz / 2; i += 2) { | ||
159 | + float16 e0 = n[H2(i)]; | ||
160 | + float16 e1 = m[H2(i + 1)] ^ neg_imag; | ||
161 | + float16 e2 = n[H2(i + 1)]; | ||
162 | + float16 e3 = m[H2(i)] ^ neg_real; | ||
163 | + | ||
164 | + d[H2(i)] = float16_add(e0, e1, fpst); | ||
165 | + d[H2(i + 1)] = float16_add(e2, e3, fpst); | ||
166 | + } | 137 | + } |
167 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | 138 | + return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
168 | +} | 139 | +} |
169 | + | 140 | + |
170 | +void HELPER(gvec_fcadds)(void *vd, void *vn, void *vm, | 141 | /* copy_from_user() and copy_to_user() are usually used to copy data |
171 | + void *vfpst, uint32_t desc) | 142 | * buffers between the target and host. These internally perform |
172 | +{ | 143 | * locking/unlocking of the memory. |
173 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
174 | + float32 *d = vd; | ||
175 | + float32 *n = vn; | ||
176 | + float32 *m = vm; | ||
177 | + float_status *fpst = vfpst; | ||
178 | + uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
179 | + uint32_t neg_imag = neg_real ^ 1; | ||
180 | + uintptr_t i; | ||
181 | + | ||
182 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
183 | + neg_real <<= 31; | ||
184 | + neg_imag <<= 31; | ||
185 | + | ||
186 | + for (i = 0; i < opr_sz / 4; i += 2) { | ||
187 | + float32 e0 = n[H4(i)]; | ||
188 | + float32 e1 = m[H4(i + 1)] ^ neg_imag; | ||
189 | + float32 e2 = n[H4(i + 1)]; | ||
190 | + float32 e3 = m[H4(i)] ^ neg_real; | ||
191 | + | ||
192 | + d[H4(i)] = float32_add(e0, e1, fpst); | ||
193 | + d[H4(i + 1)] = float32_add(e2, e3, fpst); | ||
194 | + } | ||
195 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
196 | +} | ||
197 | + | ||
198 | +void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm, | ||
199 | + void *vfpst, uint32_t desc) | ||
200 | +{ | ||
201 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
202 | + float64 *d = vd; | ||
203 | + float64 *n = vn; | ||
204 | + float64 *m = vm; | ||
205 | + float_status *fpst = vfpst; | ||
206 | + uint64_t neg_real = extract64(desc, SIMD_DATA_SHIFT, 1); | ||
207 | + uint64_t neg_imag = neg_real ^ 1; | ||
208 | + uintptr_t i; | ||
209 | + | ||
210 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
211 | + neg_real <<= 63; | ||
212 | + neg_imag <<= 63; | ||
213 | + | ||
214 | + for (i = 0; i < opr_sz / 8; i += 2) { | ||
215 | + float64 e0 = n[i]; | ||
216 | + float64 e1 = m[i + 1] ^ neg_imag; | ||
217 | + float64 e2 = n[i + 1]; | ||
218 | + float64 e3 = m[i] ^ neg_real; | ||
219 | + | ||
220 | + d[i] = float64_add(e0, e1, fpst); | ||
221 | + d[i + 1] = float64_add(e2, e3, fpst); | ||
222 | + } | ||
223 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
224 | +} | ||
225 | -- | 144 | -- |
226 | 2.16.2 | 145 | 2.20.1 |
227 | 146 | ||
228 | 147 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
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. | ||
2 | 7 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-6-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] | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 14 | --- |
8 | target/arm/helper.h | 9 +++++ | 15 | linux-user/qemu.h | 12 +++++------- |
9 | target/arm/translate-a64.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ | 16 | linux-user/uaccess.c | 45 ++++++++++++++++++++++---------------------- |
10 | target/arm/vec_helper.c | 74 +++++++++++++++++++++++++++++++++++++++++ | 17 | 2 files changed, 28 insertions(+), 29 deletions(-) |
11 | 3 files changed, 166 insertions(+) | ||
12 | 18 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 19 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 21 | --- a/linux-user/qemu.h |
16 | +++ b/target/arm/helper.h | 22 | +++ b/linux-user/qemu.h |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(dc_zva, void, env, i64) | 23 | @@ -XXX,XX +XXX,XX @@ |
18 | DEF_HELPER_FLAGS_2(neon_pmull_64_lo, TCG_CALL_NO_RWG_SE, i64, i64, i64) | 24 | #include "exec/cpu_ldst.h" |
19 | DEF_HELPER_FLAGS_2(neon_pmull_64_hi, TCG_CALL_NO_RWG_SE, i64, i64, i64) | 25 | |
20 | 26 | #undef DEBUG_REMAP | |
21 | +DEF_HELPER_FLAGS_5(gvec_qrdmlah_s16, TCG_CALL_NO_RWG, | 27 | -#ifdef DEBUG_REMAP |
22 | + void, ptr, ptr, ptr, ptr, i32) | 28 | -#endif /* DEBUG_REMAP */ |
23 | +DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s16, TCG_CALL_NO_RWG, | 29 | |
24 | + void, ptr, ptr, ptr, ptr, i32) | 30 | #include "exec/user/abitypes.h" |
25 | +DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG, | 31 | |
26 | + void, ptr, ptr, ptr, ptr, i32) | 32 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(CPUState *cpu, int type, |
27 | +DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG, | 33 | * buffers between the target and host. These internally perform |
28 | + void, ptr, ptr, ptr, ptr, i32) | 34 | * locking/unlocking of the memory. |
29 | + | 35 | */ |
30 | #ifdef TARGET_AARCH64 | 36 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len); |
31 | #include "helper-a64.h" | 37 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
32 | #endif | 38 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len); |
33 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 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 | ||
34 | index XXXXXXX..XXXXXXX 100644 | 69 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/arm/translate-a64.c | 70 | --- a/linux-user/uaccess.c |
36 | +++ b/target/arm/translate-a64.c | 71 | +++ b/linux-user/uaccess.c |
37 | @@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3(DisasContext *s, bool is_q, int rd, | 72 | @@ -XXX,XX +XXX,XX @@ |
38 | vec_full_reg_size(s), gvec_op); | 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) | ||
39 | } | 82 | } |
40 | 83 | ||
41 | +/* Expand a 3-operand + env pointer operation using | 84 | #ifdef DEBUG_REMAP |
42 | + * an out-of-line helper. | 85 | -void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
43 | + */ | 86 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); |
44 | +static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd, | 87 | { |
45 | + int rn, int rm, gen_helper_gvec_3_ptr *fn) | 88 | if (!host_ptr) { |
46 | +{ | 89 | return; |
47 | + tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd), | 90 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
48 | + vec_full_reg_offset(s, rn), | 91 | if (host_ptr == g2h_untagged(guest_addr)) { |
49 | + vec_full_reg_offset(s, rm), cpu_env, | 92 | return; |
50 | + is_q ? 16 : 8, vec_full_reg_size(s), 0, fn); | 93 | } |
51 | +} | 94 | - if (len > 0) { |
52 | + | 95 | + if (len != 0) { |
53 | /* Set ZF and NF based on a 64 bit result. This is alas fiddlier | 96 | memcpy(g2h_untagged(guest_addr), host_ptr, len); |
54 | * than the 32 bit equivalent. | 97 | } |
98 | g_free(host_ptr); | ||
99 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
100 | |||
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); | ||
110 | } | ||
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. | ||
55 | */ | 115 | */ |
56 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn) | 116 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len) |
57 | clear_vec_high(s, is_q, rd); | 117 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len) |
58 | } | 118 | { |
59 | 119 | - abi_long ret = 0; | |
60 | +/* AdvSIMD three same extra | 120 | - void *ghptr; |
61 | + * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0 | 121 | + int ret = 0; |
62 | + * +---+---+---+-----------+------+---+------+---+--------+---+----+----+ | 122 | + void *ghptr = lock_user(VERIFY_READ, gaddr, len, 1); |
63 | + * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd | | 123 | |
64 | + * +---+---+---+-----------+------+---+------+---+--------+---+----+----+ | 124 | - if ((ghptr = lock_user(VERIFY_READ, gaddr, len, 1))) { |
65 | + */ | 125 | + if (ghptr) { |
66 | +static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | 126 | memcpy(hptr, ghptr, len); |
67 | +{ | 127 | unlock_user(ghptr, gaddr, 0); |
68 | + int rd = extract32(insn, 0, 5); | 128 | - } else |
69 | + int rn = extract32(insn, 5, 5); | 129 | + } else { |
70 | + int opcode = extract32(insn, 11, 4); | 130 | ret = -TARGET_EFAULT; |
71 | + int rm = extract32(insn, 16, 5); | 131 | - |
72 | + int size = extract32(insn, 22, 2); | ||
73 | + bool u = extract32(insn, 29, 1); | ||
74 | + bool is_q = extract32(insn, 30, 1); | ||
75 | + int feature; | ||
76 | + | ||
77 | + switch (u * 16 + opcode) { | ||
78 | + case 0x10: /* SQRDMLAH (vector) */ | ||
79 | + case 0x11: /* SQRDMLSH (vector) */ | ||
80 | + if (size != 1 && size != 2) { | ||
81 | + unallocated_encoding(s); | ||
82 | + return; | ||
83 | + } | ||
84 | + feature = ARM_FEATURE_V8_RDM; | ||
85 | + break; | ||
86 | + default: | ||
87 | + unallocated_encoding(s); | ||
88 | + return; | ||
89 | + } | 132 | + } |
90 | + if (!arm_dc_feature(s, feature)) { | ||
91 | + unallocated_encoding(s); | ||
92 | + return; | ||
93 | + } | ||
94 | + if (!fp_access_check(s)) { | ||
95 | + return; | ||
96 | + } | ||
97 | + | ||
98 | + switch (opcode) { | ||
99 | + case 0x0: /* SQRDMLAH (vector) */ | ||
100 | + switch (size) { | ||
101 | + case 1: | ||
102 | + gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16); | ||
103 | + break; | ||
104 | + case 2: | ||
105 | + gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32); | ||
106 | + break; | ||
107 | + default: | ||
108 | + g_assert_not_reached(); | ||
109 | + } | ||
110 | + return; | ||
111 | + | ||
112 | + case 0x1: /* SQRDMLSH (vector) */ | ||
113 | + switch (size) { | ||
114 | + case 1: | ||
115 | + gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16); | ||
116 | + break; | ||
117 | + case 2: | ||
118 | + gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32); | ||
119 | + break; | ||
120 | + default: | ||
121 | + g_assert_not_reached(); | ||
122 | + } | ||
123 | + return; | ||
124 | + | ||
125 | + default: | ||
126 | + g_assert_not_reached(); | ||
127 | + } | ||
128 | +} | ||
129 | + | ||
130 | static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q, | ||
131 | int size, int rn, int rd) | ||
132 | { | ||
133 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
134 | static const AArch64DecodeTable data_proc_simd[] = { | ||
135 | /* pattern , mask , fn */ | ||
136 | { 0x0e200400, 0x9f200400, disas_simd_three_reg_same }, | ||
137 | + { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra }, | ||
138 | { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff }, | ||
139 | { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc }, | ||
140 | { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes }, | ||
141 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
142 | index XXXXXXX..XXXXXXX 100644 | ||
143 | --- a/target/arm/vec_helper.c | ||
144 | +++ b/target/arm/vec_helper.c | ||
145 | @@ -XXX,XX +XXX,XX @@ | ||
146 | |||
147 | #define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q | ||
148 | |||
149 | +static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz) | ||
150 | +{ | ||
151 | + uint64_t *d = vd + opr_sz; | ||
152 | + uintptr_t i; | ||
153 | + | ||
154 | + for (i = opr_sz; i < max_sz; i += 8) { | ||
155 | + *d++ = 0; | ||
156 | + } | ||
157 | +} | ||
158 | + | ||
159 | /* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */ | ||
160 | static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1, | ||
161 | int16_t src2, int16_t src3) | ||
162 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1, | ||
163 | return deposit32(e1, 16, 16, e2); | ||
164 | } | ||
165 | |||
166 | +void HELPER(gvec_qrdmlah_s16)(void *vd, void *vn, void *vm, | ||
167 | + void *ve, uint32_t desc) | ||
168 | +{ | ||
169 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
170 | + int16_t *d = vd; | ||
171 | + int16_t *n = vn; | ||
172 | + int16_t *m = vm; | ||
173 | + CPUARMState *env = ve; | ||
174 | + uintptr_t i; | ||
175 | + | ||
176 | + for (i = 0; i < opr_sz / 2; ++i) { | ||
177 | + d[i] = inl_qrdmlah_s16(env, n[i], m[i], d[i]); | ||
178 | + } | ||
179 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
180 | +} | ||
181 | + | ||
182 | /* Signed saturating rounding doubling multiply-subtract high half, 16-bit */ | ||
183 | static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1, | ||
184 | int16_t src2, int16_t src3) | ||
185 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1, | ||
186 | return deposit32(e1, 16, 16, e2); | ||
187 | } | ||
188 | |||
189 | +void HELPER(gvec_qrdmlsh_s16)(void *vd, void *vn, void *vm, | ||
190 | + void *ve, uint32_t desc) | ||
191 | +{ | ||
192 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
193 | + int16_t *d = vd; | ||
194 | + int16_t *n = vn; | ||
195 | + int16_t *m = vm; | ||
196 | + CPUARMState *env = ve; | ||
197 | + uintptr_t i; | ||
198 | + | ||
199 | + for (i = 0; i < opr_sz / 2; ++i) { | ||
200 | + d[i] = inl_qrdmlsh_s16(env, n[i], m[i], d[i]); | ||
201 | + } | ||
202 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
203 | +} | ||
204 | + | ||
205 | /* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */ | ||
206 | uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1, | ||
207 | int32_t src2, int32_t src3) | ||
208 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1, | ||
209 | return ret; | 133 | return ret; |
210 | } | 134 | } |
211 | 135 | ||
212 | +void HELPER(gvec_qrdmlah_s32)(void *vd, void *vn, void *vm, | 136 | - |
213 | + void *ve, uint32_t desc) | 137 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len) |
214 | +{ | 138 | +int copy_to_user(abi_ulong gaddr, void *hptr, size_t len) |
215 | + uintptr_t opr_sz = simd_oprsz(desc); | 139 | { |
216 | + int32_t *d = vd; | 140 | - abi_long ret = 0; |
217 | + int32_t *n = vn; | 141 | - void *ghptr; |
218 | + int32_t *m = vm; | 142 | + int ret = 0; |
219 | + CPUARMState *env = ve; | 143 | + void *ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0); |
220 | + uintptr_t i; | 144 | |
221 | + | 145 | - if ((ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0))) { |
222 | + for (i = 0; i < opr_sz / 4; ++i) { | 146 | + if (ghptr) { |
223 | + d[i] = helper_neon_qrdmlah_s32(env, n[i], m[i], d[i]); | 147 | memcpy(ghptr, hptr, len); |
148 | unlock_user(ghptr, gaddr, len); | ||
149 | - } else | ||
150 | + } else { | ||
151 | ret = -TARGET_EFAULT; | ||
224 | + } | 152 | + } |
225 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | 153 | |
226 | +} | ||
227 | + | ||
228 | /* Signed saturating rounding doubling multiply-subtract high half, 32-bit */ | ||
229 | uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1, | ||
230 | int32_t src2, int32_t src3) | ||
231 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1, | ||
232 | } | ||
233 | return ret; | 154 | return ret; |
234 | } | 155 | } |
235 | + | 156 | |
236 | +void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm, | 157 | /* Return the length of a string in target memory or -TARGET_EFAULT if |
237 | + void *ve, uint32_t desc) | 158 | access error */ |
238 | +{ | 159 | -abi_long target_strlen(abi_ulong guest_addr1) |
239 | + uintptr_t opr_sz = simd_oprsz(desc); | 160 | +ssize_t target_strlen(abi_ulong guest_addr1) |
240 | + int32_t *d = vd; | 161 | { |
241 | + int32_t *n = vn; | 162 | uint8_t *ptr; |
242 | + int32_t *m = vm; | 163 | abi_ulong guest_addr; |
243 | + CPUARMState *env = ve; | 164 | - int max_len, len; |
244 | + uintptr_t i; | 165 | + size_t max_len, len; |
245 | + | 166 | |
246 | + for (i = 0; i < opr_sz / 4; ++i) { | 167 | guest_addr = guest_addr1; |
247 | + d[i] = helper_neon_qrdmlsh_s32(env, n[i], m[i], d[i]); | 168 | for(;;) { |
248 | + } | 169 | @@ -XXX,XX +XXX,XX @@ abi_long target_strlen(abi_ulong guest_addr1) |
249 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | 170 | unlock_user(ptr, guest_addr, 0); |
250 | +} | 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 | } | ||
251 | -- | 185 | -- |
252 | 2.16.2 | 186 | 2.20.1 |
253 | 187 | ||
254 | 188 | diff view generated by jsdifflib |
1 | Move the definition of the struct for the unimplemented-device | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | from unimp.c to unimp.h, so that users can embed the struct | ||
3 | in their own device structs if they prefer. | ||
4 | 2 | ||
3 | Resolve the untagged address once, using thread_cpu. | ||
4 | Tidy the DEBUG_REMAP code using glib routines. | ||
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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180220180325.29818-10-peter.maydell@linaro.org | ||
9 | --- | 10 | --- |
10 | include/hw/misc/unimp.h | 10 ++++++++++ | 11 | linux-user/uaccess.c | 27 ++++++++++++++------------- |
11 | hw/misc/unimp.c | 10 ---------- | 12 | 1 file changed, 14 insertions(+), 13 deletions(-) |
12 | 2 files changed, 10 insertions(+), 10 deletions(-) | ||
13 | 13 | ||
14 | diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h | 14 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/hw/misc/unimp.h | 16 | --- a/linux-user/uaccess.c |
17 | +++ b/include/hw/misc/unimp.h | 17 | +++ b/linux-user/uaccess.c |
18 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ |
19 | 19 | ||
20 | #define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device" | 20 | void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) |
21 | 21 | { | |
22 | +#define UNIMPLEMENTED_DEVICE(obj) \ | 22 | + void *host_addr; |
23 | + OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE) | ||
24 | + | 23 | + |
25 | +typedef struct { | 24 | + guest_addr = cpu_untagged_addr(thread_cpu, guest_addr); |
26 | + SysBusDevice parent_obj; | 25 | if (!access_ok_untagged(type, guest_addr, len)) { |
27 | + MemoryRegion iomem; | 26 | return NULL; |
28 | + char *name; | 27 | } |
29 | + uint64_t size; | 28 | + host_addr = g2h_untagged(guest_addr); |
30 | +} UnimplementedDeviceState; | 29 | #ifdef DEBUG_REMAP |
30 | - { | ||
31 | - void *addr; | ||
32 | - addr = g_malloc(len); | ||
33 | - if (copy) { | ||
34 | - memcpy(addr, g2h(guest_addr), len); | ||
35 | - } else { | ||
36 | - memset(addr, 0, len); | ||
37 | - } | ||
38 | - return addr; | ||
39 | + if (copy) { | ||
40 | + host_addr = g_memdup(host_addr, len); | ||
41 | + } else { | ||
42 | + host_addr = g_malloc0(len); | ||
43 | } | ||
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; | ||
31 | + | 54 | + |
32 | /** | 55 | if (!host_ptr) { |
33 | * create_unimplemented_device: create and map a dummy device | 56 | return; |
34 | * @name: name of the device for debug logging | 57 | } |
35 | diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c | 58 | - if (host_ptr == g2h_untagged(guest_addr)) { |
36 | index XXXXXXX..XXXXXXX 100644 | 59 | + host_ptr_conv = g2h(thread_cpu, guest_addr); |
37 | --- a/hw/misc/unimp.c | 60 | + if (host_ptr == host_ptr_conv) { |
38 | +++ b/hw/misc/unimp.c | 61 | return; |
39 | @@ -XXX,XX +XXX,XX @@ | 62 | } |
40 | #include "qemu/log.h" | 63 | if (len != 0) { |
41 | #include "qapi/error.h" | 64 | - memcpy(g2h_untagged(guest_addr), host_ptr, len); |
42 | 65 | + memcpy(host_ptr_conv, host_ptr, len); | |
43 | -#define UNIMPLEMENTED_DEVICE(obj) \ | 66 | } |
44 | - OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE) | 67 | g_free(host_ptr); |
45 | - | 68 | } |
46 | -typedef struct { | ||
47 | - SysBusDevice parent_obj; | ||
48 | - MemoryRegion iomem; | ||
49 | - char *name; | ||
50 | - uint64_t size; | ||
51 | -} UnimplementedDeviceState; | ||
52 | - | ||
53 | static uint64_t unimp_read(void *opaque, hwaddr offset, unsigned size) | ||
54 | { | ||
55 | UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque); | ||
56 | -- | 69 | -- |
57 | 2.16.2 | 70 | 2.20.1 |
58 | 71 | ||
59 | 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 | Not enabled anywhere yet. | 3 | This is the prctl bit that controls whether syscalls accept tagged |
4 | addresses. See Documentation/arm64/tagged-address-abi.rst in the | ||
5 | linux kernel. | ||
4 | 6 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
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: 20180228193125.20577-2-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 | linux-user/elfload.c | 1 + | 13 | target/arm/cpu-param.h | 3 +++ |
13 | 2 files changed, 2 insertions(+) | 14 | target/arm/cpu.h | 31 +++++++++++++++++++++++++++++ |
15 | linux-user/syscall.c | 24 ++++++++++++++++++++++ | ||
16 | 4 files changed, 62 insertions(+) | ||
14 | 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 | ||
15 | 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 |
16 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/cpu.h | 47 | --- a/target/arm/cpu.h |
18 | +++ b/target/arm/cpu.h | 48 | +++ b/target/arm/cpu.h |
19 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 49 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { |
20 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 50 | const struct arm_boot_info *boot_info; |
21 | ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | 51 | /* Store GICv3CPUState to access from this struct */ |
22 | ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | 52 | void *gicv3state; |
23 | + ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */ | 53 | + |
24 | ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | 54 | +#ifdef TARGET_TAGGED_ADDRESSES |
25 | }; | 55 | + /* Linux syscall tagged address support */ |
26 | 56 | + bool tagged_addr_enable; | |
27 | diff --git a/linux-user/elfload.c b/linux-user/elfload.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 | ||
28 | index XXXXXXX..XXXXXXX 100644 | 95 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/linux-user/elfload.c | 96 | --- a/linux-user/syscall.c |
30 | +++ b/linux-user/elfload.c | 97 | +++ b/linux-user/syscall.c |
31 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 98 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
32 | GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); | 99 | } |
33 | GET_FEATURE(ARM_FEATURE_V8_FP16, | 100 | } |
34 | ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); | 101 | return -TARGET_EINVAL; |
35 | + GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM); | 102 | + case TARGET_PR_SET_TAGGED_ADDR_CTRL: |
36 | #undef GET_FEATURE | 103 | + { |
37 | 104 | + abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; | |
38 | return hwcaps; | 105 | + CPUARMState *env = cpu_env; |
106 | + | ||
107 | + if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { | ||
108 | + return -TARGET_EINVAL; | ||
109 | + } | ||
110 | + env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE; | ||
111 | + return 0; | ||
112 | + } | ||
113 | + case TARGET_PR_GET_TAGGED_ADDR_CTRL: | ||
114 | + { | ||
115 | + abi_long ret = 0; | ||
116 | + CPUARMState *env = cpu_env; | ||
117 | + | ||
118 | + if (arg2 || arg3 || arg4 || arg5) { | ||
119 | + return -TARGET_EINVAL; | ||
120 | + } | ||
121 | + if (env->tagged_addr_enable) { | ||
122 | + ret |= TARGET_PR_TAGGED_ADDR_ENABLE; | ||
123 | + } | ||
124 | + return ret; | ||
125 | + } | ||
126 | #endif /* AARCH64 */ | ||
127 | case PR_GET_SECCOMP: | ||
128 | case PR_SET_SECCOMP: | ||
39 | -- | 129 | -- |
40 | 2.16.2 | 130 | 2.20.1 |
41 | 131 | ||
42 | 132 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Use simple arithmetic instead of a conditional | ||
4 | move when tbi0 != tbi1. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Message-id: 20180228193125.20577-13-richard.henderson@linaro.org | 8 | Message-id: 20210212184902.1251044-22-richard.henderson@linaro.org |
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | [PMM: renamed e1/e2/e3/e4 to use the same naming as the version | ||
7 | of the pseudocode in the Arm ARM] | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | 10 | --- |
10 | target/arm/helper.h | 11 ++++ | 11 | target/arm/translate-a64.c | 25 ++++++++++++++----------- |
11 | target/arm/translate-a64.c | 94 +++++++++++++++++++++++++--- | 12 | 1 file changed, 14 insertions(+), 11 deletions(-) |
12 | target/arm/vec_helper.c | 149 +++++++++++++++++++++++++++++++++++++++++++++ | ||
13 | 3 files changed, 246 insertions(+), 8 deletions(-) | ||
14 | 13 | ||
15 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/helper.h | ||
18 | +++ b/target/arm/helper.h | ||
19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG, | ||
20 | DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG, | ||
21 | void, ptr, ptr, ptr, ptr, i32) | ||
22 | |||
23 | +DEF_HELPER_FLAGS_5(gvec_fcmlah, TCG_CALL_NO_RWG, | ||
24 | + void, ptr, ptr, ptr, ptr, i32) | ||
25 | +DEF_HELPER_FLAGS_5(gvec_fcmlah_idx, TCG_CALL_NO_RWG, | ||
26 | + void, ptr, ptr, ptr, ptr, i32) | ||
27 | +DEF_HELPER_FLAGS_5(gvec_fcmlas, TCG_CALL_NO_RWG, | ||
28 | + void, ptr, ptr, ptr, ptr, i32) | ||
29 | +DEF_HELPER_FLAGS_5(gvec_fcmlas_idx, TCG_CALL_NO_RWG, | ||
30 | + void, ptr, ptr, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_5(gvec_fcmlad, TCG_CALL_NO_RWG, | ||
32 | + void, ptr, ptr, ptr, ptr, i32) | ||
33 | + | ||
34 | #ifdef TARGET_AARCH64 | ||
35 | #include "helper-a64.h" | ||
36 | #endif | ||
37 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
38 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/arm/translate-a64.c | 16 | --- a/target/arm/translate-a64.c |
40 | +++ b/target/arm/translate-a64.c | 17 | +++ b/target/arm/translate-a64.c |
41 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst, |
42 | } | 19 | /* Sign-extend from bit 55. */ |
43 | feature = ARM_FEATURE_V8_RDM; | 20 | tcg_gen_sextract_i64(dst, src, 0, 56); |
44 | break; | 21 | |
45 | + case 0x8: /* FCMLA, #0 */ | 22 | - if (tbi != 3) { |
46 | + case 0x9: /* FCMLA, #90 */ | 23 | - TCGv_i64 tcg_zero = tcg_const_i64(0); |
47 | + case 0xa: /* FCMLA, #180 */ | 24 | - |
48 | + case 0xb: /* FCMLA, #270 */ | 25 | - /* |
49 | case 0xc: /* FCADD, #90 */ | 26 | - * The two TBI bits differ. |
50 | case 0xe: /* FCADD, #270 */ | 27 | - * If tbi0, then !tbi1: only use the extension if positive. |
51 | if (size == 0 | 28 | - * if !tbi0, then tbi1: only use the extension if negative. |
52 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | 29 | - */ |
53 | } | 30 | - tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, |
54 | return; | 31 | - dst, dst, tcg_zero, dst, src); |
55 | 32 | - tcg_temp_free_i64(tcg_zero); | |
56 | + case 0x8: /* FCMLA, #0 */ | 33 | + switch (tbi) { |
57 | + case 0x9: /* FCMLA, #90 */ | ||
58 | + case 0xa: /* FCMLA, #180 */ | ||
59 | + case 0xb: /* FCMLA, #270 */ | ||
60 | + rot = extract32(opcode, 0, 2); | ||
61 | + switch (size) { | ||
62 | + case 1: | 34 | + case 1: |
63 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot, | 35 | + /* tbi0 but !tbi1: only use the extension if positive */ |
64 | + gen_helper_gvec_fcmlah); | 36 | + tcg_gen_and_i64(dst, dst, src); |
65 | + break; | 37 | + break; |
66 | + case 2: | 38 | + case 2: |
67 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot, | 39 | + /* !tbi0 but tbi1: only use the extension if negative */ |
68 | + gen_helper_gvec_fcmlas); | 40 | + tcg_gen_or_i64(dst, dst, src); |
69 | + break; | 41 | + break; |
70 | + case 3: | 42 | + case 3: |
71 | + gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot, | 43 | + /* tbi0 and tbi1: always use the extension */ |
72 | + gen_helper_gvec_fcmlad); | ||
73 | + break; | 44 | + break; |
74 | + default: | 45 | + default: |
75 | + g_assert_not_reached(); | 46 | + g_assert_not_reached(); |
76 | + } | ||
77 | + return; | ||
78 | + | ||
79 | case 0xc: /* FCADD, #90 */ | ||
80 | case 0xe: /* FCADD, #270 */ | ||
81 | rot = extract32(opcode, 1, 1); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
83 | int rn = extract32(insn, 5, 5); | ||
84 | int rd = extract32(insn, 0, 5); | ||
85 | bool is_long = false; | ||
86 | - bool is_fp = false; | ||
87 | + int is_fp = 0; | ||
88 | bool is_fp16 = false; | ||
89 | int index; | ||
90 | TCGv_ptr fpst; | ||
91 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
92 | case 0x05: /* FMLS */ | ||
93 | case 0x09: /* FMUL */ | ||
94 | case 0x19: /* FMULX */ | ||
95 | - is_fp = true; | ||
96 | + is_fp = 1; | ||
97 | break; | ||
98 | case 0x1d: /* SQRDMLAH */ | ||
99 | case 0x1f: /* SQRDMLSH */ | ||
100 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
101 | return; | ||
102 | } | 47 | } |
103 | break; | ||
104 | + case 0x11: /* FCMLA #0 */ | ||
105 | + case 0x13: /* FCMLA #90 */ | ||
106 | + case 0x15: /* FCMLA #180 */ | ||
107 | + case 0x17: /* FCMLA #270 */ | ||
108 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)) { | ||
109 | + unallocated_encoding(s); | ||
110 | + return; | ||
111 | + } | ||
112 | + is_fp = 2; | ||
113 | + break; | ||
114 | default: | ||
115 | unallocated_encoding(s); | ||
116 | return; | ||
117 | } | 48 | } |
118 | |||
119 | - if (is_fp) { | ||
120 | + switch (is_fp) { | ||
121 | + case 1: /* normal fp */ | ||
122 | /* convert insn encoded size to TCGMemOp size */ | ||
123 | switch (size) { | ||
124 | case 0: /* half-precision */ | ||
125 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
126 | - unallocated_encoding(s); | ||
127 | - return; | ||
128 | - } | ||
129 | size = MO_16; | ||
130 | + is_fp16 = true; | ||
131 | break; | ||
132 | case MO_32: /* single precision */ | ||
133 | case MO_64: /* double precision */ | ||
134 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
135 | unallocated_encoding(s); | ||
136 | return; | ||
137 | } | ||
138 | - } else { | ||
139 | + break; | ||
140 | + | ||
141 | + case 2: /* complex fp */ | ||
142 | + /* Each indexable element is a complex pair. */ | ||
143 | + size <<= 1; | ||
144 | + switch (size) { | ||
145 | + case MO_32: | ||
146 | + if (h && !is_q) { | ||
147 | + unallocated_encoding(s); | ||
148 | + return; | ||
149 | + } | ||
150 | + is_fp16 = true; | ||
151 | + break; | ||
152 | + case MO_64: | ||
153 | + break; | ||
154 | + default: | ||
155 | + unallocated_encoding(s); | ||
156 | + return; | ||
157 | + } | ||
158 | + break; | ||
159 | + | ||
160 | + default: /* integer */ | ||
161 | switch (size) { | ||
162 | case MO_8: | ||
163 | case MO_64: | ||
164 | unallocated_encoding(s); | ||
165 | return; | ||
166 | } | ||
167 | + break; | ||
168 | + } | ||
169 | + if (is_fp16 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
170 | + unallocated_encoding(s); | ||
171 | + return; | ||
172 | } | ||
173 | |||
174 | /* Given TCGMemOp size, adjust register and indexing. */ | ||
175 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
176 | fpst = NULL; | ||
177 | } | ||
178 | |||
179 | + switch (16 * u + opcode) { | ||
180 | + case 0x11: /* FCMLA #0 */ | ||
181 | + case 0x13: /* FCMLA #90 */ | ||
182 | + case 0x15: /* FCMLA #180 */ | ||
183 | + case 0x17: /* FCMLA #270 */ | ||
184 | + tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd), | ||
185 | + vec_full_reg_offset(s, rn), | ||
186 | + vec_reg_offset(s, rm, index, size), fpst, | ||
187 | + is_q ? 16 : 8, vec_full_reg_size(s), | ||
188 | + extract32(insn, 13, 2), /* rot */ | ||
189 | + size == MO_64 | ||
190 | + ? gen_helper_gvec_fcmlas_idx | ||
191 | + : gen_helper_gvec_fcmlah_idx); | ||
192 | + tcg_temp_free_ptr(fpst); | ||
193 | + return; | ||
194 | + } | ||
195 | + | ||
196 | if (size == 3) { | ||
197 | TCGv_i64 tcg_idx = tcg_temp_new_i64(); | ||
198 | int pass; | ||
199 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
200 | index XXXXXXX..XXXXXXX 100644 | ||
201 | --- a/target/arm/vec_helper.c | ||
202 | +++ b/target/arm/vec_helper.c | ||
203 | @@ -XXX,XX +XXX,XX @@ void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm, | ||
204 | } | ||
205 | clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
206 | } | 49 | } |
207 | + | ||
208 | +void HELPER(gvec_fcmlah)(void *vd, void *vn, void *vm, | ||
209 | + void *vfpst, uint32_t desc) | ||
210 | +{ | ||
211 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
212 | + float16 *d = vd; | ||
213 | + float16 *n = vn; | ||
214 | + float16 *m = vm; | ||
215 | + float_status *fpst = vfpst; | ||
216 | + intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
217 | + uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1); | ||
218 | + uint32_t neg_real = flip ^ neg_imag; | ||
219 | + uintptr_t i; | ||
220 | + | ||
221 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
222 | + neg_real <<= 15; | ||
223 | + neg_imag <<= 15; | ||
224 | + | ||
225 | + for (i = 0; i < opr_sz / 2; i += 2) { | ||
226 | + float16 e2 = n[H2(i + flip)]; | ||
227 | + float16 e1 = m[H2(i + flip)] ^ neg_real; | ||
228 | + float16 e4 = e2; | ||
229 | + float16 e3 = m[H2(i + 1 - flip)] ^ neg_imag; | ||
230 | + | ||
231 | + d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst); | ||
232 | + d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst); | ||
233 | + } | ||
234 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
235 | +} | ||
236 | + | ||
237 | +void HELPER(gvec_fcmlah_idx)(void *vd, void *vn, void *vm, | ||
238 | + void *vfpst, uint32_t desc) | ||
239 | +{ | ||
240 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
241 | + float16 *d = vd; | ||
242 | + float16 *n = vn; | ||
243 | + float16 *m = vm; | ||
244 | + float_status *fpst = vfpst; | ||
245 | + intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
246 | + uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1); | ||
247 | + uint32_t neg_real = flip ^ neg_imag; | ||
248 | + uintptr_t i; | ||
249 | + float16 e1 = m[H2(flip)]; | ||
250 | + float16 e3 = m[H2(1 - flip)]; | ||
251 | + | ||
252 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
253 | + neg_real <<= 15; | ||
254 | + neg_imag <<= 15; | ||
255 | + e1 ^= neg_real; | ||
256 | + e3 ^= neg_imag; | ||
257 | + | ||
258 | + for (i = 0; i < opr_sz / 2; i += 2) { | ||
259 | + float16 e2 = n[H2(i + flip)]; | ||
260 | + float16 e4 = e2; | ||
261 | + | ||
262 | + d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst); | ||
263 | + d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst); | ||
264 | + } | ||
265 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
266 | +} | ||
267 | + | ||
268 | +void HELPER(gvec_fcmlas)(void *vd, void *vn, void *vm, | ||
269 | + void *vfpst, uint32_t desc) | ||
270 | +{ | ||
271 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
272 | + float32 *d = vd; | ||
273 | + float32 *n = vn; | ||
274 | + float32 *m = vm; | ||
275 | + float_status *fpst = vfpst; | ||
276 | + intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
277 | + uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1); | ||
278 | + uint32_t neg_real = flip ^ neg_imag; | ||
279 | + uintptr_t i; | ||
280 | + | ||
281 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
282 | + neg_real <<= 31; | ||
283 | + neg_imag <<= 31; | ||
284 | + | ||
285 | + for (i = 0; i < opr_sz / 4; i += 2) { | ||
286 | + float32 e2 = n[H4(i + flip)]; | ||
287 | + float32 e1 = m[H4(i + flip)] ^ neg_real; | ||
288 | + float32 e4 = e2; | ||
289 | + float32 e3 = m[H4(i + 1 - flip)] ^ neg_imag; | ||
290 | + | ||
291 | + d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst); | ||
292 | + d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst); | ||
293 | + } | ||
294 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
295 | +} | ||
296 | + | ||
297 | +void HELPER(gvec_fcmlas_idx)(void *vd, void *vn, void *vm, | ||
298 | + void *vfpst, uint32_t desc) | ||
299 | +{ | ||
300 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
301 | + float32 *d = vd; | ||
302 | + float32 *n = vn; | ||
303 | + float32 *m = vm; | ||
304 | + float_status *fpst = vfpst; | ||
305 | + intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
306 | + uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1); | ||
307 | + uint32_t neg_real = flip ^ neg_imag; | ||
308 | + uintptr_t i; | ||
309 | + float32 e1 = m[H4(flip)]; | ||
310 | + float32 e3 = m[H4(1 - flip)]; | ||
311 | + | ||
312 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
313 | + neg_real <<= 31; | ||
314 | + neg_imag <<= 31; | ||
315 | + e1 ^= neg_real; | ||
316 | + e3 ^= neg_imag; | ||
317 | + | ||
318 | + for (i = 0; i < opr_sz / 4; i += 2) { | ||
319 | + float32 e2 = n[H4(i + flip)]; | ||
320 | + float32 e4 = e2; | ||
321 | + | ||
322 | + d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst); | ||
323 | + d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst); | ||
324 | + } | ||
325 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
326 | +} | ||
327 | + | ||
328 | +void HELPER(gvec_fcmlad)(void *vd, void *vn, void *vm, | ||
329 | + void *vfpst, uint32_t desc) | ||
330 | +{ | ||
331 | + uintptr_t opr_sz = simd_oprsz(desc); | ||
332 | + float64 *d = vd; | ||
333 | + float64 *n = vn; | ||
334 | + float64 *m = vm; | ||
335 | + float_status *fpst = vfpst; | ||
336 | + intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1); | ||
337 | + uint64_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1); | ||
338 | + uint64_t neg_real = flip ^ neg_imag; | ||
339 | + uintptr_t i; | ||
340 | + | ||
341 | + /* Shift boolean to the sign bit so we can xor to negate. */ | ||
342 | + neg_real <<= 63; | ||
343 | + neg_imag <<= 63; | ||
344 | + | ||
345 | + for (i = 0; i < opr_sz / 8; i += 2) { | ||
346 | + float64 e2 = n[i + flip]; | ||
347 | + float64 e1 = m[i + flip] ^ neg_real; | ||
348 | + float64 e4 = e2; | ||
349 | + float64 e3 = m[i + 1 - flip] ^ neg_imag; | ||
350 | + | ||
351 | + d[i] = float64_muladd(e2, e1, d[i], 0, fpst); | ||
352 | + d[i + 1] = float64_muladd(e4, e3, d[i + 1], 0, fpst); | ||
353 | + } | ||
354 | + clear_tail(d, opr_sz, simd_maxsz(desc)); | ||
355 | +} | ||
356 | -- | 50 | -- |
357 | 2.16.2 | 51 | 2.20.1 |
358 | 52 | ||
359 | 53 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Enable it for the "any" CPU used by *-linux-user. | 3 | We were fudging TBI1 enabled to speed up the generated code. |
4 | Now that we've improved the code generation, remove this. | ||
5 | Also, tidy the comment to reflect the current code. | ||
4 | 6 | ||
7 | The pauth test was testing a kernel address (-1) and making | ||
8 | incorrect assumptions about TBI1; stick to userland addresses. | ||
9 | |||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Message-id: 20210212184902.1251044-23-richard.henderson@linaro.org |
7 | Message-id: 20180228193125.20577-17-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 14 | --- |
10 | target/arm/cpu.c | 1 + | 15 | target/arm/internals.h | 4 ++-- |
11 | target/arm/cpu64.c | 1 + | 16 | target/arm/cpu.c | 10 +++------- |
12 | 2 files changed, 2 insertions(+) | 17 | tests/tcg/aarch64/pauth-2.c | 1 - |
18 | 3 files changed, 5 insertions(+), 10 deletions(-) | ||
13 | 19 | ||
20 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/internals.h | ||
23 | +++ b/target/arm/internals.h | ||
24 | @@ -XXX,XX +XXX,XX @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag) | ||
25 | */ | ||
26 | static inline uint64_t useronly_clean_ptr(uint64_t ptr) | ||
27 | { | ||
28 | - /* TBI is known to be enabled. */ | ||
29 | #ifdef CONFIG_USER_ONLY | ||
30 | - ptr = sextract64(ptr, 0, 56); | ||
31 | + /* TBI0 is known to be enabled, while TBI1 is disabled. */ | ||
32 | + ptr &= sextract64(ptr, 0, 56); | ||
33 | #endif | ||
34 | return ptr; | ||
35 | } | ||
14 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 36 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.c | 38 | --- a/target/arm/cpu.c |
17 | +++ b/target/arm/cpu.c | 39 | +++ b/target/arm/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj) | 40 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
19 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 41 | env->vfp.zcr_el[1] = MIN(cpu->sve_max_vq - 1, 3); |
20 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 42 | } |
21 | set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | 43 | /* |
22 | + set_feature(&cpu->env, ARM_FEATURE_V8_FCMA); | 44 | - * Enable TBI0 and TBI1. While the real kernel only enables TBI0, |
23 | cpu->midr = 0xffffffff; | 45 | - * turning on both here will produce smaller code and otherwise |
24 | } | 46 | - * make no difference to the user-level emulation. |
25 | #endif | 47 | - * |
26 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 48 | - * In sve_probe_page, we assume that this is set. |
49 | - * Do not modify this without other changes. | ||
50 | + * Enable TBI0 but not TBI1. | ||
51 | + * Note that this must match useronly_clean_ptr. | ||
52 | */ | ||
53 | - env->cp15.tcr_el[1].raw_tcr = (3ULL << 37); | ||
54 | + env->cp15.tcr_el[1].raw_tcr = (1ULL << 37); | ||
55 | #else | ||
56 | /* Reset into the highest available EL */ | ||
57 | if (arm_feature(env, ARM_FEATURE_EL3)) { | ||
58 | diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/arm/cpu64.c | 60 | --- a/tests/tcg/aarch64/pauth-2.c |
29 | +++ b/target/arm/cpu64.c | 61 | +++ b/tests/tcg/aarch64/pauth-2.c |
30 | @@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj) | 62 | @@ -XXX,XX +XXX,XX @@ void do_test(uint64_t value) |
31 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 63 | int main() |
32 | set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | 64 | { |
33 | set_feature(&cpu->env, ARM_FEATURE_V8_FP16); | 65 | do_test(0); |
34 | + set_feature(&cpu->env, ARM_FEATURE_V8_FCMA); | 66 | - do_test(-1); |
35 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | 67 | do_test(0xda004acedeadbeefull); |
36 | cpu->dcz_blocksize = 7; /* 512 bytes */ | 68 | return 0; |
37 | } | 69 | } |
38 | -- | 70 | -- |
39 | 2.16.2 | 71 | 2.20.1 |
40 | 72 | ||
41 | 73 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Include the U bit in the switches rather than testing separately. | 3 | These prctl fields are required for the function of MTE. |
4 | 4 | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Message-id: 20210212184902.1251044-24-richard.henderson@linaro.org |
7 | Message-id: 20180228193125.20577-3-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 9 | --- |
10 | target/arm/translate-a64.c | 129 +++++++++++++++++++++------------------------ | 10 | linux-user/aarch64/target_syscall.h | 9 ++++++ |
11 | 1 file changed, 61 insertions(+), 68 deletions(-) | 11 | linux-user/syscall.c | 43 +++++++++++++++++++++++++++++ |
12 | 2 files changed, 52 insertions(+) | ||
12 | 13 | ||
13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 14 | diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate-a64.c | 16 | --- a/linux-user/aarch64/target_syscall.h |
16 | +++ b/target/arm/translate-a64.c | 17 | +++ b/linux-user/aarch64/target_syscall.h |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ struct target_pt_regs { |
18 | int index; | 19 | #define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 |
19 | TCGv_ptr fpst; | 20 | #define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 |
20 | 21 | # define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) | |
21 | - switch (opcode) { | 22 | +/* MTE tag check fault modes */ |
22 | - case 0x0: /* MLA */ | 23 | +# define TARGET_PR_MTE_TCF_SHIFT 1 |
23 | - case 0x4: /* MLS */ | 24 | +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) |
24 | - if (!u || is_scalar) { | 25 | +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) |
25 | + switch (16 * u + opcode) { | 26 | +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) |
26 | + case 0x08: /* MUL */ | 27 | +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) |
27 | + case 0x10: /* MLA */ | 28 | +/* MTE tag inclusion mask */ |
28 | + case 0x14: /* MLS */ | 29 | +# define TARGET_PR_MTE_TAG_SHIFT 3 |
29 | + if (is_scalar) { | 30 | +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT) |
30 | unallocated_encoding(s); | 31 | |
31 | return; | 32 | #endif /* AARCH64_TARGET_SYSCALL_H */ |
32 | } | 33 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
33 | break; | 34 | index XXXXXXX..XXXXXXX 100644 |
34 | - case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */ | 35 | --- a/linux-user/syscall.c |
35 | - case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */ | 36 | +++ b/linux-user/syscall.c |
36 | - case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */ | 37 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
37 | + case 0x02: /* SMLAL, SMLAL2 */ | ||
38 | + case 0x12: /* UMLAL, UMLAL2 */ | ||
39 | + case 0x06: /* SMLSL, SMLSL2 */ | ||
40 | + case 0x16: /* UMLSL, UMLSL2 */ | ||
41 | + case 0x0a: /* SMULL, SMULL2 */ | ||
42 | + case 0x1a: /* UMULL, UMULL2 */ | ||
43 | if (is_scalar) { | ||
44 | unallocated_encoding(s); | ||
45 | return; | ||
46 | } | ||
47 | is_long = true; | ||
48 | break; | ||
49 | - case 0x3: /* SQDMLAL, SQDMLAL2 */ | ||
50 | - case 0x7: /* SQDMLSL, SQDMLSL2 */ | ||
51 | - case 0xb: /* SQDMULL, SQDMULL2 */ | ||
52 | + case 0x03: /* SQDMLAL, SQDMLAL2 */ | ||
53 | + case 0x07: /* SQDMLSL, SQDMLSL2 */ | ||
54 | + case 0x0b: /* SQDMULL, SQDMULL2 */ | ||
55 | is_long = true; | ||
56 | - /* fall through */ | ||
57 | - case 0xc: /* SQDMULH */ | ||
58 | - case 0xd: /* SQRDMULH */ | ||
59 | - if (u) { | ||
60 | - unallocated_encoding(s); | ||
61 | - return; | ||
62 | - } | ||
63 | break; | ||
64 | - case 0x8: /* MUL */ | ||
65 | - if (u || is_scalar) { | ||
66 | - unallocated_encoding(s); | ||
67 | - return; | ||
68 | - } | ||
69 | + case 0x0c: /* SQDMULH */ | ||
70 | + case 0x0d: /* SQRDMULH */ | ||
71 | break; | ||
72 | - case 0x1: /* FMLA */ | ||
73 | - case 0x5: /* FMLS */ | ||
74 | - if (u) { | ||
75 | - unallocated_encoding(s); | ||
76 | - return; | ||
77 | - } | ||
78 | - /* fall through */ | ||
79 | - case 0x9: /* FMUL, FMULX */ | ||
80 | + case 0x01: /* FMLA */ | ||
81 | + case 0x05: /* FMLS */ | ||
82 | + case 0x09: /* FMUL */ | ||
83 | + case 0x19: /* FMULX */ | ||
84 | if (size == 1) { | ||
85 | unallocated_encoding(s); | ||
86 | return; | ||
87 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
88 | |||
89 | read_vec_element(s, tcg_op, rn, pass, MO_64); | ||
90 | |||
91 | - switch (opcode) { | ||
92 | - case 0x5: /* FMLS */ | ||
93 | + switch (16 * u + opcode) { | ||
94 | + case 0x05: /* FMLS */ | ||
95 | /* As usual for ARM, separate negation for fused multiply-add */ | ||
96 | gen_helper_vfp_negd(tcg_op, tcg_op); | ||
97 | /* fall through */ | ||
98 | - case 0x1: /* FMLA */ | ||
99 | + case 0x01: /* FMLA */ | ||
100 | read_vec_element(s, tcg_res, rd, pass, MO_64); | ||
101 | gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst); | ||
102 | break; | ||
103 | - case 0x9: /* FMUL, FMULX */ | ||
104 | - if (u) { | ||
105 | - gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst); | ||
106 | - } else { | ||
107 | - gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst); | ||
108 | - } | ||
109 | + case 0x09: /* FMUL */ | ||
110 | + gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst); | ||
111 | + break; | ||
112 | + case 0x19: /* FMULX */ | ||
113 | + gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst); | ||
114 | break; | ||
115 | default: | ||
116 | g_assert_not_reached(); | ||
117 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
118 | |||
119 | read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32); | ||
120 | |||
121 | - switch (opcode) { | ||
122 | - case 0x0: /* MLA */ | ||
123 | - case 0x4: /* MLS */ | ||
124 | - case 0x8: /* MUL */ | ||
125 | + switch (16 * u + opcode) { | ||
126 | + case 0x08: /* MUL */ | ||
127 | + case 0x10: /* MLA */ | ||
128 | + case 0x14: /* MLS */ | ||
129 | { | 38 | { |
130 | static NeonGenTwoOpFn * const fns[2][2] = { | 39 | abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; |
131 | { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 }, | 40 | CPUARMState *env = cpu_env; |
132 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 41 | + ARMCPU *cpu = env_archcpu(env); |
133 | genfn(tcg_res, tcg_op, tcg_res); | 42 | + |
134 | break; | 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; | ||
135 | } | 82 | } |
136 | - case 0x5: /* FMLS */ | 83 | case TARGET_PR_GET_TAGGED_ADDR_CTRL: |
137 | - case 0x1: /* FMLA */ | 84 | { |
138 | + case 0x05: /* FMLS */ | 85 | abi_long ret = 0; |
139 | + case 0x01: /* FMLA */ | 86 | CPUARMState *env = cpu_env; |
140 | read_vec_element_i32(s, tcg_res, rd, pass, | 87 | + ARMCPU *cpu = env_archcpu(env); |
141 | is_scalar ? size : MO_32); | 88 | |
142 | switch (size) { | 89 | if (arg2 || arg3 || arg4 || arg5) { |
143 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 90 | return -TARGET_EINVAL; |
144 | g_assert_not_reached(); | 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; | ||
145 | } | 94 | } |
146 | break; | 95 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
147 | - case 0x9: /* FMUL, FMULX */ | 96 | + /* See above. */ |
148 | + case 0x09: /* FMUL */ | 97 | + ret |= (extract64(env->cp15.sctlr_el[1], 38, 2) |
149 | switch (size) { | 98 | + << TARGET_PR_MTE_TCF_SHIFT); |
150 | case 1: | 99 | + ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16, |
151 | - if (u) { | 100 | + ~env->cp15.gcr_el1); |
152 | - if (is_scalar) { | ||
153 | - gen_helper_advsimd_mulxh(tcg_res, tcg_op, | ||
154 | - tcg_idx, fpst); | ||
155 | - } else { | ||
156 | - gen_helper_advsimd_mulx2h(tcg_res, tcg_op, | ||
157 | - tcg_idx, fpst); | ||
158 | - } | ||
159 | + if (is_scalar) { | ||
160 | + gen_helper_advsimd_mulh(tcg_res, tcg_op, | ||
161 | + tcg_idx, fpst); | ||
162 | } else { | ||
163 | - if (is_scalar) { | ||
164 | - gen_helper_advsimd_mulh(tcg_res, tcg_op, | ||
165 | - tcg_idx, fpst); | ||
166 | - } else { | ||
167 | - gen_helper_advsimd_mul2h(tcg_res, tcg_op, | ||
168 | - tcg_idx, fpst); | ||
169 | - } | ||
170 | + gen_helper_advsimd_mul2h(tcg_res, tcg_op, | ||
171 | + tcg_idx, fpst); | ||
172 | } | ||
173 | break; | ||
174 | case 2: | ||
175 | - if (u) { | ||
176 | - gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst); | ||
177 | - } else { | ||
178 | - gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst); | ||
179 | - } | ||
180 | + gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst); | ||
181 | break; | ||
182 | default: | ||
183 | g_assert_not_reached(); | ||
184 | } | ||
185 | break; | ||
186 | - case 0xc: /* SQDMULH */ | ||
187 | + case 0x19: /* FMULX */ | ||
188 | + switch (size) { | ||
189 | + case 1: | ||
190 | + if (is_scalar) { | ||
191 | + gen_helper_advsimd_mulxh(tcg_res, tcg_op, | ||
192 | + tcg_idx, fpst); | ||
193 | + } else { | ||
194 | + gen_helper_advsimd_mulx2h(tcg_res, tcg_op, | ||
195 | + tcg_idx, fpst); | ||
196 | + } | ||
197 | + break; | ||
198 | + case 2: | ||
199 | + gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst); | ||
200 | + break; | ||
201 | + default: | ||
202 | + g_assert_not_reached(); | ||
203 | + } | 101 | + } |
204 | + break; | 102 | return ret; |
205 | + case 0x0c: /* SQDMULH */ | 103 | } |
206 | if (size == 1) { | 104 | #endif /* AARCH64 */ |
207 | gen_helper_neon_qdmulh_s16(tcg_res, cpu_env, | ||
208 | tcg_op, tcg_idx); | ||
209 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
210 | tcg_op, tcg_idx); | ||
211 | } | ||
212 | break; | ||
213 | - case 0xd: /* SQRDMULH */ | ||
214 | + case 0x0d: /* SQRDMULH */ | ||
215 | if (size == 1) { | ||
216 | gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env, | ||
217 | tcg_op, tcg_idx); | ||
218 | -- | 105 | -- |
219 | 2.16.2 | 106 | 2.20.1 |
220 | 107 | ||
221 | 108 | diff view generated by jsdifflib |
1 | The Cortex-M33 allows the system to specify the reset value of the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | secure Vector Table Offset Register (VTOR) by asserting config | ||
3 | signals. In particular, guest images for the MPS2 AN505 board rely | ||
4 | on the MPS2's initial VTOR being correct for that board. | ||
5 | Implement a QEMU property so board and SoC code can set the reset | ||
6 | value to the correct value. | ||
7 | 2 | ||
3 | Remember the PROT_MTE bit as PAGE_MTE/PAGE_TARGET_2. | ||
4 | Otherwise this does not yet have effect. | ||
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-25-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180220180325.29818-7-peter.maydell@linaro.org | ||
11 | --- | 10 | --- |
12 | target/arm/cpu.h | 3 +++ | 11 | include/exec/cpu-all.h | 1 + |
13 | target/arm/cpu.c | 18 ++++++++++++++---- | 12 | linux-user/syscall_defs.h | 1 + |
14 | 2 files changed, 17 insertions(+), 4 deletions(-) | 13 | target/arm/cpu.h | 1 + |
14 | linux-user/mmap.c | 22 ++++++++++++++-------- | ||
15 | 4 files changed, 17 insertions(+), 8 deletions(-) | ||
15 | 16 | ||
17 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/exec/cpu-all.h | ||
20 | +++ b/include/exec/cpu-all.h | ||
21 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; | ||
22 | #endif | ||
23 | /* Target-specific bits that will be used via page_get_flags(). */ | ||
24 | #define PAGE_TARGET_1 0x0080 | ||
25 | +#define PAGE_TARGET_2 0x0200 | ||
26 | |||
27 | #if defined(CONFIG_USER_ONLY) | ||
28 | void page_dump(FILE *f); | ||
29 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/linux-user/syscall_defs.h | ||
32 | +++ b/linux-user/syscall_defs.h | ||
33 | @@ -XXX,XX +XXX,XX @@ struct target_winsize { | ||
34 | |||
35 | #ifdef TARGET_AARCH64 | ||
36 | #define TARGET_PROT_BTI 0x10 | ||
37 | +#define TARGET_PROT_MTE 0x20 | ||
38 | #endif | ||
39 | |||
40 | /* Common */ | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 41 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
17 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 43 | --- a/target/arm/cpu.h |
19 | +++ b/target/arm/cpu.h | 44 | +++ b/target/arm/cpu.h |
20 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 45 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
21 | */ | 46 | * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
22 | uint32_t psci_conduit; | 47 | */ |
23 | 48 | #define PAGE_BTI PAGE_TARGET_1 | |
24 | + /* For v8M, initial value of the Secure VTOR */ | 49 | +#define PAGE_MTE PAGE_TARGET_2 |
25 | + uint32_t init_svtor; | 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)) { | ||
26 | + | 71 | + |
27 | /* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or | 72 | + /* |
28 | * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type. | 73 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. |
29 | */ | 74 | + * Since this is the unusual case, don't bother checking unless |
30 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 75 | + * the bit has been requested. If set and valid, record the bit |
31 | index XXXXXXX..XXXXXXX 100644 | 76 | + * within QEMU's page_flags. |
32 | --- a/target/arm/cpu.c | 77 | + */ |
33 | +++ b/target/arm/cpu.c | 78 | + if ((prot & TARGET_PROT_BTI) && cpu_isar_feature(aa64_bti, cpu)) { |
34 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | 79 | valid |= TARGET_PROT_BTI; |
35 | uint32_t initial_msp; /* Loaded from 0x0 */ | 80 | page_flags |= PAGE_BTI; |
36 | uint32_t initial_pc; /* Loaded from 0x4 */ | ||
37 | uint8_t *rom; | ||
38 | + uint32_t vecbase; | ||
39 | |||
40 | if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { | ||
41 | env->v7m.secure = true; | ||
42 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | ||
43 | /* Unlike A/R profile, M profile defines the reset LR value */ | ||
44 | env->regs[14] = 0xffffffff; | ||
45 | |||
46 | - /* Load the initial SP and PC from the vector table at address 0 */ | ||
47 | - rom = rom_ptr(0); | ||
48 | + env->v7m.vecbase[M_REG_S] = cpu->init_svtor & 0xffffff80; | ||
49 | + | ||
50 | + /* Load the initial SP and PC from offset 0 and 4 in the vector table */ | ||
51 | + vecbase = env->v7m.vecbase[env->v7m.secure]; | ||
52 | + rom = rom_ptr(vecbase); | ||
53 | if (rom) { | ||
54 | /* Address zero is covered by ROM which hasn't yet been | ||
55 | * copied into physical memory. | ||
56 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | ||
57 | * it got copied into memory. In the latter case, rom_ptr | ||
58 | * will return a NULL pointer and we should use ldl_phys instead. | ||
59 | */ | ||
60 | - initial_msp = ldl_phys(s->as, 0); | ||
61 | - initial_pc = ldl_phys(s->as, 4); | ||
62 | + initial_msp = ldl_phys(s->as, vecbase); | ||
63 | + initial_pc = ldl_phys(s->as, vecbase + 4); | ||
64 | } | 81 | } |
65 | 82 | + /* Similarly for the PROT_MTE bit. */ | |
66 | env->regs[13] = initial_msp & 0xFFFFFFFC; | 83 | + if ((prot & TARGET_PROT_MTE) && cpu_isar_feature(aa64_mte, cpu)) { |
67 | @@ -XXX,XX +XXX,XX @@ static Property arm_cpu_pmsav7_dregion_property = | 84 | + valid |= TARGET_PROT_MTE; |
68 | pmsav7_dregion, | 85 | + page_flags |= PAGE_MTE; |
69 | qdev_prop_uint32, uint32_t); | 86 | + } |
70 | |||
71 | +/* M profile: initial value of the Secure VTOR */ | ||
72 | +static Property arm_cpu_initsvtor_property = | ||
73 | + DEFINE_PROP_UINT32("init-svtor", ARMCPU, init_svtor, 0); | ||
74 | + | ||
75 | static void arm_cpu_post_init(Object *obj) | ||
76 | { | ||
77 | ARMCPU *cpu = ARM_CPU(obj); | ||
78 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj) | ||
79 | qdev_prop_allow_set_link_before_realize, | ||
80 | OBJ_PROP_LINK_UNREF_ON_RELEASE, | ||
81 | &error_abort); | ||
82 | + qdev_property_add_static(DEVICE(obj), &arm_cpu_initsvtor_property, | ||
83 | + &error_abort); | ||
84 | } | 87 | } |
85 | 88 | #endif | |
86 | qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property, | 89 | |
87 | -- | 90 | -- |
88 | 2.16.2 | 91 | 2.20.1 |
89 | 92 | ||
90 | 93 | diff view generated by jsdifflib |
1 | In v8M, the Implementation Defined Attribution Unit (IDAU) is | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | a small piece of hardware typically implemented in the SoC | ||
3 | which provides board or SoC specific security attribution | ||
4 | information for each address that the CPU performs MPU/SAU | ||
5 | checks on. For QEMU, we model this with a QOM interface which | ||
6 | is implemented by the board or SoC object and connected to | ||
7 | the CPU using a link property. | ||
8 | 2 | ||
9 | This commit defines the new interface class, adds the link | 3 | Move everything related to syndromes to a new file, |
10 | property to the CPU object, and makes the SAU checking | 4 | which can be shared with linux-user. |
11 | code call the IDAU interface if one is present. | ||
12 | 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-26-richard.henderson@linaro.org | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-id: 20180220180325.29818-5-peter.maydell@linaro.org | ||
16 | --- | 11 | --- |
17 | target/arm/cpu.h | 3 +++ | 12 | target/arm/internals.h | 245 +----------------------------------- |
18 | target/arm/idau.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ | 13 | target/arm/syndrome.h | 273 +++++++++++++++++++++++++++++++++++++++++ |
19 | target/arm/cpu.c | 15 +++++++++++++ | 14 | 2 files changed, 274 insertions(+), 244 deletions(-) |
20 | target/arm/helper.c | 28 +++++++++++++++++++++--- | 15 | create mode 100644 target/arm/syndrome.h |
21 | 4 files changed, 104 insertions(+), 3 deletions(-) | ||
22 | create mode 100644 target/arm/idau.h | ||
23 | 16 | ||
24 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
25 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/arm/cpu.h | 19 | --- a/target/arm/internals.h |
27 | +++ b/target/arm/cpu.h | 20 | +++ b/target/arm/internals.h |
28 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 21 | @@ -XXX,XX +XXX,XX @@ |
29 | /* MemoryRegion to use for secure physical accesses */ | 22 | #define TARGET_ARM_INTERNALS_H |
30 | MemoryRegion *secure_memory; | 23 | |
31 | 24 | #include "hw/registerfields.h" | |
32 | + /* For v8M, pointer to the IDAU interface provided by board/SoC */ | 25 | +#include "syndrome.h" |
33 | + Object *idau; | 26 | |
34 | + | 27 | /* register banks for CPU modes */ |
35 | /* 'compatible' string for this CPU for Linux device trees */ | 28 | #define BANK_USRSYS 0 |
36 | const char *dtb_compatible; | 29 | @@ -XXX,XX +XXX,XX @@ static inline bool extended_addresses_enabled(CPUARMState *env) |
37 | 30 | (arm_feature(env, ARM_FEATURE_LPAE) && (tcr->raw_tcr & TTBCR_EAE)); | |
38 | diff --git a/target/arm/idau.h b/target/arm/idau.h | 31 | } |
32 | |||
33 | -/* Valid Syndrome Register EC field values */ | ||
34 | -enum arm_exception_class { | ||
35 | - EC_UNCATEGORIZED = 0x00, | ||
36 | - EC_WFX_TRAP = 0x01, | ||
37 | - EC_CP15RTTRAP = 0x03, | ||
38 | - EC_CP15RRTTRAP = 0x04, | ||
39 | - EC_CP14RTTRAP = 0x05, | ||
40 | - EC_CP14DTTRAP = 0x06, | ||
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 | ||
39 | new file mode 100644 | 281 | new file mode 100644 |
40 | index XXXXXXX..XXXXXXX | 282 | index XXXXXXX..XXXXXXX |
41 | --- /dev/null | 283 | --- /dev/null |
42 | +++ b/target/arm/idau.h | 284 | +++ b/target/arm/syndrome.h |
43 | @@ -XXX,XX +XXX,XX @@ | 285 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 286 | +/* |
45 | + * QEMU ARM CPU -- interface for the Arm v8M IDAU | 287 | + * QEMU ARM CPU -- syndrome functions and types |
46 | + * | 288 | + * |
47 | + * Copyright (c) 2018 Linaro Ltd | 289 | + * Copyright (c) 2014 Linaro Ltd |
48 | + * | 290 | + * |
49 | + * This program is free software; you can redistribute it and/or | 291 | + * This program is free software; you can redistribute it and/or |
50 | + * modify it under the terms of the GNU General Public License | 292 | + * modify it under the terms of the GNU General Public License |
51 | + * as published by the Free Software Foundation; either version 2 | 293 | + * as published by the Free Software Foundation; either version 2 |
52 | + * of the License, or (at your option) any later version. | 294 | + * of the License, or (at your option) any later version. |
... | ... | ||
58 | + * | 300 | + * |
59 | + * You should have received a copy of the GNU General Public License | 301 | + * You should have received a copy of the GNU General Public License |
60 | + * along with this program; if not, see | 302 | + * along with this program; if not, see |
61 | + * <http://www.gnu.org/licenses/gpl-2.0.html> | 303 | + * <http://www.gnu.org/licenses/gpl-2.0.html> |
62 | + * | 304 | + * |
63 | + * In the v8M architecture, the IDAU is a small piece of hardware | 305 | + * This header defines functions, types, etc which need to be shared |
64 | + * typically implemented in the SoC which provides board or SoC | 306 | + * between different source files within target/arm/ but which are |
65 | + * specific security attribution information for each address that | 307 | + * private to it and not required by the rest of QEMU. |
66 | + * the CPU performs MPU/SAU checks on. For QEMU, we model this with a | ||
67 | + * QOM interface which is implemented by the board or SoC object and | ||
68 | + * connected to the CPU using a link property. | ||
69 | + */ | 308 | + */ |
70 | + | 309 | + |
71 | +#ifndef TARGET_ARM_IDAU_H | 310 | +#ifndef TARGET_ARM_SYNDROME_H |
72 | +#define TARGET_ARM_IDAU_H | 311 | +#define TARGET_ARM_SYNDROME_H |
73 | + | 312 | + |
74 | +#include "qom/object.h" | 313 | +/* Valid Syndrome Register EC field values */ |
75 | + | 314 | +enum arm_exception_class { |
76 | +#define TYPE_IDAU_INTERFACE "idau-interface" | 315 | + EC_UNCATEGORIZED = 0x00, |
77 | +#define IDAU_INTERFACE(obj) \ | 316 | + EC_WFX_TRAP = 0x01, |
78 | + INTERFACE_CHECK(IDAUInterface, (obj), TYPE_IDAU_INTERFACE) | 317 | + EC_CP15RTTRAP = 0x03, |
79 | +#define IDAU_INTERFACE_CLASS(class) \ | 318 | + EC_CP15RRTTRAP = 0x04, |
80 | + OBJECT_CLASS_CHECK(IDAUInterfaceClass, (class), TYPE_IDAU_INTERFACE) | 319 | + EC_CP14RTTRAP = 0x05, |
81 | +#define IDAU_INTERFACE_GET_CLASS(obj) \ | 320 | + EC_CP14DTTRAP = 0x06, |
82 | + OBJECT_GET_CLASS(IDAUInterfaceClass, (obj), TYPE_IDAU_INTERFACE) | 321 | + EC_ADVSIMDFPACCESSTRAP = 0x07, |
83 | + | 322 | + EC_FPIDTRAP = 0x08, |
84 | +typedef struct IDAUInterface { | 323 | + EC_PACTRAP = 0x09, |
85 | + Object parent; | 324 | + EC_CP14RRTTRAP = 0x0c, |
86 | +} IDAUInterface; | 325 | + EC_BTITRAP = 0x0d, |
87 | + | 326 | + EC_ILLEGALSTATE = 0x0e, |
88 | +#define IREGION_NOTVALID -1 | 327 | + EC_AA32_SVC = 0x11, |
89 | + | 328 | + EC_AA32_HVC = 0x12, |
90 | +typedef struct IDAUInterfaceClass { | 329 | + EC_AA32_SMC = 0x13, |
91 | + InterfaceClass parent; | 330 | + EC_AA64_SVC = 0x15, |
92 | + | 331 | + EC_AA64_HVC = 0x16, |
93 | + /* Check the specified address and return the IDAU security information | 332 | + EC_AA64_SMC = 0x17, |
94 | + * for it by filling in iregion, exempt, ns and nsc: | 333 | + EC_SYSTEMREGISTERTRAP = 0x18, |
95 | + * iregion: IDAU region number, or IREGION_NOTVALID if not valid | 334 | + EC_SVEACCESSTRAP = 0x19, |
96 | + * exempt: true if address is exempt from security attribution | 335 | + EC_INSNABORT = 0x20, |
97 | + * ns: true if the address is NonSecure | 336 | + EC_INSNABORT_SAME_EL = 0x21, |
98 | + * nsc: true if the address is NonSecure-callable | 337 | + EC_PCALIGNMENT = 0x22, |
99 | + */ | 338 | + EC_DATAABORT = 0x24, |
100 | + void (*check)(IDAUInterface *ii, uint32_t address, int *iregion, | 339 | + EC_DATAABORT_SAME_EL = 0x25, |
101 | + bool *exempt, bool *ns, bool *nsc); | 340 | + EC_SPALIGNMENT = 0x26, |
102 | +} IDAUInterfaceClass; | 341 | + EC_AA32_FPTRAP = 0x28, |
103 | + | 342 | + EC_AA64_FPTRAP = 0x2c, |
104 | +#endif | 343 | + EC_SERROR = 0x2f, |
105 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 344 | + EC_BREAKPOINT = 0x30, |
106 | index XXXXXXX..XXXXXXX 100644 | 345 | + EC_BREAKPOINT_SAME_EL = 0x31, |
107 | --- a/target/arm/cpu.c | 346 | + EC_SOFTWARESTEP = 0x32, |
108 | +++ b/target/arm/cpu.c | 347 | + EC_SOFTWARESTEP_SAME_EL = 0x33, |
109 | @@ -XXX,XX +XXX,XX @@ | 348 | + EC_WATCHPOINT = 0x34, |
110 | */ | 349 | + EC_WATCHPOINT_SAME_EL = 0x35, |
111 | 350 | + EC_AA32_BKPT = 0x38, | |
112 | #include "qemu/osdep.h" | 351 | + EC_VECTORCATCH = 0x3a, |
113 | +#include "target/arm/idau.h" | 352 | + EC_AA64_BKPT = 0x3c, |
114 | #include "qemu/error-report.h" | ||
115 | #include "qapi/error.h" | ||
116 | #include "cpu.h" | ||
117 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj) | ||
118 | } | ||
119 | } | ||
120 | |||
121 | + if (arm_feature(&cpu->env, ARM_FEATURE_M_SECURITY)) { | ||
122 | + object_property_add_link(obj, "idau", TYPE_IDAU_INTERFACE, &cpu->idau, | ||
123 | + qdev_prop_allow_set_link_before_realize, | ||
124 | + OBJ_PROP_LINK_UNREF_ON_RELEASE, | ||
125 | + &error_abort); | ||
126 | + } | ||
127 | + | ||
128 | qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property, | ||
129 | &error_abort); | ||
130 | } | ||
131 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_cpu_type_info = { | ||
132 | .class_init = arm_cpu_class_init, | ||
133 | }; | ||
134 | |||
135 | +static const TypeInfo idau_interface_type_info = { | ||
136 | + .name = TYPE_IDAU_INTERFACE, | ||
137 | + .parent = TYPE_INTERFACE, | ||
138 | + .class_size = sizeof(IDAUInterfaceClass), | ||
139 | +}; | 353 | +}; |
140 | + | 354 | + |
141 | static void arm_cpu_register_types(void) | 355 | +#define ARM_EL_EC_SHIFT 26 |
142 | { | 356 | +#define ARM_EL_IL_SHIFT 25 |
143 | const ARMCPUInfo *info = arm_cpus; | 357 | +#define ARM_EL_ISV_SHIFT 24 |
144 | 358 | +#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) | |
145 | type_register_static(&arm_cpu_type_info); | 359 | +#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) |
146 | + type_register_static(&idau_interface_type_info); | 360 | + |
147 | 361 | +static inline uint32_t syn_get_ec(uint32_t syn) | |
148 | while (info->name) { | 362 | +{ |
149 | cpu_register(info); | 363 | + return syn >> ARM_EL_EC_SHIFT; |
150 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 364 | +} |
151 | index XXXXXXX..XXXXXXX 100644 | 365 | + |
152 | --- a/target/arm/helper.c | 366 | +/* |
153 | +++ b/target/arm/helper.c | 367 | + * Utility functions for constructing various kinds of syndrome value. |
154 | @@ -XXX,XX +XXX,XX @@ | 368 | + * Note that in general we follow the AArch64 syndrome values; in a |
155 | #include "qemu/osdep.h" | 369 | + * few cases the value in HSR for exceptions taken to AArch32 Hyp |
156 | +#include "target/arm/idau.h" | 370 | + * mode differs slightly, and we fix this up when populating HSR in |
157 | #include "trace.h" | 371 | + * arm_cpu_do_interrupt_aarch32_hyp(). |
158 | #include "cpu.h" | 372 | + * The exception is FP/SIMD access traps -- these report extra information |
159 | #include "internals.h" | 373 | + * when taking an exception to AArch32. For those we include the extra coproc |
160 | @@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address, | 374 | + * and TA fields, and mask them out when taking the exception to AArch64. |
161 | */ | 375 | + */ |
162 | ARMCPU *cpu = arm_env_get_cpu(env); | 376 | +static inline uint32_t syn_uncategorized(void) |
163 | int r; | 377 | +{ |
164 | + bool idau_exempt = false, idau_ns = true, idau_nsc = true; | 378 | + return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
165 | + int idau_region = IREGION_NOTVALID; | 379 | +} |
166 | 380 | + | |
167 | - /* TODO: implement IDAU */ | 381 | +static inline uint32_t syn_aa64_svc(uint32_t imm16) |
168 | + if (cpu->idau) { | 382 | +{ |
169 | + IDAUInterfaceClass *iic = IDAU_INTERFACE_GET_CLASS(cpu->idau); | 383 | + return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
170 | + IDAUInterface *ii = IDAU_INTERFACE(cpu->idau); | 384 | +} |
171 | + | 385 | + |
172 | + iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns, | 386 | +static inline uint32_t syn_aa64_hvc(uint32_t imm16) |
173 | + &idau_nsc); | 387 | +{ |
174 | + } | 388 | + return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
175 | 389 | +} | |
176 | if (access_type == MMU_INST_FETCH && extract32(address, 28, 4) == 0xf) { | 390 | + |
177 | /* 0xf0000000..0xffffffff is always S for insn fetches */ | 391 | +static inline uint32_t syn_aa64_smc(uint32_t imm16) |
178 | return; | 392 | +{ |
179 | } | 393 | + return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
180 | 394 | +} | |
181 | - if (v8m_is_sau_exempt(env, address, access_type)) { | 395 | + |
182 | + if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) { | 396 | +static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit) |
183 | sattrs->ns = !regime_is_secure(env, mmu_idx); | 397 | +{ |
184 | return; | 398 | + return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
185 | } | 399 | + | (is_16bit ? 0 : ARM_EL_IL); |
186 | 400 | +} | |
187 | + if (idau_region != IREGION_NOTVALID) { | 401 | + |
188 | + sattrs->irvalid = true; | 402 | +static inline uint32_t syn_aa32_hvc(uint32_t imm16) |
189 | + sattrs->iregion = idau_region; | 403 | +{ |
190 | + } | 404 | + return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
191 | + | 405 | +} |
192 | switch (env->sau.ctrl & 3) { | 406 | + |
193 | case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */ | 407 | +static inline uint32_t syn_aa32_smc(void) |
194 | break; | 408 | +{ |
195 | @@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address, | 409 | + return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
196 | } | 410 | +} |
197 | } | 411 | + |
198 | 412 | +static inline uint32_t syn_aa64_bkpt(uint32_t imm16) | |
199 | - /* TODO when we support the IDAU then it may override the result here */ | 413 | +{ |
200 | + /* The IDAU will override the SAU lookup results if it specifies | 414 | + return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
201 | + * higher security than the SAU does. | 415 | +} |
202 | + */ | 416 | + |
203 | + if (!idau_ns) { | 417 | +static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit) |
204 | + if (sattrs->ns || (!idau_nsc && sattrs->nsc)) { | 418 | +{ |
205 | + sattrs->ns = false; | 419 | + return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
206 | + sattrs->nsc = idau_nsc; | 420 | + | (is_16bit ? 0 : ARM_EL_IL); |
207 | + } | 421 | +} |
208 | + } | 422 | + |
209 | break; | 423 | +static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2, |
210 | } | 424 | + int crn, int crm, int rt, |
211 | } | 425 | + int isread) |
426 | +{ | ||
427 | + return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL | ||
428 | + | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5) | ||
429 | + | (crm << 1) | isread; | ||
430 | +} | ||
431 | + | ||
432 | +static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2, | ||
433 | + int crn, int crm, int rt, int isread, | ||
434 | + bool is_16bit) | ||
435 | +{ | ||
436 | + return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT) | ||
437 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
438 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) | ||
439 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; | ||
440 | +} | ||
441 | + | ||
442 | +static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2, | ||
443 | + int crn, int crm, int rt, int isread, | ||
444 | + bool is_16bit) | ||
445 | +{ | ||
446 | + return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT) | ||
447 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
448 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) | ||
449 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; | ||
450 | +} | ||
451 | + | ||
452 | +static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm, | ||
453 | + int rt, int rt2, int isread, | ||
454 | + bool is_16bit) | ||
455 | +{ | ||
456 | + return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT) | ||
457 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
458 | + | (cv << 24) | (cond << 20) | (opc1 << 16) | ||
459 | + | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; | ||
460 | +} | ||
461 | + | ||
462 | +static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm, | ||
463 | + int rt, int rt2, int isread, | ||
464 | + bool is_16bit) | ||
465 | +{ | ||
466 | + return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT) | ||
467 | + | (is_16bit ? 0 : ARM_EL_IL) | ||
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 */ | ||
212 | -- | 559 | -- |
213 | 2.16.2 | 560 | 2.20.1 |
214 | 561 | ||
215 | 562 | diff view generated by jsdifflib |
1 | The MPS2 AN505 FPGA image includes a "FPGA control block" | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | which is a small set of registers handling LEDs, buttons | ||
3 | and some counters. | ||
4 | 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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20180220180325.29818-14-peter.maydell@linaro.org | ||
8 | --- | 10 | --- |
9 | hw/misc/Makefile.objs | 1 + | 11 | linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++--- |
10 | include/hw/misc/mps2-fpgaio.h | 43 ++++++++++ | 12 | target/arm/tlb_helper.c | 15 +++++++++------ |
11 | hw/misc/mps2-fpgaio.c | 176 ++++++++++++++++++++++++++++++++++++++++ | 13 | 2 files changed, 30 insertions(+), 9 deletions(-) |
12 | default-configs/arm-softmmu.mak | 1 + | ||
13 | hw/misc/trace-events | 6 ++ | ||
14 | 5 files changed, 227 insertions(+) | ||
15 | create mode 100644 include/hw/misc/mps2-fpgaio.h | ||
16 | create mode 100644 hw/misc/mps2-fpgaio.c | ||
17 | 14 | ||
18 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 15 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
19 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/misc/Makefile.objs | 17 | --- a/linux-user/aarch64/cpu_loop.c |
21 | +++ b/hw/misc/Makefile.objs | 18 | +++ b/linux-user/aarch64/cpu_loop.c |
22 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o | ||
23 | obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o | ||
24 | obj-$(CONFIG_MIPS_CPS) += mips_cpc.o | ||
25 | obj-$(CONFIG_MIPS_ITU) += mips_itu.o | ||
26 | +obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o | ||
27 | obj-$(CONFIG_MPS2_SCC) += mps2-scc.o | ||
28 | |||
29 | obj-$(CONFIG_PVPANIC) += pvpanic.o | ||
30 | diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h | ||
31 | new file mode 100644 | ||
32 | index XXXXXXX..XXXXXXX | ||
33 | --- /dev/null | ||
34 | +++ b/include/hw/misc/mps2-fpgaio.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
36 | +/* | 20 | #include "cpu_loop-common.h" |
37 | + * ARM MPS2 FPGAIO emulation | 21 | #include "qemu/guest-random.h" |
38 | + * | 22 | #include "hw/semihosting/common-semi.h" |
39 | + * Copyright (c) 2018 Linaro Limited | 23 | +#include "target/arm/syndrome.h" |
40 | + * Written by Peter Maydell | 24 | |
41 | + * | 25 | #define get_user_code_u32(x, gaddr, env) \ |
42 | + * This program is free software; you can redistribute it and/or modify | 26 | ({ abi_long __r = get_user_u32((x), (gaddr)); \ |
43 | + * it under the terms of the GNU General Public License version 2 or | 27 | @@ -XXX,XX +XXX,XX @@ |
44 | + * (at your option) any later version. | 28 | void cpu_loop(CPUARMState *env) |
45 | + */ | 29 | { |
30 | CPUState *cs = env_cpu(env); | ||
31 | - int trapnr; | ||
32 | + int trapnr, ec, fsc; | ||
33 | abi_long ret; | ||
34 | target_siginfo_t info; | ||
35 | |||
36 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) | ||
37 | case EXCP_DATA_ABORT: | ||
38 | info.si_signo = TARGET_SIGSEGV; | ||
39 | info.si_errno = 0; | ||
40 | - /* XXX: check env->error_code */ | ||
41 | - info.si_code = TARGET_SEGV_MAPERR; | ||
42 | info._sifields._sigfault._addr = env->exception.vaddress; | ||
46 | + | 43 | + |
47 | +/* This is a model of the FPGAIO register block in the AN505 | 44 | + /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ |
48 | + * FPGA image for the MPS2 dev board; it is documented in the | 45 | + ec = syn_get_ec(env->exception.syndrome); |
49 | + * application note: | 46 | + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); |
50 | + * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html | ||
51 | + * | ||
52 | + * QEMU interface: | ||
53 | + * + sysbus MMIO region 0: the register bank | ||
54 | + */ | ||
55 | + | 47 | + |
56 | +#ifndef MPS2_FPGAIO_H | 48 | + /* Both EC have the same format for FSC, or close enough. */ |
57 | +#define MPS2_FPGAIO_H | 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 | + } | ||
58 | + | 61 | + |
59 | +#include "hw/sysbus.h" | 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; | ||
85 | } | ||
86 | - cpu_loop_exit_restore(cs, retaddr); | ||
60 | + | 87 | + |
61 | +#define TYPE_MPS2_FPGAIO "mps2-fpgaio" | 88 | + /* now we have a real cpu fault */ |
62 | +#define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO) | 89 | + cpu_restore_state(cs, retaddr, true); |
63 | + | 90 | + arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi); |
64 | +typedef struct { | 91 | #else |
65 | + /*< private >*/ | 92 | hwaddr phys_addr; |
66 | + SysBusDevice parent_obj; | 93 | target_ulong page_size; |
67 | + | 94 | int prot, ret; |
68 | + /*< public >*/ | 95 | MemTxAttrs attrs = {}; |
69 | + MemoryRegion iomem; | 96 | - ARMMMUFaultInfo fi = {}; |
70 | + | 97 | ARMCacheAttrs cacheattrs = {}; |
71 | + uint32_t led0; | 98 | |
72 | + uint32_t prescale; | 99 | /* |
73 | + uint32_t misc; | ||
74 | + | ||
75 | + uint32_t prescale_clk; | ||
76 | +} MPS2FPGAIO; | ||
77 | + | ||
78 | +#endif | ||
79 | diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c | ||
80 | new file mode 100644 | ||
81 | index XXXXXXX..XXXXXXX | ||
82 | --- /dev/null | ||
83 | +++ b/hw/misc/mps2-fpgaio.c | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | +/* | ||
86 | + * ARM MPS2 AN505 FPGAIO emulation | ||
87 | + * | ||
88 | + * Copyright (c) 2018 Linaro Limited | ||
89 | + * Written by Peter Maydell | ||
90 | + * | ||
91 | + * This program is free software; you can redistribute it and/or modify | ||
92 | + * it under the terms of the GNU General Public License version 2 or | ||
93 | + * (at your option) any later version. | ||
94 | + */ | ||
95 | + | ||
96 | +/* This is a model of the "FPGA system control and I/O" block found | ||
97 | + * in the AN505 FPGA image for the MPS2 devboard. | ||
98 | + * It is documented in AN505: | ||
99 | + * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html | ||
100 | + */ | ||
101 | + | ||
102 | +#include "qemu/osdep.h" | ||
103 | +#include "qemu/log.h" | ||
104 | +#include "qapi/error.h" | ||
105 | +#include "trace.h" | ||
106 | +#include "hw/sysbus.h" | ||
107 | +#include "hw/registerfields.h" | ||
108 | +#include "hw/misc/mps2-fpgaio.h" | ||
109 | + | ||
110 | +REG32(LED0, 0) | ||
111 | +REG32(BUTTON, 8) | ||
112 | +REG32(CLK1HZ, 0x10) | ||
113 | +REG32(CLK100HZ, 0x14) | ||
114 | +REG32(COUNTER, 0x18) | ||
115 | +REG32(PRESCALE, 0x1c) | ||
116 | +REG32(PSCNTR, 0x20) | ||
117 | +REG32(MISC, 0x4c) | ||
118 | + | ||
119 | +static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size) | ||
120 | +{ | ||
121 | + MPS2FPGAIO *s = MPS2_FPGAIO(opaque); | ||
122 | + uint64_t r; | ||
123 | + | ||
124 | + switch (offset) { | ||
125 | + case A_LED0: | ||
126 | + r = s->led0; | ||
127 | + break; | ||
128 | + case A_BUTTON: | ||
129 | + /* User-pressable board buttons. We don't model that, so just return | ||
130 | + * zeroes. | ||
131 | + */ | ||
132 | + r = 0; | ||
133 | + break; | ||
134 | + case A_PRESCALE: | ||
135 | + r = s->prescale; | ||
136 | + break; | ||
137 | + case A_MISC: | ||
138 | + r = s->misc; | ||
139 | + break; | ||
140 | + case A_CLK1HZ: | ||
141 | + case A_CLK100HZ: | ||
142 | + case A_COUNTER: | ||
143 | + case A_PSCNTR: | ||
144 | + /* These are all upcounters of various frequencies. */ | ||
145 | + qemu_log_mask(LOG_UNIMP, "MPS2 FPGAIO: counters unimplemented\n"); | ||
146 | + r = 0; | ||
147 | + break; | ||
148 | + default: | ||
149 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
150 | + "MPS2 FPGAIO read: bad offset %x\n", (int) offset); | ||
151 | + r = 0; | ||
152 | + break; | ||
153 | + } | ||
154 | + | ||
155 | + trace_mps2_fpgaio_read(offset, r, size); | ||
156 | + return r; | ||
157 | +} | ||
158 | + | ||
159 | +static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value, | ||
160 | + unsigned size) | ||
161 | +{ | ||
162 | + MPS2FPGAIO *s = MPS2_FPGAIO(opaque); | ||
163 | + | ||
164 | + trace_mps2_fpgaio_write(offset, value, size); | ||
165 | + | ||
166 | + switch (offset) { | ||
167 | + case A_LED0: | ||
168 | + /* LED bits [1:0] control board LEDs. We don't currently have | ||
169 | + * a mechanism for displaying this graphically, so use a trace event. | ||
170 | + */ | ||
171 | + trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.', | ||
172 | + value & 0x01 ? '*' : '.'); | ||
173 | + s->led0 = value & 0x3; | ||
174 | + break; | ||
175 | + case A_PRESCALE: | ||
176 | + s->prescale = value; | ||
177 | + break; | ||
178 | + case A_MISC: | ||
179 | + /* These are control bits for some of the other devices on the | ||
180 | + * board (SPI, CLCD, etc). We don't implement that yet, so just | ||
181 | + * make the bits read as written. | ||
182 | + */ | ||
183 | + qemu_log_mask(LOG_UNIMP, | ||
184 | + "MPS2 FPGAIO: MISC control bits unimplemented\n"); | ||
185 | + s->misc = value; | ||
186 | + break; | ||
187 | + default: | ||
188 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
189 | + "MPS2 FPGAIO write: bad offset 0x%x\n", (int) offset); | ||
190 | + break; | ||
191 | + } | ||
192 | +} | ||
193 | + | ||
194 | +static const MemoryRegionOps mps2_fpgaio_ops = { | ||
195 | + .read = mps2_fpgaio_read, | ||
196 | + .write = mps2_fpgaio_write, | ||
197 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
198 | +}; | ||
199 | + | ||
200 | +static void mps2_fpgaio_reset(DeviceState *dev) | ||
201 | +{ | ||
202 | + MPS2FPGAIO *s = MPS2_FPGAIO(dev); | ||
203 | + | ||
204 | + trace_mps2_fpgaio_reset(); | ||
205 | + s->led0 = 0; | ||
206 | + s->prescale = 0; | ||
207 | + s->misc = 0; | ||
208 | +} | ||
209 | + | ||
210 | +static void mps2_fpgaio_init(Object *obj) | ||
211 | +{ | ||
212 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
213 | + MPS2FPGAIO *s = MPS2_FPGAIO(obj); | ||
214 | + | ||
215 | + memory_region_init_io(&s->iomem, obj, &mps2_fpgaio_ops, s, | ||
216 | + "mps2-fpgaio", 0x1000); | ||
217 | + sysbus_init_mmio(sbd, &s->iomem); | ||
218 | +} | ||
219 | + | ||
220 | +static const VMStateDescription mps2_fpgaio_vmstate = { | ||
221 | + .name = "mps2-fpgaio", | ||
222 | + .version_id = 1, | ||
223 | + .minimum_version_id = 1, | ||
224 | + .fields = (VMStateField[]) { | ||
225 | + VMSTATE_UINT32(led0, MPS2FPGAIO), | ||
226 | + VMSTATE_UINT32(prescale, MPS2FPGAIO), | ||
227 | + VMSTATE_UINT32(misc, MPS2FPGAIO), | ||
228 | + VMSTATE_END_OF_LIST() | ||
229 | + } | ||
230 | +}; | ||
231 | + | ||
232 | +static Property mps2_fpgaio_properties[] = { | ||
233 | + /* Frequency of the prescale counter */ | ||
234 | + DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000), | ||
235 | + DEFINE_PROP_END_OF_LIST(), | ||
236 | +}; | ||
237 | + | ||
238 | +static void mps2_fpgaio_class_init(ObjectClass *klass, void *data) | ||
239 | +{ | ||
240 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
241 | + | ||
242 | + dc->vmsd = &mps2_fpgaio_vmstate; | ||
243 | + dc->reset = mps2_fpgaio_reset; | ||
244 | + dc->props = mps2_fpgaio_properties; | ||
245 | +} | ||
246 | + | ||
247 | +static const TypeInfo mps2_fpgaio_info = { | ||
248 | + .name = TYPE_MPS2_FPGAIO, | ||
249 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
250 | + .instance_size = sizeof(MPS2FPGAIO), | ||
251 | + .instance_init = mps2_fpgaio_init, | ||
252 | + .class_init = mps2_fpgaio_class_init, | ||
253 | +}; | ||
254 | + | ||
255 | +static void mps2_fpgaio_register_types(void) | ||
256 | +{ | ||
257 | + type_register_static(&mps2_fpgaio_info); | ||
258 | +} | ||
259 | + | ||
260 | +type_init(mps2_fpgaio_register_types); | ||
261 | diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak | ||
262 | index XXXXXXX..XXXXXXX 100644 | ||
263 | --- a/default-configs/arm-softmmu.mak | ||
264 | +++ b/default-configs/arm-softmmu.mak | ||
265 | @@ -XXX,XX +XXX,XX @@ CONFIG_STM32F205_SOC=y | ||
266 | CONFIG_CMSDK_APB_TIMER=y | ||
267 | CONFIG_CMSDK_APB_UART=y | ||
268 | |||
269 | +CONFIG_MPS2_FPGAIO=y | ||
270 | CONFIG_MPS2_SCC=y | ||
271 | |||
272 | CONFIG_VERSATILE_PCI=y | ||
273 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
274 | index XXXXXXX..XXXXXXX 100644 | ||
275 | --- a/hw/misc/trace-events | ||
276 | +++ b/hw/misc/trace-events | ||
277 | @@ -XXX,XX +XXX,XX @@ mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, | ||
278 | mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 | ||
279 | mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32 | ||
280 | |||
281 | +# hw/misc/mps2_fpgaio.c | ||
282 | +mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
283 | +mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
284 | +mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset" | ||
285 | +mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c" | ||
286 | + | ||
287 | # hw/misc/msf2-sysreg.c | ||
288 | msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32 | ||
289 | msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32 | ||
290 | -- | 100 | -- |
291 | 2.16.2 | 101 | 2.20.1 |
292 | 102 | ||
293 | 103 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-7-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-28-richard.henderson@linaro.org |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 7 | --- |
8 | target/arm/translate-a64.c | 29 +++++++++++++++++++++++++++++ | 8 | linux-user/aarch64/target_signal.h | 2 ++ |
9 | 1 file changed, 29 insertions(+) | 9 | linux-user/aarch64/cpu_loop.c | 3 +++ |
10 | 2 files changed, 5 insertions(+) | ||
10 | 11 | ||
11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 12 | diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate-a64.c | 14 | --- a/linux-user/aarch64/target_signal.h |
14 | +++ b/target/arm/translate-a64.c | 15 | +++ b/linux-user/aarch64/target_signal.h |
15 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
16 | case 0x19: /* FMULX */ | 17 | |
17 | is_fp = true; | 18 | #include "../generic/signal.h" |
18 | break; | 19 | |
19 | + case 0x1d: /* SQRDMLAH */ | 20 | +#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
20 | + case 0x1f: /* SQRDMLSH */ | 21 | + |
21 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | 22 | #define TARGET_ARCH_HAS_SETUP_FRAME |
22 | + unallocated_encoding(s); | 23 | #endif /* AARCH64_TARGET_SIGNAL_H */ |
23 | + return; | 24 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
24 | + } | 25 | index XXXXXXX..XXXXXXX 100644 |
25 | + break; | 26 | --- a/linux-user/aarch64/cpu_loop.c |
26 | default: | 27 | +++ b/linux-user/aarch64/cpu_loop.c |
27 | unallocated_encoding(s); | 28 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) |
28 | return; | 29 | case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ |
29 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | 30 | info.si_code = TARGET_SEGV_ACCERR; |
30 | tcg_op, tcg_idx); | ||
31 | } | ||
32 | break; | 31 | break; |
33 | + case 0x1d: /* SQRDMLAH */ | 32 | + case 0x11: /* Synchronous Tag Check Fault */ |
34 | + read_vec_element_i32(s, tcg_res, rd, pass, | 33 | + info.si_code = TARGET_SEGV_MTESERR; |
35 | + is_scalar ? size : MO_32); | ||
36 | + if (size == 1) { | ||
37 | + gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env, | ||
38 | + tcg_op, tcg_idx, tcg_res); | ||
39 | + } else { | ||
40 | + gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env, | ||
41 | + tcg_op, tcg_idx, tcg_res); | ||
42 | + } | ||
43 | + break; | ||
44 | + case 0x1f: /* SQRDMLSH */ | ||
45 | + read_vec_element_i32(s, tcg_res, rd, pass, | ||
46 | + is_scalar ? size : MO_32); | ||
47 | + if (size == 1) { | ||
48 | + gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env, | ||
49 | + tcg_op, tcg_idx, tcg_res); | ||
50 | + } else { | ||
51 | + gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env, | ||
52 | + tcg_op, tcg_idx, tcg_res); | ||
53 | + } | ||
54 | + break; | 34 | + break; |
55 | default: | 35 | default: |
56 | g_assert_not_reached(); | 36 | g_assert_not_reached(); |
57 | } | 37 | } |
58 | -- | 38 | -- |
59 | 2.16.2 | 39 | 2.20.1 |
60 | 40 | ||
61 | 41 | diff view generated by jsdifflib |
1 | The or-irq.h header file is missing the customary guard against | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | multiple inclusion, which means compilation fails if it gets | ||
3 | included twice. Fix the omission. | ||
4 | 2 | ||
3 | The real kernel collects _TIF_MTE_ASYNC_FAULT into the current thread's | ||
4 | state on any kernel entry (interrupt, exception etc), and then delivers | ||
5 | the signal in advance of resuming the thread. | ||
6 | |||
7 | This means that while the signal won't be delivered immediately, it will | ||
8 | not be delayed forever -- at minimum it will be delivered after the next | ||
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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180220180325.29818-11-peter.maydell@linaro.org | ||
9 | --- | 18 | --- |
10 | include/hw/or-irq.h | 5 +++++ | 19 | linux-user/aarch64/target_signal.h | 1 + |
11 | 1 file changed, 5 insertions(+) | 20 | linux-user/aarch64/cpu_loop.c | 11 +++++++++++ |
21 | target/arm/mte_helper.c | 10 ++++++++++ | ||
22 | 3 files changed, 22 insertions(+) | ||
12 | 23 | ||
13 | diff --git a/include/hw/or-irq.h b/include/hw/or-irq.h | 24 | diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h |
14 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/or-irq.h | 26 | --- a/linux-user/aarch64/target_signal.h |
16 | +++ b/include/hw/or-irq.h | 27 | +++ b/linux-user/aarch64/target_signal.h |
17 | @@ -XXX,XX +XXX,XX @@ | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
18 | * THE SOFTWARE. | 29 | |
19 | */ | 30 | #include "../generic/signal.h" |
20 | 31 | ||
21 | +#ifndef HW_OR_IRQ_H | 32 | +#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */ |
22 | +#define HW_OR_IRQ_H | 33 | #define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
34 | |||
35 | #define TARGET_ARCH_HAS_SETUP_FRAME | ||
36 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/linux-user/aarch64/cpu_loop.c | ||
39 | +++ b/linux-user/aarch64/cpu_loop.c | ||
40 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) | ||
41 | EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr); | ||
42 | abort(); | ||
43 | } | ||
23 | + | 44 | + |
24 | #include "hw/irq.h" | 45 | + /* Check for MTE asynchronous faults */ |
25 | #include "hw/sysbus.h" | 46 | + if (unlikely(env->cp15.tfsr_el[0])) { |
26 | #include "qom/object.h" | 47 | + env->cp15.tfsr_el[0] = 0; |
27 | @@ -XXX,XX +XXX,XX @@ struct OrIRQState { | 48 | + info.si_signo = TARGET_SIGSEGV; |
28 | bool levels[MAX_OR_LINES]; | 49 | + info.si_errno = 0; |
29 | uint16_t num_lines; | 50 | + info._sifields._sigfault._addr = 0; |
30 | }; | 51 | + info.si_code = TARGET_SEGV_MTEAERR; |
52 | + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | ||
53 | + } | ||
31 | + | 54 | + |
55 | process_pending_signals(env); | ||
56 | /* Exception return on AArch64 always clears the exclusive monitor, | ||
57 | * so any return to running guest code implies this. | ||
58 | diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/arm/mte_helper.c | ||
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)); | ||
32 | +#endif | 75 | +#endif |
76 | break; | ||
77 | |||
78 | default: | ||
33 | -- | 79 | -- |
34 | 2.16.2 | 80 | 2.20.1 |
35 | 81 | ||
36 | 82 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Use the now-saved PAGE_ANON and PAGE_MTE bits, | ||
4 | and the per-page saved data. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Message-id: 20210212184902.1251044-30-richard.henderson@linaro.org |
5 | Message-id: 20180228193125.20577-14-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ | 11 | target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++-- |
9 | 1 file changed, 68 insertions(+) | 12 | 1 file changed, 27 insertions(+), 2 deletions(-) |
10 | 13 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 16 | --- a/target/arm/mte_helper.c |
14 | +++ b/target/arm/translate.c | 17 | +++ b/target/arm/mte_helper.c |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, |
16 | return 0; | 19 | int tag_size, uintptr_t ra) |
17 | } | 20 | { |
18 | 21 | #ifdef CONFIG_USER_ONLY | |
19 | +/* Advanced SIMD three registers of the same length extension. | 22 | - /* Tag storage not implemented. */ |
20 | + * 31 25 23 22 20 16 12 11 10 9 8 3 0 | 23 | - return NULL; |
21 | + * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+ | 24 | + uint64_t clean_ptr = useronly_clean_ptr(ptr); |
22 | + * | 1 1 1 1 1 1 0 | op1 | D | op2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm | | 25 | + int flags = page_get_flags(clean_ptr); |
23 | + * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+ | 26 | + uint8_t *tags; |
24 | + */ | 27 | + uintptr_t index; |
25 | +static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
26 | +{ | ||
27 | + gen_helper_gvec_3_ptr *fn_gvec_ptr; | ||
28 | + int rd, rn, rm, rot, size, opr_sz; | ||
29 | + TCGv_ptr fpst; | ||
30 | + bool q; | ||
31 | + | 28 | + |
32 | + q = extract32(insn, 6, 1); | 29 | + if (!(flags & (ptr_access == MMU_DATA_STORE ? PAGE_WRITE : PAGE_READ))) { |
33 | + VFP_DREG_D(rd, insn); | 30 | + /* SIGSEGV */ |
34 | + VFP_DREG_N(rn, insn); | 31 | + arm_cpu_tlb_fill(env_cpu(env), ptr, ptr_size, ptr_access, |
35 | + VFP_DREG_M(rm, insn); | 32 | + ptr_mmu_idx, false, ra); |
36 | + if ((rd | rn | rm) & q) { | 33 | + g_assert_not_reached(); |
37 | + return 1; | ||
38 | + } | 34 | + } |
39 | + | 35 | + |
40 | + if ((insn & 0xfe200f10) == 0xfc200800) { | 36 | + /* Require both MAP_ANON and PROT_MTE for the page. */ |
41 | + /* VCMLA -- 1111 110R R.1S .... .... 1000 ...0 .... */ | 37 | + if (!(flags & PAGE_ANON) || !(flags & PAGE_MTE)) { |
42 | + size = extract32(insn, 20, 1); | 38 | + return NULL; |
43 | + rot = extract32(insn, 23, 2); | ||
44 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA) | ||
45 | + || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
46 | + return 1; | ||
47 | + } | ||
48 | + fn_gvec_ptr = size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah; | ||
49 | + } else if ((insn & 0xfea00f10) == 0xfc800800) { | ||
50 | + /* VCADD -- 1111 110R 1.0S .... .... 1000 ...0 .... */ | ||
51 | + size = extract32(insn, 20, 1); | ||
52 | + rot = extract32(insn, 24, 1); | ||
53 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA) | ||
54 | + || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
55 | + return 1; | ||
56 | + } | ||
57 | + fn_gvec_ptr = size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh; | ||
58 | + } else { | ||
59 | + return 1; | ||
60 | + } | 39 | + } |
61 | + | 40 | + |
62 | + if (s->fp_excp_el) { | 41 | + tags = page_get_target_data(clean_ptr); |
63 | + gen_exception_insn(s, 4, EXCP_UDEF, | 42 | + if (tags == NULL) { |
64 | + syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | 43 | + size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); |
65 | + return 0; | 44 | + tags = page_alloc_target_data(clean_ptr, alloc_size); |
66 | + } | 45 | + assert(tags != NULL); |
67 | + if (!s->vfp_enabled) { | ||
68 | + return 1; | ||
69 | + } | 46 | + } |
70 | + | 47 | + |
71 | + opr_sz = (1 + q) * 8; | 48 | + index = extract32(ptr, LOG2_TAG_GRANULE + 1, |
72 | + fpst = get_fpstatus_ptr(1); | 49 | + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); |
73 | + tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd), | 50 | + return tags + index; |
74 | + vfp_reg_offset(1, rn), | 51 | #else |
75 | + vfp_reg_offset(1, rm), fpst, | 52 | uintptr_t index; |
76 | + opr_sz, opr_sz, rot, fn_gvec_ptr); | 53 | CPUIOTLBEntry *iotlbentry; |
77 | + tcg_temp_free_ptr(fpst); | ||
78 | + return 0; | ||
79 | +} | ||
80 | + | ||
81 | static int disas_coproc_insn(DisasContext *s, uint32_t insn) | ||
82 | { | ||
83 | int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2; | ||
84 | @@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | + } else if ((insn & 0x0e000a00) == 0x0c000800 | ||
89 | + && arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
90 | + if (disas_neon_insn_3same_ext(s, insn)) { | ||
91 | + goto illegal_op; | ||
92 | + } | ||
93 | + return; | ||
94 | } else if ((insn & 0x0fe00000) == 0x0c400000) { | ||
95 | /* Coprocessor double register transfer. */ | ||
96 | ARCH(5TE); | ||
97 | -- | 54 | -- |
98 | 2.16.2 | 55 | 2.20.1 |
99 | 56 | ||
100 | 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 | Enable it for the "any" CPU used by *-linux-user. | 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 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Message-id: 20210212184902.1251044-31-richard.henderson@linaro.org |
7 | Message-id: 20180228193125.20577-10-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 | target/arm/cpu.c | 1 + | 8 | target/arm/cpu.c | 15 +++++++++++++++ |
11 | target/arm/cpu64.c | 1 + | 9 | 1 file changed, 15 insertions(+) |
12 | 2 files changed, 2 insertions(+) | ||
13 | 10 | ||
14 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.c | 13 | --- a/target/arm/cpu.c |
17 | +++ b/target/arm/cpu.c | 14 | +++ b/target/arm/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj) | 15 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
19 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | 16 | * Note that this must match useronly_clean_ptr. |
20 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 17 | */ |
21 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 18 | env->cp15.tcr_el[1].raw_tcr = (1ULL << 37); |
22 | + set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | 19 | + |
23 | cpu->midr = 0xffffffff; | 20 | + /* Enable MTE */ |
24 | } | 21 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
25 | #endif | 22 | + /* Enable tag access, but leave TCF0 as No Effect (0). */ |
26 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 23 | + env->cp15.sctlr_el[1] |= SCTLR_ATA0; |
27 | index XXXXXXX..XXXXXXX 100644 | 24 | + /* |
28 | --- a/target/arm/cpu64.c | 25 | + * Exclude all tags, so that tag 0 is always used. |
29 | +++ b/target/arm/cpu64.c | 26 | + * This corresponds to Linux current->thread.gcr_incl = 0. |
30 | @@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj) | 27 | + * |
31 | set_feature(&cpu->env, ARM_FEATURE_V8_SM4); | 28 | + * Set RRND, so that helper_irg() will generate a seed later. |
32 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 29 | + * Here in cpu_reset(), the crypto subsystem has not yet been |
33 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 30 | + * initialized. |
34 | + set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | 31 | + */ |
35 | set_feature(&cpu->env, ARM_FEATURE_V8_FP16); | 32 | + env->cp15.gcr_el1 = 0x1ffff; |
36 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | 33 | + } |
37 | cpu->dcz_blocksize = 7; /* 512 bytes */ | 34 | #else |
35 | /* Reset into the highest available EL */ | ||
36 | if (arm_feature(env, ARM_FEATURE_EL3)) { | ||
38 | -- | 37 | -- |
39 | 2.16.2 | 38 | 2.20.1 |
40 | 39 | ||
41 | 40 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | 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> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20180228193125.20577-8-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-32-richard.henderson@linaro.org |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 7 | --- |
8 | target/arm/translate.c | 86 +++++++++++++++++++++++++++++++++++++++----------- | 8 | tests/tcg/aarch64/mte.h | 60 +++++++++++++++++++++++++++++++ |
9 | 1 file changed, 67 insertions(+), 19 deletions(-) | 9 | tests/tcg/aarch64/mte-1.c | 28 +++++++++++++++ |
10 | tests/tcg/aarch64/mte-2.c | 45 +++++++++++++++++++++++ | ||
11 | tests/tcg/aarch64/mte-3.c | 51 ++++++++++++++++++++++++++ | ||
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 | ||
10 | 21 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 22 | diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h |
23 | new file mode 100644 | ||
24 | index XXXXXXX..XXXXXXX | ||
25 | --- /dev/null | ||
26 | +++ b/tests/tcg/aarch64/mte.h | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | +/* | ||
29 | + * Linux kernel fallback API definitions for MTE and test helpers. | ||
30 | + * | ||
31 | + * Copyright (c) 2021 Linaro Ltd | ||
32 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
33 | + */ | ||
34 | + | ||
35 | +#include <assert.h> | ||
36 | +#include <string.h> | ||
37 | +#include <stdlib.h> | ||
38 | +#include <stdio.h> | ||
39 | +#include <unistd.h> | ||
40 | +#include <signal.h> | ||
41 | +#include <sys/mman.h> | ||
42 | +#include <sys/prctl.h> | ||
43 | + | ||
44 | +#ifndef PR_SET_TAGGED_ADDR_CTRL | ||
45 | +# define PR_SET_TAGGED_ADDR_CTRL 55 | ||
46 | +#endif | ||
47 | +#ifndef PR_TAGGED_ADDR_ENABLE | ||
48 | +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) | ||
49 | +#endif | ||
50 | +#ifndef PR_MTE_TCF_SHIFT | ||
51 | +# define PR_MTE_TCF_SHIFT 1 | ||
52 | +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) | ||
53 | +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) | ||
54 | +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) | ||
55 | +# define PR_MTE_TAG_SHIFT 3 | ||
56 | +#endif | ||
57 | + | ||
58 | +#ifndef PROT_MTE | ||
59 | +# define PROT_MTE 0x20 | ||
60 | +#endif | ||
61 | + | ||
62 | +#ifndef SEGV_MTEAERR | ||
63 | +# define SEGV_MTEAERR 8 | ||
64 | +# define SEGV_MTESERR 9 | ||
65 | +#endif | ||
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); | ||
75 | + } | ||
76 | +} | ||
77 | + | ||
78 | +static void *alloc_mte_mem(size_t size) | ||
79 | +{ | ||
80 | + void *p = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_MTE, | ||
81 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
82 | + if (p == MAP_FAILED) { | ||
83 | + perror("mmap PROT_MTE"); | ||
84 | + exit(2); | ||
85 | + } | ||
86 | + return p; | ||
87 | +} | ||
88 | diff --git a/tests/tcg/aarch64/mte-1.c b/tests/tcg/aarch64/mte-1.c | ||
89 | new file mode 100644 | ||
90 | index XXXXXXX..XXXXXXX | ||
91 | --- /dev/null | ||
92 | +++ b/tests/tcg/aarch64/mte-1.c | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | +/* | ||
95 | + * Memory tagging, basic pass cases. | ||
96 | + * | ||
97 | + * Copyright (c) 2021 Linaro Ltd | ||
98 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
99 | + */ | ||
100 | + | ||
101 | +#include "mte.h" | ||
102 | + | ||
103 | +int main(int ac, char **av) | ||
104 | +{ | ||
105 | + int *p0, *p1, *p2; | ||
106 | + long c; | ||
107 | + | ||
108 | + enable_mte(PR_MTE_TCF_NONE); | ||
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 | ||
12 | index XXXXXXX..XXXXXXX 100644 | 282 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 283 | --- a/tests/tcg/aarch64/Makefile.target |
14 | +++ b/target/arm/translate.c | 284 | +++ b/tests/tcg/aarch64/Makefile.target |
15 | @@ -XXX,XX +XXX,XX @@ | 285 | @@ -XXX,XX +XXX,XX @@ endif |
16 | #include "disas/disas.h" | 286 | # bti-2 tests PROT_BTI, so no special compiler support required. |
17 | #include "exec/exec-all.h" | 287 | AARCH64_TESTS += bti-2 |
18 | #include "tcg-op.h" | 288 | |
19 | +#include "tcg-op-gvec.h" | 289 | +# MTE Tests |
20 | #include "qemu/log.h" | 290 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),) |
21 | #include "qemu/bitops.h" | 291 | +AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 |
22 | #include "arm_ldst.h" | 292 | +mte-%: CFLAGS += -march=armv8.5-a+memtag |
23 | @@ -XXX,XX +XXX,XX @@ static void gen_neon_narrow_op(int op, int u, int size, | 293 | +endif |
24 | #define NEON_3R_VPMAX 20 | 294 | + |
25 | #define NEON_3R_VPMIN 21 | 295 | # Semihosting smoke test for linux-user |
26 | #define NEON_3R_VQDMULH_VQRDMULH 22 | 296 | AARCH64_TESTS += semihosting |
27 | -#define NEON_3R_VPADD 23 | 297 | run-semihosting: semihosting |
28 | +#define NEON_3R_VPADD_VQRDMLAH 23 | 298 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
29 | #define NEON_3R_SHA 24 /* SHA1C,SHA1P,SHA1M,SHA1SU0,SHA256H{2},SHA256SU1 */ | 299 | index XXXXXXX..XXXXXXX 100755 |
30 | -#define NEON_3R_VFM 25 /* VFMA, VFMS : float fused multiply-add */ | 300 | --- a/tests/tcg/configure.sh |
31 | +#define NEON_3R_VFM_VQRDMLSH 25 /* VFMA, VFMS, VQRDMLSH */ | 301 | +++ b/tests/tcg/configure.sh |
32 | #define NEON_3R_FLOAT_ARITH 26 /* float VADD, VSUB, VPADD, VABD */ | 302 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do |
33 | #define NEON_3R_FLOAT_MULTIPLY 27 /* float VMLA, VMLS, VMUL */ | 303 | -mbranch-protection=standard -o $TMPE $TMPC; then |
34 | #define NEON_3R_FLOAT_CMP 28 /* float VCEQ, VCGE, VCGT */ | 304 | echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak |
35 | @@ -XXX,XX +XXX,XX @@ static const uint8_t neon_3r_sizes[] = { | 305 | fi |
36 | [NEON_3R_VPMAX] = 0x7, | 306 | + if do_compiler "$target_compiler" $target_compiler_cflags \ |
37 | [NEON_3R_VPMIN] = 0x7, | 307 | + -march=armv8.5-a+memtag -o $TMPE $TMPC; then |
38 | [NEON_3R_VQDMULH_VQRDMULH] = 0x6, | 308 | + echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak |
39 | - [NEON_3R_VPADD] = 0x7, | 309 | + fi |
40 | + [NEON_3R_VPADD_VQRDMLAH] = 0x7, | 310 | ;; |
41 | [NEON_3R_SHA] = 0xf, /* size field encodes op type */ | 311 | esac |
42 | - [NEON_3R_VFM] = 0x5, /* size bit 1 encodes op */ | 312 | |
43 | + [NEON_3R_VFM_VQRDMLSH] = 0x7, /* For VFM, size bit 1 encodes op */ | ||
44 | [NEON_3R_FLOAT_ARITH] = 0x5, /* size bit 1 encodes op */ | ||
45 | [NEON_3R_FLOAT_MULTIPLY] = 0x5, /* size bit 1 encodes op */ | ||
46 | [NEON_3R_FLOAT_CMP] = 0x5, /* size bit 1 encodes op */ | ||
47 | @@ -XXX,XX +XXX,XX @@ static const uint8_t neon_2rm_sizes[] = { | ||
48 | [NEON_2RM_VCVT_UF] = 0x4, | ||
49 | }; | ||
50 | |||
51 | + | ||
52 | +/* Expand v8.1 simd helper. */ | ||
53 | +static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn, | ||
54 | + int q, int rd, int rn, int rm) | ||
55 | +{ | ||
56 | + if (arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | ||
57 | + int opr_sz = (1 + q) * 8; | ||
58 | + tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd), | ||
59 | + vfp_reg_offset(1, rn), | ||
60 | + vfp_reg_offset(1, rm), cpu_env, | ||
61 | + opr_sz, opr_sz, 0, fn); | ||
62 | + return 0; | ||
63 | + } | ||
64 | + return 1; | ||
65 | +} | ||
66 | + | ||
67 | /* Translate a NEON data processing instruction. Return nonzero if the | ||
68 | instruction is invalid. | ||
69 | We process data in a mixture of 32-bit and 64-bit chunks. | ||
70 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
71 | if (q && ((rd | rn | rm) & 1)) { | ||
72 | return 1; | ||
73 | } | ||
74 | - /* | ||
75 | - * The SHA-1/SHA-256 3-register instructions require special treatment | ||
76 | - * here, as their size field is overloaded as an op type selector, and | ||
77 | - * they all consume their input in a single pass. | ||
78 | - */ | ||
79 | - if (op == NEON_3R_SHA) { | ||
80 | + switch (op) { | ||
81 | + case NEON_3R_SHA: | ||
82 | + /* The SHA-1/SHA-256 3-register instructions require special | ||
83 | + * treatment here, as their size field is overloaded as an | ||
84 | + * op type selector, and they all consume their input in a | ||
85 | + * single pass. | ||
86 | + */ | ||
87 | if (!q) { | ||
88 | return 1; | ||
89 | } | ||
90 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
91 | tcg_temp_free_ptr(ptr2); | ||
92 | tcg_temp_free_ptr(ptr3); | ||
93 | return 0; | ||
94 | + | ||
95 | + case NEON_3R_VPADD_VQRDMLAH: | ||
96 | + if (!u) { | ||
97 | + break; /* VPADD */ | ||
98 | + } | ||
99 | + /* VQRDMLAH */ | ||
100 | + switch (size) { | ||
101 | + case 1: | ||
102 | + return do_v81_helper(s, gen_helper_gvec_qrdmlah_s16, | ||
103 | + q, rd, rn, rm); | ||
104 | + case 2: | ||
105 | + return do_v81_helper(s, gen_helper_gvec_qrdmlah_s32, | ||
106 | + q, rd, rn, rm); | ||
107 | + } | ||
108 | + return 1; | ||
109 | + | ||
110 | + case NEON_3R_VFM_VQRDMLSH: | ||
111 | + if (!u) { | ||
112 | + /* VFM, VFMS */ | ||
113 | + if (size == 1) { | ||
114 | + return 1; | ||
115 | + } | ||
116 | + break; | ||
117 | + } | ||
118 | + /* VQRDMLSH */ | ||
119 | + switch (size) { | ||
120 | + case 1: | ||
121 | + return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s16, | ||
122 | + q, rd, rn, rm); | ||
123 | + case 2: | ||
124 | + return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s32, | ||
125 | + q, rd, rn, rm); | ||
126 | + } | ||
127 | + return 1; | ||
128 | } | ||
129 | if (size == 3 && op != NEON_3R_LOGIC) { | ||
130 | /* 64-bit element instructions. */ | ||
131 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
132 | rm = rtmp; | ||
133 | } | ||
134 | break; | ||
135 | - case NEON_3R_VPADD: | ||
136 | - if (u) { | ||
137 | - return 1; | ||
138 | - } | ||
139 | - /* Fall through */ | ||
140 | + case NEON_3R_VPADD_VQRDMLAH: | ||
141 | case NEON_3R_VPMAX: | ||
142 | case NEON_3R_VPMIN: | ||
143 | pairwise = 1; | ||
144 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
145 | return 1; | ||
146 | } | ||
147 | break; | ||
148 | - case NEON_3R_VFM: | ||
149 | - if (!arm_dc_feature(s, ARM_FEATURE_VFP4) || u) { | ||
150 | + case NEON_3R_VFM_VQRDMLSH: | ||
151 | + if (!arm_dc_feature(s, ARM_FEATURE_VFP4)) { | ||
152 | return 1; | ||
153 | } | ||
154 | break; | ||
155 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
156 | } | ||
157 | } | ||
158 | break; | ||
159 | - case NEON_3R_VPADD: | ||
160 | + case NEON_3R_VPADD_VQRDMLAH: | ||
161 | switch (size) { | ||
162 | case 0: gen_helper_neon_padd_u8(tmp, tmp, tmp2); break; | ||
163 | case 1: gen_helper_neon_padd_u16(tmp, tmp, tmp2); break; | ||
164 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
165 | } | ||
166 | } | ||
167 | break; | ||
168 | - case NEON_3R_VFM: | ||
169 | + case NEON_3R_VFM_VQRDMLSH: | ||
170 | { | ||
171 | /* VFMA, VFMS: fused multiply-add */ | ||
172 | TCGv_ptr fpstatus = get_fpstatus_ptr(1); | ||
173 | -- | 313 | -- |
174 | 2.16.2 | 314 | 2.20.1 |
175 | 315 | ||
176 | 316 | diff view generated by jsdifflib |
1 | In some board or SoC models it is necessary to split a qemu_irq line | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | so that one input can feed multiple outputs. We currently have | ||
3 | qemu_irq_split() for this, but that has several deficiencies: | ||
4 | * it can only handle splitting a line into two | ||
5 | * it unavoidably leaks memory, so it can't be used | ||
6 | in a device that can be deleted | ||
7 | 2 | ||
8 | Implement a qdev device that encapsulates splitting of IRQs, with a | 3 | This commit implements the single-byte mode of the SMBus. |
9 | configurable number of outputs. (This is in some ways the inverse of | ||
10 | the TYPE_OR_IRQ device.) | ||
11 | 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> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20180220180325.29818-13-peter.maydell@linaro.org | ||
15 | --- | 20 | --- |
16 | hw/core/Makefile.objs | 1 + | 21 | docs/system/arm/nuvoton.rst | 2 +- |
17 | include/hw/core/split-irq.h | 57 +++++++++++++++++++++++++++++ | 22 | include/hw/arm/npcm7xx.h | 2 + |
18 | include/hw/irq.h | 4 +- | 23 | include/hw/i2c/npcm7xx_smbus.h | 88 ++++ |
19 | hw/core/split-irq.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ | 24 | hw/arm/npcm7xx.c | 68 ++- |
20 | 4 files changed, 150 insertions(+), 1 deletion(-) | 25 | hw/i2c/npcm7xx_smbus.c | 783 +++++++++++++++++++++++++++++++++ |
21 | create mode 100644 include/hw/core/split-irq.h | 26 | hw/i2c/meson.build | 1 + |
22 | create mode 100644 hw/core/split-irq.c | 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 | ||
23 | 31 | ||
24 | diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
25 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/core/Makefile.objs | 34 | --- a/docs/system/arm/nuvoton.rst |
27 | +++ b/hw/core/Makefile.objs | 35 | +++ b/docs/system/arm/nuvoton.rst |
28 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_FITLOADER) += loader-fit.o | 36 | @@ -XXX,XX +XXX,XX @@ Supported devices |
29 | common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o | 37 | * GPIO controller |
30 | common-obj-$(CONFIG_SOFTMMU) += register.o | 38 | * Analog to Digital Converter (ADC) |
31 | common-obj-$(CONFIG_SOFTMMU) += or-irq.o | 39 | * Pulse Width Modulation (PWM) |
32 | +common-obj-$(CONFIG_SOFTMMU) += split-irq.o | 40 | + * SMBus controller (SMBF) |
33 | common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o | 41 | |
34 | 42 | Missing devices | |
35 | obj-$(CONFIG_SOFTMMU) += generic-loader.o | 43 | --------------- |
36 | diff --git a/include/hw/core/split-irq.h b/include/hw/core/split-irq.h | 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 | ||
37 | new file mode 100644 | 73 | new file mode 100644 |
38 | index XXXXXXX..XXXXXXX | 74 | index XXXXXXX..XXXXXXX |
39 | --- /dev/null | 75 | --- /dev/null |
40 | +++ b/include/hw/core/split-irq.h | 76 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
41 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ |
42 | +/* | 78 | +/* |
43 | + * IRQ splitter device. | 79 | + * Nuvoton NPCM7xx SMBus Module. |
44 | + * | 80 | + * |
45 | + * Copyright (c) 2018 Linaro Limited. | 81 | + * Copyright 2020 Google LLC |
46 | + * Written by Peter Maydell | ||
47 | + * | 82 | + * |
48 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 83 | + * This program is free software; you can redistribute it and/or modify it |
49 | + * of this software and associated documentation files (the "Software"), to deal | 84 | + * under the terms of the GNU General Public License as published by the |
50 | + * in the Software without restriction, including without limitation the rights | 85 | + * Free Software Foundation; either version 2 of the License, or |
51 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 86 | + * (at your option) any later version. |
52 | + * copies of the Software, and to permit persons to whom the Software is | ||
53 | + * furnished to do so, subject to the following conditions: | ||
54 | + * | 87 | + * |
55 | + * The above copyright notice and this permission notice shall be included in | 88 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
56 | + * all copies or substantial portions of the Software. | 89 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
57 | + * | 90 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
58 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 91 | + * for more details. |
59 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
60 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
61 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
62 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
63 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
64 | + * THE SOFTWARE. | ||
65 | + */ | 92 | + */ |
66 | + | 93 | +#ifndef NPCM7XX_SMBUS_H |
67 | +/* This is a simple device which has one GPIO input line and multiple | 94 | +#define NPCM7XX_SMBUS_H |
68 | + * GPIO output lines. Any change on the input line is forwarded to all | 95 | + |
69 | + * of the outputs. | 96 | +#include "exec/memory.h" |
70 | + * | 97 | +#include "hw/i2c/i2c.h" |
71 | + * QEMU interface: | ||
72 | + * + one unnamed GPIO input: the input line | ||
73 | + * + N unnamed GPIO outputs: the output lines | ||
74 | + * + QOM property "num-lines": sets the number of output lines | ||
75 | + */ | ||
76 | +#ifndef HW_SPLIT_IRQ_H | ||
77 | +#define HW_SPLIT_IRQ_H | ||
78 | + | ||
79 | +#include "hw/irq.h" | 98 | +#include "hw/irq.h" |
80 | +#include "hw/sysbus.h" | 99 | +#include "hw/sysbus.h" |
81 | +#include "qom/object.h" | 100 | + |
82 | + | 101 | +/* |
83 | +#define TYPE_SPLIT_IRQ "split-irq" | 102 | + * Number of addresses this module contains. Do not change this without |
84 | + | 103 | + * incrementing the version_id in the vmstate. |
85 | +#define MAX_SPLIT_LINES 16 | 104 | + */ |
86 | + | 105 | +#define NPCM7XX_SMBUS_NR_ADDRS 10 |
87 | +typedef struct SplitIRQ SplitIRQ; | 106 | + |
88 | + | 107 | +typedef enum NPCM7xxSMBusStatus { |
89 | +#define SPLIT_IRQ(obj) OBJECT_CHECK(SplitIRQ, (obj), TYPE_SPLIT_IRQ) | 108 | + NPCM7XX_SMBUS_STATUS_IDLE, |
90 | + | 109 | + NPCM7XX_SMBUS_STATUS_SENDING, |
91 | +struct SplitIRQ { | 110 | + NPCM7XX_SMBUS_STATUS_RECEIVING, |
92 | + DeviceState parent_obj; | 111 | + NPCM7XX_SMBUS_STATUS_NEGACK, |
93 | + | 112 | + NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE, |
94 | + qemu_irq out_irq[MAX_SPLIT_LINES]; | 113 | + NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK, |
95 | + uint16_t num_lines; | 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, | ||
96 | +}; | 215 | +}; |
97 | + | 216 | + |
98 | +#endif | 217 | static const struct { |
99 | diff --git a/include/hw/irq.h b/include/hw/irq.h | 218 | hwaddr regs_addr; |
100 | index XXXXXXX..XXXXXXX 100644 | 219 | uint32_t unconnected_pins; |
101 | --- a/include/hw/irq.h | 220 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
102 | +++ b/include/hw/irq.h | 221 | object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); |
103 | @@ -XXX,XX +XXX,XX @@ void qemu_free_irq(qemu_irq irq); | 222 | } |
104 | /* Returns a new IRQ with opposite polarity. */ | 223 | |
105 | qemu_irq qemu_irq_invert(qemu_irq irq); | 224 | + for (i = 0; i < ARRAY_SIZE(s->smbus); i++) { |
106 | 225 | + object_initialize_child(obj, "smbus[*]", &s->smbus[i], | |
107 | -/* Returns a new IRQ which feeds into both the passed IRQs */ | 226 | + TYPE_NPCM7XX_SMBUS); |
108 | +/* Returns a new IRQ which feeds into both the passed IRQs. | 227 | + } |
109 | + * It's probably better to use the TYPE_SPLIT_IRQ device instead. | 228 | + |
110 | + */ | 229 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); |
111 | qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2); | 230 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); |
112 | 231 | ||
113 | /* Returns a new IRQ set which connects 1:1 to another IRQ set, which | 232 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
114 | diff --git a/hw/core/split-irq.c b/hw/core/split-irq.c | 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 | ||
115 | new file mode 100644 | 274 | new file mode 100644 |
116 | index XXXXXXX..XXXXXXX | 275 | index XXXXXXX..XXXXXXX |
117 | --- /dev/null | 276 | --- /dev/null |
118 | +++ b/hw/core/split-irq.c | 277 | +++ b/hw/i2c/npcm7xx_smbus.c |
119 | @@ -XXX,XX +XXX,XX @@ | 278 | @@ -XXX,XX +XXX,XX @@ |
120 | +/* | 279 | +/* |
121 | + * IRQ splitter device. | 280 | + * Nuvoton NPCM7xx SMBus Module. |
122 | + * | 281 | + * |
123 | + * Copyright (c) 2018 Linaro Limited. | 282 | + * Copyright 2020 Google LLC |
124 | + * Written by Peter Maydell | ||
125 | + * | 283 | + * |
126 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 284 | + * This program is free software; you can redistribute it and/or modify it |
127 | + * of this software and associated documentation files (the "Software"), to deal | 285 | + * under the terms of the GNU General Public License as published by the |
128 | + * in the Software without restriction, including without limitation the rights | 286 | + * Free Software Foundation; either version 2 of the License, or |
129 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 287 | + * (at your option) any later version. |
130 | + * copies of the Software, and to permit persons to whom the Software is | ||
131 | + * furnished to do so, subject to the following conditions: | ||
132 | + * | 288 | + * |
133 | + * The above copyright notice and this permission notice shall be included in | 289 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
134 | + * all copies or substantial portions of the Software. | 290 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
135 | + * | 291 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
136 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 292 | + * for more details. |
137 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
138 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
139 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
140 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
141 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
142 | + * THE SOFTWARE. | ||
143 | + */ | 293 | + */ |
144 | + | 294 | + |
145 | +#include "qemu/osdep.h" | 295 | +#include "qemu/osdep.h" |
146 | +#include "hw/core/split-irq.h" | 296 | + |
147 | +#include "qapi/error.h" | 297 | +#include "hw/i2c/npcm7xx_smbus.h" |
148 | + | 298 | +#include "migration/vmstate.h" |
149 | +static void split_irq_handler(void *opaque, int n, int level) | 299 | +#include "qemu/bitops.h" |
150 | +{ | 300 | +#include "qemu/guest-random.h" |
151 | + SplitIRQ *s = SPLIT_IRQ(opaque); | 301 | +#include "qemu/log.h" |
152 | + int i; | 302 | +#include "qemu/module.h" |
153 | + | 303 | +#include "qemu/units.h" |
154 | + for (i = 0; i < s->num_lines; i++) { | 304 | + |
155 | + qemu_set_irq(s->out_irq[i], level); | 305 | +#include "trace.h" |
156 | + } | 306 | + |
157 | +} | 307 | +enum NPCM7xxSMBusCommonRegister { |
158 | + | 308 | + NPCM7XX_SMB_SDA = 0x0, |
159 | +static void split_irq_init(Object *obj) | 309 | + NPCM7XX_SMB_ST = 0x2, |
160 | +{ | 310 | + NPCM7XX_SMB_CST = 0x4, |
161 | + qdev_init_gpio_in(DEVICE(obj), split_irq_handler, 1); | 311 | + NPCM7XX_SMB_CTL1 = 0x6, |
162 | +} | 312 | + NPCM7XX_SMB_ADDR1 = 0x8, |
163 | + | 313 | + NPCM7XX_SMB_CTL2 = 0xa, |
164 | +static void split_irq_realize(DeviceState *dev, Error **errp) | 314 | + NPCM7XX_SMB_ADDR2 = 0xc, |
165 | +{ | 315 | + NPCM7XX_SMB_CTL3 = 0xe, |
166 | + SplitIRQ *s = SPLIT_IRQ(dev); | 316 | + NPCM7XX_SMB_CST2 = 0x18, |
167 | + | 317 | + NPCM7XX_SMB_CST3 = 0x19, |
168 | + if (s->num_lines < 1 || s->num_lines >= MAX_SPLIT_LINES) { | 318 | + NPCM7XX_SMB_VER = 0x1f, |
169 | + error_setg(errp, | 319 | +}; |
170 | + "IRQ splitter number of lines %d is not between 1 and %d", | 320 | + |
171 | + s->num_lines, MAX_SPLIT_LINES); | 321 | +enum NPCM7xxSMBusBank0Register { |
322 | + NPCM7XX_SMB_ADDR3 = 0x10, | ||
323 | + NPCM7XX_SMB_ADDR7 = 0x11, | ||
324 | + NPCM7XX_SMB_ADDR4 = 0x12, | ||
325 | + NPCM7XX_SMB_ADDR8 = 0x13, | ||
326 | + NPCM7XX_SMB_ADDR5 = 0x14, | ||
327 | + NPCM7XX_SMB_ADDR9 = 0x15, | ||
328 | + NPCM7XX_SMB_ADDR6 = 0x16, | ||
329 | + NPCM7XX_SMB_ADDR10 = 0x17, | ||
330 | + NPCM7XX_SMB_CTL4 = 0x1a, | ||
331 | + NPCM7XX_SMB_CTL5 = 0x1b, | ||
332 | + NPCM7XX_SMB_SCLLT = 0x1c, | ||
333 | + NPCM7XX_SMB_FIF_CTL = 0x1d, | ||
334 | + NPCM7XX_SMB_SCLHT = 0x1e, | ||
335 | +}; | ||
336 | + | ||
337 | +enum NPCM7xxSMBusBank1Register { | ||
338 | + NPCM7XX_SMB_FIF_CTS = 0x10, | ||
339 | + NPCM7XX_SMB_FAIR_PER = 0x11, | ||
340 | + NPCM7XX_SMB_TXF_CTL = 0x12, | ||
341 | + NPCM7XX_SMB_T_OUT = 0x14, | ||
342 | + NPCM7XX_SMB_TXF_STS = 0x1a, | ||
343 | + NPCM7XX_SMB_RXF_STS = 0x1c, | ||
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 | +{ | ||
498 | + /* | ||
499 | + * We can start the bus if one of these is true: | ||
500 | + * 1. The bus is idle (so we can request it) | ||
501 | + * 2. We are the occupier (it's a repeated start condition.) | ||
502 | + */ | ||
503 | + int available = !i2c_bus_busy(s->bus) || | ||
504 | + s->status != NPCM7XX_SMBUS_STATUS_IDLE; | ||
505 | + | ||
506 | + if (available) { | ||
507 | + s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST; | ||
508 | + s->cst |= NPCM7XX_SMBCST_BUSY; | ||
509 | + } else { | ||
510 | + s->st &= ~NPCM7XX_SMBST_MODE; | ||
511 | + s->cst &= ~NPCM7XX_SMBCST_BUSY; | ||
512 | + s->st |= NPCM7XX_SMBST_BER; | ||
513 | + } | ||
514 | + | ||
515 | + trace_npcm7xx_smbus_start(DEVICE(s)->canonical_path, available); | ||
516 | + s->cst |= NPCM7XX_SMBCST_BB; | ||
517 | + s->status = NPCM7XX_SMBUS_STATUS_IDLE; | ||
518 | + npcm7xx_smbus_update_irq(s); | ||
519 | +} | ||
520 | + | ||
521 | +static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value) | ||
522 | +{ | ||
523 | + int recv; | ||
524 | + int rv; | ||
525 | + | ||
526 | + recv = value & BIT(0); | ||
527 | + rv = i2c_start_transfer(s->bus, value >> 1, recv); | ||
528 | + trace_npcm7xx_smbus_send_address(DEVICE(s)->canonical_path, | ||
529 | + value >> 1, recv, !rv); | ||
530 | + if (rv) { | ||
531 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
532 | + "%s: requesting i2c bus for 0x%02x failed: %d\n", | ||
533 | + DEVICE(s)->canonical_path, value, rv); | ||
534 | + /* Failed to start transfer. NACK to reject.*/ | ||
535 | + if (recv) { | ||
536 | + s->st &= ~NPCM7XX_SMBST_XMIT; | ||
537 | + } else { | ||
538 | + s->st |= NPCM7XX_SMBST_XMIT; | ||
539 | + } | ||
540 | + npcm7xx_smbus_nack(s); | ||
541 | + npcm7xx_smbus_update_irq(s); | ||
172 | + return; | 542 | + return; |
173 | + } | 543 | + } |
174 | + | 544 | + |
175 | + qdev_init_gpio_out(dev, s->out_irq, s->num_lines); | 545 | + s->st &= ~NPCM7XX_SMBST_NEGACK; |
176 | +} | 546 | + if (recv) { |
177 | + | 547 | + s->status = NPCM7XX_SMBUS_STATUS_RECEIVING; |
178 | +static Property split_irq_properties[] = { | 548 | + s->st &= ~NPCM7XX_SMBST_XMIT; |
179 | + DEFINE_PROP_UINT16("num-lines", SplitIRQ, num_lines, 1), | 549 | + } else { |
180 | + DEFINE_PROP_END_OF_LIST(), | 550 | + s->status = NPCM7XX_SMBUS_STATUS_SENDING; |
551 | + s->st |= NPCM7XX_SMBST_XMIT; | ||
552 | + } | ||
553 | + | ||
554 | + if (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE) { | ||
555 | + s->st |= NPCM7XX_SMBST_STASTR; | ||
556 | + if (!recv) { | ||
557 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
558 | + } | ||
559 | + } else if (recv) { | ||
560 | + npcm7xx_smbus_recv_byte(s); | ||
561 | + } | ||
562 | + npcm7xx_smbus_update_irq(s); | ||
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 | + }, | ||
181 | +}; | 973 | +}; |
182 | + | 974 | + |
183 | +static void split_irq_class_init(ObjectClass *klass, void *data) | 975 | +static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type) |
184 | +{ | 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); | ||
185 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1044 | + DeviceClass *dc = DEVICE_CLASS(klass); |
186 | + | 1045 | + |
187 | + /* No state to reset or migrate */ | 1046 | + dc->desc = "NPCM7xx System Management Bus"; |
188 | + dc->props = split_irq_properties; | 1047 | + dc->vmsd = &vmstate_npcm7xx_smbus; |
189 | + dc->realize = split_irq_realize; | 1048 | + rc->phases.enter = npcm7xx_smbus_enter_reset; |
190 | + | 1049 | + rc->phases.hold = npcm7xx_smbus_hold_reset; |
191 | + /* Reason: Needs to be wired up to work */ | 1050 | +} |
192 | + dc->user_creatable = false; | 1051 | + |
193 | +} | 1052 | +static const TypeInfo npcm7xx_smbus_types[] = { |
194 | + | 1053 | + { |
195 | +static const TypeInfo split_irq_type_info = { | 1054 | + .name = TYPE_NPCM7XX_SMBUS, |
196 | + .name = TYPE_SPLIT_IRQ, | 1055 | + .parent = TYPE_SYS_BUS_DEVICE, |
197 | + .parent = TYPE_DEVICE, | 1056 | + .instance_size = sizeof(NPCM7xxSMBusState), |
198 | + .instance_size = sizeof(SplitIRQ), | 1057 | + .class_init = npcm7xx_smbus_class_init, |
199 | + .instance_init = split_irq_init, | 1058 | + .instance_init = npcm7xx_smbus_init, |
200 | + .class_init = split_irq_class_init, | 1059 | + }, |
201 | +}; | 1060 | +}; |
202 | + | 1061 | +DEFINE_TYPES(npcm7xx_smbus_types); |
203 | +static void split_irq_register_types(void) | 1062 | diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build |
204 | +{ | 1063 | index XXXXXXX..XXXXXXX 100644 |
205 | + type_register_static(&split_irq_type_info); | 1064 | --- a/hw/i2c/meson.build |
206 | +} | 1065 | +++ b/hw/i2c/meson.build |
207 | + | 1066 | @@ -XXX,XX +XXX,XX @@ i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) |
208 | +type_init(split_irq_register_types) | 1067 | i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c')) |
1068 | i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) | ||
1069 | i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) | ||
1070 | +i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c')) | ||
1071 | i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c')) | ||
1072 | i2c_ss.add(when: 'CONFIG_VERSATILE_I2C', if_true: files('versatile_i2c.c')) | ||
1073 | i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c')) | ||
1074 | diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events | ||
1075 | index XXXXXXX..XXXXXXX 100644 | ||
1076 | --- a/hw/i2c/trace-events | ||
1077 | +++ b/hw/i2c/trace-events | ||
1078 | @@ -XXX,XX +XXX,XX @@ aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t val | ||
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 | ||
1080 | aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" | ||
1081 | aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x" | ||
1082 | + | ||
1083 | +# npcm7xx_smbus.c | ||
1084 | + | ||
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" | ||
209 | -- | 1093 | -- |
210 | 2.16.2 | 1094 | 2.20.1 |
211 | 1095 | ||
212 | 1096 | diff view generated by jsdifflib |
1 | The IoTKit Security Controller includes various registers | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | that expose to software the controls for the Peripheral | ||
3 | Protection Controllers in the system. Implement these. | ||
4 | 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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20180220180325.29818-17-peter.maydell@linaro.org | ||
8 | --- | 11 | --- |
9 | include/hw/misc/iotkit-secctl.h | 64 +++++++++- | 12 | hw/arm/npcm7xx_boards.c | 19 +++++++++++++++++++ |
10 | hw/misc/iotkit-secctl.c | 270 +++++++++++++++++++++++++++++++++++++--- | 13 | 1 file changed, 19 insertions(+) |
11 | 2 files changed, 315 insertions(+), 19 deletions(-) | ||
12 | 14 | ||
13 | diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h | 15 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/misc/iotkit-secctl.h | 17 | --- a/hw/arm/npcm7xx_boards.c |
16 | +++ b/include/hw/misc/iotkit-secctl.h | 18 | +++ b/hw/arm/npcm7xx_boards.c |
17 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, |
18 | * QEMU interface: | 20 | return NPCM7XX(obj); |
19 | * + sysbus MMIO region 0 is the "secure privilege control block" registers | 21 | } |
20 | * + sysbus MMIO region 1 is the "non-secure privilege control block" registers | 22 | |
21 | + * + named GPIO output "sec_resp_cfg" indicating whether blocked accesses | 23 | +static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num) |
22 | + * should RAZ/WI or bus error | ||
23 | + * Controlling the 2 APB PPCs in the IoTKit: | ||
24 | + * + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec | ||
25 | + * + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap | ||
26 | + * + named GPIO outputs apb_ppc{0,1}_irq_enable | ||
27 | + * + named GPIO outputs apb_ppc{0,1}_irq_clear | ||
28 | + * + named GPIO inputs apb_ppc{0,1}_irq_status | ||
29 | + * Controlling each of the 4 expansion APB PPCs which a system using the IoTKit | ||
30 | + * might provide: | ||
31 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15] | ||
32 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15] | ||
33 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable | ||
34 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear | ||
35 | + * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status | ||
36 | + * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit | ||
37 | + * might provide: | ||
38 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15] | ||
39 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15] | ||
40 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable | ||
41 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear | ||
42 | + * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status | ||
43 | */ | ||
44 | |||
45 | #ifndef IOTKIT_SECCTL_H | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | #define TYPE_IOTKIT_SECCTL "iotkit-secctl" | ||
48 | #define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL) | ||
49 | |||
50 | -typedef struct IoTKitSecCtl { | ||
51 | +#define IOTS_APB_PPC0_NUM_PORTS 3 | ||
52 | +#define IOTS_APB_PPC1_NUM_PORTS 1 | ||
53 | +#define IOTS_PPC_NUM_PORTS 16 | ||
54 | +#define IOTS_NUM_APB_PPC 2 | ||
55 | +#define IOTS_NUM_APB_EXP_PPC 4 | ||
56 | +#define IOTS_NUM_AHB_EXP_PPC 4 | ||
57 | + | ||
58 | +typedef struct IoTKitSecCtl IoTKitSecCtl; | ||
59 | + | ||
60 | +/* State and IRQ lines relating to a PPC. For the | ||
61 | + * PPCs in the IoTKit not all the IRQ lines are used. | ||
62 | + */ | ||
63 | +typedef struct IoTKitSecCtlPPC { | ||
64 | + qemu_irq nonsec[IOTS_PPC_NUM_PORTS]; | ||
65 | + qemu_irq ap[IOTS_PPC_NUM_PORTS]; | ||
66 | + qemu_irq irq_enable; | ||
67 | + qemu_irq irq_clear; | ||
68 | + | ||
69 | + uint32_t ns; | ||
70 | + uint32_t sp; | ||
71 | + uint32_t nsp; | ||
72 | + | ||
73 | + /* Number of ports actually present */ | ||
74 | + int numports; | ||
75 | + /* Offset of this PPC's interrupt bits in SECPPCINTSTAT */ | ||
76 | + int irq_bit_offset; | ||
77 | + IoTKitSecCtl *parent; | ||
78 | +} IoTKitSecCtlPPC; | ||
79 | + | ||
80 | +struct IoTKitSecCtl { | ||
81 | /*< private >*/ | ||
82 | SysBusDevice parent_obj; | ||
83 | |||
84 | /*< public >*/ | ||
85 | + qemu_irq sec_resp_cfg; | ||
86 | |||
87 | MemoryRegion s_regs; | ||
88 | MemoryRegion ns_regs; | ||
89 | -} IoTKitSecCtl; | ||
90 | + | ||
91 | + uint32_t secppcintstat; | ||
92 | + uint32_t secppcinten; | ||
93 | + uint32_t secrespcfg; | ||
94 | + | ||
95 | + IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC]; | ||
96 | + IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC]; | ||
97 | + IoTKitSecCtlPPC ahbexp[IOTS_NUM_APB_EXP_PPC]; | ||
98 | +}; | ||
99 | |||
100 | #endif | ||
101 | diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/hw/misc/iotkit-secctl.c | ||
104 | +++ b/hw/misc/iotkit-secctl.c | ||
105 | @@ -XXX,XX +XXX,XX @@ static const uint8_t iotkit_secctl_ns_idregs[] = { | ||
106 | 0x0d, 0xf0, 0x05, 0xb1, | ||
107 | }; | ||
108 | |||
109 | +/* The register sets for the various PPCs (AHB internal, APB internal, | ||
110 | + * AHB expansion, APB expansion) are all set up so that they are | ||
111 | + * in 16-aligned blocks so offsets 0xN0, 0xN4, 0xN8, 0xNC are PPCs | ||
112 | + * 0, 1, 2, 3 of that type, so we can convert a register address offset | ||
113 | + * into an an index into a PPC array easily. | ||
114 | + */ | ||
115 | +static inline int offset_to_ppc_idx(uint32_t offset) | ||
116 | +{ | 24 | +{ |
117 | + return extract32(offset, 2, 2); | 25 | + g_assert(num < ARRAY_SIZE(soc->smbus)); |
26 | + return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus")); | ||
118 | +} | 27 | +} |
119 | + | 28 | + |
120 | +typedef void PerPPCFunction(IoTKitSecCtlPPC *ppc); | 29 | +static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
121 | + | ||
122 | +static void foreach_ppc(IoTKitSecCtl *s, PerPPCFunction *fn) | ||
123 | +{ | 30 | +{ |
124 | + int i; | 31 | + /* lm75 temperature sensor on SVB, tmp105 is compatible */ |
125 | + | 32 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48); |
126 | + for (i = 0; i < IOTS_NUM_APB_PPC; i++) { | 33 | + /* lm75 temperature sensor on EB, tmp105 is compatible */ |
127 | + fn(&s->apb[i]); | 34 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48); |
128 | + } | 35 | + /* tmp100 temperature sensor on EB, tmp105 is compatible */ |
129 | + for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) { | 36 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48); |
130 | + fn(&s->apbexp[i]); | 37 | + /* tmp100 temperature sensor on SVB, tmp105 is compatible */ |
131 | + } | 38 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); |
132 | + for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) { | ||
133 | + fn(&s->ahbexp[i]); | ||
134 | + } | ||
135 | +} | 39 | +} |
136 | + | 40 | + |
137 | static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | 41 | static void npcm750_evb_init(MachineState *machine) |
138 | uint64_t *pdata, | ||
139 | unsigned size, MemTxAttrs attrs) | ||
140 | { | 42 | { |
141 | uint64_t r; | 43 | NPCM7xxState *soc; |
142 | uint32_t offset = addr & ~0x3; | 44 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine) |
143 | + IoTKitSecCtl *s = IOTKIT_SECCTL(opaque); | 45 | |
144 | 46 | npcm7xx_load_bootrom(machine, soc); | |
145 | switch (offset) { | 47 | npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0)); |
146 | case A_AHBNSPPC0: | 48 | + npcm750_evb_i2c_init(soc); |
147 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | 49 | npcm7xx_load_kernel(machine, soc); |
148 | r = 0; | ||
149 | break; | ||
150 | case A_SECRESPCFG: | ||
151 | - case A_NSCCFG: | ||
152 | - case A_SECMPCINTSTATUS: | ||
153 | + r = s->secrespcfg; | ||
154 | + break; | ||
155 | case A_SECPPCINTSTAT: | ||
156 | + r = s->secppcintstat; | ||
157 | + break; | ||
158 | case A_SECPPCINTEN: | ||
159 | - case A_SECMSCINTSTAT: | ||
160 | - case A_SECMSCINTEN: | ||
161 | - case A_BRGINTSTAT: | ||
162 | - case A_BRGINTEN: | ||
163 | + r = s->secppcinten; | ||
164 | + break; | ||
165 | case A_AHBNSPPCEXP0: | ||
166 | case A_AHBNSPPCEXP1: | ||
167 | case A_AHBNSPPCEXP2: | ||
168 | case A_AHBNSPPCEXP3: | ||
169 | + r = s->ahbexp[offset_to_ppc_idx(offset)].ns; | ||
170 | + break; | ||
171 | case A_APBNSPPC0: | ||
172 | case A_APBNSPPC1: | ||
173 | + r = s->apb[offset_to_ppc_idx(offset)].ns; | ||
174 | + break; | ||
175 | case A_APBNSPPCEXP0: | ||
176 | case A_APBNSPPCEXP1: | ||
177 | case A_APBNSPPCEXP2: | ||
178 | case A_APBNSPPCEXP3: | ||
179 | + r = s->apbexp[offset_to_ppc_idx(offset)].ns; | ||
180 | + break; | ||
181 | case A_AHBSPPPCEXP0: | ||
182 | case A_AHBSPPPCEXP1: | ||
183 | case A_AHBSPPPCEXP2: | ||
184 | case A_AHBSPPPCEXP3: | ||
185 | + r = s->apbexp[offset_to_ppc_idx(offset)].sp; | ||
186 | + break; | ||
187 | case A_APBSPPPC0: | ||
188 | case A_APBSPPPC1: | ||
189 | + r = s->apb[offset_to_ppc_idx(offset)].sp; | ||
190 | + break; | ||
191 | case A_APBSPPPCEXP0: | ||
192 | case A_APBSPPPCEXP1: | ||
193 | case A_APBSPPPCEXP2: | ||
194 | case A_APBSPPPCEXP3: | ||
195 | + r = s->apbexp[offset_to_ppc_idx(offset)].sp; | ||
196 | + break; | ||
197 | + case A_NSCCFG: | ||
198 | + case A_SECMPCINTSTATUS: | ||
199 | + case A_SECMSCINTSTAT: | ||
200 | + case A_SECMSCINTEN: | ||
201 | + case A_BRGINTSTAT: | ||
202 | + case A_BRGINTEN: | ||
203 | case A_NSMSCEXP: | ||
204 | qemu_log_mask(LOG_UNIMP, | ||
205 | "IoTKit SecCtl S block read: " | ||
206 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | ||
207 | return MEMTX_OK; | ||
208 | } | 50 | } |
209 | 51 | ||
210 | +static void iotkit_secctl_update_ppc_ap(IoTKitSecCtlPPC *ppc) | ||
211 | +{ | ||
212 | + int i; | ||
213 | + | ||
214 | + for (i = 0; i < ppc->numports; i++) { | ||
215 | + bool v; | ||
216 | + | ||
217 | + if (extract32(ppc->ns, i, 1)) { | ||
218 | + v = extract32(ppc->nsp, i, 1); | ||
219 | + } else { | ||
220 | + v = extract32(ppc->sp, i, 1); | ||
221 | + } | ||
222 | + qemu_set_irq(ppc->ap[i], v); | ||
223 | + } | ||
224 | +} | ||
225 | + | ||
226 | +static void iotkit_secctl_ppc_ns_write(IoTKitSecCtlPPC *ppc, uint32_t value) | ||
227 | +{ | ||
228 | + int i; | ||
229 | + | ||
230 | + ppc->ns = value & MAKE_64BIT_MASK(0, ppc->numports); | ||
231 | + for (i = 0; i < ppc->numports; i++) { | ||
232 | + qemu_set_irq(ppc->nonsec[i], extract32(ppc->ns, i, 1)); | ||
233 | + } | ||
234 | + iotkit_secctl_update_ppc_ap(ppc); | ||
235 | +} | ||
236 | + | ||
237 | +static void iotkit_secctl_ppc_sp_write(IoTKitSecCtlPPC *ppc, uint32_t value) | ||
238 | +{ | ||
239 | + ppc->sp = value & MAKE_64BIT_MASK(0, ppc->numports); | ||
240 | + iotkit_secctl_update_ppc_ap(ppc); | ||
241 | +} | ||
242 | + | ||
243 | +static void iotkit_secctl_ppc_nsp_write(IoTKitSecCtlPPC *ppc, uint32_t value) | ||
244 | +{ | ||
245 | + ppc->nsp = value & MAKE_64BIT_MASK(0, ppc->numports); | ||
246 | + iotkit_secctl_update_ppc_ap(ppc); | ||
247 | +} | ||
248 | + | ||
249 | +static void iotkit_secctl_ppc_update_irq_clear(IoTKitSecCtlPPC *ppc) | ||
250 | +{ | ||
251 | + uint32_t value = ppc->parent->secppcintstat; | ||
252 | + | ||
253 | + qemu_set_irq(ppc->irq_clear, extract32(value, ppc->irq_bit_offset, 1)); | ||
254 | +} | ||
255 | + | ||
256 | +static void iotkit_secctl_ppc_update_irq_enable(IoTKitSecCtlPPC *ppc) | ||
257 | +{ | ||
258 | + uint32_t value = ppc->parent->secppcinten; | ||
259 | + | ||
260 | + qemu_set_irq(ppc->irq_enable, extract32(value, ppc->irq_bit_offset, 1)); | ||
261 | +} | ||
262 | + | ||
263 | static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | ||
264 | uint64_t value, | ||
265 | unsigned size, MemTxAttrs attrs) | ||
266 | { | ||
267 | + IoTKitSecCtl *s = IOTKIT_SECCTL(opaque); | ||
268 | uint32_t offset = addr; | ||
269 | + IoTKitSecCtlPPC *ppc; | ||
270 | |||
271 | trace_iotkit_secctl_s_write(offset, value, size); | ||
272 | |||
273 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | ||
274 | |||
275 | switch (offset) { | ||
276 | case A_SECRESPCFG: | ||
277 | - case A_NSCCFG: | ||
278 | + value &= 1; | ||
279 | + s->secrespcfg = value; | ||
280 | + qemu_set_irq(s->sec_resp_cfg, s->secrespcfg); | ||
281 | + break; | ||
282 | case A_SECPPCINTCLR: | ||
283 | + value &= 0x00f000f3; | ||
284 | + foreach_ppc(s, iotkit_secctl_ppc_update_irq_clear); | ||
285 | + break; | ||
286 | case A_SECPPCINTEN: | ||
287 | - case A_SECMSCINTCLR: | ||
288 | - case A_SECMSCINTEN: | ||
289 | - case A_BRGINTCLR: | ||
290 | - case A_BRGINTEN: | ||
291 | + s->secppcinten = value & 0x00f000f3; | ||
292 | + foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable); | ||
293 | + break; | ||
294 | case A_AHBNSPPCEXP0: | ||
295 | case A_AHBNSPPCEXP1: | ||
296 | case A_AHBNSPPCEXP2: | ||
297 | case A_AHBNSPPCEXP3: | ||
298 | + ppc = &s->ahbexp[offset_to_ppc_idx(offset)]; | ||
299 | + iotkit_secctl_ppc_ns_write(ppc, value); | ||
300 | + break; | ||
301 | case A_APBNSPPC0: | ||
302 | case A_APBNSPPC1: | ||
303 | + ppc = &s->apb[offset_to_ppc_idx(offset)]; | ||
304 | + iotkit_secctl_ppc_ns_write(ppc, value); | ||
305 | + break; | ||
306 | case A_APBNSPPCEXP0: | ||
307 | case A_APBNSPPCEXP1: | ||
308 | case A_APBNSPPCEXP2: | ||
309 | case A_APBNSPPCEXP3: | ||
310 | + ppc = &s->apbexp[offset_to_ppc_idx(offset)]; | ||
311 | + iotkit_secctl_ppc_ns_write(ppc, value); | ||
312 | + break; | ||
313 | case A_AHBSPPPCEXP0: | ||
314 | case A_AHBSPPPCEXP1: | ||
315 | case A_AHBSPPPCEXP2: | ||
316 | case A_AHBSPPPCEXP3: | ||
317 | + ppc = &s->ahbexp[offset_to_ppc_idx(offset)]; | ||
318 | + iotkit_secctl_ppc_sp_write(ppc, value); | ||
319 | + break; | ||
320 | case A_APBSPPPC0: | ||
321 | case A_APBSPPPC1: | ||
322 | + ppc = &s->apb[offset_to_ppc_idx(offset)]; | ||
323 | + iotkit_secctl_ppc_sp_write(ppc, value); | ||
324 | + break; | ||
325 | case A_APBSPPPCEXP0: | ||
326 | case A_APBSPPPCEXP1: | ||
327 | case A_APBSPPPCEXP2: | ||
328 | case A_APBSPPPCEXP3: | ||
329 | + ppc = &s->apbexp[offset_to_ppc_idx(offset)]; | ||
330 | + iotkit_secctl_ppc_sp_write(ppc, value); | ||
331 | + break; | ||
332 | + case A_NSCCFG: | ||
333 | + case A_SECMSCINTCLR: | ||
334 | + case A_SECMSCINTEN: | ||
335 | + case A_BRGINTCLR: | ||
336 | + case A_BRGINTEN: | ||
337 | qemu_log_mask(LOG_UNIMP, | ||
338 | "IoTKit SecCtl S block write: " | ||
339 | "unimplemented offset 0x%x\n", offset); | ||
340 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr, | ||
341 | uint64_t *pdata, | ||
342 | unsigned size, MemTxAttrs attrs) | ||
343 | { | ||
344 | + IoTKitSecCtl *s = IOTKIT_SECCTL(opaque); | ||
345 | uint64_t r; | ||
346 | uint32_t offset = addr & ~0x3; | ||
347 | |||
348 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr, | ||
349 | case A_AHBNSPPPCEXP1: | ||
350 | case A_AHBNSPPPCEXP2: | ||
351 | case A_AHBNSPPPCEXP3: | ||
352 | + r = s->ahbexp[offset_to_ppc_idx(offset)].nsp; | ||
353 | + break; | ||
354 | case A_APBNSPPPC0: | ||
355 | case A_APBNSPPPC1: | ||
356 | + r = s->apb[offset_to_ppc_idx(offset)].nsp; | ||
357 | + break; | ||
358 | case A_APBNSPPPCEXP0: | ||
359 | case A_APBNSPPPCEXP1: | ||
360 | case A_APBNSPPPCEXP2: | ||
361 | case A_APBNSPPPCEXP3: | ||
362 | - qemu_log_mask(LOG_UNIMP, | ||
363 | - "IoTKit SecCtl NS block read: " | ||
364 | - "unimplemented offset 0x%x\n", offset); | ||
365 | + r = s->apbexp[offset_to_ppc_idx(offset)].nsp; | ||
366 | break; | ||
367 | case A_PID4: | ||
368 | case A_PID5: | ||
369 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr, | ||
370 | uint64_t value, | ||
371 | unsigned size, MemTxAttrs attrs) | ||
372 | { | ||
373 | + IoTKitSecCtl *s = IOTKIT_SECCTL(opaque); | ||
374 | uint32_t offset = addr; | ||
375 | + IoTKitSecCtlPPC *ppc; | ||
376 | |||
377 | trace_iotkit_secctl_ns_write(offset, value, size); | ||
378 | |||
379 | @@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr, | ||
380 | case A_AHBNSPPPCEXP1: | ||
381 | case A_AHBNSPPPCEXP2: | ||
382 | case A_AHBNSPPPCEXP3: | ||
383 | + ppc = &s->ahbexp[offset_to_ppc_idx(offset)]; | ||
384 | + iotkit_secctl_ppc_nsp_write(ppc, value); | ||
385 | + break; | ||
386 | case A_APBNSPPPC0: | ||
387 | case A_APBNSPPPC1: | ||
388 | + ppc = &s->apb[offset_to_ppc_idx(offset)]; | ||
389 | + iotkit_secctl_ppc_nsp_write(ppc, value); | ||
390 | + break; | ||
391 | case A_APBNSPPPCEXP0: | ||
392 | case A_APBNSPPPCEXP1: | ||
393 | case A_APBNSPPPCEXP2: | ||
394 | case A_APBNSPPPCEXP3: | ||
395 | - qemu_log_mask(LOG_UNIMP, | ||
396 | - "IoTKit SecCtl NS block write: " | ||
397 | - "unimplemented offset 0x%x\n", offset); | ||
398 | + ppc = &s->apbexp[offset_to_ppc_idx(offset)]; | ||
399 | + iotkit_secctl_ppc_nsp_write(ppc, value); | ||
400 | break; | ||
401 | case A_AHBNSPPPC0: | ||
402 | case A_PID4: | ||
403 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps iotkit_secctl_ns_ops = { | ||
404 | .impl.max_access_size = 4, | ||
405 | }; | ||
406 | |||
407 | +static void iotkit_secctl_reset_ppc(IoTKitSecCtlPPC *ppc) | ||
408 | +{ | ||
409 | + ppc->ns = 0; | ||
410 | + ppc->sp = 0; | ||
411 | + ppc->nsp = 0; | ||
412 | +} | ||
413 | + | ||
414 | static void iotkit_secctl_reset(DeviceState *dev) | ||
415 | { | ||
416 | + IoTKitSecCtl *s = IOTKIT_SECCTL(dev); | ||
417 | |||
418 | + s->secppcintstat = 0; | ||
419 | + s->secppcinten = 0; | ||
420 | + s->secrespcfg = 0; | ||
421 | + | ||
422 | + foreach_ppc(s, iotkit_secctl_reset_ppc); | ||
423 | +} | ||
424 | + | ||
425 | +static void iotkit_secctl_ppc_irqstatus(void *opaque, int n, int level) | ||
426 | +{ | ||
427 | + IoTKitSecCtlPPC *ppc = opaque; | ||
428 | + IoTKitSecCtl *s = IOTKIT_SECCTL(ppc->parent); | ||
429 | + int irqbit = ppc->irq_bit_offset + n; | ||
430 | + | ||
431 | + s->secppcintstat = deposit32(s->secppcintstat, irqbit, 1, level); | ||
432 | +} | ||
433 | + | ||
434 | +static void iotkit_secctl_init_ppc(IoTKitSecCtl *s, | ||
435 | + IoTKitSecCtlPPC *ppc, | ||
436 | + const char *name, | ||
437 | + int numports, | ||
438 | + int irq_bit_offset) | ||
439 | +{ | ||
440 | + char *gpioname; | ||
441 | + DeviceState *dev = DEVICE(s); | ||
442 | + | ||
443 | + ppc->numports = numports; | ||
444 | + ppc->irq_bit_offset = irq_bit_offset; | ||
445 | + ppc->parent = s; | ||
446 | + | ||
447 | + gpioname = g_strdup_printf("%s_nonsec", name); | ||
448 | + qdev_init_gpio_out_named(dev, ppc->nonsec, gpioname, numports); | ||
449 | + g_free(gpioname); | ||
450 | + gpioname = g_strdup_printf("%s_ap", name); | ||
451 | + qdev_init_gpio_out_named(dev, ppc->ap, gpioname, numports); | ||
452 | + g_free(gpioname); | ||
453 | + gpioname = g_strdup_printf("%s_irq_enable", name); | ||
454 | + qdev_init_gpio_out_named(dev, &ppc->irq_enable, gpioname, 1); | ||
455 | + g_free(gpioname); | ||
456 | + gpioname = g_strdup_printf("%s_irq_clear", name); | ||
457 | + qdev_init_gpio_out_named(dev, &ppc->irq_clear, gpioname, 1); | ||
458 | + g_free(gpioname); | ||
459 | + gpioname = g_strdup_printf("%s_irq_status", name); | ||
460 | + qdev_init_gpio_in_named_with_opaque(dev, iotkit_secctl_ppc_irqstatus, | ||
461 | + ppc, gpioname, 1); | ||
462 | + g_free(gpioname); | ||
463 | } | ||
464 | |||
465 | static void iotkit_secctl_init(Object *obj) | ||
466 | { | ||
467 | IoTKitSecCtl *s = IOTKIT_SECCTL(obj); | ||
468 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
469 | + DeviceState *dev = DEVICE(obj); | ||
470 | + int i; | ||
471 | + | ||
472 | + iotkit_secctl_init_ppc(s, &s->apb[0], "apb_ppc0", | ||
473 | + IOTS_APB_PPC0_NUM_PORTS, 0); | ||
474 | + iotkit_secctl_init_ppc(s, &s->apb[1], "apb_ppc1", | ||
475 | + IOTS_APB_PPC1_NUM_PORTS, 1); | ||
476 | + | ||
477 | + for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) { | ||
478 | + IoTKitSecCtlPPC *ppc = &s->apbexp[i]; | ||
479 | + char *ppcname = g_strdup_printf("apb_ppcexp%d", i); | ||
480 | + iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 4 + i); | ||
481 | + g_free(ppcname); | ||
482 | + } | ||
483 | + for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) { | ||
484 | + IoTKitSecCtlPPC *ppc = &s->ahbexp[i]; | ||
485 | + char *ppcname = g_strdup_printf("ahb_ppcexp%d", i); | ||
486 | + iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 20 + i); | ||
487 | + g_free(ppcname); | ||
488 | + } | ||
489 | + | ||
490 | + qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1); | ||
491 | |||
492 | memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops, | ||
493 | s, "iotkit-secctl-s-regs", 0x1000); | ||
494 | @@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj) | ||
495 | sysbus_init_mmio(sbd, &s->ns_regs); | ||
496 | } | ||
497 | |||
498 | +static const VMStateDescription iotkit_secctl_ppc_vmstate = { | ||
499 | + .name = "iotkit-secctl-ppc", | ||
500 | + .version_id = 1, | ||
501 | + .minimum_version_id = 1, | ||
502 | + .fields = (VMStateField[]) { | ||
503 | + VMSTATE_UINT32(ns, IoTKitSecCtlPPC), | ||
504 | + VMSTATE_UINT32(sp, IoTKitSecCtlPPC), | ||
505 | + VMSTATE_UINT32(nsp, IoTKitSecCtlPPC), | ||
506 | + VMSTATE_END_OF_LIST() | ||
507 | + } | ||
508 | +}; | ||
509 | + | ||
510 | static const VMStateDescription iotkit_secctl_vmstate = { | ||
511 | .name = "iotkit-secctl", | ||
512 | .version_id = 1, | ||
513 | .minimum_version_id = 1, | ||
514 | .fields = (VMStateField[]) { | ||
515 | + VMSTATE_UINT32(secppcintstat, IoTKitSecCtl), | ||
516 | + VMSTATE_UINT32(secppcinten, IoTKitSecCtl), | ||
517 | + VMSTATE_UINT32(secrespcfg, IoTKitSecCtl), | ||
518 | + VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1, | ||
519 | + iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC), | ||
520 | + VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1, | ||
521 | + iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC), | ||
522 | + VMSTATE_STRUCT_ARRAY(ahbexp, IoTKitSecCtl, IOTS_NUM_AHB_EXP_PPC, 1, | ||
523 | + iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC), | ||
524 | VMSTATE_END_OF_LIST() | ||
525 | } | ||
526 | }; | ||
527 | -- | 52 | -- |
528 | 2.16.2 | 53 | 2.20.1 |
529 | 54 | ||
530 | 55 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@xilinx.com> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Allow the guest to determine the time set from the QEMU command line. | 3 | Add AT24 EEPROM and temperature sensors for GSJ machine. |
4 | 4 | ||
5 | This includes adding a trace event to debug the new time. | 5 | Reviewed-by: Doug Evans<dje@google.com> |
6 | 6 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> | |
7 | Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Message-id: 20210210220426.3577804-4-wuhaotsh@google.com |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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 | include/hw/timer/xlnx-zynqmp-rtc.h | 2 ++ | 12 | hw/arm/npcm7xx_boards.c | 27 +++++++++++++++++++++++++++ |
13 | hw/timer/xlnx-zynqmp-rtc.c | 58 ++++++++++++++++++++++++++++++++++++++ | 13 | hw/arm/Kconfig | 1 + |
14 | hw/timer/trace-events | 3 ++ | 14 | 2 files changed, 28 insertions(+) |
15 | 3 files changed, 63 insertions(+) | ||
16 | 15 | ||
17 | diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h | 16 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/timer/xlnx-zynqmp-rtc.h | 18 | --- a/hw/arm/npcm7xx_boards.c |
20 | +++ b/include/hw/timer/xlnx-zynqmp-rtc.h | 19 | +++ b/hw/arm/npcm7xx_boards.c |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPRTC { | 20 | @@ -XXX,XX +XXX,XX @@ |
22 | qemu_irq irq_rtc_int; | 21 | #include "exec/address-spaces.h" |
23 | qemu_irq irq_addr_error_int; | 22 | #include "hw/arm/npcm7xx.h" |
24 | 23 | #include "hw/core/cpu.h" | |
25 | + uint32_t tick_offset; | 24 | +#include "hw/i2c/smbus_eeprom.h" |
25 | #include "hw/loader.h" | ||
26 | #include "hw/qdev-properties.h" | ||
27 | #include "qapi/error.h" | ||
28 | @@ -XXX,XX +XXX,XX @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num) | ||
29 | return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus")); | ||
30 | } | ||
31 | |||
32 | +static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr, | ||
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); | ||
26 | + | 38 | + |
27 | uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX]; | 39 | + qdev_prop_set_uint32(dev, "rom-size", rsize); |
28 | RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX]; | 40 | + i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort); |
29 | } XlnxZynqMPRTC; | ||
30 | diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/timer/xlnx-zynqmp-rtc.c | ||
33 | +++ b/hw/timer/xlnx-zynqmp-rtc.c | ||
34 | @@ -XXX,XX +XXX,XX @@ | ||
35 | #include "hw/register.h" | ||
36 | #include "qemu/bitops.h" | ||
37 | #include "qemu/log.h" | ||
38 | +#include "hw/ptimer.h" | ||
39 | +#include "qemu/cutils.h" | ||
40 | +#include "sysemu/sysemu.h" | ||
41 | +#include "trace.h" | ||
42 | #include "hw/timer/xlnx-zynqmp-rtc.h" | ||
43 | |||
44 | #ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG | ||
45 | @@ -XXX,XX +XXX,XX @@ static void addr_error_int_update_irq(XlnxZynqMPRTC *s) | ||
46 | qemu_set_irq(s->irq_addr_error_int, pending); | ||
47 | } | ||
48 | |||
49 | +static uint32_t rtc_get_count(XlnxZynqMPRTC *s) | ||
50 | +{ | ||
51 | + int64_t now = qemu_clock_get_ns(rtc_clock); | ||
52 | + return s->tick_offset + now / NANOSECONDS_PER_SECOND; | ||
53 | +} | 41 | +} |
54 | + | 42 | + |
55 | +static uint64_t current_time_postr(RegisterInfo *reg, uint64_t val64) | 43 | static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
44 | { | ||
45 | /* lm75 temperature sensor on SVB, tmp105 is compatible */ | ||
46 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_i2c_init(NPCM7xxState *soc) | ||
47 | i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); | ||
48 | } | ||
49 | |||
50 | +static void quanta_gsj_i2c_init(NPCM7xxState *soc) | ||
56 | +{ | 51 | +{ |
57 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 52 | + /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */ |
53 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x5c); | ||
54 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x5c); | ||
55 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c); | ||
56 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c); | ||
58 | + | 57 | + |
59 | + return rtc_get_count(s); | 58 | + at24c_eeprom_init(soc, 9, 0x55, 8192); |
59 | + at24c_eeprom_init(soc, 10, 0x55, 8192); | ||
60 | + | ||
61 | + /* TODO: Add additional i2c devices. */ | ||
60 | +} | 62 | +} |
61 | + | 63 | + |
62 | static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64) | 64 | static void npcm750_evb_init(MachineState *machine) |
63 | { | 65 | { |
64 | XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 66 | NPCM7xxState *soc; |
65 | @@ -XXX,XX +XXX,XX @@ static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64) | 67 | @@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine) |
66 | 68 | npcm7xx_load_bootrom(machine, soc); | |
67 | static const RegisterAccessInfo rtc_regs_info[] = { | 69 | npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e", |
68 | { .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE, | 70 | drive_get(IF_MTD, 0, 0)); |
69 | + .unimp = MAKE_64BIT_MASK(0, 32), | 71 | + quanta_gsj_i2c_init(soc); |
70 | },{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ, | 72 | npcm7xx_load_kernel(machine, soc); |
71 | .ro = 0xffffffff, | ||
72 | + .post_read = current_time_postr, | ||
73 | },{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE, | ||
74 | + .unimp = MAKE_64BIT_MASK(0, 32), | ||
75 | },{ .name = "CALIB_READ", .addr = A_CALIB_READ, | ||
76 | .ro = 0x1fffff, | ||
77 | },{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME, | ||
78 | .ro = 0xffffffff, | ||
79 | + .post_read = current_time_postr, | ||
80 | },{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK, | ||
81 | .ro = 0xffff, | ||
82 | },{ .name = "ALARM", .addr = A_ALARM, | ||
83 | @@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj) | ||
84 | XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj); | ||
85 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
86 | RegisterInfoArray *reg_array; | ||
87 | + struct tm current_tm; | ||
88 | |||
89 | memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC, | ||
90 | XLNX_ZYNQMP_RTC_R_MAX * 4); | ||
91 | @@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj) | ||
92 | sysbus_init_mmio(sbd, &s->iomem); | ||
93 | sysbus_init_irq(sbd, &s->irq_rtc_int); | ||
94 | sysbus_init_irq(sbd, &s->irq_addr_error_int); | ||
95 | + | ||
96 | + qemu_get_timedate(¤t_tm, 0); | ||
97 | + s->tick_offset = mktimegm(¤t_tm) - | ||
98 | + qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND; | ||
99 | + | ||
100 | + trace_xlnx_zynqmp_rtc_gettime(current_tm.tm_year, current_tm.tm_mon, | ||
101 | + current_tm.tm_mday, current_tm.tm_hour, | ||
102 | + current_tm.tm_min, current_tm.tm_sec); | ||
103 | +} | ||
104 | + | ||
105 | +static int rtc_pre_save(void *opaque) | ||
106 | +{ | ||
107 | + XlnxZynqMPRTC *s = opaque; | ||
108 | + int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND; | ||
109 | + | ||
110 | + /* Add the time at migration */ | ||
111 | + s->tick_offset = s->tick_offset + now; | ||
112 | + | ||
113 | + return 0; | ||
114 | +} | ||
115 | + | ||
116 | +static int rtc_post_load(void *opaque, int version_id) | ||
117 | +{ | ||
118 | + XlnxZynqMPRTC *s = opaque; | ||
119 | + int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND; | ||
120 | + | ||
121 | + /* Subtract the time after migration. This combined with the pre_save | ||
122 | + * action results in us having subtracted the time that the guest was | ||
123 | + * stopped to the offset. | ||
124 | + */ | ||
125 | + s->tick_offset = s->tick_offset - now; | ||
126 | + | ||
127 | + return 0; | ||
128 | } | 73 | } |
129 | 74 | ||
130 | static const VMStateDescription vmstate_rtc = { | 75 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
131 | .name = TYPE_XLNX_ZYNQMP_RTC, | ||
132 | .version_id = 1, | ||
133 | .minimum_version_id = 1, | ||
134 | + .pre_save = rtc_pre_save, | ||
135 | + .post_load = rtc_post_load, | ||
136 | .fields = (VMStateField[]) { | ||
137 | VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX), | ||
138 | + VMSTATE_UINT32(tick_offset, XlnxZynqMPRTC), | ||
139 | VMSTATE_END_OF_LIST(), | ||
140 | } | ||
141 | }; | ||
142 | diff --git a/hw/timer/trace-events b/hw/timer/trace-events | ||
143 | index XXXXXXX..XXXXXXX 100644 | 76 | index XXXXXXX..XXXXXXX 100644 |
144 | --- a/hw/timer/trace-events | 77 | --- a/hw/arm/Kconfig |
145 | +++ b/hw/timer/trace-events | 78 | +++ b/hw/arm/Kconfig |
146 | @@ -XXX,XX +XXX,XX @@ systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr | 79 | @@ -XXX,XX +XXX,XX @@ config NPCM7XX |
147 | cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | 80 | bool |
148 | cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | 81 | select A9MPCORE |
149 | cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset" | 82 | select ARM_GIC |
150 | + | 83 | + select AT24C # EEPROM |
151 | +# hw/timer/xlnx-zynqmp-rtc.c | 84 | select PL310 # cache controller |
152 | +xlnx_zynqmp_rtc_gettime(int year, int month, int day, int hour, int min, int sec) "Get time from host: %d-%d-%d %2d:%02d:%02d" | 85 | select SERIAL |
86 | select SSI | ||
153 | -- | 87 | -- |
154 | 2.16.2 | 88 | 2.20.1 |
155 | 89 | ||
156 | 90 | diff view generated by jsdifflib |
1 | The Arm IoT Kit includes a "security controller" which is largely a | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | collection of registers for controlling the PPCs and other bits of | 2 | |
3 | glue in the system. This commit provides the initial skeleton of the | 3 | This patch adds a QTest for NPCM7XX SMBus's single byte mode. It sends a |
4 | device, implementing just the ID registers, and a couple of read-only | 4 | byte to a device in the evaluation board, and verify the retrieved value |
5 | read-as-zero registers. | 5 | is equivalent to the sent value. |
6 | 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 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20180220180325.29818-16-peter.maydell@linaro.org | ||
10 | --- | 13 | --- |
11 | hw/misc/Makefile.objs | 1 + | 14 | tests/qtest/npcm7xx_smbus-test.c | 352 +++++++++++++++++++++++++++++++ |
12 | include/hw/misc/iotkit-secctl.h | 39 ++++ | 15 | tests/qtest/meson.build | 1 + |
13 | hw/misc/iotkit-secctl.c | 448 ++++++++++++++++++++++++++++++++++++++++ | 16 | 2 files changed, 353 insertions(+) |
14 | default-configs/arm-softmmu.mak | 1 + | 17 | create mode 100644 tests/qtest/npcm7xx_smbus-test.c |
15 | hw/misc/trace-events | 7 + | 18 | |
16 | 5 files changed, 496 insertions(+) | 19 | diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c |
17 | create mode 100644 include/hw/misc/iotkit-secctl.h | ||
18 | create mode 100644 hw/misc/iotkit-secctl.c | ||
19 | |||
20 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/misc/Makefile.objs | ||
23 | +++ b/hw/misc/Makefile.objs | ||
24 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o | ||
25 | obj-$(CONFIG_MPS2_SCC) += mps2-scc.o | ||
26 | |||
27 | obj-$(CONFIG_TZ_PPC) += tz-ppc.o | ||
28 | +obj-$(CONFIG_IOTKIT_SECCTL) += iotkit-secctl.o | ||
29 | |||
30 | obj-$(CONFIG_PVPANIC) += pvpanic.o | ||
31 | obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o | ||
32 | diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h | ||
33 | new file mode 100644 | 20 | new file mode 100644 |
34 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
35 | --- /dev/null | 22 | --- /dev/null |
36 | +++ b/include/hw/misc/iotkit-secctl.h | 23 | +++ b/tests/qtest/npcm7xx_smbus-test.c |
37 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
38 | +/* | 25 | +/* |
39 | + * ARM IoT Kit security controller | 26 | + * QTests for Nuvoton NPCM7xx SMBus Modules. |
40 | + * | 27 | + * |
41 | + * Copyright (c) 2018 Linaro Limited | 28 | + * Copyright 2020 Google LLC |
42 | + * Written by Peter Maydell | ||
43 | + * | 29 | + * |
44 | + * This program is free software; you can redistribute it and/or modify | 30 | + * This program is free software; you can redistribute it and/or modify it |
45 | + * it under the terms of the GNU General Public License version 2 or | 31 | + * under the terms of the GNU General Public License as published by the |
32 | + * Free Software Foundation; either version 2 of the License, or | ||
46 | + * (at your option) any later version. | 33 | + * (at your option) any later version. |
34 | + * | ||
35 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
36 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
37 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
38 | + * for more details. | ||
47 | + */ | 39 | + */ |
48 | + | 40 | + |
49 | +/* This is a model of the security controller which is part of the | ||
50 | + * Arm IoT Kit and documented in | ||
51 | + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html | ||
52 | + * | ||
53 | + * QEMU interface: | ||
54 | + * + sysbus MMIO region 0 is the "secure privilege control block" registers | ||
55 | + * + sysbus MMIO region 1 is the "non-secure privilege control block" registers | ||
56 | + */ | ||
57 | + | ||
58 | +#ifndef IOTKIT_SECCTL_H | ||
59 | +#define IOTKIT_SECCTL_H | ||
60 | + | ||
61 | +#include "hw/sysbus.h" | ||
62 | + | ||
63 | +#define TYPE_IOTKIT_SECCTL "iotkit-secctl" | ||
64 | +#define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL) | ||
65 | + | ||
66 | +typedef struct IoTKitSecCtl { | ||
67 | + /*< private >*/ | ||
68 | + SysBusDevice parent_obj; | ||
69 | + | ||
70 | + /*< public >*/ | ||
71 | + | ||
72 | + MemoryRegion s_regs; | ||
73 | + MemoryRegion ns_regs; | ||
74 | +} IoTKitSecCtl; | ||
75 | + | ||
76 | +#endif | ||
77 | diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c | ||
78 | new file mode 100644 | ||
79 | index XXXXXXX..XXXXXXX | ||
80 | --- /dev/null | ||
81 | +++ b/hw/misc/iotkit-secctl.c | ||
82 | @@ -XXX,XX +XXX,XX @@ | ||
83 | +/* | ||
84 | + * Arm IoT Kit security controller | ||
85 | + * | ||
86 | + * Copyright (c) 2018 Linaro Limited | ||
87 | + * Written by Peter Maydell | ||
88 | + * | ||
89 | + * This program is free software; you can redistribute it and/or modify | ||
90 | + * it under the terms of the GNU General Public License version 2 or | ||
91 | + * (at your option) any later version. | ||
92 | + */ | ||
93 | + | ||
94 | +#include "qemu/osdep.h" | 41 | +#include "qemu/osdep.h" |
95 | +#include "qemu/log.h" | 42 | +#include "qemu/bitops.h" |
96 | +#include "qapi/error.h" | 43 | +#include "libqos/i2c.h" |
97 | +#include "trace.h" | 44 | +#include "libqos/libqtest.h" |
98 | +#include "hw/sysbus.h" | 45 | +#include "hw/misc/tmp105_regs.h" |
99 | +#include "hw/registerfields.h" | 46 | + |
100 | +#include "hw/misc/iotkit-secctl.h" | 47 | +#define NR_SMBUS_DEVICES 16 |
101 | + | 48 | +#define SMBUS_ADDR(x) (0xf0080000 + 0x1000 * (x)) |
102 | +/* Registers in the secure privilege control block */ | 49 | +#define SMBUS_IRQ(x) (64 + (x)) |
103 | +REG32(SECRESPCFG, 0x10) | 50 | + |
104 | +REG32(NSCCFG, 0x14) | 51 | +#define EVB_DEVICE_ADDR 0x48 |
105 | +REG32(SECMPCINTSTATUS, 0x1c) | 52 | +#define INVALID_DEVICE_ADDR 0x01 |
106 | +REG32(SECPPCINTSTAT, 0x20) | 53 | + |
107 | +REG32(SECPPCINTCLR, 0x24) | 54 | +const int evb_bus_list[] = {0, 1, 2, 6}; |
108 | +REG32(SECPPCINTEN, 0x28) | 55 | + |
109 | +REG32(SECMSCINTSTAT, 0x30) | 56 | +/* Offsets */ |
110 | +REG32(SECMSCINTCLR, 0x34) | 57 | +enum CommonRegister { |
111 | +REG32(SECMSCINTEN, 0x38) | 58 | + OFFSET_SDA = 0x0, |
112 | +REG32(BRGINTSTAT, 0x40) | 59 | + OFFSET_ST = 0x2, |
113 | +REG32(BRGINTCLR, 0x44) | 60 | + OFFSET_CST = 0x4, |
114 | +REG32(BRGINTEN, 0x48) | 61 | + OFFSET_CTL1 = 0x6, |
115 | +REG32(AHBNSPPC0, 0x50) | 62 | + OFFSET_ADDR1 = 0x8, |
116 | +REG32(AHBNSPPCEXP0, 0x60) | 63 | + OFFSET_CTL2 = 0xa, |
117 | +REG32(AHBNSPPCEXP1, 0x64) | 64 | + OFFSET_ADDR2 = 0xc, |
118 | +REG32(AHBNSPPCEXP2, 0x68) | 65 | + OFFSET_CTL3 = 0xe, |
119 | +REG32(AHBNSPPCEXP3, 0x6c) | 66 | + OFFSET_CST2 = 0x18, |
120 | +REG32(APBNSPPC0, 0x70) | 67 | + OFFSET_CST3 = 0x19, |
121 | +REG32(APBNSPPC1, 0x74) | ||
122 | +REG32(APBNSPPCEXP0, 0x80) | ||
123 | +REG32(APBNSPPCEXP1, 0x84) | ||
124 | +REG32(APBNSPPCEXP2, 0x88) | ||
125 | +REG32(APBNSPPCEXP3, 0x8c) | ||
126 | +REG32(AHBSPPPC0, 0x90) | ||
127 | +REG32(AHBSPPPCEXP0, 0xa0) | ||
128 | +REG32(AHBSPPPCEXP1, 0xa4) | ||
129 | +REG32(AHBSPPPCEXP2, 0xa8) | ||
130 | +REG32(AHBSPPPCEXP3, 0xac) | ||
131 | +REG32(APBSPPPC0, 0xb0) | ||
132 | +REG32(APBSPPPC1, 0xb4) | ||
133 | +REG32(APBSPPPCEXP0, 0xc0) | ||
134 | +REG32(APBSPPPCEXP1, 0xc4) | ||
135 | +REG32(APBSPPPCEXP2, 0xc8) | ||
136 | +REG32(APBSPPPCEXP3, 0xcc) | ||
137 | +REG32(NSMSCEXP, 0xd0) | ||
138 | +REG32(PID4, 0xfd0) | ||
139 | +REG32(PID5, 0xfd4) | ||
140 | +REG32(PID6, 0xfd8) | ||
141 | +REG32(PID7, 0xfdc) | ||
142 | +REG32(PID0, 0xfe0) | ||
143 | +REG32(PID1, 0xfe4) | ||
144 | +REG32(PID2, 0xfe8) | ||
145 | +REG32(PID3, 0xfec) | ||
146 | +REG32(CID0, 0xff0) | ||
147 | +REG32(CID1, 0xff4) | ||
148 | +REG32(CID2, 0xff8) | ||
149 | +REG32(CID3, 0xffc) | ||
150 | + | ||
151 | +/* Registers in the non-secure privilege control block */ | ||
152 | +REG32(AHBNSPPPC0, 0x90) | ||
153 | +REG32(AHBNSPPPCEXP0, 0xa0) | ||
154 | +REG32(AHBNSPPPCEXP1, 0xa4) | ||
155 | +REG32(AHBNSPPPCEXP2, 0xa8) | ||
156 | +REG32(AHBNSPPPCEXP3, 0xac) | ||
157 | +REG32(APBNSPPPC0, 0xb0) | ||
158 | +REG32(APBNSPPPC1, 0xb4) | ||
159 | +REG32(APBNSPPPCEXP0, 0xc0) | ||
160 | +REG32(APBNSPPPCEXP1, 0xc4) | ||
161 | +REG32(APBNSPPPCEXP2, 0xc8) | ||
162 | +REG32(APBNSPPPCEXP3, 0xcc) | ||
163 | +/* PID and CID registers are also present in the NS block */ | ||
164 | + | ||
165 | +static const uint8_t iotkit_secctl_s_idregs[] = { | ||
166 | + 0x04, 0x00, 0x00, 0x00, | ||
167 | + 0x52, 0xb8, 0x0b, 0x00, | ||
168 | + 0x0d, 0xf0, 0x05, 0xb1, | ||
169 | +}; | 68 | +}; |
170 | + | 69 | + |
171 | +static const uint8_t iotkit_secctl_ns_idregs[] = { | 70 | +enum NPCM7xxSMBusBank0Register { |
172 | + 0x04, 0x00, 0x00, 0x00, | 71 | + OFFSET_ADDR3 = 0x10, |
173 | + 0x53, 0xb8, 0x0b, 0x00, | 72 | + OFFSET_ADDR7 = 0x11, |
174 | + 0x0d, 0xf0, 0x05, 0xb1, | 73 | + OFFSET_ADDR4 = 0x12, |
74 | + OFFSET_ADDR8 = 0x13, | ||
75 | + OFFSET_ADDR5 = 0x14, | ||
76 | + OFFSET_ADDR9 = 0x15, | ||
77 | + OFFSET_ADDR6 = 0x16, | ||
78 | + OFFSET_ADDR10 = 0x17, | ||
79 | + OFFSET_CTL4 = 0x1a, | ||
80 | + OFFSET_CTL5 = 0x1b, | ||
81 | + OFFSET_SCLLT = 0x1c, | ||
82 | + OFFSET_FIF_CTL = 0x1d, | ||
83 | + OFFSET_SCLHT = 0x1e, | ||
175 | +}; | 84 | +}; |
176 | + | 85 | + |
177 | +static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr, | 86 | +enum NPCM7xxSMBusBank1Register { |
178 | + uint64_t *pdata, | 87 | + OFFSET_FIF_CTS = 0x10, |
179 | + unsigned size, MemTxAttrs attrs) | 88 | + OFFSET_FAIR_PER = 0x11, |
180 | +{ | 89 | + OFFSET_TXF_CTL = 0x12, |
181 | + uint64_t r; | 90 | + OFFSET_T_OUT = 0x14, |
182 | + uint32_t offset = addr & ~0x3; | 91 | + OFFSET_TXF_STS = 0x1a, |
183 | + | 92 | + OFFSET_RXF_STS = 0x1c, |
184 | + switch (offset) { | 93 | + OFFSET_RXF_CTL = 0x1e, |
185 | + case A_AHBNSPPC0: | 94 | +}; |
186 | + case A_AHBSPPPC0: | 95 | + |
187 | + r = 0; | 96 | +/* ST fields */ |
188 | + break; | 97 | +#define ST_STP BIT(7) |
189 | + case A_SECRESPCFG: | 98 | +#define ST_SDAST BIT(6) |
190 | + case A_NSCCFG: | 99 | +#define ST_BER BIT(5) |
191 | + case A_SECMPCINTSTATUS: | 100 | +#define ST_NEGACK BIT(4) |
192 | + case A_SECPPCINTSTAT: | 101 | +#define ST_STASTR BIT(3) |
193 | + case A_SECPPCINTEN: | 102 | +#define ST_NMATCH BIT(2) |
194 | + case A_SECMSCINTSTAT: | 103 | +#define ST_MODE BIT(1) |
195 | + case A_SECMSCINTEN: | 104 | +#define ST_XMIT BIT(0) |
196 | + case A_BRGINTSTAT: | 105 | + |
197 | + case A_BRGINTEN: | 106 | +/* CST fields */ |
198 | + case A_AHBNSPPCEXP0: | 107 | +#define CST_ARPMATCH BIT(7) |
199 | + case A_AHBNSPPCEXP1: | 108 | +#define CST_MATCHAF BIT(6) |
200 | + case A_AHBNSPPCEXP2: | 109 | +#define CST_TGSCL BIT(5) |
201 | + case A_AHBNSPPCEXP3: | 110 | +#define CST_TSDA BIT(4) |
202 | + case A_APBNSPPC0: | 111 | +#define CST_GCMATCH BIT(3) |
203 | + case A_APBNSPPC1: | 112 | +#define CST_MATCH BIT(2) |
204 | + case A_APBNSPPCEXP0: | 113 | +#define CST_BB BIT(1) |
205 | + case A_APBNSPPCEXP1: | 114 | +#define CST_BUSY BIT(0) |
206 | + case A_APBNSPPCEXP2: | 115 | + |
207 | + case A_APBNSPPCEXP3: | 116 | +/* CST2 fields */ |
208 | + case A_AHBSPPPCEXP0: | 117 | +#define CST2_INSTTS BIT(7) |
209 | + case A_AHBSPPPCEXP1: | 118 | +#define CST2_MATCH7F BIT(6) |
210 | + case A_AHBSPPPCEXP2: | 119 | +#define CST2_MATCH6F BIT(5) |
211 | + case A_AHBSPPPCEXP3: | 120 | +#define CST2_MATCH5F BIT(4) |
212 | + case A_APBSPPPC0: | 121 | +#define CST2_MATCH4F BIT(3) |
213 | + case A_APBSPPPC1: | 122 | +#define CST2_MATCH3F BIT(2) |
214 | + case A_APBSPPPCEXP0: | 123 | +#define CST2_MATCH2F BIT(1) |
215 | + case A_APBSPPPCEXP1: | 124 | +#define CST2_MATCH1F BIT(0) |
216 | + case A_APBSPPPCEXP2: | 125 | + |
217 | + case A_APBSPPPCEXP3: | 126 | +/* CST3 fields */ |
218 | + case A_NSMSCEXP: | 127 | +#define CST3_EO_BUSY BIT(7) |
219 | + qemu_log_mask(LOG_UNIMP, | 128 | +#define CST3_MATCH10F BIT(2) |
220 | + "IoTKit SecCtl S block read: " | 129 | +#define CST3_MATCH9F BIT(1) |
221 | + "unimplemented offset 0x%x\n", offset); | 130 | +#define CST3_MATCH8F BIT(0) |
222 | + r = 0; | 131 | + |
223 | + break; | 132 | +/* CTL1 fields */ |
224 | + case A_PID4: | 133 | +#define CTL1_STASTRE BIT(7) |
225 | + case A_PID5: | 134 | +#define CTL1_NMINTE BIT(6) |
226 | + case A_PID6: | 135 | +#define CTL1_GCMEN BIT(5) |
227 | + case A_PID7: | 136 | +#define CTL1_ACK BIT(4) |
228 | + case A_PID0: | 137 | +#define CTL1_EOBINTE BIT(3) |
229 | + case A_PID1: | 138 | +#define CTL1_INTEN BIT(2) |
230 | + case A_PID2: | 139 | +#define CTL1_STOP BIT(1) |
231 | + case A_PID3: | 140 | +#define CTL1_START BIT(0) |
232 | + case A_CID0: | 141 | + |
233 | + case A_CID1: | 142 | +/* CTL2 fields */ |
234 | + case A_CID2: | 143 | +#define CTL2_SCLFRQ(rv) extract8((rv), 1, 6) |
235 | + case A_CID3: | 144 | +#define CTL2_ENABLE BIT(0) |
236 | + r = iotkit_secctl_s_idregs[(offset - A_PID4) / 4]; | 145 | + |
237 | + break; | 146 | +/* CTL3 fields */ |
238 | + case A_SECPPCINTCLR: | 147 | +#define CTL3_SCL_LVL BIT(7) |
239 | + case A_SECMSCINTCLR: | 148 | +#define CTL3_SDA_LVL BIT(6) |
240 | + case A_BRGINTCLR: | 149 | +#define CTL3_BNK_SEL BIT(5) |
241 | + qemu_log_mask(LOG_GUEST_ERROR, | 150 | +#define CTL3_400K_MODE BIT(4) |
242 | + "IotKit SecCtl S block read: write-only offset 0x%x\n", | 151 | +#define CTL3_IDL_START BIT(3) |
243 | + offset); | 152 | +#define CTL3_ARPMEN BIT(2) |
244 | + r = 0; | 153 | +#define CTL3_SCLFRQ(rv) extract8((rv), 0, 2) |
245 | + break; | 154 | + |
246 | + default: | 155 | +/* ADDR fields */ |
247 | + qemu_log_mask(LOG_GUEST_ERROR, | 156 | +#define ADDR_EN BIT(7) |
248 | + "IotKit SecCtl S block read: bad offset 0x%x\n", offset); | 157 | +#define ADDR_A(rv) extract8((rv), 0, 6) |
249 | + r = 0; | 158 | + |
250 | + break; | 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 | + } | ||
251 | + } | 266 | + } |
252 | + | 267 | +} |
253 | + if (size != 4) { | 268 | + |
254 | + /* None of our registers are access-sensitive, so just pull the right | 269 | +static void send_nack(QTestState *qts, uint64_t base_addr) |
255 | + * byte out of the word read result. | 270 | +{ |
256 | + */ | 271 | + uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); |
257 | + r = extract32(r, (addr & 3) * 8, size * 8); | 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) | ||
358 | + | ||
359 | +int main(int argc, char **argv) | ||
360 | +{ | ||
361 | + int i; | ||
362 | + | ||
363 | + g_test_init(&argc, &argv, NULL); | ||
364 | + g_test_set_nonfatal_assertions(); | ||
365 | + | ||
366 | + for (i = 0; i < NR_SMBUS_DEVICES; ++i) { | ||
367 | + add_test(disable_bus, i); | ||
368 | + add_test(invalid_addr, i); | ||
258 | + } | 369 | + } |
259 | + | 370 | + |
260 | + trace_iotkit_secctl_s_read(offset, r, size); | 371 | + for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) { |
261 | + *pdata = r; | 372 | + add_test(single_mode, evb_bus_list[i]); |
262 | + return MEMTX_OK; | ||
263 | +} | ||
264 | + | ||
265 | +static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, | ||
266 | + uint64_t value, | ||
267 | + unsigned size, MemTxAttrs attrs) | ||
268 | +{ | ||
269 | + uint32_t offset = addr; | ||
270 | + | ||
271 | + trace_iotkit_secctl_s_write(offset, value, size); | ||
272 | + | ||
273 | + if (size != 4) { | ||
274 | + /* Byte and halfword writes are ignored */ | ||
275 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
276 | + "IotKit SecCtl S block write: bad size, ignored\n"); | ||
277 | + return MEMTX_OK; | ||
278 | + } | 373 | + } |
279 | + | 374 | + |
280 | + switch (offset) { | 375 | + return g_test_run(); |
281 | + case A_SECRESPCFG: | 376 | +} |
282 | + case A_NSCCFG: | 377 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
283 | + case A_SECPPCINTCLR: | ||
284 | + case A_SECPPCINTEN: | ||
285 | + case A_SECMSCINTCLR: | ||
286 | + case A_SECMSCINTEN: | ||
287 | + case A_BRGINTCLR: | ||
288 | + case A_BRGINTEN: | ||
289 | + case A_AHBNSPPCEXP0: | ||
290 | + case A_AHBNSPPCEXP1: | ||
291 | + case A_AHBNSPPCEXP2: | ||
292 | + case A_AHBNSPPCEXP3: | ||
293 | + case A_APBNSPPC0: | ||
294 | + case A_APBNSPPC1: | ||
295 | + case A_APBNSPPCEXP0: | ||
296 | + case A_APBNSPPCEXP1: | ||
297 | + case A_APBNSPPCEXP2: | ||
298 | + case A_APBNSPPCEXP3: | ||
299 | + case A_AHBSPPPCEXP0: | ||
300 | + case A_AHBSPPPCEXP1: | ||
301 | + case A_AHBSPPPCEXP2: | ||
302 | + case A_AHBSPPPCEXP3: | ||
303 | + case A_APBSPPPC0: | ||
304 | + case A_APBSPPPC1: | ||
305 | + case A_APBSPPPCEXP0: | ||
306 | + case A_APBSPPPCEXP1: | ||
307 | + case A_APBSPPPCEXP2: | ||
308 | + case A_APBSPPPCEXP3: | ||
309 | + qemu_log_mask(LOG_UNIMP, | ||
310 | + "IoTKit SecCtl S block write: " | ||
311 | + "unimplemented offset 0x%x\n", offset); | ||
312 | + break; | ||
313 | + case A_SECMPCINTSTATUS: | ||
314 | + case A_SECPPCINTSTAT: | ||
315 | + case A_SECMSCINTSTAT: | ||
316 | + case A_BRGINTSTAT: | ||
317 | + case A_AHBNSPPC0: | ||
318 | + case A_AHBSPPPC0: | ||
319 | + case A_NSMSCEXP: | ||
320 | + case A_PID4: | ||
321 | + case A_PID5: | ||
322 | + case A_PID6: | ||
323 | + case A_PID7: | ||
324 | + case A_PID0: | ||
325 | + case A_PID1: | ||
326 | + case A_PID2: | ||
327 | + case A_PID3: | ||
328 | + case A_CID0: | ||
329 | + case A_CID1: | ||
330 | + case A_CID2: | ||
331 | + case A_CID3: | ||
332 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
333 | + "IoTKit SecCtl S block write: " | ||
334 | + "read-only offset 0x%x\n", offset); | ||
335 | + break; | ||
336 | + default: | ||
337 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
338 | + "IotKit SecCtl S block write: bad offset 0x%x\n", | ||
339 | + offset); | ||
340 | + break; | ||
341 | + } | ||
342 | + | ||
343 | + return MEMTX_OK; | ||
344 | +} | ||
345 | + | ||
346 | +static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr, | ||
347 | + uint64_t *pdata, | ||
348 | + unsigned size, MemTxAttrs attrs) | ||
349 | +{ | ||
350 | + uint64_t r; | ||
351 | + uint32_t offset = addr & ~0x3; | ||
352 | + | ||
353 | + switch (offset) { | ||
354 | + case A_AHBNSPPPC0: | ||
355 | + r = 0; | ||
356 | + break; | ||
357 | + case A_AHBNSPPPCEXP0: | ||
358 | + case A_AHBNSPPPCEXP1: | ||
359 | + case A_AHBNSPPPCEXP2: | ||
360 | + case A_AHBNSPPPCEXP3: | ||
361 | + case A_APBNSPPPC0: | ||
362 | + case A_APBNSPPPC1: | ||
363 | + case A_APBNSPPPCEXP0: | ||
364 | + case A_APBNSPPPCEXP1: | ||
365 | + case A_APBNSPPPCEXP2: | ||
366 | + case A_APBNSPPPCEXP3: | ||
367 | + qemu_log_mask(LOG_UNIMP, | ||
368 | + "IoTKit SecCtl NS block read: " | ||
369 | + "unimplemented offset 0x%x\n", offset); | ||
370 | + break; | ||
371 | + case A_PID4: | ||
372 | + case A_PID5: | ||
373 | + case A_PID6: | ||
374 | + case A_PID7: | ||
375 | + case A_PID0: | ||
376 | + case A_PID1: | ||
377 | + case A_PID2: | ||
378 | + case A_PID3: | ||
379 | + case A_CID0: | ||
380 | + case A_CID1: | ||
381 | + case A_CID2: | ||
382 | + case A_CID3: | ||
383 | + r = iotkit_secctl_ns_idregs[(offset - A_PID4) / 4]; | ||
384 | + break; | ||
385 | + default: | ||
386 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
387 | + "IotKit SecCtl NS block write: bad offset 0x%x\n", | ||
388 | + offset); | ||
389 | + r = 0; | ||
390 | + break; | ||
391 | + } | ||
392 | + | ||
393 | + if (size != 4) { | ||
394 | + /* None of our registers are access-sensitive, so just pull the right | ||
395 | + * byte out of the word read result. | ||
396 | + */ | ||
397 | + r = extract32(r, (addr & 3) * 8, size * 8); | ||
398 | + } | ||
399 | + | ||
400 | + trace_iotkit_secctl_ns_read(offset, r, size); | ||
401 | + *pdata = r; | ||
402 | + return MEMTX_OK; | ||
403 | +} | ||
404 | + | ||
405 | +static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr, | ||
406 | + uint64_t value, | ||
407 | + unsigned size, MemTxAttrs attrs) | ||
408 | +{ | ||
409 | + uint32_t offset = addr; | ||
410 | + | ||
411 | + trace_iotkit_secctl_ns_write(offset, value, size); | ||
412 | + | ||
413 | + if (size != 4) { | ||
414 | + /* Byte and halfword writes are ignored */ | ||
415 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
416 | + "IotKit SecCtl NS block write: bad size, ignored\n"); | ||
417 | + return MEMTX_OK; | ||
418 | + } | ||
419 | + | ||
420 | + switch (offset) { | ||
421 | + case A_AHBNSPPPCEXP0: | ||
422 | + case A_AHBNSPPPCEXP1: | ||
423 | + case A_AHBNSPPPCEXP2: | ||
424 | + case A_AHBNSPPPCEXP3: | ||
425 | + case A_APBNSPPPC0: | ||
426 | + case A_APBNSPPPC1: | ||
427 | + case A_APBNSPPPCEXP0: | ||
428 | + case A_APBNSPPPCEXP1: | ||
429 | + case A_APBNSPPPCEXP2: | ||
430 | + case A_APBNSPPPCEXP3: | ||
431 | + qemu_log_mask(LOG_UNIMP, | ||
432 | + "IoTKit SecCtl NS block write: " | ||
433 | + "unimplemented offset 0x%x\n", offset); | ||
434 | + break; | ||
435 | + case A_AHBNSPPPC0: | ||
436 | + case A_PID4: | ||
437 | + case A_PID5: | ||
438 | + case A_PID6: | ||
439 | + case A_PID7: | ||
440 | + case A_PID0: | ||
441 | + case A_PID1: | ||
442 | + case A_PID2: | ||
443 | + case A_PID3: | ||
444 | + case A_CID0: | ||
445 | + case A_CID1: | ||
446 | + case A_CID2: | ||
447 | + case A_CID3: | ||
448 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
449 | + "IoTKit SecCtl NS block write: " | ||
450 | + "read-only offset 0x%x\n", offset); | ||
451 | + break; | ||
452 | + default: | ||
453 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
454 | + "IotKit SecCtl NS block write: bad offset 0x%x\n", | ||
455 | + offset); | ||
456 | + break; | ||
457 | + } | ||
458 | + | ||
459 | + return MEMTX_OK; | ||
460 | +} | ||
461 | + | ||
462 | +static const MemoryRegionOps iotkit_secctl_s_ops = { | ||
463 | + .read_with_attrs = iotkit_secctl_s_read, | ||
464 | + .write_with_attrs = iotkit_secctl_s_write, | ||
465 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
466 | + .valid.min_access_size = 1, | ||
467 | + .valid.max_access_size = 4, | ||
468 | + .impl.min_access_size = 1, | ||
469 | + .impl.max_access_size = 4, | ||
470 | +}; | ||
471 | + | ||
472 | +static const MemoryRegionOps iotkit_secctl_ns_ops = { | ||
473 | + .read_with_attrs = iotkit_secctl_ns_read, | ||
474 | + .write_with_attrs = iotkit_secctl_ns_write, | ||
475 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
476 | + .valid.min_access_size = 1, | ||
477 | + .valid.max_access_size = 4, | ||
478 | + .impl.min_access_size = 1, | ||
479 | + .impl.max_access_size = 4, | ||
480 | +}; | ||
481 | + | ||
482 | +static void iotkit_secctl_reset(DeviceState *dev) | ||
483 | +{ | ||
484 | + | ||
485 | +} | ||
486 | + | ||
487 | +static void iotkit_secctl_init(Object *obj) | ||
488 | +{ | ||
489 | + IoTKitSecCtl *s = IOTKIT_SECCTL(obj); | ||
490 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
491 | + | ||
492 | + memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops, | ||
493 | + s, "iotkit-secctl-s-regs", 0x1000); | ||
494 | + memory_region_init_io(&s->ns_regs, obj, &iotkit_secctl_ns_ops, | ||
495 | + s, "iotkit-secctl-ns-regs", 0x1000); | ||
496 | + sysbus_init_mmio(sbd, &s->s_regs); | ||
497 | + sysbus_init_mmio(sbd, &s->ns_regs); | ||
498 | +} | ||
499 | + | ||
500 | +static const VMStateDescription iotkit_secctl_vmstate = { | ||
501 | + .name = "iotkit-secctl", | ||
502 | + .version_id = 1, | ||
503 | + .minimum_version_id = 1, | ||
504 | + .fields = (VMStateField[]) { | ||
505 | + VMSTATE_END_OF_LIST() | ||
506 | + } | ||
507 | +}; | ||
508 | + | ||
509 | +static void iotkit_secctl_class_init(ObjectClass *klass, void *data) | ||
510 | +{ | ||
511 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
512 | + | ||
513 | + dc->vmsd = &iotkit_secctl_vmstate; | ||
514 | + dc->reset = iotkit_secctl_reset; | ||
515 | +} | ||
516 | + | ||
517 | +static const TypeInfo iotkit_secctl_info = { | ||
518 | + .name = TYPE_IOTKIT_SECCTL, | ||
519 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
520 | + .instance_size = sizeof(IoTKitSecCtl), | ||
521 | + .instance_init = iotkit_secctl_init, | ||
522 | + .class_init = iotkit_secctl_class_init, | ||
523 | +}; | ||
524 | + | ||
525 | +static void iotkit_secctl_register_types(void) | ||
526 | +{ | ||
527 | + type_register_static(&iotkit_secctl_info); | ||
528 | +} | ||
529 | + | ||
530 | +type_init(iotkit_secctl_register_types); | ||
531 | diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak | ||
532 | index XXXXXXX..XXXXXXX 100644 | 378 | index XXXXXXX..XXXXXXX 100644 |
533 | --- a/default-configs/arm-softmmu.mak | 379 | --- a/tests/qtest/meson.build |
534 | +++ b/default-configs/arm-softmmu.mak | 380 | +++ b/tests/qtest/meson.build |
535 | @@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y | 381 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ |
536 | CONFIG_MPS2_SCC=y | 382 | 'npcm7xx_gpio-test', |
537 | 383 | 'npcm7xx_pwm-test', | |
538 | CONFIG_TZ_PPC=y | 384 | 'npcm7xx_rng-test', |
539 | +CONFIG_IOTKIT_SECCTL=y | 385 | + 'npcm7xx_smbus-test', |
540 | 386 | 'npcm7xx_timer-test', | |
541 | CONFIG_VERSATILE_PCI=y | 387 | 'npcm7xx_watchdog_timer-test'] |
542 | CONFIG_VERSATILE_I2C=y | 388 | qtests_arm = \ |
543 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
544 | index XXXXXXX..XXXXXXX 100644 | ||
545 | --- a/hw/misc/trace-events | ||
546 | +++ b/hw/misc/trace-events | ||
547 | @@ -XXX,XX +XXX,XX @@ tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d" | ||
548 | tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d" | ||
549 | tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked" | ||
550 | tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked" | ||
551 | + | ||
552 | +# hw/misc/iotkit-secctl.c | ||
553 | +iotkit_secctl_s_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs read: offset 0x%x data 0x%" PRIx64 " size %u" | ||
554 | +iotkit_secctl_s_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs write: offset 0x%x data 0x%" PRIx64 " size %u" | ||
555 | +iotkit_secctl_ns_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs read: offset 0x%x data 0x%" PRIx64 " size %u" | ||
556 | +iotkit_secctl_ns_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs write: offset 0x%x data 0x%" PRIx64 " size %u" | ||
557 | +iotkit_secctl_reset(void) "IoTKit SecCtl: reset" | ||
558 | -- | 389 | -- |
559 | 2.16.2 | 390 | 2.20.1 |
560 | 391 | ||
561 | 392 | diff view generated by jsdifflib |
1 | Model the Arm IoT Kit documented in | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html | ||
3 | 2 | ||
4 | The Arm IoT Kit is a subsystem which includes a CPU and some devices, | 3 | This patch implements the FIFO mode of the SMBus module. In FIFO, the |
5 | and is intended be extended by adding extra devices to form a | 4 | user transmits or receives at most 16 bytes at a time. The FIFO mode |
6 | complete system. It is used in the MPS2 board's AN505 image for the | 5 | allows the module to transmit large amount of data faster than single |
7 | Cortex-M33. | 6 | byte mode. |
8 | 7 | ||
8 | Since we only added the device in a patch that is only a few commits | ||
9 | away in the same patch set. We do not increase the VMstate version | ||
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> | ||
15 | Reviewed-by: Corey Minyard <cminyard@mvista.com> | ||
16 | Message-id: 20210210220426.3577804-6-wuhaotsh@google.com | ||
17 | Acked-by: Corey Minyard <cminyard@mvista.com> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20180220180325.29818-19-peter.maydell@linaro.org | ||
12 | --- | 19 | --- |
13 | hw/arm/Makefile.objs | 1 + | 20 | include/hw/i2c/npcm7xx_smbus.h | 25 +++ |
14 | include/hw/arm/iotkit.h | 109 ++++++++ | 21 | hw/i2c/npcm7xx_smbus.c | 342 +++++++++++++++++++++++++++++-- |
15 | hw/arm/iotkit.c | 598 ++++++++++++++++++++++++++++++++++++++++ | 22 | tests/qtest/npcm7xx_smbus-test.c | 149 +++++++++++++- |
16 | default-configs/arm-softmmu.mak | 1 + | 23 | hw/i2c/trace-events | 1 + |
17 | 4 files changed, 709 insertions(+) | 24 | 4 files changed, 501 insertions(+), 16 deletions(-) |
18 | create mode 100644 include/hw/arm/iotkit.h | ||
19 | create mode 100644 hw/arm/iotkit.c | ||
20 | 25 | ||
21 | diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs | 26 | diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h |
22 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/arm/Makefile.objs | 28 | --- a/include/hw/i2c/npcm7xx_smbus.h |
24 | +++ b/hw/arm/Makefile.objs | 29 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
25 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o | ||
26 | obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o | ||
27 | obj-$(CONFIG_MPS2) += mps2.o | ||
28 | obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o | ||
29 | +obj-$(CONFIG_IOTKIT) += iotkit.o | ||
30 | diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/iotkit.h | ||
31 | new file mode 100644 | ||
32 | index XXXXXXX..XXXXXXX | ||
33 | --- /dev/null | ||
34 | +++ b/include/hw/arm/iotkit.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | 30 | @@ -XXX,XX +XXX,XX @@ |
36 | +/* | 31 | */ |
37 | + * ARM IoT Kit | 32 | #define NPCM7XX_SMBUS_NR_ADDRS 10 |
38 | + * | 33 | |
39 | + * Copyright (c) 2018 Linaro Limited | 34 | +/* Size of the FIFO buffer. */ |
40 | + * Written by Peter Maydell | 35 | +#define NPCM7XX_SMBUS_FIFO_SIZE 16 |
41 | + * | 36 | + |
42 | + * This program is free software; you can redistribute it and/or modify | 37 | typedef enum NPCM7xxSMBusStatus { |
43 | + * it under the terms of the GNU General Public License version 2 or | 38 | NPCM7XX_SMBUS_STATUS_IDLE, |
44 | + * (at your option) any later version. | 39 | NPCM7XX_SMBUS_STATUS_SENDING, |
45 | + */ | 40 | @@ -XXX,XX +XXX,XX @@ typedef enum NPCM7xxSMBusStatus { |
46 | + | 41 | * @addr: The SMBus module's own addresses on the I2C bus. |
47 | +/* This is a model of the Arm IoT Kit which is documented in | 42 | * @scllt: The SCL low time register. |
48 | + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html | 43 | * @sclht: The SCL high time register. |
49 | + * It contains: | 44 | + * @fif_ctl: The FIFO control register. |
50 | + * a Cortex-M33 | 45 | + * @fif_cts: The FIFO control status register. |
51 | + * the IDAU | 46 | + * @fair_per: The fair preriod register. |
52 | + * some timers and watchdogs | 47 | + * @txf_ctl: The transmit FIFO control register. |
53 | + * two peripheral protection controllers | 48 | + * @t_out: The SMBus timeout register. |
54 | + * a memory protection controller | 49 | + * @txf_sts: The transmit FIFO status register. |
55 | + * a security controller | 50 | + * @rxf_sts: The receive FIFO status register. |
56 | + * a bus fabric which arranges that some parts of the address | 51 | + * @rxf_ctl: The receive FIFO control register. |
57 | + * space are secure and non-secure aliases of each other | 52 | + * @rx_fifo: The FIFO buffer for receiving in FIFO mode. |
58 | + * | 53 | + * @rx_cur: The current position of rx_fifo. |
59 | + * QEMU interface: | 54 | * @status: The current status of the SMBus. |
60 | + * + QOM property "memory" is a MemoryRegion containing the devices provided | 55 | */ |
61 | + * by the board model. | 56 | typedef struct NPCM7xxSMBusState { |
62 | + * + QOM property "MAINCLK" is the frequency of the main system clock | 57 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxSMBusState { |
63 | + * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts | 58 | uint8_t scllt; |
64 | + * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts, which | 59 | uint8_t sclht; |
65 | + * are wired to the NVIC lines 32 .. n+32 | 60 | |
66 | + * Controlling up to 4 AHB expansion PPBs which a system using the IoTKit | 61 | + uint8_t fif_ctl; |
67 | + * might provide: | 62 | + uint8_t fif_cts; |
68 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15] | 63 | + uint8_t fair_per; |
69 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15] | 64 | + uint8_t txf_ctl; |
70 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable | 65 | + uint8_t t_out; |
71 | + * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear | 66 | + uint8_t txf_sts; |
72 | + * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status | 67 | + uint8_t rxf_sts; |
73 | + * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit | 68 | + uint8_t rxf_ctl; |
74 | + * might provide: | 69 | + |
75 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15] | 70 | + uint8_t rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE]; |
76 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15] | 71 | + uint8_t rx_cur; |
77 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable | 72 | + |
78 | + * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear | 73 | NPCM7xxSMBusStatus status; |
79 | + * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status | 74 | } NPCM7xxSMBusState; |
80 | + */ | 75 | |
81 | + | 76 | diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c |
82 | +#ifndef IOTKIT_H | 77 | index XXXXXXX..XXXXXXX 100644 |
83 | +#define IOTKIT_H | 78 | --- a/hw/i2c/npcm7xx_smbus.c |
84 | + | 79 | +++ b/hw/i2c/npcm7xx_smbus.c |
85 | +#include "hw/sysbus.h" | 80 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { |
86 | +#include "hw/arm/armv7m.h" | 81 | #define NPCM7XX_ADDR_EN BIT(7) |
87 | +#include "hw/misc/iotkit-secctl.h" | 82 | #define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6) |
88 | +#include "hw/misc/tz-ppc.h" | 83 | |
89 | +#include "hw/timer/cmsdk-apb-timer.h" | 84 | +/* FIFO Mode Register Fields */ |
90 | +#include "hw/misc/unimp.h" | 85 | +/* FIF_CTL fields */ |
91 | +#include "hw/or-irq.h" | 86 | +#define NPCM7XX_SMBFIF_CTL_FIFO_EN BIT(4) |
92 | +#include "hw/core/split-irq.h" | 87 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY_IE BIT(2) |
93 | + | 88 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY BIT(1) |
94 | +#define TYPE_IOTKIT "iotkit" | 89 | +#define NPCM7XX_SMBFIF_CTL_FAIR_BUSY BIT(0) |
95 | +#define IOTKIT(obj) OBJECT_CHECK(IoTKit, (obj), TYPE_IOTKIT) | 90 | +/* FIF_CTS fields */ |
96 | + | 91 | +#define NPCM7XX_SMBFIF_CTS_STR BIT(7) |
97 | +/* We have an IRQ splitter and an OR gate input for each external PPC | 92 | +#define NPCM7XX_SMBFIF_CTS_CLR_FIFO BIT(6) |
98 | + * and the 2 internal PPCs | 93 | +#define NPCM7XX_SMBFIF_CTS_RFTE_IE BIT(3) |
99 | + */ | 94 | +#define NPCM7XX_SMBFIF_CTS_RXF_TXE BIT(1) |
100 | +#define NUM_EXTERNAL_PPCS (IOTS_NUM_AHB_EXP_PPC + IOTS_NUM_APB_EXP_PPC) | 95 | +/* TXF_CTL fields */ |
101 | +#define NUM_PPCS (NUM_EXTERNAL_PPCS + 2) | 96 | +#define NPCM7XX_SMBTXF_CTL_THR_TXIE BIT(6) |
102 | + | 97 | +#define NPCM7XX_SMBTXF_CTL_TX_THR(rv) extract8((rv), 0, 5) |
103 | +typedef struct IoTKit { | 98 | +/* T_OUT fields */ |
104 | + /*< private >*/ | 99 | +#define NPCM7XX_SMBT_OUT_ST BIT(7) |
105 | + SysBusDevice parent_obj; | 100 | +#define NPCM7XX_SMBT_OUT_IE BIT(6) |
106 | + | 101 | +#define NPCM7XX_SMBT_OUT_CLKDIV(rv) extract8((rv), 0, 6) |
107 | + /*< public >*/ | 102 | +/* TXF_STS fields */ |
108 | + ARMv7MState armv7m; | 103 | +#define NPCM7XX_SMBTXF_STS_TX_THST BIT(6) |
109 | + IoTKitSecCtl secctl; | 104 | +#define NPCM7XX_SMBTXF_STS_TX_BYTES(rv) extract8((rv), 0, 5) |
110 | + TZPPC apb_ppc0; | 105 | +/* RXF_STS fields */ |
111 | + TZPPC apb_ppc1; | 106 | +#define NPCM7XX_SMBRXF_STS_RX_THST BIT(6) |
112 | + CMSDKAPBTIMER timer0; | 107 | +#define NPCM7XX_SMBRXF_STS_RX_BYTES(rv) extract8((rv), 0, 5) |
113 | + CMSDKAPBTIMER timer1; | 108 | +/* RXF_CTL fields */ |
114 | + qemu_or_irq ppc_irq_orgate; | 109 | +#define NPCM7XX_SMBRXF_CTL_THR_RXIE BIT(6) |
115 | + SplitIRQ sec_resp_splitter; | 110 | +#define NPCM7XX_SMBRXF_CTL_LAST BIT(5) |
116 | + SplitIRQ ppc_irq_splitter[NUM_PPCS]; | 111 | +#define NPCM7XX_SMBRXF_CTL_RX_THR(rv) extract8((rv), 0, 5) |
117 | + | 112 | + |
118 | + UnimplementedDeviceState dualtimer; | 113 | #define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b))) |
119 | + UnimplementedDeviceState s32ktimer; | 114 | #define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o)) |
120 | + | 115 | |
121 | + MemoryRegion container; | 116 | #define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE) |
122 | + MemoryRegion alias1; | 117 | +#define NPCM7XX_SMBUS_FIFO_ENABLED(s) ((s)->fif_ctl & \ |
123 | + MemoryRegion alias2; | 118 | + NPCM7XX_SMBFIF_CTL_FIFO_EN) |
124 | + MemoryRegion alias3; | 119 | |
125 | + MemoryRegion sram0; | 120 | /* VERSION fields values, read-only. */ |
126 | + | 121 | #define NPCM7XX_SMBUS_VERSION_NUMBER 1 |
127 | + qemu_irq *exp_irqs; | 122 | -#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0 |
128 | + qemu_irq ppc0_irq; | 123 | +#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 1 |
129 | + qemu_irq ppc1_irq; | 124 | |
130 | + qemu_irq sec_resp_cfg; | 125 | /* Reset values */ |
131 | + qemu_irq sec_resp_cfg_in; | 126 | #define NPCM7XX_SMB_ST_INIT_VAL 0x00 |
132 | + qemu_irq nsc_cfg_in; | 127 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { |
133 | + | 128 | #define NPCM7XX_SMB_ADDR_INIT_VAL 0x00 |
134 | + qemu_irq irq_status_in[NUM_EXTERNAL_PPCS]; | 129 | #define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00 |
135 | + | 130 | #define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00 |
136 | + uint32_t nsccfg; | 131 | +#define NPCM7XX_SMB_FIF_CTL_INIT_VAL 0x00 |
137 | + | 132 | +#define NPCM7XX_SMB_FIF_CTS_INIT_VAL 0x00 |
138 | + /* Properties */ | 133 | +#define NPCM7XX_SMB_FAIR_PER_INIT_VAL 0x00 |
139 | + MemoryRegion *board_memory; | 134 | +#define NPCM7XX_SMB_TXF_CTL_INIT_VAL 0x00 |
140 | + uint32_t exp_numirq; | 135 | +#define NPCM7XX_SMB_T_OUT_INIT_VAL 0x3f |
141 | + uint32_t mainclk_frq; | 136 | +#define NPCM7XX_SMB_TXF_STS_INIT_VAL 0x00 |
142 | +} IoTKit; | 137 | +#define NPCM7XX_SMB_RXF_STS_INIT_VAL 0x00 |
143 | + | 138 | +#define NPCM7XX_SMB_RXF_CTL_INIT_VAL 0x01 |
144 | +#endif | 139 | |
145 | diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c | 140 | static uint8_t npcm7xx_smbus_get_version(void) |
146 | new file mode 100644 | 141 | { |
147 | index XXXXXXX..XXXXXXX | 142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s) |
148 | --- /dev/null | 143 | (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE && |
149 | +++ b/hw/arm/iotkit.c | 144 | s->st & NPCM7XX_SMBST_SDAST) || |
150 | @@ -XXX,XX +XXX,XX @@ | 145 | (s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE && |
151 | +/* | 146 | - s->cst3 & NPCM7XX_SMBCST3_EO_BUSY)); |
152 | + * Arm IoT Kit | 147 | + s->cst3 & NPCM7XX_SMBCST3_EO_BUSY) || |
153 | + * | 148 | + (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE && |
154 | + * Copyright (c) 2018 Linaro Limited | 149 | + s->rxf_sts & NPCM7XX_SMBRXF_STS_RX_THST) || |
155 | + * Written by Peter Maydell | 150 | + (s->txf_ctl & NPCM7XX_SMBTXF_CTL_THR_TXIE && |
156 | + * | 151 | + s->txf_sts & NPCM7XX_SMBTXF_STS_TX_THST) || |
157 | + * This program is free software; you can redistribute it and/or modify | 152 | + (s->fif_cts & NPCM7XX_SMBFIF_CTS_RFTE_IE && |
158 | + * it under the terms of the GNU General Public License version 2 or | 153 | + s->fif_cts & NPCM7XX_SMBFIF_CTS_RXF_TXE)); |
159 | + * (at your option) any later version. | 154 | |
160 | + */ | 155 | if (level) { |
161 | + | 156 | s->cst2 |= NPCM7XX_SMBCST2_INTSTS; |
162 | +#include "qemu/osdep.h" | 157 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s) |
163 | +#include "qemu/log.h" | 158 | s->status = NPCM7XX_SMBUS_STATUS_NEGACK; |
164 | +#include "qapi/error.h" | 159 | } |
165 | +#include "trace.h" | 160 | |
166 | +#include "hw/sysbus.h" | 161 | +static void npcm7xx_smbus_clear_buffer(NPCM7xxSMBusState *s) |
167 | +#include "hw/registerfields.h" | 162 | +{ |
168 | +#include "hw/arm/iotkit.h" | 163 | + s->fif_cts &= ~NPCM7XX_SMBFIF_CTS_RXF_TXE; |
169 | +#include "hw/misc/unimp.h" | 164 | + s->txf_sts = 0; |
170 | +#include "hw/arm/arm.h" | 165 | + s->rxf_sts = 0; |
171 | + | 166 | +} |
172 | +/* Create an alias region of @size bytes starting at @base | 167 | + |
173 | + * which mirrors the memory starting at @orig. | 168 | static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) |
174 | + */ | 169 | { |
175 | +static void make_alias(IoTKit *s, MemoryRegion *mr, const char *name, | 170 | int rv = i2c_send(s->bus, value); |
176 | + hwaddr base, hwaddr size, hwaddr orig) | 171 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) |
177 | +{ | 172 | npcm7xx_smbus_nack(s); |
178 | + memory_region_init_alias(mr, NULL, name, &s->container, orig, size); | 173 | } else { |
179 | + /* The alias is even lower priority than unimplemented_device regions */ | 174 | s->st |= NPCM7XX_SMBST_SDAST; |
180 | + memory_region_add_subregion_overlap(&s->container, base, mr, -1500); | 175 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
181 | +} | 176 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
182 | + | 177 | + if (NPCM7XX_SMBTXF_STS_TX_BYTES(s->txf_sts) == |
183 | +static void init_sysbus_child(Object *parent, const char *childname, | 178 | + NPCM7XX_SMBTXF_CTL_TX_THR(s->txf_ctl)) { |
184 | + void *child, size_t childsize, | 179 | + s->txf_sts = NPCM7XX_SMBTXF_STS_TX_THST; |
185 | + const char *childtype) | 180 | + } else { |
186 | +{ | 181 | + s->txf_sts = 0; |
187 | + object_initialize(child, childsize, childtype); | 182 | + } |
188 | + object_property_add_child(parent, childname, OBJECT(child), &error_abort); | 183 | + } |
189 | + qdev_set_parent_bus(DEVICE(child), sysbus_get_default()); | 184 | } |
190 | +} | 185 | trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv); |
191 | + | 186 | npcm7xx_smbus_update_irq(s); |
192 | +static void irq_status_forwarder(void *opaque, int n, int level) | 187 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s) |
193 | +{ | 188 | npcm7xx_smbus_update_irq(s); |
194 | + qemu_irq destirq = opaque; | 189 | } |
195 | + | 190 | |
196 | + qemu_set_irq(destirq, level); | 191 | +static void npcm7xx_smbus_recv_fifo(NPCM7xxSMBusState *s) |
197 | +} | 192 | +{ |
198 | + | 193 | + uint8_t expected_bytes = NPCM7XX_SMBRXF_CTL_RX_THR(s->rxf_ctl); |
199 | +static void nsccfg_handler(void *opaque, int n, int level) | 194 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); |
200 | +{ | 195 | + uint8_t pos; |
201 | + IoTKit *s = IOTKIT(opaque); | 196 | + |
202 | + | 197 | + if (received_bytes == expected_bytes) { |
203 | + s->nsccfg = level; | ||
204 | +} | ||
205 | + | ||
206 | +static void iotkit_forward_ppc(IoTKit *s, const char *ppcname, int ppcnum) | ||
207 | +{ | ||
208 | + /* Each of the 4 AHB and 4 APB PPCs that might be present in a | ||
209 | + * system using the IoTKit has a collection of control lines which | ||
210 | + * are provided by the security controller and which we want to | ||
211 | + * expose as control lines on the IoTKit device itself, so the | ||
212 | + * code using the IoTKit can wire them up to the PPCs. | ||
213 | + */ | ||
214 | + SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum]; | ||
215 | + DeviceState *iotkitdev = DEVICE(s); | ||
216 | + DeviceState *dev_secctl = DEVICE(&s->secctl); | ||
217 | + DeviceState *dev_splitter = DEVICE(splitter); | ||
218 | + char *name; | ||
219 | + | ||
220 | + name = g_strdup_printf("%s_nonsec", ppcname); | ||
221 | + qdev_pass_gpios(dev_secctl, iotkitdev, name); | ||
222 | + g_free(name); | ||
223 | + name = g_strdup_printf("%s_ap", ppcname); | ||
224 | + qdev_pass_gpios(dev_secctl, iotkitdev, name); | ||
225 | + g_free(name); | ||
226 | + name = g_strdup_printf("%s_irq_enable", ppcname); | ||
227 | + qdev_pass_gpios(dev_secctl, iotkitdev, name); | ||
228 | + g_free(name); | ||
229 | + name = g_strdup_printf("%s_irq_clear", ppcname); | ||
230 | + qdev_pass_gpios(dev_secctl, iotkitdev, name); | ||
231 | + g_free(name); | ||
232 | + | ||
233 | + /* irq_status is a little more tricky, because we need to | ||
234 | + * split it so we can send it both to the security controller | ||
235 | + * and to our OR gate for the NVIC interrupt line. | ||
236 | + * Connect up the splitter's outputs, and create a GPIO input | ||
237 | + * which will pass the line state to the input splitter. | ||
238 | + */ | ||
239 | + name = g_strdup_printf("%s_irq_status", ppcname); | ||
240 | + qdev_connect_gpio_out(dev_splitter, 0, | ||
241 | + qdev_get_gpio_in_named(dev_secctl, | ||
242 | + name, 0)); | ||
243 | + qdev_connect_gpio_out(dev_splitter, 1, | ||
244 | + qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum)); | ||
245 | + s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0); | ||
246 | + qdev_init_gpio_in_named_with_opaque(iotkitdev, irq_status_forwarder, | ||
247 | + s->irq_status_in[ppcnum], name, 1); | ||
248 | + g_free(name); | ||
249 | +} | ||
250 | + | ||
251 | +static void iotkit_forward_sec_resp_cfg(IoTKit *s) | ||
252 | +{ | ||
253 | + /* Forward the 3rd output from the splitter device as a | ||
254 | + * named GPIO output of the iotkit object. | ||
255 | + */ | ||
256 | + DeviceState *dev = DEVICE(s); | ||
257 | + DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter); | ||
258 | + | ||
259 | + qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1); | ||
260 | + s->sec_resp_cfg_in = qemu_allocate_irq(irq_status_forwarder, | ||
261 | + s->sec_resp_cfg, 1); | ||
262 | + qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in); | ||
263 | +} | ||
264 | + | ||
265 | +static void iotkit_init(Object *obj) | ||
266 | +{ | ||
267 | + IoTKit *s = IOTKIT(obj); | ||
268 | + int i; | ||
269 | + | ||
270 | + memory_region_init(&s->container, obj, "iotkit-container", UINT64_MAX); | ||
271 | + | ||
272 | + init_sysbus_child(obj, "armv7m", &s->armv7m, sizeof(s->armv7m), | ||
273 | + TYPE_ARMV7M); | ||
274 | + qdev_prop_set_string(DEVICE(&s->armv7m), "cpu-type", | ||
275 | + ARM_CPU_TYPE_NAME("cortex-m33")); | ||
276 | + | ||
277 | + init_sysbus_child(obj, "secctl", &s->secctl, sizeof(s->secctl), | ||
278 | + TYPE_IOTKIT_SECCTL); | ||
279 | + init_sysbus_child(obj, "apb-ppc0", &s->apb_ppc0, sizeof(s->apb_ppc0), | ||
280 | + TYPE_TZ_PPC); | ||
281 | + init_sysbus_child(obj, "apb-ppc1", &s->apb_ppc1, sizeof(s->apb_ppc1), | ||
282 | + TYPE_TZ_PPC); | ||
283 | + init_sysbus_child(obj, "timer0", &s->timer0, sizeof(s->timer0), | ||
284 | + TYPE_CMSDK_APB_TIMER); | ||
285 | + init_sysbus_child(obj, "timer1", &s->timer1, sizeof(s->timer1), | ||
286 | + TYPE_CMSDK_APB_TIMER); | ||
287 | + init_sysbus_child(obj, "dualtimer", &s->dualtimer, sizeof(s->dualtimer), | ||
288 | + TYPE_UNIMPLEMENTED_DEVICE); | ||
289 | + object_initialize(&s->ppc_irq_orgate, sizeof(s->ppc_irq_orgate), | ||
290 | + TYPE_OR_IRQ); | ||
291 | + object_property_add_child(obj, "ppc-irq-orgate", | ||
292 | + OBJECT(&s->ppc_irq_orgate), &error_abort); | ||
293 | + object_initialize(&s->sec_resp_splitter, sizeof(s->sec_resp_splitter), | ||
294 | + TYPE_SPLIT_IRQ); | ||
295 | + object_property_add_child(obj, "sec-resp-splitter", | ||
296 | + OBJECT(&s->sec_resp_splitter), &error_abort); | ||
297 | + for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) { | ||
298 | + char *name = g_strdup_printf("ppc-irq-splitter-%d", i); | ||
299 | + SplitIRQ *splitter = &s->ppc_irq_splitter[i]; | ||
300 | + | ||
301 | + object_initialize(splitter, sizeof(*splitter), TYPE_SPLIT_IRQ); | ||
302 | + object_property_add_child(obj, name, OBJECT(splitter), &error_abort); | ||
303 | + } | ||
304 | + init_sysbus_child(obj, "s32ktimer", &s->s32ktimer, sizeof(s->s32ktimer), | ||
305 | + TYPE_UNIMPLEMENTED_DEVICE); | ||
306 | +} | ||
307 | + | ||
308 | +static void iotkit_exp_irq(void *opaque, int n, int level) | ||
309 | +{ | ||
310 | + IoTKit *s = IOTKIT(opaque); | ||
311 | + | ||
312 | + qemu_set_irq(s->exp_irqs[n], level); | ||
313 | +} | ||
314 | + | ||
315 | +static void iotkit_realize(DeviceState *dev, Error **errp) | ||
316 | +{ | ||
317 | + IoTKit *s = IOTKIT(dev); | ||
318 | + int i; | ||
319 | + MemoryRegion *mr; | ||
320 | + Error *err = NULL; | ||
321 | + SysBusDevice *sbd_apb_ppc0; | ||
322 | + SysBusDevice *sbd_secctl; | ||
323 | + DeviceState *dev_apb_ppc0; | ||
324 | + DeviceState *dev_apb_ppc1; | ||
325 | + DeviceState *dev_secctl; | ||
326 | + DeviceState *dev_splitter; | ||
327 | + | ||
328 | + if (!s->board_memory) { | ||
329 | + error_setg(errp, "memory property was not set"); | ||
330 | + return; | 198 | + return; |
331 | + } | 199 | + } |
332 | + | 200 | + |
333 | + if (!s->mainclk_frq) { | 201 | + while (received_bytes < expected_bytes && |
334 | + error_setg(errp, "MAINCLK property was not set"); | 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); | ||
335 | + return; | 217 | + return; |
336 | + } | 218 | + } |
337 | + | 219 | + |
338 | + /* Handling of which devices should be available only to secure | 220 | + s->rxf_sts |= NPCM7XX_SMBRXF_STS_RX_THST; |
339 | + * code is usually done differently for M profile than for A profile. | 221 | + if (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_LAST) { |
340 | + * Instead of putting some devices only into the secure address space, | 222 | + trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path); |
341 | + * devices exist in both address spaces but with hard-wired security | 223 | + i2c_nack(s->bus); |
342 | + * permissions that will cause the CPU to fault for non-secure accesses. | 224 | + s->rxf_ctl &= ~NPCM7XX_SMBRXF_CTL_LAST; |
343 | + * | 225 | + } |
344 | + * The IoTKit has an IDAU (Implementation Defined Access Unit), | 226 | + if (received_bytes == NPCM7XX_SMBUS_FIFO_SIZE) { |
345 | + * which specifies hard-wired security permissions for different | 227 | + s->st |= NPCM7XX_SMBST_SDAST; |
346 | + * areas of the physical address space. For the IoTKit IDAU, the | 228 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
347 | + * top 4 bits of the physical address are the IDAU region ID, and | 229 | + } else if (!(s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE)) { |
348 | + * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS | 230 | + s->st |= NPCM7XX_SMBST_SDAST; |
349 | + * region, otherwise it is an S region. | 231 | + } else { |
350 | + * | 232 | + s->st &= ~NPCM7XX_SMBST_SDAST; |
351 | + * The various devices and RAMs are generally all mapped twice, | 233 | + } |
352 | + * once into a region that the IDAU defines as secure and once | 234 | + npcm7xx_smbus_update_irq(s); |
353 | + * into a non-secure region. They sit behind either a Memory | 235 | +} |
354 | + * Protection Controller (for RAM) or a Peripheral Protection | 236 | + |
355 | + * Controller (for devices), which allow a more fine grained | 237 | +static void npcm7xx_smbus_read_byte_fifo(NPCM7xxSMBusState *s) |
356 | + * configuration of whether non-secure accesses are permitted. | 238 | +{ |
357 | + * | 239 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); |
358 | + * (The other place that guest software can configure security | 240 | + |
359 | + * permissions is in the architected SAU (Security Attribution | 241 | + if (received_bytes == 0) { |
360 | + * Unit), which is entirely inside the CPU. The IDAU can upgrade | 242 | + npcm7xx_smbus_recv_fifo(s); |
361 | + * the security attributes for a region to more restrictive than | ||
362 | + * the SAU specifies, but cannot downgrade them.) | ||
363 | + * | ||
364 | + * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff | ||
365 | + * 0x20000000..0x2007ffff 32KB FPGA block RAM | ||
366 | + * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff | ||
367 | + * 0x40000000..0x4000ffff base peripheral region 1 | ||
368 | + * 0x40010000..0x4001ffff CPU peripherals (none for IoTKit) | ||
369 | + * 0x40020000..0x4002ffff system control element peripherals | ||
370 | + * 0x40080000..0x400fffff base peripheral region 2 | ||
371 | + * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff | ||
372 | + */ | ||
373 | + | ||
374 | + memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1); | ||
375 | + | ||
376 | + qdev_prop_set_uint32(DEVICE(&s->armv7m), "num-irq", s->exp_numirq + 32); | ||
377 | + /* In real hardware the initial Secure VTOR is set from the INITSVTOR0 | ||
378 | + * register in the IoT Kit System Control Register block, and the | ||
379 | + * initial value of that is in turn specifiable by the FPGA that | ||
380 | + * instantiates the IoT Kit. In QEMU we don't implement this wrinkle, | ||
381 | + * and simply set the CPU's init-svtor to the IoT Kit default value. | ||
382 | + */ | ||
383 | + qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-svtor", 0x10000000); | ||
384 | + object_property_set_link(OBJECT(&s->armv7m), OBJECT(&s->container), | ||
385 | + "memory", &err); | ||
386 | + if (err) { | ||
387 | + error_propagate(errp, err); | ||
388 | + return; | 243 | + return; |
389 | + } | 244 | + } |
390 | + object_property_set_link(OBJECT(&s->armv7m), OBJECT(s), "idau", &err); | 245 | + |
391 | + if (err) { | 246 | + s->sda = s->rx_fifo[s->rx_cur]; |
392 | + error_propagate(errp, err); | 247 | + s->rx_cur = (s->rx_cur + 1u) % NPCM7XX_SMBUS_FIFO_SIZE; |
393 | + return; | 248 | + --s->rxf_sts; |
394 | + } | 249 | + npcm7xx_smbus_update_irq(s); |
395 | + object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err); | 250 | +} |
396 | + if (err) { | 251 | + |
397 | + error_propagate(errp, err); | 252 | static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) |
398 | + return; | 253 | { |
399 | + } | 254 | /* |
400 | + | 255 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) |
401 | + /* Connect our EXP_IRQ GPIOs to the NVIC's lines 32 and up. */ | 256 | if (available) { |
402 | + s->exp_irqs = g_new(qemu_irq, s->exp_numirq); | 257 | s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST; |
403 | + for (i = 0; i < s->exp_numirq; i++) { | 258 | s->cst |= NPCM7XX_SMBCST_BUSY; |
404 | + s->exp_irqs[i] = qdev_get_gpio_in(DEVICE(&s->armv7m), i + 32); | 259 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
405 | + } | 260 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
406 | + qdev_init_gpio_in_named(dev, iotkit_exp_irq, "EXP_IRQ", s->exp_numirq); | ||
407 | + | ||
408 | + /* Set up the big aliases first */ | ||
409 | + make_alias(s, &s->alias1, "alias 1", 0x10000000, 0x10000000, 0x00000000); | ||
410 | + make_alias(s, &s->alias2, "alias 2", 0x30000000, 0x10000000, 0x20000000); | ||
411 | + /* The 0x50000000..0x5fffffff region is not a pure alias: it has | ||
412 | + * a few extra devices that only appear there (generally the | ||
413 | + * control interfaces for the protection controllers). | ||
414 | + * We implement this by mapping those devices over the top of this | ||
415 | + * alias MR at a higher priority. | ||
416 | + */ | ||
417 | + make_alias(s, &s->alias3, "alias 3", 0x50000000, 0x10000000, 0x40000000); | ||
418 | + | ||
419 | + /* This RAM should be behind a Memory Protection Controller, but we | ||
420 | + * don't implement that yet. | ||
421 | + */ | ||
422 | + memory_region_init_ram(&s->sram0, NULL, "iotkit.sram0", 0x00008000, &err); | ||
423 | + if (err) { | ||
424 | + error_propagate(errp, err); | ||
425 | + return; | ||
426 | + } | ||
427 | + memory_region_add_subregion(&s->container, 0x20000000, &s->sram0); | ||
428 | + | ||
429 | + /* Security controller */ | ||
430 | + object_property_set_bool(OBJECT(&s->secctl), true, "realized", &err); | ||
431 | + if (err) { | ||
432 | + error_propagate(errp, err); | ||
433 | + return; | ||
434 | + } | ||
435 | + sbd_secctl = SYS_BUS_DEVICE(&s->secctl); | ||
436 | + dev_secctl = DEVICE(&s->secctl); | ||
437 | + sysbus_mmio_map(sbd_secctl, 0, 0x50080000); | ||
438 | + sysbus_mmio_map(sbd_secctl, 1, 0x40080000); | ||
439 | + | ||
440 | + s->nsc_cfg_in = qemu_allocate_irq(nsccfg_handler, s, 1); | ||
441 | + qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in); | ||
442 | + | ||
443 | + /* The sec_resp_cfg output from the security controller must be split into | ||
444 | + * multiple lines, one for each of the PPCs within the IoTKit and one | ||
445 | + * that will be an output from the IoTKit to the system. | ||
446 | + */ | ||
447 | + object_property_set_int(OBJECT(&s->sec_resp_splitter), 3, | ||
448 | + "num-lines", &err); | ||
449 | + if (err) { | ||
450 | + error_propagate(errp, err); | ||
451 | + return; | ||
452 | + } | ||
453 | + object_property_set_bool(OBJECT(&s->sec_resp_splitter), true, | ||
454 | + "realized", &err); | ||
455 | + if (err) { | ||
456 | + error_propagate(errp, err); | ||
457 | + return; | ||
458 | + } | ||
459 | + dev_splitter = DEVICE(&s->sec_resp_splitter); | ||
460 | + qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0, | ||
461 | + qdev_get_gpio_in(dev_splitter, 0)); | ||
462 | + | ||
463 | + /* Devices behind APB PPC0: | ||
464 | + * 0x40000000: timer0 | ||
465 | + * 0x40001000: timer1 | ||
466 | + * 0x40002000: dual timer | ||
467 | + * We must configure and realize each downstream device and connect | ||
468 | + * it to the appropriate PPC port; then we can realize the PPC and | ||
469 | + * map its upstream ends to the right place in the container. | ||
470 | + */ | ||
471 | + qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq); | ||
472 | + object_property_set_bool(OBJECT(&s->timer0), true, "realized", &err); | ||
473 | + if (err) { | ||
474 | + error_propagate(errp, err); | ||
475 | + return; | ||
476 | + } | ||
477 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer0), 0, | ||
478 | + qdev_get_gpio_in(DEVICE(&s->armv7m), 3)); | ||
479 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer0), 0); | ||
480 | + object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[0]", &err); | ||
481 | + if (err) { | ||
482 | + error_propagate(errp, err); | ||
483 | + return; | ||
484 | + } | ||
485 | + | ||
486 | + qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq); | ||
487 | + object_property_set_bool(OBJECT(&s->timer1), true, "realized", &err); | ||
488 | + if (err) { | ||
489 | + error_propagate(errp, err); | ||
490 | + return; | ||
491 | + } | ||
492 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer1), 0, | ||
493 | + qdev_get_gpio_in(DEVICE(&s->armv7m), 3)); | ||
494 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer1), 0); | ||
495 | + object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[1]", &err); | ||
496 | + if (err) { | ||
497 | + error_propagate(errp, err); | ||
498 | + return; | ||
499 | + } | ||
500 | + | ||
501 | + qdev_prop_set_string(DEVICE(&s->dualtimer), "name", "Dual timer"); | ||
502 | + qdev_prop_set_uint64(DEVICE(&s->dualtimer), "size", 0x1000); | ||
503 | + object_property_set_bool(OBJECT(&s->dualtimer), true, "realized", &err); | ||
504 | + if (err) { | ||
505 | + error_propagate(errp, err); | ||
506 | + return; | ||
507 | + } | ||
508 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dualtimer), 0); | ||
509 | + object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[2]", &err); | ||
510 | + if (err) { | ||
511 | + error_propagate(errp, err); | ||
512 | + return; | ||
513 | + } | ||
514 | + | ||
515 | + object_property_set_bool(OBJECT(&s->apb_ppc0), true, "realized", &err); | ||
516 | + if (err) { | ||
517 | + error_propagate(errp, err); | ||
518 | + return; | ||
519 | + } | ||
520 | + | ||
521 | + sbd_apb_ppc0 = SYS_BUS_DEVICE(&s->apb_ppc0); | ||
522 | + dev_apb_ppc0 = DEVICE(&s->apb_ppc0); | ||
523 | + | ||
524 | + mr = sysbus_mmio_get_region(sbd_apb_ppc0, 0); | ||
525 | + memory_region_add_subregion(&s->container, 0x40000000, mr); | ||
526 | + mr = sysbus_mmio_get_region(sbd_apb_ppc0, 1); | ||
527 | + memory_region_add_subregion(&s->container, 0x40001000, mr); | ||
528 | + mr = sysbus_mmio_get_region(sbd_apb_ppc0, 2); | ||
529 | + memory_region_add_subregion(&s->container, 0x40002000, mr); | ||
530 | + for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) { | ||
531 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i, | ||
532 | + qdev_get_gpio_in_named(dev_apb_ppc0, | ||
533 | + "cfg_nonsec", i)); | ||
534 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_ap", i, | ||
535 | + qdev_get_gpio_in_named(dev_apb_ppc0, | ||
536 | + "cfg_ap", i)); | ||
537 | + } | ||
538 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_enable", 0, | ||
539 | + qdev_get_gpio_in_named(dev_apb_ppc0, | ||
540 | + "irq_enable", 0)); | ||
541 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_clear", 0, | ||
542 | + qdev_get_gpio_in_named(dev_apb_ppc0, | ||
543 | + "irq_clear", 0)); | ||
544 | + qdev_connect_gpio_out(dev_splitter, 0, | ||
545 | + qdev_get_gpio_in_named(dev_apb_ppc0, | ||
546 | + "cfg_sec_resp", 0)); | ||
547 | + | ||
548 | + /* All the PPC irq lines (from the 2 internal PPCs and the 8 external | ||
549 | + * ones) are sent individually to the security controller, and also | ||
550 | + * ORed together to give a single combined PPC interrupt to the NVIC. | ||
551 | + */ | ||
552 | + object_property_set_int(OBJECT(&s->ppc_irq_orgate), | ||
553 | + NUM_PPCS, "num-lines", &err); | ||
554 | + if (err) { | ||
555 | + error_propagate(errp, err); | ||
556 | + return; | ||
557 | + } | ||
558 | + object_property_set_bool(OBJECT(&s->ppc_irq_orgate), true, | ||
559 | + "realized", &err); | ||
560 | + if (err) { | ||
561 | + error_propagate(errp, err); | ||
562 | + return; | ||
563 | + } | ||
564 | + qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0, | ||
565 | + qdev_get_gpio_in(DEVICE(&s->armv7m), 10)); | ||
566 | + | ||
567 | + /* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */ | ||
568 | + | ||
569 | + /* 0x40020000 .. 0x4002ffff : IoTKit system control peripheral region */ | ||
570 | + /* Devices behind APB PPC1: | ||
571 | + * 0x4002f000: S32K timer | ||
572 | + */ | ||
573 | + qdev_prop_set_string(DEVICE(&s->s32ktimer), "name", "S32KTIMER"); | ||
574 | + qdev_prop_set_uint64(DEVICE(&s->s32ktimer), "size", 0x1000); | ||
575 | + object_property_set_bool(OBJECT(&s->s32ktimer), true, "realized", &err); | ||
576 | + if (err) { | ||
577 | + error_propagate(errp, err); | ||
578 | + return; | ||
579 | + } | ||
580 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->s32ktimer), 0); | ||
581 | + object_property_set_link(OBJECT(&s->apb_ppc1), OBJECT(mr), "port[0]", &err); | ||
582 | + if (err) { | ||
583 | + error_propagate(errp, err); | ||
584 | + return; | ||
585 | + } | ||
586 | + | ||
587 | + object_property_set_bool(OBJECT(&s->apb_ppc1), true, "realized", &err); | ||
588 | + if (err) { | ||
589 | + error_propagate(errp, err); | ||
590 | + return; | ||
591 | + } | ||
592 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->apb_ppc1), 0); | ||
593 | + memory_region_add_subregion(&s->container, 0x4002f000, mr); | ||
594 | + | ||
595 | + dev_apb_ppc1 = DEVICE(&s->apb_ppc1); | ||
596 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_nonsec", 0, | ||
597 | + qdev_get_gpio_in_named(dev_apb_ppc1, | ||
598 | + "cfg_nonsec", 0)); | ||
599 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_ap", 0, | ||
600 | + qdev_get_gpio_in_named(dev_apb_ppc1, | ||
601 | + "cfg_ap", 0)); | ||
602 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_enable", 0, | ||
603 | + qdev_get_gpio_in_named(dev_apb_ppc1, | ||
604 | + "irq_enable", 0)); | ||
605 | + qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_clear", 0, | ||
606 | + qdev_get_gpio_in_named(dev_apb_ppc1, | ||
607 | + "irq_clear", 0)); | ||
608 | + qdev_connect_gpio_out(dev_splitter, 1, | ||
609 | + qdev_get_gpio_in_named(dev_apb_ppc1, | ||
610 | + "cfg_sec_resp", 0)); | ||
611 | + | ||
612 | + /* Using create_unimplemented_device() maps the stub into the | ||
613 | + * system address space rather than into our container, but the | ||
614 | + * overall effect to the guest is the same. | ||
615 | + */ | ||
616 | + create_unimplemented_device("SYSINFO", 0x40020000, 0x1000); | ||
617 | + | ||
618 | + create_unimplemented_device("SYSCONTROL", 0x50021000, 0x1000); | ||
619 | + create_unimplemented_device("S32KWATCHDOG", 0x5002e000, 0x1000); | ||
620 | + | ||
621 | + /* 0x40080000 .. 0x4008ffff : IoTKit second Base peripheral region */ | ||
622 | + | ||
623 | + create_unimplemented_device("NS watchdog", 0x40081000, 0x1000); | ||
624 | + create_unimplemented_device("S watchdog", 0x50081000, 0x1000); | ||
625 | + | ||
626 | + create_unimplemented_device("SRAM0 MPC", 0x50083000, 0x1000); | ||
627 | + | ||
628 | + for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) { | ||
629 | + Object *splitter = OBJECT(&s->ppc_irq_splitter[i]); | ||
630 | + | ||
631 | + object_property_set_int(splitter, 2, "num-lines", &err); | ||
632 | + if (err) { | ||
633 | + error_propagate(errp, err); | ||
634 | + return; | ||
635 | + } | 261 | + } |
636 | + object_property_set_bool(splitter, true, "realized", &err); | 262 | } else { |
637 | + if (err) { | 263 | s->st &= ~NPCM7XX_SMBST_MODE; |
638 | + error_propagate(errp, err); | 264 | s->cst &= ~NPCM7XX_SMBCST_BUSY; |
639 | + return; | 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); | ||
640 | + } | 275 | + } |
641 | + } | 276 | + } else if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
642 | + | 277 | + s->st |= NPCM7XX_SMBST_SDAST; |
643 | + for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) { | 278 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
644 | + char *ppcname = g_strdup_printf("ahb_ppcexp%d", i); | 279 | } |
645 | + | 280 | npcm7xx_smbus_update_irq(s); |
646 | + iotkit_forward_ppc(s, ppcname, i); | 281 | } |
647 | + g_free(ppcname); | 282 | @@ -XXX,XX +XXX,XX @@ static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s) |
648 | + } | 283 | |
649 | + | 284 | switch (s->status) { |
650 | + for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) { | 285 | case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE: |
651 | + char *ppcname = g_strdup_printf("apb_ppcexp%d", i); | 286 | - npcm7xx_smbus_execute_stop(s); |
652 | + | 287 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
653 | + iotkit_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC); | 288 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) <= 1) { |
654 | + g_free(ppcname); | 289 | + npcm7xx_smbus_execute_stop(s); |
655 | + } | 290 | + } |
656 | + | 291 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) == 0) { |
657 | + for (i = NUM_EXTERNAL_PPCS; i < NUM_PPCS; i++) { | 292 | + qemu_log_mask(LOG_GUEST_ERROR, |
658 | + /* Wire up IRQ splitter for internal PPCs */ | 293 | + "%s: read to SDA with an empty rx-fifo buffer, " |
659 | + DeviceState *devs = DEVICE(&s->ppc_irq_splitter[i]); | 294 | + "result undefined: %u\n", |
660 | + char *gpioname = g_strdup_printf("apb_ppc%d_irq_status", | 295 | + DEVICE(s)->canonical_path, s->sda); |
661 | + i - NUM_EXTERNAL_PPCS); | 296 | + break; |
662 | + TZPPC *ppc = (i == NUM_EXTERNAL_PPCS) ? &s->apb_ppc0 : &s->apb_ppc1; | 297 | + } |
663 | + | 298 | + npcm7xx_smbus_read_byte_fifo(s); |
664 | + qdev_connect_gpio_out(devs, 0, | 299 | + value = s->sda; |
665 | + qdev_get_gpio_in_named(dev_secctl, gpioname, 0)); | 300 | + } else { |
666 | + qdev_connect_gpio_out(devs, 1, | 301 | + npcm7xx_smbus_execute_stop(s); |
667 | + qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), i)); | 302 | + } |
668 | + qdev_connect_gpio_out_named(DEVICE(ppc), "irq", 0, | 303 | break; |
669 | + qdev_get_gpio_in(devs, 0)); | 304 | |
670 | + } | 305 | case NPCM7XX_SMBUS_STATUS_RECEIVING: |
671 | + | 306 | - npcm7xx_smbus_recv_byte(s); |
672 | + iotkit_forward_sec_resp_cfg(s); | 307 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
673 | + | 308 | + npcm7xx_smbus_read_byte_fifo(s); |
674 | + system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq; | 309 | + value = s->sda; |
675 | +} | 310 | + } else { |
676 | + | 311 | + npcm7xx_smbus_recv_byte(s); |
677 | +static void iotkit_idau_check(IDAUInterface *ii, uint32_t address, | 312 | + } |
678 | + int *iregion, bool *exempt, bool *ns, bool *nsc) | 313 | break; |
679 | +{ | 314 | |
680 | + /* For IoTKit systems the IDAU responses are simple logical functions | 315 | default: |
681 | + * of the address bits. The NSC attribute is guest-adjustable via the | 316 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value) |
682 | + * NSCCFG register in the security controller. | 317 | } |
683 | + */ | 318 | |
684 | + IoTKit *s = IOTKIT(ii); | 319 | if (value & NPCM7XX_SMBST_STASTR && |
685 | + int region = extract32(address, 28, 4); | 320 | - s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { |
686 | + | 321 | - npcm7xx_smbus_recv_byte(s); |
687 | + *ns = !(region & 1); | 322 | + s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { |
688 | + *nsc = (region == 1 && (s->nsccfg & 1)) || (region == 3 && (s->nsccfg & 2)); | 323 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
689 | + /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */ | 324 | + npcm7xx_smbus_recv_fifo(s); |
690 | + *exempt = (address & 0xeff00000) == 0xe0000000; | 325 | + } else { |
691 | + *iregion = region; | 326 | + npcm7xx_smbus_recv_byte(s); |
692 | +} | 327 | + } |
693 | + | 328 | } |
694 | +static const VMStateDescription iotkit_vmstate = { | 329 | |
695 | + .name = "iotkit", | 330 | npcm7xx_smbus_update_irq(s); |
696 | + .version_id = 1, | 331 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value) |
697 | + .minimum_version_id = 1, | 332 | s->st = 0; |
698 | + .fields = (VMStateField[]) { | 333 | s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY); |
699 | + VMSTATE_UINT32(nsccfg, IoTKit), | 334 | s->cst = 0; |
700 | + VMSTATE_END_OF_LIST() | 335 | + npcm7xx_smbus_clear_buffer(s); |
701 | + } | 336 | } |
702 | +}; | 337 | } |
703 | + | 338 | |
704 | +static Property iotkit_properties[] = { | 339 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value) |
705 | + DEFINE_PROP_LINK("memory", IoTKit, board_memory, TYPE_MEMORY_REGION, | 340 | NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL); |
706 | + MemoryRegion *), | 341 | } |
707 | + DEFINE_PROP_UINT32("EXP_NUMIRQ", IoTKit, exp_numirq, 64), | 342 | |
708 | + DEFINE_PROP_UINT32("MAINCLK", IoTKit, mainclk_frq, 0), | 343 | +static void npcm7xx_smbus_write_fif_ctl(NPCM7xxSMBusState *s, uint8_t value) |
709 | + DEFINE_PROP_END_OF_LIST() | 344 | +{ |
710 | +}; | 345 | + uint8_t new_ctl = value; |
711 | + | 346 | + |
712 | +static void iotkit_reset(DeviceState *dev) | 347 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_RDY); |
713 | +{ | 348 | + new_ctl = WRITE_ONE_CLEAR(new_ctl, value, NPCM7XX_SMBFIF_CTL_FAIR_RDY); |
714 | + IoTKit *s = IOTKIT(dev); | 349 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_BUSY); |
715 | + | 350 | + s->fif_ctl = new_ctl; |
716 | + s->nsccfg = 0; | 351 | +} |
717 | +} | 352 | + |
718 | + | 353 | +static void npcm7xx_smbus_write_fif_cts(NPCM7xxSMBusState *s, uint8_t value) |
719 | +static void iotkit_class_init(ObjectClass *klass, void *data) | 354 | +{ |
720 | +{ | 355 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_STR); |
721 | + DeviceClass *dc = DEVICE_CLASS(klass); | 356 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_RXF_TXE); |
722 | + IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass); | 357 | + s->fif_cts = KEEP_OLD_BIT(value, s->fif_cts, NPCM7XX_SMBFIF_CTS_RFTE_IE); |
723 | + | 358 | + |
724 | + dc->realize = iotkit_realize; | 359 | + if (value & NPCM7XX_SMBFIF_CTS_CLR_FIFO) { |
725 | + dc->vmsd = &iotkit_vmstate; | 360 | + npcm7xx_smbus_clear_buffer(s); |
726 | + dc->props = iotkit_properties; | 361 | + } |
727 | + dc->reset = iotkit_reset; | 362 | +} |
728 | + iic->check = iotkit_idau_check; | 363 | + |
729 | +} | 364 | +static void npcm7xx_smbus_write_txf_ctl(NPCM7xxSMBusState *s, uint8_t value) |
730 | + | 365 | +{ |
731 | +static const TypeInfo iotkit_info = { | 366 | + s->txf_ctl = value; |
732 | + .name = TYPE_IOTKIT, | 367 | +} |
733 | + .parent = TYPE_SYS_BUS_DEVICE, | 368 | + |
734 | + .instance_size = sizeof(IoTKit), | 369 | +static void npcm7xx_smbus_write_t_out(NPCM7xxSMBusState *s, uint8_t value) |
735 | + .instance_init = iotkit_init, | 370 | +{ |
736 | + .class_init = iotkit_class_init, | 371 | + uint8_t new_t_out = value; |
737 | + .interfaces = (InterfaceInfo[]) { | 372 | + |
738 | + { TYPE_IDAU_INTERFACE }, | 373 | + if ((value & NPCM7XX_SMBT_OUT_ST) || (!(s->t_out & NPCM7XX_SMBT_OUT_ST))) { |
739 | + { } | 374 | + new_t_out &= ~NPCM7XX_SMBT_OUT_ST; |
740 | + } | 375 | + } else { |
741 | +}; | 376 | + new_t_out |= NPCM7XX_SMBT_OUT_ST; |
742 | + | 377 | + } |
743 | +static void iotkit_register_types(void) | 378 | + |
744 | +{ | 379 | + s->t_out = new_t_out; |
745 | + type_register_static(&iotkit_info); | 380 | +} |
746 | +} | 381 | + |
747 | + | 382 | +static void npcm7xx_smbus_write_txf_sts(NPCM7xxSMBusState *s, uint8_t value) |
748 | +type_init(iotkit_register_types); | 383 | +{ |
749 | diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak | 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 | + } | ||
452 | } else { | ||
453 | /* Bank 0 */ | ||
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 | ||
750 | index XXXXXXX..XXXXXXX 100644 | 560 | index XXXXXXX..XXXXXXX 100644 |
751 | --- a/default-configs/arm-softmmu.mak | 561 | --- a/tests/qtest/npcm7xx_smbus-test.c |
752 | +++ b/default-configs/arm-softmmu.mak | 562 | +++ b/tests/qtest/npcm7xx_smbus-test.c |
753 | @@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y | 563 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { |
754 | CONFIG_MPS2_SCC=y | 564 | #define ADDR_EN BIT(7) |
755 | 565 | #define ADDR_A(rv) extract8((rv), 0, 6) | |
756 | CONFIG_TZ_PPC=y | 566 | |
757 | +CONFIG_IOTKIT=y | 567 | +/* FIF_CTL fields */ |
758 | CONFIG_IOTKIT_SECCTL=y | 568 | +#define FIF_CTL_FIFO_EN BIT(4) |
759 | 569 | + | |
760 | CONFIG_VERSATILE_PCI=y | 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); | ||
652 | } | ||
653 | @@ -XXX,XX +XXX,XX @@ static void send_nack(QTestState *qts, uint64_t base_addr) | ||
654 | qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
655 | } | ||
656 | |||
657 | +static void start_fifo_mode(QTestState *qts, uint64_t base_addr) | ||
658 | +{ | ||
659 | + choose_bank(qts, base_addr, 0); | ||
660 | + qtest_writeb(qts, base_addr + OFFSET_FIF_CTL, FIF_CTL_FIFO_EN); | ||
661 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTL) & | ||
662 | + FIF_CTL_FIFO_EN); | ||
663 | + choose_bank(qts, base_addr, 1); | ||
664 | + qtest_writeb(qts, base_addr + OFFSET_FIF_CTS, | ||
665 | + FIF_CTS_CLR_FIFO | FIF_CTS_RFTE_IE); | ||
666 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_FIF_CTS), ==, | ||
667 | + FIF_CTS_RFTE_IE); | ||
668 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_TXF_STS), ==, 0); | ||
669 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_RXF_STS), ==, 0); | ||
670 | +} | ||
671 | + | ||
672 | +static void start_recv_fifo(QTestState *qts, uint64_t base_addr, uint8_t bytes) | ||
673 | +{ | ||
674 | + choose_bank(qts, base_addr, 1); | ||
675 | + qtest_writeb(qts, base_addr + OFFSET_TXF_CTL, 0); | ||
676 | + qtest_writeb(qts, base_addr + OFFSET_RXF_CTL, | ||
677 | + RXF_CTL_THR_RXIE | RXF_CTL_LAST | bytes); | ||
678 | +} | ||
679 | + | ||
680 | /* Check the SMBus's status is set correctly when disabled. */ | ||
681 | static void test_disable_bus(gconstpointer data) | ||
682 | { | ||
683 | @@ -XXX,XX +XXX,XX @@ static void test_single_mode(gconstpointer data) | ||
684 | qtest_quit(qts); | ||
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 | ||
757 | index XXXXXXX..XXXXXXX 100644 | ||
758 | --- a/hw/i2c/trace-events | ||
759 | +++ b/hw/i2c/trace-events | ||
760 | @@ -XXX,XX +XXX,XX @@ npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byt | ||
761 | npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x" | ||
762 | npcm7xx_smbus_stop(const char *id) "%s stopping" | ||
763 | npcm7xx_smbus_nack(const char *id) "%s nacking" | ||
764 | +npcm7xx_smbus_recv_fifo(const char *id, uint8_t received, uint8_t expected) "%s recv fifo: received %u, expected %u" | ||
761 | -- | 765 | -- |
762 | 2.16.2 | 766 | 2.20.1 |
763 | 767 | ||
764 | 768 | diff view generated by jsdifflib |
1 | Instead of loading guest images to the system address space, use the | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | CPU's address space. This is important if we're trying to load the | ||
3 | file to memory or via an alias memory region that is provided by an | ||
4 | SoC object and thus not mapped into the system address space. | ||
5 | 2 | ||
3 | Also add Damien as a reviewer. | ||
4 | |||
5 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
6 | Acked-by: Damien Hedde <damien.hedde@greensocs.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20210211085318.2507-1-luc@lmichel.fr | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20180220180325.29818-4-peter.maydell@linaro.org | ||
10 | --- | 10 | --- |
11 | hw/arm/armv7m.c | 17 ++++++++++++++--- | 11 | MAINTAINERS | 11 +++++++++++ |
12 | 1 file changed, 14 insertions(+), 3 deletions(-) | 12 | 1 file changed, 11 insertions(+) |
13 | 13 | ||
14 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | 14 | diff --git a/MAINTAINERS b/MAINTAINERS |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/armv7m.c | 16 | --- a/MAINTAINERS |
17 | +++ b/hw/arm/armv7m.c | 17 | +++ b/MAINTAINERS |
18 | @@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size) | 18 | @@ -XXX,XX +XXX,XX @@ F: pc-bios/opensbi-* |
19 | uint64_t entry; | 19 | F: .gitlab-ci.d/opensbi.yml |
20 | uint64_t lowaddr; | 20 | F: .gitlab-ci.d/opensbi/ |
21 | int big_endian; | 21 | |
22 | + AddressSpace *as; | 22 | +Clock framework |
23 | + int asidx; | 23 | +M: Luc Michel <luc@lmichel.fr> |
24 | + CPUState *cs = CPU(cpu); | 24 | +R: Damien Hedde <damien.hedde@greensocs.com> |
25 | 25 | +S: Maintained | |
26 | #ifdef TARGET_WORDS_BIGENDIAN | 26 | +F: include/hw/clock.h |
27 | big_endian = 1; | 27 | +F: include/hw/qdev-clock.h |
28 | @@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size) | 28 | +F: hw/core/clock.c |
29 | exit(1); | 29 | +F: hw/core/clock-vmstate.c |
30 | } | 30 | +F: hw/core/qdev-clock.c |
31 | 31 | +F: docs/devel/clocks.rst | |
32 | + if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) { | ||
33 | + asidx = ARMASIdx_S; | ||
34 | + } else { | ||
35 | + asidx = ARMASIdx_NS; | ||
36 | + } | ||
37 | + as = cpu_get_address_space(cs, asidx); | ||
38 | + | 32 | + |
39 | if (kernel_filename) { | 33 | Usermode Emulation |
40 | - image_size = load_elf(kernel_filename, NULL, NULL, &entry, &lowaddr, | 34 | ------------------ |
41 | - NULL, big_endian, EM_ARM, 1, 0); | 35 | Overall usermode emulation |
42 | + image_size = load_elf_as(kernel_filename, NULL, NULL, &entry, &lowaddr, | ||
43 | + NULL, big_endian, EM_ARM, 1, 0, as); | ||
44 | if (image_size < 0) { | ||
45 | - image_size = load_image_targphys(kernel_filename, 0, mem_size); | ||
46 | + image_size = load_image_targphys_as(kernel_filename, 0, | ||
47 | + mem_size, as); | ||
48 | lowaddr = 0; | ||
49 | } | ||
50 | if (image_size < 0) { | ||
51 | -- | 36 | -- |
52 | 2.16.2 | 37 | 2.20.1 |
53 | 38 | ||
54 | 39 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@xilinx.com> | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Initial commit of the ZynqMP RTC device. | 3 | This is a 10/100 ethernet device that has several features. |
4 | Only the ones needed by the Linux driver have been implemented. | ||
5 | See npcm7xx_emc.c for a list of unimplemented features. | ||
4 | 6 | ||
5 | Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> | 7 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 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-2-dje@google.com | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 13 | --- |
9 | hw/timer/Makefile.objs | 1 + | 14 | include/hw/net/npcm7xx_emc.h | 286 ++++++++++++ |
10 | include/hw/timer/xlnx-zynqmp-rtc.h | 84 +++++++++++++++ | 15 | hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++ |
11 | hw/timer/xlnx-zynqmp-rtc.c | 214 +++++++++++++++++++++++++++++++++++++ | 16 | hw/net/meson.build | 1 + |
12 | 3 files changed, 299 insertions(+) | 17 | hw/net/trace-events | 17 + |
13 | create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h | 18 | 4 files changed, 1161 insertions(+) |
14 | create mode 100644 hw/timer/xlnx-zynqmp-rtc.c | 19 | create mode 100644 include/hw/net/npcm7xx_emc.h |
20 | create mode 100644 hw/net/npcm7xx_emc.c | ||
15 | 21 | ||
16 | diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs | 22 | diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h |
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/timer/Makefile.objs | ||
19 | +++ b/hw/timer/Makefile.objs | ||
20 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IMX) += imx_epit.o | ||
21 | common-obj-$(CONFIG_IMX) += imx_gpt.o | ||
22 | common-obj-$(CONFIG_LM32) += lm32_timer.o | ||
23 | common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o | ||
24 | +common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-rtc.o | ||
25 | |||
26 | obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o | ||
27 | obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o | ||
28 | diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h | ||
29 | new file mode 100644 | 23 | new file mode 100644 |
30 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
31 | --- /dev/null | 25 | --- /dev/null |
32 | +++ b/include/hw/timer/xlnx-zynqmp-rtc.h | 26 | +++ b/include/hw/net/npcm7xx_emc.h |
33 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
34 | +/* | 28 | +/* |
35 | + * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC). | 29 | + * Nuvoton NPCM7xx EMC Module |
36 | + * | 30 | + * |
37 | + * Copyright (c) 2017 Xilinx Inc. | 31 | + * Copyright 2020 Google LLC |
38 | + * | 32 | + * |
39 | + * Written-by: Alistair Francis <alistair.francis@xilinx.com> | 33 | + * This program is free software; you can redistribute it and/or modify it |
34 | + * under the terms of the GNU General Public License as published by the | ||
35 | + * Free Software Foundation; either version 2 of the License, or | ||
36 | + * (at your option) any later version. | ||
40 | + * | 37 | + * |
41 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 38 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
42 | + * of this software and associated documentation files (the "Software"), to deal | 39 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
43 | + * in the Software without restriction, including without limitation the rights | 40 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
44 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 41 | + * for more details. |
45 | + * copies of the Software, and to permit persons to whom the Software is | ||
46 | + * furnished to do so, subject to the following conditions: | ||
47 | + * | ||
48 | + * The above copyright notice and this permission notice shall be included in | ||
49 | + * all copies or substantial portions of the Software. | ||
50 | + * | ||
51 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
52 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
53 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
54 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
55 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
56 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
57 | + * THE SOFTWARE. | ||
58 | + */ | 42 | + */ |
59 | + | 43 | + |
60 | +#include "hw/register.h" | 44 | +#ifndef NPCM7XX_EMC_H |
61 | + | 45 | +#define NPCM7XX_EMC_H |
62 | +#define TYPE_XLNX_ZYNQMP_RTC "xlnx-zynmp.rtc" | 46 | + |
63 | + | 47 | +#include "hw/irq.h" |
64 | +#define XLNX_ZYNQMP_RTC(obj) \ | 48 | +#include "hw/sysbus.h" |
65 | + OBJECT_CHECK(XlnxZynqMPRTC, (obj), TYPE_XLNX_ZYNQMP_RTC) | 49 | +#include "net/net.h" |
66 | + | 50 | + |
67 | +REG32(SET_TIME_WRITE, 0x0) | 51 | +/* 32-bit register indices. */ |
68 | +REG32(SET_TIME_READ, 0x4) | 52 | +enum NPCM7xxPWMRegister { |
69 | +REG32(CALIB_WRITE, 0x8) | 53 | + /* Control registers. */ |
70 | + FIELD(CALIB_WRITE, FRACTION_EN, 20, 1) | 54 | + REG_CAMCMR, |
71 | + FIELD(CALIB_WRITE, FRACTION_DATA, 16, 4) | 55 | + REG_CAMEN, |
72 | + FIELD(CALIB_WRITE, MAX_TICK, 0, 16) | 56 | + |
73 | +REG32(CALIB_READ, 0xc) | 57 | + /* There are 16 CAMn[ML] registers. */ |
74 | + FIELD(CALIB_READ, FRACTION_EN, 20, 1) | 58 | + REG_CAMM_BASE, |
75 | + FIELD(CALIB_READ, FRACTION_DATA, 16, 4) | 59 | + REG_CAML_BASE, |
76 | + FIELD(CALIB_READ, MAX_TICK, 0, 16) | 60 | + REG_CAMML_LAST = 0x21, |
77 | +REG32(CURRENT_TIME, 0x10) | 61 | + |
78 | +REG32(CURRENT_TICK, 0x14) | 62 | + REG_TXDLSA = 0x22, |
79 | + FIELD(CURRENT_TICK, VALUE, 0, 16) | 63 | + REG_RXDLSA, |
80 | +REG32(ALARM, 0x18) | 64 | + REG_MCMDR, |
81 | +REG32(RTC_INT_STATUS, 0x20) | 65 | + REG_MIID, |
82 | + FIELD(RTC_INT_STATUS, ALARM, 1, 1) | 66 | + REG_MIIDA, |
83 | + FIELD(RTC_INT_STATUS, SECONDS, 0, 1) | 67 | + REG_FFTCR, |
84 | +REG32(RTC_INT_MASK, 0x24) | 68 | + REG_TSDR, |
85 | + FIELD(RTC_INT_MASK, ALARM, 1, 1) | 69 | + REG_RSDR, |
86 | + FIELD(RTC_INT_MASK, SECONDS, 0, 1) | 70 | + REG_DMARFC, |
87 | +REG32(RTC_INT_EN, 0x28) | 71 | + REG_MIEN, |
88 | + FIELD(RTC_INT_EN, ALARM, 1, 1) | 72 | + |
89 | + FIELD(RTC_INT_EN, SECONDS, 0, 1) | 73 | + /* Status registers. */ |
90 | +REG32(RTC_INT_DIS, 0x2c) | 74 | + REG_MISTA, |
91 | + FIELD(RTC_INT_DIS, ALARM, 1, 1) | 75 | + REG_MGSTA, |
92 | + FIELD(RTC_INT_DIS, SECONDS, 0, 1) | 76 | + REG_MPCNT, |
93 | +REG32(ADDR_ERROR, 0x30) | 77 | + REG_MRPC, |
94 | + FIELD(ADDR_ERROR, STATUS, 0, 1) | 78 | + REG_MRPCC, |
95 | +REG32(ADDR_ERROR_INT_MASK, 0x34) | 79 | + REG_MREPC, |
96 | + FIELD(ADDR_ERROR_INT_MASK, MASK, 0, 1) | 80 | + REG_DMARFS, |
97 | +REG32(ADDR_ERROR_INT_EN, 0x38) | 81 | + REG_CTXDSA, |
98 | + FIELD(ADDR_ERROR_INT_EN, MASK, 0, 1) | 82 | + REG_CTXBSA, |
99 | +REG32(ADDR_ERROR_INT_DIS, 0x3c) | 83 | + REG_CRXDSA, |
100 | + FIELD(ADDR_ERROR_INT_DIS, MASK, 0, 1) | 84 | + REG_CRXBSA, |
101 | +REG32(CONTROL, 0x40) | 85 | + |
102 | + FIELD(CONTROL, BATTERY_DISABLE, 31, 1) | 86 | + NPCM7XX_NUM_EMC_REGS, |
103 | + FIELD(CONTROL, OSC_CNTRL, 24, 4) | 87 | +}; |
104 | + FIELD(CONTROL, SLVERR_ENABLE, 0, 1) | 88 | + |
105 | +REG32(SAFETY_CHK, 0x50) | 89 | +/* REG_CAMCMR fields */ |
106 | + | 90 | +/* Enable CAM Compare */ |
107 | +#define XLNX_ZYNQMP_RTC_R_MAX (R_SAFETY_CHK + 1) | 91 | +#define REG_CAMCMR_ECMP (1 << 4) |
108 | + | 92 | +/* Complement CAM Compare */ |
109 | +typedef struct XlnxZynqMPRTC { | 93 | +#define REG_CAMCMR_CCAM (1 << 3) |
110 | + SysBusDevice parent_obj; | 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 | + | ||
111 | + MemoryRegion iomem; | 281 | + MemoryRegion iomem; |
112 | + qemu_irq irq_rtc_int; | 282 | + |
113 | + qemu_irq irq_addr_error_int; | 283 | + qemu_irq tx_irq; |
114 | + | 284 | + qemu_irq rx_irq; |
115 | + uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX]; | 285 | + |
116 | + RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX]; | 286 | + NICState *nic; |
117 | +} XlnxZynqMPRTC; | 287 | + NICConf conf; |
118 | diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c | 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 | ||
119 | new file mode 100644 | 315 | new file mode 100644 |
120 | index XXXXXXX..XXXXXXX | 316 | index XXXXXXX..XXXXXXX |
121 | --- /dev/null | 317 | --- /dev/null |
122 | +++ b/hw/timer/xlnx-zynqmp-rtc.c | 318 | +++ b/hw/net/npcm7xx_emc.c |
123 | @@ -XXX,XX +XXX,XX @@ | 319 | @@ -XXX,XX +XXX,XX @@ |
124 | +/* | 320 | +/* |
125 | + * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC). | 321 | + * Nuvoton NPCM7xx EMC Module |
126 | + * | 322 | + * |
127 | + * Copyright (c) 2017 Xilinx Inc. | 323 | + * Copyright 2020 Google LLC |
128 | + * | 324 | + * |
129 | + * Written-by: Alistair Francis <alistair.francis@xilinx.com> | 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. | ||
130 | + * | 329 | + * |
131 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 330 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
132 | + * of this software and associated documentation files (the "Software"), to deal | 331 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
133 | + * in the Software without restriction, including without limitation the rights | 332 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
134 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 333 | + * for more details. |
135 | + * copies of the Software, and to permit persons to whom the Software is | ||
136 | + * furnished to do so, subject to the following conditions: | ||
137 | + * | 334 | + * |
138 | + * The above copyright notice and this permission notice shall be included in | 335 | + * Unsupported/unimplemented features: |
139 | + * all copies or substantial portions of the Software. | 336 | + * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported |
140 | + * | 337 | + * - Only CAM0 is supported, CAM[1-15] are not |
141 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 338 | + * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes |
142 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 339 | + * - MII is not implemented, MIIDA.BUSY and MIID always return zero |
143 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 340 | + * - MCMDR.LBK is not implemented |
144 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 341 | + * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported |
145 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 342 | + * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored |
146 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 343 | + * - MGSTA.SQE is not supported |
147 | + * THE SOFTWARE. | 344 | + * - pause and control frames are not implemented |
345 | + * - MGSTA.CCNT is not supported | ||
346 | + * - MPCNT, DMARFS are not implemented | ||
148 | + */ | 347 | + */ |
149 | + | 348 | + |
150 | +#include "qemu/osdep.h" | 349 | +#include "qemu/osdep.h" |
151 | +#include "hw/sysbus.h" | 350 | + |
152 | +#include "hw/register.h" | 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" | ||
153 | +#include "qemu/bitops.h" | 361 | +#include "qemu/bitops.h" |
362 | +#include "qemu/error-report.h" | ||
154 | +#include "qemu/log.h" | 363 | +#include "qemu/log.h" |
155 | +#include "hw/timer/xlnx-zynqmp-rtc.h" | 364 | +#include "qemu/module.h" |
156 | + | 365 | +#include "qemu/units.h" |
157 | +#ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG | 366 | +#include "sysemu/dma.h" |
158 | +#define XLNX_ZYNQMP_RTC_ERR_DEBUG 0 | 367 | +#include "trace.h" |
159 | +#endif | 368 | + |
160 | + | 369 | +#define CRC_LENGTH 4 |
161 | +static void rtc_int_update_irq(XlnxZynqMPRTC *s) | 370 | + |
162 | +{ | 371 | +/* |
163 | + bool pending = s->regs[R_RTC_INT_STATUS] & ~s->regs[R_RTC_INT_MASK]; | 372 | + * The maximum size of a (layer 2) ethernet frame as defined by 802.3. |
164 | + qemu_set_irq(s->irq_rtc_int, pending); | 373 | + * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload) |
165 | +} | 374 | + * This does not include an additional 4 for the vlan field (802.1q). |
166 | + | 375 | + */ |
167 | +static void addr_error_int_update_irq(XlnxZynqMPRTC *s) | 376 | +#define MAX_ETH_FRAME_SIZE 1518 |
168 | +{ | 377 | + |
169 | + bool pending = s->regs[R_ADDR_ERROR] & ~s->regs[R_ADDR_ERROR_INT_MASK]; | 378 | +static const char *emc_reg_name(int regno) |
170 | + qemu_set_irq(s->irq_addr_error_int, pending); | 379 | +{ |
171 | +} | 380 | +#define REG(name) case REG_ ## name: return #name; |
172 | + | 381 | + switch (regno) { |
173 | +static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64) | 382 | + REG(CAMCMR) |
174 | +{ | 383 | + REG(CAMEN) |
175 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 384 | + REG(TXDLSA) |
176 | + rtc_int_update_irq(s); | 385 | + REG(RXDLSA) |
177 | +} | 386 | + REG(MCMDR) |
178 | + | 387 | + REG(MIID) |
179 | +static uint64_t rtc_int_en_prew(RegisterInfo *reg, uint64_t val64) | 388 | + REG(MIIDA) |
180 | +{ | 389 | + REG(FFTCR) |
181 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 390 | + REG(TSDR) |
182 | + | 391 | + REG(RSDR) |
183 | + s->regs[R_RTC_INT_MASK] &= (uint32_t) ~val64; | 392 | + REG(DMARFC) |
184 | + rtc_int_update_irq(s); | 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); | ||
185 | + return 0; | 531 | + return 0; |
186 | +} | 532 | +} |
187 | + | 533 | + |
188 | +static uint64_t rtc_int_dis_prew(RegisterInfo *reg, uint64_t val64) | 534 | +static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr) |
189 | +{ | 535 | +{ |
190 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 536 | + NPCM7xxEMCTxDesc le_desc; |
191 | + | 537 | + |
192 | + s->regs[R_RTC_INT_MASK] |= (uint32_t) val64; | 538 | + le_desc.flags = cpu_to_le32(desc->flags); |
193 | + rtc_int_update_irq(s); | 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 | + } | ||
194 | + return 0; | 548 | + return 0; |
195 | +} | 549 | +} |
196 | + | 550 | + |
197 | +static void addr_error_postw(RegisterInfo *reg, uint64_t val64) | 551 | +static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc) |
198 | +{ | 552 | +{ |
199 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 553 | + if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) { |
200 | + addr_error_int_update_irq(s); | 554 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%" |
201 | +} | 555 | + HWADDR_PRIx "\n", __func__, addr); |
202 | + | 556 | + return -1; |
203 | +static uint64_t addr_error_int_en_prew(RegisterInfo *reg, uint64_t val64) | 557 | + } |
204 | +{ | 558 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); |
205 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 559 | + desc->rxbsa = le32_to_cpu(desc->rxbsa); |
206 | + | 560 | + desc->reserved = le32_to_cpu(desc->reserved); |
207 | + s->regs[R_ADDR_ERROR_INT_MASK] &= (uint32_t) ~val64; | 561 | + desc->nrxdsa = le32_to_cpu(desc->nrxdsa); |
208 | + addr_error_int_update_irq(s); | ||
209 | + return 0; | 562 | + return 0; |
210 | +} | 563 | +} |
211 | + | 564 | + |
212 | +static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64) | 565 | +static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr) |
213 | +{ | 566 | +{ |
214 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque); | 567 | + NPCM7xxEMCRxDesc le_desc; |
215 | + | 568 | + |
216 | + s->regs[R_ADDR_ERROR_INT_MASK] |= (uint32_t) val64; | 569 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); |
217 | + addr_error_int_update_irq(s); | 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 | + } | ||
218 | + return 0; | 579 | + return 0; |
219 | +} | 580 | +} |
220 | + | 581 | + |
221 | +static const RegisterAccessInfo rtc_regs_info[] = { | 582 | +static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags) |
222 | + { .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE, | 583 | +{ |
223 | + },{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ, | 584 | + trace_npcm7xx_emc_set_mista(flags); |
224 | + .ro = 0xffffffff, | 585 | + emc->regs[REG_MISTA] |= flags; |
225 | + },{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE, | 586 | + if (extract32(flags, 16, 16)) { |
226 | + },{ .name = "CALIB_READ", .addr = A_CALIB_READ, | 587 | + emc_update_mista_txintr(emc); |
227 | + .ro = 0x1fffff, | 588 | + } |
228 | + },{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME, | 589 | + if (extract32(flags, 0, 16)) { |
229 | + .ro = 0xffffffff, | 590 | + emc_update_mista_rxintr(emc); |
230 | + },{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK, | 591 | + } |
231 | + .ro = 0xffff, | 592 | +} |
232 | + },{ .name = "ALARM", .addr = A_ALARM, | 593 | + |
233 | + },{ .name = "RTC_INT_STATUS", .addr = A_RTC_INT_STATUS, | 594 | +static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag) |
234 | + .w1c = 0x3, | 595 | +{ |
235 | + .post_write = rtc_int_status_postw, | 596 | + emc->tx_active = false; |
236 | + },{ .name = "RTC_INT_MASK", .addr = A_RTC_INT_MASK, | 597 | + emc_set_mista(emc, mista_flag); |
237 | + .reset = 0x3, | 598 | +} |
238 | + .ro = 0x3, | 599 | + |
239 | + },{ .name = "RTC_INT_EN", .addr = A_RTC_INT_EN, | 600 | +static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag) |
240 | + .pre_write = rtc_int_en_prew, | 601 | +{ |
241 | + },{ .name = "RTC_INT_DIS", .addr = A_RTC_INT_DIS, | 602 | + emc->rx_active = false; |
242 | + .pre_write = rtc_int_dis_prew, | 603 | + emc_set_mista(emc, mista_flag); |
243 | + },{ .name = "ADDR_ERROR", .addr = A_ADDR_ERROR, | 604 | +} |
244 | + .w1c = 0x1, | 605 | + |
245 | + .post_write = addr_error_postw, | 606 | +static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc, |
246 | + },{ .name = "ADDR_ERROR_INT_MASK", .addr = A_ADDR_ERROR_INT_MASK, | 607 | + const NPCM7xxEMCTxDesc *tx_desc, |
247 | + .reset = 0x1, | 608 | + uint32_t desc_addr) |
248 | + .ro = 0x1, | 609 | +{ |
249 | + },{ .name = "ADDR_ERROR_INT_EN", .addr = A_ADDR_ERROR_INT_EN, | 610 | + /* Update the current descriptor, if only to reset the owner flag. */ |
250 | + .pre_write = addr_error_int_en_prew, | 611 | + if (emc_write_tx_desc(tx_desc, desc_addr)) { |
251 | + },{ .name = "ADDR_ERROR_INT_DIS", .addr = A_ADDR_ERROR_INT_DIS, | 612 | + /* |
252 | + .pre_write = addr_error_int_dis_prew, | 613 | + * We just read it so this shouldn't generally happen. |
253 | + },{ .name = "CONTROL", .addr = A_CONTROL, | 614 | + * Error already reported. |
254 | + .reset = 0x1000000, | 615 | + */ |
255 | + .rsvd = 0x70fffffe, | 616 | + emc_set_mista(emc, REG_MISTA_TXBERR); |
256 | + },{ .name = "SAFETY_CHK", .addr = A_SAFETY_CHK, | 617 | + } |
257 | + } | 618 | + emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa); |
258 | +}; | 619 | +} |
259 | + | 620 | + |
260 | +static void rtc_reset(DeviceState *dev) | 621 | +static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc, |
261 | +{ | 622 | + const NPCM7xxEMCRxDesc *rx_desc, |
262 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(dev); | 623 | + uint32_t desc_addr) |
263 | + unsigned int i; | 624 | +{ |
264 | + | 625 | + /* Update the current descriptor, if only to reset the owner flag. */ |
265 | + for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) { | 626 | + if (emc_write_rx_desc(rx_desc, desc_addr)) { |
266 | + register_reset(&s->regs_info[i]); | 627 | + /* |
267 | + } | 628 | + * We just read it so this shouldn't generally happen. |
268 | + | 629 | + * Error already reported. |
269 | + rtc_int_update_irq(s); | 630 | + */ |
270 | + addr_error_int_update_irq(s); | 631 | + emc_set_mista(emc, REG_MISTA_RXBERR); |
271 | +} | 632 | + } |
272 | + | 633 | + emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa); |
273 | +static const MemoryRegionOps rtc_ops = { | 634 | +} |
274 | + .read = register_read_memory, | 635 | + |
275 | + .write = register_write_memory, | 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, | ||
276 | + .endianness = DEVICE_LITTLE_ENDIAN, | 1087 | + .endianness = DEVICE_LITTLE_ENDIAN, |
277 | + .valid = { | 1088 | + .valid = { |
278 | + .min_access_size = 4, | 1089 | + .min_access_size = 4, |
279 | + .max_access_size = 4, | 1090 | + .max_access_size = 4, |
1091 | + .unaligned = false, | ||
280 | + }, | 1092 | + }, |
281 | +}; | 1093 | +}; |
282 | + | 1094 | + |
283 | +static void rtc_init(Object *obj) | 1095 | +static void emc_cleanup(NetClientState *nc) |
284 | +{ | 1096 | +{ |
285 | + XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj); | 1097 | + /* Nothing to do yet. */ |
286 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 1098 | +} |
287 | + RegisterInfoArray *reg_array; | 1099 | + |
288 | + | 1100 | +static NetClientInfo net_npcm7xx_emc_info = { |
289 | + memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC, | 1101 | + .type = NET_CLIENT_DRIVER_NIC, |
290 | + XLNX_ZYNQMP_RTC_R_MAX * 4); | 1102 | + .size = sizeof(NICState), |
291 | + reg_array = | 1103 | + .can_receive = emc_can_receive, |
292 | + register_init_block32(DEVICE(obj), rtc_regs_info, | 1104 | + .receive = emc_receive, |
293 | + ARRAY_SIZE(rtc_regs_info), | 1105 | + .cleanup = emc_cleanup, |
294 | + s->regs_info, s->regs, | 1106 | + .link_status_changed = emc_set_link, |
295 | + &rtc_ops, | 1107 | +}; |
296 | + XLNX_ZYNQMP_RTC_ERR_DEBUG, | 1108 | + |
297 | + XLNX_ZYNQMP_RTC_R_MAX * 4); | 1109 | +static void npcm7xx_emc_realize(DeviceState *dev, Error **errp) |
298 | + memory_region_add_subregion(&s->iomem, | 1110 | +{ |
299 | + 0x0, | 1111 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); |
300 | + ®_array->mem); | 1112 | + SysBusDevice *sbd = SYS_BUS_DEVICE(emc); |
301 | + sysbus_init_mmio(sbd, &s->iomem); | 1113 | + |
302 | + sysbus_init_irq(sbd, &s->irq_rtc_int); | 1114 | + memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc, |
303 | + sysbus_init_irq(sbd, &s->irq_addr_error_int); | 1115 | + TYPE_NPCM7XX_EMC, 4 * KiB); |
304 | +} | 1116 | + sysbus_init_mmio(sbd, &emc->iomem); |
305 | + | 1117 | + sysbus_init_irq(sbd, &emc->tx_irq); |
306 | +static const VMStateDescription vmstate_rtc = { | 1118 | + sysbus_init_irq(sbd, &emc->rx_irq); |
307 | + .name = TYPE_XLNX_ZYNQMP_RTC, | 1119 | + |
308 | + .version_id = 1, | 1120 | + qemu_macaddr_default_if_unset(&emc->conf.macaddr); |
309 | + .minimum_version_id = 1, | 1121 | + emc->nic = qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf, |
1122 | + object_get_typename(OBJECT(dev)), dev->id, emc); | ||
1123 | + qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a); | ||
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, | ||
310 | + .fields = (VMStateField[]) { | 1137 | + .fields = (VMStateField[]) { |
311 | + VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX), | 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), | ||
312 | + VMSTATE_END_OF_LIST(), | 1142 | + VMSTATE_END_OF_LIST(), |
313 | + } | 1143 | + }, |
314 | +}; | 1144 | +}; |
315 | + | 1145 | + |
316 | +static void rtc_class_init(ObjectClass *klass, void *data) | 1146 | +static Property npcm7xx_emc_properties[] = { |
1147 | + DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf), | ||
1148 | + DEFINE_PROP_END_OF_LIST(), | ||
1149 | +}; | ||
1150 | + | ||
1151 | +static void npcm7xx_emc_class_init(ObjectClass *klass, void *data) | ||
317 | +{ | 1152 | +{ |
318 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1153 | + DeviceClass *dc = DEVICE_CLASS(klass); |
319 | + | 1154 | + |
320 | + dc->reset = rtc_reset; | 1155 | + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); |
321 | + dc->vmsd = &vmstate_rtc; | 1156 | + dc->desc = "NPCM7xx EMC Controller"; |
322 | +} | 1157 | + dc->realize = npcm7xx_emc_realize; |
323 | + | 1158 | + dc->unrealize = npcm7xx_emc_unrealize; |
324 | +static const TypeInfo rtc_info = { | 1159 | + dc->reset = npcm7xx_emc_reset; |
325 | + .name = TYPE_XLNX_ZYNQMP_RTC, | 1160 | + dc->vmsd = &vmstate_npcm7xx_emc; |
326 | + .parent = TYPE_SYS_BUS_DEVICE, | 1161 | + device_class_set_props(dc, npcm7xx_emc_properties); |
327 | + .instance_size = sizeof(XlnxZynqMPRTC), | 1162 | +} |
328 | + .class_init = rtc_class_init, | 1163 | + |
329 | + .instance_init = rtc_init, | 1164 | +static const TypeInfo npcm7xx_emc_info = { |
1165 | + .name = TYPE_NPCM7XX_EMC, | ||
1166 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
1167 | + .instance_size = sizeof(NPCM7xxEMCState), | ||
1168 | + .class_init = npcm7xx_emc_class_init, | ||
330 | +}; | 1169 | +}; |
331 | + | 1170 | + |
332 | +static void rtc_register_types(void) | 1171 | +static void npcm7xx_emc_register_type(void) |
333 | +{ | 1172 | +{ |
334 | + type_register_static(&rtc_info); | 1173 | + type_register_static(&npcm7xx_emc_info); |
335 | +} | 1174 | +} |
336 | + | 1175 | + |
337 | +type_init(rtc_register_types) | 1176 | +type_init(npcm7xx_emc_register_type) |
1177 | diff --git a/hw/net/meson.build b/hw/net/meson.build | ||
1178 | index XXXXXXX..XXXXXXX 100644 | ||
1179 | --- a/hw/net/meson.build | ||
1180 | +++ b/hw/net/meson.build | ||
1181 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c')) | ||
1182 | softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c')) | ||
1183 | softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c')) | ||
1184 | softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c')) | ||
1185 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c')) | ||
1186 | |||
1187 | softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c')) | ||
1188 | softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c')) | ||
1189 | diff --git a/hw/net/trace-events b/hw/net/trace-events | ||
1190 | index XXXXXXX..XXXXXXX 100644 | ||
1191 | --- a/hw/net/trace-events | ||
1192 | +++ b/hw/net/trace-events | ||
1193 | @@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x" | ||
1194 | imx_enet_receive(size_t size) "len %zu" | ||
1195 | imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d" | ||
1196 | imx_enet_receive_last(int last) "rx frame flags 0x%04x" | ||
1197 | + | ||
1198 | +# npcm7xx_emc.c | ||
1199 | +npcm7xx_emc_reset(int emc_num) "Resetting emc%d" | ||
1200 | +npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d" | ||
1201 | +npcm7xx_emc_update_rx_irq(int level) "Setting rx irq to %d" | ||
1202 | +npcm7xx_emc_set_mista(uint32_t flags) "ORing 0x%x into MISTA" | ||
1203 | +npcm7xx_emc_cpu_owned_desc(uint32_t addr) "Can't process cpu-owned descriptor @0x%x" | ||
1204 | +npcm7xx_emc_sent_packet(uint32_t len) "Sent %u byte packet" | ||
1205 | +npcm7xx_emc_tx_done(uint32_t ctxdsa) "TX done, CTXDSA=0x%x" | ||
1206 | +npcm7xx_emc_can_receive(int can_receive) "Can receive: %d" | ||
1207 | +npcm7xx_emc_packet_filtered_out(const char* fail_reason) "Packet filtered out: %s" | ||
1208 | +npcm7xx_emc_packet_dropped(uint32_t len) "%u byte packet dropped" | ||
1209 | +npcm7xx_emc_receiving_packet(uint32_t len) "Receiving %u byte packet" | ||
1210 | +npcm7xx_emc_received_packet(uint32_t len) "Received %u byte packet" | ||
1211 | +npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x" | ||
1212 | +npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]" | ||
1213 | +npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x" | ||
338 | -- | 1214 | -- |
339 | 2.16.2 | 1215 | 2.20.1 |
340 | 1216 | ||
341 | 1217 | diff view generated by jsdifflib |
1 | Add a model of the TrustZone peripheral protection controller (PPC), | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | which is used to gate transactions to non-TZ-aware peripherals so | ||
3 | that secure software can configure them to not be accessible to | ||
4 | non-secure software. | ||
5 | 2 | ||
3 | This is a 10/100 ethernet device that has several features. | ||
4 | Only the ones needed by the Linux driver have been implemented. | ||
5 | See npcm7xx_emc.c for a list of unimplemented features. | ||
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 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180220180325.29818-15-peter.maydell@linaro.org | ||
9 | --- | 13 | --- |
10 | hw/misc/Makefile.objs | 2 + | 14 | docs/system/arm/nuvoton.rst | 3 ++- |
11 | include/hw/misc/tz-ppc.h | 101 ++++++++++++++ | 15 | include/hw/arm/npcm7xx.h | 2 ++ |
12 | hw/misc/tz-ppc.c | 302 ++++++++++++++++++++++++++++++++++++++++ | 16 | hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++-- |
13 | default-configs/arm-softmmu.mak | 2 + | 17 | 3 files changed, 52 insertions(+), 3 deletions(-) |
14 | hw/misc/trace-events | 11 ++ | ||
15 | 5 files changed, 418 insertions(+) | ||
16 | create mode 100644 include/hw/misc/tz-ppc.h | ||
17 | create mode 100644 hw/misc/tz-ppc.c | ||
18 | 18 | ||
19 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 19 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/misc/Makefile.objs | 21 | --- a/docs/system/arm/nuvoton.rst |
22 | +++ b/hw/misc/Makefile.objs | 22 | +++ b/docs/system/arm/nuvoton.rst |
23 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MIPS_ITU) += mips_itu.o | 23 | @@ -XXX,XX +XXX,XX @@ Supported devices |
24 | obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o | 24 | * Analog to Digital Converter (ADC) |
25 | obj-$(CONFIG_MPS2_SCC) += mps2-scc.o | 25 | * Pulse Width Modulation (PWM) |
26 | 26 | * SMBus controller (SMBF) | |
27 | +obj-$(CONFIG_TZ_PPC) += tz-ppc.o | 27 | + * Ethernet controller (EMC) |
28 | + | 28 | |
29 | obj-$(CONFIG_PVPANIC) += pvpanic.o | 29 | Missing devices |
30 | obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o | 30 | --------------- |
31 | obj-$(CONFIG_AUX) += auxbus.o | 31 | @@ -XXX,XX +XXX,XX @@ Missing devices |
32 | diff --git a/include/hw/misc/tz-ppc.h b/include/hw/misc/tz-ppc.h | 32 | * Shared memory (SHM) |
33 | new file mode 100644 | 33 | * eSPI slave interface |
34 | index XXXXXXX..XXXXXXX | 34 | |
35 | --- /dev/null | 35 | - * Ethernet controllers (GMAC and EMC) |
36 | +++ b/include/hw/misc/tz-ppc.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 | ||
42 | --- a/include/hw/arm/npcm7xx.h | ||
43 | +++ b/include/hw/arm/npcm7xx.h | ||
37 | @@ -XXX,XX +XXX,XX @@ | 44 | @@ -XXX,XX +XXX,XX @@ |
38 | +/* | 45 | #include "hw/misc/npcm7xx_gcr.h" |
39 | + * ARM TrustZone peripheral protection controller emulation | 46 | #include "hw/misc/npcm7xx_pwm.h" |
40 | + * | 47 | #include "hw/misc/npcm7xx_rng.h" |
41 | + * Copyright (c) 2018 Linaro Limited | 48 | +#include "hw/net/npcm7xx_emc.h" |
42 | + * Written by Peter Maydell | 49 | #include "hw/nvram/npcm7xx_otp.h" |
43 | + * | 50 | #include "hw/timer/npcm7xx_timer.h" |
44 | + * This program is free software; you can redistribute it and/or modify | 51 | #include "hw/ssi/npcm7xx_fiu.h" |
45 | + * it under the terms of the GNU General Public License version 2 or | 52 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
46 | + * (at your option) any later version. | 53 | EHCISysBusState ehci; |
47 | + */ | 54 | OHCISysBusState ohci; |
48 | + | 55 | NPCM7xxFIUState fiu[2]; |
49 | +/* This is a model of the TrustZone peripheral protection controller (PPC). | 56 | + NPCM7xxEMCState emc[2]; |
50 | + * It is documented in the ARM CoreLink SIE-200 System IP for Embedded TRM | 57 | } NPCM7xxState; |
51 | + * (DDI 0571G): | 58 | |
52 | + * https://developer.arm.com/products/architecture/m-profile/docs/ddi0571/g | 59 | #define TYPE_NPCM7XX "npcm7xx" |
53 | + * | 60 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
54 | + * The PPC sits in front of peripherals and allows secure software to | 61 | index XXXXXXX..XXXXXXX 100644 |
55 | + * configure it to either pass through or reject transactions. | 62 | --- a/hw/arm/npcm7xx.c |
56 | + * Rejected transactions may be configured to either be aborted, or to | 63 | +++ b/hw/arm/npcm7xx.c |
57 | + * behave as RAZ/WI. An interrupt can be signalled for a rejected transaction. | 64 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
58 | + * | 65 | NPCM7XX_UART1_IRQ, |
59 | + * The PPC has no register interface -- it is configured purely by a | 66 | NPCM7XX_UART2_IRQ, |
60 | + * collection of input signals from other hardware in the system. Typically | 67 | NPCM7XX_UART3_IRQ, |
61 | + * they are either hardwired or exposed in an ad-hoc register interface by | 68 | + NPCM7XX_EMC1RX_IRQ = 15, |
62 | + * the SoC that uses the PPC. | 69 | + NPCM7XX_EMC1TX_IRQ, |
63 | + * | 70 | NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */ |
64 | + * This QEMU model can be used to model either the AHB5 or APB4 TZ PPC, | 71 | NPCM7XX_TIMER1_IRQ, |
65 | + * since the only difference between them is that the AHB version has a | 72 | NPCM7XX_TIMER2_IRQ, |
66 | + * "default" port which has no security checks applied. In QEMU the default | 73 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
67 | + * port can be emulated simply by wiring its downstream devices directly | 74 | NPCM7XX_SMBUS15_IRQ, |
68 | + * into the parent address space, since the PPC does not need to intercept | 75 | NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ |
69 | + * transactions there. | 76 | NPCM7XX_PWM1_IRQ, /* PWM module 1 */ |
70 | + * | 77 | + NPCM7XX_EMC2RX_IRQ = 114, |
71 | + * In the hardware, selection of which downstream port to use is done by | 78 | + NPCM7XX_EMC2TX_IRQ, |
72 | + * the user's decode logic asserting one of the hsel[] signals. In QEMU, | 79 | NPCM7XX_GPIO0_IRQ = 116, |
73 | + * we provide 16 MMIO regions, one per port, and the user maps these into | 80 | NPCM7XX_GPIO1_IRQ, |
74 | + * the desired addresses to implement the address decode. | 81 | NPCM7XX_GPIO2_IRQ, |
75 | + * | 82 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = { |
76 | + * QEMU interface: | 83 | 0xf008f000, |
77 | + * + sysbus MMIO regions 0..15: MemoryRegions defining the upstream end | 84 | }; |
78 | + * of each of the 16 ports of the PPC | 85 | |
79 | + * + Property "port[0..15]": MemoryRegion defining the downstream device(s) | 86 | +/* Register base address for each EMC Module */ |
80 | + * for each of the 16 ports of the PPC | 87 | +static const hwaddr npcm7xx_emc_addr[] = { |
81 | + * + Named GPIO inputs "cfg_nonsec[0..15]": set to 1 if the port should be | 88 | + 0xf0825000, |
82 | + * accessible to NonSecure transactions | 89 | + 0xf0826000, |
83 | + * + Named GPIO inputs "cfg_ap[0..15]": set to 1 if the port should be | ||
84 | + * accessible to non-privileged transactions | ||
85 | + * + Named GPIO input "cfg_sec_resp": set to 1 if a rejected transaction should | ||
86 | + * result in a transaction error, or 0 for the transaction to RAZ/WI | ||
87 | + * + Named GPIO input "irq_enable": set to 1 to enable interrupts | ||
88 | + * + Named GPIO input "irq_clear": set to 1 to clear a pending interrupt | ||
89 | + * + Named GPIO output "irq": set for a transaction-failed interrupt | ||
90 | + * + Property "NONSEC_MASK": if a bit is set in this mask then accesses to | ||
91 | + * the associated port do not have the TZ security check performed. (This | ||
92 | + * corresponds to the hardware allowing this to be set as a Verilog | ||
93 | + * parameter.) | ||
94 | + */ | ||
95 | + | ||
96 | +#ifndef TZ_PPC_H | ||
97 | +#define TZ_PPC_H | ||
98 | + | ||
99 | +#include "hw/sysbus.h" | ||
100 | + | ||
101 | +#define TYPE_TZ_PPC "tz-ppc" | ||
102 | +#define TZ_PPC(obj) OBJECT_CHECK(TZPPC, (obj), TYPE_TZ_PPC) | ||
103 | + | ||
104 | +#define TZ_NUM_PORTS 16 | ||
105 | + | ||
106 | +typedef struct TZPPC TZPPC; | ||
107 | + | ||
108 | +typedef struct TZPPCPort { | ||
109 | + TZPPC *ppc; | ||
110 | + MemoryRegion upstream; | ||
111 | + AddressSpace downstream_as; | ||
112 | + MemoryRegion *downstream; | ||
113 | +} TZPPCPort; | ||
114 | + | ||
115 | +struct TZPPC { | ||
116 | + /*< private >*/ | ||
117 | + SysBusDevice parent_obj; | ||
118 | + | ||
119 | + /*< public >*/ | ||
120 | + | ||
121 | + /* State: these just track the values of our input signals */ | ||
122 | + bool cfg_nonsec[TZ_NUM_PORTS]; | ||
123 | + bool cfg_ap[TZ_NUM_PORTS]; | ||
124 | + bool cfg_sec_resp; | ||
125 | + bool irq_enable; | ||
126 | + bool irq_clear; | ||
127 | + /* State: are we asserting irq ? */ | ||
128 | + bool irq_status; | ||
129 | + | ||
130 | + qemu_irq irq; | ||
131 | + | ||
132 | + /* Properties */ | ||
133 | + uint32_t nonsec_mask; | ||
134 | + | ||
135 | + TZPPCPort port[TZ_NUM_PORTS]; | ||
136 | +}; | 90 | +}; |
137 | + | 91 | + |
138 | +#endif | 92 | static const struct { |
139 | diff --git a/hw/misc/tz-ppc.c b/hw/misc/tz-ppc.c | 93 | hwaddr regs_addr; |
140 | new file mode 100644 | 94 | uint32_t unconnected_pins; |
141 | index XXXXXXX..XXXXXXX | 95 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
142 | --- /dev/null | 96 | for (i = 0; i < ARRAY_SIZE(s->pwm); i++) { |
143 | +++ b/hw/misc/tz-ppc.c | 97 | object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM); |
144 | @@ -XXX,XX +XXX,XX @@ | 98 | } |
145 | +/* | ||
146 | + * ARM TrustZone peripheral protection controller emulation | ||
147 | + * | ||
148 | + * Copyright (c) 2018 Linaro Limited | ||
149 | + * Written by Peter Maydell | ||
150 | + * | ||
151 | + * This program is free software; you can redistribute it and/or modify | ||
152 | + * it under the terms of the GNU General Public License version 2 or | ||
153 | + * (at your option) any later version. | ||
154 | + */ | ||
155 | + | 99 | + |
156 | +#include "qemu/osdep.h" | 100 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { |
157 | +#include "qemu/log.h" | 101 | + object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC); |
158 | +#include "qapi/error.h" | ||
159 | +#include "trace.h" | ||
160 | +#include "hw/sysbus.h" | ||
161 | +#include "hw/registerfields.h" | ||
162 | +#include "hw/misc/tz-ppc.h" | ||
163 | + | ||
164 | +static void tz_ppc_update_irq(TZPPC *s) | ||
165 | +{ | ||
166 | + bool level = s->irq_status && s->irq_enable; | ||
167 | + | ||
168 | + trace_tz_ppc_update_irq(level); | ||
169 | + qemu_set_irq(s->irq, level); | ||
170 | +} | ||
171 | + | ||
172 | +static void tz_ppc_cfg_nonsec(void *opaque, int n, int level) | ||
173 | +{ | ||
174 | + TZPPC *s = TZ_PPC(opaque); | ||
175 | + | ||
176 | + assert(n < TZ_NUM_PORTS); | ||
177 | + trace_tz_ppc_cfg_nonsec(n, level); | ||
178 | + s->cfg_nonsec[n] = level; | ||
179 | +} | ||
180 | + | ||
181 | +static void tz_ppc_cfg_ap(void *opaque, int n, int level) | ||
182 | +{ | ||
183 | + TZPPC *s = TZ_PPC(opaque); | ||
184 | + | ||
185 | + assert(n < TZ_NUM_PORTS); | ||
186 | + trace_tz_ppc_cfg_ap(n, level); | ||
187 | + s->cfg_ap[n] = level; | ||
188 | +} | ||
189 | + | ||
190 | +static void tz_ppc_cfg_sec_resp(void *opaque, int n, int level) | ||
191 | +{ | ||
192 | + TZPPC *s = TZ_PPC(opaque); | ||
193 | + | ||
194 | + trace_tz_ppc_cfg_sec_resp(level); | ||
195 | + s->cfg_sec_resp = level; | ||
196 | +} | ||
197 | + | ||
198 | +static void tz_ppc_irq_enable(void *opaque, int n, int level) | ||
199 | +{ | ||
200 | + TZPPC *s = TZ_PPC(opaque); | ||
201 | + | ||
202 | + trace_tz_ppc_irq_enable(level); | ||
203 | + s->irq_enable = level; | ||
204 | + tz_ppc_update_irq(s); | ||
205 | +} | ||
206 | + | ||
207 | +static void tz_ppc_irq_clear(void *opaque, int n, int level) | ||
208 | +{ | ||
209 | + TZPPC *s = TZ_PPC(opaque); | ||
210 | + | ||
211 | + trace_tz_ppc_irq_clear(level); | ||
212 | + | ||
213 | + s->irq_clear = level; | ||
214 | + if (level) { | ||
215 | + s->irq_status = false; | ||
216 | + tz_ppc_update_irq(s); | ||
217 | + } | 102 | + } |
218 | +} | 103 | } |
219 | + | 104 | |
220 | +static bool tz_ppc_check(TZPPC *s, int n, MemTxAttrs attrs) | 105 | static void npcm7xx_realize(DeviceState *dev, Error **errp) |
221 | +{ | 106 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
222 | + /* Check whether to allow an access to port n; return true if | 107 | sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i)); |
223 | + * the check passes, and false if the transaction must be blocked. | 108 | } |
224 | + * If the latter, the caller must check cfg_sec_resp to determine | 109 | |
225 | + * whether to abort or RAZ/WI the transaction. | 110 | + /* |
226 | + * The checks are: | 111 | + * EMC Modules. Cannot fail. |
227 | + * + nonsec_mask suppresses any check of the secure attribute | 112 | + * The mapping of the device to its netdev backend works as follows: |
228 | + * + otherwise, block if cfg_nonsec is 1 and transaction is secure, | 113 | + * emc[i] = nd_table[i] |
229 | + * or if cfg_nonsec is 0 and transaction is non-secure | 114 | + * This works around the inability to specify the netdev property for the |
230 | + * + block if transaction is usermode and cfg_ap is 0 | 115 | + * emc device: it's not pluggable and thus the -device option can't be |
116 | + * used. | ||
231 | + */ | 117 | + */ |
232 | + if ((attrs.secure == s->cfg_nonsec[n] && !(s->nonsec_mask & (1 << n))) || | 118 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc)); |
233 | + (attrs.user && !s->cfg_ap[n])) { | 119 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2); |
234 | + /* Block the transaction. */ | 120 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { |
235 | + if (!s->irq_clear) { | 121 | + s->emc[i].emc_num = i; |
236 | + /* Note that holding irq_clear high suppresses interrupts */ | 122 | + SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]); |
237 | + s->irq_status = true; | 123 | + if (nd_table[i].used) { |
238 | + tz_ppc_update_irq(s); | 124 | + qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC); |
125 | + qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]); | ||
239 | + } | 126 | + } |
240 | + return false; | 127 | + /* |
241 | + } | 128 | + * The device exists regardless of whether it's connected to a QEMU |
242 | + return true; | 129 | + * netdev backend. So always instantiate it even if there is no |
243 | +} | 130 | + * backend. |
244 | + | 131 | + */ |
245 | +static MemTxResult tz_ppc_read(void *opaque, hwaddr addr, uint64_t *pdata, | 132 | + sysbus_realize(sbd, &error_abort); |
246 | + unsigned size, MemTxAttrs attrs) | 133 | + sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]); |
247 | +{ | 134 | + int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ; |
248 | + TZPPCPort *p = opaque; | 135 | + int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ; |
249 | + TZPPC *s = p->ppc; | 136 | + /* |
250 | + int n = p - s->port; | 137 | + * N.B. The values for the second argument sysbus_connect_irq are |
251 | + AddressSpace *as = &p->downstream_as; | 138 | + * chosen to match the registration order in npcm7xx_emc_realize. |
252 | + uint64_t data; | 139 | + */ |
253 | + MemTxResult res; | 140 | + sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq)); |
254 | + | 141 | + sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq)); |
255 | + if (!tz_ppc_check(s, n, attrs)) { | ||
256 | + trace_tz_ppc_read_blocked(n, addr, attrs.secure, attrs.user); | ||
257 | + if (s->cfg_sec_resp) { | ||
258 | + return MEMTX_ERROR; | ||
259 | + } else { | ||
260 | + *pdata = 0; | ||
261 | + return MEMTX_OK; | ||
262 | + } | ||
263 | + } | 142 | + } |
264 | + | 143 | + |
265 | + switch (size) { | 144 | /* |
266 | + case 1: | 145 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
267 | + data = address_space_ldub(as, addr, attrs, &res); | 146 | * specified, but this is a programming error. |
268 | + break; | 147 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
269 | + case 2: | 148 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); |
270 | + data = address_space_lduw_le(as, addr, attrs, &res); | 149 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); |
271 | + break; | 150 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); |
272 | + case 4: | 151 | - create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB); |
273 | + data = address_space_ldl_le(as, addr, attrs, &res); | 152 | - create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB); |
274 | + break; | 153 | create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB); |
275 | + case 8: | 154 | create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB); |
276 | + data = address_space_ldq_le(as, addr, attrs, &res); | 155 | create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB); |
277 | + break; | ||
278 | + default: | ||
279 | + g_assert_not_reached(); | ||
280 | + } | ||
281 | + *pdata = data; | ||
282 | + return res; | ||
283 | +} | ||
284 | + | ||
285 | +static MemTxResult tz_ppc_write(void *opaque, hwaddr addr, uint64_t val, | ||
286 | + unsigned size, MemTxAttrs attrs) | ||
287 | +{ | ||
288 | + TZPPCPort *p = opaque; | ||
289 | + TZPPC *s = p->ppc; | ||
290 | + AddressSpace *as = &p->downstream_as; | ||
291 | + int n = p - s->port; | ||
292 | + MemTxResult res; | ||
293 | + | ||
294 | + if (!tz_ppc_check(s, n, attrs)) { | ||
295 | + trace_tz_ppc_write_blocked(n, addr, attrs.secure, attrs.user); | ||
296 | + if (s->cfg_sec_resp) { | ||
297 | + return MEMTX_ERROR; | ||
298 | + } else { | ||
299 | + return MEMTX_OK; | ||
300 | + } | ||
301 | + } | ||
302 | + | ||
303 | + switch (size) { | ||
304 | + case 1: | ||
305 | + address_space_stb(as, addr, val, attrs, &res); | ||
306 | + break; | ||
307 | + case 2: | ||
308 | + address_space_stw_le(as, addr, val, attrs, &res); | ||
309 | + break; | ||
310 | + case 4: | ||
311 | + address_space_stl_le(as, addr, val, attrs, &res); | ||
312 | + break; | ||
313 | + case 8: | ||
314 | + address_space_stq_le(as, addr, val, attrs, &res); | ||
315 | + break; | ||
316 | + default: | ||
317 | + g_assert_not_reached(); | ||
318 | + } | ||
319 | + return res; | ||
320 | +} | ||
321 | + | ||
322 | +static const MemoryRegionOps tz_ppc_ops = { | ||
323 | + .read_with_attrs = tz_ppc_read, | ||
324 | + .write_with_attrs = tz_ppc_write, | ||
325 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
326 | +}; | ||
327 | + | ||
328 | +static void tz_ppc_reset(DeviceState *dev) | ||
329 | +{ | ||
330 | + TZPPC *s = TZ_PPC(dev); | ||
331 | + | ||
332 | + trace_tz_ppc_reset(); | ||
333 | + s->cfg_sec_resp = false; | ||
334 | + memset(s->cfg_nonsec, 0, sizeof(s->cfg_nonsec)); | ||
335 | + memset(s->cfg_ap, 0, sizeof(s->cfg_ap)); | ||
336 | +} | ||
337 | + | ||
338 | +static void tz_ppc_init(Object *obj) | ||
339 | +{ | ||
340 | + DeviceState *dev = DEVICE(obj); | ||
341 | + TZPPC *s = TZ_PPC(obj); | ||
342 | + | ||
343 | + qdev_init_gpio_in_named(dev, tz_ppc_cfg_nonsec, "cfg_nonsec", TZ_NUM_PORTS); | ||
344 | + qdev_init_gpio_in_named(dev, tz_ppc_cfg_ap, "cfg_ap", TZ_NUM_PORTS); | ||
345 | + qdev_init_gpio_in_named(dev, tz_ppc_cfg_sec_resp, "cfg_sec_resp", 1); | ||
346 | + qdev_init_gpio_in_named(dev, tz_ppc_irq_enable, "irq_enable", 1); | ||
347 | + qdev_init_gpio_in_named(dev, tz_ppc_irq_clear, "irq_clear", 1); | ||
348 | + qdev_init_gpio_out_named(dev, &s->irq, "irq", 1); | ||
349 | +} | ||
350 | + | ||
351 | +static void tz_ppc_realize(DeviceState *dev, Error **errp) | ||
352 | +{ | ||
353 | + Object *obj = OBJECT(dev); | ||
354 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
355 | + TZPPC *s = TZ_PPC(dev); | ||
356 | + int i; | ||
357 | + | ||
358 | + /* We can't create the upstream end of the port until realize, | ||
359 | + * as we don't know the size of the MR used as the downstream until then. | ||
360 | + */ | ||
361 | + for (i = 0; i < TZ_NUM_PORTS; i++) { | ||
362 | + TZPPCPort *port = &s->port[i]; | ||
363 | + char *name; | ||
364 | + uint64_t size; | ||
365 | + | ||
366 | + if (!port->downstream) { | ||
367 | + continue; | ||
368 | + } | ||
369 | + | ||
370 | + name = g_strdup_printf("tz-ppc-port[%d]", i); | ||
371 | + | ||
372 | + port->ppc = s; | ||
373 | + address_space_init(&port->downstream_as, port->downstream, name); | ||
374 | + | ||
375 | + size = memory_region_size(port->downstream); | ||
376 | + memory_region_init_io(&port->upstream, obj, &tz_ppc_ops, | ||
377 | + port, name, size); | ||
378 | + sysbus_init_mmio(sbd, &port->upstream); | ||
379 | + g_free(name); | ||
380 | + } | ||
381 | +} | ||
382 | + | ||
383 | +static const VMStateDescription tz_ppc_vmstate = { | ||
384 | + .name = "tz-ppc", | ||
385 | + .version_id = 1, | ||
386 | + .minimum_version_id = 1, | ||
387 | + .fields = (VMStateField[]) { | ||
388 | + VMSTATE_BOOL_ARRAY(cfg_nonsec, TZPPC, 16), | ||
389 | + VMSTATE_BOOL_ARRAY(cfg_ap, TZPPC, 16), | ||
390 | + VMSTATE_BOOL(cfg_sec_resp, TZPPC), | ||
391 | + VMSTATE_BOOL(irq_enable, TZPPC), | ||
392 | + VMSTATE_BOOL(irq_clear, TZPPC), | ||
393 | + VMSTATE_BOOL(irq_status, TZPPC), | ||
394 | + VMSTATE_END_OF_LIST() | ||
395 | + } | ||
396 | +}; | ||
397 | + | ||
398 | +#define DEFINE_PORT(N) \ | ||
399 | + DEFINE_PROP_LINK("port[" #N "]", TZPPC, port[N].downstream, \ | ||
400 | + TYPE_MEMORY_REGION, MemoryRegion *) | ||
401 | + | ||
402 | +static Property tz_ppc_properties[] = { | ||
403 | + DEFINE_PROP_UINT32("NONSEC_MASK", TZPPC, nonsec_mask, 0), | ||
404 | + DEFINE_PORT(0), | ||
405 | + DEFINE_PORT(1), | ||
406 | + DEFINE_PORT(2), | ||
407 | + DEFINE_PORT(3), | ||
408 | + DEFINE_PORT(4), | ||
409 | + DEFINE_PORT(5), | ||
410 | + DEFINE_PORT(6), | ||
411 | + DEFINE_PORT(7), | ||
412 | + DEFINE_PORT(8), | ||
413 | + DEFINE_PORT(9), | ||
414 | + DEFINE_PORT(10), | ||
415 | + DEFINE_PORT(11), | ||
416 | + DEFINE_PORT(12), | ||
417 | + DEFINE_PORT(13), | ||
418 | + DEFINE_PORT(14), | ||
419 | + DEFINE_PORT(15), | ||
420 | + DEFINE_PROP_END_OF_LIST(), | ||
421 | +}; | ||
422 | + | ||
423 | +static void tz_ppc_class_init(ObjectClass *klass, void *data) | ||
424 | +{ | ||
425 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
426 | + | ||
427 | + dc->realize = tz_ppc_realize; | ||
428 | + dc->vmsd = &tz_ppc_vmstate; | ||
429 | + dc->reset = tz_ppc_reset; | ||
430 | + dc->props = tz_ppc_properties; | ||
431 | +} | ||
432 | + | ||
433 | +static const TypeInfo tz_ppc_info = { | ||
434 | + .name = TYPE_TZ_PPC, | ||
435 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
436 | + .instance_size = sizeof(TZPPC), | ||
437 | + .instance_init = tz_ppc_init, | ||
438 | + .class_init = tz_ppc_class_init, | ||
439 | +}; | ||
440 | + | ||
441 | +static void tz_ppc_register_types(void) | ||
442 | +{ | ||
443 | + type_register_static(&tz_ppc_info); | ||
444 | +} | ||
445 | + | ||
446 | +type_init(tz_ppc_register_types); | ||
447 | diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak | ||
448 | index XXXXXXX..XXXXXXX 100644 | ||
449 | --- a/default-configs/arm-softmmu.mak | ||
450 | +++ b/default-configs/arm-softmmu.mak | ||
451 | @@ -XXX,XX +XXX,XX @@ CONFIG_CMSDK_APB_UART=y | ||
452 | CONFIG_MPS2_FPGAIO=y | ||
453 | CONFIG_MPS2_SCC=y | ||
454 | |||
455 | +CONFIG_TZ_PPC=y | ||
456 | + | ||
457 | CONFIG_VERSATILE_PCI=y | ||
458 | CONFIG_VERSATILE_I2C=y | ||
459 | |||
460 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
461 | index XXXXXXX..XXXXXXX 100644 | ||
462 | --- a/hw/misc/trace-events | ||
463 | +++ b/hw/misc/trace-events | ||
464 | @@ -XXX,XX +XXX,XX @@ mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d co | ||
465 | mos6522_set_sr_int(void) "set sr_int" | ||
466 | mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64 | ||
467 | mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x" | ||
468 | + | ||
469 | +# hw/misc/tz-ppc.c | ||
470 | +tz_ppc_reset(void) "TZ PPC: reset" | ||
471 | +tz_ppc_cfg_nonsec(int n, int level) "TZ PPC: cfg_nonsec[%d] = %d" | ||
472 | +tz_ppc_cfg_ap(int n, int level) "TZ PPC: cfg_ap[%d] = %d" | ||
473 | +tz_ppc_cfg_sec_resp(int level) "TZ PPC: cfg_sec_resp = %d" | ||
474 | +tz_ppc_irq_enable(int level) "TZ PPC: int_enable = %d" | ||
475 | +tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d" | ||
476 | +tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d" | ||
477 | +tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked" | ||
478 | +tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked" | ||
479 | -- | 156 | -- |
480 | 2.16.2 | 157 | 2.20.1 |
481 | 158 | ||
482 | 159 | diff view generated by jsdifflib |
1 | Define a new board model for the MPS2 with an AN505 FPGA image | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | containing a Cortex-M33. Since the FPGA images for TrustZone | ||
3 | cores (AN505, and the similar AN519 for Cortex-M23) have a | ||
4 | significantly different layout of devices to the non-TrustZone | ||
5 | images, we use a new source file rather than shoehorning them | ||
6 | into the existing mps2.c. | ||
7 | 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 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180220180325.29818-20-peter.maydell@linaro.org | ||
11 | --- | 9 | --- |
12 | hw/arm/Makefile.objs | 1 + | 10 | tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++ |
13 | hw/arm/mps2-tz.c | 503 +++++++++++++++++++++++++++++++++++++++++++++++++++ | 11 | tests/qtest/meson.build | 1 + |
14 | 2 files changed, 504 insertions(+) | 12 | 2 files changed, 863 insertions(+) |
15 | create mode 100644 hw/arm/mps2-tz.c | 13 | create mode 100644 tests/qtest/npcm7xx_emc-test.c |
16 | 14 | ||
17 | diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs | 15 | diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c |
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/arm/Makefile.objs | ||
20 | +++ b/hw/arm/Makefile.objs | ||
21 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o | ||
22 | obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o | ||
23 | obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o | ||
24 | obj-$(CONFIG_MPS2) += mps2.o | ||
25 | +obj-$(CONFIG_MPS2) += mps2-tz.o | ||
26 | obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o | ||
27 | obj-$(CONFIG_IOTKIT) += iotkit.o | ||
28 | diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c | ||
29 | new file mode 100644 | 16 | new file mode 100644 |
30 | index XXXXXXX..XXXXXXX | 17 | index XXXXXXX..XXXXXXX |
31 | --- /dev/null | 18 | --- /dev/null |
32 | +++ b/hw/arm/mps2-tz.c | 19 | +++ b/tests/qtest/npcm7xx_emc-test.c |
33 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ |
34 | +/* | 21 | +/* |
35 | + * ARM V2M MPS2 board emulation, trustzone aware FPGA images | 22 | + * QTests for Nuvoton NPCM7xx EMC Modules. |
36 | + * | 23 | + * |
37 | + * Copyright (c) 2017 Linaro Limited | 24 | + * Copyright 2020 Google LLC |
38 | + * Written by Peter Maydell | ||
39 | + * | 25 | + * |
40 | + * This program is free software; you can redistribute it and/or modify | 26 | + * This program is free software; you can redistribute it and/or modify it |
41 | + * it under the terms of the GNU General Public License version 2 or | 27 | + * under the terms of the GNU General Public License as published by the |
42 | + * (at your option) any later version. | 28 | + * Free Software Foundation; either version 2 of the License, or |
29 | + * (at your option) any later version. | ||
30 | + * | ||
31 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
32 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
33 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
34 | + * for more details. | ||
43 | + */ | 35 | + */ |
44 | + | 36 | + |
45 | +/* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger | 37 | +#include "qemu/osdep.h" |
46 | + * FPGA but is otherwise the same as the 2). Since the CPU itself | 38 | +#include "qemu-common.h" |
47 | + * and most of the devices are in the FPGA, the details of the board | 39 | +#include "libqos/libqos.h" |
48 | + * as seen by the guest depend significantly on the FPGA image. | 40 | +#include "qapi/qmp/qdict.h" |
49 | + * This source file covers the following FPGA images, for TrustZone cores: | 41 | +#include "qapi/qmp/qnum.h" |
50 | + * "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505 | 42 | +#include "qemu/bitops.h" |
51 | + * | 43 | +#include "qemu/iov.h" |
52 | + * Links to the TRM for the board itself and to the various Application | 44 | + |
53 | + * Notes which document the FPGA images can be found here: | 45 | +/* Name of the emc device. */ |
54 | + * https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2 | 46 | +#define TYPE_NPCM7XX_EMC "npcm7xx-emc" |
55 | + * | 47 | + |
56 | + * Board TRM: | 48 | +/* Timeout for various operations, in seconds. */ |
57 | + * http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf | 49 | +#define TIMEOUT_SECONDS 10 |
58 | + * Application Note AN505: | 50 | + |
59 | + * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html | 51 | +/* Address in memory of the descriptor. */ |
60 | + * | 52 | +#define DESC_ADDR (1 << 20) /* 1 MiB */ |
61 | + * The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide | 53 | + |
62 | + * (ARM ECM0601256) for the details of some of the device layout: | 54 | +/* Address in memory of the data packet. */ |
63 | + * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html | 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 | +} | ||
323 | + | ||
324 | +/* | ||
325 | + * Reset the EMC module. | ||
326 | + * The module must be reset before, e.g., TXDLSA,RXDLSA are changed. | ||
64 | + */ | 327 | + */ |
65 | + | 328 | +static bool emc_soft_reset(QTestState *qts, const EMCModule *mod) |
66 | +#include "qemu/osdep.h" | 329 | +{ |
67 | +#include "qapi/error.h" | 330 | + uint32_t val; |
68 | +#include "qemu/error-report.h" | 331 | + uint64_t end_time; |
69 | +#include "hw/arm/arm.h" | 332 | + |
70 | +#include "hw/arm/armv7m.h" | 333 | + emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR); |
71 | +#include "hw/or-irq.h" | 334 | + |
72 | +#include "hw/boards.h" | 335 | + /* |
73 | +#include "exec/address-spaces.h" | 336 | + * Wait for device to reset as the linux driver does. |
74 | +#include "sysemu/sysemu.h" | 337 | + * During reset the AHB reads 0 for all registers. So first wait for |
75 | +#include "hw/misc/unimp.h" | 338 | + * something that resets to non-zero, and then wait for SWR becoming 0. |
76 | +#include "hw/char/cmsdk-apb-uart.h" | ||
77 | +#include "hw/timer/cmsdk-apb-timer.h" | ||
78 | +#include "hw/misc/mps2-scc.h" | ||
79 | +#include "hw/misc/mps2-fpgaio.h" | ||
80 | +#include "hw/arm/iotkit.h" | ||
81 | +#include "hw/devices.h" | ||
82 | +#include "net/net.h" | ||
83 | +#include "hw/core/split-irq.h" | ||
84 | + | ||
85 | +typedef enum MPS2TZFPGAType { | ||
86 | + FPGA_AN505, | ||
87 | +} MPS2TZFPGAType; | ||
88 | + | ||
89 | +typedef struct { | ||
90 | + MachineClass parent; | ||
91 | + MPS2TZFPGAType fpga_type; | ||
92 | + uint32_t scc_id; | ||
93 | +} MPS2TZMachineClass; | ||
94 | + | ||
95 | +typedef struct { | ||
96 | + MachineState parent; | ||
97 | + | ||
98 | + IoTKit iotkit; | ||
99 | + MemoryRegion psram; | ||
100 | + MemoryRegion ssram1; | ||
101 | + MemoryRegion ssram1_m; | ||
102 | + MemoryRegion ssram23; | ||
103 | + MPS2SCC scc; | ||
104 | + MPS2FPGAIO fpgaio; | ||
105 | + TZPPC ppc[5]; | ||
106 | + UnimplementedDeviceState ssram_mpc[3]; | ||
107 | + UnimplementedDeviceState spi[5]; | ||
108 | + UnimplementedDeviceState i2c[4]; | ||
109 | + UnimplementedDeviceState i2s_audio; | ||
110 | + UnimplementedDeviceState gpio[5]; | ||
111 | + UnimplementedDeviceState dma[4]; | ||
112 | + UnimplementedDeviceState gfx; | ||
113 | + CMSDKAPBUART uart[5]; | ||
114 | + SplitIRQ sec_resp_splitter; | ||
115 | + qemu_or_irq uart_irq_orgate; | ||
116 | +} MPS2TZMachineState; | ||
117 | + | ||
118 | +#define TYPE_MPS2TZ_MACHINE "mps2tz" | ||
119 | +#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505") | ||
120 | + | ||
121 | +#define MPS2TZ_MACHINE(obj) \ | ||
122 | + OBJECT_CHECK(MPS2TZMachineState, obj, TYPE_MPS2TZ_MACHINE) | ||
123 | +#define MPS2TZ_MACHINE_GET_CLASS(obj) \ | ||
124 | + OBJECT_GET_CLASS(MPS2TZMachineClass, obj, TYPE_MPS2TZ_MACHINE) | ||
125 | +#define MPS2TZ_MACHINE_CLASS(klass) \ | ||
126 | + OBJECT_CLASS_CHECK(MPS2TZMachineClass, klass, TYPE_MPS2TZ_MACHINE) | ||
127 | + | ||
128 | +/* Main SYSCLK frequency in Hz */ | ||
129 | +#define SYSCLK_FRQ 20000000 | ||
130 | + | ||
131 | +/* Initialize the auxiliary RAM region @mr and map it into | ||
132 | + * the memory map at @base. | ||
133 | + */ | ||
134 | +static void make_ram(MemoryRegion *mr, const char *name, | ||
135 | + hwaddr base, hwaddr size) | ||
136 | +{ | ||
137 | + memory_region_init_ram(mr, NULL, name, size, &error_fatal); | ||
138 | + memory_region_add_subregion(get_system_memory(), base, mr); | ||
139 | +} | ||
140 | + | ||
141 | +/* Create an alias of an entire original MemoryRegion @orig | ||
142 | + * located at @base in the memory map. | ||
143 | + */ | ||
144 | +static void make_ram_alias(MemoryRegion *mr, const char *name, | ||
145 | + MemoryRegion *orig, hwaddr base) | ||
146 | +{ | ||
147 | + memory_region_init_alias(mr, NULL, name, orig, 0, | ||
148 | + memory_region_size(orig)); | ||
149 | + memory_region_add_subregion(get_system_memory(), base, mr); | ||
150 | +} | ||
151 | + | ||
152 | +static void init_sysbus_child(Object *parent, const char *childname, | ||
153 | + void *child, size_t childsize, | ||
154 | + const char *childtype) | ||
155 | +{ | ||
156 | + object_initialize(child, childsize, childtype); | ||
157 | + object_property_add_child(parent, childname, OBJECT(child), &error_abort); | ||
158 | + qdev_set_parent_bus(DEVICE(child), sysbus_get_default()); | ||
159 | + | ||
160 | +} | ||
161 | + | ||
162 | +/* Most of the devices in the AN505 FPGA image sit behind | ||
163 | + * Peripheral Protection Controllers. These data structures | ||
164 | + * define the layout of which devices sit behind which PPCs. | ||
165 | + * The devfn for each port is a function which creates, configures | ||
166 | + * and initializes the device, returning the MemoryRegion which | ||
167 | + * needs to be plugged into the downstream end of the PPC port. | ||
168 | + */ | ||
169 | +typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque, | ||
170 | + const char *name, hwaddr size); | ||
171 | + | ||
172 | +typedef struct PPCPortInfo { | ||
173 | + const char *name; | ||
174 | + MakeDevFn *devfn; | ||
175 | + void *opaque; | ||
176 | + hwaddr addr; | ||
177 | + hwaddr size; | ||
178 | +} PPCPortInfo; | ||
179 | + | ||
180 | +typedef struct PPCInfo { | ||
181 | + const char *name; | ||
182 | + PPCPortInfo ports[TZ_NUM_PORTS]; | ||
183 | +} PPCInfo; | ||
184 | + | ||
185 | +static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms, | ||
186 | + void *opaque, | ||
187 | + const char *name, hwaddr size) | ||
188 | +{ | ||
189 | + /* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE, | ||
190 | + * and return a pointer to its MemoryRegion. | ||
191 | + */ | 339 | + */ |
192 | + UnimplementedDeviceState *uds = opaque; | 340 | + end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; |
193 | + | 341 | + |
194 | + init_sysbus_child(OBJECT(mms), name, uds, | 342 | + do { |
195 | + sizeof(UnimplementedDeviceState), | 343 | + qtest_clock_step(qts, 100); |
196 | + TYPE_UNIMPLEMENTED_DEVICE); | 344 | + val = emc_read(qts, mod, REG_FFTCR); |
197 | + qdev_prop_set_string(DEVICE(uds), "name", name); | 345 | + } while (val == 0 && g_get_monotonic_time() < end_time); |
198 | + qdev_prop_set_uint64(DEVICE(uds), "size", size); | 346 | + if (val != 0) { |
199 | + object_property_set_bool(OBJECT(uds), true, "realized", &error_fatal); | 347 | + do { |
200 | + return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0); | 348 | + qtest_clock_step(qts, 100); |
201 | +} | 349 | + val = emc_read(qts, mod, REG_MCMDR); |
202 | + | 350 | + if ((val & REG_MCMDR_SWR) == 0) { |
203 | +static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque, | 351 | + /* |
204 | + const char *name, hwaddr size) | 352 | + * N.B. The CAMs have been reset here, so macaddr matching of |
205 | +{ | 353 | + * incoming packets will not work. |
206 | + CMSDKAPBUART *uart = opaque; | 354 | + */ |
207 | + int i = uart - &mms->uart[0]; | 355 | + return true; |
208 | + Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL; | 356 | + } |
209 | + int rxirqno = i * 2; | 357 | + } while (g_get_monotonic_time() < end_time); |
210 | + int txirqno = i * 2 + 1; | 358 | + } |
211 | + int combirqno = i + 10; | 359 | + |
212 | + SysBusDevice *s; | 360 | + g_message("%s: Timeout expired", __func__); |
213 | + DeviceState *iotkitdev = DEVICE(&mms->iotkit); | 361 | + return false; |
214 | + DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate); | 362 | +} |
215 | + | 363 | + |
216 | + init_sysbus_child(OBJECT(mms), name, uart, | 364 | +/* Check emc registers are reset to default value. */ |
217 | + sizeof(mms->uart[0]), TYPE_CMSDK_APB_UART); | 365 | +static void test_init(gconstpointer test_data) |
218 | + qdev_prop_set_chr(DEVICE(uart), "chardev", uartchr); | 366 | +{ |
219 | + qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ); | 367 | + const TestData *td = test_data; |
220 | + object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal); | 368 | + const EMCModule *mod = td->module; |
221 | + s = SYS_BUS_DEVICE(uart); | 369 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
222 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev, | ||
223 | + "EXP_IRQ", txirqno)); | ||
224 | + sysbus_connect_irq(s, 1, qdev_get_gpio_in_named(iotkitdev, | ||
225 | + "EXP_IRQ", rxirqno)); | ||
226 | + sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2)); | ||
227 | + sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1)); | ||
228 | + sysbus_connect_irq(s, 4, qdev_get_gpio_in_named(iotkitdev, | ||
229 | + "EXP_IRQ", combirqno)); | ||
230 | + return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0); | ||
231 | +} | ||
232 | + | ||
233 | +static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque, | ||
234 | + const char *name, hwaddr size) | ||
235 | +{ | ||
236 | + MPS2SCC *scc = opaque; | ||
237 | + DeviceState *sccdev; | ||
238 | + MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms); | ||
239 | + | ||
240 | + object_initialize(scc, sizeof(mms->scc), TYPE_MPS2_SCC); | ||
241 | + sccdev = DEVICE(scc); | ||
242 | + qdev_set_parent_bus(sccdev, sysbus_get_default()); | ||
243 | + qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2); | ||
244 | + qdev_prop_set_uint32(sccdev, "scc-aid", 0x02000008); | ||
245 | + qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id); | ||
246 | + object_property_set_bool(OBJECT(scc), true, "realized", &error_fatal); | ||
247 | + return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0); | ||
248 | +} | ||
249 | + | ||
250 | +static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque, | ||
251 | + const char *name, hwaddr size) | ||
252 | +{ | ||
253 | + MPS2FPGAIO *fpgaio = opaque; | ||
254 | + | ||
255 | + object_initialize(fpgaio, sizeof(mms->fpgaio), TYPE_MPS2_FPGAIO); | ||
256 | + qdev_set_parent_bus(DEVICE(fpgaio), sysbus_get_default()); | ||
257 | + object_property_set_bool(OBJECT(fpgaio), true, "realized", &error_fatal); | ||
258 | + return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0); | ||
259 | +} | ||
260 | + | ||
261 | +static void mps2tz_common_init(MachineState *machine) | ||
262 | +{ | ||
263 | + MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine); | ||
264 | + MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
265 | + MemoryRegion *system_memory = get_system_memory(); | ||
266 | + DeviceState *iotkitdev; | ||
267 | + DeviceState *dev_splitter; | ||
268 | + int i; | 370 | + int i; |
269 | + | 371 | + |
270 | + if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) { | 372 | +#define CHECK_REG(regno, value) \ |
271 | + error_report("This board can only be used with CPU %s", | 373 | + do { \ |
272 | + mc->default_cpu_type); | 374 | + g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \ |
273 | + exit(1); | 375 | + } while (0) |
274 | + } | 376 | + |
275 | + | 377 | + CHECK_REG(REG_CAMCMR, 0); |
276 | + init_sysbus_child(OBJECT(machine), "iotkit", &mms->iotkit, | 378 | + CHECK_REG(REG_CAMEN, 0); |
277 | + sizeof(mms->iotkit), TYPE_IOTKIT); | 379 | + CHECK_REG(REG_TXDLSA, 0xfffffffc); |
278 | + iotkitdev = DEVICE(&mms->iotkit); | 380 | + CHECK_REG(REG_RXDLSA, 0xfffffffc); |
279 | + object_property_set_link(OBJECT(&mms->iotkit), OBJECT(system_memory), | 381 | + CHECK_REG(REG_MCMDR, 0); |
280 | + "memory", &error_abort); | 382 | + CHECK_REG(REG_MIID, 0); |
281 | + qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", 92); | 383 | + CHECK_REG(REG_MIIDA, 0x00900000); |
282 | + qdev_prop_set_uint32(iotkitdev, "MAINCLK", SYSCLK_FRQ); | 384 | + CHECK_REG(REG_FFTCR, 0x0101); |
283 | + object_property_set_bool(OBJECT(&mms->iotkit), true, "realized", | 385 | + CHECK_REG(REG_DMARFC, 0x0800); |
284 | + &error_fatal); | 386 | + CHECK_REG(REG_MIEN, 0); |
285 | + | 387 | + CHECK_REG(REG_MISTA, 0); |
286 | + /* The sec_resp_cfg output from the IoTKit must be split into multiple | 388 | + CHECK_REG(REG_MGSTA, 0); |
287 | + * lines, one for each of the PPCs we create here. | 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. | ||
288 | + */ | 584 | + */ |
289 | + object_initialize(&mms->sec_resp_splitter, sizeof(mms->sec_resp_splitter), | 585 | + got_tdu = false; |
290 | + TYPE_SPLIT_IRQ); | 586 | + while (!got_tdu) { |
291 | + object_property_add_child(OBJECT(machine), "sec-resp-splitter", | 587 | + if (with_irq) { |
292 | + OBJECT(&mms->sec_resp_splitter), &error_abort); | 588 | + g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT, |
293 | + object_property_set_int(OBJECT(&mms->sec_resp_splitter), 5, | 589 | + /*is_tx=*/true)); |
294 | + "num-lines", &error_fatal); | 590 | + } else { |
295 | + object_property_set_bool(OBJECT(&mms->sec_resp_splitter), true, | 591 | + g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT, |
296 | + "realized", &error_fatal); | 592 | + REG_MISTA_TXINTR)); |
297 | + dev_splitter = DEVICE(&mms->sec_resp_splitter); | 593 | + } |
298 | + qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0, | 594 | + got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU); |
299 | + qdev_get_gpio_in(dev_splitter, 0)); | 595 | + /* If we don't have TDU yet, reset the interrupt. */ |
300 | + | 596 | + if (!got_tdu) { |
301 | + /* The IoTKit sets up much of the memory layout, including | 597 | + emc_write(qts, mod, REG_MISTA, |
302 | + * the aliases between secure and non-secure regions in the | 598 | + emc_read(qts, mod, REG_MISTA) & 0xffff0000); |
303 | + * address space. The FPGA itself contains: | 599 | + } |
304 | + * | 600 | + } |
305 | + * 0x00000000..0x003fffff SSRAM1 | 601 | + |
306 | + * 0x00400000..0x007fffff alias of SSRAM1 | 602 | + end_desc_addr = desc_addr + 2 * sizeof(desc[0]); |
307 | + * 0x28000000..0x283fffff 4MB SSRAM2 + SSRAM3 | 603 | + g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr); |
308 | + * 0x40100000..0x4fffffff AHB Master Expansion 1 interface devices | 604 | + g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==, |
309 | + * 0x80000000..0x80ffffff 16MB PSRAM | 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. | ||
310 | + */ | 644 | + */ |
311 | + | 645 | + for (size_t i = 0; i < count; ++i) { |
312 | + /* The FPGA images have an odd combination of different RAMs, | 646 | + emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc)); |
313 | + * because in hardware they are different implementations and | 647 | + } |
314 | + * connected to different buses, giving varying performance/size | 648 | + |
315 | + * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily | 649 | + /* Trigger receiving the packet. */ |
316 | + * call the 16MB our "system memory", as it's the largest lump. | 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). | ||
317 | + */ | 658 | + */ |
318 | + memory_region_allocate_system_memory(&mms->psram, | 659 | + emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP); |
319 | + NULL, "mps.ram", 0x01000000); | 660 | + emc_write(qts, mod, REG_CAMEN, 1 << 0); |
320 | + memory_region_add_subregion(system_memory, 0x80000000, &mms->psram); | 661 | + { |
321 | + | 662 | + uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR); |
322 | + /* The SSRAM memories should all be behind Memory Protection Controllers, | 663 | + mcmdr |= REG_MCMDR_RXON | mcmdr_flags; |
323 | + * but we don't implement that yet. | 664 | + emc_write(qts, mod, REG_MCMDR, mcmdr); |
324 | + */ | 665 | + } |
325 | + make_ram(&mms->ssram1, "mps.ssram1", 0x00000000, 0x00400000); | 666 | + |
326 | + make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x00400000); | 667 | + /* Prod the device to accept a packet. */ |
327 | + | 668 | + emc_write(qts, mod, REG_RSDR, 1); |
328 | + make_ram(&mms->ssram23, "mps.ssram23", 0x28000000, 0x00400000); | 669 | +} |
329 | + | 670 | + |
330 | + /* The overflow IRQs for all UARTs are ORed together. | 671 | +static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd, |
331 | + * Tx, Rx and "combined" IRQs are sent to the NVIC separately. | 672 | + bool with_irq) |
332 | + * Create the OR gate for this. | 673 | +{ |
333 | + */ | 674 | + NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS]; |
334 | + object_initialize(&mms->uart_irq_orgate, sizeof(mms->uart_irq_orgate), | 675 | + uint32_t desc_addr = DESC_ADDR; |
335 | + TYPE_OR_IRQ); | 676 | + uint32_t data_addr = DATA_ADDR; |
336 | + object_property_add_child(OBJECT(mms), "uart-irq-orgate", | 677 | + int ret; |
337 | + OBJECT(&mms->uart_irq_orgate), &error_abort); | 678 | + uint32_t expected_mask, expected_value; |
338 | + object_property_set_int(OBJECT(&mms->uart_irq_orgate), 10, "num-lines", | 679 | + NPCM7xxEMCRxDesc result_desc; |
339 | + &error_fatal); | 680 | + |
340 | + object_property_set_bool(OBJECT(&mms->uart_irq_orgate), true, | 681 | + /* Prepare test data buffer. */ |
341 | + "realized", &error_fatal); | 682 | + const char test[RX_DATA_LEN] = "TEST"; |
342 | + qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0, | 683 | + int len = htonl(sizeof(test)); |
343 | + qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 15)); | 684 | + const struct iovec iov[] = { |
344 | + | 685 | + { |
345 | + /* Most of the devices in the FPGA are behind Peripheral Protection | 686 | + .iov_base = &len, |
346 | + * Controllers. The required order for initializing things is: | 687 | + .iov_len = sizeof(len), |
347 | + * + initialize the PPC | 688 | + },{ |
348 | + * + initialize, configure and realize downstream devices | 689 | + .iov_base = (char *) test, |
349 | + * + connect downstream device MemoryRegions to the PPC | 690 | + .iov_len = sizeof(test), |
350 | + * + realize the PPC | ||
351 | + * + map the PPC's MemoryRegions to the places in the address map | ||
352 | + * where the downstream devices should appear | ||
353 | + * + wire up the PPC's control lines to the IoTKit object | ||
354 | + */ | ||
355 | + | ||
356 | + const PPCInfo ppcs[] = { { | ||
357 | + .name = "apb_ppcexp0", | ||
358 | + .ports = { | ||
359 | + { "ssram-mpc0", make_unimp_dev, &mms->ssram_mpc[0], | ||
360 | + 0x58007000, 0x1000 }, | ||
361 | + { "ssram-mpc1", make_unimp_dev, &mms->ssram_mpc[1], | ||
362 | + 0x58008000, 0x1000 }, | ||
363 | + { "ssram-mpc2", make_unimp_dev, &mms->ssram_mpc[2], | ||
364 | + 0x58009000, 0x1000 }, | ||
365 | + }, | ||
366 | + }, { | ||
367 | + .name = "apb_ppcexp1", | ||
368 | + .ports = { | ||
369 | + { "spi0", make_unimp_dev, &mms->spi[0], 0x40205000, 0x1000 }, | ||
370 | + { "spi1", make_unimp_dev, &mms->spi[1], 0x40206000, 0x1000 }, | ||
371 | + { "spi2", make_unimp_dev, &mms->spi[2], 0x40209000, 0x1000 }, | ||
372 | + { "spi3", make_unimp_dev, &mms->spi[3], 0x4020a000, 0x1000 }, | ||
373 | + { "spi4", make_unimp_dev, &mms->spi[4], 0x4020b000, 0x1000 }, | ||
374 | + { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000 }, | ||
375 | + { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000 }, | ||
376 | + { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000 }, | ||
377 | + { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000 }, | ||
378 | + { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000 }, | ||
379 | + { "i2c0", make_unimp_dev, &mms->i2c[0], 0x40207000, 0x1000 }, | ||
380 | + { "i2c1", make_unimp_dev, &mms->i2c[1], 0x40208000, 0x1000 }, | ||
381 | + { "i2c2", make_unimp_dev, &mms->i2c[2], 0x4020c000, 0x1000 }, | ||
382 | + { "i2c3", make_unimp_dev, &mms->i2c[3], 0x4020d000, 0x1000 }, | ||
383 | + }, | ||
384 | + }, { | ||
385 | + .name = "apb_ppcexp2", | ||
386 | + .ports = { | ||
387 | + { "scc", make_scc, &mms->scc, 0x40300000, 0x1000 }, | ||
388 | + { "i2s-audio", make_unimp_dev, &mms->i2s_audio, | ||
389 | + 0x40301000, 0x1000 }, | ||
390 | + { "fpgaio", make_fpgaio, &mms->fpgaio, 0x40302000, 0x1000 }, | ||
391 | + }, | ||
392 | + }, { | ||
393 | + .name = "ahb_ppcexp0", | ||
394 | + .ports = { | ||
395 | + { "gfx", make_unimp_dev, &mms->gfx, 0x41000000, 0x140000 }, | ||
396 | + { "gpio0", make_unimp_dev, &mms->gpio[0], 0x40100000, 0x1000 }, | ||
397 | + { "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 }, | ||
398 | + { "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 }, | ||
399 | + { "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 }, | ||
400 | + { "gpio4", make_unimp_dev, &mms->gpio[4], 0x40104000, 0x1000 }, | ||
401 | + }, | ||
402 | + }, { | ||
403 | + .name = "ahb_ppcexp1", | ||
404 | + .ports = { | ||
405 | + { "dma0", make_unimp_dev, &mms->dma[0], 0x40110000, 0x1000 }, | ||
406 | + { "dma1", make_unimp_dev, &mms->dma[1], 0x40111000, 0x1000 }, | ||
407 | + { "dma2", make_unimp_dev, &mms->dma[2], 0x40112000, 0x1000 }, | ||
408 | + { "dma3", make_unimp_dev, &mms->dma[3], 0x40113000, 0x1000 }, | ||
409 | + }, | ||
410 | + }, | 691 | + }, |
411 | + }; | 692 | + }; |
412 | + | 693 | + |
413 | + for (i = 0; i < ARRAY_SIZE(ppcs); i++) { | 694 | + /* |
414 | + const PPCInfo *ppcinfo = &ppcs[i]; | 695 | + * Reset the device BEFORE sending a test packet, otherwise the packet |
415 | + TZPPC *ppc = &mms->ppc[i]; | 696 | + * may get swallowed by an active device of an earlier test. |
416 | + DeviceState *ppcdev; | ||
417 | + int port; | ||
418 | + char *gpioname; | ||
419 | + | ||
420 | + init_sysbus_child(OBJECT(machine), ppcinfo->name, ppc, | ||
421 | + sizeof(TZPPC), TYPE_TZ_PPC); | ||
422 | + ppcdev = DEVICE(ppc); | ||
423 | + | ||
424 | + for (port = 0; port < TZ_NUM_PORTS; port++) { | ||
425 | + const PPCPortInfo *pinfo = &ppcinfo->ports[port]; | ||
426 | + MemoryRegion *mr; | ||
427 | + char *portname; | ||
428 | + | ||
429 | + if (!pinfo->devfn) { | ||
430 | + continue; | ||
431 | + } | ||
432 | + | ||
433 | + mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size); | ||
434 | + portname = g_strdup_printf("port[%d]", port); | ||
435 | + object_property_set_link(OBJECT(ppc), OBJECT(mr), | ||
436 | + portname, &error_fatal); | ||
437 | + g_free(portname); | ||
438 | + } | ||
439 | + | ||
440 | + object_property_set_bool(OBJECT(ppc), true, "realized", &error_fatal); | ||
441 | + | ||
442 | + for (port = 0; port < TZ_NUM_PORTS; port++) { | ||
443 | + const PPCPortInfo *pinfo = &ppcinfo->ports[port]; | ||
444 | + | ||
445 | + if (!pinfo->devfn) { | ||
446 | + continue; | ||
447 | + } | ||
448 | + sysbus_mmio_map(SYS_BUS_DEVICE(ppc), port, pinfo->addr); | ||
449 | + | ||
450 | + gpioname = g_strdup_printf("%s_nonsec", ppcinfo->name); | ||
451 | + qdev_connect_gpio_out_named(iotkitdev, gpioname, port, | ||
452 | + qdev_get_gpio_in_named(ppcdev, | ||
453 | + "cfg_nonsec", | ||
454 | + port)); | ||
455 | + g_free(gpioname); | ||
456 | + gpioname = g_strdup_printf("%s_ap", ppcinfo->name); | ||
457 | + qdev_connect_gpio_out_named(iotkitdev, gpioname, port, | ||
458 | + qdev_get_gpio_in_named(ppcdev, | ||
459 | + "cfg_ap", port)); | ||
460 | + g_free(gpioname); | ||
461 | + } | ||
462 | + | ||
463 | + gpioname = g_strdup_printf("%s_irq_enable", ppcinfo->name); | ||
464 | + qdev_connect_gpio_out_named(iotkitdev, gpioname, 0, | ||
465 | + qdev_get_gpio_in_named(ppcdev, | ||
466 | + "irq_enable", 0)); | ||
467 | + g_free(gpioname); | ||
468 | + gpioname = g_strdup_printf("%s_irq_clear", ppcinfo->name); | ||
469 | + qdev_connect_gpio_out_named(iotkitdev, gpioname, 0, | ||
470 | + qdev_get_gpio_in_named(ppcdev, | ||
471 | + "irq_clear", 0)); | ||
472 | + g_free(gpioname); | ||
473 | + gpioname = g_strdup_printf("%s_irq_status", ppcinfo->name); | ||
474 | + qdev_connect_gpio_out_named(ppcdev, "irq", 0, | ||
475 | + qdev_get_gpio_in_named(iotkitdev, | ||
476 | + gpioname, 0)); | ||
477 | + g_free(gpioname); | ||
478 | + | ||
479 | + qdev_connect_gpio_out(dev_splitter, i, | ||
480 | + qdev_get_gpio_in_named(ppcdev, | ||
481 | + "cfg_sec_resp", 0)); | ||
482 | + } | ||
483 | + | ||
484 | + /* In hardware this is a LAN9220; the LAN9118 is software compatible | ||
485 | + * except that it doesn't support the checksum-offload feature. | ||
486 | + * The ethernet controller is not behind a PPC. | ||
487 | + */ | 697 | + */ |
488 | + lan9118_init(&nd_table[0], 0x42000000, | 698 | + init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr); |
489 | + qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 16)); | 699 | + enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr, |
490 | + | 700 | + with_irq ? REG_MIEN_ENRXINTR : 0, 0); |
491 | + create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000); | 701 | + |
492 | + | 702 | + /* Send test packet to device's socket. */ |
493 | + armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000); | 703 | + ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test)); |
494 | +} | 704 | + g_assert_cmpint(ret, == , sizeof(test) + sizeof(len)); |
495 | + | 705 | + |
496 | +static void mps2tz_class_init(ObjectClass *oc, void *data) | 706 | + /* Wait for RX interrupt. */ |
497 | +{ | 707 | + if (with_irq) { |
498 | + MachineClass *mc = MACHINE_CLASS(oc); | 708 | + g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false)); |
499 | + | 709 | + } else { |
500 | + mc->init = mps2tz_common_init; | 710 | + g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD)); |
501 | + mc->max_cpus = 1; | 711 | + } |
502 | +} | 712 | + |
503 | + | 713 | + g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==, |
504 | +static void mps2tz_an505_class_init(ObjectClass *oc, void *data) | 714 | + desc_addr + sizeof(desc[0])); |
505 | +{ | 715 | + |
506 | + MachineClass *mc = MACHINE_CLASS(oc); | 716 | + expected_mask = 0xffff; |
507 | + MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc); | 717 | + expected_value = (REG_MISTA_DENI | |
508 | + | 718 | + REG_MISTA_RXGD | |
509 | + mc->desc = "ARM MPS2 with AN505 FPGA image for Cortex-M33"; | 719 | + REG_MISTA_RXINTR); |
510 | + mmc->fpga_type = FPGA_AN505; | 720 | + g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask), |
511 | + mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33"); | 721 | + ==, expected_value); |
512 | + mmc->scc_id = 0x41040000 | (505 << 4); | 722 | + |
513 | +} | 723 | + /* Read the descriptor back. */ |
514 | + | 724 | + emc_read_rx_desc(qts, desc_addr, &result_desc); |
515 | +static const TypeInfo mps2tz_info = { | 725 | + /* Descriptor should be owned by cpu now. */ |
516 | + .name = TYPE_MPS2TZ_MACHINE, | 726 | + g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0); |
517 | + .parent = TYPE_MACHINE, | 727 | + /* Test the status bits, ignoring the length field. */ |
518 | + .abstract = true, | 728 | + expected_mask = 0xffff << 16; |
519 | + .instance_size = sizeof(MPS2TZMachineState), | 729 | + expected_value = RX_DESC_STATUS_RXGD; |
520 | + .class_size = sizeof(MPS2TZMachineClass), | 730 | + if (with_irq) { |
521 | + .class_init = mps2tz_class_init, | 731 | + expected_value |= RX_DESC_STATUS_RXINTR; |
522 | +}; | 732 | + } |
523 | + | 733 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, |
524 | +static const TypeInfo mps2tz_an505_info = { | 734 | + expected_value); |
525 | + .name = TYPE_MPS2TZ_AN505_MACHINE, | 735 | + g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==, |
526 | + .parent = TYPE_MPS2TZ_MACHINE, | 736 | + RX_DATA_LEN + CRC_LENGTH); |
527 | + .class_init = mps2tz_an505_class_init, | 737 | + |
528 | +}; | 738 | + { |
529 | + | 739 | + char buffer[RX_DATA_LEN]; |
530 | +static void mps2tz_machine_init(void) | 740 | + qtest_memread(qts, data_addr, buffer, sizeof(buffer)); |
531 | +{ | 741 | + g_assert_cmpstr(buffer, == , "TEST"); |
532 | + type_register_static(&mps2tz_info); | 742 | + } |
533 | + type_register_static(&mps2tz_an505_info); | 743 | +} |
534 | +} | 744 | + |
535 | + | 745 | +static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd) |
536 | +type_init(mps2tz_machine_init); | 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) | ||
864 | + | ||
865 | +int main(int argc, char **argv) | ||
866 | +{ | ||
867 | + TestData test_data_list[ARRAY_SIZE(emc_module_list)]; | ||
868 | + | ||
869 | + g_test_init(&argc, &argv, NULL); | ||
870 | + | ||
871 | + for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) { | ||
872 | + TestData *td = &test_data_list[i]; | ||
873 | + | ||
874 | + td->module = &emc_module_list[i]; | ||
875 | + | ||
876 | + add_test(init, td); | ||
877 | + add_test(tx, td); | ||
878 | + add_test(rx, td); | ||
879 | + } | ||
880 | + | ||
881 | + return g_test_run(); | ||
882 | +} | ||
883 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
884 | index XXXXXXX..XXXXXXX 100644 | ||
885 | --- a/tests/qtest/meson.build | ||
886 | +++ b/tests/qtest/meson.build | ||
887 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
888 | |||
889 | qtests_npcm7xx = \ | ||
890 | ['npcm7xx_adc-test', | ||
891 | + 'npcm7xx_emc-test', | ||
892 | 'npcm7xx_gpio-test', | ||
893 | 'npcm7xx_pwm-test', | ||
894 | 'npcm7xx_rng-test', | ||
537 | -- | 895 | -- |
538 | 2.16.2 | 896 | 2.20.1 |
539 | 897 | ||
540 | 898 | diff view generated by jsdifflib |