qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Martin Kaiser <martin@kaiser.cx>
Cc: qemu-arm <qemu-arm@nongnu.org>,
	Peter Chubb <peter.chubb@nicta.com.au>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Jean-Christophe Dubois <jcd@tribudubois.net>
Subject: Re: [PATCH] i.MX: add an emulation for RNGC
Date: Mon, 6 Jan 2020 17:54:21 +0000	[thread overview]
Message-ID: <CAFEAcA-JTxqGid8EW=Vu=xePrEVgxD9pZRNAg0BehFVhYKfebw@mail.gmail.com> (raw)
In-Reply-To: <20191226175132.28116-1-martin@kaiser.cx>

On Thu, 26 Dec 2019 at 17:52, Martin Kaiser <martin@kaiser.cx> wrote:
>
> Add an emulation for the RNGC random number generator and the compatible
> RNGB variant. These peripherals are included (at least) in imx25 and
> imx35 chipsets.
>
> The emulation supports the initial self test, reseeding the prng and
> reading random numbers.
>
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>

Thanks for this patch; it looks good to me -- the only
major missing item is a VMStateDescription, which should
be easy to add. (I haven't checked the actual device
functionality against a datasheet, but it all looks plausible.)
There were also a couple of minor nits which I've listed inline below.

> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index ba898a5781..2b28f8c096 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -42,6 +42,7 @@ common-obj-$(CONFIG_IMX) += imx7_ccm.o
>  common-obj-$(CONFIG_IMX) += imx2_wdt.o
>  common-obj-$(CONFIG_IMX) += imx7_snvs.o
>  common-obj-$(CONFIG_IMX) += imx7_gpr.o
> +common-obj-$(CONFIG_IMX) += imx_rngc.o
>  common-obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o
>  common-obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o
>  common-obj-$(CONFIG_MAINSTONE) += mst_fpga.o
> diff --git a/hw/misc/imx_rngc.c b/hw/misc/imx_rngc.c
> new file mode 100644
> index 0000000000..f935ec46a6
> --- /dev/null
> +++ b/hw/misc/imx_rngc.c
> @@ -0,0 +1,262 @@
> +/*
> + * Freescale i.MX RNGC emulation
> + *
> + * Copyright (C) 2019 Martin Kaiser <martin@kaiser.cx>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + *
> + * This driver provides the minimum functionality to initialize and seed
> + * an rngc and to read random numbers. The rngb that is found in imx25
> + * chipsets is also supported.
> + */
> +
> +
> +#include "qemu/osdep.h"
> +#include "qemu/main-loop.h"

Do you really need main-loop.h ?

> +#include "qemu/module.h"
> +#include "qemu/log.h"
> +#include "qemu/guest-random.h"
> +#include "hw/irq.h"
> +#include "hw/misc/imx_rngc.h"

> +static void __imx_rngc_reset(IMXRNGCState *s)

Don't use __ prefixes for function names, please.

> +{
> +    s->op_self_test = OP_IDLE;
> +    s->op_seed = OP_IDLE;
> +    s->mask = 0;
> +    s->auto_seed = false;
> +}
> +
> +static void imx_rngc_write(void *opaque, hwaddr offset, uint64_t value,
> +                           unsigned size)
> +{
> +    IMXRNGCState *s = IMX_RNGC(opaque);
> +
> +    switch (offset) {
> +    case RNGC_COMMAND:
> +        if (value & RNGC_CMD_BIT_SW_RST) {
> +            __imx_rngc_reset(s);
> +        }
> +
> +        /*
> +         * For now, both CLR_ERR and CLR_INT clear the interrupt. We
> +         * don't report any erors yet.

"errors"

> +         */
> +        if (value & (RNGC_CMD_BIT_CLR_ERR | RNGC_CMD_BIT_CLR_INT)) {
> +            qemu_irq_lower(s->irq);
> +        }

> +static void imx_rngc_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->realize = imx_rngc_realize;
> +    dc->reset = imx_rngc_reset;
> +    dc->desc = "i.MX RNGC";

You need also to set dc->vmsd to a VMStateDescription
which describes the variable state of the device that
needs to be migrated.

> +}
> +
> +static const TypeInfo imx_rngc_info = {
> +    .name          = TYPE_IMX_RNGC,
> +    .parent        = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(IMXRNGCState),
> +    .class_init    = imx_rngc_class_init,
> +};
> +
> +static void imx_rngc_register_types(void)
> +{
> +    type_register_static(&imx_rngc_info);
> +}

thanks
-- PMM


  reply	other threads:[~2020-01-06 17:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-26 17:51 [PATCH] i.MX: add an emulation for RNGC Martin Kaiser
2020-01-06 17:54 ` Peter Maydell [this message]
2020-01-08  8:55   ` Martin Kaiser
2020-01-08  8:46 ` [PATCH v2] " Martin Kaiser
2020-01-16 17:58   ` 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='CAFEAcA-JTxqGid8EW=Vu=xePrEVgxD9pZRNAg0BehFVhYKfebw@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=jcd@tribudubois.net \
    --cc=martin@kaiser.cx \
    --cc=peter.chubb@nicta.com.au \
    --cc=qemu-arm@nongnu.org \
    --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).