[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 31/38] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce
From: |
Peter Maydell |
Subject: |
[PULL 31/38] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting |
Date: |
Thu, 20 Jan 2022 12:36:23 +0000 |
Refactor process_its_cmd() so that it consistently uses
the structure
do thing;
if (error condition) {
return early;
}
do next thing;
rather than doing some of the work nested inside if (not error)
code blocks.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20220111171048.3545974-8-peter.maydell@linaro.org
---
hw/intc/arm_gicv3_its.c | 103 +++++++++++++++++++---------------------
1 file changed, 50 insertions(+), 53 deletions(-)
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
index 0929116c0fe..5dc6846fe3f 100644
--- a/hw/intc/arm_gicv3_its.c
+++ b/hw/intc/arm_gicv3_its.c
@@ -273,79 +273,76 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s,
uint64_t value,
}
dte_valid = FIELD_EX64(dte, DTE, VALID);
- if (dte_valid) {
- num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
-
- ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
-
- if (res != MEMTX_OK) {
- return CMD_STALL;
- }
-
- if (ite_valid) {
- cte_valid = get_cte(s, icid, &cte, &res);
- }
-
- if (res != MEMTX_OK) {
- return CMD_STALL;
- }
- } else {
+ if (!dte_valid) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: invalid command attributes: "
- "invalid dte: %"PRIx64" for %d (MEM_TX: %d)\n",
- __func__, dte, devid, res);
+ "invalid dte: %"PRIx64" for %d\n",
+ __func__, dte, devid);
return CMD_CONTINUE;
}
+ num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
+
+ ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
+ if (res != MEMTX_OK) {
+ return CMD_STALL;
+ }
+
+ if (!ite_valid) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: invalid command attributes: invalid ITE\n",
+ __func__);
+ return CMD_CONTINUE;
+ }
+
+ cte_valid = get_cte(s, icid, &cte, &res);
+ if (res != MEMTX_OK) {
+ return CMD_STALL;
+ }
+ if (!cte_valid) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: invalid command attributes: "
+ "invalid cte: %"PRIx64"\n",
+ __func__, cte);
+ return CMD_CONTINUE;
+ }
- /*
- * In this implementation, in case of guest errors we ignore the
- * command and move onto the next command in the queue.
- */
if (devid >= s->dt.num_ids) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: invalid command attributes: devid %d>=%d",
__func__, devid, s->dt.num_ids);
return CMD_CONTINUE;
- } else if (!dte_valid || !ite_valid || !cte_valid) {
- qemu_log_mask(LOG_GUEST_ERROR,
- "%s: invalid command attributes: "
- "dte: %s, ite: %s, cte: %s\n",
- __func__,
- dte_valid ? "valid" : "invalid",
- ite_valid ? "valid" : "invalid",
- cte_valid ? "valid" : "invalid");
- return CMD_CONTINUE;
- } else if (eventid >= num_eventids) {
+ }
+ if (eventid >= num_eventids) {
qemu_log_mask(LOG_GUEST_ERROR,
"%s: invalid command attributes: eventid %d >= %"
PRId64 "\n",
__func__, eventid, num_eventids);
return CMD_CONTINUE;
- } else {
- /*
- * Current implementation only supports rdbase == procnum
- * Hence rdbase physical address is ignored
- */
- rdbase = FIELD_EX64(cte, CTE, RDBASE);
+ }
- if (rdbase >= s->gicv3->num_cpu) {
- return CMD_CONTINUE;
- }
+ /*
+ * Current implementation only supports rdbase == procnum
+ * Hence rdbase physical address is ignored
+ */
+ rdbase = FIELD_EX64(cte, CTE, RDBASE);
- if ((cmd == CLEAR) || (cmd == DISCARD)) {
- gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0);
- } else {
- gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1);
- }
-
- if (cmd == DISCARD) {
- IteEntry ite = {};
- /* remove mapping from interrupt translation table */
- return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
- }
+ if (rdbase >= s->gicv3->num_cpu) {
return CMD_CONTINUE;
}
+
+ if ((cmd == CLEAR) || (cmd == DISCARD)) {
+ gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0);
+ } else {
+ gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1);
+ }
+
+ if (cmd == DISCARD) {
+ IteEntry ite = {};
+ /* remove mapping from interrupt translation table */
+ return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
+ }
+ return CMD_CONTINUE;
}
static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
--
2.25.1
- [PULL 09/38] hw/acpi/aml-build: Support cluster level in PPTT generation, (continued)
- [PULL 09/38] hw/acpi/aml-build: Support cluster level in PPTT generation, Peter Maydell, 2022/01/20
- [PULL 17/38] hw/arm/virt: Add a control for the the highmem redistributors, Peter Maydell, 2022/01/20
- [PULL 08/38] tests/acpi/bios-tables-test: Allow changes to virt/PPTT file, Peter Maydell, 2022/01/20
- [PULL 02/38] hw: Move MARVELL_88W8618 Kconfig from audio/ to arm/, Peter Maydell, 2022/01/20
- [PULL 12/38] virtio-mem: Correct default THP size for ARM64, Peter Maydell, 2022/01/20
- [PULL 14/38] hw/intc/arm_gic: Implement read of GICC_IIDR, Peter Maydell, 2022/01/20
- [PULL 23/38] hw/misc/aspeed_i3c.c: Introduce a dummy AST2600 I3C model., Peter Maydell, 2022/01/20
- [PULL 35/38] hw/intc/arm_gicv3_its: Factor out "find address of table entry" code, Peter Maydell, 2022/01/20
- [PULL 18/38] hw/arm/virt: Honor highmem setting when computing the memory map, Peter Maydell, 2022/01/20
- [PULL 34/38] hw/intc/arm_gicv3_its: Fix return codes in process_mapd(), Peter Maydell, 2022/01/20
- [PULL 31/38] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting,
Peter Maydell <=
- [PULL 20/38] hw/arm/virt: Disable highmem devices that don't fit in the PA range, Peter Maydell, 2022/01/20
- [PULL 22/38] hw/arm: kudo add lm75s behind bus 1 switch at 75, Peter Maydell, 2022/01/20
- [PULL 29/38] hw/intc/arm_gicv3_its: Use enum for return value of process_* functions, Peter Maydell, 2022/01/20
- [PULL 07/38] hw/acpi/aml-build: Improve scalability of PPTT generation, Peter Maydell, 2022/01/20
- [PULL 06/38] hw/arm/virt: Support cluster level in DT cpu-map, Peter Maydell, 2022/01/20
- [PULL 04/38] hw/net: Move MV88W8618 network device out of hw/arm/ directory, Peter Maydell, 2022/01/20
- [PULL 03/38] hw/arm/musicpal: Fix coding style of code related to MV88W8618 device, Peter Maydell, 2022/01/20
- [PULL 16/38] hw/arm/virt: Add a control for the the highmem PCIe MMIO, Peter Maydell, 2022/01/20
- [PULL 13/38] hw/arm/virt: Support for virtio-mem-pci, Peter Maydell, 2022/01/20
- [PULL 10/38] tests/acpi/bios-table-test: Update expected virt/PPTT file, Peter Maydell, 2022/01/20