From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9345C433EF for ; Tue, 21 Sep 2021 01:12:13 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2230A610A1 for ; Tue, 21 Sep 2021 01:12:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2230A610A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D73F382DB0; Tue, 21 Sep 2021 03:12:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ri7lOifi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 77DBB8326B; Tue, 21 Sep 2021 03:11:51 +0200 (CEST) Received: from mail-ua1-x92a.google.com (mail-ua1-x92a.google.com [IPv6:2607:f8b0:4864:20::92a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0A7108328D for ; Tue, 21 Sep 2021 03:11:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-ua1-x92a.google.com with SMTP id 6so1607509uac.1 for ; Mon, 20 Sep 2021 18:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iN7OqeDqCTDyvUvXb9ZO4U1liKzSIiId5DinARtML2E=; b=Ri7lOifiLit/7s4Cjbc2SpKyzA8HNmeofmaqjkIuIZUMzo7epdRIwGd/AzG0V+gdMO f4TLyNI5xsFbA8/8swrZtyHWvdJfCeV6Jvh2Z+A8AWFnWLV2iNQOtTgaGYoTaW6Ig1e1 ZTfO0FLDlbIw599KcTOIwYo3fZ3DVINLSzCn0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iN7OqeDqCTDyvUvXb9ZO4U1liKzSIiId5DinARtML2E=; b=VlqPbRELkC0x56MBoQd5z+VF4nCxfkQpjwJdLhss1Fonu7ieoAawPhWWrQcoo20mis BMBvmRCy0/pDhsZQfQ8zmyJlug1DAaEcN0DwelnfHvH68PhJsjXnUpVX+2VbqbGHKsvc 8VubXgZJE/AiEIm5GjSkuA2fTMez68Ig+z9i+8I5kQfZiTrIQpZ0XAELwQygbI6NWzj/ HysPdj7QvjOA+3wABau7C9e0owXmomNzG9ZNQiqgb2kxAktFhh0nsSS+2UM3axfPTRJ9 ozm7BEZJrriAuo96AFzTYYI8nJnWWYecH5bzuiwTBYH0/mrRtHoowDvD3qz0m8gO4XYG kf9Q== X-Gm-Message-State: AOAM533sIJRvcefH/OETu0aH/7iI174ptt2lnmbcnDyeNP/eNnlMX8no T0eGFUcbwF/4cLi/eTrVrdu9z5AoxQzNVsRK3mu+CA== X-Google-Smtp-Source: ABdhPJyAY02vBcYUsG1H4Jjbywv0URpmIYHaxBDMbBGRg8VFZEBW8jmT7AVhBJaVZGz4NiIiZzztFWLiZGXnDnsj+GU= X-Received: by 2002:ab0:6d8b:: with SMTP id m11mr14529017uah.35.1632186697133; Mon, 20 Sep 2021 18:11:37 -0700 (PDT) MIME-Version: 1.0 References: <20210918135437.36667-1-kettenis@openbsd.org> <20210918135437.36667-4-kettenis@openbsd.org> <56146d936d16f96c@bloch.sibelius.xs4all.nl> In-Reply-To: <56146d936d16f96c@bloch.sibelius.xs4all.nl> From: Simon Glass Date: Mon, 20 Sep 2021 19:11:25 -0600 Message-ID: Subject: Re: [PATCH 3/5] misc: Add Apple DART driver To: Mark Kettenis Cc: Mark Kettenis , U-Boot Mailing List , Oliver Graute , Stephan Gerhold , Masami Hiramatsu , Priyanka Jain , Leo Liang , Padmarao Begari , Michael Walle , Kishon Vijay Abraham I , Heinrich Schuchardt , Bin Meng , Asherah Connor , Michal Simek , Wasim Khan , Heiko Schocher , Igor Opaniuk , Ye Li , Stefan Roese , AKASHI Takahiro , Weijie Gao , Vabhav Sharma , Andy Shevchenko , Pratyush Yadav Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Mark, On Mon, 20 Sept 2021 at 02:33, Mark Kettenis wrote: > > > From: Simon Glass > > Date: Sun, 19 Sep 2021 21:16:00 -0600 > > > > Hi Mark, > > > > On Sat, 18 Sept 2021 at 07:55, Mark Kettenis 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 > > > --- > > > 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