[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/35] hw/misc/mps2-scc: Factor out which-board conditionals
From: |
Peter Maydell |
Subject: |
[PULL 28/35] hw/misc/mps2-scc: Factor out which-board conditionals |
Date: |
Thu, 15 Feb 2024 17:35:31 +0000 |
The MPS SCC device has a lot of different flavours for the various
different MPS FPGA images, which look mostly similar but have
differences in how particular registers are handled. Currently we
deal with this with a lot of open-coded checks on scc_partno(), but
as we add more board types this is getting a bit hard to read.
Factor out the conditions into some functions which we can
give more descriptive names to.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240206132931.38376-7-peter.maydell@linaro.org
---
hw/misc/mps2-scc.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
index 6c1b1cd3795..02a80bacd71 100644
--- a/hw/misc/mps2-scc.c
+++ b/hw/misc/mps2-scc.c
@@ -59,6 +59,30 @@ static int scc_partno(MPS2SCC *s)
return extract32(s->id, 4, 8);
}
+/* Is CFG_REG2 present? */
+static bool have_cfg2(MPS2SCC *s)
+{
+ return scc_partno(s) == 0x524 || scc_partno(s) == 0x547;
+}
+
+/* Is CFG_REG3 present? */
+static bool have_cfg3(MPS2SCC *s)
+{
+ return scc_partno(s) != 0x524 && scc_partno(s) != 0x547;
+}
+
+/* Is CFG_REG5 present? */
+static bool have_cfg5(MPS2SCC *s)
+{
+ return scc_partno(s) == 0x524 || scc_partno(s) == 0x547;
+}
+
+/* Is CFG_REG6 present? */
+static bool have_cfg6(MPS2SCC *s)
+{
+ return scc_partno(s) == 0x524;
+}
+
/* Handle a write via the SYS_CFG channel to the specified function/device.
* Return false on error (reported to guest via SYS_CFGCTRL ERROR bit).
*/
@@ -111,15 +135,13 @@ static uint64_t mps2_scc_read(void *opaque, hwaddr
offset, unsigned size)
r = s->cfg1;
break;
case A_CFG2:
- if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) {
- /* CFG2 reserved on other boards */
+ if (!have_cfg2(s)) {
goto bad_offset;
}
r = s->cfg2;
break;
case A_CFG3:
- if (scc_partno(s) == 0x524 || scc_partno(s) == 0x547) {
- /* CFG3 reserved on AN524 */
+ if (!have_cfg3(s)) {
goto bad_offset;
}
/* These are user-settable DIP switches on the board. We don't
@@ -131,15 +153,13 @@ static uint64_t mps2_scc_read(void *opaque, hwaddr
offset, unsigned size)
r = s->cfg4;
break;
case A_CFG5:
- if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) {
- /* CFG5 reserved on other boards */
+ if (!have_cfg5(s)) {
goto bad_offset;
}
r = s->cfg5;
break;
case A_CFG6:
- if (scc_partno(s) != 0x524) {
- /* CFG6 reserved on other boards */
+ if (!have_cfg6(s)) {
goto bad_offset;
}
r = s->cfg6;
@@ -202,24 +222,21 @@ static void mps2_scc_write(void *opaque, hwaddr offset,
uint64_t value,
}
break;
case A_CFG2:
- if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) {
- /* CFG2 reserved on other boards */
+ if (!have_cfg2(s)) {
goto bad_offset;
}
/* AN524: QSPI Select signal */
s->cfg2 = value;
break;
case A_CFG5:
- if (scc_partno(s) != 0x524 && scc_partno(s) != 0x547) {
- /* CFG5 reserved on other boards */
+ if (!have_cfg5(s)) {
goto bad_offset;
}
/* AN524: ACLK frequency in Hz */
s->cfg5 = value;
break;
case A_CFG6:
- if (scc_partno(s) != 0x524) {
- /* CFG6 reserved on other boards */
+ if (!have_cfg6(s)) {
goto bad_offset;
}
/* AN524: Clock divider for BRAM */
--
2.34.1
- [PULL 09/35] hw/block/tc58128: Don't emit deprecation warning under qtest, (continued)
- [PULL 09/35] hw/block/tc58128: Don't emit deprecation warning under qtest, Peter Maydell, 2024/02/15
- [PULL 17/35] tests/qtest: Fix GMAC test to run on a machine in upstream QEMU, Peter Maydell, 2024/02/15
- [PULL 12/35] hw/arm/virt: Wire up non-secure EL2 virtual timer IRQ, Peter Maydell, 2024/02/15
- [PULL 15/35] tests/qtest/npcm7xx_emc-test: Connect all NICs to a backend, Peter Maydell, 2024/02/15
- [PULL 19/35] hw/arm/stellaris: Convert ADC controller to Resettable interface, Peter Maydell, 2024/02/15
- [PULL 21/35] hw/arm/stellaris: Add missing QOM 'machine' parent, Peter Maydell, 2024/02/15
- [PULL 23/35] target/arm: Use new CBAR encoding for all v8 CPUs, not all aarch64 CPUs, Peter Maydell, 2024/02/15
- [PULL 29/35] hw/misc/mps2-scc: Make changes needed for AN536 FPGA image, Peter Maydell, 2024/02/15
- [PULL 07/35] target/arm: Fix SVE/SME gross MTE suppression checks, Peter Maydell, 2024/02/15
- [PULL 26/35] target/arm: Allow access to SPSR_hyp from hyp mode, Peter Maydell, 2024/02/15
- [PULL 28/35] hw/misc/mps2-scc: Factor out which-board conditionals,
Peter Maydell <=
- [PULL 25/35] target/arm: Add Cortex-R52 IMPDEF sysregs, Peter Maydell, 2024/02/15
- [PULL 34/35] hw/arm/mps3r: Add remaining devices, Peter Maydell, 2024/02/15
- [PULL 30/35] hw/arm/mps3r: Initial skeleton for mps3-an536 board, Peter Maydell, 2024/02/15
- [PULL 03/35] target/arm: Fix nregs computation in do_{ld,st}_zpa, Peter Maydell, 2024/02/15
- [PULL 06/35] target/arm: Handle mte in do_ldrq, do_ldro, Peter Maydell, 2024/02/15
- [PULL 31/35] hw/arm/mps3r: Add CPUs, GIC, and per-CPU RAM, Peter Maydell, 2024/02/15
- [PULL 35/35] docs: Add documentation for the mps3-an536 board, Peter Maydell, 2024/02/15
- [PULL 20/35] hw/arm/stellaris: Convert I2C controller to Resettable interface, Peter Maydell, 2024/02/15
- [PULL 32/35] hw/arm/mps3r: Add UARTs, Peter Maydell, 2024/02/15
- [PULL 33/35] hw/arm/mps3r: Add GPIO, watchdog, dual-timer, I2C devices, Peter Maydell, 2024/02/15