qemu-devel.nongnu.org archive mirror
 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 v7 03/12] register: Add Memory API glue
Date: Thu, 23 Jun 2016 13:21:02 +0100	[thread overview]
Message-ID: <CAFEAcA97LOz74YKhCu2vqbzk+jXFNkhuq4+V0SGptEO8ue4t1w@mail.gmail.com> (raw)
In-Reply-To: <0a14ebd735f88ae57a0d976cf5c1517a1ec0dadc.1466626975.git.alistair.francis@xilinx.com>

On 22 June 2016 at 21:23, 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>
> ---
> V7:
>  - Remove endianess handling
>  - Remove assert() and log missing registers
> V6:
>  - Add the memory region later
> V5:
>  - Convert to using only one memory region
>
>  hw/core/register.c    | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/register.h | 43 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 101 insertions(+)
>
> diff --git a/hw/core/register.c b/hw/core/register.c
> index cc067f1..149aebb 100644
> --- a/hw/core/register.c
> +++ b/hw/core/register.c
> @@ -154,3 +154,61 @@ void register_reset(RegisterInfo *reg)
>
>      register_write_val(reg, reg->access->reset);
>  }
> +
> +void register_write_memory(void *opaque, hwaddr addr,
> +                           uint64_t value, unsigned size)
> +{
> +    RegisterInfoArray *reg_array = opaque;
> +    RegisterInfo *reg = NULL;
> +    uint64_t we = ~0;

Really ~0 and not ~0ULL ? In any case this shouldn't need
initializing as we will always set it later.

> +    int i;
> +
> +    for (i = 0; i < reg_array->num_elements; i++) {
> +        if (reg_array->r[i]->access->addr == addr) {
> +            reg = reg_array->r[i];
> +            break;
> +        }
> +    }
> +
> +    if (!reg) {
> +        qemu_log_mask(LOG_UNIMP, "Write to unimplemented register at " \
> +                      "address: %#" PRIx64 "\n", addr);

Shouldn't this be a LOG_GUEST_ERROR ?

> +        return;
> +    }
> +
> +    /* Generate appropriate write enable mask */
> +    if (reg->data_size < size) {
> +        we = MAKE_64BIT_MASK(0, reg->data_size * 8);
> +    } else if (reg->data_size >= size) {

Why not just "else {" ?

> +        we = MAKE_64BIT_MASK(0, size * 8);
> +    }
> +
> +    register_write(reg, value, we, reg_array->prefix,
> +                   reg_array->debug);
> +}
> +
> +uint64_t register_read_memory(void *opaque, hwaddr addr,
> +                              unsigned size)
> +{
> +    RegisterInfoArray *reg_array = opaque;
> +    RegisterInfo *reg = NULL;
> +    uint64_t read_val;
> +    int i;
> +
> +    for (i = 0; i < reg_array->num_elements; i++) {
> +        if (reg_array->r[i]->access->addr == addr) {
> +            reg = reg_array->r[i];
> +            break;
> +        }
> +    }
> +
> +    if (!reg) {
> +        qemu_log_mask(LOG_UNIMP, "Read to unimplemented register at " \
> +                      "address: %#" PRIx64 "\n", addr);
> +        return 0;
> +    }
> +
> +    read_val = register_read(reg, reg_array->prefix, reg_array->debug);

This will silently affect bits of the register outside the
specified size with clear-on-read or other "reads have
side effects" behaviour, which isn't consistent with how
we handle writes.

>  /**
> + * This structure is used to group all of the individual registers which are
> + * modeled using the RegisterInfo strucutre.

"structure"

> + *
> + * @r is an aray containing of all the relevent RegisterInfo structures.
> + *
> + * @num_elements is the number of elements in the array r
> + *
> + * @mem: optional Memory region for the register
> + */
> +
> +struct RegisterInfoArray {
> +    int num_elements;
> +    RegisterInfo **r;
> +
> +    bool debug;
> +    const char *prefix;
> +};
> +

thanks
-- PMM

  reply	other threads:[~2016-06-23 12:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-22 20:23 [Qemu-devel] [PATCH v7 00/12] data-driven device registers Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 01/12] bitops: Add MAKE_64BIT_MASK macro Alistair Francis
2016-06-23 12:14   ` Peter Maydell
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 02/12] register: Add Register API Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 03/12] register: Add Memory API glue Alistair Francis
2016-06-23 12:21   ` Peter Maydell [this message]
2016-06-23 16:30     ` Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 04/12] register: Define REG and FIELD macros Alistair Francis
2016-06-23 12:39   ` Peter Maydell
2016-06-23 17:51     ` Alistair Francis
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 05/12] register: QOMify Alistair Francis
2016-06-23 12:40   ` Peter Maydell
2016-06-22 20:23 ` [Qemu-devel] [PATCH v7 06/12] register: Add block initialise helper Alistair Francis
2016-06-23 12:55   ` Peter Maydell
2016-06-23 17:29     ` Alistair Francis
2016-06-23 18:02       ` Peter Maydell
2016-06-23 18:10         ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 07/12] dma: Add Xilinx Zynq devcfg device model Alistair Francis
2016-06-23 13:08   ` Peter Maydell
2016-06-23 18:08     ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 08/12] xilinx_zynq: Connect devcfg to the Zynq machine model Alistair Francis
2016-06-23 13:09   ` Peter Maydell
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 09/12] irq: Add opaque setter routine Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 10/12] register: Add GPIO API Alistair Francis
2016-06-23 13:19   ` Peter Maydell
2016-06-23 18:14     ` Alistair Francis
2016-06-22 20:24 ` [Qemu-devel] [PATCH v7 11/12] misc: Introduce ZynqMP IOU SLCR 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=CAFEAcA97LOz74YKhCu2vqbzk+jXFNkhuq4+V0SGptEO8ue4t1w@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 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).