1 | Last minute pullreq for arm related patches; quite large because | 1 | Another go at the v8.5-MemTag linux-user support, plus a |
---|---|---|---|
2 | there were several series that only just made it through code review | 2 | couple more npcm7xx devices. |
3 | in time. | ||
4 | 3 | ||
5 | thanks | ||
6 | -- PMM | 4 | -- PMM |
7 | 5 | ||
8 | The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99: | 6 | The following changes since commit 8ba4bca570ace1e60614a0808631a517cf5df67a: |
9 | 7 | ||
10 | Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000) | 8 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-02-15 17:13:57 +0000) |
11 | 9 | ||
12 | are available in the Git repository at: | 10 | are available in the Git repository at: |
13 | 11 | ||
14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1 | 12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210216 |
15 | 13 | ||
16 | for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb: | 14 | for you to fetch changes up to 64fd5bddf3b71d1b92b55382ab39768bd87ecfbd: |
17 | 15 | ||
18 | hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000) | 16 | tests/qtests: Add npcm7xx emc model test (2021-02-16 14:27:05 +0000) |
19 | 17 | ||
20 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
21 | target-arm queue: | 19 | target-arm queue: |
22 | * raspi: add model of cprman clock manager | 20 | * Support ARMv8.5-MemTag for linux-user |
23 | * sbsa-ref: add an SBSA generic watchdog device | 21 | * ncpm7xx: Support SMBus, EMC ethernet devices |
24 | * arm/trace: Fix hex printing | 22 | * MAINTAINERS: add section for Clock framework |
25 | * raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+ | ||
26 | * hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | ||
27 | * Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support | ||
28 | * hw/arm: fix min_cpus for xlnx-versal-virt platform | ||
29 | * hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
30 | * linux-user: Support Aarch64 BTI | ||
31 | * Armv7M systick: fix corner case bugs by rewriting to use ptimer | ||
32 | 23 | ||
33 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
34 | Dr. David Alan Gilbert (1): | 25 | Doug Evans (3): |
35 | arm/trace: Fix hex printing | 26 | hw/net: Add npcm7xx emc model |
27 | hw/arm: Add npcm7xx emc model | ||
28 | tests/qtests: Add npcm7xx emc model test | ||
36 | 29 | ||
37 | Hao Wu (1): | 30 | Hao Wu (5): |
38 | hw/timer: Adding watchdog for NPCM7XX Timer. | 31 | hw/i2c: Implement NPCM7XX SMBus Module Single Mode |
32 | hw/arm: Add I2C sensors for NPCM750 eval board | ||
33 | hw/arm: Add I2C sensors and EEPROM for GSJ machine | ||
34 | hw/i2c: Add a QTest for NPCM7XX SMBus Device | ||
35 | hw/i2c: Implement NPCM7XX SMBus Module FIFO Mode | ||
39 | 36 | ||
40 | Havard Skinnemoen (4): | 37 | Luc Michel (1): |
41 | Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause | 38 | MAINTAINERS: add myself maintainer for the clock framework |
42 | hw/misc: Add npcm7xx random number generator | ||
43 | hw/arm/npcm7xx: Add EHCI and OHCI controllers | ||
44 | hw/gpio: Add GPIO model for Nuvoton NPCM7xx | ||
45 | 39 | ||
46 | Luc Michel (14): | 40 | Richard Henderson (31): |
47 | hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro | 41 | tcg: Introduce target-specific page data for user-only |
48 | hw/core/clock: trace clock values in Hz instead of ns | 42 | linux-user: Introduce PAGE_ANON |
49 | hw/arm/raspi: fix CPRMAN base address | 43 | exec: Use uintptr_t for guest_base |
50 | hw/arm/raspi: add a skeleton implementation of the CPRMAN | 44 | exec: Use uintptr_t in cpu_ldst.h |
51 | hw/misc/bcm2835_cprman: add a PLL skeleton implementation | 45 | exec: Improve types for guest_addr_valid |
52 | hw/misc/bcm2835_cprman: implement PLLs behaviour | 46 | linux-user: Check for overflow in access_ok |
53 | hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation | 47 | linux-user: Tidy VERIFY_READ/VERIFY_WRITE |
54 | hw/misc/bcm2835_cprman: implement PLL channels behaviour | 48 | bsd-user: Tidy VERIFY_READ/VERIFY_WRITE |
55 | hw/misc/bcm2835_cprman: add a clock mux skeleton implementation | 49 | linux-user: Do not use guest_addr_valid for h2g_valid |
56 | hw/misc/bcm2835_cprman: implement clock mux behaviour | 50 | linux-user: Fix guest_addr_valid vs reserved_va |
57 | hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer | 51 | exec: Introduce cpu_untagged_addr |
58 | hw/misc/bcm2835_cprman: add sane reset values to the registers | 52 | exec: Use cpu_untagged_addr in g2h; split out g2h_untagged |
59 | hw/char/pl011: add a clock input | 53 | linux-user: Explicitly untag memory management syscalls |
60 | hw/arm/bcm2835_peripherals: connect the UART clock | 54 | linux-user: Use guest_range_valid in access_ok |
55 | exec: Rename guest_{addr,range}_valid to *_untagged | ||
56 | linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged | ||
57 | linux-user: Move lock_user et al out of line | ||
58 | linux-user: Fix types in uaccess.c | ||
59 | linux-user: Handle tags in lock_user/unlock_user | ||
60 | linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE | ||
61 | target/arm: Improve gen_top_byte_ignore | ||
62 | target/arm: Use the proper TBI settings for linux-user | ||
63 | linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG | ||
64 | linux-user/aarch64: Implement PROT_MTE | ||
65 | target/arm: Split out syndrome.h from internals.h | ||
66 | linux-user/aarch64: Pass syndrome to EXC_*_ABORT | ||
67 | linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault | ||
68 | linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error | ||
69 | target/arm: Add allocation tag storage for user mode | ||
70 | target/arm: Enable MTE for user-only | ||
71 | tests/tcg/aarch64: Add mte smoke tests | ||
61 | 72 | ||
62 | Pavel Dovgalyuk (1): | 73 | docs/system/arm/nuvoton.rst | 5 +- |
63 | hw/arm: fix min_cpus for xlnx-versal-virt platform | 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 | ||
64 | 147 | ||
65 | Peter Maydell (2): | ||
66 | hw/core/ptimer: Support ptimer being disabled by timer callback | ||
67 | hw/timer/armv7m_systick: Rewrite to use ptimers | ||
68 | |||
69 | Philippe Mathieu-Daudé (10): | ||
70 | linux-user/elfload: Avoid leaking interp_name using GLib memory API | ||
71 | hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source | ||
72 | hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type | ||
73 | hw/arm/bcm2836: Introduce BCM283XClass::core_count | ||
74 | hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs | ||
75 | hw/arm/bcm2836: Split out common realize() code | ||
76 | hw/arm/bcm2836: Introduce the BCM2835 SoC | ||
77 | hw/arm/raspi: Add the Raspberry Pi A+ machine | ||
78 | hw/arm/raspi: Add the Raspberry Pi Zero machine | ||
79 | hw/arm/raspi: Add the Raspberry Pi 3 model A+ | ||
80 | |||
81 | Richard Henderson (11): | ||
82 | linux-user/aarch64: Reset btype for signals | ||
83 | linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI | ||
84 | include/elf: Add defines related to GNU property notes for AArch64 | ||
85 | linux-user/elfload: Fix coding style in load_elf_image | ||
86 | linux-user/elfload: Adjust iteration over phdr | ||
87 | linux-user/elfload: Move PT_INTERP detection to first loop | ||
88 | linux-user/elfload: Use Error for load_elf_image | ||
89 | linux-user/elfload: Use Error for load_elf_interp | ||
90 | linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes | ||
91 | linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND | ||
92 | tests/tcg/aarch64: Add bti smoke tests | ||
93 | |||
94 | Shashi Mallela (2): | ||
95 | hw/watchdog: Implement SBSA watchdog device | ||
96 | hw/arm/sbsa-ref: add SBSA watchdog device | ||
97 | |||
98 | Thomas Huth (1): | ||
99 | hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
100 | |||
101 | Zenghui Yu (1): | ||
102 | hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | ||
103 | |||
104 | docs/system/arm/nuvoton.rst | 6 +- | ||
105 | hw/usb/hcd-ehci.h | 1 + | ||
106 | include/elf.h | 22 + | ||
107 | include/exec/cpu-all.h | 2 + | ||
108 | include/hw/arm/bcm2835_peripherals.h | 5 +- | ||
109 | include/hw/arm/bcm2836.h | 9 +- | ||
110 | include/hw/arm/npcm7xx.h | 8 + | ||
111 | include/hw/arm/raspi_platform.h | 5 +- | ||
112 | include/hw/char/pl011.h | 1 + | ||
113 | include/hw/clock.h | 5 + | ||
114 | include/hw/gpio/npcm7xx_gpio.h | 55 ++ | ||
115 | include/hw/misc/bcm2835_cprman.h | 210 ++++++ | ||
116 | include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++++++++++ | ||
117 | include/hw/misc/npcm7xx_clk.h | 2 + | ||
118 | include/hw/misc/npcm7xx_rng.h | 34 + | ||
119 | include/hw/timer/armv7m_systick.h | 3 +- | ||
120 | include/hw/timer/npcm7xx_timer.h | 48 +- | ||
121 | include/hw/watchdog/sbsa_gwdt.h | 79 +++ | ||
122 | linux-user/qemu.h | 4 + | ||
123 | linux-user/syscall_defs.h | 4 + | ||
124 | target/arm/cpu.h | 5 + | ||
125 | hw/arm/bcm2835_peripherals.c | 15 +- | ||
126 | hw/arm/bcm2836.c | 182 +++-- | ||
127 | hw/arm/highbank.c | 2 + | ||
128 | hw/arm/npcm7xx.c | 126 +++- | ||
129 | hw/arm/raspi.c | 41 ++ | ||
130 | hw/arm/sbsa-ref.c | 23 + | ||
131 | hw/arm/smmuv3.c | 1 + | ||
132 | hw/arm/xlnx-versal-virt.c | 1 + | ||
133 | hw/char/pl011.c | 45 ++ | ||
134 | hw/core/clock.c | 6 +- | ||
135 | hw/core/ptimer.c | 4 + | ||
136 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++ | ||
137 | hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++++++++ | ||
138 | hw/misc/npcm7xx_clk.c | 28 + | ||
139 | hw/misc/npcm7xx_rng.c | 180 +++++ | ||
140 | hw/timer/armv7m_systick.c | 124 ++-- | ||
141 | hw/timer/npcm7xx_timer.c | 270 ++++++-- | ||
142 | hw/usb/hcd-ehci-sysbus.c | 19 + | ||
143 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++ | ||
144 | linux-user/aarch64/signal.c | 10 +- | ||
145 | linux-user/elfload.c | 326 +++++++-- | ||
146 | linux-user/mmap.c | 16 + | ||
147 | target/arm/translate-a64.c | 6 +- | ||
148 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++ | ||
149 | tests/qtest/npcm7xx_rng-test.c | 278 ++++++++ | ||
150 | tests/qtest/npcm7xx_watchdog_timer-test.c | 319 +++++++++ | ||
151 | tests/tcg/aarch64/bti-1.c | 62 ++ | ||
152 | tests/tcg/aarch64/bti-2.c | 116 ++++ | ||
153 | tests/tcg/aarch64/bti-crt.inc.c | 51 ++ | ||
154 | MAINTAINERS | 1 + | ||
155 | hw/arm/Kconfig | 1 + | ||
156 | hw/arm/trace-events | 2 +- | ||
157 | hw/char/trace-events | 1 + | ||
158 | hw/core/trace-events | 4 +- | ||
159 | hw/gpio/meson.build | 1 + | ||
160 | hw/gpio/trace-events | 7 + | ||
161 | hw/misc/meson.build | 2 + | ||
162 | hw/misc/trace-events | 9 + | ||
163 | hw/watchdog/Kconfig | 3 + | ||
164 | hw/watchdog/meson.build | 1 + | ||
165 | tests/qtest/meson.build | 6 +- | ||
166 | tests/tcg/aarch64/Makefile.target | 10 + | ||
167 | tests/tcg/configure.sh | 4 + | ||
168 | 64 files changed, 5461 insertions(+), 279 deletions(-) | ||
169 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
170 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
171 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
172 | create mode 100644 include/hw/misc/npcm7xx_rng.h | ||
173 | create mode 100644 include/hw/watchdog/sbsa_gwdt.h | ||
174 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
175 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
176 | create mode 100644 hw/misc/npcm7xx_rng.c | ||
177 | create mode 100644 hw/watchdog/sbsa_gwdt.c | ||
178 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
179 | create mode 100644 tests/qtest/npcm7xx_rng-test.c | ||
180 | create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c | ||
181 | create mode 100644 tests/tcg/aarch64/bti-1.c | ||
182 | create mode 100644 tests/tcg/aarch64/bti-2.c | ||
183 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | ||
184 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | PLLs are composed of multiple channels. Each channel outputs one clock | 3 | This data can be allocated by page_alloc_target_data() and |
4 | signal. They are modeled as one device taking the PLL generated clock as | 4 | released by page_set_flags(start, end, prot | PAGE_RESET). |
5 | input, and outputting a new clock. | ||
6 | 5 | ||
7 | A channel shares the CM register with its parent PLL, and has its own | 6 | This data will be used to hold tag memory for AArch64 MTE. |
8 | A2W_CTRL register. A write to the CM register will trigger an update of | ||
9 | the PLL and all its channels, while a write to an A2W_CTRL channel | ||
10 | register will update the required channel only. | ||
11 | 7 | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
14 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 10 | Message-id: 20210212184902.1251044-2-richard.henderson@linaro.org |
15 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 12 | --- |
18 | include/hw/misc/bcm2835_cprman.h | 44 ++++++ | 13 | include/exec/cpu-all.h | 42 +++++++++++++++++++++++++++++++++------ |
19 | include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ | 14 | accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++ |
20 | hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- | 15 | linux-user/mmap.c | 4 +++- |
21 | 3 files changed, 337 insertions(+), 8 deletions(-) | 16 | linux-user/syscall.c | 4 ++-- |
17 | 4 files changed, 69 insertions(+), 9 deletions(-) | ||
22 | 18 | ||
23 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 19 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
24 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/misc/bcm2835_cprman.h | 21 | --- a/include/exec/cpu-all.h |
26 | +++ b/include/hw/misc/bcm2835_cprman.h | 22 | +++ b/include/exec/cpu-all.h |
27 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll { | 23 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
28 | CPRMAN_NUM_PLL | 24 | #define PAGE_EXEC 0x0004 |
29 | } CprmanPll; | 25 | #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC) |
30 | 26 | #define PAGE_VALID 0x0008 | |
31 | +typedef enum CprmanPllChannel { | 27 | -/* original state of the write flag (used when tracking self-modifying |
32 | + CPRMAN_PLLA_CHANNEL_DSI0 = 0, | 28 | - code */ |
33 | + CPRMAN_PLLA_CHANNEL_CORE, | 29 | +/* |
34 | + CPRMAN_PLLA_CHANNEL_PER, | 30 | + * Original state of the write flag (used when tracking self-modifying code) |
35 | + CPRMAN_PLLA_CHANNEL_CCP2, | 31 | + */ |
32 | #define PAGE_WRITE_ORG 0x0010 | ||
33 | -/* Invalidate the TLB entry immediately, helpful for s390x | ||
34 | - * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() */ | ||
35 | -#define PAGE_WRITE_INV 0x0040 | ||
36 | +/* | ||
37 | + * Invalidate the TLB entry immediately, helpful for s390x | ||
38 | + * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() | ||
39 | + */ | ||
40 | +#define PAGE_WRITE_INV 0x0020 | ||
41 | +/* For use with page_set_flags: page is being replaced; target_data cleared. */ | ||
42 | +#define PAGE_RESET 0x0040 | ||
36 | + | 43 | + |
37 | + CPRMAN_PLLC_CHANNEL_CORE2, | 44 | #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) |
38 | + CPRMAN_PLLC_CHANNEL_CORE1, | 45 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ |
39 | + CPRMAN_PLLC_CHANNEL_PER, | 46 | -#define PAGE_RESERVED 0x0020 |
40 | + CPRMAN_PLLC_CHANNEL_CORE0, | 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); | ||
41 | + | 55 | + |
42 | + CPRMAN_PLLD_CHANNEL_DSI0, | 56 | +/** |
43 | + CPRMAN_PLLD_CHANNEL_CORE, | 57 | + * page_alloc_target_data(address, size) |
44 | + CPRMAN_PLLD_CHANNEL_PER, | 58 | + * @address: guest virtual address |
45 | + CPRMAN_PLLD_CHANNEL_DSI1, | 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); | ||
46 | + | 70 | + |
47 | + CPRMAN_PLLH_CHANNEL_AUX, | 71 | +/** |
48 | + CPRMAN_PLLH_CHANNEL_RCAL, | 72 | + * page_get_target_data(address) |
49 | + CPRMAN_PLLH_CHANNEL_PIX, | 73 | + * @address: guest virtual address |
50 | + | 74 | + * |
51 | + CPRMAN_PLLB_CHANNEL_ARM, | 75 | + * Return any out-of-bound memory assocated with the guest page |
52 | + | 76 | + * at @address, as per page_alloc_target_data. |
53 | + CPRMAN_NUM_PLL_CHANNEL, | 77 | + */ |
54 | +} CprmanPllChannel; | 78 | +void *page_get_target_data(target_ulong address); |
55 | + | 79 | #endif |
56 | typedef struct CprmanPllState { | 80 | |
57 | /*< private >*/ | 81 | CPUArchState *cpu_copy(CPUArchState *env); |
58 | DeviceState parent_obj; | 82 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c |
59 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllState { | ||
60 | Clock *out; | ||
61 | } CprmanPllState; | ||
62 | |||
63 | +typedef struct CprmanPllChannelState { | ||
64 | + /*< private >*/ | ||
65 | + DeviceState parent_obj; | ||
66 | + | ||
67 | + /*< public >*/ | ||
68 | + CprmanPllChannel id; | ||
69 | + CprmanPll parent; | ||
70 | + | ||
71 | + uint32_t *reg_cm; | ||
72 | + uint32_t hold_mask; | ||
73 | + uint32_t load_mask; | ||
74 | + uint32_t *reg_a2w_ctrl; | ||
75 | + int fixed_divider; | ||
76 | + | ||
77 | + Clock *pll_in; | ||
78 | + Clock *out; | ||
79 | +} CprmanPllChannelState; | ||
80 | + | ||
81 | struct BCM2835CprmanState { | ||
82 | /*< private >*/ | ||
83 | SysBusDevice parent_obj; | ||
84 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
85 | MemoryRegion iomem; | ||
86 | |||
87 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
88 | + CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
89 | |||
90 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
91 | uint32_t xosc_freq; | ||
92 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
93 | index XXXXXXX..XXXXXXX 100644 | 83 | index XXXXXXX..XXXXXXX 100644 |
94 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 84 | --- a/accel/tcg/translate-all.c |
95 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 85 | +++ b/accel/tcg/translate-all.c |
96 | @@ -XXX,XX +XXX,XX @@ | 86 | @@ -XXX,XX +XXX,XX @@ typedef struct PageDesc { |
97 | #include "hw/misc/bcm2835_cprman.h" | 87 | unsigned int code_write_count; |
98 | 88 | #else | |
99 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | 89 | unsigned long flags; |
100 | +#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | 90 | + void *target_data; |
101 | 91 | #endif | |
102 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | 92 | #ifndef CONFIG_USER_ONLY |
103 | TYPE_CPRMAN_PLL) | 93 | QemuSpin lock; |
104 | +DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, | 94 | @@ -XXX,XX +XXX,XX @@ int page_get_flags(target_ulong address) |
105 | + TYPE_CPRMAN_PLL_CHANNEL) | 95 | void page_set_flags(target_ulong start, target_ulong end, int flags) |
106 | 96 | { | |
107 | /* Register map */ | 97 | target_ulong addr, len; |
108 | 98 | + bool reset_target_data; | |
109 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) | 99 | |
110 | REG32(A2W_PLLH_FRAC, 0x1260) | 100 | /* This function should never be called with addresses outside the |
111 | REG32(A2W_PLLB_FRAC, 0x12e0) | 101 | guest address space. If this assert fires, it probably indicates |
112 | 102 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) | |
113 | +/* PLL channels */ | 103 | if (flags & PAGE_WRITE) { |
114 | +REG32(A2W_PLLA_DSI0, 0x1300) | 104 | flags |= PAGE_WRITE_ORG; |
115 | + FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8) | 105 | } |
116 | + FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1) | 106 | + reset_target_data = !(flags & PAGE_VALID) || (flags & PAGE_RESET); |
117 | +REG32(A2W_PLLA_CORE, 0x1400) | 107 | + flags &= ~PAGE_RESET; |
118 | +REG32(A2W_PLLA_PER, 0x1500) | 108 | |
119 | +REG32(A2W_PLLA_CCP2, 0x1600) | 109 | for (addr = start, len = end - start; |
120 | + | 110 | len != 0; |
121 | +REG32(A2W_PLLC_CORE2, 0x1320) | 111 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) |
122 | +REG32(A2W_PLLC_CORE1, 0x1420) | 112 | p->first_tb) { |
123 | +REG32(A2W_PLLC_PER, 0x1520) | 113 | tb_invalidate_phys_page(addr, 0); |
124 | +REG32(A2W_PLLC_CORE0, 0x1620) | 114 | } |
125 | + | 115 | + if (reset_target_data && p->target_data) { |
126 | +REG32(A2W_PLLD_DSI0, 0x1340) | 116 | + g_free(p->target_data); |
127 | +REG32(A2W_PLLD_CORE, 0x1440) | 117 | + p->target_data = NULL; |
128 | +REG32(A2W_PLLD_PER, 0x1540) | 118 | + } |
129 | +REG32(A2W_PLLD_DSI1, 0x1640) | 119 | p->flags = flags; |
130 | + | 120 | } |
131 | +REG32(A2W_PLLH_AUX, 0x1360) | ||
132 | +REG32(A2W_PLLH_RCAL, 0x1460) | ||
133 | +REG32(A2W_PLLH_PIX, 0x1560) | ||
134 | +REG32(A2W_PLLH_STS, 0x1660) | ||
135 | + | ||
136 | +REG32(A2W_PLLB_ARM, 0x13e0) | ||
137 | + | ||
138 | /* misc registers */ | ||
139 | REG32(CM_LOCK, 0x114) | ||
140 | FIELD(CM_LOCK, FLOCKH, 12, 1) | ||
141 | @@ -XXX,XX +XXX,XX @@ static inline void set_pll_init_info(BCM2835CprmanState *s, | ||
142 | pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset]; | ||
143 | } | 121 | } |
144 | 122 | ||
145 | + | 123 | +void *page_get_target_data(target_ulong address) |
146 | +/* PLL channel init info */ | ||
147 | +typedef struct PLLChannelInitInfo { | ||
148 | + const char *name; | ||
149 | + CprmanPll parent; | ||
150 | + size_t cm_offset; | ||
151 | + uint32_t cm_hold_mask; | ||
152 | + uint32_t cm_load_mask; | ||
153 | + size_t a2w_ctrl_offset; | ||
154 | + unsigned int fixed_divider; | ||
155 | +} PLLChannelInitInfo; | ||
156 | + | ||
157 | +#define FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_) \ | ||
158 | + .parent = CPRMAN_ ## pll_, \ | ||
159 | + .cm_offset = R_CM_ ## pll_, \ | ||
160 | + .cm_load_mask = R_CM_ ## pll_ ## _ ## LOAD ## channel_ ## _MASK, \ | ||
161 | + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _ ## channel_ | ||
162 | + | ||
163 | +#define FILL_PLL_CHANNEL_INIT_INFO(pll_, channel_) \ | ||
164 | + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ | ||
165 | + .cm_hold_mask = R_CM_ ## pll_ ## _ ## HOLD ## channel_ ## _MASK, \ | ||
166 | + .fixed_divider = 1 | ||
167 | + | ||
168 | +#define FILL_PLL_CHANNEL_INIT_INFO_nohold(pll_, channel_) \ | ||
169 | + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ | ||
170 | + .cm_hold_mask = 0 | ||
171 | + | ||
172 | +static PLLChannelInitInfo PLL_CHANNEL_INIT_INFO[] = { | ||
173 | + [CPRMAN_PLLA_CHANNEL_DSI0] = { | ||
174 | + .name = "plla-dsi0", | ||
175 | + FILL_PLL_CHANNEL_INIT_INFO(PLLA, DSI0), | ||
176 | + }, | ||
177 | + [CPRMAN_PLLA_CHANNEL_CORE] = { | ||
178 | + .name = "plla-core", | ||
179 | + FILL_PLL_CHANNEL_INIT_INFO(PLLA, CORE), | ||
180 | + }, | ||
181 | + [CPRMAN_PLLA_CHANNEL_PER] = { | ||
182 | + .name = "plla-per", | ||
183 | + FILL_PLL_CHANNEL_INIT_INFO(PLLA, PER), | ||
184 | + }, | ||
185 | + [CPRMAN_PLLA_CHANNEL_CCP2] = { | ||
186 | + .name = "plla-ccp2", | ||
187 | + FILL_PLL_CHANNEL_INIT_INFO(PLLA, CCP2), | ||
188 | + }, | ||
189 | + | ||
190 | + [CPRMAN_PLLC_CHANNEL_CORE2] = { | ||
191 | + .name = "pllc-core2", | ||
192 | + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE2), | ||
193 | + }, | ||
194 | + [CPRMAN_PLLC_CHANNEL_CORE1] = { | ||
195 | + .name = "pllc-core1", | ||
196 | + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE1), | ||
197 | + }, | ||
198 | + [CPRMAN_PLLC_CHANNEL_PER] = { | ||
199 | + .name = "pllc-per", | ||
200 | + FILL_PLL_CHANNEL_INIT_INFO(PLLC, PER), | ||
201 | + }, | ||
202 | + [CPRMAN_PLLC_CHANNEL_CORE0] = { | ||
203 | + .name = "pllc-core0", | ||
204 | + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE0), | ||
205 | + }, | ||
206 | + | ||
207 | + [CPRMAN_PLLD_CHANNEL_DSI0] = { | ||
208 | + .name = "plld-dsi0", | ||
209 | + FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI0), | ||
210 | + }, | ||
211 | + [CPRMAN_PLLD_CHANNEL_CORE] = { | ||
212 | + .name = "plld-core", | ||
213 | + FILL_PLL_CHANNEL_INIT_INFO(PLLD, CORE), | ||
214 | + }, | ||
215 | + [CPRMAN_PLLD_CHANNEL_PER] = { | ||
216 | + .name = "plld-per", | ||
217 | + FILL_PLL_CHANNEL_INIT_INFO(PLLD, PER), | ||
218 | + }, | ||
219 | + [CPRMAN_PLLD_CHANNEL_DSI1] = { | ||
220 | + .name = "plld-dsi1", | ||
221 | + FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI1), | ||
222 | + }, | ||
223 | + | ||
224 | + [CPRMAN_PLLH_CHANNEL_AUX] = { | ||
225 | + .name = "pllh-aux", | ||
226 | + .fixed_divider = 1, | ||
227 | + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, AUX), | ||
228 | + }, | ||
229 | + [CPRMAN_PLLH_CHANNEL_RCAL] = { | ||
230 | + .name = "pllh-rcal", | ||
231 | + .fixed_divider = 10, | ||
232 | + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, RCAL), | ||
233 | + }, | ||
234 | + [CPRMAN_PLLH_CHANNEL_PIX] = { | ||
235 | + .name = "pllh-pix", | ||
236 | + .fixed_divider = 10, | ||
237 | + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, PIX), | ||
238 | + }, | ||
239 | + | ||
240 | + [CPRMAN_PLLB_CHANNEL_ARM] = { | ||
241 | + .name = "pllb-arm", | ||
242 | + FILL_PLL_CHANNEL_INIT_INFO(PLLB, ARM), | ||
243 | + }, | ||
244 | +}; | ||
245 | + | ||
246 | +#undef FILL_PLL_CHANNEL_INIT_INFO_nohold | ||
247 | +#undef FILL_PLL_CHANNEL_INIT_INFO | ||
248 | +#undef FILL_PLL_CHANNEL_INIT_INFO_common | ||
249 | + | ||
250 | +static inline void set_pll_channel_init_info(BCM2835CprmanState *s, | ||
251 | + CprmanPllChannelState *channel, | ||
252 | + CprmanPllChannel id) | ||
253 | +{ | 124 | +{ |
254 | + channel->id = id; | 125 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); |
255 | + channel->parent = PLL_CHANNEL_INIT_INFO[id].parent; | 126 | + return p ? p->target_data : NULL; |
256 | + channel->reg_cm = &s->regs[PLL_CHANNEL_INIT_INFO[id].cm_offset]; | ||
257 | + channel->hold_mask = PLL_CHANNEL_INIT_INFO[id].cm_hold_mask; | ||
258 | + channel->load_mask = PLL_CHANNEL_INIT_INFO[id].cm_load_mask; | ||
259 | + channel->reg_a2w_ctrl = &s->regs[PLL_CHANNEL_INIT_INFO[id].a2w_ctrl_offset]; | ||
260 | + channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider; | ||
261 | +} | 127 | +} |
262 | + | 128 | + |
263 | #endif | 129 | +void *page_alloc_target_data(target_ulong address, size_t size) |
264 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 130 | +{ |
265 | index XXXXXXX..XXXXXXX 100644 | 131 | + PageDesc *p = page_find(address >> TARGET_PAGE_BITS); |
266 | --- a/hw/misc/bcm2835_cprman.c | 132 | + void *ret = NULL; |
267 | +++ b/hw/misc/bcm2835_cprman.c | ||
268 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | ||
269 | }; | ||
270 | |||
271 | |||
272 | +/* PLL channel */ | ||
273 | + | 133 | + |
274 | +static void pll_channel_update(CprmanPllChannelState *channel) | 134 | + if (p->flags & PAGE_VALID) { |
275 | +{ | 135 | + ret = p->target_data; |
276 | + clock_update(channel->out, 0); | 136 | + if (!ret) { |
137 | + p->target_data = ret = g_malloc0(size); | ||
138 | + } | ||
139 | + } | ||
140 | + return ret; | ||
277 | +} | 141 | +} |
278 | + | 142 | + |
279 | +/* Update a PLL and all its channels */ | 143 | int page_check_range(target_ulong start, target_ulong len, int flags) |
280 | +static void pll_update_all_channels(BCM2835CprmanState *s, | 144 | { |
281 | + CprmanPllState *pll) | 145 | PageDesc *p; |
282 | +{ | 146 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
283 | + size_t i; | 147 | index XXXXXXX..XXXXXXX 100644 |
284 | + | 148 | --- a/linux-user/mmap.c |
285 | + pll_update(pll); | 149 | +++ b/linux-user/mmap.c |
286 | + | 150 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
287 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
288 | + CprmanPllChannelState *channel = &s->channels[i]; | ||
289 | + if (channel->parent == pll->id) { | ||
290 | + pll_channel_update(channel); | ||
291 | + } | ||
292 | + } | ||
293 | +} | ||
294 | + | ||
295 | +static void pll_channel_pll_in_update(void *opaque) | ||
296 | +{ | ||
297 | + pll_channel_update(CPRMAN_PLL_CHANNEL(opaque)); | ||
298 | +} | ||
299 | + | ||
300 | +static void pll_channel_init(Object *obj) | ||
301 | +{ | ||
302 | + CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(obj); | ||
303 | + | ||
304 | + s->pll_in = qdev_init_clock_in(DEVICE(s), "pll-in", | ||
305 | + pll_channel_pll_in_update, s); | ||
306 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
307 | +} | ||
308 | + | ||
309 | +static const VMStateDescription pll_channel_vmstate = { | ||
310 | + .name = TYPE_CPRMAN_PLL_CHANNEL, | ||
311 | + .version_id = 1, | ||
312 | + .minimum_version_id = 1, | ||
313 | + .fields = (VMStateField[]) { | ||
314 | + VMSTATE_CLOCK(pll_in, CprmanPllChannelState), | ||
315 | + VMSTATE_END_OF_LIST() | ||
316 | + } | ||
317 | +}; | ||
318 | + | ||
319 | +static void pll_channel_class_init(ObjectClass *klass, void *data) | ||
320 | +{ | ||
321 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
322 | + | ||
323 | + dc->vmsd = &pll_channel_vmstate; | ||
324 | +} | ||
325 | + | ||
326 | +static const TypeInfo cprman_pll_channel_info = { | ||
327 | + .name = TYPE_CPRMAN_PLL_CHANNEL, | ||
328 | + .parent = TYPE_DEVICE, | ||
329 | + .instance_size = sizeof(CprmanPllChannelState), | ||
330 | + .class_init = pll_channel_class_init, | ||
331 | + .instance_init = pll_channel_init, | ||
332 | +}; | ||
333 | + | ||
334 | + | ||
335 | /* CPRMAN "top level" model */ | ||
336 | |||
337 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
338 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
339 | return r; | ||
340 | } | ||
341 | |||
342 | -#define CASE_PLL_REGS(pll_) \ | ||
343 | - case R_CM_ ## pll_: \ | ||
344 | +static inline void update_pll_and_channels_from_cm(BCM2835CprmanState *s, | ||
345 | + size_t idx) | ||
346 | +{ | ||
347 | + size_t i; | ||
348 | + | ||
349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
350 | + if (PLL_INIT_INFO[i].cm_offset == idx) { | ||
351 | + pll_update_all_channels(s, &s->plls[i]); | ||
352 | + return; | ||
353 | + } | ||
354 | + } | ||
355 | +} | ||
356 | + | ||
357 | +static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) | ||
358 | +{ | ||
359 | + size_t i; | ||
360 | + | ||
361 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
362 | + if (PLL_CHANNEL_INIT_INFO[i].a2w_ctrl_offset == idx) { | ||
363 | + pll_channel_update(&s->channels[i]); | ||
364 | + return; | ||
365 | + } | ||
366 | + } | ||
367 | +} | ||
368 | + | ||
369 | +#define CASE_PLL_A2W_REGS(pll_) \ | ||
370 | case R_A2W_ ## pll_ ## _CTRL: \ | ||
371 | case R_A2W_ ## pll_ ## _ANA0: \ | ||
372 | case R_A2W_ ## pll_ ## _ANA1: \ | ||
373 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, | ||
374 | s->regs[idx] = value; | ||
375 | |||
376 | switch (idx) { | ||
377 | - CASE_PLL_REGS(PLLA) : | ||
378 | + case R_CM_PLLA ... R_CM_PLLH: | ||
379 | + case R_CM_PLLB: | ||
380 | + /* | ||
381 | + * A given CM_PLLx register is shared by both the PLL and the channels | ||
382 | + * of this PLL. | ||
383 | + */ | ||
384 | + update_pll_and_channels_from_cm(s, idx); | ||
385 | + break; | ||
386 | + | ||
387 | + CASE_PLL_A2W_REGS(PLLA) : | ||
388 | pll_update(&s->plls[CPRMAN_PLLA]); | ||
389 | break; | ||
390 | |||
391 | - CASE_PLL_REGS(PLLC) : | ||
392 | + CASE_PLL_A2W_REGS(PLLC) : | ||
393 | pll_update(&s->plls[CPRMAN_PLLC]); | ||
394 | break; | ||
395 | |||
396 | - CASE_PLL_REGS(PLLD) : | ||
397 | + CASE_PLL_A2W_REGS(PLLD) : | ||
398 | pll_update(&s->plls[CPRMAN_PLLD]); | ||
399 | break; | ||
400 | |||
401 | - CASE_PLL_REGS(PLLH) : | ||
402 | + CASE_PLL_A2W_REGS(PLLH) : | ||
403 | pll_update(&s->plls[CPRMAN_PLLH]); | ||
404 | break; | ||
405 | |||
406 | - CASE_PLL_REGS(PLLB) : | ||
407 | + CASE_PLL_A2W_REGS(PLLB) : | ||
408 | pll_update(&s->plls[CPRMAN_PLLB]); | ||
409 | break; | ||
410 | + | ||
411 | + case R_A2W_PLLA_DSI0: | ||
412 | + case R_A2W_PLLA_CORE: | ||
413 | + case R_A2W_PLLA_PER: | ||
414 | + case R_A2W_PLLA_CCP2: | ||
415 | + case R_A2W_PLLC_CORE2: | ||
416 | + case R_A2W_PLLC_CORE1: | ||
417 | + case R_A2W_PLLC_PER: | ||
418 | + case R_A2W_PLLC_CORE0: | ||
419 | + case R_A2W_PLLD_DSI0: | ||
420 | + case R_A2W_PLLD_CORE: | ||
421 | + case R_A2W_PLLD_PER: | ||
422 | + case R_A2W_PLLD_DSI1: | ||
423 | + case R_A2W_PLLH_AUX: | ||
424 | + case R_A2W_PLLH_RCAL: | ||
425 | + case R_A2W_PLLH_PIX: | ||
426 | + case R_A2W_PLLB_ARM: | ||
427 | + update_channel_from_a2w(s, idx); | ||
428 | + break; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | -#undef CASE_PLL_REGS | ||
433 | +#undef CASE_PLL_A2W_REGS | ||
434 | |||
435 | static const MemoryRegionOps cprman_ops = { | ||
436 | .read = cprman_read, | ||
437 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | ||
438 | device_cold_reset(DEVICE(&s->plls[i])); | ||
439 | } | ||
440 | |||
441 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
442 | + device_cold_reset(DEVICE(&s->channels[i])); | ||
443 | + } | ||
444 | + | ||
445 | clock_update_hz(s->xosc, s->xosc_freq); | ||
446 | } | ||
447 | |||
448 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
449 | set_pll_init_info(s, &s->plls[i], i); | ||
450 | } | ||
451 | |||
452 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
453 | + object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name, | ||
454 | + &s->channels[i], | ||
455 | + TYPE_CPRMAN_PLL_CHANNEL); | ||
456 | + set_pll_channel_init_info(s, &s->channels[i], i); | ||
457 | + } | ||
458 | + | ||
459 | s->xosc = clock_new(obj, "xosc"); | ||
460 | |||
461 | memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
462 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
463 | return; | ||
464 | } | 151 | } |
465 | } | 152 | } |
466 | + | 153 | the_end1: |
467 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | 154 | + page_flags |= PAGE_RESET; |
468 | + CprmanPllChannelState *channel = &s->channels[i]; | 155 | page_set_flags(start, start + len, page_flags); |
469 | + CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent; | 156 | the_end: |
470 | + Clock *parent_clk = s->plls[parent].out; | 157 | trace_target_mmap_complete(start); |
471 | + | 158 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
472 | + clock_set_source(channel->pll_in, parent_clk); | 159 | new_addr = h2g(host_addr); |
473 | + | 160 | prot = page_get_flags(old_addr); |
474 | + if (!qdev_realize(DEVICE(channel), NULL, errp)) { | 161 | page_set_flags(old_addr, old_addr + old_size, 0); |
475 | + return; | 162 | - page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID); |
476 | + } | 163 | + page_set_flags(new_addr, new_addr + new_size, |
477 | + } | 164 | + prot | PAGE_VALID | PAGE_RESET); |
478 | } | 165 | } |
479 | 166 | tb_invalidate_phys_range(new_addr, new_addr + new_size); | |
480 | static const VMStateDescription cprman_vmstate = { | 167 | mmap_unlock(); |
481 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | 168 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
482 | { | 169 | index XXXXXXX..XXXXXXX 100644 |
483 | type_register_static(&cprman_info); | 170 | --- a/linux-user/syscall.c |
484 | type_register_static(&cprman_pll_info); | 171 | +++ b/linux-user/syscall.c |
485 | + type_register_static(&cprman_pll_channel_info); | 172 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, |
486 | } | 173 | raddr=h2g((unsigned long)host_raddr); |
487 | 174 | ||
488 | type_init(cprman_register_types); | 175 | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
176 | - PAGE_VALID | PAGE_READ | | ||
177 | - ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); | ||
178 | + PAGE_VALID | PAGE_RESET | PAGE_READ | | ||
179 | + (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE)); | ||
180 | |||
181 | for (i = 0; i < N_SHM_REGIONS; i++) { | ||
182 | if (!shm_regions[i].in_use) { | ||
489 | -- | 183 | -- |
490 | 2.20.1 | 184 | 2.20.1 |
491 | 185 | ||
492 | 186 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This simple mux sits between the PLL channels and the DSI0E and DSI0P | 3 | Record whether the backing page is anonymous, or if it has file |
4 | clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel | 4 | backing. This will allow us to get close to the Linux AArch64 |
5 | and outputs the selected signal to source number 4 of DSI0E/P clock | 5 | ABI for MTE, which allows tag memory only on ram-backed VMAs. |
6 | muxes. It is controlled by the cm_dsi0hsck register. | ||
7 | 6 | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | The real ABI allows tag memory on files, when those files are |
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | on ram-backed filesystems, such as tmpfs. We will not be able |
10 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 9 | to implement that in QEMU linux-user. |
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 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 | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 19 | --- |
14 | include/hw/misc/bcm2835_cprman.h | 15 +++++ | 20 | include/exec/cpu-all.h | 2 ++ |
15 | include/hw/misc/bcm2835_cprman_internals.h | 6 ++ | 21 | linux-user/mmap.c | 3 +++ |
16 | hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- | 22 | 2 files changed, 5 insertions(+) |
17 | 3 files changed, 94 insertions(+), 1 deletion(-) | ||
18 | 23 | ||
19 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 24 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/misc/bcm2835_cprman.h | 26 | --- a/include/exec/cpu-all.h |
22 | +++ b/include/hw/misc/bcm2835_cprman.h | 27 | +++ b/include/exec/cpu-all.h |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState { | 28 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
24 | struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; | 29 | #define PAGE_WRITE_INV 0x0020 |
25 | } CprmanClockMuxState; | 30 | /* For use with page_set_flags: page is being replaced; target_data cleared. */ |
26 | 31 | #define PAGE_RESET 0x0040 | |
27 | +typedef struct CprmanDsi0HsckMuxState { | 32 | +/* For linux-user, indicates that the page is MAP_ANON. */ |
28 | + /*< private >*/ | 33 | +#define PAGE_ANON 0x0080 |
29 | + DeviceState parent_obj; | 34 | |
30 | + | 35 | #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY) |
31 | + /*< public >*/ | 36 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ |
32 | + CprmanClockMux id; | 37 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
33 | + | ||
34 | + uint32_t *reg_cm; | ||
35 | + | ||
36 | + Clock *plla_in; | ||
37 | + Clock *plld_in; | ||
38 | + Clock *out; | ||
39 | +} CprmanDsi0HsckMuxState; | ||
40 | + | ||
41 | struct BCM2835CprmanState { | ||
42 | /*< private >*/ | ||
43 | SysBusDevice parent_obj; | ||
44 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
45 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
46 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
47 | CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; | ||
48 | + CprmanDsi0HsckMuxState dsi0hsck_mux; | ||
49 | |||
50 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
51 | uint32_t xosc_freq; | ||
52 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 39 | --- a/linux-user/mmap.c |
55 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 40 | +++ b/linux-user/mmap.c |
56 | @@ -XXX,XX +XXX,XX @@ | 41 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
57 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | ||
58 | #define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | ||
59 | #define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux" | ||
60 | +#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux" | ||
61 | |||
62 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | ||
63 | TYPE_CPRMAN_PLL) | ||
64 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, | ||
65 | TYPE_CPRMAN_PLL_CHANNEL) | ||
66 | DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX, | ||
67 | TYPE_CPRMAN_CLOCK_MUX) | ||
68 | +DECLARE_INSTANCE_CHECKER(CprmanDsi0HsckMuxState, CPRMAN_DSI0HSCK_MUX, | ||
69 | + TYPE_CPRMAN_DSI0HSCK_MUX) | ||
70 | |||
71 | /* Register map */ | ||
72 | |||
73 | @@ -XXX,XX +XXX,XX @@ REG32(CM_LOCK, 0x114) | ||
74 | FIELD(CM_LOCK, FLOCKB, 9, 1) | ||
75 | FIELD(CM_LOCK, FLOCKA, 8, 1) | ||
76 | |||
77 | +REG32(CM_DSI0HSCK, 0x120) | ||
78 | + FIELD(CM_DSI0HSCK, SELPLLD, 0, 1) | ||
79 | + | ||
80 | /* | ||
81 | * This field is common to all registers. Each register write value must match | ||
82 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
83 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/hw/misc/bcm2835_cprman.c | ||
86 | +++ b/hw/misc/bcm2835_cprman.c | ||
87 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_clock_mux_info = { | ||
88 | }; | ||
89 | |||
90 | |||
91 | +/* DSI0HSCK mux */ | ||
92 | + | ||
93 | +static void dsi0hsck_mux_update(CprmanDsi0HsckMuxState *s) | ||
94 | +{ | ||
95 | + bool src_is_plld = FIELD_EX32(*s->reg_cm, CM_DSI0HSCK, SELPLLD); | ||
96 | + Clock *src = src_is_plld ? s->plld_in : s->plla_in; | ||
97 | + | ||
98 | + clock_update(s->out, clock_get(src)); | ||
99 | +} | ||
100 | + | ||
101 | +static void dsi0hsck_mux_in_update(void *opaque) | ||
102 | +{ | ||
103 | + dsi0hsck_mux_update(CPRMAN_DSI0HSCK_MUX(opaque)); | ||
104 | +} | ||
105 | + | ||
106 | +static void dsi0hsck_mux_init(Object *obj) | ||
107 | +{ | ||
108 | + CprmanDsi0HsckMuxState *s = CPRMAN_DSI0HSCK_MUX(obj); | ||
109 | + DeviceState *dev = DEVICE(obj); | ||
110 | + | ||
111 | + s->plla_in = qdev_init_clock_in(dev, "plla-in", dsi0hsck_mux_in_update, s); | ||
112 | + s->plld_in = qdev_init_clock_in(dev, "plld-in", dsi0hsck_mux_in_update, s); | ||
113 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
114 | +} | ||
115 | + | ||
116 | +static const VMStateDescription dsi0hsck_mux_vmstate = { | ||
117 | + .name = TYPE_CPRMAN_DSI0HSCK_MUX, | ||
118 | + .version_id = 1, | ||
119 | + .minimum_version_id = 1, | ||
120 | + .fields = (VMStateField[]) { | ||
121 | + VMSTATE_CLOCK(plla_in, CprmanDsi0HsckMuxState), | ||
122 | + VMSTATE_CLOCK(plld_in, CprmanDsi0HsckMuxState), | ||
123 | + VMSTATE_END_OF_LIST() | ||
124 | + } | ||
125 | +}; | ||
126 | + | ||
127 | +static void dsi0hsck_mux_class_init(ObjectClass *klass, void *data) | ||
128 | +{ | ||
129 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
130 | + | ||
131 | + dc->vmsd = &dsi0hsck_mux_vmstate; | ||
132 | +} | ||
133 | + | ||
134 | +static const TypeInfo cprman_dsi0hsck_mux_info = { | ||
135 | + .name = TYPE_CPRMAN_DSI0HSCK_MUX, | ||
136 | + .parent = TYPE_DEVICE, | ||
137 | + .instance_size = sizeof(CprmanDsi0HsckMuxState), | ||
138 | + .class_init = dsi0hsck_mux_class_init, | ||
139 | + .instance_init = dsi0hsck_mux_init, | ||
140 | +}; | ||
141 | + | ||
142 | + | ||
143 | /* CPRMAN "top level" model */ | ||
144 | |||
145 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
146 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, | ||
147 | case R_CM_EMMC2CTL ... R_CM_EMMC2DIV: | ||
148 | update_mux_from_cm(s, idx); | ||
149 | break; | ||
150 | + | ||
151 | + case R_CM_DSI0HSCK: | ||
152 | + dsi0hsck_mux_update(&s->dsi0hsck_mux); | ||
153 | + break; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | ||
158 | device_cold_reset(DEVICE(&s->channels[i])); | ||
159 | } | ||
160 | |||
161 | + device_cold_reset(DEVICE(&s->dsi0hsck_mux)); | ||
162 | + | ||
163 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
164 | device_cold_reset(DEVICE(&s->clock_muxes[i])); | ||
165 | } | ||
166 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
167 | set_pll_channel_init_info(s, &s->channels[i], i); | ||
168 | } | ||
169 | |||
170 | + object_initialize_child(obj, "dsi0hsck-mux", | ||
171 | + &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX); | ||
172 | + s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK]; | ||
173 | + | ||
174 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
175 | char *alias; | ||
176 | |||
177 | @@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s, | ||
178 | if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { | ||
179 | src = s->gnd; | ||
180 | } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { | ||
181 | - src = s->gnd; /* TODO */ | ||
182 | + src = s->dsi0hsck_mux.out; | ||
183 | } else if (i < CPRMAN_CLOCK_SRC_PLLA) { | ||
184 | src = CLK_SRC_MAPPING[i]; | ||
185 | } else { | ||
186 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
187 | } | 42 | } |
188 | } | 43 | } |
189 | 44 | the_end1: | |
190 | + clock_set_source(s->dsi0hsck_mux.plla_in, | 45 | + if (flags & MAP_ANONYMOUS) { |
191 | + s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); | 46 | + page_flags |= PAGE_ANON; |
192 | + clock_set_source(s->dsi0hsck_mux.plld_in, | ||
193 | + s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); | ||
194 | + | ||
195 | + if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { | ||
196 | + return; | ||
197 | + } | 47 | + } |
198 | + | 48 | page_flags |= PAGE_RESET; |
199 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | 49 | page_set_flags(start, start + len, page_flags); |
200 | CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | 50 | the_end: |
201 | |||
202 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
203 | type_register_static(&cprman_pll_info); | ||
204 | type_register_static(&cprman_pll_channel_info); | ||
205 | type_register_static(&cprman_clock_mux_info); | ||
206 | + type_register_static(&cprman_dsi0hsck_mux_info); | ||
207 | } | ||
208 | |||
209 | type_init(cprman_register_types); | ||
210 | -- | 51 | -- |
211 | 2.20.1 | 52 | 2.20.1 |
212 | 53 | ||
213 | 54 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Fix an unlikely memory leak in load_elf_image(). | 3 | This is more descriptive than 'unsigned long'. |
4 | No functional change, since these match on all linux+bsd hosts. | ||
4 | 5 | ||
5 | Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20201021173749.111103-5-richard.henderson@linaro.org | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Message-Id: <20201003174944.1972444-1-f4bug@amsat.org> | 9 | Message-id: 20210212184902.1251044-4-richard.henderson@linaro.org |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 11 | --- |
14 | linux-user/elfload.c | 8 ++++---- | 12 | include/exec/cpu-all.h | 2 +- |
15 | 1 file changed, 4 insertions(+), 4 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(-) | ||
16 | 17 | ||
18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/exec/cpu-all.h | ||
21 | +++ b/include/exec/cpu-all.h | ||
22 | @@ -XXX,XX +XXX,XX @@ static inline void tswap64s(uint64_t *s) | ||
23 | /* On some host systems the guest address space is reserved on the host. | ||
24 | * This allows the guest address space to be offset to a convenient location. | ||
25 | */ | ||
26 | -extern unsigned long guest_base; | ||
27 | +extern uintptr_t guest_base; | ||
28 | extern bool have_guest_base; | ||
29 | extern unsigned long reserved_va; | ||
30 | |||
31 | diff --git a/bsd-user/main.c b/bsd-user/main.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/bsd-user/main.c | ||
34 | +++ b/bsd-user/main.c | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | |||
37 | int singlestep; | ||
38 | unsigned long mmap_min_addr; | ||
39 | -unsigned long guest_base; | ||
40 | +uintptr_t guest_base; | ||
41 | bool have_guest_base; | ||
42 | unsigned long reserved_va; | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
45 | g_free(target_environ); | ||
46 | |||
47 | if (qemu_loglevel_mask(CPU_LOG_PAGE)) { | ||
48 | - qemu_log("guest_base 0x%lx\n", guest_base); | ||
49 | + qemu_log("guest_base %p\n", (void *)guest_base); | ||
50 | log_page_dump("binary load"); | ||
51 | |||
52 | qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); | ||
17 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 53 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
18 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/linux-user/elfload.c | 55 | --- a/linux-user/elfload.c |
20 | +++ b/linux-user/elfload.c | 56 | +++ b/linux-user/elfload.c |
21 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 57 | @@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, |
22 | info->brk = vaddr_em; | 58 | void *addr, *test; |
23 | } | 59 | |
24 | } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | 60 | if (!QEMU_IS_ALIGNED(guest_base, align)) { |
25 | - char *interp_name; | 61 | - fprintf(stderr, "Requested guest base 0x%lx does not satisfy " |
26 | + g_autofree char *interp_name = NULL; | 62 | + fprintf(stderr, "Requested guest base %p does not satisfy " |
27 | 63 | "host minimum alignment (0x%lx)\n", | |
28 | if (*pinterp_name) { | 64 | - guest_base, align); |
29 | errmsg = "Multiple PT_INTERP entries"; | 65 | + (void *)guest_base, align); |
30 | goto exit_errmsg; | 66 | exit(EXIT_FAILURE); |
31 | } | ||
32 | - interp_name = malloc(eppnt->p_filesz); | ||
33 | + interp_name = g_malloc(eppnt->p_filesz); | ||
34 | if (!interp_name) { | ||
35 | goto exit_perror; | ||
36 | } | ||
37 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
38 | errmsg = "Invalid PT_INTERP entry"; | ||
39 | goto exit_errmsg; | ||
40 | } | ||
41 | - *pinterp_name = interp_name; | ||
42 | + *pinterp_name = g_steal_pointer(&interp_name); | ||
43 | #ifdef TARGET_MIPS | ||
44 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
45 | Mips_elf_abiflags_v0 abiflags; | ||
46 | @@ -XXX,XX +XXX,XX @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) | ||
47 | if (elf_interpreter) { | ||
48 | info->load_bias = interp_info.load_bias; | ||
49 | info->entry = interp_info.entry; | ||
50 | - free(elf_interpreter); | ||
51 | + g_free(elf_interpreter); | ||
52 | } | 67 | } |
53 | 68 | ||
54 | #ifdef USE_ELF_CORE_DUMP | 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); | ||
55 | -- | 91 | -- |
56 | 2.20.1 | 92 | 2.20.1 |
57 | 93 | ||
58 | 94 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | It makes no sense to set enabled-cpus=0 on single core SoCs. | 3 | This is more descriptive than 'unsigned long'. |
4 | No functional change, since these match on all linux+bsd hosts. | ||
4 | 5 | ||
5 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20201024170127.3592182-5-f4bug@amsat.org | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Message-id: 20210212184902.1251044-5-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | hw/arm/bcm2836.c | 15 +++++++-------- | 12 | include/exec/cpu_ldst.h | 6 +++--- |
11 | 1 file changed, 7 insertions(+), 8 deletions(-) | 13 | 1 file changed, 3 insertions(+), 3 deletions(-) |
12 | 14 | ||
13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | 15 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/arm/bcm2836.c | 17 | --- a/include/exec/cpu_ldst.h |
16 | +++ b/hw/arm/bcm2836.c | 18 | +++ b/include/exec/cpu_ldst.h |
17 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { | 19 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
18 | #define BCM283X_GET_CLASS(obj) \ | 20 | #endif |
19 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | 21 | |
20 | 22 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ | |
21 | +static Property bcm2836_enabled_cores_property = | 23 | -#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) |
22 | + DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0); | 24 | +#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
23 | + | 25 | |
24 | static void bcm2836_init(Object *obj) | 26 | #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
27 | #define guest_addr_valid(x) (1) | ||
28 | #else | ||
29 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) | ||
30 | #endif | ||
31 | -#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) | ||
32 | +#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) | ||
33 | |||
34 | static inline int guest_range_valid(unsigned long start, unsigned long len) | ||
25 | { | 35 | { |
26 | BCM283XState *s = BCM283X(obj); | 36 | @@ -XXX,XX +XXX,XX @@ static inline int guest_range_valid(unsigned long start, unsigned long len) |
27 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
28 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, | ||
29 | bc->cpu_type); | ||
30 | } | ||
31 | + if (bc->core_count > 1) { | ||
32 | + qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property); | ||
33 | + qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); | ||
34 | + } | ||
35 | |||
36 | object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
37 | |||
38 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
39 | } | ||
40 | } | 37 | } |
41 | 38 | ||
42 | -static Property bcm2836_props[] = { | 39 | #define h2g_nocheck(x) ({ \ |
43 | - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, | 40 | - unsigned long __ret = (unsigned long)(x) - guest_base; \ |
44 | - BCM283X_NCPUS), | 41 | + uintptr_t __ret = (uintptr_t)(x) - guest_base; \ |
45 | - DEFINE_PROP_END_OF_LIST() | 42 | (abi_ptr)__ret; \ |
46 | -}; | 43 | }) |
47 | - | ||
48 | static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
49 | { | ||
50 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
51 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
52 | bc->ctrl_base = 0x40000000; | ||
53 | bc->clusterid = 0xf; | ||
54 | dc->realize = bcm2836_realize; | ||
55 | - device_class_set_props(dc, bcm2836_props); | ||
56 | }; | ||
57 | |||
58 | #ifdef TARGET_AARCH64 | ||
59 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
60 | bc->ctrl_base = 0x40000000; | ||
61 | bc->clusterid = 0x0; | ||
62 | dc->realize = bcm2836_realize; | ||
63 | - device_class_set_props(dc, bcm2836_props); | ||
64 | }; | ||
65 | #endif | ||
66 | 44 | ||
67 | -- | 45 | -- |
68 | 2.20.1 | 46 | 2.20.1 |
69 | 47 | ||
70 | 48 | diff view generated by jsdifflib |
1 | From: "Dr. David Alan Gilbert" <dgilbert@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Use of 0x%d - make up our mind as 0x%x | 3 | Return bool not int; pass abi_ulong not 'unsigned long'. |
4 | All callers use abi_ulong already, so the change in type | ||
5 | has no effect. | ||
4 | 6 | ||
5 | Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Acked-by: Eric Auger <eric.auger@redhat.com> | 10 | Message-id: 20210212184902.1251044-6-richard.henderson@linaro.org |
8 | Message-id: 20201014193355.53074-1-dgilbert@redhat.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 12 | --- |
11 | hw/arm/trace-events | 2 +- | 13 | include/exec/cpu_ldst.h | 2 +- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events | 16 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/trace-events | 18 | --- a/include/exec/cpu_ldst.h |
17 | +++ b/hw/arm/trace-events | 19 | +++ b/include/exec/cpu_ldst.h |
18 | @@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 | 20 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
19 | smmuv3_decode_cd(uint32_t oas) "oas=%d" | 21 | #endif |
20 | smmuv3_decode_cd_tt(int i, uint32_t tsz, uint64_t ttb, uint32_t granule_sz, bool had) "TT[%d]:tsz:%d ttb:0x%"PRIx64" granule_sz:%d had:%d" | 22 | #define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) |
21 | smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d" | 23 | |
22 | -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d" | 24 | -static inline int guest_range_valid(unsigned long start, unsigned long len) |
23 | +smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" | 25 | +static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
24 | smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d" | 26 | { |
25 | smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache HIT for sid %d (hits=%d, misses=%d, hit rate=%d)" | 27 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
26 | smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache MISS for sid %d (hits=%d, misses=%d, hit rate=%d)" | 28 | } |
27 | -- | 29 | -- |
28 | 2.20.1 | 30 | 2.20.1 |
29 | 31 | ||
30 | 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 | This is generic support, with the code disabled for all targets. | 3 | Verify that addr + size - 1 does not wrap around. |
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 | Message-id: 20201021173749.111103-11-richard.henderson@linaro.org | 7 | Message-id: 20210212184902.1251044-7-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@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 | linux-user/qemu.h | 4 ++ | 10 | linux-user/qemu.h | 17 ++++++++++++----- |
11 | linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ | 11 | 1 file changed, 12 insertions(+), 5 deletions(-) |
12 | 2 files changed, 161 insertions(+) | ||
13 | 12 | ||
14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | 13 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/qemu.h | 15 | --- a/linux-user/qemu.h |
17 | +++ b/linux-user/qemu.h | 16 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ struct image_info { | 17 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
19 | abi_ulong interpreter_loadmap_addr; | 18 | #define VERIFY_READ 0 |
20 | abi_ulong interpreter_pt_dynamic_addr; | 19 | #define VERIFY_WRITE 1 /* implies read access */ |
21 | struct image_info *other_info; | 20 | |
22 | + | 21 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) |
23 | + /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */ | 22 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
24 | + uint32_t note_flags; | ||
25 | + | ||
26 | #ifdef TARGET_MIPS | ||
27 | int fp_abi; | ||
28 | int interp_fp_abi; | ||
29 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/linux-user/elfload.c | ||
32 | +++ b/linux-user/elfload.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, | ||
34 | |||
35 | #include "elf.h" | ||
36 | |||
37 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
38 | + const uint32_t *data, | ||
39 | + struct image_info *info, | ||
40 | + Error **errp) | ||
41 | +{ | ||
42 | + g_assert_not_reached(); | ||
43 | +} | ||
44 | +#define ARCH_USE_GNU_PROPERTY 0 | ||
45 | + | ||
46 | struct exec | ||
47 | { | 23 | { |
48 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ | 24 | - return guest_addr_valid(addr) && |
49 | @@ -XXX,XX +XXX,XX @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, | 25 | - (size == 0 || guest_addr_valid(addr + size - 1)) && |
50 | "@ 0x%" PRIx64 "\n", (uint64_t)guest_base); | 26 | - page_check_range((target_ulong)addr, size, |
51 | } | 27 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; |
52 | 28 | + if (!guest_addr_valid(addr)) { | |
53 | +enum { | ||
54 | + /* The string "GNU\0" as a magic number. */ | ||
55 | + GNU0_MAGIC = const_le32('G' | 'N' << 8 | 'U' << 16), | ||
56 | + NOTE_DATA_SZ = 1 * KiB, | ||
57 | + NOTE_NAME_SZ = 4, | ||
58 | + ELF_GNU_PROPERTY_ALIGN = ELF_CLASS == ELFCLASS32 ? 4 : 8, | ||
59 | +}; | ||
60 | + | ||
61 | +/* | ||
62 | + * Process a single gnu_property entry. | ||
63 | + * Return false for error. | ||
64 | + */ | ||
65 | +static bool parse_elf_property(const uint32_t *data, int *off, int datasz, | ||
66 | + struct image_info *info, bool have_prev_type, | ||
67 | + uint32_t *prev_type, Error **errp) | ||
68 | +{ | ||
69 | + uint32_t pr_type, pr_datasz, step; | ||
70 | + | ||
71 | + if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) { | ||
72 | + goto error_data; | ||
73 | + } | ||
74 | + datasz -= *off; | ||
75 | + data += *off / sizeof(uint32_t); | ||
76 | + | ||
77 | + if (datasz < 2 * sizeof(uint32_t)) { | ||
78 | + goto error_data; | ||
79 | + } | ||
80 | + pr_type = data[0]; | ||
81 | + pr_datasz = data[1]; | ||
82 | + data += 2; | ||
83 | + datasz -= 2 * sizeof(uint32_t); | ||
84 | + step = ROUND_UP(pr_datasz, ELF_GNU_PROPERTY_ALIGN); | ||
85 | + if (step > datasz) { | ||
86 | + goto error_data; | ||
87 | + } | ||
88 | + | ||
89 | + /* Properties are supposed to be unique and sorted on pr_type. */ | ||
90 | + if (have_prev_type && pr_type <= *prev_type) { | ||
91 | + if (pr_type == *prev_type) { | ||
92 | + error_setg(errp, "Duplicate property in PT_GNU_PROPERTY"); | ||
93 | + } else { | ||
94 | + error_setg(errp, "Unsorted property in PT_GNU_PROPERTY"); | ||
95 | + } | ||
96 | + return false; | 29 | + return false; |
97 | + } | 30 | + } |
98 | + *prev_type = pr_type; | 31 | + if (size != 0 && |
99 | + | 32 | + (addr + size - 1 < addr || |
100 | + if (!arch_parse_elf_property(pr_type, pr_datasz, data, info, errp)) { | 33 | + !guest_addr_valid(addr + size - 1))) { |
101 | + return false; | 34 | + return false; |
102 | + } | 35 | + } |
103 | + | 36 | + return page_check_range((target_ulong)addr, size, |
104 | + *off += 2 * sizeof(uint32_t) + step; | 37 | + (type == VERIFY_READ) ? PAGE_READ : |
105 | + return true; | 38 | + (PAGE_READ | PAGE_WRITE)) == 0; |
106 | + | 39 | } |
107 | + error_data: | 40 | |
108 | + error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY"); | 41 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
109 | + return false; | ||
110 | +} | ||
111 | + | ||
112 | +/* Process NT_GNU_PROPERTY_TYPE_0. */ | ||
113 | +static bool parse_elf_properties(int image_fd, | ||
114 | + struct image_info *info, | ||
115 | + const struct elf_phdr *phdr, | ||
116 | + char bprm_buf[BPRM_BUF_SIZE], | ||
117 | + Error **errp) | ||
118 | +{ | ||
119 | + union { | ||
120 | + struct elf_note nhdr; | ||
121 | + uint32_t data[NOTE_DATA_SZ / sizeof(uint32_t)]; | ||
122 | + } note; | ||
123 | + | ||
124 | + int n, off, datasz; | ||
125 | + bool have_prev_type; | ||
126 | + uint32_t prev_type; | ||
127 | + | ||
128 | + /* Unless the arch requires properties, ignore them. */ | ||
129 | + if (!ARCH_USE_GNU_PROPERTY) { | ||
130 | + return true; | ||
131 | + } | ||
132 | + | ||
133 | + /* If the properties are crazy large, that's too bad. */ | ||
134 | + n = phdr->p_filesz; | ||
135 | + if (n > sizeof(note)) { | ||
136 | + error_setg(errp, "PT_GNU_PROPERTY too large"); | ||
137 | + return false; | ||
138 | + } | ||
139 | + if (n < sizeof(note.nhdr)) { | ||
140 | + error_setg(errp, "PT_GNU_PROPERTY too small"); | ||
141 | + return false; | ||
142 | + } | ||
143 | + | ||
144 | + if (phdr->p_offset + n <= BPRM_BUF_SIZE) { | ||
145 | + memcpy(¬e, bprm_buf + phdr->p_offset, n); | ||
146 | + } else { | ||
147 | + ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); | ||
148 | + if (len != n) { | ||
149 | + error_setg_errno(errp, errno, "Error reading file header"); | ||
150 | + return false; | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + /* | ||
155 | + * The contents of a valid PT_GNU_PROPERTY is a sequence | ||
156 | + * of uint32_t -- swap them all now. | ||
157 | + */ | ||
158 | +#ifdef BSWAP_NEEDED | ||
159 | + for (int i = 0; i < n / 4; i++) { | ||
160 | + bswap32s(note.data + i); | ||
161 | + } | ||
162 | +#endif | ||
163 | + | ||
164 | + /* | ||
165 | + * Note that nhdr is 3 words, and that the "name" described by namesz | ||
166 | + * immediately follows nhdr and is thus at the 4th word. Further, all | ||
167 | + * of the inputs to the kernel's round_up are multiples of 4. | ||
168 | + */ | ||
169 | + if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 || | ||
170 | + note.nhdr.n_namesz != NOTE_NAME_SZ || | ||
171 | + note.data[3] != GNU0_MAGIC) { | ||
172 | + error_setg(errp, "Invalid note in PT_GNU_PROPERTY"); | ||
173 | + return false; | ||
174 | + } | ||
175 | + off = sizeof(note.nhdr) + NOTE_NAME_SZ; | ||
176 | + | ||
177 | + datasz = note.nhdr.n_descsz + off; | ||
178 | + if (datasz > n) { | ||
179 | + error_setg(errp, "Invalid note size in PT_GNU_PROPERTY"); | ||
180 | + return false; | ||
181 | + } | ||
182 | + | ||
183 | + have_prev_type = false; | ||
184 | + prev_type = 0; | ||
185 | + while (1) { | ||
186 | + if (off == datasz) { | ||
187 | + return true; /* end, exit ok */ | ||
188 | + } | ||
189 | + if (!parse_elf_property(note.data, &off, datasz, info, | ||
190 | + have_prev_type, &prev_type, errp)) { | ||
191 | + return false; | ||
192 | + } | ||
193 | + have_prev_type = true; | ||
194 | + } | ||
195 | +} | ||
196 | + | ||
197 | /* Load an ELF image into the address space. | ||
198 | |||
199 | IMAGE_NAME is the filename of the image, to use in error messages. | ||
200 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
201 | goto exit_errmsg; | ||
202 | } | ||
203 | *pinterp_name = g_steal_pointer(&interp_name); | ||
204 | + } else if (eppnt->p_type == PT_GNU_PROPERTY) { | ||
205 | + if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { | ||
206 | + goto exit_errmsg; | ||
207 | + } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | -- | 42 | -- |
212 | 2.20.1 | 43 | 2.20.1 |
213 | 44 | ||
214 | 45 | diff view generated by jsdifflib |
1 | From: Shashi Mallela <shashi.mallela@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Included the newly implemented SBSA generic watchdog device model into | 3 | These constants are only ever used with access_ok, and friends. |
4 | SBSA platform | 4 | Rather than translating them to PAGE_* bits, let them equal |
5 | the PAGE_* bits to begin. | ||
5 | 6 | ||
6 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20210212184902.1251044-8-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 | hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++ | 12 | linux-user/qemu.h | 8 +++----- |
12 | 1 file changed, 23 insertions(+) | 13 | 1 file changed, 3 insertions(+), 5 deletions(-) |
13 | 14 | ||
14 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c | 15 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/sbsa-ref.c | 17 | --- a/linux-user/qemu.h |
17 | +++ b/hw/arm/sbsa-ref.c | 18 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
19 | #include "hw/qdev-properties.h" | 20 | |
20 | #include "hw/usb.h" | 21 | /* user access */ |
21 | #include "hw/char/pl011.h" | 22 | |
22 | +#include "hw/watchdog/sbsa_gwdt.h" | 23 | -#define VERIFY_READ 0 |
23 | #include "net/net.h" | 24 | -#define VERIFY_WRITE 1 /* implies read access */ |
24 | #include "qom/object.h" | 25 | +#define VERIFY_READ PAGE_READ |
25 | 26 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) | |
26 | @@ -XXX,XX +XXX,XX @@ enum { | 27 | |
27 | SBSA_GIC_DIST, | 28 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
28 | SBSA_GIC_REDIST, | 29 | { |
29 | SBSA_SECURE_EC, | 30 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
30 | + SBSA_GWDT, | 31 | !guest_addr_valid(addr + size - 1))) { |
31 | + SBSA_GWDT_REFRESH, | 32 | return false; |
32 | + SBSA_GWDT_CONTROL, | 33 | } |
33 | SBSA_SMMU, | 34 | - return page_check_range((target_ulong)addr, size, |
34 | SBSA_UART, | 35 | - (type == VERIFY_READ) ? PAGE_READ : |
35 | SBSA_RTC, | 36 | - (PAGE_READ | PAGE_WRITE)) == 0; |
36 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { | 37 | + return page_check_range((target_ulong)addr, size, type) == 0; |
37 | [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 }, | ||
38 | [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 }, | ||
39 | [SBSA_SECURE_EC] = { 0x50000000, 0x00001000 }, | ||
40 | + [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 }, | ||
41 | + [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 }, | ||
42 | [SBSA_UART] = { 0x60000000, 0x00001000 }, | ||
43 | [SBSA_RTC] = { 0x60010000, 0x00001000 }, | ||
44 | [SBSA_GPIO] = { 0x60020000, 0x00001000 }, | ||
45 | @@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = { | ||
46 | [SBSA_AHCI] = 10, | ||
47 | [SBSA_EHCI] = 11, | ||
48 | [SBSA_SMMU] = 12, /* ... to 15 */ | ||
49 | + [SBSA_GWDT] = 16, | ||
50 | }; | ||
51 | |||
52 | static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) | ||
53 | @@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms) | ||
54 | sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq)); | ||
55 | } | 38 | } |
56 | 39 | ||
57 | +static void create_wdt(const SBSAMachineState *sms) | 40 | /* NOTE __get_user and __put_user use host pointers and don't check access. |
58 | +{ | ||
59 | + hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base; | ||
60 | + hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base; | ||
61 | + DeviceState *dev = qdev_new(TYPE_WDT_SBSA); | ||
62 | + SysBusDevice *s = SYS_BUS_DEVICE(dev); | ||
63 | + int irq = sbsa_ref_irqmap[SBSA_GWDT]; | ||
64 | + | ||
65 | + sysbus_realize_and_unref(s, &error_fatal); | ||
66 | + sysbus_mmio_map(s, 0, rbase); | ||
67 | + sysbus_mmio_map(s, 1, cbase); | ||
68 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq)); | ||
69 | +} | ||
70 | + | ||
71 | static DeviceState *gpio_key_dev; | ||
72 | static void sbsa_ref_powerdown_req(Notifier *n, void *opaque) | ||
73 | { | ||
74 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) | ||
75 | |||
76 | create_rtc(sms); | ||
77 | |||
78 | + create_wdt(sms); | ||
79 | + | ||
80 | create_gpio(sms); | ||
81 | |||
82 | create_ahci(sms); | ||
83 | -- | 41 | -- |
84 | 2.20.1 | 42 | 2.20.1 |
85 | 43 | ||
86 | 44 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | A PLL channel is able to further divide the generated PLL frequency. | 3 | These constants are only ever used with access_ok, and friends. |
4 | The divider is given in the CTRL_A2W register. Some channels have an | 4 | Rather than translating them to PAGE_* bits, let them equal |
5 | additional fixed divider which is always applied to the signal. | 5 | the PAGE_* bits to begin. |
6 | 6 | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Reviewed-by: Warner Losh <imp@bsdimp.com> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 10 | Message-id: 20210212184902.1251044-9-richard.henderson@linaro.org |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 12 | --- |
13 | hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- | 13 | bsd-user/qemu.h | 9 ++++----- |
14 | 1 file changed, 32 insertions(+), 1 deletion(-) | 14 | 1 file changed, 4 insertions(+), 5 deletions(-) |
15 | 15 | ||
16 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 16 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/misc/bcm2835_cprman.c | 18 | --- a/bsd-user/qemu.h |
19 | +++ b/hw/misc/bcm2835_cprman.c | 19 | +++ b/bsd-user/qemu.h |
20 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | 20 | @@ -XXX,XX +XXX,XX @@ extern unsigned long x86_stack_size; |
21 | 21 | ||
22 | /* PLL channel */ | 22 | /* user access */ |
23 | 23 | ||
24 | +static bool pll_channel_is_enabled(CprmanPllChannelState *channel) | 24 | -#define VERIFY_READ 0 |
25 | +{ | 25 | -#define VERIFY_WRITE 1 /* implies read access */ |
26 | + /* | 26 | +#define VERIFY_READ PAGE_READ |
27 | + * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does | 27 | +#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) |
28 | + * not set it when enabling the channel, but does clear it when disabling | 28 | |
29 | + * it. | 29 | -static inline int access_ok(int type, abi_ulong addr, abi_ulong size) |
30 | + */ | 30 | +static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) |
31 | + return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) | ||
32 | + && !(*channel->reg_cm & channel->hold_mask); | ||
33 | +} | ||
34 | + | ||
35 | static void pll_channel_update(CprmanPllChannelState *channel) | ||
36 | { | 31 | { |
37 | - clock_update(channel->out, 0); | 32 | - return page_check_range((target_ulong)addr, size, |
38 | + uint64_t freq, div; | 33 | - (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; |
39 | + | 34 | + return page_check_range((target_ulong)addr, size, type) == 0; |
40 | + if (!pll_channel_is_enabled(channel)) { | ||
41 | + clock_update(channel->out, 0); | ||
42 | + return; | ||
43 | + } | ||
44 | + | ||
45 | + div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); | ||
46 | + | ||
47 | + if (!div) { | ||
48 | + /* | ||
49 | + * It seems that when the divider value is 0, it is considered as | ||
50 | + * being maximum by the hardware (see the Linux driver). | ||
51 | + */ | ||
52 | + div = R_A2W_PLLx_CHANNELy_DIV_MASK; | ||
53 | + } | ||
54 | + | ||
55 | + /* Some channels have an additional fixed divider */ | ||
56 | + freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); | ||
57 | + | ||
58 | + clock_update_hz(channel->out, freq); | ||
59 | } | 35 | } |
60 | 36 | ||
61 | /* Update a PLL and all its channels */ | 37 | /* NOTE __get_user and __put_user use host pointers and don't check access. */ |
62 | -- | 38 | -- |
63 | 2.20.1 | 39 | 2.20.1 |
64 | 40 | ||
65 | 41 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | 3 | This is the only use of guest_addr_valid that does not begin |
4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | with a guest address, but a host address being transformed to |
5 | Message-id: 20201024170127.3592182-7-f4bug@amsat.org | 5 | a guest address. |
6 | |||
7 | We will shortly adjust guest_addr_valid to handle guest memory | ||
8 | tags, and the host address should not be subjected to that. | ||
9 | |||
10 | Move h2g_valid adjacent to the other h2g macros. | ||
11 | |||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20210212184902.1251044-10-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 16 | --- |
8 | include/hw/arm/bcm2836.h | 1 + | 17 | include/exec/cpu_ldst.h | 5 ++++- |
9 | hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++ | 18 | 1 file changed, 4 insertions(+), 1 deletion(-) |
10 | hw/arm/raspi.c | 2 ++ | ||
11 | 3 files changed, 37 insertions(+) | ||
12 | 19 | ||
13 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h | 20 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
14 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/arm/bcm2836.h | 22 | --- a/include/exec/cpu_ldst.h |
16 | +++ b/include/hw/arm/bcm2836.h | 23 | +++ b/include/exec/cpu_ldst.h |
17 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) | 24 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
18 | * them, code using these devices should always handle them via the | 25 | #else |
19 | * BCM283x base class, so they have no BCM2836(obj) etc macros. | 26 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
20 | */ | 27 | #endif |
21 | +#define TYPE_BCM2835 "bcm2835" | 28 | -#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base) |
22 | #define TYPE_BCM2836 "bcm2836" | 29 | |
23 | #define TYPE_BCM2837 "bcm2837" | 30 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
24 | 31 | { | |
25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | 32 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/arm/bcm2836.c | ||
28 | +++ b/hw/arm/bcm2836.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp) | ||
30 | return true; | ||
31 | } | 33 | } |
32 | 34 | ||
33 | +static void bcm2835_realize(DeviceState *dev, Error **errp) | 35 | +#define h2g_valid(x) \ |
34 | +{ | 36 | + (HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS || \ |
35 | + BCM283XState *s = BCM283X(dev); | 37 | + (uintptr_t)(x) - guest_base <= GUEST_ADDR_MAX) |
36 | + | 38 | + |
37 | + if (!bcm283x_common_realize(dev, errp)) { | 39 | #define h2g_nocheck(x) ({ \ |
38 | + return; | 40 | uintptr_t __ret = (uintptr_t)(x) - guest_base; \ |
39 | + } | 41 | (abi_ptr)__ret; \ |
40 | + | ||
41 | + if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) { | ||
42 | + return; | ||
43 | + } | ||
44 | + | ||
45 | + /* Connect irq/fiq outputs from the interrupt controller. */ | ||
46 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
47 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ)); | ||
48 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, | ||
49 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ)); | ||
50 | +} | ||
51 | + | ||
52 | static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
53 | { | ||
54 | BCM283XState *s = BCM283X(dev); | ||
55 | @@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
56 | dc->user_creatable = false; | ||
57 | } | ||
58 | |||
59 | +static void bcm2835_class_init(ObjectClass *oc, void *data) | ||
60 | +{ | ||
61 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
62 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
63 | + | ||
64 | + bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176"); | ||
65 | + bc->core_count = 1; | ||
66 | + bc->peri_base = 0x20000000; | ||
67 | + dc->realize = bcm2835_realize; | ||
68 | +}; | ||
69 | + | ||
70 | static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
71 | { | ||
72 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
73 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
74 | |||
75 | static const TypeInfo bcm283x_types[] = { | ||
76 | { | ||
77 | + .name = TYPE_BCM2835, | ||
78 | + .parent = TYPE_BCM283X, | ||
79 | + .class_init = bcm2835_class_init, | ||
80 | + }, { | ||
81 | .name = TYPE_BCM2836, | ||
82 | .parent = TYPE_BCM283X, | ||
83 | .class_init = bcm2836_class_init, | ||
84 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/hw/arm/raspi.c | ||
87 | +++ b/hw/arm/raspi.c | ||
88 | @@ -XXX,XX +XXX,XX @@ FIELD(REV_CODE, MEMORY_SIZE, 20, 3); | ||
89 | FIELD(REV_CODE, STYLE, 23, 1); | ||
90 | |||
91 | typedef enum RaspiProcessorId { | ||
92 | + PROCESSOR_ID_BCM2835 = 0, | ||
93 | PROCESSOR_ID_BCM2836 = 1, | ||
94 | PROCESSOR_ID_BCM2837 = 2, | ||
95 | } RaspiProcessorId; | ||
96 | @@ -XXX,XX +XXX,XX @@ static const struct { | ||
97 | const char *type; | ||
98 | int cores_count; | ||
99 | } soc_property[] = { | ||
100 | + [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1}, | ||
101 | [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, | ||
102 | [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, | ||
103 | }; | ||
104 | -- | 42 | -- |
105 | 2.20.1 | 43 | 2.20.1 |
106 | 44 | ||
107 | 45 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Connect the 'uart-out' clock from the CPRMAN to the PL011 instance. | 3 | We must always use GUEST_ADDR_MAX, because even 32-bit hosts can |
4 | use -R <reserved_va> to restrict the memory address of the guest. | ||
4 | 5 | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 8 | Message-id: 20210212184902.1251044-11-richard.henderson@linaro.org |
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 10 | --- |
11 | hw/arm/bcm2835_peripherals.c | 2 ++ | 11 | include/exec/cpu_ldst.h | 9 ++++----- |
12 | 1 file changed, 2 insertions(+) | 12 | 1 file changed, 4 insertions(+), 5 deletions(-) |
13 | 13 | ||
14 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/bcm2835_peripherals.c | 16 | --- a/include/exec/cpu_ldst.h |
17 | +++ b/hw/arm/bcm2835_peripherals.c | 17 | +++ b/include/exec/cpu_ldst.h |
18 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
19 | } | 19 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
20 | memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | 20 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
21 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | 21 | |
22 | + qdev_connect_clock_in(DEVICE(&s->uart0), "clk", | 22 | -#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
23 | + qdev_get_clock_out(DEVICE(&s->cprman), "uart-out")); | 23 | -#define guest_addr_valid(x) (1) |
24 | 24 | -#else | |
25 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | 25 | -#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
26 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | 26 | -#endif |
27 | +static inline bool guest_addr_valid(abi_ulong x) | ||
28 | +{ | ||
29 | + return x <= GUEST_ADDR_MAX; | ||
30 | +} | ||
31 | |||
32 | static inline bool guest_range_valid(abi_ulong start, abi_ulong len) | ||
33 | { | ||
27 | -- | 34 | -- |
28 | 2.20.1 | 35 | 2.20.1 |
29 | 36 | ||
30 | 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 | The second loop uses a loop induction variable, and the first | 3 | Provide an identity fallback for target that do not |
4 | does not. Transform the first to match the second, to simplify | 4 | use tagged addresses. |
5 | a following patch moving code between them. | ||
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 | Message-id: 20201021173749.111103-7-richard.henderson@linaro.org | 8 | Message-id: 20210212184902.1251044-12-richard.henderson@linaro.org |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 10 | --- |
12 | linux-user/elfload.c | 9 +++++---- | 11 | include/exec/cpu_ldst.h | 7 +++++++ |
13 | 1 file changed, 5 insertions(+), 4 deletions(-) | 12 | 1 file changed, 7 insertions(+) |
14 | 13 | ||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 14 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/linux-user/elfload.c | 16 | --- a/include/exec/cpu_ldst.h |
18 | +++ b/linux-user/elfload.c | 17 | +++ b/include/exec/cpu_ldst.h |
19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 18 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr; |
20 | loaddr = -1, hiaddr = 0; | 19 | #define TARGET_ABI_FMT_ptr "%"PRIx64 |
21 | info->alignment = 0; | 20 | #endif |
22 | for (i = 0; i < ehdr->e_phnum; ++i) { | 21 | |
23 | - if (phdr[i].p_type == PT_LOAD) { | 22 | +#ifndef TARGET_TAGGED_ADDRESSES |
24 | - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; | 23 | +static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) |
25 | + struct elf_phdr *eppnt = phdr + i; | 24 | +{ |
26 | + if (eppnt->p_type == PT_LOAD) { | 25 | + return x; |
27 | + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset; | 26 | +} |
28 | if (a < loaddr) { | 27 | +#endif |
29 | loaddr = a; | 28 | + |
30 | } | 29 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
31 | - a = phdr[i].p_vaddr + phdr[i].p_memsz; | 30 | #define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) |
32 | + a = eppnt->p_vaddr + eppnt->p_memsz; | ||
33 | if (a > hiaddr) { | ||
34 | hiaddr = a; | ||
35 | } | ||
36 | ++info->nsegs; | ||
37 | - info->alignment |= phdr[i].p_align; | ||
38 | + info->alignment |= eppnt->p_align; | ||
39 | } | ||
40 | } | ||
41 | 31 | ||
42 | -- | 32 | -- |
43 | 2.20.1 | 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 | For BTI, we need to know if the executable is static or dynamic, | 3 | Use g2h_untagged in contexts that have no cpu, e.g. the binary |
4 | which means looking for PT_INTERP earlier. | 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. | ||
5 | 7 | ||
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: 20201021173749.111103-8-richard.henderson@linaro.org | 21 | Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 23 | --- |
11 | linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- | 24 | bsd-user/qemu.h | 8 ++-- |
12 | 1 file changed, 31 insertions(+), 29 deletions(-) | 25 | include/exec/cpu_ldst.h | 12 +++++- |
26 | include/exec/exec-all.h | 2 +- | ||
27 | linux-user/qemu.h | 6 +-- | ||
28 | accel/tcg/translate-all.c | 4 +- | ||
29 | accel/tcg/user-exec.c | 48 ++++++++++++------------ | ||
30 | bsd-user/elfload.c | 2 +- | ||
31 | bsd-user/main.c | 4 +- | ||
32 | bsd-user/mmap.c | 23 ++++++------ | ||
33 | linux-user/elfload.c | 12 +++--- | ||
34 | linux-user/flatload.c | 2 +- | ||
35 | linux-user/hppa/cpu_loop.c | 31 ++++++++-------- | ||
36 | linux-user/i386/cpu_loop.c | 4 +- | ||
37 | linux-user/mmap.c | 45 +++++++++++----------- | ||
38 | linux-user/ppc/signal.c | 4 +- | ||
39 | linux-user/syscall.c | 72 +++++++++++++++++++----------------- | ||
40 | target/arm/helper-a64.c | 4 +- | ||
41 | target/hppa/op_helper.c | 2 +- | ||
42 | target/i386/tcg/mem_helper.c | 2 +- | ||
43 | target/s390x/mem_helper.c | 4 +- | ||
44 | 20 files changed, 154 insertions(+), 137 deletions(-) | ||
13 | 45 | ||
46 | diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/bsd-user/qemu.h | ||
49 | +++ b/bsd-user/qemu.h | ||
50 | @@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy | ||
51 | void *addr; | ||
52 | addr = g_malloc(len); | ||
53 | if (copy) | ||
54 | - memcpy(addr, g2h(guest_addr), len); | ||
55 | + memcpy(addr, g2h_untagged(guest_addr), len); | ||
56 | else | ||
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 | } | ||
14 | 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 |
15 | index XXXXXXX..XXXXXXX 100644 | 521 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/elfload.c | 522 | --- a/linux-user/elfload.c |
17 | +++ b/linux-user/elfload.c | 523 | +++ b/linux-user/elfload.c |
18 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 524 | @@ -XXX,XX +XXX,XX @@ enum { |
19 | 525 | ||
526 | static bool init_guest_commpage(void) | ||
527 | { | ||
528 | - void *want = g2h(ARM_COMMPAGE & -qemu_host_page_size); | ||
529 | + void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size); | ||
530 | void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, | ||
531 | MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); | ||
532 | |||
533 | @@ -XXX,XX +XXX,XX @@ static bool init_guest_commpage(void) | ||
534 | } | ||
535 | |||
536 | /* Set kernel helper versions; rest of page is 0. */ | ||
537 | - __put_user(5, (uint32_t *)g2h(0xffff0ffcu)); | ||
538 | + __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); | ||
539 | |||
540 | if (mprotect(addr, qemu_host_page_size, PROT_READ)) { | ||
541 | perror("Protecting guest commpage"); | ||
542 | @@ -XXX,XX +XXX,XX @@ static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) | ||
543 | here is still actually needed. For now, continue with it, | ||
544 | but merge it with the "normal" mmap that would allocate the bss. */ | ||
545 | |||
546 | - host_start = (uintptr_t) g2h(elf_bss); | ||
547 | - host_end = (uintptr_t) g2h(last_bss); | ||
548 | + host_start = (uintptr_t) g2h_untagged(elf_bss); | ||
549 | + host_end = (uintptr_t) g2h_untagged(last_bss); | ||
550 | host_map_start = REAL_HOST_PAGE_ALIGN(host_start); | ||
551 | |||
552 | if (host_map_start < host_end) { | ||
553 | @@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr, | ||
554 | } | ||
555 | |||
556 | /* Reserve the address space for the binary, or reserved_va. */ | ||
557 | - test = g2h(guest_loaddr); | ||
558 | + test = g2h_untagged(guest_loaddr); | ||
559 | addr = mmap(test, guest_hiaddr - guest_loaddr, PROT_NONE, flags, -1, 0); | ||
560 | if (test != addr) { | ||
561 | pgb_fail_in_use(image_name); | ||
562 | @@ -XXX,XX +XXX,XX @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, | ||
563 | |||
564 | /* Reserve the memory on the host. */ | ||
565 | assert(guest_base != 0); | ||
566 | - test = g2h(0); | ||
567 | + test = g2h_untagged(0); | ||
568 | addr = mmap(test, reserved_va, PROT_NONE, flags, -1, 0); | ||
569 | if (addr == MAP_FAILED || addr != test) { | ||
570 | error_report("Unable to reserve 0x%lx bytes of virtual address " | ||
571 | diff --git a/linux-user/flatload.c b/linux-user/flatload.c | ||
572 | index XXXXXXX..XXXXXXX 100644 | ||
573 | --- a/linux-user/flatload.c | ||
574 | +++ b/linux-user/flatload.c | ||
575 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
576 | } | ||
577 | |||
578 | /* zero the BSS. */ | ||
579 | - memset(g2h(datapos + data_len), 0, bss_len); | ||
580 | + memset(g2h_untagged(datapos + data_len), 0, bss_len); | ||
581 | |||
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, | ||
20 | mmap_lock(); | 807 | mmap_lock(); |
21 | 808 | ||
22 | - /* Find the maximum size of the image and allocate an appropriate | 809 | if (flags & MREMAP_FIXED) { |
23 | - amount of memory to handle that. */ | 810 | - host_addr = mremap(g2h(old_addr), old_size, new_size, |
24 | + /* | 811 | - flags, g2h(new_addr)); |
25 | + * Find the maximum size of the image and allocate an appropriate | 812 | + host_addr = mremap(g2h_untagged(old_addr), old_size, new_size, |
26 | + * amount of memory to handle that. Locate the interpreter, if any. | 813 | + flags, g2h_untagged(new_addr)); |
27 | + */ | 814 | |
28 | loaddr = -1, hiaddr = 0; | 815 | if (reserved_va && host_addr != MAP_FAILED) { |
29 | info->alignment = 0; | 816 | /* If new and old addresses overlap then the above mremap will |
30 | for (i = 0; i < ehdr->e_phnum; ++i) { | 817 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
31 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 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); | ||
32 | } | 828 | } |
33 | ++info->nsegs; | 829 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
34 | info->alignment |= eppnt->p_align; | ||
35 | + } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
36 | + g_autofree char *interp_name = NULL; | ||
37 | + | ||
38 | + if (*pinterp_name) { | ||
39 | + errmsg = "Multiple PT_INTERP entries"; | ||
40 | + goto exit_errmsg; | ||
41 | + } | ||
42 | + interp_name = g_malloc(eppnt->p_filesz); | ||
43 | + if (!interp_name) { | ||
44 | + goto exit_perror; | ||
45 | + } | ||
46 | + | ||
47 | + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
48 | + memcpy(interp_name, bprm_buf + eppnt->p_offset, | ||
49 | + eppnt->p_filesz); | ||
50 | + } else { | ||
51 | + retval = pread(image_fd, interp_name, eppnt->p_filesz, | ||
52 | + eppnt->p_offset); | ||
53 | + if (retval != eppnt->p_filesz) { | ||
54 | + goto exit_perror; | ||
55 | + } | ||
56 | + } | ||
57 | + if (interp_name[eppnt->p_filesz - 1] != 0) { | ||
58 | + errmsg = "Invalid PT_INTERP entry"; | ||
59 | + goto exit_errmsg; | ||
60 | + } | ||
61 | + *pinterp_name = g_steal_pointer(&interp_name); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
66 | if (vaddr_em > info->brk) { | ||
67 | info->brk = vaddr_em; | ||
68 | } | 830 | } |
69 | - } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | 831 | } |
70 | - g_autofree char *interp_name = NULL; | 832 | if (prot == 0) { |
71 | - | 833 | - host_addr = mremap(g2h(old_addr), old_size, new_size, flags); |
72 | - if (*pinterp_name) { | 834 | + host_addr = mremap(g2h_untagged(old_addr), |
73 | - errmsg = "Multiple PT_INTERP entries"; | 835 | + old_size, new_size, flags); |
74 | - goto exit_errmsg; | 836 | |
75 | - } | 837 | if (host_addr != MAP_FAILED) { |
76 | - interp_name = g_malloc(eppnt->p_filesz); | 838 | /* Check if address fits target address space */ |
77 | - if (!interp_name) { | 839 | if (!guest_range_valid(h2g(host_addr), new_size)) { |
78 | - goto exit_perror; | 840 | /* Revert mremap() changes */ |
79 | - } | 841 | - host_addr = mremap(g2h(old_addr), new_size, old_size, |
80 | - | 842 | - flags); |
81 | - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | 843 | + host_addr = mremap(g2h_untagged(old_addr), |
82 | - memcpy(interp_name, bprm_buf + eppnt->p_offset, | 844 | + new_size, old_size, flags); |
83 | - eppnt->p_filesz); | 845 | errno = ENOMEM; |
84 | - } else { | 846 | host_addr = MAP_FAILED; |
85 | - retval = pread(image_fd, interp_name, eppnt->p_filesz, | 847 | } else if (reserved_va && old_size > new_size) { |
86 | - eppnt->p_offset); | 848 | diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c |
87 | - if (retval != eppnt->p_filesz) { | 849 | index XXXXXXX..XXXXXXX 100644 |
88 | - goto exit_perror; | 850 | --- a/linux-user/ppc/signal.c |
89 | - } | 851 | +++ b/linux-user/ppc/signal.c |
90 | - } | 852 | @@ -XXX,XX +XXX,XX @@ static void restore_user_regs(CPUPPCState *env, |
91 | - if (interp_name[eppnt->p_filesz - 1] != 0) { | 853 | uint64_t v_addr; |
92 | - errmsg = "Invalid PT_INTERP entry"; | 854 | /* 64-bit needs to recover the pointer to the vectors from the frame */ |
93 | - goto exit_errmsg; | 855 | __get_user(v_addr, &frame->v_regs); |
94 | - } | 856 | - v_regs = g2h(v_addr); |
95 | - *pinterp_name = g_steal_pointer(&interp_name); | 857 | + v_regs = g2h(env_cpu(env), v_addr); |
96 | #ifdef TARGET_MIPS | 858 | #else |
97 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | 859 | v_regs = (ppc_avr_t *)frame->mc_vregs.altivec; |
98 | Mips_elf_abiflags_v0 abiflags; | 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); | ||
99 | -- | 1173 | -- |
100 | 2.20.1 | 1174 | 2.20.1 |
101 | 1175 | ||
102 | 1176 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them | 3 | We define target_mmap et al as untagged, so that they can be |
4 | take the xosc clock as input and produce a new clock. | 4 | used from the binary loaders. Explicitly call cpu_untagged_addr |
5 | for munmap, mprotect, mremap syscall entry points. | ||
5 | 6 | ||
6 | This commit adds a skeleton implementation for the PLLs as sub-devices | 7 | Add a few comments for the syscalls that are exempted by the |
7 | of the CPRMAN. The PLLs are instantiated and connected internally to the | 8 | kernel's tagged-address-abi.rst. |
8 | main oscillator. | ||
9 | 9 | ||
10 | Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | write to any of them triggers a call to the (not yet implemented) | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | pll_update function. | 12 | Message-id: 20210212184902.1251044-14-richard.henderson@linaro.org |
13 | |||
14 | If the main oscillator changes frequency, an update is also triggered. | ||
15 | |||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
19 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 14 | --- |
22 | include/hw/misc/bcm2835_cprman.h | 29 +++++ | 15 | linux-user/syscall.c | 11 +++++++++++ |
23 | include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ | 16 | 1 file changed, 11 insertions(+) |
24 | hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ | ||
25 | 3 files changed, 281 insertions(+) | ||
26 | 17 | ||
27 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 18 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
28 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/misc/bcm2835_cprman.h | 20 | --- a/linux-user/syscall.c |
30 | +++ b/include/hw/misc/bcm2835_cprman.h | 21 | +++ b/linux-user/syscall.c |
31 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | 22 | @@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk) |
32 | 23 | abi_long mapped_addr; | |
33 | #define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | 24 | abi_ulong new_alloc_size; |
34 | 25 | ||
35 | +typedef enum CprmanPll { | 26 | + /* brk pointers are always untagged */ |
36 | + CPRMAN_PLLA = 0, | ||
37 | + CPRMAN_PLLC, | ||
38 | + CPRMAN_PLLD, | ||
39 | + CPRMAN_PLLH, | ||
40 | + CPRMAN_PLLB, | ||
41 | + | 27 | + |
42 | + CPRMAN_NUM_PLL | 28 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); |
43 | +} CprmanPll; | 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 */ | ||
44 | + | 36 | + |
45 | +typedef struct CprmanPllState { | 37 | /* find out the length of the shared memory segment */ |
46 | + /*< private >*/ | 38 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); |
47 | + DeviceState parent_obj; | 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 */ | ||
48 | + | 45 | + |
49 | + /*< public >*/ | 46 | mmap_lock(); |
50 | + CprmanPll id; | 47 | |
51 | + | 48 | for (i = 0; i < N_SHM_REGIONS; ++i) { |
52 | + uint32_t *reg_cm; | 49 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
53 | + uint32_t *reg_a2w_ctrl; | 50 | v5, v6)); |
54 | + uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */ | 51 | } |
55 | + uint32_t prediv_mask; /* prediv bit in ana[1] */ | 52 | #else |
56 | + uint32_t *reg_a2w_frac; | 53 | + /* mmap pointers are always untagged */ |
57 | + | 54 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
58 | + Clock *xosc_in; | 55 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
59 | + Clock *out; | 56 | arg5, |
60 | +} CprmanPllState; | 57 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
61 | + | 58 | return get_errno(ret); |
62 | struct BCM2835CprmanState { | ||
63 | /*< private >*/ | ||
64 | SysBusDevice parent_obj; | ||
65 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
66 | /*< public >*/ | ||
67 | MemoryRegion iomem; | ||
68 | |||
69 | + CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
70 | + | ||
71 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
72 | uint32_t xosc_freq; | ||
73 | |||
74 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
77 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
78 | @@ -XXX,XX +XXX,XX @@ | ||
79 | #include "hw/registerfields.h" | ||
80 | #include "hw/misc/bcm2835_cprman.h" | ||
81 | |||
82 | +#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | ||
83 | + | ||
84 | +DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | ||
85 | + TYPE_CPRMAN_PLL) | ||
86 | + | ||
87 | /* Register map */ | ||
88 | |||
89 | +/* PLLs */ | ||
90 | +REG32(CM_PLLA, 0x104) | ||
91 | + FIELD(CM_PLLA, LOADDSI0, 0, 1) | ||
92 | + FIELD(CM_PLLA, HOLDDSI0, 1, 1) | ||
93 | + FIELD(CM_PLLA, LOADCCP2, 2, 1) | ||
94 | + FIELD(CM_PLLA, HOLDCCP2, 3, 1) | ||
95 | + FIELD(CM_PLLA, LOADCORE, 4, 1) | ||
96 | + FIELD(CM_PLLA, HOLDCORE, 5, 1) | ||
97 | + FIELD(CM_PLLA, LOADPER, 6, 1) | ||
98 | + FIELD(CM_PLLA, HOLDPER, 7, 1) | ||
99 | + FIELD(CM_PLLx, ANARST, 8, 1) | ||
100 | +REG32(CM_PLLC, 0x108) | ||
101 | + FIELD(CM_PLLC, LOADCORE0, 0, 1) | ||
102 | + FIELD(CM_PLLC, HOLDCORE0, 1, 1) | ||
103 | + FIELD(CM_PLLC, LOADCORE1, 2, 1) | ||
104 | + FIELD(CM_PLLC, HOLDCORE1, 3, 1) | ||
105 | + FIELD(CM_PLLC, LOADCORE2, 4, 1) | ||
106 | + FIELD(CM_PLLC, HOLDCORE2, 5, 1) | ||
107 | + FIELD(CM_PLLC, LOADPER, 6, 1) | ||
108 | + FIELD(CM_PLLC, HOLDPER, 7, 1) | ||
109 | +REG32(CM_PLLD, 0x10c) | ||
110 | + FIELD(CM_PLLD, LOADDSI0, 0, 1) | ||
111 | + FIELD(CM_PLLD, HOLDDSI0, 1, 1) | ||
112 | + FIELD(CM_PLLD, LOADDSI1, 2, 1) | ||
113 | + FIELD(CM_PLLD, HOLDDSI1, 3, 1) | ||
114 | + FIELD(CM_PLLD, LOADCORE, 4, 1) | ||
115 | + FIELD(CM_PLLD, HOLDCORE, 5, 1) | ||
116 | + FIELD(CM_PLLD, LOADPER, 6, 1) | ||
117 | + FIELD(CM_PLLD, HOLDPER, 7, 1) | ||
118 | +REG32(CM_PLLH, 0x110) | ||
119 | + FIELD(CM_PLLH, LOADPIX, 0, 1) | ||
120 | + FIELD(CM_PLLH, LOADAUX, 1, 1) | ||
121 | + FIELD(CM_PLLH, LOADRCAL, 2, 1) | ||
122 | +REG32(CM_PLLB, 0x170) | ||
123 | + FIELD(CM_PLLB, LOADARM, 0, 1) | ||
124 | + FIELD(CM_PLLB, HOLDARM, 1, 1) | ||
125 | + | ||
126 | +REG32(A2W_PLLA_CTRL, 0x1100) | ||
127 | + FIELD(A2W_PLLx_CTRL, NDIV, 0, 10) | ||
128 | + FIELD(A2W_PLLx_CTRL, PDIV, 12, 3) | ||
129 | + FIELD(A2W_PLLx_CTRL, PWRDN, 16, 1) | ||
130 | + FIELD(A2W_PLLx_CTRL, PRST_DISABLE, 17, 1) | ||
131 | +REG32(A2W_PLLC_CTRL, 0x1120) | ||
132 | +REG32(A2W_PLLD_CTRL, 0x1140) | ||
133 | +REG32(A2W_PLLH_CTRL, 0x1160) | ||
134 | +REG32(A2W_PLLB_CTRL, 0x11e0) | ||
135 | + | ||
136 | +REG32(A2W_PLLA_ANA0, 0x1010) | ||
137 | +REG32(A2W_PLLA_ANA1, 0x1014) | ||
138 | + FIELD(A2W_PLLx_ANA1, FB_PREDIV, 14, 1) | ||
139 | +REG32(A2W_PLLA_ANA2, 0x1018) | ||
140 | +REG32(A2W_PLLA_ANA3, 0x101c) | ||
141 | + | ||
142 | +REG32(A2W_PLLC_ANA0, 0x1030) | ||
143 | +REG32(A2W_PLLC_ANA1, 0x1034) | ||
144 | +REG32(A2W_PLLC_ANA2, 0x1038) | ||
145 | +REG32(A2W_PLLC_ANA3, 0x103c) | ||
146 | + | ||
147 | +REG32(A2W_PLLD_ANA0, 0x1050) | ||
148 | +REG32(A2W_PLLD_ANA1, 0x1054) | ||
149 | +REG32(A2W_PLLD_ANA2, 0x1058) | ||
150 | +REG32(A2W_PLLD_ANA3, 0x105c) | ||
151 | + | ||
152 | +REG32(A2W_PLLH_ANA0, 0x1070) | ||
153 | +REG32(A2W_PLLH_ANA1, 0x1074) | ||
154 | + FIELD(A2W_PLLH_ANA1, FB_PREDIV, 11, 1) | ||
155 | +REG32(A2W_PLLH_ANA2, 0x1078) | ||
156 | +REG32(A2W_PLLH_ANA3, 0x107c) | ||
157 | + | ||
158 | +REG32(A2W_PLLB_ANA0, 0x10f0) | ||
159 | +REG32(A2W_PLLB_ANA1, 0x10f4) | ||
160 | +REG32(A2W_PLLB_ANA2, 0x10f8) | ||
161 | +REG32(A2W_PLLB_ANA3, 0x10fc) | ||
162 | + | ||
163 | +REG32(A2W_PLLA_FRAC, 0x1200) | ||
164 | + FIELD(A2W_PLLx_FRAC, FRAC, 0, 20) | ||
165 | +REG32(A2W_PLLC_FRAC, 0x1220) | ||
166 | +REG32(A2W_PLLD_FRAC, 0x1240) | ||
167 | +REG32(A2W_PLLH_FRAC, 0x1260) | ||
168 | +REG32(A2W_PLLB_FRAC, 0x12e0) | ||
169 | + | ||
170 | /* | ||
171 | * This field is common to all registers. Each register write value must match | ||
172 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
173 | @@ -XXX,XX +XXX,XX @@ | ||
174 | FIELD(CPRMAN, PASSWORD, 24, 8) | ||
175 | #define CPRMAN_PASSWORD 0x5a | ||
176 | |||
177 | +/* PLL init info */ | ||
178 | +typedef struct PLLInitInfo { | ||
179 | + const char *name; | ||
180 | + size_t cm_offset; | ||
181 | + size_t a2w_ctrl_offset; | ||
182 | + size_t a2w_ana_offset; | ||
183 | + uint32_t prediv_mask; /* Prediv bit in ana[1] */ | ||
184 | + size_t a2w_frac_offset; | ||
185 | +} PLLInitInfo; | ||
186 | + | ||
187 | +#define FILL_PLL_INIT_INFO(pll_) \ | ||
188 | + .cm_offset = R_CM_ ## pll_, \ | ||
189 | + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _CTRL, \ | ||
190 | + .a2w_ana_offset = R_A2W_ ## pll_ ## _ANA0, \ | ||
191 | + .a2w_frac_offset = R_A2W_ ## pll_ ## _FRAC | ||
192 | + | ||
193 | +static const PLLInitInfo PLL_INIT_INFO[] = { | ||
194 | + [CPRMAN_PLLA] = { | ||
195 | + .name = "plla", | ||
196 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
197 | + FILL_PLL_INIT_INFO(PLLA), | ||
198 | + }, | ||
199 | + [CPRMAN_PLLC] = { | ||
200 | + .name = "pllc", | ||
201 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
202 | + FILL_PLL_INIT_INFO(PLLC), | ||
203 | + }, | ||
204 | + [CPRMAN_PLLD] = { | ||
205 | + .name = "plld", | ||
206 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
207 | + FILL_PLL_INIT_INFO(PLLD), | ||
208 | + }, | ||
209 | + [CPRMAN_PLLH] = { | ||
210 | + .name = "pllh", | ||
211 | + .prediv_mask = R_A2W_PLLH_ANA1_FB_PREDIV_MASK, | ||
212 | + FILL_PLL_INIT_INFO(PLLH), | ||
213 | + }, | ||
214 | + [CPRMAN_PLLB] = { | ||
215 | + .name = "pllb", | ||
216 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
217 | + FILL_PLL_INIT_INFO(PLLB), | ||
218 | + }, | ||
219 | +}; | ||
220 | + | ||
221 | +#undef FILL_PLL_CHANNEL_INIT_INFO | ||
222 | + | ||
223 | +static inline void set_pll_init_info(BCM2835CprmanState *s, | ||
224 | + CprmanPllState *pll, | ||
225 | + CprmanPll id) | ||
226 | +{ | ||
227 | + pll->id = id; | ||
228 | + pll->reg_cm = &s->regs[PLL_INIT_INFO[id].cm_offset]; | ||
229 | + pll->reg_a2w_ctrl = &s->regs[PLL_INIT_INFO[id].a2w_ctrl_offset]; | ||
230 | + pll->reg_a2w_ana = &s->regs[PLL_INIT_INFO[id].a2w_ana_offset]; | ||
231 | + pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask; | ||
232 | + pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset]; | ||
233 | +} | ||
234 | + | ||
235 | #endif | 59 | #endif |
236 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 60 | case TARGET_NR_munmap: |
237 | index XXXXXXX..XXXXXXX 100644 | 61 | + arg1 = cpu_untagged_addr(cpu, arg1); |
238 | --- a/hw/misc/bcm2835_cprman.c | 62 | return get_errno(target_munmap(arg1, arg2)); |
239 | +++ b/hw/misc/bcm2835_cprman.c | 63 | case TARGET_NR_mprotect: |
240 | @@ -XXX,XX +XXX,XX @@ | 64 | + arg1 = cpu_untagged_addr(cpu, arg1); |
241 | #include "hw/misc/bcm2835_cprman_internals.h" | 65 | { |
242 | #include "trace.h" | 66 | TaskState *ts = cpu->opaque; |
243 | 67 | /* Special hack to detect libc making the stack executable. */ | |
244 | +/* PLL */ | 68 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, |
245 | + | 69 | return get_errno(target_mprotect(arg1, arg2, arg3)); |
246 | +static void pll_update(CprmanPllState *pll) | 70 | #ifdef TARGET_NR_mremap |
247 | +{ | 71 | case TARGET_NR_mremap: |
248 | + clock_update(pll->out, 0); | 72 | + arg1 = cpu_untagged_addr(cpu, arg1); |
249 | +} | 73 | + /* mremap new_addr (arg5) is always untagged */ |
250 | + | 74 | return get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
251 | +static void pll_xosc_update(void *opaque) | 75 | #endif |
252 | +{ | 76 | /* ??? msync/mlock/munlock are broken for softmmu. */ |
253 | + pll_update(CPRMAN_PLL(opaque)); | ||
254 | +} | ||
255 | + | ||
256 | +static void pll_init(Object *obj) | ||
257 | +{ | ||
258 | + CprmanPllState *s = CPRMAN_PLL(obj); | ||
259 | + | ||
260 | + s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); | ||
261 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
262 | +} | ||
263 | + | ||
264 | +static const VMStateDescription pll_vmstate = { | ||
265 | + .name = TYPE_CPRMAN_PLL, | ||
266 | + .version_id = 1, | ||
267 | + .minimum_version_id = 1, | ||
268 | + .fields = (VMStateField[]) { | ||
269 | + VMSTATE_CLOCK(xosc_in, CprmanPllState), | ||
270 | + VMSTATE_END_OF_LIST() | ||
271 | + } | ||
272 | +}; | ||
273 | + | ||
274 | +static void pll_class_init(ObjectClass *klass, void *data) | ||
275 | +{ | ||
276 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
277 | + | ||
278 | + dc->vmsd = &pll_vmstate; | ||
279 | +} | ||
280 | + | ||
281 | +static const TypeInfo cprman_pll_info = { | ||
282 | + .name = TYPE_CPRMAN_PLL, | ||
283 | + .parent = TYPE_DEVICE, | ||
284 | + .instance_size = sizeof(CprmanPllState), | ||
285 | + .class_init = pll_class_init, | ||
286 | + .instance_init = pll_init, | ||
287 | +}; | ||
288 | + | ||
289 | + | ||
290 | /* CPRMAN "top level" model */ | ||
291 | |||
292 | static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
293 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
294 | return r; | ||
295 | } | ||
296 | |||
297 | +#define CASE_PLL_REGS(pll_) \ | ||
298 | + case R_CM_ ## pll_: \ | ||
299 | + case R_A2W_ ## pll_ ## _CTRL: \ | ||
300 | + case R_A2W_ ## pll_ ## _ANA0: \ | ||
301 | + case R_A2W_ ## pll_ ## _ANA1: \ | ||
302 | + case R_A2W_ ## pll_ ## _ANA2: \ | ||
303 | + case R_A2W_ ## pll_ ## _ANA3: \ | ||
304 | + case R_A2W_ ## pll_ ## _FRAC | ||
305 | + | ||
306 | static void cprman_write(void *opaque, hwaddr offset, | ||
307 | uint64_t value, unsigned size) | ||
308 | { | ||
309 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, | ||
310 | trace_bcm2835_cprman_write(offset, value); | ||
311 | s->regs[idx] = value; | ||
312 | |||
313 | + switch (idx) { | ||
314 | + CASE_PLL_REGS(PLLA) : | ||
315 | + pll_update(&s->plls[CPRMAN_PLLA]); | ||
316 | + break; | ||
317 | + | ||
318 | + CASE_PLL_REGS(PLLC) : | ||
319 | + pll_update(&s->plls[CPRMAN_PLLC]); | ||
320 | + break; | ||
321 | + | ||
322 | + CASE_PLL_REGS(PLLD) : | ||
323 | + pll_update(&s->plls[CPRMAN_PLLD]); | ||
324 | + break; | ||
325 | + | ||
326 | + CASE_PLL_REGS(PLLH) : | ||
327 | + pll_update(&s->plls[CPRMAN_PLLH]); | ||
328 | + break; | ||
329 | + | ||
330 | + CASE_PLL_REGS(PLLB) : | ||
331 | + pll_update(&s->plls[CPRMAN_PLLB]); | ||
332 | + break; | ||
333 | + } | ||
334 | } | ||
335 | |||
336 | +#undef CASE_PLL_REGS | ||
337 | + | ||
338 | static const MemoryRegionOps cprman_ops = { | ||
339 | .read = cprman_read, | ||
340 | .write = cprman_write, | ||
341 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cprman_ops = { | ||
342 | static void cprman_reset(DeviceState *dev) | ||
343 | { | ||
344 | BCM2835CprmanState *s = CPRMAN(dev); | ||
345 | + size_t i; | ||
346 | |||
347 | memset(s->regs, 0, sizeof(s->regs)); | ||
348 | |||
349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
350 | + device_cold_reset(DEVICE(&s->plls[i])); | ||
351 | + } | ||
352 | + | ||
353 | clock_update_hz(s->xosc, s->xosc_freq); | ||
354 | } | ||
355 | |||
356 | static void cprman_init(Object *obj) | ||
357 | { | ||
358 | BCM2835CprmanState *s = CPRMAN(obj); | ||
359 | + size_t i; | ||
360 | + | ||
361 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
362 | + object_initialize_child(obj, PLL_INIT_INFO[i].name, | ||
363 | + &s->plls[i], TYPE_CPRMAN_PLL); | ||
364 | + set_pll_init_info(s, &s->plls[i], i); | ||
365 | + } | ||
366 | |||
367 | s->xosc = clock_new(obj, "xosc"); | ||
368 | |||
369 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
370 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
371 | } | ||
372 | |||
373 | +static void cprman_realize(DeviceState *dev, Error **errp) | ||
374 | +{ | ||
375 | + BCM2835CprmanState *s = CPRMAN(dev); | ||
376 | + size_t i; | ||
377 | + | ||
378 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
379 | + CprmanPllState *pll = &s->plls[i]; | ||
380 | + | ||
381 | + clock_set_source(pll->xosc_in, s->xosc); | ||
382 | + | ||
383 | + if (!qdev_realize(DEVICE(pll), NULL, errp)) { | ||
384 | + return; | ||
385 | + } | ||
386 | + } | ||
387 | +} | ||
388 | + | ||
389 | static const VMStateDescription cprman_vmstate = { | ||
390 | .name = TYPE_BCM2835_CPRMAN, | ||
391 | .version_id = 1, | ||
392 | @@ -XXX,XX +XXX,XX @@ static void cprman_class_init(ObjectClass *klass, void *data) | ||
393 | { | ||
394 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
395 | |||
396 | + dc->realize = cprman_realize; | ||
397 | dc->reset = cprman_reset; | ||
398 | dc->vmsd = &cprman_vmstate; | ||
399 | device_class_set_props(dc, cprman_properties); | ||
400 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_info = { | ||
401 | static void cprman_register_types(void) | ||
402 | { | ||
403 | type_register_static(&cprman_info); | ||
404 | + type_register_static(&cprman_pll_info); | ||
405 | } | ||
406 | |||
407 | type_init(cprman_register_types); | ||
408 | -- | 77 | -- |
409 | 2.20.1 | 78 | 2.20.1 |
410 | 79 | ||
411 | 80 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The nanosecond unit greatly limits the dynamic range we can display in | 3 | We're currently open-coding the range check in access_ok; |
4 | clock value traces, for values in the order of 1GHz and more. The | 4 | use guest_range_valid when size != 0. |
5 | internal representation can go way beyond this value and it is quite | ||
6 | common for today's clocks to be within those ranges. | ||
7 | 5 | ||
8 | For example, a frequency between 500MHz+ and 1GHz will be displayed as | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | 1ns. Beyond 1GHz, it will show up as 0ns. | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | 8 | Message-id: 20210212184902.1251044-15-richard.henderson@linaro.org | |
11 | Replace nanosecond periods traces with frequencies in the Hz unit | ||
12 | to have more dynamic range in the trace output. | ||
13 | |||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
16 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
17 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
18 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 10 | --- |
21 | hw/core/clock.c | 6 +++--- | 11 | linux-user/qemu.h | 9 +++------ |
22 | hw/core/trace-events | 4 ++-- | 12 | 1 file changed, 3 insertions(+), 6 deletions(-) |
23 | 2 files changed, 5 insertions(+), 5 deletions(-) | ||
24 | 13 | ||
25 | diff --git a/hw/core/clock.c b/hw/core/clock.c | 14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
26 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/core/clock.c | 16 | --- a/linux-user/qemu.h |
28 | +++ b/hw/core/clock.c | 17 | +++ b/linux-user/qemu.h |
29 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) | 18 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; |
30 | if (clk->period == period) { | 19 | |
20 | static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
21 | { | ||
22 | - if (!guest_addr_valid(addr)) { | ||
23 | - return false; | ||
24 | - } | ||
25 | - if (size != 0 && | ||
26 | - (addr + size - 1 < addr || | ||
27 | - !guest_addr_valid(addr + size - 1))) { | ||
28 | + if (size == 0 | ||
29 | + ? !guest_addr_valid(addr) | ||
30 | + : !guest_range_valid(addr, size)) { | ||
31 | return false; | 31 | return false; |
32 | } | 32 | } |
33 | - trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period), | 33 | return page_check_range((target_ulong)addr, size, type) == 0; |
34 | - CLOCK_PERIOD_TO_NS(period)); | ||
35 | + trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period), | ||
36 | + CLOCK_PERIOD_TO_HZ(period)); | ||
37 | clk->period = period; | ||
38 | |||
39 | return true; | ||
40 | @@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks) | ||
41 | if (child->period != clk->period) { | ||
42 | child->period = clk->period; | ||
43 | trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk), | ||
44 | - CLOCK_PERIOD_TO_NS(clk->period), | ||
45 | + CLOCK_PERIOD_TO_HZ(clk->period), | ||
46 | call_callbacks); | ||
47 | if (call_callbacks && child->callback) { | ||
48 | child->callback(child->callback_opaque); | ||
49 | diff --git a/hw/core/trace-events b/hw/core/trace-events | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/hw/core/trace-events | ||
52 | +++ b/hw/core/trace-events | ||
53 | @@ -XXX,XX +XXX,XX @@ resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" | ||
54 | # clock.c | ||
55 | clock_set_source(const char *clk, const char *src) "'%s', src='%s'" | ||
56 | clock_disconnect(const char *clk) "'%s'" | ||
57 | -clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64 | ||
58 | +clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz" | ||
59 | clock_propagate(const char *clk) "'%s'" | ||
60 | -clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d" | ||
61 | +clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d" | ||
62 | -- | 34 | -- |
63 | 2.20.1 | 35 | 2.20.1 |
64 | 36 | ||
65 | 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 | This is a bit clearer than open-coding some of this | 3 | The places that use these are better off using untagged |
4 | with a bare c string. | 4 | addresses, so do not provide a tagged versions. Rename |
5 | to make it clear about the address type. | ||
5 | 6 | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20201021173749.111103-9-richard.henderson@linaro.org | 9 | Message-id: 20210212184902.1251044-16-richard.henderson@linaro.org |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 11 | --- |
11 | linux-user/elfload.c | 37 ++++++++++++++++++++----------------- | 12 | include/exec/cpu_ldst.h | 4 ++-- |
12 | 1 file changed, 20 insertions(+), 17 deletions(-) | 13 | linux-user/qemu.h | 4 ++-- |
14 | accel/tcg/user-exec.c | 3 ++- | ||
15 | linux-user/mmap.c | 14 +++++++------- | ||
16 | linux-user/syscall.c | 2 +- | ||
17 | 5 files changed, 14 insertions(+), 13 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 19 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/elfload.c | 21 | --- a/include/exec/cpu_ldst.h |
17 | +++ b/linux-user/elfload.c | 22 | +++ b/include/exec/cpu_ldst.h |
18 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ static inline void *g2h(CPUState *cs, abi_ptr x) |
19 | #include "qemu/guest-random.h" | 24 | return g2h_untagged(cpu_untagged_addr(cs, x)); |
20 | #include "qemu/units.h" | 25 | } |
21 | #include "qemu/selfmap.h" | 26 | |
22 | +#include "qapi/error.h" | 27 | -static inline bool guest_addr_valid(abi_ulong x) |
23 | 28 | +static inline bool guest_addr_valid_untagged(abi_ulong x) | |
24 | #ifdef _ARCH_PPC64 | 29 | { |
25 | #undef ARCH_DLINFO | 30 | return x <= GUEST_ADDR_MAX; |
26 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 31 | } |
27 | struct elf_phdr *phdr; | 32 | |
28 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; | 33 | -static inline bool guest_range_valid(abi_ulong start, abi_ulong len) |
29 | int i, retval; | 34 | +static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len) |
30 | - const char *errmsg; | 35 | { |
31 | + Error *err = NULL; | 36 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
32 | 37 | } | |
33 | /* First of all, some simple consistency checks */ | 38 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
34 | - errmsg = "Invalid ELF image for this architecture"; | 39 | index XXXXXXX..XXXXXXX 100644 |
35 | if (!elf_check_ident(ehdr)) { | 40 | --- a/linux-user/qemu.h |
36 | + error_setg(&err, "Invalid ELF image for this architecture"); | 41 | +++ b/linux-user/qemu.h |
37 | goto exit_errmsg; | 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; | ||
38 | } | 51 | } |
39 | bswap_ehdr(ehdr); | 52 | return page_check_range((target_ulong)addr, size, type) == 0; |
40 | if (!elf_check_ehdr(ehdr)) { | 53 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c |
41 | + error_setg(&err, "Invalid ELF image for this architecture"); | 54 | index XXXXXXX..XXXXXXX 100644 |
42 | goto exit_errmsg; | 55 | --- a/accel/tcg/user-exec.c |
56 | +++ b/accel/tcg/user-exec.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | ||
58 | g_assert_not_reached(); | ||
43 | } | 59 | } |
44 | 60 | ||
45 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 61 | - if (!guest_addr_valid(addr) || page_check_range(addr, 1, flags) < 0) { |
46 | g_autofree char *interp_name = NULL; | 62 | + if (!guest_addr_valid_untagged(addr) || |
47 | 63 | + page_check_range(addr, 1, flags) < 0) { | |
48 | if (*pinterp_name) { | 64 | if (nonfault) { |
49 | - errmsg = "Multiple PT_INTERP entries"; | 65 | return TLB_INVALID_MASK; |
50 | + error_setg(&err, "Multiple PT_INTERP entries"); | 66 | } else { |
51 | goto exit_errmsg; | 67 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
52 | } | 68 | index XXXXXXX..XXXXXXX 100644 |
53 | + | 69 | --- a/linux-user/mmap.c |
54 | interp_name = g_malloc(eppnt->p_filesz); | 70 | +++ b/linux-user/mmap.c |
55 | - if (!interp_name) { | 71 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) |
56 | - goto exit_perror; | ||
57 | - } | ||
58 | |||
59 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
60 | memcpy(interp_name, bprm_buf + eppnt->p_offset, | ||
61 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
62 | retval = pread(image_fd, interp_name, eppnt->p_filesz, | ||
63 | eppnt->p_offset); | ||
64 | if (retval != eppnt->p_filesz) { | ||
65 | - goto exit_perror; | ||
66 | + goto exit_read; | ||
67 | } | ||
68 | } | ||
69 | if (interp_name[eppnt->p_filesz - 1] != 0) { | ||
70 | - errmsg = "Invalid PT_INTERP entry"; | ||
71 | + error_setg(&err, "Invalid PT_INTERP entry"); | ||
72 | goto exit_errmsg; | ||
73 | } | ||
74 | *pinterp_name = g_steal_pointer(&interp_name); | ||
75 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
76 | (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), | ||
77 | -1, 0); | ||
78 | if (load_addr == -1) { | ||
79 | - goto exit_perror; | ||
80 | + goto exit_mmap; | ||
81 | } | 72 | } |
82 | load_bias = load_addr - loaddr; | 73 | len = TARGET_PAGE_ALIGN(len); |
83 | 74 | end = start + len; | |
84 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 75 | - if (!guest_range_valid(start, len)) { |
85 | image_fd, eppnt->p_offset - vaddr_po); | 76 | + if (!guest_range_valid_untagged(start, len)) { |
86 | 77 | return -TARGET_ENOMEM; | |
87 | if (error == -1) { | ||
88 | - goto exit_perror; | ||
89 | + goto exit_mmap; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
94 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
95 | Mips_elf_abiflags_v0 abiflags; | ||
96 | if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { | ||
97 | - errmsg = "Invalid PT_MIPS_ABIFLAGS entry"; | ||
98 | + error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); | ||
99 | goto exit_errmsg; | ||
100 | } | ||
101 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
102 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
103 | retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), | ||
104 | eppnt->p_offset); | ||
105 | if (retval != sizeof(Mips_elf_abiflags_v0)) { | ||
106 | - goto exit_perror; | ||
107 | + goto exit_read; | ||
108 | } | ||
109 | } | ||
110 | bswap_mips_abiflags(&abiflags); | ||
111 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
112 | |||
113 | exit_read: | ||
114 | if (retval >= 0) { | ||
115 | - errmsg = "Incomplete read of file header"; | ||
116 | - goto exit_errmsg; | ||
117 | + error_setg(&err, "Incomplete read of file header"); | ||
118 | + } else { | ||
119 | + error_setg_errno(&err, errno, "Error reading file header"); | ||
120 | } | 78 | } |
121 | - exit_perror: | 79 | if (len == 0) { |
122 | - errmsg = strerror(errno); | 80 | @@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, |
123 | + goto exit_errmsg; | 81 | * It can fail only on 64-bit host with 32-bit target. |
124 | + exit_mmap: | 82 | * On any other target/host host mmap() handles this error correctly. |
125 | + error_setg_errno(&err, errno, "Error mapping file"); | 83 | */ |
126 | + goto exit_errmsg; | 84 | - if (end < start || !guest_range_valid(start, len)) { |
127 | exit_errmsg: | 85 | + if (end < start || !guest_range_valid_untagged(start, len)) { |
128 | - fprintf(stderr, "%s: %s\n", image_name, errmsg); | 86 | errno = ENOMEM; |
129 | + error_reportf_err(err, "%s: ", image_name); | 87 | goto fail; |
130 | exit(-1); | 88 | } |
131 | } | 89 | @@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len) |
90 | if (start & ~TARGET_PAGE_MASK) | ||
91 | return -TARGET_EINVAL; | ||
92 | len = TARGET_PAGE_ALIGN(len); | ||
93 | - if (len == 0 || !guest_range_valid(start, len)) { | ||
94 | + if (len == 0 || !guest_range_valid_untagged(start, len)) { | ||
95 | return -TARGET_EINVAL; | ||
96 | } | ||
97 | |||
98 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
99 | int prot; | ||
100 | void *host_addr; | ||
101 | |||
102 | - if (!guest_range_valid(old_addr, old_size) || | ||
103 | + if (!guest_range_valid_untagged(old_addr, old_size) || | ||
104 | ((flags & MREMAP_FIXED) && | ||
105 | - !guest_range_valid(new_addr, new_size)) || | ||
106 | + !guest_range_valid_untagged(new_addr, new_size)) || | ||
107 | ((flags & MREMAP_MAYMOVE) == 0 && | ||
108 | - !guest_range_valid(old_addr, new_size))) { | ||
109 | + !guest_range_valid_untagged(old_addr, new_size))) { | ||
110 | errno = ENOMEM; | ||
111 | return -1; | ||
112 | } | ||
113 | @@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, | ||
114 | |||
115 | if (host_addr != MAP_FAILED) { | ||
116 | /* Check if address fits target address space */ | ||
117 | - if (!guest_range_valid(h2g(host_addr), new_size)) { | ||
118 | + if (!guest_range_valid_untagged(h2g(host_addr), new_size)) { | ||
119 | /* Revert mremap() changes */ | ||
120 | host_addr = mremap(g2h_untagged(old_addr), | ||
121 | new_size, old_size, flags); | ||
122 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/linux-user/syscall.c | ||
125 | +++ b/linux-user/syscall.c | ||
126 | @@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, | ||
127 | return -TARGET_EINVAL; | ||
128 | } | ||
129 | } | ||
130 | - if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) { | ||
131 | + if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) { | ||
132 | return -TARGET_EINVAL; | ||
133 | } | ||
132 | 134 | ||
133 | -- | 135 | -- |
134 | 2.20.1 | 136 | 2.20.1 |
135 | 137 | ||
136 | 138 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This is slightly clearer than just using strerror, though | 3 | Provide both tagged and untagged versions of access_ok. |
4 | the different forms produced by error_setg_file_open and | 4 | In a few places use thread_cpu, as the user is several |
5 | error_setg_errno isn't entirely convenient. | 5 | callees removed from do_syscall1. |
6 | 6 | ||
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: 20201021173749.111103-10-richard.henderson@linaro.org | 9 | Message-id: 20210212184902.1251044-17-richard.henderson@linaro.org |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | linux-user/elfload.c | 15 ++++++++------- | 12 | linux-user/qemu.h | 11 +++++++++-- |
13 | 1 file changed, 8 insertions(+), 7 deletions(-) | 13 | linux-user/elfload.c | 2 +- |
14 | linux-user/hppa/cpu_loop.c | 8 ++++---- | ||
15 | linux-user/i386/cpu_loop.c | 2 +- | ||
16 | linux-user/i386/signal.c | 5 +++-- | ||
17 | linux-user/syscall.c | 9 ++++++--- | ||
18 | 6 files changed, 24 insertions(+), 13 deletions(-) | ||
14 | 19 | ||
20 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/linux-user/qemu.h | ||
23 | +++ b/linux-user/qemu.h | ||
24 | @@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size; | ||
25 | #define VERIFY_READ PAGE_READ | ||
26 | #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) | ||
27 | |||
28 | -static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
29 | +static inline bool access_ok_untagged(int type, abi_ulong addr, abi_ulong size) | ||
30 | { | ||
31 | if (size == 0 | ||
32 | ? !guest_addr_valid_untagged(addr) | ||
33 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size) | ||
34 | return page_check_range((target_ulong)addr, size, type) == 0; | ||
35 | } | ||
36 | |||
37 | +static inline bool access_ok(CPUState *cpu, int type, | ||
38 | + abi_ulong addr, abi_ulong size) | ||
39 | +{ | ||
40 | + return access_ok_untagged(type, cpu_untagged_addr(cpu, addr), size); | ||
41 | +} | ||
42 | + | ||
43 | /* NOTE __get_user and __put_user use host pointers and don't check access. | ||
44 | These are usually used to access struct data members once the struct has | ||
45 | been locked - usually with lock_user_struct. */ | ||
46 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); | ||
47 | host area will have the same contents as the guest. */ | ||
48 | static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
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; | ||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 57 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
16 | index XXXXXXX..XXXXXXX 100644 | 58 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/linux-user/elfload.c | 59 | --- a/linux-user/elfload.c |
18 | +++ b/linux-user/elfload.c | 60 | +++ b/linux-user/elfload.c |
19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info, | 61 | @@ -XXX,XX +XXX,XX @@ static int vma_get_mapping_count(const struct mm_struct *mm) |
20 | char bprm_buf[BPRM_BUF_SIZE]) | 62 | static abi_ulong vma_dump_size(const struct vm_area_struct *vma) |
21 | { | 63 | { |
22 | int fd, retval; | 64 | /* if we cannot even read the first page, skip it */ |
23 | + Error *err = NULL; | 65 | - if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) |
24 | 66 | + if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE)) | |
25 | fd = open(path(filename), O_RDONLY); | 67 | return (0); |
26 | if (fd < 0) { | 68 | |
27 | - goto exit_perror; | 69 | /* |
28 | + error_setg_file_open(&err, errno, filename); | 70 | diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c |
29 | + error_report_err(err); | 71 | index XXXXXXX..XXXXXXX 100644 |
30 | + exit(-1); | 72 | --- a/linux-user/hppa/cpu_loop.c |
73 | +++ b/linux-user/hppa/cpu_loop.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
75 | return -TARGET_ENOSYS; | ||
76 | |||
77 | case 0: /* elf32 atomic 32bit cmpxchg */ | ||
78 | - if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) { | ||
79 | + if ((addr & 3) || !access_ok(cs, VERIFY_WRITE, addr, 4)) { | ||
80 | return -TARGET_EFAULT; | ||
81 | } | ||
82 | old = tswap32(old); | ||
83 | @@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env) | ||
84 | return -TARGET_ENOSYS; | ||
85 | } | ||
86 | if (((addr | old | new) & ((1 << size) - 1)) | ||
87 | - || !access_ok(VERIFY_WRITE, addr, 1 << size) | ||
88 | - || !access_ok(VERIFY_READ, old, 1 << size) | ||
89 | - || !access_ok(VERIFY_READ, new, 1 << size)) { | ||
90 | + || !access_ok(cs, VERIFY_WRITE, addr, 1 << size) | ||
91 | + || !access_ok(cs, VERIFY_READ, old, 1 << size) | ||
92 | + || !access_ok(cs, VERIFY_READ, new, 1 << size)) { | ||
93 | return -TARGET_EFAULT; | ||
94 | } | ||
95 | /* Note that below we use host-endian loads so that the cmpxchg | ||
96 | diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/linux-user/i386/cpu_loop.c | ||
99 | +++ b/linux-user/i386/cpu_loop.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len) | ||
101 | * For all the vsyscalls, NULL means "don't write anything" not | ||
102 | * "write it at address 0". | ||
103 | */ | ||
104 | - if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) { | ||
105 | + if (addr == 0 || access_ok(env_cpu(env), VERIFY_WRITE, addr, len)) { | ||
106 | return true; | ||
31 | } | 107 | } |
32 | 108 | ||
33 | retval = read(fd, bprm_buf, BPRM_BUF_SIZE); | 109 | diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c |
34 | if (retval < 0) { | 110 | index XXXXXXX..XXXXXXX 100644 |
35 | - goto exit_perror; | 111 | --- a/linux-user/i386/signal.c |
36 | + error_setg_errno(&err, errno, "Error reading file header"); | 112 | +++ b/linux-user/i386/signal.c |
37 | + error_reportf_err(err, "%s: ", filename); | 113 | @@ -XXX,XX +XXX,XX @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc) |
38 | + exit(-1); | 114 | |
115 | fpstate_addr = tswapl(sc->fpstate); | ||
116 | if (fpstate_addr != 0) { | ||
117 | - if (!access_ok(VERIFY_READ, fpstate_addr, | ||
118 | - sizeof(struct target_fpstate))) | ||
119 | + if (!access_ok(env_cpu(env), VERIFY_READ, fpstate_addr, | ||
120 | + sizeof(struct target_fpstate))) { | ||
121 | goto badframe; | ||
122 | + } | ||
123 | #ifndef TARGET_X86_64 | ||
124 | cpu_x86_frstor(env, fpstate_addr, 1); | ||
125 | #else | ||
126 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/linux-user/syscall.c | ||
129 | +++ b/linux-user/syscall.c | ||
130 | @@ -XXX,XX +XXX,XX @@ static abi_long do_accept4(int fd, abi_ulong target_addr, | ||
131 | return -TARGET_EINVAL; | ||
39 | } | 132 | } |
40 | + | 133 | |
41 | if (retval < BPRM_BUF_SIZE) { | 134 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
42 | memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); | 135 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { |
136 | return -TARGET_EFAULT; | ||
137 | + } | ||
138 | |||
139 | addr = alloca(addrlen); | ||
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, | ||
142 | return -TARGET_EINVAL; | ||
43 | } | 143 | } |
44 | 144 | ||
45 | load_elf_image(filename, fd, info, NULL, bprm_buf); | 145 | - if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
46 | - return; | 146 | + if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) { |
47 | - | 147 | return -TARGET_EFAULT; |
48 | - exit_perror: | 148 | + } |
49 | - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); | 149 | |
50 | - exit(-1); | 150 | addr = alloca(addrlen); |
51 | } | 151 | |
52 | 152 | @@ -XXX,XX +XXX,XX @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, | |
53 | static int symfind(const void *s0, const void *s1) | 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 | |||
54 | -- | 163 | -- |
55 | 2.20.1 | 164 | 2.20.1 |
56 | 165 | ||
57 | 166 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and | 3 | These functions are not small, except for unlock_user |
4 | a divider. The prescaler doubles the parent (xosc) frequency, then the | 4 | without debugging enabled. Move them out of line, and |
5 | multiplier/divider are applied. The multiplier has an integer and a | 5 | add missing braces on the way. |
6 | fractional part. | ||
7 | 6 | ||
8 | This commit also implements the CPRMAN CM_LOCK register. This register | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | reports which PLL is currently locked. We consider a PLL has being | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | locked as soon as it is enabled (on real hardware, there is a delay | ||
11 | after turning a PLL on, for it to stabilize). | ||
12 | |||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 10 | Message-id: 20210212184902.1251044-18-richard.henderson@linaro.org |
15 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 11 | [PMM: fixed the sense of an ifdef test in qemu.h] |
16 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 13 | --- |
19 | include/hw/misc/bcm2835_cprman_internals.h | 8 +++ | 14 | linux-user/qemu.h | 47 +++++++------------------------------------- |
20 | hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- | 15 | linux-user/uaccess.c | 46 +++++++++++++++++++++++++++++++++++++++++++ |
21 | 2 files changed, 71 insertions(+), 1 deletion(-) | 16 | 2 files changed, 53 insertions(+), 40 deletions(-) |
22 | 17 | ||
23 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | 18 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
24 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 20 | --- a/linux-user/qemu.h |
26 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 21 | +++ b/linux-user/qemu.h |
27 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) | 22 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
28 | REG32(A2W_PLLH_FRAC, 0x1260) | 23 | |
29 | REG32(A2W_PLLB_FRAC, 0x12e0) | 24 | /* Lock an area of guest memory into the host. If copy is true then the |
30 | 25 | host area will have the same contents as the guest. */ | |
31 | +/* misc registers */ | 26 | -static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
32 | +REG32(CM_LOCK, 0x114) | 27 | -{ |
33 | + FIELD(CM_LOCK, FLOCKH, 12, 1) | 28 | - if (!access_ok_untagged(type, guest_addr, len)) { |
34 | + FIELD(CM_LOCK, FLOCKD, 11, 1) | 29 | - return NULL; |
35 | + FIELD(CM_LOCK, FLOCKC, 10, 1) | 30 | - } |
36 | + FIELD(CM_LOCK, FLOCKB, 9, 1) | 31 | -#ifdef DEBUG_REMAP |
37 | + FIELD(CM_LOCK, FLOCKA, 8, 1) | 32 | - { |
38 | + | 33 | - void *addr; |
39 | /* | 34 | - addr = g_malloc(len); |
40 | * This field is common to all registers. Each register write value must match | 35 | - if (copy) |
41 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | 36 | - memcpy(addr, g2h(guest_addr), len); |
42 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 37 | - else |
38 | - memset(addr, 0, len); | ||
39 | - return addr; | ||
40 | - } | ||
41 | -#else | ||
42 | - return g2h_untagged(guest_addr); | ||
43 | -#endif | ||
44 | -} | ||
45 | +void *lock_user(int type, abi_ulong guest_addr, long len, int copy); | ||
46 | |||
47 | /* Unlock an area of guest memory. The first LEN bytes must be | ||
48 | flushed back to guest memory. host_ptr = NULL is explicitly | ||
49 | allowed and does nothing. */ | ||
50 | -static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, | ||
51 | - long len) | ||
52 | -{ | ||
53 | - | ||
54 | -#ifdef DEBUG_REMAP | ||
55 | - if (!host_ptr) | ||
56 | - return; | ||
57 | - if (host_ptr == g2h_untagged(guest_addr)) | ||
58 | - return; | ||
59 | - if (len > 0) | ||
60 | - memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
61 | - g_free(host_ptr); | ||
62 | +#ifndef DEBUG_REMAP | ||
63 | +static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len) | ||
64 | +{ } | ||
65 | +#else | ||
66 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); | ||
67 | #endif | ||
68 | -} | ||
69 | |||
70 | /* Return the length of a string in target memory or -TARGET_EFAULT if | ||
71 | access error. */ | ||
72 | abi_long target_strlen(abi_ulong gaddr); | ||
73 | |||
74 | /* Like lock_user but for null terminated strings. */ | ||
75 | -static inline void *lock_user_string(abi_ulong guest_addr) | ||
76 | -{ | ||
77 | - abi_long len; | ||
78 | - len = target_strlen(guest_addr); | ||
79 | - if (len < 0) | ||
80 | - return NULL; | ||
81 | - return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); | ||
82 | -} | ||
83 | +void *lock_user_string(abi_ulong guest_addr); | ||
84 | |||
85 | /* Helper macros for locking/unlocking a target struct. */ | ||
86 | #define lock_user_struct(type, host_ptr, guest_addr, copy) \ | ||
87 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | 88 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/hw/misc/bcm2835_cprman.c | 89 | --- a/linux-user/uaccess.c |
45 | +++ b/hw/misc/bcm2835_cprman.c | 90 | +++ b/linux-user/uaccess.c |
46 | @@ -XXX,XX +XXX,XX @@ | 91 | @@ -XXX,XX +XXX,XX @@ |
47 | 92 | ||
48 | /* PLL */ | 93 | #include "qemu.h" |
49 | 94 | ||
50 | +static bool pll_is_locked(const CprmanPllState *pll) | 95 | +void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
51 | +{ | 96 | +{ |
52 | + return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) | 97 | + if (!access_ok_untagged(type, guest_addr, len)) { |
53 | + && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); | 98 | + return NULL; |
99 | + } | ||
100 | +#ifdef DEBUG_REMAP | ||
101 | + { | ||
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 | ||
54 | +} | 114 | +} |
55 | + | 115 | + |
56 | static void pll_update(CprmanPllState *pll) | 116 | +#ifdef DEBUG_REMAP |
57 | { | 117 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
58 | - clock_update(pll->out, 0); | 118 | +{ |
59 | + uint64_t freq, ndiv, fdiv, pdiv; | 119 | + if (!host_ptr) { |
60 | + | ||
61 | + if (!pll_is_locked(pll)) { | ||
62 | + clock_update(pll->out, 0); | ||
63 | + return; | 120 | + return; |
64 | + } | 121 | + } |
65 | + | 122 | + if (host_ptr == g2h_untagged(guest_addr)) { |
66 | + pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); | ||
67 | + | ||
68 | + if (!pdiv) { | ||
69 | + clock_update(pll->out, 0); | ||
70 | + return; | 123 | + return; |
71 | + } | 124 | + } |
125 | + if (len > 0) { | ||
126 | + memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
127 | + } | ||
128 | + g_free(host_ptr); | ||
129 | +} | ||
130 | +#endif | ||
72 | + | 131 | + |
73 | + ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); | 132 | +void *lock_user_string(abi_ulong guest_addr) |
74 | + fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC); | 133 | +{ |
75 | + | 134 | + abi_long len = target_strlen(guest_addr); |
76 | + if (pll->reg_a2w_ana[1] & pll->prediv_mask) { | 135 | + if (len < 0) { |
77 | + /* The prescaler doubles the parent frequency */ | 136 | + return NULL; |
78 | + ndiv *= 2; | ||
79 | + fdiv *= 2; | ||
80 | + } | 137 | + } |
81 | + | 138 | + return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
82 | + /* | ||
83 | + * We have a multiplier with an integer part (ndiv) and a fractional part | ||
84 | + * (fdiv), and a divider (pdiv). | ||
85 | + */ | ||
86 | + freq = clock_get_hz(pll->xosc_in) * | ||
87 | + ((ndiv << R_A2W_PLLx_FRAC_FRAC_LENGTH) + fdiv); | ||
88 | + freq /= pdiv; | ||
89 | + freq >>= R_A2W_PLLx_FRAC_FRAC_LENGTH; | ||
90 | + | ||
91 | + clock_update_hz(pll->out, freq); | ||
92 | } | ||
93 | |||
94 | static void pll_xosc_update(void *opaque) | ||
95 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | ||
96 | |||
97 | /* CPRMAN "top level" model */ | ||
98 | |||
99 | +static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
100 | +{ | ||
101 | + static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = { | ||
102 | + [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT, | ||
103 | + [CPRMAN_PLLC] = R_CM_LOCK_FLOCKC_SHIFT, | ||
104 | + [CPRMAN_PLLD] = R_CM_LOCK_FLOCKD_SHIFT, | ||
105 | + [CPRMAN_PLLH] = R_CM_LOCK_FLOCKH_SHIFT, | ||
106 | + [CPRMAN_PLLB] = R_CM_LOCK_FLOCKB_SHIFT, | ||
107 | + }; | ||
108 | + | ||
109 | + uint32_t r = 0; | ||
110 | + size_t i; | ||
111 | + | ||
112 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
113 | + r |= pll_is_locked(&s->plls[i]) << CM_LOCK_MAPPING[i]; | ||
114 | + } | ||
115 | + | ||
116 | + return r; | ||
117 | +} | 139 | +} |
118 | + | 140 | + |
119 | static uint64_t cprman_read(void *opaque, hwaddr offset, | 141 | /* copy_from_user() and copy_to_user() are usually used to copy data |
120 | unsigned size) | 142 | * buffers between the target and host. These internally perform |
121 | { | 143 | * locking/unlocking of the memory. |
122 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
123 | size_t idx = offset / sizeof(uint32_t); | ||
124 | |||
125 | switch (idx) { | ||
126 | + case R_CM_LOCK: | ||
127 | + r = get_cm_lock(s); | ||
128 | + break; | ||
129 | + | ||
130 | default: | ||
131 | r = s->regs[idx]; | ||
132 | } | ||
133 | -- | 144 | -- |
134 | 2.20.1 | 145 | 2.20.1 |
135 | 146 | ||
136 | 147 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Remove usage of TypeInfo::class_data. Instead fill the fields in | 3 | For copy_*_user, only 0 and -TARGET_EFAULT are returned; no need |
4 | the corresponding class_init(). | 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. | ||
5 | 7 | ||
6 | So far all children use the same values for almost all fields, | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | but we are going to add the BCM2711/BCM2838 SoC for the raspi4 | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | machine which use different fields. | 10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | 11 | Message-id: 20210212184902.1251044-19-richard.henderson@linaro.org | |
10 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | 12 | [PMM: moved fix for ifdef error to previous commit] |
11 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Message-id: 20201024170127.3592182-3-f4bug@amsat.org | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 14 | --- |
15 | hw/arm/bcm2836.c | 108 ++++++++++++++++++++++------------------------- | 15 | linux-user/qemu.h | 12 +++++------- |
16 | 1 file changed, 51 insertions(+), 57 deletions(-) | 16 | linux-user/uaccess.c | 45 ++++++++++++++++++++++---------------------- |
17 | 2 files changed, 28 insertions(+), 29 deletions(-) | ||
17 | 18 | ||
18 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | 19 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/arm/bcm2836.c | 21 | --- a/linux-user/qemu.h |
21 | +++ b/hw/arm/bcm2836.c | 22 | +++ b/linux-user/qemu.h |
22 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ |
23 | #include "hw/arm/raspi_platform.h" | 24 | #include "exec/cpu_ldst.h" |
24 | #include "hw/sysbus.h" | 25 | |
25 | 26 | #undef DEBUG_REMAP | |
26 | -typedef struct BCM283XInfo BCM283XInfo; | 27 | -#ifdef DEBUG_REMAP |
27 | - | 28 | -#endif /* DEBUG_REMAP */ |
28 | typedef struct BCM283XClass { | 29 | |
29 | /*< private >*/ | 30 | #include "exec/user/abitypes.h" |
30 | DeviceClass parent_class; | 31 | |
31 | /*< public >*/ | 32 | @@ -XXX,XX +XXX,XX @@ static inline bool access_ok(CPUState *cpu, int type, |
32 | - const BCM283XInfo *info; | 33 | * buffers between the target and host. These internally perform |
33 | -} BCM283XClass; | 34 | * locking/unlocking of the memory. |
34 | - | 35 | */ |
35 | -struct BCM283XInfo { | 36 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len); |
36 | const char *name; | 37 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
37 | const char *cpu_type; | 38 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len); |
38 | hwaddr peri_base; /* Peripheral base address seen by the CPU */ | 39 | +int copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
39 | hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ | 40 | |
40 | int clusterid; | 41 | /* Functions for accessing guest memory. The tget and tput functions |
41 | -}; | 42 | read/write single values, byteswapping as necessary. The lock_user function |
42 | +} BCM283XClass; | 43 | @@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
43 | 44 | ||
44 | #define BCM283X_CLASS(klass) \ | 45 | /* Lock an area of guest memory into the host. If copy is true then the |
45 | OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) | 46 | host area will have the same contents as the guest. */ |
46 | #define BCM283X_GET_CLASS(obj) \ | 47 | -void *lock_user(int type, abi_ulong guest_addr, long len, int copy); |
47 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | 48 | +void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy); |
48 | 49 | ||
49 | -static const BCM283XInfo bcm283x_socs[] = { | 50 | /* Unlock an area of guest memory. The first LEN bytes must be |
50 | - { | 51 | flushed back to guest memory. host_ptr = NULL is explicitly |
51 | - .name = TYPE_BCM2836, | 52 | allowed and does nothing. */ |
52 | - .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"), | 53 | #ifndef DEBUG_REMAP |
53 | - .peri_base = 0x3f000000, | 54 | -static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len) |
54 | - .ctrl_base = 0x40000000, | 55 | +static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len) |
55 | - .clusterid = 0xf, | 56 | { } |
56 | - }, | 57 | #else |
57 | -#ifdef TARGET_AARCH64 | 58 | void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
58 | - { | 59 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
59 | - .name = TYPE_BCM2837, | 60 | |
60 | - .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"), | 61 | /* Return the length of a string in target memory or -TARGET_EFAULT if |
61 | - .peri_base = 0x3f000000, | 62 | access error. */ |
62 | - .ctrl_base = 0x40000000, | 63 | -abi_long target_strlen(abi_ulong gaddr); |
63 | - .clusterid = 0x0, | 64 | +ssize_t target_strlen(abi_ulong gaddr); |
64 | - }, | 65 | |
65 | -#endif | 66 | /* Like lock_user but for null terminated strings. */ |
66 | -}; | 67 | void *lock_user_string(abi_ulong guest_addr); |
67 | - | 68 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c |
68 | static void bcm2836_init(Object *obj) | 69 | index XXXXXXX..XXXXXXX 100644 |
70 | --- a/linux-user/uaccess.c | ||
71 | +++ b/linux-user/uaccess.c | ||
72 | @@ -XXX,XX +XXX,XX @@ | ||
73 | |||
74 | #include "qemu.h" | ||
75 | |||
76 | -void *lock_user(int type, abi_ulong guest_addr, long len, int copy) | ||
77 | +void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) | ||
69 | { | 78 | { |
70 | BCM283XState *s = BCM283X(obj); | 79 | if (!access_ok_untagged(type, guest_addr, len)) { |
71 | BCM283XClass *bc = BCM283X_GET_CLASS(obj); | 80 | return NULL; |
72 | - const BCM283XInfo *info = bc->info; | 81 | @@ -XXX,XX +XXX,XX @@ void *lock_user(int type, abi_ulong guest_addr, long len, int copy) |
73 | int n; | 82 | } |
74 | 83 | ||
75 | for (n = 0; n < BCM283X_NCPUS; n++) { | 84 | #ifdef DEBUG_REMAP |
76 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, | 85 | -void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
77 | - info->cpu_type); | 86 | +void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); |
78 | + bc->cpu_type); | ||
79 | } | ||
80 | |||
81 | object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
83 | { | 87 | { |
84 | BCM283XState *s = BCM283X(dev); | 88 | if (!host_ptr) { |
85 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); | 89 | return; |
86 | - const BCM283XInfo *info = bc->info; | 90 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
87 | Object *obj; | 91 | if (host_ptr == g2h_untagged(guest_addr)) { |
88 | int n; | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
91 | "sd-bus"); | ||
92 | |||
93 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
94 | - info->peri_base, 1); | ||
95 | + bc->peri_base, 1); | ||
96 | |||
97 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
98 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { | ||
99 | return; | 92 | return; |
100 | } | 93 | } |
101 | 94 | - if (len > 0) { | |
102 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base); | 95 | + if (len != 0) { |
103 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base); | 96 | memcpy(g2h_untagged(guest_addr), host_ptr, len); |
104 | 97 | } | |
105 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, | 98 | g_free(host_ptr); |
106 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0)); | 99 | @@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len); |
107 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | 100 | |
108 | 101 | void *lock_user_string(abi_ulong guest_addr) | |
109 | for (n = 0; n < BCM283X_NCPUS; n++) { | ||
110 | /* TODO: this should be converted to a property of ARM_CPU */ | ||
111 | - s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n; | ||
112 | + s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n; | ||
113 | |||
114 | /* set periphbase/CBAR value for CPU-local registers */ | ||
115 | if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar", | ||
116 | - info->peri_base, errp)) { | ||
117 | + bc->peri_base, errp)) { | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | @@ -XXX,XX +XXX,XX @@ static Property bcm2836_props[] = { | ||
122 | static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
123 | { | 102 | { |
124 | DeviceClass *dc = DEVICE_CLASS(oc); | 103 | - abi_long len = target_strlen(guest_addr); |
125 | - BCM283XClass *bc = BCM283X_CLASS(oc); | 104 | + ssize_t len = target_strlen(guest_addr); |
126 | 105 | if (len < 0) { | |
127 | - bc->info = data; | 106 | return NULL; |
128 | - dc->realize = bcm2836_realize; | 107 | } |
129 | - device_class_set_props(dc, bcm2836_props); | 108 | - return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
130 | /* Reason: Must be wired up in code (see raspi_init() function) */ | 109 | + return lock_user(VERIFY_READ, guest_addr, (size_t)len + 1, 1); |
131 | dc->user_creatable = false; | ||
132 | } | 110 | } |
133 | 111 | ||
134 | -static const TypeInfo bcm283x_type_info = { | 112 | /* copy_from_user() and copy_to_user() are usually used to copy data |
135 | - .name = TYPE_BCM283X, | 113 | * buffers between the target and host. These internally perform |
136 | - .parent = TYPE_DEVICE, | 114 | * locking/unlocking of the memory. |
137 | - .instance_size = sizeof(BCM283XState), | 115 | */ |
138 | - .instance_init = bcm2836_init, | 116 | -abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len) |
139 | - .class_size = sizeof(BCM283XClass), | 117 | +int copy_from_user(void *hptr, abi_ulong gaddr, size_t len) |
140 | - .abstract = true, | ||
141 | +static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
142 | +{ | ||
143 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
144 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
145 | + | ||
146 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); | ||
147 | + bc->peri_base = 0x3f000000; | ||
148 | + bc->ctrl_base = 0x40000000; | ||
149 | + bc->clusterid = 0xf; | ||
150 | + dc->realize = bcm2836_realize; | ||
151 | + device_class_set_props(dc, bcm2836_props); | ||
152 | }; | ||
153 | |||
154 | -static void bcm2836_register_types(void) | ||
155 | +#ifdef TARGET_AARCH64 | ||
156 | +static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
157 | { | 118 | { |
158 | - int i; | 119 | - abi_long ret = 0; |
159 | + DeviceClass *dc = DEVICE_CLASS(oc); | 120 | - void *ghptr; |
160 | + BCM283XClass *bc = BCM283X_CLASS(oc); | 121 | + int ret = 0; |
161 | 122 | + void *ghptr = lock_user(VERIFY_READ, gaddr, len, 1); | |
162 | - type_register_static(&bcm283x_type_info); | 123 | |
163 | - for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) { | 124 | - if ((ghptr = lock_user(VERIFY_READ, gaddr, len, 1))) { |
164 | - TypeInfo ti = { | 125 | + if (ghptr) { |
165 | - .name = bcm283x_socs[i].name, | 126 | memcpy(hptr, ghptr, len); |
166 | - .parent = TYPE_BCM283X, | 127 | unlock_user(ghptr, gaddr, 0); |
167 | - .class_init = bcm283x_class_init, | 128 | - } else |
168 | - .class_data = (void *) &bcm283x_socs[i], | 129 | + } else { |
169 | - }; | 130 | ret = -TARGET_EFAULT; |
170 | - type_register(&ti); | 131 | - |
171 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | 132 | + } |
172 | + bc->peri_base = 0x3f000000; | 133 | return ret; |
173 | + bc->ctrl_base = 0x40000000; | 134 | } |
174 | + bc->clusterid = 0x0; | 135 | |
175 | + dc->realize = bcm2836_realize; | 136 | - |
176 | + device_class_set_props(dc, bcm2836_props); | 137 | -abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len) |
177 | +}; | 138 | +int copy_to_user(abi_ulong gaddr, void *hptr, size_t len) |
178 | +#endif | 139 | { |
179 | + | 140 | - abi_long ret = 0; |
180 | +static const TypeInfo bcm283x_types[] = { | 141 | - void *ghptr; |
181 | + { | 142 | + int ret = 0; |
182 | + .name = TYPE_BCM2836, | 143 | + void *ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0); |
183 | + .parent = TYPE_BCM283X, | 144 | |
184 | + .class_init = bcm2836_class_init, | 145 | - if ((ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0))) { |
185 | +#ifdef TARGET_AARCH64 | 146 | + if (ghptr) { |
186 | + }, { | 147 | memcpy(ghptr, hptr, len); |
187 | + .name = TYPE_BCM2837, | 148 | unlock_user(ghptr, gaddr, len); |
188 | + .parent = TYPE_BCM283X, | 149 | - } else |
189 | + .class_init = bcm2837_class_init, | 150 | + } else { |
190 | +#endif | 151 | ret = -TARGET_EFAULT; |
191 | + }, { | 152 | + } |
192 | + .name = TYPE_BCM283X, | 153 | |
193 | + .parent = TYPE_DEVICE, | 154 | return ret; |
194 | + .instance_size = sizeof(BCM283XState), | 155 | } |
195 | + .instance_init = bcm2836_init, | 156 | |
196 | + .class_size = sizeof(BCM283XClass), | 157 | /* Return the length of a string in target memory or -TARGET_EFAULT if |
197 | + .class_init = bcm283x_class_init, | 158 | access error */ |
198 | + .abstract = true, | 159 | -abi_long target_strlen(abi_ulong guest_addr1) |
160 | +ssize_t target_strlen(abi_ulong guest_addr1) | ||
161 | { | ||
162 | uint8_t *ptr; | ||
163 | abi_ulong guest_addr; | ||
164 | - int max_len, len; | ||
165 | + size_t max_len, len; | ||
166 | |||
167 | guest_addr = guest_addr1; | ||
168 | for(;;) { | ||
169 | @@ -XXX,XX +XXX,XX @@ abi_long target_strlen(abi_ulong guest_addr1) | ||
170 | unlock_user(ptr, guest_addr, 0); | ||
171 | guest_addr += len; | ||
172 | /* we don't allow wrapping or integer overflow */ | ||
173 | - if (guest_addr == 0 || | ||
174 | - (guest_addr - guest_addr1) > 0x7fffffff) | ||
175 | + if (guest_addr == 0 || (guest_addr - guest_addr1) > 0x7fffffff) { | ||
176 | return -TARGET_EFAULT; | ||
177 | - if (len != max_len) | ||
178 | + } | ||
179 | + if (len != max_len) { | ||
180 | break; | ||
181 | + } | ||
199 | } | 182 | } |
200 | -} | 183 | return guest_addr - guest_addr1; |
201 | +}; | 184 | } |
202 | |||
203 | -type_init(bcm2836_register_types) | ||
204 | +DEFINE_TYPES(bcm283x_types) | ||
205 | -- | 185 | -- |
206 | 2.20.1 | 186 | 2.20.1 |
207 | 187 | ||
208 | 188 | diff view generated by jsdifflib |
1 | The armv7m systick timer is a 24-bit decrementing, wrap-on-zero, | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | clear-on-write counter. Our current implementation has various | ||
3 | bugs and dubious workarounds in it (for instance see | ||
4 | https://bugs.launchpad.net/qemu/+bug/1872237). | ||
5 | 2 | ||
6 | We have an implementation of a simple decrementing counter | 3 | Resolve the untagged address once, using thread_cpu. |
7 | and we put a lot of effort into making sure it handles the | 4 | Tidy the DEBUG_REMAP code using glib routines. |
8 | interesting corner cases (like "spend a cycle at 0 before | ||
9 | reloading") -- ptimer. | ||
10 | 5 | ||
11 | Rewrite the systick timer to use a ptimer rather than | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
12 | a raw QEMU timer. | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20210212184902.1251044-20-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | linux-user/uaccess.c | 27 ++++++++++++++------------- | ||
12 | 1 file changed, 14 insertions(+), 13 deletions(-) | ||
13 | 13 | ||
14 | Unfortunately this is a migration compatibility break, | 14 | diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c |
15 | which will affect all M-profile boards. | ||
16 | |||
17 | Among other bugs, this fixes | ||
18 | https://bugs.launchpad.net/qemu/+bug/1872237 : | ||
19 | now writes to SYST_CVR when the timer is enabled correctly | ||
20 | do nothing; when the timer is enabled via SYST_CSR.ENABLE, | ||
21 | the ptimer code will (because of POLICY_NO_IMMEDIATE_RELOAD) | ||
22 | arrange that after one timer tick the counter is reloaded | ||
23 | from SYST_RVR and then counts down from there, as the | ||
24 | architecture requires. | ||
25 | |||
26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
27 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
28 | Message-id: 20201015151829.14656-3-peter.maydell@linaro.org | ||
29 | --- | ||
30 | include/hw/timer/armv7m_systick.h | 3 +- | ||
31 | hw/timer/armv7m_systick.c | 124 +++++++++++++----------------- | ||
32 | 2 files changed, 54 insertions(+), 73 deletions(-) | ||
33 | |||
34 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/include/hw/timer/armv7m_systick.h | 16 | --- a/linux-user/uaccess.c |
37 | +++ b/include/hw/timer/armv7m_systick.h | 17 | +++ b/linux-user/uaccess.c |
38 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ |
39 | 19 | ||
40 | #include "hw/sysbus.h" | 20 | void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy) |
41 | #include "qom/object.h" | 21 | { |
42 | +#include "hw/ptimer.h" | 22 | + void *host_addr; |
43 | 23 | + | |
44 | #define TYPE_SYSTICK "armv7m_systick" | 24 | + guest_addr = cpu_untagged_addr(thread_cpu, guest_addr); |
45 | 25 | if (!access_ok_untagged(type, guest_addr, len)) { | |
46 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { | 26 | return NULL; |
47 | uint32_t control; | ||
48 | uint32_t reload; | ||
49 | int64_t tick; | ||
50 | - QEMUTimer *timer; | ||
51 | + ptimer_state *ptimer; | ||
52 | MemoryRegion iomem; | ||
53 | qemu_irq irq; | ||
54 | }; | ||
55 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/hw/timer/armv7m_systick.c | ||
58 | +++ b/hw/timer/armv7m_systick.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s) | ||
60 | } | 27 | } |
28 | + host_addr = g2h_untagged(guest_addr); | ||
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; | ||
61 | } | 48 | } |
62 | 49 | ||
63 | -static void systick_reload(SysTickState *s, int reset) | 50 | #ifdef DEBUG_REMAP |
64 | -{ | 51 | void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len); |
65 | - /* The Cortex-M3 Devices Generic User Guide says that "When the | ||
66 | - * ENABLE bit is set to 1, the counter loads the RELOAD value from the | ||
67 | - * SYST RVR register and then counts down". So, we need to check the | ||
68 | - * ENABLE bit before reloading the value. | ||
69 | - */ | ||
70 | - trace_systick_reload(); | ||
71 | - | ||
72 | - if ((s->control & SYSTICK_ENABLE) == 0) { | ||
73 | - return; | ||
74 | - } | ||
75 | - | ||
76 | - if (reset) { | ||
77 | - s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
78 | - } | ||
79 | - s->tick += (s->reload + 1) * systick_scale(s); | ||
80 | - timer_mod(s->timer, s->tick); | ||
81 | -} | ||
82 | - | ||
83 | static void systick_timer_tick(void *opaque) | ||
84 | { | 52 | { |
85 | SysTickState *s = (SysTickState *)opaque; | 53 | + void *host_ptr_conv; |
86 | @@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque) | 54 | + |
87 | /* Tell the NVIC to pend the SysTick exception */ | 55 | if (!host_ptr) { |
88 | qemu_irq_pulse(s->irq); | 56 | return; |
89 | } | 57 | } |
90 | - if (s->reload == 0) { | 58 | - if (host_ptr == g2h_untagged(guest_addr)) { |
91 | - s->control &= ~SYSTICK_ENABLE; | 59 | + host_ptr_conv = g2h(thread_cpu, guest_addr); |
92 | - } else { | 60 | + if (host_ptr == host_ptr_conv) { |
93 | - systick_reload(s, 0); | 61 | return; |
94 | + if (ptimer_get_limit(s->ptimer) == 0) { | ||
95 | + /* | ||
96 | + * Timer expiry with SYST_RVR zero disables the timer | ||
97 | + * (but doesn't clear SYST_CSR.ENABLE) | ||
98 | + */ | ||
99 | + ptimer_stop(s->ptimer); | ||
100 | } | 62 | } |
63 | if (len != 0) { | ||
64 | - memcpy(g2h_untagged(guest_addr), host_ptr, len); | ||
65 | + memcpy(host_ptr_conv, host_ptr, len); | ||
66 | } | ||
67 | g_free(host_ptr); | ||
101 | } | 68 | } |
102 | |||
103 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data, | ||
104 | s->control &= ~SYSTICK_COUNTFLAG; | ||
105 | break; | ||
106 | case 0x4: /* SysTick Reload Value. */ | ||
107 | - val = s->reload; | ||
108 | + val = ptimer_get_limit(s->ptimer); | ||
109 | break; | ||
110 | case 0x8: /* SysTick Current Value. */ | ||
111 | - { | ||
112 | - int64_t t; | ||
113 | - | ||
114 | - if ((s->control & SYSTICK_ENABLE) == 0) { | ||
115 | - val = 0; | ||
116 | - break; | ||
117 | - } | ||
118 | - t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
119 | - if (t >= s->tick) { | ||
120 | - val = 0; | ||
121 | - break; | ||
122 | - } | ||
123 | - val = ((s->tick - (t + 1)) / systick_scale(s)) + 1; | ||
124 | - /* The interrupt in triggered when the timer reaches zero. | ||
125 | - However the counter is not reloaded until the next clock | ||
126 | - tick. This is a hack to return zero during the first tick. */ | ||
127 | - if (val > s->reload) { | ||
128 | - val = 0; | ||
129 | - } | ||
130 | + val = ptimer_get_count(s->ptimer); | ||
131 | break; | ||
132 | - } | ||
133 | case 0xc: /* SysTick Calibration Value. */ | ||
134 | val = 10000; | ||
135 | break; | ||
136 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr, | ||
137 | switch (addr) { | ||
138 | case 0x0: /* SysTick Control and Status. */ | ||
139 | { | ||
140 | - uint32_t oldval = s->control; | ||
141 | + uint32_t oldval; | ||
142 | |||
143 | + ptimer_transaction_begin(s->ptimer); | ||
144 | + oldval = s->control; | ||
145 | s->control &= 0xfffffff8; | ||
146 | s->control |= value & 7; | ||
147 | + | ||
148 | if ((oldval ^ value) & SYSTICK_ENABLE) { | ||
149 | - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
150 | if (value & SYSTICK_ENABLE) { | ||
151 | - if (s->tick) { | ||
152 | - s->tick += now; | ||
153 | - timer_mod(s->timer, s->tick); | ||
154 | - } else { | ||
155 | - systick_reload(s, 1); | ||
156 | - } | ||
157 | + /* | ||
158 | + * Always reload the period in case board code has | ||
159 | + * changed system_clock_scale. If we ever replace that | ||
160 | + * global with a more sensible API then we might be able | ||
161 | + * to set the period only when it actually changes. | ||
162 | + */ | ||
163 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
164 | + ptimer_run(s->ptimer, 0); | ||
165 | } else { | ||
166 | - timer_del(s->timer); | ||
167 | - s->tick -= now; | ||
168 | - if (s->tick < 0) { | ||
169 | - s->tick = 0; | ||
170 | - } | ||
171 | + ptimer_stop(s->ptimer); | ||
172 | } | ||
173 | } else if ((oldval ^ value) & SYSTICK_CLKSOURCE) { | ||
174 | - /* This is a hack. Force the timer to be reloaded | ||
175 | - when the reference clock is changed. */ | ||
176 | - systick_reload(s, 1); | ||
177 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
178 | } | ||
179 | + ptimer_transaction_commit(s->ptimer); | ||
180 | break; | ||
181 | } | ||
182 | case 0x4: /* SysTick Reload Value. */ | ||
183 | - s->reload = value; | ||
184 | + ptimer_transaction_begin(s->ptimer); | ||
185 | + ptimer_set_limit(s->ptimer, value & 0xffffff, 0); | ||
186 | + ptimer_transaction_commit(s->ptimer); | ||
187 | break; | ||
188 | - case 0x8: /* SysTick Current Value. Writes reload the timer. */ | ||
189 | - systick_reload(s, 1); | ||
190 | + case 0x8: /* SysTick Current Value. */ | ||
191 | + /* | ||
192 | + * Writing any value clears SYST_CVR to zero and clears | ||
193 | + * SYST_CSR.COUNTFLAG. The counter will then reload from SYST_RVR | ||
194 | + * on the next clock edge unless SYST_RVR is zero. | ||
195 | + */ | ||
196 | + ptimer_transaction_begin(s->ptimer); | ||
197 | + if (ptimer_get_limit(s->ptimer) == 0) { | ||
198 | + ptimer_stop(s->ptimer); | ||
199 | + } | ||
200 | + ptimer_set_count(s->ptimer, 0); | ||
201 | s->control &= ~SYSTICK_COUNTFLAG; | ||
202 | + ptimer_transaction_commit(s->ptimer); | ||
203 | break; | ||
204 | default: | ||
205 | qemu_log_mask(LOG_GUEST_ERROR, | ||
206 | @@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev) | ||
207 | */ | ||
208 | assert(system_clock_scale != 0); | ||
209 | |||
210 | + ptimer_transaction_begin(s->ptimer); | ||
211 | s->control = 0; | ||
212 | - s->reload = 0; | ||
213 | - s->tick = 0; | ||
214 | - timer_del(s->timer); | ||
215 | + ptimer_stop(s->ptimer); | ||
216 | + ptimer_set_count(s->ptimer, 0); | ||
217 | + ptimer_set_limit(s->ptimer, 0, 0); | ||
218 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
219 | + ptimer_transaction_commit(s->ptimer); | ||
220 | } | ||
221 | |||
222 | static void systick_instance_init(Object *obj) | ||
223 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | ||
224 | static void systick_realize(DeviceState *dev, Error **errp) | ||
225 | { | ||
226 | SysTickState *s = SYSTICK(dev); | ||
227 | - s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s); | ||
228 | + s->ptimer = ptimer_init(systick_timer_tick, s, | ||
229 | + PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD | | ||
230 | + PTIMER_POLICY_NO_COUNTER_ROUND_DOWN | | ||
231 | + PTIMER_POLICY_NO_IMMEDIATE_RELOAD | | ||
232 | + PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); | ||
233 | } | ||
234 | |||
235 | static const VMStateDescription vmstate_systick = { | ||
236 | .name = "armv7m_systick", | ||
237 | - .version_id = 1, | ||
238 | - .minimum_version_id = 1, | ||
239 | + .version_id = 2, | ||
240 | + .minimum_version_id = 2, | ||
241 | .fields = (VMStateField[]) { | ||
242 | VMSTATE_UINT32(control, SysTickState), | ||
243 | - VMSTATE_UINT32(reload, SysTickState), | ||
244 | VMSTATE_INT64(tick, SysTickState), | ||
245 | - VMSTATE_TIMER_PTR(timer, SysTickState), | ||
246 | + VMSTATE_PTIMER(ptimer, SysTickState), | ||
247 | VMSTATE_END_OF_LIST() | ||
248 | } | ||
249 | }; | ||
250 | -- | 69 | -- |
251 | 2.20.1 | 70 | 2.20.1 |
252 | 71 | ||
253 | 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 | These are all of the defines required to parse | 3 | This is the prctl bit that controls whether syscalls accept tagged |
4 | GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. | 4 | addresses. See Documentation/arm64/tagged-address-abi.rst in the |
5 | Other missing defines related to other GNU program headers | 5 | linux kernel. |
6 | and notes are elided for now. | ||
7 | 6 | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Message-id: 20201021173749.111103-4-richard.henderson@linaro.org | 9 | Message-id: 20210212184902.1251044-21-richard.henderson@linaro.org |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 11 | --- |
13 | include/elf.h | 22 ++++++++++++++++++++++ | 12 | linux-user/aarch64/target_syscall.h | 4 ++++ |
14 | 1 file changed, 22 insertions(+) | 13 | target/arm/cpu-param.h | 3 +++ |
14 | target/arm/cpu.h | 31 +++++++++++++++++++++++++++++ | ||
15 | linux-user/syscall.c | 24 ++++++++++++++++++++++ | ||
16 | 4 files changed, 62 insertions(+) | ||
15 | 17 | ||
16 | diff --git a/include/elf.h b/include/elf.h | 18 | diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h |
17 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/include/elf.h | 20 | --- a/linux-user/aarch64/target_syscall.h |
19 | +++ b/include/elf.h | 21 | +++ b/linux-user/aarch64/target_syscall.h |
20 | @@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword; | 22 | @@ -XXX,XX +XXX,XX @@ struct target_pt_regs { |
21 | #define PT_NOTE 4 | 23 | # define TARGET_PR_PAC_APDBKEY (1 << 3) |
22 | #define PT_SHLIB 5 | 24 | # define TARGET_PR_PAC_APGAKEY (1 << 4) |
23 | #define PT_PHDR 6 | 25 | |
24 | +#define PT_LOOS 0x60000000 | 26 | +#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 |
25 | +#define PT_HIOS 0x6fffffff | 27 | +#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 |
26 | #define PT_LOPROC 0x70000000 | 28 | +# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) |
27 | #define PT_HIPROC 0x7fffffff | ||
28 | |||
29 | +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) | ||
30 | + | 29 | + |
31 | #define PT_MIPS_REGINFO 0x70000000 | 30 | #endif /* AARCH64_TARGET_SYSCALL_H */ |
32 | #define PT_MIPS_RTPROC 0x70000001 | 31 | diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h |
33 | #define PT_MIPS_OPTIONS 0x70000002 | 32 | index XXXXXXX..XXXXXXX 100644 |
34 | @@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr { | 33 | --- a/target/arm/cpu-param.h |
35 | #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ | 34 | +++ b/target/arm/cpu-param.h |
36 | #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension regs */ | 35 | @@ -XXX,XX +XXX,XX @@ |
37 | 36 | ||
38 | +/* Defined note types for GNU systems. */ | 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 | ||
45 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/target/arm/cpu.h | ||
48 | +++ b/target/arm/cpu.h | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
50 | const struct arm_boot_info *boot_info; | ||
51 | /* Store GICv3CPUState to access from this struct */ | ||
52 | void *gicv3state; | ||
39 | + | 53 | + |
40 | +#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */ | 54 | +#ifdef TARGET_TAGGED_ADDRESSES |
41 | + | 55 | + /* Linux syscall tagged address support */ |
42 | +/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */ | 56 | + bool tagged_addr_enable; |
43 | + | 57 | +#endif |
44 | +#define GNU_PROPERTY_STACK_SIZE 1 | 58 | } CPUARMState; |
45 | +#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 | 59 | |
46 | + | 60 | static inline void set_feature(CPUARMState *env, int feature) |
47 | +#define GNU_PROPERTY_LOPROC 0xc0000000 | 61 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
48 | +#define GNU_PROPERTY_HIPROC 0xdfffffff | 62 | */ |
49 | +#define GNU_PROPERTY_LOUSER 0xe0000000 | 63 | #define PAGE_BTI PAGE_TARGET_1 |
50 | +#define GNU_PROPERTY_HIUSER 0xffffffff | 64 | |
51 | + | 65 | +#ifdef TARGET_TAGGED_ADDRESSES |
52 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 | 66 | +/** |
53 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) | 67 | + * cpu_untagged_addr: |
54 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) | 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 | ||
55 | + | 90 | + |
56 | /* | 91 | /* |
57 | * Physical entry point into the kernel. | 92 | * Naming convention for isar_feature functions: |
58 | * | 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 | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/linux-user/syscall.c | ||
97 | +++ b/linux-user/syscall.c | ||
98 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
99 | } | ||
100 | } | ||
101 | return -TARGET_EINVAL; | ||
102 | + case TARGET_PR_SET_TAGGED_ADDR_CTRL: | ||
103 | + { | ||
104 | + abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; | ||
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: | ||
59 | -- | 129 | -- |
60 | 2.20.1 | 130 | 2.20.1 |
61 | 131 | ||
62 | 132 | diff view generated by jsdifflib |
1 | From: Havard Skinnemoen <hskinnemoen@google.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This allows us to reuse npcm7xx_timer_pause for the watchdog timer. | 3 | Use simple arithmetic instead of a conditional |
4 | move when tbi0 != tbi1. | ||
4 | 5 | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20210212184902.1251044-22-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 10 | --- |
9 | hw/timer/npcm7xx_timer.c | 6 +++--- | 11 | target/arm/translate-a64.c | 25 ++++++++++++++----------- |
10 | 1 file changed, 3 insertions(+), 3 deletions(-) | 12 | 1 file changed, 14 insertions(+), 11 deletions(-) |
11 | 13 | ||
12 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | 14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/timer/npcm7xx_timer.c | 16 | --- a/target/arm/translate-a64.c |
15 | +++ b/hw/timer/npcm7xx_timer.c | 17 | +++ b/target/arm/translate-a64.c |
16 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) | 18 | @@ -XXX,XX +XXX,XX @@ static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst, |
17 | timer_del(&t->qtimer); | 19 | /* Sign-extend from bit 55. */ |
18 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 20 | tcg_gen_sextract_i64(dst, src, 0, 56); |
19 | t->remaining_ns = t->expires_ns - now; | 21 | |
20 | - if (t->remaining_ns <= 0) { | 22 | - if (tbi != 3) { |
21 | - npcm7xx_timer_reached_zero(t); | 23 | - TCGv_i64 tcg_zero = tcg_const_i64(0); |
22 | - } | 24 | - |
23 | } | 25 | - /* |
24 | 26 | - * The two TBI bits differ. | |
25 | /* | 27 | - * If tbi0, then !tbi1: only use the extension if positive. |
26 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | 28 | - * if !tbi0, then tbi1: only use the extension if negative. |
27 | } else { | 29 | - */ |
28 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | 30 | - tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, |
29 | npcm7xx_timer_pause(t); | 31 | - dst, dst, tcg_zero, dst, src); |
30 | + if (t->remaining_ns <= 0) { | 32 | - tcg_temp_free_i64(tcg_zero); |
31 | + npcm7xx_timer_reached_zero(t); | 33 | + switch (tbi) { |
32 | + } | 34 | + case 1: |
35 | + /* tbi0 but !tbi1: only use the extension if positive */ | ||
36 | + tcg_gen_and_i64(dst, dst, src); | ||
37 | + break; | ||
38 | + case 2: | ||
39 | + /* !tbi0 but tbi1: only use the extension if negative */ | ||
40 | + tcg_gen_or_i64(dst, dst, src); | ||
41 | + break; | ||
42 | + case 3: | ||
43 | + /* tbi0 and tbi1: always use the extension */ | ||
44 | + break; | ||
45 | + default: | ||
46 | + g_assert_not_reached(); | ||
33 | } | 47 | } |
34 | } | 48 | } |
35 | } | 49 | } |
36 | -- | 50 | -- |
37 | 2.20.1 | 51 | 2.20.1 |
38 | 52 | ||
39 | 53 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The CPRMAN (clock controller) was mapped at the watchdog/power manager | 3 | We were fudging TBI1 enabled to speed up the generated code. |
4 | address. It was also split into two unimplemented peripherals (CM and | 4 | Now that we've improved the code generation, remove this. |
5 | A2W) but this is really the same one, as shown by this extract of the | 5 | Also, tidy the comment to reflect the current code. |
6 | Raspberry Pi 3 Linux device tree: | ||
7 | 6 | ||
8 | watchdog@7e100000 { | 7 | The pauth test was testing a kernel address (-1) and making |
9 | compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt"; | 8 | incorrect assumptions about TBI1; stick to userland addresses. |
10 | [...] | ||
11 | reg = <0x7e100000 0x114 0x7e00a000 0x24>; | ||
12 | [...] | ||
13 | }; | ||
14 | 9 | ||
15 | [...] | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
16 | cprman@7e101000 { | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
17 | compatible = "brcm,bcm2835-cprman"; | 12 | Message-id: 20210212184902.1251044-23-richard.henderson@linaro.org |
18 | [...] | ||
19 | reg = <0x7e101000 0x2000>; | ||
20 | [...] | ||
21 | }; | ||
22 | |||
23 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
25 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
26 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
28 | --- | 14 | --- |
29 | include/hw/arm/bcm2835_peripherals.h | 2 +- | 15 | target/arm/internals.h | 4 ++-- |
30 | include/hw/arm/raspi_platform.h | 5 ++--- | 16 | target/arm/cpu.c | 10 +++------- |
31 | hw/arm/bcm2835_peripherals.c | 4 ++-- | 17 | tests/tcg/aarch64/pauth-2.c | 1 - |
32 | 3 files changed, 5 insertions(+), 6 deletions(-) | 18 | 3 files changed, 5 insertions(+), 10 deletions(-) |
33 | 19 | ||
34 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | 20 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
35 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/include/hw/arm/bcm2835_peripherals.h | 22 | --- a/target/arm/internals.h |
37 | +++ b/include/hw/arm/bcm2835_peripherals.h | 23 | +++ b/target/arm/internals.h |
38 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | 24 | @@ -XXX,XX +XXX,XX @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag) |
39 | BCM2835MphiState mphi; | 25 | */ |
40 | UnimplementedDeviceState txp; | 26 | static inline uint64_t useronly_clean_ptr(uint64_t ptr) |
41 | UnimplementedDeviceState armtmr; | 27 | { |
42 | + UnimplementedDeviceState powermgt; | 28 | - /* TBI is known to be enabled. */ |
43 | UnimplementedDeviceState cprman; | 29 | #ifdef CONFIG_USER_ONLY |
44 | - UnimplementedDeviceState a2w; | 30 | - ptr = sextract64(ptr, 0, 56); |
45 | PL011State uart0; | 31 | + /* TBI0 is known to be enabled, while TBI1 is disabled. */ |
46 | BCM2835AuxState aux; | 32 | + ptr &= sextract64(ptr, 0, 56); |
47 | BCM2835FBState fb; | 33 | #endif |
48 | diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h | 34 | return ptr; |
35 | } | ||
36 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/include/hw/arm/raspi_platform.h | 38 | --- a/target/arm/cpu.c |
51 | +++ b/include/hw/arm/raspi_platform.h | 39 | +++ b/target/arm/cpu.c |
52 | @@ -XXX,XX +XXX,XX @@ | 40 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
53 | #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */ | 41 | env->vfp.zcr_el[1] = MIN(cpu->sve_max_vq - 1, 3); |
54 | #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores | 42 | } |
55 | * Doorbells & Mailboxes */ | 43 | /* |
56 | -#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */ | 44 | - * Enable TBI0 and TBI1. While the real kernel only enables TBI0, |
57 | -#define CM_OFFSET 0x101000 /* Clock Management */ | 45 | - * turning on both here will produce smaller code and otherwise |
58 | -#define A2W_OFFSET 0x102000 /* Reset controller */ | 46 | - * make no difference to the user-level emulation. |
59 | +#define PM_OFFSET 0x100000 /* Power Management */ | 47 | - * |
60 | +#define CPRMAN_OFFSET 0x101000 /* Clock Management */ | 48 | - * In sve_probe_page, we assume that this is set. |
61 | #define AVS_OFFSET 0x103000 /* Audio Video Standard */ | 49 | - * Do not modify this without other changes. |
62 | #define RNG_OFFSET 0x104000 | 50 | + * Enable TBI0 but not TBI1. |
63 | #define GPIO_OFFSET 0x200000 | 51 | + * Note that this must match useronly_clean_ptr. |
64 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | 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 | ||
65 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
66 | --- a/hw/arm/bcm2835_peripherals.c | 60 | --- a/tests/tcg/aarch64/pauth-2.c |
67 | +++ b/hw/arm/bcm2835_peripherals.c | 61 | +++ b/tests/tcg/aarch64/pauth-2.c |
68 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 62 | @@ -XXX,XX +XXX,XX @@ void do_test(uint64_t value) |
69 | 63 | int main() | |
70 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | 64 | { |
71 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | 65 | do_test(0); |
72 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); | 66 | - do_test(-1); |
73 | - create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); | 67 | do_test(0xda004acedeadbeefull); |
74 | + create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | 68 | return 0; |
75 | + create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | 69 | } |
76 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); | ||
77 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); | ||
78 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); | ||
79 | -- | 70 | -- |
80 | 2.20.1 | 71 | 2.20.1 |
81 | 72 | ||
82 | 73 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The Pi 3A+ is a stripped down version of the 3B: | 3 | These prctl fields are required for the function of MTE. |
4 | - 512 MiB of RAM instead of 1 GiB | ||
5 | - no on-board ethernet chipset | ||
6 | 4 | ||
7 | Add it as it is a closer match to what we model. | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | |
9 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | 7 | Message-id: 20210212184902.1251044-24-richard.henderson@linaro.org |
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20201024170127.3592182-10-f4bug@amsat.org | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 9 | --- |
14 | hw/arm/raspi.c | 13 +++++++++++++ | 10 | linux-user/aarch64/target_syscall.h | 9 ++++++ |
15 | 1 file changed, 13 insertions(+) | 11 | linux-user/syscall.c | 43 +++++++++++++++++++++++++++++ |
12 | 2 files changed, 52 insertions(+) | ||
16 | 13 | ||
17 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | 14 | diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h |
18 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/arm/raspi.c | 16 | --- a/linux-user/aarch64/target_syscall.h |
20 | +++ b/hw/arm/raspi.c | 17 | +++ b/linux-user/aarch64/target_syscall.h |
21 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) | 18 | @@ -XXX,XX +XXX,XX @@ struct target_pt_regs { |
22 | }; | 19 | #define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 |
23 | 20 | #define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 | |
24 | #ifdef TARGET_AARCH64 | 21 | # define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) |
25 | +static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) | 22 | +/* MTE tag check fault modes */ |
26 | +{ | 23 | +# define TARGET_PR_MTE_TCF_SHIFT 1 |
27 | + MachineClass *mc = MACHINE_CLASS(oc); | 24 | +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) |
28 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | 25 | +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) |
26 | +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) | ||
27 | +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) | ||
28 | +/* MTE tag inclusion mask */ | ||
29 | +# define TARGET_PR_MTE_TAG_SHIFT 3 | ||
30 | +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT) | ||
31 | |||
32 | #endif /* AARCH64_TARGET_SYSCALL_H */ | ||
33 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/linux-user/syscall.c | ||
36 | +++ b/linux-user/syscall.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
38 | { | ||
39 | abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; | ||
40 | CPUARMState *env = cpu_env; | ||
41 | + ARMCPU *cpu = env_archcpu(env); | ||
29 | + | 42 | + |
30 | + rmc->board_rev = 0x9020e0; /* Revision 1.0 */ | 43 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
31 | + raspi_machine_class_common_init(mc, rmc->board_rev); | 44 | + valid_mask |= TARGET_PR_MTE_TCF_MASK; |
32 | +}; | 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; | ||
33 | + | 52 | + |
34 | static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | 53 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
35 | { | 54 | + switch (arg2 & TARGET_PR_MTE_TCF_MASK) { |
36 | MachineClass *mc = MACHINE_CLASS(oc); | 55 | + case TARGET_PR_MTE_TCF_NONE: |
37 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = { | 56 | + case TARGET_PR_MTE_TCF_SYNC: |
38 | .parent = TYPE_RASPI_MACHINE, | 57 | + case TARGET_PR_MTE_TCF_ASYNC: |
39 | .class_init = raspi2b_machine_class_init, | 58 | + break; |
40 | #ifdef TARGET_AARCH64 | 59 | + default: |
41 | + }, { | 60 | + return -EINVAL; |
42 | + .name = MACHINE_TYPE_NAME("raspi3ap"), | 61 | + } |
43 | + .parent = TYPE_RASPI_MACHINE, | 62 | + |
44 | + .class_init = raspi3ap_machine_class_init, | 63 | + /* |
45 | }, { | 64 | + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. |
46 | .name = MACHINE_TYPE_NAME("raspi3b"), | 65 | + * Note that the syscall values are consistent with hw. |
47 | .parent = TYPE_RASPI_MACHINE, | 66 | + */ |
67 | + env->cp15.sctlr_el[1] = | ||
68 | + deposit64(env->cp15.sctlr_el[1], 38, 2, | ||
69 | + arg2 >> TARGET_PR_MTE_TCF_SHIFT); | ||
70 | + | ||
71 | + /* | ||
72 | + * Write PR_MTE_TAG to GCR_EL1[Exclude]. | ||
73 | + * Note that the syscall uses an include mask, | ||
74 | + * and hardware uses an exclude mask -- invert. | ||
75 | + */ | ||
76 | + env->cp15.gcr_el1 = | ||
77 | + deposit64(env->cp15.gcr_el1, 0, 16, | ||
78 | + ~arg2 >> TARGET_PR_MTE_TAG_SHIFT); | ||
79 | + arm_rebuild_hflags(env); | ||
80 | + } | ||
81 | return 0; | ||
82 | } | ||
83 | case TARGET_PR_GET_TAGGED_ADDR_CTRL: | ||
84 | { | ||
85 | abi_long ret = 0; | ||
86 | CPUARMState *env = cpu_env; | ||
87 | + ARMCPU *cpu = env_archcpu(env); | ||
88 | |||
89 | if (arg2 || arg3 || arg4 || arg5) { | ||
90 | return -TARGET_EINVAL; | ||
91 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
92 | if (env->tagged_addr_enable) { | ||
93 | ret |= TARGET_PR_TAGGED_ADDR_ENABLE; | ||
94 | } | ||
95 | + if (cpu_isar_feature(aa64_mte, cpu)) { | ||
96 | + /* See above. */ | ||
97 | + ret |= (extract64(env->cp15.sctlr_el[1], 38, 2) | ||
98 | + << TARGET_PR_MTE_TCF_SHIFT); | ||
99 | + ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16, | ||
100 | + ~env->cp15.gcr_el1); | ||
101 | + } | ||
102 | return ret; | ||
103 | } | ||
104 | #endif /* AARCH64 */ | ||
48 | -- | 105 | -- |
49 | 2.20.1 | 106 | 2.20.1 |
50 | 107 | ||
51 | 108 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Transform the prot bit to a qemu internal page bit, and save | 3 | Remember the PROT_MTE bit as PAGE_MTE/PAGE_TARGET_2. |
4 | it in the page tables. | 4 | Otherwise this does not yet have effect. |
5 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20201021173749.111103-3-richard.henderson@linaro.org | 8 | Message-id: 20210212184902.1251044-25-richard.henderson@linaro.org |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 10 | --- |
11 | include/exec/cpu-all.h | 2 ++ | 11 | include/exec/cpu-all.h | 1 + |
12 | linux-user/syscall_defs.h | 4 ++++ | 12 | linux-user/syscall_defs.h | 1 + |
13 | target/arm/cpu.h | 5 +++++ | 13 | target/arm/cpu.h | 1 + |
14 | linux-user/mmap.c | 16 ++++++++++++++++ | 14 | linux-user/mmap.c | 22 ++++++++++++++-------- |
15 | target/arm/translate-a64.c | 6 +++--- | 15 | 4 files changed, 17 insertions(+), 8 deletions(-) |
16 | 5 files changed, 30 insertions(+), 3 deletions(-) | ||
17 | 16 | ||
18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h | 17 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
19 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/exec/cpu-all.h | 19 | --- a/include/exec/cpu-all.h |
21 | +++ b/include/exec/cpu-all.h | 20 | +++ b/include/exec/cpu-all.h |
22 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; | 21 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
23 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ | ||
24 | #define PAGE_RESERVED 0x0020 | ||
25 | #endif | 22 | #endif |
26 | +/* Target-specific bits that will be used via page_get_flags(). */ | 23 | /* Target-specific bits that will be used via page_get_flags(). */ |
27 | +#define PAGE_TARGET_1 0x0080 | 24 | #define PAGE_TARGET_1 0x0080 |
25 | +#define PAGE_TARGET_2 0x0200 | ||
28 | 26 | ||
29 | #if defined(CONFIG_USER_ONLY) | 27 | #if defined(CONFIG_USER_ONLY) |
30 | void page_dump(FILE *f); | 28 | void page_dump(FILE *f); |
31 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h | 29 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h |
32 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/linux-user/syscall_defs.h | 31 | --- a/linux-user/syscall_defs.h |
34 | +++ b/linux-user/syscall_defs.h | 32 | +++ b/linux-user/syscall_defs.h |
35 | @@ -XXX,XX +XXX,XX @@ struct target_winsize { | 33 | @@ -XXX,XX +XXX,XX @@ struct target_winsize { |
36 | #define TARGET_PROT_SEM 0x08 | 34 | |
35 | #ifdef TARGET_AARCH64 | ||
36 | #define TARGET_PROT_BTI 0x10 | ||
37 | +#define TARGET_PROT_MTE 0x20 | ||
37 | #endif | 38 | #endif |
38 | 39 | ||
39 | +#ifdef TARGET_AARCH64 | ||
40 | +#define TARGET_PROT_BTI 0x10 | ||
41 | +#endif | ||
42 | + | ||
43 | /* Common */ | 40 | /* Common */ |
44 | #define TARGET_MAP_SHARED 0x01 /* Share changes */ | ||
45 | #define TARGET_MAP_PRIVATE 0x02 /* Changes are private */ | ||
46 | 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 |
47 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/arm/cpu.h | 43 | --- a/target/arm/cpu.h |
49 | +++ b/target/arm/cpu.h | 44 | +++ b/target/arm/cpu.h |
50 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) | 45 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
51 | #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) | 46 | * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
52 | #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) | 47 | */ |
53 | 48 | #define PAGE_BTI PAGE_TARGET_1 | |
54 | +/* | 49 | +#define PAGE_MTE PAGE_TARGET_2 |
55 | + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. | 50 | |
56 | + */ | 51 | #ifdef TARGET_TAGGED_ADDRESSES |
57 | +#define PAGE_BTI PAGE_TARGET_1 | 52 | /** |
58 | + | ||
59 | /* | ||
60 | * Naming convention for isar_feature functions: | ||
61 | * Functions which test 32-bit ID registers should have _aa32_ in | ||
62 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | 53 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
63 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/linux-user/mmap.c | 55 | --- a/linux-user/mmap.c |
65 | +++ b/linux-user/mmap.c | 56 | +++ b/linux-user/mmap.c |
66 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | 57 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) |
67 | *host_prot = (prot & (PROT_READ | PROT_WRITE)) | ||
68 | | (prot & PROT_EXEC ? PROT_READ : 0); | 58 | | (prot & PROT_EXEC ? PROT_READ : 0); |
69 | 59 | ||
70 | +#ifdef TARGET_AARCH64 | 60 | #ifdef TARGET_AARCH64 |
71 | + /* | 61 | - /* |
72 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. | 62 | - * The PROT_BTI bit is only accepted if the cpu supports the feature. |
73 | + * Since this is the unusual case, don't bother checking unless | 63 | - * Since this is the unusual case, don't bother checking unless |
74 | + * the bit has been requested. If set and valid, record the bit | 64 | - * the bit has been requested. If set and valid, record the bit |
75 | + * within QEMU's page_flags. | 65 | - * within QEMU's page_flags. |
76 | + */ | 66 | - */ |
77 | + if (prot & TARGET_PROT_BTI) { | 67 | - if (prot & TARGET_PROT_BTI) { |
78 | + ARMCPU *cpu = ARM_CPU(thread_cpu); | 68 | + { |
79 | + if (cpu_isar_feature(aa64_bti, cpu)) { | 69 | ARMCPU *cpu = ARM_CPU(thread_cpu); |
80 | + valid |= TARGET_PROT_BTI; | 70 | - if (cpu_isar_feature(aa64_bti, cpu)) { |
81 | + page_flags |= PAGE_BTI; | 71 | + |
72 | + /* | ||
73 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. | ||
74 | + * Since this is the unusual case, don't bother checking unless | ||
75 | + * the bit has been requested. If set and valid, record the bit | ||
76 | + * within QEMU's page_flags. | ||
77 | + */ | ||
78 | + if ((prot & TARGET_PROT_BTI) && cpu_isar_feature(aa64_bti, cpu)) { | ||
79 | valid |= TARGET_PROT_BTI; | ||
80 | page_flags |= PAGE_BTI; | ||
81 | } | ||
82 | + /* Similarly for the PROT_MTE bit. */ | ||
83 | + if ((prot & TARGET_PROT_MTE) && cpu_isar_feature(aa64_mte, cpu)) { | ||
84 | + valid |= TARGET_PROT_MTE; | ||
85 | + page_flags |= PAGE_MTE; | ||
82 | + } | 86 | + } |
83 | + } | 87 | } |
84 | +#endif | 88 | #endif |
85 | + | 89 | |
86 | return prot & ~valid ? 0 : page_flags; | ||
87 | } | ||
88 | |||
89 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/arm/translate-a64.c | ||
92 | +++ b/target/arm/translate-a64.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) | ||
94 | */ | ||
95 | static bool is_guarded_page(CPUARMState *env, DisasContext *s) | ||
96 | { | ||
97 | -#ifdef CONFIG_USER_ONLY | ||
98 | - return false; /* FIXME */ | ||
99 | -#else | ||
100 | uint64_t addr = s->base.pc_first; | ||
101 | +#ifdef CONFIG_USER_ONLY | ||
102 | + return page_get_flags(addr) & PAGE_BTI; | ||
103 | +#else | ||
104 | int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); | ||
105 | unsigned int index = tlb_index(env, mmu_idx, addr); | ||
106 | CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); | ||
107 | -- | 90 | -- |
108 | 2.20.1 | 91 | 2.20.1 |
109 | 92 | ||
110 | 93 | diff view generated by jsdifflib |
1 | From: Shashi Mallela <shashi.mallela@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Generic watchdog device model implementation as per ARM SBSA v6.0 | 3 | Move everything related to syndromes to a new file, |
4 | which can be shared with linux-user. | ||
4 | 5 | ||
5 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | ||
6 | Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 20210212184902.1251044-26-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++ | 12 | target/arm/internals.h | 245 +----------------------------------- |
11 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++ | 13 | target/arm/syndrome.h | 273 +++++++++++++++++++++++++++++++++++++++++ |
12 | hw/arm/Kconfig | 1 + | 14 | 2 files changed, 274 insertions(+), 244 deletions(-) |
13 | hw/watchdog/Kconfig | 3 + | 15 | create mode 100644 target/arm/syndrome.h |
14 | hw/watchdog/meson.build | 1 + | ||
15 | 5 files changed, 377 insertions(+) | ||
16 | create mode 100644 include/hw/watchdog/sbsa_gwdt.h | ||
17 | create mode 100644 hw/watchdog/sbsa_gwdt.c | ||
18 | 16 | ||
19 | diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h | 17 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/arm/internals.h | ||
20 | +++ b/target/arm/internals.h | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #define TARGET_ARM_INTERNALS_H | ||
23 | |||
24 | #include "hw/registerfields.h" | ||
25 | +#include "syndrome.h" | ||
26 | |||
27 | /* register banks for CPU modes */ | ||
28 | #define BANK_USRSYS 0 | ||
29 | @@ -XXX,XX +XXX,XX @@ static inline bool extended_addresses_enabled(CPUARMState *env) | ||
30 | (arm_feature(env, ARM_FEATURE_LPAE) && (tcr->raw_tcr & TTBCR_EAE)); | ||
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 | ||
20 | new file mode 100644 | 281 | new file mode 100644 |
21 | index XXXXXXX..XXXXXXX | 282 | index XXXXXXX..XXXXXXX |
22 | --- /dev/null | 283 | --- /dev/null |
23 | +++ b/include/hw/watchdog/sbsa_gwdt.h | 284 | +++ b/target/arm/syndrome.h |
24 | @@ -XXX,XX +XXX,XX @@ | 285 | @@ -XXX,XX +XXX,XX @@ |
25 | +/* | 286 | +/* |
26 | + * Copyright (c) 2020 Linaro Limited | 287 | + * QEMU ARM CPU -- syndrome functions and types |
27 | + * | 288 | + * |
28 | + * Authors: | 289 | + * Copyright (c) 2014 Linaro Ltd |
29 | + * Shashi Mallela <shashi.mallela@linaro.org> | ||
30 | + * | 290 | + * |
31 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | 291 | + * This program is free software; you can redistribute it and/or |
32 | + * option) any later version. See the COPYING file in the top-level directory. | 292 | + * modify it under the terms of the GNU General Public License |
293 | + * as published by the Free Software Foundation; either version 2 | ||
294 | + * of the License, or (at your option) any later version. | ||
33 | + * | 295 | + * |
296 | + * This program is distributed in the hope that it will be useful, | ||
297 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
298 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
299 | + * GNU General Public License for more details. | ||
300 | + * | ||
301 | + * You should have received a copy of the GNU General Public License | ||
302 | + * along with this program; if not, see | ||
303 | + * <http://www.gnu.org/licenses/gpl-2.0.html> | ||
304 | + * | ||
305 | + * This header defines functions, types, etc which need to be shared | ||
306 | + * between different source files within target/arm/ but which are | ||
307 | + * private to it and not required by the rest of QEMU. | ||
34 | + */ | 308 | + */ |
35 | + | 309 | + |
36 | +#ifndef WDT_SBSA_GWDT_H | 310 | +#ifndef TARGET_ARM_SYNDROME_H |
37 | +#define WDT_SBSA_GWDT_H | 311 | +#define TARGET_ARM_SYNDROME_H |
38 | + | 312 | + |
39 | +#include "qemu/bitops.h" | 313 | +/* Valid Syndrome Register EC field values */ |
40 | +#include "hw/sysbus.h" | 314 | +enum arm_exception_class { |
41 | +#include "hw/irq.h" | 315 | + EC_UNCATEGORIZED = 0x00, |
42 | + | 316 | + EC_WFX_TRAP = 0x01, |
43 | +#define TYPE_WDT_SBSA "sbsa_gwdt" | 317 | + EC_CP15RTTRAP = 0x03, |
44 | +#define SBSA_GWDT(obj) \ | 318 | + EC_CP15RRTTRAP = 0x04, |
45 | + OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA) | 319 | + EC_CP14RTTRAP = 0x05, |
46 | +#define SBSA_GWDT_CLASS(klass) \ | 320 | + EC_CP14DTTRAP = 0x06, |
47 | + OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA) | 321 | + EC_ADVSIMDFPACCESSTRAP = 0x07, |
48 | +#define SBSA_GWDT_GET_CLASS(obj) \ | 322 | + EC_FPIDTRAP = 0x08, |
49 | + OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA) | 323 | + EC_PACTRAP = 0x09, |
50 | + | 324 | + EC_CP14RRTTRAP = 0x0c, |
51 | +/* SBSA Generic Watchdog register definitions */ | 325 | + EC_BTITRAP = 0x0d, |
52 | +/* refresh frame */ | 326 | + EC_ILLEGALSTATE = 0x0e, |
53 | +#define SBSA_GWDT_WRR 0x000 | 327 | + EC_AA32_SVC = 0x11, |
54 | + | 328 | + EC_AA32_HVC = 0x12, |
55 | +/* control frame */ | 329 | + EC_AA32_SMC = 0x13, |
56 | +#define SBSA_GWDT_WCS 0x000 | 330 | + EC_AA64_SVC = 0x15, |
57 | +#define SBSA_GWDT_WOR 0x008 | 331 | + EC_AA64_HVC = 0x16, |
58 | +#define SBSA_GWDT_WORU 0x00C | 332 | + EC_AA64_SMC = 0x17, |
59 | +#define SBSA_GWDT_WCV 0x010 | 333 | + EC_SYSTEMREGISTERTRAP = 0x18, |
60 | +#define SBSA_GWDT_WCVU 0x014 | 334 | + EC_SVEACCESSTRAP = 0x19, |
61 | + | 335 | + EC_INSNABORT = 0x20, |
62 | +/* Watchdog Interface Identification Register */ | 336 | + EC_INSNABORT_SAME_EL = 0x21, |
63 | +#define SBSA_GWDT_W_IIDR 0xFCC | 337 | + EC_PCALIGNMENT = 0x22, |
64 | + | 338 | + EC_DATAABORT = 0x24, |
65 | +/* Watchdog Control and Status Register Bits */ | 339 | + EC_DATAABORT_SAME_EL = 0x25, |
66 | +#define SBSA_GWDT_WCS_EN BIT(0) | 340 | + EC_SPALIGNMENT = 0x26, |
67 | +#define SBSA_GWDT_WCS_WS0 BIT(1) | 341 | + EC_AA32_FPTRAP = 0x28, |
68 | +#define SBSA_GWDT_WCS_WS1 BIT(2) | 342 | + EC_AA64_FPTRAP = 0x2c, |
69 | + | 343 | + EC_SERROR = 0x2f, |
70 | +#define SBSA_GWDT_WOR_MASK 0x0000FFFF | 344 | + EC_BREAKPOINT = 0x30, |
345 | + EC_BREAKPOINT_SAME_EL = 0x31, | ||
346 | + EC_SOFTWARESTEP = 0x32, | ||
347 | + EC_SOFTWARESTEP_SAME_EL = 0x33, | ||
348 | + EC_WATCHPOINT = 0x34, | ||
349 | + EC_WATCHPOINT_SAME_EL = 0x35, | ||
350 | + EC_AA32_BKPT = 0x38, | ||
351 | + EC_VECTORCATCH = 0x3a, | ||
352 | + EC_AA64_BKPT = 0x3c, | ||
353 | +}; | ||
354 | + | ||
355 | +#define ARM_EL_EC_SHIFT 26 | ||
356 | +#define ARM_EL_IL_SHIFT 25 | ||
357 | +#define ARM_EL_ISV_SHIFT 24 | ||
358 | +#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) | ||
359 | +#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) | ||
360 | + | ||
361 | +static inline uint32_t syn_get_ec(uint32_t syn) | ||
362 | +{ | ||
363 | + return syn >> ARM_EL_EC_SHIFT; | ||
364 | +} | ||
71 | + | 365 | + |
72 | +/* | 366 | +/* |
73 | + * Watchdog Interface Identification Register definition | 367 | + * Utility functions for constructing various kinds of syndrome value. |
74 | + * considering JEP106 code for ARM in Bits [11:0] | 368 | + * Note that in general we follow the AArch64 syndrome values; in a |
369 | + * few cases the value in HSR for exceptions taken to AArch32 Hyp | ||
370 | + * mode differs slightly, and we fix this up when populating HSR in | ||
371 | + * arm_cpu_do_interrupt_aarch32_hyp(). | ||
372 | + * The exception is FP/SIMD access traps -- these report extra information | ||
373 | + * when taking an exception to AArch32. For those we include the extra coproc | ||
374 | + * and TA fields, and mask them out when taking the exception to AArch64. | ||
75 | + */ | 375 | + */ |
76 | +#define SBSA_GWDT_ID 0x1043B | 376 | +static inline uint32_t syn_uncategorized(void) |
77 | + | 377 | +{ |
78 | +/* 2 Separate memory regions for each of refresh & control register frames */ | 378 | + return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
79 | +#define SBSA_GWDT_RMMIO_SIZE 0x1000 | 379 | +} |
80 | +#define SBSA_GWDT_CMMIO_SIZE 0x1000 | 380 | + |
81 | + | 381 | +static inline uint32_t syn_aa64_svc(uint32_t imm16) |
82 | +#define SBSA_TIMER_FREQ 62500000 /* Hz */ | 382 | +{ |
83 | + | 383 | + return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
84 | +typedef struct SBSA_GWDTState { | 384 | +} |
85 | + /* <private> */ | 385 | + |
86 | + SysBusDevice parent_obj; | 386 | +static inline uint32_t syn_aa64_hvc(uint32_t imm16) |
87 | + | 387 | +{ |
88 | + /*< public >*/ | 388 | + return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
89 | + MemoryRegion rmmio; | 389 | +} |
90 | + MemoryRegion cmmio; | 390 | + |
91 | + qemu_irq irq; | 391 | +static inline uint32_t syn_aa64_smc(uint32_t imm16) |
92 | + | 392 | +{ |
93 | + QEMUTimer *timer; | 393 | + return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
94 | + | 394 | +} |
95 | + uint32_t id; | 395 | + |
96 | + uint32_t wcs; | 396 | +static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit) |
97 | + uint32_t worl; | 397 | +{ |
98 | + uint32_t woru; | 398 | + return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
99 | + uint32_t wcvl; | 399 | + | (is_16bit ? 0 : ARM_EL_IL); |
100 | + uint32_t wcvu; | 400 | +} |
101 | +} SBSA_GWDTState; | 401 | + |
102 | + | 402 | +static inline uint32_t syn_aa32_hvc(uint32_t imm16) |
103 | +#endif /* WDT_SBSA_GWDT_H */ | 403 | +{ |
104 | diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c | 404 | + return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
105 | new file mode 100644 | 405 | +} |
106 | index XXXXXXX..XXXXXXX | 406 | + |
107 | --- /dev/null | 407 | +static inline uint32_t syn_aa32_smc(void) |
108 | +++ b/hw/watchdog/sbsa_gwdt.c | 408 | +{ |
109 | @@ -XXX,XX +XXX,XX @@ | 409 | + return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL; |
110 | +/* | 410 | +} |
111 | + * Generic watchdog device model for SBSA | 411 | + |
112 | + * | 412 | +static inline uint32_t syn_aa64_bkpt(uint32_t imm16) |
113 | + * The watchdog device has been implemented as revision 1 variant of | 413 | +{ |
114 | + * the ARM SBSA specification v6.0 | 414 | + return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff); |
115 | + * (https://developer.arm.com/documentation/den0029/d?lang=en) | 415 | +} |
116 | + * | 416 | + |
117 | + * Copyright Linaro.org 2020 | 417 | +static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit) |
118 | + * | 418 | +{ |
119 | + * Authors: | 419 | + return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff) |
120 | + * Shashi Mallela <shashi.mallela@linaro.org> | 420 | + | (is_16bit ? 0 : ARM_EL_IL); |
121 | + * | 421 | +} |
122 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | 422 | + |
123 | + * option) any later version. See the COPYING file in the top-level directory. | 423 | +static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2, |
124 | + * | 424 | + int crn, int crm, int rt, |
125 | + */ | 425 | + int isread) |
126 | + | 426 | +{ |
127 | +#include "qemu/osdep.h" | 427 | + return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL |
128 | +#include "sysemu/reset.h" | 428 | + | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5) |
129 | +#include "sysemu/watchdog.h" | 429 | + | (crm << 1) | isread; |
130 | +#include "hw/watchdog/sbsa_gwdt.h" | 430 | +} |
131 | +#include "qemu/timer.h" | 431 | + |
132 | +#include "migration/vmstate.h" | 432 | +static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2, |
133 | +#include "qemu/log.h" | 433 | + int crn, int crm, int rt, int isread, |
134 | +#include "qemu/module.h" | 434 | + bool is_16bit) |
135 | + | 435 | +{ |
136 | +static WatchdogTimerModel model = { | 436 | + return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT) |
137 | + .wdt_name = TYPE_WDT_SBSA, | 437 | + | (is_16bit ? 0 : ARM_EL_IL) |
138 | + .wdt_description = "SBSA-compliant generic watchdog device", | 438 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) |
139 | +}; | 439 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; |
140 | + | 440 | +} |
141 | +static const VMStateDescription vmstate_sbsa_gwdt = { | 441 | + |
142 | + .name = "sbsa-gwdt", | 442 | +static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2, |
143 | + .version_id = 1, | 443 | + int crn, int crm, int rt, int isread, |
144 | + .minimum_version_id = 1, | 444 | + bool is_16bit) |
145 | + .fields = (VMStateField[]) { | 445 | +{ |
146 | + VMSTATE_TIMER_PTR(timer, SBSA_GWDTState), | 446 | + return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT) |
147 | + VMSTATE_UINT32(wcs, SBSA_GWDTState), | 447 | + | (is_16bit ? 0 : ARM_EL_IL) |
148 | + VMSTATE_UINT32(worl, SBSA_GWDTState), | 448 | + | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14) |
149 | + VMSTATE_UINT32(woru, SBSA_GWDTState), | 449 | + | (crn << 10) | (rt << 5) | (crm << 1) | isread; |
150 | + VMSTATE_UINT32(wcvl, SBSA_GWDTState), | 450 | +} |
151 | + VMSTATE_UINT32(wcvu, SBSA_GWDTState), | 451 | + |
152 | + VMSTATE_END_OF_LIST() | 452 | +static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm, |
153 | + } | 453 | + int rt, int rt2, int isread, |
154 | +}; | 454 | + bool is_16bit) |
155 | + | 455 | +{ |
156 | +typedef enum WdtRefreshType { | 456 | + return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT) |
157 | + EXPLICIT_REFRESH = 0, | 457 | + | (is_16bit ? 0 : ARM_EL_IL) |
158 | + TIMEOUT_REFRESH = 1, | 458 | + | (cv << 24) | (cond << 20) | (opc1 << 16) |
159 | +} WdtRefreshType; | 459 | + | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; |
160 | + | 460 | +} |
161 | +static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size) | 461 | + |
162 | +{ | 462 | +static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm, |
163 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | 463 | + int rt, int rt2, int isread, |
164 | + uint32_t ret = 0; | 464 | + bool is_16bit) |
165 | + | 465 | +{ |
166 | + switch (addr) { | 466 | + return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT) |
167 | + case SBSA_GWDT_WRR: | 467 | + | (is_16bit ? 0 : ARM_EL_IL) |
168 | + /* watch refresh read has no effect and returns 0 */ | 468 | + | (cv << 24) | (cond << 20) | (opc1 << 16) |
169 | + ret = 0; | 469 | + | (rt2 << 10) | (rt << 5) | (crm << 1) | isread; |
170 | + break; | 470 | +} |
171 | + case SBSA_GWDT_W_IIDR: | 471 | + |
172 | + ret = s->id; | 472 | +static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit) |
173 | + break; | 473 | +{ |
174 | + default: | 474 | + /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */ |
175 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame read :" | 475 | + return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) |
176 | + " 0x%x\n", (int)addr); | 476 | + | (is_16bit ? 0 : ARM_EL_IL) |
177 | + } | 477 | + | (cv << 24) | (cond << 20) | 0xa; |
178 | + return ret; | 478 | +} |
179 | +} | 479 | + |
180 | + | 480 | +static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit) |
181 | +static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size) | 481 | +{ |
182 | +{ | 482 | + /* AArch32 SIMD trap: TA == 1 coproc == 0 */ |
183 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | 483 | + return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) |
184 | + uint32_t ret = 0; | 484 | + | (is_16bit ? 0 : ARM_EL_IL) |
185 | + | 485 | + | (cv << 24) | (cond << 20) | (1 << 5); |
186 | + switch (addr) { | 486 | +} |
187 | + case SBSA_GWDT_WCS: | 487 | + |
188 | + ret = s->wcs; | 488 | +static inline uint32_t syn_sve_access_trap(void) |
189 | + break; | 489 | +{ |
190 | + case SBSA_GWDT_WOR: | 490 | + return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; |
191 | + ret = s->worl; | 491 | +} |
192 | + break; | 492 | + |
193 | + case SBSA_GWDT_WORU: | 493 | +static inline uint32_t syn_pactrap(void) |
194 | + ret = s->woru; | 494 | +{ |
195 | + break; | 495 | + return EC_PACTRAP << ARM_EL_EC_SHIFT; |
196 | + case SBSA_GWDT_WCV: | 496 | +} |
197 | + ret = s->wcvl; | 497 | + |
198 | + break; | 498 | +static inline uint32_t syn_btitrap(int btype) |
199 | + case SBSA_GWDT_WCVU: | 499 | +{ |
200 | + ret = s->wcvu; | 500 | + return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype; |
201 | + break; | 501 | +} |
202 | + case SBSA_GWDT_W_IIDR: | 502 | + |
203 | + ret = s->id; | 503 | +static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) |
204 | + break; | 504 | +{ |
205 | + default: | 505 | + return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
206 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame read :" | 506 | + | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc; |
207 | + " 0x%x\n", (int)addr); | 507 | +} |
208 | + } | 508 | + |
209 | + return ret; | 509 | +static inline uint32_t syn_data_abort_no_iss(int same_el, int fnv, |
210 | +} | 510 | + int ea, int cm, int s1ptw, |
211 | + | 511 | + int wnr, int fsc) |
212 | +static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype) | 512 | +{ |
213 | +{ | 513 | + return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
214 | + uint64_t timeout = 0; | 514 | + | ARM_EL_IL |
215 | + | 515 | + | (fnv << 10) | (ea << 9) | (cm << 8) | (s1ptw << 7) |
216 | + timer_del(s->timer); | 516 | + | (wnr << 6) | fsc; |
217 | + | 517 | +} |
218 | + if (s->wcs & SBSA_GWDT_WCS_EN) { | 518 | + |
219 | + /* | 519 | +static inline uint32_t syn_data_abort_with_iss(int same_el, |
220 | + * Extract the upper 16 bits from woru & 32 bits from worl | 520 | + int sas, int sse, int srt, |
221 | + * registers to construct the 48 bit offset value | 521 | + int sf, int ar, |
222 | + */ | 522 | + int ea, int cm, int s1ptw, |
223 | + timeout = s->woru; | 523 | + int wnr, int fsc, |
224 | + timeout <<= 32; | 524 | + bool is_16bit) |
225 | + timeout |= s->worl; | 525 | +{ |
226 | + timeout = muldiv64(timeout, NANOSECONDS_PER_SECOND, SBSA_TIMER_FREQ); | 526 | + return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
227 | + timeout += qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 527 | + | (is_16bit ? 0 : ARM_EL_IL) |
228 | + | 528 | + | ARM_EL_ISV | (sas << 22) | (sse << 21) | (srt << 16) |
229 | + if ((rtype == EXPLICIT_REFRESH) || ((rtype == TIMEOUT_REFRESH) && | 529 | + | (sf << 15) | (ar << 14) |
230 | + (!(s->wcs & SBSA_GWDT_WCS_WS0)))) { | 530 | + | (ea << 9) | (cm << 8) | (s1ptw << 7) | (wnr << 6) | fsc; |
231 | + /* store the current timeout value into compare registers */ | 531 | +} |
232 | + s->wcvu = timeout >> 32; | 532 | + |
233 | + s->wcvl = timeout; | 533 | +static inline uint32_t syn_swstep(int same_el, int isv, int ex) |
234 | + } | 534 | +{ |
235 | + timer_mod(s->timer, timeout); | 535 | + return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
236 | + } | 536 | + | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22; |
237 | +} | 537 | +} |
238 | + | 538 | + |
239 | +static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data, | 539 | +static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr) |
240 | + unsigned size) { | 540 | +{ |
241 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | 541 | + return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
242 | + | 542 | + | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22; |
243 | + if (offset == SBSA_GWDT_WRR) { | 543 | +} |
244 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | 544 | + |
245 | + | 545 | +static inline uint32_t syn_breakpoint(int same_el) |
246 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | 546 | +{ |
247 | + } else { | 547 | + return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) |
248 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :" | 548 | + | ARM_EL_IL | 0x22; |
249 | + " 0x%x\n", (int)offset); | 549 | +} |
250 | + } | 550 | + |
251 | +} | 551 | +static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit) |
252 | + | 552 | +{ |
253 | +static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data, | 553 | + return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) | |
254 | + unsigned size) { | 554 | + (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) | |
255 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | 555 | + (cv << 24) | (cond << 20) | ti; |
256 | + | 556 | +} |
257 | + switch (offset) { | 557 | + |
258 | + case SBSA_GWDT_WCS: | 558 | +#endif /* TARGET_ARM_SYNDROME_H */ |
259 | + s->wcs = data & SBSA_GWDT_WCS_EN; | ||
260 | + qemu_set_irq(s->irq, 0); | ||
261 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
262 | + break; | ||
263 | + | ||
264 | + case SBSA_GWDT_WOR: | ||
265 | + s->worl = data; | ||
266 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
267 | + qemu_set_irq(s->irq, 0); | ||
268 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
269 | + break; | ||
270 | + | ||
271 | + case SBSA_GWDT_WORU: | ||
272 | + s->woru = data & SBSA_GWDT_WOR_MASK; | ||
273 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
274 | + qemu_set_irq(s->irq, 0); | ||
275 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
276 | + break; | ||
277 | + | ||
278 | + case SBSA_GWDT_WCV: | ||
279 | + s->wcvl = data; | ||
280 | + break; | ||
281 | + | ||
282 | + case SBSA_GWDT_WCVU: | ||
283 | + s->wcvu = data; | ||
284 | + break; | ||
285 | + | ||
286 | + default: | ||
287 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame write :" | ||
288 | + " 0x%x\n", (int)offset); | ||
289 | + } | ||
290 | + return; | ||
291 | +} | ||
292 | + | ||
293 | +static void wdt_sbsa_gwdt_reset(DeviceState *dev) | ||
294 | +{ | ||
295 | + SBSA_GWDTState *s = SBSA_GWDT(dev); | ||
296 | + | ||
297 | + timer_del(s->timer); | ||
298 | + | ||
299 | + s->wcs = 0; | ||
300 | + s->wcvl = 0; | ||
301 | + s->wcvu = 0; | ||
302 | + s->worl = 0; | ||
303 | + s->woru = 0; | ||
304 | + s->id = SBSA_GWDT_ID; | ||
305 | +} | ||
306 | + | ||
307 | +static void sbsa_gwdt_timer_sysinterrupt(void *opaque) | ||
308 | +{ | ||
309 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
310 | + | ||
311 | + if (!(s->wcs & SBSA_GWDT_WCS_WS0)) { | ||
312 | + s->wcs |= SBSA_GWDT_WCS_WS0; | ||
313 | + sbsa_gwdt_update_timer(s, TIMEOUT_REFRESH); | ||
314 | + qemu_set_irq(s->irq, 1); | ||
315 | + } else { | ||
316 | + s->wcs |= SBSA_GWDT_WCS_WS1; | ||
317 | + qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n"); | ||
318 | + /* | ||
319 | + * Reset the watchdog only if the guest gets notified about | ||
320 | + * expiry. watchdog_perform_action() may temporarily relinquish | ||
321 | + * the BQL; reset before triggering the action to avoid races with | ||
322 | + * sbsa_gwdt instructions. | ||
323 | + */ | ||
324 | + switch (get_watchdog_action()) { | ||
325 | + case WATCHDOG_ACTION_DEBUG: | ||
326 | + case WATCHDOG_ACTION_NONE: | ||
327 | + case WATCHDOG_ACTION_PAUSE: | ||
328 | + break; | ||
329 | + default: | ||
330 | + wdt_sbsa_gwdt_reset(DEVICE(s)); | ||
331 | + } | ||
332 | + watchdog_perform_action(); | ||
333 | + } | ||
334 | +} | ||
335 | + | ||
336 | +static const MemoryRegionOps sbsa_gwdt_rops = { | ||
337 | + .read = sbsa_gwdt_rread, | ||
338 | + .write = sbsa_gwdt_rwrite, | ||
339 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
340 | + .valid.min_access_size = 4, | ||
341 | + .valid.max_access_size = 4, | ||
342 | + .valid.unaligned = false, | ||
343 | +}; | ||
344 | + | ||
345 | +static const MemoryRegionOps sbsa_gwdt_ops = { | ||
346 | + .read = sbsa_gwdt_read, | ||
347 | + .write = sbsa_gwdt_write, | ||
348 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
349 | + .valid.min_access_size = 4, | ||
350 | + .valid.max_access_size = 4, | ||
351 | + .valid.unaligned = false, | ||
352 | +}; | ||
353 | + | ||
354 | +static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp) | ||
355 | +{ | ||
356 | + SBSA_GWDTState *s = SBSA_GWDT(dev); | ||
357 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
358 | + | ||
359 | + memory_region_init_io(&s->rmmio, OBJECT(dev), | ||
360 | + &sbsa_gwdt_rops, s, | ||
361 | + "sbsa_gwdt.refresh", | ||
362 | + SBSA_GWDT_RMMIO_SIZE); | ||
363 | + | ||
364 | + memory_region_init_io(&s->cmmio, OBJECT(dev), | ||
365 | + &sbsa_gwdt_ops, s, | ||
366 | + "sbsa_gwdt.control", | ||
367 | + SBSA_GWDT_CMMIO_SIZE); | ||
368 | + | ||
369 | + sysbus_init_mmio(sbd, &s->rmmio); | ||
370 | + sysbus_init_mmio(sbd, &s->cmmio); | ||
371 | + | ||
372 | + sysbus_init_irq(sbd, &s->irq); | ||
373 | + | ||
374 | + s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sbsa_gwdt_timer_sysinterrupt, | ||
375 | + dev); | ||
376 | +} | ||
377 | + | ||
378 | +static void wdt_sbsa_gwdt_class_init(ObjectClass *klass, void *data) | ||
379 | +{ | ||
380 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
381 | + | ||
382 | + dc->realize = wdt_sbsa_gwdt_realize; | ||
383 | + dc->reset = wdt_sbsa_gwdt_reset; | ||
384 | + dc->hotpluggable = false; | ||
385 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
386 | + dc->vmsd = &vmstate_sbsa_gwdt; | ||
387 | +} | ||
388 | + | ||
389 | +static const TypeInfo wdt_sbsa_gwdt_info = { | ||
390 | + .class_init = wdt_sbsa_gwdt_class_init, | ||
391 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
392 | + .name = TYPE_WDT_SBSA, | ||
393 | + .instance_size = sizeof(SBSA_GWDTState), | ||
394 | +}; | ||
395 | + | ||
396 | +static void wdt_sbsa_gwdt_register_types(void) | ||
397 | +{ | ||
398 | + watchdog_add_model(&model); | ||
399 | + type_register_static(&wdt_sbsa_gwdt_info); | ||
400 | +} | ||
401 | + | ||
402 | +type_init(wdt_sbsa_gwdt_register_types) | ||
403 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
404 | index XXXXXXX..XXXXXXX 100644 | ||
405 | --- a/hw/arm/Kconfig | ||
406 | +++ b/hw/arm/Kconfig | ||
407 | @@ -XXX,XX +XXX,XX @@ config SBSA_REF | ||
408 | select PL031 # RTC | ||
409 | select PL061 # GPIO | ||
410 | select USB_EHCI_SYSBUS | ||
411 | + select WDT_SBSA | ||
412 | |||
413 | config SABRELITE | ||
414 | bool | ||
415 | diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig | ||
416 | index XXXXXXX..XXXXXXX 100644 | ||
417 | --- a/hw/watchdog/Kconfig | ||
418 | +++ b/hw/watchdog/Kconfig | ||
419 | @@ -XXX,XX +XXX,XX @@ config WDT_DIAG288 | ||
420 | |||
421 | config WDT_IMX2 | ||
422 | bool | ||
423 | + | ||
424 | +config WDT_SBSA | ||
425 | + bool | ||
426 | diff --git a/hw/watchdog/meson.build b/hw/watchdog/meson.build | ||
427 | index XXXXXXX..XXXXXXX 100644 | ||
428 | --- a/hw/watchdog/meson.build | ||
429 | +++ b/hw/watchdog/meson.build | ||
430 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c')) | ||
431 | softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) | ||
432 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) | ||
433 | softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) | ||
434 | +softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c')) | ||
435 | -- | 559 | -- |
436 | 2.20.1 | 560 | 2.20.1 |
437 | 561 | ||
438 | 562 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The realize() function is clearly composed of two parts, | 3 | A proper syndrome is required to fill in the proper si_code. |
4 | each described by a comment: | 4 | Use page_get_flags to determine permission vs translation for user-only. |
5 | 5 | ||
6 | void realize() | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | { | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | /* common peripherals from bcm2835 */ | 8 | Message-id: 20210212184902.1251044-27-richard.henderson@linaro.org |
9 | ... | ||
10 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
11 | ... | ||
12 | } | ||
13 | |||
14 | Split the two part, so we can reuse the common part with other | ||
15 | SoCs from this family. | ||
16 | |||
17 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Message-id: 20201024170127.3592182-6-f4bug@amsat.org | ||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 10 | --- |
22 | hw/arm/bcm2836.c | 22 ++++++++++++++++++---- | 11 | linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++--- |
23 | 1 file changed, 18 insertions(+), 4 deletions(-) | 12 | target/arm/tlb_helper.c | 15 +++++++++------ |
13 | 2 files changed, 30 insertions(+), 9 deletions(-) | ||
24 | 14 | ||
25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | 15 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
26 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/arm/bcm2836.c | 17 | --- a/linux-user/aarch64/cpu_loop.c |
28 | +++ b/hw/arm/bcm2836.c | 18 | +++ b/linux-user/aarch64/cpu_loop.c |
29 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | 19 | @@ -XXX,XX +XXX,XX @@ |
30 | qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); | 20 | #include "cpu_loop-common.h" |
21 | #include "qemu/guest-random.h" | ||
22 | #include "hw/semihosting/common-semi.h" | ||
23 | +#include "target/arm/syndrome.h" | ||
24 | |||
25 | #define get_user_code_u32(x, gaddr, env) \ | ||
26 | ({ abi_long __r = get_user_u32((x), (gaddr)); \ | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | void cpu_loop(CPUARMState *env) | ||
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; | ||
43 | + | ||
44 | + /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ | ||
45 | + ec = syn_get_ec(env->exception.syndrome); | ||
46 | + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); | ||
47 | + | ||
48 | + /* Both EC have the same format for FSC, or close enough. */ | ||
49 | + fsc = extract32(env->exception.syndrome, 0, 6); | ||
50 | + switch (fsc) { | ||
51 | + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ | ||
52 | + info.si_code = TARGET_SEGV_MAPERR; | ||
53 | + break; | ||
54 | + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ | ||
55 | + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ | ||
56 | + info.si_code = TARGET_SEGV_ACCERR; | ||
57 | + break; | ||
58 | + default: | ||
59 | + g_assert_not_reached(); | ||
60 | + } | ||
61 | + | ||
62 | queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | ||
63 | break; | ||
64 | case EXCP_DEBUG: | ||
65 | diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/arm/tlb_helper.c | ||
68 | +++ b/target/arm/tlb_helper.c | ||
69 | @@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
70 | bool probe, uintptr_t retaddr) | ||
71 | { | ||
72 | ARMCPU *cpu = ARM_CPU(cs); | ||
73 | + ARMMMUFaultInfo fi = {}; | ||
74 | |||
75 | #ifdef CONFIG_USER_ONLY | ||
76 | - cpu->env.exception.vaddress = address; | ||
77 | - if (access_type == MMU_INST_FETCH) { | ||
78 | - cs->exception_index = EXCP_PREFETCH_ABORT; | ||
79 | + int flags = page_get_flags(useronly_clean_ptr(address)); | ||
80 | + if (flags & PAGE_VALID) { | ||
81 | + fi.type = ARMFault_Permission; | ||
82 | } else { | ||
83 | - cs->exception_index = EXCP_DATA_ABORT; | ||
84 | + fi.type = ARMFault_Translation; | ||
31 | } | 85 | } |
32 | 86 | - cpu_loop_exit_restore(cs, retaddr); | |
33 | - object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
34 | + if (bc->ctrl_base) { | ||
35 | + object_initialize_child(obj, "control", &s->control, | ||
36 | + TYPE_BCM2836_CONTROL); | ||
37 | + } | ||
38 | |||
39 | object_initialize_child(obj, "peripherals", &s->peripherals, | ||
40 | TYPE_BCM2835_PERIPHERALS); | ||
41 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
42 | "vcram-size"); | ||
43 | } | ||
44 | |||
45 | -static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
46 | +static bool bcm283x_common_realize(DeviceState *dev, Error **errp) | ||
47 | { | ||
48 | BCM283XState *s = BCM283X(dev); | ||
49 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
50 | Object *obj; | ||
51 | - int n; | ||
52 | |||
53 | /* common peripherals from bcm2835 */ | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
56 | object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj); | ||
57 | |||
58 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) { | ||
59 | - return; | ||
60 | + return false; | ||
61 | } | ||
62 | |||
63 | object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals), | ||
64 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
65 | |||
66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
67 | bc->peri_base, 1); | ||
68 | + return true; | ||
69 | +} | ||
70 | + | 87 | + |
71 | +static void bcm2836_realize(DeviceState *dev, Error **errp) | 88 | + /* now we have a real cpu fault */ |
72 | +{ | 89 | + cpu_restore_state(cs, retaddr, true); |
73 | + BCM283XState *s = BCM283X(dev); | 90 | + arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi); |
74 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); | 91 | #else |
75 | + int n; | 92 | hwaddr phys_addr; |
76 | + | 93 | target_ulong page_size; |
77 | + if (!bcm283x_common_realize(dev, errp)) { | 94 | int prot, ret; |
78 | + return; | 95 | MemTxAttrs attrs = {}; |
79 | + } | 96 | - ARMMMUFaultInfo fi = {}; |
80 | 97 | ARMCacheAttrs cacheattrs = {}; | |
81 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | 98 | |
82 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { | 99 | /* |
83 | -- | 100 | -- |
84 | 2.20.1 | 101 | 2.20.1 |
85 | 102 | ||
86 | 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 | Fixing this now will clarify following patches. | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20201021173749.111103-6-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-28-richard.henderson@linaro.org |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 7 | --- |
10 | linux-user/elfload.c | 12 +++++++++--- | 8 | linux-user/aarch64/target_signal.h | 2 ++ |
11 | 1 file changed, 9 insertions(+), 3 deletions(-) | 9 | linux-user/aarch64/cpu_loop.c | 3 +++ |
10 | 2 files changed, 5 insertions(+) | ||
12 | 11 | ||
13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 12 | diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h |
14 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/linux-user/elfload.c | 14 | --- a/linux-user/aarch64/target_signal.h |
16 | +++ b/linux-user/elfload.c | 15 | +++ b/linux-user/aarch64/target_signal.h |
17 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
18 | abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; | 17 | |
19 | int elf_prot = 0; | 18 | #include "../generic/signal.h" |
20 | 19 | ||
21 | - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; | 20 | +#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
22 | - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; | 21 | + |
23 | - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; | 22 | #define TARGET_ARCH_HAS_SETUP_FRAME |
24 | + if (eppnt->p_flags & PF_R) { | 23 | #endif /* AARCH64_TARGET_SIGNAL_H */ |
25 | + elf_prot |= PROT_READ; | 24 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
26 | + } | 25 | index XXXXXXX..XXXXXXX 100644 |
27 | + if (eppnt->p_flags & PF_W) { | 26 | --- a/linux-user/aarch64/cpu_loop.c |
28 | + elf_prot |= PROT_WRITE; | 27 | +++ b/linux-user/aarch64/cpu_loop.c |
29 | + } | 28 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env) |
30 | + if (eppnt->p_flags & PF_X) { | 29 | case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ |
31 | + elf_prot |= PROT_EXEC; | 30 | info.si_code = TARGET_SEGV_ACCERR; |
32 | + } | 31 | break; |
33 | 32 | + case 0x11: /* Synchronous Tag Check Fault */ | |
34 | vaddr = load_bias + eppnt->p_vaddr; | 33 | + info.si_code = TARGET_SEGV_MTESERR; |
35 | vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); | 34 | + break; |
35 | default: | ||
36 | g_assert_not_reached(); | ||
37 | } | ||
36 | -- | 38 | -- |
37 | 2.20.1 | 39 | 2.20.1 |
38 | 40 | ||
39 | 41 | 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 kernel sets btype for the signal handler as if for a call. | 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. | ||
4 | 13 | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 15 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20201021173749.111103-2-richard.henderson@linaro.org | 16 | Message-id: 20210212184902.1251044-29-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 18 | --- |
10 | linux-user/aarch64/signal.c | 10 ++++++++-- | 19 | linux-user/aarch64/target_signal.h | 1 + |
11 | 1 file changed, 8 insertions(+), 2 deletions(-) | 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/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c | 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/linux-user/aarch64/signal.c | 26 | --- a/linux-user/aarch64/target_signal.h |
16 | +++ b/linux-user/aarch64/signal.c | 27 | +++ b/linux-user/aarch64/target_signal.h |
17 | @@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka, | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack { |
18 | + offsetof(struct target_rt_frame_record, tramp); | 29 | |
19 | } | 30 | #include "../generic/signal.h" |
20 | env->xregs[0] = usig; | 31 | |
21 | - env->xregs[31] = frame_addr; | 32 | +#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */ |
22 | env->xregs[29] = frame_addr + fr_ofs; | 33 | #define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */ |
23 | - env->pc = ka->_sa_handler; | 34 | |
24 | env->xregs[30] = return_addr; | 35 | #define TARGET_ARCH_HAS_SETUP_FRAME |
25 | + env->xregs[31] = frame_addr; | 36 | diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c |
26 | + env->pc = ka->_sa_handler; | 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 | } | ||
27 | + | 44 | + |
28 | + /* Invoke the signal handler as if by indirect call. */ | 45 | + /* Check for MTE asynchronous faults */ |
29 | + if (cpu_isar_feature(aa64_bti, env_archcpu(env))) { | 46 | + if (unlikely(env->cp15.tfsr_el[0])) { |
30 | + env->btype = 2; | 47 | + env->cp15.tfsr_el[0] = 0; |
31 | + } | 48 | + info.si_signo = TARGET_SIGSEGV; |
49 | + info.si_errno = 0; | ||
50 | + info._sifields._sigfault._addr = 0; | ||
51 | + info.si_code = TARGET_SEGV_MTEAERR; | ||
52 | + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); | ||
53 | + } | ||
32 | + | 54 | + |
33 | if (info) { | 55 | process_pending_signals(env); |
34 | tswap_siginfo(&frame->info, info); | 56 | /* Exception return on AArch64 always clears the exclusive monitor, |
35 | env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info); | 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)); | ||
75 | +#endif | ||
76 | break; | ||
77 | |||
78 | default: | ||
36 | -- | 79 | -- |
37 | 2.20.1 | 80 | 2.20.1 |
38 | 81 | ||
39 | 82 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The clock multiplexers are the last clock stage in the CPRMAN. Each mux | 3 | Use the now-saved PAGE_ANON and PAGE_MTE bits, |
4 | outputs one clock signal that goes out of the CPRMAN to the SoC | 4 | and the per-page saved data. |
5 | peripherals. | ||
6 | 5 | ||
7 | Each mux has at most 10 sources. The sources 0 to 3 are common to all | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | muxes. They are: | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | 0. ground (no clock signal) | 8 | Message-id: 20210212184902.1251044-30-richard.henderson@linaro.org |
10 | 1. the main oscillator (xosc) | ||
11 | 2. "test debug 0" clock | ||
12 | 3. "test debug 1" clock | ||
13 | |||
14 | Test debug 0 and 1 are actual clock muxes that can be used as sources to | ||
15 | other muxes (for debug purpose). | ||
16 | |||
17 | Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those | ||
18 | sources are fed by the PLL channels outputs. | ||
19 | |||
20 | One corner case exists for DSI0E and DSI0P muxes. They have their source | ||
21 | number 4 connected to an intermediate multiplexer that can select | ||
22 | between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called | ||
23 | DSI0HSCK and is not a clock mux as such. It is really a simple mux from | ||
24 | the hardware point of view (see https://elinux.org/The_Undocumented_Pi). | ||
25 | This mux is not implemented in this commit. | ||
26 | |||
27 | Note that there is some muxes for which sources are unknown (because of | ||
28 | a lack of documentation). For those cases all the sources are connected | ||
29 | to ground in this implementation. | ||
30 | |||
31 | Each clock mux output is exported by the CPRMAN at the qdev level, | ||
32 | adding the suffix '-out' to the mux name to form the output clock name. | ||
33 | (E.g. the 'uart' mux sees its output exported as 'uart-out' at the | ||
34 | CPRMAN level.) | ||
35 | |||
36 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
38 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
39 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
40 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
41 | --- | 10 | --- |
42 | include/hw/misc/bcm2835_cprman.h | 85 +++++ | 11 | target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++-- |
43 | include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ | 12 | 1 file changed, 27 insertions(+), 2 deletions(-) |
44 | hw/misc/bcm2835_cprman.c | 151 ++++++++ | ||
45 | 3 files changed, 658 insertions(+) | ||
46 | 13 | ||
47 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 14 | diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c |
48 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/include/hw/misc/bcm2835_cprman.h | 16 | --- a/target/arm/mte_helper.c |
50 | +++ b/include/hw/misc/bcm2835_cprman.h | 17 | +++ b/target/arm/mte_helper.c |
51 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel { | 18 | @@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, |
52 | CPRMAN_PLLB_CHANNEL_ARM, | 19 | int tag_size, uintptr_t ra) |
53 | 20 | { | |
54 | CPRMAN_NUM_PLL_CHANNEL, | 21 | #ifdef CONFIG_USER_ONLY |
22 | - /* Tag storage not implemented. */ | ||
23 | - return NULL; | ||
24 | + uint64_t clean_ptr = useronly_clean_ptr(ptr); | ||
25 | + int flags = page_get_flags(clean_ptr); | ||
26 | + uint8_t *tags; | ||
27 | + uintptr_t index; | ||
55 | + | 28 | + |
56 | + /* Special values used when connecting clock sources to clocks */ | 29 | + if (!(flags & (ptr_access == MMU_DATA_STORE ? PAGE_WRITE : PAGE_READ))) { |
57 | + CPRMAN_CLOCK_SRC_NORMAL = -1, | 30 | + /* SIGSEGV */ |
58 | + CPRMAN_CLOCK_SRC_FORCE_GROUND = -2, | 31 | + arm_cpu_tlb_fill(env_cpu(env), ptr, ptr_size, ptr_access, |
59 | + CPRMAN_CLOCK_SRC_DSI0HSCK = -3, | 32 | + ptr_mmu_idx, false, ra); |
60 | } CprmanPllChannel; | 33 | + g_assert_not_reached(); |
61 | |||
62 | +typedef enum CprmanClockMux { | ||
63 | + CPRMAN_CLOCK_GNRIC, | ||
64 | + CPRMAN_CLOCK_VPU, | ||
65 | + CPRMAN_CLOCK_SYS, | ||
66 | + CPRMAN_CLOCK_PERIA, | ||
67 | + CPRMAN_CLOCK_PERII, | ||
68 | + CPRMAN_CLOCK_H264, | ||
69 | + CPRMAN_CLOCK_ISP, | ||
70 | + CPRMAN_CLOCK_V3D, | ||
71 | + CPRMAN_CLOCK_CAM0, | ||
72 | + CPRMAN_CLOCK_CAM1, | ||
73 | + CPRMAN_CLOCK_CCP2, | ||
74 | + CPRMAN_CLOCK_DSI0E, | ||
75 | + CPRMAN_CLOCK_DSI0P, | ||
76 | + CPRMAN_CLOCK_DPI, | ||
77 | + CPRMAN_CLOCK_GP0, | ||
78 | + CPRMAN_CLOCK_GP1, | ||
79 | + CPRMAN_CLOCK_GP2, | ||
80 | + CPRMAN_CLOCK_HSM, | ||
81 | + CPRMAN_CLOCK_OTP, | ||
82 | + CPRMAN_CLOCK_PCM, | ||
83 | + CPRMAN_CLOCK_PWM, | ||
84 | + CPRMAN_CLOCK_SLIM, | ||
85 | + CPRMAN_CLOCK_SMI, | ||
86 | + CPRMAN_CLOCK_TEC, | ||
87 | + CPRMAN_CLOCK_TD0, | ||
88 | + CPRMAN_CLOCK_TD1, | ||
89 | + CPRMAN_CLOCK_TSENS, | ||
90 | + CPRMAN_CLOCK_TIMER, | ||
91 | + CPRMAN_CLOCK_UART, | ||
92 | + CPRMAN_CLOCK_VEC, | ||
93 | + CPRMAN_CLOCK_PULSE, | ||
94 | + CPRMAN_CLOCK_SDC, | ||
95 | + CPRMAN_CLOCK_ARM, | ||
96 | + CPRMAN_CLOCK_AVEO, | ||
97 | + CPRMAN_CLOCK_EMMC, | ||
98 | + CPRMAN_CLOCK_EMMC2, | ||
99 | + | ||
100 | + CPRMAN_NUM_CLOCK_MUX | ||
101 | +} CprmanClockMux; | ||
102 | + | ||
103 | +typedef enum CprmanClockMuxSource { | ||
104 | + CPRMAN_CLOCK_SRC_GND = 0, | ||
105 | + CPRMAN_CLOCK_SRC_XOSC, | ||
106 | + CPRMAN_CLOCK_SRC_TD0, | ||
107 | + CPRMAN_CLOCK_SRC_TD1, | ||
108 | + CPRMAN_CLOCK_SRC_PLLA, | ||
109 | + CPRMAN_CLOCK_SRC_PLLC, | ||
110 | + CPRMAN_CLOCK_SRC_PLLD, | ||
111 | + CPRMAN_CLOCK_SRC_PLLH, | ||
112 | + CPRMAN_CLOCK_SRC_PLLC_CORE1, | ||
113 | + CPRMAN_CLOCK_SRC_PLLC_CORE2, | ||
114 | + | ||
115 | + CPRMAN_NUM_CLOCK_MUX_SRC | ||
116 | +} CprmanClockMuxSource; | ||
117 | + | ||
118 | typedef struct CprmanPllState { | ||
119 | /*< private >*/ | ||
120 | DeviceState parent_obj; | ||
121 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllChannelState { | ||
122 | Clock *out; | ||
123 | } CprmanPllChannelState; | ||
124 | |||
125 | +typedef struct CprmanClockMuxState { | ||
126 | + /*< private >*/ | ||
127 | + DeviceState parent_obj; | ||
128 | + | ||
129 | + /*< public >*/ | ||
130 | + CprmanClockMux id; | ||
131 | + | ||
132 | + uint32_t *reg_ctl; | ||
133 | + uint32_t *reg_div; | ||
134 | + int int_bits; | ||
135 | + int frac_bits; | ||
136 | + | ||
137 | + Clock *srcs[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
138 | + Clock *out; | ||
139 | + | ||
140 | + /* | ||
141 | + * Used by clock srcs update callback to retrieve both the clock and the | ||
142 | + * source number. | ||
143 | + */ | ||
144 | + struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
145 | +} CprmanClockMuxState; | ||
146 | + | ||
147 | struct BCM2835CprmanState { | ||
148 | /*< private >*/ | ||
149 | SysBusDevice parent_obj; | ||
150 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
151 | |||
152 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
153 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
154 | + CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; | ||
155 | |||
156 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
157 | uint32_t xosc_freq; | ||
158 | |||
159 | Clock *xosc; | ||
160 | + Clock *gnd; | ||
161 | }; | ||
162 | |||
163 | #endif | ||
164 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
167 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
168 | @@ -XXX,XX +XXX,XX @@ | ||
169 | |||
170 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | ||
171 | #define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | ||
172 | +#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux" | ||
173 | |||
174 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | ||
175 | TYPE_CPRMAN_PLL) | ||
176 | DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, | ||
177 | TYPE_CPRMAN_PLL_CHANNEL) | ||
178 | +DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX, | ||
179 | + TYPE_CPRMAN_CLOCK_MUX) | ||
180 | |||
181 | /* Register map */ | ||
182 | |||
183 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLH_STS, 0x1660) | ||
184 | |||
185 | REG32(A2W_PLLB_ARM, 0x13e0) | ||
186 | |||
187 | +/* Clock muxes */ | ||
188 | +REG32(CM_GNRICCTL, 0x000) | ||
189 | + FIELD(CM_CLOCKx_CTL, SRC, 0, 4) | ||
190 | + FIELD(CM_CLOCKx_CTL, ENABLE, 4, 1) | ||
191 | + FIELD(CM_CLOCKx_CTL, KILL, 5, 1) | ||
192 | + FIELD(CM_CLOCKx_CTL, GATE, 6, 1) | ||
193 | + FIELD(CM_CLOCKx_CTL, BUSY, 7, 1) | ||
194 | + FIELD(CM_CLOCKx_CTL, BUSYD, 8, 1) | ||
195 | + FIELD(CM_CLOCKx_CTL, MASH, 9, 2) | ||
196 | + FIELD(CM_CLOCKx_CTL, FLIP, 11, 1) | ||
197 | +REG32(CM_GNRICDIV, 0x004) | ||
198 | + FIELD(CM_CLOCKx_DIV, FRAC, 0, 12) | ||
199 | +REG32(CM_VPUCTL, 0x008) | ||
200 | +REG32(CM_VPUDIV, 0x00c) | ||
201 | +REG32(CM_SYSCTL, 0x010) | ||
202 | +REG32(CM_SYSDIV, 0x014) | ||
203 | +REG32(CM_PERIACTL, 0x018) | ||
204 | +REG32(CM_PERIADIV, 0x01c) | ||
205 | +REG32(CM_PERIICTL, 0x020) | ||
206 | +REG32(CM_PERIIDIV, 0x024) | ||
207 | +REG32(CM_H264CTL, 0x028) | ||
208 | +REG32(CM_H264DIV, 0x02c) | ||
209 | +REG32(CM_ISPCTL, 0x030) | ||
210 | +REG32(CM_ISPDIV, 0x034) | ||
211 | +REG32(CM_V3DCTL, 0x038) | ||
212 | +REG32(CM_V3DDIV, 0x03c) | ||
213 | +REG32(CM_CAM0CTL, 0x040) | ||
214 | +REG32(CM_CAM0DIV, 0x044) | ||
215 | +REG32(CM_CAM1CTL, 0x048) | ||
216 | +REG32(CM_CAM1DIV, 0x04c) | ||
217 | +REG32(CM_CCP2CTL, 0x050) | ||
218 | +REG32(CM_CCP2DIV, 0x054) | ||
219 | +REG32(CM_DSI0ECTL, 0x058) | ||
220 | +REG32(CM_DSI0EDIV, 0x05c) | ||
221 | +REG32(CM_DSI0PCTL, 0x060) | ||
222 | +REG32(CM_DSI0PDIV, 0x064) | ||
223 | +REG32(CM_DPICTL, 0x068) | ||
224 | +REG32(CM_DPIDIV, 0x06c) | ||
225 | +REG32(CM_GP0CTL, 0x070) | ||
226 | +REG32(CM_GP0DIV, 0x074) | ||
227 | +REG32(CM_GP1CTL, 0x078) | ||
228 | +REG32(CM_GP1DIV, 0x07c) | ||
229 | +REG32(CM_GP2CTL, 0x080) | ||
230 | +REG32(CM_GP2DIV, 0x084) | ||
231 | +REG32(CM_HSMCTL, 0x088) | ||
232 | +REG32(CM_HSMDIV, 0x08c) | ||
233 | +REG32(CM_OTPCTL, 0x090) | ||
234 | +REG32(CM_OTPDIV, 0x094) | ||
235 | +REG32(CM_PCMCTL, 0x098) | ||
236 | +REG32(CM_PCMDIV, 0x09c) | ||
237 | +REG32(CM_PWMCTL, 0x0a0) | ||
238 | +REG32(CM_PWMDIV, 0x0a4) | ||
239 | +REG32(CM_SLIMCTL, 0x0a8) | ||
240 | +REG32(CM_SLIMDIV, 0x0ac) | ||
241 | +REG32(CM_SMICTL, 0x0b0) | ||
242 | +REG32(CM_SMIDIV, 0x0b4) | ||
243 | +REG32(CM_TCNTCTL, 0x0c0) | ||
244 | +REG32(CM_TCNTCNT, 0x0c4) | ||
245 | +REG32(CM_TECCTL, 0x0c8) | ||
246 | +REG32(CM_TECDIV, 0x0cc) | ||
247 | +REG32(CM_TD0CTL, 0x0d0) | ||
248 | +REG32(CM_TD0DIV, 0x0d4) | ||
249 | +REG32(CM_TD1CTL, 0x0d8) | ||
250 | +REG32(CM_TD1DIV, 0x0dc) | ||
251 | +REG32(CM_TSENSCTL, 0x0e0) | ||
252 | +REG32(CM_TSENSDIV, 0x0e4) | ||
253 | +REG32(CM_TIMERCTL, 0x0e8) | ||
254 | +REG32(CM_TIMERDIV, 0x0ec) | ||
255 | +REG32(CM_UARTCTL, 0x0f0) | ||
256 | +REG32(CM_UARTDIV, 0x0f4) | ||
257 | +REG32(CM_VECCTL, 0x0f8) | ||
258 | +REG32(CM_VECDIV, 0x0fc) | ||
259 | +REG32(CM_PULSECTL, 0x190) | ||
260 | +REG32(CM_PULSEDIV, 0x194) | ||
261 | +REG32(CM_SDCCTL, 0x1a8) | ||
262 | +REG32(CM_SDCDIV, 0x1ac) | ||
263 | +REG32(CM_ARMCTL, 0x1b0) | ||
264 | +REG32(CM_AVEOCTL, 0x1b8) | ||
265 | +REG32(CM_AVEODIV, 0x1bc) | ||
266 | +REG32(CM_EMMCCTL, 0x1c0) | ||
267 | +REG32(CM_EMMCDIV, 0x1c4) | ||
268 | +REG32(CM_EMMC2CTL, 0x1d0) | ||
269 | +REG32(CM_EMMC2DIV, 0x1d4) | ||
270 | + | ||
271 | /* misc registers */ | ||
272 | REG32(CM_LOCK, 0x114) | ||
273 | FIELD(CM_LOCK, FLOCKH, 12, 1) | ||
274 | @@ -XXX,XX +XXX,XX @@ static inline void set_pll_channel_init_info(BCM2835CprmanState *s, | ||
275 | channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider; | ||
276 | } | ||
277 | |||
278 | +/* Clock mux init info */ | ||
279 | +typedef struct ClockMuxInitInfo { | ||
280 | + const char *name; | ||
281 | + size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */ | ||
282 | + int int_bits; | ||
283 | + int frac_bits; | ||
284 | + | ||
285 | + CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
286 | +} ClockMuxInitInfo; | ||
287 | + | ||
288 | +/* | ||
289 | + * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the | ||
290 | + * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not | ||
291 | + * always populated. The following macros catch all those cases. | ||
292 | + */ | ||
293 | + | ||
294 | +/* Unknown mapping. Connect everything to ground */ | ||
295 | +#define SRC_MAPPING_INFO_unknown \ | ||
296 | + .src_mapping = { \ | ||
297 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* gnd */ \ | ||
298 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* xosc */ \ | ||
299 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 0 */ \ | ||
300 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 1 */ \ | ||
301 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll a */ \ | ||
302 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c */ \ | ||
303 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll d */ \ | ||
304 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll h */ \ | ||
305 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core1 */ \ | ||
306 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core2 */ \ | ||
307 | + } | 34 | + } |
308 | + | 35 | + |
309 | +/* Only the oscillator and the two test debug clocks */ | 36 | + /* Require both MAP_ANON and PROT_MTE for the page. */ |
310 | +#define SRC_MAPPING_INFO_xosc \ | 37 | + if (!(flags & PAGE_ANON) || !(flags & PAGE_MTE)) { |
311 | + .src_mapping = { \ | 38 | + return NULL; |
312 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
313 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
314 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
315 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
316 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
317 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
318 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
319 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
320 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
321 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
322 | + } | 39 | + } |
323 | + | 40 | + |
324 | +/* All the PLL "core" channels */ | 41 | + tags = page_get_target_data(clean_ptr); |
325 | +#define SRC_MAPPING_INFO_core \ | 42 | + if (tags == NULL) { |
326 | + .src_mapping = { \ | 43 | + size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); |
327 | + CPRMAN_CLOCK_SRC_NORMAL, \ | 44 | + tags = page_alloc_target_data(clean_ptr, alloc_size); |
328 | + CPRMAN_CLOCK_SRC_NORMAL, \ | 45 | + assert(tags != NULL); |
329 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
330 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
331 | + CPRMAN_PLLA_CHANNEL_CORE, \ | ||
332 | + CPRMAN_PLLC_CHANNEL_CORE0, \ | ||
333 | + CPRMAN_PLLD_CHANNEL_CORE, \ | ||
334 | + CPRMAN_PLLH_CHANNEL_AUX, \ | ||
335 | + CPRMAN_PLLC_CHANNEL_CORE1, \ | ||
336 | + CPRMAN_PLLC_CHANNEL_CORE2, \ | ||
337 | + } | 46 | + } |
338 | + | 47 | + |
339 | +/* All the PLL "per" channels */ | 48 | + index = extract32(ptr, LOG2_TAG_GRANULE + 1, |
340 | +#define SRC_MAPPING_INFO_periph \ | 49 | + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); |
341 | + .src_mapping = { \ | 50 | + return tags + index; |
342 | + CPRMAN_CLOCK_SRC_NORMAL, \ | 51 | #else |
343 | + CPRMAN_CLOCK_SRC_NORMAL, \ | 52 | uintptr_t index; |
344 | + CPRMAN_CLOCK_SRC_NORMAL, \ | 53 | CPUIOTLBEntry *iotlbentry; |
345 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
346 | + CPRMAN_PLLA_CHANNEL_PER, \ | ||
347 | + CPRMAN_PLLC_CHANNEL_PER, \ | ||
348 | + CPRMAN_PLLD_CHANNEL_PER, \ | ||
349 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
350 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
351 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
352 | + } | ||
353 | + | ||
354 | +/* | ||
355 | + * The DSI0 channels. This one got an intermediate mux between the PLL channels | ||
356 | + * and the clock input. | ||
357 | + */ | ||
358 | +#define SRC_MAPPING_INFO_dsi0 \ | ||
359 | + .src_mapping = { \ | ||
360 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
361 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
362 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
363 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
364 | + CPRMAN_CLOCK_SRC_DSI0HSCK, \ | ||
365 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
366 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
367 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
368 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
369 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
370 | + } | ||
371 | + | ||
372 | +/* The DSI1 channel */ | ||
373 | +#define SRC_MAPPING_INFO_dsi1 \ | ||
374 | + .src_mapping = { \ | ||
375 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
376 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
377 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
378 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
379 | + CPRMAN_PLLD_CHANNEL_DSI1, \ | ||
380 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
381 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
382 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
383 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
384 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
385 | + } | ||
386 | + | ||
387 | +#define FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_) \ | ||
388 | + SRC_MAPPING_INFO_ ## kind_ | ||
389 | + | ||
390 | +#define FILL_CLOCK_MUX_INIT_INFO(clock_, kind_) \ | ||
391 | + .cm_offset = R_CM_ ## clock_ ## CTL, \ | ||
392 | + FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_) | ||
393 | + | ||
394 | +static ClockMuxInitInfo CLOCK_MUX_INIT_INFO[] = { | ||
395 | + [CPRMAN_CLOCK_GNRIC] = { | ||
396 | + .name = "gnric", | ||
397 | + FILL_CLOCK_MUX_INIT_INFO(GNRIC, unknown), | ||
398 | + }, | ||
399 | + [CPRMAN_CLOCK_VPU] = { | ||
400 | + .name = "vpu", | ||
401 | + .int_bits = 12, | ||
402 | + .frac_bits = 8, | ||
403 | + FILL_CLOCK_MUX_INIT_INFO(VPU, core), | ||
404 | + }, | ||
405 | + [CPRMAN_CLOCK_SYS] = { | ||
406 | + .name = "sys", | ||
407 | + FILL_CLOCK_MUX_INIT_INFO(SYS, unknown), | ||
408 | + }, | ||
409 | + [CPRMAN_CLOCK_PERIA] = { | ||
410 | + .name = "peria", | ||
411 | + FILL_CLOCK_MUX_INIT_INFO(PERIA, unknown), | ||
412 | + }, | ||
413 | + [CPRMAN_CLOCK_PERII] = { | ||
414 | + .name = "perii", | ||
415 | + FILL_CLOCK_MUX_INIT_INFO(PERII, unknown), | ||
416 | + }, | ||
417 | + [CPRMAN_CLOCK_H264] = { | ||
418 | + .name = "h264", | ||
419 | + .int_bits = 4, | ||
420 | + .frac_bits = 8, | ||
421 | + FILL_CLOCK_MUX_INIT_INFO(H264, core), | ||
422 | + }, | ||
423 | + [CPRMAN_CLOCK_ISP] = { | ||
424 | + .name = "isp", | ||
425 | + .int_bits = 4, | ||
426 | + .frac_bits = 8, | ||
427 | + FILL_CLOCK_MUX_INIT_INFO(ISP, core), | ||
428 | + }, | ||
429 | + [CPRMAN_CLOCK_V3D] = { | ||
430 | + .name = "v3d", | ||
431 | + FILL_CLOCK_MUX_INIT_INFO(V3D, core), | ||
432 | + }, | ||
433 | + [CPRMAN_CLOCK_CAM0] = { | ||
434 | + .name = "cam0", | ||
435 | + .int_bits = 4, | ||
436 | + .frac_bits = 8, | ||
437 | + FILL_CLOCK_MUX_INIT_INFO(CAM0, periph), | ||
438 | + }, | ||
439 | + [CPRMAN_CLOCK_CAM1] = { | ||
440 | + .name = "cam1", | ||
441 | + .int_bits = 4, | ||
442 | + .frac_bits = 8, | ||
443 | + FILL_CLOCK_MUX_INIT_INFO(CAM1, periph), | ||
444 | + }, | ||
445 | + [CPRMAN_CLOCK_CCP2] = { | ||
446 | + .name = "ccp2", | ||
447 | + FILL_CLOCK_MUX_INIT_INFO(CCP2, unknown), | ||
448 | + }, | ||
449 | + [CPRMAN_CLOCK_DSI0E] = { | ||
450 | + .name = "dsi0e", | ||
451 | + .int_bits = 4, | ||
452 | + .frac_bits = 8, | ||
453 | + FILL_CLOCK_MUX_INIT_INFO(DSI0E, dsi0), | ||
454 | + }, | ||
455 | + [CPRMAN_CLOCK_DSI0P] = { | ||
456 | + .name = "dsi0p", | ||
457 | + .int_bits = 0, | ||
458 | + .frac_bits = 0, | ||
459 | + FILL_CLOCK_MUX_INIT_INFO(DSI0P, dsi0), | ||
460 | + }, | ||
461 | + [CPRMAN_CLOCK_DPI] = { | ||
462 | + .name = "dpi", | ||
463 | + .int_bits = 4, | ||
464 | + .frac_bits = 8, | ||
465 | + FILL_CLOCK_MUX_INIT_INFO(DPI, periph), | ||
466 | + }, | ||
467 | + [CPRMAN_CLOCK_GP0] = { | ||
468 | + .name = "gp0", | ||
469 | + .int_bits = 12, | ||
470 | + .frac_bits = 12, | ||
471 | + FILL_CLOCK_MUX_INIT_INFO(GP0, periph), | ||
472 | + }, | ||
473 | + [CPRMAN_CLOCK_GP1] = { | ||
474 | + .name = "gp1", | ||
475 | + .int_bits = 12, | ||
476 | + .frac_bits = 12, | ||
477 | + FILL_CLOCK_MUX_INIT_INFO(GP1, periph), | ||
478 | + }, | ||
479 | + [CPRMAN_CLOCK_GP2] = { | ||
480 | + .name = "gp2", | ||
481 | + .int_bits = 12, | ||
482 | + .frac_bits = 12, | ||
483 | + FILL_CLOCK_MUX_INIT_INFO(GP2, periph), | ||
484 | + }, | ||
485 | + [CPRMAN_CLOCK_HSM] = { | ||
486 | + .name = "hsm", | ||
487 | + .int_bits = 4, | ||
488 | + .frac_bits = 8, | ||
489 | + FILL_CLOCK_MUX_INIT_INFO(HSM, periph), | ||
490 | + }, | ||
491 | + [CPRMAN_CLOCK_OTP] = { | ||
492 | + .name = "otp", | ||
493 | + .int_bits = 4, | ||
494 | + .frac_bits = 0, | ||
495 | + FILL_CLOCK_MUX_INIT_INFO(OTP, xosc), | ||
496 | + }, | ||
497 | + [CPRMAN_CLOCK_PCM] = { | ||
498 | + .name = "pcm", | ||
499 | + .int_bits = 12, | ||
500 | + .frac_bits = 12, | ||
501 | + FILL_CLOCK_MUX_INIT_INFO(PCM, periph), | ||
502 | + }, | ||
503 | + [CPRMAN_CLOCK_PWM] = { | ||
504 | + .name = "pwm", | ||
505 | + .int_bits = 12, | ||
506 | + .frac_bits = 12, | ||
507 | + FILL_CLOCK_MUX_INIT_INFO(PWM, periph), | ||
508 | + }, | ||
509 | + [CPRMAN_CLOCK_SLIM] = { | ||
510 | + .name = "slim", | ||
511 | + .int_bits = 12, | ||
512 | + .frac_bits = 12, | ||
513 | + FILL_CLOCK_MUX_INIT_INFO(SLIM, periph), | ||
514 | + }, | ||
515 | + [CPRMAN_CLOCK_SMI] = { | ||
516 | + .name = "smi", | ||
517 | + .int_bits = 4, | ||
518 | + .frac_bits = 8, | ||
519 | + FILL_CLOCK_MUX_INIT_INFO(SMI, periph), | ||
520 | + }, | ||
521 | + [CPRMAN_CLOCK_TEC] = { | ||
522 | + .name = "tec", | ||
523 | + .int_bits = 6, | ||
524 | + .frac_bits = 0, | ||
525 | + FILL_CLOCK_MUX_INIT_INFO(TEC, xosc), | ||
526 | + }, | ||
527 | + [CPRMAN_CLOCK_TD0] = { | ||
528 | + .name = "td0", | ||
529 | + FILL_CLOCK_MUX_INIT_INFO(TD0, unknown), | ||
530 | + }, | ||
531 | + [CPRMAN_CLOCK_TD1] = { | ||
532 | + .name = "td1", | ||
533 | + FILL_CLOCK_MUX_INIT_INFO(TD1, unknown), | ||
534 | + }, | ||
535 | + [CPRMAN_CLOCK_TSENS] = { | ||
536 | + .name = "tsens", | ||
537 | + .int_bits = 5, | ||
538 | + .frac_bits = 0, | ||
539 | + FILL_CLOCK_MUX_INIT_INFO(TSENS, xosc), | ||
540 | + }, | ||
541 | + [CPRMAN_CLOCK_TIMER] = { | ||
542 | + .name = "timer", | ||
543 | + .int_bits = 6, | ||
544 | + .frac_bits = 12, | ||
545 | + FILL_CLOCK_MUX_INIT_INFO(TIMER, xosc), | ||
546 | + }, | ||
547 | + [CPRMAN_CLOCK_UART] = { | ||
548 | + .name = "uart", | ||
549 | + .int_bits = 10, | ||
550 | + .frac_bits = 12, | ||
551 | + FILL_CLOCK_MUX_INIT_INFO(UART, periph), | ||
552 | + }, | ||
553 | + [CPRMAN_CLOCK_VEC] = { | ||
554 | + .name = "vec", | ||
555 | + .int_bits = 4, | ||
556 | + .frac_bits = 0, | ||
557 | + FILL_CLOCK_MUX_INIT_INFO(VEC, periph), | ||
558 | + }, | ||
559 | + [CPRMAN_CLOCK_PULSE] = { | ||
560 | + .name = "pulse", | ||
561 | + FILL_CLOCK_MUX_INIT_INFO(PULSE, xosc), | ||
562 | + }, | ||
563 | + [CPRMAN_CLOCK_SDC] = { | ||
564 | + .name = "sdram", | ||
565 | + .int_bits = 6, | ||
566 | + .frac_bits = 0, | ||
567 | + FILL_CLOCK_MUX_INIT_INFO(SDC, core), | ||
568 | + }, | ||
569 | + [CPRMAN_CLOCK_ARM] = { | ||
570 | + .name = "arm", | ||
571 | + FILL_CLOCK_MUX_INIT_INFO(ARM, unknown), | ||
572 | + }, | ||
573 | + [CPRMAN_CLOCK_AVEO] = { | ||
574 | + .name = "aveo", | ||
575 | + .int_bits = 4, | ||
576 | + .frac_bits = 0, | ||
577 | + FILL_CLOCK_MUX_INIT_INFO(AVEO, periph), | ||
578 | + }, | ||
579 | + [CPRMAN_CLOCK_EMMC] = { | ||
580 | + .name = "emmc", | ||
581 | + .int_bits = 4, | ||
582 | + .frac_bits = 8, | ||
583 | + FILL_CLOCK_MUX_INIT_INFO(EMMC, periph), | ||
584 | + }, | ||
585 | + [CPRMAN_CLOCK_EMMC2] = { | ||
586 | + .name = "emmc2", | ||
587 | + .int_bits = 4, | ||
588 | + .frac_bits = 8, | ||
589 | + FILL_CLOCK_MUX_INIT_INFO(EMMC2, unknown), | ||
590 | + }, | ||
591 | +}; | ||
592 | + | ||
593 | +#undef FILL_CLOCK_MUX_INIT_INFO | ||
594 | +#undef FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO | ||
595 | +#undef SRC_MAPPING_INFO_dsi1 | ||
596 | +#undef SRC_MAPPING_INFO_dsi0 | ||
597 | +#undef SRC_MAPPING_INFO_periph | ||
598 | +#undef SRC_MAPPING_INFO_core | ||
599 | +#undef SRC_MAPPING_INFO_xosc | ||
600 | +#undef SRC_MAPPING_INFO_unknown | ||
601 | + | ||
602 | +static inline void set_clock_mux_init_info(BCM2835CprmanState *s, | ||
603 | + CprmanClockMuxState *mux, | ||
604 | + CprmanClockMux id) | ||
605 | +{ | ||
606 | + mux->id = id; | ||
607 | + mux->reg_ctl = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset]; | ||
608 | + mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset + 1]; | ||
609 | + mux->int_bits = CLOCK_MUX_INIT_INFO[id].int_bits; | ||
610 | + mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | ||
611 | +} | ||
612 | + | ||
613 | #endif | ||
614 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
615 | index XXXXXXX..XXXXXXX 100644 | ||
616 | --- a/hw/misc/bcm2835_cprman.c | ||
617 | +++ b/hw/misc/bcm2835_cprman.c | ||
618 | @@ -XXX,XX +XXX,XX @@ | ||
619 | * | ||
620 | * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
621 | * tree configuration. | ||
622 | + * | ||
623 | + * The CPRMAN exposes clock outputs with the name of the clock mux suffixed | ||
624 | + * with "-out" (e.g. "uart-out", "h264-out", ...). | ||
625 | */ | ||
626 | |||
627 | #include "qemu/osdep.h" | ||
628 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { | ||
629 | }; | ||
630 | |||
631 | |||
632 | +/* clock mux */ | ||
633 | + | ||
634 | +static void clock_mux_update(CprmanClockMuxState *mux) | ||
635 | +{ | ||
636 | + clock_update(mux->out, 0); | ||
637 | +} | ||
638 | + | ||
639 | +static void clock_mux_src_update(void *opaque) | ||
640 | +{ | ||
641 | + CprmanClockMuxState **backref = opaque; | ||
642 | + CprmanClockMuxState *s = *backref; | ||
643 | + | ||
644 | + clock_mux_update(s); | ||
645 | +} | ||
646 | + | ||
647 | +static void clock_mux_init(Object *obj) | ||
648 | +{ | ||
649 | + CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); | ||
650 | + size_t i; | ||
651 | + | ||
652 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { | ||
653 | + char *name = g_strdup_printf("srcs[%zu]", i); | ||
654 | + s->backref[i] = s; | ||
655 | + s->srcs[i] = qdev_init_clock_in(DEVICE(s), name, | ||
656 | + clock_mux_src_update, | ||
657 | + &s->backref[i]); | ||
658 | + g_free(name); | ||
659 | + } | ||
660 | + | ||
661 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
662 | +} | ||
663 | + | ||
664 | +static const VMStateDescription clock_mux_vmstate = { | ||
665 | + .name = TYPE_CPRMAN_CLOCK_MUX, | ||
666 | + .version_id = 1, | ||
667 | + .minimum_version_id = 1, | ||
668 | + .fields = (VMStateField[]) { | ||
669 | + VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState, | ||
670 | + CPRMAN_NUM_CLOCK_MUX_SRC), | ||
671 | + VMSTATE_END_OF_LIST() | ||
672 | + } | ||
673 | +}; | ||
674 | + | ||
675 | +static void clock_mux_class_init(ObjectClass *klass, void *data) | ||
676 | +{ | ||
677 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
678 | + | ||
679 | + dc->vmsd = &clock_mux_vmstate; | ||
680 | +} | ||
681 | + | ||
682 | +static const TypeInfo cprman_clock_mux_info = { | ||
683 | + .name = TYPE_CPRMAN_CLOCK_MUX, | ||
684 | + .parent = TYPE_DEVICE, | ||
685 | + .instance_size = sizeof(CprmanClockMuxState), | ||
686 | + .class_init = clock_mux_class_init, | ||
687 | + .instance_init = clock_mux_init, | ||
688 | +}; | ||
689 | + | ||
690 | + | ||
691 | /* CPRMAN "top level" model */ | ||
692 | |||
693 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
694 | @@ -XXX,XX +XXX,XX @@ static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) | ||
695 | } | ||
696 | } | ||
697 | |||
698 | +static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx) | ||
699 | +{ | ||
700 | + size_t i; | ||
701 | + | ||
702 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
703 | + if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) || | ||
704 | + (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) { | ||
705 | + /* matches CM_CTL or CM_DIV mux register */ | ||
706 | + clock_mux_update(&s->clock_muxes[i]); | ||
707 | + return; | ||
708 | + } | ||
709 | + } | ||
710 | +} | ||
711 | + | ||
712 | #define CASE_PLL_A2W_REGS(pll_) \ | ||
713 | case R_A2W_ ## pll_ ## _CTRL: \ | ||
714 | case R_A2W_ ## pll_ ## _ANA0: \ | ||
715 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, | ||
716 | case R_A2W_PLLB_ARM: | ||
717 | update_channel_from_a2w(s, idx); | ||
718 | break; | ||
719 | + | ||
720 | + case R_CM_GNRICCTL ... R_CM_SMIDIV: | ||
721 | + case R_CM_TCNTCNT ... R_CM_VECDIV: | ||
722 | + case R_CM_PULSECTL ... R_CM_PULSEDIV: | ||
723 | + case R_CM_SDCCTL ... R_CM_ARMCTL: | ||
724 | + case R_CM_AVEOCTL ... R_CM_EMMCDIV: | ||
725 | + case R_CM_EMMC2CTL ... R_CM_EMMC2DIV: | ||
726 | + update_mux_from_cm(s, idx); | ||
727 | + break; | ||
728 | } | ||
729 | } | ||
730 | |||
731 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | ||
732 | device_cold_reset(DEVICE(&s->channels[i])); | ||
733 | } | ||
734 | |||
735 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
736 | + device_cold_reset(DEVICE(&s->clock_muxes[i])); | ||
737 | + } | ||
738 | + | ||
739 | clock_update_hz(s->xosc, s->xosc_freq); | ||
740 | } | ||
741 | |||
742 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
743 | set_pll_channel_init_info(s, &s->channels[i], i); | ||
744 | } | ||
745 | |||
746 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
747 | + char *alias; | ||
748 | + | ||
749 | + object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name, | ||
750 | + &s->clock_muxes[i], | ||
751 | + TYPE_CPRMAN_CLOCK_MUX); | ||
752 | + set_clock_mux_init_info(s, &s->clock_muxes[i], i); | ||
753 | + | ||
754 | + /* Expose muxes output as CPRMAN outputs */ | ||
755 | + alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name); | ||
756 | + qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias); | ||
757 | + g_free(alias); | ||
758 | + } | ||
759 | + | ||
760 | s->xosc = clock_new(obj, "xosc"); | ||
761 | + s->gnd = clock_new(obj, "gnd"); | ||
762 | + | ||
763 | + clock_set(s->gnd, 0); | ||
764 | |||
765 | memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
766 | s, "bcm2835-cprman", 0x2000); | ||
767 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
768 | } | ||
769 | |||
770 | +static void connect_mux_sources(BCM2835CprmanState *s, | ||
771 | + CprmanClockMuxState *mux, | ||
772 | + const CprmanPllChannel *clk_mapping) | ||
773 | +{ | ||
774 | + size_t i; | ||
775 | + Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out; | ||
776 | + Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out; | ||
777 | + | ||
778 | + /* For sources from 0 to 3. Source 4 to 9 are mux specific */ | ||
779 | + Clock * const CLK_SRC_MAPPING[] = { | ||
780 | + [CPRMAN_CLOCK_SRC_GND] = s->gnd, | ||
781 | + [CPRMAN_CLOCK_SRC_XOSC] = s->xosc, | ||
782 | + [CPRMAN_CLOCK_SRC_TD0] = td0, | ||
783 | + [CPRMAN_CLOCK_SRC_TD1] = td1, | ||
784 | + }; | ||
785 | + | ||
786 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { | ||
787 | + CprmanPllChannel mapping = clk_mapping[i]; | ||
788 | + Clock *src; | ||
789 | + | ||
790 | + if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { | ||
791 | + src = s->gnd; | ||
792 | + } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { | ||
793 | + src = s->gnd; /* TODO */ | ||
794 | + } else if (i < CPRMAN_CLOCK_SRC_PLLA) { | ||
795 | + src = CLK_SRC_MAPPING[i]; | ||
796 | + } else { | ||
797 | + src = s->channels[mapping].out; | ||
798 | + } | ||
799 | + | ||
800 | + clock_set_source(mux->srcs[i], src); | ||
801 | + } | ||
802 | +} | ||
803 | + | ||
804 | static void cprman_realize(DeviceState *dev, Error **errp) | ||
805 | { | ||
806 | BCM2835CprmanState *s = CPRMAN(dev); | ||
807 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
808 | return; | ||
809 | } | ||
810 | } | ||
811 | + | ||
812 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
813 | + CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | ||
814 | + | ||
815 | + connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping); | ||
816 | + | ||
817 | + if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) { | ||
818 | + return; | ||
819 | + } | ||
820 | + } | ||
821 | } | ||
822 | |||
823 | static const VMStateDescription cprman_vmstate = { | ||
824 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
825 | type_register_static(&cprman_info); | ||
826 | type_register_static(&cprman_pll_info); | ||
827 | type_register_static(&cprman_pll_channel_info); | ||
828 | + type_register_static(&cprman_clock_mux_info); | ||
829 | } | ||
830 | |||
831 | type_init(cprman_register_types); | ||
832 | -- | 54 | -- |
833 | 2.20.1 | 55 | 2.20.1 |
834 | 56 | ||
835 | 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 | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20201021173749.111103-12-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-31-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 7 | --- |
10 | linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- | 8 | target/arm/cpu.c | 15 +++++++++++++++ |
11 | 1 file changed, 46 insertions(+), 2 deletions(-) | 9 | 1 file changed, 15 insertions(+) |
12 | 10 | ||
13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/linux-user/elfload.c | 13 | --- a/target/arm/cpu.c |
16 | +++ b/linux-user/elfload.c | 14 | +++ b/target/arm/cpu.c |
17 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, | 15 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
18 | 16 | * Note that this must match useronly_clean_ptr. | |
19 | #include "elf.h" | 17 | */ |
20 | 18 | env->cp15.tcr_el[1].raw_tcr = (1ULL << 37); | |
21 | +/* We must delay the following stanzas until after "elf.h". */ | ||
22 | +#if defined(TARGET_AARCH64) | ||
23 | + | 19 | + |
24 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | 20 | + /* Enable MTE */ |
25 | + const uint32_t *data, | 21 | + if (cpu_isar_feature(aa64_mte, cpu)) { |
26 | + struct image_info *info, | 22 | + /* Enable tag access, but leave TCF0 as No Effect (0). */ |
27 | + Error **errp) | 23 | + env->cp15.sctlr_el[1] |= SCTLR_ATA0; |
28 | +{ | 24 | + /* |
29 | + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { | 25 | + * Exclude all tags, so that tag 0 is always used. |
30 | + if (pr_datasz != sizeof(uint32_t)) { | 26 | + * This corresponds to Linux current->thread.gcr_incl = 0. |
31 | + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); | 27 | + * |
32 | + return false; | 28 | + * Set RRND, so that helper_irg() will generate a seed later. |
29 | + * Here in cpu_reset(), the crypto subsystem has not yet been | ||
30 | + * initialized. | ||
31 | + */ | ||
32 | + env->cp15.gcr_el1 = 0x1ffff; | ||
33 | + } | 33 | + } |
34 | + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ | 34 | #else |
35 | + info->note_flags = *data; | 35 | /* Reset into the highest available EL */ |
36 | + } | 36 | if (arm_feature(env, ARM_FEATURE_EL3)) { |
37 | + return true; | ||
38 | +} | ||
39 | +#define ARCH_USE_GNU_PROPERTY 1 | ||
40 | + | ||
41 | +#else | ||
42 | + | ||
43 | static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
44 | const uint32_t *data, | ||
45 | struct image_info *info, | ||
46 | @@ -XXX,XX +XXX,XX @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
47 | } | ||
48 | #define ARCH_USE_GNU_PROPERTY 0 | ||
49 | |||
50 | +#endif | ||
51 | + | ||
52 | struct exec | ||
53 | { | ||
54 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ | ||
55 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
56 | struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; | ||
57 | struct elf_phdr *phdr; | ||
58 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; | ||
59 | - int i, retval; | ||
60 | + int i, retval, prot_exec; | ||
61 | Error *err = NULL; | ||
62 | |||
63 | /* First of all, some simple consistency checks */ | ||
64 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
65 | info->brk = 0; | ||
66 | info->elf_flags = ehdr->e_flags; | ||
67 | |||
68 | + prot_exec = PROT_EXEC; | ||
69 | +#ifdef TARGET_AARCH64 | ||
70 | + /* | ||
71 | + * If the BTI feature is present, this indicates that the executable | ||
72 | + * pages of the startup binary should be mapped with PROT_BTI, so that | ||
73 | + * branch targets are enforced. | ||
74 | + * | ||
75 | + * The startup binary is either the interpreter or the static executable. | ||
76 | + * The interpreter is responsible for all pages of a dynamic executable. | ||
77 | + * | ||
78 | + * Elf notes are backward compatible to older cpus. | ||
79 | + * Do not enable BTI unless it is supported. | ||
80 | + */ | ||
81 | + if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) | ||
82 | + && (pinterp_name == NULL || *pinterp_name == 0) | ||
83 | + && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) { | ||
84 | + prot_exec |= TARGET_PROT_BTI; | ||
85 | + } | ||
86 | +#endif | ||
87 | + | ||
88 | for (i = 0; i < ehdr->e_phnum; i++) { | ||
89 | struct elf_phdr *eppnt = phdr + i; | ||
90 | if (eppnt->p_type == PT_LOAD) { | ||
91 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
92 | elf_prot |= PROT_WRITE; | ||
93 | } | ||
94 | if (eppnt->p_flags & PF_X) { | ||
95 | - elf_prot |= PROT_EXEC; | ||
96 | + elf_prot |= prot_exec; | ||
97 | } | ||
98 | |||
99 | vaddr = load_bias + eppnt->p_vaddr; | ||
100 | -- | 37 | -- |
101 | 2.20.1 | 38 | 2.20.1 |
102 | 39 | ||
103 | 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 | The note test requires gcc 10 for -mbranch-protection=standard. | ||
4 | The mmap test uses PROT_BTI and does not require special compiler support. | ||
5 | |||
6 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20201021173749.111103-13-richard.henderson@linaro.org | 5 | Message-id: 20210212184902.1251044-32-richard.henderson@linaro.org |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 7 | --- |
12 | tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ | 8 | tests/tcg/aarch64/mte.h | 60 +++++++++++++++++++++++++++++++ |
13 | tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ | 9 | tests/tcg/aarch64/mte-1.c | 28 +++++++++++++++ |
14 | tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ | 10 | tests/tcg/aarch64/mte-2.c | 45 +++++++++++++++++++++++ |
15 | tests/tcg/aarch64/Makefile.target | 10 +++ | 11 | tests/tcg/aarch64/mte-3.c | 51 ++++++++++++++++++++++++++ |
16 | tests/tcg/configure.sh | 4 ++ | 12 | tests/tcg/aarch64/mte-4.c | 45 +++++++++++++++++++++++ |
17 | 5 files changed, 243 insertions(+) | 13 | tests/tcg/aarch64/Makefile.target | 6 ++++ |
18 | create mode 100644 tests/tcg/aarch64/bti-1.c | 14 | tests/tcg/configure.sh | 4 +++ |
19 | create mode 100644 tests/tcg/aarch64/bti-2.c | 15 | 7 files changed, 239 insertions(+) |
20 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | 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 | ||
21 | 21 | ||
22 | diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c | 22 | diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h |
23 | new file mode 100644 | 23 | new file mode 100644 |
24 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
25 | --- /dev/null | 25 | --- /dev/null |
26 | +++ b/tests/tcg/aarch64/bti-1.c | 26 | +++ b/tests/tcg/aarch64/mte.h |
27 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
28 | +/* | 28 | +/* |
29 | + * Branch target identification, basic notskip cases. | 29 | + * Linux kernel fallback API definitions for MTE and test helpers. |
30 | + */ | 30 | + * |
31 | + | 31 | + * Copyright (c) 2021 Linaro Ltd |
32 | +#include "bti-crt.inc.c" | 32 | + * SPDX-License-Identifier: GPL-2.0-or-later |
33 | + | 33 | + */ |
34 | +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) | 34 | + |
35 | +{ | 35 | +#include <assert.h> |
36 | + uc->uc_mcontext.pc += 8; | 36 | +#include <string.h> |
37 | + uc->uc_mcontext.pstate = 1; | 37 | +#include <stdlib.h> |
38 | +} | ||
39 | + | ||
40 | +#define NOP "nop" | ||
41 | +#define BTI_N "hint #32" | ||
42 | +#define BTI_C "hint #34" | ||
43 | +#define BTI_J "hint #36" | ||
44 | +#define BTI_JC "hint #38" | ||
45 | + | ||
46 | +#define BTYPE_1(DEST) \ | ||
47 | + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ | ||
48 | + : "=r"(skipped) : : "x16") | ||
49 | + | ||
50 | +#define BTYPE_2(DEST) \ | ||
51 | + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ | ||
52 | + : "=r"(skipped) : : "x16", "x30") | ||
53 | + | ||
54 | +#define BTYPE_3(DEST) \ | ||
55 | + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ | ||
56 | + : "=r"(skipped) : : "x15") | ||
57 | + | ||
58 | +#define TEST(WHICH, DEST, EXPECT) \ | ||
59 | + do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0) | ||
60 | + | ||
61 | + | ||
62 | +int main() | ||
63 | +{ | ||
64 | + int fail = 0; | ||
65 | + int skipped; | ||
66 | + | ||
67 | + /* Signal-like with SA_SIGINFO. */ | ||
68 | + signal_info(SIGILL, skip2_sigill); | ||
69 | + | ||
70 | + TEST(BTYPE_1, NOP, 1); | ||
71 | + TEST(BTYPE_1, BTI_N, 1); | ||
72 | + TEST(BTYPE_1, BTI_C, 0); | ||
73 | + TEST(BTYPE_1, BTI_J, 0); | ||
74 | + TEST(BTYPE_1, BTI_JC, 0); | ||
75 | + | ||
76 | + TEST(BTYPE_2, NOP, 1); | ||
77 | + TEST(BTYPE_2, BTI_N, 1); | ||
78 | + TEST(BTYPE_2, BTI_C, 0); | ||
79 | + TEST(BTYPE_2, BTI_J, 1); | ||
80 | + TEST(BTYPE_2, BTI_JC, 0); | ||
81 | + | ||
82 | + TEST(BTYPE_3, NOP, 1); | ||
83 | + TEST(BTYPE_3, BTI_N, 1); | ||
84 | + TEST(BTYPE_3, BTI_C, 1); | ||
85 | + TEST(BTYPE_3, BTI_J, 0); | ||
86 | + TEST(BTYPE_3, BTI_JC, 0); | ||
87 | + | ||
88 | + return fail; | ||
89 | +} | ||
90 | diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c | ||
91 | new file mode 100644 | ||
92 | index XXXXXXX..XXXXXXX | ||
93 | --- /dev/null | ||
94 | +++ b/tests/tcg/aarch64/bti-2.c | ||
95 | @@ -XXX,XX +XXX,XX @@ | ||
96 | +/* | ||
97 | + * Branch target identification, basic notskip cases. | ||
98 | + */ | ||
99 | + | ||
100 | +#include <stdio.h> | 38 | +#include <stdio.h> |
39 | +#include <unistd.h> | ||
101 | +#include <signal.h> | 40 | +#include <signal.h> |
102 | +#include <string.h> | ||
103 | +#include <unistd.h> | ||
104 | +#include <sys/mman.h> | 41 | +#include <sys/mman.h> |
105 | + | 42 | +#include <sys/prctl.h> |
106 | +#ifndef PROT_BTI | 43 | + |
107 | +#define PROT_BTI 0x10 | 44 | +#ifndef PR_SET_TAGGED_ADDR_CTRL |
108 | +#endif | 45 | +# define PR_SET_TAGGED_ADDR_CTRL 55 |
109 | + | 46 | +#endif |
110 | +static void skip2_sigill(int sig, siginfo_t *info, void *vuc) | 47 | +#ifndef PR_TAGGED_ADDR_ENABLE |
111 | +{ | 48 | +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) |
112 | + ucontext_t *uc = vuc; | 49 | +#endif |
113 | + uc->uc_mcontext.pc += 8; | 50 | +#ifndef PR_MTE_TCF_SHIFT |
114 | + uc->uc_mcontext.pstate = 1; | 51 | +# define PR_MTE_TCF_SHIFT 1 |
115 | +} | 52 | +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) |
116 | + | 53 | +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) |
117 | +#define NOP "nop" | 54 | +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) |
118 | +#define BTI_N "hint #32" | 55 | +# define PR_MTE_TAG_SHIFT 3 |
119 | +#define BTI_C "hint #34" | 56 | +#endif |
120 | +#define BTI_J "hint #36" | 57 | + |
121 | +#define BTI_JC "hint #38" | 58 | +#ifndef PROT_MTE |
122 | + | 59 | +# define PROT_MTE 0x20 |
123 | +#define BTYPE_1(DEST) \ | 60 | +#endif |
124 | + "mov x1, #1\n\t" \ | 61 | + |
125 | + "adr x16, 1f\n\t" \ | 62 | +#ifndef SEGV_MTEAERR |
126 | + "br x16\n" \ | 63 | +# define SEGV_MTEAERR 8 |
127 | +"1: " DEST "\n\t" \ | 64 | +# define SEGV_MTESERR 9 |
128 | + "mov x1, #0" | 65 | +#endif |
129 | + | 66 | + |
130 | +#define BTYPE_2(DEST) \ | 67 | +static void enable_mte(int tcf) |
131 | + "mov x1, #1\n\t" \ | 68 | +{ |
132 | + "adr x16, 1f\n\t" \ | 69 | + int r = prctl(PR_SET_TAGGED_ADDR_CTRL, |
133 | + "blr x16\n" \ | 70 | + PR_TAGGED_ADDR_ENABLE | tcf | (0xfffe << PR_MTE_TAG_SHIFT), |
134 | +"1: " DEST "\n\t" \ | 71 | + 0, 0, 0); |
135 | + "mov x1, #0" | 72 | + if (r < 0) { |
136 | + | 73 | + perror("PR_SET_TAGGED_ADDR_CTRL"); |
137 | +#define BTYPE_3(DEST) \ | 74 | + exit(2); |
138 | + "mov x1, #1\n\t" \ | 75 | + } |
139 | + "adr x15, 1f\n\t" \ | 76 | +} |
140 | + "br x15\n" \ | 77 | + |
141 | +"1: " DEST "\n\t" \ | 78 | +static void *alloc_mte_mem(size_t size) |
142 | + "mov x1, #0" | 79 | +{ |
143 | + | 80 | + void *p = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_MTE, |
144 | +#define TEST(WHICH, DEST, EXPECT) \ | ||
145 | + WHICH(DEST) "\n" \ | ||
146 | + ".if " #EXPECT "\n\t" \ | ||
147 | + "eor x1, x1," #EXPECT "\n" \ | ||
148 | + ".endif\n\t" \ | ||
149 | + "add x0, x0, x1\n\t" | ||
150 | + | ||
151 | +asm("\n" | ||
152 | +"test_begin:\n\t" | ||
153 | + BTI_C "\n\t" | ||
154 | + "mov x2, x30\n\t" | ||
155 | + "mov x0, #0\n\t" | ||
156 | + | ||
157 | + TEST(BTYPE_1, NOP, 1) | ||
158 | + TEST(BTYPE_1, BTI_N, 1) | ||
159 | + TEST(BTYPE_1, BTI_C, 0) | ||
160 | + TEST(BTYPE_1, BTI_J, 0) | ||
161 | + TEST(BTYPE_1, BTI_JC, 0) | ||
162 | + | ||
163 | + TEST(BTYPE_2, NOP, 1) | ||
164 | + TEST(BTYPE_2, BTI_N, 1) | ||
165 | + TEST(BTYPE_2, BTI_C, 0) | ||
166 | + TEST(BTYPE_2, BTI_J, 1) | ||
167 | + TEST(BTYPE_2, BTI_JC, 0) | ||
168 | + | ||
169 | + TEST(BTYPE_3, NOP, 1) | ||
170 | + TEST(BTYPE_3, BTI_N, 1) | ||
171 | + TEST(BTYPE_3, BTI_C, 1) | ||
172 | + TEST(BTYPE_3, BTI_J, 0) | ||
173 | + TEST(BTYPE_3, BTI_JC, 0) | ||
174 | + | ||
175 | + "ret x2\n" | ||
176 | +"test_end:" | ||
177 | +); | ||
178 | + | ||
179 | +int main() | ||
180 | +{ | ||
181 | + struct sigaction sa; | ||
182 | + void *tb, *te; | ||
183 | + | ||
184 | + void *p = mmap(0, getpagesize(), | ||
185 | + PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI, | ||
186 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 81 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
187 | + if (p == MAP_FAILED) { | 82 | + if (p == MAP_FAILED) { |
188 | + perror("mmap"); | 83 | + perror("mmap PROT_MTE"); |
189 | + return 1; | 84 | + exit(2); |
190 | + } | 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; | ||
191 | + | 163 | + |
192 | + memset(&sa, 0, sizeof(sa)); | 164 | + memset(&sa, 0, sizeof(sa)); |
193 | + sa.sa_sigaction = skip2_sigill; | 165 | + sa.sa_sigaction = pass; |
194 | + sa.sa_flags = SA_SIGINFO; | 166 | + sa.sa_flags = SA_SIGINFO; |
195 | + if (sigaction(SIGILL, &sa, NULL) < 0) { | 167 | + sigaction(SIGSEGV, &sa, NULL); |
196 | + perror("sigaction"); | 168 | + |
197 | + return 1; | 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)); | ||
198 | + } | 250 | + } |
199 | + | 251 | +} |
200 | + /* | 252 | + |
201 | + * ??? With "extern char test_begin[]", some compiler versions | 253 | +void __attribute__((noinline)) tagcheck(void *p, size_t size) |
202 | + * will use :got references, and some linker versions will | 254 | +{ |
203 | + * resolve this reference to a static symbol incorrectly. | 255 | + size_t i; |
204 | + * Bypass this error by using a pc-relative reference directly. | 256 | + void *c; |
205 | + */ | 257 | + |
206 | + asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb), "=r"(te)); | 258 | + for (i = 0; i < size; i += 16) { |
207 | + | 259 | + asm("ldg %0, [%1]" : "=r"(c) : "r"(p + i), "0"(p)); |
208 | + memcpy(p, tb, te - tb); | 260 | + assert(c == p); |
209 | + | 261 | + } |
210 | + return ((int (*)(void))p)(); | 262 | +} |
211 | +} | 263 | + |
212 | diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c | 264 | +int main(int ac, char **av) |
213 | new file mode 100644 | 265 | +{ |
214 | index XXXXXXX..XXXXXXX | 266 | + size_t size = getpagesize() * 4; |
215 | --- /dev/null | 267 | + long excl = 1; |
216 | +++ b/tests/tcg/aarch64/bti-crt.inc.c | 268 | + int *p0, *p1; |
217 | @@ -XXX,XX +XXX,XX @@ | 269 | + |
218 | +/* | 270 | + enable_mte(PR_MTE_TCF_ASYNC); |
219 | + * Minimal user-environment for testing BTI. | 271 | + p0 = alloc_mte_mem(size); |
220 | + * | 272 | + |
221 | + * Normal libc is not (yet) built with BTI support enabled, | 273 | + /* Tag the pointer. */ |
222 | + * and so could generate a BTI TRAP before ever reaching main. | 274 | + asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl)); |
223 | + */ | 275 | + |
224 | + | 276 | + tagset(p1, size); |
225 | +#include <stdlib.h> | 277 | + tagcheck(p1, size); |
226 | +#include <signal.h> | 278 | + |
227 | +#include <ucontext.h> | 279 | + return 0; |
228 | +#include <asm/unistd.h> | ||
229 | + | ||
230 | +int main(void); | ||
231 | + | ||
232 | +void _start(void) | ||
233 | +{ | ||
234 | + exit(main()); | ||
235 | +} | ||
236 | + | ||
237 | +void exit(int ret) | ||
238 | +{ | ||
239 | + register int x0 __asm__("x0") = ret; | ||
240 | + register int x8 __asm__("x8") = __NR_exit; | ||
241 | + | ||
242 | + asm volatile("svc #0" : : "r"(x0), "r"(x8)); | ||
243 | + __builtin_unreachable(); | ||
244 | +} | ||
245 | + | ||
246 | +/* | ||
247 | + * Irritatingly, the user API struct sigaction does not match the | ||
248 | + * kernel API struct sigaction. So for simplicity, isolate the | ||
249 | + * kernel ABI here, and make this act like signal. | ||
250 | + */ | ||
251 | +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) | ||
252 | +{ | ||
253 | + struct kernel_sigaction { | ||
254 | + void (*handler)(int, siginfo_t *, ucontext_t *); | ||
255 | + unsigned long flags; | ||
256 | + unsigned long restorer; | ||
257 | + unsigned long mask; | ||
258 | + } sa = { fn, SA_SIGINFO, 0, 0 }; | ||
259 | + | ||
260 | + register int x0 __asm__("x0") = sig; | ||
261 | + register void *x1 __asm__("x1") = &sa; | ||
262 | + register void *x2 __asm__("x2") = 0; | ||
263 | + register int x3 __asm__("x3") = sizeof(unsigned long); | ||
264 | + register int x8 __asm__("x8") = __NR_rt_sigaction; | ||
265 | + | ||
266 | + asm volatile("svc #0" | ||
267 | + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory"); | ||
268 | +} | 280 | +} |
269 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target | 281 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target |
270 | index XXXXXXX..XXXXXXX 100644 | 282 | index XXXXXXX..XXXXXXX 100644 |
271 | --- a/tests/tcg/aarch64/Makefile.target | 283 | --- a/tests/tcg/aarch64/Makefile.target |
272 | +++ b/tests/tcg/aarch64/Makefile.target | 284 | +++ b/tests/tcg/aarch64/Makefile.target |
273 | @@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max | 285 | @@ -XXX,XX +XXX,XX @@ endif |
274 | run-plugin-pauth-%: QEMU_OPTS += -cpu max | 286 | # bti-2 tests PROT_BTI, so no special compiler support required. |
275 | endif | 287 | AARCH64_TESTS += bti-2 |
276 | 288 | ||
277 | +# BTI Tests | 289 | +# MTE Tests |
278 | +# bti-1 tests the elf notes, so we require special compiler support. | 290 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),) |
279 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) | 291 | +AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 |
280 | +AARCH64_TESTS += bti-1 | 292 | +mte-%: CFLAGS += -march=armv8.5-a+memtag |
281 | +bti-1: CFLAGS += -mbranch-protection=standard | ||
282 | +bti-1: LDFLAGS += -nostdlib | ||
283 | +endif | 293 | +endif |
284 | +# bti-2 tests PROT_BTI, so no special compiler support required. | ||
285 | +AARCH64_TESTS += bti-2 | ||
286 | + | 294 | + |
287 | # Semihosting smoke test for linux-user | 295 | # Semihosting smoke test for linux-user |
288 | AARCH64_TESTS += semihosting | 296 | AARCH64_TESTS += semihosting |
289 | run-semihosting: semihosting | 297 | run-semihosting: semihosting |
290 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh | 298 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
291 | index XXXXXXX..XXXXXXX 100755 | 299 | index XXXXXXX..XXXXXXX 100755 |
292 | --- a/tests/tcg/configure.sh | 300 | --- a/tests/tcg/configure.sh |
293 | +++ b/tests/tcg/configure.sh | 301 | +++ b/tests/tcg/configure.sh |
294 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do | 302 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do |
295 | -march=armv8.3-a -o $TMPE $TMPC; then | 303 | -mbranch-protection=standard -o $TMPE $TMPC; then |
296 | echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak | 304 | echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak |
297 | fi | 305 | fi |
298 | + if do_compiler "$target_compiler" $target_compiler_cflags \ | 306 | + if do_compiler "$target_compiler" $target_compiler_cflags \ |
299 | + -mbranch-protection=standard -o $TMPE $TMPC; then | 307 | + -march=armv8.5-a+memtag -o $TMPE $TMPC; then |
300 | + echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak | 308 | + echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak |
301 | + fi | 309 | + fi |
302 | ;; | 310 | ;; |
303 | esac | 311 | esac |
304 | 312 | ||
305 | -- | 313 | -- |
306 | 2.20.1 | 314 | 2.20.1 |
307 | 315 | ||
308 | 316 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
2 | 1 | ||
3 | When compiling with -Werror=implicit-fallthrough, gcc complains about | ||
4 | missing fallthrough annotations in this file. Looking at the code, | ||
5 | the fallthrough is very likely intended here, so add some comments | ||
6 | to silence the compiler warnings. | ||
7 | |||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
9 | Message-id: 20201020105938.23209-1-thuth@redhat.com | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | hw/arm/highbank.c | 2 ++ | ||
14 | 1 file changed, 2 insertions(+) | ||
15 | |||
16 | diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/arm/highbank.c | ||
19 | +++ b/hw/arm/highbank.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) | ||
21 | address_space_stl_notdirty(&address_space_memory, | ||
22 | SMP_BOOT_REG + 0x30, 0, | ||
23 | MEMTXATTRS_UNSPECIFIED, NULL); | ||
24 | + /* fallthrough */ | ||
25 | case 3: | ||
26 | address_space_stl_notdirty(&address_space_memory, | ||
27 | SMP_BOOT_REG + 0x20, 0, | ||
28 | MEMTXATTRS_UNSPECIFIED, NULL); | ||
29 | + /* fallthrough */ | ||
30 | case 2: | ||
31 | address_space_stl_notdirty(&address_space_memory, | ||
32 | SMP_BOOT_REG + 0x10, 0, | ||
33 | -- | ||
34 | 2.20.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> | ||
2 | 1 | ||
3 | This patch sets min_cpus field for xlnx-versal-virt platform, | ||
4 | because it always creates XLNX_VERSAL_NR_ACPUS cpus even with | ||
5 | -smp 1 command line option. | ||
6 | |||
7 | Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
10 | Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280 | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | hw/arm/xlnx-versal-virt.c | 1 + | ||
14 | 1 file changed, 1 insertion(+) | ||
15 | |||
16 | diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/arm/xlnx-versal-virt.c | ||
19 | +++ b/hw/arm/xlnx-versal-virt.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) | ||
21 | |||
22 | mc->desc = "Xilinx Versal Virtual development board"; | ||
23 | mc->init = versal_virt_init; | ||
24 | + mc->min_cpus = XLNX_VERSAL_NR_ACPUS; | ||
25 | mc->max_cpus = XLNX_VERSAL_NR_ACPUS; | ||
26 | mc->default_cpus = XLNX_VERSAL_NR_ACPUS; | ||
27 | mc->no_cdrom = true; | ||
28 | -- | ||
29 | 2.20.1 | ||
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Havard Skinnemoen <hskinnemoen@google.com> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The RNG module returns a byte of randomness when the Data Valid bit is | 3 | This commit implements the single-byte mode of the SMBus. |
4 | set. | ||
5 | 4 | ||
6 | This implementation ignores the prescaler setting, and loads a new value | 5 | Each Nuvoton SoC has 16 System Management Bus (SMBus). These buses |
7 | into RNGD every time RNGCS is read while the RNG is enabled and random | 6 | compliant with SMBus and I2C protocol. |
8 | data is available. | ||
9 | 7 | ||
10 | A qtest featuring some simple randomness tests is included. | 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. | ||
11 | 12 | ||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | 13 | Reviewed-by: Doug Evans<dje@google.com> |
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> |
14 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.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> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 20 | --- |
17 | docs/system/arm/nuvoton.rst | 2 +- | 21 | docs/system/arm/nuvoton.rst | 2 +- |
18 | include/hw/arm/npcm7xx.h | 2 + | 22 | include/hw/arm/npcm7xx.h | 2 + |
19 | include/hw/misc/npcm7xx_rng.h | 34 ++++ | 23 | include/hw/i2c/npcm7xx_smbus.h | 88 ++++ |
20 | hw/arm/npcm7xx.c | 7 +- | 24 | hw/arm/npcm7xx.c | 68 ++- |
21 | hw/misc/npcm7xx_rng.c | 180 +++++++++++++++++++++ | 25 | hw/i2c/npcm7xx_smbus.c | 783 +++++++++++++++++++++++++++++++++ |
22 | tests/qtest/npcm7xx_rng-test.c | 278 +++++++++++++++++++++++++++++++++ | 26 | hw/i2c/meson.build | 1 + |
23 | hw/misc/meson.build | 1 + | 27 | hw/i2c/trace-events | 11 + |
24 | hw/misc/trace-events | 4 + | 28 | 7 files changed, 938 insertions(+), 17 deletions(-) |
25 | tests/qtest/meson.build | 5 +- | 29 | create mode 100644 include/hw/i2c/npcm7xx_smbus.h |
26 | 9 files changed, 510 insertions(+), 3 deletions(-) | 30 | create mode 100644 hw/i2c/npcm7xx_smbus.c |
27 | create mode 100644 include/hw/misc/npcm7xx_rng.h | ||
28 | create mode 100644 hw/misc/npcm7xx_rng.c | ||
29 | create mode 100644 tests/qtest/npcm7xx_rng-test.c | ||
30 | 31 | ||
31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
32 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/docs/system/arm/nuvoton.rst | 34 | --- a/docs/system/arm/nuvoton.rst |
34 | +++ b/docs/system/arm/nuvoton.rst | 35 | +++ b/docs/system/arm/nuvoton.rst |
35 | @@ -XXX,XX +XXX,XX @@ Supported devices | 36 | @@ -XXX,XX +XXX,XX @@ Supported devices |
36 | * DDR4 memory controller (dummy interface indicating memory training is done) | 37 | * GPIO controller |
37 | * OTP controllers (no protection features) | 38 | * Analog to Digital Converter (ADC) |
38 | * Flash Interface Unit (FIU; no protection features) | 39 | * Pulse Width Modulation (PWM) |
39 | + * Random Number Generator (RNG) | 40 | + * SMBus controller (SMBF) |
40 | 41 | ||
41 | Missing devices | 42 | Missing devices |
42 | --------------- | 43 | --------------- |
43 | @@ -XXX,XX +XXX,XX @@ Missing devices | 44 | @@ -XXX,XX +XXX,XX @@ Missing devices |
45 | |||
46 | * Ethernet controllers (GMAC and EMC) | ||
47 | * USB device (USBD) | ||
48 | - * SMBus controller (SMBF) | ||
44 | * Peripheral SPI controller (PSPI) | 49 | * Peripheral SPI controller (PSPI) |
45 | * Analog to Digital Converter (ADC) | ||
46 | * SD/MMC host | 50 | * SD/MMC host |
47 | - * Random Number Generator (RNG) | ||
48 | * PECI interface | 51 | * PECI interface |
49 | * Pulse Width Modulation (PWM) | ||
50 | * Tachometer | ||
51 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | 52 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h |
52 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/include/hw/arm/npcm7xx.h | 54 | --- a/include/hw/arm/npcm7xx.h |
54 | +++ b/include/hw/arm/npcm7xx.h | 55 | +++ b/include/hw/arm/npcm7xx.h |
55 | @@ -XXX,XX +XXX,XX @@ | 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" | ||
56 | #include "hw/mem/npcm7xx_mc.h" | 61 | #include "hw/mem/npcm7xx_mc.h" |
57 | #include "hw/misc/npcm7xx_clk.h" | 62 | #include "hw/misc/npcm7xx_clk.h" |
58 | #include "hw/misc/npcm7xx_gcr.h" | 63 | #include "hw/misc/npcm7xx_gcr.h" |
59 | +#include "hw/misc/npcm7xx_rng.h" | ||
60 | #include "hw/nvram/npcm7xx_otp.h" | ||
61 | #include "hw/timer/npcm7xx_timer.h" | ||
62 | #include "hw/ssi/npcm7xx_fiu.h" | ||
63 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | 64 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
64 | NPCM7xxOTPState key_storage; | ||
65 | NPCM7xxOTPState fuse_array; | ||
66 | NPCM7xxMCState mc; | 65 | NPCM7xxMCState mc; |
67 | + NPCM7xxRNGState rng; | 66 | NPCM7xxRNGState rng; |
67 | NPCM7xxGPIOState gpio[8]; | ||
68 | + NPCM7xxSMBusState smbus[16]; | ||
69 | EHCISysBusState ehci; | ||
70 | OHCISysBusState ohci; | ||
68 | NPCM7xxFIUState fiu[2]; | 71 | NPCM7xxFIUState fiu[2]; |
69 | } NPCM7xxState; | 72 | diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h |
70 | |||
71 | diff --git a/include/hw/misc/npcm7xx_rng.h b/include/hw/misc/npcm7xx_rng.h | ||
72 | new file mode 100644 | 73 | new file mode 100644 |
73 | index XXXXXXX..XXXXXXX | 74 | index XXXXXXX..XXXXXXX |
74 | --- /dev/null | 75 | --- /dev/null |
75 | +++ b/include/hw/misc/npcm7xx_rng.h | 76 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
76 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ |
77 | +/* | 78 | +/* |
78 | + * Nuvoton NPCM7xx Random Number Generator. | 79 | + * Nuvoton NPCM7xx SMBus Module. |
79 | + * | 80 | + * |
80 | + * Copyright 2020 Google LLC | 81 | + * Copyright 2020 Google LLC |
81 | + * | 82 | + * |
82 | + * This program is free software; you can redistribute it and/or modify it | 83 | + * This program is free software; you can redistribute it and/or modify it |
83 | + * under the terms of the GNU General Public License as published by the | 84 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
87 | + * This program is distributed in the hope that it will be useful, but WITHOUT | 88 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
88 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 89 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
89 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 90 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90 | + * for more details. | 91 | + * for more details. |
91 | + */ | 92 | + */ |
92 | +#ifndef NPCM7XX_RNG_H | 93 | +#ifndef NPCM7XX_SMBUS_H |
93 | +#define NPCM7XX_RNG_H | 94 | +#define NPCM7XX_SMBUS_H |
94 | + | 95 | + |
96 | +#include "exec/memory.h" | ||
97 | +#include "hw/i2c/i2c.h" | ||
98 | +#include "hw/irq.h" | ||
95 | +#include "hw/sysbus.h" | 99 | +#include "hw/sysbus.h" |
96 | + | 100 | + |
97 | +typedef struct NPCM7xxRNGState { | 101 | +/* |
102 | + * Number of addresses this module contains. Do not change this without | ||
103 | + * incrementing the version_id in the vmstate. | ||
104 | + */ | ||
105 | +#define NPCM7XX_SMBUS_NR_ADDRS 10 | ||
106 | + | ||
107 | +typedef enum NPCM7xxSMBusStatus { | ||
108 | + NPCM7XX_SMBUS_STATUS_IDLE, | ||
109 | + NPCM7XX_SMBUS_STATUS_SENDING, | ||
110 | + NPCM7XX_SMBUS_STATUS_RECEIVING, | ||
111 | + NPCM7XX_SMBUS_STATUS_NEGACK, | ||
112 | + NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE, | ||
113 | + NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK, | ||
114 | +} NPCM7xxSMBusStatus; | ||
115 | + | ||
116 | +/* | ||
117 | + * struct NPCM7xxSMBusState - System Management Bus device state. | ||
118 | + * @bus: The underlying I2C Bus. | ||
119 | + * @irq: GIC interrupt line to fire on events (if enabled). | ||
120 | + * @sda: The serial data register. | ||
121 | + * @st: The status register. | ||
122 | + * @cst: The control status register. | ||
123 | + * @cst2: The control status register 2. | ||
124 | + * @cst3: The control status register 3. | ||
125 | + * @ctl1: The control register 1. | ||
126 | + * @ctl2: The control register 2. | ||
127 | + * @ctl3: The control register 3. | ||
128 | + * @ctl4: The control register 4. | ||
129 | + * @ctl5: The control register 5. | ||
130 | + * @addr: The SMBus module's own addresses on the I2C bus. | ||
131 | + * @scllt: The SCL low time register. | ||
132 | + * @sclht: The SCL high time register. | ||
133 | + * @status: The current status of the SMBus. | ||
134 | + */ | ||
135 | +typedef struct NPCM7xxSMBusState { | ||
98 | + SysBusDevice parent; | 136 | + SysBusDevice parent; |
99 | + | 137 | + |
100 | + MemoryRegion iomem; | 138 | + MemoryRegion iomem; |
101 | + | 139 | + |
102 | + uint8_t rngcs; | 140 | + I2CBus *bus; |
103 | + uint8_t rngd; | 141 | + qemu_irq irq; |
104 | + uint8_t rngmode; | 142 | + |
105 | +} NPCM7xxRNGState; | 143 | + uint8_t sda; |
106 | + | 144 | + uint8_t st; |
107 | +#define TYPE_NPCM7XX_RNG "npcm7xx-rng" | 145 | + uint8_t cst; |
108 | +#define NPCM7XX_RNG(obj) OBJECT_CHECK(NPCM7xxRNGState, (obj), TYPE_NPCM7XX_RNG) | 146 | + uint8_t cst2; |
109 | + | 147 | + uint8_t cst3; |
110 | +#endif /* NPCM7XX_RNG_H */ | 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 */ | ||
111 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | 166 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
112 | index XXXXXXX..XXXXXXX 100644 | 167 | index XXXXXXX..XXXXXXX 100644 |
113 | --- a/hw/arm/npcm7xx.c | 168 | --- a/hw/arm/npcm7xx.c |
114 | +++ b/hw/arm/npcm7xx.c | 169 | +++ b/hw/arm/npcm7xx.c |
115 | @@ -XXX,XX +XXX,XX @@ | 170 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
116 | #define NPCM7XX_GCR_BA (0xf0800000) | 171 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ |
117 | #define NPCM7XX_CLK_BA (0xf0801000) | 172 | NPCM7XX_EHCI_IRQ = 61, |
118 | #define NPCM7XX_MC_BA (0xf0824000) | 173 | NPCM7XX_OHCI_IRQ = 62, |
119 | +#define NPCM7XX_RNG_BA (0xf000b000) | 174 | + NPCM7XX_SMBUS0_IRQ = 64, |
120 | 175 | + NPCM7XX_SMBUS1_IRQ, | |
121 | /* Internal AHB SRAM */ | 176 | + NPCM7XX_SMBUS2_IRQ, |
122 | #define NPCM7XX_RAM3_BA (0xc0008000) | 177 | + NPCM7XX_SMBUS3_IRQ, |
178 | + NPCM7XX_SMBUS4_IRQ, | ||
179 | + NPCM7XX_SMBUS5_IRQ, | ||
180 | + NPCM7XX_SMBUS6_IRQ, | ||
181 | + NPCM7XX_SMBUS7_IRQ, | ||
182 | + NPCM7XX_SMBUS8_IRQ, | ||
183 | + NPCM7XX_SMBUS9_IRQ, | ||
184 | + NPCM7XX_SMBUS10_IRQ, | ||
185 | + NPCM7XX_SMBUS11_IRQ, | ||
186 | + NPCM7XX_SMBUS12_IRQ, | ||
187 | + NPCM7XX_SMBUS13_IRQ, | ||
188 | + NPCM7XX_SMBUS14_IRQ, | ||
189 | + NPCM7XX_SMBUS15_IRQ, | ||
190 | NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ | ||
191 | NPCM7XX_PWM1_IRQ, /* PWM module 1 */ | ||
192 | NPCM7XX_GPIO0_IRQ = 116, | ||
193 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_pwm_addr[] = { | ||
194 | 0xf0104000, | ||
195 | }; | ||
196 | |||
197 | +/* Direct memory-mapped access to each SMBus Module. */ | ||
198 | +static const hwaddr npcm7xx_smbus_addr[] = { | ||
199 | + 0xf0080000, | ||
200 | + 0xf0081000, | ||
201 | + 0xf0082000, | ||
202 | + 0xf0083000, | ||
203 | + 0xf0084000, | ||
204 | + 0xf0085000, | ||
205 | + 0xf0086000, | ||
206 | + 0xf0087000, | ||
207 | + 0xf0088000, | ||
208 | + 0xf0089000, | ||
209 | + 0xf008a000, | ||
210 | + 0xf008b000, | ||
211 | + 0xf008c000, | ||
212 | + 0xf008d000, | ||
213 | + 0xf008e000, | ||
214 | + 0xf008f000, | ||
215 | +}; | ||
216 | + | ||
217 | static const struct { | ||
218 | hwaddr regs_addr; | ||
219 | uint32_t unconnected_pins; | ||
123 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | 220 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
124 | object_initialize_child(obj, "otp2", &s->fuse_array, | 221 | object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); |
125 | TYPE_NPCM7XX_FUSE_ARRAY); | 222 | } |
126 | object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); | 223 | |
127 | + object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG); | 224 | + for (i = 0; i < ARRAY_SIZE(s->smbus); i++) { |
128 | 225 | + object_initialize_child(obj, "smbus[*]", &s->smbus[i], | |
129 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | 226 | + TYPE_NPCM7XX_SMBUS); |
130 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | 227 | + } |
228 | + | ||
229 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
230 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
231 | |||
131 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 232 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
132 | serial_hd(i), DEVICE_LITTLE_ENDIAN); | 233 | npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i)); |
133 | } | 234 | } |
134 | 235 | ||
135 | + /* Random Number Generator. Cannot fail. */ | 236 | + /* SMBus modules. Cannot fail. */ |
136 | + sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | 237 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_smbus_addr) != ARRAY_SIZE(s->smbus)); |
137 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | 238 | + for (i = 0; i < ARRAY_SIZE(s->smbus); i++) { |
138 | + | 239 | + Object *obj = OBJECT(&s->smbus[i]); |
139 | /* | 240 | + |
140 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | 241 | + sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort); |
141 | * specified, but this is a programming error. | 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); | ||
142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 250 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
143 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); | ||
144 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | 251 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); |
145 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | 252 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); |
146 | - create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB); | ||
147 | create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | ||
148 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | 253 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); |
149 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | 254 | - create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB); |
150 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c | 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 | ||
151 | new file mode 100644 | 274 | new file mode 100644 |
152 | index XXXXXXX..XXXXXXX | 275 | index XXXXXXX..XXXXXXX |
153 | --- /dev/null | 276 | --- /dev/null |
154 | +++ b/hw/misc/npcm7xx_rng.c | 277 | +++ b/hw/i2c/npcm7xx_smbus.c |
155 | @@ -XXX,XX +XXX,XX @@ | 278 | @@ -XXX,XX +XXX,XX @@ |
156 | +/* | 279 | +/* |
157 | + * Nuvoton NPCM7xx Random Number Generator. | 280 | + * Nuvoton NPCM7xx SMBus Module. |
158 | + * | 281 | + * |
159 | + * Copyright 2020 Google LLC | 282 | + * Copyright 2020 Google LLC |
160 | + * | 283 | + * |
161 | + * This program is free software; you can redistribute it and/or modify it | 284 | + * This program is free software; you can redistribute it and/or modify it |
162 | + * under the terms of the GNU General Public License as published by the | 285 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
169 | + * for more details. | 292 | + * for more details. |
170 | + */ | 293 | + */ |
171 | + | 294 | + |
172 | +#include "qemu/osdep.h" | 295 | +#include "qemu/osdep.h" |
173 | + | 296 | + |
174 | +#include "hw/misc/npcm7xx_rng.h" | 297 | +#include "hw/i2c/npcm7xx_smbus.h" |
175 | +#include "migration/vmstate.h" | 298 | +#include "migration/vmstate.h" |
176 | +#include "qemu/bitops.h" | 299 | +#include "qemu/bitops.h" |
177 | +#include "qemu/guest-random.h" | 300 | +#include "qemu/guest-random.h" |
178 | +#include "qemu/log.h" | 301 | +#include "qemu/log.h" |
179 | +#include "qemu/module.h" | 302 | +#include "qemu/module.h" |
180 | +#include "qemu/units.h" | 303 | +#include "qemu/units.h" |
181 | + | 304 | + |
182 | +#include "trace.h" | 305 | +#include "trace.h" |
183 | + | 306 | + |
184 | +#define NPCM7XX_RNG_REGS_SIZE (4 * KiB) | 307 | +enum NPCM7xxSMBusCommonRegister { |
185 | + | 308 | + NPCM7XX_SMB_SDA = 0x0, |
186 | +#define NPCM7XX_RNGCS (0x00) | 309 | + NPCM7XX_SMB_ST = 0x2, |
187 | +#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4) | 310 | + NPCM7XX_SMB_CST = 0x4, |
188 | +#define NPCM7XX_RNGCS_DVALID BIT(1) | 311 | + NPCM7XX_SMB_CTL1 = 0x6, |
189 | +#define NPCM7XX_RNGCS_RNGE BIT(0) | 312 | + NPCM7XX_SMB_ADDR1 = 0x8, |
190 | + | 313 | + NPCM7XX_SMB_CTL2 = 0xa, |
191 | +#define NPCM7XX_RNGD (0x04) | 314 | + NPCM7XX_SMB_ADDR2 = 0xc, |
192 | +#define NPCM7XX_RNGMODE (0x08) | 315 | + NPCM7XX_SMB_CTL3 = 0xe, |
193 | +#define NPCM7XX_RNGMODE_NORMAL (0x02) | 316 | + NPCM7XX_SMB_CST2 = 0x18, |
194 | + | 317 | + NPCM7XX_SMB_CST3 = 0x19, |
195 | +static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s) | 318 | + NPCM7XX_SMB_VER = 0x1f, |
196 | +{ | 319 | +}; |
197 | + return (s->rngcs & NPCM7XX_RNGCS_RNGE) && | 320 | + |
198 | + (s->rngmode == NPCM7XX_RNGMODE_NORMAL); | 321 | +enum NPCM7xxSMBusBank0Register { |
199 | +} | 322 | + NPCM7XX_SMB_ADDR3 = 0x10, |
200 | + | 323 | + NPCM7XX_SMB_ADDR7 = 0x11, |
201 | +static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size) | 324 | + NPCM7XX_SMB_ADDR4 = 0x12, |
202 | +{ | 325 | + NPCM7XX_SMB_ADDR8 = 0x13, |
203 | + NPCM7xxRNGState *s = opaque; | 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); | ||
542 | + return; | ||
543 | + } | ||
544 | + | ||
545 | + s->st &= ~NPCM7XX_SMBST_NEGACK; | ||
546 | + if (recv) { | ||
547 | + s->status = NPCM7XX_SMBUS_STATUS_RECEIVING; | ||
548 | + s->st &= ~NPCM7XX_SMBST_XMIT; | ||
549 | + } else { | ||
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; | ||
204 | + uint64_t value = 0; | 715 | + uint64_t value = 0; |
205 | + | 716 | + uint8_t bank = s->ctl3 & NPCM7XX_SMBCTL3_BNK_SEL; |
717 | + | ||
718 | + /* The order of the registers are their order in memory. */ | ||
206 | + switch (offset) { | 719 | + switch (offset) { |
207 | + case NPCM7XX_RNGCS: | 720 | + case NPCM7XX_SMB_SDA: |
208 | + /* | 721 | + value = npcm7xx_smbus_read_sda(s); |
209 | + * If the RNG is enabled, but we don't have any valid random data, try | 722 | + break; |
210 | + * obtaining some and update the DVALID bit accordingly. | 723 | + |
211 | + */ | 724 | + case NPCM7XX_SMB_ST: |
212 | + if (!npcm7xx_rng_is_enabled(s)) { | 725 | + value = s->st; |
213 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | 726 | + break; |
214 | + } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) { | 727 | + |
215 | + uint8_t byte = 0; | 728 | + case NPCM7XX_SMB_CST: |
216 | + | 729 | + value = s->cst; |
217 | + if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) { | 730 | + break; |
218 | + s->rngd = byte; | 731 | + |
219 | + s->rngcs |= NPCM7XX_RNGCS_DVALID; | 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; | ||
220 | + } | 827 | + } |
221 | + } | 828 | + } |
222 | + value = s->rngcs; | 829 | + break; |
223 | + break; | 830 | + } |
224 | + case NPCM7XX_RNGD: | 831 | + |
225 | + if (npcm7xx_rng_is_enabled(s) && s->rngcs & NPCM7XX_RNGCS_DVALID) { | 832 | + trace_npcm7xx_smbus_read(DEVICE(s)->canonical_path, offset, value, size); |
226 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | 833 | + |
227 | + value = s->rngd; | 834 | + return value; |
228 | + s->rngd = 0; | 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 | + } | ||
229 | + } | 959 | + } |
230 | + break; | 960 | + break; |
231 | + case NPCM7XX_RNGMODE: | 961 | + } |
232 | + value = s->rngmode; | 962 | +} |
233 | + break; | 963 | + |
234 | + | 964 | +static const MemoryRegionOps npcm7xx_smbus_ops = { |
235 | + default: | 965 | + .read = npcm7xx_smbus_read, |
236 | + qemu_log_mask(LOG_GUEST_ERROR, | 966 | + .write = npcm7xx_smbus_write, |
237 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
238 | + DEVICE(s)->canonical_path, offset); | ||
239 | + break; | ||
240 | + } | ||
241 | + | ||
242 | + trace_npcm7xx_rng_read(offset, value, size); | ||
243 | + | ||
244 | + return value; | ||
245 | +} | ||
246 | + | ||
247 | +static void npcm7xx_rng_write(void *opaque, hwaddr offset, uint64_t value, | ||
248 | + unsigned size) | ||
249 | +{ | ||
250 | + NPCM7xxRNGState *s = opaque; | ||
251 | + | ||
252 | + trace_npcm7xx_rng_write(offset, value, size); | ||
253 | + | ||
254 | + switch (offset) { | ||
255 | + case NPCM7XX_RNGCS: | ||
256 | + s->rngcs &= NPCM7XX_RNGCS_DVALID; | ||
257 | + s->rngcs |= value & ~NPCM7XX_RNGCS_DVALID; | ||
258 | + break; | ||
259 | + case NPCM7XX_RNGD: | ||
260 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
261 | + "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n", | ||
262 | + DEVICE(s)->canonical_path, offset); | ||
263 | + break; | ||
264 | + case NPCM7XX_RNGMODE: | ||
265 | + s->rngmode = value; | ||
266 | + break; | ||
267 | + default: | ||
268 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
269 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
270 | + DEVICE(s)->canonical_path, offset); | ||
271 | + break; | ||
272 | + } | ||
273 | +} | ||
274 | + | ||
275 | +static const MemoryRegionOps npcm7xx_rng_ops = { | ||
276 | + .read = npcm7xx_rng_read, | ||
277 | + .write = npcm7xx_rng_write, | ||
278 | + .endianness = DEVICE_LITTLE_ENDIAN, | 967 | + .endianness = DEVICE_LITTLE_ENDIAN, |
279 | + .valid = { | 968 | + .valid = { |
280 | + .min_access_size = 1, | 969 | + .min_access_size = 1, |
281 | + .max_access_size = 4, | 970 | + .max_access_size = 1, |
282 | + .unaligned = false, | 971 | + .unaligned = false, |
283 | + }, | 972 | + }, |
284 | +}; | 973 | +}; |
285 | + | 974 | + |
286 | +static void npcm7xx_rng_enter_reset(Object *obj, ResetType type) | 975 | +static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type) |
287 | +{ | 976 | +{ |
288 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | 977 | + NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj); |
289 | + | 978 | + |
290 | + s->rngcs = 0; | 979 | + s->st = NPCM7XX_SMB_ST_INIT_VAL; |
291 | + s->rngd = 0; | 980 | + s->cst = NPCM7XX_SMB_CST_INIT_VAL; |
292 | + s->rngmode = 0; | 981 | + s->cst2 = NPCM7XX_SMB_CST2_INIT_VAL; |
293 | +} | 982 | + s->cst3 = NPCM7XX_SMB_CST3_INIT_VAL; |
294 | + | 983 | + s->ctl1 = NPCM7XX_SMB_CTL1_INIT_VAL; |
295 | +static void npcm7xx_rng_init(Object *obj) | 984 | + s->ctl2 = NPCM7XX_SMB_CTL2_INIT_VAL; |
296 | +{ | 985 | + s->ctl3 = NPCM7XX_SMB_CTL3_INIT_VAL; |
297 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | 986 | + s->ctl4 = NPCM7XX_SMB_CTL4_INIT_VAL; |
298 | + | 987 | + s->ctl5 = NPCM7XX_SMB_CTL5_INIT_VAL; |
299 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs", | 988 | + |
300 | + NPCM7XX_RNG_REGS_SIZE); | 989 | + for (int i = 0; i < NPCM7XX_SMBUS_NR_ADDRS; ++i) { |
301 | + sysbus_init_mmio(&s->parent, &s->iomem); | 990 | + s->addr[i] = NPCM7XX_SMB_ADDR_INIT_VAL; |
302 | +} | 991 | + } |
303 | + | 992 | + s->scllt = NPCM7XX_SMB_SCLLT_INIT_VAL; |
304 | +static const VMStateDescription vmstate_npcm7xx_rng = { | 993 | + s->sclht = NPCM7XX_SMB_SCLHT_INIT_VAL; |
305 | + .name = "npcm7xx-rng", | 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", | ||
306 | + .version_id = 0, | 1021 | + .version_id = 0, |
307 | + .minimum_version_id = 0, | 1022 | + .minimum_version_id = 0, |
308 | + .fields = (VMStateField[]) { | 1023 | + .fields = (VMStateField[]) { |
309 | + VMSTATE_UINT8(rngcs, NPCM7xxRNGState), | 1024 | + VMSTATE_UINT8(sda, NPCM7xxSMBusState), |
310 | + VMSTATE_UINT8(rngd, NPCM7xxRNGState), | 1025 | + VMSTATE_UINT8(st, NPCM7xxSMBusState), |
311 | + VMSTATE_UINT8(rngmode, NPCM7xxRNGState), | 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), | ||
312 | + VMSTATE_END_OF_LIST(), | 1037 | + VMSTATE_END_OF_LIST(), |
313 | + }, | 1038 | + }, |
314 | +}; | 1039 | +}; |
315 | + | 1040 | + |
316 | +static void npcm7xx_rng_class_init(ObjectClass *klass, void *data) | 1041 | +static void npcm7xx_smbus_class_init(ObjectClass *klass, void *data) |
317 | +{ | 1042 | +{ |
318 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | 1043 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
319 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1044 | + DeviceClass *dc = DEVICE_CLASS(klass); |
320 | + | 1045 | + |
321 | + dc->desc = "NPCM7xx Random Number Generator"; | 1046 | + dc->desc = "NPCM7xx System Management Bus"; |
322 | + dc->vmsd = &vmstate_npcm7xx_rng; | 1047 | + dc->vmsd = &vmstate_npcm7xx_smbus; |
323 | + rc->phases.enter = npcm7xx_rng_enter_reset; | 1048 | + rc->phases.enter = npcm7xx_smbus_enter_reset; |
324 | +} | 1049 | + rc->phases.hold = npcm7xx_smbus_hold_reset; |
325 | + | 1050 | +} |
326 | +static const TypeInfo npcm7xx_rng_types[] = { | 1051 | + |
1052 | +static const TypeInfo npcm7xx_smbus_types[] = { | ||
327 | + { | 1053 | + { |
328 | + .name = TYPE_NPCM7XX_RNG, | 1054 | + .name = TYPE_NPCM7XX_SMBUS, |
329 | + .parent = TYPE_SYS_BUS_DEVICE, | 1055 | + .parent = TYPE_SYS_BUS_DEVICE, |
330 | + .instance_size = sizeof(NPCM7xxRNGState), | 1056 | + .instance_size = sizeof(NPCM7xxSMBusState), |
331 | + .class_init = npcm7xx_rng_class_init, | 1057 | + .class_init = npcm7xx_smbus_class_init, |
332 | + .instance_init = npcm7xx_rng_init, | 1058 | + .instance_init = npcm7xx_smbus_init, |
333 | + }, | 1059 | + }, |
334 | +}; | 1060 | +}; |
335 | +DEFINE_TYPES(npcm7xx_rng_types); | 1061 | +DEFINE_TYPES(npcm7xx_smbus_types); |
336 | diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c | 1062 | diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build |
337 | new file mode 100644 | ||
338 | index XXXXXXX..XXXXXXX | ||
339 | --- /dev/null | ||
340 | +++ b/tests/qtest/npcm7xx_rng-test.c | ||
341 | @@ -XXX,XX +XXX,XX @@ | ||
342 | +/* | ||
343 | + * QTest testcase for the Nuvoton NPCM7xx Random Number Generator | ||
344 | + * | ||
345 | + * Copyright 2020 Google LLC | ||
346 | + * | ||
347 | + * This program is free software; you can redistribute it and/or modify it | ||
348 | + * under the terms of the GNU General Public License as published by the | ||
349 | + * Free Software Foundation; either version 2 of the License, or | ||
350 | + * (at your option) any later version. | ||
351 | + * | ||
352 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
353 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
354 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
355 | + * for more details. | ||
356 | + */ | ||
357 | + | ||
358 | +#include "qemu/osdep.h" | ||
359 | + | ||
360 | +#include <math.h> | ||
361 | + | ||
362 | +#include "libqtest-single.h" | ||
363 | +#include "qemu/bitops.h" | ||
364 | + | ||
365 | +#define RNG_BASE_ADDR 0xf000b000 | ||
366 | + | ||
367 | +/* Control and Status Register */ | ||
368 | +#define RNGCS 0x00 | ||
369 | +# define DVALID BIT(1) /* Data Valid */ | ||
370 | +# define RNGE BIT(0) /* RNG Enable */ | ||
371 | +/* Data Register */ | ||
372 | +#define RNGD 0x04 | ||
373 | +/* Mode Register */ | ||
374 | +#define RNGMODE 0x08 | ||
375 | +# define ROSEL_NORMAL (2) /* RNG only works in this mode */ | ||
376 | + | ||
377 | +/* Number of bits to collect for randomness tests. */ | ||
378 | +#define TEST_INPUT_BITS (128) | ||
379 | + | ||
380 | +static void rng_writeb(unsigned int offset, uint8_t value) | ||
381 | +{ | ||
382 | + writeb(RNG_BASE_ADDR + offset, value); | ||
383 | +} | ||
384 | + | ||
385 | +static uint8_t rng_readb(unsigned int offset) | ||
386 | +{ | ||
387 | + return readb(RNG_BASE_ADDR + offset); | ||
388 | +} | ||
389 | + | ||
390 | +/* Disable RNG and set normal ring oscillator mode. */ | ||
391 | +static void rng_reset(void) | ||
392 | +{ | ||
393 | + rng_writeb(RNGCS, 0); | ||
394 | + rng_writeb(RNGMODE, ROSEL_NORMAL); | ||
395 | +} | ||
396 | + | ||
397 | +/* Reset RNG and then enable it. */ | ||
398 | +static void rng_reset_enable(void) | ||
399 | +{ | ||
400 | + rng_reset(); | ||
401 | + rng_writeb(RNGCS, RNGE); | ||
402 | +} | ||
403 | + | ||
404 | +/* Wait until Data Valid bit is set. */ | ||
405 | +static bool rng_wait_ready(void) | ||
406 | +{ | ||
407 | + /* qemu_guest_getrandom may fail. Assume it won't fail 10 times in a row. */ | ||
408 | + int retries = 10; | ||
409 | + | ||
410 | + while (retries-- > 0) { | ||
411 | + if (rng_readb(RNGCS) & DVALID) { | ||
412 | + return true; | ||
413 | + } | ||
414 | + } | ||
415 | + | ||
416 | + return false; | ||
417 | +} | ||
418 | + | ||
419 | +/* | ||
420 | + * Perform a frequency (monobit) test, as defined by NIST SP 800-22, on the | ||
421 | + * sequence in buf and return the P-value. This represents the probability of a | ||
422 | + * truly random sequence having the same proportion of zeros and ones as the | ||
423 | + * sequence in buf. | ||
424 | + * | ||
425 | + * An RNG which always returns 0x00 or 0xff, or has some bits stuck at 0 or 1, | ||
426 | + * will fail this test. However, an RNG which always returns 0x55, 0xf0 or some | ||
427 | + * other value with an equal number of zeroes and ones will pass. | ||
428 | + */ | ||
429 | +static double calc_monobit_p(const uint8_t *buf, unsigned int len) | ||
430 | +{ | ||
431 | + unsigned int i; | ||
432 | + double s_obs; | ||
433 | + int sn = 0; | ||
434 | + | ||
435 | + for (i = 0; i < len; i++) { | ||
436 | + /* | ||
437 | + * Each 1 counts as 1, each 0 counts as -1. | ||
438 | + * s = cp - (8 - cp) = 2 * cp - 8 | ||
439 | + */ | ||
440 | + sn += 2 * ctpop8(buf[i]) - 8; | ||
441 | + } | ||
442 | + | ||
443 | + s_obs = abs(sn) / sqrt(len * BITS_PER_BYTE); | ||
444 | + | ||
445 | + return erfc(s_obs / sqrt(2)); | ||
446 | +} | ||
447 | + | ||
448 | +/* | ||
449 | + * Perform a runs test, as defined by NIST SP 800-22, and return the P-value. | ||
450 | + * This represents the probability of a truly random sequence having the same | ||
451 | + * number of runs (i.e. uninterrupted sequences of identical bits) as the | ||
452 | + * sequence in buf. | ||
453 | + */ | ||
454 | +static double calc_runs_p(const unsigned long *buf, unsigned int nr_bits) | ||
455 | +{ | ||
456 | + unsigned int j; | ||
457 | + unsigned int k; | ||
458 | + int nr_ones = 0; | ||
459 | + int vn_obs = 0; | ||
460 | + double pi; | ||
461 | + | ||
462 | + g_assert(nr_bits % BITS_PER_LONG == 0); | ||
463 | + | ||
464 | + for (j = 0; j < nr_bits / BITS_PER_LONG; j++) { | ||
465 | + nr_ones += __builtin_popcountl(buf[j]); | ||
466 | + } | ||
467 | + pi = (double)nr_ones / nr_bits; | ||
468 | + | ||
469 | + for (k = 0; k < nr_bits - 1; k++) { | ||
470 | + vn_obs += !(test_bit(k, buf) ^ test_bit(k + 1, buf)); | ||
471 | + } | ||
472 | + vn_obs += 1; | ||
473 | + | ||
474 | + return erfc(fabs(vn_obs - 2 * nr_bits * pi * (1.0 - pi)) | ||
475 | + / (2 * sqrt(2 * nr_bits) * pi * (1.0 - pi))); | ||
476 | +} | ||
477 | + | ||
478 | +/* | ||
479 | + * Verifies that DVALID is clear, and RNGD reads zero, when RNGE is cleared, | ||
480 | + * and DVALID eventually becomes set when RNGE is set. | ||
481 | + */ | ||
482 | +static void test_enable_disable(void) | ||
483 | +{ | ||
484 | + /* Disable: DVALID should not be set, and RNGD should read zero */ | ||
485 | + rng_reset(); | ||
486 | + g_assert_cmphex(rng_readb(RNGCS), ==, 0); | ||
487 | + g_assert_cmphex(rng_readb(RNGD), ==, 0); | ||
488 | + | ||
489 | + /* Enable: DVALID should be set, but we can't make assumptions about RNGD */ | ||
490 | + rng_writeb(RNGCS, RNGE); | ||
491 | + g_assert_true(rng_wait_ready()); | ||
492 | + g_assert_cmphex(rng_readb(RNGCS), ==, DVALID | RNGE); | ||
493 | + | ||
494 | + /* Disable: DVALID should not be set, and RNGD should read zero */ | ||
495 | + rng_writeb(RNGCS, 0); | ||
496 | + g_assert_cmphex(rng_readb(RNGCS), ==, 0); | ||
497 | + g_assert_cmphex(rng_readb(RNGD), ==, 0); | ||
498 | +} | ||
499 | + | ||
500 | +/* | ||
501 | + * Verifies that the RNG only produces data when RNGMODE is set to 'normal' | ||
502 | + * ring oscillator mode. | ||
503 | + */ | ||
504 | +static void test_rosel(void) | ||
505 | +{ | ||
506 | + rng_reset_enable(); | ||
507 | + g_assert_true(rng_wait_ready()); | ||
508 | + rng_writeb(RNGMODE, 0); | ||
509 | + g_assert_false(rng_wait_ready()); | ||
510 | + rng_writeb(RNGMODE, ROSEL_NORMAL); | ||
511 | + g_assert_true(rng_wait_ready()); | ||
512 | + rng_writeb(RNGMODE, 0); | ||
513 | + g_assert_false(rng_wait_ready()); | ||
514 | +} | ||
515 | + | ||
516 | +/* | ||
517 | + * Verifies that a continuous sequence of bits collected after enabling the RNG | ||
518 | + * satisfies a monobit test. | ||
519 | + */ | ||
520 | +static void test_continuous_monobit(void) | ||
521 | +{ | ||
522 | + uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
523 | + unsigned int i; | ||
524 | + | ||
525 | + rng_reset_enable(); | ||
526 | + for (i = 0; i < sizeof(buf); i++) { | ||
527 | + g_assert_true(rng_wait_ready()); | ||
528 | + buf[i] = rng_readb(RNGD); | ||
529 | + } | ||
530 | + | ||
531 | + g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01); | ||
532 | +} | ||
533 | + | ||
534 | +/* | ||
535 | + * Verifies that a continuous sequence of bits collected after enabling the RNG | ||
536 | + * satisfies a runs test. | ||
537 | + */ | ||
538 | +static void test_continuous_runs(void) | ||
539 | +{ | ||
540 | + union { | ||
541 | + unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG]; | ||
542 | + uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
543 | + } buf; | ||
544 | + unsigned int i; | ||
545 | + | ||
546 | + rng_reset_enable(); | ||
547 | + for (i = 0; i < sizeof(buf); i++) { | ||
548 | + g_assert_true(rng_wait_ready()); | ||
549 | + buf.c[i] = rng_readb(RNGD); | ||
550 | + } | ||
551 | + | ||
552 | + g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01); | ||
553 | +} | ||
554 | + | ||
555 | +/* | ||
556 | + * Verifies that the first data byte collected after enabling the RNG satisfies | ||
557 | + * a monobit test. | ||
558 | + */ | ||
559 | +static void test_first_byte_monobit(void) | ||
560 | +{ | ||
561 | + /* Enable, collect one byte, disable. Repeat until we have 100 bits. */ | ||
562 | + uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
563 | + unsigned int i; | ||
564 | + | ||
565 | + rng_reset(); | ||
566 | + for (i = 0; i < sizeof(buf); i++) { | ||
567 | + rng_writeb(RNGCS, RNGE); | ||
568 | + g_assert_true(rng_wait_ready()); | ||
569 | + buf[i] = rng_readb(RNGD); | ||
570 | + rng_writeb(RNGCS, 0); | ||
571 | + } | ||
572 | + | ||
573 | + g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01); | ||
574 | +} | ||
575 | + | ||
576 | +/* | ||
577 | + * Verifies that the first data byte collected after enabling the RNG satisfies | ||
578 | + * a runs test. | ||
579 | + */ | ||
580 | +static void test_first_byte_runs(void) | ||
581 | +{ | ||
582 | + /* Enable, collect one byte, disable. Repeat until we have 100 bits. */ | ||
583 | + union { | ||
584 | + unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG]; | ||
585 | + uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
586 | + } buf; | ||
587 | + unsigned int i; | ||
588 | + | ||
589 | + rng_reset(); | ||
590 | + for (i = 0; i < sizeof(buf); i++) { | ||
591 | + rng_writeb(RNGCS, RNGE); | ||
592 | + g_assert_true(rng_wait_ready()); | ||
593 | + buf.c[i] = rng_readb(RNGD); | ||
594 | + rng_writeb(RNGCS, 0); | ||
595 | + } | ||
596 | + | ||
597 | + g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01); | ||
598 | +} | ||
599 | + | ||
600 | +int main(int argc, char **argv) | ||
601 | +{ | ||
602 | + int ret; | ||
603 | + | ||
604 | + g_test_init(&argc, &argv, NULL); | ||
605 | + g_test_set_nonfatal_assertions(); | ||
606 | + | ||
607 | + qtest_add_func("npcm7xx_rng/enable_disable", test_enable_disable); | ||
608 | + qtest_add_func("npcm7xx_rng/rosel", test_rosel); | ||
609 | + qtest_add_func("npcm7xx_rng/continuous/monobit", test_continuous_monobit); | ||
610 | + qtest_add_func("npcm7xx_rng/continuous/runs", test_continuous_runs); | ||
611 | + qtest_add_func("npcm7xx_rng/first_byte/monobit", test_first_byte_monobit); | ||
612 | + qtest_add_func("npcm7xx_rng/first_byte/runs", test_first_byte_runs); | ||
613 | + | ||
614 | + qtest_start("-machine npcm750-evb"); | ||
615 | + ret = g_test_run(); | ||
616 | + qtest_end(); | ||
617 | + | ||
618 | + return ret; | ||
619 | +} | ||
620 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
621 | index XXXXXXX..XXXXXXX 100644 | 1063 | index XXXXXXX..XXXXXXX 100644 |
622 | --- a/hw/misc/meson.build | 1064 | --- a/hw/i2c/meson.build |
623 | +++ b/hw/misc/meson.build | 1065 | +++ b/hw/i2c/meson.build |
624 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) | 1066 | @@ -XXX,XX +XXX,XX @@ i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) |
625 | softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( | 1067 | i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c')) |
626 | 'npcm7xx_clk.c', | 1068 | i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) |
627 | 'npcm7xx_gcr.c', | 1069 | i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) |
628 | + 'npcm7xx_rng.c', | 1070 | +i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c')) |
629 | )) | 1071 | i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c')) |
630 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( | 1072 | i2c_ss.add(when: 'CONFIG_VERSATILE_I2C', if_true: files('versatile_i2c.c')) |
631 | 'omap_clk.c', | 1073 | i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c')) |
632 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 1074 | diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events |
633 | index XXXXXXX..XXXXXXX 100644 | 1075 | index XXXXXXX..XXXXXXX 100644 |
634 | --- a/hw/misc/trace-events | 1076 | --- a/hw/i2c/trace-events |
635 | +++ b/hw/misc/trace-events | 1077 | +++ b/hw/i2c/trace-events |
636 | @@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu | 1078 | @@ -XXX,XX +XXX,XX @@ aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t val |
637 | npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | 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 |
638 | npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | 1080 | aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" |
639 | 1081 | aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x" | |
640 | +# npcm7xx_rng.c | 1082 | + |
641 | +npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | 1083 | +# npcm7xx_smbus.c |
642 | +npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | 1084 | + |
643 | + | 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" |
644 | # stm32f4xx_syscfg.c | 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" |
645 | stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" | 1087 | +npcm7xx_smbus_start(const char *id, int success) "%s starting, success: %d" |
646 | stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %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" |
647 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 1089 | +npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byte: 0x%02x, success: %d" |
648 | index XXXXXXX..XXXXXXX 100644 | 1090 | +npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x" |
649 | --- a/tests/qtest/meson.build | 1091 | +npcm7xx_smbus_stop(const char *id) "%s stopping" |
650 | +++ b/tests/qtest/meson.build | 1092 | +npcm7xx_smbus_nack(const char *id) "%s nacking" |
651 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
652 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | ||
653 | ['prom-env-test', 'boot-serial-test'] | ||
654 | |||
655 | -qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | ||
656 | +qtests_npcm7xx = \ | ||
657 | + ['npcm7xx_rng-test', | ||
658 | + 'npcm7xx_timer-test', | ||
659 | + 'npcm7xx_watchdog_timer-test'] | ||
660 | qtests_arm = \ | ||
661 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | ||
662 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
663 | -- | 1093 | -- |
664 | 2.20.1 | 1094 | 2.20.1 |
665 | 1095 | ||
666 | 1096 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Add a clock input to the PL011 UART so we can compute the current baud | 3 | Add I2C temperature sensors for NPCM750 eval board. |
4 | rate and trace it. This is intended for developers who wish to use QEMU | ||
5 | to e.g. debug their firmware or to figure out the baud rate configured | ||
6 | by an unknown/closed source binary. | ||
7 | 4 | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Reviewed-by: Doug Evans<dje@google.com> |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 6 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> |
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
11 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Message-id: 20210210220426.3577804-3-wuhaotsh@google.com | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 11 | --- |
14 | include/hw/char/pl011.h | 1 + | 12 | hw/arm/npcm7xx_boards.c | 19 +++++++++++++++++++ |
15 | hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ | 13 | 1 file changed, 19 insertions(+) |
16 | hw/char/trace-events | 1 + | ||
17 | 3 files changed, 47 insertions(+) | ||
18 | 14 | ||
19 | diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h | 15 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
20 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/char/pl011.h | 17 | --- a/hw/arm/npcm7xx_boards.c |
22 | +++ b/include/hw/char/pl011.h | 18 | +++ b/hw/arm/npcm7xx_boards.c |
23 | @@ -XXX,XX +XXX,XX @@ struct PL011State { | 19 | @@ -XXX,XX +XXX,XX @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, |
24 | int read_trigger; | 20 | return NPCM7XX(obj); |
25 | CharBackend chr; | ||
26 | qemu_irq irq[6]; | ||
27 | + Clock *clk; | ||
28 | const unsigned char *id; | ||
29 | }; | ||
30 | |||
31 | diff --git a/hw/char/pl011.c b/hw/char/pl011.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/hw/char/pl011.c | ||
34 | +++ b/hw/char/pl011.c | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "hw/char/pl011.h" | ||
37 | #include "hw/irq.h" | ||
38 | #include "hw/sysbus.h" | ||
39 | +#include "hw/qdev-clock.h" | ||
40 | #include "migration/vmstate.h" | ||
41 | #include "chardev/char-fe.h" | ||
42 | #include "qemu/log.h" | ||
43 | @@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s) | ||
44 | s->read_trigger = 1; | ||
45 | } | 21 | } |
46 | 22 | ||
47 | +static unsigned int pl011_get_baudrate(const PL011State *s) | 23 | +static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num) |
48 | +{ | 24 | +{ |
49 | + uint64_t clk; | 25 | + g_assert(num < ARRAY_SIZE(soc->smbus)); |
50 | + | 26 | + return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus")); |
51 | + if (s->fbrd == 0) { | ||
52 | + return 0; | ||
53 | + } | ||
54 | + | ||
55 | + clk = clock_get_hz(s->clk); | ||
56 | + return (clk / ((s->ibrd << 6) + s->fbrd)) << 2; | ||
57 | +} | 27 | +} |
58 | + | 28 | + |
59 | +static void pl011_trace_baudrate_change(const PL011State *s) | 29 | +static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
60 | +{ | 30 | +{ |
61 | + trace_pl011_baudrate_change(pl011_get_baudrate(s), | 31 | + /* lm75 temperature sensor on SVB, tmp105 is compatible */ |
62 | + clock_get_hz(s->clk), | 32 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48); |
63 | + s->ibrd, s->fbrd); | 33 | + /* lm75 temperature sensor on EB, tmp105 is compatible */ |
34 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48); | ||
35 | + /* tmp100 temperature sensor on EB, tmp105 is compatible */ | ||
36 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48); | ||
37 | + /* tmp100 temperature sensor on SVB, tmp105 is compatible */ | ||
38 | + i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); | ||
64 | +} | 39 | +} |
65 | + | 40 | + |
66 | static void pl011_write(void *opaque, hwaddr offset, | 41 | static void npcm750_evb_init(MachineState *machine) |
67 | uint64_t value, unsigned size) | ||
68 | { | 42 | { |
69 | @@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset, | 43 | NPCM7xxState *soc; |
70 | break; | 44 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine) |
71 | case 9: /* UARTIBRD */ | 45 | |
72 | s->ibrd = value; | 46 | npcm7xx_load_bootrom(machine, soc); |
73 | + pl011_trace_baudrate_change(s); | 47 | npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0)); |
74 | break; | 48 | + npcm750_evb_i2c_init(soc); |
75 | case 10: /* UARTFBRD */ | 49 | npcm7xx_load_kernel(machine, soc); |
76 | s->fbrd = value; | ||
77 | + pl011_trace_baudrate_change(s); | ||
78 | break; | ||
79 | case 11: /* UARTLCR_H */ | ||
80 | /* Reset the FIFO state on FIFO enable or disable */ | ||
81 | @@ -XXX,XX +XXX,XX @@ static void pl011_event(void *opaque, QEMUChrEvent event) | ||
82 | pl011_put_fifo(opaque, 0x400); | ||
83 | } | 50 | } |
84 | 51 | ||
85 | +static void pl011_clock_update(void *opaque) | ||
86 | +{ | ||
87 | + PL011State *s = PL011(opaque); | ||
88 | + | ||
89 | + pl011_trace_baudrate_change(s); | ||
90 | +} | ||
91 | + | ||
92 | static const MemoryRegionOps pl011_ops = { | ||
93 | .read = pl011_read, | ||
94 | .write = pl011_write, | ||
95 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
96 | }; | ||
97 | |||
98 | +static const VMStateDescription vmstate_pl011_clock = { | ||
99 | + .name = "pl011/clock", | ||
100 | + .version_id = 1, | ||
101 | + .minimum_version_id = 1, | ||
102 | + .fields = (VMStateField[]) { | ||
103 | + VMSTATE_CLOCK(clk, PL011State), | ||
104 | + VMSTATE_END_OF_LIST() | ||
105 | + } | ||
106 | +}; | ||
107 | + | ||
108 | static const VMStateDescription vmstate_pl011 = { | ||
109 | .name = "pl011", | ||
110 | .version_id = 2, | ||
111 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = { | ||
112 | VMSTATE_INT32(read_count, PL011State), | ||
113 | VMSTATE_INT32(read_trigger, PL011State), | ||
114 | VMSTATE_END_OF_LIST() | ||
115 | + }, | ||
116 | + .subsections = (const VMStateDescription * []) { | ||
117 | + &vmstate_pl011_clock, | ||
118 | + NULL | ||
119 | } | ||
120 | }; | ||
121 | |||
122 | @@ -XXX,XX +XXX,XX @@ static void pl011_init(Object *obj) | ||
123 | sysbus_init_irq(sbd, &s->irq[i]); | ||
124 | } | ||
125 | |||
126 | + s->clk = qdev_init_clock_in(DEVICE(obj), "clk", pl011_clock_update, s); | ||
127 | + | ||
128 | s->read_trigger = 1; | ||
129 | s->ifl = 0x12; | ||
130 | s->cr = 0x300; | ||
131 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/hw/char/trace-events | ||
134 | +++ b/hw/char/trace-events | ||
135 | @@ -XXX,XX +XXX,XX @@ pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" | ||
136 | pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" | ||
137 | pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" | ||
138 | pl011_put_fifo_full(void) "FIFO now full, RXFF set" | ||
139 | +pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" | ||
140 | |||
141 | # cmsdk-apb-uart.c | ||
142 | cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
143 | -- | 52 | -- |
144 | 2.20.1 | 53 | 2.20.1 |
145 | 54 | ||
146 | 55 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Those reset values have been extracted from a Raspberry Pi 3 model B | 3 | Add AT24 EEPROM and temperature sensors for GSJ machine. |
4 | v1.2, using the 2020-08-20 version of raspios. The dump was done using | ||
5 | the debugfs interface of the CPRMAN driver in Linux (under | ||
6 | '/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels | ||
7 | and muxes) can be observed by reading the 'regdump' file (e.g. | ||
8 | 'plla/regdump'). | ||
9 | 4 | ||
10 | Those values are set by the Raspberry Pi firmware at boot time (Linux | 5 | Reviewed-by: Doug Evans<dje@google.com> |
11 | expects them to be set when it boots up). | 6 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> |
12 | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | |
13 | Some stages are not exposed by the Linux driver (e.g. the PLL B). For | 8 | Message-id: 20210210220426.3577804-4-wuhaotsh@google.com |
14 | those, the reset values are unknown and left to 0 which implies a | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | disabled output. | ||
16 | |||
17 | Once booted in QEMU, the final clock tree is very similar to the one | ||
18 | visible on real hardware. The differences come from some unimplemented | ||
19 | devices for which the driver simply disable the corresponding clock. | ||
20 | |||
21 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
22 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
23 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
26 | --- | 11 | --- |
27 | include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ | 12 | hw/arm/npcm7xx_boards.c | 27 +++++++++++++++++++++++++++ |
28 | hw/misc/bcm2835_cprman.c | 31 +++ | 13 | hw/arm/Kconfig | 1 + |
29 | 2 files changed, 300 insertions(+) | 14 | 2 files changed, 28 insertions(+) |
30 | 15 | ||
31 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | 16 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
32 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 18 | --- a/hw/arm/npcm7xx_boards.c |
34 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 19 | +++ b/hw/arm/npcm7xx_boards.c |
35 | @@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, | 20 | @@ -XXX,XX +XXX,XX @@ |
36 | mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | 21 | #include "exec/address-spaces.h" |
22 | #include "hw/arm/npcm7xx.h" | ||
23 | #include "hw/core/cpu.h" | ||
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")); | ||
37 | } | 30 | } |
38 | 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); | ||
39 | + | 38 | + |
40 | +/* | 39 | + qdev_prop_set_uint32(dev, "rom-size", rsize); |
41 | + * Object reset info | 40 | + i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort); |
42 | + * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the | ||
43 | + * clk debugfs interface in Linux. | ||
44 | + */ | ||
45 | +typedef struct PLLResetInfo { | ||
46 | + uint32_t cm; | ||
47 | + uint32_t a2w_ctrl; | ||
48 | + uint32_t a2w_ana[4]; | ||
49 | + uint32_t a2w_frac; | ||
50 | +} PLLResetInfo; | ||
51 | + | ||
52 | +static const PLLResetInfo PLL_RESET_INFO[] = { | ||
53 | + [CPRMAN_PLLA] = { | ||
54 | + .cm = 0x0000008a, | ||
55 | + .a2w_ctrl = 0x0002103a, | ||
56 | + .a2w_frac = 0x00098000, | ||
57 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
58 | + }, | ||
59 | + | ||
60 | + [CPRMAN_PLLC] = { | ||
61 | + .cm = 0x00000228, | ||
62 | + .a2w_ctrl = 0x0002103e, | ||
63 | + .a2w_frac = 0x00080000, | ||
64 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
65 | + }, | ||
66 | + | ||
67 | + [CPRMAN_PLLD] = { | ||
68 | + .cm = 0x0000020a, | ||
69 | + .a2w_ctrl = 0x00021034, | ||
70 | + .a2w_frac = 0x00015556, | ||
71 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
72 | + }, | ||
73 | + | ||
74 | + [CPRMAN_PLLH] = { | ||
75 | + .cm = 0x00000000, | ||
76 | + .a2w_ctrl = 0x0002102d, | ||
77 | + .a2w_frac = 0x00000000, | ||
78 | + .a2w_ana = { 0x00900000, 0x0000000c, 0x00000000, 0x00000000 } | ||
79 | + }, | ||
80 | + | ||
81 | + [CPRMAN_PLLB] = { | ||
82 | + /* unknown */ | ||
83 | + .cm = 0x00000000, | ||
84 | + .a2w_ctrl = 0x00000000, | ||
85 | + .a2w_frac = 0x00000000, | ||
86 | + .a2w_ana = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 } | ||
87 | + } | ||
88 | +}; | ||
89 | + | ||
90 | +typedef struct PLLChannelResetInfo { | ||
91 | + /* | ||
92 | + * Even though a PLL channel has a CM register, it shares it with its | ||
93 | + * parent PLL. The parent already takes care of the reset value. | ||
94 | + */ | ||
95 | + uint32_t a2w_ctrl; | ||
96 | +} PLLChannelResetInfo; | ||
97 | + | ||
98 | +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO[] = { | ||
99 | + [CPRMAN_PLLA_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
100 | + [CPRMAN_PLLA_CHANNEL_CORE] = { .a2w_ctrl = 0x00000003 }, | ||
101 | + [CPRMAN_PLLA_CHANNEL_PER] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
102 | + [CPRMAN_PLLA_CHANNEL_CCP2] = { .a2w_ctrl = 0x00000100 }, | ||
103 | + | ||
104 | + [CPRMAN_PLLC_CHANNEL_CORE2] = { .a2w_ctrl = 0x00000100 }, | ||
105 | + [CPRMAN_PLLC_CHANNEL_CORE1] = { .a2w_ctrl = 0x00000100 }, | ||
106 | + [CPRMAN_PLLC_CHANNEL_PER] = { .a2w_ctrl = 0x00000002 }, | ||
107 | + [CPRMAN_PLLC_CHANNEL_CORE0] = { .a2w_ctrl = 0x00000002 }, | ||
108 | + | ||
109 | + [CPRMAN_PLLD_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
110 | + [CPRMAN_PLLD_CHANNEL_CORE] = { .a2w_ctrl = 0x00000004 }, | ||
111 | + [CPRMAN_PLLD_CHANNEL_PER] = { .a2w_ctrl = 0x00000004 }, | ||
112 | + [CPRMAN_PLLD_CHANNEL_DSI1] = { .a2w_ctrl = 0x00000100 }, | ||
113 | + | ||
114 | + [CPRMAN_PLLH_CHANNEL_AUX] = { .a2w_ctrl = 0x00000004 }, | ||
115 | + [CPRMAN_PLLH_CHANNEL_RCAL] = { .a2w_ctrl = 0x00000000 }, | ||
116 | + [CPRMAN_PLLH_CHANNEL_PIX] = { .a2w_ctrl = 0x00000000 }, | ||
117 | + | ||
118 | + [CPRMAN_PLLB_CHANNEL_ARM] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
119 | +}; | ||
120 | + | ||
121 | +typedef struct ClockMuxResetInfo { | ||
122 | + uint32_t cm_ctl; | ||
123 | + uint32_t cm_div; | ||
124 | +} ClockMuxResetInfo; | ||
125 | + | ||
126 | +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO[] = { | ||
127 | + [CPRMAN_CLOCK_GNRIC] = { | ||
128 | + .cm_ctl = 0, /* unknown */ | ||
129 | + .cm_div = 0 | ||
130 | + }, | ||
131 | + | ||
132 | + [CPRMAN_CLOCK_VPU] = { | ||
133 | + .cm_ctl = 0x00000245, | ||
134 | + .cm_div = 0x00003000, | ||
135 | + }, | ||
136 | + | ||
137 | + [CPRMAN_CLOCK_SYS] = { | ||
138 | + .cm_ctl = 0, /* unknown */ | ||
139 | + .cm_div = 0 | ||
140 | + }, | ||
141 | + | ||
142 | + [CPRMAN_CLOCK_PERIA] = { | ||
143 | + .cm_ctl = 0, /* unknown */ | ||
144 | + .cm_div = 0 | ||
145 | + }, | ||
146 | + | ||
147 | + [CPRMAN_CLOCK_PERII] = { | ||
148 | + .cm_ctl = 0, /* unknown */ | ||
149 | + .cm_div = 0 | ||
150 | + }, | ||
151 | + | ||
152 | + [CPRMAN_CLOCK_H264] = { | ||
153 | + .cm_ctl = 0x00000244, | ||
154 | + .cm_div = 0x00003000, | ||
155 | + }, | ||
156 | + | ||
157 | + [CPRMAN_CLOCK_ISP] = { | ||
158 | + .cm_ctl = 0x00000244, | ||
159 | + .cm_div = 0x00003000, | ||
160 | + }, | ||
161 | + | ||
162 | + [CPRMAN_CLOCK_V3D] = { | ||
163 | + .cm_ctl = 0, /* unknown */ | ||
164 | + .cm_div = 0 | ||
165 | + }, | ||
166 | + | ||
167 | + [CPRMAN_CLOCK_CAM0] = { | ||
168 | + .cm_ctl = 0x00000000, | ||
169 | + .cm_div = 0x00000000, | ||
170 | + }, | ||
171 | + | ||
172 | + [CPRMAN_CLOCK_CAM1] = { | ||
173 | + .cm_ctl = 0x00000000, | ||
174 | + .cm_div = 0x00000000, | ||
175 | + }, | ||
176 | + | ||
177 | + [CPRMAN_CLOCK_CCP2] = { | ||
178 | + .cm_ctl = 0, /* unknown */ | ||
179 | + .cm_div = 0 | ||
180 | + }, | ||
181 | + | ||
182 | + [CPRMAN_CLOCK_DSI0E] = { | ||
183 | + .cm_ctl = 0x00000000, | ||
184 | + .cm_div = 0x00000000, | ||
185 | + }, | ||
186 | + | ||
187 | + [CPRMAN_CLOCK_DSI0P] = { | ||
188 | + .cm_ctl = 0x00000000, | ||
189 | + .cm_div = 0x00000000, | ||
190 | + }, | ||
191 | + | ||
192 | + [CPRMAN_CLOCK_DPI] = { | ||
193 | + .cm_ctl = 0x00000000, | ||
194 | + .cm_div = 0x00000000, | ||
195 | + }, | ||
196 | + | ||
197 | + [CPRMAN_CLOCK_GP0] = { | ||
198 | + .cm_ctl = 0x00000200, | ||
199 | + .cm_div = 0x00000000, | ||
200 | + }, | ||
201 | + | ||
202 | + [CPRMAN_CLOCK_GP1] = { | ||
203 | + .cm_ctl = 0x00000096, | ||
204 | + .cm_div = 0x00014000, | ||
205 | + }, | ||
206 | + | ||
207 | + [CPRMAN_CLOCK_GP2] = { | ||
208 | + .cm_ctl = 0x00000291, | ||
209 | + .cm_div = 0x00249f00, | ||
210 | + }, | ||
211 | + | ||
212 | + [CPRMAN_CLOCK_HSM] = { | ||
213 | + .cm_ctl = 0x00000000, | ||
214 | + .cm_div = 0x00000000, | ||
215 | + }, | ||
216 | + | ||
217 | + [CPRMAN_CLOCK_OTP] = { | ||
218 | + .cm_ctl = 0x00000091, | ||
219 | + .cm_div = 0x00004000, | ||
220 | + }, | ||
221 | + | ||
222 | + [CPRMAN_CLOCK_PCM] = { | ||
223 | + .cm_ctl = 0x00000200, | ||
224 | + .cm_div = 0x00000000, | ||
225 | + }, | ||
226 | + | ||
227 | + [CPRMAN_CLOCK_PWM] = { | ||
228 | + .cm_ctl = 0x00000200, | ||
229 | + .cm_div = 0x00000000, | ||
230 | + }, | ||
231 | + | ||
232 | + [CPRMAN_CLOCK_SLIM] = { | ||
233 | + .cm_ctl = 0x00000200, | ||
234 | + .cm_div = 0x00000000, | ||
235 | + }, | ||
236 | + | ||
237 | + [CPRMAN_CLOCK_SMI] = { | ||
238 | + .cm_ctl = 0x00000000, | ||
239 | + .cm_div = 0x00000000, | ||
240 | + }, | ||
241 | + | ||
242 | + [CPRMAN_CLOCK_TEC] = { | ||
243 | + .cm_ctl = 0x00000000, | ||
244 | + .cm_div = 0x00000000, | ||
245 | + }, | ||
246 | + | ||
247 | + [CPRMAN_CLOCK_TD0] = { | ||
248 | + .cm_ctl = 0, /* unknown */ | ||
249 | + .cm_div = 0 | ||
250 | + }, | ||
251 | + | ||
252 | + [CPRMAN_CLOCK_TD1] = { | ||
253 | + .cm_ctl = 0, /* unknown */ | ||
254 | + .cm_div = 0 | ||
255 | + }, | ||
256 | + | ||
257 | + [CPRMAN_CLOCK_TSENS] = { | ||
258 | + .cm_ctl = 0x00000091, | ||
259 | + .cm_div = 0x0000a000, | ||
260 | + }, | ||
261 | + | ||
262 | + [CPRMAN_CLOCK_TIMER] = { | ||
263 | + .cm_ctl = 0x00000291, | ||
264 | + .cm_div = 0x00013333, | ||
265 | + }, | ||
266 | + | ||
267 | + [CPRMAN_CLOCK_UART] = { | ||
268 | + .cm_ctl = 0x00000296, | ||
269 | + .cm_div = 0x0000a6ab, | ||
270 | + }, | ||
271 | + | ||
272 | + [CPRMAN_CLOCK_VEC] = { | ||
273 | + .cm_ctl = 0x00000097, | ||
274 | + .cm_div = 0x00002000, | ||
275 | + }, | ||
276 | + | ||
277 | + [CPRMAN_CLOCK_PULSE] = { | ||
278 | + .cm_ctl = 0, /* unknown */ | ||
279 | + .cm_div = 0 | ||
280 | + }, | ||
281 | + | ||
282 | + [CPRMAN_CLOCK_SDC] = { | ||
283 | + .cm_ctl = 0x00004006, | ||
284 | + .cm_div = 0x00003000, | ||
285 | + }, | ||
286 | + | ||
287 | + [CPRMAN_CLOCK_ARM] = { | ||
288 | + .cm_ctl = 0, /* unknown */ | ||
289 | + .cm_div = 0 | ||
290 | + }, | ||
291 | + | ||
292 | + [CPRMAN_CLOCK_AVEO] = { | ||
293 | + .cm_ctl = 0x00000000, | ||
294 | + .cm_div = 0x00000000, | ||
295 | + }, | ||
296 | + | ||
297 | + [CPRMAN_CLOCK_EMMC] = { | ||
298 | + .cm_ctl = 0x00000295, | ||
299 | + .cm_div = 0x00006000, | ||
300 | + }, | ||
301 | + | ||
302 | + [CPRMAN_CLOCK_EMMC2] = { | ||
303 | + .cm_ctl = 0, /* unknown */ | ||
304 | + .cm_div = 0 | ||
305 | + }, | ||
306 | +}; | ||
307 | + | ||
308 | #endif | ||
309 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
310 | index XXXXXXX..XXXXXXX 100644 | ||
311 | --- a/hw/misc/bcm2835_cprman.c | ||
312 | +++ b/hw/misc/bcm2835_cprman.c | ||
313 | @@ -XXX,XX +XXX,XX @@ | ||
314 | |||
315 | /* PLL */ | ||
316 | |||
317 | +static void pll_reset(DeviceState *dev) | ||
318 | +{ | ||
319 | + CprmanPllState *s = CPRMAN_PLL(dev); | ||
320 | + const PLLResetInfo *info = &PLL_RESET_INFO[s->id]; | ||
321 | + | ||
322 | + *s->reg_cm = info->cm; | ||
323 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
324 | + memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana)); | ||
325 | + *s->reg_a2w_frac = info->a2w_frac; | ||
326 | +} | 41 | +} |
327 | + | 42 | + |
328 | static bool pll_is_locked(const CprmanPllState *pll) | 43 | static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
329 | { | 44 | { |
330 | return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) | 45 | /* lm75 temperature sensor on SVB, tmp105 is compatible */ |
331 | @@ -XXX,XX +XXX,XX @@ static void pll_class_init(ObjectClass *klass, void *data) | 46 | @@ -XXX,XX +XXX,XX @@ static void npcm750_evb_i2c_init(NPCM7xxState *soc) |
332 | { | 47 | i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48); |
333 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
334 | |||
335 | + dc->reset = pll_reset; | ||
336 | dc->vmsd = &pll_vmstate; | ||
337 | } | 48 | } |
338 | 49 | ||
339 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | 50 | +static void quanta_gsj_i2c_init(NPCM7xxState *soc) |
340 | |||
341 | /* PLL channel */ | ||
342 | |||
343 | +static void pll_channel_reset(DeviceState *dev) | ||
344 | +{ | 51 | +{ |
345 | + CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev); | 52 | + /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */ |
346 | + const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id]; | 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); | ||
347 | + | 57 | + |
348 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | 58 | + at24c_eeprom_init(soc, 9, 0x55, 8192); |
59 | + at24c_eeprom_init(soc, 10, 0x55, 8192); | ||
60 | + | ||
61 | + /* TODO: Add additional i2c devices. */ | ||
349 | +} | 62 | +} |
350 | + | 63 | + |
351 | static bool pll_channel_is_enabled(CprmanPllChannelState *channel) | 64 | static void npcm750_evb_init(MachineState *machine) |
352 | { | 65 | { |
353 | /* | 66 | NPCM7xxState *soc; |
354 | @@ -XXX,XX +XXX,XX @@ static void pll_channel_class_init(ObjectClass *klass, void *data) | 67 | @@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine) |
355 | { | 68 | npcm7xx_load_bootrom(machine, soc); |
356 | DeviceClass *dc = DEVICE_CLASS(klass); | 69 | npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e", |
357 | 70 | drive_get(IF_MTD, 0, 0)); | |
358 | + dc->reset = pll_channel_reset; | 71 | + quanta_gsj_i2c_init(soc); |
359 | dc->vmsd = &pll_channel_vmstate; | 72 | npcm7xx_load_kernel(machine, soc); |
360 | } | 73 | } |
361 | 74 | ||
362 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_src_update(void *opaque) | 75 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
363 | clock_mux_update(s); | 76 | index XXXXXXX..XXXXXXX 100644 |
364 | } | 77 | --- a/hw/arm/Kconfig |
365 | 78 | +++ b/hw/arm/Kconfig | |
366 | +static void clock_mux_reset(DeviceState *dev) | 79 | @@ -XXX,XX +XXX,XX @@ config NPCM7XX |
367 | +{ | 80 | bool |
368 | + CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev); | 81 | select A9MPCORE |
369 | + const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id]; | 82 | select ARM_GIC |
370 | + | 83 | + select AT24C # EEPROM |
371 | + *clock->reg_ctl = info->cm_ctl; | 84 | select PL310 # cache controller |
372 | + *clock->reg_div = info->cm_div; | 85 | select SERIAL |
373 | +} | 86 | select SSI |
374 | + | ||
375 | static void clock_mux_init(Object *obj) | ||
376 | { | ||
377 | CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); | ||
378 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_class_init(ObjectClass *klass, void *data) | ||
379 | { | ||
380 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
381 | |||
382 | + dc->reset = clock_mux_reset; | ||
383 | dc->vmsd = &clock_mux_vmstate; | ||
384 | } | ||
385 | |||
386 | -- | 87 | -- |
387 | 2.20.1 | 88 | 2.20.1 |
388 | 89 | ||
389 | 90 | diff view generated by jsdifflib |
1 | From: Havard Skinnemoen <hskinnemoen@google.com> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The NPCM7xx chips have multiple GPIO controllers that are mostly | 3 | This patch adds a QTest for NPCM7XX SMBus's single byte mode. It sends a |
4 | identical except for some minor differences like the reset values of | 4 | byte to a device in the evaluation board, and verify the retrieved value |
5 | some registers. Each controller controls up to 32 pins. | 5 | is equivalent to the sent value. |
6 | 6 | ||
7 | Each individual pin is modeled as a pair of unnamed GPIOs -- one for | 7 | Reviewed-by: Doug Evans<dje@google.com> |
8 | emitting the actual pin state, and one for driving the pin externally. | 8 | Reviewed-by: Tyrong Ting<kfting@nuvoton.com> |
9 | Like the nRF51 GPIO controller, a gpio level may be negative, which | 9 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
10 | means the pin is not driven, or floating. | ||
11 | |||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
13 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Message-id: 20210210220426.3577804-5-wuhaotsh@google.com | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 13 | --- |
17 | docs/system/arm/nuvoton.rst | 2 +- | 14 | tests/qtest/npcm7xx_smbus-test.c | 352 +++++++++++++++++++++++++++++++ |
18 | include/hw/arm/npcm7xx.h | 2 + | 15 | tests/qtest/meson.build | 1 + |
19 | include/hw/gpio/npcm7xx_gpio.h | 55 +++++ | 16 | 2 files changed, 353 insertions(+) |
20 | hw/arm/npcm7xx.c | 80 ++++++ | 17 | create mode 100644 tests/qtest/npcm7xx_smbus-test.c |
21 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++ | 18 | |
22 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++ | 19 | diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c |
23 | hw/gpio/meson.build | 1 + | ||
24 | hw/gpio/trace-events | 7 + | ||
25 | tests/qtest/meson.build | 3 +- | ||
26 | 9 files changed, 957 insertions(+), 2 deletions(-) | ||
27 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
28 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
29 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
30 | |||
31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/docs/system/arm/nuvoton.rst | ||
34 | +++ b/docs/system/arm/nuvoton.rst | ||
35 | @@ -XXX,XX +XXX,XX @@ Supported devices | ||
36 | * Flash Interface Unit (FIU; no protection features) | ||
37 | * Random Number Generator (RNG) | ||
38 | * USB host (USBH) | ||
39 | + * GPIO controller | ||
40 | |||
41 | Missing devices | ||
42 | --------------- | ||
43 | |||
44 | - * GPIO controller | ||
45 | * LPC/eSPI host-to-BMC interface, including | ||
46 | |||
47 | * Keyboard and mouse controller interface (KBCI) | ||
48 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/include/hw/arm/npcm7xx.h | ||
51 | +++ b/include/hw/arm/npcm7xx.h | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | |||
54 | #include "hw/boards.h" | ||
55 | #include "hw/cpu/a9mpcore.h" | ||
56 | +#include "hw/gpio/npcm7xx_gpio.h" | ||
57 | #include "hw/mem/npcm7xx_mc.h" | ||
58 | #include "hw/misc/npcm7xx_clk.h" | ||
59 | #include "hw/misc/npcm7xx_gcr.h" | ||
60 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | ||
61 | NPCM7xxOTPState fuse_array; | ||
62 | NPCM7xxMCState mc; | ||
63 | NPCM7xxRNGState rng; | ||
64 | + NPCM7xxGPIOState gpio[8]; | ||
65 | EHCISysBusState ehci; | ||
66 | OHCISysBusState ohci; | ||
67 | NPCM7xxFIUState fiu[2]; | ||
68 | diff --git a/include/hw/gpio/npcm7xx_gpio.h b/include/hw/gpio/npcm7xx_gpio.h | ||
69 | new file mode 100644 | 20 | new file mode 100644 |
70 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
71 | --- /dev/null | 22 | --- /dev/null |
72 | +++ b/include/hw/gpio/npcm7xx_gpio.h | 23 | +++ b/tests/qtest/npcm7xx_smbus-test.c |
73 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
74 | +/* | 25 | +/* |
75 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | 26 | + * QTests for Nuvoton NPCM7xx SMBus Modules. |
76 | + * | ||
77 | + * Copyright 2020 Google LLC | ||
78 | + * | ||
79 | + * This program is free software; you can redistribute it and/or | ||
80 | + * modify it under the terms of the GNU General Public License | ||
81 | + * version 2 as published by the Free Software Foundation. | ||
82 | + * | ||
83 | + * This program is distributed in the hope that it will be useful, | ||
84 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
85 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
86 | + * GNU General Public License for more details. | ||
87 | + */ | ||
88 | +#ifndef NPCM7XX_GPIO_H | ||
89 | +#define NPCM7XX_GPIO_H | ||
90 | + | ||
91 | +#include "exec/memory.h" | ||
92 | +#include "hw/sysbus.h" | ||
93 | + | ||
94 | +/* Number of pins managed by each controller. */ | ||
95 | +#define NPCM7XX_GPIO_NR_PINS (32) | ||
96 | + | ||
97 | +/* | ||
98 | + * Number of registers in our device state structure. Don't change this without | ||
99 | + * incrementing the version_id in the vmstate. | ||
100 | + */ | ||
101 | +#define NPCM7XX_GPIO_NR_REGS (0x80 / sizeof(uint32_t)) | ||
102 | + | ||
103 | +typedef struct NPCM7xxGPIOState { | ||
104 | + SysBusDevice parent; | ||
105 | + | ||
106 | + /* Properties to be defined by the SoC */ | ||
107 | + uint32_t reset_pu; | ||
108 | + uint32_t reset_pd; | ||
109 | + uint32_t reset_osrc; | ||
110 | + uint32_t reset_odsc; | ||
111 | + | ||
112 | + MemoryRegion mmio; | ||
113 | + | ||
114 | + qemu_irq irq; | ||
115 | + qemu_irq output[NPCM7XX_GPIO_NR_PINS]; | ||
116 | + | ||
117 | + uint32_t pin_level; | ||
118 | + uint32_t ext_level; | ||
119 | + uint32_t ext_driven; | ||
120 | + | ||
121 | + uint32_t regs[NPCM7XX_GPIO_NR_REGS]; | ||
122 | +} NPCM7xxGPIOState; | ||
123 | + | ||
124 | +#define TYPE_NPCM7XX_GPIO "npcm7xx-gpio" | ||
125 | +#define NPCM7XX_GPIO(obj) \ | ||
126 | + OBJECT_CHECK(NPCM7xxGPIOState, (obj), TYPE_NPCM7XX_GPIO) | ||
127 | + | ||
128 | +#endif /* NPCM7XX_GPIO_H */ | ||
129 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/hw/arm/npcm7xx.c | ||
132 | +++ b/hw/arm/npcm7xx.c | ||
133 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
134 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
135 | NPCM7XX_EHCI_IRQ = 61, | ||
136 | NPCM7XX_OHCI_IRQ = 62, | ||
137 | + NPCM7XX_GPIO0_IRQ = 116, | ||
138 | + NPCM7XX_GPIO1_IRQ, | ||
139 | + NPCM7XX_GPIO2_IRQ, | ||
140 | + NPCM7XX_GPIO3_IRQ, | ||
141 | + NPCM7XX_GPIO4_IRQ, | ||
142 | + NPCM7XX_GPIO5_IRQ, | ||
143 | + NPCM7XX_GPIO6_IRQ, | ||
144 | + NPCM7XX_GPIO7_IRQ, | ||
145 | }; | ||
146 | |||
147 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
148 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = { | ||
149 | 0xb8000000, /* CS3 */ | ||
150 | }; | ||
151 | |||
152 | +static const struct { | ||
153 | + hwaddr regs_addr; | ||
154 | + uint32_t unconnected_pins; | ||
155 | + uint32_t reset_pu; | ||
156 | + uint32_t reset_pd; | ||
157 | + uint32_t reset_osrc; | ||
158 | + uint32_t reset_odsc; | ||
159 | +} npcm7xx_gpio[] = { | ||
160 | + { | ||
161 | + .regs_addr = 0xf0010000, | ||
162 | + .reset_pu = 0xff03ffff, | ||
163 | + .reset_pd = 0x00fc0000, | ||
164 | + }, { | ||
165 | + .regs_addr = 0xf0011000, | ||
166 | + .unconnected_pins = 0x0000001e, | ||
167 | + .reset_pu = 0xfefffe07, | ||
168 | + .reset_pd = 0x010001e0, | ||
169 | + }, { | ||
170 | + .regs_addr = 0xf0012000, | ||
171 | + .reset_pu = 0x780fffff, | ||
172 | + .reset_pd = 0x07f00000, | ||
173 | + .reset_odsc = 0x00700000, | ||
174 | + }, { | ||
175 | + .regs_addr = 0xf0013000, | ||
176 | + .reset_pu = 0x00fc0000, | ||
177 | + .reset_pd = 0xff000000, | ||
178 | + }, { | ||
179 | + .regs_addr = 0xf0014000, | ||
180 | + .reset_pu = 0xffffffff, | ||
181 | + }, { | ||
182 | + .regs_addr = 0xf0015000, | ||
183 | + .reset_pu = 0xbf83f801, | ||
184 | + .reset_pd = 0x007c0000, | ||
185 | + .reset_osrc = 0x000000f1, | ||
186 | + .reset_odsc = 0x3f9f80f1, | ||
187 | + }, { | ||
188 | + .regs_addr = 0xf0016000, | ||
189 | + .reset_pu = 0xfc00f801, | ||
190 | + .reset_pd = 0x000007fe, | ||
191 | + .reset_odsc = 0x00000800, | ||
192 | + }, { | ||
193 | + .regs_addr = 0xf0017000, | ||
194 | + .unconnected_pins = 0xffffff00, | ||
195 | + .reset_pu = 0x0000007f, | ||
196 | + .reset_osrc = 0x0000007f, | ||
197 | + .reset_odsc = 0x0000007f, | ||
198 | + }, | ||
199 | +}; | ||
200 | + | ||
201 | static const struct { | ||
202 | const char *name; | ||
203 | hwaddr regs_addr; | ||
204 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
205 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
206 | } | ||
207 | |||
208 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { | ||
209 | + object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); | ||
210 | + } | ||
211 | + | ||
212 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
213 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
214 | |||
215 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
216 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
217 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
218 | |||
219 | + /* GPIO modules. Cannot fail. */ | ||
220 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_gpio) != ARRAY_SIZE(s->gpio)); | ||
221 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { | ||
222 | + Object *obj = OBJECT(&s->gpio[i]); | ||
223 | + | ||
224 | + object_property_set_uint(obj, "reset-pullup", | ||
225 | + npcm7xx_gpio[i].reset_pu, &error_abort); | ||
226 | + object_property_set_uint(obj, "reset-pulldown", | ||
227 | + npcm7xx_gpio[i].reset_pd, &error_abort); | ||
228 | + object_property_set_uint(obj, "reset-osrc", | ||
229 | + npcm7xx_gpio[i].reset_osrc, &error_abort); | ||
230 | + object_property_set_uint(obj, "reset-odsc", | ||
231 | + npcm7xx_gpio[i].reset_odsc, &error_abort); | ||
232 | + sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort); | ||
233 | + sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_gpio[i].regs_addr); | ||
234 | + sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, | ||
235 | + npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i)); | ||
236 | + } | ||
237 | + | ||
238 | /* USB Host */ | ||
239 | object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
240 | &error_abort); | ||
241 | diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c | ||
242 | new file mode 100644 | ||
243 | index XXXXXXX..XXXXXXX | ||
244 | --- /dev/null | ||
245 | +++ b/hw/gpio/npcm7xx_gpio.c | ||
246 | @@ -XXX,XX +XXX,XX @@ | ||
247 | +/* | ||
248 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | ||
249 | + * | ||
250 | + * Copyright 2020 Google LLC | ||
251 | + * | ||
252 | + * This program is free software; you can redistribute it and/or | ||
253 | + * modify it under the terms of the GNU General Public License | ||
254 | + * version 2 as published by the Free Software Foundation. | ||
255 | + * | ||
256 | + * This program is distributed in the hope that it will be useful, | ||
257 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
258 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
259 | + * GNU General Public License for more details. | ||
260 | + */ | ||
261 | + | ||
262 | +#include "qemu/osdep.h" | ||
263 | + | ||
264 | +#include "hw/gpio/npcm7xx_gpio.h" | ||
265 | +#include "hw/irq.h" | ||
266 | +#include "hw/qdev-properties.h" | ||
267 | +#include "migration/vmstate.h" | ||
268 | +#include "qapi/error.h" | ||
269 | +#include "qemu/log.h" | ||
270 | +#include "qemu/module.h" | ||
271 | +#include "qemu/units.h" | ||
272 | +#include "trace.h" | ||
273 | + | ||
274 | +/* 32-bit register indices. */ | ||
275 | +enum NPCM7xxGPIORegister { | ||
276 | + NPCM7XX_GPIO_TLOCK1, | ||
277 | + NPCM7XX_GPIO_DIN, | ||
278 | + NPCM7XX_GPIO_POL, | ||
279 | + NPCM7XX_GPIO_DOUT, | ||
280 | + NPCM7XX_GPIO_OE, | ||
281 | + NPCM7XX_GPIO_OTYP, | ||
282 | + NPCM7XX_GPIO_MP, | ||
283 | + NPCM7XX_GPIO_PU, | ||
284 | + NPCM7XX_GPIO_PD, | ||
285 | + NPCM7XX_GPIO_DBNC, | ||
286 | + NPCM7XX_GPIO_EVTYP, | ||
287 | + NPCM7XX_GPIO_EVBE, | ||
288 | + NPCM7XX_GPIO_OBL0, | ||
289 | + NPCM7XX_GPIO_OBL1, | ||
290 | + NPCM7XX_GPIO_OBL2, | ||
291 | + NPCM7XX_GPIO_OBL3, | ||
292 | + NPCM7XX_GPIO_EVEN, | ||
293 | + NPCM7XX_GPIO_EVENS, | ||
294 | + NPCM7XX_GPIO_EVENC, | ||
295 | + NPCM7XX_GPIO_EVST, | ||
296 | + NPCM7XX_GPIO_SPLCK, | ||
297 | + NPCM7XX_GPIO_MPLCK, | ||
298 | + NPCM7XX_GPIO_IEM, | ||
299 | + NPCM7XX_GPIO_OSRC, | ||
300 | + NPCM7XX_GPIO_ODSC, | ||
301 | + NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t), | ||
302 | + NPCM7XX_GPIO_DOC, | ||
303 | + NPCM7XX_GPIO_OES, | ||
304 | + NPCM7XX_GPIO_OEC, | ||
305 | + NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t), | ||
306 | + NPCM7XX_GPIO_REGS_END, | ||
307 | +}; | ||
308 | + | ||
309 | +#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB) | ||
310 | + | ||
311 | +#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73) | ||
312 | +#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248) | ||
313 | + | ||
314 | +static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff) | ||
315 | +{ | ||
316 | + uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN]; | ||
317 | + | ||
318 | + /* Trigger on high level */ | ||
319 | + s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP]; | ||
320 | + /* Trigger on both edges */ | ||
321 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP] | ||
322 | + & s->regs[NPCM7XX_GPIO_EVBE]); | ||
323 | + /* Trigger on rising edge */ | ||
324 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new | ||
325 | + & s->regs[NPCM7XX_GPIO_EVTYP]); | ||
326 | + | ||
327 | + trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path, | ||
328 | + s->regs[NPCM7XX_GPIO_EVST], | ||
329 | + s->regs[NPCM7XX_GPIO_EVEN]); | ||
330 | + qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST] | ||
331 | + & s->regs[NPCM7XX_GPIO_EVEN])); | ||
332 | +} | ||
333 | + | ||
334 | +static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff) | ||
335 | +{ | ||
336 | + uint32_t drive_en; | ||
337 | + uint32_t drive_lvl; | ||
338 | + uint32_t not_driven; | ||
339 | + uint32_t undefined; | ||
340 | + uint32_t pin_diff; | ||
341 | + uint32_t din_old; | ||
342 | + | ||
343 | + /* Calculate level of each pin driven by GPIO controller. */ | ||
344 | + drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL]; | ||
345 | + /* If OTYP=1, only drive low (open drain) */ | ||
346 | + drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP] | ||
347 | + & drive_lvl); | ||
348 | + /* | ||
349 | + * If a pin is driven to opposite levels by the GPIO controller and the | ||
350 | + * external driver, the result is undefined. | ||
351 | + */ | ||
352 | + undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level); | ||
353 | + if (undefined) { | ||
354 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
355 | + "%s: pins have multiple drivers: 0x%" PRIx32 "\n", | ||
356 | + DEVICE(s)->canonical_path, undefined); | ||
357 | + } | ||
358 | + | ||
359 | + not_driven = ~(drive_en | s->ext_driven); | ||
360 | + pin_diff = s->pin_level; | ||
361 | + | ||
362 | + /* Set pins to externally driven level. */ | ||
363 | + s->pin_level = s->ext_level & s->ext_driven; | ||
364 | + /* Set internally driven pins, ignoring any conflicts. */ | ||
365 | + s->pin_level |= drive_lvl & drive_en; | ||
366 | + /* Pull up undriven pins with internal pull-up enabled. */ | ||
367 | + s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU]; | ||
368 | + /* Pins not driven, pulled up or pulled down are undefined */ | ||
369 | + undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU] | ||
370 | + | s->regs[NPCM7XX_GPIO_PD]); | ||
371 | + | ||
372 | + /* If any pins changed state, update the outgoing GPIOs. */ | ||
373 | + pin_diff ^= s->pin_level; | ||
374 | + pin_diff |= undefined & diff; | ||
375 | + if (pin_diff) { | ||
376 | + int i; | ||
377 | + | ||
378 | + for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) { | ||
379 | + uint32_t mask = BIT(i); | ||
380 | + if (pin_diff & mask) { | ||
381 | + int level = (undefined & mask) ? -1 : !!(s->pin_level & mask); | ||
382 | + trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path, | ||
383 | + i, level); | ||
384 | + qemu_set_irq(s->output[i], level); | ||
385 | + } | ||
386 | + } | ||
387 | + } | ||
388 | + | ||
389 | + /* Calculate new value of DIN after masking and polarity setting. */ | ||
390 | + din_old = s->regs[NPCM7XX_GPIO_DIN]; | ||
391 | + s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM]) | ||
392 | + ^ s->regs[NPCM7XX_GPIO_POL]); | ||
393 | + | ||
394 | + /* See if any new events triggered because of all this. */ | ||
395 | + npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]); | ||
396 | +} | ||
397 | + | ||
398 | +static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s) | ||
399 | +{ | ||
400 | + return s->regs[NPCM7XX_GPIO_TLOCK1] == 1; | ||
401 | +} | ||
402 | + | ||
403 | +static uint64_t npcm7xx_gpio_regs_read(void *opaque, hwaddr addr, | ||
404 | + unsigned int size) | ||
405 | +{ | ||
406 | + hwaddr reg = addr / sizeof(uint32_t); | ||
407 | + NPCM7xxGPIOState *s = opaque; | ||
408 | + uint64_t value = 0; | ||
409 | + | ||
410 | + switch (reg) { | ||
411 | + case NPCM7XX_GPIO_TLOCK1 ... NPCM7XX_GPIO_EVEN: | ||
412 | + case NPCM7XX_GPIO_EVST ... NPCM7XX_GPIO_ODSC: | ||
413 | + value = s->regs[reg]; | ||
414 | + break; | ||
415 | + | ||
416 | + case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC: | ||
417 | + case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2: | ||
418 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
419 | + "%s: read from write-only register 0x%" HWADDR_PRIx "\n", | ||
420 | + DEVICE(s)->canonical_path, addr); | ||
421 | + break; | ||
422 | + | ||
423 | + default: | ||
424 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
425 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
426 | + DEVICE(s)->canonical_path, addr); | ||
427 | + break; | ||
428 | + } | ||
429 | + | ||
430 | + trace_npcm7xx_gpio_read(DEVICE(s)->canonical_path, addr, value); | ||
431 | + | ||
432 | + return value; | ||
433 | +} | ||
434 | + | ||
435 | +static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v, | ||
436 | + unsigned int size) | ||
437 | +{ | ||
438 | + hwaddr reg = addr / sizeof(uint32_t); | ||
439 | + NPCM7xxGPIOState *s = opaque; | ||
440 | + uint32_t value = v; | ||
441 | + uint32_t diff; | ||
442 | + | ||
443 | + trace_npcm7xx_gpio_write(DEVICE(s)->canonical_path, addr, v); | ||
444 | + | ||
445 | + if (npcm7xx_gpio_is_locked(s)) { | ||
446 | + switch (reg) { | ||
447 | + case NPCM7XX_GPIO_TLOCK1: | ||
448 | + if (s->regs[NPCM7XX_GPIO_TLOCK2] == NPCM7XX_GPIO_LOCK_MAGIC2 && | ||
449 | + value == NPCM7XX_GPIO_LOCK_MAGIC1) { | ||
450 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 0; | ||
451 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
452 | + } | ||
453 | + break; | ||
454 | + | ||
455 | + case NPCM7XX_GPIO_TLOCK2: | ||
456 | + s->regs[reg] = value; | ||
457 | + break; | ||
458 | + | ||
459 | + default: | ||
460 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
461 | + "%s: write to locked register @ 0x%" HWADDR_PRIx "\n", | ||
462 | + DEVICE(s)->canonical_path, addr); | ||
463 | + break; | ||
464 | + } | ||
465 | + | ||
466 | + return; | ||
467 | + } | ||
468 | + | ||
469 | + diff = s->regs[reg] ^ value; | ||
470 | + | ||
471 | + switch (reg) { | ||
472 | + case NPCM7XX_GPIO_TLOCK1: | ||
473 | + case NPCM7XX_GPIO_TLOCK2: | ||
474 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 1; | ||
475 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
476 | + break; | ||
477 | + | ||
478 | + case NPCM7XX_GPIO_DIN: | ||
479 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
480 | + "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n", | ||
481 | + DEVICE(s)->canonical_path, addr); | ||
482 | + break; | ||
483 | + | ||
484 | + case NPCM7XX_GPIO_POL: | ||
485 | + case NPCM7XX_GPIO_DOUT: | ||
486 | + case NPCM7XX_GPIO_OE: | ||
487 | + case NPCM7XX_GPIO_OTYP: | ||
488 | + case NPCM7XX_GPIO_PU: | ||
489 | + case NPCM7XX_GPIO_PD: | ||
490 | + case NPCM7XX_GPIO_IEM: | ||
491 | + s->regs[reg] = value; | ||
492 | + npcm7xx_gpio_update_pins(s, diff); | ||
493 | + break; | ||
494 | + | ||
495 | + case NPCM7XX_GPIO_DOS: | ||
496 | + s->regs[NPCM7XX_GPIO_DOUT] |= value; | ||
497 | + npcm7xx_gpio_update_pins(s, value); | ||
498 | + break; | ||
499 | + case NPCM7XX_GPIO_DOC: | ||
500 | + s->regs[NPCM7XX_GPIO_DOUT] &= ~value; | ||
501 | + npcm7xx_gpio_update_pins(s, value); | ||
502 | + break; | ||
503 | + case NPCM7XX_GPIO_OES: | ||
504 | + s->regs[NPCM7XX_GPIO_OE] |= value; | ||
505 | + npcm7xx_gpio_update_pins(s, value); | ||
506 | + break; | ||
507 | + case NPCM7XX_GPIO_OEC: | ||
508 | + s->regs[NPCM7XX_GPIO_OE] &= ~value; | ||
509 | + npcm7xx_gpio_update_pins(s, value); | ||
510 | + break; | ||
511 | + | ||
512 | + case NPCM7XX_GPIO_EVTYP: | ||
513 | + case NPCM7XX_GPIO_EVBE: | ||
514 | + case NPCM7XX_GPIO_EVEN: | ||
515 | + s->regs[reg] = value; | ||
516 | + npcm7xx_gpio_update_events(s, 0); | ||
517 | + break; | ||
518 | + | ||
519 | + case NPCM7XX_GPIO_EVENS: | ||
520 | + s->regs[NPCM7XX_GPIO_EVEN] |= value; | ||
521 | + npcm7xx_gpio_update_events(s, 0); | ||
522 | + break; | ||
523 | + case NPCM7XX_GPIO_EVENC: | ||
524 | + s->regs[NPCM7XX_GPIO_EVEN] &= ~value; | ||
525 | + npcm7xx_gpio_update_events(s, 0); | ||
526 | + break; | ||
527 | + | ||
528 | + case NPCM7XX_GPIO_EVST: | ||
529 | + s->regs[reg] &= ~value; | ||
530 | + npcm7xx_gpio_update_events(s, 0); | ||
531 | + break; | ||
532 | + | ||
533 | + case NPCM7XX_GPIO_MP: | ||
534 | + case NPCM7XX_GPIO_DBNC: | ||
535 | + case NPCM7XX_GPIO_OSRC: | ||
536 | + case NPCM7XX_GPIO_ODSC: | ||
537 | + /* Nothing to do; just store the value. */ | ||
538 | + s->regs[reg] = value; | ||
539 | + break; | ||
540 | + | ||
541 | + case NPCM7XX_GPIO_OBL0: | ||
542 | + case NPCM7XX_GPIO_OBL1: | ||
543 | + case NPCM7XX_GPIO_OBL2: | ||
544 | + case NPCM7XX_GPIO_OBL3: | ||
545 | + s->regs[reg] = value; | ||
546 | + qemu_log_mask(LOG_UNIMP, "%s: Blinking is not implemented\n", | ||
547 | + __func__); | ||
548 | + break; | ||
549 | + | ||
550 | + case NPCM7XX_GPIO_SPLCK: | ||
551 | + case NPCM7XX_GPIO_MPLCK: | ||
552 | + qemu_log_mask(LOG_UNIMP, "%s: Per-pin lock is not implemented\n", | ||
553 | + __func__); | ||
554 | + break; | ||
555 | + | ||
556 | + default: | ||
557 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
558 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
559 | + DEVICE(s)->canonical_path, addr); | ||
560 | + break; | ||
561 | + } | ||
562 | +} | ||
563 | + | ||
564 | +static const MemoryRegionOps npcm7xx_gpio_regs_ops = { | ||
565 | + .read = npcm7xx_gpio_regs_read, | ||
566 | + .write = npcm7xx_gpio_regs_write, | ||
567 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
568 | + .valid = { | ||
569 | + .min_access_size = 4, | ||
570 | + .max_access_size = 4, | ||
571 | + .unaligned = false, | ||
572 | + }, | ||
573 | +}; | ||
574 | + | ||
575 | +static void npcm7xx_gpio_set_input(void *opaque, int line, int level) | ||
576 | +{ | ||
577 | + NPCM7xxGPIOState *s = opaque; | ||
578 | + | ||
579 | + trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level); | ||
580 | + | ||
581 | + g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS); | ||
582 | + | ||
583 | + s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0); | ||
584 | + s->ext_level = deposit32(s->ext_level, line, 1, level > 0); | ||
585 | + | ||
586 | + npcm7xx_gpio_update_pins(s, BIT(line)); | ||
587 | +} | ||
588 | + | ||
589 | +static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type) | ||
590 | +{ | ||
591 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
592 | + | ||
593 | + memset(s->regs, 0, sizeof(s->regs)); | ||
594 | + | ||
595 | + s->regs[NPCM7XX_GPIO_PU] = s->reset_pu; | ||
596 | + s->regs[NPCM7XX_GPIO_PD] = s->reset_pd; | ||
597 | + s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc; | ||
598 | + s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc; | ||
599 | +} | ||
600 | + | ||
601 | +static void npcm7xx_gpio_hold_reset(Object *obj) | ||
602 | +{ | ||
603 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
604 | + | ||
605 | + npcm7xx_gpio_update_pins(s, -1); | ||
606 | +} | ||
607 | + | ||
608 | +static void npcm7xx_gpio_init(Object *obj) | ||
609 | +{ | ||
610 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
611 | + DeviceState *dev = DEVICE(obj); | ||
612 | + | ||
613 | + memory_region_init_io(&s->mmio, obj, &npcm7xx_gpio_regs_ops, s, | ||
614 | + "regs", NPCM7XX_GPIO_REGS_SIZE); | ||
615 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | ||
616 | + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); | ||
617 | + | ||
618 | + qdev_init_gpio_in(dev, npcm7xx_gpio_set_input, NPCM7XX_GPIO_NR_PINS); | ||
619 | + qdev_init_gpio_out(dev, s->output, NPCM7XX_GPIO_NR_PINS); | ||
620 | +} | ||
621 | + | ||
622 | +static const VMStateDescription vmstate_npcm7xx_gpio = { | ||
623 | + .name = "npcm7xx-gpio", | ||
624 | + .version_id = 0, | ||
625 | + .minimum_version_id = 0, | ||
626 | + .fields = (VMStateField[]) { | ||
627 | + VMSTATE_UINT32(pin_level, NPCM7xxGPIOState), | ||
628 | + VMSTATE_UINT32(ext_level, NPCM7xxGPIOState), | ||
629 | + VMSTATE_UINT32(ext_driven, NPCM7xxGPIOState), | ||
630 | + VMSTATE_UINT32_ARRAY(regs, NPCM7xxGPIOState, NPCM7XX_GPIO_NR_REGS), | ||
631 | + VMSTATE_END_OF_LIST(), | ||
632 | + }, | ||
633 | +}; | ||
634 | + | ||
635 | +static Property npcm7xx_gpio_properties[] = { | ||
636 | + /* Bit n set => pin n has pullup enabled by default. */ | ||
637 | + DEFINE_PROP_UINT32("reset-pullup", NPCM7xxGPIOState, reset_pu, 0), | ||
638 | + /* Bit n set => pin n has pulldown enabled by default. */ | ||
639 | + DEFINE_PROP_UINT32("reset-pulldown", NPCM7xxGPIOState, reset_pd, 0), | ||
640 | + /* Bit n set => pin n has high slew rate by default. */ | ||
641 | + DEFINE_PROP_UINT32("reset-osrc", NPCM7xxGPIOState, reset_osrc, 0), | ||
642 | + /* Bit n set => pin n has high drive strength by default. */ | ||
643 | + DEFINE_PROP_UINT32("reset-odsc", NPCM7xxGPIOState, reset_odsc, 0), | ||
644 | + DEFINE_PROP_END_OF_LIST(), | ||
645 | +}; | ||
646 | + | ||
647 | +static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data) | ||
648 | +{ | ||
649 | + ResettableClass *reset = RESETTABLE_CLASS(klass); | ||
650 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
651 | + | ||
652 | + QEMU_BUILD_BUG_ON(NPCM7XX_GPIO_REGS_END > NPCM7XX_GPIO_NR_REGS); | ||
653 | + | ||
654 | + dc->desc = "NPCM7xx GPIO Controller"; | ||
655 | + dc->vmsd = &vmstate_npcm7xx_gpio; | ||
656 | + reset->phases.enter = npcm7xx_gpio_enter_reset; | ||
657 | + reset->phases.hold = npcm7xx_gpio_hold_reset; | ||
658 | + device_class_set_props(dc, npcm7xx_gpio_properties); | ||
659 | +} | ||
660 | + | ||
661 | +static const TypeInfo npcm7xx_gpio_types[] = { | ||
662 | + { | ||
663 | + .name = TYPE_NPCM7XX_GPIO, | ||
664 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
665 | + .instance_size = sizeof(NPCM7xxGPIOState), | ||
666 | + .class_init = npcm7xx_gpio_class_init, | ||
667 | + .instance_init = npcm7xx_gpio_init, | ||
668 | + }, | ||
669 | +}; | ||
670 | +DEFINE_TYPES(npcm7xx_gpio_types); | ||
671 | diff --git a/tests/qtest/npcm7xx_gpio-test.c b/tests/qtest/npcm7xx_gpio-test.c | ||
672 | new file mode 100644 | ||
673 | index XXXXXXX..XXXXXXX | ||
674 | --- /dev/null | ||
675 | +++ b/tests/qtest/npcm7xx_gpio-test.c | ||
676 | @@ -XXX,XX +XXX,XX @@ | ||
677 | +/* | ||
678 | + * QTest testcase for the Nuvoton NPCM7xx GPIO modules. | ||
679 | + * | 27 | + * |
680 | + * Copyright 2020 Google LLC | 28 | + * Copyright 2020 Google LLC |
681 | + * | 29 | + * |
682 | + * This program is free software; you can redistribute it and/or modify it | 30 | + * This program is free software; you can redistribute it and/or modify it |
683 | + * under the terms of the GNU General Public License as published by the | 31 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
689 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 37 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
690 | + * for more details. | 38 | + * for more details. |
691 | + */ | 39 | + */ |
692 | + | 40 | + |
693 | +#include "qemu/osdep.h" | 41 | +#include "qemu/osdep.h" |
694 | +#include "libqtest-single.h" | 42 | +#include "qemu/bitops.h" |
695 | + | 43 | +#include "libqos/i2c.h" |
696 | +#define NR_GPIO_DEVICES (8) | 44 | +#include "libqos/libqtest.h" |
697 | +#define GPIO(x) (0xf0010000 + (x) * 0x1000) | 45 | +#include "hw/misc/tmp105_regs.h" |
698 | +#define GPIO_IRQ(x) (116 + (x)) | 46 | + |
699 | + | 47 | +#define NR_SMBUS_DEVICES 16 |
700 | +/* GPIO registers */ | 48 | +#define SMBUS_ADDR(x) (0xf0080000 + 0x1000 * (x)) |
701 | +#define GP_N_TLOCK1 0x00 | 49 | +#define SMBUS_IRQ(x) (64 + (x)) |
702 | +#define GP_N_DIN 0x04 /* Data IN */ | 50 | + |
703 | +#define GP_N_POL 0x08 /* Polarity */ | 51 | +#define EVB_DEVICE_ADDR 0x48 |
704 | +#define GP_N_DOUT 0x0c /* Data OUT */ | 52 | +#define INVALID_DEVICE_ADDR 0x01 |
705 | +#define GP_N_OE 0x10 /* Output Enable */ | 53 | + |
706 | +#define GP_N_OTYP 0x14 | 54 | +const int evb_bus_list[] = {0, 1, 2, 6}; |
707 | +#define GP_N_MP 0x18 | 55 | + |
708 | +#define GP_N_PU 0x1c /* Pull-up */ | 56 | +/* Offsets */ |
709 | +#define GP_N_PD 0x20 /* Pull-down */ | 57 | +enum CommonRegister { |
710 | +#define GP_N_DBNC 0x24 /* Debounce */ | 58 | + OFFSET_SDA = 0x0, |
711 | +#define GP_N_EVTYP 0x28 /* Event Type */ | 59 | + OFFSET_ST = 0x2, |
712 | +#define GP_N_EVBE 0x2c /* Event Both Edge */ | 60 | + OFFSET_CST = 0x4, |
713 | +#define GP_N_OBL0 0x30 | 61 | + OFFSET_CTL1 = 0x6, |
714 | +#define GP_N_OBL1 0x34 | 62 | + OFFSET_ADDR1 = 0x8, |
715 | +#define GP_N_OBL2 0x38 | 63 | + OFFSET_CTL2 = 0xa, |
716 | +#define GP_N_OBL3 0x3c | 64 | + OFFSET_ADDR2 = 0xc, |
717 | +#define GP_N_EVEN 0x40 /* Event Enable */ | 65 | + OFFSET_CTL3 = 0xe, |
718 | +#define GP_N_EVENS 0x44 /* Event Set (enable) */ | 66 | + OFFSET_CST2 = 0x18, |
719 | +#define GP_N_EVENC 0x48 /* Event Clear (disable) */ | 67 | + OFFSET_CST3 = 0x19, |
720 | +#define GP_N_EVST 0x4c /* Event Status */ | 68 | +}; |
721 | +#define GP_N_SPLCK 0x50 | 69 | + |
722 | +#define GP_N_MPLCK 0x54 | 70 | +enum NPCM7xxSMBusBank0Register { |
723 | +#define GP_N_IEM 0x58 /* Input Enable */ | 71 | + OFFSET_ADDR3 = 0x10, |
724 | +#define GP_N_OSRC 0x5c | 72 | + OFFSET_ADDR7 = 0x11, |
725 | +#define GP_N_ODSC 0x60 | 73 | + OFFSET_ADDR4 = 0x12, |
726 | +#define GP_N_DOS 0x68 /* Data OUT Set */ | 74 | + OFFSET_ADDR8 = 0x13, |
727 | +#define GP_N_DOC 0x6c /* Data OUT Clear */ | 75 | + OFFSET_ADDR5 = 0x14, |
728 | +#define GP_N_OES 0x70 /* Output Enable Set */ | 76 | + OFFSET_ADDR9 = 0x15, |
729 | +#define GP_N_OEC 0x74 /* Output Enable Clear */ | 77 | + OFFSET_ADDR6 = 0x16, |
730 | +#define GP_N_TLOCK2 0x7c | 78 | + OFFSET_ADDR10 = 0x17, |
731 | + | 79 | + OFFSET_CTL4 = 0x1a, |
732 | +static void gpio_unlock(int n) | 80 | + OFFSET_CTL5 = 0x1b, |
733 | +{ | 81 | + OFFSET_SCLLT = 0x1c, |
734 | + if (readl(GPIO(n) + GP_N_TLOCK1) != 0) { | 82 | + OFFSET_FIF_CTL = 0x1d, |
735 | + writel(GPIO(n) + GP_N_TLOCK2, 0xc0de1248); | 83 | + OFFSET_SCLHT = 0x1e, |
736 | + writel(GPIO(n) + GP_N_TLOCK1, 0xc0defa73); | 84 | +}; |
85 | + | ||
86 | +enum NPCM7xxSMBusBank1Register { | ||
87 | + OFFSET_FIF_CTS = 0x10, | ||
88 | + OFFSET_FAIR_PER = 0x11, | ||
89 | + OFFSET_TXF_CTL = 0x12, | ||
90 | + OFFSET_T_OUT = 0x14, | ||
91 | + OFFSET_TXF_STS = 0x1a, | ||
92 | + OFFSET_RXF_STS = 0x1c, | ||
93 | + OFFSET_RXF_CTL = 0x1e, | ||
94 | +}; | ||
95 | + | ||
96 | +/* ST fields */ | ||
97 | +#define ST_STP BIT(7) | ||
98 | +#define ST_SDAST BIT(6) | ||
99 | +#define ST_BER BIT(5) | ||
100 | +#define ST_NEGACK BIT(4) | ||
101 | +#define ST_STASTR BIT(3) | ||
102 | +#define ST_NMATCH BIT(2) | ||
103 | +#define ST_MODE BIT(1) | ||
104 | +#define ST_XMIT BIT(0) | ||
105 | + | ||
106 | +/* CST fields */ | ||
107 | +#define CST_ARPMATCH BIT(7) | ||
108 | +#define CST_MATCHAF BIT(6) | ||
109 | +#define CST_TGSCL BIT(5) | ||
110 | +#define CST_TSDA BIT(4) | ||
111 | +#define CST_GCMATCH BIT(3) | ||
112 | +#define CST_MATCH BIT(2) | ||
113 | +#define CST_BB BIT(1) | ||
114 | +#define CST_BUSY BIT(0) | ||
115 | + | ||
116 | +/* CST2 fields */ | ||
117 | +#define CST2_INSTTS BIT(7) | ||
118 | +#define CST2_MATCH7F BIT(6) | ||
119 | +#define CST2_MATCH6F BIT(5) | ||
120 | +#define CST2_MATCH5F BIT(4) | ||
121 | +#define CST2_MATCH4F BIT(3) | ||
122 | +#define CST2_MATCH3F BIT(2) | ||
123 | +#define CST2_MATCH2F BIT(1) | ||
124 | +#define CST2_MATCH1F BIT(0) | ||
125 | + | ||
126 | +/* CST3 fields */ | ||
127 | +#define CST3_EO_BUSY BIT(7) | ||
128 | +#define CST3_MATCH10F BIT(2) | ||
129 | +#define CST3_MATCH9F BIT(1) | ||
130 | +#define CST3_MATCH8F BIT(0) | ||
131 | + | ||
132 | +/* CTL1 fields */ | ||
133 | +#define CTL1_STASTRE BIT(7) | ||
134 | +#define CTL1_NMINTE BIT(6) | ||
135 | +#define CTL1_GCMEN BIT(5) | ||
136 | +#define CTL1_ACK BIT(4) | ||
137 | +#define CTL1_EOBINTE BIT(3) | ||
138 | +#define CTL1_INTEN BIT(2) | ||
139 | +#define CTL1_STOP BIT(1) | ||
140 | +#define CTL1_START BIT(0) | ||
141 | + | ||
142 | +/* CTL2 fields */ | ||
143 | +#define CTL2_SCLFRQ(rv) extract8((rv), 1, 6) | ||
144 | +#define CTL2_ENABLE BIT(0) | ||
145 | + | ||
146 | +/* CTL3 fields */ | ||
147 | +#define CTL3_SCL_LVL BIT(7) | ||
148 | +#define CTL3_SDA_LVL BIT(6) | ||
149 | +#define CTL3_BNK_SEL BIT(5) | ||
150 | +#define CTL3_400K_MODE BIT(4) | ||
151 | +#define CTL3_IDL_START BIT(3) | ||
152 | +#define CTL3_ARPMEN BIT(2) | ||
153 | +#define CTL3_SCLFRQ(rv) extract8((rv), 0, 2) | ||
154 | + | ||
155 | +/* ADDR fields */ | ||
156 | +#define ADDR_EN BIT(7) | ||
157 | +#define ADDR_A(rv) extract8((rv), 0, 6) | ||
158 | + | ||
159 | + | ||
160 | +static void check_running(QTestState *qts, uint64_t base_addr) | ||
161 | +{ | ||
162 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY); | ||
163 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB); | ||
164 | +} | ||
165 | + | ||
166 | +static void check_stopped(QTestState *qts, uint64_t base_addr) | ||
167 | +{ | ||
168 | + uint8_t cst3; | ||
169 | + | ||
170 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0); | ||
171 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY); | ||
172 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB); | ||
173 | + | ||
174 | + cst3 = qtest_readb(qts, base_addr + OFFSET_CST3); | ||
175 | + g_assert_true(cst3 & CST3_EO_BUSY); | ||
176 | + qtest_writeb(qts, base_addr + OFFSET_CST3, cst3); | ||
177 | + cst3 = qtest_readb(qts, base_addr + OFFSET_CST3); | ||
178 | + g_assert_false(cst3 & CST3_EO_BUSY); | ||
179 | +} | ||
180 | + | ||
181 | +static void enable_bus(QTestState *qts, uint64_t base_addr) | ||
182 | +{ | ||
183 | + uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2); | ||
184 | + | ||
185 | + ctl2 |= CTL2_ENABLE; | ||
186 | + qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2); | ||
187 | + g_assert_true(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE); | ||
188 | +} | ||
189 | + | ||
190 | +static void disable_bus(QTestState *qts, uint64_t base_addr) | ||
191 | +{ | ||
192 | + uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2); | ||
193 | + | ||
194 | + ctl2 &= ~CTL2_ENABLE; | ||
195 | + qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2); | ||
196 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE); | ||
197 | +} | ||
198 | + | ||
199 | +static void start_transfer(QTestState *qts, uint64_t base_addr) | ||
200 | +{ | ||
201 | + uint8_t ctl1; | ||
202 | + | ||
203 | + ctl1 = CTL1_START | CTL1_INTEN | CTL1_STASTRE; | ||
204 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
205 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==, | ||
206 | + CTL1_INTEN | CTL1_STASTRE | CTL1_INTEN); | ||
207 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
208 | + ST_MODE | ST_XMIT | ST_SDAST); | ||
209 | + check_running(qts, base_addr); | ||
210 | +} | ||
211 | + | ||
212 | +static void stop_transfer(QTestState *qts, uint64_t base_addr) | ||
213 | +{ | ||
214 | + uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); | ||
215 | + | ||
216 | + ctl1 &= ~(CTL1_START | CTL1_ACK); | ||
217 | + ctl1 |= CTL1_STOP | CTL1_INTEN | CTL1_EOBINTE; | ||
218 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); | ||
219 | + ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); | ||
220 | + g_assert_false(ctl1 & CTL1_STOP); | ||
221 | +} | ||
222 | + | ||
223 | +static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte) | ||
224 | +{ | ||
225 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
226 | + ST_MODE | ST_XMIT | ST_SDAST); | ||
227 | + qtest_writeb(qts, base_addr + OFFSET_SDA, byte); | ||
228 | +} | ||
229 | + | ||
230 | +static uint8_t recv_byte(QTestState *qts, uint64_t base_addr) | ||
231 | +{ | ||
232 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
233 | + ST_MODE | ST_SDAST); | ||
234 | + return qtest_readb(qts, base_addr + OFFSET_SDA); | ||
235 | +} | ||
236 | + | ||
237 | +static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr, | ||
238 | + bool recv, bool valid) | ||
239 | +{ | ||
240 | + uint8_t encoded_addr = (addr << 1) | (recv ? 1 : 0); | ||
241 | + uint8_t st; | ||
242 | + | ||
243 | + qtest_writeb(qts, base_addr + OFFSET_SDA, encoded_addr); | ||
244 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
245 | + | ||
246 | + if (valid) { | ||
247 | + if (recv) { | ||
248 | + g_assert_cmphex(st, ==, ST_MODE | ST_SDAST | ST_STASTR); | ||
249 | + } else { | ||
250 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST | ST_STASTR); | ||
251 | + } | ||
252 | + | ||
253 | + qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR); | ||
254 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
255 | + if (recv) { | ||
256 | + g_assert_cmphex(st, ==, ST_MODE | ST_SDAST); | ||
257 | + } else { | ||
258 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST); | ||
259 | + } | ||
260 | + } else { | ||
261 | + if (recv) { | ||
262 | + g_assert_cmphex(st, ==, ST_MODE | ST_NEGACK); | ||
263 | + } else { | ||
264 | + g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_NEGACK); | ||
265 | + } | ||
737 | + } | 266 | + } |
738 | +} | 267 | +} |
739 | + | 268 | + |
740 | +/* Restore the GPIO controller to a sensible default state. */ | 269 | +static void send_nack(QTestState *qts, uint64_t base_addr) |
741 | +static void gpio_reset(int n) | 270 | +{ |
742 | +{ | 271 | + uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1); |
743 | + gpio_unlock(0); | 272 | + |
744 | + | 273 | + ctl1 &= ~(CTL1_START | CTL1_STOP); |
745 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | 274 | + ctl1 |= CTL1_ACK | CTL1_INTEN; |
746 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | 275 | + qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1); |
747 | + writel(GPIO(n) + GP_N_POL, 0x00000000); | 276 | +} |
748 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | 277 | + |
749 | + writel(GPIO(n) + GP_N_OE, 0x00000000); | 278 | +/* Check the SMBus's status is set correctly when disabled. */ |
750 | + writel(GPIO(n) + GP_N_OTYP, 0x00000000); | 279 | +static void test_disable_bus(gconstpointer data) |
751 | + writel(GPIO(n) + GP_N_PU, 0xffffffff); | 280 | +{ |
752 | + writel(GPIO(n) + GP_N_PD, 0x00000000); | 281 | + intptr_t index = (intptr_t)data; |
753 | + writel(GPIO(n) + GP_N_IEM, 0xffffffff); | 282 | + uint64_t base_addr = SMBUS_ADDR(index); |
754 | +} | 283 | + QTestState *qts = qtest_init("-machine npcm750-evb"); |
755 | + | 284 | + |
756 | +static void test_dout_to_din(void) | 285 | + disable_bus(qts, base_addr); |
757 | +{ | 286 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==, 0); |
758 | + gpio_reset(0); | 287 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0); |
759 | + | 288 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST3) & CST3_EO_BUSY); |
760 | + /* When output is enabled, DOUT should be reflected on DIN. */ | 289 | + g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CST), ==, 0); |
761 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 290 | + qtest_quit(qts); |
762 | + /* PU and PD shouldn't have any impact on DIN. */ | 291 | +} |
763 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | 292 | + |
764 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | 293 | +/* Check the SMBus returns a NACK for an invalid address. */ |
765 | + writel(GPIO(0) + GP_N_DOUT, 0x12345678); | 294 | +static void test_invalid_addr(gconstpointer data) |
766 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x12345678); | 295 | +{ |
767 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x12345678); | 296 | + intptr_t index = (intptr_t)data; |
768 | +} | 297 | + uint64_t base_addr = SMBUS_ADDR(index); |
769 | + | 298 | + int irq = SMBUS_IRQ(index); |
770 | +static void test_pullup_pulldown(void) | 299 | + QTestState *qts = qtest_init("-machine npcm750-evb"); |
771 | +{ | 300 | + |
772 | + gpio_reset(0); | 301 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
773 | + | 302 | + enable_bus(qts, base_addr); |
774 | + /* | 303 | + g_assert_false(qtest_get_irq(qts, irq)); |
775 | + * When output is disabled, and PD is the inverse of PU, PU should be | 304 | + start_transfer(qts, base_addr); |
776 | + * reflected on DIN. If PD is not the inverse of PU, the state of DIN is | 305 | + send_address(qts, base_addr, INVALID_DEVICE_ADDR, false, false); |
777 | + * undefined, so we don't test that. | 306 | + g_assert_true(qtest_get_irq(qts, irq)); |
778 | + */ | 307 | + stop_transfer(qts, base_addr); |
779 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | 308 | + check_running(qts, base_addr); |
780 | + /* DOUT shouldn't have any impact on DIN. */ | 309 | + qtest_writeb(qts, base_addr + OFFSET_ST, ST_NEGACK); |
781 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | 310 | + g_assert_false(qtest_readb(qts, base_addr + OFFSET_ST) & ST_NEGACK); |
782 | + writel(GPIO(0) + GP_N_PU, 0x23456789); | 311 | + check_stopped(qts, base_addr); |
783 | + writel(GPIO(0) + GP_N_PD, ~0x23456789U); | 312 | + qtest_quit(qts); |
784 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PU), ==, 0x23456789); | 313 | +} |
785 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PD), ==, ~0x23456789U); | 314 | + |
786 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x23456789); | 315 | +/* Check the SMBus can send and receive bytes to a device in single mode. */ |
787 | +} | 316 | +static void test_single_mode(gconstpointer data) |
788 | + | 317 | +{ |
789 | +static void test_output_enable(void) | 318 | + intptr_t index = (intptr_t)data; |
790 | +{ | 319 | + uint64_t base_addr = SMBUS_ADDR(index); |
791 | + gpio_reset(0); | 320 | + int irq = SMBUS_IRQ(index); |
792 | + | 321 | + uint8_t value = 0x60; |
793 | + /* | 322 | + QTestState *qts = qtest_init("-machine npcm750-evb"); |
794 | + * With all pins weakly pulled down, and DOUT all-ones, OE should be | 323 | + |
795 | + * reflected on DIN. | 324 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
796 | + */ | 325 | + enable_bus(qts, base_addr); |
797 | + writel(GPIO(0) + GP_N_DOUT, 0xffffffff); | 326 | + |
798 | + writel(GPIO(0) + GP_N_PU, 0x00000000); | 327 | + /* Sending */ |
799 | + writel(GPIO(0) + GP_N_PD, 0xffffffff); | 328 | + g_assert_false(qtest_get_irq(qts, irq)); |
800 | + writel(GPIO(0) + GP_N_OE, 0x3456789a); | 329 | + start_transfer(qts, base_addr); |
801 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3456789a); | 330 | + g_assert_true(qtest_get_irq(qts, irq)); |
802 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3456789a); | 331 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); |
803 | + | 332 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); |
804 | + writel(GPIO(0) + GP_N_OEC, 0x00030002); | 333 | + send_byte(qts, base_addr, value); |
805 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x34547898); | 334 | + stop_transfer(qts, base_addr); |
806 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x34547898); | 335 | + check_stopped(qts, base_addr); |
807 | + | 336 | + |
808 | + writel(GPIO(0) + GP_N_OES, 0x0000f001); | 337 | + /* Receiving */ |
809 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3454f899); | 338 | + start_transfer(qts, base_addr); |
810 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3454f899); | 339 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true); |
811 | +} | 340 | + send_byte(qts, base_addr, TMP105_REG_CONFIG); |
812 | + | 341 | + start_transfer(qts, base_addr); |
813 | +static void test_open_drain(void) | 342 | + send_address(qts, base_addr, EVB_DEVICE_ADDR, true, true); |
814 | +{ | 343 | + send_nack(qts, base_addr); |
815 | + gpio_reset(0); | 344 | + stop_transfer(qts, base_addr); |
816 | + | 345 | + check_running(qts, base_addr); |
817 | + /* | 346 | + g_assert_cmphex(recv_byte(qts, base_addr), ==, value); |
818 | + * Upper half of DOUT drives a 1 only if the corresponding bit in OTYP is | 347 | + check_stopped(qts, base_addr); |
819 | + * not set. If OTYP is set, DIN is determined by PU/PD. Lower half of | 348 | + qtest_quit(qts); |
820 | + * DOUT always drives a 0 regardless of OTYP; PU/PD have no effect. When | 349 | +} |
821 | + * OE is 0, output is determined by PU/PD; OTYP has no effect. | 350 | + |
822 | + */ | 351 | +static void smbus_add_test(const char *name, int index, GTestDataFunc fn) |
823 | + writel(GPIO(0) + GP_N_OTYP, 0x456789ab); | 352 | +{ |
824 | + writel(GPIO(0) + GP_N_OE, 0xf0f0f0f0); | 353 | + g_autofree char *full_name = g_strdup_printf( |
825 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | 354 | + "npcm7xx_smbus[%d]/%s", index, name); |
826 | + writel(GPIO(0) + GP_N_PU, 0xff00ff00); | 355 | + qtest_add_data_func(full_name, (void *)(intptr_t)index, fn); |
827 | + writel(GPIO(0) + GP_N_PD, 0x00ff00ff); | 356 | +} |
828 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OTYP), ==, 0x456789ab); | 357 | +#define add_test(name, td) smbus_add_test(#name, td, test_##name) |
829 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff900f00); | ||
830 | +} | ||
831 | + | ||
832 | +static void test_polarity(void) | ||
833 | +{ | ||
834 | + gpio_reset(0); | ||
835 | + | ||
836 | + /* | ||
837 | + * In push-pull mode, DIN should reflect DOUT because the signal is | ||
838 | + * inverted in both directions. | ||
839 | + */ | ||
840 | + writel(GPIO(0) + GP_N_OTYP, 0x00000000); | ||
841 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
842 | + writel(GPIO(0) + GP_N_DOUT, 0x56789abc); | ||
843 | + writel(GPIO(0) + GP_N_POL, 0x6789abcd); | ||
844 | + g_assert_cmphex(readl(GPIO(0) + GP_N_POL), ==, 0x6789abcd); | ||
845 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x56789abc); | ||
846 | + | ||
847 | + /* | ||
848 | + * When turning off the drivers, DIN should reflect the inverse of the | ||
849 | + * pulled-up lines. | ||
850 | + */ | ||
851 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | ||
852 | + writel(GPIO(0) + GP_N_POL, 0xffffffff); | ||
853 | + writel(GPIO(0) + GP_N_PU, 0x789abcde); | ||
854 | + writel(GPIO(0) + GP_N_PD, ~0x789abcdeU); | ||
855 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, ~0x789abcdeU); | ||
856 | + | ||
857 | + /* | ||
858 | + * In open-drain mode, DOUT=1 will appear to drive the pin high (since DIN | ||
859 | + * is inverted), while DOUT=0 will leave the pin floating. | ||
860 | + */ | ||
861 | + writel(GPIO(0) + GP_N_OTYP, 0xffffffff); | ||
862 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
863 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | ||
864 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | ||
865 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
866 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff00ffff); | ||
867 | +} | ||
868 | + | ||
869 | +static void test_input_mask(void) | ||
870 | +{ | ||
871 | + gpio_reset(0); | ||
872 | + | ||
873 | + /* IEM=0 forces the input to zero before polarity inversion. */ | ||
874 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
875 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
876 | + writel(GPIO(0) + GP_N_POL, 0xffff0000); | ||
877 | + writel(GPIO(0) + GP_N_IEM, 0x87654321); | ||
878 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff9a4300); | ||
879 | +} | ||
880 | + | ||
881 | +static void test_temp_lock(void) | ||
882 | +{ | ||
883 | + gpio_reset(0); | ||
884 | + | ||
885 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
886 | + | ||
887 | + /* Make sure we're unlocked initially. */ | ||
888 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
889 | + /* Writing any value to TLOCK1 will lock. */ | ||
890 | + writel(GPIO(0) + GP_N_TLOCK1, 0); | ||
891 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
892 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
893 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
894 | + /* Now, try to unlock. */ | ||
895 | + gpio_unlock(0); | ||
896 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
897 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
898 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
899 | + | ||
900 | + /* Try it again, but write TLOCK2 to lock. */ | ||
901 | + writel(GPIO(0) + GP_N_TLOCK2, 0); | ||
902 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
903 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
904 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
905 | + /* Now, try to unlock. */ | ||
906 | + gpio_unlock(0); | ||
907 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
908 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
909 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
910 | +} | ||
911 | + | ||
912 | +static void test_events_level(void) | ||
913 | +{ | ||
914 | + gpio_reset(0); | ||
915 | + | ||
916 | + writel(GPIO(0) + GP_N_EVTYP, 0x00000000); | ||
917 | + writel(GPIO(0) + GP_N_DOUT, 0xba987654); | ||
918 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
919 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
920 | + | ||
921 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
922 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
923 | + writel(GPIO(0) + GP_N_DOUT, 0x00000000); | ||
924 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
925 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
926 | + writel(GPIO(0) + GP_N_EVST, 0x00007654); | ||
927 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba980000); | ||
928 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
929 | + writel(GPIO(0) + GP_N_EVST, 0xba980000); | ||
930 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
931 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
932 | +} | ||
933 | + | ||
934 | +static void test_events_rising_edge(void) | ||
935 | +{ | ||
936 | + gpio_reset(0); | ||
937 | + | ||
938 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
939 | + writel(GPIO(0) + GP_N_EVBE, 0x00000000); | ||
940 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
941 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
942 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
943 | + | ||
944 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
945 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
946 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
947 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x0000ff00); | ||
948 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
949 | + writel(GPIO(0) + GP_N_DOUT, 0x00ff0000); | ||
950 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
951 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
952 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
953 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ff0f00); | ||
954 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
955 | + writel(GPIO(0) + GP_N_EVST, 0x00ff0f00); | ||
956 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
957 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
958 | +} | ||
959 | + | ||
960 | +static void test_events_both_edges(void) | ||
961 | +{ | ||
962 | + gpio_reset(0); | ||
963 | + | ||
964 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
965 | + writel(GPIO(0) + GP_N_EVBE, 0xffffffff); | ||
966 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
967 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
968 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
969 | + | ||
970 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
971 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
972 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
973 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
974 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
975 | + writel(GPIO(0) + GP_N_DOUT, 0xef00ff08); | ||
976 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ffff08); | ||
977 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
978 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
979 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ff0f08); | ||
980 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
981 | + writel(GPIO(0) + GP_N_EVST, 0x10ff0f08); | ||
982 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
983 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
984 | +} | ||
985 | + | ||
986 | +static void test_gpion_irq(gconstpointer test_data) | ||
987 | +{ | ||
988 | + intptr_t n = (intptr_t)test_data; | ||
989 | + | ||
990 | + gpio_reset(n); | ||
991 | + | ||
992 | + writel(GPIO(n) + GP_N_EVTYP, 0x00000000); | ||
993 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | ||
994 | + writel(GPIO(n) + GP_N_OE, 0xffffffff); | ||
995 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | ||
996 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | ||
997 | + | ||
998 | + /* Trigger an event; interrupts are masked. */ | ||
999 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00000000); | ||
1000 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1001 | + writel(GPIO(n) + GP_N_DOS, 0x00008000); | ||
1002 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00008000); | ||
1003 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1004 | + | ||
1005 | + /* Unmask all event interrupts; verify that the interrupt fired. */ | ||
1006 | + writel(GPIO(n) + GP_N_EVEN, 0xffffffff); | ||
1007 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1008 | + | ||
1009 | + /* Clear the current bit, set a new bit, irq stays asserted. */ | ||
1010 | + writel(GPIO(n) + GP_N_DOC, 0x00008000); | ||
1011 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1012 | + writel(GPIO(n) + GP_N_DOS, 0x00000200); | ||
1013 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1014 | + writel(GPIO(n) + GP_N_EVST, 0x00008000); | ||
1015 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1016 | + | ||
1017 | + /* Mask/unmask the event that's currently active. */ | ||
1018 | + writel(GPIO(n) + GP_N_EVENC, 0x00000200); | ||
1019 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1020 | + writel(GPIO(n) + GP_N_EVENS, 0x00000200); | ||
1021 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1022 | + | ||
1023 | + /* Clear the input and the status bit, irq is deasserted. */ | ||
1024 | + writel(GPIO(n) + GP_N_DOC, 0x00000200); | ||
1025 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1026 | + writel(GPIO(n) + GP_N_EVST, 0x00000200); | ||
1027 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1028 | +} | ||
1029 | + | 358 | + |
1030 | +int main(int argc, char **argv) | 359 | +int main(int argc, char **argv) |
1031 | +{ | 360 | +{ |
1032 | + int ret; | ||
1033 | + int i; | 361 | + int i; |
1034 | + | 362 | + |
1035 | + g_test_init(&argc, &argv, NULL); | 363 | + g_test_init(&argc, &argv, NULL); |
1036 | + g_test_set_nonfatal_assertions(); | 364 | + g_test_set_nonfatal_assertions(); |
1037 | + | 365 | + |
1038 | + qtest_add_func("/npcm7xx_gpio/dout_to_din", test_dout_to_din); | 366 | + for (i = 0; i < NR_SMBUS_DEVICES; ++i) { |
1039 | + qtest_add_func("/npcm7xx_gpio/pullup_pulldown", test_pullup_pulldown); | 367 | + add_test(disable_bus, i); |
1040 | + qtest_add_func("/npcm7xx_gpio/output_enable", test_output_enable); | 368 | + add_test(invalid_addr, i); |
1041 | + qtest_add_func("/npcm7xx_gpio/open_drain", test_open_drain); | ||
1042 | + qtest_add_func("/npcm7xx_gpio/polarity", test_polarity); | ||
1043 | + qtest_add_func("/npcm7xx_gpio/input_mask", test_input_mask); | ||
1044 | + qtest_add_func("/npcm7xx_gpio/temp_lock", test_temp_lock); | ||
1045 | + qtest_add_func("/npcm7xx_gpio/events/level", test_events_level); | ||
1046 | + qtest_add_func("/npcm7xx_gpio/events/rising_edge", test_events_rising_edge); | ||
1047 | + qtest_add_func("/npcm7xx_gpio/events/both_edges", test_events_both_edges); | ||
1048 | + | ||
1049 | + for (i = 0; i < NR_GPIO_DEVICES; i++) { | ||
1050 | + g_autofree char *test_name = | ||
1051 | + g_strdup_printf("/npcm7xx_gpio/gpio[%d]/irq", i); | ||
1052 | + qtest_add_data_func(test_name, (void *)(intptr_t)i, test_gpion_irq); | ||
1053 | + } | 369 | + } |
1054 | + | 370 | + |
1055 | + qtest_start("-machine npcm750-evb"); | 371 | + for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) { |
1056 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/a9mpcore/gic"); | 372 | + add_test(single_mode, evb_bus_list[i]); |
1057 | + ret = g_test_run(); | 373 | + } |
1058 | + qtest_end(); | 374 | + |
1059 | + | 375 | + return g_test_run(); |
1060 | + return ret; | 376 | +} |
1061 | +} | ||
1062 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | ||
1063 | index XXXXXXX..XXXXXXX 100644 | ||
1064 | --- a/hw/gpio/meson.build | ||
1065 | +++ b/hw/gpio/meson.build | ||
1066 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c')) | ||
1067 | softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c')) | ||
1068 | |||
1069 | softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c')) | ||
1070 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) | ||
1071 | softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) | ||
1072 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) | ||
1073 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) | ||
1074 | diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events | ||
1075 | index XXXXXXX..XXXXXXX 100644 | ||
1076 | --- a/hw/gpio/trace-events | ||
1077 | +++ b/hw/gpio/trace-events | ||
1078 | @@ -XXX,XX +XXX,XX @@ | ||
1079 | # See docs/devel/tracing.txt for syntax documentation. | ||
1080 | |||
1081 | +# npcm7xx_gpio.c | ||
1082 | +npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | ||
1083 | +npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | ||
1084 | +npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 | ||
1085 | +npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 | ||
1086 | +npcm7xx_gpio_update_events(const char *id, uint32_t evst, uint32_t even) "%s evst: 0x%08" PRIx32 " even: 0x%08" PRIx32 | ||
1087 | + | ||
1088 | # nrf51_gpio.c | ||
1089 | nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1090 | nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1091 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 377 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
1092 | index XXXXXXX..XXXXXXX 100644 | 378 | index XXXXXXX..XXXXXXX 100644 |
1093 | --- a/tests/qtest/meson.build | 379 | --- a/tests/qtest/meson.build |
1094 | +++ b/tests/qtest/meson.build | 380 | +++ b/tests/qtest/meson.build |
1095 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | 381 | @@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \ |
1096 | ['prom-env-test', 'boot-serial-test'] | 382 | 'npcm7xx_gpio-test', |
1097 | 383 | 'npcm7xx_pwm-test', | |
1098 | qtests_npcm7xx = \ | 384 | 'npcm7xx_rng-test', |
1099 | - ['npcm7xx_rng-test', | 385 | + 'npcm7xx_smbus-test', |
1100 | + ['npcm7xx_gpio-test', | ||
1101 | + 'npcm7xx_rng-test', | ||
1102 | 'npcm7xx_timer-test', | 386 | 'npcm7xx_timer-test', |
1103 | 'npcm7xx_watchdog_timer-test'] | 387 | 'npcm7xx_watchdog_timer-test'] |
1104 | qtests_arm = \ | 388 | qtests_arm = \ |
1105 | -- | 389 | -- |
1106 | 2.20.1 | 390 | 2.20.1 |
1107 | 391 | ||
1108 | 392 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | A clock mux can be configured to select one of its 10 sources through | 3 | This patch implements the FIFO mode of the SMBus module. In FIFO, the |
4 | the CM_CTL register. It also embeds yet another clock divider, composed | 4 | user transmits or receives at most 16 bytes at a time. The FIFO mode |
5 | of an integer part and a fractional part. The number of bits of each | 5 | allows the module to transmit large amount of data faster than single |
6 | part is mux dependent. | 6 | byte mode. |
7 | 7 | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Since we only added the device in a patch that is only a few commits |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 9 | away in the same patch set. We do not increase the VMstate version |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 10 | number in this special case. |
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 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> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 19 | --- |
14 | hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- | 20 | include/hw/i2c/npcm7xx_smbus.h | 25 +++ |
15 | 1 file changed, 52 insertions(+), 1 deletion(-) | 21 | hw/i2c/npcm7xx_smbus.c | 342 +++++++++++++++++++++++++++++-- |
22 | tests/qtest/npcm7xx_smbus-test.c | 149 +++++++++++++- | ||
23 | hw/i2c/trace-events | 1 + | ||
24 | 4 files changed, 501 insertions(+), 16 deletions(-) | ||
16 | 25 | ||
17 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 26 | diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h |
18 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/misc/bcm2835_cprman.c | 28 | --- a/include/hw/i2c/npcm7xx_smbus.h |
20 | +++ b/hw/misc/bcm2835_cprman.c | 29 | +++ b/include/hw/i2c/npcm7xx_smbus.h |
21 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { | 30 | @@ -XXX,XX +XXX,XX @@ |
22 | 31 | */ | |
23 | /* clock mux */ | 32 | #define NPCM7XX_SMBUS_NR_ADDRS 10 |
24 | 33 | ||
25 | +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) | 34 | +/* Size of the FIFO buffer. */ |
26 | +{ | 35 | +#define NPCM7XX_SMBUS_FIFO_SIZE 16 |
27 | + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); | 36 | + |
28 | +} | 37 | typedef enum NPCM7xxSMBusStatus { |
29 | + | 38 | NPCM7XX_SMBUS_STATUS_IDLE, |
30 | static void clock_mux_update(CprmanClockMuxState *mux) | 39 | NPCM7XX_SMBUS_STATUS_SENDING, |
40 | @@ -XXX,XX +XXX,XX @@ typedef enum NPCM7xxSMBusStatus { | ||
41 | * @addr: The SMBus module's own addresses on the I2C bus. | ||
42 | * @scllt: The SCL low time register. | ||
43 | * @sclht: The SCL high time register. | ||
44 | + * @fif_ctl: The FIFO control register. | ||
45 | + * @fif_cts: The FIFO control status register. | ||
46 | + * @fair_per: The fair preriod register. | ||
47 | + * @txf_ctl: The transmit FIFO control register. | ||
48 | + * @t_out: The SMBus timeout register. | ||
49 | + * @txf_sts: The transmit FIFO status register. | ||
50 | + * @rxf_sts: The receive FIFO status register. | ||
51 | + * @rxf_ctl: The receive FIFO control register. | ||
52 | + * @rx_fifo: The FIFO buffer for receiving in FIFO mode. | ||
53 | + * @rx_cur: The current position of rx_fifo. | ||
54 | * @status: The current status of the SMBus. | ||
55 | */ | ||
56 | typedef struct NPCM7xxSMBusState { | ||
57 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxSMBusState { | ||
58 | uint8_t scllt; | ||
59 | uint8_t sclht; | ||
60 | |||
61 | + uint8_t fif_ctl; | ||
62 | + uint8_t fif_cts; | ||
63 | + uint8_t fair_per; | ||
64 | + uint8_t txf_ctl; | ||
65 | + uint8_t t_out; | ||
66 | + uint8_t txf_sts; | ||
67 | + uint8_t rxf_sts; | ||
68 | + uint8_t rxf_ctl; | ||
69 | + | ||
70 | + uint8_t rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE]; | ||
71 | + uint8_t rx_cur; | ||
72 | + | ||
73 | NPCM7xxSMBusStatus status; | ||
74 | } NPCM7xxSMBusState; | ||
75 | |||
76 | diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/hw/i2c/npcm7xx_smbus.c | ||
79 | +++ b/hw/i2c/npcm7xx_smbus.c | ||
80 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
81 | #define NPCM7XX_ADDR_EN BIT(7) | ||
82 | #define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6) | ||
83 | |||
84 | +/* FIFO Mode Register Fields */ | ||
85 | +/* FIF_CTL fields */ | ||
86 | +#define NPCM7XX_SMBFIF_CTL_FIFO_EN BIT(4) | ||
87 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY_IE BIT(2) | ||
88 | +#define NPCM7XX_SMBFIF_CTL_FAIR_RDY BIT(1) | ||
89 | +#define NPCM7XX_SMBFIF_CTL_FAIR_BUSY BIT(0) | ||
90 | +/* FIF_CTS fields */ | ||
91 | +#define NPCM7XX_SMBFIF_CTS_STR BIT(7) | ||
92 | +#define NPCM7XX_SMBFIF_CTS_CLR_FIFO BIT(6) | ||
93 | +#define NPCM7XX_SMBFIF_CTS_RFTE_IE BIT(3) | ||
94 | +#define NPCM7XX_SMBFIF_CTS_RXF_TXE BIT(1) | ||
95 | +/* TXF_CTL fields */ | ||
96 | +#define NPCM7XX_SMBTXF_CTL_THR_TXIE BIT(6) | ||
97 | +#define NPCM7XX_SMBTXF_CTL_TX_THR(rv) extract8((rv), 0, 5) | ||
98 | +/* T_OUT fields */ | ||
99 | +#define NPCM7XX_SMBT_OUT_ST BIT(7) | ||
100 | +#define NPCM7XX_SMBT_OUT_IE BIT(6) | ||
101 | +#define NPCM7XX_SMBT_OUT_CLKDIV(rv) extract8((rv), 0, 6) | ||
102 | +/* TXF_STS fields */ | ||
103 | +#define NPCM7XX_SMBTXF_STS_TX_THST BIT(6) | ||
104 | +#define NPCM7XX_SMBTXF_STS_TX_BYTES(rv) extract8((rv), 0, 5) | ||
105 | +/* RXF_STS fields */ | ||
106 | +#define NPCM7XX_SMBRXF_STS_RX_THST BIT(6) | ||
107 | +#define NPCM7XX_SMBRXF_STS_RX_BYTES(rv) extract8((rv), 0, 5) | ||
108 | +/* RXF_CTL fields */ | ||
109 | +#define NPCM7XX_SMBRXF_CTL_THR_RXIE BIT(6) | ||
110 | +#define NPCM7XX_SMBRXF_CTL_LAST BIT(5) | ||
111 | +#define NPCM7XX_SMBRXF_CTL_RX_THR(rv) extract8((rv), 0, 5) | ||
112 | + | ||
113 | #define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b))) | ||
114 | #define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o)) | ||
115 | |||
116 | #define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE) | ||
117 | +#define NPCM7XX_SMBUS_FIFO_ENABLED(s) ((s)->fif_ctl & \ | ||
118 | + NPCM7XX_SMBFIF_CTL_FIFO_EN) | ||
119 | |||
120 | /* VERSION fields values, read-only. */ | ||
121 | #define NPCM7XX_SMBUS_VERSION_NUMBER 1 | ||
122 | -#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0 | ||
123 | +#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 1 | ||
124 | |||
125 | /* Reset values */ | ||
126 | #define NPCM7XX_SMB_ST_INIT_VAL 0x00 | ||
127 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
128 | #define NPCM7XX_SMB_ADDR_INIT_VAL 0x00 | ||
129 | #define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00 | ||
130 | #define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00 | ||
131 | +#define NPCM7XX_SMB_FIF_CTL_INIT_VAL 0x00 | ||
132 | +#define NPCM7XX_SMB_FIF_CTS_INIT_VAL 0x00 | ||
133 | +#define NPCM7XX_SMB_FAIR_PER_INIT_VAL 0x00 | ||
134 | +#define NPCM7XX_SMB_TXF_CTL_INIT_VAL 0x00 | ||
135 | +#define NPCM7XX_SMB_T_OUT_INIT_VAL 0x3f | ||
136 | +#define NPCM7XX_SMB_TXF_STS_INIT_VAL 0x00 | ||
137 | +#define NPCM7XX_SMB_RXF_STS_INIT_VAL 0x00 | ||
138 | +#define NPCM7XX_SMB_RXF_CTL_INIT_VAL 0x01 | ||
139 | |||
140 | static uint8_t npcm7xx_smbus_get_version(void) | ||
31 | { | 141 | { |
32 | - clock_update(mux->out, 0); | 142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s) |
33 | + uint64_t freq; | 143 | (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE && |
34 | + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); | 144 | s->st & NPCM7XX_SMBST_SDAST) || |
35 | + bool enabled = clock_mux_is_enabled(mux); | 145 | (s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE && |
36 | + | 146 | - s->cst3 & NPCM7XX_SMBCST3_EO_BUSY)); |
37 | + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); | 147 | + s->cst3 & NPCM7XX_SMBCST3_EO_BUSY) || |
38 | + | 148 | + (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE && |
39 | + if (!enabled) { | 149 | + s->rxf_sts & NPCM7XX_SMBRXF_STS_RX_THST) || |
40 | + clock_update(mux->out, 0); | 150 | + (s->txf_ctl & NPCM7XX_SMBTXF_CTL_THR_TXIE && |
151 | + s->txf_sts & NPCM7XX_SMBTXF_STS_TX_THST) || | ||
152 | + (s->fif_cts & NPCM7XX_SMBFIF_CTS_RFTE_IE && | ||
153 | + s->fif_cts & NPCM7XX_SMBFIF_CTS_RXF_TXE)); | ||
154 | |||
155 | if (level) { | ||
156 | s->cst2 |= NPCM7XX_SMBCST2_INTSTS; | ||
157 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s) | ||
158 | s->status = NPCM7XX_SMBUS_STATUS_NEGACK; | ||
159 | } | ||
160 | |||
161 | +static void npcm7xx_smbus_clear_buffer(NPCM7xxSMBusState *s) | ||
162 | +{ | ||
163 | + s->fif_cts &= ~NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
164 | + s->txf_sts = 0; | ||
165 | + s->rxf_sts = 0; | ||
166 | +} | ||
167 | + | ||
168 | static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) | ||
169 | { | ||
170 | int rv = i2c_send(s->bus, value); | ||
171 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value) | ||
172 | npcm7xx_smbus_nack(s); | ||
173 | } else { | ||
174 | s->st |= NPCM7XX_SMBST_SDAST; | ||
175 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
176 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
177 | + if (NPCM7XX_SMBTXF_STS_TX_BYTES(s->txf_sts) == | ||
178 | + NPCM7XX_SMBTXF_CTL_TX_THR(s->txf_ctl)) { | ||
179 | + s->txf_sts = NPCM7XX_SMBTXF_STS_TX_THST; | ||
180 | + } else { | ||
181 | + s->txf_sts = 0; | ||
182 | + } | ||
183 | + } | ||
184 | } | ||
185 | trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv); | ||
186 | npcm7xx_smbus_update_irq(s); | ||
187 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s) | ||
188 | npcm7xx_smbus_update_irq(s); | ||
189 | } | ||
190 | |||
191 | +static void npcm7xx_smbus_recv_fifo(NPCM7xxSMBusState *s) | ||
192 | +{ | ||
193 | + uint8_t expected_bytes = NPCM7XX_SMBRXF_CTL_RX_THR(s->rxf_ctl); | ||
194 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); | ||
195 | + uint8_t pos; | ||
196 | + | ||
197 | + if (received_bytes == expected_bytes) { | ||
41 | + return; | 198 | + return; |
42 | + } | 199 | + } |
43 | + | 200 | + |
44 | + freq = clock_get_hz(mux->srcs[src]); | 201 | + while (received_bytes < expected_bytes && |
45 | + | 202 | + received_bytes < NPCM7XX_SMBUS_FIFO_SIZE) { |
46 | + if (mux->int_bits == 0 && mux->frac_bits == 0) { | 203 | + pos = (s->rx_cur + received_bytes) % NPCM7XX_SMBUS_FIFO_SIZE; |
47 | + clock_update_hz(mux->out, freq); | 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); | ||
48 | + return; | 217 | + return; |
49 | + } | 218 | + } |
50 | + | 219 | + |
51 | + /* | 220 | + s->rxf_sts |= NPCM7XX_SMBRXF_STS_RX_THST; |
52 | + * The divider has an integer and a fractional part. The size of each part | 221 | + if (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_LAST) { |
53 | + * varies with the muxes (int_bits and frac_bits). Both parts are | 222 | + trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path); |
54 | + * concatenated, with the integer part always starting at bit 12. | 223 | + i2c_nack(s->bus); |
55 | + * | 224 | + s->rxf_ctl &= ~NPCM7XX_SMBRXF_CTL_LAST; |
56 | + * 31 12 11 0 | 225 | + } |
57 | + * ------------------------------ | 226 | + if (received_bytes == NPCM7XX_SMBUS_FIFO_SIZE) { |
58 | + * CM_DIV | | int | frac | | | 227 | + s->st |= NPCM7XX_SMBST_SDAST; |
59 | + * ------------------------------ | 228 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
60 | + * <-----> <------> | 229 | + } else if (!(s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE)) { |
61 | + * int_bits frac_bits | 230 | + s->st |= NPCM7XX_SMBST_SDAST; |
62 | + */ | 231 | + } else { |
63 | + div = extract32(*mux->reg_div, | 232 | + s->st &= ~NPCM7XX_SMBST_SDAST; |
64 | + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, | 233 | + } |
65 | + mux->int_bits + mux->frac_bits); | 234 | + npcm7xx_smbus_update_irq(s); |
66 | + | 235 | +} |
67 | + if (!div) { | 236 | + |
68 | + clock_update(mux->out, 0); | 237 | +static void npcm7xx_smbus_read_byte_fifo(NPCM7xxSMBusState *s) |
238 | +{ | ||
239 | + uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts); | ||
240 | + | ||
241 | + if (received_bytes == 0) { | ||
242 | + npcm7xx_smbus_recv_fifo(s); | ||
69 | + return; | 243 | + return; |
70 | + } | 244 | + } |
71 | + | 245 | + |
72 | + freq = muldiv64(freq, 1 << mux->frac_bits, div); | 246 | + s->sda = s->rx_fifo[s->rx_cur]; |
73 | + | 247 | + s->rx_cur = (s->rx_cur + 1u) % NPCM7XX_SMBUS_FIFO_SIZE; |
74 | + clock_update_hz(mux->out, freq); | 248 | + --s->rxf_sts; |
75 | } | 249 | + npcm7xx_smbus_update_irq(s); |
76 | 250 | +} | |
77 | static void clock_mux_src_update(void *opaque) | 251 | + |
252 | static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) | ||
78 | { | 253 | { |
79 | CprmanClockMuxState **backref = opaque; | 254 | /* |
80 | CprmanClockMuxState *s = *backref; | 255 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_start(NPCM7xxSMBusState *s) |
81 | + CprmanClockMuxSource src = backref - s->backref; | 256 | if (available) { |
82 | + | 257 | s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST; |
83 | + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { | 258 | s->cst |= NPCM7XX_SMBCST_BUSY; |
84 | + return; | 259 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { |
85 | + } | 260 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; |
86 | 261 | + } | |
87 | clock_mux_update(s); | 262 | } else { |
88 | } | 263 | s->st &= ~NPCM7XX_SMBST_MODE; |
264 | s->cst &= ~NPCM7XX_SMBCST_BUSY; | ||
265 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value) | ||
266 | s->st |= NPCM7XX_SMBST_SDAST; | ||
267 | } | ||
268 | } else if (recv) { | ||
269 | - npcm7xx_smbus_recv_byte(s); | ||
270 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
271 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
272 | + npcm7xx_smbus_recv_fifo(s); | ||
273 | + } else { | ||
274 | + npcm7xx_smbus_recv_byte(s); | ||
275 | + } | ||
276 | + } else if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
277 | + s->st |= NPCM7XX_SMBST_SDAST; | ||
278 | + s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE; | ||
279 | } | ||
280 | npcm7xx_smbus_update_irq(s); | ||
281 | } | ||
282 | @@ -XXX,XX +XXX,XX @@ static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s) | ||
283 | |||
284 | switch (s->status) { | ||
285 | case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE: | ||
286 | - npcm7xx_smbus_execute_stop(s); | ||
287 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
288 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) <= 1) { | ||
289 | + npcm7xx_smbus_execute_stop(s); | ||
290 | + } | ||
291 | + if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) == 0) { | ||
292 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
293 | + "%s: read to SDA with an empty rx-fifo buffer, " | ||
294 | + "result undefined: %u\n", | ||
295 | + DEVICE(s)->canonical_path, s->sda); | ||
296 | + break; | ||
297 | + } | ||
298 | + npcm7xx_smbus_read_byte_fifo(s); | ||
299 | + value = s->sda; | ||
300 | + } else { | ||
301 | + npcm7xx_smbus_execute_stop(s); | ||
302 | + } | ||
303 | break; | ||
304 | |||
305 | case NPCM7XX_SMBUS_STATUS_RECEIVING: | ||
306 | - npcm7xx_smbus_recv_byte(s); | ||
307 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
308 | + npcm7xx_smbus_read_byte_fifo(s); | ||
309 | + value = s->sda; | ||
310 | + } else { | ||
311 | + npcm7xx_smbus_recv_byte(s); | ||
312 | + } | ||
313 | break; | ||
314 | |||
315 | default: | ||
316 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value) | ||
317 | } | ||
318 | |||
319 | if (value & NPCM7XX_SMBST_STASTR && | ||
320 | - s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
321 | - npcm7xx_smbus_recv_byte(s); | ||
322 | + s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
323 | + if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) { | ||
324 | + npcm7xx_smbus_recv_fifo(s); | ||
325 | + } else { | ||
326 | + npcm7xx_smbus_recv_byte(s); | ||
327 | + } | ||
328 | } | ||
329 | |||
330 | npcm7xx_smbus_update_irq(s); | ||
331 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value) | ||
332 | s->st = 0; | ||
333 | s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY); | ||
334 | s->cst = 0; | ||
335 | + npcm7xx_smbus_clear_buffer(s); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value) | ||
340 | NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL); | ||
341 | } | ||
342 | |||
343 | +static void npcm7xx_smbus_write_fif_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
344 | +{ | ||
345 | + uint8_t new_ctl = value; | ||
346 | + | ||
347 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_RDY); | ||
348 | + new_ctl = WRITE_ONE_CLEAR(new_ctl, value, NPCM7XX_SMBFIF_CTL_FAIR_RDY); | ||
349 | + new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_BUSY); | ||
350 | + s->fif_ctl = new_ctl; | ||
351 | +} | ||
352 | + | ||
353 | +static void npcm7xx_smbus_write_fif_cts(NPCM7xxSMBusState *s, uint8_t value) | ||
354 | +{ | ||
355 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_STR); | ||
356 | + s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_RXF_TXE); | ||
357 | + s->fif_cts = KEEP_OLD_BIT(value, s->fif_cts, NPCM7XX_SMBFIF_CTS_RFTE_IE); | ||
358 | + | ||
359 | + if (value & NPCM7XX_SMBFIF_CTS_CLR_FIFO) { | ||
360 | + npcm7xx_smbus_clear_buffer(s); | ||
361 | + } | ||
362 | +} | ||
363 | + | ||
364 | +static void npcm7xx_smbus_write_txf_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
365 | +{ | ||
366 | + s->txf_ctl = value; | ||
367 | +} | ||
368 | + | ||
369 | +static void npcm7xx_smbus_write_t_out(NPCM7xxSMBusState *s, uint8_t value) | ||
370 | +{ | ||
371 | + uint8_t new_t_out = value; | ||
372 | + | ||
373 | + if ((value & NPCM7XX_SMBT_OUT_ST) || (!(s->t_out & NPCM7XX_SMBT_OUT_ST))) { | ||
374 | + new_t_out &= ~NPCM7XX_SMBT_OUT_ST; | ||
375 | + } else { | ||
376 | + new_t_out |= NPCM7XX_SMBT_OUT_ST; | ||
377 | + } | ||
378 | + | ||
379 | + s->t_out = new_t_out; | ||
380 | +} | ||
381 | + | ||
382 | +static void npcm7xx_smbus_write_txf_sts(NPCM7xxSMBusState *s, uint8_t value) | ||
383 | +{ | ||
384 | + s->txf_sts = WRITE_ONE_CLEAR(s->txf_sts, value, NPCM7XX_SMBTXF_STS_TX_THST); | ||
385 | +} | ||
386 | + | ||
387 | +static void npcm7xx_smbus_write_rxf_sts(NPCM7xxSMBusState *s, uint8_t value) | ||
388 | +{ | ||
389 | + if (value & NPCM7XX_SMBRXF_STS_RX_THST) { | ||
390 | + s->rxf_sts &= ~NPCM7XX_SMBRXF_STS_RX_THST; | ||
391 | + if (s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) { | ||
392 | + npcm7xx_smbus_recv_fifo(s); | ||
393 | + } | ||
394 | + } | ||
395 | +} | ||
396 | + | ||
397 | +static void npcm7xx_smbus_write_rxf_ctl(NPCM7xxSMBusState *s, uint8_t value) | ||
398 | +{ | ||
399 | + uint8_t new_ctl = value; | ||
400 | + | ||
401 | + if (!(value & NPCM7XX_SMBRXF_CTL_LAST)) { | ||
402 | + new_ctl = KEEP_OLD_BIT(s->rxf_ctl, new_ctl, NPCM7XX_SMBRXF_CTL_LAST); | ||
403 | + } | ||
404 | + s->rxf_ctl = new_ctl; | ||
405 | +} | ||
406 | + | ||
407 | static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
408 | { | ||
409 | NPCM7xxSMBusState *s = opaque; | ||
410 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size) | ||
411 | default: | ||
412 | if (bank) { | ||
413 | /* Bank 1 */ | ||
414 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
415 | - "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
416 | - DEVICE(s)->canonical_path, offset); | ||
417 | + switch (offset) { | ||
418 | + case NPCM7XX_SMB_FIF_CTS: | ||
419 | + value = s->fif_cts; | ||
420 | + break; | ||
421 | + | ||
422 | + case NPCM7XX_SMB_FAIR_PER: | ||
423 | + value = s->fair_per; | ||
424 | + break; | ||
425 | + | ||
426 | + case NPCM7XX_SMB_TXF_CTL: | ||
427 | + value = s->txf_ctl; | ||
428 | + break; | ||
429 | + | ||
430 | + case NPCM7XX_SMB_T_OUT: | ||
431 | + value = s->t_out; | ||
432 | + break; | ||
433 | + | ||
434 | + case NPCM7XX_SMB_TXF_STS: | ||
435 | + value = s->txf_sts; | ||
436 | + break; | ||
437 | + | ||
438 | + case NPCM7XX_SMB_RXF_STS: | ||
439 | + value = s->rxf_sts; | ||
440 | + break; | ||
441 | + | ||
442 | + case NPCM7XX_SMB_RXF_CTL: | ||
443 | + value = s->rxf_ctl; | ||
444 | + break; | ||
445 | + | ||
446 | + default: | ||
447 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
448 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
449 | + DEVICE(s)->canonical_path, offset); | ||
450 | + break; | ||
451 | + } | ||
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 | ||
560 | index XXXXXXX..XXXXXXX 100644 | ||
561 | --- a/tests/qtest/npcm7xx_smbus-test.c | ||
562 | +++ b/tests/qtest/npcm7xx_smbus-test.c | ||
563 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register { | ||
564 | #define ADDR_EN BIT(7) | ||
565 | #define ADDR_A(rv) extract8((rv), 0, 6) | ||
566 | |||
567 | +/* FIF_CTL fields */ | ||
568 | +#define FIF_CTL_FIFO_EN BIT(4) | ||
569 | + | ||
570 | +/* FIF_CTS fields */ | ||
571 | +#define FIF_CTS_CLR_FIFO BIT(6) | ||
572 | +#define FIF_CTS_RFTE_IE BIT(3) | ||
573 | +#define FIF_CTS_RXF_TXE BIT(1) | ||
574 | + | ||
575 | +/* TXF_CTL fields */ | ||
576 | +#define TXF_CTL_THR_TXIE BIT(6) | ||
577 | +#define TXF_CTL_TX_THR(rv) extract8((rv), 0, 5) | ||
578 | + | ||
579 | +/* TXF_STS fields */ | ||
580 | +#define TXF_STS_TX_THST BIT(6) | ||
581 | +#define TXF_STS_TX_BYTES(rv) extract8((rv), 0, 5) | ||
582 | + | ||
583 | +/* RXF_CTL fields */ | ||
584 | +#define RXF_CTL_THR_RXIE BIT(6) | ||
585 | +#define RXF_CTL_LAST BIT(5) | ||
586 | +#define RXF_CTL_RX_THR(rv) extract8((rv), 0, 5) | ||
587 | + | ||
588 | +/* RXF_STS fields */ | ||
589 | +#define RXF_STS_RX_THST BIT(6) | ||
590 | +#define RXF_STS_RX_BYTES(rv) extract8((rv), 0, 5) | ||
591 | + | ||
592 | + | ||
593 | +static void choose_bank(QTestState *qts, uint64_t base_addr, uint8_t bank) | ||
594 | +{ | ||
595 | + uint8_t ctl3 = qtest_readb(qts, base_addr + OFFSET_CTL3); | ||
596 | + | ||
597 | + if (bank) { | ||
598 | + ctl3 |= CTL3_BNK_SEL; | ||
599 | + } else { | ||
600 | + ctl3 &= ~CTL3_BNK_SEL; | ||
601 | + } | ||
602 | + | ||
603 | + qtest_writeb(qts, base_addr + OFFSET_CTL3, ctl3); | ||
604 | +} | ||
605 | |||
606 | static void check_running(QTestState *qts, uint64_t base_addr) | ||
607 | { | ||
608 | @@ -XXX,XX +XXX,XX @@ static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte) | ||
609 | qtest_writeb(qts, base_addr + OFFSET_SDA, byte); | ||
610 | } | ||
611 | |||
612 | +static bool check_recv(QTestState *qts, uint64_t base_addr) | ||
613 | +{ | ||
614 | + uint8_t st, fif_ctl, rxf_ctl, rxf_sts; | ||
615 | + bool fifo; | ||
616 | + | ||
617 | + st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
618 | + choose_bank(qts, base_addr, 0); | ||
619 | + fif_ctl = qtest_readb(qts, base_addr + OFFSET_FIF_CTL); | ||
620 | + fifo = fif_ctl & FIF_CTL_FIFO_EN; | ||
621 | + if (!fifo) { | ||
622 | + return st == (ST_MODE | ST_SDAST); | ||
623 | + } | ||
624 | + | ||
625 | + choose_bank(qts, base_addr, 1); | ||
626 | + rxf_ctl = qtest_readb(qts, base_addr + OFFSET_RXF_CTL); | ||
627 | + rxf_sts = qtest_readb(qts, base_addr + OFFSET_RXF_STS); | ||
628 | + | ||
629 | + if ((rxf_ctl & RXF_CTL_THR_RXIE) && RXF_STS_RX_BYTES(rxf_sts) < 16) { | ||
630 | + return st == ST_MODE; | ||
631 | + } else { | ||
632 | + return st == (ST_MODE | ST_SDAST); | ||
633 | + } | ||
634 | +} | ||
635 | + | ||
636 | static uint8_t recv_byte(QTestState *qts, uint64_t base_addr) | ||
637 | { | ||
638 | - g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, | ||
639 | - ST_MODE | ST_SDAST); | ||
640 | + g_assert_true(check_recv(qts, base_addr)); | ||
641 | return qtest_readb(qts, base_addr + OFFSET_SDA); | ||
642 | } | ||
643 | |||
644 | @@ -XXX,XX +XXX,XX @@ static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr, | ||
645 | qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR); | ||
646 | st = qtest_readb(qts, base_addr + OFFSET_ST); | ||
647 | if (recv) { | ||
648 | - g_assert_cmphex(st, ==, ST_MODE | ST_SDAST); | ||
649 | + g_assert_true(check_recv(qts, base_addr)); | ||
650 | } else { | ||
651 | g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST); | ||
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" | ||
89 | -- | 765 | -- |
90 | 2.20.1 | 766 | 2.20.1 |
91 | 767 | ||
92 | 768 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 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> | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
4 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | 8 | Message-id: 20210211085318.2507-1-luc@lmichel.fr |
5 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 10 | --- |
10 | include/hw/clock.h | 5 +++++ | 11 | MAINTAINERS | 11 +++++++++++ |
11 | 1 file changed, 5 insertions(+) | 12 | 1 file changed, 11 insertions(+) |
12 | 13 | ||
13 | diff --git a/include/hw/clock.h b/include/hw/clock.h | 14 | diff --git a/MAINTAINERS b/MAINTAINERS |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/clock.h | 16 | --- a/MAINTAINERS |
16 | +++ b/include/hw/clock.h | 17 | +++ b/MAINTAINERS |
17 | @@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock; | 18 | @@ -XXX,XX +XXX,XX @@ F: pc-bios/opensbi-* |
18 | VMSTATE_CLOCK_V(field, state, 0) | 19 | F: .gitlab-ci.d/opensbi.yml |
19 | #define VMSTATE_CLOCK_V(field, state, version) \ | 20 | F: .gitlab-ci.d/opensbi/ |
20 | VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) | 21 | |
21 | +#define VMSTATE_ARRAY_CLOCK(field, state, num) \ | 22 | +Clock framework |
22 | + VMSTATE_ARRAY_CLOCK_V(field, state, num, 0) | 23 | +M: Luc Michel <luc@lmichel.fr> |
23 | +#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \ | 24 | +R: Damien Hedde <damien.hedde@greensocs.com> |
24 | + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \ | 25 | +S: Maintained |
25 | + vmstate_clock, Clock) | 26 | +F: include/hw/clock.h |
26 | 27 | +F: include/hw/qdev-clock.h | |
27 | /** | 28 | +F: hw/core/clock.c |
28 | * clock_setup_canonical_path: | 29 | +F: hw/core/clock-vmstate.c |
30 | +F: hw/core/qdev-clock.c | ||
31 | +F: docs/devel/clocks.rst | ||
32 | + | ||
33 | Usermode Emulation | ||
34 | ------------------ | ||
35 | Overall usermode emulation | ||
29 | -- | 36 | -- |
30 | 2.20.1 | 37 | 2.20.1 |
31 | 38 | ||
32 | 39 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a | 3 | This is a 10/100 ethernet device that has several features. |
4 | main oscillator, and several sub-components (PLLs, multiplexers, ...) to | 4 | Only the ones needed by the Linux driver have been implemented. |
5 | generate the BCM2835 clock tree. | 5 | See npcm7xx_emc.c for a list of unimplemented features. |
6 | 6 | ||
7 | This commit adds a skeleton of the CPRMAN, with a dummy register | 7 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
8 | read/write implementation. It embeds the main oscillator (xosc) from | 8 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> |
9 | which all the clocks will be derived. | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | 10 | Signed-off-by: Doug Evans <dje@google.com> | |
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 11 | Message-id: 20210213002520.1374134-2-dje@google.com |
12 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
14 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 13 | --- |
17 | include/hw/arm/bcm2835_peripherals.h | 3 +- | 14 | include/hw/net/npcm7xx_emc.h | 286 ++++++++++++ |
18 | include/hw/misc/bcm2835_cprman.h | 37 +++++ | 15 | hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++ |
19 | include/hw/misc/bcm2835_cprman_internals.h | 24 +++ | 16 | hw/net/meson.build | 1 + |
20 | hw/arm/bcm2835_peripherals.c | 11 +- | 17 | hw/net/trace-events | 17 + |
21 | hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++ | 18 | 4 files changed, 1161 insertions(+) |
22 | hw/misc/meson.build | 1 + | 19 | create mode 100644 include/hw/net/npcm7xx_emc.h |
23 | hw/misc/trace-events | 5 + | 20 | create mode 100644 hw/net/npcm7xx_emc.c |
24 | 7 files changed, 242 insertions(+), 2 deletions(-) | ||
25 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
26 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
27 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
28 | 21 | ||
29 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | 22 | diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h |
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/arm/bcm2835_peripherals.h | ||
32 | +++ b/include/hw/arm/bcm2835_peripherals.h | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | #include "hw/misc/bcm2835_mbox.h" | ||
35 | #include "hw/misc/bcm2835_mphi.h" | ||
36 | #include "hw/misc/bcm2835_thermal.h" | ||
37 | +#include "hw/misc/bcm2835_cprman.h" | ||
38 | #include "hw/sd/sdhci.h" | ||
39 | #include "hw/sd/bcm2835_sdhost.h" | ||
40 | #include "hw/gpio/bcm2835_gpio.h" | ||
41 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | ||
42 | UnimplementedDeviceState txp; | ||
43 | UnimplementedDeviceState armtmr; | ||
44 | UnimplementedDeviceState powermgt; | ||
45 | - UnimplementedDeviceState cprman; | ||
46 | + BCM2835CprmanState cprman; | ||
47 | PL011State uart0; | ||
48 | BCM2835AuxState aux; | ||
49 | BCM2835FBState fb; | ||
50 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | ||
51 | new file mode 100644 | 23 | new file mode 100644 |
52 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
53 | --- /dev/null | 25 | --- /dev/null |
54 | +++ b/include/hw/misc/bcm2835_cprman.h | 26 | +++ b/include/hw/net/npcm7xx_emc.h |
55 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
56 | +/* | 28 | +/* |
57 | + * BCM2835 CPRMAN clock manager | 29 | + * Nuvoton NPCM7xx EMC Module |
58 | + * | 30 | + * |
59 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | 31 | + * Copyright 2020 Google LLC |
60 | + * | 32 | + * |
61 | + * SPDX-License-Identifier: GPL-2.0-or-later | 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. | ||
37 | + * | ||
38 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
39 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
40 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
41 | + * for more details. | ||
62 | + */ | 42 | + */ |
63 | + | 43 | + |
64 | +#ifndef HW_MISC_CPRMAN_H | 44 | +#ifndef NPCM7XX_EMC_H |
65 | +#define HW_MISC_CPRMAN_H | 45 | +#define NPCM7XX_EMC_H |
66 | + | 46 | + |
47 | +#include "hw/irq.h" | ||
67 | +#include "hw/sysbus.h" | 48 | +#include "hw/sysbus.h" |
68 | +#include "hw/qdev-clock.h" | 49 | +#include "net/net.h" |
69 | + | 50 | + |
70 | +#define TYPE_BCM2835_CPRMAN "bcm2835-cprman" | 51 | +/* 32-bit register indices. */ |
71 | + | 52 | +enum NPCM7xxPWMRegister { |
72 | +typedef struct BCM2835CprmanState BCM2835CprmanState; | 53 | + /* Control registers. */ |
73 | + | 54 | + REG_CAMCMR, |
74 | +DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | 55 | + REG_CAMEN, |
75 | + TYPE_BCM2835_CPRMAN) | 56 | + |
76 | + | 57 | + /* There are 16 CAMn[ML] registers. */ |
77 | +#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | 58 | + REG_CAMM_BASE, |
78 | + | 59 | + REG_CAML_BASE, |
79 | +struct BCM2835CprmanState { | 60 | + REG_CAMML_LAST = 0x21, |
61 | + | ||
62 | + REG_TXDLSA = 0x22, | ||
63 | + REG_RXDLSA, | ||
64 | + REG_MCMDR, | ||
65 | + REG_MIID, | ||
66 | + REG_MIIDA, | ||
67 | + REG_FFTCR, | ||
68 | + REG_TSDR, | ||
69 | + REG_RSDR, | ||
70 | + REG_DMARFC, | ||
71 | + REG_MIEN, | ||
72 | + | ||
73 | + /* Status registers. */ | ||
74 | + REG_MISTA, | ||
75 | + REG_MGSTA, | ||
76 | + REG_MPCNT, | ||
77 | + REG_MRPC, | ||
78 | + REG_MRPCC, | ||
79 | + REG_MREPC, | ||
80 | + REG_DMARFS, | ||
81 | + REG_CTXDSA, | ||
82 | + REG_CTXBSA, | ||
83 | + REG_CRXDSA, | ||
84 | + REG_CRXBSA, | ||
85 | + | ||
86 | + NPCM7XX_NUM_EMC_REGS, | ||
87 | +}; | ||
88 | + | ||
89 | +/* REG_CAMCMR fields */ | ||
90 | +/* Enable CAM Compare */ | ||
91 | +#define REG_CAMCMR_ECMP (1 << 4) | ||
92 | +/* Complement CAM Compare */ | ||
93 | +#define REG_CAMCMR_CCAM (1 << 3) | ||
94 | +/* Accept Broadcast Packet */ | ||
95 | +#define REG_CAMCMR_ABP (1 << 2) | ||
96 | +/* Accept Multicast Packet */ | ||
97 | +#define REG_CAMCMR_AMP (1 << 1) | ||
98 | +/* Accept Unicast Packet */ | ||
99 | +#define REG_CAMCMR_AUP (1 << 0) | ||
100 | + | ||
101 | +/* REG_MCMDR fields */ | ||
102 | +/* Software Reset */ | ||
103 | +#define REG_MCMDR_SWR (1 << 24) | ||
104 | +/* Internal Loopback Select */ | ||
105 | +#define REG_MCMDR_LBK (1 << 21) | ||
106 | +/* Operation Mode Select */ | ||
107 | +#define REG_MCMDR_OPMOD (1 << 20) | ||
108 | +/* Enable MDC Clock Generation */ | ||
109 | +#define REG_MCMDR_ENMDC (1 << 19) | ||
110 | +/* Full-Duplex Mode Select */ | ||
111 | +#define REG_MCMDR_FDUP (1 << 18) | ||
112 | +/* Enable SQE Checking */ | ||
113 | +#define REG_MCMDR_ENSEQ (1 << 17) | ||
114 | +/* Send PAUSE Frame */ | ||
115 | +#define REG_MCMDR_SDPZ (1 << 16) | ||
116 | +/* No Defer */ | ||
117 | +#define REG_MCMDR_NDEF (1 << 9) | ||
118 | +/* Frame Transmission On */ | ||
119 | +#define REG_MCMDR_TXON (1 << 8) | ||
120 | +/* Strip CRC Checksum */ | ||
121 | +#define REG_MCMDR_SPCRC (1 << 5) | ||
122 | +/* Accept CRC Error Packet */ | ||
123 | +#define REG_MCMDR_AEP (1 << 4) | ||
124 | +/* Accept Control Packet */ | ||
125 | +#define REG_MCMDR_ACP (1 << 3) | ||
126 | +/* Accept Runt Packet */ | ||
127 | +#define REG_MCMDR_ARP (1 << 2) | ||
128 | +/* Accept Long Packet */ | ||
129 | +#define REG_MCMDR_ALP (1 << 1) | ||
130 | +/* Frame Reception On */ | ||
131 | +#define REG_MCMDR_RXON (1 << 0) | ||
132 | + | ||
133 | +/* REG_MIEN fields */ | ||
134 | +/* Enable Transmit Descriptor Unavailable Interrupt */ | ||
135 | +#define REG_MIEN_ENTDU (1 << 23) | ||
136 | +/* Enable Transmit Completion Interrupt */ | ||
137 | +#define REG_MIEN_ENTXCP (1 << 18) | ||
138 | +/* Enable Transmit Interrupt */ | ||
139 | +#define REG_MIEN_ENTXINTR (1 << 16) | ||
140 | +/* Enable Receive Descriptor Unavailable Interrupt */ | ||
141 | +#define REG_MIEN_ENRDU (1 << 10) | ||
142 | +/* Enable Receive Good Interrupt */ | ||
143 | +#define REG_MIEN_ENRXGD (1 << 4) | ||
144 | +/* Enable Receive Interrupt */ | ||
145 | +#define REG_MIEN_ENRXINTR (1 << 0) | ||
146 | + | ||
147 | +/* REG_MISTA fields */ | ||
148 | +/* TODO: Add error fields and support simulated errors? */ | ||
149 | +/* Transmit Bus Error Interrupt */ | ||
150 | +#define REG_MISTA_TXBERR (1 << 24) | ||
151 | +/* Transmit Descriptor Unavailable Interrupt */ | ||
152 | +#define REG_MISTA_TDU (1 << 23) | ||
153 | +/* Transmit Completion Interrupt */ | ||
154 | +#define REG_MISTA_TXCP (1 << 18) | ||
155 | +/* Transmit Interrupt */ | ||
156 | +#define REG_MISTA_TXINTR (1 << 16) | ||
157 | +/* Receive Bus Error Interrupt */ | ||
158 | +#define REG_MISTA_RXBERR (1 << 11) | ||
159 | +/* Receive Descriptor Unavailable Interrupt */ | ||
160 | +#define REG_MISTA_RDU (1 << 10) | ||
161 | +/* DMA Early Notification Interrupt */ | ||
162 | +#define REG_MISTA_DENI (1 << 9) | ||
163 | +/* Maximum Frame Length Interrupt */ | ||
164 | +#define REG_MISTA_DFOI (1 << 8) | ||
165 | +/* Receive Good Interrupt */ | ||
166 | +#define REG_MISTA_RXGD (1 << 4) | ||
167 | +/* Packet Too Long Interrupt */ | ||
168 | +#define REG_MISTA_PTLE (1 << 3) | ||
169 | +/* Receive Interrupt */ | ||
170 | +#define REG_MISTA_RXINTR (1 << 0) | ||
171 | + | ||
172 | +/* REG_MGSTA fields */ | ||
173 | +/* Transmission Halted */ | ||
174 | +#define REG_MGSTA_TXHA (1 << 11) | ||
175 | +/* Receive Halted */ | ||
176 | +#define REG_MGSTA_RXHA (1 << 11) | ||
177 | + | ||
178 | +/* REG_DMARFC fields */ | ||
179 | +/* Maximum Receive Frame Length */ | ||
180 | +#define REG_DMARFC_RXMS(word) extract32((word), 0, 16) | ||
181 | + | ||
182 | +/* REG MIIDA fields */ | ||
183 | +/* Busy Bit */ | ||
184 | +#define REG_MIIDA_BUSY (1 << 17) | ||
185 | + | ||
186 | +/* Transmit and receive descriptors */ | ||
187 | +typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc; | ||
188 | +typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc; | ||
189 | + | ||
190 | +struct NPCM7xxEMCTxDesc { | ||
191 | + uint32_t flags; | ||
192 | + uint32_t txbsa; | ||
193 | + uint32_t status_and_length; | ||
194 | + uint32_t ntxdsa; | ||
195 | +}; | ||
196 | + | ||
197 | +struct NPCM7xxEMCRxDesc { | ||
198 | + uint32_t status_and_length; | ||
199 | + uint32_t rxbsa; | ||
200 | + uint32_t reserved; | ||
201 | + uint32_t nrxdsa; | ||
202 | +}; | ||
203 | + | ||
204 | +/* NPCM7xxEMCTxDesc.flags values */ | ||
205 | +/* Owner: 0 = cpu, 1 = emc */ | ||
206 | +#define TX_DESC_FLAG_OWNER_MASK (1 << 31) | ||
207 | +/* Transmit interrupt enable */ | ||
208 | +#define TX_DESC_FLAG_INTEN (1 << 2) | ||
209 | +/* CRC append */ | ||
210 | +#define TX_DESC_FLAG_CRCAPP (1 << 1) | ||
211 | +/* Padding enable */ | ||
212 | +#define TX_DESC_FLAG_PADEN (1 << 0) | ||
213 | + | ||
214 | +/* NPCM7xxEMCTxDesc.status_and_length values */ | ||
215 | +/* Collision count */ | ||
216 | +#define TX_DESC_STATUS_CCNT_SHIFT 28 | ||
217 | +#define TX_DESC_STATUS_CCNT_BITSIZE 4 | ||
218 | +/* SQE error */ | ||
219 | +#define TX_DESC_STATUS_SQE (1 << 26) | ||
220 | +/* Transmission paused */ | ||
221 | +#define TX_DESC_STATUS_PAU (1 << 25) | ||
222 | +/* P transmission halted */ | ||
223 | +#define TX_DESC_STATUS_TXHA (1 << 24) | ||
224 | +/* Late collision */ | ||
225 | +#define TX_DESC_STATUS_LC (1 << 23) | ||
226 | +/* Transmission abort */ | ||
227 | +#define TX_DESC_STATUS_TXABT (1 << 22) | ||
228 | +/* No carrier sense */ | ||
229 | +#define TX_DESC_STATUS_NCS (1 << 21) | ||
230 | +/* Defer exceed */ | ||
231 | +#define TX_DESC_STATUS_EXDEF (1 << 20) | ||
232 | +/* Transmission complete */ | ||
233 | +#define TX_DESC_STATUS_TXCP (1 << 19) | ||
234 | +/* Transmission deferred */ | ||
235 | +#define TX_DESC_STATUS_DEF (1 << 17) | ||
236 | +/* Transmit interrupt */ | ||
237 | +#define TX_DESC_STATUS_TXINTR (1 << 16) | ||
238 | + | ||
239 | +#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16) | ||
240 | + | ||
241 | +/* Transmit buffer start address */ | ||
242 | +#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u) | ||
243 | + | ||
244 | +/* Next transmit descriptor start address */ | ||
245 | +#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u) | ||
246 | + | ||
247 | +/* NPCM7xxEMCRxDesc.status_and_length values */ | ||
248 | +/* Owner: 0b00 = cpu, 0b01 = undefined, 0b10 = emc, 0b11 = undefined */ | ||
249 | +#define RX_DESC_STATUS_OWNER_SHIFT 30 | ||
250 | +#define RX_DESC_STATUS_OWNER_BITSIZE 2 | ||
251 | +#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT) | ||
252 | +/* Runt packet */ | ||
253 | +#define RX_DESC_STATUS_RP (1 << 22) | ||
254 | +/* Alignment error */ | ||
255 | +#define RX_DESC_STATUS_ALIE (1 << 21) | ||
256 | +/* Frame reception complete */ | ||
257 | +#define RX_DESC_STATUS_RXGD (1 << 20) | ||
258 | +/* Packet too long */ | ||
259 | +#define RX_DESC_STATUS_PTLE (1 << 19) | ||
260 | +/* CRC error */ | ||
261 | +#define RX_DESC_STATUS_CRCE (1 << 17) | ||
262 | +/* Receive interrupt */ | ||
263 | +#define RX_DESC_STATUS_RXINTR (1 << 16) | ||
264 | + | ||
265 | +#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16) | ||
266 | + | ||
267 | +/* Receive buffer start address */ | ||
268 | +#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u) | ||
269 | + | ||
270 | +/* Next receive descriptor start address */ | ||
271 | +#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u) | ||
272 | + | ||
273 | +/* Minimum packet length, when TX_DESC_FLAG_PADEN is set. */ | ||
274 | +#define MIN_PACKET_LENGTH 64 | ||
275 | + | ||
276 | +struct NPCM7xxEMCState { | ||
80 | + /*< private >*/ | 277 | + /*< private >*/ |
81 | + SysBusDevice parent_obj; | 278 | + SysBusDevice parent; |
82 | + | ||
83 | + /*< public >*/ | 279 | + /*< public >*/ |
280 | + | ||
84 | + MemoryRegion iomem; | 281 | + MemoryRegion iomem; |
85 | + | 282 | + |
86 | + uint32_t regs[CPRMAN_NUM_REGS]; | 283 | + qemu_irq tx_irq; |
87 | + uint32_t xosc_freq; | 284 | + qemu_irq rx_irq; |
88 | + | 285 | + |
89 | + Clock *xosc; | 286 | + NICState *nic; |
287 | + NICConf conf; | ||
288 | + | ||
289 | + /* 0 or 1, for log messages */ | ||
290 | + uint8_t emc_num; | ||
291 | + | ||
292 | + uint32_t regs[NPCM7XX_NUM_EMC_REGS]; | ||
293 | + | ||
294 | + /* | ||
295 | + * tx is active. Set to true by TSDR and then switches off when out of | ||
296 | + * descriptors. If the TXON bit in REG_MCMDR is off then this is off. | ||
297 | + */ | ||
298 | + bool tx_active; | ||
299 | + | ||
300 | + /* | ||
301 | + * rx is active. Set to true by RSDR and then switches off when out of | ||
302 | + * descriptors. If the RXON bit in REG_MCMDR is off then this is off. | ||
303 | + */ | ||
304 | + bool rx_active; | ||
90 | +}; | 305 | +}; |
91 | + | 306 | + |
92 | +#endif | 307 | +typedef struct NPCM7xxEMCState NPCM7xxEMCState; |
93 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | 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 | ||
94 | new file mode 100644 | 315 | new file mode 100644 |
95 | index XXXXXXX..XXXXXXX | 316 | index XXXXXXX..XXXXXXX |
96 | --- /dev/null | 317 | --- /dev/null |
97 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 318 | +++ b/hw/net/npcm7xx_emc.c |
98 | @@ -XXX,XX +XXX,XX @@ | 319 | @@ -XXX,XX +XXX,XX @@ |
99 | +/* | 320 | +/* |
100 | + * BCM2835 CPRMAN clock manager | 321 | + * Nuvoton NPCM7xx EMC Module |
101 | + * | 322 | + * |
102 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | 323 | + * Copyright 2020 Google LLC |
103 | + * | 324 | + * |
104 | + * SPDX-License-Identifier: GPL-2.0-or-later | 325 | + * This program is free software; you can redistribute it and/or modify it |
326 | + * under the terms of the GNU General Public License as published by the | ||
327 | + * Free Software Foundation; either version 2 of the License, or | ||
328 | + * (at your option) any later version. | ||
329 | + * | ||
330 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
331 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
332 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
333 | + * for more details. | ||
334 | + * | ||
335 | + * Unsupported/unimplemented features: | ||
336 | + * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported | ||
337 | + * - Only CAM0 is supported, CAM[1-15] are not | ||
338 | + * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes | ||
339 | + * - MII is not implemented, MIIDA.BUSY and MIID always return zero | ||
340 | + * - MCMDR.LBK is not implemented | ||
341 | + * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported | ||
342 | + * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored | ||
343 | + * - MGSTA.SQE is not supported | ||
344 | + * - pause and control frames are not implemented | ||
345 | + * - MGSTA.CCNT is not supported | ||
346 | + * - MPCNT, DMARFS are not implemented | ||
105 | + */ | 347 | + */ |
106 | + | 348 | + |
107 | +#ifndef HW_MISC_CPRMAN_INTERNALS_H | 349 | +#include "qemu/osdep.h" |
108 | +#define HW_MISC_CPRMAN_INTERNALS_H | 350 | + |
109 | + | 351 | +/* For crc32 */ |
110 | +#include "hw/registerfields.h" | 352 | +#include <zlib.h> |
111 | +#include "hw/misc/bcm2835_cprman.h" | 353 | + |
112 | + | 354 | +#include "qemu-common.h" |
113 | +/* Register map */ | 355 | +#include "hw/irq.h" |
356 | +#include "hw/qdev-clock.h" | ||
357 | +#include "hw/qdev-properties.h" | ||
358 | +#include "hw/net/npcm7xx_emc.h" | ||
359 | +#include "net/eth.h" | ||
360 | +#include "migration/vmstate.h" | ||
361 | +#include "qemu/bitops.h" | ||
362 | +#include "qemu/error-report.h" | ||
363 | +#include "qemu/log.h" | ||
364 | +#include "qemu/module.h" | ||
365 | +#include "qemu/units.h" | ||
366 | +#include "sysemu/dma.h" | ||
367 | +#include "trace.h" | ||
368 | + | ||
369 | +#define CRC_LENGTH 4 | ||
114 | + | 370 | + |
115 | +/* | 371 | +/* |
116 | + * This field is common to all registers. Each register write value must match | 372 | + * The maximum size of a (layer 2) ethernet frame as defined by 802.3. |
117 | + * the CPRMAN_PASSWORD magic value in its 8 MSB. | 373 | + * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload) |
374 | + * This does not include an additional 4 for the vlan field (802.1q). | ||
118 | + */ | 375 | + */ |
119 | +FIELD(CPRMAN, PASSWORD, 24, 8) | 376 | +#define MAX_ETH_FRAME_SIZE 1518 |
120 | +#define CPRMAN_PASSWORD 0x5a | 377 | + |
121 | + | 378 | +static const char *emc_reg_name(int regno) |
122 | +#endif | 379 | +{ |
123 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | 380 | +#define REG(name) case REG_ ## name: return #name; |
124 | index XXXXXXX..XXXXXXX 100644 | 381 | + switch (regno) { |
125 | --- a/hw/arm/bcm2835_peripherals.c | 382 | + REG(CAMCMR) |
126 | +++ b/hw/arm/bcm2835_peripherals.c | 383 | + REG(CAMEN) |
127 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | 384 | + REG(TXDLSA) |
128 | /* DWC2 */ | 385 | + REG(RXDLSA) |
129 | object_initialize_child(obj, "dwc2", &s->dwc2, TYPE_DWC2_USB); | 386 | + REG(MCMDR) |
130 | 387 | + REG(MIID) | |
131 | + /* CPRMAN clock manager */ | 388 | + REG(MIIDA) |
132 | + object_initialize_child(obj, "cprman", &s->cprman, TYPE_BCM2835_CPRMAN); | 389 | + REG(FFTCR) |
133 | + | 390 | + REG(TSDR) |
134 | object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr", | 391 | + REG(RSDR) |
135 | OBJECT(&s->gpu_bus_mr)); | 392 | + REG(DMARFC) |
136 | } | 393 | + REG(MIEN) |
137 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 394 | + REG(MISTA) |
138 | return; | 395 | + REG(MGSTA) |
139 | } | 396 | + REG(MPCNT) |
140 | 397 | + REG(MRPC) | |
141 | + /* CPRMAN clock manager */ | 398 | + REG(MRPCC) |
142 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) { | 399 | + REG(MREPC) |
400 | + REG(DMARFS) | ||
401 | + REG(CTXDSA) | ||
402 | + REG(CTXBSA) | ||
403 | + REG(CRXDSA) | ||
404 | + REG(CRXBSA) | ||
405 | + case REG_CAMM_BASE + 0: return "CAM0M"; | ||
406 | + case REG_CAML_BASE + 0: return "CAM0L"; | ||
407 | + case REG_CAMM_BASE + 2 ... REG_CAMML_LAST: | ||
408 | + /* Only CAM0 is supported, fold the others into something simple. */ | ||
409 | + if (regno & 1) { | ||
410 | + return "CAM<n>L"; | ||
411 | + } else { | ||
412 | + return "CAM<n>M"; | ||
413 | + } | ||
414 | + default: return "UNKNOWN"; | ||
415 | + } | ||
416 | +#undef REG | ||
417 | +} | ||
418 | + | ||
419 | +static void emc_reset(NPCM7xxEMCState *emc) | ||
420 | +{ | ||
421 | + trace_npcm7xx_emc_reset(emc->emc_num); | ||
422 | + | ||
423 | + memset(&emc->regs[0], 0, sizeof(emc->regs)); | ||
424 | + | ||
425 | + /* These regs have non-zero reset values. */ | ||
426 | + emc->regs[REG_TXDLSA] = 0xfffffffc; | ||
427 | + emc->regs[REG_RXDLSA] = 0xfffffffc; | ||
428 | + emc->regs[REG_MIIDA] = 0x00900000; | ||
429 | + emc->regs[REG_FFTCR] = 0x0101; | ||
430 | + emc->regs[REG_DMARFC] = 0x0800; | ||
431 | + emc->regs[REG_MPCNT] = 0x7fff; | ||
432 | + | ||
433 | + emc->tx_active = false; | ||
434 | + emc->rx_active = false; | ||
435 | +} | ||
436 | + | ||
437 | +static void npcm7xx_emc_reset(DeviceState *dev) | ||
438 | +{ | ||
439 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); | ||
440 | + emc_reset(emc); | ||
441 | +} | ||
442 | + | ||
443 | +static void emc_soft_reset(NPCM7xxEMCState *emc) | ||
444 | +{ | ||
445 | + /* | ||
446 | + * The docs say at least MCMDR.{LBK,OPMOD} bits are not changed during a | ||
447 | + * soft reset, but does not go into further detail. For now, KISS. | ||
448 | + */ | ||
449 | + uint32_t mcmdr = emc->regs[REG_MCMDR]; | ||
450 | + emc_reset(emc); | ||
451 | + emc->regs[REG_MCMDR] = mcmdr & (REG_MCMDR_LBK | REG_MCMDR_OPMOD); | ||
452 | + | ||
453 | + qemu_set_irq(emc->tx_irq, 0); | ||
454 | + qemu_set_irq(emc->rx_irq, 0); | ||
455 | +} | ||
456 | + | ||
457 | +static void emc_set_link(NetClientState *nc) | ||
458 | +{ | ||
459 | + /* Nothing to do yet. */ | ||
460 | +} | ||
461 | + | ||
462 | +/* MISTA.TXINTR is the union of the individual bits with their enables. */ | ||
463 | +static void emc_update_mista_txintr(NPCM7xxEMCState *emc) | ||
464 | +{ | ||
465 | + /* Only look at the bits we support. */ | ||
466 | + uint32_t mask = (REG_MISTA_TXBERR | | ||
467 | + REG_MISTA_TDU | | ||
468 | + REG_MISTA_TXCP); | ||
469 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) { | ||
470 | + emc->regs[REG_MISTA] |= REG_MISTA_TXINTR; | ||
471 | + } else { | ||
472 | + emc->regs[REG_MISTA] &= ~REG_MISTA_TXINTR; | ||
473 | + } | ||
474 | +} | ||
475 | + | ||
476 | +/* MISTA.RXINTR is the union of the individual bits with their enables. */ | ||
477 | +static void emc_update_mista_rxintr(NPCM7xxEMCState *emc) | ||
478 | +{ | ||
479 | + /* Only look at the bits we support. */ | ||
480 | + uint32_t mask = (REG_MISTA_RXBERR | | ||
481 | + REG_MISTA_RDU | | ||
482 | + REG_MISTA_RXGD); | ||
483 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) { | ||
484 | + emc->regs[REG_MISTA] |= REG_MISTA_RXINTR; | ||
485 | + } else { | ||
486 | + emc->regs[REG_MISTA] &= ~REG_MISTA_RXINTR; | ||
487 | + } | ||
488 | +} | ||
489 | + | ||
490 | +/* N.B. emc_update_mista_txintr must have already been called. */ | ||
491 | +static void emc_update_tx_irq(NPCM7xxEMCState *emc) | ||
492 | +{ | ||
493 | + int level = !!(emc->regs[REG_MISTA] & | ||
494 | + emc->regs[REG_MIEN] & | ||
495 | + REG_MISTA_TXINTR); | ||
496 | + trace_npcm7xx_emc_update_tx_irq(level); | ||
497 | + qemu_set_irq(emc->tx_irq, level); | ||
498 | +} | ||
499 | + | ||
500 | +/* N.B. emc_update_mista_rxintr must have already been called. */ | ||
501 | +static void emc_update_rx_irq(NPCM7xxEMCState *emc) | ||
502 | +{ | ||
503 | + int level = !!(emc->regs[REG_MISTA] & | ||
504 | + emc->regs[REG_MIEN] & | ||
505 | + REG_MISTA_RXINTR); | ||
506 | + trace_npcm7xx_emc_update_rx_irq(level); | ||
507 | + qemu_set_irq(emc->rx_irq, level); | ||
508 | +} | ||
509 | + | ||
510 | +/* Update IRQ states due to changes in MIEN,MISTA. */ | ||
511 | +static void emc_update_irq_from_reg_change(NPCM7xxEMCState *emc) | ||
512 | +{ | ||
513 | + emc_update_mista_txintr(emc); | ||
514 | + emc_update_tx_irq(emc); | ||
515 | + | ||
516 | + emc_update_mista_rxintr(emc); | ||
517 | + emc_update_rx_irq(emc); | ||
518 | +} | ||
519 | + | ||
520 | +static int emc_read_tx_desc(dma_addr_t addr, NPCM7xxEMCTxDesc *desc) | ||
521 | +{ | ||
522 | + if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) { | ||
523 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%" | ||
524 | + HWADDR_PRIx "\n", __func__, addr); | ||
525 | + return -1; | ||
526 | + } | ||
527 | + desc->flags = le32_to_cpu(desc->flags); | ||
528 | + desc->txbsa = le32_to_cpu(desc->txbsa); | ||
529 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
530 | + desc->ntxdsa = le32_to_cpu(desc->ntxdsa); | ||
531 | + return 0; | ||
532 | +} | ||
533 | + | ||
534 | +static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr) | ||
535 | +{ | ||
536 | + NPCM7xxEMCTxDesc le_desc; | ||
537 | + | ||
538 | + le_desc.flags = cpu_to_le32(desc->flags); | ||
539 | + le_desc.txbsa = cpu_to_le32(desc->txbsa); | ||
540 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
541 | + le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa); | ||
542 | + if (dma_memory_write(&address_space_memory, addr, &le_desc, | ||
543 | + sizeof(le_desc))) { | ||
544 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%" | ||
545 | + HWADDR_PRIx "\n", __func__, addr); | ||
546 | + return -1; | ||
547 | + } | ||
548 | + return 0; | ||
549 | +} | ||
550 | + | ||
551 | +static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc) | ||
552 | +{ | ||
553 | + if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) { | ||
554 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%" | ||
555 | + HWADDR_PRIx "\n", __func__, addr); | ||
556 | + return -1; | ||
557 | + } | ||
558 | + desc->status_and_length = le32_to_cpu(desc->status_and_length); | ||
559 | + desc->rxbsa = le32_to_cpu(desc->rxbsa); | ||
560 | + desc->reserved = le32_to_cpu(desc->reserved); | ||
561 | + desc->nrxdsa = le32_to_cpu(desc->nrxdsa); | ||
562 | + return 0; | ||
563 | +} | ||
564 | + | ||
565 | +static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr) | ||
566 | +{ | ||
567 | + NPCM7xxEMCRxDesc le_desc; | ||
568 | + | ||
569 | + le_desc.status_and_length = cpu_to_le32(desc->status_and_length); | ||
570 | + le_desc.rxbsa = cpu_to_le32(desc->rxbsa); | ||
571 | + le_desc.reserved = cpu_to_le32(desc->reserved); | ||
572 | + le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa); | ||
573 | + if (dma_memory_write(&address_space_memory, addr, &le_desc, | ||
574 | + sizeof(le_desc))) { | ||
575 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%" | ||
576 | + HWADDR_PRIx "\n", __func__, addr); | ||
577 | + return -1; | ||
578 | + } | ||
579 | + return 0; | ||
580 | +} | ||
581 | + | ||
582 | +static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags) | ||
583 | +{ | ||
584 | + trace_npcm7xx_emc_set_mista(flags); | ||
585 | + emc->regs[REG_MISTA] |= flags; | ||
586 | + if (extract32(flags, 16, 16)) { | ||
587 | + emc_update_mista_txintr(emc); | ||
588 | + } | ||
589 | + if (extract32(flags, 0, 16)) { | ||
590 | + emc_update_mista_rxintr(emc); | ||
591 | + } | ||
592 | +} | ||
593 | + | ||
594 | +static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag) | ||
595 | +{ | ||
596 | + emc->tx_active = false; | ||
597 | + emc_set_mista(emc, mista_flag); | ||
598 | +} | ||
599 | + | ||
600 | +static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag) | ||
601 | +{ | ||
602 | + emc->rx_active = false; | ||
603 | + emc_set_mista(emc, mista_flag); | ||
604 | +} | ||
605 | + | ||
606 | +static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc, | ||
607 | + const NPCM7xxEMCTxDesc *tx_desc, | ||
608 | + uint32_t desc_addr) | ||
609 | +{ | ||
610 | + /* Update the current descriptor, if only to reset the owner flag. */ | ||
611 | + if (emc_write_tx_desc(tx_desc, desc_addr)) { | ||
612 | + /* | ||
613 | + * We just read it so this shouldn't generally happen. | ||
614 | + * Error already reported. | ||
615 | + */ | ||
616 | + emc_set_mista(emc, REG_MISTA_TXBERR); | ||
617 | + } | ||
618 | + emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa); | ||
619 | +} | ||
620 | + | ||
621 | +static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc, | ||
622 | + const NPCM7xxEMCRxDesc *rx_desc, | ||
623 | + uint32_t desc_addr) | ||
624 | +{ | ||
625 | + /* Update the current descriptor, if only to reset the owner flag. */ | ||
626 | + if (emc_write_rx_desc(rx_desc, desc_addr)) { | ||
627 | + /* | ||
628 | + * We just read it so this shouldn't generally happen. | ||
629 | + * Error already reported. | ||
630 | + */ | ||
631 | + emc_set_mista(emc, REG_MISTA_RXBERR); | ||
632 | + } | ||
633 | + emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa); | ||
634 | +} | ||
635 | + | ||
636 | +static void emc_try_send_next_packet(NPCM7xxEMCState *emc) | ||
637 | +{ | ||
638 | + /* Working buffer for sending out packets. Most packets fit in this. */ | ||
639 | +#define TX_BUFFER_SIZE 2048 | ||
640 | + uint8_t tx_send_buffer[TX_BUFFER_SIZE]; | ||
641 | + uint32_t desc_addr = TX_DESC_NTXDSA(emc->regs[REG_CTXDSA]); | ||
642 | + NPCM7xxEMCTxDesc tx_desc; | ||
643 | + uint32_t next_buf_addr, length; | ||
644 | + uint8_t *buf; | ||
645 | + g_autofree uint8_t *malloced_buf = NULL; | ||
646 | + | ||
647 | + if (emc_read_tx_desc(desc_addr, &tx_desc)) { | ||
648 | + /* Error reading descriptor, already reported. */ | ||
649 | + emc_halt_tx(emc, REG_MISTA_TXBERR); | ||
650 | + emc_update_tx_irq(emc); | ||
143 | + return; | 651 | + return; |
144 | + } | 652 | + } |
145 | + memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | 653 | + |
146 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | 654 | + /* Nothing we can do if we don't own the descriptor. */ |
147 | + | 655 | + if (!(tx_desc.flags & TX_DESC_FLAG_OWNER_MASK)) { |
148 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | 656 | + trace_npcm7xx_emc_cpu_owned_desc(desc_addr); |
149 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | 657 | + emc_halt_tx(emc, REG_MISTA_TDU); |
150 | sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic)); | 658 | + emc_update_tx_irq(emc); |
151 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 659 | + return; |
152 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | 660 | + } |
153 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | 661 | + |
154 | create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | 662 | + /* Give the descriptor back regardless of what happens. */ |
155 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | 663 | + tx_desc.flags &= ~TX_DESC_FLAG_OWNER_MASK; |
156 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); | 664 | + tx_desc.status_and_length &= 0xffff; |
157 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); | 665 | + |
158 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); | 666 | + /* |
159 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 667 | + * Despite the h/w documentation saying the tx buffer is word aligned, |
160 | new file mode 100644 | 668 | + * the linux driver does not word align the buffer. There is value in not |
161 | index XXXXXXX..XXXXXXX | 669 | + * aligning the buffer: See the description of NET_IP_ALIGN in linux |
162 | --- /dev/null | 670 | + * kernel sources. |
163 | +++ b/hw/misc/bcm2835_cprman.c | 671 | + */ |
164 | @@ -XXX,XX +XXX,XX @@ | 672 | + next_buf_addr = tx_desc.txbsa; |
165 | +/* | 673 | + emc->regs[REG_CTXBSA] = next_buf_addr; |
166 | + * BCM2835 CPRMAN clock manager | 674 | + length = TX_DESC_PKT_LEN(tx_desc.status_and_length); |
167 | + * | 675 | + buf = &tx_send_buffer[0]; |
168 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | 676 | + |
169 | + * | 677 | + if (length > sizeof(tx_send_buffer)) { |
170 | + * SPDX-License-Identifier: GPL-2.0-or-later | 678 | + malloced_buf = g_malloc(length); |
171 | + */ | 679 | + buf = malloced_buf; |
172 | + | 680 | + } |
173 | +/* | 681 | + |
174 | + * This peripheral is roughly divided into 3 main parts: | 682 | + if (dma_memory_read(&address_space_memory, next_buf_addr, buf, length)) { |
175 | + * - the PLLs | 683 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n", |
176 | + * - the PLL channels | 684 | + __func__, next_buf_addr); |
177 | + * - the clock muxes | 685 | + emc_set_mista(emc, REG_MISTA_TXBERR); |
178 | + * | 686 | + emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr); |
179 | + * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more | 687 | + emc_update_tx_irq(emc); |
180 | + * channels. Those channel are then connected to the clock muxes. Each mux has | 688 | + trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]); |
181 | + * multiples sources (usually the xosc, some of the PLL channels and some "test | 689 | + return; |
182 | + * debug" clocks). A mux is configured to select a given source through its | 690 | + } |
183 | + * control register. Each mux has one output clock that also goes out of the | 691 | + |
184 | + * CPRMAN. This output clock usually connects to another peripheral in the SoC | 692 | + if ((tx_desc.flags & TX_DESC_FLAG_PADEN) && (length < MIN_PACKET_LENGTH)) { |
185 | + * (so a given mux is dedicated to a peripheral). | 693 | + memset(buf + length, 0, MIN_PACKET_LENGTH - length); |
186 | + * | 694 | + length = MIN_PACKET_LENGTH; |
187 | + * At each level (PLL, channel and mux), the clock can be altered through | 695 | + } |
188 | + * dividers (and multipliers in case of the PLLs), and can be disabled (in this | 696 | + |
189 | + * case, the next levels see no clock). | 697 | + /* N.B. emc_receive can get called here. */ |
190 | + * | 698 | + qemu_send_packet(qemu_get_queue(emc->nic), buf, length); |
191 | + * This can be sum-up as follows (this is an example and not the actual BCM2835 | 699 | + trace_npcm7xx_emc_sent_packet(length); |
192 | + * clock tree): | 700 | + |
193 | + * | 701 | + tx_desc.status_and_length |= TX_DESC_STATUS_TXCP; |
194 | + * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals | 702 | + if (tx_desc.flags & TX_DESC_FLAG_INTEN) { |
195 | + * | |->[PLL channel] muxes takes [mux] | 703 | + emc_set_mista(emc, REG_MISTA_TXCP); |
196 | + * | \->[PLL channel] inputs from [mux] | 704 | + } |
197 | + * | some channels [mux] | 705 | + if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_TXINTR) { |
198 | + * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux] | 706 | + tx_desc.status_and_length |= TX_DESC_STATUS_TXINTR; |
199 | + * | \->[PLL channel] ...-->[mux] | 707 | + } |
200 | + * | [mux] | 708 | + |
201 | + * \-->[PLL]--->[PLL channel] [mux] | 709 | + emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr); |
202 | + * | 710 | + emc_update_tx_irq(emc); |
203 | + * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | 711 | + trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]); |
204 | + * tree configuration. | 712 | +} |
205 | + */ | 713 | + |
206 | + | 714 | +static bool emc_can_receive(NetClientState *nc) |
207 | +#include "qemu/osdep.h" | 715 | +{ |
208 | +#include "qemu/log.h" | 716 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc)); |
209 | +#include "migration/vmstate.h" | 717 | + |
210 | +#include "hw/qdev-properties.h" | 718 | + bool can_receive = emc->rx_active; |
211 | +#include "hw/misc/bcm2835_cprman.h" | 719 | + trace_npcm7xx_emc_can_receive(can_receive); |
212 | +#include "hw/misc/bcm2835_cprman_internals.h" | 720 | + return can_receive; |
213 | +#include "trace.h" | 721 | +} |
214 | + | 722 | + |
215 | +/* CPRMAN "top level" model */ | 723 | +/* If result is false then *fail_reason contains the reason. */ |
216 | + | 724 | +static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf, |
217 | +static uint64_t cprman_read(void *opaque, hwaddr offset, | 725 | + size_t len, const char **fail_reason) |
218 | + unsigned size) | 726 | +{ |
219 | +{ | 727 | + eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf)); |
220 | + BCM2835CprmanState *s = CPRMAN(opaque); | 728 | + |
221 | + uint64_t r = 0; | 729 | + switch (pkt_type) { |
222 | + size_t idx = offset / sizeof(uint32_t); | 730 | + case ETH_PKT_BCAST: |
223 | + | 731 | + if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) { |
224 | + switch (idx) { | 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 | + } | ||
225 | + default: | 761 | + default: |
226 | + r = s->regs[idx]; | 762 | + g_assert_not_reached(); |
227 | + } | 763 | + } |
228 | + | 764 | +} |
229 | + trace_bcm2835_cprman_read(offset, r); | 765 | + |
230 | + return r; | 766 | +static bool emc_receive_filter(NPCM7xxEMCState *emc, const uint8_t *buf, |
231 | +} | 767 | + size_t len) |
232 | + | 768 | +{ |
233 | +static void cprman_write(void *opaque, hwaddr offset, | 769 | + const char *fail_reason = NULL; |
234 | + uint64_t value, unsigned size) | 770 | + bool ok = emc_receive_filter1(emc, buf, len, &fail_reason); |
235 | +{ | 771 | + if (!ok) { |
236 | + BCM2835CprmanState *s = CPRMAN(opaque); | 772 | + trace_npcm7xx_emc_packet_filtered_out(fail_reason); |
237 | + size_t idx = offset / sizeof(uint32_t); | 773 | + } |
238 | + | 774 | + return ok; |
239 | + if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) { | 775 | +} |
240 | + trace_bcm2835_cprman_write_invalid_magic(offset, value); | 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); | ||
241 | + return; | 960 | + return; |
242 | + } | 961 | + } |
243 | + | 962 | + |
244 | + value &= ~R_CPRMAN_PASSWORD_MASK; | 963 | + trace_npcm7xx_emc_reg_write(emc->emc_num, emc_reg_name(reg), reg, value); |
245 | + | 964 | + |
246 | + trace_bcm2835_cprman_write(offset, value); | 965 | + switch (reg) { |
247 | + s->regs[idx] = value; | 966 | + case REG_CAMCMR: |
248 | + | 967 | + emc->regs[reg] = value; |
249 | +} | 968 | + break; |
250 | + | 969 | + case REG_CAMEN: |
251 | +static const MemoryRegionOps cprman_ops = { | 970 | + /* Only CAM0 is supported, don't pretend otherwise. */ |
252 | + .read = cprman_read, | 971 | + if (value & ~1) { |
253 | + .write = cprman_write, | 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, | ||
254 | + .endianness = DEVICE_LITTLE_ENDIAN, | 1087 | + .endianness = DEVICE_LITTLE_ENDIAN, |
255 | + .valid = { | 1088 | + .valid = { |
256 | + /* | 1089 | + .min_access_size = 4, |
257 | + * Although this hasn't been checked against real hardware, nor the | ||
258 | + * information can be found in a datasheet, it seems reasonable because | ||
259 | + * of the "PASSWORD" magic value found in every registers. | ||
260 | + */ | ||
261 | + .min_access_size = 4, | ||
262 | + .max_access_size = 4, | ||
263 | + .unaligned = false, | ||
264 | + }, | ||
265 | + .impl = { | ||
266 | + .max_access_size = 4, | 1090 | + .max_access_size = 4, |
1091 | + .unaligned = false, | ||
267 | + }, | 1092 | + }, |
268 | +}; | 1093 | +}; |
269 | + | 1094 | + |
270 | +static void cprman_reset(DeviceState *dev) | 1095 | +static void emc_cleanup(NetClientState *nc) |
271 | +{ | 1096 | +{ |
272 | + BCM2835CprmanState *s = CPRMAN(dev); | 1097 | + /* Nothing to do yet. */ |
273 | + | 1098 | +} |
274 | + memset(s->regs, 0, sizeof(s->regs)); | 1099 | + |
275 | + | 1100 | +static NetClientInfo net_npcm7xx_emc_info = { |
276 | + clock_update_hz(s->xosc, s->xosc_freq); | 1101 | + .type = NET_CLIENT_DRIVER_NIC, |
277 | +} | 1102 | + .size = sizeof(NICState), |
278 | + | 1103 | + .can_receive = emc_can_receive, |
279 | +static void cprman_init(Object *obj) | 1104 | + .receive = emc_receive, |
280 | +{ | 1105 | + .cleanup = emc_cleanup, |
281 | + BCM2835CprmanState *s = CPRMAN(obj); | 1106 | + .link_status_changed = emc_set_link, |
282 | + | 1107 | +}; |
283 | + s->xosc = clock_new(obj, "xosc"); | 1108 | + |
284 | + | 1109 | +static void npcm7xx_emc_realize(DeviceState *dev, Error **errp) |
285 | + memory_region_init_io(&s->iomem, obj, &cprman_ops, | 1110 | +{ |
286 | + s, "bcm2835-cprman", 0x2000); | 1111 | + NPCM7xxEMCState *emc = NPCM7XX_EMC(dev); |
287 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | 1112 | + SysBusDevice *sbd = SYS_BUS_DEVICE(emc); |
288 | +} | 1113 | + |
289 | + | 1114 | + memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc, |
290 | +static const VMStateDescription cprman_vmstate = { | 1115 | + TYPE_NPCM7XX_EMC, 4 * KiB); |
291 | + .name = TYPE_BCM2835_CPRMAN, | 1116 | + sysbus_init_mmio(sbd, &emc->iomem); |
292 | + .version_id = 1, | 1117 | + sysbus_init_irq(sbd, &emc->tx_irq); |
293 | + .minimum_version_id = 1, | 1118 | + sysbus_init_irq(sbd, &emc->rx_irq); |
1119 | + | ||
1120 | + qemu_macaddr_default_if_unset(&emc->conf.macaddr); | ||
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, | ||
294 | + .fields = (VMStateField[]) { | 1137 | + .fields = (VMStateField[]) { |
295 | + VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS), | 1138 | + VMSTATE_UINT8(emc_num, NPCM7xxEMCState), |
296 | + VMSTATE_END_OF_LIST() | 1139 | + VMSTATE_UINT32_ARRAY(regs, NPCM7xxEMCState, NPCM7XX_NUM_EMC_REGS), |
297 | + } | 1140 | + VMSTATE_BOOL(tx_active, NPCM7xxEMCState), |
1141 | + VMSTATE_BOOL(rx_active, NPCM7xxEMCState), | ||
1142 | + VMSTATE_END_OF_LIST(), | ||
1143 | + }, | ||
298 | +}; | 1144 | +}; |
299 | + | 1145 | + |
300 | +static Property cprman_properties[] = { | 1146 | +static Property npcm7xx_emc_properties[] = { |
301 | + DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), | 1147 | + DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf), |
302 | + DEFINE_PROP_END_OF_LIST() | 1148 | + DEFINE_PROP_END_OF_LIST(), |
303 | +}; | 1149 | +}; |
304 | + | 1150 | + |
305 | +static void cprman_class_init(ObjectClass *klass, void *data) | 1151 | +static void npcm7xx_emc_class_init(ObjectClass *klass, void *data) |
306 | +{ | 1152 | +{ |
307 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1153 | + DeviceClass *dc = DEVICE_CLASS(klass); |
308 | + | 1154 | + |
309 | + dc->reset = cprman_reset; | 1155 | + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); |
310 | + dc->vmsd = &cprman_vmstate; | 1156 | + dc->desc = "NPCM7xx EMC Controller"; |
311 | + device_class_set_props(dc, cprman_properties); | 1157 | + dc->realize = npcm7xx_emc_realize; |
312 | +} | 1158 | + dc->unrealize = npcm7xx_emc_unrealize; |
313 | + | 1159 | + dc->reset = npcm7xx_emc_reset; |
314 | +static const TypeInfo cprman_info = { | 1160 | + dc->vmsd = &vmstate_npcm7xx_emc; |
315 | + .name = TYPE_BCM2835_CPRMAN, | 1161 | + device_class_set_props(dc, npcm7xx_emc_properties); |
1162 | +} | ||
1163 | + | ||
1164 | +static const TypeInfo npcm7xx_emc_info = { | ||
1165 | + .name = TYPE_NPCM7XX_EMC, | ||
316 | + .parent = TYPE_SYS_BUS_DEVICE, | 1166 | + .parent = TYPE_SYS_BUS_DEVICE, |
317 | + .instance_size = sizeof(BCM2835CprmanState), | 1167 | + .instance_size = sizeof(NPCM7xxEMCState), |
318 | + .class_init = cprman_class_init, | 1168 | + .class_init = npcm7xx_emc_class_init, |
319 | + .instance_init = cprman_init, | ||
320 | +}; | 1169 | +}; |
321 | + | 1170 | + |
322 | +static void cprman_register_types(void) | 1171 | +static void npcm7xx_emc_register_type(void) |
323 | +{ | 1172 | +{ |
324 | + type_register_static(&cprman_info); | 1173 | + type_register_static(&npcm7xx_emc_info); |
325 | +} | 1174 | +} |
326 | + | 1175 | + |
327 | +type_init(cprman_register_types); | 1176 | +type_init(npcm7xx_emc_register_type) |
328 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 1177 | diff --git a/hw/net/meson.build b/hw/net/meson.build |
329 | index XXXXXXX..XXXXXXX 100644 | 1178 | index XXXXXXX..XXXXXXX 100644 |
330 | --- a/hw/misc/meson.build | 1179 | --- a/hw/net/meson.build |
331 | +++ b/hw/misc/meson.build | 1180 | +++ b/hw/net/meson.build |
332 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( | 1181 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c')) |
333 | 'bcm2835_property.c', | 1182 | softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c')) |
334 | 'bcm2835_rng.c', | 1183 | softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c')) |
335 | 'bcm2835_thermal.c', | 1184 | softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c')) |
336 | + 'bcm2835_cprman.c', | 1185 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c')) |
337 | )) | 1186 | |
338 | softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) | 1187 | softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c')) |
339 | softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c')) | 1188 | softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c')) |
340 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 1189 | diff --git a/hw/net/trace-events b/hw/net/trace-events |
341 | index XXXXXXX..XXXXXXX 100644 | 1190 | index XXXXXXX..XXXXXXX 100644 |
342 | --- a/hw/misc/trace-events | 1191 | --- a/hw/net/trace-events |
343 | +++ b/hw/misc/trace-events | 1192 | +++ b/hw/net/trace-events |
344 | @@ -XXX,XX +XXX,XX @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 | 1193 | @@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x" |
345 | # pca9552.c | 1194 | imx_enet_receive(size_t size) "len %zu" |
346 | pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" | 1195 | imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d" |
347 | pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" | 1196 | imx_enet_receive_last(int last) "rx frame flags 0x%04x" |
348 | + | 1197 | + |
349 | +# bcm2835_cprman.c | 1198 | +# npcm7xx_emc.c |
350 | +bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | 1199 | +npcm7xx_emc_reset(int emc_num) "Resetting emc%d" |
351 | +bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | 1200 | +npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d" |
352 | +bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | 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" | ||
353 | -- | 1214 | -- |
354 | 2.20.1 | 1215 | 2.20.1 |
355 | 1216 | ||
356 | 1217 | diff view generated by jsdifflib |
1 | From: Havard Skinnemoen <hskinnemoen@google.com> | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The NPCM730 and NPCM750 chips have a single USB host port shared between | 3 | This is a 10/100 ethernet device that has several features. |
4 | a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This | 4 | Only the ones needed by the Linux driver have been implemented. |
5 | adds support for both of them. | 5 | See npcm7xx_emc.c for a list of unimplemented features. |
6 | 6 | ||
7 | Testing notes: | 7 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
8 | * With -device usb-kbd, qemu will automatically insert a full-speed | 8 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> |
9 | hub, and the keyboard becomes controlled by the OHCI controller. | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | * With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly | 10 | Signed-off-by: Doug Evans <dje@google.com> |
11 | attached to the port without any hubs, and the device becomes | 11 | Message-id: 20210213002520.1374134-3-dje@google.com |
12 | controlled by the EHCI controller since it's high speed capable. | ||
13 | * With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the | ||
14 | keyboard is directly attached to the port, but it only advertises | ||
15 | itself as full-speed capable, so it becomes controlled by the OHCI | ||
16 | controller. | ||
17 | |||
18 | In all cases, the keyboard device enumerates correctly. | ||
19 | |||
20 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
21 | Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> | ||
22 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
24 | --- | 13 | --- |
25 | docs/system/arm/nuvoton.rst | 2 +- | 14 | docs/system/arm/nuvoton.rst | 3 ++- |
26 | hw/usb/hcd-ehci.h | 1 + | 15 | include/hw/arm/npcm7xx.h | 2 ++ |
27 | include/hw/arm/npcm7xx.h | 4 ++++ | 16 | hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++-- |
28 | hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++-- | 17 | 3 files changed, 52 insertions(+), 3 deletions(-) |
29 | hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++ | ||
30 | 5 files changed, 50 insertions(+), 3 deletions(-) | ||
31 | 18 | ||
32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | 19 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
33 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/docs/system/arm/nuvoton.rst | 21 | --- a/docs/system/arm/nuvoton.rst |
35 | +++ b/docs/system/arm/nuvoton.rst | 22 | +++ b/docs/system/arm/nuvoton.rst |
36 | @@ -XXX,XX +XXX,XX @@ Supported devices | 23 | @@ -XXX,XX +XXX,XX @@ Supported devices |
37 | * OTP controllers (no protection features) | 24 | * Analog to Digital Converter (ADC) |
38 | * Flash Interface Unit (FIU; no protection features) | 25 | * Pulse Width Modulation (PWM) |
39 | * Random Number Generator (RNG) | 26 | * SMBus controller (SMBF) |
40 | + * USB host (USBH) | 27 | + * Ethernet controller (EMC) |
41 | 28 | ||
42 | Missing devices | 29 | Missing devices |
43 | --------------- | 30 | --------------- |
44 | @@ -XXX,XX +XXX,XX @@ Missing devices | 31 | @@ -XXX,XX +XXX,XX @@ Missing devices |
32 | * Shared memory (SHM) | ||
45 | * eSPI slave interface | 33 | * eSPI slave interface |
46 | 34 | ||
47 | * Ethernet controllers (GMAC and EMC) | 35 | - * Ethernet controllers (GMAC and EMC) |
48 | - * USB host (USBH) | 36 | + * Ethernet controller (GMAC) |
49 | * USB device (USBD) | 37 | * USB device (USBD) |
50 | * SMBus controller (SMBF) | ||
51 | * Peripheral SPI controller (PSPI) | 38 | * Peripheral SPI controller (PSPI) |
52 | diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h | 39 | * SD/MMC host |
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/usb/hcd-ehci.h | ||
55 | +++ b/hw/usb/hcd-ehci.h | ||
56 | @@ -XXX,XX +XXX,XX @@ struct EHCIPCIState { | ||
57 | #define TYPE_PLATFORM_EHCI "platform-ehci-usb" | ||
58 | #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" | ||
59 | #define TYPE_AW_H3_EHCI "aw-h3-ehci-usb" | ||
60 | +#define TYPE_NPCM7XX_EHCI "npcm7xx-ehci-usb" | ||
61 | #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb" | ||
62 | #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb" | ||
63 | #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb" | ||
64 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | 40 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h |
65 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
66 | --- a/include/hw/arm/npcm7xx.h | 42 | --- a/include/hw/arm/npcm7xx.h |
67 | +++ b/include/hw/arm/npcm7xx.h | 43 | +++ b/include/hw/arm/npcm7xx.h |
68 | @@ -XXX,XX +XXX,XX @@ | 44 | @@ -XXX,XX +XXX,XX @@ |
45 | #include "hw/misc/npcm7xx_gcr.h" | ||
46 | #include "hw/misc/npcm7xx_pwm.h" | ||
47 | #include "hw/misc/npcm7xx_rng.h" | ||
48 | +#include "hw/net/npcm7xx_emc.h" | ||
69 | #include "hw/nvram/npcm7xx_otp.h" | 49 | #include "hw/nvram/npcm7xx_otp.h" |
70 | #include "hw/timer/npcm7xx_timer.h" | 50 | #include "hw/timer/npcm7xx_timer.h" |
71 | #include "hw/ssi/npcm7xx_fiu.h" | 51 | #include "hw/ssi/npcm7xx_fiu.h" |
72 | +#include "hw/usb/hcd-ehci.h" | ||
73 | +#include "hw/usb/hcd-ohci.h" | ||
74 | #include "target/arm/cpu.h" | ||
75 | |||
76 | #define NPCM7XX_MAX_NUM_CPUS (2) | ||
77 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | 52 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
78 | NPCM7xxOTPState fuse_array; | 53 | EHCISysBusState ehci; |
79 | NPCM7xxMCState mc; | 54 | OHCISysBusState ohci; |
80 | NPCM7xxRNGState rng; | ||
81 | + EHCISysBusState ehci; | ||
82 | + OHCISysBusState ohci; | ||
83 | NPCM7xxFIUState fiu[2]; | 55 | NPCM7xxFIUState fiu[2]; |
56 | + NPCM7xxEMCState emc[2]; | ||
84 | } NPCM7xxState; | 57 | } NPCM7xxState; |
85 | 58 | ||
59 | #define TYPE_NPCM7XX "npcm7xx" | ||
86 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | 60 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
87 | index XXXXXXX..XXXXXXX 100644 | 61 | index XXXXXXX..XXXXXXX 100644 |
88 | --- a/hw/arm/npcm7xx.c | 62 | --- a/hw/arm/npcm7xx.c |
89 | +++ b/hw/arm/npcm7xx.c | 63 | +++ b/hw/arm/npcm7xx.c |
90 | @@ -XXX,XX +XXX,XX @@ | 64 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
91 | #define NPCM7XX_MC_BA (0xf0824000) | 65 | NPCM7XX_UART1_IRQ, |
92 | #define NPCM7XX_RNG_BA (0xf000b000) | 66 | NPCM7XX_UART2_IRQ, |
93 | 67 | NPCM7XX_UART3_IRQ, | |
94 | +/* USB Host modules */ | 68 | + NPCM7XX_EMC1RX_IRQ = 15, |
95 | +#define NPCM7XX_EHCI_BA (0xf0806000) | 69 | + NPCM7XX_EMC1TX_IRQ, |
96 | +#define NPCM7XX_OHCI_BA (0xf0807000) | 70 | NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */ |
71 | NPCM7XX_TIMER1_IRQ, | ||
72 | NPCM7XX_TIMER2_IRQ, | ||
73 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
74 | NPCM7XX_SMBUS15_IRQ, | ||
75 | NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ | ||
76 | NPCM7XX_PWM1_IRQ, /* PWM module 1 */ | ||
77 | + NPCM7XX_EMC2RX_IRQ = 114, | ||
78 | + NPCM7XX_EMC2TX_IRQ, | ||
79 | NPCM7XX_GPIO0_IRQ = 116, | ||
80 | NPCM7XX_GPIO1_IRQ, | ||
81 | NPCM7XX_GPIO2_IRQ, | ||
82 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = { | ||
83 | 0xf008f000, | ||
84 | }; | ||
85 | |||
86 | +/* Register base address for each EMC Module */ | ||
87 | +static const hwaddr npcm7xx_emc_addr[] = { | ||
88 | + 0xf0825000, | ||
89 | + 0xf0826000, | ||
90 | +}; | ||
97 | + | 91 | + |
98 | /* Internal AHB SRAM */ | 92 | static const struct { |
99 | #define NPCM7XX_RAM3_BA (0xc0008000) | 93 | hwaddr regs_addr; |
100 | #define NPCM7XX_RAM3_SZ (4 * KiB) | 94 | uint32_t unconnected_pins; |
101 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
102 | NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ | ||
103 | NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ | ||
104 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
105 | + NPCM7XX_EHCI_IRQ = 61, | ||
106 | + NPCM7XX_OHCI_IRQ = 62, | ||
107 | }; | ||
108 | |||
109 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
110 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | 95 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
111 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | 96 | for (i = 0; i < ARRAY_SIZE(s->pwm); i++) { |
97 | object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM); | ||
112 | } | 98 | } |
113 | |||
114 | + object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
115 | + object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
116 | + | 99 | + |
117 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu)); | 100 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { |
118 | for (i = 0; i < ARRAY_SIZE(s->fiu); i++) { | 101 | + object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC); |
119 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], | 102 | + } |
103 | } | ||
104 | |||
105 | static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
120 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 106 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
121 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | 107 | sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i)); |
122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | 108 | } |
123 | 109 | ||
124 | + /* USB Host */ | 110 | + /* |
125 | + object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | 111 | + * EMC Modules. Cannot fail. |
126 | + &error_abort); | 112 | + * The mapping of the device to its netdev backend works as follows: |
127 | + sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort); | 113 | + * emc[i] = nd_table[i] |
128 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA); | 114 | + * This works around the inability to specify the netdev property for the |
129 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0, | 115 | + * emc device: it's not pluggable and thus the -device option can't be |
130 | + npcm7xx_irq(s, NPCM7XX_EHCI_IRQ)); | 116 | + * used. |
131 | + | 117 | + */ |
132 | + object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0", | 118 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc)); |
133 | + &error_abort); | 119 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2); |
134 | + object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort); | 120 | + for (i = 0; i < ARRAY_SIZE(s->emc); i++) { |
135 | + sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort); | 121 | + s->emc[i].emc_num = i; |
136 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA); | 122 | + SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]); |
137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, | 123 | + if (nd_table[i].used) { |
138 | + npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); | 124 | + qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC); |
125 | + qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]); | ||
126 | + } | ||
127 | + /* | ||
128 | + * The device exists regardless of whether it's connected to a QEMU | ||
129 | + * netdev backend. So always instantiate it even if there is no | ||
130 | + * backend. | ||
131 | + */ | ||
132 | + sysbus_realize(sbd, &error_abort); | ||
133 | + sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]); | ||
134 | + int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ; | ||
135 | + int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ; | ||
136 | + /* | ||
137 | + * N.B. The values for the second argument sysbus_connect_irq are | ||
138 | + * chosen to match the registration order in npcm7xx_emc_realize. | ||
139 | + */ | ||
140 | + sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq)); | ||
141 | + sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq)); | ||
142 | + } | ||
139 | + | 143 | + |
140 | /* | 144 | /* |
141 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | 145 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
142 | * specified, but this is a programming error. | 146 | * specified, but this is a programming error. |
143 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 147 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
144 | create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB); | ||
145 | create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB); | ||
146 | create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB); | ||
147 | - create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB); | ||
148 | - create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); | 148 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); |
150 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); | 149 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); |
151 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); | 150 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); |
152 | diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c | 151 | - create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB); |
153 | index XXXXXXX..XXXXXXX 100644 | 152 | - create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB); |
154 | --- a/hw/usb/hcd-ehci-sysbus.c | 153 | create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB); |
155 | +++ b/hw/usb/hcd-ehci-sysbus.c | 154 | create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB); |
156 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = { | 155 | create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB); |
157 | .class_init = ehci_aw_h3_class_init, | ||
158 | }; | ||
159 | |||
160 | +static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data) | ||
161 | +{ | ||
162 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); | ||
163 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
164 | + | ||
165 | + sec->capsbase = 0x0; | ||
166 | + sec->opregbase = 0x10; | ||
167 | + sec->portscbase = 0x44; | ||
168 | + sec->portnr = 1; | ||
169 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | ||
170 | +} | ||
171 | + | ||
172 | +static const TypeInfo ehci_npcm7xx_type_info = { | ||
173 | + .name = TYPE_NPCM7XX_EHCI, | ||
174 | + .parent = TYPE_SYS_BUS_EHCI, | ||
175 | + .class_init = ehci_npcm7xx_class_init, | ||
176 | +}; | ||
177 | + | ||
178 | static void ehci_tegra2_class_init(ObjectClass *oc, void *data) | ||
179 | { | ||
180 | SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); | ||
181 | @@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void) | ||
182 | type_register_static(&ehci_platform_type_info); | ||
183 | type_register_static(&ehci_exynos4210_type_info); | ||
184 | type_register_static(&ehci_aw_h3_type_info); | ||
185 | + type_register_static(&ehci_npcm7xx_type_info); | ||
186 | type_register_static(&ehci_tegra2_type_info); | ||
187 | type_register_static(&ehci_ppc4xx_type_info); | ||
188 | type_register_static(&ehci_fusbh200_type_info); | ||
189 | -- | 156 | -- |
190 | 2.20.1 | 157 | 2.20.1 |
191 | 158 | ||
192 | 159 | diff view generated by jsdifflib |
1 | From: Hao Wu <wuhaotsh@google.com> | 1 | From: Doug Evans <dje@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The watchdog is part of NPCM7XX's timer module. Its behavior is | 3 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
4 | controlled by the WTCR register in the timer. | 4 | Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com> |
5 | |||
6 | When enabled, the watchdog issues an interrupt signal after a pre-set | ||
7 | amount of cycles, and issues a reset signal shortly after that. | ||
8 | |||
9 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
10 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
11 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | [PMM: deleted blank line at end of npcm_watchdog_timer-test.c] | 6 | Signed-off-by: Doug Evans <dje@google.com> |
7 | Message-id: 20210213002520.1374134-4-dje@google.com | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 9 | --- |
16 | include/hw/misc/npcm7xx_clk.h | 2 + | 10 | tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++ |
17 | include/hw/timer/npcm7xx_timer.h | 48 +++- | 11 | tests/qtest/meson.build | 1 + |
18 | hw/arm/npcm7xx.c | 12 + | 12 | 2 files changed, 863 insertions(+) |
19 | hw/misc/npcm7xx_clk.c | 28 ++ | 13 | create mode 100644 tests/qtest/npcm7xx_emc-test.c |
20 | hw/timer/npcm7xx_timer.c | 266 ++++++++++++++---- | ||
21 | tests/qtest/npcm7xx_watchdog_timer-test.c | 319 ++++++++++++++++++++++ | ||
22 | MAINTAINERS | 1 + | ||
23 | tests/qtest/meson.build | 2 +- | ||
24 | 8 files changed, 624 insertions(+), 54 deletions(-) | ||
25 | create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c | ||
26 | 14 | ||
27 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h | 15 | diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c |
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/hw/misc/npcm7xx_clk.h | ||
30 | +++ b/include/hw/misc/npcm7xx_clk.h | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | */ | ||
33 | #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) | ||
34 | |||
35 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" | ||
36 | + | ||
37 | typedef struct NPCM7xxCLKState { | ||
38 | SysBusDevice parent; | ||
39 | |||
40 | diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/include/hw/timer/npcm7xx_timer.h | ||
43 | +++ b/include/hw/timer/npcm7xx_timer.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | */ | ||
46 | #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) | ||
47 | |||
48 | +/* The basic watchdog timer period is 2^14 clock cycles. */ | ||
49 | +#define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14 | ||
50 | + | ||
51 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out" | ||
52 | + | ||
53 | typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState; | ||
54 | |||
55 | /** | ||
56 | - * struct NPCM7xxTimer - Individual timer state. | ||
57 | - * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
58 | + * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and | ||
59 | + * watchdog timer use. | ||
60 | * @qtimer: QEMU timer that notifies us on expiration. | ||
61 | * @expires_ns: Absolute virtual expiration time. | ||
62 | * @remaining_ns: Remaining time until expiration if timer is paused. | ||
63 | + */ | ||
64 | +typedef struct NPCM7xxBaseTimer { | ||
65 | + QEMUTimer qtimer; | ||
66 | + int64_t expires_ns; | ||
67 | + int64_t remaining_ns; | ||
68 | +} NPCM7xxBaseTimer; | ||
69 | + | ||
70 | +/** | ||
71 | + * struct NPCM7xxTimer - Individual timer state. | ||
72 | + * @ctrl: The timer module that owns this timer. | ||
73 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
74 | + * @base_timer: The basic timer functionality for this timer. | ||
75 | * @tcsr: The Timer Control and Status Register. | ||
76 | * @ticr: The Timer Initial Count Register. | ||
77 | */ | ||
78 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxTimer { | ||
79 | NPCM7xxTimerCtrlState *ctrl; | ||
80 | |||
81 | qemu_irq irq; | ||
82 | - QEMUTimer qtimer; | ||
83 | - int64_t expires_ns; | ||
84 | - int64_t remaining_ns; | ||
85 | + NPCM7xxBaseTimer base_timer; | ||
86 | |||
87 | uint32_t tcsr; | ||
88 | uint32_t ticr; | ||
89 | } NPCM7xxTimer; | ||
90 | |||
91 | +/** | ||
92 | + * struct NPCM7xxWatchdogTimer - The watchdog timer state. | ||
93 | + * @ctrl: The timer module that owns this timer. | ||
94 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
95 | + * @reset_signal: The GPIO used to send a reset signal. | ||
96 | + * @base_timer: The basic timer functionality for this timer. | ||
97 | + * @wtcr: The Watchdog Timer Control Register. | ||
98 | + */ | ||
99 | +typedef struct NPCM7xxWatchdogTimer { | ||
100 | + NPCM7xxTimerCtrlState *ctrl; | ||
101 | + | ||
102 | + qemu_irq irq; | ||
103 | + qemu_irq reset_signal; | ||
104 | + NPCM7xxBaseTimer base_timer; | ||
105 | + | ||
106 | + uint32_t wtcr; | ||
107 | +} NPCM7xxWatchdogTimer; | ||
108 | + | ||
109 | /** | ||
110 | * struct NPCM7xxTimerCtrlState - Timer Module device state. | ||
111 | * @parent: System bus device. | ||
112 | * @iomem: Memory region through which registers are accessed. | ||
113 | + * @index: The index of this timer module. | ||
114 | * @tisr: The Timer Interrupt Status Register. | ||
115 | - * @wtcr: The Watchdog Timer Control Register. | ||
116 | * @timer: The five individual timers managed by this module. | ||
117 | + * @watchdog_timer: The watchdog timer managed by this module. | ||
118 | */ | ||
119 | struct NPCM7xxTimerCtrlState { | ||
120 | SysBusDevice parent; | ||
121 | @@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState { | ||
122 | MemoryRegion iomem; | ||
123 | |||
124 | uint32_t tisr; | ||
125 | - uint32_t wtcr; | ||
126 | |||
127 | NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL]; | ||
128 | + NPCM7xxWatchdogTimer watchdog_timer; | ||
129 | }; | ||
130 | |||
131 | #define TYPE_NPCM7XX_TIMER "npcm7xx-timer" | ||
132 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/hw/arm/npcm7xx.c | ||
135 | +++ b/hw/arm/npcm7xx.c | ||
136 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
137 | NPCM7XX_TIMER12_IRQ, | ||
138 | NPCM7XX_TIMER13_IRQ, | ||
139 | NPCM7XX_TIMER14_IRQ, | ||
140 | + NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ | ||
141 | + NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ | ||
142 | + NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
143 | }; | ||
144 | |||
145 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
146 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
147 | qemu_irq irq = npcm7xx_irq(s, first_irq + j); | ||
148 | sysbus_connect_irq(sbd, j, irq); | ||
149 | } | ||
150 | + | ||
151 | + /* IRQ for watchdogs */ | ||
152 | + sysbus_connect_irq(sbd, NPCM7XX_TIMERS_PER_CTRL, | ||
153 | + npcm7xx_irq(s, NPCM7XX_WDG0_IRQ + i)); | ||
154 | + /* GPIO that connects clk module with watchdog */ | ||
155 | + qdev_connect_gpio_out_named(DEVICE(&s->tim[i]), | ||
156 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 0, | ||
157 | + qdev_get_gpio_in_named(DEVICE(&s->clk), | ||
158 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, i)); | ||
159 | } | ||
160 | |||
161 | /* UART0..3 (16550 compatible) */ | ||
162 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/hw/misc/npcm7xx_clk.c | ||
165 | +++ b/hw/misc/npcm7xx_clk.c | ||
166 | @@ -XXX,XX +XXX,XX @@ | ||
167 | #include "qemu/osdep.h" | ||
168 | |||
169 | #include "hw/misc/npcm7xx_clk.h" | ||
170 | +#include "hw/timer/npcm7xx_timer.h" | ||
171 | #include "migration/vmstate.h" | ||
172 | #include "qemu/error-report.h" | ||
173 | #include "qemu/log.h" | ||
174 | @@ -XXX,XX +XXX,XX @@ | ||
175 | #include "qemu/timer.h" | ||
176 | #include "qemu/units.h" | ||
177 | #include "trace.h" | ||
178 | +#include "sysemu/watchdog.h" | ||
179 | |||
180 | #define PLLCON_LOKI BIT(31) | ||
181 | #define PLLCON_LOKS BIT(30) | ||
182 | @@ -XXX,XX +XXX,XX @@ static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = { | ||
183 | [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, | ||
184 | }; | ||
185 | |||
186 | +/* Register Field Definitions */ | ||
187 | +#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */ | ||
188 | + | ||
189 | +/* The number of watchdogs that can trigger a reset. */ | ||
190 | +#define NPCM7XX_NR_WATCHDOGS (3) | ||
191 | + | ||
192 | static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size) | ||
193 | { | ||
194 | uint32_t reg = offset / sizeof(uint32_t); | ||
195 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset, | ||
196 | s->regs[reg] = value; | ||
197 | } | ||
198 | |||
199 | +/* Perform reset action triggered by a watchdog */ | ||
200 | +static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n, | ||
201 | + int level) | ||
202 | +{ | ||
203 | + NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque); | ||
204 | + uint32_t rcr; | ||
205 | + | ||
206 | + g_assert(n >= 0 && n <= NPCM7XX_NR_WATCHDOGS); | ||
207 | + rcr = clk->regs[NPCM7XX_CLK_WD0RCR + n]; | ||
208 | + if (rcr & NPCM7XX_CLK_WDRCR_CA9C) { | ||
209 | + watchdog_perform_action(); | ||
210 | + } else { | ||
211 | + qemu_log_mask(LOG_UNIMP, | ||
212 | + "%s: only CPU reset is implemented. (requested 0x%" PRIx32")\n", | ||
213 | + __func__, rcr); | ||
214 | + } | ||
215 | +} | ||
216 | + | ||
217 | static const struct MemoryRegionOps npcm7xx_clk_ops = { | ||
218 | .read = npcm7xx_clk_read, | ||
219 | .write = npcm7xx_clk_write, | ||
220 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj) | ||
221 | memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s, | ||
222 | TYPE_NPCM7XX_CLK, 4 * KiB); | ||
223 | sysbus_init_mmio(&s->parent, &s->iomem); | ||
224 | + qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset, | ||
225 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS); | ||
226 | } | ||
227 | |||
228 | static const VMStateDescription vmstate_npcm7xx_clk = { | ||
229 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | ||
230 | index XXXXXXX..XXXXXXX 100644 | ||
231 | --- a/hw/timer/npcm7xx_timer.c | ||
232 | +++ b/hw/timer/npcm7xx_timer.c | ||
233 | @@ -XXX,XX +XXX,XX @@ | ||
234 | #include "qemu/osdep.h" | ||
235 | |||
236 | #include "hw/irq.h" | ||
237 | +#include "hw/qdev-properties.h" | ||
238 | #include "hw/misc/npcm7xx_clk.h" | ||
239 | #include "hw/timer/npcm7xx_timer.h" | ||
240 | #include "migration/vmstate.h" | ||
241 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxTimerRegisters { | ||
242 | #define NPCM7XX_TCSR_PRESCALE_START 0 | ||
243 | #define NPCM7XX_TCSR_PRESCALE_LEN 8 | ||
244 | |||
245 | +#define NPCM7XX_WTCR_WTCLK(rv) extract32(rv, 10, 2) | ||
246 | +#define NPCM7XX_WTCR_FREEZE_EN BIT(9) | ||
247 | +#define NPCM7XX_WTCR_WTE BIT(7) | ||
248 | +#define NPCM7XX_WTCR_WTIE BIT(6) | ||
249 | +#define NPCM7XX_WTCR_WTIS(rv) extract32(rv, 4, 2) | ||
250 | +#define NPCM7XX_WTCR_WTIF BIT(3) | ||
251 | +#define NPCM7XX_WTCR_WTRF BIT(2) | ||
252 | +#define NPCM7XX_WTCR_WTRE BIT(1) | ||
253 | +#define NPCM7XX_WTCR_WTR BIT(0) | ||
254 | + | ||
255 | +/* | ||
256 | + * The number of clock cycles between interrupt and reset in watchdog, used | ||
257 | + * by the software to handle the interrupt before system is reset. | ||
258 | + */ | ||
259 | +#define NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES 1024 | ||
260 | + | ||
261 | +/* Start or resume the timer. */ | ||
262 | +static void npcm7xx_timer_start(NPCM7xxBaseTimer *t) | ||
263 | +{ | ||
264 | + int64_t now; | ||
265 | + | ||
266 | + now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
267 | + t->expires_ns = now + t->remaining_ns; | ||
268 | + timer_mod(&t->qtimer, t->expires_ns); | ||
269 | +} | ||
270 | + | ||
271 | +/* Stop counting. Record the time remaining so we can continue later. */ | ||
272 | +static void npcm7xx_timer_pause(NPCM7xxBaseTimer *t) | ||
273 | +{ | ||
274 | + int64_t now; | ||
275 | + | ||
276 | + timer_del(&t->qtimer); | ||
277 | + now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
278 | + t->remaining_ns = t->expires_ns - now; | ||
279 | +} | ||
280 | + | ||
281 | +/* Delete the timer and reset it to default state. */ | ||
282 | +static void npcm7xx_timer_clear(NPCM7xxBaseTimer *t) | ||
283 | +{ | ||
284 | + timer_del(&t->qtimer); | ||
285 | + t->expires_ns = 0; | ||
286 | + t->remaining_ns = 0; | ||
287 | +} | ||
288 | + | ||
289 | /* | ||
290 | * Returns the index of timer in the tc->timer array. This can be used to | ||
291 | * locate the registers that belong to this timer. | ||
292 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns) | ||
293 | return count; | ||
294 | } | ||
295 | |||
296 | +static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t) | ||
297 | +{ | ||
298 | + switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) { | ||
299 | + case 0: | ||
300 | + return 1; | ||
301 | + case 1: | ||
302 | + return 256; | ||
303 | + case 2: | ||
304 | + return 2048; | ||
305 | + case 3: | ||
306 | + return 65536; | ||
307 | + default: | ||
308 | + g_assert_not_reached(); | ||
309 | + } | ||
310 | +} | ||
311 | + | ||
312 | +static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, | ||
313 | + int64_t cycles) | ||
314 | +{ | ||
315 | + uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t); | ||
316 | + int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles; | ||
317 | + | ||
318 | + /* | ||
319 | + * The reset function always clears the current timer. The caller of the | ||
320 | + * this needs to decide whether to start the watchdog timer based on | ||
321 | + * specific flag in WTCR. | ||
322 | + */ | ||
323 | + npcm7xx_timer_clear(&t->base_timer); | ||
324 | + | ||
325 | + ns *= prescaler; | ||
326 | + t->base_timer.remaining_ns = ns; | ||
327 | +} | ||
328 | + | ||
329 | +static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t) | ||
330 | +{ | ||
331 | + int64_t cycles = 1; | ||
332 | + uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr); | ||
333 | + | ||
334 | + g_assert(s <= 3); | ||
335 | + | ||
336 | + cycles <<= NPCM7XX_WATCHDOG_BASETIME_SHIFT; | ||
337 | + cycles <<= 2 * s; | ||
338 | + | ||
339 | + npcm7xx_watchdog_timer_reset_cycles(t, cycles); | ||
340 | +} | ||
341 | + | ||
342 | /* | ||
343 | * Raise the interrupt line if there's a pending interrupt and interrupts are | ||
344 | * enabled for this timer. If not, lower it. | ||
345 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t) | ||
346 | trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending); | ||
347 | } | ||
348 | |||
349 | -/* Start or resume the timer. */ | ||
350 | -static void npcm7xx_timer_start(NPCM7xxTimer *t) | ||
351 | -{ | ||
352 | - int64_t now; | ||
353 | - | ||
354 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
355 | - t->expires_ns = now + t->remaining_ns; | ||
356 | - timer_mod(&t->qtimer, t->expires_ns); | ||
357 | -} | ||
358 | - | ||
359 | /* | ||
360 | * Called when the counter reaches zero. Sets the interrupt flag, and either | ||
361 | * restarts or disables the timer. | ||
362 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
363 | tc->tisr |= BIT(index); | ||
364 | |||
365 | if (t->tcsr & NPCM7XX_TCSR_PERIODIC) { | ||
366 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
367 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
368 | if (t->tcsr & NPCM7XX_TCSR_CEN) { | ||
369 | - npcm7xx_timer_start(t); | ||
370 | + npcm7xx_timer_start(&t->base_timer); | ||
371 | } | ||
372 | } else { | ||
373 | t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); | ||
374 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
375 | npcm7xx_timer_check_interrupt(t); | ||
376 | } | ||
377 | |||
378 | -/* Stop counting. Record the time remaining so we can continue later. */ | ||
379 | -static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
380 | -{ | ||
381 | - int64_t now; | ||
382 | - | ||
383 | - timer_del(&t->qtimer); | ||
384 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
385 | - t->remaining_ns = t->expires_ns - now; | ||
386 | -} | ||
387 | |||
388 | /* | ||
389 | * Restart the timer from its initial value. If the timer was enabled and stays | ||
390 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
391 | */ | ||
392 | static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) | ||
393 | { | ||
394 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
395 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
396 | |||
397 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
398 | - npcm7xx_timer_start(t); | ||
399 | + npcm7xx_timer_start(&t->base_timer); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) | ||
404 | if (t->tcsr & NPCM7XX_TCSR_CEN) { | ||
405 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
406 | |||
407 | - return npcm7xx_timer_ns_to_count(t, t->expires_ns - now); | ||
408 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.expires_ns - now); | ||
409 | } | ||
410 | |||
411 | - return npcm7xx_timer_ns_to_count(t, t->remaining_ns); | ||
412 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns); | ||
413 | } | ||
414 | |||
415 | static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
416 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
417 | |||
418 | if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) { | ||
419 | /* Recalculate time remaining based on the current TDR value. */ | ||
420 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
421 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
422 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
423 | - npcm7xx_timer_start(t); | ||
424 | + npcm7xx_timer_start(&t->base_timer); | ||
425 | } | ||
426 | } | ||
427 | |||
428 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
429 | if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) { | ||
430 | if (new_tcsr & NPCM7XX_TCSR_CEN) { | ||
431 | t->tcsr |= NPCM7XX_TCSR_CACT; | ||
432 | - npcm7xx_timer_start(t); | ||
433 | + npcm7xx_timer_start(&t->base_timer); | ||
434 | } else { | ||
435 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | ||
436 | - npcm7xx_timer_pause(t); | ||
437 | - if (t->remaining_ns <= 0) { | ||
438 | + npcm7xx_timer_pause(&t->base_timer); | ||
439 | + if (t->base_timer.remaining_ns <= 0) { | ||
440 | npcm7xx_timer_reached_zero(t); | ||
441 | } | ||
442 | } | ||
443 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value) | ||
444 | if (value & (1U << i)) { | ||
445 | npcm7xx_timer_check_interrupt(&s->timer[i]); | ||
446 | } | ||
447 | + | ||
448 | } | ||
449 | } | ||
450 | |||
451 | +static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr) | ||
452 | +{ | ||
453 | + uint32_t old_wtcr = t->wtcr; | ||
454 | + | ||
455 | + /* | ||
456 | + * WTIF and WTRF are cleared by writing 1. Writing 0 makes these bits | ||
457 | + * unchanged. | ||
458 | + */ | ||
459 | + if (new_wtcr & NPCM7XX_WTCR_WTIF) { | ||
460 | + new_wtcr &= ~NPCM7XX_WTCR_WTIF; | ||
461 | + } else if (old_wtcr & NPCM7XX_WTCR_WTIF) { | ||
462 | + new_wtcr |= NPCM7XX_WTCR_WTIF; | ||
463 | + } | ||
464 | + if (new_wtcr & NPCM7XX_WTCR_WTRF) { | ||
465 | + new_wtcr &= ~NPCM7XX_WTCR_WTRF; | ||
466 | + } else if (old_wtcr & NPCM7XX_WTCR_WTRF) { | ||
467 | + new_wtcr |= NPCM7XX_WTCR_WTRF; | ||
468 | + } | ||
469 | + | ||
470 | + t->wtcr = new_wtcr; | ||
471 | + | ||
472 | + if (new_wtcr & NPCM7XX_WTCR_WTR) { | ||
473 | + t->wtcr &= ~NPCM7XX_WTCR_WTR; | ||
474 | + npcm7xx_watchdog_timer_reset(t); | ||
475 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
476 | + npcm7xx_timer_start(&t->base_timer); | ||
477 | + } | ||
478 | + } else if ((old_wtcr ^ new_wtcr) & NPCM7XX_WTCR_WTE) { | ||
479 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
480 | + npcm7xx_timer_start(&t->base_timer); | ||
481 | + } else { | ||
482 | + npcm7xx_timer_pause(&t->base_timer); | ||
483 | + } | ||
484 | + } | ||
485 | + | ||
486 | +} | ||
487 | + | ||
488 | static hwaddr npcm7xx_tcsr_index(hwaddr reg) | ||
489 | { | ||
490 | switch (reg) { | ||
491 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size) | ||
492 | break; | ||
493 | |||
494 | case NPCM7XX_TIMER_WTCR: | ||
495 | - value = s->wtcr; | ||
496 | + value = s->watchdog_timer.wtcr; | ||
497 | break; | ||
498 | |||
499 | default: | ||
500 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write(void *opaque, hwaddr offset, | ||
501 | return; | ||
502 | |||
503 | case NPCM7XX_TIMER_WTCR: | ||
504 | - qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n", | ||
505 | - __func__, value); | ||
506 | + npcm7xx_timer_write_wtcr(&s->watchdog_timer, value); | ||
507 | return; | ||
508 | } | ||
509 | |||
510 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_enter_reset(Object *obj, ResetType type) | ||
511 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
512 | NPCM7xxTimer *t = &s->timer[i]; | ||
513 | |||
514 | - timer_del(&t->qtimer); | ||
515 | - t->expires_ns = 0; | ||
516 | - t->remaining_ns = 0; | ||
517 | + npcm7xx_timer_clear(&t->base_timer); | ||
518 | t->tcsr = 0x00000005; | ||
519 | t->ticr = 0x00000000; | ||
520 | } | ||
521 | |||
522 | s->tisr = 0x00000000; | ||
523 | - s->wtcr = 0x00000400; | ||
524 | + /* | ||
525 | + * Set WTCLK to 1(default) and reset all flags except WTRF. | ||
526 | + * WTRF is not reset during a core domain reset. | ||
527 | + */ | ||
528 | + s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr & | ||
529 | + NPCM7XX_WTCR_WTRF); | ||
530 | +} | ||
531 | + | ||
532 | +static void npcm7xx_watchdog_timer_expired(void *opaque) | ||
533 | +{ | ||
534 | + NPCM7xxWatchdogTimer *t = opaque; | ||
535 | + | ||
536 | + if (t->wtcr & NPCM7XX_WTCR_WTE) { | ||
537 | + if (t->wtcr & NPCM7XX_WTCR_WTIF) { | ||
538 | + if (t->wtcr & NPCM7XX_WTCR_WTRE) { | ||
539 | + t->wtcr |= NPCM7XX_WTCR_WTRF; | ||
540 | + /* send reset signal to CLK module*/ | ||
541 | + qemu_irq_raise(t->reset_signal); | ||
542 | + } | ||
543 | + } else { | ||
544 | + t->wtcr |= NPCM7XX_WTCR_WTIF; | ||
545 | + if (t->wtcr & NPCM7XX_WTCR_WTIE) { | ||
546 | + /* send interrupt */ | ||
547 | + qemu_irq_raise(t->irq); | ||
548 | + } | ||
549 | + npcm7xx_watchdog_timer_reset_cycles(t, | ||
550 | + NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES); | ||
551 | + npcm7xx_timer_start(&t->base_timer); | ||
552 | + } | ||
553 | + } | ||
554 | } | ||
555 | |||
556 | static void npcm7xx_timer_hold_reset(Object *obj) | ||
557 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj) | ||
558 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
559 | qemu_irq_lower(s->timer[i].irq); | ||
560 | } | ||
561 | + qemu_irq_lower(s->watchdog_timer.irq); | ||
562 | } | ||
563 | |||
564 | static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
565 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
566 | NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev); | ||
567 | SysBusDevice *sbd = &s->parent; | ||
568 | int i; | ||
569 | + NPCM7xxWatchdogTimer *w; | ||
570 | |||
571 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
572 | NPCM7xxTimer *t = &s->timer[i]; | ||
573 | t->ctrl = s; | ||
574 | - timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t); | ||
575 | + timer_init_ns(&t->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
576 | + npcm7xx_timer_expired, t); | ||
577 | sysbus_init_irq(sbd, &t->irq); | ||
578 | } | ||
579 | |||
580 | + w = &s->watchdog_timer; | ||
581 | + w->ctrl = s; | ||
582 | + timer_init_ns(&w->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
583 | + npcm7xx_watchdog_timer_expired, w); | ||
584 | + sysbus_init_irq(sbd, &w->irq); | ||
585 | + | ||
586 | memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s, | ||
587 | TYPE_NPCM7XX_TIMER, 4 * KiB); | ||
588 | sysbus_init_mmio(sbd, &s->iomem); | ||
589 | + qdev_init_gpio_out_named(dev, &w->reset_signal, | ||
590 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 1); | ||
591 | } | ||
592 | |||
593 | -static const VMStateDescription vmstate_npcm7xx_timer = { | ||
594 | - .name = "npcm7xx-timer", | ||
595 | +static const VMStateDescription vmstate_npcm7xx_base_timer = { | ||
596 | + .name = "npcm7xx-base-timer", | ||
597 | .version_id = 0, | ||
598 | .minimum_version_id = 0, | ||
599 | .fields = (VMStateField[]) { | ||
600 | - VMSTATE_TIMER(qtimer, NPCM7xxTimer), | ||
601 | - VMSTATE_INT64(expires_ns, NPCM7xxTimer), | ||
602 | - VMSTATE_INT64(remaining_ns, NPCM7xxTimer), | ||
603 | + VMSTATE_TIMER(qtimer, NPCM7xxBaseTimer), | ||
604 | + VMSTATE_INT64(expires_ns, NPCM7xxBaseTimer), | ||
605 | + VMSTATE_INT64(remaining_ns, NPCM7xxBaseTimer), | ||
606 | + VMSTATE_END_OF_LIST(), | ||
607 | + }, | ||
608 | +}; | ||
609 | + | ||
610 | +static const VMStateDescription vmstate_npcm7xx_timer = { | ||
611 | + .name = "npcm7xx-timer", | ||
612 | + .version_id = 1, | ||
613 | + .minimum_version_id = 1, | ||
614 | + .fields = (VMStateField[]) { | ||
615 | + VMSTATE_STRUCT(base_timer, NPCM7xxTimer, | ||
616 | + 0, vmstate_npcm7xx_base_timer, | ||
617 | + NPCM7xxBaseTimer), | ||
618 | VMSTATE_UINT32(tcsr, NPCM7xxTimer), | ||
619 | VMSTATE_UINT32(ticr, NPCM7xxTimer), | ||
620 | VMSTATE_END_OF_LIST(), | ||
621 | }, | ||
622 | }; | ||
623 | |||
624 | -static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
625 | - .name = "npcm7xx-timer-ctrl", | ||
626 | +static const VMStateDescription vmstate_npcm7xx_watchdog_timer = { | ||
627 | + .name = "npcm7xx-watchdog-timer", | ||
628 | .version_id = 0, | ||
629 | .minimum_version_id = 0, | ||
630 | + .fields = (VMStateField[]) { | ||
631 | + VMSTATE_STRUCT(base_timer, NPCM7xxWatchdogTimer, | ||
632 | + 0, vmstate_npcm7xx_base_timer, | ||
633 | + NPCM7xxBaseTimer), | ||
634 | + VMSTATE_UINT32(wtcr, NPCM7xxWatchdogTimer), | ||
635 | + VMSTATE_END_OF_LIST(), | ||
636 | + }, | ||
637 | +}; | ||
638 | + | ||
639 | +static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
640 | + .name = "npcm7xx-timer-ctrl", | ||
641 | + .version_id = 1, | ||
642 | + .minimum_version_id = 1, | ||
643 | .fields = (VMStateField[]) { | ||
644 | VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState), | ||
645 | - VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState), | ||
646 | VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState, | ||
647 | NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer, | ||
648 | NPCM7xxTimer), | ||
649 | + VMSTATE_STRUCT(watchdog_timer, NPCM7xxTimerCtrlState, | ||
650 | + 0, vmstate_npcm7xx_watchdog_timer, | ||
651 | + NPCM7xxWatchdogTimer), | ||
652 | VMSTATE_END_OF_LIST(), | ||
653 | }, | ||
654 | }; | ||
655 | diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c | ||
656 | new file mode 100644 | 16 | new file mode 100644 |
657 | index XXXXXXX..XXXXXXX | 17 | index XXXXXXX..XXXXXXX |
658 | --- /dev/null | 18 | --- /dev/null |
659 | +++ b/tests/qtest/npcm7xx_watchdog_timer-test.c | 19 | +++ b/tests/qtest/npcm7xx_emc-test.c |
660 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ |
661 | +/* | 21 | +/* |
662 | + * QTests for Nuvoton NPCM7xx Timer Watchdog Modules. | 22 | + * QTests for Nuvoton NPCM7xx EMC Modules. |
663 | + * | 23 | + * |
664 | + * Copyright 2020 Google LLC | 24 | + * Copyright 2020 Google LLC |
665 | + * | 25 | + * |
666 | + * This program is free software; you can redistribute it and/or modify it | 26 | + * This program is free software; you can redistribute it and/or modify it |
667 | + * under the terms of the GNU General Public License as published by the | 27 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
673 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 33 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
674 | + * for more details. | 34 | + * for more details. |
675 | + */ | 35 | + */ |
676 | + | 36 | + |
677 | +#include "qemu/osdep.h" | 37 | +#include "qemu/osdep.h" |
678 | +#include "qemu/timer.h" | 38 | +#include "qemu-common.h" |
679 | + | 39 | +#include "libqos/libqos.h" |
680 | +#include "libqos/libqtest.h" | ||
681 | +#include "qapi/qmp/qdict.h" | 40 | +#include "qapi/qmp/qdict.h" |
682 | + | 41 | +#include "qapi/qmp/qnum.h" |
683 | +#define WTCR_OFFSET 0x1c | 42 | +#include "qemu/bitops.h" |
684 | +#define REF_HZ (25000000) | 43 | +#include "qemu/iov.h" |
685 | + | 44 | + |
686 | +/* WTCR bit fields */ | 45 | +/* Name of the emc device. */ |
687 | +#define WTCLK(rv) ((rv) << 10) | 46 | +#define TYPE_NPCM7XX_EMC "npcm7xx-emc" |
688 | +#define WTE BIT(7) | 47 | + |
689 | +#define WTIE BIT(6) | 48 | +/* Timeout for various operations, in seconds. */ |
690 | +#define WTIS(rv) ((rv) << 4) | 49 | +#define TIMEOUT_SECONDS 10 |
691 | +#define WTIF BIT(3) | 50 | + |
692 | +#define WTRF BIT(2) | 51 | +/* Address in memory of the descriptor. */ |
693 | +#define WTRE BIT(1) | 52 | +#define DESC_ADDR (1 << 20) /* 1 MiB */ |
694 | +#define WTR BIT(0) | 53 | + |
695 | + | 54 | +/* Address in memory of the data packet. */ |
696 | +typedef struct Watchdog { | 55 | +#define DATA_ADDR (DESC_ADDR + 4096) |
697 | + int irq; | 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; | ||
698 | + uint64_t base_addr; | 203 | + uint64_t base_addr; |
699 | +} Watchdog; | 204 | +} EMCModule; |
700 | + | 205 | + |
701 | +static const Watchdog watchdog_list[] = { | 206 | +typedef struct TestData { |
207 | + const EMCModule *module; | ||
208 | +} TestData; | ||
209 | + | ||
210 | +static const EMCModule emc_module_list[] = { | ||
702 | + { | 211 | + { |
703 | + .irq = 47, | 212 | + .rx_irq = 15, |
704 | + .base_addr = 0xf0008000 | 213 | + .tx_irq = 16, |
214 | + .base_addr = 0xf0825000 | ||
705 | + }, | 215 | + }, |
706 | + { | 216 | + { |
707 | + .irq = 48, | 217 | + .rx_irq = 114, |
708 | + .base_addr = 0xf0009000 | 218 | + .tx_irq = 115, |
709 | + }, | 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. | ||
327 | + */ | ||
328 | +static bool emc_soft_reset(QTestState *qts, const EMCModule *mod) | ||
329 | +{ | ||
330 | + uint32_t val; | ||
331 | + uint64_t end_time; | ||
332 | + | ||
333 | + emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR); | ||
334 | + | ||
335 | + /* | ||
336 | + * Wait for device to reset as the linux driver does. | ||
337 | + * During reset the AHB reads 0 for all registers. So first wait for | ||
338 | + * something that resets to non-zero, and then wait for SWR becoming 0. | ||
339 | + */ | ||
340 | + end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; | ||
341 | + | ||
342 | + do { | ||
343 | + qtest_clock_step(qts, 100); | ||
344 | + val = emc_read(qts, mod, REG_FFTCR); | ||
345 | + } while (val == 0 && g_get_monotonic_time() < end_time); | ||
346 | + if (val != 0) { | ||
347 | + do { | ||
348 | + qtest_clock_step(qts, 100); | ||
349 | + val = emc_read(qts, mod, REG_MCMDR); | ||
350 | + if ((val & REG_MCMDR_SWR) == 0) { | ||
351 | + /* | ||
352 | + * N.B. The CAMs have been reset here, so macaddr matching of | ||
353 | + * incoming packets will not work. | ||
354 | + */ | ||
355 | + return true; | ||
356 | + } | ||
357 | + } while (g_get_monotonic_time() < end_time); | ||
358 | + } | ||
359 | + | ||
360 | + g_message("%s: Timeout expired", __func__); | ||
361 | + return false; | ||
362 | +} | ||
363 | + | ||
364 | +/* Check emc registers are reset to default value. */ | ||
365 | +static void test_init(gconstpointer test_data) | ||
366 | +{ | ||
367 | + const TestData *td = test_data; | ||
368 | + const EMCModule *mod = td->module; | ||
369 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
370 | + int i; | ||
371 | + | ||
372 | +#define CHECK_REG(regno, value) \ | ||
373 | + do { \ | ||
374 | + g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \ | ||
375 | + } while (0) | ||
376 | + | ||
377 | + CHECK_REG(REG_CAMCMR, 0); | ||
378 | + CHECK_REG(REG_CAMEN, 0); | ||
379 | + CHECK_REG(REG_TXDLSA, 0xfffffffc); | ||
380 | + CHECK_REG(REG_RXDLSA, 0xfffffffc); | ||
381 | + CHECK_REG(REG_MCMDR, 0); | ||
382 | + CHECK_REG(REG_MIID, 0); | ||
383 | + CHECK_REG(REG_MIIDA, 0x00900000); | ||
384 | + CHECK_REG(REG_FFTCR, 0x0101); | ||
385 | + CHECK_REG(REG_DMARFC, 0x0800); | ||
386 | + CHECK_REG(REG_MIEN, 0); | ||
387 | + CHECK_REG(REG_MISTA, 0); | ||
388 | + CHECK_REG(REG_MGSTA, 0); | ||
389 | + CHECK_REG(REG_MPCNT, 0x7fff); | ||
390 | + CHECK_REG(REG_MRPC, 0); | ||
391 | + CHECK_REG(REG_MRPCC, 0); | ||
392 | + CHECK_REG(REG_MREPC, 0); | ||
393 | + CHECK_REG(REG_DMARFS, 0); | ||
394 | + CHECK_REG(REG_CTXDSA, 0); | ||
395 | + CHECK_REG(REG_CTXBSA, 0); | ||
396 | + CHECK_REG(REG_CRXDSA, 0); | ||
397 | + CHECK_REG(REG_CRXBSA, 0); | ||
398 | + | ||
399 | +#undef CHECK_REG | ||
400 | + | ||
401 | + for (i = 0; i < NUM_CAMML_REGS; ++i) { | ||
402 | + g_assert_cmpuint(emc_read(qts, mod, REG_CAMM_BASE + i * 2), ==, | ||
403 | + 0); | ||
404 | + g_assert_cmpuint(emc_read(qts, mod, REG_CAML_BASE + i * 2), ==, | ||
405 | + 0); | ||
406 | + } | ||
407 | + | ||
408 | + qtest_quit(qts); | ||
409 | +} | ||
410 | + | ||
411 | +static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step, | ||
412 | + bool is_tx) | ||
413 | +{ | ||
414 | + uint64_t end_time = | ||
415 | + g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; | ||
416 | + | ||
417 | + do { | ||
418 | + if (qtest_get_irq(qts, is_tx ? mod->tx_irq : mod->rx_irq)) { | ||
419 | + return true; | ||
420 | + } | ||
421 | + qtest_clock_step(qts, step); | ||
422 | + } while (g_get_monotonic_time() < end_time); | ||
423 | + | ||
424 | + g_message("%s: Timeout expired", __func__); | ||
425 | + return false; | ||
426 | +} | ||
427 | + | ||
428 | +static bool emc_wait_mista(QTestState *qts, const EMCModule *mod, int step, | ||
429 | + uint32_t flag) | ||
430 | +{ | ||
431 | + uint64_t end_time = | ||
432 | + g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND; | ||
433 | + | ||
434 | + do { | ||
435 | + uint32_t mista = emc_read(qts, mod, REG_MISTA); | ||
436 | + if (mista & flag) { | ||
437 | + return true; | ||
438 | + } | ||
439 | + qtest_clock_step(qts, step); | ||
440 | + } while (g_get_monotonic_time() < end_time); | ||
441 | + | ||
442 | + g_message("%s: Timeout expired", __func__); | ||
443 | + return false; | ||
444 | +} | ||
445 | + | ||
446 | +static bool wait_socket_readable(int fd) | ||
447 | +{ | ||
448 | + fd_set read_fds; | ||
449 | + struct timeval tv; | ||
450 | + int rv; | ||
451 | + | ||
452 | + FD_ZERO(&read_fds); | ||
453 | + FD_SET(fd, &read_fds); | ||
454 | + tv.tv_sec = TIMEOUT_SECONDS; | ||
455 | + tv.tv_usec = 0; | ||
456 | + rv = select(fd + 1, &read_fds, NULL, NULL, &tv); | ||
457 | + if (rv == -1) { | ||
458 | + perror("select"); | ||
459 | + } else if (rv == 0) { | ||
460 | + g_message("%s: Timeout expired", __func__); | ||
461 | + } | ||
462 | + return rv == 1; | ||
463 | +} | ||
464 | + | ||
465 | +/* Initialize *desc (in host endian format). */ | ||
466 | +static void init_tx_desc(NPCM7xxEMCTxDesc *desc, size_t count, | ||
467 | + uint32_t desc_addr) | ||
468 | +{ | ||
469 | + g_assert(count >= 2); | ||
470 | + memset(&desc[0], 0, sizeof(*desc) * count); | ||
471 | + /* Leave the last one alone, owned by the cpu -> stops transmission. */ | ||
472 | + for (size_t i = 0; i < count - 1; ++i) { | ||
473 | + desc[i].flags = | ||
474 | + (TX_DESC_FLAG_OWNER_MASK | /* owner = 1: emc */ | ||
475 | + TX_DESC_FLAG_INTEN | | ||
476 | + 0 | /* crc append = 0 */ | ||
477 | + 0 /* padding enable = 0 */); | ||
478 | + desc[i].status_and_length = | ||
479 | + (0 | /* collision count = 0 */ | ||
480 | + 0 | /* SQE = 0 */ | ||
481 | + 0 | /* PAU = 0 */ | ||
482 | + 0 | /* TXHA = 0 */ | ||
483 | + 0 | /* LC = 0 */ | ||
484 | + 0 | /* TXABT = 0 */ | ||
485 | + 0 | /* NCS = 0 */ | ||
486 | + 0 | /* EXDEF = 0 */ | ||
487 | + 0 | /* TXCP = 0 */ | ||
488 | + 0 | /* DEF = 0 */ | ||
489 | + 0 | /* TXINTR = 0 */ | ||
490 | + 0 /* length filled in later */); | ||
491 | + desc[i].ntxdsa = desc_addr + (i + 1) * sizeof(*desc); | ||
492 | + } | ||
493 | +} | ||
494 | + | ||
495 | +static void enable_tx(QTestState *qts, const EMCModule *mod, | ||
496 | + const NPCM7xxEMCTxDesc *desc, size_t count, | ||
497 | + uint32_t desc_addr, uint32_t mien_flags) | ||
498 | +{ | ||
499 | + /* Write the descriptors to guest memory. */ | ||
500 | + for (size_t i = 0; i < count; ++i) { | ||
501 | + emc_write_tx_desc(qts, desc + i, desc_addr + i * sizeof(*desc)); | ||
502 | + } | ||
503 | + | ||
504 | + /* Trigger sending the packet. */ | ||
505 | + /* The module must be reset before changing TXDLSA. */ | ||
506 | + g_assert(emc_soft_reset(qts, mod)); | ||
507 | + emc_write(qts, mod, REG_TXDLSA, desc_addr); | ||
508 | + emc_write(qts, mod, REG_CTXDSA, ~0); | ||
509 | + emc_write(qts, mod, REG_MIEN, REG_MIEN_ENTXCP | mien_flags); | ||
710 | + { | 510 | + { |
711 | + .irq = 49, | 511 | + uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR); |
712 | + .base_addr = 0xf000a000 | 512 | + mcmdr |= REG_MCMDR_TXON; |
713 | + } | 513 | + emc_write(qts, mod, REG_MCMDR, mcmdr); |
714 | +}; | 514 | + } |
715 | + | 515 | + |
716 | +static int watchdog_index(const Watchdog *wd) | 516 | + /* Prod the device to send the packet. */ |
717 | +{ | 517 | + emc_write(qts, mod, REG_TSDR, 1); |
718 | + ptrdiff_t diff = wd - watchdog_list; | 518 | +} |
719 | + | 519 | + |
720 | + g_assert(diff >= 0 && diff < ARRAY_SIZE(watchdog_list)); | 520 | +static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd, |
721 | + | 521 | + bool with_irq, uint32_t desc_addr, |
722 | + return diff; | 522 | + uint32_t next_desc_addr, |
723 | +} | 523 | + const char *test_data, int test_size) |
724 | + | 524 | +{ |
725 | +static uint32_t watchdog_read_wtcr(QTestState *qts, const Watchdog *wd) | 525 | + NPCM7xxEMCTxDesc result_desc; |
726 | +{ | 526 | + uint32_t expected_mask, expected_value, recv_len; |
727 | + return qtest_readl(qts, wd->base_addr + WTCR_OFFSET); | 527 | + int ret; |
728 | +} | 528 | + char buffer[TX_DATA_LEN]; |
729 | + | 529 | + |
730 | +static void watchdog_write_wtcr(QTestState *qts, const Watchdog *wd, | 530 | + g_assert(wait_socket_readable(fd)); |
731 | + uint32_t value) | 531 | + |
732 | +{ | 532 | + /* Read the descriptor back. */ |
733 | + qtest_writel(qts, wd->base_addr + WTCR_OFFSET, value); | 533 | + emc_read_tx_desc(qts, desc_addr, &result_desc); |
734 | +} | 534 | + /* Descriptor should be owned by cpu now. */ |
735 | + | 535 | + g_assert((result_desc.flags & TX_DESC_FLAG_OWNER_MASK) == 0); |
736 | +static uint32_t watchdog_prescaler(QTestState *qts, const Watchdog *wd) | 536 | + /* Test the status bits, ignoring the length field. */ |
737 | +{ | 537 | + expected_mask = 0xffff << 16; |
738 | + switch (extract32(watchdog_read_wtcr(qts, wd), 10, 2)) { | 538 | + expected_value = TX_DESC_STATUS_TXCP; |
739 | + case 0: | 539 | + if (with_irq) { |
740 | + return 1; | 540 | + expected_value |= TX_DESC_STATUS_TXINTR; |
741 | + case 1: | 541 | + } |
742 | + return 256; | 542 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, |
743 | + case 2: | 543 | + expected_value); |
744 | + return 2048; | 544 | + |
745 | + case 3: | 545 | + /* Check data sent to the backend. */ |
746 | + return 65536; | 546 | + recv_len = ~0; |
747 | + default: | 547 | + ret = qemu_recv(fd, &recv_len, sizeof(recv_len), MSG_DONTWAIT); |
748 | + g_assert_not_reached(); | 548 | + g_assert_cmpint(ret, == , sizeof(recv_len)); |
749 | + } | 549 | + |
750 | +} | 550 | + g_assert(wait_socket_readable(fd)); |
751 | + | 551 | + memset(buffer, 0xff, sizeof(buffer)); |
752 | +static QDict *get_watchdog_action(QTestState *qts) | 552 | + ret = qemu_recv(fd, buffer, test_size, MSG_DONTWAIT); |
753 | +{ | 553 | + g_assert_cmpmem(buffer, ret, test_data, test_size); |
754 | + QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG"); | 554 | +} |
755 | + QDict *data; | 555 | + |
756 | + | 556 | +static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd, |
757 | + data = qdict_get_qdict(ev, "data"); | 557 | + bool with_irq) |
758 | + qobject_ref(data); | 558 | +{ |
759 | + qobject_unref(ev); | 559 | + NPCM7xxEMCTxDesc desc[NUM_TX_DESCRIPTORS]; |
760 | + return data; | 560 | + uint32_t desc_addr = DESC_ADDR; |
761 | +} | 561 | + static const char test1_data[] = "TEST1"; |
762 | + | 562 | + static const char test2_data[] = "Testing 1 2 3 ..."; |
763 | +#define RESET_CYCLES 1024 | 563 | + uint32_t data1_addr = DATA_ADDR; |
764 | +static uint32_t watchdog_interrupt_cycles(QTestState *qts, const Watchdog *wd) | 564 | + uint32_t data2_addr = data1_addr + sizeof(test1_data); |
765 | +{ | 565 | + bool got_tdu; |
766 | + uint32_t wtis = extract32(watchdog_read_wtcr(qts, wd), 4, 2); | 566 | + uint32_t end_desc_addr; |
767 | + return 1 << (14 + 2 * wtis); | 567 | + |
768 | +} | 568 | + /* Prepare test data buffer. */ |
769 | + | 569 | + qtest_memwrite(qts, data1_addr, test1_data, sizeof(test1_data)); |
770 | +static int64_t watchdog_calculate_steps(uint32_t count, uint32_t prescale) | 570 | + qtest_memwrite(qts, data2_addr, test2_data, sizeof(test2_data)); |
771 | +{ | 571 | + |
772 | + return (NANOSECONDS_PER_SECOND / REF_HZ) * count * prescale; | 572 | + init_tx_desc(&desc[0], NUM_TX_DESCRIPTORS, desc_addr); |
773 | +} | 573 | + desc[0].txbsa = data1_addr; |
774 | + | 574 | + desc[0].status_and_length |= sizeof(test1_data); |
775 | +static int64_t watchdog_interrupt_steps(QTestState *qts, const Watchdog *wd) | 575 | + desc[1].txbsa = data2_addr; |
776 | +{ | 576 | + desc[1].status_and_length |= sizeof(test2_data); |
777 | + return watchdog_calculate_steps(watchdog_interrupt_cycles(qts, wd), | 577 | + |
778 | + watchdog_prescaler(qts, wd)); | 578 | + enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr, |
779 | +} | 579 | + with_irq ? REG_MIEN_ENTXINTR : 0); |
780 | + | 580 | + |
781 | +/* Check wtcr can be reset to default value */ | 581 | + /* |
782 | +static void test_init(gconstpointer watchdog) | 582 | + * It's problematic to observe the interrupt for each packet. |
783 | +{ | 583 | + * Instead just wait until all the packets go out. |
784 | + const Watchdog *wd = watchdog; | 584 | + */ |
785 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | 585 | + got_tdu = false; |
586 | + while (!got_tdu) { | ||
587 | + if (with_irq) { | ||
588 | + g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT, | ||
589 | + /*is_tx=*/true)); | ||
590 | + } else { | ||
591 | + g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT, | ||
592 | + REG_MISTA_TXINTR)); | ||
593 | + } | ||
594 | + got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU); | ||
595 | + /* If we don't have TDU yet, reset the interrupt. */ | ||
596 | + if (!got_tdu) { | ||
597 | + emc_write(qts, mod, REG_MISTA, | ||
598 | + emc_read(qts, mod, REG_MISTA) & 0xffff0000); | ||
599 | + } | ||
600 | + } | ||
601 | + | ||
602 | + end_desc_addr = desc_addr + 2 * sizeof(desc[0]); | ||
603 | + g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr); | ||
604 | + g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==, | ||
605 | + REG_MISTA_TXCP | REG_MISTA_TXINTR | REG_MISTA_TDU); | ||
606 | + | ||
607 | + emc_send_verify1(qts, mod, fd, with_irq, | ||
608 | + desc_addr, end_desc_addr, | ||
609 | + test1_data, sizeof(test1_data)); | ||
610 | + emc_send_verify1(qts, mod, fd, with_irq, | ||
611 | + desc_addr + sizeof(desc[0]), end_desc_addr, | ||
612 | + test2_data, sizeof(test2_data)); | ||
613 | +} | ||
614 | + | ||
615 | +/* Initialize *desc (in host endian format). */ | ||
616 | +static void init_rx_desc(NPCM7xxEMCRxDesc *desc, size_t count, | ||
617 | + uint32_t desc_addr, uint32_t data_addr) | ||
618 | +{ | ||
619 | + g_assert_true(count >= 2); | ||
620 | + memset(desc, 0, sizeof(*desc) * count); | ||
621 | + desc[0].rxbsa = data_addr; | ||
622 | + desc[0].status_and_length = | ||
623 | + (0b10 << RX_DESC_STATUS_OWNER_SHIFT | /* owner = 10: emc */ | ||
624 | + 0 | /* RP = 0 */ | ||
625 | + 0 | /* ALIE = 0 */ | ||
626 | + 0 | /* RXGD = 0 */ | ||
627 | + 0 | /* PTLE = 0 */ | ||
628 | + 0 | /* CRCE = 0 */ | ||
629 | + 0 | /* RXINTR = 0 */ | ||
630 | + 0 /* length (filled in later) */); | ||
631 | + /* Leave the last one alone, owned by the cpu -> stops transmission. */ | ||
632 | + desc[0].nrxdsa = desc_addr + sizeof(*desc); | ||
633 | +} | ||
634 | + | ||
635 | +static void enable_rx(QTestState *qts, const EMCModule *mod, | ||
636 | + const NPCM7xxEMCRxDesc *desc, size_t count, | ||
637 | + uint32_t desc_addr, uint32_t mien_flags, | ||
638 | + uint32_t mcmdr_flags) | ||
639 | +{ | ||
640 | + /* | ||
641 | + * Write the descriptor to guest memory. | ||
642 | + * FWIW, IWBN if the docs said the buffer needs to be at least DMARFC | ||
643 | + * bytes. | ||
644 | + */ | ||
645 | + for (size_t i = 0; i < count; ++i) { | ||
646 | + emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc)); | ||
647 | + } | ||
648 | + | ||
649 | + /* Trigger receiving the packet. */ | ||
650 | + /* The module must be reset before changing RXDLSA. */ | ||
651 | + g_assert(emc_soft_reset(qts, mod)); | ||
652 | + emc_write(qts, mod, REG_RXDLSA, desc_addr); | ||
653 | + emc_write(qts, mod, REG_MIEN, REG_MIEN_ENRXGD | mien_flags); | ||
654 | + | ||
655 | + /* | ||
656 | + * We don't know what the device's macaddr is, so just accept all | ||
657 | + * unicast packets (AUP). | ||
658 | + */ | ||
659 | + emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP); | ||
660 | + emc_write(qts, mod, REG_CAMEN, 1 << 0); | ||
661 | + { | ||
662 | + uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR); | ||
663 | + mcmdr |= REG_MCMDR_RXON | mcmdr_flags; | ||
664 | + emc_write(qts, mod, REG_MCMDR, mcmdr); | ||
665 | + } | ||
666 | + | ||
667 | + /* Prod the device to accept a packet. */ | ||
668 | + emc_write(qts, mod, REG_RSDR, 1); | ||
669 | +} | ||
670 | + | ||
671 | +static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd, | ||
672 | + bool with_irq) | ||
673 | +{ | ||
674 | + NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS]; | ||
675 | + uint32_t desc_addr = DESC_ADDR; | ||
676 | + uint32_t data_addr = DATA_ADDR; | ||
677 | + int ret; | ||
678 | + uint32_t expected_mask, expected_value; | ||
679 | + NPCM7xxEMCRxDesc result_desc; | ||
680 | + | ||
681 | + /* Prepare test data buffer. */ | ||
682 | + const char test[RX_DATA_LEN] = "TEST"; | ||
683 | + int len = htonl(sizeof(test)); | ||
684 | + const struct iovec iov[] = { | ||
685 | + { | ||
686 | + .iov_base = &len, | ||
687 | + .iov_len = sizeof(len), | ||
688 | + },{ | ||
689 | + .iov_base = (char *) test, | ||
690 | + .iov_len = sizeof(test), | ||
691 | + }, | ||
692 | + }; | ||
693 | + | ||
694 | + /* | ||
695 | + * Reset the device BEFORE sending a test packet, otherwise the packet | ||
696 | + * may get swallowed by an active device of an earlier test. | ||
697 | + */ | ||
698 | + init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr); | ||
699 | + enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr, | ||
700 | + with_irq ? REG_MIEN_ENRXINTR : 0, 0); | ||
701 | + | ||
702 | + /* Send test packet to device's socket. */ | ||
703 | + ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test)); | ||
704 | + g_assert_cmpint(ret, == , sizeof(test) + sizeof(len)); | ||
705 | + | ||
706 | + /* Wait for RX interrupt. */ | ||
707 | + if (with_irq) { | ||
708 | + g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false)); | ||
709 | + } else { | ||
710 | + g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD)); | ||
711 | + } | ||
712 | + | ||
713 | + g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==, | ||
714 | + desc_addr + sizeof(desc[0])); | ||
715 | + | ||
716 | + expected_mask = 0xffff; | ||
717 | + expected_value = (REG_MISTA_DENI | | ||
718 | + REG_MISTA_RXGD | | ||
719 | + REG_MISTA_RXINTR); | ||
720 | + g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask), | ||
721 | + ==, expected_value); | ||
722 | + | ||
723 | + /* Read the descriptor back. */ | ||
724 | + emc_read_rx_desc(qts, desc_addr, &result_desc); | ||
725 | + /* Descriptor should be owned by cpu now. */ | ||
726 | + g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0); | ||
727 | + /* Test the status bits, ignoring the length field. */ | ||
728 | + expected_mask = 0xffff << 16; | ||
729 | + expected_value = RX_DESC_STATUS_RXGD; | ||
730 | + if (with_irq) { | ||
731 | + expected_value |= RX_DESC_STATUS_RXINTR; | ||
732 | + } | ||
733 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, | ||
734 | + expected_value); | ||
735 | + g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==, | ||
736 | + RX_DATA_LEN + CRC_LENGTH); | ||
737 | + | ||
738 | + { | ||
739 | + char buffer[RX_DATA_LEN]; | ||
740 | + qtest_memread(qts, data_addr, buffer, sizeof(buffer)); | ||
741 | + g_assert_cmpstr(buffer, == , "TEST"); | ||
742 | + } | ||
743 | +} | ||
744 | + | ||
745 | +static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd) | ||
746 | +{ | ||
747 | + NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS]; | ||
748 | + uint32_t desc_addr = DESC_ADDR; | ||
749 | + uint32_t data_addr = DATA_ADDR; | ||
750 | + int ret; | ||
751 | + NPCM7xxEMCRxDesc result_desc; | ||
752 | + uint32_t expected_mask, expected_value; | ||
753 | + | ||
754 | + /* Prepare test data buffer. */ | ||
755 | +#define PTLE_DATA_LEN 1600 | ||
756 | + char test_data[PTLE_DATA_LEN]; | ||
757 | + int len = htonl(sizeof(test_data)); | ||
758 | + const struct iovec iov[] = { | ||
759 | + { | ||
760 | + .iov_base = &len, | ||
761 | + .iov_len = sizeof(len), | ||
762 | + },{ | ||
763 | + .iov_base = (char *) test_data, | ||
764 | + .iov_len = sizeof(test_data), | ||
765 | + }, | ||
766 | + }; | ||
767 | + memset(test_data, 42, sizeof(test_data)); | ||
768 | + | ||
769 | + /* | ||
770 | + * Reset the device BEFORE sending a test packet, otherwise the packet | ||
771 | + * may get swallowed by an active device of an earlier test. | ||
772 | + */ | ||
773 | + init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr); | ||
774 | + enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr, | ||
775 | + REG_MIEN_ENRXINTR, REG_MCMDR_ALP); | ||
776 | + | ||
777 | + /* Send test packet to device's socket. */ | ||
778 | + ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test_data)); | ||
779 | + g_assert_cmpint(ret, == , sizeof(test_data) + sizeof(len)); | ||
780 | + | ||
781 | + /* Wait for RX interrupt. */ | ||
782 | + g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false)); | ||
783 | + | ||
784 | + /* Read the descriptor back. */ | ||
785 | + emc_read_rx_desc(qts, desc_addr, &result_desc); | ||
786 | + /* Descriptor should be owned by cpu now. */ | ||
787 | + g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0); | ||
788 | + /* Test the status bits, ignoring the length field. */ | ||
789 | + expected_mask = 0xffff << 16; | ||
790 | + expected_value = (RX_DESC_STATUS_RXGD | | ||
791 | + RX_DESC_STATUS_PTLE | | ||
792 | + RX_DESC_STATUS_RXINTR); | ||
793 | + g_assert_cmphex((result_desc.status_and_length & expected_mask), ==, | ||
794 | + expected_value); | ||
795 | + g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==, | ||
796 | + PTLE_DATA_LEN + CRC_LENGTH); | ||
797 | + | ||
798 | + { | ||
799 | + char buffer[PTLE_DATA_LEN]; | ||
800 | + qtest_memread(qts, data_addr, buffer, sizeof(buffer)); | ||
801 | + g_assert(memcmp(buffer, test_data, PTLE_DATA_LEN) == 0); | ||
802 | + } | ||
803 | +} | ||
804 | + | ||
805 | +static void test_tx(gconstpointer test_data) | ||
806 | +{ | ||
807 | + const TestData *td = test_data; | ||
808 | + GString *cmd_line = g_string_new("-machine quanta-gsj"); | ||
809 | + int *test_sockets = packet_test_init(emc_module_index(td->module), | ||
810 | + cmd_line); | ||
811 | + QTestState *qts = qtest_init(cmd_line->str); | ||
812 | + | ||
813 | + /* | ||
814 | + * TODO: For pedantic correctness test_sockets[0] should be closed after | ||
815 | + * the fork and before the exec, but that will require some harness | ||
816 | + * improvements. | ||
817 | + */ | ||
818 | + close(test_sockets[1]); | ||
819 | + /* Defensive programming */ | ||
820 | + test_sockets[1] = -1; | ||
786 | + | 821 | + |
787 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | 822 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
788 | + | 823 | + |
789 | + watchdog_write_wtcr(qts, wd, WTCLK(1) | WTRF | WTIF | WTR); | 824 | + emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/false); |
790 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1)); | 825 | + emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/true); |
791 | + | 826 | + |
792 | + qtest_quit(qts); | 827 | + qtest_quit(qts); |
793 | +} | 828 | +} |
794 | + | 829 | + |
795 | +/* Check a watchdog can generate interrupt and reset actions */ | 830 | +static void test_rx(gconstpointer test_data) |
796 | +static void test_reset_action(gconstpointer watchdog) | 831 | +{ |
797 | +{ | 832 | + const TestData *td = test_data; |
798 | + const Watchdog *wd = watchdog; | 833 | + GString *cmd_line = g_string_new("-machine quanta-gsj"); |
799 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | 834 | + int *test_sockets = packet_test_init(emc_module_index(td->module), |
800 | + QDict *ad; | 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; | ||
801 | + | 846 | + |
802 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | 847 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
803 | + | 848 | + |
804 | + watchdog_write_wtcr(qts, wd, | 849 | + emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false); |
805 | + WTCLK(0) | WTE | WTRF | WTRE | WTIF | WTIE | WTR); | 850 | + emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true); |
806 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | 851 | + emc_test_ptle(qts, td->module, test_sockets[0]); |
807 | + WTCLK(0) | WTE | WTRE | WTIE); | 852 | + |
808 | + | ||
809 | + /* Check a watchdog can generate an interrupt */ | ||
810 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
811 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | ||
812 | + WTCLK(0) | WTE | WTIF | WTIE | WTRE); | ||
813 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
814 | + | ||
815 | + /* Check a watchdog can generate a reset signal */ | ||
816 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
817 | + watchdog_prescaler(qts, wd))); | ||
818 | + ad = get_watchdog_action(qts); | ||
819 | + /* The signal is a reset signal */ | ||
820 | + g_assert_false(strcmp(qdict_get_str(ad, "action"), "reset")); | ||
821 | + qobject_unref(ad); | ||
822 | + qtest_qmp_eventwait(qts, "RESET"); | ||
823 | + /* | ||
824 | + * Make sure WTCR is reset to default except for WTRF bit which shouldn't | ||
825 | + * be reset. | ||
826 | + */ | ||
827 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1) | WTRF); | ||
828 | + qtest_quit(qts); | 853 | + qtest_quit(qts); |
829 | +} | 854 | +} |
830 | + | 855 | + |
831 | +/* Check a watchdog works with all possible WTCLK prescalers and WTIS cycles */ | 856 | +static void emc_add_test(const char *name, const TestData* td, |
832 | +static void test_prescaler(gconstpointer watchdog) | 857 | + GTestDataFunc fn) |
833 | +{ | ||
834 | + const Watchdog *wd = watchdog; | ||
835 | + | ||
836 | + for (int wtclk = 0; wtclk < 4; ++wtclk) { | ||
837 | + for (int wtis = 0; wtis < 4; ++wtis) { | ||
838 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
839 | + | ||
840 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
841 | + watchdog_write_wtcr(qts, wd, | ||
842 | + WTCLK(wtclk) | WTE | WTIF | WTIS(wtis) | WTIE | WTR); | ||
843 | + /* | ||
844 | + * The interrupt doesn't fire until watchdog_interrupt_steps() | ||
845 | + * cycles passed | ||
846 | + */ | ||
847 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd) - 1); | ||
848 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTIF); | ||
849 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
850 | + qtest_clock_step(qts, 1); | ||
851 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
852 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
853 | + | ||
854 | + qtest_quit(qts); | ||
855 | + } | ||
856 | + } | ||
857 | +} | ||
858 | + | ||
859 | +/* | ||
860 | + * Check a watchdog doesn't fire if corresponding flags (WTIE and WTRE) are not | ||
861 | + * set. | ||
862 | + */ | ||
863 | +static void test_enabling_flags(gconstpointer watchdog) | ||
864 | +{ | ||
865 | + const Watchdog *wd = watchdog; | ||
866 | + QTestState *qts; | ||
867 | + | ||
868 | + /* Neither WTIE or WTRE is set, no interrupt or reset should happen */ | ||
869 | + qts = qtest_init("-machine quanta-gsj"); | ||
870 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
871 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRF | WTR); | ||
872 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
873 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
874 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
875 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
876 | + watchdog_prescaler(qts, wd))); | ||
877 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
878 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); | ||
879 | + qtest_quit(qts); | ||
880 | + | ||
881 | + /* Only WTIE is set, interrupt is triggered but reset should not happen */ | ||
882 | + qts = qtest_init("-machine quanta-gsj"); | ||
883 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
884 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); | ||
885 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
886 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
887 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
888 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
889 | + watchdog_prescaler(qts, wd))); | ||
890 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
891 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); | ||
892 | + qtest_quit(qts); | ||
893 | + | ||
894 | + /* Only WTRE is set, interrupt is triggered but reset should not happen */ | ||
895 | + qts = qtest_init("-machine quanta-gsj"); | ||
896 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
897 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRE | WTRF | WTR); | ||
898 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
899 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
900 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
901 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
902 | + watchdog_prescaler(qts, wd))); | ||
903 | + g_assert_false(strcmp(qdict_get_str(get_watchdog_action(qts), "action"), | ||
904 | + "reset")); | ||
905 | + qtest_qmp_eventwait(qts, "RESET"); | ||
906 | + qtest_quit(qts); | ||
907 | + | ||
908 | + /* | ||
909 | + * The case when both flags are set is already tested in | ||
910 | + * test_reset_action(). | ||
911 | + */ | ||
912 | +} | ||
913 | + | ||
914 | +/* Check a watchdog can pause and resume by setting WTE bits */ | ||
915 | +static void test_pause(gconstpointer watchdog) | ||
916 | +{ | ||
917 | + const Watchdog *wd = watchdog; | ||
918 | + QTestState *qts; | ||
919 | + int64_t remaining_steps, steps; | ||
920 | + | ||
921 | + qts = qtest_init("-machine quanta-gsj"); | ||
922 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
923 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); | ||
924 | + remaining_steps = watchdog_interrupt_steps(qts, wd); | ||
925 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); | ||
926 | + | ||
927 | + /* Run for half of the execution period. */ | ||
928 | + steps = remaining_steps / 2; | ||
929 | + remaining_steps -= steps; | ||
930 | + qtest_clock_step(qts, steps); | ||
931 | + | ||
932 | + /* Pause the watchdog */ | ||
933 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTIE); | ||
934 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); | ||
935 | + | ||
936 | + /* Run for a long period of time, the watchdog shouldn't fire */ | ||
937 | + qtest_clock_step(qts, steps << 4); | ||
938 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); | ||
939 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
940 | + | ||
941 | + /* Resume the watchdog */ | ||
942 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIE); | ||
943 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); | ||
944 | + | ||
945 | + /* Run for the reset of the execution period, the watchdog should fire */ | ||
946 | + qtest_clock_step(qts, remaining_steps); | ||
947 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | ||
948 | + WTCLK(0) | WTE | WTIF | WTIE); | ||
949 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
950 | + | ||
951 | + qtest_quit(qts); | ||
952 | +} | ||
953 | + | ||
954 | +static void watchdog_add_test(const char *name, const Watchdog* wd, | ||
955 | + GTestDataFunc fn) | ||
956 | +{ | 858 | +{ |
957 | + g_autofree char *full_name = g_strdup_printf( | 859 | + g_autofree char *full_name = g_strdup_printf( |
958 | + "npcm7xx_watchdog_timer[%d]/%s", watchdog_index(wd), name); | 860 | + "npcm7xx_emc/emc[%d]/%s", emc_module_index(td->module), name); |
959 | + qtest_add_data_func(full_name, wd, fn); | 861 | + qtest_add_data_func(full_name, td, fn); |
960 | +} | 862 | +} |
961 | +#define add_test(name, td) watchdog_add_test(#name, td, test_##name) | 863 | +#define add_test(name, td) emc_add_test(#name, td, test_##name) |
962 | + | 864 | + |
963 | +int main(int argc, char **argv) | 865 | +int main(int argc, char **argv) |
964 | +{ | 866 | +{ |
867 | + TestData test_data_list[ARRAY_SIZE(emc_module_list)]; | ||
868 | + | ||
965 | + g_test_init(&argc, &argv, NULL); | 869 | + g_test_init(&argc, &argv, NULL); |
966 | + g_test_set_nonfatal_assertions(); | 870 | + |
967 | + | 871 | + for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) { |
968 | + for (int i = 0; i < ARRAY_SIZE(watchdog_list); ++i) { | 872 | + TestData *td = &test_data_list[i]; |
969 | + const Watchdog *wd = &watchdog_list[i]; | 873 | + |
970 | + | 874 | + td->module = &emc_module_list[i]; |
971 | + add_test(init, wd); | 875 | + |
972 | + add_test(reset_action, wd); | 876 | + add_test(init, td); |
973 | + add_test(prescaler, wd); | 877 | + add_test(tx, td); |
974 | + add_test(enabling_flags, wd); | 878 | + add_test(rx, td); |
975 | + add_test(pause, wd); | ||
976 | + } | 879 | + } |
977 | + | 880 | + |
978 | + return g_test_run(); | 881 | + return g_test_run(); |
979 | +} | 882 | +} |
980 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
981 | index XXXXXXX..XXXXXXX 100644 | ||
982 | --- a/MAINTAINERS | ||
983 | +++ b/MAINTAINERS | ||
984 | @@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org | ||
985 | S: Supported | ||
986 | F: hw/*/npcm7xx* | ||
987 | F: include/hw/*/npcm7xx* | ||
988 | +F: tests/qtest/npcm7xx* | ||
989 | F: pc-bios/npcm7xx_bootrom.bin | ||
990 | F: roms/vbootrom | ||
991 | |||
992 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 883 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
993 | index XXXXXXX..XXXXXXX 100644 | 884 | index XXXXXXX..XXXXXXX 100644 |
994 | --- a/tests/qtest/meson.build | 885 | --- a/tests/qtest/meson.build |
995 | +++ b/tests/qtest/meson.build | 886 | +++ b/tests/qtest/meson.build |
996 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | 887 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ |
997 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | 888 | |
998 | ['prom-env-test', 'boot-serial-test'] | 889 | qtests_npcm7xx = \ |
999 | 890 | ['npcm7xx_adc-test', | |
1000 | -qtests_npcm7xx = ['npcm7xx_timer-test'] | 891 | + 'npcm7xx_emc-test', |
1001 | +qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | 892 | 'npcm7xx_gpio-test', |
1002 | qtests_arm = \ | 893 | 'npcm7xx_pwm-test', |
1003 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | 894 | 'npcm7xx_rng-test', |
1004 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
1005 | -- | 895 | -- |
1006 | 2.20.1 | 896 | 2.20.1 |
1007 | 897 | ||
1008 | 898 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zenghui Yu <yuzenghui@huawei.com> | ||
2 | 1 | ||
3 | Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA | ||
4 | translation can work properly during migration. | ||
5 | |||
6 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
7 | Message-id: 20201019091508.197-1-yuzenghui@huawei.com | ||
8 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/arm/smmuv3.c | 1 + | ||
12 | 1 file changed, 1 insertion(+) | ||
13 | |||
14 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/arm/smmuv3.c | ||
17 | +++ b/hw/arm/smmuv3.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = { | ||
19 | .name = "smmuv3", | ||
20 | .version_id = 1, | ||
21 | .minimum_version_id = 1, | ||
22 | + .priority = MIG_PRI_IOMMU, | ||
23 | .fields = (VMStateField[]) { | ||
24 | VMSTATE_UINT32(features, SMMUv3State), | ||
25 | VMSTATE_UINT8(sid_size, SMMUv3State), | ||
26 | -- | ||
27 | 2.20.1 | ||
28 | |||
29 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | No code out of bcm2836.c uses (or requires) the BCM283XInfo | ||
4 | declarations. Move it locally to the C source file. | ||
5 | |||
6 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20201024170127.3592182-2-f4bug@amsat.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | include/hw/arm/bcm2836.h | 8 -------- | ||
12 | hw/arm/bcm2836.c | 14 ++++++++++++++ | ||
13 | 2 files changed, 14 insertions(+), 8 deletions(-) | ||
14 | |||
15 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/hw/arm/bcm2836.h | ||
18 | +++ b/include/hw/arm/bcm2836.h | ||
19 | @@ -XXX,XX +XXX,XX @@ struct BCM283XState { | ||
20 | BCM2835PeripheralState peripherals; | ||
21 | }; | ||
22 | |||
23 | -typedef struct BCM283XInfo BCM283XInfo; | ||
24 | - | ||
25 | -struct BCM283XClass { | ||
26 | - DeviceClass parent_class; | ||
27 | - const BCM283XInfo *info; | ||
28 | -}; | ||
29 | - | ||
30 | - | ||
31 | #endif /* BCM2836_H */ | ||
32 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/hw/arm/bcm2836.c | ||
35 | +++ b/hw/arm/bcm2836.c | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #include "hw/arm/raspi_platform.h" | ||
38 | #include "hw/sysbus.h" | ||
39 | |||
40 | +typedef struct BCM283XInfo BCM283XInfo; | ||
41 | + | ||
42 | +typedef struct BCM283XClass { | ||
43 | + /*< private >*/ | ||
44 | + DeviceClass parent_class; | ||
45 | + /*< public >*/ | ||
46 | + const BCM283XInfo *info; | ||
47 | +} BCM283XClass; | ||
48 | + | ||
49 | struct BCM283XInfo { | ||
50 | const char *name; | ||
51 | const char *cpu_type; | ||
52 | @@ -XXX,XX +XXX,XX @@ struct BCM283XInfo { | ||
53 | int clusterid; | ||
54 | }; | ||
55 | |||
56 | +#define BCM283X_CLASS(klass) \ | ||
57 | + OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) | ||
58 | +#define BCM283X_GET_CLASS(obj) \ | ||
59 | + OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | ||
60 | + | ||
61 | static const BCM283XInfo bcm283x_socs[] = { | ||
62 | { | ||
63 | .name = TYPE_BCM2836, | ||
64 | -- | ||
65 | 2.20.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | The BCM2835 has only one core. Introduce the core_count field to | ||
4 | be able to use values different than BCM283X_NCPUS (4). | ||
5 | |||
6 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20201024170127.3592182-4-f4bug@amsat.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/arm/bcm2836.c | 5 ++++- | ||
12 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/arm/bcm2836.c | ||
17 | +++ b/hw/arm/bcm2836.c | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { | ||
19 | /*< public >*/ | ||
20 | const char *name; | ||
21 | const char *cpu_type; | ||
22 | + unsigned core_count; | ||
23 | hwaddr peri_base; /* Peripheral base address seen by the CPU */ | ||
24 | hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ | ||
25 | int clusterid; | ||
26 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
27 | BCM283XClass *bc = BCM283X_GET_CLASS(obj); | ||
28 | int n; | ||
29 | |||
30 | - for (n = 0; n < BCM283X_NCPUS; n++) { | ||
31 | + for (n = 0; n < bc->core_count; n++) { | ||
32 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, | ||
33 | bc->cpu_type); | ||
34 | } | ||
35 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
36 | BCM283XClass *bc = BCM283X_CLASS(oc); | ||
37 | |||
38 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); | ||
39 | + bc->core_count = BCM283X_NCPUS; | ||
40 | bc->peri_base = 0x3f000000; | ||
41 | bc->ctrl_base = 0x40000000; | ||
42 | bc->clusterid = 0xf; | ||
43 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
44 | BCM283XClass *bc = BCM283X_CLASS(oc); | ||
45 | |||
46 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | ||
47 | + bc->core_count = BCM283X_NCPUS; | ||
48 | bc->peri_base = 0x3f000000; | ||
49 | bc->ctrl_base = 0x40000000; | ||
50 | bc->clusterid = 0x0; | ||
51 | -- | ||
52 | 2.20.1 | ||
53 | |||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | The Pi A is almost the first machine released. | ||
4 | It uses a BCM2835 SoC which includes a ARMv6Z core. | ||
5 | |||
6 | Example booting the machine using content from [*] | ||
7 | (we use the device tree from the B model): | ||
8 | |||
9 | $ qemu-system-arm -M raspi1ap -serial stdio \ | ||
10 | -kernel raspberrypi/firmware/boot/kernel.img \ | ||
11 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-b-plus.dtb \ | ||
12 | -append 'earlycon=pl011,0x20201000 console=ttyAMA0' | ||
13 | [ 0.000000] Booting Linux on physical CPU 0x0 | ||
14 | [ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020 | ||
15 | [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d | ||
16 | [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache | ||
17 | [ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B+ | ||
18 | ... | ||
19 | |||
20 | [*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb | ||
21 | |||
22 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
23 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Message-id: 20201024170127.3592182-8-f4bug@amsat.org | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | --- | ||
27 | hw/arm/raspi.c | 13 +++++++++++++ | ||
28 | 1 file changed, 13 insertions(+) | ||
29 | |||
30 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/arm/raspi.c | ||
33 | +++ b/hw/arm/raspi.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, | ||
35 | mc->default_ram_id = "ram"; | ||
36 | }; | ||
37 | |||
38 | +static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) | ||
39 | +{ | ||
40 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
41 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
42 | + | ||
43 | + rmc->board_rev = 0x900021; /* Revision 1.1 */ | ||
44 | + raspi_machine_class_common_init(mc, rmc->board_rev); | ||
45 | +}; | ||
46 | + | ||
47 | static void raspi2b_machine_class_init(ObjectClass *oc, void *data) | ||
48 | { | ||
49 | MachineClass *mc = MACHINE_CLASS(oc); | ||
50 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | ||
51 | |||
52 | static const TypeInfo raspi_machine_types[] = { | ||
53 | { | ||
54 | + .name = MACHINE_TYPE_NAME("raspi1ap"), | ||
55 | + .parent = TYPE_RASPI_MACHINE, | ||
56 | + .class_init = raspi1ap_machine_class_init, | ||
57 | + }, { | ||
58 | .name = MACHINE_TYPE_NAME("raspi2b"), | ||
59 | .parent = TYPE_RASPI_MACHINE, | ||
60 | .class_init = raspi2b_machine_class_init, | ||
61 | -- | ||
62 | 2.20.1 | ||
63 | |||
64 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core). | ||
4 | |||
5 | The only difference between the revision 1.2 and 1.3 is the latter | ||
6 | exposes a CSI camera connector. As we do not implement the Unicam | ||
7 | peripheral, there is no point in exposing a camera connector :) | ||
8 | Therefore we choose to model the 1.2 revision. | ||
9 | |||
10 | Example booting the machine using content from [*]: | ||
11 | |||
12 | $ qemu-system-arm -M raspi0 -serial stdio \ | ||
13 | -kernel raspberrypi/firmware/boot/kernel.img \ | ||
14 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-zero.dtb \ | ||
15 | -append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0' | ||
16 | [ 0.000000] Booting Linux on physical CPU 0x0 | ||
17 | [ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020 | ||
18 | [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d | ||
19 | [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache | ||
20 | [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero | ||
21 | ... | ||
22 | |||
23 | [*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb | ||
24 | |||
25 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
26 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
27 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
28 | Message-id: 20201024170127.3592182-9-f4bug@amsat.org | ||
29 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
30 | --- | ||
31 | hw/arm/raspi.c | 13 +++++++++++++ | ||
32 | 1 file changed, 13 insertions(+) | ||
33 | |||
34 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/arm/raspi.c | ||
37 | +++ b/hw/arm/raspi.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, | ||
39 | mc->default_ram_id = "ram"; | ||
40 | }; | ||
41 | |||
42 | +static void raspi0_machine_class_init(ObjectClass *oc, void *data) | ||
43 | +{ | ||
44 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
45 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
46 | + | ||
47 | + rmc->board_rev = 0x920092; /* Revision 1.2 */ | ||
48 | + raspi_machine_class_common_init(mc, rmc->board_rev); | ||
49 | +}; | ||
50 | + | ||
51 | static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) | ||
52 | { | ||
53 | MachineClass *mc = MACHINE_CLASS(oc); | ||
54 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | ||
55 | |||
56 | static const TypeInfo raspi_machine_types[] = { | ||
57 | { | ||
58 | + .name = MACHINE_TYPE_NAME("raspi0"), | ||
59 | + .parent = TYPE_RASPI_MACHINE, | ||
60 | + .class_init = raspi0_machine_class_init, | ||
61 | + }, { | ||
62 | .name = MACHINE_TYPE_NAME("raspi1ap"), | ||
63 | .parent = TYPE_RASPI_MACHINE, | ||
64 | .class_init = raspi1ap_machine_class_init, | ||
65 | -- | ||
66 | 2.20.1 | ||
67 | |||
68 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | In ptimer_reload(), we call the callback function provided by the | ||
2 | timer device that is using the ptimer. This callback might disable | ||
3 | the ptimer. The code mostly handles this correctly, except that | ||
4 | we'll still print the warning about "Timer with delta zero, | ||
5 | disabling" if the now-disabled timer happened to be set such that it | ||
6 | would fire again immediately if it were enabled (eg because the | ||
7 | limit/reload value is zero). | ||
8 | 1 | ||
9 | Suppress the spurious warning message and the unnecessary | ||
10 | repeat-deletion of the underlying timer in this case. | ||
11 | |||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Message-id: 20201015151829.14656-2-peter.maydell@linaro.org | ||
15 | --- | ||
16 | hw/core/ptimer.c | 4 ++++ | ||
17 | 1 file changed, 4 insertions(+) | ||
18 | |||
19 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/core/ptimer.c | ||
22 | +++ b/hw/core/ptimer.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) | ||
24 | } | ||
25 | |||
26 | if (delta == 0) { | ||
27 | + if (s->enabled == 0) { | ||
28 | + /* trigger callback disabled the timer already */ | ||
29 | + return; | ||
30 | + } | ||
31 | if (!qtest_enabled()) { | ||
32 | fprintf(stderr, "Timer with delta zero, disabling\n"); | ||
33 | } | ||
34 | -- | ||
35 | 2.20.1 | ||
36 | |||
37 | diff view generated by jsdifflib |