All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Alistair Francis <alistair.francis@xilinx.com>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"Peter Crosthwaite" <crosthwaitepeter@gmail.com>,
	"Edgar Iglesias" <edgar.iglesias@xilinx.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"KONRAD Frédéric" <fred.konrad@greensocs.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v6 03/13] register: Add Memory API glue
Date: Thu, 9 Jun 2016 20:03:26 +0100	[thread overview]
Message-ID: <CAFEAcA94HCH0JR-pgkr-ixaHXucmr+mPq4iDRthuD1yF9XQDpA@mail.gmail.com> (raw)
In-Reply-To: <f0a306440be607edf6f46ab52d77f4098773aca9.1463093051.git.alistair.francis@xilinx.com>

On 12 May 2016 at 23:45, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Add memory io handlers that glue the register API to the memory API.
> Just translation functions at this stage. Although it does allow for
> devices to be created without all-in-one mmio r/w handlers.
>
> This patch also adds the RegisterInfoArray struct, which allows all of
> the individual RegisterInfo structs to be grouped into a single memory
> region.
>
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V6:
>  - Add the memory region later
> V5:
>  - Convert to using only one memory region
>
>  hw/core/register.c    | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/register.h | 50 +++++++++++++++++++++++++++++++++++
>  2 files changed, 122 insertions(+)
>
> diff --git a/hw/core/register.c b/hw/core/register.c
> index 5e6f621..25196e6 100644
> --- a/hw/core/register.c
> +++ b/hw/core/register.c
> @@ -147,3 +147,75 @@ void register_reset(RegisterInfo *reg)
>
>      register_write_val(reg, reg->access->reset);
>  }
> +
> +static inline void register_write_memory(void *opaque, hwaddr addr,
> +                                         uint64_t value, unsigned size, bool be)
> +{
> +    RegisterInfoArray *reg_array = opaque;
> +    RegisterInfo *reg = NULL;
> +    uint64_t we = ~0;
> +    int i, shift = 0;
> +
> +    for (i = 0; i < reg_array->num_elements; i++) {
> +        if (reg_array->r[i]->access->decode.addr == addr) {
> +            reg = reg_array->r[i];
> +            break;
> +        }
> +    }
> +    assert(reg);

I'm surprised we don't support having the register array have
gaps for unimplemented/undefined registers. Presumably users
have to specify a lot of unimplemented entries ?

If you're going to assert() on undecoded addresses it would be
better to do a scan through at device init to sanity check
the register array, so missing elements are an obvious failure
rather than only showing up if the guest happens to access them.

> +
> +    /* Generate appropriate write enable mask and shift values */
> +    if (reg->data_size < size) {
> +        we = MAKE_64BIT_MASK(0, reg->data_size * 8);
> +        shift = 8 * (be ? reg->data_size - size : 0);
> +    } else if (reg->data_size >= size) {
> +        we = MAKE_64BIT_MASK(0, size * 8);
> +    }
> +
> +    register_write(reg, value << shift, we << shift, reg_array->prefix,
> +                   reg_array->debug);
> +}
> +
> +void register_write_memory_be(void *opaque, hwaddr addr, uint64_t value,
> +                              unsigned size)
> +{
> +    register_write_memory(opaque, addr, value, size, true);
> +}
> +
> +
> +void register_write_memory_le(void *opaque, hwaddr addr, uint64_t value,
> +                              unsigned size)
> +{
> +    register_write_memory(opaque, addr, value, size, false);
> +}
> +
> +static inline uint64_t register_read_memory(void *opaque, hwaddr addr,
> +                                            unsigned size, bool be)
> +{
> +    RegisterInfoArray *reg_array = opaque;
> +    RegisterInfo *reg = NULL;
> +    int i, shift;
> +
> +    for (i = 0; i < reg_array->num_elements; i++) {
> +        if (reg_array->r[i]->access->decode.addr == addr) {
> +            reg = reg_array->r[i];
> +            break;
> +        }
> +    }
> +    assert(reg);
> +
> +    shift = 8 * (be ? reg->data_size - size : 0);
> +
> +    return (register_read(reg, reg_array->prefix, reg_array->debug) >> shift) &
> +           MAKE_64BIT_MASK(0, size * 8);

This kind of thing is reimplementing extract64().

> +}
> +
> +uint64_t register_read_memory_be(void *opaque, hwaddr addr, unsigned size)
> +{
> +    return register_read_memory(opaque, addr, size, true);
> +}
> +
> +uint64_t register_read_memory_le(void *opaque, hwaddr addr, unsigned size)
> +{
> +    return register_read_memory(opaque, addr, size, false);
> +}

Why do we need to handle big vs little endian separately rather
than just having the memory region say which it is and letting
the core memory system handle things appropriately ?

thanks
-- PMM

  parent reply	other threads:[~2016-06-09 19:03 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-12 22:45 [Qemu-devel] [PATCH v6 00/13] data-driven device registers Alistair Francis
2016-05-12 22:45 ` [Qemu-devel] [PATCH v6 01/13] bitops: Add MAKE_64BIT_MASK macro Alistair Francis
2016-06-09 18:46   ` Peter Maydell
2016-06-13 20:57     ` Alistair Francis
2016-05-12 22:45 ` [Qemu-devel] [PATCH v6 02/13] register: Add Register API Alistair Francis
2016-06-09 18:55   ` Peter Maydell
2016-06-13 21:01     ` Alistair Francis
2016-05-12 22:45 ` [Qemu-devel] [PATCH v6 03/13] register: Add Memory API glue Alistair Francis
2016-06-09 13:08   ` KONRAD Frederic
2016-06-21 16:52     ` Alistair Francis
2016-06-09 19:03   ` Peter Maydell [this message]
2016-06-21  0:46     ` Alistair Francis
2016-06-21  6:48       ` Peter Maydell
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 04/13] register: Define REG and FIELD macros Alistair Francis
2016-06-10 10:52   ` Peter Maydell
2016-06-21 17:41     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 05/13] register: QOMify Alistair Francis
2016-06-10 10:55   ` Peter Maydell
2016-06-21 16:49     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 06/13] register: Add block initialise helper Alistair Francis
2016-06-10 11:02   ` Peter Maydell
2016-06-21 18:25     ` Alistair Francis
2016-06-21 19:45       ` Peter Maydell
2016-06-21 22:21         ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 07/13] dma: Add Xilinx Zynq devcfg device model Alistair Francis
2016-06-10 11:16   ` Peter Maydell
2016-06-21 18:34     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 08/13] xilinx_zynq: Connect devcfg to the Zynq machine model Alistair Francis
2016-06-10 11:19   ` Peter Maydell
2016-06-21 18:36     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 09/13] qdev: Define qdev_get_gpio_out Alistair Francis
2016-06-10 11:48   ` Peter Maydell
2016-06-21 19:05     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 10/13] irq: Add opaque setter routine Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 11/13] register: Add GPIO API Alistair Francis
2016-06-10 11:52   ` Peter Maydell
2016-06-21 22:34     ` Alistair Francis
2016-05-12 22:46 ` [Qemu-devel] [PATCH v6 12/13] misc: Introduce ZynqMP IOU SLCR Alistair Francis
2016-06-09  0:30 ` [Qemu-devel] [PATCH v6 00/13] data-driven device registers Alistair Francis
2016-06-10 11:53   ` Peter Maydell
2016-06-13 21:11     ` Alistair Francis

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=CAFEAcA94HCH0JR-pgkr-ixaHXucmr+mPq4iDRthuD1yF9XQDpA@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=afaerber@suse.de \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@xilinx.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=fred.konrad@greensocs.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.