From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Shashi Mallela <shashi.mallela@linaro.org>,
qemu-arm@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH 26/26] hw/intc/arm_gicv3_its: Factor out "find address of table entry" code
Date: Mon, 13 Dec 2021 14:53:26 +0000 [thread overview]
Message-ID: <871r2gk0sq.fsf@linaro.org> (raw)
In-Reply-To: <20211211191135.1764649-27-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> The ITS has several tables which all share a similar format,
> described by the TableDesc struct: the guest may configure them
> to be a single-level table or a two-level table. Currently we
> open-code the process of finding the table entry in all the
> functions which read or write the device table or the collection
> table. Factor out the "get the address of the table entry"
> logic into a new function, so that the code which needs to
> read or write a table entry only needs to call table_entry_addr()
> and then perform a suitable load or store to that address.
>
> Note that the error handling is slightly complicated because
> we want to handle two cases differently:
> * failure to read the L1 table entry should end up causing
> a command stall, like other kinds of DMA error
> * an L1 table entry that says there is no L2 table for this
> index (ie whose valid bit is 0) must result in us treating
> the table entry as not-valid on read, and discarding
> writes (this is mandated by the spec)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> This is a worthwhile refactoring on its own, but still more
> so given that GICv4 adds another table in this format.
> ---
> hw/intc/arm_gicv3_its.c | 212 +++++++++++++---------------------------
> 1 file changed, 70 insertions(+), 142 deletions(-)
>
> diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
> index 3bcc4c3db85..90a9fd3b3d4 100644
> --- a/hw/intc/arm_gicv3_its.c
> +++ b/hw/intc/arm_gicv3_its.c
> @@ -83,44 +83,62 @@ static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz)
> return result;
> }
>
> +static uint64_t table_entry_addr(GICv3ITSState *s, TableDesc *td,
> + uint32_t idx, MemTxResult *res)
> +{
It seems odd to have a uint64_t return type when....
> + /*
> + * Given a TableDesc describing one of the ITS in-guest-memory
> + * tables and an index into it, return the guest address
> + * corresponding to that table entry.
> + * If there was a memory error reading the L1 table of an
> + * indirect table, *res is set accordingly, and we return -1.
> + * If the L1 table entry is marked not valid, we return -1 with
> + * *res set to MEMTX_OK.
> + *
> + * The specification defines the format of level 1 entries of a
> + * 2-level table, but the format of level 2 entries and the format
> + * of flat-mapped tables is IMPDEF.
> + */
> + AddressSpace *as = &s->gicv3->dma_as;
> + uint32_t l2idx;
> + uint64_t l2;
> + uint32_t num_l2_entries;
> +
> + *res = MEMTX_OK;
> +
> + if (!td->indirect) {
> + /* Single level table */
> + return td->base_addr + idx * td->entry_sz;
> + }
> +
> + /* Two level table */
> + l2idx = idx / (td->page_sz / L1TABLE_ENTRY_SIZE);
> +
> + l2 = address_space_ldq_le(as,
> + td->base_addr + (l2idx * L1TABLE_ENTRY_SIZE),
> + MEMTXATTRS_UNSPECIFIED, res);
> + if (*res != MEMTX_OK) {
> + return -1;
> + }
> + if (!(l2 & L2_TABLE_VALID_MASK)) {
> + return -1;
> + }
We can return signed results. I guess implicit conversion takes care of
it but I wonder if it would be cleaner to return an int (or maybe
compare against UNINT64_MAX == INVALID_TABLE_ENTRY)?
--
Alex Bennée
next prev parent reply other threads:[~2021-12-13 15:05 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-11 19:11 [PATCH 00/26] arm gicv3 ITS: Various bug fixes and refactorings Peter Maydell
2021-12-11 19:11 ` [PATCH 01/26] hw/intc: clean-up error reporting for failed ITS cmd Peter Maydell
2021-12-12 17:31 ` Richard Henderson
2021-12-11 19:11 ` [PATCH 02/26] hw/intc/arm_gicv3_its: Correct off-by-one bounds check on rdbase Peter Maydell
2021-12-12 17:32 ` Richard Henderson
2021-12-13 11:22 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 03/26] hw/intc/arm_gicv3_its: Remove redundant ITS_CTLR_ENABLED define Peter Maydell
2021-12-12 17:34 ` Richard Henderson
2021-12-12 20:46 ` Philippe Mathieu-Daudé
2021-12-13 11:55 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 04/26] hw/intc/arm_gicv3_its: Remove maxids union from TableDesc Peter Maydell
2021-12-12 17:37 ` Richard Henderson
2021-12-13 11:32 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 05/26] hw/intc/arm_gicv3_its: Don't return early in extract_table_params() loop Peter Maydell
2021-12-12 17:46 ` Richard Henderson
2021-12-13 11:33 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 06/26] hw/intc/arm_gicv3_its: Reduce code duplication in extract_table_params() Peter Maydell
2021-12-12 18:30 ` Richard Henderson
2021-12-12 20:47 ` Philippe Mathieu-Daudé
2021-12-13 11:34 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 07/26] hw/intc/arm_gicv3_its: Correct setting of TableDesc entry_sz Peter Maydell
2021-12-12 18:33 ` Richard Henderson
2021-12-13 11:37 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 08/26] hw/intc/arm_gicv3_its: Don't misuse GITS_TYPE_PHYSICAL define Peter Maydell
2021-12-12 18:40 ` Richard Henderson
2021-12-13 11:52 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 09/26] hw/intc/arm_gicv3_its: Correct handling of MAPI Peter Maydell
2021-12-12 18:48 ` Richard Henderson
2021-12-13 11:54 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 10/26] hw/intc/arm_gicv3_its: Use FIELD macros for DTEs Peter Maydell
2021-12-12 20:23 ` Richard Henderson
2021-12-12 21:16 ` Philippe Mathieu-Daudé
2021-12-13 8:23 ` Philippe Mathieu-Daudé
2021-12-13 11:56 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 11/26] hw/intc/arm_gicv3_its: Use 1ULL when shifting by (DTE.SIZE + 1) Peter Maydell
2021-12-12 20:31 ` Richard Henderson
2021-12-12 20:43 ` Richard Henderson
2021-12-13 9:48 ` Peter Maydell
2021-12-13 10:56 ` Peter Maydell
2021-12-11 19:11 ` [PATCH 12/26] hw/intc/arm_gicv3_its: Correct comment about CTE RDBase field size Peter Maydell
2021-12-12 20:34 ` Richard Henderson
2021-12-13 13:07 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 13/26] hw/intc/arm_gicv3_its: Use FIELD macros for CTEs Peter Maydell
2021-12-12 20:35 ` Richard Henderson
2021-12-13 13:08 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 14/26] hw/intc/arm_gicv3_its: Fix various off-by-one errors Peter Maydell
2021-12-13 13:35 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 15/26] hw/intc/arm_gicv3_its: Rename max_l2_entries to num_l2_entries Peter Maydell
2021-12-12 20:38 ` Richard Henderson
2021-12-13 12:58 ` Philippe Mathieu-Daudé
2021-12-13 13:36 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 16/26] hw/intc/arm_gicv3_its: Fix event ID bounds checks Peter Maydell
2021-12-13 13:00 ` Philippe Mathieu-Daudé
2021-12-13 13:37 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 17/26] hw/intc/arm_gicv3_its: Convert int ID check to num_intids convention Peter Maydell
2021-12-13 13:39 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 18/26] hw/intc/arm_gicv3_its: Fix handling of process_its_cmd() return value Peter Maydell
2021-12-12 20:53 ` Richard Henderson
2021-12-13 13:01 ` Philippe Mathieu-Daudé
2021-12-13 13:41 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 19/26] hw/intc/arm_gicv3_its: Don't use data if reading command failed Peter Maydell
2021-12-12 20:54 ` Richard Henderson
2021-12-13 14:49 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 20/26] hw/intc/arm_gicv3_its: Use enum for return value of process_* functions Peter Maydell
2021-12-12 21:06 ` Richard Henderson
2021-12-13 13:03 ` Philippe Mathieu-Daudé
2021-12-13 14:40 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 21/26] hw/intc/arm_gicv3_its: Fix return codes in process_its_cmd() Peter Maydell
2021-12-12 22:02 ` Richard Henderson
2021-12-13 14:40 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 22/26] hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting Peter Maydell
2021-12-12 22:34 ` Richard Henderson
2021-12-13 14:50 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 23/26] hw/intc/arm_gicv3_its: Fix return codes in process_mapti() Peter Maydell
2021-12-12 22:36 ` Richard Henderson
2021-12-13 14:51 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 24/26] hw/intc/arm_gicv3_its: Fix return codes in process_mapc() Peter Maydell
2021-12-12 22:37 ` Richard Henderson
2021-12-13 14:51 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 25/26] hw/intc/arm_gicv3_its: Fix return codes in process_mapd() Peter Maydell
2021-12-12 22:39 ` Richard Henderson
2021-12-13 14:51 ` Alex Bennée
2021-12-11 19:11 ` [PATCH 26/26] hw/intc/arm_gicv3_its: Factor out "find address of table entry" code Peter Maydell
2021-12-12 22:52 ` Richard Henderson
2021-12-13 14:53 ` Alex Bennée [this message]
2021-12-13 15:48 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871r2gk0sq.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shashi.mallela@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).