|
From: | Philippe Mathieu-Daudé |
Subject: | Re: [RFC PATCH 05/23] hw: add register access utility functions |
Date: | Tue, 13 Aug 2024 10:28:16 +0200 |
User-agent: | Mozilla Thunderbird |
On 12/8/24 23:14, Octavian Purdila wrote:
On Mon, Aug 12, 2024 at 8:33 AM Peter Maydell <peter.maydell@linaro.org> wrote:On Mon, 5 Aug 2024 at 21:17, Octavian Purdila <tavip@google.com> wrote:Add register access utility functions for device models, like checking aligned access and reading and writing to a register backstore.Signed-off-by: Octavian Purdila <tavip@google.com> --- include/hw/regs.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 include/hw/regs.h
+/* + * reg32_read + * @base: base address + * @addr: register offset in bytes + * + * Returns: 32bit value from register backstore + */ +static inline uint32_t reg32_read(void *base, uint32_t addr) +{ + return *(uint32_t *)(base + addr); +}Pointer type handling looks suspicious here -- if the thing we're accessing is really a uint32_t* then we should take that; if it isn't then casting it to one and dereferencing might be reading unaligned memory.It is used for performing generic accesses to generated structs (patch 3/23) which should be aligned in the way that are used in the patch set. If we decide to keep it, I'll add a note regarding alignment.
Could we use ldl_he_p() instead?
[Prev in Thread] | Current Thread | [Next in Thread] |