All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Tobias Waldekranz <tobias@waldekranz.com>
Cc: xypron.glpk@gmx.de, ilias.apalodimas@linaro.org, u-boot@lists.denx.de
Subject: Re: [PATCH 4/8] blk: blkmap: Add memory mapping support
Date: Wed, 1 Feb 2023 13:21:01 -0700	[thread overview]
Message-ID: <CAPnjgZ2_5CZqLEnsZ4kpWDP6tju101wCApgB7zdO9founY0Cfw@mail.gmail.com> (raw)
In-Reply-To: <20230201181016.4145834-5-tobias@waldekranz.com>

Hi Tobias,

On Wed, 1 Feb 2023 at 11:10, Tobias Waldekranz <tobias@waldekranz.com> wrote:
>
> Allow a slice of RAM to be mapped to a blkmap. This means that RAM can
> now be accessed as if it was a block device, meaning that existing
> filesystem drivers can now be used to access ramdisks.
>
> Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
> ---
>  drivers/block/blkmap.c | 106 +++++++++++++++++++++++++++++++++++++++++
>  include/blkmap.h       |   4 ++
>  2 files changed, 110 insertions(+)
>
> diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c
> index a6ba07404c..c8c2dcac11 100644
> --- a/drivers/block/blkmap.c
> +++ b/drivers/block/blkmap.c
> @@ -12,6 +12,7 @@
>  #include <dm/lists.h>
>  #include <dm/root.h>
>  #include <malloc.h>
> +#include <mapmem.h>
>  #include <part.h>
>
>  struct blkmap;
> @@ -93,6 +94,111 @@ static int blkmap_add(struct blkmap *bm, struct blkmap_slice *new)
>         return 0;
>  }
>
> +struct blkmap_mem {
> +       struct blkmap_slice slice;
> +       void *addr;
> +       bool remapped;
> +};
> +
> +static ulong blkmap_mem_read(struct blkmap *bm, struct blkmap_slice *bms,
> +                            lbaint_t blknr, lbaint_t blkcnt, void *buffer)
> +{
> +       struct blkmap_mem *bmm = container_of(bms, struct blkmap_mem, slice);
> +       struct blk_desc *bd = dev_get_uclass_plat(bm->dev);
> +       char *src;
> +
> +       src = bmm->addr + (blknr << bd->log2blksz);
> +       memcpy(buffer, src, blkcnt << bd->log2blksz);
> +       return blkcnt;
> +}
> +
> +static ulong blkmap_mem_write(struct blkmap *bm, struct blkmap_slice *bms,
> +                             lbaint_t blknr, lbaint_t blkcnt,
> +                             const void *buffer)
> +{
> +       struct blkmap_mem *bmm = container_of(bms, struct blkmap_mem, slice);
> +       struct blk_desc *bd = dev_get_uclass_plat(bm->dev);
> +       char *dst;
> +
> +       dst = bmm->addr + (blknr << bd->log2blksz);
> +       memcpy(dst, buffer, blkcnt << bd->log2blksz);
> +       return blkcnt;
> +}
> +
> +static void blkmap_mem_destroy(struct blkmap *bm, struct blkmap_slice *bms)
> +{
> +       struct blkmap_mem *bmm = container_of(bms, struct blkmap_mem, slice);
> +
> +       if (bmm->remapped)
> +               unmap_sysmem(bmm->addr);
> +}
> +
> +int __blkmap_map_mem(int devnum, lbaint_t blknr, lbaint_t blkcnt, void *addr,
> +                    bool remapped)
> +{
> +       struct blkmap_mem *bmm;
> +       struct blkmap *bm;
> +       int err;
> +
> +       bm = blkmap_from_devnum(devnum);
> +       if (!bm)
> +               return -ENODEV;
> +
> +       bmm = malloc(sizeof(*bmm));
> +       if (!bmm)
> +               return -ENOMEM;
> +
> +       *bmm = (struct blkmap_mem) {
> +               .slice = {
> +                       .blknr = blknr,
> +                       .blkcnt = blkcnt,
> +
> +                       .read = blkmap_mem_read,
> +                       .write = blkmap_mem_write,
> +                       .destroy = blkmap_mem_destroy,
> +               },
> +
> +               .addr = addr,
> +               .remapped = remapped,
> +       };
> +
> +       err = blkmap_add(bm, &bmm->slice);
> +       if (err)
> +               free(bmm);
> +
> +       return err;
> +}
> +
> +int blkmap_map_mem(int devnum, lbaint_t blknr, lbaint_t blkcnt, void *addr)
> +{
> +       return __blkmap_map_mem(devnum, blknr, blkcnt, addr, false);
> +}
> +
> +int blkmap_map_pmem(int devnum, lbaint_t blknr, lbaint_t blkcnt,
> +                   phys_addr_t paddr)
> +{
> +       struct blk_desc *bd;
> +       struct blkmap *bm;
> +       void *addr;
> +       int err;
> +
> +       bm = blkmap_from_devnum(devnum);
> +       if (!bm)
> +               return -ENODEV;
> +
> +       bd = dev_get_uclass_plat(bm->dev);
> +
> +       addr = map_sysmem(paddr, blkcnt << bd->log2blksz);
> +       if (!addr)
> +               return -ENOMEM;
> +
> +       err = __blkmap_map_mem(devnum, blknr, blkcnt, addr, true);
> +       if (err)
> +               unmap_sysmem(addr);
> +
> +       return err;
> +}
> +
>  static struct udevice *blkmap_root(void)
>  {
>         static struct udevice *dev;
> diff --git a/include/blkmap.h b/include/blkmap.h
> index 37c0c31c3f..a93611ff62 100644
> --- a/include/blkmap.h
> +++ b/include/blkmap.h
> @@ -9,6 +9,10 @@
>
>  #include <stdbool.h>
>
> +int blkmap_map_mem(int devnum, lbaint_t blknr, lbaint_t blkcnt, void *addr);
> +int blkmap_map_pmem(int devnum, lbaint_t blknr, lbaint_t blkcnt,
> +                   phys_addr_t paddr);

Comments again.

> +
>  int blkmap_create(int devnum);
>  int blkmap_destroy(int devnum);
>
> --
> 2.34.1
>

Other than that and the devnum stuff, LGTM

Regards,
Simon

  reply	other threads:[~2023-02-01 20:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-01 18:10 [PATCH 0/8] blk: blkmap: Composable virtual block devices Tobias Waldekranz
2023-02-01 18:10 ` [PATCH 1/8] image: Fix script execution from FIT images with external data Tobias Waldekranz
2023-02-01 20:20   ` Simon Glass
2023-02-01 18:10 ` [PATCH 2/8] cmd: blk: Allow generic read/write operations to work in sandbox Tobias Waldekranz
2023-02-01 20:20   ` Simon Glass
2023-02-01 18:10 ` [PATCH 3/8] blk: blkmap: Add basic infrastructure Tobias Waldekranz
2023-02-01 20:20   ` Simon Glass
2023-02-03  9:38     ` Tobias Waldekranz
2023-02-04  0:20       ` Simon Glass
2023-02-06  8:30         ` Tobias Waldekranz
2023-02-07  4:02           ` Simon Glass
2023-02-07  8:31             ` Tobias Waldekranz
2023-02-07 13:38               ` Simon Glass
2023-02-01 18:10 ` [PATCH 4/8] blk: blkmap: Add memory mapping support Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass [this message]
2023-02-01 18:10 ` [PATCH 5/8] blk: blkmap: Add linear device " Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 6/8] cmd: blkmap: Add blkmap command Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 7/8] test: blkmap: Add test suite Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 18:10 ` [PATCH 8/8] doc: blkmap: Add introduction and examples Tobias Waldekranz
2023-02-01 20:21   ` Simon Glass
2023-02-01 21:14   ` Heinrich Schuchardt
2023-02-01 20:21 ` [PATCH 0/8] blk: blkmap: Composable virtual block devices Simon Glass

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=CAPnjgZ2_5CZqLEnsZ4kpWDP6tju101wCApgB7zdO9founY0Cfw@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=tobias@waldekranz.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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 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.