All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: Mark Kettenis <kettenis@openbsd.org>,
	U-Boot Mailing List <u-boot@lists.denx.de>,
	 Oliver Graute <oliver.graute@kococonnector.com>,
	Stephan Gerhold <stephan@gerhold.net>,
	 Masami Hiramatsu <masami.hiramatsu@linaro.org>,
	Priyanka Jain <priyanka.jain@nxp.com>,
	Leo Liang <ycliang@andestech.com>,
	Padmarao Begari <padmarao.begari@microchip.com>,
	 Michael Walle <michael@walle.cc>,
	Kishon Vijay Abraham I <kishon@ti.com>,
	 Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Bin Meng <bin.meng@windriver.com>,
	 Asherah Connor <ashe@kivikakk.ee>,
	Michal Simek <michal.simek@xilinx.com>,
	 Wasim Khan <wasim.khan@nxp.com>, Heiko Schocher <hs@denx.de>,
	 Igor Opaniuk <igor.opaniuk@foundries.io>, Ye Li <ye.li@nxp.com>,
	Stefan Roese <sr@denx.de>,
	AKASHI Takahiro <takahiro.akashi@linaro.org>,
	Weijie Gao <weijie.gao@mediatek.com>,
	 Vabhav Sharma <vabhav.sharma@nxp.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Pratyush Yadav <p.yadav@ti.com>
Subject: Re: [PATCH 3/5] misc: Add Apple DART driver
Date: Mon, 20 Sep 2021 19:11:25 -0600	[thread overview]
Message-ID: <CAPnjgZ02UE8ZNiNv7e8h54e94P5Ykok6GZiqzvg7RgBe+sPEtg@mail.gmail.com> (raw)
In-Reply-To: <56146d936d16f96c@bloch.sibelius.xs4all.nl>

Hi Mark,

On Mon, 20 Sept 2021 at 02:33, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>
> > From: Simon Glass <sjg@chromium.org>
> > Date: Sun, 19 Sep 2021 21:16:00 -0600
> >
> > Hi Mark,
> >
> > On Sat, 18 Sept 2021 at 07:55, Mark Kettenis <kettenis@openbsd.org> wrote:
> > >
> > > The DART is an IOMMU that is used on Apple's M1 SoC.  This driver
> > > supports the DART in bypass mode as well as in a mode where it
> > > creates a 1:1 mapping of a subset of RAM as not all DARTs support
> > > bypass mode.  The USB3 ports integrated on the SoC use a DART
> > > that supports bypass mode.  The 1:1 mapping will be used in the
> > > future to support other devices such as the PCIe host bridge
> > > of the M1 SoC.
> > >
> > > Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
> > > ---
> > >  drivers/misc/Kconfig      |   7 ++
> > >  drivers/misc/Makefile     |   1 +
> > >  drivers/misc/apple_dart.c | 171 ++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 179 insertions(+)
> > >  create mode 100644 drivers/misc/apple_dart.c
> > >

[..]

> > > +
> > > +struct apple_dart_priv {
> >
> > How about s/apple_dart/dart/ ?
> >
> > It makes the code easier to read.
>
> I think using apple_dart_ consistently as a prefix makes more sense.

OK I don't mind too much. I just prefer shorter code and sometimes
people use globally unique things in drivers when it really doesn't
help anything.

>
> > > +       struct clk_bulk clks;
> > > +       void *base;
> > > +};
> > > +
> > > +dma_addr_t apple_dart_bus_start;
> > > +phys_addr_t apple_dart_phys_start;
> > > +phys_size_t apple_dart_size = SZ_512M;
> >
> > Try to avoid variables in drivers. Can these go in a priv struct?
>
> Not really since the intent is that these variables specify a global
> "window" that is mapped 1:1 into all the DARTs.

So there are multiple DART devices? In that can you could store this
info in a priv struct attached to the uclass.

[..]

> > > +static int apple_dart_bind(struct udevice *dev)
> > > +{
> > > +       void *base;
> > > +       int sid, i;
> > > +
> > > +       base = dev_read_addr_ptr(dev);
> > > +       if (!base)
> > > +               return -EINVAL;
> > > +
> > > +       u32 params2 = readl(base + DART_PARAMS2);
> > > +       if (params2 & DART_PARAMS2_BYPASS_SUPPORT) {
> > > +               for (sid = 0; sid < 16; sid++) {
> > > +                       writel(DART_TCR_BYPASS_DART | DART_TCR_BYPASS_DAPF,
> > > +                              base + DART_TCR(sid));
> > > +                       for (i = 0; i < 4; i++)
> > > +                               writel(0, base + DART_TTBR(sid, i));
> > > +               }
> > > +       }
> >
> > Not allowed hardware access in bind(). Can this more to probe() ?
>
> Well, I need to make sure that this happens before other drivers get
> probed (in particular the xhci-dwc3 driver).  Is there a better
> mechanism to achieve that?

If those drivers have something in the DT indicating that they need
this, then you can add a uclass_get_device_by_phandle() in those
drivers.

If not, then you can probe all the DART devices with uclass_probe_all().

Having said that, I see you are using UCLASS_MISC. I suspect this
should have its own UCLASS_IOMMU.

[..]

> >
> > > +               memset(l2, 0, SZ_16K);
> > > +
> > > +               for (j = 0; j < 2048; j++) {
> > > +                       l2[j] = phys | 0x3;
> > > +                       phys += SZ_16K;
> > > +               }
> > > +               flush_dcache_range((unsigned long)l2,
> > > +                                  (unsigned long)l2 + SZ_16K);
> > > +
> > > +               l1[i++] = (phys_addr_t)l2 | 0x8 | 0x3;
> >
> > Do you need the cast? What are the magic numbers here? Can you use an
> > enum/#define ?
>
> Not sure if we know the exact meaning of those bits yet.  But there is
> a Linux driver now, so maybe I need to look at it again.

Oh well, a comment that we don't know is fine, too. People can fix it
later if it becomes known.

[..]

Regards,
Simon

  reply	other threads:[~2021-09-21  1:12 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18 13:54 [PATCH 0/5] Apple M1 Support Mark Kettenis
2021-09-18 13:54 ` [PATCH 1/5] arm: apple: Add initial support for Apple's M1 SoC Mark Kettenis
2021-09-19  1:04   ` Bin Meng
2021-09-19  1:17     ` Bin Meng
2021-09-19 20:33       ` Mark Kettenis
2021-09-21 12:42         ` Tom Rini
2021-09-21 15:53           ` Bin Meng
2021-09-21 16:04             ` Tom Rini
2021-09-21 16:08             ` Mark Kettenis
2021-09-25 13:27               ` Simon Glass
2021-09-19 20:05     ` Mark Kettenis
2021-09-20  3:15   ` Simon Glass
2021-09-20  8:49     ` Mark Kettenis
2021-09-21  1:11       ` Simon Glass
2021-09-18 13:54 ` [PATCH 2/5] serial: s5p: Add Apple M1 support Mark Kettenis
2021-09-19  1:11   ` Bin Meng
2021-09-19 20:30     ` Mark Kettenis
2021-09-20  3:15   ` Simon Glass
2021-09-25 13:27     ` Simon Glass
2021-10-02 22:15     ` Mark Kettenis
2021-10-03  2:01       ` Simon Glass
2021-09-18 13:54 ` [PATCH 3/5] misc: Add Apple DART driver Mark Kettenis
2021-09-20  3:16   ` Simon Glass
2021-09-20  8:33     ` Mark Kettenis
2021-09-21  1:11       ` Simon Glass [this message]
2021-09-25 13:27         ` Simon Glass
2021-09-26 20:53         ` Mark Kettenis
2021-09-27 20:14           ` Simon Glass
2021-09-18 13:54 ` [PATCH 4/5] arm: dts: apple: Add preliminary device trees Mark Kettenis
2021-09-20  3:16   ` Simon Glass
2021-09-25 13:27     ` Simon Glass
2021-09-18 13:54 ` [PATCH 5/5] doc: board: apple: Add Apple M1 documentation Mark Kettenis
2021-09-19  1:22   ` Bin Meng
2021-09-20  3:16   ` Simon Glass
2021-09-25 13:27     ` Simon Glass
2021-09-20  8:45   ` Igor Opaniuk
2021-09-25  1:20 ` [PATCH 0/5] Apple M1 Support Simon Glass
2021-09-25  8:11   ` Mark Kettenis
2021-09-25 13:27     ` Simon Glass
2021-09-25 13:52       ` Mark Kettenis
2021-09-25 14:42         ` Simon Glass
2021-09-25 16:45           ` Mark Kettenis
2021-09-26 15:53             ` Simon Glass
2021-09-28  3:46               ` Simon Glass
2021-09-28  7:36                 ` Mark Kettenis
2021-09-28 12:07                   ` 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=CAPnjgZ02UE8ZNiNv7e8h54e94P5Ykok6GZiqzvg7RgBe+sPEtg@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ashe@kivikakk.ee \
    --cc=bin.meng@windriver.com \
    --cc=hs@denx.de \
    --cc=igor.opaniuk@foundries.io \
    --cc=kettenis@openbsd.org \
    --cc=kishon@ti.com \
    --cc=mark.kettenis@xs4all.nl \
    --cc=masami.hiramatsu@linaro.org \
    --cc=michael@walle.cc \
    --cc=michal.simek@xilinx.com \
    --cc=oliver.graute@kococonnector.com \
    --cc=p.yadav@ti.com \
    --cc=padmarao.begari@microchip.com \
    --cc=priyanka.jain@nxp.com \
    --cc=sr@denx.de \
    --cc=stephan@gerhold.net \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=vabhav.sharma@nxp.com \
    --cc=wasim.khan@nxp.com \
    --cc=weijie.gao@mediatek.com \
    --cc=xypron.glpk@gmx.de \
    --cc=ycliang@andestech.com \
    --cc=ye.li@nxp.com \
    --subject='Re: [PATCH 3/5] misc: Add Apple DART driver' \
    /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

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.