1 | Last minute pullreq for arm related patches; quite large because | 1 | Arm queue; not huge but I figured I might as well send it out since |
---|---|---|---|
2 | there were several series that only just made it through code review | 2 | I've been doing code review today and there's no queue of unprocessed |
3 | in time. | 3 | pullreqs... |
4 | 4 | ||
5 | thanks | 5 | thanks |
6 | -- PMM | 6 | -- PMM |
7 | 7 | ||
8 | The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99: | 8 | The following changes since commit b3f846c59d8405bb87c551187721fc92ff2f1b92: |
9 | 9 | ||
10 | Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000) | 10 | Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2021-01-11v2' into staging (2021-01-11 15:15:35 +0000) |
11 | 11 | ||
12 | are available in the Git repository at: | 12 | are available in the Git repository at: |
13 | 13 | ||
14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210112 |
15 | 15 | ||
16 | for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb: | 16 | for you to fetch changes up to 19d131395ccaf503db21dadd8257e6dc9fc1d7de: |
17 | 17 | ||
18 | hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000) | 18 | ui/cocoa: Fix openFile: deprecation on Big Sur (2021-01-12 11:38:37 +0000) |
19 | 19 | ||
20 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
21 | target-arm queue: | 21 | target-arm queue: |
22 | * raspi: add model of cprman clock manager | 22 | * arm: Support emulation of ARMv8.4-TTST extension |
23 | * sbsa-ref: add an SBSA generic watchdog device | 23 | * arm: Update cpu.h ID register field definitions |
24 | * arm/trace: Fix hex printing | 24 | * arm: Fix breakage of XScale instruction emulation |
25 | * raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+ | 25 | * hw/net/lan9118: Fix RX Status FIFO PEEK value |
26 | * hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | 26 | * npcm7xx: Add ADC and PWM emulation |
27 | * Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support | 27 | * ui/cocoa: Make "open docs" help menu entry work again when binary |
28 | * hw/arm: fix min_cpus for xlnx-versal-virt platform | 28 | is run from the build tree |
29 | * hw/arm/highbank: Silence warnings about missing fallthrough statements | 29 | * ui/cocoa: Fix openFile: deprecation on Big Sur |
30 | * linux-user: Support Aarch64 BTI | 30 | * docs: Add qemu-storage-daemon(1) manpage to meson.build |
31 | * Armv7M systick: fix corner case bugs by rewriting to use ptimer | 31 | * docs: Build and install all the docs in a single manual |
32 | 32 | ||
33 | ---------------------------------------------------------------- | 33 | ---------------------------------------------------------------- |
34 | Dr. David Alan Gilbert (1): | 34 | Hao Wu (6): |
35 | arm/trace: Fix hex printing | 35 | hw/misc: Add clock converter in NPCM7XX CLK module |
36 | hw/timer: Refactor NPCM7XX Timer to use CLK clock | ||
37 | hw/adc: Add an ADC module for NPCM7XX | ||
38 | hw/misc: Add a PWM module for NPCM7XX | ||
39 | hw/misc: Add QTest for NPCM7XX PWM Module | ||
40 | hw/*: Use type casting for SysBusDevice in NPCM7XX | ||
36 | 41 | ||
37 | Hao Wu (1): | 42 | Leif Lindholm (6): |
38 | hw/timer: Adding watchdog for NPCM7XX Timer. | 43 | target/arm: fix typo in cpu.h ID_AA64PFR1 field name |
44 | target/arm: make ARMCPU.clidr 64-bit | ||
45 | target/arm: make ARMCPU.ctr 64-bit | ||
46 | target/arm: add descriptions of CLIDR_EL1, CCSIDR_EL1, CTR_EL0 to cpu.h | ||
47 | target/arm: add aarch64 ID register fields to cpu.h | ||
48 | target/arm: add aarch32 ID register fields to cpu.h | ||
39 | 49 | ||
40 | Havard Skinnemoen (4): | 50 | Peter Maydell (5): |
41 | Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause | 51 | docs: Add qemu-storage-daemon(1) manpage to meson.build |
42 | hw/misc: Add npcm7xx random number generator | 52 | docs: Build and install all the docs in a single manual |
43 | hw/arm/npcm7xx: Add EHCI and OHCI controllers | 53 | target/arm: Don't decode insns in the XScale/iWMMXt space as cp insns |
44 | hw/gpio: Add GPIO model for Nuvoton NPCM7xx | 54 | hw/net/lan9118: Fix RX Status FIFO PEEK value |
55 | hw/net/lan9118: Add symbolic constants for register offsets | ||
45 | 56 | ||
46 | Luc Michel (14): | 57 | Roman Bolshakov (2): |
47 | hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro | 58 | ui/cocoa: Update path to docs in build tree |
48 | hw/core/clock: trace clock values in Hz instead of ns | 59 | ui/cocoa: Fix openFile: deprecation on Big Sur |
49 | hw/arm/raspi: fix CPRMAN base address | ||
50 | hw/arm/raspi: add a skeleton implementation of the CPRMAN | ||
51 | hw/misc/bcm2835_cprman: add a PLL skeleton implementation | ||
52 | hw/misc/bcm2835_cprman: implement PLLs behaviour | ||
53 | hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation | ||
54 | hw/misc/bcm2835_cprman: implement PLL channels behaviour | ||
55 | hw/misc/bcm2835_cprman: add a clock mux skeleton implementation | ||
56 | hw/misc/bcm2835_cprman: implement clock mux behaviour | ||
57 | hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer | ||
58 | hw/misc/bcm2835_cprman: add sane reset values to the registers | ||
59 | hw/char/pl011: add a clock input | ||
60 | hw/arm/bcm2835_peripherals: connect the UART clock | ||
61 | 60 | ||
62 | Pavel Dovgalyuk (1): | 61 | Rémi Denis-Courmont (2): |
63 | hw/arm: fix min_cpus for xlnx-versal-virt platform | 62 | target/arm: ARMv8.4-TTST extension |
63 | target/arm: enable Small Translation tables in max CPU | ||
64 | 64 | ||
65 | Peter Maydell (2): | 65 | docs/conf.py | 46 ++- |
66 | hw/core/ptimer: Support ptimer being disabled by timer callback | 66 | docs/devel/conf.py | 15 - |
67 | hw/timer/armv7m_systick: Rewrite to use ptimers | 67 | docs/index.html.in | 17 - |
68 | docs/interop/conf.py | 28 -- | ||
69 | docs/meson.build | 65 ++-- | ||
70 | docs/specs/conf.py | 16 - | ||
71 | docs/system/arm/nuvoton.rst | 4 +- | ||
72 | docs/system/conf.py | 28 -- | ||
73 | docs/tools/conf.py | 37 -- | ||
74 | docs/user/conf.py | 15 - | ||
75 | meson.build | 1 + | ||
76 | hw/adc/trace.h | 1 + | ||
77 | include/hw/adc/npcm7xx_adc.h | 69 ++++ | ||
78 | include/hw/arm/npcm7xx.h | 4 + | ||
79 | include/hw/misc/npcm7xx_clk.h | 146 ++++++- | ||
80 | include/hw/misc/npcm7xx_pwm.h | 105 +++++ | ||
81 | include/hw/timer/npcm7xx_timer.h | 1 + | ||
82 | target/arm/cpu.h | 85 ++++- | ||
83 | hw/adc/npcm7xx_adc.c | 301 +++++++++++++++ | ||
84 | hw/arm/npcm7xx.c | 55 ++- | ||
85 | hw/arm/npcm7xx_boards.c | 2 +- | ||
86 | hw/mem/npcm7xx_mc.c | 2 +- | ||
87 | hw/misc/npcm7xx_clk.c | 807 ++++++++++++++++++++++++++++++++++++++- | ||
88 | hw/misc/npcm7xx_gcr.c | 2 +- | ||
89 | hw/misc/npcm7xx_pwm.c | 550 ++++++++++++++++++++++++++ | ||
90 | hw/misc/npcm7xx_rng.c | 2 +- | ||
91 | hw/net/lan9118.c | 26 +- | ||
92 | hw/nvram/npcm7xx_otp.c | 2 +- | ||
93 | hw/ssi/npcm7xx_fiu.c | 2 +- | ||
94 | hw/timer/npcm7xx_timer.c | 39 +- | ||
95 | target/arm/cpu64.c | 1 + | ||
96 | target/arm/helper.c | 15 +- | ||
97 | target/arm/translate.c | 7 + | ||
98 | tests/qtest/npcm7xx_adc-test.c | 377 ++++++++++++++++++ | ||
99 | tests/qtest/npcm7xx_pwm-test.c | 490 ++++++++++++++++++++++++ | ||
100 | hw/adc/meson.build | 1 + | ||
101 | hw/adc/trace-events | 5 + | ||
102 | hw/misc/meson.build | 1 + | ||
103 | hw/misc/trace-events | 6 + | ||
104 | tests/qtest/meson.build | 4 +- | ||
105 | ui/cocoa.m | 7 +- | ||
106 | 41 files changed, 3124 insertions(+), 263 deletions(-) | ||
107 | delete mode 100644 docs/devel/conf.py | ||
108 | delete mode 100644 docs/index.html.in | ||
109 | delete mode 100644 docs/interop/conf.py | ||
110 | delete mode 100644 docs/specs/conf.py | ||
111 | delete mode 100644 docs/system/conf.py | ||
112 | delete mode 100644 docs/tools/conf.py | ||
113 | delete mode 100644 docs/user/conf.py | ||
114 | create mode 100644 hw/adc/trace.h | ||
115 | create mode 100644 include/hw/adc/npcm7xx_adc.h | ||
116 | create mode 100644 include/hw/misc/npcm7xx_pwm.h | ||
117 | create mode 100644 hw/adc/npcm7xx_adc.c | ||
118 | create mode 100644 hw/misc/npcm7xx_pwm.c | ||
119 | create mode 100644 tests/qtest/npcm7xx_adc-test.c | ||
120 | create mode 100644 tests/qtest/npcm7xx_pwm-test.c | ||
121 | create mode 100644 hw/adc/trace-events | ||
68 | 122 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | The kernel sets btype for the signal handler as if for a call. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20201021173749.111103-2-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | linux-user/aarch64/signal.c | 10 ++++++++-- | ||
11 | 1 file changed, 8 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/linux-user/aarch64/signal.c | ||
16 | +++ b/linux-user/aarch64/signal.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka, | ||
18 | + offsetof(struct target_rt_frame_record, tramp); | ||
19 | } | ||
20 | env->xregs[0] = usig; | ||
21 | - env->xregs[31] = frame_addr; | ||
22 | env->xregs[29] = frame_addr + fr_ofs; | ||
23 | - env->pc = ka->_sa_handler; | ||
24 | env->xregs[30] = return_addr; | ||
25 | + env->xregs[31] = frame_addr; | ||
26 | + env->pc = ka->_sa_handler; | ||
27 | + | ||
28 | + /* Invoke the signal handler as if by indirect call. */ | ||
29 | + if (cpu_isar_feature(aa64_bti, env_archcpu(env))) { | ||
30 | + env->btype = 2; | ||
31 | + } | ||
32 | + | ||
33 | if (info) { | ||
34 | tswap_siginfo(&frame->info, info); | ||
35 | env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info); | ||
36 | -- | ||
37 | 2.20.1 | ||
38 | |||
39 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Rémi Denis-Courmont <remi.denis.courmont@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | This simple mux sits between the PLL channels and the DSI0E and DSI0P | 3 | This adds for the Small Translation tables extension in AArch64 state. |
4 | clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel | ||
5 | and outputs the selected signal to source number 4 of DSI0E/P clock | ||
6 | muxes. It is controlled by the cm_dsi0hsck register. | ||
7 | 4 | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Signed-off-by: Rémi Denis-Courmont <remi.denis.courmont@huawei.com> |
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 8 | --- |
14 | include/hw/misc/bcm2835_cprman.h | 15 +++++ | 9 | target/arm/cpu.h | 5 +++++ |
15 | include/hw/misc/bcm2835_cprman_internals.h | 6 ++ | 10 | target/arm/helper.c | 15 +++++++++++++-- |
16 | hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- | 11 | 2 files changed, 18 insertions(+), 2 deletions(-) |
17 | 3 files changed, 94 insertions(+), 1 deletion(-) | ||
18 | 12 | ||
19 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 13 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
20 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/misc/bcm2835_cprman.h | 15 | --- a/target/arm/cpu.h |
22 | +++ b/include/hw/misc/bcm2835_cprman.h | 16 | +++ b/target/arm/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState { | 17 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_uao(const ARMISARegisters *id) |
24 | struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; | 18 | return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, UAO) != 0; |
25 | } CprmanClockMuxState; | 19 | } |
26 | 20 | ||
27 | +typedef struct CprmanDsi0HsckMuxState { | 21 | +static inline bool isar_feature_aa64_st(const ARMISARegisters *id) |
28 | + /*< private >*/ | ||
29 | + DeviceState parent_obj; | ||
30 | + | ||
31 | + /*< public >*/ | ||
32 | + CprmanClockMux id; | ||
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 | ||
54 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
55 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
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 | +{ | 22 | +{ |
95 | + bool src_is_plld = FIELD_EX32(*s->reg_cm, CM_DSI0HSCK, SELPLLD); | 23 | + return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, ST) != 0; |
96 | + Clock *src = src_is_plld ? s->plld_in : s->plla_in; | ||
97 | + | ||
98 | + clock_update(s->out, clock_get(src)); | ||
99 | +} | 24 | +} |
100 | + | 25 | + |
101 | +static void dsi0hsck_mux_in_update(void *opaque) | 26 | static inline bool isar_feature_aa64_bti(const ARMISARegisters *id) |
102 | +{ | 27 | { |
103 | + dsi0hsck_mux_update(CPRMAN_DSI0HSCK_MUX(opaque)); | 28 | return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0; |
104 | +} | 29 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
105 | + | 30 | index XXXXXXX..XXXXXXX 100644 |
106 | +static void dsi0hsck_mux_init(Object *obj) | 31 | --- a/target/arm/helper.c |
107 | +{ | 32 | +++ b/target/arm/helper.c |
108 | + CprmanDsi0HsckMuxState *s = CPRMAN_DSI0HSCK_MUX(obj); | 33 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, |
109 | + DeviceState *dev = DEVICE(obj); | 34 | { |
110 | + | 35 | uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
111 | + s->plla_in = qdev_init_clock_in(dev, "plla-in", dsi0hsck_mux_in_update, s); | 36 | bool epd, hpd, using16k, using64k; |
112 | + s->plld_in = qdev_init_clock_in(dev, "plld-in", dsi0hsck_mux_in_update, s); | 37 | - int select, tsz, tbi; |
113 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | 38 | + int select, tsz, tbi, max_tsz; |
114 | +} | 39 | |
115 | + | 40 | if (!regime_has_2_ranges(mmu_idx)) { |
116 | +static const VMStateDescription dsi0hsck_mux_vmstate = { | 41 | select = 0; |
117 | + .name = TYPE_CPRMAN_DSI0HSCK_MUX, | 42 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, |
118 | + .version_id = 1, | 43 | hpd = extract64(tcr, 42, 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 | } | 44 | } |
188 | } | 45 | } |
189 | 46 | - tsz = MIN(tsz, 39); /* TODO: ARMv8.4-TTST */ | |
190 | + clock_set_source(s->dsi0hsck_mux.plla_in, | ||
191 | + s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); | ||
192 | + clock_set_source(s->dsi0hsck_mux.plld_in, | ||
193 | + s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); | ||
194 | + | 47 | + |
195 | + if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { | 48 | + if (cpu_isar_feature(aa64_st, env_archcpu(env))) { |
196 | + return; | 49 | + max_tsz = 48 - using64k; |
50 | + } else { | ||
51 | + max_tsz = 39; | ||
197 | + } | 52 | + } |
198 | + | 53 | + |
199 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | 54 | + tsz = MIN(tsz, max_tsz); |
200 | CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | 55 | tsz = MAX(tsz, 16); /* TODO: ARMv8.2-LVA */ |
201 | 56 | ||
202 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | 57 | /* Present TBI as a composite with TBID. */ |
203 | type_register_static(&cprman_pll_info); | 58 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, |
204 | type_register_static(&cprman_pll_channel_info); | 59 | if (!aarch64 || stride == 9) { |
205 | type_register_static(&cprman_clock_mux_info); | 60 | /* AArch32 or 4KB pages */ |
206 | + type_register_static(&cprman_dsi0hsck_mux_info); | 61 | startlevel = 2 - sl0; |
207 | } | 62 | + |
208 | 63 | + if (cpu_isar_feature(aa64_st, cpu)) { | |
209 | type_init(cprman_register_types); | 64 | + startlevel &= 3; |
65 | + } | ||
66 | } else { | ||
67 | /* 16KB or 64KB pages */ | ||
68 | startlevel = 3 - sl0; | ||
210 | -- | 69 | -- |
211 | 2.20.1 | 70 | 2.20.1 |
212 | 71 | ||
213 | 72 | diff view generated by jsdifflib |
1 | From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> | 1 | From: Rémi Denis-Courmont <remi.denis.courmont@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | This patch sets min_cpus field for xlnx-versal-virt platform, | 3 | Signed-off-by: Rémi Denis-Courmont <remi.denis.courmont@huawei.com> |
4 | because it always creates XLNX_VERSAL_NR_ACPUS cpus even with | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
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> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 6 | --- |
13 | hw/arm/xlnx-versal-virt.c | 1 + | 7 | target/arm/cpu64.c | 1 + |
14 | 1 file changed, 1 insertion(+) | 8 | 1 file changed, 1 insertion(+) |
15 | 9 | ||
16 | diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c | 10 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c |
17 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/arm/xlnx-versal-virt.c | 12 | --- a/target/arm/cpu64.c |
19 | +++ b/hw/arm/xlnx-versal-virt.c | 13 | +++ b/target/arm/cpu64.c |
20 | @@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) | 14 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) |
21 | 15 | t = cpu->isar.id_aa64mmfr2; | |
22 | mc->desc = "Xilinx Versal Virtual development board"; | 16 | t = FIELD_DP64(t, ID_AA64MMFR2, UAO, 1); |
23 | mc->init = versal_virt_init; | 17 | t = FIELD_DP64(t, ID_AA64MMFR2, CNP, 1); /* TTCNP */ |
24 | + mc->min_cpus = XLNX_VERSAL_NR_ACPUS; | 18 | + t = FIELD_DP64(t, ID_AA64MMFR2, ST, 1); /* TTST */ |
25 | mc->max_cpus = XLNX_VERSAL_NR_ACPUS; | 19 | cpu->isar.id_aa64mmfr2 = t; |
26 | mc->default_cpus = XLNX_VERSAL_NR_ACPUS; | 20 | |
27 | mc->no_cdrom = true; | 21 | /* Replicate the same data to the 32-bit id registers. */ |
28 | -- | 22 | -- |
29 | 2.20.1 | 23 | 2.20.1 |
30 | 24 | ||
31 | 25 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Those reset values have been extracted from a Raspberry Pi 3 model B | 3 | SBSS -> SSBS |
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 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> |
11 | expects them to be set when it boots up). | ||
12 | |||
13 | Some stages are not exposed by the Linux driver (e.g. the PLL B). For | ||
14 | those, the reset values are unknown and left to 0 which implies a | ||
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> | 6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
24 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> | ||
9 | Message-id: 20210108185154.8108-2-leif@nuviainc.com | ||
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 | target/arm/cpu.h | 2 +- |
28 | hw/misc/bcm2835_cprman.c | 31 +++ | 13 | 1 file changed, 1 insertion(+), 1 deletion(-) |
29 | 2 files changed, 300 insertions(+) | ||
30 | 14 | ||
31 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | 15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
32 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 17 | --- a/target/arm/cpu.h |
34 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 18 | +++ b/target/arm/cpu.h |
35 | @@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, | 19 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64PFR0, RAS, 28, 4) |
36 | mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | 20 | FIELD(ID_AA64PFR0, SVE, 32, 4) |
37 | } | 21 | |
38 | 22 | FIELD(ID_AA64PFR1, BT, 0, 4) | |
39 | + | 23 | -FIELD(ID_AA64PFR1, SBSS, 4, 4) |
40 | +/* | 24 | +FIELD(ID_AA64PFR1, SSBS, 4, 4) |
41 | + * Object reset info | 25 | FIELD(ID_AA64PFR1, MTE, 8, 4) |
42 | + * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the | 26 | FIELD(ID_AA64PFR1, RAS_FRAC, 12, 4) |
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 | +} | ||
327 | + | ||
328 | static bool pll_is_locked(const CprmanPllState *pll) | ||
329 | { | ||
330 | return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) | ||
331 | @@ -XXX,XX +XXX,XX @@ static void pll_class_init(ObjectClass *klass, void *data) | ||
332 | { | ||
333 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
334 | |||
335 | + dc->reset = pll_reset; | ||
336 | dc->vmsd = &pll_vmstate; | ||
337 | } | ||
338 | |||
339 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | ||
340 | |||
341 | /* PLL channel */ | ||
342 | |||
343 | +static void pll_channel_reset(DeviceState *dev) | ||
344 | +{ | ||
345 | + CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev); | ||
346 | + const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id]; | ||
347 | + | ||
348 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
349 | +} | ||
350 | + | ||
351 | static bool pll_channel_is_enabled(CprmanPllChannelState *channel) | ||
352 | { | ||
353 | /* | ||
354 | @@ -XXX,XX +XXX,XX @@ static void pll_channel_class_init(ObjectClass *klass, void *data) | ||
355 | { | ||
356 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
357 | |||
358 | + dc->reset = pll_channel_reset; | ||
359 | dc->vmsd = &pll_channel_vmstate; | ||
360 | } | ||
361 | |||
362 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_src_update(void *opaque) | ||
363 | clock_mux_update(s); | ||
364 | } | ||
365 | |||
366 | +static void clock_mux_reset(DeviceState *dev) | ||
367 | +{ | ||
368 | + CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev); | ||
369 | + const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id]; | ||
370 | + | ||
371 | + *clock->reg_ctl = info->cm_ctl; | ||
372 | + *clock->reg_div = info->cm_div; | ||
373 | +} | ||
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 | 27 | ||
386 | -- | 28 | -- |
387 | 2.20.1 | 29 | 2.20.1 |
388 | 30 | ||
389 | 31 | diff view generated by jsdifflib |
1 | From: Shashi Mallela <shashi.mallela@linaro.org> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Included the newly implemented SBSA generic watchdog device model into | 3 | The AArch64 view of CLIDR_EL1 extends the ICB field to include also bit |
4 | SBSA platform | 4 | 32, as well as adding a Ttype<n> field when FEAT_MTE is implemented. |
5 | Extend the clidr field to be able to hold this context. | ||
5 | 6 | ||
6 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | 7 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org | 10 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> |
11 | Message-id: 20210108185154.8108-3-leif@nuviainc.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 13 | --- |
11 | hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++ | 14 | target/arm/cpu.h | 2 +- |
12 | 1 file changed, 23 insertions(+) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 16 | ||
14 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c | 17 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/sbsa-ref.c | 19 | --- a/target/arm/cpu.h |
17 | +++ b/hw/arm/sbsa-ref.c | 20 | +++ b/target/arm/cpu.h |
18 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { |
19 | #include "hw/qdev-properties.h" | 22 | uint32_t id_afr0; |
20 | #include "hw/usb.h" | 23 | uint64_t id_aa64afr0; |
21 | #include "hw/char/pl011.h" | 24 | uint64_t id_aa64afr1; |
22 | +#include "hw/watchdog/sbsa_gwdt.h" | 25 | - uint32_t clidr; |
23 | #include "net/net.h" | 26 | + uint64_t clidr; |
24 | #include "qom/object.h" | 27 | uint64_t mp_affinity; /* MP ID without feature bits */ |
25 | 28 | /* The elements of this array are the CCSIDR values for each cache, | |
26 | @@ -XXX,XX +XXX,XX @@ enum { | 29 | * in the order L1DCache, L1ICache, L2DCache, L2ICache, etc. |
27 | SBSA_GIC_DIST, | ||
28 | SBSA_GIC_REDIST, | ||
29 | SBSA_SECURE_EC, | ||
30 | + SBSA_GWDT, | ||
31 | + SBSA_GWDT_REFRESH, | ||
32 | + SBSA_GWDT_CONTROL, | ||
33 | SBSA_SMMU, | ||
34 | SBSA_UART, | ||
35 | SBSA_RTC, | ||
36 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { | ||
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 | } | ||
56 | |||
57 | +static void create_wdt(const SBSAMachineState *sms) | ||
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 | -- | 30 | -- |
84 | 2.20.1 | 31 | 2.20.1 |
85 | 32 | ||
86 | 33 | diff view generated by jsdifflib |
1 | From: Shashi Mallela <shashi.mallela@linaro.org> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Generic watchdog device model implementation as per ARM SBSA v6.0 | 3 | When FEAT_MTE is implemented, the AArch64 view of CTR_EL0 adds the |
4 | TminLine field in bits [37:32]. | ||
5 | Extend the ctr field to be able to hold this context. | ||
4 | 6 | ||
5 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | 7 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> |
6 | Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org | 8 | Reviewed-by: Hao Wu <wuhaotsh@google.com> |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> | ||
11 | Message-id: 20210108185154.8108-4-leif@nuviainc.com | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 13 | --- |
10 | include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++ | 14 | target/arm/cpu.h | 2 +- |
11 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++ | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
12 | hw/arm/Kconfig | 1 + | ||
13 | hw/watchdog/Kconfig | 3 + | ||
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/cpu.h b/target/arm/cpu.h |
20 | new file mode 100644 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/include/hw/watchdog/sbsa_gwdt.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +/* | ||
26 | + * Copyright (c) 2020 Linaro Limited | ||
27 | + * | ||
28 | + * Authors: | ||
29 | + * Shashi Mallela <shashi.mallela@linaro.org> | ||
30 | + * | ||
31 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | ||
32 | + * option) any later version. See the COPYING file in the top-level directory. | ||
33 | + * | ||
34 | + */ | ||
35 | + | ||
36 | +#ifndef WDT_SBSA_GWDT_H | ||
37 | +#define WDT_SBSA_GWDT_H | ||
38 | + | ||
39 | +#include "qemu/bitops.h" | ||
40 | +#include "hw/sysbus.h" | ||
41 | +#include "hw/irq.h" | ||
42 | + | ||
43 | +#define TYPE_WDT_SBSA "sbsa_gwdt" | ||
44 | +#define SBSA_GWDT(obj) \ | ||
45 | + OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA) | ||
46 | +#define SBSA_GWDT_CLASS(klass) \ | ||
47 | + OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA) | ||
48 | +#define SBSA_GWDT_GET_CLASS(obj) \ | ||
49 | + OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA) | ||
50 | + | ||
51 | +/* SBSA Generic Watchdog register definitions */ | ||
52 | +/* refresh frame */ | ||
53 | +#define SBSA_GWDT_WRR 0x000 | ||
54 | + | ||
55 | +/* control frame */ | ||
56 | +#define SBSA_GWDT_WCS 0x000 | ||
57 | +#define SBSA_GWDT_WOR 0x008 | ||
58 | +#define SBSA_GWDT_WORU 0x00C | ||
59 | +#define SBSA_GWDT_WCV 0x010 | ||
60 | +#define SBSA_GWDT_WCVU 0x014 | ||
61 | + | ||
62 | +/* Watchdog Interface Identification Register */ | ||
63 | +#define SBSA_GWDT_W_IIDR 0xFCC | ||
64 | + | ||
65 | +/* Watchdog Control and Status Register Bits */ | ||
66 | +#define SBSA_GWDT_WCS_EN BIT(0) | ||
67 | +#define SBSA_GWDT_WCS_WS0 BIT(1) | ||
68 | +#define SBSA_GWDT_WCS_WS1 BIT(2) | ||
69 | + | ||
70 | +#define SBSA_GWDT_WOR_MASK 0x0000FFFF | ||
71 | + | ||
72 | +/* | ||
73 | + * Watchdog Interface Identification Register definition | ||
74 | + * considering JEP106 code for ARM in Bits [11:0] | ||
75 | + */ | ||
76 | +#define SBSA_GWDT_ID 0x1043B | ||
77 | + | ||
78 | +/* 2 Separate memory regions for each of refresh & control register frames */ | ||
79 | +#define SBSA_GWDT_RMMIO_SIZE 0x1000 | ||
80 | +#define SBSA_GWDT_CMMIO_SIZE 0x1000 | ||
81 | + | ||
82 | +#define SBSA_TIMER_FREQ 62500000 /* Hz */ | ||
83 | + | ||
84 | +typedef struct SBSA_GWDTState { | ||
85 | + /* <private> */ | ||
86 | + SysBusDevice parent_obj; | ||
87 | + | ||
88 | + /*< public >*/ | ||
89 | + MemoryRegion rmmio; | ||
90 | + MemoryRegion cmmio; | ||
91 | + qemu_irq irq; | ||
92 | + | ||
93 | + QEMUTimer *timer; | ||
94 | + | ||
95 | + uint32_t id; | ||
96 | + uint32_t wcs; | ||
97 | + uint32_t worl; | ||
98 | + uint32_t woru; | ||
99 | + uint32_t wcvl; | ||
100 | + uint32_t wcvu; | ||
101 | +} SBSA_GWDTState; | ||
102 | + | ||
103 | +#endif /* WDT_SBSA_GWDT_H */ | ||
104 | diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c | ||
105 | new file mode 100644 | ||
106 | index XXXXXXX..XXXXXXX | ||
107 | --- /dev/null | ||
108 | +++ b/hw/watchdog/sbsa_gwdt.c | ||
109 | @@ -XXX,XX +XXX,XX @@ | ||
110 | +/* | ||
111 | + * Generic watchdog device model for SBSA | ||
112 | + * | ||
113 | + * The watchdog device has been implemented as revision 1 variant of | ||
114 | + * the ARM SBSA specification v6.0 | ||
115 | + * (https://developer.arm.com/documentation/den0029/d?lang=en) | ||
116 | + * | ||
117 | + * Copyright Linaro.org 2020 | ||
118 | + * | ||
119 | + * Authors: | ||
120 | + * Shashi Mallela <shashi.mallela@linaro.org> | ||
121 | + * | ||
122 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | ||
123 | + * option) any later version. See the COPYING file in the top-level directory. | ||
124 | + * | ||
125 | + */ | ||
126 | + | ||
127 | +#include "qemu/osdep.h" | ||
128 | +#include "sysemu/reset.h" | ||
129 | +#include "sysemu/watchdog.h" | ||
130 | +#include "hw/watchdog/sbsa_gwdt.h" | ||
131 | +#include "qemu/timer.h" | ||
132 | +#include "migration/vmstate.h" | ||
133 | +#include "qemu/log.h" | ||
134 | +#include "qemu/module.h" | ||
135 | + | ||
136 | +static WatchdogTimerModel model = { | ||
137 | + .wdt_name = TYPE_WDT_SBSA, | ||
138 | + .wdt_description = "SBSA-compliant generic watchdog device", | ||
139 | +}; | ||
140 | + | ||
141 | +static const VMStateDescription vmstate_sbsa_gwdt = { | ||
142 | + .name = "sbsa-gwdt", | ||
143 | + .version_id = 1, | ||
144 | + .minimum_version_id = 1, | ||
145 | + .fields = (VMStateField[]) { | ||
146 | + VMSTATE_TIMER_PTR(timer, SBSA_GWDTState), | ||
147 | + VMSTATE_UINT32(wcs, SBSA_GWDTState), | ||
148 | + VMSTATE_UINT32(worl, SBSA_GWDTState), | ||
149 | + VMSTATE_UINT32(woru, SBSA_GWDTState), | ||
150 | + VMSTATE_UINT32(wcvl, SBSA_GWDTState), | ||
151 | + VMSTATE_UINT32(wcvu, SBSA_GWDTState), | ||
152 | + VMSTATE_END_OF_LIST() | ||
153 | + } | ||
154 | +}; | ||
155 | + | ||
156 | +typedef enum WdtRefreshType { | ||
157 | + EXPLICIT_REFRESH = 0, | ||
158 | + TIMEOUT_REFRESH = 1, | ||
159 | +} WdtRefreshType; | ||
160 | + | ||
161 | +static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size) | ||
162 | +{ | ||
163 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
164 | + uint32_t ret = 0; | ||
165 | + | ||
166 | + switch (addr) { | ||
167 | + case SBSA_GWDT_WRR: | ||
168 | + /* watch refresh read has no effect and returns 0 */ | ||
169 | + ret = 0; | ||
170 | + break; | ||
171 | + case SBSA_GWDT_W_IIDR: | ||
172 | + ret = s->id; | ||
173 | + break; | ||
174 | + default: | ||
175 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame read :" | ||
176 | + " 0x%x\n", (int)addr); | ||
177 | + } | ||
178 | + return ret; | ||
179 | +} | ||
180 | + | ||
181 | +static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size) | ||
182 | +{ | ||
183 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
184 | + uint32_t ret = 0; | ||
185 | + | ||
186 | + switch (addr) { | ||
187 | + case SBSA_GWDT_WCS: | ||
188 | + ret = s->wcs; | ||
189 | + break; | ||
190 | + case SBSA_GWDT_WOR: | ||
191 | + ret = s->worl; | ||
192 | + break; | ||
193 | + case SBSA_GWDT_WORU: | ||
194 | + ret = s->woru; | ||
195 | + break; | ||
196 | + case SBSA_GWDT_WCV: | ||
197 | + ret = s->wcvl; | ||
198 | + break; | ||
199 | + case SBSA_GWDT_WCVU: | ||
200 | + ret = s->wcvu; | ||
201 | + break; | ||
202 | + case SBSA_GWDT_W_IIDR: | ||
203 | + ret = s->id; | ||
204 | + break; | ||
205 | + default: | ||
206 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame read :" | ||
207 | + " 0x%x\n", (int)addr); | ||
208 | + } | ||
209 | + return ret; | ||
210 | +} | ||
211 | + | ||
212 | +static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype) | ||
213 | +{ | ||
214 | + uint64_t timeout = 0; | ||
215 | + | ||
216 | + timer_del(s->timer); | ||
217 | + | ||
218 | + if (s->wcs & SBSA_GWDT_WCS_EN) { | ||
219 | + /* | ||
220 | + * Extract the upper 16 bits from woru & 32 bits from worl | ||
221 | + * registers to construct the 48 bit offset value | ||
222 | + */ | ||
223 | + timeout = s->woru; | ||
224 | + timeout <<= 32; | ||
225 | + timeout |= s->worl; | ||
226 | + timeout = muldiv64(timeout, NANOSECONDS_PER_SECOND, SBSA_TIMER_FREQ); | ||
227 | + timeout += qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
228 | + | ||
229 | + if ((rtype == EXPLICIT_REFRESH) || ((rtype == TIMEOUT_REFRESH) && | ||
230 | + (!(s->wcs & SBSA_GWDT_WCS_WS0)))) { | ||
231 | + /* store the current timeout value into compare registers */ | ||
232 | + s->wcvu = timeout >> 32; | ||
233 | + s->wcvl = timeout; | ||
234 | + } | ||
235 | + timer_mod(s->timer, timeout); | ||
236 | + } | ||
237 | +} | ||
238 | + | ||
239 | +static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data, | ||
240 | + unsigned size) { | ||
241 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
242 | + | ||
243 | + if (offset == SBSA_GWDT_WRR) { | ||
244 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
245 | + | ||
246 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
247 | + } else { | ||
248 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :" | ||
249 | + " 0x%x\n", (int)offset); | ||
250 | + } | ||
251 | +} | ||
252 | + | ||
253 | +static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data, | ||
254 | + unsigned size) { | ||
255 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
256 | + | ||
257 | + switch (offset) { | ||
258 | + case SBSA_GWDT_WCS: | ||
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 | 18 | index XXXXXXX..XXXXXXX 100644 |
405 | --- a/hw/arm/Kconfig | 19 | --- a/target/arm/cpu.h |
406 | +++ b/hw/arm/Kconfig | 20 | +++ b/target/arm/cpu.h |
407 | @@ -XXX,XX +XXX,XX @@ config SBSA_REF | 21 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { |
408 | select PL031 # RTC | 22 | uint64_t midr; |
409 | select PL061 # GPIO | 23 | uint32_t revidr; |
410 | select USB_EHCI_SYSBUS | 24 | uint32_t reset_fpsid; |
411 | + select WDT_SBSA | 25 | - uint32_t ctr; |
412 | 26 | + uint64_t ctr; | |
413 | config SABRELITE | 27 | uint32_t reset_sctlr; |
414 | bool | 28 | uint64_t pmceid0; |
415 | diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig | 29 | uint64_t pmceid1; |
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 | -- | 30 | -- |
436 | 2.20.1 | 31 | 2.20.1 |
437 | 32 | ||
438 | 33 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Connect the 'uart-out' clock from the CPRMAN to the PL011 instance. | 3 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> |
4 | 4 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> | |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Message-id: 20210108185154.8108-5-leif@nuviainc.com |
6 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 7 | --- |
11 | hw/arm/bcm2835_peripherals.c | 2 ++ | 8 | target/arm/cpu.h | 31 +++++++++++++++++++++++++++++++ |
12 | 1 file changed, 2 insertions(+) | 9 | 1 file changed, 31 insertions(+) |
13 | 10 | ||
14 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | 11 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/bcm2835_peripherals.c | 13 | --- a/target/arm/cpu.h |
17 | +++ b/hw/arm/bcm2835_peripherals.c | 14 | +++ b/target/arm/cpu.h |
18 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 15 | @@ -XXX,XX +XXX,XX @@ FIELD(V7M_FPCCR, ASPEN, 31, 1) |
19 | } | 16 | /* |
20 | memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | 17 | * System register ID fields. |
21 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | 18 | */ |
22 | + qdev_connect_clock_in(DEVICE(&s->uart0), "clk", | 19 | +FIELD(CLIDR_EL1, CTYPE1, 0, 3) |
23 | + qdev_get_clock_out(DEVICE(&s->cprman), "uart-out")); | 20 | +FIELD(CLIDR_EL1, CTYPE2, 3, 3) |
24 | 21 | +FIELD(CLIDR_EL1, CTYPE3, 6, 3) | |
25 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | 22 | +FIELD(CLIDR_EL1, CTYPE4, 9, 3) |
26 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | 23 | +FIELD(CLIDR_EL1, CTYPE5, 12, 3) |
24 | +FIELD(CLIDR_EL1, CTYPE6, 15, 3) | ||
25 | +FIELD(CLIDR_EL1, CTYPE7, 18, 3) | ||
26 | +FIELD(CLIDR_EL1, LOUIS, 21, 3) | ||
27 | +FIELD(CLIDR_EL1, LOC, 24, 3) | ||
28 | +FIELD(CLIDR_EL1, LOUU, 27, 3) | ||
29 | +FIELD(CLIDR_EL1, ICB, 30, 3) | ||
30 | + | ||
31 | +/* When FEAT_CCIDX is implemented */ | ||
32 | +FIELD(CCSIDR_EL1, CCIDX_LINESIZE, 0, 3) | ||
33 | +FIELD(CCSIDR_EL1, CCIDX_ASSOCIATIVITY, 3, 21) | ||
34 | +FIELD(CCSIDR_EL1, CCIDX_NUMSETS, 32, 24) | ||
35 | + | ||
36 | +/* When FEAT_CCIDX is not implemented */ | ||
37 | +FIELD(CCSIDR_EL1, LINESIZE, 0, 3) | ||
38 | +FIELD(CCSIDR_EL1, ASSOCIATIVITY, 3, 10) | ||
39 | +FIELD(CCSIDR_EL1, NUMSETS, 13, 15) | ||
40 | + | ||
41 | +FIELD(CTR_EL0, IMINLINE, 0, 4) | ||
42 | +FIELD(CTR_EL0, L1IP, 14, 2) | ||
43 | +FIELD(CTR_EL0, DMINLINE, 16, 4) | ||
44 | +FIELD(CTR_EL0, ERG, 20, 4) | ||
45 | +FIELD(CTR_EL0, CWG, 24, 4) | ||
46 | +FIELD(CTR_EL0, IDC, 28, 1) | ||
47 | +FIELD(CTR_EL0, DIC, 29, 1) | ||
48 | +FIELD(CTR_EL0, TMINLINE, 32, 6) | ||
49 | + | ||
50 | FIELD(MIDR_EL1, REVISION, 0, 4) | ||
51 | FIELD(MIDR_EL1, PARTNUM, 4, 12) | ||
52 | FIELD(MIDR_EL1, ARCHITECTURE, 16, 4) | ||
27 | -- | 53 | -- |
28 | 2.20.1 | 54 | 2.20.1 |
29 | 55 | ||
30 | 56 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Add a clock input to the PL011 UART so we can compute the current baud | 3 | Add entries present in ARM DDI 0487F.c (August 2020). |
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 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 7 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> |
11 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Message-id: 20210108185154.8108-6-leif@nuviainc.com |
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 10 | --- |
14 | include/hw/char/pl011.h | 1 + | 11 | target/arm/cpu.h | 15 +++++++++++++++ |
15 | hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ | 12 | 1 file changed, 15 insertions(+) |
16 | hw/char/trace-events | 1 + | ||
17 | 3 files changed, 47 insertions(+) | ||
18 | 13 | ||
19 | diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
20 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/char/pl011.h | 16 | --- a/target/arm/cpu.h |
22 | +++ b/include/hw/char/pl011.h | 17 | +++ b/target/arm/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ struct PL011State { | 18 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64ISAR1, GPI, 28, 4) |
24 | int read_trigger; | 19 | FIELD(ID_AA64ISAR1, FRINTTS, 32, 4) |
25 | CharBackend chr; | 20 | FIELD(ID_AA64ISAR1, SB, 36, 4) |
26 | qemu_irq irq[6]; | 21 | FIELD(ID_AA64ISAR1, SPECRES, 40, 4) |
27 | + Clock *clk; | 22 | +FIELD(ID_AA64ISAR1, BF16, 44, 4) |
28 | const unsigned char *id; | 23 | +FIELD(ID_AA64ISAR1, DGH, 48, 4) |
29 | }; | 24 | +FIELD(ID_AA64ISAR1, I8MM, 52, 4) |
30 | 25 | ||
31 | diff --git a/hw/char/pl011.c b/hw/char/pl011.c | 26 | FIELD(ID_AA64PFR0, EL0, 0, 4) |
32 | index XXXXXXX..XXXXXXX 100644 | 27 | FIELD(ID_AA64PFR0, EL1, 4, 4) |
33 | --- a/hw/char/pl011.c | 28 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64PFR0, ADVSIMD, 20, 4) |
34 | +++ b/hw/char/pl011.c | 29 | FIELD(ID_AA64PFR0, GIC, 24, 4) |
35 | @@ -XXX,XX +XXX,XX @@ | 30 | FIELD(ID_AA64PFR0, RAS, 28, 4) |
36 | #include "hw/char/pl011.h" | 31 | FIELD(ID_AA64PFR0, SVE, 32, 4) |
37 | #include "hw/irq.h" | 32 | +FIELD(ID_AA64PFR0, SEL2, 36, 4) |
38 | #include "hw/sysbus.h" | 33 | +FIELD(ID_AA64PFR0, MPAM, 40, 4) |
39 | +#include "hw/qdev-clock.h" | 34 | +FIELD(ID_AA64PFR0, AMU, 44, 4) |
40 | #include "migration/vmstate.h" | 35 | +FIELD(ID_AA64PFR0, DIT, 48, 4) |
41 | #include "chardev/char-fe.h" | 36 | +FIELD(ID_AA64PFR0, CSV2, 56, 4) |
42 | #include "qemu/log.h" | 37 | +FIELD(ID_AA64PFR0, CSV3, 60, 4) |
43 | @@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s) | 38 | |
44 | s->read_trigger = 1; | 39 | FIELD(ID_AA64PFR1, BT, 0, 4) |
45 | } | 40 | FIELD(ID_AA64PFR1, SSBS, 4, 4) |
46 | 41 | FIELD(ID_AA64PFR1, MTE, 8, 4) | |
47 | +static unsigned int pl011_get_baudrate(const PL011State *s) | 42 | FIELD(ID_AA64PFR1, RAS_FRAC, 12, 4) |
48 | +{ | 43 | +FIELD(ID_AA64PFR1, MPAM_FRAC, 16, 4) |
49 | + uint64_t clk; | 44 | |
50 | + | 45 | FIELD(ID_AA64MMFR0, PARANGE, 0, 4) |
51 | + if (s->fbrd == 0) { | 46 | FIELD(ID_AA64MMFR0, ASIDBITS, 4, 4) |
52 | + return 0; | 47 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64MMFR0, TGRAN16_2, 32, 4) |
53 | + } | 48 | FIELD(ID_AA64MMFR0, TGRAN64_2, 36, 4) |
54 | + | 49 | FIELD(ID_AA64MMFR0, TGRAN4_2, 40, 4) |
55 | + clk = clock_get_hz(s->clk); | 50 | FIELD(ID_AA64MMFR0, EXS, 44, 4) |
56 | + return (clk / ((s->ibrd << 6) + s->fbrd)) << 2; | 51 | +FIELD(ID_AA64MMFR0, FGT, 56, 4) |
57 | +} | 52 | +FIELD(ID_AA64MMFR0, ECV, 60, 4) |
58 | + | 53 | |
59 | +static void pl011_trace_baudrate_change(const PL011State *s) | 54 | FIELD(ID_AA64MMFR1, HAFDBS, 0, 4) |
60 | +{ | 55 | FIELD(ID_AA64MMFR1, VMIDBITS, 4, 4) |
61 | + trace_pl011_baudrate_change(pl011_get_baudrate(s), | 56 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64MMFR1, LO, 16, 4) |
62 | + clock_get_hz(s->clk), | 57 | FIELD(ID_AA64MMFR1, PAN, 20, 4) |
63 | + s->ibrd, s->fbrd); | 58 | FIELD(ID_AA64MMFR1, SPECSEI, 24, 4) |
64 | +} | 59 | FIELD(ID_AA64MMFR1, XNX, 28, 4) |
65 | + | 60 | +FIELD(ID_AA64MMFR1, TWED, 32, 4) |
66 | static void pl011_write(void *opaque, hwaddr offset, | 61 | +FIELD(ID_AA64MMFR1, ETS, 36, 4) |
67 | uint64_t value, unsigned size) | 62 | |
68 | { | 63 | FIELD(ID_AA64MMFR2, CNP, 0, 4) |
69 | @@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset, | 64 | FIELD(ID_AA64MMFR2, UAO, 4, 4) |
70 | break; | 65 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64DFR0, CTX_CMPS, 28, 4) |
71 | case 9: /* UARTIBRD */ | 66 | FIELD(ID_AA64DFR0, PMSVER, 32, 4) |
72 | s->ibrd = value; | 67 | FIELD(ID_AA64DFR0, DOUBLELOCK, 36, 4) |
73 | + pl011_trace_baudrate_change(s); | 68 | FIELD(ID_AA64DFR0, TRACEFILT, 40, 4) |
74 | break; | 69 | +FIELD(ID_AA64DFR0, MTPMU, 48, 4) |
75 | case 10: /* UARTFBRD */ | 70 | |
76 | s->fbrd = value; | 71 | FIELD(ID_DFR0, COPDBG, 0, 4) |
77 | + pl011_trace_baudrate_change(s); | 72 | FIELD(ID_DFR0, COPSDBG, 4, 4) |
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 | } | ||
84 | |||
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 | -- | 73 | -- |
144 | 2.20.1 | 74 | 2.20.1 |
145 | 75 | ||
146 | 76 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Leif Lindholm <leif@nuviainc.com> |
---|---|---|---|
2 | 2 | ||
3 | Transform the prot bit to a qemu internal page bit, and save | 3 | Add entries present in ARM DDI 0487F.c (August 2020). |
4 | it in the page tables. | ||
5 | 4 | ||
5 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> |
8 | Message-id: 20201021173749.111103-3-richard.henderson@linaro.org | 8 | Message-id: 20210108185154.8108-7-leif@nuviainc.com |
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 | target/arm/cpu.h | 28 ++++++++++++++++++++++++++++ |
12 | linux-user/syscall_defs.h | 4 ++++ | 12 | 1 file changed, 28 insertions(+) |
13 | target/arm/cpu.h | 5 +++++ | ||
14 | linux-user/mmap.c | 16 ++++++++++++++++ | ||
15 | target/arm/translate-a64.c | 6 +++--- | ||
16 | 5 files changed, 30 insertions(+), 3 deletions(-) | ||
17 | 13 | ||
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 @@ 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 | ||
26 | +/* Target-specific bits that will be used via page_get_flags(). */ | ||
27 | +#define PAGE_TARGET_1 0x0080 | ||
28 | |||
29 | #if defined(CONFIG_USER_ONLY) | ||
30 | void page_dump(FILE *f); | ||
31 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/linux-user/syscall_defs.h | ||
34 | +++ b/linux-user/syscall_defs.h | ||
35 | @@ -XXX,XX +XXX,XX @@ struct target_winsize { | ||
36 | #define TARGET_PROT_SEM 0x08 | ||
37 | #endif | ||
38 | |||
39 | +#ifdef TARGET_AARCH64 | ||
40 | +#define TARGET_PROT_BTI 0x10 | ||
41 | +#endif | ||
42 | + | ||
43 | /* 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 | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
47 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/arm/cpu.h | 16 | --- a/target/arm/cpu.h |
49 | +++ b/target/arm/cpu.h | 17 | +++ b/target/arm/cpu.h |
50 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) | 18 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_ISAR6, DP, 4, 4) |
51 | #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) | 19 | FIELD(ID_ISAR6, FHM, 8, 4) |
52 | #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) | 20 | FIELD(ID_ISAR6, SB, 12, 4) |
53 | 21 | FIELD(ID_ISAR6, SPECRES, 16, 4) | |
54 | +/* | 22 | +FIELD(ID_ISAR6, BF16, 20, 4) |
55 | + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. | 23 | +FIELD(ID_ISAR6, I8MM, 24, 4) |
56 | + */ | 24 | |
57 | +#define PAGE_BTI PAGE_TARGET_1 | 25 | FIELD(ID_MMFR0, VMSA, 0, 4) |
26 | FIELD(ID_MMFR0, PMSA, 4, 4) | ||
27 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_MMFR0, AUXREG, 20, 4) | ||
28 | FIELD(ID_MMFR0, FCSE, 24, 4) | ||
29 | FIELD(ID_MMFR0, INNERSHR, 28, 4) | ||
30 | |||
31 | +FIELD(ID_MMFR1, L1HVDVA, 0, 4) | ||
32 | +FIELD(ID_MMFR1, L1UNIVA, 4, 4) | ||
33 | +FIELD(ID_MMFR1, L1HVDSW, 8, 4) | ||
34 | +FIELD(ID_MMFR1, L1UNISW, 12, 4) | ||
35 | +FIELD(ID_MMFR1, L1HVD, 16, 4) | ||
36 | +FIELD(ID_MMFR1, L1UNI, 20, 4) | ||
37 | +FIELD(ID_MMFR1, L1TSTCLN, 24, 4) | ||
38 | +FIELD(ID_MMFR1, BPRED, 28, 4) | ||
58 | + | 39 | + |
59 | /* | 40 | +FIELD(ID_MMFR2, L1HVDFG, 0, 4) |
60 | * Naming convention for isar_feature functions: | 41 | +FIELD(ID_MMFR2, L1HVDBG, 4, 4) |
61 | * Functions which test 32-bit ID registers should have _aa32_ in | 42 | +FIELD(ID_MMFR2, L1HVDRNG, 8, 4) |
62 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | 43 | +FIELD(ID_MMFR2, HVDTLB, 12, 4) |
63 | index XXXXXXX..XXXXXXX 100644 | 44 | +FIELD(ID_MMFR2, UNITLB, 16, 4) |
64 | --- a/linux-user/mmap.c | 45 | +FIELD(ID_MMFR2, MEMBARR, 20, 4) |
65 | +++ b/linux-user/mmap.c | 46 | +FIELD(ID_MMFR2, WFISTALL, 24, 4) |
66 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | 47 | +FIELD(ID_MMFR2, HWACCFLG, 28, 4) |
67 | *host_prot = (prot & (PROT_READ | PROT_WRITE)) | ||
68 | | (prot & PROT_EXEC ? PROT_READ : 0); | ||
69 | |||
70 | +#ifdef TARGET_AARCH64 | ||
71 | + /* | ||
72 | + * 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 | ||
74 | + * the bit has been requested. If set and valid, record the bit | ||
75 | + * within QEMU's page_flags. | ||
76 | + */ | ||
77 | + if (prot & TARGET_PROT_BTI) { | ||
78 | + ARMCPU *cpu = ARM_CPU(thread_cpu); | ||
79 | + if (cpu_isar_feature(aa64_bti, cpu)) { | ||
80 | + valid |= TARGET_PROT_BTI; | ||
81 | + page_flags |= PAGE_BTI; | ||
82 | + } | ||
83 | + } | ||
84 | +#endif | ||
85 | + | 48 | + |
86 | return prot & ~valid ? 0 : page_flags; | 49 | FIELD(ID_MMFR3, CMAINTVA, 0, 4) |
87 | } | 50 | FIELD(ID_MMFR3, CMAINTSW, 4, 4) |
88 | 51 | FIELD(ID_MMFR3, BPMAINT, 8, 4) | |
89 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 52 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_MMFR4, LSM, 20, 4) |
90 | index XXXXXXX..XXXXXXX 100644 | 53 | FIELD(ID_MMFR4, CCIDX, 24, 4) |
91 | --- a/target/arm/translate-a64.c | 54 | FIELD(ID_MMFR4, EVT, 28, 4) |
92 | +++ b/target/arm/translate-a64.c | 55 | |
93 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) | 56 | +FIELD(ID_MMFR5, ETS, 0, 4) |
94 | */ | 57 | + |
95 | static bool is_guarded_page(CPUARMState *env, DisasContext *s) | 58 | FIELD(ID_PFR0, STATE0, 0, 4) |
96 | { | 59 | FIELD(ID_PFR0, STATE1, 4, 4) |
97 | -#ifdef CONFIG_USER_ONLY | 60 | FIELD(ID_PFR0, STATE2, 8, 4) |
98 | - return false; /* FIXME */ | 61 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_PFR1, SEC_FRAC, 20, 4) |
99 | -#else | 62 | FIELD(ID_PFR1, VIRT_FRAC, 24, 4) |
100 | uint64_t addr = s->base.pc_first; | 63 | FIELD(ID_PFR1, GIC, 28, 4) |
101 | +#ifdef CONFIG_USER_ONLY | 64 | |
102 | + return page_get_flags(addr) & PAGE_BTI; | 65 | +FIELD(ID_PFR2, CSV3, 0, 4) |
103 | +#else | 66 | +FIELD(ID_PFR2, SSBS, 4, 4) |
104 | int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); | 67 | +FIELD(ID_PFR2, RAS_FRAC, 8, 4) |
105 | unsigned int index = tlb_index(env, mmu_idx, addr); | 68 | + |
106 | CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); | 69 | FIELD(ID_AA64ISAR0, AES, 4, 4) |
70 | FIELD(ID_AA64ISAR0, SHA1, 8, 4) | ||
71 | FIELD(ID_AA64ISAR0, SHA2, 12, 4) | ||
72 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_DFR0, MPROFDBG, 20, 4) | ||
73 | FIELD(ID_DFR0, PERFMON, 24, 4) | ||
74 | FIELD(ID_DFR0, TRACEFILT, 28, 4) | ||
75 | |||
76 | +FIELD(ID_DFR1, MTPMU, 0, 4) | ||
77 | + | ||
78 | FIELD(DBGDIDR, SE_IMP, 12, 1) | ||
79 | FIELD(DBGDIDR, NSUHD_IMP, 14, 1) | ||
80 | FIELD(DBGDIDR, VERSION, 16, 4) | ||
107 | -- | 81 | -- |
108 | 2.20.1 | 82 | 2.20.1 |
109 | 83 | ||
110 | 84 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | These are all of the defines required to parse | ||
4 | GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. | ||
5 | Other missing defines related to other GNU program headers | ||
6 | and notes are elided for now. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20201021173749.111103-4-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | include/elf.h | 22 ++++++++++++++++++++++ | ||
14 | 1 file changed, 22 insertions(+) | ||
15 | |||
16 | diff --git a/include/elf.h b/include/elf.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/elf.h | ||
19 | +++ b/include/elf.h | ||
20 | @@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword; | ||
21 | #define PT_NOTE 4 | ||
22 | #define PT_SHLIB 5 | ||
23 | #define PT_PHDR 6 | ||
24 | +#define PT_LOOS 0x60000000 | ||
25 | +#define PT_HIOS 0x6fffffff | ||
26 | #define PT_LOPROC 0x70000000 | ||
27 | #define PT_HIPROC 0x7fffffff | ||
28 | |||
29 | +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) | ||
30 | + | ||
31 | #define PT_MIPS_REGINFO 0x70000000 | ||
32 | #define PT_MIPS_RTPROC 0x70000001 | ||
33 | #define PT_MIPS_OPTIONS 0x70000002 | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr { | ||
35 | #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ | ||
36 | #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension regs */ | ||
37 | |||
38 | +/* Defined note types for GNU systems. */ | ||
39 | + | ||
40 | +#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */ | ||
41 | + | ||
42 | +/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */ | ||
43 | + | ||
44 | +#define GNU_PROPERTY_STACK_SIZE 1 | ||
45 | +#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 | ||
46 | + | ||
47 | +#define GNU_PROPERTY_LOPROC 0xc0000000 | ||
48 | +#define GNU_PROPERTY_HIPROC 0xdfffffff | ||
49 | +#define GNU_PROPERTY_LOUSER 0xe0000000 | ||
50 | +#define GNU_PROPERTY_HIUSER 0xffffffff | ||
51 | + | ||
52 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 | ||
53 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) | ||
54 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) | ||
55 | + | ||
56 | /* | ||
57 | * Physical entry point into the kernel. | ||
58 | * | ||
59 | -- | ||
60 | 2.20.1 | ||
61 | |||
62 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Fix an unlikely memory leak in load_elf_image(). | ||
4 | |||
5 | Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-5-richard.henderson@linaro.org | ||
9 | Message-Id: <20201003174944.1972444-1-f4bug@amsat.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> | ||
13 | --- | ||
14 | linux-user/elfload.c | 8 ++++---- | ||
15 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
16 | |||
17 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/linux-user/elfload.c | ||
20 | +++ b/linux-user/elfload.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
22 | info->brk = vaddr_em; | ||
23 | } | ||
24 | } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
25 | - char *interp_name; | ||
26 | + g_autofree char *interp_name = NULL; | ||
27 | |||
28 | if (*pinterp_name) { | ||
29 | errmsg = "Multiple PT_INTERP entries"; | ||
30 | goto exit_errmsg; | ||
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 | } | ||
53 | |||
54 | #ifdef USE_ELF_CORE_DUMP | ||
55 | -- | ||
56 | 2.20.1 | ||
57 | |||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | Fixing this now will clarify following patches. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-6-richard.henderson@linaro.org | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | linux-user/elfload.c | 12 +++++++++--- | ||
11 | 1 file changed, 9 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/linux-user/elfload.c | ||
16 | +++ b/linux-user/elfload.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
18 | abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; | ||
19 | int elf_prot = 0; | ||
20 | |||
21 | - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; | ||
22 | - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; | ||
23 | - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; | ||
24 | + if (eppnt->p_flags & PF_R) { | ||
25 | + elf_prot |= PROT_READ; | ||
26 | + } | ||
27 | + if (eppnt->p_flags & PF_W) { | ||
28 | + elf_prot |= PROT_WRITE; | ||
29 | + } | ||
30 | + if (eppnt->p_flags & PF_X) { | ||
31 | + elf_prot |= PROT_EXEC; | ||
32 | + } | ||
33 | |||
34 | vaddr = load_bias + eppnt->p_vaddr; | ||
35 | vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); | ||
36 | -- | ||
37 | 2.20.1 | ||
38 | |||
39 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | The second loop uses a loop induction variable, and the first | ||
4 | does not. Transform the first to match the second, to simplify | ||
5 | a following patch moving code between them. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-7-richard.henderson@linaro.org | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | linux-user/elfload.c | 9 +++++---- | ||
13 | 1 file changed, 5 insertions(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/linux-user/elfload.c | ||
18 | +++ b/linux-user/elfload.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
20 | loaddr = -1, hiaddr = 0; | ||
21 | info->alignment = 0; | ||
22 | for (i = 0; i < ehdr->e_phnum; ++i) { | ||
23 | - if (phdr[i].p_type == PT_LOAD) { | ||
24 | - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; | ||
25 | + struct elf_phdr *eppnt = phdr + i; | ||
26 | + if (eppnt->p_type == PT_LOAD) { | ||
27 | + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset; | ||
28 | if (a < loaddr) { | ||
29 | loaddr = a; | ||
30 | } | ||
31 | - a = phdr[i].p_vaddr + phdr[i].p_memsz; | ||
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 | |||
42 | -- | ||
43 | 2.20.1 | ||
44 | |||
45 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Roman Bolshakov <r.bolshakov@yadro.com> |
---|---|---|---|
2 | 2 | ||
3 | For BTI, we need to know if the executable is static or dynamic, | 3 | QEMU documentation can't be opened if QEMU is run from build tree |
4 | which means looking for PT_INTERP earlier. | 4 | because executables are placed in the top of build tree after conversion |
5 | to meson. | ||
5 | 6 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> |
7 | Message-id: 20201021173749.111103-8-richard.henderson@linaro.org | 8 | Reported-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Message-id: 20210108213815.64678-1-r.bolshakov@yadro.com | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 12 | --- |
11 | linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- | 13 | ui/cocoa.m | 2 +- |
12 | 1 file changed, 31 insertions(+), 29 deletions(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 16 | diff --git a/ui/cocoa.m b/ui/cocoa.m |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/elfload.c | 18 | --- a/ui/cocoa.m |
17 | +++ b/linux-user/elfload.c | 19 | +++ b/ui/cocoa.m |
18 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | 20 | @@ -XXX,XX +XXX,XX @@ QemuCocoaView *cocoaView; |
19 | 21 | - (void) openDocumentation: (NSString *) filename | |
20 | mmap_lock(); | 22 | { |
21 | 23 | /* Where to look for local files */ | |
22 | - /* Find the maximum size of the image and allocate an appropriate | 24 | - NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"../docs/"}; |
23 | - amount of memory to handle that. */ | 25 | + NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"docs/"}; |
24 | + /* | 26 | NSString *full_file_path; |
25 | + * Find the maximum size of the image and allocate an appropriate | 27 | |
26 | + * amount of memory to handle that. Locate the interpreter, if any. | 28 | /* iterate thru the possible paths until the file is found */ |
27 | + */ | ||
28 | loaddr = -1, hiaddr = 0; | ||
29 | info->alignment = 0; | ||
30 | for (i = 0; i < ehdr->e_phnum; ++i) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
32 | } | ||
33 | ++info->nsegs; | ||
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 | } | ||
69 | - } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
70 | - g_autofree char *interp_name = NULL; | ||
71 | - | ||
72 | - if (*pinterp_name) { | ||
73 | - errmsg = "Multiple PT_INTERP entries"; | ||
74 | - goto exit_errmsg; | ||
75 | - } | ||
76 | - interp_name = g_malloc(eppnt->p_filesz); | ||
77 | - if (!interp_name) { | ||
78 | - goto exit_perror; | ||
79 | - } | ||
80 | - | ||
81 | - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
82 | - memcpy(interp_name, bprm_buf + eppnt->p_offset, | ||
83 | - eppnt->p_filesz); | ||
84 | - } else { | ||
85 | - retval = pread(image_fd, interp_name, eppnt->p_filesz, | ||
86 | - eppnt->p_offset); | ||
87 | - if (retval != eppnt->p_filesz) { | ||
88 | - goto exit_perror; | ||
89 | - } | ||
90 | - } | ||
91 | - if (interp_name[eppnt->p_filesz - 1] != 0) { | ||
92 | - errmsg = "Invalid PT_INTERP entry"; | ||
93 | - goto exit_errmsg; | ||
94 | - } | ||
95 | - *pinterp_name = g_steal_pointer(&interp_name); | ||
96 | #ifdef TARGET_MIPS | ||
97 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
98 | Mips_elf_abiflags_v0 abiflags; | ||
99 | -- | 29 | -- |
100 | 2.20.1 | 30 | 2.20.1 |
101 | 31 | ||
102 | 32 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | This is a bit clearer than open-coding some of this | ||
4 | with a bare c string. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20201021173749.111103-9-richard.henderson@linaro.org | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | linux-user/elfload.c | 37 ++++++++++++++++++++----------------- | ||
12 | 1 file changed, 20 insertions(+), 17 deletions(-) | ||
13 | |||
14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/linux-user/elfload.c | ||
17 | +++ b/linux-user/elfload.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "qemu/guest-random.h" | ||
20 | #include "qemu/units.h" | ||
21 | #include "qemu/selfmap.h" | ||
22 | +#include "qapi/error.h" | ||
23 | |||
24 | #ifdef _ARCH_PPC64 | ||
25 | #undef ARCH_DLINFO | ||
26 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
27 | struct elf_phdr *phdr; | ||
28 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; | ||
29 | int i, retval; | ||
30 | - const char *errmsg; | ||
31 | + Error *err = NULL; | ||
32 | |||
33 | /* First of all, some simple consistency checks */ | ||
34 | - errmsg = "Invalid ELF image for this architecture"; | ||
35 | if (!elf_check_ident(ehdr)) { | ||
36 | + error_setg(&err, "Invalid ELF image for this architecture"); | ||
37 | goto exit_errmsg; | ||
38 | } | ||
39 | bswap_ehdr(ehdr); | ||
40 | if (!elf_check_ehdr(ehdr)) { | ||
41 | + error_setg(&err, "Invalid ELF image for this architecture"); | ||
42 | goto exit_errmsg; | ||
43 | } | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
46 | g_autofree char *interp_name = NULL; | ||
47 | |||
48 | if (*pinterp_name) { | ||
49 | - errmsg = "Multiple PT_INTERP entries"; | ||
50 | + error_setg(&err, "Multiple PT_INTERP entries"); | ||
51 | goto exit_errmsg; | ||
52 | } | ||
53 | + | ||
54 | interp_name = g_malloc(eppnt->p_filesz); | ||
55 | - if (!interp_name) { | ||
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 | } | ||
82 | load_bias = load_addr - loaddr; | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
85 | image_fd, eppnt->p_offset - vaddr_po); | ||
86 | |||
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 | } | ||
121 | - exit_perror: | ||
122 | - errmsg = strerror(errno); | ||
123 | + goto exit_errmsg; | ||
124 | + exit_mmap: | ||
125 | + error_setg_errno(&err, errno, "Error mapping file"); | ||
126 | + goto exit_errmsg; | ||
127 | exit_errmsg: | ||
128 | - fprintf(stderr, "%s: %s\n", image_name, errmsg); | ||
129 | + error_reportf_err(err, "%s: ", image_name); | ||
130 | exit(-1); | ||
131 | } | ||
132 | |||
133 | -- | ||
134 | 2.20.1 | ||
135 | |||
136 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | This is slightly clearer than just using strerror, though | ||
4 | the different forms produced by error_setg_file_open and | ||
5 | error_setg_errno isn't entirely convenient. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-10-richard.henderson@linaro.org | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | linux-user/elfload.c | 15 ++++++++------- | ||
13 | 1 file changed, 8 insertions(+), 7 deletions(-) | ||
14 | |||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/linux-user/elfload.c | ||
18 | +++ b/linux-user/elfload.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info, | ||
20 | char bprm_buf[BPRM_BUF_SIZE]) | ||
21 | { | ||
22 | int fd, retval; | ||
23 | + Error *err = NULL; | ||
24 | |||
25 | fd = open(path(filename), O_RDONLY); | ||
26 | if (fd < 0) { | ||
27 | - goto exit_perror; | ||
28 | + error_setg_file_open(&err, errno, filename); | ||
29 | + error_report_err(err); | ||
30 | + exit(-1); | ||
31 | } | ||
32 | |||
33 | retval = read(fd, bprm_buf, BPRM_BUF_SIZE); | ||
34 | if (retval < 0) { | ||
35 | - goto exit_perror; | ||
36 | + error_setg_errno(&err, errno, "Error reading file header"); | ||
37 | + error_reportf_err(err, "%s: ", filename); | ||
38 | + exit(-1); | ||
39 | } | ||
40 | + | ||
41 | if (retval < BPRM_BUF_SIZE) { | ||
42 | memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); | ||
43 | } | ||
44 | |||
45 | load_elf_image(filename, fd, info, NULL, bprm_buf); | ||
46 | - return; | ||
47 | - | ||
48 | - exit_perror: | ||
49 | - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); | ||
50 | - exit(-1); | ||
51 | } | ||
52 | |||
53 | static int symfind(const void *s0, const void *s1) | ||
54 | -- | ||
55 | 2.20.1 | ||
56 | |||
57 | diff view generated by jsdifflib |
1 | In ptimer_reload(), we call the callback function provided by the | 1 | In commit 1982e1602d15 we added a new qemu-storage-daemon(1) manpage. |
---|---|---|---|
2 | timer device that is using the ptimer. This callback might disable | 2 | At the moment new manpages have to be listed both in the conf.py for |
3 | the ptimer. The code mostly handles this correctly, except that | 3 | Sphinx and also in docs/meson.build for Meson. We forgot the second |
4 | we'll still print the warning about "Timer with delta zero, | 4 | of those -- correct the omission. |
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 | |||
9 | Suppress the spurious warning message and the unnecessary | ||
10 | repeat-deletion of the underlying timer in this case. | ||
11 | 5 | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
14 | Message-id: 20201015151829.14656-2-peter.maydell@linaro.org | 8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
9 | Message-id: 20210108161416.21129-2-peter.maydell@linaro.org | ||
15 | --- | 10 | --- |
16 | hw/core/ptimer.c | 4 ++++ | 11 | docs/meson.build | 1 + |
17 | 1 file changed, 4 insertions(+) | 12 | 1 file changed, 1 insertion(+) |
18 | 13 | ||
19 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c | 14 | diff --git a/docs/meson.build b/docs/meson.build |
20 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/core/ptimer.c | 16 | --- a/docs/meson.build |
22 | +++ b/hw/core/ptimer.c | 17 | +++ b/docs/meson.build |
23 | @@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) | 18 | @@ -XXX,XX +XXX,XX @@ if build_docs |
24 | } | 19 | 'qemu-img.1': (have_tools ? 'man1' : ''), |
25 | 20 | 'qemu-nbd.8': (have_tools ? 'man8' : ''), | |
26 | if (delta == 0) { | 21 | 'qemu-pr-helper.8': (have_tools ? 'man8' : ''), |
27 | + if (s->enabled == 0) { | 22 | + 'qemu-storage-daemon.1': (have_tools ? 'man1' : ''), |
28 | + /* trigger callback disabled the timer already */ | 23 | 'qemu-trace-stap.1': (config_host.has_key('CONFIG_TRACE_SYSTEMTAP') ? 'man1' : ''), |
29 | + return; | 24 | 'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''), |
30 | + } | 25 | 'virtiofsd.1': (have_virtiofsd ? 'man1' : ''), |
31 | if (!qtest_enabled()) { | ||
32 | fprintf(stderr, "Timer with delta zero, disabling\n"); | ||
33 | } | ||
34 | -- | 26 | -- |
35 | 2.20.1 | 27 | 2.20.1 |
36 | 28 | ||
37 | 29 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | When we first converted our documentation to Sphinx, we split it into |
---|---|---|---|
2 | 2 | multiple manuals (system, interop, tools, etc), which are all built | |
3 | A clock mux can be configured to select one of its 10 sources through | 3 | separately. The primary driver for this was wanting to be able to |
4 | the CM_CTL register. It also embeds yet another clock divider, composed | 4 | avoid shipping the 'devel' manual to end-users. However, this is |
5 | of an integer part and a fractional part. The number of bits of each | 5 | working against the grain of the way Sphinx wants to be used and |
6 | part is mux dependent. | 6 | causes some annoyances: |
7 | 7 | * Cross-references between documents become much harder or | |
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | possibly impossible |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 9 | * There is no single index to the whole documentation |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 10 | * Within one manual there's no links or table-of-contents info |
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 11 | that lets you easily navigate to the others |
12 | * The devel manual doesn't get published on the QEMU website | ||
13 | (it would be nice to able to refer to it there) | ||
14 | |||
15 | Merely hiding our developer documentation from end users seems like | ||
16 | it's not enough benefit for these costs. Combine all the | ||
17 | documentation into a single manual (the same way that the readthedocs | ||
18 | site builds it) and install the whole thing. The previous manual | ||
19 | divisions remain as the new top level sections in the manual. | ||
20 | |||
21 | * The per-manual conf.py files are no longer needed | ||
22 | * The man_pages[] specifications previously in each per-manual | ||
23 | conf.py move to the top level conf.py | ||
24 | * docs/meson.build logic is simplified as we now only need to run | ||
25 | Sphinx once for the HTML and then once for the manpages5B | ||
26 | * The old index.html.in that produced the top-level page with | ||
27 | links to each manual is no longer needed | ||
28 | |||
29 | Unfortunately this means that we now have to build the HTML | ||
30 | documentation into docs/manual in the build tree rather than directly | ||
31 | into docs/; otherwise it is too awkward to ensure we install only the | ||
32 | built manual and not also the dependency info, stamp file, etc. The | ||
33 | manual still ends up in the same place in the final installed | ||
34 | directory, but anybody who was consulting documentation from within | ||
35 | the build tree will have to adjust where they're looking. | ||
36 | |||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 37 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
38 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
39 | Message-id: 20210108161416.21129-3-peter.maydell@linaro.org | ||
13 | --- | 40 | --- |
14 | hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- | 41 | docs/conf.py | 46 ++++++++++++++++++++++++++++++- |
15 | 1 file changed, 52 insertions(+), 1 deletion(-) | 42 | docs/devel/conf.py | 15 ----------- |
16 | 43 | docs/index.html.in | 17 ------------ | |
17 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 44 | docs/interop/conf.py | 28 ------------------- |
45 | docs/meson.build | 64 +++++++++++++++++--------------------------- | ||
46 | docs/specs/conf.py | 16 ----------- | ||
47 | docs/system/conf.py | 28 ------------------- | ||
48 | docs/tools/conf.py | 37 ------------------------- | ||
49 | docs/user/conf.py | 15 ----------- | ||
50 | 9 files changed, 70 insertions(+), 196 deletions(-) | ||
51 | delete mode 100644 docs/devel/conf.py | ||
52 | delete mode 100644 docs/index.html.in | ||
53 | delete mode 100644 docs/interop/conf.py | ||
54 | delete mode 100644 docs/specs/conf.py | ||
55 | delete mode 100644 docs/system/conf.py | ||
56 | delete mode 100644 docs/tools/conf.py | ||
57 | delete mode 100644 docs/user/conf.py | ||
58 | |||
59 | diff --git a/docs/conf.py b/docs/conf.py | ||
18 | index XXXXXXX..XXXXXXX 100644 | 60 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/misc/bcm2835_cprman.c | 61 | --- a/docs/conf.py |
20 | +++ b/hw/misc/bcm2835_cprman.c | 62 | +++ b/docs/conf.py |
21 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { | 63 | @@ -XXX,XX +XXX,XX @@ latex_documents = [ |
22 | 64 | ||
23 | /* clock mux */ | 65 | # -- Options for manual page output --------------------------------------- |
24 | 66 | # Individual manual/conf.py can override this to create man pages | |
25 | +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) | 67 | -man_pages = [] |
26 | +{ | 68 | +man_pages = [ |
27 | + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); | 69 | + ('interop/qemu-ga', 'qemu-ga', |
28 | +} | 70 | + 'QEMU Guest Agent', |
71 | + ['Michael Roth <mdroth@linux.vnet.ibm.com>'], 8), | ||
72 | + ('interop/qemu-ga-ref', 'qemu-ga-ref', | ||
73 | + 'QEMU Guest Agent Protocol Reference', | ||
74 | + [], 7), | ||
75 | + ('interop/qemu-qmp-ref', 'qemu-qmp-ref', | ||
76 | + 'QEMU QMP Reference Manual', | ||
77 | + [], 7), | ||
78 | + ('interop/qemu-storage-daemon-qmp-ref', 'qemu-storage-daemon-qmp-ref', | ||
79 | + 'QEMU Storage Daemon QMP Reference Manual', | ||
80 | + [], 7), | ||
81 | + ('system/qemu-manpage', 'qemu', | ||
82 | + 'QEMU User Documentation', | ||
83 | + ['Fabrice Bellard'], 1), | ||
84 | + ('system/qemu-block-drivers', 'qemu-block-drivers', | ||
85 | + 'QEMU block drivers reference', | ||
86 | + ['Fabrice Bellard and the QEMU Project developers'], 7), | ||
87 | + ('system/qemu-cpu-models', 'qemu-cpu-models', | ||
88 | + 'QEMU CPU Models', | ||
89 | + ['The QEMU Project developers'], 7), | ||
90 | + ('tools/qemu-img', 'qemu-img', | ||
91 | + 'QEMU disk image utility', | ||
92 | + ['Fabrice Bellard'], 1), | ||
93 | + ('tools/qemu-nbd', 'qemu-nbd', | ||
94 | + 'QEMU Disk Network Block Device Server', | ||
95 | + ['Anthony Liguori <anthony@codemonkey.ws>'], 8), | ||
96 | + ('tools/qemu-pr-helper', 'qemu-pr-helper', | ||
97 | + 'QEMU persistent reservation helper', | ||
98 | + [], 8), | ||
99 | + ('tools/qemu-storage-daemon', 'qemu-storage-daemon', | ||
100 | + 'QEMU storage daemon', | ||
101 | + [], 1), | ||
102 | + ('tools/qemu-trace-stap', 'qemu-trace-stap', | ||
103 | + 'QEMU SystemTap trace tool', | ||
104 | + [], 1), | ||
105 | + ('tools/virtfs-proxy-helper', 'virtfs-proxy-helper', | ||
106 | + 'QEMU 9p virtfs proxy filesystem helper', | ||
107 | + ['M. Mohan Kumar'], 1), | ||
108 | + ('tools/virtiofsd', 'virtiofsd', | ||
109 | + 'QEMU virtio-fs shared file system daemon', | ||
110 | + ['Stefan Hajnoczi <stefanha@redhat.com>', | ||
111 | + 'Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>'], 1), | ||
112 | +] | ||
113 | |||
114 | # -- Options for Texinfo output ------------------------------------------- | ||
115 | |||
116 | diff --git a/docs/devel/conf.py b/docs/devel/conf.py | ||
117 | deleted file mode 100644 | ||
118 | index XXXXXXX..XXXXXXX | ||
119 | --- a/docs/devel/conf.py | ||
120 | +++ /dev/null | ||
121 | @@ -XXX,XX +XXX,XX @@ | ||
122 | -# -*- coding: utf-8 -*- | ||
123 | -# | ||
124 | -# QEMU documentation build configuration file for the 'devel' manual. | ||
125 | -# | ||
126 | -# This includes the top level conf file and then makes any necessary tweaks. | ||
127 | -import sys | ||
128 | -import os | ||
129 | - | ||
130 | -qemu_docdir = os.path.abspath("..") | ||
131 | -parent_config = os.path.join(qemu_docdir, "conf.py") | ||
132 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) | ||
133 | - | ||
134 | -# This slightly misuses the 'description', but is the best way to get | ||
135 | -# the manual title to appear in the sidebar. | ||
136 | -html_theme_options['description'] = u'Developer''s Guide' | ||
137 | diff --git a/docs/index.html.in b/docs/index.html.in | ||
138 | deleted file mode 100644 | ||
139 | index XXXXXXX..XXXXXXX | ||
140 | --- a/docs/index.html.in | ||
141 | +++ /dev/null | ||
142 | @@ -XXX,XX +XXX,XX @@ | ||
143 | -<!DOCTYPE html> | ||
144 | -<html lang="en"> | ||
145 | - <head> | ||
146 | - <meta charset="UTF-8"> | ||
147 | - <title>QEMU @VERSION@ Documentation</title> | ||
148 | - </head> | ||
149 | - <body> | ||
150 | - <h1>QEMU @VERSION@ Documentation</h1> | ||
151 | - <ul> | ||
152 | - <li><a href="system/index.html">System Emulation User's Guide</a></li> | ||
153 | - <li><a href="user/index.html">User Mode Emulation User's Guide</a></li> | ||
154 | - <li><a href="tools/index.html">Tools Guide</a></li> | ||
155 | - <li><a href="interop/index.html">System Emulation Management and Interoperability Guide</a></li> | ||
156 | - <li><a href="specs/index.html">System Emulation Guest Hardware Specifications</a></li> | ||
157 | - </ul> | ||
158 | - </body> | ||
159 | -</html> | ||
160 | diff --git a/docs/interop/conf.py b/docs/interop/conf.py | ||
161 | deleted file mode 100644 | ||
162 | index XXXXXXX..XXXXXXX | ||
163 | --- a/docs/interop/conf.py | ||
164 | +++ /dev/null | ||
165 | @@ -XXX,XX +XXX,XX @@ | ||
166 | -# -*- coding: utf-8 -*- | ||
167 | -# | ||
168 | -# QEMU documentation build configuration file for the 'interop' manual. | ||
169 | -# | ||
170 | -# This includes the top level conf file and then makes any necessary tweaks. | ||
171 | -import sys | ||
172 | -import os | ||
173 | - | ||
174 | -qemu_docdir = os.path.abspath("..") | ||
175 | -parent_config = os.path.join(qemu_docdir, "conf.py") | ||
176 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) | ||
177 | - | ||
178 | -# This slightly misuses the 'description', but is the best way to get | ||
179 | -# the manual title to appear in the sidebar. | ||
180 | -html_theme_options['description'] = u'System Emulation Management and Interoperability Guide' | ||
181 | - | ||
182 | -# One entry per manual page. List of tuples | ||
183 | -# (source start file, name, description, authors, manual section). | ||
184 | -man_pages = [ | ||
185 | - ('qemu-ga', 'qemu-ga', u'QEMU Guest Agent', | ||
186 | - ['Michael Roth <mdroth@linux.vnet.ibm.com>'], 8), | ||
187 | - ('qemu-ga-ref', 'qemu-ga-ref', 'QEMU Guest Agent Protocol Reference', | ||
188 | - [], 7), | ||
189 | - ('qemu-qmp-ref', 'qemu-qmp-ref', 'QEMU QMP Reference Manual', | ||
190 | - [], 7), | ||
191 | - ('qemu-storage-daemon-qmp-ref', 'qemu-storage-daemon-qmp-ref', | ||
192 | - 'QEMU Storage Daemon QMP Reference Manual', [], 7), | ||
193 | -] | ||
194 | diff --git a/docs/meson.build b/docs/meson.build | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/docs/meson.build | ||
197 | +++ b/docs/meson.build | ||
198 | @@ -XXX,XX +XXX,XX @@ if build_docs | ||
199 | meson.source_root() / 'docs/sphinx/qmp_lexer.py', | ||
200 | qapi_gen_depends ] | ||
201 | |||
202 | - configure_file(output: 'index.html', | ||
203 | - input: files('index.html.in'), | ||
204 | - configuration: {'VERSION': meson.project_version()}, | ||
205 | - install_dir: qemu_docdir) | ||
206 | - manuals = [ 'devel', 'interop', 'tools', 'specs', 'system', 'user' ] | ||
207 | man_pages = { | ||
208 | - 'interop' : { | ||
209 | 'qemu-ga.8': (have_tools ? 'man8' : ''), | ||
210 | 'qemu-ga-ref.7': 'man7', | ||
211 | 'qemu-qmp-ref.7': 'man7', | ||
212 | 'qemu-storage-daemon-qmp-ref.7': (have_tools ? 'man7' : ''), | ||
213 | - }, | ||
214 | - 'tools': { | ||
215 | 'qemu-img.1': (have_tools ? 'man1' : ''), | ||
216 | 'qemu-nbd.8': (have_tools ? 'man8' : ''), | ||
217 | 'qemu-pr-helper.8': (have_tools ? 'man8' : ''), | ||
218 | @@ -XXX,XX +XXX,XX @@ if build_docs | ||
219 | 'qemu-trace-stap.1': (config_host.has_key('CONFIG_TRACE_SYSTEMTAP') ? 'man1' : ''), | ||
220 | 'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''), | ||
221 | 'virtiofsd.1': (have_virtiofsd ? 'man1' : ''), | ||
222 | - }, | ||
223 | - 'system': { | ||
224 | 'qemu.1': 'man1', | ||
225 | 'qemu-block-drivers.7': 'man7', | ||
226 | 'qemu-cpu-models.7': 'man7' | ||
227 | - }, | ||
228 | } | ||
229 | |||
230 | sphinxdocs = [] | ||
231 | sphinxmans = [] | ||
232 | - foreach manual : manuals | ||
233 | - private_dir = meson.current_build_dir() / (manual + '.p') | ||
234 | - output_dir = meson.current_build_dir() / manual | ||
235 | - input_dir = meson.current_source_dir() / manual | ||
236 | |||
237 | - this_manual = custom_target(manual + ' manual', | ||
238 | + private_dir = meson.current_build_dir() / 'manual.p' | ||
239 | + output_dir = meson.current_build_dir() / 'manual' | ||
240 | + input_dir = meson.current_source_dir() | ||
29 | + | 241 | + |
30 | static void clock_mux_update(CprmanClockMuxState *mux) | 242 | + this_manual = custom_target('QEMU manual', |
31 | { | 243 | build_by_default: build_docs, |
32 | - clock_update(mux->out, 0); | 244 | - output: [manual + '.stamp'], |
33 | + uint64_t freq; | 245 | - input: [files('conf.py'), files(manual / 'conf.py')], |
34 | + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); | 246 | - depfile: manual + '.d', |
35 | + bool enabled = clock_mux_is_enabled(mux); | 247 | + output: 'docs.stamp', |
248 | + input: files('conf.py'), | ||
249 | + depfile: 'docs.d', | ||
250 | depend_files: sphinx_extn_depends, | ||
251 | command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@', | ||
252 | '-Ddepfile_stamp=@OUTPUT0@', | ||
253 | '-b', 'html', '-d', private_dir, | ||
254 | input_dir, output_dir]) | ||
255 | - sphinxdocs += this_manual | ||
256 | - if build_docs and manual != 'devel' | ||
257 | - install_subdir(output_dir, install_dir: qemu_docdir) | ||
258 | - endif | ||
259 | + sphinxdocs += this_manual | ||
260 | + install_subdir(output_dir, install_dir: qemu_docdir, strip_directory: true) | ||
261 | |||
262 | - these_man_pages = [] | ||
263 | - install_dirs = [] | ||
264 | - foreach page, section : man_pages.get(manual, {}) | ||
265 | - these_man_pages += page | ||
266 | - install_dirs += section == '' ? false : get_option('mandir') / section | ||
267 | - endforeach | ||
268 | - if these_man_pages.length() > 0 | ||
269 | - sphinxmans += custom_target(manual + ' man pages', | ||
270 | - build_by_default: build_docs, | ||
271 | - output: these_man_pages, | ||
272 | - input: this_manual, | ||
273 | - install: build_docs, | ||
274 | - install_dir: install_dirs, | ||
275 | - command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir, | ||
276 | - input_dir, meson.current_build_dir()]) | ||
277 | - endif | ||
278 | + these_man_pages = [] | ||
279 | + install_dirs = [] | ||
280 | + foreach page, section : man_pages | ||
281 | + these_man_pages += page | ||
282 | + install_dirs += section == '' ? false : get_option('mandir') / section | ||
283 | endforeach | ||
36 | + | 284 | + |
37 | + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); | 285 | + sphinxmans += custom_target('QEMU man pages', |
286 | + build_by_default: build_docs, | ||
287 | + output: these_man_pages, | ||
288 | + input: this_manual, | ||
289 | + install: build_docs, | ||
290 | + install_dir: install_dirs, | ||
291 | + command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir, | ||
292 | + input_dir, meson.current_build_dir()]) | ||
38 | + | 293 | + |
39 | + if (!enabled) { | 294 | alias_target('sphinxdocs', sphinxdocs) |
40 | + clock_update(mux->out, 0); | 295 | alias_target('html', sphinxdocs) |
41 | + return; | 296 | alias_target('man', sphinxmans) |
42 | + } | 297 | diff --git a/docs/specs/conf.py b/docs/specs/conf.py |
43 | + | 298 | deleted file mode 100644 |
44 | + freq = clock_get_hz(mux->srcs[src]); | 299 | index XXXXXXX..XXXXXXX |
45 | + | 300 | --- a/docs/specs/conf.py |
46 | + if (mux->int_bits == 0 && mux->frac_bits == 0) { | 301 | +++ /dev/null |
47 | + clock_update_hz(mux->out, freq); | 302 | @@ -XXX,XX +XXX,XX @@ |
48 | + return; | 303 | -# -*- coding: utf-8 -*- |
49 | + } | 304 | -# |
50 | + | 305 | -# QEMU documentation build configuration file for the 'specs' manual. |
51 | + /* | 306 | -# |
52 | + * The divider has an integer and a fractional part. The size of each part | 307 | -# This includes the top level conf file and then makes any necessary tweaks. |
53 | + * varies with the muxes (int_bits and frac_bits). Both parts are | 308 | -import sys |
54 | + * concatenated, with the integer part always starting at bit 12. | 309 | -import os |
55 | + * | 310 | - |
56 | + * 31 12 11 0 | 311 | -qemu_docdir = os.path.abspath("..") |
57 | + * ------------------------------ | 312 | -parent_config = os.path.join(qemu_docdir, "conf.py") |
58 | + * CM_DIV | | int | frac | | | 313 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) |
59 | + * ------------------------------ | 314 | - |
60 | + * <-----> <------> | 315 | -# This slightly misuses the 'description', but is the best way to get |
61 | + * int_bits frac_bits | 316 | -# the manual title to appear in the sidebar. |
62 | + */ | 317 | -html_theme_options['description'] = \ |
63 | + div = extract32(*mux->reg_div, | 318 | - u'System Emulation Guest Hardware Specifications' |
64 | + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, | 319 | diff --git a/docs/system/conf.py b/docs/system/conf.py |
65 | + mux->int_bits + mux->frac_bits); | 320 | deleted file mode 100644 |
66 | + | 321 | index XXXXXXX..XXXXXXX |
67 | + if (!div) { | 322 | --- a/docs/system/conf.py |
68 | + clock_update(mux->out, 0); | 323 | +++ /dev/null |
69 | + return; | 324 | @@ -XXX,XX +XXX,XX @@ |
70 | + } | 325 | -# -*- coding: utf-8 -*- |
71 | + | 326 | -# |
72 | + freq = muldiv64(freq, 1 << mux->frac_bits, div); | 327 | -# QEMU documentation build configuration file for the 'system' manual. |
73 | + | 328 | -# |
74 | + clock_update_hz(mux->out, freq); | 329 | -# This includes the top level conf file and then makes any necessary tweaks. |
75 | } | 330 | -import sys |
76 | 331 | -import os | |
77 | static void clock_mux_src_update(void *opaque) | 332 | - |
78 | { | 333 | -qemu_docdir = os.path.abspath("..") |
79 | CprmanClockMuxState **backref = opaque; | 334 | -parent_config = os.path.join(qemu_docdir, "conf.py") |
80 | CprmanClockMuxState *s = *backref; | 335 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) |
81 | + CprmanClockMuxSource src = backref - s->backref; | 336 | - |
82 | + | 337 | -# This slightly misuses the 'description', but is the best way to get |
83 | + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { | 338 | -# the manual title to appear in the sidebar. |
84 | + return; | 339 | -html_theme_options['description'] = u'System Emulation User''s Guide' |
85 | + } | 340 | - |
86 | 341 | -# One entry per manual page. List of tuples | |
87 | clock_mux_update(s); | 342 | -# (source start file, name, description, authors, manual section). |
88 | } | 343 | -man_pages = [ |
344 | - ('qemu-manpage', 'qemu', u'QEMU User Documentation', | ||
345 | - ['Fabrice Bellard'], 1), | ||
346 | - ('qemu-block-drivers', 'qemu-block-drivers', | ||
347 | - u'QEMU block drivers reference', | ||
348 | - ['Fabrice Bellard and the QEMU Project developers'], 7), | ||
349 | - ('qemu-cpu-models', 'qemu-cpu-models', | ||
350 | - u'QEMU CPU Models', | ||
351 | - ['The QEMU Project developers'], 7) | ||
352 | -] | ||
353 | diff --git a/docs/tools/conf.py b/docs/tools/conf.py | ||
354 | deleted file mode 100644 | ||
355 | index XXXXXXX..XXXXXXX | ||
356 | --- a/docs/tools/conf.py | ||
357 | +++ /dev/null | ||
358 | @@ -XXX,XX +XXX,XX @@ | ||
359 | -# -*- coding: utf-8 -*- | ||
360 | -# | ||
361 | -# QEMU documentation build configuration file for the 'tools' manual. | ||
362 | -# | ||
363 | -# This includes the top level conf file and then makes any necessary tweaks. | ||
364 | -import sys | ||
365 | -import os | ||
366 | - | ||
367 | -qemu_docdir = os.path.abspath("..") | ||
368 | -parent_config = os.path.join(qemu_docdir, "conf.py") | ||
369 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) | ||
370 | - | ||
371 | -# This slightly misuses the 'description', but is the best way to get | ||
372 | -# the manual title to appear in the sidebar. | ||
373 | -html_theme_options['description'] = \ | ||
374 | - u'Tools Guide' | ||
375 | - | ||
376 | -# One entry per manual page. List of tuples | ||
377 | -# (source start file, name, description, authors, manual section). | ||
378 | -man_pages = [ | ||
379 | - ('qemu-img', 'qemu-img', u'QEMU disk image utility', | ||
380 | - ['Fabrice Bellard'], 1), | ||
381 | - ('qemu-storage-daemon', 'qemu-storage-daemon', u'QEMU storage daemon', | ||
382 | - [], 1), | ||
383 | - ('qemu-nbd', 'qemu-nbd', u'QEMU Disk Network Block Device Server', | ||
384 | - ['Anthony Liguori <anthony@codemonkey.ws>'], 8), | ||
385 | - ('qemu-pr-helper', 'qemu-pr-helper', 'QEMU persistent reservation helper', | ||
386 | - [], 8), | ||
387 | - ('qemu-trace-stap', 'qemu-trace-stap', u'QEMU SystemTap trace tool', | ||
388 | - [], 1), | ||
389 | - ('virtfs-proxy-helper', 'virtfs-proxy-helper', | ||
390 | - u'QEMU 9p virtfs proxy filesystem helper', | ||
391 | - ['M. Mohan Kumar'], 1), | ||
392 | - ('virtiofsd', 'virtiofsd', u'QEMU virtio-fs shared file system daemon', | ||
393 | - ['Stefan Hajnoczi <stefanha@redhat.com>', | ||
394 | - 'Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>'], 1), | ||
395 | -] | ||
396 | diff --git a/docs/user/conf.py b/docs/user/conf.py | ||
397 | deleted file mode 100644 | ||
398 | index XXXXXXX..XXXXXXX | ||
399 | --- a/docs/user/conf.py | ||
400 | +++ /dev/null | ||
401 | @@ -XXX,XX +XXX,XX @@ | ||
402 | -# -*- coding: utf-8 -*- | ||
403 | -# | ||
404 | -# QEMU documentation build configuration file for the 'user' manual. | ||
405 | -# | ||
406 | -# This includes the top level conf file and then makes any necessary tweaks. | ||
407 | -import sys | ||
408 | -import os | ||
409 | - | ||
410 | -qemu_docdir = os.path.abspath("..") | ||
411 | -parent_config = os.path.join(qemu_docdir, "conf.py") | ||
412 | -exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) | ||
413 | - | ||
414 | -# This slightly misuses the 'description', but is the best way to get | ||
415 | -# the manual title to appear in the sidebar. | ||
416 | -html_theme_options['description'] = u'User Mode Emulation User''s Guide' | ||
89 | -- | 417 | -- |
90 | 2.20.1 | 418 | 2.20.1 |
91 | 419 | ||
92 | 420 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | In commit cd8be50e58f63413c0 we converted the A32 coprocessor |
---|---|---|---|
2 | insns to decodetree. This accidentally broke XScale/iWMMXt insns, | ||
3 | because it moved the handling of "cp insns which are handled | ||
4 | by looking up the cp register in the hashtable" from after the | ||
5 | call to the legacy disas_xscale_insn() decode to before it, | ||
6 | with the result that all XScale/iWMMXt insns now UNDEF. | ||
2 | 7 | ||
3 | This is generic support, with the code disabled for all targets. | 8 | Update valid_cp() so that it knows that on XScale cp 0 and 1 |
9 | are not standard coprocessor instructions; this will cause | ||
10 | the decodetree trans_ functions to ignore them, so that | ||
11 | execution will correctly get through to the legacy decode again. | ||
4 | 12 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Cc: qemu-stable@nongnu.org |
6 | Message-id: 20201021173749.111103-11-richard.henderson@linaro.org | 14 | Reported-by: Guenter Roeck <linux@roeck-us.net> |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
18 | Message-id: 20210108195157.32067-1-peter.maydell@linaro.org | ||
9 | --- | 19 | --- |
10 | linux-user/qemu.h | 4 ++ | 20 | target/arm/translate.c | 7 +++++++ |
11 | linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ | 21 | 1 file changed, 7 insertions(+) |
12 | 2 files changed, 161 insertions(+) | ||
13 | 22 | ||
14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | 23 | diff --git a/target/arm/translate.c b/target/arm/translate.c |
15 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/linux-user/qemu.h | 25 | --- a/target/arm/translate.c |
17 | +++ b/linux-user/qemu.h | 26 | +++ b/target/arm/translate.c |
18 | @@ -XXX,XX +XXX,XX @@ struct image_info { | 27 | @@ -XXX,XX +XXX,XX @@ static bool valid_cp(DisasContext *s, int cp) |
19 | abi_ulong interpreter_loadmap_addr; | 28 | * only cp14 and cp15 are valid, and other values aren't considered |
20 | abi_ulong interpreter_pt_dynamic_addr; | 29 | * to be in the coprocessor-instruction space at all. v8M still |
21 | struct image_info *other_info; | 30 | * permits coprocessors 0..7. |
22 | + | 31 | + * For XScale, we must not decode the XScale cp0, cp1 space as |
23 | + /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */ | 32 | + * a standard coprocessor insn, because we want to fall through to |
24 | + uint32_t note_flags; | 33 | + * the legacy disas_xscale_insn() decoder after decodetree is done. |
25 | + | 34 | */ |
26 | #ifdef TARGET_MIPS | 35 | + if (arm_dc_feature(s, ARM_FEATURE_XSCALE) && (cp == 0 || cp == 1)) { |
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 | { | ||
48 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ | ||
49 | @@ -XXX,XX +XXX,XX @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, | ||
50 | "@ 0x%" PRIx64 "\n", (uint64_t)guest_base); | ||
51 | } | ||
52 | |||
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; | ||
97 | + } | ||
98 | + *prev_type = pr_type; | ||
99 | + | ||
100 | + if (!arch_parse_elf_property(pr_type, pr_datasz, data, info, errp)) { | ||
101 | + return false; | 36 | + return false; |
102 | + } | 37 | + } |
103 | + | 38 | + |
104 | + *off += 2 * sizeof(uint32_t) + step; | 39 | if (arm_dc_feature(s, ARM_FEATURE_V8) && |
105 | + return true; | 40 | !arm_dc_feature(s, ARM_FEATURE_M)) { |
106 | + | 41 | return cp >= 14; |
107 | + error_data: | ||
108 | + error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY"); | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
3 | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-12-richard.henderson@linaro.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- | ||
11 | 1 file changed, 46 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/linux-user/elfload.c | ||
16 | +++ b/linux-user/elfload.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, | ||
18 | |||
19 | #include "elf.h" | ||
20 | |||
21 | +/* We must delay the following stanzas until after "elf.h". */ | ||
22 | +#if defined(TARGET_AARCH64) | ||
23 | + | ||
24 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
25 | + const uint32_t *data, | ||
26 | + struct image_info *info, | ||
27 | + Error **errp) | ||
28 | +{ | ||
29 | + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { | ||
30 | + if (pr_datasz != sizeof(uint32_t)) { | ||
31 | + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); | ||
32 | + return false; | ||
33 | + } | ||
34 | + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ | ||
35 | + info->note_flags = *data; | ||
36 | + } | ||
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 | -- | ||
101 | 2.20.1 | ||
102 | |||
103 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
2 | 1 | ||
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> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20201021173749.111103-13-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ | ||
13 | tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ | ||
14 | tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ | ||
15 | tests/tcg/aarch64/Makefile.target | 10 +++ | ||
16 | tests/tcg/configure.sh | 4 ++ | ||
17 | 5 files changed, 243 insertions(+) | ||
18 | create mode 100644 tests/tcg/aarch64/bti-1.c | ||
19 | create mode 100644 tests/tcg/aarch64/bti-2.c | ||
20 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | ||
21 | |||
22 | diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c | ||
23 | new file mode 100644 | ||
24 | index XXXXXXX..XXXXXXX | ||
25 | --- /dev/null | ||
26 | +++ b/tests/tcg/aarch64/bti-1.c | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | +/* | ||
29 | + * Branch target identification, basic notskip cases. | ||
30 | + */ | ||
31 | + | ||
32 | +#include "bti-crt.inc.c" | ||
33 | + | ||
34 | +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) | ||
35 | +{ | ||
36 | + uc->uc_mcontext.pc += 8; | ||
37 | + uc->uc_mcontext.pstate = 1; | ||
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> | ||
101 | +#include <signal.h> | ||
102 | +#include <string.h> | ||
103 | +#include <unistd.h> | ||
104 | +#include <sys/mman.h> | ||
105 | + | ||
106 | +#ifndef PROT_BTI | ||
107 | +#define PROT_BTI 0x10 | ||
108 | +#endif | ||
109 | + | ||
110 | +static void skip2_sigill(int sig, siginfo_t *info, void *vuc) | ||
111 | +{ | ||
112 | + ucontext_t *uc = vuc; | ||
113 | + uc->uc_mcontext.pc += 8; | ||
114 | + uc->uc_mcontext.pstate = 1; | ||
115 | +} | ||
116 | + | ||
117 | +#define NOP "nop" | ||
118 | +#define BTI_N "hint #32" | ||
119 | +#define BTI_C "hint #34" | ||
120 | +#define BTI_J "hint #36" | ||
121 | +#define BTI_JC "hint #38" | ||
122 | + | ||
123 | +#define BTYPE_1(DEST) \ | ||
124 | + "mov x1, #1\n\t" \ | ||
125 | + "adr x16, 1f\n\t" \ | ||
126 | + "br x16\n" \ | ||
127 | +"1: " DEST "\n\t" \ | ||
128 | + "mov x1, #0" | ||
129 | + | ||
130 | +#define BTYPE_2(DEST) \ | ||
131 | + "mov x1, #1\n\t" \ | ||
132 | + "adr x16, 1f\n\t" \ | ||
133 | + "blr x16\n" \ | ||
134 | +"1: " DEST "\n\t" \ | ||
135 | + "mov x1, #0" | ||
136 | + | ||
137 | +#define BTYPE_3(DEST) \ | ||
138 | + "mov x1, #1\n\t" \ | ||
139 | + "adr x15, 1f\n\t" \ | ||
140 | + "br x15\n" \ | ||
141 | +"1: " DEST "\n\t" \ | ||
142 | + "mov x1, #0" | ||
143 | + | ||
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); | ||
187 | + if (p == MAP_FAILED) { | ||
188 | + perror("mmap"); | ||
189 | + return 1; | ||
190 | + } | ||
191 | + | ||
192 | + memset(&sa, 0, sizeof(sa)); | ||
193 | + sa.sa_sigaction = skip2_sigill; | ||
194 | + sa.sa_flags = SA_SIGINFO; | ||
195 | + if (sigaction(SIGILL, &sa, NULL) < 0) { | ||
196 | + perror("sigaction"); | ||
197 | + return 1; | ||
198 | + } | ||
199 | + | ||
200 | + /* | ||
201 | + * ??? With "extern char test_begin[]", some compiler versions | ||
202 | + * will use :got references, and some linker versions will | ||
203 | + * resolve this reference to a static symbol incorrectly. | ||
204 | + * Bypass this error by using a pc-relative reference directly. | ||
205 | + */ | ||
206 | + asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb), "=r"(te)); | ||
207 | + | ||
208 | + memcpy(p, tb, te - tb); | ||
209 | + | ||
210 | + return ((int (*)(void))p)(); | ||
211 | +} | ||
212 | diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c | ||
213 | new file mode 100644 | ||
214 | index XXXXXXX..XXXXXXX | ||
215 | --- /dev/null | ||
216 | +++ b/tests/tcg/aarch64/bti-crt.inc.c | ||
217 | @@ -XXX,XX +XXX,XX @@ | ||
218 | +/* | ||
219 | + * Minimal user-environment for testing BTI. | ||
220 | + * | ||
221 | + * Normal libc is not (yet) built with BTI support enabled, | ||
222 | + * and so could generate a BTI TRAP before ever reaching main. | ||
223 | + */ | ||
224 | + | ||
225 | +#include <stdlib.h> | ||
226 | +#include <signal.h> | ||
227 | +#include <ucontext.h> | ||
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 | +} | ||
269 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/tests/tcg/aarch64/Makefile.target | ||
272 | +++ b/tests/tcg/aarch64/Makefile.target | ||
273 | @@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max | ||
274 | run-plugin-pauth-%: QEMU_OPTS += -cpu max | ||
275 | endif | ||
276 | |||
277 | +# BTI Tests | ||
278 | +# bti-1 tests the elf notes, so we require special compiler support. | ||
279 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) | ||
280 | +AARCH64_TESTS += bti-1 | ||
281 | +bti-1: CFLAGS += -mbranch-protection=standard | ||
282 | +bti-1: LDFLAGS += -nostdlib | ||
283 | +endif | ||
284 | +# bti-2 tests PROT_BTI, so no special compiler support required. | ||
285 | +AARCH64_TESTS += bti-2 | ||
286 | + | ||
287 | # Semihosting smoke test for linux-user | ||
288 | AARCH64_TESTS += semihosting | ||
289 | run-semihosting: semihosting | ||
290 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh | ||
291 | index XXXXXXX..XXXXXXX 100755 | ||
292 | --- a/tests/tcg/configure.sh | ||
293 | +++ b/tests/tcg/configure.sh | ||
294 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do | ||
295 | -march=armv8.3-a -o $TMPE $TMPC; then | ||
296 | echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak | ||
297 | fi | ||
298 | + if do_compiler "$target_compiler" $target_compiler_cflags \ | ||
299 | + -mbranch-protection=standard -o $TMPE $TMPC; then | ||
300 | + echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak | ||
301 | + fi | ||
302 | ;; | ||
303 | esac | ||
304 | |||
305 | -- | ||
306 | 2.20.1 | ||
307 | |||
308 | 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: Havard Skinnemoen <hskinnemoen@google.com> | ||
2 | 1 | ||
3 | This allows us to reuse npcm7xx_timer_pause for the watchdog timer. | ||
4 | |||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | hw/timer/npcm7xx_timer.c | 6 +++--- | ||
10 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
11 | |||
12 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/timer/npcm7xx_timer.c | ||
15 | +++ b/hw/timer/npcm7xx_timer.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
17 | timer_del(&t->qtimer); | ||
18 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
19 | t->remaining_ns = t->expires_ns - now; | ||
20 | - if (t->remaining_ns <= 0) { | ||
21 | - npcm7xx_timer_reached_zero(t); | ||
22 | - } | ||
23 | } | ||
24 | |||
25 | /* | ||
26 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
27 | } else { | ||
28 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | ||
29 | npcm7xx_timer_pause(t); | ||
30 | + if (t->remaining_ns <= 0) { | ||
31 | + npcm7xx_timer_reached_zero(t); | ||
32 | + } | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | -- | ||
37 | 2.20.1 | ||
38 | |||
39 | diff view generated by jsdifflib |
1 | From: "Dr. David Alan Gilbert" <dgilbert@redhat.com> | 1 | A copy-and-paste error meant that the return value for register offset 0x44 |
---|---|---|---|
2 | (the RX Status FIFO PEEK register) returned a byte from a bogus offset in | ||
3 | the rx status FIFO. Fix the typo. | ||
2 | 4 | ||
3 | Use of 0x%d - make up our mind as 0x%x | 5 | Cc: qemu-stable@nongnu.org |
4 | 6 | Fixes: https://bugs.launchpad.net/qemu/+bug/1904954 | |
5 | Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Acked-by: Eric Auger <eric.auger@redhat.com> | 9 | Message-id: 20210108180401.2263-2-peter.maydell@linaro.org |
8 | Message-id: 20201014193355.53074-1-dgilbert@redhat.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | 10 | --- |
11 | hw/arm/trace-events | 2 +- | 11 | hw/net/lan9118.c | 2 +- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 13 | ||
14 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events | 14 | diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/trace-events | 16 | --- a/hw/net/lan9118.c |
17 | +++ b/hw/arm/trace-events | 17 | +++ b/hw/net/lan9118.c |
18 | @@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 | 18 | @@ -XXX,XX +XXX,XX @@ static uint64_t lan9118_readl(void *opaque, hwaddr offset, |
19 | smmuv3_decode_cd(uint32_t oas) "oas=%d" | 19 | case 0x40: |
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" | 20 | return rx_status_fifo_pop(s); |
21 | smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d" | 21 | case 0x44: |
22 | -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d" | 22 | - return s->rx_status_fifo[s->tx_status_fifo_head]; |
23 | +smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" | 23 | + return s->rx_status_fifo[s->rx_status_fifo_head]; |
24 | smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d" | 24 | case 0x48: |
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)" | 25 | return tx_status_fifo_pop(s); |
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)" | 26 | case 0x4c: |
27 | -- | 27 | -- |
28 | 2.20.1 | 28 | 2.20.1 |
29 | 29 | ||
30 | 30 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | The lan9118 code mostly uses symbolic constants for register offsets; |
---|---|---|---|
2 | the exceptions are those which the datasheet doesn't give an official | ||
3 | symbolic name to. | ||
2 | 4 | ||
3 | A PLL channel is able to further divide the generated PLL frequency. | 5 | Add some names for the registers which don't already have them, based |
4 | The divider is given in the CTRL_A2W register. Some channels have an | 6 | on the longer names they are given in the memory map. |
5 | additional fixed divider which is always applied to the signal. | ||
6 | 7 | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 10 | Message-id: 20210108180401.2263-3-peter.maydell@linaro.org |
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | 11 | --- |
13 | hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- | 12 | hw/net/lan9118.c | 24 ++++++++++++++++++------ |
14 | 1 file changed, 32 insertions(+), 1 deletion(-) | 13 | 1 file changed, 18 insertions(+), 6 deletions(-) |
15 | 14 | ||
16 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 15 | diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c |
17 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/misc/bcm2835_cprman.c | 17 | --- a/hw/net/lan9118.c |
19 | +++ b/hw/misc/bcm2835_cprman.c | 18 | +++ b/hw/net/lan9118.c |
20 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | 19 | @@ -XXX,XX +XXX,XX @@ do { hw_error("lan9118: error: " fmt , ## __VA_ARGS__);} while (0) |
21 | 20 | do { fprintf(stderr, "lan9118: error: " fmt , ## __VA_ARGS__);} while (0) | |
22 | /* PLL channel */ | 21 | #endif |
23 | 22 | ||
24 | +static bool pll_channel_is_enabled(CprmanPllChannelState *channel) | 23 | +/* The tx and rx fifo ports are a range of aliased 32-bit registers */ |
25 | +{ | 24 | +#define RX_DATA_FIFO_PORT_FIRST 0x00 |
26 | + /* | 25 | +#define RX_DATA_FIFO_PORT_LAST 0x1f |
27 | + * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does | 26 | +#define TX_DATA_FIFO_PORT_FIRST 0x20 |
28 | + * not set it when enabling the channel, but does clear it when disabling | 27 | +#define TX_DATA_FIFO_PORT_LAST 0x3f |
29 | + * it. | ||
30 | + */ | ||
31 | + return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) | ||
32 | + && !(*channel->reg_cm & channel->hold_mask); | ||
33 | +} | ||
34 | + | 28 | + |
35 | static void pll_channel_update(CprmanPllChannelState *channel) | 29 | +#define RX_STATUS_FIFO_PORT 0x40 |
36 | { | 30 | +#define RX_STATUS_FIFO_PEEK 0x44 |
37 | - clock_update(channel->out, 0); | 31 | +#define TX_STATUS_FIFO_PORT 0x48 |
38 | + uint64_t freq, div; | 32 | +#define TX_STATUS_FIFO_PEEK 0x4c |
39 | + | 33 | + |
40 | + if (!pll_channel_is_enabled(channel)) { | 34 | #define CSR_ID_REV 0x50 |
41 | + clock_update(channel->out, 0); | 35 | #define CSR_IRQ_CFG 0x54 |
42 | + return; | 36 | #define CSR_INT_STS 0x58 |
43 | + } | 37 | @@ -XXX,XX +XXX,XX @@ static void lan9118_writel(void *opaque, hwaddr offset, |
44 | + | 38 | offset &= 0xff; |
45 | + div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); | 39 | |
46 | + | 40 | //DPRINTF("Write reg 0x%02x = 0x%08x\n", (int)offset, val); |
47 | + if (!div) { | 41 | - if (offset >= 0x20 && offset < 0x40) { |
48 | + /* | 42 | + if (offset >= TX_DATA_FIFO_PORT_FIRST && |
49 | + * It seems that when the divider value is 0, it is considered as | 43 | + offset <= TX_DATA_FIFO_PORT_LAST) { |
50 | + * being maximum by the hardware (see the Linux driver). | 44 | /* TX FIFO */ |
51 | + */ | 45 | tx_fifo_push(s, val); |
52 | + div = R_A2W_PLLx_CHANNELy_DIV_MASK; | 46 | return; |
53 | + } | 47 | @@ -XXX,XX +XXX,XX @@ static uint64_t lan9118_readl(void *opaque, hwaddr offset, |
54 | + | 48 | lan9118_state *s = (lan9118_state *)opaque; |
55 | + /* Some channels have an additional fixed divider */ | 49 | |
56 | + freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); | 50 | //DPRINTF("Read reg 0x%02x\n", (int)offset); |
57 | + | 51 | - if (offset < 0x20) { |
58 | + clock_update_hz(channel->out, freq); | 52 | + if (offset <= RX_DATA_FIFO_PORT_LAST) { |
59 | } | 53 | /* RX FIFO */ |
60 | 54 | return rx_fifo_pop(s); | |
61 | /* Update a PLL and all its channels */ | 55 | } |
56 | switch (offset) { | ||
57 | - case 0x40: | ||
58 | + case RX_STATUS_FIFO_PORT: | ||
59 | return rx_status_fifo_pop(s); | ||
60 | - case 0x44: | ||
61 | + case RX_STATUS_FIFO_PEEK: | ||
62 | return s->rx_status_fifo[s->rx_status_fifo_head]; | ||
63 | - case 0x48: | ||
64 | + case TX_STATUS_FIFO_PORT: | ||
65 | return tx_status_fifo_pop(s); | ||
66 | - case 0x4c: | ||
67 | + case TX_STATUS_FIFO_PEEK: | ||
68 | return s->tx_status_fifo[s->tx_status_fifo_head]; | ||
69 | case CSR_ID_REV: | ||
70 | return 0x01180001; | ||
62 | -- | 71 | -- |
63 | 2.20.1 | 72 | 2.20.1 |
64 | 73 | ||
65 | 74 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them | 3 | This patch allows NPCM7XX CLK module to compute clocks that are used by |
4 | take the xosc clock as input and produce a new clock. | 4 | other NPCM7XX modules. |
5 | 5 | ||
6 | This commit adds a skeleton implementation for the PLLs as sub-devices | 6 | Add a new struct NPCM7xxClockConverterState which represents a |
7 | of the CPRMAN. The PLLs are instantiated and connected internally to the | 7 | single converter. Each clock converter in CLK module represents one |
8 | main oscillator. | 8 | converter in NPCM7XX CLK Module(PLL, SEL or Divider). Each converter |
9 | takes one or more input clocks and converts them into one output clock. | ||
10 | They form a clock hierarchy in the CLK module and are responsible for | ||
11 | outputing clocks for various other modules in an NPCM7XX SoC. | ||
9 | 12 | ||
10 | Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A | 13 | Each converter has a function pointer called "convert" which represents |
11 | write to any of them triggers a call to the (not yet implemented) | 14 | the unique logic for that converter. |
12 | pll_update function. | ||
13 | 15 | ||
14 | If the main oscillator changes frequency, an update is also triggered. | 16 | The clock contains two initialization information: ConverterInitInfo and |
17 | ConverterConnectionInfo. They represent the vertices and edges in the | ||
18 | clock diagram respectively. | ||
15 | 19 | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 20 | Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com> |
17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 21 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
18 | Signed-off-by: Luc Michel <luc@lmichel.fr> | 22 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
19 | Tested-by: Guenter Roeck <linux@roeck-us.net> | 23 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
24 | Message-id: 20210108190945.949196-2-wuhaotsh@google.com | ||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 26 | --- |
22 | include/hw/misc/bcm2835_cprman.h | 29 +++++ | 27 | include/hw/misc/npcm7xx_clk.h | 140 +++++- |
23 | include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ | 28 | hw/misc/npcm7xx_clk.c | 805 +++++++++++++++++++++++++++++++++- |
24 | hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ | 29 | 2 files changed, 932 insertions(+), 13 deletions(-) |
25 | 3 files changed, 281 insertions(+) | ||
26 | 30 | ||
27 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 31 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h |
28 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/misc/bcm2835_cprman.h | 33 | --- a/include/hw/misc/npcm7xx_clk.h |
30 | +++ b/include/hw/misc/bcm2835_cprman.h | 34 | +++ b/include/hw/misc/npcm7xx_clk.h |
31 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | 35 | @@ -XXX,XX +XXX,XX @@ |
32 | 36 | #define NPCM7XX_CLK_H | |
33 | #define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | 37 | |
34 | 38 | #include "exec/memory.h" | |
35 | +typedef enum CprmanPll { | 39 | +#include "hw/clock.h" |
36 | + CPRMAN_PLLA = 0, | 40 | #include "hw/sysbus.h" |
37 | + CPRMAN_PLLC, | 41 | |
38 | + CPRMAN_PLLD, | 42 | /* |
39 | + CPRMAN_PLLH, | 43 | @@ -XXX,XX +XXX,XX @@ |
40 | + CPRMAN_PLLB, | 44 | |
41 | + | 45 | #define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" |
42 | + CPRMAN_NUM_PLL | 46 | |
43 | +} CprmanPll; | 47 | -typedef struct NPCM7xxCLKState { |
44 | + | 48 | +/* Maximum amount of clock inputs in a SEL module. */ |
45 | +typedef struct CprmanPllState { | 49 | +#define NPCM7XX_CLK_SEL_MAX_INPUT 5 |
46 | + /*< private >*/ | 50 | + |
47 | + DeviceState parent_obj; | 51 | +/* PLLs in CLK module. */ |
48 | + | 52 | +typedef enum NPCM7xxClockPLL { |
49 | + /*< public >*/ | 53 | + NPCM7XX_CLOCK_PLL0, |
50 | + CprmanPll id; | 54 | + NPCM7XX_CLOCK_PLL1, |
51 | + | 55 | + NPCM7XX_CLOCK_PLL2, |
52 | + uint32_t *reg_cm; | 56 | + NPCM7XX_CLOCK_PLLG, |
53 | + uint32_t *reg_a2w_ctrl; | 57 | + NPCM7XX_CLOCK_NR_PLLS, |
54 | + uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */ | 58 | +} NPCM7xxClockPLL; |
55 | + uint32_t prediv_mask; /* prediv bit in ana[1] */ | 59 | + |
56 | + uint32_t *reg_a2w_frac; | 60 | +/* SEL/MUX in CLK module. */ |
57 | + | 61 | +typedef enum NPCM7xxClockSEL { |
58 | + Clock *xosc_in; | 62 | + NPCM7XX_CLOCK_PIXCKSEL, |
59 | + Clock *out; | 63 | + NPCM7XX_CLOCK_MCCKSEL, |
60 | +} CprmanPllState; | 64 | + NPCM7XX_CLOCK_CPUCKSEL, |
61 | + | 65 | + NPCM7XX_CLOCK_CLKOUTSEL, |
62 | struct BCM2835CprmanState { | 66 | + NPCM7XX_CLOCK_UARTCKSEL, |
63 | /*< private >*/ | 67 | + NPCM7XX_CLOCK_TIMCKSEL, |
64 | SysBusDevice parent_obj; | 68 | + NPCM7XX_CLOCK_SDCKSEL, |
65 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | 69 | + NPCM7XX_CLOCK_GFXMSEL, |
66 | /*< public >*/ | 70 | + NPCM7XX_CLOCK_SUCKSEL, |
71 | + NPCM7XX_CLOCK_NR_SELS, | ||
72 | +} NPCM7xxClockSEL; | ||
73 | + | ||
74 | +/* Dividers in CLK module. */ | ||
75 | +typedef enum NPCM7xxClockDivider { | ||
76 | + NPCM7XX_CLOCK_PLL1D2, /* PLL1/2 */ | ||
77 | + NPCM7XX_CLOCK_PLL2D2, /* PLL2/2 */ | ||
78 | + NPCM7XX_CLOCK_MC_DIVIDER, | ||
79 | + NPCM7XX_CLOCK_AXI_DIVIDER, | ||
80 | + NPCM7XX_CLOCK_AHB_DIVIDER, | ||
81 | + NPCM7XX_CLOCK_AHB3_DIVIDER, | ||
82 | + NPCM7XX_CLOCK_SPI0_DIVIDER, | ||
83 | + NPCM7XX_CLOCK_SPIX_DIVIDER, | ||
84 | + NPCM7XX_CLOCK_APB1_DIVIDER, | ||
85 | + NPCM7XX_CLOCK_APB2_DIVIDER, | ||
86 | + NPCM7XX_CLOCK_APB3_DIVIDER, | ||
87 | + NPCM7XX_CLOCK_APB4_DIVIDER, | ||
88 | + NPCM7XX_CLOCK_APB5_DIVIDER, | ||
89 | + NPCM7XX_CLOCK_CLKOUT_DIVIDER, | ||
90 | + NPCM7XX_CLOCK_UART_DIVIDER, | ||
91 | + NPCM7XX_CLOCK_TIMER_DIVIDER, | ||
92 | + NPCM7XX_CLOCK_ADC_DIVIDER, | ||
93 | + NPCM7XX_CLOCK_MMC_DIVIDER, | ||
94 | + NPCM7XX_CLOCK_SDHC_DIVIDER, | ||
95 | + NPCM7XX_CLOCK_GFXM_DIVIDER, /* divide by 3 */ | ||
96 | + NPCM7XX_CLOCK_UTMI_DIVIDER, | ||
97 | + NPCM7XX_CLOCK_NR_DIVIDERS, | ||
98 | +} NPCM7xxClockConverter; | ||
99 | + | ||
100 | +typedef struct NPCM7xxCLKState NPCM7xxCLKState; | ||
101 | + | ||
102 | +/** | ||
103 | + * struct NPCM7xxClockPLLState - A PLL module in CLK module. | ||
104 | + * @name: The name of the module. | ||
105 | + * @clk: The CLK module that owns this module. | ||
106 | + * @clock_in: The input clock of this module. | ||
107 | + * @clock_out: The output clock of this module. | ||
108 | + * @reg: The control registers for this PLL module. | ||
109 | + */ | ||
110 | +typedef struct NPCM7xxClockPLLState { | ||
111 | + DeviceState parent; | ||
112 | + | ||
113 | + const char *name; | ||
114 | + NPCM7xxCLKState *clk; | ||
115 | + Clock *clock_in; | ||
116 | + Clock *clock_out; | ||
117 | + | ||
118 | + int reg; | ||
119 | +} NPCM7xxClockPLLState; | ||
120 | + | ||
121 | +/** | ||
122 | + * struct NPCM7xxClockSELState - A SEL module in CLK module. | ||
123 | + * @name: The name of the module. | ||
124 | + * @clk: The CLK module that owns this module. | ||
125 | + * @input_size: The size of inputs of this module. | ||
126 | + * @clock_in: The input clocks of this module. | ||
127 | + * @clock_out: The output clocks of this module. | ||
128 | + * @offset: The offset of this module in the control register. | ||
129 | + * @len: The length of this module in the control register. | ||
130 | + */ | ||
131 | +typedef struct NPCM7xxClockSELState { | ||
132 | + DeviceState parent; | ||
133 | + | ||
134 | + const char *name; | ||
135 | + NPCM7xxCLKState *clk; | ||
136 | + uint8_t input_size; | ||
137 | + Clock *clock_in[NPCM7XX_CLK_SEL_MAX_INPUT]; | ||
138 | + Clock *clock_out; | ||
139 | + | ||
140 | + int offset; | ||
141 | + int len; | ||
142 | +} NPCM7xxClockSELState; | ||
143 | + | ||
144 | +/** | ||
145 | + * struct NPCM7xxClockDividerState - A Divider module in CLK module. | ||
146 | + * @name: The name of the module. | ||
147 | + * @clk: The CLK module that owns this module. | ||
148 | + * @clock_in: The input clock of this module. | ||
149 | + * @clock_out: The output clock of this module. | ||
150 | + * @divide: The function the divider uses to divide the input. | ||
151 | + * @reg: The index of the control register that contains the divisor. | ||
152 | + * @offset: The offset of the divisor in the control register. | ||
153 | + * @len: The length of the divisor in the control register. | ||
154 | + * @divisor: The divisor for a constant divisor | ||
155 | + */ | ||
156 | +typedef struct NPCM7xxClockDividerState { | ||
157 | + DeviceState parent; | ||
158 | + | ||
159 | + const char *name; | ||
160 | + NPCM7xxCLKState *clk; | ||
161 | + Clock *clock_in; | ||
162 | + Clock *clock_out; | ||
163 | + | ||
164 | + uint32_t (*divide)(struct NPCM7xxClockDividerState *s); | ||
165 | + union { | ||
166 | + struct { | ||
167 | + int reg; | ||
168 | + int offset; | ||
169 | + int len; | ||
170 | + }; | ||
171 | + int divisor; | ||
172 | + }; | ||
173 | +} NPCM7xxClockDividerState; | ||
174 | + | ||
175 | +struct NPCM7xxCLKState { | ||
176 | SysBusDevice parent; | ||
177 | |||
67 | MemoryRegion iomem; | 178 | MemoryRegion iomem; |
68 | 179 | ||
69 | + CprmanPllState plls[CPRMAN_NUM_PLL]; | 180 | + /* Clock converters */ |
70 | + | 181 | + NPCM7xxClockPLLState plls[NPCM7XX_CLOCK_NR_PLLS]; |
71 | uint32_t regs[CPRMAN_NUM_REGS]; | 182 | + NPCM7xxClockSELState sels[NPCM7XX_CLOCK_NR_SELS]; |
72 | uint32_t xosc_freq; | 183 | + NPCM7xxClockDividerState dividers[NPCM7XX_CLOCK_NR_DIVIDERS]; |
73 | 184 | + | |
74 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | 185 | uint32_t regs[NPCM7XX_CLK_NR_REGS]; |
186 | |||
187 | /* Time reference for SECCNT and CNTR25M, initialized by power on reset */ | ||
188 | int64_t ref_ns; | ||
189 | -} NPCM7xxCLKState; | ||
190 | + | ||
191 | + /* The incoming reference clock. */ | ||
192 | + Clock *clkref; | ||
193 | +}; | ||
194 | |||
195 | #define TYPE_NPCM7XX_CLK "npcm7xx-clk" | ||
196 | #define NPCM7XX_CLK(obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX_CLK) | ||
197 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | 198 | index XXXXXXX..XXXXXXX 100644 |
76 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 199 | --- a/hw/misc/npcm7xx_clk.c |
77 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 200 | +++ b/hw/misc/npcm7xx_clk.c |
78 | @@ -XXX,XX +XXX,XX @@ | 201 | @@ -XXX,XX +XXX,XX @@ |
79 | #include "hw/registerfields.h" | 202 | |
80 | #include "hw/misc/bcm2835_cprman.h" | 203 | #include "hw/misc/npcm7xx_clk.h" |
81 | 204 | #include "hw/timer/npcm7xx_timer.h" | |
82 | +#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | 205 | +#include "hw/qdev-clock.h" |
83 | + | 206 | #include "migration/vmstate.h" |
84 | +DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | 207 | #include "qemu/error-report.h" |
85 | + TYPE_CPRMAN_PLL) | 208 | #include "qemu/log.h" |
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 @@ | 209 | @@ -XXX,XX +XXX,XX @@ |
174 | FIELD(CPRMAN, PASSWORD, 24, 8) | 210 | #include "trace.h" |
175 | #define CPRMAN_PASSWORD 0x5a | 211 | #include "sysemu/watchdog.h" |
176 | 212 | ||
177 | +/* PLL init info */ | 213 | +/* |
214 | + * The reference clock hz, and the SECCNT and CNTR25M registers in this module, | ||
215 | + * is always 25 MHz. | ||
216 | + */ | ||
217 | +#define NPCM7XX_CLOCK_REF_HZ (25000000) | ||
218 | + | ||
219 | +/* Register Field Definitions */ | ||
220 | +#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */ | ||
221 | + | ||
222 | #define PLLCON_LOKI BIT(31) | ||
223 | #define PLLCON_LOKS BIT(30) | ||
224 | #define PLLCON_PWDEN BIT(12) | ||
225 | +#define PLLCON_FBDV(con) extract32((con), 16, 12) | ||
226 | +#define PLLCON_OTDV2(con) extract32((con), 13, 3) | ||
227 | +#define PLLCON_OTDV1(con) extract32((con), 8, 3) | ||
228 | +#define PLLCON_INDV(con) extract32((con), 0, 6) | ||
229 | |||
230 | enum NPCM7xxCLKRegisters { | ||
231 | NPCM7XX_CLK_CLKEN1, | ||
232 | @@ -XXX,XX +XXX,XX @@ static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = { | ||
233 | [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, | ||
234 | }; | ||
235 | |||
236 | -/* Register Field Definitions */ | ||
237 | -#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */ | ||
238 | - | ||
239 | /* The number of watchdogs that can trigger a reset. */ | ||
240 | #define NPCM7XX_NR_WATCHDOGS (3) | ||
241 | |||
242 | +/* Clock converter functions */ | ||
243 | + | ||
244 | +#define TYPE_NPCM7XX_CLOCK_PLL "npcm7xx-clock-pll" | ||
245 | +#define NPCM7XX_CLOCK_PLL(obj) OBJECT_CHECK(NPCM7xxClockPLLState, \ | ||
246 | + (obj), TYPE_NPCM7XX_CLOCK_PLL) | ||
247 | +#define TYPE_NPCM7XX_CLOCK_SEL "npcm7xx-clock-sel" | ||
248 | +#define NPCM7XX_CLOCK_SEL(obj) OBJECT_CHECK(NPCM7xxClockSELState, \ | ||
249 | + (obj), TYPE_NPCM7XX_CLOCK_SEL) | ||
250 | +#define TYPE_NPCM7XX_CLOCK_DIVIDER "npcm7xx-clock-divider" | ||
251 | +#define NPCM7XX_CLOCK_DIVIDER(obj) OBJECT_CHECK(NPCM7xxClockDividerState, \ | ||
252 | + (obj), TYPE_NPCM7XX_CLOCK_DIVIDER) | ||
253 | + | ||
254 | +static void npcm7xx_clk_update_pll(void *opaque) | ||
255 | +{ | ||
256 | + NPCM7xxClockPLLState *s = opaque; | ||
257 | + uint32_t con = s->clk->regs[s->reg]; | ||
258 | + uint64_t freq; | ||
259 | + | ||
260 | + /* The PLL is grounded if it is not locked yet. */ | ||
261 | + if (con & PLLCON_LOKI) { | ||
262 | + freq = clock_get_hz(s->clock_in); | ||
263 | + freq *= PLLCON_FBDV(con); | ||
264 | + freq /= PLLCON_INDV(con) * PLLCON_OTDV1(con) * PLLCON_OTDV2(con); | ||
265 | + } else { | ||
266 | + freq = 0; | ||
267 | + } | ||
268 | + | ||
269 | + clock_update_hz(s->clock_out, freq); | ||
270 | +} | ||
271 | + | ||
272 | +static void npcm7xx_clk_update_sel(void *opaque) | ||
273 | +{ | ||
274 | + NPCM7xxClockSELState *s = opaque; | ||
275 | + uint32_t index = extract32(s->clk->regs[NPCM7XX_CLK_CLKSEL], s->offset, | ||
276 | + s->len); | ||
277 | + | ||
278 | + if (index >= s->input_size) { | ||
279 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
280 | + "%s: SEL index: %u out of range\n", | ||
281 | + __func__, index); | ||
282 | + index = 0; | ||
283 | + } | ||
284 | + clock_update_hz(s->clock_out, clock_get_hz(s->clock_in[index])); | ||
285 | +} | ||
286 | + | ||
287 | +static void npcm7xx_clk_update_divider(void *opaque) | ||
288 | +{ | ||
289 | + NPCM7xxClockDividerState *s = opaque; | ||
290 | + uint32_t freq; | ||
291 | + | ||
292 | + freq = s->divide(s); | ||
293 | + clock_update_hz(s->clock_out, freq); | ||
294 | +} | ||
295 | + | ||
296 | +static uint32_t divide_by_constant(NPCM7xxClockDividerState *s) | ||
297 | +{ | ||
298 | + return clock_get_hz(s->clock_in) / s->divisor; | ||
299 | +} | ||
300 | + | ||
301 | +static uint32_t divide_by_reg_divisor(NPCM7xxClockDividerState *s) | ||
302 | +{ | ||
303 | + return clock_get_hz(s->clock_in) / | ||
304 | + (extract32(s->clk->regs[s->reg], s->offset, s->len) + 1); | ||
305 | +} | ||
306 | + | ||
307 | +static uint32_t divide_by_reg_divisor_times_2(NPCM7xxClockDividerState *s) | ||
308 | +{ | ||
309 | + return divide_by_reg_divisor(s) / 2; | ||
310 | +} | ||
311 | + | ||
312 | +static uint32_t shift_by_reg_divisor(NPCM7xxClockDividerState *s) | ||
313 | +{ | ||
314 | + return clock_get_hz(s->clock_in) >> | ||
315 | + extract32(s->clk->regs[s->reg], s->offset, s->len); | ||
316 | +} | ||
317 | + | ||
318 | +static NPCM7xxClockPLL find_pll_by_reg(enum NPCM7xxCLKRegisters reg) | ||
319 | +{ | ||
320 | + switch (reg) { | ||
321 | + case NPCM7XX_CLK_PLLCON0: | ||
322 | + return NPCM7XX_CLOCK_PLL0; | ||
323 | + case NPCM7XX_CLK_PLLCON1: | ||
324 | + return NPCM7XX_CLOCK_PLL1; | ||
325 | + case NPCM7XX_CLK_PLLCON2: | ||
326 | + return NPCM7XX_CLOCK_PLL2; | ||
327 | + case NPCM7XX_CLK_PLLCONG: | ||
328 | + return NPCM7XX_CLOCK_PLLG; | ||
329 | + default: | ||
330 | + g_assert_not_reached(); | ||
331 | + } | ||
332 | +} | ||
333 | + | ||
334 | +static void npcm7xx_clk_update_all_plls(NPCM7xxCLKState *clk) | ||
335 | +{ | ||
336 | + int i; | ||
337 | + | ||
338 | + for (i = 0; i < NPCM7XX_CLOCK_NR_PLLS; ++i) { | ||
339 | + npcm7xx_clk_update_pll(&clk->plls[i]); | ||
340 | + } | ||
341 | +} | ||
342 | + | ||
343 | +static void npcm7xx_clk_update_all_sels(NPCM7xxCLKState *clk) | ||
344 | +{ | ||
345 | + int i; | ||
346 | + | ||
347 | + for (i = 0; i < NPCM7XX_CLOCK_NR_SELS; ++i) { | ||
348 | + npcm7xx_clk_update_sel(&clk->sels[i]); | ||
349 | + } | ||
350 | +} | ||
351 | + | ||
352 | +static void npcm7xx_clk_update_all_dividers(NPCM7xxCLKState *clk) | ||
353 | +{ | ||
354 | + int i; | ||
355 | + | ||
356 | + for (i = 0; i < NPCM7XX_CLOCK_NR_DIVIDERS; ++i) { | ||
357 | + npcm7xx_clk_update_divider(&clk->dividers[i]); | ||
358 | + } | ||
359 | +} | ||
360 | + | ||
361 | +static void npcm7xx_clk_update_all_clocks(NPCM7xxCLKState *clk) | ||
362 | +{ | ||
363 | + clock_update_hz(clk->clkref, NPCM7XX_CLOCK_REF_HZ); | ||
364 | + npcm7xx_clk_update_all_plls(clk); | ||
365 | + npcm7xx_clk_update_all_sels(clk); | ||
366 | + npcm7xx_clk_update_all_dividers(clk); | ||
367 | +} | ||
368 | + | ||
369 | +/* Types of clock sources. */ | ||
370 | +typedef enum ClockSrcType { | ||
371 | + CLKSRC_REF, | ||
372 | + CLKSRC_PLL, | ||
373 | + CLKSRC_SEL, | ||
374 | + CLKSRC_DIV, | ||
375 | +} ClockSrcType; | ||
376 | + | ||
178 | +typedef struct PLLInitInfo { | 377 | +typedef struct PLLInitInfo { |
179 | + const char *name; | 378 | + const char *name; |
180 | + size_t cm_offset; | 379 | + ClockSrcType src_type; |
181 | + size_t a2w_ctrl_offset; | 380 | + int src_index; |
182 | + size_t a2w_ana_offset; | 381 | + int reg; |
183 | + uint32_t prediv_mask; /* Prediv bit in ana[1] */ | 382 | + const char *public_name; |
184 | + size_t a2w_frac_offset; | ||
185 | +} PLLInitInfo; | 383 | +} PLLInitInfo; |
186 | + | 384 | + |
187 | +#define FILL_PLL_INIT_INFO(pll_) \ | 385 | +typedef struct SELInitInfo { |
188 | + .cm_offset = R_CM_ ## pll_, \ | 386 | + const char *name; |
189 | + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _CTRL, \ | 387 | + uint8_t input_size; |
190 | + .a2w_ana_offset = R_A2W_ ## pll_ ## _ANA0, \ | 388 | + ClockSrcType src_type[NPCM7XX_CLK_SEL_MAX_INPUT]; |
191 | + .a2w_frac_offset = R_A2W_ ## pll_ ## _FRAC | 389 | + int src_index[NPCM7XX_CLK_SEL_MAX_INPUT]; |
192 | + | 390 | + int offset; |
193 | +static const PLLInitInfo PLL_INIT_INFO[] = { | 391 | + int len; |
194 | + [CPRMAN_PLLA] = { | 392 | + const char *public_name; |
195 | + .name = "plla", | 393 | +} SELInitInfo; |
196 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | 394 | + |
197 | + FILL_PLL_INIT_INFO(PLLA), | 395 | +typedef struct DividerInitInfo { |
198 | + }, | 396 | + const char *name; |
199 | + [CPRMAN_PLLC] = { | 397 | + ClockSrcType src_type; |
200 | + .name = "pllc", | 398 | + int src_index; |
201 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | 399 | + uint32_t (*divide)(NPCM7xxClockDividerState *s); |
202 | + FILL_PLL_INIT_INFO(PLLC), | 400 | + int reg; /* not used when type == CONSTANT */ |
203 | + }, | 401 | + int offset; /* not used when type == CONSTANT */ |
204 | + [CPRMAN_PLLD] = { | 402 | + int len; /* not used when type == CONSTANT */ |
205 | + .name = "plld", | 403 | + int divisor; /* used only when type == CONSTANT */ |
206 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | 404 | + const char *public_name; |
207 | + FILL_PLL_INIT_INFO(PLLD), | 405 | +} DividerInitInfo; |
208 | + }, | 406 | + |
209 | + [CPRMAN_PLLH] = { | 407 | +static const PLLInitInfo pll_init_info_list[] = { |
210 | + .name = "pllh", | 408 | + [NPCM7XX_CLOCK_PLL0] = { |
211 | + .prediv_mask = R_A2W_PLLH_ANA1_FB_PREDIV_MASK, | 409 | + .name = "pll0", |
212 | + FILL_PLL_INIT_INFO(PLLH), | 410 | + .src_type = CLKSRC_REF, |
213 | + }, | 411 | + .reg = NPCM7XX_CLK_PLLCON0, |
214 | + [CPRMAN_PLLB] = { | 412 | + }, |
215 | + .name = "pllb", | 413 | + [NPCM7XX_CLOCK_PLL1] = { |
216 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | 414 | + .name = "pll1", |
217 | + FILL_PLL_INIT_INFO(PLLB), | 415 | + .src_type = CLKSRC_REF, |
416 | + .reg = NPCM7XX_CLK_PLLCON1, | ||
417 | + }, | ||
418 | + [NPCM7XX_CLOCK_PLL2] = { | ||
419 | + .name = "pll2", | ||
420 | + .src_type = CLKSRC_REF, | ||
421 | + .reg = NPCM7XX_CLK_PLLCON2, | ||
422 | + }, | ||
423 | + [NPCM7XX_CLOCK_PLLG] = { | ||
424 | + .name = "pllg", | ||
425 | + .src_type = CLKSRC_REF, | ||
426 | + .reg = NPCM7XX_CLK_PLLCONG, | ||
218 | + }, | 427 | + }, |
219 | +}; | 428 | +}; |
220 | + | 429 | + |
221 | +#undef FILL_PLL_CHANNEL_INIT_INFO | 430 | +static const SELInitInfo sel_init_info_list[] = { |
222 | + | 431 | + [NPCM7XX_CLOCK_PIXCKSEL] = { |
223 | +static inline void set_pll_init_info(BCM2835CprmanState *s, | 432 | + .name = "pixcksel", |
224 | + CprmanPllState *pll, | 433 | + .input_size = 2, |
225 | + CprmanPll id) | 434 | + .src_type = {CLKSRC_PLL, CLKSRC_REF}, |
226 | +{ | 435 | + .src_index = {NPCM7XX_CLOCK_PLLG, 0}, |
227 | + pll->id = id; | 436 | + .offset = 5, |
228 | + pll->reg_cm = &s->regs[PLL_INIT_INFO[id].cm_offset]; | 437 | + .len = 1, |
229 | + pll->reg_a2w_ctrl = &s->regs[PLL_INIT_INFO[id].a2w_ctrl_offset]; | 438 | + .public_name = "pixel-clock", |
230 | + pll->reg_a2w_ana = &s->regs[PLL_INIT_INFO[id].a2w_ana_offset]; | 439 | + }, |
231 | + pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask; | 440 | + [NPCM7XX_CLOCK_MCCKSEL] = { |
232 | + pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset]; | 441 | + .name = "mccksel", |
233 | +} | 442 | + .input_size = 4, |
234 | + | 443 | + .src_type = {CLKSRC_DIV, CLKSRC_REF, CLKSRC_REF, |
235 | #endif | 444 | + /*MCBPCK, shouldn't be used in normal operation*/ |
236 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | 445 | + CLKSRC_REF}, |
237 | index XXXXXXX..XXXXXXX 100644 | 446 | + .src_index = {NPCM7XX_CLOCK_PLL1D2, 0, 0, 0}, |
238 | --- a/hw/misc/bcm2835_cprman.c | 447 | + .offset = 12, |
239 | +++ b/hw/misc/bcm2835_cprman.c | 448 | + .len = 2, |
240 | @@ -XXX,XX +XXX,XX @@ | 449 | + .public_name = "mc-phy-clock", |
241 | #include "hw/misc/bcm2835_cprman_internals.h" | 450 | + }, |
242 | #include "trace.h" | 451 | + [NPCM7XX_CLOCK_CPUCKSEL] = { |
243 | 452 | + .name = "cpucksel", | |
244 | +/* PLL */ | 453 | + .input_size = 4, |
245 | + | 454 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, |
246 | +static void pll_update(CprmanPllState *pll) | 455 | + /*SYSBPCK, shouldn't be used in normal operation*/ |
247 | +{ | 456 | + CLKSRC_REF}, |
248 | + clock_update(pll->out, 0); | 457 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, 0}, |
249 | +} | 458 | + .offset = 0, |
250 | + | 459 | + .len = 2, |
251 | +static void pll_xosc_update(void *opaque) | 460 | + .public_name = "system-clock", |
252 | +{ | 461 | + }, |
253 | + pll_update(CPRMAN_PLL(opaque)); | 462 | + [NPCM7XX_CLOCK_CLKOUTSEL] = { |
254 | +} | 463 | + .name = "clkoutsel", |
255 | + | 464 | + .input_size = 5, |
256 | +static void pll_init(Object *obj) | 465 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, |
257 | +{ | 466 | + CLKSRC_PLL, CLKSRC_DIV}, |
258 | + CprmanPllState *s = CPRMAN_PLL(obj); | 467 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, |
259 | + | 468 | + NPCM7XX_CLOCK_PLLG, NPCM7XX_CLOCK_PLL2D2}, |
260 | + s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); | 469 | + .offset = 18, |
261 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | 470 | + .len = 3, |
262 | +} | 471 | + .public_name = "tock", |
263 | + | 472 | + }, |
264 | +static const VMStateDescription pll_vmstate = { | 473 | + [NPCM7XX_CLOCK_UARTCKSEL] = { |
265 | + .name = TYPE_CPRMAN_PLL, | 474 | + .name = "uartcksel", |
475 | + .input_size = 4, | ||
476 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, CLKSRC_DIV}, | ||
477 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, | ||
478 | + NPCM7XX_CLOCK_PLL2D2}, | ||
479 | + .offset = 8, | ||
480 | + .len = 2, | ||
481 | + }, | ||
482 | + [NPCM7XX_CLOCK_TIMCKSEL] = { | ||
483 | + .name = "timcksel", | ||
484 | + .input_size = 4, | ||
485 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, CLKSRC_DIV}, | ||
486 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, | ||
487 | + NPCM7XX_CLOCK_PLL2D2}, | ||
488 | + .offset = 14, | ||
489 | + .len = 2, | ||
490 | + }, | ||
491 | + [NPCM7XX_CLOCK_SDCKSEL] = { | ||
492 | + .name = "sdcksel", | ||
493 | + .input_size = 4, | ||
494 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, CLKSRC_DIV}, | ||
495 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, | ||
496 | + NPCM7XX_CLOCK_PLL2D2}, | ||
497 | + .offset = 6, | ||
498 | + .len = 2, | ||
499 | + }, | ||
500 | + [NPCM7XX_CLOCK_GFXMSEL] = { | ||
501 | + .name = "gfxmksel", | ||
502 | + .input_size = 2, | ||
503 | + .src_type = {CLKSRC_REF, CLKSRC_PLL}, | ||
504 | + .src_index = {0, NPCM7XX_CLOCK_PLL2}, | ||
505 | + .offset = 21, | ||
506 | + .len = 1, | ||
507 | + }, | ||
508 | + [NPCM7XX_CLOCK_SUCKSEL] = { | ||
509 | + .name = "sucksel", | ||
510 | + .input_size = 4, | ||
511 | + .src_type = {CLKSRC_PLL, CLKSRC_DIV, CLKSRC_REF, CLKSRC_DIV}, | ||
512 | + .src_index = {NPCM7XX_CLOCK_PLL0, NPCM7XX_CLOCK_PLL1D2, 0, | ||
513 | + NPCM7XX_CLOCK_PLL2D2}, | ||
514 | + .offset = 10, | ||
515 | + .len = 2, | ||
516 | + }, | ||
517 | +}; | ||
518 | + | ||
519 | +static const DividerInitInfo divider_init_info_list[] = { | ||
520 | + [NPCM7XX_CLOCK_PLL1D2] = { | ||
521 | + .name = "pll1d2", | ||
522 | + .src_type = CLKSRC_PLL, | ||
523 | + .src_index = NPCM7XX_CLOCK_PLL1, | ||
524 | + .divide = divide_by_constant, | ||
525 | + .divisor = 2, | ||
526 | + }, | ||
527 | + [NPCM7XX_CLOCK_PLL2D2] = { | ||
528 | + .name = "pll2d2", | ||
529 | + .src_type = CLKSRC_PLL, | ||
530 | + .src_index = NPCM7XX_CLOCK_PLL2, | ||
531 | + .divide = divide_by_constant, | ||
532 | + .divisor = 2, | ||
533 | + }, | ||
534 | + [NPCM7XX_CLOCK_MC_DIVIDER] = { | ||
535 | + .name = "mc-divider", | ||
536 | + .src_type = CLKSRC_SEL, | ||
537 | + .src_index = NPCM7XX_CLOCK_MCCKSEL, | ||
538 | + .divide = divide_by_constant, | ||
539 | + .divisor = 2, | ||
540 | + .public_name = "mc-clock" | ||
541 | + }, | ||
542 | + [NPCM7XX_CLOCK_AXI_DIVIDER] = { | ||
543 | + .name = "axi-divider", | ||
544 | + .src_type = CLKSRC_SEL, | ||
545 | + .src_index = NPCM7XX_CLOCK_CPUCKSEL, | ||
546 | + .divide = shift_by_reg_divisor, | ||
547 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
548 | + .offset = 0, | ||
549 | + .len = 1, | ||
550 | + .public_name = "clk2" | ||
551 | + }, | ||
552 | + [NPCM7XX_CLOCK_AHB_DIVIDER] = { | ||
553 | + .name = "ahb-divider", | ||
554 | + .src_type = CLKSRC_DIV, | ||
555 | + .src_index = NPCM7XX_CLOCK_AXI_DIVIDER, | ||
556 | + .divide = divide_by_reg_divisor, | ||
557 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
558 | + .offset = 26, | ||
559 | + .len = 2, | ||
560 | + .public_name = "clk4" | ||
561 | + }, | ||
562 | + [NPCM7XX_CLOCK_AHB3_DIVIDER] = { | ||
563 | + .name = "ahb3-divider", | ||
564 | + .src_type = CLKSRC_DIV, | ||
565 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
566 | + .divide = divide_by_reg_divisor, | ||
567 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
568 | + .offset = 6, | ||
569 | + .len = 5, | ||
570 | + .public_name = "ahb3-spi3-clock" | ||
571 | + }, | ||
572 | + [NPCM7XX_CLOCK_SPI0_DIVIDER] = { | ||
573 | + .name = "spi0-divider", | ||
574 | + .src_type = CLKSRC_DIV, | ||
575 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
576 | + .divide = divide_by_reg_divisor, | ||
577 | + .reg = NPCM7XX_CLK_CLKDIV3, | ||
578 | + .offset = 6, | ||
579 | + .len = 5, | ||
580 | + .public_name = "spi0-clock", | ||
581 | + }, | ||
582 | + [NPCM7XX_CLOCK_SPIX_DIVIDER] = { | ||
583 | + .name = "spix-divider", | ||
584 | + .src_type = CLKSRC_DIV, | ||
585 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
586 | + .divide = divide_by_reg_divisor, | ||
587 | + .reg = NPCM7XX_CLK_CLKDIV3, | ||
588 | + .offset = 1, | ||
589 | + .len = 5, | ||
590 | + .public_name = "spix-clock", | ||
591 | + }, | ||
592 | + [NPCM7XX_CLOCK_APB1_DIVIDER] = { | ||
593 | + .name = "apb1-divider", | ||
594 | + .src_type = CLKSRC_DIV, | ||
595 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
596 | + .divide = shift_by_reg_divisor, | ||
597 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
598 | + .offset = 24, | ||
599 | + .len = 2, | ||
600 | + .public_name = "apb1-clock", | ||
601 | + }, | ||
602 | + [NPCM7XX_CLOCK_APB2_DIVIDER] = { | ||
603 | + .name = "apb2-divider", | ||
604 | + .src_type = CLKSRC_DIV, | ||
605 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
606 | + .divide = shift_by_reg_divisor, | ||
607 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
608 | + .offset = 26, | ||
609 | + .len = 2, | ||
610 | + .public_name = "apb2-clock", | ||
611 | + }, | ||
612 | + [NPCM7XX_CLOCK_APB3_DIVIDER] = { | ||
613 | + .name = "apb3-divider", | ||
614 | + .src_type = CLKSRC_DIV, | ||
615 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
616 | + .divide = shift_by_reg_divisor, | ||
617 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
618 | + .offset = 28, | ||
619 | + .len = 2, | ||
620 | + .public_name = "apb3-clock", | ||
621 | + }, | ||
622 | + [NPCM7XX_CLOCK_APB4_DIVIDER] = { | ||
623 | + .name = "apb4-divider", | ||
624 | + .src_type = CLKSRC_DIV, | ||
625 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
626 | + .divide = shift_by_reg_divisor, | ||
627 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
628 | + .offset = 30, | ||
629 | + .len = 2, | ||
630 | + .public_name = "apb4-clock", | ||
631 | + }, | ||
632 | + [NPCM7XX_CLOCK_APB5_DIVIDER] = { | ||
633 | + .name = "apb5-divider", | ||
634 | + .src_type = CLKSRC_DIV, | ||
635 | + .src_index = NPCM7XX_CLOCK_AHB_DIVIDER, | ||
636 | + .divide = shift_by_reg_divisor, | ||
637 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
638 | + .offset = 22, | ||
639 | + .len = 2, | ||
640 | + .public_name = "apb5-clock", | ||
641 | + }, | ||
642 | + [NPCM7XX_CLOCK_CLKOUT_DIVIDER] = { | ||
643 | + .name = "clkout-divider", | ||
644 | + .src_type = CLKSRC_SEL, | ||
645 | + .src_index = NPCM7XX_CLOCK_CLKOUTSEL, | ||
646 | + .divide = divide_by_reg_divisor, | ||
647 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
648 | + .offset = 16, | ||
649 | + .len = 5, | ||
650 | + .public_name = "clkout", | ||
651 | + }, | ||
652 | + [NPCM7XX_CLOCK_UART_DIVIDER] = { | ||
653 | + .name = "uart-divider", | ||
654 | + .src_type = CLKSRC_SEL, | ||
655 | + .src_index = NPCM7XX_CLOCK_UARTCKSEL, | ||
656 | + .divide = divide_by_reg_divisor, | ||
657 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
658 | + .offset = 16, | ||
659 | + .len = 5, | ||
660 | + .public_name = "uart-clock", | ||
661 | + }, | ||
662 | + [NPCM7XX_CLOCK_TIMER_DIVIDER] = { | ||
663 | + .name = "timer-divider", | ||
664 | + .src_type = CLKSRC_SEL, | ||
665 | + .src_index = NPCM7XX_CLOCK_TIMCKSEL, | ||
666 | + .divide = divide_by_reg_divisor, | ||
667 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
668 | + .offset = 21, | ||
669 | + .len = 5, | ||
670 | + .public_name = "timer-clock", | ||
671 | + }, | ||
672 | + [NPCM7XX_CLOCK_ADC_DIVIDER] = { | ||
673 | + .name = "adc-divider", | ||
674 | + .src_type = CLKSRC_DIV, | ||
675 | + .src_index = NPCM7XX_CLOCK_TIMER_DIVIDER, | ||
676 | + .divide = shift_by_reg_divisor, | ||
677 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
678 | + .offset = 28, | ||
679 | + .len = 3, | ||
680 | + .public_name = "adc-clock", | ||
681 | + }, | ||
682 | + [NPCM7XX_CLOCK_MMC_DIVIDER] = { | ||
683 | + .name = "mmc-divider", | ||
684 | + .src_type = CLKSRC_SEL, | ||
685 | + .src_index = NPCM7XX_CLOCK_SDCKSEL, | ||
686 | + .divide = divide_by_reg_divisor, | ||
687 | + .reg = NPCM7XX_CLK_CLKDIV1, | ||
688 | + .offset = 11, | ||
689 | + .len = 5, | ||
690 | + .public_name = "mmc-clock", | ||
691 | + }, | ||
692 | + [NPCM7XX_CLOCK_SDHC_DIVIDER] = { | ||
693 | + .name = "sdhc-divider", | ||
694 | + .src_type = CLKSRC_SEL, | ||
695 | + .src_index = NPCM7XX_CLOCK_SDCKSEL, | ||
696 | + .divide = divide_by_reg_divisor_times_2, | ||
697 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
698 | + .offset = 0, | ||
699 | + .len = 4, | ||
700 | + .public_name = "sdhc-clock", | ||
701 | + }, | ||
702 | + [NPCM7XX_CLOCK_GFXM_DIVIDER] = { | ||
703 | + .name = "gfxm-divider", | ||
704 | + .src_type = CLKSRC_SEL, | ||
705 | + .src_index = NPCM7XX_CLOCK_GFXMSEL, | ||
706 | + .divide = divide_by_constant, | ||
707 | + .divisor = 3, | ||
708 | + .public_name = "gfxm-clock", | ||
709 | + }, | ||
710 | + [NPCM7XX_CLOCK_UTMI_DIVIDER] = { | ||
711 | + .name = "utmi-divider", | ||
712 | + .src_type = CLKSRC_SEL, | ||
713 | + .src_index = NPCM7XX_CLOCK_SUCKSEL, | ||
714 | + .divide = divide_by_reg_divisor, | ||
715 | + .reg = NPCM7XX_CLK_CLKDIV2, | ||
716 | + .offset = 8, | ||
717 | + .len = 5, | ||
718 | + .public_name = "utmi-clock", | ||
719 | + }, | ||
720 | +}; | ||
721 | + | ||
722 | +static void npcm7xx_clk_pll_init(Object *obj) | ||
723 | +{ | ||
724 | + NPCM7xxClockPLLState *pll = NPCM7XX_CLOCK_PLL(obj); | ||
725 | + | ||
726 | + pll->clock_in = qdev_init_clock_in(DEVICE(pll), "clock-in", | ||
727 | + npcm7xx_clk_update_pll, pll); | ||
728 | + pll->clock_out = qdev_init_clock_out(DEVICE(pll), "clock-out"); | ||
729 | +} | ||
730 | + | ||
731 | +static void npcm7xx_clk_sel_init(Object *obj) | ||
732 | +{ | ||
733 | + int i; | ||
734 | + NPCM7xxClockSELState *sel = NPCM7XX_CLOCK_SEL(obj); | ||
735 | + | ||
736 | + for (i = 0; i < NPCM7XX_CLK_SEL_MAX_INPUT; ++i) { | ||
737 | + sel->clock_in[i] = qdev_init_clock_in(DEVICE(sel), | ||
738 | + g_strdup_printf("clock-in[%d]", i), | ||
739 | + npcm7xx_clk_update_sel, sel); | ||
740 | + } | ||
741 | + sel->clock_out = qdev_init_clock_out(DEVICE(sel), "clock-out"); | ||
742 | +} | ||
743 | +static void npcm7xx_clk_divider_init(Object *obj) | ||
744 | +{ | ||
745 | + NPCM7xxClockDividerState *div = NPCM7XX_CLOCK_DIVIDER(obj); | ||
746 | + | ||
747 | + div->clock_in = qdev_init_clock_in(DEVICE(div), "clock-in", | ||
748 | + npcm7xx_clk_update_divider, div); | ||
749 | + div->clock_out = qdev_init_clock_out(DEVICE(div), "clock-out"); | ||
750 | +} | ||
751 | + | ||
752 | +static void npcm7xx_init_clock_pll(NPCM7xxClockPLLState *pll, | ||
753 | + NPCM7xxCLKState *clk, const PLLInitInfo *init_info) | ||
754 | +{ | ||
755 | + pll->name = init_info->name; | ||
756 | + pll->clk = clk; | ||
757 | + pll->reg = init_info->reg; | ||
758 | + if (init_info->public_name != NULL) { | ||
759 | + qdev_alias_clock(DEVICE(pll), "clock-out", DEVICE(clk), | ||
760 | + init_info->public_name); | ||
761 | + } | ||
762 | +} | ||
763 | + | ||
764 | +static void npcm7xx_init_clock_sel(NPCM7xxClockSELState *sel, | ||
765 | + NPCM7xxCLKState *clk, const SELInitInfo *init_info) | ||
766 | +{ | ||
767 | + int input_size = init_info->input_size; | ||
768 | + | ||
769 | + sel->name = init_info->name; | ||
770 | + sel->clk = clk; | ||
771 | + sel->input_size = init_info->input_size; | ||
772 | + g_assert(input_size <= NPCM7XX_CLK_SEL_MAX_INPUT); | ||
773 | + sel->offset = init_info->offset; | ||
774 | + sel->len = init_info->len; | ||
775 | + if (init_info->public_name != NULL) { | ||
776 | + qdev_alias_clock(DEVICE(sel), "clock-out", DEVICE(clk), | ||
777 | + init_info->public_name); | ||
778 | + } | ||
779 | +} | ||
780 | + | ||
781 | +static void npcm7xx_init_clock_divider(NPCM7xxClockDividerState *div, | ||
782 | + NPCM7xxCLKState *clk, const DividerInitInfo *init_info) | ||
783 | +{ | ||
784 | + div->name = init_info->name; | ||
785 | + div->clk = clk; | ||
786 | + | ||
787 | + div->divide = init_info->divide; | ||
788 | + if (div->divide == divide_by_constant) { | ||
789 | + div->divisor = init_info->divisor; | ||
790 | + } else { | ||
791 | + div->reg = init_info->reg; | ||
792 | + div->offset = init_info->offset; | ||
793 | + div->len = init_info->len; | ||
794 | + } | ||
795 | + if (init_info->public_name != NULL) { | ||
796 | + qdev_alias_clock(DEVICE(div), "clock-out", DEVICE(clk), | ||
797 | + init_info->public_name); | ||
798 | + } | ||
799 | +} | ||
800 | + | ||
801 | +static Clock *npcm7xx_get_clock(NPCM7xxCLKState *clk, ClockSrcType type, | ||
802 | + int index) | ||
803 | +{ | ||
804 | + switch (type) { | ||
805 | + case CLKSRC_REF: | ||
806 | + return clk->clkref; | ||
807 | + case CLKSRC_PLL: | ||
808 | + return clk->plls[index].clock_out; | ||
809 | + case CLKSRC_SEL: | ||
810 | + return clk->sels[index].clock_out; | ||
811 | + case CLKSRC_DIV: | ||
812 | + return clk->dividers[index].clock_out; | ||
813 | + default: | ||
814 | + g_assert_not_reached(); | ||
815 | + } | ||
816 | +} | ||
817 | + | ||
818 | +static void npcm7xx_connect_clocks(NPCM7xxCLKState *clk) | ||
819 | +{ | ||
820 | + int i, j; | ||
821 | + Clock *src; | ||
822 | + | ||
823 | + for (i = 0; i < NPCM7XX_CLOCK_NR_PLLS; ++i) { | ||
824 | + src = npcm7xx_get_clock(clk, pll_init_info_list[i].src_type, | ||
825 | + pll_init_info_list[i].src_index); | ||
826 | + clock_set_source(clk->plls[i].clock_in, src); | ||
827 | + } | ||
828 | + for (i = 0; i < NPCM7XX_CLOCK_NR_SELS; ++i) { | ||
829 | + for (j = 0; j < sel_init_info_list[i].input_size; ++j) { | ||
830 | + src = npcm7xx_get_clock(clk, sel_init_info_list[i].src_type[j], | ||
831 | + sel_init_info_list[i].src_index[j]); | ||
832 | + clock_set_source(clk->sels[i].clock_in[j], src); | ||
833 | + } | ||
834 | + } | ||
835 | + for (i = 0; i < NPCM7XX_CLOCK_NR_DIVIDERS; ++i) { | ||
836 | + src = npcm7xx_get_clock(clk, divider_init_info_list[i].src_type, | ||
837 | + divider_init_info_list[i].src_index); | ||
838 | + clock_set_source(clk->dividers[i].clock_in, src); | ||
839 | + } | ||
840 | +} | ||
841 | + | ||
842 | static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size) | ||
843 | { | ||
844 | uint32_t reg = offset / sizeof(uint32_t); | ||
845 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size) | ||
846 | * | ||
847 | * The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000. | ||
848 | */ | ||
849 | - value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_HZ; | ||
850 | + value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_CLOCK_REF_HZ; | ||
851 | break; | ||
852 | |||
853 | default: | ||
854 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset, | ||
855 | value |= (value & PLLCON_LOKS); | ||
856 | } | ||
857 | } | ||
858 | + /* Only update PLL when it is locked. */ | ||
859 | + if (value & PLLCON_LOKI) { | ||
860 | + npcm7xx_clk_update_pll(&s->plls[find_pll_by_reg(reg)]); | ||
861 | + } | ||
862 | + break; | ||
863 | + | ||
864 | + case NPCM7XX_CLK_CLKSEL: | ||
865 | + npcm7xx_clk_update_all_sels(s); | ||
866 | + break; | ||
867 | + | ||
868 | + case NPCM7XX_CLK_CLKDIV1: | ||
869 | + case NPCM7XX_CLK_CLKDIV2: | ||
870 | + case NPCM7XX_CLK_CLKDIV3: | ||
871 | + npcm7xx_clk_update_all_dividers(s); | ||
872 | break; | ||
873 | |||
874 | case NPCM7XX_CLK_CNTR25M: | ||
875 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_enter_reset(Object *obj, ResetType type) | ||
876 | case RESET_TYPE_COLD: | ||
877 | memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values)); | ||
878 | s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
879 | + npcm7xx_clk_update_all_clocks(s); | ||
880 | return; | ||
881 | } | ||
882 | |||
883 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_enter_reset(Object *obj, ResetType type) | ||
884 | __func__, type); | ||
885 | } | ||
886 | |||
887 | +static void npcm7xx_clk_init_clock_hierarchy(NPCM7xxCLKState *s) | ||
888 | +{ | ||
889 | + int i; | ||
890 | + | ||
891 | + s->clkref = qdev_init_clock_in(DEVICE(s), "clkref", NULL, NULL); | ||
892 | + | ||
893 | + /* First pass: init all converter modules */ | ||
894 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(pll_init_info_list) != NPCM7XX_CLOCK_NR_PLLS); | ||
895 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(sel_init_info_list) != NPCM7XX_CLOCK_NR_SELS); | ||
896 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(divider_init_info_list) | ||
897 | + != NPCM7XX_CLOCK_NR_DIVIDERS); | ||
898 | + for (i = 0; i < NPCM7XX_CLOCK_NR_PLLS; ++i) { | ||
899 | + object_initialize_child(OBJECT(s), pll_init_info_list[i].name, | ||
900 | + &s->plls[i], TYPE_NPCM7XX_CLOCK_PLL); | ||
901 | + npcm7xx_init_clock_pll(&s->plls[i], s, | ||
902 | + &pll_init_info_list[i]); | ||
903 | + } | ||
904 | + for (i = 0; i < NPCM7XX_CLOCK_NR_SELS; ++i) { | ||
905 | + object_initialize_child(OBJECT(s), sel_init_info_list[i].name, | ||
906 | + &s->sels[i], TYPE_NPCM7XX_CLOCK_SEL); | ||
907 | + npcm7xx_init_clock_sel(&s->sels[i], s, | ||
908 | + &sel_init_info_list[i]); | ||
909 | + } | ||
910 | + for (i = 0; i < NPCM7XX_CLOCK_NR_DIVIDERS; ++i) { | ||
911 | + object_initialize_child(OBJECT(s), divider_init_info_list[i].name, | ||
912 | + &s->dividers[i], TYPE_NPCM7XX_CLOCK_DIVIDER); | ||
913 | + npcm7xx_init_clock_divider(&s->dividers[i], s, | ||
914 | + ÷r_init_info_list[i]); | ||
915 | + } | ||
916 | + | ||
917 | + /* Second pass: connect converter modules */ | ||
918 | + npcm7xx_connect_clocks(s); | ||
919 | + | ||
920 | + clock_update_hz(s->clkref, NPCM7XX_CLOCK_REF_HZ); | ||
921 | +} | ||
922 | + | ||
923 | static void npcm7xx_clk_init(Object *obj) | ||
924 | { | ||
925 | NPCM7xxCLKState *s = NPCM7XX_CLK(obj); | ||
926 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj) | ||
927 | memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s, | ||
928 | TYPE_NPCM7XX_CLK, 4 * KiB); | ||
929 | sysbus_init_mmio(&s->parent, &s->iomem); | ||
930 | - qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset, | ||
931 | - NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS); | ||
932 | } | ||
933 | |||
934 | -static const VMStateDescription vmstate_npcm7xx_clk = { | ||
935 | - .name = "npcm7xx-clk", | ||
936 | +static int npcm7xx_clk_post_load(void *opaque, int version_id) | ||
937 | +{ | ||
938 | + if (version_id >= 1) { | ||
939 | + NPCM7xxCLKState *clk = opaque; | ||
940 | + | ||
941 | + npcm7xx_clk_update_all_clocks(clk); | ||
942 | + } | ||
943 | + | ||
944 | + return 0; | ||
945 | +} | ||
946 | + | ||
947 | +static void npcm7xx_clk_realize(DeviceState *dev, Error **errp) | ||
948 | +{ | ||
949 | + int i; | ||
950 | + NPCM7xxCLKState *s = NPCM7XX_CLK(dev); | ||
951 | + | ||
952 | + qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset, | ||
953 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS); | ||
954 | + npcm7xx_clk_init_clock_hierarchy(s); | ||
955 | + | ||
956 | + /* Realize child devices */ | ||
957 | + for (i = 0; i < NPCM7XX_CLOCK_NR_PLLS; ++i) { | ||
958 | + if (!qdev_realize(DEVICE(&s->plls[i]), NULL, errp)) { | ||
959 | + return; | ||
960 | + } | ||
961 | + } | ||
962 | + for (i = 0; i < NPCM7XX_CLOCK_NR_SELS; ++i) { | ||
963 | + if (!qdev_realize(DEVICE(&s->sels[i]), NULL, errp)) { | ||
964 | + return; | ||
965 | + } | ||
966 | + } | ||
967 | + for (i = 0; i < NPCM7XX_CLOCK_NR_DIVIDERS; ++i) { | ||
968 | + if (!qdev_realize(DEVICE(&s->dividers[i]), NULL, errp)) { | ||
969 | + return; | ||
970 | + } | ||
971 | + } | ||
972 | +} | ||
973 | + | ||
974 | +static const VMStateDescription vmstate_npcm7xx_clk_pll = { | ||
975 | + .name = "npcm7xx-clock-pll", | ||
976 | .version_id = 0, | ||
977 | .minimum_version_id = 0, | ||
978 | - .fields = (VMStateField[]) { | ||
979 | - VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS), | ||
980 | - VMSTATE_INT64(ref_ns, NPCM7xxCLKState), | ||
981 | + .fields = (VMStateField[]) { | ||
982 | + VMSTATE_CLOCK(clock_in, NPCM7xxClockPLLState), | ||
983 | VMSTATE_END_OF_LIST(), | ||
984 | }, | ||
985 | }; | ||
986 | |||
987 | +static const VMStateDescription vmstate_npcm7xx_clk_sel = { | ||
988 | + .name = "npcm7xx-clock-sel", | ||
989 | + .version_id = 0, | ||
990 | + .minimum_version_id = 0, | ||
991 | + .fields = (VMStateField[]) { | ||
992 | + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(clock_in, NPCM7xxClockSELState, | ||
993 | + NPCM7XX_CLK_SEL_MAX_INPUT, 0, vmstate_clock, Clock), | ||
994 | + VMSTATE_END_OF_LIST(), | ||
995 | + }, | ||
996 | +}; | ||
997 | + | ||
998 | +static const VMStateDescription vmstate_npcm7xx_clk_divider = { | ||
999 | + .name = "npcm7xx-clock-divider", | ||
1000 | + .version_id = 0, | ||
1001 | + .minimum_version_id = 0, | ||
1002 | + .fields = (VMStateField[]) { | ||
1003 | + VMSTATE_CLOCK(clock_in, NPCM7xxClockDividerState), | ||
1004 | + VMSTATE_END_OF_LIST(), | ||
1005 | + }, | ||
1006 | +}; | ||
1007 | + | ||
1008 | +static const VMStateDescription vmstate_npcm7xx_clk = { | ||
1009 | + .name = "npcm7xx-clk", | ||
266 | + .version_id = 1, | 1010 | + .version_id = 1, |
267 | + .minimum_version_id = 1, | 1011 | + .minimum_version_id = 1, |
1012 | + .post_load = npcm7xx_clk_post_load, | ||
268 | + .fields = (VMStateField[]) { | 1013 | + .fields = (VMStateField[]) { |
269 | + VMSTATE_CLOCK(xosc_in, CprmanPllState), | 1014 | + VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS), |
270 | + VMSTATE_END_OF_LIST() | 1015 | + VMSTATE_INT64(ref_ns, NPCM7xxCLKState), |
271 | + } | 1016 | + VMSTATE_CLOCK(clkref, NPCM7xxCLKState), |
1017 | + VMSTATE_END_OF_LIST(), | ||
1018 | + }, | ||
272 | +}; | 1019 | +}; |
273 | + | 1020 | + |
274 | +static void pll_class_init(ObjectClass *klass, void *data) | 1021 | +static void npcm7xx_clk_pll_class_init(ObjectClass *klass, void *data) |
275 | +{ | 1022 | +{ |
276 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1023 | + DeviceClass *dc = DEVICE_CLASS(klass); |
277 | + | 1024 | + |
278 | + dc->vmsd = &pll_vmstate; | 1025 | + dc->desc = "NPCM7xx Clock PLL Module"; |
279 | +} | 1026 | + dc->vmsd = &vmstate_npcm7xx_clk_pll; |
280 | + | 1027 | +} |
281 | +static const TypeInfo cprman_pll_info = { | 1028 | + |
282 | + .name = TYPE_CPRMAN_PLL, | 1029 | +static void npcm7xx_clk_sel_class_init(ObjectClass *klass, void *data) |
283 | + .parent = TYPE_DEVICE, | 1030 | +{ |
284 | + .instance_size = sizeof(CprmanPllState), | 1031 | + DeviceClass *dc = DEVICE_CLASS(klass); |
285 | + .class_init = pll_class_init, | 1032 | + |
286 | + .instance_init = pll_init, | 1033 | + dc->desc = "NPCM7xx Clock SEL Module"; |
1034 | + dc->vmsd = &vmstate_npcm7xx_clk_sel; | ||
1035 | +} | ||
1036 | + | ||
1037 | +static void npcm7xx_clk_divider_class_init(ObjectClass *klass, void *data) | ||
1038 | +{ | ||
1039 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
1040 | + | ||
1041 | + dc->desc = "NPCM7xx Clock Divider Module"; | ||
1042 | + dc->vmsd = &vmstate_npcm7xx_clk_divider; | ||
1043 | +} | ||
1044 | + | ||
1045 | static void npcm7xx_clk_class_init(ObjectClass *klass, void *data) | ||
1046 | { | ||
1047 | ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
1048 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_class_init(ObjectClass *klass, void *data) | ||
1049 | |||
1050 | dc->desc = "NPCM7xx Clock Control Registers"; | ||
1051 | dc->vmsd = &vmstate_npcm7xx_clk; | ||
1052 | + dc->realize = npcm7xx_clk_realize; | ||
1053 | rc->phases.enter = npcm7xx_clk_enter_reset; | ||
1054 | } | ||
1055 | |||
1056 | +static const TypeInfo npcm7xx_clk_pll_info = { | ||
1057 | + .name = TYPE_NPCM7XX_CLOCK_PLL, | ||
1058 | + .parent = TYPE_DEVICE, | ||
1059 | + .instance_size = sizeof(NPCM7xxClockPLLState), | ||
1060 | + .instance_init = npcm7xx_clk_pll_init, | ||
1061 | + .class_init = npcm7xx_clk_pll_class_init, | ||
287 | +}; | 1062 | +}; |
288 | + | 1063 | + |
289 | + | 1064 | +static const TypeInfo npcm7xx_clk_sel_info = { |
290 | /* CPRMAN "top level" model */ | 1065 | + .name = TYPE_NPCM7XX_CLOCK_SEL, |
291 | 1066 | + .parent = TYPE_DEVICE, | |
292 | static uint64_t cprman_read(void *opaque, hwaddr offset, | 1067 | + .instance_size = sizeof(NPCM7xxClockSELState), |
293 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, | 1068 | + .instance_init = npcm7xx_clk_sel_init, |
294 | return r; | 1069 | + .class_init = npcm7xx_clk_sel_class_init, |
1070 | +}; | ||
1071 | + | ||
1072 | +static const TypeInfo npcm7xx_clk_divider_info = { | ||
1073 | + .name = TYPE_NPCM7XX_CLOCK_DIVIDER, | ||
1074 | + .parent = TYPE_DEVICE, | ||
1075 | + .instance_size = sizeof(NPCM7xxClockDividerState), | ||
1076 | + .instance_init = npcm7xx_clk_divider_init, | ||
1077 | + .class_init = npcm7xx_clk_divider_class_init, | ||
1078 | +}; | ||
1079 | + | ||
1080 | static const TypeInfo npcm7xx_clk_info = { | ||
1081 | .name = TYPE_NPCM7XX_CLK, | ||
1082 | .parent = TYPE_SYS_BUS_DEVICE, | ||
1083 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo npcm7xx_clk_info = { | ||
1084 | |||
1085 | static void npcm7xx_clk_register_type(void) | ||
1086 | { | ||
1087 | + type_register_static(&npcm7xx_clk_pll_info); | ||
1088 | + type_register_static(&npcm7xx_clk_sel_info); | ||
1089 | + type_register_static(&npcm7xx_clk_divider_info); | ||
1090 | type_register_static(&npcm7xx_clk_info); | ||
295 | } | 1091 | } |
296 | 1092 | type_init(npcm7xx_clk_register_type); | |
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 | -- | 1093 | -- |
409 | 2.20.1 | 1094 | 2.20.1 |
410 | 1095 | ||
411 | 1096 | diff view generated by jsdifflib |
1 | The armv7m systick timer is a 24-bit decrementing, wrap-on-zero, | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
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 | This patch makes NPCM7XX Timer to use a the timer clock generated by the |
7 | and we put a lot of effort into making sure it handles the | 4 | CLK module instead of the magic number TIMER_REF_HZ. |
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: Havard Skinnemoen <hskinnemoen@google.com> |
12 | a raw QEMU timer. | 7 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
8 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
9 | Message-id: 20210108190945.949196-3-wuhaotsh@google.com | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | include/hw/misc/npcm7xx_clk.h | 6 ----- | ||
14 | include/hw/timer/npcm7xx_timer.h | 1 + | ||
15 | hw/arm/npcm7xx.c | 5 ++++ | ||
16 | hw/timer/npcm7xx_timer.c | 39 +++++++++++++++----------------- | ||
17 | 4 files changed, 24 insertions(+), 27 deletions(-) | ||
13 | 18 | ||
14 | Unfortunately this is a migration compatibility break, | 19 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h |
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 | 20 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/include/hw/timer/armv7m_systick.h | 21 | --- a/include/hw/misc/npcm7xx_clk.h |
37 | +++ b/include/hw/timer/armv7m_systick.h | 22 | +++ b/include/hw/misc/npcm7xx_clk.h |
38 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ |
39 | 24 | #include "hw/clock.h" | |
40 | #include "hw/sysbus.h" | 25 | #include "hw/sysbus.h" |
41 | #include "qom/object.h" | 26 | |
42 | +#include "hw/ptimer.h" | 27 | -/* |
43 | 28 | - * The reference clock frequency for the timer modules, and the SECCNT and | |
44 | #define TYPE_SYSTICK "armv7m_systick" | 29 | - * CNTR25M registers in this module, is always 25 MHz. |
45 | 30 | - */ | |
46 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { | 31 | -#define NPCM7XX_TIMER_REF_HZ (25000000) |
47 | uint32_t control; | 32 | - |
48 | uint32_t reload; | 33 | /* |
49 | int64_t tick; | 34 | * Number of registers in our device state structure. Don't change this without |
50 | - QEMUTimer *timer; | 35 | * incrementing the version_id in the vmstate. |
51 | + ptimer_state *ptimer; | 36 | diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h |
52 | MemoryRegion iomem; | 37 | index XXXXXXX..XXXXXXX 100644 |
53 | qemu_irq irq; | 38 | --- a/include/hw/timer/npcm7xx_timer.h |
39 | +++ b/include/hw/timer/npcm7xx_timer.h | ||
40 | @@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState { | ||
41 | |||
42 | uint32_t tisr; | ||
43 | |||
44 | + Clock *clock; | ||
45 | NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL]; | ||
46 | NPCM7xxWatchdogTimer watchdog_timer; | ||
54 | }; | 47 | }; |
55 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | 48 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
56 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
57 | --- a/hw/timer/armv7m_systick.c | 50 | --- a/hw/arm/npcm7xx.c |
58 | +++ b/hw/timer/armv7m_systick.c | 51 | +++ b/hw/arm/npcm7xx.c |
59 | @@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s) | 52 | @@ -XXX,XX +XXX,XX @@ |
60 | } | 53 | #include "hw/char/serial.h" |
54 | #include "hw/loader.h" | ||
55 | #include "hw/misc/unimp.h" | ||
56 | +#include "hw/qdev-clock.h" | ||
57 | #include "hw/qdev-properties.h" | ||
58 | #include "qapi/error.h" | ||
59 | #include "qemu/units.h" | ||
60 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
61 | int first_irq; | ||
62 | int j; | ||
63 | |||
64 | + /* Connect the timer clock. */ | ||
65 | + qdev_connect_clock_in(DEVICE(&s->tim[i]), "clock", qdev_get_clock_out( | ||
66 | + DEVICE(&s->clk), "timer-clock")); | ||
67 | + | ||
68 | sysbus_realize(sbd, &error_abort); | ||
69 | sysbus_mmio_map(sbd, 0, npcm7xx_tim_addr[i]); | ||
70 | |||
71 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/hw/timer/npcm7xx_timer.c | ||
74 | +++ b/hw/timer/npcm7xx_timer.c | ||
75 | @@ -XXX,XX +XXX,XX @@ | ||
76 | #include "qemu/osdep.h" | ||
77 | |||
78 | #include "hw/irq.h" | ||
79 | +#include "hw/qdev-clock.h" | ||
80 | #include "hw/qdev-properties.h" | ||
81 | -#include "hw/misc/npcm7xx_clk.h" | ||
82 | #include "hw/timer/npcm7xx_timer.h" | ||
83 | #include "migration/vmstate.h" | ||
84 | #include "qemu/bitops.h" | ||
85 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_tcsr_prescaler(uint32_t tcsr) | ||
86 | /* Convert a timer cycle count to a time interval in nanoseconds. */ | ||
87 | static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count) | ||
88 | { | ||
89 | - int64_t ns = count; | ||
90 | + int64_t ticks = count; | ||
91 | |||
92 | - ns *= NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ; | ||
93 | - ns *= npcm7xx_tcsr_prescaler(t->tcsr); | ||
94 | + ticks *= npcm7xx_tcsr_prescaler(t->tcsr); | ||
95 | |||
96 | - return ns; | ||
97 | + return clock_ticks_to_ns(t->ctrl->clock, ticks); | ||
61 | } | 98 | } |
62 | 99 | ||
63 | -static void systick_reload(SysTickState *s, int reset) | 100 | /* Convert a time interval in nanoseconds to a timer cycle count. */ |
64 | -{ | 101 | static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns) |
65 | - /* The Cortex-M3 Devices Generic User Guide says that "When the | 102 | { |
66 | - * ENABLE bit is set to 1, the counter loads the RELOAD value from the | 103 | - int64_t count; |
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 | - | 104 | - |
72 | - if ((s->control & SYSTICK_ENABLE) == 0) { | 105 | - count = ns / (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ); |
73 | - return; | 106 | - count /= npcm7xx_tcsr_prescaler(t->tcsr); |
74 | - } | ||
75 | - | 107 | - |
76 | - if (reset) { | 108 | - return count; |
77 | - s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | 109 | + return ns / clock_ticks_to_ns(t->ctrl->clock, |
78 | - } | 110 | + npcm7xx_tcsr_prescaler(t->tcsr)); |
79 | - s->tick += (s->reload + 1) * systick_scale(s); | 111 | } |
80 | - timer_mod(s->timer, s->tick); | 112 | |
81 | -} | 113 | static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t) |
82 | - | 114 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t) |
83 | static void systick_timer_tick(void *opaque) | 115 | static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, |
116 | int64_t cycles) | ||
84 | { | 117 | { |
85 | SysTickState *s = (SysTickState *)opaque; | 118 | - uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t); |
86 | @@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque) | 119 | - int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles; |
87 | /* Tell the NVIC to pend the SysTick exception */ | 120 | + int64_t ticks = cycles * npcm7xx_watchdog_timer_prescaler(t); |
88 | qemu_irq_pulse(s->irq); | 121 | + int64_t ns = clock_ticks_to_ns(t->ctrl->clock, ticks); |
89 | } | 122 | |
90 | - if (s->reload == 0) { | 123 | /* |
91 | - s->control &= ~SYSTICK_ENABLE; | 124 | * The reset function always clears the current timer. The caller of the |
92 | - } else { | 125 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, |
93 | - systick_reload(s, 0); | 126 | */ |
94 | + if (ptimer_get_limit(s->ptimer) == 0) { | 127 | npcm7xx_timer_clear(&t->base_timer); |
95 | + /* | 128 | |
96 | + * Timer expiry with SYST_RVR zero disables the timer | 129 | - ns *= prescaler; |
97 | + * (but doesn't clear SYST_CSR.ENABLE) | 130 | t->base_timer.remaining_ns = ns; |
98 | + */ | ||
99 | + ptimer_stop(s->ptimer); | ||
100 | } | ||
101 | } | 131 | } |
102 | 132 | ||
103 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data, | 133 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj) |
104 | s->control &= ~SYSTICK_COUNTFLAG; | 134 | qemu_irq_lower(s->watchdog_timer.irq); |
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 | } | 135 | } |
221 | 136 | ||
222 | static void systick_instance_init(Object *obj) | 137 | -static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) |
223 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | 138 | +static void npcm7xx_timer_init(Object *obj) |
224 | static void systick_realize(DeviceState *dev, Error **errp) | ||
225 | { | 139 | { |
226 | SysTickState *s = SYSTICK(dev); | 140 | - NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev); |
227 | - s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s); | 141 | - SysBusDevice *sbd = &s->parent; |
228 | + s->ptimer = ptimer_init(systick_timer_tick, s, | 142 | + NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj); |
229 | + PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD | | 143 | + DeviceState *dev = DEVICE(obj); |
230 | + PTIMER_POLICY_NO_COUNTER_ROUND_DOWN | | 144 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
231 | + PTIMER_POLICY_NO_IMMEDIATE_RELOAD | | 145 | int i; |
232 | + PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); | 146 | NPCM7xxWatchdogTimer *w; |
147 | |||
148 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
149 | npcm7xx_watchdog_timer_expired, w); | ||
150 | sysbus_init_irq(sbd, &w->irq); | ||
151 | |||
152 | - memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s, | ||
153 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_timer_ops, s, | ||
154 | TYPE_NPCM7XX_TIMER, 4 * KiB); | ||
155 | sysbus_init_mmio(sbd, &s->iomem); | ||
156 | qdev_init_gpio_out_named(dev, &w->reset_signal, | ||
157 | NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 1); | ||
158 | + s->clock = qdev_init_clock_in(dev, "clock", NULL, NULL); | ||
233 | } | 159 | } |
234 | 160 | ||
235 | static const VMStateDescription vmstate_systick = { | 161 | static const VMStateDescription vmstate_npcm7xx_base_timer = { |
236 | .name = "armv7m_systick", | 162 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_npcm7xx_watchdog_timer = { |
163 | |||
164 | static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
165 | .name = "npcm7xx-timer-ctrl", | ||
237 | - .version_id = 1, | 166 | - .version_id = 1, |
238 | - .minimum_version_id = 1, | 167 | - .minimum_version_id = 1, |
239 | + .version_id = 2, | 168 | + .version_id = 2, |
240 | + .minimum_version_id = 2, | 169 | + .minimum_version_id = 2, |
241 | .fields = (VMStateField[]) { | 170 | .fields = (VMStateField[]) { |
242 | VMSTATE_UINT32(control, SysTickState), | 171 | VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState), |
243 | - VMSTATE_UINT32(reload, SysTickState), | 172 | + VMSTATE_CLOCK(clock, NPCM7xxTimerCtrlState), |
244 | VMSTATE_INT64(tick, SysTickState), | 173 | VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState, |
245 | - VMSTATE_TIMER_PTR(timer, SysTickState), | 174 | NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer, |
246 | + VMSTATE_PTIMER(ptimer, SysTickState), | 175 | NPCM7xxTimer), |
247 | VMSTATE_END_OF_LIST() | 176 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_class_init(ObjectClass *klass, void *data) |
248 | } | 177 | QEMU_BUILD_BUG_ON(NPCM7XX_TIMER_REGS_END > NPCM7XX_TIMER_NR_REGS); |
178 | |||
179 | dc->desc = "NPCM7xx Timer Controller"; | ||
180 | - dc->realize = npcm7xx_timer_realize; | ||
181 | dc->vmsd = &vmstate_npcm7xx_timer_ctrl; | ||
182 | rc->phases.enter = npcm7xx_timer_enter_reset; | ||
183 | rc->phases.hold = npcm7xx_timer_hold_reset; | ||
184 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo npcm7xx_timer_info = { | ||
185 | .parent = TYPE_SYS_BUS_DEVICE, | ||
186 | .instance_size = sizeof(NPCM7xxTimerCtrlState), | ||
187 | .class_init = npcm7xx_timer_class_init, | ||
188 | + .instance_init = npcm7xx_timer_init, | ||
249 | }; | 189 | }; |
190 | |||
191 | static void npcm7xx_timer_register_type(void) | ||
250 | -- | 192 | -- |
251 | 2.20.1 | 193 | 2.20.1 |
252 | 194 | ||
253 | 195 | 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 | The ADC is part of NPCM7XX Module. Its behavior is controled by the |
4 | identical except for some minor differences like the reset values of | 4 | ADC_CON register. It converts one of the eight analog inputs into a |
5 | some registers. Each controller controls up to 32 pins. | 5 | digital input and stores it in the ADC_DATA register when enabled. |
6 | 6 | ||
7 | Each individual pin is modeled as a pair of unnamed GPIOs -- one for | 7 | Users can alter input value by using qom-set QMP command. |
8 | emitting the actual pin state, and one for driving the pin externally. | ||
9 | Like the nRF51 GPIO controller, a gpio level may be negative, which | ||
10 | means the pin is not driven, or floating. | ||
11 | 8 | ||
9 | Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | 10 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
13 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | 11 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
12 | Message-id: 20210108190945.949196-4-wuhaotsh@google.com | ||
13 | [PMM: Added missing hw/adc/trace.h file] | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 16 | --- |
17 | docs/system/arm/nuvoton.rst | 2 +- | 17 | docs/system/arm/nuvoton.rst | 2 +- |
18 | include/hw/arm/npcm7xx.h | 2 + | 18 | meson.build | 1 + |
19 | include/hw/gpio/npcm7xx_gpio.h | 55 +++++ | 19 | hw/adc/trace.h | 1 + |
20 | hw/arm/npcm7xx.c | 80 ++++++ | 20 | include/hw/adc/npcm7xx_adc.h | 69 ++++++ |
21 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++ | 21 | include/hw/arm/npcm7xx.h | 2 + |
22 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++ | 22 | hw/adc/npcm7xx_adc.c | 301 ++++++++++++++++++++++++++ |
23 | hw/gpio/meson.build | 1 + | 23 | hw/arm/npcm7xx.c | 24 ++- |
24 | hw/gpio/trace-events | 7 + | 24 | tests/qtest/npcm7xx_adc-test.c | 377 +++++++++++++++++++++++++++++++++ |
25 | tests/qtest/meson.build | 3 +- | 25 | hw/adc/meson.build | 1 + |
26 | 9 files changed, 957 insertions(+), 2 deletions(-) | 26 | hw/adc/trace-events | 5 + |
27 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | 27 | tests/qtest/meson.build | 3 +- |
28 | create mode 100644 hw/gpio/npcm7xx_gpio.c | 28 | 11 files changed, 783 insertions(+), 3 deletions(-) |
29 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | 29 | create mode 100644 hw/adc/trace.h |
30 | create mode 100644 include/hw/adc/npcm7xx_adc.h | ||
31 | create mode 100644 hw/adc/npcm7xx_adc.c | ||
32 | create mode 100644 tests/qtest/npcm7xx_adc-test.c | ||
33 | create mode 100644 hw/adc/trace-events | ||
30 | 34 | ||
31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | 35 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
32 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/docs/system/arm/nuvoton.rst | 37 | --- a/docs/system/arm/nuvoton.rst |
34 | +++ b/docs/system/arm/nuvoton.rst | 38 | +++ b/docs/system/arm/nuvoton.rst |
35 | @@ -XXX,XX +XXX,XX @@ Supported devices | 39 | @@ -XXX,XX +XXX,XX @@ Supported devices |
36 | * Flash Interface Unit (FIU; no protection features) | ||
37 | * Random Number Generator (RNG) | 40 | * Random Number Generator (RNG) |
38 | * USB host (USBH) | 41 | * USB host (USBH) |
39 | + * GPIO controller | 42 | * GPIO controller |
43 | + * Analog to Digital Converter (ADC) | ||
40 | 44 | ||
41 | Missing devices | 45 | Missing devices |
42 | --------------- | 46 | --------------- |
43 | 47 | @@ -XXX,XX +XXX,XX @@ Missing devices | |
44 | - * GPIO controller | 48 | * USB device (USBD) |
45 | * LPC/eSPI host-to-BMC interface, including | 49 | * SMBus controller (SMBF) |
46 | 50 | * Peripheral SPI controller (PSPI) | |
47 | * Keyboard and mouse controller interface (KBCI) | 51 | - * Analog to Digital Converter (ADC) |
48 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | 52 | * SD/MMC host |
53 | * PECI interface | ||
54 | * Pulse Width Modulation (PWM) | ||
55 | diff --git a/meson.build b/meson.build | ||
49 | index XXXXXXX..XXXXXXX 100644 | 56 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/include/hw/arm/npcm7xx.h | 57 | --- a/meson.build |
51 | +++ b/include/hw/arm/npcm7xx.h | 58 | +++ b/meson.build |
52 | @@ -XXX,XX +XXX,XX @@ | 59 | @@ -XXX,XX +XXX,XX @@ if have_system |
53 | 60 | 'chardev', | |
54 | #include "hw/boards.h" | 61 | 'hw/9pfs', |
55 | #include "hw/cpu/a9mpcore.h" | 62 | 'hw/acpi', |
56 | +#include "hw/gpio/npcm7xx_gpio.h" | 63 | + 'hw/adc', |
57 | #include "hw/mem/npcm7xx_mc.h" | 64 | 'hw/alpha', |
58 | #include "hw/misc/npcm7xx_clk.h" | 65 | 'hw/arm', |
59 | #include "hw/misc/npcm7xx_gcr.h" | 66 | 'hw/audio', |
60 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | 67 | diff --git a/hw/adc/trace.h b/hw/adc/trace.h |
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 | 68 | new file mode 100644 |
70 | index XXXXXXX..XXXXXXX | 69 | index XXXXXXX..XXXXXXX |
71 | --- /dev/null | 70 | --- /dev/null |
72 | +++ b/include/hw/gpio/npcm7xx_gpio.h | 71 | +++ b/hw/adc/trace.h |
73 | @@ -XXX,XX +XXX,XX @@ | 72 | @@ -0,0 +1 @@ |
74 | +/* | 73 | +#include "trace/trace-hw_adc.h" |
75 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | 74 | diff --git a/include/hw/adc/npcm7xx_adc.h b/include/hw/adc/npcm7xx_adc.h |
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 | 75 | new file mode 100644 |
243 | index XXXXXXX..XXXXXXX | 76 | index XXXXXXX..XXXXXXX |
244 | --- /dev/null | 77 | --- /dev/null |
245 | +++ b/hw/gpio/npcm7xx_gpio.c | 78 | +++ b/include/hw/adc/npcm7xx_adc.h |
246 | @@ -XXX,XX +XXX,XX @@ | 79 | @@ -XXX,XX +XXX,XX @@ |
247 | +/* | 80 | +/* |
248 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | 81 | + * Nuvoton NPCM7xx ADC Module |
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 | + * | 82 | + * |
680 | + * Copyright 2020 Google LLC | 83 | + * Copyright 2020 Google LLC |
681 | + * | 84 | + * |
682 | + * This program is free software; you can redistribute it and/or modify it | 85 | + * 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 | 86 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
687 | + * This program is distributed in the hope that it will be useful, but WITHOUT | 90 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
688 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 91 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
689 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 92 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
690 | + * for more details. | 93 | + * for more details. |
691 | + */ | 94 | + */ |
95 | +#ifndef NPCM7XX_ADC_H | ||
96 | +#define NPCM7XX_ADC_H | ||
97 | + | ||
98 | +#include "hw/clock.h" | ||
99 | +#include "hw/irq.h" | ||
100 | +#include "hw/sysbus.h" | ||
101 | +#include "qemu/timer.h" | ||
102 | + | ||
103 | +#define NPCM7XX_ADC_NUM_INPUTS 8 | ||
104 | +/** | ||
105 | + * This value should not be changed unless write_adc_calibration function in | ||
106 | + * hw/arm/npcm7xx.c is also changed. | ||
107 | + */ | ||
108 | +#define NPCM7XX_ADC_NUM_CALIB 2 | ||
109 | + | ||
110 | +/** | ||
111 | + * struct NPCM7xxADCState - Analog to Digital Converter Module device state. | ||
112 | + * @parent: System bus device. | ||
113 | + * @iomem: Memory region through which registers are accessed. | ||
114 | + * @conv_timer: The timer counts down remaining cycles for the conversion. | ||
115 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
116 | + * @con: The Control Register. | ||
117 | + * @data: The Data Buffer. | ||
118 | + * @clock: The ADC Clock. | ||
119 | + * @adci: The input voltage in units of uV. 1uv = 1e-6V. | ||
120 | + * @vref: The external reference voltage. | ||
121 | + * @iref: The internal reference voltage, initialized at launch time. | ||
122 | + * @rv: The calibrated output values of 0.5V and 1.5V for the ADC. | ||
123 | + */ | ||
124 | +typedef struct { | ||
125 | + SysBusDevice parent; | ||
126 | + | ||
127 | + MemoryRegion iomem; | ||
128 | + | ||
129 | + QEMUTimer conv_timer; | ||
130 | + | ||
131 | + qemu_irq irq; | ||
132 | + uint32_t con; | ||
133 | + uint32_t data; | ||
134 | + Clock *clock; | ||
135 | + | ||
136 | + /* Voltages are in unit of uV. 1V = 1000000uV. */ | ||
137 | + uint32_t adci[NPCM7XX_ADC_NUM_INPUTS]; | ||
138 | + uint32_t vref; | ||
139 | + uint32_t iref; | ||
140 | + | ||
141 | + uint16_t calibration_r_values[NPCM7XX_ADC_NUM_CALIB]; | ||
142 | +} NPCM7xxADCState; | ||
143 | + | ||
144 | +#define TYPE_NPCM7XX_ADC "npcm7xx-adc" | ||
145 | +#define NPCM7XX_ADC(obj) \ | ||
146 | + OBJECT_CHECK(NPCM7xxADCState, (obj), TYPE_NPCM7XX_ADC) | ||
147 | + | ||
148 | +#endif /* NPCM7XX_ADC_H */ | ||
149 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/include/hw/arm/npcm7xx.h | ||
152 | +++ b/include/hw/arm/npcm7xx.h | ||
153 | @@ -XXX,XX +XXX,XX @@ | ||
154 | #define NPCM7XX_H | ||
155 | |||
156 | #include "hw/boards.h" | ||
157 | +#include "hw/adc/npcm7xx_adc.h" | ||
158 | #include "hw/cpu/a9mpcore.h" | ||
159 | #include "hw/gpio/npcm7xx_gpio.h" | ||
160 | #include "hw/mem/npcm7xx_mc.h" | ||
161 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | ||
162 | NPCM7xxGCRState gcr; | ||
163 | NPCM7xxCLKState clk; | ||
164 | NPCM7xxTimerCtrlState tim[3]; | ||
165 | + NPCM7xxADCState adc; | ||
166 | NPCM7xxOTPState key_storage; | ||
167 | NPCM7xxOTPState fuse_array; | ||
168 | NPCM7xxMCState mc; | ||
169 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c | ||
170 | new file mode 100644 | ||
171 | index XXXXXXX..XXXXXXX | ||
172 | --- /dev/null | ||
173 | +++ b/hw/adc/npcm7xx_adc.c | ||
174 | @@ -XXX,XX +XXX,XX @@ | ||
175 | +/* | ||
176 | + * Nuvoton NPCM7xx ADC Module | ||
177 | + * | ||
178 | + * Copyright 2020 Google LLC | ||
179 | + * | ||
180 | + * This program is free software; you can redistribute it and/or modify it | ||
181 | + * under the terms of the GNU General Public License as published by the | ||
182 | + * Free Software Foundation; either version 2 of the License, or | ||
183 | + * (at your option) any later version. | ||
184 | + * | ||
185 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
186 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
187 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
188 | + * for more details. | ||
189 | + */ | ||
692 | + | 190 | + |
693 | +#include "qemu/osdep.h" | 191 | +#include "qemu/osdep.h" |
694 | +#include "libqtest-single.h" | 192 | +#include "hw/adc/npcm7xx_adc.h" |
695 | + | 193 | +#include "hw/qdev-clock.h" |
696 | +#define NR_GPIO_DEVICES (8) | 194 | +#include "hw/qdev-properties.h" |
697 | +#define GPIO(x) (0xf0010000 + (x) * 0x1000) | 195 | +#include "hw/registerfields.h" |
698 | +#define GPIO_IRQ(x) (116 + (x)) | 196 | +#include "migration/vmstate.h" |
699 | + | 197 | +#include "qemu/log.h" |
700 | +/* GPIO registers */ | 198 | +#include "qemu/module.h" |
701 | +#define GP_N_TLOCK1 0x00 | 199 | +#include "qemu/timer.h" |
702 | +#define GP_N_DIN 0x04 /* Data IN */ | 200 | +#include "qemu/units.h" |
703 | +#define GP_N_POL 0x08 /* Polarity */ | 201 | +#include "trace.h" |
704 | +#define GP_N_DOUT 0x0c /* Data OUT */ | 202 | + |
705 | +#define GP_N_OE 0x10 /* Output Enable */ | 203 | +REG32(NPCM7XX_ADC_CON, 0x0) |
706 | +#define GP_N_OTYP 0x14 | 204 | +REG32(NPCM7XX_ADC_DATA, 0x4) |
707 | +#define GP_N_MP 0x18 | 205 | + |
708 | +#define GP_N_PU 0x1c /* Pull-up */ | 206 | +/* Register field definitions. */ |
709 | +#define GP_N_PD 0x20 /* Pull-down */ | 207 | +#define NPCM7XX_ADC_CON_MUX(rv) extract32(rv, 24, 4) |
710 | +#define GP_N_DBNC 0x24 /* Debounce */ | 208 | +#define NPCM7XX_ADC_CON_INT_EN BIT(21) |
711 | +#define GP_N_EVTYP 0x28 /* Event Type */ | 209 | +#define NPCM7XX_ADC_CON_REFSEL BIT(19) |
712 | +#define GP_N_EVBE 0x2c /* Event Both Edge */ | 210 | +#define NPCM7XX_ADC_CON_INT BIT(18) |
713 | +#define GP_N_OBL0 0x30 | 211 | +#define NPCM7XX_ADC_CON_EN BIT(17) |
714 | +#define GP_N_OBL1 0x34 | 212 | +#define NPCM7XX_ADC_CON_RST BIT(16) |
715 | +#define GP_N_OBL2 0x38 | 213 | +#define NPCM7XX_ADC_CON_CONV BIT(14) |
716 | +#define GP_N_OBL3 0x3c | 214 | +#define NPCM7XX_ADC_CON_DIV(rv) extract32(rv, 1, 8) |
717 | +#define GP_N_EVEN 0x40 /* Event Enable */ | 215 | + |
718 | +#define GP_N_EVENS 0x44 /* Event Set (enable) */ | 216 | +#define NPCM7XX_ADC_MAX_RESULT 1023 |
719 | +#define GP_N_EVENC 0x48 /* Event Clear (disable) */ | 217 | +#define NPCM7XX_ADC_DEFAULT_IREF 2000000 |
720 | +#define GP_N_EVST 0x4c /* Event Status */ | 218 | +#define NPCM7XX_ADC_CONV_CYCLES 20 |
721 | +#define GP_N_SPLCK 0x50 | 219 | +#define NPCM7XX_ADC_RESET_CYCLES 10 |
722 | +#define GP_N_MPLCK 0x54 | 220 | +#define NPCM7XX_ADC_R0_INPUT 500000 |
723 | +#define GP_N_IEM 0x58 /* Input Enable */ | 221 | +#define NPCM7XX_ADC_R1_INPUT 1500000 |
724 | +#define GP_N_OSRC 0x5c | 222 | + |
725 | +#define GP_N_ODSC 0x60 | 223 | +static void npcm7xx_adc_reset(NPCM7xxADCState *s) |
726 | +#define GP_N_DOS 0x68 /* Data OUT Set */ | 224 | +{ |
727 | +#define GP_N_DOC 0x6c /* Data OUT Clear */ | 225 | + timer_del(&s->conv_timer); |
728 | +#define GP_N_OES 0x70 /* Output Enable Set */ | 226 | + s->con = 0x000c0001; |
729 | +#define GP_N_OEC 0x74 /* Output Enable Clear */ | 227 | + s->data = 0x00000000; |
730 | +#define GP_N_TLOCK2 0x7c | 228 | +} |
731 | + | 229 | + |
732 | +static void gpio_unlock(int n) | 230 | +static uint32_t npcm7xx_adc_convert(uint32_t input, uint32_t ref) |
733 | +{ | 231 | +{ |
734 | + if (readl(GPIO(n) + GP_N_TLOCK1) != 0) { | 232 | + uint32_t result; |
735 | + writel(GPIO(n) + GP_N_TLOCK2, 0xc0de1248); | 233 | + |
736 | + writel(GPIO(n) + GP_N_TLOCK1, 0xc0defa73); | 234 | + result = input * (NPCM7XX_ADC_MAX_RESULT + 1) / ref; |
737 | + } | 235 | + if (result > NPCM7XX_ADC_MAX_RESULT) { |
738 | +} | 236 | + result = NPCM7XX_ADC_MAX_RESULT; |
739 | + | 237 | + } |
740 | +/* Restore the GPIO controller to a sensible default state. */ | 238 | + |
741 | +static void gpio_reset(int n) | 239 | + return result; |
742 | +{ | 240 | +} |
743 | + gpio_unlock(0); | 241 | + |
744 | + | 242 | +static uint32_t npcm7xx_adc_prescaler(NPCM7xxADCState *s) |
745 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | 243 | +{ |
746 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | 244 | + return 2 * (NPCM7XX_ADC_CON_DIV(s->con) + 1); |
747 | + writel(GPIO(n) + GP_N_POL, 0x00000000); | 245 | +} |
748 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | 246 | + |
749 | + writel(GPIO(n) + GP_N_OE, 0x00000000); | 247 | +static void npcm7xx_adc_start_timer(Clock *clk, QEMUTimer *timer, |
750 | + writel(GPIO(n) + GP_N_OTYP, 0x00000000); | 248 | + uint32_t cycles, uint32_t prescaler) |
751 | + writel(GPIO(n) + GP_N_PU, 0xffffffff); | 249 | +{ |
752 | + writel(GPIO(n) + GP_N_PD, 0x00000000); | 250 | + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
753 | + writel(GPIO(n) + GP_N_IEM, 0xffffffff); | 251 | + int64_t ticks = cycles; |
754 | +} | 252 | + int64_t ns; |
755 | + | 253 | + |
756 | +static void test_dout_to_din(void) | 254 | + ticks *= prescaler; |
757 | +{ | 255 | + ns = clock_ticks_to_ns(clk, ticks); |
758 | + gpio_reset(0); | 256 | + ns += now; |
759 | + | 257 | + timer_mod(timer, ns); |
760 | + /* When output is enabled, DOUT should be reflected on DIN. */ | 258 | +} |
761 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 259 | + |
762 | + /* PU and PD shouldn't have any impact on DIN. */ | 260 | +static void npcm7xx_adc_start_convert(NPCM7xxADCState *s) |
763 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | 261 | +{ |
764 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | 262 | + uint32_t prescaler = npcm7xx_adc_prescaler(s); |
765 | + writel(GPIO(0) + GP_N_DOUT, 0x12345678); | 263 | + |
766 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x12345678); | 264 | + npcm7xx_adc_start_timer(s->clock, &s->conv_timer, NPCM7XX_ADC_CONV_CYCLES, |
767 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x12345678); | 265 | + prescaler); |
768 | +} | 266 | +} |
769 | + | 267 | + |
770 | +static void test_pullup_pulldown(void) | 268 | +static void npcm7xx_adc_convert_done(void *opaque) |
771 | +{ | 269 | +{ |
772 | + gpio_reset(0); | 270 | + NPCM7xxADCState *s = opaque; |
271 | + uint32_t input = NPCM7XX_ADC_CON_MUX(s->con); | ||
272 | + uint32_t ref = (s->con & NPCM7XX_ADC_CON_REFSEL) | ||
273 | + ? s->iref : s->vref; | ||
274 | + | ||
275 | + if (input >= NPCM7XX_ADC_NUM_INPUTS) { | ||
276 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid input: %u\n", | ||
277 | + __func__, input); | ||
278 | + return; | ||
279 | + } | ||
280 | + s->data = npcm7xx_adc_convert(s->adci[input], ref); | ||
281 | + if (s->con & NPCM7XX_ADC_CON_INT_EN) { | ||
282 | + s->con |= NPCM7XX_ADC_CON_INT; | ||
283 | + qemu_irq_raise(s->irq); | ||
284 | + } | ||
285 | + s->con &= ~NPCM7XX_ADC_CON_CONV; | ||
286 | +} | ||
287 | + | ||
288 | +static void npcm7xx_adc_calibrate(NPCM7xxADCState *adc) | ||
289 | +{ | ||
290 | + adc->calibration_r_values[0] = npcm7xx_adc_convert(NPCM7XX_ADC_R0_INPUT, | ||
291 | + adc->iref); | ||
292 | + adc->calibration_r_values[1] = npcm7xx_adc_convert(NPCM7XX_ADC_R1_INPUT, | ||
293 | + adc->iref); | ||
294 | +} | ||
295 | + | ||
296 | +static void npcm7xx_adc_write_con(NPCM7xxADCState *s, uint32_t new_con) | ||
297 | +{ | ||
298 | + uint32_t old_con = s->con; | ||
299 | + | ||
300 | + /* Write ADC_INT to 1 to clear it */ | ||
301 | + if (new_con & NPCM7XX_ADC_CON_INT) { | ||
302 | + new_con &= ~NPCM7XX_ADC_CON_INT; | ||
303 | + qemu_irq_lower(s->irq); | ||
304 | + } else if (old_con & NPCM7XX_ADC_CON_INT) { | ||
305 | + new_con |= NPCM7XX_ADC_CON_INT; | ||
306 | + } | ||
307 | + | ||
308 | + s->con = new_con; | ||
309 | + | ||
310 | + if (s->con & NPCM7XX_ADC_CON_RST) { | ||
311 | + npcm7xx_adc_reset(s); | ||
312 | + return; | ||
313 | + } | ||
314 | + | ||
315 | + if ((s->con & NPCM7XX_ADC_CON_EN)) { | ||
316 | + if (s->con & NPCM7XX_ADC_CON_CONV) { | ||
317 | + if (!(old_con & NPCM7XX_ADC_CON_CONV)) { | ||
318 | + npcm7xx_adc_start_convert(s); | ||
319 | + } | ||
320 | + } else { | ||
321 | + timer_del(&s->conv_timer); | ||
322 | + } | ||
323 | + } | ||
324 | +} | ||
325 | + | ||
326 | +static uint64_t npcm7xx_adc_read(void *opaque, hwaddr offset, unsigned size) | ||
327 | +{ | ||
328 | + uint64_t value = 0; | ||
329 | + NPCM7xxADCState *s = opaque; | ||
330 | + | ||
331 | + switch (offset) { | ||
332 | + case A_NPCM7XX_ADC_CON: | ||
333 | + value = s->con; | ||
334 | + break; | ||
335 | + | ||
336 | + case A_NPCM7XX_ADC_DATA: | ||
337 | + value = s->data; | ||
338 | + break; | ||
339 | + | ||
340 | + default: | ||
341 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
342 | + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", | ||
343 | + __func__, offset); | ||
344 | + break; | ||
345 | + } | ||
346 | + | ||
347 | + trace_npcm7xx_adc_read(DEVICE(s)->canonical_path, offset, value); | ||
348 | + return value; | ||
349 | +} | ||
350 | + | ||
351 | +static void npcm7xx_adc_write(void *opaque, hwaddr offset, uint64_t v, | ||
352 | + unsigned size) | ||
353 | +{ | ||
354 | + NPCM7xxADCState *s = opaque; | ||
355 | + | ||
356 | + trace_npcm7xx_adc_write(DEVICE(s)->canonical_path, offset, v); | ||
357 | + switch (offset) { | ||
358 | + case A_NPCM7XX_ADC_CON: | ||
359 | + npcm7xx_adc_write_con(s, v); | ||
360 | + break; | ||
361 | + | ||
362 | + case A_NPCM7XX_ADC_DATA: | ||
363 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
364 | + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n", | ||
365 | + __func__, offset); | ||
366 | + break; | ||
367 | + | ||
368 | + default: | ||
369 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
370 | + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", | ||
371 | + __func__, offset); | ||
372 | + break; | ||
373 | + } | ||
374 | + | ||
375 | +} | ||
376 | + | ||
377 | +static const struct MemoryRegionOps npcm7xx_adc_ops = { | ||
378 | + .read = npcm7xx_adc_read, | ||
379 | + .write = npcm7xx_adc_write, | ||
380 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
381 | + .valid = { | ||
382 | + .min_access_size = 4, | ||
383 | + .max_access_size = 4, | ||
384 | + .unaligned = false, | ||
385 | + }, | ||
386 | +}; | ||
387 | + | ||
388 | +static void npcm7xx_adc_enter_reset(Object *obj, ResetType type) | ||
389 | +{ | ||
390 | + NPCM7xxADCState *s = NPCM7XX_ADC(obj); | ||
391 | + | ||
392 | + npcm7xx_adc_reset(s); | ||
393 | +} | ||
394 | + | ||
395 | +static void npcm7xx_adc_hold_reset(Object *obj) | ||
396 | +{ | ||
397 | + NPCM7xxADCState *s = NPCM7XX_ADC(obj); | ||
398 | + | ||
399 | + qemu_irq_lower(s->irq); | ||
400 | +} | ||
401 | + | ||
402 | +static void npcm7xx_adc_init(Object *obj) | ||
403 | +{ | ||
404 | + NPCM7xxADCState *s = NPCM7XX_ADC(obj); | ||
405 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
406 | + int i; | ||
407 | + | ||
408 | + sysbus_init_irq(sbd, &s->irq); | ||
409 | + | ||
410 | + timer_init_ns(&s->conv_timer, QEMU_CLOCK_VIRTUAL, | ||
411 | + npcm7xx_adc_convert_done, s); | ||
412 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_adc_ops, s, | ||
413 | + TYPE_NPCM7XX_ADC, 4 * KiB); | ||
414 | + sysbus_init_mmio(sbd, &s->iomem); | ||
415 | + s->clock = qdev_init_clock_in(DEVICE(s), "clock", NULL, NULL); | ||
416 | + | ||
417 | + for (i = 0; i < NPCM7XX_ADC_NUM_INPUTS; ++i) { | ||
418 | + object_property_add_uint32_ptr(obj, "adci[*]", | ||
419 | + &s->adci[i], OBJ_PROP_FLAG_WRITE); | ||
420 | + } | ||
421 | + object_property_add_uint32_ptr(obj, "vref", | ||
422 | + &s->vref, OBJ_PROP_FLAG_WRITE); | ||
423 | + npcm7xx_adc_calibrate(s); | ||
424 | +} | ||
425 | + | ||
426 | +static const VMStateDescription vmstate_npcm7xx_adc = { | ||
427 | + .name = "npcm7xx-adc", | ||
428 | + .version_id = 0, | ||
429 | + .minimum_version_id = 0, | ||
430 | + .fields = (VMStateField[]) { | ||
431 | + VMSTATE_TIMER(conv_timer, NPCM7xxADCState), | ||
432 | + VMSTATE_UINT32(con, NPCM7xxADCState), | ||
433 | + VMSTATE_UINT32(data, NPCM7xxADCState), | ||
434 | + VMSTATE_CLOCK(clock, NPCM7xxADCState), | ||
435 | + VMSTATE_UINT32_ARRAY(adci, NPCM7xxADCState, NPCM7XX_ADC_NUM_INPUTS), | ||
436 | + VMSTATE_UINT32(vref, NPCM7xxADCState), | ||
437 | + VMSTATE_UINT32(iref, NPCM7xxADCState), | ||
438 | + VMSTATE_UINT16_ARRAY(calibration_r_values, NPCM7xxADCState, | ||
439 | + NPCM7XX_ADC_NUM_CALIB), | ||
440 | + VMSTATE_END_OF_LIST(), | ||
441 | + }, | ||
442 | +}; | ||
443 | + | ||
444 | +static Property npcm7xx_timer_properties[] = { | ||
445 | + DEFINE_PROP_UINT32("iref", NPCM7xxADCState, iref, NPCM7XX_ADC_DEFAULT_IREF), | ||
446 | + DEFINE_PROP_END_OF_LIST(), | ||
447 | +}; | ||
448 | + | ||
449 | +static void npcm7xx_adc_class_init(ObjectClass *klass, void *data) | ||
450 | +{ | ||
451 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
452 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
453 | + | ||
454 | + dc->desc = "NPCM7xx ADC Module"; | ||
455 | + dc->vmsd = &vmstate_npcm7xx_adc; | ||
456 | + rc->phases.enter = npcm7xx_adc_enter_reset; | ||
457 | + rc->phases.hold = npcm7xx_adc_hold_reset; | ||
458 | + | ||
459 | + device_class_set_props(dc, npcm7xx_timer_properties); | ||
460 | +} | ||
461 | + | ||
462 | +static const TypeInfo npcm7xx_adc_info = { | ||
463 | + .name = TYPE_NPCM7XX_ADC, | ||
464 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
465 | + .instance_size = sizeof(NPCM7xxADCState), | ||
466 | + .class_init = npcm7xx_adc_class_init, | ||
467 | + .instance_init = npcm7xx_adc_init, | ||
468 | +}; | ||
469 | + | ||
470 | +static void npcm7xx_adc_register_types(void) | ||
471 | +{ | ||
472 | + type_register_static(&npcm7xx_adc_info); | ||
473 | +} | ||
474 | + | ||
475 | +type_init(npcm7xx_adc_register_types); | ||
476 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
477 | index XXXXXXX..XXXXXXX 100644 | ||
478 | --- a/hw/arm/npcm7xx.c | ||
479 | +++ b/hw/arm/npcm7xx.c | ||
480 | @@ -XXX,XX +XXX,XX @@ | ||
481 | #define NPCM7XX_EHCI_BA (0xf0806000) | ||
482 | #define NPCM7XX_OHCI_BA (0xf0807000) | ||
483 | |||
484 | +/* ADC Module */ | ||
485 | +#define NPCM7XX_ADC_BA (0xf000c000) | ||
486 | + | ||
487 | /* Internal AHB SRAM */ | ||
488 | #define NPCM7XX_RAM3_BA (0xc0008000) | ||
489 | #define NPCM7XX_RAM3_SZ (4 * KiB) | ||
490 | @@ -XXX,XX +XXX,XX @@ | ||
491 | #define NPCM7XX_ROM_BA (0xffff0000) | ||
492 | #define NPCM7XX_ROM_SZ (64 * KiB) | ||
493 | |||
494 | + | ||
495 | /* Clock configuration values to be fixed up when bypassing bootloader */ | ||
496 | |||
497 | /* Run PLL1 at 1600 MHz */ | ||
498 | @@ -XXX,XX +XXX,XX @@ | ||
499 | * interrupts. | ||
500 | */ | ||
501 | enum NPCM7xxInterrupt { | ||
502 | + NPCM7XX_ADC_IRQ = 0, | ||
503 | NPCM7XX_UART0_IRQ = 2, | ||
504 | NPCM7XX_UART1_IRQ, | ||
505 | NPCM7XX_UART2_IRQ, | ||
506 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init_fuses(NPCM7xxState *s) | ||
507 | sizeof(value)); | ||
508 | } | ||
509 | |||
510 | +static void npcm7xx_write_adc_calibration(NPCM7xxState *s) | ||
511 | +{ | ||
512 | + /* Both ADC and the fuse array must have realized. */ | ||
513 | + QEMU_BUILD_BUG_ON(sizeof(s->adc.calibration_r_values) != 4); | ||
514 | + npcm7xx_otp_array_write(&s->fuse_array, s->adc.calibration_r_values, | ||
515 | + NPCM7XX_FUSE_ADC_CALIB, sizeof(s->adc.calibration_r_values)); | ||
516 | +} | ||
517 | + | ||
518 | static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n) | ||
519 | { | ||
520 | return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n); | ||
521 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
522 | TYPE_NPCM7XX_FUSE_ARRAY); | ||
523 | object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); | ||
524 | object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG); | ||
525 | + object_initialize_child(obj, "adc", &s->adc, TYPE_NPCM7XX_ADC); | ||
526 | |||
527 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | ||
528 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
529 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
530 | sysbus_realize(SYS_BUS_DEVICE(&s->mc), &error_abort); | ||
531 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->mc), 0, NPCM7XX_MC_BA); | ||
532 | |||
533 | + /* ADC Modules. Cannot fail. */ | ||
534 | + qdev_connect_clock_in(DEVICE(&s->adc), "clock", qdev_get_clock_out( | ||
535 | + DEVICE(&s->clk), "adc-clock")); | ||
536 | + sysbus_realize(SYS_BUS_DEVICE(&s->adc), &error_abort); | ||
537 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->adc), 0, NPCM7XX_ADC_BA); | ||
538 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->adc), 0, | ||
539 | + npcm7xx_irq(s, NPCM7XX_ADC_IRQ)); | ||
540 | + npcm7xx_write_adc_calibration(s); | ||
541 | + | ||
542 | /* Timer Modules (TIM). Cannot fail. */ | ||
543 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim)); | ||
544 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | ||
545 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
546 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); | ||
547 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | ||
548 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | ||
549 | - create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | ||
550 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | ||
551 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | ||
552 | create_unimplemented_device("npcm7xx.gpio[1]", 0xf0011000, 4 * KiB); | ||
553 | diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c | ||
554 | new file mode 100644 | ||
555 | index XXXXXXX..XXXXXXX | ||
556 | --- /dev/null | ||
557 | +++ b/tests/qtest/npcm7xx_adc-test.c | ||
558 | @@ -XXX,XX +XXX,XX @@ | ||
559 | +/* | ||
560 | + * QTests for Nuvoton NPCM7xx ADCModules. | ||
561 | + * | ||
562 | + * Copyright 2020 Google LLC | ||
563 | + * | ||
564 | + * This program is free software; you can redistribute it and/or modify it | ||
565 | + * under the terms of the GNU General Public License as published by the | ||
566 | + * Free Software Foundation; either version 2 of the License, or | ||
567 | + * (at your option) any later version. | ||
568 | + * | ||
569 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
570 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
571 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
572 | + * for more details. | ||
573 | + */ | ||
574 | + | ||
575 | +#include "qemu/osdep.h" | ||
576 | +#include "qemu/bitops.h" | ||
577 | +#include "qemu/timer.h" | ||
578 | +#include "libqos/libqtest.h" | ||
579 | +#include "qapi/qmp/qdict.h" | ||
580 | + | ||
581 | +#define REF_HZ (25000000) | ||
582 | + | ||
583 | +#define CON_OFFSET 0x0 | ||
584 | +#define DATA_OFFSET 0x4 | ||
585 | + | ||
586 | +#define NUM_INPUTS 8 | ||
587 | +#define DEFAULT_IREF 2000000 | ||
588 | +#define CONV_CYCLES 20 | ||
589 | +#define RESET_CYCLES 10 | ||
590 | +#define R0_INPUT 500000 | ||
591 | +#define R1_INPUT 1500000 | ||
592 | +#define MAX_RESULT 1023 | ||
593 | + | ||
594 | +#define DEFAULT_CLKDIV 5 | ||
595 | + | ||
596 | +#define FUSE_ARRAY_BA 0xf018a000 | ||
597 | +#define FCTL_OFFSET 0x14 | ||
598 | +#define FST_OFFSET 0x0 | ||
599 | +#define FADDR_OFFSET 0x4 | ||
600 | +#define FDATA_OFFSET 0x8 | ||
601 | +#define ADC_CALIB_ADDR 24 | ||
602 | +#define FUSE_READ 0x2 | ||
603 | + | ||
604 | +/* Register field definitions. */ | ||
605 | +#define CON_MUX(rv) ((rv) << 24) | ||
606 | +#define CON_INT_EN BIT(21) | ||
607 | +#define CON_REFSEL BIT(19) | ||
608 | +#define CON_INT BIT(18) | ||
609 | +#define CON_EN BIT(17) | ||
610 | +#define CON_RST BIT(16) | ||
611 | +#define CON_CONV BIT(14) | ||
612 | +#define CON_DIV(rv) extract32(rv, 1, 8) | ||
613 | + | ||
614 | +#define FST_RDST BIT(1) | ||
615 | +#define FDATA_MASK 0xff | ||
616 | + | ||
617 | +#define MAX_ERROR 10000 | ||
618 | +#define MIN_CALIB_INPUT 100000 | ||
619 | +#define MAX_CALIB_INPUT 1800000 | ||
620 | + | ||
621 | +static const uint32_t input_list[] = { | ||
622 | + 100000, | ||
623 | + 500000, | ||
624 | + 1000000, | ||
625 | + 1500000, | ||
626 | + 1800000, | ||
627 | + 2000000, | ||
628 | +}; | ||
629 | + | ||
630 | +static const uint32_t vref_list[] = { | ||
631 | + 2000000, | ||
632 | + 2200000, | ||
633 | + 2500000, | ||
634 | +}; | ||
635 | + | ||
636 | +static const uint32_t iref_list[] = { | ||
637 | + 1800000, | ||
638 | + 1900000, | ||
639 | + 2000000, | ||
640 | + 2100000, | ||
641 | + 2200000, | ||
642 | +}; | ||
643 | + | ||
644 | +static const uint32_t div_list[] = {0, 1, 3, 7, 15}; | ||
645 | + | ||
646 | +typedef struct ADC { | ||
647 | + int irq; | ||
648 | + uint64_t base_addr; | ||
649 | +} ADC; | ||
650 | + | ||
651 | +ADC adc = { | ||
652 | + .irq = 0, | ||
653 | + .base_addr = 0xf000c000 | ||
654 | +}; | ||
655 | + | ||
656 | +static uint32_t adc_read_con(QTestState *qts, const ADC *adc) | ||
657 | +{ | ||
658 | + return qtest_readl(qts, adc->base_addr + CON_OFFSET); | ||
659 | +} | ||
660 | + | ||
661 | +static void adc_write_con(QTestState *qts, const ADC *adc, uint32_t value) | ||
662 | +{ | ||
663 | + qtest_writel(qts, adc->base_addr + CON_OFFSET, value); | ||
664 | +} | ||
665 | + | ||
666 | +static uint32_t adc_read_data(QTestState *qts, const ADC *adc) | ||
667 | +{ | ||
668 | + return qtest_readl(qts, adc->base_addr + DATA_OFFSET); | ||
669 | +} | ||
670 | + | ||
671 | +static uint32_t adc_calibrate(uint32_t measured, uint32_t *rv) | ||
672 | +{ | ||
673 | + return R0_INPUT + (R1_INPUT - R0_INPUT) * (int32_t)(measured - rv[0]) | ||
674 | + / (int32_t)(rv[1] - rv[0]); | ||
675 | +} | ||
676 | + | ||
677 | +static void adc_qom_set(QTestState *qts, const ADC *adc, | ||
678 | + const char *name, uint32_t value) | ||
679 | +{ | ||
680 | + QDict *response; | ||
681 | + const char *path = "/machine/soc/adc"; | ||
682 | + | ||
683 | + g_test_message("Setting properties %s of %s with value %u", | ||
684 | + name, path, value); | ||
685 | + response = qtest_qmp(qts, "{ 'execute': 'qom-set'," | ||
686 | + " 'arguments': { 'path': %s, 'property': %s, 'value': %u}}", | ||
687 | + path, name, value); | ||
688 | + /* The qom set message returns successfully. */ | ||
689 | + g_assert_true(qdict_haskey(response, "return")); | ||
690 | +} | ||
691 | + | ||
692 | +static void adc_write_input(QTestState *qts, const ADC *adc, | ||
693 | + uint32_t index, uint32_t value) | ||
694 | +{ | ||
695 | + char name[100]; | ||
696 | + | ||
697 | + sprintf(name, "adci[%u]", index); | ||
698 | + adc_qom_set(qts, adc, name, value); | ||
699 | +} | ||
700 | + | ||
701 | +static void adc_write_vref(QTestState *qts, const ADC *adc, uint32_t value) | ||
702 | +{ | ||
703 | + adc_qom_set(qts, adc, "vref", value); | ||
704 | +} | ||
705 | + | ||
706 | +static uint32_t adc_calculate_output(uint32_t input, uint32_t ref) | ||
707 | +{ | ||
708 | + uint32_t output; | ||
709 | + | ||
710 | + g_assert_cmpuint(input, <=, ref); | ||
711 | + output = (input * (MAX_RESULT + 1)) / ref; | ||
712 | + if (output > MAX_RESULT) { | ||
713 | + output = MAX_RESULT; | ||
714 | + } | ||
715 | + | ||
716 | + return output; | ||
717 | +} | ||
718 | + | ||
719 | +static uint32_t adc_prescaler(QTestState *qts, const ADC *adc) | ||
720 | +{ | ||
721 | + uint32_t div = extract32(adc_read_con(qts, adc), 1, 8); | ||
722 | + | ||
723 | + return 2 * (div + 1); | ||
724 | +} | ||
725 | + | ||
726 | +static int64_t adc_calculate_steps(uint32_t cycles, uint32_t prescale, | ||
727 | + uint32_t clkdiv) | ||
728 | +{ | ||
729 | + return (NANOSECONDS_PER_SECOND / (REF_HZ >> clkdiv)) * cycles * prescale; | ||
730 | +} | ||
731 | + | ||
732 | +static void adc_wait_conv_finished(QTestState *qts, const ADC *adc, | ||
733 | + uint32_t clkdiv) | ||
734 | +{ | ||
735 | + uint32_t prescaler = adc_prescaler(qts, adc); | ||
773 | + | 736 | + |
774 | + /* | 737 | + /* |
775 | + * When output is disabled, and PD is the inverse of PU, PU should be | 738 | + * ADC should takes roughly 20 cycles to convert one sample. So we assert it |
776 | + * reflected on DIN. If PD is not the inverse of PU, the state of DIN is | 739 | + * should take 10~30 cycles here. |
777 | + * undefined, so we don't test that. | ||
778 | + */ | 740 | + */ |
779 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | 741 | + qtest_clock_step(qts, adc_calculate_steps(CONV_CYCLES / 2, prescaler, |
780 | + /* DOUT shouldn't have any impact on DIN. */ | 742 | + clkdiv)); |
781 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | 743 | + /* ADC is still converting. */ |
782 | + writel(GPIO(0) + GP_N_PU, 0x23456789); | 744 | + g_assert_true(adc_read_con(qts, adc) & CON_CONV); |
783 | + writel(GPIO(0) + GP_N_PD, ~0x23456789U); | 745 | + qtest_clock_step(qts, adc_calculate_steps(CONV_CYCLES, prescaler, clkdiv)); |
784 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PU), ==, 0x23456789); | 746 | + /* ADC has finished conversion. */ |
785 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PD), ==, ~0x23456789U); | 747 | + g_assert_false(adc_read_con(qts, adc) & CON_CONV); |
786 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x23456789); | 748 | +} |
787 | +} | 749 | + |
788 | + | 750 | +/* Check ADC can be reset to default value. */ |
789 | +static void test_output_enable(void) | 751 | +static void test_init(gconstpointer adc_p) |
790 | +{ | 752 | +{ |
791 | + gpio_reset(0); | 753 | + const ADC *adc = adc_p; |
792 | + | 754 | + |
793 | + /* | 755 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
794 | + * With all pins weakly pulled down, and DOUT all-ones, OE should be | 756 | + adc_write_con(qts, adc, CON_REFSEL | CON_INT); |
795 | + * reflected on DIN. | 757 | + g_assert_cmphex(adc_read_con(qts, adc), ==, CON_REFSEL); |
796 | + */ | 758 | + qtest_quit(qts); |
797 | + writel(GPIO(0) + GP_N_DOUT, 0xffffffff); | 759 | +} |
798 | + writel(GPIO(0) + GP_N_PU, 0x00000000); | 760 | + |
799 | + writel(GPIO(0) + GP_N_PD, 0xffffffff); | 761 | +/* Check ADC can convert from an internal reference. */ |
800 | + writel(GPIO(0) + GP_N_OE, 0x3456789a); | 762 | +static void test_convert_internal(gconstpointer adc_p) |
801 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3456789a); | 763 | +{ |
802 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3456789a); | 764 | + const ADC *adc = adc_p; |
803 | + | 765 | + uint32_t index, input, output, expected_output; |
804 | + writel(GPIO(0) + GP_N_OEC, 0x00030002); | 766 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
805 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x34547898); | 767 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
806 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x34547898); | 768 | + |
807 | + | 769 | + for (index = 0; index < NUM_INPUTS; ++index) { |
808 | + writel(GPIO(0) + GP_N_OES, 0x0000f001); | 770 | + for (size_t i = 0; i < ARRAY_SIZE(input_list); ++i) { |
809 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3454f899); | 771 | + input = input_list[i]; |
810 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3454f899); | 772 | + expected_output = adc_calculate_output(input, DEFAULT_IREF); |
811 | +} | 773 | + |
812 | + | 774 | + adc_write_input(qts, adc, index, input); |
813 | +static void test_open_drain(void) | 775 | + adc_write_con(qts, adc, CON_MUX(index) | CON_REFSEL | CON_INT | |
814 | +{ | 776 | + CON_EN | CON_CONV); |
815 | + gpio_reset(0); | 777 | + adc_wait_conv_finished(qts, adc, DEFAULT_CLKDIV); |
816 | + | 778 | + g_assert_cmphex(adc_read_con(qts, adc), ==, CON_MUX(index) | |
817 | + /* | 779 | + CON_REFSEL | CON_EN); |
818 | + * Upper half of DOUT drives a 1 only if the corresponding bit in OTYP is | 780 | + g_assert_false(qtest_get_irq(qts, adc->irq)); |
819 | + * not set. If OTYP is set, DIN is determined by PU/PD. Lower half of | 781 | + output = adc_read_data(qts, adc); |
820 | + * DOUT always drives a 0 regardless of OTYP; PU/PD have no effect. When | 782 | + g_assert_cmpuint(output, ==, expected_output); |
821 | + * OE is 0, output is determined by PU/PD; OTYP has no effect. | 783 | + } |
822 | + */ | 784 | + } |
823 | + writel(GPIO(0) + GP_N_OTYP, 0x456789ab); | 785 | + |
824 | + writel(GPIO(0) + GP_N_OE, 0xf0f0f0f0); | 786 | + qtest_quit(qts); |
825 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | 787 | +} |
826 | + writel(GPIO(0) + GP_N_PU, 0xff00ff00); | 788 | + |
827 | + writel(GPIO(0) + GP_N_PD, 0x00ff00ff); | 789 | +/* Check ADC can convert from an external reference. */ |
828 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OTYP), ==, 0x456789ab); | 790 | +static void test_convert_external(gconstpointer adc_p) |
829 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff900f00); | 791 | +{ |
830 | +} | 792 | + const ADC *adc = adc_p; |
831 | + | 793 | + uint32_t index, input, vref, output, expected_output; |
832 | +static void test_polarity(void) | 794 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
833 | +{ | 795 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
834 | + gpio_reset(0); | 796 | + |
835 | + | 797 | + for (index = 0; index < NUM_INPUTS; ++index) { |
836 | + /* | 798 | + for (size_t i = 0; i < ARRAY_SIZE(input_list); ++i) { |
837 | + * In push-pull mode, DIN should reflect DOUT because the signal is | 799 | + for (size_t j = 0; j < ARRAY_SIZE(vref_list); ++j) { |
838 | + * inverted in both directions. | 800 | + input = input_list[i]; |
839 | + */ | 801 | + vref = vref_list[j]; |
840 | + writel(GPIO(0) + GP_N_OTYP, 0x00000000); | 802 | + expected_output = adc_calculate_output(input, vref); |
841 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 803 | + |
842 | + writel(GPIO(0) + GP_N_DOUT, 0x56789abc); | 804 | + adc_write_input(qts, adc, index, input); |
843 | + writel(GPIO(0) + GP_N_POL, 0x6789abcd); | 805 | + adc_write_vref(qts, adc, vref); |
844 | + g_assert_cmphex(readl(GPIO(0) + GP_N_POL), ==, 0x6789abcd); | 806 | + adc_write_con(qts, adc, CON_MUX(index) | CON_INT | CON_EN | |
845 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x56789abc); | 807 | + CON_CONV); |
846 | + | 808 | + adc_wait_conv_finished(qts, adc, DEFAULT_CLKDIV); |
847 | + /* | 809 | + g_assert_cmphex(adc_read_con(qts, adc), ==, |
848 | + * When turning off the drivers, DIN should reflect the inverse of the | 810 | + CON_MUX(index) | CON_EN); |
849 | + * pulled-up lines. | 811 | + g_assert_false(qtest_get_irq(qts, adc->irq)); |
850 | + */ | 812 | + output = adc_read_data(qts, adc); |
851 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | 813 | + g_assert_cmpuint(output, ==, expected_output); |
852 | + writel(GPIO(0) + GP_N_POL, 0xffffffff); | 814 | + } |
853 | + writel(GPIO(0) + GP_N_PU, 0x789abcde); | 815 | + } |
854 | + writel(GPIO(0) + GP_N_PD, ~0x789abcdeU); | 816 | + } |
855 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, ~0x789abcdeU); | 817 | + |
856 | + | 818 | + qtest_quit(qts); |
857 | + /* | 819 | +} |
858 | + * In open-drain mode, DOUT=1 will appear to drive the pin high (since DIN | 820 | + |
859 | + * is inverted), while DOUT=0 will leave the pin floating. | 821 | +/* Check ADC interrupt files if and only if CON_INT_EN is set. */ |
860 | + */ | 822 | +static void test_interrupt(gconstpointer adc_p) |
861 | + writel(GPIO(0) + GP_N_OTYP, 0xffffffff); | 823 | +{ |
862 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 824 | + const ADC *adc = adc_p; |
863 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | 825 | + uint32_t index, input, output, expected_output; |
864 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | 826 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
865 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | 827 | + |
866 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff00ffff); | 828 | + index = 1; |
867 | +} | 829 | + input = input_list[1]; |
868 | + | 830 | + expected_output = adc_calculate_output(input, DEFAULT_IREF); |
869 | +static void test_input_mask(void) | 831 | + |
870 | +{ | 832 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
871 | + gpio_reset(0); | 833 | + adc_write_input(qts, adc, index, input); |
872 | + | 834 | + g_assert_false(qtest_get_irq(qts, adc->irq)); |
873 | + /* IEM=0 forces the input to zero before polarity inversion. */ | 835 | + adc_write_con(qts, adc, CON_MUX(index) | CON_INT_EN | CON_REFSEL | CON_INT |
874 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 836 | + | CON_EN | CON_CONV); |
875 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | 837 | + adc_wait_conv_finished(qts, adc, DEFAULT_CLKDIV); |
876 | + writel(GPIO(0) + GP_N_POL, 0xffff0000); | 838 | + g_assert_cmphex(adc_read_con(qts, adc), ==, CON_MUX(index) | CON_INT_EN |
877 | + writel(GPIO(0) + GP_N_IEM, 0x87654321); | 839 | + | CON_REFSEL | CON_INT | CON_EN); |
878 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff9a4300); | 840 | + g_assert_true(qtest_get_irq(qts, adc->irq)); |
879 | +} | 841 | + output = adc_read_data(qts, adc); |
880 | + | 842 | + g_assert_cmpuint(output, ==, expected_output); |
881 | +static void test_temp_lock(void) | 843 | + |
882 | +{ | 844 | + qtest_quit(qts); |
883 | + gpio_reset(0); | 845 | +} |
884 | + | 846 | + |
885 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | 847 | +/* Check ADC is reset after setting ADC_RST for 10 ADC cycles. */ |
886 | + | 848 | +static void test_reset(gconstpointer adc_p) |
887 | + /* Make sure we're unlocked initially. */ | 849 | +{ |
888 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | 850 | + const ADC *adc = adc_p; |
889 | + /* Writing any value to TLOCK1 will lock. */ | 851 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
890 | + writel(GPIO(0) + GP_N_TLOCK1, 0); | 852 | + |
891 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | 853 | + for (size_t i = 0; i < ARRAY_SIZE(div_list); ++i) { |
892 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | 854 | + uint32_t div = div_list[i]; |
893 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | 855 | + |
894 | + /* Now, try to unlock. */ | 856 | + adc_write_con(qts, adc, CON_INT | CON_EN | CON_RST | CON_DIV(div)); |
895 | + gpio_unlock(0); | 857 | + qtest_clock_step(qts, adc_calculate_steps(RESET_CYCLES, |
896 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | 858 | + adc_prescaler(qts, adc), DEFAULT_CLKDIV)); |
897 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | 859 | + g_assert_false(adc_read_con(qts, adc) & CON_EN); |
898 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | 860 | + } |
899 | + | 861 | + qtest_quit(qts); |
900 | + /* Try it again, but write TLOCK2 to lock. */ | 862 | +} |
901 | + writel(GPIO(0) + GP_N_TLOCK2, 0); | 863 | + |
902 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | 864 | +/* Check ADC Calibration works as desired. */ |
903 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | 865 | +static void test_calibrate(gconstpointer adc_p) |
904 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | 866 | +{ |
905 | + /* Now, try to unlock. */ | 867 | + int i, j; |
906 | + gpio_unlock(0); | 868 | + const ADC *adc = adc_p; |
907 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | 869 | + |
908 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | 870 | + for (j = 0; j < ARRAY_SIZE(iref_list); ++j) { |
909 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | 871 | + uint32_t iref = iref_list[j]; |
910 | +} | 872 | + uint32_t expected_rv[] = { |
911 | + | 873 | + adc_calculate_output(R0_INPUT, iref), |
912 | +static void test_events_level(void) | 874 | + adc_calculate_output(R1_INPUT, iref), |
913 | +{ | 875 | + }; |
914 | + gpio_reset(0); | 876 | + char buf[100]; |
915 | + | 877 | + QTestState *qts; |
916 | + writel(GPIO(0) + GP_N_EVTYP, 0x00000000); | 878 | + |
917 | + writel(GPIO(0) + GP_N_DOUT, 0xba987654); | 879 | + sprintf(buf, "-machine quanta-gsj -global npcm7xx-adc.iref=%u", iref); |
918 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 880 | + qts = qtest_init(buf); |
919 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | 881 | + |
920 | + | 882 | + /* Check the converted value is correct using the calibration value. */ |
921 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | 883 | + for (i = 0; i < ARRAY_SIZE(input_list); ++i) { |
922 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 884 | + uint32_t input; |
923 | + writel(GPIO(0) + GP_N_DOUT, 0x00000000); | 885 | + uint32_t output; |
924 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | 886 | + uint32_t expected_output; |
925 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 887 | + uint32_t calibrated_voltage; |
926 | + writel(GPIO(0) + GP_N_EVST, 0x00007654); | 888 | + uint32_t index = 0; |
927 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba980000); | 889 | + |
928 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 890 | + input = input_list[i]; |
929 | + writel(GPIO(0) + GP_N_EVST, 0xba980000); | 891 | + /* Calibration only works for input range 0.1V ~ 1.8V. */ |
930 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | 892 | + if (input < MIN_CALIB_INPUT || input > MAX_CALIB_INPUT) { |
931 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 893 | + continue; |
932 | +} | 894 | + } |
933 | + | 895 | + expected_output = adc_calculate_output(input, iref); |
934 | +static void test_events_rising_edge(void) | 896 | + |
935 | +{ | 897 | + adc_write_input(qts, adc, index, input); |
936 | + gpio_reset(0); | 898 | + adc_write_con(qts, adc, CON_MUX(index) | CON_REFSEL | CON_INT | |
937 | + | 899 | + CON_EN | CON_CONV); |
938 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | 900 | + adc_wait_conv_finished(qts, adc, DEFAULT_CLKDIV); |
939 | + writel(GPIO(0) + GP_N_EVBE, 0x00000000); | 901 | + g_assert_cmphex(adc_read_con(qts, adc), ==, |
940 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | 902 | + CON_REFSEL | CON_MUX(index) | CON_EN); |
941 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | 903 | + output = adc_read_data(qts, adc); |
942 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | 904 | + g_assert_cmpuint(output, ==, expected_output); |
943 | + | 905 | + |
944 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | 906 | + calibrated_voltage = adc_calibrate(output, expected_rv); |
945 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 907 | + g_assert_cmpuint(calibrated_voltage, >, input - MAX_ERROR); |
946 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | 908 | + g_assert_cmpuint(calibrated_voltage, <, input + MAX_ERROR); |
947 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x0000ff00); | 909 | + } |
948 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 910 | + |
949 | + writel(GPIO(0) + GP_N_DOUT, 0x00ff0000); | 911 | + qtest_quit(qts); |
950 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | 912 | + } |
951 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 913 | +} |
952 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | 914 | + |
953 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ff0f00); | 915 | +static void adc_add_test(const char *name, const ADC* wd, |
954 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 916 | + GTestDataFunc fn) |
955 | + writel(GPIO(0) + GP_N_EVST, 0x00ff0f00); | 917 | +{ |
956 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | 918 | + g_autofree char *full_name = g_strdup_printf("npcm7xx_adc/%s", name); |
957 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | 919 | + qtest_add_data_func(full_name, wd, fn); |
958 | +} | 920 | +} |
959 | + | 921 | +#define add_test(name, td) adc_add_test(#name, td, test_##name) |
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 | + | 922 | + |
1030 | +int main(int argc, char **argv) | 923 | +int main(int argc, char **argv) |
1031 | +{ | 924 | +{ |
1032 | + int ret; | ||
1033 | + int i; | ||
1034 | + | ||
1035 | + g_test_init(&argc, &argv, NULL); | 925 | + g_test_init(&argc, &argv, NULL); |
1036 | + g_test_set_nonfatal_assertions(); | 926 | + |
1037 | + | 927 | + add_test(init, &adc); |
1038 | + qtest_add_func("/npcm7xx_gpio/dout_to_din", test_dout_to_din); | 928 | + add_test(convert_internal, &adc); |
1039 | + qtest_add_func("/npcm7xx_gpio/pullup_pulldown", test_pullup_pulldown); | 929 | + add_test(convert_external, &adc); |
1040 | + qtest_add_func("/npcm7xx_gpio/output_enable", test_output_enable); | 930 | + add_test(interrupt, &adc); |
1041 | + qtest_add_func("/npcm7xx_gpio/open_drain", test_open_drain); | 931 | + add_test(reset, &adc); |
1042 | + qtest_add_func("/npcm7xx_gpio/polarity", test_polarity); | 932 | + add_test(calibrate, &adc); |
1043 | + qtest_add_func("/npcm7xx_gpio/input_mask", test_input_mask); | 933 | + |
1044 | + qtest_add_func("/npcm7xx_gpio/temp_lock", test_temp_lock); | 934 | + return g_test_run(); |
1045 | + qtest_add_func("/npcm7xx_gpio/events/level", test_events_level); | 935 | +} |
1046 | + qtest_add_func("/npcm7xx_gpio/events/rising_edge", test_events_rising_edge); | 936 | diff --git a/hw/adc/meson.build b/hw/adc/meson.build |
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 | + } | ||
1054 | + | ||
1055 | + qtest_start("-machine npcm750-evb"); | ||
1056 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/a9mpcore/gic"); | ||
1057 | + ret = g_test_run(); | ||
1058 | + qtest_end(); | ||
1059 | + | ||
1060 | + return ret; | ||
1061 | +} | ||
1062 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | ||
1063 | index XXXXXXX..XXXXXXX 100644 | 937 | index XXXXXXX..XXXXXXX 100644 |
1064 | --- a/hw/gpio/meson.build | 938 | --- a/hw/adc/meson.build |
1065 | +++ b/hw/gpio/meson.build | 939 | +++ b/hw/adc/meson.build |
1066 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c')) | 940 | @@ -1 +1,2 @@ |
1067 | softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c')) | 941 | softmmu_ss.add(when: 'CONFIG_STM32F2XX_ADC', if_true: files('stm32f2xx_adc.c')) |
1068 | 942 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_adc.c')) | |
1069 | softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c')) | 943 | diff --git a/hw/adc/trace-events b/hw/adc/trace-events |
1070 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) | 944 | new file mode 100644 |
1071 | softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) | 945 | index XXXXXXX..XXXXXXX |
1072 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) | 946 | --- /dev/null |
1073 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) | 947 | +++ b/hw/adc/trace-events |
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 @@ | 948 | @@ -XXX,XX +XXX,XX @@ |
1079 | # See docs/devel/tracing.txt for syntax documentation. | 949 | +# See docs/devel/tracing.txt for syntax documentation. |
1080 | 950 | + | |
1081 | +# npcm7xx_gpio.c | 951 | +# npcm7xx_adc.c |
1082 | +npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | 952 | +npcm7xx_adc_read(const char *id, uint64_t offset, uint32_t value) " %s offset: 0x%04" PRIx64 " value 0x%04" PRIx32 |
1083 | +npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | 953 | +npcm7xx_adc_write(const char *id, uint64_t offset, uint32_t value) "%s offset: 0x%04" PRIx64 " value 0x%04" PRIx32 |
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 | 954 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
1092 | index XXXXXXX..XXXXXXX 100644 | 955 | index XXXXXXX..XXXXXXX 100644 |
1093 | --- a/tests/qtest/meson.build | 956 | --- a/tests/qtest/meson.build |
1094 | +++ b/tests/qtest/meson.build | 957 | +++ b/tests/qtest/meson.build |
1095 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | 958 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ |
1096 | ['prom-env-test', 'boot-serial-test'] | 959 | ['prom-env-test', 'boot-serial-test'] |
1097 | 960 | ||
1098 | qtests_npcm7xx = \ | 961 | qtests_npcm7xx = \ |
1099 | - ['npcm7xx_rng-test', | 962 | - ['npcm7xx_gpio-test', |
1100 | + ['npcm7xx_gpio-test', | 963 | + ['npcm7xx_adc-test', |
1101 | + 'npcm7xx_rng-test', | 964 | + 'npcm7xx_gpio-test', |
965 | 'npcm7xx_rng-test', | ||
1102 | 'npcm7xx_timer-test', | 966 | 'npcm7xx_timer-test', |
1103 | 'npcm7xx_watchdog_timer-test'] | 967 | 'npcm7xx_watchdog_timer-test'] |
1104 | qtests_arm = \ | ||
1105 | -- | 968 | -- |
1106 | 2.20.1 | 969 | 2.20.1 |
1107 | 970 | ||
1108 | 971 | 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 | The PWM module is part of NPCM7XX module. Each NPCM7XX module has two |
4 | set. | 4 | identical PWM modules. Each module contains 4 PWM entries. Each PWM has |
5 | two outputs: frequency and duty_cycle. Both are computed using inputs | ||
6 | from software side. | ||
5 | 7 | ||
6 | This implementation ignores the prescaler setting, and loads a new value | 8 | This module does not model detail pulse signals since it is expensive. |
7 | into RNGD every time RNGCS is read while the RNG is enabled and random | 9 | It also does not model interrupts and watchdogs that are dependant on |
8 | data is available. | 10 | the detail models. The interfaces for these are left in the module so |
11 | that anyone in need for these functionalities can implement on their | ||
12 | own. | ||
9 | 13 | ||
10 | A qtest featuring some simple randomness tests is included. | 14 | The user can read the duty cycle and frequency using qom-get command. |
11 | 15 | ||
16 | Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | 17 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
18 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
19 | Message-id: 20210108190945.949196-5-wuhaotsh@google.com | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 22 | --- |
17 | docs/system/arm/nuvoton.rst | 2 +- | 23 | docs/system/arm/nuvoton.rst | 2 +- |
18 | include/hw/arm/npcm7xx.h | 2 + | 24 | include/hw/arm/npcm7xx.h | 2 + |
19 | include/hw/misc/npcm7xx_rng.h | 34 ++++ | 25 | include/hw/misc/npcm7xx_pwm.h | 105 +++++++ |
20 | hw/arm/npcm7xx.c | 7 +- | 26 | hw/arm/npcm7xx.c | 26 +- |
21 | hw/misc/npcm7xx_rng.c | 180 +++++++++++++++++++++ | 27 | hw/misc/npcm7xx_pwm.c | 550 ++++++++++++++++++++++++++++++++++ |
22 | tests/qtest/npcm7xx_rng-test.c | 278 +++++++++++++++++++++++++++++++++ | 28 | hw/misc/meson.build | 1 + |
23 | hw/misc/meson.build | 1 + | 29 | hw/misc/trace-events | 6 + |
24 | hw/misc/trace-events | 4 + | 30 | 7 files changed, 689 insertions(+), 3 deletions(-) |
25 | tests/qtest/meson.build | 5 +- | 31 | create mode 100644 include/hw/misc/npcm7xx_pwm.h |
26 | 9 files changed, 510 insertions(+), 3 deletions(-) | 32 | create mode 100644 hw/misc/npcm7xx_pwm.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 | 33 | ||
31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | 34 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
32 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/docs/system/arm/nuvoton.rst | 36 | --- a/docs/system/arm/nuvoton.rst |
34 | +++ b/docs/system/arm/nuvoton.rst | 37 | +++ b/docs/system/arm/nuvoton.rst |
35 | @@ -XXX,XX +XXX,XX @@ Supported devices | 38 | @@ -XXX,XX +XXX,XX @@ Supported devices |
36 | * DDR4 memory controller (dummy interface indicating memory training is done) | 39 | * USB host (USBH) |
37 | * OTP controllers (no protection features) | 40 | * GPIO controller |
38 | * Flash Interface Unit (FIU; no protection features) | 41 | * Analog to Digital Converter (ADC) |
39 | + * Random Number Generator (RNG) | 42 | + * Pulse Width Modulation (PWM) |
40 | 43 | ||
41 | Missing devices | 44 | Missing devices |
42 | --------------- | 45 | --------------- |
43 | @@ -XXX,XX +XXX,XX @@ Missing devices | 46 | @@ -XXX,XX +XXX,XX @@ Missing devices |
44 | * Peripheral SPI controller (PSPI) | 47 | * Peripheral SPI controller (PSPI) |
45 | * Analog to Digital Converter (ADC) | ||
46 | * SD/MMC host | 48 | * SD/MMC host |
47 | - * Random Number Generator (RNG) | ||
48 | * PECI interface | 49 | * PECI interface |
49 | * Pulse Width Modulation (PWM) | 50 | - * Pulse Width Modulation (PWM) |
50 | * Tachometer | 51 | * Tachometer |
52 | * PCI and PCIe root complex and bridges | ||
53 | * VDM and MCTP support | ||
51 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | 54 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h |
52 | index XXXXXXX..XXXXXXX 100644 | 55 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/include/hw/arm/npcm7xx.h | 56 | --- a/include/hw/arm/npcm7xx.h |
54 | +++ b/include/hw/arm/npcm7xx.h | 57 | +++ b/include/hw/arm/npcm7xx.h |
55 | @@ -XXX,XX +XXX,XX @@ | 58 | @@ -XXX,XX +XXX,XX @@ |
56 | #include "hw/mem/npcm7xx_mc.h" | 59 | #include "hw/mem/npcm7xx_mc.h" |
57 | #include "hw/misc/npcm7xx_clk.h" | 60 | #include "hw/misc/npcm7xx_clk.h" |
58 | #include "hw/misc/npcm7xx_gcr.h" | 61 | #include "hw/misc/npcm7xx_gcr.h" |
59 | +#include "hw/misc/npcm7xx_rng.h" | 62 | +#include "hw/misc/npcm7xx_pwm.h" |
63 | #include "hw/misc/npcm7xx_rng.h" | ||
60 | #include "hw/nvram/npcm7xx_otp.h" | 64 | #include "hw/nvram/npcm7xx_otp.h" |
61 | #include "hw/timer/npcm7xx_timer.h" | 65 | #include "hw/timer/npcm7xx_timer.h" |
62 | #include "hw/ssi/npcm7xx_fiu.h" | ||
63 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | 66 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
67 | NPCM7xxCLKState clk; | ||
68 | NPCM7xxTimerCtrlState tim[3]; | ||
69 | NPCM7xxADCState adc; | ||
70 | + NPCM7xxPWMState pwm[2]; | ||
64 | NPCM7xxOTPState key_storage; | 71 | NPCM7xxOTPState key_storage; |
65 | NPCM7xxOTPState fuse_array; | 72 | NPCM7xxOTPState fuse_array; |
66 | NPCM7xxMCState mc; | 73 | NPCM7xxMCState mc; |
67 | + NPCM7xxRNGState rng; | 74 | diff --git a/include/hw/misc/npcm7xx_pwm.h b/include/hw/misc/npcm7xx_pwm.h |
68 | NPCM7xxFIUState fiu[2]; | ||
69 | } NPCM7xxState; | ||
70 | |||
71 | diff --git a/include/hw/misc/npcm7xx_rng.h b/include/hw/misc/npcm7xx_rng.h | ||
72 | new file mode 100644 | 75 | new file mode 100644 |
73 | index XXXXXXX..XXXXXXX | 76 | index XXXXXXX..XXXXXXX |
74 | --- /dev/null | 77 | --- /dev/null |
75 | +++ b/include/hw/misc/npcm7xx_rng.h | 78 | +++ b/include/hw/misc/npcm7xx_pwm.h |
76 | @@ -XXX,XX +XXX,XX @@ | 79 | @@ -XXX,XX +XXX,XX @@ |
77 | +/* | 80 | +/* |
78 | + * Nuvoton NPCM7xx Random Number Generator. | 81 | + * Nuvoton NPCM7xx PWM Module |
79 | + * | 82 | + * |
80 | + * Copyright 2020 Google LLC | 83 | + * Copyright 2020 Google LLC |
81 | + * | 84 | + * |
82 | + * This program is free software; you can redistribute it and/or modify it | 85 | + * 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 | 86 | + * 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 | 90 | + * 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 | 91 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
89 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 92 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90 | + * for more details. | 93 | + * for more details. |
91 | + */ | 94 | + */ |
92 | +#ifndef NPCM7XX_RNG_H | 95 | +#ifndef NPCM7XX_PWM_H |
93 | +#define NPCM7XX_RNG_H | 96 | +#define NPCM7XX_PWM_H |
94 | + | 97 | + |
98 | +#include "hw/clock.h" | ||
95 | +#include "hw/sysbus.h" | 99 | +#include "hw/sysbus.h" |
96 | + | 100 | +#include "hw/irq.h" |
97 | +typedef struct NPCM7xxRNGState { | 101 | + |
102 | +/* Each PWM module holds 4 PWM channels. */ | ||
103 | +#define NPCM7XX_PWM_PER_MODULE 4 | ||
104 | + | ||
105 | +/* | ||
106 | + * Number of registers in one pwm module. Don't change this without increasing | ||
107 | + * the version_id in vmstate. | ||
108 | + */ | ||
109 | +#define NPCM7XX_PWM_NR_REGS (0x54 / sizeof(uint32_t)) | ||
110 | + | ||
111 | +/* | ||
112 | + * The maximum duty values. Each duty unit represents 1/NPCM7XX_PWM_MAX_DUTY | ||
113 | + * cycles. For example, if NPCM7XX_PWM_MAX_DUTY=1,000,000 and a PWM has a duty | ||
114 | + * value of 100,000 the duty cycle for that PWM is 10%. | ||
115 | + */ | ||
116 | +#define NPCM7XX_PWM_MAX_DUTY 1000000 | ||
117 | + | ||
118 | +typedef struct NPCM7xxPWMState NPCM7xxPWMState; | ||
119 | + | ||
120 | +/** | ||
121 | + * struct NPCM7xxPWM - The state of a single PWM channel. | ||
122 | + * @module: The PWM module that contains this channel. | ||
123 | + * @irq: GIC interrupt line to fire on expiration if enabled. | ||
124 | + * @running: Whether this PWM channel is generating output. | ||
125 | + * @inverted: Whether this PWM channel is inverted. | ||
126 | + * @index: The index of this PWM channel. | ||
127 | + * @cnr: The counter register. | ||
128 | + * @cmr: The comparator register. | ||
129 | + * @pdr: The data register. | ||
130 | + * @pwdr: The watchdog register. | ||
131 | + * @freq: The frequency of this PWM channel. | ||
132 | + * @duty: The duty cycle of this PWM channel. One unit represents | ||
133 | + * 1/NPCM7XX_MAX_DUTY cycles. | ||
134 | + */ | ||
135 | +typedef struct NPCM7xxPWM { | ||
136 | + NPCM7xxPWMState *module; | ||
137 | + | ||
138 | + qemu_irq irq; | ||
139 | + | ||
140 | + bool running; | ||
141 | + bool inverted; | ||
142 | + | ||
143 | + uint8_t index; | ||
144 | + uint32_t cnr; | ||
145 | + uint32_t cmr; | ||
146 | + uint32_t pdr; | ||
147 | + uint32_t pwdr; | ||
148 | + | ||
149 | + uint32_t freq; | ||
150 | + uint32_t duty; | ||
151 | +} NPCM7xxPWM; | ||
152 | + | ||
153 | +/** | ||
154 | + * struct NPCM7xxPWMState - Pulse Width Modulation device state. | ||
155 | + * @parent: System bus device. | ||
156 | + * @iomem: Memory region through which registers are accessed. | ||
157 | + * @clock: The PWM clock. | ||
158 | + * @pwm: The PWM channels owned by this module. | ||
159 | + * @ppr: The prescaler register. | ||
160 | + * @csr: The clock selector register. | ||
161 | + * @pcr: The control register. | ||
162 | + * @pier: The interrupt enable register. | ||
163 | + * @piir: The interrupt indication register. | ||
164 | + */ | ||
165 | +struct NPCM7xxPWMState { | ||
98 | + SysBusDevice parent; | 166 | + SysBusDevice parent; |
99 | + | 167 | + |
100 | + MemoryRegion iomem; | 168 | + MemoryRegion iomem; |
101 | + | 169 | + |
102 | + uint8_t rngcs; | 170 | + Clock *clock; |
103 | + uint8_t rngd; | 171 | + NPCM7xxPWM pwm[NPCM7XX_PWM_PER_MODULE]; |
104 | + uint8_t rngmode; | 172 | + |
105 | +} NPCM7xxRNGState; | 173 | + uint32_t ppr; |
106 | + | 174 | + uint32_t csr; |
107 | +#define TYPE_NPCM7XX_RNG "npcm7xx-rng" | 175 | + uint32_t pcr; |
108 | +#define NPCM7XX_RNG(obj) OBJECT_CHECK(NPCM7xxRNGState, (obj), TYPE_NPCM7XX_RNG) | 176 | + uint32_t pier; |
109 | + | 177 | + uint32_t piir; |
110 | +#endif /* NPCM7XX_RNG_H */ | 178 | +}; |
179 | + | ||
180 | +#define TYPE_NPCM7XX_PWM "npcm7xx-pwm" | ||
181 | +#define NPCM7XX_PWM(obj) \ | ||
182 | + OBJECT_CHECK(NPCM7xxPWMState, (obj), TYPE_NPCM7XX_PWM) | ||
183 | + | ||
184 | +#endif /* NPCM7XX_PWM_H */ | ||
111 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | 185 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
112 | index XXXXXXX..XXXXXXX 100644 | 186 | index XXXXXXX..XXXXXXX 100644 |
113 | --- a/hw/arm/npcm7xx.c | 187 | --- a/hw/arm/npcm7xx.c |
114 | +++ b/hw/arm/npcm7xx.c | 188 | +++ b/hw/arm/npcm7xx.c |
115 | @@ -XXX,XX +XXX,XX @@ | 189 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
116 | #define NPCM7XX_GCR_BA (0xf0800000) | 190 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ |
117 | #define NPCM7XX_CLK_BA (0xf0801000) | 191 | NPCM7XX_EHCI_IRQ = 61, |
118 | #define NPCM7XX_MC_BA (0xf0824000) | 192 | NPCM7XX_OHCI_IRQ = 62, |
119 | +#define NPCM7XX_RNG_BA (0xf000b000) | 193 | + NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */ |
120 | 194 | + NPCM7XX_PWM1_IRQ, /* PWM module 1 */ | |
121 | /* Internal AHB SRAM */ | 195 | NPCM7XX_GPIO0_IRQ = 116, |
122 | #define NPCM7XX_RAM3_BA (0xc0008000) | 196 | NPCM7XX_GPIO1_IRQ, |
197 | NPCM7XX_GPIO2_IRQ, | ||
198 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = { | ||
199 | 0xb8000000, /* CS3 */ | ||
200 | }; | ||
201 | |||
202 | +/* Register base address for each PWM Module */ | ||
203 | +static const hwaddr npcm7xx_pwm_addr[] = { | ||
204 | + 0xf0103000, | ||
205 | + 0xf0104000, | ||
206 | +}; | ||
207 | + | ||
208 | static const struct { | ||
209 | hwaddr regs_addr; | ||
210 | uint32_t unconnected_pins; | ||
123 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | 211 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
124 | object_initialize_child(obj, "otp2", &s->fuse_array, | 212 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], |
125 | TYPE_NPCM7XX_FUSE_ARRAY); | 213 | TYPE_NPCM7XX_FIU); |
126 | object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); | 214 | } |
127 | + object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG); | 215 | + |
128 | 216 | + for (i = 0; i < ARRAY_SIZE(s->pwm); i++) { | |
129 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | 217 | + object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM); |
130 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | 218 | + } |
219 | } | ||
220 | |||
221 | static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
131 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 222 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
132 | serial_hd(i), DEVICE_LITTLE_ENDIAN); | 223 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, |
133 | } | 224 | npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); |
134 | 225 | ||
135 | + /* Random Number Generator. Cannot fail. */ | 226 | + /* PWM Modules. Cannot fail. */ |
136 | + sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | 227 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_pwm_addr) != ARRAY_SIZE(s->pwm)); |
137 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | 228 | + for (i = 0; i < ARRAY_SIZE(s->pwm); i++) { |
229 | + SysBusDevice *sbd = SYS_BUS_DEVICE(&s->pwm[i]); | ||
230 | + | ||
231 | + qdev_connect_clock_in(DEVICE(&s->pwm[i]), "clock", qdev_get_clock_out( | ||
232 | + DEVICE(&s->clk), "apb3-clock")); | ||
233 | + sysbus_realize(sbd, &error_abort); | ||
234 | + sysbus_mmio_map(sbd, 0, npcm7xx_pwm_addr[i]); | ||
235 | + sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i)); | ||
236 | + } | ||
138 | + | 237 | + |
139 | /* | 238 | /* |
140 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | 239 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
141 | * specified, but this is a programming error. | 240 | * specified, but this is a programming error. |
142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | 241 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
143 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); | 242 | create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB); |
144 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | 243 | create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB); |
145 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | 244 | create_unimplemented_device("npcm7xx.siox[2]", 0xf0102000, 4 * KiB); |
146 | - create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB); | 245 | - create_unimplemented_device("npcm7xx.pwm[0]", 0xf0103000, 4 * KiB); |
147 | create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | 246 | - create_unimplemented_device("npcm7xx.pwm[1]", 0xf0104000, 4 * KiB); |
148 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | 247 | create_unimplemented_device("npcm7xx.mft[0]", 0xf0180000, 4 * KiB); |
149 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | 248 | create_unimplemented_device("npcm7xx.mft[1]", 0xf0181000, 4 * KiB); |
150 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c | 249 | create_unimplemented_device("npcm7xx.mft[2]", 0xf0182000, 4 * KiB); |
250 | diff --git a/hw/misc/npcm7xx_pwm.c b/hw/misc/npcm7xx_pwm.c | ||
151 | new file mode 100644 | 251 | new file mode 100644 |
152 | index XXXXXXX..XXXXXXX | 252 | index XXXXXXX..XXXXXXX |
153 | --- /dev/null | 253 | --- /dev/null |
154 | +++ b/hw/misc/npcm7xx_rng.c | 254 | +++ b/hw/misc/npcm7xx_pwm.c |
155 | @@ -XXX,XX +XXX,XX @@ | 255 | @@ -XXX,XX +XXX,XX @@ |
156 | +/* | 256 | +/* |
157 | + * Nuvoton NPCM7xx Random Number Generator. | 257 | + * Nuvoton NPCM7xx PWM Module |
158 | + * | 258 | + * |
159 | + * Copyright 2020 Google LLC | 259 | + * Copyright 2020 Google LLC |
160 | + * | 260 | + * |
161 | + * This program is free software; you can redistribute it and/or modify it | 261 | + * 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 | 262 | + * under the terms of the GNU General Public License as published by the |
... | ... | ||
168 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 268 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
169 | + * for more details. | 269 | + * for more details. |
170 | + */ | 270 | + */ |
171 | + | 271 | + |
172 | +#include "qemu/osdep.h" | 272 | +#include "qemu/osdep.h" |
173 | + | 273 | +#include "hw/irq.h" |
174 | +#include "hw/misc/npcm7xx_rng.h" | 274 | +#include "hw/qdev-clock.h" |
275 | +#include "hw/qdev-properties.h" | ||
276 | +#include "hw/misc/npcm7xx_pwm.h" | ||
277 | +#include "hw/registerfields.h" | ||
175 | +#include "migration/vmstate.h" | 278 | +#include "migration/vmstate.h" |
176 | +#include "qemu/bitops.h" | 279 | +#include "qemu/bitops.h" |
177 | +#include "qemu/guest-random.h" | 280 | +#include "qemu/error-report.h" |
178 | +#include "qemu/log.h" | 281 | +#include "qemu/log.h" |
179 | +#include "qemu/module.h" | 282 | +#include "qemu/module.h" |
180 | +#include "qemu/units.h" | 283 | +#include "qemu/units.h" |
181 | + | ||
182 | +#include "trace.h" | 284 | +#include "trace.h" |
183 | + | 285 | + |
184 | +#define NPCM7XX_RNG_REGS_SIZE (4 * KiB) | 286 | +REG32(NPCM7XX_PWM_PPR, 0x00); |
185 | + | 287 | +REG32(NPCM7XX_PWM_CSR, 0x04); |
186 | +#define NPCM7XX_RNGCS (0x00) | 288 | +REG32(NPCM7XX_PWM_PCR, 0x08); |
187 | +#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4) | 289 | +REG32(NPCM7XX_PWM_CNR0, 0x0c); |
188 | +#define NPCM7XX_RNGCS_DVALID BIT(1) | 290 | +REG32(NPCM7XX_PWM_CMR0, 0x10); |
189 | +#define NPCM7XX_RNGCS_RNGE BIT(0) | 291 | +REG32(NPCM7XX_PWM_PDR0, 0x14); |
190 | + | 292 | +REG32(NPCM7XX_PWM_CNR1, 0x18); |
191 | +#define NPCM7XX_RNGD (0x04) | 293 | +REG32(NPCM7XX_PWM_CMR1, 0x1c); |
192 | +#define NPCM7XX_RNGMODE (0x08) | 294 | +REG32(NPCM7XX_PWM_PDR1, 0x20); |
193 | +#define NPCM7XX_RNGMODE_NORMAL (0x02) | 295 | +REG32(NPCM7XX_PWM_CNR2, 0x24); |
194 | + | 296 | +REG32(NPCM7XX_PWM_CMR2, 0x28); |
195 | +static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s) | 297 | +REG32(NPCM7XX_PWM_PDR2, 0x2c); |
196 | +{ | 298 | +REG32(NPCM7XX_PWM_CNR3, 0x30); |
197 | + return (s->rngcs & NPCM7XX_RNGCS_RNGE) && | 299 | +REG32(NPCM7XX_PWM_CMR3, 0x34); |
198 | + (s->rngmode == NPCM7XX_RNGMODE_NORMAL); | 300 | +REG32(NPCM7XX_PWM_PDR3, 0x38); |
199 | +} | 301 | +REG32(NPCM7XX_PWM_PIER, 0x3c); |
200 | + | 302 | +REG32(NPCM7XX_PWM_PIIR, 0x40); |
201 | +static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size) | 303 | +REG32(NPCM7XX_PWM_PWDR0, 0x44); |
202 | +{ | 304 | +REG32(NPCM7XX_PWM_PWDR1, 0x48); |
203 | + NPCM7xxRNGState *s = opaque; | 305 | +REG32(NPCM7XX_PWM_PWDR2, 0x4c); |
306 | +REG32(NPCM7XX_PWM_PWDR3, 0x50); | ||
307 | + | ||
308 | +/* Register field definitions. */ | ||
309 | +#define NPCM7XX_PPR(rv, index) extract32((rv), npcm7xx_ppr_base[index], 8) | ||
310 | +#define NPCM7XX_CSR(rv, index) extract32((rv), npcm7xx_csr_base[index], 3) | ||
311 | +#define NPCM7XX_CH(rv, index) extract32((rv), npcm7xx_ch_base[index], 4) | ||
312 | +#define NPCM7XX_CH_EN BIT(0) | ||
313 | +#define NPCM7XX_CH_INV BIT(2) | ||
314 | +#define NPCM7XX_CH_MOD BIT(3) | ||
315 | + | ||
316 | +/* Offset of each PWM channel's prescaler in the PPR register. */ | ||
317 | +static const int npcm7xx_ppr_base[] = { 0, 0, 8, 8 }; | ||
318 | +/* Offset of each PWM channel's clock selector in the CSR register. */ | ||
319 | +static const int npcm7xx_csr_base[] = { 0, 4, 8, 12 }; | ||
320 | +/* Offset of each PWM channel's control variable in the PCR register. */ | ||
321 | +static const int npcm7xx_ch_base[] = { 0, 8, 12, 16 }; | ||
322 | + | ||
323 | +static uint32_t npcm7xx_pwm_calculate_freq(NPCM7xxPWM *p) | ||
324 | +{ | ||
325 | + uint32_t ppr; | ||
326 | + uint32_t csr; | ||
327 | + uint32_t freq; | ||
328 | + | ||
329 | + if (!p->running) { | ||
330 | + return 0; | ||
331 | + } | ||
332 | + | ||
333 | + csr = NPCM7XX_CSR(p->module->csr, p->index); | ||
334 | + ppr = NPCM7XX_PPR(p->module->ppr, p->index); | ||
335 | + freq = clock_get_hz(p->module->clock); | ||
336 | + freq /= ppr + 1; | ||
337 | + /* csr can only be 0~4 */ | ||
338 | + if (csr > 4) { | ||
339 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
340 | + "%s: invalid csr value %u\n", | ||
341 | + __func__, csr); | ||
342 | + csr = 4; | ||
343 | + } | ||
344 | + /* freq won't be changed if csr == 4. */ | ||
345 | + if (csr < 4) { | ||
346 | + freq >>= csr + 1; | ||
347 | + } | ||
348 | + | ||
349 | + return freq / (p->cnr + 1); | ||
350 | +} | ||
351 | + | ||
352 | +static uint32_t npcm7xx_pwm_calculate_duty(NPCM7xxPWM *p) | ||
353 | +{ | ||
354 | + uint64_t duty; | ||
355 | + | ||
356 | + if (p->running) { | ||
357 | + if (p->cnr == 0) { | ||
358 | + duty = 0; | ||
359 | + } else if (p->cmr >= p->cnr) { | ||
360 | + duty = NPCM7XX_PWM_MAX_DUTY; | ||
361 | + } else { | ||
362 | + duty = NPCM7XX_PWM_MAX_DUTY * (p->cmr + 1) / (p->cnr + 1); | ||
363 | + } | ||
364 | + } else { | ||
365 | + duty = 0; | ||
366 | + } | ||
367 | + | ||
368 | + if (p->inverted) { | ||
369 | + duty = NPCM7XX_PWM_MAX_DUTY - duty; | ||
370 | + } | ||
371 | + | ||
372 | + return duty; | ||
373 | +} | ||
374 | + | ||
375 | +static void npcm7xx_pwm_update_freq(NPCM7xxPWM *p) | ||
376 | +{ | ||
377 | + uint32_t freq = npcm7xx_pwm_calculate_freq(p); | ||
378 | + | ||
379 | + if (freq != p->freq) { | ||
380 | + trace_npcm7xx_pwm_update_freq(DEVICE(p->module)->canonical_path, | ||
381 | + p->index, p->freq, freq); | ||
382 | + p->freq = freq; | ||
383 | + } | ||
384 | +} | ||
385 | + | ||
386 | +static void npcm7xx_pwm_update_duty(NPCM7xxPWM *p) | ||
387 | +{ | ||
388 | + uint32_t duty = npcm7xx_pwm_calculate_duty(p); | ||
389 | + | ||
390 | + if (duty != p->duty) { | ||
391 | + trace_npcm7xx_pwm_update_duty(DEVICE(p->module)->canonical_path, | ||
392 | + p->index, p->duty, duty); | ||
393 | + p->duty = duty; | ||
394 | + } | ||
395 | +} | ||
396 | + | ||
397 | +static void npcm7xx_pwm_update_output(NPCM7xxPWM *p) | ||
398 | +{ | ||
399 | + npcm7xx_pwm_update_freq(p); | ||
400 | + npcm7xx_pwm_update_duty(p); | ||
401 | +} | ||
402 | + | ||
403 | +static void npcm7xx_pwm_write_ppr(NPCM7xxPWMState *s, uint32_t new_ppr) | ||
404 | +{ | ||
405 | + int i; | ||
406 | + uint32_t old_ppr = s->ppr; | ||
407 | + | ||
408 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_ppr_base) != NPCM7XX_PWM_PER_MODULE); | ||
409 | + s->ppr = new_ppr; | ||
410 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) { | ||
411 | + if (NPCM7XX_PPR(old_ppr, i) != NPCM7XX_PPR(new_ppr, i)) { | ||
412 | + npcm7xx_pwm_update_freq(&s->pwm[i]); | ||
413 | + } | ||
414 | + } | ||
415 | +} | ||
416 | + | ||
417 | +static void npcm7xx_pwm_write_csr(NPCM7xxPWMState *s, uint32_t new_csr) | ||
418 | +{ | ||
419 | + int i; | ||
420 | + uint32_t old_csr = s->csr; | ||
421 | + | ||
422 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_csr_base) != NPCM7XX_PWM_PER_MODULE); | ||
423 | + s->csr = new_csr; | ||
424 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) { | ||
425 | + if (NPCM7XX_CSR(old_csr, i) != NPCM7XX_CSR(new_csr, i)) { | ||
426 | + npcm7xx_pwm_update_freq(&s->pwm[i]); | ||
427 | + } | ||
428 | + } | ||
429 | +} | ||
430 | + | ||
431 | +static void npcm7xx_pwm_write_pcr(NPCM7xxPWMState *s, uint32_t new_pcr) | ||
432 | +{ | ||
433 | + int i; | ||
434 | + bool inverted; | ||
435 | + uint32_t pcr; | ||
436 | + NPCM7xxPWM *p; | ||
437 | + | ||
438 | + s->pcr = new_pcr; | ||
439 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_ch_base) != NPCM7XX_PWM_PER_MODULE); | ||
440 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) { | ||
441 | + p = &s->pwm[i]; | ||
442 | + pcr = NPCM7XX_CH(new_pcr, i); | ||
443 | + inverted = pcr & NPCM7XX_CH_INV; | ||
444 | + | ||
445 | + /* | ||
446 | + * We only run a PWM channel with toggle mode. Single-shot mode does not | ||
447 | + * generate frequency and duty-cycle values. | ||
448 | + */ | ||
449 | + if ((pcr & NPCM7XX_CH_EN) && (pcr & NPCM7XX_CH_MOD)) { | ||
450 | + if (p->running) { | ||
451 | + /* Re-run this PWM channel if inverted changed. */ | ||
452 | + if (p->inverted ^ inverted) { | ||
453 | + p->inverted = inverted; | ||
454 | + npcm7xx_pwm_update_duty(p); | ||
455 | + } | ||
456 | + } else { | ||
457 | + /* Run this PWM channel. */ | ||
458 | + p->running = true; | ||
459 | + p->inverted = inverted; | ||
460 | + npcm7xx_pwm_update_output(p); | ||
461 | + } | ||
462 | + } else { | ||
463 | + /* Clear this PWM channel. */ | ||
464 | + p->running = false; | ||
465 | + p->inverted = inverted; | ||
466 | + npcm7xx_pwm_update_output(p); | ||
467 | + } | ||
468 | + } | ||
469 | + | ||
470 | +} | ||
471 | + | ||
472 | +static hwaddr npcm7xx_cnr_index(hwaddr offset) | ||
473 | +{ | ||
474 | + switch (offset) { | ||
475 | + case A_NPCM7XX_PWM_CNR0: | ||
476 | + return 0; | ||
477 | + case A_NPCM7XX_PWM_CNR1: | ||
478 | + return 1; | ||
479 | + case A_NPCM7XX_PWM_CNR2: | ||
480 | + return 2; | ||
481 | + case A_NPCM7XX_PWM_CNR3: | ||
482 | + return 3; | ||
483 | + default: | ||
484 | + g_assert_not_reached(); | ||
485 | + } | ||
486 | +} | ||
487 | + | ||
488 | +static hwaddr npcm7xx_cmr_index(hwaddr offset) | ||
489 | +{ | ||
490 | + switch (offset) { | ||
491 | + case A_NPCM7XX_PWM_CMR0: | ||
492 | + return 0; | ||
493 | + case A_NPCM7XX_PWM_CMR1: | ||
494 | + return 1; | ||
495 | + case A_NPCM7XX_PWM_CMR2: | ||
496 | + return 2; | ||
497 | + case A_NPCM7XX_PWM_CMR3: | ||
498 | + return 3; | ||
499 | + default: | ||
500 | + g_assert_not_reached(); | ||
501 | + } | ||
502 | +} | ||
503 | + | ||
504 | +static hwaddr npcm7xx_pdr_index(hwaddr offset) | ||
505 | +{ | ||
506 | + switch (offset) { | ||
507 | + case A_NPCM7XX_PWM_PDR0: | ||
508 | + return 0; | ||
509 | + case A_NPCM7XX_PWM_PDR1: | ||
510 | + return 1; | ||
511 | + case A_NPCM7XX_PWM_PDR2: | ||
512 | + return 2; | ||
513 | + case A_NPCM7XX_PWM_PDR3: | ||
514 | + return 3; | ||
515 | + default: | ||
516 | + g_assert_not_reached(); | ||
517 | + } | ||
518 | +} | ||
519 | + | ||
520 | +static hwaddr npcm7xx_pwdr_index(hwaddr offset) | ||
521 | +{ | ||
522 | + switch (offset) { | ||
523 | + case A_NPCM7XX_PWM_PWDR0: | ||
524 | + return 0; | ||
525 | + case A_NPCM7XX_PWM_PWDR1: | ||
526 | + return 1; | ||
527 | + case A_NPCM7XX_PWM_PWDR2: | ||
528 | + return 2; | ||
529 | + case A_NPCM7XX_PWM_PWDR3: | ||
530 | + return 3; | ||
531 | + default: | ||
532 | + g_assert_not_reached(); | ||
533 | + } | ||
534 | +} | ||
535 | + | ||
536 | +static uint64_t npcm7xx_pwm_read(void *opaque, hwaddr offset, unsigned size) | ||
537 | +{ | ||
538 | + NPCM7xxPWMState *s = opaque; | ||
204 | + uint64_t value = 0; | 539 | + uint64_t value = 0; |
205 | + | 540 | + |
206 | + switch (offset) { | 541 | + switch (offset) { |
207 | + case NPCM7XX_RNGCS: | 542 | + case A_NPCM7XX_PWM_CNR0: |
208 | + /* | 543 | + case A_NPCM7XX_PWM_CNR1: |
209 | + * If the RNG is enabled, but we don't have any valid random data, try | 544 | + case A_NPCM7XX_PWM_CNR2: |
210 | + * obtaining some and update the DVALID bit accordingly. | 545 | + case A_NPCM7XX_PWM_CNR3: |
211 | + */ | 546 | + value = s->pwm[npcm7xx_cnr_index(offset)].cnr; |
212 | + if (!npcm7xx_rng_is_enabled(s)) { | 547 | + break; |
213 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | 548 | + |
214 | + } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) { | 549 | + case A_NPCM7XX_PWM_CMR0: |
215 | + uint8_t byte = 0; | 550 | + case A_NPCM7XX_PWM_CMR1: |
216 | + | 551 | + case A_NPCM7XX_PWM_CMR2: |
217 | + if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) { | 552 | + case A_NPCM7XX_PWM_CMR3: |
218 | + s->rngd = byte; | 553 | + value = s->pwm[npcm7xx_cmr_index(offset)].cmr; |
219 | + s->rngcs |= NPCM7XX_RNGCS_DVALID; | 554 | + break; |
220 | + } | 555 | + |
221 | + } | 556 | + case A_NPCM7XX_PWM_PDR0: |
222 | + value = s->rngcs; | 557 | + case A_NPCM7XX_PWM_PDR1: |
223 | + break; | 558 | + case A_NPCM7XX_PWM_PDR2: |
224 | + case NPCM7XX_RNGD: | 559 | + case A_NPCM7XX_PWM_PDR3: |
225 | + if (npcm7xx_rng_is_enabled(s) && s->rngcs & NPCM7XX_RNGCS_DVALID) { | 560 | + value = s->pwm[npcm7xx_pdr_index(offset)].pdr; |
226 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | 561 | + break; |
227 | + value = s->rngd; | 562 | + |
228 | + s->rngd = 0; | 563 | + case A_NPCM7XX_PWM_PWDR0: |
229 | + } | 564 | + case A_NPCM7XX_PWM_PWDR1: |
230 | + break; | 565 | + case A_NPCM7XX_PWM_PWDR2: |
231 | + case NPCM7XX_RNGMODE: | 566 | + case A_NPCM7XX_PWM_PWDR3: |
232 | + value = s->rngmode; | 567 | + value = s->pwm[npcm7xx_pwdr_index(offset)].pwdr; |
568 | + break; | ||
569 | + | ||
570 | + case A_NPCM7XX_PWM_PPR: | ||
571 | + value = s->ppr; | ||
572 | + break; | ||
573 | + | ||
574 | + case A_NPCM7XX_PWM_CSR: | ||
575 | + value = s->csr; | ||
576 | + break; | ||
577 | + | ||
578 | + case A_NPCM7XX_PWM_PCR: | ||
579 | + value = s->pcr; | ||
580 | + break; | ||
581 | + | ||
582 | + case A_NPCM7XX_PWM_PIER: | ||
583 | + value = s->pier; | ||
584 | + break; | ||
585 | + | ||
586 | + case A_NPCM7XX_PWM_PIIR: | ||
587 | + value = s->piir; | ||
233 | + break; | 588 | + break; |
234 | + | 589 | + |
235 | + default: | 590 | + default: |
236 | + qemu_log_mask(LOG_GUEST_ERROR, | 591 | + qemu_log_mask(LOG_GUEST_ERROR, |
237 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | 592 | + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", |
238 | + DEVICE(s)->canonical_path, offset); | 593 | + __func__, offset); |
239 | + break; | 594 | + break; |
240 | + } | 595 | + } |
241 | + | 596 | + |
242 | + trace_npcm7xx_rng_read(offset, value, size); | 597 | + trace_npcm7xx_pwm_read(DEVICE(s)->canonical_path, offset, value); |
243 | + | ||
244 | + return value; | 598 | + return value; |
245 | +} | 599 | +} |
246 | + | 600 | + |
247 | +static void npcm7xx_rng_write(void *opaque, hwaddr offset, uint64_t value, | 601 | +static void npcm7xx_pwm_write(void *opaque, hwaddr offset, |
248 | + unsigned size) | 602 | + uint64_t v, unsigned size) |
249 | +{ | 603 | +{ |
250 | + NPCM7xxRNGState *s = opaque; | 604 | + NPCM7xxPWMState *s = opaque; |
251 | + | 605 | + NPCM7xxPWM *p; |
252 | + trace_npcm7xx_rng_write(offset, value, size); | 606 | + uint32_t value = v; |
253 | + | 607 | + |
608 | + trace_npcm7xx_pwm_write(DEVICE(s)->canonical_path, offset, value); | ||
254 | + switch (offset) { | 609 | + switch (offset) { |
255 | + case NPCM7XX_RNGCS: | 610 | + case A_NPCM7XX_PWM_CNR0: |
256 | + s->rngcs &= NPCM7XX_RNGCS_DVALID; | 611 | + case A_NPCM7XX_PWM_CNR1: |
257 | + s->rngcs |= value & ~NPCM7XX_RNGCS_DVALID; | 612 | + case A_NPCM7XX_PWM_CNR2: |
258 | + break; | 613 | + case A_NPCM7XX_PWM_CNR3: |
259 | + case NPCM7XX_RNGD: | 614 | + p = &s->pwm[npcm7xx_cnr_index(offset)]; |
615 | + p->cnr = value; | ||
616 | + npcm7xx_pwm_update_output(p); | ||
617 | + break; | ||
618 | + | ||
619 | + case A_NPCM7XX_PWM_CMR0: | ||
620 | + case A_NPCM7XX_PWM_CMR1: | ||
621 | + case A_NPCM7XX_PWM_CMR2: | ||
622 | + case A_NPCM7XX_PWM_CMR3: | ||
623 | + p = &s->pwm[npcm7xx_cmr_index(offset)]; | ||
624 | + p->cmr = value; | ||
625 | + npcm7xx_pwm_update_output(p); | ||
626 | + break; | ||
627 | + | ||
628 | + case A_NPCM7XX_PWM_PDR0: | ||
629 | + case A_NPCM7XX_PWM_PDR1: | ||
630 | + case A_NPCM7XX_PWM_PDR2: | ||
631 | + case A_NPCM7XX_PWM_PDR3: | ||
260 | + qemu_log_mask(LOG_GUEST_ERROR, | 632 | + qemu_log_mask(LOG_GUEST_ERROR, |
261 | + "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n", | 633 | + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n", |
262 | + DEVICE(s)->canonical_path, offset); | 634 | + __func__, offset); |
263 | + break; | 635 | + break; |
264 | + case NPCM7XX_RNGMODE: | 636 | + |
265 | + s->rngmode = value; | 637 | + case A_NPCM7XX_PWM_PWDR0: |
266 | + break; | 638 | + case A_NPCM7XX_PWM_PWDR1: |
639 | + case A_NPCM7XX_PWM_PWDR2: | ||
640 | + case A_NPCM7XX_PWM_PWDR3: | ||
641 | + qemu_log_mask(LOG_UNIMP, | ||
642 | + "%s: register @ 0x%04" HWADDR_PRIx " is not implemented\n", | ||
643 | + __func__, offset); | ||
644 | + break; | ||
645 | + | ||
646 | + case A_NPCM7XX_PWM_PPR: | ||
647 | + npcm7xx_pwm_write_ppr(s, value); | ||
648 | + break; | ||
649 | + | ||
650 | + case A_NPCM7XX_PWM_CSR: | ||
651 | + npcm7xx_pwm_write_csr(s, value); | ||
652 | + break; | ||
653 | + | ||
654 | + case A_NPCM7XX_PWM_PCR: | ||
655 | + npcm7xx_pwm_write_pcr(s, value); | ||
656 | + break; | ||
657 | + | ||
658 | + case A_NPCM7XX_PWM_PIER: | ||
659 | + qemu_log_mask(LOG_UNIMP, | ||
660 | + "%s: register @ 0x%04" HWADDR_PRIx " is not implemented\n", | ||
661 | + __func__, offset); | ||
662 | + break; | ||
663 | + | ||
664 | + case A_NPCM7XX_PWM_PIIR: | ||
665 | + qemu_log_mask(LOG_UNIMP, | ||
666 | + "%s: register @ 0x%04" HWADDR_PRIx " is not implemented\n", | ||
667 | + __func__, offset); | ||
668 | + break; | ||
669 | + | ||
267 | + default: | 670 | + default: |
268 | + qemu_log_mask(LOG_GUEST_ERROR, | 671 | + qemu_log_mask(LOG_GUEST_ERROR, |
269 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | 672 | + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", |
270 | + DEVICE(s)->canonical_path, offset); | 673 | + __func__, offset); |
271 | + break; | 674 | + break; |
272 | + } | 675 | + } |
273 | +} | 676 | +} |
274 | + | 677 | + |
275 | +static const MemoryRegionOps npcm7xx_rng_ops = { | 678 | +static const struct MemoryRegionOps npcm7xx_pwm_ops = { |
276 | + .read = npcm7xx_rng_read, | 679 | + .read = npcm7xx_pwm_read, |
277 | + .write = npcm7xx_rng_write, | 680 | + .write = npcm7xx_pwm_write, |
278 | + .endianness = DEVICE_LITTLE_ENDIAN, | 681 | + .endianness = DEVICE_LITTLE_ENDIAN, |
279 | + .valid = { | 682 | + .valid = { |
280 | + .min_access_size = 1, | 683 | + .min_access_size = 4, |
281 | + .max_access_size = 4, | 684 | + .max_access_size = 4, |
282 | + .unaligned = false, | 685 | + .unaligned = false, |
283 | + }, | 686 | + }, |
284 | +}; | 687 | +}; |
285 | + | 688 | + |
286 | +static void npcm7xx_rng_enter_reset(Object *obj, ResetType type) | 689 | +static void npcm7xx_pwm_enter_reset(Object *obj, ResetType type) |
287 | +{ | 690 | +{ |
288 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | 691 | + NPCM7xxPWMState *s = NPCM7XX_PWM(obj); |
289 | + | 692 | + int i; |
290 | + s->rngcs = 0; | 693 | + |
291 | + s->rngd = 0; | 694 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; i++) { |
292 | + s->rngmode = 0; | 695 | + NPCM7xxPWM *p = &s->pwm[i]; |
293 | +} | 696 | + |
294 | + | 697 | + p->cnr = 0x00000000; |
295 | +static void npcm7xx_rng_init(Object *obj) | 698 | + p->cmr = 0x00000000; |
296 | +{ | 699 | + p->pdr = 0x00000000; |
297 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | 700 | + p->pwdr = 0x00000000; |
298 | + | 701 | + } |
299 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs", | 702 | + |
300 | + NPCM7XX_RNG_REGS_SIZE); | 703 | + s->ppr = 0x00000000; |
301 | + sysbus_init_mmio(&s->parent, &s->iomem); | 704 | + s->csr = 0x00000000; |
302 | +} | 705 | + s->pcr = 0x00000000; |
303 | + | 706 | + s->pier = 0x00000000; |
304 | +static const VMStateDescription vmstate_npcm7xx_rng = { | 707 | + s->piir = 0x00000000; |
305 | + .name = "npcm7xx-rng", | 708 | +} |
709 | + | ||
710 | +static void npcm7xx_pwm_hold_reset(Object *obj) | ||
711 | +{ | ||
712 | + NPCM7xxPWMState *s = NPCM7XX_PWM(obj); | ||
713 | + int i; | ||
714 | + | ||
715 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; i++) { | ||
716 | + qemu_irq_lower(s->pwm[i].irq); | ||
717 | + } | ||
718 | +} | ||
719 | + | ||
720 | +static void npcm7xx_pwm_init(Object *obj) | ||
721 | +{ | ||
722 | + NPCM7xxPWMState *s = NPCM7XX_PWM(obj); | ||
723 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
724 | + int i; | ||
725 | + | ||
726 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; i++) { | ||
727 | + NPCM7xxPWM *p = &s->pwm[i]; | ||
728 | + p->module = s; | ||
729 | + p->index = i; | ||
730 | + sysbus_init_irq(sbd, &p->irq); | ||
731 | + } | ||
732 | + | ||
733 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_pwm_ops, s, | ||
734 | + TYPE_NPCM7XX_PWM, 4 * KiB); | ||
735 | + sysbus_init_mmio(sbd, &s->iomem); | ||
736 | + s->clock = qdev_init_clock_in(DEVICE(s), "clock", NULL, NULL); | ||
737 | + | ||
738 | + for (i = 0; i < NPCM7XX_PWM_PER_MODULE; ++i) { | ||
739 | + object_property_add_uint32_ptr(obj, "freq[*]", | ||
740 | + &s->pwm[i].freq, OBJ_PROP_FLAG_READ); | ||
741 | + object_property_add_uint32_ptr(obj, "duty[*]", | ||
742 | + &s->pwm[i].duty, OBJ_PROP_FLAG_READ); | ||
743 | + } | ||
744 | +} | ||
745 | + | ||
746 | +static const VMStateDescription vmstate_npcm7xx_pwm = { | ||
747 | + .name = "npcm7xx-pwm", | ||
306 | + .version_id = 0, | 748 | + .version_id = 0, |
307 | + .minimum_version_id = 0, | 749 | + .minimum_version_id = 0, |
308 | + .fields = (VMStateField[]) { | 750 | + .fields = (VMStateField[]) { |
309 | + VMSTATE_UINT8(rngcs, NPCM7xxRNGState), | 751 | + VMSTATE_BOOL(running, NPCM7xxPWM), |
310 | + VMSTATE_UINT8(rngd, NPCM7xxRNGState), | 752 | + VMSTATE_BOOL(inverted, NPCM7xxPWM), |
311 | + VMSTATE_UINT8(rngmode, NPCM7xxRNGState), | 753 | + VMSTATE_UINT8(index, NPCM7xxPWM), |
754 | + VMSTATE_UINT32(cnr, NPCM7xxPWM), | ||
755 | + VMSTATE_UINT32(cmr, NPCM7xxPWM), | ||
756 | + VMSTATE_UINT32(pdr, NPCM7xxPWM), | ||
757 | + VMSTATE_UINT32(pwdr, NPCM7xxPWM), | ||
758 | + VMSTATE_UINT32(freq, NPCM7xxPWM), | ||
759 | + VMSTATE_UINT32(duty, NPCM7xxPWM), | ||
312 | + VMSTATE_END_OF_LIST(), | 760 | + VMSTATE_END_OF_LIST(), |
313 | + }, | 761 | + }, |
314 | +}; | 762 | +}; |
315 | + | 763 | + |
316 | +static void npcm7xx_rng_class_init(ObjectClass *klass, void *data) | 764 | +static const VMStateDescription vmstate_npcm7xx_pwm_module = { |
765 | + .name = "npcm7xx-pwm-module", | ||
766 | + .version_id = 0, | ||
767 | + .minimum_version_id = 0, | ||
768 | + .fields = (VMStateField[]) { | ||
769 | + VMSTATE_CLOCK(clock, NPCM7xxPWMState), | ||
770 | + VMSTATE_STRUCT_ARRAY(pwm, NPCM7xxPWMState, | ||
771 | + NPCM7XX_PWM_PER_MODULE, 0, vmstate_npcm7xx_pwm, | ||
772 | + NPCM7xxPWM), | ||
773 | + VMSTATE_UINT32(ppr, NPCM7xxPWMState), | ||
774 | + VMSTATE_UINT32(csr, NPCM7xxPWMState), | ||
775 | + VMSTATE_UINT32(pcr, NPCM7xxPWMState), | ||
776 | + VMSTATE_UINT32(pier, NPCM7xxPWMState), | ||
777 | + VMSTATE_UINT32(piir, NPCM7xxPWMState), | ||
778 | + VMSTATE_END_OF_LIST(), | ||
779 | + }, | ||
780 | +}; | ||
781 | + | ||
782 | +static void npcm7xx_pwm_class_init(ObjectClass *klass, void *data) | ||
317 | +{ | 783 | +{ |
318 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | 784 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
319 | + DeviceClass *dc = DEVICE_CLASS(klass); | 785 | + DeviceClass *dc = DEVICE_CLASS(klass); |
320 | + | 786 | + |
321 | + dc->desc = "NPCM7xx Random Number Generator"; | 787 | + dc->desc = "NPCM7xx PWM Controller"; |
322 | + dc->vmsd = &vmstate_npcm7xx_rng; | 788 | + dc->vmsd = &vmstate_npcm7xx_pwm_module; |
323 | + rc->phases.enter = npcm7xx_rng_enter_reset; | 789 | + rc->phases.enter = npcm7xx_pwm_enter_reset; |
324 | +} | 790 | + rc->phases.hold = npcm7xx_pwm_hold_reset; |
325 | + | 791 | +} |
326 | +static const TypeInfo npcm7xx_rng_types[] = { | 792 | + |
327 | + { | 793 | +static const TypeInfo npcm7xx_pwm_info = { |
328 | + .name = TYPE_NPCM7XX_RNG, | 794 | + .name = TYPE_NPCM7XX_PWM, |
329 | + .parent = TYPE_SYS_BUS_DEVICE, | 795 | + .parent = TYPE_SYS_BUS_DEVICE, |
330 | + .instance_size = sizeof(NPCM7xxRNGState), | 796 | + .instance_size = sizeof(NPCM7xxPWMState), |
331 | + .class_init = npcm7xx_rng_class_init, | 797 | + .class_init = npcm7xx_pwm_class_init, |
332 | + .instance_init = npcm7xx_rng_init, | 798 | + .instance_init = npcm7xx_pwm_init, |
333 | + }, | ||
334 | +}; | 799 | +}; |
335 | +DEFINE_TYPES(npcm7xx_rng_types); | 800 | + |
336 | diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c | 801 | +static void npcm7xx_pwm_register_type(void) |
337 | new file mode 100644 | 802 | +{ |
338 | index XXXXXXX..XXXXXXX | 803 | + type_register_static(&npcm7xx_pwm_info); |
339 | --- /dev/null | 804 | +} |
340 | +++ b/tests/qtest/npcm7xx_rng-test.c | 805 | +type_init(npcm7xx_pwm_register_type); |
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 | 806 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build |
621 | index XXXXXXX..XXXXXXX 100644 | 807 | index XXXXXXX..XXXXXXX 100644 |
622 | --- a/hw/misc/meson.build | 808 | --- a/hw/misc/meson.build |
623 | +++ b/hw/misc/meson.build | 809 | +++ b/hw/misc/meson.build |
624 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) | 810 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) |
625 | softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( | 811 | softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( |
626 | 'npcm7xx_clk.c', | 812 | 'npcm7xx_clk.c', |
627 | 'npcm7xx_gcr.c', | 813 | 'npcm7xx_gcr.c', |
628 | + 'npcm7xx_rng.c', | 814 | + 'npcm7xx_pwm.c', |
815 | 'npcm7xx_rng.c', | ||
629 | )) | 816 | )) |
630 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( | 817 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( |
631 | 'omap_clk.c', | ||
632 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 818 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events |
633 | index XXXXXXX..XXXXXXX 100644 | 819 | index XXXXXXX..XXXXXXX 100644 |
634 | --- a/hw/misc/trace-events | 820 | --- a/hw/misc/trace-events |
635 | +++ b/hw/misc/trace-events | 821 | +++ b/hw/misc/trace-events |
636 | @@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu | 822 | @@ -XXX,XX +XXX,XX @@ npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu |
637 | npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | 823 | npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" |
638 | npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | 824 | npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" |
639 | 825 | ||
640 | +# npcm7xx_rng.c | 826 | +# npcm7xx_pwm.c |
641 | +npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | 827 | +npcm7xx_pwm_read(const char *id, uint64_t offset, uint32_t value) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 |
642 | +npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | 828 | +npcm7xx_pwm_write(const char *id, uint64_t offset, uint32_t value) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 |
829 | +npcm7xx_pwm_update_freq(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Freq: old_freq: %u, new_freq: %u" | ||
830 | +npcm7xx_pwm_update_duty(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Duty: old_duty: %u, new_duty: %u" | ||
643 | + | 831 | + |
644 | # stm32f4xx_syscfg.c | 832 | # stm32f4xx_syscfg.c |
645 | stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" | 833 | stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" |
646 | stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d" | 834 | stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d" |
647 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
648 | index XXXXXXX..XXXXXXX 100644 | ||
649 | --- a/tests/qtest/meson.build | ||
650 | +++ b/tests/qtest/meson.build | ||
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 | -- | 835 | -- |
664 | 2.20.1 | 836 | 2.20.1 |
665 | 837 | ||
666 | 838 | diff view generated by jsdifflib |
1 | From: Hao Wu <wuhaotsh@google.com> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | The watchdog is part of NPCM7XX's timer module. Its behavior is | 3 | We add a qtest for the PWM in the previous patch. It proves it works as |
4 | controlled by the WTCR register in the timer. | 4 | expected. |
5 | 5 | ||
6 | When enabled, the watchdog issues an interrupt signal after a pre-set | 6 | Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com> |
7 | amount of cycles, and issues a reset signal shortly after that. | ||
8 | |||
9 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | 7 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
10 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | 8 | 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> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | [PMM: deleted blank line at end of npcm_watchdog_timer-test.c] | 10 | Message-id: 20210108190945.949196-6-wuhaotsh@google.com |
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 12 | --- |
16 | include/hw/misc/npcm7xx_clk.h | 2 + | 13 | tests/qtest/npcm7xx_pwm-test.c | 490 +++++++++++++++++++++++++++++++++ |
17 | include/hw/timer/npcm7xx_timer.h | 48 +++- | 14 | tests/qtest/meson.build | 1 + |
18 | hw/arm/npcm7xx.c | 12 + | 15 | 2 files changed, 491 insertions(+) |
19 | hw/misc/npcm7xx_clk.c | 28 ++ | 16 | create mode 100644 tests/qtest/npcm7xx_pwm-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 | 17 | ||
27 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h | 18 | diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-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 | 19 | new file mode 100644 |
657 | index XXXXXXX..XXXXXXX | 20 | index XXXXXXX..XXXXXXX |
658 | --- /dev/null | 21 | --- /dev/null |
659 | +++ b/tests/qtest/npcm7xx_watchdog_timer-test.c | 22 | +++ b/tests/qtest/npcm7xx_pwm-test.c |
660 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ |
661 | +/* | 24 | +/* |
662 | + * QTests for Nuvoton NPCM7xx Timer Watchdog Modules. | 25 | + * QTests for Nuvoton NPCM7xx PWM Modules. |
663 | + * | 26 | + * |
664 | + * Copyright 2020 Google LLC | 27 | + * Copyright 2020 Google LLC |
665 | + * | 28 | + * |
666 | + * This program is free software; you can redistribute it and/or modify it | 29 | + * 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 | 30 | + * 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 | 36 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
674 | + * for more details. | 37 | + * for more details. |
675 | + */ | 38 | + */ |
676 | + | 39 | + |
677 | +#include "qemu/osdep.h" | 40 | +#include "qemu/osdep.h" |
678 | +#include "qemu/timer.h" | 41 | +#include "qemu/bitops.h" |
679 | + | ||
680 | +#include "libqos/libqtest.h" | 42 | +#include "libqos/libqtest.h" |
681 | +#include "qapi/qmp/qdict.h" | 43 | +#include "qapi/qmp/qdict.h" |
682 | + | 44 | +#include "qapi/qmp/qnum.h" |
683 | +#define WTCR_OFFSET 0x1c | 45 | + |
684 | +#define REF_HZ (25000000) | 46 | +#define REF_HZ 25000000 |
685 | + | 47 | + |
686 | +/* WTCR bit fields */ | 48 | +/* Register field definitions. */ |
687 | +#define WTCLK(rv) ((rv) << 10) | 49 | +#define CH_EN BIT(0) |
688 | +#define WTE BIT(7) | 50 | +#define CH_INV BIT(2) |
689 | +#define WTIE BIT(6) | 51 | +#define CH_MOD BIT(3) |
690 | +#define WTIS(rv) ((rv) << 4) | 52 | + |
691 | +#define WTIF BIT(3) | 53 | +/* Registers shared between all PWMs in a module */ |
692 | +#define WTRF BIT(2) | 54 | +#define PPR 0x00 |
693 | +#define WTRE BIT(1) | 55 | +#define CSR 0x04 |
694 | +#define WTR BIT(0) | 56 | +#define PCR 0x08 |
695 | + | 57 | +#define PIER 0x3c |
696 | +typedef struct Watchdog { | 58 | +#define PIIR 0x40 |
59 | + | ||
60 | +/* CLK module related */ | ||
61 | +#define CLK_BA 0xf0801000 | ||
62 | +#define CLKSEL 0x04 | ||
63 | +#define CLKDIV1 0x08 | ||
64 | +#define CLKDIV2 0x2c | ||
65 | +#define PLLCON0 0x0c | ||
66 | +#define PLLCON1 0x10 | ||
67 | +#define PLL_INDV(rv) extract32((rv), 0, 6) | ||
68 | +#define PLL_FBDV(rv) extract32((rv), 16, 12) | ||
69 | +#define PLL_OTDV1(rv) extract32((rv), 8, 3) | ||
70 | +#define PLL_OTDV2(rv) extract32((rv), 13, 3) | ||
71 | +#define APB3CKDIV(rv) extract32((rv), 28, 2) | ||
72 | +#define CLK2CKDIV(rv) extract32((rv), 0, 1) | ||
73 | +#define CLK4CKDIV(rv) extract32((rv), 26, 2) | ||
74 | +#define CPUCKSEL(rv) extract32((rv), 0, 2) | ||
75 | + | ||
76 | +#define MAX_DUTY 1000000 | ||
77 | + | ||
78 | +typedef struct PWMModule { | ||
697 | + int irq; | 79 | + int irq; |
698 | + uint64_t base_addr; | 80 | + uint64_t base_addr; |
699 | +} Watchdog; | 81 | +} PWMModule; |
700 | + | 82 | + |
701 | +static const Watchdog watchdog_list[] = { | 83 | +typedef struct PWM { |
84 | + uint32_t cnr_offset; | ||
85 | + uint32_t cmr_offset; | ||
86 | + uint32_t pdr_offset; | ||
87 | + uint32_t pwdr_offset; | ||
88 | +} PWM; | ||
89 | + | ||
90 | +typedef struct TestData { | ||
91 | + const PWMModule *module; | ||
92 | + const PWM *pwm; | ||
93 | +} TestData; | ||
94 | + | ||
95 | +static const PWMModule pwm_module_list[] = { | ||
702 | + { | 96 | + { |
703 | + .irq = 47, | 97 | + .irq = 93, |
704 | + .base_addr = 0xf0008000 | 98 | + .base_addr = 0xf0103000 |
705 | + }, | 99 | + }, |
706 | + { | 100 | + { |
707 | + .irq = 48, | 101 | + .irq = 94, |
708 | + .base_addr = 0xf0009000 | 102 | + .base_addr = 0xf0104000 |
103 | + } | ||
104 | +}; | ||
105 | + | ||
106 | +static const PWM pwm_list[] = { | ||
107 | + { | ||
108 | + .cnr_offset = 0x0c, | ||
109 | + .cmr_offset = 0x10, | ||
110 | + .pdr_offset = 0x14, | ||
111 | + .pwdr_offset = 0x44, | ||
709 | + }, | 112 | + }, |
710 | + { | 113 | + { |
711 | + .irq = 49, | 114 | + .cnr_offset = 0x18, |
712 | + .base_addr = 0xf000a000 | 115 | + .cmr_offset = 0x1c, |
713 | + } | 116 | + .pdr_offset = 0x20, |
117 | + .pwdr_offset = 0x48, | ||
118 | + }, | ||
119 | + { | ||
120 | + .cnr_offset = 0x24, | ||
121 | + .cmr_offset = 0x28, | ||
122 | + .pdr_offset = 0x2c, | ||
123 | + .pwdr_offset = 0x4c, | ||
124 | + }, | ||
125 | + { | ||
126 | + .cnr_offset = 0x30, | ||
127 | + .cmr_offset = 0x34, | ||
128 | + .pdr_offset = 0x38, | ||
129 | + .pwdr_offset = 0x50, | ||
130 | + }, | ||
714 | +}; | 131 | +}; |
715 | + | 132 | + |
716 | +static int watchdog_index(const Watchdog *wd) | 133 | +static const int ppr_base[] = { 0, 0, 8, 8 }; |
717 | +{ | 134 | +static const int csr_base[] = { 0, 4, 8, 12 }; |
718 | + ptrdiff_t diff = wd - watchdog_list; | 135 | +static const int pcr_base[] = { 0, 8, 12, 16 }; |
719 | + | 136 | + |
720 | + g_assert(diff >= 0 && diff < ARRAY_SIZE(watchdog_list)); | 137 | +static const uint32_t ppr_list[] = { |
138 | + 0, | ||
139 | + 1, | ||
140 | + 10, | ||
141 | + 100, | ||
142 | + 255, /* Max possible value. */ | ||
143 | +}; | ||
144 | + | ||
145 | +static const uint32_t csr_list[] = { | ||
146 | + 0, | ||
147 | + 1, | ||
148 | + 2, | ||
149 | + 3, | ||
150 | + 4, /* Max possible value. */ | ||
151 | +}; | ||
152 | + | ||
153 | +static const uint32_t cnr_list[] = { | ||
154 | + 0, | ||
155 | + 1, | ||
156 | + 50, | ||
157 | + 100, | ||
158 | + 150, | ||
159 | + 200, | ||
160 | + 1000, | ||
161 | + 10000, | ||
162 | + 65535, /* Max possible value. */ | ||
163 | +}; | ||
164 | + | ||
165 | +static const uint32_t cmr_list[] = { | ||
166 | + 0, | ||
167 | + 1, | ||
168 | + 10, | ||
169 | + 50, | ||
170 | + 100, | ||
171 | + 150, | ||
172 | + 200, | ||
173 | + 1000, | ||
174 | + 10000, | ||
175 | + 65535, /* Max possible value. */ | ||
176 | +}; | ||
177 | + | ||
178 | +/* Returns the index of the PWM module. */ | ||
179 | +static int pwm_module_index(const PWMModule *module) | ||
180 | +{ | ||
181 | + ptrdiff_t diff = module - pwm_module_list; | ||
182 | + | ||
183 | + g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list)); | ||
721 | + | 184 | + |
722 | + return diff; | 185 | + return diff; |
723 | +} | 186 | +} |
724 | + | 187 | + |
725 | +static uint32_t watchdog_read_wtcr(QTestState *qts, const Watchdog *wd) | 188 | +/* Returns the index of the PWM entry. */ |
726 | +{ | 189 | +static int pwm_index(const PWM *pwm) |
727 | + return qtest_readl(qts, wd->base_addr + WTCR_OFFSET); | 190 | +{ |
728 | +} | 191 | + ptrdiff_t diff = pwm - pwm_list; |
729 | + | 192 | + |
730 | +static void watchdog_write_wtcr(QTestState *qts, const Watchdog *wd, | 193 | + g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_list)); |
731 | + uint32_t value) | 194 | + |
732 | +{ | 195 | + return diff; |
733 | + qtest_writel(qts, wd->base_addr + WTCR_OFFSET, value); | 196 | +} |
734 | +} | 197 | + |
735 | + | 198 | +static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name) |
736 | +static uint32_t watchdog_prescaler(QTestState *qts, const Watchdog *wd) | 199 | +{ |
737 | +{ | 200 | + QDict *response; |
738 | + switch (extract32(watchdog_read_wtcr(qts, wd), 10, 2)) { | 201 | + |
202 | + g_test_message("Getting properties %s from %s", name, path); | ||
203 | + response = qtest_qmp(qts, "{ 'execute': 'qom-get'," | ||
204 | + " 'arguments': { 'path': %s, 'property': %s}}", | ||
205 | + path, name); | ||
206 | + /* The qom set message returns successfully. */ | ||
207 | + g_assert_true(qdict_haskey(response, "return")); | ||
208 | + return qnum_get_uint(qobject_to(QNum, qdict_get(response, "return"))); | ||
209 | +} | ||
210 | + | ||
211 | +static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index) | ||
212 | +{ | ||
213 | + char path[100]; | ||
214 | + char name[100]; | ||
215 | + | ||
216 | + sprintf(path, "/machine/soc/pwm[%d]", module_index); | ||
217 | + sprintf(name, "freq[%d]", pwm_index); | ||
218 | + | ||
219 | + return pwm_qom_get(qts, path, name); | ||
220 | +} | ||
221 | + | ||
222 | +static uint64_t pwm_get_duty(QTestState *qts, int module_index, int pwm_index) | ||
223 | +{ | ||
224 | + char path[100]; | ||
225 | + char name[100]; | ||
226 | + | ||
227 | + sprintf(path, "/machine/soc/pwm[%d]", module_index); | ||
228 | + sprintf(name, "duty[%d]", pwm_index); | ||
229 | + | ||
230 | + return pwm_qom_get(qts, path, name); | ||
231 | +} | ||
232 | + | ||
233 | +static uint32_t get_pll(uint32_t con) | ||
234 | +{ | ||
235 | + return REF_HZ * PLL_FBDV(con) / (PLL_INDV(con) * PLL_OTDV1(con) | ||
236 | + * PLL_OTDV2(con)); | ||
237 | +} | ||
238 | + | ||
239 | +static uint64_t read_pclk(QTestState *qts) | ||
240 | +{ | ||
241 | + uint64_t freq = REF_HZ; | ||
242 | + uint32_t clksel = qtest_readl(qts, CLK_BA + CLKSEL); | ||
243 | + uint32_t pllcon; | ||
244 | + uint32_t clkdiv1 = qtest_readl(qts, CLK_BA + CLKDIV1); | ||
245 | + uint32_t clkdiv2 = qtest_readl(qts, CLK_BA + CLKDIV2); | ||
246 | + | ||
247 | + switch (CPUCKSEL(clksel)) { | ||
739 | + case 0: | 248 | + case 0: |
740 | + return 1; | 249 | + pllcon = qtest_readl(qts, CLK_BA + PLLCON0); |
250 | + freq = get_pll(pllcon); | ||
251 | + break; | ||
741 | + case 1: | 252 | + case 1: |
742 | + return 256; | 253 | + pllcon = qtest_readl(qts, CLK_BA + PLLCON1); |
254 | + freq = get_pll(pllcon); | ||
255 | + break; | ||
743 | + case 2: | 256 | + case 2: |
744 | + return 2048; | 257 | + break; |
745 | + case 3: | 258 | + case 3: |
746 | + return 65536; | 259 | + break; |
747 | + default: | 260 | + default: |
748 | + g_assert_not_reached(); | 261 | + g_assert_not_reached(); |
749 | + } | 262 | + } |
750 | +} | 263 | + |
751 | + | 264 | + freq >>= (CLK2CKDIV(clkdiv1) + CLK4CKDIV(clkdiv1) + APB3CKDIV(clkdiv2)); |
752 | +static QDict *get_watchdog_action(QTestState *qts) | 265 | + |
753 | +{ | 266 | + return freq; |
754 | + QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG"); | 267 | +} |
755 | + QDict *data; | 268 | + |
756 | + | 269 | +static uint32_t pwm_selector(uint32_t csr) |
757 | + data = qdict_get_qdict(ev, "data"); | 270 | +{ |
758 | + qobject_ref(data); | 271 | + switch (csr) { |
759 | + qobject_unref(ev); | 272 | + case 0: |
760 | + return data; | 273 | + return 2; |
761 | +} | 274 | + case 1: |
762 | + | 275 | + return 4; |
763 | +#define RESET_CYCLES 1024 | 276 | + case 2: |
764 | +static uint32_t watchdog_interrupt_cycles(QTestState *qts, const Watchdog *wd) | 277 | + return 8; |
765 | +{ | 278 | + case 3: |
766 | + uint32_t wtis = extract32(watchdog_read_wtcr(qts, wd), 4, 2); | 279 | + return 16; |
767 | + return 1 << (14 + 2 * wtis); | 280 | + case 4: |
768 | +} | 281 | + return 1; |
769 | + | 282 | + default: |
770 | +static int64_t watchdog_calculate_steps(uint32_t count, uint32_t prescale) | 283 | + g_assert_not_reached(); |
771 | +{ | 284 | + } |
772 | + return (NANOSECONDS_PER_SECOND / REF_HZ) * count * prescale; | 285 | +} |
773 | +} | 286 | + |
774 | + | 287 | +static uint64_t pwm_compute_freq(QTestState *qts, uint32_t ppr, uint32_t csr, |
775 | +static int64_t watchdog_interrupt_steps(QTestState *qts, const Watchdog *wd) | 288 | + uint32_t cnr) |
776 | +{ | 289 | +{ |
777 | + return watchdog_calculate_steps(watchdog_interrupt_cycles(qts, wd), | 290 | + return read_pclk(qts) / ((ppr + 1) * pwm_selector(csr) * (cnr + 1)); |
778 | + watchdog_prescaler(qts, wd)); | 291 | +} |
779 | +} | 292 | + |
780 | + | 293 | +static uint64_t pwm_compute_duty(uint32_t cnr, uint32_t cmr, bool inverted) |
781 | +/* Check wtcr can be reset to default value */ | 294 | +{ |
782 | +static void test_init(gconstpointer watchdog) | 295 | + uint64_t duty; |
783 | +{ | 296 | + |
784 | + const Watchdog *wd = watchdog; | 297 | + if (cnr == 0) { |
298 | + /* PWM is stopped. */ | ||
299 | + duty = 0; | ||
300 | + } else if (cmr >= cnr) { | ||
301 | + duty = MAX_DUTY; | ||
302 | + } else { | ||
303 | + duty = MAX_DUTY * (cmr + 1) / (cnr + 1); | ||
304 | + } | ||
305 | + | ||
306 | + if (inverted) { | ||
307 | + duty = MAX_DUTY - duty; | ||
308 | + } | ||
309 | + | ||
310 | + return duty; | ||
311 | +} | ||
312 | + | ||
313 | +static uint32_t pwm_read(QTestState *qts, const TestData *td, unsigned offset) | ||
314 | +{ | ||
315 | + return qtest_readl(qts, td->module->base_addr + offset); | ||
316 | +} | ||
317 | + | ||
318 | +static void pwm_write(QTestState *qts, const TestData *td, unsigned offset, | ||
319 | + uint32_t value) | ||
320 | +{ | ||
321 | + qtest_writel(qts, td->module->base_addr + offset, value); | ||
322 | +} | ||
323 | + | ||
324 | +static uint32_t pwm_read_ppr(QTestState *qts, const TestData *td) | ||
325 | +{ | ||
326 | + return extract32(pwm_read(qts, td, PPR), ppr_base[pwm_index(td->pwm)], 8); | ||
327 | +} | ||
328 | + | ||
329 | +static void pwm_write_ppr(QTestState *qts, const TestData *td, uint32_t value) | ||
330 | +{ | ||
331 | + pwm_write(qts, td, PPR, value << ppr_base[pwm_index(td->pwm)]); | ||
332 | +} | ||
333 | + | ||
334 | +static uint32_t pwm_read_csr(QTestState *qts, const TestData *td) | ||
335 | +{ | ||
336 | + return extract32(pwm_read(qts, td, CSR), csr_base[pwm_index(td->pwm)], 3); | ||
337 | +} | ||
338 | + | ||
339 | +static void pwm_write_csr(QTestState *qts, const TestData *td, uint32_t value) | ||
340 | +{ | ||
341 | + pwm_write(qts, td, CSR, value << csr_base[pwm_index(td->pwm)]); | ||
342 | +} | ||
343 | + | ||
344 | +static uint32_t pwm_read_pcr(QTestState *qts, const TestData *td) | ||
345 | +{ | ||
346 | + return extract32(pwm_read(qts, td, PCR), pcr_base[pwm_index(td->pwm)], 4); | ||
347 | +} | ||
348 | + | ||
349 | +static void pwm_write_pcr(QTestState *qts, const TestData *td, uint32_t value) | ||
350 | +{ | ||
351 | + pwm_write(qts, td, PCR, value << pcr_base[pwm_index(td->pwm)]); | ||
352 | +} | ||
353 | + | ||
354 | +static uint32_t pwm_read_cnr(QTestState *qts, const TestData *td) | ||
355 | +{ | ||
356 | + return pwm_read(qts, td, td->pwm->cnr_offset); | ||
357 | +} | ||
358 | + | ||
359 | +static void pwm_write_cnr(QTestState *qts, const TestData *td, uint32_t value) | ||
360 | +{ | ||
361 | + pwm_write(qts, td, td->pwm->cnr_offset, value); | ||
362 | +} | ||
363 | + | ||
364 | +static uint32_t pwm_read_cmr(QTestState *qts, const TestData *td) | ||
365 | +{ | ||
366 | + return pwm_read(qts, td, td->pwm->cmr_offset); | ||
367 | +} | ||
368 | + | ||
369 | +static void pwm_write_cmr(QTestState *qts, const TestData *td, uint32_t value) | ||
370 | +{ | ||
371 | + pwm_write(qts, td, td->pwm->cmr_offset, value); | ||
372 | +} | ||
373 | + | ||
374 | +/* Check pwm registers can be reset to default value */ | ||
375 | +static void test_init(gconstpointer test_data) | ||
376 | +{ | ||
377 | + const TestData *td = test_data; | ||
785 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | 378 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
786 | + | 379 | + int module = pwm_module_index(td->module); |
787 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | 380 | + int pwm = pwm_index(td->pwm); |
788 | + | 381 | + |
789 | + watchdog_write_wtcr(qts, wd, WTCLK(1) | WTRF | WTIF | WTR); | 382 | + g_assert_cmpuint(pwm_get_freq(qts, module, pwm), ==, 0); |
790 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1)); | 383 | + g_assert_cmpuint(pwm_get_duty(qts, module, pwm), ==, 0); |
791 | + | 384 | + |
792 | + qtest_quit(qts); | 385 | + qtest_quit(qts); |
793 | +} | 386 | +} |
794 | + | 387 | + |
795 | +/* Check a watchdog can generate interrupt and reset actions */ | 388 | +/* One-shot mode should not change frequency and duty cycle. */ |
796 | +static void test_reset_action(gconstpointer watchdog) | 389 | +static void test_oneshot(gconstpointer test_data) |
797 | +{ | 390 | +{ |
798 | + const Watchdog *wd = watchdog; | 391 | + const TestData *td = test_data; |
799 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | 392 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
800 | + QDict *ad; | 393 | + int module = pwm_module_index(td->module); |
801 | + | 394 | + int pwm = pwm_index(td->pwm); |
802 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | 395 | + uint32_t ppr, csr, pcr; |
803 | + | 396 | + int i, j; |
804 | + watchdog_write_wtcr(qts, wd, | 397 | + |
805 | + WTCLK(0) | WTE | WTRF | WTRE | WTIF | WTIE | WTR); | 398 | + pcr = CH_EN; |
806 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | 399 | + for (i = 0; i < ARRAY_SIZE(ppr_list); ++i) { |
807 | + WTCLK(0) | WTE | WTRE | WTIE); | 400 | + ppr = ppr_list[i]; |
808 | + | 401 | + pwm_write_ppr(qts, td, ppr); |
809 | + /* Check a watchdog can generate an interrupt */ | 402 | + |
810 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | 403 | + for (j = 0; j < ARRAY_SIZE(csr_list); ++j) { |
811 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | 404 | + csr = csr_list[j]; |
812 | + WTCLK(0) | WTE | WTIF | WTIE | WTRE); | 405 | + pwm_write_csr(qts, td, csr); |
813 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | 406 | + pwm_write_pcr(qts, td, pcr); |
814 | + | 407 | + |
815 | + /* Check a watchdog can generate a reset signal */ | 408 | + g_assert_cmpuint(pwm_read_ppr(qts, td), ==, ppr); |
816 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | 409 | + g_assert_cmpuint(pwm_read_csr(qts, td), ==, csr); |
817 | + watchdog_prescaler(qts, wd))); | 410 | + g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr); |
818 | + ad = get_watchdog_action(qts); | 411 | + g_assert_cmpuint(pwm_get_freq(qts, module, pwm), ==, 0); |
819 | + /* The signal is a reset signal */ | 412 | + g_assert_cmpuint(pwm_get_duty(qts, module, pwm), ==, 0); |
820 | + g_assert_false(strcmp(qdict_get_str(ad, "action"), "reset")); | 413 | + } |
821 | + qobject_unref(ad); | 414 | + } |
822 | + qtest_qmp_eventwait(qts, "RESET"); | 415 | + |
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); | 416 | + qtest_quit(qts); |
829 | +} | 417 | +} |
830 | + | 418 | + |
831 | +/* Check a watchdog works with all possible WTCLK prescalers and WTIS cycles */ | 419 | +/* In toggle mode, the PWM generates correct outputs. */ |
832 | +static void test_prescaler(gconstpointer watchdog) | 420 | +static void test_toggle(gconstpointer test_data) |
833 | +{ | 421 | +{ |
834 | + const Watchdog *wd = watchdog; | 422 | + const TestData *td = test_data; |
835 | + | 423 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
836 | + for (int wtclk = 0; wtclk < 4; ++wtclk) { | 424 | + int module = pwm_module_index(td->module); |
837 | + for (int wtis = 0; wtis < 4; ++wtis) { | 425 | + int pwm = pwm_index(td->pwm); |
838 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | 426 | + uint32_t ppr, csr, pcr, cnr, cmr; |
839 | + | 427 | + int i, j, k, l; |
840 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | 428 | + uint64_t expected_freq, expected_duty; |
841 | + watchdog_write_wtcr(qts, wd, | 429 | + |
842 | + WTCLK(wtclk) | WTE | WTIF | WTIS(wtis) | WTIE | WTR); | 430 | + pcr = CH_EN | CH_MOD; |
843 | + /* | 431 | + for (i = 0; i < ARRAY_SIZE(ppr_list); ++i) { |
844 | + * The interrupt doesn't fire until watchdog_interrupt_steps() | 432 | + ppr = ppr_list[i]; |
845 | + * cycles passed | 433 | + pwm_write_ppr(qts, td, ppr); |
846 | + */ | 434 | + |
847 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd) - 1); | 435 | + for (j = 0; j < ARRAY_SIZE(csr_list); ++j) { |
848 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTIF); | 436 | + csr = csr_list[j]; |
849 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | 437 | + pwm_write_csr(qts, td, csr); |
850 | + qtest_clock_step(qts, 1); | 438 | + |
851 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | 439 | + for (k = 0; k < ARRAY_SIZE(cnr_list); ++k) { |
852 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | 440 | + cnr = cnr_list[k]; |
853 | + | 441 | + pwm_write_cnr(qts, td, cnr); |
854 | + qtest_quit(qts); | 442 | + |
443 | + for (l = 0; l < ARRAY_SIZE(cmr_list); ++l) { | ||
444 | + cmr = cmr_list[l]; | ||
445 | + pwm_write_cmr(qts, td, cmr); | ||
446 | + expected_freq = pwm_compute_freq(qts, ppr, csr, cnr); | ||
447 | + expected_duty = pwm_compute_duty(cnr, cmr, false); | ||
448 | + | ||
449 | + pwm_write_pcr(qts, td, pcr); | ||
450 | + g_assert_cmpuint(pwm_read_ppr(qts, td), ==, ppr); | ||
451 | + g_assert_cmpuint(pwm_read_csr(qts, td), ==, csr); | ||
452 | + g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr); | ||
453 | + g_assert_cmpuint(pwm_read_cnr(qts, td), ==, cnr); | ||
454 | + g_assert_cmpuint(pwm_read_cmr(qts, td), ==, cmr); | ||
455 | + g_assert_cmpuint(pwm_get_duty(qts, module, pwm), | ||
456 | + ==, expected_duty); | ||
457 | + if (expected_duty != 0 && expected_duty != 100) { | ||
458 | + /* Duty cycle with 0 or 100 doesn't need frequency. */ | ||
459 | + g_assert_cmpuint(pwm_get_freq(qts, module, pwm), | ||
460 | + ==, expected_freq); | ||
461 | + } | ||
462 | + | ||
463 | + /* Test inverted mode */ | ||
464 | + expected_duty = pwm_compute_duty(cnr, cmr, true); | ||
465 | + pwm_write_pcr(qts, td, pcr | CH_INV); | ||
466 | + g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr | CH_INV); | ||
467 | + g_assert_cmpuint(pwm_get_duty(qts, module, pwm), | ||
468 | + ==, expected_duty); | ||
469 | + if (expected_duty != 0 && expected_duty != 100) { | ||
470 | + /* Duty cycle with 0 or 100 doesn't need frequency. */ | ||
471 | + g_assert_cmpuint(pwm_get_freq(qts, module, pwm), | ||
472 | + ==, expected_freq); | ||
473 | + } | ||
474 | + | ||
475 | + } | ||
476 | + } | ||
855 | + } | 477 | + } |
856 | + } | 478 | + } |
857 | +} | 479 | + |
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); | 480 | + qtest_quit(qts); |
880 | + | 481 | +} |
881 | + /* Only WTIE is set, interrupt is triggered but reset should not happen */ | 482 | + |
882 | + qts = qtest_init("-machine quanta-gsj"); | 483 | +static void pwm_add_test(const char *name, const TestData* td, |
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) | 484 | + GTestDataFunc fn) |
956 | +{ | 485 | +{ |
957 | + g_autofree char *full_name = g_strdup_printf( | 486 | + g_autofree char *full_name = g_strdup_printf( |
958 | + "npcm7xx_watchdog_timer[%d]/%s", watchdog_index(wd), name); | 487 | + "npcm7xx_pwm/module[%d]/pwm[%d]/%s", pwm_module_index(td->module), |
959 | + qtest_add_data_func(full_name, wd, fn); | 488 | + pwm_index(td->pwm), name); |
960 | +} | 489 | + qtest_add_data_func(full_name, td, fn); |
961 | +#define add_test(name, td) watchdog_add_test(#name, td, test_##name) | 490 | +} |
491 | +#define add_test(name, td) pwm_add_test(#name, td, test_##name) | ||
962 | + | 492 | + |
963 | +int main(int argc, char **argv) | 493 | +int main(int argc, char **argv) |
964 | +{ | 494 | +{ |
495 | + TestData test_data_list[ARRAY_SIZE(pwm_module_list) * ARRAY_SIZE(pwm_list)]; | ||
496 | + | ||
965 | + g_test_init(&argc, &argv, NULL); | 497 | + g_test_init(&argc, &argv, NULL); |
966 | + g_test_set_nonfatal_assertions(); | 498 | + |
967 | + | 499 | + for (int i = 0; i < ARRAY_SIZE(pwm_module_list); ++i) { |
968 | + for (int i = 0; i < ARRAY_SIZE(watchdog_list); ++i) { | 500 | + for (int j = 0; j < ARRAY_SIZE(pwm_list); ++j) { |
969 | + const Watchdog *wd = &watchdog_list[i]; | 501 | + TestData *td = &test_data_list[i * ARRAY_SIZE(pwm_list) + j]; |
970 | + | 502 | + |
971 | + add_test(init, wd); | 503 | + td->module = &pwm_module_list[i]; |
972 | + add_test(reset_action, wd); | 504 | + td->pwm = &pwm_list[j]; |
973 | + add_test(prescaler, wd); | 505 | + |
974 | + add_test(enabling_flags, wd); | 506 | + add_test(init, td); |
975 | + add_test(pause, wd); | 507 | + add_test(oneshot, td); |
508 | + add_test(toggle, td); | ||
509 | + } | ||
976 | + } | 510 | + } |
977 | + | 511 | + |
978 | + return g_test_run(); | 512 | + return g_test_run(); |
979 | +} | 513 | +} |
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 | 514 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
993 | index XXXXXXX..XXXXXXX 100644 | 515 | index XXXXXXX..XXXXXXX 100644 |
994 | --- a/tests/qtest/meson.build | 516 | --- a/tests/qtest/meson.build |
995 | +++ b/tests/qtest/meson.build | 517 | +++ b/tests/qtest/meson.build |
996 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | 518 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ |
997 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | 519 | qtests_npcm7xx = \ |
998 | ['prom-env-test', 'boot-serial-test'] | 520 | ['npcm7xx_adc-test', |
999 | 521 | 'npcm7xx_gpio-test', | |
1000 | -qtests_npcm7xx = ['npcm7xx_timer-test'] | 522 | + 'npcm7xx_pwm-test', |
1001 | +qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | 523 | 'npcm7xx_rng-test', |
1002 | qtests_arm = \ | 524 | 'npcm7xx_timer-test', |
1003 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | 525 | 'npcm7xx_watchdog_timer-test'] |
1004 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
1005 | -- | 526 | -- |
1006 | 2.20.1 | 527 | 2.20.1 |
1007 | 528 | ||
1008 | 529 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Havard Skinnemoen <hskinnemoen@google.com> | ||
2 | 1 | ||
3 | The NPCM730 and NPCM750 chips have a single USB host port shared between | ||
4 | a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This | ||
5 | adds support for both of them. | ||
6 | |||
7 | Testing notes: | ||
8 | * With -device usb-kbd, qemu will automatically insert a full-speed | ||
9 | hub, and the keyboard becomes controlled by the OHCI controller. | ||
10 | * With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly | ||
11 | attached to the port without any hubs, and the device becomes | ||
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> | ||
24 | --- | ||
25 | docs/system/arm/nuvoton.rst | 2 +- | ||
26 | hw/usb/hcd-ehci.h | 1 + | ||
27 | include/hw/arm/npcm7xx.h | 4 ++++ | ||
28 | hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++-- | ||
29 | hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++ | ||
30 | 5 files changed, 50 insertions(+), 3 deletions(-) | ||
31 | |||
32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/docs/system/arm/nuvoton.rst | ||
35 | +++ b/docs/system/arm/nuvoton.rst | ||
36 | @@ -XXX,XX +XXX,XX @@ Supported devices | ||
37 | * OTP controllers (no protection features) | ||
38 | * Flash Interface Unit (FIU; no protection features) | ||
39 | * Random Number Generator (RNG) | ||
40 | + * USB host (USBH) | ||
41 | |||
42 | Missing devices | ||
43 | --------------- | ||
44 | @@ -XXX,XX +XXX,XX @@ Missing devices | ||
45 | * eSPI slave interface | ||
46 | |||
47 | * Ethernet controllers (GMAC and EMC) | ||
48 | - * USB host (USBH) | ||
49 | * USB device (USBD) | ||
50 | * SMBus controller (SMBF) | ||
51 | * Peripheral SPI controller (PSPI) | ||
52 | diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h | ||
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 | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/include/hw/arm/npcm7xx.h | ||
67 | +++ b/include/hw/arm/npcm7xx.h | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "hw/nvram/npcm7xx_otp.h" | ||
70 | #include "hw/timer/npcm7xx_timer.h" | ||
71 | #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 { | ||
78 | NPCM7xxOTPState fuse_array; | ||
79 | NPCM7xxMCState mc; | ||
80 | NPCM7xxRNGState rng; | ||
81 | + EHCISysBusState ehci; | ||
82 | + OHCISysBusState ohci; | ||
83 | NPCM7xxFIUState fiu[2]; | ||
84 | } NPCM7xxState; | ||
85 | |||
86 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/hw/arm/npcm7xx.c | ||
89 | +++ b/hw/arm/npcm7xx.c | ||
90 | @@ -XXX,XX +XXX,XX @@ | ||
91 | #define NPCM7XX_MC_BA (0xf0824000) | ||
92 | #define NPCM7XX_RNG_BA (0xf000b000) | ||
93 | |||
94 | +/* USB Host modules */ | ||
95 | +#define NPCM7XX_EHCI_BA (0xf0806000) | ||
96 | +#define NPCM7XX_OHCI_BA (0xf0807000) | ||
97 | + | ||
98 | /* Internal AHB SRAM */ | ||
99 | #define NPCM7XX_RAM3_BA (0xc0008000) | ||
100 | #define NPCM7XX_RAM3_SZ (4 * KiB) | ||
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) | ||
111 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
112 | } | ||
113 | |||
114 | + object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
115 | + object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
116 | + | ||
117 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu)); | ||
118 | for (i = 0; i < ARRAY_SIZE(s->fiu); i++) { | ||
119 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], | ||
120 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
121 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
123 | |||
124 | + /* USB Host */ | ||
125 | + object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
126 | + &error_abort); | ||
127 | + sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort); | ||
128 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA); | ||
129 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0, | ||
130 | + npcm7xx_irq(s, NPCM7XX_EHCI_IRQ)); | ||
131 | + | ||
132 | + object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0", | ||
133 | + &error_abort); | ||
134 | + object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort); | ||
135 | + sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort); | ||
136 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA); | ||
137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, | ||
138 | + npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); | ||
139 | + | ||
140 | /* | ||
141 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | ||
142 | * specified, but this is a programming error. | ||
143 | @@ -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); | ||
150 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); | ||
151 | 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 | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/hw/usb/hcd-ehci-sysbus.c | ||
155 | +++ b/hw/usb/hcd-ehci-sysbus.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = { | ||
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 | -- | ||
190 | 2.20.1 | ||
191 | |||
192 | 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 | Remove usage of TypeInfo::class_data. Instead fill the fields in | ||
4 | the corresponding class_init(). | ||
5 | |||
6 | So far all children use the same values for almost all fields, | ||
7 | but we are going to add the BCM2711/BCM2838 SoC for the raspi4 | ||
8 | machine which use different fields. | ||
9 | |||
10 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
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> | ||
14 | --- | ||
15 | hw/arm/bcm2836.c | 108 ++++++++++++++++++++++------------------------- | ||
16 | 1 file changed, 51 insertions(+), 57 deletions(-) | ||
17 | |||
18 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/arm/bcm2836.c | ||
21 | +++ b/hw/arm/bcm2836.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include "hw/arm/raspi_platform.h" | ||
24 | #include "hw/sysbus.h" | ||
25 | |||
26 | -typedef struct BCM283XInfo BCM283XInfo; | ||
27 | - | ||
28 | typedef struct BCM283XClass { | ||
29 | /*< private >*/ | ||
30 | DeviceClass parent_class; | ||
31 | /*< public >*/ | ||
32 | - const BCM283XInfo *info; | ||
33 | -} BCM283XClass; | ||
34 | - | ||
35 | -struct BCM283XInfo { | ||
36 | const char *name; | ||
37 | const char *cpu_type; | ||
38 | hwaddr peri_base; /* Peripheral base address seen by the CPU */ | ||
39 | hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ | ||
40 | int clusterid; | ||
41 | -}; | ||
42 | +} BCM283XClass; | ||
43 | |||
44 | #define BCM283X_CLASS(klass) \ | ||
45 | OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) | ||
46 | #define BCM283X_GET_CLASS(obj) \ | ||
47 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | ||
48 | |||
49 | -static const BCM283XInfo bcm283x_socs[] = { | ||
50 | - { | ||
51 | - .name = TYPE_BCM2836, | ||
52 | - .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"), | ||
53 | - .peri_base = 0x3f000000, | ||
54 | - .ctrl_base = 0x40000000, | ||
55 | - .clusterid = 0xf, | ||
56 | - }, | ||
57 | -#ifdef TARGET_AARCH64 | ||
58 | - { | ||
59 | - .name = TYPE_BCM2837, | ||
60 | - .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"), | ||
61 | - .peri_base = 0x3f000000, | ||
62 | - .ctrl_base = 0x40000000, | ||
63 | - .clusterid = 0x0, | ||
64 | - }, | ||
65 | -#endif | ||
66 | -}; | ||
67 | - | ||
68 | static void bcm2836_init(Object *obj) | ||
69 | { | ||
70 | BCM283XState *s = BCM283X(obj); | ||
71 | BCM283XClass *bc = BCM283X_GET_CLASS(obj); | ||
72 | - const BCM283XInfo *info = bc->info; | ||
73 | int n; | ||
74 | |||
75 | for (n = 0; n < BCM283X_NCPUS; n++) { | ||
76 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, | ||
77 | - info->cpu_type); | ||
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 | { | ||
84 | BCM283XState *s = BCM283X(dev); | ||
85 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
86 | - const BCM283XInfo *info = bc->info; | ||
87 | Object *obj; | ||
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; | ||
100 | } | ||
101 | |||
102 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base); | ||
103 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base); | ||
104 | |||
105 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
106 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0)); | ||
107 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
108 | |||
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 | { | ||
124 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
125 | - BCM283XClass *bc = BCM283X_CLASS(oc); | ||
126 | |||
127 | - bc->info = data; | ||
128 | - dc->realize = bcm2836_realize; | ||
129 | - device_class_set_props(dc, bcm2836_props); | ||
130 | /* Reason: Must be wired up in code (see raspi_init() function) */ | ||
131 | dc->user_creatable = false; | ||
132 | } | ||
133 | |||
134 | -static const TypeInfo bcm283x_type_info = { | ||
135 | - .name = TYPE_BCM283X, | ||
136 | - .parent = TYPE_DEVICE, | ||
137 | - .instance_size = sizeof(BCM283XState), | ||
138 | - .instance_init = bcm2836_init, | ||
139 | - .class_size = sizeof(BCM283XClass), | ||
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 | { | ||
158 | - int i; | ||
159 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
160 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
161 | |||
162 | - type_register_static(&bcm283x_type_info); | ||
163 | - for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) { | ||
164 | - TypeInfo ti = { | ||
165 | - .name = bcm283x_socs[i].name, | ||
166 | - .parent = TYPE_BCM283X, | ||
167 | - .class_init = bcm283x_class_init, | ||
168 | - .class_data = (void *) &bcm283x_socs[i], | ||
169 | - }; | ||
170 | - type_register(&ti); | ||
171 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | ||
172 | + bc->peri_base = 0x3f000000; | ||
173 | + bc->ctrl_base = 0x40000000; | ||
174 | + bc->clusterid = 0x0; | ||
175 | + dc->realize = bcm2836_realize; | ||
176 | + device_class_set_props(dc, bcm2836_props); | ||
177 | +}; | ||
178 | +#endif | ||
179 | + | ||
180 | +static const TypeInfo bcm283x_types[] = { | ||
181 | + { | ||
182 | + .name = TYPE_BCM2836, | ||
183 | + .parent = TYPE_BCM283X, | ||
184 | + .class_init = bcm2836_class_init, | ||
185 | +#ifdef TARGET_AARCH64 | ||
186 | + }, { | ||
187 | + .name = TYPE_BCM2837, | ||
188 | + .parent = TYPE_BCM283X, | ||
189 | + .class_init = bcm2837_class_init, | ||
190 | +#endif | ||
191 | + }, { | ||
192 | + .name = TYPE_BCM283X, | ||
193 | + .parent = TYPE_DEVICE, | ||
194 | + .instance_size = sizeof(BCM283XState), | ||
195 | + .instance_init = bcm2836_init, | ||
196 | + .class_size = sizeof(BCM283XClass), | ||
197 | + .class_init = bcm283x_class_init, | ||
198 | + .abstract = true, | ||
199 | } | ||
200 | -} | ||
201 | +}; | ||
202 | |||
203 | -type_init(bcm2836_register_types) | ||
204 | +DEFINE_TYPES(bcm283x_types) | ||
205 | -- | ||
206 | 2.20.1 | ||
207 | |||
208 | 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 | It makes no sense to set enabled-cpus=0 on single core SoCs. | ||
4 | |||
5 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Message-id: 20201024170127.3592182-5-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/arm/bcm2836.c | 15 +++++++-------- | ||
11 | 1 file changed, 7 insertions(+), 8 deletions(-) | ||
12 | |||
13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/arm/bcm2836.c | ||
16 | +++ b/hw/arm/bcm2836.c | ||
17 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { | ||
18 | #define BCM283X_GET_CLASS(obj) \ | ||
19 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | ||
20 | |||
21 | +static Property bcm2836_enabled_cores_property = | ||
22 | + DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0); | ||
23 | + | ||
24 | static void bcm2836_init(Object *obj) | ||
25 | { | ||
26 | BCM283XState *s = BCM283X(obj); | ||
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 | } | ||
41 | |||
42 | -static Property bcm2836_props[] = { | ||
43 | - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, | ||
44 | - BCM283X_NCPUS), | ||
45 | - DEFINE_PROP_END_OF_LIST() | ||
46 | -}; | ||
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 | |||
67 | -- | ||
68 | 2.20.1 | ||
69 | |||
70 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | The realize() function is clearly composed of two parts, | ||
4 | each described by a comment: | ||
5 | |||
6 | void realize() | ||
7 | { | ||
8 | /* common peripherals from bcm2835 */ | ||
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> | ||
21 | --- | ||
22 | hw/arm/bcm2836.c | 22 ++++++++++++++++++---- | ||
23 | 1 file changed, 18 insertions(+), 4 deletions(-) | ||
24 | |||
25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/arm/bcm2836.c | ||
28 | +++ b/hw/arm/bcm2836.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
30 | qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); | ||
31 | } | ||
32 | |||
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 | + | ||
71 | +static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
72 | +{ | ||
73 | + BCM283XState *s = BCM283X(dev); | ||
74 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
75 | + int n; | ||
76 | + | ||
77 | + if (!bcm283x_common_realize(dev, errp)) { | ||
78 | + return; | ||
79 | + } | ||
80 | |||
81 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
82 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { | ||
83 | -- | ||
84 | 2.20.1 | ||
85 | |||
86 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Message-id: 20201024170127.3592182-7-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | include/hw/arm/bcm2836.h | 1 + | ||
9 | hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++ | ||
10 | hw/arm/raspi.c | 2 ++ | ||
11 | 3 files changed, 37 insertions(+) | ||
12 | |||
13 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/include/hw/arm/bcm2836.h | ||
16 | +++ b/include/hw/arm/bcm2836.h | ||
17 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) | ||
18 | * them, code using these devices should always handle them via the | ||
19 | * BCM283x base class, so they have no BCM2836(obj) etc macros. | ||
20 | */ | ||
21 | +#define TYPE_BCM2835 "bcm2835" | ||
22 | #define TYPE_BCM2836 "bcm2836" | ||
23 | #define TYPE_BCM2837 "bcm2837" | ||
24 | |||
25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
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 | } | ||
32 | |||
33 | +static void bcm2835_realize(DeviceState *dev, Error **errp) | ||
34 | +{ | ||
35 | + BCM283XState *s = BCM283X(dev); | ||
36 | + | ||
37 | + if (!bcm283x_common_realize(dev, errp)) { | ||
38 | + return; | ||
39 | + } | ||
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 | -- | ||
105 | 2.20.1 | ||
106 | |||
107 | 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 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | The Pi 3A+ is a stripped down version of the 3B: | ||
4 | - 512 MiB of RAM instead of 1 GiB | ||
5 | - no on-board ethernet chipset | ||
6 | |||
7 | Add it as it is a closer match to what we model. | ||
8 | |||
9 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
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> | ||
13 | --- | ||
14 | hw/arm/raspi.c | 13 +++++++++++++ | ||
15 | 1 file changed, 13 insertions(+) | ||
16 | |||
17 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/arm/raspi.c | ||
20 | +++ b/hw/arm/raspi.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) | ||
22 | }; | ||
23 | |||
24 | #ifdef TARGET_AARCH64 | ||
25 | +static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) | ||
26 | +{ | ||
27 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
28 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
29 | + | ||
30 | + rmc->board_rev = 0x9020e0; /* Revision 1.0 */ | ||
31 | + raspi_machine_class_common_init(mc, rmc->board_rev); | ||
32 | +}; | ||
33 | + | ||
34 | static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | ||
35 | { | ||
36 | MachineClass *mc = MACHINE_CLASS(oc); | ||
37 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = { | ||
38 | .parent = TYPE_RASPI_MACHINE, | ||
39 | .class_init = raspi2b_machine_class_init, | ||
40 | #ifdef TARGET_AARCH64 | ||
41 | + }, { | ||
42 | + .name = MACHINE_TYPE_NAME("raspi3ap"), | ||
43 | + .parent = TYPE_RASPI_MACHINE, | ||
44 | + .class_init = raspi3ap_machine_class_init, | ||
45 | }, { | ||
46 | .name = MACHINE_TYPE_NAME("raspi3b"), | ||
47 | .parent = TYPE_RASPI_MACHINE, | ||
48 | -- | ||
49 | 2.20.1 | ||
50 | |||
51 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
2 | 1 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
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 | --- | ||
10 | include/hw/clock.h | 5 +++++ | ||
11 | 1 file changed, 5 insertions(+) | ||
12 | |||
13 | diff --git a/include/hw/clock.h b/include/hw/clock.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/include/hw/clock.h | ||
16 | +++ b/include/hw/clock.h | ||
17 | @@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock; | ||
18 | VMSTATE_CLOCK_V(field, state, 0) | ||
19 | #define VMSTATE_CLOCK_V(field, state, version) \ | ||
20 | VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) | ||
21 | +#define VMSTATE_ARRAY_CLOCK(field, state, num) \ | ||
22 | + VMSTATE_ARRAY_CLOCK_V(field, state, num, 0) | ||
23 | +#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \ | ||
24 | + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \ | ||
25 | + vmstate_clock, Clock) | ||
26 | |||
27 | /** | ||
28 | * clock_setup_canonical_path: | ||
29 | -- | ||
30 | 2.20.1 | ||
31 | |||
32 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
2 | 1 | ||
3 | The nanosecond unit greatly limits the dynamic range we can display in | ||
4 | clock value traces, for values in the order of 1GHz and more. The | ||
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 | |||
8 | For example, a frequency between 500MHz+ and 1GHz will be displayed as | ||
9 | 1ns. Beyond 1GHz, it will show up as 0ns. | ||
10 | |||
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> | ||
20 | --- | ||
21 | hw/core/clock.c | 6 +++--- | ||
22 | hw/core/trace-events | 4 ++-- | ||
23 | 2 files changed, 5 insertions(+), 5 deletions(-) | ||
24 | |||
25 | diff --git a/hw/core/clock.c b/hw/core/clock.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/core/clock.c | ||
28 | +++ b/hw/core/clock.c | ||
29 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) | ||
30 | if (clk->period == period) { | ||
31 | return false; | ||
32 | } | ||
33 | - trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period), | ||
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 | -- | ||
63 | 2.20.1 | ||
64 | |||
65 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
2 | 1 | ||
3 | The CPRMAN (clock controller) was mapped at the watchdog/power manager | ||
4 | address. It was also split into two unimplemented peripherals (CM and | ||
5 | A2W) but this is really the same one, as shown by this extract of the | ||
6 | Raspberry Pi 3 Linux device tree: | ||
7 | |||
8 | watchdog@7e100000 { | ||
9 | compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt"; | ||
10 | [...] | ||
11 | reg = <0x7e100000 0x114 0x7e00a000 0x24>; | ||
12 | [...] | ||
13 | }; | ||
14 | |||
15 | [...] | ||
16 | cprman@7e101000 { | ||
17 | compatible = "brcm,bcm2835-cprman"; | ||
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> | ||
28 | --- | ||
29 | include/hw/arm/bcm2835_peripherals.h | 2 +- | ||
30 | include/hw/arm/raspi_platform.h | 5 ++--- | ||
31 | hw/arm/bcm2835_peripherals.c | 4 ++-- | ||
32 | 3 files changed, 5 insertions(+), 6 deletions(-) | ||
33 | |||
34 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/hw/arm/bcm2835_peripherals.h | ||
37 | +++ b/include/hw/arm/bcm2835_peripherals.h | ||
38 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | ||
39 | BCM2835MphiState mphi; | ||
40 | UnimplementedDeviceState txp; | ||
41 | UnimplementedDeviceState armtmr; | ||
42 | + UnimplementedDeviceState powermgt; | ||
43 | UnimplementedDeviceState cprman; | ||
44 | - UnimplementedDeviceState a2w; | ||
45 | PL011State uart0; | ||
46 | BCM2835AuxState aux; | ||
47 | BCM2835FBState fb; | ||
48 | diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/include/hw/arm/raspi_platform.h | ||
51 | +++ b/include/hw/arm/raspi_platform.h | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */ | ||
54 | #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores | ||
55 | * Doorbells & Mailboxes */ | ||
56 | -#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */ | ||
57 | -#define CM_OFFSET 0x101000 /* Clock Management */ | ||
58 | -#define A2W_OFFSET 0x102000 /* Reset controller */ | ||
59 | +#define PM_OFFSET 0x100000 /* Power Management */ | ||
60 | +#define CPRMAN_OFFSET 0x101000 /* Clock Management */ | ||
61 | #define AVS_OFFSET 0x103000 /* Audio Video Standard */ | ||
62 | #define RNG_OFFSET 0x104000 | ||
63 | #define GPIO_OFFSET 0x200000 | ||
64 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/arm/bcm2835_peripherals.c | ||
67 | +++ b/hw/arm/bcm2835_peripherals.c | ||
68 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
69 | |||
70 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | ||
71 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | ||
72 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); | ||
73 | - create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); | ||
74 | + create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | ||
75 | + create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | ||
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 | -- | ||
80 | 2.20.1 | ||
81 | |||
82 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
2 | 1 | ||
3 | The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a | ||
4 | main oscillator, and several sub-components (PLLs, multiplexers, ...) to | ||
5 | generate the BCM2835 clock tree. | ||
6 | |||
7 | This commit adds a skeleton of the CPRMAN, with a dummy register | ||
8 | read/write implementation. It embeds the main oscillator (xosc) from | ||
9 | which all the clocks will be derived. | ||
10 | |||
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
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> | ||
16 | --- | ||
17 | include/hw/arm/bcm2835_peripherals.h | 3 +- | ||
18 | include/hw/misc/bcm2835_cprman.h | 37 +++++ | ||
19 | include/hw/misc/bcm2835_cprman_internals.h | 24 +++ | ||
20 | hw/arm/bcm2835_peripherals.c | 11 +- | ||
21 | hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++ | ||
22 | hw/misc/meson.build | 1 + | ||
23 | hw/misc/trace-events | 5 + | ||
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 | |||
29 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.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 | ||
52 | index XXXXXXX..XXXXXXX | ||
53 | --- /dev/null | ||
54 | +++ b/include/hw/misc/bcm2835_cprman.h | ||
55 | @@ -XXX,XX +XXX,XX @@ | ||
56 | +/* | ||
57 | + * BCM2835 CPRMAN clock manager | ||
58 | + * | ||
59 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
60 | + * | ||
61 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
62 | + */ | ||
63 | + | ||
64 | +#ifndef HW_MISC_CPRMAN_H | ||
65 | +#define HW_MISC_CPRMAN_H | ||
66 | + | ||
67 | +#include "hw/sysbus.h" | ||
68 | +#include "hw/qdev-clock.h" | ||
69 | + | ||
70 | +#define TYPE_BCM2835_CPRMAN "bcm2835-cprman" | ||
71 | + | ||
72 | +typedef struct BCM2835CprmanState BCM2835CprmanState; | ||
73 | + | ||
74 | +DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | ||
75 | + TYPE_BCM2835_CPRMAN) | ||
76 | + | ||
77 | +#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | ||
78 | + | ||
79 | +struct BCM2835CprmanState { | ||
80 | + /*< private >*/ | ||
81 | + SysBusDevice parent_obj; | ||
82 | + | ||
83 | + /*< public >*/ | ||
84 | + MemoryRegion iomem; | ||
85 | + | ||
86 | + uint32_t regs[CPRMAN_NUM_REGS]; | ||
87 | + uint32_t xosc_freq; | ||
88 | + | ||
89 | + Clock *xosc; | ||
90 | +}; | ||
91 | + | ||
92 | +#endif | ||
93 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
94 | new file mode 100644 | ||
95 | index XXXXXXX..XXXXXXX | ||
96 | --- /dev/null | ||
97 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | +/* | ||
100 | + * BCM2835 CPRMAN clock manager | ||
101 | + * | ||
102 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
103 | + * | ||
104 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
105 | + */ | ||
106 | + | ||
107 | +#ifndef HW_MISC_CPRMAN_INTERNALS_H | ||
108 | +#define HW_MISC_CPRMAN_INTERNALS_H | ||
109 | + | ||
110 | +#include "hw/registerfields.h" | ||
111 | +#include "hw/misc/bcm2835_cprman.h" | ||
112 | + | ||
113 | +/* Register map */ | ||
114 | + | ||
115 | +/* | ||
116 | + * This field is common to all registers. Each register write value must match | ||
117 | + * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
118 | + */ | ||
119 | +FIELD(CPRMAN, PASSWORD, 24, 8) | ||
120 | +#define CPRMAN_PASSWORD 0x5a | ||
121 | + | ||
122 | +#endif | ||
123 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/hw/arm/bcm2835_peripherals.c | ||
126 | +++ b/hw/arm/bcm2835_peripherals.c | ||
127 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | ||
128 | /* DWC2 */ | ||
129 | object_initialize_child(obj, "dwc2", &s->dwc2, TYPE_DWC2_USB); | ||
130 | |||
131 | + /* CPRMAN clock manager */ | ||
132 | + object_initialize_child(obj, "cprman", &s->cprman, TYPE_BCM2835_CPRMAN); | ||
133 | + | ||
134 | object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr", | ||
135 | OBJECT(&s->gpu_bus_mr)); | ||
136 | } | ||
137 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | + /* CPRMAN clock manager */ | ||
142 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) { | ||
143 | + return; | ||
144 | + } | ||
145 | + memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | ||
146 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | ||
147 | + | ||
148 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | ||
149 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | ||
150 | sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic)); | ||
151 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
152 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | ||
153 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | ||
154 | create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | ||
155 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | ||
156 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); | ||
157 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); | ||
158 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); | ||
159 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
160 | new file mode 100644 | ||
161 | index XXXXXXX..XXXXXXX | ||
162 | --- /dev/null | ||
163 | +++ b/hw/misc/bcm2835_cprman.c | ||
164 | @@ -XXX,XX +XXX,XX @@ | ||
165 | +/* | ||
166 | + * BCM2835 CPRMAN clock manager | ||
167 | + * | ||
168 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
169 | + * | ||
170 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
171 | + */ | ||
172 | + | ||
173 | +/* | ||
174 | + * This peripheral is roughly divided into 3 main parts: | ||
175 | + * - the PLLs | ||
176 | + * - the PLL channels | ||
177 | + * - the clock muxes | ||
178 | + * | ||
179 | + * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more | ||
180 | + * channels. Those channel are then connected to the clock muxes. Each mux has | ||
181 | + * multiples sources (usually the xosc, some of the PLL channels and some "test | ||
182 | + * debug" clocks). A mux is configured to select a given source through its | ||
183 | + * control register. Each mux has one output clock that also goes out of the | ||
184 | + * CPRMAN. This output clock usually connects to another peripheral in the SoC | ||
185 | + * (so a given mux is dedicated to a peripheral). | ||
186 | + * | ||
187 | + * At each level (PLL, channel and mux), the clock can be altered through | ||
188 | + * dividers (and multipliers in case of the PLLs), and can be disabled (in this | ||
189 | + * case, the next levels see no clock). | ||
190 | + * | ||
191 | + * This can be sum-up as follows (this is an example and not the actual BCM2835 | ||
192 | + * clock tree): | ||
193 | + * | ||
194 | + * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals | ||
195 | + * | |->[PLL channel] muxes takes [mux] | ||
196 | + * | \->[PLL channel] inputs from [mux] | ||
197 | + * | some channels [mux] | ||
198 | + * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux] | ||
199 | + * | \->[PLL channel] ...-->[mux] | ||
200 | + * | [mux] | ||
201 | + * \-->[PLL]--->[PLL channel] [mux] | ||
202 | + * | ||
203 | + * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
204 | + * tree configuration. | ||
205 | + */ | ||
206 | + | ||
207 | +#include "qemu/osdep.h" | ||
208 | +#include "qemu/log.h" | ||
209 | +#include "migration/vmstate.h" | ||
210 | +#include "hw/qdev-properties.h" | ||
211 | +#include "hw/misc/bcm2835_cprman.h" | ||
212 | +#include "hw/misc/bcm2835_cprman_internals.h" | ||
213 | +#include "trace.h" | ||
214 | + | ||
215 | +/* CPRMAN "top level" model */ | ||
216 | + | ||
217 | +static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
218 | + unsigned size) | ||
219 | +{ | ||
220 | + BCM2835CprmanState *s = CPRMAN(opaque); | ||
221 | + uint64_t r = 0; | ||
222 | + size_t idx = offset / sizeof(uint32_t); | ||
223 | + | ||
224 | + switch (idx) { | ||
225 | + default: | ||
226 | + r = s->regs[idx]; | ||
227 | + } | ||
228 | + | ||
229 | + trace_bcm2835_cprman_read(offset, r); | ||
230 | + return r; | ||
231 | +} | ||
232 | + | ||
233 | +static void cprman_write(void *opaque, hwaddr offset, | ||
234 | + uint64_t value, unsigned size) | ||
235 | +{ | ||
236 | + BCM2835CprmanState *s = CPRMAN(opaque); | ||
237 | + size_t idx = offset / sizeof(uint32_t); | ||
238 | + | ||
239 | + if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) { | ||
240 | + trace_bcm2835_cprman_write_invalid_magic(offset, value); | ||
241 | + return; | ||
242 | + } | ||
243 | + | ||
244 | + value &= ~R_CPRMAN_PASSWORD_MASK; | ||
245 | + | ||
246 | + trace_bcm2835_cprman_write(offset, value); | ||
247 | + s->regs[idx] = value; | ||
248 | + | ||
249 | +} | ||
250 | + | ||
251 | +static const MemoryRegionOps cprman_ops = { | ||
252 | + .read = cprman_read, | ||
253 | + .write = cprman_write, | ||
254 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
255 | + .valid = { | ||
256 | + /* | ||
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, | ||
267 | + }, | ||
268 | +}; | ||
269 | + | ||
270 | +static void cprman_reset(DeviceState *dev) | ||
271 | +{ | ||
272 | + BCM2835CprmanState *s = CPRMAN(dev); | ||
273 | + | ||
274 | + memset(s->regs, 0, sizeof(s->regs)); | ||
275 | + | ||
276 | + clock_update_hz(s->xosc, s->xosc_freq); | ||
277 | +} | ||
278 | + | ||
279 | +static void cprman_init(Object *obj) | ||
280 | +{ | ||
281 | + BCM2835CprmanState *s = CPRMAN(obj); | ||
282 | + | ||
283 | + s->xosc = clock_new(obj, "xosc"); | ||
284 | + | ||
285 | + memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
286 | + s, "bcm2835-cprman", 0x2000); | ||
287 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
288 | +} | ||
289 | + | ||
290 | +static const VMStateDescription cprman_vmstate = { | ||
291 | + .name = TYPE_BCM2835_CPRMAN, | ||
292 | + .version_id = 1, | ||
293 | + .minimum_version_id = 1, | ||
294 | + .fields = (VMStateField[]) { | ||
295 | + VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS), | ||
296 | + VMSTATE_END_OF_LIST() | ||
297 | + } | ||
298 | +}; | ||
299 | + | ||
300 | +static Property cprman_properties[] = { | ||
301 | + DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), | ||
302 | + DEFINE_PROP_END_OF_LIST() | ||
303 | +}; | ||
304 | + | ||
305 | +static void cprman_class_init(ObjectClass *klass, void *data) | ||
306 | +{ | ||
307 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
308 | + | ||
309 | + dc->reset = cprman_reset; | ||
310 | + dc->vmsd = &cprman_vmstate; | ||
311 | + device_class_set_props(dc, cprman_properties); | ||
312 | +} | ||
313 | + | ||
314 | +static const TypeInfo cprman_info = { | ||
315 | + .name = TYPE_BCM2835_CPRMAN, | ||
316 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
317 | + .instance_size = sizeof(BCM2835CprmanState), | ||
318 | + .class_init = cprman_class_init, | ||
319 | + .instance_init = cprman_init, | ||
320 | +}; | ||
321 | + | ||
322 | +static void cprman_register_types(void) | ||
323 | +{ | ||
324 | + type_register_static(&cprman_info); | ||
325 | +} | ||
326 | + | ||
327 | +type_init(cprman_register_types); | ||
328 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
329 | index XXXXXXX..XXXXXXX 100644 | ||
330 | --- a/hw/misc/meson.build | ||
331 | +++ b/hw/misc/meson.build | ||
332 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( | ||
333 | 'bcm2835_property.c', | ||
334 | 'bcm2835_rng.c', | ||
335 | 'bcm2835_thermal.c', | ||
336 | + 'bcm2835_cprman.c', | ||
337 | )) | ||
338 | softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) | ||
339 | softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c')) | ||
340 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/hw/misc/trace-events | ||
343 | +++ b/hw/misc/trace-events | ||
344 | @@ -XXX,XX +XXX,XX @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 | ||
345 | # pca9552.c | ||
346 | pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" | ||
347 | pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" | ||
348 | + | ||
349 | +# bcm2835_cprman.c | ||
350 | +bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
351 | +bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
352 | +bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
353 | -- | ||
354 | 2.20.1 | ||
355 | |||
356 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
2 | 1 | ||
3 | The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and | ||
4 | a divider. The prescaler doubles the parent (xosc) frequency, then the | ||
5 | multiplier/divider are applied. The multiplier has an integer and a | ||
6 | fractional part. | ||
7 | |||
8 | This commit also implements the CPRMAN CM_LOCK register. This register | ||
9 | reports which PLL is currently locked. We consider a PLL has being | ||
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> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
16 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | --- | ||
19 | include/hw/misc/bcm2835_cprman_internals.h | 8 +++ | ||
20 | hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- | ||
21 | 2 files changed, 71 insertions(+), 1 deletion(-) | ||
22 | |||
23 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
26 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
27 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) | ||
28 | REG32(A2W_PLLH_FRAC, 0x1260) | ||
29 | REG32(A2W_PLLB_FRAC, 0x12e0) | ||
30 | |||
31 | +/* misc registers */ | ||
32 | +REG32(CM_LOCK, 0x114) | ||
33 | + FIELD(CM_LOCK, FLOCKH, 12, 1) | ||
34 | + FIELD(CM_LOCK, FLOCKD, 11, 1) | ||
35 | + FIELD(CM_LOCK, FLOCKC, 10, 1) | ||
36 | + FIELD(CM_LOCK, FLOCKB, 9, 1) | ||
37 | + FIELD(CM_LOCK, FLOCKA, 8, 1) | ||
38 | + | ||
39 | /* | ||
40 | * This field is common to all registers. Each register write value must match | ||
41 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
42 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/misc/bcm2835_cprman.c | ||
45 | +++ b/hw/misc/bcm2835_cprman.c | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | |||
48 | /* PLL */ | ||
49 | |||
50 | +static bool pll_is_locked(const CprmanPllState *pll) | ||
51 | +{ | ||
52 | + return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) | ||
53 | + && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); | ||
54 | +} | ||
55 | + | ||
56 | static void pll_update(CprmanPllState *pll) | ||
57 | { | ||
58 | - clock_update(pll->out, 0); | ||
59 | + uint64_t freq, ndiv, fdiv, pdiv; | ||
60 | + | ||
61 | + if (!pll_is_locked(pll)) { | ||
62 | + clock_update(pll->out, 0); | ||
63 | + return; | ||
64 | + } | ||
65 | + | ||
66 | + pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); | ||
67 | + | ||
68 | + if (!pdiv) { | ||
69 | + clock_update(pll->out, 0); | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
73 | + ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); | ||
74 | + fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC); | ||
75 | + | ||
76 | + if (pll->reg_a2w_ana[1] & pll->prediv_mask) { | ||
77 | + /* The prescaler doubles the parent frequency */ | ||
78 | + ndiv *= 2; | ||
79 | + fdiv *= 2; | ||
80 | + } | ||
81 | + | ||
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 | +} | ||
118 | + | ||
119 | static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
120 | unsigned size) | ||
121 | { | ||
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 | -- | ||
134 | 2.20.1 | ||
135 | |||
136 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | PLLs are composed of multiple channels. Each channel outputs one clock | 3 | A device shouldn't access its parent object which is QOM internal. |
4 | signal. They are modeled as one device taking the PLL generated clock as | 4 | Instead it should use type cast for this purporse. This patch fixes this |
5 | input, and outputting a new clock. | 5 | issue for all NPCM7XX Devices. |
6 | 6 | ||
7 | A channel shares the CM register with its parent PLL, and has its own | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
8 | A2W_CTRL register. A write to the CM register will trigger an update of | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | the PLL and all its channels, while a write to an A2W_CTRL channel | 9 | Message-id: 20210108190945.949196-7-wuhaotsh@google.com |
10 | register will update the required channel only. | ||
11 | |||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
15 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 11 | --- |
18 | include/hw/misc/bcm2835_cprman.h | 44 ++++++ | 12 | hw/arm/npcm7xx_boards.c | 2 +- |
19 | include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ | 13 | hw/mem/npcm7xx_mc.c | 2 +- |
20 | hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- | 14 | hw/misc/npcm7xx_clk.c | 2 +- |
21 | 3 files changed, 337 insertions(+), 8 deletions(-) | 15 | hw/misc/npcm7xx_gcr.c | 2 +- |
16 | hw/misc/npcm7xx_rng.c | 2 +- | ||
17 | hw/nvram/npcm7xx_otp.c | 2 +- | ||
18 | hw/ssi/npcm7xx_fiu.c | 2 +- | ||
19 | 7 files changed, 7 insertions(+), 7 deletions(-) | ||
22 | 20 | ||
23 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 21 | diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c |
24 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/misc/bcm2835_cprman.h | 23 | --- a/hw/arm/npcm7xx_boards.c |
26 | +++ b/include/hw/misc/bcm2835_cprman.h | 24 | +++ b/hw/arm/npcm7xx_boards.c |
27 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll { | 25 | @@ -XXX,XX +XXX,XX @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, |
28 | CPRMAN_NUM_PLL | 26 | uint32_t hw_straps) |
29 | } CprmanPll; | 27 | { |
30 | 28 | NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_GET_CLASS(machine); | |
31 | +typedef enum CprmanPllChannel { | 29 | - MachineClass *mc = &nmc->parent; |
32 | + CPRMAN_PLLA_CHANNEL_DSI0 = 0, | 30 | + MachineClass *mc = MACHINE_CLASS(nmc); |
33 | + CPRMAN_PLLA_CHANNEL_CORE, | 31 | Object *obj; |
34 | + CPRMAN_PLLA_CHANNEL_PER, | 32 | |
35 | + CPRMAN_PLLA_CHANNEL_CCP2, | 33 | if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) { |
36 | + | 34 | diff --git a/hw/mem/npcm7xx_mc.c b/hw/mem/npcm7xx_mc.c |
37 | + CPRMAN_PLLC_CHANNEL_CORE2, | ||
38 | + CPRMAN_PLLC_CHANNEL_CORE1, | ||
39 | + CPRMAN_PLLC_CHANNEL_PER, | ||
40 | + CPRMAN_PLLC_CHANNEL_CORE0, | ||
41 | + | ||
42 | + CPRMAN_PLLD_CHANNEL_DSI0, | ||
43 | + CPRMAN_PLLD_CHANNEL_CORE, | ||
44 | + CPRMAN_PLLD_CHANNEL_PER, | ||
45 | + CPRMAN_PLLD_CHANNEL_DSI1, | ||
46 | + | ||
47 | + CPRMAN_PLLH_CHANNEL_AUX, | ||
48 | + CPRMAN_PLLH_CHANNEL_RCAL, | ||
49 | + CPRMAN_PLLH_CHANNEL_PIX, | ||
50 | + | ||
51 | + CPRMAN_PLLB_CHANNEL_ARM, | ||
52 | + | ||
53 | + CPRMAN_NUM_PLL_CHANNEL, | ||
54 | +} CprmanPllChannel; | ||
55 | + | ||
56 | typedef struct CprmanPllState { | ||
57 | /*< private >*/ | ||
58 | DeviceState parent_obj; | ||
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 | 35 | index XXXXXXX..XXXXXXX 100644 |
94 | --- a/include/hw/misc/bcm2835_cprman_internals.h | 36 | --- a/hw/mem/npcm7xx_mc.c |
95 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | 37 | +++ b/hw/mem/npcm7xx_mc.c |
96 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_mc_realize(DeviceState *dev, Error **errp) |
97 | #include "hw/misc/bcm2835_cprman.h" | 39 | |
98 | 40 | memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs", | |
99 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | 41 | NPCM7XX_MC_REGS_SIZE); |
100 | +#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | 42 | - sysbus_init_mmio(&s->parent, &s->mmio); |
101 | 43 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio); | |
102 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, | ||
103 | TYPE_CPRMAN_PLL) | ||
104 | +DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, | ||
105 | + TYPE_CPRMAN_PLL_CHANNEL) | ||
106 | |||
107 | /* Register map */ | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) | ||
110 | REG32(A2W_PLLH_FRAC, 0x1260) | ||
111 | REG32(A2W_PLLB_FRAC, 0x12e0) | ||
112 | |||
113 | +/* PLL channels */ | ||
114 | +REG32(A2W_PLLA_DSI0, 0x1300) | ||
115 | + FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8) | ||
116 | + FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1) | ||
117 | +REG32(A2W_PLLA_CORE, 0x1400) | ||
118 | +REG32(A2W_PLLA_PER, 0x1500) | ||
119 | +REG32(A2W_PLLA_CCP2, 0x1600) | ||
120 | + | ||
121 | +REG32(A2W_PLLC_CORE2, 0x1320) | ||
122 | +REG32(A2W_PLLC_CORE1, 0x1420) | ||
123 | +REG32(A2W_PLLC_PER, 0x1520) | ||
124 | +REG32(A2W_PLLC_CORE0, 0x1620) | ||
125 | + | ||
126 | +REG32(A2W_PLLD_DSI0, 0x1340) | ||
127 | +REG32(A2W_PLLD_CORE, 0x1440) | ||
128 | +REG32(A2W_PLLD_PER, 0x1540) | ||
129 | +REG32(A2W_PLLD_DSI1, 0x1640) | ||
130 | + | ||
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 | } | 44 | } |
144 | 45 | ||
145 | + | 46 | static void npcm7xx_mc_class_init(ObjectClass *klass, void *data) |
146 | +/* PLL channel init info */ | 47 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c |
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 | +{ | ||
254 | + channel->id = id; | ||
255 | + channel->parent = PLL_CHANNEL_INIT_INFO[id].parent; | ||
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 | +} | ||
262 | + | ||
263 | #endif | ||
264 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
265 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
266 | --- a/hw/misc/bcm2835_cprman.c | 49 | --- a/hw/misc/npcm7xx_clk.c |
267 | +++ b/hw/misc/bcm2835_cprman.c | 50 | +++ b/hw/misc/npcm7xx_clk.c |
268 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { | 51 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj) |
269 | }; | 52 | |
270 | 53 | memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s, | |
271 | 54 | TYPE_NPCM7XX_CLK, 4 * KiB); | |
272 | +/* PLL channel */ | 55 | - sysbus_init_mmio(&s->parent, &s->iomem); |
273 | + | 56 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); |
274 | +static void pll_channel_update(CprmanPllChannelState *channel) | ||
275 | +{ | ||
276 | + clock_update(channel->out, 0); | ||
277 | +} | ||
278 | + | ||
279 | +/* Update a PLL and all its channels */ | ||
280 | +static void pll_update_all_channels(BCM2835CprmanState *s, | ||
281 | + CprmanPllState *pll) | ||
282 | +{ | ||
283 | + size_t i; | ||
284 | + | ||
285 | + pll_update(pll); | ||
286 | + | ||
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 | } | 57 | } |
341 | 58 | ||
342 | -#define CASE_PLL_REGS(pll_) \ | 59 | static int npcm7xx_clk_post_load(void *opaque, int version_id) |
343 | - case R_CM_ ## pll_: \ | 60 | diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c |
344 | +static inline void update_pll_and_channels_from_cm(BCM2835CprmanState *s, | 61 | index XXXXXXX..XXXXXXX 100644 |
345 | + size_t idx) | 62 | --- a/hw/misc/npcm7xx_gcr.c |
346 | +{ | 63 | +++ b/hw/misc/npcm7xx_gcr.c |
347 | + size_t i; | 64 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_gcr_init(Object *obj) |
348 | + | 65 | |
349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | 66 | memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s, |
350 | + if (PLL_INIT_INFO[i].cm_offset == idx) { | 67 | TYPE_NPCM7XX_GCR, 4 * KiB); |
351 | + pll_update_all_channels(s, &s->plls[i]); | 68 | - sysbus_init_mmio(&s->parent, &s->iomem); |
352 | + return; | 69 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); |
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 | } | 70 | } |
431 | 71 | ||
432 | -#undef CASE_PLL_REGS | 72 | static const VMStateDescription vmstate_npcm7xx_gcr = { |
433 | +#undef CASE_PLL_A2W_REGS | 73 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c |
434 | 74 | index XXXXXXX..XXXXXXX 100644 | |
435 | static const MemoryRegionOps cprman_ops = { | 75 | --- a/hw/misc/npcm7xx_rng.c |
436 | .read = cprman_read, | 76 | +++ b/hw/misc/npcm7xx_rng.c |
437 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | 77 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_rng_init(Object *obj) |
438 | device_cold_reset(DEVICE(&s->plls[i])); | 78 | |
439 | } | 79 | memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs", |
440 | 80 | NPCM7XX_RNG_REGS_SIZE); | |
441 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | 81 | - sysbus_init_mmio(&s->parent, &s->iomem); |
442 | + device_cold_reset(DEVICE(&s->channels[i])); | 82 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); |
443 | + } | ||
444 | + | ||
445 | clock_update_hz(s->xosc, s->xosc_freq); | ||
446 | } | 83 | } |
447 | 84 | ||
448 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | 85 | static const VMStateDescription vmstate_npcm7xx_rng = { |
449 | set_pll_init_info(s, &s->plls[i], i); | 86 | diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c |
450 | } | 87 | index XXXXXXX..XXXXXXX 100644 |
451 | 88 | --- a/hw/nvram/npcm7xx_otp.c | |
452 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | 89 | +++ b/hw/nvram/npcm7xx_otp.c |
453 | + object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name, | 90 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_otp_realize(DeviceState *dev, Error **errp) |
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 | } | ||
465 | } | ||
466 | + | ||
467 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
468 | + CprmanPllChannelState *channel = &s->channels[i]; | ||
469 | + CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent; | ||
470 | + Clock *parent_clk = s->plls[parent].out; | ||
471 | + | ||
472 | + clock_set_source(channel->pll_in, parent_clk); | ||
473 | + | ||
474 | + if (!qdev_realize(DEVICE(channel), NULL, errp)) { | ||
475 | + return; | ||
476 | + } | ||
477 | + } | ||
478 | } | ||
479 | |||
480 | static const VMStateDescription cprman_vmstate = { | ||
481 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
482 | { | 91 | { |
483 | type_register_static(&cprman_info); | 92 | NPCM7xxOTPClass *oc = NPCM7XX_OTP_GET_CLASS(dev); |
484 | type_register_static(&cprman_pll_info); | 93 | NPCM7xxOTPState *s = NPCM7XX_OTP(dev); |
485 | + type_register_static(&cprman_pll_channel_info); | 94 | - SysBusDevice *sbd = &s->parent; |
486 | } | 95 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
487 | 96 | ||
488 | type_init(cprman_register_types); | 97 | memset(s->array, 0, sizeof(s->array)); |
98 | |||
99 | diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/hw/ssi/npcm7xx_fiu.c | ||
102 | +++ b/hw/ssi/npcm7xx_fiu.c | ||
103 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_fiu_hold_reset(Object *obj) | ||
104 | static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp) | ||
105 | { | ||
106 | NPCM7xxFIUState *s = NPCM7XX_FIU(dev); | ||
107 | - SysBusDevice *sbd = &s->parent; | ||
108 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
109 | int i; | ||
110 | |||
111 | if (s->cs_count <= 0) { | ||
489 | -- | 112 | -- |
490 | 2.20.1 | 113 | 2.20.1 |
491 | 114 | ||
492 | 115 | diff view generated by jsdifflib |
1 | From: Luc Michel <luc@lmichel.fr> | 1 | From: Roman Bolshakov <r.bolshakov@yadro.com> |
---|---|---|---|
2 | 2 | ||
3 | The clock multiplexers are the last clock stage in the CPRMAN. Each mux | 3 | ui/cocoa.m:1188:44: warning: 'openFile:' is deprecated: first deprecated in macOS 11.0 - Use -[NSWorkspace openURL:] instead. |
4 | outputs one clock signal that goes out of the CPRMAN to the SoC | 4 | [-Wdeprecated-declarations] |
5 | peripherals. | 5 | if ([[NSWorkspace sharedWorkspace] openFile: full_file_path] == YES) { |
6 | ^ | ||
7 | /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSWorkspace.h:350:1: note: | ||
8 | 'openFile:' has been explicitly marked deprecated here | ||
9 | - (BOOL)openFile:(NSString *)fullPath API_DEPRECATED("Use -[NSWorkspace openURL:] instead.", macos(10.0, 11.0)); | ||
10 | ^ | ||
6 | 11 | ||
7 | Each mux has at most 10 sources. The sources 0 to 3 are common to all | 12 | Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> |
8 | muxes. They are: | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | 0. ground (no clock signal) | 14 | Message-id: 20210102150718.47618-1-r.bolshakov@yadro.com |
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> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
41 | --- | 16 | --- |
42 | include/hw/misc/bcm2835_cprman.h | 85 +++++ | 17 | ui/cocoa.m | 5 ++++- |
43 | include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ | 18 | 1 file changed, 4 insertions(+), 1 deletion(-) |
44 | hw/misc/bcm2835_cprman.c | 151 ++++++++ | ||
45 | 3 files changed, 658 insertions(+) | ||
46 | 19 | ||
47 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | 20 | diff --git a/ui/cocoa.m b/ui/cocoa.m |
48 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/include/hw/misc/bcm2835_cprman.h | 22 | --- a/ui/cocoa.m |
50 | +++ b/include/hw/misc/bcm2835_cprman.h | 23 | +++ b/ui/cocoa.m |
51 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel { | 24 | @@ -XXX,XX +XXX,XX @@ QemuCocoaView *cocoaView; |
52 | CPRMAN_PLLB_CHANNEL_ARM, | 25 | /* Where to look for local files */ |
53 | 26 | NSString *path_array[] = {@"../share/doc/qemu/", @"../doc/qemu/", @"docs/"}; | |
54 | CPRMAN_NUM_PLL_CHANNEL, | 27 | NSString *full_file_path; |
55 | + | 28 | + NSURL *full_file_url; |
56 | + /* Special values used when connecting clock sources to clocks */ | 29 | |
57 | + CPRMAN_CLOCK_SRC_NORMAL = -1, | 30 | /* iterate thru the possible paths until the file is found */ |
58 | + CPRMAN_CLOCK_SRC_FORCE_GROUND = -2, | 31 | int index; |
59 | + CPRMAN_CLOCK_SRC_DSI0HSCK = -3, | 32 | @@ -XXX,XX +XXX,XX @@ QemuCocoaView *cocoaView; |
60 | } CprmanPllChannel; | 33 | full_file_path = [full_file_path stringByDeletingLastPathComponent]; |
61 | 34 | full_file_path = [NSString stringWithFormat: @"%@/%@%@", full_file_path, | |
62 | +typedef enum CprmanClockMux { | 35 | path_array[index], filename]; |
63 | + CPRMAN_CLOCK_GNRIC, | 36 | - if ([[NSWorkspace sharedWorkspace] openFile: full_file_path] == YES) { |
64 | + CPRMAN_CLOCK_VPU, | 37 | + full_file_url = [NSURL fileURLWithPath: full_file_path |
65 | + CPRMAN_CLOCK_SYS, | 38 | + isDirectory: false]; |
66 | + CPRMAN_CLOCK_PERIA, | 39 | + if ([[NSWorkspace sharedWorkspace] openURL: full_file_url] == YES) { |
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 | + } | ||
308 | + | ||
309 | +/* Only the oscillator and the two test debug clocks */ | ||
310 | +#define SRC_MAPPING_INFO_xosc \ | ||
311 | + .src_mapping = { \ | ||
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 | + } | ||
323 | + | ||
324 | +/* All the PLL "core" channels */ | ||
325 | +#define SRC_MAPPING_INFO_core \ | ||
326 | + .src_mapping = { \ | ||
327 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
328 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
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 | + } | ||
338 | + | ||
339 | +/* All the PLL "per" channels */ | ||
340 | +#define SRC_MAPPING_INFO_periph \ | ||
341 | + .src_mapping = { \ | ||
342 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
343 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
344 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
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; | 40 | return; |
809 | } | 41 | } |
810 | } | 42 | } |
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 | -- | 43 | -- |
833 | 2.20.1 | 44 | 2.20.1 |
834 | 45 | ||
835 | 46 | diff view generated by jsdifflib |