Mark Kettenis | 357a256 | 2021-10-23 16:58:05 +0200 | [diff] [blame] | 1 | // 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 Grunau | 06c61d5 | 2022-07-01 00:06:16 +0200 | [diff] [blame] | 27 | #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 Kettenis | 357a256 | 2021-10-23 16:58:05 +0200 | [diff] [blame] | 33 | static 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 Grunau | 06c61d5 | 2022-07-01 00:06:16 +0200 | [diff] [blame] | 43 | 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 Kettenis | 357a256 | 2021-10-23 16:58:05 +0200 | [diff] [blame] | 53 | 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 | |
| 64 | static const struct udevice_id apple_dart_ids[] = { |
| 65 | { .compatible = "apple,t8103-dart" }, |
Janne Grunau | 622a058 | 2022-02-08 22:27:49 +0100 | [diff] [blame] | 66 | { .compatible = "apple,t6000-dart" }, |
Janne Grunau | 06c61d5 | 2022-07-01 00:06:16 +0200 | [diff] [blame] | 67 | { .compatible = "apple,t8112-dart" }, |
Mark Kettenis | 357a256 | 2021-10-23 16:58:05 +0200 | [diff] [blame] | 68 | { /* sentinel */ } |
| 69 | }; |
| 70 | |
| 71 | U_BOOT_DRIVER(apple_dart) = { |
| 72 | .name = "apple_dart", |
| 73 | .id = UCLASS_IOMMU, |
| 74 | .of_match = apple_dart_ids, |
| 75 | .probe = apple_dart_probe |
| 76 | }; |