[PATCH v6 8/8] virtio: rng: Add a random number generator(rng) driver

Heinrich Schuchardt xypron.glpk at gmx.de
Sat Dec 28 11:28:55 CET 2019


On 12/28/19 7:09 AM, Heinrich Schuchardt wrote:
> #define BUFFER_SIZE 16UL
> 
> static int virtio_rng_read(struct udevice *dev, void *data, size_t len)
> {
>      int ret;
>      unsigned int rsize = 0;
>      unsigned char buf[BUFFER_SIZE];

This should be
	unsigned char buf[BUFFER_SIZE] __aligned(4);

>      unsigned char *ptr = data;
>      struct virtio_sg sg;
>      struct virtio_sg *sgs = sg;
>      struct virtio_rng_priv *priv = dev_get_priv(dev);
> 
>      while (len) {
>          sg.addr = buf;
>          sg.length = min(BUFFER_SIZE, len);
> 
>          ret = virtqueue_add(priv->rng_vq, &sgs, 0, 1);
>          if (ret)
>              return ret;
> 
>          virtqueue_kick(priv->rng_vq);
> 
>          while (!virtqueue_get_buf(priv->rng_vq, &rsize))
>              ;
>          memcpy(ptr, buf, rsize);
>          len -= rsize;
>          ptr += rsize;
>      }
> 
>      return 0;
> }



More information about the U-Boot mailing list