All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready
@ 2022-05-20 12:42 Icenowy Zheng
  2022-05-23 14:14 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Icenowy Zheng @ 2022-05-20 12:42 UTC (permalink / raw)
  To: Beniamino Galvani, Peter Maydell, Niek Linnenbank
  Cc: qemu-arm, qemu-devel, Icenowy Zheng

U-Boot queries the FIFO water level to reduce checking status register
when doing PIO SD card operation.

Report a FIFO water level of 1 when data is ready, to prevent the code
from trying to read 0 words from the FIFO each time.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
---
 hw/sd/allwinner-sdhost.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
index 041e45c680..b66fd9bce7 100644
--- a/hw/sd/allwinner-sdhost.c
+++ b/hw/sd/allwinner-sdhost.c
@@ -114,7 +114,9 @@ enum {
 };
 
 enum {
+    SD_STAR_FIFO_EMPTY      = (1 << 2),
     SD_STAR_CARD_PRESENT    = (1 << 8),
+    SD_STAR_FIFO_LEVEL_1    = (1 << 17),
 };
 
 enum {
@@ -467,6 +469,11 @@ static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
         break;
     case REG_SD_STAR:      /* Status */
         res = s->status;
+        if (sdbus_data_ready(&s->sdbus)) {
+            res |= SD_STAR_FIFO_LEVEL_1;
+        } else {
+            res |= SD_STAR_FIFO_EMPTY;
+        }
         break;
     case REG_SD_FWLR:      /* FIFO Water Level */
         res = s->fifo_wlevel;
-- 
2.36.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready
  2022-05-20 12:42 [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready Icenowy Zheng
@ 2022-05-23 14:14 ` Peter Maydell
  2022-05-23 16:40   ` Icenowy Zheng
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2022-05-23 14:14 UTC (permalink / raw)
  To: Icenowy Zheng; +Cc: Beniamino Galvani, Niek Linnenbank, qemu-arm, qemu-devel

On Fri, 20 May 2022 at 13:42, Icenowy Zheng <uwu@icenowy.me> wrote:
>
> U-Boot queries the FIFO water level to reduce checking status register
> when doing PIO SD card operation.
>
> Report a FIFO water level of 1 when data is ready, to prevent the code
> from trying to read 0 words from the FIFO each time.
>
> Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> ---
>  hw/sd/allwinner-sdhost.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
> index 041e45c680..b66fd9bce7 100644
> --- a/hw/sd/allwinner-sdhost.c
> +++ b/hw/sd/allwinner-sdhost.c
> @@ -114,7 +114,9 @@ enum {
>  };
>
>  enum {
> +    SD_STAR_FIFO_EMPTY      = (1 << 2),
>      SD_STAR_CARD_PRESENT    = (1 << 8),
> +    SD_STAR_FIFO_LEVEL_1    = (1 << 17),
>  };

Is there documentation on this hardware available somewhere?
The Linux kernel driver for it doesn't seem to have a #define
for this bit 17.

In an ideal world we'd actually emulate the FIFO itself
(our pl181 and bcm2835_sdhost models do this, for example).

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready
  2022-05-23 14:14 ` Peter Maydell
@ 2022-05-23 16:40   ` Icenowy Zheng
  2022-05-30 11:36     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Icenowy Zheng @ 2022-05-23 16:40 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Beniamino Galvani, Niek Linnenbank, qemu-arm, qemu-devel

在 2022-05-23星期一的 15:14 +0100,Peter Maydell写道:
> On Fri, 20 May 2022 at 13:42, Icenowy Zheng <uwu@icenowy.me> wrote:
> > 
> > U-Boot queries the FIFO water level to reduce checking status
> > register
> > when doing PIO SD card operation.
> > 
> > Report a FIFO water level of 1 when data is ready, to prevent the
> > code
> > from trying to read 0 words from the FIFO each time.
> > 
> > Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> > ---
> >  hw/sd/allwinner-sdhost.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
> > index 041e45c680..b66fd9bce7 100644
> > --- a/hw/sd/allwinner-sdhost.c
> > +++ b/hw/sd/allwinner-sdhost.c
> > @@ -114,7 +114,9 @@ enum {
> >  };
> > 
> >  enum {
> > +    SD_STAR_FIFO_EMPTY      = (1 << 2),
> >      SD_STAR_CARD_PRESENT    = (1 << 8),
> > +    SD_STAR_FIFO_LEVEL_1    = (1 << 17),
> >  };
> 
> Is there documentation on this hardware available somewhere?
> The Linux kernel driver for it doesn't seem to have a #define
> for this bit 17.

For the specific version on H3,
https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf .

> 
> In an ideal world we'd actually emulate the FIFO itself
> (our pl181 and bcm2835_sdhost models do this, for example).

Interesting, I will check it.

> -- PMM




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready
  2022-05-23 16:40   ` Icenowy Zheng
@ 2022-05-30 11:36     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2022-05-30 11:36 UTC (permalink / raw)
  To: Icenowy Zheng; +Cc: Beniamino Galvani, Niek Linnenbank, qemu-arm, qemu-devel

On Mon, 23 May 2022 at 17:40, Icenowy Zheng <uwu@icenowy.me> wrote:
>
> 在 2022-05-23星期一的 15:14 +0100,Peter Maydell写道:
> > On Fri, 20 May 2022 at 13:42, Icenowy Zheng <uwu@icenowy.me> wrote:
> > >
> > > U-Boot queries the FIFO water level to reduce checking status
> > > register
> > > when doing PIO SD card operation.
> > >
> > > Report a FIFO water level of 1 when data is ready, to prevent the
> > > code
> > > from trying to read 0 words from the FIFO each time.
> > >
> > > Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
> > > ---
> > >  hw/sd/allwinner-sdhost.c | 7 +++++++
> > >  1 file changed, 7 insertions(+)
> > >
> > > diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
> > > index 041e45c680..b66fd9bce7 100644
> > > --- a/hw/sd/allwinner-sdhost.c
> > > +++ b/hw/sd/allwinner-sdhost.c
> > > @@ -114,7 +114,9 @@ enum {
> > >  };
> > >
> > >  enum {
> > > +    SD_STAR_FIFO_EMPTY      = (1 << 2),
> > >      SD_STAR_CARD_PRESENT    = (1 << 8),
> > > +    SD_STAR_FIFO_LEVEL_1    = (1 << 17),
> > >  };
> >
> > Is there documentation on this hardware available somewhere?
> > The Linux kernel driver for it doesn't seem to have a #define
> > for this bit 17.
>
> For the specific version on H3,
> https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf .

Thanks. Since this patch fixes u-boot and is a reasonable
approximation to correct device behaviour assuming we don't
want to bother emulating the FIFO properly, I've applied
it to my target-arm.next tree.

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-30 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 12:42 [PATCH] hw/sd/allwinner-sdhost: report FIFO water level as 1 when data ready Icenowy Zheng
2022-05-23 14:14 ` Peter Maydell
2022-05-23 16:40   ` Icenowy Zheng
2022-05-30 11:36     ` Peter Maydell

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.