Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1546C433EF for ; Mon, 11 Oct 2021 16:41:44 +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 4AA4060F38 for ; Mon, 11 Oct 2021 16:41:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4AA4060F38 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=openbsd.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 EA3D083719; Mon, 11 Oct 2021 18:41:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id F3B2B83710; Mon, 11 Oct 2021 18:40:58 +0200 (CEST) Received: from lb3-smtp-cloud9.xs4all.net (lb3-smtp-cloud9.xs4all.net [194.109.24.30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AA18083273 for ; Mon, 11 Oct 2021 18:40:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=kettenis@openbsd.org Received: from cust-df1d398c ([IPv6:fc0c:c1f5:9ac0:c45f:1583:5c5b:91fa:2436]) by smtp-cloud9.xs4all.net with ESMTPA id ZyLwmfrbW8cVwZyM5m7Jqa; Mon, 11 Oct 2021 18:40:49 +0200 From: Mark Kettenis To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, Mark Kettenis Subject: [PATCH v3 5/7] iommu: Add Apple DART driver Date: Mon, 11 Oct 2021 18:40:32 +0200 Message-Id: <20211011164034.6421-6-kettenis@openbsd.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011164034.6421-1-kettenis@openbsd.org> References: <20211011164034.6421-1-kettenis@openbsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfDdiBKJPXqSLLyc+VR6BMkSa47KddglfLnGKfCAuOKC1jxXQl4wk1m3tr/jiDvVUlvNbq6WEOL3s2dch3/k1tshYKbtf2687uXZ9VnnzLGLjPmqoGXlr U8y6gDHjiwYypCumgNu3fE27vDVWY4z0sFMAahKCJluW5lI45OTsRsUCEbs55RP+CKgkVfpqRkq8Or0XznOQRD/ox1oQVXGRGhg+4I8r8VPY8j4lANJPDt5q /XjG9uuKA/4LCRO6wmbNZGFiOuvPIg+zv6lCso6tO9IzJeZvnuoHBT+7vpGCpLgh 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 The DART is an IOMMU that is used on Apple's M1 SoC. This driver configures the DART such that it operates in bypass mode which is enough to support DMA for the USB3 ports integrated on the SoC. Signed-off-by: Mark Kettenis --- arch/arm/Kconfig | 1 + drivers/iommu/Kconfig | 10 +++++++ drivers/iommu/Makefile | 1 + drivers/iommu/apple_dart.c | 59 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 drivers/iommu/apple_dart.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index c3ddd8af52..39420c48ad 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -934,6 +934,7 @@ config ARCH_APPLE select DM_SERIAL select DM_USB select DM_VIDEO + select IOMMU select LINUX_KERNEL_IMAGE_HEADER select OF_CONTROL select OF_BOARD diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 8cb377560e..51694c168c 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -10,4 +10,14 @@ config IOMMU help Enable driver model for IOMMU devices. +config APPLE_DART + bool "Apple DART support" + depends on IOMMU && ARCH_APPLE + default y + help + Enable support for the DART on Apple SoCs. The DART is Apple's + IOMMU implementation. The driver performs the necessary + configuration to put the DART into bypass mode such that it can + be used transparently by U-Boot. + endmenu diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index af1c6bbb7a..e3e0900e17 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_IOMMU) += iommu-uclass.o +obj-$(CONFIG_APPLE_DART) += apple_dart.o obj-$(CONFIG_SANDBOX) += sandbox_iommu.o diff --git a/drivers/iommu/apple_dart.c b/drivers/iommu/apple_dart.c new file mode 100644 index 0000000000..ff8c5fa62c --- /dev/null +++ b/drivers/iommu/apple_dart.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Mark Kettenis + */ + +#include +#include +#include +#include + +#define DART_PARAMS2 0x0004 +#define DART_PARAMS2_BYPASS_SUPPORT BIT(0) +#define DART_TLB_OP 0x0020 +#define DART_TLB_OP_OPMASK (0xfff << 20) +#define DART_TLB_OP_FLUSH (0x001 << 20) +#define DART_TLB_OP_BUSY BIT(2) +#define DART_TLB_OP_SIDMASK 0x0034 +#define DART_ERROR_STATUS 0x0040 +#define DART_TCR(sid) (0x0100 + 4 * (sid)) +#define DART_TCR_TRANSLATE_ENABLE BIT(7) +#define DART_TCR_BYPASS_DART BIT(8) +#define DART_TCR_BYPASS_DAPF BIT(12) +#define DART_TTBR(sid, idx) (0x0200 + 16 * (sid) + 4 * (idx)) +#define DART_TTBR_VALID BIT(31) +#define DART_TTBR_SHIFT 12 + +static int apple_dart_probe(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)); + } + } + + return 0; +} + +static const struct udevice_id apple_dart_ids[] = { + { .compatible = "apple,t8103-dart" }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(apple_dart) = { + .name = "apple_dart", + .id = UCLASS_IOMMU, + .of_match = apple_dart_ids, + .probe = apple_dart_probe +}; -- 2.33.0