Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
RPMh's sequencer under one lock: the audio DSP's and the modem's drivers asked through TCS 0 at the same time
shimoku74e5b01a04b942
diff --git a/xnu/files/bsd/dev/redwood_adsp.c b/xnu/files/bsd/dev/redwood_adsp.cindex 1c68ea1..b331003 100644--- a/xnu/files/bsd/dev/redwood_adsp.c+++ b/xnu/files/bsd/dev/redwood_adsp.c@@ -109,6 +109,7 @@ extern int mdevgetkernelrange(dev_t dev, vm_offset_t *base, uint64_t *size);/* What the Wi-Fi's DSP and this one both use (redwood_wifi.c). */extern lck_mtx_t redwood_aop_mailbox_lock;extern lck_mtx_t redwood_smem_alloc_lock;+extern lck_mtx_t redwood_rsc_lock; /* RPMh's sequencer, shared with the other DSP's driver */static LCK_GRP_DECLARE(adsp_lock_group, "redwood-adsp");@@ -896,10 +897,12 @@ rails(uint32_t level)values[r] = (uint32_t)position;}need(&rsc);+ lck_mtx_lock(&redwood_rsc_lock);/* (the boot loader leaves the trigger set after its last request, done: idle is what the status says) */if (rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS) == 0) {printf("adsp: %u: TCS %u of the sequencer is busy (status %#x, control %#x): the rails are not asked\n", step, RPMH_TCS,rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS), rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL));+ lck_mtx_unlock(&redwood_rsc_lock);return false;}printf("adsp: %u: about to ask RPMh, through TCS %u, for lcx.lvl (%#x) = %u and lmx.lvl (%#x) = %u (level %u%s)\n", step,@@ -932,6 +935,7 @@ rails(uint32_t level)wr(rsc.base + RSC_IRQ_CLEAR, 1u << RPMH_TCS);wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL, rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL) & ~(TCS_TRIGGER | TCS_ACTIVE_MODE));wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_ENABLED, 0);+ lck_mtx_unlock(&redwood_rsc_lock);return done != 0;}diff --git a/xnu/files/bsd/dev/redwood_mpss.c b/xnu/files/bsd/dev/redwood_mpss.cindex 54bdc99..4a09ae9 100644--- a/xnu/files/bsd/dev/redwood_mpss.c+++ b/xnu/files/bsd/dev/redwood_mpss.c@@ -95,6 +95,7 @@ extern void FlushPoC_DcacheRegion(vm_offset_t va, size_t length); /* osfmk/arm/* What the Wi-Fi's DSP and this one both use (redwood_wifi.c). */extern lck_mtx_t redwood_aop_mailbox_lock;extern lck_mtx_t redwood_smem_alloc_lock;+extern lck_mtx_t redwood_rsc_lock; /* RPMh's sequencer, shared with the other DSP's driver */static LCK_GRP_DECLARE(mpss_lock_group, "redwood-mpss");@@ -892,10 +893,12 @@ rails(uint32_t level)values[r] = (uint32_t)position;}need(&rsc);+ lck_mtx_lock(&redwood_rsc_lock);/* (the boot loader leaves the trigger set after its last request, done: idle is what the status says) */if (rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS) == 0) {printf("mpss: %u: TCS %u of the sequencer is busy (status %#x, control %#x): the rails are not asked\n", step, RPMH_TCS,rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS), rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL));+ lck_mtx_unlock(&redwood_rsc_lock);return false;}printf("mpss: %u: about to ask RPMh, through TCS %u, for cx.lvl (%#x) = %u and mss.lvl (%#x) = %u (level %u%s)\n", step,@@ -928,6 +931,7 @@ rails(uint32_t level)wr(rsc.base + RSC_IRQ_CLEAR, 1u << RPMH_TCS);wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL, rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL) & ~(TCS_TRIGGER | TCS_ACTIVE_MODE));wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_ENABLED, 0);+ lck_mtx_unlock(&redwood_rsc_lock);return done != 0;}@@ -949,8 +953,10 @@ rpmh_command(const char *name, uint32_t value)return false;}need(&rsc);+ lck_mtx_lock(&redwood_rsc_lock);if (rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_STATUS) == 0) {printf("mpss: %u: TCS %u of the sequencer is busy: \"%s\" is not asked\n", step, RPMH_TCS, name);+ lck_mtx_unlock(&redwood_rsc_lock);return false;}printf("mpss: %u: about to ask RPMh, through TCS %u, for %s (%#x) = %#x\n", step, RPMH_TCS, name, address, value);@@ -979,6 +985,7 @@ rpmh_command(const char *name, uint32_t value)wr(rsc.base + RSC_IRQ_CLEAR, 1u << RPMH_TCS);wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL, rd(rsc.base + RSC_TCS(RPMH_TCS) + TCS_CONTROL) & ~(TCS_TRIGGER | TCS_ACTIVE_MODE));wr(rsc.base + RSC_TCS(RPMH_TCS) + TCS_ENABLED, 0);+ lck_mtx_unlock(&redwood_rsc_lock);return done != 0;}diff --git a/xnu/files/bsd/dev/redwood_wifi.c b/xnu/files/bsd/dev/redwood_wifi.cindex c7751c1..4185611 100644--- a/xnu/files/bsd/dev/redwood_wifi.c+++ b/xnu/files/bsd/dev/redwood_wifi.c@@ -189,6 +189,7 @@ static LCK_GRP_DECLARE(wifi_lock_group, "redwood-wifi");*/LCK_MTX_DECLARE(redwood_aop_mailbox_lock, &wifi_lock_group);LCK_MTX_DECLARE(redwood_smem_alloc_lock, &wifi_lock_group);+LCK_MTX_DECLARE(redwood_rsc_lock, &wifi_lock_group); /* RPMh's sequencer (TCS 0 of the RSC): the audio DSP's and the modem's drivers both ask through it *//* ... and the sound's (redwood_sound.c): a free match register and context of the SMMU, found and taken */LCK_MTX_DECLARE(redwood_smmu_lock, &wifi_lock_group);