Skip to content

Commit e639908

Browse files
marcankettenis
authored andcommitted
arm: apple: rtkit: Support allocating OSLog out of SRAM in helper
The new OSLog region in MTP (firmware 13.3+) persists on handoff to Linux. To avoid having to come up with some weird DART handoff or DAPF tricks, let's just steal some of the coprocessor's dedicated SRAM. This keeps it happy and Linux doesn't need any special handoff then. Signed-off-by: Hector Martin <[email protected]>
1 parent 19ff75a commit e639908

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

arch/arm/mach-apple/rtkit_helper.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,60 @@
1616
#define REG_CPU_CTRL 0x0044
1717
#define REG_CPU_CTRL_RUN BIT(4)
1818

19+
#define APPLE_RTKIT_EP_OSLOG 8
20+
1921
struct rtkit_helper_priv {
2022
void *asc; /* ASC registers */
2123
struct mbox_chan chan;
2224
struct apple_rtkit *rtk;
25+
bool sram_stolen;
2326
};
2427

28+
static int shmem_setup(void *cookie, struct apple_rtkit_buffer *buf) {
29+
struct udevice *dev = cookie;
30+
struct rtkit_helper_priv *priv = dev_get_priv(dev);
31+
32+
if (!buf->is_mapped) {
33+
/*
34+
* Special case: The OSLog buffer on MTP persists on Linux handoff.
35+
* Steal some SRAM instead of putting this in DRAM, so we don't
36+
* have to hand off DART/DAPF mappings.
37+
*/
38+
if (buf->endpoint == APPLE_RTKIT_EP_OSLOG) {
39+
if (priv->sram_stolen) {
40+
printf("%s: Tried to map more than one OSLog buffer out of SRAM\n",
41+
__func__);
42+
} else {
43+
fdt_size_t size;
44+
fdt_addr_t addr;
45+
46+
addr = dev_read_addr_size_name(dev, "sram", &size);
47+
48+
if (addr != FDT_ADDR_T_NONE) {
49+
buf->dva = ALIGN_DOWN(addr + size - buf->size, SZ_16K);
50+
priv->sram_stolen = true;
51+
52+
return 0;
53+
} else {
54+
printf("%s: No SRAM, falling back to DRAM\n", __func__);
55+
}
56+
}
57+
}
58+
59+
buf->buffer = memalign(SZ_16K, ALIGN(buf->size, SZ_16K));
60+
if (!buf->buffer)
61+
return -ENOMEM;
62+
63+
buf->dva = (u64)buf->buffer;
64+
}
65+
return 0;
66+
}
67+
68+
static void shmem_destroy(void *cookie, struct apple_rtkit_buffer *buf) {
69+
if (buf->buffer)
70+
free(buf->buffer);
71+
}
72+
2573
static int rtkit_helper_probe(struct udevice *dev)
2674
{
2775
struct rtkit_helper_priv *priv = dev_get_priv(dev);
@@ -39,7 +87,7 @@ static int rtkit_helper_probe(struct udevice *dev)
3987
ctrl = readl(priv->asc + REG_CPU_CTRL);
4088
writel(ctrl | REG_CPU_CTRL_RUN, priv->asc + REG_CPU_CTRL);
4189

42-
priv->rtk = apple_rtkit_init(&priv->chan, priv, NULL, NULL);
90+
priv->rtk = apple_rtkit_init(&priv->chan, dev, shmem_setup, shmem_destroy);
4391
if (!priv->rtk)
4492
return -ENOMEM;
4593

0 commit comments

Comments
 (0)