blob: 2faacb8f3b6f142ccb66ba883fccb8505b33ff50 [file] [log] [blame]
Mark Kettenis357a2562021-10-23 16:58:05 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
4 */
5
6#include <common.h>
7#include <cpu_func.h>
8#include <dm.h>
9#include <asm/io.h>
10
11#define DART_PARAMS2 0x0004
12#define DART_PARAMS2_BYPASS_SUPPORT BIT(0)
13#define DART_TLB_OP 0x0020
14#define DART_TLB_OP_OPMASK (0xfff << 20)
15#define DART_TLB_OP_FLUSH (0x001 << 20)
16#define DART_TLB_OP_BUSY BIT(2)
17#define DART_TLB_OP_SIDMASK 0x0034
18#define DART_ERROR_STATUS 0x0040
19#define DART_TCR(sid) (0x0100 + 4 * (sid))
20#define DART_TCR_TRANSLATE_ENABLE BIT(7)
21#define DART_TCR_BYPASS_DART BIT(8)
22#define DART_TCR_BYPASS_DAPF BIT(12)
23#define DART_TTBR(sid, idx) (0x0200 + 16 * (sid) + 4 * (idx))
24#define DART_TTBR_VALID BIT(31)
25#define DART_TTBR_SHIFT 12
26
Janne Grunau06c61d52022-07-01 00:06:16 +020027#define DART_T8110_TCR(sid) (0x1000 + 4 * (sid))
28#define DART_T8110_TCR_BYPASS_DAPF BIT(2)
29#define DART_T8110_TCR_BYPASS_DART BIT(1)
30#define DART_T8110_TCR_TRANSLATE_ENABLE BIT(0)
31#define DART_T8110_TTBR(sid) (0x1400 + 4 * (sid))
32
Mark Kettenis357a2562021-10-23 16:58:05 +020033static int apple_dart_probe(struct udevice *dev)
34{
35 void *base;
36 int sid, i;
37
38 base = dev_read_addr_ptr(dev);
39 if (!base)
40 return -EINVAL;
41
42 u32 params2 = readl(base + DART_PARAMS2);
Janne Grunau06c61d52022-07-01 00:06:16 +020043 if (!(params2 & DART_PARAMS2_BYPASS_SUPPORT))
44 return 0;
45
46 if (device_is_compatible(dev, "apple,t8112-dart")) {
47 for (sid = 0; sid < 256; sid++) {
48 writel(DART_T8110_TCR_BYPASS_DART | DART_T8110_TCR_BYPASS_DAPF,
49 base + DART_T8110_TCR(sid));
50 writel(0, base + DART_T8110_TTBR(sid));
51 }
52 } else {
Mark Kettenis357a2562021-10-23 16:58:05 +020053 for (sid = 0; sid < 16; sid++) {
54 writel(DART_TCR_BYPASS_DART | DART_TCR_BYPASS_DAPF,
55 base + DART_TCR(sid));
56 for (i = 0; i < 4; i++)
57 writel(0, base + DART_TTBR(sid, i));
58 }
59 }
60
61 return 0;
62}
63
64static const struct udevice_id apple_dart_ids[] = {
65 { .compatible = "apple,t8103-dart" },
Janne Grunau622a0582022-02-08 22:27:49 +010066 { .compatible = "apple,t6000-dart" },
Janne Grunau06c61d52022-07-01 00:06:16 +020067 { .compatible = "apple,t8112-dart" },
Mark Kettenis357a2562021-10-23 16:58:05 +020068 { /* sentinel */ }
69};
70
71U_BOOT_DRIVER(apple_dart) = {
72 .name = "apple_dart",
73 .id = UCLASS_IOMMU,
74 .of_match = apple_dart_ids,
75 .probe = apple_dart_probe
76};