public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Max Resch <resch.max@gmail.com>
To: u-boot@lists.denx.de
Cc: sr@denx.de, Max Resch <resch.max@gmail.com>
Subject: [PATCH v3] rng: Add Turris Mox rTWM RNG driver
Date: Wed,  7 Feb 2024 16:00:12 +0100	[thread overview]
Message-ID: <20240207150017.666213-1-resch.max@gmail.com> (raw)

A RNG driver for Armada 3720 boards running the Turris Mox rWTM firmware
from CZ.NIC in the secure processor.

Signed-off-by: Max Resch <resch.max@gmail.com>
---

Changes in v3:
 - More meaningful variable names in accordance with review

Changes in v2:
 - Removed ring buffer implementation

 drivers/rng/turris_rwtm_rng.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/rng/turris_rwtm_rng.c b/drivers/rng/turris_rwtm_rng.c
index 143fe0b47f..ec2cb0bca3 100644
--- a/drivers/rng/turris_rwtm_rng.c
+++ b/drivers/rng/turris_rwtm_rng.c
@@ -41,18 +41,19 @@ static int turris_rwtm_rng_fill_entropy(phys_addr_t entropy, size_t size)
 
 static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t count)
 {
-	phys_addr_t p;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+	phys_addr_t phys;
 	size_t size;
 	int ret;
 
-	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
+	phys = priv->buffer;
 
 	while (count) {
 		size = min_t(size_t, RNG_BUFFER_SIZE, count);
 
-		ret = turris_rwtm_rng_fill_entropy(p, size);
+		ret = turris_rwtm_rng_fill_entropy(phys, size);
 
-		memcpy(data, (void *)p, size);
+		memcpy(data, (void *)phys, size);
 		count -= size;
 		data = (u8 *)data + size;
 	}
@@ -62,7 +63,7 @@ static int turris_rwtm_rng_random_read(struct udevice *dev, void *data, size_t c
 
 static int turris_rwtm_rng_probe(struct udevice *dev)
 {
-	struct turris_rwtm_rng_priv *priv;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
 	u32 args[] = { 0 };
 	int ret;
 
@@ -76,7 +77,6 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
 		return ret;
 
 	/* entropy buffer */
-	priv = (struct turris_rwtm_rng_priv *)dev_get_priv(dev);
 	priv->buffer = 0;
 
 	/* buffer address need to be aligned */
@@ -89,10 +89,10 @@ static int turris_rwtm_rng_probe(struct udevice *dev)
 
 static int turris_rwtm_rng_remove(struct udevice *dev)
 {
-	phys_addr_t p;
+	struct turris_rwtm_rng_priv *priv = dev_get_priv(dev);
+	phys_addr_t phys = priv->buffer;
 
-	p = ((struct turris_rwtm_rng_priv *)dev_get_priv(dev))->buffer;
-	dma_free_coherent((void *)p);
+	dma_free_coherent((void *)phys);
 
 	return 0;
 }
-- 
2.43.0


             reply	other threads:[~2024-02-07 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 15:00 Max Resch [this message]
2024-02-08  5:42 ` [PATCH v3] rng: Add Turris Mox rTWM RNG driver Stefan Roese

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=20240207150017.666213-1-resch.max@gmail.com \
    --to=resch.max@gmail.com \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /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