Skip to content

Commit 374f261

Browse files
asdfugilsvenpeter42
authored andcommitted
sart: Add SARTv0 support
SARTv0 is used on Apple A11 SoC. Signed-off-by: Nick Chan <towinchenmi@gmail.com>
1 parent 9eeefda commit 374f261

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

src/sart.c

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ struct sart_dev {
1818

1919
#define APPLE_SART_MAX_ENTRIES 16
2020

21+
/* SARTv0 registers */
22+
#define APPLE_SART0_CONFIG(idx) (0x00 + 4 * (idx))
23+
#define APPLE_SART0_CONFIG_FLAGS GENMASK(28, 24)
24+
#define APPLE_SART0_CONFIG_SIZE GENMASK(18, 0)
25+
#define APPLE_SART0_CONFIG_SIZE_SHIFT 12
26+
#define APPLE_SART0_CONFIG_SIZE_MAX GENMASK(18, 0)
27+
28+
#define APPLE_SART0_PADDR(idx) (0x40 + 4 * (idx))
29+
#define APPLE_SART0_PADDR_SHIFT 12
30+
31+
#define APPLE_SART0_FLAGS_ALLOW 0xf
32+
2133
/* SARTv2 registers */
2234
#define APPLE_SART2_CONFIG(idx) (0x00 + 4 * (idx))
2335
#define APPLE_SART2_CONFIG_FLAGS GENMASK(31, 24)
@@ -42,6 +54,40 @@ struct sart_dev {
4254

4355
#define APPLE_SART3_FLAGS_ALLOW 0xff
4456

57+
static void sart0_get_entry(sart_dev_t *sart, int index, u8 *flags, void **paddr, size_t *size)
58+
{
59+
u32 cfg = read32(sart->base + APPLE_SART0_CONFIG(index));
60+
*flags = FIELD_GET(APPLE_SART0_CONFIG_FLAGS, cfg);
61+
*size = (size_t)FIELD_GET(APPLE_SART0_CONFIG_SIZE, cfg) << APPLE_SART0_CONFIG_SIZE_SHIFT;
62+
*paddr =
63+
(void *)((u64)read32(sart->base + APPLE_SART0_PADDR(index)) << APPLE_SART0_PADDR_SHIFT);
64+
}
65+
66+
static bool sart0_set_entry(sart_dev_t *sart, int index, u8 flags, void *paddr_, size_t size)
67+
{
68+
u32 cfg;
69+
u64 paddr = (u64)paddr_;
70+
71+
if (size & ((1 << APPLE_SART0_CONFIG_SIZE_SHIFT) - 1))
72+
return false;
73+
if (paddr & ((1 << APPLE_SART0_PADDR_SHIFT) - 1))
74+
return false;
75+
76+
size >>= APPLE_SART0_CONFIG_SIZE_SHIFT;
77+
paddr >>= APPLE_SART0_PADDR_SHIFT;
78+
79+
if (size > APPLE_SART0_CONFIG_SIZE_MAX)
80+
return false;
81+
82+
cfg = FIELD_PREP(APPLE_SART0_CONFIG_FLAGS, flags);
83+
cfg |= FIELD_PREP(APPLE_SART0_CONFIG_SIZE, size);
84+
85+
write32(sart->base + APPLE_SART0_PADDR(index), paddr);
86+
write32(sart->base + APPLE_SART0_CONFIG(index), cfg);
87+
88+
return true;
89+
}
90+
4591
static void sart2_get_entry(sart_dev_t *sart, int index, u8 *flags, void **paddr, size_t *size)
4692
{
4793
u32 cfg = read32(sart->base + APPLE_SART2_CONFIG(index));
@@ -121,9 +167,14 @@ sart_dev_t *sart_init(const char *adt_path)
121167
}
122168

123169
const u32 *sart_version = adt_getprop(adt, node, "sart-version", NULL);
170+
const u32 sart_version_zero = 0;
124171
if (!sart_version) {
125-
printf("sart: SART %s has no sart-version property\n", adt_path);
126-
return NULL;
172+
if (adt_is_compatible(adt, node, "sart,t8015")) {
173+
sart_version = &sart_version_zero;
174+
} else {
175+
printf("sart: SART %s has no sart-version property\n", adt_path);
176+
return NULL;
177+
}
127178
}
128179

129180
sart_dev_t *sart = calloc(1, sizeof(*sart));
@@ -133,6 +184,10 @@ sart_dev_t *sart_init(const char *adt_path)
133184
sart->base = base;
134185

135186
switch (*sart_version) {
187+
case 0:
188+
sart->get_entry = sart0_get_entry;
189+
sart->set_entry = sart0_set_entry;
190+
sart->flags_allow = APPLE_SART0_FLAGS_ALLOW;
136191
case 2:
137192
sart->get_entry = sart2_get_entry;
138193
sart->set_entry = sart2_set_entry;

0 commit comments

Comments
 (0)