From bdb0b149e156dea2a9dcf7474890e16a596f126c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Fri, 30 Oct 2026 00:22:24 +0100 Subject: [PATCH 001/342] soc: apple: sep: Open the host-state store only for each operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store::open() opens /var/lib/aurora-sep-host-state.bin read-write, and the store keeps the file open until the driver goes away, in practice until power-off. The driver opens it from the kernel, so no task holds it, and killing every process at shutdown does not close it. The file system it lives on can then be neither unmounted nor remounted read-only: every poweroff logs Failed to unmount /persist: Device or resource busy and the file system stays mounted read-write until the machine powers off. This hits any setup where the store is not on the root file system, such as an impermanent root that keeps /var/lib state on a /persist file system through a symlink. Keep the slot table in memory as before, and open the file only to load it, to read a record and for each write, closing it when the operation returns. The write sequence and the on-disk format do not change. The keybag, ref-key and catacomb files are already opened per use, and the xART store is a block device under /dev. Store is now generic over a StoreSource that opens the backing file. An open StoreIo that is Copy is its own source, so the KUnit tests keep using their in-memory files unchanged. Fixes: 24d20c9828b8 ("soc: apple: add Apple SEP driver (Touch ID and key sealing)") Assisted-by: LLM Signed-off-by: Andrzej Broński --- drivers/soc/apple/store.rs | 100 ++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 28 deletions(-) diff --git a/drivers/soc/apple/store.rs b/drivers/soc/apple/store.rs index e3abe11c7d5c8..f5ee54b375335 100644 --- a/drivers/soc/apple/store.rs +++ b/drivers/soc/apple/store.rs @@ -131,9 +131,42 @@ impl StoreIo for shim::StoreFile { } } +/// Where a [`Store`] reaches its backing file. Every operation opens it and +/// closes it again before returning. +pub(crate) trait StoreSource { + type Io: StoreIo; + fn open(&self) -> Result; +} + +/// A file that is already open is its own source, as the tests' in-memory +/// files are. +impl StoreSource for T { + type Io = T; + + fn open(&self) -> Result { + Ok(*self) + } +} + +/// The host-state file at [`STORE_PATH`]. +pub(crate) struct HostFile; + +impl StoreSource for HostFile { + type Io = shim::StoreFile; + + fn open(&self) -> Result { + shim::StoreFile::open_host(STORE_PATH).map(|(file, _)| file) + } +} + // Not internally locked; the caller holds a mutex around all access. -pub(crate) struct Store { - file: F, +// +// The store keeps its table in memory and holds no open file between +// operations. The driver opens the file from the kernel, so no task owns it: +// held open for writing, it would pin its file system until power-off, which +// could then be neither unmounted nor remounted read-only. +pub(crate) struct Store { + source: S, slots: [Slot; SLOT_COUNT], generation: u64, } @@ -242,14 +275,21 @@ fn decode(sb: &[u8], slots: &mut [Slot; SLOT_COUNT]) -> Result<(), Damage> { impl Store { pub(crate) fn open() -> Result { let (file, created) = shim::StoreFile::open_host(STORE_PATH)?; - Self::from_file(file, created) + Self::load(HostFile, &file, created) } } -impl Store { - fn from_file(file: F, created: bool) -> Result { +impl Store { + #[cfg(CONFIG_APPLE_SEP_KUNIT_TEST)] + fn from_file(source: S, created: bool) -> Result { + let file = source.open()?; + Self::load(source, &file, created) + } + + /// Loads the store from `file`, the open backing file of `source`. + fn load(source: S, file: &S::Io, created: bool) -> Result { let mut store = Store { - file, + source, slots: [Slot::FREE; SLOT_COUNT], generation: 0, }; @@ -257,9 +297,9 @@ impl Store { // New files and interrupted empty or all-zero creations hold no state. // Any other existing file may hold the only copy of the host state, // so one that does not validate is refused and left as it is. - let size = store.file.size()?; + let size = file.size()?; if created && size == 0 { - store.create()?; + store.create(file)?; pr_info!("created a new host-state store\n"); return Ok(store); } @@ -267,19 +307,19 @@ impl Store { let mut sb = KVec::with_capacity(BLOCK_SIZE, GFP_KERNEL)?; sb.resize(BLOCK_SIZE, 0, GFP_KERNEL)?; let decoded = if size == STORE_SIZE as u64 { - store.file.read_exact(0, &mut sb)?; + file.read_exact(0, &mut sb)?; decode(&sb, &mut store.slots) } else { Err(Damage::Size) }; if let Err(damage) = decoded { if matches!(damage, Damage::Size | Damage::Header) { - if let Some(what) = describe(&store.file, size) { + if let Some(what) = describe(file, size) { pr_warn!( "host-state store file is {} and holds no state; initialising it\n", what ); - store.create()?; + store.create(file)?; return Ok(store); } } @@ -303,26 +343,26 @@ impl Store { EIO } - fn create(&mut self) -> Result<()> { + fn create(&mut self, file: &S::Io) -> Result<()> { self.slots = [Slot::FREE; SLOT_COUNT]; self.generation = 1; let mut zero = KVec::with_capacity(BLOCK_SIZE, GFP_KERNEL)?; zero.resize(BLOCK_SIZE, 0, GFP_KERNEL)?; for b in 0..BLOCK_COUNT { - self.file.write_all((b * BLOCK_SIZE) as u64, &zero)?; + file.write_all((b * BLOCK_SIZE) as u64, &zero)?; } - self.commit()?; + self.commit(file)?; Ok(()) } - fn commit(&mut self) -> Result<()> { - self.write_superblock(Intent::None)?; - self.file.sync() + fn commit(&mut self, file: &S::Io) -> Result<()> { + self.write_superblock(file, Intent::None)?; + file.sync() } - fn write_superblock(&mut self, intent: Intent) -> Result<()> { + fn write_superblock(&mut self, file: &S::Io, intent: Intent) -> Result<()> { let mut sb = KVec::with_capacity(BLOCK_SIZE, GFP_KERNEL)?; sb.resize(BLOCK_SIZE, 0, GFP_KERNEL)?; @@ -348,7 +388,7 @@ impl Store { sb[off + 18..off + 22].copy_from_slice(&slot.len.to_le_bytes()); } - self.file.write_all(0, &sb) + file.write_all(0, &sb) } fn find(&self, key: &Key) -> Option { @@ -374,7 +414,7 @@ impl Store { let mut value = KVec::with_capacity(len, GFP_KERNEL)?; value.resize(len, 0, GFP_KERNEL)?; if len > 0 { - self.file.read_exact(Self::block_offset(idx), &mut value)?; + self.source.open()?.read_exact(Self::block_offset(idx), &mut value)?; } Ok(Some(value)) } @@ -389,19 +429,23 @@ impl Store { let old = self.find(key); let fresh = self.find_free().ok_or(ENOSPC)?; + let file = self.source.open()?; // 1. Record the intent, durably, before touching any data block. - self.write_superblock(Intent::Write { - slot: fresh as u16, - kind: key.kind, - })?; - self.file.sync()?; + self.write_superblock( + &file, + Intent::Write { + slot: fresh as u16, + kind: key.kind, + }, + )?; + file.sync()?; // 2. Fill the new block and make it durable. if !value.is_empty() { - self.file.write_all(Self::block_offset(fresh), value)?; + file.write_all(Self::block_offset(fresh), value)?; } - self.file.sync()?; + file.sync()?; // 3. Switch the slot table, release the old block, clear the intent. self.slots[fresh] = Slot { @@ -414,7 +458,7 @@ impl Store { self.slots[old] = Slot::FREE; } self.generation = self.generation.wrapping_add(1); - self.commit() + self.commit(&file) } } From cf772cf8e32222ebe58940a7b9282b606b346eb5 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 2 Nov 2026 00:48:57 -0500 Subject: [PATCH 002/342] iommu/apple-dart-apif: Park a released device off its domain The driver provided neither a release_domain nor a translation change in release_device(), so a removed device left its SIDs enabled on the domain that the core frees next. When the same device came back, as the N1 Wi-Fi and Bluetooth functions do after a firmware reset removes and rescans them, its new domain was attached over that stale state, and the first DMA through it froze the machine. Provide a blocking release_domain. Its attach takes the released device's SIDs out of the domain it leaves the same way an attach unwind does: disable each SID, undo the domain's mappings on it and clear it from the domain. Retained SIDs keep their current handling. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/iommu/apple-dart-apif.c | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/iommu/apple-dart-apif.c b/drivers/iommu/apple-dart-apif.c index 7c1519c70e3bd..8b5792c1efd7e 100644 --- a/drivers/iommu/apple-dart-apif.c +++ b/drivers/iommu/apple-dart-apif.c @@ -1548,6 +1548,66 @@ apple_dart_apif_domain_alloc_paging(struct device *dev) return &dom->domain; } +/* + * The core attaches this before release_device(), so a released device no + * longer uses the domain that is about to be freed. Its SIDs leave that + * domain disabled, with the domain's mappings undone, as an attach unwind + * does. Without it the SIDs stayed enabled on the freed domain's tables, and + * the next attach of the same SIDs met that stale state. Retained SIDs keep + * their current handling. + */ +static int apple_dart_apif_release_attach(struct iommu_domain *domain, + struct device *dev, + struct iommu_domain *old) +{ + struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); + struct apple_dart_apif_domain *prior; + unsigned long flags; + unsigned int sid; + + if (!master || !old || old->owner != &apple_dart_apif_ops || + old->ops != apple_dart_apif_ops.default_domain_ops) + return 0; + prior = to_apif_domain(old); + mutex_lock(&prior->lock); + write_lock_irqsave(&prior->streams_lock, flags); + for (unsigned int i = 0; i < master->num_darts; i++) { + struct apple_dart_apif *dart = master->streams[i].dart; + struct apif_stream_map *before = apif_find_stream(prior, dart); + + if (!before) + continue; + spin_lock(&dart->batch_lock); + for_each_set_bit(sid, master->streams[i].sids, + dart->num_streams) { + if (dart->retained[sid] || !test_bit(sid, before->sids)) + continue; + dart->batch->count = 1; + dart->batch->op[0] = (struct apif_op){ + .op = APIF_DART_DISABLE, + .arg = { sid }, + }; + if (apif_ring(dart)) + dev_err(dart->dev, + "failed to disable SID %u at release\n", + sid); + apif_undo_replay(prior, before, sid, U64_MAX); + clear_bit(sid, before->sids); + } + spin_unlock(&dart->batch_lock); + } + write_unlock_irqrestore(&prior->streams_lock, flags); + mutex_unlock(&prior->lock); + return 0; +} + +static struct iommu_domain apple_dart_apif_release_domain = { + .type = IOMMU_DOMAIN_BLOCKED, + .ops = &(const struct iommu_domain_ops){ + .attach_dev = apple_dart_apif_release_attach, + }, +}; + static struct iommu_device *apple_dart_apif_probe_device(struct device *dev) { struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); @@ -1808,6 +1868,7 @@ static const struct iommu_ops apple_dart_apif_ops = { .domain_alloc_paging = apple_dart_apif_domain_alloc_paging, .probe_device = apple_dart_apif_probe_device, .release_device = apple_dart_apif_release_device, + .release_domain = &apple_dart_apif_release_domain, .device_group = apple_dart_apif_device_group, .of_xlate = apple_dart_apif_of_xlate, .owner = THIS_MODULE, From c0e42a1852a6dbd1a31b3321dbe1c0c6827a8d09 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 19:47:02 -0800 Subject: [PATCH 003/342] phy: apple: dptx: Add the T6050 variant The M5 Ultra's lpdptx PHY has the T602x bank layout: core plus dptx, with the PLL command at dptx+0x100c. Its PLL calibration, clocking, rate programming, AUX impedance calibration and PHY power follow the newer blocks. The T6020 sequence replays captured register words, and on this PHY it would program the wrong fields. Give T6050 its own sequence: - activate: core power for PLL, AUX and PHY (1 us apart); source select from the crossbar's ufp endpoint; the board's PLL calibration (DCOCFG split across 0x2240[2:1] and [6:4], DTCVREG, DTCCAL, DCDADJ, DLFCFG, optional RODCOROLEAKCOMP) and fixed settings; PLL setup with the pixel-clock driver selected by pclkdrv-select and single-ended clock out; lanes released; AUX up; impedance calibration, with its result copied into 0x4228. - link reconfiguration, as the DCP brackets it: PHY down, PLL down, lane count, rate, then PLL up and PHY up. A per-rate PLL record gives the divider and analog fields for 1.62 to 8.1 Gbit/s. PLL commands wait 100 us, then check the acknowledgment (0x1014[0]) and the lock (0x1008[3]) separately. - deactivate: the reverse. Every write is a field update. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 [erik: dropped the bring-up debugfs interface] Signed-off-by: Erik Bourget --- drivers/phy/apple/dptx.c | 433 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) diff --git a/drivers/phy/apple/dptx.c b/drivers/phy/apple/dptx.c index 5e58f149ce96a..f191efe4c6286 100644 --- a/drivers/phy/apple/dptx.c +++ b/drivers/phy/apple/dptx.c @@ -16,11 +16,14 @@ #include #include "linux/of.h" #include +#include +#include #include #include #include #include #include +#include #include #define DPTX_MAX_LANES 4 @@ -31,6 +34,23 @@ enum apple_dptx_type { DPTX_PHY_T8112, DPTX_PHY_T6020, + DPTX_PHY_T6050, +}; + +/* The PLL core calibration the board describes, in t6050_pll_core_cfg() order. */ +enum { + T6050_DCOCFG, + T6050_DTCVREG, + T6050_DTCCAL, + T6050_DCDADJ, + T6050_DLFCFG, + T6050_RODCOROLEAKCOMP, + T6050_NR_CAL, +}; + +static const char *const t6050_cal_props[T6050_NR_CAL] = { + "apple,pll-dcocfg", "apple,pll-dtcvreg", "apple,pll-dtccal", + "apple,pll-dcdadj", "apple,pll-dlfcfg", "apple,pll-rodcoroleakcomp", }; struct apple_dptx_phy_hw { @@ -49,6 +69,14 @@ struct apple_dptx_phy { void __iomem *dptx; } regs; + /* T6050 */ + u32 cal[T6050_NR_CAL]; + bool cal_set[T6050_NR_CAL]; + u32 source_select; + bool pclkdrv_select; + bool active; + u32 rate; /* Mbit/s; 0: none programmed */ + struct phy *phy_dp; struct phy_provider *phy_provider; @@ -523,10 +551,398 @@ static int dptx_phy_set_link_rate(struct apple_dptx_phy *phy, u32 link_rate) return 0; } +/* + * T6050 (M5 Ultra) lpdptx. The two banks are T602x's ("core" and "dptx", the + * PLL command register at dptx+0x100c), but the PLL calibration, clocking, + * rate programming, AUX calibration and PHY power are T8122/T8132's. Every + * write is a field update; nothing below replays a captured register word. + */ +static void t6050_rmw(void __iomem *base, u32 off, u32 shift, u32 mask, u32 val) +{ + mask32(base + off, mask, (val << shift) & mask); +} + +#define T6050_D(phy, off, shift, mask, val) \ + t6050_rmw((phy)->regs.dptx, off, shift, mask, val) +#define T6050_C(phy, off, shift, mask, val) \ + t6050_rmw((phy)->regs.core, off, shift, mask, val) + +/* core+0x48: PLL (bits 6:4), AUX (10:8) and PHY (2:0) power, 1 us apart. */ +static void t6050_block_power(struct apple_dptx_phy *phy, u32 lsb, bool on) +{ + if (on) { + T6050_C(phy, 0x48, lsb, BIT(lsb), 1); + udelay(1); + T6050_C(phy, 0x48, lsb + 1, BIT(lsb + 1), 1); + udelay(1); + T6050_C(phy, 0x48, lsb + 2, BIT(lsb + 2), 0); + udelay(1); + } else { + T6050_C(phy, 0x48, lsb + 2, BIT(lsb + 2), 1); + udelay(1); + T6050_C(phy, 0x48, lsb + 1, BIT(lsb + 1), 0); + udelay(1); + T6050_C(phy, 0x48, lsb, BIT(lsb), 0); + udelay(1); + } +} + +static void t6050_device_power(struct apple_dptx_phy *phy, bool on) +{ + T6050_C(phy, 0x10, 0, 0x7, phy->source_select); + t6050_block_power(phy, 4, on); /* PLL */ + t6050_block_power(phy, 8, on); /* AUX */ + t6050_block_power(phy, 0, on); /* PHY */ +} + +/* The board's PLL core calibration (an absent value leaves its field), then fixed settings. */ +static void t6050_pll_core_cfg(struct apple_dptx_phy *phy) +{ + const u32 *v = phy->cal; + const bool *set = phy->cal_set; + + if (set[T6050_DCOCFG]) { + T6050_D(phy, 0x2240, 1, 0x6, (v[T6050_DCOCFG] >> 3) & 3); + T6050_D(phy, 0x2240, 4, 0x70, v[T6050_DCOCFG] & 7); + } + if (set[T6050_DTCVREG]) + T6050_D(phy, 0x2230, 0, 0x1f, v[T6050_DTCVREG]); + if (set[T6050_DTCCAL]) + T6050_D(phy, 0x22e8, 17, 0x60000, v[T6050_DTCCAL]); + if (set[T6050_DCDADJ]) + T6050_D(phy, 0x2240, 22, 0x7c00000, v[T6050_DCDADJ]); + if (set[T6050_DLFCFG]) + T6050_D(phy, 0x22b0, 20, 0x700000, v[T6050_DLFCFG]); + if (set[T6050_RODCOROLEAKCOMP]) + T6050_D(phy, 0x2240, 19, 0x180000, v[T6050_RODCOROLEAKCOMP]); + + T6050_D(phy, 0x22e8, 0, 0x1, 1); + T6050_D(phy, 0x2240, 3, 0x8, 1); + T6050_D(phy, 0x2240, 0, 0x1, 1); + T6050_D(phy, 0x2224, 10, 0xc00, 2); + T6050_D(phy, 0x22b0, 27, 0x08000000, 0); + T6050_D(phy, 0x2338, 23, 0x0f800000, 0xf); +} + +/* The pixel clock driver: dptx+0x2200 bit 3 with pclkdrv-select, else bit 1. */ +static bool t6050_pclk(struct apple_dptx_phy *phy, bool on) +{ + u32 bit = phy->pclkdrv_select ? 3 : 1; + + if (!on) { + if (!(readl(phy->regs.dptx + 0x2200) & BIT(bit))) + return false; + } + T6050_D(phy, 0x2200, bit, BIT(bit), on); + return true; +} + +static void t6050_configure_pll(struct apple_dptx_phy *phy) +{ + T6050_D(phy, 0x2218, 0, 0x1, 1); + T6050_D(phy, 0x2234, 0, 0x3, 0); + t6050_pclk(phy, true); + T6050_D(phy, 0x2320, 1, 0x6, 1); /* single-ended clock output */ +} + +/* AUX impedance calibration: start, sample completion once, copy the result. */ +static int t6050_impedance_calibration(struct apple_dptx_phy *phy) +{ + u32 done, code; + + T6050_D(phy, 0x4224, 0, 0x1, 0); + usleep_range(1000, 1200); + T6050_D(phy, 0x4224, 0, 0x1, 1); + udelay(1); + T6050_D(phy, 0x4200, 4, 0x3f0, 0x3c); + udelay(1); + T6050_D(phy, 0x4200, 0, 0x1, 1); + udelay(125); + done = readl(phy->regs.dptx + 0x4204) & 1; + udelay(10); + T6050_D(phy, 0x4200, 0, 0x1, 0); + code = (readl(phy->regs.dptx + 0x4210) >> 18) & 0x7f; + if (!done) { + dev_err(phy->dev, "impedance calibration did not complete (0x4204 %#x)\n", + readl(phy->regs.dptx + 0x4204)); + return -ETIMEDOUT; + } + T6050_D(phy, 0x4228, 16, 0x7f0000, code); + T6050_D(phy, 0x4228, 15, 0x8000, 1); + dev_dbg(phy->dev, "impedance calibration code %#x\n", code); + return 0; +} + +static int t6050_activate(struct apple_dptx_phy *phy) +{ + t6050_device_power(phy, true); + phy->active = true; + t6050_pll_core_cfg(phy); /* PLL top, PHY and AUX configuration: nothing on this board */ + t6050_configure_pll(phy); + /* PLL activation */ + T6050_D(phy, 0x1000, 1, 0x2, 0); + T6050_D(phy, 0x4004, 3, 0x8, 1); + /* PHY activation: every lane, highest first */ + udelay(1); + for (int l = DPTX_MAX_LANES - 1; l >= 0; l--) + T6050_D(phy, DPTX_LANE0_OFFSET + DPTX_LANE_STRIDE * l, 9, 0x200, 0); + /* AUX power-up */ + T6050_D(phy, 0xd000, 0, 0x1, 0); + return t6050_impedance_calibration(phy); +} + +/* One PLL command (7 up, 0 down): request, 100 us, acknowledgment, lock state. */ +static int t6050_pll_command(struct apple_dptx_phy *phy, u32 cmd) +{ + bool up = cmd == 7; + u32 ack, sts; + + T6050_D(phy, 0x100c, 0, 0x7, cmd); + T6050_D(phy, 0x100c, 3, 0x8, 1); + udelay(100); + ack = readl(phy->regs.dptx + 0x1014); + T6050_D(phy, 0x100c, 3, 0x8, 0); + sts = readl(phy->regs.dptx + 0x1008); + if (!(ack & 1)) { + dev_err(phy->dev, "PLL power %s: no acknowledgment (0x1014 %#x)\n", + up ? "up" : "down", ack); + return -ETIMEDOUT; + } + if (!!(sts & BIT(3)) != up) { + dev_err(phy->dev, "PLL power %s: lock is %s (0x1008 %#x)\n", + up ? "up" : "down", up ? "missing" : "still set", sts); + return -EIO; + } + return 0; +} + +static int t6050_pll_power_down(struct apple_dptx_phy *phy) +{ + int ret; + + if (!t6050_pclk(phy, false)) + return 0; /* already down */ + ret = t6050_pll_command(phy, 0); + udelay(1); + return ret; +} + +static int t6050_pll_power_up(struct apple_dptx_phy *phy) +{ + int ret = t6050_pll_command(phy, 7); + + if (!ret) + t6050_pclk(phy, true); + return ret; +} + +static void t6050_phy_power_down(struct apple_dptx_phy *phy) +{ + T6050_D(phy, 0x4004, 0, 0x1, 1); + T6050_D(phy, 0x4000, 6, 0x40, 0); + T6050_D(phy, 0x4004, 3, 0x8, 0); + T6050_D(phy, 0x4000, 25, 0x2000000, 0); + T6050_D(phy, 0x4000, 24, 0x1000000, 0); +} + +static void t6050_phy_power_up(struct apple_dptx_phy *phy) +{ + T6050_D(phy, 0x4004, 3, 0x8, 1); + for (int l = 0; l < DPTX_MAX_LANES; l++) + T6050_D(phy, DPTX_LANE0_OFFSET + DPTX_LANE_STRIDE * l + 0x10, + 27, 0x38000000, 4); + T6050_D(phy, 0x4030, 0, 0x1, 1); /* TXA LDO low-power mode */ + udelay(1); + T6050_D(phy, 0x4000, 24, 0x1000000, 1); + ndelay(250); + T6050_D(phy, 0x4000, 25, 0x2000000, 1); + udelay(1); + T6050_D(phy, 0x4000, 6, 0x40, 1); + udelay(1); + T6050_D(phy, 0x4004, 0, 0x1, 0); +} + +static int t6050_set_lanes(struct apple_dptx_phy *phy, u32 n) +{ + if (n == 3 || n > DPTX_MAX_LANES) + return -EINVAL; + if (!phy->active) + return 0; + T6050_D(phy, 0x4000, 26, 0x4000000, 1); + udelay(1); + for (u32 l = 0; l < DPTX_MAX_LANES; l++) + T6050_D(phy, DPTX_LANE0_OFFSET + DPTX_LANE_STRIDE * l, 8, 0x100, n <= l); + if (n) + T6050_D(phy, 0x4000, 26, 0x4000000, 0); + phy->active_lanes = n; + return 0; +} + +/* + * The PLL record of a link rate (after the T8122 adjustment of its first two + * words): the integer/fraction divider q08 + q0c / q10, the analog fields and + * whether the PLL clock output is bypassed. + */ +struct t6050_pll_cfg { + u32 rate; + u8 q00, q04, q14, q18, q1c; + u16 q08, q0c, q10, q24, q28; + bool bypass; +}; + +static const struct t6050_pll_cfg t6050_pll_cfgs[] = { + { 1620, 1, 0, 1, 5, 0x13, 0x87, 0, 0, 0x80, 0x8804, true }, + { 2700, 1, 0, 1, 5, 0x09, 0x70, 0x1fff, 0x3ffe, 0x80, 0x8804, true }, + { 5400, 1, 1, 1, 5, 0x04, 0x70, 0x1fff, 0x3ffe, 0x100, 0x8984, true }, + { 8100, 1, 1, 1, 6, 0x04, 0xa8, 0x2ffd, 0x3ffc, 0x100, 0x8984, false }, +}; + +static void t6050_shadow_update(struct apple_dptx_phy *phy) +{ + set32(phy->regs.core + 0xa0, 0x8); + set32(phy->regs.core + 0xa0, 0x4); + set32(phy->regs.core + 0xa0, 0x40000); + clear32(phy->regs.core + 0xa0, 0x40000); + set32(phy->regs.core + 0xa0, 0x80000); + clear32(phy->regs.core + 0xa0, 0x80000); + clear32(phy->regs.core + 0xa0, 0x4); + clear32(phy->regs.core + 0xa0, 0x8); +} + +/* Program a link rate's PLL frequency and half-rate fields (the PLL and PHY stay as they are). */ +static int t6050_program_rate(struct apple_dptx_phy *phy, u32 rate) +{ + const struct t6050_pll_cfg *c = NULL; + u32 q10, f, e; + bool half; + + for (int i = 0; i < ARRAY_SIZE(t6050_pll_cfgs); i++) + if (t6050_pll_cfgs[i].rate == rate) + c = &t6050_pll_cfgs[i]; + if (!c) + return -EINVAL; + + q10 = c->q10 ? c->q10 : 1; + f = 4 * c->q08 + (4 * c->q0c) / q10; + e = c->q0c > 1 ? c->q10 : 0; + half = rate >= 2000; + + T6050_D(phy, 0x222c, 1, 0x2, c->bypass); + T6050_D(phy, 0x222c, 0, 0x1, !c->bypass); + T6050_D(phy, 0x2244, 0, 0xffff, c->q28); + T6050_D(phy, 0x2234, 23, 0xff800000, c->q24); + T6050_D(phy, 0x20b0, 0, 0x3ff, f); + T6050_D(phy, 0x20b0, 10, 0x400, 0); + T6050_D(phy, 0x20b4, 14, 0x0fffc000, c->q0c); + T6050_D(phy, 0x20b4, 0, 0x3fff, e); + T6050_D(phy, 0x20b8, 9, 0x3e00, c->q1c); + T6050_D(phy, 0x20b8, 14, 0xc000, c->q14); + T6050_D(phy, 0x20b8, 16, 0xf0000, c->q18); + T6050_D(phy, 0x20b8, 20, 0x300000, c->q00); + T6050_D(phy, 0x20b8, 22, 0x400000, c->q04); + t6050_shadow_update(phy); + + /* half-link-rate: PHY, then PLL */ + T6050_D(phy, 0x4004, 5, 0x20, !half); + T6050_D(phy, 0x4004, 6, 0x40, half); + T6050_D(phy, 0x2000, 29, 0x20000000, !half); + T6050_D(phy, 0x201c, 5, 0x20, !half); + phy->rate = rate; + return 0; +} + +/* + * A link reconfiguration as the DCP brackets it: PHY and PLL down, the new + * lane count and rate, then (for a nonzero rate) PLL and PHY up. + */ +static int t6050_reconfigure(struct apple_dptx_phy *phy, bool set_lanes, + u32 lanes, bool set_rate, u32 rate) +{ + int ret; + + if (!phy->active) + return -ENODEV; + t6050_phy_power_down(phy); + ret = t6050_pll_power_down(phy); + if (ret) + return ret; + if (set_lanes) { + ret = t6050_set_lanes(phy, lanes); + if (ret) + return ret; + } + if (set_rate) { + if (!rate) { + phy->rate = 0; + return 0; + } + ret = t6050_program_rate(phy, rate); + if (ret) + return ret; + } + if (!phy->rate) + return 0; + ret = t6050_pll_power_up(phy); + if (ret) + return ret; + t6050_phy_power_up(phy); + return 0; +} + +static int t6050_deactivate(struct apple_dptx_phy *phy) +{ + int ret; + + if (!phy->active) + return 0; + t6050_set_lanes(phy, 0); + t6050_phy_power_down(phy); + for (int l = 0; l < DPTX_MAX_LANES; l++) + T6050_D(phy, DPTX_LANE0_OFFSET + DPTX_LANE_STRIDE * l, 9, 0x200, 1); + ret = t6050_pll_power_down(phy); + T6050_D(phy, 0xd000, 0, 0x1, 1); /* AUX power-down */ + phy->active = false; + phy->rate = 0; + t6050_device_power(phy, false); + return ret; +} + +static int t6050_probe(struct apple_dptx_phy *phy) +{ + struct device_node *np = phy->dev->of_node; + u32 v; + + for (int i = 0; i < T6050_NR_CAL; i++) { + if (of_property_read_u32(np, t6050_cal_props[i], &v) || v == 0xffffffff) + continue; + phy->cal[i] = v; + phy->cal_set[i] = true; + } + /* The crossbar's ufp endpoint u: 5 and 6 select themselves, 0xf none, any other u + 1. */ + if (of_property_read_u32(np, "apple,ufp-endpoint", &v)) + return dev_err_probe(phy->dev, -EINVAL, "no apple,ufp-endpoint\n"); + phy->source_select = (v == 5 || v == 6) ? v : v == 0xf ? 0 : v + 1; + phy->pclkdrv_select = !of_property_read_u32(np, "apple,pclkdrv-select", &v) && v; + + return 0; +} + static int dptx_phy_set_mode(struct phy *phy, enum phy_mode mode, int submode) { struct apple_dptx_phy *dptx_phy = phy_get_drvdata(phy); + if (dptx_phy->hw.type == DPTX_PHY_T6050) { + int ret = -EINVAL; + + mutex_lock(&dptx_phy->lock); + if (mode == PHY_MODE_INVALID) + ret = t6050_deactivate(dptx_phy); + else if (mode == PHY_MODE_DP) + ret = dptx_phy->active ? 0 : t6050_activate(dptx_phy); + mutex_unlock(&dptx_phy->lock); + return ret; + } + switch (mode) { case PHY_MODE_INVALID: return dptx_phy_deactivate(dptx_phy); @@ -574,6 +990,16 @@ static int dptx_phy_configure(struct phy *phy, union phy_configure_opts *opts_) enum dptx_phy_link_rate link_rate; int ret = 0; + if (dptx_phy->hw.type == DPTX_PHY_T6050) { + if (!opts->set_lanes && !opts->set_rate) + return 0; + mutex_lock(&dptx_phy->lock); + ret = t6050_reconfigure(dptx_phy, opts->set_lanes, opts->lanes, + opts->set_rate, opts->link_rate); + mutex_unlock(&dptx_phy->lock); + return ret; + } + if (opts->set_lanes) { mutex_lock(&dptx_phy->lock); ret = dptx_phy_set_active_lane_count(dptx_phy, opts->lanes); @@ -656,6 +1082,8 @@ static int dptx_phy_probe(struct platform_device *pdev) if (IS_ERR(dptx_phy->phy_provider)) return PTR_ERR(dptx_phy->phy_provider); + if (dptx_phy->hw.type == DPTX_PHY_T6050) + return t6050_probe(dptx_phy); return 0; } @@ -667,9 +1095,14 @@ static const struct apple_dptx_phy_hw apple_dptx_hw_t8112 = { .type = DPTX_PHY_T8112, }; +static const struct apple_dptx_phy_hw apple_dptx_hw_t6050 = { + .type = DPTX_PHY_T6050, +}; + static const struct of_device_id dptx_phy_match[] = { { .compatible = "apple,t6020-dptx-phy", .data = &apple_dptx_hw_t6020 }, { .compatible = "apple,t8112-dptx-phy", .data = &apple_dptx_hw_t8112 }, + { .compatible = "apple,t6050-dptx-phy", .data = &apple_dptx_hw_t6050 }, {}, }; MODULE_DEVICE_TABLE(of, dptx_phy_match); From 5b0f430dae5813da53da05f69338bd5320d83f02 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 19 Oct 2026 07:10:51 -0400 Subject: [PATCH 004/342] soc: apple: rtkit: read crashlogs written after the crash report A co-processor whose crashlog endpoint was never discovered or started, such as a DCP adopted from the bootloader, requests the crashlog buffer only when it crashes and writes the log after receiving it. The header read right after mapping the buffer then fails, and the report was dropped without a word: on T6050 all three DCPs crashed this way within 8 s, display swaps stopped completing and the compositor froze, with nothing in the log but "Message to undiscovered endpoint 0x01". Report such a crash and poll the buffer until the log is written, then dump it. Only do this when APPLE_RTKIT_EP_CRASHLOG is not in rtk->endpoints. On a started crashlog endpoint the first message without a buffer is the normal boot-time buffer request, not a crash; treating it as one reported a crash for every other co-processor at boot (SMC, NVMe, PMP and the DP PHY on T6050). That path stays as it was: map the buffer and return silently. Nothing else changes: the consumer is not told, as before. Signed-off-by: Diljit Singh Signed-off-by: Erik Bourget --- drivers/soc/apple/rtkit-internal.h | 5 +++ drivers/soc/apple/rtkit.c | 69 +++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h index 0c5acb7fc7090..b555e13cf93e3 100644 --- a/drivers/soc/apple/rtkit-internal.h +++ b/drivers/soc/apple/rtkit-internal.h @@ -82,6 +82,11 @@ struct apple_rtkit { bool crashlog_inherited; bool oslog_inherited; + /* A crash reported before the crashlog buffer was mapped: the log is + * read once the co-processor has written it. */ + struct delayed_work crashlog_late_work; + unsigned int crashlog_late_polls; + struct workqueue_struct *wq; }; diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index d352083aaa26c..04d603129f0fd 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -695,6 +695,51 @@ static void apple_rtkit_memcpy(struct apple_rtkit *rtk, void *dst, len, DMA_FROM_DEVICE); } +#define APPLE_RTKIT_CRASHLOG_LATE_POLL_MS 250 +#define APPLE_RTKIT_CRASHLOG_LATE_POLLS 20 + +static bool apple_rtkit_crashlog_header_valid(struct apple_rtkit *rtk) +{ + struct apple_rtkit_crashlog_header header; + + if (rtk->crashlog_buffer.size < sizeof(header)) + return false; + apple_rtkit_memcpy(rtk, &header, &rtk->crashlog_buffer, 0, + sizeof(header)); + return header.fourcc == APPLE_RTKIT_CRASHLOG_HEADER_FOURCC && + header.size >= sizeof(header) && + header.size <= rtk->crashlog_buffer.size; +} + +static void apple_rtkit_crashlog_late(struct work_struct *work) +{ + struct apple_rtkit *rtk = container_of(to_delayed_work(work), + struct apple_rtkit, + crashlog_late_work); + u8 *bfr __free(kfree) = NULL; + + if (!apple_rtkit_crashlog_header_valid(rtk)) { + if (++rtk->crashlog_late_polls < APPLE_RTKIT_CRASHLOG_LATE_POLLS) + queue_delayed_work(rtk->wq, &rtk->crashlog_late_work, + msecs_to_jiffies(APPLE_RTKIT_CRASHLOG_LATE_POLL_MS)); + else + dev_err(rtk->dev, + "RTKit: crash reported, but no crashlog was written in %u ms\n", + APPLE_RTKIT_CRASHLOG_LATE_POLLS * + APPLE_RTKIT_CRASHLOG_LATE_POLL_MS); + return; + } + + dev_err(rtk->dev, "RTKit: co-processor crashed; crashlog written after %u ms\n", + (rtk->crashlog_late_polls + 1) * APPLE_RTKIT_CRASHLOG_LATE_POLL_MS); + bfr = kzalloc(rtk->crashlog_buffer.size, GFP_KERNEL); + if (!bfr) + return; + apple_rtkit_memcpy(rtk, bfr, &rtk->crashlog_buffer, 0, + rtk->crashlog_buffer.size); + apple_rtkit_crashlog_dump(rtk, bfr, rtk->crashlog_buffer.size); +} + static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) { u8 type = FIELD_GET(APPLE_RTKIT_SYSLOG_TYPE, msg); @@ -728,8 +773,27 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) sizeof(header)); if (header.fourcc != APPLE_RTKIT_CRASHLOG_HEADER_FOURCC || header.size < sizeof(header) || - header.size > rtk->crashlog_buffer.size) + header.size > rtk->crashlog_buffer.size) { + /* + * On a started crashlog endpoint the first message + * without a buffer is the normal boot-time buffer + * request. A co-processor whose crashlog endpoint was + * never discovered or started (a DCP adopted from the + * bootloader) sends it only when it crashes, and writes + * the log after receiving the buffer. Say so and read + * the log once it is there, rather than dropping the + * report. + */ + if (!test_bit(APPLE_RTKIT_EP_CRASHLOG, rtk->endpoints)) { + dev_err(rtk->dev, + "RTKit: co-processor reported a crash before its crashlog buffer was mapped\n"); + rtk->crashlog_late_polls = 0; + queue_delayed_work(rtk->wq, &rtk->crashlog_late_work, + msecs_to_jiffies(APPLE_RTKIT_CRASHLOG_LATE_POLL_MS)); + return; + } goto unmapped; + } } dev_err(rtk->dev, "RTKit: co-processor has crashed\n"); @@ -1279,6 +1343,7 @@ static void apple_rtkit_detach_rx(struct apple_rtkit *rtk) static void apple_rtkit_stop_rx(struct apple_rtkit *rtk) { apple_rtkit_detach_rx(rtk); + cancel_delayed_work_sync(&rtk->crashlog_late_work); destroy_workqueue(rtk->wq); } @@ -1382,6 +1447,7 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, init_completion(&rtk->coreanalytics_completion); init_completion(&rtk->iop_pwr_ack_completion); init_completion(&rtk->ap_pwr_ack_completion); + INIT_DELAYED_WORK(&rtk->crashlog_late_work, apple_rtkit_crashlog_late); bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints); @@ -1511,6 +1577,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk) /* make sure we don't handle any messages while reinitializing */ apple_rtkit_detach_rx(rtk); + cancel_delayed_work_sync(&rtk->crashlog_late_work); flush_workqueue(rtk->wq); apple_rtkit_free_buffer(rtk, &rtk->coreanalytics_buffer); From 8ee4d615e076d1294ef6c07fd2c115fdeced5387 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sun, 1 Nov 2026 22:35:05 -0800 Subject: [PATCH 005/342] soc: apple: rtkit: Report a crash on an undiscovered crashlog endpoint In a session that went through the handshake, the crashlog handler takes the first message on the crashlog endpoint for the buffer request that answers the endpoint's start: it sets the buffer up and returns. That has been the rule since RTKit was added. Two later commits made an inherited session's first message a crash report and kept the rule for every other session: commit e52b589758bd ("soc: apple: rtkit: recognise an initial crash log in adopted sessions") commit 8a2875a6789d ("soc: apple: rtkit: Only parse an initial crash log in inherited sessions") The previous commit reads the log of such a report when it is written after the report, but only in an inherited session, and without telling the client. The rule only holds when the endpoint was in the endpoint map and was started. The external DCP on T6050 (dcpext0 on J775D) does not list the crashlog endpoint in its map, so the endpoint is never started and the co-processor is never asked for a buffer. Its firmware still reports a crash there, naming a buffer of its own, in a session that went through the handshake as well. That report was set up as a buffer and dropped: the instance was never marked crashed and the DCP driver's crash handling never ran. Presents stopped (a swap timed out 36 s later) and every later modeset failed with -EINVAL until a reboot, with nothing in the log but "Message to undiscovered endpoint 0x01". Handle a crashlog message on an undiscovered endpoint as an inherited session's report is handled, in any session: set up the buffer it names and dump a valid log if there is one, then mark the instance crashed and notify the client at once, with or without a readable log. A log that is not written yet is still read once it is there, after the client has been told. A buffer that could not be set up and a buffer that holds no valid log yet are reported separately. Log when the endpoint map lacks the crashlog endpoint. A crashlog message still being handled may queue that late read, so stopping and reinitializing flush the work queue before cancelling it. A discovered endpoint is unchanged: its first message is still the buffer request. This builds on the inherited-session path those commits added, so a backport needs them. Testing: on J775D the map line appears for dcpext0 and for no other co-processor. A crash caused on dcpext0, by an IOMFB call to a method neither of its firmware tables has, was reported on the crashlog endpoint 4.7 ms after the call, with the same buffer as a crash seen in normal use. The instance was marked crashed and the DCP driver's crash handling ran ("DCP has crashed", the connector then reported disconnected). Fixes: 9bd1d9a0d8bb ("soc: apple: Add RTKit IPC library") Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/soc/apple/rtkit.c | 93 ++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 04d603129f0fd..e6c7aa4a28216 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -256,6 +256,9 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) if (!(msg & APPLE_RTKIT_MGMT_EPMAP_LAST)) return; + if (!test_bit(APPLE_RTKIT_EP_CRASHLOG, rtk->endpoints)) + dev_info(rtk->dev, "RTKit: crashlog endpoint not in the endpoint map\n"); + for_each_set_bit(ep, rtk->endpoints, APPLE_RTKIT_APP_ENDPOINT_START) { switch (ep) { /* the management endpoint is started by default */ @@ -730,6 +733,7 @@ static void apple_rtkit_crashlog_late(struct work_struct *work) return; } + /* The crash was reported and the client told; only dump the log. */ dev_err(rtk->dev, "RTKit: co-processor crashed; crashlog written after %u ms\n", (rtk->crashlog_late_polls + 1) * APPLE_RTKIT_CRASHLOG_LATE_POLL_MS); bfr = kzalloc(rtk->crashlog_buffer.size, GFP_KERNEL); @@ -744,7 +748,16 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) { u8 type = FIELD_GET(APPLE_RTKIT_SYSLOG_TYPE, msg); u8 *bfr __free(kfree) = NULL; - struct apple_rtkit_crashlog_header header; + /* + * An undiscovered crashlog endpoint was never started, so the + * co-processor was never asked for a buffer and, as in an inherited + * session, a message there can only be a crash report. Firmware that + * leaves this endpoint out of its map still reports crashes on it, + * with a buffer of its own. + */ + bool reports_crash = rtk->crashlog_inherited || + !test_bit(APPLE_RTKIT_EP_CRASHLOG, rtk->endpoints); + bool await_log = false; if (type != APPLE_RTKIT_CRASHLOG_CRASH) { dev_warn(rtk->dev, "RTKit: Unknown crashlog message: %llx\n", @@ -755,45 +768,23 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) if (!rtk->crashlog_buffer.size) { if (apple_rtkit_common_rx_get_buffer(rtk, &rtk->crashlog_buffer, APPLE_RTKIT_EP_CRASHLOG, msg)) - goto unmapped; + goto no_buffer; /* * In a session that went through the handshake, the first - * message on this endpoint is the buffer request. Firmware may - * place that buffer in memory which still holds the log of an - * earlier crash, so only look for one in an inherited session. + * message on a started crashlog endpoint is the buffer request. + * Firmware may place that buffer in memory which still holds + * the log of an earlier crash, so only look for one when the + * message can only be a crash report. */ - if (!rtk->crashlog_inherited) + if (!reports_crash) return; } - if (rtk->crashlog_inherited) { - if (rtk->crashlog_buffer.size < sizeof(header)) - goto unmapped; - - apple_rtkit_memcpy(rtk, &header, &rtk->crashlog_buffer, 0, - sizeof(header)); - if (header.fourcc != APPLE_RTKIT_CRASHLOG_HEADER_FOURCC || - header.size < sizeof(header) || - header.size > rtk->crashlog_buffer.size) { - /* - * On a started crashlog endpoint the first message - * without a buffer is the normal boot-time buffer - * request. A co-processor whose crashlog endpoint was - * never discovered or started (a DCP adopted from the - * bootloader) sends it only when it crashes, and writes - * the log after receiving the buffer. Say so and read - * the log once it is there, rather than dropping the - * report. - */ - if (!test_bit(APPLE_RTKIT_EP_CRASHLOG, rtk->endpoints)) { - dev_err(rtk->dev, - "RTKit: co-processor reported a crash before its crashlog buffer was mapped\n"); - rtk->crashlog_late_polls = 0; - queue_delayed_work(rtk->wq, &rtk->crashlog_late_work, - msecs_to_jiffies(APPLE_RTKIT_CRASHLOG_LATE_POLL_MS)); - return; - } - goto unmapped; - } + if (reports_crash) { + if (rtk->crashlog_buffer.size < + sizeof(struct apple_rtkit_crashlog_header)) + goto no_buffer; + if (!apple_rtkit_crashlog_header_valid(rtk)) + goto no_log; } dev_err(rtk->dev, "RTKit: co-processor has crashed\n"); @@ -818,14 +809,34 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) rtk->ops->crashed(rtk->cookie, bfr, bfr ? rtk->crashlog_buffer.size : 0); return; -unmapped: - /* An inherited session already negotiated its crash buffer. */ - if (!rtk->crashlog_inherited) +no_buffer: + /* Otherwise this was a buffer request that could not be served. */ + if (!reports_crash) return; - dev_err(rtk->dev, "RTKit: adopted co-processor crashed without a readable log\n"); + dev_err(rtk->dev, "RTKit: co-processor crashed without a usable crashlog buffer\n"); + goto crashed; + +no_log: + /* The buffer is mapped, but holds no valid log (yet). */ + dev_err(rtk->dev, "RTKit: co-processor crashed without a readable log\n"); + /* + * A co-processor whose crashlog endpoint was never discovered or + * started (the external DCP on T6050) requests the buffer only when + * it crashes, and writes the log after receiving it. Read the log once + * it is there, rather than dropping it. + */ + await_log = !test_bit(APPLE_RTKIT_EP_CRASHLOG, rtk->endpoints); + +crashed: rtk->crashed = true; if (rtk->ops->crashed) rtk->ops->crashed(rtk->cookie, NULL, 0); + + if (await_log) { + rtk->crashlog_late_polls = 0; + queue_delayed_work(rtk->wq, &rtk->crashlog_late_work, + msecs_to_jiffies(APPLE_RTKIT_CRASHLOG_LATE_POLL_MS)); + } } static void apple_rtkit_ioreport_rx(struct apple_rtkit *rtk, u64 msg) @@ -1343,6 +1354,8 @@ static void apple_rtkit_detach_rx(struct apple_rtkit *rtk) static void apple_rtkit_stop_rx(struct apple_rtkit *rtk) { apple_rtkit_detach_rx(rtk); + /* A crashlog message still being handled may queue the late read. */ + flush_workqueue(rtk->wq); cancel_delayed_work_sync(&rtk->crashlog_late_work); destroy_workqueue(rtk->wq); } @@ -1577,8 +1590,8 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk) /* make sure we don't handle any messages while reinitializing */ apple_rtkit_detach_rx(rtk); - cancel_delayed_work_sync(&rtk->crashlog_late_work); flush_workqueue(rtk->wq); + cancel_delayed_work_sync(&rtk->crashlog_late_work); apple_rtkit_free_buffer(rtk, &rtk->coreanalytics_buffer); apple_rtkit_free_buffer(rtk, &rtk->ioreport_buffer); From edbf3214f22ac0ab0dc3049641572d05aec28168 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:09:37 -0800 Subject: [PATCH 006/342] soc: apple: rtkit: Read crashlogs written as a container The external DCP of T6050 (dcpext0 on J775D) writes its crashlog as a container: a 'CLGH' header and a table of records (ID, offset), where the record whose ID is the container's current ID holds this crash's log. That record can be a container itself; on this DCP the buffer holds one per co-processor and, inside, one per task. The log at the end is an ordinary 'CLHE' crashlog with the usual sections. RTKit looked for 'CLHE' at offset 0 only, so such a log was never valid: the crash was reported "without a readable log" although the log was in the buffer. Follow the container to its log, through at most 8 levels and with offsets that only move forward, both when checking that a log is there and when dumping it. A log selected through a container is not complete while bit 8 of its flags is set. Decode the 'Crl4' register frame, at the offsets of Diljit Singh's T8140 DCP decoder. The DCP logs read on J775D so far carry no register frame section, neither 'Crg8' nor 'Crl4', so this decoder has not run on a real log, only in the host test below. Container logs come from firmware that has just crashed, so the section walk no longer trusts their sizes. A section header must fit in the log; a section's size must cover its own 16-byte header and stay inside the log; and a section is decoded only with at least the footer's 16-byte header after it, since the decoders read up to the section's size from 16 bytes in. A zero size used to loop forever, and a size past the log, or a mailbox section under 28 bytes, made the decoders read past the copy. The version and message strings are bounded by the section's size instead of a terminating NUL, and a buffer shorter than a log header is refused. A buffer that starts with 'CLHE' is checked as before, and a well-formed log there is decoded exactly as before. Testing: on J775D, the crash caused on dcpext0 as in the previous commit now prints "Crashlog container: log 'RTAL' at 0x2000 (depth 2)", the log's message naming the method the firmware could not find, and the firmware's mailbox history (128 entries), whose last entry is that call. The log was complete when the crash was reported. A buffer read back after an earlier crash on the 27.2 firmware has the same layout (logs for the root task, RTAL and one untagged task). These runs predate the section bounds, which change nothing for a well-formed log. A host test, tools/asahi/rtkit-crashlog-tests.py, builds this file with ASan and UBSan and feeds it a log with the layout of that crash (two containers, then RTAL's log with its eleven sections and footer) and malformed logs: zero, oversized and footer-less sections, a truncated section header, mailbox sections of 16 to 27 bytes, short, truncated and undecodable 'Crl4' sections, unterminated strings, short buffers and broken containers. Each is decoded or refused without a loop or a read past the log, and removing any one bound makes it fail. The buffer read back after the earlier crash decodes the same with and without the bounds. The container selection, the record layout, the incomplete flag and the 'Crl4' offsets follow that decoder. Here they are in RTKit, so that every client gets them. Co-developed-by: Diljit Singh Signed-off-by: Diljit Singh Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/soc/apple/rtkit-crashlog.c | 225 +++++++++++- drivers/soc/apple/rtkit-internal.h | 4 + drivers/soc/apple/rtkit.c | 20 +- tools/asahi/rtkit-crashlog-tests.py | 512 ++++++++++++++++++++++++++++ tools/asahi/run-host-tests.py | 3 + 5 files changed, 757 insertions(+), 7 deletions(-) create mode 100755 tools/asahi/rtkit-crashlog-tests.py diff --git a/drivers/soc/apple/rtkit-crashlog.c b/drivers/soc/apple/rtkit-crashlog.c index 5defa12862b15..2ec4bd9569e46 100644 --- a/drivers/soc/apple/rtkit-crashlog.c +++ b/drivers/soc/apple/rtkit-crashlog.c @@ -3,6 +3,8 @@ * Apple RTKit IPC library * Copyright (C) The Asahi Linux Contributors */ +#include + #include "rtkit-internal.h" #define FOURCC(a, b, c, d) \ @@ -13,6 +15,51 @@ #define APPLE_RTKIT_CRASHLOG_MBOX FOURCC('C', 'm', 'b', 'x') #define APPLE_RTKIT_CRASHLOG_TIME FOURCC('C', 't', 'i', 'm') #define APPLE_RTKIT_CRASHLOG_REGS FOURCC('C', 'r', 'g', '8') +#define APPLE_RTKIT_CRASHLOG_REGS_CL4 FOURCC('C', 'r', 'l', '4') + +/* + * Newer firmware writes a container instead of a single crashlog: a + * 'CLGH' header and a table of records, each with an ID and an offset from + * the container. The record whose ID is the container's current ID holds + * the log of this crash, and may itself be a container (on T6050's DCP: + * per-coprocessor, then per-task). The log at the end is an ordinary + * 'CLHE' crashlog with the same sections. + */ +struct apple_rtkit_crashlog_container { + u32 fourcc; + u32 version; + u32 size; + u32 current_id; + u32 count; +} __packed; +static_assert(sizeof(struct apple_rtkit_crashlog_container) == 0x14); + +struct apple_rtkit_crashlog_record { + u64 id; + u64 _unk0; + u32 offset; + u32 _unk1; +} __packed; +static_assert(sizeof(struct apple_rtkit_crashlog_record) == 0x18); + +#define APPLE_RTKIT_CRASHLOG_CONTAINER_VERSION 2 +#define APPLE_RTKIT_CRASHLOG_CONTAINER_MAX_DEPTH 8 +/* Set in a log's flags while the co-processor is still writing it. */ +#define APPLE_RTKIT_CRASHLOG_INCOMPLETE BIT(8) + +/* Register frame of the 'Crl4' section, offsets from the section start. */ +#define APPLE_RTKIT_CRASHLOG_CL4_SECTION_SIZE 0x378 +#define APPLE_RTKIT_CRASHLOG_CL4_FLAGS 0x10 +#define APPLE_RTKIT_CRASHLOG_CL4_SIZE 0x14 +#define APPLE_RTKIT_CRASHLOG_CL4_NOMINAL_SIZE 0xd8 +#define APPLE_RTKIT_CRASHLOG_CL4_REGS 0x18 +#define APPLE_RTKIT_CRASHLOG_CL4_LR 0x108 +#define APPLE_RTKIT_CRASHLOG_CL4_PC 0x110 +#define APPLE_RTKIT_CRASHLOG_CL4_SP 0x118 +#define APPLE_RTKIT_CRASHLOG_CL4_PSR 0x120 +#define APPLE_RTKIT_CRASHLOG_CL4_ESR 0x358 +#define APPLE_RTKIT_CRASHLOG_CL4_FAR 0x360 +#define APPLE_RTKIT_CRASHLOG_CL4_UNDECODABLE BIT(16) /* For COMPILE_TEST on non-ARM64 architectures */ #ifndef PSR_MODE_EL0t @@ -71,8 +118,8 @@ static void apple_rtkit_crashlog_dump_str(struct apple_rtkit *rtk, u8 *bfr, *newline = tmp; ptr = newline + 1; } else { - dev_warn(rtk->dev, "RTKit: Message (id=%x): %s", idx, - ptr); + dev_warn(rtk->dev, "RTKit: Message (id=%x): %.*s", idx, + (int)(end - ptr), ptr); break; } } @@ -81,7 +128,8 @@ static void apple_rtkit_crashlog_dump_str(struct apple_rtkit *rtk, u8 *bfr, static void apple_rtkit_crashlog_dump_version(struct apple_rtkit *rtk, u8 *bfr, size_t size) { - dev_warn(rtk->dev, "RTKit: Version: %s", bfr + 16); + /* The string need not be terminated inside the section. */ + dev_warn(rtk->dev, "RTKit: Version: %.*s", (int)(size - 16), bfr + 16); } static void apple_rtkit_crashlog_dump_time(struct apple_rtkit *rtk, u8 *bfr, @@ -100,6 +148,10 @@ static void apple_rtkit_crashlog_dump_mailbox(struct apple_rtkit *rtk, u8 *bfr, size_t n_messages; struct apple_rtkit_crashlog_mbox_entry entry; + if (size < 28) { + dev_warn(rtk->dev, "RTKit: Mailbox section too small: 0x%zx", size); + return; + } memcpy(&type, bfr + 16, 4); memcpy(&index, bfr + 24, 4); n_messages = (size - 28) / sizeof(entry); @@ -173,13 +225,150 @@ static void apple_rtkit_crashlog_dump_regs(struct apple_rtkit *rtk, u8 *bfr, dev_warn(rtk->dev, "\n"); } +static void apple_rtkit_crashlog_dump_regs_cl4(struct apple_rtkit *rtk, + u8 *section, size_t size) +{ + u32 flags, regs_size; + int i; + + if (size < APPLE_RTKIT_CRASHLOG_CL4_SECTION_SIZE) { + dev_warn(rtk->dev, "RTKit: Crl4 section too small: 0x%zx", size); + return; + } + flags = get_unaligned_le32(section + APPLE_RTKIT_CRASHLOG_CL4_FLAGS); + regs_size = get_unaligned_le32(section + APPLE_RTKIT_CRASHLOG_CL4_SIZE); + if (regs_size != APPLE_RTKIT_CRASHLOG_CL4_NOMINAL_SIZE || + (flags & APPLE_RTKIT_CRASHLOG_CL4_UNDECODABLE)) { + dev_warn(rtk->dev, "RTKit: Crl4 frame not decodable (flags %#x, size %#x)", + flags, regs_size); + return; + } + + dev_warn(rtk->dev, "RTKit: Exception dump (Crl4):"); + dev_warn(rtk->dev, " PSR = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_PSR)); + dev_warn(rtk->dev, " PC = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_PC)); + dev_warn(rtk->dev, " LR = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_LR)); + dev_warn(rtk->dev, " ESR = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_ESR)); + dev_warn(rtk->dev, " FAR = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_FAR)); + dev_warn(rtk->dev, " SP = 0x%llx", + get_unaligned_le64(section + APPLE_RTKIT_CRASHLOG_CL4_SP)); + for (i = 0; i < 28; i += 4) { + u8 *r = section + APPLE_RTKIT_CRASHLOG_CL4_REGS + i * 8; + + dev_warn(rtk->dev, " x%02d-x%02d = %016llx %016llx %016llx %016llx", + i, i + 3, get_unaligned_le64(r), get_unaligned_le64(r + 8), + get_unaligned_le64(r + 16), get_unaligned_le64(r + 24)); + } +} + +/** + * apple_rtkit_crashlog_locate() - find this crash's log in a crashlog buffer + * @bfr: a copy of the buffer + * @size: its size + * @log_offset: set to the offset of the 'CLHE' log + * @log_id: set to the ID of the record that held it (0 for a bare log) + * @depth: set to the number of containers followed + * + * A bare 'CLHE' log at offset 0 is returned as it is. In a 'CLGH' container, + * the record with the current ID is followed, through nested containers, + * to its log. Offsets only move forward, so a corrupt table cannot loop. + * + * Return: 0 if a complete log was found, -EAGAIN if the selected log is + * still being written, -EINVAL otherwise. + */ +int apple_rtkit_crashlog_locate(const u8 *bfr, size_t size, size_t *log_offset, + u32 *log_id, unsigned int *depth) +{ + struct apple_rtkit_crashlog_container container; + struct apple_rtkit_crashlog_header header; + struct apple_rtkit_crashlog_record record; + size_t offset = 0, avail, next; + unsigned int level; + u32 id = 0, i; + + for (level = 0; level <= APPLE_RTKIT_CRASHLOG_CONTAINER_MAX_DEPTH; level++) { + avail = size - offset; + if (avail < sizeof(header)) + return -EINVAL; + memcpy(&header, bfr + offset, sizeof(header)); + + if (header.fourcc == APPLE_RTKIT_CRASHLOG_HEADER_FOURCC) { + if (header.size < sizeof(header) || header.size > avail) + return -EINVAL; + if (level && (header.flags & APPLE_RTKIT_CRASHLOG_INCOMPLETE)) + return -EAGAIN; + *log_offset = offset; + *log_id = id; + *depth = level; + return 0; + } + if (header.fourcc != APPLE_RTKIT_CRASHLOG_CONTAINER_FOURCC) + return -EINVAL; + + memcpy(&container, bfr + offset, sizeof(container)); + if (((container.version >> 8) & 0xff) != + APPLE_RTKIT_CRASHLOG_CONTAINER_VERSION || + container.size > avail || !container.count || + container.count > (avail - sizeof(container)) / sizeof(record)) + return -EINVAL; + + next = 0; + for (i = 0; i < container.count; i++) { + memcpy(&record, bfr + offset + sizeof(container) + + i * sizeof(record), sizeof(record)); + if (record.id == container.current_id) { + next = record.offset; + break; + } + } + if (next < sizeof(container) || next >= avail) + return -EINVAL; + + id = container.current_id; + offset += next; + } + + return -EINVAL; +} + void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size) { size_t offset; u32 section_fourcc, section_size; struct apple_rtkit_crashlog_header header; + if (size < sizeof(header)) { + dev_warn(rtk->dev, "RTKit: Crashlog buffer too small: 0x%zx", + size); + return; + } memcpy(&header, bfr, sizeof(header)); + if (header.fourcc == APPLE_RTKIT_CRASHLOG_CONTAINER_FOURCC) { + unsigned int depth; + u32 id; + int ret; + + ret = apple_rtkit_crashlog_locate(bfr, size, &offset, &id, &depth); + if (ret) { + dev_warn(rtk->dev, + "RTKit: Crashlog container holds no complete log (%d)", + ret); + return; + } + dev_warn(rtk->dev, + "RTKit: Crashlog container: log '%c%c%c%c' at 0x%zx (depth %u)", + (id >> 24) & 0xff, (id >> 16) & 0xff, (id >> 8) & 0xff, + id & 0xff, offset, depth); + bfr += offset; + size -= offset; + memcpy(&header, bfr, sizeof(header)); + } + if (header.fourcc != APPLE_RTKIT_CRASHLOG_HEADER_FOURCC) { dev_warn(rtk->dev, "RTKit: Expected crashlog header but got %x", header.fourcc); @@ -196,13 +385,35 @@ void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size) offset = sizeof(header); while (offset < size) { + if (size - offset < 16) { + dev_warn(rtk->dev, + "RTKit: Crashlog section header at 0x%zx is truncated", + offset); + return; + } memcpy(§ion_fourcc, bfr + offset, 4); memcpy(§ion_size, bfr + offset + 12, 4); - switch (section_fourcc) { - case APPLE_RTKIT_CRASHLOG_HEADER_FOURCC: + if (section_fourcc == APPLE_RTKIT_CRASHLOG_HEADER_FOURCC) { dev_dbg(rtk->dev, "RTKit: End of crashlog reached"); return; + } + /* A zero size would never advance. */ + if (section_size < 16 || section_size > size - offset) { + dev_warn(rtk->dev, + "RTKit: Crashlog section %x at 0x%zx has a bad size 0x%x", + section_fourcc, offset, section_size); + return; + } + /* + * The decoders read up to section_size bytes from 16 bytes into + * the section, so a section is only decoded with at least the + * footer's 16-byte header after it. + */ + if (section_size > size - offset - 16) + break; + + switch (section_fourcc) { case APPLE_RTKIT_CRASHLOG_STR: apple_rtkit_crashlog_dump_str(rtk, bfr + offset + 16, section_size); @@ -223,6 +434,10 @@ void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size) apple_rtkit_crashlog_dump_regs(rtk, bfr + offset + 16, section_size); break; + case APPLE_RTKIT_CRASHLOG_REGS_CL4: + apple_rtkit_crashlog_dump_regs_cl4(rtk, bfr + offset, + section_size); + break; default: dev_warn(rtk->dev, "RTKit: Unknown crashlog section: %x", diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h index b555e13cf93e3..a4976fd1b456c 100644 --- a/drivers/soc/apple/rtkit-internal.h +++ b/drivers/soc/apple/rtkit-internal.h @@ -23,6 +23,8 @@ #define APPLE_RTKIT_APP_ENDPOINT_START 0x20 #define APPLE_RTKIT_MAX_ENDPOINTS 0x100 #define APPLE_RTKIT_CRASHLOG_HEADER_FOURCC 0x434c4845 +/* A container of crashlogs (one per task or core): 'CLGH'. */ +#define APPLE_RTKIT_CRASHLOG_CONTAINER_FOURCC 0x434c4748 struct apple_rtkit_crashlog_header { u32 fourcc; @@ -91,5 +93,7 @@ struct apple_rtkit { }; void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size); +int apple_rtkit_crashlog_locate(const u8 *bfr, size_t size, size_t *log_offset, + u32 *log_id, unsigned int *depth); #endif diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index e6c7aa4a28216..1d56f00c851ec 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -701,17 +701,33 @@ static void apple_rtkit_memcpy(struct apple_rtkit *rtk, void *dst, #define APPLE_RTKIT_CRASHLOG_LATE_POLL_MS 250 #define APPLE_RTKIT_CRASHLOG_LATE_POLLS 20 +/* + * Whether the crashlog buffer holds a log: an ordinary 'CLHE' log at its + * start, or a 'CLGH' container whose current record leads to a complete one. + */ static bool apple_rtkit_crashlog_header_valid(struct apple_rtkit *rtk) { struct apple_rtkit_crashlog_header header; + size_t size = rtk->crashlog_buffer.size, offset; + unsigned int depth; + u32 id; - if (rtk->crashlog_buffer.size < sizeof(header)) + if (size < sizeof(header)) return false; apple_rtkit_memcpy(rtk, &header, &rtk->crashlog_buffer, 0, sizeof(header)); + if (header.fourcc == APPLE_RTKIT_CRASHLOG_CONTAINER_FOURCC) { + u8 *bfr __free(kfree) = kmalloc(size, GFP_KERNEL); + + if (!bfr) + return false; + apple_rtkit_memcpy(rtk, bfr, &rtk->crashlog_buffer, 0, size); + return !apple_rtkit_crashlog_locate(bfr, size, &offset, &id, + &depth); + } return header.fourcc == APPLE_RTKIT_CRASHLOG_HEADER_FOURCC && header.size >= sizeof(header) && - header.size <= rtk->crashlog_buffer.size; + header.size <= size; } static void apple_rtkit_crashlog_late(struct work_struct *work) diff --git a/tools/asahi/rtkit-crashlog-tests.py b/tools/asahi/rtkit-crashlog-tests.py new file mode 100755 index 0000000000000..382c8d39cd1a3 --- /dev/null +++ b/tools/asahi/rtkit-crashlog-tests.py @@ -0,0 +1,512 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Feed RTKit's crashlog parser a container log and malformed logs. + +drivers/soc/apple/rtkit-crashlog.c is compiled whole and unchanged, with ASan +and UBSan, against a stand-in for rtkit-internal.h that carries the real +header's crashlog definitions. Every log is allocated at its exact size, so a +read past it is a sanitizer error, and a walk that stops advancing runs into +the line limit. + +The container log has the layout of a T6050 DCP crash (a 'CLGH' container, +a nested one, and at 0x2000 the 'CLHE' log of task RTAL with eleven sections +and a footer), with neutral contents. The malformed logs cover a zero and an +oversized section size, a truncated section header, a short mailbox section, +a short and a truncated 'Crl4' section, unterminated strings, short buffers +and broken containers. --log FILE feeds a raw crashlog buffer read from a +device instead, and prints what the parser makes of it. +""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import re +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +SOURCE = 'drivers/soc/apple/rtkit-crashlog.c' +HEADER = 'drivers/soc/apple/rtkit-internal.h' + +# Each mutation removes one bound; a test case must catch it. +MUTATIONS = { + 'buffer-header': ('if (size < sizeof(header)) {', 'if (0) {'), + 'section-header': ('if (size - offset < 16) {', 'if (0) {'), + 'section-size': ('if (section_size < 16 || section_size > size - offset) {', 'if (0) {'), + 'footer-room': ('if (section_size > size - offset - 16)\n\t\t\tbreak;', ''), + 'mailbox-minimum': ('if (size < 28) {', 'if (0) {'), + 'version-string': ('"RTKit: Version: %.*s", (int)(size - 16), bfr + 16', '"RTKit: Version: %s", bfr + 16'), + 'message-string': ('%.*s", idx,\n\t\t\t\t (int)(end - ptr), ptr', '%s", idx,\n\t\t\t\t ptr'), +} + +STUB = r''' +#include +#include +#include +#include +#include +#include +#include +#include +/* As linux/build_bug.h has it: the message is optional. */ +#undef static_assert +#define __static_assert(expr, msg, ...) _Static_assert(expr, msg) +#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) +typedef uint8_t u8; +typedef uint32_t u32; +typedef unsigned long long u64; +#define __packed __attribute__((packed)) +#define BIT(n) (1UL << (n)) +#define EINVAL 22 +#define EAGAIN 11 +struct device { int id; }; +struct apple_rtkit { struct device *dev; }; +void dev_printk(const char *level, struct device *dev, const char *fmt, ...) + __attribute__((format(printf, 3, 4))); +#define dev_warn(dev, ...) dev_printk("warn", dev, __VA_ARGS__) +#define dev_dbg(dev, ...) dev_printk("dbg", dev, __VA_ARGS__) +@DEFINITIONS@ +int apple_rtkit_crashlog_locate(const u8 *bfr, size_t size, size_t *log_offset, + u32 *log_id, unsigned int *depth); +void apple_rtkit_crashlog_dump(struct apple_rtkit *rtk, u8 *bfr, size_t size); +''' + +UNALIGNED = r''' +#include +#include +static inline uint32_t get_unaligned_le32(const void *p) { uint32_t v; memcpy(&v, p, 4); return v; } +static inline unsigned long long get_unaligned_le64(const void *p) +{ unsigned long long v; memcpy(&v, p, 8); return v; } +''' + +MAIN = r''' +#include "rtkit-internal.h" + +#define FOURCC(s) (((u32)(s)[0] << 24) | ((u32)(s)[1] << 16) | ((u32)(s)[2] << 8) | (u32)(s)[3]) +#define MAX_LINES 1000 + +static char lines[MAX_LINES][512]; +static unsigned int n_lines; +static struct device device; +static struct apple_rtkit rtk = { .dev = &device }; + +void dev_printk(const char *level, struct device *dev, const char *fmt, ...) +{ + char *line = lines[n_lines]; + va_list ap; + size_t n; + + assert(dev == &device); + /* A walk that does not advance prints without end. */ + assert(n_lines < MAX_LINES - 1); + n_lines++; + va_start(ap, fmt); + vsnprintf(line, sizeof(lines[0]), fmt, ap); + va_end(ap); + n = strlen(line); + while (n && line[n - 1] == '\n') + line[--n] = 0; + printf(" %s: %s\n", level, line); +} + +static void put32(u8 *b, size_t off, u32 v) { memcpy(b + off, &v, 4); } +static void put64(u8 *b, size_t off, u64 v) { memcpy(b + off, &v, 8); } + +/* A section header: its type, a fill word, flags and its size, header included. */ +static size_t section(u8 *b, size_t off, const char *type, u32 flags, u32 size) +{ + put32(b, off, FOURCC(type)); + put32(b, off + 4, 0xefefefef); + put32(b, off + 8, flags); + put32(b, off + 12, size); + return off + size; +} + +/* A 'CLHE' header (or footer) of a log of `size` bytes at `off`. */ +static void clhe(u8 *b, size_t off, u32 size, u32 flags) +{ + put32(b, off, FOURCC("CLHE")); + put32(b, off + 4, 0x303); + put32(b, off + 8, size); + put32(b, off + 12, flags); +} + +/* A 'CLGH' container at `off` with `count` (id, offset) records. */ +static void clgh(u8 *b, size_t off, u32 size, const char *current, unsigned int count, + const char *const *ids, const u32 *offsets) +{ + put32(b, off, FOURCC("CLGH")); + put32(b, off + 4, 0x202); + put32(b, off + 8, size); + put32(b, off + 12, FOURCC(current)); + put32(b, off + 16, count); + for (unsigned int i = 0; i < count; i++) { + put64(b, off + 0x14 + i * 0x18, FOURCC(ids[i])); + put32(b, off + 0x14 + i * 0x18 + 16, offsets[i]); + } +} + +/* Runs the dump on an exact-size copy of `log` and returns the number of lines. */ +static unsigned int dump(const char *name, const u8 *log, size_t size) +{ + u8 *copy = malloc(size ? size : 1); + + assert(copy); + memcpy(copy, log, size); + n_lines = 0; + printf("%s (%zu bytes)\n", name, size); + apple_rtkit_crashlog_dump(&rtk, copy, size); + free(copy); + return n_lines; +} + +static bool printed(const char *text) +{ + for (unsigned int i = 0; i < n_lines; i++) + if (strstr(lines[i], text)) + return true; + return false; +} + +static bool ended(void) +{ + return n_lines && !strcmp(lines[n_lines - 1], "RTKit: End of crashlog reached"); +} + +#define DCP_SIZE 0x17000 +#define DCP_LOG 0x2000 +#define DCP_LOG_SIZE 0x26e0 +#define MAILBOX_ENTRIES 128 + +/* The layout of a T6050 DCP crashlog: the RTAL task's log, two containers deep. */ +static void dcp_log(u8 *b) +{ + static const char *const top[] = { "CL4U", "CL4K" }, *const tasks[] = { "root", "RTAL" }; + static const u32 top_offsets[] = { 0x44, 0x12000 }, task_offsets[] = { 0x44, 0x1fbc }; + static const u32 pattern[8] = { 0x202, 0x242, 0x302, 0x342, 0x302, 0x342, 0x202, 0x242 }; + size_t off = DCP_LOG + 0x20, body; + + memset(b, 0, DCP_SIZE); + clgh(b, 0, DCP_SIZE, "CL4U", 2, top, top_offsets); + clgh(b, 0x44, 0x11fbc, "RTAL", 2, tasks, task_offsets); + clhe(b, DCP_LOG, DCP_LOG_SIZE, 0x820); + put32(b, DCP_LOG + 0x1c, FOURCC("RTAL")); + + body = off + 16; + off = section(b, off, "Cstr", 0x101, 0x60); + put32(b, body, 1); + strcpy((char *)b + body + 4, "crash message [0x87aa9a0]"); + off = section(b, off, "Cver", 0x300, 0xa0); + body = off + 16; + off = section(b, off, "Ctim", 0x100, 0x20); + put64(b, body, 87481704354ULL); + off = section(b, off, "Ccst", 0x400, 0x70); + off = section(b, off, "Crtk", 0x300, 0x17c0); + body = off + 16; + off = section(b, off, "Cmbx", 0x300, 0xc30); + for (unsigned int i = 0; i < MAILBOX_ENTRIES; i++) { + size_t e = body + 28 + i * 0x18; + + put64(b, e, 0x37); + put64(b, e + 8, pattern[i % 8]); + put32(b, e + 16, 0xda8656a9 + i * 0x1000); + } + off = section(b, off, "Cpct", 0x200, 0x50); + off = section(b, off, "Csta", 0x100, 0x30); + off = section(b, off, "Cced", 0x100, 0x50); + off = section(b, off, "Chex", 0x100, 0x20); + off = section(b, off, "Csta", 0x100, 0x30); + assert(off == DCP_LOG + DCP_LOG_SIZE - 0x20); + clhe(b, off, DCP_LOG_SIZE, 0x820); +} + +static void test_dcp_log(void) +{ + static const char *const expect[] = { + "RTKit: Crashlog container: log 'RTAL' at 0x2000 (depth 2)", + "RTKit: Message (id=1): crash message [0x87aa9a0]", + "RTKit: Version: ", + "RTKit: Crash time: 87481704354", + "RTKit: Unknown crashlog section: 43637374", + "RTKit: Unknown crashlog section: 4372746b", + "RTKit: Mailbox history (type = 0, index = 0)", + "RTKit: Unknown crashlog section: 43706374", + "RTKit: Unknown crashlog section: 43737461", + "RTKit: Unknown crashlog section: 43636564", + "RTKit: Unknown crashlog section: 43686578", + "RTKit: Unknown crashlog section: 43737461", + "RTKit: End of crashlog reached", + }; + static u8 b[DCP_SIZE]; + unsigned int n, i, j = 0, entries = 0; + size_t log_offset; + unsigned int depth; + u32 id; + + dcp_log(b); + assert(!apple_rtkit_crashlog_locate(b, DCP_SIZE, &log_offset, &id, &depth)); + assert(log_offset == DCP_LOG && id == FOURCC("RTAL") && depth == 2); + n = dump("T6050 DCP container log", b, DCP_SIZE); + for (i = 0; i < n; i++) { + if (!strncmp(lines[i], "RTKit: #", 9)) { + entries++; + continue; + } + assert(j < sizeof(expect) / sizeof(expect[0])); + assert(!strcmp(lines[i], expect[j])); + j++; + } + assert(j == sizeof(expect) / sizeof(expect[0])); + assert(entries == MAILBOX_ENTRIES); + assert(printed("RTKit: #000@da8656a9: 0000000000000037 0000000000000202")); + assert(printed("RTKit: #127@da8e46a9: 0000000000000037 0000000000000242")); + + /* Still being written: not a complete log. */ + put32(b, DCP_LOG + 12, 0x820 | 0x100); + assert(apple_rtkit_crashlog_locate(b, DCP_SIZE, &log_offset, &id, &depth) == -EAGAIN); + dump("log still being written", b, DCP_SIZE); + assert(printed("holds no complete log (-11)")); + put32(b, DCP_LOG + 12, 0x820); + + /* A record past the buffer, and a container that names itself. */ + put32(b, 0x44 + 0x14 + 0x18 + 16, DCP_SIZE); + assert(apple_rtkit_crashlog_locate(b, DCP_SIZE, &log_offset, &id, &depth) == -EINVAL); + dump("record past the buffer", b, DCP_SIZE); + assert(printed("holds no complete log (-22)")); + put32(b, 0x44 + 0x14 + 0x18 + 16, 0); + assert(apple_rtkit_crashlog_locate(b, DCP_SIZE, &log_offset, &id, &depth) == -EINVAL); + /* The log's section walk is bounded by the log, not the buffer. */ + dcp_log(b); + put32(b, DCP_LOG + 8, 0x20 + 0x60); + dump("log cut after its first section", b, DCP_SIZE); + assert(printed("End of crashlog reached but no footer present") && !printed("Message")); +} + +/* A bare log: a header, then sections built by the caller, then optionally a footer. */ +static u8 logbuf[0x1000]; + +static size_t bare(void) +{ + memset(logbuf, 0, sizeof(logbuf)); + return 0x20; +} + +static unsigned int finish(const char *name, size_t off, bool footer) +{ + size_t size = off + (footer ? 0x20 : 0); + + if (footer) + clhe(logbuf, off, size, 0); + clhe(logbuf, 0, size, 0); + return dump(name, logbuf, size); +} + +static void test_malformed(void) +{ + size_t off, body; + unsigned int i; + + off = section(logbuf, bare(), "Ctim", 0x100, 0x20); + section(logbuf, off, "Csta", 0x100, 0); + finish("zero section size", off + 0x30, true); + assert(printed("section 43737461 at 0x40 has a bad size 0x0") && n_lines == 2); + + off = section(logbuf, bare(), "Ctim", 0x100, 0x20); + section(logbuf, off, "Cmbx", 0x300, 0x10000); + finish("oversized section", off + 0x40, true); + assert(printed("section 436d6278 at 0x40 has a bad size 0x10000")); + + off = bare(); + put32(logbuf, off, FOURCC("Ctim")); + finish("truncated section header", off + 8, false); + assert(printed("section header at 0x20 is truncated") && n_lines == 1); + + off = section(logbuf, bare(), "Ctim", 0x100, 0x20); + finish("section, then the footer", off, true); + assert(printed("Crash time: 0") && ended() && n_lines == 2); + + /* Without a footer the last section may not be decoded: its decoder reads 16 bytes on. */ + body = bare(); + off = section(logbuf, body, "Cstr", 0x101, 0x40); + put32(logbuf, body + 16, 1); + memset(logbuf + body + 20, 'm', 0x40 - 20); + finish("section reaching the end of a log without a footer", off, false); + assert(printed("End of crashlog reached but no footer present") && n_lines == 1); + + for (u32 size = 16; size < 28; size++) { + off = section(logbuf, bare(), "Cmbx", 0x300, size); + finish("short mailbox section", off, true); + assert(printed("Mailbox section too small") && ended()); + } + off = section(logbuf, bare(), "Cmbx", 0x300, 28 + 2 * 0x18); + finish("two-entry mailbox section", off, true); + assert(printed("RTKit: #001@") && !printed("#002") && ended()); + + body = bare(); + off = section(logbuf, body, "Crl4", 0x100, 0x378); + put32(logbuf, body + 0x14, 0xd8); + put64(logbuf, body + 0x110, 0xfffffe0007001234ULL); + put64(logbuf, body + 0x360, 0xdead0000ULL); + for (i = 0; i < 28; i++) + put64(logbuf, body + 0x18 + i * 8, 0x1000 + i); + finish("whole Crl4 section", off, true); + assert(printed("Exception dump (Crl4):") && printed("PC = 0xfffffe0007001234") && + printed("FAR = 0xdead0000") && + printed("x24-x27 = 0000000000001018 0000000000001019 000000000000101a 000000000000101b") && + ended()); + + off = section(logbuf, bare(), "Crl4", 0x100, 0x378); + finish("truncated Crl4 section", 0x20 + 0x100, true); + assert(printed("section 43726c34 at 0x20 has a bad size 0x378")); + + off = section(logbuf, bare(), "Crl4", 0x100, 0x40); + finish("short Crl4 section", off, true); + assert(printed("Crl4 section too small: 0x40") && ended()); + + body = bare(); + off = section(logbuf, body, "Crl4", 0x100, 0x378); + put32(logbuf, body + 0x10, 1 << 16); + put32(logbuf, body + 0x14, 0xd8); + finish("undecodable Crl4 frame", off, true); + assert(printed("Crl4 frame not decodable") && ended()); + + /* Strings without a terminator, against the end of the log. */ + body = bare(); + off = section(logbuf, body, "Cver", 0x300, 0x40); + memset(logbuf + body + 32, 'v', 0x40 - 32); + put32(logbuf, off, FOURCC("CLHE")); + memset(logbuf + off + 4, 0x55, 12); + clhe(logbuf, 0, off + 16, 0); + dump("unterminated version", logbuf, off + 16); + assert(!strcmp(lines[0], "RTKit: Version: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvEHLCUUUUUUUUUUUU")); + + body = bare(); + off = section(logbuf, body, "Cstr", 0x101, 0x40); + put32(logbuf, body + 16, 1); + memset(logbuf + body + 20, 'm', 0x40 - 20); + put32(logbuf, off, FOURCC("CLHE")); + memset(logbuf + off + 4, 0x55, 12); + clhe(logbuf, 0, off + 16, 0); + dump("unterminated message", logbuf, off + 16); + assert(!strcmp(lines[0], "RTKit: Message (id=1): mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmEHLCUUUUUUUUUUUU")); + + body = bare(); + off = section(logbuf, body, "Cstr", 0x101, 0x40); + put32(logbuf, body + 16, 2); + strcpy((char *)logbuf + body + 20, "first\nsecond\n"); + finish("message lines", off, true); + assert(printed("Message (id=2): first") && printed("Message (id=2): second") && ended()); + + /* Buffers too short for a header, and logs larger than their buffer. */ + for (size_t size = 0; size < 0x20; size += 4) { + memset(logbuf, 0, sizeof(logbuf)); + clhe(logbuf, 0, 0x20, 0); + dump("short buffer", logbuf, size); + assert(printed("Crashlog buffer too small")); + } + clhe(logbuf, 0, 0x40, 0); + dump("log larger than its buffer", logbuf, 0x20); + assert(printed("Crashlog size (40) is too large")); + memset(logbuf, 0, sizeof(logbuf)); + put32(logbuf, 0, FOURCC("CLGH")); + dump("container header only", logbuf, 0x20); + assert(printed("holds no complete log (-22)")); +} + +static int test_file(const char *path) +{ + FILE *f = fopen(path, "rb"); + size_t size; + u8 *b; + + assert(f); + fseek(f, 0, SEEK_END); + size = ftell(f); + rewind(f); + b = malloc(size); + assert(b && fread(b, 1, size, f) == size); + fclose(f); + dump(path, b, size); + free(b); + return 0; +} + +int main(int argc, char **argv) +{ + assert(FOURCC("CLHE") == APPLE_RTKIT_CRASHLOG_HEADER_FOURCC); + assert(FOURCC("CLGH") == APPLE_RTKIT_CRASHLOG_CONTAINER_FOURCC); + if (argc > 1) + return test_file(argv[1]); + test_dcp_log(); + test_malformed(); + printf("PASS rtkit crashlog: container log decoded; malformed logs refused without a loop or an over-read\n"); + return 0; +} +''' + + +def definitions(header): + """The crashlog fourccs and header struct of rtkit-internal.h.""" + found = re.findall(r'^#define APPLE_RTKIT_CRASHLOG_\w+_FOURCC .*$', header, re.M) + found += re.findall(r'^struct apple_rtkit_crashlog_header \{.*?^\};\n(?:\nstatic_assert\(.*?\);)?', + header, re.M | re.S) + assert len(found) == 3, found + return '\n'.join(found) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--ref', help='Git revision of the parser to exercise') + parser.add_argument('--out', type=Path) + parser.add_argument('--mutation', choices=sorted(MUTATIONS)) + parser.add_argument('--log', type=Path, help='a raw crashlog buffer to dump') + args = parser.parse_args() + + def read(path): + if args.ref: + return subprocess.check_output(['git', 'show', f'{args.ref}:{path}'], cwd=ROOT, text=True) + return (ROOT / path).read_text() + source, header = read(SOURCE), read(HEADER) + if args.mutation: + old, new = MUTATIONS[args.mutation] + # A mutation that no longer matches the parser would test nothing. + assert source.count(old) == 1, 'stale mutation: ' + args.mutation + source = source.replace(old, new) + + def run(out): + out.mkdir(parents=True, exist_ok=True) + (out / 'linux').mkdir(exist_ok=True) + (out / 'rtkit-crashlog.c').write_text(source) + (out / 'rtkit-internal.h').write_text(STUB.replace('@DEFINITIONS@', definitions(header))) + (out / 'linux/unaligned.h').write_text(UNALIGNED) + (out / 'main.c').write_text(MAIN) + exe = out / 'crashlog-tests' + compiler = subprocess.run(['clang', '-std=gnu11', '-O1', '-g', '-Wall', '-Werror', '-Wno-unused-function', + '-fsanitize=address,undefined', '-fno-sanitize-recover=all', + '-I', str(out), str(out / 'rtkit-crashlog.c'), str(out / 'main.c'), + '-o', str(exe)], capture_output=True, text=True) + (out / 'compile.log').write_text(compiler.stdout + compiler.stderr) + if compiler.returncode: + print(compiler.stdout + compiler.stderr) + compiler.check_returncode() + env = dict(os.environ, ASAN_OPTIONS='abort_on_error=1:detect_leaks=0', UBSAN_OPTIONS='print_stacktrace=1') + result = subprocess.run([str(exe)] + ([str(args.log.resolve())] if args.log else []), + capture_output=True, text=True, env=env) + receipt = {'source_sha256': hashlib.sha256(source.encode()).hexdigest(), 'ref': args.ref, + 'mutation': args.mutation, 'log': str(args.log) if args.log else None, + 'exit': result.returncode} + (out / 'results.json').write_text(json.dumps(dict(receipt, stdout=result.stdout, + stderr=result.stderr), indent=2) + '\n') + print(result.stdout + result.stderr) + print(json.dumps(receipt)) + return result.returncode != 0 + + if args.out: + return run(args.out) + with tempfile.TemporaryDirectory(prefix='rtkit-crashlog-') as out: + return run(Path(out)) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 5c5ca93c68594..b8ea5fdd70b11 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -145,6 +145,9 @@ def mutations(flag, names, base, expect=KILL): + mutations('--mutation', ('ack-clobber', 'arm-ack', 'offset-seconds', 'offset-sign', 'event-bit', 'wrong-base'), out()), 'qspi-nvram-tests.py': [(out('--output'), PASS)], + 'rtkit-crashlog-tests.py': [(out(), PASS)] + + mutations('--mutation', ('buffer-header', 'section-header', 'section-size', 'footer-room', + 'mailbox-minimum', 'version-string', 'message-string'), out()), 'rtkit-oslog-tests.py': [(out(), PASS)] + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), 't6030-clock-tests.py': [(out(), PASS)], From 71825bddabf83f5338eac225fb628efcd03e3897 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 05:59:44 +1100 Subject: [PATCH 007/342] iio: apple: expose AOP fused motion and temperature The J616s AOP announces two sensor services Linux left unclaimed: devmotion6, the always-on processor's six-axis fusion output, and als-temp, a board temperature sensor next to the light sensor. Claim them in the AOP core and expose them through IIO: the fused orientation as a quaternion (W/X/Y/Z, signed Q30, 50 Hz) and the board temperature in millidegrees Celsius (1 Hz). Stop both streams across system sleep and restart them on resume. Optional temperature calibration comes from bootloader-filled DT properties; without it the sensor runs on its own defaults. Add the T604x AOP child nodes and their bindings. The wakehint and cma services stay unclaimed: wakehint is a single vendor byte with no established meaning, and cma is a CoreMotion command and history transport rather than a sensor. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../bindings/iio/imu/apple,aop-devmotion.yaml | 33 + .../iio/temperature/apple,aop-temp.yaml | 50 ++ .../bindings/soc/apple/apple,t6041-aop.yaml | 20 + Documentation/iio/aop-sensors.rst | 71 ++- arch/arm64/boot/dts/apple/t604x.dtsi | 8 + arch/arm64/configs/asahi.config | 2 + drivers/iio/common/aop_sensors/Kconfig | 26 + drivers/iio/common/aop_sensors/Makefile | 2 + .../iio/common/aop_sensors/aop_devmotion.rs | 526 ++++++++++++++++ drivers/iio/common/aop_sensors/aop_temp.rs | 571 ++++++++++++++++++ drivers/soc/apple/aop.rs | 2 + rust/bindings/bindings_helper.h | 3 + 12 files changed, 1312 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/imu/apple,aop-devmotion.yaml create mode 100644 Documentation/devicetree/bindings/iio/temperature/apple,aop-temp.yaml create mode 100644 drivers/iio/common/aop_sensors/aop_devmotion.rs create mode 100644 drivers/iio/common/aop_sensors/aop_temp.rs diff --git a/Documentation/devicetree/bindings/iio/imu/apple,aop-devmotion.yaml b/Documentation/devicetree/bindings/iio/imu/apple,aop-devmotion.yaml new file mode 100644 index 0000000000000..22e0950345f12 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/imu/apple,aop-devmotion.yaml @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/imu/apple,aop-devmotion.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple AOP device-motion fusion service + +maintainers: + - Ryan Murray + +description: + The Always-On Processor of Apple laptops fuses the machine's inertial + sensors and reports an orientation quaternion through this service. The + service has no application-processor MMIO or interrupt resource of its own. + +properties: + compatible: + items: + - const: apple,t6041-aop-devmotion6 + - const: apple,aop-devmotion6 + +required: + - compatible + +additionalProperties: false + +examples: + - | + devmotion6 { + compatible = "apple,t6041-aop-devmotion6", "apple,aop-devmotion6"; + }; + diff --git a/Documentation/devicetree/bindings/iio/temperature/apple,aop-temp.yaml b/Documentation/devicetree/bindings/iio/temperature/apple,aop-temp.yaml new file mode 100644 index 0000000000000..3652ae2c78502 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/temperature/apple,aop-temp.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/apple,aop-temp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple AOP board temperature sensor service + +maintainers: + - Ryan Murray + +description: | + The Always-On Processor of Apple laptops reads a board temperature sensor + and reports it through this service. The bootloader may copy per-machine + calibration containers into the optional properties below. Their payloads + are opaque to the operating system and are sent unchanged to the firmware. + +properties: + compatible: + items: + - const: apple,t6041-aop-als-temp + - const: apple,aop-als-temp + + apple,temp-offset-calibration: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: Sensor offset calibration container from the bootloader. + + apple,absolute-temp-offset-cal: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: Absolute temperature offset container from the bootloader. + + apple,absolute-temp-offset-fcm-cal: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: Front-compensation absolute offset container. + + apple,absolute-temp-offset-bcm-cal: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: Back-compensation absolute offset container. + +required: + - compatible + +additionalProperties: false + +examples: + - | + als-temp { + compatible = "apple,t6041-aop-als-temp", "apple,aop-als-temp"; + }; + diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml index 786bd7b1993c0..cdb3bb926ba7a 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6041-aop.yaml @@ -107,6 +107,18 @@ properties: description: The gyroscope service. unevaluatedProperties: false + devmotion6: + type: object + $ref: /schemas/iio/imu/apple,aop-devmotion.yaml# + description: The device-motion fusion service. + unevaluatedProperties: false + + als-temp: + type: object + $ref: /schemas/iio/temperature/apple,aop-temp.yaml# + description: The board temperature sensor service. + unevaluatedProperties: false + required: - compatible - reg @@ -159,5 +171,13 @@ examples: gyro { compatible = "apple,t6041-aop-gyro", "apple,aop-gyro"; }; + + devmotion6 { + compatible = "apple,t6041-aop-devmotion6", "apple,aop-devmotion6"; + }; + + als-temp { + compatible = "apple,t6041-aop-als-temp", "apple,aop-als-temp"; + }; }; }; diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 6c3225024a82a..3f47ba72778b5 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -7,8 +7,9 @@ Apple AOP sensors The AOP firmware announces sensor services over EPIC. The AOP core matches each service to a child node in the device tree and forwards its fake-HID reports to the corresponding IIO driver. Ambient light (``als``), lid -angle (``las``), acceleration (``accel``) and angular rate (``gyro``) use -this same transport; no HID bus device is created. +angle (``las``), acceleration (``accel``), angular rate (``gyro``), fused +device motion (``devmotion6``) and board temperature (``als-temp``) use this +same transport; no HID bus device is created. Lid angle ========= @@ -60,6 +61,42 @@ core's ``nCal`` boot argument for the SoC. The T6040 firmware accepts the calibration and the report interval with ``nCal`` 0, but sends no reports; its own default, which the core keeps, is 1. +Device-motion fusion +==================== + +Enable ``CONFIG_IIO_AOP_SENSOR_DEVMOTION``. The device is named +``aop-sensors-devmotion6`` and exposes one ``IIO_ROT`` channel modified as a +quaternion. Direct reads return four signed values in W, X, Y, Z order; their +fixed scale is ``1 / 2^30``. The buffered channel uses the same four-value +Q30 representation followed by an optional host timestamp. At rest the +quaternion norm should be close to one, and tilting the laptop should move at +least two components smoothly while the norm remains close to one. + +The service's current report has a type byte followed by a versioned fixed +layout. Type 2 is 108 bytes and carries little-endian IEEE-754 X, Y, Z and W +at offset 28. Types 3 and 4 are 60 bytes and carry the same fields at offset +12. Type 1 is a five-byte state report and does not update the IIO sample. +Reports begin after property 0 is set to a non-zero interval in microseconds; +the driver requests 50 Hz, writes zero around system sleep, and restores the +interval after resume. This fused stream needs no separate calibration blob. + +Board temperature +================= + +Enable ``CONFIG_IIO_AOP_SENSOR_TEMP``. The device is named +``aop-sensors-als-temp``. ``in_temp_input`` and buffered samples are in +millidegrees Celsius, following the IIO temperature ABI, and +``sampling_frequency`` is one hertz. The 14-byte report stores signed Q16.16 +degrees Celsius at offset 2; the driver timestamps it on receipt. + +The bootloader may provide ``apple,temp-offset-calibration``, +``apple,absolute-temp-offset-cal``, ``apple,absolute-temp-offset-fcm-cal`` and +``apple,absolute-temp-offset-bcm-cal`` containers. Location-zero packets are +sent unchanged before the one-hertz interval. If none are present the driver +warns and selects the firmware's default calibration state; otherwise it +selects the calibrated state. A missing optional calibration therefore does +not hide an otherwise usable sensor. + Host regression tests require Python 3 and a Rust compiler:: @@ -92,3 +129,33 @@ On J616s, or another supported laptop: A readable feature report alone does not prove unsolicited reports arrive. Establish that transport behaviour before adding any polling or firmware setup request. + +To test the two additional J616s services without rebooting, replace the +module names below with their installed paths if the distribution does not +put them in the normal module tree:: + + modprobe -r aop_devmotion aop_temp + modprobe aop_devmotion + modprobe aop_temp + +Find the devices by name rather than assuming IIO numbers:: + + for d in /sys/bus/iio/devices/iio:device*; do + printf '%s: ' "$d"; cat "$d/name" + done + iio_info + +For ``aop-sensors-devmotion6``, enable ``in_rot_quaternion_en`` and the +timestamp if desired, then run ``iio_readdev``. Four signed Q30 values make +one quaternion sample. Flat and stationary, the values should be stable and +their scaled squared norm close to one. Tilt the left, right and display +edges in turn; components should change continuously rather than jump or +remain zero. For ``aop-sensors-als-temp``, ``cat in_temp_input`` should show a +plausible board temperature in millidegrees and ``iio_readdev`` should yield +one signed 32-bit temperature plus the optional timestamp each second. + +After testing, suspend and resume once and verify both streams restart. A +missing device means the AOP did not announce the service or its child did +not bind; ``ENODATA`` means it announced and bound but has not delivered a +valid sample. Record ``dmesg`` around either case, including property refusal, +report-size, AOP timeout and DART messages. diff --git a/arch/arm64/boot/dts/apple/t604x.dtsi b/arch/arm64/boot/dts/apple/t604x.dtsi index 178f1b061283e..8399b5db53d08 100644 --- a/arch/arm64/boot/dts/apple/t604x.dtsi +++ b/arch/arm64/boot/dts/apple/t604x.dtsi @@ -1421,6 +1421,14 @@ aop_gyro: gyro { compatible = "apple,t6041-aop-gyro", "apple,aop-gyro"; }; + + aop_devmotion: devmotion6 { + compatible = "apple,t6041-aop-devmotion6", "apple,aop-devmotion6"; + }; + + aop_temp: als-temp { + compatible = "apple,t6041-aop-als-temp", "apple,aop-als-temp"; + }; }; /* ADT lists the interrupts as 1, 0, 3, 2 of the block: send-empty is the lowest. */ diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 870ff1b6b4dda..b088d1b622109 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -123,6 +123,8 @@ CONFIG_APPLE_T8132_PLATFORM_HANDOFF=y CONFIG_IIO_AOP_SENSOR_LAS=m CONFIG_IIO_AOP_SENSOR_ALS=m CONFIG_IIO_AOP_SENSOR_MOTION=m +CONFIG_IIO_AOP_SENSOR_DEVMOTION=m +CONFIG_IIO_AOP_SENSOR_TEMP=m CONFIG_RUST_FW_LOADER_ABSTRACTIONS=y CONFIG_PWM_APPLE=m CONFIG_APPLE_AIC=y diff --git a/drivers/iio/common/aop_sensors/Kconfig b/drivers/iio/common/aop_sensors/Kconfig index df1277d4082af..08bfa02ae8d08 100644 --- a/drivers/iio/common/aop_sensors/Kconfig +++ b/drivers/iio/common/aop_sensors/Kconfig @@ -35,3 +35,29 @@ config IIO_AOP_SENSOR_MOTION with X, Y and Z channels, readable directly or through a buffer. The bootloader has to pass the machine's sensor calibration in the device tree. + +config IIO_AOP_SENSOR_DEVMOTION + tristate "AOP device-motion fusion" + depends on ARCH_APPLE || COMPILE_TEST + depends on RUST + depends on SYSFS + select APPLE_AOP + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Module to expose the orientation quaternion produced by the Apple + Always-On Processor's device-motion fusion service. The quaternion is + an IIO rotation channel readable directly or through a buffer. + +config IIO_AOP_SENSOR_TEMP + tristate "AOP board temperature sensor" + depends on ARCH_APPLE || COMPILE_TEST + depends on RUST + depends on SYSFS + select APPLE_AOP + select IIO_BUFFER + select IIO_KFIFO_BUF + help + Module to expose the board-temperature sensor announced by the Apple + Always-On Processor as an IIO temperature device. Calibration data can + be supplied by the bootloader in the device tree. diff --git a/drivers/iio/common/aop_sensors/Makefile b/drivers/iio/common/aop_sensors/Makefile index 4b769a78d44c5..bdbbcf19da63b 100644 --- a/drivers/iio/common/aop_sensors/Makefile +++ b/drivers/iio/common/aop_sensors/Makefile @@ -3,3 +3,5 @@ obj-$(CONFIG_IIO_AOP_SENSOR_LAS) += aop_las.o obj-$(CONFIG_IIO_AOP_SENSOR_ALS) += aop_als.o obj-$(CONFIG_IIO_AOP_SENSOR_MOTION) += aop_motion.o +obj-$(CONFIG_IIO_AOP_SENSOR_DEVMOTION) += aop_devmotion.o +obj-$(CONFIG_IIO_AOP_SENSOR_TEMP) += aop_temp.o diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs new file mode 100644 index 0000000000000..cc14b1bb58b20 --- /dev/null +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -0,0 +1,526 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Apple AOP device-motion fusion driver +//! +//! The `devmotion6` service reports the AOP fusion engine's orientation as a +//! quaternion. The service has several versioned report layouts; the current +//! layouts all carry four little-endian IEEE-754 singles in X, Y, Z, W order. +//! IIO exposes them in its standard W, X, Y, Z order as signed Q30 values. + +use core::{ + ffi::{c_int, c_void}, + marker::PhantomPinned, + ptr, +}; + +use kernel::{ + bindings, c_str, + device::{self, Core}, + module_platform_driver, new_spinlock, of, platform, + prelude::*, + soc::apple::aop::{EPICService, FakehidListener, FakehidRegistration, AOP}, + sync::{ + aref::ARef, + atomic::{Atomic, Relaxed}, + Arc, SpinLock, + }, + types::{ForeignOwnable, Opaque}, +}; + +const SUBTYPE_SET_PROPERTY: u16 = 4; +const PROP_INTERVAL: u32 = 0; +const INTERVAL_US: u32 = 20_000; +const Q_FRAC_BITS: i32 = 30; + +/// The latest quaternion, in the IIO-defined W, X, Y, Z order. +#[derive(Clone, Copy, Default)] +struct Sample { + quat: [i32; 4], + valid: bool, +} + +/// One buffer scan. A quaternion is aligned like `IIO_DECLARE_QUATERNION()`. +#[repr(C, align(16))] +struct Scan { + quat: [i32; 4], + timestamp: i64, +} + +fn le_u32(data: &[u8], at: usize) -> Option { + Some(u32::from_le_bytes(data.get(at..at + 4)?.try_into().ok()?)) +} + +/// Converts a finite IEEE-754 single to signed Q30 without using FP in the +/// kernel. Values outside the representation saturate. +fn f32_to_q30(bits: u32) -> Option { + let exp = ((bits >> 23) & 0xff) as i32; + if exp == 0xff { + return None; + } + if exp == 0 { + return Some(0); + } + + let mant = i64::from(bits & 0x7f_ffff | 0x80_0000); + let shift = exp - 127 - 23 + Q_FRAC_BITS; + let magnitude = if shift >= 31 { + i64::MAX + } else if shift >= 0 { + mant.checked_shl(shift as u32).unwrap_or(i64::MAX) + } else if shift <= -63 { + 0 + } else { + mant >> -shift + }; + let signed = if bits & 0x8000_0000 != 0 { + -magnitude + } else { + magnitude + }; + Some(signed.clamp(i64::from(i32::MIN), i64::from(i32::MAX)) as i32) +} + +fn decode(report: &[u8]) -> Option<[i32; 4]> { + let offset = match (report.first().copied()?, report.len()) { + (2, 108) => 28, + (3 | 4, 60) => 12, + // Type 1 is a five-byte state report and has no orientation. + _ => return None, + }; + let x = f32_to_q30(le_u32(report, offset)?)?; + let y = f32_to_q30(le_u32(report, offset + 4)?)?; + let z = f32_to_q30(le_u32(report, offset + 8)?)?; + let w = f32_to_q30(le_u32(report, offset + 12)?)?; + Some([w, x, y, z]) +} + +struct Control { + dev: ARef, + aop: Arc, + service: EPICService, +} + +impl Control { + fn set_interval(&self, interval: u32) -> Result { + let mut msg = KVec::with_capacity(12, GFP_KERNEL)?; + msg.extend_from_slice(&0u32.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(&PROP_INTERVAL.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(&interval.to_le_bytes(), GFP_KERNEL)?; + let status = self + .aop + .epic_call(&self.service, SUBTYPE_SET_PROPERTY, &msg)?; + if status != 0 { + dev_err!(self.dev, "interval refused: status {:#x}\n", status); + return Err(EIO); + } + Ok(()) + } +} + +#[pin_data] +struct State { + iio: IioPtr, + #[pin] + sample: SpinLock, +} + +struct IioPtr(*mut bindings::iio_dev); + +// SAFETY: The IIO device may be used from any thread. The listener only calls +// IIO helpers that are valid from the AOP receive worker. +unsafe impl Send for IioPtr {} +// SAFETY: As above. +unsafe impl Sync for IioPtr {} + +impl FakehidListener for State { + fn process_fakehid_report(&self, data: &[u8]) -> Result<()> { + let Some(quat) = decode(data) else { + // State-only reports are expected and leave the sample unchanged. + return Ok(()); + }; + *self.sample.lock() = Sample { quat, valid: true }; + // SAFETY: The listener is removed before the IIO device is freed. + let timestamp = unsafe { bindings::iio_get_time_ns(self.iio.0) }; + let scan = Scan { quat, timestamp }; + // SAFETY: `scan` contains the complete only data channel followed by + // the timestamp, and the IIO core copies it synchronously. + unsafe { bindings::iio_push_to_buffers(self.iio.0, ptr::from_ref(&scan).cast()) }; + Ok(()) + } +} + +static SCAN_MASKS: [usize; 2] = [1, 0]; + +/// # Safety +/// +/// The IIO core supplies the registered device, channel, and output arrays. +unsafe extern "C" fn read_raw_multi( + indio_dev: *mut bindings::iio_dev, + _chan: *const bindings::iio_chan_spec, + max_len: i32, + vals: *mut i32, + val_len: *mut i32, + mask: isize, +) -> i32 { + // SAFETY: `priv_` is the `Arc` installed during allocation. + let state = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }; + if mask == bindings::BINDINGS_IIO_CHAN_INFO_SCALE as isize { + if max_len < 2 { + return EINVAL.to_errno(); + } + // SAFETY: The caller provided at least two elements. + unsafe { + *vals = 1; + *vals.add(1) = Q_FRAC_BITS; + *val_len = 2; + } + return bindings::IIO_VAL_FRACTIONAL_LOG2 as i32; + } + if mask != bindings::BINDINGS_IIO_CHAN_INFO_RAW as isize || max_len < 4 { + return EINVAL.to_errno(); + } + let sample = *state.sample.lock(); + if !sample.valid { + return ENODATA.to_errno(); + } + // SAFETY: The caller provided at least four elements. + unsafe { + ptr::copy_nonoverlapping(sample.quat.as_ptr(), vals, sample.quat.len()); + *val_len = sample.quat.len() as i32; + } + bindings::IIO_VAL_INT_MULTIPLE as i32 +} + +fn quaternion_channel() -> bindings::iio_chan_spec { + let mut chan = bindings::iio_chan_spec { + type_: bindings::BINDINGS_IIO_ROT, + channel2: bindings::BINDINGS_IIO_MOD_QUATERNION as i32, + scan_index: 0, + __bindgen_anon_1: bindings::iio_chan_spec__bindgen_ty_1 { + scan_type: bindings::iio_scan_type { + __bindgen_anon_1: bindings::iio_scan_type__bindgen_ty_1 { sign: b's' }, + realbits: 32, + storagebits: 32, + repeat: 4, + ..Default::default() + }, + }, + info_mask_separate: (1usize << bindings::BINDINGS_IIO_CHAN_INFO_RAW) + | (1usize << bindings::BINDINGS_IIO_CHAN_INFO_SCALE), + ..Default::default() + }; + chan.set_modified(1); + chan +} + +fn timestamp_channel() -> bindings::iio_chan_spec { + bindings::iio_chan_spec { + type_: bindings::BINDINGS_IIO_TIMESTAMP, + channel: -1, + scan_index: 1, + __bindgen_anon_1: bindings::iio_chan_spec__bindgen_ty_1 { + scan_type: bindings::iio_scan_type { + __bindgen_anon_1: bindings::iio_scan_type__bindgen_ty_1 { sign: b's' }, + realbits: 64, + storagebits: 64, + ..Default::default() + }, + }, + ..Default::default() + } +} + +struct Spec { + channels: [bindings::iio_chan_spec; 2], + info: bindings::iio_info, + _p: PhantomPinned, +} + +struct MotionIio { + dev: *mut bindings::iio_dev, + _spec: Pin>, + registered: bool, +} + +impl MotionIio { + fn new(pdev: &platform::Device>) -> Result<(Self, Arc)> { + let dev = pdev.as_ref(); + let spec = KBox::pin( + Spec { + channels: [quaternion_channel(), timestamp_channel()], + info: bindings::iio_info { + read_raw_multi: Some(read_raw_multi), + ..Default::default() + }, + _p: PhantomPinned, + }, + GFP_KERNEL, + )?; + // SAFETY: `dev` is a valid platform device. + let indio_dev = unsafe { bindings::iio_device_alloc(dev.as_raw(), 0) }; + if indio_dev.is_null() { + return Err(ENOMEM); + } + let state = match Arc::pin_init( + pin_init!(State { + iio: IioPtr(indio_dev), + sample <- new_spinlock!(Sample::default()), + }), + GFP_KERNEL, + ) { + Ok(state) => state, + Err(e) => { + // SAFETY: Allocated above and not registered. + unsafe { bindings::iio_device_free(indio_dev) }; + return Err(e); + } + }; + // SAFETY: The IIO device is unregistered and `spec` is pinned. + unsafe { + (*indio_dev).priv_ = state.clone().into_foreign().cast(); + (*indio_dev).name = c"aop-sensors-devmotion6".as_char_ptr(); + (*indio_dev).channels = spec.channels.as_ptr(); + (*indio_dev).num_channels = spec.channels.len() as i32; + (*indio_dev).info = &spec.info; + (*indio_dev).modes = bindings::INDIO_DIRECT_MODE as i32; + (*indio_dev).available_scan_masks = SCAN_MASKS.as_ptr(); + } + // SAFETY: Both devices are valid and the buffer is device-managed. + let ret = unsafe { + bindings::devm_iio_kfifo_buffer_setup_ext( + dev.as_raw(), + indio_dev, + ptr::null(), + ptr::null_mut(), + ) + }; + if ret < 0 { + // SAFETY: The device is not registered; the private pointer is + // the foreign `Arc` installed above. + unsafe { + drop(Arc::::from_foreign((*indio_dev).priv_.cast())); + bindings::iio_device_free(indio_dev); + } + return Err(Error::from_errno(ret)); + } + Ok(( + Self { + dev: indio_dev, + _spec: spec, + registered: false, + }, + state, + )) + } + + fn register(&mut self) -> Result { + let module = kernel::module::this_module::(); + // SAFETY: The device is fully initialized and unregistered. + let ret = unsafe { bindings::__iio_device_register(self.dev, module.as_ptr()) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + self.registered = true; + Ok(()) + } +} + +impl Drop for MotionIio { + fn drop(&mut self) { + // SAFETY: The device and its private `Arc` were installed by `new()`. + unsafe { + if self.registered { + bindings::iio_device_unregister(self.dev); + } + drop(Arc::::from_foreign((*self.dev).priv_.cast())); + bindings::iio_device_free(self.dev); + } + } +} + +// SAFETY: The IIO core serializes registration and removal. +unsafe impl Send for MotionIio {} +// SAFETY: As above; there are no methods taking `&self`. +unsafe impl Sync for MotionIio {} + +#[repr(C)] +struct PmHook { + nb: Opaque, + control: Arc, + registered: Atomic, +} + +/// # Safety +/// +/// `nb` is the first field of a registered `PmHook`. +unsafe extern "C" fn pm_event( + nb: *mut bindings::notifier_block, + action: usize, + _data: *mut c_void, +) -> c_int { + // SAFETY: By the callback contract above. + let hook = unsafe { &*nb.cast::() }; + let ret = match action as u32 { + bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => { + hook.control.set_interval(0) + } + bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => { + hook.control.set_interval(INTERVAL_US) + } + _ => return bindings::NOTIFY_DONE as c_int, + }; + if let Err(e) = ret { + dev_warn!( + hook.control.dev, + "reports not switched for sleep: {:?}\n", + e + ); + } + bindings::NOTIFY_OK as c_int +} + +#[cfg(CONFIG_PM_SLEEP)] +/// # Safety +/// +/// `nb` remains pinned until [`pm_unregister`] is called. +unsafe fn pm_register(nb: *mut bindings::notifier_block) -> c_int { + // SAFETY: The caller keeps the block pinned through unregister. + unsafe { bindings::register_pm_notifier(nb) } +} + +#[cfg(CONFIG_PM_SLEEP)] +/// # Safety +/// +/// `nb` was registered by [`pm_register`]. +unsafe fn pm_unregister(nb: *mut bindings::notifier_block) { + // SAFETY: The block was registered by `pm_register`. + unsafe { bindings::unregister_pm_notifier(nb) }; +} + +#[cfg(not(CONFIG_PM_SLEEP))] +/// # Safety +/// +/// No requirements; this configuration has no PM notifier. +unsafe fn pm_register(_nb: *mut bindings::notifier_block) -> c_int { + 0 +} + +#[cfg(not(CONFIG_PM_SLEEP))] +/// # Safety +/// +/// No requirements; this configuration has no PM notifier. +unsafe fn pm_unregister(_nb: *mut bindings::notifier_block) {} + +// SAFETY: The PM core serializes notifier operations. +unsafe impl Send for PmHook {} +// SAFETY: As above. +unsafe impl Sync for PmHook {} + +impl PmHook { + fn new(control: Arc) -> Result>> { + let hook = KBox::pin( + Self { + nb: Opaque::new(bindings::notifier_block { + notifier_call: Some(pm_event), + next: ptr::null_mut(), + priority: 0, + }), + control, + registered: Atomic::new(false), + }, + GFP_KERNEL, + )?; + // SAFETY: The notifier remains pinned in `hook`. + let ret = unsafe { pm_register(hook.nb.get()) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + hook.registered.store(true, Relaxed); + Ok(hook) + } + + fn unregister(&self) { + if self.registered.xchg(false, Relaxed) { + // SAFETY: Registered by `new()` and still pinned. + unsafe { pm_unregister(self.nb.get()) }; + } + } +} + +impl Drop for PmHook { + fn drop(&mut self) { + self.unregister(); + } +} + +struct IIOAopDevMotionDriver { + pm: Pin>, + listener: FakehidRegistration, + control: Arc, + _iio: MotionIio, +} + +kernel::of_device_table!( + OF_TABLE, + (), + [(of::DeviceId::new(c_str!("apple,aop-devmotion6")), ())] +); + +impl platform::Driver for IIOAopDevMotionDriver { + type IdInfo = (); + type Data<'bound> = IIOAopDevMotionDriver; + + const OF_ID_TABLE: Option> = Some(&OF_TABLE); + + fn probe<'bound>( + pdev: &'bound platform::Device>, + _info: Option<&'bound ()>, + ) -> impl PinInit, Error> + 'bound { + let dev = pdev.as_ref(); + // SAFETY: This binds only to children created by the AOP core. + let aop = unsafe { ::from_child(dev) }?; + // SAFETY: The AOP core attaches an `EPICService` as platform data. + let service = unsafe { (*dev.as_raw()).platform_data.cast::() }; + if service.is_null() { + return Err(ENODEV); + } + // SAFETY: The record lives as long as this child device. + let service = unsafe { *service }; + let control = Arc::new( + Control { + dev: dev.into(), + aop: aop.clone(), + service, + }, + GFP_KERNEL, + )?; + let (mut iio, state) = MotionIio::new(pdev)?; + let listener = FakehidRegistration::new(aop, service, state)?; + let pm = PmHook::new(control.clone())?; + control.set_interval(INTERVAL_US)?; + if let Err(e) = iio.register() { + let _ = control.set_interval(0); + return Err(e); + } + Ok(IIOAopDevMotionDriver { + pm, + listener, + control, + _iio: iio, + }) + } + + fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { + this.pm.unregister(); + let _ = this.control.set_interval(0); + this.listener.unregister(); + } +} + +module_platform_driver! { + type: IIOAopDevMotionDriver, + name: "iio_aop_devmotion", + description: "AOP device-motion fusion driver", + license: "Dual MIT/GPL", + alias: ["platform:iio_aop_devmotion"], +} diff --git a/drivers/iio/common/aop_sensors/aop_temp.rs b/drivers/iio/common/aop_sensors/aop_temp.rs new file mode 100644 index 0000000000000..e74ddb231ec4a --- /dev/null +++ b/drivers/iio/common/aop_sensors/aop_temp.rs @@ -0,0 +1,571 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Apple AOP temperature sensor driver +//! +//! The `als-temp` service on current laptops is a board-temperature sensor. +//! Its fake-HID report carries a signed Q16.16 Celsius value and an AOP +//! timestamp. Calibration data, when supplied by the bootloader, is sent +//! unchanged before reports are enabled. + +use core::{ + ffi::{c_int, c_void}, + marker::PhantomPinned, + ptr, +}; + +use kernel::{ + bindings, c_str, + device::{self, Core}, + module_platform_driver, new_spinlock, of, platform, + prelude::*, + soc::apple::aop::{EPICService, FakehidListener, FakehidRegistration, AOP}, + sync::{ + aref::ARef, + atomic::{Atomic, Relaxed}, + Arc, SpinLock, + }, + types::{ForeignOwnable, Opaque}, +}; + +const SUBTYPE_SET_PROPERTY: u16 = 4; +const PROP_INTERVAL: u32 = 0; +const PROP_CALIBRATION_STATE: u32 = 61; +const INTERVAL_US: u32 = 1_000_000; +const STATUS_UNSUPPORTED: u32 = 0xe000_02c7; +const REPORT_LEN: usize = 14; +const TEMP_OFFSET: usize = 2; + +const CALIBRATION: [(u32, &CStr); 4] = [ + (11, c_str!("apple,temp-offset-calibration")), + (208, c_str!("apple,absolute-temp-offset-cal")), + (208, c_str!("apple,absolute-temp-offset-fcm-cal")), + (208, c_str!("apple,absolute-temp-offset-bcm-cal")), +]; + +fn le_u32(data: &[u8], at: usize) -> Option { + Some(u32::from_le_bytes(data.get(at..at + 4)?.try_into().ok()?)) +} + +fn location0_packet(prop: &[u8]) -> Option<&[u8]> { + if prop.len() < 4 || prop[3] != 1 { + return None; + } + let mut at = 4; + for _ in 0..prop[2] { + let location = le_u32(prop, at)?; + let len = usize::try_from(le_u32(prop, at + 4)?).ok()?; + let start = at.checked_add(8)?; + let packet = prop.get(start..start.checked_add(len)?)?; + if location == 0 { + return Some(packet); + } + at = start + len; + } + None +} + +fn decode_millicelsius(report: &[u8]) -> Option { + if report.len() != REPORT_LEN { + return None; + } + let raw = le_u32(report, TEMP_OFFSET)? as i32; + Some(((i64::from(raw) * 1000) / 65_536) as i32) +} + +struct Control { + dev: ARef, + aop: Arc, + service: EPICService, + packets: KVec<(u32, KVec)>, +} + +impl Control { + fn new(dev: &device::Device, aop: Arc, service: EPICService) -> Result> { + let node = dev.fwnode().ok_or(ENODEV)?; + let mut packets = KVec::new(); + for (prop, name) in CALIBRATION { + if !node.property_present(name) { + continue; + } + let len = node.property_count_elem::(name)?; + let data = node + .property_read_array_vec::(name, len)? + .required_by(dev)?; + let Some(packet) = location0_packet(&data) else { + dev_err!(dev, "{:?} holds no calibration for location 0\n", name); + return Err(EINVAL); + }; + let mut owned = KVec::new(); + owned.extend_from_slice(packet, GFP_KERNEL)?; + packets.push((prop, owned), GFP_KERNEL)?; + } + if packets.is_empty() { + dev_dbg!( + dev, + "no temperature calibration from the bootloader; using sensor defaults\n" + ); + } + Ok(Arc::new( + Self { + dev: dev.into(), + aop, + service, + packets, + }, + GFP_KERNEL, + )?) + } + + fn write(&self, prop: u32, value: &[u8]) -> Result { + let mut msg = KVec::with_capacity(8 + value.len(), GFP_KERNEL)?; + msg.extend_from_slice(&0u32.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(&prop.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(value, GFP_KERNEL)?; + self.aop + .epic_call(&self.service, SUBTYPE_SET_PROPERTY, &msg) + } + + fn start(&self) -> Result { + for (prop, packet) in &self.packets { + let status = self.write(*prop, packet)?; + if status != 0 && status != STATUS_UNSUPPORTED { + dev_err!( + self.dev, + "calibration property {} refused: status {:#x}\n", + prop, + status + ); + return Err(EIO); + } + } + let calibration_state = if self.packets.is_empty() { 1u32 } else { 2u32 }; + let status = self.write(PROP_CALIBRATION_STATE, &calibration_state.to_le_bytes())?; + if status != 0 { + dev_err!( + self.dev, + "calibration state refused: status {:#x}\n", + status + ); + return Err(EIO); + } + let status = self.write(PROP_INTERVAL, &INTERVAL_US.to_le_bytes())?; + if status != 0 { + dev_err!(self.dev, "interval refused: status {:#x}\n", status); + return Err(EIO); + } + Ok(()) + } + + fn stop(&self) -> Result { + let status = self.write(PROP_INTERVAL, &0u32.to_le_bytes())?; + if status != 0 { + dev_err!(self.dev, "stop refused: status {:#x}\n", status); + return Err(EIO); + } + Ok(()) + } +} + +#[derive(Clone, Copy, Default)] +struct Sample { + millicelsius: i32, + valid: bool, +} + +#[repr(C, align(8))] +struct Scan { + millicelsius: i32, + pad: u32, + timestamp: i64, +} + +#[pin_data] +struct State { + iio: IioPtr, + #[pin] + sample: SpinLock, +} + +struct IioPtr(*mut bindings::iio_dev); + +// SAFETY: The IIO device may be used from any thread. +unsafe impl Send for IioPtr {} +// SAFETY: As above. +unsafe impl Sync for IioPtr {} + +impl FakehidListener for State { + fn process_fakehid_report(&self, data: &[u8]) -> Result<()> { + let millicelsius = decode_millicelsius(data).ok_or(EMSGSIZE)?; + *self.sample.lock() = Sample { + millicelsius, + valid: true, + }; + // SAFETY: The listener is removed before the IIO device is freed. + let timestamp = unsafe { bindings::iio_get_time_ns(self.iio.0) }; + let scan = Scan { + millicelsius, + pad: 0, + timestamp, + }; + // SAFETY: The scan layout matches the only available scan mask. + unsafe { bindings::iio_push_to_buffers(self.iio.0, ptr::from_ref(&scan).cast()) }; + Ok(()) + } +} + +static SCAN_MASKS: [usize; 2] = [1, 0]; + +/// # Safety +/// +/// The IIO core supplies the registered device and output pointers. +unsafe extern "C" fn read_raw( + indio_dev: *mut bindings::iio_dev, + _chan: *const bindings::iio_chan_spec, + val: *mut i32, + val2: *mut i32, + mask: isize, +) -> i32 { + // SAFETY: `priv_` is the `Arc` installed during allocation. + let state = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }; + if mask == bindings::BINDINGS_IIO_CHAN_INFO_SAMP_FREQ as isize { + // SAFETY: The pointers are the caller's result variables. + unsafe { + *val = 1; + *val2 = 0; + } + return bindings::IIO_VAL_INT as i32; + } + if mask != bindings::BINDINGS_IIO_CHAN_INFO_PROCESSED as isize { + return EINVAL.to_errno(); + } + let sample = *state.sample.lock(); + if !sample.valid { + return ENODATA.to_errno(); + } + // SAFETY: The pointers are the caller's result variables. IIO temperature + // processed values are in millidegrees Celsius. + unsafe { + *val = sample.millicelsius; + *val2 = 0; + } + bindings::IIO_VAL_INT as i32 +} + +fn temp_channel() -> bindings::iio_chan_spec { + bindings::iio_chan_spec { + type_: bindings::BINDINGS_IIO_TEMP, + scan_index: 0, + __bindgen_anon_1: bindings::iio_chan_spec__bindgen_ty_1 { + scan_type: bindings::iio_scan_type { + __bindgen_anon_1: bindings::iio_scan_type__bindgen_ty_1 { sign: b's' }, + realbits: 32, + storagebits: 32, + ..Default::default() + }, + }, + info_mask_separate: 1usize << bindings::BINDINGS_IIO_CHAN_INFO_PROCESSED, + info_mask_shared_by_type: 1usize << bindings::BINDINGS_IIO_CHAN_INFO_SAMP_FREQ, + ..Default::default() + } +} + +fn timestamp_channel() -> bindings::iio_chan_spec { + bindings::iio_chan_spec { + type_: bindings::BINDINGS_IIO_TIMESTAMP, + channel: -1, + scan_index: 1, + __bindgen_anon_1: bindings::iio_chan_spec__bindgen_ty_1 { + scan_type: bindings::iio_scan_type { + __bindgen_anon_1: bindings::iio_scan_type__bindgen_ty_1 { sign: b's' }, + realbits: 64, + storagebits: 64, + ..Default::default() + }, + }, + ..Default::default() + } +} + +struct Spec { + channels: [bindings::iio_chan_spec; 2], + info: bindings::iio_info, + _p: PhantomPinned, +} + +struct TempIio { + dev: *mut bindings::iio_dev, + _spec: Pin>, + registered: bool, +} + +impl TempIio { + fn new(pdev: &platform::Device>) -> Result<(Self, Arc)> { + let dev = pdev.as_ref(); + let spec = KBox::pin( + Spec { + channels: [temp_channel(), timestamp_channel()], + info: bindings::iio_info { + read_raw: Some(read_raw), + ..Default::default() + }, + _p: PhantomPinned, + }, + GFP_KERNEL, + )?; + // SAFETY: `dev` is valid. + let indio_dev = unsafe { bindings::iio_device_alloc(dev.as_raw(), 0) }; + if indio_dev.is_null() { + return Err(ENOMEM); + } + let state = match Arc::pin_init( + pin_init!(State { + iio: IioPtr(indio_dev), + sample <- new_spinlock!(Sample::default()), + }), + GFP_KERNEL, + ) { + Ok(state) => state, + Err(e) => { + // SAFETY: Allocated above and not registered. + unsafe { bindings::iio_device_free(indio_dev) }; + return Err(e); + } + }; + // SAFETY: The IIO device is unregistered and `spec` is pinned. + unsafe { + (*indio_dev).priv_ = state.clone().into_foreign().cast(); + (*indio_dev).name = c"aop-sensors-als-temp".as_char_ptr(); + (*indio_dev).channels = spec.channels.as_ptr(); + (*indio_dev).num_channels = spec.channels.len() as i32; + (*indio_dev).info = &spec.info; + (*indio_dev).modes = bindings::INDIO_DIRECT_MODE as i32; + (*indio_dev).available_scan_masks = SCAN_MASKS.as_ptr(); + } + // SAFETY: Both devices are valid and the buffer is device-managed. + let ret = unsafe { + bindings::devm_iio_kfifo_buffer_setup_ext( + dev.as_raw(), + indio_dev, + ptr::null(), + ptr::null_mut(), + ) + }; + if ret < 0 { + // SAFETY: The device is not registered; the private pointer is + // the foreign `Arc` installed above. + unsafe { + drop(Arc::::from_foreign((*indio_dev).priv_.cast())); + bindings::iio_device_free(indio_dev); + } + return Err(Error::from_errno(ret)); + } + Ok(( + Self { + dev: indio_dev, + _spec: spec, + registered: false, + }, + state, + )) + } + + fn register(&mut self) -> Result { + let module = kernel::module::this_module::(); + // SAFETY: The device is fully initialized and unregistered. + let ret = unsafe { bindings::__iio_device_register(self.dev, module.as_ptr()) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + self.registered = true; + Ok(()) + } +} + +impl Drop for TempIio { + fn drop(&mut self) { + // SAFETY: The device and its private `Arc` were installed by `new()`. + unsafe { + if self.registered { + bindings::iio_device_unregister(self.dev); + } + drop(Arc::::from_foreign((*self.dev).priv_.cast())); + bindings::iio_device_free(self.dev); + } + } +} + +// SAFETY: The IIO core serializes registration and removal. +unsafe impl Send for TempIio {} +// SAFETY: As above. +unsafe impl Sync for TempIio {} + +#[repr(C)] +struct PmHook { + nb: Opaque, + control: Arc, + registered: Atomic, +} + +/// # Safety +/// +/// `nb` is the first field of a registered `PmHook`. +unsafe extern "C" fn pm_event( + nb: *mut bindings::notifier_block, + action: usize, + _data: *mut c_void, +) -> c_int { + // SAFETY: `nb` is the first field of a registered, pinned `PmHook`. + let hook = unsafe { &*nb.cast::() }; + let ret = match action as u32 { + bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => hook.control.stop(), + bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => hook.control.start(), + _ => return bindings::NOTIFY_DONE as c_int, + }; + if let Err(e) = ret { + dev_warn!( + hook.control.dev, + "reports not switched for sleep: {:?}\n", + e + ); + } + bindings::NOTIFY_OK as c_int +} + +#[cfg(CONFIG_PM_SLEEP)] +/// # Safety +/// +/// `nb` remains pinned until [`pm_unregister`] is called. +unsafe fn pm_register(nb: *mut bindings::notifier_block) -> c_int { + // SAFETY: The caller keeps the block pinned through unregister. + unsafe { bindings::register_pm_notifier(nb) } +} + +#[cfg(CONFIG_PM_SLEEP)] +/// # Safety +/// +/// `nb` was registered by [`pm_register`]. +unsafe fn pm_unregister(nb: *mut bindings::notifier_block) { + // SAFETY: The block was registered by `pm_register`. + unsafe { bindings::unregister_pm_notifier(nb) }; +} + +#[cfg(not(CONFIG_PM_SLEEP))] +/// # Safety +/// +/// No requirements; this configuration has no PM notifier. +unsafe fn pm_register(_nb: *mut bindings::notifier_block) -> c_int { + 0 +} + +#[cfg(not(CONFIG_PM_SLEEP))] +/// # Safety +/// +/// No requirements; this configuration has no PM notifier. +unsafe fn pm_unregister(_nb: *mut bindings::notifier_block) {} + +// SAFETY: The PM core serializes notifier operations. +unsafe impl Send for PmHook {} +// SAFETY: As above. +unsafe impl Sync for PmHook {} + +impl PmHook { + fn new(control: Arc) -> Result>> { + let hook = KBox::pin( + Self { + nb: Opaque::new(bindings::notifier_block { + notifier_call: Some(pm_event), + next: ptr::null_mut(), + priority: 0, + }), + control, + registered: Atomic::new(false), + }, + GFP_KERNEL, + )?; + // SAFETY: The notifier remains pinned in `hook`. + let ret = unsafe { pm_register(hook.nb.get()) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + hook.registered.store(true, Relaxed); + Ok(hook) + } + + fn unregister(&self) { + if self.registered.xchg(false, Relaxed) { + // SAFETY: Registered by `new()` and still pinned. + unsafe { pm_unregister(self.nb.get()) }; + } + } +} + +impl Drop for PmHook { + fn drop(&mut self) { + self.unregister(); + } +} + +struct IIOAopTempDriver { + pm: Pin>, + listener: FakehidRegistration, + control: Arc, + _iio: TempIio, +} + +kernel::of_device_table!( + OF_TABLE, + (), + [(of::DeviceId::new(c_str!("apple,aop-als-temp")), ())] +); + +impl platform::Driver for IIOAopTempDriver { + type IdInfo = (); + type Data<'bound> = IIOAopTempDriver; + + const OF_ID_TABLE: Option> = Some(&OF_TABLE); + + fn probe<'bound>( + pdev: &'bound platform::Device>, + _info: Option<&'bound ()>, + ) -> impl PinInit, Error> + 'bound { + let dev = pdev.as_ref(); + // SAFETY: This binds only to children created by the AOP core. + let aop = unsafe { ::from_child(dev) }?; + // SAFETY: The AOP core attaches an `EPICService` as platform data. + let service = unsafe { (*dev.as_raw()).platform_data.cast::() }; + if service.is_null() { + return Err(ENODEV); + } + // SAFETY: The record lives as long as this child device. + let service = unsafe { *service }; + let control = Control::new(dev, aop.clone(), service)?; + let (mut iio, state) = TempIio::new(pdev)?; + let listener = FakehidRegistration::new(aop, service, state)?; + let pm = PmHook::new(control.clone())?; + control.start()?; + if let Err(e) = iio.register() { + let _ = control.stop(); + return Err(e); + } + Ok(IIOAopTempDriver { + pm, + listener, + control, + _iio: iio, + }) + } + + fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { + this.pm.unregister(); + let _ = this.control.stop(); + this.listener.unregister(); + } +} + +module_platform_driver! { + type: IIOAopTempDriver, + name: "iio_aop_temp", + description: "AOP temperature sensor driver", + license: "Dual MIT/GPL", + alias: ["platform:iio_aop_temp"], +} diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 20e78e2b542cb..089a2334d52ee 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -1480,6 +1480,8 @@ impl AopData { b"als" => c_str!("als"), b"accel" => c_str!("accel"), b"gyro" => c_str!("gyro"), + b"devmotion6" => c_str!("devmotion6"), + b"als-temp" => c_str!("als-temp"), _ => { return Ok(()); } diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 56f9f84689804..da14d221008de 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -173,10 +173,13 @@ const u32 BINDINGS_IIO_LIGHT = IIO_LIGHT; const u32 BINDINGS_IIO_COLORTEMP = IIO_COLORTEMP; const u32 BINDINGS_IIO_ACCEL = IIO_ACCEL; const u32 BINDINGS_IIO_ANGL_VEL = IIO_ANGL_VEL; +const u32 BINDINGS_IIO_ROT = IIO_ROT; +const u32 BINDINGS_IIO_TEMP = IIO_TEMP; const u32 BINDINGS_IIO_TIMESTAMP = IIO_TIMESTAMP; const u32 BINDINGS_IIO_MOD_X = IIO_MOD_X; const u32 BINDINGS_IIO_MOD_Y = IIO_MOD_Y; const u32 BINDINGS_IIO_MOD_Z = IIO_MOD_Z; +const u32 BINDINGS_IIO_MOD_QUATERNION = IIO_MOD_QUATERNION; const u32 BINDINGS_IIO_CHAN_INFO_SAMP_FREQ = IIO_CHAN_INFO_SAMP_FREQ; const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT; From 1285463a8eb56174fe9a692a9e9f03d6ab94fdb3 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 07:13:30 +1100 Subject: [PATCH 008/342] iio: apple: initialize devmotion calibration state Select the AOP firmware's built-in calibration state before enabling the devmotion6 interval. AppleSPUHIDDriver performs this generic state write even though the fused service has no calibration blob; an interval alone is accepted but leaves the service silent. Keep the state across sleep and restore only the interval on resume, matching the macOS power path. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/iio/aop-sensors.rst | 10 +++-- .../iio/common/aop_sensors/aop_devmotion.rs | 41 +++++++++++++++---- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 3f47ba72778b5..1adcc90b9ce8a 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -76,9 +76,13 @@ The service's current report has a type byte followed by a versioned fixed layout. Type 2 is 108 bytes and carries little-endian IEEE-754 X, Y, Z and W at offset 28. Types 3 and 4 are 60 bytes and carry the same fields at offset 12. Type 1 is a five-byte state report and does not update the IIO sample. -Reports begin after property 0 is set to a non-zero interval in microseconds; -the driver requests 50 Hz, writes zero around system sleep, and restores the -interval after resume. This fused stream needs no separate calibration blob. +The driver first selects the firmware's built-in calibration by writing value +1 to property 61, then writes a non-zero interval in microseconds to property +0. The order matters: setting the interval alone is accepted but does not +start the fusion stream. The driver requests 50 Hz, writes a zero interval +around system sleep, and restores that interval after resume; the calibration +state persists across this power transition. This fused stream needs no +separate calibration blob. Board temperature ================= diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index cc14b1bb58b20..dd7c6459c8eee 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -29,6 +29,10 @@ use kernel::{ const SUBTYPE_SET_PROPERTY: u16 = 4; const PROP_INTERVAL: u32 = 0; +/// Selects the firmware's built-in calibration. AppleSPUHIDDriver writes this +/// even though devmotion6 has no service-specific calibration packets. +const PROP_CALIBRATION_STATE: u32 = 61; +const CALIBRATION_DEFAULT: u32 = 1; const INTERVAL_US: u32 = 20_000; const Q_FRAC_BITS: i32 = 30; @@ -101,20 +105,39 @@ struct Control { } impl Control { - fn set_interval(&self, interval: u32) -> Result { + fn set(&self, prop: u32, value: u32) -> Result { let mut msg = KVec::with_capacity(12, GFP_KERNEL)?; msg.extend_from_slice(&0u32.to_le_bytes(), GFP_KERNEL)?; - msg.extend_from_slice(&PROP_INTERVAL.to_le_bytes(), GFP_KERNEL)?; - msg.extend_from_slice(&interval.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(&prop.to_le_bytes(), GFP_KERNEL)?; + msg.extend_from_slice(&value.to_le_bytes(), GFP_KERNEL)?; let status = self .aop .epic_call(&self.service, SUBTYPE_SET_PROPERTY, &msg)?; if status != 0 { - dev_err!(self.dev, "interval refused: status {:#x}\n", status); + dev_err!( + self.dev, + "property {} refused: status {:#x}\n", + prop, + status + ); return Err(EIO); } Ok(()) } + + /// Selects the default calibration before the first enable after probe. + fn initialize(&self) -> Result { + self.set(PROP_CALIBRATION_STATE, CALIBRATION_DEFAULT)?; + self.enable() + } + + fn enable(&self) -> Result { + self.set(PROP_INTERVAL, INTERVAL_US) + } + + fn disable(&self) -> Result { + self.set(PROP_INTERVAL, 0) + } } #[pin_data] @@ -362,10 +385,10 @@ unsafe extern "C" fn pm_event( let hook = unsafe { &*nb.cast::() }; let ret = match action as u32 { bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => { - hook.control.set_interval(0) + hook.control.disable() } bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => { - hook.control.set_interval(INTERVAL_US) + hook.control.enable() } _ => return bindings::NOTIFY_DONE as c_int, }; @@ -497,9 +520,9 @@ impl platform::Driver for IIOAopDevMotionDriver { let (mut iio, state) = MotionIio::new(pdev)?; let listener = FakehidRegistration::new(aop, service, state)?; let pm = PmHook::new(control.clone())?; - control.set_interval(INTERVAL_US)?; + control.initialize()?; if let Err(e) = iio.register() { - let _ = control.set_interval(0); + let _ = control.disable(); return Err(e); } Ok(IIOAopDevMotionDriver { @@ -512,7 +535,7 @@ impl platform::Driver for IIOAopDevMotionDriver { fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { this.pm.unregister(); - let _ = this.control.set_interval(0); + let _ = this.control.disable(); this.listener.unregister(); } } From a623d56c6e4f09220b2025929025d32b26a6b7cd Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 07:33:00 +1100 Subject: [PATCH 009/342] iio: apple: devmotion: accept a calibration state already held On the J616s the devmotion6 service answers the calibration-state write with the 'unsupported' status the other AOP sensor services use when they already hold their calibration from an earlier start in the same AOP session. Treat it the same way instead of failing the probe. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/iio/common/aop_sensors/aop_devmotion.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index dd7c6459c8eee..93f62e3c63c8e 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -33,6 +33,10 @@ const PROP_INTERVAL: u32 = 0; /// even though devmotion6 has no service-specific calibration packets. const PROP_CALIBRATION_STATE: u32 = 61; const CALIBRATION_DEFAULT: u32 = 1; +/// The status a calibration-state write is answered with when the service +/// already holds a state from an earlier start in the same AOP session (a +/// rebind, a resume, or a warm reboot); the stream can be started as is. +const STATUS_UNSUPPORTED: u32 = 0xe000_02c7; const INTERVAL_US: u32 = 20_000; const Q_FRAC_BITS: i32 = 30; @@ -106,6 +110,10 @@ struct Control { impl Control { fn set(&self, prop: u32, value: u32) -> Result { + self.set_allowing(prop, value, 0) + } + + fn set_allowing(&self, prop: u32, value: u32, also_ok: u32) -> Result { let mut msg = KVec::with_capacity(12, GFP_KERNEL)?; msg.extend_from_slice(&0u32.to_le_bytes(), GFP_KERNEL)?; msg.extend_from_slice(&prop.to_le_bytes(), GFP_KERNEL)?; @@ -113,7 +121,7 @@ impl Control { let status = self .aop .epic_call(&self.service, SUBTYPE_SET_PROPERTY, &msg)?; - if status != 0 { + if status != 0 && (also_ok == 0 || status != also_ok) { dev_err!( self.dev, "property {} refused: status {:#x}\n", @@ -127,7 +135,7 @@ impl Control { /// Selects the default calibration before the first enable after probe. fn initialize(&self) -> Result { - self.set(PROP_CALIBRATION_STATE, CALIBRATION_DEFAULT)?; + self.set_allowing(PROP_CALIBRATION_STATE, CALIBRATION_DEFAULT, STATUS_UNSUPPORTED)?; self.enable() } From d14a657b07f205b8e3b1ccb886f1f8c844de4e85 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 08:29:50 +1100 Subject: [PATCH 010/342] iio: apple: open devmotion fast path devmotion6 does not stream over fake-HID reports. Its reports arrive in a per-service shared-memory fast path that the AP must open before the report interval does anything. Read the payload size from property 81, allocate a coherent two-slot ping-pong buffer, open the client with EPIC command 25, then set the interval. Poll the published slot for new reports. On sleep and unbind, clear the interval and close the client with command 26; on resume, open a new client before restoring the interval. If an open or close outcome is unknown, keep the DMA mapping, since the firmware may still hold it. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/iio/aop-sensors.rst | 29 +- .../iio/common/aop_sensors/aop_devmotion.rs | 349 +++++++++++++++--- 2 files changed, 320 insertions(+), 58 deletions(-) diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 1adcc90b9ce8a..409cb28507378 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -5,11 +5,10 @@ Apple AOP sensors ================= The AOP firmware announces sensor services over EPIC. The AOP core matches -each service to a child node in the device tree and forwards its fake-HID -reports to the corresponding IIO driver. Ambient light (``als``), lid -angle (``las``), acceleration (``accel``), angular rate (``gyro``), fused -device motion (``devmotion6``) and board temperature (``als-temp``) use this -same transport; no HID bus device is created. +each service to a child node in the device tree. Most sensors send fake-HID +reports over EPIC; fused device motion (``devmotion6``) instead writes a +shared fast-path buffer opened by its IIO driver. No HID bus device is +created. Lid angle ========= @@ -76,13 +75,19 @@ The service's current report has a type byte followed by a versioned fixed layout. Type 2 is 108 bytes and carries little-endian IEEE-754 X, Y, Z and W at offset 28. Types 3 and 4 are 60 bytes and carry the same fields at offset 12. Type 1 is a five-byte state report and does not update the IIO sample. -The driver first selects the firmware's built-in calibration by writing value -1 to property 61, then writes a non-zero interval in microseconds to property -0. The order matters: setting the interval alone is accepted but does not -start the fusion stream. The driver requests 50 Hz, writes a zero interval -around system sleep, and restores that interval after resume; the calibration -state persists across this power transition. This fused stream needs no -separate calibration blob. +The driver writes value 1 to property 61 first. Some firmware answers status +0xe00002c7 (unsupported) for this service, which is harmless. The stream is +armed by the consumer registration: the driver reads property 81 for the +report size, allocates a coherent two-slot ping-pong buffer, and opens it +with EPIC command 25. Only then does the driver write the non-zero interval in microseconds to +property 0. Reports are polled from the published shared-memory slot rather +than received as fake-HID subtype 0xc4 messages. + +The driver requests 50 Hz. Around system sleep it writes a zero interval and +closes the fast path with command 26; after resume it opens the fast path +before restoring the interval. A failed or timed-out close retains the DMA +mapping because the firmware may still hold its address. This fused stream +needs no separate calibration blob. Board temperature ================= diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index 93f62e3c63c8e..26d7363e1a127 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -8,36 +8,49 @@ //! IIO exposes them in its standard W, X, Y, Z order as signed Q30 values. use core::{ + arch::asm, ffi::{c_int, c_void}, marker::PhantomPinned, - ptr, + mem, ptr, }; use kernel::{ bindings, c_str, device::{self, Core}, - module_platform_driver, new_spinlock, of, platform, + dma::Coherent, + module_platform_driver, new_delayed_work, new_mutex, new_spinlock, of, platform, prelude::*, - soc::apple::aop::{EPICService, FakehidListener, FakehidRegistration, AOP}, + soc::apple::aop::{EPICService, AOP}, sync::{ aref::ARef, - atomic::{Atomic, Relaxed}, - Arc, SpinLock, + atomic::{Acquire, Atomic, Relaxed, Release}, + Arc, Mutex, SpinLock, }, + time, types::{ForeignOwnable, Opaque}, + workqueue::{self, impl_has_delayed_work, DelayedWork, Work, WorkItem}, }; +const SUBTYPE_GET_PROPERTY: u16 = 10; const SUBTYPE_SET_PROPERTY: u16 = 4; +const SUBTYPE_CLIENT_OPEN: u16 = 25; +const SUBTYPE_CLIENT_CLOSE: u16 = 26; const PROP_INTERVAL: u32 = 0; -/// Selects the firmware's built-in calibration. AppleSPUHIDDriver writes this -/// even though devmotion6 has no service-specific calibration packets. +/// Selects the firmware's built-in calibration. devmotion6 has no +/// service-specific calibration packets; this generic write is harmless. const PROP_CALIBRATION_STATE: u32 = 61; const CALIBRATION_DEFAULT: u32 = 1; -/// The status a calibration-state write is answered with when the service -/// already holds a state from an earlier start in the same AOP session (a -/// rebind, a resume, or a warm reboot); the stream can be started as is. +/// The "unsupported" status some firmware returns for the calibration-state +/// write on this service. The stream does not depend on that property: +/// opening the report client is the operation that arms it. const STATUS_UNSUPPORTED: u32 = 0xe000_02c7; +const PROP_FASTPATH_PAYLOAD_SIZE: u32 = 81; const INTERVAL_US: u32 = 20_000; +const FASTPATH_COMMAND_LEN: usize = 84; +const FASTPATH_HEADER_LEN: usize = 64; +const FASTPATH_PAGE_SIZE: usize = 4096; +const MAX_REPORT_LEN: usize = 108; +const POLL_MS: u32 = 5; const Q_FRAC_BITS: i32 = 30; /// The latest quaternion, in the IIO-defined W, X, Y, Z order. @@ -58,6 +71,10 @@ fn le_u32(data: &[u8], at: usize) -> Option { Some(u32::from_le_bytes(data.get(at..at + 4)?.try_into().ok()?)) } +fn le_u64(data: &[u8], at: usize) -> Option { + Some(u64::from_le_bytes(data.get(at..at + 8)?.try_into().ok()?)) +} + /// Converts a finite IEEE-754 single to signed Q30 without using FP in the /// kernel. Values outside the representation saturate. fn f32_to_q30(bits: u32) -> Option { @@ -133,10 +150,33 @@ impl Control { Ok(()) } - /// Selects the default calibration before the first enable after probe. - fn initialize(&self) -> Result { - self.set_allowing(PROP_CALIBRATION_STATE, CALIBRATION_DEFAULT, STATUS_UNSUPPORTED)?; - self.enable() + fn get(&self, prop: u32, len: usize) -> Result> { + let mut msg = KVec::new(); + msg.resize(8, 0, GFP_KERNEL)?; + msg[4..8].copy_from_slice(&prop.to_le_bytes()); + let (status, value) = + self.aop + .epic_call_ret(&self.service, SUBTYPE_GET_PROPERTY, &msg, len)?; + if status != 0 { + dev_err!( + self.dev, + "property {} read refused: status {:#x}\n", + prop, + status + ); + return Err(EIO); + } + Ok(value) + } + + /// Writes the generic calibration state. Unsupported is normal for a + /// service whose actual enable operation is ClientOpen. + fn calibrate(&self) -> Result { + self.set_allowing( + PROP_CALIBRATION_STATE, + CALIBRATION_DEFAULT, + STATUS_UNSUPPORTED, + ) } fn enable(&self) -> Result { @@ -148,36 +188,241 @@ impl Control { } } -#[pin_data] +#[pin_data(PinnedDrop)] struct State { iio: IioPtr, + control: Arc, + payload_len: usize, + stride: usize, + #[pin] + ring: Mutex>>, #[pin] sample: SpinLock, + active: Atomic, + opened: Atomic, + retain_ring: Atomic, + client_id: Atomic, + next_client_id: Atomic, + last_aop_timestamp: Atomic, + #[pin] + poll_work: DelayedWork, } struct IioPtr(*mut bindings::iio_dev); -// SAFETY: The IIO device may be used from any thread. The listener only calls -// IIO helpers that are valid from the AOP receive worker. +// SAFETY: The IIO device may be used from any thread. The polling worker only +// calls IIO helpers that are valid from process context. unsafe impl Send for IioPtr {} // SAFETY: As above. unsafe impl Sync for IioPtr {} -impl FakehidListener for State { - fn process_fakehid_report(&self, data: &[u8]) -> Result<()> { +impl_has_delayed_work! { + impl HasDelayedWork for State { self.poll_work } +} + +impl State { + fn publish(&self, data: &[u8]) { let Some(quat) = decode(data) else { // State-only reports are expected and leave the sample unchanged. - return Ok(()); + return; }; *self.sample.lock() = Sample { quat, valid: true }; - // SAFETY: The listener is removed before the IIO device is freed. + // SAFETY: The polling work is disabled before the IIO device is freed. let timestamp = unsafe { bindings::iio_get_time_ns(self.iio.0) }; let scan = Scan { quat, timestamp }; // SAFETY: `scan` contains the complete only data channel followed by // the timestamp, and the IIO core copies it synchronously. unsafe { bindings::iio_push_to_buffers(self.iio.0, ptr::from_ref(&scan).cast()) }; + } + + fn open_fastpath(&self) -> Result { + if self.opened.load(Acquire) { + return Ok(()); + } + let id = self.next_client_id.fetch_add(1, Relaxed); + let ring = self.ring.lock(); + let ring = ring.as_ref().ok_or(ENODEV)?; + let mut msg = KVec::new(); + // EPIC reserves the first word. The 84-byte ClientOpen body is: + // client id, flags, IOVA, allocation size, payload size, then zeroes. + msg.resize(4 + FASTPATH_COMMAND_LEN, 0, GFP_KERNEL)?; + msg[4..12].copy_from_slice(&id.to_le_bytes()); + msg[16..24].copy_from_slice(&ring.dma_address().to_le_bytes()); + msg[24..28].copy_from_slice(&(ring.size() as u32).to_le_bytes()); + msg[28..32].copy_from_slice(&(self.payload_len as u32).to_le_bytes()); + let status = + match self + .control + .aop + .epic_call(&self.control.service, SUBTYPE_CLIENT_OPEN, &msg) + { + Ok(status) => status, + Err(e) => { + // A timed-out open may already have handed the IOVA to the + // firmware. Keep the mapping for the rest of the boot. + self.retain_ring.store(true, Release); + return Err(e); + } + }; + if status != 0 { + dev_err!( + self.control.dev, + "fast-path open refused: status {:#x}\n", + status + ); + return Err(EIO); + } + self.client_id.store(id, Relaxed); + self.opened.store(true, Release); + Ok(()) + } + + fn close_fastpath(&self) -> Result { + if !self.opened.load(Acquire) { + return Ok(()); + } + let mut msg = KVec::new(); + msg.resize(12, 0, GFP_KERNEL)?; + msg[4..12].copy_from_slice(&self.client_id.load(Relaxed).to_le_bytes()); + let status = + match self + .control + .aop + .epic_call(&self.control.service, SUBTYPE_CLIENT_CLOSE, &msg) + { + Ok(status) => status, + Err(e) => { + self.retain_ring.store(true, Release); + return Err(e); + } + }; + if status != 0 { + self.retain_ring.store(true, Release); + dev_err!( + self.control.dev, + "fast-path close refused: status {:#x}\n", + status + ); + return Err(EIO); + } + self.opened.store(false, Release); Ok(()) } + + fn start(self: &Arc) -> Result { + self.open_fastpath()?; + if let Err(e) = self.control.enable() { + if self.close_fastpath().is_err() { + self.retain_ring.store(true, Release); + } + return Err(e); + } + self.active.store(true, Release); + self.queue_poll(); + Ok(()) + } + + fn stop(&self) -> Result { + self.active.store(false, Release); + let interval = self.control.disable(); + let close = self.close_fastpath(); + interval.and(close) + } + + fn queue_poll(self: &Arc) { + let _ = + workqueue::system_dfl().enqueue_delayed(self.clone(), time::msecs_to_jiffies(POLL_MS)); + } + + fn poll(&self) { + let guard = self.ring.lock(); + let Some(ring) = guard.as_ref() else { + return; + }; + let base = ring.as_ptr().cast::(); + // SAFETY: the allocation is at least one page. The firmware publishes + // one of the two aligned slot offsets in the first word. + let slot = unsafe { u32::from_le(ptr::read_volatile(base.cast::())) as usize }; + if slot != FASTPATH_HEADER_LEN && slot != FASTPATH_HEADER_LEN + self.stride { + return; + } + // SAFETY: the barrier touches no memory and orders the slot body after + // the firmware's selector publication. + unsafe { asm!("dmb oshld", options(nostack, preserves_flags)) }; + // SAFETY: both allowed slots are aligned and fit in the allocation. + let (aop_timestamp, len) = unsafe { + ( + u64::from_le(ptr::read_volatile(base.add(slot).cast::())), + u32::from_le(ptr::read_volatile(base.add(slot + 8).cast::())) as usize, + ) + }; + if aop_timestamp == 0 + || aop_timestamp == self.last_aop_timestamp.load(Relaxed) + || len > self.payload_len + || len > MAX_REPORT_LEN + || slot + 12 + len > ring.size() + { + return; + } + let mut report = [0u8; MAX_REPORT_LEN]; + // SAFETY: the bounds above keep the source inside the coherent ring; + // the published slot is not reused until the other slot is published. + unsafe { + ptr::copy_nonoverlapping(base.add(slot + 12), report.as_mut_ptr(), len); + asm!("dmb oshld", options(nostack, preserves_flags)); + } + // If publication changed while copying, consume the newer slot on the + // next tick rather than risk a slot that has already been recycled. + // SAFETY: as for the first selector read. + if unsafe { u32::from_le(ptr::read_volatile(base.cast::())) as usize } != slot { + return; + } + self.last_aop_timestamp.store(aop_timestamp, Relaxed); + self.publish(&report[..len]); + } + + fn disable_poll(self: &Arc) { + self.active.store(false, Release); + // SAFETY: `poll_work` is initialized and pinned in this `Arc`. The + // call prevents requeue, cancels pending work and joins a callback. + let cancelled = unsafe { + let work = Work::raw_get(DelayedWork::raw_as_work(ptr::addr_of!(self.poll_work))); + let delayed = kernel::container_of!(work, bindings::delayed_work, work); + bindings::disable_delayed_work_sync(delayed) + }; + if cancelled { + // SAFETY: a cancelled pending callback owned exactly one Arc + // transferred by `enqueue_delayed`. + drop(unsafe { Arc::from_raw(Arc::as_ptr(self)) }); + } + } +} + +impl WorkItem for State { + type Pointer = Arc; + + fn run(this: Arc) { + if !this.active.load(Acquire) { + return; + } + this.poll(); + if this.active.load(Acquire) { + this.queue_poll(); + } + } +} + +#[pinned_drop] +impl PinnedDrop for State { + fn drop(self: Pin<&mut Self>) { + if self.retain_ring.load(Acquire) { + if let Some(ring) = self.ring.lock().take() { + // The outcome of ClientOpen/ClientClose is unknown, so the + // firmware may retain this IOVA until the AOP reboots. + mem::forget(ring); + } + } + } } static SCAN_MASKS: [usize; 2] = [1, 0]; @@ -274,8 +519,18 @@ struct MotionIio { } impl MotionIio { - fn new(pdev: &platform::Device>) -> Result<(Self, Arc)> { + fn new(pdev: &platform::Device>, control: Arc) -> Result<(Self, Arc)> { let dev = pdev.as_ref(); + let payload = control.get(PROP_FASTPATH_PAYLOAD_SIZE, 8)?; + let payload_len = usize::try_from(le_u64(&payload, 0).ok_or(EIO)?).map_err(|_| EINVAL)?; + if !(5..=MAX_REPORT_LEN).contains(&payload_len) { + dev_err!(dev, "invalid fast-path payload size {}\n", payload_len); + return Err(EINVAL); + } + let stride = (payload_len + 75) & !63; + let required = FASTPATH_HEADER_LEN + 2 * stride; + let ring_size = (required + FASTPATH_PAGE_SIZE - 1) & !(FASTPATH_PAGE_SIZE - 1); + let ring = Coherent::::zeroed_slice(dev, ring_size, GFP_KERNEL)?; let spec = KBox::pin( Spec { channels: [quaternion_channel(), timestamp_channel()], @@ -295,7 +550,18 @@ impl MotionIio { let state = match Arc::pin_init( pin_init!(State { iio: IioPtr(indio_dev), + control, + payload_len, + stride, + ring <- new_mutex!(Some(ring)), sample <- new_spinlock!(Sample::default()), + active: Atomic::new(false), + opened: Atomic::new(false), + retain_ring: Atomic::new(false), + client_id: Atomic::new(0), + next_client_id: Atomic::new(1), + last_aop_timestamp: Atomic::new(0), + poll_work <- new_delayed_work!("State::poll_work"), }), GFP_KERNEL, ) { @@ -377,7 +643,7 @@ unsafe impl Sync for MotionIio {} #[repr(C)] struct PmHook { nb: Opaque, - control: Arc, + state: Arc, registered: Atomic, } @@ -392,17 +658,13 @@ unsafe extern "C" fn pm_event( // SAFETY: By the callback contract above. let hook = unsafe { &*nb.cast::() }; let ret = match action as u32 { - bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => { - hook.control.disable() - } - bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => { - hook.control.enable() - } + bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => hook.state.stop(), + bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => hook.state.start(), _ => return bindings::NOTIFY_DONE as c_int, }; if let Err(e) = ret { dev_warn!( - hook.control.dev, + hook.state.control.dev, "reports not switched for sleep: {:?}\n", e ); @@ -448,7 +710,7 @@ unsafe impl Send for PmHook {} unsafe impl Sync for PmHook {} impl PmHook { - fn new(control: Arc) -> Result>> { + fn new(state: Arc) -> Result>> { let hook = KBox::pin( Self { nb: Opaque::new(bindings::notifier_block { @@ -456,7 +718,7 @@ impl PmHook { next: ptr::null_mut(), priority: 0, }), - control, + state, registered: Atomic::new(false), }, GFP_KERNEL, @@ -486,8 +748,7 @@ impl Drop for PmHook { struct IIOAopDevMotionDriver { pm: Pin>, - listener: FakehidRegistration, - control: Arc, + state: Arc, _iio: MotionIio, } @@ -525,26 +786,22 @@ impl platform::Driver for IIOAopDevMotionDriver { }, GFP_KERNEL, )?; - let (mut iio, state) = MotionIio::new(pdev)?; - let listener = FakehidRegistration::new(aop, service, state)?; - let pm = PmHook::new(control.clone())?; - control.initialize()?; - if let Err(e) = iio.register() { - let _ = control.disable(); - return Err(e); - } + control.calibrate()?; + let (mut iio, state) = MotionIio::new(pdev, control)?; + iio.register()?; + let pm = PmHook::new(state.clone())?; + state.start()?; Ok(IIOAopDevMotionDriver { pm, - listener, - control, + state, _iio: iio, }) } fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { this.pm.unregister(); - let _ = this.control.disable(); - this.listener.unregister(); + let _ = this.state.stop(); + this.state.disable_poll(); } } From a8be37d13bddd51b009f8d6e69556f5d8af5ff34 Mon Sep 17 00:00:00 2001 From: "Michal S." Date: Fri, 6 Nov 2026 22:11:34 +0000 Subject: [PATCH 011/342] wifi: brcmfmac: select CCMP explicitly for firmware offload On BCM4388, an SAE join that requests CCMP can return a driver-generated association RSNE selecting GCMP-256 instead. wpa_supplicant rejects that cipher because it is outside the profile's allowed set and disconnects locally with PAIRWISE_CIPHER_NOT_VALID. The CCMP arm sets the generic AES_ENABLED flag but leaves the wsec_info algorithm selection and mask at zero. The firmware ABI leaves algorithms outside the mask unchanged, so this does not select CCMP over GCMP-256. Select AES-CCM explicitly and mask AES-GCM256, mirroring the existing GCMP-256 arm. The existing GCMP feature guard keeps this command away from firmware that does not advertise it. Add host controls that execute the production cipher-selection and XTLV encoding functions and observe the firmware command bytes. Check the CCMP mask, existing GCMP and legacy paths, and setup failures. The original code fails the CCMP payload assertion. Hardware verification of the fix is pending. Fixes: 999b7240c323 ("[brcmfmac] Support GCMP cipher suite, used by WPA3.") Assisted-by: LLM Signed-off-by: Michal S. --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 3 + tools/asahi/brcmf-cipher-tests.py | 342 ++++++++++++++++++ tools/asahi/run-host-tests.py | 2 + 3 files changed, 347 insertions(+) create mode 100755 tools/asahi/brcmf-cipher-tests.py diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 078a689320ef2..1cbdc1cdd18ba 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -2001,6 +2001,9 @@ brcmf_set_wsec_mode(struct net_device *ndev, break; case WLAN_CIPHER_SUITE_CCMP: pval = AES_ENABLED; + /* SAE offload builds its own RSNE; select CCMP explicitly. */ + algos = KEY_ALGO_MASK(CRYPTO_ALGO_AES_CCM); + mask = algos | KEY_ALGO_MASK(CRYPTO_ALGO_AES_GCM256); break; case WLAN_CIPHER_SUITE_AES_CMAC: pval = AES_ENABLED; diff --git a/tools/asahi/brcmf-cipher-tests.py b/tools/asahi/brcmf-cipher-tests.py new file mode 100755 index 0000000000000..0ac22f07b3547 --- /dev/null +++ b/tools/asahi/brcmf-cipher-tests.py @@ -0,0 +1,342 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Observe brcmfmac's cipher-selection commands at the firmware boundary.""" + +import argparse +import importlib.util +import json +import re +import subprocess +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DRIVER = Path("drivers/net/wireless/broadcom/brcm80211/brcmfmac") +spec = importlib.util.spec_from_file_location( + "association_controls", ROOT / "tools/asahi/brcmf-assoc-tests.py" +) +association = importlib.util.module_from_spec(spec) +spec.loader.exec_module(association) + +PREFIX = r""" + +#include +#include +#include +#include +#include +#include +#include +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef int32_t s32; +#define BIT(n) (1U << (n)) +#define GFP_KERNEL 0 +#define brcmf_dbg(...) ((void)0) +#define brcmf_err(...) ((void)0) +#define bphy_err(...) ((void)0) +#define WARN(test, ...) assert(!(test)) +#define WARN_ON(test) assert(!(test)) +#define WLAN_CIPHER_SUITE_WEP40 0x000fac01 +#define WLAN_CIPHER_SUITE_TKIP 0x000fac02 +#define WLAN_CIPHER_SUITE_CCMP 0x000fac04 +#define WLAN_CIPHER_SUITE_WEP104 0x000fac05 +#define WLAN_CIPHER_SUITE_AES_CMAC 0x000fac06 +#define WLAN_CIPHER_SUITE_GCMP_256 0x000fac09 +#define BRCMF_FEAT_GCMP 1 +struct brcmf_pub { + bool gcmp; +}; +struct brcmf_if { + struct brcmf_pub *drvr; +}; +struct brcmf_cfg80211_security { + u32 cipher_pairwise, cipher_group; +}; +struct brcmf_cfg80211_profile { + struct brcmf_cfg80211_security sec; +}; +struct net_device { + struct brcmf_if *ifp; + struct brcmf_cfg80211_profile profile; +}; +struct cfg80211_connect_params { + struct { + unsigned int n_ciphers_pairwise; + u32 ciphers_pairwise[1]; + u32 cipher_group; + } crypto; + const u8 *ie; + unsigned int ie_len; + bool privacy; +}; +static unsigned int wsec_calls, algorithm_calls, allocations; +static u32 observed_wsec, observed_algos, observed_mask, firmware_algos; +static int wsec_error, algorithm_error; +static bool allocation_error; +static void *netdev_priv(struct net_device *ndev) +{ + return ndev->ifp; +} +static struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *ndev) +{ + return &ndev->profile; +} +static bool brcmf_feat_is_enabled(struct brcmf_if *ifp, int feature) +{ + assert(feature == BRCMF_FEAT_GCMP); + return ifp->drvr->gcmp; +} +static bool brcmf_find_wpsie(const u8 *ie, unsigned int len) +{ + assert(!ie && !len); + return false; +} +static void *kzalloc(size_t size, int flags) +{ + assert(flags == GFP_KERNEL); + if (allocation_error) + return NULL; + void *data = calloc(1, size); + assert(data); + allocations++; + return data; +} +static void kfree(void *data) +{ + assert(allocations); + allocations--; + free(data); +} +static u32 read_le32(const u8 *data) +{ + return (u32)data[0] | (u32)data[1] << 8 | (u32)data[2] << 16 | + (u32)data[3] << 24; +} +static void put_unaligned_le16(u16 value, u8 *data) +{ + data[0] = value; + data[1] = value >> 8; +} +static int brcmf_fil_bsscfg_int_set(struct brcmf_if *ifp, const char *name, + u32 value) +{ + (void)ifp; + assert(!strcmp(name, "wsec")); + assert(!wsec_calls && !algorithm_calls); + wsec_calls++; + observed_wsec = value; + return wsec_error; +} +static int brcmf_fil_bsscfg_data_set(struct brcmf_if *ifp, const char *name, + const void *data, u32 len) +{ + const u8 *bytes = data; + (void)ifp; + assert(!strcmp(name, "wsec_info")); + assert(wsec_calls == 1 && !algorithm_calls); + /* Version 1, one BSS_ALGOS (0x106) TLV with two little-endian u32s. */ + assert(len == 16); + assert(bytes[0] == 1 && !bytes[1] && !bytes[2] && bytes[3] == 1); + assert(bytes[4] == 6 && bytes[5] == 1 && bytes[6] == 8 && !bytes[7]); + observed_algos = read_le32(bytes + 8); + observed_mask = read_le32(bytes + 12); + algorithm_calls++; + if (algorithm_error) + return algorithm_error; + /* Firmware ABI: algorithms outside the mask remain unchanged. */ + firmware_algos = (firmware_algos & ~observed_mask) | + (observed_algos & observed_mask); + return 0; +} +""" + +CONTROLS = r""" + +static struct brcmf_pub pub; +static struct brcmf_if ifp = { &pub }; +static struct net_device ndev = { .ifp = &ifp }; +static struct cfg80211_connect_params params; + +static void reset(bool gcmp, u32 pairwise, u32 group) +{ + assert(!allocations); + pub.gcmp = gcmp; + memset(¶ms, 0, sizeof(params)); + params.crypto.n_ciphers_pairwise = 1; + params.crypto.ciphers_pairwise[0] = pairwise; + params.crypto.cipher_group = group; + params.privacy = true; + memset(&ndev.profile, 0, sizeof(ndev.profile)); + observed_wsec = observed_algos = observed_mask = 0; + wsec_calls = algorithm_calls = 0; + wsec_error = algorithm_error = 0; + allocation_error = false; + /* GCMP-256 starts enabled; bit 31 represents an unrelated algorithm. */ + firmware_algos = 0x80010000U; +} + +int main(void) +{ + unsigned int controls = 0; + reset(true, WLAN_CIPHER_SUITE_CCMP, WLAN_CIPHER_SUITE_CCMP); + assert(!brcmf_set_wsec_mode(&ndev, ¶ms)); + assert(observed_wsec == 4 && algorithm_calls == 1); + assert(observed_algos == 0x10 && observed_mask == 0x10010); + assert(firmware_algos == 0x80000010U); + assert(ndev.profile.sec.cipher_pairwise == WLAN_CIPHER_SUITE_CCMP); + assert(ndev.profile.sec.cipher_group == WLAN_CIPHER_SUITE_CCMP); + assert(!allocations); + controls++; + + reset(false, WLAN_CIPHER_SUITE_CCMP, WLAN_CIPHER_SUITE_CCMP); + assert(!brcmf_set_wsec_mode(&ndev, ¶ms)); + assert(observed_wsec == 4 && !algorithm_calls); + assert(firmware_algos == 0x80010000U); + controls++; + + const u32 groups[] = { WLAN_CIPHER_SUITE_CCMP, + WLAN_CIPHER_SUITE_GCMP_256 }; + for (unsigned int i = 0; i < 2; i++) { + reset(true, WLAN_CIPHER_SUITE_GCMP_256, groups[i]); + assert(!brcmf_set_wsec_mode(&ndev, ¶ms)); + assert(observed_wsec == 4 && algorithm_calls == 1); + assert(observed_algos == 0x10000 && observed_mask == 0x10010); + assert(firmware_algos == 0x80010000U); + assert(!allocations); + controls++; + } + + const u32 legacy[] = { WLAN_CIPHER_SUITE_TKIP, WLAN_CIPHER_SUITE_WEP40, + WLAN_CIPHER_SUITE_WEP104 }; + const u32 flags[] = { 2, 1, 1 }; + for (unsigned int i = 0; i < 3; i++) { + reset(true, legacy[i], legacy[i]); + assert(!brcmf_set_wsec_mode(&ndev, ¶ms)); + assert(observed_wsec == flags[i] && algorithm_calls == 1); + assert(!observed_algos && !observed_mask); + assert(firmware_algos == 0x80010000U && !allocations); + controls++; + } + + reset(false, WLAN_CIPHER_SUITE_GCMP_256, WLAN_CIPHER_SUITE_CCMP); + assert(brcmf_set_wsec_mode(&ndev, ¶ms) == -EOPNOTSUPP); + assert(!wsec_calls && !algorithm_calls); + controls++; + + reset(true, WLAN_CIPHER_SUITE_CCMP, WLAN_CIPHER_SUITE_CCMP); + wsec_error = -EIO; + assert(brcmf_set_wsec_mode(&ndev, ¶ms) == -EIO); + assert(wsec_calls == 1 && !algorithm_calls && !allocations); + assert(!ndev.profile.sec.cipher_pairwise); + controls++; + + reset(true, WLAN_CIPHER_SUITE_CCMP, WLAN_CIPHER_SUITE_CCMP); + algorithm_error = -EIO; + assert(brcmf_set_wsec_mode(&ndev, ¶ms) == -EIO); + assert(algorithm_calls == 1 && firmware_algos == 0x80010000U); + assert(!ndev.profile.sec.cipher_pairwise && !allocations); + controls++; + + reset(true, WLAN_CIPHER_SUITE_CCMP, WLAN_CIPHER_SUITE_CCMP); + allocation_error = true; + assert(brcmf_set_wsec_mode(&ndev, ¶ms) == -ENOMEM); + assert(!algorithm_calls && !allocations); + assert(!ndev.profile.sec.cipher_pairwise); + controls++; + + printf("%u production cipher-command controls passed\n", controls); + return 0; +} +""" + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--ref", help="Git source revision to exercise") + parser.add_argument("--out", type=Path, help="retain executable and results") + args = parser.parse_args() + + def read(path): + if args.ref: + return subprocess.check_output( + ["git", "show", f"{args.ref}:{path}"], cwd=ROOT, text=True + ) + return (ROOT / path).read_text() + + cfg = read(DRIVER / "cfg80211.c") + types = read(DRIVER / "fwil_types.h") + xtlv = read(DRIVER / "xtlv.h") + wifi = read(DRIVER.parent / "include/brcmu_wifi.h") + constants = "\n".join( + line + for source in (cfg, types, wifi) + for line in source.splitlines() + if re.match( + r"#define\s+(KEY_ALGO_MASK\(|WL_WSEC_INFO_BSS_(?:BASE|ALGOS)\s|" + r"BRCMF_WSEC_INFO_VER\s|(?:AES|TKIP|WEP)_ENABLED\s|" + r"CRYPTO_ALGO_AES_(?:CCM|GCM256)\s)", + line, + ) + ) + parts = [PREFIX, constants] + for name in ("brcmf_wsec_info_tlv", "brcmf_wsec_info"): + parts.append(association.structure(types, name)) + parts.append(association.structure(xtlv, "brcmf_xtlv")) + start = xtlv.index("enum brcmf_xtlv_option {") + parts.append(xtlv[start : xtlv.index("};", start) + 2]) + parts.append( + association.function(read(DRIVER / "xtlv.c"), "brcmf_xtlv_pack_header") + ) + for name in ("brcmf_set_wsec_info_algos", "brcmf_set_wsec_mode"): + parts.append(association.function(cfg, name)) + code = "\n".join(parts) + CONTROLS + + def run(out): + out.mkdir(parents=True, exist_ok=True) + source = out / "controls.c" + source.write_text(code) + executable = out / "controls" + subprocess.run( + [ + "clang", + "-std=gnu11", + "-O1", + "-g", + "-Wall", + "-Wextra", + "-Werror", + "-Wno-unused-variable", + "-fsanitize=address,undefined", + "-fno-sanitize-recover=all", + str(source), + "-o", + str(executable), + ], + check=True, + ) + result = subprocess.run([str(executable)], capture_output=True, text=True) + receipt = { + "exit": result.returncode, + "stdout": result.stdout, + "stderr": result.stderr, + "ref": args.ref, + "limits": ( + "Production command encoding at an observing host boundary; " + "no firmware or hardware test." + ), + } + (out / "results.json").write_text(json.dumps(receipt, indent=2) + "\n") + print(result.stdout or result.stderr, end="") + return result.returncode != 0 + + if args.out: + return run(args.out) + with tempfile.TemporaryDirectory(prefix="brcmf-cipher-") as out: + return run(Path(out)) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 95444268423a3..cbeca96b33ca6 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -85,6 +85,8 @@ def mutations(flag, names, base, expect=KILL): 'brcmf-assoc-tests.py': [(out('--output'), PASS)] + mutations('--mutation', ('short-ie', 'header-length', 'skb-capacity', 'cmplt-header'), out('--output')), 'brcmf-bss-tests.py': [(out(), PASS)], + 'brcmf-cipher-tests.py': [(out(), PASS)] + + [(out() + ['--ref', '33bec4016c466985bfbb5ff4c2089fcab8242dcf'], KILL)], # The old revision reports a failed join against the last associated BSS. 'brcmf-join-bssid-tests.py': [(out(), PASS)] + mutations('--mutation', ('stale-target', 'zero-named', 'no-call'), out()), From 7d21d499bfb548023b24f22971b046b43f5bb67d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 09:46:40 +1100 Subject: [PATCH 012/342] soc: apple: aop: route client command replies The firmware answers the client-open (25) and client-close (26) commands with reply subtypes 0x99 and 0x9a: the request subtype with bit 7 set, like the existing 0x84 and 0x8a replies. The core only matched the older subtypes, so it dropped these replies and the caller timed out. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/aop.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 089a2334d52ee..adfae0141bb98 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -128,6 +128,11 @@ const EPIC_SUBTYPE_ACCEL_REPORT: u16 = 0xc2; const EPIC_SUBTYPE_RETCODE: u16 = 0x84; const EPIC_SUBTYPE_RETCODE_PAYLOAD: u16 = 0xa0; const EPIC_SUBTYPE_STRING: u16 = 0x8a; +/// Replies to the client-open (25) and client-close (26) commands. As with +/// the other replies, the subtype is the request's with bit 7 set, and the +/// body starts with the return code. +const EPIC_SUBTYPE_CLIENT_OPEN_REPLY: u16 = 0x99; +const EPIC_SUBTYPE_CLIENT_CLOSE_REPLY: u16 = 0x9a; const QE_MAGIC1: u32 = from_fourcc(b" POI"); const QE_MAGIC2: u32 = from_fourcc(b" POA"); /// Bound on the wait for the reply to an EPIC call. The firmware can stop @@ -774,6 +779,8 @@ impl AFKEndpoint { if subtype == EPIC_SUBTYPE_RETCODE_PAYLOAD || subtype == EPIC_SUBTYPE_RETCODE || subtype == EPIC_SUBTYPE_STRING + || subtype == EPIC_SUBTYPE_CLIENT_OPEN_REPLY + || subtype == EPIC_SUBTYPE_CLIENT_CLOSE_REPLY { if data.len() < mem::size_of::() { return Err(EMSGSIZE); From c2e596f5f0b3768147916b12ead393b723fe4ee6 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 09:46:40 +1100 Subject: [PATCH 013/342] iio: apple: devmotion: map the fast path through the AOP The firmware writes the fast-path ring, so the ring has to be mapped through the AOP core's own DART stream. The service device has no DMA setup, and the allocation on it failed with -ENOMEM. Allocate on the parent AOP device instead. The payload-size property also answers with 32 bits on the M4 Pro, not 64, which failed the probe with a silent -EIO. Accept either width, and log the reply length when it is too short. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../iio/common/aop_sensors/aop_devmotion.rs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index 26d7363e1a127..2066a35f976b7 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -522,7 +522,21 @@ impl MotionIio { fn new(pdev: &platform::Device>, control: Arc) -> Result<(Self, Arc)> { let dev = pdev.as_ref(); let payload = control.get(PROP_FASTPATH_PAYLOAD_SIZE, 8)?; - let payload_len = usize::try_from(le_u64(&payload, 0).ok_or(EIO)?).map_err(|_| EINVAL)?; + // The reply is a 32-bit value on the M4 Pro; accept 64 bits as well. + let size = match payload.len() { + 8.. => le_u64(&payload, 0), + 4..=7 => le_u32(&payload, 0).map(u64::from), + _ => None, + }; + let Some(size) = size else { + dev_err!( + dev, + "fast-path payload size reply is {} bytes\n", + payload.len() + ); + return Err(EIO); + }; + let payload_len = usize::try_from(size).map_err(|_| EINVAL)?; if !(5..=MAX_REPORT_LEN).contains(&payload_len) { dev_err!(dev, "invalid fast-path payload size {}\n", payload_len); return Err(EINVAL); @@ -530,7 +544,15 @@ impl MotionIio { let stride = (payload_len + 75) & !63; let required = FASTPATH_HEADER_LEN + 2 * stride; let ring_size = (required + FASTPATH_PAGE_SIZE - 1) & !(FASTPATH_PAGE_SIZE - 1); - let ring = Coherent::::zeroed_slice(dev, ring_size, GFP_KERNEL)?; + // The AOP firmware writes the ring, so it is mapped through the AOP + // core's own DART stream: the service device has no DMA setup. + let aop_dev = dev.parent().ok_or(ENODEV)?; + // SAFETY: The AOP core unbinds its service devices before it unbinds + // itself, so the parent is bound while this probe runs. The reference + // is used only for the allocation; the buffer keeps its own device + // reference. + let aop_dev = unsafe { aop_dev.as_bound() }; + let ring = Coherent::::zeroed_slice(aop_dev, ring_size, GFP_KERNEL)?; let spec = KBox::pin( Spec { channels: [quaternion_channel(), timestamp_channel()], From 3b980a29d26948d9f5f80910c05133cc070e7b8e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:07:41 +1100 Subject: [PATCH 014/342] iio: apple: devmotion: accept any length that holds the quaternion The M4 Pro firmware sends 52-byte type 3 reports, while the decoder only took type 3 and 4 reports of exactly 60 bytes. It treated every report as a state report and the device never produced a sample. The length varies with the firmware, so require only that the quaternion fits. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/iio/aop-sensors.rst | 4 ++-- drivers/iio/common/aop_sensors/aop_devmotion.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 409cb28507378..90a2b792b2445 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -73,8 +73,8 @@ least two components smoothly while the norm remains close to one. The service's current report has a type byte followed by a versioned fixed layout. Type 2 is 108 bytes and carries little-endian IEEE-754 X, Y, Z and W -at offset 28. Types 3 and 4 are 60 bytes and carry the same fields at offset -12. Type 1 is a five-byte state report and does not update the IIO sample. +at offset 28. Types 3 and 4 carry the same fields at offset 12; their length +depends on the firmware (the M4 Pro sends 52-byte type 3 reports). Type 1 is a five-byte state report and does not update the IIO sample. The driver writes value 1 to property 61 first. Some firmware answers status 0xe00002c7 (unsupported) for this service, which is harmless. The stream is armed by the consumer registration: the driver reads property 81 for the diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index 2066a35f976b7..bd1056e935108 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -106,9 +106,11 @@ fn f32_to_q30(bits: u32) -> Option { } fn decode(report: &[u8]) -> Option<[i32; 4]> { - let offset = match (report.first().copied()?, report.len()) { - (2, 108) => 28, - (3 | 4, 60) => 12, + // The report length varies with the firmware (the M4 Pro sends 52-byte + // type 3 reports), so only the quaternion has to fit. + let offset = match report.first().copied()? { + 2 => 28, + 3 | 4 => 12, // Type 1 is a five-byte state report and has no orientation. _ => return None, }; From b24da4a6450ad3cdf8afdf5bdd82c1729604c084 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 11:51:23 +1100 Subject: [PATCH 015/342] media: apple-jpeg: add T8112 and describe the T6000 register layout Select register maps, reset images, DMA widths and completion masks through immutable compatible match data. T8112 shares the wide64 profile; describe the compact legacy32 map and enforce its address bounds without truncation. Add disabled engine/DART nodes, binding examples and KUnit coverage. The clean register contract omits the exact sparse T6000 scratch reset entries. Keep that variant refused at probe until its reset image is complete. Document this limitation and the remaining recovery and board qualification requirements. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../admin-guide/media/apple-jpeg.rst | 124 +++--- .../devicetree/bindings/media/apple,jpeg.yaml | 52 ++- arch/arm64/boot/dts/apple/t6000.dtsi | 46 ++ arch/arm64/boot/dts/apple/t8112.dtsi | 44 ++ drivers/media/platform/apple/jpeg/Kconfig | 8 +- .../platform/apple/jpeg/apple-jpeg-drv.c | 23 +- .../media/platform/apple/jpeg/apple-jpeg-hw.c | 406 +++++++++++++++--- .../media/platform/apple/jpeg/apple-jpeg-hw.h | 72 ++-- .../platform/apple/jpeg/apple-jpeg-test.c | 257 ++++++++++- 9 files changed, 847 insertions(+), 185 deletions(-) diff --git a/Documentation/admin-guide/media/apple-jpeg.rst b/Documentation/admin-guide/media/apple-jpeg.rst index f1d1faffc6a39..50e748214f821 100644 --- a/Documentation/admin-guide/media/apple-jpeg.rst +++ b/Documentation/admin-guide/media/apple-jpeg.rst @@ -2,53 +2,77 @@ :orphan: -Apple JPEG scaffold -=================== - -This driver provides a common platform and V4L2 memory-to-memory scaffold -for the Apple T6041 and T8140 JPEG engines. Each DT platform device owns one -independent m2m scheduler, with formats and VB2 queues allocated per open file. -T6041's nodes reside in ``t604x.dtsi`` in this source tree. All JPEG engine -nodes and the new T8140 DART remain disabled. SoC DART defaults are disabled; -existing board overrides are preserved. In particular, J700 already enables -its first JPEG DART independently of the disabled codec engines. - -No target HWREV is qualified. Runtime resume reads HWREV with the power domain -active and returns ``-ENODEV`` for an unlisted revision, including zero and -all-ones readbacks. Both per-compatible allow-lists are deliberately empty. -The driver does not infer a revision from a compatible, an instance number, -an ADT hw-type, or a revision observed on another SoC. - -Identification precedes reset: the public reset sequence has not been qualified -on these targets, so issuing it before admission would undermine the refusal -boundary. There are no MMIO writes, interrupt requests, reset sequences or DMA -jobs in this scaffold. Probe failure balances runtime PM and never registers -a video node. The power domain and the IOMMU are managed by their normal kernel -providers; the scaffold requires a SID-0 IOMMU attachment and the binding's -exact high DMA window. This is a topology check, not proof of pointer aliasing. - -The future video node has JPEG/NV12M format negotiation for encode and decode, -buffer allocation/import, and queue teardown. STREAMON returns ``-EOPNOTSUPP`` -and returns queued buffers according to the VB2 failure contract. The scheduler -also refuses jobs. The advertised allocation dimensions and formats are draft -API scaffolding, not a tested codec capability. Open video files retain the -m2m/device allocation through final close after platform removal; they cannot -access removed MMIO resources. - -Before enabling nodes or adding a target revision, qualification must establish -the revision, bounded reset/idle sequence, interrupt acknowledgment/deassertion, -high DVA alias, timeout/recovery and supported geometry on both instances of -each SoC. Filling an HWREV list alone does not implement streaming. Reset and -job code must validate revisions again on every runtime resume, preserve the -shared power-domain accounting, and return DMA buffers only after quiescing -hardware. Encode/decode controls, JPEG header validation, media-controller -topology and actual job programming belong to the subsequent codec work. - -The HWREV register offset comes from the MIT-licensed m1n1 register -description at commit ``f3ac615eb1376d3bbba24cd84c414b9e41892adb``: - -https://github.com/aurora-silicon/m1n1/blob/f3ac615eb1376d3bbba24cd84c414b9e41892adb/proxyclient/m1n1/hw/jpeg.py - -The scaffold deliberately does not translate the experiment's unqualified -reset or interrupt writes. ``VIDEO_APPLE_JPEG_KUNIT_TEST`` tests empty target -allow-lists, invalid readbacks and exact matching with synthetic revisions. +Apple JPEG encoder +================== + +The driver exposes one V4L2 memory-to-memory encoder per JPEG engine. It takes +full-range NV12M (4:2:0) or NV16M (4:2:2) input and produces baseline JPEG with +the standard Huffman tables. Quality and restart interval are V4L2 controls. +Decode is not exposed. + +The device compatible selects immutable register-layout and identity data: + +=================== ========= ======================== +Compatible Layout Masked HWREV +=================== ========= ======================== +apple,t6000-jpeg legacy32 0x0d0013 +apple,t6041-jpeg wide64 0x100008 +apple,t8112-jpeg wide64 0x0e0008 +apple,t8140-jpeg wide64 0x110000 +=================== ========= ======================== + +Identification powers the domain, writes MODE=0x147 and reads the selected +layout's HWREV register. The mask is 0xffff0fff: bits 12 through 15 are ignored. +Zero, all-ones and other identities are refused. The legacy selector 0x0a0103 +is not a HWREV. The wide64 variants share register and reset data; legacy32 +uses compact 32-bit DMA addresses and a separate reset image. DMA addresses +and inclusive boundaries must fit the selected address width. They are never +truncated to fit a register. + +The T6000 reset image is incomplete: its sparse scratch-register defaults +still need a complete clean specification. Its layout and job programming are +testable without hardware, but probe refuses runtime use until that reset +image is complete. Do not enable T6000 engine nodes for streaming yet. + +Each engine has a 16 KiB MMIO resource and a separate adjacent DART at SID 0. +The engine's resource must not include the DART window. Both new T6000 and +T8112 engine/DART pairs remain disabled in the SoC descriptions. Enabling +nodes and changing installed boot DTBs requires board qualification. Existing +power-domain and performance-provider nodes must also be available. + +KUnit +----- + +``VIDEO_APPLE_JPEG_KUNIT_TEST`` checks layout sharing, register offsets, +HWREV admission, quantisation tables, 4:2:0 and 4:2:2 job programming, and +address/capacity rejection. No JPEG hardware is needed. An arm64 QEMU run can +use the configuration fragment next to the driver:: + + tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1 \ + --kunitconfig=drivers/media/platform/apple/jpeg/.kunitconfig \ + --jobs=8 'apple-jpeg*' + +Qualification +------------- + +Before enabling a new board, qualify both instances: record raw HWREV, +terminal interrupt status (bit 30 or bit 31 for initial older-family +qualification), reset/idle handshakes, runtime PM, geometry, output-capacity +checks and error recovery. T8140 retains its qualified bit-31 completion +mask. The other variants initially accept bits 30 and 31; status/error and +output-capacity checks still apply. + +Check each encoder's advertised formats and use its actual video node. For +example, with a GStreamer V4L2 JPEG encoder element available:: + + gst-launch-1.0 -e videotestsrc num-buffers=1 ! \ + 'video/x-raw,format=NV12,width=640,height=480,colorimetry=1:4:5:4' ! \ + v4l2jpegenc device=/dev/videoN ! filesink location=encoded.jpg + ffmpeg -v error -i encoded.jpg -frames:v 1 -f null - + +Repeat with both supported sampling formats, 1920x1080, non-MCU-aligned +heights, consecutive jobs, quality/restart controls and undersized capture +buffers. Record negotiated range/caps. Verify that failed reset polls and +watchdog timeouts stop DMA authority before returning buffers. The current +watchdog's stop-and-defer-reset behavior still needs a reset/power-cycle +recovery implementation before new production enablement. diff --git a/Documentation/devicetree/bindings/media/apple,jpeg.yaml b/Documentation/devicetree/bindings/media/apple,jpeg.yaml index 056e1d33c00fd..e04dfecd05aa3 100644 --- a/Documentation/devicetree/bindings/media/apple,jpeg.yaml +++ b/Documentation/devicetree/bindings/media/apple,jpeg.yaml @@ -15,14 +15,17 @@ description: | share a power domain. The power controller manages the gate; no separate clock or firmware interface is required. - On T6041 the DMA window reserves one 4 GiB slice of the DART high alias for - the engine's 32-bit buffer pointer registers. T8140 engines take 64-bit - buffer addresses and use their DART's full window. + T6000 engines have 32-bit buffer pointers and require DMA addresses below + 4 GiB. T6041, T8112 and T8140 engines have 64-bit buffer pointers. Each + engine exposes only its non-overlapping 16 KiB register window; its adjacent + DART is a separate device. properties: compatible: enum: + - apple,t6000-jpeg - apple,t6041-jpeg + - apple,t8112-jpeg - apple,t8140-jpeg reg: @@ -51,8 +54,9 @@ properties: items: - const: 0x10000000000 - const: 0x100000000 - description: Device-visible DMA window, as a 64-bit base and size. - Only for engines with 32-bit buffer pointers. + description: Per-engine DMA allocation window, as a 64-bit base and size. + Existing T6041 descriptions constrain allocations to a 4 GiB slice of + the DART high aperture. required: - compatible @@ -95,3 +99,41 @@ examples: status = "disabled"; }; }; + - | + #include + #include + + soc { + #address-cells = <2>; + #size-cells = <2>; + + jpeg@409000000 { + compatible = "apple,t6000-jpeg"; + reg = <0x4 0x09000000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg0_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + }; + - | + #include + #include + + soc { + #address-cells = <2>; + #size-cells = <2>; + + jpeg@265000000 { + compatible = "apple,t8112-jpeg"; + reg = <0x2 0x65000000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg0_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + }; diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 75b3fcf23b573..77d44c9cc6d43 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -90,3 +90,49 @@ power-domains = <&ps_ane_sys_cpu>, <&ps_ane_set1>, <&ps_ane_set2>, <&ps_ane_set3>, <&ps_ane_set4>, <&ps_pms_sram>; }; + +/ { + soc { + jpeg0: jpeg@409000000 { + compatible = "apple,t6000-jpeg"; + reg = <0x4 0x09000000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg0_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + + jpeg0_dart: iommu@409004000 { + compatible = "apple,t6000-dart"; + reg = <0x4 0x09004000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_jpg>; + status = "disabled"; + }; + + jpeg1: jpeg@409008000 { + compatible = "apple,t6000-jpeg"; + reg = <0x4 0x09008000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg1_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + + jpeg1_dart: iommu@40900c000 { + compatible = "apple,t6000-dart"; + reg = <0x4 0x0900c000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_jpg>; + status = "disabled"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 23369ae0246a2..3a0414a13fd5f 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -1753,6 +1753,50 @@ #mbox-cells = <0>; }; + jpeg0: jpeg@265000000 { + compatible = "apple,t8112-jpeg"; + reg = <0x2 0x65000000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg0_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + + jpeg0_dart: iommu@265004000 { + compatible = "apple,t8110-dart"; + reg = <0x2 0x65004000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,dma-range = /bits/ 64 <0x4000 0xfffff0000>; + power-domains = <&ps_jpg>; + status = "disabled"; + }; + + jpeg1: jpeg@265008000 { + compatible = "apple,t8112-jpeg"; + reg = <0x2 0x65008000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&jpeg1_dart 0>; + power-domains = <&ps_jpg>, <&pmp_report_jpg>; + power-domain-names = "core", "perf"; + status = "disabled"; + }; + + jpeg1_dart: iommu@26500c000 { + compatible = "apple,t8110-dart"; + reg = <0x2 0x6500c000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,dma-range = /bits/ 64 <0x4000 0xfffff0000>; + power-domains = <&ps_jpg>; + status = "disabled"; + }; + avd: avd@269080000 { compatible = "apple,t8112-avd"; interrupt-parent = <&aic>; diff --git a/drivers/media/platform/apple/jpeg/Kconfig b/drivers/media/platform/apple/jpeg/Kconfig index 3aa424975834d..4b0b4632a8db2 100644 --- a/drivers/media/platform/apple/jpeg/Kconfig +++ b/drivers/media/platform/apple/jpeg/Kconfig @@ -9,9 +9,11 @@ config VIDEO_APPLE_JPEG select VIDEOBUF2_DMA_CONTIG help V4L2 memory-to-memory baseline JPEG encoder for the JPEG engine - in Apple A18 Pro (T8140) SoCs. It takes full-range NV12M (4:2:0) - or NV16M (4:2:2) frames. Other SoCs' engines are identified and - refused until their register layout is supported. + in T6000, T6041, T8112 and T8140 SoCs. It takes full-range NV12M + (4:2:0) or NV16M (4:2:2) frames. The device compatible selects the + register layout and address width; unrecognized revisions are refused. + T6000 has a layout description but remains refused until its complete + reset image is specified. To compile this driver as a module, choose M here: the module will be called apple-jpeg. diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-drv.c b/drivers/media/platform/apple/jpeg/apple-jpeg-drv.c index 736ffbeba55a0..156bfe20320c7 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-drv.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-drv.c @@ -96,7 +96,8 @@ static int aj_reset(struct apple_jpeg *jpeg) aj_write(jpeg, AJ_MODE, AJ_MODE_RESET); aj_write(jpeg, AJ_MODE, AJ_MODE_SETUP); aj_write(jpeg, AJ_MAIN_RUN, 0); - n = apple_jpeg_defaults(false, jpeg->writes, ARRAY_SIZE(jpeg->writes)); + n = apple_jpeg_defaults(jpeg->variant->layout, false, jpeg->writes, + ARRAY_SIZE(jpeg->writes)); if (n < 0) return n; for (int i = 0; i < n; i++) @@ -161,14 +162,15 @@ static irqreturn_t aj_irq(int irq, void *data) jpeg->status = aj_read(jpeg, AJ_STATUS); jpeg->int_status = aj_read(jpeg, AJ_INT_STATUS); aj_read(jpeg, AJ_DEBUG_STATUS); - if (!(jpeg->int_status & AJ_INT_STATUS_DONE) && !(jpeg->status & AJ_STATUS_ERRORS)) { + if (!(jpeg->int_status & jpeg->variant->int_done_mask) && + !(jpeg->status & AJ_STATUS_ERRORS)) { spin_unlock(&jpeg->hw_lock); return IRQ_NONE; } aj_write(jpeg, AJ_INT_STATUS, 0); aj_write(jpeg, AJ_MAIN_RUN, 0); - aj_write(jpeg, AJ_AXI_READ_PREFETCH, 0); - aj_write(jpeg, AJ_AXI_WRITE_PREFETCH, 0); + aj_write(jpeg, jpeg->variant->layout->prefetch_read, 0); + aj_write(jpeg, jpeg->variant->layout->prefetch_write, 0); aj_write(jpeg, AJ_IRQ_MASK, 0); aj_read(jpeg, AJ_BITSTREAM_CORRUPTION); jpeg->bytes = aj_read(jpeg, AJ_COMPRESSED_BYTES); @@ -176,7 +178,7 @@ static irqreturn_t aj_irq(int irq, void *data) spin_unlock(&jpeg->hw_lock); if (!(jpeg->status & AJ_STATUS_DONE) || (jpeg->status & AJ_STATUS_ERRORS) || - !(jpeg->int_status & AJ_INT_STATUS_DONE)) { + !(jpeg->int_status & jpeg->variant->int_done_mask)) { dev_err_ratelimited(jpeg->dev, "job failed: status %#x int %#x\n", jpeg->status, jpeg->int_status); err = -EIO; @@ -253,7 +255,8 @@ static void aj_device_run(void *priv) aj_finish(jpeg, ctx, -EIO); return; } - n = apple_jpeg_build_job(&job, jpeg->writes, ARRAY_SIZE(jpeg->writes)); + n = apple_jpeg_build_job(jpeg->variant->layout, &job, jpeg->writes, + ARRAY_SIZE(jpeg->writes)); if (n < 0) { spin_unlock_irqrestore(&jpeg->hw_lock, flags); aj_finish(jpeg, ctx, n); @@ -690,7 +693,7 @@ static int aj_identify(struct apple_jpeg *jpeg) if (ret < 0) return ret; aj_write(jpeg, AJ_MODE, AJ_MODE_IDENTIFY); - hwrev = aj_read(jpeg, AJ_HWREV); + hwrev = aj_read(jpeg, jpeg->variant->layout->hwrev); pm_runtime_put_sync_suspend(jpeg->dev); if (!apple_jpeg_hwrev_supported(jpeg->variant, hwrev)) return dev_err_probe(jpeg->dev, -ENODEV, "unsupported HWREV %#x\n", hwrev); @@ -713,6 +716,8 @@ static int aj_probe(struct platform_device *pdev) jpeg->variant = of_device_get_match_data(dev); if (!jpeg->variant || !jpeg->variant->hwrev) return dev_err_probe(dev, -ENODEV, "engine layout not supported\n"); + if (!jpeg->variant->layout->reset_complete) + return dev_err_probe(dev, -EOPNOTSUPP, "engine reset image incomplete\n"); mutex_init(&jpeg->lock); spin_lock_init(&jpeg->hw_lock); INIT_DELAYED_WORK(&jpeg->watchdog, aj_watchdog); @@ -743,7 +748,7 @@ static int aj_probe(struct platform_device *pdev) jpeg->regs = devm_ioremap_resource(dev, res); if (IS_ERR(jpeg->regs)) return PTR_ERR(jpeg->regs); - ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(jpeg->variant->layout->dma_addr_bits)); if (ret) return ret; @@ -798,6 +803,8 @@ static void aj_remove(struct platform_device *pdev) } static const struct of_device_id aj_of_match[] = { + { .compatible = "apple,t6000-jpeg", .data = &apple_jpeg_t6000 }, + { .compatible = "apple,t8112-jpeg", .data = &apple_jpeg_t8112 }, { .compatible = "apple,t6041-jpeg", .data = &apple_jpeg_t6041 }, { .compatible = "apple,t8140-jpeg", .data = &apple_jpeg_t8140 }, { } diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c index 4922f6a35ea23..88acd49dd1e63 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c @@ -6,11 +6,13 @@ * Quantisation tables are the ITU-T T.81 Annex K tables scaled with the * libjpeg quality formula. */ +#include #include #include #include #include #include +#include #include @@ -60,9 +62,300 @@ u32 apple_jpeg_timeout(u32 width, u32 height) } EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_timeout); +static const struct apple_jpeg_write aj_wide64_defaults[] = { + { 0x000, 0x0 }, + { 0x004, 0x0 }, + { 0x028, 0x0 }, + { 0x02c, 0x0 }, + { 0x030, 0x0 }, + { 0x090, 0x0 }, + { 0x094, 0x0 }, + { 0x0a0, 0x0 }, + { 0x0a4, 0x0 }, + { 0x0c0, 0x0 }, + { 0x0c4, 0x0 }, + { 0x0d0, 0x0 }, + { 0x0d4, 0x0 }, + { 0x1c0, 0x0 }, + { 0x1dc, 0x0 }, + { 0x288, 0x0 }, + { 0x28c, 0x0 }, + { 0x290, 0x0 }, + { 0x2a4, 0x0 }, + { 0x2a8, 0x0 }, + { 0x2ac, 0x0 }, + { 0x03c, 0x0 }, + { 0x040, 0x0 }, + { 0x044, 0x0 }, + { 0x048, 0x0 }, + { 0x04c, 0x0 }, + { 0x050, 0x0 }, + { 0x054, 0x0 }, + { 0x058, 0x0 }, + { 0x0e8, 0x0 }, + { 0x0ec, 0x0 }, + { 0x0f0, 0x0 }, + { 0x0f4, 0x0 }, + { 0x0f8, 0x0 }, + { 0x0fc, 0x0 }, + { 0x100, 0x0 }, + { 0x104, 0x0 }, + { 0x108, 0x0 }, + { 0x10c, 0x0 }, + { 0x110, 0x0 }, + { 0x13c, 0x0 }, + { 0x140, 0x0 }, + { 0x144, 0x0 }, + { 0x148, 0x0 }, + { 0x14c, 0x0 }, + { 0x150, 0x0 }, + { 0x154, 0x0 }, + { 0x158, 0x0 }, + { 0x16c, 0x0 }, + { 0x170, 0x0 }, + { 0x174, 0x0 }, + { 0x178, 0x0 }, + { 0x17c, 0x0 }, + { 0x180, 0x0 }, + { 0x184, 0x0 }, + { 0x188, 0x0 }, + { 0x18c, 0x0 }, + { 0x190, 0x0 }, + { 0x194, 0x0 }, + { 0x198, 0x0 }, + { 0x1e4, 0x0 }, + { 0x1e8, 0x0 }, + { 0x1ec, 0x0 }, + { 0x1f0, 0x0 }, + { 0x1f8, 0x0 }, + { 0x1fc, 0x0 }, + { 0x200, 0x0 }, + { 0x204, 0x0 }, + { 0x208, 0x0 }, + { 0x20c, 0x0 }, + { 0x210, 0x0 }, + { 0x218, 0x0 }, + { 0x21c, 0x0 }, + { 0x220, 0x0 }, + { 0x224, 0x0 }, + { 0x228, 0x0 }, + { 0x22c, 0x0 }, + { 0x230, 0x0 }, + { 0x234, 0x0 }, + { 0x238, 0x0 }, + { 0x23c, 0x0 }, + { 0x240, 0x0 }, + { 0x244, 0x0 }, + { 0x248, 0x0 }, + { 0x24c, 0x0 }, + { 0x250, 0x0 }, + { 0x254, 0x0 }, + { 0x260, 0x0 }, + { 0x264, 0x0 }, + { 0x268, 0x0 }, + { 0x26c, 0x0 }, + { 0x270, 0x0 }, + { 0x274, 0x0 }, + { 0x278, 0x0 }, + { 0x27c, 0x0 }, + { 0x034, 0x1 }, + { 0x038, 0x1 }, + { 0x05c, 0x1 }, + { 0x060, 0x1 }, + { 0x064, 0x1 }, + { 0x068, 0x1 }, + { 0x06c, 0x1 }, + { 0x070, 0x1 }, + { 0x074, 0x1 }, + { 0x078, 0x1 }, + { 0x07c, 0x1 }, + { 0x080, 0x1 }, + { 0x084, 0x1 }, + { 0x088, 0x1 }, + { 0x0b0, 0xffffffff }, + { 0x0b4, 0xf }, + { 0x0e0, 0xffffffff }, + { 0x0e4, 0xf }, + { 0x0b8, 0x1 }, + { 0x0bc, 0x1 }, + { 0x280, 0x1f40 }, + { 0x294, 0x7 }, + { 0x2b0, 0x7 }, + { 0x020, 0xff }, +}; + +/* Known legacy defaults; sparse scratch entries still need specification. */ +static const struct apple_jpeg_write aj_legacy32_defaults[] = { + { 0x000, 0x0 }, + { 0x004, 0x0 }, + { 0x028, 0x0 }, + { 0x02c, 0x0 }, + { 0x030, 0x0 }, + { 0x08c, 0x0 }, + { 0x090, 0x0 }, + { 0x0a0, 0x0 }, + { 0x0a4, 0x0 }, + { 0x184, 0x0 }, + { 0x03c, 0x0 }, + { 0x040, 0x0 }, + { 0x044, 0x0 }, + { 0x048, 0x0 }, + { 0x04c, 0x0 }, + { 0x050, 0x0 }, + { 0x054, 0x0 }, + { 0x058, 0x0 }, + { 0x0ac, 0x0 }, + { 0x0b0, 0x0 }, + { 0x0b4, 0x0 }, + { 0x0b8, 0x0 }, + { 0x0bc, 0x0 }, + { 0x0c0, 0x0 }, + { 0x0c4, 0x0 }, + { 0x0c8, 0x0 }, + { 0x0cc, 0x0 }, + { 0x0d0, 0x0 }, + { 0x0d4, 0x0 }, + { 0x0d8, 0xff }, + { 0x0dc, 0xff }, + { 0x0e0, 0xff }, + { 0x0e4, 0xff }, + { 0x0e8, 0xff }, + { 0x0ec, 0xff }, + { 0x0f0, 0xff }, + { 0x0f4, 0xff }, + { 0x0f8, 0xff }, + { 0x0fc, 0xff }, + { 0x100, 0x0 }, + { 0x104, 0x0 }, + { 0x108, 0x0 }, + { 0x10c, 0x0 }, + { 0x110, 0x0 }, + { 0x114, 0x0 }, + { 0x118, 0x0 }, + { 0x11c, 0x0 }, + { 0x130, 0x0 }, + { 0x134, 0x0 }, + { 0x138, 0x0 }, + { 0x13c, 0x0 }, + { 0x140, 0x0 }, + { 0x144, 0x0 }, + { 0x148, 0x0 }, + { 0x14c, 0x0 }, + { 0x150, 0x0 }, + { 0x154, 0x0 }, + { 0x158, 0x0 }, + { 0x15c, 0x0 }, + { 0x05c, 0x1 }, + { 0x060, 0x1 }, + { 0x064, 0x1 }, + { 0x068, 0x1 }, + { 0x06c, 0x1 }, + { 0x070, 0x1 }, + { 0x074, 0x1 }, + { 0x078, 0x1 }, + { 0x07c, 0x1 }, + { 0x080, 0x1 }, + { 0x084, 0x1 }, + { 0x088, 0x1 }, + { 0x034, 0x1 }, + { 0x038, 0x1 }, + { 0x09c, 0xffffffff }, + { 0x0a8, 0xffffffff }, + { 0x094, 0x1 }, + { 0x098, 0x1 }, + { 0x020, 0xff }, +}; + +static const struct apple_jpeg_reg_layout aj_wide64 = { + .input_plane0 = 0x090, + .input_plane1 = 0x0a0, + .input_end = 0x0b0, + .pipe_limit0 = 0x0b8, + .pipe_limit1 = 0x0bc, + .output_start0 = 0x0c0, + .output_start1 = 0x0d0, + .output_end = 0x0e0, + .matrix_base = 0x0e8, + .encode_format = 0x13c, + .component_pos_base = 0x140, + .convert_cs = 0x150, + .prefetch_read = 0x154, + .prefetch_write = 0x158, + .tiling = 0x19c, + .timeout = 0x1c0, + .hwrev = 0x1c4, + .image_width = 0x258, + .image_height = 0x25c, + .decode_block_base = 0x16c, + .dma_addr_bits = 64, + .reset_complete = true, + .defaults = aj_wide64_defaults, + .num_defaults = ARRAY_SIZE(aj_wide64_defaults), +}; + +static const struct apple_jpeg_reg_layout aj_legacy32 = { + .input_plane0 = 0x08c, + .input_plane1 = 0x090, + .input_end = 0x09c, + .pipe_limit0 = 0x094, + .pipe_limit1 = 0x098, + .output_start0 = 0x0a0, + .output_start1 = 0x0a4, + .output_end = 0x0a8, + .matrix_base = 0x0ac, + .encode_format = 0x100, + .component_pos_base = 0x104, + .convert_cs = 0x114, + .prefetch_read = 0x118, + .prefetch_write = 0x11c, + .tiling = 0x160, + .timeout = 0x184, + .hwrev = 0x188, + .image_width = 0x20c, + .image_height = 0x210, + .decode_block_base = 0x130, + .dma_addr_bits = 32, + .reset_complete = false, + .defaults = aj_legacy32_defaults, + .num_defaults = ARRAY_SIZE(aj_legacy32_defaults), +}; + +const struct apple_jpeg_variant apple_jpeg_t6000 = { + .layout = &aj_legacy32, + .hwrev_mask = AJ_HWREV_MASK, + .hwrev = 0x0d0013, + .int_done_mask = BIT(31) | BIT(30), +}; +EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_t6000); + +const struct apple_jpeg_variant apple_jpeg_t6041 = { + .layout = &aj_wide64, + .hwrev_mask = AJ_HWREV_MASK, + .hwrev = AJ_HWREV_T6041, + .int_done_mask = BIT(31) | BIT(30), +}; +EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_t6041); + +const struct apple_jpeg_variant apple_jpeg_t8112 = { + .layout = &aj_wide64, + .hwrev_mask = AJ_HWREV_MASK, + .hwrev = 0x0e0008, + .int_done_mask = BIT(31) | BIT(30), +}; +EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_t8112); + +const struct apple_jpeg_variant apple_jpeg_t8140 = { + .layout = &aj_wide64, + .hwrev_mask = AJ_HWREV_MASK, + .hwrev = AJ_HWREV_T8140, + .int_done_mask = AJ_INT_STATUS_DONE, +}; +EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_t8140); + struct aj_list { struct apple_jpeg_write *w; unsigned int n, max; + int error; }; static void aj_put(struct aj_list *l, u32 offset, u32 value) @@ -72,57 +365,34 @@ static void aj_put(struct aj_list *l, u32 offset, u32 value) l->n++; } -static void aj_put64(struct aj_list *l, u32 offset, u64 value) +static void aj_put_addr(struct aj_list *l, const struct apple_jpeg_reg_layout *layout, + u32 offset, u64 value) { + if (layout->dma_addr_bits == 32 && upper_32_bits(value)) { + l->error = -ERANGE; + return; + } aj_put(l, offset, lower_32_bits(value)); - aj_put(l, offset + 4, upper_32_bits(value)); + if (layout->dma_addr_bits == 64) + aj_put(l, offset + 4, upper_32_bits(value)); } -static void aj_put_range(struct aj_list *l, u32 from, u32 to, u32 value) +static void aj_defaults(struct aj_list *l, const struct apple_jpeg_reg_layout *layout, + bool encode) { - for (u32 off = from; off <= to; off += 4) - aj_put(l, off, value); -} - -static void aj_defaults(struct aj_list *l, bool encode) -{ - static const u32 zero[] = { - 0x000, 0x004, 0x028, 0x02c, 0x030, 0x090, 0x094, 0x0a0, 0x0a4, - 0x0c0, 0x0c4, 0x0d0, 0x0d4, 0x1c0, 0x1dc, 0x288, 0x28c, 0x290, - 0x2a4, 0x2a8, 0x2ac, - }; - - for (unsigned int i = 0; i < ARRAY_SIZE(zero); i++) - aj_put(l, zero[i], 0); - aj_put_range(l, 0x03c, 0x058, 0); - aj_put_range(l, 0x0e8, 0x110, 0); - aj_put_range(l, 0x13c, 0x158, 0); - aj_put_range(l, 0x16c, 0x198, 0); - aj_put_range(l, 0x1e4, 0x1f0, 0); - aj_put_range(l, 0x1f8, 0x210, 0); - aj_put_range(l, 0x218, 0x254, 0); - aj_put_range(l, 0x260, 0x27c, 0); - aj_put(l, AJ_DECODE_ENABLE, 1); - aj_put(l, AJ_ENCODE_ENABLE, 1); - aj_put_range(l, 0x05c, 0x088, 1); - aj_put64(l, AJ_INPUT_END, 0xfffffffffULL); - aj_put64(l, AJ_OUTPUT_END, 0xfffffffffULL); - aj_put(l, AJ_ENCODE_PIPE_LIMIT0, 1); - aj_put(l, AJ_ENCODE_PIPE_LIMIT1, 1); - aj_put(l, 0x280, 0x1f40); - aj_put(l, 0x294, 7); - aj_put(l, 0x2b0, 7); - aj_put(l, AJ_IRQ_MASK, 0xff); - aj_put(l, AJ_TILING_ENABLE, encode); + for (unsigned int i = 0; i < layout->num_defaults; i++) + aj_put(l, layout->defaults[i].offset, layout->defaults[i].value); + aj_put(l, layout->tiling, encode); } /* The reset image, as written between the mode changes of a reset. */ -int apple_jpeg_defaults(bool encode, struct apple_jpeg_write *w, unsigned int max) +int apple_jpeg_defaults(const struct apple_jpeg_reg_layout *layout, bool encode, + struct apple_jpeg_write *w, unsigned int max) { - struct aj_list l = { w, 0, max }; + struct aj_list l = { .w = w, .max = max }; - aj_defaults(&l, encode); - return l.n <= max ? l.n : -ENOSPC; + aj_defaults(&l, layout, encode); + return l.error ?: (l.n <= max ? l.n : -ENOSPC); } EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_defaults); @@ -130,14 +400,16 @@ EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_defaults); * Every register write of one baseline encode of two-plane (NV12 or NV16) * full-range input, in order, ending with the start command. */ -int apple_jpeg_build_job(const struct apple_jpeg_job *job, struct apple_jpeg_write *w, +int apple_jpeg_build_job(const struct apple_jpeg_reg_layout *layout, + const struct apple_jpeg_job *job, struct apple_jpeg_write *w, unsigned int max) { u32 width = job->width, height = job->height; u32 mcu_h = job->is422 ? 8 : 16; u32 crows = job->is422 ? height : DIV_ROUND_UP(height, 2); - struct aj_list l = { w, 0, max }; + struct aj_list l = { .w = w, .max = max }; u8 luma[64], chroma[64]; + u64 output_end, addr_mask = DMA_BIT_MASK(layout->dma_addr_bits); if (!width || !height || width > U16_MAX || height > U16_MAX) return -EINVAL; @@ -149,9 +421,15 @@ int apple_jpeg_build_job(const struct apple_jpeg_job *job, struct apple_jpeg_wri job->restart_interval > U16_MAX) return -EINVAL; + /* Validate every inclusive boundary before emitting any address word. */ + if (check_add_overflow(job->output, (u64)job->output_size - 1, &output_end) || + ((job->luma | job->chroma | (job->input_end | 7) | job->output | + output_end) & ~addr_mask)) + return -ERANGE; + aj_put(&l, AJ_MODE, AJ_MODE_SETUP); aj_put(&l, AJ_MAIN_RUN, 0); - aj_defaults(&l, true); + aj_defaults(&l, layout, true); aj_put(&l, AJ_MODE, AJ_MODE_OPEN); aj_put(&l, AJ_ENCODE_ENABLE, 1); @@ -172,30 +450,30 @@ int apple_jpeg_build_job(const struct apple_jpeg_job *job, struct apple_jpeg_wri aj_put(&l, AJ_PX_PLANE1_TILE_H, 2); aj_put(&l, AJ_PX_PLANE1_TILE_V, 8); aj_put(&l, AJ_PX_PLANE1_STRIDE, job->chroma_stride); - aj_put(&l, AJ_DMA_IMAGE_WIDTH, width); - aj_put(&l, AJ_DMA_IMAGE_HEIGHT, height); + aj_put(&l, layout->image_width, width); + aj_put(&l, layout->image_height, height); - aj_put64(&l, AJ_INPUT_PLANE0, job->luma); - aj_put64(&l, AJ_INPUT_PLANE1, job->chroma); + aj_put_addr(&l, layout, layout->input_plane0, job->luma); + aj_put_addr(&l, layout, layout->input_plane1, job->chroma); /* The engine treats the end as inclusive of a whole 8-byte word. */ - aj_put64(&l, AJ_INPUT_END, job->input_end | 7); - aj_put64(&l, AJ_OUTPUT_START0, job->output); - aj_put64(&l, AJ_OUTPUT_START1, job->output); - aj_put64(&l, AJ_OUTPUT_END, job->output + job->output_size - 1); - aj_put(&l, AJ_ENCODE_PIPE_LIMIT0, job->is422 ? 8 : 3); - aj_put(&l, AJ_ENCODE_PIPE_LIMIT1, job->is422 ? 2 : 1); + aj_put_addr(&l, layout, layout->input_end, job->input_end | 7); + aj_put_addr(&l, layout, layout->output_start0, job->output); + aj_put_addr(&l, layout, layout->output_start1, job->output); + aj_put_addr(&l, layout, layout->output_end, output_end); + aj_put(&l, layout->pipe_limit0, job->is422 ? 8 : 3); + aj_put(&l, layout->pipe_limit1, job->is422 ? 2 : 1); /* Two planes, Y then interleaved Cb, Cr; no colour conversion. */ - aj_put(&l, AJ_ENCODE_PIXEL_FORMAT, AJ_PIXEL_FORMAT_YUV_PLANES); - aj_put(&l, AJ_ENCODE_COMPONENT_POS(0), 0); - aj_put(&l, AJ_ENCODE_COMPONENT_POS(1), 0); - aj_put(&l, AJ_ENCODE_COMPONENT_POS(2), 1); - aj_put(&l, AJ_ENCODE_COMPONENT_POS(3), 0); - aj_put(&l, AJ_CONVERT_COLOR_SPACE, 0); + aj_put(&l, layout->encode_format, AJ_PIXEL_FORMAT_YUV_PLANES); + aj_put(&l, layout->component_pos_base, 0); + aj_put(&l, layout->component_pos_base + 4, 0); + aj_put(&l, layout->component_pos_base + 8, 1); + aj_put(&l, layout->component_pos_base + 12, 0); + aj_put(&l, layout->convert_cs, 0); - aj_put(&l, AJ_TIMEOUT, apple_jpeg_timeout(width, height)); - aj_put(&l, AJ_AXI_READ_PREFETCH, 1); - aj_put(&l, AJ_AXI_WRITE_PREFETCH, 0); + aj_put(&l, layout->timeout, apple_jpeg_timeout(width, height)); + aj_put(&l, layout->prefetch_read, 1); + aj_put(&l, layout->prefetch_write, 0); aj_put(&l, AJ_MODE, AJ_MODE_ENCODE); aj_put(&l, AJ_JPEG_IO_FLAGS, AJ_IO_FLAGS_ORDER | @@ -217,6 +495,6 @@ int apple_jpeg_build_job(const struct apple_jpeg_job *job, struct apple_jpeg_wri aj_put(&l, AJ_MAIN_RUN, 1); aj_put(&l, AJ_COMMAND, 1); - return l.n <= max ? l.n : -ENOSPC; + return l.error ?: (l.n <= max ? l.n : -ENOSPC); } EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_build_job); diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.h b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.h index 38d8b20eb99a9..50631bc3b293c 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.h +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.h @@ -9,6 +9,7 @@ #ifndef APPLE_JPEG_HW_H #define APPLE_JPEG_HW_H +#include #include #include @@ -46,25 +47,7 @@ #define AJ_PX_PLANE1_TILE_H 0x080 #define AJ_PX_PLANE1_TILE_V 0x084 #define AJ_PX_PLANE1_STRIDE 0x088 -#define AJ_INPUT_PLANE0 0x090 /* low, high */ -#define AJ_INPUT_PLANE1 0x0a0 -#define AJ_INPUT_END 0x0b0 -#define AJ_ENCODE_PIPE_LIMIT0 0x0b8 -#define AJ_ENCODE_PIPE_LIMIT1 0x0bc -#define AJ_OUTPUT_START0 0x0c0 -#define AJ_OUTPUT_START1 0x0d0 -#define AJ_OUTPUT_END 0x0e0 -#define AJ_ENCODE_PIXEL_FORMAT 0x13c -#define AJ_PIXEL_FORMAT_YUV_PLANES 4 -#define AJ_ENCODE_COMPONENT_POS(i) (0x140 + 4 * (i)) -#define AJ_CONVERT_COLOR_SPACE 0x150 -#define AJ_AXI_READ_PREFETCH 0x154 -#define AJ_AXI_WRITE_PREFETCH 0x158 -#define AJ_TILING_ENABLE 0x19c -#define AJ_TIMEOUT 0x1c0 -#define AJ_HWREV 0x1c4 -#define AJ_DMA_IMAGE_WIDTH 0x258 -#define AJ_DMA_IMAGE_HEIGHT 0x25c +#define AJ_PIXEL_FORMAT_YUV_PLANES 4 #define AJ_JPEG_IO_FLAGS 0x1000 #define AJ_IO_FLAGS_ORDER (BIT(4) | BIT(5)) #define AJ_IO_FLAGS_422 1 @@ -89,25 +72,39 @@ #define AJ_HWREV_T6041 0x100008 #define AJ_HWREV_T8140 0x110000 -struct apple_jpeg_variant { - u32 hwrev_mask; - u32 hwrev; +struct apple_jpeg_write { + u32 offset; + u32 value; }; -/* - * T6041 identifies as 0x101008 but uses the same 64-bit address layout and - * encode programming as T8140. - */ -static const struct apple_jpeg_variant apple_jpeg_t6041 = { - .hwrev_mask = AJ_HWREV_MASK, - .hwrev = AJ_HWREV_T6041, +/* Only the control/geometry and JPEG blocks are common to both layouts. */ +struct apple_jpeg_reg_layout { + u16 input_plane0, input_plane1, input_end; + u16 pipe_limit0, pipe_limit1; + u16 output_start0, output_start1, output_end; + u16 matrix_base; + u16 encode_format, component_pos_base, convert_cs; + u16 prefetch_read, prefetch_write, tiling; + u16 timeout, hwrev, image_width, image_height; + u16 decode_block_base; + u8 dma_addr_bits; + bool reset_complete; + const struct apple_jpeg_write *defaults; + u16 num_defaults; }; -static const struct apple_jpeg_variant apple_jpeg_t8140 = { - .hwrev_mask = AJ_HWREV_MASK, - .hwrev = AJ_HWREV_T8140, +struct apple_jpeg_variant { + const struct apple_jpeg_reg_layout *layout; + u32 hwrev_mask; + u32 hwrev; + u32 int_done_mask; }; +extern const struct apple_jpeg_variant apple_jpeg_t6000; +extern const struct apple_jpeg_variant apple_jpeg_t6041; +extern const struct apple_jpeg_variant apple_jpeg_t8112; +extern const struct apple_jpeg_variant apple_jpeg_t8140; + static inline bool apple_jpeg_hwrev_supported(const struct apple_jpeg_variant *variant, u32 hwrev) { @@ -116,11 +113,6 @@ apple_jpeg_hwrev_supported(const struct apple_jpeg_variant *variant, u32 hwrev) return (hwrev & variant->hwrev_mask) == variant->hwrev; } -struct apple_jpeg_write { - u32 offset; - u32 value; -}; - struct apple_jpeg_job { u32 width; u32 height; @@ -141,8 +133,10 @@ struct apple_jpeg_job { void apple_jpeg_quant_tables(u32 quality, u8 luma[64], u8 chroma[64]); u32 apple_jpeg_timeout(u32 width, u32 height); -int apple_jpeg_defaults(bool encode, struct apple_jpeg_write *w, unsigned int max); -int apple_jpeg_build_job(const struct apple_jpeg_job *job, struct apple_jpeg_write *w, +int apple_jpeg_defaults(const struct apple_jpeg_reg_layout *layout, bool encode, + struct apple_jpeg_write *w, unsigned int max); +int apple_jpeg_build_job(const struct apple_jpeg_reg_layout *layout, + const struct apple_jpeg_job *job, struct apple_jpeg_write *w, unsigned int max); #endif /* APPLE_JPEG_HW_H */ diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c index 8f8d49ade826e..6dbab0e49571a 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c @@ -74,7 +74,7 @@ static void apple_jpeg_job_420_test(struct kunit *test) int n; KUNIT_ASSERT_NOT_NULL(test, w); - n = apple_jpeg_build_job(&job, w, APPLE_JPEG_MAX_WRITES); + n = apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES); KUNIT_ASSERT_GT(test, n, 0); /* Mode opens first; the start command is the very last write. */ KUNIT_EXPECT_EQ(test, w[0].offset, AJ_MODE); @@ -89,19 +89,19 @@ static void apple_jpeg_job_420_test(struct kunit *test) KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_MCUS_H), 68); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_PLANE0_TILE_V), 16); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_PLANE1_HEIGHT_M1), 539); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_INPUT_PLANE0), 0x00100000); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_INPUT_PLANE0 + 4), 0x100); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_INPUT_END), 0x004fffff); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_OUTPUT_START1), 0x01000000); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_OUTPUT_END), 0x017fffff); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_ENCODE_PIPE_LIMIT0), 3); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x090), 0x00100000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x090 + 4), 0x100); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0b0), 0x004fffff); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0d0), 0x01000000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0e0), 0x017fffff); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0b8), 3); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_JPEG_IO_FLAGS), 0x32); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_TIMEOUT), 0x03000000); /* floor */ + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x1c0), 0x03000000); /* floor */ /* Table slot 0 holds luma 8, 6, 5, 8 at quality 75, MSB first. */ KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_QTBL(0)), 0x08060508); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_QTBL_SEL), 0x14); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_IRQ_MASK), 0xff); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_TILING_ENABLE), 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x19c), 1); } static void apple_jpeg_job_422_test(struct kunit *test) @@ -116,15 +116,15 @@ static void apple_jpeg_job_422_test(struct kunit *test) job.width = 641; /* odd width: chroma rounds up */ job.luma_stride = 656; job.chroma_stride = 656; - n = apple_jpeg_build_job(&job, w, APPLE_JPEG_MAX_WRITES); + n = apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES); KUNIT_ASSERT_GT(test, n, 0); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_CODEC), AJ_CODEC_422); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_MCUS_W), 41); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_MCUS_H), 135); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_PLANE1_WIDTH_M1), 641); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_PX_PLANE1_HEIGHT_M1), 1079); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_ENCODE_PIPE_LIMIT0), 8); - KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_ENCODE_PIPE_LIMIT1), 2); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0b8), 8); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0bc), 2); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_JPEG_IO_FLAGS), 0x31); /* Large pictures get three cycles per input byte. */ KUNIT_EXPECT_EQ(test, apple_jpeg_timeout(8192, 8192), 3 * 8192 * 8192); @@ -139,19 +139,244 @@ static void apple_jpeg_job_reject_test(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, w); job = apple_jpeg_test_job(); job.luma_stride = 1000; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(&job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); job.output += 16; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(&job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); job.input_end = job.chroma - 1; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(&job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(&job, w, 10), -ENOSPC); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, 10), -ENOSPC); +} + + +static void apple_jpeg_layout_test(struct kunit *test) +{ + const struct apple_jpeg_reg_layout *wide = apple_jpeg_t8140.layout; + const struct apple_jpeg_reg_layout *legacy = apple_jpeg_t6000.layout; + + KUNIT_EXPECT_PTR_EQ(test, apple_jpeg_t8112.layout, wide); + KUNIT_EXPECT_PTR_EQ(test, apple_jpeg_t6041.layout, wide); + KUNIT_EXPECT_PTR_NE(test, legacy, wide); + KUNIT_EXPECT_TRUE(test, wide->reset_complete); + KUNIT_EXPECT_FALSE(test, legacy->reset_complete); + KUNIT_EXPECT_EQ(test, wide->dma_addr_bits, 64); + KUNIT_EXPECT_EQ(test, legacy->dma_addr_bits, 32); + KUNIT_EXPECT_EQ(test, wide->input_plane0, 0x090); + KUNIT_EXPECT_EQ(test, wide->input_plane1, 0x0a0); + KUNIT_EXPECT_EQ(test, wide->input_end, 0x0b0); + KUNIT_EXPECT_EQ(test, wide->pipe_limit0, 0x0b8); + KUNIT_EXPECT_EQ(test, wide->pipe_limit1, 0x0bc); + KUNIT_EXPECT_EQ(test, wide->output_start0, 0x0c0); + KUNIT_EXPECT_EQ(test, wide->output_start1, 0x0d0); + KUNIT_EXPECT_EQ(test, wide->output_end, 0x0e0); + KUNIT_EXPECT_EQ(test, wide->matrix_base, 0x0e8); + KUNIT_EXPECT_EQ(test, wide->encode_format, 0x13c); + KUNIT_EXPECT_EQ(test, wide->component_pos_base, 0x140); + KUNIT_EXPECT_EQ(test, wide->convert_cs, 0x150); + KUNIT_EXPECT_EQ(test, wide->prefetch_read, 0x154); + KUNIT_EXPECT_EQ(test, wide->prefetch_write, 0x158); + KUNIT_EXPECT_EQ(test, wide->tiling, 0x19c); + KUNIT_EXPECT_EQ(test, wide->timeout, 0x1c0); + KUNIT_EXPECT_EQ(test, wide->hwrev, 0x1c4); + KUNIT_EXPECT_EQ(test, wide->image_width, 0x258); + KUNIT_EXPECT_EQ(test, wide->image_height, 0x25c); + KUNIT_EXPECT_EQ(test, wide->decode_block_base, 0x16c); + KUNIT_EXPECT_EQ(test, legacy->input_plane0, 0x08c); + KUNIT_EXPECT_EQ(test, legacy->input_plane1, 0x090); + KUNIT_EXPECT_EQ(test, legacy->input_end, 0x09c); + KUNIT_EXPECT_EQ(test, legacy->pipe_limit0, 0x094); + KUNIT_EXPECT_EQ(test, legacy->pipe_limit1, 0x098); + KUNIT_EXPECT_EQ(test, legacy->output_start0, 0x0a0); + KUNIT_EXPECT_EQ(test, legacy->output_start1, 0x0a4); + KUNIT_EXPECT_EQ(test, legacy->output_end, 0x0a8); + KUNIT_EXPECT_EQ(test, legacy->matrix_base, 0x0ac); + KUNIT_EXPECT_EQ(test, legacy->encode_format, 0x100); + KUNIT_EXPECT_EQ(test, legacy->component_pos_base, 0x104); + KUNIT_EXPECT_EQ(test, legacy->convert_cs, 0x114); + KUNIT_EXPECT_EQ(test, legacy->prefetch_read, 0x118); + KUNIT_EXPECT_EQ(test, legacy->prefetch_write, 0x11c); + KUNIT_EXPECT_EQ(test, legacy->tiling, 0x160); + KUNIT_EXPECT_EQ(test, legacy->timeout, 0x184); + KUNIT_EXPECT_EQ(test, legacy->hwrev, 0x188); + KUNIT_EXPECT_EQ(test, legacy->image_width, 0x20c); + KUNIT_EXPECT_EQ(test, legacy->image_height, 0x210); + KUNIT_EXPECT_EQ(test, legacy->decode_block_base, 0x130); + KUNIT_EXPECT_EQ(test, apple_jpeg_t8140.int_done_mask, BIT(31)); + KUNIT_EXPECT_EQ(test, apple_jpeg_t8112.int_done_mask, BIT(31) | BIT(30)); + KUNIT_EXPECT_EQ(test, apple_jpeg_t6000.int_done_mask, BIT(31) | BIT(30)); +} + +static void apple_jpeg_older_hwrev_test(struct kunit *test) +{ + const struct apple_jpeg_variant *variants[] = { + &apple_jpeg_t6000, &apple_jpeg_t6041, + &apple_jpeg_t8112, &apple_jpeg_t8140, + }; + const u32 raw[] = { 0x0d1013, 0x101008, 0x0e0008, 0x110000 }; + + for (unsigned int i = 0; i < ARRAY_SIZE(variants); i++) { + KUNIT_EXPECT_EQ(test, variants[i]->hwrev_mask, 0xffff0fff); + for (unsigned int nibble = 0; nibble < 16; nibble++) + KUNIT_EXPECT_TRUE(test, apple_jpeg_hwrev_supported(variants[i], + (raw[i] & 0xffff0fff) | (nibble << 12))); + for (unsigned int j = 0; j < ARRAY_SIZE(raw); j++) + KUNIT_EXPECT_EQ(test, apple_jpeg_hwrev_supported(variants[i], raw[j]), + i == j); + KUNIT_EXPECT_FALSE(test, apple_jpeg_hwrev_supported(variants[i], raw[i] ^ 1)); + KUNIT_EXPECT_FALSE(test, apple_jpeg_hwrev_supported(variants[i], 0)); + KUNIT_EXPECT_FALSE(test, apple_jpeg_hwrev_supported(variants[i], U32_MAX)); + } + /* The legacy selector is not in the HWREV namespace. */ + KUNIT_EXPECT_FALSE(test, apple_jpeg_hwrev_supported(&apple_jpeg_t6000, 0x0a0103)); + KUNIT_EXPECT_TRUE(test, apple_jpeg_hwrev_supported(&apple_jpeg_t6000, 0x0d2013)); +} + +static void apple_jpeg_legacy_job_test(struct kunit *test) +{ + struct apple_jpeg_write *w = kunit_kcalloc(test, APPLE_JPEG_MAX_WRITES, + sizeof(*w), GFP_KERNEL); + struct apple_jpeg_job job = apple_jpeg_test_job(); + int n; + + KUNIT_ASSERT_NOT_NULL(test, w); + job.luma = 0x100000; + job.chroma = 0x400000; + job.input_end = 0x4ffff8; + job.output = 0x1000000; + for (unsigned int is422 = 0; is422 < 2; is422++) { + job.is422 = is422; + n = apple_jpeg_build_job(apple_jpeg_t6000.layout, &job, w, + APPLE_JPEG_MAX_WRITES); + KUNIT_ASSERT_GT(test, n, 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x08c), 0x100000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x090), 0x400000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x094), is422 ? 8 : 3); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x098), is422 ? 2 : 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x09c), 0x4fffff); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0a0), 0x1000000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0a4), 0x1000000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0a8), 0x17fffff); + /* One default and one job write for each single-word pointer. */ + for (unsigned int pointer = 0; pointer < 6; pointer++) { + const u32 offsets[] = { 0x08c, 0x090, 0x09c, 0x0a0, 0x0a4, 0x0a8 }; + unsigned int count = 0; + + for (int i = 0; i < n; i++) + count += w[i].offset == offsets[pointer]; + KUNIT_EXPECT_EQ(test, count, 2); + } + /* A spurious output high half would overwrite the matrix. */ + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0ac), 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x100), 4); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x10c), 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x114), 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x118), 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x11c), 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x160), 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x184), 0x03000000); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x20c), 1920); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x210), 1080); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, AJ_JPEG_IO_FLAGS), is422 ? 0x31 : 0x32); + KUNIT_EXPECT_EQ(test, w[n - 1].offset, AJ_COMMAND); + } + /* Last representable inclusive boundaries are valid. */ + job.input_end = U32_MAX; + job.output = 0xff800000; + n = apple_jpeg_build_job(apple_jpeg_t6000.layout, &job, w, APPLE_JPEG_MAX_WRITES); + KUNIT_ASSERT_GT(test, n, 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0a8), U32_MAX); +} + +static void apple_jpeg_defaults_test(struct kunit *test) +{ + struct apple_jpeg_write *w = kunit_kcalloc(test, APPLE_JPEG_MAX_WRITES, + sizeof(*w), GFP_KERNEL); + const struct apple_jpeg_reg_layout *wide = apple_jpeg_t8140.layout; + const struct apple_jpeg_reg_layout *legacy = apple_jpeg_t6000.layout; + int n; + + KUNIT_ASSERT_NOT_NULL(test, w); + n = apple_jpeg_defaults(wide, false, w, APPLE_JPEG_MAX_WRITES); + KUNIT_ASSERT_GT(test, n, 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0b0), U32_MAX); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0b4), 0xf); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0e4), 0xf); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x19c), 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x280), 0x1f40); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x294), 7); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x2b0), 7); + /* Neither reset image may write its read-only identity register. */ + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x1c4), 0xdeadbeef); + n = apple_jpeg_defaults(legacy, true, w, APPLE_JPEG_MAX_WRITES); + KUNIT_ASSERT_GT(test, n, 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x09c), U32_MAX); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x0a8), U32_MAX); + for (u32 off = 0x0d8; off <= 0x0fc; off += 4) + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, off), 0xff); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x160), 1); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x188), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x120), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x124), 0xdeadbeef); + /* Wide reset literals must not leak into the legacy image. */ + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x280), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x2b0), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_defaults(wide, true, w, 1), -ENOSPC); + KUNIT_EXPECT_EQ(test, apple_jpeg_defaults(legacy, true, w, 1), -ENOSPC); +} + +static void apple_jpeg_address_reject_test(struct kunit *test) +{ + struct apple_jpeg_write *w = kunit_kcalloc(test, APPLE_JPEG_MAX_WRITES, + sizeof(*w), GFP_KERNEL); + struct apple_jpeg_job job = apple_jpeg_test_job(); + + KUNIT_ASSERT_NOT_NULL(test, w); + /* Each address and inclusive end must fit, without truncation. */ + job.luma = 0x100000; + job.chroma = 0x400000; + job.input_end = 0x4fffff; + job.output = 0x1000000; + for (unsigned int i = 0; i < 5; i++) { + struct apple_jpeg_job bad = job; + + switch (i) { + case 0: + bad.luma |= BIT_ULL(32); + bad.input_end = bad.luma + 0x500000; + break; + case 1: + bad.chroma |= BIT_ULL(32); + bad.input_end = bad.chroma + 0x500000; + break; + case 2: + bad.input_end |= BIT_ULL(32); + break; + case 3: + bad.output |= BIT_ULL(32); + break; + default: + bad.output = 0xffffffe0; + break; + } + w[0].value = 0xdeadbeef; + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t6000.layout, &bad, w, + APPLE_JPEG_MAX_WRITES), -ERANGE); + KUNIT_EXPECT_EQ(test, w[0].value, 0xdeadbeef); + } + job.output = U64_MAX & ~31ULL; + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, + APPLE_JPEG_MAX_WRITES), -ERANGE); } static struct kunit_case apple_jpeg_cases[] = { KUNIT_CASE(apple_jpeg_hwrev_test), + KUNIT_CASE(apple_jpeg_layout_test), + KUNIT_CASE(apple_jpeg_older_hwrev_test), + KUNIT_CASE(apple_jpeg_legacy_job_test), + KUNIT_CASE(apple_jpeg_address_reject_test), + KUNIT_CASE(apple_jpeg_defaults_test), KUNIT_CASE(apple_jpeg_quant_test), KUNIT_CASE(apple_jpeg_job_420_test), KUNIT_CASE(apple_jpeg_job_422_test), From 091f105d7e484ae5e1494962099bc457f92e6e6b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 11:55:29 +1100 Subject: [PATCH 016/342] iio: apple: devmotion: pace the fast path on the host, open it on demand The interval in property 0 does not pace the fast-path buffer. The firmware stores whatever is written there, but it refreshes the shared slots at the fusion engine's own rate, every 5 ms on the M4 Pro, for every value from 20 us to 20 s and even for zero, until the client is closed. The driver opened the client at probe and polled the buffer every 5 ms for the rest of the boot, with or without a reader. Open the client only while samples are consumed: when the IIO buffer is enabled, and briefly for a direct read, which waits up to 100 ms for the first sample and closes the client again. Poll at the requested rate, exposed as sampling_frequency (default 50 Hz, 1 to 200 Hz), and still write the matching interval for the firmware's record. Suspend now closes and resume reopens only a client that was open, and a stopped client's last sample is never returned to a later reader. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/iio/aop-sensors.rst | 17 +- .../iio/common/aop_sensors/aop_devmotion.rs | 189 ++++++++++++++++-- 2 files changed, 181 insertions(+), 25 deletions(-) diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 90a2b792b2445..3d19863000a88 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -83,11 +83,18 @@ with EPIC command 25. Only then does the driver write the non-zero interval in m property 0. Reports are polled from the published shared-memory slot rather than received as fake-HID subtype 0xc4 messages. -The driver requests 50 Hz. Around system sleep it writes a zero interval and -closes the fast path with command 26; after resume it opens the fast path -before restoring the interval. A failed or timed-out close retains the DMA -mapping because the firmware may still hold its address. This fused stream -needs no separate calibration blob. +The firmware records the property 0 interval but refreshes the shared buffer +at the fusion engine's own rate (every 5 ms on the M4 Pro) whatever value it +holds, and keeps refreshing it until the client is closed. The driver +therefore paces itself: ``sampling_frequency`` (default 50 Hz, 1 to 200 Hz) +sets how often it polls the buffer, and the client is open only while samples +are consumed. Enabling the buffer opens the client and disabling it closes it +with command 26 after writing a zero interval. A direct read without an +enabled buffer opens the client, waits up to 100 ms for the first sample and +closes it again. Around system sleep an open client is closed and reopened +after resume. A failed or timed-out close retains the DMA mapping because the +firmware may still hold its address. This fused stream needs no separate +calibration blob. Board temperature ================= diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index bd1056e935108..33263c770b39f 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -26,7 +26,7 @@ use kernel::{ atomic::{Acquire, Atomic, Relaxed, Release}, Arc, Mutex, SpinLock, }, - time, + time::{self, delay::fsleep, Delta}, types::{ForeignOwnable, Opaque}, workqueue::{self, impl_has_delayed_work, DelayedWork, Work, WorkItem}, }; @@ -45,12 +45,19 @@ const CALIBRATION_DEFAULT: u32 = 1; /// opening the report client is the operation that arms it. const STATUS_UNSUPPORTED: u32 = 0xe000_02c7; const PROP_FASTPATH_PAYLOAD_SIZE: u32 = 81; -const INTERVAL_US: u32 = 20_000; +/// The default sample rate. The fusion engine refreshes the shared buffer at +/// its own fixed rate (200 Hz on the M4 Pro) whatever interval property 0 +/// holds, so the host paces itself: it polls at the requested rate and keeps +/// the client open only while samples are consumed. +const DEFAULT_HZ: u32 = 50; +const MAX_HZ: u32 = 200; +/// How long a direct read waits for the first sample of a new client. +const FIRST_SAMPLE_MS: i64 = 100; +const FIRST_SAMPLE_POLL_MS: i64 = 5; const FASTPATH_COMMAND_LEN: usize = 84; const FASTPATH_HEADER_LEN: usize = 64; const FASTPATH_PAGE_SIZE: usize = 4096; const MAX_REPORT_LEN: usize = 108; -const POLL_MS: u32 = 5; const Q_FRAC_BITS: i32 = 30; /// The latest quaternion, in the IIO-defined W, X, Y, Z order. @@ -181,8 +188,10 @@ impl Control { ) } - fn enable(&self) -> Result { - self.set(PROP_INTERVAL, INTERVAL_US) + /// Writes the consumer's interval. The firmware records it, but the + /// fast-path buffer is refreshed at the fusion rate regardless. + fn enable(&self, interval_us: u32) -> Result { + self.set(PROP_INTERVAL, interval_us) } fn disable(&self) -> Result { @@ -206,6 +215,13 @@ struct State { client_id: Atomic, next_client_id: Atomic, last_aop_timestamp: Atomic, + hz: Atomic, + buffer_on: Atomic, + /// Set across system sleep and after unbind: no client may be open. + parked: Atomic, + /// Serializes opening and closing the client. + #[pin] + stream: Mutex<()>, #[pin] poll_work: DelayedWork, } @@ -313,7 +329,8 @@ impl State { fn start(self: &Arc) -> Result { self.open_fastpath()?; - if let Err(e) = self.control.enable() { + let interval_us = 1_000_000 / self.hz.load(Relaxed); + if let Err(e) = self.control.enable(interval_us) { if self.close_fastpath().is_err() { self.retain_ring.store(true, Release); } @@ -328,12 +345,74 @@ impl State { self.active.store(false, Release); let interval = self.control.disable(); let close = self.close_fastpath(); + // A later client must not be answered with this client's last sample. + self.sample.lock().valid = false; interval.and(close) } + /// Opens or closes the client to match its consumers. The caller holds + /// the stream lock. + fn sync_locked(self: &Arc) -> Result { + let want = self.buffer_on.load(Acquire) && !self.parked.load(Acquire); + match (want, self.active.load(Acquire)) { + (true, false) => self.start(), + (false, true) => self.stop(), + _ => Ok(()), + } + } + + fn set_buffer(self: &Arc, on: bool) -> Result { + let _guard = self.stream.lock(); + self.buffer_on.store(on, Release); + let ret = self.sync_locked(); + if on && ret.is_err() { + // The IIO core does not call predisable after a failed enable. + self.buffer_on.store(false, Release); + } + ret + } + + fn set_parked(self: &Arc, parked: bool) -> Result { + let _guard = self.stream.lock(); + self.parked.store(parked, Release); + self.sync_locked() + } + + /// Returns the current orientation. Without a buffer consumer the client + /// is opened only for this read. + fn read_now(self: &Arc) -> Result<[i32; 4]> { + let _guard = self.stream.lock(); + if !self.active.load(Acquire) { + if self.parked.load(Acquire) { + return Err(EBUSY); + } + self.start()?; + let mut waited = 0; + while waited < FIRST_SAMPLE_MS && !self.sample.lock().valid { + fsleep(Delta::from_millis(FIRST_SAMPLE_POLL_MS)); + waited += FIRST_SAMPLE_POLL_MS; + self.poll(); + } + let sample = *self.sample.lock(); + self.stop()?; + return if sample.valid { + Ok(sample.quat) + } else { + Err(ENODATA) + }; + } + let sample = *self.sample.lock(); + if sample.valid { + Ok(sample.quat) + } else { + Err(ENODATA) + } + } + fn queue_poll(self: &Arc) { - let _ = - workqueue::system_dfl().enqueue_delayed(self.clone(), time::msecs_to_jiffies(POLL_MS)); + let period_ms = 1000 / self.hz.load(Relaxed); + let _ = workqueue::system_dfl() + .enqueue_delayed(self.clone(), time::msecs_to_jiffies(period_ms)); } fn poll(&self) { @@ -441,7 +520,15 @@ unsafe extern "C" fn read_raw_multi( mask: isize, ) -> i32 { // SAFETY: `priv_` is the `Arc` installed during allocation. - let state = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }; + let state: Arc = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }.into(); + if mask == bindings::BINDINGS_IIO_CHAN_INFO_SAMP_FREQ as isize { + // SAFETY: The caller provided at least one element. + unsafe { + *vals = state.hz.load(Relaxed) as i32; + *val_len = 1; + } + return bindings::IIO_VAL_INT as i32; + } if mask == bindings::BINDINGS_IIO_CHAN_INFO_SCALE as isize { if max_len < 2 { return EINVAL.to_errno(); @@ -457,18 +544,73 @@ unsafe extern "C" fn read_raw_multi( if mask != bindings::BINDINGS_IIO_CHAN_INFO_RAW as isize || max_len < 4 { return EINVAL.to_errno(); } - let sample = *state.sample.lock(); - if !sample.valid { - return ENODATA.to_errno(); - } + let quat = match state.read_now() { + Ok(quat) => quat, + Err(e) => return e.to_errno(), + }; // SAFETY: The caller provided at least four elements. unsafe { - ptr::copy_nonoverlapping(sample.quat.as_ptr(), vals, sample.quat.len()); - *val_len = sample.quat.len() as i32; + ptr::copy_nonoverlapping(quat.as_ptr(), vals, quat.len()); + *val_len = quat.len() as i32; } bindings::IIO_VAL_INT_MULTIPLE as i32 } +/// # Safety +/// +/// The IIO core supplies the registered device. +unsafe extern "C" fn write_raw( + indio_dev: *mut bindings::iio_dev, + _chan: *const bindings::iio_chan_spec, + val: c_int, + val2: c_int, + mask: isize, +) -> c_int { + // SAFETY: `priv_` is the `Arc` installed during allocation. + let state = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }; + if mask != bindings::BINDINGS_IIO_CHAN_INFO_SAMP_FREQ as isize + || val2 != 0 + || !(1..=MAX_HZ as c_int).contains(&val) + { + return EINVAL.to_errno(); + } + // The next poll and the next client use the new rate. + state.hz.store(val as u32, Relaxed); + 0 +} + +/// # Safety +/// +/// The IIO core supplies the registered device. +unsafe extern "C" fn buffer_postenable(indio_dev: *mut bindings::iio_dev) -> c_int { + // SAFETY: `priv_` is the `Arc` installed during allocation. + let state: Arc = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }.into(); + match state.set_buffer(true) { + Ok(()) => 0, + Err(e) => e.to_errno(), + } +} + +/// # Safety +/// +/// The IIO core supplies the registered device. +unsafe extern "C" fn buffer_predisable(indio_dev: *mut bindings::iio_dev) -> c_int { + // SAFETY: `priv_` is the `Arc` installed during allocation. + let state: Arc = unsafe { Arc::::borrow((*indio_dev).priv_.cast()) }.into(); + match state.set_buffer(false) { + Ok(()) => 0, + Err(e) => e.to_errno(), + } +} + +static BUFFER_OPS: bindings::iio_buffer_setup_ops = bindings::iio_buffer_setup_ops { + preenable: None, + postenable: Some(buffer_postenable), + predisable: Some(buffer_predisable), + postdisable: None, + validate_scan_mask: None, +}; + fn quaternion_channel() -> bindings::iio_chan_spec { let mut chan = bindings::iio_chan_spec { type_: bindings::BINDINGS_IIO_ROT, @@ -485,6 +627,7 @@ fn quaternion_channel() -> bindings::iio_chan_spec { }, info_mask_separate: (1usize << bindings::BINDINGS_IIO_CHAN_INFO_RAW) | (1usize << bindings::BINDINGS_IIO_CHAN_INFO_SCALE), + info_mask_shared_by_all: 1usize << bindings::BINDINGS_IIO_CHAN_INFO_SAMP_FREQ, ..Default::default() }; chan.set_modified(1); @@ -560,6 +703,7 @@ impl MotionIio { channels: [quaternion_channel(), timestamp_channel()], info: bindings::iio_info { read_raw_multi: Some(read_raw_multi), + write_raw: Some(write_raw), ..Default::default() }, _p: PhantomPinned, @@ -585,6 +729,10 @@ impl MotionIio { client_id: Atomic::new(0), next_client_id: Atomic::new(1), last_aop_timestamp: Atomic::new(0), + hz: Atomic::new(DEFAULT_HZ), + buffer_on: Atomic::new(false), + parked: Atomic::new(false), + stream <- new_mutex!(()), poll_work <- new_delayed_work!("State::poll_work"), }), GFP_KERNEL, @@ -611,7 +759,7 @@ impl MotionIio { bindings::devm_iio_kfifo_buffer_setup_ext( dev.as_raw(), indio_dev, - ptr::null(), + &BUFFER_OPS, ptr::null_mut(), ) }; @@ -682,8 +830,10 @@ unsafe extern "C" fn pm_event( // SAFETY: By the callback contract above. let hook = unsafe { &*nb.cast::() }; let ret = match action as u32 { - bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => hook.state.stop(), - bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => hook.state.start(), + bindings::PM_SUSPEND_PREPARE | bindings::PM_HIBERNATION_PREPARE => { + hook.state.set_parked(true) + } + bindings::PM_POST_SUSPEND | bindings::PM_POST_HIBERNATION => hook.state.set_parked(false), _ => return bindings::NOTIFY_DONE as c_int, }; if let Err(e) = ret { @@ -814,7 +964,6 @@ impl platform::Driver for IIOAopDevMotionDriver { let (mut iio, state) = MotionIio::new(pdev, control)?; iio.register()?; let pm = PmHook::new(state.clone())?; - state.start()?; Ok(IIOAopDevMotionDriver { pm, state, @@ -824,7 +973,7 @@ impl platform::Driver for IIOAopDevMotionDriver { fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { this.pm.unregister(); - let _ = this.state.stop(); + let _ = this.state.set_parked(true); this.state.disable_poll(); } } From 682923a813093bebf9f243912b72bb94804230d7 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:05:15 +1100 Subject: [PATCH 017/342] media: apple-jpeg: tidy layout KUnit assertions Shorten nested assertions and align continuation lines reported by strict checkpatch in the buildbox validation run. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../platform/apple/jpeg/apple-jpeg-test.c | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c index 6dbab0e49571a..971c530c4fb30 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c @@ -134,23 +134,23 @@ static void apple_jpeg_job_reject_test(struct kunit *test) { struct apple_jpeg_write *w = kunit_kcalloc(test, APPLE_JPEG_MAX_WRITES, sizeof(*w), GFP_KERNEL); + const struct apple_jpeg_reg_layout *layout = apple_jpeg_t8140.layout; struct apple_jpeg_job job; KUNIT_ASSERT_NOT_NULL(test, w); job = apple_jpeg_test_job(); job.luma_stride = 1000; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); job.output += 16; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); job.input_end = job.chroma - 1; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); job = apple_jpeg_test_job(); - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, 10), -ENOSPC); + KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, 10), -ENOSPC); } - static void apple_jpeg_layout_test(struct kunit *test) { const struct apple_jpeg_reg_layout *wide = apple_jpeg_t8140.layout; @@ -218,9 +218,11 @@ static void apple_jpeg_older_hwrev_test(struct kunit *test) for (unsigned int i = 0; i < ARRAY_SIZE(variants); i++) { KUNIT_EXPECT_EQ(test, variants[i]->hwrev_mask, 0xffff0fff); - for (unsigned int nibble = 0; nibble < 16; nibble++) - KUNIT_EXPECT_TRUE(test, apple_jpeg_hwrev_supported(variants[i], - (raw[i] & 0xffff0fff) | (nibble << 12))); + for (unsigned int nibble = 0; nibble < 16; nibble++) { + u32 hwrev = (raw[i] & 0xffff0fff) | (nibble << 12); + + KUNIT_EXPECT_TRUE(test, apple_jpeg_hwrev_supported(variants[i], hwrev)); + } for (unsigned int j = 0; j < ARRAY_SIZE(raw); j++) KUNIT_EXPECT_EQ(test, apple_jpeg_hwrev_supported(variants[i], raw[j]), i == j); @@ -331,6 +333,7 @@ static void apple_jpeg_address_reject_test(struct kunit *test) struct apple_jpeg_write *w = kunit_kcalloc(test, APPLE_JPEG_MAX_WRITES, sizeof(*w), GFP_KERNEL); struct apple_jpeg_job job = apple_jpeg_test_job(); + int ret; KUNIT_ASSERT_NOT_NULL(test, w); /* Each address and inclusive end must fit, without truncation. */ @@ -361,13 +364,14 @@ static void apple_jpeg_address_reject_test(struct kunit *test) break; } w[0].value = 0xdeadbeef; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t6000.layout, &bad, w, - APPLE_JPEG_MAX_WRITES), -ERANGE); + ret = apple_jpeg_build_job(apple_jpeg_t6000.layout, &bad, w, + APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, ret, -ERANGE); KUNIT_EXPECT_EQ(test, w[0].value, 0xdeadbeef); } job.output = U64_MAX & ~31ULL; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, - APPLE_JPEG_MAX_WRITES), -ERANGE); + ret = apple_jpeg_build_job(apple_jpeg_t8140.layout, &job, w, APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, ret, -ERANGE); } static struct kunit_case apple_jpeg_cases[] = { From d8fa876c681cc7cf9a25d555e81959a0bdea8f4a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:05:51 +1100 Subject: [PATCH 018/342] media: apple-jpeg: keep rejection assertions within the line limit Store builder errors before checking them so the rejection cases remain readable under the strict line-length check. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/media/platform/apple/jpeg/apple-jpeg-test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c index 971c530c4fb30..1dac54e83705b 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c @@ -136,17 +136,21 @@ static void apple_jpeg_job_reject_test(struct kunit *test) GFP_KERNEL); const struct apple_jpeg_reg_layout *layout = apple_jpeg_t8140.layout; struct apple_jpeg_job job; + int ret; KUNIT_ASSERT_NOT_NULL(test, w); job = apple_jpeg_test_job(); job.luma_stride = 1000; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + ret = apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); job = apple_jpeg_test_job(); job.output += 16; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + ret = apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); job = apple_jpeg_test_job(); job.input_end = job.chroma - 1; - KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES), -EINVAL); + ret = apple_jpeg_build_job(layout, &job, w, APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, ret, -EINVAL); job = apple_jpeg_test_job(); KUNIT_EXPECT_EQ(test, apple_jpeg_build_job(layout, &job, w, 10), -ENOSPC); } From 5a685b33a1a24f1d7cf7c2fc115b4237516eda73 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:20:47 +1100 Subject: [PATCH 019/342] iio: apple: devmotion: skip the placeholder before the first estimate When the AOP starts the fusion engine, the service publishes the exact identity quaternion until its filter has a first estimate, about 140 ms (23 reports) on the M4 Pro. Since the client is now opened on demand, a direct read right after a cold start returned that placeholder as the orientation. Do not report a bit-exact identity quaternion, which a measured attitude never is, and let a direct read wait up to 500 ms for a real estimate. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/iio/aop-sensors.rst | 6 +++-- .../iio/common/aop_sensors/aop_devmotion.rs | 23 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/iio/aop-sensors.rst b/Documentation/iio/aop-sensors.rst index 3d19863000a88..dd00cb84e2709 100644 --- a/Documentation/iio/aop-sensors.rst +++ b/Documentation/iio/aop-sensors.rst @@ -90,8 +90,10 @@ therefore paces itself: ``sampling_frequency`` (default 50 Hz, 1 to 200 Hz) sets how often it polls the buffer, and the client is open only while samples are consumed. Enabling the buffer opens the client and disabling it closes it with command 26 after writing a zero interval. A direct read without an -enabled buffer opens the client, waits up to 100 ms for the first sample and -closes it again. Around system sleep an open client is closed and reopened +enabled buffer opens the client, waits up to 500 ms for the first sample and +closes it again. After the AOP starts the fusion engine, the service publishes +the exact identity quaternion until the filter has its first estimate (about +140 ms on the M4 Pro); the driver does not report those placeholders. Around system sleep an open client is closed and reopened after resume. A failed or timed-out close retains the DMA mapping because the firmware may still hold its address. This fused stream needs no separate calibration blob. diff --git a/drivers/iio/common/aop_sensors/aop_devmotion.rs b/drivers/iio/common/aop_sensors/aop_devmotion.rs index 33263c770b39f..e392c1435bbd4 100644 --- a/drivers/iio/common/aop_sensors/aop_devmotion.rs +++ b/drivers/iio/common/aop_sensors/aop_devmotion.rs @@ -52,13 +52,15 @@ const PROP_FASTPATH_PAYLOAD_SIZE: u32 = 81; const DEFAULT_HZ: u32 = 50; const MAX_HZ: u32 = 200; /// How long a direct read waits for the first sample of a new client. -const FIRST_SAMPLE_MS: i64 = 100; +const FIRST_SAMPLE_MS: i64 = 500; const FIRST_SAMPLE_POLL_MS: i64 = 5; const FASTPATH_COMMAND_LEN: usize = 84; const FASTPATH_HEADER_LEN: usize = 64; const FASTPATH_PAGE_SIZE: usize = 4096; const MAX_REPORT_LEN: usize = 108; const Q_FRAC_BITS: i32 = 30; +/// IEEE-754 single 1.0. +const IDENTITY_W: u32 = 0x3f80_0000; /// The latest quaternion, in the IIO-defined W, X, Y, Z order. #[derive(Clone, Copy, Default)] @@ -121,11 +123,20 @@ fn decode(report: &[u8]) -> Option<[i32; 4]> { // Type 1 is a five-byte state report and has no orientation. _ => return None, }; - let x = f32_to_q30(le_u32(report, offset)?)?; - let y = f32_to_q30(le_u32(report, offset + 4)?)?; - let z = f32_to_q30(le_u32(report, offset + 8)?)?; - let w = f32_to_q30(le_u32(report, offset + 12)?)?; - Some([w, x, y, z]) + let bits = [ + le_u32(report, offset)?, + le_u32(report, offset + 4)?, + le_u32(report, offset + 8)?, + le_u32(report, offset + 12)?, + ]; + // After the AOP starts the fusion engine it publishes the exact identity + // quaternion until the filter has its first estimate (about 140 ms on + // the M4 Pro). A measured attitude is never bit-exactly the identity. + if bits == [0, 0, 0, IDENTITY_W] { + return None; + } + let [x, y, z, w] = bits.map(f32_to_q30); + Some([w?, x?, y?, z?]) } struct Control { From 1a8e429a7865ea8d67df600f6abd88d108a21ede Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:39:48 +1100 Subject: [PATCH 020/342] drm/asahi: drain G16S and G17P utilisation on statistics reads Consume pending statistics from both firmware roles under the existing device mutex and epoch admission rules, without requiring another event notification. Retain the shared tag-0x13 decoder and keep device percentages separate from per-client fdinfo engine time. Exercise the production reader with queued samples, expiry, zero samples and lifecycle boundaries; add a missing-drain negative control. Document the exact shared-power ABI facts still needed before pstate or frequency can be exported. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/gpu/asahi-usage-stats.rst | 60 +++++++++ drivers/gpu/drm/asahi/g17/stats.rs | 13 ++ drivers/gpu/drm/asahi/sysfs.c | 5 + .../asahi/g17-telemetry-integration-tests.py | 116 +++++++++++++++++- tools/asahi/run-host-tests.py | 2 +- 5 files changed, 190 insertions(+), 6 deletions(-) diff --git a/Documentation/gpu/asahi-usage-stats.rst b/Documentation/gpu/asahi-usage-stats.rst index f5e731e77d0c2..ff37cce1675e5 100644 --- a/Documentation/gpu/asahi-usage-stats.rst +++ b/Documentation/gpu/asahi-usage-stats.rst @@ -68,6 +68,66 @@ per stage; commands without application timestamps also execute two existing timestamp microsequence operations per stage. Reading fdinfo loads three counters and does not traverse queues, wait for fences or access hardware. +G16S and G17P device utilisation +------------------------------ + +The shared G17 backend also exposes device-wide utilisation through the existing +``agx_stats`` sysfs attribute. Both firmware graphs use the same decoder for +statistics tag ``0x13``: words 3, 4 and 6 are tiler, renderer and device +percentages. Each complete record contributes one equally weighted sample to +three bounded sums and a common count. Device utilisation is independent of the +two engine percentages; it is not their sum. + +Reading ``agx_stats`` drains the statistics rings of both firmware roles under +the device mutex, even without an event notification. The reader observes power +epochs before and after draining and retains the transport's copy-before-consume, +suspension, queued-prefix discard and quarantine rules. It does not wake the GPU +or send a firmware command. Event service continues to drain the same rings. + +``utilisation_status`` distinguishes valid, stale and unavailable samples. +Numeric ``util_tiler_percent``, ``util_renderer_percent`` and +``util_device_percent`` values appear only for valid samples, including valid +zero samples. The existing ``unsupported`` value placeholder is retained for +other statuses; consult ``utilisation_status`` for the reason. The source, +sample count and newest host receive timestamp are reported as +``utilisation_source``, ``utilisation_samples`` and ``utilisation_host_ns``. +The averaging/freshness policy is selected by firmware graph: two nominal +periods (16 ms or 32 ms), with the existing measured delivery slack for batched +packets. Suspend, recovery, GPU power epochs and ring quarantine invalidate the +snapshot; old samples cannot become a new epoch's baseline. + +These samples have neither a qualified duration nor a client identity. They do +not change ``busy_ns`` or fdinfo's per-client ``drm-engine-*`` counters. A quiet +ring becomes stale rather than fabricating a zero-utilisation sample. Readers +must not convert these percentages into engine nanoseconds or cycles. + +Deferred shared power telemetry +------------------------------ + +Current pstate and requested/achieved frequency remain unsupported for these +firmware graphs. The shared-power snapshot ABI is not sufficiently specified +to implement a read-only reader. For **each** of G16S and G17P, it still needs: + +* The firmware-version-to-layout mapping, containing allocation and bounds, + offsets, widths and stride of the generation/seqlock word, live pstate, + performance-table selector, residency/throttle counters and PI-controller + effective-frequency field. +* The generation word's stable/odd/update protocol, including its relation to + reset and power epochs and the order required for a coherent snapshot. +* The exact selector bit/encoding for performance table A versus B, and the + valid live pstate range in that table. +* Effective-frequency units, scaling, valid range and overflow rules for both + layouts, qualified against an independent frequency measurement; G17P's + units in particular remain unresolved. +* Counter units, wrap/regression/reset semantics, and whether controller fields + remain valid while the GPU is power-gated. + +A future implementation needs bounded seqlock retries and lifecycle invalidation +before publishing these fields. Tag ``0x10`` remains decoded for diagnostics but +is not emitted by the currently qualified firmware graphs. A dormant pstate +record, a host request or a command timer cannot provide achieved frequency. +``drm-curfreq-gpu`` must wait for a qualified shared snapshot. + Host arithmetic tests --------------------- diff --git a/drivers/gpu/drm/asahi/g17/stats.rs b/drivers/gpu/drm/asahi/g17/stats.rs index 02e7cb2822610..887d966a04de3 100644 --- a/drivers/gpu/drm/asahi/g17/stats.rs +++ b/drivers/gpu/drm/asahi/g17/stats.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT //! A sysfs reader owns the session, never a pointer into detachable Firmware. +//! Reads drain the statistics rings without waking the GPU or servicing work. use super::{fw::variant::InitGraph, telemetry::Readout, Shared}; use core::sync::atomic::Ordering; @@ -17,6 +18,18 @@ impl Reader { if self.0.crashed.load(Ordering::Acquire) || firmware.recovery.pending() { firmware.rings.invalidate_statistics(); } else { + // A statistics producer update need not coincide with an event + // notification. Consume complete queued records on demand too, + // using the same epoch, suspension and quarantine admission as + // the event worker. The device mutex serializes both consumers. + firmware.observe_statistics_power(); + for &role in firmware.roles() { + firmware + .rings + .drain_statistics(&self.0.dev, &firmware.init, role); + } + // Power may have changed while copying the records. Do not + // export samples across an observed boundary. firmware.observe_statistics_power(); } qualify( diff --git a/drivers/gpu/drm/asahi/sysfs.c b/drivers/gpu/drm/asahi/sysfs.c index 3e87901b304b3..0b2bca6571129 100644 --- a/drivers/gpu/drm/asahi/sysfs.c +++ b/drivers/gpu/drm/asahi/sysfs.c @@ -105,6 +105,11 @@ static ssize_t agx_qualified_stats_show(struct asahi_stats_attribute *stats, cha "busy_ns unsupported\n" "power_mw unsupported\n" "temperature_raw unsupported\n"); + n += sysfs_emit_at(buf, n, "utilisation_source firmware-statistics-tag-0x13\n" + "utilisation_samples %llu\n" + "utilisation_host_ns %llu\n", + (unsigned long long)snap.util_samples, + (unsigned long long)snap.util_host_ns); return n; } diff --git a/tools/asahi/g17-telemetry-integration-tests.py b/tools/asahi/g17-telemetry-integration-tests.py index f493854f1466a..72230910df15a 100644 --- a/tools/asahi/g17-telemetry-integration-tests.py +++ b/tools/asahi/g17-telemetry-integration-tests.py @@ -116,16 +116,115 @@ def item(source, signature): pub fn publish_control(&self,_:u32,_:&[u8],_:bool,_:u32)->Result { Ok(()) } } } - struct Firmware { rings:channel::Rings } + struct Recovery(bool); + impl Recovery { fn pending(&self)->bool { self.0 } } + struct Firmware { + rings:channel::Rings, + init:initdata::InitData, + powered:bool, + epoch:u64, + recovery:Recovery, + } + impl Firmware { + fn roles(&self)->&'static [Role] { &[Role::Primary,Role::Secondary] } + fn observe_statistics_power(&mut self) { + if !self.rings.statistics_suspended() { + let roles=self.roles(); + self.rings.observe_statistics_power(&crate::device::Device,&self.init,roles,self.powered,self.epoch); + } + } + } struct State(std::sync::Mutex>>); impl State { fn lock(&self)->std::sync::MutexGuard<'_,Option>> { self.0.lock().unwrap() } } struct Variant { graph:fw::variant::InitGraph } - struct Shared { state:State, dev:crate::device::Device, variant:Variant } + struct Shared { state:State, dev:crate::device::Device, variant:Variant, crashed:std::sync::atomic::AtomicBool } mod reports; ''' RUST_TESTS = r''' + fn reader(graph:fw::variant::InitGraph)->stats::Reader { + stats::Reader(std::sync::Arc::new(Shared { + state:State(std::sync::Mutex::new(Some(Box::new(Firmware { + rings:channel::Rings::new(graph).unwrap(), + init:initdata::InitData::new(),powered:true,epoch:0,recovery:Recovery(false), + })))),dev:crate::device::Device,variant:Variant { graph },crashed:false.into(), + })) + } + + #[test] + fn reader_drains_without_events_and_does_not_reuse_old_samples() { + use {fw::variant::InitGraph,Role::*}; + for graph in [InitGraph::V25G83,InitGraph::G17P] { + let reader=reader(graph); + let sample=|tiler,renderer,device|[0x13,0,0,tiler,renderer,0,device,0,0,0,0,0,0,0,0,0,0,0]; + { + let state=reader.0.state.lock(); + let fw=state.as_ref().unwrap(); + fw.init.push(Primary,sample(25,75,50)); + fw.init.push(Secondary,sample(35,85,65)); + } + let view=reader.read(); + assert_eq!((view.util_status,view.tiler,view.renderer,view.device,view.util_samples), + (telemetry::VALID,30,80,57,2)); + assert_eq!(reader.read(),view); // Empty reads do not add samples. + NOW.with(|now|now.set(stats::max_age_ns(graph)+1)); + assert_eq!(reader.read().util_status,telemetry::STALE); + { + let state=reader.0.state.lock(); + state.as_ref().unwrap().init.push(Secondary,sample(0,0,0)); + } + let view=reader.read(); + assert_eq!((view.util_status,view.device,view.util_samples),(telemetry::VALID,0,1)); + assert_eq!(view.pstate_status,telemetry::UNSUPPORTED); + NOW.with(|now|now.set(1)); + } + } + + #[test] + fn reader_respects_suspend_recovery_power_epochs_and_detach() { + use {fw::variant::InitGraph,Role::*}; + for graph in [InitGraph::V25G83,InitGraph::G17P] { + let reader=reader(graph); + let sample=[0x13,0,0,25,75,0,50,0,0,0,0,0,0,0,0,0,0,0]; + let push=||reader.0.state.lock().as_ref().unwrap().init.push(Primary,sample); + push(); + assert_eq!(reader.read().util_status,telemetry::VALID); + reader.suspend(true); + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + reader.suspend(false); + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + push(); + assert_eq!(reader.read().util_status,telemetry::VALID); + reader.0.state.lock().as_mut().unwrap().epoch+=1; + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + push(); + assert_eq!(reader.read().util_status,telemetry::VALID); + reader.0.state.lock().as_mut().unwrap().powered=false; + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + reader.0.state.lock().as_mut().unwrap().powered=true; + assert_eq!(reader.read().util_status,telemetry::STALE); + push(); + assert_eq!(reader.read().util_status,telemetry::VALID); + reader.0.state.lock().as_mut().unwrap().recovery.0=true; + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + reader.0.state.lock().as_mut().unwrap().recovery.0=false; + assert_eq!(reader.read().util_status,telemetry::STALE); + push(); + assert_eq!(reader.read().util_status,telemetry::VALID); + reader.0.crashed.store(true,Ordering::Release); + push(); + assert_eq!(reader.read().util_status,telemetry::STALE); + *reader.0.state.lock()=None; + assert_eq!(reader.read().util_status,telemetry::UNAVAILABLE); + } + } + // Complete V26A428 payloads; unqualified words must never become pstate. const HIST_IDLE:[u32;18]=[0x12,0x0dc6727d,0,8,4,1,0,3,7,0,0,1000,0,0,0,0,0,0]; const HIST_ACTIVE:[u32;18]=[0x12,0x0003c9f5,0,10,0,1,0,3,9,0,0,1000,0,0,0,0,0,0]; @@ -285,7 +384,9 @@ def item(source, signature): init.push(Secondary,HIST_IDLE); rings.observe_statistics_power(&dev,&init,&[Primary,Secondary],true,1); init.push(Secondary,HIST_ACTIVE); - let shared=std::sync::Arc::new(Shared { state:State(std::sync::Mutex::new(Some(Box::new(Firmware { rings })))),dev,variant:Variant { graph } }); + let shared=std::sync::Arc::new(Shared { state:State(std::sync::Mutex::new(Some(Box::new(Firmware { + rings,init:initdata::InitData::new(),powered:true,epoch:0,recovery:Recovery(false), + })))),dev,variant:Variant { graph },crashed:false.into() }); let view=reports::View(shared.clone()); struct View<'a>(&'a reports::View); impl std::fmt::Display for View<'_> { @@ -509,7 +610,7 @@ def main(): ap.add_argument('--baseline', default='ebcf9cb777a434867e9d880892ee2b46887728bb', help='revision containing the legacy formatter') ap.add_argument('--mutation', choices=['fields', 'range', 'timestamp', 'age', 'delivery', - 'quarantine', 'epoch', 'cutoff', 'whole-batch', 'legacy-format']) + 'quarantine', 'epoch', 'cutoff', 'whole-batch', 'legacy-format', 'read-drain']) args = ap.parse_args() work = args.out or Path(tempfile.mkdtemp(prefix='asahi-g17-telemetry-')) work.mkdir(parents=True, exist_ok=True) @@ -554,10 +655,15 @@ def main(): telemetry = telemetry.replace(before, after, 1) (work / 'telemetry.rs').write_text(telemetry) stats_rs = (DRIVER / 'g17/stats.rs').read_text() + if args.mutation == 'read-drain': + assert 'for &role in firmware.roles()' in stats_rs + stats_rs = stats_rs.replace('for &role in firmware.roles()', 'for &role in &[]', 1) policy = '\n'.join(item(stats_rs, signature) for signature in ['pub(super) const fn max_age_ns', 'pub(super) const fn reports_pstate', 'pub(super) fn qualify(']) - (work / 'rings.rs').write_text(RUST_HEADER + 'mod stats { use super::fw::variant::InitGraph;\n' + reader_rs = 'pub(crate) struct Reader(pub(super) Arc);\n' + item(stats_rs, 'impl Reader') + (work / 'rings.rs').write_text(RUST_HEADER + 'mod stats { use super::{fw::variant::InitGraph, telemetry::Readout, Shared};\n' + + 'use std::sync::{Arc,atomic::Ordering};\n' + reader_rs + '\n' + policy + '\n}\nmod telemetry;\nmod channel;\n' + RUST_TESTS) # Rust resolves child modules relative to the inline parent's directory. (work / 'g17').mkdir(exist_ok=True) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 95444268423a3..eca278f74e404 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -117,7 +117,7 @@ def mutations(flag, names, base, expect=KILL): 'g15-zero-words-tests.py': [([], PASS), (['--mutations'], PASS)], 'g17-telemetry-integration-tests.py': [(out(), PASS)] + mutations('--mutation', ('fields', 'range', 'timestamp', 'age', 'delivery', - 'quarantine', 'epoch', 'cutoff', 'whole-batch', 'legacy-format'), out()), + 'quarantine', 'epoch', 'cutoff', 'whole-batch', 'legacy-format', 'read-drain'), out()), 'g17-admission-deadline-tests.py': [([], PASS)], 'g17-admission-order-tests.py': [([], PASS)], 'g17-capacity-fault-tests.py': [([], PASS)], From c47837d232ac47d2bec0b3f317ad9d7af0360552 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:40:14 +1100 Subject: [PATCH 021/342] test: check utilisation snapshot diagnostics Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/asahi/g17-telemetry-integration-tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/asahi/g17-telemetry-integration-tests.py b/tools/asahi/g17-telemetry-integration-tests.py index 72230910df15a..bd1dda2583adf 100644 --- a/tools/asahi/g17-telemetry-integration-tests.py +++ b/tools/asahi/g17-telemetry-integration-tests.py @@ -575,10 +575,12 @@ def item(source, signature): } } /* G16S/G17P: pstate unsupported by firmware, utilisation still valid. */ - current=(struct asahi_qualified_stats){.util_status=1,.pstate_status=3,.tiler=30,.renderer=80,.device=57,.pstate=0}; + current=(struct asahi_qualified_stats){.util_status=1,.pstate_status=3,.tiler=30,.renderer=80,.device=57,.pstate=0, + .util_samples=19,.util_host_ns=123}; agx_stats_show(NULL,&stats.attr,now); assert(strstr(now,"utilisation_status valid\nutil_tiler_percent 30\nutil_renderer_percent 80\nutil_device_percent 57\n" "pstate_status unsupported\npstate unsupported\nrequested_frequency_hz unsupported\n")); + assert(strstr(now,"utilisation_source firmware-statistics-tag-0x13\nutilisation_samples 19\nutilisation_host_ns 123\n")); struct device dev; struct asahi_gpu_memory memory={0}; void *handle=NULL; From c977cb309bc05f5bd51567b8a1117ef0e8475b0c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:49:58 +1100 Subject: [PATCH 022/342] docs: record G16S and G17P telemetry hardware acceptance Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/gpu/asahi-usage-stats.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/gpu/asahi-usage-stats.rst b/Documentation/gpu/asahi-usage-stats.rst index ff37cce1675e5..9294310d21794 100644 --- a/Documentation/gpu/asahi-usage-stats.rst +++ b/Documentation/gpu/asahi-usage-stats.rst @@ -128,6 +128,23 @@ is not emitted by the currently qualified firmware graphs. A dormant pstate record, a host request or a command timer cannot provide achieved frequency. ``drm-curfreq-gpu`` must wait for a qualified shared snapshot. +Hardware acceptance +------------------- + +Validate the same candidate on J616s (G16S) and Neo (G17P), retaining the known +boot fallback. Record the firmware graph, ``aurora-diag gpu``, ``agx_stats``, +the load client's fdinfo and the initial kernel warning count. Poll statistics +at 4--10 Hz through 60 seconds idle, at least 60 seconds of ``glmark2``, then +60 seconds idle. Require utilisation to rise under load and return to fresh +zero samples at idle, with every value in 0--100 and zero new kernel warnings. +Stale or unavailable samples do not satisfy the idle-zero check. + +Repeat ten idle/load transitions, suspend/resume and a normal GPU power epoch. +Require no ring quarantine or cross-epoch accumulation, renewed valid samples +after each boundary and no rendering/recovery regression. Confirm only the +submitting client's fdinfo engine counters increase. These checks are runtime +acceptance criteria; host decoder tests alone do not establish a hardware pass. + Host arithmetic tests --------------------- From a6ee55ad5626f7c5cd0de3d6958f6d7848bd374a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 23:10:45 +1100 Subject: [PATCH 023/342] accel/ane: run M1 Pro and Max requests when the PMP is not running Since the M1 Pro and Max device trees name the PMP report as the ANE's performance controller (659e2ccef5c9, "arm64: dts: apple: wire M1 Pro and Max ANE level control"), every submit first asks the report for a level. The PMP that serves the report is not started by Linux on these SoCs (its node is disabled), so the request fails with -EAGAIN and the submit is refused. On the M1 Pro (fleet22) all 16 images of the MobileNet classify demo failed with "performance request failed: -11" and fell back to the CPU. Treat -EAGAIN from the report as "nobody takes a level request now": log it once and run the request at the level the firmware chose, as the driver did before the level control. Other errors, ownership and ACK failures, still fail the submit, and a running PMP still gets the level request on every new burst. Fixes: 996ef2aef581 ("accel/ane: replace CPU QoS boost with scoped performance requests") Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_perf.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/accel/ane/ane_perf.c b/drivers/accel/ane/ane_perf.c index 468fd151c4886..54f04d1ec9817 100644 --- a/drivers/accel/ane/ane_perf.c +++ b/drivers/accel/ane/ane_perf.c @@ -80,9 +80,21 @@ int ane_perf_begin(struct ane_device *ane) if (p->report && !p->clock_held) { ret = apple_pmp_report_ane_perf(p->report, ane->dev, p->high_level, &p->clock_held); - if (ret) + /* + * -EAGAIN: the PMP that serves the report is not running (on + * the M1 Pro and Max Linux does not start it), so nobody can + * take a level request. The engine still runs at the level the + * firmware chose; failing every submit would leave it unusable. + */ + if (ret == -EAGAIN && !p->clock_held) { + dev_info_once(ane->dev, + "performance controller not running; running at the firmware's level\n"); + ret = 0; + } else if (ret) { goto out; - p->level = p->high_level; + } else { + p->level = p->high_level; + } } out: p->error = ret; From 7a1effc628cb46c28e80b0092cc4f7ff249ec2be Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 01:26:37 +1100 Subject: [PATCH 024/342] drm/asahi: g17: read a power-gated GPU as idle, not stale The firmware gates the G16S/G17P cores a few milliseconds after the last work completes and emits no utilisation record while they are gated. Every power observation invalidated the readout, so agx_stats reported a stale sample (and "unsupported" values) whenever it was read on an idle or lightly loaded GPU, which is almost always. On the Neo, with or without the statistics drain on reads, utilisation was valid only under sustained glmark2 load and stale at idle and under short bursts, although the firmware delivered and the driver admitted every tag 0x13 record. A power gate still ends the averaging epoch, but the last sample now stays valid until it ages out, and the gated GPU then reads as a valid zero for every utilisation value. A wake starts a new epoch that stays stale until its first record. Suspend, recovery, restart and quarantine remain stale, never idle. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/gpu/asahi-usage-stats.rst | 10 +++- drivers/gpu/drm/asahi/g17/channel.rs | 6 ++- drivers/gpu/drm/asahi/g17/telemetry.rs | 51 ++++++++++++++++++- .../asahi/g17-telemetry-integration-tests.py | 10 ++-- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/Documentation/gpu/asahi-usage-stats.rst b/Documentation/gpu/asahi-usage-stats.rst index 9294310d21794..e18208c7d25ea 100644 --- a/Documentation/gpu/asahi-usage-stats.rst +++ b/Documentation/gpu/asahi-usage-stats.rst @@ -96,9 +96,17 @@ periods (16 ms or 32 ms), with the existing measured delivery slack for batched packets. Suspend, recovery, GPU power epochs and ring quarantine invalidate the snapshot; old samples cannot become a new epoch's baseline. +The firmware power-gates the GPU cores a few milliseconds after the last work +completes and emits no utilisation record while they are gated. A power gate +therefore ends the averaging epoch but is not a loss of knowledge: the last +sample stays valid until it ages out, after which the gated GPU reads as a valid +zero for every utilisation value until it powers up again. Waking starts a new +epoch, stale until its first record arrives. + These samples have neither a qualified duration nor a client identity. They do not change ``busy_ns`` or fdinfo's per-client ``drm-engine-*`` counters. A quiet -ring becomes stale rather than fabricating a zero-utilisation sample. Readers +ring on powered cores becomes stale rather than fabricating a zero-utilisation +sample; only gated cores read as zero. Readers must not convert these percentages into engine nanoseconds or cycles. Deferred shared power telemetry diff --git a/drivers/gpu/drm/asahi/g17/channel.rs b/drivers/gpu/drm/asahi/g17/channel.rs index bd9a946d49176..5e92cce8683c8 100644 --- a/drivers/gpu/drm/asahi/g17/channel.rs +++ b/drivers/gpu/drm/asahi/g17/channel.rs @@ -96,7 +96,11 @@ impl Rings { epoch: u64, ) { if !powered || !self.statistics_powered || epoch != self.statistics_epoch { - self.telemetry.invalidate(); + if powered { + self.telemetry.invalidate(); + } else { + self.telemetry.gate(); + } // End the queued prefix *now*, not at the next drain. A boolean // discard-next-batch also throws away records produced after this // observation, even if the queue was empty at the boundary. diff --git a/drivers/gpu/drm/asahi/g17/telemetry.rs b/drivers/gpu/drm/asahi/g17/telemetry.rs index 300780d960d63..e57f91b5bea02 100644 --- a/drivers/gpu/drm/asahi/g17/telemetry.rs +++ b/drivers/gpu/drm/asahi/g17/telemetry.rs @@ -45,6 +45,10 @@ pub(super) struct Telemetry { delivery_ns: Option, /// The last two intervals between utilisation deliveries in this epoch. pub(super) delivery_intervals: [Option; 2], + /// The GPU cores were power-gated at the last observation. The firmware + /// gates them a few milliseconds after the last work completes and emits no + /// utilisation record while gated, so a gated GPU is idle, not unknown. + gated: bool, } impl Telemetry { @@ -62,6 +66,18 @@ impl Telemetry { self.delta_ticks = None; self.delivery_ns = None; self.delivery_intervals = [None; 2]; + self.gated = false; + } + + /// The cores were observed power-gated. End the averaging epoch exactly as + /// any other boundary does, but keep the last published utilisation until + /// it ages out: it describes the work that ran just before the gate. After + /// that the GPU reads as idle (0%) for as long as it stays gated. + pub(super) fn gate(&mut self) { + let view = self.view; + self.invalidate(); + self.view.util_status = view.util_status; + self.gated = true; } /// The firmware may publish several records per producer update: V25G83 @@ -144,7 +160,14 @@ impl Telemetry { let expired = |received| now_ns < received || now_ns - received >= limit; // The oldest contributing sample bounds the whole averaging window, // measured against the next expected delivery plus the host policy. - if view.util_status == VALID && expired(self.window_ns) { + if self.gated && (view.util_status != VALID || expired(self.window_ns)) { + // No work can run on gated cores: idle is a measurement here. + view.util_status = VALID; + view.tiler = 0; + view.renderer = 0; + view.device = 0; + view.util_samples = 0; + } else if view.util_status == VALID && expired(self.window_ns) { view.util_status = STALE; } // A pstate report describes a state transition, with no qualified @@ -255,6 +278,32 @@ mod tests { assert_eq!(stats.read(102 + AGE, AGE).pstate_status, VALID); } + #[test] + fn a_gated_gpu_reads_idle_after_its_last_sample_ages_out() { + let mut stats = Telemetry::default(); + // Gated before any record (idle since boot): idle, not unknown. + stats.gate(); + let view = stats.read(0, AGE); + assert_eq!(view.util_status, VALID); + assert_eq!((view.tiler, view.renderer, view.device), (0, 0, 0)); + // Busy, then gated: the last sample stays until it ages out. + stats.invalidate(); + stats.record(&U1, 100, AGE); + stats.gate(); + let view = stats.read(100 + AGE - 1, AGE); + assert_eq!((view.util_status, view.device), (VALID, 50)); + let view = stats.read(100 + AGE, AGE); + assert_eq!((view.util_status, view.tiler, view.renderer, view.device), (VALID, 0, 0, 0)); + // The gate ends the averaging epoch: the next record starts a new window. + stats.record(&U2, 200 + AGE, AGE); + let view = stats.read(200 + AGE, AGE); + assert_eq!((view.device, view.util_samples), (65, 1)); + // A non-power boundary (suspend, crash, quarantine) is stale, never idle. + stats.gate(); + stats.invalidate(); + assert_eq!(stats.read(u64::MAX, AGE).util_status, STALE); + } + #[test] fn batched_deliveries_stay_valid_until_the_next_one_is_late() { const BATCH: u64 = 24_000_000; diff --git a/tools/asahi/g17-telemetry-integration-tests.py b/tools/asahi/g17-telemetry-integration-tests.py index bd1dda2583adf..b018a44b4b15c 100644 --- a/tools/asahi/g17-telemetry-integration-tests.py +++ b/tools/asahi/g17-telemetry-integration-tests.py @@ -205,7 +205,9 @@ def item(source, signature): assert_eq!(reader.read().util_status,telemetry::VALID); reader.0.state.lock().as_mut().unwrap().powered=false; push(); - assert_eq!(reader.read().util_status,telemetry::STALE); + // Gated cores run no work: the last sample stays until it ages + // out, then the GPU reads idle. Neither is stale. + assert_eq!(reader.read().util_status,telemetry::VALID); reader.0.state.lock().as_mut().unwrap().powered=true; assert_eq!(reader.read().util_status,telemetry::STALE); push(); @@ -441,9 +443,11 @@ def item(source, signature): 2=>rings.observe_statistics_power(&dev,&init,&[Primary],true,1), // Wake observed by a fast publisher. _=>rings.invalidate_statistics(), // Restart handshake. } - assert_eq!(rings.read_statistics(1).util_status,telemetry::STALE); + // A power gate reads idle (valid); every other boundary is stale. + let expect=if boundary==1 {telemetry::VALID} else {telemetry::STALE}; + assert_eq!(rings.read_statistics(1).util_status,expect); rings.drain_statistics(&dev,&init,Primary); - assert_eq!(rings.read_statistics(1).util_status,telemetry::STALE); + assert_eq!(rings.read_statistics(1).util_status,expect); rings.observe_statistics_power(&dev,&init,&[Primary],true,u64::from(boundary >= 2)); init.push(Primary,words); rings.drain_statistics(&dev,&init,Primary); From 72f8eecf708bb43e3409cade6fbbdcb7b3ff292a Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sat, 7 Nov 2026 04:21:48 -0500 Subject: [PATCH 025/342] arm64: idle: T6050 idles in WFI even with idle=nop m1n1 appends "idle=nop arm64.nowfxt" to the command line on every chip whose Apple system registers are locked (M4 and later), for kernels that do not preserve the state WFI loses there. It appends them after the user's arguments, so an idle= on the command line cannot override it. This kernel preserves that state (apple_wfi_quirk_init(), and WFxT is forced off for M4 and later in idreg-override), so on T6050 idle=nop only makes every idle CPU spin: cpuidle's two WFI states call cpu_do_idle(), which does nothing with idle=nop. Treat T6050 (MIDR parts 0x064 and 0x065) like T8142 and keep WFI as the idle method. On the 16-inch M5 Pro (J716s) the system then draws 9.8 W at idle on the charger instead of 16.4 W (SMC total system power), and a 56-minute idle soak with an FP consistency check on all 18 CPUs and four s2idle steps up to a real suspend/resume passed. On the 14-inch M5 Pro (J714s), betizzel measured 5.6 W against 15.3 W, and a per-CPU register check passed 250,000 1 ms sleeps on each of its 15 CPUs. Add apple_keep_idle_nop to keep idle=nop for comparisons and as a fallback that needs no new kernel. Link: https://github.com/betizzel/omarchy-m5/commit/a5df9e4df61b60dd6195e13a2a3a043d76b92c0f Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- .../admin-guide/kernel-parameters.txt | 7 +++++ arch/arm64/kernel/idle.c | 27 ++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9526a1b399fcd..2e6fa8b49752e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -552,6 +552,13 @@ Kernel parameters apm= [APM] Advanced Power Management See header of arch/x86/kernel/apm_32.c. + apple_keep_idle_nop + [ARM64,EARLY] On T6050 and T8142, keep idle=nop. + These cores idle in WFI by default, and an idle=nop + that the boot loader appends is ignored, because the + kernel preserves the registers WFI loses there. With + this flag idle=nop spins the idle loop as elsewhere. + apparmor= [APPARMOR] Disable or enable AppArmor at boot time Format: { "0" | "1" } See security/apparmor/Kconfig help text diff --git a/arch/arm64/kernel/idle.c b/arch/arm64/kernel/idle.c index 267677adc220a..0d76030f78205 100644 --- a/arch/arm64/kernel/idle.c +++ b/arch/arm64/kernel/idle.c @@ -50,6 +50,18 @@ early_param("idle", setup_idle); * yet, so it is a plain flag. */ static bool apple_wfi_loses_regs __ro_after_init; +static bool apple_keep_idle_nop __initdata; + +/* + * The boot loader appends idle=nop after the user's arguments, so it cannot + * be overridden on the command line. This flag keeps it anyway. + */ +static int __init setup_apple_keep_idle_nop(char *arg) +{ + apple_keep_idle_nop = true; + return 0; +} +early_param("apple_keep_idle_nop", setup_apple_keep_idle_nop); void __init apple_wfi_quirk_init(void) { @@ -60,14 +72,17 @@ void __init apple_wfi_quirk_init(void) pr_info("Apple: preserving registers across WFI\n"); } /* - * aura passes idle=nop on M5 for kernels without this quirk. Spinning - * idle keeps all ten cores busy (cpuidle's WFI state spins too), and - * the SoC sits near 90 C and throttles; WFI is safe here. + * aura (J813) and m1n1 (T6050) pass idle=nop on M4 and later for + * kernels without this quirk. Spinning idle keeps every core busy + * (cpuidle's WFI states spin too): on T8142 the SoC sits near 90 C + * and throttles, on T6050 the system draws about 10 W more at idle. + * WFI is safe here. */ - if (idle == ARM64_IDLE_NOP && - (model == MIDR_APPLE_T8142_E || model == MIDR_APPLE_T8142_P)) { + if (idle == ARM64_IDLE_NOP && !apple_keep_idle_nop && + (model == MIDR_APPLE_T8142_E || model == MIDR_APPLE_T8142_P || + model == MIDR_APPLE_T6050_064 || model == MIDR_APPLE_T6050_065)) { idle = ARM64_IDLE_WFI; - pr_info("Apple: T8142 idles in WFI, ignoring idle=nop\n"); + pr_info("Apple: idling in WFI, ignoring idle=nop\n"); } } From 186ce02e0e6fcda583e265055c283b22d21a07a0 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 03:53:22 +1100 Subject: [PATCH 026/342] media: apple-prores: add T6000 APR a0 descriptor and match data Select descriptor, statistics registers, IRQ count, resources and initialization from the DT compatible. Add the public MIT m1n1 48-entry T6000 core sequence and an independent legacy descriptor builder; preserve its public opaque rate-control settings rather than assuming v1 semantics. Describe APR0 and its DART disabled and add the dormant SCODEC performance request. Document the bounded J316s boot.bin DTB-set trial and the DMA-ownership and PMP prerequisites to first DMA. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../bindings/media/apple,prores.yaml | 14 +- arch/arm64/boot/dts/apple/t600x-die0.dtsi | 25 +++ drivers/media/platform/apple/prores/Kconfig | 2 +- .../platform/apple/prores/apple-prores-desc.c | 78 ++++++++- .../platform/apple/prores/apple-prores-drv.c | 160 +++++++++++++++--- .../platform/apple/prores/apple-prores-test.c | 88 ++++++++++ .../platform/apple/prores/apple-prores.h | 1 + .../media/platform/apple/prores/m1n1-LICENSE | 22 +++ .../apple/prores/t6000-qualification.rst | 105 ++++++++++++ 9 files changed, 464 insertions(+), 31 deletions(-) create mode 100644 drivers/media/platform/apple/prores/m1n1-LICENSE create mode 100644 drivers/media/platform/apple/prores/t6000-qualification.rst diff --git a/Documentation/devicetree/bindings/media/apple,prores.yaml b/Documentation/devicetree/bindings/media/apple,prores.yaml index 4124c331a9f8c..85d6b0f8f8319 100644 --- a/Documentation/devicetree/bindings/media/apple,prores.yaml +++ b/Documentation/devicetree/bindings/media/apple,prores.yaml @@ -17,7 +17,9 @@ description: | properties: compatible: oneOf: - - const: apple,t8140-prores + - enum: + - apple,t6000-prores + - apple,t8140-prores - items: - const: apple,t6041-prores - const: apple,prores @@ -89,6 +91,16 @@ allOf: reg-names: maxItems: 2 +allOf: + - if: + properties: + compatible: + const: apple,t6000-prores + then: + properties: + interrupts: + maxItems: 1 + additionalProperties: false examples: diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi index dd36e7e53ebea..c266fc9dd5831 100644 --- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi @@ -8,6 +8,30 @@ &SOC_NODE { + apr0_dart: iommu@311008000 { + compatible = "apple,t6000-dart", "apple,t8110-dart"; + reg = <0x3 0x11008000 0x0 0x4000>; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_scodec>; + status = "disabled"; + }; + + apr0: video-codec@311000000 { + compatible = "apple,t6000-prores"; + reg = <0x3 0x11000000 0x0 0x4000>, + <0x3 0x10000000 0x0 0x1000000>; + reg-names = "core", "wrapper"; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&apr0_dart 0>; + power-domains = <&ps_scodec>, <&pmp_report_scodec>; + power-domain-names = "core", "perf"; + resets = <&ps_scodec>; + status = "disabled"; + }; + ave_dart1: iommu@20d030000 { compatible = "apple,t6000-dart"; reg = <0x2 0x0d030000 0 0x4000>; @@ -237,6 +261,7 @@ compatible = "apple,t6000-pmp-v2-report-entry"; reg = <0x14>; label = "pmp-scodec"; + apple,dvfs = <0x115 2>; #power-domain-cells = <0>; power-domains = <&ps_scodec>; status = "disabled"; diff --git a/drivers/media/platform/apple/prores/Kconfig b/drivers/media/platform/apple/prores/Kconfig index a0fddcaab7fee..3b908f60cdd7c 100644 --- a/drivers/media/platform/apple/prores/Kconfig +++ b/drivers/media/platform/apple/prores/Kconfig @@ -9,7 +9,7 @@ config VIDEO_APPLE_PRORES select VIDEOBUF2_DMA_CONTIG help V4L2 memory-to-memory driver for the ProRes encoder engine (APR) - in Apple A18 Pro (T8140) SoCs. It encodes 8 and 16 bit 4:2:2 and + in Apple M1 Pro (T6000) and A18 Pro (T8140) SoCs. It encodes 8 and 16 bit 4:2:2 and 4:4:4 frames to ProRes 422 Proxy, LT, 422, HQ, 4444 and 4444 XQ. To compile this driver as a module, choose M here: the module diff --git a/drivers/media/platform/apple/prores/apple-prores-desc.c b/drivers/media/platform/apple/prores/apple-prores-desc.c index c12c31007b17c..17a87ea2e6353 100644 --- a/drivers/media/platform/apple/prores/apple-prores-desc.c +++ b/drivers/media/platform/apple/prores/apple-prores-desc.c @@ -322,15 +322,15 @@ u32 apr_slice_count(u32 width, u32 height, u32 log2_slice) } EXPORT_SYMBOL_IF_KUNIT(apr_slice_count); -int apr_build_desc(const struct apr_frame *f, u8 *desc) +static int apr_build_desc_common(const struct apr_frame *f, u8 *desc) { bool is444 = apr_input_is_444(f->input); bool deep = f->input == APR_INPUT_422_16 || f->input == APR_INPUT_444_16; - enum apr_qtable table = apr_profile_qtable(f->profile); - u32 min_luma, min_chroma, cmd, slices, mbs, target, max; - unsigned int i; + u32 min_luma, min_chroma, cmd, slices; - if (f->profile >= APR_PROFILES || is444 != apr_profile_is_444(f->profile)) + if ((unsigned int)f->input > APR_INPUT_444_16 || + (unsigned int)f->profile >= APR_PROFILES || + is444 != apr_profile_is_444(f->profile)) return -EINVAL; if (!f->width || !f->height || f->width > U16_MAX || f->height > U16_MAX || f->width & 1) @@ -346,8 +346,6 @@ int apr_build_desc(const struct apr_frame *f, u8 *desc) slices = apr_slice_count(f->width, f->height, APR_SLICE_LOG2); if (slices > U16_MAX) return -EINVAL; - mbs = DIV_ROUND_UP(f->width, 16) * DIV_ROUND_UP(f->height, 16); - apr_frame_budget(f->profile, f->width, f->height, &target, &max); memset(desc, 0, APR_DESC_BYTES); @@ -370,6 +368,24 @@ int apr_build_desc(const struct apr_frame *f, u8 *desc) put_unaligned_le64(f->chroma, desc + D_CHROMA); put_unaligned_le64(0, desc + D_ALPHA); + return 0; +} + +int apr_build_desc(const struct apr_frame *f, u8 *desc) +{ + bool is444 = apr_input_is_444(f->input); + enum apr_qtable table = apr_profile_qtable(f->profile); + u32 slices, mbs, target, max; + unsigned int i; + int ret; + + ret = apr_build_desc_common(f, desc); + if (ret) + return ret; + slices = apr_slice_count(f->width, f->height, APR_SLICE_LOG2); + mbs = DIV_ROUND_UP(f->width, 16) * DIV_ROUND_UP(f->height, 16); + apr_frame_budget(f->profile, f->width, f->height, &target, &max); + put_unaligned_be16(slices, desc + D_SLICES); desc[D_SLICE_LOG2] = APR_SLICE_LOG2 << 4; desc[D_QUANT_INDEX] = apr_profile_policy[f->profile].quant_index; @@ -403,6 +419,54 @@ int apr_build_desc(const struct apr_frame *f, u8 *desc) } EXPORT_SYMBOL_IF_KUNIT(apr_build_desc); +/* + * T6000 constants: Copyright The Asahi Linux Contributors. + * MIT license: see m1n1-LICENSE. + * Descriptor v0 (APR a0). Source: MIT m1n1 f3ac615eb137, + * proxyclient/m1n1/hw/prores.py:7-111 and + * proxyclient/experiments/prores.py:592-644. Only the input/output prefix + * is shared with v1. The public experiment leaves both legacy limits at + * 0xffff; their meaning is unqualified, so do not apply v1 budget formulas. + */ +int apr_build_desc_v0(const struct apr_frame *f, u8 *desc) +{ + bool is444 = apr_input_is_444(f->input); + enum apr_qtable table = apr_profile_qtable(f->profile); + unsigned int i; + int ret; + + ret = apr_build_desc_common(f, desc); + if (ret) + return ret; + + /* Frame header, including the legacy aspect/rate byte at 0x065. */ + put_unaligned_be16(D_FH_BYTES, desc + 0x058); + desc[0x05b] = is444 ? 1 : 0; + memcpy(desc + 0x05c, "aurr", 4); + put_unaligned_be16(f->width, desc + 0x060); + put_unaligned_be16(f->height, desc + 0x062); + desc[0x064] = (is444 ? 3 : 2) << 6; + desc[0x066] = f->primaries; + desc[0x067] = f->transfer; + desc[0x068] = f->matrix; + /* No alpha. Both quantisation matrices are included in the header. */ + desc[0x06b] = 3; + /* Deprecated slice count at 0x0ec stays zero, as in m1n1. */ + desc[0x0ee] = APR_SLICE_LOG2 << 4; + desc[0x0ef] = apr_profile_policy[f->profile].quant_index; + put_unaligned_le16(0xffff, desc + 0x0f0); + put_unaligned_le16(0xffff, desc + 0x0f2); + put_unaligned_le64(APR_RC_THRESHOLDS, desc + 0x0f4); + put_unaligned_le32(0x2c8080, desc + 0x0fc); + for (i = 0; i < ARRAY_SIZE(apr_rc_beta); i++) + put_unaligned_le32(apr_rc_beta[i], desc + 0x100 + 4 * i); + for (i = 0; i < 16; i++) + put_unaligned_le32(APR_RC_QUANT, desc + 0x110 + 4 * i); + put_unaligned_le32(table << 4 | 3, desc + 0x150); + return 0; +} +EXPORT_SYMBOL_IF_KUNIT(apr_build_desc_v0); + /* * A finished frame starts with its big-endian length, which counts the whole * frame, followed by the 'icpf' frame identifier. diff --git a/drivers/media/platform/apple/prores/apple-prores-drv.c b/drivers/media/platform/apple/prores/apple-prores-drv.c index 1fa95ce3bdbe6..9a45518d4814a 100644 --- a/drivers/media/platform/apple/prores/apple-prores-drv.c +++ b/drivers/media/platform/apple/prores/apple-prores-drv.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #define APR_TIMEOUT_MS 1000 #define APR_POLL_MS 4 #define APR_AUTOSUSPEND_MS 500 -#define APR_RING_ENTRIES (APR_RING_BYTES / APR_DESC_BYTES) struct apr_fmt { u32 fourcc; @@ -191,7 +191,114 @@ static const struct apr_tunable apr_t8140_wrapper_tunables[] = { { 0x401c, 0x00000001, 0x00000001 }, }; +/* + * T6000 constants: Copyright The Asahi Linux Contributors. + * MIT license: see m1n1-LICENSE. + * MIT m1n1 f3ac615eb1376d3bbba24cd84c414b9e41892adb, + * proxyclient/experiments/prores.py:42-89, in the published order. + * APR a0 has no wrapper or SCODEC-system initialization table. + */ +static const struct apr_tunable apr_t6000_engine_tunables[] = { + { 0x118, 0x07ff07ff, 0x00000600 }, + { 0x148, 0x00000001, 0x00000001 }, + { 0x160, 0x800f3fff, 0x800a04ff }, + { 0x164, 0x07ff07ff, 0x07800080 }, + { 0x170, 0x800f3fff, 0x800404ff }, + { 0x174, 0x07ff07ff, 0x06000080 }, + { 0x180, 0x800f3fff, 0x800504ff }, + { 0x184, 0x07ff07ff, 0x06800080 }, + { 0x190, 0x800f3fff, 0x800004ff }, + { 0x194, 0x000000ff, 0x00000040 }, + { 0x1a0, 0x800f3fff, 0x800104ff }, + { 0x1a4, 0x000000ff, 0x00000080 }, + { 0x1b0, 0x800f3fff, 0x800204ff }, + { 0x1b4, 0x000000ff, 0x00000040 }, + { 0x1c0, 0x800f3fff, 0x800304ff }, + { 0x1c4, 0x000000ff, 0x00000040 }, + { 0x1d0, 0xbc00ff86, 0xa4000786 }, + { 0x1d4, 0x000000ff, 0x00000020 }, + { 0x1d8, 0x000000ff, 0x000000ff }, + { 0x1dc, 0x00ffffff, 0x00928170 }, + { 0x270, 0x800f3fff, 0x800b08ff }, + { 0x274, 0x07ff07ff, 0x07000080 }, + { 0x280, 0xffffffc0, 0x00180000 }, + { 0x290, 0x800f3fff, 0x800004ff }, + { 0x294, 0x000000ff, 0x00000080 }, + { 0x2a0, 0x800f3fff, 0x800104ff }, + { 0x2a4, 0x000000ff, 0x00000080 }, + { 0x2b0, 0x800f3fff, 0x800204ff }, + { 0x2b4, 0x000000ff, 0x00000040 }, + { 0x2c0, 0x800f3fff, 0x800304ff }, + { 0x2c4, 0x000000ff, 0x00000040 }, + { 0x2d0, 0x802ff04c, 0x80070040 }, + { 0x2d4, 0x00000001, 0x00000000 }, + { 0x2d8, 0xffff0003, 0x00ff0003 }, + { 0x2e0, 0x07ff07ff, 0x06000040 }, + { 0x2f8, 0x802ff04c, 0x80081040 }, + { 0x2fc, 0x00000001, 0x00000000 }, + { 0x300, 0xffff0003, 0x00ff0003 }, + { 0x308, 0x07ff07ff, 0x06400040 }, + { 0x320, 0x802ff04c, 0x80092040 }, + { 0x324, 0x00000001, 0x00000000 }, + { 0x328, 0xffff0003, 0x00ff0003 }, + { 0x330, 0x07ff07ff, 0x06800040 }, + { 0x350, 0x800f3fff, 0x800b08ff }, + { 0x354, 0x07ff07ff, 0x076000a0 }, + { 0x360, 0xffffffc0, 0x00180000 }, + { 0x370, 0x800f3fff, 0x800604ff }, + { 0x374, 0x07ff07ff, 0x06c000a0 }, +}; + +struct apr_stats_regs { + u32 lo, hi, size; +}; + +/* Selected only by the DT compatible, before mapping any resources. */ +struct apr_variant { + int (*build_desc)(const struct apr_frame *f, u8 *desc); + struct apr_stats_regs stats[2]; + const struct apr_tunable *engine_tunables; + size_t num_engine_tunables; + const struct apr_tunable *wrapper_tunables; + size_t num_wrapper_tunables; + const char *reg_names[2]; + unsigned int num_regs; + unsigned int num_irqs; + u32 ring_bytes; + u32 desc_bytes; +}; + +static const struct apr_variant apr_t8140 = { + .build_desc = apr_build_desc, + .stats = { + { APR_REG_STATS0_LO, APR_REG_STATS0_HI, APR_REG_STATS0_SIZE }, + { APR_REG_STATS1_LO, APR_REG_STATS1_HI, APR_REG_STATS1_SIZE }, + }, + .engine_tunables = apr_t8140_engine_tunables, + .num_engine_tunables = ARRAY_SIZE(apr_t8140_engine_tunables), + .wrapper_tunables = apr_t8140_wrapper_tunables, + .num_wrapper_tunables = ARRAY_SIZE(apr_t8140_wrapper_tunables), + .reg_names = { "core", "wrapper" }, + .num_regs = 2, + .num_irqs = 2, + .ring_bytes = APR_RING_BYTES, + .desc_bytes = APR_DESC_BYTES, +}; + +static const struct apr_variant apr_t6000 = { + .build_desc = apr_build_desc_v0, + .stats = { { 0x278, 0x27c, 0x280 }, { 0x358, 0x35c, 0x360 } }, + .engine_tunables = apr_t6000_engine_tunables, + .num_engine_tunables = ARRAY_SIZE(apr_t6000_engine_tunables), + .reg_names = { "core", "wrapper" }, + .num_regs = 2, + .num_irqs = 1, + .ring_bytes = APR_RING_BYTES, + .desc_bytes = APR_DESC_BYTES, +}; + struct apr_dev { + const struct apr_variant *variant; struct device *dev; void __iomem *regs; void __iomem *wrapper; @@ -265,23 +372,24 @@ static void apr_apply(void __iomem *base, const struct apr_tunable *t, size_t n) static void apr_hw_init(struct apr_dev *apr) { + const struct apr_variant *v = apr->variant; unsigned int t, i; apr_write(apr, APR_REG_MODE, APR_MODE_OFF); apr_write(apr, APR_REG_IRQ_ENABLE, 0); - apr_apply(apr->regs, apr_t8140_engine_tunables, ARRAY_SIZE(apr_t8140_engine_tunables)); - apr_apply(apr->wrapper, apr_t8140_wrapper_tunables, - ARRAY_SIZE(apr_t8140_wrapper_tunables)); + apr_apply(apr->regs, v->engine_tunables, v->num_engine_tunables); + if (v->num_wrapper_tunables) + apr_apply(apr->wrapper, v->wrapper_tunables, v->num_wrapper_tunables); apr_write(apr, APR_REG_RING_HEAD, 0); apr_write(apr, APR_REG_RING_TAIL, 0); - apr_write(apr, APR_REG_RING_SIZE, APR_RING_BYTES); + apr_write(apr, APR_REG_RING_SIZE, v->ring_bytes); apr_write(apr, APR_REG_RING_LO, lower_32_bits(apr->ring_dma)); apr_write(apr, APR_REG_RING_HI, upper_32_bits(apr->ring_dma)); /* Both statistics consumers share one area. */ - apr_write(apr, APR_REG_STATS0_LO, lower_32_bits(apr->stats_dma) & ~0x3fU); - apr_write(apr, APR_REG_STATS0_HI, upper_32_bits(apr->stats_dma) & 0x3ff); - apr_write(apr, APR_REG_STATS1_LO, lower_32_bits(apr->stats_dma) & ~0x3fU); - apr_write(apr, APR_REG_STATS1_HI, upper_32_bits(apr->stats_dma) & 0x3ff); + for (i = 0; i < ARRAY_SIZE(v->stats); i++) { + apr_write(apr, v->stats[i].lo, lower_32_bits(apr->stats_dma) & ~0x3fU); + apr_write(apr, v->stats[i].hi, upper_32_bits(apr->stats_dma) & 0x3ff); + } apr_write(apr, APR_REG_MODE, APR_MODE_RUN); for (t = 0; t < APR_QTABLES; t++) { @@ -550,15 +658,15 @@ static void apr_device_run(void *priv) * The engine's ring wrap protocol is not known, so start again at the * beginning of the ring instead of wrapping. The engine is idle here. */ - if (!apr->ring_ready || apr->head + APR_DESC_BYTES > APR_RING_BYTES) + if (!apr->ring_ready || apr->head + apr->variant->desc_bytes > apr->variant->ring_bytes) apr_hw_init(apr); - ret = apr_build_desc(&f, apr->ring + apr->head); + ret = apr->variant->build_desc(&f, apr->ring + apr->head); if (ret) { spin_unlock_irqrestore(&apr->hw_lock, flags); apr_finish_job(apr, ctx, ret); return; } - apr->head += APR_DESC_BYTES; + apr->head += apr->variant->desc_bytes; apr->active = ctx; apr->started = jiffies; /* Descriptor and buffers must be visible before the head moves. */ @@ -1053,6 +1161,7 @@ static int apr_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct video_device *vdev; + void __iomem *regs[2] = {}; struct apr_dev *apr; unsigned int i; int ret; @@ -1061,17 +1170,22 @@ static int apr_probe(struct platform_device *pdev) if (!apr) return -ENOMEM; apr->dev = dev; + apr->variant = of_device_get_match_data(dev); + if (!apr->variant) + return -ENODEV; mutex_init(&apr->vdev_lock); spin_lock_init(&apr->hw_lock); INIT_DELAYED_WORK(&apr->watchdog, apr_watchdog); platform_set_drvdata(pdev, apr); - apr->regs = devm_platform_ioremap_resource_byname(pdev, "core"); - if (IS_ERR(apr->regs)) - return PTR_ERR(apr->regs); - apr->wrapper = devm_platform_ioremap_resource_byname(pdev, "wrapper"); - if (IS_ERR(apr->wrapper)) - return PTR_ERR(apr->wrapper); + for (i = 0; i < apr->variant->num_regs; i++) { + regs[i] = devm_platform_ioremap_resource_byname(pdev, + apr->variant->reg_names[i]); + if (IS_ERR(regs[i])) + return PTR_ERR(regs[i]); + } + apr->regs = regs[0]; + apr->wrapper = regs[1]; /* * A second power domain, "perf", is the SoC performance request the * engine needs for full speed. With more than one domain the core @@ -1098,7 +1212,7 @@ static int apr_probe(struct platform_device *pdev) ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (ret) return ret; - apr->ring = dmam_alloc_coherent(dev, APR_RING_BYTES, &apr->ring_dma, + apr->ring = dmam_alloc_coherent(dev, apr->variant->ring_bytes, &apr->ring_dma, GFP_KERNEL); if (!apr->ring) return -ENOMEM; @@ -1107,7 +1221,7 @@ static int apr_probe(struct platform_device *pdev) if (!apr->stats) return -ENOMEM; - for (i = 0; i < ARRAY_SIZE(apr->irq); i++) { + for (i = 0; i < apr->variant->num_irqs; i++) { apr->irq[i] = platform_get_irq_optional(pdev, i); if (apr->irq[i] == -ENXIO && i) continue; @@ -1142,7 +1256,8 @@ static int apr_probe(struct platform_device *pdev) if (ret < 0) return ret; /* The engine reports how much statistics space it writes. */ - if (max(apr_read(apr, APR_REG_STATS0_SIZE), apr_read(apr, APR_REG_STATS1_SIZE)) > + if (max(apr_read(apr, apr->variant->stats[0].size), + apr_read(apr, apr->variant->stats[1].size)) > apr->stats_size) { pm_runtime_put_autosuspend(dev); return dev_err_probe(dev, -EINVAL, "statistics area larger than %zu bytes\n", @@ -1172,7 +1287,8 @@ static void apr_remove(struct platform_device *pdev) } static const struct of_device_id apr_of_match[] = { - { .compatible = "apple,t8140-prores" }, + { .compatible = "apple,t6000-prores", .data = &apr_t6000 }, + { .compatible = "apple,t8140-prores", .data = &apr_t8140 }, { } }; MODULE_DEVICE_TABLE(of, apr_of_match); diff --git a/drivers/media/platform/apple/prores/apple-prores-test.c b/drivers/media/platform/apple/prores/apple-prores-test.c index 15d13ec0ada82..3e727ff0ae3dc 100644 --- a/drivers/media/platform/apple/prores/apple-prores-test.c +++ b/drivers/media/platform/apple/prores/apple-prores-test.c @@ -156,18 +156,104 @@ static void apr_test_desc_rejects(struct kunit *test) f = apr_test_frame(); f.profile = APR_PROFILE_4444; /* 4:2:2 input, 4:4:4 profile */ KUNIT_EXPECT_EQ(test, apr_build_desc(&f, d), -EINVAL); + KUNIT_EXPECT_EQ(test, apr_build_desc_v0(&f, d), -EINVAL); f = apr_test_frame(); f.luma_stride = 600; /* not a multiple of 64 */ KUNIT_EXPECT_EQ(test, apr_build_desc(&f, d), -EINVAL); + KUNIT_EXPECT_EQ(test, apr_build_desc_v0(&f, d), -EINVAL); f = apr_test_frame(); f.chroma_stride = 576; /* shorter than a row */ KUNIT_EXPECT_EQ(test, apr_build_desc(&f, d), -EINVAL); + KUNIT_EXPECT_EQ(test, apr_build_desc_v0(&f, d), -EINVAL); f = apr_test_frame(); f.width = 321; KUNIT_EXPECT_EQ(test, apr_build_desc(&f, d), -EINVAL); + KUNIT_EXPECT_EQ(test, apr_build_desc_v0(&f, d), -EINVAL); f = apr_test_frame(); f.output = 0; KUNIT_EXPECT_EQ(test, apr_build_desc(&f, d), -EINVAL); + KUNIT_EXPECT_EQ(test, apr_build_desc_v0(&f, d), -EINVAL); +} + +/* Legacy words from MIT m1n1 f3ac615eb137 experiments/prores.py:607-644. */ +static void apr_test_desc_v0(struct kunit *test) +{ + static const u32 legacy[] = { + 0xffffffff, 0x15100c0c, 0x80004020, 0x002c8080, + 0x00880080, 0x004e00c5, 0x009000d0, 0x00200122, + 0x00400200, 0x00400200, 0x00400200, 0x00400200, + 0x00400200, 0x00400200, 0x00400200, 0x00400200, + 0x00400200, 0x00400200, 0x00400200, 0x00400200, + 0x00400200, 0x00400200, 0x00400200, 0x00400200, 0x23, + }; + struct apr_frame f = apr_test_frame(); + u8 *d = kunit_kmalloc(test, APR_DESC_BYTES + 1, GFP_KERNEL); + unsigned int i; + + KUNIT_ASSERT_NOT_NULL(test, d); + memset(d, 0xa5, APR_DESC_BYTES + 1); + KUNIT_ASSERT_EQ(test, apr_build_desc_v0(&f, d), 0); + KUNIT_EXPECT_EQ(test, d[APR_DESC_BYTES], 0xa5); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d), 0x363b); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 4), 0); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(d + 8), f.output); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 0x10), f.output_size); + KUNIT_EXPECT_EQ(test, get_unaligned_le16(d + 0x18), 320); + KUNIT_EXPECT_EQ(test, get_unaligned_le16(d + 0x1a), 240); + KUNIT_EXPECT_EQ(test, get_unaligned_le16(d + 0x20), 10); + KUNIT_EXPECT_EQ(test, get_unaligned_le16(d + 0x22), 10); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(d + 0x28), f.luma); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(d + 0x38), f.chroma); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(d + 0x58), 148); + KUNIT_EXPECT_EQ(test, d[0x5b], 0); + KUNIT_EXPECT_MEMEQ(test, d + 0x5c, "aurr", 4); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(d + 0x60), 320); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(d + 0x62), 240); + KUNIT_EXPECT_EQ(test, d[0x64], 0x80); + KUNIT_EXPECT_EQ(test, d[0x65], 0); + KUNIT_EXPECT_EQ(test, d[0x66], f.primaries); + KUNIT_EXPECT_EQ(test, d[0x67], f.transfer); + KUNIT_EXPECT_EQ(test, d[0x68], f.matrix); + KUNIT_EXPECT_EQ(test, d[0x69], 0); + KUNIT_EXPECT_EQ(test, d[0x6a], 0); + KUNIT_EXPECT_EQ(test, d[0x6b], 3); + for (i = 0x6c; i < 0xee; i++) + KUNIT_EXPECT_EQ_MSG(test, d[i], 0, "padding/slices %#x", i); + KUNIT_EXPECT_EQ(test, d[0xee], 0x30); + KUNIT_EXPECT_EQ(test, d[0xef], 2); + for (i = 0; i < ARRAY_SIZE(legacy); i++) + KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(d + 0xf0 + 4 * i), + legacy[i], "legacy word %u", i); + for (i = 0x154; i < APR_DESC_BYTES; i++) + KUNIT_EXPECT_EQ_MSG(test, d[i], 0, "v0 trailing padding %#x", i); + + /* Reusing the buffer for v1 must clear the old frame header. */ + KUNIT_ASSERT_EQ(test, apr_build_desc(&f, d), 0); + KUNIT_EXPECT_EQ(test, get_unaligned_le64(d + 0x58), 0); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(d + 0x7c), 148); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 0x170), 0x23); +} + +static void apr_test_desc_v0_profiles(struct kunit *test) +{ + struct apr_frame f = apr_test_frame(); + u8 *d = kunit_kmalloc(test, APR_DESC_BYTES, GFP_KERNEL); + unsigned int profile; + + KUNIT_ASSERT_NOT_NULL(test, d); + for (profile = 0; profile < APR_PROFILES; profile++) { + bool is444 = apr_profile_is_444(profile); + + f.profile = profile; + f.input = is444 ? APR_INPUT_444_8 : APR_INPUT_422_16; + KUNIT_ASSERT_EQ(test, apr_build_desc_v0(&f, d), 0); + KUNIT_EXPECT_EQ(test, d[0x5b], is444 ? 1 : 0); + KUNIT_EXPECT_EQ(test, d[0x64], is444 ? 0xc0 : 0x80); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 0x150), + apr_profile_qtable(profile) << 4 | 3); + /* The v1 extension is never written into a v0 descriptor. */ + KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 0x170), 0); + } } static void apr_test_budgets(struct kunit *test) @@ -251,6 +337,8 @@ static struct kunit_case apr_test_cases[] = { KUNIT_CASE(apr_test_desc_422), KUNIT_CASE(apr_test_desc_444), KUNIT_CASE(apr_test_desc_rejects), + KUNIT_CASE(apr_test_desc_v0), + KUNIT_CASE(apr_test_desc_v0_profiles), KUNIT_CASE(apr_test_budgets), KUNIT_CASE(apr_test_slices), KUNIT_CASE(apr_test_output), diff --git a/drivers/media/platform/apple/prores/apple-prores.h b/drivers/media/platform/apple/prores/apple-prores.h index 114b52ac76b89..d41fbdeff9e46 100644 --- a/drivers/media/platform/apple/prores/apple-prores.h +++ b/drivers/media/platform/apple/prores/apple-prores.h @@ -117,6 +117,7 @@ void apr_frame_budget(enum apr_profile profile, u32 width, u32 height, u32 *target, u32 *max); u32 apr_slice_count(u32 width, u32 height, u32 log2_slice); int apr_build_desc(const struct apr_frame *f, u8 *desc); +int apr_build_desc_v0(const struct apr_frame *f, u8 *desc); int apr_check_output(const u8 *out, size_t capacity, u32 *frame_bytes); #endif diff --git a/drivers/media/platform/apple/prores/m1n1-LICENSE b/drivers/media/platform/apple/prores/m1n1-LICENSE new file mode 100644 index 0000000000000..aff0557da45ae --- /dev/null +++ b/drivers/media/platform/apple/prores/m1n1-LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright The Asahi Linux Contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/drivers/media/platform/apple/prores/t6000-qualification.rst b/drivers/media/platform/apple/prores/t6000-qualification.rst new file mode 100644 index 0000000000000..b9a4ace694c4b --- /dev/null +++ b/drivers/media/platform/apple/prores/t6000-qualification.rst @@ -0,0 +1,105 @@ +T6000 APR a0 qualification +========================= + +This port describes an encoder, not a decoder. The APR and its DART remain +disabled in the shipped DT. Compile and descriptor tests do not qualify +silicon operation, DMA quiescence, output quality or rate control. + +Implementation sources +---------------------- + +The generation/resource contract is t-5068's CLEANROOM.md (2026-11-07). +The licensed implementation source is MIT m1n1 commit +f3ac615eb1376d3bbba24cd84c414b9e41892adb: + +* ``proxyclient/experiments/prores.py:42-89``: all 48 core RMWs, in order. +* ``proxyclient/m1n1/hw/prores.py:7-111``: the v0 descriptor layout. +* ``proxyclient/experiments/prores.py:592-644``: legacy header, slice and + rate-control words. The v0 builder retains the two public 0xffff limits; + it does not assign them v1 coefficient-budget semantics. Profile matrices + and initial quantisers follow the existing driver's policy, but profile + bitrate/quality equivalence remains to be measured on v0. + +The MIT notice for the adapted constants is retained in ``m1n1-LICENSE``. +T6000 selects neither wrapper nor SCODEC-system writes. It has no BWR entry; +this port adds no DCS floor. T6041/J616s resources and initialization are +outside this implementation. + +Prerequisites to first DMA +------------------------- + +1. Use an approved controller request explicitly identifying ``m1pro`` + (T6000/J316s), the exact kernel and DTB-set hashes, source ownership and + the existing boot fallback. No target access is needed for this patch. +2. Land the DMA-ownership repair described by Linux PR #925, or a reviewed + equivalent: an uncertain completion or failed reset must retain buffers, + mappings, runtime PM, scheduler ownership and the fixed platform device. + The base driver is not qualified for an intentional hang/reset test. +3. Qualify the PMP report provider's update aperture and a narrow allow-list + for entry 0x115. The disabled report@14 describes level 2, but the provider + at this patch's base cannot admit that update. Require physical SCODEC + residency, record-20 request/ACK, then level 2 before starting APR. Publish + level 0 before releasing record 20 or SCODEC. Never replace this with an + unmeasured bandwidth or DCS vote. +4. Prepare a J316s-only trial DTB enabling ``apr0_dart``, ``apr0`` and + ``pmp_report_scodec`` after the provider prerequisite is met. Preserve + other boards' disabled nodes. Check SID 0, the DART aperture and the + firmware DVA window 0x4000 + 0xfffe00000; verify every DMA mapping fits. + Record the APR ID/version and confirm the expected a0/v0 engine before + submitting a descriptor. The ID must never select a different generation. + +Boot the actual DTB set +----------------------- + +The M1 Pro obtains its DTBs from ``boot.bin``, not from the kernel package's +loose DTB. Use lane DT2's refmac DTB-set trial procedure in +``kits/aura/20261107-refmac-dtb-int/README.md``. Freeze the complete trial set +and its manifest, incorporating the J316s trial DTB. Preserve the known-good +production set and ``boot.bin`` backup. + +Run the recipe's status/reproduction checks, stage, enable the trial guard, +arm a one-shot and reboot through the approved controller operation. Confirm +``chosen/aurora,trial``, the running APR/DART/report properties, the DTB hash, +and a successfully armed trial watchdog before DMA. Keep bootguard fallback +and the trial watchdog throughout. Preserve the reference-Mac regression +results required by DT2. This patch does not authorize making the trial set +permanent. On failure use the spent-marker fallback and the kit's clean or +rollback procedure, preserving the failed trial evidence. + +Bounded first job +----------------- + +* Keep the normal speaker protection service governing; this test is silent. +* Allocate a coherent 128 KiB ring, a coherent 2 MiB statistics area and one + contiguous P216 input: 320x240, Y/C strides 640 bytes, padded to whole + 16-row macroblocks. Use one CAPTURE buffer of at least 4 MiB, with guard + mappings where supported. Submit one Standard 4:2:2 frame only. +* With MODE OFF and IRQs masked, apply exactly the public 48 core RMWs. + Install ring size/IOVA with head and tail zero. Use statistics consumers at + 0x278/0x27c and 0x358/0x35c, checking capacities 0x280/0x360 against the + allocation after initialization as well as at probe. Set RUN, program + matrices/DC scale, clear stale status and enable DONE|ERROR. +* Inspect the v0 descriptor before publication: frame header at 0x58, + deprecated slice count zero at 0xec, slice/quantiser at 0xee/0xef, public + legacy words at 0xf0..0x14f, matrix selector 0x23 at 0x150, zero trailing + bytes. Zero the first eight output bytes, execute dma_wmb(), then publish + head 0x180. Start the existing one-second watchdog; do not auto-retry. +* Accept only DONE with tail low 24 bits 0x180. After the sampled W1C ACK and + tail readback, execute dma_rmb(). Require a bounded big-endian frame length + and ``icpf`` signature. Software-decode exactly that frame and check + 320x240 dimensions, 4:2:2/header colour codes, Standard matrix selection, + and decoded pixels against the synthetic source using a recorded error + metric. ProRes is lossy; do not require raw-source byte equality. +* On timeout, ERROR, unexpected tail or a DART fault, collect bounded status, + head/tail, IRQ, DART and PMP request/ACK evidence. Mask IRQs, request the + qualified reset and retain DMA ownership until quiescence is proven. An + unproven reset requires retained resources and the boot fallback, never a + second submission or freeing memory still reachable by DMA. + +Retain source/DTB hashes, descriptor bytes, test input/output hashes, decoded +metrics, IRQ timing, reset outcome and rollback result in the qualification +record. Publish only reviewed, non-identifying extracts. A first-job pass +still leaves cancellation, runtime/system suspend, failed-reset retention, +all four input formats, all profiles and dimensions, ring reinitialization +at capacity, and repeated-job completion to qualify. Keep one in-flight job; +ring wrap and batching require separate evidence before expanding that limit. From db20caf5331eba6b75a4a2a018fd4da9d9913307 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 03:56:57 +1100 Subject: [PATCH 027/342] media: apple-prores: match the normalized compatible array in binding Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/devicetree/bindings/media/apple,prores.yaml | 3 ++- drivers/media/platform/apple/prores/apple-prores-drv.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/media/apple,prores.yaml b/Documentation/devicetree/bindings/media/apple,prores.yaml index d86e956b4a7f4..09f17161eb200 100644 --- a/Documentation/devicetree/bindings/media/apple,prores.yaml +++ b/Documentation/devicetree/bindings/media/apple,prores.yaml @@ -76,7 +76,8 @@ allOf: - if: properties: compatible: - const: apple,t6000-prores + contains: + const: apple,t6000-prores then: properties: interrupts: diff --git a/drivers/media/platform/apple/prores/apple-prores-drv.c b/drivers/media/platform/apple/prores/apple-prores-drv.c index 9a45518d4814a..e74a3ae09919b 100644 --- a/drivers/media/platform/apple/prores/apple-prores-drv.c +++ b/drivers/media/platform/apple/prores/apple-prores-drv.c @@ -658,7 +658,8 @@ static void apr_device_run(void *priv) * The engine's ring wrap protocol is not known, so start again at the * beginning of the ring instead of wrapping. The engine is idle here. */ - if (!apr->ring_ready || apr->head + apr->variant->desc_bytes > apr->variant->ring_bytes) + if (!apr->ring_ready || + apr->head + apr->variant->desc_bytes > apr->variant->ring_bytes) apr_hw_init(apr); ret = apr->variant->build_desc(&f, apr->ring + apr->head); if (ret) { @@ -1180,7 +1181,7 @@ static int apr_probe(struct platform_device *pdev) for (i = 0; i < apr->variant->num_regs; i++) { regs[i] = devm_platform_ioremap_resource_byname(pdev, - apr->variant->reg_names[i]); + apr->variant->reg_names[i]); if (IS_ERR(regs[i])) return PTR_ERR(regs[i]); } From bbc26268524fa53c1e7730b8822025b87caa3eea Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 04:01:41 +1100 Subject: [PATCH 028/342] docs: media: mark the T6000 qualification plan license Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/media/platform/apple/prores/t6000-qualification.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/apple/prores/t6000-qualification.rst b/drivers/media/platform/apple/prores/t6000-qualification.rst index b9a4ace694c4b..14c4da6977c68 100644 --- a/drivers/media/platform/apple/prores/t6000-qualification.rst +++ b/drivers/media/platform/apple/prores/t6000-qualification.rst @@ -1,3 +1,5 @@ +.. SPDX-License-Identifier: GPL-2.0-only + T6000 APR a0 qualification ========================= From 54485c922f72eeb4dfcad88f144117c70ef45f61 Mon Sep 17 00:00:00 2001 From: Friedrich <261542475+aeries0x@users.noreply.github.com> Date: Sun, 8 Nov 2026 01:06:01 +0100 Subject: [PATCH 029/342] soc: apple: t8132: describe the CIO PMGR in the platform data Every T8132 tree carries pmgr_cio (t8132-usb4.dtsi). The platform data describes only pmgr and pmgr_mini, so t8132_pmgr_policy() cannot resolve pmgr_cio and fails the whole handoff: t8132-platform-handoff: cannot resolve PMGR policy for /soc/power-management@380780000: -1 Since the policy runs on the qualified firmware of every M4 Mac, a tree that leaves its domain status to the policy then has none: on the J604 65 domains fail closed with "missing M4 power-domain policy", and the NVMe mailbox, serial, IOMMUs and PMP never probe. The J713 tree reaches the same error but states every domain itself. Describe pmgr_cio in the data. It has no power-state domains, so the policy is unchanged and an undescribed PMGR still fails closed. On the J604 the handoff then reports "supplied 0 platform nodes, 140 PMGR policy properties" and the system boots to the login screen. Fixes: ce5aebdff7ce ("arm64: dts: apple: t8132, j713: describe the USB4 host routers") Assisted-by: LLM Signed-off-by: Friedrich <261542475+aeries0x@users.noreply.github.com> --- drivers/soc/apple/t8132-platform-data.dts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/apple/t8132-platform-data.dts b/drivers/soc/apple/t8132-platform-data.dts index 52d97f73b81b3..13edfc1b94b44 100644 --- a/drivers/soc/apple/t8132-platform-data.dts +++ b/drivers/soc/apple/t8132-platform-data.dts @@ -17,6 +17,13 @@ reg = <0x3 0x80700000 0 0x14000>; }; + /* Describes no domain; resolves the CIO PMGR the SoC tree carries. */ + pmgr_cio: power-management@380780000 { + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x80780000 0 0x4000>; + }; + pmgr_mini: power-management@388280000 { #address-cells = <1>; #size-cells = <1>; From e0815b436112837cc46bf67fc6d3655f65107991 Mon Sep 17 00:00:00 2001 From: Friedrich <261542475+aeries0x@users.noreply.github.com> Date: Sun, 8 Nov 2026 01:06:02 +0100 Subject: [PATCH 030/342] arm64: dts: apple: t8132-j604: drop the boot framebuffer's power domains The boot framebuffer (t8132-jxxx.dtsi) lists ps_disp_fe and ps_dptx_phy. The M4 PMGR policy disables ps_dptx_phy, so simpledrm waits for it until the deferred probe timeout: simple-framebuffer 103e0126880.framebuffer: [drm] pm_domain_attach_by_id(1) failed: -110 and the J604 shows no console for the first ~16 s. Delete the property, as the J713 tree does (t8132-j713-j715.dtsi). Assisted-by: LLM Signed-off-by: Friedrich <261542475+aeries0x@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8132-j604.dts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j604.dts b/arch/arm64/boot/dts/apple/t8132-j604.dts index 8c86b23bf92ef..09a2730f1c442 100644 --- a/arch/arm64/boot/dts/apple/t8132-j604.dts +++ b/arch/arm64/boot/dts/apple/t8132-j604.dts @@ -80,6 +80,14 @@ apple,panel-height-mm = <196>; }; +/* + * The M4 PMGR policy disables ps_dptx_phy, which the shared boot + * framebuffer lists; as on the J713, the loader keeps the display on. + */ +&framebuffer0 { + /delete-property/ power-domains; +}; + &sound_jack { compatible = "apple,j604-macaudio-jack", "apple,macaudio"; model = "MacBook Pro J604 Jack"; From 8c6f00312eaf1dd6e5295ba352f37596f7adf892 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 15:29:11 +1100 Subject: [PATCH 031/342] soc: apple: sep: add /dev/sep-key for P-256 keys that stay in the SEP Add a character device that creates P-256 keys inside the Secure Enclave's key store and signs digests with them. Each key is an enclave ref-key bound to this SEP and to the Linux identity key bag; the private key never leaves the enclave. Userspace gets an opaque handle (a short versioned header plus the enclave's wrapped record) that only this Mac can use, and the public point. ioctls (magic 0xB1, nr 0x20-0x23): SEP_KEY_GET_INFO, SEP_KEY_CREATE, SEP_KEY_SIGN (ECDSA-P256 over a caller-supplied 32-byte digest, DER signature) and SEP_KEY_PUBLIC (point from a handle, no enclave round trip). Each enclave operation loads and unlocks the identity key bag the way a trusted-key unseal does and unloads it afterwards. Version 1 has no access control: every flags field must be zero and is reserved for an enclave-enforced policy. A handle the enclave does not accept (another Mac, another key bag) fails with EKEYREJECTED, so the ref-key sign helper now reports the enclave's refusal separately from a missing or malformed reply. KUnit covers the handle format and the reply bounds. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/key.rs | 338 +++++++++++++++++++++++++++++++++ drivers/soc/apple/refkey.rs | 96 ++++++++-- drivers/soc/apple/sbio.rs | 8 + drivers/soc/apple/sep.rs | 8 + include/uapi/linux/apple-sep.h | 63 ++++++ 5 files changed, 500 insertions(+), 13 deletions(-) create mode 100644 drivers/soc/apple/key.rs diff --git a/drivers/soc/apple/key.rs b/drivers/soc/apple/key.rs new file mode 100644 index 0000000000000..d92d50716cc03 --- /dev/null +++ b/drivers/soc/apple/key.rs @@ -0,0 +1,338 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +// Copyright 2026 Ryan Murray +//! `/dev/sep-key`: P-256 keys created inside the SEP. +//! +//! Each key is an enclave ref-key bound to this SEP and to the Linux identity +//! key bag. Its private half never leaves the enclave; userspace holds only a +//! key handle, the wrapped ref-key record behind a small versioned header. +//! A handle works on the Mac that created it and nowhere else. Signing takes a +//! 32-byte digest and returns a DER `ECDSA-Sig-Value`. +//! +//! There is no access control in this version: anyone who can open the node +//! and holds a handle can sign with it. The `flags` words are reserved for an +//! enclave-enforced policy and must be zero. + +use crate::SepData; +use kernel::ioctl::{_IOR, _IOWR}; +use kernel::prelude::*; +use kernel::sync::atomic::Relaxed; +use kernel::uaccess::{UserPtr, UserSlice}; + +pub(crate) const DEVICE_NAME: &CStr = c"sep-key"; +/// Root only by default; distributions grant a group with a udev rule. +pub(crate) const DEVICE_MODE: u16 = 0o600; + +pub(crate) const IFACE_VERSION: u32 = 1; + +pub(crate) const HANDLE_MAX: usize = 2048; +pub(crate) const PUB_LEN: usize = 65; +pub(crate) const DIGEST_LEN: usize = 32; +pub(crate) const SIG_MAX: usize = 72; + +const MAGIC: u32 = 0xB1; + +/// Handle header: `"SEPK"`, version, flags, reserved u16, blob length (LE u32). +const HANDLE_MAGIC: &[u8; 4] = b"SEPK"; +const HANDLE_VERSION: u8 = 1; +pub(crate) const HANDLE_HEADER: usize = 12; +/// The largest enclave record a handle can carry. +pub(crate) const BLOB_MAX: usize = HANDLE_MAX - HANDLE_HEADER; + +#[repr(C)] +pub(crate) struct Info { + pub(crate) version: u32, + /// `flags` bits `CREATE` and `SIGN` accept; zero in this version. + pub(crate) flags_supported: u32, + pub(crate) handle_max: u32, + pub(crate) reserved: u32, +} + +#[repr(C)] +pub(crate) struct Create { + pub(crate) flags: u32, + pub(crate) handle_len: u32, + pub(crate) public_key: [u8; PUB_LEN], + pub(crate) reserved: [u8; 3], + pub(crate) handle: [u8; HANDLE_MAX], +} + +#[repr(C)] +pub(crate) struct Sign { + pub(crate) flags: u32, + pub(crate) handle_len: u32, + pub(crate) digest: [u8; DIGEST_LEN], + pub(crate) sig_len: u32, + pub(crate) signature: [u8; SIG_MAX], + pub(crate) handle: [u8; HANDLE_MAX], +} + +#[repr(C)] +pub(crate) struct Public { + pub(crate) flags: u32, + pub(crate) handle_len: u32, + pub(crate) public_key: [u8; PUB_LEN], + pub(crate) reserved: [u8; 3], + pub(crate) handle: [u8; HANDLE_MAX], +} + +static_assert!(core::mem::size_of::() == 16); +static_assert!(core::mem::size_of::() == 2124); +static_assert!(core::mem::size_of::() == 2164); +static_assert!(core::mem::size_of::() == 2124); + +// SAFETY: `repr(C)` with no padding (the asserts above), so each value is a +// faithful byte image and every bit pattern is a valid value. +unsafe impl kernel::transmute::AsBytes for Info {} +// SAFETY: as above. +unsafe impl kernel::transmute::AsBytes for Create {} +// SAFETY: as above. +unsafe impl kernel::transmute::FromBytes for Create {} +// SAFETY: as above. +unsafe impl kernel::transmute::AsBytes for Sign {} +// SAFETY: as above. +unsafe impl kernel::transmute::FromBytes for Sign {} +// SAFETY: as above. +unsafe impl kernel::transmute::AsBytes for Public {} +// SAFETY: as above. +unsafe impl kernel::transmute::FromBytes for Public {} + +pub(crate) const IOC_INFO: u32 = _IOR::(MAGIC, 0x20); +pub(crate) const IOC_CREATE: u32 = _IOWR::(MAGIC, 0x21); +pub(crate) const IOC_SIGN: u32 = _IOWR::(MAGIC, 0x22); +pub(crate) const IOC_PUBLIC: u32 = _IOWR::(MAGIC, 0x23); + +pub(crate) fn info() -> Info { + Info { + version: IFACE_VERSION, + flags_supported: 0, + handle_max: HANDLE_MAX as u32, + reserved: 0, + } +} + +/// Writes the handle for `blob` into `out`; returns its length. +pub(crate) fn encode_handle(blob: &[u8], out: &mut [u8; HANDLE_MAX]) -> Result { + if blob.is_empty() || blob.len() > BLOB_MAX { + return Err(EINVAL); + } + let len = u32::try_from(blob.len()).map_err(|_| EINVAL)?; + out.fill(0); + out[..4].copy_from_slice(HANDLE_MAGIC); + out[4] = HANDLE_VERSION; + out[5] = 0; + out[8..12].copy_from_slice(&len.to_le_bytes()); + out[HANDLE_HEADER..HANDLE_HEADER + blob.len()].copy_from_slice(blob); + Ok(HANDLE_HEADER + blob.len()) +} + +/// The enclave record inside the first `len` bytes of `handle`. Refuses an +/// unknown version, any flag, a non-zero reserved field or a length that does +/// not match exactly. +pub(crate) fn decode_handle(handle: &[u8; HANDLE_MAX], len: u32) -> Result<&[u8]> { + let len = len as usize; + if !(HANDLE_HEADER + 1..=HANDLE_MAX).contains(&len) { + return Err(EINVAL); + } + if &handle[..4] != HANDLE_MAGIC || handle[4] != HANDLE_VERSION || handle[5] != 0 { + return Err(EINVAL); + } + if handle[6] != 0 || handle[7] != 0 { + return Err(EINVAL); + } + let blob_len = u32::from_le_bytes([handle[8], handle[9], handle[10], handle[11]]) as usize; + if blob_len != len - HANDLE_HEADER { + return Err(EINVAL); + } + Ok(&handle[HANDLE_HEADER..len]) +} + +/// Copies a DER signature into the reply; refuses one that does not fit. +pub(crate) fn put_signature(sig: &[u8], out: &mut Sign) -> Result<()> { + if sig.is_empty() || sig.len() > SIG_MAX { + return Err(EIO); + } + out.signature.fill(0); + out.signature[..sig.len()].copy_from_slice(sig); + out.sig_len = sig.len() as u32; + Ok(()) +} + +#[::kernel::macros::kunit_tests(apple_sep_key_handle)] +mod tests { + use super::*; + + fn blob() -> [u8; 100] { + let mut b = [0u8; 100]; + for (i, v) in b.iter_mut().enumerate() { + *v = i as u8 ^ 0x5a; + } + b + } + + #[test] + fn round_trip() { + let mut h = [0u8; HANDLE_MAX]; + let n = encode_handle(&blob(), &mut h).unwrap(); + assert_eq!(n, HANDLE_HEADER + 100); + assert_eq!(&h[..4], b"SEPK"); + assert_eq!(decode_handle(&h, n as u32).unwrap(), &blob()[..]); + } + + #[test] + fn length_must_match_exactly() { + let mut h = [0u8; HANDLE_MAX]; + let n = encode_handle(&blob(), &mut h).unwrap() as u32; + assert!(decode_handle(&h, n - 1).is_err()); + assert!(decode_handle(&h, n + 1).is_err()); + assert!(decode_handle(&h, 0).is_err()); + assert!(decode_handle(&h, HANDLE_MAX as u32 + 1).is_err()); + } + + #[test] + fn header_fields_are_checked() { + let mut h = [0u8; HANDLE_MAX]; + let n = encode_handle(&blob(), &mut h).unwrap() as u32; + for at in [0usize, 4, 5, 6, 7] { + let mut bad = h; + bad[at] ^= 0x01; + assert!(decode_handle(&bad, n).is_err()); + } + } + + #[test] + fn empty_and_oversize_blobs_are_refused() { + let mut h = [0u8; HANDLE_MAX]; + assert!(encode_handle(&[], &mut h).is_err()); + let big = [1u8; BLOB_MAX + 1]; + assert!(encode_handle(&big, &mut h).is_err()); + let max = [1u8; BLOB_MAX]; + assert_eq!(encode_handle(&max, &mut h).unwrap(), HANDLE_MAX); + } + + #[test] + fn signature_bounds() { + let mut s = Sign { + flags: 0, + handle_len: 0, + digest: [0; DIGEST_LEN], + sig_len: 0, + signature: [0; SIG_MAX], + handle: [0; HANDLE_MAX], + }; + assert!(put_signature(&[], &mut s).is_err()); + assert!(put_signature(&[0x30; SIG_MAX + 1], &mut s).is_err()); + put_signature(&[0x30, 0x02, 0x01, 0x01], &mut s).unwrap(); + assert_eq!(s.sig_len, 4); + } +} + +impl SepData { + pub(crate) fn register_key(&self) -> Result<()> { + let mut guard = self.key_dev.lock(); + if guard.is_some() { + return Ok(()); + } + let ctx = core::ptr::from_ref(self).cast_mut().cast::(); + // SAFETY: as in `register_bio`: `remove()` drops the registration + // before the `Arc` that keeps `ctx` alive, and the shim's unregister + // clears the stored context under the lock every callback takes. + let dev = unsafe { + crate::shim::BioChardev::register( + DEVICE_NAME, + DEVICE_MODE, + ctx, + key_open_trampoline, + key_release_trampoline, + key_ioctl_trampoline, + key_ready_trampoline, + ) + }?; + *guard = Some(dev); + Ok(()) + } + + fn key_ioctl(&self, cmd: u32, arg: usize) -> Result<()> { + if self.shutting_down.load(Relaxed) { + return Err(ENODEV); + } + let user = UserPtr::from_addr(arg); + match cmd { + IOC_INFO => UserSlice::new(user, core::mem::size_of::()) + .writer() + .write(&info()), + IOC_CREATE => { + let slice = UserSlice::new(user, core::mem::size_of::()); + let (mut reader, mut writer) = slice.reader_writer(); + let mut req: Create = reader.read()?; + if req.flags != 0 || req.reserved != [0; 3] { + return Err(EINVAL); + } + let (blob, point) = self.user_key_create()?; + req.handle_len = encode_handle(&blob, &mut req.handle)? as u32; + req.public_key = point; + writer.write(&req) + } + IOC_SIGN => { + let slice = UserSlice::new(user, core::mem::size_of::()); + let (mut reader, mut writer) = slice.reader_writer(); + let mut req: Sign = reader.read()?; + if req.flags != 0 { + return Err(EINVAL); + } + let sig = { + let blob = decode_handle(&req.handle, req.handle_len)?; + self.user_key_sign(blob, &req.digest)? + }; + put_signature(&sig, &mut req)?; + writer.write(&req) + } + IOC_PUBLIC => { + let slice = UserSlice::new(user, core::mem::size_of::()); + let (mut reader, mut writer) = slice.reader_writer(); + let mut req: Public = reader.read()?; + if req.flags != 0 || req.reserved != [0; 3] { + return Err(EINVAL); + } + req.public_key = + SepData::user_key_public(decode_handle(&req.handle, req.handle_len)?)?; + writer.write(&req) + } + _ => Err(ENOTTY), + } + } +} + +// /dev/sep-key has no session: any number of openers, no poll. + +/// # Safety +/// `ctx` is the `SepData` pointer given to `register_key`, valid while the +/// registration lives (see `register_key`). +unsafe extern "C" fn key_open_trampoline(ctx: *mut c_void) -> c_int { + // SAFETY: per the contract above. + let this = unsafe { &*ctx.cast::() }; + if this.shutting_down.load(Relaxed) { + return ENODEV.to_errno(); + } + 0 +} + +/// # Safety +/// As for `key_open_trampoline`. +unsafe extern "C" fn key_release_trampoline(_ctx: *mut c_void) {} + +/// # Safety +/// As for `key_open_trampoline`. +unsafe extern "C" fn key_ioctl_trampoline(ctx: *mut c_void, cmd: c_uint, arg: c_ulong) -> c_long { + // SAFETY: per the contract above. + let this = unsafe { &*ctx.cast::() }; + match this.key_ioctl(cmd, arg) { + Ok(()) => 0, + Err(e) => e.to_errno() as c_long, + } +} + +/// # Safety +/// As for `key_open_trampoline`. +unsafe extern "C" fn key_ready_trampoline(_ctx: *mut c_void) -> c_int { + 0 +} diff --git a/drivers/soc/apple/refkey.rs b/drivers/soc/apple/refkey.rs index e505fb8d03bea..f1c60a815f60b 100644 --- a/drivers/soc/apple/refkey.rs +++ b/drivers/soc/apple/refkey.rs @@ -309,37 +309,44 @@ impl SepData { } /// Op `osgn`: ECDSA-P256 over `challenge` as the pre-computed digest. + /// `EKEYREJECTED` when the enclave refuses the operation (for example a + /// ref-key record another SEP or another key bag made), `EIO` for no or + /// a malformed reply. fn sks_refkey_sign( &self, handle: crate::sks::KeyBagHandle, refkey_blob: &[u8], challenge: &[u8], - ) -> Option> { + ) -> Result> { use crate::der::RefKeyValue as RV; let mut items: KVec<(&[u8], RV<'_>)> = KVec::new(); - items.push((b"o", RV::Utf8(b"osgn")), GFP_KERNEL).ok()?; - items.push((b"d", RV::Octets(challenge)), GFP_KERNEL).ok()?; - items.push((b"rk", RV::Der(refkey_blob)), GFP_KERNEL).ok()?; - let der = crate::der::encode_refkey_set(&items).ok()?; - let out = self.sks_send(self.sks_req_refkey(handle.value(), &der))?; + items.push((b"o", RV::Utf8(b"osgn")), GFP_KERNEL)?; + items.push((b"d", RV::Octets(challenge)), GFP_KERNEL)?; + items.push((b"rk", RV::Der(refkey_blob)), GFP_KERNEL)?; + let der = crate::der::encode_refkey_set(&items)?; + let out = self + .sks_send(self.sks_req_refkey(handle.value(), &der)) + .ok_or(EIO)?; if out.reply.status != 0 { dev_warn!( self.dev, - "sks: ref-key attest sign failed (status {})\n", + "sks: ref-key sign refused by the enclave (status {})\n", out.reply.status ); - return None; + return Err(EKEYREJECTED); } - let body = self.sks_report_response(crate::sks::SKS_PERFORM_OP_NAME, &out)?; + let body = self + .sks_report_response(crate::sks::SKS_PERFORM_OP_NAME, &out) + .ok_or(EIO)?; let mut f = proto::FieldCursor::new(body); let (Some(0), Some(sig)) = (f.i32(), f.blob()) else { - return None; + return Err(EIO); }; // Enclave wraps the sig in OCTET STRING { SEQUENCE { r, s } }; strip to inner DER. let der_sig = crate::der::octet_string_body(sig).unwrap_or(sig); let mut owned: KVec = KVec::new(); - owned.extend_from_slice(der_sig, GFP_KERNEL).ok()?; - Some(owned) + owned.extend_from_slice(der_sig, GFP_KERNEL)?; + Ok(owned) } /// Attestation of key possession by signing proof; op `oa` (attestation-chained) @@ -371,7 +378,70 @@ impl SepData { }); let sig = self.sks_refkey_sign(handle, &blob, challenge); let _ = self.sks_send(self.sks_req_unload_keybag(handle)); - Ok((sig.ok_or(EIO)?, pubk)) + Ok((sig?, pubk)) + } + + /// Runs `op` with the identity key bag loaded and unlocked, as a trusted + /// key unseal does, and unloads the bag afterwards whatever `op` returns. + fn with_identity_bag( + &self, + op: impl FnOnce(crate::sks::KeyBagHandle, &[u8]) -> Result, + ) -> Result { + self.wait_for_trusted_ready()?; + let keybag::State::Present(stored) = keybag::read(keybag::Slot::Identity)? else { + return Err(ENODEV); + }; + let (handle, _uuid) = self.sks_recover(&stored).ok_or(EIO)?; + let unlocked = crate::xart_guard::policy_window(|| { + if self.profile.key_store == profile::KeyStore::Variant5 { + if let Some(healthy) = self.sks_health_check(c"sep-key unlock") { + let _ = self.sks_send(self.sks_req_change_lock_state( + handle, + LockState::Unlocked, + stored.secret(), + healthy, + )); + } + true + } else { + self.sks_prepare_identity_refkey(handle, stored.secret()) + } + }); + let result = if unlocked { + op(handle, stored.secret()) + } else { + Err(EIO) + }; + let _ = self.sks_send(self.sks_req_unload_keybag(handle)); + result + } + + /// `/dev/sep-key` create: a new enclave P-256 ref-key under the identity + /// key bag. Returns its record and public point; the private half stays + /// in the enclave. + pub(crate) fn user_key_create(&self) -> Result<(KVec, [u8; refkey_seal::POINT_LEN])> { + let blob = self.with_identity_bag(|handle, secret| { + self.sks_create_refkey(handle, secret).ok_or(EIO) + })?; + let mut point = [0u8; refkey_seal::POINT_LEN]; + point.copy_from_slice(Self::refkey_pub(&blob).ok_or(EIO)?); + Ok((blob, point)) + } + + /// The public point recorded in a ref-key record; no enclave round trip. + pub(crate) fn user_key_public(blob: &[u8]) -> Result<[u8; refkey_seal::POINT_LEN]> { + let mut point = [0u8; refkey_seal::POINT_LEN]; + point.copy_from_slice(Self::refkey_pub(blob).ok_or(EINVAL)?); + Ok(point) + } + + /// `/dev/sep-key` sign: the enclave's ECDSA-P256 over `digest` with the + /// key in `blob`. A record this SEP and key bag did not make is refused + /// by the enclave (`EKEYREJECTED`). + pub(crate) fn user_key_sign(&self, blob: &[u8], digest: &[u8; 32]) -> Result> { + // A record without a public point is not a ref-key record at all. + Self::refkey_pub(blob).ok_or(EINVAL)?; + self.with_identity_bag(|handle, _secret| self.sks_refkey_sign(handle, blob, digest)) } /// Enclave ECIES-decrypt (o = "oecd"); takes the ephemeral from the front of `d`. diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 58582dc6e1b8b..7a8e2ae11d609 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -1898,6 +1898,14 @@ impl SepData { e ); } + if let Err(e) = self.register_key() { + dev_err!( + self.dev, + "bringup: could not publish /dev/{}: {:?}\n", + crate::key::DEVICE_NAME, + e + ); + } } fn activate_touchid(&self) -> Result<()> { diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index fd75957ddeca2..ef7c47605ae8b 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -18,6 +18,7 @@ mod dt; mod fv; mod hwrng; mod image; +mod key; mod keybag; mod keybag_identity; mod os_identity; @@ -763,6 +764,10 @@ struct SepData { #[pin] rearm_dev: Mutex>, + // /dev/sep-key: P-256 keys created inside the SEP (see `key`). + #[pin] + key_dev: Mutex>, + // The enclave refused to match (MATCH_RESULT answered 0x1) after failed // attempts, or the lockout survived a restart. Every verify is refused // without a capture until a password authentication re-arms Touch ID. @@ -1041,6 +1046,7 @@ impl SepData { bio_index <- new_mutex!(bio_index), bio_dev <- new_mutex!(None), rearm_dev <- new_mutex!(None), + key_dev <- new_mutex!(None), bio_lockout: Atomic::new(false), bio_lockout_logged: Atomic::new(false), bio_nomatch_streak: Atomic::new(0), @@ -2619,6 +2625,8 @@ impl SepData { drop(dev); let dev = self.rearm_dev.lock().take(); drop(dev); + let dev = self.key_dev.lock().take(); + drop(dev); self.rng_shutdown.store(true, Relaxed); self.control_wq.notify_all(); diff --git a/include/uapi/linux/apple-sep.h b/include/uapi/linux/apple-sep.h index a347d8d8d0c06..5337e379208b1 100644 --- a/include/uapi/linux/apple-sep.h +++ b/include/uapi/linux/apple-sep.h @@ -179,4 +179,67 @@ struct sep_bio_rearm { #define SEP_BIO_REARM _IOW(SEP_BIO_IOC_MAGIC, 0x0f, struct sep_bio_rearm) +/* + * /dev/sep-key: P-256 keys created inside the SEP. + * + * Each key is made by the enclave's key store and bound to this SEP and to + * the Linux identity key bag. The private key never leaves the enclave. + * Userspace holds only an opaque handle (at most SEP_KEY_HANDLE_MAX bytes) + * that works on the Mac that made it and nowhere else; keep it like a key + * file. Signing takes a 32-byte digest (for ES256/ecdsa-sha2-nistp256, the + * SHA-256 of the message) and returns a DER ECDSA-Sig-Value. + * + * Interface version 1 has no access control: whoever can open the node and + * holds a handle can sign with it. The node is created 0600; distributions + * may grant a group. Every 'flags' and 'reserved' field must be zero; later + * versions report what they accept in SEP_KEY_GET_INFO. + * + * Errors: EINVAL for a malformed request or handle, EKEYREJECTED when the + * enclave refuses the key (for example a handle from another Mac or an + * earlier Linux install), ENODEV/ETIMEDOUT while the key store is not up, + * EIO for any other enclave failure. + */ +#define SEP_KEY_IFACE_VERSION 1 +#define SEP_KEY_HANDLE_MAX 2048 +#define SEP_KEY_PUB_LEN 65 /* uncompressed point, 04 || X || Y */ +#define SEP_KEY_DIGEST_LEN 32 +#define SEP_KEY_SIG_MAX 72 /* DER SEQUENCE { INTEGER r, INTEGER s } */ + +struct sep_key_info { + __u32 version; /* SEP_KEY_IFACE_VERSION */ + __u32 flags_supported; /* 0 in version 1 */ + __u32 handle_max; /* SEP_KEY_HANDLE_MAX */ + __u32 reserved; +}; + +struct sep_key_create { + __u32 flags; /* in: 0 */ + __u32 handle_len; /* out */ + __u8 public_key[SEP_KEY_PUB_LEN]; /* out */ + __u8 reserved[3]; /* in: 0 */ + __u8 handle[SEP_KEY_HANDLE_MAX]; /* out */ +}; + +struct sep_key_sign { + __u32 flags; /* in: 0 */ + __u32 handle_len; /* in */ + __u8 digest[SEP_KEY_DIGEST_LEN]; /* in */ + __u32 sig_len; /* out */ + __u8 signature[SEP_KEY_SIG_MAX]; /* out, zero-padded */ + __u8 handle[SEP_KEY_HANDLE_MAX]; /* in */ +}; + +struct sep_key_public { + __u32 flags; /* in: 0 */ + __u32 handle_len; /* in */ + __u8 public_key[SEP_KEY_PUB_LEN]; /* out */ + __u8 reserved[3]; /* in: 0 */ + __u8 handle[SEP_KEY_HANDLE_MAX]; /* in */ +}; + +#define SEP_KEY_GET_INFO _IOR(SEP_BIO_IOC_MAGIC, 0x20, struct sep_key_info) +#define SEP_KEY_CREATE _IOWR(SEP_BIO_IOC_MAGIC, 0x21, struct sep_key_create) +#define SEP_KEY_SIGN _IOWR(SEP_BIO_IOC_MAGIC, 0x22, struct sep_key_sign) +#define SEP_KEY_PUBLIC _IOWR(SEP_BIO_IOC_MAGIC, 0x23, struct sep_key_public) + #endif /* _UAPI_LINUX_APPLE_SEP_H */ From b8b2d92c4e5b65c3f1f0f589bced695202ba6c58 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 16:43:15 +1100 Subject: [PATCH 032/342] usb: typec: tipd: keep the I2C event handler out of system sleep The I2C controllers share a level interrupt (all three on the M2), and that interrupt stays enabled through system sleep unless the port is a wakeup source. The I2C adapter suspends right after its clients and resumes right before them, and cannot transfer in between. When an attached partner holds the interrupt asserted across that window, every pass of the handler fails to read the events, cannot clear them and returns, and the line fires again at once. That is what a USB4 host on the other end of the cable does. On the M2 with an M4 Pro MacBook Pro attached over Thunderbolt, every s2idle cycle logged "cd321x_interrupt: failed to read events" about 3600 times for each of the three controllers, and one sleep in six did not freeze. Without a partner the window is just as open but nothing fires in it. Disable the interrupt before suspending a controller and enable it again after it has resumed, as the SPMI variant (SN201202x) already does. An event that arrives meanwhile is handled once the interrupt is enabled. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/usb/typec/tipd/i2c.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tipd/i2c.c b/drivers/usb/typec/tipd/i2c.c index ba5e8e3a32b19..7e63d2dfc04c7 100644 --- a/drivers/usb/typec/tipd/i2c.c +++ b/drivers/usb/typec/tipd/i2c.c @@ -58,18 +58,39 @@ static void tps6598x_remove_i2c(struct i2c_client *client) tipd_remove(tps); } +/* + * The I2C adapter suspends right after its clients and resumes right before + * them, and cannot transfer in between. Keep the event handler out of that + * window: a partner such as a USB4 host can keep the shared level interrupt + * asserted through system sleep, and every pass of the handler would then fail + * its bus reads and leave it asserted. An event that arrives meanwhile is + * handled once the interrupt is enabled again on resume. + */ static int __maybe_unused tps6598x_suspend(struct device *dev) { struct tps6598x *tps = dev_get_drvdata(dev); + int ret; + + if (tps->irq) + disable_irq(tps->irq); + + ret = tipd_suspend(tps); + if (ret && tps->irq) + enable_irq(tps->irq); - return tipd_suspend(tps); + return ret; } static int __maybe_unused tps6598x_resume(struct device *dev) { struct tps6598x *tps = dev_get_drvdata(dev); + int ret; - return tipd_resume(tps); + ret = tipd_resume(tps); + if (tps->irq) + enable_irq(tps->irq); + + return ret; } static const struct dev_pm_ops tps6598x_pm_ops = { From 95e9c52a0875ef41c167529993a85d69a9355e67 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:24:07 -0800 Subject: [PATCH 033/342] dt-bindings: pci: apple,pcie: Add T6050 hosts adopted from the boot loader Add apple,t6050-pcie, a T6050 (M5 Ultra) PCIe host whose root ports the boot loader powered, trained and left running. Each such port is marked apple,link-trained-by-bootloader and named by its port, phy and intr2axi register ranges and its port interrupt; the host's local MSI map starts at apple,msi-vector-base. The OS adopts the trained state and never resets, retrains or changes the port's power: reset-gpios, pwren-gpios and power-domains are not allowed on it. Also name nonposted-mmio, which these hosts take. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 245231ecfc3a9..5823cc0ff837a 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -98,11 +98,11 @@ properties: reg: minItems: 3 - maxItems: 11 + maxItems: 14 reg-names: minItems: 3 - maxItems: 11 + maxItems: 14 ranges: minItems: 2 @@ -128,8 +128,7 @@ properties: apple,msi-vector-base: $ref: /schemas/types.yaml#/definitions/uint32 description: - First vector of this PCIe-C controller's slice of the MSI window it - shares with the internal PCIe controller. + First global vector targeted by this controller's local MSI map. iommu-map: true iommu-map-mask: true @@ -234,6 +233,48 @@ allOf: - apple,msi-vector-base - $ref: /schemas/pci/pci-host-bridge.yaml# - $ref: /schemas/interrupt-controller/msi-controller.yaml# + - if: + properties: + compatible: + contains: + const: apple,t6050-pcie + then: + properties: + reg: + minItems: 5 + maxItems: 14 + reg-names: + description: + config and rc, then port, phy and intr2axi for each + bootloader-trained root port 00:.0. + minItems: 5 + maxItems: 14 + items: + pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" + interrupts: + maxItems: 4 + interrupt-names: + items: + pattern: "^port[0-3]$" + apple,msi-vector-base: + const: 64 + power-domains: false + required: + - interrupt-names + - apple,msi-vector-base + - iommu-map + patternProperties: + "^pci@": + properties: + reset-gpios: false + pwren-gpios: false + required: + - apple,link-trained-by-bootloader + else: + patternProperties: + "^pci@": + properties: + apple,link-trained-by-bootloader: false - if: properties: compatible: @@ -390,10 +431,10 @@ allOf: properties: reg: minItems: 5 - maxItems: 11 + maxItems: 14 reg-names: minItems: 5 - maxItems: 11 + maxItems: 14 items: enum: [config, rc, port0, phy0, intr2axi0, port1, phy1, intr2axi1, port2, phy2, intr2axi2, port3, phy3, @@ -420,6 +461,8 @@ allOf: maxItems: 3 else: properties: + reg: + maxItems: 10 reg-names: minItems: 3 items: From 500d016017203e44579be3068b4a542c6cde6eb1 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:25:06 -0800 Subject: [PATCH 034/342] PCI: apple: Adopt T6050 root ports the boot loader trained On the M5 Ultra (T6050, J775D) running Linux on the hardware, the boot loader brings up the internal PCIe host's ports itself: it powers the shared PHY, trains each port's link and leaves it up, with the endpoint idle. Port 2 carries the onboard RTL8127 Ethernet controller and port 3 the ASM3142 xHCI behind the rear USB-A ports. Repeating the reset and training sequence from Linux is not needed and not known to be safe on this SoC. Add apple,t6050-pcie, a host whose root ports marked apple,link-trained-by-bootloader are adopted as they are: no reset, no tunable replay, no clock or power change and no retraining. Every resource comes from the DT by the port's index (port, phy, intr2axi, interrupt port, the iommu-map entry for the endpoint's RID). Before the first PCIe register write the driver checks that the link is up and not retraining at Gen3 x1, that the boot loader numbered the root port's buses (primary 0, one secondary), that the endpoint on it is device 0 function 0 with DMA and MSI off and a well-formed capability list, and that the port's RID table holds no valid entry. A port that fails a check is left alone and the others are still adopted. Then the endpoint's RID is routed to its SID, the host's MSI map is set up from apple,msi-vector-base, and only the adopted root ports and the endpoint behind each are enumerated. The links cannot be recovered by a user reset or removal, since the boot loader owns them. No other SoC sets adopt_link. Testing: on J775D, every boot adopts port 2 (RTL8127, DHCP and SSH over it on every boot) and port 3 (ASM3142, a USB keyboard and mouse driving the desktop session). Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 283 ++++++++++++++++++++++++++-- 1 file changed, 270 insertions(+), 13 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 3173186c85209..447e820d6349d 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -207,6 +207,7 @@ struct hw_info { u32 pwren_on_ms; bool sid_indexed_rid2sid; bool retain_clocks; + bool adopt_link; bool root_bus_only; bool tunneled; bool tunnel_intr2axi; @@ -281,6 +282,24 @@ static const struct hw_info t8152_hw = { .pipe_rst = true, }; +/* + * Bare-metal T6050 adoption only. Firmware owns power, PHY, reset and training. + * The 64-entry route table is never probed with test writes. + */ +static const struct hw_info t6050_hw = { + .port_msiaddr = PORT_T602X_MSIADDR, + .port_msiaddr_hi = PORT_T602X_MSIADDR_HI, + .port_perst = PORT_T602X_PERST, + .port_rid2sid = PORT_T602X_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .max_rid2sid = 64, + .retain_clocks = true, + .adopt_link = true, +}; + +#define T6050_ROUTE(rid, sid) (PORT_RID2SID_VALID | \ + ((sid) << PORT_RID2SID_SID_SHIFT) | (rid)) + static const struct hw_info t8103_pciec_hw = { .port_msiaddr = PORT_MSIADDR, .port_perst = PORT_PERST, @@ -441,6 +460,10 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; + bool adopted_route; + void __iomem *intr2axi; /* adopt_link: this port's */ + u16 adopted_rid; /* adopt_link: secondary bus << 8 */ + u32 adopted_sid; }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -752,9 +775,20 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) struct apple_pcie *pcie = port->pcie; u32 val = 0; - /* FIXME: consider moving each interrupt under each port */ - port->irq = irq_of_parse_and_map(to_of_node(dev_fwnode(port->pcie->dev)), - port->idx); + if (pcie->hw->adopt_link) { + char name[16]; + int irq; + + snprintf(name, sizeof(name), "port%d", port->idx); + irq = of_irq_get_byname(pcie->dev->of_node, name); + + if (irq <= 0) + return irq ?: -ENXIO; + port->irq = irq; + } else { + /* FIXME: consider moving each interrupt under each port */ + port->irq = irq_of_parse_and_map(pcie->dev->of_node, port->idx); + } if (!port->irq) return -ENXIO; @@ -767,6 +801,9 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) return -ENOMEM; } + if (pcie->hw->adopt_link) + apple_pcie_port_writel(port, 0, PORT_MSICFG); + /* Disable all interrupts */ apple_pcie_port_writel(port, ~0, PORT_INTMSK); apple_pcie_port_writel(port, ~0, PORT_INTSTAT); @@ -800,7 +837,22 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) val = ilog2(pcie->nvecs) << PORT_MSICFG_L2MSINUM_SHIFT; } + if (pcie->hw->adopt_link) { + if (apple_pcie_port_readl(port, pcie->hw->port_msiaddr) != DOORBELL_ADDR || + apple_pcie_port_readl(port, pcie->hw->port_msiaddr_hi)) + return -EIO; + for (int i = 0; i < pcie->nvecs; i++) + if (apple_pcie_port_readl(port, pcie->hw->port_msimap + 4 * i) != + (PORT_MSIMAP_ENABLE | (pcie->msi_vector_base + i))) + return -EIO; + /* Enable command is not readable; +0x84 is only a completion read. */ + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + readl(port->intr2axi + 0x84); + } apple_pcie_port_writel(port, val | PORT_MSICFG_EN, PORT_MSICFG); + if (pcie->hw->adopt_link && + !(apple_pcie_port_readl(port, PORT_MSICFG) & PORT_MSICFG_EN)) + return -EIO; return 0; } @@ -816,6 +868,8 @@ static irqreturn_t apple_pcie_port_irq(int irq, void *data) complete_all(&port->pcie->event); break; case PORT_INT_LINK_DOWN: + if (port->pcie->hw->adopt_link) + WRITE_ONCE(port->link_failed, true); /* A later link-up alone does not prove downstream state survived. */ if (port->pcie->hw->tunneled && READ_ONCE(port->started)) { WRITE_ONCE(port->link_failed, true); @@ -1494,9 +1548,18 @@ static void apple_pcie_port_teardown(struct apple_pcie_port *port) apple_pcie_port_disable_irq(port); /* Busy managed admission has not acquired or programmed this IRQ block. */ - if (port->base && (!port->pcie->managed_sids || port->domain)) + if (port->base && + (port->domain || + (!port->pcie->managed_sids && !port->pcie->hw->adopt_link))) apple_pcie_port_writel(port, ~0, PORT_INTMSK); + if (port->pcie->hw->adopt_link && port->domain) + apple_pcie_port_writel(port, 0, PORT_MSICFG); + if (port->adopted_route) { + apple_pcie_rid2sid_write(port, port->adopted_sid, 0); + port->adopted_route = false; + } + if (port->pcie->hw->tunneled && (port->started || port->needs_stop)) apple_pcie_tunnel_stop(port); @@ -1580,6 +1643,134 @@ static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port, return apple_pcie_port_readl(port, offset); } +/* + * Qualified J775D handoff of one bootloader-trained port: its root port + * 00:.0 and the single endpoint on its secondary bus, with DMA and + * endpoint MSI disabled. Every resource comes from the DT by the port's index + * (port, phy, intr2axi, interrupt port, the iommu-map entry for the + * endpoint's RID). All checks precede the first PCIe register write. + */ +static int apple_pcie_adopt_link(struct apple_pcie_port *port) +{ + static const char *const names[] = { "port%d", "phy%d", "intr2axi%d" }; + struct apple_pcie *pcie = port->pcie; + struct platform_device *pdev = to_platform_device(pcie->dev); + struct of_phandle_args iommu = {}; + void __iomem *rp, *ep; + char name[16]; + u32 value, bus; + u8 cap; + bool msi = false; + int ret, i; + + if (pcie->cfg->busr.start != 0 || + !platform_get_resource_byname(pdev, IORESOURCE_MEM, "config") || + !platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc")) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(names); i++) { + snprintf(name, sizeof(name), names[i], port->idx); + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) + return -EINVAL; + } + + if (!(readl(pcie->base + CORE_RC_CTL) & CORE_RC_CTL_RUN) || + !(readl(pcie->base + CORE_RC_STAT) & CORE_RC_STAT_READY) || + !(apple_pcie_port_readl(port, PORT_STATUS) & PORT_STATUS_READY) || + (apple_pcie_port_readl(port, PORT_LINKSTS) & + (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP || + !(apple_pcie_port_readl(port, PORT_LTSSMCTL) & PORT_LTSSMCTL_START) || + (apple_pcie_port_readl(port, PORT_APPCLK) & 0x101) != 0x101 || + (apple_pcie_port_readl(port, pcie->hw->port_perst) & 0x10001) != 1 || + (readl(port->phy + PHY_LANE_CFG) & 0x1000061f) != 0x60f) + return -ENOLINK; + + /* The bootloader numbered the root port's buses: primary 0, one secondary. */ + rp = pcie->cfg->win + (PCI_DEVFN(port->idx, 0) << 12); + value = readl(rp + PCI_PRIMARY_BUS); + bus = (value >> 8) & 0xff; + if (readl(rp) != 0x100c106b || (value & 0xff) != 0 || !bus || + ((value >> 16) & 0xff) != bus || bus > pcie->cfg->busr.end || + (readw(rp + PCI_BRIDGE_CONTROL) & PCI_BRIDGE_CTL_BUS_RESET)) + return -ENODEV; + ep = pcie->cfg->win + (bus << 20); + value = readl(ep); + if (value == 0xffffffff || !(value & 0xffff) || + (readb(ep + PCI_HEADER_TYPE) & 0x7f) != PCI_HEADER_TYPE_NORMAL || + (readw(ep + PCI_COMMAND) & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | + PCI_COMMAND_MASTER))) + return -ENODEV; + + port->adopted_rid = bus << 8; + ret = of_map_iommu_id(pcie->dev->of_node, port->adopted_rid, &iommu); + if (ret) + return ret; + ret = iommu.args_count == 1 && iommu.args[0] && + iommu.args[0] < pcie->hw->max_rid2sid && + of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; + port->adopted_sid = iommu.args[0]; + of_node_put(iommu.np); + if (ret) + return ret; + + snprintf(name, sizeof(name), "intr2axi%d", port->idx); + port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); + if (IS_ERR(port->intr2axi)) + return PTR_ERR(port->intr2axi); + + /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ + cap = readb(rp + PCI_CAPABILITY_LIST); + for (i = 0; cap && i < 48; i++) { + if (cap < 0x40 || (cap & 3)) + return -EINVAL; + if (readb(rp + cap + PCI_CAP_LIST_ID) == PCI_CAP_ID_EXP) + break; + cap = readb(rp + cap + PCI_CAP_LIST_NEXT); + } + if (!cap || i == 48) + return -EINVAL; + value = readw(rp + cap + PCI_EXP_LNKSTA); + if ((value & (PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != + (PCI_EXP_LNKSTA_CLS_8_0GB | (1 << PCI_EXP_LNKSTA_NLW_SHIFT))) + return -ENOLINK; + + /* Refuse an active endpoint or malformed capability chain. */ + cap = readb(ep + PCI_CAPABILITY_LIST); + for (i = 0; cap && i < 48; i++) { + if (cap < 0x40 || (cap & 3)) + return -EINVAL; + value = readw(ep + cap + PCI_MSI_FLAGS); + switch (readb(ep + cap + PCI_CAP_LIST_ID)) { + case PCI_CAP_ID_MSI: + if (value & PCI_MSI_FLAGS_ENABLE) + return -EBUSY; + msi = true; + break; + case PCI_CAP_ID_MSIX: + if (value & PCI_MSIX_FLAGS_ENABLE) + return -EBUSY; + msi = true; + break; + } + cap = readb(ep + cap + PCI_CAP_LIST_NEXT); + } + if (cap || !msi) + return -EINVAL; + + for (i = 0; i < pcie->hw->max_rid2sid; i++) + if (apple_pcie_port_readl(port, port_rid2sid_offset(port, i)) & + PORT_RID2SID_VALID) + return -EBUSY; + + /* The route goes in the slot whose index is the SID, as on J775D's adopted ports. */ + value = T6050_ROUTE(port->adopted_rid, port->adopted_sid); + port->adopted_route = true; + if (apple_pcie_rid2sid_write(port, port->adopted_sid, value) != value) + return -EIO; + dev_info(pcie->dev, "adopted port %d, RID %04x -> SID %u, slot %u\n", + port->idx, port->adopted_rid, port->adopted_sid, port->adopted_sid); + return 0; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) @@ -1866,6 +2057,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, goto err_teardown; } } + } else if (pcie->hw->adopt_link) { + ret = apple_pcie_adopt_link(port); + if (ret) + goto err_teardown; } else { if (pcie->hw->retain_clocks) rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK); @@ -1907,9 +2102,8 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, if (ret) goto err_teardown; - if (pcie->managed_sids) { + if (pcie->managed_sids || pcie->hw->adopt_link) goto rid2sid_ready; - } /* Reset all RID/SID mappings, and check for RAZ/WI registers */ for (i = 0; i < pcie->hw->max_rid2sid; i++) { @@ -1934,6 +2128,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, unsigned long timeout, left = 0; int attempt, attempts = 1; + if (pcie->hw->adopt_link) { + ret = -ENOLINK; + goto err_teardown; + } if (pcie->hw->tunneled) { if (pcie->kernel_init) { apple_pcie_tunnel_apply_tunable(port->base, @@ -2080,6 +2278,17 @@ static int apple_msi_init(struct apple_pcie *pcie) return ret; } + if (pcie->hw->adopt_link) { + ret = of_property_read_u32(to_of_node(fwnode), "apple,msi-vector-base", + &pcie->msi_vector_base); + if (ret || pcie->msi_vector_base != 64 || + (pcie->nvecs != 32 && pcie->nvecs != 64) || + args.args_count != 4 || args.args[0] != 0 || args.args[1] != 0 || + args.args[2] != 1888 || args.args[3] != IRQ_TYPE_EDGE_RISING || + DOORBELL_ADDR != 0xfffff000) + goto invalid_slice; + } + /* * The controller-wide ADT count (512) is not a per-host allocation. * Internal PCIe owns vectors 0..31. Each PCIe-C bridge owns a distinct @@ -2186,7 +2395,7 @@ static int apple_msi_init(struct apple_pcie *pcie) invalid_slice: of_node_put(args.np); return dev_err_probe(pcie->dev, -EINVAL, - "invalid or missing PCIe-C MSI slice\n"); + "invalid or missing MSI slice\n"); } static void apple_pcie_cleanup(void *data) @@ -2387,6 +2596,11 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d of_node_put(iommu_spec.np); sid = iommu_spec.args[0]; + if (pcie->hw->adopt_link) + return rid == port->adopted_rid && sid == port->adopted_sid && + !READ_ONCE(port->link_failed) && + apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)) == + T6050_ROUTE(rid, sid) ? 0 : -ENODEV; mutex_lock(&port->pcie->lock); if (port->pcie->managed_sids || port->pcie->hw->sid_indexed_rid2sid) { @@ -2453,7 +2667,7 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci int idx; port = apple_pcie_get_port(pdev); - if (!port) + if (!port || port->pcie->hw->adopt_link) return; mutex_lock(&port->pcie->lock); @@ -2494,9 +2708,13 @@ static int apple_pcie_init(struct pci_config_window *cfg) ret = apple_pcie_setup_port(pcie, of_port); if (ret) { dev_err(dev, "Port %pOF setup fail: %d\n", of_port, ret); - return ret; + /* Adopted ports are independent: one refused leaves the others. */ + if (!pcie->hw->adopt_link) + return ret; } } + if (pcie->hw->adopt_link && list_empty(&pcie->ports)) + return -ENODEV; /* The bus scan follows this callback. */ apple_pcie_tunnel_wait_ready(pcie); @@ -2516,6 +2734,27 @@ static void __iomem *apple_pcie_map_bus(struct pci_bus *bus, struct apple_pcie *pcie = apple_pcie_lookup(cfg->parent); struct apple_pcie_port *port; + if (pcie->hw->adopt_link) { + /* Only adopted ports' root ports, and the one endpoint behind each. */ + list_for_each_entry(port, &pcie->ports, entry) { + if (bus->number == 0) { + if (devfn == PCI_DEVFN(port->idx, 0)) + return pci_ecam_map_bus(bus, devfn, where); + continue; + } + if (bus->number != port->adopted_rid >> 8) + continue; + if (devfn || READ_ONCE(port->link_failed)) + return NULL; + if ((apple_pcie_port_readl(port, PORT_LINKSTS) & + (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP) { + WRITE_ONCE(port->link_failed, true); + return NULL; + } + return pci_ecam_map_bus(bus, devfn, where); + } + return NULL; + } if (!pcie->hw->root_bus_only) return pci_ecam_map_bus(bus, devfn, where); @@ -3089,7 +3328,22 @@ static int apple_pcie_probe(struct platform_device *pdev) * reset-gpios provider here rejects the valid synthesized port before * the tunneled setup path can consume that handoff. */ - if (!hw->tunneled) { + if (hw->adopt_link) { + if (!of_get_available_child_count(dev->of_node) || + of_property_present(dev->of_node, "power-domains")) + return -EINVAL; + for_each_available_child_of_node_scoped(dev->of_node, child) { + u32 reg; + + /* A root port 00:.0 on bus 0, n a GP port */ + if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || + !(reg >> 11) || (reg >> 11) > 3 || + !of_property_read_bool(child, "apple,link-trained-by-bootloader") || + of_property_present(child, "reset-gpios") || + of_property_present(child, "pwren-gpios")) + return -EINVAL; + } + } else if (!hw->tunneled) { /* Check for probe dependencies for all ports first */ for_each_available_child_of_node(dev->of_node, of_port) { ret = apple_pcie_probe_port(of_port); @@ -3132,15 +3386,15 @@ static int apple_pcie_probe(struct platform_device *pdev) return ret; } pcie->piodma_supplier = piodma_supplier; - /* Only this retained-DMA radio hierarchy forbids user reset/removal. */ - if (piodma_supplier || pcie->managed_sids) { + /* Firmware-owned links cannot be recovered by user reset/removal. */ + if (piodma_supplier || pcie->managed_sids || hw->adopt_link) { bridge->no_user_remove = true; bridge->reset_sensitive = true; bridge->native_pcie_hotplug = false; bridge->native_shpc_hotplug = false; bridge->native_aer = false; bridge->native_dpc = false; - dev_dbg(dev, "radio host: automatic AER/DPC recovery disabled for retained DMA\n"); + dev_dbg(dev, "firmware-owned host: automatic AER/DPC recovery disabled\n"); } if (hw->root_bus_only && !piodma_supplier) dev_info(dev, "root-port probe only; downstream config is blocked\n"); @@ -3920,6 +4174,8 @@ static int apple_pcie_suspend_noirq(struct device *dev) */ if (pcie->managed_sids) return pm_suspend_target_state == PM_SUSPEND_TO_IDLE ? 0 : -EBUSY; + if (pcie->hw->adopt_link) + return -EBUSY; if (!pcie->hw->tunneled) return 0; pcie->reset_on_resume = false; @@ -4062,6 +4318,7 @@ static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t8152-pcie", .data = &t8152_hw }, { .compatible = "apple,t6020-pcie", .data = &t602x_hw }, { .compatible = "apple,t8140-pcie", .data = &t8140_hw }, + { .compatible = "apple,t6050-pcie", .data = &t6050_hw }, { .compatible = "apple,pcie", .data = &t8103_hw }, { } }; From 9522dc08d514a8c46a501c2f08c7054a0facefb6 Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:16 -0400 Subject: [PATCH 035/342] PCI: Add pci_trylock_rescan_remove() A driver's work item that rescans or resets part of a bus takes the rescan/remove lock. When the device is being removed, the remover holds that lock while it cancels the work, so a worker that blocks on the lock deadlocks against its own cancellation. Add pci_trylock_rescan_remove(), which takes the rescan/remove lock only if it is free. A worker that cannot get it returns and retries later, and the remover's cancellation completes. Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/probe.c | 7 +++++++ include/linux/pci.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 27008e2ea5afc..d625dd5e778a8 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3517,6 +3517,13 @@ void pci_lock_rescan_remove(void) } EXPORT_SYMBOL_GPL(pci_lock_rescan_remove); +/* Work cancelled by removal must not wait on the remover's own lock. */ +bool pci_trylock_rescan_remove(void) +{ + return mutex_trylock(&pci_rescan_remove_lock); +} +EXPORT_SYMBOL_GPL(pci_trylock_rescan_remove); + void pci_unlock_rescan_remove(void) { mutex_unlock(&pci_rescan_remove_lock); diff --git a/include/linux/pci.h b/include/linux/pci.h index 5cec6d838b3f7..c0d76d93a78f5 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1559,6 +1559,7 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev); /* Functions for PCI Hotplug drivers to use */ unsigned int pci_rescan_bus(struct pci_bus *bus); void pci_lock_rescan_remove(void); +bool pci_trylock_rescan_remove(void); void pci_unlock_rescan_remove(void); /* Vital Product Data routines */ From 847c7493f8709bca983b86cbbe824c9726c9ce53 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 20:45:53 -0500 Subject: [PATCH 036/342] PCI: apple: Add the T6050 port reset, enable, configure and train sequences An adopted T6050 port is left as the boot loader trained it, but an endpoint that has to come back on a retrained link (the N1 on port 0, after its ROM boot) needs the host to take the port down and bring it up again. Add the sequences for that, on the port's own register blocks (port, phy and intr2axi) and the root port's config space: - Disable: wait for the link to leave L1 and go idle, assert the port's PERST# through its handshake, then stop the lane clocks and the port's application clock. - Enable: the port reset table, which also clears the RID2SID and MSI map tables, the port's tunables, then the application clock and the PERST# release handshake, until the port is ready and its link idle. - Configure: with the root complex's read-only registers opened, its tunables and the per-rate shadow tunables, then a Gen3 x1 link (target speed, link width and capability) and a directed speed change; Intr2AXI enabled. - Train: the lane's reference clocks, the endpoint's PERST# released through its pad, the LTSSM started, then the 100 ms wait after link up. The tunables are the lists the boot loader copies onto the root port node, groups of (offset, 4, mask, value); a list it did not copy is skipped. The root-port reset that runs the sequences follows; until then they are marked __maybe_unused. Co-developed-by: Dj Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 340 ++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 447e820d6349d..9048fe5f0c4d2 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -186,6 +186,20 @@ MODULE_PARM_DESC(link_up_timeout, "PCIe link training timeout in milliseconds"); #define PORT_MSIMAP_ENABLE BIT(31) #define PORT_MSIMAP_TARGET GENMASK(7, 0) +/* T6050: the root port's port logic, laid out as DesignWare's */ +#define RC_T6050_PORT_LINK_CTRL 0x710 +#define RC_T6050_LINK_MODE GENMASK(21, 16) +#define RC_T6050_PORT_DEBUG0 0x728 +#define RC_T6050_LTSSM_STATE GENMASK(5, 0) +#define RC_T6050_LTSSM_L1_IDLE 0x14 +#define RC_T6050_LINK_WIDTH_SPEED_CTRL 0x80c +#define RC_T6050_LINK_WIDTH GENMASK(12, 8) +#define RC_T6050_SPEED_CHANGE BIT(17) +#define RC_T6050_GEN3_RELATED 0x890 +#define RC_T6050_RATE_SHADOW_SEL GENMASK(25, 24) +#define RC_T6050_MISC_CONTROL_1 0x8bc +#define RC_T6050_DBI_RO_WR_EN BIT(0) + /* * The doorbell address must be in the bottom 4GB because the base register * is only 32 bits wide. Exclude it from the IOVA range and share the same @@ -464,6 +478,7 @@ struct apple_pcie_port { void __iomem *intr2axi; /* adopt_link: this port's */ u16 adopted_rid; /* adopt_link: secondary bus << 8 */ u32 adopted_sid; + void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -1771,6 +1786,331 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) return 0; } +/* + * T6050 port bring-up, for an adopted port whose endpoint must come back on a + * retrained link: port disable, the port reset table, port enable, root complex + * configuration for Gen3 x1, then the lane PHY, PERST# and the LTSSM. The port's + * registers are its port, phy and intr2axi blocks; the root complex's + * are the root port's config space. The boot loader copies the port's tunables + * onto its node. + */ +static const struct apple_pcie_reset_reg apple_pcie_t6050_reset_regs[] = { + { 0x088, 0x00000110 }, + { 0x100, 0xffffffff }, + { 0x148, 0xffffffff }, + { 0x210, 0xffffffff }, + { 0x080, 0x00000000 }, + { 0x084, 0x00000000 }, + { 0x104, 0xfffffff0 }, + { 0x124, 0x00000100 }, + { 0x16c, 0x00000000 }, + { 0x13c, 0x00000000 }, + { 0x800, 0x00100100 }, + { 0x808, 0x001001ff }, + { 0x82c, 0x00010000 }, +}; + +/* Written after the RID2SID and MSI map tables are cleared */ +static const struct apple_pcie_reset_reg apple_pcie_t6050_reset_regs_late[] = { + { 0x130, 0x03020000 }, + { 0x140, 0x00000010 }, + { 0x144, 0x00253770 }, + { 0x21c, 0x00000000 }, + { 0x834, 0x00000000 }, + { 0x83c, 0x00000000 }, +}; + +static void apple_pcie_t6050_rmw(void __iomem *addr, u32 clear, u32 set) +{ + writel((readl(addr) & ~clear) | set, addr); +} + +static int apple_pcie_t6050_rc_rmw(struct pci_dev *rp, int where, u32 clear, u32 set) +{ + u32 value; + int ret; + + ret = pci_read_config_dword(rp, where, &value); + if (!ret) + ret = pci_write_config_dword(rp, where, (value & ~clear) | set); + return pcibios_err_to_errno(ret); +} + +static int apple_pcie_t6050_wait(struct apple_pcie_port *port, void __iomem *base, + u32 offset, u32 mask, u32 value, unsigned int timeout_us) +{ + u32 stat; + int ret; + + ret = readl_poll_timeout(base + offset, stat, (stat & mask) == value, 1, timeout_us); + if (ret) + dev_err(port->pcie->dev, "port %d: %#x = %#x, waiting for %#x/%#x\n", + port->idx, offset, stat, value, mask); + return ret; +} + +/* + * A tunable list the boot loader copies onto the root port node, groups of + * (offset, 4, mask, value): for the port's registers, or with @rp for the root + * port's config space. A list it did not copy is skipped. + */ +static int apple_pcie_t6050_tune(struct apple_pcie_port *port, struct pci_dev *rp, + const char *name) +{ + u32 cells[64]; + int count, ret, i; + + if (!of_property_present(port->np, name)) + return 0; + count = of_property_count_u32_elems(port->np, name); + if (count <= 0 || count > ARRAY_SIZE(cells) || count % 4) + return -EINVAL; + ret = of_property_read_u32_array(port->np, name, cells, count); + if (ret) + return ret; + for (i = 0; i < count; i += 4) + if (cells[i + 1] != 4 || (cells[i] & 3) || + cells[i] >= (rp ? PCI_CFG_SPACE_EXP_SIZE : SZ_16K)) + return -EINVAL; + + for (i = 0; i < count; i += 4) { + if (!rp) { + apple_pcie_t6050_rmw(port->base + cells[i], cells[i + 2], cells[i + 3]); + continue; + } + ret = apple_pcie_t6050_rc_rmw(rp, cells[i], cells[i + 2], cells[i + 3]); + if (ret) + return ret; + } + return 0; +} + +/* PERST# through its pad: a GPIO output (function bits cleared) at the level asked for */ +static int apple_pcie_t6050_perst(struct apple_pcie_port *port, bool asserted) +{ + u32 old, value; + + old = readl(port->perst); + if (old & BIT(21)) + return -EIO; + value = (old & ~0x27f) | 0x202 | !asserted; + /* The input enable (bit 9) goes on after the rest */ + writel((value & ~0x200) | (old & 0x200), port->perst); + if (!(old & 0x200)) + writel(value, port->perst); + return (readl(port->perst) ^ value) & 0x27f ? -EIO : 0; +} + +/* Let the link go idle, hold the endpoint in reset and stop the port and its lane clocks */ +static int apple_pcie_t6050_port_disable(struct apple_pcie_port *port, struct pci_dev *rp) +{ + void __iomem *perst = port->base + PORT_T602X_PERST; + void __iomem *lane = port->phy + PHY_LANE_CFG; + u32 stat; + int ret, err; + + if (!(readl(port->base + PORT_STATUS) & BIT(2))) { + ret = apple_pcie_t6050_wait(port, port->base, 0x820, BIT(2), BIT(2), 10000); + if (ret) + return ret; + } + ret = readl_poll_timeout_atomic(port->base + 0x820, stat, + !(stat & GENMASK(8, 0)) || !(stat & GENMASK(23, 16)), + 1, 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + 0x13c, 0, BIT(8)); + + /* The link out of L1 */ + ret = read_poll_timeout_atomic(pci_read_config_dword, err, + err || FIELD_GET(RC_T6050_LTSSM_STATE, stat) != + RC_T6050_LTSSM_L1_IDLE, + 5, 5000, false, rp, RC_T6050_PORT_DEBUG0, &stat); + if (ret || err) + return ret ?: pcibios_err_to_errno(err); + + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(0), BIT(0), 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, BIT(24)); + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(16), BIT(16), 2000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, BIT(16)); + udelay(1); + apple_pcie_t6050_rmw(perst, PORT_PERST_OFF, 0); + udelay(1); + apple_pcie_t6050_rmw(perst, BIT(24), 0); + apple_pcie_t6050_rmw(port->base + 0x13c, BIT(8), 0); + + apple_pcie_t6050_rmw(lane, BIT(31), 0); + apple_pcie_t6050_rmw(lane, BIT(10), 0); + apple_pcie_t6050_rmw(lane, BIT(9), 0); + apple_pcie_t6050_rmw(lane, 0, BIT(4)); + apple_pcie_t6050_rmw(lane, PHY_LANE_CFG_REFCLK0REQ, 0); + apple_pcie_t6050_rmw(lane, PHY_LANE_CFG_REFCLK1REQ, 0); + + writel(~0, port->base + PORT_INTSTAT); + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, PORT_APPCLK_EN, 0); + return apple_pcie_t6050_wait(port, port->base, PORT_STATUS, PORT_STATUS_READY, 0, + 250000); +} + +/* The port reset table, then the port clocked and out of reset, ready to train */ +static int apple_pcie_t6050_port_enable(struct apple_pcie_port *port) +{ + void __iomem *perst = port->base + PORT_T602X_PERST; + u32 stat; + int ret, i; + + for (i = 0; i < ARRAY_SIZE(apple_pcie_t6050_reset_regs); i++) + writel(apple_pcie_t6050_reset_regs[i].value, + port->base + apple_pcie_t6050_reset_regs[i].offset); + for (i = 0; i < port->pcie->hw->max_rid2sid; i++) + writel(0, port->base + port_rid2sid_offset(port, i)); + for (i = 0; i < 256; i++) + writel(0, port->base + PORT_T602X_MSIMAP + 4 * i); + for (i = 0; i < ARRAY_SIZE(apple_pcie_t6050_reset_regs_late); i++) + writel(apple_pcie_t6050_reset_regs_late[i].value, + port->base + apple_pcie_t6050_reset_regs_late[i].offset); + + if (!(readl(perst) & BIT(16))) + return -EIO; + ret = apple_pcie_t6050_tune(port, NULL, "apple,apcie-config-tunables"); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, 0, PORT_APPCLK_EN); + + ret = readl_poll_timeout_atomic(port->base + 0xa8, stat, + (stat & (BIT(16) | BIT(0))) != (BIT(16) | BIT(0)), + 1, 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, PORT_PERST_OFF); + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(0), BIT(0), 20000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, BIT(16), 0); + ret = apple_pcie_t6050_wait(port, port->base, PORT_STATUS, PORT_STATUS_READY, + PORT_STATUS_READY, 250000); + if (ret) + return ret; + + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, 0, PORT_APPCLK_CGDIS); + return apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, PORT_LINKSTS_BUSY, 0, + 250000); +} + +/* Root complex tunables and a Gen3 x1 link, with the read-only registers opened for it */ +static int apple_pcie_t6050_port_configure(struct apple_pcie_port *port, struct pci_dev *rp) +{ + static const char * const shadow[] = { + "apple,pcie-rc-gen3-shadow-tunables", + "apple,pcie-rc-gen4-shadow-tunables", + "apple,pcie-rc-gen5-shadow-tunables", + }; + static const u32 shadow_sel[] = { 0, BIT(24), 0 }; + int cap = pci_pcie_cap(rp); + u32 value; + u16 ctl2; + int ret, err, i; + + if (!cap) + return -EIO; + ret = apple_pcie_t6050_rc_rmw(rp, RC_T6050_MISC_CONTROL_1, 0, RC_T6050_DBI_RO_WR_EN); + if (ret) + return ret; + ret = apple_pcie_t6050_tune(port, rp, "apple,pcie-rc-tunables"); + if (ret) + goto lock; + for (i = 0; i < ARRAY_SIZE(shadow); i++) { + ret = apple_pcie_t6050_rc_rmw(rp, RC_T6050_GEN3_RELATED, + RC_T6050_RATE_SHADOW_SEL, shadow_sel[i]) ?: + apple_pcie_t6050_tune(port, rp, shadow[i]); + if (ret) + goto lock; + } + ret = apple_pcie_t6050_rc_rmw(rp, 0x194, 0, BIT(0)); + if (ret) + goto lock; + + ret = pcibios_err_to_errno(pci_read_config_dword(rp, cap + PCI_EXP_LNKCAP2, &value)); + if (ret) + goto lock; + if (!(value & PCI_EXP_LNKCAP2_SLS_8_0GB)) { + ret = -EIO; + goto lock; + } + ret = pcibios_err_to_errno(pci_read_config_word(rp, cap + PCI_EXP_LNKCTL2, &ctl2)) ?: + pcibios_err_to_errno(pci_write_config_word(rp, cap + PCI_EXP_LNKCTL2, + (ctl2 & ~PCI_EXP_LNKCTL2_TLS) | + PCI_EXP_LNKCTL2_TLS_8_0GT)) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_PORT_LINK_CTRL, RC_T6050_LINK_MODE, + FIELD_PREP(RC_T6050_LINK_MODE, 1)) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_LINK_WIDTH_SPEED_CTRL, RC_T6050_LINK_WIDTH, + FIELD_PREP(RC_T6050_LINK_WIDTH, 1)) ?: + apple_pcie_t6050_rc_rmw(rp, cap + PCI_EXP_LNKCAP, PCI_EXP_LNKCAP_MLW, + FIELD_PREP(PCI_EXP_LNKCAP_MLW, 1)); +lock: + err = apple_pcie_t6050_rc_rmw(rp, RC_T6050_MISC_CONTROL_1, RC_T6050_DBI_RO_WR_EN, 0); + ret = ret ?: err; + if (ret) + return ret; + + ret = apple_pcie_t6050_rc_rmw(rp, cap + PCI_EXP_LNKCTL, 0, PCI_EXP_LNKCTL_LBMIE) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_LINK_WIDTH_SPEED_CTRL, 0, RC_T6050_SPEED_CHANGE); + if (ret) + return ret; + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + return 0; +} + +/* Disable, reset, enable and configure an adopted port whose endpoint is held in PERST# */ +static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port *port, + struct pci_dev *rp) +{ + return apple_pcie_t6050_port_disable(port, rp) ?: + apple_pcie_t6050_port_enable(port) ?: + apple_pcie_t6050_port_configure(port, rp); +} + +/* Lane clocks, PERST# released, then the LTSSM to link up */ +static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *port) +{ + void __iomem *lane = port->phy + PHY_LANE_CFG; + int ret; + + apple_pcie_t6050_rmw(lane, 0, PHY_LANE_CFG_REFCLK0REQ); + ret = apple_pcie_t6050_wait(port, port->phy, PHY_LANE_CFG, PHY_LANE_CFG_REFCLK0ACK, + PHY_LANE_CFG_REFCLK0ACK, 500000); + if (ret) + return ret; + apple_pcie_t6050_rmw(lane, 0, PHY_LANE_CFG_REFCLK1REQ); + ret = apple_pcie_t6050_wait(port, port->phy, PHY_LANE_CFG, PHY_LANE_CFG_REFCLK1ACK, + PHY_LANE_CFG_REFCLK1ACK, 500000); + if (ret) + return ret; + apple_pcie_t6050_rmw(lane, BIT(4), 0); + udelay(1); + apple_pcie_t6050_rmw(lane, 0, BIT(9)); + apple_pcie_t6050_rmw(lane, 0, BIT(10)); + + /* Tperst-clk is at least 100 us (PCIe CEM r5.0, 2.9.2) */ + usleep_range(100, 110); + ret = apple_pcie_t6050_perst(port, false); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + PORT_LTSSMCTL, 0, PORT_LTSSMCTL_START); + ret = apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, PORT_LINKSTS_UP, + PORT_LINKSTS_UP, 500000); + if (ret) + return ret; + + /* Wait for 100ms after the link trains (PCIe r5.0, 6.6.1) */ + msleep(100); + return 0; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) From b8c92012dfe330a0bb5c494043855ced1c608079 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 037/342] PCI: apple: Adopt T6050 port 0's multi-function N1 and reset its root port The N1 Wi-Fi/Bluetooth sits on apcie0 port 0, which the bootloader now trains like ports 2 and 3. Two things the adoption assumed do not hold for it: - It is multi-function. In its ROM personality only function 0 answers; after its firmware starts, Control, Alpha and Beta (0-2) do. Each function's RID is routed to its own DART stream from the iommu-map (slot == SID) when it is enabled, instead of the one route set at adoption; config accesses on the adopted bus reach every function of device 0; teardown clears every slot it routed. Port 0 is accepted. - Its ROM links at Gen1. Adoption takes an x1 link at Gen1 to Gen3 (the bootloader's target), not only Gen3; the endpoint picks the speed. - After the ROM boot it must come back on a retrained link. The host provides reset_root_port for an adopted port that names its PERST# pad (perst): PME_Turn_Off to L2, PERST#, then the T6050 port disable, reset, enable, configure and train sequences, with the routes and the MSI map rewritten in between. Tunables the boot loader copied onto the root port node are applied; absent ones are skipped. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 9 +- drivers/pci/controller/pcie-apple.c | 218 ++++++++++++++---- 2 files changed, 184 insertions(+), 43 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 5823cc0ff837a..2446facb91d3a 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -242,15 +242,16 @@ allOf: properties: reg: minItems: 5 - maxItems: 14 + maxItems: 18 reg-names: description: config and rc, then port, phy and intr2axi for each - bootloader-trained root port 00:.0. + bootloader-trained root port 00:.0, and perst (its PERST# + pad) for a port whose endpoint needs a root-port reset. minItems: 5 - maxItems: 14 + maxItems: 18 items: - pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" + pattern: "^(config|rc|(port|phy|intr2axi|perst)[0-3])$" interrupts: maxItems: 4 interrupt-names: diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 9048fe5f0c4d2..4ebf2208e9ab0 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -474,14 +474,14 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; - bool adopted_route; void __iomem *intr2axi; /* adopt_link: this port's */ - u16 adopted_rid; /* adopt_link: secondary bus << 8 */ - u32 adopted_sid; + u8 adopted_bus; /* adopt_link: the secondary bus */ + unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); +static struct apple_pcie *apple_pcie_lookup(struct device *dev); static int apple_pcie_radio_check_cold(struct apple_pcie_port *port); static void rmw_set(u32 set, void __iomem *addr) @@ -1570,9 +1570,12 @@ static void apple_pcie_port_teardown(struct apple_pcie_port *port) if (port->pcie->hw->adopt_link && port->domain) apple_pcie_port_writel(port, 0, PORT_MSICFG); - if (port->adopted_route) { - apple_pcie_rid2sid_write(port, port->adopted_sid, 0); - port->adopted_route = false; + if (port->adopted_slots) { + int slot; + + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + apple_pcie_rid2sid_write(port, slot, 0); + port->adopted_slots = 0; } if (port->pcie->hw->tunneled && (port->started || port->needs_stop)) @@ -1658,9 +1661,60 @@ static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port, return apple_pcie_port_readl(port, offset); } +/* + * The DART stream an adopted port's function `rid` maps to: one T6050 DART stream, nonzero + * and below the RID2SID table size (slot == SID), from the host's iommu-map. + */ +static int apple_pcie_adopted_sid(struct apple_pcie_port *port, u32 rid, u32 *sid) +{ + struct apple_pcie *pcie = port->pcie; + struct of_phandle_args iommu = {}; + int ret; + + if (rid >> 8 != port->adopted_bus) { + /* The PCI core numbers root ports' buses in devfn order: the bootloader must too */ + dev_err(pcie->dev, "port %d: RID %04x is off bus %02x, which the bootloader numbered\n", + port->idx, rid, port->adopted_bus); + return -ENODEV; + } + ret = of_map_iommu_id(pcie->dev->of_node, rid, &iommu); + if (ret) + return ret; + ret = iommu.args_count == 1 && iommu.args[0] && + iommu.args[0] < pcie->hw->max_rid2sid && + iommu.args[0] < BITS_PER_LONG && + of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; + *sid = iommu.args[0]; + of_node_put(iommu.np); + return ret; +} + +/* Route an adopted port's function `rid` to its stream, or confirm the route is in place. */ +static int apple_pcie_adopted_route(struct apple_pcie_port *port, u32 rid) +{ + u32 sid, value, cur; + int ret = apple_pcie_adopted_sid(port, rid, &sid); + + if (ret) + return ret; + value = T6050_ROUTE(rid, sid); + cur = apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)); + if (cur == value && test_bit(sid, &port->adopted_slots)) + return 0; + if (cur & PORT_RID2SID_VALID) + return -EBUSY; + set_bit(sid, &port->adopted_slots); + if (apple_pcie_rid2sid_write(port, sid, value) != value) + return -EIO; + dev_info(port->pcie->dev, "port %d: RID %04x -> SID %u, slot %u\n", + port->idx, rid, sid, sid); + return 0; +} + /* * Qualified J775D handoff of one bootloader-trained port: its root port - * 00:.0 and the single endpoint on its secondary bus, with DMA and + * 00:.0 and the endpoint on its secondary bus (function 0 routed here; a + * multi-function endpoint's other functions when they are enabled), with DMA and * endpoint MSI disabled. Every resource comes from the DT by the port's index * (port, phy, intr2axi, interrupt port, the iommu-map entry for the * endpoint's RID). All checks precede the first PCIe register write. @@ -1670,7 +1724,6 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) static const char *const names[] = { "port%d", "phy%d", "intr2axi%d" }; struct apple_pcie *pcie = port->pcie; struct platform_device *pdev = to_platform_device(pcie->dev); - struct of_phandle_args iommu = {}; void __iomem *rp, *ep; char name[16]; u32 value, bus; @@ -1715,15 +1768,8 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) PCI_COMMAND_MASTER))) return -ENODEV; - port->adopted_rid = bus << 8; - ret = of_map_iommu_id(pcie->dev->of_node, port->adopted_rid, &iommu); - if (ret) - return ret; - ret = iommu.args_count == 1 && iommu.args[0] && - iommu.args[0] < pcie->hw->max_rid2sid && - of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; - port->adopted_sid = iommu.args[0]; - of_node_put(iommu.np); + port->adopted_bus = bus; + ret = apple_pcie_adopted_sid(port, bus << 8, &value); if (ret) return ret; @@ -1731,6 +1777,13 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); if (IS_ERR(port->intr2axi)) return PTR_ERR(port->intr2axi); + /* Only a port whose endpoint needs a root-port reset names its PERST# pad */ + snprintf(name, sizeof(name), "perst%d", port->idx); + if (platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) { + port->perst = devm_platform_ioremap_resource_byname(pdev, name); + if (IS_ERR(port->perst)) + return PTR_ERR(port->perst); + } /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ cap = readb(rp + PCI_CAPABILITY_LIST); @@ -1743,9 +1796,14 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) } if (!cap || i == 48) return -EINVAL; + /* + * x1 at up to the Gen3 target the bootloader set. The endpoint picks the speed: the N1's + * ROM personality links at Gen1 and comes back at Gen3 after its root-port reset. + */ value = readw(rp + cap + PCI_EXP_LNKSTA); - if ((value & (PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != - (PCI_EXP_LNKSTA_CLS_8_0GB | (1 << PCI_EXP_LNKSTA_NLW_SHIFT))) + if ((value & (PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != (1 << PCI_EXP_LNKSTA_NLW_SHIFT) || + (value & PCI_EXP_LNKSTA_CLS) < PCI_EXP_LNKSTA_CLS_2_5GB || + (value & PCI_EXP_LNKSTA_CLS) > PCI_EXP_LNKSTA_CLS_8_0GB) return -ENOLINK; /* Refuse an active endpoint or malformed capability chain. */ @@ -1777,13 +1835,10 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) return -EBUSY; /* The route goes in the slot whose index is the SID, as on J775D's adopted ports. */ - value = T6050_ROUTE(port->adopted_rid, port->adopted_sid); - port->adopted_route = true; - if (apple_pcie_rid2sid_write(port, port->adopted_sid, value) != value) - return -EIO; - dev_info(pcie->dev, "adopted port %d, RID %04x -> SID %u, slot %u\n", - port->idx, port->adopted_rid, port->adopted_sid, port->adopted_sid); - return 0; + ret = apple_pcie_adopted_route(port, bus << 8); + if (!ret) + dev_info(pcie->dev, "adopted port %d, endpoint %02x:00\n", port->idx, bus); + return ret; } /* @@ -2066,8 +2121,7 @@ static int apple_pcie_t6050_port_configure(struct apple_pcie_port *port, struct } /* Disable, reset, enable and configure an adopted port whose endpoint is held in PERST# */ -static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port *port, - struct pci_dev *rp) +static int apple_pcie_t6050_port_restart(struct apple_pcie_port *port, struct pci_dev *rp) { return apple_pcie_t6050_port_disable(port, rp) ?: apple_pcie_t6050_port_enable(port) ?: @@ -2075,7 +2129,7 @@ static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port * } /* Lane clocks, PERST# released, then the LTSSM to link up */ -static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *port) +static int apple_pcie_t6050_port_train(struct apple_pcie_port *port) { void __iomem *lane = port->phy + PHY_LANE_CFG; int ret; @@ -2111,6 +2165,87 @@ static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *po return 0; } +/* + * Root-port reset of an adopted T6050 port, for an endpoint that must come back on a + * retrained link (the N1 after its ROM boot): PME_Turn_Off to L2, PERST# asserted, the + * port disabled, reset, enabled and configured, its routes and MSI map rewritten, then the + * lane PHY, PERST# release and LTSSM to a Gen3 x1 link. The caller has quiesced the + * endpoint and saved the root port's state; the PCI core restores it. + */ +static int apple_pcie_t6050_reset_root_port(struct pci_host_bridge *bridge, + struct pci_dev *rp) +{ + struct pci_config_window *cfg = rp->sysdata; + struct apple_pcie *pcie = apple_pcie_lookup(cfg->parent); + struct apple_pcie_port *port = NULL, *p; + u32 routes[BITS_PER_LONG], value; + int ret, slot, i; + + if (!pcie || !pcie->hw->adopt_link || !pci_is_root_bus(rp->bus)) + return -EOPNOTSUPP; + list_for_each_entry(p, &pcie->ports, entry) + if (p->idx == PCI_SLOT(rp->devfn)) + port = p; + if (!port || !port->perst || !port->intr2axi) + return -EOPNOTSUPP; + + mutex_lock(&pcie->lock); + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + routes[slot] = apple_pcie_port_readl(port, port_rid2sid_offset(port, slot)); + + /* Bridge decoding off and the secondary bus unnumbered while the link is down */ + ret = pcibios_err_to_errno(pci_write_config_word(rp, PCI_COMMAND, 0)) ?: + pcibios_err_to_errno(pci_read_config_dword(rp, PCI_PRIMARY_BUS, &value)) ?: + pcibios_err_to_errno(pci_write_config_dword(rp, PCI_PRIMARY_BUS, + value & 0xff0000ff)); + if (ret) + goto out; + /* PME_Turn_Off, then L2 */ + apple_pcie_port_writel(port, apple_pcie_port_readl(port, PORT_APPCLK) | 0x100, PORT_APPCLK); + apple_pcie_port_writel(port, 0x11, 0x88); + ret = apple_pcie_t6050_wait(port, port->base, 0x88, 1, 0, 500000) ?: + apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, BIT(6), BIT(6), 500000); + if (ret) + goto out; + WRITE_ONCE(port->link_failed, true); + ret = apple_pcie_t6050_perst(port, true); + if (ret) + goto out; + writel(readl(port->phy) & ~BIT(31), port->phy); + ret = apple_pcie_t6050_port_restart(port, rp); + if (ret) + goto out; + + /* The reset table cleared the routes and the MSI setup: put back what Linux set */ + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + if (apple_pcie_rid2sid_write(port, slot, routes[slot]) != routes[slot]) + ret = -EIO; + apple_pcie_port_writel(port, lower_32_bits(DOORBELL_ADDR), pcie->hw->port_msiaddr); + if (pcie->hw->port_msiaddr_hi) + apple_pcie_port_writel(port, 0, pcie->hw->port_msiaddr_hi); + for (i = 0; i < pcie->nvecs; i++) + apple_pcie_port_writel(port, FIELD_PREP(PORT_MSIMAP_TARGET, pcie->msi_vector_base + i) | + PORT_MSIMAP_ENABLE, pcie->hw->port_msimap + 4 * i); + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + readl(port->intr2axi + 0x84); + apple_pcie_port_writel(port, PORT_MSICFG_EN, PORT_MSICFG); + if (ret) + goto out; + + ret = apple_pcie_t6050_port_train(port); + if (ret) + goto out; + /* Link interrupts stay masked after the reset table: the link is checked on access */ + apple_pcie_port_writel(port, ~0, PORT_INTSTAT); + WRITE_ONCE(port->link_failed, false); + dev_info(pcie->dev, "port %d: link retrained after a root-port reset\n", port->idx); +out: + mutex_unlock(&pcie->lock); + if (ret) + dev_err(pcie->dev, "port %d: root-port reset stopped: %d\n", port->idx, ret); + return ret; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) @@ -2936,11 +3071,14 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d of_node_put(iommu_spec.np); sid = iommu_spec.args[0]; - if (pcie->hw->adopt_link) - return rid == port->adopted_rid && sid == port->adopted_sid && - !READ_ONCE(port->link_failed) && - apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)) == - T6050_ROUTE(rid, sid) ? 0 : -ENODEV; + if (pcie->hw->adopt_link) { + if (READ_ONCE(port->link_failed)) + return -ENODEV; + mutex_lock(&pcie->lock); + err = apple_pcie_adopted_route(port, rid); + mutex_unlock(&pcie->lock); + return err; + } mutex_lock(&port->pcie->lock); if (port->pcie->managed_sids || port->pcie->hw->sid_indexed_rid2sid) { @@ -3075,16 +3213,16 @@ static void __iomem *apple_pcie_map_bus(struct pci_bus *bus, struct apple_pcie_port *port; if (pcie->hw->adopt_link) { - /* Only adopted ports' root ports, and the one endpoint behind each. */ + /* Only adopted ports' root ports, and the endpoint behind each. */ list_for_each_entry(port, &pcie->ports, entry) { if (bus->number == 0) { if (devfn == PCI_DEVFN(port->idx, 0)) return pci_ecam_map_bus(bus, devfn, where); continue; } - if (bus->number != port->adopted_rid >> 8) + if (bus->number != port->adopted_bus) continue; - if (devfn || READ_ONCE(port->link_failed)) + if (PCI_SLOT(devfn) || READ_ONCE(port->link_failed)) return NULL; if ((apple_pcie_port_readl(port, PORT_LINKSTS) & (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP) { @@ -3675,9 +3813,9 @@ static int apple_pcie_probe(struct platform_device *pdev) for_each_available_child_of_node_scoped(dev->of_node, child) { u32 reg; - /* A root port 00:.0 on bus 0, n a GP port */ + /* A root port 00:.0 on bus 0, n a GP port (0-3) */ if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || - !(reg >> 11) || (reg >> 11) > 3 || + (reg >> 11) > 3 || !of_property_read_bool(child, "apple,link-trained-by-bootloader") || of_property_present(child, "reset-gpios") || of_property_present(child, "pwren-gpios")) @@ -3800,6 +3938,8 @@ static int apple_pcie_probe(struct platform_device *pdev) } } + if (hw->adopt_link) + bridge->reset_root_port = apple_pcie_t6050_reset_root_port; ret = pci_host_common_init(pdev, bridge, &apple_pcie_cfg_ecam_ops); if (ret) { apple_pcie_cleanup(pcie); From 2b7607519da94a9a599cc6b2cece6c3098167479 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 23:53:26 -0800 Subject: [PATCH 038/342] PCI: apple: Drive T6050 port 0's PERST# through the pin controller The adopted port 0 named its PERST# pad as a 4-byte reg of the host (perst0, one word inside the pin controller's block) and wrote it raw. With the pin controller in the device tree the two nodes claim the same MMIO word, and whichever probes second fails: when pinctrl wins, the host's port setup stops with -EBUSY and no port is adopted, so the Ethernet and USB behind ports 2 and 3 are gone with it. One owner for the pad: the pin controller. The port node carries reset-gpios, as every other Apple host's port nodes do, and the host takes the line as the bootloader left it (GPIOD_ASIS: probe never touches a trained link's reset) and drives it only in the root-port reset, as a GPIO output at the logical level the reset asks for. The raw pad write set the same things (function bits cleared, mode output, the data bit) plus the pad's input enable, which the pin controller leaves as the bootloader set it. Probe asks for the line before any port is set up, so a host whose pin controller is not up yet defers instead of adopting nothing; an adopted port without reset-gpios has no reset, as before (reset_root_port answers -EOPNOTSUPP). The perst reg, its binding entry and the raw pad write go; the binding allows reset-gpios on an adopted port again. Probe names the port whose line it cannot have, as the probe of the other hosts' ports does: a line the pin controller reserves (gpio-reserved-ranges) is refused with -EINVAL, which the host's probe otherwise returned with no word of which port or property. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 15 +++--- drivers/pci/controller/pcie-apple.c | 49 +++++++++++-------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 2446facb91d3a..64f0a2d43e9aa 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -242,16 +242,15 @@ allOf: properties: reg: minItems: 5 - maxItems: 18 + maxItems: 14 reg-names: description: config and rc, then port, phy and intr2axi for each - bootloader-trained root port 00:.0, and perst (its PERST# - pad) for a port whose endpoint needs a root-port reset. + bootloader-trained root port 00:.0. minItems: 5 - maxItems: 18 + maxItems: 14 items: - pattern: "^(config|rc|(port|phy|intr2axi|perst)[0-3])$" + pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" interrupts: maxItems: 4 interrupt-names: @@ -267,7 +266,11 @@ allOf: patternProperties: "^pci@": properties: - reset-gpios: false + reset-gpios: + description: + The PERST# line of a port whose endpoint needs a root-port + reset after the bootloader trained the link. Left as the + bootloader set it until that reset. pwren-gpios: false required: - apple,link-trained-by-bootloader diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 4ebf2208e9ab0..349e008bb0154 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -458,7 +458,7 @@ struct apple_pcie_port { struct device_node *np; void __iomem *base; void __iomem *phy; - /* PERST# of a conventional port with a single reset line. */ + /* PERST# of a conventional or adopted port with a single reset line. */ struct gpio_desc *perst; struct irq_domain *domain; struct list_head entry; @@ -477,7 +477,6 @@ struct apple_pcie_port { void __iomem *intr2axi; /* adopt_link: this port's */ u8 adopted_bus; /* adopt_link: the secondary bus */ unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ - void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -1777,12 +1776,18 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); if (IS_ERR(port->intr2axi)) return PTR_ERR(port->intr2axi); - /* Only a port whose endpoint needs a root-port reset names its PERST# pad */ - snprintf(name, sizeof(name), "perst%d", port->idx); - if (platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) { - port->perst = devm_platform_ioremap_resource_byname(pdev, name); - if (IS_ERR(port->perst)) + /* + * Only a port whose endpoint needs a root-port reset names its PERST# line + * (reset-gpios, on the port node as on every other Apple host). The pin + * controller owns the pad; the line is taken as the bootloader left it, + * released, and driven only by the reset. + */ + port->perst = devm_fwnode_gpiod_get(pcie->dev, of_fwnode_handle(port->np), "reset", + GPIOD_ASIS, "PERST#"); + if (IS_ERR(port->perst)) { + if (PTR_ERR(port->perst) != -ENOENT) return PTR_ERR(port->perst); + port->perst = NULL; } /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ @@ -1940,20 +1945,14 @@ static int apple_pcie_t6050_tune(struct apple_pcie_port *port, struct pci_dev *r return 0; } -/* PERST# through its pad: a GPIO output (function bits cleared) at the level asked for */ +/* + * PERST# through the pin controller: the pad as a GPIO output (its function bits + * cleared, mode output) at the line's logical level, which the DT's + * GPIO_ACTIVE_LOW turns into the pad level. + */ static int apple_pcie_t6050_perst(struct apple_pcie_port *port, bool asserted) { - u32 old, value; - - old = readl(port->perst); - if (old & BIT(21)) - return -EIO; - value = (old & ~0x27f) | 0x202 | !asserted; - /* The input enable (bit 9) goes on after the rest */ - writel((value & ~0x200) | (old & 0x200), port->perst); - if (!(old & 0x200)) - writel(value, port->perst); - return (readl(port->perst) ^ value) & 0x27f ? -EIO : 0; + return gpiod_direction_output(port->perst, asserted); } /* Let the link go idle, hold the endpoint in reset and stop the port and its lane clocks */ @@ -3817,9 +3816,19 @@ static int apple_pcie_probe(struct platform_device *pdev) if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || (reg >> 11) > 3 || !of_property_read_bool(child, "apple,link-trained-by-bootloader") || - of_property_present(child, "reset-gpios") || of_property_present(child, "pwren-gpios")) return -EINVAL; + /* + * A port whose endpoint needs a root-port reset names its PERST# + * line: probe waits for the line's controller before any port is + * touched (a failed adoption would otherwise swallow the deferral). + */ + if (of_property_present(child, "reset-gpios")) { + ret = apple_pcie_probe_port(child); + if (ret) + return dev_err_probe(dev, ret, "Port %pOF probe fail\n", + child); + } } } else if (!hw->tunneled) { /* Check for probe dependencies for all ports first */ From 911da8c5008a05f69cffb1cc1169a598c9138117 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 01:06:09 -0500 Subject: [PATCH 039/342] selftests: apple: Preserve multiline PCIe macros in policy tests The PCIe-C policy test extracts driver macro definitions to compile its production-code fixture. Taking only the first physical line truncates T6050_ROUTE and joins the following directive to its trailing backslash, so the fixture fails to compile after the T6050 host support is added. Copy continuation lines along with their define. The production fixture and both negative controls now pass. Developed with Claude Code. Signed-off-by: Erik Bourget --- tools/asahi/pciec-policy-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index 825caefac0912..60442d60b8410 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -144,7 +144,7 @@ def main(): args = parser.parse_args() pci = (ROOT / 'drivers/pci/controller/pcie-apple.c').read_text() acio = (ROOT / 'drivers/thunderbolt/apple.c').read_text() - defines = '\n'.join(re.findall(r'^#define .*$', pci, re.M)) + defines = '\n'.join(re.findall(r'^#define (?:[^\n]*\\\n)*[^\n]*$', pci, re.M)) info = pci[pci.index('struct hw_info {'):pci.index('static const struct of_device_id apple_pcie_of_match[];')] matches = re.search(r'static const struct of_device_id apple_pcie_of_match\[\] = \{.*?\n\};', pci, re.S)[0] production = '\n'.join((defines, info, matches, From ed3d647659522c42f2cc9b182b957464b984a357 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 17:08:37 +1100 Subject: [PATCH 040/342] soc: apple: sep: sep-key: Touch ID keys the enclave guards Add SEP_KEY_CREATE_BIOMETRY_CURRENT_SET (interface version 2). Such a key's record carries the access-control list macOS gives a Secure Enclave key made with .biometryCurrentSet: signing, key agreement and derivation need a biometric credential for this catacomb and enrolled set; delete and attest are free. The kernel reads the catacomb id and enrolled-set hash with SBIO 0x33 and 0x36 (read only) and puts the list in the create request (`ed`); the enclave keeps it in the record and enforces it on every later operation. Adding or removing a finger changes the hash and makes the key unusable. SEP_KEY_SIGN on such a key waits up to 30 s for a touch. Inside that one call the kernel opens a fresh credential context, evaluates the signing constraint on it (ACM command 0x20, best effort), runs one Touch ID match in it through the normal verify path (ACM match mode, MATCH_CANCEL, the same lockout counting and template persistence as any verify), signs with the context (`acmh`) and deletes the context before returning. No handle to the context ever reaches userspace, so a satisfied context cannot outlive the signature it was opened for: every signature needs its own touch. While it runs, the verify belongs to the ioctl, not to /dev/sep-bio's session; it serialises with that session's work on the catacomb writer lock and never reuses its open prompt. SEP_KEY_SELFTEST (test only: apple_sep.key_selftest=1 and root) signs a biometric key under deliberately unsuitable contexts: none, one with no match, one holding only the key-bag secret (the Linux passcode), a deleted one, and, with one touch, the matched context after it was deleted. It reports the enclave's answer, so the refusal is seen to come from the enclave. The request layouts follow our own trace of macOS 26.6.2 creating and using such keys through public APIs. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/der.rs | 7 + drivers/soc/apple/key.rs | 504 +++++++++++++++++++++++++++++++-- drivers/soc/apple/refkey.rs | 61 ++-- drivers/soc/apple/sbio.rs | 111 +++++++- drivers/soc/apple/scrd.rs | 29 ++ drivers/soc/apple/sep.rs | 16 ++ include/uapi/linux/apple-sep.h | 49 +++- 7 files changed, 709 insertions(+), 68 deletions(-) diff --git a/drivers/soc/apple/der.rs b/drivers/soc/apple/der.rs index fcd198561872f..19acef903feb7 100644 --- a/drivers/soc/apple/der.rs +++ b/drivers/soc/apple/der.rs @@ -8,6 +8,7 @@ use kernel::prelude::*; const TAG_SET: u8 = 0x31; const TAG_SEQUENCE: u8 = 0x30; const TAG_UTF8: u8 = 0x0c; +const TAG_BOOLEAN: u8 = 0x01; pub(crate) const TAG_INTEGER: u8 = 0x02; pub(crate) const TAG_OCTET_STRING: u8 = 0x04; @@ -51,6 +52,8 @@ pub(crate) enum RefKeyValue<'a> { Integer(u32), Octets(&'a [u8]), Der(&'a [u8]), + /// BOOLEAN, encoded as the key store writes it (true = 0x01). + Bool(bool), } /// Canonical DER `SET OF SEQUENCE`, members sorted by key — the shape the @@ -85,6 +88,10 @@ pub(crate) fn encode_refkey_set(items: &[(&[u8], RefKeyValue<'_>)]) -> Result inner.extend_from_slice(d, GFP_KERNEL)?, + RefKeyValue::Bool(b) => { + put_header(&mut inner, TAG_BOOLEAN, 1)?; + inner.push(u8::from(*b), GFP_KERNEL)?; + } } let mut seq = KVec::new(); put_header(&mut seq, TAG_SEQUENCE, inner.len())?; diff --git a/drivers/soc/apple/key.rs b/drivers/soc/apple/key.rs index d92d50716cc03..aa991b4639fd0 100644 --- a/drivers/soc/apple/key.rs +++ b/drivers/soc/apple/key.rs @@ -8,10 +8,17 @@ //! A handle works on the Mac that created it and nowhere else. Signing takes a //! 32-byte digest and returns a DER `ECDSA-Sig-Value`. //! -//! There is no access control in this version: anyone who can open the node -//! and holds a handle can sign with it. The `flags` words are reserved for an -//! enclave-enforced policy and must be zero. +//! A key made with `CREATE_BIOMETRY_CURRENT_SET` carries an access-control +//! list in its record, the one macOS gives a Secure Enclave key made with +//! `.biometryCurrentSet`: signing (and key agreement) needs a credential +//! context in which the enclave itself saw a match of one of the fingers +//! enrolled now. The kernel opens that context inside the `SIGN` call, runs a +//! Touch ID match in it, signs, and deletes it before the call returns. No +//! handle to it ever reaches userspace, and every signature needs its own +//! touch. The enclave refuses the signature for any other context; the +//! header's flag only tells the kernel to ask for the touch. +use crate::der::RefKeyValue as RV; use crate::SepData; use kernel::ioctl::{_IOR, _IOWR}; use kernel::prelude::*; @@ -22,18 +29,28 @@ pub(crate) const DEVICE_NAME: &CStr = c"sep-key"; /// Root only by default; distributions grant a group with a udev rule. pub(crate) const DEVICE_MODE: u16 = 0o600; -pub(crate) const IFACE_VERSION: u32 = 1; +pub(crate) const IFACE_VERSION: u32 = 2; pub(crate) const HANDLE_MAX: usize = 2048; pub(crate) const PUB_LEN: usize = 65; pub(crate) const DIGEST_LEN: usize = 32; pub(crate) const SIG_MAX: usize = 72; +/// `CREATE` flag: signing needs a Touch ID match of a currently enrolled +/// finger, enforced by the enclave. +pub(crate) const CREATE_BIOMETRY_CURRENT_SET: u32 = 1; +const CREATE_FLAGS: u32 = CREATE_BIOMETRY_CURRENT_SET; + +/// How long a touch-gated `SIGN` waits for a finger in all. +const TOUCH_WAIT_MS: u64 = 30_000; + const MAGIC: u32 = 0xB1; /// Handle header: `"SEPK"`, version, flags, reserved u16, blob length (LE u32). const HANDLE_MAGIC: &[u8; 4] = b"SEPK"; const HANDLE_VERSION: u8 = 1; +/// Handle flag: the record carries a biometric access-control list. +pub(crate) const HANDLE_BIOMETRY: u8 = 0x01; pub(crate) const HANDLE_HEADER: usize = 12; /// The largest enclave record a handle can carry. pub(crate) const BLOB_MAX: usize = HANDLE_MAX - HANDLE_HEADER; @@ -41,7 +58,7 @@ pub(crate) const BLOB_MAX: usize = HANDLE_MAX - HANDLE_HEADER; #[repr(C)] pub(crate) struct Info { pub(crate) version: u32, - /// `flags` bits `CREATE` and `SIGN` accept; zero in this version. + /// `flags` bits `CREATE` accepts. pub(crate) flags_supported: u32, pub(crate) handle_max: u32, pub(crate) reserved: u32, @@ -75,10 +92,40 @@ pub(crate) struct Public { pub(crate) handle: [u8; HANDLE_MAX], } +/// Test only (module parameter `key_selftest`, root): sign with a +/// biometric key under a deliberately unsuitable context. +#[repr(C)] +pub(crate) struct Selftest { + pub(crate) mode: u32, + pub(crate) handle_len: u32, + pub(crate) digest: [u8; DIGEST_LEN], + /// 0 when the enclave signed, else the negative errno. + pub(crate) result: i32, + /// The enclave's status for that signature. + pub(crate) enclave_status: i32, + /// `SELFTEST_TOUCH_THEN_DELETED`: the second signature. + pub(crate) result2: i32, + pub(crate) enclave_status2: i32, + pub(crate) handle: [u8; HANDLE_MAX], +} + +/// No credential context at all. +pub(crate) const SELFTEST_NO_CONTEXT: u32 = 1; +/// A fresh context in which nothing has matched. +pub(crate) const SELFTEST_UNSATISFIED: u32 = 2; +/// A context holding only the key bag's secret (Linux's "passcode"). +pub(crate) const SELFTEST_PASSCODE: u32 = 3; +/// A fresh context, deleted before the signature. +pub(crate) const SELFTEST_DELETED: u32 = 4; +/// One touch: sign in the matched context, delete it, sign again with it +/// (needs a finger). +pub(crate) const SELFTEST_TOUCH_THEN_DELETED: u32 = 5; + static_assert!(core::mem::size_of::() == 16); static_assert!(core::mem::size_of::() == 2124); static_assert!(core::mem::size_of::() == 2164); static_assert!(core::mem::size_of::() == 2124); +static_assert!(core::mem::size_of::() == 2104); // SAFETY: `repr(C)` with no padding (the asserts above), so each value is a // faithful byte image and every bit pattern is a valid value. @@ -95,45 +142,51 @@ unsafe impl kernel::transmute::FromBytes for Sign {} unsafe impl kernel::transmute::AsBytes for Public {} // SAFETY: as above. unsafe impl kernel::transmute::FromBytes for Public {} +// SAFETY: as above. +unsafe impl kernel::transmute::AsBytes for Selftest {} +// SAFETY: as above. +unsafe impl kernel::transmute::FromBytes for Selftest {} pub(crate) const IOC_INFO: u32 = _IOR::(MAGIC, 0x20); pub(crate) const IOC_CREATE: u32 = _IOWR::(MAGIC, 0x21); pub(crate) const IOC_SIGN: u32 = _IOWR::(MAGIC, 0x22); pub(crate) const IOC_PUBLIC: u32 = _IOWR::(MAGIC, 0x23); +pub(crate) const IOC_SELFTEST: u32 = _IOWR::(MAGIC, 0x24); pub(crate) fn info() -> Info { Info { version: IFACE_VERSION, - flags_supported: 0, + flags_supported: CREATE_FLAGS, handle_max: HANDLE_MAX as u32, reserved: 0, } } -/// Writes the handle for `blob` into `out`; returns its length. -pub(crate) fn encode_handle(blob: &[u8], out: &mut [u8; HANDLE_MAX]) -> Result { - if blob.is_empty() || blob.len() > BLOB_MAX { +/// Writes the handle for `blob` with `flags` into `out`; returns its length. +pub(crate) fn encode_handle(blob: &[u8], flags: u8, out: &mut [u8; HANDLE_MAX]) -> Result { + if blob.is_empty() || blob.len() > BLOB_MAX || flags & !HANDLE_BIOMETRY != 0 { return Err(EINVAL); } let len = u32::try_from(blob.len()).map_err(|_| EINVAL)?; out.fill(0); out[..4].copy_from_slice(HANDLE_MAGIC); out[4] = HANDLE_VERSION; - out[5] = 0; + out[5] = flags; out[8..12].copy_from_slice(&len.to_le_bytes()); out[HANDLE_HEADER..HANDLE_HEADER + blob.len()].copy_from_slice(blob); Ok(HANDLE_HEADER + blob.len()) } -/// The enclave record inside the first `len` bytes of `handle`. Refuses an -/// unknown version, any flag, a non-zero reserved field or a length that does -/// not match exactly. -pub(crate) fn decode_handle(handle: &[u8; HANDLE_MAX], len: u32) -> Result<&[u8]> { +/// The enclave record inside the first `len` bytes of `handle`, and the +/// handle's flags. Refuses an unknown version or flag, a non-zero reserved +/// field or a length that does not match exactly. The flags are not +/// authenticated; the enclave enforces the record's own list either way. +pub(crate) fn decode_handle(handle: &[u8; HANDLE_MAX], len: u32) -> Result<(&[u8], u8)> { let len = len as usize; if !(HANDLE_HEADER + 1..=HANDLE_MAX).contains(&len) { return Err(EINVAL); } - if &handle[..4] != HANDLE_MAGIC || handle[4] != HANDLE_VERSION || handle[5] != 0 { + if &handle[..4] != HANDLE_MAGIC || handle[4] != HANDLE_VERSION || handle[5] & !HANDLE_BIOMETRY != 0 { return Err(EINVAL); } if handle[6] != 0 || handle[7] != 0 { @@ -143,7 +196,7 @@ pub(crate) fn decode_handle(handle: &[u8; HANDLE_MAX], len: u32) -> Result<&[u8] if blob_len != len - HANDLE_HEADER { return Err(EINVAL); } - Ok(&handle[HANDLE_HEADER..len]) + Ok((&handle[HANDLE_HEADER..len], handle[5])) } /// Copies a DER signature into the reply; refuses one that does not fit. @@ -157,6 +210,75 @@ pub(crate) fn put_signature(sig: &[u8], out: &mut Sign) -> Result<()> { Ok(()) } +/// The access-control list of a biometry-current-set key, in the key +/// store's DER, and the constraint its signing operation carries. +/// +/// As macOS writes it for `.privateKeyUsage | .biometryCurrentSet`: sign, +/// key agreement (`ock`) and derivation (`okd`) need a biometric credential +/// (`cbio`) for this catacomb (`pbioc`) and enrolled set (`pbioh`); delete +/// (`odel`) and attest (`oa`) are free. +pub(crate) struct BioAcl { + pub(crate) ed: KVec, + pub(crate) constraint: KVec, +} + +pub(crate) fn bio_acl(catacomb: &[u8; 16], enrolled_hash: &[u8; 32]) -> Result { + let cbio = crate::der::encode_refkey_set(&[ + (b"pbioc".as_slice(), RV::Octets(catacomb)), + (b"pbioh".as_slice(), RV::Octets(enrolled_hash)), + ])?; + let constraint = crate::der::encode_refkey_set(&[(b"cbio".as_slice(), RV::Der(&cbio))])?; + let acl = crate::der::encode_refkey_set(&[ + (b"oa".as_slice(), RV::Bool(true)), + (b"ock".as_slice(), RV::Der(&constraint)), + (b"odel".as_slice(), RV::Bool(true)), + (b"okd".as_slice(), RV::Der(&constraint)), + (b"osgn".as_slice(), RV::Der(&constraint)), + ])?; + let ed = crate::der::encode_refkey_set(&[(b"acl".as_slice(), RV::Der(&acl))])?; + Ok(BioAcl { ed, constraint }) +} + +/// What one verify run of a touch-gated signature ended with. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) enum TouchOutcome { + Matched, + NoMatch, + Failed(u32), +} + +/// The touch-gated signature a `SIGN` call is waiting for. Lives only for +/// that call; the verify it runs fills it in. +pub(crate) struct KeyTouch { + blob: KVec, + digest: [u8; DIGEST_LEN], + constraint: KVec, + sign_again_after_delete: bool, + outcome: Option, + sig: Option>>, + status: i32, + again: Option>>, + again_status: i32, +} + +impl KeyTouch { + pub(crate) fn set_outcome(&mut self, outcome: &crate::bio::VerifyOutcome) { + self.outcome = Some(match outcome { + crate::bio::VerifyOutcome::Matched(_) => TouchOutcome::Matched, + crate::bio::VerifyOutcome::NoMatch => TouchOutcome::NoMatch, + crate::bio::VerifyOutcome::Failed(s) => TouchOutcome::Failed(*s), + }); + } +} + +fn errno_of(r: &Option>) -> i32 { + match r { + Some(Ok(_)) => 0, + Some(Err(e)) => e.to_errno(), + None => EIO.to_errno(), + } +} + #[::kernel::macros::kunit_tests(apple_sep_key_handle)] mod tests { use super::*; @@ -172,16 +294,16 @@ mod tests { #[test] fn round_trip() { let mut h = [0u8; HANDLE_MAX]; - let n = encode_handle(&blob(), &mut h).unwrap(); + let n = encode_handle(&blob(), 0, &mut h).unwrap(); assert_eq!(n, HANDLE_HEADER + 100); assert_eq!(&h[..4], b"SEPK"); - assert_eq!(decode_handle(&h, n as u32).unwrap(), &blob()[..]); + assert_eq!(decode_handle(&h, n as u32).unwrap(), (&blob()[..], 0)); } #[test] fn length_must_match_exactly() { let mut h = [0u8; HANDLE_MAX]; - let n = encode_handle(&blob(), &mut h).unwrap() as u32; + let n = encode_handle(&blob(), 0, &mut h).unwrap() as u32; assert!(decode_handle(&h, n - 1).is_err()); assert!(decode_handle(&h, n + 1).is_err()); assert!(decode_handle(&h, 0).is_err()); @@ -191,8 +313,8 @@ mod tests { #[test] fn header_fields_are_checked() { let mut h = [0u8; HANDLE_MAX]; - let n = encode_handle(&blob(), &mut h).unwrap() as u32; - for at in [0usize, 4, 5, 6, 7] { + let n = encode_handle(&blob(), 0, &mut h).unwrap() as u32; + for at in [0usize, 4, 6, 7] { let mut bad = h; bad[at] ^= 0x01; assert!(decode_handle(&bad, n).is_err()); @@ -202,11 +324,11 @@ mod tests { #[test] fn empty_and_oversize_blobs_are_refused() { let mut h = [0u8; HANDLE_MAX]; - assert!(encode_handle(&[], &mut h).is_err()); + assert!(encode_handle(&[], 0, &mut h).is_err()); let big = [1u8; BLOB_MAX + 1]; - assert!(encode_handle(&big, &mut h).is_err()); + assert!(encode_handle(&big, 0, &mut h).is_err()); let max = [1u8; BLOB_MAX]; - assert_eq!(encode_handle(&max, &mut h).unwrap(), HANDLE_MAX); + assert_eq!(encode_handle(&max, 0, &mut h).unwrap(), HANDLE_MAX); } #[test] @@ -224,6 +346,43 @@ mod tests { put_signature(&[0x30, 0x02, 0x01, 0x01], &mut s).unwrap(); assert_eq!(s.sig_len, 4); } + + #[test] + fn biometry_flag_round_trips_and_unknown_flags_are_refused() { + let mut h = [0u8; HANDLE_MAX]; + let n = encode_handle(&blob(), HANDLE_BIOMETRY, &mut h).unwrap() as u32; + assert_eq!(decode_handle(&h, n).unwrap().1, HANDLE_BIOMETRY); + assert!(encode_handle(&blob(), 0x02, &mut h).is_err()); + let mut bad = h; + bad[5] = 0x02; + assert!(decode_handle(&bad, n).is_err()); + } + + #[test] + fn biometric_acl_has_the_key_store_shape() { + let acl = bio_acl(&[0x11; 16], &[0x22; 32]).unwrap(); + // SET { SEQ { "cbio", SET { SEQ { "pbioc", OCTETS[16] }, SEQ { "pbioh", OCTETS[32] } } } } + assert_eq!(acl.constraint.len(), 2 + 2 + 6 + 2 + (2 + 7 + 18) + (2 + 7 + 34)); + assert_eq!(&acl.constraint[..2], &[0x31, 0x50]); + assert_eq!(&acl.constraint[4..10], b"\x0c\x04cbio"); + let ed = &acl.ed; + assert_eq!(ed[0], 0x31); + // The list names all five operations; delete and attest are free. + for op in [b"oa".as_slice(), b"ock", b"odel", b"okd", b"osgn"] { + assert!(ed.windows(op.len() + 2).any(|w| w[0] == 0x0c && w[1] as usize == op.len() && &w[2..] == op)); + } + assert!(ed.windows(3).any(|w| w == [0x01u8, 0x01, 0x01].as_slice())); + } + + #[test] + fn acl_constraint_command_has_the_captured_layout() { + let acl = bio_acl(&[0x11; 16], &[0x22; 32]).unwrap(); + let cmd = crate::scrd::scrd_verify_acl_constraint(&[0x33; 16], &acl.constraint, b"ock").unwrap(); + // macOS: 138 bytes for a 94-byte constraint and "ock"; this one is 80 bytes. + assert_eq!(cmd.len(), 8 + 16 + 4 + acl.constraint.len() + 4 + 3 + 1 + 8); + assert_eq!(&cmd[..8], b"DRCS\x20\x00\x00\x02"); + assert_eq!(&cmd[24..28], &(acl.constraint.len() as u32).to_le_bytes()); + } } impl SepData { @@ -251,6 +410,275 @@ impl SepData { Ok(()) } + /// Whether the capture a verify is waiting on is still wanted: the + /// touch-gated signature that owns it, or /dev/sep-bio's live session. + pub(crate) fn capture_live(&self) -> bool { + (self.key_touch_active.load(Relaxed) && !self.shutting_down.load(Relaxed)) + || crate::bio::capture_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) + } + + fn key_bio_acl(&self) -> Result { + if !self.touchid_started.load(Relaxed) { + return Err(ENODEV); + } + let (catacomb, enrolled) = self.catacomb_binding()?; + bio_acl(&catacomb, &enrolled) + } + + /// Evaluates the signing constraint on the fresh context before the + /// match, as LocalAuthentication does. Best effort: logged only. + pub(crate) fn key_touch_preflight(&self, evaluation: &[u8; crate::scrd::SCRD_ACM_HANDLE_LEN]) { + let constraint = { + let guard = self.key_touch.lock(); + let Some(job) = guard.as_ref() else { + return; + }; + let mut c = KVec::new(); + if c.extend_from_slice(&job.constraint, GFP_KERNEL).is_err() { + return; + } + c + }; + let Ok(payload) = crate::scrd::scrd_verify_acl_constraint(evaluation, &constraint, b"osgn") else { + return; + }; + match self.scrd_transact( + c"SCRD_VERIFY_ACL_CONSTRAINT", + crate::scrd::SCRD_REQUEST_COMMAND, + &payload, + crate::SCRD_TIMEOUT_MS, + ) { + Some((reply, out)) => { + let word = |at: usize| { + out.get(at..at + 4) + .map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])) + }; + dev_info!( + self.dev, + "sep-key: signing constraint on the new context: status {}, {} reply bytes, satisfied {:?}, first requirement {:?}\n", + reply.status, + out.len(), + word(0), + word(4) + ); + } + None => dev_info!(self.dev, "sep-key: signing constraint check got no answer\n"), + } + } + + /// Signs the waiting job in `evaluation`, the context the match just + /// satisfied. Called from the verify, at most once with success. + pub(crate) fn key_touch_sign(&self, evaluation: &[u8; crate::scrd::SCRD_ACM_HANDLE_LEN], when: &CStr) { + let (blob, digest) = { + let guard = self.key_touch.lock(); + let Some(job) = guard.as_ref() else { + return; + }; + if matches!(job.sig, Some(Ok(_))) { + return; + } + let mut b = KVec::new(); + if b.extend_from_slice(&job.blob, GFP_KERNEL).is_err() { + return; + } + (b, job.digest) + }; + let r = self.user_key_sign(&blob, &digest, Some(evaluation)); + let status = self.last_key_status.load(Relaxed) as i32; + dev_info!( + self.dev, + "sep-key: touch-gated signature {}: {} (enclave status {})\n", + when, + (if r.is_ok() { "signed" } else { "refused" }), + status + ); + if let Some(job) = &mut *self.key_touch.lock() { + job.sig = Some(r); + job.status = status; + } + } + + /// Self-test only: after the matched context is deleted, sign once more + /// with its old handle. + pub(crate) fn key_touch_after_close(&self, evaluation: &[u8; crate::scrd::SCRD_ACM_HANDLE_LEN]) { + let (blob, digest) = { + let guard = self.key_touch.lock(); + let Some(job) = guard.as_ref() else { + return; + }; + if !job.sign_again_after_delete || !matches!(job.sig, Some(Ok(_))) { + return; + } + let mut b = KVec::new(); + if b.extend_from_slice(&job.blob, GFP_KERNEL).is_err() { + return; + } + (b, job.digest) + }; + let r = self.user_key_sign(&blob, &digest, Some(evaluation)); + let status = self.last_key_status.load(Relaxed) as i32; + dev_info!( + self.dev, + "sep-key: self-test: signature with the deleted matched context: {} (enclave status {})\n", + (if r.is_ok() { "SIGNED" } else { "refused" }), + status + ); + if let Some(job) = &mut *self.key_touch.lock() { + job.again = Some(r); + job.again_status = status; + } + } + + /// A touch-gated signature: one fresh credential context, one Touch ID + /// match in it, the signature, and the context deleted, all inside this + /// call. Waits up to `TOUCH_WAIT_MS` for a finger. + fn key_sign_with_touch(&self, blob: &[u8], digest: &[u8; DIGEST_LEN], again: bool) -> Result { + let acl = self.key_bio_acl()?; + let mut owned = KVec::new(); + owned.extend_from_slice(blob, GFP_KERNEL)?; + // Serialises with /dev/sep-bio's enrol and verify work, as they do + // with each other. + let _writer = self.catacomb_writer.lock(); + *self.key_touch.lock() = Some(KeyTouch { + blob: owned, + digest: *digest, + constraint: acl.constraint, + sign_again_after_delete: again, + outcome: None, + sig: None, + status: 0, + again: None, + again_status: 0, + }); + self.key_touch_active.store(true, Relaxed); + dev_info!(self.dev, "sep-key: waiting for a Touch ID match to sign (up to {} s)\n", TOUCH_WAIT_MS / 1000); + let deadline = crate::shim::boottime_ns().saturating_add(TOUCH_WAIT_MS * 1_000_000); + let ended = loop { + if self.shutting_down.load(Relaxed) { + break Err(ENODEV); + } + if !self.capture_begin() { + break Err(EAGAIN); + } + self.run_verify(); + self.capture_end(); + let outcome = match &mut *self.key_touch.lock() { + Some(job) => job.outcome.take(), + None => None, + }; + match outcome { + Some(TouchOutcome::Matched) => break Ok(()), + Some(TouchOutcome::NoMatch) => break Err(EACCES), + Some(TouchOutcome::Failed(s)) if s == crate::ENROL_STATUS_RETRY => { + if crate::shim::boottime_ns() >= deadline { + break Err(ETIMEDOUT); + } + } + Some(TouchOutcome::Failed(s)) if s == crate::ENROL_STATUS_LOCKOUT => break Err(EACCES), + Some(TouchOutcome::Failed(_)) | None => break Err(EIO), + } + }; + self.key_touch_active.store(false, Relaxed); + let job = self.key_touch.lock().take().ok_or(EIO)?; + dev_info!( + self.dev, + "sep-key: touch-gated signature ended: {:?}, signature {}\n", + ended, + errno_of(&job.sig) + ); + ended?; + Ok(job) + } + + /// A credential context holding only the identity key bag's secret, the + /// Linux stand-in for a passcode (self-test). + fn passcode_context(&self) -> Result<[u8; crate::scrd::SCRD_ACM_HANDLE_LEN]> { + let du = crate::sks::DesignateUser::new(crate::SBIO_PROBE_USER_ID).ok_or(EINVAL)?; + let crate::keybag::State::Present(stored) = crate::keybag::read(crate::keybag::Slot::Identity)? else { + return Err(ENODEV); + }; + let (status, _) = self.scrd_command(&crate::scrd::scrd_initialize()).ok_or(EIO)?; + if status != 0 { + return Err(EIO); + } + let (status, out) = self + .scrd_command(&crate::scrd::scrd_context_create_tracked(crate::SBIO_PROBE_USER_ID)) + .ok_or(EIO)?; + let handle = crate::scrd::tracked_create_reference(&out) + .filter(|_| status == 0) + .ok_or(EIO)?; + let ok = (|| -> Option<()> { + let (status, _) = self.scrd_command(&crate::scrd::scrd_context_externalize(&handle))?; + if status != 0 { + return None; + } + let out = self.sks_send(self.sks_req_verify_secret(du.special_handle(), stored.secret(), &handle))?; + dev_info!(self.dev, "sep-key: self-test: passcode credential added, status {}\n", out.reply.status); + (out.reply.status == 0).then_some(()) + })(); + if ok.is_none() { + self.close_unlock_evaluation(&handle); + return Err(EIO); + } + Ok(handle) + } + + fn key_selftest(&self, req: &mut Selftest) -> Result<()> { + if crate::module_parameters::key_selftest.value() == 0 { + return Err(EPERM); + } + crate::bio::require_admin()?; + let (blob, flags) = decode_handle(&req.handle, req.handle_len)?; + if flags & HANDLE_BIOMETRY == 0 { + return Err(EINVAL); + } + let mut owned = KVec::new(); + owned.extend_from_slice(blob, GFP_KERNEL)?; + let digest = req.digest; + let user = crate::sbio::UserId::new(crate::SBIO_PROBE_USER_ID).ok_or(EINVAL)?; + let record = |r: Result>, s: &SepData| -> (i32, i32) { + (r.err().map(|e| e.to_errno()).unwrap_or(0), s.last_key_status.load(Relaxed) as i32) + }; + self.last_key_status.store(0, Relaxed); + let (result, status) = match req.mode { + SELFTEST_NO_CONTEXT => record(self.user_key_sign(&owned, &digest, None), self), + SELFTEST_UNSATISFIED => { + let ctx = self.open_unlock_evaluation(user).ok_or(EIO)?; + let r = record(self.user_key_sign(&owned, &digest, Some(&ctx)), self); + self.close_unlock_evaluation(&ctx); + r + } + SELFTEST_PASSCODE => { + let ctx = self.passcode_context()?; + let r = record(self.user_key_sign(&owned, &digest, Some(&ctx)), self); + self.close_unlock_evaluation(&ctx); + r + } + SELFTEST_DELETED => { + let ctx = self.open_unlock_evaluation(user).ok_or(EIO)?; + self.close_unlock_evaluation(&ctx); + record(self.user_key_sign(&owned, &digest, Some(&ctx)), self) + } + SELFTEST_TOUCH_THEN_DELETED => { + let job = self.key_sign_with_touch(&owned, &digest, true)?; + req.result2 = errno_of(&job.again); + req.enclave_status2 = job.again_status; + (errno_of(&job.sig), job.status) + } + _ => return Err(EINVAL), + }; + req.result = result; + req.enclave_status = status; + dev_info!( + self.dev, + "sep-key: self-test mode {}: {} (enclave status {})\n", + req.mode, + (if result == 0 { "SIGNED" } else { "refused" }), + status + ); + Ok(()) + } + fn key_ioctl(&self, cmd: u32, arg: usize) -> Result<()> { if self.shutting_down.load(Relaxed) { return Err(ENODEV); @@ -264,11 +692,14 @@ impl SepData { let slice = UserSlice::new(user, core::mem::size_of::()); let (mut reader, mut writer) = slice.reader_writer(); let mut req: Create = reader.read()?; - if req.flags != 0 || req.reserved != [0; 3] { + if req.flags & !CREATE_FLAGS != 0 || req.reserved != [0; 3] { return Err(EINVAL); } - let (blob, point) = self.user_key_create()?; - req.handle_len = encode_handle(&blob, &mut req.handle)? as u32; + let biometry = req.flags & CREATE_BIOMETRY_CURRENT_SET != 0; + let acl = if biometry { Some(self.key_bio_acl()?) } else { None }; + let (blob, point) = self.user_key_create(acl.as_ref().map(|a| &a.ed[..]))?; + let flags = if biometry { HANDLE_BIOMETRY } else { 0 }; + req.handle_len = encode_handle(&blob, flags, &mut req.handle)? as u32; req.public_key = point; writer.write(&req) } @@ -280,8 +711,14 @@ impl SepData { return Err(EINVAL); } let sig = { - let blob = decode_handle(&req.handle, req.handle_len)?; - self.user_key_sign(blob, &req.digest)? + let (blob, flags) = decode_handle(&req.handle, req.handle_len)?; + if flags & HANDLE_BIOMETRY != 0 { + let digest = req.digest; + let job = self.key_sign_with_touch(blob, &digest, false)?; + job.sig.ok_or(EIO)?? + } else { + self.user_key_sign(blob, &req.digest, None)? + } }; put_signature(&sig, &mut req)?; writer.write(&req) @@ -294,7 +731,14 @@ impl SepData { return Err(EINVAL); } req.public_key = - SepData::user_key_public(decode_handle(&req.handle, req.handle_len)?)?; + SepData::user_key_public(decode_handle(&req.handle, req.handle_len)?.0)?; + writer.write(&req) + } + IOC_SELFTEST => { + let slice = UserSlice::new(user, core::mem::size_of::()); + let (mut reader, mut writer) = slice.reader_writer(); + let mut req: Selftest = reader.read()?; + self.key_selftest(&mut req)?; writer.write(&req) } _ => Err(ENOTTY), diff --git a/drivers/soc/apple/refkey.rs b/drivers/soc/apple/refkey.rs index f1c60a815f60b..a8b01c4346e97 100644 --- a/drivers/soc/apple/refkey.rs +++ b/drivers/soc/apple/refkey.rs @@ -87,6 +87,7 @@ impl SepData { &self, handle: crate::sks::KeyBagHandle, secret: &[u8], + acl: Option<&[u8]>, ) -> Option> { use crate::der::RefKeyValue as RV; @@ -126,6 +127,11 @@ impl SepData { { return None; } + // `ed` carries the key's access-control list; the enclave keeps it + // in the record and enforces it on every later operation. + if let Some(acl) = acl { + items.push((b"ed", RV::Der(acl)), GFP_KERNEL).ok()?; + } crate::der::encode_refkey_set(&items).ok()? }; let cout = match self.sks_send(self.sks_req_refkey(handle.value(), &create_der)) { @@ -197,7 +203,7 @@ impl SepData { return; } - let Some(blob) = self.sks_create_refkey(handle, secret) else { + let Some(blob) = self.sks_create_refkey(handle, secret, None) else { dev_warn!( self.dev, "sks: could not create the machine ref-key; trusted-key sealing is unavailable this boot.\n" @@ -309,29 +315,39 @@ impl SepData { } /// Op `osgn`: ECDSA-P256 over `challenge` as the pre-computed digest. - /// `EKEYREJECTED` when the enclave refuses the operation (for example a - /// ref-key record another SEP or another key bag made), `EIO` for no or - /// a malformed reply. + /// `acm` is the credential context an access-controlled key's operation + /// is checked against (`acmh`). `EKEYREJECTED` when the enclave refuses + /// the operation (a record another SEP or key bag made, or an access- + /// control list the context does not satisfy), `EIO` for no or a + /// malformed reply. The enclave's status is logged and kept in + /// `last_key_status` for the self-test. fn sks_refkey_sign( &self, handle: crate::sks::KeyBagHandle, refkey_blob: &[u8], challenge: &[u8], + acm: Option<&[u8; crate::scrd::SCRD_ACM_HANDLE_LEN]>, ) -> Result> { use crate::der::RefKeyValue as RV; let mut items: KVec<(&[u8], RV<'_>)> = KVec::new(); items.push((b"o", RV::Utf8(b"osgn")), GFP_KERNEL)?; items.push((b"d", RV::Octets(challenge)), GFP_KERNEL)?; items.push((b"rk", RV::Der(refkey_blob)), GFP_KERNEL)?; + if let Some(acm) = acm { + items.push((b"acmh", RV::Octets(acm)), GFP_KERNEL)?; + } let der = crate::der::encode_refkey_set(&items)?; - let out = self - .sks_send(self.sks_req_refkey(handle.value(), &der)) - .ok_or(EIO)?; + let Some(out) = self.sks_send(self.sks_req_refkey(handle.value(), &der)) else { + self.last_key_status.store(i32::MIN as u32, Relaxed); + return Err(EIO); + }; + self.last_key_status.store(i32::from(out.reply.status) as u32, Relaxed); if out.reply.status != 0 { dev_warn!( self.dev, - "sks: ref-key sign refused by the enclave (status {})\n", - out.reply.status + "sks: ref-key sign refused by the enclave (status {}{})\n", + out.reply.status, + (if acm.is_some() { ", with a credential context" } else { "" }) ); return Err(EKEYREJECTED); } @@ -376,7 +392,7 @@ impl SepData { )); } }); - let sig = self.sks_refkey_sign(handle, &blob, challenge); + let sig = self.sks_refkey_sign(handle, &blob, challenge, None); let _ = self.sks_send(self.sks_req_unload_keybag(handle)); Ok((sig?, pubk)) } @@ -418,10 +434,14 @@ impl SepData { /// `/dev/sep-key` create: a new enclave P-256 ref-key under the identity /// key bag. Returns its record and public point; the private half stays - /// in the enclave. - pub(crate) fn user_key_create(&self) -> Result<(KVec, [u8; refkey_seal::POINT_LEN])> { + /// in the enclave. With `acl` the record carries that access-control + /// list (see `bio_acl`). + pub(crate) fn user_key_create( + &self, + acl: Option<&[u8]>, + ) -> Result<(KVec, [u8; refkey_seal::POINT_LEN])> { let blob = self.with_identity_bag(|handle, secret| { - self.sks_create_refkey(handle, secret).ok_or(EIO) + self.sks_create_refkey(handle, secret, acl).ok_or(EIO) })?; let mut point = [0u8; refkey_seal::POINT_LEN]; point.copy_from_slice(Self::refkey_pub(&blob).ok_or(EIO)?); @@ -436,12 +456,19 @@ impl SepData { } /// `/dev/sep-key` sign: the enclave's ECDSA-P256 over `digest` with the - /// key in `blob`. A record this SEP and key bag did not make is refused - /// by the enclave (`EKEYREJECTED`). - pub(crate) fn user_key_sign(&self, blob: &[u8], digest: &[u8; 32]) -> Result> { + /// key in `blob`, checked against the credential context `acm` when one + /// is given. A record this SEP and key bag did not make, or an access- + /// control list `acm` does not satisfy, is refused by the enclave + /// (`EKEYREJECTED`). + pub(crate) fn user_key_sign( + &self, + blob: &[u8], + digest: &[u8; 32], + acm: Option<&[u8; crate::scrd::SCRD_ACM_HANDLE_LEN]>, + ) -> Result> { // A record without a public point is not a ref-key record at all. Self::refkey_pub(blob).ok_or(EINVAL)?; - self.with_identity_bag(|handle, _secret| self.sks_refkey_sign(handle, blob, digest)) + self.with_identity_bag(|handle, _secret| self.sks_refkey_sign(handle, blob, digest, acm)) } /// Enclave ECIES-decrypt (o = "oecd"); takes the ephemeral from the front of `d`. diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 1071475e6b461..35476d6e4cc38 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -535,6 +535,30 @@ impl SepData { } } + /// The Linux enclave user's catacomb id and enrolled-set hash, which a + /// key's biometric access-control list names (`pbioc`, `pbioh`). Read + /// only. + pub(crate) fn catacomb_binding( + &self, + ) -> Result<([u8; crate::sbio::SBIO_CATACOMB_ID_LEN], [u8; crate::sbio::SBIO_CATACOMB_HASH_LEN])> { + let user = crate::sbio::UserId::new(SBIO_PROBE_USER_ID).ok_or(EINVAL)?; + let id_reply = self.sbio_expect_ok(&crate::sbio::sbio_catacomb_id(user)).ok_or(EIO)?; + let hash_reply = self.sbio_expect_ok(&crate::sbio::sbio_catacomb_hash(user)).ok_or(EIO)?; + dev_info!( + self.dev, + "sep-key: catacomb id {} bytes, hash {} bytes\n", + id_reply.len(), + hash_reply.len() + ); + if id_reply.len() != crate::sbio::SBIO_CATACOMB_ID_LEN { + return Err(EIO); + } + let mut id = [0u8; crate::sbio::SBIO_CATACOMB_ID_LEN]; + id.copy_from_slice(&id_reply); + let hash = crate::sbio::catacomb_hash_from_reply(&hash_reply).ok_or(EIO)?; + Ok((id, hash)) + } + fn sbio_expect_ok(&self, op: &crate::sbio::SbioOp) -> Option> { match self.sbio_call(op) { SbioOutcome::Ok(payload) => Some(payload), @@ -842,7 +866,7 @@ impl SepData { let mut told = false; let mut first: Option<[u8; sensor::STATUS_LEN]> = None; loop { - if !bio::capture_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) { + if !self.capture_live() { return false; } let Ok(st) = sensor::status() else { @@ -2401,7 +2425,8 @@ impl SepData { /// not ended by a suspend and not closed. fn verify_wanted(&self) -> bool { !self.shutting_down.load(Relaxed) - && bio::verify_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) + && (self.key_touch_active.load(Relaxed) + || bio::verify_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed))) } // Every verify registers the sensor again. On a profile with a nonce @@ -2525,7 +2550,10 @@ impl SepData { // MATCH_CANCEL only after the third). Here a prompt is one open of the // Touch ID device: fprintd claims it for one PAM authentication. let open_gen = self.bio_open_gen.load(Relaxed); - let current = if self.match_scope_gen.load(Relaxed) == open_gen { + let key_mode = self.key_touch_active.load(Relaxed); + // A /dev/sep-key signature is its own prompt: a fresh evaluation that + // never outlives this run, whatever prompt /dev/sep-bio has open. + let current = if !key_mode && self.match_scope_gen.load(Relaxed) == open_gen { *self.match_context.lock() } else { None @@ -2566,6 +2594,9 @@ impl SepData { return; } *self.match_context.lock() = Some(evaluation); + if key_mode { + self.key_touch_preflight(&evaluation); + } self.match_scope_gen.store(open_gen, Relaxed); self.match_scope_touches.store(1, Relaxed); self.match_scope_misses.store(0, Relaxed); @@ -2602,7 +2633,7 @@ impl SepData { let total_misses = self.bio_nomatch_streak.load(Relaxed).saturating_add(miss); self.match_scope_misses.store(prompt_misses, Relaxed); let step = prompt_step(no_match, capture_retry, prompt_misses, total_misses); - let keep_open = !self.enclave_reports_lockout() && step == PromptStep::KeepOpen; + let keep_open = !key_mode && !self.enclave_reports_lockout() && step == PromptStep::KeepOpen; if no_match && !keep_open && prompt_misses >= PROMPT_RETRY_LIMIT @@ -2641,15 +2672,26 @@ impl SepData { } } } - if matches!(outcome, bio::VerifyOutcome::Matched(_)) - && !self.complete_unlock_evaluation(&evaluation, user) - { + let matched = matches!(outcome, bio::VerifyOutcome::Matched(_)); + // The signature runs in the evaluation the match just satisfied, + // before it is completed (as macOS signs after MATCH_CANCEL) and, + // if the enclave wants the completed evaluation, once more after. + if key_mode && matched { + self.key_touch_sign(&evaluation, c"after the match"); + } + if matched && !self.complete_unlock_evaluation(&evaluation, user) { dev_err!(self.dev, "verify: the enclave matched but the unlock policy was not satisfied\n"); outcome = bio::VerifyOutcome::Failed(ENROL_STATUS_ENCLAVE); } + if key_mode && matched { + self.key_touch_sign(&evaluation, c"after the completed evaluation"); + } *self.match_context.lock() = None; self.match_scope_gen.store(0, Relaxed); self.close_unlock_evaluation(&evaluation); + if key_mode && matched { + self.key_touch_after_close(&evaluation); + } } // macOS saves the enclave's lockout record once after every answered // result (SAVE_LOCKOUT, kept on disk for the boot's LOAD_LOCKOUT), @@ -2821,9 +2863,9 @@ impl SepData { } CaptureWait::Abandon => { // A cancelled verify also abandons; only a live one is a fault. - if bio::verify_is_live( - &self.bio_session.lock(), self.capture_epoch.load(Relaxed), - ) { + if self.key_touch_active.load(Relaxed) + || bio::verify_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) + { dev_err!( self.dev, "verify: the sensor status became unreadable during the capture\n" @@ -4084,7 +4126,7 @@ impl SepData { let deadline_ns = crate::shim::monotonic_ns().saturating_add(wait_ms.saturating_mul(1_000_000)); let mut attempt: u32 = 0; loop { - if !bio::capture_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) { + if !self.capture_live() { return CaptureWait::Abandon; } @@ -4827,6 +4869,14 @@ impl SepData { } fn finish_verify(&self, outcome: bio::VerifyOutcome, token_bytes: [u8; bio::TOKEN_LEN]) { + // A touch-gated /dev/sep-key signature owns this verify: its result + // goes to that ioctl, never to /dev/sep-bio's session. + if self.key_touch_active.load(Relaxed) { + if let Some(job) = &mut *self.key_touch.lock() { + job.set_outcome(&outcome); + } + return; + } let filed = bio::verify_finish( &mut self.bio_session.lock(), self.capture_epoch.load(Relaxed), outcome, token_bytes, ); @@ -6411,6 +6461,45 @@ pub(crate) fn sbio_protected_config(id: UserId) -> SbioOp { } } +/// The 16-byte id of `id`'s Touch ID catacomb (the enrolled-template set), +/// as a key access-control list names it. Read only. +const OP_SBIO_CATACOMB_ID: u16 = 0x33; +pub(crate) const SBIO_CATACOMB_ID_LEN: usize = 16; +pub(crate) fn sbio_catacomb_id(id: UserId) -> SbioOp { + SbioOp { + opcode: OP_SBIO_CATACOMB_ID, + payload: pad_payload(&id.value().to_le_bytes()), + payload_len: 4, + name: c"CATACOMB_ID", + } +} + +/// The 32-byte hash of `id`'s enrolled set, which changes when a finger is +/// added or removed. Read only. The reply may lead with one version byte. +const OP_SBIO_CATACOMB_HASH: u16 = 0x36; +pub(crate) const SBIO_CATACOMB_HASH_LEN: usize = 32; +pub(crate) fn sbio_catacomb_hash(id: UserId) -> SbioOp { + SbioOp { + opcode: OP_SBIO_CATACOMB_HASH, + payload: pad_payload(&id.value().to_le_bytes()), + payload_len: 4, + name: c"CATACOMB_HASH", + } +} + +/// The 32-byte hash in a CATACOMB_HASH reply: the bare hash, or one leading +/// version byte and the hash. +pub(crate) fn catacomb_hash_from_reply(reply: &[u8]) -> Option<[u8; SBIO_CATACOMB_HASH_LEN]> { + let raw = match reply.len() { + SBIO_CATACOMB_HASH_LEN => reply, + n if n == SBIO_CATACOMB_HASH_LEN + 1 => &reply[1..], + _ => return None, + }; + let mut out = [0u8; SBIO_CATACOMB_HASH_LEN]; + out.copy_from_slice(raw); + Some(out) +} + const OP_SBIO_BEGIN_ENROL: u16 = 0x03; pub(crate) const BE_AUTH_TYPE_ACM_CONTEXT: u32 = 0; diff --git a/drivers/soc/apple/scrd.rs b/drivers/soc/apple/scrd.rs index fea9b390b6466..bb03acb4a10c7 100644 --- a/drivers/soc/apple/scrd.rs +++ b/drivers/soc/apple/scrd.rs @@ -130,6 +130,35 @@ pub(crate) fn scrd_verify_touchid_enrollment(handle: &[u8; SCRD_ACM_HANDLE_LEN]) } } +const SCRD_CMD_VERIFY_ACL_CONSTRAINT: u8 = 0x20; +const SCRD_ACL_VERSION: u8 = 2; + +/// Command 0x20: evaluate one operation's access-control constraint (a DER +/// set, as in a key's ACL) on the context, as LocalAuthentication does before +/// and after a Touch ID match for a key operation. Laid out as macOS sends it: +/// header, context, u32 constraint length, constraint, u32 operation length, +/// operation, a 1 byte, two zero u32 words. +pub(crate) fn scrd_verify_acl_constraint( + handle: &[u8; SCRD_ACM_HANDLE_LEN], + constraint: &[u8], + operation: &[u8], +) -> Result> { + let mut out = KVec::new(); + let mut header = [0u8; SCRD_MAX_LOGICAL]; + scrd_header(&mut header, SCRD_CMD_VERIFY_ACL_CONSTRAINT, 0, SCRD_ACL_VERSION); + out.extend_from_slice(&header[..8], GFP_KERNEL)?; + out.extend_from_slice(handle, GFP_KERNEL)?; + let clen = u32::try_from(constraint.len()).map_err(|_| EINVAL)?; + out.extend_from_slice(&clen.to_le_bytes(), GFP_KERNEL)?; + out.extend_from_slice(constraint, GFP_KERNEL)?; + let olen = u32::try_from(operation.len()).map_err(|_| EINVAL)?; + out.extend_from_slice(&olen.to_le_bytes(), GFP_KERNEL)?; + out.extend_from_slice(operation, GFP_KERNEL)?; + out.push(1, GFP_KERNEL)?; + out.extend_from_slice(&[0u8; 8], GFP_KERNEL)?; + Ok(out) +} + /// The reference of a tracked context-create reply, or `None` for any /// other shape. pub(crate) fn tracked_create_reference(reply: &[u8]) -> Option<[u8; SCRD_ACM_HANDLE_LEN]> { diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 06b876e928a86..fdc937da60ff2 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -775,6 +775,15 @@ struct SepData { #[pin] key_dev: Mutex>, + // /dev/sep-key: the signature a touch-gated SEP_KEY_SIGN is waiting for. + // Set only for the length of that ioctl; while set, a verify run belongs + // to it and not to /dev/sep-bio's session. + #[pin] + key_touch: Mutex>, + key_touch_active: Atomic, + // The enclave status of the last /dev/sep-key signature (self-test). + last_key_status: Atomic, + // The enclave refused to match (MATCH_RESULT answered 0x1) after failed // attempts, or the lockout survived a restart. Every verify is refused // without a capture until a password authentication re-arms Touch ID. @@ -1061,6 +1070,9 @@ impl SepData { bio_dev <- new_mutex!(None), rearm_dev <- new_mutex!(None), key_dev <- new_mutex!(None), + key_touch <- new_mutex!(None), + key_touch_active: Atomic::new(false), + last_key_status: Atomic::new(0), bio_lockout: Atomic::new(false), bio_lockout_logged: Atomic::new(false), bio_nomatch_streak: Atomic::new(0), @@ -3077,6 +3089,10 @@ module! { default: 0, description: "Opt-in J414s diagnostic: with zero live identities, select the system context and try saving the missing owner Catacomb", }, + key_selftest: u8 { + default: 0, + description: "Test only: let root run SEP_KEY_SELFTEST, which signs with an access-controlled /dev/sep-key key under deliberately unsuitable credential contexts to show the enclave refuses", + }, refkey_v2: u8 { default: 0, description: "Explicit recovery slot for a new identity-bag context; preserves the original machine ref-key", diff --git a/include/uapi/linux/apple-sep.h b/include/uapi/linux/apple-sep.h index 9c1e940a1027e..80b731de98247 100644 --- a/include/uapi/linux/apple-sep.h +++ b/include/uapi/linux/apple-sep.h @@ -213,17 +213,25 @@ struct sep_bio_rearm { * file. Signing takes a 32-byte digest (for ES256/ecdsa-sha2-nistp256, the * SHA-256 of the message) and returns a DER ECDSA-Sig-Value. * - * Interface version 1 has no access control: whoever can open the node and - * holds a handle can sign with it. The node is created 0600; distributions - * may grant a group. Every 'flags' and 'reserved' field must be zero; later - * versions report what they accept in SEP_KEY_GET_INFO. + * A key made without flags has no access control: whoever can open the node + * and holds its handle can sign with it. A key made with + * SEP_KEY_CREATE_BIOMETRY_CURRENT_SET (version 2) carries an access-control + * list the enclave enforces: every signature needs a Touch ID match of a + * finger enrolled when the key was made. SEP_KEY_SIGN then waits (up to 30 s) + * for a touch; the kernel opens a credential context, runs the match in it, + * signs and deletes the context inside that one call. Enrolling or removing a + * finger makes the key unusable. The node is created 0600; distributions may + * grant a group. Unknown 'flags' bits and 'reserved' fields must be zero. * * Errors: EINVAL for a malformed request or handle, EKEYREJECTED when the - * enclave refuses the key (for example a handle from another Mac or an - * earlier Linux install), ENODEV/ETIMEDOUT while the key store is not up, - * EIO for any other enclave failure. + * enclave refuses the key (a handle from another Mac or an earlier Linux + * install, or an access-control list not satisfied), EACCES when the touch + * did not match (or Touch ID is locked out), ETIMEDOUT when no finger came, + * ENODEV while the key store or Touch ID is not up, EIO for any other + * enclave failure. */ -#define SEP_KEY_IFACE_VERSION 1 +#define SEP_KEY_IFACE_VERSION 2 +#define SEP_KEY_CREATE_BIOMETRY_CURRENT_SET 0x1 #define SEP_KEY_HANDLE_MAX 2048 #define SEP_KEY_PUB_LEN 65 /* uncompressed point, 04 || X || Y */ #define SEP_KEY_DIGEST_LEN 32 @@ -231,13 +239,13 @@ struct sep_bio_rearm { struct sep_key_info { __u32 version; /* SEP_KEY_IFACE_VERSION */ - __u32 flags_supported; /* 0 in version 1 */ + __u32 flags_supported; /* SEP_KEY_CREATE_* bits this kernel accepts */ __u32 handle_max; /* SEP_KEY_HANDLE_MAX */ __u32 reserved; }; struct sep_key_create { - __u32 flags; /* in: 0 */ + __u32 flags; /* in: SEP_KEY_CREATE_* */ __u32 handle_len; /* out */ __u8 public_key[SEP_KEY_PUB_LEN]; /* out */ __u8 reserved[3]; /* in: 0 */ @@ -266,4 +274,25 @@ struct sep_key_public { #define SEP_KEY_SIGN _IOWR(SEP_BIO_IOC_MAGIC, 0x22, struct sep_key_sign) #define SEP_KEY_PUBLIC _IOWR(SEP_BIO_IOC_MAGIC, 0x23, struct sep_key_public) +/* + * Test only, refused unless apple_sep.key_selftest=1, root: sign with a + * biometric key under a deliberately unsuitable credential context, to show + * the enclave refuses. Modes: 1 no context, 2 a context with no match, + * 3 a context holding only the key bag secret, 4 a deleted context, 5 one + * touch: sign in the matched context, delete it, sign again with it. + * 'result' is 0 when the enclave signed, else a negative errno. + */ +struct sep_key_selftest { + __u32 mode; + __u32 handle_len; + __u8 digest[SEP_KEY_DIGEST_LEN]; + __s32 result; + __s32 enclave_status; + __s32 result2; /* mode 5: the signature after the delete */ + __s32 enclave_status2; + __u8 handle[SEP_KEY_HANDLE_MAX]; +}; + +#define SEP_KEY_SELFTEST _IOWR(SEP_BIO_IOC_MAGIC, 0x24, struct sep_key_selftest) + #endif /* _UAPI_LINUX_APPLE_SEP_H */ From 303fb19521ac0b6fdf19084794b5f5197e180dab Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 17:37:04 +1100 Subject: [PATCH 041/342] accel/ane: bound H16G program hints by validated resources The staged compiler increases the program record and work hints with task and tensor size. Treating these hints as enums rejects softmax, tiled matmul and larger elementwise programs before firmware sees them. Bound the nonzero record hint by the validated task payload's capacity for minimum-sized records, excluding task headers and padding. It is not an exact encoded record count: the staged softmax declares 88 with 51 encoded records, while the 3072 matmul declares 340 with 757 records. Bound the work hint by the sum of validated surface allocation bytes. Neither hint grants an allocation, mapping or stream extent. Keep all structural, register, relocation and reserved-byte checks. Exercise staged task/hint combinations in both program forms, coalesced records, count and work boundaries, and malformed payloads in KUnit. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_hwx.c | 41 +++++----- drivers/accel/ane/ane_h16_hwx_test.c | 86 ++++++++++++++++++++ drivers/accel/ane/ane_h16_hwx_test_fixture.h | 2 +- drivers/accel/ane/ane_h16_tasks.h | 19 ++++- 4 files changed, 122 insertions(+), 26 deletions(-) diff --git a/drivers/accel/ane/ane_h16_hwx.c b/drivers/accel/ane/ane_h16_hwx.c index e970df7d1105e..aaa38d29e6f2d 100644 --- a/drivers/accel/ane/ane_h16_hwx.c +++ b/drivers/accel/ane/ane_h16_hwx.c @@ -206,25 +206,13 @@ static int hwx_segment(struct hwx_parser *p, const u8 *c, u32 length) return 0; } -static bool hwx_format(u32 code) -{ - static const u8 known[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16, 17, - 18, 20, 21, 23, 27, 30, 31, 36, 41, 43, 72, 145, - }; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(known); i++) - if (known[i] == code) - return true; - return false; -} - static int hwx_program(struct hwx_parser *p) { const u8 *c = p->bytes + p->info.program_offset; struct ane_h16_hwx *info = &p->info; - u32 length = get_unaligned_le32(c + 4), records, i; + u32 length = get_unaligned_le32(c + 4), records, record_limit, i; + u32 prologue = info->subtype == ANE_HWX_SUBTYPE_H17 ? 0 : 1; + u64 work_limit = 0; bool mixed = length == 0x8c0; /* Nonzero cells only; every other byte is checked below. */ static const u16 common[] = { @@ -249,8 +237,6 @@ static int hwx_program(struct hwx_parser *p) get_unaligned_le32(c + 0x848) != (mixed ? 0x8b8 : 0x898)) return -ENOEXEC; records = get_unaligned_le32(c + 0x860); - if (records != 0x10 && records != 0x12 && records != 0x1f && records != 0x20) - return -ENOEXEC; info->tasks = get_unaligned_le32(c + 0x830); if (mixed) { u32 usable = get_unaligned_le32(c + 0x858); @@ -271,7 +257,14 @@ static int hwx_program(struct hwx_parser *p) get_unaligned_le64(c + 0x78 + i * 16)) return -ENOEXEC; } - if (!hwx_format(get_unaligned_le32(c + (mixed ? 0x8b0 : 0x890)))) + /* + * Work hints scale with tensor size, rather than selecting a format. + * Bound them by the total validated surface allocation in bytes; they + * never authorize an allocation, mapping or task-stream extent. + */ + for (i = 0; i < info->surface_count; i++) + work_limit += info->surfaces[i].allocation; + if (get_unaligned_le32(c + (mixed ? 0x8b0 : 0x890)) > work_limit) return -ENOEXEC; /* Construct the exact fixed trailer and reserved-space expectation. */ @@ -301,10 +294,14 @@ static int hwx_program(struct hwx_parser *p) } memcpy(expected + (mixed ? 0x8b0 : 0x890), c + (mixed ? 0x8b0 : 0x890), 4); memcpy(expected + (mixed ? 0x8b8 : 0x898), "main", 5); - if (!memcmp(c, expected, length)) - ret = ane_hx_task_stream_validate(p->bytes + info->text.offset, - info->text.size, info->tasks, - info->subtype == ANE_HWX_SUBTYPE_H17 ? 0 : 1); + if (!memcmp(c, expected, length)) { + ret = ane_hx_task_stream_validate_limit(p->bytes + info->text.offset, + info->text.size, info->tasks, prologue, + &record_limit); + /* This compiler hint need not equal the encoded record count. */ + if (!ret && (!records || records > record_limit)) + ret = -ENOEXEC; + } kfree(expected); return ret; } diff --git a/drivers/accel/ane/ane_h16_hwx_test.c b/drivers/accel/ane/ane_h16_hwx_test.c index 86af1c4779763..1b852982f3f04 100644 --- a/drivers/accel/ane/ane_h16_hwx_test.c +++ b/drivers/accel/ane/ane_h16_hwx_test.c @@ -216,6 +216,91 @@ static void hwx_program_test(struct kunit *test) } } +/* Build only structural tasks: no model bytes or hardware fixtures needed. */ +static void fixture_tasks(struct hwx_fixture *f, u32 tasks, u32 records) +{ + u8 *text = f->bytes + SZ_16K, *program = f->bytes + f->program; + u8 *section = f->bytes + f->text_command + 72; + u64 vm = get_unaligned_le64(section + 32); + u32 pos = 16, task, constants; + + memset(text, 0, SZ_16K); + put_unaligned_le32(1, text); + for (task = 0; task < tasks; task++) { + u32 count = records / tasks + (task < records % tasks); + + put_unaligned_le32((9 + 2 * count) << 16, text + pos); + /* Coalesce writes: the hint exceeds the encoded record count. */ + put_unaligned_le32(((2 * count - 2) << 15) | (0x4100 / 4), + text + pos + 36); + pos += (9 + 2 * count) * 4; + if (task + 1 < tasks) + pos = ALIGN(pos, 16); + } + constants = ALIGN(pos, 64); + put_unaligned_le64(pos, section + 40); + put_unaligned_le64(vm + constants, section + 80 + 32); + put_unaligned_le32(SZ_16K + constants, section + 80 + 48); + put_unaligned_le64(vm + constants, program + 0x20); + put_unaligned_le32(pos / 4, program + 0x824); + put_unaligned_le32(tasks, program + 0x830); + put_unaligned_le32(records, program + 0x860); +} + +static void hwx_staged_counts_test(struct kunit *test) +{ + static const struct { + u32 tasks, records, work; + } shapes[] = { + { 7, 0x58, 1 }, /* Row softmax. */ + { 4, 0x2e, 0 }, /* Tiled matmul 768. */ + { 5, 0x3c, 0 }, /* Tiled matmul 896. */ + { 7, 0x58, 0 }, /* Tiled matmul 1536. */ + { 25, 0x154, 0 }, /* Tiled matmul 3072. */ + { 10, 0x75, 1 }, /* Decoded attention. */ + { 1, 0x10, 61 }, { 1, 0x10, 92 }, /* LUT/ALU 1024. */ + { 1, 0x10, 245 }, { 1, 0x10, 368 }, /* LUT/ALU 2048. */ + }; + struct ane_h16_hwx info; + unsigned int form, i; + + for (form = 0; form < 2; form++) { + for (i = 0; i < ARRAY_SIZE(shapes); i++) { + struct hwx_fixture *f = fixture_create(test, form, false); + u32 work_offset = form ? 0x8b0 : 0x890; + u8 *program; + + KUNIT_ASSERT_NOT_NULL(test, f); + fixture_tasks(f, shapes[i].tasks, shapes[i].records); + program = f->bytes + f->program; + put_unaligned_le32(shapes[i].work, program + work_offset); + KUNIT_ASSERT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + KUNIT_EXPECT_EQ(test, info.tasks, shapes[i].tasks); + /* Neither count nor work may exceed its program-derived bound. */ + put_unaligned_le32(shapes[i].records + 1, program + 0x860); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC); + put_unaligned_le32(0, program + 0x860); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC); + put_unaligned_le32(shapes[i].records, program + 0x860); + put_unaligned_le32(SZ_32K, program + work_offset); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + put_unaligned_le32(SZ_32K + 1, program + work_offset); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC); + put_unaligned_le32(U32_MAX, program + work_offset); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC); + put_unaligned_le32(shapes[i].work, program + work_offset); + /* A plausible hint never overrides a corrupt task stream. */ + put_unaligned_le32(0x6000 / 4, f->bytes + SZ_16K + 52); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC); + } + } +} + static void hwx_geometry_test(struct kunit *test) { struct hwx_fixture *f = fixture_create(test, false, false); @@ -483,6 +568,7 @@ static struct kunit_case hwx_cases[] = { KUNIT_CASE(hwx_tensor_test), KUNIT_CASE(hwx_surface_order_test), KUNIT_CASE(hwx_program_test), + KUNIT_CASE(hwx_staged_counts_test), KUNIT_CASE(hwx_geometry_test), KUNIT_CASE(hwx_symbols_test), KUNIT_CASE(hwx_relocations_test), diff --git a/drivers/accel/ane/ane_h16_hwx_test_fixture.h b/drivers/accel/ane/ane_h16_hwx_test_fixture.h index fd839d68afc56..e129550d84151 100644 --- a/drivers/accel/ane/ane_h16_hwx_test_fixture.h +++ b/drivers/accel/ane/ane_h16_hwx_test_fixture.h @@ -122,7 +122,7 @@ static struct hwx_fixture *fixture_create(struct kunit *test, bool mixed, bool k put_unaligned_le32(U32_MAX, c + 0x83c); put_unaligned_le32(0xffff, c + 0x844); put_unaligned_le32(mixed ? 0x8b8 : 0x898, c + 0x848); - put_unaligned_le32(0x10, c + 0x860); + put_unaligned_le32(1, c + 0x860); put_unaligned_le32(4, c + 0x868); put_unaligned_le32(mixed ? 4 : 2, c + 0x870); put_unaligned_le32(mixed ? 2 : 7, c + 0x878); diff --git a/drivers/accel/ane/ane_h16_tasks.h b/drivers/accel/ane/ane_h16_tasks.h index e6e4ebc70694e..413be2af81ba4 100644 --- a/drivers/accel/ane/ane_h16_tasks.h +++ b/drivers/accel/ane/ane_h16_tasks.h @@ -41,11 +41,12 @@ static inline bool ane_h16_register_valid(u32 word) * does not replace container/tensor/aperture validation. */ static inline int -ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u32 prologue) +ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_tasks, + u32 prologue, u32 *record_limit) { const u8 *p = text; size_t pos = 16; - u32 tasks = 0; + u32 tasks = 0, limit = 0; if (!p || !expected_tasks || size < 16 || size > ANE_H16_TASK_MAX || (size & 3) || get_unaligned_le32(p) != prologue || @@ -72,6 +73,8 @@ ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u if (words < header_words) return -ENOEXEC; rec = pos + header_words * 4; + /* A record needs at least one header and one register value. */ + limit += (end - rec) / 8; while (rec < end) { u32 h = get_unaligned_le32(p + rec); u32 base = h & 0x7fff; @@ -104,7 +107,17 @@ ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u if (++tasks > expected_tasks) return -ENOEXEC; } - return tasks == expected_tasks ? 0 : -ENOEXEC; + if (tasks != expected_tasks) + return -ENOEXEC; + if (record_limit) + *record_limit = limit; + return 0; +} + +static inline int +ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u32 prologue) +{ + return ane_hx_task_stream_validate_limit(text, size, expected_tasks, prologue, NULL); } static inline int From ac6c191af91080da081a2d842551fea440259c7d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:15:40 +1100 Subject: [PATCH 042/342] soc: apple: sep: sep-key: say how long a Touch ID signature waits One verify capture already waits up to a minute for a finger, so the 30 s overall budget only ever allowed one capture. Make the budget a minute and say "about a minute" in the UAPI comment and the log. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/key.rs | 9 +++++---- include/uapi/linux/apple-sep.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/soc/apple/key.rs b/drivers/soc/apple/key.rs index aa991b4639fd0..261ab907703eb 100644 --- a/drivers/soc/apple/key.rs +++ b/drivers/soc/apple/key.rs @@ -41,8 +41,9 @@ pub(crate) const SIG_MAX: usize = 72; pub(crate) const CREATE_BIOMETRY_CURRENT_SET: u32 = 1; const CREATE_FLAGS: u32 = CREATE_BIOMETRY_CURRENT_SET; -/// How long a touch-gated `SIGN` waits for a finger in all. -const TOUCH_WAIT_MS: u64 = 30_000; +/// A touch-gated `SIGN` asks for a finger again after a capture that saw +/// none until this long has passed; one capture itself waits up to a minute. +const TOUCH_WAIT_MS: u64 = 60_000; const MAGIC: u32 = 0xB1; @@ -531,7 +532,7 @@ impl SepData { /// A touch-gated signature: one fresh credential context, one Touch ID /// match in it, the signature, and the context deleted, all inside this - /// call. Waits up to `TOUCH_WAIT_MS` for a finger. + /// call. Waits about a minute for a finger. fn key_sign_with_touch(&self, blob: &[u8], digest: &[u8; DIGEST_LEN], again: bool) -> Result { let acl = self.key_bio_acl()?; let mut owned = KVec::new(); @@ -551,7 +552,7 @@ impl SepData { again_status: 0, }); self.key_touch_active.store(true, Relaxed); - dev_info!(self.dev, "sep-key: waiting for a Touch ID match to sign (up to {} s)\n", TOUCH_WAIT_MS / 1000); + dev_info!(self.dev, "sep-key: waiting for a Touch ID match to sign\n"); let deadline = crate::shim::boottime_ns().saturating_add(TOUCH_WAIT_MS * 1_000_000); let ended = loop { if self.shutting_down.load(Relaxed) { diff --git a/include/uapi/linux/apple-sep.h b/include/uapi/linux/apple-sep.h index 80b731de98247..9415c7bc2adaf 100644 --- a/include/uapi/linux/apple-sep.h +++ b/include/uapi/linux/apple-sep.h @@ -217,7 +217,7 @@ struct sep_bio_rearm { * and holds its handle can sign with it. A key made with * SEP_KEY_CREATE_BIOMETRY_CURRENT_SET (version 2) carries an access-control * list the enclave enforces: every signature needs a Touch ID match of a - * finger enrolled when the key was made. SEP_KEY_SIGN then waits (up to 30 s) + * finger enrolled when the key was made. SEP_KEY_SIGN then waits (about a minute) * for a touch; the kernel opens a credential context, runs the match in it, * signs and deletes the context inside that one call. Enrolling or removing a * finger makes the key unusable. The node is created 0600; distributions may From b6425fc7d83139b5ba710554789cfd5b8795df38 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 15:06:08 -0500 Subject: [PATCH 043/342] arm64: dts: apple: t8132-j773g: Keep the PMC power state on Once the PMP runs on the M4 Mac mini (J773g), its firmware accesses the PMC block at 0x382800000. Linux treats its PMGR power state, ps_pmc, as an ordinary domain without consumers. J713 disables the domain in its board PMGR policy; J773g has no such policy yet. Mark ps_pmc always-on for J773g. Linux then keeps the domain on. Pavel Shago's J773g tree ended up with the same property in his commit of 2026-10-19, which predates ours. He sets it for all T8132 boards and reports a DCP SError on HDMI unplug. His observation and explanation have not been reproduced here. On one J773g (10-core GPU, system firmware 27.0, OS firmware 26.6.2), using a custom m1n1 stage 2 (build/commit unavailable) and Omarchy (Arch, release unavailable), v38 and v40 differed by this property: v38 had a PMP firmware crash and v40 logged PMP started without it. Across several configurations, 12 logs without the property showed the crash and 11 with it showed PMP started without the crash. Two further boots with PMC enabled left the board dead about 22 s after entry; no kernel log was kept for v34/v35. Attribution to ps_pmc rests on v42/v43 passing with the property, not a matched pair. v41 also changed the PMP register window and still crashed without the property. The driver never logged that an always-on domain was off at boot, which supports an inference that ps_pmc was on at handoff. These boots used pd_ignore_unused and clk_ignore_unused. A power-off was not observed; whether Linux turns the domain off without the property and causes the firmware fault remains inferred, not observed. These boots used our own J773g device tree on an older kernel. This tree's t8132-j773g.dts with this patch has not been booted on hardware. Link: https://github.com/shgpavel/linux-asahi/commit/172d11a1691fd2d8df28520517ee58de5307297e Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- arch/arm64/boot/dts/apple/t8132-j773g.dts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 89d2514815914..c7878c5a1ca31 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -43,6 +43,15 @@ power-domains = <&ps_dispext0_fe>, <&ps_dptx_phy>; }; +/* + * Without this, the PMP firmware faults in the PMC block (0x382800000) + * shortly after it starts on this board. J713 keeps ps_pmc out of Linux + * in its PMGR policy; this board has none yet. + */ +&ps_pmc { + apple,always-on; +}; + /* * The AOP audio component always runs a microphone stream, and this Mac * has no microphones (ADT iop-audio-controller has no audio-hp) and no From 8f905ae00b1b3612bb6d6c7b5084d1e02d276c4a Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 15:35:45 -0500 Subject: [PATCH 044/342] phy: apple: atc: use the common USB2 host field for a fixed hub T8132's ordinary Type-C ports use its alternate USB2 host-mode field. The fixed-hub path on the M4 Mac mini instead uses the common host field that the other supported SoCs use. Select the field from the fixed-hub topology. Ordinary T8132 Type-C ports keep their current field, while a T8132 PHY connected to a fixed hub takes the common field. SoCs without an alternate field are unchanged. Tested on one J773g with the two front USB-C ports, which sit behind an on-board USB2 hub on ATC2. With this field, together with the hub child and PHY-to-controller graph link in the board tree, the hub enumerates at 480 Mb/s, a keyboard delivers key events, and unplug/replug succeeds. That boot proves the combination works, but does not isolate whether this field is necessary. The change is derived from the U1 bring-up patch and narrowed to the fixed-hub path. Ordinary T8132 Type-C ports are unchanged. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/phy/apple/atc.c | 25 +++++++++++++------ .../selftests/drivers/gpu/apple-dcp/common.py | 9 +++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 6ed4bc2295d7b..33507b68de52e 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -925,6 +925,19 @@ static bool atcphy_usb2_only(const struct apple_atcphy *atcphy) return atcphy->hw->usb2_only && !atcphy->t8132_ss; } +/* + * The USB2 PHY's host-mode field. T8132's ordinary Type-C ports use bits 6:4, + * while its fixed-hub path uses bits 14:12 (plus the VBUSDET force bits 1:0 + * that this driver programs separately). + */ +static u32 atcphy_usb2_sig_host(const struct apple_atcphy *atcphy) +{ + if (atcphy->hw->usb2phy_sig_host && + !atcphy->fixed_usb2) + return atcphy->hw->usb2phy_sig_host; + return USB2PHY_SIG_HOST; +} + static const struct { const struct atcphy_mode_configuration normal; const struct atcphy_mode_configuration swapped; @@ -4261,12 +4274,10 @@ static int atcphy_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode switch (mode) { case PHY_MODE_USB_HOST: - set32(atcphy->regs.usb2phy + USB2PHY_SIG, - atcphy->hw->usb2phy_sig_host ?: USB2PHY_SIG_HOST); + set32(atcphy->regs.usb2phy + USB2PHY_SIG, atcphy_usb2_sig_host(atcphy)); break; case PHY_MODE_USB_DEVICE: - clear32(atcphy->regs.usb2phy + USB2PHY_SIG, - atcphy->hw->usb2phy_sig_host ?: USB2PHY_SIG_HOST); + clear32(atcphy->regs.usb2phy + USB2PHY_SIG, atcphy_usb2_sig_host(atcphy)); break; default: return -EINVAL; @@ -4310,8 +4321,7 @@ static int atcphy_usb2_init(struct phy *phy) * powered off as well the whole block is off; bring it back in the mode * the Type-C mux last asked for, USB2 until a cable event says otherwise. */ - set32(atcphy->regs.usb2phy + USB2PHY_SIG, - atcphy->hw->usb2phy_sig_host ?: USB2PHY_SIG_HOST); + set32(atcphy->regs.usb2phy + USB2PHY_SIG, atcphy_usb2_sig_host(atcphy)); if (atcphy->mode == APPLE_ATCPHY_MODE_OFF || atcphy->mode_dirty) return atcphy_configure(atcphy, atcphy->typec_mode); @@ -6246,8 +6256,7 @@ static int atcphy_probe_finalize(struct apple_atcphy *atcphy) * in reset. */ if (atcphy->fixed_usb2) { - set32(atcphy->regs.usb2phy + USB2PHY_SIG, - atcphy->hw->usb2phy_sig_host ?: USB2PHY_SIG_HOST); + set32(atcphy->regs.usb2phy + USB2PHY_SIG, atcphy_usb2_sig_host(atcphy)); ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB2); if (ret) return dev_err_probe(atcphy->dev, ret, "Failed to bring up USB2\n"); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py index c15ae40d30b8d..6c140662b6967 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py @@ -123,10 +123,15 @@ def atc_cio_helpers(source): The mux and PIPE functions call these; older sources have neither: ''. """ result = '' - for name in ('atcphy_mode_is_cio', 'atcphy_pipe_state_for'): + for name in ('atcphy_mode_is_cio', 'atcphy_pipe_state_for', + 'atcphy_usb2_sig_host'): marker = re.search(r'^static [^;{}()]+\b' + name + r'\([^;{}]*\)\s*\{', source, re.M) if marker: - result += block(source, marker.start()) + '\n' + helper = block(source, marker.start()) + if name == 'atcphy_usb2_sig_host': + helper = helper.replace('static u32', + 'static __attribute__((unused)) u32', 1) + result += helper + '\n' return result From f6f0bd033746b2ae44dc040956a2bedfff2fa393 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Sat, 7 Nov 2026 15:35:46 -0500 Subject: [PATCH 045/342] arm64: dts: apple: t8132-j773g: describe the front USB hub The M4 Mac mini two front USB-C ports hang off an on-board USB2 hub on ATC2 controller (ADT usb-drd2, hub 05ac:800b on raw root port 1), with no Type-C port controller. The board tree enables the controller as a host but gives it no hub child: dwc3-apple then waits for a role-switch event that nothing on this port ever sends, and the PHY only powers its USB2 path on a cable event, so the controller never starts. Describe the hub as the controller fixed child, as t8140-j700.dts does for its VL122. Link the PHY USB3 port to the controller SuperSpeed port: the PHY driver follows that graph to find the hub child and keeps its USB2 path up from probe on. No SuperSpeed data path is described, so the hub runs at high speed only. Hog the hub reset and SPI-flash output-enable lines high (ADT usb3hub_rst GPIO 198, usb3hub_flash_oe GPIO 101). Both are high under the boot loader and macOS, and a Linux boot that drove both high had a working hub. Whether the flash line must stay high after the hub has loaded its firmware is not known; keeping it as macOS leaves it is the conservative choice. Tested on one J773g (macOS 26.6.2 firmware): with this description and the PHY host-field change, the hub enumerates at 480 Mb/s on the ATC2 controller, a keyboard behind it reports press and release events and survives an unplug/replug. That boot shows the combination works; the hub child, graph link and GPIO hogs have not been removed one at a time, and the tree without the hub child has not been booted on its own. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- arch/arm64/boot/dts/apple/t8132-j773g.dts | 61 +++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 89d2514815914..4be114605cae4 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -166,12 +166,31 @@ }; /* - * The two front USB-C ports: an on-board hub behind ATC2 (ADT usb-drd2, - * hub firmware on spi3), with no port controller. The PHY only enters - * USB3 mode from a Type-C mode switch, so the hub runs at high speed. + * The two front USB-C ports: an on-board USB2 hub (Apple 05ac:800b, firmware + * on spi3) on raw USB2 root port 1 of ATC2's controller (ADT usb-drd2), with + * no port controller. The PHY only enters USB3 mode from a Type-C mode + * switch, so the hub runs at high speed. The hub child tells dwc3-apple the + * controller is a host from probe on; the graph link from the PHY's USB3 port + * to the controller's SuperSpeed port is how the PHY finds that fixed hub + * and keeps its USB2 path up without a cable event (no SuperSpeed data path + * is described). The hub's reset and SPI-flash output-enable lines (ADT + * usb3hub_rst, usb3hub_flash_oe) are AP GPIOs; the boot loader leaves both + * high, as does macOS, and the hub runs with them high. */ &atcphy2 { status = "okay"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + atcphy2_usb: endpoint { + remote-endpoint = <&dwc3_2_ss>; + }; + }; + }; }; &dwc3_2_dart_0 { @@ -184,7 +203,43 @@ &dwc3_2 { dr_mode = "host"; + #address-cells = <1>; + #size-cells = <0>; status = "okay"; + + hub@1 { + compatible = "usb5ac,800b"; + reg = <1>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* Raw xHCI port 1 is USB2; raw port 2 is SuperSpeed. */ + port@2 { + reg = <2>; + dwc3_2_ss: endpoint { + remote-endpoint = <&atcphy2_usb>; + }; + }; + }; +}; + +&pinctrl_ap { + usb3hub-flash-oe-hog { + gpio-hog; + gpios = <101 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "usb3hub-flash-oe"; + }; + + usb3hub-reset-hog { + gpio-hog; + gpios = <198 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "usb3hub-reset"; + }; }; &wifi0 { From 3c677e0f6cb56302b96d087621c2ab1e75e3ba59 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:11:38 +1100 Subject: [PATCH 046/342] soc: apple: sep: say why Touch ID needs the password Every refused verify ends with SEP_BIO_STATUS_LOCKOUT, whether Touch ID waits for the first password since boot, follows five failed matches, or needs the password because the enclave's match credential lapsed. Login screens then all say there were too many failed attempts, which is wrong for the wait after a restart that the administrator asked for; macOS says "Your password is required to enable Touch ID" there. Report SEP_BIO_LOCKOUT_STATE on /dev/sep-bio as well, read-only, so the verifying daemon, which holds that node and not the re-arm one, can ask why. Add SEP_BIO_LOCKOUT_FLAG_FAILED_ATTEMPTS: set while the lockout follows too many failed matches, five since the last match or password or the enclave's own lockout bits. A lockout with neither that flag nor SEP_BIO_LOCKOUT_FLAG_AFTER_BOOT needs the password for another reason. Older kernels answer the ioctl on /dev/sep-bio with -ENOTTY, so userspace can tell them apart. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/bio.rs | 20 ++++++-- drivers/soc/apple/sbio.rs | 94 ++++++++++++++++++++++++++-------- include/uapi/linux/apple-sep.h | 14 ++++- 3 files changed, 101 insertions(+), 27 deletions(-) diff --git a/drivers/soc/apple/bio.rs b/drivers/soc/apple/bio.rs index 86448b2528bc5..45831d5b3d930 100644 --- a/drivers/soc/apple/bio.rs +++ b/drivers/soc/apple/bio.rs @@ -218,16 +218,28 @@ pub(crate) struct Lockout { pub(crate) const LOCKOUT_FLAG_EVERY_PASSWORD: u32 = 1; /// Touch ID waits for the first password since this boot. pub(crate) const LOCKOUT_FLAG_AFTER_BOOT: u32 = 2; +/// The lockout follows too many failed matches. +pub(crate) const LOCKOUT_FLAG_FAILED_ATTEMPTS: u32 = 4; impl Lockout { - /// `locked` is a lockout after failed matches (or one recorded before the - /// restart); `after_boot` is the wait for the first password since boot. - /// Either one refuses every verify. - pub(crate) fn new(locked: bool, after_boot: bool, failures: u32) -> Lockout { + /// `locked` is a lockout (or one recorded before the restart); + /// `after_boot` is the wait for the first password since boot. Either + /// one refuses every verify. `failed_attempts` says that the lockout + /// follows too many failed matches; without it, a lockout needs the + /// password for another reason, such as a lapsed match credential. + pub(crate) fn new( + locked: bool, + after_boot: bool, + failed_attempts: bool, + failures: u32, + ) -> Lockout { let mut flags = LOCKOUT_FLAG_EVERY_PASSWORD; if after_boot { flags |= LOCKOUT_FLAG_AFTER_BOOT; } + if locked && failed_attempts { + flags |= LOCKOUT_FLAG_FAILED_ATTEMPTS; + } Lockout { locked: u32::from(locked || after_boot), failures, diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 463e974e8af5a..2464fcb028c9a 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -159,6 +159,14 @@ fn lockout_record_failures(raw: &[u8; LOCKOUT_RECORD_LEN]) -> u32 { u32::from_le_bytes([raw[12], raw[13], raw[14], raw[15]]).min(VERIFY_RETRY_LIMIT) } +/// Whether a lockout follows too many failed matches: `VERIFY_RETRY_LIMIT` +/// of them since the last match or password, or the enclave's own lockout +/// after failed matches (which macOS can have caused). Otherwise the lockout +/// needs the password for another reason, such as a lapsed match credential. +fn lockout_after_failures(failures: u32, enclave_lockout: bool) -> bool { + failures >= VERIFY_RETRY_LIMIT || enclave_lockout +} + fn lockout_record_locked(raw: &[u8; LOCKOUT_RECORD_LEN]) -> bool { raw[..LOCKOUT_MAGIC.len()] == LOCKOUT_MAGIC && u32::from_le_bytes([raw[8], raw[9], raw[10], raw[11]]) == LOCKOUT_LOCKED @@ -192,22 +200,45 @@ mod lockout_tests { #[test] fn after_boot_wait_reports_locked() { use crate::bio::{Lockout, LOCKOUT_FLAG_AFTER_BOOT, LOCKOUT_FLAG_EVERY_PASSWORD}; - let plain = Lockout::new(false, false, 2); + let plain = Lockout::new(false, false, false, 2); assert_eq!(plain.locked, 0); assert_eq!(plain.failures, 2); assert_eq!(plain.flags, LOCKOUT_FLAG_EVERY_PASSWORD); - let waiting = Lockout::new(false, true, 0); + let waiting = Lockout::new(false, true, false, 0); assert_eq!(waiting.locked, 1); assert_eq!(waiting.flags, LOCKOUT_FLAG_EVERY_PASSWORD | LOCKOUT_FLAG_AFTER_BOOT); // A lockout and the wait together: one password ends both. - let both = Lockout::new(true, true, 5); + let both = Lockout::new(true, true, true, 5); assert_eq!(both.locked, 1); assert_ne!(both.flags & LOCKOUT_FLAG_AFTER_BOOT, 0); - let locked = Lockout::new(true, false, 5); + let locked = Lockout::new(true, false, true, 5); assert_eq!(locked.locked, 1); assert_eq!(locked.flags & LOCKOUT_FLAG_AFTER_BOOT, 0); } + #[test] + fn lockout_names_failed_attempts() { + use crate::bio::{Lockout, LOCKOUT_FLAG_FAILED_ATTEMPTS}; + // Five misses, on the host or in the enclave, are the real lockout. + assert!(lockout_after_failures(VERIFY_RETRY_LIMIT, false)); + assert!(lockout_after_failures(0, true)); + // Fewer misses and no lockout in the enclave: the password is needed + // for another reason (a lapsed credential, a refused match context). + assert!(!lockout_after_failures(0, false)); + assert!(!lockout_after_failures(VERIFY_RETRY_LIMIT - 1, false)); + let locked = Lockout::new(true, false, true, VERIFY_RETRY_LIMIT); + assert_ne!(locked.flags & LOCKOUT_FLAG_FAILED_ATTEMPTS, 0); + let lapsed = Lockout::new(true, false, false, 0); + assert_eq!(lapsed.locked, 1); + assert_eq!(lapsed.flags & LOCKOUT_FLAG_FAILED_ATTEMPTS, 0); + // Only a lockout carries the flag; failed matches alone do not. + let open = Lockout::new(false, false, true, VERIFY_RETRY_LIMIT - 1); + assert_eq!(open.flags & LOCKOUT_FLAG_FAILED_ATTEMPTS, 0); + // The wait after boot is not a lockout after failed matches. + let waiting = Lockout::new(false, true, false, 0); + assert_eq!(waiting.flags & LOCKOUT_FLAG_FAILED_ATTEMPTS, 0); + } + #[test] fn record_round_trips() { assert!(lockout_record_locked(&lockout_record(true, 5))); @@ -5052,29 +5083,42 @@ impl SepData { Ok(()) } + /// Reports the lockout, and why Touch ID needs the password, so that + /// login screens can say which. Read-only, on both nodes. + fn write_lockout_state(&self, arg: usize) -> Result<()> { + let (locked, failures) = if self.touchid_started.load(Relaxed) { + ( + self.bio_lockout.load(Relaxed), + self.bio_nomatch_streak.load(Relaxed), + ) + } else { + (self.read_lockout_record(), self.read_recorded_failures()) + }; + let failed_attempts = locked + && lockout_after_failures( + failures, + self.enclave_reports_state(LOCK_STATE_LOCKOUT | LOCK_STATE_BIO_LOCKOUT), + ); + let state = bio::Lockout::new( + locked, + self.bio_after_boot.load(Relaxed), + failed_attempts, + failures, + ); + kernel::uaccess::UserSlice::new( + kernel::uaccess::UserPtr::from_addr(arg), + core::mem::size_of::(), + ) + .writer() + .write(&state) + } + pub(crate) fn rearm_ioctl(&self, cmd: u32, arg: usize) -> Result<()> { if self.shutting_down.load(Relaxed) { return Err(ENODEV); } match cmd { - bio::IOC_LOCKOUT_STATE => { - let locked = if self.touchid_started.load(Relaxed) { - self.bio_lockout.load(Relaxed) - } else { - self.read_lockout_record() - }; - let state = bio::Lockout::new( - locked, - self.bio_after_boot.load(Relaxed), - self.bio_nomatch_streak.load(Relaxed), - ); - kernel::uaccess::UserSlice::new( - kernel::uaccess::UserPtr::from_addr(arg), - core::mem::size_of::(), - ) - .writer() - .write(&state) - } + bio::IOC_LOCKOUT_STATE => self.write_lockout_state(arg), bio::IOC_REARM => { bio::require_admin()?; let mut request: bio::Rearm = kernel::uaccess::UserSlice::new( @@ -5530,6 +5574,12 @@ impl SepData { if cmd == bio::IOC_PREPARE_ENROL { return self.bio_prepare_enrol(arg); } + // fprintd holds this node, not the re-arm one: it reads here why a + // verify was refused, to tell the user. + if cmd == bio::IOC_LOCKOUT_STATE { + self.write_lockout_state(arg)?; + return bio::ok(); + } // With xART writes off the enclave cannot persist what an enrolment or // a match changes. It saves anti-replay state after every match, and a // refused save has left it unresponsive until reboot. Refuse the diff --git a/include/uapi/linux/apple-sep.h b/include/uapi/linux/apple-sep.h index 090d9cf96ac0e..ece6cedd4b299 100644 --- a/include/uapi/linux/apple-sep.h +++ b/include/uapi/linux/apple-sep.h @@ -172,7 +172,12 @@ struct sep_bio_attest { */ #define SEP_BIO_STATUS_LOCKOUT 8 -/* /dev/sep-bio-rearm, which any number of root callers may open. */ +/* + * SEP_BIO_LOCKOUT_STATE works on /dev/sep-bio-rearm, which any number of root + * callers may open, and on /dev/sep-bio, so that the verifying daemon can say + * why a verify ended with SEP_BIO_STATUS_LOCKOUT. Older kernels answer it on + * /dev/sep-bio with -ENOTTY. + */ struct sep_bio_lockout { __u32 locked; /* 1 while every verify is refused */ __u32 failures; /* failed matches since the last match or re-arm */ @@ -191,6 +196,13 @@ struct sep_bio_lockout { * (SEP_BIO_REQUIRE_PASSWORD); 'locked' is 1 then too. */ #define SEP_BIO_LOCKOUT_FLAG_AFTER_BOOT 2 +/* + * Set while 'locked' follows too many failed matches: five since the last + * match or password, or the enclave's own lockout after failed matches. A + * lockout without it (and without SEP_BIO_LOCKOUT_FLAG_AFTER_BOOT) needs the + * password for another reason, such as a lapsed match credential. + */ +#define SEP_BIO_LOCKOUT_FLAG_FAILED_ATTEMPTS 4 #define SEP_BIO_LOCKOUT_STATE _IOR(SEP_BIO_IOC_MAGIC, 0x0e, struct sep_bio_lockout) /* From 50ba8b00f5b1dfc3d676b28a05bdc07397d3b7b2 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:46:14 +1100 Subject: [PATCH 047/342] soc: apple: sep: sep-key: biometry-any keys; reserve the password policies Add SEP_KEY_CREATE_BIOMETRY_ANY, macOS's .biometryAny: the key's access-control list names the Touch ID catacomb (pbioc) but no enrolled-set hash, so any finger enrolled on this install matches, including fingers enrolled after the key was made. SIGN runs the same touch-gated path as a biometry-current-set key; handle flag 0x02 (with 0x01) picks the matching preflight constraint. The enclave enforces the list in the record either way. Reserve SEP_KEY_CREATE_USER_PRESENCE (.userPresence, Touch ID or the password) and SEP_KEY_CREATE_DEVICE_PASSCODE (.devicePasscode). Both need the enclave to check the user's own password. On Linux the only passcode the enclave knows today is the identity key bag's secret, which root holds, so such a key would be root-satisfiable. CREATE refuses them with EOPNOTSUPP; they are not emulated in software. At most one policy bit may be set. Add self-test mode 6 (key_selftest=1, root, no finger): a throwaway key with the .userPresence list as macOS writes it (cpo "DeviceOwnerAuthentication"), signed with a key-bag-secret context and with an unsatisfied context, to measure what the enclave enforces for that policy on Linux. KUnit: policy parsing, handle flags, the biometry-any and presence lists. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/key.rs | 182 +++++++++++++++++++++++++++++---- include/uapi/linux/apple-sep.h | 28 ++++- 2 files changed, 185 insertions(+), 25 deletions(-) diff --git a/drivers/soc/apple/key.rs b/drivers/soc/apple/key.rs index 261ab907703eb..e846a02e555f4 100644 --- a/drivers/soc/apple/key.rs +++ b/drivers/soc/apple/key.rs @@ -17,6 +17,18 @@ //! handle to it ever reaches userspace, and every signature needs its own //! touch. The enclave refuses the signature for any other context; the //! header's flag only tells the kernel to ask for the touch. +//! +//! `CREATE_BIOMETRY_ANY` is macOS's `.biometryAny`: the same list without +//! the enrolled-set hash, so any finger enrolled in this catacomb matches, +//! including fingers enrolled after the key was made. +//! +//! macOS's `.userPresence` (Touch ID or the password) and `.devicePasscode` +//! need a passcode credential the enclave checks against the user's own +//! secret. On Linux the only passcode the enclave knows today is the identity +//! key bag's secret, which root holds, so those policies would be +//! root-satisfiable. Their `CREATE` bits are reserved and refused with +//! `EOPNOTSUPP` until a per-user, password-keyed bag exists; they are never +//! emulated in software. use crate::der::RefKeyValue as RV; use crate::SepData; @@ -39,7 +51,36 @@ pub(crate) const SIG_MAX: usize = 72; /// `CREATE` flag: signing needs a Touch ID match of a currently enrolled /// finger, enforced by the enclave. pub(crate) const CREATE_BIOMETRY_CURRENT_SET: u32 = 1; -const CREATE_FLAGS: u32 = CREATE_BIOMETRY_CURRENT_SET; +/// `CREATE` flag: signing needs a Touch ID match of any finger enrolled in +/// this catacomb, now or later, enforced by the enclave. +pub(crate) const CREATE_BIOMETRY_ANY: u32 = 2; +/// Reserved `CREATE` flags for macOS's `.userPresence` and `.devicePasscode`. +/// Refused with `EOPNOTSUPP` until the enclave can check the user's own +/// password (see the module comment). +pub(crate) const CREATE_USER_PRESENCE: u32 = 4; +pub(crate) const CREATE_DEVICE_PASSCODE: u32 = 8; +const CREATE_FLAGS: u32 = CREATE_BIOMETRY_CURRENT_SET | CREATE_BIOMETRY_ANY; +const CREATE_RESERVED: u32 = CREATE_USER_PRESENCE | CREATE_DEVICE_PASSCODE; + +/// The access policy a `CREATE` request asks for: at most one policy bit. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub(crate) enum Policy { + None, + BiometryCurrentSet, + BiometryAny, +} + +pub(crate) fn create_policy(flags: u32) -> Result { + if flags & !(CREATE_FLAGS | CREATE_RESERVED) != 0 || flags.count_ones() > 1 { + return Err(EINVAL); + } + match flags { + 0 => Ok(Policy::None), + CREATE_BIOMETRY_CURRENT_SET => Ok(Policy::BiometryCurrentSet), + CREATE_BIOMETRY_ANY => Ok(Policy::BiometryAny), + _ => Err(EOPNOTSUPP), + } +} /// A touch-gated `SIGN` asks for a finger again after a capture that saw /// none until this long has passed; one capture itself waits up to a minute. @@ -52,6 +93,9 @@ const HANDLE_MAGIC: &[u8; 4] = b"SEPK"; const HANDLE_VERSION: u8 = 1; /// Handle flag: the record carries a biometric access-control list. pub(crate) const HANDLE_BIOMETRY: u8 = 0x01; +/// Handle flag, with `HANDLE_BIOMETRY` only: the list names no enrolled-set +/// hash (biometry-any). +pub(crate) const HANDLE_BIOMETRY_ANY: u8 = 0x02; pub(crate) const HANDLE_HEADER: usize = 12; /// The largest enclave record a handle can carry. pub(crate) const BLOB_MAX: usize = HANDLE_MAX - HANDLE_HEADER; @@ -121,6 +165,13 @@ pub(crate) const SELFTEST_DELETED: u32 = 4; /// One touch: sign in the matched context, delete it, sign again with it /// (needs a finger). pub(crate) const SELFTEST_TOUCH_THEN_DELETED: u32 = 5; +/// Research probe, no finger, ignores the handle: make a throwaway key with +/// macOS's `.userPresence` list (`cpo` "DeviceOwnerAuthentication") and sign +/// with a context holding only the key bag's secret (`result`) and with an +/// unsatisfied context (`result2`). Shows whether the enclave enforces that +/// policy and whether a root-held secret satisfies it; `CREATE` refuses the +/// policy either way. +pub(crate) const SELFTEST_PRESENCE_PROBE: u32 = 6; static_assert!(core::mem::size_of::() == 16); static_assert!(core::mem::size_of::() == 2124); @@ -163,9 +214,14 @@ pub(crate) fn info() -> Info { } } +/// No flags, biometry (current set), or biometry plus biometry-any. +fn handle_flags_valid(flags: u8) -> bool { + matches!(flags, 0 | HANDLE_BIOMETRY | 0x03) +} + /// Writes the handle for `blob` with `flags` into `out`; returns its length. pub(crate) fn encode_handle(blob: &[u8], flags: u8, out: &mut [u8; HANDLE_MAX]) -> Result { - if blob.is_empty() || blob.len() > BLOB_MAX || flags & !HANDLE_BIOMETRY != 0 { + if blob.is_empty() || blob.len() > BLOB_MAX || !handle_flags_valid(flags) { return Err(EINVAL); } let len = u32::try_from(blob.len()).map_err(|_| EINVAL)?; @@ -187,7 +243,7 @@ pub(crate) fn decode_handle(handle: &[u8; HANDLE_MAX], len: u32) -> Result<(&[u8 if !(HANDLE_HEADER + 1..=HANDLE_MAX).contains(&len) { return Err(EINVAL); } - if &handle[..4] != HANDLE_MAGIC || handle[4] != HANDLE_VERSION || handle[5] & !HANDLE_BIOMETRY != 0 { + if &handle[..4] != HANDLE_MAGIC || handle[4] != HANDLE_VERSION || !handle_flags_valid(handle[5]) { return Err(EINVAL); } if handle[6] != 0 || handle[7] != 0 { @@ -211,23 +267,43 @@ pub(crate) fn put_signature(sig: &[u8], out: &mut Sign) -> Result<()> { Ok(()) } +/// macOS's `.userPresence` list: every constrained operation names the +/// `DeviceOwnerAuthentication` policy (Touch ID or the password). Used only +/// by `SELFTEST_PRESENCE_PROBE`. +pub(crate) fn presence_acl() -> Result> { + let constraint = + crate::der::encode_refkey_set(&[(b"cpo".as_slice(), RV::Utf8(b"DeviceOwnerAuthentication"))])?; + let acl = crate::der::encode_refkey_set(&[ + (b"oa".as_slice(), RV::Bool(true)), + (b"ock".as_slice(), RV::Der(&constraint)), + (b"odel".as_slice(), RV::Bool(true)), + (b"okd".as_slice(), RV::Der(&constraint)), + (b"osgn".as_slice(), RV::Der(&constraint)), + ])?; + crate::der::encode_refkey_set(&[(b"acl".as_slice(), RV::Der(&acl))]) +} + /// The access-control list of a biometry-current-set key, in the key /// store's DER, and the constraint its signing operation carries. /// /// As macOS writes it for `.privateKeyUsage | .biometryCurrentSet`: sign, /// key agreement (`ock`) and derivation (`okd`) need a biometric credential /// (`cbio`) for this catacomb (`pbioc`) and enrolled set (`pbioh`); delete -/// (`odel`) and attest (`oa`) are free. +/// (`odel`) and attest (`oa`) are free. With no `enrolled_hash` it is the +/// `.biometryAny` list: `cbio` names the catacomb only. pub(crate) struct BioAcl { pub(crate) ed: KVec, pub(crate) constraint: KVec, } -pub(crate) fn bio_acl(catacomb: &[u8; 16], enrolled_hash: &[u8; 32]) -> Result { - let cbio = crate::der::encode_refkey_set(&[ - (b"pbioc".as_slice(), RV::Octets(catacomb)), - (b"pbioh".as_slice(), RV::Octets(enrolled_hash)), - ])?; +pub(crate) fn bio_acl(catacomb: &[u8; 16], enrolled_hash: Option<&[u8; 32]>) -> Result { + let cbio = match enrolled_hash { + Some(hash) => crate::der::encode_refkey_set(&[ + (b"pbioc".as_slice(), RV::Octets(catacomb)), + (b"pbioh".as_slice(), RV::Octets(hash)), + ])?, + None => crate::der::encode_refkey_set(&[(b"pbioc".as_slice(), RV::Octets(catacomb))])?, + }; let constraint = crate::der::encode_refkey_set(&[(b"cbio".as_slice(), RV::Der(&cbio))])?; let acl = crate::der::encode_refkey_set(&[ (b"oa".as_slice(), RV::Bool(true)), @@ -354,14 +430,46 @@ mod tests { let n = encode_handle(&blob(), HANDLE_BIOMETRY, &mut h).unwrap() as u32; assert_eq!(decode_handle(&h, n).unwrap().1, HANDLE_BIOMETRY); assert!(encode_handle(&blob(), 0x02, &mut h).is_err()); + assert!(encode_handle(&blob(), 0x04, &mut h).is_err()); let mut bad = h; bad[5] = 0x02; assert!(decode_handle(&bad, n).is_err()); + let n = encode_handle(&blob(), HANDLE_BIOMETRY | HANDLE_BIOMETRY_ANY, &mut h).unwrap() as u32; + assert_eq!(decode_handle(&h, n).unwrap().1, HANDLE_BIOMETRY | HANDLE_BIOMETRY_ANY); + } + + #[test] + fn create_takes_one_policy_and_refuses_the_password_ones() { + assert_eq!(create_policy(0).unwrap(), Policy::None); + assert_eq!(create_policy(CREATE_BIOMETRY_CURRENT_SET).unwrap(), Policy::BiometryCurrentSet); + assert_eq!(create_policy(CREATE_BIOMETRY_ANY).unwrap(), Policy::BiometryAny); + assert_eq!(create_policy(CREATE_USER_PRESENCE).unwrap_err(), EOPNOTSUPP); + assert_eq!(create_policy(CREATE_DEVICE_PASSCODE).unwrap_err(), EOPNOTSUPP); + assert_eq!(create_policy(CREATE_BIOMETRY_CURRENT_SET | CREATE_BIOMETRY_ANY).unwrap_err(), EINVAL); + assert_eq!(create_policy(0x10).unwrap_err(), EINVAL); + assert_eq!(info().flags_supported, CREATE_BIOMETRY_CURRENT_SET | CREATE_BIOMETRY_ANY); + } + + #[test] + fn biometry_any_list_names_the_catacomb_only() { + let acl = bio_acl(&[0x11; 16], None).unwrap(); + // SET { SEQ { "cbio", SET { SEQ { "pbioc", OCTETS[16] } } } } + assert_eq!(acl.constraint.len(), 2 + 2 + 6 + 2 + (2 + 7 + 18)); + assert!(!acl.ed.windows(5).any(|w| w == b"pbioh")); + assert!(acl.ed.windows(5).any(|w| w == b"pbioc")); + } + + #[test] + fn presence_list_has_the_captured_shape() { + let ed = presence_acl().unwrap(); + // macOS: each constrained op is SET(34) { SEQ { "cpo", "DeviceOwnerAuthentication" } }. + assert_eq!(ed.windows(2).filter(|w| *w == [0x31u8, 34].as_slice()).count(), 3); + assert_eq!(ed.windows(25).filter(|w| *w == b"DeviceOwnerAuthentication").count(), 3); } #[test] fn biometric_acl_has_the_key_store_shape() { - let acl = bio_acl(&[0x11; 16], &[0x22; 32]).unwrap(); + let acl = bio_acl(&[0x11; 16], Some(&[0x22; 32])).unwrap(); // SET { SEQ { "cbio", SET { SEQ { "pbioc", OCTETS[16] }, SEQ { "pbioh", OCTETS[32] } } } } assert_eq!(acl.constraint.len(), 2 + 2 + 6 + 2 + (2 + 7 + 18) + (2 + 7 + 34)); assert_eq!(&acl.constraint[..2], &[0x31, 0x50]); @@ -377,7 +485,7 @@ mod tests { #[test] fn acl_constraint_command_has_the_captured_layout() { - let acl = bio_acl(&[0x11; 16], &[0x22; 32]).unwrap(); + let acl = bio_acl(&[0x11; 16], Some(&[0x22; 32])).unwrap(); let cmd = crate::scrd::scrd_verify_acl_constraint(&[0x33; 16], &acl.constraint, b"ock").unwrap(); // macOS: 138 bytes for a 94-byte constraint and "ock"; this one is 80 bytes. assert_eq!(cmd.len(), 8 + 16 + 4 + acl.constraint.len() + 4 + 3 + 1 + 8); @@ -418,12 +526,12 @@ impl SepData { || crate::bio::capture_is_live(&self.bio_session.lock(), self.capture_epoch.load(Relaxed)) } - fn key_bio_acl(&self) -> Result { + fn key_bio_acl(&self, any: bool) -> Result { if !self.touchid_started.load(Relaxed) { return Err(ENODEV); } let (catacomb, enrolled) = self.catacomb_binding()?; - bio_acl(&catacomb, &enrolled) + bio_acl(&catacomb, (!any).then_some(&enrolled)) } /// Evaluates the signing constraint on the fresh context before the @@ -533,8 +641,8 @@ impl SepData { /// A touch-gated signature: one fresh credential context, one Touch ID /// match in it, the signature, and the context deleted, all inside this /// call. Waits about a minute for a finger. - fn key_sign_with_touch(&self, blob: &[u8], digest: &[u8; DIGEST_LEN], again: bool) -> Result { - let acl = self.key_bio_acl()?; + fn key_sign_with_touch(&self, blob: &[u8], flags: u8, digest: &[u8; DIGEST_LEN], again: bool) -> Result { + let acl = self.key_bio_acl(flags & HANDLE_BIOMETRY_ANY != 0)?; let mut owned = KVec::new(); owned.extend_from_slice(blob, GFP_KERNEL)?; // Serialises with /dev/sep-bio's enrol and verify work, as they do @@ -624,11 +732,41 @@ impl SepData { Ok(handle) } + fn key_presence_probe(&self, req: &mut Selftest) -> Result<()> { + let ed = presence_acl()?; + let (blob, _) = self.user_key_create(Some(&ed))?; + let digest = req.digest; + let user = crate::sbio::UserId::new(crate::SBIO_PROBE_USER_ID).ok_or(EINVAL)?; + let record = |r: Result>, s: &SepData| -> (i32, i32) { + (r.err().map(|e| e.to_errno()).unwrap_or(0), s.last_key_status.load(Relaxed) as i32) + }; + self.last_key_status.store(0, Relaxed); + let ctx = self.passcode_context()?; + (req.result, req.enclave_status) = record(self.user_key_sign(&blob, &digest, Some(&ctx)), self); + self.close_unlock_evaluation(&ctx); + self.last_key_status.store(0, Relaxed); + let ctx = self.open_unlock_evaluation(user).ok_or(EIO)?; + (req.result2, req.enclave_status2) = record(self.user_key_sign(&blob, &digest, Some(&ctx)), self); + self.close_unlock_evaluation(&ctx); + dev_info!( + self.dev, + "sep-key: self-test presence probe: bag-secret context {} (enclave status {}), unsatisfied context {} (enclave status {})\n", + (if req.result == 0 { "SIGNED" } else { "refused" }), + req.enclave_status, + (if req.result2 == 0 { "SIGNED" } else { "refused" }), + req.enclave_status2 + ); + Ok(()) + } + fn key_selftest(&self, req: &mut Selftest) -> Result<()> { if crate::module_parameters::key_selftest.value() == 0 { return Err(EPERM); } crate::bio::require_admin()?; + if req.mode == SELFTEST_PRESENCE_PROBE { + return self.key_presence_probe(req); + } let (blob, flags) = decode_handle(&req.handle, req.handle_len)?; if flags & HANDLE_BIOMETRY == 0 { return Err(EINVAL); @@ -661,7 +799,7 @@ impl SepData { record(self.user_key_sign(&owned, &digest, Some(&ctx)), self) } SELFTEST_TOUCH_THEN_DELETED => { - let job = self.key_sign_with_touch(&owned, &digest, true)?; + let job = self.key_sign_with_touch(&owned, flags, &digest, true)?; req.result2 = errno_of(&job.again); req.enclave_status2 = job.again_status; (errno_of(&job.sig), job.status) @@ -693,13 +831,15 @@ impl SepData { let slice = UserSlice::new(user, core::mem::size_of::()); let (mut reader, mut writer) = slice.reader_writer(); let mut req: Create = reader.read()?; - if req.flags & !CREATE_FLAGS != 0 || req.reserved != [0; 3] { + if req.reserved != [0; 3] { return Err(EINVAL); } - let biometry = req.flags & CREATE_BIOMETRY_CURRENT_SET != 0; - let acl = if biometry { Some(self.key_bio_acl()?) } else { None }; + let (acl, flags) = match create_policy(req.flags)? { + Policy::None => (None, 0), + Policy::BiometryCurrentSet => (Some(self.key_bio_acl(false)?), HANDLE_BIOMETRY), + Policy::BiometryAny => (Some(self.key_bio_acl(true)?), HANDLE_BIOMETRY | HANDLE_BIOMETRY_ANY), + }; let (blob, point) = self.user_key_create(acl.as_ref().map(|a| &a.ed[..]))?; - let flags = if biometry { HANDLE_BIOMETRY } else { 0 }; req.handle_len = encode_handle(&blob, flags, &mut req.handle)? as u32; req.public_key = point; writer.write(&req) @@ -715,7 +855,7 @@ impl SepData { let (blob, flags) = decode_handle(&req.handle, req.handle_len)?; if flags & HANDLE_BIOMETRY != 0 { let digest = req.digest; - let job = self.key_sign_with_touch(blob, &digest, false)?; + let job = self.key_sign_with_touch(blob, flags, &digest, false)?; job.sig.ok_or(EIO)?? } else { self.user_key_sign(blob, &req.digest, None)? diff --git a/include/uapi/linux/apple-sep.h b/include/uapi/linux/apple-sep.h index 9415c7bc2adaf..762dcaf4b085c 100644 --- a/include/uapi/linux/apple-sep.h +++ b/include/uapi/linux/apple-sep.h @@ -220,18 +220,35 @@ struct sep_bio_rearm { * finger enrolled when the key was made. SEP_KEY_SIGN then waits (about a minute) * for a touch; the kernel opens a credential context, runs the match in it, * signs and deletes the context inside that one call. Enrolling or removing a - * finger makes the key unusable. The node is created 0600; distributions may - * grant a group. Unknown 'flags' bits and 'reserved' fields must be zero. + * finger makes the key unusable (macOS .biometryCurrentSet). + * SEP_KEY_CREATE_BIOMETRY_ANY is macOS .biometryAny: the same, but any finger + * enrolled on this install matches, including ones enrolled later. At most one + * policy bit may be set; flags_supported lists the ones this kernel accepts. + * + * SEP_KEY_CREATE_USER_PRESENCE (.userPresence: Touch ID or the password) and + * SEP_KEY_CREATE_DEVICE_PASSCODE (.devicePasscode) are reserved. They need + * the enclave to check the user's own password; on Linux today the enclave's + * only passcode is a key bag secret root holds, so CREATE refuses them with + * EOPNOTSUPP rather than check a password in software. + * + * Keep a second key (a backup) wherever a biometric key is trusted, as with + * hardware security keys: no key can be exported or recovered. + * + * The node is created 0600; distributions may grant a group. Unknown 'flags' + * bits and 'reserved' fields must be zero. * * Errors: EINVAL for a malformed request or handle, EKEYREJECTED when the * enclave refuses the key (a handle from another Mac or an earlier Linux * install, or an access-control list not satisfied), EACCES when the touch * did not match (or Touch ID is locked out), ETIMEDOUT when no finger came, - * ENODEV while the key store or Touch ID is not up, EIO for any other - * enclave failure. + * ENODEV while the key store or Touch ID is not up, EOPNOTSUPP for a + * reserved policy, EIO for any other enclave failure. */ #define SEP_KEY_IFACE_VERSION 2 #define SEP_KEY_CREATE_BIOMETRY_CURRENT_SET 0x1 +#define SEP_KEY_CREATE_BIOMETRY_ANY 0x2 +#define SEP_KEY_CREATE_USER_PRESENCE 0x4 /* reserved: EOPNOTSUPP */ +#define SEP_KEY_CREATE_DEVICE_PASSCODE 0x8 /* reserved: EOPNOTSUPP */ #define SEP_KEY_HANDLE_MAX 2048 #define SEP_KEY_PUB_LEN 65 /* uncompressed point, 04 || X || Y */ #define SEP_KEY_DIGEST_LEN 32 @@ -280,6 +297,9 @@ struct sep_key_public { * the enclave refuses. Modes: 1 no context, 2 a context with no match, * 3 a context holding only the key bag secret, 4 a deleted context, 5 one * touch: sign in the matched context, delete it, sign again with it. + * 6 (handle ignored): make a throwaway key with the .userPresence list and + * sign with a key-bag-secret context ('result') and with a context with no + * match ('result2'). * 'result' is 0 when the enclave signed, else a negative errno. */ struct sep_key_selftest { From d9fab835f97c13208aa9df0925897242624dfd36 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:54:34 +1100 Subject: [PATCH 048/342] accel/ane: refuse bytes after the last H16 task On the J616s, a staged H16G program whose __text carried zero padding after its final task loaded and ran, but the next EXECUTE on the device timed out every time (13/13). The structural walk accepts zero padding to 16 bytes and zero blocks between tasks, so nothing caught it. Have the task-stream walk report where the last task ends. For H16 programs, refuse any section that continues past it: 4, 8 or 12 bytes of padding and trailing zero blocks alike. H17 keeps the current rule until it has its own device evidence. The shared KUnit fixture now ends its one task at the section end, and a new case covers the exact end plus every refused tail on both forms. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_hwx.c | 11 +++++- drivers/accel/ane/ane_h16_hwx_test.c | 36 ++++++++++++++++++++ drivers/accel/ane/ane_h16_hwx_test_fixture.h | 5 +-- drivers/accel/ane/ane_h16_tasks.h | 10 ++++-- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/accel/ane/ane_h16_hwx.c b/drivers/accel/ane/ane_h16_hwx.c index aaa38d29e6f2d..cca48baeb30bc 100644 --- a/drivers/accel/ane/ane_h16_hwx.c +++ b/drivers/accel/ane/ane_h16_hwx.c @@ -212,6 +212,7 @@ static int hwx_program(struct hwx_parser *p) struct ane_h16_hwx *info = &p->info; u32 length = get_unaligned_le32(c + 4), records, record_limit, i; u32 prologue = info->subtype == ANE_HWX_SUBTYPE_H17 ? 0 : 1; + size_t final_end = 0; u64 work_limit = 0; bool mixed = length == 0x8c0; /* Nonzero cells only; every other byte is checked below. */ @@ -297,10 +298,18 @@ static int hwx_program(struct hwx_parser *p) if (!memcmp(c, expected, length)) { ret = ane_hx_task_stream_validate_limit(p->bytes + info->text.offset, info->text.size, info->tasks, prologue, - &record_limit); + &record_limit, &final_end); /* This compiler hint need not equal the encoded record count. */ if (!ret && (!records || records > record_limit)) ret = -ENOEXEC; + /* + * On H16 the final task must end the section: zero padding or + * zero blocks after it leave the engine armed, and the next + * EXECUTE on the device times out. + */ + if (!ret && info->subtype == ANE_HWX_SUBTYPE_H16 && + final_end != info->text.size) + ret = -ENOEXEC; } kfree(expected); return ret; diff --git a/drivers/accel/ane/ane_h16_hwx_test.c b/drivers/accel/ane/ane_h16_hwx_test.c index 1b852982f3f04..fc48ca002b93f 100644 --- a/drivers/accel/ane/ane_h16_hwx_test.c +++ b/drivers/accel/ane/ane_h16_hwx_test.c @@ -301,6 +301,41 @@ static void hwx_staged_counts_test(struct kunit *test) } } +/* + * Trailing zero bytes after the last H16 task leave the engine armed, and the + * next EXECUTE times out. The final task must end the section exactly. + */ +static void hwx_final_task_end_test(struct kunit *test) +{ + static const u32 tails[] = { 4, 8, 12, 12 + 16 }; + struct ane_h16_hwx info; + unsigned int form, i; + + for (form = 0; form < 2; form++) { + struct hwx_fixture *f = fixture_create(test, form, false); + u8 *section, *program; + u64 end; + + KUNIT_ASSERT_NOT_NULL(test, f); + /* One task with two records ends at 68; __const starts at 128. */ + fixture_tasks(f, 1, 2); + section = f->bytes + f->text_command + 72; + program = f->bytes + f->program; + end = get_unaligned_le64(section + 40); + KUNIT_ASSERT_EQ(test, end, 68ULL); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + for (i = 0; i < ARRAY_SIZE(tails); i++) { + put_unaligned_le64(end + tails[i], section + 40); + put_unaligned_le32((end + tails[i]) / 4, program + 0x824); + KUNIT_EXPECT_EQ_MSG(test, ane_h16_hwx_validate(f->bytes, f->size, &info), + -ENOEXEC, "form %u tail %u", form, tails[i]); + } + put_unaligned_le64(end, section + 40); + put_unaligned_le32(end / 4, program + 0x824); + KUNIT_EXPECT_EQ(test, ane_h16_hwx_validate(f->bytes, f->size, &info), 0); + } +} + static void hwx_geometry_test(struct kunit *test) { struct hwx_fixture *f = fixture_create(test, false, false); @@ -569,6 +604,7 @@ static struct kunit_case hwx_cases[] = { KUNIT_CASE(hwx_surface_order_test), KUNIT_CASE(hwx_program_test), KUNIT_CASE(hwx_staged_counts_test), + KUNIT_CASE(hwx_final_task_end_test), KUNIT_CASE(hwx_geometry_test), KUNIT_CASE(hwx_symbols_test), KUNIT_CASE(hwx_relocations_test), diff --git a/drivers/accel/ane/ane_h16_hwx_test_fixture.h b/drivers/accel/ane/ane_h16_hwx_test_fixture.h index e129550d84151..13650e9f0271a 100644 --- a/drivers/accel/ane/ane_h16_hwx_test_fixture.h +++ b/drivers/accel/ane/ane_h16_hwx_test_fixture.h @@ -87,7 +87,8 @@ static struct hwx_fixture *fixture_create(struct kunit *test, bool mixed, bool k f->text_command = f->cursor; text_section = fixture_segment(f, "__TEXT", text, SZ_32K, SZ_16K, 5, mixed ? 4 : 0, 2); - fixture_section(text_section, "__TEXT", "__text", text, 64, SZ_16K, + /* The one task ends the section: H16 refuses bytes after the last task. */ + fixture_section(text_section, "__TEXT", "__text", text, 60, SZ_16K, 14, kernel ? 0x128 : 0x28); fixture_section(text_section + 80, "__TEXT", "__const", text + 64, SZ_16K, SZ_16K + 64, 6, 0x26); @@ -116,7 +117,7 @@ static struct hwx_fixture *fixture_create(struct kunit *test, bool mixed, bool k put_unaligned_le64(kern, c + 0x90); put_unaligned_le64(text, c + 0x810); put_unaligned_le32(4, c + 0x820); - put_unaligned_le32(16, c + 0x824); + put_unaligned_le32(15, c + 0x824); put_unaligned_le32(1, c + 0x830); put_unaligned_le32(U32_MAX, c + 0x838); put_unaligned_le32(U32_MAX, c + 0x83c); diff --git a/drivers/accel/ane/ane_h16_tasks.h b/drivers/accel/ane/ane_h16_tasks.h index 413be2af81ba4..a375d77ae65b1 100644 --- a/drivers/accel/ane/ane_h16_tasks.h +++ b/drivers/accel/ane/ane_h16_tasks.h @@ -42,10 +42,10 @@ static inline bool ane_h16_register_valid(u32 word) */ static inline int ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_tasks, - u32 prologue, u32 *record_limit) + u32 prologue, u32 *record_limit, size_t *final_end) { const u8 *p = text; - size_t pos = 16; + size_t pos = 16, last = 0; u32 tasks = 0, limit = 0; if (!p || !expected_tasks || size < 16 || size > ANE_H16_TASK_MAX || @@ -103,6 +103,7 @@ ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_ta padded = end == size ? end : ALIGN(end, 16); if (padded > size || memchr_inv(p + end, 0, padded - end)) return -ENOEXEC; + last = end; pos = padded; if (++tasks > expected_tasks) return -ENOEXEC; @@ -111,13 +112,16 @@ ane_hx_task_stream_validate_limit(const void *text, size_t size, u32 expected_ta return -ENOEXEC; if (record_limit) *record_limit = limit; + if (final_end) + *final_end = last; return 0; } static inline int ane_hx_task_stream_validate(const void *text, size_t size, u32 expected_tasks, u32 prologue) { - return ane_hx_task_stream_validate_limit(text, size, expected_tasks, prologue, NULL); + return ane_hx_task_stream_validate_limit(text, size, expected_tasks, prologue, NULL, + NULL); } static inline int From 8aaab0996ff288f87a14c202893a6fa3e43e9e32 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:07:16 +1100 Subject: [PATCH 049/342] thunderbolt: apple: support the T6040 ACIO v2 router and its Type 7 NHI Teach the Apple USB4 glue and the PCIe-C controller the T6040 (M4 Pro) generation: the v2 router layout, its Type 7 NHI and the T6040 PCIe-C register and shared-MSI data. Taken from the driver half of the draft in linux#1052; the device tree half is already in integration. Tested on the J616s (M4 Pro) against the M2 over a TB5 cable: router firmware ready, XDomain link 2 x 20 Gb/s each way, thunderbolt-net iperf3 17.9 / 19.6 Gbit/s. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/pci/controller/pcie-apple.c | 37 +++++++++++++++++++++++-- drivers/thunderbolt/apple.c | 42 ++++++++++++++++++++++------- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 3173186c85209..6ad3376dcf75e 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -336,6 +336,21 @@ static const struct hw_info t8132_pciec_hw = { .s2idle_hold_domain = true, }; +static const struct hw_info t6040_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = 0x1088, + .max_rid2sid = 256, + .sid_indexed_rid2sid = true, + .tunneled = true, + .t8132_reset = true, + .msimap_by_vector = true, + .s2idle_hold_domain = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -2086,7 +2101,8 @@ static int apple_msi_init(struct apple_pcie *pcie) * 32-vector slice. Keep endpoint MSI data local, and route its table * entry to the corresponding shared-window vector. */ - if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw) { + if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || + pcie->hw == &t6040_pciec_hw) { struct resource ecam; u32 expected_base, aic_base; @@ -2108,6 +2124,21 @@ static int apple_msi_init(struct apple_pcie *pcie) default: goto invalid_slice; } + } else if (of_machine_is_compatible("apple,t6040")) { + aic_base = 2071; + switch (ecam.start) { + case 0x1c50000000ULL: + expected_base = 0x20; + break; + case 0x1c60000000ULL: + expected_base = 0x40; + break; + case 0x1c70000000ULL: + expected_base = 0x60; + break; + default: + goto invalid_slice; + } } else if (of_machine_is_compatible("apple,t8132")) { aic_base = 1506; switch (ecam.start) { @@ -2153,7 +2184,8 @@ static int apple_msi_init(struct apple_pcie *pcie) } /* Keep map targets within the supported 8-bit range. */ - if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw) && + if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || + pcie->hw == &t6040_pciec_hw) && (!pcie->nvecs || pcie->nvecs > 256 || pcie->msi_vector_base > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 - pcie->nvecs)) { @@ -4052,6 +4084,7 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { }; static const struct of_device_id apple_pcie_of_match[] = { + { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 61325859752d4..ba7ec0bc0296c 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -181,6 +181,16 @@ static const struct apple_cio_hw apple_cio_t8142_hw = { .dp = &apple_dpin_disabled, }; +static const struct apple_cio_hw apple_cio_t6040_hw = { + .mxwrap = true, + .lstx_explicit = true, + .skip_run = true, + .lstx_after_boot = true, + .strict_fw_ready = true, + .no_host_clx = true, + .dp = &apple_dpin_disabled, +}; + #define APPLE_CIO_NHI_HOP_COUNT 0x0 #define APPLE_CIO_NHI_HOP_COUNT_MASK GENMASK(9, 0) @@ -883,14 +893,20 @@ static void apple_cio_of_node_put(void *data) of_node_put(data); } +static bool apple_cio_pciec_eligible(const struct device_node *np) +{ + return of_device_is_compatible(np, "apple,t6040-pciec") || + of_device_is_compatible(np, "apple,t8103-pciec") || + of_device_is_compatible(np, "apple,t6000-pciec"); +} + static bool apple_cio_pcie_tunnel_is_preinitialized(struct device_node *parent) { for_each_available_child_of_node_scoped(parent, child) { u32 status; - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; if (!of_property_read_u32(child, "apple,pciec-preinit-status", @@ -919,8 +935,7 @@ static int apple_cio_get_pcie_reset(struct apple_cio *acio) struct reset_control *rst = NULL; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; if (!of_property_read_bool(child, "apple,pciec-kernel-init")) break; @@ -952,8 +967,7 @@ static int apple_cio_map_pcie_intr2axi(struct apple_cio *acio) int index, ret; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; index = of_property_match_string(child, "reg-names", "intr2axi"); @@ -2032,7 +2046,8 @@ static int apple_nhi_probe(struct platform_device *pdev) int ret = 0; if (acio->type7 != - of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi")) { + (of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || + of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi"))) { ret = dev_err_probe(&pdev->dev, -EINVAL, "ACIO/NHI generation mismatch\n"); goto err; } @@ -2458,6 +2473,9 @@ static const struct dev_pm_ops apple_nhi_pm_ops = { }; static const struct of_device_id apple_nhi_match[] = { + { + .compatible = "apple,t6040-usb4-nhi", + }, { .compatible = "apple,t8142-usb4-nhi", }, @@ -2486,8 +2504,7 @@ static struct platform_device *apple_cio_find_pcie_tunnel(struct apple_cio *acio return NULL; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; pdev = of_find_device_by_node(child); @@ -3279,7 +3296,8 @@ static int apple_cio_probe(struct platform_device *pdev) init_completion(&acio->nhi_boot_completion); acio->dev = &pdev->dev; acio->np = dev->of_node; - acio->type7 = of_device_is_compatible(acio->np, "apple,t8142-usb4-acio"); + acio->type7 = of_device_is_compatible(acio->np, "apple,t8142-usb4-acio") || + of_device_is_compatible(acio->np, "apple,t6040-usb4-acio"); if (acio->type7 && of_property_count_u32_elems(acio->np, "apple,tunable-rc") <= 0) return dev_err_probe(dev, -EINVAL, "Missing bootloader RC tuning\n"); @@ -3487,6 +3505,10 @@ static void apple_cio_remove(struct platform_device *pdev) static const struct of_device_id apple_acio_match[] = { + { + .compatible = "apple,t6040-usb4-acio", + .data = &apple_cio_t6040_hw, + }, { .compatible = "apple,t8142-usb4-acio", .data = &apple_cio_t8142_hw, From 632f6d60be7c80750d8995e78275871825986042 Mon Sep 17 00:00:00 2001 From: AxxzyWasTaken Date: Sun, 8 Nov 2026 23:07:17 +1100 Subject: [PATCH 050/342] phy: apple: t6040: add the CIO (USB4/Thunderbolt) mode Take the lanes for USB4 or the Thunderbolt alternate mode: the common tunables and the CIO ones, the crossbar with orientation in one bit, both lanes released, then the same PHY firmware as USB3. USB3 stays parked until the lanes come back. The order is AppleT6040TypeCPhy mode 2 from the 25G83 kernelcache and matches the T6050 recipe, except for the AHB clock request at CFG +0x28. Not run on hardware. Signed-off-by: AxxzyWasTaken (cherry picked from commit cf727761e6f9, linux#1126) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/phy/apple/t6040-usb2.c | 214 +++++++++++++++++++++++++++++---- 1 file changed, 193 insertions(+), 21 deletions(-) diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index cb4146d91faf1..73b687686294d 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -49,6 +49,8 @@ #include #include #include +#include +#include #define T6040_USB2_USBCTL 0x00 #define T6040_USB2_USBCTL_MODE GENMASK(2, 0) @@ -120,7 +122,10 @@ #define T6040_CORE_CMN_OVRD_SLEEP_B_BIG BIT(0) #define T6040_CORE_CMN_OVRD_SLEEP_B_SML BIT(2) #define T6040_CORE_CMN_OVRD_CLAMP BIT(4) +#define T6040_CORE_LANE_RX 0x10 /* CFG1_TOP */ #define T6040_CORE_SLP_CTRL 0x120 /* CFG_SLP_CTRL */ +#define T6040_CORE_LN0_RX_TOP_CIO 0x935c +#define T6040_CORE_LN1_RX_TOP_CIO 0x1935c #define T6040_CORE_CMN_BIAS 0xa00 /* AUS40CMN_SHM CMN_BIAS_REG */ #define T6040_CORE_CMN_BIAS_BGBIAS_EN_OV BIT(1) #define T6040_CORE_UC_CTRL 0x260 /* ACIOPHY_TOP_BLK_UC_CTRL_REG */ @@ -241,6 +246,7 @@ struct t6040_usb2_phy { bool usb3_pipe; /* dwc3 asked for the PIPE switch this power cycle */ bool usb3_lent; /* DP mode took the lanes of this Type-C port */ bool pipe_switched; /* the controller's PIPE runs on this PHY */ + bool cio_up; /* the lanes run USB4/Thunderbolt */ /* DisplayPort; dp_ok is false when the DT lacks a DP route */ struct phy *dp; @@ -598,14 +604,15 @@ static int t6040_usb3_cpu_start(struct t6040_usb2_phy *tphy) * every detach; each start makes the firmware tune the PHY. Then release the * PHY reset (D). */ -static int t6040_usb3_run_firmware(struct t6040_usb2_phy *tphy, bool swap) +static int t6040_usb3_run_firmware(struct t6040_usb2_phy *tphy, bool usb, bool swap) { void __iomem *cpu = t6040_cpu(tphy); u32 uc_before; int ret; - t6040_usb2_mask32(t6040_cfg(tphy) + T6040_CFG_SPARE0, T6040_CFG_SPARE0_USB_LN_SWAP, - swap ? T6040_CFG_SPARE0_USB_LN_SWAP : 0); + if (usb) + t6040_usb2_mask32(t6040_cfg(tphy) + T6040_CFG_SPARE0, T6040_CFG_SPARE0_USB_LN_SWAP, + swap ? T6040_CFG_SPARE0_USB_LN_SWAP : 0); fsleep(20); t6040_usb2_set32(cpu + T6040_CPU_IDLE_CTRL, T6040_CPU_IDLE_CTRL_EN); fsleep(10); @@ -750,24 +757,12 @@ static void t6040_usb3_bist_off(struct t6040_usb2_phy *tphy) * aciophy_phy_shutdown_partA: the PHY's USB link side down (the same BIST * handshake as the PIPE switch), both TX lanes, then the common block. */ -static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) +/* aciophy_tx_powerdown(0), (1), then aciophy_cmn_shutdown: USB and CIO alike. */ +static void t6040_phy_tx_cmn_down(struct t6040_usb2_phy *tphy) { - void __iomem *bist = t6040_bist(tphy); void __iomem *core = t6040_core(tphy); unsigned int lane; - t6040_usb2_set32(bist + T6040_BIST_CFG0, BIT(0)); - t6040_usb2_clear32(bist + T6040_BIST_OVRD0, 0x100000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x60, 0x20); - t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); - t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD0, ~0xe1ffffffu, 0x4000000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x600, 0x200); - t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); - t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); - t6040_usb2_clear32(bist + T6040_BIST_CFG0, BIT(0)); - - /* aciophy_tx_powerdown(0), (1) */ for (lane = 0; lane < 2; lane++) { t6040_usb2_set32(core + T6040_CORE_SLP_CTRL, 0x100 << lane); udelay(1); @@ -786,6 +781,25 @@ static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) udelay(1); t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, T6040_CORE_CMN_OVRD_SLEEP_B_SML); udelay(1); +} + + +static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) +{ + void __iomem *bist = t6040_bist(tphy); + + t6040_usb2_set32(bist + T6040_BIST_CFG0, BIT(0)); + t6040_usb2_clear32(bist + T6040_BIST_OVRD0, 0x100000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x60, 0x20); + t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); + t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD0, ~0xe1ffffffu, 0x4000000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x600, 0x200); + t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); + t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); + t6040_usb2_clear32(bist + T6040_BIST_CFG0, BIT(0)); + + t6040_phy_tx_cmn_down(tphy); fsleep(200); } @@ -896,8 +910,8 @@ static void t6040_usb3_up_locked(struct t6040_usb2_phy *tphy) lockdep_assert_held(&tphy->lock); if (!tphy->usb3_ok || tphy->usb3_up) return; - /* DP mode owns all four lanes; USB3 comes back in t6040_usb3_reclaim_locked(). */ - if (tphy->dp_up) { + /* DP and CIO own all four lanes; USB3 comes back in t6040_usb3_reclaim_locked(). */ + if (tphy->dp_up || tphy->cio_up) { dev_dbg(tphy->dev, "USB3: lanes held by DP, USB2 only for now\n"); return; } @@ -922,7 +936,7 @@ static void t6040_usb3_up_locked(struct t6040_usb2_phy *tphy) goto sleep; /* the coprocessor block may be unclocked: never touch it */ t6040_usb3_tunables(tphy); t6040_usb3_lanes(tphy, swap); - ret = t6040_usb3_run_firmware(tphy, swap); + ret = t6040_usb3_run_firmware(tphy, true, swap); if (ret) goto usb2_only; @@ -1409,7 +1423,7 @@ static void t6040_dp_drive(struct t6040_usb2_phy *tphy, unsigned int lane, u32 p static void t6040_usb3_reclaim_locked(struct t6040_usb2_phy *tphy) { lockdep_assert_held(&tphy->lock); - if (!tphy->usb3_lent || tphy->dp_up || tphy->dp_alt) + if (!tphy->usb3_lent || tphy->dp_up || tphy->dp_alt || tphy->cio_up) return; tphy->usb3_lent = false; if (!tphy->usb3_on || tphy->usb3_up) @@ -1422,6 +1436,156 @@ static void t6040_usb3_reclaim_locked(struct t6040_usb2_phy *tphy) dev_info(tphy->dev, "USB3 %s after DP\n", tphy->usb3_up ? "back" : "not restored"); } +/* ---- CIO: USB4 and Thunderbolt on both lanes ---- */ + +/* The ADT tables of the common set, then the CIO ones; no DPTX writes. */ +static void t6040_cio_tunables(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + size_t i; + + for (i = 0; i < T6040_USB3_NR_TUNABLES; i++) + apple_tunable_apply(tphy->regs[t6040_usb3_tunable_list[i].region], + tphy->tunables[i]); + /* tunable_LN0/1_RX_TOP_CIO_DFLT; UC_REGS_CIO and RX_EQ_CIO are empty. */ + t6040_usb2_clear32(core + T6040_CORE_LN0_RX_TOP_CIO, 0xe00); + t6040_usb2_clear32(core + T6040_CORE_LN1_RX_TOP_CIO, 0xe00); +} + +/* aciophy_xbar_config, mode 2: orientation is one crossbar bit. */ +static void t6040_cio_xbar(struct t6040_usb2_phy *tphy, bool flip) +{ + void __iomem *core = t6040_core(tphy); + + t6040_usb2_clear32(core + T6040_CORE_XBAR, 0xfc); + t6040_usb2_mask32(core + T6040_CORE_XBAR_LANES, 0x1f, flip ? 1 : 0); + t6040_usb2_mask32(core + T6040_CORE_XBAR, 0x3, 0x2); +} + +/* aciophy_slpctrl_init, mode 2: both lanes, whatever the orientation. */ +static void t6040_cio_lanes_on(struct t6040_usb2_phy *tphy) +{ + static const struct { u32 off, bit; bool set; } steps[] = { + { T6040_CORE_LANE_RX, 0x10, true }, { T6040_CORE_LANE_RX, 0x40, true }, + { T6040_CORE_LANE_RX, 0x1, true }, { T6040_CORE_LANE_RX, 0x4, true }, + { T6040_CORE_CMN_OVRD, 0x400, true }, { T6040_CORE_CMN_OVRD, 0x1000, true }, + { T6040_CORE_CMN_OVRD, 0x40, true }, { T6040_CORE_CMN_OVRD, 0x100, true }, + { T6040_CORE_CMN_OVRD, 0x4000, false }, { T6040_CORE_CMN_OVRD, 0x10000, true }, + { T6040_CORE_SLP_CTRL, 0x40, false }, { T6040_CORE_SLP_CTRL, 0x4, false }, + { T6040_CORE_SLP_CTRL, 0x400, false }, + }; + void __iomem *core = t6040_core(tphy); + unsigned int lane; + size_t i; + + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x2a); + udelay(1); + for (lane = 0; lane < 2; lane++) { + for (i = 0; i < ARRAY_SIZE(steps); i++) { + if (steps[i].set) + t6040_usb2_set32(core + steps[i].off, steps[i].bit << lane); + else + t6040_usb2_clear32(core + steps[i].off, steps[i].bit << lane); + udelay(1); + } + } +} + +/* aciophy_rx_powerdown(0), (1): CIO powers the receivers down, USB does not. */ +static void t6040_cio_rx_down(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + unsigned int lane; + + for (lane = 0; lane < 2; lane++) { + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x4000 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x40 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x400 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_LANE_RX, 0x1 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_LANE_RX, 0x10 << lane); + udelay(1); + } +} + +/* The Type-C state that needs CIO: USB4 entered, or the Thunderbolt alt mode. */ +static bool t6040_cio_state(const struct typec_mux_state *state) +{ + if (state->alt) + return state->alt->svid == USB_TYPEC_TBT_SID; + if (state->mode != TYPEC_MODE_USB4 || !state->data) + return false; + return FIELD_GET(EUDO_USB_MODE_MASK, + ((const struct enter_usb_data *)state->data)->eudo) == EUDO_USB_MODE_USB4; +} + +static int t6040_cio_up_locked(struct t6040_usb2_phy *tphy) +{ + bool flip; + int ret; + + lockdep_assert_held(&tphy->lock); + if (!tphy->usb3_ok || tphy->dp_up) + return -EBUSY; + switch (tphy->orientation) { + case TYPEC_ORIENTATION_NORMAL: + flip = false; + break; + case TYPEC_ORIENTATION_REVERSE: + flip = true; + break; + default: + dev_warn(tphy->dev, "CIO: no plug orientation\n"); + return -EINVAL; + } + if (tphy->usb3_up || tphy->pipe_switched) + t6040_usb3_down_locked(tphy); + tphy->usb3_lent = tphy->usb3_on; + + ret = pm_runtime_resume_and_get(tphy->dev); + if (ret) + return ret; + ret = t6040_usb3_wake(tphy); + if (ret) + goto sleep; /* the coprocessor block may be unclocked: never touch it */ + t6040_cio_tunables(tphy); + t6040_cio_xbar(tphy, flip); + t6040_cio_lanes_on(tphy); + ret = t6040_usb3_run_firmware(tphy, false, flip); + if (ret) { + t6040_usb3_firmware_power_down(tphy); + goto sleep; + } + tphy->cio_up = true; + dev_info(tphy->dev, "CIO PHY up, %s orientation\n", flip ? "reverse" : "normal"); + return 0; + +sleep: + t6040_usb3_sleep(tphy); + pm_runtime_put(tphy->dev); + dev_warn(tphy->dev, "CIO PHY bring-up failed: %d\n", ret); + return ret; +} + +static void t6040_cio_down_locked(struct t6040_usb2_phy *tphy) +{ + lockdep_assert_held(&tphy->lock); + if (!tphy->cio_up) + return; + t6040_phy_tx_cmn_down(tphy); + t6040_cio_rx_down(tphy); + fsleep(200); + t6040_usb3_firmware_power_down(tphy); + t6040_usb3_sleep(tphy); + tphy->cio_up = false; + pm_runtime_put(tphy->dev); + dev_info(tphy->dev, "CIO PHY asleep\n"); + t6040_usb3_reclaim_locked(tphy); +} + /* ---- DP phy_ops ---- */ static int t6040_dp_power_on(struct phy *phy) @@ -1432,6 +1596,8 @@ static int t6040_dp_power_on(struct phy *phy) guard(mutex)(&tphy->lock); if (!tphy->dp_ok || tphy->dp_up) return 0; + if (tphy->cio_up) + return -EBUSY; /* Pin D shares the running PHY with USB3. Keep its PIPE and firmware. */ if (tphy->dp_two_lanes) { if (!tphy->usb3_ok || !tphy->dp_alt) @@ -1581,6 +1747,12 @@ static int t6040_dp_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *s bool alt = false; guard(mutex)(&tphy->lock); + if (t6040_cio_state(state)) { + if (tphy->cio_up) + return 0; + return t6040_cio_up_locked(tphy); + } + t6040_cio_down_locked(tphy); tphy->dp_flip = (tphy->orientation == TYPEC_ORIENTATION_REVERSE); /* * Latch the DP alt mode state for the DCP's Type-C route. Pin From d4ede2888dbf637d27e391418f4801636ae40ebe Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:09:52 +1100 Subject: [PATCH 051/342] dt-bindings: apple: allow the T6040 USB4 routers' CIO reset and LSTX pin The T6040 (M4 Pro/Max) routers are reset through the PMGR CIO reconfig register, like T6000, and drive an LSTX sideband pin, like T8132. Add the apple,t6041-cio-reset compatible and let apple,t6040-usb4-acio carry the lstx pinctrl state and lstx-gpios. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../devicetree/bindings/reset/apple,t8103-cio-reset.yaml | 1 + .../bindings/thunderbolt/apple,t8103-usb4-acio.yaml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index 4c048e4f5487d..a7bc6bf4885c9 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -40,6 +40,7 @@ properties: - apple,t6020-cio-reset - apple,t6030-cio-reset - apple,t6031-cio-reset + - apple,t6041-cio-reset - apple,t8122-cio-reset - apple,t8132-cio-reset - const: apple,t6000-cio-reset diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index c8b7fc98c1545..d9dd4cd1aa756 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -207,7 +207,9 @@ allOf: properties: compatible: contains: - const: apple,t8132-usb4-acio + enum: + - apple,t6040-usb4-acio + - apple,t8132-usb4-acio then: properties: reg: From f5fedb273a5f7eb455e905a20568c6232592d873 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:09:52 +1100 Subject: [PATCH 052/342] arm64: dts: apple: t6040: wire the USB4 routers to their resets, LSTX pins and Type-C ports Give each T6040 router its CIO reconfig reset line (ADT pmgr reg[44], enableCioReconfig at +0x2024), its LSTX pin and lstx-gpios (ADT acioN gpio-lstx: AOP pins 49, 51, 53), and label the routers' graph endpoints. The CIO reconfig block uses the T8132 PMGR compatibles. On the J614s/J616s link each Type-C connector to the router behind the same ATC PHY (ADT acioN atc-phy-parent): typec0 (left back) to ACIO0, typec1 (left front) to ACIO1, typec2 (right) to ACIO2. The port controller skips a link to a disabled router. Name the routers' aliases usb4-N-acio, the name the loader looks up for the router (RC) tuning, as on T8112. Nothing is enabled here. From linux#1165. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6040-usb4.dtsi | 63 +++++++++++++++---- .../boot/dts/apple/t604x-j614-j616-usb4.dtsi | 54 ++++++++++++++++ .../arm64/boot/dts/apple/t604x-j614-j616.dtsi | 2 + 3 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi diff --git a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi index 1313766fe8775..cb15a0516393c 100644 --- a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi @@ -2,21 +2,20 @@ /* * T6040 USB4/PCIe-C resource description. * - * Every node remains disabled until the Type-C PHY transition, bootloader - * tuning handoff, and dynamic PCIe RID-to-SID policy are qualified. + * Every node is disabled here; a board enables the routers it has qualified. */ / { aliases { - usb4-0-rc = &usb4_0_acio; + usb4-0-acio = &usb4_0_acio; usb4-0-nhi = &usb4_0_nhi; usb4-0-pcie = &usb4_0_pcie; usb4-0-pcie-adapter = &usb4_0_acio; - usb4-1-rc = &usb4_1_acio; + usb4-1-acio = &usb4_1_acio; usb4-1-nhi = &usb4_1_nhi; usb4-1-pcie = &usb4_1_pcie; usb4-1-pcie-adapter = &usb4_1_acio; - usb4-2-rc = &usb4_2_acio; + usb4-2-acio = &usb4_2_acio; usb4-2-nhi = &usb4_2_nhi; usb4-2-pcie = &usb4_2_pcie; usb4-2-pcie-adapter = &usb4_2_acio; @@ -33,7 +32,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_0_mbox>; - resets = <&ps_atc0_cio>; + resets = <&cio_reset 0>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_0_lstx_pins>; + lstx-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; thunderbolt-switch; @@ -50,7 +52,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_0_acio_tbt: endpoint { }; }; }; @@ -127,7 +129,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_1_mbox>; - resets = <&ps_atc1_cio>; + resets = <&cio_reset 1>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_1_lstx_pins>; + lstx-gpios = <&pinctrl_aop 51 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; thunderbolt-switch; @@ -144,7 +149,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_1_acio_tbt: endpoint { }; }; }; @@ -221,7 +226,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_2_mbox>; - resets = <&ps_atc2_cio>; + resets = <&cio_reset 2>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_2_lstx_pins>; + lstx-gpios = <&pinctrl_aop 53 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; thunderbolt-switch; @@ -238,7 +246,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_2_acio_tbt: endpoint { }; }; }; @@ -517,3 +525,36 @@ }; }; }; + +/ { + /* ADT pmgr reg[44]: AppleT6041PMGR::enableCioReconfig at +0x2024. */ + pmgr_cio: power-management@502820000 { + compatible = "apple,t6041-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x5 0x02820000 0 0x4000>; + /* Enabled together with the routers. */ + status = "disabled"; + + cio_reset: reset-controller@2024 { + compatible = "apple,t6041-cio-reset", "apple,t6000-cio-reset"; + reg = <0x2024 0x4>; + #reset-cells = <1>; + }; + }; +}; + +&pinctrl_aop { + /* ADT acioN gpio-lstx. */ + usb4_0_lstx_pins: usb4-0-lstx-pins { + pinmux = ; + }; + + usb4_1_lstx_pins: usb4-1-lstx-pins { + pinmux = ; + }; + + usb4_2_lstx_pins: usb4-2-lstx-pins { + pinmux = ; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi new file mode 100644 index 0000000000000..ec32ca4bf9c03 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * MacBook Pro (14-inch and 16-inch, M4 Pro) USB4/Thunderbolt: each Type-C + * port's connector is linked to the USB4 router behind the same ATC PHY + * (ADT acioN atc-phy-parent = atc-phyN): typec0 (left back) to ACIO0, + * typec1 (left front) to ACIO1, typec2 (right) to ACIO2. The routers stay + * disabled, and a port controller skips a link to a disabled router, so this + * changes nothing until a board enables them. + */ + +&usb4_0_acio_tbt { + remote-endpoint = <&typec0_con_tbt>; +}; + +&usb4_1_acio_tbt { + remote-endpoint = <&typec1_con_tbt>; +}; + +&usb4_2_acio_tbt { + remote-endpoint = <&typec2_con_tbt>; +}; + +&typec0 { + ports { + port@2 { + reg = <2>; + typec0_con_tbt: endpoint { + remote-endpoint = <&usb4_0_acio_tbt>; + }; + }; + }; +}; + +&typec1 { + ports { + port@2 { + reg = <2>; + typec1_con_tbt: endpoint { + remote-endpoint = <&usb4_1_acio_tbt>; + }; + }; + }; +}; + +&typec2 { + ports { + port@2 { + reg = <2>; + typec2_con_tbt: endpoint { + remote-endpoint = <&usb4_2_acio_tbt>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi index 368503f7f4884..864e87400bb87 100644 --- a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi @@ -3444,3 +3444,5 @@ power-domain-names = "sys", "cpu", "mpm", "td", "base", "perf"; status = "okay"; }; + +#include "t604x-j614-j616-usb4.dtsi" From 6e1a916a25443db32782f87d10adf07a71a75bc0 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:10:08 +1100 Subject: [PATCH 053/342] arm64: dts: apple: j616s: enable USB4/Thunderbolt on the left back port Enable ACIO0 (typec0, left back), its DART, NHI, mailbox, CIO reconfig block and power domains. The loader hands over the router, adapter and NHI tuning and the DROM. Give the router DART the ADT vm-base window so the NHI rings sit where its 32-bit + 1 TiB addressing reaches them. The PCIe tunnel stays off: host-to-host (XDomain, thunderbolt-net) and USB4 links only for now. Tested on the J616s against the M2 (TB5 cable): link after cold boot, 2 x 20 Gb/s each way, thunderbolt-net iperf3; see the PR for numbers. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index c934110c69b95..0e29b6291ed9f 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -165,3 +165,47 @@ &scaler0 { status = "okay"; }; + +/* + * USB4/Thunderbolt on the left back port (typec0, ACIO0). The loader hands + * the router, adapter and NHI tuning and the DROM over. No PCIe tunnel yet: + * host-to-host (XDomain, thunderbolt-net) and USB4 links only. + */ +&pmgr_cio { + status = "okay"; +}; + +&ps_atc0_cio { + status = "okay"; +}; + +&ps_atc0_pcie { + status = "okay"; +}; + +&ps_atc0_cio_pcie { + status = "okay"; +}; + +&ps_atc0_cio_usb { + status = "okay"; +}; + +&usb4_0_mbox { + status = "okay"; +}; + +&usb4_0_acio { + /delete-property/ apple,pcie-tunnel; + status = "okay"; +}; + +&usb4_0_dart { + /* ADT dart-acio0 vm-base: the NHI addresses its rings below 1 TiB + 4 GiB. */ + apple,dma-range = <0x100 0x4000 0x0 0xffff0000>; + status = "okay"; +}; + +&usb4_0_nhi { + status = "okay"; +}; From 56ac7f78d800f16f7c21b2e79e6be64f008cc1be Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:27:48 +1100 Subject: [PATCH 054/342] usb: core: Keep a device that wakes itself when suspended awake in suspend-to-idle The SteelSeries Apex Pro keyboard (1038:1610) signals a remote wakeup by itself about 0.5 s after every suspend, with no key pressed. With its wakeup enabled, which is the default for a USB keyboard, every suspend-to-idle aborts with "Some devices failed to suspend, or early wake event detected", and with runtime PM it autosuspends and resumes every couple of seconds. The report it sends after such a wake is the same every time, Enter, Space and Escape down, then Escape up, and usbhid drops it while the resume runs. Disabling its wakeup lets the system sleep but then the keyboard cannot wake it. Where the host controller keeps running in suspend-to-idle, the USB core can already keep a device awake with its interrupt transfers in flight, and a completed transfer then wakes the system. Add a quirk for devices that wake themselves when suspended and keep them awake that way when their wakeup is enabled. The keyboard then never sees a suspend, sends nothing, and its first real key press wakes the system. The hubs above it are kept awake as for any other device kept awake below them. Measured on a MacBook Pro (M4 Pro) with the keyboard behind a USB-C dock: 4 of 4 suspend-to-idle attempts aborted 0.49 s after the keyboard's suspend, and runtime autosuspend resumed it 0.5-0.7 s after each suspend. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/usb/core/driver.c | 8 +++++- drivers/usb/core/quirks.c | 4 +++ drivers/usb/core/usb-wakeup-test.c | 42 ++++++++++++++++++++++++++++++ drivers/usb/host/xhci-ring.c | 6 ++--- include/linux/usb/quirks.h | 8 ++++++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 4a9bdcf8bb11a..81bb9ffad1059 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1394,7 +1394,9 @@ static int usb_resume_interface(struct usb_device *udev, * can reach the host controller: a hub that does not pass one on from below * while it is suspended itself, a hub with wakeup enabled that does not signal * the changes of its own ports while it is suspended, and every device between - * such a hub and the root hub, root hub included. This only works while the + * such a hub and the root hub, root hub included, and a device that wakes + * itself whenever it is suspended, which then wakes the system with its own + * input instead, as do the devices above it. This only works while the * host controller keeps running, so its interrupt reports the hub's status * change. * @@ -1422,6 +1424,10 @@ VISIBLE_IF_KUNIT bool usb_stay_awake_for_wakeup(struct usb_device *udev, pm_mess usb_wakeup_reaches(udev)) return true; + if ((udev->quirks & USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED) && + udev->do_remote_wakeup) + return true; + /* Children are done with their suspend before their parent starts */ usb_hub_for_each_child(udev, port1, child) { if (child->awake_in_sleep) diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index a374ff625a24c..770bba563ee1e 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c @@ -476,6 +476,10 @@ static const struct usb_device_id usb_quirk_list[] = { /* Sony Xperia XZ1 Compact (lilac) smartphone in fastboot mode */ { USB_DEVICE(0x0fce, 0x0dde), .driver_info = USB_QUIRK_NO_LPM }, + /* SteelSeries Apex Pro: wakes itself about 0.5 s after every suspend */ + { USB_DEVICE(0x1038, 0x1610), .driver_info = + USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED }, + /* Action Semiconductor flash disk */ { USB_DEVICE(0x10d6, 0x2200), .driver_info = USB_QUIRK_STRING_FETCH_255 }, diff --git a/drivers/usb/core/usb-wakeup-test.c b/drivers/usb/core/usb-wakeup-test.c index e563dd7822886..c62c238389d6a 100644 --- a/drivers/usb/core/usb-wakeup-test.c +++ b/drivers/usb/core/usb-wakeup-test.c @@ -296,6 +296,47 @@ static void usb_wakeup_stay_awake_not_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&vl122->udev, PMSG_SUSPEND)); } +/* + * A keyboard that wakes itself whenever it is suspended, behind two hubs that pass a + * remote wakeup on: with its wakeup enabled it is kept awake in suspend-to-idle, so its + * own input wakes the system, and so are the hubs and the root hub above it. Not with + * its wakeup disabled, for other system sleep transitions, or on a controller that halts. + */ +static void usb_wakeup_stay_awake_self_waking_test(struct kunit *test) +{ + struct usb_wakeup_test_dev *root = usb_wakeup_test_s2idle_root(test); + struct usb_wakeup_test_dev *hub = usb_wakeup_test_add(test, root, true); + struct usb_wakeup_test_dev *dock = usb_wakeup_test_add(test, hub, true); + struct usb_wakeup_test_dev *keyboard = usb_wakeup_test_add(test, dock, false); + struct usb_hcd *hcd = bus_to_hcd(root->udev.bus); + + keyboard->udev.quirks = USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED; + KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_SUSPEND)); + + keyboard->udev.do_remote_wakeup = 1; + KUNIT_EXPECT_TRUE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_SUSPEND)); + KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_FREEZE)); + + pm_suspend_target_state = PM_SUSPEND_MEM; + KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_SUSPEND)); + pm_suspend_target_state = PM_SUSPEND_TO_IDLE; + + hcd->runs_in_s2idle = 0; + KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_SUSPEND)); + hcd->runs_in_s2idle = 1; + + keyboard->udev.awake_in_sleep = 1; + KUNIT_EXPECT_TRUE(test, usb_stay_awake_for_wakeup(&dock->udev, PMSG_SUSPEND)); + dock->udev.awake_in_sleep = 1; + KUNIT_EXPECT_TRUE(test, usb_stay_awake_for_wakeup(&hub->udev, PMSG_SUSPEND)); + hub->udev.awake_in_sleep = 1; + KUNIT_EXPECT_TRUE(test, usb_stay_awake_for_wakeup(&root->udev, PMSG_SUSPEND)); + + /* A keyboard without the quirk is suspended and wakes through the hubs. */ + keyboard->udev.quirks = 0; + KUNIT_EXPECT_FALSE(test, usb_stay_awake_for_wakeup(&keyboard->udev, PMSG_SUSPEND)); +} + static struct kunit_case usb_wakeup_test_cases[] = { KUNIT_CASE(usb_wakeup_reaches_vl122_test), KUNIT_CASE(usb_wakeup_reaches_hub_test), @@ -306,6 +347,7 @@ static struct kunit_case usb_wakeup_test_cases[] = { KUNIT_CASE(usb_wakeup_stay_awake_armed_vl122_test), KUNIT_CASE(usb_wakeup_stay_awake_vl122_test), KUNIT_CASE(usb_wakeup_stay_awake_not_test), + KUNIT_CASE(usb_wakeup_stay_awake_self_waking_test), {} }; diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a976c7407b989..0a96730627d73 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2035,9 +2035,9 @@ static bool xhci_s2idle_port_change(struct xhci_hcd *xhci, struct xhci_port *por } /* - * Only hubs that the USB core kept awake for a remote wakeup have transfers in - * flight, see usb_suspend_both(): a completed one reports a change on one of - * their ports. + * Only devices that the USB core kept awake for a remote wakeup have transfers + * in flight, see usb_suspend_both(): a completed one reports a change on one of + * a hub's ports, or the input of a device that wakes itself when suspended. */ VISIBLE_IF_KUNIT bool xhci_s2idle_transfer_wakeup(const struct usb_device *udev) { diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h index a77d3eaf8dc4c..fcb8208b398e7 100644 --- a/include/linux/usb/quirks.h +++ b/include/linux/usb/quirks.h @@ -99,4 +99,12 @@ */ #define USB_QUIRK_HUB_NO_SUSPENDED_PORT_WAKEUP BIT(21) +/* + * Device signals a remote wakeup by itself shortly after every suspend, with + * no input. Keep it awake in suspend-to-idle, with its interrupt transfers + * running, when its wakeup is enabled and the host controller keeps running, + * so that its own input wakes the system instead. + */ +#define USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED BIT(22) + #endif /* __LINUX_USB_QUIRKS_H */ From a3044a6668c060b08c3d7e4a2a7e0daf4bb80c82 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sat, 7 Nov 2026 23:43:50 +1100 Subject: [PATCH 055/342] media: apple: ave: constant-quality rate control Offer V4L2_MPEG_VIDEO_BITRATE_MODE_CQ with V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (0-100, 100 best). The session and frame writers already carry the constant-quality layout (rate-control mode 3); what was missing was the quality-to-QP mapping. Measured on macOS 27.0 on the M4 Pro from the slice QPs of its own VideoToolbox output at every quality step 0.00-1.00 (H.264 and HEVC agree, and so do the J700 captures at 0.30, 0.60 and 0.90): one QP for every frame, capped at 48. Use the same table, no data-rate limit, and twice the coded-data capacity, as macOS allows. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/media/platform/apple/ave/ave-sess.c | 31 ++++++++++++++++++++- drivers/media/platform/apple/ave/ave-v4l2.c | 11 +++++--- drivers/media/platform/apple/ave/ave.h | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/apple/ave/ave-sess.c b/drivers/media/platform/apple/ave/ave-sess.c index 902f6faf30fd7..583d5c1998be6 100644 --- a/drivers/media/platform/apple/ave/ave-sess.c +++ b/drivers/media/platform/apple/ave/ave-sess.c @@ -27,6 +27,7 @@ #define AVE_RC_VBR 4 #define AVE_RC_CBR 2 +#define AVE_RC_CQ 3 /* Filler-data NAL unit types */ #define AVE_H264_NAL_FILLER 12 @@ -106,6 +107,23 @@ static int ave_pick_level(const struct ave_params *p, u32 requested) return -EINVAL; } +/* + * Constant quality: the QP macOS 27.0 encodes with for VideoToolbox quality + * q = index / 100 (read from the slice QPs of its own H.264 and HEVC output on + * the M4 Pro; the J700 captures at 0.30, 0.60 and 0.90 agree). Every frame of + * a constant-quality session uses this one QP, and the QP never exceeds 48. + */ +static const u8 ave_cq_qp[101] = { + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 47, 47, 47, 46, 46, 46, 45, 45, 44, + 44, 44, 43, 43, 43, 42, 42, 42, 41, 41, 40, 40, 40, 39, 39, 39, 38, 38, 37, 37, + 37, 36, 36, 35, 35, 35, 34, 34, 33, 33, 33, 32, 32, 31, 31, 30, 30, 29, 29, 29, + 28, 28, 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 18, + 18, 17, 17, 16, 15, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, + 0, +}; + +#define AVE_CQ_MAX_QP 48 + static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) { bool baseline = false; @@ -178,7 +196,15 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) p->gop = ctx->gop_size ?: 120; p->bitrate = ctx->bitrate; - if (ctx->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) { + if (ctx->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ) { + /* One QP for every frame, no data-rate limit, as macOS sets it. */ + p->rc_mode = AVE_RC_CQ; + p->limit_bytes = 0; + p->initial_qp = ave_cq_qp[min(ctx->quality, 100U)]; + p->max_qp = min_t(u32, p->max_qp, AVE_CQ_MAX_QP); + if (p->min_qp > (s32)p->max_qp) + p->min_qp = p->max_qp; + } else if (ctx->bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) { p->rc_mode = AVE_RC_CBR; p->limit_bytes = 0; } else { @@ -205,6 +231,9 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) /* 10-bit sessions get a quarter more, as macOS sizes them. */ if (p->bit_depth == 10) p->coded_cap = ALIGN(p->coded_cap * 5 / 4, SZ_16K); + /* Constant quality can exceed the bit-rate modes' frame size; macOS sizes up to 2x. */ + if (p->rc_mode == AVE_RC_CQ) + p->coded_cap = ALIGN(p->coded_cap * 2, SZ_16K); p->coded_cap = max_t(u32, p->coded_cap, AVE_CODED_MIN); if (ctx->ave->layout->counted && (p->fps_num != 30ULL * p->fps_den || diff --git a/drivers/media/platform/apple/ave/ave-v4l2.c b/drivers/media/platform/apple/ave/ave-v4l2.c index ac86638f4cafc..0faf1cc70784e 100644 --- a/drivers/media/platform/apple/ave/ave-v4l2.c +++ b/drivers/media/platform/apple/ave/ave-v4l2.c @@ -420,6 +420,9 @@ static int ave_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: ctx->bitrate_mode = ctrl->val; break; + case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY: + ctx->quality = ctrl->val; + break; case V4L2_CID_MPEG_VIDEO_BITRATE: WRITE_ONCE(ctx->bitrate, ctrl->val); break; @@ -478,13 +481,13 @@ static int ave_init_ctrls(struct ave_ctx *ctx) const struct v4l2_ctrl_ops *ops = &ave_ctrl_ops; struct v4l2_ctrl *c; - v4l2_ctrl_handler_init(hdl, 17); + v4l2_ctrl_handler_init(hdl, 18); - /* Constant quality needs a quality-to-QP mapping that is not known yet. */ v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_MPEG_VIDEO_BITRATE_MODE, - V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, - BIT(V4L2_MPEG_VIDEO_BITRATE_MODE_CQ), + V4L2_MPEG_VIDEO_BITRATE_MODE_CQ, 0, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); + /* Constant quality: 100 is the best; same scale as VideoToolbox's 0.0-1.0. */ + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, 0, 100, 1, 50); v4l2_ctrl_new_std(hdl, ops, V4L2_CID_MPEG_VIDEO_BITRATE, 100000, 100000000, 1, 4000000); /* diff --git a/drivers/media/platform/apple/ave/ave.h b/drivers/media/platform/apple/ave/ave.h index 0f654aa842f16..bda3949208575 100644 --- a/drivers/media/platform/apple/ave/ave.h +++ b/drivers/media/platform/apple/ave/ave.h @@ -332,6 +332,7 @@ struct ave_ctx { struct delayed_work poll_work; u32 bitrate_mode; + u32 quality; /* V4L2 constant quality, 0..100 */ u32 bitrate; u32 bitrate_peak; u32 gop_size; From 0b990338ea561bd0139189b8f6cdd126d9c7e796 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:28:59 +0000 Subject: [PATCH 056/342] wifi: brcmfmac: report no channel for the AWDL interface AWDL has no operating channel. The firmware moves awdl0 through its availability-window channel sequence, and the AWDL bsscfg rejects the chanspec query (brcmfmac returns -EBADE). cfg80211 asks for the channel whenever nl80211 describes the interface, which includes the notification sent when awdl0 is removed, so every AWDL teardown logged ieee80211 phy1: brcmf_cfg80211_get_channel: chanspec failed (-52) Return -ENODATA for an AWDL interface, as cfg80211 expects from an interface that is not on a channel. nl80211 then leaves the channel attributes out instead of failing. Seen on the BCM4387 of a MacBook Air (M2) and a MacBook Pro (M1 Pro) with firmware 20.96.31.0.8.7.148. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 078a689320ef2..b415aaeb73479 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -5970,6 +5970,7 @@ static int brcmf_cfg80211_get_channel(struct wiphy *wiphy, struct net_device *ndev = wdev->netdev; struct brcmf_pub *drvr = cfg->pub; struct brcmu_chan ch; + struct brcmf_if *ifp; enum nl80211_band band = 0; enum nl80211_chan_width width = 0; u32 chanspec; @@ -5978,7 +5979,17 @@ static int brcmf_cfg80211_get_channel(struct wiphy *wiphy, if (!ndev || drvr->bus_if->state != BRCMF_BUS_UP) return -ENODEV; - err = brcmf_fil_iovar_int_get(netdev_priv(ndev), "chanspec", &chanspec); + /* AWDL has no operating channel: the firmware moves the interface + * through its availability-window channel sequence, and the AWDL + * bsscfg rejects the chanspec query. Report no channel, as for an + * interface that is not on one, rather than logging an error each + * time nl80211 describes awdl0 (its removal notification does). + */ + ifp = netdev_priv(ndev); + if (ifp->is_awdl) + return -ENODATA; + + err = brcmf_fil_iovar_int_get(ifp, "chanspec", &chanspec); if (err) { bphy_err(drvr, "chanspec failed (%d)\n", err); return err; From 00f6ed7c8e65b7a581565c77ecf35cb2a22343eb Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:38:44 +1100 Subject: [PATCH 057/342] tools/asahi: pciec-policy-tests: extract the shared PCIe-C eligibility helper apple_cio_pcie_tunnel_is_preinitialized() now calls apple_cio_pciec_eligible(), which also admits apple,t6040-pciec. Pull the helper into the test build and take a const node in the fixture's of_device_is_compatible(), as the kernel's does. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/asahi/pciec-policy-tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index 825caefac0912..a399c7ef6e023 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -38,7 +38,7 @@ def function(source, name): struct of_device_id { const char *compatible; const void *data; }; struct of_phandle_args { struct device_node *np; }; static int maps; -static bool of_device_is_compatible(struct device_node *np, const char *compat) +static bool of_device_is_compatible(const struct device_node *np, const char *compat) { for (int i = 0; np && i < 3 && np->compat[i]; i++) if (!strcmp(np->compat[i], compat)) @@ -149,6 +149,7 @@ def main(): matches = re.search(r'static const struct of_device_id apple_pcie_of_match\[\] = \{.*?\n\};', pci, re.S)[0] production = '\n'.join((defines, info, matches, function(pci, 'apple_pcie_tunnel_needs_cold_init'), + function(acio, 'apple_cio_pciec_eligible'), function(acio, 'apple_cio_pcie_tunnel_is_preinitialized'))) code = FIXTURE.replace('/* PRODUCTION */', production) with tempfile.TemporaryDirectory(prefix='pciec-policy-') as tmp: From 0e2e11314ec7485921e4fd25ce9b8f154c35cc53 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:44:11 +1100 Subject: [PATCH 058/342] arm64: dts: apple: t8112: enable the JPEG encoders The T8112 JPEG engines now have wide64 match data. Enable both engines and their DARTs for every M2 board; they are SoC blocks with no board-specific wiring. T6000 stays disabled (incomplete reset image). Tested on the M2 (J413, fleet33 + this driver, DT enabled at runtime): both engines identify as HWREV 0xe0008 and bind; NV12 encodes at 3840x2160/1920x1080/1280x720/640x480 decode with ffmpeg at 41.6-43.4 dB PSNR (q75) on both engines; GStreamer -e drains (3/3 per size); three s2idle cycles with both engines bound, encoding after every resume; no DART or JPEG faults. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/admin-guide/media/apple-jpeg.rst | 8 ++++---- arch/arm64/boot/dts/apple/t8112.dtsi | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/media/apple-jpeg.rst b/Documentation/admin-guide/media/apple-jpeg.rst index 4719fe5ca8970..a5bc6e18de907 100644 --- a/Documentation/admin-guide/media/apple-jpeg.rst +++ b/Documentation/admin-guide/media/apple-jpeg.rst @@ -35,10 +35,10 @@ testable without hardware, but probe refuses runtime use until that reset image is complete. Do not enable T6000 engine nodes for streaming yet. Each engine has a 16 KiB MMIO resource and a separate adjacent DART at SID 0. -The engine's resource must not include the DART window. Both new T6000 and -T8112 engine/DART pairs remain disabled in the SoC descriptions. Enabling -nodes and changing installed boot DTBs requires board qualification. Existing -power-domain and performance-provider nodes must also be available. +The engine's resource must not include the DART window. Both T8112 engines +and their DARTs are enabled in ``t8112.dtsi`` (qualified on the J413). The +T6000 pairs stay disabled until the reset image is complete. Enabling nodes on +another SoC requires qualifying both of its instances. KUnit ----- diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 35bc48e39bb4e..f9ead58538938 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -2651,3 +2651,20 @@ }; #include "t8112-peripherals.dtsi" + +/* Both JPEG encoders are SoC blocks with no board wiring. */ +&m2_dart_jpeg0 { + status = "okay"; +}; + +&m2_jpeg0 { + status = "okay"; +}; + +&m2_dart_jpeg1 { + status = "okay"; +}; + +&m2_jpeg1 { + status = "okay"; +}; From 556fa11552bc2db5cfbba44686f3c837afe6d5a3 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:48:01 +1100 Subject: [PATCH 059/342] media: apple: ave: add a speed-over-quality control Add a driver-private boolean control, "Prioritize Speed Over Quality" (V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED), off by default. It is VideoToolbox's PrioritizeEncodingSpeedOverQuality: macOS changes one Start word from 3 to 5 for it, the word the driver called the size class (3 above 720p). With 5 there, HEVC encodes 1.7-1.8 times faster for about 12% more bits at the same PSNR; H.264 does not get faster (on macOS either), so the control only applies to 8-bit HEVC above 1280x720 (Main 10 is not measured yet). macOS 27.0 also changes a per-frame Process word from 3 to 5. Its counterpart in this firmware's layout, the low-delay word at Process +0xcf8, is not the same field: writing 5 there corrupts the coded pictures (PSNR-Y 16 dB), so it is left alone. With only the Start word the bitstreams match what macOS writes in speed mode to the byte average. The control is read when streaming starts. With the control off, every command the driver builds is byte-identical to before. Also expose the constant-quality table lookup for a KUnit test, and document constant quality and the new control. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/admin-guide/media/apple-ave.rst | 13 +++- .../media/platform/apple/ave/ave-abi-test.c | 76 +++++++++++++++++++ drivers/media/platform/apple/ave/ave-sess.c | 16 +++- drivers/media/platform/apple/ave/ave-v4l2.c | 17 ++++- drivers/media/platform/apple/ave/ave-writer.c | 10 ++- drivers/media/platform/apple/ave/ave.h | 13 ++++ 6 files changed, 139 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/media/apple-ave.rst b/Documentation/admin-guide/media/apple-ave.rst index d43e759481cd6..02eede3115323 100644 --- a/Documentation/admin-guide/media/apple-ave.rst +++ b/Documentation/admin-guide/media/apple-ave.rst @@ -139,8 +139,17 @@ Limits (twice the average when left at 0), or CBR. In CBR mode, frames are padded with filler data once more than half a second of bit rate has gone unused, as macOS does; the driver adds the filler itself if the firmware does not. - Constant quality is not offered. ``BITRATE`` may change while streaming and applies from the next - frame; ``FORCE_KEY_FRAME`` makes the next frame an IDR. + ``BITRATE_MODE_CQ`` codes every frame with one QP taken from + ``CONSTANT_QUALITY`` (0-100, 100 best) through the table macOS uses for + the same quality. ``BITRATE`` may change while streaming and applies from + the next frame; ``FORCE_KEY_FRAME`` makes the next frame an IDR. +- ``Prioritize Speed Over Quality`` (driver-private boolean, + ``V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED`` = codec class base ``0x1200``, off by + default) is VideoToolbox's PrioritizeEncodingSpeedOverQuality: it sets the + firmware's throughput mode to 5 instead of 3. It applies to 8-bit HEVC + above 1280x720 (Main 10 is not measured yet) and is read when streaming + starts. H.264 is not faster with it, on macOS either, so it has no effect + there. - Either three B-frames or none (``B_FRAMES`` 3 or 0). H.264 Baseline and a GOP size of 1 never use them. - The level control is a minimum: the driver raises it to what the size, diff --git a/drivers/media/platform/apple/ave/ave-abi-test.c b/drivers/media/platform/apple/ave/ave-abi-test.c index 5e3ed8e212d23..255ec6e9950d2 100644 --- a/drivers/media/platform/apple/ave/ave-abi-test.c +++ b/drivers/media/platform/apple/ave/ave-abi-test.c @@ -225,6 +225,81 @@ static void ave_9003_hevc_main10(struct kunit *test) } } +/* One 1080p HEVC Start or first Process image, with speed mode @speed. */ +static void ave_speed_image(struct kunit *test, struct ave_ctx *ctx, + enum ave_image image, bool bframes, bool speed, + u8 *cmd, size_t len) +{ + ave_test_session(ctx->sess, AVE_CODEC_HEVC, 1920, 1080, bframes); + ctx->sess->p.speed = speed; + memset(cmd, 0, len); + if (image == AVE_IMAGE_START) + KUNIT_ASSERT_EQ(test, ave_build_start(ctx, cmd, len), 0); + else + KUNIT_ASSERT_EQ(test, ave_build_process(ctx, cmd, len, 0, + 0x8f0000000ULL, 8000000, + false), 0); + ave_stamp_command(ctx->ave->layout->abi, cmd, 1, 2); +} + +/* + * Speed over quality on 9003: HEVC Start changes only the throughput mode + * (+0x320, 3 -> 5); Process stays the same, with and without B-frames. + */ +static void ave_9003_speed(struct kunit *test) +{ + struct ave_dev *ave = kunit_kzalloc(test, sizeof(*ave), GFP_KERNEL); + struct ave_ctx *ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + struct ave_session *sess = kunit_kzalloc(test, sizeof(*sess), GFP_KERNEL); + u8 *quality = kunit_kzalloc(test, 0x14000, GFP_KERNEL); + u8 *speed = kunit_kzalloc(test, 0x14000, GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, ave); + KUNIT_ASSERT_NOT_NULL(test, ctx); + KUNIT_ASSERT_NOT_NULL(test, sess); + KUNIT_ASSERT_NOT_NULL(test, quality); + KUNIT_ASSERT_NOT_NULL(test, speed); + ave->layout = &ave_layout_9003_78_0; + ctx->ave = ave; + ctx->sess = sess; + + for (unsigned int i = 0; i < 4; i++) { + enum ave_image image = i & 1 ? AVE_IMAGE_PROCESS : AVE_IMAGE_START; + bool bframes = i & 2; + size_t len = ave->layout->bytes[AVE_CODEC_HEVC - 1][image]; + u32 changed = image == AVE_IMAGE_START ? 0x320 : 0; + + ave_speed_image(test, ctx, image, bframes, false, quality, len); + ave_speed_image(test, ctx, image, bframes, true, speed, len); + if (changed) { + KUNIT_EXPECT_EQ(test, get_unaligned_le32(quality + changed), 3); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(speed + changed), 5); + } + for (size_t off = 0; off < len; off += 4) { + if (changed && off == changed) + continue; + KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(quality + off), + get_unaligned_le32(speed + off), + "case %u word +%#zx", i, off); + } + } +} + +/* Constant quality uses the measured macOS table: anchors and shape. */ +static void ave_cq_table(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(0), 48); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(30), 40); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(50), 33); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(60), 28); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(90), 10); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(100), 0); + KUNIT_EXPECT_EQ(test, ave_cq_initial_qp(1000), 0); + for (unsigned int q = 1; q <= 100; q++) + KUNIT_EXPECT_LE(test, ave_cq_initial_qp(q), + ave_cq_initial_qp(q - 1)); +} + static void ave_6070_images(struct kunit *test) { const struct ave_fw_abi *abi = &ave_abi_6070; @@ -462,6 +537,7 @@ static void ave_6070_variants(struct kunit *test) static struct kunit_case ave_abi_cases[] = { KUNIT_CASE(ave_9003_byte_equality), KUNIT_CASE(ave_9003_hevc_main10), + KUNIT_CASE(ave_9003_speed), KUNIT_CASE(ave_cq_table), KUNIT_CASE(ave_6070_images), KUNIT_CASE(ave_6070_replies), KUNIT_CASE(ave_6070_split_surfaces), KUNIT_CASE(ave_6070_gate), KUNIT_CASE(ave_6070_channels), diff --git a/drivers/media/platform/apple/ave/ave-sess.c b/drivers/media/platform/apple/ave/ave-sess.c index 583d5c1998be6..dde038a81299a 100644 --- a/drivers/media/platform/apple/ave/ave-sess.c +++ b/drivers/media/platform/apple/ave/ave-sess.c @@ -124,6 +124,11 @@ static const u8 ave_cq_qp[101] = { #define AVE_CQ_MAX_QP 48 +u32 ave_cq_initial_qp(u32 quality) +{ + return ave_cq_qp[min(quality, 100U)]; +} + static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) { bool baseline = false; @@ -193,6 +198,15 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) p->reorder_off = !ctx->b_frames; p->refs = p->intra_only ? 1 : p->bframes ? 5 : 2; p->slots = p->bframes ? 5 : 3; + /* + * Speed over quality changes the firmware's throughput mode from 3 to + * 5, as macOS does. It is measured for 8-bit HEVC above 720p on the + * 9003 layout only; H.264 does not get faster from it (on macOS + * either). + */ + p->speed = ctx->prioritize_speed && p->codec == AVE_CODEC_HEVC && + p->sample_bytes == 1 && !ctx->ave->layout->counted && + p->width * p->height > 1280 * 720; p->gop = ctx->gop_size ?: 120; p->bitrate = ctx->bitrate; @@ -200,7 +214,7 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) /* One QP for every frame, no data-rate limit, as macOS sets it. */ p->rc_mode = AVE_RC_CQ; p->limit_bytes = 0; - p->initial_qp = ave_cq_qp[min(ctx->quality, 100U)]; + p->initial_qp = ave_cq_initial_qp(ctx->quality); p->max_qp = min_t(u32, p->max_qp, AVE_CQ_MAX_QP); if (p->min_qp > (s32)p->max_qp) p->min_qp = p->max_qp; diff --git a/drivers/media/platform/apple/ave/ave-v4l2.c b/drivers/media/platform/apple/ave/ave-v4l2.c index 0faf1cc70784e..d46a810e24923 100644 --- a/drivers/media/platform/apple/ave/ave-v4l2.c +++ b/drivers/media/platform/apple/ave/ave-v4l2.c @@ -462,6 +462,9 @@ static int ave_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_MPEG_VIDEO_HEVC_PROFILE: ctx->hevc_profile = ctrl->val; break; + case V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED: + ctx->prioritize_speed = ctrl->val; + break; case V4L2_CID_MPEG_VIDEO_HEADER_MODE: case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT: break; @@ -475,13 +478,22 @@ static const struct v4l2_ctrl_ops ave_ctrl_ops = { .s_ctrl = ave_s_ctrl, }; +static const struct v4l2_ctrl_config ave_ctrl_prioritize_speed = { + .ops = &ave_ctrl_ops, + .id = V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED, + .name = "Prioritize Speed Over Quality", + .type = V4L2_CTRL_TYPE_BOOLEAN, + .max = 1, + .step = 1, +}; + static int ave_init_ctrls(struct ave_ctx *ctx) { struct v4l2_ctrl_handler *hdl = &ctx->hdl; const struct v4l2_ctrl_ops *ops = &ave_ctrl_ops; struct v4l2_ctrl *c; - v4l2_ctrl_handler_init(hdl, 18); + v4l2_ctrl_handler_init(hdl, 19); v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_MPEG_VIDEO_BITRATE_MODE, V4L2_MPEG_VIDEO_BITRATE_MODE_CQ, 0, @@ -534,6 +546,9 @@ static int ave_init_ctrls(struct ave_ctx *ctx) v4l2_ctrl_new_std(hdl, ops, V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP, 0, 51, 1, 0); v4l2_ctrl_new_std(hdl, ops, V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP, 0, 51, 1, 51); + /* Off by default: macOS also codes for quality unless asked. */ + v4l2_ctrl_new_custom(hdl, &ave_ctrl_prioritize_speed, NULL); + /* The firmware holds up to five frames; one more keeps it fed. */ c = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, 1, 32, 1, AVE_MAX_SLOTS + 1); diff --git a/drivers/media/platform/apple/ave/ave-writer.c b/drivers/media/platform/apple/ave/ave-writer.c index 1e69481057cc8..60883b73766f7 100644 --- a/drivers/media/platform/apple/ave/ave-writer.c +++ b/drivers/media/platform/apple/ave/ave-writer.c @@ -153,6 +153,10 @@ void ave_stamp_command(const struct ave_fw_abi *abi, u8 *cmd, u64 timeout, ave_put64(cmd, abi->created_offset, created); } +/* Throughput modes: 3 codes for quality, 5 prioritizes speed (as macOS) */ +#define AVE_THROUGHPUT_QUALITY 3 +#define AVE_THROUGHPUT_SPEED 5 + #define AVE_START_ARRAY_LEN 30 #define AVE_START_INIT_QP_VALUE 26 @@ -306,9 +310,11 @@ static void ave_start_config(const struct ave_params *p, u8 *cmd, ave_start_put32(cmd, l->ref_depth, p->bframes ? 3 : 1); ave_start_put32(cmd, l->idr_interval, p->gop); - /* Picture size */ + /* Picture size class, which is also the throughput mode */ ave_start_put32(cmd, l->size_class, - p->width * p->height > 1280 * 720 ? 3 : 1); + p->speed ? AVE_THROUGHPUT_SPEED : + p->width * p->height > 1280 * 720 ? AVE_THROUGHPUT_QUALITY : + 1); ave_start_put32(cmd, l->coded_w, p->cw); ave_start_put32(cmd, l->coded_h, p->ch); ave_start_put32(cmd, l->coded_h2, p->ch); diff --git a/drivers/media/platform/apple/ave/ave.h b/drivers/media/platform/apple/ave/ave.h index bda3949208575..8abe90415f9a4 100644 --- a/drivers/media/platform/apple/ave/ave.h +++ b/drivers/media/platform/apple/ave/ave.h @@ -128,6 +128,16 @@ enum ave_opcode { #include "ave-layout.h" +/* + * Driver-private codec-class controls. + * + * PRIORITIZE_SPEED is VideoToolbox's PrioritizeEncodingSpeedOverQuality: + * off (the default) codes for quality, on trades some compression + * efficiency for encoding speed. It is read when streaming starts. + */ +#define V4L2_CID_APPLE_AVE_BASE (V4L2_CTRL_CLASS_CODEC | 0x1200) +#define V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED (V4L2_CID_APPLE_AVE_BASE + 0) + /* The firmware build whose command layouts the driver generates */ #define AVE_FW_TEXT_CRC_9003_78_0 0x69c54454 /* The M4 Pro (T6040) build of the same 25G83 firmware. */ @@ -263,6 +273,7 @@ struct ave_params { u32 coded_cap; u32 bit_depth; /* zero also means the existing 8-bit API */ u32 initial_qp; /* CQ only; bit-rate modes use 26 */ + bool speed; /* prioritize encoding speed over quality */ }; struct ave_slot { @@ -346,6 +357,7 @@ struct ave_ctx { u32 hevc_min_qp; u32 hevc_max_qp; bool force_key_frame; + bool prioritize_speed; struct ave_session *sess; atomic_t ready; /* outputs waiting for a CAPTURE buffer */ @@ -434,6 +446,7 @@ struct ave_vb2_mem *ave_vb2_get(struct vb2_buffer *vb); void ave_vb2_put(void *buf_priv); /* ave-sess.c */ +u32 ave_cq_initial_qp(u32 quality); struct ave_session *ave_sess_create(struct ave_ctx *ctx); void ave_sess_destroy(struct ave_ctx *ctx); void ave_sess_reap(struct ave_dev *ave); From f0c38eaae238a5b7f73f0484e474249e5631ceb3 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:59:55 +1100 Subject: [PATCH 060/342] arm64: dts: apple: t6000: enable the ProRes encoder APR a0 now has its v0 descriptor and T6000 match data. Enable APR0 and its DART on T6000 (M1 Pro). Its peripherals node descriptions are kept as they are: the DART binds as apple,t8110-dart. T6001/T6002 stay disabled. Record the J316s result in the qualification notes. Tested on the M1 Pro (J316s, fleet35 + this driver, DT enabled at runtime): engine id 0x10001; NV16/P216/NV24/P416 input, all six profiles at 1080p and Standard/HQ/4444 at 4K; ffmpeg decodes every frame; no DART faults; runtime suspend powers SCODEC off. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 8 ++++++++ .../apple/prores/t6000-qualification.rst | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index f4551b00b25cb..8cafe1065db0e 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -93,3 +93,11 @@ #include "t6000-peripherals.dtsi" #include "t6000-aux-spmi.dtsi" + +&apr0_dart { + status = "okay"; +}; + +&apr0 { + status = "okay"; +}; diff --git a/drivers/media/platform/apple/prores/t6000-qualification.rst b/drivers/media/platform/apple/prores/t6000-qualification.rst index 14c4da6977c68..17a44eb892328 100644 --- a/drivers/media/platform/apple/prores/t6000-qualification.rst +++ b/drivers/media/platform/apple/prores/t6000-qualification.rst @@ -3,9 +3,22 @@ T6000 APR a0 qualification ========================= -This port describes an encoder, not a decoder. The APR and its DART remain -disabled in the shipped DT. Compile and descriptor tests do not qualify -silicon operation, DMA quiescence, output quality or rate control. +This port describes an encoder, not a decoder. T6000 enables APR0 and its +DART in ``t6000.dtsi``; T6001 and T6002 keep theirs disabled. + +Status +------ + +Run on a J316s (M1 Pro) on 2026-11-08 with the shipped node descriptions, +without a performance request. The engine identifies as 0x10001. The +four input formats and all six profiles were encoded at 1920x1080, plus +Standard, HQ and 4444 at 3840x2160. ffmpeg decoded every frame at the +expected size and chroma format. There were no DART faults, and the +engine runtime-suspended with its power domain off afterwards. + +Not yet covered: cancellation, failed-reset retention (#925), system +suspend, rate-control parity with macOS, and the SCODEC performance +request below. Implementation sources ---------------------- From 29a0eaef4d9775b26ca8e9f368137cc0111c2cf2 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:22:41 +0200 Subject: [PATCH 061/342] dt-bindings: arm: apple: Name the J704 MacBook Pro (14-inch, M5, 2025) The J704 entry names the board only by its code. It is the MacBook Pro (14-inch, M5, 2025), as its device tree's model now says. Signed-off-by: Dmitriy Assisted-by: LLM --- Documentation/devicetree/bindings/arm/apple.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/arm/apple.yaml b/Documentation/devicetree/bindings/arm/apple.yaml index f5acf01039a14..691716f025522 100644 --- a/Documentation/devicetree/bindings/arm/apple.yaml +++ b/Documentation/devicetree/bindings/arm/apple.yaml @@ -366,7 +366,7 @@ properties: - description: Apple M5 SoC based platforms items: - enum: - - apple,j704 # MacBook Pro (J704) + - apple,j704 # MacBook Pro (14-inch, M5, 2025) - apple,j813 # MacBook Air (13-inch, M5, 2026) - apple,j815 # MacBook Air (J815) - const: apple,t8142 From 9b776acc0d5044e584505ba0ad57d42351343175 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:33:09 +0200 Subject: [PATCH 062/342] dt-bindings: watchdog: apple,wdt: Add the T8142 watchdog The M5 (T8142) watchdog is the T8103 one, as on the other recent SoCs. The J704 and J813 device trees use apple,t8142-wdt. Signed-off-by: Dmitriy Assisted-by: LLM --- Documentation/devicetree/bindings/watchdog/apple,wdt.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml index d09fb81bd506b..e321ee28733d1 100644 --- a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml @@ -25,6 +25,7 @@ properties: - apple,t8122-wdt - apple,t8132-wdt - apple,t8140-wdt + - apple,t8142-wdt - const: apple,t8103-wdt - items: - enum: From 2f018d8692d5e30280bc10ad83ccbb7e186676fc Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:33:09 +0200 Subject: [PATCH 063/342] dt-bindings: spi: apple,qspi: Add the T8142 QSPI The M5 (T8142) QSPI controller is the T8140 one, as on T6050 and T8152. The J704 and J813 device trees use apple,t8142-qspi. Signed-off-by: Dmitriy Assisted-by: LLM --- Documentation/devicetree/bindings/spi/apple,qspi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/apple,qspi.yaml b/Documentation/devicetree/bindings/spi/apple,qspi.yaml index 2cf6f7286efd3..cf140aaab29bd 100644 --- a/Documentation/devicetree/bindings/spi/apple,qspi.yaml +++ b/Documentation/devicetree/bindings/spi/apple,qspi.yaml @@ -34,6 +34,7 @@ properties: - items: - enum: - apple,t6050-qspi + - apple,t8142-qspi - apple,t8152-qspi - const: apple,t8140-qspi From e5cd689b79d9062bd372f177cc133f1a28f0d6d8 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:33:09 +0200 Subject: [PATCH 064/342] dt-bindings: soc: apple: apple,pmp: Add the T8142 PMP The M5 (T8142) PMP takes the T8140 firmware interface, so it falls back to apple,t8140-pmp-v2. The J704 and J813 device trees use that pair. Signed-off-by: Dmitriy Assisted-by: LLM --- Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml index 927dd53f8909e..bcbd0ecf4568a 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml @@ -32,6 +32,9 @@ properties: - apple,t8132-pmp-v2 - apple,t8140-pmp-v2 - const: apple,t6000-pmp-v2 + - items: + - const: apple,t8142-pmp-v2 + - const: apple,t8140-pmp-v2 - items: - const: apple,t8103-pmp - const: apple,pmp From d84beb5d225310b050d70aee8782ce9dc882d3a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:33:09 +0200 Subject: [PATCH 065/342] dt-bindings: display: apple,display-subsystem: Add T8142 The M5 (T8142) display subsystem takes the same description as the T8140 one. The J704 and J813 device trees use apple,t8142-display-subsystem with apple,display-subsystem. Signed-off-by: Dmitriy Assisted-by: LLM --- .../devicetree/bindings/display/apple,display-subsystem.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml index 0d3e74d6a804c..be4e56cb2a39f 100644 --- a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml +++ b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml @@ -23,7 +23,9 @@ properties: - const: apple,t8132-display-diagnostics deprecated: true - items: - - const: apple,t8140-display-subsystem + - enum: + - apple,t8140-display-subsystem + - apple,t8142-display-subsystem - const: apple,display-subsystem - items: - const: apple,t8132-display-subsystem From 8e90594cb08c59d2a0ae9273838536b3cd77f18d Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:33:10 +0200 Subject: [PATCH 066/342] arm64: dts: apple: t8142: Name the MTP DART's address filter region The MTP DART's second register region is its DAPF (ADT dart-mtp instance DAPF). The DART binding requires reg-names once a second region is listed. Signed-off-by: Dmitriy Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8142.dtsi | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/boot/dts/apple/t8142.dtsi b/arch/arm64/boot/dts/apple/t8142.dtsi index 9bf8a297f31be..13cae26f21d96 100644 --- a/arch/arm64/boot/dts/apple/t8142.dtsi +++ b/arch/arm64/boot/dts/apple/t8142.dtsi @@ -213,6 +213,7 @@ compatible = "apple,t8142-dart", "apple,t8110-dart"; reg = <0x3 0x94800000 0x0 0xc000>, <0x3 0x94810000 0x0 0x4000>; + reg-names = "dart", "dapf"; interrupts = ; #iommu-cells = <1>; status = "disabled"; From 862f207fa078d99b2d499457a477ff5afe010b44 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:23:01 +0200 Subject: [PATCH 067/342] arm64: dts: apple: t8142-j704: Enable the MacBook Pro (14-inch, M5) The J704 board file includes the disabled T8142 inventory. Enable what runs on this machine and describe the board's own devices from its Apple Device Tree: - The ten CPUs with cpufreq and the PMC voters: E-cluster states up to 3048 MHz and P-cluster states up to 4608 MHz. - AIC, the timer, the Samsung UART as the console (serial0, 115200 baud) and the dockchannel UART (serial1). - PMGR power domains, the PMP and the SMC: battery, AC, fan and temperatures, the power button and lid, reboot and the RTC through the PMU's rtc_scrpad offset. - The keyboard and trackpad on the MTP, with the trackpad firmware name and the keyboard backlight at half brightness. - The three Type-C ports: ATC0 and ATC1 on nub SPMI A0, ATC3 on nub SPMI A1. ATC2 drives the HDMI port and is left out. - The AVD video decoder. - The internal DCP and the 14.2" mini-LED panel, disabled: the loader enables them for a display session it hands over. On macOS 27.0 firmware the panel stays on the boot framebuffer until the DCP driver runs that firmware. The inventory's DARTs are used through their labels. Each USB DART node lists both of its instances in reg; the board keeps instance 0 there and adds instance 1 as its own node, as on the J813. Signed-off-by: Dmitriy Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8142-j704-avd.dtsi | 42 ++ .../boot/dts/apple/t8142-j704-display.dtsi | 102 ++++ .../boot/dts/apple/t8142-j704-hwmon.dtsi | 174 +++++++ .../dts/apple/t8142-j704-peripherals.dtsi | 264 ++++++++++ .../boot/dts/apple/t8142-j704-power.dtsi | 83 +++ arch/arm64/boot/dts/apple/t8142-j704-usb.dtsi | 488 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8142-j704.dts | 312 ++++++++++- 7 files changed, 1464 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-avd.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-display.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-hwmon.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-peripherals.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-power.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-usb.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j704-avd.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-avd.dtsi new file mode 100644 index 0000000000000..0d807f3712162 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-avd.dtsi @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * M5 (T8142) AVD video decoder: a "Hibiscus" AVD (macOS CAvdMcpuHibiscus, + * avd-version 4, tunables = avd-fw v5 tier 2). The J704 ADT has it where the + * J813 does: avd reg[0] 0x2f0000000 + 0x1404000, here at the arm-io offset + * 0x500000000; 0x14000 each of CM3 code and SRAM, mailbox at +0x10a8000 + * (CAvdApCommHibiscus); IRQs 1077/1078; dart-avd at +0x1020000, IRQ 1084, + * SIDs 0-2; power: PMGR device AVD-SYS-V -> AVD_SYS (+0x310). + */ + +&pmgr { + ps_avd_sys: power-controller@310 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x310 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "avd_sys"; + }; +}; + +&{/soc} { + avd: avd@501080000 { + compatible = "apple,t8142-avd"; + interrupt-parent = <&aic>; + interrupts = , + ; + power-domains = <&ps_avd_sys>; + resets = <&ps_avd_sys>; + reg = <0x5 0x01080000 0x0 0x14000>, + <0x5 0x01094000 0x0 0x14000>, + <0x5 0x010a8000 0x0 0x4000>, + <0x5 0x01100000 0x0 0x10000>; + reg-names = "code", "sram", "mbox", "ctrl"; + iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>; + }; + +}; + +&avd_dart { + power-domains = <&ps_avd_sys>; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-display.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-display.dtsi new file mode 100644 index 0000000000000..fa807294542e2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-display.dtsi @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J704 internal display pipeline: the DCP coprocessor and its DARTs. + * + * The bootloader leaves DCP running with its firmware mapped through + * locked DART tables. The loader reserves those mappings and enables the + * nodes below; Linux attaches to the running coprocessor without resetting + * it. Resources were read from this machine's Apple Device Tree. + */ + +/ { + aliases { + dcp = &dcp; + disp0 = &display; + disp0_piodma = &disp0_piodma; + }; + + display: display-subsystem { + compatible = "apple,t8142-display-subsystem", "apple,display-subsystem"; + /* disp0_dart must be first since it is locked */ + iommus = <&disp0_dart 0>; + /* generate phandle explicitly for use in loader */ + phandle = <&display>; + }; +}; + +&{/soc} { + pmgr_dcp: power-management@382720000 { + reg = <3 0x82720000 0 0x8>, <3 0x827a4000 0 0x4>; + reg-names = "dcp-bw-scratch", "dcp-bw-doorbell"; + #apple,bw-scratch-cells = <3>; + #apple,bw-doorbell-cells = <2>; + }; + + dcp_mbox: mailbox@286e08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <2 0x86e08000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + dcp: dcp@286e00000 { + compatible = "apple,t8142-dcp", "apple,dcp"; + mboxes = <&dcp_mbox>; + mbox-names = "mbox"; + iommus = <&dcp_dart 23>; + reg-names = "coproc", "disp-0", "disp-1", "disp-2", + "disp-3", "disp-4", "iop-vbar"; + reg = <2 0x86e00000 0 0x4000>, + <2 0x84000000 0 0xb1c000>, + <2 0x86240000 0 0x10000>, + <2 0x863ac000 0 0x4000>, + <2 0x86800000 0 0x800000>, + <3 0x82700000 0 0x114000>, + <2 0x86850000 0 0x4000>; + apple,bw-scratch = <&pmgr_dcp 0 5 0>; + apple,bw-doorbell = <&pmgr_dcp 1 6>; + /* Scan out the primary plane on IOMFB surface 2. */ + apple,iomfb-surfaces = <0 0 1 0>; + clocks = <&clkref>; + /* generate phandle explicitly for use in loader */ + phandle = <&dcp>; + status = "disabled"; + /* required bus properties for 'piodma' subdevice */ + #address-cells = <2>; + #size-cells = <2>; + + disp0_piodma: piodma { + iommus = <&disp0_dart 16>; + phandle = <&disp0_piodma>; + }; + + /* + * 14.2" mini-LED, 3024x1964 (1890 below the notch, which the + * loader passes as apple,notch-height). Makes the connector eDP + * and gives the DCP a backlight to drive. + */ + panel: panel { + compatible = "apple,panel-j704", "apple,panel-mini-led", + "apple,panel"; + width-mm = <302>; + height-mm = <196>; + adj-height-mm = <189>; + apple,max-brightness = <600>; + }; + }; +}; + +&disp0_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; + status = "disabled"; +}; + +&dcp_dart { + apple,dma-range = <0x100 0x0 0x10 0x0>; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-hwmon.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-hwmon.dtsi new file mode 100644 index 0000000000000..be16e2982ba45 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-hwmon.dtsi @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * SMC sensors and the fan of the MacBook Pro (14-inch, M5, 2025), J704. + */ + +#include "hwmon-common.dtsi" +#include "hwmon-laptop.dtsi" +#include "hwmon-fan.dtsi" + +&smc_hwmon { + /* + * CPU sensors respond to loads pinned to each cluster. The GPU keys + * follow the M5 macOS sensor group; numbers identify sensors, not cores. + * The hottest of these die readings supplies the driver's SoC zone. + */ + apple,soc-die-keys = "Te04", "Te08", "Te0C", "Te0R", + "Tp00", "Tp04", "Tp0C", "Tp0G", "Tp0O", + "Tp0R", "Tp0X", "Tp0a", "Tp0p", "Tp0u", + "Tp0y", "Tp12", "Tp16", "Tp1E", + "Tg0U", "Tg0X", "Tg0d", "Tg0g", "Tg0j", + "Tg1Y", "Tg1c", "Tg1g"; + apple,thermal-pressure-key = "mTPL"; + + fan-F0Ac { + /* This SMC names the fan mode key in lower case. */ + apple,fan-mode = "F0md"; + apple,fan-manual-control; + }; + + temperature-Te04 { + apple,key-id = "Te04"; + label = "CPU E-cluster Temperature 1"; + }; + + temperature-Te08 { + apple,key-id = "Te08"; + label = "CPU E-cluster Temperature 2"; + }; + + temperature-Te0C { + apple,key-id = "Te0C"; + label = "CPU E-cluster Temperature 3"; + }; + + temperature-Te0R { + apple,key-id = "Te0R"; + label = "CPU E-cluster Temperature 4"; + }; + + temperature-Tp00 { + apple,key-id = "Tp00"; + label = "CPU P-cluster Temperature 1"; + }; + + temperature-Tp04 { + apple,key-id = "Tp04"; + label = "CPU P-cluster Temperature 2"; + }; + + temperature-Tp0C { + apple,key-id = "Tp0C"; + label = "CPU P-cluster Temperature 3"; + }; + + temperature-Tp0G { + apple,key-id = "Tp0G"; + label = "CPU P-cluster Temperature 4"; + }; + + temperature-Tp0O { + apple,key-id = "Tp0O"; + label = "CPU P-cluster Temperature 5"; + }; + + temperature-Tp0R { + apple,key-id = "Tp0R"; + label = "CPU P-cluster Temperature 6"; + }; + + temperature-Tp0X { + apple,key-id = "Tp0X"; + label = "CPU P-cluster Temperature 7"; + }; + + temperature-Tp0a { + apple,key-id = "Tp0a"; + label = "CPU P-cluster Temperature 8"; + }; + + temperature-Tp0p { + apple,key-id = "Tp0p"; + label = "CPU P-cluster Temperature 9"; + }; + + temperature-Tp0u { + apple,key-id = "Tp0u"; + label = "CPU P-cluster Temperature 10"; + }; + + temperature-Tp0y { + apple,key-id = "Tp0y"; + label = "CPU P-cluster Temperature 11"; + }; + + temperature-Tp12 { + apple,key-id = "Tp12"; + label = "CPU P-cluster Temperature 12"; + }; + + temperature-Tp16 { + apple,key-id = "Tp16"; + label = "CPU P-cluster Temperature 13"; + }; + + temperature-Tp1E { + apple,key-id = "Tp1E"; + label = "CPU P-cluster Temperature 14"; + }; + + temperature-Tg0U { + apple,key-id = "Tg0U"; + label = "GPU Temperature 1"; + }; + + temperature-Tg0X { + apple,key-id = "Tg0X"; + label = "GPU Temperature 2"; + }; + + temperature-Tg0d { + apple,key-id = "Tg0d"; + label = "GPU Temperature 3"; + }; + + temperature-Tg0g { + apple,key-id = "Tg0g"; + label = "GPU Temperature 4"; + }; + + temperature-Tg0j { + apple,key-id = "Tg0j"; + label = "GPU Temperature 5"; + }; + + temperature-Tg1Y { + apple,key-id = "Tg1Y"; + label = "GPU Temperature 6"; + }; + + temperature-Tg1c { + apple,key-id = "Tg1c"; + label = "GPU Temperature 7"; + }; + + temperature-Tg1g { + apple,key-id = "Tg1g"; + label = "GPU Temperature 8"; + }; + + temperature-TB1T { + apple,key-id = "TB1T"; + label = "Battery Temperature 1"; + }; + + temperature-TB2T { + apple,key-id = "TB2T"; + label = "Battery Temperature 2"; + }; + + temperature-TAOL { + apple,key-id = "TAOL"; + label = "Ambient (TAOL)"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-peripherals.dtsi new file mode 100644 index 0000000000000..d962ab3291e03 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-peripherals.dtsi @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +#include +#include + +/ { + aliases { + mtp = &mtp; + keyboard = &keyboard; + nvram = &nvram; + pmp = &pmp; + }; + + /* ADT /arm-io/qspi clock-ids [396]; rate as the T8140 QSPI. */ + clk_qspi: clock-qspi { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + clock-output-names = "clk_qspi"; + }; + + led-controller { + compatible = "pwm-leds"; + + led-0 { + pwms = <&fpwm0 0 40000>; + label = "kbd_backlight"; + function = LED_FUNCTION_KBD_BACKLIGHT; + color = ; + max-brightness = <255>; + default-brightness = <127>; + default-state = "on"; + }; + }; +}; + +&pmgr { + ps_fpwm0: power-controller@330 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x330 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fpwm0"; + }; + + /* ADT pmgr devices: SPI_P id 94 (+0x390), QSPI id 120 (+0x460). */ + ps_spi_p: power-controller@390 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x390 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi_p"; + }; + + /* ADT pmgr devices: PMP id 159 (+0x598), PMS_SRAM id 160 (+0x5a0). */ + ps_pmp: power-controller@598 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x598 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pmp"; + /* The PMP's SRAM, which the driver reads first. */ + power-domains = <&ps_pms_sram>; + }; + + ps_pms_sram: power-controller@5a0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_sram"; + /* T8140 holds it through its always-on PMP report node. */ + apple,always-on; + }; + + ps_qspi: power-controller@460 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x460 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "qspi"; + power-domains = <&ps_spi_p>; + }; +}; + +&{/soc} { + /* + * PMP, laid out as on T8140 (ADT /arm-io/pmp, dart-pmp): it runs the + * DRAM controller (DCS) and fabric DVFS. Without it the memory stays at + * the bootloader's state (memcpy ~20 GB/s against ~120 GB/s on macOS). + */ + pmp: pmp@380500000 { + compatible = "apple,t8142-pmp-v2", "apple,t8140-pmp-v2"; + reg = <0x3 0x80500000 0x0 0xd0000>, + <0x3 0x80e00000 0x0 0x4000>; + reg-names = "pmp", "asc"; + mboxes = <&pmp_mbox>; + mbox-names = "mbox"; + iommus = <&pmp_dart 0>; + power-domains = <&ps_pmp>; + /* + * ADT /arm-io/pmgr pmc, pmc-pmgr (registry-v2 boot arguments). + * The loader adds apple,board-id, apple,dram-vendor-id and the + * apple,tunable-* values from this machine's ADT. + */ + apple,pmc = <1>; + apple,pmc-pmgr = <31>; + }; + + pmp_mbox: mailbox@380e08000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x80e08000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + power-domains = <&ps_pmp>; + }; + + /* ADT /arm-io/qspi: 0x195118000 and its FIFO window at +0x800, IRQ 1245. */ + qspi: spi@3a5118000 { + compatible = "apple,t8142-qspi", "apple,t8140-qspi"; + reg = <0x3 0xa5118000 0x0 0x4800>; + clocks = <&clk_qspi>; + interrupt-parent = <&aic>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + power-domains = <&ps_qspi>; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + /* Conservative until the input clock is confirmed. */ + spi-max-frequency = <10000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* ADT spinor/anvram reg: 0x100000 bytes at 0x700000. */ + nvram: partition@700000 { + label = "nvram"; + reg = <0x700000 0x100000>; + }; + }; + }; + }; + + fpwm0: pwm@3a5040000 { + compatible = "apple,t8142-fpwm", "apple,s5l-fpwm"; + reg = <3 0xa5040000 0 0x4000>; + power-domains = <&ps_fpwm0>; + clocks = <&clkref>; + #pwm-cells = <2>; + }; + + smc_mbox: mailbox@38c608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0x8c608000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + smc: smc@38c600000 { + compatible = "apple,t8142-smc", "apple,t8103-smc"; + reg = <3 0x8c600000 0 0x4000>, <3 0x8de00000 0 0x120000>; + reg-names = "smc", "sram"; + mboxes = <&smc_mbox>; + + smc_hwmon: hwmon { + compatible = "apple,smc-hwmon"; + }; + + smc_gpio: gpio { + compatible = "apple,smc-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + }; + + mtp: mtp@394600000 { + compatible = "apple,t8142-mtp", "apple,t8142-rtk-helper-asc4", + "apple,mtp", "apple,rtk-helper-asc4"; + /* The second region is firmware SRAM, not the ASC control window. */ + reg = <3 0x94600000 0 0x4000>, <3 0x94c00000 0 0x100000>; + reg-names = "asc", "sram"; + mboxes = <&mtp_mbox>; + iommus = <&mtp_dart 0>; + }; + + mtp_mbox: mailbox@394608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0x94608000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + mtp_dockchannel: fifo@394b14000 { + compatible = "apple,t8142-dockchannel", "apple,dockchannel"; + reg = <3 0x94b14000 0 0x1000>; + reg-names = "irq"; + interrupts = ; + ranges = <0 3 0x94b28000 0x20000>; + nonposted-mmio; + #address-cells = <1>; + #size-cells = <1>; + interrupt-controller; + #interrupt-cells = <2>; + + mtp_hid: input@8000 { + compatible = "apple,dockchannel-hid"; + reg = <0x8000 0x1000>, <0xc000 0x1000>, + <0x0000 0x1000>, <0x4000 0x1000>; + reg-names = "config", "data", "rmt-config", "rmt-data"; + iommus = <&mtp_dart 0>; + interrupt-parent = <&mtp_dockchannel>; + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>, <3 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "tx", "rx"; + apple,fifo-size = <0x800>; + apple,helper-cpu = <&mtp>; + /* + * ADT dockchannel-mtp/mtp-transport/multi-touch: + * function-afe-reset = smc-pmu pKW4('gP1c'), SMC GPIO 28, + * as on J813. + */ + apple,afe-reset-gpios = <&smc_gpio 28 GPIO_ACTIVE_LOW>; + + stm { }; + + multi-touch { + firmware-name = "apple/tpmtfw-j704.bin"; + apple,power-method = <2>; + }; + + /* Layout is filled by the loader using this machine's own data. */ + keyboard: keyboard { }; + }; + }; +}; + +&pmp_dart { + apple,dma-range = /bits/ 64 <0x10000000000 0xbff00000>; + power-domains = <&ps_pmp>; + status = "okay"; +}; + +&mtp_dart { + /* Keep host allocations clear of firmware's low IOVA mappings. */ + apple,dma-range = <0 0x02000000 0 0x10000000>; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-power.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-power.dtsi new file mode 100644 index 0000000000000..6011d77695aa3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-power.dtsi @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple MacBook Pro (14-inch, M5) J704: SMC power off / restart, the RTC, the + * PMU on SPMI and the watchdog. + */ + +&{/soc} { + /* ADT /arm-io/wdt (wdt,t8142): restart (and the SMC's fallback). */ + wdt: watchdog@3882b0000 { + compatible = "apple,t8142-wdt", "apple,t8103-wdt"; + reg = <0x3 0x882b0000 0x0 0x4000>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + }; +}; + +&{/soc} { + /* + * ADT /arm-io/nub-spmi0 (gen 4) and its primary PMU, pmu-main + * ("abbey", slave 0xe). The boot flags live in the legacy scratchpad + * (info-leg_scrpad = 0xf800), laid out as on T8103 and J873. + */ + nub_spmi0: spmi@388714000 { + compatible = "apple,t8142-spmi"; + reg = <0x3 0x88714000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + + pmic@e { + compatible = "apple,abbey-pmic", "apple,spmi-nvmem"; + reg = <0xe SPMI_USID>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + /* ADT info-rtc_scrpad: 48-bit offset in 32768 Hz ticks. */ + rtc_offset: rtc-offset@2100 { + reg = <0x2100 0x6>; + }; + + boot_stage: boot-stage@f801 { + reg = <0xf801 0x1>; + }; + + boot_error_count: boot-error-count@f802,0 { + reg = <0xf802 0x1>; + bits = <0 4>; + }; + + panic_count: panic-count@f802,4 { + reg = <0xf802 0x1>; + bits = <4 4>; + }; + + /* Set before off1, or the machine powers back on. */ + shutdown_flag: shutdown-flag@f80f,3 { + reg = <0xf80f 0x1>; + bits = <3 1>; + }; + }; + }; + }; +}; + +&smc { + /* Power off (MBSE = off1) and restart (MBSE = phra). */ + reboot { + compatible = "apple,smc-reboot"; + nvmem-cells = <&shutdown_flag>, <&boot_stage>, + <&boot_error_count>, <&panic_count>; + nvmem-cell-names = "shutdown_flag", "boot_stage", + "boot_error_count", "panic_count"; + }; + + rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-usb.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-usb.dtsi new file mode 100644 index 0000000000000..09c51e0888aa2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-usb.dtsi @@ -0,0 +1,488 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +#include +#include + +/* + * Type-C ports: left-front (ATC0) and left-rear (ATC1) on nub SPMI A0, + * right (ATC3) on nub SPMI A1. ATC2 has no connector: it drives the HDMI + * port through a DisplayPort to HDMI converter. + */ + +/ { + aliases { + atcphy0 = &atcphy0; + usb0 = &dwc3_0; + atcphy1 = &atcphy1; + usb1 = &dwc3_1; + atcphy3 = &atcphy3; + usb3 = &dwc3_3; + }; +}; + +&pmgr { + ps_atc0_common: power-controller@2c8 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0-common"; + }; +}; + +&{/soc} { + pmgr_nub: power-management@388280000 { + compatible = "apple,t8142-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <3 0x88280000 0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + + ps_nub_spmi_a0: power-controller@70 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x70 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub-spmi-a0"; + }; + + ps_atc0_usb_aon: power-controller@c8 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0-usb-aon"; + }; + + ps_atc0_usb: power-controller@d0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xd0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc0_common>, <&ps_atc0_usb_aon>; + label = "atc0-usb"; + }; + }; + + nub_spmi_a0: spmi@388908000 { + compatible = "apple,t8142-spmi"; + reg = <3 0x88908000 0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + power-domains = <&ps_nub_spmi_a0>; + + hpm0: usb-pd@c { + compatible = "apple,sn201202x"; + reg = <0xc SPMI_USID>; + + typec0: connector { + compatible = "usb-c-connector"; + label = "USB-C Left-front"; + power-role = "dual"; + data-role = "host"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + typec0_hs: endpoint { + remote-endpoint = <&dwc3_0_hs>; + }; + }; + + port@1 { + reg = <1>; + typec0_ss: endpoint { + remote-endpoint = <&atcphy0_typec>; + }; + }; + }; + }; + }; + }; + + dwc3_0: usb@402280000 { + compatible = "apple,t8142-dwc3", "apple,t8103-dwc3"; + reg = <4 0x02280000 0 0xcd00>, <4 0x0228cd00 0 0x4b00>; + reg-names = "dwc3-core", "dwc3-apple"; + interrupts = ; + dr_mode = "host"; + usb-role-switch; + role-switch-default-mode = "host"; + iommus = <&dwc3_0_dart 0>, <&dwc3_0_dart_1 1>; + power-domains = <&ps_atc0_usb>; + resets = <&atcphy0>; + phys = <&atcphy0 PHY_TYPE_USB2>, <&atcphy0 PHY_TYPE_USB3>; + phy-names = "usb2-phy", "usb3-phy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + dwc3_0_hs: endpoint { + remote-endpoint = <&typec0_hs>; + }; + }; + port@1 { + reg = <1>; + dwc3_0_ss: endpoint { + remote-endpoint = <&atcphy0_usb>; + }; + }; + }; + }; + + dwc3_0_dart_1: iommu@402f80000 { + compatible = "apple,t8142-dart", "apple,t8110-dart"; + reg = <4 0x02f80000 0 0xc000>; + interrupts = ; + power-domains = <&ps_atc0_usb>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + }; + + atcphy0: phy@403000000 { + compatible = "apple,t8142-atcphy"; + reg = <4 0x03000000 0 0x4c000>, + <4 0x03050000 0 0x8000>, + <4 0x00000000 0 0x8000>, + <4 0x02a90000 0 0x4000>, + <4 0x02a84000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler"; + #phy-cells = <1>; + #reset-cells = <0>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc0_usb>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + atcphy0_typec: endpoint { + remote-endpoint = <&typec0_ss>; + }; + }; + port@1 { + reg = <1>; + atcphy0_usb: endpoint { + remote-endpoint = <&dwc3_0_ss>; + }; + }; + }; + }; +}; + +&pmgr { + ps_atc1_common: power-controller@2d0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1-common"; + }; +}; + +&pmgr_nub { + ps_atc1_usb_aon: power-controller@d8 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xd8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1-usb-aon"; + }; + + ps_atc1_usb: power-controller@e0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xe0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc1_common>, <&ps_atc1_usb_aon>; + label = "atc1-usb"; + }; +}; + +&nub_spmi_a0 { + hpm1: usb-pd@a { + compatible = "apple,sn201202x"; + reg = <0xa SPMI_USID>; + + typec1: connector { + compatible = "usb-c-connector"; + label = "USB-C Left-rear"; + power-role = "dual"; + data-role = "host"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + typec1_hs: endpoint { + remote-endpoint = <&dwc3_1_hs>; + }; + }; + + port@1 { + reg = <1>; + typec1_ss: endpoint { + remote-endpoint = <&atcphy1_typec>; + }; + }; + }; + }; + }; +}; + +&{/soc} { + dwc3_1: usb@40a280000 { + compatible = "apple,t8142-dwc3", "apple,t8103-dwc3"; + reg = <4 0x0a280000 0 0xcd00>, <4 0x0a28cd00 0 0x4b00>; + reg-names = "dwc3-core", "dwc3-apple"; + interrupts = ; + dr_mode = "host"; + usb-role-switch; + role-switch-default-mode = "host"; + iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; + power-domains = <&ps_atc1_usb>; + resets = <&atcphy1>; + phys = <&atcphy1 PHY_TYPE_USB2>, <&atcphy1 PHY_TYPE_USB3>; + phy-names = "usb2-phy", "usb3-phy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + dwc3_1_hs: endpoint { + remote-endpoint = <&typec1_hs>; + }; + }; + port@1 { + reg = <1>; + dwc3_1_ss: endpoint { + remote-endpoint = <&atcphy1_usb>; + }; + }; + }; + }; + + dwc3_1_dart_1: iommu@40af80000 { + compatible = "apple,t8142-dart", "apple,t8110-dart"; + reg = <4 0x0af80000 0 0xc000>; + interrupts = ; + power-domains = <&ps_atc1_usb>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + }; + + atcphy1: phy@40b000000 { + compatible = "apple,t8142-atcphy"; + reg = <4 0x0b000000 0 0x4c000>, + <4 0x0b050000 0 0x8000>, + <4 0x08000000 0 0x8000>, + <4 0x0aa90000 0 0x4000>, + <4 0x0aa84000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler"; + #phy-cells = <1>; + #reset-cells = <0>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc1_usb>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + atcphy1_typec: endpoint { + remote-endpoint = <&typec1_ss>; + }; + }; + port@1 { + reg = <1>; + atcphy1_usb: endpoint { + remote-endpoint = <&dwc3_1_ss>; + }; + }; + }; + }; +}; + +&pmgr { + ps_atc3_common: power-controller@2e0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3-common"; + }; +}; + +&pmgr_nub { + ps_nub_spmi_a1: power-controller@78 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x78 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub-spmi-a1"; + }; + + ps_atc3_usb_aon: power-controller@f8 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xf8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3-usb-aon"; + }; + + ps_atc3_usb: power-controller@100 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc3_common>, <&ps_atc3_usb_aon>; + label = "atc3-usb"; + }; +}; + +&{/soc} { + nub_spmi_a1: spmi@388a08000 { + compatible = "apple,t8142-spmi"; + reg = <3 0x88a08000 0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + power-domains = <&ps_nub_spmi_a1>; + + hpm3: usb-pd@c { + compatible = "apple,sn201202x"; + reg = <0xc SPMI_USID>; + + typec3: connector { + compatible = "usb-c-connector"; + label = "USB-C Right"; + power-role = "dual"; + data-role = "host"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + typec3_hs: endpoint { + remote-endpoint = <&dwc3_3_hs>; + }; + }; + + port@1 { + reg = <1>; + typec3_ss: endpoint { + remote-endpoint = <&atcphy3_typec>; + }; + }; + }; + }; + }; + }; + + dwc3_3: usb@41a280000 { + compatible = "apple,t8142-dwc3", "apple,t8103-dwc3"; + reg = <4 0x1a280000 0 0xcd00>, <4 0x1a28cd00 0 0x4b00>; + reg-names = "dwc3-core", "dwc3-apple"; + interrupts = ; + dr_mode = "host"; + usb-role-switch; + role-switch-default-mode = "host"; + iommus = <&dwc3_3_dart 0>, <&dwc3_3_dart_1 1>; + power-domains = <&ps_atc3_usb>; + resets = <&atcphy3>; + phys = <&atcphy3 PHY_TYPE_USB2>, <&atcphy3 PHY_TYPE_USB3>; + phy-names = "usb2-phy", "usb3-phy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + dwc3_3_hs: endpoint { + remote-endpoint = <&typec3_hs>; + }; + }; + port@1 { + reg = <1>; + dwc3_3_ss: endpoint { + remote-endpoint = <&atcphy3_usb>; + }; + }; + }; + }; + + dwc3_3_dart_1: iommu@41af80000 { + compatible = "apple,t8142-dart", "apple,t8110-dart"; + reg = <4 0x1af80000 0 0xc000>; + interrupts = ; + power-domains = <&ps_atc3_usb>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + }; + + atcphy3: phy@41b000000 { + compatible = "apple,t8142-atcphy"; + reg = <4 0x1b000000 0 0x4c000>, + <4 0x1b050000 0 0x8000>, + <4 0x18000000 0 0x8000>, + <4 0x1aa90000 0 0x4000>, + <4 0x1aa84000 0 0x4000>; + reg-names = "core", "lpdptx", "axi2af", "usb2phy", "pipehandler"; + #phy-cells = <1>; + #reset-cells = <0>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc3_usb>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + atcphy3_typec: endpoint { + remote-endpoint = <&typec3_ss>; + }; + }; + port@1 { + reg = <1>; + atcphy3_usb: endpoint { + remote-endpoint = <&dwc3_3_ss>; + }; + }; + }; + }; +}; + +&dwc3_0_dart { + /* Instance 0 only: instance 1 is dwc3_0_dart_1. */ + reg = <4 0x02f00000 0 0xc000>; + power-domains = <&ps_atc0_usb>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + status = "okay"; +}; + +&dwc3_1_dart { + /* Instance 0 only: instance 1 is dwc3_1_dart_1. */ + reg = <4 0x0af00000 0 0xc000>; + power-domains = <&ps_atc1_usb>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + status = "okay"; +}; + +&dwc3_3_dart { + /* Instance 0 only: instance 1 is dwc3_3_dart_1. */ + reg = <4 0x1af00000 0 0xc000>; + power-domains = <&ps_atc3_usb>; + apple,dma-range = <0x100 0x4000 0 0xffff0000>; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704.dts b/arch/arm64/boot/dts/apple/t8142-j704.dts index d3a9329dc59ec..b6ce8a4dc5556 100644 --- a/arch/arm64/boot/dts/apple/t8142-j704.dts +++ b/arch/arm64/boot/dts/apple/t8142-j704.dts @@ -1,10 +1,320 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple MacBook Pro (14-inch, M5, 2025), J704. + * + * Resources from the J704 Apple Device Tree. The loader supplies usable + * memory, CPU release addresses and framebuffer geometry. + */ /dts-v1/; #include "t8142.dtsi" / { - model = "Apple MacBook Pro (J704)"; compatible = "apple,j704", "apple,t8142", "apple,arm-platform"; + model = "Apple MacBook Pro (14-inch, M5, 2025)"; chassis-type = "laptop"; + + aliases { + serial0 = &serial0; + serial1 = &dockchannel; + }; + + chosen { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + stdout-path = "serial0:115200n8"; + + framebuffer0: framebuffer@0 { + compatible = "apple,simple-framebuffer", "simple-framebuffer"; + reg = <0 0 0 0>; /* Filled by the loader. */ + status = "disabled"; + }; + }; + + /* + * State 1 is 300 MHz; the ADT voltage-states1-sram (E) and + * voltage-states5-sram (P) tables begin at state 2. + */ + ecluster_opp: opp-table-0 { + compatible = "operating-points-v2"; + opp-shared; + + opp-300000000 { + opp-hz = /bits/ 64 <300000000>; + opp-level = <1>; + }; + + opp-972000000 { + opp-hz = /bits/ 64 <972000000>; + opp-level = <2>; + }; + + opp-1152000000 { + opp-hz = /bits/ 64 <1152000000>; + opp-level = <3>; + }; + + opp-1584000000 { + opp-hz = /bits/ 64 <1584000000>; + opp-level = <4>; + }; + + opp-1992000000 { + opp-hz = /bits/ 64 <1992000000>; + opp-level = <5>; + }; + + opp-2352000000 { + opp-hz = /bits/ 64 <2352000000>; + opp-level = <6>; + }; + + opp-2700000000 { + opp-hz = /bits/ 64 <2700000000>; + opp-level = <7>; + }; + + opp-2964000000 { + opp-hz = /bits/ 64 <2964000000>; + opp-level = <8>; + }; + + opp-3048000000 { + opp-hz = /bits/ 64 <3048000000>; + opp-level = <9>; + }; + }; + + pcluster_opp: opp-table-1 { + compatible = "operating-points-v2"; + opp-shared; + + opp-300000000 { + opp-hz = /bits/ 64 <300000000>; + opp-level = <1>; + }; + + opp-1308000000 { + opp-hz = /bits/ 64 <1308000000>; + opp-level = <2>; + }; + + opp-1608000000 { + opp-hz = /bits/ 64 <1608000000>; + opp-level = <3>; + }; + + opp-1932000000 { + opp-hz = /bits/ 64 <1932000000>; + opp-level = <4>; + }; + + opp-2220000000 { + opp-hz = /bits/ 64 <2220000000>; + opp-level = <5>; + }; + + opp-2508000000 { + opp-hz = /bits/ 64 <2508000000>; + opp-level = <6>; + }; + + opp-2820000000 { + opp-hz = /bits/ 64 <2820000000>; + opp-level = <7>; + }; + + opp-3072000000 { + opp-hz = /bits/ 64 <3072000000>; + opp-level = <8>; + }; + + opp-3300000000 { + opp-hz = /bits/ 64 <3300000000>; + opp-level = <9>; + }; + + opp-3516000000 { + opp-hz = /bits/ 64 <3516000000>; + opp-level = <10>; + }; + + /* The SoC throttles levels 11 and up when hot. */ + opp-3720000000 { + opp-hz = /bits/ 64 <3720000000>; + opp-level = <11>; + }; + + opp-3876000000 { + opp-hz = /bits/ 64 <3876000000>; + opp-level = <12>; + }; + + opp-4020000000 { + opp-hz = /bits/ 64 <4020000000>; + opp-level = <13>; + }; + + opp-4176000000 { + opp-hz = /bits/ 64 <4176000000>; + opp-level = <14>; + }; + + opp-4248000000 { + opp-hz = /bits/ 64 <4248000000>; + opp-level = <15>; + }; + + opp-4272000000 { + opp-hz = /bits/ 64 <4272000000>; + opp-level = <16>; + }; + + opp-4332000000 { + opp-hz = /bits/ 64 <4332000000>; + opp-level = <17>; + }; + + opp-4428000000 { + opp-hz = /bits/ 64 <4428000000>; + opp-level = <18>; + }; + + opp-4512000000 { + opp-hz = /bits/ 64 <4512000000>; + opp-level = <19>; + }; + + opp-4608000000 { + opp-hz = /bits/ 64 <4608000000>; + opp-level = <20>; + }; + }; }; + +&{/soc} { + cpufreq_e: performance-controller@210e20000 { + compatible = "apple,t8142-cluster-cpufreq"; + reg = <0x2 0x10e20000 0 0x1000>; + #performance-domain-cells = <0>; + }; + + cpufreq_p: performance-controller@211e20000 { + compatible = "apple,t8142-cluster-cpufreq"; + reg = <0x2 0x11e20000 0 0x1000>; + #performance-domain-cells = <0>; + }; + + /* + * PMC voter interface (AppleT8142PMC, ADT pmc-pmgr 31 + 0x700000): + * floors at 0x382700000 + agent * 0x4000, per-agent states at + * +0x106000, rail enables at +0x108000. Agents (ADT voter-agent): + * PMP 0, CLPC 1, GFX 2, AP 3. iBoot leaves every enable at 0, so + * no vote is honoured and DRAM and fabric stay at their lowest + * states (CPU DRAM latency 171 ns instead of 70 ns). + */ + pmc: power-management@382700000 { + compatible = "apple,t8142-pmc"; + reg = <0x3 0x82700000 0x0 0x10000>, + <0x3 0x82806000 0x0 0x3000>; + reg-names = "voters", "rails"; + #address-cells = <1>; + #size-cells = <0>; + /* PMP, CLPC and AP agents */ + apple,static-voters = <0 1 3>; + + clpc: performance-controller@1 { + compatible = "apple,t8142-clpc"; + reg = <1>; + }; + }; +}; + +&cpu0 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu1 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu2 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu3 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu4 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu5 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu6 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu7 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu8 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu9 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&{/timer} { + status = "okay"; +}; + +&aic { + status = "okay"; +}; + +&serial0 { + status = "okay"; +}; + +&dockchannel { + status = "okay"; +}; + +&pmgr { + status = "okay"; +}; + +#include "t8142-j704-display.dtsi" +#include "t8142-j704-peripherals.dtsi" +#include "t8142-j704-usb.dtsi" +#include "t8142-j704-avd.dtsi" +#include "t8142-j704-power.dtsi" +#include "t8142-j704-hwmon.dtsi" From 99e75f5890f09bf03bfb0fee7b2e54ce0b658eca Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sun, 8 Nov 2026 15:23:01 +0200 Subject: [PATCH 068/342] arm64: dts: apple: t8142-j704: Add NVMe, Wi-Fi/Bluetooth and the SD reader Describe the internal ANS2 NVMe SSD as on J813. This machine's ANS firmware ends the nvme register block at 0x10000 (ADT ans reg[9]) and keeps the linear submission queue doorbells in the NVMMU block, which the driver detects from the window size. Describe the internal PCIe as J813 describes its N1: the boot loader trains the links and Linux drives the root ports as a generic ECAM host. Port 0 carries the BCM4388 Wi-Fi/Bluetooth, port 2 the GL9755 SD card reader. Both ports' MSI maps share one AIC range, so one apple,t8142-pcie-msi controller lists both. The ports use the inventory's pcie0 and pcie2 DARTs, stream 0. Signed-off-by: Dmitriy Assisted-by: LLM --- .../arm64/boot/dts/apple/t8142-j704-nvme.dtsi | 103 ++++++++++++++++++ .../arm64/boot/dts/apple/t8142-j704-pcie.dtsi | 91 ++++++++++++++++ arch/arm64/boot/dts/apple/t8142-j704.dts | 4 + 3 files changed, 198 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-nvme.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8142-j704-pcie.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j704-nvme.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-nvme.dtsi new file mode 100644 index 0000000000000..67a08b81d4a29 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-nvme.dtsi @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple MacBook Pro (14-inch, M5) J704 with the internal ANS2 NVMe SSD. + * + * Laid out as on J813 (ADT /arm-io/ans, /arm-io/sart-ans, arm-io offset + * 0x210000000), but this machine's ANS firmware ends the nvme register + * block at 0x10000 (ADT ans reg[9]) and has the linear submission queue + * doorbells in the NVMMU block. iBoot leaves ANS running with the + * controller disabled, so the driver wakes it with a fresh RTKit handshake. + */ + +&pmgr { + ps_apcie_gp: power-controller@2f0 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp"; + }; + + ps_ans: power-controller@300 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x300 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ans"; + apple,always-on; /* handed over running, cannot be reset */ + }; + + ps_apcie_sys_gp: power-controller@408 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x408 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_gp"; + power-domains = <&ps_apcie_gp>; + }; + + ps_apcie_st: power-controller@410 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x410 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st"; + power-domains = <&ps_ans>; + }; + + ps_apcie_sys_st: power-controller@520 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x520 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_st"; + power-domains = <&ps_ans>, <&ps_apcie_st>; + }; + + ps_apcie_phy_sw: power-controller@560 { + compatible = "apple,t8142-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x560 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_phy_sw"; + power-domains = <&ps_apcie_sys_st>, <&ps_apcie_sys_gp>; + }; +}; + +&{/soc} { + ans_mbox: mailbox@481608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x4 0x81608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + power-domains = <&ps_ans>; + #mbox-cells = <0>; + }; + + sart: iommu@485c50000 { + compatible = "apple,t8142-sart", "apple,t6000-sart"; + reg = <0x4 0x85c50000 0x0 0xc000>; + power-domains = <&ps_ans>; + }; + + nvme: nvme@4c5cc0000 { + compatible = "apple,t8142-nvme-ans2", "apple,t8140-nvme-ans2"; + reg = <0x4 0xc5cc0000 0x0 0x10000>, + <0x4 0x81600000 0x0 0x4000>, + <0x4 0x85cc0000 0x0 0x60000>; + reg-names = "nvme", "ans", "nvmmu"; + interrupt-parent = <&aic>; + interrupts = ; + mboxes = <&ans_mbox>; + apple,sart = <&sart>; + power-domains = <&ps_ans>, <&ps_apcie_sys_st>, + <&ps_apcie_phy_sw>; + power-domain-names = "ans", "apcie0", "apcie_phy"; + resets = <&ps_ans>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704-pcie.dtsi b/arch/arm64/boot/dts/apple/t8142-j704-pcie.dtsi new file mode 100644 index 0000000000000..a0694d5064555 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j704-pcie.dtsi @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Internal PCIe: BCM4388 Wi-Fi/Bluetooth on apcie port 0 and the GL9755 SD + * card reader on port 2. As on J813, the bootloader trains the links and + * Linux uses the root ports as a generic ECAM host that owns the DARTs and + * the endpoints. Nothing programs the ports' RID-to-SID tables, so every + * function uses stream zero of its port's DART. Ranges, MSI maps and DART + * IRQs are from the J704 ADT; port 0 matches J813. + */ + +&{/} { + pcie0: pcie@1cb0000000 { + compatible = "pci-host-ecam-generic"; + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + bus-range = <0 2>; + reg = <0x1c 0xb0000000 0 0x300000>; + ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0 0x20000000>, + <0x02000000 0 0x80000000 0xb 0x80000000 0 0x40000000>; + dma-coherent; + msi-parent = <&pcie0_msi>; + iommu-map = <0x100 &pcie0_dart 0 1>, + <0x101 &pcie0_dart 0 1>, + <0x200 &pcie2_dart 0 1>; + + port00: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <1 1>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + wifi0: wifi@0,0 { + compatible = "pci14e4,4434"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "apple,linosa"; + /* To be filled by the loader */ + local-mac-address = [00 10 18 00 00 10]; + apple,antenna-sku = "XX"; + }; + + bluetooth0: bluetooth@0,1 { + compatible = "pci14e4,5f72"; + reg = <0x10100 0x0 0x0 0x0 0x0>; + brcm,board-type = "apple,linosa"; + /* To be filled by the loader */ + local-bd-address = [00 00 00 00 00 00]; + }; + }; + + port02: pci@2,0 { + device_type = "pci"; + reg = <0x1000 0x0 0x0 0x0 0x0>; + bus-range = <2 2>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + sdhci0: mmc@0,0 { + compatible = "pci17a0,9755"; + reg = <0x20000 0x0 0x0 0x0 0x0>; + cd-inverted; + wp-inverted; + }; + }; + }; +}; + +&{/soc} { + /* + * The MSI maps of ports 0 and 2. They share the root complex's AIC + * range (ADT msi-vector-offset 1741); 32 vectors are enough for both. + */ + pcie0_msi: msi-controller@488028000 { + compatible = "apple,t8142-pcie-msi"; + reg = <0x4 0x88028000 0x0 0x8000>, + <0x4 0x8a028000 0x0 0x8000>; + msi-controller; + msi-ranges = <&aic AIC_IRQ 1741 IRQ_TYPE_EDGE_RISING 32>; + }; +}; + +&pcie0_dart { + status = "okay"; +}; + +&pcie2_dart { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8142-j704.dts b/arch/arm64/boot/dts/apple/t8142-j704.dts index b6ce8a4dc5556..aebc8830d136a 100644 --- a/arch/arm64/boot/dts/apple/t8142-j704.dts +++ b/arch/arm64/boot/dts/apple/t8142-j704.dts @@ -17,6 +17,8 @@ aliases { serial0 = &serial0; serial1 = &dockchannel; + bluetooth0 = &bluetooth0; + wifi0 = &wifi0; }; chosen { @@ -316,5 +318,7 @@ #include "t8142-j704-peripherals.dtsi" #include "t8142-j704-usb.dtsi" #include "t8142-j704-avd.dtsi" +#include "t8142-j704-nvme.dtsi" +#include "t8142-j704-pcie.dtsi" #include "t8142-j704-power.dtsi" #include "t8142-j704-hwmon.dtsi" From 2aa89d3a76a360750a95f04e0482f4a97ce3a140 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 00:57:58 +1100 Subject: [PATCH 069/342] usb: core: Resume an autosuspended self-waking device for suspend-to-idle A device with USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED is kept awake in suspend-to-idle, but usb_suspend_both() returns early for a device that is already runtime suspended, so one that was autosuspended when the system suspend starts, with power/control set to auto, stays suspended, wakes itself again and still aborts the sleep. choose_wakeup() already resumes a runtime-suspended device whose wakeup setting has to change. Resume a self-waking device there too when it is about to be kept awake, and share the host controller checks with usb_stay_awake_for_wakeup(). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/usb/core/driver.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 81bb9ffad1059..f771e107ad51f 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1389,6 +1389,16 @@ static int usb_resume_interface(struct usb_device *udev, return status; } +/* Whether the host controller keeps running in this sleep and may wake the system */ +static bool usb_s2idle_may_keep_awake(struct usb_device *udev, pm_message_t msg) +{ + struct usb_hcd *hcd = bus_to_hcd(udev->bus); + + return msg.event == PM_EVENT_SUSPEND && hcd->runs_in_s2idle && + pm_suspend_target_state == PM_SUSPEND_TO_IDLE && + device_may_wakeup(hcd->self.controller); +} + /* * Whether to keep a device awake in suspend-to-idle so that a remote wakeup * can reach the host controller: a hub that does not pass one on from below @@ -1407,13 +1417,10 @@ static int usb_resume_interface(struct usb_device *udev, */ VISIBLE_IF_KUNIT bool usb_stay_awake_for_wakeup(struct usb_device *udev, pm_message_t msg) { - struct usb_hcd *hcd = bus_to_hcd(udev->bus); struct usb_device *child; int port1; - if (msg.event != PM_EVENT_SUSPEND || !hcd->runs_in_s2idle || - pm_suspend_target_state != PM_SUSPEND_TO_IDLE || - !device_may_wakeup(hcd->self.controller)) + if (!usb_s2idle_may_keep_awake(udev, msg)) return false; if ((udev->quirks & USB_QUIRK_HUB_NO_SUSPENDED_PORT_WAKEUP) && @@ -1673,6 +1680,14 @@ static void choose_wakeup(struct usb_device *udev, pm_message_t msg) */ if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup) pm_runtime_resume(&udev->dev); + /* + * A device that wakes itself when suspended is kept awake instead, see + * usb_stay_awake_for_wakeup(), so bring it back from an autosuspend. + */ + else if (udev->state == USB_STATE_SUSPENDED && w && + (udev->quirks & USB_QUIRK_WAKES_ITSELF_WHEN_SUSPENDED) && + usb_s2idle_may_keep_awake(udev, msg)) + pm_runtime_resume(&udev->dev); udev->do_remote_wakeup = w; } From f6ba35b02115a9a41b0eb647b8c2f10b2632cf5e Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Thu, 5 Nov 2026 14:37:46 +0200 Subject: [PATCH 070/342] thunderbolt: apple: Do not start the NHI without its DART The NHI and its DART are both children of the ACIO and are created together when the router starts. The DART normally binds first, and the driver core defers the NHI until it has. Once the core has stopped waiting for missing suppliers, though (for example, the DART driver is a module that is not loaded yet when a cable is plugged in), the NHI probes without an IOMMU and would hand the hardware physical ring addresses. Refuse to probe an NHI that has iommus but is not attached to an IOMMU domain. Report it through the boot status as well, so that the ACIO fails this start right away with -EPROBE_DEFER instead of waiting for the 10 s NHI boot timeout; the next connection retries. Signed-off-by: Dmitriy Assisted-by: LLM --- drivers/thunderbolt/apple.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index ba7ec0bc0296c..6330140715e2b 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -2052,6 +2053,20 @@ static int apple_nhi_probe(struct platform_device *pdev) goto err; } + /* + * The rings must never run untranslated. The DART is populated with + * the NHI, so it is normally bound first; but once the driver core + * has stopped waiting for missing suppliers (DART driver not loaded + * yet), the NHI would probe without its IOMMU. Defer, and fail the + * ACIO start now instead of letting it wait for the NHI to time out. + */ + if (of_property_present(pdev->dev.of_node, "iommus") && + !device_iommu_mapped(&pdev->dev)) { + dev_warn(&pdev->dev, "DART not bound yet, not starting the NHI\n"); + ret = -EPROBE_DEFER; + goto err; + } + anhi = devm_kzalloc(&pdev->dev, sizeof(*anhi), GFP_KERNEL); if (!anhi) { ret = -ENOMEM; From ce5428ab0aeec98fed85afeb9bab6144ead7115c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 03:56:33 +1100 Subject: [PATCH 071/342] accel/ane: pipeline bounded H16/H17 EXECUTEs by request key Keep publication, acknowledgment and completion dispatch under the session mutex, but release it while waiting between terminal-report polls. Reserve a bounded session slot and each program's surfaces through copy-out so other fds can overlap preparation and submission with engine execution. Default to two slots; a read-only execute_depth parameter permits 1-4. Dispatch reports and timing to their own pending keys. Fail every pending request on quarantine, retain the command arena on uncertain outcomes, and drain owners before lifecycle traffic and sleep. Reclaim successful batches only after the last running request ends, with backpressure when a sustained pipeline fills the arena. Hold the gate and performance vote while any request runs, preserving the existing idle gate hold. Allow H16 program switching through the queued BAR-context setup already used on H17. Queue overlapping requests and invalidate speculative direct context after an overlapping batch, whose completion order can differ. Keep one program per fd with a file mutex protecting its lifetime. Exercise out-of-order completion on H16/H17, same-program exclusion, the default bound, arena pressure, surface ownership, timeout, quarantine and sleep with concurrent KUnit callers. Only the poll pause runs without the session lock. On H16 the backend relax also drains the ASC mailbox (two reads pop one entry), steps RTKit and checks faults; two waiters doing that at once could tear a message. A new optional service op does that part under the lock before the pause. A request that already completed keeps its own status even if the session is quarantined before its owner re-takes the lock. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_fw_transport.h | 16 +- drivers/accel/ane/ane_fw_transport_test.c | 6 +- drivers/accel/ane/ane_h16_accel.c | 36 +- drivers/accel/ane/ane_h16_backend.c | 8 +- drivers/accel/ane/ane_h16_pending.h | 32 +- drivers/accel/ane/ane_h16_pending_test.c | 6 +- drivers/accel/ane/ane_h16_program.c | 317 ++++++++++++---- drivers/accel/ane/ane_h16_program.h | 27 +- drivers/accel/ane/ane_h16_program_test.c | 440 +++++++++++++++++++++- 9 files changed, 757 insertions(+), 131 deletions(-) diff --git a/drivers/accel/ane/ane_fw_transport.h b/drivers/accel/ane/ane_fw_transport.h index 7ae897bc90c80..d327118204120 100644 --- a/drivers/accel/ane/ane_fw_transport.h +++ b/drivers/accel/ane/ane_fw_transport.h @@ -86,6 +86,12 @@ struct ane_fw_transport_ops { u64 (*now_ns)(void *ctx); /* Wait before the next poll of a wait that began waited_ns ago. */ void (*relax)(void *ctx, u64 waited_ns); + /* + * Optional: the non-waiting half of relax() (drain the mailbox, check + * faults). It touches shared transport state, so callers that drop + * their lock around the pause call it first, with the lock held. + */ + void (*service)(void *ctx); int (*alloc)(void *ctx, size_t size, u32 tag, struct ane_fw_surface *surface); void (*refused)(void *ctx, u64 word0, u64 word1, u64 word2, int error); /* Optional: a shared allocation was freed ("FREE") or served again ("reuse"). */ @@ -311,7 +317,7 @@ static inline int ane_fw_transport_arm(struct ane_fw_transport *t) } /* - * The H17 firmware's direct submission path reuses the engine's current BAR + * The H16/H17 firmware's direct submission path reuses the engine's current BAR * context. When that context came from a different program, a job (of a new * or previously loaded program, even after the earlier one was destroyed) can * write through the earlier program's output binding. Bit 0 of the request @@ -319,8 +325,7 @@ static inline int ane_fw_transport_arm(struct ane_fw_transport *t) * installs a fresh BAR context. Queue the first EXECUTE after any change of program, process or * program lifetime; later jobs of the same process keep the direct path. This * lifts the one-program-per-firmware-session limit. Applies to the pool copy, - * so every published EXECUTE follows the rule. H16 shares the firmware - * architecture but has not executed under Linux yet; it is left unchanged. + * so every published EXECUTE follows the rule. */ static inline void ane_fw_transport_bar_context(struct ane_fw_transport *t, u8 *copy, size_t size) @@ -350,12 +355,11 @@ ane_fw_transport_bar_context(struct ane_fw_transport *t, u8 *copy, size_t size) /* * Whether one firmware session may run several programs: the transport - * queues the first EXECUTE after every program change (H17, above). H16 - * shares the firmware design, but the rule is unconfirmed there. + * queues the first EXECUTE after every program change (above). */ static inline bool ane_fw_transport_switch_safe(const struct ane_fw_transport *t) { - return t->soc->chip_family == 17; + return t->soc->chip_family == 16 || t->soc->chip_family == 17; } /* Commands are copied into a monotonic pool arena, never external DMA memory. */ diff --git a/drivers/accel/ane/ane_fw_transport_test.c b/drivers/accel/ane/ane_fw_transport_test.c index 4f4b87cf98974..c38415ada6c6b 100644 --- a/drivers/accel/ane/ane_fw_transport_test.c +++ b/drivers/accel/ane/ane_fw_transport_test.c @@ -1433,9 +1433,11 @@ static void ane_transport_bar_context_h16_test(struct kunit *test) f->soc.chip_family = 16; KUNIT_ASSERT_EQ(test, ane_fw_transport_arm(&f->t), 0); - /* Not yet measured on H16: requests are published unchanged. */ + /* Each H16 program switch installs the queued job's private BARs. */ + KUNIT_EXPECT_EQ(test, ane_test_execute(f, 0, 0), ANE_H16_EXECUTE_FLAG_QUEUED); KUNIT_EXPECT_EQ(test, ane_test_execute(f, 0, 0), 0U); - KUNIT_EXPECT_EQ(test, ane_test_execute(f, 1, 1), 0U); + KUNIT_EXPECT_EQ(test, ane_test_execute(f, 1, 1), ANE_H16_EXECUTE_FLAG_QUEUED); + KUNIT_EXPECT_EQ(test, ane_test_execute(f, 0, 0), ANE_H16_EXECUTE_FLAG_QUEUED); } /* Each relax() learns how long its wait has run, and every call is counted. */ diff --git a/drivers/accel/ane/ane_h16_accel.c b/drivers/accel/ane/ane_h16_accel.c index 8657f148f0ccb..830bab5d4a5a3 100644 --- a/drivers/accel/ane/ane_h16_accel.c +++ b/drivers/accel/ane/ane_h16_accel.c @@ -25,11 +25,13 @@ struct ane_h16_accel { struct drm_device drm; struct ane_h16_session *session; - /* Serializes the session, every program and all firmware traffic. */ + /* Serializes admission, transport traffic and completion dispatch. */ struct mutex lock; }; struct ane_h16_accel_file { + /* Pins the program lifetime across LOAD and an EXECUTE's copy phases. */ + struct mutex lock; struct ane_h16_program *program; }; @@ -109,9 +111,12 @@ static int ane_h16_load_ioctl(struct drm_device *drm, void *data, struct drm_fil args->hwx_size, &snapshot); if (ret) goto out; + mutex_lock(&f->lock); ret = ane_h16_session_enter(a->session, file->filp->f_flags & O_NONBLOCK); - if (ret) + if (ret) { + mutex_unlock(&f->lock); goto out; + } /* Lost across system sleep: release it, the caller is reloading. */ if (f->program && ane_h16_program_lost(a->session, f->program) && !ane_h16_session_close(a->session, f->program)) { @@ -123,9 +128,6 @@ static int ane_h16_load_ioctl(struct drm_device *drm, void *data, struct drm_fil } else { ret = ane_h16_session_load(a->session, &snapshot, (const void *const *)aux, aux_size, &program); - if (ret == -EBUSY) - /* The caller's own EBUSY, not a driver error. */ - drm_dbg(drm, "another program is still loaded; close it first\n"); if (!ret) f->program = program; } @@ -141,6 +143,7 @@ static int ane_h16_load_ioctl(struct drm_device *drm, void *data, struct drm_fil } } mutex_unlock(&a->lock); + mutex_unlock(&f->lock); out: /* A consumed snapshot was moved into the program and reads as empty. */ if (snapshot.bytes) @@ -167,10 +170,12 @@ static int ane_h16_exec_ioctl(struct drm_device *drm, void *data, struct drm_fil array_size(args->count, sizeof(*buffers)))) return -EFAULT; start = ktime_get_ns(); + mutex_lock(&f->lock); ret = ane_h16_session_enter(a->session, file->filp->f_flags & O_NONBLOCK); - if (ret) + if (ret) { + mutex_unlock(&f->lock); return ret; - locked = ktime_get_ns(); + } p = f->program; if (!p || p->closed || args->count != p->resource_count) { ret = -EINVAL; @@ -182,14 +187,18 @@ static int ane_h16_exec_ioctl(struct drm_device *drm, void *data, struct drm_fil goto unlock; } } - /* The firmware is idle for this program, so its inputs may change now. */ + ret = ane_h16_session_acquire(a->session, p); + if (ret) + goto unlock; + locked = ktime_get_ns(); + /* This program's shared surfaces are ours through the final copy-out. */ for (i = 0; i < args->count; i++) { void *cpu = p->surfaces[i]->cpu; if (p->resources[i].permissions == 1) { if (copy_from_user(cpu, u64_to_user_ptr(buffers[i].ptr), buffers[i].size)) { ret = -EFAULT; - goto unlock; + goto release; } } else { memset(cpu, 0xff, buffers[i].size); @@ -197,9 +206,9 @@ static int ane_h16_exec_ioctl(struct drm_device *drm, void *data, struct drm_fil } ane_h16_session_sync(a->session, p, true); copied = ktime_get_ns(); - ret = ane_h16_session_execute(a->session, p); + ret = ane_h16_session_run(a->session, p); if (ret) - goto unlock; + goto release; done = ktime_get_ns(); ane_h16_session_sync(a->session, p, false); for (i = 0; i < args->count; i++) @@ -228,8 +237,11 @@ static int ane_h16_exec_ioctl(struct drm_device *drm, void *data, struct drm_fil div_u64(ns[ANE_H16_T_FIRMWARE], 1000), div_u64(end - start, 1000), a->session->timing.polls); } +release: + ane_h16_session_release(a->session, p); unlock: mutex_unlock(&a->lock); + mutex_unlock(&f->lock); return ret; } @@ -239,6 +251,7 @@ static int ane_h16_open(struct drm_device *drm, struct drm_file *file) if (!f) return -ENOMEM; + mutex_init(&f->lock); file->driver_priv = f; return 0; } @@ -270,6 +283,7 @@ static void ane_h16_postclose(struct drm_device *drm, struct drm_file *file) ane_h16_session_put(a->session, f->program); } mutex_unlock(&a->lock); + mutex_destroy(&f->lock); kfree(f); } diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index 8628802578c55..e44e55e6ac510 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -977,7 +977,7 @@ static u64 ane_h16_now(void *ctx) * sleeps. A fixed 1 ms sleep made each of the four waits of an EXECUTE cost * at least a millisecond. */ -static void ane_h16_relax(void *ctx, u64 waited_ns) +static void ane_h16_service(void *ctx) { struct ane_h16_device *h = ctx; int ret; @@ -986,6 +986,11 @@ static void ane_h16_relax(void *ctx, u64 waited_ns) ret = ane_h16_faults(&h->boot, false); if (ret) ane_fw_transport_fail(&h->boot.transport, ret); +} + +static void ane_h16_relax(void *ctx, u64 waited_ns) +{ + ane_h16_service(ctx); ane_fw_poll_pause(waited_ns); } @@ -1106,6 +1111,7 @@ static const struct ane_fw_transport_ops ane_h16_transport_ops = { .write32 = ane_h16_engine_write, .now_ns = ane_h16_now, .relax = ane_h16_relax, + .service = ane_h16_service, .alloc = ane_h16_alloc_shared, .refused = ane_h16_refused, .shared_note = ane_h16_shared_note, diff --git a/drivers/accel/ane/ane_h16_pending.h b/drivers/accel/ane/ane_h16_pending.h index b74b20a0b0ea2..60207d2bc09ec 100644 --- a/drivers/accel/ane/ane_h16_pending.h +++ b/drivers/accel/ane/ane_h16_pending.h @@ -66,14 +66,31 @@ ane_h16_pending_remove(struct ane_h16_pending_table *table, request->active = false; } +/* A session fault fails every waiter and pins all DMA backing until reset. */ +static inline void +ane_h16_pending_fail_all(struct ane_h16_pending_table *table, int status) +{ + unsigned int i; + + table->quarantined = true; + table->error = status; + for (i = 0; i < ANE_H16_PENDING_MAX; i++) { + struct ane_h16_pending *request = table->slots[i]; + + if (!request) + continue; + request->status = status; + request->active = false; + table->slots[i] = NULL; + } +} + /* A published command with an uncertain outcome pins all its mappings. */ static inline void ane_h16_pending_abort(struct ane_h16_pending_table *table, struct ane_h16_pending *request, int status) { - table->quarantined = true; - table->error = status; - ane_h16_pending_remove(table, request); + ane_h16_pending_fail_all(table, status); request->status = status; } @@ -113,15 +130,12 @@ ane_h16_pending_event(struct ane_h16_pending_table *table, const void *bytes, ane_h16_pending_remove(table, request); request->terminal = true; request->status = ret == ANE_H16_EVENT_COMPLETE ? 0 : -EIO; - if (request->status) { - table->error = request->status; - table->quarantined = true; - } + if (request->status) + ane_h16_pending_fail_all(table, request->status); return ret; corrupt: - table->error = ret; - table->quarantined = true; + ane_h16_pending_fail_all(table, ret); return ret; } diff --git a/drivers/accel/ane/ane_h16_pending_test.c b/drivers/accel/ane/ane_h16_pending_test.c index bff31e3d9ca39..ed866c45710d7 100644 --- a/drivers/accel/ane/ane_h16_pending_test.c +++ b/drivers/accel/ane/ane_h16_pending_test.c @@ -69,7 +69,8 @@ static void pending_mismatched_ids_test(struct kunit *test) make_event(event, &request, 1); put_unaligned_le32(1, event + offset); KUNIT_EXPECT_EQ(test, ane_h16_pending_dispatch(&table, event, 0x60, 6, 1), -EPROTO); - KUNIT_EXPECT_TRUE(test, request.active); + KUNIT_EXPECT_FALSE(test, request.active); + KUNIT_EXPECT_EQ(test, request.status, -EPROTO); KUNIT_EXPECT_FALSE(test, request.terminal); KUNIT_EXPECT_TRUE(test, table.quarantined); KUNIT_EXPECT_EQ(test, table.error, -EPROTO); @@ -123,7 +124,8 @@ static void pending_malformed_test(struct kunit *test) } KUNIT_EXPECT_EQ(test, ane_h16_pending_dispatch(&table, bytes, length, channel, 1), -EPROTO); - KUNIT_EXPECT_TRUE(test, request.active); + KUNIT_EXPECT_FALSE(test, request.active); + KUNIT_EXPECT_EQ(test, request.status, -EPROTO); KUNIT_EXPECT_TRUE(test, table.quarantined); } } diff --git a/drivers/accel/ane/ane_h16_program.c b/drivers/accel/ane/ane_h16_program.c index 0ab46d7a1303d..87cd8bb2a0b2f 100644 --- a/drivers/accel/ane/ane_h16_program.c +++ b/drivers/accel/ane/ane_h16_program.c @@ -491,8 +491,26 @@ int ane_h16_custom_bars(const struct ane_h16_hwx_snapshot *snapshot, } EXPORT_SYMBOL_GPL(ane_h16_custom_bars); +/* Read-only after module load: use depth 1 for the throughput A/B baseline. */ +static unsigned int execute_depth = 2; +module_param(execute_depth, uint, 0444); +MODULE_PARM_DESC(execute_depth, "Maximum concurrent EXECUTEs (1-4, default 2)"); + static void h16_gate_work(struct work_struct *work); +/* Lifecycle traffic must not interleave with a batch's command arena. */ +static void h16_drain(struct ane_h16_session *s) +{ + if (!s->active) + return; + s->draining++; + mutex_unlock(s->lock); + wait_event(s->wake, !READ_ONCE(s->active)); + mutex_lock(s->lock); + s->draining--; + wake_up_all(&s->wake); +} + int ane_h16_session_init(struct ane_h16_session *s, struct ane_fw_transport *transport, const struct ane_h16_session_ops *ops, void *ctx, u64 timeout_ns) @@ -507,6 +525,7 @@ int ane_h16_session_init(struct ane_h16_session *s, struct ane_fw_transport *tra s->timeout_ns = timeout_ns; s->dsid = ANE_H16_MCACHE_DSID; s->settle_ns = ANE_H16_SETTLE_QUIET_NS; + s->depth = clamp(execute_depth, 1U, 4U); init_waitqueue_head(&s->wake); INIT_LIST_HEAD(&s->deferred); INIT_LIST_HEAD(&s->programs); @@ -522,7 +541,8 @@ static int h16_fail(struct ane_h16_session *s, int error) s->error = error; if (!s->quarantined) { s->quarantined = true; - s->pending.quarantined = true; + ane_h16_pending_fail_all(&s->pending, s->error); + wake_up_all(&s->wake); s->ops->log(s->ctx, "program quarantine", (u64)-s->error, 0); } return s->error; @@ -756,9 +776,8 @@ static const size_t h16_load_sequence[] = { * the previous program's output buffer unless it is queued. The session * queues the first EXECUTE whenever the engine last ran another program, the * first one after boot included (see ane_h16_session_execute()). A LOAD is - * refused while the previous program is still loaded and accepted once it - * closed; a switch-safe transport (H17) also requeues on every program or - * process change, so its session may hold several programs at once. Every + * serialized with in-flight EXECUTEs. The transport also requeues on every + * program or process change, so a session may hold several programs. Every * program's firmware-visible memory stays mapped until reset. */ int ane_h16_session_load(struct ane_h16_session *s, @@ -776,11 +795,11 @@ int ane_h16_session_load(struct ane_h16_session *s, if (!s || !snapshot || !aux || !aux_size || !program) return -EINVAL; + h16_drain(s); + if (s->asleep) + return -EAGAIN; if (s->quarantined) return -EIO; - if (s->program && !s->program->closed && - !ane_fw_transport_switch_safe(s->transport)) - return -EBUSY; for (i = 0; i < ANE_H16_AUX_COUNT; i++) if (!aux[i] || aux_size[i] < ANE_H16_AUX_MIN || aux_size[i] > ANE_H16_AUX_MAX || !IS_ALIGNED(aux_size[i], 4)) @@ -896,7 +915,7 @@ int ane_h16_session_gate_expire(struct ane_h16_session *s) { if (!s->gate_held) return 0; - if (h16_now(s) - s->gate_last_ns < s->gate_hold_ns) + if (s->running || h16_now(s) - s->gate_last_ns < s->gate_hold_ns) return -EAGAIN; return h16_gate_release(s); } @@ -992,6 +1011,11 @@ struct h16_execute_trace { u64 done_ns; }; +struct h16_request { + struct ane_h16_pending pending; + struct h16_execute_trace trace; +}; + enum { H16_STEP_GATE_OPEN = 1, H16_STEP_SEND, @@ -1014,7 +1038,32 @@ static void h16_trace_report(struct h16_execute_trace *trace, const u8 *report, } } -/* Wait for the terminal report of one pending UUID, servicing allocations. */ +/* Dispatch by key, including timing, even when another caller polls the ring. */ +static int h16_report(struct ane_h16_session *s, const u8 *report, size_t size) +{ + struct ane_h16_event event; + unsigned int i; + u64 now = h16_now(s); + + if (!ane_h16_event_decode(report, size, ANE_FW_IO_T2H, &event)) { + for (i = 0; i < ANE_H16_PENDING_MAX; i++) { + struct ane_h16_pending *p = s->pending.slots[i]; + struct h16_request *r; + + if (!p || p->key.uuid != event.key.uuid) + continue; + r = container_of(p, struct h16_request, pending); + h16_trace_report(&r->trace, report, size, p, now); + if (event.state == 1) + r->trace.done_ns = now; + break; + } + } + return ane_h16_pending_dispatch(&s->pending, report, size, ANE_FW_IO_T2H, + (unsigned long)div_u64(now, NSEC_PER_USEC)); +} + +/* Wait for this request, serving all keys under the session mutex. */ static int h16_wait_report(struct ane_h16_session *s, struct ane_h16_pending *request, u64 deadline, struct h16_execute_trace *trace) { @@ -1030,33 +1079,28 @@ static int h16_wait_report(struct ane_h16_session *s, struct ane_h16_pending *re size_t size; u32 pending; + /* A request that already ended keeps its own result. */ + if (!request->active) { + ret = request->status; + break; + } + if (s->quarantined || s->pending.quarantined) { + ret = s->error ?: s->pending.error ?: -EIO; + break; + } + /* Other keys' reports must not postpone this request's deadline. */ + if (h16_now(s) >= deadline) { + ret = -ETIMEDOUT; + break; + } ret = ane_fw_transport_consume(t, report, ANE_H16_REPORT_MAX, &size); if (!ret) { - ret = ane_h16_pending_dispatch(&s->pending, report, size, - ANE_FW_IO_T2H, - (unsigned long)div_u64(h16_now(s), - NSEC_PER_USEC)); - if (ret == ANE_H16_EVENT_COMPLETE) { - trace->done_ns = h16_now(s); - if (!trace->reports) - trace->first_ns = trace->done_ns; - ret = 0; - break; - } - if (ret == ANE_H16_EVENT_FAILED) { - ret = -EIO; - break; - } - /* Foreign or late UUIDs and ISP-routed reports never retire this call. */ - if (ret == ANE_H16_EVENT_PROGRESS) { - h16_trace_report(trace, report, size, request, h16_now(s)); - continue; - } - if (ret == -ENOENT || ret == -ENOMSG) { + ret = h16_report(s, report, size); + if (ret == -ENOENT || ret == -ENOMSG) trace->other++; - continue; - } - break; + else if (ret < 0) + break; + continue; } if (ret != -EAGAIN) break; @@ -1076,12 +1120,40 @@ static int h16_wait_report(struct ane_h16_session *s, struct ane_h16_pending *re break; } t->polls++; - t->ops->relax(t->ctx, now - start); + /* + * Publish/ack and dispatch stay serialized; engine time can + * overlap. Only the pause runs unlocked: servicing the mailbox + * and fault state touches shared transport state. + */ + if (s->lock && t->ops->service) { + t->ops->service(t->ctx); + mutex_unlock(s->lock); + ane_fw_poll_pause(now - start); + mutex_lock(s->lock); + } else if (s->lock) { + mutex_unlock(s->lock); + t->ops->relax(t->ctx, now - start); + mutex_lock(s->lock); + } else { + t->ops->relax(t->ctx, now - start); + } } kfree(report); return ret; } +/* Include the final gate and teardown pair before admitting another command. */ +static int h16_execute_room(struct ane_h16_session *s, struct ane_h16_program *p) +{ + const size_t sequence[] = { + ANE_H16_GATE_SIZE, + ANE_H16_EXECUTE_BASE_SIZE + p->bar_count * ANE_H16_CUSTOM_BAR_STRIDE, + ANE_H16_GATE_SIZE, ANE_H16_TERMINATE_SIZE, ANE_H16_UNLOAD_SIZE, + }; + + return h16_pool_room(s, sequence, ARRAY_SIZE(sequence)); +} + /* * 0x002d with 0, EXECUTE on channel 7 with its UUID already pending, the * matching state-1 report on channel 6, 0x002d with 1, then a DMA read @@ -1091,11 +1163,12 @@ static int h16_wait_report(struct ane_h16_session *s, struct ane_h16_pending *re static int h16_execute(struct ane_h16_session *s, struct ane_h16_program *p) { struct ane_h16_execute_buffer buffers[ANE_H16_SURFACES + 1]; - struct ane_h16_pending request = {}; - struct h16_execute_trace trace = { .last_state = U32_MAX }; + struct h16_request r = { .trace.last_state = U32_MAX }; + struct ane_h16_pending *request = &r.pending; + struct h16_execute_trace *trace = &r.trace; struct ane_h16_execute call = {}; struct ane_h16_exec_sample *x = &s->timing; - size_t length, sequence[5], mark; + size_t length; u8 *command; const u8 *reply = NULL; unsigned int i; @@ -1135,39 +1208,32 @@ static int h16_execute(struct ane_h16_session *s, struct ane_h16_program *p) if (p->has_scratch) buffers[i++] = p->scratch; length = ANE_H16_EXECUTE_BASE_SIZE + p->bar_count * ANE_H16_CUSTOM_BAR_STRIDE; - /* Keep room for the teardown pair after this request. */ - sequence[0] = ANE_H16_GATE_SIZE; - sequence[1] = length; - sequence[2] = ANE_H16_GATE_SIZE; - sequence[3] = ANE_H16_TERMINATE_SIZE; - sequence[4] = ANE_H16_UNLOAD_SIZE; - ret = h16_pool_room(s, sequence, ARRAY_SIZE(sequence)); + ret = h16_execute_room(s, p); if (ret) return ret; command = kzalloc(length, GFP_KERNEL); if (!command) return -ENOMEM; - mark = ane_fw_transport_mark(s->transport); /* Inputs and poisoned outputs must reach memory before any doorbell. */ s->transport->ops->write_barrier(s->transport->ctx); polls = s->transport->polls; - trace.step = H16_STEP_GATE_OPEN; + trace->step = H16_STEP_GATE_OPEN; t0 = h16_now(s); if (!s->gate_held) { ret = h16_gate(s, 0); if (ret) goto fail; - s->gate_held = s->gate_hold_ns != 0; + s->gate_held = true; } gate_open = h16_now(s) - t0; deadline = t0 + gate_open + s->timeout_ns; - request.key = p->key; - request.deadline = (unsigned long)div_u64(deadline, NSEC_PER_USEC); - ret = ane_h16_pending_insert(&s->pending, &request, + request->key = p->key; + request->deadline = (unsigned long)div_u64(deadline, NSEC_PER_USEC); + ret = ane_h16_pending_insert(&s->pending, request, (unsigned long)div_u64(h16_now(s), NSEC_PER_USEC)); if (ret) goto fail; - call.key = request.key; + call.key = request->key; call.buffers = buffers; call.buffer_count = p->resource_count + (p->has_scratch ? 1 : 0); /* @@ -1177,7 +1243,7 @@ static int h16_execute(struct ane_h16_session *s, struct ane_h16_program *p) * request carries every descriptor-declared custom BAR, including both * mixed-descriptor mcache streams, on the queued and direct paths. */ - if (s->executed != p->generation) + if (s->running > 1 || s->executed != p->generation) call.flags = ANE_H16_EXECUTE_FLAG_QUEUED; s->executed = p->generation; call.bars = p->bars; @@ -1187,30 +1253,30 @@ static int h16_execute(struct ane_h16_session *s, struct ane_h16_program *p) ret = ane_h16_command_prepare(command, length, ANE_H16_EXECUTE, ANE_FW_DATA_CHAIN); if (!ret) { - trace.step = H16_STEP_SEND; + trace->step = H16_STEP_SEND; t1 = h16_now(s); ret = h16_send(s, ANE_FW_DATA_CHAIN, command, length, &reply); } /* The channel-7 reply acknowledges transport only, never completion. */ if (!ret) { - trace.step = H16_STEP_REPORT; + trace->step = H16_STEP_REPORT; t2 = h16_now(s); - ret = h16_wait_report(s, &request, deadline, &trace); + ret = h16_wait_report(s, request, deadline, trace); } if (ret) { - if (request.active) - ane_h16_pending_abort(&s->pending, &request, ret); + if (request->active) + ane_h16_pending_abort(&s->pending, request, ret); goto fail; } - trace.step = H16_STEP_GATE_CLOSE; + trace->step = H16_STEP_GATE_CLOSE; t3 = h16_now(s); - if (!s->gate_held) { - ret = h16_gate(s, 1); + if (s->running == 1 && !s->gate_hold_ns) { + ret = h16_gate_release(s); if (ret) goto fail; } end = h16_now(s); - if (s->gate_held) { + if (s->gate_held && s->running == 1) { /* Back-to-back requests find gating off; it goes on when idle. */ s->gate_last_ns = end; if (s->lock) @@ -1222,30 +1288,25 @@ static int h16_execute(struct ane_h16_session *s, struct ane_h16_program *p) x->ns[ANE_H16_T_PREPARE] = t0 - entry; x->ns[ANE_H16_T_GATE_OPEN] = gate_open; x->ns[ANE_H16_T_SUBMIT_ACK] = t2 - t1; - x->ns[ANE_H16_T_ACK_REPORT] = trace.first_ns - t2; - x->ns[ANE_H16_T_REPORT_DONE] = trace.done_ns - trace.first_ns; + x->ns[ANE_H16_T_ACK_REPORT] = trace->first_ns - t2; + x->ns[ANE_H16_T_REPORT_DONE] = trace->done_ns - trace->first_ns; x->ns[ANE_H16_T_GATE_CLOSE] = end - t3; x->ns[ANE_H16_T_FIRMWARE] = end - t0; x->polls = s->transport->polls - polls; kfree(command); - /* - * The completion report and the closing gate reply both arrived, so the - * firmware no longer reads this sequence's commands: reuse their space. - */ - ret = ane_fw_transport_release(s->transport, mark); x->ns[ANE_H16_T_FINISH] = h16_now(s) - end; - return ret; + return 0; fail: - s->ops->log(s->ctx, "EXECUTE failed", (u64)-ret, request.key.uuid); + s->ops->log(s->ctx, "EXECUTE failed", (u64)-ret, request->key.uuid); /* * Step 1 opening gate, 2 channel-7 ack, 3 report wait, 4 closing gate. * Reports for this UUID and the last state (0 start, 3 engine start, * ffffffff none), then the count of other reports seen while waiting. */ - s->ops->log(s->ctx, "EXECUTE step/flags", trace.step, call.flags); - s->ops->log(s->ctx, "EXECUTE reports/last state", trace.reports, trace.last_state); - s->ops->log(s->ctx, "EXECUTE other reports", trace.other, 0); - if (trace.step >= H16_STEP_SEND) { + s->ops->log(s->ctx, "EXECUTE step/flags", trace->step, call.flags); + s->ops->log(s->ctx, "EXECUTE reports/last state", trace->reports, trace->last_state); + s->ops->log(s->ctx, "EXECUTE other reports", trace->other, 0); + if (trace->step >= H16_STEP_SEND) { h16_dump_rows("EXECUTE sent", command, length); if (reply) h16_dump_rows("EXECUTE ack", reply, 0x40); @@ -1262,20 +1323,109 @@ bool ane_h16_program_lost(const struct ane_h16_session *s, const struct ane_h16_ } EXPORT_SYMBOL_GPL(ane_h16_program_lost); -int ane_h16_session_execute(struct ane_h16_session *s, struct ane_h16_program *p) +/* Read without the mutex in wait_event(), then rechecked under it. */ +static bool h16_available(struct ane_h16_session *s, struct ane_h16_program *p) +{ + return !READ_ONCE(s->asleep) && !READ_ONCE(s->draining) && + !READ_ONCE(p->executing) && READ_ONCE(s->active) < s->depth; +} + +/* Own one program's surfaces, and one bounded session slot, through copy-out. */ +int ane_h16_session_acquire(struct ane_h16_session *s, struct ane_h16_program *p) { int ret; if (!s || !p || p->session != s) return -EINVAL; - /* The firmware that knew it is gone: no firmware traffic, reload. */ + while (!s->quarantined && !h16_available(s, p)) { + mutex_unlock(s->lock); + ret = wait_event_freezable(s->wake, + READ_ONCE(s->quarantined) || h16_available(s, p)); + mutex_lock(s->lock); + if (ret) + return ret; + } + if (s->quarantined) + return -EIO; if (ane_h16_program_lost(s, p)) return -ENODEV; - if (s->ops->busy) - s->ops->busy(s->ctx, true); + if (!p->created || p->closed) + return -EINVAL; + p->executing = true; + s->active++; + return 0; +} +EXPORT_SYMBOL_GPL(ane_h16_session_acquire); + +void ane_h16_session_release(struct ane_h16_session *s, struct ane_h16_program *p) +{ + p->executing = false; + s->active--; + wake_up_all(&s->wake); +} +EXPORT_SYMBOL_GPL(ane_h16_session_release); + +/* Surface ownership was acquired before copy-in. Called with s->lock held. */ +int ane_h16_session_run(struct ane_h16_session *s, struct ane_h16_program *p) +{ + int ret; + + if (!s || !p || p->session != s || !p->executing) + return -EINVAL; + /* + * A continuous pipeline can fill the monotonic command arena. Stop + * admission and let the current batch drain and reclaim it, without + * counting this not-yet-published request among the running commands. + */ + if (s->running && h16_execute_room(s, p)) { + s->draining++; + do { + mutex_unlock(s->lock); + wait_event(s->wake, !READ_ONCE(s->running)); + mutex_lock(s->lock); + } while (s->running); + s->draining--; + wake_up_all(&s->wake); + if (s->quarantined) + return s->error; + } + if (s->running) + s->pipelined = true; + if (!s->running++) { + s->execute_mark = ane_fw_transport_mark(s->transport); + if (s->ops->busy) + s->ops->busy(s->ctx, true); + } ret = h16_execute(s, p); - if (s->ops->busy) - s->ops->busy(s->ctx, false); + if (!--s->running) { + /* Completion order need not match submission order. */ + if (s->pipelined) { + s->executed = 0; + s->transport->bar_known = false; + s->pipelined = false; + } + /* An uncertain outcome pins the entire batch, including its commands. */ + if (!s->quarantined) { + int err = ane_fw_transport_release(s->transport, s->execute_mark); + + if (err) + ret = h16_fail(s, err); + } + if (s->ops->busy) + s->ops->busy(s->ctx, false); + } + return ret; +} +EXPORT_SYMBOL_GPL(ane_h16_session_run); + +int ane_h16_session_execute(struct ane_h16_session *s, struct ane_h16_program *p) +{ + int ret = ane_h16_session_acquire(s, p); + + if (ret) + return ret; + ret = ane_h16_session_run(s, p); + ane_h16_session_release(s, p); return ret; } EXPORT_SYMBOL_GPL(ane_h16_session_execute); @@ -1401,6 +1551,7 @@ int ane_h16_session_close(struct ane_h16_session *s, struct ane_h16_program *p) if (!s || !p || p->session != s) return -EINVAL; + h16_drain(s); if (p->closed || !p->created) return 0; /* @@ -1485,7 +1636,7 @@ int ane_h16_session_enter(struct ane_h16_session *s, bool nonblock) EXPORT_SYMBOL_GPL(ane_h16_session_enter); /* - * Close the session to new requests and wait for the one in flight + * Close the session to new requests and wait for every surface owner * (asleep), or reopen it. The caller cycles the firmware in between. */ void ane_h16_session_sleep(struct ane_h16_session *s, bool asleep) @@ -1493,6 +1644,10 @@ void ane_h16_session_sleep(struct ane_h16_session *s, bool asleep) struct ane_h16_program *p, *n; mutex_lock(s->lock); + /* Close admission before dropping the lock to drain every owner. */ + WRITE_ONCE(s->asleep, asleep); + if (asleep) + h16_drain(s); /* The firmware is suspended or powered off with gating on. */ if (asleep && s->gate_held && h16_gate_release(s)) s->ops->log(s->ctx, "gate release before sleep failed", (u64)-s->error, 0); diff --git a/drivers/accel/ane/ane_h16_program.h b/drivers/accel/ane/ane_h16_program.h index b00c16e9e4cc8..468e83c7101be 100644 --- a/drivers/accel/ane/ane_h16_program.h +++ b/drivers/accel/ane/ane_h16_program.h @@ -162,9 +162,9 @@ struct ane_h16_session_ops { */ void (*sync)(void *ctx, const struct ane_fw_surface *surface, bool for_device); /* - * Optional. Called with true before an EXECUTE touches the firmware - * and with false after it ended, successful or not, so a backend can - * hold a performance vote only while work is in flight. + * Optional. Called with true before the first EXECUTE touches firmware + * and false after the last one ends, successful or not. A backend can + * hold a performance vote while any request is in flight. */ void (*busy)(void *ctx, bool busy); }; @@ -194,6 +194,8 @@ struct ane_h16_program { /* Session-local identity; firmware program IDs are reused after UNLOAD. */ u64 generation; struct ane_h16_request_key key; + /* Owns the shared surfaces from copy-in through copy-out. */ + bool executing; bool created; bool closed; /* Torn down cleanly: its memory went back to the session's spares. */ @@ -248,8 +250,7 @@ void ane_h16_exec_stats_add(struct ane_h16_exec_stats *st, const struct ane_h16_exec_sample *x); /* - * Programs of one firmware session: one loaded at a time, any number per - * boot; a switch-safe transport may hold several. See ane_h16_session_load(). + * Programs of one firmware session, with private surfaces for each program. */ /* * Program memory given back by a program that the firmware unloaded. It @@ -298,13 +299,21 @@ struct ane_h16_session { u64 executed; u32 dsid; int error; + /* All admission, transport and completion state is under lock. */ + unsigned int depth; + unsigned int active; + unsigned int running; + unsigned int draining; + bool pipelined; + /* Reclaim a batch of command buffers only after its last caller ends. */ + size_t execute_mark; /* Firmware log lines printed after the last failed EXECUTE. */ unsigned int fwlog_lines; bool quarantined; /* * Dynamic power gating (0x002d) held off across back-to-back requests. - * With gate_hold_ns zero every EXECUTE opens and closes the gate itself. - * Otherwise the first EXECUTE opens it, later ones find it open, and it + * The first EXECUTE opens it and the last one closes it. With a nonzero + * gate_hold_ns, back-to-back requests find it open instead, and it * closes gate_hold_ns after the last one ended (gate_work, serialized on * lock), before TERMINATE, and before system sleep. */ @@ -327,6 +336,10 @@ int ane_h16_session_load(struct ane_h16_session *s, const void *const aux[ANE_H16_AUX_COUNT], const size_t aux_size[ANE_H16_AUX_COUNT], struct ane_h16_program **program); +/* Caller holds s->lock; acquire may drop it while waiting. */ +int ane_h16_session_acquire(struct ane_h16_session *s, struct ane_h16_program *p); +void ane_h16_session_release(struct ane_h16_session *s, struct ane_h16_program *p); +int ane_h16_session_run(struct ane_h16_session *s, struct ane_h16_program *p); int ane_h16_session_execute(struct ane_h16_session *s, struct ane_h16_program *p); int ane_h16_session_close(struct ane_h16_session *s, struct ane_h16_program *p); void ane_h16_session_put(struct ane_h16_session *s, struct ane_h16_program *p); diff --git a/drivers/accel/ane/ane_h16_program_test.c b/drivers/accel/ane/ane_h16_program_test.c index 48c64c73a1669..c19f985f312dc 100644 --- a/drivers/accel/ane/ane_h16_program_test.c +++ b/drivers/accel/ane/ane_h16_program_test.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT #include #include +#include +#include +#include #include #include "ane_h16_boot.h" @@ -27,6 +30,8 @@ enum fw_mode { FW_REPORT_STALL, /* State 0 at once, then states 3 and 1 after late_polls sleeps. */ FW_REPORT_LATE, + /* Reports and the clock are driven by the test under the session mutex. */ + FW_REPORT_PIPELINE, }; /* A synchronous fake firmware that answers on each doorbell. */ @@ -55,6 +60,8 @@ struct prog_fw { u8 exec[0xd00]; size_t exec_length; u32 exec_flags[32]; + struct ane_h16_request_key exec_keys[32]; + wait_queue_head_t pipeline_wake; unsigned int execs; u8 load[ANE_H16_LOAD_SIZE]; unsigned int maps, writable_maps; @@ -125,10 +132,17 @@ static void fw_execute(struct prog_fw *f, const u8 *cmd) u64 uuid = get_unaligned_le64(cmd + 0x20); u32 program = get_unaligned_le32(cmd + 8), process = get_unaligned_le32(cmd + 0xc); - if (f->execs < ARRAY_SIZE(f->exec_flags)) + if (f->execs < ARRAY_SIZE(f->exec_flags)) { f->exec_flags[f->execs] = get_unaligned_le32(cmd + ANE_H16_EXECUTE_FLAGS); + f->exec_keys[f->execs] = (struct ane_h16_request_key) { + .uuid = uuid, .program = program, .process = process, + }; + } f->execs++; + wake_up_all(&f->pipeline_wake); switch (f->mode) { + case FW_REPORT_PIPELINE: + break; case FW_REPORT_FOREIGN_UUID: fw_report(f, uuid + 100, program, process, 0); fw_report(f, uuid + 100, program, process, 1); @@ -258,6 +272,10 @@ static void fw_relax(void *ctx, u64 waited_ns) { struct prog_fw *f = ctx; + if (f->mode == FW_REPORT_PIPELINE) { + usleep_range(50, 100); + return; + } f->now += 10; if (f->late_uuid && !--f->late_polls) { fw_report(f, f->late_uuid, f->late_program, f->late_process, 3); @@ -382,6 +400,7 @@ static struct prog_fw *fw_create_family(struct kunit *test, unsigned int family) if (!f) return NULL; f->test = test; + init_waitqueue_head(&f->pipeline_wake); f->soc.chip_family = family; f->soc.hwx_subtype = family == 17 ? ANE_HWX_SUBTYPE_H17 : ANE_HWX_SUBTYPE_H16; f->soc.doorbell = 0x1884000; @@ -991,7 +1010,7 @@ static void program_session_test(struct kunit *test) }; static const u32 gates[] = { 0, 0, 0, 0, 1, 0, 0, 1 }; struct prog_fw *f = fw_create(test); - struct ane_h16_program *p = NULL, *second = NULL, *third = NULL; + struct ane_h16_program *p = NULL, *second = NULL; unsigned int i; KUNIT_ASSERT_NOT_NULL(test, f); @@ -1036,11 +1055,6 @@ static void program_session_test(struct kunit *test) /* Later requests of the same program take the direct path. */ KUNIT_EXPECT_EQ(test, get_unaligned_le32(f->exec + 0x30), 0); - /* A second LOAD while the first is loaded refuses, before any traffic. */ - i = f->count; - KUNIT_EXPECT_EQ(test, fw_load_program(f, &second), -EBUSY); - KUNIT_EXPECT_EQ(test, f->count, i); - KUNIT_EXPECT_PTR_EQ(test, second, NULL); KUNIT_EXPECT_EQ(test, ane_h16_session_close(&f->s, p), 0); KUNIT_EXPECT_TRUE(test, p->closed); @@ -1064,10 +1078,7 @@ static void program_session_test(struct kunit *test) KUNIT_EXPECT_EQ(test, get_unaligned_le32(f->exec + 0x30), ANE_H16_EXECUTE_FLAG_QUEUED); KUNIT_ASSERT_EQ(test, ane_h16_session_execute(&f->s, second), 0); KUNIT_EXPECT_EQ(test, get_unaligned_le32(f->exec + 0x30), 0); - i = f->count; - KUNIT_EXPECT_EQ(test, fw_load_program(f, &third), -EBUSY); - KUNIT_EXPECT_EQ(test, f->count, i); - KUNIT_EXPECT_PTR_EQ(test, third, NULL); + KUNIT_EXPECT_EQ(test, ane_h16_session_close(&f->s, second), 0); /* Closing the first program's file late is harmless. */ KUNIT_EXPECT_EQ(test, ane_h16_session_close(&f->s, p), 0); @@ -1700,7 +1711,7 @@ static void program_h17_mobilenet_test(struct kunit *test) /* * An H17 session switches between programs: a second LOAD succeeds, and * every EXECUTE that follows a different program, a LOAD or a CREATE is - * queued. H16 keeps one program lifetime, and a program built for the other + * queued. A program built for the other * engine is refused before any traffic. */ static void program_h17_switch_test(struct kunit *test) @@ -2224,7 +2235,412 @@ static void program_sleep_replay_deferred_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, f->s.quarantined); } +/* Real concurrent callers; the fake firmware alone decides completion order. */ +struct pipeline_thread { + struct prog_fw *fw; + struct ane_h16_program *program; + struct task_struct *task; + struct completion entered; + struct completion done; + bool sleep; + int result; +}; + +static int pipeline_thread_run(void *arg) +{ + struct pipeline_thread *t = arg; + struct ane_h16_session *s = &t->fw->s; + + complete(&t->entered); + if (t->sleep) { + ane_h16_session_sleep(s, true); + } else { + mutex_lock(s->lock); + t->result = ane_h16_session_execute(s, t->program); + mutex_unlock(s->lock); + } + complete(&t->done); + /* Keep the task alive until the cleanup action calls kthread_stop(). */ + set_current_state(TASK_INTERRUPTIBLE); + while (!kthread_should_stop()) { + schedule(); + set_current_state(TASK_INTERRUPTIBLE); + } + __set_current_state(TASK_RUNNING); + return 0; +} + +/* Also recovers a failed assertion, before KUnit releases the fake's memory. */ +static void pipeline_thread_stop(void *arg) +{ + struct pipeline_thread *t = arg; + struct ane_h16_session *s = &t->fw->s; + + mutex_lock(s->lock); + if (s->active) { + s->quarantined = true; + s->error = -ECANCELED; + ane_h16_pending_fail_all(&s->pending, -ECANCELED); + } + s->asleep = false; + wake_up_all(&s->wake); + mutex_unlock(s->lock); + kthread_stop(t->task); + cancel_delayed_work_sync(&s->gate_work); +} + +static struct pipeline_thread *pipeline_start(struct kunit *test, struct prog_fw *f, + struct ane_h16_program *p) +{ + struct pipeline_thread *t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); + + if (!t) + return NULL; + t->fw = f; + t->program = p; + t->sleep = !p; + init_completion(&t->entered); + init_completion(&t->done); + t->task = kthread_run(pipeline_thread_run, t, "ane-pipeline-test"); + if (IS_ERR(t->task)) + return NULL; + if (kunit_add_action_or_reset(test, pipeline_thread_stop, t)) + return NULL; + if (!wait_for_completion_timeout(&t->entered, HZ)) + return NULL; + return t; +} + +static struct prog_fw *pipeline_create(struct kunit *test, unsigned int family, + struct ane_h16_program **a, + struct ane_h16_program **b) +{ + struct prog_fw *f = fw_create_family(test, family); + struct mutex *lock = kunit_kzalloc(test, sizeof(*lock), GFP_KERNEL); + const void *aux[ANE_H16_AUX_COUNT]; + size_t sizes[ANE_H16_AUX_COUNT]; + int ret; + + if (!f || !lock) + return NULL; + if (family == 16) { + ret = fw_load_program(f, a); + if (!ret) + ret = fw_load_program(f, b); + } else { + mobilenet_sections(test, aux, sizes); + ret = ane_h16_session_load(&f->s, mobilenet_snapshot(test), aux, sizes, a); + if (!ret) + ret = ane_h16_session_load(&f->s, mobilenet_snapshot(test), aux, sizes, b); + } + if (ret) + return NULL; + mutex_init(lock); + f->s.lock = lock; + f->s.timeout_ns = NSEC_PER_SEC; + f->mode = FW_REPORT_PIPELINE; + return f; +} + +static bool pipeline_submitted(struct prog_fw *f, unsigned int count) +{ + return wait_event_timeout(f->pipeline_wake, READ_ONCE(f->execs) >= count, HZ); +} + +static void pipeline_complete(struct prog_fw *f, unsigned int index, u32 state) +{ + const struct ane_h16_request_key *key = &f->exec_keys[index]; + + mutex_lock(f->s.lock); + fw_report(f, key->uuid, key->program, key->process, state); + mutex_unlock(f->s.lock); +} + +static void pipeline_expect_empty(struct kunit *test, struct prog_fw *f) +{ + unsigned int i; + + KUNIT_EXPECT_EQ(test, f->s.active, 0U); + KUNIT_EXPECT_EQ(test, f->s.running, 0U); + KUNIT_EXPECT_EQ(test, f->busy_on, 1U); + KUNIT_EXPECT_EQ(test, f->busy_off, 1U); + KUNIT_EXPECT_EQ(test, f->busy_depth, 0); + for (i = 0; i < ANE_H16_PENDING_MAX; i++) + KUNIT_EXPECT_PTR_EQ(test, f->s.pending.slots[i], NULL); +} + +/* B completes while A remains pending; neither its arena nor gate is released. */ +static void program_pipeline_out_of_order_test(struct kunit *test) +{ + unsigned int family; + + for (family = 16; family <= 17; family++) { + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, family, &a, &b); + struct pipeline_thread *ta, *tb; + size_t mark, used; + + KUNIT_ASSERT_NOT_NULL(test, f); + mark = f->t.pool_used; + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + tb = pipeline_start(test, f, b); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + mutex_lock(f->s.lock); + used = f->t.pool_used; + KUNIT_EXPECT_EQ(test, f->s.active, 2U); + KUNIT_EXPECT_EQ(test, f->busy_on, 1U); + KUNIT_EXPECT_EQ(test, f->busy_off, 0U); + KUNIT_EXPECT_EQ(test, ane_h16_session_gate_expire(&f->s), -EAGAIN); + mutex_unlock(f->s.lock); + KUNIT_EXPECT_NE(test, f->exec_keys[0].uuid, f->exec_keys[1].uuid); + KUNIT_EXPECT_EQ(test, f->exec_flags[1], ANE_H16_EXECUTE_FLAG_QUEUED); + pipeline_complete(f, 1, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, tb->result, 0); + KUNIT_EXPECT_FALSE(test, completion_done(&ta->done)); + mutex_lock(f->s.lock); + KUNIT_EXPECT_TRUE(test, f->s.gate_held); + KUNIT_EXPECT_EQ(test, f->t.pool_used, used); + KUNIT_EXPECT_EQ(test, f->busy_off, 0U); + mutex_unlock(f->s.lock); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, 0); + pipeline_expect_empty(test, f); + KUNIT_EXPECT_EQ(test, f->t.pool_used, mark); + KUNIT_EXPECT_FALSE(test, f->s.gate_held); + /* Completion order invalidates the speculative direct BAR context. */ + KUNIT_EXPECT_FALSE(test, f->t.bar_known); + } +} + +/* A second user of the same surfaces cannot publish until the first returns. */ +static void program_pipeline_same_program_test(struct kunit *test) +{ + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *ta, *tb; + + KUNIT_ASSERT_NOT_NULL(test, f); + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + tb = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_EXPECT_EQ(test, wait_event_timeout(f->pipeline_wake, + READ_ONCE(f->execs) >= 2, + msecs_to_jiffies(20)), 0L); + KUNIT_EXPECT_FALSE(test, completion_done(&tb->done)); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + pipeline_complete(f, 1, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, 0); + KUNIT_EXPECT_EQ(test, tb->result, 0); + KUNIT_EXPECT_EQ(test, f->busy_max, 1); + KUNIT_EXPECT_EQ(test, f->s.active, 0U); +} + +/* A third, distinct program waits for a slot, then overlaps the survivor. */ +static void program_pipeline_bound_test(struct kunit *test) +{ + struct ane_h16_program *a, *b, *c = NULL; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *ta, *tb, *tc; + int ret; + + KUNIT_ASSERT_NOT_NULL(test, f); + mutex_lock(f->s.lock); + ret = fw_load_program(f, &c); + mutex_unlock(f->s.lock); + KUNIT_ASSERT_EQ(test, ret, 0); + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + tb = pipeline_start(test, f, b); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + tc = pipeline_start(test, f, c); + KUNIT_ASSERT_NOT_NULL(test, tc); + KUNIT_EXPECT_EQ(test, wait_event_timeout(f->pipeline_wake, + READ_ONCE(f->execs) >= 3, + msecs_to_jiffies(20)), 0L); + KUNIT_EXPECT_FALSE(test, completion_done(&tc->done)); + pipeline_complete(f, 1, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 3)); + KUNIT_EXPECT_FALSE(test, completion_done(&ta->done)); + pipeline_complete(f, 2, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tc->done, HZ), 0UL); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, 0); + KUNIT_EXPECT_EQ(test, tb->result, 0); + KUNIT_EXPECT_EQ(test, tc->result, 0); + pipeline_expect_empty(test, f); +} + +/* Arena pressure drains a batch rather than failing a long-running pipeline. */ +static void program_pipeline_arena_pressure_test(struct kunit *test) +{ + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *ta, *tb; + size_t mark; + + KUNIT_ASSERT_NOT_NULL(test, f); + mark = f->t.pool_used; + /* Room for one sequence and its teardown, but not a second command. */ + f->t.pool.size = mark + 0xe00; + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + tb = pipeline_start(test, f, b); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_EXPECT_EQ(test, wait_event_timeout(f->pipeline_wake, + READ_ONCE(f->execs) >= 2, + msecs_to_jiffies(20)), 0L); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + pipeline_complete(f, 1, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, 0); + KUNIT_EXPECT_EQ(test, tb->result, 0); + KUNIT_EXPECT_EQ(test, f->s.active, 0U); + KUNIT_EXPECT_EQ(test, f->t.pool_used, mark); + KUNIT_EXPECT_EQ(test, f->busy_on, 2U); + KUNIT_EXPECT_EQ(test, f->busy_off, 2U); +} + +/* Copy-out retains ownership after the terminal report and busy vote end. */ +static void program_pipeline_surface_owner_test(struct kunit *test) +{ + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *t; + int ret; + + KUNIT_ASSERT_NOT_NULL(test, f); + /* Emulate the ioctl between its acquire and run, before copy-in. */ + mutex_lock(f->s.lock); + ret = ane_h16_session_acquire(&f->s, a); + mutex_unlock(f->s.lock); + KUNIT_ASSERT_EQ(test, ret, 0); + t = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, t); + KUNIT_EXPECT_EQ(test, wait_event_timeout(f->pipeline_wake, + READ_ONCE(f->execs) >= 1, + msecs_to_jiffies(20)), 0L); + /* Copy-out uses the same ownership; no firmware need be running. */ + mutex_lock(f->s.lock); + KUNIT_EXPECT_EQ(test, f->s.running, 0U); + ane_h16_session_release(&f->s, a); + mutex_unlock(f->s.lock); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&t->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, t->result, 0); + pipeline_expect_empty(test, f); +} + +/* A timeout or malformed report fails both waiters and retains the whole arena. */ +static void program_pipeline_fault(struct kunit *test, bool timeout) +{ + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *ta, *tb; + size_t mark; + int error = timeout ? -ETIMEDOUT : -EPROTO; + + KUNIT_ASSERT_NOT_NULL(test, f); + mark = f->t.pool_used; + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + /* Only A expires; B's deadline remains a full second later. */ + mutex_lock(f->s.lock); + f->now += NSEC_PER_MSEC; + mutex_unlock(f->s.lock); + tb = pipeline_start(test, f, b); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + mutex_lock(f->s.lock); + if (timeout) { + f->now = NSEC_PER_SEC; + } else { + const struct ane_h16_request_key *key = &f->exec_keys[0]; + + fw_report(f, key->uuid, key->program, key->process + 1, 1); + } + mutex_unlock(f->s.lock); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, error); + KUNIT_EXPECT_EQ(test, tb->result, error); + KUNIT_EXPECT_TRUE(test, f->s.quarantined); + KUNIT_EXPECT_GT(test, f->t.pool_used, mark); + pipeline_expect_empty(test, f); +} + +static void program_pipeline_timeout_test(struct kunit *test) +{ + program_pipeline_fault(test, true); +} + +static void program_pipeline_quarantine_test(struct kunit *test) +{ + program_pipeline_fault(test, false); +} + +/* Sleep closes admission, then waits for both callers before closing the gate. */ +static void program_pipeline_sleep_test(struct kunit *test) +{ + struct ane_h16_program *a, *b; + struct prog_fw *f = pipeline_create(test, 16, &a, &b); + struct pipeline_thread *ta, *tb, *sleep; + unsigned int tries; + + KUNIT_ASSERT_NOT_NULL(test, f); + ta = pipeline_start(test, f, a); + KUNIT_ASSERT_NOT_NULL(test, ta); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 1)); + tb = pipeline_start(test, f, b); + KUNIT_ASSERT_NOT_NULL(test, tb); + KUNIT_ASSERT_TRUE(test, pipeline_submitted(f, 2)); + sleep = pipeline_start(test, f, NULL); + KUNIT_ASSERT_NOT_NULL(test, sleep); + for (tries = 0; tries < 100 && !READ_ONCE(f->s.asleep); tries++) + usleep_range(100, 200); + KUNIT_ASSERT_TRUE(test, READ_ONCE(f->s.asleep)); + KUNIT_EXPECT_FALSE(test, completion_done(&sleep->done)); + pipeline_complete(f, 0, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&ta->done, HZ), 0UL); + KUNIT_EXPECT_FALSE(test, completion_done(&sleep->done)); + pipeline_complete(f, 1, 1); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&tb->done, HZ), 0UL); + KUNIT_ASSERT_NE(test, wait_for_completion_timeout(&sleep->done, HZ), 0UL); + KUNIT_EXPECT_EQ(test, ta->result, 0); + KUNIT_EXPECT_EQ(test, tb->result, 0); + KUNIT_EXPECT_TRUE(test, f->s.asleep); + KUNIT_EXPECT_FALSE(test, f->s.gate_held); + pipeline_expect_empty(test, f); + ane_h16_session_sleep(&f->s, false); +} + static struct kunit_case program_cases[] = { + KUNIT_CASE(program_pipeline_out_of_order_test), + KUNIT_CASE(program_pipeline_same_program_test), + KUNIT_CASE(program_pipeline_bound_test), + KUNIT_CASE(program_pipeline_arena_pressure_test), + KUNIT_CASE(program_pipeline_surface_owner_test), + KUNIT_CASE(program_pipeline_timeout_test), + KUNIT_CASE(program_pipeline_quarantine_test), + KUNIT_CASE(program_pipeline_sleep_test), KUNIT_CASE(program_sleep_replay_test), KUNIT_CASE(program_sleep_nonblock_test), KUNIT_CASE(program_sleep_replay_failure_test), From 2f9be42ff7efc4c0b954f8e855978d5567a2484e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:48:06 +1100 Subject: [PATCH 072/342] usb: core: arm remote wakeup for every function of a USB 3 device A USB 3 device enables remote wakeup per function: the host arms each function with SET_FEATURE(FUNCTION_SUSPEND) addressed to the first interface of that function (USB 3.2, 9.4.9). usb_enable_remote_wakeup() only ever sent it to interface 0 and carried a FIXME for devices whose interface association descriptors show more than one function. Docks are such devices. The Plugable UD-ULTC4K (DisplayLink 17e9:6011) has a vendor display function at interface 0, DFU at 1, UAC2 audio at 2-4 and its CDC NCM Ethernet at 5-6. With wakeup enabled on the dock, only the display function was armed, and a magic packet to its Ethernet never woke the host from suspend-to-idle (0 of 2 on an M4 Pro MacBook Pro; with this change 6 of 6 wake within 0.6 s). Send FUNCTION_SUSPEND to the first interface of every function: the bFirstInterface of each association, and every interface outside one. Do the same when disarming, so that on resume every function leaves function suspend. The status of the request to the first interface is still the return value. A failure on another function is only logged, so a device that rejects the request there keeps working as it did. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/usb/core/hub.c | 69 +++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 7c5d5db928b11..dc8adbd34d09e 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3708,15 +3708,62 @@ void usb_enable_ltm(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_enable_ltm); +/* + * usb_set_function_suspend - send FUNCTION_SUSPEND to every function + * @udev: target USB-3 device + * @options: USB_INTRF_FUNC_SUSPEND_* bits, 0 to leave function suspend + * + * A USB-3 device enables remote wakeup per function: the host arms it with a + * FUNCTION_SUSPEND request to the first interface of each function (USB 3.2, + * sections 9.4.9 and 9.2.5.2). An interface association descriptor groups + * the interfaces of one function; an interface outside any association is a + * function of its own. A composite device such as a dock with a display, an + * audio and a network function signals remote wakeup only for the functions + * that were armed. + * + * Return: the status of the request to the device's first interface. The + * other functions only log a failure: older code armed just the first + * interface, and a device that refuses the request elsewhere must keep + * working as before. + */ +static int usb_set_function_suspend(struct usb_device *udev, u16 options) +{ + struct usb_host_config *config = udev->actconfig; + int i, ret, status = -ENODEV; + + if (!config) + return status; + + for (i = 0; i < config->desc.bNumInterfaces; i++) { + struct usb_interface *intf = config->interface[i]; + struct usb_interface_assoc_descriptor *iad = intf->intf_assoc; + u8 ifnum = intf->altsetting[0].desc.bInterfaceNumber; + + if (iad && iad->bFirstInterface != ifnum) + continue; + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, + USB_INTRF_FUNC_SUSPEND, options | ifnum, + NULL, 0, USB_CTRL_SET_TIMEOUT); + if (i == 0) + status = ret; + else if (ret < 0) + dev_dbg(&udev->dev, + "function suspend 0x%04x of interface %u failed: %d\n", + options, ifnum, ret); + } + + return status; +} + /* * usb_enable_remote_wakeup - enable remote wakeup for a device * @udev: target device * * For USB-2 devices: Set the device's remote wakeup feature. * - * For USB-3 devices: Assume there's only one function on the device and - * enable remote wake for the first interface. FIXME if the interface - * association descriptor shows there's more than one function. + * For USB-3 devices: Enable remote wake for every function of the device. */ static int usb_enable_remote_wakeup(struct usb_device *udev) { @@ -3726,12 +3773,9 @@ static int usb_enable_remote_wakeup(struct usb_device *udev) USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); else - return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), - USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, - USB_INTRF_FUNC_SUSPEND, + return usb_set_function_suspend(udev, USB_INTRF_FUNC_SUSPEND_RW | - USB_INTRF_FUNC_SUSPEND_LP, - NULL, 0, USB_CTRL_SET_TIMEOUT); + USB_INTRF_FUNC_SUSPEND_LP); } /* @@ -3740,9 +3784,7 @@ static int usb_enable_remote_wakeup(struct usb_device *udev) * * For USB-2 devices: Clear the device's remote wakeup feature. * - * For USB-3 devices: Assume there's only one function on the device and - * disable remote wake for the first interface. FIXME if the interface - * association descriptor shows there's more than one function. + * For USB-3 devices: Disable remote wake for every function of the device. */ static int usb_disable_remote_wakeup(struct usb_device *udev) { @@ -3752,10 +3794,7 @@ static int usb_disable_remote_wakeup(struct usb_device *udev) USB_DEVICE_REMOTE_WAKEUP, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); else - return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), - USB_REQ_SET_FEATURE, USB_RECIP_INTERFACE, - USB_INTRF_FUNC_SUSPEND, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); + return usb_set_function_suspend(udev, 0); } /* Count of wakeup-enabled devices at or below udev */ From 2a1242b03b5b76b44d5a0757e914790ed471b9b6 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:48:09 +1100 Subject: [PATCH 073/342] net: usb: cdc_ncm: Wake-on-LAN for the Plugable UD-ULTC4K dock The Ethernet function of the Plugable UD-ULTC4K (DisplayLink 17e9:6011) wakes the host on a magic packet addressed to it while it is suspended with remote wakeup enabled. It does not wake on other traffic: unicast pings, broadcast and multicast UDP, and a magic packet carrying another station address all leave the host asleep. cdc_ncm had no ethtool WoL operations, so "ethtool -s wol g" failed and NetworkManager's wake-on-lan setting could not be applied. Its CDC Ethernet descriptor lists 8 power management pattern filters, but the function stalls SET and GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER for every filter, so generic pattern-filter WoL cannot be used with it. The magic packet match is built into the function. Add CDC_NCM_FLAG_WAKE_ON_MAGIC for such functions, pass the driver_info data of cdc_ncm devices on as their driver flags, and give the dock its own entry ahead of the DisplayLink vendor match. With the flag, get_wol/set_wol report WAKE_MAGIC and map it to the remote wakeup setting of the USB device, which is what arms the match. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/net/usb/cdc_ncm.c | 66 ++++++++++++++++++++++++++++++++++++- include/linux/usb/cdc_ncm.h | 1 + 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index 35db38cb3e4a2..04d367d7fbc4d 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -133,7 +133,44 @@ static void cdc_ncm_get_strings(struct net_device __always_unused *netdev, u32 s static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx); +/* + * Wake-on-LAN for functions known to wake the host on a magic packet while + * they are suspended with remote wakeup enabled (CDC_NCM_FLAG_WAKE_ON_MAGIC). + * Such a function matches the magic packet by itself, so WAKE_MAGIC is the + * remote wakeup setting of the USB device (power/wakeup in sysfs). + */ +static void cdc_ncm_get_wol(struct net_device *net, struct ethtool_wolinfo *wol) +{ + struct usbnet *dev = netdev_priv(net); + struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + + if (!(ctx->drvflags & CDC_NCM_FLAG_WAKE_ON_MAGIC)) + return; + + wol->supported = WAKE_MAGIC; + if (device_may_wakeup(&dev->udev->dev)) + wol->wolopts = WAKE_MAGIC; +} + +static int cdc_ncm_set_wol(struct net_device *net, struct ethtool_wolinfo *wol) +{ + struct usbnet *dev = netdev_priv(net); + struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; + bool enable = wol->wolopts & WAKE_MAGIC; + + if (!(ctx->drvflags & CDC_NCM_FLAG_WAKE_ON_MAGIC)) + return -EOPNOTSUPP; + if (wol->wolopts & ~WAKE_MAGIC) + return -EINVAL; + + if (device_may_wakeup(&dev->udev->dev) == enable) + return 0; + return device_set_wakeup_enable(&dev->udev->dev, enable); +} + static const struct ethtool_ops cdc_ncm_ethtool_ops = { + .get_wol = cdc_ncm_get_wol, + .set_wol = cdc_ncm_set_wol, .get_link = usbnet_get_link, .nway_reset = usbnet_nway_reset, .get_drvinfo = usbnet_get_drvinfo, @@ -1074,7 +1111,8 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf) * Additionally, generic NCM devices are assumed to accept arbitrarily * placed NDP. */ - return cdc_ncm_bind_common(dev, intf, CDC_NCM_DATA_ALTSETTING_NCM, 0); + return cdc_ncm_bind_common(dev, intf, CDC_NCM_DATA_ALTSETTING_NCM, + dev->driver_info->data); } static void cdc_ncm_align_tail(struct sk_buff *skb, size_t modulus, size_t remainder, size_t max) @@ -1939,6 +1977,26 @@ static const struct driver_info cdc_ncm_zlp_info = { .set_rx_mode = cdc_ncm_update_filter, }; +/* + * Same as cdc_ncm_zlp_info, for DisplayLink docks whose Ethernet wakes the + * host on a magic packet. Their CDC Ethernet descriptor lists power + * management pattern filters, but the function stalls the requests that + * load them; the magic packet match is built in. + */ +static const struct driver_info cdc_ncm_displaylink_wol_info = { + .description = "CDC NCM (SEND ZLP)", + .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET + | FLAG_LINK_INTR | FLAG_ETHER | FLAG_SEND_ZLP, + .bind = cdc_ncm_bind, + .unbind = cdc_ncm_unbind, + .manage_power = usbnet_manage_power, + .status = cdc_ncm_status, + .rx_fixup = cdc_ncm_rx_fixup, + .tx_fixup = cdc_ncm_tx_fixup, + .set_rx_mode = cdc_ncm_update_filter, + .data = CDC_NCM_FLAG_WAKE_ON_MAGIC, +}; + /* Same as cdc_ncm_info, but with FLAG_SEND_ZLP */ static const struct driver_info apple_tethering_interface_info = { .description = "CDC NCM (Apple Tethering)", @@ -2111,6 +2169,12 @@ static const struct usb_device_id cdc_devs[] = { }, /* DisplayLink docking stations */ + /* Plugable UD-ULTC4K: wakes the host on a magic packet */ + { USB_DEVICE_AND_INTERFACE_INFO(0x17e9, 0x6011, + USB_CLASS_COMM, + USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE), + .driver_info = (unsigned long)&cdc_ncm_displaylink_wol_info, + }, { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | USB_DEVICE_ID_MATCH_VENDOR, .idVendor = 0x17e9, diff --git a/include/linux/usb/cdc_ncm.h b/include/linux/usb/cdc_ncm.h index 97ef37a1ff4ac..2114b5ef66ef2 100644 --- a/include/linux/usb/cdc_ncm.h +++ b/include/linux/usb/cdc_ncm.h @@ -88,6 +88,7 @@ #define CDC_NCM_FLAG_NDP_TO_END 0x02 /* NDP is placed at end of frame */ #define CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE 0x04 /* Avoid altsetting toggle during init */ #define CDC_NCM_FLAG_PREFER_NTB32 0x08 /* prefer NDP32 over NDP16 */ +#define CDC_NCM_FLAG_WAKE_ON_MAGIC 0x10 /* wakes the host on a magic packet */ #define cdc_ncm_comm_intf_is_mbim(x) ((x)->desc.bInterfaceSubClass == USB_CDC_SUBCLASS_MBIM && \ (x)->desc.bInterfaceProtocol == USB_CDC_PROTO_NONE) From 76b09427c2295ca237e5253c6dcd6f54427bef9f Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sun, 8 Nov 2026 06:15:05 -0500 Subject: [PATCH 074/342] drm/apple: Fix a GPU fence that never signals wedging the display drm_atomic_helper_commit() waits for every plane's in-fence with dma_fence_wait() and no timeout: in the commit worker before the driver's commit tail, and, for blocking commits, before the swap. The in-fence is the scanout buffer's implicit write fence (zink imports its GPU job's fence into each exported dma-buf) or the compositor's IN_FENCE_FD. When a GPU fence never signals, after a GPU recovery for example, the worker sleeps for good: commit_planes() never runs, no swap reaches DCP, the commit's flip event never comes, and every later nonblocking commit fails with -EBUSY (stall_checks(), only a debug message). The 10 s flip_done timeout is never reached, so nothing is logged. The panel stays black across compositor restarts, which see "Cannot commit when a page-flip is awaiting", until a reboot. Commit through a copy of drm_atomic_helper_commit() whose fence wait is bounded: all of a commit's planes share one second, and a fence that does not signal in time is dropped with a rate-limited warning naming its driver and timeline. The buffer is scanned out as it is, so a GPU bug costs a stale or torn frame instead of the panel. The copy keeps the helper's sequence (setup, prepare, the interruptible pre-swap wait for blocking commits, swap, the worker's wait for dependencies, the tail, cleanup) and its fence deadline hint, and leaves out only the self-refresh accounting, which this driver does not use. Once the commit goes on, its flip completes as usual. If DCP then does not complete the swap within drm_atomic_helper_wait_for_flip_done()'s 10 s, the commit's event stayed pending and a compositor would still wait for it before committing again. Send that event as failed (-ETIMEDOUT on its out-fence) after the wait; only the event that belongs to this commit is sent. The commit then leaves its CRTC's list at cleanup_done as before, so later nonblocking commits are not held by it either. Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- drivers/gpu/drm/apple/apple_drv.c | 201 +++++++++++++++++++++++++++++- drivers/gpu/drm/apple/dcp.c | 18 +++ drivers/gpu/drm/apple/dcp.h | 2 + 3 files changed, 220 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 763ba82ad29ac..fbd0325b963d2 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include #include @@ -18,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -562,12 +565,206 @@ static void apple_atomic_state_free(struct drm_atomic_commit *state) kfree(to_apple_atomic_state(state)); } +/* + * A plane's in-fence (its buffer's implicit write fence, or the compositor's + * IN_FENCE_FD) is waited for at most this long per commit. The helpers wait + * for it without a timeout: a GPU fence that never signals, after a GPU + * recovery for example, leaves the commit worker asleep for good. No later + * frame reaches the display, the commit's flip event never comes, and every + * later nonblocking commit fails with -EBUSY. One second is many frames even + * at the panel's slowest refresh; past it the buffer is scanned out as it is, + * so a GPU bug costs a stale or torn frame instead of the panel. + */ +#define APPLE_PLANE_FENCE_TIMEOUT_MS 1000 + +static void apple_warn_fence_timeout(struct drm_device *dev, + struct drm_plane *plane, + struct dma_fence *fence) +{ + static DEFINE_RATELIMIT_STATE(rs, 60 * HZ, 1); + const char __rcu *driver; + const char __rcu *timeline; + + if (!__ratelimit(&rs)) + return; + rcu_read_lock(); + driver = dma_fence_driver_name(fence); + timeline = dma_fence_timeline_name(fence); + drm_warn(dev, + "[PLANE:%d:%s] in-fence %s:%s seqno %llu not signalled after %u ms, scanning out without it\n", + plane->base.id, plane->name, rcu_dereference(driver), + rcu_dereference(timeline), fence->seqno, + APPLE_PLANE_FENCE_TIMEOUT_MS); + rcu_read_unlock(); +} + +/* As the helpers do: the GPU may finish the frame sooner knowing the vblank. */ +static void apple_set_fence_deadline(struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new_crtc_state; + struct drm_plane_state *new_plane_state; + struct drm_plane *plane; + struct drm_crtc *crtc; + ktime_t vbltime = 0; + int i; + + for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { + ktime_t v; + + if (drm_atomic_crtc_needs_modeset(new_crtc_state) || + !new_crtc_state->active || + drm_crtc_next_vblank_start(crtc, &v)) + continue; + if (!vbltime || ktime_before(v, vbltime)) + vbltime = v; + } + if (!vbltime) + return; + for_each_new_plane_in_state(state, plane, new_plane_state, i) + if (new_plane_state->fence) + dma_fence_set_deadline(new_plane_state->fence, vbltime); +} + +/* + * drm_atomic_helper_wait_for_fences() with one bound for all of the commit's + * planes (APPLE_PLANE_FENCE_TIMEOUT_MS). A fence that does not signal in time + * is dropped. Before the swap (blocking commits) the wait is interruptible, + * as the helper's is. + */ +static int apple_wait_for_fences(struct drm_device *dev, + struct drm_atomic_commit *state, + bool pre_swap) +{ + unsigned long deadline = + jiffies + msecs_to_jiffies(APPLE_PLANE_FENCE_TIMEOUT_MS); + struct drm_plane_state *new_plane_state; + struct drm_plane *plane; + int i; + + apple_set_fence_deadline(state); + + for_each_new_plane_in_state(state, plane, new_plane_state, i) { + struct dma_fence *fence = new_plane_state->fence; + long left, ret; + + if (!fence) + continue; + + WARN_ON(!new_plane_state->fb); + + left = time_before(jiffies, deadline) ? deadline - jiffies : 0; + ret = dma_fence_wait_timeout(fence, pre_swap, left); + if (ret < 0) + return ret; + if (!ret) + apple_warn_fence_timeout(dev, plane, fence); + + dma_fence_put(fence); + new_plane_state->fence = NULL; + } + + return 0; +} + +/* + * A flip DCP did not complete within the helper's 10 s + * (drm_atomic_helper_wait_for_flip_done() gave up) leaves its event pending. + * A compositor waits for that event before it commits again, so send it now, + * with -ETIMEDOUT on its out-fence, and the next commit can go ahead. A swap + * completion that still comes later finds no event. + */ +static void apple_fail_lost_flips(struct drm_atomic_commit *state) +{ + for (int i = 0; i < state->dev->mode_config.num_crtc; i++) { + struct drm_crtc_commit *commit = state->crtcs[i].commit; + struct drm_crtc *crtc = state->crtcs[i].ptr; + + if (!crtc || !commit || t8132_ext_crtc(crtc) || + completion_done(&commit->flip_done)) + continue; + dcp_drm_crtc_flip_lost(to_apple_crtc(crtc), &commit->flip_done, + -ETIMEDOUT); + } +} + +static void apple_atomic_commit_tail(struct drm_atomic_commit *state); + +/* The helper's commit_tail() with the bounded fence wait. */ +static void apple_commit_tail(struct drm_atomic_commit *state) +{ + apple_wait_for_fences(state->dev, state, false); + drm_atomic_helper_wait_for_dependencies(state); + apple_atomic_commit_tail(state); + drm_atomic_helper_commit_cleanup_done(state); + drm_atomic_commit_put(state); +} + +static void apple_commit_work(struct work_struct *work) +{ + apple_commit_tail(container_of(work, struct drm_atomic_commit, + commit_work)); +} + +/* + * drm_atomic_helper_commit() with apple_wait_for_fences() in place of the + * helper's unbounded wait. The driver keeps no self-refresh state, so the + * helper's self-refresh accounting is left out. + */ +static int apple_atomic_commit(struct drm_device *dev, + struct drm_atomic_commit *state, bool nonblock) +{ + int ret; + + if (state->async_update) { + ret = drm_atomic_helper_prepare_planes(dev, state); + if (ret) + return ret; + + drm_atomic_helper_async_commit(dev, state); + drm_atomic_helper_unprepare_planes(dev, state); + + return 0; + } + + ret = drm_atomic_helper_setup_commit(state, nonblock); + if (ret) + return ret; + + INIT_WORK(&state->commit_work, apple_commit_work); + + ret = drm_atomic_helper_prepare_planes(dev, state); + if (ret) + return ret; + + if (!nonblock) { + ret = apple_wait_for_fences(dev, state, true); + if (ret) + goto err; + } + + ret = drm_atomic_helper_swap_state(state, true); + if (ret) + goto err; + + drm_atomic_commit_get(state); + if (nonblock) + queue_work(system_dfl_wq, &state->commit_work); + else + apple_commit_tail(state); + + return 0; + +err: + drm_atomic_helper_unprepare_planes(dev, state); + return ret; +} + static const struct drm_mode_config_funcs apple_mode_config_funcs = { .atomic_state_alloc = apple_atomic_state_alloc, .atomic_state_clear = apple_atomic_state_clear, .atomic_state_free = apple_atomic_state_free, .atomic_check = drm_atomic_helper_check, - .atomic_commit = drm_atomic_helper_commit, + .atomic_commit = apple_atomic_commit, .fb_create = drm_gem_fb_create, }; @@ -600,9 +797,11 @@ static void apple_atomic_commit_tail(struct drm_atomic_commit *state) drm_atomic_helper_fake_vblank(state); drm_atomic_helper_commit_hw_done(state); drm_atomic_helper_wait_for_flip_done(state->dev, state); + apple_fail_lost_flips(state); drm_atomic_helper_cleanup_planes(state->dev, state); } +/* apple_atomic_commit() calls the tail itself; this serves other helper users. */ static const struct drm_mode_config_helper_funcs apple_mode_config_helpers = { .atomic_commit_tail = apple_atomic_commit_tail, }; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index f56c4423ea247..4669e4fb983c1 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -531,6 +531,24 @@ void dcp_drm_crtc_error(struct apple_crtc *crtc, spin_unlock_irqrestore(&drm->event_lock, flags); } +/* + * The flip of the commit whose flip_done is @flip_done never completed: send + * its still pending event as failed. Only that commit's event is sent; a newer + * commit's stays for its own swap. + */ +void dcp_drm_crtc_flip_lost(struct apple_crtc *crtc, + struct completion *flip_done, int error) +{ + unsigned long flags; + + spin_lock_irqsave(&crtc->base.dev->event_lock, flags); + if (crtc->event && crtc->event->base.completion == flip_done) { + dcp_failed_page_flip(crtc, crtc->event, error); + crtc->event = NULL; + } + spin_unlock_irqrestore(&crtc->base.dev->event_lock, flags); +} + void dcp_drm_crtc_page_flip(struct apple_dcp *dcp, ktime_t now) { unsigned long flags; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index d65367c8af13f..aaaf2918c4b75 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -88,6 +88,8 @@ void apple_crtc_vblank(struct apple_crtc *apple); void dcp_drm_crtc_vblank(struct apple_crtc *crtc); void dcp_drm_crtc_error(struct apple_crtc *crtc, struct drm_crtc_state *state, int error); +void dcp_drm_crtc_flip_lost(struct apple_crtc *crtc, + struct completion *flip_done, int error); int dcp_get_modes(struct drm_connector *connector); enum drm_mode_status dcp_mode_valid(struct drm_connector *connector, const struct drm_display_mode *mode); From 22372224854a66dd9878dccaeec103440c10366a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 01:56:54 +1100 Subject: [PATCH 075/342] accel/ane: h16: do not let a refused LOAD block every later LOAD On the J616s, one LOAD of a program whose operation section did not validate left the ANE refusing every later LOAD, from every process, with -EBUSY until reboot. ane_h16_session_load() made the program the session's (s->program) before h16_program_map() ran the binding and operation checks, and the failure path left it there, open, so the switch guard kept refusing. Run those checks, which map nothing, before the session owns the program, and free it when they fail. If a later mapping step fails, firmware has still never seen the program; mark it closed so it keeps its mappings until reset, as before, without holding the session. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_program.c | 58 ++++++++++++++++++------ drivers/accel/ane/ane_h16_program_test.c | 36 +++++++++++++++ 2 files changed, 81 insertions(+), 13 deletions(-) diff --git a/drivers/accel/ane/ane_h16_program.c b/drivers/accel/ane/ane_h16_program.c index 87cd8bb2a0b2f..eb860a3d4799d 100644 --- a/drivers/accel/ane/ane_h16_program.c +++ b/drivers/accel/ane/ane_h16_program.c @@ -668,25 +668,42 @@ static int h16_map(struct ane_h16_session *s, size_t size, bool write, return 0; } +struct h16_program_binds { + struct ane_h16_process_binding bindings[ANE_H16_SURFACES]; + struct ane_h16_process_binding scratch; + unsigned int count; +}; + +/* Pure checks of the program and its process descriptors; nothing is mapped. */ +static int h16_program_bind(const struct ane_h16_program *p, + const void *const aux[ANE_H16_AUX_COUNT], + const size_t aux_size[ANE_H16_AUX_COUNT], + struct h16_program_binds *b) +{ + int ret; + + ret = ane_h16_process_bindings(&p->hwx, aux[ANE_H16_AUX_GENERIC], + aux_size[ANE_H16_AUX_GENERIC], b->bindings, + &b->count, &b->scratch); + if (!ret) + ret = ane_h16_operation_validate(&p->snapshot, &p->hwx, + aux[ANE_H16_AUX_OPERATION], + aux_size[ANE_H16_AUX_OPERATION], + b->bindings, b->count, &b->scratch); + return ret; +} + static int h16_program_map(struct ane_h16_session *s, struct ane_h16_program *p, const void *const aux[ANE_H16_AUX_COUNT], const size_t aux_size[ANE_H16_AUX_COUNT], + struct h16_program_binds *b, struct ane_h16_load_layout *layout) { - struct ane_h16_process_binding bindings[ANE_H16_SURFACES], scratch = {}; + struct ane_h16_process_binding *bindings = b->bindings, scratch = b->scratch; const struct ane_h16_hwx *hwx = &p->hwx; - unsigned int i, j, count; + unsigned int i, j, count = b->count; int ret; - ret = ane_h16_process_bindings(hwx, aux[ANE_H16_AUX_GENERIC], - aux_size[ANE_H16_AUX_GENERIC], bindings, &count, - &scratch); - if (!ret) - ret = ane_h16_operation_validate(&p->snapshot, hwx, aux[ANE_H16_AUX_OPERATION], - aux_size[ANE_H16_AUX_OPERATION], bindings, - count, &scratch); - if (ret) - return ret; for (i = 0; i < p->plan.count; i++) { const struct ane_h16_hwx_region *r = &p->plan.regions[i]; @@ -787,6 +804,7 @@ int ane_h16_session_load(struct ane_h16_session *s, struct ane_h16_program **program) { struct ane_h16_load_layout layout = {}; + struct h16_program_binds binds = {}; struct ane_h16_program *p; u8 *command; const u8 *reply; @@ -825,6 +843,14 @@ int ane_h16_session_load(struct ane_h16_session *s, if (ret) goto free; p->snapshot = *snapshot; + /* + * Refuse a program whose process descriptors do not validate before the + * session owns it: nothing is mapped yet, so it can still be freed and + * the next LOAD is not blocked by it. + */ + ret = h16_program_bind(p, aux, aux_size, &binds); + if (ret) + goto free; /* * From the first mapping on, firmware-visible memory exists that is never * released before reset, so the program becomes the session's here and @@ -837,11 +863,17 @@ int ane_h16_session_load(struct ane_h16_session *s, memset(snapshot, 0, sizeof(*snapshot)); p->session = s; s->program = p; - ret = h16_program_map(s, p, aux, aux_size, &layout); + ret = h16_program_map(s, p, aux, aux_size, &binds, &layout); if (!ret) ret = ane_h16_load_encode(command, ANE_H16_LOAD_SIZE, p->slots); - if (ret) + if (ret) { + /* + * Firmware never saw this program. It keeps its mappings until + * reset, but it must not hold the session against the next LOAD. + */ + p->closed = true; goto out; + } ret = h16_send(s, ANE_FW_IO, command, ANE_H16_LOAD_SIZE, &reply); if (!ret) ret = ane_h16_load_reply(reply, ANE_H16_LOAD_SIZE, command, &p->key.program); diff --git a/drivers/accel/ane/ane_h16_program_test.c b/drivers/accel/ane/ane_h16_program_test.c index c19f985f312dc..bd72e34e2e1a1 100644 --- a/drivers/accel/ane/ane_h16_program_test.c +++ b/drivers/accel/ane/ane_h16_program_test.c @@ -1249,6 +1249,41 @@ static void program_bad_load_test(struct kunit *test) } } +/* + * A LOAD whose process descriptors do not validate is refused before any + * mapping or firmware traffic, and it must not block the next LOAD. + */ +static void program_bad_operation_test(struct kunit *test) +{ + struct prog_fw *f = fw_create(test); + struct ane_h16_hwx_snapshot *snapshot; + struct ane_h16_program *p = NULL; + struct ane_h16_hwx hwx; + + KUNIT_ASSERT_NOT_NULL(test, f); + snapshot = fw_snapshot(test, false, false); + KUNIT_ASSERT_NOT_NULL(test, snapshot); + KUNIT_ASSERT_EQ(test, ane_h16_hwx_validate(snapshot->bytes, snapshot->size, &hwx), 0); + test_aux_size[ANE_H16_AUX_GENERIC] = + generic_fill(test_aux[ANE_H16_AUX_GENERIC], &hwx, TEST_GENERIC_BASE); + test_aux_size[ANE_H16_AUX_OPERATION] = + operation_fill(test_aux[ANE_H16_AUX_OPERATION], snapshot, &hwx, + TEST_GENERIC_BASE); + /* One record more than the section carries. */ + put_unaligned_le32(get_unaligned_le32(test_aux[ANE_H16_AUX_OPERATION]) + 1, + test_aux[ANE_H16_AUX_OPERATION]); + KUNIT_EXPECT_EQ(test, ane_h16_session_load(&f->s, snapshot, test_aux_ptr, + test_aux_size, &p), -ENOEXEC); + KUNIT_EXPECT_PTR_EQ(test, p, NULL); + KUNIT_EXPECT_PTR_EQ(test, f->s.program, NULL); + KUNIT_EXPECT_FALSE(test, f->s.quarantined); + KUNIT_EXPECT_EQ(test, f->count, 0); + /* The refused LOAD left nothing behind: a valid one still works. */ + KUNIT_ASSERT_EQ(test, fw_load_program(f, &p), 0); + KUNIT_EXPECT_EQ(test, ane_h16_session_execute(&f->s, p), 0); + KUNIT_EXPECT_EQ(test, ane_h16_session_close(&f->s, p), 0); +} + static void program_bad_report_test(struct kunit *test) { static const enum fw_mode modes[] = { @@ -2665,6 +2700,7 @@ static struct kunit_case program_cases[] = { KUNIT_CASE(program_gate_hold_test), KUNIT_CASE(program_scratch_test), KUNIT_CASE(program_bad_load_test), + KUNIT_CASE(program_bad_operation_test), KUNIT_CASE(program_bad_report_test), KUNIT_CASE(program_stall_trace_test), KUNIT_CASE(program_timing_test), From 0ace6788393262036f3b8ee068cf8b78b074fa35 Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sun, 8 Nov 2026 06:09:55 -0500 Subject: [PATCH 076/342] drm/asahi: g17: Fix a GPU recovery failing the compositor for compute work it dropped When a GPU recovery cannot name the culprit (on M5 every firmware restart is attributed to the firmware, and classify() gives up when a guilty queue has no in-flight owner), it classifies nobody. Compute commands it dropped before they ran then come back from their queue's records as unexecuted (ENODATA), unclassified, and poisons() is true for unclassified ENODATA: the queue's terminal records the error and fails every queue of the VM, and the client's driver reads the VM status as a lost device. A Chromium GPU fault took Hyprland down this way: right after the faulting client's EIO, the log reported "GPU work of a client failed (ENODATA, ...)" for Hyprland too, and zink lost its device. The render side already handles this: groups a restart dropped are classified Spared before they fail with ENODATA. Do the same for compute: - When a compute queue's front comes back unexecuted after crossing a recovery, and the firmware reported no fault on the queue, classify every unclassified command of the queue Spared before quarantining it. All of them are ordered behind the front, so none of them ran. The queue then takes the existing spared path: its commands replay when their records prove they never ran, and otherwise fail with ENODATA without touching the VM status. - Without a recovery in between, a zero-duration record is the firmware's report of the queue's own failed command (see note_fault()). Those commands are classified Guilty and fail the VM as before. A fault report that arrives after the commands were spared as dropped reclassifies them Guilty, stops the queue from being replayed or returned to service, and queues the VM failure the report would have caused. - A compute replay that cannot be published was spared work: classify it Spared (unless guilty) before it fails with ENODATA, as dropped render groups are. - poisons(): ENODATA no longer poisons unless the command is guilty. A command that never ran cannot have faulted the GPU; a blamed render still fails with EIO, and a faulting compute command is classified Guilty first. The faulting client still fails: a blamed render fails with EIO, a watchdog timeout with ETIMEDOUT, and a reported compute fault now classifies its queue's work Guilty. What changes is only work that never ran on a queue nobody blamed. When the recovery attributes nothing, the command that was running when the firmware stopped and comes back with no record is spared too: its fence still fails with ENODATA, but its VM is not poisoned. A spared command is replayed only when its record shows it never ran, and a second fault on a replayed command is blamed on its VM (oldest_spared() counts replays), so this costs at most one more recovery. Completion::signalled() is added for note_fault(): a spared command whose fence already signalled is not reclassified. Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- drivers/gpu/drm/asahi/g17/completion.rs | 16 +++++- drivers/gpu/drm/asahi/g17/queue/compute.rs | 50 +++++++++++++++++++ .../drm/asahi/g17/runtime/compute_replay.rs | 5 ++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/completion.rs b/drivers/gpu/drm/asahi/g17/completion.rs index 0f027e7e06828..1fbe95a53c90f 100644 --- a/drivers/gpu/drm/asahi/g17/completion.rs +++ b/drivers/gpu/drm/asahi/g17/completion.rs @@ -564,9 +564,21 @@ impl Completion { self.interrupted.load(Ordering::Acquire) } - /// Whether this failure makes the VM unusable. Spared work, and interrupted - /// work no recovery found guilty, fail without poisoning it. + /// Whether the fence has been signalled (completed or failed). + pub(crate) fn signalled(&self) -> bool { + self.signalled.load(Ordering::Acquire) + } + + /// Whether this failure makes the VM unusable. Spared work, interrupted + /// work no recovery found guilty, and work that never ran (ENODATA) fail + /// without poisoning it. pub(crate) fn poisons(&self, error: Error) -> bool { + // A command that never ran cannot have faulted the GPU. The queue's own failed + // command also comes back as ENODATA (a zero-duration record); it is classified + // guilty before it fails, by the firmware's fault report or by a recovery. + if error == ENODATA && !self.guilty() { + return false; + } let interrupted = self.interrupted(); (error != ECANCELED || interrupted) && !self.spared() && !(interrupted && !self.guilty()) } diff --git a/drivers/gpu/drm/asahi/g17/queue/compute.rs b/drivers/gpu/drm/asahi/g17/queue/compute.rs index 4dab923c9e1bb..294ad42d9dc2a 100644 --- a/drivers/gpu/drm/asahi/g17/queue/compute.rs +++ b/drivers/gpu/drm/asahi/g17/queue/compute.rs @@ -467,6 +467,9 @@ struct Active { observed_at: Option, failure_deferred: bool, qos_pending: bool, + /// Spared because it came back unexecuted after a recovery ([`Queue::classify_unexecuted`]), + /// not by the recovery's own attribution. A later fault report on the queue makes it guilty. + spared_as_dropped: bool, } struct Previous> { binding: Option, @@ -698,6 +701,23 @@ impl Queue { { self.fault_stamp = Some(stamp); } + // The report can arrive after the queue's unexecuted commands were spared as dropped by + // a recovery: the failed command is among them. They are guilty, as without the + // recovery: the VM fails, and the queue is neither replayed nor returned to service. + let mut guilty = None; + for active in self.active.iter_mut().filter(|active| active.spared_as_dropped) { + active.spared_as_dropped = false; + if !active.packet.completion.signalled() { + active.packet.completion.classify(recovery::Class::Guilty); + guilty.get_or_insert_with(|| active.packet.completion.status().clone()); + } + } + if let Some(status) = guilty { + self.spared_quarantine = false; + if self.terminal.is_none() { + self.terminal = Some((status, ENODATA)); + } + } } /// The firmware failed a command of this quarantined queue, and the queue still waits for @@ -999,6 +1019,7 @@ impl Queue { let mut oldest = true; while let Some(front) = self.active.front() { let mut restart = None; + let mut crossed = false; let result = (|| { let ticket = front.ticket.ok_or(EIO)?; self.valid_ticket(front, &ticket)?; @@ -1006,6 +1027,7 @@ impl Queue { return Err(EAGAIN); } let recordless = if epoch != ticket.epoch { + crossed = true; Recordless::CrossedRecovery } else if masks.is_none() || (finished_before && oldest) { Recordless::Allowed @@ -1097,6 +1119,9 @@ impl Queue { break; } Err(error) => { + if error == ENODATA { + self.classify_unexecuted(crossed); + } self.terminal = self.quarantine(error, defer)?.map(|status| (status, error)); return Ok(()); } @@ -1105,6 +1130,30 @@ impl Queue { Ok(()) } + /// The front command came back unexecuted (ENODATA from [`retirement::poll`]), and every + /// later command of the queue is ordered behind it, so none of them ran either. After a + /// recovery (`crossed`) the recovery dropped them: they cannot have faulted the GPU and are + /// spared, as the render groups a restart drops are, so they fail or replay without + /// poisoning their VM. Without a recovery in between, or once the firmware reported a fault + /// on this queue ([`Self::note_fault`]), the zero-duration record is the firmware's report + /// of the queue's own failed command: the work is guilty and fails its VM as before. Work a + /// recovery already classified keeps its class. + fn classify_unexecuted(&mut self, crossed: bool) { + let dropped = crossed && self.fault_stamp.is_none(); + for active in self.active.iter_mut() { + let completion = &active.packet.completion; + if completion.spared() || completion.guilty() { + continue; + } + if dropped { + completion.classify(recovery::Class::Spared); + active.spared_as_dropped = true; + } else { + completion.classify(recovery::Class::Guilty); + } + } + } + /// Exact terminal witness releases command pins, not installed graph ownership. Spared /// zero-duration work can return its queue to service after settling its accounting. pub(crate) fn release_witnessed( @@ -2328,6 +2377,7 @@ impl Queue { observed_at: None, failure_deferred: false, qos_pending: false, + spared_as_dropped: false, }) .map_err(|_| EBUSY)?; self.retirement_ready = false; diff --git a/drivers/gpu/drm/asahi/g17/runtime/compute_replay.rs b/drivers/gpu/drm/asahi/g17/runtime/compute_replay.rs index 32b9acef94c0f..4f6b11eac8d4a 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/compute_replay.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/compute_replay.rs @@ -96,6 +96,11 @@ impl Firmware { } queue.fail_replays(error); if !queue.owns_packet(&packet) { + // Replays are spared work a recovery dropped before it ran: it fails + // without poisoning its VM, as a dropped render group does. + if !packet.completion.guilty() { + packet.completion.classify(recovery::Class::Spared); + } deferred .push(Deferred::Retired(packet.completion.clone(), Err(ENODATA)))?; } From 9c1cc06ccc38a07bab38905e22e726a3f4db9651 Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sun, 8 Nov 2026 06:11:35 -0500 Subject: [PATCH 077/342] drm/asahi: g17: Fix fences of work a GPU recovery dropped failing as a lost device or never signalling A fence on a scanout buffer that never signals wedges KMS: the atomic commit worker waits for it with no timeout, so no frame reaches the display again, even across compositor restarts. Work a recovery dropped must signal within a bound, and since it never ran, it must not cost its client the device either. Three paths did not do that: - A compute queue whose commands a recovery dropped waits, spared, for its retirement witness before it replays or fails them. When the queue's job watchdog expires first, timeout() failed them with ETIMEDOUT, and fail_while_owned() reports every error but ENODATA and ECANCELED to the client's VM status: the client lost its device for work it never got to run. They now fail with ENODATA. - That witness needs every entry to hold a ticket. A spared queue with an entry without one would never get it, and the entry's own watchdog does nothing for an unpublished packet. quarantine() now fails such spared work at once with ENODATA, and timeout_head() reports a queue whose spared work still waits, ticketed or not, so that other VMs' watchdogs see it as a failed blocker and defer to it within their bounded renewals rather than fail their own work immediately. - Render groups parked for replay after a recovery that do not publish within 10 s made replay_render_front() return ETIMEDOUT. That failed the GPU event service, which loses every client's device and stops the runtime. The parked groups are innocent work that never ran (replay::decide() parks only those), so they now fail with ENODATA like fail_dropped()'s, spared, and the replay pass goes on. Bounds: no new timeout. A spared compute fence is settled by its job's scheduler watchdog, TIMEOUT_MS (2 s) per expiry; on M5 a job is renewed only while it waits behind an older node of its own context and the firmware's progress word moves (at most 14 renewals), plus 4 for ray traversal and AS builds, so 2 s typically and 38 s at most after the quarantine. A parked render replay keeps its 10 s bound (background_stalled(), the same as the recovery handshake's wait). Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- drivers/gpu/drm/asahi/g17/queue/compute.rs | 28 +++++++++++++++++-- drivers/gpu/drm/asahi/g17/queue/render.rs | 22 +++++++++++++++ .../drm/asahi/g17/runtime/render/replay.rs | 7 ++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/queue/compute.rs b/drivers/gpu/drm/asahi/g17/queue/compute.rs index 294ad42d9dc2a..69d6bacd42986 100644 --- a/drivers/gpu/drm/asahi/g17/queue/compute.rs +++ b/drivers/gpu/drm/asahi/g17/queue/compute.rs @@ -785,9 +785,13 @@ impl Queue { && active.packet.command.long_job() }) } - /// Quarantines without a pending witness no longer describe live pipe order. + /// Quarantines without a pending witness no longer describe live pipe order. Spared work + /// whose fences still wait (`spared_deferred`) does, whether or not every entry holds a + /// ticket: it holds the GPU until the firmware drains it or this queue's watchdog settles it + /// ([`Self::timeout`]), so other VMs' watchdogs see it as a failed blocker and defer to it + /// within their bounded renewals instead of failing their own work at once. pub(crate) fn timeout_head(&self) -> Option { - if self.quarantined && !self.awaiting_witness { + if self.quarantined && !self.awaiting_witness && !self.spared_deferred { return None; } self.active.front().map(|active| crate::g17::timeout::Head { @@ -998,6 +1002,19 @@ impl Queue { self.failure_status_pending = false; self.awaiting_witness = self.active.len != 0 && self.active.iter().all(|a| a.ticket.is_some()); + // Spared work waits for its retirement witness to replay or fail. An entry without a + // ticket never gives one (release_witnessed() validates every ticket), and an + // unpublished entry's own watchdog does nothing, so nothing would bound that wait. Fail + // it now instead: ENODATA, which stays out of the VM status. + if self.spared_deferred && !self.awaiting_witness { + for active in self.active.iter_mut() { + if !active.failure_deferred { + defer(Deferred::FailedOwned(active.packet.completion.clone(), ENODATA))?; + active.failure_deferred = true; + } + } + self.spared_deferred = false; + } Ok(terminal) } @@ -2001,6 +2018,11 @@ impl Queue { /// A watchdog settles spared, deferred waiters without changing their VM status. /// Fully ticketed spared work can still return this queue after its drain witness. + /// + /// Spared, deferred work is work a recovery dropped before it ran (the quarantine's + /// ENODATA) whose witness did not come before this queue's job watchdog expired: it fails + /// with ENODATA too. ETIMEDOUT would reach the client as a lost device (`fail_while_owned` + /// reports every error but ENODATA and ECANCELED), for work it never got to run. pub(crate) fn timeout( &mut self, defer: &mut impl FnMut(Deferred) -> Result, @@ -2016,7 +2038,7 @@ impl Queue { if !active.failure_deferred { defer(Deferred::FailedOwned( active.packet.completion.clone(), - ETIMEDOUT, + ENODATA, ))?; active.failure_deferred = true; } diff --git a/drivers/gpu/drm/asahi/g17/queue/render.rs b/drivers/gpu/drm/asahi/g17/queue/render.rs index 76447a297c5ec..a41e9b48b112a 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render.rs @@ -1784,6 +1784,28 @@ impl Pair { Ok(()) } + /// The parked groups did not publish within the replay bound + /// ([`crate::g17::timeout::background_stalled`], 10 s after they were parked). They are + /// groups a restart dropped before they ran, which `replay::decide` parks only for innocent + /// VMs: like `fail_dropped`'s, they fail with ENODATA without poisoning their VM, instead of + /// the replay pass failing the whole device. + pub(crate) fn fail_stalled_replay( + &mut self, + defer: &mut impl FnMut(Deferred) -> Result, + ) -> Result { + pr_warn!( + "G17: render slot {}: replay of {} parked groups stalled; failing them\n", + self.slot, + self.replay.len() + ); + for packet in self.replay.iter() { + if !packet.completion.guilty() { + packet.completion.classify(recovery::Class::Spared); + } + } + self.fail_replay(ENODATA, defer) + } + /// A closed preparation epoch invalidates only this unpublished descriptor. /// Its completion remains available for a retry under the next epoch. pub(crate) fn discard_prepared(&mut self, packet: &Arc) -> Result { diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs b/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs index 499e3858fcca1..7dda54f710eff 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs @@ -55,7 +55,12 @@ impl Firmware { return Ok(false); }; if stalled { - return Err(ETIMEDOUT); + // The parked groups' fences must signal; a stalled replay is no reason to lose + // every client's device. + self.with_render(slot, |pair, _| { + pair.fail_stalled_replay(&mut |event| deferred.push(event)) + })?; + return Ok(false); } if busy { return Ok(false); From 8f0df287cf6791fc9998704c9744cb64e001f911 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:08:47 +1100 Subject: [PATCH 078/342] thunderbolt: xdomain: do not redo lane bonding on a link that is still bonded A system resume restarts the XDomain handshake. When the routers were kept awake through the sleep (QUIRK_NO_SYSTEM_SLEEP) the link is still up and bonded, but the state machine walks lane bonding again: the host with the lower UUID sends link state change requests and both hosts re-set the link width, while thunderbolt-net logs in and activates its DMA paths. On the J616s (T6040, ACIO v2) talking to an M2, that overlap leaves the local router's control port unresponsive after a few resumes: every config space read of route 0 times out, thunderbolt-net cannot enable its paths, and only a reboot brings the link back. Skip the link status and bonding states when the downstream port is already bonded and its lanes report a bonded width. The first handshake of a new connection still bonds the lanes as before. Link: https://github.com/aurora-silicon/linux/issues/1230 Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/thunderbolt/xdomain.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c index b0f212c5c3b4b..857219a9ac8da 100644 --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c @@ -1727,6 +1727,30 @@ static void tb_xdomain_failed(struct tb_xdomain *xd) msecs_to_jiffies(XDOMAIN_DEFAULT_TIMEOUT)); } +/* + * Whether the lanes to @xd are bonded already. A handshake restarted on + * system resume, with the routers kept awake through the sleep, finds the + * link as it left it. Redoing lane bonding there makes both hosts walk the + * link width again while the services (thunderbolt-net) set up their paths + * at the same time, and on Apple ACIO v2 routers that can leave the local + * router's control port unresponsive. + */ +static bool tb_xdomain_lanes_bonded(struct tb_xdomain *xd) +{ + struct tb_port *port = tb_xdomain_downstream_port(xd); + int width; + + if (!port->dual_link_port || !port->bonded) + return false; + + width = tb_port_get_link_width(port); + if (width < 0) + return false; + + return width & (TB_LINK_WIDTH_DUAL | TB_LINK_WIDTH_ASYM_TX | + TB_LINK_WIDTH_ASYM_RX); +} + static void tb_xdomain_state_work(struct work_struct *work) { struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work); @@ -1756,7 +1780,7 @@ static void tb_xdomain_state_work(struct work_struct *work) tb_xdomain_failed(xd); } else { tb_xdomain_queue_properties_changed(xd); - if (xd->bonding_possible) + if (xd->bonding_possible && !tb_xdomain_lanes_bonded(xd)) tb_xdomain_queue_link_status(xd); else tb_xdomain_queue_properties(xd); From 62fdfa4ffbaece3c19335388c0c4a85a04d0bedd Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:08:50 +1100 Subject: [PATCH 079/342] media: apple: jpeg: complete the T6000 reset image Add the 33 sparse scratch defaults the legacy32 reset image was missing (32 zero writes and 0x234 = 0x1f40; the holes in that block stay unwritten), so T6000 no longer refuses at probe. T6000 completes jobs with interrupt status bit 31, so accept only that bit. Tested on the M1 Pro (J316s, fleet36 + this driver, DT enabled at runtime): both engines identify as HWREV 0xd1013; NV12 encodes at 3840x2160/1920x1080/1280x720/640x480 decode with ffmpeg at 41.6-43.4 dB PSNR (q75) on both engines; GStreamer -e drains; every job completed with INT_STATUS 0x80000000; three pm_test device suspend cycles with both engines bound; no DART or JPEG faults. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../admin-guide/media/apple-jpeg.rst | 19 ++++----- drivers/media/platform/apple/jpeg/Kconfig | 2 - .../media/platform/apple/jpeg/apple-jpeg-hw.c | 39 +++++++++++++++++-- .../platform/apple/jpeg/apple-jpeg-test.c | 29 +++++++++++++- 4 files changed, 73 insertions(+), 16 deletions(-) diff --git a/Documentation/admin-guide/media/apple-jpeg.rst b/Documentation/admin-guide/media/apple-jpeg.rst index a5bc6e18de907..9dd4c8d2c7304 100644 --- a/Documentation/admin-guide/media/apple-jpeg.rst +++ b/Documentation/admin-guide/media/apple-jpeg.rst @@ -29,16 +29,17 @@ uses compact 32-bit DMA addresses and a separate reset image. DMA addresses and inclusive boundaries must fit the selected address width. They are never truncated to fit a register. -The T6000 reset image is incomplete: its sparse scratch-register defaults -still need a complete clean specification. Its layout and job programming are -testable without hardware, but probe refuses runtime use until that reset -image is complete. Do not enable T6000 engine nodes for streaming yet. +The legacy32 reset image is complete: 111 static defaults, including the +sparse scratch block, plus the tiling write the helper appends. Unlisted +registers in that block are left unwritten. T6000 completes jobs with +interrupt status bit 31. Each engine has a 16 KiB MMIO resource and a separate adjacent DART at SID 0. The engine's resource must not include the DART window. Both T8112 engines -and their DARTs are enabled in ``t8112.dtsi`` (qualified on the J413). The -T6000 pairs stay disabled until the reset image is complete. Enabling nodes on -another SoC requires qualifying both of its instances. +and their DARTs are enabled in ``t8112.dtsi`` (qualified on the J413), and +both T6000 engines in ``t6000.dtsi`` (qualified on the J316s). T6001 and T6002 +stay disabled. Enabling nodes on another SoC requires qualifying both of its +instances. KUnit ----- @@ -58,8 +59,8 @@ Qualification Before enabling a new board, qualify both instances: record raw HWREV, terminal interrupt status (bit 30 or bit 31 for initial older-family qualification), reset/idle handshakes, runtime PM, geometry, output-capacity -checks and error recovery. T8140 retains its qualified bit-31 completion -mask. The other variants initially accept bits 30 and 31; status/error and +checks and error recovery. T8140 and T6000 use their qualified bit-31 +completion mask. The other variants accept bits 30 and 31; status/error and output-capacity checks still apply. Check each encoder's advertised formats and use its actual video node. For diff --git a/drivers/media/platform/apple/jpeg/Kconfig b/drivers/media/platform/apple/jpeg/Kconfig index 9d8ca09462e55..e6f63c05b75d0 100644 --- a/drivers/media/platform/apple/jpeg/Kconfig +++ b/drivers/media/platform/apple/jpeg/Kconfig @@ -12,8 +12,6 @@ config VIDEO_APPLE_JPEG in T6000, T6041, T8112 and T8140 SoCs. It takes full-range NV12 (4:2:0) or NV16 (4:2:2) frames. The device compatible selects the register layout and address width; unrecognized revisions are refused. - T6000 has a layout description but remains refused until its complete - reset image is specified. To compile this driver as a module, choose M here: the module will be called apple-jpeg. diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c index 88acd49dd1e63..7c25b25a18c20 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-hw.c @@ -184,7 +184,7 @@ static const struct apple_jpeg_write aj_wide64_defaults[] = { { 0x020, 0xff }, }; -/* Known legacy defaults; sparse scratch entries still need specification. */ +/* Complete legacy32 reset image; the layout helper appends tiling. */ static const struct apple_jpeg_write aj_legacy32_defaults[] = { { 0x000, 0x0 }, { 0x004, 0x0 }, @@ -263,6 +263,39 @@ static const struct apple_jpeg_write aj_legacy32_defaults[] = { { 0x0a8, 0xffffffff }, { 0x094, 0x1 }, { 0x098, 0x1 }, + { 0x1fc, 0x0 }, + { 0x200, 0x0 }, + { 0x204, 0x0 }, + { 0x208, 0x0 }, + { 0x214, 0x0 }, + { 0x218, 0x0 }, + { 0x21c, 0x0 }, + { 0x220, 0x0 }, + { 0x224, 0x0 }, + { 0x228, 0x0 }, + { 0x22c, 0x0 }, + { 0x230, 0x0 }, + { 0x234, 0x1f40 }, + { 0x244, 0x0 }, + { 0x248, 0x0 }, + { 0x258, 0x0 }, + { 0x25c, 0x0 }, + { 0x23c, 0x0 }, + { 0x240, 0x0 }, + { 0x250, 0x0 }, + { 0x254, 0x0 }, + { 0x1a0, 0x0 }, + { 0x1a8, 0x0 }, + { 0x1ac, 0x0 }, + { 0x1b0, 0x0 }, + { 0x1b4, 0x0 }, + { 0x1bc, 0x0 }, + { 0x1c0, 0x0 }, + { 0x1c4, 0x0 }, + { 0x1c8, 0x0 }, + { 0x1cc, 0x0 }, + { 0x1d0, 0x0 }, + { 0x1d4, 0x0 }, { 0x020, 0xff }, }; @@ -315,7 +348,7 @@ static const struct apple_jpeg_reg_layout aj_legacy32 = { .image_height = 0x210, .decode_block_base = 0x130, .dma_addr_bits = 32, - .reset_complete = false, + .reset_complete = true, .defaults = aj_legacy32_defaults, .num_defaults = ARRAY_SIZE(aj_legacy32_defaults), }; @@ -324,7 +357,7 @@ const struct apple_jpeg_variant apple_jpeg_t6000 = { .layout = &aj_legacy32, .hwrev_mask = AJ_HWREV_MASK, .hwrev = 0x0d0013, - .int_done_mask = BIT(31) | BIT(30), + .int_done_mask = BIT(31), }; EXPORT_SYMBOL_IF_KUNIT(apple_jpeg_t6000); diff --git a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c index 615127af8093f..8e9b61e684e8f 100644 --- a/drivers/media/platform/apple/jpeg/apple-jpeg-test.c +++ b/drivers/media/platform/apple/jpeg/apple-jpeg-test.c @@ -164,7 +164,8 @@ static void apple_jpeg_layout_test(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, apple_jpeg_t6041.layout, wide); KUNIT_EXPECT_PTR_NE(test, legacy, wide); KUNIT_EXPECT_TRUE(test, wide->reset_complete); - KUNIT_EXPECT_FALSE(test, legacy->reset_complete); + KUNIT_EXPECT_TRUE(test, legacy->reset_complete); + KUNIT_EXPECT_EQ(test, legacy->num_defaults, 111); KUNIT_EXPECT_EQ(test, wide->dma_addr_bits, 64); KUNIT_EXPECT_EQ(test, legacy->dma_addr_bits, 32); KUNIT_EXPECT_EQ(test, wide->input_plane0, 0x090); @@ -209,7 +210,7 @@ static void apple_jpeg_layout_test(struct kunit *test) KUNIT_EXPECT_EQ(test, legacy->decode_block_base, 0x130); KUNIT_EXPECT_EQ(test, apple_jpeg_t8140.int_done_mask, BIT(31)); KUNIT_EXPECT_EQ(test, apple_jpeg_t8112.int_done_mask, BIT(31) | BIT(30)); - KUNIT_EXPECT_EQ(test, apple_jpeg_t6000.int_done_mask, BIT(31) | BIT(30)); + KUNIT_EXPECT_EQ(test, apple_jpeg_t6000.int_done_mask, BIT(31)); } static void apple_jpeg_older_hwrev_test(struct kunit *test) @@ -328,6 +329,30 @@ static void apple_jpeg_defaults_test(struct kunit *test) /* Wide reset literals must not leak into the legacy image. */ KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x280), 0xdeadbeef); KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x2b0), 0xdeadbeef); + /* The sparse scratch block: one non-zero default, holes stay holes. */ + KUNIT_EXPECT_EQ(test, n, 112); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x234), 0x1f40); + for (u32 off = 0x1fc; off <= 0x25c; off += 4) { + if (off == 0x20c || off == 0x210 || off == 0x234 || off == 0x238 || + off == 0x24c) + continue; + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, off), 0); + } + for (u32 off = 0x1a0; off <= 0x1d4; off += 4) { + if (off == 0x1a4 || off == 0x1b8) + continue; + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, off), 0); + } + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x1a4), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x1b8), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x20c), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x210), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x238), 0xdeadbeef); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x24c), 0xdeadbeef); + n = apple_jpeg_defaults(legacy, false, w, APPLE_JPEG_MAX_WRITES); + KUNIT_EXPECT_EQ(test, n, 112); + KUNIT_EXPECT_EQ(test, apple_jpeg_last(w, n, 0x160), 0); + KUNIT_EXPECT_EQ(test, apple_jpeg_defaults(legacy, true, w, 111), -ENOSPC); KUNIT_EXPECT_EQ(test, apple_jpeg_defaults(wide, true, w, 1), -ENOSPC); KUNIT_EXPECT_EQ(test, apple_jpeg_defaults(legacy, true, w, 1), -ENOSPC); } From 4e0b2c3e1db5cd14d565d57b36b8ac85415ddf66 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:08:50 +1100 Subject: [PATCH 080/342] arm64: dts: apple: t6000: enable the JPEG encoders Both T6000 JPEG engines now probe with a complete reset image. Enable them and their DARTs for the M1 Pro boards; they are SoC blocks with no board-specific wiring. T6001/T6002 stay disabled. Tested on the M1 Pro (J316s), see the driver change. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 8cafe1065db0e..6c5e086626bda 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -101,3 +101,20 @@ &apr0 { status = "okay"; }; + +/* Both JPEG encoders are SoC blocks with no board wiring. */ +&jpeg0_dart { + status = "okay"; +}; + +&jpeg0 { + status = "okay"; +}; + +&jpeg1_dart { + status = "okay"; +}; + +&jpeg1 { + status = "okay"; +}; From f349347cb6db61acd082b3c34e7c6f6480468b0f Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 02:12:44 +1100 Subject: [PATCH 081/342] media: apple: ave: speed over quality for HEVC Main 10 too The speed-over-quality control was limited to 8-bit HEVC because Main 10 had not been measured. Main 10 behaves like Main: the same Start word (3 -> 5) makes it 1.6-1.8 times faster, its pictures stay intact, and the bit-rate cost is lower than for 8-bit (+7.2% BD-rate PSNR-Y against +12.4%). Apply the control to Main 10 as well. It still applies only to HEVC above 1280x720. With the control off, every command is byte-identical to before. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/admin-guide/media/apple-ave.rst | 5 ++--- .../media/platform/apple/ave/ave-abi-test.c | 21 ++++++++++++------- drivers/media/platform/apple/ave/ave-sess.c | 8 +++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Documentation/admin-guide/media/apple-ave.rst b/Documentation/admin-guide/media/apple-ave.rst index 02eede3115323..41aeaadc71834 100644 --- a/Documentation/admin-guide/media/apple-ave.rst +++ b/Documentation/admin-guide/media/apple-ave.rst @@ -146,9 +146,8 @@ Limits - ``Prioritize Speed Over Quality`` (driver-private boolean, ``V4L2_CID_APPLE_AVE_PRIORITIZE_SPEED`` = codec class base ``0x1200``, off by default) is VideoToolbox's PrioritizeEncodingSpeedOverQuality: it sets the - firmware's throughput mode to 5 instead of 3. It applies to 8-bit HEVC - above 1280x720 (Main 10 is not measured yet) and is read when streaming - starts. H.264 is not faster with it, on macOS either, so it has no effect + firmware's throughput mode to 5 instead of 3. It applies to HEVC (Main + and Main 10) above 1280x720 and is read when streaming starts. H.264 is not faster with it, on macOS either, so it has no effect there. - Either three B-frames or none (``B_FRAMES`` 3 or 0). H.264 Baseline and a GOP size of 1 never use them. diff --git a/drivers/media/platform/apple/ave/ave-abi-test.c b/drivers/media/platform/apple/ave/ave-abi-test.c index 255ec6e9950d2..06e6a1df052ed 100644 --- a/drivers/media/platform/apple/ave/ave-abi-test.c +++ b/drivers/media/platform/apple/ave/ave-abi-test.c @@ -227,10 +227,15 @@ static void ave_9003_hevc_main10(struct kunit *test) /* One 1080p HEVC Start or first Process image, with speed mode @speed. */ static void ave_speed_image(struct kunit *test, struct ave_ctx *ctx, - enum ave_image image, bool bframes, bool speed, - u8 *cmd, size_t len) + enum ave_image image, bool bframes, bool main10, + bool speed, u8 *cmd, size_t len) { ave_test_session(ctx->sess, AVE_CODEC_HEVC, 1920, 1080, bframes); + if (main10) { + ctx->sess->p.min_qp = -12; + ctx->sess->p.profile = 2; + ctx->sess->p.bit_depth = 10; + } ctx->sess->p.speed = speed; memset(cmd, 0, len); if (image == AVE_IMAGE_START) @@ -244,7 +249,8 @@ static void ave_speed_image(struct kunit *test, struct ave_ctx *ctx, /* * Speed over quality on 9003: HEVC Start changes only the throughput mode - * (+0x320, 3 -> 5); Process stays the same, with and without B-frames. + * (+0x320, 3 -> 5); Process stays the same, with and without B-frames, for + * Main and Main 10. */ static void ave_9003_speed(struct kunit *test) { @@ -263,14 +269,15 @@ static void ave_9003_speed(struct kunit *test) ctx->ave = ave; ctx->sess = sess; - for (unsigned int i = 0; i < 4; i++) { + for (unsigned int i = 0; i < 8; i++) { enum ave_image image = i & 1 ? AVE_IMAGE_PROCESS : AVE_IMAGE_START; - bool bframes = i & 2; + bool bframes = i & 2, main10 = i & 4; size_t len = ave->layout->bytes[AVE_CODEC_HEVC - 1][image]; u32 changed = image == AVE_IMAGE_START ? 0x320 : 0; - ave_speed_image(test, ctx, image, bframes, false, quality, len); - ave_speed_image(test, ctx, image, bframes, true, speed, len); + ave_speed_image(test, ctx, image, bframes, main10, false, quality, + len); + ave_speed_image(test, ctx, image, bframes, main10, true, speed, len); if (changed) { KUNIT_EXPECT_EQ(test, get_unaligned_le32(quality + changed), 3); KUNIT_EXPECT_EQ(test, get_unaligned_le32(speed + changed), 5); diff --git a/drivers/media/platform/apple/ave/ave-sess.c b/drivers/media/platform/apple/ave/ave-sess.c index dde038a81299a..e47337b611307 100644 --- a/drivers/media/platform/apple/ave/ave-sess.c +++ b/drivers/media/platform/apple/ave/ave-sess.c @@ -200,12 +200,12 @@ static int ave_sess_params(struct ave_ctx *ctx, struct ave_params *p) p->slots = p->bframes ? 5 : 3; /* * Speed over quality changes the firmware's throughput mode from 3 to - * 5, as macOS does. It is measured for 8-bit HEVC above 720p on the - * 9003 layout only; H.264 does not get faster from it (on macOS - * either). + * 5, as macOS does. It is measured for HEVC (Main and Main 10) above + * 720p on the 9003 layout only; H.264 does not get faster from it (on + * macOS either). */ p->speed = ctx->prioritize_speed && p->codec == AVE_CODEC_HEVC && - p->sample_bytes == 1 && !ctx->ave->layout->counted && + !ctx->ave->layout->counted && p->width * p->height > 1280 * 720; p->gop = ctx->gop_size ?: 120; From 9e8fa1e28ac5df677694ceb187b85873eb6cce34 Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sun, 8 Nov 2026 11:19:20 -0500 Subject: [PATCH 082/342] drm/asahi: g17: address the review of the recovery-dropped work fixes Follow-up to the automated review of this pull request, kept as a separate commit for review and squashed on request. drm/asahi: g17: Fix fences of work a GPU recovery dropped failing as a lost device or never signalling A fence on a scanout buffer that never signals wedges KMS: the atomic commit worker waits for it with no timeout, so no frame reaches the display again, even across compositor restarts. Work a recovery dropped must signal within a bound, and since it never ran, it must not cost its client the device either. Three paths did not do that: - A compute queue whose commands a recovery dropped waits, spared, for its retirement witness before it replays or fails them. When the queue's job watchdog expires first, timeout() failed them with ETIMEDOUT, and fail_while_owned() reports every error but ENODATA and ECANCELED to the client's VM status: the client lost its device for work it never got to run. They now fail with ENODATA. - That witness needs every entry to hold a ticket. A spared queue with an entry without one would never get it, and the entry's own watchdog does nothing for an unpublished packet. quarantine() now fails such spared work at once with ENODATA, and timeout_head() reports a queue whose spared work still waits, ticketed or not, so that other VMs' watchdogs see it as a failed blocker and defer to it within their bounded renewals rather than fail their own work immediately. - Render groups parked for replay after a recovery that do not publish within 10 s made replay_render_front() return ETIMEDOUT. That failed the GPU event service, which loses every client's device and stops the runtime. The parked groups are innocent work that never ran (replay::decide() parks only those), so they now fail with ENODATA like fail_dropped()'s, spared, and the replay pass goes on. A replay that publish_render() refused before publishing it (outer work ring full, an owner switch still releasing, a recovery pending) kept its prepared descriptor, so the next pass could not prepare it again and the replay always ran into that bound; failing it then left the descriptor installed, and the pair took no work again. Such a descriptor is now discarded when the publication is refused, so the next pass prepares the group again, and fail_replay() discards one it finds for the front. Bounds: no new timeout. A spared compute fence is settled by its job's scheduler watchdog, TIMEOUT_MS (2 s) per expiry; on M5 a job is renewed only while it waits behind an older node of its own context and the firmware's progress word moves (at most 14 renewals), plus 4 for ray traversal and AS builds, so 2 s typically and 38 s at most after the quarantine. A parked render replay keeps its 10 s bound (background_stalled(), the same as the recovery handshake's wait). drm/asahi: g17: Fix a GPU recovery failing the compositor for compute work it dropped When a GPU recovery cannot name the culprit (on M5 every firmware restart is attributed to the firmware, and classify() gives up when a guilty queue has no in-flight owner), it classifies nobody. Compute commands it dropped before they ran then come back from their queue's records as unexecuted (ENODATA), unclassified, and poisons() is true for unclassified ENODATA: the queue's terminal records the error and fails every queue of the VM, and the client's driver reads the VM status as a lost device. A Chromium GPU fault took Hyprland down this way: right after the faulting client's EIO, the log reported "GPU work of a client failed (ENODATA, ...)" for Hyprland too, and zink lost its device. The render side already handles this: groups a restart dropped are classified Spared before they fail with ENODATA. Do the same for compute: - When a compute queue's front comes back unexecuted after crossing a recovery, and the firmware reported no fault on the queue, classify every unclassified command of the queue Spared before quarantining it. All of them are ordered behind the front, so none of them ran. The queue then takes the existing spared path: its commands replay when their records prove they never ran, and otherwise fail with ENODATA Compile-checked with W=1 CLIPPY=1 over drivers/gpu/drm/{asahi,apple}: no new warnings against the base; checkpatch --strict clean; rustfmt unchanged. Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- drivers/gpu/drm/asahi/g17/queue/compute.rs | 11 +++++++---- drivers/gpu/drm/asahi/g17/queue/render.rs | 11 +++++++++++ drivers/gpu/drm/asahi/g17/runtime/render/replay.rs | 9 ++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/queue/compute.rs b/drivers/gpu/drm/asahi/g17/queue/compute.rs index 69d6bacd42986..9f847eb383931 100644 --- a/drivers/gpu/drm/asahi/g17/queue/compute.rs +++ b/drivers/gpu/drm/asahi/g17/queue/compute.rs @@ -468,7 +468,8 @@ struct Active { failure_deferred: bool, qos_pending: bool, /// Spared because it came back unexecuted after a recovery ([`Queue::classify_unexecuted`]), - /// not by the recovery's own attribution. A later fault report on the queue makes it guilty. + /// not by the recovery's own attribution, or a replay of spared work, which runs again from + /// the start. A later fault report on the queue makes it guilty. spared_as_dropped: bool, } struct Previous> { @@ -702,8 +703,9 @@ impl Queue { self.fault_stamp = Some(stamp); } // The report can arrive after the queue's unexecuted commands were spared as dropped by - // a recovery: the failed command is among them. They are guilty, as without the - // recovery: the VM fails, and the queue is neither replayed nor returned to service. + // a recovery, or while replays of spared work run: the failed command is among them. + // They are guilty, as without the recovery: the VM fails, and the queue is neither + // replayed nor returned to service. let mut guilty = None; for active in self.active.iter_mut().filter(|active| active.spared_as_dropped) { active.spared_as_dropped = false; @@ -2399,7 +2401,8 @@ impl Queue { observed_at: None, failure_deferred: false, qos_pending: false, - spared_as_dropped: false, + // A replay keeps its spared class: its own fault must still make it guilty. + spared_as_dropped: packet.completion.spared(), }) .map_err(|_| EBUSY)?; self.retirement_ready = false; diff --git a/drivers/gpu/drm/asahi/g17/queue/render.rs b/drivers/gpu/drm/asahi/g17/queue/render.rs index a41e9b48b112a..81948e738769c 100644 --- a/drivers/gpu/drm/asahi/g17/queue/render.rs +++ b/drivers/gpu/drm/asahi/g17/queue/render.rs @@ -1778,6 +1778,17 @@ impl Pair { defer: &mut impl FnMut(Deferred) -> Result, ) -> Result { self.replay_since = None; + // A descriptor prepared for the front and never published goes with it, or the pair + // would take no work again. + if let Some(front) = self.replay.front().cloned() { + if self + .prepared + .as_ref() + .is_some_and(|prepared| Arc::ptr_eq(&prepared.packet, &front)) + { + self.discard_prepared(&front)?; + } + } while let Some(packet) = self.replay.pop() { defer(Deferred::Retired(packet.completion.clone(), Err(error)))?; } diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs b/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs index 7dda54f710eff..c4fb20fa0952a 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/replay.rs @@ -110,9 +110,16 @@ impl Firmware { self.with_render(slot, |pair, _| pair.finish_replay(&packet))?; Ok(true) } - Err(error) if error == EBUSY || error == EAGAIN => Ok(false), Err(error) => { self.with_render(slot, |pair, _| { + // A refusal before publication leaves the descriptor prepared; the next + // pass prepares the group again, which it cannot while that one is held. + if !packet.is_published() { + pair.discard_prepared(&packet)?; + } + if error == EBUSY || error == EAGAIN { + return Ok(()); + } pair.fail_replay(error, &mut |event| deferred.push(event)) })?; Ok(false) From f2f745f21544211e1598618c6aa2f9599a4f0878 Mon Sep 17 00:00:00 2001 From: Rolando Trevino Date: Sun, 8 Nov 2026 11:20:19 -0500 Subject: [PATCH 083/342] drm/apple: address the review of the bounded fence wait Follow-up to the automated review of this pull request, kept as a separate commit for review and squashed on request. drm/apple: Fix a GPU fence that never signals wedging the display drm_atomic_helper_commit() waits for every plane's in-fence with dma_fence_wait() and no timeout: in the commit worker before the driver's commit tail, and, for blocking commits, before the swap. The in-fence is the scanout buffer's implicit write fence (zink imports its GPU job's fence into each exported dma-buf) or the compositor's IN_FENCE_FD. When a GPU fence never signals, after a GPU recovery for example, the worker sleeps for good: commit_planes() never runs, no swap reaches DCP, the commit's flip event never comes, and every later nonblocking commit fails with -EBUSY (stall_checks(), only a debug message). The 10 s flip_done timeout is never reached, so nothing is logged. The panel stays black across compositor restarts, which see "Cannot commit when a page-flip is awaiting", until a reboot. Commit through a copy of drm_atomic_helper_commit() whose fence wait is bounded: all of a commit's planes share one second, and a fence that does not signal in time is dropped with a rate-limited warning naming its driver and timeline. The buffer is scanned out as it is, so a GPU bug costs a stale or torn frame instead of the panel. The copy keeps the helper's sequence (setup, prepare, the interruptible pre-swap wait for blocking commits, swap, the worker's wait for dependencies, the tail, cleanup) and its fence deadline hint, and leaves out only the self-refresh accounting, which this driver does not use. Once the commit goes on, its flip completes as usual. If DCP then does not complete the swap within drm_atomic_helper_wait_for_flip_done()'s 10 s, the commit's event stayed pending and a compositor would still wait for it before committing again. Send that event as failed (-ETIMEDOUT on its out-fence) after the wait; only the event that belongs to this commit is sent. The commit then leaves its CRTC's list at cleanup_done as before, so later nonblocking commits are not held by it either. The swap of that flip may still complete after the next commit installed its event. The H17P and desktop 26.x paths match a completion to its present; on the older firmware (12.3, 13.5, the 14.7 template, H17G) a completion retires whatever flip is pending, so there the lost swap's completion is now ignored. The framebuffers the lost swap displaced are unarmed, as the swap watchdog does for a dropped swap, so that the next swap re-arms them and its completion releases them; they were otherwise kept until the display powered off. Compile-checked with W=1 CLIPPY=1 over drivers/gpu/drm/{asahi,apple}: no new warnings against the base; checkpatch --strict clean; rustfmt unchanged. Signed-off-by: Rolando Trevino Assisted-by: LLM Claude --- drivers/gpu/drm/apple/apple_drv.c | 2 +- drivers/gpu/drm/apple/dcp-internal.h | 10 +++++++ drivers/gpu/drm/apple/dcp.c | 39 ++++++++++++++++++++++++++ drivers/gpu/drm/apple/iomfb_template.c | 8 ++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index fbd0325b963d2..1981a33aff91f 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -652,7 +652,7 @@ static int apple_wait_for_fences(struct drm_device *dev, WARN_ON(!new_plane_state->fb); - left = time_before(jiffies, deadline) ? deadline - jiffies : 0; + left = max_t(long, (long)(deadline - jiffies), 0); ret = dma_fence_wait_timeout(fence, pre_swap, left); if (ret < 0) return ret; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 5b9f50b60d300..26ff331cc27d0 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -73,6 +73,7 @@ struct apple_dcp_typec_port; void dcp_swap_watchdog_arm(struct apple_dcp *dcp); void dcp_swap_watchdog_complete(struct apple_dcp *dcp); +bool dcp_swap_lost(struct apple_dcp *dcp, u32 swap_id); void dcp_retry_placeholder_edid(struct apple_dcp *dcp, const struct drm_edid *drm_edid); bool dcp_typec_relink(struct apple_dcp *dcp); @@ -573,6 +574,15 @@ struct apple_dcp { u32 last_swap_id; /* last_swap_id is only meaningful after the first swap completes */ bool have_swap_complete; + /* swap id of the last started swap */ + u32 started_swap_id; + /* + * A started swap whose flip a commit gave up on + * (dcp_drm_crtc_flip_lost()); event_lock. Firmware that does not track + * its presents ignores its completion, see dcp_swap_lost(). + */ + u32 lost_swap_id; + bool swap_lost; ktime_t swap_start; u64 swap_submit_timestamp; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 4669e4fb983c1..efbe331d2467a 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -535,18 +535,57 @@ void dcp_drm_crtc_error(struct apple_crtc *crtc, * The flip of the commit whose flip_done is @flip_done never completed: send * its still pending event as failed. Only that commit's event is sent; a newer * commit's stays for its own swap. + * + * The swap started last is that flip's. Its displaced framebuffers are + * unarmed, as the swap watchdog does, so that the next swap arms them and its + * completion releases them. Its completion may still come, after the next + * commit installed its event: firmware that does not track its presents + * ignores it (dcp_swap_lost()), so that it does not retire the newer flip. */ void dcp_drm_crtc_flip_lost(struct apple_crtc *crtc, struct completion *flip_done, int error) { + struct apple_dcp *dcp = platform_get_drvdata(crtc->dcp); unsigned long flags; + bool lost = false; + u32 swap_id = 0; spin_lock_irqsave(&crtc->base.dev->event_lock, flags); if (crtc->event && crtc->event->base.completion == flip_done) { dcp_failed_page_flip(crtc, crtc->event, error); crtc->event = NULL; + swap_id = READ_ONCE(dcp->started_swap_id); + dcp->lost_swap_id = swap_id; + dcp->swap_lost = true; + lost = true; } spin_unlock_irqrestore(&crtc->base.dev->event_lock, flags); + + if (lost) + dcp_unarm_retained_framebuffers(dcp, swap_id); +} + +/* + * Is @swap_id the swap whose flip dcp_drm_crtc_flip_lost() gave up on? On + * firmware that does not track its presents, its completion would retire + * whichever flip is pending; it is ignored instead. Swaps complete in order, + * so once another swap completed, the lost one will not. + */ +bool dcp_swap_lost(struct apple_dcp *dcp, u32 swap_id) +{ + unsigned long flags; + bool lost; + + spin_lock_irqsave(&dcp->crtc->base.dev->event_lock, flags); + lost = dcp->swap_lost && dcp->lost_swap_id == swap_id; + dcp->swap_lost = false; + spin_unlock_irqrestore(&dcp->crtc->base.dev->event_lock, flags); + + if (lost) + dev_warn_ratelimited(dcp->dev, + "completion for lost present %u ignored\n", + swap_id); + return lost; } void dcp_drm_crtc_page_flip(struct apple_dcp *dcp, ktime_t now) diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 82e5310f3fd6e..19615309aa2b9 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -649,6 +649,12 @@ static void dcpep_cb_swap_complete(struct apple_dcp *dcp, if (!dcp_desktop_present_complete(dcp, resp->swap_id)) return; dcp_backlight_desktop_finish(dcp, resp->swap_id, false, true); +#else + /* Nor can a lost flip's on firmware that does not track its presents. */ + if ((!DCP_FW_H17(DCP_FW_VER) || + dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G) && + dcp_swap_lost(dcp, resp->swap_id)) + return; #endif trace_iomfb_swap_complete(dcp, resp->swap_id); dcp->last_swap_id = resp->swap_id; @@ -2088,6 +2094,7 @@ static void dcp_swap_clear_started(struct apple_dcp *dcp, void *data, dcp_prepare_clear_swap(dcp, &DCP_FW_SWAP(dcp)); #endif DCP_FW_SWAP(dcp).swap.swap_id = resp->swap_id; + WRITE_ONCE(dcp->started_swap_id, resp->swap_id); if (dcp_present_retires(dcp)) dcp_arm_retained_framebuffers(dcp, resp->swap_id); @@ -2943,6 +2950,7 @@ static void dcp_swap_started(struct apple_dcp *dcp, void *data, void *cookie) return; } DCP_FW_SWAP(dcp).swap.swap_id = resp->swap_id; + WRITE_ONCE(dcp->started_swap_id, resp->swap_id); if (dcp_present_retires(dcp)) dcp_arm_retained_framebuffers(dcp, resp->swap_id); From ae1b7ec4049cfbc4dca8155c2c8e11b16c606c3a Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 4 Nov 2026 20:00:35 -0600 Subject: [PATCH 084/342] perf: avoid charging mmap aliases twice Charge normal-ring and AUX pages only on first allocation. Repeated aliases share the existing charge; the final close releases it once. A failed alias mapping previously left an extra per-user charge. Add a source-level host regression for duplicate and failed aliases, metadata-only rings, limit splitting and alternate close orders. Against the exact base the harness reports 16 failing alias cases; on this tree it passes 26/26. A focused x86-64 core.o build passed. This is single- user, single-mm, single-threaded host testing with stubbed kernel plumbing; it is not runtime or hardware validation. Fixes: 0c8a4e4139ad ("perf/core: Further simplify perf_mmap()") Assisted-by: LLM Signed-off-by: Joshua Warren --- kernel/events/core.c | 15 +- .../asahi/perf-mmap-alias-lifecycle-tests.py | 1504 +++++++++++++++++ 2 files changed, 1516 insertions(+), 3 deletions(-) create mode 100755 tools/asahi/perf-mmap-alias-lifecycle-tests.py diff --git a/kernel/events/core.c b/kernel/events/core.c index db8783602d08e..93574bee7b4b2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7349,9 +7349,11 @@ static int perf_mmap_rb(struct vm_area_struct *vma, struct perf_event *event, if (refcount_inc_not_zero(&event->rb->mmap_count)) { /* * Success -- managed to mmap() the same buffer - * multiple times. + * multiple times. The alias shares the ring's + * already-locked pages; the existing charge stays + * as-is and is removed once, when the last mapping + * closes. */ - perf_mmap_account(vma, user_extra, extra); refcount_inc(&event->mmap_count); return 0; } @@ -7463,9 +7465,16 @@ static int perf_mmap_aux(struct vm_area_struct *vma, struct perf_event *event) refcount_set(&rb->aux_mmap_count, 1); rb->aux_mmap_locked = extra; + + /* + * Charge the AUX area once, at first allocation. The alias + * branch above shares the already-locked pages and adds no + * charge; the single charge is removed when the last AUX + * mapping closes. + */ + perf_mmap_account(vma, user_extra, extra); } - perf_mmap_account(vma, user_extra, extra); refcount_inc(&event->mmap_count); return 0; diff --git a/tools/asahi/perf-mmap-alias-lifecycle-tests.py b/tools/asahi/perf-mmap-alias-lifecycle-tests.py new file mode 100755 index 0000000000000..55f385052ea29 --- /dev/null +++ b/tools/asahi/perf-mmap-alias-lifecycle-tests.py @@ -0,0 +1,1504 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Duplicate-alias and failed-alias lifecycle regression tests for the perf +mmap locked-memory accounting (normal ring and AUX area). + +The tool compiles the accounting code straight out of each tree under test +(kernel/events/core.c + internal.h: perf_mmap, perf_mmap_rb, perf_mmap_aux, +perf_mmap_close, perf_mmap_account, perf_mmap_unaccount, perf_mmap_calc_limits +and the internal.h inline helpers) into a host harness and drives full +lifecycles through it: + + - duplicate aliases of the normal ring: charge per alias, uncharge once at + final close (user-reported leak), in both close orders -- aliases first + and the original mapping first while every alias is still live, + - duplicate aliases of the AUX area: charge per alias, uncharge once at the + last AUX close (user-reported leak), in both close orders -- AUX first + and the normal ring VMA first while the AUX area stays live, + - failed aliases: AUX first-map failures (-EPERM limit check, rb_alloc_aux + failure, early -EINVAL), and map_range() failures through the real + perf_mmap() dispatcher error path, both for a first mapping (minimal + perf_mmap_close()) and for an alias (full perf_mmap_close()), + - real limit splitting through the tree's own perf_mmap_calc_limits() + (partial spill and full spill into pinned_vm), + - ring geometries: full data ring, metadata-only ring, and (user4k trees) + a sub-native-page data ring on a 4K-page mm. + +This is a source-level test: the extracted C is the tree's real code, but +VMA/file/user/mutex plumbing, map_range(), rb_alloc()/rb_alloc_aux() page +backing and ring_buffer_attach() are signature-faithful host stubs, it is +single-threaded, and nothing runs in a kernel. It is not evidence about +hardware or a booted kernel; it is evidence about the source's charge/ +uncharge/refcount behaviour. + +Assertions encode the desired invariant (every counter and refcount returns +to its initial value when a lifecycle completes; perf_mlock and locked_vm +are checked individually, so a transfer between them cannot mask a leak). +A scenario that ends with +a nonzero counter therefore FAILS and prints the exact leaked page count -- +leaks are reported, not hidden. The tool exits nonzero if any invariant +broke: a tree that charges every alias fails the duplicate-alias scenarios; +a tree whose aliases share the first map's single charge balances every +lifecycle and passes. +""" + +from pathlib import Path +import argparse +import re +import subprocess +import sys +import tempfile +from string import Template + +HERE = Path(__file__).resolve().parent + +DEFAULT_TREES = [base for base in HERE.parents + if (base / 'kernel/events/core.c').is_file()] + +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument('--tree', type=Path, action='append', dest='trees', + default=None, + help='kernel tree holding kernel/events ' + '(repeatable; default: the kernel tree this test ' + 'lives in)') +parser.add_argument('--cc', default='cc', help='C compiler (default: cc)') +args = parser.parse_args() +if args.trees is None: + if not DEFAULT_TREES: + parser.error('--tree is required: no kernel/events/core.c found ' + 'above %s' % HERE) + args.trees = DEFAULT_TREES + + +def definition(text, name): + """Return the C text of a function definition, not of its prototype.""" + for match in re.finditer(r'\b' + re.escape(name) + r'\s*\(', text): + index = match.end() - 1 + depth = 0 + while index < len(text): + if text[index] == '(': + depth += 1 + elif text[index] == ')': + depth -= 1 + if depth == 0: + break + index += 1 + brace = text.find('{', index) + semi = text.find(';', index) + if brace == -1 or (semi != -1 and semi < brace): + continue + if '*/' in text[match.start():brace]: + continue # match sat inside a comment; find the real definition + depth = 0 + for position in range(brace, len(text)): + if text[position] == '{': + depth += 1 + elif text[position] == '}': + depth -= 1 + if depth == 0: + start = text.rfind('\n', 0, match.start()) + 1 + return text[start:position + 1] + return None + + +def rb_alloc_profile(ring): + """Detect the rb_alloc() shape: user4k data_size form or plain nr_pages.""" + func = definition(ring, 'rb_alloc') + if func is None: + raise SystemExit('no rb_alloc() definition in ring_buffer.c') + head = func.split(')')[0] + user4k = 'data_size' in head + match = re.search(r'int nr_pages\s*=\s*([^;]+);', func) + nr_pages_expr = match.group(1).strip() if match else 'nr_pages' + match = re.search(r'rb->data_page_shift\s*=\s*([^;]+);', func) + return user4k, nr_pages_expr, match.group(1).strip() if match else None + + +def rb_init_lines(ring): + """The mmap_count/mmap_user initialisation the tree does at rb_alloc.""" + lines = [] + if re.search(r'rb->mmap_user\s*=\s*get_current_user\(\);', ring): + lines.append('\trb->mmap_user = current_user();') + if re.search(r'refcount_set\(&rb->mmap_count,\s*1\);', ring): + lines.append('\trefcount_set(&rb->mmap_count, 1);') + return '\n'.join(lines) + + +HARNESS = r''' +#include +#include +#include +#include +#include +#include +#include +#include + +#define RB_USER4K $RB_USER4K + +typedef long atomic_long_t; +typedef long long atomic64_t; +typedef unsigned long long u64; +typedef unsigned long pgoff_t; + +#define PAGE_SHIFT 14 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE - 1)) +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#define ilog2(n) (31 - __builtin_clz((unsigned int)(n))) +#define READ_ONCE(x) (x) +#define IS_ALIGNED(x, a) (((x) & ((a) - 1)) == 0) +#define VM_SHARED 0x1 +#define VM_WRITE 0x2 +#define VM_DONTCOPY 0x0 +#define VM_DONTEXPAND 0x0 +#define VM_DONTDUMP 0x0 +#define CAP_IPC_LOCK 14 +#define RLIMIT_MEMLOCK 0 +#define PERF_EVENT_STATE_REVOKED (-1) + +static int warn_count, warn_printed; +static void warn_hit(int condition, const char *tag, int line) +{ + if (!condition) + return; + warn_count++; + if (warn_printed++ < 20) + printf(" WARN %s line %d fired\n", tag, line); +} +#define WARN_ON(c) warn_hit(!!(c), "WARN_ON", __LINE__) +#define WARN_ON_ONCE(c) warn_hit(!!(c), "WARN_ON_ONCE", __LINE__) + +/* --- environment knobs the real code reads ---------------------------- */ +static long sysctl_perf_event_mlock = 256UL << 20; /* KiB, kernel units */ +static unsigned long h_rlimit_memlock = 1UL << 40; /* bytes */ +static int h_paranoid = 1; +static int h_capable = 0; +static int h_cpus = 1; +static int rb_alloc_aux_fail = 0; +static int map_range_fail = 0; + +static int num_online_cpus(void) { return h_cpus; } +static unsigned long rlimit(int which) { (void)which; return h_rlimit_memlock; } +static int perf_is_paranoid(void) { return h_paranoid; } +static int capable(int cap) { (void)cap; return h_capable; } + +/* --- shims ------------------------------------------------------------ */ +struct user_struct { + atomic_long_t perf_mlock; + atomic_long_t locked_vm; +}; +static struct user_struct test_user; +static struct user_struct *current_user(void) { return &test_user; } +#define get_current_user() current_user() + +struct mm_struct { + atomic64_t pinned_vm; + unsigned int page_shift; +}; +static unsigned int mm_page_shift(struct mm_struct *mm) { return mm->page_shift; } +static unsigned long mm_page_size(struct mm_struct *mm) { return 1UL << mm->page_shift; } + +struct file; +struct perf_event; +struct perf_buffer; +struct vm_operations_struct; + +struct vm_area_struct { + unsigned long vm_start, vm_end; + unsigned long vm_pgoff; + unsigned long vm_flags; + unsigned int vm_subpage_offset; + struct mm_struct *vm_mm; + struct file *vm_file; + const struct vm_operations_struct *vm_ops; +}; +static inline unsigned int vma_subpage_offset(const struct vm_area_struct *vma) +{ + return vma->vm_subpage_offset; +} +#define vm_flags_set(v, f) ((void)(f)) + +struct file { void *private_data; }; + +struct perf_event_mmap_page { + u64 aux_offset; + u64 aux_size; +}; + +struct list_head { struct list_head *next, *prev; }; +#define INIT_LIST_HEAD(l) do { (l)->next = (l)->prev = (l); } while (0) +static void list_add_rcu(struct list_head *new_, struct list_head *head) +{ + new_->next = head->next; + new_->prev = head; + head->next->prev = new_; + head->next = new_; +} +static void list_del_rcu(struct list_head *entry) +{ + entry->prev->next = entry->next; + entry->next->prev = entry->prev; + entry->prev = entry->next = entry; +} +#define container_of_(p, t, m) ((t *)((char *)(p) - __builtin_offsetof(t, m))) +#define list_for_each_entry_rcu(pos, head, m) \ + for (pos = container_of_((head)->next, typeof(*pos), m); \ + &pos->m != (head); \ + pos = container_of_(pos->m.next, typeof(*pos), m)) +static void rcu_read_lock(void) { } +static void rcu_read_unlock(void) { } + +typedef struct { int refs; } refcount_t; +static void refcount_set(refcount_t *r, int v) { r->refs = v; } +static int refcount_read(refcount_t *r) { return r->refs; } +static bool refcount_inc_not_zero(refcount_t *r) +{ + if (r->refs <= 0) + return false; + r->refs++; + return true; +} +static void refcount_inc(refcount_t *r) { assert(r->refs > 0); r->refs++; } +static void refcount_dec(refcount_t *r) { assert(r->refs > 0); r->refs--; } +static bool refcount_dec_and_test(refcount_t *r) +{ + assert(r->refs > 0); + return --r->refs == 0; +} + +struct mutex { int locked; }; +static void mutex_lock(struct mutex *m) { assert(!m->locked); m->locked = 1; } +static void mutex_unlock(struct mutex *m) { assert(m->locked); m->locked = 0; } +static void mutex_init(struct mutex *m) { m->locked = 0; } +static void h_mutex_unlock_cb(struct mutex **m) +{ + if (*m) + mutex_unlock(*m); /* scoped_guard step already nulled it */ +} +static bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *m) +{ + assert(r->refs > 0); + if (--r->refs != 0) + return false; + mutex_lock(m); + return true; +} +#define H_CAT_(a, b) a##b +#define H_CAT(a, b) H_CAT_(a, b) +#define scoped_guard(scope, lock) \ + for (struct mutex *H_CAT(h_sgl_, __LINE__) \ + __attribute__((cleanup(h_mutex_unlock_cb))) = \ + (mutex_lock(lock), (struct mutex *)(lock)), \ + *H_CAT(h_sgq_, __LINE__) = H_CAT(h_sgl_, __LINE__); \ + H_CAT(h_sgq_, __LINE__) != NULL; \ + H_CAT(h_sgq_, __LINE__) = NULL) +/* The tree writes guard(mutex)(&lock): the expansion must end with the + * guard function so the trailing parenthesised group becomes its call. */ +static struct mutex *h_mutex_guard_fn(struct mutex *m) +{ + mutex_lock(m); + return m; +} +#define guard(scope) \ + struct mutex *H_CAT(h_g_, __LINE__) \ + __attribute__((cleanup(h_mutex_unlock_cb))) = h_mutex_guard_fn + +#define RING_BUFFER_WRITABLE 0x01 +#define atomic_long_sub(v, p) (*(p) -= (v)) +#define atomic_long_add(v, p) (*(p) += (v)) +#define atomic_long_set(p, v) (*(p) = (v)) +#define atomic_long_read(p) (*(p)) +#define atomic64_sub(v, p) (*(p) -= (v)) +#define atomic64_add(v, p) (*(p) += (v)) +#define atomic64_read(p) (*(p)) +#define atomic_long_inc_not_zero(p) \ + ({ long *h_p_ = (long *)(p); bool h_r_ = false; \ + if (*h_p_ > 0) { (*h_p_)++; h_r_ = true; } \ + h_r_; }) +#define likely(x) (x) +#define unlikely(x) (x) + +static bool is_power_of_2(unsigned long n) +{ + return n != 0 && (n & (n - 1)) == 0; +} + +typedef void (*mapped_f)(struct perf_event *, struct mm_struct *); +enum perf_event_mapped_state { event_unmapped, event_mapped }; +static inline mapped_f get_mapped(struct perf_event *event, int which) +{ + (void)event; (void)which; + return NULL; +} + +struct vm_operations_struct { int unused_; }; +static const struct vm_operations_struct perf_mmap_vmops = { 0 }; + +/* --- tree shapes ------------------------------------------------------- */ +struct perf_buffer { + refcount_t refcount; + refcount_t mmap_count; + refcount_t aux_mmap_count; + refcount_t aux_refcount; + unsigned long mmap_locked; + unsigned long aux_mmap_locked; + struct user_struct *mmap_user; + struct list_head event_list; + struct mutex aux_mutex; + int nr_pages; + int aux_nr_pages; + long aux_watermark; + struct perf_event_mmap_page *user_page; +#if RB_USER4K + unsigned int data_page_shift; + unsigned int mmap_page_shift; + u64 aux_offset; +#else + unsigned long aux_pgoff; + int page_order; +#endif +}; + +struct perf_event_context { void *parent_ctx; }; +struct perf_event_attr { + long watermark; + long wakeup_watermark; + long aux_watermark; + int inherit; +}; +struct perf_event { + int cpu; + int state; + struct perf_event_attr attr; + struct perf_event_context *ctx; + /* atomic_long_t as in the tree: the rb->event_list walk in + * perf_mmap_close() takes a ref on every event, so the stub must + * hold list-sized counts */ + atomic_long_t refcount; + refcount_t mmap_count; + struct mutex mmap_mutex; + struct perf_buffer *rb; + struct list_head rb_entry; +}; + +/* --- stub declarations (definitions below the extracted helpers) ------- */ +$rb_alloc_decl +$rb_alloc_aux_decl +static void rb_free_aux(struct perf_buffer *rb); +static void rb_free(struct perf_buffer *rb); +static struct perf_buffer *ring_buffer_get(struct perf_event *event); +static void ring_buffer_put(struct perf_buffer *rb); +static void ring_buffer_attach(struct perf_event *event, struct perf_buffer *rb); +static void perf_event_update_time(struct perf_event *event); +static void perf_event_init_userpage(struct perf_event *event); +static void perf_event_update_userpage(struct perf_event *event); +static void perf_pmu_output_stop(struct perf_event *event); +static int security_perf_event_read(struct perf_event *event); +static void put_event(struct perf_event *event); +static int map_range(struct perf_buffer *rb, struct vm_area_struct *vma); + +/* --- accounting code taken from the tree under test -------------------- */ +$helpers + +/* --- harness stub definitions ------------------------------------------ */ +static int rb_allocs, rb_frees, aux_allocs, aux_frees, map_range_calls; + +#if RB_USER4K +struct perf_buffer *rb_alloc(unsigned long data_size, unsigned int mmap_page_shift, + long watermark, int cpu, int flags) +{ + struct perf_buffer *rb; + int nr_pages = $rb_nr_pages; + + (void)watermark; (void)cpu; (void)flags; + rb = calloc(1, sizeof(*rb) + nr_pages * sizeof(void *)); + if (!rb) + return NULL; + rb->nr_pages = nr_pages; + rb->mmap_page_shift = mmap_page_shift; +$rb_data_shift + rb->user_page = calloc(1, sizeof(*rb->user_page)); + if (!rb->user_page) { + free(rb); + return NULL; + } +$rb_init + INIT_LIST_HEAD(&rb->event_list); + mutex_init(&rb->aux_mutex); + refcount_set(&rb->refcount, 1); + rb_allocs++; + return rb; +} +#else +struct perf_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) +{ + struct perf_buffer *rb; + + (void)watermark; (void)cpu; (void)flags; + rb = calloc(1, sizeof(*rb) + nr_pages * sizeof(void *)); + if (!rb) + return NULL; + rb->nr_pages = nr_pages; + rb->page_order = 0; + rb->user_page = calloc(1, sizeof(*rb->user_page)); + if (!rb->user_page) { + free(rb); + return NULL; + } +$rb_init + INIT_LIST_HEAD(&rb->event_list); + mutex_init(&rb->aux_mutex); + refcount_set(&rb->refcount, 1); + rb_allocs++; + return rb; +} +#endif + +$rb_alloc_aux_def + +static void rb_free_aux(struct perf_buffer *rb) +{ + assert(rb->aux_nr_pages); + rb->aux_nr_pages = 0; + refcount_set(&rb->aux_refcount, 0); + aux_frees++; +} + +static void rb_free(struct perf_buffer *rb) +{ + rb_frees++; + free(rb->user_page); + free(rb); +} + +/* Mirrors the tree's ring_buffer_attach(): the rb_alloc() initial refcount + * IS the first event's attach reference, attach() adds no reference, and + * detach puts the old rb (which frees it when it hits zero). */ +static void ring_buffer_attach(struct perf_event *event, struct perf_buffer *rb) +{ + struct perf_buffer *old_rb = NULL; + + if (rb && rb == event->rb) + return; + if (event->rb) { + old_rb = event->rb; + list_del_rcu(&event->rb_entry); + } + event->rb = rb; + if (rb) + list_add_rcu(&event->rb_entry, &rb->event_list); + if (old_rb) + ring_buffer_put(old_rb); +} + +static struct perf_buffer *ring_buffer_get(struct perf_event *event) +{ + struct perf_buffer *rb = event->rb; + + if (rb) + refcount_inc(&rb->refcount); + return rb; +} + +static void ring_buffer_put(struct perf_buffer *rb) +{ + if (refcount_dec_and_test(&rb->refcount)) + rb_free(rb); +} + +static void perf_event_update_time(struct perf_event *event) { (void)event; } +static void perf_event_init_userpage(struct perf_event *event) { (void)event; } +static void perf_event_update_userpage(struct perf_event *event) { (void)event; } +static void perf_pmu_output_stop(struct perf_event *event) { (void)event; } +static int security_perf_event_read(struct perf_event *event) { (void)event; return 0; } +static void put_event(struct perf_event *event) { (void)event; } + +static int map_range(struct perf_buffer *rb, struct vm_area_struct *vma) +{ + (void)rb; (void)vma; + map_range_calls++; + if (map_range_fail) + return -ENOMEM; + return 0; +} + +/* --- lifecycle driver --------------------------------------------------- */ +static struct perf_event ev; +static struct perf_event_context ctx; +static struct mm_struct mm; +static struct file file; + +static void reset_all(unsigned int mm_shift) +{ + memset(&ev, 0, sizeof(ev)); + memset(&ctx, 0, sizeof(ctx)); + memset(&mm, 0, sizeof(mm)); + memset(&file, 0, sizeof(file)); + ev.cpu = 0; + ev.ctx = &ctx; + ev.state = 0; + mutex_init(&ev.mmap_mutex); + atomic_long_set(&ev.refcount, 2); + mm.page_shift = mm_shift; + file.private_data = &ev; + test_user.perf_mlock = 0; + test_user.locked_vm = 0; + mm.pinned_vm = 0; + rb_allocs = rb_frees = aux_allocs = aux_frees = 0; + map_range_calls = 0; + warn_count = 0; + warn_printed = 0; + rb_alloc_aux_fail = 0; + map_range_fail = 0; + sysctl_perf_event_mlock = 256UL << 20; + h_rlimit_memlock = 1UL << 40; + h_paranoid = 1; + h_capable = 0; + h_cpus = 1; +} + +/* Point user_lock_limit at `pages` pages for one CPU (kernel units: KiB). */ +static void set_user_lock_limit(unsigned long pages) +{ + sysctl_perf_event_mlock = (long)pages << (PAGE_SHIFT - 10); +} + +static struct vm_area_struct make_vma_bytes(unsigned long bytes, unsigned long pgoff) +{ + struct vm_area_struct v; + + memset(&v, 0, sizeof(v)); + v.vm_start = 0x100000000UL; + v.vm_end = v.vm_start + bytes; + v.vm_pgoff = pgoff; + v.vm_flags = VM_SHARED | VM_WRITE; + v.vm_mm = &mm; + v.vm_file = &file; + return v; +} + +static void dump(const char *tag) +{ + struct perf_buffer *rb = ev.rb; + + printf(" %-26s perf_mlock=%ld locked_vm=%ld pinned=%ld " + "ev.mmap_count=%d rb->mmap_count=%d rb=%d " + "alloc=%d/%d aux=%d/%d warns=%d\n", tag, + test_user.perf_mlock, test_user.locked_vm, (long)mm.pinned_vm, + ev.mmap_count.refs, rb ? rb->mmap_count.refs : -1, rb != NULL, + rb_allocs, rb_frees, aux_allocs, aux_frees, warn_count); +} + +static long user_perf_mlock(void) { return test_user.perf_mlock; } +static long user_locked_vm(void) { return test_user.locked_vm; } + +/* The tree charges exactly one user counter ($charge_counter) and must + * leave the other ($spare_counter) untouched: assert both individually, + * so a transfer between them cannot pose as unchanged or balanced. */ +static int user_charge_broken(const char *what, long want) +{ + int bad = 0; + + if (user_$charge_counter() != want) { + printf(" OBSERVED %s: $charge_counter %ld, expected %ld\n", + what, user_$charge_counter(), want); + bad = 1; + } + if (user_$spare_counter() != 0) { + printf(" OBSERVED %s: $spare_counter nonzero (%ld), expected 0\n", + what, user_$spare_counter()); + bad = 1; + } + return bad; +} + +static int invariants_broken(const char *what) +{ + int bad = 0; + struct perf_buffer *rb = ev.rb; + + /* each user counter individually: a +leak on one and a -leak on + * the other would hide behind a summed total */ + if (user_perf_mlock()) { + printf(" OBSERVED %s: perf_mlock leaked %ld pages\n", + what, user_perf_mlock()); + bad = 1; + } + if (user_locked_vm()) { + printf(" OBSERVED %s: locked_vm leaked %ld pages\n", + what, user_locked_vm()); + bad = 1; + } + if (mm.pinned_vm) { + printf(" OBSERVED %s: pinned_vm leaked %ld pages\n", + what, (long)mm.pinned_vm); + bad = 1; + } + if (rb_allocs != rb_frees || aux_allocs != aux_frees) { + printf(" OBSERVED %s: allocation imbalance rb %d/%d aux %d/%d\n", + what, rb_allocs, rb_frees, aux_allocs, aux_frees); + bad = 1; + } + if (ev.mmap_count.refs != 0 || rb != NULL || ev.rb != NULL) { + printf(" OBSERVED %s: stale refs ev.mmap_count=%d rb=%d\n", + what, ev.mmap_count.refs, ev.rb != NULL); + bad = 1; + } + if (warn_count) { + printf(" OBSERVED %s: %d WARN_ON fires\n", what, warn_count); + bad = 1; + } + return bad; +} + +/* Assert the user counters and pinned_vm individually at an intermediate + * step, so a charge/uncharge mismatch on either counter is reported on + * its own instead of only via the final zero check. */ +static int check_split(const char *what, long want_user, long want_pinned) +{ + int bad = user_charge_broken(what, want_user); + + if (mm.pinned_vm != want_pinned) { + printf(" OBSERVED %s: pinned_vm %ld, expected %ld\n", + what, (long)mm.pinned_vm, want_pinned); + bad |= 1; + } + return bad; +} + +/* --- scenarios ---------------------------------------------------------- + * A ring geometry is (vma_pages, mm_shift): vma_pages = data pages + 1 + * metadata page; vma_pages == 1 is a metadata-only ring; the user4k + * sub-native geometry uses a 4K-page mm so the data chunk (4K) is smaller + * than the native (16K) page. charge = pages the tree charges for the + * first ring mmap. split = pages of the first charge spilled into + * pinned_vm via the tree's own perf_mmap_calc_limits(): 0 none, >0 partial, + * -1 full spill. + */ +static long ring_charge(unsigned long vma_pages, unsigned long mm_shift) +{ +#if RB_USER4K + return DIV_ROUND_UP((long)(vma_pages - 1) << mm_shift, PAGE_SIZE) + 1; +#else + return vma_pages; +#endif +} + +static void setup_limits(long split) +{ + if (split == 0) + return; /* default generous limit, no split */ + if (split < 0) { + set_user_lock_limit(0); /* full spill */ + return; + } + set_user_lock_limit(charge_expect - split); +} + +static int sc_rb_baseline(unsigned long vma_pages, unsigned long mm_shift, long split) +{ + struct vm_area_struct v; + + reset_all(mm_shift); + charge_expect = ring_charge(vma_pages, mm_shift); + setup_limits(split); + + v = make_vma_bytes(vma_pages << mm_shift, 0); + if (perf_mmap(&file, &v)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + dump("after first mmap"); + perf_mmap_close(&v); + dump("after close"); + return invariants_broken("baseline ring lifecycle"); +} + +/* One duplicate-ring-alias lifecycle. Close order: aliases first when + * orig_first is 0; the original mapping first, while every alias is + * still live, when orig_first is 1. */ +static int rb_dup_cycle(unsigned long vma_pages, unsigned long mm_shift, + long split, int orig_first) +{ + struct vm_area_struct v[4]; /* 0 = ring, 1..3 = aliases */ + int i, bad = 0; + long user_first, pinned_first; + + reset_all(mm_shift); + charge_expect = ring_charge(vma_pages, mm_shift); + setup_limits(split); + user_first = split < 0 ? 0 : charge_expect - (split > 0 ? split : 0); + pinned_first = split < 0 ? charge_expect : (split > 0 ? split : 0); + + v[0] = make_vma_bytes(vma_pages << mm_shift, 0); + if (perf_mmap(&file, &v[0])) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + dump("after first mmap"); + bad |= check_split("after first mmap", user_first, pinned_first); + for (i = 1; i < 4; i++) { + v[i] = make_vma_bytes(vma_pages << mm_shift, 0); + if (perf_mmap(&file, &v[i])) { + printf(" UNEXPECTED alias mmap %d failed\n", i); + return 1; + } + dump("after alias mmap"); + /* an alias shares the already-locked pages: no new charge */ + bad |= check_split("after alias mmap", user_first, pinned_first); + } + if (orig_first) { + /* alternate order: the original mapping closes while all + * three aliases are still live; the charge must stay put + * until the last alias closes */ + perf_mmap_close(&v[0]); + dump("after original close"); + bad |= check_split("after original close", user_first, + pinned_first); + for (i = 1; i < 4; i++) { + perf_mmap_close(&v[i]); + dump(i == 3 ? "after final close" : "after alias close"); + /* the last close completes the lifecycle: its zero + * check is invariants_broken() below */ + if (i < 3) + bad |= check_split("after alias close", + user_first, pinned_first); + } + } else { + for (i = 1; i < 4; i++) { + perf_mmap_close(&v[i]); + dump("after alias close"); + bad |= check_split("after alias close", user_first, + pinned_first); + } + perf_mmap_close(&v[0]); + dump("after final close"); + } + bad |= invariants_broken(orig_first + ? "duplicate ring aliases (3), original closed first" + : "duplicate ring aliases (3)"); + printf(" expected first charge: %ld user + %ld pinned; aliases add no charge\n", + user_first, pinned_first); + return bad; +} + +static int sc_rb_duplicate(unsigned long vma_pages, unsigned long mm_shift, long split) +{ + /* both close orders must balance */ + return rb_dup_cycle(vma_pages, mm_shift, split, 0) | + rb_dup_cycle(vma_pages, mm_shift, split, 1); +} + +static int sc_rb_alias_map_range_fail(long split) +{ + struct vm_area_struct v[2]; + int bad = 0; + long user_first, pinned_first; + + reset_all(PAGE_SHIFT); + charge_expect = ring_charge(17, PAGE_SHIFT); + setup_limits(split); + user_first = split < 0 ? 0 : charge_expect - (split > 0 ? split : 0); + pinned_first = split < 0 ? charge_expect : (split > 0 ? split : 0); + + v[0] = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &v[0])) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + dump("after first mmap"); + + map_range_fail = 1; + v[1] = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (!perf_mmap(&file, &v[1])) { + printf(" UNEXPECTED failing alias mmap succeeded\n"); + map_range_fail = 0; + return 1; + } + map_range_fail = 0; + dump("after FAILED alias mmap (map_range)"); + /* the failed alias charged nothing: counters still hold only the + * first map's split */ + bad |= check_split("after FAILED alias mmap (map_range)", + user_first, pinned_first); + + if (ev.mmap_count.refs != 1 || ev.rb == NULL || + ev.rb->mmap_count.refs != 1) { + printf(" UNEXPECTED refcount unwind after failed alias\n"); + bad = 1; + } + perf_mmap_close(&v[0]); + dump("after final close"); + return invariants_broken("failed ring alias via map_range") || bad; +} + +static int sc_rb_first_map_range_fail(long split) +{ + struct vm_area_struct v; + int bad; + + reset_all(PAGE_SHIFT); + charge_expect = ring_charge(17, PAGE_SHIFT); + setup_limits(split); + + map_range_fail = 1; + v = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (!perf_mmap(&file, &v)) { + printf(" UNEXPECTED failing first mmap succeeded\n"); + map_range_fail = 0; + return 1; + } + map_range_fail = 0; + dump("after FAILED first mmap (map_range)"); + bad = invariants_broken("failed first ring mmap via map_range"); + return bad; +} + +static unsigned long aux_request(struct perf_buffer *rb, unsigned long aux_pages) +{ + unsigned long base; + + base = (perf_data_size(rb) +#if RB_USER4K + + perf_metadata_size(rb) +#else + + PAGE_SIZE +#endif + ) >> PAGE_SHIFT; + /* Userspace announces the AUX layout through the shared user page + * before the first AUX mmap (same values the tree checks for). */ + rb->user_page->aux_offset = (u64)base << PAGE_SHIFT; + rb->user_page->aux_size = (u64)aux_pages << PAGE_SHIFT; + return base; +} + +static int sc_aux_baseline(void) +{ + struct vm_area_struct vring, vaux; + int bad; + + reset_all(PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + aux_pgoff_target = aux_request(ev.rb, 8); + vaux = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (perf_mmap(&file, &vaux)) { + printf(" UNEXPECTED aux mmap failed\n"); + return 1; + } + dump("after aux mmap"); + perf_mmap_close(&vaux); + dump("after aux close"); + perf_mmap_close(&vring); + dump("after ring close"); + bad = invariants_broken("baseline aux lifecycle"); + return bad; +} + +/* One duplicate-AUX-alias lifecycle. Close order: AUX aliases then the + * normal ring VMA when ring_first is 0; the normal ring VMA first, + * while the AUX area stays live, when ring_first is 1. */ +static int aux_dup_cycle(long split, int ring_first) +{ + struct vm_area_struct vring, vaux[4]; + int i, bad = 0; + long ring_chg = ring_charge(17, PAGE_SHIFT); + long aux_user, aux_pinned; /* the AUX charge's own split */ + + reset_all(PAGE_SHIFT); + + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + if (split < 0) + set_user_lock_limit(0); + else if (split > 0) + /* the ring already sits in the user counter: the AUX charge + * of 8 pages must split 5 user / `split` pinned against a + * limit of current-user + (8 - split) */ + set_user_lock_limit(ring_chg + 8 - split); + aux_user = split < 0 ? 0 : 8 - split; + aux_pinned = split < 0 ? 8 : split; + + aux_pgoff_target = aux_request(ev.rb, 8); + vaux[0] = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (perf_mmap(&file, &vaux[0])) { + printf(" UNEXPECTED aux mmap failed\n"); + return 1; + } + dump("after first aux mmap"); + bad |= check_split("after first aux mmap", ring_chg + aux_user, + aux_pinned); + for (i = 1; i < 4; i++) { + vaux[i] = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (perf_mmap(&file, &vaux[i])) { + printf(" UNEXPECTED aux alias mmap %d failed\n", i); + return 1; + } + dump("after aux alias mmap"); + /* an alias shares the already-locked pages: no new charge */ + bad |= check_split("after aux alias mmap", ring_chg + aux_user, + aux_pinned); + } + if (ring_first) { + /* alternate order: the normal ring VMA closes while the + * AUX area stays live; the AUX mappings still hold + * rb->mmap_count, so neither charge may uncharge yet */ + perf_mmap_close(&vring); + dump("after ring close (aux live)"); + bad |= check_split("after ring close (aux live)", + ring_chg + aux_user, aux_pinned); + } + for (i = 1; i < 4; i++) { + perf_mmap_close(&vaux[i]); + dump("after aux alias close"); + bad |= check_split("after aux alias close", ring_chg + aux_user, + aux_pinned); + } + perf_mmap_close(&vaux[0]); + if (ring_first) { + /* the last AUX close empties rb->mmap_count: the ring and + * AUX charges uncharge together here */ + dump("after last aux close (all uncharge)"); + } else { + dump("after last aux close (aux uncharge)"); + perf_mmap_close(&vring); + dump("after ring close"); + } + bad |= invariants_broken(ring_first + ? "duplicate aux aliases (3), ring closed first" + : "duplicate aux aliases (3)"); + return bad; +} + +static int sc_aux_duplicate(long split) +{ + /* both close orders must balance */ + return aux_dup_cycle(split, 0) | aux_dup_cycle(split, 1); +} + +static int sc_aux_limit_fail(void) +{ + struct vm_area_struct vring, vaux; + int bad = 0; + + reset_all(PAGE_SHIFT); + charge_expect = ring_charge(17, PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + aux_pgoff_target = aux_request(ev.rb, 8); + + /* Force the tree's own calc_limits to reject: pinned_vm pressure. */ + h_rlimit_memlock = 4UL << 20; /* 256 native pages */ + mm.pinned_vm = 300; + vaux = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (!perf_mmap(&file, &vaux)) { + printf(" UNEXPECTED over-limit aux mmap succeeded\n"); + return 1; + } + dump("after REJECTED aux mmap (-EPERM)"); + bad |= user_charge_broken("after REJECTED aux mmap (-EPERM)", + charge_expect); + if (ev.rb->mmap_count.refs != 1 || ev.rb->aux_mmap_count.refs != 0 || + ev.mmap_count.refs != 1 || aux_allocs != 0) { + printf(" UNEXPECTED unwound state after -EPERM aux " + "(rbmc=%d auxmc=%d evmc=%d auxa=%d)\n", + ev.rb->mmap_count.refs, ev.rb->aux_mmap_count.refs, + ev.mmap_count.refs, aux_allocs); + bad = 1; + } + mm.pinned_vm = 0; /* the -EPERM trigger preload, not a leak */ + perf_mmap_close(&vring); + dump("after ring close"); + return invariants_broken("aux limit-rejected first map") || bad; +} + +static int sc_aux_alloc_fail(void) +{ + struct vm_area_struct vring, vaux; + int bad = 0; + + reset_all(PAGE_SHIFT); + charge_expect = ring_charge(17, PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + aux_pgoff_target = aux_request(ev.rb, 8); + + rb_alloc_aux_fail = 1; + vaux = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (!perf_mmap(&file, &vaux)) { + printf(" UNEXPECTED failing aux mmap succeeded\n"); + rb_alloc_aux_fail = 0; + return 1; + } + rb_alloc_aux_fail = 0; + dump("after FAILED aux mmap (rb_alloc_aux)"); + bad |= user_charge_broken("after FAILED aux mmap (rb_alloc_aux)", + charge_expect); + if (ev.rb->mmap_count.refs != 1 || ev.rb->aux_mmap_count.refs != 0 || + ev.mmap_count.refs != 1 || aux_allocs != 0) { + printf(" UNEXPECTED unwound state after rb_alloc_aux failure " + "(rbmc=%d auxmc=%d evmc=%d auxa=%d)\n", + ev.rb->mmap_count.refs, ev.rb->aux_mmap_count.refs, + ev.mmap_count.refs, aux_allocs); + bad = 1; + } + perf_mmap_close(&vring); + dump("after ring close"); + return invariants_broken("aux rb_alloc_aux failure") || bad; +} + +static int sc_aux_alias_size_reject(void) +{ + struct vm_area_struct vring, vaux, vbad; + struct perf_buffer *rb; + int bad = 0; + long before_mlock, before_locked; + + reset_all(PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + rb = ev.rb; + aux_pgoff_target = aux_request(rb, 8); + vaux = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (perf_mmap(&file, &vaux)) { + printf(" UNEXPECTED aux mmap failed\n"); + return 1; + } + before_mlock = user_perf_mlock(); + before_locked = user_locked_vm(); + + /* A wrong-size alias must be rejected before any refcount or charge. */ + vbad = make_vma_bytes(4 << PAGE_SHIFT, aux_pgoff_target); + if (!perf_mmap(&file, &vbad)) { + printf(" UNEXPECTED wrong-size aux alias succeeded\n"); + return 1; + } + dump("after REJECTED wrong-size aux alias"); + if (user_perf_mlock() != before_mlock || + user_locked_vm() != before_locked || + rb->mmap_count.refs != 2 || + rb->aux_mmap_count.refs != 1 || ev.mmap_count.refs != 2) { + printf(" UNEXPECTED state after rejected alias\n"); + bad = 1; + } + perf_mmap_close(&vaux); + perf_mmap_close(&vring); + dump("after closes"); + return invariants_broken("wrong-size aux alias") || bad; +} + +static int sc_aux_alias_map_range_fail(long split) +{ + struct vm_area_struct vring, vaux[2]; + struct perf_buffer *rb; + int bad = 0; + + reset_all(PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + rb = ev.rb; + if (split < 0) + set_user_lock_limit(0); + else if (split > 0) + /* the ring already sits in the user counter (see + * sc_aux_duplicate): limit = current-user + (8 - split) */ + set_user_lock_limit(ring_charge(17, PAGE_SHIFT) + 8 - split); + aux_pgoff_target = aux_request(rb, 8); + vaux[0] = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (perf_mmap(&file, &vaux[0])) { + printf(" UNEXPECTED aux mmap failed\n"); + return 1; + } + dump("after first aux mmap"); + + map_range_fail = 1; + vaux[1] = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (!perf_mmap(&file, &vaux[1])) { + printf(" UNEXPECTED failing aux alias mmap succeeded\n"); + map_range_fail = 0; + return 1; + } + map_range_fail = 0; + dump("after FAILED aux alias mmap (map_range)"); + /* the failed alias charged nothing: counters still hold only the + * ring's charge plus the first AUX map's split */ + bad |= check_split("after FAILED aux alias mmap (map_range)", + ring_charge(17, PAGE_SHIFT) + + (split < 0 ? 0 : 8 - split), + split < 0 ? 8 : split); + if (ev.mmap_count.refs != 2 || rb->mmap_count.refs != 2 || + rb->aux_mmap_count.refs != 1) { + printf(" UNEXPECTED refcount unwind after failed aux alias\n"); + bad = 1; + } + perf_mmap_close(&vaux[0]); + dump("after last aux close"); + perf_mmap_close(&vring); + dump("after ring close"); + return invariants_broken("failed aux alias via map_range") || bad; +} + +static int sc_aux_first_map_range_fail(void) +{ + struct vm_area_struct vring, vaux; + int bad = 0; + + reset_all(PAGE_SHIFT); + charge_expect = ring_charge(17, PAGE_SHIFT); + vring = make_vma_bytes(17 << PAGE_SHIFT, 0); + if (perf_mmap(&file, &vring)) { + printf(" UNEXPECTED first mmap failed\n"); + return 1; + } + aux_pgoff_target = aux_request(ev.rb, 8); + + map_range_fail = 1; + vaux = make_vma_bytes(8 << PAGE_SHIFT, aux_pgoff_target); + if (!perf_mmap(&file, &vaux)) { + printf(" UNEXPECTED failing first aux mmap succeeded\n"); + map_range_fail = 0; + return 1; + } + map_range_fail = 0; + dump("after FAILED first aux mmap (map_range)"); + /* perf_mmap_close() must have unwound the whole AUX allocation: + * the ring keeps its own charge, the AUX charge and allocation + * are gone again, each counter checked individually */ + bad |= user_charge_broken("after FAILED first aux mmap (map_range)", + charge_expect); + if (mm.pinned_vm != 0 || + ev.rb->mmap_count.refs != 1 || ev.rb->aux_mmap_count.refs != 0 || + ev.mmap_count.refs != 1 || aux_allocs != aux_frees) { + printf(" UNEXPECTED unwound state after failed first aux " + "(pinned=%ld rbmc=%d auxmc=%d evmc=%d " + "auxa=%d auxf=%d)\n", + (long)mm.pinned_vm, + ev.rb->mmap_count.refs, ev.rb->aux_mmap_count.refs, + ev.mmap_count.refs, aux_allocs, aux_frees); + bad = 1; + } + perf_mmap_close(&vring); + dump("after ring close"); + return invariants_broken("failed first aux mmap via map_range") || bad; +} + +int main(void) +{ + int failures = 0; + unsigned long geos[][2] = { /* vma_pages, mm_shift */ + { 17, PAGE_SHIFT }, /* 16 data pages + metadata */ + { 1, PAGE_SHIFT }, /* metadata-only */ + { 2, 12 }, /* user4k: 1 data chunk of 4K on a 4K mm */ + }; + long splits[] = { 0, 3, -1 }; /* none, partial, full spill */ + const char *geo_names[] = { "ring16+meta", "metadata-only", "sub4k-1chunk+meta" }; + const char *lim_names[] = { "nosplit", "partialsplit3", "fullspill" }; + int g, s; + + for (g = 0; g < 3; g++) { + if (g == 2 && !RB_USER4K) + continue; + printf("-- scenario rb-baseline geometry=%s\n", geo_names[g]); + if (sc_rb_baseline(geos[g][0], geos[g][1], 0)) { + printf("RESULT scenario=rb-baseline geometry=%s status=FAIL\n", + geo_names[g]); + failures++; + } else { + printf("RESULT scenario=rb-baseline geometry=%s status=PASS\n", + geo_names[g]); + } + } + for (s = 0; s < 3; s++) { + for (g = 0; g < 3; g++) { + long split = splits[s]; + const char *lim = lim_names[s]; + char limname[32]; + long ringchg = ring_charge(geos[g][0], geos[g][1]); + + if (g == 2 && !RB_USER4K) + continue; + if (split > 0 && split >= ringchg) { + /* this charge cannot give up `split` pages + * to pinned_vm; use the largest valid + * partial spill instead of letting the + * limit underflow into "no limit" */ + split = ringchg - 1; + if (split <= 0) { + split = -1; /* cannot split at all */ + lim = lim_names[2]; + } else { + snprintf(limname, sizeof(limname), + "partialsplit%ld", split); + lim = limname; + } + } + printf("-- scenario rb-duplicate geometry=%s limits=%s\n", + geo_names[g], lim); + if (sc_rb_duplicate(geos[g][0], geos[g][1], split)) { + printf("RESULT scenario=rb-duplicate geometry=%s limits=%s status=FAIL\n", + geo_names[g], lim); + failures++; + } else { + printf("RESULT scenario=rb-duplicate geometry=%s limits=%s status=PASS\n", + geo_names[g], lim); + } + } + } + for (s = 0; s < 3; s += 2) { /* nosplit and fullspill */ + printf("-- scenario rb-alias-map-range-fail limits=%s\n", lim_names[s]); + if (sc_rb_alias_map_range_fail(splits[s])) { + printf("RESULT scenario=rb-alias-map-range-fail limits=%s status=FAIL\n", + lim_names[s]); + failures++; + } else { + printf("RESULT scenario=rb-alias-map-range-fail limits=%s status=PASS\n", + lim_names[s]); + } + printf("-- scenario rb-first-map-range-fail limits=%s\n", lim_names[s]); + if (sc_rb_first_map_range_fail(splits[s])) { + printf("RESULT scenario=rb-first-map-range-fail limits=%s status=FAIL\n", + lim_names[s]); + failures++; + } else { + printf("RESULT scenario=rb-first-map-range-fail limits=%s status=PASS\n", + lim_names[s]); + } + } + printf("-- scenario aux-baseline\n"); + if (sc_aux_baseline()) { + printf("RESULT scenario=aux-baseline status=FAIL\n"); + failures++; + } else { + printf("RESULT scenario=aux-baseline status=PASS\n"); + } + for (s = 0; s < 3; s++) { + printf("-- scenario aux-duplicate limits=%s\n", lim_names[s]); + if (sc_aux_duplicate(splits[s])) { + printf("RESULT scenario=aux-duplicate limits=%s status=FAIL\n", + lim_names[s]); + failures++; + } else { + printf("RESULT scenario=aux-duplicate limits=%s status=PASS\n", + lim_names[s]); + } + } + printf("-- scenario aux-limit-reject\n"); + if (sc_aux_limit_fail()) { + printf("RESULT scenario=aux-limit-reject status=FAIL\n"); + failures++; + } else { + printf("RESULT scenario=aux-limit-reject status=PASS\n"); + } + printf("-- scenario aux-alloc-fail\n"); + if (sc_aux_alloc_fail()) { + printf("RESULT scenario=aux-alloc-fail status=FAIL\n"); + failures++; + } else { + printf("RESULT scenario=aux-alloc-fail status=PASS\n"); + } + printf("-- scenario aux-alias-size-reject\n"); + if (sc_aux_alias_size_reject()) { + printf("RESULT scenario=aux-alias-size-reject status=FAIL\n"); + failures++; + } else { + printf("RESULT scenario=aux-alias-size-reject status=PASS\n"); + } + for (s = 0; s < 3; s += 2) { + printf("-- scenario aux-alias-map-range-fail limits=%s\n", lim_names[s]); + if (sc_aux_alias_map_range_fail(splits[s])) { + printf("RESULT scenario=aux-alias-map-range-fail limits=%s status=FAIL\n", + lim_names[s]); + failures++; + } else { + printf("RESULT scenario=aux-alias-map-range-fail limits=%s status=PASS\n", + lim_names[s]); + } + } + printf("-- scenario aux-first-map-range-fail\n"); + if (sc_aux_first_map_range_fail()) { + printf("RESULT scenario=aux-first-map-range-fail status=FAIL\n"); + failures++; + } else { + printf("RESULT scenario=aux-first-map-range-fail status=PASS\n"); + } + + printf("SUMMARY failures=%d\n", failures); + return failures ? 1 : 0; +} +''' + +HARNESS_GLOBALS = ''' +static unsigned long aux_pgoff_target; +static long charge_expect; +''' + + +def source_notes(core): + """Probe the source shape so the tree under test is reported honestly.""" + notes = [] + rb = definition(core, 'perf_mmap_rb') + close = definition(core, 'perf_mmap_close') + if rb: + marker = rb.find('refcount_inc_not_zero(&event->rb->mmap_count)') + tail = rb[marker:marker + 400] if marker != -1 else '' + if 'perf_mmap_account' in tail: + notes.append('ring alias path charges perf_mmap_account() per alias') + else: + notes.append('ring alias path adds no charge ' + '(aliases share the first map\'s charge)') + if close: + count = close.count('perf_mmap_unaccount(') + notes.append('close has %d perf_mmap_unaccount call site(s) ' + '(ring uncharge happens only when rb->mmap_count ' + 'reaches 0)' % count) + return notes + + +def build(tree, out): + core_path = tree / 'kernel/events/core.c' + internal_path = tree / 'kernel/events/internal.h' + ring_path = tree / 'kernel/events/ring_buffer.c' + core = core_path.read_text() + internal = internal_path.read_text() + ring = ring_path.read_text() + + user4k, nr_pages_expr, data_shift_expr = rb_alloc_profile(ring) + init = rb_init_lines(ring) + + helpers = [] + if not user4k: + body = definition(internal, 'page_order') + if body is None: + raise SystemExit('missing page_order() in internal.h') + helpers.append(body) + for name in ('rb_has_aux', 'perf_data_size', 'data_page_nr', 'perf_aux_size'): + body = definition(internal, name) + if body is None: + raise SystemExit('missing inline %s in internal.h' % name) + helpers.append(body) + if user4k: + body = definition(internal, 'perf_metadata_size') + if body: + helpers.append(body) + body = definition(core, 'perf_mmap_offset') + if body is None: + raise SystemExit('user4k tree lacks perf_mmap_offset()') + helpers.append(body) + for name in ('perf_mmap_calc_limits', 'perf_mmap_account', + 'perf_mmap_unaccount', 'perf_mmap_rb', 'perf_mmap_aux', + 'perf_mmap_close', 'perf_mmap'): + body = definition(core, name) + if body is None: + raise SystemExit('missing %s in core.c' % name) + helpers.append(body) + + aux_decl = re.search(r'extern int rb_alloc_aux\(([^;]+)\);', internal) + if aux_decl is None: + raise SystemExit('missing rb_alloc_aux prototype in internal.h') + params = aux_decl.group(1).strip().rstrip(')') + names = [p.strip().split()[-1].lstrip('*') for p in params.split(',')] + aux_def = ('static int rb_alloc_aux(%s)\n' + '{\n' + '\tif (rb_alloc_aux_fail)\n' + '\t\treturn -ENOMEM;\t/* the real allocator frees its own partial work */\n' + '\trb->aux_nr_pages = nr_pages;\n' + '\trb->aux_watermark = watermark;\n' + '\trefcount_set(&rb->aux_refcount, 1);\n' + '#if RB_USER4K\n' + '\trb->aux_offset = %s;\n' + '#else\n' + '\trb->aux_pgoff = %s;\n' + '#endif\n' + '\taux_allocs++;\n' + '\treturn 0;\n' + '}' % (params, names[2], names[2])) + + unaccount = definition(core, 'perf_mmap_unaccount') + if unaccount is None: + raise SystemExit('missing perf_mmap_unaccount in core.c') + counter = 'perf_mlock' if 'user->perf_mlock' in unaccount else 'locked_vm' + + if user4k: + rb_alloc_decl = ('struct perf_buffer *rb_alloc(unsigned long data_size, ' + 'unsigned int mmap_page_shift, long watermark, int cpu, ' + 'int flags);') + else: + rb_alloc_decl = ('struct perf_buffer *rb_alloc(int nr_pages, ' + 'long watermark, int cpu, int flags);') + + source = HARNESS_GLOBALS + Template(HARNESS).substitute({ + 'RB_USER4K': '1' if user4k else '0', + 'rb_alloc_decl': rb_alloc_decl, + 'rb_alloc_aux_decl': 'static int rb_alloc_aux(%s);' % params, + 'rb_alloc_aux_def': aux_def, + 'helpers': '\n\n'.join(helpers), + 'rb_nr_pages': nr_pages_expr, + 'rb_data_shift': ('\trb->data_page_shift = %s;' % data_shift_expr) + if data_shift_expr else '\t/* none */', + 'rb_init': init or '\t/* tree leaves mmap_count at 0 */', + 'charge_counter': counter, + 'spare_counter': 'locked_vm' if counter == 'perf_mlock' + else 'perf_mlock', + }) + path = out / (tree.name + '.c') + path.write_text(source) + binary = out / (tree.name + '.bin') + subprocess.run([args.cc, '-std=gnu11', '-Wall', '-Werror', + '-Wno-unused-function', str(path), '-o', str(binary)], + check=True) + return binary, user4k, counter, source_notes(core) + + +overall = 0 +with tempfile.TemporaryDirectory(prefix='perf-alias-lifecycle-') as directory: + for tree in args.trees: + print('=' * 72) + print('TREE %s' % tree) + try: + binary, user4k, counter, notes = build(tree, Path(directory)) + except SystemExit as error: + print('FAIL: %s' % error) + overall = 2 + continue + except subprocess.CalledProcessError: + print('FAIL: harness build failed for %s' % tree) + src = Path(directory) / (tree.name + '.c') + if src.exists(): + print('harness source kept at %s' % src) + overall = 2 + continue + print('profile: %s, user counter: %s' % + ('user4k (data_size rb_alloc, per-mm page shift)' if user4k + else 'plain (nr_pages rb_alloc, PAGE_SHIFT)', counter)) + for note in notes: + print('source: %s' % note) + result = subprocess.run([str(binary)], capture_output=True, text=True) + sys.stdout.write(result.stdout) + if result.stderr.strip(): + sys.stdout.write(result.stderr) + if result.returncode != 0 and overall == 0: + overall = 1 +print('=' * 72) +print('OVERALL: %s' % ('tested invariants failed' if overall == 1 + else 'build/source error' if overall == 2 + else 'tested single-user, single-mm lifecycles balanced')) +raise SystemExit(overall) From 37c5cb7deebfd46106950536d70482352135843b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:18:37 -0600 Subject: [PATCH 085/342] test: register perf mmap accounting host check Register the alias lifecycle harness so the host-test runner executes it instead of rejecting the unregistered file. Verified with the runner before and after registration. Assisted-by: LLM Signed-off-by: Joshua Warren --- tools/asahi/run-host-tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 84ced6b0f27d5..77acf649e7d39 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -153,6 +153,7 @@ def mutations(flag, names, base, expect=KILL): + mutations('--mutation', ('ack-clobber', 'arm-ack', 'offset-seconds', 'offset-sign', 'event-bit', 'wrong-control', 'maverick-event', 'stowe-offset'), out()), + 'perf-mmap-alias-lifecycle-tests.py': [([], PASS)], 'qspi-nvram-tests.py': [(out('--output'), PASS)], 'rtkit-oslog-tests.py': [(out(), PASS)] + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), From 0c521040cf6c8c766b8a5e335b5f7fa9806e169b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 04:12:19 +1100 Subject: [PATCH 086/342] media: apple: prores: budget the T6000 v0 descriptor per profile The v0 descriptor left its two rate-control limits at 0xffff, so the APR a0 engine never limited a frame: on detailed or noisy input every profile came out far above its data rate (1080p 422 HQ on noise at 1028 Mbit/s instead of about 220) and the engine slowed down accordingly. The v0 rate-control block is the v1 block 0x20 bytes earlier (the thresholds, weights, betas, quantiser words and matrix selector already line up), so 0xf0/0xf2 are the target and maximum Q3 bytes per macroblock. Write the same per-profile budgets as v1. Frame sizes on the M1 Pro now equal the Neo's and macOS VideoToolbox's on the same input in all six profiles, on three clip types, at 1080p and 2160p. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../platform/apple/prores/apple-prores-desc.c | 14 ++++++++++---- .../platform/apple/prores/apple-prores-test.c | 8 +++++++- .../platform/apple/prores/t6000-qualification.rst | 15 +++++++++------ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/apple/prores/apple-prores-desc.c b/drivers/media/platform/apple/prores/apple-prores-desc.c index 17a87ea2e6353..82abe6acce3f9 100644 --- a/drivers/media/platform/apple/prores/apple-prores-desc.c +++ b/drivers/media/platform/apple/prores/apple-prores-desc.c @@ -425,19 +425,25 @@ EXPORT_SYMBOL_IF_KUNIT(apr_build_desc); * Descriptor v0 (APR a0). Source: MIT m1n1 f3ac615eb137, * proxyclient/m1n1/hw/prores.py:7-111 and * proxyclient/experiments/prores.py:592-644. Only the input/output prefix - * is shared with v1. The public experiment leaves both legacy limits at - * 0xffff; their meaning is unqualified, so do not apply v1 budget formulas. + * is shared with v1. The rate-control block is v1's, 0x20 bytes earlier: + * the target and maximum Q3 bytes per macroblock at 0xf0/0xf2 take the same + * per-profile budgets, so every profile lands on its data rate. (The public + * experiment's 0xffff limits leave the engine unbudgeted.) */ int apr_build_desc_v0(const struct apr_frame *f, u8 *desc) { bool is444 = apr_input_is_444(f->input); enum apr_qtable table = apr_profile_qtable(f->profile); + u32 slices, mbs, target, max; unsigned int i; int ret; ret = apr_build_desc_common(f, desc); if (ret) return ret; + slices = apr_slice_count(f->width, f->height, APR_SLICE_LOG2); + mbs = DIV_ROUND_UP(f->width, 16) * DIV_ROUND_UP(f->height, 16); + apr_frame_budget(f->profile, f->width, f->height, &target, &max); /* Frame header, including the legacy aspect/rate byte at 0x065. */ put_unaligned_be16(D_FH_BYTES, desc + 0x058); @@ -454,8 +460,8 @@ int apr_build_desc_v0(const struct apr_frame *f, u8 *desc) /* Deprecated slice count at 0x0ec stays zero, as in m1n1. */ desc[0x0ee] = APR_SLICE_LOG2 << 4; desc[0x0ef] = apr_profile_policy[f->profile].quant_index; - put_unaligned_le16(0xffff, desc + 0x0f0); - put_unaligned_le16(0xffff, desc + 0x0f2); + put_unaligned_le16(apr_mb_budget(target, slices, mbs), desc + 0x0f0); + put_unaligned_le16(apr_mb_budget(max, slices, mbs), desc + 0x0f2); put_unaligned_le64(APR_RC_THRESHOLDS, desc + 0x0f4); put_unaligned_le32(0x2c8080, desc + 0x0fc); for (i = 0; i < ARRAY_SIZE(apr_rc_beta); i++) diff --git a/drivers/media/platform/apple/prores/apple-prores-test.c b/drivers/media/platform/apple/prores/apple-prores-test.c index 3e727ff0ae3dc..9ac7080e072a2 100644 --- a/drivers/media/platform/apple/prores/apple-prores-test.c +++ b/drivers/media/platform/apple/prores/apple-prores-test.c @@ -189,6 +189,7 @@ static void apr_test_desc_v0(struct kunit *test) struct apr_frame f = apr_test_frame(); u8 *d = kunit_kmalloc(test, APR_DESC_BYTES + 1, GFP_KERNEL); unsigned int i; + u32 budget; KUNIT_ASSERT_NOT_NULL(test, d); memset(d, 0xa5, APR_DESC_BYTES + 1); @@ -221,9 +222,11 @@ static void apr_test_desc_v0(struct kunit *test) KUNIT_EXPECT_EQ_MSG(test, d[i], 0, "padding/slices %#x", i); KUNIT_EXPECT_EQ(test, d[0xee], 0x30); KUNIT_EXPECT_EQ(test, d[0xef], 2); - for (i = 0; i < ARRAY_SIZE(legacy); i++) + /* Word 0 is the rate budget, checked against v1 below. */ + for (i = 1; i < ARRAY_SIZE(legacy); i++) KUNIT_EXPECT_EQ_MSG(test, get_unaligned_le32(d + 0xf0 + 4 * i), legacy[i], "legacy word %u", i); + budget = get_unaligned_le32(d + 0xf0); for (i = 0x154; i < APR_DESC_BYTES; i++) KUNIT_EXPECT_EQ_MSG(test, d[i], 0, "v0 trailing padding %#x", i); @@ -232,6 +235,9 @@ static void apr_test_desc_v0(struct kunit *test) KUNIT_EXPECT_EQ(test, get_unaligned_le64(d + 0x58), 0); KUNIT_EXPECT_EQ(test, get_unaligned_be16(d + 0x7c), 148); KUNIT_EXPECT_EQ(test, get_unaligned_le32(d + 0x170), 0x23); + /* v0 carries v1's target and maximum budget words. */ + KUNIT_EXPECT_EQ(test, budget, get_unaligned_le32(d + 0x110)); + KUNIT_EXPECT_NE(test, budget, 0xffffffff); } static void apr_test_desc_v0_profiles(struct kunit *test) diff --git a/drivers/media/platform/apple/prores/t6000-qualification.rst b/drivers/media/platform/apple/prores/t6000-qualification.rst index 17a44eb892328..c8f021988687e 100644 --- a/drivers/media/platform/apple/prores/t6000-qualification.rst +++ b/drivers/media/platform/apple/prores/t6000-qualification.rst @@ -16,9 +16,12 @@ Standard, HQ and 4444 at 3840x2160. ffmpeg decoded every frame at the expected size and chroma format. There were no DART faults, and the engine runtime-suspended with its power domain off afterwards. +Rate control matches macOS: with the per-profile budgets, frame sizes +equal VideoToolbox's on the same input (measured against macOS on the +T8140 engine), on easy, detailed and noisy clips at 1080p and 2160p. + Not yet covered: cancellation, failed-reset retention (#925), system -suspend, rate-control parity with macOS, and the SCODEC performance -request below. +suspend and the SCODEC performance request below. Implementation sources ---------------------- @@ -30,10 +33,10 @@ f3ac615eb1376d3bbba24cd84c414b9e41892adb: * ``proxyclient/experiments/prores.py:42-89``: all 48 core RMWs, in order. * ``proxyclient/m1n1/hw/prores.py:7-111``: the v0 descriptor layout. * ``proxyclient/experiments/prores.py:592-644``: legacy header, slice and - rate-control words. The v0 builder retains the two public 0xffff limits; - it does not assign them v1 coefficient-budget semantics. Profile matrices - and initial quantisers follow the existing driver's policy, but profile - bitrate/quality equivalence remains to be measured on v0. + rate-control words. The v0 rate-control block is the v1 one, 0x20 bytes + earlier; the builder writes the per-profile target and maximum budgets + at 0xf0/0xf2 instead of the experiment's unbudgeted 0xffff. Profile + matrices and initial quantisers follow the existing driver's policy. The MIT notice for the adapted constants is retained in ``m1n1-LICENSE``. T6000 selects neither wrapper nor SCODEC-system writes. It has no BWR entry; From 2f86a048520d3c5dd59cb4aaa2b2b3dcbee6f220 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 04:37:37 +1100 Subject: [PATCH 087/342] drm/apple: answer the DCP PMU temperature query with the battery temperature DCP asks the AP for "PMUS"/"Temperature" once while it starts and, when no 2D panel temperature has been set, takes the answer as the initial panel temperature for its compensation. Linux answered with a constant 3029 on every machine. Our own macOS observation on the J700 (macOS 26.6.2) shows what macOS sends: the system battery's gas gauge temperature in 0.1 K, the same value the SMC reports in B0AT. At one boot the battery read 2997, the DCP logged "using PMU temperature as initial guess: 29.969985961" and published InitialPanelTemperature 26.5 C in Q16.16, which is (2997 - 2732) / 10, the battery temperature. An earlier boot matched in the same way (29.78 logged, 24.59 C published). Read the temperature from the system battery power supply at the time of the query and convert it back to 0.1 K. Without a battery (desktops, or no battery driver bound) keep the old reply. Load macsmc-power before the DCP so the battery exists when DCP starts. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/apple_drv.c | 4 +- drivers/gpu/drm/apple/iomfb.c | 58 ++++++++++++++++++++++++++ drivers/gpu/drm/apple/iomfb.h | 5 +++ drivers/gpu/drm/apple/iomfb_h17p.c | 4 +- drivers/gpu/drm/apple/iomfb_template.c | 6 +-- drivers/gpu/drm/apple/iomfb_v14_7.c | 7 +--- 6 files changed, 71 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 763ba82ad29ac..41b9c672ae398 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1806,5 +1806,7 @@ MODULE_LICENSE("Dual MIT/GPL"); * crossbar. Without this, initramfs generators leave it out, it loads only * from the root filesystem, and a DCP probe that waits past the deferred * probe timeout (an encrypted root's passphrase prompt) gives up its routes. + * DCP also asks for the battery temperature once while it starts (see + * dcp_pmu_temperature()), so have the SMC battery registered by then. */ -MODULE_SOFTDEP("pre: mux-apple-display-crossbar"); +MODULE_SOFTDEP("pre: mux-apple-display-crossbar macsmc-power"); diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index a504dca5a6bea..8bca8d2cebeca 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,63 @@ struct dcp_identity_trace { atomic_t *count; }; +/* + * DCP asks the AP for "PMUS"/"Temperature" once at start-up and uses it as + * the initial panel temperature when no 2D panel temperature has been set. + * macOS answers with the system battery's gas gauge temperature in units of + * 0.1 K (the AppleSmartBattery "Temperature" property, the SMC B0AT key); + * the firmware takes off 273.2 K itself. Observed on the J700 under macOS + * 26.6: a reply of 2997 gave an InitialPanelTemperature of 26.5 C, equal to + * the battery temperature at that boot. + * + * Linux power supplies report temperature in 0.1 C, so add the 273.2 K back. + */ +struct dcp_battery_temp { + u64 value; + bool found; +}; + +static int dcp_battery_temp_cb(struct power_supply *psy, void *data) +{ + struct dcp_battery_temp *bt = data; + union power_supply_propval val; + + if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY) + return 0; + if (!power_supply_get_property(psy, POWER_SUPPLY_PROP_SCOPE, &val) && + val.intval == POWER_SUPPLY_SCOPE_DEVICE) + return 0; + if (power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val)) + return 0; + if (val.intval <= -2732) + return 0; + + bt->value = val.intval + 2732; + bt->found = true; + return 1; +} + +u64 dcp_pmu_temperature(struct device *dev) +{ + struct dcp_battery_temp bt = { 0 }; + + if (IS_REACHABLE(CONFIG_POWER_SUPPLY)) + power_supply_for_each_psy(&bt, dcp_battery_temp_cb); + + if (bt.found) { + dev_dbg(dev, "PMU temperature from the battery: %llu (0.1 K)\n", + bt.value); + return bt.value; + } + + /* + * No system battery (desktops, or the battery driver is not bound): + * keep the reply Linux has always sent, 302.9 K. + */ + dev_dbg(dev, "no system battery, PMU temperature fallback\n"); + return DCP_PMU_TEMPERATURE_FALLBACK; +} + /* * set_matrix coefficients for @ctm, the identity when @ctm is NULL. DRM * carries S31.32 sign-magnitude; the firmware takes signed (two's diff --git a/drivers/gpu/drm/apple/iomfb.h b/drivers/gpu/drm/apple/iomfb.h index 5e5795ba3c379..2ae15b13b8d43 100644 --- a/drivers/gpu/drm/apple/iomfb.h +++ b/drivers/gpu/drm/apple/iomfb.h @@ -391,6 +391,11 @@ struct iomfb_set_matrix_req { u8 padding[3]; } __packed; +/* "PMUS"/"Temperature" reply in 0.1 K: the battery temperature, as macOS. */ +#define DCP_PMU_TEMPERATURE_FALLBACK 3029 +struct device; +u64 dcp_pmu_temperature(struct device *dev); + struct drm_color_ctm; void dcp_ctm_to_fw(u64 fw[9], const struct drm_color_ctm *ctm); diff --git a/drivers/gpu/drm/apple/iomfb_h17p.c b/drivers/gpu/drm/apple/iomfb_h17p.c index ad8307f602ea7..1e24d0e617a79 100644 --- a/drivers/gpu/drm/apple/iomfb_h17p.c +++ b/drivers/gpu/drm/apple/iomfb_h17p.c @@ -516,7 +516,7 @@ static bool trampoline_get_uint_prop_h17p(struct apple_dcp *dcp, int tag, return trampoline_get_uint_prop(dcp, tag, out, in); trace_iomfb_callback(dcp, tag, __func__); - /* The observed startup query uses Asahi's existing Temperature reply. */ + /* The observed startup query: the battery temperature in 0.1 K. */ if (memcmp(request->obj, "SUMP", sizeof(request->obj)) || strnlen(request->key, sizeof(request->key)) == sizeof(request->key) || strcmp(request->key, "Temperature") || request->value_null || @@ -526,7 +526,7 @@ static bool trampoline_get_uint_prop_h17p(struct apple_dcp *dcp, int tag, return false; } - put_unaligned_le64(3029, out); + put_unaligned_le64(dcp_pmu_temperature(dcp->dev), out); *((u8 *)out + offsetof(struct dcp_get_uint_prop_resp, ret)) = true; return true; } diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 82e5310f3fd6e..ad87814e9bb9b 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -877,11 +877,7 @@ dcpep_cb_get_uint_prop(struct apple_dcp *dcp, struct dcp_get_uint_prop_req *req) if (dcp->panel.has_mini_led && memcmp(req->obj, "SUMP", sizeof(req->obj)) == 0) { /* "PMUS */ if (strncmp(req->key, "Temperature", sizeof(req->key)) == 0) { - /* - * TODO: value from j314c, find out if it is temperature in - * centigrade C and which temperature sensor reports it - */ - resp.value = 3029; + resp.value = dcp_pmu_temperature(dcp->dev); resp.ret = true; } } diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index 5c1b20c730c4c..1f98ace1d9a89 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -1342,12 +1342,9 @@ static int dcp_v14_callback(void *cookie, u32 tag, const void *input, u32 in_siz } /* Unsigned property read. */ if (tag == D(401) && SHAPE(80, 12)) { - /* - * The PMU temperature the M1/M2 mini-LED hosts report: a fixed - * placeholder in centidegrees, not a measurement. - */ + /* The PMU temperature: the battery temperature in 0.1 K. */ if (!memcmp(in, "SUMP", 4) && !strncmp(in + 4, "Temperature", 64)) { - put_unaligned_le64(3029, out); + put_unaligned_le64(dcp_pmu_temperature(v14->dev), out); out[8] = 1; return 0; } From 349bc3bc104186d36bca018a1eb8f9e655e0c138 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 05:37:56 +1100 Subject: [PATCH 088/342] PM: hibernate: allow pm_test dry runs on Apple silicon Hibernation is disabled on Apple silicon Macs with a blanket check in hibernation_available(). That is right for real images: restoring one means a cold boot through the platform boot chain, which restarts the coprocessor firmware, and most of the Apple drivers have no freeze/poweroff/restore path that rebuilds their mailbox, ring and DMA state from a cold start. The check is silent, though, and it also blocks the pm_test dry runs that are needed to bring those callbacks up. Every pm_test level stops before create_image() takes a snapshot, so a dry run never writes or restores an image. Keep hibernation_available() false on these machines, so /sys/power/disk stays "[disabled]", "disk" is not listed in /sys/power/state, resume from an image is skipped and /dev/snapshot stays closed. Then: - print the reason once at boot, - let hibernate() run when pm_test is set to a level other than "none", checked under system_transition_mutex so the level cannot change during the run, - refuse the real transition with a clear message and -EPERM, as before, - drop the snapshot and bail out, with a warning, if one is ever taken during a dry run. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- kernel/power/hibernate.c | 66 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index af4a1943b1eee..890bf7b447f89 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -107,13 +107,45 @@ bool hibernation_in_progress(void) return !atomic_read(&hibernate_atomic); } -bool hibernation_available(void) +/* + * Apple silicon Macs run firmware on their coprocessors (storage, secure + * enclave, display, always-on processor, system controller, GPU and more). + * Restoring an image means a cold boot through the platform boot chain, which + * restarts that firmware, but most of the Linux drivers have no + * freeze/poweroff/restore path that rebuilds their mailbox, ring and DMA state + * from a cold start. The restored kernel would keep using stale state, so + * writing and restoring images stays disabled on these machines. + * + * pm_test dry runs are allowed (see hibernate()): every pm_test level stops + * before create_image() takes a snapshot, so no image is written or restored. + * They exercise the freezer and the device freeze/thaw callbacks that a real + * implementation needs. + */ +static bool hibernation_platform_blocked(void) +{ + return of_machine_is_compatible("apple,arm-platform"); +} + +static bool hibernation_generic_available(void) { return nohibernate == 0 && !security_locked_down(LOCKDOWN_HIBERNATION) && - !secretmem_active() && !cxl_mem_active() && - !of_machine_is_compatible("apple,arm-platform"); + !secretmem_active() && !cxl_mem_active(); +} + +bool hibernation_available(void) +{ + return hibernation_generic_available() && + !hibernation_platform_blocked(); +} + +static int __init hibernation_platform_report(void) +{ + if (hibernation_platform_blocked()) + pr_info("disabled on this platform: coprocessor firmware state is not restored from an image\n"); + return 0; } +late_initcall(hibernation_platform_report); /** * hibernation_set_ops - Set the global hibernate operations. @@ -764,12 +796,17 @@ static int load_image_and_restore(void) int hibernate(void) { bool snapshot_test = false; + bool dry_run_only = false; unsigned int sleep_flags; int error; if (!hibernation_available()) { - pm_pr_dbg("Hibernation not available.\n"); - return -EPERM; + if (!hibernation_generic_available() || + !hibernation_platform_blocked()) { + pm_pr_dbg("Hibernation not available.\n"); + return -EPERM; + } + dry_run_only = true; } /* @@ -784,6 +821,16 @@ int hibernate(void) } sleep_flags = lock_system_sleep(); + /* + * pm_test_level cannot change while system_transition_mutex is held, + * so a dry run started here stays a dry run. + */ + if (dry_run_only && pm_test_level == TEST_NONE) { + pr_info("not supported on this platform yet; only pm_test dry runs are allowed\n"); + error = -EPERM; + goto Unlock; + } + /* The snapshot device should not be opened while we're running */ if (!hibernate_acquire()) { error = -EBUSY; @@ -816,6 +863,15 @@ int hibernate(void) if (error || freezer_test_done) goto Free_bitmaps; + if (in_suspend && WARN_ON_ONCE(dry_run_only)) { + /* A snapshot exists although only a dry run was allowed: drop it. */ + swsusp_free(); + in_suspend = 0; + pm_restore_gfp_mask(); + error = -EPERM; + goto Free_bitmaps; + } + if (in_suspend) { unsigned int flags = 0; From e242c9bfc8b14b09999155827ccffcf935f60ed5 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:06:42 +1100 Subject: [PATCH 089/342] thunderbolt: apple: order PCIe-C after the NHI with a device link Every boot with a USB4 router on the M2 and the M4 Pro logs thunderbolt-apple-nhi ...: device links to tunneled native ports are missing! tb_probe() looks for links only in ACPI tables and on Intel Macs. The Apple Silicon hosts have no such tables: their one tunneled native port is the PCIe-C controller, which the driver populates itself once a PCIe tunnel is up. Add an add_links hook to tb_nhi_ops that tb_probe() asks first. The Apple NHI answers true and links PCIe-C to the NHI when it populates it. That gives the order the ACPI links give on PCs: PCIe-C suspends before the NHI and resumes after it rebuilds the tunnel. Until now it held only because PCIe-C is registered later. A port without PCIe-C tunnels no native port, so it needs no link. The link is stateless. It orders system sleep and does not tie probe or unbind together, because apple_cio_remove_children() has to stop the NHI while PCIe-C is still bound. Both devices are removed together, and that drops the link. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/thunderbolt/apple.c | 39 +++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/nhi.h | 6 ++++++ drivers/thunderbolt/tb.c | 9 ++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index ba7ec0bc0296c..3374e0d3e794f 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -1354,6 +1354,33 @@ static int apple_cio_pcie_tunnel_ready_locked(struct apple_cio *acio) return ret; } +/* + * PCIe-C is the only native port this host tunnels. Order it after the NHI, + * which rebuilds the tunnel underneath it at resume (the job of the ACPI + * device links on PC hosts). The link is stateless: it orders system sleep + * only and leaves probe and unbind alone, because apple_cio_remove_children() + * must stop the NHI while PCIe-C is still bound. Removing either device drops + * the link; both are removed together and PCIe-C is populated only once per + * NHI, so this runs once per pair. + */ +static void apple_cio_link_pcie_tunnel(struct apple_cio *acio) +{ + struct platform_device *nhi_pdev = READ_ONCE(acio->nhi_pdev); + struct platform_device *pcie_pdev; + + lockdep_assert_held(&acio->pcie_tunnel_lock); + pcie_pdev = apple_cio_find_pcie_tunnel(acio); + if (!pcie_pdev) + return; + if (!nhi_pdev || + !device_link_add(&pcie_pdev->dev, &nhi_pdev->dev, DL_FLAG_STATELESS)) + dev_warn(acio->dev, "PCIe-C: device link to the NHI failed\n"); + else + dev_dbg(acio->dev, "PCIe-C: linked %s to %s\n", + dev_name(&pcie_pdev->dev), dev_name(&nhi_pdev->dev)); + put_device(&pcie_pdev->dev); +} + static int apple_cio_activate_pcie_tunnel_locked(struct apple_cio *acio) { int ret = 0; @@ -1383,6 +1410,7 @@ static int apple_cio_activate_pcie_tunnel_locked(struct apple_cio *acio) "failed to populate tunneled PCIe controller\n"); acio->pcie_tunnel_populated = true; + apple_cio_link_pcie_tunnel(acio); dev_info(acio->dev, "PCIe-C populated after USB4 PCIe tunnel adapter enable\n"); return apple_cio_pcie_tunnel_ready_locked(acio); @@ -2015,7 +2043,18 @@ static bool apple_nhi_dp_tunnel_awaits_display(struct tb_nhi *nhi, return apple_dpin_awaits_display(&c->state, c->acio->dp); } +/* + * There are no firmware tables naming the tunneled ports: PCIe-C, when the + * port has one, is linked to the NHI as it is populated (see + * apple_cio_link_pcie_tunnel()). A port without PCIe-C tunnels no native port. + */ +static bool apple_nhi_add_links(struct tb_nhi *nhi) +{ + return true; +} + static const struct tb_nhi_ops apple_nhi_ops = { + .add_links = apple_nhi_add_links, .request_ring_irq = apple_nhi_request_irq, .release_ring_irq = apple_nhi_release_irq, .ring_interrupt_active = apple_nhi_ring_interrupt_active, diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 7201e0c279cc3..75795fbf865a1 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -100,6 +100,11 @@ struct tb_nhi_ring_layout { * meanwhile, so the tunnel is kept instead of being * torn down at the DPRX timeout. Called with the * domain lock held. + * @add_links: NHI specific hook that makes the native ports tunneled + * through this host (PCIe) resume after the NHI, like the device + * links tb_acpi_add_links() creates from firmware tables. Returns + * %true if the host orders all of its tunneled native ports, so + * none is left without a link. * @is_present: Whether the device is currently present on the parent bus * @init_interrupts: NHI specific interrupt initialization hook * @reset_interface: Resets the host interface @@ -127,6 +132,7 @@ struct tb_nhi_ops { struct tb_port *out, u64 generation); void (*dp_tunnel_deactivate)(struct tb_nhi *nhi, struct tb_port *in, struct tb_port *out, u64 generation); + bool (*add_links)(struct tb_nhi *nhi); bool (*is_present)(struct tb_nhi *nhi); void (*dp_tunnel_changed)(struct tb_nhi *nhi, u8 in_port, u64 generation, bool active); bool (*dp_tunnel_awaits_display)(struct tb_nhi *nhi, struct tb_port *in); diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 94eb59113dd66..a4d439f2394df 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -4388,6 +4388,12 @@ static bool tb_apple_add_links(struct tb_nhi *nhi) return ret; } +/* Hosts without ACPI tables may order their tunneled native ports themselves. */ +static bool tb_nhi_add_links(struct tb_nhi *nhi) +{ + return nhi->ops && nhi->ops->add_links && nhi->ops->add_links(nhi); +} + static void tb_cm_init(struct tb_cm *tcm) { INIT_LIST_HEAD(&tcm->tunnel_list); @@ -4425,7 +4431,8 @@ struct tb *tb_probe(struct tb_nhi *nhi) * before the PCIe/USB stack is resumed so complain here if we * found them missing. */ - if (!tb_apple_add_links(nhi) && !tb_acpi_add_links(nhi)) + if (!tb_nhi_add_links(nhi) && !tb_apple_add_links(nhi) && + !tb_acpi_add_links(nhi)) tb_warn(tb, "device links to tunneled native ports are missing!\n"); return tb; From a10defefab5d9585fa961f857e03e0873e522fc3 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 06:20:28 +1100 Subject: [PATCH 090/342] pmdomain: apple: clear a latched bit 11 with a PS reset on power-on On the Neo (T8140) ANE_SYS sometimes fails to come back on when genpd powers it on in the noirq resume of a system sleep: PS ane_sys: Failed to reach power state 0xf (requested 0x200f, now: 0x2b4f) Target 0xf, actual 0x4 (clock-gated), bit 11 set. genpd ignores the error there, the ANE finds ANE_SYS off at PM_POST_SUSPEND and quarantines itself until reboot, and every later power-on of the domain stops the same way. It happens in about one boot in four, within the first ten sleeps. Bit 11 is not a parent that comes up late here. A test kernel that kept watching the word saw no change for 20 ms; the fabric domains above ANE_SYS (0x1a8, 0x1e8, 0x228) and its siblings were all on. Gated again, the domain reports actual 0 at once, but bit 11 stays set (0x2b00), and the next power-on stops at 0x2b4f again. Writing bit 11 back does nothing. A PS reset pulse while the domain is off clears it (0x3300, then 0x2300), and the power-on then reaches 0x23ff in 8 us. So when a power-on times out with bit 11 set and the actual state short of the target, gate the domain, pulse the PS reset, release it and request the on state again, each step with the usual 100 us budget. The devices of the domain lose their state while it is off anyway. Domains whose bit 11 means a parent that is not up yet (wait_parent, T6000 GFX), strict-state and externally clocked domains are left as they were. A latch the reset does not clear still fails and logs. KUnit: four new cases (latch cleared, cleared in the noirq phase, a latch the reset does not clear, no reset for wait_parent domains or a plain stall). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/pmdomain/apple/pmgr-pwrstate-test.c | 87 +++++++++++++++++++++ drivers/pmdomain/apple/pmgr-pwrstate.c | 53 +++++++++++++ 2 files changed, 140 insertions(+) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate-test.c b/drivers/pmdomain/apple/pmgr-pwrstate-test.c index b73e2973cb6f1..b3a8cd1f5715c 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate-test.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate-test.c @@ -15,6 +15,9 @@ struct pmgr_ps_test_reg { bool parent_read_error; unsigned int busy_writes; unsigned int auto_writes; /* writes that enabled automatic PM */ + bool latched; /* bit 11 latched: on stops at clock-gated, off still reaches 0 */ + bool latch_sticky; /* not even a PS reset clears it */ + unsigned int reset_writes; /* writes with the PS reset bit */ }; static int pmgr_ps_test_read(void *ctx, unsigned int reg, unsigned int *val) @@ -43,6 +46,19 @@ static int pmgr_ps_test_write(void *ctx, unsigned int reg, unsigned int val) u32 parent = r->val & APPLE_PMGR_BUSY; u32 actual; + if (val & APPLE_PMGR_PS_RESET) { + r->reset_writes++; + if (r->latched && !r->latch_sticky) { + r->latched = false; + parent = 0; + } + } + if (r->latched) { + actual = FIELD_GET(APPLE_PMGR_PS_TARGET, val) ? APPLE_PMGR_PS_CLKGATE : 0; + r->val = (val & ~(APPLE_PMGR_PS_ACTUAL | APPLE_PMGR_BUSY)) | APPLE_PMGR_BUSY | + FIELD_PREP(APPLE_PMGR_PS_ACTUAL, actual); + return 0; + } if (FIELD_GET(APPLE_PMGR_PS_TARGET, val) == APPLE_PMGR_PS_ACTIVE && (r->parent_stuck || r->parent_reads)) parent = APPLE_PMGR_BUSY; @@ -261,6 +277,73 @@ static void pmgr_ps_power_on_sleep_stuck_test(struct kunit *test) KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, r->val), APPLE_PMGR_PS_ACTIVE); } +/* + * A latched bit 11 (T8140 ANE_SYS after sleep: 0x2b4f) is cleared by a PS reset + * while the domain is off, and the power-on then completes. + */ +static void pmgr_ps_power_on_latch_cleared_test(struct kunit *test) +{ + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, false, &r); + r->latched = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), 0); + KUNIT_EXPECT_EQ(test, r->reset_writes, 1U); + KUNIT_EXPECT_FALSE(test, r->val & (APPLE_PMGR_BUSY | APPLE_PMGR_PS_RESET)); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 1U); +} + +/* The same in the noirq phase of a system sleep, where genpd ignores errors. */ +static void pmgr_ps_power_on_latch_sleep_test(struct kunit *test) +{ + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, true, &r); + ps->system_sleep = true; + r->latched = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), 0); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); +} + +/* A latch the reset does not clear still fails, and the domain is requested off. */ +static void pmgr_ps_power_on_latch_sticky_test(struct kunit *test) +{ + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, true, &r); + r->latched = true; + r->latch_sticky = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->reset_writes, 1U); + KUNIT_EXPECT_FALSE(test, r->val & APPLE_PMGR_PS_RESET); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, r->val), APPLE_PMGR_PS_PWRGATE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); +} + +/* No PS reset where bit 11 means a parent not up yet, nor on a plain stall. */ +static void pmgr_ps_power_on_no_reset_test(struct kunit *test) +{ + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, false, &r); + ps->wait_parent = true; + r->latched = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->reset_writes, 0U); + + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, true, &r); + r->stuck = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->reset_writes, 0U); +} + static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_power_on_test), KUNIT_CASE(pmgr_ps_power_off_undo_test), @@ -272,6 +355,10 @@ static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_power_on_parent_only_test), KUNIT_CASE(pmgr_ps_power_on_parent_read_error_test), KUNIT_CASE(pmgr_ps_power_on_sleep_stuck_test), + KUNIT_CASE(pmgr_ps_power_on_latch_cleared_test), + KUNIT_CASE(pmgr_ps_power_on_latch_sleep_test), + KUNIT_CASE(pmgr_ps_power_on_latch_sticky_test), + KUNIT_CASE(pmgr_ps_power_on_no_reset_test), {} }; diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index b84bfc4432111..0c825a64b42bd 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -84,6 +84,48 @@ static int apple_pmgr_ps_wait_parent(struct apple_pmgr_ps *ps, u32 *cur) return err ?: ret; } +/* + * A power-on can stop with the actual state short of the target and bit 11 + * latched: on the T8140 ANE_SYS after system sleep the word reads 0x2b4f + * (target 0xf, actual 0x4) and stays so. That is not a parent that comes up + * late: gated again, the domain reaches actual 0 at once, but bit 11 stays + * set and every later power-on stops the same way. Only a PS reset clears it. + * Power the domain off, pulse the PS reset while it is off (its devices lose + * their state there anyway), then request @reg, the on state, again. + * Domains whose bit 11 means a parent that is not up yet (wait_parent) and + * those with their own state contract are left alone. + */ +static int apple_pmgr_ps_clear_latch(struct apple_pmgr_ps *ps, u32 reg, u32 *cur) +{ + u32 off = (reg & ~APPLE_PMGR_PS_TARGET) | APPLE_PMGR_PS_PWRGATE; + int ret; + + if (ps->wait_parent || ps->strict_state || ps->externally_clocked || + !(*cur & APPLE_PMGR_BUSY) || + FIELD_GET(APPLE_PMGR_PS_ACTUAL, *cur) == APPLE_PMGR_PS_ACTIVE) + return -ETIMEDOUT; + + regmap_write(ps->regmap, ps->offset, off); + ret = regmap_read_poll_timeout_atomic(ps->regmap, ps->offset, *cur, + !FIELD_GET(APPLE_PMGR_PS_ACTUAL, *cur), 1, + APPLE_PMGR_PS_SET_TIMEOUT); + if (ret) + return ret; + regmap_write(ps->regmap, ps->offset, off | APPLE_PMGR_PS_RESET); + ret = regmap_read_poll_timeout_atomic(ps->regmap, ps->offset, *cur, + !(*cur & APPLE_PMGR_BUSY), 1, + APPLE_PMGR_PS_SET_TIMEOUT); + regmap_write(ps->regmap, ps->offset, off); + if (ret) + return ret; + regmap_write(ps->regmap, ps->offset, reg); + return regmap_read_poll_timeout_atomic(ps->regmap, ps->offset, *cur, + FIELD_GET(APPLE_PMGR_PS_ACTUAL, *cur) == + APPLE_PMGR_PS_ACTIVE && + !(*cur & APPLE_PMGR_BUSY), 1, + APPLE_PMGR_PS_SET_TIMEOUT); +} + static int apple_pmgr_ps_set(struct generic_pm_domain *genpd, u32 pstate, bool auto_enable) { int ret; @@ -174,6 +216,17 @@ static int apple_pmgr_ps_set(struct generic_pm_domain *genpd, u32 pstate, bool a return ret; } + if (ret < 0 && pstate == APPLE_PMGR_PS_ACTIVE) { + u32 stalled = cur; + + if (!apple_pmgr_ps_clear_latch(ps, reg, &cur)) { + dev_info_ratelimited(ps->dev, + "PS %s: power-on stopped at 0x%x with bit 11 latched; cleared by a PS reset\n", + genpd->name, stalled); + ret = 0; + } + } + report: if (ret < 0) dev_err_ratelimited(ps->dev, From d1ad27fe1fbc6ffe98c492550a1e8440e7165f77 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 14:49:08 -0500 Subject: [PATCH 091/342] dt-bindings: media: apple: Describe the T6050 capture interface Describe named register resources, host stream pairs, camera power gates and loader-provided memory for the T6050 ISP. Retain the disabled hardware inventory format used by the other T6050 boards. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/media/apple,t6050-isp.yaml | 228 ++++++++++++++++-- 1 file changed, 206 insertions(+), 22 deletions(-) diff --git a/Documentation/devicetree/bindings/media/apple,t6050-isp.yaml b/Documentation/devicetree/bindings/media/apple,t6050-isp.yaml index ea791487d642e..61892d3c8c17c 100644 --- a/Documentation/devicetree/bindings/media/apple,t6050-isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,t6050-isp.yaml @@ -4,19 +4,23 @@ $id: http://devicetree.org/schemas/media/apple,t6050-isp.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T6050 image signal processor +title: Apple T6050 Image Signal Processor maintainers: - Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> + - Erik Bourget description: - The camera image signal processor of the T6050 MacBook Pros (ADT isp0). - Unlike earlier generations its ADT node lists the coprocessor window and - two PMGR windows rather than mailbox and handshake windows inside the ISP - block. Its buffers go through the three instances of the ISP DART. It is - described from the ADT so the device tree lists all of the SoC's - hardware; no driver supports this generation yet and the node stays - disabled. + The T6050 ISP controls the attached camera sensor and processes its frames + through firmware the bootloader loads. The firmware segments are described + as reserved memory mapped at the addresses the firmware runs them at. The + host exchanges commands and image buffers through streams 0 and 12 of three + DART instances. A capture watchdog must be serviced while streaming. + + Disabled hardware inventory nodes use three register windows, five interrupts, + three stream references and two power domains. Driver-ready nodes name their + five register windows and describe the host streams and individual power gates. + The bootloader supplies the reserved memory and platform ID before enabling them. select: properties: @@ -33,31 +37,124 @@ properties: - const: apple,isp reg: + minItems: 3 + maxItems: 5 + description: + Inventory nodes list the coprocessor and two PMGR windows. Named driver + resources list the coprocessor, mailbox, handshake, doorbell and watchdog. + + reg-names: items: - - description: Coprocessor registers - - description: The ISP's PMGR control window - - description: The ISP's PMGR power-state window + - const: coproc + - const: mbox + - const: gpio + - const: mbox2 + - const: wdt interrupts: - minItems: 5 + minItems: 1 maxItems: 5 iommus: - items: - - description: Stream 0 of the first ISP DART - - description: Stream 0 of the second ISP DART - - description: Stream 0 of the third ISP DART + minItems: 3 + maxItems: 6 + description: + Inventory nodes list stream 0 of each DART. Driver-ready nodes list + streams 0 and 12 of each of the three DARTs, in controller order. power-domains: - items: - - description: ISP system domain - - description: Camera sensor domain + minItems: 2 + maxItems: 8 + description: + Inventory nodes list system and sensor domains. Driver-ready nodes list + system, CPU, FE, sensor, DPRX, secure, BE and CLR domains, in that order. clocks: maxItems: 2 - status: - const: disabled + memory-region: + items: + - description: Firmware text loaded by the bootloader + - description: Firmware data loaded by the bootloader + - description: Firmware main memory window; host allocations follow it + + memory-region-names: + items: + - const: text + - const: data + - const: heap + + apple,dart-vm-size: + $ref: /schemas/types.yaml#/definitions/uint64 + description: + Size in bytes of the host allocation aperture used by the ISP driver. + + apple,platform-id: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Platform identifier passed in the firmware boot descriptor. + + apple,cam-connections-scheme: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Camera connection layout of the board passed in the firmware boot + descriptor. + + apple,firmware-version: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3 + maxItems: 5 + description: Version of the firmware loaded by the bootloader. + + apple,firmware-compat: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 3 + maxItems: 5 + description: Compatibility version supplied by the bootloader. + + apple,temporal-filter: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Firmware temporal-filter strength selected for the attached sensor. + + sensor-presets: + type: object + description: + Sensor firmware presets and the host output geometry associated with them. + patternProperties: + "^preset[0-9]+$": + type: object + properties: + apple,config-index: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Sensor configuration index understood by the firmware + apple,input-size: + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - description: Input width in pixels + - description: Input height in pixels + description: Sensor input dimensions + apple,output-size: + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - description: Output width in pixels + - description: Output height in pixels + description: Delivered frame dimensions + apple,crop: + $ref: /schemas/types.yaml#/definitions/uint32-array + items: + - description: Horizontal crop origin in pixels + - description: Vertical crop origin in pixels + - description: Crop width in pixels + - description: Crop height in pixels + description: Cropped sensor rectangle + required: + - apple,config-index + - apple,input-size + - apple,output-size + - apple,crop + additionalProperties: false + additionalProperties: false required: - compatible @@ -65,6 +162,93 @@ required: - interrupts - iommus - power-domains - - status + +allOf: + - if: + required: + - reg-names + then: + properties: + reg: + minItems: 5 + interrupts: + maxItems: 1 + iommus: + minItems: 6 + power-domains: + minItems: 8 + clocks: false + required: + - apple,dart-vm-size + - sensor-presets + allOf: + - if: + properties: + status: + const: disabled + required: + - status + then: {} + else: + required: + - memory-region + - memory-region-names + - apple,platform-id + else: + properties: + reg: + maxItems: 3 + interrupts: + minItems: 5 + iommus: + maxItems: 3 + power-domains: + maxItems: 2 + status: + const: disabled + required: + - status additionalProperties: false + +examples: + - | + #include + #include + + soc { + #address-cells = <2>; + #size-cells = <2>; + + isp@580000000 { + compatible = "apple,t6050-isp", "apple,isp"; + reg = <0x5 0x80000000 0x0 0x1604000>, + <0x5 0x82924000 0x0 0x40>, + <0x5 0x829241d0 0x0 0x20>, + <0x5 0x82924464 0x0 0x10>, + <0x5 0xc3b50000 0x0 0x8000>; + reg-names = "coproc", "mbox", "gpio", "mbox2", "wdt"; + interrupt-parent = <&aic>; + interrupts = ; + iommus = <&isp_dart0 0>, <&isp_dart0 12>, + <&isp_dart1 0>, <&isp_dart1 12>, + <&isp_dart2 0>, <&isp_dart2 12>; + power-domains = <&ps_isp_sys>, <&ps_isp_cpu>, <&ps_isp_fe>, + <&ps_ispsens0>, <&ps_isp_dprx>, <&ps_isp_secure>, + <&ps_isp_be>, <&ps_isp_clr>; + memory-region = <&isp_fw_text>, <&isp_fw_data>, <&isp_heap>; + memory-region-names = "text", "data", "heap"; + apple,dart-vm-size = /bits/ 64 <0xde000000>; + apple,platform-id = <0x75>; + apple,cam-connections-scheme = <0x10>; + + sensor-presets { + preset0 { + apple,config-index = <5>; + apple,input-size = <1920 2160>; + apple,output-size = <1920 1080>; + apple,crop = <0 0 1920 1080>; + }; + }; + }; + }; From 562e67859dc0f356548bff552e0ad97115984cc5 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 14:49:09 -0500 Subject: [PATCH 092/342] media: apple: isp: Add T6050 camera capture support The T6050 ISP uses the H17 capture path with its own MMIO and DSID clear windows, host stream filter mask and mailbox interrupt enables. Describe these resources and keep the existing per-SoC behavior as the default. Exercise both the default and T6050 address-filter masks in KUnit. The source implementation captured 1080p NV12 frames at 30 fps on J716c. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../media/platform/apple/isp/isp-drv-test.c | 18 ++++- drivers/media/platform/apple/isp/isp-drv.c | 80 ++++++++++++++++++- drivers/media/platform/apple/isp/isp-drv.h | 3 + drivers/media/platform/apple/isp/isp-fw.c | 14 ++-- 4 files changed, 104 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/apple/isp/isp-drv-test.c b/drivers/media/platform/apple/isp/isp-drv-test.c index dbddb079a0f57..53f731234e64c 100644 --- a/drivers/media/platform/apple/isp/isp-drv-test.c +++ b/drivers/media/platform/apple/isp/isp-drv-test.c @@ -43,15 +43,16 @@ static void isp_test_dapf_in_fw_mmio(struct kunit *test) * leaves every other byte alone. The bank is plain memory here: the driver * is arm64 only, where the MMIO accessors work on it unchanged. */ -static void isp_test_dapf_program(struct kunit *test) +static void isp_test_dapf_program_mask(struct kunit *test, u32 sidmask) { static const struct isp_dapf_window windows[] = { { 0x380704000, 0x380704063 }, { 0x382824000, 0x382824004 }, }; - static const struct apple_isp_hw hw = { + const struct apple_isp_hw hw = { .dapf = windows, .num_dapf = ARRAY_SIZE(windows), + .dapf_sidmask = sidmask, }; size_t size = (ARRAY_SIZE(windows) + 1) * DAPF_WINDOW_STRIDE; u8 expect[DAPF_WINDOW_STRIDE]; @@ -76,7 +77,7 @@ static void isp_test_dapf_program(struct kunit *test) put_unaligned_le32(0, &expect[0x04]); put_unaligned_le64(windows[i].start, &expect[0x08]); put_unaligned_le64(windows[i].end, &expect[0x10]); - put_unaligned_le32(1, &expect[0x20]); + put_unaligned_le32(sidmask ?: 1, &expect[0x20]); KUNIT_EXPECT_MEMEQ_MSG(test, bank + i * DAPF_WINDOW_STRIDE, expect, sizeof(expect), "window %u", i); } @@ -86,9 +87,20 @@ static void isp_test_dapf_program(struct kunit *test) ISP_TEST_DAPF_FILL, DAPF_WINDOW_STRIDE)); } +static void isp_test_dapf_program(struct kunit *test) +{ + isp_test_dapf_program_mask(test, 0); +} + +static void isp_test_dapf_program_t6050(struct kunit *test) +{ + isp_test_dapf_program_mask(test, 0xcc3); +} + static struct kunit_case isp_dapf_test_cases[] = { KUNIT_CASE(isp_test_dapf_in_fw_mmio), KUNIT_CASE(isp_test_dapf_program), + KUNIT_CASE(isp_test_dapf_program_t6050), {} }; diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index 627a9bdb9e94d..21dd9cdc1be2a 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -255,6 +255,7 @@ static int apple_isp_map_dapf(struct apple_isp *isp) int apple_isp_program_dapf(struct apple_isp *isp) { const struct apple_isp_hw *hw = isp->hw; + u32 sidmask = hw->dapf_sidmask ?: DAPF_CTRL2_ISP; void __iomem *w; unsigned int i; @@ -264,7 +265,7 @@ int apple_isp_program_dapf(struct apple_isp *isp) writeq(hw->dapf[i].start, w + DAPF_START); writeq(hw->dapf[i].end, w + DAPF_END); writel(DAPF_CTRL0_ISP, w + DAPF_CTRL0); - writel(DAPF_CTRL2_ISP, w + DAPF_CTRL2); + writel(sidmask, w + DAPF_CTRL2); } /* Only bits 7:0 of CTRL0 and bits 63:2 of END read back. */ @@ -274,7 +275,7 @@ int apple_isp_program_dapf(struct apple_isp *isp) readq(w + DAPF_START) != hw->dapf[i].start || (readq(w + DAPF_END) | 3) != (hw->dapf[i].end | 3) || (readl(w + DAPF_CTRL0) & 0xff) != DAPF_CTRL0_ISP || - readl(w + DAPF_CTRL2) != DAPF_CTRL2_ISP) { + readl(w + DAPF_CTRL2) != sidmask) { dev_err(isp->dev, "DAPF window %u (0x%llx-0x%llx) failed readback\n", i, hw->dapf[i].start, hw->dapf[i].end); return -EIO; @@ -1141,7 +1142,82 @@ static const struct apple_isp_hw apple_isp_hw_t8142 = { .setfile_stride_fixup = true, }; +/* T6050 ISP17c: CPU-visible firmware MMIO windows and DART filters. */ +static const struct isp_mmio_window apple_isp_fw_mmio_t6050[] = { + { 0x280680000, 0x8000 }, + { 0x280900000, 0x4000 }, + { 0x284240000, 0x28000 }, + { 0x284e3c000, 0x4000 }, + { 0x286724000, 0x4000 }, + { 0x29062c000, 0x20000 }, + { 0x509660000, 0x4000 }, + { 0x2220004000, 0x14000 }, + { 0x2222004000, 0x14000 }, + { 0x2224004000, 0x14000 }, + { 0x2226004000, 0x14000 }, + { 0x2228004000, 0x14000 }, + { 0x222a004000, 0x14000 }, + { 0x222c004000, 0x14000 }, + { 0x222e004000, 0x14000 }, +}; + +static const struct isp_dapf_window apple_isp_dapf_t6050[] = { + { 0x2809003b0, 0x2809003f3 }, + { 0x280680000, 0x280687fff }, + { 0x284e3c000, 0x284e3c003 }, + { 0x29062c000, 0x290648003 }, + { 0x509660000, 0x509660003 }, + { 0x286724000, 0x286724004 }, + { 0x284240000, 0x284264000 }, + { 0x2220004000, 0x22200162fc }, + { 0x2222004000, 0x22220162fc }, + { 0x2224004000, 0x22240162fc }, + { 0x2226004000, 0x22260162fc }, + { 0x2228004000, 0x22280162fc }, + { 0x222a004000, 0x222a0162fc }, + { 0x222c004000, 0x222c0162fc }, + { 0x222e004000, 0x222e0162fc }, +}; + +static const u64 apple_isp_dsid_t6050[] = { + 0x2220016000, + 0x2222016000, + 0x2224016000, + 0x2226016000, + 0x2228016000, + 0x222a016000, + 0x222c016000, + 0x222e016000, +}; + +static const struct apple_isp_hw apple_isp_hw_t6050 = { + .gen = ISP_GEN_T6040, + .fw_abi = ISP_FW_ABI_H17, + .dsid_count = ARRAY_SIZE(apple_isp_dsid_t6050), + .dsid_clr_bases = apple_isp_dsid_t6050, + .dsid_clr_range0 = 0x2fc, + .mbox_irq_enable = ISP_MBOX_IRQ_ENABLE_T6031, + .mbox_extra_enables = true, + .scl1 = true, + .meta_size = ISP_META_SIZE_T8140, + .capture_meta_size = ISP_CAPTURE_META_SIZE_T8140, + .fw_mmio = apple_isp_fw_mmio_t6050, + .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t6050), + .dapf = apple_isp_dapf_t6050, + .num_dapf = ARRAY_SIZE(apple_isp_dapf_t6050), + .dapf_sidmask = 0xcc3, + .coproc_control = ISP_COPROC_CONTROL_T8140, + .coproc_status = ISP_COPROC_STATUS_T8140, + .coproc_quiesce = ISP_COPROC_QUIESCE_T8140, + .boot_mode = 1, + .shared_size = 0xde000000, + .fw_restore = true, + .deferred_start = true, + .setfile_stride_fixup = true, +}; + static const struct of_device_id apple_isp_of_match[] = { + { .compatible = "apple,t6050-isp", .data = &apple_isp_hw_t6050 }, { .compatible = "apple,t8103-isp", .data = &apple_isp_hw_t8103 }, { .compatible = "apple,t8112-isp", .data = &apple_isp_hw_t8112 }, { .compatible = "apple,t8122-isp", .data = &apple_isp_hw_t8122 }, diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 9056c3d7af143..66fa3e1264576 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -162,6 +162,7 @@ struct apple_isp_hw { u64 pmu_base; int dsid_count; + const u64 *dsid_clr_bases; /* windows of the H17 multi broadcast-clear command, the unused all ones */ u8 dsid_slots; u64 dsid_clr_base0; @@ -194,6 +195,7 @@ struct apple_isp_hw { u32 mbox2_offset; /* further interrupt enable and routing words (ISP17a) */ bool mbox_irq_route; + bool mbox_extra_enables; /* coprocessor control register, 0 for ISP_COPROC_CONTROL */ u32 coproc_control; /* coprocessor status register, 0 for ISP_COPROC_STATUS */ @@ -216,6 +218,7 @@ struct apple_isp_hw { */ const struct isp_dapf_window *dapf; unsigned int num_dapf; + u32 dapf_sidmask; /* ISP_GPIO_6 boot mode */ u32 boot_mode; diff --git a/drivers/media/platform/apple/isp/isp-fw.c b/drivers/media/platform/apple/isp/isp-fw.c index 28727ef24fbb6..302b18cd189c6 100644 --- a/drivers/media/platform/apple/isp/isp-fw.c +++ b/drivers/media/platform/apple/isp/isp-fw.c @@ -251,7 +251,7 @@ static irqreturn_t apple_isp_isr_thread(int irq, void *dev) static void isp_disable_irq(struct apple_isp *isp) { isp_mbox_write32(isp, isp->hw->mbox_irq_enable, 0x0); - if (isp->hw->mbox_irq_route) { + if (isp->hw->mbox_irq_route || isp->hw->mbox_extra_enables) { isp_mbox_write32(isp, ISP_MBOX_IRQ_ENABLE1_T8140, 0x0); isp_mbox_write32(isp, ISP_MBOX_IRQ_ENABLE2_T8140, 0x0); } @@ -273,13 +273,14 @@ static int isp_enable_irq(struct apple_isp *isp) isp_dbg(isp, "about to enable interrupts...\n"); isp_mbox_write32(isp, isp->hw->mbox_irq_enable, 0xf); - if (isp->hw->mbox_irq_route) { + if (isp->hw->mbox_irq_route || isp->hw->mbox_extra_enables) { isp_mbox_write32(isp, ISP_MBOX_IRQ_ENABLE1_T8140, ISP_MBOX_IRQ_ENABLE1_T8140_VAL); isp_mbox_write32(isp, ISP_MBOX_IRQ_ENABLE2_T8140, ISP_MBOX_IRQ_ENABLE2_T8140_VAL); - isp_mbox_write32(isp, ISP_MBOX_IRQ_ROUTE_T8140, - ISP_MBOX_IRQ_ROUTE_T8140_VAL); + if (isp->hw->mbox_irq_route) + isp_mbox_write32(isp, ISP_MBOX_IRQ_ROUTE_T8140, + ISP_MBOX_IRQ_ROUTE_T8140_VAL); } return 0; @@ -934,12 +935,13 @@ static int isp_set_dsid_clr(struct apple_isp *isp) unsigned int slots = max_t(unsigned int, hw->dsid_count, hw->dsid_slots); - if (WARN_ON(hw->dsid_count > ARRAY_SIZE(used) || + if (WARN_ON((!hw->dsid_clr_bases && hw->dsid_count > ARRAY_SIZE(used)) || slots > ARRAY_SIZE(bases))) return -EINVAL; for (unsigned int i = 0; i < slots; i++) - bases[i] = i < hw->dsid_count ? used[i] : U64_MAX; + bases[i] = i < hw->dsid_count ? + (hw->dsid_clr_bases ? hw->dsid_clr_bases[i] : used[i]) : U64_MAX; return isp_cmd_set_dsid_clr_multi_bc(isp, bases, slots, hw->dsid_clr_range0); From ae6b06fd7893410afdb4504cdf03c681828240b0 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 14:49:09 -0500 Subject: [PATCH 093/342] dt-bindings: iommu: apple,dart: Add the T6050 ISP compatible Identify the ISP DARTs separately so the driver can reset host-owned streams without disturbing the secure core's translation roots. Developed with Claude Code. Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/iommu/apple,dart.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 9ba41ab9806d2..4d33293082a62 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -48,6 +48,7 @@ properties: - apple,t6031-dart - apple,t6041-dart - apple,t6050-dart + - apple,t6050-isp-dart - apple,t8122-dart - apple,t8132-dart - apple,t8140-dart From b6e1439872e61d8981954b4fbdecdea4640af6ce Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 14:49:09 -0500 Subject: [PATCH 094/342] iommu: apple-dart: Limit T6050 ISP reset to host streams The T6050 ISP shares its DARTs with a secure core. A full reset clears translation roots outside the host's ownership. Reset and invalidate only the host streams, admit client mappings on streams 0 and 12, and preserve the retained translation state across system sleep. Refuse a locked controller or a pending fault at reset. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/iommu/apple-dart.c | 46 +++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index d5b60c897a4c2..5e675e0416a37 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -299,6 +299,7 @@ struct apple_dart { u32 locked : 1; u32 tunneled : 1; u32 per_stream : 1; + u32 isp_host : 1; u32 power_retained : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; @@ -2001,11 +2002,45 @@ static void apple_dart_managed_quarantine(struct apple_dart *dart) spin_unlock_irqrestore(&dart->managed_lock, flags); } +/* ISP streams 4/5/8/9 belong to its secure core. Never reset those roots. */ +static int apple_dart_isp_host_reset(struct apple_dart *dart) +{ + const u32 host = BIT(0) | BIT(1) | BIT(6) | BIT(7) | + BIT(10) | BIT(11) | BIT(12); + struct apple_dart_stream_map map = { .dart = dart }; + unsigned int sid; + int ret; + + if (dart->hw->type != DART_T8110 || dart->num_streams != 16 || + dart->locked || (apple_dart_readl(dart, DART_T8110_ERROR) & DART_T8110_ERROR_FLAG)) + return -EBUSY; + for (sid = 0; sid < 16; sid++) + if (host & BIT(sid)) + __set_bit(sid, map.sidmap); + apple_dart_hw_disable_dma(&map); + apple_dart_hw_clear_all_ttbrs(&map); + apple_dart_hw_apply_remaps(dart); + apple_dart_writel(dart, host, DART_T8110_ENABLE_STREAMS); + for (sid = 0; sid < 16; sid++) { + if (!(host & BIT(sid))) + continue; + bitmap_zero(map.sidmap, DART_MAX_STREAMS); + __set_bit(sid, map.sidmap); + ret = dart->hw->invalidate_tlb(&map); + if (ret) + return ret; + } + apple_dart_writel(dart, 0, DART_T8110_ERROR_MASK); + return 0; +} + static int apple_dart_hw_reset(struct apple_dart *dart) { struct apple_dart_stream_map stream_map; int i; + if (dart->isp_host) + return apple_dart_isp_host_reset(dart); if (dart->managed_sids || dart->cold_ane) return -EBUSY; stream_map.dart = dart; @@ -2990,6 +3025,8 @@ static int apple_dart_of_xlate(struct device *dev, return i; sid = args->args[0]; + if (dart->isp_host && sid != 0 && sid != 12) + return -EINVAL; if (dart->cold_ane && sid != 0) return -EPERM; if (dart->managed_sids && @@ -4243,7 +4280,10 @@ static int apple_dart_probe(struct platform_device *pdev) dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart"); if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) return -EOPNOTSUPP; - dart->per_stream = of_device_is_compatible(dev->of_node, "apple,t8140-dart") || + dart->isp_host = of_device_is_compatible(dev->of_node, "apple,t6050-isp-dart"); + dart->power_retained = dart->isp_host; + dart->per_stream = dart->isp_host || + of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart"); if (of_property_present(dev->of_node, "apple,managed-sids")) { u32 ids[2]; @@ -4534,6 +4574,10 @@ static int apple_dart_probe(struct platform_device *pdev) dart->locked = false; else dart->locked = apple_dart_is_locked(dart); + if (dart->isp_host && dart->locked) { + ret = -EBUSY; + goto err_clk_disable; + } /* Reserved table-page lifetime requires the matched three-level loader. */ dart->fw_handoff = apple_dart_fw_handoff_enabled(dart); /* Preserve our retained-root path when no reserved-table handoff exists. */ From ec5c067ab2eec0f3b57fb31e154627f2b212be9a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:17:40 +1100 Subject: [PATCH 095/342] dmaengine: apple-sio: add the T6041 SIO The M4 Pro/Max (T6041) SIO carries the DisplayPort/HDMI audio streams of the external display processors. Its firmware reports protocol 10, as T6030's does, but its boot contract differs, so the compatible selects it and protocol 10 alone does not: - the boot loader's control tables go to the firmware in a fixed order (panic buffer, map ranges, wrapper tunables, the optional register tables, a power-gating scalar 0x2a = 0, DMA shims, device types, performance buffer), each as its address and then its exact size; - the driver owns the segment array (0xaaa entries of 12 bytes) and the response array (0x1cc0 entries of 16 bytes, one per endpoint and tag) and publishes both as entry counts; DMA is registered only after the response count is acknowledged; - a channel configuration is six words: shape, timeout, FIFO size, refill threshold 0x600, the host default timeout 5 and a zero word; - recycled period descriptors are cleared before reuse. The probe refuses tables that are not exactly that contract (a missing, repeated, unknown or wrongly sized table, the DMA arrays or the scalar from the loader, or a table outside the windows the loader mapped) before it starts the coprocessor, and refuses firmware that reports another protocol. The firmware itself is preloaded by iBoot; nothing is loaded. KUnit: apple-sio-t6041 covers admission, order, optional tables, every ACK failure, the array counts and the six-word configuration; the existing protocol 9 and T6030 suites are unchanged and pass. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/dma/Kconfig | 10 + drivers/dma/apple-sio-t6041-test.c | 276 +++++++++++++++++++++++++ drivers/dma/apple-sio.c | 313 ++++++++++++++++++++++++++++- 3 files changed, 588 insertions(+), 11 deletions(-) create mode 100644 drivers/dma/apple-sio-t6041-test.c diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 46eb147157185..12b59fc898a29 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig @@ -125,6 +125,16 @@ config APPLE_SIO_T6030_KUNIT_TEST against tables a T6030-aware boot loader builds, an earlier loader's tables, and malformed, truncated and out-of-window ones. +config APPLE_SIO_T6041_KUNIT_TEST + bool "KUnit tests for the T6041 SIO boot contract" if !KUNIT_ALL_TESTS + depends on APPLE_SIO=y && KUNIT=y + default KUNIT_ALL_TESTS + help + Check the T6041 (M4 Pro/Max) SIO boot: which boot-loader tables + are admitted and at which sizes, the order the firmware takes them + in with the power-gating scalar, the DMA array counts, and the + six-word channel configuration. + config ARM_DMA350 tristate "Arm DMA-350 support" depends on ARM || ARM64 || COMPILE_TEST diff --git a/drivers/dma/apple-sio-t6041-test.c b/drivers/dma/apple-sio-t6041-test.c new file mode 100644 index 0000000000000..1c9b1a56f8ae7 --- /dev/null +++ b/drivers/dma/apple-sio-t6041-test.c @@ -0,0 +1,276 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* Included by apple-sio.c: the T6041 SIO boot contract. */ +#include + +struct sio_t6041_test { + struct device dev; + struct sio_data sio; + u32 keys[32]; + u32 values[32]; + unsigned int count; + u32 fail_key; +}; + +#define T6041_WIN 0x10000118000ULL /* a window the loader mapped */ + +/* What a T6041-aware loader passes: J616s has no optional tables. */ +static const u32 sio_t6041_loader[] = { + 0x1e, 0x10000118, 0x1f, 0x30, + 0x0f, 0x1000011c, 0x10, 0x1e000, + 0x30d, 0x1000013c, 0x30e, 0x4000, + 0x1a, 0x10000140, 0x1b, 0x40, + 0x22, 0x10000141, 0x23, 0xd8, + 0x1c, 0x10000142, 0x1d, 0x48, +}; + +/* The firmware's order, the scalar after the register tables, before the shims. */ +static const u32 sio_t6041_expected[][2] = { + { 0x0f, 0x1000011c }, { 0x10, 0x1e000 }, + { 0x1a, 0x10000140 }, { 0x1b, 0x40 }, + { 0x1e, 0x10000118 }, { 0x1f, 0x30 }, + { 0x2a, 0 }, + { 0x22, 0x10000141 }, { 0x23, 0xd8 }, + { 0x1c, 0x10000142 }, { 0x1d, 0x48 }, + { 0x30d, 0x1000013c }, { 0x30e, 0x4000 }, +}; + +static const struct sio_t6030_window sio_t6041_windows[] = { + { T6041_WIN, 0x2d000 }, +}; + +static struct sio_t6041_test *sio_t6041_alloc(struct kunit *test) +{ + struct sio_t6041_test *t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, t); + t->sio.dev = &t->dev; + t->sio.hw = &sio_hw_t6041; + t->fail_key = U32_MAX; + return t; +} + +static int sio_t6041_set_param(struct sio_data *sio, u32 key, u32 val) +{ + struct sio_t6041_test *t = container_of(sio, struct sio_t6041_test, sio); + + if (t->count >= ARRAY_SIZE(t->keys)) + return -E2BIG; + t->keys[t->count] = key; + t->values[t->count++] = val; + return key == t->fail_key ? -ETIME : 0; +} + +static int sio_t6041_run(struct sio_t6041_test *t, const u32 *params, unsigned int n) +{ + u32 addr[ARRAY_SIZE(sio_t6041_params)] = {}; + u32 size[ARRAY_SIZE(sio_t6041_params)] = {}; + int err; + + t->count = 0; + err = sio_t6041_collect(params, n, sio_t6041_windows, ARRAY_SIZE(sio_t6041_windows), + addr, size); + if (err) + return err; + return sio_t6041_send_params(&t->sio, addr, size, sio_t6041_set_param); +} + +static void sio_t6041_order_test(struct kunit *test) +{ + struct sio_t6041_test *t = sio_t6041_alloc(test); + u32 params[ARRAY_SIZE(sio_t6041_loader)]; + unsigned int i, n = ARRAY_SIZE(sio_t6041_loader), rev; + + for (rev = 0; rev < 2; rev++) { + for (i = 0; i < n; i += 2) { + unsigned int src = rev ? n - i - 2 : i; + + params[i] = sio_t6041_loader[src]; + params[i + 1] = sio_t6041_loader[src + 1]; + } + KUNIT_ASSERT_EQ(test, sio_t6041_run(t, params, n), 0); + KUNIT_ASSERT_EQ(test, t->count, ARRAY_SIZE(sio_t6041_expected)); + for (i = 0; i < t->count; i++) { + KUNIT_EXPECT_EQ(test, t->keys[i], sio_t6041_expected[i][0]); + KUNIT_EXPECT_EQ(test, t->values[i], sio_t6041_expected[i][1]); + } + } +} + +static void sio_t6041_optional_test(struct kunit *test) +{ + struct sio_t6041_test *t = sio_t6041_alloc(test); + u32 params[ARRAY_SIZE(sio_t6041_loader) + 8]; + unsigned int n = ARRAY_SIZE(sio_t6041_loader); + + memcpy(params, sio_t6041_loader, sizeof(sio_t6041_loader)); + /* SIO registers, then misc tunables: both go before the scalar, in table order */ + params[n++] = 0x28; params[n++] = 0x10000143; + params[n++] = 0x29; params[n++] = 0x18; + params[n++] = 0x20; params[n++] = 0x10000144; + params[n++] = 0x21; params[n++] = 0x30; + KUNIT_ASSERT_EQ(test, sio_t6041_run(t, params, n), 0); + KUNIT_ASSERT_EQ(test, t->count, ARRAY_SIZE(sio_t6041_expected) + 4); + KUNIT_EXPECT_EQ(test, t->keys[6], 0x20U); + KUNIT_EXPECT_EQ(test, t->keys[7], 0x21U); + KUNIT_EXPECT_EQ(test, t->keys[8], 0x28U); + KUNIT_EXPECT_EQ(test, t->values[9], 0x18U); + KUNIT_EXPECT_EQ(test, t->keys[10], 0x2aU); + KUNIT_EXPECT_EQ(test, t->keys[11], 0x22U); + /* Half an optional table */ + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n - 2), -EINVAL); + KUNIT_EXPECT_EQ(test, t->count, 0U); +} + +static void sio_t6041_reject_test(struct kunit *test) +{ + struct sio_t6041_test *t = sio_t6041_alloc(test); + u32 params[ARRAY_SIZE(sio_t6041_loader) + 2]; + unsigned int n = ARRAY_SIZE(sio_t6041_loader), i; + /* Each required size, one off: protocol-9 shims, eight device types... */ + static const u32 wrong[][2] = { + { 0x23, 0xa0 }, { 0x23, 6 * 32 }, { 0x1d, 0x40 }, { 0x1b, 0x50 }, + { 0x10, 0x1d000 }, { 0x1f, 0x18 }, { 0x30e, 0x8000 }, + }; + /* Keys the loader must not pass: arrays, the scalar, unknown */ + static const u32 foreign[] = { 0x0b, 0x0c, 0x01, 0x02, 0x2a, 0x1234, 0x10b }; + + for (i = 0; i < ARRAY_SIZE(wrong); i++) { + unsigned int j; + + memcpy(params, sio_t6041_loader, sizeof(sio_t6041_loader)); + for (j = 0; j < n; j += 2) + if (params[j] == wrong[i][0]) + params[j + 1] = wrong[i][1]; + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n), -EINVAL); + } + for (i = 0; i < ARRAY_SIZE(foreign); i++) { + memcpy(params, sio_t6041_loader, sizeof(sio_t6041_loader)); + params[n] = foreign[i]; + params[n + 1] = 0x10000145; + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n + 2), -EINVAL); + } + /* A duplicate, a missing required table, an odd count, nothing */ + memcpy(params, sio_t6041_loader, sizeof(sio_t6041_loader)); + params[n] = 0x1e; + params[n + 1] = 0x10000118; + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n + 2), -EINVAL); + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n - 2), -EINVAL); + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n - 1), -EINVAL); + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, 0), -EINVAL); + /* Outside the mapped window: below it, and running past its end */ + params[1] = 0x10000100; + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n), -EINVAL); + params[1] = 0x10000143; /* 0x30 bytes from the window's last page: fits */ + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n), 0); + params[5] = 0x10000130; /* the panic buffer would end past the window */ + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, params, n), -EINVAL); + KUNIT_EXPECT_EQ(test, t->count, 0U); +} + +static void sio_t6041_ack_failure_test(struct kunit *test) +{ + struct sio_t6041_test *t = sio_t6041_alloc(test); + unsigned int fail; + + for (fail = 0; fail < ARRAY_SIZE(sio_t6041_expected); fail++) { + t->fail_key = sio_t6041_expected[fail][0]; + KUNIT_EXPECT_EQ(test, sio_t6041_run(t, sio_t6041_loader, + ARRAY_SIZE(sio_t6041_loader)), -ETIME); + /* Nothing follows a refused parameter, a table's size included. */ + KUNIT_EXPECT_EQ(test, t->count, fail + 1); + } +} + +static void sio_t6041_arrays_test(struct kunit *test) +{ + struct sio_t6041_test *t = sio_t6041_alloc(test); + static const u32 keys[] = { 1, 2, 0x0b, 0x0c }; + static const u32 values[] = { 0x10200000, 0xaaa, 0x10300000, 0x1cc0 }; + unsigned int i; + + KUNIT_EXPECT_EQ(test, sio_t6041_arrays.segments * sio_t6041_arrays.segment_size, + 0x7ff8U); + KUNIT_EXPECT_EQ(test, sio_t6041_arrays.responses * sio_t6041_arrays.response_size, + 0x1cc00U); + /* Every endpoint and tag has its response: index endpoint * 32 + tag - 1. */ + KUNIT_EXPECT_LT(test, (NCHANNELS_MAX - 1) * 32 + SIO_NTAGS - 2, + (int)sio_t6041_arrays.responses); + t->sio.arrays = &sio_t6041_arrays; + t->sio.shmem_iova = 0x10200000000ULL; + t->sio.responses_iova = 0x10300000000ULL; + KUNIT_ASSERT_EQ(test, sio_send_v9_shmem(&t->sio, sio_t6041_set_param), 0); + KUNIT_ASSERT_EQ(test, t->count, ARRAY_SIZE(keys)); + for (i = 0; i < t->count; i++) { + KUNIT_EXPECT_EQ(test, t->keys[i], keys[i]); + KUNIT_EXPECT_EQ(test, t->values[i], values[i]); + } + /* The response count's ACK is the last step: a refusal there fails the boot. */ + t->count = 0; + t->fail_key = 0x0c; + KUNIT_EXPECT_EQ(test, sio_send_v9_shmem(&t->sio, sio_t6041_set_param), -ETIME); + KUNIT_EXPECT_EQ(test, t->count, 4U); +} + +static void sio_t6041_config_test(struct kunit *test) +{ + struct sio_shmem_chan_config cfg = { + .datashape = 2, .timeout = 0, .fifo = 0x800, + .threshold = sio_hw_t6041.fifo_threshold, .limit = sio_hw_t6041.cfg_word4, + }; + static const u32 t6041[] = { 2, 0, 0x800, 0x600, 5, 0 }; + u32 words[8]; + + memset(words, 0xa5, sizeof(words)); + sio_write_config(&sio_hw_t6041, words, &cfg); + KUNIT_EXPECT_MEMEQ(test, words, t6041, sizeof(t6041)); + KUNIT_EXPECT_EQ(test, words[6], 0xa5a5a5a5U); + + /* The other layouts keep their five words and leave the sixth alone. */ + memset(words, 0xa5, sizeof(words)); + cfg.threshold = sio_hw_t6030.fifo_threshold; + cfg.limit = sio_hw_t6030.cfg_word4; + sio_write_config(&sio_hw_t6030, words, &cfg); + KUNIT_EXPECT_EQ(test, words[3], 0x600U); + KUNIT_EXPECT_EQ(test, words[4], 0x800U); + KUNIT_EXPECT_EQ(test, words[5], 0xa5a5a5a5U); +} + +static void sio_t6041_match_test(struct kunit *test) +{ + const struct of_device_id *id; + + for (id = sio_of_match; id->compatible[0]; id++) + if (!strcmp(id->compatible, "apple,t6041-sio")) + break; + KUNIT_ASSERT_TRUE(test, id->compatible[0] != '\0'); + KUNIT_EXPECT_PTR_EQ(test, id->data, (const void *)&sio_hw_t6041); + KUNIT_EXPECT_EQ(test, sio_hw_t6041.protocol, 10U); + KUNIT_EXPECT_TRUE(test, sio_hw_t6041.clear_period_desc); + KUNIT_EXPECT_PTR_EQ(test, sio_hw_t6041.arrays, &sio_t6041_arrays); + /* Protocol 10 alone is T6030's too, which keeps its own contract. */ + KUNIT_EXPECT_EQ(test, sio_hw_t6030.protocol, 0U); + KUNIT_EXPECT_NULL(test, sio_hw_t6030.arrays); + /* The one-segment descriptor overlay: handle slot * 4, IOVA at +72, length at +80 */ + KUNIT_EXPECT_EQ(test, 56 + offsetof(struct sio_coproc_desc, flag), 60U); + KUNIT_EXPECT_EQ(test, 56 + offsetof(struct sio_coproc_desc, iova), 72U); + KUNIT_EXPECT_EQ(test, 56 + offsetof(struct sio_coproc_desc, size), 80U); + KUNIT_EXPECT_EQ(test, sizeof(struct sio_coproc_desc), 4U * SIO_T6041_SEGMENT_SIZE); +} + +static struct kunit_case sio_t6041_test_cases[] = { + KUNIT_CASE(sio_t6041_order_test), + KUNIT_CASE(sio_t6041_optional_test), + KUNIT_CASE(sio_t6041_reject_test), + KUNIT_CASE(sio_t6041_ack_failure_test), + KUNIT_CASE(sio_t6041_arrays_test), + KUNIT_CASE(sio_t6041_config_test), + KUNIT_CASE(sio_t6041_match_test), + {} +}; + +static struct kunit_suite sio_t6041_test_suite = { + .name = "apple-sio-t6041", + .test_cases = sio_t6041_test_cases, +}; + +kunit_test_suite(sio_t6041_test_suite); diff --git a/drivers/dma/apple-sio.c b/drivers/dma/apple-sio.c index f2d3afaaf9bc3..94c48dffb983b 100644 --- a/drivers/dma/apple-sio.c +++ b/drivers/dma/apple-sio.c @@ -151,10 +151,20 @@ struct sio_chan { typedef void (*sio_ack_callback)(struct sio_chan *, void *, bool); +struct sio_data; +struct sio_dma_arrays; + struct sio_hw_data { + u32 protocol; /* the only protocol STARTED may report, or 0 */ u32 fifo_threshold; + u32 cfg_word4; /* configuration word 4 */ + bool cfg_six_words; /* the configuration ends in a zero sixth word */ bool clear_period_desc; + /* DMA arrays owned by the driver, if not protocol 9's */ + const struct sio_dma_arrays *arrays; int (*check_boot_tables)(struct device *dev); + /* The boot loader's tables in this firmware's order, if not as listed */ + int (*send_dt_params)(struct sio_data *sio); }; struct sio_data { @@ -168,6 +178,7 @@ struct sio_data { dma_addr_t shmem_iova; void *responses; dma_addr_t responses_iova; + const struct sio_dma_arrays *arrays; /* when the driver owns them */ struct sio_coproc_desc *shmem_desc_base; unsigned long *desc_allocated; @@ -206,6 +217,7 @@ static int sio_send_siomsg_atomic(struct sio_data *sio, u64 msg, sio_ack_callback ack_callback, void *cookie); static int sio_call(struct sio_data *sio, u64 msg); +static int sio_set_param(struct sio_data *sio, u32 key, u32 val); /* * Boot tables of the T6030 SIO firmware, protocol 10. The boot loader builds them from the ADT @@ -363,17 +375,265 @@ static int sio_t6030_check_boot_tables(struct device *dev) return 0; } +/* + * The T6041 (M4 Pro/Max) SIO firmware. It reports protocol 10 as T6030's + * does, but its boot is a different contract, so the protocol number does + * not select it; the compatible does: + * + * - the control tables go in this order, a table's address (IOVA page) + * then its size in bytes, which also completes it. Optional tables the + * ADT does not describe are left out whole. Key 0x2a, after the register + * tables, is a scalar: 0 leaves the SIO CPU's power gating off. The shim + * size (0x23) comes before the device types and lets the firmware set up + * its shims. + * - the segment array (keys 1, 2) and the response array (0x0b, 0x0c) are + * published last, as entry counts: 0xaaa segments of 12 bytes and 0x1cc0 + * responses of 16 bytes (one per endpoint and tag). The ACK of 0x0c + * brings up the DMA service. The driver owns both arrays. + * - a channel configuration is six words: data shape, timeout, FIFO size, + * refill threshold, the host's default timeout (5) and a zero word. + * + * The boot loader builds the control tables from the ADT and maps them + * into the windows it lists in memory-region. + */ +#define SIO_T6041_SEGMENTS 0xaaa +#define SIO_T6041_SEGMENT_SIZE 12 +#define SIO_T6041_RESPONSES 0x1cc0 +#define SIO_T6041_RESPONSE_SIZE 16 +#define SIO_T6041_KEY_CPU_POWER_GATE 0x2a + +enum sio_t6041_kind { + SIO_T6041_REQUIRED, /* an address and its exact size */ + SIO_T6041_OPTIONAL, /* both or neither, any non-zero size */ + SIO_T6041_SCALAR, /* the driver's own value, never the loader's */ +}; + +static const struct sio_t6041_param { + u16 key; + u8 kind; + u32 value; /* the size of a required table, or a scalar */ +} sio_t6041_params[] = { + { 0x0f, SIO_T6041_REQUIRED, 0x1e000 }, /* panic buffer */ + { 0x1a, SIO_T6041_REQUIRED, 4 * 16 }, /* map ranges */ + { 0x1e, SIO_T6041_REQUIRED, 0x30 }, /* ASC-wrapper tunables */ + { 0x20, SIO_T6041_OPTIONAL }, /* miscellaneous tunables */ + { 0x24, SIO_T6041_OPTIONAL }, /* power-state registers */ + { 0x28, SIO_T6041_OPTIONAL }, /* SIO registers */ + { SIO_T6041_KEY_CPU_POWER_GATE, SIO_T6041_SCALAR, 0 }, + { 0x22, SIO_T6041_REQUIRED, 6 * 36 }, /* DMA shims */ + { 0x1c, SIO_T6041_REQUIRED, 9 * 8 }, /* device types */ + { 0x30d, SIO_T6041_REQUIRED, 0x4000 }, /* performance endpoint */ +}; + +/* Where a loader key goes in sio_t6041_params, or -1 */ +static int sio_t6041_param_index(u32 key, bool *size) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(sio_t6041_params); i++) { + const struct sio_t6041_param *p = &sio_t6041_params[i]; + + if (p->kind == SIO_T6041_SCALAR) + continue; + if (key == p->key || key == p->key + 1) { + *size = key == p->key + 1; + return i; + } + } + return -1; +} + +/* + * Collect the loader's T6041 control tables into addr[]/size[] (indexed as + * sio_t6041_params), refusing anything not exactly the contract above: an + * unknown or repeated key, a scalar or a DMA array from the loader, a + * required table missing or of another size, half an optional table, or a + * table outside every window the loader mapped for this SIO. + */ +static int sio_t6041_collect(const u32 *params, unsigned int nparams, + const struct sio_t6030_window *windows, unsigned int nwindows, + u32 *addr, u32 *size) +{ + unsigned long seen = 0; + unsigned int i, j; + + static_assert(2 * ARRAY_SIZE(sio_t6041_params) <= BITS_PER_LONG); + if (!nparams || nparams % 2 || nparams > 2 * SIO_T6030_PARAMS_MAX) + return -EINVAL; + for (i = 0; i < nparams; i += 2) { + bool is_size; + int idx = sio_t6041_param_index(params[i], &is_size); + unsigned int bit; + + if (idx < 0) + return -EINVAL; + bit = 2 * idx + is_size; + if (seen & BIT(bit)) + return -EINVAL; + seen |= BIT(bit); + (is_size ? size : addr)[idx] = params[i + 1]; + } + + for (i = 0; i < ARRAY_SIZE(sio_t6041_params); i++) { + const struct sio_t6041_param *p = &sio_t6041_params[i]; + bool have_addr = seen & BIT(2 * i), have_size = seen & BIT(2 * i + 1); + bool inside = false; + u64 start, end; + + if (p->kind == SIO_T6041_SCALAR) + continue; + if (have_addr != have_size) + return -EINVAL; + if (!have_addr) { + if (p->kind == SIO_T6041_REQUIRED) + return -EINVAL; + continue; + } + if (!size[i] || (p->kind == SIO_T6041_REQUIRED && size[i] != p->value)) + return -EINVAL; + start = (u64)addr[i] << 12; + if (check_add_overflow(start, (u64)size[i], &end) || end > SIO_T6030_IOVA_LIMIT) + return -EINVAL; + for (j = 0; j < nwindows && !inside; j++) { + u64 window_end; + + if (check_add_overflow(windows[j].start, windows[j].size, &window_end)) + continue; + inside = start >= windows[j].start && end <= window_end; + } + if (!inside) + return -EINVAL; + } + return 0; +} + +static int sio_t6041_read_params(struct device_node *np, u32 *params, unsigned int max) +{ + int nparams = of_property_count_u32_elems(np, "apple,sio-firmware-params"); + + if (nparams <= 0 || nparams > max || + of_property_read_u32_array(np, "apple,sio-firmware-params", params, nparams)) + return -EINVAL; + return nparams; +} + +static int sio_t6041_check_node(struct device_node *np, u32 *addr, u32 *size) +{ + struct sio_t6030_window windows[SIO_T6030_WINDOWS_MAX]; + u32 params[2 * SIO_T6030_PARAMS_MAX]; + int nparams, nwindows; + + nparams = sio_t6041_read_params(np, params, ARRAY_SIZE(params)); + if (nparams < 0) + return nparams; + nwindows = sio_t6030_windows(np, windows, ARRAY_SIZE(windows)); + if (nwindows < 0) + return nwindows; + return sio_t6041_collect(params, nparams, windows, nwindows, addr, size); +} + +static int sio_t6041_check_boot_tables(struct device *dev) +{ + u32 addr[ARRAY_SIZE(sio_t6041_params)] = {}; + u32 size[ARRAY_SIZE(sio_t6041_params)] = {}; + + if (sio_t6041_check_node(dev->of_node, addr, size)) { + dev_err(dev, "boot tables are not T6041 SIO tables; leaving the SIO stopped\n"); + return -ENODEV; + } + return 0; +} + +/* Publish the collected control tables, and the scalar, in firmware order. */ +static int sio_t6041_send_params(struct sio_data *sio, const u32 *addr, const u32 *size, + int (*set_param)(struct sio_data *, u32, u32)) +{ + unsigned int i; + int err; + + for (i = 0; i < ARRAY_SIZE(sio_t6041_params); i++) { + const struct sio_t6041_param *p = &sio_t6041_params[i]; + + if (p->kind == SIO_T6041_SCALAR) { + err = set_param(sio, p->key, p->value); + if (err) + return err; + continue; + } + if (!size[i]) + continue; /* an optional table the ADT does not have */ + err = set_param(sio, p->key, addr[i]); + if (!err) + err = set_param(sio, p->key + 1, size[i]); + if (err) + return err; + } + return 0; +} + +static int sio_t6041_send_dt_params(struct sio_data *sio) +{ + u32 addr[ARRAY_SIZE(sio_t6041_params)] = {}; + u32 size[ARRAY_SIZE(sio_t6041_params)] = {}; + int err; + + /* Checked before the boot already; the property cannot have changed. */ + err = sio_t6041_check_node(sio->dev->of_node, addr, size); + if (err) + return err; + return sio_t6041_send_params(sio, addr, size, sio_set_param); +} + +/* The DMA arrays a protocol publishes as entry counts, after its control tables. */ +struct sio_dma_arrays { + u32 segments; + u32 segment_size; + u32 responses; + u32 response_size; +}; + +static const struct sio_dma_arrays sio_v9_arrays = { + .segments = SIO_V9_SEGMENTS, + .segment_size = SIO_V9_SEGMENT_SIZE, + .responses = SIO_V9_RESPONSES, + .response_size = SIO_V9_RESPONSE_SIZE, +}; + +static const struct sio_dma_arrays sio_t6041_arrays = { + .segments = SIO_T6041_SEGMENTS, + .segment_size = SIO_T6041_SEGMENT_SIZE, + .responses = SIO_T6041_RESPONSES, + .response_size = SIO_T6041_RESPONSE_SIZE, +}; + +static_assert(56 + SIO_NO_DESC_SLOTS * sizeof(struct sio_coproc_desc) <= + SIO_T6041_SEGMENTS * SIO_T6041_SEGMENT_SIZE); + static const struct sio_hw_data sio_hw_generic = { .fifo_threshold = 0x800, + .cfg_word4 = 0x800, }; static const struct sio_hw_data sio_hw_t6030 = { .fifo_threshold = 0x600, + .cfg_word4 = 0x800, .clear_period_desc = true, .check_boot_tables = sio_t6030_check_boot_tables, }; +static const struct sio_hw_data sio_hw_t6041 = { + .protocol = 10, + .fifo_threshold = 0x600, + .cfg_word4 = 5, /* the host's default timeout */ + .cfg_six_words = true, + .clear_period_desc = true, + .arrays = &sio_t6041_arrays, + .check_boot_tables = sio_t6041_check_boot_tables, + .send_dt_params = sio_t6041_send_dt_params, +}; + static const struct of_device_id sio_of_match[] = { + { .compatible = "apple,t6041-sio", .data = &sio_hw_t6041 }, { .compatible = "apple,t6030-sio", .data = &sio_hw_t6030 }, { .compatible = "apple,sio", .data = &sio_hw_generic }, { } @@ -1323,6 +1583,16 @@ static const struct apple_rtkit_ops sio_rtkit_ops = { .recv_message = sio_recv_msg, }; +/* The configuration record CONFIGURE points the firmware at (handle 0) */ +static void sio_write_config(const struct sio_hw_data *hw, void *shmem, + const struct sio_shmem_chan_config *cfg) +{ + memcpy(shmem, cfg, sizeof(*cfg)); + /* T6041 takes a sixth configuration word, zero. */ + if (hw->cfg_six_words) + memset(shmem + sizeof(*cfg), 0, sizeof(u32)); +} + static int sio_device_config(struct dma_chan *chan, struct dma_slave_config *config) { @@ -1355,7 +1625,7 @@ static int sio_device_config(struct dma_chan *chan, cfg.timeout = 0; cfg.fifo = 0x800; - cfg.limit = 0x800; + cfg.limit = sio->hw->cfg_word4; /* * The ADT records each client's channel configuration with it (the * dp-audioN dma-channels: channel, data shape, timeout, FIFO size, @@ -1390,7 +1660,7 @@ static int sio_device_config(struct dma_chan *chan, if (siochan->configured && memcmp(&siochan->cfg, &cfg, sizeof(cfg))) return -EBUSY; - *cfg_shmem = cfg; + sio_write_config(sio->hw, cfg_shmem, &cfg); dma_wmb(); ret = sio_call(sio, FIELD_PREP(SIOMSG_TYPE, MSG_CONFIGURE) | @@ -1497,9 +1767,9 @@ static void sio_free_v9_shmem(void *data) dev_err(sio->dev, "SIO shutdown failed: %d; retaining DMA buffers\n", err); return; } - dma_free_coherent(sio->dev, SIO_V9_RESPONSES * SIO_V9_RESPONSE_SIZE, + dma_free_coherent(sio->dev, sio->arrays->responses * sio->arrays->response_size, sio->responses, sio->responses_iova); - dma_free_coherent(sio->dev, SIO_V9_SEGMENTS * SIO_V9_SEGMENT_SIZE, + dma_free_coherent(sio->dev, sio->arrays->segments * sio->arrays->segment_size, sio->shmem, sio->shmem_iova); } @@ -1511,9 +1781,9 @@ static int sio_send_v9_shmem(struct sio_data *sio, u32 value; } params[] = { { 1, sio->shmem_iova >> 12 }, - { 2, SIO_V9_SEGMENTS }, + { 2, (sio->arrays ?: &sio_v9_arrays)->segments }, { 0x0b, sio->responses_iova >> 12 }, - { 0x0c, SIO_V9_RESPONSES }, + { 0x0c, (sio->arrays ?: &sio_v9_arrays)->responses }, }; unsigned int i; int err; @@ -1528,10 +1798,21 @@ static int sio_send_v9_shmem(struct sio_data *sio, static int sio_alloc_shmem(struct sio_data *sio) { - bool v9 = sio->protocol == 9; - size_t size = v9 ? SIO_V9_SEGMENTS * SIO_V9_SEGMENT_SIZE : SIO_SHMEM_SIZE; + const struct sio_dma_arrays *arrays = sio->hw->arrays; + size_t size, responses_size = 0; int err; + if (!arrays && sio->protocol == 9) + arrays = &sio_v9_arrays; + sio->arrays = arrays; + if (arrays && + (check_mul_overflow((size_t)arrays->segments, (size_t)arrays->segment_size, &size) || + check_mul_overflow((size_t)arrays->responses, (size_t)arrays->response_size, + &responses_size))) + return -EOVERFLOW; + if (!arrays) + size = SIO_SHMEM_SIZE; + sio->shmem = dma_alloc_coherent(sio->dev, size, &sio->shmem_iova, GFP_KERNEL | __GFP_ZERO); if (!sio->shmem) @@ -1545,9 +1826,8 @@ static int sio_alloc_shmem(struct sio_data *sio) goto free_shmem; } - if (v9) { - sio->responses = dma_alloc_coherent(sio->dev, - SIO_V9_RESPONSES * SIO_V9_RESPONSE_SIZE, + if (arrays) { + sio->responses = dma_alloc_coherent(sio->dev, responses_size, &sio->responses_iova, GFP_KERNEL | __GFP_ZERO); if (!sio->responses) { err = -ENOMEM; @@ -1577,6 +1857,9 @@ static int sio_send_dt_params(struct sio_data *sio) const char *propname = "apple,sio-firmware-params"; int nparams, err, i; + if (sio->hw->send_dt_params) + return sio->hw->send_dt_params(sio); + nparams = of_property_count_u32_elems(np, propname); if (nparams < 0) { err = nparams; @@ -1719,6 +2002,10 @@ static int sio_probe(struct platform_device *pdev) err = -ENXIO; return dev_err_probe(&pdev->dev, err, "starting SIO service\n"); } + if (hw->protocol && sio->protocol != hw->protocol) + return dev_err_probe(&pdev->dev, -ENODEV, + "SIO firmware protocol %u, this SoC's is %u\n", + sio->protocol, hw->protocol); err = sio_send_dt_params(sio); if (err < 0) @@ -1786,6 +2073,10 @@ MODULE_LICENSE("Dual MIT/GPL"); #include "apple-sio-test.c" #endif +#if IS_ENABLED(CONFIG_APPLE_SIO_T6041_KUNIT_TEST) +#include "apple-sio-t6041-test.c" +#endif + #if IS_ENABLED(CONFIG_APPLE_SIO_KUNIT_TEST) #include "apple-sio-probe-test.c" #include "apple-sio-boot-test.c" From 733268011b9f9e3abda84b2ac219d2515efebbbd Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:17:41 +1100 Subject: [PATCH 096/342] drm/apple: start desktop external audio on the T6041 DCPEXTs The desktop 26.x audio binding (endpoint 0x2b) could not start on any Mac: avep_init(), its admission and the native-link check all required dcp->external, which is set only for apple,t6030-dcpext. The M4 Pro/Max external processors are apple,t6041-dcpext, so appledrm.hdmi_audio=1 on the J616s logged "endpoint 0x2b (AUDIO) not started: audio init failed (-95)" for both. Record the desktop external role in its own flag and use it on those paths. The audio interface those processors publish is dcpav-audio-interface-epic, unit 0, not the provisional dcpav-audio-epic. With its role in front ("dispext0:") the compact announcement is longer than the 32-byte field and arrives cut to 31 characters, without its unit. Let an ops entry name its full ":" (compact_full) and match a cut of it of at least 20 characters, only when the announcement filled its field; the admission takes such a cut as unit 0 and nothing else. The binding stays behind appledrm.hdmi_audio (off by default). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/afk.c | 24 ++++++++++++++++++++++-- drivers/gpu/drm/apple/afk.h | 15 +++++++++++++++ drivers/gpu/drm/apple/av-v14-test.c | 25 ++++++++++++++++++++++++- drivers/gpu/drm/apple/av.c | 26 +++++++++++++++++++------- drivers/gpu/drm/apple/dcp-internal.h | 2 ++ drivers/gpu/drm/apple/dcp.c | 1 + 6 files changed, 83 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index c988e566c5344..9ac50fb8b6576 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -778,9 +778,29 @@ afk_compact_match_service(struct apple_dcp_afkep *ep, const char *name) return ops; } + /* An announcement that filled its field may have lost its end. */ + if (strlen(name) < AFK_COMPACT_NAME_LEN - 1) + return NULL; + for (ops = ep->ops; ops->name[0]; ops++) + if (afk_compact_cut_of(ops, service_name)) + return ops; + return NULL; } +/* + * Whether @service_name, the part after the role of an announcement that + * filled its field, is the firmware's cut of @ops's long name. + */ +bool afk_compact_cut_of(const struct apple_epic_service_ops *ops, const char *service_name) +{ + size_t len = strlen(service_name); + + return ops->compact_full && len >= AFK_COMPACT_CUT_MIN && + len < strlen(ops->compact_full) && + !strncmp(ops->compact_full, service_name, len); +} + /* A free slot for a newly announced service, or the one it replaces. */ static struct apple_epic_service * afk_compact_slot(struct apple_dcp_afkep *ep, @@ -867,8 +887,8 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep, ep->endpoint, channel); return; } - memcpy(wire_name, payload, 32); - wire_name[32] = '\0'; + memcpy(wire_name, payload, AFK_COMPACT_NAME_LEN); + wire_name[AFK_COMPACT_NAME_LEN] = '\0'; name = strchr(wire_name, ':'); name = name ? name + 1 : wire_name; strscpy(service_name, name, sizeof(service_name)); diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index d9fb811252f87..1e0a3fae1138c 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -89,8 +89,20 @@ struct apple_epic_service { enum epic_subtype; +/* A compact service announcement's name field, with its NUL */ +#define AFK_COMPACT_NAME_LEN 32 +/* The shortest cut of a long compact service name that still identifies it */ +#define AFK_COMPACT_CUT_MIN 20 + struct apple_epic_service_ops { const char name[32]; + /* + * A compact service whose announcement does not fit the 32-byte field: + * its full ":". The firmware cuts the announcement to 31 + * characters, losing the end of the name and the unit; a cut of this + * string, at least AFK_COMPACT_CUT_MIN characters of it, matches. + */ + const char *compact_full; /* All retained pointers must be pinned before enabling slot reuse. */ bool reusable; /* EOPNOTSUPP from prepare means intentional absence only for this role. */ @@ -117,6 +129,9 @@ struct apple_epic_service_ops { void (*teardown)(struct apple_epic_service *service); }; +bool afk_compact_cut_of(const struct apple_epic_service_ops *ops, const char *service_name); + + static inline int afk_ring_stride(u32 total, u32 bufsz, u32 *stride) { u32 header, block; diff --git a/drivers/gpu/drm/apple/av-v14-test.c b/drivers/gpu/drm/apple/av-v14-test.c index 433530763af7f..4718b61c27c00 100644 --- a/drivers/gpu/drm/apple/av-v14-test.c +++ b/drivers/gpu/drm/apple/av-v14-test.c @@ -128,6 +128,7 @@ static struct av_v14_test *av_v14_setup(struct kunit *test) DCP_FIRMWARE_V_26_6_DESKTOP : DCP_FIRMWARE_V_14_7; t->dcp->external = true; t->dcp->external_native = true; + t->dcp->desktop_external = true; init_rwsem(&asrv->srv_rwsem); mutex_init(&asrv->plug_lock); @@ -429,8 +430,9 @@ static void av_native_link_payload_status(struct kunit *test) static void av_desktop_service_admission(struct kunit *test) { struct av_v14_test *t = av_v14_setup(test); - const char *name = "dcpav-audio-epic"; + const char *name = "dcpav-audio-interface-epic"; bool desktop = t->dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP; + const struct apple_epic_service_ops *ops; KUNIT_EXPECT_TRUE(test, dcp_audiosrv_native_link(t->dcp->dev)); KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, name, name, 0), @@ -443,6 +445,27 @@ static void av_desktop_service_admission(struct kunit *test) -EINVAL); KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, NULL, name, 0), -EINVAL); KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, name, name, 1), -EINVAL); + /* The provisional pre-capture name is no longer admitted. */ + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, "dcpav-audio-epic", + "dcpav-audio-epic", 0), -EINVAL); + /* "dispext0:dcpav-audio-interface-epic:0" cut to its 31-character field */ + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, "dcpav-audio-interface-", + "dcpav-audio-interface-", -1), 0); + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, "dcpav-audio-interface-", + "dcpav-audio-interface-", 1), -EINVAL); + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, "dcpav-audio-i", + "dcpav-audio-i", -1), -EINVAL); + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, "dcpav-audio-interface-epix", + "dcpav-audio-interface-epix", -1), -EINVAL); + ops = &av_desktop_ops[0]; + KUNIT_EXPECT_TRUE(test, afk_compact_cut_of(ops, "dcpav-audio-interface-")); + KUNIT_EXPECT_TRUE(test, afk_compact_cut_of(ops, "dcpav-audio-interface-epic:")); + KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(ops, "dcpav-audio-interface-epic:0")); + KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(ops, "dcpav-audio-epic")); + KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(&avep_ops[0], "DCPAVSimpleVideoInter")); + /* Only the desktop external processor's own flag admits it. */ + t->dcp->desktop_external = false; + KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, name, name, 0), -EINVAL); t->dcp->external = false; KUNIT_EXPECT_FALSE(test, dcp_audiosrv_native_link(t->dcp->dev)); KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, name, name, 0), -EINVAL); diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 5e11c704a86ef..567b03156d163 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -260,7 +260,7 @@ bool dcp_audiosrv_native_link(struct device *dev) struct apple_dcp *dcp = dev_get_drvdata(dev); return dcp_is_v14_7_external(dcp) || - (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP && dcp->external); + (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP && dcp->desktop_external); } /* The 14.7 external role's audio service calls; KUnit stubs them. */ @@ -664,21 +664,33 @@ static void av_cec_teardown(struct apple_epic_service *service) #endif #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) +static const struct apple_epic_service_ops av_desktop_ops[]; + +/* + * The desktop 26.x external processors (T6041 DCPEXT) publish their audio + * interface on endpoint 0x2b as dcpav-audio-interface-epic, unit 0. With + * the role in front ("dispext0:") the announcement is longer than its + * field, so it arrives cut, without the unit: admit the cut too, as unit 0. + */ static int av_desktop_audio_prepare(struct apple_epic_service *service, const char *name, const char *class, s64 unit) { struct apple_dcp *dcp = service->ep->dcp; - if (dcp->fw_compat != DCP_FIRMWARE_V_26_6_DESKTOP || !dcp->external || - service->ep->endpoint != AV_AUDIO_ENDPOINT_DESKTOP || - !name || strcmp(name, "dcpav-audio-epic") || unit != 0) + if (dcp->fw_compat != DCP_FIRMWARE_V_26_6_DESKTOP || !dcp->desktop_external || + service->ep->endpoint != AV_AUDIO_ENDPOINT_DESKTOP || !name) return -EINVAL; - return 0; + if (!strcmp(name, av_desktop_ops[0].name) && unit == 0) + return 0; + if (unit == -1 && afk_compact_cut_of(&av_desktop_ops[0], name)) + return 0; + return -EINVAL; } static const struct apple_epic_service_ops av_desktop_ops[] = { { - .name = "dcpav-audio-epic", + .name = "dcpav-audio-interface-epic", + .compact_full = "dcpav-audio-interface-epic:0", .reusable = true, .prepare = av_desktop_audio_prepare, .init = av_audiosrv_init, @@ -1032,7 +1044,7 @@ int avep_init(struct apple_dcp *dcp) if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) - if (!dcp->external) + if (!dcp->desktop_external) return -EOPNOTSUPP; ops = av_desktop_ops; av_endpoint = AV_AUDIO_ENDPOINT_DESKTOP; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 5b9f50b60d300..e7d3d9891aa4f 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -447,6 +447,8 @@ struct apple_dcp { /* Bumped by every iomfb poweron; see afk_compact_slot(). */ u32 afk_power_gen; bool external; + /* A desktop 26.x external processor (apple,t6041-dcpext) */ + bool desktop_external; /* * T8122 dcpext: the panel's DRM device never waits on this processor. * A probe or bind failure leaves it in the device as an unusable pipe diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index f56c4423ea247..a724f318a778e 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -5888,6 +5888,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) dcp->ext_failsafe = of_device_is_compatible(dev->of_node, "apple,t8122-dcpext") || of_device_is_compatible(dev->of_node, "apple,t6041-dcpext"); dcp->external = of_device_is_compatible(dev->of_node, "apple,t6030-dcpext"); + dcp->desktop_external = of_device_is_compatible(dev->of_node, "apple,t6041-dcpext"); dcp->external_native = dcp->external && dcp_t6030_ext_native(dev->of_node); dcp_external_audio_init(dcp); dcp->dev = dev; From ec8e1fa90f9994d6f9f40c38b9716deedb10a1f8 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:17:41 +1100 Subject: [PATCH 097/342] arm64: dts: apple: t6040-j616s: enable the DPA1 audio chain Enable what the first DisplayPort/HDMI audio stream needs: the SIO CPU power domain, the SIO DART and mailbox, the DPA power domains and the DPA1 client of DCPEXT0 (SIO channel 0x66). The SIO node itself stays disabled: the boot loader enables it once it has reserved the firmware iBoot preloaded and published the T6041 boot tables, and finds it through the new "sio" alias. Without such a loader DPA1 waits for its channel. DPA2 (DCPEXT1, channel 0x68) stays disabled until it is qualified. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../boot/dts/apple/t6040-j616s-dpaudio.dtsi | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi index 8acd2d04aea8d..a43d5df5683c3 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi @@ -1,18 +1,28 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT /* * DPA1 and DPA2 belong to DCPEXT0 and DCPEXT1, respectively. SIO supplies - * their sample streams; neither interface has AP-side registers. Keep the - * clients disabled until the T6041 SIO firmware backend and loader handoff - * are available and the compact audio protocol has been qualified. + * their sample streams; neither interface has AP-side registers. + * + * The first chain is enabled: the SIO DART, mailbox and CPU domain, DPA1 + * and its client. The SIO itself stays disabled here: iBoot has loaded its + * firmware, and the boot loader enables the node once it has reserved that + * firmware and published the T6041 boot tables (it finds it by the alias). + * Without a T6041-aware loader DPA1 waits for its DMA channel and nothing + * else changes. The DCP side starts only with appledrm.hdmi_audio=1. + * DPA2 (DCPEXT1, SIO channel 0x68) stays disabled until it is qualified. */ / { + aliases { + sio = &sio; + }; + dpaudio1: audio-controller-1 { compatible = "apple,t6041-dpaudio", "apple,dpaudio"; dmas = <&sio 0x66>; dma-names = "tx"; power-domains = <&ps_dpa1>; - status = "disabled"; + status = "okay"; ports { #address-cells = <1>; @@ -75,3 +85,23 @@ }; }; }; + +&ps_sio_cpu { + status = "okay"; +}; + +&sio_dart { + status = "okay"; +}; + +&sio_mbox { + status = "okay"; +}; + +&ps_dpa_p { + status = "okay"; +}; + +&ps_dpa1 { + status = "okay"; +}; From dd39d21e83e6fadccf6e97ee298e5fc0ba1c4051 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:35:39 +1100 Subject: [PATCH 098/342] Documentation: gpu: apple-dcp: T6041 desktop audio service and DPA1 chain Name the published desktop audio service, describe how its cut compact announcement is admitted, and say which part of the J616s DPA chain the device tree enables and what the boot loader enables. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/gpu/apple-dcp-t6041-panel.rst | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Documentation/gpu/apple-dcp-t6041-panel.rst b/Documentation/gpu/apple-dcp-t6041-panel.rst index b75e6584bc1d2..d8834d7e1a877 100644 --- a/Documentation/gpu/apple-dcp-t6041-panel.rst +++ b/Documentation/gpu/apple-dcp-t6041-panel.rst @@ -190,9 +190,13 @@ Desktop external audio (draft) The desktop audio integration uses the existing DCP PCM and native link lifecycle, with a separate compact service binding on endpoint 0x2b. Endpoint -0x29 retains AV device control. Only the external firmware role admits the -``dcpav-audio-epic`` unit-zero service; the internal panel does not acquire an -audio client. The existing ``hdmi_audio`` opt-in still controls service startup. +0x29 retains AV device control. Only the external processors +(``apple,t6041-dcpext``) admit the ``dcpav-audio-interface-epic`` unit-zero +service; the internal panel does not acquire an audio client. With its role +prefix the compact announcement does not fit its 32-byte field and arrives cut +to 31 characters without the unit; such a cut of at least 20 characters is +admitted as unit zero. The existing ``hdmi_audio`` opt-in still controls +service startup. A PCM opens and pins one service instance. Prepare, Start, Stop and Complete use that instance's element link data. Sink termination disconnects the card, @@ -202,10 +206,12 @@ method replies must have the expected body length; serialized property replies must contain their declared used bytes within the actual received body. J616s DPA1 and DPA2 are described with SIO channels 0x66 and 0x68, connected -bidirectionally to DCPEXT0 and DCPEXT1 port zero, respectively. Both clients -remain disabled. This description does not enable SIO, its DART, its mailbox -or any DPA power domain. A generation-specific SIO firmware backend and loader -handoff are still required before a candidate may enable the clients. +bidirectionally to DCPEXT0 and DCPEXT1 port zero, respectively. DPA1 is +enabled with the SIO DART, mailbox, CPU domain and the DPA power domains. The +SIO node stays disabled in the device tree: the boot loader reserves the +firmware iBoot preloaded, publishes the T6041 boot tables and enables the node +(``apple,t6041-sio``, see the apple-sio driver). DPA2 stays disabled until it +is qualified the same way. The desktop service name/unit, shared 13.5 command numbers and native 14.7 link and element layouts are provisional integration choices. Build and synthetic From db2036536223b3f446a9fada2820782ef95e77b7 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 07:44:58 +1100 Subject: [PATCH 099/342] drm/apple: take the T6041 DCPEXT CEC interface on endpoint 0x2b Endpoint 0x2b of the M4 Pro/Max external processors also publishes their CEC interface, which arrives cut to "dispext0:dcpav-cec-interface-ep". Unmatched, every boot with appledrm.hdmi_audio=1 logged "unable to match compact service". The host makes no use of CEC: take it with the same no-op service the T6030 HDMI port uses and drop its reports. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/av-v14-test.c | 3 +++ drivers/gpu/drm/apple/av.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/gpu/drm/apple/av-v14-test.c b/drivers/gpu/drm/apple/av-v14-test.c index 4718b61c27c00..f0dbe8f079dd0 100644 --- a/drivers/gpu/drm/apple/av-v14-test.c +++ b/drivers/gpu/drm/apple/av-v14-test.c @@ -463,6 +463,9 @@ static void av_desktop_service_admission(struct kunit *test) KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(ops, "dcpav-audio-interface-epic:0")); KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(ops, "dcpav-audio-epic")); KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(&avep_ops[0], "DCPAVSimpleVideoInter")); + /* The CEC interface the same endpoint publishes, as it arrives on the J616s */ + KUNIT_EXPECT_TRUE(test, afk_compact_cut_of(&av_desktop_ops[1], "dcpav-cec-interface-ep")); + KUNIT_EXPECT_FALSE(test, afk_compact_cut_of(&av_desktop_ops[0], "dcpav-cec-interface-ep")); /* Only the desktop external processor's own flag admits it. */ t->dcp->desktop_external = false; KUNIT_EXPECT_EQ(test, av_desktop_audio_prepare(&t->svc, name, name, 0), -EINVAL); diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 567b03156d163..7b1e308890c02 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -697,6 +697,18 @@ static const struct apple_epic_service_ops av_desktop_ops[] = { .report = av_audiosrv_report, .teardown = av_audiosrv_teardown, }, + { + /* + * The same endpoint also publishes the processor's CEC + * interface, cut to "dcpav-cec-interface-ep" as above. The + * host makes no use of CEC: take it and drop its reports. + */ + .name = "dcpav-cec-interface-epic", + .compact_full = "dcpav-cec-interface-epic:0", + .init = av_cec_init, + .report = av_cec_report, + .teardown = av_cec_teardown, + }, {} }; #endif From 64ad8cbd2cea11af17c0175060a38d7b32ccd76a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:12:50 +1100 Subject: [PATCH 100/342] wifi: brcmfmac: fail a join whose BSS is gone instead of reporting success On the J616s (BCM4388), a reconnect that is still in flight when the system enters sleep logs, in 3 of 6 fleet suites: brcmf_inform_single_bss: Invalid Bss info record. Discarding WARNING: net/wireless/sme.c:845 at __cfg80211_connect_result WARNING: net/wireless/sme.c:1302 at __cfg80211_port_authorized cfg80211's suspend disconnects the interface (reason 3, locally generated) while the firmware completes the association. The link-up event is then processed against a torn-down join: GET_BSS_INFO returns no valid record, brcmf_update_bss_info()'s error is ignored, and the driver reports WLAN_STATUS_SUCCESS for a BSS that cfg80211 does not know. cfg80211 rejects that with the first WARN. For firmware-supplicant (PSK/SAE) joins it then gets a port-authorized event for a connection it never made, which is the second WARN. When the firmware cannot describe the BSS and cfg80211 has no entry for it either, report the join as failed and disassociate the firmware, so the two sides agree. The supplicant retries as for any failed join. A BSS that cfg80211 already knows (from a scan) is still reported as connected, as before. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index b415aaeb73479..75e2a3dd16059 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -6846,6 +6846,21 @@ brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg, return err; } +/* Whether cfg80211 has a BSS entry for @bssid (the firmware's may be gone). */ +static bool brcmf_bss_known(struct brcmf_cfg80211_info *cfg, const u8 *bssid) +{ + struct cfg80211_bss *bss; + + if (is_zero_ether_addr(bssid)) + return false; + bss = cfg80211_get_bss(cfg_to_wiphy(cfg), NULL, bssid, NULL, 0, + IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY); + if (!bss) + return false; + cfg80211_put_bss(cfg_to_wiphy(cfg), bss); + return true; +} + static s32 brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, struct net_device *ndev, const struct brcmf_event_msg *e, @@ -6864,7 +6879,25 @@ brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg, memset(&conn_params, 0, sizeof(conn_params)); if (completed) { brcmf_get_assoc_ies(cfg, ifp); - brcmf_update_bss_info(cfg, ifp); + if (brcmf_update_bss_info(cfg, ifp) && + !brcmf_bss_known(cfg, profile->bssid)) { + /* + * A link-up that raced the join's teardown (a + * disconnect for system sleep, say) leaves the + * firmware with no BSS to report, and cfg80211 + * has none either: it would reject the success + * with a WARN in __cfg80211_connect_result and + * another in __cfg80211_port_authorized. Report + * the join as failed and drop the firmware's + * half-made association instead. + */ + brcmf_dbg(CONN, "connected BSS %pM unknown, join failed\n", + profile->bssid); + brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, NULL, 0); + completed = false; + } + } + if (completed) { set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state); conn_params.status = WLAN_STATUS_SUCCESS; From 691e2fbdbe8e9bd661f3c512491f650ceedd3004 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:30:30 +1100 Subject: [PATCH 101/342] tools/asahi: test a join whose BSS was lost before its link-up brcmf-join-bssid-tests.py stubs brcmf_update_bss_info() with an error return now, plus brcmf_bss_known() and the DISASSOC command. Two new controls cover it. With no BSS from the firmware or cfg80211, every fwsup mode reports a failed join, is never authorized, and disassociates once. When the firmware lost the record but cfg80211 knows the BSS, the join stays a success. The new 'lost-bss-success' mutation, which keeps reporting success, must fail the controls. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- tools/asahi/brcmf-join-bssid-tests.py | 30 ++++++++++++++++++++++++++- tools/asahi/run-host-tests.py | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/asahi/brcmf-join-bssid-tests.py b/tools/asahi/brcmf-join-bssid-tests.py index ae29767becdc3..770b0af9764f7 100755 --- a/tools/asahi/brcmf-join-bssid-tests.py +++ b/tools/asahi/brcmf-join-bssid-tests.py @@ -24,6 +24,7 @@ '\t\t\tconn_params.links[0].bssid = profile->bssid;\n', '\t\tconn_params.links[0].bssid = profile->bssid;\n'), 'no-call': ('\tbrcmf_connect_set_target(profile, params->bssid);\n', ''), + 'lost-bss-success': ('\t\t\t\tcompleted = false;\n', '\t\t\t\t;\n'), } PREFIX = r''' @@ -67,7 +68,14 @@ static u8 reported_bssid[ETH_ALEN]; static bool reported_none; static void brcmf_get_assoc_ies(struct brcmf_cfg80211_info *c, struct brcmf_if *i) { (void)c; (void)i; } -static void brcmf_update_bss_info(struct brcmf_cfg80211_info *c, struct brcmf_if *i) { (void)c; (void)i; } +#define BRCMF_C_DISASSOC 52 +static s32 bss_info_err; +static bool bss_known = true; +static int disassocs; +static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *c, struct brcmf_if *i) { (void)c; (void)i; return bss_info_err; } +static bool brcmf_bss_known(struct brcmf_cfg80211_info *c, const u8 *b) { (void)c; (void)b; return bss_known; } +static s32 brcmf_fil_cmd_data_set(struct brcmf_if *i, u32 cmd, void *d, u32 l) +{ (void)i; (void)d; (void)l; if (cmd == BRCMF_C_DISASSOC) disassocs++; return 0; } static void cfg80211_connect_done(struct net_device *n, struct cfg80211_connect_resp_params *p, int gfp) { (void)n; (void)gfp; reports++; reported_status = p->status; @@ -141,6 +149,26 @@ assert(reports == 1 && !memcmp(reported_bssid, TRY24, ETH_ALEN) && authorized == 1); controls++; + /* A link-up after the join was torn down: no BSS from the firmware or cfg80211. */ + for (int fwsup = 0; fwsup <= BRCMF_PROFILE_FWSUP_SAE; fwsup++) { + start(TRY24, fwsup); + bss_info_err = -22; bss_known = false; disassocs = 0; + brcmf_bss_connect_done(&cfg, &ndev, &ssid, true); + assert(reports == 1 && reported_status == WLAN_STATUS_AUTH_TIMEOUT); + assert(!authorized && !test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif.sme_state)); + assert(disassocs == 1); + controls++; + } + + /* The firmware lost the record but cfg80211 knows the BSS: still connected. */ + start(TRY24, BRCMF_PROFILE_FWSUP_PSK); + bss_info_err = -22; bss_known = true; disassocs = 0; + brcmf_bss_connect_done(&cfg, &ndev, &psk, true); + assert(reports == 1 && reported_status == WLAN_STATUS_SUCCESS && authorized == 1); + assert(test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif.sme_state) && !disassocs); + bss_info_err = 0; + controls++; + /* Only one report per join. */ brcmf_bss_connect_done(&cfg, &ndev, NULL, false); assert(reports == 1); diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 84ced6b0f27d5..e472c9d74cc10 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -87,7 +87,7 @@ def mutations(flag, names, base, expect=KILL): 'brcmf-bss-tests.py': [(out(), PASS)], # The old revision reports a failed join against the last associated BSS. 'brcmf-join-bssid-tests.py': [(out(), PASS)] - + mutations('--mutation', ('stale-target', 'zero-named', 'no-call'), out()), + + mutations('--mutation', ('stale-target', 'zero-named', 'no-call', 'lost-bss-success'), out()), 'brcmf-pcie-dma-tests.py': [(out('--output'), PASS)] + mutations('--mutation', ('narrow-stream', 'ignore-aperture', 'revision-wide'), out('--output')), 'brcmf-roam-tests.py': [(out(), PASS)], From 85193a07c0d71d34a175971ef6d22df30abd17bb Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 09:32:16 +1100 Subject: [PATCH 102/342] ASoC: apple: mca: Bound the PCM buffer size again Commit 79af0bae4d0d ("ASoC: apple: mca: Make the capture buffers cacheable") stopped preallocating the capture buffers, so they are now allocated at hw_params to the buffer's own size. The 3 MiB preallocation was also what bounded the capture buffer: the core sets a substream's buffer_bytes_max to its preallocated size, and the runtime hardware leaves it at SIZE_MAX. Without a preallocation the sense PCM offers buffers of up to 4 GiB. speakersafetyd sets no buffer size on the speaker sense PCM, so alsa-lib picks the largest buffer and the NONCOHERENT allocation fails: snd_pcm_hw_params failed with error 'Out of memory (12)' speakersafetyd then panics and restarts in a loop. It never takes the speaker volume lock, and the speakers stay at the kernel's floor, with no sound on every MCA Mac it protects (seen on a J316 on 7.3.0-26.fc45.aurora, the kernel with the legacy unlock interface). Bound the PCM buffer at 3 MiB, the playback preallocation's size and the limit capture had before 79af0bae4d0d. Clients that size their own buffer (speakerguardd, PipeWire) ask for far less and are unaffected. Fixes: 79af0bae4d0d ("ASoC: apple: mca: Make the capture buffers cacheable") Assisted-by: LLM Signed-off-by: Ryan Murray --- sound/soc/apple/mca.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sound/soc/apple/mca.c b/sound/soc/apple/mca.c index 69abfcda7e813..18d73b50af861 100644 --- a/sound/soc/apple/mca.c +++ b/sound/soc/apple/mca.c @@ -127,6 +127,9 @@ SNDRV_PCM_FMTBIT_S24_LE | \ SNDRV_PCM_FMTBIT_S32_LE) +/* Largest PCM buffer, and the playback preallocation: 3 MiB. */ +#define MCA_BUFFER_BYTES_MAX (512 * 1024 * 6) + struct mca_cluster { int no; __iomem void *base; @@ -962,7 +965,15 @@ static int mca_set_runtime_hwparams(struct snd_soc_component *component, hw.periods_max = UINT_MAX; hw.period_bytes_min = 256; hw.period_bytes_max = dma_get_max_seg_size(dma_dev); - hw.buffer_bytes_max = SIZE_MAX; + /* + * The capture buffer is not preallocated (see mca_pcm_new()), so the + * core does not bound it by a preallocation: bound it here, at the size + * the playback preallocation (and formerly the capture one) allows. An + * unbounded maximum lets a client that sets no buffer size, such as + * speakersafetyd on the speaker sense PCM, ask for gigabytes and fail + * hw_params with -ENOMEM. + */ + hw.buffer_bytes_max = MCA_BUFFER_BYTES_MAX; hw.fifo_size = 16; ret = snd_dmaengine_pcm_refine_runtime_hwparams(substream, &dma_data, @@ -1245,7 +1256,7 @@ static int mca_pcm_new(struct snd_soc_component *component, chan->device->dev, 0, SIZE_MAX); else snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV_IRAM, - chan->device->dev, 512 * 1024 * 6, + chan->device->dev, MCA_BUFFER_BYTES_MAX, SIZE_MAX); } From f8c7547ef29eae71436808226b86601f7d112f80 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:47:08 +1100 Subject: [PATCH 103/342] arm64: dts: apple: j616s: enable USB4/Thunderbolt on the left front and right ports Enable ACIO1 (typec1, left front) and ACIO2 (typec2, right) the same way as ACIO0: router, its DART with the ACIO0 DVA window, NHI, mailbox and power domains, PCIe tunnel off. The routers' resets, LSTX pins, ring interrupts and Type-C graph links are already described. The loader hands every router its tuning and DROM. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 77 ++++++++++++++++++++++- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index 0e29b6291ed9f..0d7c60454d480 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -167,9 +167,10 @@ }; /* - * USB4/Thunderbolt on the left back port (typec0, ACIO0). The loader hands - * the router, adapter and NHI tuning and the DROM over. No PCIe tunnel yet: - * host-to-host (XDomain, thunderbolt-net) and USB4 links only. + * USB4/Thunderbolt on all three Type-C ports: typec0 (left back, ACIO0), + * typec1 (left front, ACIO1) and typec2 (right, ACIO2). The loader hands + * each router its router, adapter and NHI tuning and its DROM over. No PCIe + * tunnels yet: host-to-host (XDomain, thunderbolt-net) and USB4 links only. */ &pmgr_cio { status = "okay"; @@ -209,3 +210,73 @@ &usb4_0_nhi { status = "okay"; }; + +&ps_atc1_cio { + status = "okay"; +}; + +&ps_atc1_pcie { + status = "okay"; +}; + +&ps_atc1_cio_pcie { + status = "okay"; +}; + +&ps_atc1_cio_usb { + status = "okay"; +}; + +&usb4_1_mbox { + status = "okay"; +}; + +&usb4_1_acio { + /delete-property/ apple,pcie-tunnel; + status = "okay"; +}; + +&usb4_1_dart { + /* The same DVA window as the ACIO0 router DART. */ + apple,dma-range = <0x100 0x4000 0x0 0xffff0000>; + status = "okay"; +}; + +&usb4_1_nhi { + status = "okay"; +}; + +&ps_atc2_cio { + status = "okay"; +}; + +&ps_atc2_pcie { + status = "okay"; +}; + +&ps_atc2_cio_pcie { + status = "okay"; +}; + +&ps_atc2_cio_usb { + status = "okay"; +}; + +&usb4_2_mbox { + status = "okay"; +}; + +&usb4_2_acio { + /delete-property/ apple,pcie-tunnel; + status = "okay"; +}; + +&usb4_2_dart { + /* The same DVA window as the ACIO0 router DART. */ + apple,dma-range = <0x100 0x4000 0x0 0xffff0000>; + status = "okay"; +}; + +&usb4_2_nhi { + status = "okay"; +}; From 2e23899af9db961603b0dece672d22d2cfcfa1ba Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:40:00 +1100 Subject: [PATCH 104/342] drm/apple: keep display sound cards after the built-in ones The DCPs probe before the built-in audio, so a display audio card took the first free slot and moved the speakers, the headphone jack and the microphones up by one (on the J616s macaudio went from card 1 to 2). Anything that names the built-in cards by number then picks the wrong one. Register display cards from slot 8 up. The built-in cards keep the numbers they have without display audio, whatever the probe order. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/audio.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 44c228deb2a89..48539904efa91 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -1323,6 +1323,17 @@ static void dcpaud_expose_debugfs_blob(struct dcp_audio *dcpaud, const char *nam extern bool hdmi_audio; +/* + * The DCPs probe before the built-in audio (speakers, headphone jack, + * microphones), and a display card in the first free slot would move + * those. Display cards take the slots from DCPAUD_FIRST_SLOT up, so the + * built-in cards keep their numbers whether or not display audio is on. + * A negative index is a mask of acceptable slots, see snd_card_new(). + */ +#define DCPAUD_FIRST_SLOT 8 +#define DCPAUD_CARD_SLOTS (SNDRV_CARDS > DCPAUD_FIRST_SLOT ? \ + (int)~(BIT(DCPAUD_FIRST_SLOT) - 1) : SNDRV_DEFAULT_IDX1) + static int dcpaud_init_snd_card(struct dcp_audio *dcpaud) { int ret; @@ -1330,7 +1341,7 @@ static int dcpaud_init_snd_card(struct dcp_audio *dcpaud) return -ENODEV; - ret = snd_card_new(dcpaud->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, + ret = snd_card_new(dcpaud->dev, DCPAUD_CARD_SLOTS, SNDRV_DEFAULT_STR1, THIS_MODULE, 0, &dcpaud->card); if (ret) return ret; From 333ea91c896b566bfa686e1dd3d5fc62c14ea4d4 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:40:01 +1100 Subject: [PATCH 105/342] drm/apple: turn DP/HDMI audio on by default On macOS a display that takes audio is an output as soon as it is connected, over HDMI and over DisplayPort, USB-C alt mode and docks included. Here it took appledrm.hdmi_audio=1, so nobody had it. Make hdmi_audio default to on. Every processor whose port@0 links an audio device starts its audio endpoint and registers its card; one without stays as it is. hdmi_audio=0 still turns it all off. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/gpu/apple-dcp-t6041-panel.rst | 2 +- arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi | 2 +- drivers/gpu/drm/apple/av.c | 2 +- drivers/gpu/drm/apple/av.h | 2 +- drivers/gpu/drm/apple/dcp.c | 12 +++++++++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Documentation/gpu/apple-dcp-t6041-panel.rst b/Documentation/gpu/apple-dcp-t6041-panel.rst index d8834d7e1a877..c131fb02a5683 100644 --- a/Documentation/gpu/apple-dcp-t6041-panel.rst +++ b/Documentation/gpu/apple-dcp-t6041-panel.rst @@ -195,7 +195,7 @@ lifecycle, with a separate compact service binding on endpoint 0x2b. Endpoint service; the internal panel does not acquire an audio client. With its role prefix the compact announcement does not fit its 32-byte field and arrives cut to 31 characters without the unit; such a cut of at least 20 characters is -admitted as unit zero. The existing ``hdmi_audio`` opt-in still controls +admitted as unit zero. ``hdmi_audio`` (on by default; 0 turns it off) controls service startup. A PCM opens and pins one service instance. Prepare, Start, Stop and Complete diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi index a43d5df5683c3..1f6e862285bc2 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi @@ -8,7 +8,7 @@ * firmware, and the boot loader enables the node once it has reserved that * firmware and published the T6041 boot tables (it finds it by the alias). * Without a T6041-aware loader DPA1 waits for its DMA channel and nothing - * else changes. The DCP side starts only with appledrm.hdmi_audio=1. + * else changes. The DCP side starts unless appledrm.hdmi_audio=0. * DPA2 (DCPEXT1, SIO channel 0x68) stays disabled until it is qualified. */ diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 7b1e308890c02..23d963992cbdd 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -1069,7 +1069,7 @@ int avep_init(struct apple_dcp *dcp) * Only a processor whose port@0 links an audio device has DP/HDMI * audio to start. Look before the firmware: a processor without one * (an internal panel's, or one whose firmware has no audio service - * here, such as H17P) stays as it is without hdmi_audio, quietly. + * here, such as H17P) stays as it is, quietly. */ endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0); if (endpoint) { diff --git a/drivers/gpu/drm/apple/av.h b/drivers/gpu/drm/apple/av.h index 1d710b0f706f3..6d25d83d78d79 100644 --- a/drivers/gpu/drm/apple/av.h +++ b/drivers/gpu/drm/apple/av.h @@ -6,7 +6,7 @@ //int avep_audiosrv_startlink(struct apple_dcp *dcp, struct dcp_sound_cookie *cookie); //int avep_audiosrv_stoplink(struct apple_dcp *dcp); -/* dcp.c: the opt-in to DP/HDMI audio (appledrm.hdmi_audio). */ +/* dcp.c: DP/HDMI audio, on unless appledrm.hdmi_audio=0. */ extern bool hdmi_audio; #if IS_ENABLED(CONFIG_DRM_APPLE_AUDIO) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index a724f318a778e..f233c079997cc 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -204,9 +204,15 @@ static bool show_notch; module_param(show_notch, bool, 0644); MODULE_PARM_DESC(show_notch, "Use the full display height and show the notch (also when /chosen/asahi,show-notch is \"1\")"); -bool hdmi_audio; +/* + * DP/HDMI audio of external displays, on by default as on macOS: a display + * that takes audio, over HDMI or DisplayPort (USB-C alt mode included), + * is an audio output while it is connected. hdmi_audio=0 leaves the audio + * endpoints stopped and registers no sound cards. + */ +bool hdmi_audio = true; module_param(hdmi_audio, bool, 0644); -MODULE_PARM_DESC(hdmi_audio, "Enable unstable HDMI audio support"); +MODULE_PARM_DESC(hdmi_audio, "DP/HDMI audio of external displays (default: on)"); static bool unstable_edid = true; module_param(unstable_edid, bool, 0644); @@ -3919,7 +3925,7 @@ int dcp_start(struct platform_device *pdev) /* * A native T6030 external processor: its DP/HDMI audio endpoint (EP 0x29) - * on the driver's opt-in (hdmi_audio), as the other DCPs start it, for a + * unless hdmi_audio is off, as the other DCPs start it, for a * processor whose port@0 links an audio device; once per session, and after * the first display's EDID was read: with the endpoint's interfaces * published, an EDID copy (dcpavserv_copy_edid()) has the firmware rebuild From 9532c57d63be076a77ad97b9a3f0aa681e2ecc5f Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:40:51 +1100 Subject: [PATCH 106/342] arm64: dts: apple: t6040-j616s: enable DP audio on DCPEXT1 DCPEXT1 drives USB-C DisplayPort on the J616s, next to DCPEXT0 (HDMI, and USB-C when DCPEXT1 is taken). Its audio interface is DPA2 on SIO channel 0x68, as macOS has it (dp-audio2, DCPAVAudioDMADelegate). With only DPA1 enabled a display on the port DCPEXT1 drives had no audio. Enable DPA2 and its power domain, as DPA1 already is. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../boot/dts/apple/t6040-j616s-dpaudio.dtsi | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi index 1f6e862285bc2..597feaa71ac51 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi @@ -3,13 +3,13 @@ * DPA1 and DPA2 belong to DCPEXT0 and DCPEXT1, respectively. SIO supplies * their sample streams; neither interface has AP-side registers. * - * The first chain is enabled: the SIO DART, mailbox and CPU domain, DPA1 - * and its client. The SIO itself stays disabled here: iBoot has loaded its - * firmware, and the boot loader enables the node once it has reserved that - * firmware and published the T6041 boot tables (it finds it by the alias). - * Without a T6041-aware loader DPA1 waits for its DMA channel and nothing - * else changes. The DCP side starts unless appledrm.hdmi_audio=0. - * DPA2 (DCPEXT1, SIO channel 0x68) stays disabled until it is qualified. + * Both chains are enabled: the SIO DART, mailbox and CPU domain, DPA1 and + * DPA2 and their clients. The SIO itself stays disabled here: iBoot has + * loaded its firmware, and the boot loader enables the node once it has + * reserved that firmware and published the T6041 boot tables (it finds it + * by the alias). Without a T6041-aware loader DPA1 and DPA2 wait for their + * DMA channels and nothing else changes. The DCP side starts unless + * appledrm.hdmi_audio=0. */ / { @@ -42,7 +42,7 @@ dmas = <&sio 0x68>; dma-names = "tx"; power-domains = <&ps_dpa2>; - status = "disabled"; + status = "okay"; ports { #address-cells = <1>; @@ -105,3 +105,7 @@ &ps_dpa1 { status = "okay"; }; + +&ps_dpa2 { + status = "okay"; +}; From ae7bd1043f2fc90df3a241885e4ae5d4a64c868a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:43:15 +1100 Subject: [PATCH 107/342] drm/apple: give display audio an ELD control Userspace names a display's audio output after the display, as macOS does, from the ELD control HDMI codecs have: PipeWire and PulseAudio read the monitor name, the channel count and the speaker layout from it. The DCP audio card had none, so every display was "Apple DisplayPort" in GNOME and KDE. Add the ELD control (PCM device 0, read-only, volatile) and fill it on connect from the ELD drm builds for the connector the processor drives. The firmware may hand out an EDID rebuilt from its display metadata, with no CTA-861 audio block: a sink the firmware reports as taking audio then gets the basic audio CTA-861 requires of every sink with audio, two-channel LPCM at 32, 44.1 and 48 kHz. The control is cleared on disconnect and changes before the jack does, so the name is there when the output becomes available. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/audio.c | 97 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/apple/audio.h | 1 + drivers/gpu/drm/apple/av.c | 24 +++++++++ 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 48539904efa91..64496a827c776 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -23,6 +23,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -36,6 +40,7 @@ #define DCPAUD_ELEMENTS_MAXSIZE 16384 #define DCPAUD_PRODUCTATTRS_MAXSIZE 1024 +#define DCPAUD_ELD_SIZE MAX_ELD_BYTES /* The native element catalog capacity (14.7 external role). */ #define DCPAUD_ELEMENTS_V14_7 SZ_256K @@ -70,6 +75,7 @@ struct dcp_audio { struct dma_chan *chan; struct snd_card *card; struct snd_jack *jack; + struct snd_kcontrol *eld_ctl; struct snd_pcm_substream *substream; unsigned int open_cookie; bool open_unplugged; @@ -78,6 +84,8 @@ struct dcp_audio { bool dcp_connected; /// dcp status keep for delayed initialization bool connected; unsigned int connection_cookie; + /* The connected sink's ELD, zero while none is; data_lock */ + u8 eld[DCPAUD_ELD_SIZE]; /* When the sink was last connected */ ktime_t connected_at; @@ -1261,8 +1269,39 @@ static int dcpaud_create_pcm(struct dcp_audio *dcpaud) return 0; } +/* + * The sink's ELD, so that userspace names the output after the display, as + * macOS does, and sees its formats. drm builds it from the EDID. An EDID + * without a CTA-861 audio block (the firmware may provide one rebuilt from + * its display metadata, which has none) gets the basic audio CTA-861 makes + * every sink with audio take: two-channel LPCM at 32, 44.1 and 48 kHz. A + * sink is connected here only once the firmware reports it takes audio. + */ +static void dcpaud_build_eld(struct dcp_audio *dcpaud, u8 *eld) +{ + u8 *sad; + + if (dcp_audio_sink_eld(dcpaud->dcp_dev, eld, DCPAUD_ELD_SIZE) || + !eld[DRM_ELD_VER]) { + memset(eld, 0, DCPAUD_ELD_SIZE); + eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D; + } + if (!drm_eld_sad_count(eld)) { + sad = eld + DRM_ELD_CEA_SAD(drm_eld_mnl(eld), 0); + sad[0] = (HDMI_AUDIO_CODING_TYPE_PCM << 3) | (2 - 1); + sad[1] = BIT(0) | BIT(1) | BIT(2); /* 32, 44.1, 48 kHz */ + sad[2] = BIT(0) | BIT(1) | BIT(2); /* 16, 20, 24 bits */ + eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= 1 << DRM_ELD_SAD_COUNT_SHIFT; + if (!(eld[DRM_ELD_SPEAKER] & DRM_ELD_SPEAKER_MASK)) + eld[DRM_ELD_SPEAKER] = DRM_ELD_SPEAKER_FLR; + } + eld[DRM_ELD_BASELINE_ELD_LEN] = + DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4); +} + /* expects to be called with data_lock locked and unlocks it */ -static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected) +static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected, + const u8 *eld) { struct snd_pcm_substream *substream = dcpaud->substream; @@ -1276,8 +1315,14 @@ static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected) dcpaud->connection_cookie++; dcpaud->connected_at = ktime_get(); } + if (connected && eld) + memcpy(dcpaud->eld, eld, DCPAUD_ELD_SIZE); + else + memset(dcpaud->eld, 0, DCPAUD_ELD_SIZE); mutex_unlock(&dcpaud->data_lock); + /* The name first: the jack makes the output available. */ + snd_ctl_notify(dcpaud->card, SNDRV_CTL_EVENT_MASK_VALUE, &dcpaud->eld_ctl->id); snd_jack_report(dcpaud->jack, connected ? SND_JACK_AVOUT : 0); if (!connected) { @@ -1289,6 +1334,42 @@ static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected) } } +static int dcpaud_eld_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; + uinfo->count = DCPAUD_ELD_SIZE; + return 0; +} + +static int dcpaud_eld_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct dcp_audio *dcpaud = snd_kcontrol_chip(kcontrol); + + guard(mutex)(&dcpaud->data_lock); + memcpy(ucontrol->value.bytes.data, dcpaud->eld, DCPAUD_ELD_SIZE); + return 0; +} + +/* The ELD control of HDMI codecs, which PipeWire and PulseAudio read. */ +static int dcpaud_create_eld_ctl(struct dcp_audio *dcpaud) +{ + struct snd_kcontrol_new tmpl = { + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = "ELD", + .device = dcpaud->substream->pcm->device, + .info = dcpaud_eld_info, + .get = dcpaud_eld_get, + }; + + dcpaud->eld_ctl = snd_ctl_new1(&tmpl, dcpaud); + if (!dcpaud->eld_ctl) + return -ENOMEM; + return snd_ctl_add(dcpaud->card, dcpaud->eld_ctl); +} + static int dcpaud_create_jack(struct dcp_audio *dcpaud) { struct snd_card *card = dcpaud->card; @@ -1356,6 +1437,10 @@ static int dcpaud_init_snd_card(struct dcp_audio *dcpaud) if (ret) goto err_free_card; + ret = dcpaud_create_eld_ctl(dcpaud); + if (ret) + goto err_free_card; + ret = dcpaud_create_jack(dcpaud); if (ret) goto err_free_card; @@ -1375,10 +1460,16 @@ static int dcpaud_init_snd_card(struct dcp_audio *dcpaud) void dcpaud_connect(struct platform_device *pdev, bool connected) { struct dcp_audio *dcpaud = platform_get_drvdata(pdev); + u8 eld[DCPAUD_ELD_SIZE]; + + if (connected && dcpaud->dcp_dev) + dcpaud_build_eld(dcpaud, eld); + else + memset(eld, 0, sizeof(eld)); mutex_lock(&dcpaud->data_lock); - dcpaud_report_hotplug(dcpaud, connected); + dcpaud_report_hotplug(dcpaud, connected, eld); } void dcpaud_disconnect(struct platform_device *pdev) @@ -1389,7 +1480,7 @@ void dcpaud_disconnect(struct platform_device *pdev) dcpaud = platform_get_drvdata(pdev); mutex_lock(&dcpaud->data_lock); - dcpaud_report_hotplug(dcpaud, false); + dcpaud_report_hotplug(dcpaud, false, NULL); #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) /* The service may go without a release, and a held link with it. */ if (dcpaud->native_link) diff --git a/drivers/gpu/drm/apple/audio.h b/drivers/gpu/drm/apple/audio.h index 79bee44bcefbc..6cda3f38c9308 100644 --- a/drivers/gpu/drm/apple/audio.h +++ b/drivers/gpu/drm/apple/audio.h @@ -13,6 +13,7 @@ int dcp_audiosrv_stoplink(struct device *dev); int dcp_audiosrv_unprepare(struct device *dev); int dcp_audiosrv_get_elements(struct device *dev, void *elements, size_t maxsize); int dcp_audiosrv_get_product_attrs(struct device *dev, void *attrs, size_t maxsize); +int dcp_audio_sink_eld(struct device *dev, u8 *eld, size_t size); void dcpaud_connect(struct platform_device *pdev, bool connected); void dcpaud_disconnect(struct platform_device *pdev); diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 23d963992cbdd..81b7389f9f99f 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -591,6 +591,30 @@ int dcp_audiosrv_get_product_attrs(struct device *dev, void *attrs, size_t maxsi return ret; } +/* + * The ELD of the display this processor drives, as drm builds it from the + * connector's EDID: monitor name, vendor and product codes, connection type + * and the audio descriptors of a CTA-861 audio block, if there is one. + * Zeroes without a connector or EDID. + */ +int dcp_audio_sink_eld(struct device *dev, u8 *eld, size_t size) +{ + struct apple_dcp *dcp; + struct apple_connector *connector; + + KUNIT_STATIC_STUB_REDIRECT(dcp_audio_sink_eld, dev, eld, size); + memset(eld, 0, size); + dcp = dev_get_drvdata(dev); + if (!dcp) + return -ENODEV; + connector = READ_ONCE(dcp->connector); + if (!connector) + return -ENODEV; + guard(mutex)(&connector->base.eld_mutex); + memcpy(eld, connector->base.eld, min(size, sizeof(connector->base.eld))); + return 0; +} + #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) /* A DCPAV report (group 2) with command 1: Terminate. */ static bool av_report_terminate(const void *data, size_t size) From deb91317b986add207307ccde2498d78beda4229 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:46:00 +1100 Subject: [PATCH 108/342] soc: apple: clpc: hold the T6040 DRAM floor for ANE work On the M4 Pro the ANE votes only the PMC SoC-max floor (fabric 2) while an EXECUTE is in flight. Nothing raises the DRAM controller: the DCS stays at state 0 unless a CPU cluster happens to be busy. ResNet-50 streams about 50 MB of weights per inference, so it runs DRAM bound: host p50 1.43 ms with a 0.93-1.98 ms spread, the fast runs being the ones where CLPC had raised the DCS for an unrelated CPU burst. Give the T6040 CLPC the ANE input the T8140 already has (DCS 5, fabric 2: the states a busy CPU cluster gets), let apple_clpc_ane_get() find the T6041 CLPC, and publish H16 EXECUTEs in flight from the H16 backend, next to the existing perf floor vote. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_backend.c | 10 ++++++++++ drivers/soc/apple/clpc.c | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index e44e55e6ac510..5b8cd939d1a5f 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,8 @@ struct ane_h16_device { /* Optional "perf" floor, voted only while an EXECUTE is in flight. */ struct device *perf; bool perf_held; + /* Optional CLPC input: DRAM and fabric floors while an EXECUTE is in flight. */ + struct apple_clpc_ane *clpc; struct device *dart[3]; u32 powered; u32 darts_powered; @@ -1171,6 +1174,8 @@ static void ane_h16_release(struct ane_h16_device *h) dev_pm_domain_detach(h->perf, false); h->perf = NULL; } + apple_clpc_ane_put(h->clpc); + h->clpc = NULL; while (h->powered) { struct device *pd = h->power[--h->powered]; @@ -1216,6 +1221,7 @@ static void ane_h16_busy(void *ctx, bool busy) { struct ane_h16_device *h = ctx; + apple_clpc_ane_set_active(h->clpc, busy); if (!h->perf) return; if (busy) { @@ -1292,6 +1298,10 @@ static int ane_h16_acquire(struct platform_device *pdev, struct ane_h16_device * if (ret) return ret; } + /* Optional: success with no input when the SoC's CLPC takes none. */ + ret = apple_clpc_ane_get(h->dev, &h->clpc); + if (ret) + return ret; for (i = 0; i < ARRAY_SIZE(names); i++) { struct resource *r = platform_get_resource_byname(pdev, IORESOURCE_MEM, names[i]); diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index fa94e1d522937..26aa54fffa2be 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -334,6 +334,13 @@ void apple_clpc_ane_put(struct apple_clpc_ane *ane) } EXPORT_SYMBOL_GPL(apple_clpc_ane_put); +/* SoCs whose CLPC takes ANE input; each SoC has exactly one CLPC. */ +static const struct of_device_id apple_clpc_ane_providers[] = { + { .compatible = "apple,t6041-clpc" }, + { .compatible = "apple,t8140-clpc" }, + {} +}; + int apple_clpc_ane_get(struct device *dev, struct apple_clpc_ane **out) { struct device_node *np; @@ -345,10 +352,10 @@ int apple_clpc_ane_get(struct device *dev, struct apple_clpc_ane **out) return 0; np = of_parse_phandle(dev->of_node, "apple,clpc", 0); if (!np && !of_find_property(dev->of_node, "apple,clpc", NULL)) - np = of_find_compatible_node(NULL, NULL, "apple,t8140-clpc"); + np = of_find_matching_node(NULL, apple_clpc_ane_providers); if (!np) return 0; - if (!of_device_is_compatible(np, "apple,t8140-clpc")) { + if (!of_match_node(apple_clpc_ane_providers, np)) { of_node_put(np); return 0; } @@ -1181,6 +1188,13 @@ static const struct apple_clpc_hw apple_clpc_hw_t6040 = { .sustain = 3, .gpu_demand = false, .gpu_input = true, + /* + * The ANE's own floor (PMC SoC-max) holds only the fabric. ResNet-50 + * streams about 50 MB of weights per inference, and with DRAM left at + * DCS 0 an EXECUTE takes 0.9-2.0 ms (p50 1.43 ms) instead of 0.9 ms. + * Hold the same qualified DCS 5 / fabric 2 a busy CPU cluster gets. + */ + .ane = { [APPLE_CLPC_DCS] = 5, [APPLE_CLPC_SOC] = 2 }, }; /* @@ -1393,6 +1407,9 @@ static void apple_clpc_ane_demand_hold_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, apple_clpc_ane_input_demand(clpc, demand)); KUNIT_EXPECT_GT(test, ane.updated_ns, 0ull); KUNIT_EXPECT_EQ(test, ane.sequence, 4ull); + /* T6040 holds its top qualified DCS and fabric states for the ANE. */ + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6040.ane[APPLE_CLPC_DCS], 5); + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6040.ane[APPLE_CLPC_SOC], 2); } static void apple_clpc_ane_states_test(struct kunit *test) @@ -1435,7 +1452,6 @@ static void apple_clpc_ane_no_provider_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, apple_clpc_ane_input_demand(clpc, demand)); KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_DCS], 0u); KUNIT_EXPECT_EQ(test, demand[APPLE_CLPC_SOC], 0u); - KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6040.ane[APPLE_CLPC_DCS], 0); KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8132.ane[APPLE_CLPC_DCS], 0); KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8142.ane[APPLE_CLPC_DCS], 0); } From 3241d0c726a4eef94148dba7b399b8c88ab9d37e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:46:20 +1100 Subject: [PATCH 109/342] drm/apple: retry an audio open the firmware gave to a replaced instance When a display wakes up (DPMS on), the DCP reports its sink on the audio interface instance it had and replaces that instance some 200 ms later. PipeWire opens the PCM as soon as the jack turns on, the Open goes to the old instance, the firmware answers it with a reply that matches no call, and the Open times out a second later. PipeWire then drops the output for good: on the J616s, with the Acer QG270 S3 on a USB-C dock, every DPMS cycle left the display without an audio output ("playback open failed: Connection timed out"). Retry the Open once when the published instance changed while it ran. The second Open goes to the new instance and is answered. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/av.c | 68 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 81b7389f9f99f..fae38c8468ad3 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -295,7 +295,8 @@ int dcp_audiosrv_open(struct device *dev) struct apple_dcp *dcp = dev_get_drvdata(dev); struct audiosrv_data *asrv = dcp->audiosrv; struct apple_epic_service *srv; - u8 reply[32] = {}; + u8 reply[32]; + bool replaced; u64 gen; int ret; @@ -303,32 +304,51 @@ int dcp_audiosrv_open(struct device *dev) return -ENODEV; guard(mutex)(&asrv->open_lock); - scoped_guard(rwsem_read, &asrv->srv_rwsem) { - srv = afk_service_get(asrv->srv); - gen = asrv->gen; - } - if (!srv) - return -ENODEV; - if (asrv->open_srv) { - if (asrv->open_gen == gen) { - afk_service_put(srv); - return 0; + /* + * A display that wakes up (DPMS on) reports its sink on the audio + * interface it had, and the firmware replaces that instance a few + * hundred milliseconds later: an Open sent in between is refused + * with a reply that matches no call, and times out. The Open that + * follows the replacement is answered, so try the instance published + * by then once more. Userspace drops an output whose first open + * fails, so this is the difference between a display with and + * without audio after it wakes up. + */ + for (int attempt = 0; ; attempt++) { + scoped_guard(rwsem_read, &asrv->srv_rwsem) { + srv = afk_service_get(asrv->srv); + gen = asrv->gen; + } + if (!srv) + return -ENODEV; + if (asrv->open_srv) { + if (asrv->open_gen == gen) { + afk_service_put(srv); + return 0; + } + /* An earlier instance's open went with that instance. */ + afk_service_put(asrv->open_srv); + asrv->open_srv = NULL; } - /* An earlier instance's open went with that instance. */ - afk_service_put(asrv->open_srv); - asrv->open_srv = NULL; - } - /* Open: a zero body; status at +0, the opened Boolean at +16. */ - ret = av_audiosrv_call(srv, asrv->cmds.open, NULL, 0, 32, reply, sizeof(reply)); - if (!ret && (get_unaligned_le32(reply) || !get_unaligned_le64(reply + 16))) { - dev_err(dev, "audiosrv: open answered %#x, opened %llu\n", - get_unaligned_le32(reply), get_unaligned_le64(reply + 16)); - ret = -EIO; - } - if (ret) { + /* Open: a zero body; status at +0, the opened Boolean at +16. */ + memset(reply, 0, sizeof(reply)); + ret = av_audiosrv_call(srv, asrv->cmds.open, NULL, 0, 32, reply, sizeof(reply)); + if (!ret && (get_unaligned_le32(reply) || !get_unaligned_le64(reply + 16))) { + dev_err(dev, "audiosrv: open answered %#x, opened %llu\n", + get_unaligned_le32(reply), get_unaligned_le64(reply + 16)); + ret = -EIO; + } + if (!ret) + break; afk_service_put(srv); - return ret; + if (attempt) + return ret; + scoped_guard(rwsem_read, &asrv->srv_rwsem) + replaced = asrv->srv && asrv->gen != gen; + if (!replaced) + return ret; + dev_dbg(dev, "audiosrv: open on a replaced instance failed (%d), retrying\n", ret); } asrv->open_srv = srv; asrv->open_gen = gen; From 44f79bc3863431b9674ae599732d787dfb99d455 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:19:13 +1100 Subject: [PATCH 110/342] drm/apple: take the T6041 DCPEXT video interface on endpoint 0x2b With display audio on, every power-on of a display on a T6041 DCPEXT logged "unable to match compact service" for its DCPAV video interface, which endpoint 0x2b publishes cut to "dispext0:dcpav-video-interface-". The video side runs through IOMFB: take the interface with the no-op service the CEC interface already uses. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/av.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index fae38c8468ad3..550e695e2485c 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -753,6 +753,18 @@ static const struct apple_epic_service_ops av_desktop_ops[] = { .report = av_cec_report, .teardown = av_cec_teardown, }, + { + /* + * And its video interface, cut to "dcpav-video-interface-" on + * every display power-on. The video side runs through the + * IOMFB endpoint; take it like the CEC interface. + */ + .name = "dcpav-video-interface-epic", + .compact_full = "dcpav-video-interface-epic:0", + .init = av_cec_init, + .report = av_cec_report, + .teardown = av_cec_teardown, + }, {} }; #endif From f20d2ce0230c0ef7cd5e71aff6e222c03f569d4b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:46:00 +1100 Subject: [PATCH 111/342] soc: apple: clpc: hold the T6040 ANE cluster frequency floor On the M4 Pro the ANE engine runs at a speed set by the frequency of the second P cluster (cpu-map cluster2), whether or not anything runs on it. With that cluster at its idle frequency MobileNetV1 takes 65-375 us of engine time per EXECUTE (mean ~165 us) and ResNet-50 0.8-1.7 ms; with it at 3.3 GHz or above, 88-91 us and 0.70-0.97 ms. Raising the first P cluster or the E cluster changes nothing; above 3.756 GHz nothing more is gained. While ANE work is in flight, and for the vote hold after it, add a cpufreq minimum-frequency request of 3.756 GHz on that cluster, next to the DCS and fabric floors. The request is added on first use, since cpufreq may register after the CLPC, and dropped on halt. debugfs ane_cluster_khz sets the floor for A/B runs (0 = off). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/clpc.c | 131 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index 26aa54fffa2be..f1194055f6e0a 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -80,6 +81,10 @@ enum apple_clpc_rail { * @gpu_dense: submissions per sampling period that make light GPU work * dense, see apple_clpc_gpu_dense(); 0 for none * @ane: state of each rail while ANE work is in flight; all zero disables input + * @ane_cluster: /cpus/cpu-map cluster whose CPUs' frequency the ANE engine + * speed follows + * @ane_cluster_khz: minimum frequency of that cluster while ANE work is in + * flight; 0 for none * @gpu_input: the GPU driver reports its work in flight through * apple_clpc_gpu_get(); while there is some, both rails go to the top * of @map @@ -96,6 +101,8 @@ struct apple_clpc_hw { unsigned int gpu_dense; bool gpu_input; u8 ane[APPLE_CLPC_RAILS]; + unsigned int ane_cluster; + unsigned int ane_cluster_khz; }; struct apple_clpc_cluster { @@ -161,6 +168,12 @@ struct apple_clpc { struct apple_clpc_gpu *gpu; struct apple_clpc_ane *ane; unsigned int ane_states[APPLE_CLPC_RAILS]; + /* Minimum frequency of hw->ane_cluster while ANE work is in flight. */ + u32 ane_cluster_khz; + int ane_cpu; + struct freq_qos_request ane_qos; + unsigned int ane_qos_khz; + unsigned long ane_until; u32 last_floor; u32 last_reason; u64 last_vote_ns; @@ -678,6 +691,38 @@ static bool apple_clpc_gpu_input_demand(const struct apple_clpc_hw *hw, return true; } +/* + * Hold the ANE's cluster frequency floor from the first sample that sees ANE + * work until the vote hold after the last one. The request is added on first + * use: cpufreq may register its policies after the CLPC probes. + */ +static void apple_clpc_ane_cluster(struct apple_clpc *clpc, bool active, + unsigned long now) +{ + unsigned int khz = 0; + + if (active) + clpc->ane_until = now + msecs_to_jiffies(APPLE_CLPC_HOLD_MS); + if (time_before(now, clpc->ane_until)) + khz = clpc->ane_cluster_khz; + if (khz && !freq_qos_request_active(&clpc->ane_qos) && clpc->ane_cpu >= 0) { + struct cpufreq_policy *policy = cpufreq_cpu_get(clpc->ane_cpu); + + if (policy) { + if (freq_qos_add_request(&policy->constraints, &clpc->ane_qos, + FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE) < 0) + clpc->update_errors++; + cpufreq_cpu_put(policy); + } + } + if (khz == clpc->ane_qos_khz || !freq_qos_request_active(&clpc->ane_qos)) + return; + if (freq_qos_update_request(&clpc->ane_qos, khz ?: FREQ_QOS_MIN_DEFAULT_VALUE) < 0) + clpc->update_errors++; + else + clpc->ane_qos_khz = khz; +} + static void apple_clpc_sample(struct apple_clpc *clpc) { unsigned int demand[APPLE_CLPC_RAILS] = {}; @@ -707,6 +752,7 @@ static void apple_clpc_sample(struct apple_clpc *clpc) reason |= 2; if (apple_clpc_ane_input_demand(clpc, demand)) reason |= 32; + apple_clpc_ane_cluster(clpc, reason & 32, now); if (clpc->gpu_pmgr) { /* Both run every sample: each tracks state across samples. */ bool late = time_after(now, clpc->gpu_sampled + @@ -746,7 +792,8 @@ static void apple_clpc_sample(struct apple_clpc *clpc) clpc->update_errors++; /* Sample on time while graphics is powered, to see it power off. */ - apple_clpc_queue(clpc, !apple_clpc_floor(clpc, state) && !clpc->gpu_on); + apple_clpc_queue(clpc, !apple_clpc_floor(clpc, state) && !clpc->gpu_on && + !clpc->ane_qos_khz); } static void apple_clpc_work(struct work_struct *work) @@ -921,6 +968,10 @@ static void apple_clpc_halt(struct apple_clpc *clpc) clpc->saved_floor); for (rail = 0; rail < APPLE_CLPC_RAILS; rail++) clpc->vote[rail].state = 0; + if (clpc->ane_qos_khz && + freq_qos_update_request(&clpc->ane_qos, FREQ_QOS_MIN_DEFAULT_VALUE) >= 0) + clpc->ane_qos_khz = 0; + clpc->ane_until = jiffies; } static void apple_clpc_stop(void *data) @@ -940,9 +991,39 @@ static void apple_clpc_stop(void *data) apple_clpc_ane_detach(clpc->ane); debugfs_remove_recursive(clpc->debugfs); apple_clpc_halt(clpc); + if (freq_qos_request_active(&clpc->ane_qos)) + freq_qos_remove_request(&clpc->ane_qos); apple_clpc_free_clusters(clpc); } +/* The first CPU of /cpus/cpu-map/cluster@index, or -ENODEV. */ +static int apple_clpc_cluster_cpu(unsigned int index) +{ + struct device_node *map, *cluster, *core, *cpu; + char name[16]; + int id = -ENODEV; + + map = of_find_node_by_path("/cpus/cpu-map"); + if (!map) + return id; + snprintf(name, sizeof(name), "cluster%u", index); + cluster = of_get_child_by_name(map, name); + of_node_put(map); + if (!cluster) + return id; + core = of_get_child_by_name(cluster, "core0"); + of_node_put(cluster); + if (!core) + return id; + cpu = of_parse_phandle(core, "cpu", 0); + of_node_put(core); + if (cpu) { + id = of_cpu_node_to_id(cpu); + of_node_put(cpu); + } + return id; +} + static int apple_clpc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -985,6 +1066,15 @@ static int apple_clpc_probe(struct platform_device *pdev) for (rail = 0; rail < APPLE_CLPC_RAILS; rail++) clpc->ane_states[rail] = clpc->hw->ane[rail]; } + clpc->ane_cpu = -ENODEV; + if (clpc->ane && clpc->hw->ane_cluster_khz) { + clpc->ane_cpu = apple_clpc_cluster_cpu(clpc->hw->ane_cluster); + if (clpc->ane_cpu >= 0) + clpc->ane_cluster_khz = clpc->hw->ane_cluster_khz; + else + dev_warn(dev, "no CPU in cpu-map cluster%u: no ANE cluster floor\n", + clpc->hw->ane_cluster); + } /* The property is optional: without it, CPU demand alone sets the floors. */ if (clpc->hw->gpu_demand) gpu = of_parse_phandle(dev->of_node, "apple,gpu-power-state", 0); @@ -1059,6 +1149,9 @@ static int apple_clpc_probe(struct platform_device *pdev) if (clpc->ane) debugfs_create_file("ane_states", 0600, clpc->debugfs, clpc, &apple_clpc_ane_states_fops); + if (clpc->ane && clpc->ane_cpu >= 0) + debugfs_create_u32("ane_cluster_khz", 0600, clpc->debugfs, + &clpc->ane_cluster_khz); ret = devm_add_action_or_reset(dev, apple_clpc_stop, clpc); if (ret) @@ -1189,12 +1282,19 @@ static const struct apple_clpc_hw apple_clpc_hw_t6040 = { .gpu_demand = false, .gpu_input = true, /* - * The ANE's own floor (PMC SoC-max) holds only the fabric. ResNet-50 - * streams about 50 MB of weights per inference, and with DRAM left at - * DCS 0 an EXECUTE takes 0.9-2.0 ms (p50 1.43 ms) instead of 0.9 ms. - * Hold the same qualified DCS 5 / fabric 2 a busy CPU cluster gets. + * ANE work needs two things its own floor (PMC SoC-max: fabric 2) + * does not give it. ResNet-50 streams about 50 MB of weights per + * inference and runs DRAM bound at DCS 0, so hold the DCS 5 / fabric + * 2 a busy CPU cluster gets. And the engine runs at a speed set by + * the frequency of the second P cluster (cpu-map cluster2), whatever + * runs on it: MobileNetV1 takes 65-375 us of engine time (mean 165) + * with that cluster at its idle frequency and 88-91 us with it at + * 3.3 GHz or above (no gain above 3.756 GHz, measured at 1.8 to 4.5); + * the first P cluster and the E cluster make no difference. */ .ane = { [APPLE_CLPC_DCS] = 5, [APPLE_CLPC_SOC] = 2 }, + .ane_cluster = 2, + .ane_cluster_khz = 3756000, }; /* @@ -1412,6 +1512,26 @@ static void apple_clpc_ane_demand_hold_test(struct kunit *test) KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6040.ane[APPLE_CLPC_SOC], 2); } +static void apple_clpc_ane_cluster_test(struct kunit *test) +{ + struct apple_clpc *clpc = kunit_kzalloc(test, sizeof(*clpc), GFP_KERNEL); + unsigned long now = 1000; + + KUNIT_ASSERT_NOT_NULL(test, clpc); + /* No CPU for the cluster: the floor is never requested. */ + clpc->ane_cpu = -ENODEV; + clpc->ane_cluster_khz = apple_clpc_hw_t6040.ane_cluster_khz; + apple_clpc_ane_cluster(clpc, true, now); + KUNIT_EXPECT_FALSE(test, freq_qos_request_active(&clpc->ane_qos)); + KUNIT_EXPECT_EQ(test, clpc->ane_qos_khz, 0u); + /* The hold runs from the last active sample. */ + KUNIT_EXPECT_TRUE(test, time_before(now, clpc->ane_until)); + KUNIT_EXPECT_FALSE(test, time_before(now + msecs_to_jiffies(APPLE_CLPC_HOLD_MS), + clpc->ane_until)); + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t6040.ane_cluster, 2u); + KUNIT_EXPECT_EQ(test, apple_clpc_hw_t8140.ane_cluster_khz, 0u); +} + static void apple_clpc_ane_states_test(struct kunit *test) { struct apple_clpc *clpc = kunit_kzalloc(test, sizeof(*clpc), GFP_KERNEL); @@ -1485,6 +1605,7 @@ static void apple_clpc_ane_wake_removal_test(struct kunit *test) static struct kunit_case apple_clpc_cases[] = { KUNIT_CASE(apple_clpc_ane_demand_hold_test), KUNIT_CASE(apple_clpc_ane_states_test), + KUNIT_CASE(apple_clpc_ane_cluster_test), KUNIT_CASE(apple_clpc_ane_no_provider_test), KUNIT_CASE(apple_clpc_ane_wake_removal_test), KUNIT_CASE(apple_clpc_t8132_gpu_input_test), From 88b4acd769a0d01bfca40280226216a197c54516 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:47:49 +1100 Subject: [PATCH 112/342] tools/asahi: cover the T6040 ANE floors in the CLPC host demand test Extract apple_clpc_ane_cluster() into the host fixture with cpufreq QoS stand-ins and check that T6040 ANE work publishes DCS 5 / fabric 2, adds the cluster minimum-frequency request once, keeps it through the vote hold and drops it after. Two negative controls: the request never made, and the floor dropped without the hold. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- tools/asahi/clpc-gpu-demand-tests.py | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/asahi/clpc-gpu-demand-tests.py b/tools/asahi/clpc-gpu-demand-tests.py index c8c2c9d9ad361..57e3d43fc135e 100644 --- a/tools/asahi/clpc-gpu-demand-tests.py +++ b/tools/asahi/clpc-gpu-demand-tests.py @@ -38,6 +38,7 @@ def main(): 'static void apple_clpc_gpu_floor_count(', 'static bool apple_clpc_gpu_input_demand(', 'static bool apple_clpc_ane_input_demand(', + 'static void apple_clpc_ane_cluster(', 'static void apple_clpc_sample(']) code = r''' #include @@ -69,6 +70,20 @@ def main(): #define spin_lock_irqsave(l, f) ((void)(l), (f) = 0) #define spin_unlock_irqrestore(l, f) ((void)(l), (void)(f)) struct apple_clpc_cluster { unsigned int request[APPLE_CLPC_RAILS]; }; +// cpufreq QoS stand-ins: one policy, the last requested minimum is recorded. +#define FREQ_QOS_MIN 1 +#define FREQ_QOS_MIN_DEFAULT_VALUE 0 +struct freq_qos_request { bool active; int value; }; +struct cpufreq_policy { int constraints; }; +static struct cpufreq_policy policy; +static int qos_min = -1, qos_adds; +static bool freq_qos_request_active(struct freq_qos_request *r) { return r->active; } +static struct cpufreq_policy *cpufreq_cpu_get(int cpu) { (void)cpu; return &policy; } +static void cpufreq_cpu_put(struct cpufreq_policy *p) { (void)p; } +static int freq_qos_add_request(int *c, struct freq_qos_request *r, int type, int v) { + (void)c; assert(type==FREQ_QOS_MIN && !r->active); r->active=true; r->value=v; qos_min=v; qos_adds++; return 1; +} +static int freq_qos_update_request(struct freq_qos_request *r, int v) { assert(r->active); r->value=v; qos_min=v; return 1; } struct apple_clpc { const struct apple_clpc_hw *hw; struct apple_clpc_cluster clusters[1]; @@ -88,6 +103,11 @@ def main(): struct apple_clpc_gpu *gpu; struct apple_clpc_ane *ane; unsigned int ane_states[APPLE_CLPC_RAILS]; + u32 ane_cluster_khz; + int ane_cpu; + struct freq_qos_request ane_qos; + unsigned int ane_qos_khz; + unsigned long ane_until; }; static unsigned long jiffies; static u64 ktime_get_mono_fast_ns(void) { return jiffies * 1000000ull; } @@ -127,6 +147,25 @@ def main(): jiffies=1040; apple_clpc_sample(&c); assert(published==0 && queued_idle); } +// T6040 ANE work also holds the second P cluster at its qualified frequency, +// added on first use, for the vote hold after the last request, then drops it. +static void check_t6040_ane(void) { + struct apple_clpc_ane ane={0}; + struct apple_clpc c={.hw=&apple_clpc_hw_t6040,.agent=1,.mask=3,.ane=&ane}; + c.ane_states[APPLE_CLPC_DCS]=c.hw->ane[APPLE_CLPC_DCS]; + c.ane_states[APPLE_CLPC_SOC]=c.hw->ane[APPLE_CLPC_SOC]; + c.ane_cpu=9; c.ane_cluster_khz=c.hw->ane_cluster_khz; + assert(c.hw->ane_cluster==2 && c.ane_cluster_khz==3756000); + read_error=vote_error=0; pmgr_status=0; pmp_floor=0; jiffies=2000; published=~0u; qos_min=-1; qos_adds=0; + apple_clpc_sample(&c); assert(published==0 && qos_adds==0 && queued_idle); + ane.active=true; jiffies=2004; apple_clpc_sample(&c); + assert(published==0x25 && c.last_reason==32 && qos_adds==1 && qos_min==3756000); + ane.active=false; jiffies=2008; apple_clpc_sample(&c); + assert(qos_min==3756000 && !queued_idle); + jiffies=2036; apple_clpc_sample(&c); assert(published==0 && qos_min==0 && c.ane_qos_khz==0 && queued_idle); + ane.active=true; jiffies=2040; apple_clpc_sample(&c); assert(qos_adds==1 && qos_min==3756000); +} + // T8132's G16 firmware keeps graphics powered while the GPU idles: the // M5/F3 floor follows the work the GPU driver reports, as on T6040. static void check_t8132(void) { @@ -229,6 +268,7 @@ def main(): check_t8140(); check_t8140_dense(); check_t8140_ane(); + check_t6040_ane(); puts("PASS: T6040 and T8132 host demand; T8140 ANE, streaming, dense work, read errors and PMP backoff; idle release"); } ''' @@ -240,6 +280,10 @@ def main(): ('omit-host-demand', code.replace('if (apple_clpc_gpu_input_demand(clpc->hw, clpc->gpu, demand))', 'if (false && apple_clpc_gpu_input_demand(clpc->hw, clpc->gpu, demand))')), ('omit-ane-demand', code.replace('if (apple_clpc_ane_input_demand(clpc, demand))', 'if (false && apple_clpc_ane_input_demand(clpc, demand))')), + ('omit-ane-cluster', code.replace('apple_clpc_ane_cluster(clpc, reason & 32, now);', + '(void)apple_clpc_ane_cluster;')), + ('ane-cluster-no-hold', code.replace('if (time_before(now, clpc->ane_until))', + 'if (active)')), ('omit-streaming-demand', code.replace('bool streaming = apple_clpc_gpu_streaming(clpc, now);', 'bool streaming = (apple_clpc_gpu_streaming(clpc, now), false);')), ('omit-dense-demand', code.replace('if (streaming || dense) {', 'if (streaming || (dense && false)) {')), From 285908af68b66cb274884000b8aeb7746055f16d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:01:01 +1100 Subject: [PATCH 113/342] soc: apple: clpc: withdraw the ANE cluster floor with its cpufreq policy Review follow-ups for the T6040 ANE floors: - The cluster floor is a QoS request on a cpufreq policy, and the Apple cpufreq driver is a module: withdraw the request when that policy is removed (CPUFREQ_REMOVE_POLICY) instead of updating freed memory, and let the next ANE work add it again. - The floor was measured on the M4 Pro only. The M4 Max and T6050 share this CLPC table, so apply the cluster floor only on machines compatible with apple,t6040, and say so at debug level elsewhere. - Start the hold expired, and restart it from the current time once it has run out, so that jiffies wrap can never re-arm it. - The H16 backend looks the CLPC up again before its node appears, in case the CLPC bound after acquire, and says when the input is attached. - Drop an unneeded include. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_backend.c | 7 ++-- drivers/soc/apple/clpc.c | 52 +++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index 5b8cd939d1a5f..eb1de39a24f09 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -1458,6 +1458,9 @@ static int ane_h16_program_stage(struct ane_h16_device *h) { int ret; + /* Before the node exists: the CLPC may have bound after acquire. */ + if (!h->clpc && apple_clpc_ane_get(h->dev, &h->clpc)) + h->clpc = NULL; ret = ane_h16_session_init(&h->session, &h->boot.transport, &ane_h16_session_ops, h, h->boot.build->command_timeout_ns); if (!ret) { @@ -1470,8 +1473,8 @@ static int ane_h16_program_stage(struct ane_h16_device *h) return ret; } h->program_ready = true; - dev_info(h->dev, "H16 stage 5 program window %llx..%llx\n", h->program_next, - h->program_end - 1); + dev_info(h->dev, "H16 stage 5 program window %llx..%llx%s\n", h->program_next, + h->program_end - 1, h->clpc ? ", CLPC input attached" : ""); return 0; } diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index f1194055f6e0a..6dfd277463a13 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -21,7 +21,6 @@ */ #include -#include #include #include #include @@ -85,6 +84,8 @@ enum apple_clpc_rail { * speed follows * @ane_cluster_khz: minimum frequency of that cluster while ANE work is in * flight; 0 for none + * @ane_cluster_machine: the machine compatible the cluster floor was + * measured on; SoCs sharing this CLPC without it get no cluster floor * @gpu_input: the GPU driver reports its work in flight through * apple_clpc_gpu_get(); while there is some, both rails go to the top * of @map @@ -103,6 +104,7 @@ struct apple_clpc_hw { u8 ane[APPLE_CLPC_RAILS]; unsigned int ane_cluster; unsigned int ane_cluster_khz; + const char *ane_cluster_machine; }; struct apple_clpc_cluster { @@ -174,6 +176,8 @@ struct apple_clpc { struct freq_qos_request ane_qos; unsigned int ane_qos_khz; unsigned long ane_until; + struct notifier_block policy_nb; + bool policy_nb_added; u32 last_floor; u32 last_reason; u64 last_vote_ns; @@ -705,6 +709,8 @@ static void apple_clpc_ane_cluster(struct apple_clpc *clpc, bool active, clpc->ane_until = now + msecs_to_jiffies(APPLE_CLPC_HOLD_MS); if (time_before(now, clpc->ane_until)) khz = clpc->ane_cluster_khz; + else + clpc->ane_until = now; if (khz && !freq_qos_request_active(&clpc->ane_qos) && clpc->ane_cpu >= 0) { struct cpufreq_policy *policy = cpufreq_cpu_get(clpc->ane_cpu); @@ -991,11 +997,34 @@ static void apple_clpc_stop(void *data) apple_clpc_ane_detach(clpc->ane); debugfs_remove_recursive(clpc->debugfs); apple_clpc_halt(clpc); + if (clpc->policy_nb_added) + cpufreq_unregister_notifier(&clpc->policy_nb, CPUFREQ_POLICY_NOTIFIER); if (freq_qos_request_active(&clpc->ane_qos)) freq_qos_remove_request(&clpc->ane_qos); apple_clpc_free_clusters(clpc); } +/* + * The cluster floor is a request on a cpufreq policy, which goes away with + * the cpufreq driver (a module). Withdraw it then; it is added again on the + * next ANE work once a policy covers the CPU. + */ +static int apple_clpc_policy_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct apple_clpc *clpc = container_of(nb, struct apple_clpc, policy_nb); + struct cpufreq_policy *policy = data; + + if (event != CPUFREQ_REMOVE_POLICY || + !cpumask_test_cpu(clpc->ane_cpu, policy->related_cpus)) + return NOTIFY_DONE; + guard(mutex)(&clpc->sample_lock); + if (freq_qos_request_active(&clpc->ane_qos)) + freq_qos_remove_request(&clpc->ane_qos); + clpc->ane_qos_khz = 0; + return NOTIFY_OK; +} + /* The first CPU of /cpus/cpu-map/cluster@index, or -ENODEV. */ static int apple_clpc_cluster_cpu(unsigned int index) { @@ -1067,13 +1096,21 @@ static int apple_clpc_probe(struct platform_device *pdev) clpc->ane_states[rail] = clpc->hw->ane[rail]; } clpc->ane_cpu = -ENODEV; - if (clpc->ane && clpc->hw->ane_cluster_khz) { + clpc->ane_until = jiffies; + if (clpc->ane && clpc->hw->ane_cluster_khz && + of_machine_is_compatible(clpc->hw->ane_cluster_machine)) { clpc->ane_cpu = apple_clpc_cluster_cpu(clpc->hw->ane_cluster); - if (clpc->ane_cpu >= 0) - clpc->ane_cluster_khz = clpc->hw->ane_cluster_khz; - else - dev_warn(dev, "no CPU in cpu-map cluster%u: no ANE cluster floor\n", - clpc->hw->ane_cluster); + if (clpc->ane_cpu >= 0) { + clpc->policy_nb.notifier_call = apple_clpc_policy_notify; + if (!cpufreq_register_notifier(&clpc->policy_nb, + CPUFREQ_POLICY_NOTIFIER)) { + clpc->policy_nb_added = true; + clpc->ane_cluster_khz = clpc->hw->ane_cluster_khz; + } + } + if (!clpc->ane_cluster_khz) + dev_dbg(dev, "no ANE cluster floor (cpu-map cluster%u)\n", + clpc->hw->ane_cluster); } /* The property is optional: without it, CPU demand alone sets the floors. */ if (clpc->hw->gpu_demand) @@ -1295,6 +1332,7 @@ static const struct apple_clpc_hw apple_clpc_hw_t6040 = { .ane = { [APPLE_CLPC_DCS] = 5, [APPLE_CLPC_SOC] = 2 }, .ane_cluster = 2, .ane_cluster_khz = 3756000, + .ane_cluster_machine = "apple,t6040", }; /* From d3ab97e972b0a88c48e546104599f24a6a53f6d7 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sun, 8 Nov 2026 21:29:07 -0500 Subject: [PATCH 114/342] dt-bindings: mailbox: Add the physical T6050 GPU profile Describe the ASCWrap v6 compatible for the physical GPU aperture shared by J775D and J716c, distinct from the existing T6050 alias profiles. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/mailbox/apple,ascwrap-v6.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml b/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml index 289c29ba752fb..a08c3224e7b1e 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml @@ -14,7 +14,9 @@ description: wrapper resource contains the coprocessor control registers and mailbox FIFOs. A separate resource provides the coprocessor vector-base register. The firmware role identifies which GPU firmware instance uses the mailbox; - the T6040 runs a single one. + the T6040 runs a single one. The T6050 J775D profile describes the physical + GPU aperture shared by J775D and J716c; the other T6050 profiles describe + alias windows. properties: compatible: @@ -25,6 +27,7 @@ properties: - apple,t6050-apif-ascwrap-v6 - apple,t6050-ascwrap-v6 - apple,t6050-x1n1-ascwrap-v6 + - apple,t6050-j775d-ascwrap-v6 reg: items: From 174cd0f4c2fe90451130dd7155b7f1614df40267 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sun, 8 Nov 2026 21:29:07 -0500 Subject: [PATCH 115/342] soc: apple: mailbox: Add the physical T6050 GPU windows The existing T6050 profiles validate alias addresses and reject the physical GFX/GFX1 resources used on J716c. Add the shared J775D/J716c profile for 0x2302600000 and 0x2302e00000, including their vector-base registers. Reuse the ASCWrap v6 transport and retain all existing address profiles. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/soc/apple/mailbox.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index c13c03f9d92ab..999dec63b3b29 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -144,6 +144,11 @@ static bool ascwrap_v8_rx_irq; module_param(ascwrap_v8_rx_irq, bool, 0444); MODULE_PARM_DESC(ascwrap_v8_rx_irq, "Service T8152 GPU ASCWrap v8 receive with the recv-not-empty interrupt (default: poll, no GPU mailbox interrupt is enabled)"); +/* Physical T6050 GPU windows, shared by J775D and J716c. */ +#define APPLE_J775D_GFX_WRAPPER_BASE 0x2302600000ULL +#define APPLE_J775D_GFX_IOP_VBAR_BASE 0x2302050000ULL +#define APPLE_J775D_GFX1_WRAPPER_BASE 0x2302e00000ULL +#define APPLE_J775D_GFX1_IOP_VBAR_BASE 0x2302850000ULL static_assert(APPLE_ASCWRAP_V6_MBOX_OFFSET + APPLE_ASC_MBOX_A2I_CONTROL == 0x8110); @@ -1636,8 +1641,7 @@ static const struct apple_mbox_hw apple_mbox_t8152_gfx_ascwrap_v8_hw = { static_assert(0x20 + sizeof(u32) <= APPLE_ASCWRAP_V8_MBOX_SIZE); -/* T6050's native ASCWrap v6 uses the same RUN/stop sequence. Aura grants - * these complete wrapper/VBAR windows in the retained GPU aperture. */ +/* Retained T6050 wrapper/VBAR alias profile. */ static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_ascwrap_v6_roles[] = { { "GFX", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX, APPLE_T8140_GFX_WRAPPER_BASE + APPLE_T6050_ASCWRAP_BASE_DELTA, @@ -1647,6 +1651,17 @@ static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_ascwrap_v6_ APPLE_T8140_GFX1_IOP_VBAR_BASE + APPLE_T6050_ASCWRAP_BASE_DELTA }, }; +/* + * T6050 at its physical addresses, with both roles in the GPU aperture at + * 0x2300000000 on die 0. The other T6050 profiles retain their alias windows. + */ +static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_j775d_ascwrap_v6_roles[] = { + { "GFX", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX, + APPLE_J775D_GFX_WRAPPER_BASE, APPLE_J775D_GFX_IOP_VBAR_BASE }, + { "GFX1", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX1, + APPLE_J775D_GFX1_WRAPPER_BASE, APPLE_J775D_GFX1_IOP_VBAR_BASE }, +}; + static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_apif_ascwrap_v6_roles[] = { { "GFX", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX, APPLE_T8140_GFX_WRAPPER_BASE, @@ -1672,6 +1687,22 @@ static const struct apple_mbox_hw apple_mbox_t6050_ascwrap_v6_hw = { .has_irq_controls = false, }; +static const struct apple_mbox_hw apple_mbox_t6050_j775d_ascwrap_v6_hw = { + .reg_offset = APPLE_ASCWRAP_V6_MBOX_OFFSET, + .is_ascwrap_v6 = true, + .ascwrap_v6_roles = apple_mbox_t6050_j775d_ascwrap_v6_roles, + .num_ascwrap_v6_roles = ARRAY_SIZE(apple_mbox_t6050_j775d_ascwrap_v6_roles), + .control_full = APPLE_ASC_MBOX_CONTROL_FULL, + .control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY, + .a2i_control = APPLE_ASC_MBOX_A2I_CONTROL, + .a2i_send0 = APPLE_ASC_MBOX_A2I_SEND0, + .a2i_send1 = APPLE_ASC_MBOX_A2I_SEND1, + .i2a_control = APPLE_ASC_MBOX_I2A_CONTROL, + .i2a_recv0 = APPLE_ASC_MBOX_I2A_RECV0, + .i2a_recv1 = APPLE_ASC_MBOX_I2A_RECV1, + .has_irq_controls = false, +}; + /* Retained compatibility profile: unshifted wrapper aliases, native VBAR. */ static const struct apple_mbox_hw apple_mbox_t6050_apif_ascwrap_v6_hw = { .reg_offset = APPLE_ASCWRAP_V6_MBOX_OFFSET, @@ -1717,6 +1748,8 @@ static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t6050-apif-ascwrap-v6", .data = &apple_mbox_t6050_apif_ascwrap_v6_hw }, { .compatible = "apple,t6050-ascwrap-v6", .data = &apple_mbox_t6050_ascwrap_v6_hw }, { .compatible = "apple,t6050-x1n1-ascwrap-v6", .data = &apple_mbox_t6050_ascwrap_v6_hw }, + { .compatible = "apple,t6050-j775d-ascwrap-v6", + .data = &apple_mbox_t6050_j775d_ascwrap_v6_hw }, { .compatible = "apple,t8140-asc-mailbox", .data = &apple_mbox_t8140_asc_hw }, { .compatible = "apple,t8140-aop-setup-mailbox", .data = &apple_mbox_t8140_aop_setup_hw }, /* From 8f84cdd51be83496b61ff233c7713fb1cf94737c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:43:53 +1100 Subject: [PATCH 116/342] drm/apple: take a refused compact call's bare descriptor as its answer A desktop 26.x DCP refuses a service call by answering with the call's descriptor alone: the request's status, and an IOReturn where the length goes. The reply matcher wanted the call header back for every service call, so a refusal matched nothing: it logged "AFK[ep:2b]: unexpected compact reply c0" and the call waited out its full timeout. On the J616s this happens every time an external display powers on. The display audio sink is reported on the audio interface instance the DCP had, PipeWire opens it within some 25 ms, and that instance, which the firmware replaces about 160 ms later, refuses the Open with kIOReturnOffline (0xe00002d7). Captured on the J616s with the Acer QG270 S3 on a USB-C dock, three DPMS cycles: each Open (group 0, method 4, status tag 0xc00) was answered at once with the 8-byte descriptor 00 0c 00 00 d7 02 00 e0. Match a bare descriptor by its status alone and complete the call with the refusal: -ENODEV for an interface that is offline, not ready or not there, -EREMOTEIO for anything else, at debug level. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/afk.c | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 9ac50fb8b6576..302932f3b31a0 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -960,6 +960,27 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep, } } +/* IOReturn values of a refused call (IOKit's sys_iokit error space) */ +#define AFK_IORETURN_NO_DEVICE 0xe00002c0 +#define AFK_IORETURN_OFFLINE 0xe00002d7 +#define AFK_IORETURN_NOT_READY 0xe00002d8 + +/* + * An interface that is offline or not there (yet) is -ENODEV, as a call to + * an interface already gone is; anything else the firmware refused, -EREMOTEIO. + */ +static int afk_compact_refusal_errno(u32 ioreturn) +{ + switch (ioreturn) { + case AFK_IORETURN_NO_DEVICE: + case AFK_IORETURN_OFFLINE: + case AFK_IORETURN_NOT_READY: + return -ENODEV; + default: + return -EREMOTEIO; + } +} + static void afk_recv_handle_compact_reply(struct apple_dcp_afkep *ep, u16 channel, u8 type, const void *payload, @@ -970,6 +991,7 @@ static void afk_recv_handle_compact_reply(struct apple_dcp_afkep *ep, struct afk_compact_cmd *pending, *match = NULL; unsigned long flags; size_t copy_size; + bool refused; if (payload_size < sizeof(*desc)) { dev_err(ep->dcp->dev, @@ -984,13 +1006,22 @@ static void afk_recv_handle_compact_reply(struct apple_dcp_afkep *ep, call = NULL; } + /* + * A call the firmware refuses is answered with its descriptor alone: + * the request's status, and an IOReturn where the length goes (an + * audio interface the firmware is replacing answers an Open with + * kIOReturnOffline). It carries no call header, so it matches by its + * status only. + */ + refused = payload_size == sizeof(*desc); + spin_lock_irqsave(&ep->lock, flags); list_for_each_entry(pending, &ep->compact_cmds, node) { if (pending->channel != channel || pending->type != type) continue; if (pending->request_status != le32_to_cpu(desc->status)) continue; - if (pending->service_call && + if (pending->service_call && !refused && (!call || pending->group != le16_to_cpu(call->group) || pending->command != le32_to_cpu(call->command))) continue; @@ -1018,6 +1049,18 @@ static void afk_recv_handle_compact_reply(struct apple_dcp_afkep *ep, kfree(match); return; } + if (refused && match->service_call) { + u32 ioreturn = le32_to_cpu(desc->length); + + match->retcode = ioreturn; + match->status = afk_compact_refusal_errno(ioreturn); + complete(&match->done); + spin_unlock_irqrestore(&ep->lock, flags); + dev_dbg(ep->dcp->dev, + "AFK[ep:%02x]: call group %u cmd %u on interface %u refused: %#x\n", + ep->endpoint, match->group, match->command, channel, ioreturn); + return; + } match->retcode = le32_to_cpu(desc->status); match->status = 0; if (call && le32_to_cpu(call->data_len) > From be7df3364d7f7bc20a556855dc198740b5dae68a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:43:53 +1100 Subject: [PATCH 117/342] drm/apple: reopen display audio on the instance that replaces a refused one An Open that the dying audio interface refuses (kIOReturnOffline) now fails at once instead of after its 1 s timeout. The retry looked for the replacement instance right away, but the firmware publishes it some 160 ms later, so the Open would have failed and PipeWire would have dropped the output. On -ENODEV, wait up to 1 s for the next instance to be published, then open that one. After a display wakes up, its audio output is back about 200 ms after the jack turns on instead of a second later. KUnit: apple-av-native-audio gains a refused Open with a successor (reopened on the successor) and without one (fails after the wait). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/av-lifetime-test.c | 3 ++ drivers/gpu/drm/apple/av-v14-test.c | 42 ++++++++++++++++++++++++ drivers/gpu/drm/apple/av.c | 27 ++++++++++++--- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/av-lifetime-test.c b/drivers/gpu/drm/apple/av-lifetime-test.c index 193358ce2bfba..f75be1a5bb3a8 100644 --- a/drivers/gpu/drm/apple/av-lifetime-test.c +++ b/drivers/gpu/drm/apple/av-lifetime-test.c @@ -157,6 +157,9 @@ static struct av_life_test *av_life_setup(struct kunit *test, work_func_t owner_ spin_lock_init(&t->ep->lock); INIT_LIST_HEAD(&t->ep->compact_cmds); init_rwsem(&t->asrv->srv_rwsem); +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) + init_waitqueue_head(&t->asrv->gen_wq); +#endif INIT_WORK(&t->asrv->start_av_service_wq, owner_fn); INIT_WORK(&t->asrv->terminate_wq, owner_fn); INIT_WORK(&t->dcp->external_audio_work, av_life_owner_fn); diff --git a/drivers/gpu/drm/apple/av-v14-test.c b/drivers/gpu/drm/apple/av-v14-test.c index f0dbe8f079dd0..f0e5ee63d9d0a 100644 --- a/drivers/gpu/drm/apple/av-v14-test.c +++ b/drivers/gpu/drm/apple/av-v14-test.c @@ -30,6 +30,9 @@ struct av_v14_test { u32 link_status; u8 link_body[64]; bool replace_during_prepare; + /* The next Open is refused as offline; with a successor published first */ + bool refuse_open; + bool successor_with_refusal; }; static struct av_v14_test *av_v14_current; @@ -46,6 +49,12 @@ static int av_v14_call(struct apple_epic_service *srv, u32 command, const void * } t->ncalls++; memset(reply, 0, reply_len); + if (command == t->asrv->cmds.open && t->refuse_open) { + t->refuse_open = false; + if (t->successor_with_refusal) + av_v14_replace(t); + return -ENODEV; /* afk: the instance answered kIOReturnOffline */ + } /* Open: status 0 at +0, opened at +16 */ if (command == t->asrv->cmds.open && reply_len >= 24) put_unaligned_le64(1, reply + 16); @@ -133,6 +142,7 @@ static struct av_v14_test *av_v14_setup(struct kunit *test) init_rwsem(&asrv->srv_rwsem); mutex_init(&asrv->plug_lock); mutex_init(&asrv->open_lock); + init_waitqueue_head(&asrv->gen_wq); asrv->cmds = dcp_av_audio_cmds_v13_5; INIT_WORK(&asrv->start_av_service_wq, av_work_service_start); disable_work(&asrv->start_av_service_wq); @@ -234,6 +244,36 @@ static void av_v14_old_terminate_vs_successor(struct kunit *test) KUNIT_EXPECT_EQ(test, t->svc.users, 1U); } +/* + * A display waking up: the Open goes to the instance the firmware is + * replacing, which refuses it as offline; the Open waits for the successor + * and goes to it. + */ +static void av_v14_refused_open_reopens_successor(struct kunit *test) +{ + struct av_v14_test *t = av_v14_setup(test); + + t->refuse_open = true; + t->successor_with_refusal = true; + KUNIT_EXPECT_EQ(test, dcp_audiosrv_open(t->dcp->dev), 0); + KUNIT_ASSERT_EQ(test, t->ncalls, 2U); + KUNIT_EXPECT_EQ(test, t->calls[1], t->asrv->cmds.open); + KUNIT_EXPECT_NE(test, t->call_gens[1], t->call_gens[0]); + KUNIT_EXPECT_EQ(test, t->asrv->open_gen, t->asrv->gen); + KUNIT_EXPECT_PTR_EQ(test, t->asrv->open_srv, &t->svc); +} + +/* Refused, and no successor comes: the Open fails once its wait is over. */ +static void av_v14_refused_open_without_successor(struct kunit *test) +{ + struct av_v14_test *t = av_v14_setup(test); + + t->refuse_open = true; + KUNIT_EXPECT_EQ(test, dcp_audiosrv_open(t->dcp->dev), -ENODEV); + KUNIT_EXPECT_EQ(test, t->ncalls, 1U); + KUNIT_EXPECT_NULL(test, t->asrv->open_srv); +} + /* An instance published over the open one, without a teardown, is opened too. */ static void av_v14_republished(struct kunit *test) { @@ -490,6 +530,8 @@ static struct kunit_case av_v14_cases[] = { KUNIT_CASE_PARAM(av_v14_old_close_not_to_successor, av_native_gen_params), KUNIT_CASE_PARAM(av_v14_old_terminate_vs_successor, av_native_gen_params), KUNIT_CASE_PARAM(av_v14_republished, av_native_gen_params), + KUNIT_CASE_PARAM(av_v14_refused_open_reopens_successor, av_native_gen_params), + KUNIT_CASE_PARAM(av_v14_refused_open_without_successor, av_native_gen_params), KUNIT_CASE_PARAM(av_v14_successor_during_release, av_native_gen_params), KUNIT_CASE_PARAM(av_v14_terminate_after_successor, av_native_gen_params), KUNIT_CASE_PARAM(av_v14_link_instance, av_native_gen_params), diff --git a/drivers/gpu/drm/apple/av.c b/drivers/gpu/drm/apple/av.c index 550e695e2485c..f32d9343439c5 100644 --- a/drivers/gpu/drm/apple/av.c +++ b/drivers/gpu/drm/apple/av.c @@ -92,6 +92,8 @@ struct audiosrv_data { struct mutex open_lock; struct apple_epic_service *open_srv; u64 open_gen; + /* Woken when gen changes: an Open waits there for a replacement. */ + wait_queue_head_t gen_wq; /* The instance the link was last prepared on (open_lock) */ u64 link_gen; #endif @@ -155,6 +157,9 @@ static void av_audiosrv_init(struct apple_epic_service *service, const char *nam #endif queue_start = !asrv->reports_stopped; up_write(&asrv->srv_rwsem); +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) + wake_up_all(&asrv->gen_wq); +#endif if (old) afk_service_put(old); @@ -280,6 +285,9 @@ static int av_audiosrv_call(struct apple_epic_service *srv, u32 command, const v return afk_service_call(srv, 0, command, body, body_len, body_pad, reply, reply_len, 0); } +/* How long an Open refused by an instance being replaced waits for the next one */ +#define AV_AUDIOSRV_REPLACE_MS 1000 + /* * The 14.7 external role: the service is open while a PCM is (see * av_service_connect()). The instance the PCM opened is kept under open_lock, @@ -308,11 +316,11 @@ int dcp_audiosrv_open(struct device *dev) * A display that wakes up (DPMS on) reports its sink on the audio * interface it had, and the firmware replaces that instance a few * hundred milliseconds later: an Open sent in between is refused - * with a reply that matches no call, and times out. The Open that - * follows the replacement is answered, so try the instance published - * by then once more. Userspace drops an output whose first open - * fails, so this is the difference between a display with and - * without audio after it wakes up. + * (kIOReturnOffline). The Open that follows the replacement is + * answered, so wait for that instance and try it once more. + * Userspace drops an output whose first open fails, so this is the + * difference between a display with and without audio after it + * wakes up. */ for (int attempt = 0; ; attempt++) { scoped_guard(rwsem_read, &asrv->srv_rwsem) { @@ -344,6 +352,14 @@ int dcp_audiosrv_open(struct device *dev) afk_service_put(srv); if (attempt) return ret; + /* + * The instance refused it as offline: its successor is on the + * way (published within some 200 ms on the J616s), wait for it. + */ + if (ret == -ENODEV) + wait_event_timeout(asrv->gen_wq, + READ_ONCE(asrv->srv) && READ_ONCE(asrv->gen) != gen, + msecs_to_jiffies(AV_AUDIOSRV_REPLACE_MS)); scoped_guard(rwsem_read, &asrv->srv_rwsem) replaced = asrv->srv && asrv->gen != gen; if (!replaced) @@ -1176,6 +1192,7 @@ int avep_init(struct apple_dcp *dcp) #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T6030_AUDIO) INIT_WORK(&audiosrv_data->terminate_wq, av_work_service_terminate); mutex_init(&audiosrv_data->open_lock); + init_waitqueue_head(&audiosrv_data->gen_wq); #endif audiosrv_data->works_live = true; dcp->audiosrv = audiosrv_data; From 11319ea8e3740fc4dab909b9b1e9437807277aa4 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:43:53 +1100 Subject: [PATCH 118/342] drm/apple: update the display audio ELD when the sink's EDID arrives The firmware reports a newly attached sink before the DCP has read its EDID, and reports it again once the mode is set. The card took the ELD only from the first report, so a display plugged in after boot, or one moved to another display processor, kept an ELD with no monitor name and the basic-audio fallback: on the J616s, the Acer QG270 S3 moved to DCPEXT1 showed up as an unnamed HDMI sink while the same display on DCPEXT0 had its name. When a connected sink is reported again with a different ELD, store it and notify the ELD control, as HDMI codecs do when the ELD changes. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/apple/audio.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/audio.c b/drivers/gpu/drm/apple/audio.c index 64496a827c776..de8fc565a11dd 100644 --- a/drivers/gpu/drm/apple/audio.c +++ b/drivers/gpu/drm/apple/audio.c @@ -1305,10 +1305,26 @@ static void dcpaud_report_hotplug(struct dcp_audio *dcpaud, bool connected, { struct snd_pcm_substream *substream = dcpaud->substream; - if (!dcpaud->card || dcpaud->connected == connected) { + if (!dcpaud->card) { mutex_unlock(&dcpaud->data_lock); return; } + /* + * A sink the firmware reports before its EDID is read (a display + * plugged in, or brought up on another processor) is connected again + * once the mode is set: its ELD then has the monitor name. + */ + if (dcpaud->connected == connected) { + bool changed = connected && eld && memcmp(dcpaud->eld, eld, DCPAUD_ELD_SIZE); + + if (changed) + memcpy(dcpaud->eld, eld, DCPAUD_ELD_SIZE); + mutex_unlock(&dcpaud->data_lock); + if (changed) + snd_ctl_notify(dcpaud->card, SNDRV_CTL_EVENT_MASK_VALUE, + &dcpaud->eld_ctl->id); + return; + } dcpaud->connected = connected; if (connected) { From d95db69304a5d405989721972191e8fb8208d41c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Fri, 6 Nov 2026 23:38:36 +1100 Subject: [PATCH 119/342] accel/ane: wake H16 firmware waits on the channel IRQ Every H16 wait polls the rings: 2 us busy steps for the first 30 us, then 20-50 us sleeps. On the M4 Pro an EXECUTE transport reply arrives about 90 us after the doorbell, so it lands inside a sleep and is seen up to 50 us late; the completion report of a MobileNet request is quantised the same way. Busy-polling instead does not help: polling the engine's mailbox and fault registers every 2 us while the request runs slows the engine itself (MobileNet report->done 88 -> 158 us). macOS takes the same replies from the channel interrupt. Do the same once the firmware is up: before sleeping, the wait enables the channel IRQ, and the handler disables it again and wakes the wait. The transport still reads, acknowledges and drains every ring from the waiting thread, exactly as before; the IRQ only ends the sleep early, and the old sleep length stays as the timeout. The report wait drops the session lock around its pause, so the waiting half of relax() becomes its own transport op, pause(), which needs no lock; waits without it keep ane_fw_poll_pause(). The IRQ stays off during the firmware startup handshake (at boot and on the cold restart after system sleep), so that sequence keeps its polled timing, and only platforms whose IRQ drains the channels (ANE_FW_IRQ_CHANNELS, H16) use it. debugfs ane-h16//irq_wakeups and irq_timeouts count how each sleep ended. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_fw_transport.h | 6 ++ drivers/accel/ane/ane_h16_backend.c | 112 ++++++++++++++++++++++++--- drivers/accel/ane/ane_h16_program.c | 5 +- 3 files changed, 113 insertions(+), 10 deletions(-) diff --git a/drivers/accel/ane/ane_fw_transport.h b/drivers/accel/ane/ane_fw_transport.h index d327118204120..527dff351aabf 100644 --- a/drivers/accel/ane/ane_fw_transport.h +++ b/drivers/accel/ane/ane_fw_transport.h @@ -92,6 +92,12 @@ struct ane_fw_transport_ops { * their lock around the pause call it first, with the lock held. */ void (*service)(void *ctx); + /* + * Optional: the waiting half of relax(), safe without the caller's + * lock (it may end early on the channel IRQ). Default + * ane_fw_poll_pause(). + */ + void (*pause)(void *ctx, u64 waited_ns); int (*alloc)(void *ctx, size_t size, u32 tag, struct ane_fw_surface *surface); void (*refused)(void *ctx, u64 word0, u64 word1, u64 word2, int error); /* Optional: a shared allocation was freed ("FREE") or served again ("reuse"). */ diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index eb1de39a24f09..010dca71d8c07 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include "ane_fw_sleep.h" @@ -66,6 +68,19 @@ struct ane_h16_device { /* While pinned: refuse system sleep (ane_fw_sleep.h). */ struct notifier_block pm_notifier; int irq; + /* + * The channel IRQ (ANE_FW_IRQ_CHANNELS) as a wakeup for the polled + * waits once the firmware is up: relax() arms it before sleeping and + * the handler disables it again. The transport still reads, + * acknowledges and drains every ring itself, as before. + */ + spinlock_t irq_lock; + wait_queue_head_t irq_wq; + bool irq_wait; + bool irq_armed; + bool irq_fired; + u64 irq_wakeups; + u64 irq_timeouts; struct ane_fw_rtk rtk; struct { u64 word0; @@ -188,6 +203,28 @@ static void ane_h16_quarantine(void *ctx, int error) static void ane_h16_busy(void *ctx, bool busy); static void ane_h16_sleep_trace(struct ane_h16_device *h, const char *when); +/* + * Let the channel IRQ wake the waits, or go back to pure polling. Off + * across power down and the firmware startup that follows it, so the + * startup handshake keeps its proven polled timing. + */ +static void ane_h16_irq_wait_set(struct ane_h16_device *h, bool on) +{ + bool disarm = false; + + if (h->irq < 0 || h->boot.soc->irq_role != ANE_FW_IRQ_CHANNELS) + return; + scoped_guard(spinlock_irqsave, &h->irq_lock) { + WRITE_ONCE(h->irq_wait, on); + if (!on && h->irq_armed) { + h->irq_armed = false; + disarm = true; + } + } + if (disarm) + disable_irq(h->irq); +} + static int ane_h16_suspend_firmware(struct ane_h16_device *h) { struct ane_fw_transport *t = &h->boot.transport; @@ -263,6 +300,7 @@ static void ane_h16_power_down(struct ane_h16_device *h) unsigned int i; ane_h16_busy(h, false); + ane_h16_irq_wait_set(h, false); for (i = ARRAY_SIZE(h->dart); i-- > 0; ) pm_runtime_put_sync(h->dart[i]); for (i = h->powered; i-- > 0; ) @@ -503,6 +541,7 @@ static int ane_h16_cold_boot(struct ane_h16_device *h) if (ret) return ret; h->resume_ready_ns = ktime_get_ns(); + ane_h16_irq_wait_set(h, true); dev_info(h->dev, "H16 ANE: booted again from the preload after system sleep\n"); ane_h16_session_restart(&h->session); ret = ane_h16_session_replay(&h->session, &h->resume_replayed, &h->resume_first_ns); @@ -975,11 +1014,50 @@ static u64 ane_h16_now(void *ctx) } /* - * The channel IRQ stays masked, so every wait polls, with the shared pacing - * (see ane_fw_poll_sleep_us()): busy steps for the first 30 us, then short - * sleeps. A fixed 1 ms sleep made each of the four waits of an EXECUTE cost - * at least a millisecond. + * Every wait polls, with the shared pacing (see ane_fw_poll_sleep_us()): + * busy steps for the first 30 us, then short sleeps. A fixed 1 ms sleep + * made each of the four waits of an EXECUTE cost at least a millisecond. + * + * After the busy window an EXECUTE reply (typically 40-50 us) landed in a + * 20-50 us sleep and was seen 40-50 us late. Once the firmware is up, the + * sleep therefore also ends on the channel IRQ, the way macOS drains the + * rings from IRQ 1054; the timeout keeps the polled cadence as a bound. */ +static void ane_h16_irq_pause(struct ane_h16_device *h, u64 waited_ns) +{ + unsigned int min_us, max_us; + long ret; + + min_us = ane_fw_poll_sleep_us(waited_ns, &max_us); + scoped_guard(spinlock_irqsave, &h->irq_lock) { + h->irq_fired = false; + if (!h->irq_armed) { + h->irq_armed = true; + enable_irq(h->irq); + } + } + ret = wait_event_hrtimeout(h->irq_wq, READ_ONCE(h->irq_fired), + us_to_ktime(min_us)); + scoped_guard(spinlock_irqsave, &h->irq_lock) { + if (ret) + h->irq_timeouts++; + else + h->irq_wakeups++; + } +} + +/* The waiting half of relax(); callers may hold no lock. */ +static void ane_h16_pause(void *ctx, u64 waited_ns) +{ + struct ane_h16_device *h = ctx; + + if (READ_ONCE(h->irq_wait) && waited_ns >= ANE_FW_POLL_SPIN_NS && + !READ_ONCE(h->boot.transport.error)) + ane_h16_irq_pause(h, waited_ns); + else + ane_fw_poll_pause(waited_ns); +} + static void ane_h16_service(void *ctx) { struct ane_h16_device *h = ctx; @@ -994,7 +1072,7 @@ static void ane_h16_service(void *ctx) static void ane_h16_relax(void *ctx, u64 waited_ns) { ane_h16_service(ctx); - ane_fw_poll_pause(waited_ns); + ane_h16_pause(ctx, waited_ns); } static int ane_h16_alloc_shared(void *ctx, size_t size, u32 tag, struct ane_fw_surface *out) @@ -1114,6 +1192,7 @@ static const struct ane_fw_transport_ops ane_h16_transport_ops = { .write32 = ane_h16_engine_write, .now_ns = ane_h16_now, .relax = ane_h16_relax, + .pause = ane_h16_pause, .service = ane_h16_service, .alloc = ane_h16_alloc_shared, .refused = ane_h16_refused, @@ -1189,9 +1268,20 @@ static void ane_h16_release(struct ane_h16_device *h) dev_info(h->dev, "H16 pre-RUN rollback complete; no CPU release\n"); } -static irqreturn_t ane_h16_masked_irq(int irq, void *data) +/* Wake the sleeping wait and stay disabled until relax() arms it again. */ +static irqreturn_t ane_h16_irq(int irq, void *data) { - return IRQ_NONE; + struct ane_h16_device *h = data; + + scoped_guard(spinlock_irqsave, &h->irq_lock) { + if (h->irq_armed) { + disable_irq_nosync(irq); + h->irq_armed = false; + } + WRITE_ONCE(h->irq_fired, true); + } + wake_up(&h->irq_wq); + return IRQ_HANDLED; } /* @@ -1357,11 +1447,10 @@ static int ane_h16_acquire(struct platform_device *pdev, struct ane_h16_device * irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; - ret = request_irq(irq, ane_h16_masked_irq, IRQF_NO_AUTOEN, "ane-h16-polled", h); + ret = request_irq(irq, ane_h16_irq, IRQF_NO_AUTOEN, "ane-h16", h); if (ret) return ret; h->irq = irq; - dev_info(h->dev, "H16 polled mode; channel IRQ remains masked\n"); return 0; } @@ -1473,6 +1562,7 @@ static int ane_h16_program_stage(struct ane_h16_device *h) return ret; } h->program_ready = true; + ane_h16_irq_wait_set(h, true); dev_info(h->dev, "H16 stage 5 program window %llx..%llx%s\n", h->program_next, h->program_end - 1, h->clpc ? ", CLPC input attached" : ""); return 0; @@ -1669,6 +1759,8 @@ int ane_h16_backend_probe(struct platform_device *pdev, const struct ane_fw_plat } h->dev = &pdev->dev; h->irq = -1; + spin_lock_init(&h->irq_lock); + init_waitqueue_head(&h->irq_wq); INIT_LIST_HEAD(&h->mappings); h->boot.soc = soc; /* The build, and with it the DVA layout, is chosen from the preload. */ @@ -1695,6 +1787,8 @@ int ane_h16_backend_probe(struct platform_device *pdev, const struct ane_fw_plat h->debugfs = debugfs_create_dir(dev_name(h->dev), ane_h16_debugfs); debugfs_create_file("stage", 0600, h->debugfs, h, &ane_h16_stage_fops); debugfs_create_file("execute", 0600, h->debugfs, h, &ane_h16_execute_fops); + debugfs_create_u64("irq_wakeups", 0400, h->debugfs, &h->irq_wakeups); + debugfs_create_u64("irq_timeouts", 0400, h->debugfs, &h->irq_timeouts); platform_set_drvdata(pdev, h); INIT_WORK(&h->start, ane_h16_start_work); schedule_work(&h->start); diff --git a/drivers/accel/ane/ane_h16_program.c b/drivers/accel/ane/ane_h16_program.c index eb860a3d4799d..7a47f842e7b7d 100644 --- a/drivers/accel/ane/ane_h16_program.c +++ b/drivers/accel/ane/ane_h16_program.c @@ -1160,7 +1160,10 @@ static int h16_wait_report(struct ane_h16_session *s, struct ane_h16_pending *re if (s->lock && t->ops->service) { t->ops->service(t->ctx); mutex_unlock(s->lock); - ane_fw_poll_pause(now - start); + if (t->ops->pause) + t->ops->pause(t->ctx, now - start); + else + ane_fw_poll_pause(now - start); mutex_lock(s->lock); } else if (s->lock) { mutex_unlock(s->lock); From aad9099efc7486e10e2633d43d12111142870e1c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 13:57:12 +1100 Subject: [PATCH 120/342] ASoC: apple: macaudio: Serve both speaker protection interfaces The tree carries only the "Speaker Protection" lease, which a protection engine in the signal path (speakerguardd v2) owns. The distribution kernels revert it to get "Speaker Volume Unlock" back, the volume lock that speakersafetyd and speakerguardd 0.1 use, so the fleet and distribution kernels differ, and the lease cannot return on the boards it is qualified for without locking every other Mac out. Carry both. "Speaker Protection Interface" says which one owns the speakers: - "Speaker Volume Unlock", at every card bind: the volume lock exactly as on a lock-only kernel ("Speaker Sample Rate", the ELEM_LOCK and ping lease, its ceiling, the system-sleep handling, the J700 software-gain epoch, "Amp Gain Volume" limited but the amp's to set). An owner may hold "Speaker Protection", but nothing is granted, and its locks and releases touch no amp. - "Speaker Protection", after a CAP_SYS_ADMIN write only. The handover passes through both floors: the lock's ceiling first, then no speaker start and the running streams stopped, the lease's safe level, every amp gain fixed at its limit, and only then the ceiling lifted with every volume still at the safe level. While leased the lock's ping fails with -EBUSY and userspace writes to the speaker volumes and amp gains with -EPERM. Back to "Speaker Volume Unlock" by a write, or after 30 s without an owner of "Speaker Protection" (the engine died, or never came): the lease's floor, then the lock's ceiling over the safe level. The speakers go up only once a daemon holds the lock and pings it, as after a cold bind, and a daemon still holding it learns once, with -ETIMEDOUT, that it lost it. An engine that restarts within the grace keeps the lease. The switch is state for the boot: INACTIVE keeps alsactl off it, and whatever makes it persist writes it again at every boot. On the J700 the software gain's table top follows the interface through a new register of the AOP component, which no control exposes: half the amplifier's full scale under the lock, the scale its daemon was calibrated against, and the full scale only while leased. Assisted-by: LLM Signed-off-by: Ryan Murray --- sound/soc/apple/aop_t8140.rs | 91 +- sound/soc/apple/macaudio-iface-test.h | 264 +++ sound/soc/apple/macaudio-pm-volumes-test.h | 268 ++++ sound/soc/apple/macaudio-protection-test.h | 67 +- sound/soc/apple/macaudio.c | 1428 +++++++++++++++-- .../selftests/alsa/macaudio-fixed-controls.py | 15 +- 6 files changed, 1993 insertions(+), 140 deletions(-) create mode 100644 sound/soc/apple/macaudio-iface-test.h create mode 100644 sound/soc/apple/macaudio-pm-volumes-test.h diff --git a/sound/soc/apple/aop_t8140.rs b/sound/soc/apple/aop_t8140.rs index ff3bd53591276..aa97deda3b5c3 100644 --- a/sound/soc/apple/aop_t8140.rs +++ b/sound/soc/apple/aop_t8140.rs @@ -27,8 +27,10 @@ //! //! The speaker front-end is copy-only: the LEAP consumes float32 and the //! driver converts each S32 sample through the amplifier's full scale and -//! the "Speaker Playback Volume" control, which macaudio holds at full scale -//! while a protection engine owns the speakers and 20 dB down otherwise. +//! the "Speaker Playback Volume" control, below one of two ceilings that +//! macaudio selects with the protection interface: half the amplifier's full +//! scale under the volume lock of a protection daemon, the full scale under +//! the lease of a protection engine in the signal path. //! //! Closing the lid disconnects both internal microphones in hardware. The //! array then reads back as digital silence, but the low-power microphone's @@ -492,6 +494,9 @@ struct SndSocT8140AopData { hpai_want_run: AtomicFlag, /// "Speaker Playback Volume" (REG_SPKR_VOLUME), 0..=SPKR_VOLUME_MAX. spkr_volume: Atomic, + /// REG_SPKR_FULL_SCALE: the volume is below SPKR_CEILING_Q31, not the + /// legacy ceiling. + spkr_full_scale: AtomicFlag, /// The sleeping firmware starts queued from the atomic triggers. #[pin] spkr_start_work: Work, @@ -1614,9 +1619,10 @@ const FE_DMA_NAMES: [[Option<&core::ffi::CStr>; 2]; FE_COUNT] = [ /// "Secondary" PCM): its data goes through `spkr_copy` below. const FE_SPKR: usize = 1; -/// Digital ceiling of the speaker path, as a Q31 gain applied to every -/// sample userspace writes: unity, so a full-scale S32 sample is a float of -/// 1.0, the amplifier's full scale. +/// Digital ceiling of the speaker path under the lease of a protection engine +/// ("Speaker Protection"), as a Q31 gain applied to every sample userspace +/// writes: unity, so a full-scale S32 sample is a float of 1.0, the +/// amplifier's full scale. /// /// The LEAP consumes float32 with 1.0 as the I2S full scale. Measured /// from outside the machine, the same program through the same speaker @@ -1636,6 +1642,13 @@ const FE_SPKR: usize = 1; /// down with speaker playback refused. const SPKR_CEILING_Q31: i64 = 1 << 31; +/// Digital ceiling under the volume lock of a protection daemon ("Speaker +/// Volume Unlock", speakerguardd 0.1): 0.5, the scale that daemon was +/// calibrated against, unchanged from the kernels that had only that +/// interface. It is the default: macaudio selects the full scale only +/// while the lease is the interface (REG_SPKR_FULL_SCALE). +const SPKR_LEGACY_CEILING_Q31: i64 = 1 << 30; + /// "Speaker Playback Volume": the software gain below the ceiling that /// macaudio sets (full scale or its safe level), 0.5 dB per /// step from -63.0 dB (1) to 0 dB (127) relative to SPKR_CEILING_Q31, 0 = @@ -1659,8 +1672,33 @@ const SPKR_VOLUME_Q31: [u32; 128] = [ 1140065663, 1207618800, 1279174713, 1354970580, 1435257634, 1520301996, 1610385552, 1705806895, 1806882308, 1913946816, 2027355295, 2147483648, ]; -/// The component's only "register": the speaker volume. +/// The volume table under the volume lock: entry i = +/// round(SPKR_LEGACY_CEILING_Q31 * 10^(-(127 - i) / 40)). +const _: () = assert!( + SPKR_LEGACY_VOLUME_Q31[SPKR_VOLUME_MAX as usize] as i64 == SPKR_LEGACY_CEILING_Q31 +); +const SPKR_LEGACY_VOLUME_Q31: [u32; 128] = [ + 0, 760151, 805193, 852903, 903441, 956973, 1013678, 1073742, 1137365, 1204758, 1276145, + 1351761, 1431858, 1516701, 1606571, 1701766, 1802602, 1909413, 2022553, 2142397, 2269342, + 2403809, 2546243, 2697118, 2856932, 3026216, 3205530, 3395470, 3596664, 3809780, 4035523, + 4274643, 4527932, 4796229, 5080423, 5381457, 5700328, 6038094, 6395874, 6774853, 7176288, + 7601510, 8051928, 8529034, 9034412, 9569734, 10136776, 10737418, 11373650, 12047581, 12761445, + 13517609, 14318577, 15167006, 16065708, 17017661, 18026021, 19094130, 20225528, 21423966, + 22693416, 24038085, 25462431, 26971175, 28569318, 30262156, 32055302, 33954698, 35966640, + 38097798, 40355234, 42746432, 45279317, 47962285, 50804230, 53814569, 57003283, 60380940, + 63958736, 67748529, 71762882, 76015100, 80519278, 85290345, 90344115, 95697341, 101367765, + 107374182, 113736503, 120475814, 127614455, 135176087, 143185773, 151670064, 160657080, + 170176611, 180260209, 190941298, 202255281, 214239660, 226934158, 240380852, 254624313, + 269711752, 285693178, 302621563, 320553018, 339546978, 359666402, 380977976, 403552340, + 427464319, 452793173, 479622855, 508042296, 538145694, 570032831, 603809400, 639587356, + 677485290, 717628817, 760150998, 805192776, 852903448, 903441154, 956973408, 1013677647, + 1073741824, +]; +/// The component's "registers": the speaker volume, and which ceiling it +/// is below (0: SPKR_LEGACY_CEILING_Q31, 1: SPKR_CEILING_Q31), which +/// macaudio writes (MACAUDIO_SW_GAIN_REG_FULL_SCALE) and no control exposes. const REG_SPKR_VOLUME: u32 = 0; +const REG_SPKR_FULL_SCALE: u32 = 1; /// DECLARE_TLV_DB_SCALE(-6350, 50, 1): a dB scale from -63.50 dB in 0.50 dB /// steps whose lowest value mutes. static SPKR_VOLUME_TLV: [u32; 4] = [ @@ -1972,6 +2010,15 @@ fn f32_bits_of_q31(v: i32) -> u32 { /// One S32 sample -> the float32 word the LEAP consumes, through the volume /// table (whose top entry is the ceiling). +/// The Q31 gain of @volume below the selected ceiling. +fn spkr_gain_q31(full_scale: bool, volume: usize) -> u32 { + if full_scale { + SPKR_VOLUME_Q31[volume] + } else { + SPKR_LEGACY_VOLUME_Q31[volume] + } +} + fn spkr_f32_bits(sample: i32, gain_q31: u32) -> u32 { let scaled = (i64::from(sample) * i64::from(gain_q31)) >> 31; // |scaled| <= SPKR_CEILING_Q31 f32_bits_of_q31(scaled as i32) @@ -2038,7 +2085,7 @@ unsafe extern "C" fn asoc_pcm_copy( // throughout registration, use and unregister. let data = unsafe { component_data(component) }; let volume = core::cmp::min(data.spkr_volume.load(Relaxed), SPKR_VOLUME_MAX) as usize; - let gain = SPKR_VOLUME_Q31[volume]; + let gain = spkr_gain_q31(data.spkr_full_scale.load(Relaxed), volume); let mut chunk = [0u8; 512]; let mut off = 0; while off < bytes { @@ -2135,6 +2182,7 @@ unsafe extern "C" fn asoc_component_read( let data = unsafe { component_data(component) }; match reg { REG_SPKR_VOLUME => data.spkr_volume.load(Relaxed), + REG_SPKR_FULL_SCALE => u32::from(data.spkr_full_scale.load(Relaxed)), _ => 0, } } @@ -2157,6 +2205,10 @@ unsafe extern "C" fn asoc_component_write( .store(core::cmp::min(val, SPKR_VOLUME_MAX), Relaxed); 0 } + REG_SPKR_FULL_SCALE => { + data.spkr_full_scale.store(val != 0, Relaxed); + 0 + } _ => EINVAL.to_errno(), } } @@ -2889,6 +2941,7 @@ impl SndSocT8140AopDriver { spkr_want_run: AtomicFlag::new(false), hpai_want_run: AtomicFlag::new(false), spkr_volume: Atomic::new(SPKR_VOLUME_MAX), + spkr_full_scale: AtomicFlag::new(false), spkr_start_work <- new_work!("SndSocT8140AopData::spkr_start_work"), hpai_start_work <- new_work!("SndSocT8140AopData::hpai_start_work"), mic, @@ -2929,6 +2982,30 @@ mod tests { /// 1.0 as a float32: the amplifier's full scale on the wire. const F32_ONE: u32 = 0x3f80_0000; + /// Under the volume lock the table is the one the lock-only kernels had: + /// half the full scale at the top, every entry within one LSB of half + /// the lease's, and 20 dB below it at the locked level. + #[test] + fn the_volume_lock_keeps_the_legacy_ceiling() { + assert_eq!(SPKR_LEGACY_CEILING_Q31, 1 << 30); + assert_eq!( + spkr_gain_q31(false, SPKR_VOLUME_MAX as usize) as i64, + SPKR_LEGACY_CEILING_Q31 + ); + assert_eq!( + spkr_gain_q31(true, SPKR_VOLUME_MAX as usize) as i64, + SPKR_CEILING_Q31 + ); + assert_eq!(f32_bits_of_q31(SPKR_LEGACY_CEILING_Q31 as i32), 0x3f00_0000); + for i in 0..=SPKR_VOLUME_MAX as usize { + let half = i64::from(SPKR_VOLUME_Q31[i]) / 2; + assert!((i64::from(SPKR_LEGACY_VOLUME_Q31[i]) - half).abs() <= 1); + } + // 0.05 as a float32 is 0x3d4c_cccd; the conversion truncates + let locked = spkr_f32_bits(i32::MIN, spkr_gain_q31(false, LOCKED_VOLUME)); + assert!(locked & 0x7fff_ffff <= 0x3d4c_cccd && locked & 0x7fff_ffff > 0x3d4c_cccd - 64); + } + #[test] fn the_top_of_the_volume_range_is_the_amplifier_full_scale() { assert_eq!( diff --git a/sound/soc/apple/macaudio-iface-test.h b/sound/soc/apple/macaudio-iface-test.h new file mode 100644 index 0000000000000..83155d80b04d9 --- /dev/null +++ b/sound/soc/apple/macaudio-iface-test.h @@ -0,0 +1,264 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * "Speaker Protection Interface": the volume lock in charge from the bind, + * the switch to the lease and back through the floor of both, and the way + * back when the lease has no owner. On the card of fake controls that + * macaudio-protection-test.h builds, with the volume lock's controls added. + */ +#include + +struct macaudio_test_iface { + struct macaudio_test_spk t; + struct snd_kcontrol *slk; + struct snd_kcontrol *iface; + /* The legacy daemon's control file */ + struct snd_ctl_file *daemon; +}; + +/* A bound card with both interfaces: the volume lock in charge, at its ceiling */ +static void macaudio_test_iface_card(struct kunit *test, struct macaudio_test_iface *f) +{ + struct snd_kcontrol_new slk = macaudio_test_control("Speaker Volume Unlock"); + struct snd_kcontrol_new iface = macaudio_test_control("Speaker Protection Interface"); + struct macaudio_snd_data *ma; + unsigned int i; + + macaudio_test_spk_card(test, &f->t, &macaudio_j316_cfg, SN012776_0DB); + ma = f->t.ma; + f->daemon = kunit_kzalloc(test, sizeof(*f->daemon), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, f->daemon); + KUNIT_ASSERT_NOT_NULL(test, slk.name); + KUNIT_ASSERT_NOT_NULL(test, iface.name); + f->slk = macaudio_test_add_kctl(test, ma->card.snd_card, &slk, &ma->card); + f->iface = macaudio_test_add_kctl(test, ma->card.snd_card, &iface, &ma->card); + ma->speaker_lock_kctl = f->slk; + ma->spk_iface_kctl = f->iface; + ma->has_safety = true; + + /* As macaudio_late_probe() does at every bind */ + for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) + macaudio_test_vol(f->t.vols[i])->value = MACAUDIO_TEST_START_VOL; + ma->spk_iface = MACAUDIO_SPK_IFACE_UNLOCK; + mutex_lock(&ma->volume_lock_mutex); + macaudio_vlimit_unlock(ma, false); + mutex_unlock(&ma->volume_lock_mutex); +} + +static int macaudio_test_iface_write(struct kunit *test, struct macaudio_test_iface *f, + unsigned int item) +{ + struct snd_ctl_elem_value *uval = kunit_kzalloc(test, sizeof(*uval), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, uval); + uval->value.enumerated.item[0] = item; + return macaudio_spk_iface_put(f->iface, uval); +} + +/* The legacy daemon takes the lock and every speaker volume */ +static void macaudio_test_daemon_take(struct kunit *test, struct macaudio_test_iface *f) +{ + unsigned int i; + + for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) + f->t.vols[i]->vd[0].owner = f->daemon; + KUNIT_ASSERT_EQ(test, macaudio_slk_lock(f->slk, f->daemon), 0); +} + +static int macaudio_test_daemon_ping(struct kunit *test, struct macaudio_test_iface *f) +{ + struct snd_ctl_elem_value *uval = kunit_kzalloc(test, sizeof(*uval), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, uval); + uval->value.integer.value[0] = SPEAKER_MAGIC_VALUE; + return macaudio_slk_put(f->slk, uval); +} + +/* Every speaker volume's value and limit */ +static void macaudio_test_expect_limit(struct kunit *test, struct macaudio_test_iface *f, + long value, int limit) +{ + unsigned int i; + + for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) { + KUNIT_EXPECT_EQ(test, macaudio_test_vol(f->t.vols[i])->value, value); + KUNIT_EXPECT_EQ(test, macaudio_test_vol(f->t.vols[i])->mc.platform_max, limit); + } +} + +/* At the bind: the volume lock owns the speakers and the lease grants nothing */ +static void macaudio_iface_volume_lock_from_binding(struct kunit *test) +{ + struct macaudio_test_iface f; + + macaudio_test_iface_card(test, &f); + KUNIT_EXPECT_FALSE(test, macaudio_spk_leased(f.t.ma)); + /* The lock's ceiling, 1 on the SN012776, clips what was there */ + macaudio_test_expect_limit(test, &f, 1, 1); + + /* A lease owner may hold its control, but takes nothing */ + macaudio_test_take(test, &f.t); + macaudio_test_expect_limit(test, &f, 1, 1); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), -EBUSY); + KUNIT_EXPECT_EQ(test, macaudio_test_read(test, &f.t), 0L); + macaudio_spk_unlock(f.t.spk); + macaudio_test_expect_limit(test, &f, 1, 1); + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + + /* Speaker volumes are the daemon's to write */ + KUNIT_EXPECT_EQ(test, f.t.vols[0]->write_check(f.t.vols[0], NULL), 0); + + /* The daemon unlocks them as on a lock-only kernel */ + macaudio_test_daemon_take(test, &f); + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), 0); + KUNIT_EXPECT_TRUE(test, f.t.ma->speaker_volume_unlocked); + macaudio_test_expect_limit(test, &f, 1, SN012776_0DB); +} + +/* Into the lease: the lock's ceiling, then the lease's floor, then the lift */ +static void macaudio_iface_switch_goes_through_the_floor(struct kunit *test) +{ + struct macaudio_test_iface f; + unsigned int i; + + macaudio_test_iface_card(test, &f); + macaudio_test_daemon_take(test, &f); + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), 0); + for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) + macaudio_test_vol(f.t.vols[i])->value = 180; + + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_LEASE), 1); + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, f.t.ma->speaker_volume_unlocked); + /* At the lease's floor, below a ceiling that no longer applies */ + macaudio_test_expect_limit(test, &f, 0, SN012776_0DB); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); + + /* The volume lock is refused, and so are the daemon's volume writes */ + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), -EBUSY); + KUNIT_EXPECT_EQ(test, f.t.vols[0]->write_check(f.t.vols[0], NULL), -EPERM); + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_LEASE), 0); + + /* The engine is granted its operating gain */ + macaudio_test_take(test, &f.t); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), 0); + KUNIT_EXPECT_TRUE(test, macaudio_spk_admitted(f.t.ma)); + macaudio_test_expect_limit(test, &f, SN012776_0DB, SN012776_0DB); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 0), 0); + macaudio_test_settle(f.t.ma); +} + +/* + * Back to the volume lock: the speakers come back at the floor under the + * lock's ceiling, and go up only once the daemon pings, as after a cold + * bind; its first ping learns that it lost the lock. + */ +static void macaudio_iface_revert_starts_at_the_floor(struct kunit *test) +{ + struct macaudio_test_iface f; + + macaudio_test_iface_card(test, &f); + macaudio_test_daemon_take(test, &f); + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_LEASE), 1); + macaudio_test_take(test, &f.t); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), 0); + macaudio_test_expect_limit(test, &f, SN012776_0DB, SN012776_0DB); + + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_UNLOCK), 1); + macaudio_test_settle(f.t.ma); + KUNIT_EXPECT_FALSE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); + KUNIT_EXPECT_FALSE(test, f.t.ma->speaker_volume_unlocked); + macaudio_test_expect_limit(test, &f, 0, 1); + /* The lease grants nothing any more */ + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), -EBUSY); + macaudio_test_expect_limit(test, &f, 0, 1); + + /* The daemon's lock was lost: told once, then it unlocks */ + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), -ETIMEDOUT); + KUNIT_EXPECT_FALSE(test, f.t.ma->speaker_volume_unlocked); + macaudio_test_expect_limit(test, &f, 0, 1); + KUNIT_EXPECT_EQ(test, macaudio_test_daemon_ping(test, &f), 0); + KUNIT_EXPECT_TRUE(test, f.t.ma->speaker_volume_unlocked); + /* Unlocking lifts the ceiling only: the daemon sets the volumes itself */ + macaudio_test_expect_limit(test, &f, 0, SN012776_0DB); +} + +/* The engine dies: the lease's floor at once, the volume lock after the grace */ +static void macaudio_iface_unowned_lease_reverts(struct kunit *test) +{ + struct macaudio_test_iface f; + + macaudio_test_iface_card(test, &f); + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_LEASE), 1); + /* Entered without an owner: the grace runs already */ + KUNIT_EXPECT_TRUE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + macaudio_test_take(test, &f.t); + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + KUNIT_EXPECT_EQ(test, macaudio_test_write(test, &f.t, 50), 0); + + macaudio_spk_unlock(f.t.spk); + macaudio_test_settle(f.t.ma); + KUNIT_EXPECT_TRUE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, macaudio_spk_admitted(f.t.ma)); + macaudio_test_expect_limit(test, &f, 0, SN012776_0DB); + KUNIT_EXPECT_TRUE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + + /* A restarted engine takes it back within the grace: no revert */ + macaudio_test_take(test, &f.t); + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&f.t.ma->spk_unowned_work)); + macaudio_spk_unlock(f.t.spk); + + /* The grace runs out */ + mod_delayed_work(system_wq, &f.t.ma->spk_unowned_work, 0); + flush_delayed_work(&f.t.ma->spk_unowned_work); + macaudio_test_settle(f.t.ma); + KUNIT_EXPECT_FALSE(test, macaudio_spk_leased(f.t.ma)); + KUNIT_EXPECT_FALSE(test, f.t.ma->speaker_volume_unlocked); + macaudio_test_expect_limit(test, &f, 0, 1); +} + +/* Only a CAP_SYS_ADMIN process hands the speakers over */ +static void macaudio_iface_needs_cap_sys_admin(struct kunit *test) +{ + struct macaudio_test_iface f; + const struct cred *old; + struct cred *cred; + + macaudio_test_iface_card(test, &f); + cred = prepare_creds(); + KUNIT_ASSERT_NOT_NULL(test, cred); + cap_lower(cred->cap_effective, CAP_SYS_ADMIN); + old = override_creds(cred); + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, MACAUDIO_SPK_IFACE_LEASE), + -EPERM); + revert_creds(old); + put_cred(cred); + KUNIT_EXPECT_FALSE(test, macaudio_spk_leased(f.t.ma)); + macaudio_test_expect_limit(test, &f, 1, 1); + KUNIT_EXPECT_EQ(test, macaudio_test_iface_write(test, &f, 2), -EINVAL); +} + +/* The switch is no mixer setting: alsactl neither saves nor restores it */ +static void macaudio_iface_control_is_inactive(struct kunit *test) +{ + struct snd_kcontrol_new iface = macaudio_test_control("Speaker Protection Interface"); + + KUNIT_EXPECT_TRUE(test, iface.access & SNDRV_CTL_ELEM_ACCESS_INACTIVE); + KUNIT_EXPECT_TRUE(test, iface.access & SNDRV_CTL_ELEM_ACCESS_VOLATILE); +} + +static struct kunit_case macaudio_iface_cases[] = { + KUNIT_CASE(macaudio_iface_volume_lock_from_binding), + KUNIT_CASE(macaudio_iface_switch_goes_through_the_floor), + KUNIT_CASE(macaudio_iface_revert_starts_at_the_floor), + KUNIT_CASE(macaudio_iface_unowned_lease_reverts), + KUNIT_CASE(macaudio_iface_needs_cap_sys_admin), + KUNIT_CASE(macaudio_iface_control_is_inactive), + {} +}; + +static struct kunit_suite macaudio_iface_suite = { + .name = "apple-speaker-interface", + .test_cases = macaudio_iface_cases, +}; +kunit_test_suite(macaudio_iface_suite); diff --git a/sound/soc/apple/macaudio-pm-volumes-test.h b/sound/soc/apple/macaudio-pm-volumes-test.h new file mode 100644 index 0000000000000..dab9d69bb0faa --- /dev/null +++ b/sound/soc/apple/macaudio-pm-volumes-test.h @@ -0,0 +1,268 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * The speaker volumes the system-sleep lock clips are set again at the + * daemon's first ping after it, through the lock control and the PM notifier. + */ +#include + +struct macaudio_pmt_vol { + struct soc_mixer_control mc; + long value; +}; + +static struct macaudio_pmt_vol *macaudio_pmt_vol(struct snd_kcontrol *kctl) +{ + return container_of((struct soc_mixer_control *)kctl->private_value, + struct macaudio_pmt_vol, mc); +} + +static int macaudio_pmt_vol_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.max = SN012776_0DB; + return 0; +} + +static int macaudio_pmt_vol_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uval) +{ + uval->value.integer.value[0] = macaudio_pmt_vol(kctl)->value; + return 0; +} + +static int macaudio_pmt_vol_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uval) +{ + struct macaudio_pmt_vol *vol = macaudio_pmt_vol(kctl); + bool changed = vol->value != uval->value.integer.value[0]; + + vol->value = uval->value.integer.value[0]; + return changed; +} + +static void macaudio_pmt_free_kctl(void *kctl) +{ + snd_ctl_free_one(kctl); +} + +/* Last in, so first out: before the controls go */ +static void macaudio_pmt_pm_cleanup(void *data) +{ + struct macaudio_snd_data *ma = data; + + cancel_delayed_work_sync(&ma->lock_timeout_work); + macaudio_pm_volumes_drop(ma); + macaudio_spk_fini(ma); +} + +static const char *const macaudio_pmt_vol_names[] = { + "Left Woofer Speaker Volume", + "Right Woofer Speaker Volume", + "Left Tweeter Speaker Volume", + "Right Tweeter Speaker Volume", + /* Not a speaker volume: never locked, kept or set */ + "Headphone Playback Volume", +}; + +/* As the daemon set them before the sleep */ +static const long macaudio_pmt_vols[] = { 201, 190, 201, 170, 120 }; + +#define MACAUDIO_PMT_NR_VOLS ARRAY_SIZE(macaudio_pmt_vol_names) + +struct macaudio_pmt_pm { + struct macaudio_snd_data *ma; + struct snd_kcontrol *slk; + struct snd_kcontrol *vols[MACAUDIO_PMT_NR_VOLS]; +}; + +static struct snd_kcontrol *macaudio_pmt_add_kctl(struct kunit *test, struct snd_card *card, + const struct snd_kcontrol_new *tmpl, + void *private_data) +{ + struct snd_kcontrol *kctl = snd_ctl_new1(tmpl, private_data); + int ret; + + KUNIT_ASSERT_NOT_NULL(test, kctl); + ret = kunit_add_action_or_reset(test, macaudio_pmt_free_kctl, kctl); + KUNIT_ASSERT_EQ(test, ret, 0); + list_add_tail(&kctl->list, &card->controls); + return kctl; +} + +/* A card with speaker safety, its lock control and the volumes, none owned yet */ +static void macaudio_pmt_pm_card(struct kunit *test, struct macaudio_pmt_pm *t) +{ + struct snd_kcontrol_new slk = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Speaker Volume Unlock", + .info = snd_ctl_boolean_mono_info, + .get = macaudio_slk_get, + .put = macaudio_slk_put, + }; + struct macaudio_snd_data *ma; + struct snd_card *card; + unsigned int i; + int ret; + + ma = kunit_kzalloc(test, sizeof(*ma), GFP_KERNEL); + card = kunit_kzalloc(test, sizeof(*card), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ma); + KUNIT_ASSERT_NOT_NULL(test, card); + + INIT_LIST_HEAD(&card->controls); + INIT_LIST_HEAD(&card->ctl_files); + init_rwsem(&card->controls_rwsem); + rwlock_init(&card->controls_rwlock); + ma->card.snd_card = card; + snd_soc_card_set_drvdata(&ma->card, ma); + ma->cfg = &macaudio_j493_cfg; + ma->has_speakers = true; + ma->has_safety = true; + INIT_LIST_HEAD(&ma->card.rtd_list); + mutex_init(&ma->volume_lock_mutex); + INIT_DELAYED_WORK(&ma->lock_timeout_work, macaudio_vlimit_timeout_work); + /* The volume lock is the interface, as at every bind */ + mutex_init(&ma->spk_mutex); + KUNIT_ASSERT_EQ(test, macaudio_spk_init(ma), 0); + + t->ma = ma; + t->slk = macaudio_pmt_add_kctl(test, card, &slk, &ma->card); + ma->speaker_lock_kctl = t->slk; + + for (i = 0; i < MACAUDIO_PMT_NR_VOLS; i++) { + struct macaudio_pmt_vol *vol = kunit_kzalloc(test, sizeof(*vol), GFP_KERNEL); + struct snd_kcontrol_new tmpl = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = macaudio_pmt_vol_names[i], + .info = macaudio_pmt_vol_info, + .get = macaudio_pmt_vol_get, + .put = macaudio_pmt_vol_put, + }; + + KUNIT_ASSERT_NOT_NULL(test, vol); + vol->mc.max = SN012776_0DB; + vol->value = macaudio_pmt_vols[i]; + tmpl.private_value = (unsigned long)&vol->mc; + t->vols[i] = macaudio_pmt_add_kctl(test, card, &tmpl, NULL); + } + + ret = kunit_add_action_or_reset(test, macaudio_pmt_pm_cleanup, ma); + KUNIT_ASSERT_EQ(test, ret, 0); +} + +/* A daemon takes the lock and every speaker volume, as speakersafetyd does */ +static void macaudio_pmt_take(struct kunit *test, struct macaudio_pmt_pm *t) +{ + struct snd_ctl_file *owner = kunit_kzalloc(test, sizeof(*owner), GFP_KERNEL); + unsigned int i; + + KUNIT_ASSERT_NOT_NULL(test, owner); + for (i = 0; i < MACAUDIO_PMT_NR_VOLS - 1; i++) + t->vols[i]->vd[0].owner = owner; + KUNIT_ASSERT_EQ(test, macaudio_slk_lock(t->slk, owner), 0); +} + +static int macaudio_pmt_ping(struct kunit *test, struct macaudio_pmt_pm *t) +{ + struct snd_ctl_elem_value *uval = kunit_kzalloc(test, sizeof(*uval), GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, uval); + uval->value.integer.value[0] = SPEAKER_MAGIC_VALUE; + return macaudio_slk_put(t->slk, uval); +} + +static void macaudio_pmt_notify(struct macaudio_pmt_pm *t, unsigned long action) +{ + macaudio_pm_notify(&t->ma->pm_nb, action, NULL); +} + +/* The speaker volumes as the daemon set them, or clipped to the lock's ceiling */ +static void macaudio_pmt_expect_vols(struct kunit *test, struct macaudio_pmt_pm *t, + bool clipped) +{ + unsigned int i; + + for (i = 0; i < MACAUDIO_PMT_NR_VOLS; i++) { + bool speaker = i < MACAUDIO_PMT_NR_VOLS - 1; + + KUNIT_EXPECT_EQ(test, macaudio_pmt_vol(t->vols[i])->value, + speaker && clipped ? 1L : macaudio_pmt_vols[i]); + } +} + +static void macaudio_pm_volumes_restored_after_sleep(struct kunit *test) +{ + struct macaudio_pmt_pm t; + + macaudio_pmt_pm_card(test, &t); + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_TRUE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, false); + + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + KUNIT_EXPECT_FALSE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, true); + /* A ping before the freeze leaves them locked */ + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_FALSE(test, t.ma->speaker_volume_unlocked); + + /* Locked after the resume until the daemon pings */ + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + KUNIT_EXPECT_FALSE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, true); + + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_TRUE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, false); + KUNIT_EXPECT_NULL(test, t.ma->pm_volumes); +} + +/* The daemon pings only once a stream runs: a second sleep can come first. */ +static void macaudio_pm_volumes_second_sleep_before_ping(struct kunit *test) +{ + struct macaudio_pmt_pm t; + + macaudio_pmt_pm_card(test, &t); + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + macaudio_pmt_expect_vols(test, &t, true); + + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + macaudio_pmt_expect_vols(test, &t, false); +} + +/* A new owner, such as a restarted daemon, sets the volumes itself. */ +static void macaudio_pm_volumes_new_owner(struct kunit *test) +{ + struct macaudio_pmt_pm t; + + macaudio_pmt_pm_card(test, &t); + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + macaudio_pmt_notify(&t, PM_SUSPEND_PREPARE); + macaudio_pmt_notify(&t, PM_POST_SUSPEND); + + macaudio_pmt_take(test, &t); + KUNIT_EXPECT_NULL(test, t.ma->pm_volumes); + KUNIT_EXPECT_EQ(test, macaudio_pmt_ping(test, &t), 0); + KUNIT_EXPECT_TRUE(test, t.ma->speaker_volume_unlocked); + macaudio_pmt_expect_vols(test, &t, true); +} + +static struct kunit_case macaudio_pm_volumes_cases[] = { + KUNIT_CASE(macaudio_pm_volumes_restored_after_sleep), + KUNIT_CASE(macaudio_pm_volumes_second_sleep_before_ping), + KUNIT_CASE(macaudio_pm_volumes_new_owner), + {} +}; + +static struct kunit_suite macaudio_pm_volumes_suite = { + .name = "apple-speaker-pm-volumes", + .test_cases = macaudio_pm_volumes_cases, +}; +kunit_test_suite(macaudio_pm_volumes_suite); diff --git a/sound/soc/apple/macaudio-protection-test.h b/sound/soc/apple/macaudio-protection-test.h index ca50d5055a322..7c3c6b03d7cf5 100644 --- a/sound/soc/apple/macaudio-protection-test.h +++ b/sound/soc/apple/macaudio-protection-test.h @@ -33,7 +33,9 @@ static int macaudio_test_vol_info(struct snd_kcontrol *kctl, struct snd_ctl_elem { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; - uinfo->value.integer.max = macaudio_test_vol(kctl)->mc.max; + /* As snd_soc_info_volsw(): a limit is the top of the range */ + uinfo->value.integer.max = macaudio_test_vol(kctl)->mc.platform_max ?: + macaudio_test_vol(kctl)->mc.max; return 0; } @@ -98,8 +100,21 @@ struct macaudio_test_spk { /* "Speaker Protection Crossover" */ struct snd_kcontrol *xover; struct snd_ctl_file *owner; + /* The codec the speaker volumes belong to */ + struct snd_soc_component component; }; +/* The card's control named @name */ +static struct snd_kcontrol_new macaudio_test_control(const char *name) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(macaudio_controls); i++) + if (macaudio_controls[i].name && !strcmp(macaudio_controls[i].name, name)) + return macaudio_controls[i]; + return (struct snd_kcontrol_new){}; +} + static struct snd_kcontrol *macaudio_test_add_kctl(struct kunit *test, struct snd_card *card, const struct snd_kcontrol_new *tmpl, void *private_data) @@ -118,7 +133,7 @@ static struct snd_kcontrol *macaudio_test_add_kctl(struct kunit *test, struct sn static void macaudio_test_spk_card(struct kunit *test, struct macaudio_test_spk *t, const struct macaudio_platform_cfg *cfg, long max) { - struct snd_kcontrol_new spk = macaudio_controls[ARRAY_SIZE(macaudio_controls) - 1]; + struct snd_kcontrol_new spk = macaudio_test_control("Speaker Protection"); struct macaudio_snd_data *ma; struct snd_card *card; struct device *dev; @@ -148,7 +163,14 @@ static void macaudio_test_spk_card(struct kunit *test, struct macaudio_test_spk ma->cfg = cfg; ma->has_speakers = true; mutex_init(&ma->spk_mutex); + mutex_init(&ma->volume_lock_mutex); + INIT_DELAYED_WORK(&ma->lock_timeout_work, macaudio_vlimit_timeout_work); + INIT_WORK(&ma->lock_fail_work, macaudio_lock_fail_work); + INIT_WORK(&ma->sw_gain_stop_work, macaudio_sw_gain_stop_work); + /* The lease is the interface, as after "Speaker Protection Interface" */ + ma->spk_iface = MACAUDIO_SPK_IFACE_LEASE; KUNIT_ASSERT_EQ(test, macaudio_spk_init(ma), 0); + t->component.card = &ma->card; t->ma = ma; t->spk = macaudio_test_add_kctl(test, card, &spk, &ma->card); @@ -170,7 +192,7 @@ static void macaudio_test_spk_card(struct kunit *test, struct macaudio_test_spk if (cfg->amp == AMP_MAX98360A && i < MACAUDIO_TEST_NR_SPK) tmpl.name = macaudio_test_sw_vol_names[i]; tmpl.private_value = (unsigned long)&vol->mc; - t->vols[i] = macaudio_test_add_kctl(test, card, &tmpl, NULL); + t->vols[i] = macaudio_test_add_kctl(test, card, &tmpl, &t->component); } t->xover = macaudio_test_add_kctl(test, card, &macaudio_spk_xover_control, &ma->card); @@ -266,9 +288,8 @@ static void macaudio_spk_floor_from_binding(struct kunit *test) /* Userspace can read the speaker volumes but never write them */ for (i = 0; i < MACAUDIO_TEST_NR_SPK; i++) - KUNIT_EXPECT_FALSE(test, t.vols[i]->vd[0].access & SNDRV_CTL_ELEM_ACCESS_WRITE); - KUNIT_EXPECT_TRUE(test, t.vols[MACAUDIO_TEST_NR_SPK]->vd[0].access & - SNDRV_CTL_ELEM_ACCESS_WRITE); + KUNIT_EXPECT_EQ(test, t.vols[i]->write_check(t.vols[i], NULL), -EPERM); + KUNIT_EXPECT_NULL(test, t.vols[MACAUDIO_TEST_NR_SPK]->write_check); } static void macaudio_spk_grant_needs_owner_and_valid_lease(struct kunit *test) @@ -703,7 +724,10 @@ static void macaudio_spk_regrant_waits_for_the_stop(struct kunit *test) macaudio_test_expect_vols(test, &t, SN012776_0DB); } -/* "Amp Gain Volume": held at the configured gain, readable, not writable */ +/* + * "Amp Gain Volume": limited at the configured gain, fixed at it while + * leased and not writable then, the amp's own under the volume lock. + */ static void macaudio_spk_amp_gain_is_fixed(struct kunit *test) { static const char *const names[] = { @@ -715,6 +739,7 @@ static void macaudio_spk_amp_gain_is_fixed(struct kunit *test) struct macaudio_test_spk t; const int level = 15; unsigned int i; + int ret; macaudio_test_spk_card(test, &t, &macaudio_j316_cfg, SN012776_0DB); for (i = 0; i < ARRAY_SIZE(names); i++) { @@ -731,25 +756,35 @@ static void macaudio_spk_amp_gain_is_fixed(struct kunit *test) KUNIT_ASSERT_NOT_NULL(test, vols[i]); vols[i]->mc.max = 20; tmpl.private_value = (unsigned long)&vols[i]->mc; - kctls[i] = macaudio_test_add_kctl(test, t.ma->card.snd_card, &tmpl, NULL); + kctls[i] = macaudio_test_add_kctl(test, t.ma->card.snd_card, &tmpl, + &t.component); } /* Above the amp level (any level the ADT gives), and below it */ vols[0]->value = 20; vols[1]->value = 5; - KUNIT_EXPECT_EQ(test, macaudio_set_fixed_volume(&t.ma->card, "* Amp Gain Volume", - level), 2); + KUNIT_EXPECT_EQ(test, snd_soc_limit_volume(&t.ma->card, "* Amp Gain Volume", level), 2); + KUNIT_EXPECT_EQ(test, vols[0]->value, (long)level); + KUNIT_EXPECT_EQ(test, vols[1]->value, 5L); + KUNIT_ASSERT_EQ(test, macaudio_spk_take_amp_gains(t.ma), 0); + KUNIT_EXPECT_EQ(test, t.ma->spk_nr_amp_gains, (unsigned int)ARRAY_SIZE(names)); + + mutex_lock(&t.ma->spk_mutex); + ret = macaudio_spk_fix_amp_gains(t.ma); + mutex_unlock(&t.ma->spk_mutex); + KUNIT_EXPECT_EQ(test, ret, 0); for (i = 0; i < ARRAY_SIZE(names); i++) { KUNIT_EXPECT_EQ(test, vols[i]->value, (long)level); KUNIT_EXPECT_EQ(test, vols[i]->mc.platform_max, level); - KUNIT_EXPECT_TRUE(test, kctls[i]->vd[0].access & SNDRV_CTL_ELEM_ACCESS_READ); - KUNIT_EXPECT_FALSE(test, kctls[i]->vd[0].access & SNDRV_CTL_ELEM_ACCESS_WRITE); + KUNIT_EXPECT_EQ(test, kctls[i]->write_check(kctls[i], NULL), -EPERM); } /* The speaker volumes and the headphone volume are not amp gains */ - KUNIT_EXPECT_TRUE(test, t.vols[MACAUDIO_TEST_NR_SPK]->vd[0].access & - SNDRV_CTL_ELEM_ACCESS_WRITE); - KUNIT_EXPECT_EQ(test, macaudio_set_fixed_volume(&t.ma->card, "* Missing Volume", 15), - -EINVAL); + KUNIT_EXPECT_NULL(test, t.vols[MACAUDIO_TEST_NR_SPK]->write_check); + + /* Under the volume lock they are the amp's again */ + WRITE_ONCE(t.ma->spk_iface, MACAUDIO_SPK_IFACE_UNLOCK); + for (i = 0; i < ARRAY_SIZE(names); i++) + KUNIT_EXPECT_EQ(test, kctls[i]->write_check(kctls[i], NULL), 0); } struct macaudio_test_sleep { diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index 220b99b853879..4e1b642e4b0a5 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -66,8 +66,17 @@ */ #define MACAUDIO_MAX_BCLK_FREQ 24576000 +#define SPEAKER_MAGIC_VALUE (s32)0xdec1be15 /* Primary, Secondary and Speaker Sense */ #define MACAUDIO_NUM_FE_LINKS 3 +/* The "Speaker Volume Unlock" lease, in milliseconds */ +#define SPEAKER_LOCK_TIMEOUT 250 +/* + * While "Speaker Protection" is the interface, this long without an owner of + * it (the engine died, or never came) puts "Speaker Volume Unlock" back in + * charge, at its ceiling. + */ +#define SPEAKER_LEASE_UNOWNED_MS 30000 /* The speaker protection lease an owner may ask for, in milliseconds */ #define SPEAKER_LEASE_MIN_MS 10 #define SPEAKER_LEASE_MAX_MS 100 @@ -121,6 +130,11 @@ struct macaudio_platform_cfg { * amplifiers) unless set. */ const char *spk_out_widget; + /* + * Software-gain amplifier: the CPU DAI whose front-end converts the + * speaker samples through the volume control at copy time. + */ + const char *sw_gain_dai; /* * A CPU component other than the MCA: its front-end DAI names in * place of "mca-pcm-N", the DAI format its serial links run (the @@ -192,6 +206,29 @@ struct ma_codec_idle { u32 idle_mask; }; +/* A speaker volume control and its value, as the system-sleep lock found it */ +struct macaudio_pm_volume { + struct snd_kcontrol *kctl; + long value[2]; +}; + +/* + * The interface that owns the speakers (see "Speaker Protection Interface"): + * the volume lock of speakersafetyd and speakerguardd 0.1, or the lease of a + * protection engine in the signal path. + */ +enum macaudio_spk_iface { + MACAUDIO_SPK_IFACE_UNLOCK, + MACAUDIO_SPK_IFACE_LEASE, +}; + +/* + * The software-gain CPU component's register that selects the volume + * table's top: 0 the legacy ceiling (half the amplifier's full scale), 1 the + * full scale (sound/soc/apple/aop_t8140.rs, REG_SPKR_FULL_SCALE). + */ +#define MACAUDIO_SW_GAIN_REG_FULL_SCALE 1 + struct macaudio_snd_data { struct snd_soc_card card; struct snd_soc_jack jack; @@ -202,6 +239,7 @@ struct macaudio_snd_data { const struct macaudio_platform_cfg *cfg; bool has_speakers; bool has_sense; + bool has_safety; unsigned int max_channels; struct gpio_descs *speaker_id_gpios; @@ -209,6 +247,8 @@ struct macaudio_snd_data { /* frontend props */ unsigned int bclk_ratio; bool is_sense; + /* the front-end that applies the software speaker gain */ + bool sw_gain; /* backend props */ bool is_speakers; @@ -280,8 +320,80 @@ struct macaudio_snd_data { */ struct snd_kcontrol *spk_xover_kctl; bool spk_xover; + + /* + * The interface in charge (enum macaudio_spk_iface): written under + * spk_mutex and volume_lock_mutex, read with either or without both. + */ + int spk_iface; + struct snd_kcontrol *spk_iface_kctl; + /* "Speaker Volume Unlock" back in charge after a lease without owner */ + struct delayed_work spk_unowned_work; + /* The amps' own gains, fixed at their limit while leased */ + struct snd_kcontrol **spk_amp_gains; + unsigned int spk_nr_amp_gains; + /* The software-gain CPU component, whose volume table top follows the interface */ + struct snd_soc_component *sw_gain_component; + + /* + * "Speaker Volume Unlock": the speakersafetyd / speakerguardd 0.1 + * interface (see macaudio_vlimit_update()). + */ + int speaker_sample_rate; + struct snd_kcontrol *speaker_sample_rate_kctl; + + struct mutex volume_lock_mutex; + bool speaker_volume_unlocked; + bool speaker_volume_was_locked; + struct snd_kcontrol *speaker_lock_kctl; + struct snd_ctl_file *speaker_lock_owner; + u64 bes_active; + bool speaker_lock_timeout_enabled; + ktime_t speaker_lock_timeout; + ktime_t speaker_lock_remain; + struct delayed_work lock_timeout_work; + struct work_struct lock_update_work; + /* + * The speaker volumes as the system-sleep lock found them. Locking clips + * them to its ceiling and unlocking only lifts the ceiling; the daemon + * keeps its lease across the sleep and does not set them again. + */ + struct macaudio_pm_volume *pm_volumes; + unsigned int pm_nr_volumes; + /* Allocated with them, so that setting them again cannot fail */ + struct snd_ctl_elem_value *pm_uval; + + /* + * Software-gain amplifier: a lower gain cannot change samples that + * were converted before it was set, so every lock event bumps the + * epoch and stops the front-end stream; it is refused until it has + * been prepared (and its buffer cleared) under the new epoch. + */ + atomic_t sw_gain_lock_epoch; + atomic_t sw_gain_prepared_epoch; + atomic_t sw_gain_limit_failed; + struct work_struct sw_gain_stop_work; + + /* + * A lock that did not take on every speaker volume (a control write + * failed) is a failed lock: the playback streams are stopped and + * refused until the driver is reloaded, since a volume above the safe + * value may be left behind. + */ + bool speaker_lock_failed; + struct work_struct lock_fail_work; }; +static int please_blow_up_my_speakers; +module_param(please_blow_up_my_speakers, int, 0644); +MODULE_PARM_DESC(please_blow_up_my_speakers, "Deprecated: cannot bypass speaker admission or protection"); + +/* "Speaker Protection" owns the speakers, not "Speaker Volume Unlock" */ +static bool macaudio_spk_leased(const struct macaudio_snd_data *ma) +{ + return READ_ONCE(ma->spk_iface) == MACAUDIO_SPK_IFACE_LEASE; +} + SND_SOC_DAILINK_DEFS(primary, DAILINK_COMP_ARRAY(COMP_CPU("mca-pcm-0")), // CPU @@ -374,9 +486,485 @@ static struct macaudio_link_props macaudio_fe_link_props[] = { }; /* - * Speaker protection ownership. + * "Speaker Volume Unlock": speaker protection by a userspace daemon + * (speakersafetyd, speakerguardd 0.1), the default interface. * - * The speakers play only while a protection engine owns them. Without an + * The daemon holds SNDRV_CTL_IOCTL_ELEM_LOCK on "Speaker Volume Unlock" and + * on every speaker volume control, and pings the unlock control with + * SPEAKER_MAGIC_VALUE at least every SPEAKER_LOCK_TIMEOUT ms while the + * speakers play. While it does, the volumes may go up to the amps' 0 dB; + * otherwise they are held at the lock's ceiling. The daemon governs them + * from its thermal model. + */ + +static void macaudio_vlimit_unlock(struct macaudio_snd_data *ma, bool unlock) +{ + int ret, max, hits = 0; + const char *name = volume_control_names[ma->cfg->amp]; + struct snd_kcontrol *kctl; + bool failed = false; + + if (!name) { + WARN_ON_ONCE(1); + return; + } + + switch (ma->cfg->amp) { + case AMP_NONE: + WARN_ON_ONCE(1); + return; + case AMP_TAS5770: + if (unlock) + max = TAS5770_0DB; + else + max = 1; //TAS5770_DB(ma->cfg->safe_vol); + break; + case AMP_SN012776: + if (unlock) + max = SN012776_0DB; + else + max = 1; //SN012776_DB(ma->cfg->safe_vol); + break; + case AMP_SSM3515: + if (unlock) + max = SSM3515_0DB; + else + max = SSM3515_DB(ma->cfg->safe_vol); + break; + case AMP_MAX98360A: + if (unlock) + max = MAX98360A_0DB; + else + max = MAX98360A_DB(ma->cfg->safe_vol); + break; + } + + /* + * One control at a time: snd_soc_limit_volume() stops at the first + * control it cannot clip, which would leave the rest at their old + * limit and value. + */ + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { + if (!snd_soc_control_matches(kctl, name)) + continue; + + hits++; + ret = snd_soc_limit_volume(&ma->card, kctl->id.name, max); + if (ret < 0) { + dev_err(ma->card.dev, "Failed to %slock volume %s: %d\n", + unlock ? "un" : "", kctl->id.name, ret); + failed = true; + } + } + if (!hits) + dev_err(ma->card.dev, "Failed to %slock volume %s: %d\n", + unlock ? "un" : "", name, -EINVAL); + + /* + * With a software gain the limit is the whole protection: refuse to + * play rather than run the amplifier at full scale unlimited. + */ + if (ma->cfg->amp == AMP_MAX98360A) + atomic_set(&ma->sw_gain_limit_failed, failed || !hits); + + if (failed && !unlock) { + WRITE_ONCE(ma->speaker_lock_failed, true); + schedule_work(&ma->lock_fail_work); + } +} + +/* + * Stop every running playback stream of the card, or with sw_gain_only those + * on software-gain links whose prepare predates the current lock epoch. + */ +static void macaudio_stop_playback(struct macaudio_snd_data *ma, bool sw_gain_only) +{ + struct snd_soc_pcm_runtime *rtd; + struct snd_pcm_substream *substream; + unsigned long flags; + + /* + * No volume or control lock may be held while taking the stream lock. + * Pick the links from the runtime being walked: not every playback + * substream on the card carries a runtime as its private data. + */ + for_each_card_rtds(&ma->card, rtd) { + /* A back-end's substream shares its front-end's runtime: stop front-ends only. */ + if (!rtd->pcm || rtd->dai_link->no_pcm) + continue; + if (sw_gain_only && !ma->link_props[rtd->dai_link->id].sw_gain) + continue; + substream = rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + if (!substream) + continue; + snd_pcm_stream_lock_irqsave(substream, flags); + if (substream->runtime && + (!sw_gain_only || + atomic_read(&ma->sw_gain_prepared_epoch) != + atomic_read(&ma->sw_gain_lock_epoch))) { + switch (substream->runtime->state) { + case SNDRV_PCM_STATE_PREPARED: + case SNDRV_PCM_STATE_RUNNING: + case SNDRV_PCM_STATE_DRAINING: + case SNDRV_PCM_STATE_PAUSED: + snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); + break; + default: + break; + } + } + snd_pcm_stream_unlock_irqrestore(substream, flags); + } +} + +/* Stop every running playback stream of the card after a failed lock. */ +static void macaudio_lock_fail_work(struct work_struct *work) +{ + struct macaudio_snd_data *ma = container_of(work, struct macaudio_snd_data, + lock_fail_work); + + dev_crit(ma->card.dev, "speaker volume lock failed: stopping and refusing playback\n"); + macaudio_stop_playback(ma, false); +} + +static void macaudio_pm_volumes_drop(struct macaudio_snd_data *ma) +{ + kfree(ma->pm_volumes); + kfree(ma->pm_uval); + ma->pm_volumes = NULL; + ma->pm_nr_volumes = 0; + ma->pm_uval = NULL; +} + +/* + * Keep the speaker volumes before the system-sleep lock clips them. + * + * Context: volume_lock_mutex and the card's controls_rwsem held, so the daemon + * cannot set a volume between this and the clip. + */ +static void macaudio_pm_volumes_save(struct macaudio_snd_data *ma) +{ + const char *name = volume_control_names[ma->cfg->amp]; + struct snd_ctl_elem_value *uval = NULL; + struct macaudio_pm_volume *vols = NULL; + struct snd_kcontrol *kctl; + unsigned int nr = 0, i = 0; + int ret; + + lockdep_assert_held(&ma->volume_lock_mutex); + lockdep_assert_held(&ma->card.snd_card->controls_rwsem); + + if (!ma->has_safety || !name || ma->card.snd_card->shutdown) + return; + /* + * Locked already, as after a sleep the daemon has not pinged since: + * the volumes are at the ceiling, and those from before it are kept. + */ + if (!ma->speaker_volume_unlocked) + return; + macaudio_pm_volumes_drop(ma); + + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) + if (snd_soc_control_matches(kctl, name)) + nr++; + if (!nr) + return; + + vols = kzalloc_objs(*vols, nr); + uval = kzalloc_obj(*uval); + if (!vols || !uval) + goto out; + + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { + if (!snd_soc_control_matches(kctl, name)) + continue; + memset(uval, 0, sizeof(*uval)); + uval->id = kctl->id; + ret = kctl->get(kctl, uval); + if (ret < 0) { + dev_warn(ma->card.dev, "Failed to keep volume %s for the system sleep: %d\n", + kctl->id.name, ret); + goto out; + } + vols[i].kctl = kctl; + vols[i].value[0] = uval->value.integer.value[0]; + vols[i].value[1] = uval->value.integer.value[1]; + i++; + } + + ma->pm_volumes = vols; + ma->pm_nr_volumes = i; + ma->pm_uval = uval; + return; +out: + kfree(uval); + kfree(vols); +} + +/* + * At the unlock after a system sleep: the volumes the daemon had set. + * + * Context: volume_lock_mutex and the card's controls_rwsem held, so no volume + * write races these. + */ +static void macaudio_pm_volumes_restore(struct macaudio_snd_data *ma) +{ + struct snd_ctl_elem_value *uval = ma->pm_uval; + unsigned int i; + int ret; + + if (!ma->pm_volumes) + return; + + for (i = 0; i < ma->pm_nr_volumes; i++) { + struct snd_kcontrol *kctl = ma->pm_volumes[i].kctl; + + memset(uval, 0, sizeof(*uval)); + uval->id = kctl->id; + uval->value.integer.value[0] = ma->pm_volumes[i].value[0]; + uval->value.integer.value[1] = ma->pm_volumes[i].value[1]; + ret = kctl->put(kctl, uval); + if (ret < 0) + dev_err(ma->card.dev, "Failed to restore volume %s: %d\n", + kctl->id.name, ret); + else if (ret > 0) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &kctl->id); + } + macaudio_pm_volumes_drop(ma); +} + +static void macaudio_vlimit_update(struct macaudio_snd_data *ma) +{ + int i; + bool unlock = true; + struct snd_kcontrol *kctl; + const char *reason; + + /* Do nothing if there is no safety configured */ + if (!ma->has_safety) + return; + + /* + * "Speaker Protection" owns the speakers: the lock is held at its + * ceiling until the interface switches back (macaudio_spk_leave_lease()). + */ + if (macaudio_spk_leased(ma)) + return; + + /* Check that someone is holding the main lock */ + if (!ma->speaker_lock_owner) { + reason = "Main control not locked"; + unlock = false; + } + + /* Check that the control has been pinged within the timeout */ + if (ma->speaker_lock_remain <= 0) { + reason = "Lock timeout"; + unlock = false; + } + + /* + * System sleep: userspace is frozen long before the card suspends (over + * half a second on J616s), and a playback stream left running then plays + * out its stale buffer and stops on an xrun into the still unmuted amps. + * Lock the volumes before the freeze instead of when the frozen daemon's + * lease runs out. + */ + if (ma->pm_quiesced) { + reason = "System suspend"; + unlock = false; + } + + /* Check that *every* limited control is locked by the same owner */ + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { + if(!snd_soc_control_matches(kctl, volume_control_names[ma->cfg->amp])) + continue; + + for (i = 0; i < kctl->count; i++) { + if (kctl->vd[i].owner != ma->speaker_lock_owner) { + reason = "Not all child controls locked by the same process"; + unlock = false; + } + } + } + + + if (unlock != ma->speaker_volume_unlocked) { + if (unlock) { + dev_info(ma->card.dev, "Speaker volumes unlocked\n"); + } else { + dev_info(ma->card.dev, "Speaker volumes locked: %s\n", reason); + /* The system-sleep lock is the kernel's own, not a lease the daemon lost */ + if (!ma->pm_quiesced) + ma->speaker_volume_was_locked = true; + } + + macaudio_vlimit_unlock(ma, unlock); + if (unlock) + macaudio_pm_volumes_restore(ma); + if (!unlock && ma->cfg->amp == AMP_MAX98360A) { + /* Samples already converted at the old gain must not play */ + atomic_inc(&ma->sw_gain_lock_epoch); + schedule_work(&ma->sw_gain_stop_work); + } + ma->speaker_volume_unlocked = unlock; + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->speaker_lock_kctl->id); + } +} + +/* + * The volume lock's part of a system sleep (see macaudio_pm_notify()), after + * pm_quiesced has been set or cleared. + * + * Volume writes hold the controls for writing: none can land between + * keeping the volumes and clipping them. Control writes take + * volume_lock_mutex inside it as well. + */ +static void macaudio_vlimit_pm(struct macaudio_snd_data *ma, bool quiesce) +{ + down_read(&ma->card.snd_card->controls_rwsem); + mutex_lock(&ma->volume_lock_mutex); + /* + * The lease ends here, so after the resume the volumes stay locked until + * the daemon's next ping. Its clock (CLOCK_MONOTONIC) stops across s2idle: + * a lease left running would unlock them at resume and expire before the + * thawed daemon pings, which reports a lost lock and restarts it cold. + */ + if (quiesce) { + cancel_delayed_work(&ma->lock_timeout_work); + ma->speaker_lock_remain = 0; + macaudio_pm_volumes_save(ma); + } + macaudio_vlimit_update(ma); + mutex_unlock(&ma->volume_lock_mutex); + up_read(&ma->card.snd_card->controls_rwsem); +} + +static void macaudio_vlimit_enable_timeout(struct macaudio_snd_data *ma) +{ + mutex_lock(&ma->volume_lock_mutex); + + if (ma->speaker_lock_timeout_enabled) { + mutex_unlock(&ma->volume_lock_mutex); + return; + } + + if (ma->speaker_lock_remain > 0) { + ma->speaker_lock_timeout = ktime_add(ktime_get(), ma->speaker_lock_remain); + schedule_delayed_work(&ma->lock_timeout_work, usecs_to_jiffies(ktime_to_us(ma->speaker_lock_remain))); + dev_dbg(ma->card.dev, "Enabling volume limit timeout: %ld us left\n", + (long)ktime_to_us(ma->speaker_lock_remain)); + } + + macaudio_vlimit_update(ma); + + ma->speaker_lock_timeout_enabled = true; + mutex_unlock(&ma->volume_lock_mutex); +} + +static void macaudio_vlimit_disable_timeout(struct macaudio_snd_data *ma) +{ + ktime_t now; + + mutex_lock(&ma->volume_lock_mutex); + + if (!ma->speaker_lock_timeout_enabled) { + mutex_unlock(&ma->volume_lock_mutex); + return; + } + + now = ktime_get(); + + cancel_delayed_work(&ma->lock_timeout_work); + + if (ktime_after(now, ma->speaker_lock_timeout)) + ma->speaker_lock_remain = 0; + else if (ma->speaker_lock_remain > 0) + ma->speaker_lock_remain = ktime_sub(ma->speaker_lock_timeout, now); + + dev_dbg(ma->card.dev, "Disabling volume limit timeout: %ld us left\n", + (long)ktime_to_us(ma->speaker_lock_remain)); + + macaudio_vlimit_update(ma); + + ma->speaker_lock_timeout_enabled = false; + + mutex_unlock(&ma->volume_lock_mutex); +} + +static void macaudio_vlimit_timeout_work(struct work_struct *wrk) +{ + struct macaudio_snd_data *ma = container_of(to_delayed_work(wrk), + struct macaudio_snd_data, lock_timeout_work); + ktime_t now, left; + + mutex_lock(&ma->volume_lock_mutex); + + /* + * A ping or a disabled timeout can have cancelled this work after it + * had already started running; neither must expire the lease. + */ + if (!ma->speaker_lock_timeout_enabled || !ma->speaker_lock_owner || + ma->speaker_lock_remain <= 0) + goto out; + + /* A ping renewed the lease while this work was already running */ + now = ktime_get(); + if (ktime_before(now, ma->speaker_lock_timeout)) { + left = ktime_sub(ma->speaker_lock_timeout, now); + schedule_delayed_work(&ma->lock_timeout_work, + usecs_to_jiffies(ktime_to_us(left))); + goto out; + } + + ma->speaker_lock_remain = 0; + macaudio_vlimit_update(ma); + +out: + mutex_unlock(&ma->volume_lock_mutex); +} + +static void macaudio_vlimit_update_work(struct work_struct *wrk) +{ + struct macaudio_snd_data *ma = container_of(wrk, + struct macaudio_snd_data, lock_update_work); + + /* An unlock here sets the kept volumes again: no volume write may race it */ + down_read(&ma->card.snd_card->controls_rwsem); + if (ma->bes_active) + macaudio_vlimit_enable_timeout(ma); + else + macaudio_vlimit_disable_timeout(ma); + up_read(&ma->card.snd_card->controls_rwsem); +} + +static bool macaudio_sw_gain_pcm(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card); + struct macaudio_link_props *props = &ma->link_props[rtd->dai_link->id]; + + return props->sw_gain && substream->stream == SNDRV_PCM_STREAM_PLAYBACK; +} + +static void macaudio_sw_gain_stop_work(struct work_struct *work) +{ + struct macaudio_snd_data *ma = container_of(work, struct macaudio_snd_data, + sw_gain_stop_work); + + macaudio_stop_playback(ma, true); +} + +/* + * Speaker protection ownership: "Speaker Protection", a protection engine + * in the signal path. It owns the speakers only while it is the interface + * ("Speaker Protection Interface", see macaudio_spk_iface_put()); under + * "Speaker Volume Unlock" an owner may hold the control, but nothing is + * granted and its locks and releases touch no amp. + * + * While leased, the speakers play only while a protection engine owns them. Without an * owner, or once its lease has run out, every speaker amp sits at the safe * level and no speaker playback can start: that is the hardware floor, and it * holds from the card's registration on. @@ -892,6 +1480,7 @@ static void macaudio_spk_fini(void *data) { struct macaudio_snd_data *ma = data; + cancel_delayed_work_sync(&ma->spk_unowned_work); hrtimer_cancel(&ma->spk_lease_timer); /* The expiry may queue a stop: its worker goes first */ if (!IS_ERR_OR_NULL(ma->spk_worker)) @@ -905,12 +1494,15 @@ static void macaudio_spk_fini(void *data) static int macaudio_pm_notify(struct notifier_block *nb, unsigned long action, void *data); +static void macaudio_spk_unowned_work(struct work_struct *work); + /* The lease timer, the workers and the sleep notifier, until macaudio_spk_fini() */ static int macaudio_spk_init(struct macaudio_snd_data *ma) { hrtimer_setup(&ma->spk_lease_timer, macaudio_spk_lease_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD); kthread_init_work(&ma->spk_expire_work, macaudio_spk_expire_work); + INIT_DELAYED_WORK(&ma->spk_unowned_work, macaudio_spk_unowned_work); kthread_init_work(&ma->spk_stop_work, macaudio_spk_stop_work); /* First in the chain: no other driver's sleep preparation goes before the floor */ ma->pm_nb.notifier_call = macaudio_pm_notify; @@ -950,42 +1542,326 @@ static int macaudio_pm_notify(struct notifier_block *nb, unsigned long action, ktime_t t0; s64 waited; - /* A card without speakers (the J616s jack) has nothing to floor */ - if (!ma->has_speakers) - return NOTIFY_DONE; + /* A card without speakers (the J616s jack) has nothing to floor */ + if (!ma->has_speakers) + return NOTIFY_DONE; + + switch (action) { + case PM_SUSPEND_PREPARE: + case PM_HIBERNATION_PREPARE: + /* + * Before anything that can wait, spk_mutex included: a writer + * that holds it may be stuck behind the sleep itself. No grant + * and no start from here on, and the running streams stop. + */ + WRITE_ONCE(ma->pm_quiesced, true); + macaudio_spk_close_gate(ma, "system sleep"); + t0 = ktime_get(); + mutex_lock(&ma->spk_mutex); + waited = ktime_ms_delta(ktime_get(), t0); + if (waited > 50) + dev_warn(ma->card.dev, + "speaker floor for system sleep waited %lld ms for the protection lock\n", + waited); + if (macaudio_spk_leased(ma)) + macaudio_spk_floor(ma, "system sleep"); + mutex_unlock(&ma->spk_mutex); + macaudio_vlimit_pm(ma, true); + return NOTIFY_OK; + case PM_POST_SUSPEND: + case PM_POST_HIBERNATION: + case PM_POST_RESTORE: + mutex_lock(&ma->spk_mutex); + WRITE_ONCE(ma->pm_quiesced, false); + if (ma->spk_owner) + ma->spk_lapsed = true; + mutex_unlock(&ma->spk_mutex); + macaudio_vlimit_pm(ma, false); + return NOTIFY_OK; + default: + return NOTIFY_DONE; + } +} + +/* + * The "Speaker Protection Interface" switch. + * + * At every card bind "Speaker Volume Unlock" is in charge, exactly as on a + * kernel without the lease. A CAP_SYS_ADMIN write of "Speaker Protection" + * hands the speakers to the lease, through the floor of both: the volume + * lock's ceiling first, then no speaker start, the running streams stopped, + * the lease's safe level, the amps' own gains fixed at their limit, and only + * then the ceiling lifted, with every volume still at the safe level. A + * write of "Speaker Volume Unlock", or SPEAKER_LEASE_UNOWNED_MS without an + * owner of "Speaker Protection", hands them back through the lease's floor: + * the volumes stay at the safe level under the lock's ceiling, and go up + * only once a daemon holds the lock and pings it, as after a cold bind. Its + * first ping after the switch fails with -ETIMEDOUT: the lock was lost. + * + * While leased the lock's ping fails with -EBUSY, and the speaker volumes + * and amp gains are the driver's: userspace writes fail with -EPERM. + * + * The switch is state for the boot, not a mixer setting: INACTIVE keeps + * alsactl off it. Whatever makes it persist (the protection engine's + * service) writes it again at every boot. + */ + +static const char * const macaudio_spk_iface_texts[] = { + [MACAUDIO_SPK_IFACE_UNLOCK] = "Speaker Volume Unlock", + [MACAUDIO_SPK_IFACE_LEASE] = "Speaker Protection", +}; + +static void macaudio_spk_iface_notify(struct macaudio_snd_data *ma) +{ + if (ma->spk_dead) + return; + if (ma->spk_iface_kctl) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->spk_iface_kctl->id); + if (ma->speaker_lock_kctl) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->speaker_lock_kctl->id); + if (ma->spk_kctl) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->spk_kctl->id); +} + +/* The software gain's table top: the full scale only while leased */ +static int macaudio_sw_gain_full_scale(struct macaudio_snd_data *ma, bool full) +{ + if (!ma->sw_gain_component) + return 0; + return snd_soc_component_write(ma->sw_gain_component, + MACAUDIO_SW_GAIN_REG_FULL_SCALE, full); +} + +/* + * Every amp's own gain at its limit, a fixed operating point, as the + * engine's tuning assumes. Returns 0 or a negative error. + * + * Context: spk_mutex held. + */ +static int macaudio_spk_fix_amp_gains(struct macaudio_snd_data *ma) +{ + struct snd_ctl_elem_value *uval = ma->spk_uval; + struct snd_ctl_elem_info *uinfo; + struct snd_kcontrol *kctl; + unsigned int i; + int ret = 0; + + lockdep_assert_held(&ma->spk_mutex); + + if (!ma->spk_nr_amp_gains) + return 0; + if (!uval) + return -EINVAL; + uinfo = kzalloc_obj(*uinfo); + if (!uinfo) + return -ENOMEM; + + for (i = 0; i < ma->spk_nr_amp_gains; i++) { + kctl = ma->spk_amp_gains[i]; + memset(uinfo, 0, sizeof(*uinfo)); + uinfo->id = kctl->id; + ret = kctl->info(kctl, uinfo); + if (ret < 0) + break; + memset(uval, 0, sizeof(*uval)); + uval->id = kctl->id; + uval->value.integer.value[0] = uinfo->value.integer.max; + uval->value.integer.value[1] = uinfo->value.integer.max; + ret = kctl->put(kctl, uval); + if (ret < 0) + break; + if (ret > 0) + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &kctl->id); + ret = 0; + } + if (ret < 0) + dev_err(ma->card.dev, "Failed to fix %s at its limit: %d\n", + kctl->id.name, ret); + kfree(uinfo); + return ret; +} + +/* + * Hand the speakers to "Speaker Protection". + * + * Context: the card's controls_rwsem and spk_mutex held, the card powered. + */ +static int macaudio_spk_enter_lease(struct macaudio_snd_data *ma) +{ + int ret; + + lockdep_assert_held(&ma->spk_mutex); + + if (ma->spk_dead) + return -ENODEV; + if (!ma->has_speakers || !ma->has_safety) + return -ENODEV; + if (READ_ONCE(ma->pm_quiesced)) + return -EBUSY; + if (READ_ONCE(ma->spk_floor_failed) || READ_ONCE(ma->speaker_lock_failed)) + return -EIO; + + /* The volume lock's ceiling first: whatever a daemon had unlocked goes down */ + mutex_lock(&ma->volume_lock_mutex); + cancel_delayed_work(&ma->lock_timeout_work); + ma->speaker_lock_remain = 0; + macaudio_pm_volumes_drop(ma); + macaudio_vlimit_update(ma); + if (READ_ONCE(ma->speaker_lock_failed)) { + mutex_unlock(&ma->volume_lock_mutex); + return -EIO; + } + /* No speaker start from here on: nothing is granted yet */ + WRITE_ONCE(ma->spk_iface, MACAUDIO_SPK_IFACE_LEASE); + mutex_unlock(&ma->volume_lock_mutex); + + /* What still plays stops before the amps are touched */ + kthread_queue_work(ma->spk_stop_worker, &ma->spk_stop_work); + kthread_flush_work(&ma->spk_stop_work); + + /* The lease's floor; a failed one refuses speaker playback for good */ + macaudio_spk_floor(ma, "interface switched"); + if (READ_ONCE(ma->spk_floor_failed)) + ret = -EIO; + else + ret = macaudio_spk_fix_amp_gains(ma); + if (ret) { + WRITE_ONCE(ma->spk_floor_failed, true); + dev_crit(ma->card.dev, + "speaker floor for the lease not set: speaker playback refused\n"); + macaudio_spk_iface_notify(ma); + return ret; + } + + /* The volumes stay at the safe level: the ceiling no longer applies */ + mutex_lock(&ma->volume_lock_mutex); + macaudio_vlimit_unlock(ma, true); + mutex_unlock(&ma->volume_lock_mutex); + ret = macaudio_sw_gain_full_scale(ma, true); + if (ret < 0) + dev_err(ma->card.dev, "software gain full scale not set: %d\n", ret); + + if (!ma->spk_owner) + mod_delayed_work(system_wq, &ma->spk_unowned_work, + msecs_to_jiffies(SPEAKER_LEASE_UNOWNED_MS)); + dev_info(ma->card.dev, + "Speaker protection interface: Speaker Protection (lease); Speaker Volume Unlock refused\n"); + macaudio_spk_iface_notify(ma); + return 0; +} + +/* + * Hand the speakers back to "Speaker Volume Unlock", at its floor. + * + * Context: the card's controls_rwsem and spk_mutex held. + */ +static void macaudio_spk_leave_lease(struct macaudio_snd_data *ma, const char *why) +{ + lockdep_assert_held(&ma->spk_mutex); + + if (!macaudio_spk_leased(ma)) + return; + cancel_delayed_work(&ma->spk_unowned_work); + + /* No start, the stream stopped, every amp at the safe level */ + macaudio_spk_floor_ramped(ma, why); + if (!ma->spk_dead) { + kthread_flush_work(&ma->spk_stop_work); + if (macaudio_sw_gain_full_scale(ma, false) < 0) + WRITE_ONCE(ma->spk_floor_failed, true); + } + + mutex_lock(&ma->volume_lock_mutex); + /* The lock's ceiling over the safe level; it lifts on a fresh ping only */ + if (!ma->spk_dead) + macaudio_vlimit_unlock(ma, false); + ma->speaker_volume_unlocked = false; + cancel_delayed_work(&ma->lock_timeout_work); + ma->speaker_lock_remain = 0; + ma->speaker_lock_timeout = 0; + macaudio_pm_volumes_drop(ma); + /* A daemon still holding the lock learns that it lost it */ + ma->speaker_volume_was_locked = true; + if (READ_ONCE(ma->spk_floor_failed) && !READ_ONCE(ma->speaker_lock_failed)) { + WRITE_ONCE(ma->speaker_lock_failed, true); + schedule_work(&ma->lock_fail_work); + } + if (ma->cfg->amp == AMP_MAX98360A) { + /* Samples converted at the lease's gain must not play */ + atomic_inc(&ma->sw_gain_lock_epoch); + schedule_work(&ma->sw_gain_stop_work); + } + WRITE_ONCE(ma->spk_iface, MACAUDIO_SPK_IFACE_UNLOCK); + macaudio_vlimit_update(ma); + mutex_unlock(&ma->volume_lock_mutex); + + dev_info(ma->card.dev, "Speaker protection interface: Speaker Volume Unlock (%s)\n", why); + macaudio_spk_iface_notify(ma); +} + +static void macaudio_spk_unowned_work(struct work_struct *work) +{ + struct macaudio_snd_data *ma = container_of(to_delayed_work(work), + struct macaudio_snd_data, + spk_unowned_work); + + /* The same locks as a control write, in the same order */ + down_write(&ma->card.snd_card->controls_rwsem); + mutex_lock(&ma->spk_mutex); + if (!ma->spk_owner && !ma->spk_dead) + macaudio_spk_leave_lease(ma, "no owner of Speaker Protection"); + mutex_unlock(&ma->spk_mutex); + up_write(&ma->card.snd_card->controls_rwsem); +} + +static int macaudio_spk_iface_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(macaudio_spk_iface_texts), + macaudio_spk_iface_texts); +} + +static int macaudio_spk_iface_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uvalue) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + + uvalue->value.enumerated.item[0] = READ_ONCE(ma->spk_iface); + return 0; +} + +static int macaudio_spk_iface_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *uvalue) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + unsigned int item = uvalue->value.enumerated.item[0]; + int ret; + + if (item >= ARRAY_SIZE(macaudio_spk_iface_texts)) + return -EINVAL; + /* The speakers are not a seat user's to hand over */ + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; - switch (action) { - case PM_SUSPEND_PREPARE: - case PM_HIBERNATION_PREPARE: - /* - * Before anything that can wait, spk_mutex included: a writer - * that holds it may be stuck behind the sleep itself. No grant - * and no start from here on, and the running streams stop. - */ - WRITE_ONCE(ma->pm_quiesced, true); - macaudio_spk_close_gate(ma, "system sleep"); - t0 = ktime_get(); - mutex_lock(&ma->spk_mutex); - waited = ktime_ms_delta(ktime_get(), t0); - if (waited > 50) - dev_warn(ma->card.dev, - "speaker floor for system sleep waited %lld ms for the protection lock\n", - waited); - macaudio_spk_floor(ma, "system sleep"); - mutex_unlock(&ma->spk_mutex); - return NOTIFY_OK; - case PM_POST_SUSPEND: - case PM_POST_HIBERNATION: - case PM_POST_RESTORE: - mutex_lock(&ma->spk_mutex); - WRITE_ONCE(ma->pm_quiesced, false); - if (ma->spk_owner) - ma->spk_lapsed = true; - mutex_unlock(&ma->spk_mutex); - return NOTIFY_OK; - default: - return NOTIFY_DONE; + mutex_lock(&ma->spk_mutex); + if (item == READ_ONCE(ma->spk_iface)) { + ret = 0; + } else if (item == MACAUDIO_SPK_IFACE_LEASE) { + ret = macaudio_spk_enter_lease(ma); + if (!ret) + ret = 1; + } else { + macaudio_spk_leave_lease(ma, "switched by the administrator"); + ret = 1; } + mutex_unlock(&ma->spk_mutex); + return ret; } static int macaudio_spk_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) @@ -1027,6 +1903,12 @@ static int macaudio_spk_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v goto out; } + /* "Speaker Volume Unlock" owns the speakers: nothing to grant or release */ + if (!macaudio_spk_leased(ma)) { + ret = -EBUSY; + goto out; + } + if (!ms) { ma->spk_lapsed = false; macaudio_spk_floor_ramped(ma, "released by the owner"); @@ -1103,7 +1985,10 @@ static int macaudio_spk_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_file ma->spk_owner = owner; ma->spk_lapsed = false; macaudio_spk_xover_clear(ma); - macaudio_spk_floor_ramped(ma, "new owner"); + if (macaudio_spk_leased(ma)) { + cancel_delayed_work(&ma->spk_unowned_work); + macaudio_spk_floor_ramped(ma, "new owner"); + } mutex_unlock(&ma->spk_mutex); return 0; } @@ -1117,7 +2002,13 @@ static void macaudio_spk_unlock(struct snd_kcontrol *kcontrol) ma->spk_owner = NULL; ma->spk_lapsed = false; macaudio_spk_xover_clear(ma); - macaudio_spk_floor_ramped(ma, "owner gone"); + if (macaudio_spk_leased(ma)) { + macaudio_spk_floor_ramped(ma, "owner gone"); + /* A restarting engine takes it back in time; a dead one does not */ + if (!ma->spk_dead) + mod_delayed_work(system_wq, &ma->spk_unowned_work, + msecs_to_jiffies(SPEAKER_LEASE_UNOWNED_MS)); + } mutex_unlock(&ma->spk_mutex); } @@ -1205,6 +2096,8 @@ static const struct snd_kcontrol_new macaudio_spk_xover_control = { /* ALSA serializes this with protection lock/unlock, including file close. */ static int macaudio_sense_owner_check(struct macaudio_snd_data *ma, struct snd_ctl_file *file) { + if (!macaudio_spk_leased(ma)) + return 0; return ma->spk_owner && ma->spk_owner != file ? -EPERM : 0; } @@ -1255,8 +2148,21 @@ static void macaudio_protect_sense(struct snd_soc_card *card) } /* - * The speaker volumes are the driver's: keep them, and take the write access - * away from userspace before the card is exposed. + * Speaker volumes and amp gains: the volume lock's daemon sets them under + * "Speaker Volume Unlock"; while leased they are the driver's alone. + */ +static int macaudio_spk_owned_write_check(struct snd_kcontrol *kctl, + struct snd_ctl_file *file) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kctl); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(component->card); + + return macaudio_spk_leased(ma) ? -EPERM : 0; +} + +/* + * Keep the speaker volumes, which the lease sets, and refuse userspace + * writes to them while leased (macaudio_spk_owned_write_check()). * * Context: before the card registers, or with the card's controls held. */ @@ -1265,7 +2171,7 @@ static int macaudio_spk_take_volumes(struct macaudio_snd_data *ma) const char *name = volume_control_names[ma->cfg->amp]; struct device *dev = ma->card.dev; struct snd_kcontrol *kctl; - unsigned int i, nr = 0; + unsigned int nr = 0; if (!name) return -EINVAL; @@ -1284,13 +2190,51 @@ static int macaudio_spk_take_volumes(struct macaudio_snd_data *ma) list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { if (!snd_soc_control_matches(kctl, name)) continue; - for (i = 0; i < kctl->count; i++) - kctl->vd[i].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE; + kctl->write_check = macaudio_spk_owned_write_check; ma->spk_vols[ma->spk_nr_vols++] = kctl; } return 0; } +static bool macaudio_is_amp_gain(const struct macaudio_snd_data *ma, + struct snd_kcontrol *kctl) +{ + if (ma->cfg->amp != AMP_TAS5770 && ma->cfg->amp != AMP_SN012776) + return false; + return snd_soc_control_matches(kctl, "* Amp Gain Volume") || + !strcmp(kctl->id.name, "Amp Gain Volume"); +} + +/* + * The amps' own gains ("Amp Gain Volume"): limited at fixup, theirs to set + * under "Speaker Volume Unlock", fixed at the limit while leased. + * + * Context: before the card registers. + */ +static int macaudio_spk_take_amp_gains(struct macaudio_snd_data *ma) +{ + struct device *dev = ma->card.dev; + struct snd_kcontrol *kctl; + unsigned int nr = 0; + + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) + if (macaudio_is_amp_gain(ma, kctl)) + nr++; + if (!nr) + return 0; + + ma->spk_amp_gains = devm_kcalloc(dev, nr, sizeof(*ma->spk_amp_gains), GFP_KERNEL); + if (!ma->spk_amp_gains) + return -ENOMEM; + list_for_each_entry(kctl, &ma->card.snd_card->controls, list) { + if (!macaudio_is_amp_gain(ma, kctl)) + continue; + kctl->write_check = macaudio_spk_owned_write_check; + ma->spk_amp_gains[ma->spk_nr_amp_gains++] = kctl; + } + return 0; +} + /* The item of enum control @kctl named @text, or a negative error */ static int macaudio_enum_item(struct snd_kcontrol *kctl, const char *text) { @@ -1463,11 +2407,11 @@ static bool macaudio_sn012776_levels_present(struct device *dev, return n > 0; } -static int macaudio_set_fixed_volume(struct snd_soc_card *card, const char *name, - int value); - -/* Every SN012776's "Amp Gain Volume" is fixed at its own level */ -static int macaudio_fix_sn012776_levels(struct snd_soc_card *card) +/* + * Every SN012776's "Amp Gain Volume" ends at its own level; the lease fixes + * it there (macaudio_spk_fix_amp_gains()). + */ +static int macaudio_limit_sn012776_levels(struct snd_soc_card *card) { struct snd_soc_component *component; char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; @@ -1484,10 +2428,10 @@ static int macaudio_fix_sn012776_levels(struct snd_soc_card *card) snprintf(name, sizeof(name), "%s%sAmp Gain Volume", component->name_prefix ?: "", component->name_prefix ? " " : ""); - ret = macaudio_set_fixed_volume(card, name, level); + ret = snd_soc_limit_volume(card, name, level); if (ret != 1) return dev_err_probe(card->dev, ret < 0 ? ret : -EINVAL, - "fixed level on '%s': %d\n", name, ret); + "limit on '%s': %d\n", name, ret); } return 0; } @@ -1660,6 +2604,9 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma) link_props->bclk_ratio = ma->cfg->primary_bclk_ratio; if (i == 1 && ma->cfg->secondary_bclk_ratio) link_props->bclk_ratio = ma->cfg->secondary_bclk_ratio; + if (ma->cfg->sw_gain_dai) + link_props->sw_gain = !strcmp(link->cpus[0].dai_name, + ma->cfg->sw_gain_dai); link++; link_props++; } @@ -1907,6 +2854,14 @@ static int macaudio_dpcm_hw_params(struct snd_pcm_substream *substream, rate->min = rate->max = cpu_dai->symmetric_rate; return 0; + } else { + /* + * Set the sense PCM rate control to inform userspace of the + * new sample rate. + */ + ma->speaker_sample_rate = params_rate(params); + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->speaker_sample_rate_kctl->id); } } @@ -2014,6 +2969,11 @@ static int macaudio_be_hw_free(struct snd_pcm_substream *substream) for_each_rtd_dais(rtd, i, dai) { dai->symmetric_rate = 0; } + + /* Notify userspace that the speakers are closed */ + ma->speaker_sample_rate = 0; + snd_ctl_notify(ma->card.snd_card, SNDRV_CTL_EVENT_MASK_VALUE, + &ma->speaker_sample_rate_kctl->id); } return 0; @@ -2042,7 +3002,7 @@ static bool macaudio_fe_refuses(struct macaudio_snd_data *ma, struct snd_soc_pcm struct snd_pcm_substream *substream, int cmd) { if (!ma->has_speakers || substream->stream != SNDRV_PCM_STREAM_PLAYBACK || - !macaudio_trigger_starts(cmd)) + !macaudio_trigger_starts(cmd) || !macaudio_spk_leased(ma)) return false; return macaudio_fe_drives_speakers(ma, rtd, substream->stream) && !macaudio_spk_admitted(ma); @@ -2063,12 +3023,57 @@ static int macaudio_spk_refuse(struct macaudio_snd_data *ma) * macaudio_quiet_refusals()), so ASoC fails these triggers without logging * them; each refusal is counted instead, and the next grant reports the run. */ +static int macaudio_fe_prepare(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && + READ_ONCE(ma->speaker_lock_failed)) + return -EIO; + + if (!macaudio_sw_gain_pcm(substream)) + return 0; + + if (atomic_read(&ma->sw_gain_limit_failed)) + return -EIO; + /* The CPU DAI's prepare clears the old samples out of the buffer next */ + atomic_set(&ma->sw_gain_prepared_epoch, + atomic_read(&ma->sw_gain_lock_epoch)); + return 0; +} + +/* + * Runs before the CPU DAI and the back-ends are triggered (see the + * front-end links). While leased, a speaker start without a grant is + * refused. Under the volume lock, a lock event since prepare means the + * buffer holds samples converted at the old gain, so the start is refused + * and the stream has to be prepared again. + */ static int macaudio_fe_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(rtd->card); - return macaudio_fe_refuses(ma, rtd, substream, cmd) ? macaudio_spk_refuse(ma) : 0; + if (macaudio_fe_refuses(ma, rtd, substream, cmd)) + return macaudio_spk_refuse(ma); + + /* + * A prepare can pass just before a failed lock is recorded and the + * stop work then find the stream not yet prepared: refuse its start. + */ + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && + READ_ONCE(ma->speaker_lock_failed) && macaudio_trigger_starts(cmd)) + return -EIO; + + if (!macaudio_sw_gain_pcm(substream) || !macaudio_trigger_starts(cmd)) + return 0; + + if (atomic_read(&ma->sw_gain_limit_failed) || + atomic_read(&ma->sw_gain_prepared_epoch) != + atomic_read(&ma->sw_gain_lock_epoch)) + return -EPIPE; + return 0; } /* The gate's -EPERM on every link of a card with speakers is a quiet refusal */ @@ -2099,20 +3104,29 @@ static int macaudio_be_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - return macaudio_spk_admitted(ma) ? 0 : macaudio_spk_refuse(ma); + if (macaudio_spk_leased(ma) && !macaudio_spk_admitted(ma)) + return macaudio_spk_refuse(ma); + ma->bes_active |= BIT(rtd->dai_link->id); + break; case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_STOP: - return 0; + ma->bes_active &= ~BIT(rtd->dai_link->id); + break; default: return -EINVAL; } + + /* The volume lock's lease runs only while the speakers play */ + schedule_work(&ma->lock_update_work); + return 0; } static const struct snd_soc_ops macaudio_fe_ops = { .startup = macaudio_fe_startup, .shutdown = macaudio_dpcm_shutdown, .hw_params = macaudio_fe_hw_params, + .prepare = macaudio_fe_prepare, .trigger = macaudio_fe_trigger, }; @@ -2417,10 +3431,20 @@ static int macaudio_late_probe(struct snd_soc_card *card) } } - /* The hardware floor holds from here on, before userspace sees the card */ + /* + * The volume lock's floor holds from here on, before userspace sees the + * card: "Speaker Volume Unlock" is in charge at every bind. + */ if (ma->has_speakers) { + ma->speaker_sample_rate_kctl = snd_soc_card_get_kcontrol(card, + "Speaker Sample Rate"); + ma->speaker_lock_kctl = snd_soc_card_get_kcontrol(card, + "Speaker Volume Unlock"); ma->spk_kctl = snd_soc_card_get_kcontrol(card, "Speaker Protection"); - if (!ma->spk_kctl) + ma->spk_iface_kctl = snd_soc_card_get_kcontrol(card, + "Speaker Protection Interface"); + if (!ma->speaker_sample_rate_kctl || !ma->speaker_lock_kctl || + !ma->spk_kctl || !ma->spk_iface_kctl) return -EINVAL; ret = macaudio_spk_take_volumes(ma); if (ret) @@ -2430,12 +3454,25 @@ static int macaudio_late_probe(struct snd_soc_card *card) if (ret) return dev_err_probe(card->dev, ret, "tweeter high-pass controls missing\n"); - mutex_lock(&ma->spk_mutex); - macaudio_spk_floor(ma, "card bound"); - ret = ma->spk_floor_failed ? -EIO : 0; - mutex_unlock(&ma->spk_mutex); + ret = macaudio_spk_take_amp_gains(ma); + if (ret) + return ret; + for_each_card_rtds(card, rtd) { + if (!rtd->dai_link->no_pcm && + ma->link_props[rtd->dai_link->id].sw_gain) + ma->sw_gain_component = snd_soc_rtd_to_cpu(rtd, 0)->component; + } + /* The volume table's top under the lock: the legacy ceiling */ + ret = macaudio_sw_gain_full_scale(ma, false); + if (ret < 0) + return dev_err_probe(card->dev, ret, "software gain ceiling not set\n"); + + mutex_lock(&ma->volume_lock_mutex); + macaudio_vlimit_unlock(ma, false); + ret = READ_ONCE(ma->speaker_lock_failed) ? -EIO : 0; + mutex_unlock(&ma->volume_lock_mutex); if (ret) - return dev_err_probe(card->dev, ret, "speaker safe level not set\n"); + return dev_err_probe(card->dev, ret, "speaker volume lock not set\n"); #ifdef CONFIG_DEBUG_FS debugfs_create_atomic_t("speaker_starts_refused", 0444, card->debugfs_card_root, &ma->spk_refused); @@ -2484,6 +3521,16 @@ static int macaudio_card_remove(struct snd_soc_card *card) hrtimer_cancel(&ma->spk_lease_timer); kthread_cancel_work_sync(&ma->spk_expire_work); kthread_cancel_work_sync(&ma->spk_stop_work); + cancel_delayed_work_sync(&ma->spk_unowned_work); + /* + * No back-end can trigger any more, but a lock update it queued takes + * the card's controls_rwsem: finish it while the snd_card still exists. + */ + cancel_work_sync(&ma->lock_update_work); + cancel_delayed_work_sync(&ma->lock_timeout_work); + mutex_lock(&ma->volume_lock_mutex); + macaudio_pm_volumes_drop(ma); + mutex_unlock(&ma->volume_lock_mutex); return 0; } @@ -2523,48 +3570,6 @@ static int macaudio_set_fixed_enum(struct snd_soc_card *card, const char *name, return ret; } -/* - * Hold the volumes matching @name at @value, their maximum, and take them - * away from userspace: a fixed operating point, as the protection engine's - * tuning assumes. Returns the number of controls, as snd_soc_limit_volume(). - * - * Called during control fixup, before the card is exposed to userspace. - */ -static int macaudio_set_fixed_volume(struct snd_soc_card *card, const char *name, - int value) -{ - struct snd_ctl_elem_value *uval; - struct snd_kcontrol *kctl; - int ret, hits; - - hits = snd_soc_limit_volume(card, name, value); - if (hits < 0) - return hits; - - uval = kzalloc_obj(*uval); - if (!uval) - return -ENOMEM; - list_for_each_entry(kctl, &card->snd_card->controls, list) { - if (!snd_soc_control_matches(kctl, name)) - continue; - memset(uval, 0, sizeof(*uval)); - uval->id = kctl->id; - uval->value.integer.value[0] = value; - uval->value.integer.value[1] = value; - ret = kctl->put(kctl, uval); - if (ret < 0) { - hits = ret; - break; - } - } - kfree(uval); - if (hits < 0) - return hits; - - macaudio_deny_write(card, name); - return hits; -} - #define CHECK(call, pattern, value, min) \ { \ int ret = call(card, pattern, value); \ @@ -2598,15 +3603,15 @@ static int macaudio_set_speaker(struct snd_soc_card *card, const char *prefix, b if (ma->cfg->stereo) CHECK_CONCAT(macaudio_set_fixed_enum, "ASI1 Sel", "Left"); - CHECK_CONCAT(macaudio_set_fixed_volume, "Amp Gain Volume", ma->cfg->amp_gain); + CHECK_CONCAT(snd_soc_limit_volume, "Amp Gain Volume", ma->cfg->amp_gain); break; case AMP_SN012776: if (ma->cfg->stereo) CHECK_CONCAT(macaudio_set_fixed_enum, "ASI1 Sel", "Left"); /* - * Each amp's gain is fixed at its level from the Mac's ADT - * (macaudio_fix_sn012776_levels()). The tweeters' playback + * Each amp's gain ends at its level from the Mac's ADT + * (macaudio_limit_sn012776_levels()). The tweeters' playback * high-pass starts at the protection floor; the woofers keep * the corner the amps were given from the ADT. */ @@ -2662,7 +3667,7 @@ static int macaudio_fixup_controls(struct snd_soc_card *card) macaudio_protect_sense(card); if (ma->cfg->amp == AMP_SN012776) { - int ret = macaudio_fix_sn012776_levels(card); + int ret = macaudio_limit_sn012776_levels(card); if (ret) return ret; @@ -2737,13 +3742,184 @@ static const struct snd_soc_dapm_widget macaudio_snd_widgets[] = { SND_SOC_DAPM_AIF_IN("Speaker Sense Capture", NULL, 0, SND_SOC_NOPM, 0, 0), }; +static int macaudio_sss_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = 0; + uinfo->value.integer.max = 192000; + + return 0; +} + +static int macaudio_sss_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uvalue) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + + /* + * TODO: Check if any locking is in order here. I would + * assume there is some ALSA-level lock, but DAPM implementations + * of kcontrol ops do explicit locking, so look into it. + */ + uvalue->value.integer.value[0] = ma->speaker_sample_rate; + + return 0; +} + +static int macaudio_slk_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = INT_MIN; + uinfo->value.integer.max = INT_MAX; + + return 0; +} + +static int macaudio_slk_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uvalue) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + long val = uvalue->value.integer.value[0]; + + /* + * Reads return the lock state (0 or 1), so a saved mixer state holds + * one of those. Writing it back changes nothing: only the lock owner's + * magic value renews the lease. Accept it as a no-op so that restoring + * a saved state before the daemon has taken the lock is not an error. + */ + if (val == 0 || val == 1) + return 0; + + if (val != SPEAKER_MAGIC_VALUE) + return -EINVAL; + + mutex_lock(&ma->volume_lock_mutex); + + if (!ma->speaker_lock_owner) { + mutex_unlock(&ma->volume_lock_mutex); + return -EPERM; + } + + /* "Speaker Protection" owns the speakers: no unlock to renew */ + if (macaudio_spk_leased(ma)) { + mutex_unlock(&ma->volume_lock_mutex); + return -EBUSY; + } + + /* Serves as a notification that the lock was lost at some point */ + if (ma->speaker_volume_was_locked) { + ma->speaker_volume_was_locked = false; + mutex_unlock(&ma->volume_lock_mutex); + return -ETIMEDOUT; + } + + /* Between suspend-prepare and the freeze: the lease starts again after the resume */ + if (ma->pm_quiesced) { + mutex_unlock(&ma->volume_lock_mutex); + return 0; + } + + cancel_delayed_work(&ma->lock_timeout_work); + + ma->speaker_lock_remain = ms_to_ktime(SPEAKER_LOCK_TIMEOUT); + ma->speaker_lock_timeout = ktime_add(ktime_get(), ma->speaker_lock_remain); + macaudio_vlimit_update(ma); + + if (ma->speaker_lock_timeout_enabled) { + dev_dbg(ma->card.dev, "Volume limit timeout ping: %ld us left\n", + (long)ktime_to_us(ma->speaker_lock_remain)); + schedule_delayed_work(&ma->lock_timeout_work, usecs_to_jiffies(ktime_to_us(ma->speaker_lock_remain))); + } + + mutex_unlock(&ma->volume_lock_mutex); + + return 0; +} + +static int macaudio_slk_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *uvalue) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + + uvalue->value.integer.value[0] = ma->speaker_volume_unlocked ? 1 : 0; + + return 0; +} + +static int macaudio_slk_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_file *owner) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + + mutex_lock(&ma->volume_lock_mutex); + + /* + * A lease belongs to the owner that pinged for it. Whatever the + * previous owner had left must not unlock the volume for a new one + * before it has pinged itself. + */ + cancel_delayed_work(&ma->lock_timeout_work); + ma->speaker_lock_remain = 0; + ma->speaker_lock_timeout = 0; + /* A new owner sets the volumes itself */ + macaudio_pm_volumes_drop(ma); + + ma->speaker_lock_owner = owner; + macaudio_vlimit_update(ma); + + /* + * Reset the unintended lock flag when the control is first locked. + * At this point the state is locked and cannot be unlocked until + * userspace writes to this control, so this cannot spuriously become + * true again until that point. + */ + ma->speaker_volume_was_locked = false; + + mutex_unlock(&ma->volume_lock_mutex); + + return 0; +} + +static void macaudio_slk_unlock(struct snd_kcontrol *kcontrol) +{ + struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); + struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); + + mutex_lock(&ma->volume_lock_mutex); + cancel_delayed_work(&ma->lock_timeout_work); + ma->speaker_lock_owner = NULL; + ma->speaker_lock_remain = 0; + ma->speaker_lock_timeout = 0; + macaudio_vlimit_update(ma); + mutex_unlock(&ma->volume_lock_mutex); +} + /* The speaker controls go last: a card without speakers drops them. */ -#define MACAUDIO_NUM_SPEAKER_CONTROLS 1 +#define MACAUDIO_NUM_SPEAKER_CONTROLS 4 static const struct snd_kcontrol_new macaudio_controls[] = { SOC_DAPM_PIN_SWITCH("Speaker"), SOC_DAPM_PIN_SWITCH("Headphone"), SOC_DAPM_PIN_SWITCH("Headset Mic"), + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .name = "Speaker Sample Rate", + .info = macaudio_sss_info, .get = macaudio_sss_get, + }, + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_WRITE | + SNDRV_CTL_ELEM_ACCESS_VOLATILE, + .name = "Speaker Volume Unlock", + .info = macaudio_slk_info, + .put = macaudio_slk_put, .get = macaudio_slk_get, + .lock = macaudio_slk_lock, .unlock = macaudio_slk_unlock, + }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = MACAUDIO_SPK_OWNERSHIP_ACCESS, @@ -2752,6 +3928,13 @@ static const struct snd_kcontrol_new macaudio_controls[] = { .put = macaudio_spk_put, .get = macaudio_spk_get, .lock = macaudio_spk_lock, .unlock = macaudio_spk_unlock, }, + { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = MACAUDIO_SPK_OWNERSHIP_ACCESS, + .name = "Speaker Protection Interface", + .info = macaudio_spk_iface_info, + .put = macaudio_spk_iface_put, .get = macaudio_spk_iface_get, + }, }; static const struct snd_soc_dapm_route macaudio_dapm_routes[] = { @@ -2803,8 +3986,9 @@ struct macaudio_platform_cfg macaudio_j313_cfg = { * launched on the rising SCLK edge: DSP_A with an inverted bit clock. The * speakers are one MAX98360A per channel on the "spkr" back-end, with no * sense lines and no amplifier controls; the volume is the CPU DAI's - * software gain: full scale while a protection engine owns the speakers, - * 20 dB down otherwise. The "Speaker Sense" capture is the SpeakerTap, a + * software gain, which the volume lock holds 20 dB down until a protection + * daemon takes it, and the lease 20 dB down below the full scale until its + * engine is granted. The "Speaker Sense" capture is the SpeakerTap, a * digital tap of the words the amplifier receives; there is no V/I sense. */ struct macaudio_platform_cfg macaudio_j700_cfg = { @@ -2814,6 +3998,7 @@ struct macaudio_platform_cfg macaudio_j700_cfg = { .stereo = true, .safe_vol = -20, .spk_out_widget = "Speaker", + .sw_gain_dai = "j700-pcm-1", .fe_dai_names = { "j700-pcm-0", "j700-pcm-1", "j700-pcm-2" }, .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBC_CFC | SND_SOC_DAIFMT_IB_NF, .primary_bclk_ratio = 125, @@ -3096,6 +4281,7 @@ static int macaudio_snd_platform_probe(struct platform_device *pdev) snd_soc_card_set_drvdata(card, data); dev_set_drvdata(&pdev->dev, data); mutex_init(&data->spk_mutex); + mutex_init(&data->volume_lock_mutex); card->owner = THIS_MODULE; card->driver_name = "macaudio"; @@ -3142,10 +4328,12 @@ static int macaudio_snd_platform_probe(struct platform_device *pdev) card->num_dapm_routes--; /* Admitted speakers always have a safe level (macaudio_speakers_allowed()) */ - if (!data->has_speakers) + if (!data->has_speakers) { card->num_controls -= MACAUDIO_NUM_SPEAKER_CONTROLS; - else + } else { + data->has_safety = true; macaudio_quiet_refusals(card); + } for_each_card_prelinks(card, i, link) { if (link->no_pcm) { @@ -3158,6 +4346,15 @@ static int macaudio_snd_platform_probe(struct platform_device *pdev) } } + INIT_WORK(&data->lock_update_work, macaudio_vlimit_update_work); + INIT_DELAYED_WORK(&data->lock_timeout_work, macaudio_vlimit_timeout_work); + INIT_WORK(&data->sw_gain_stop_work, macaudio_sw_gain_stop_work); + INIT_WORK(&data->lock_fail_work, macaudio_lock_fail_work); + atomic_set(&data->sw_gain_lock_epoch, 0); + atomic_set(&data->sw_gain_prepared_epoch, -1); + atomic_set(&data->sw_gain_limit_failed, 0); + data->spk_iface = MACAUDIO_SPK_IFACE_UNLOCK; + ret = macaudio_spk_init(data); if (ret) return dev_err_probe(dev, ret, "speaker protection workers not started\n"); @@ -3174,6 +4371,11 @@ static void macaudio_snd_platform_remove(struct platform_device *pdev) /* The card's removal stops the lease timer and its works; devm frees them */ snd_soc_unregister_card(&ma->card); + cancel_work_sync(&ma->lock_update_work); + cancel_delayed_work_sync(&ma->lock_timeout_work); + cancel_work_sync(&ma->sw_gain_stop_work); + cancel_work_sync(&ma->lock_fail_work); + cancel_delayed_work_sync(&ma->spk_unowned_work); } static struct platform_driver macaudio_snd_driver = { @@ -3195,6 +4397,8 @@ MODULE_LICENSE("GPL"); #include "macaudio-admission-test.h" #include "macaudio-protection-test.h" #include "macaudio-hpf-test.h" +#include "macaudio-pm-volumes-test.h" +#include "macaudio-iface-test.h" #if IS_ENABLED(CONFIG_OF_OVERLAY) #include "macaudio-amp-level-test.h" #endif diff --git a/tools/testing/selftests/alsa/macaudio-fixed-controls.py b/tools/testing/selftests/alsa/macaudio-fixed-controls.py index 12a94f6c201c3..5ca87d990c11f 100644 --- a/tools/testing/selftests/alsa/macaudio-fixed-controls.py +++ b/tools/testing/selftests/alsa/macaudio-fixed-controls.py @@ -74,8 +74,10 @@ def function(source, name): struct snd_ctl_file *spk_owner; struct snd_soc_card card; struct snd_kcontrol **spk_hpfs; unsigned int *spk_hpf_granted; unsigned int spk_nr_hpfs, spk_hpf_safe; struct snd_ctl_elem_value *spk_uval; - bool spk_granted; + bool spk_granted; int spk_iface; }; +/* MACAUDIO_SPK_IFACE_LEASE: the sense switches are the lease owner's */ +static bool macaudio_spk_leased(const struct macaudio_snd_data *ma) { return ma->spk_iface == 1; } #define GFP_KERNEL 0 #define devm_kcalloc(d, n, s, g) calloc(n, s) #define kzalloc_obj(o) calloc(1, sizeof(o)) @@ -112,8 +114,8 @@ def function(source, name): static unsigned int snd_soc_enum_item_to_val(struct soc_enum *e, unsigned int item) { return item; } static int snd_soc_component_update_bits(struct snd_soc_component *c, unsigned int r, unsigned int m, unsigned int v) { unsigned int old = c->reg; c->writes++; c->reg = (old & ~m) | (v & m); return old != c->reg; } -/* Amp gain is a fixed volume (KUnit apple-speaker-protection), not a fixed enum. */ -static int macaudio_set_fixed_volume(struct snd_soc_card *c, const char *n, int v) { return 1; } +/* Amp gain is volume-limited (KUnit apple-speaker-protection), not a fixed enum. */ +static int snd_soc_limit_volume(struct snd_soc_card *c, const char *n, int v) { return 1; } static int enum_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *i) { struct soc_enum *e = (void *)k->private_value; @@ -211,7 +213,10 @@ def function(source, name): v.id.index = j; ma.spk_owner = NULL; check(snd_ctl_elem_write(&card, &other, &v) == 0, "unowned writable", names[i]); - ma.spk_owner = &owner; + /* Under the volume lock a lease owner owns nothing */ + ma.spk_owner = &owner; ma.spk_iface = 0; + check(snd_ctl_elem_write(&card, &other, &v) == 0, "lease owner without the lease", names[i]); + ma.spk_iface = 1; unsigned int before = regs[i].writes; int rc = snd_ctl_elem_write(&card, &other, &v); check(rc == (i < 6 ? -EPERM : 0), "other file during ownership", names[i]); @@ -223,7 +228,7 @@ def function(source, name): controls[i].vd[j].owner = NULL; ma.spk_owner = NULL; check(snd_ctl_elem_write(&card, &other, &v) == 0, "after owner close", names[i]); - attempts += 5; + attempts += 6; } } /* The speaker route is fixed while protection is granted, for every file. */ From 55facfacd40df9bd8979759566a16983f8337b95 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:11:39 +1100 Subject: [PATCH 121/342] pmdomain: apple: no PS reset recovery during system sleep A power-on that stops with bit 11 latched is retried after a PS reset pulse while the domain is gated (commit a10defefab5d). The genpd noirq resume runs that power-on with the domain's DARTs and engine still in their noirq phase, and on the T8140 the recovery there hangs the machine. In a suspend loop on the J700 (12 systemd and 12 direct pm_test=platform suspends per boot, from a fresh boot), kernels with the recovery hung on 3 of 3 boots. The hw watchdog brought each one back, and no "cleared by a PS reset" line ever reached the disk. Kernels without it (fleet36, and the same tree with the recovery reverted) hung on none of 6 boots. Two of those boots latched ANE_SYS, quarantined the ANE and kept going. The freezer and devices test levels, which never power a domain off, hung on none of 6 boots with the recovery in place. This is the J700 "hang on suspend entry" seen in fleet43 suites and on aneres2. Skip the recovery while the domain is in a system sleep transition (from its suspend_late to its resume_early). The power-on then fails as before #1255. genpd ignores the error in that phase and keeps the domain requested on, and the ANE quarantines at PM_POST_SUSPEND as it did before. Runtime power-ons, including apple_pmgr_ps_cycle(), keep the recovery. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/pmdomain/apple/pmgr-pwrstate-test.c | 17 +++++++++++++++-- drivers/pmdomain/apple/pmgr-pwrstate.c | 13 +++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate-test.c b/drivers/pmdomain/apple/pmgr-pwrstate-test.c index b3a8cd1f5715c..67698ccfc74aa 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate-test.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate-test.c @@ -296,7 +296,11 @@ static void pmgr_ps_power_on_latch_cleared_test(struct kunit *test) KUNIT_EXPECT_EQ(test, r->auto_writes, 1U); } -/* The same in the noirq phase of a system sleep, where genpd ignores errors. */ +/* + * Not in the noirq phase of a system sleep (no PS reset there: it hangs the + * T8140). The power-on fails, which genpd ignores in that phase, and the + * domain stays requested on. + */ static void pmgr_ps_power_on_latch_sleep_test(struct kunit *test) { struct pmgr_ps_test_reg *r; @@ -305,9 +309,18 @@ static void pmgr_ps_power_on_latch_sleep_test(struct kunit *test) ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_PWRGATE, true, &r); ps->system_sleep = true; r->latched = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->reset_writes, 0U); + KUNIT_EXPECT_FALSE(test, r->val & APPLE_PMGR_PS_RESET); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_CLKGATE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); + + /* The same domain after the sleep: the recovery runs again. */ + ps->system_sleep = false; KUNIT_EXPECT_EQ(test, apple_pmgr_ps_power_on(&ps->genpd), 0); + KUNIT_EXPECT_EQ(test, r->reset_writes, 1U); KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_ACTIVE); - KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); } /* A latch the reset does not clear still fails, and the domain is requested off. */ diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 0c825a64b42bd..688842390a6a2 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -94,14 +94,23 @@ static int apple_pmgr_ps_wait_parent(struct apple_pmgr_ps *ps, u32 *cur) * their state there anyway), then request @reg, the on state, again. * Domains whose bit 11 means a parent that is not up yet (wait_parent) and * those with their own state contract are left alone. + * + * Never during a system sleep transition: there the power-on comes from the + * genpd noirq resume, with the DARTs and the engine of the domain still in + * their noirq phase. On the T8140 a recovery at that point hangs the machine: + * in a suspend loop on the J700, kernels with it hung on 3 of 3 boots and came + * back only through the watchdog, while kernels without it hung on none of 6, + * two of which latched ANE_SYS and carried on with the ANE quarantined. The + * power-on then fails as it did before, and genpd, which ignores errors in + * that phase, keeps the domain requested on. */ static int apple_pmgr_ps_clear_latch(struct apple_pmgr_ps *ps, u32 reg, u32 *cur) { u32 off = (reg & ~APPLE_PMGR_PS_TARGET) | APPLE_PMGR_PS_PWRGATE; int ret; - if (ps->wait_parent || ps->strict_state || ps->externally_clocked || - !(*cur & APPLE_PMGR_BUSY) || + if (ps->system_sleep || ps->wait_parent || ps->strict_state || + ps->externally_clocked || !(*cur & APPLE_PMGR_BUSY) || FIELD_GET(APPLE_PMGR_PS_ACTUAL, *cur) == APPLE_PMGR_PS_ACTIVE) return -ETIMEDOUT; From 12a3560110366df3d3ebdf81bc676e27d2d53d78 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:55:55 +1100 Subject: [PATCH 122/342] dmaengine: apple-sio: configure DisplayPort audio channels as macOS does macOS 26.6 writes a six-word record for a DisplayPort audio channel: [2, 0, 0x800, 0x600, 0x800, 0] on T6041 and [2, 0, 0x800, 0x800, 0x800, 0] on T8140. The T6041 backend sent 5 as the limit: that is the host's mailbox call timeout, not part of the record. Send 0x800, as on the earlier SoCs. Add the T8140 (MacBook Neo) SIO: its firmware reports protocol 10 and takes the T6041 boot tables and driver-owned arrays (its ADT describes the same map-range, DMA shim and device-type tables key for key); its DisplayPort audio channels refill at 0x800, as its ADT dp-audioN records say. KUnit apple-sio-t6041: the T6041 and T8140 records, and the T8140 match. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/dma/apple-sio-t6041-test.c | 22 +++++++++++++++++++++- drivers/dma/apple-sio.c | 24 +++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/dma/apple-sio-t6041-test.c b/drivers/dma/apple-sio-t6041-test.c index 1c9b1a56f8ae7..78b1f7419fc52 100644 --- a/drivers/dma/apple-sio-t6041-test.c +++ b/drivers/dma/apple-sio-t6041-test.c @@ -217,7 +217,9 @@ static void sio_t6041_config_test(struct kunit *test) .datashape = 2, .timeout = 0, .fifo = 0x800, .threshold = sio_hw_t6041.fifo_threshold, .limit = sio_hw_t6041.cfg_word4, }; - static const u32 t6041[] = { 2, 0, 0x800, 0x600, 5, 0 }; + /* macOS 26.6 DisplayPort audio records */ + static const u32 t6041[] = { 2, 0, 0x800, 0x600, 0x800, 0 }; + static const u32 t8140[] = { 2, 0, 0x800, 0x800, 0x800, 0 }; u32 words[8]; memset(words, 0xa5, sizeof(words)); @@ -225,6 +227,15 @@ static void sio_t6041_config_test(struct kunit *test) KUNIT_EXPECT_MEMEQ(test, words, t6041, sizeof(t6041)); KUNIT_EXPECT_EQ(test, words[6], 0xa5a5a5a5U); + memset(words, 0xa5, sizeof(words)); + cfg.threshold = sio_hw_t8140.fifo_threshold; + cfg.limit = sio_hw_t8140.cfg_word4; + sio_write_config(&sio_hw_t8140, words, &cfg); + KUNIT_EXPECT_MEMEQ(test, words, t8140, sizeof(t8140)); + KUNIT_EXPECT_EQ(test, words[6], 0xa5a5a5a5U); + cfg.threshold = sio_hw_t6041.fifo_threshold; + cfg.limit = sio_hw_t6041.cfg_word4; + /* The other layouts keep their five words and leave the sixth alone. */ memset(words, 0xa5, sizeof(words)); cfg.threshold = sio_hw_t6030.fifo_threshold; @@ -244,6 +255,15 @@ static void sio_t6041_match_test(struct kunit *test) break; KUNIT_ASSERT_TRUE(test, id->compatible[0] != '\0'); KUNIT_EXPECT_PTR_EQ(test, id->data, (const void *)&sio_hw_t6041); + /* T8140 takes the T6041 tables, with its own channel record */ + for (id = sio_of_match; id->compatible[0]; id++) + if (!strcmp(id->compatible, "apple,t8140-sio")) + break; + KUNIT_ASSERT_TRUE(test, id->compatible[0] != '\0'); + KUNIT_EXPECT_PTR_EQ(test, id->data, (const void *)&sio_hw_t8140); + KUNIT_EXPECT_EQ(test, sio_hw_t8140.protocol, 10U); + KUNIT_EXPECT_PTR_EQ(test, sio_hw_t8140.arrays, &sio_t6041_arrays); + KUNIT_EXPECT_TRUE(test, sio_hw_t8140.check_boot_tables == sio_t6041_check_boot_tables); KUNIT_EXPECT_EQ(test, sio_hw_t6041.protocol, 10U); KUNIT_EXPECT_TRUE(test, sio_hw_t6041.clear_period_desc); KUNIT_EXPECT_PTR_EQ(test, sio_hw_t6041.arrays, &sio_t6041_arrays); diff --git a/drivers/dma/apple-sio.c b/drivers/dma/apple-sio.c index 94c48dffb983b..e1a8ec545b8c6 100644 --- a/drivers/dma/apple-sio.c +++ b/drivers/dma/apple-sio.c @@ -621,10 +621,31 @@ static const struct sio_hw_data sio_hw_t6030 = { .check_boot_tables = sio_t6030_check_boot_tables, }; +/* + * macOS 26.6 configures a T6041 DisplayPort audio channel with + * [2, 0, 0x800, 0x600, 0x800, 0]: the limit is 0x800, as on earlier SoCs; + * the 5 of the host's mailbox call timeout is not part of the record. + */ static const struct sio_hw_data sio_hw_t6041 = { .protocol = 10, .fifo_threshold = 0x600, - .cfg_word4 = 5, /* the host's default timeout */ + .cfg_word4 = 0x800, + .cfg_six_words = true, + .clear_period_desc = true, + .arrays = &sio_t6041_arrays, + .check_boot_tables = sio_t6041_check_boot_tables, + .send_dt_params = sio_t6041_send_dt_params, +}; + +/* + * T8140 (MacBook Neo) firmware takes the T6041 boot tables (its ADT + * describes them alike); its DisplayPort audio channels refill at 0x800 + * (ADT dp-audioN dma-channels): [2, 0, 0x800, 0x800, 0x800, 0]. + */ +static const struct sio_hw_data sio_hw_t8140 = { + .protocol = 10, + .fifo_threshold = 0x800, + .cfg_word4 = 0x800, .cfg_six_words = true, .clear_period_desc = true, .arrays = &sio_t6041_arrays, @@ -634,6 +655,7 @@ static const struct sio_hw_data sio_hw_t6041 = { static const struct of_device_id sio_of_match[] = { { .compatible = "apple,t6041-sio", .data = &sio_hw_t6041 }, + { .compatible = "apple,t8140-sio", .data = &sio_hw_t8140 }, { .compatible = "apple,t6030-sio", .data = &sio_hw_t6030 }, { .compatible = "apple,sio", .data = &sio_hw_generic }, { } From d14ce94cdc25bcc1837e8da74138501c02a8e2f4 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:16:06 +1100 Subject: [PATCH 123/342] accel/ane: h16: close the channel-IRQ arm/disarm race Review of the IRQ wake found three holes: - ane_h16_irq_wait_set(false) cleared irq_armed under irq_lock but called disable_irq() after dropping it. A pause that had already seen irq_wait set could re-arm in that gap: an unbalanced enable_irq() warning, then a line left disabled while irq_armed was true, so every later wait silently fell back to its timeout. Disarm with disable_irq_nosync() under the lock, synchronize_irq() after it, and let a pause arm only when it sees irq_wait set under the same lock. - Concurrent waiters (pipelined EXECUTEs from several processes) shared one irq_fired flag, and a new waiter cleared it before an earlier one had seen it. The handler now bumps a sequence count and each waiter waits for it to move past its own snapshot. - The warm-boot resume path never turned the IRQ wait back on after power down. H16 does not take that path today; turn it on there like the cold boot does. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_h16_backend.c | 45 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/accel/ane/ane_h16_backend.c b/drivers/accel/ane/ane_h16_backend.c index 010dca71d8c07..9e0b061204a2b 100644 --- a/drivers/accel/ane/ane_h16_backend.c +++ b/drivers/accel/ane/ane_h16_backend.c @@ -70,15 +70,16 @@ struct ane_h16_device { int irq; /* * The channel IRQ (ANE_FW_IRQ_CHANNELS) as a wakeup for the polled - * waits once the firmware is up: relax() arms it before sleeping and + * waits once the firmware is up: pause() arms it before sleeping and * the handler disables it again. The transport still reads, - * acknowledges and drains every ring itself, as before. + * acknowledges and drains every ring itself, as before. irq_seq + * counts IRQs, so concurrent waiters each see their own wakeup. */ spinlock_t irq_lock; wait_queue_head_t irq_wq; bool irq_wait; bool irq_armed; - bool irq_fired; + unsigned long irq_seq; u64 irq_wakeups; u64 irq_timeouts; struct ane_fw_rtk rtk; @@ -210,19 +211,22 @@ static void ane_h16_sleep_trace(struct ane_h16_device *h, const char *when); */ static void ane_h16_irq_wait_set(struct ane_h16_device *h, bool on) { - bool disarm = false; - if (h->irq < 0 || h->boot.soc->irq_role != ANE_FW_IRQ_CHANNELS) return; + /* + * Arming and disarming both happen under irq_lock, so a pause racing + * with power down either armed before this (and is disarmed here) or + * sees irq_wait clear and polls. + */ scoped_guard(spinlock_irqsave, &h->irq_lock) { WRITE_ONCE(h->irq_wait, on); if (!on && h->irq_armed) { h->irq_armed = false; - disarm = true; + disable_irq_nosync(h->irq); } } - if (disarm) - disable_irq(h->irq); + if (!on) + synchronize_irq(h->irq); } static int ane_h16_suspend_firmware(struct ane_h16_device *h) @@ -392,8 +396,10 @@ static int ane_h16_warm_boot(struct ane_h16_device *h) return ret; ret = ane_fw_transport_check(&b->transport); h->resume_ready_ns = ktime_get_ns(); - if (!ret) + if (!ret) { + ane_h16_irq_wait_set(h, true); dev_info(h->dev, "H16 ANE: firmware resumed (warm boot); programs kept\n"); + } return ret; } @@ -1026,17 +1032,26 @@ static u64 ane_h16_now(void *ctx) static void ane_h16_irq_pause(struct ane_h16_device *h, u64 waited_ns) { unsigned int min_us, max_us; + unsigned long seq = 0; + bool armed = false; long ret; min_us = ane_fw_poll_sleep_us(waited_ns, &max_us); scoped_guard(spinlock_irqsave, &h->irq_lock) { - h->irq_fired = false; - if (!h->irq_armed) { - h->irq_armed = true; - enable_irq(h->irq); + if (h->irq_wait) { + seq = h->irq_seq; + if (!h->irq_armed) { + h->irq_armed = true; + enable_irq(h->irq); + } + armed = true; } } - ret = wait_event_hrtimeout(h->irq_wq, READ_ONCE(h->irq_fired), + if (!armed) { + ane_fw_poll_pause(waited_ns); + return; + } + ret = wait_event_hrtimeout(h->irq_wq, READ_ONCE(h->irq_seq) != seq, us_to_ktime(min_us)); scoped_guard(spinlock_irqsave, &h->irq_lock) { if (ret) @@ -1278,7 +1293,7 @@ static irqreturn_t ane_h16_irq(int irq, void *data) disable_irq_nosync(irq); h->irq_armed = false; } - WRITE_ONCE(h->irq_fired, true); + WRITE_ONCE(h->irq_seq, h->irq_seq + 1); } wake_up(&h->irq_wq); return IRQ_HANDLED; From 39204544c26bd05500d2eb444f7141c9fe3654f6 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:12:27 +1100 Subject: [PATCH 124/342] accel/ane: survive an event backlog and recover with a shared PMP SRAM On the M1 Pro (T6000), an ANE MobileNet loop plus four busy CPUs wedges the engine within a minute, and only a reboot brings it back. Two bugs make that happen. The trigger: every task of a request can post a completion event, and the poll treated more than 64 pending events on a line as a bad read and failed the request with -EIO. The linked MobileNet has 99 tasks. When the poller runs late because every CPU is busy, the backlog passes 64 (84 events were seen on line 1). Drain any count a queue can produce, and keep the bad-read check for counts no queue reaches. The wedge: recovery waits until every power domain of the ANE reads off before it powers the engine back on. Since the ANE level control (659e2cce), the M1 Pro/Max ANE also holds ps_pms_sram, the SRAM of its performance controller. That domain stays on whenever the PMP report provider is up, so the wait always timed out ('engine power-off actual=0x0 rc=-110') and every recovery failed. Domains that the ANE shares with its performance controller are not part of the engine's power state, so recovery no longer waits for them. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/accel/ane/ane_tm.c | 48 +++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/accel/ane/ane_tm.c b/drivers/accel/ane/ane_tm.c index eb157b684e0e4..f259edcf1ed6c 100644 --- a/drivers/accel/ane/ane_tm.c +++ b/drivers/accel/ane/ane_tm.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "ane_tm.h" #include "ane_pm.h" @@ -224,13 +225,21 @@ static void ane_tm_push_tq(struct ane_device *ane, struct ane_request *req) */ u32 ane_last_tmst; +/* + * Every task of a request can post an event, so a program with more tasks + * than one poll drains leaves a backlog: a delayed poller (all CPUs busy) + * saw 84 events on line 1 for a 99-task MobileNet. Only a count no queue + * can produce means the read itself is bad. + */ +#define ANE_TM_EVENTS_MAX 0x1000 + static int ane_tm_collect_events(struct ane_device *ane, struct ane_request *req, u32 *finished) { for (unsigned int line = 0; line < 2; line++) { u32 count = tm_read32(ane, TM_IRQ_EVTC(line)); - if (count > 64) + if (count > ANE_TM_EVENTS_MAX) return -EIO; for (u32 n = 0; n < count; n++) { u32 info = tm_read32(ane, TM_IRQ_INFO(line)); @@ -419,6 +428,32 @@ static int ane_ps_verify_on(struct ane_device *ane) return err; } +/* + * A power domain the ANE shares with its performance controller (the T600x + * PMP report SRAM, ps_pms_sram) stays on for as long as the controller is + * up, whatever the ANE does, so it is no part of the engine's power state. + */ +static bool ane_pd_is_perf_supply(struct ane_device *ane, int index) +{ + struct device_node *report = ane->perf.report; + struct of_phandle_args pd, rp; + bool shared = false; + + if (!report || of_parse_phandle_with_args(ane->dev->of_node, "power-domains", + "#power-domain-cells", index, &pd)) + return false; + for (int i = 0; !shared; i++) { + if (of_parse_phandle_with_args(report, "power-domains", + "#power-domain-cells", i, &rp)) + break; + shared = rp.np == pd.np && rp.args_count == pd.args_count && + !memcmp(rp.args, pd.args, pd.args_count * sizeof(pd.args[0])); + of_node_put(rp.np); + } + of_node_put(pd.np); + return shared; +} + static bool ane_partitions_off(struct ane_device *ane) { if (ane_ps_act(ane)) @@ -432,7 +467,8 @@ static bool ane_partitions_off(struct ane_device *ane) if (ane->pd_count == 1) return !dev_pm_genpd_is_on(ane->dev); for (int i = 0; i < ane->pd_count; i++) - if (dev_pm_genpd_is_on(ane->pd_dev[i])) + if (dev_pm_genpd_is_on(ane->pd_dev[i]) && + !ane_pd_is_perf_supply(ane, i)) return false; return true; } @@ -480,8 +516,8 @@ static int ane_pd_cycle(struct ane_device *ane) * Two things must go, or the retained TM never reads idle again: * - pending events on both IRQ lines. Each event pops by reading * INFO/UNK1/TMST/UNK2, exactly as ane_tm_collect_events pops them; - * a stale backlog (or one over the 64-entry collect cap) would make - * the next submit's completion poll miss or fail. + * a stale backlog would make the next submit's completion poll + * miss its events. * - the latched queue entry of the dead task. TQ_STATUS/NID1 get the * same clear the normal completion path gives a finished queue. */ @@ -501,8 +537,8 @@ static void ane_tm_drain_retained(struct ane_device *ane) u32 count = tm_read32(ane, TM_IRQ_EVTC(line)); u32 n; - if (count > 64) - count = 64; + if (count > ANE_TM_EVENTS_MAX) + count = ANE_TM_EVENTS_MAX; for (n = 0; n < count; n++) { tm_read32(ane, TM_IRQ_INFO(line)); tm_read32(ane, TM_IRQ_UNK1(line)); From 6546b58683ada4332bac9de9fc5a24354bb5e35b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:46:51 +1100 Subject: [PATCH 125/342] arm64: dts: apple: t8112: match the ISP and DPA1 power states to the ADT The M2 ADT gates the ISP on ISPSENS0-3 in addition to the ISP_SYS and ISP set domains, but the ISP node did not list them, so genpd switched them off as unused at boot and never turned them on for a capture. List them after the existing domains. The ISP driver powers every secondary domain with the firmware and drops them when it stops, so they follow the camera like the other ISP domains do. The T6030 and T6040 ISP nodes already carry ps_ispsens0. The ADT marks DPA1 critical (iBoot leaves it on and macOS never gates it). Every other critical T8112 power state is apple,always-on in the DT, except PMP, which is deliberately left to its consumers. Mark ps_dpa1 always-on to match. Found by the DTCOVER ADT/DT coverage audit of the M2 (J413). Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8112-pmgr.dtsi | 1 + arch/arm64/boot/dts/apple/t8112.dtsi | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi index 9ff4ed911d482..e2564eac95e50 100644 --- a/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-pmgr.dtsi @@ -455,6 +455,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "dpa1"; + apple,always-on; power-domains = <&ps_audio_p>; }; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index f9ead58538938..3b733a4e61b1b 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -731,7 +731,9 @@ <&ps_isp_set4>, <&ps_isp_set5>, <&ps_isp_set6>, <&ps_isp_set7>, <&ps_isp_set8>, <&ps_isp_set9>, <&ps_isp_set10>, <&ps_isp_set11>, - <&ps_isp_set12>; + <&ps_isp_set12>, <&ps_ispsens0>, + <&ps_ispsens1>, <&ps_ispsens2>, + <&ps_ispsens3>; apple,dart-vm-size = <0x0 0xa0000000>; status = "disabled"; From 048819f3e28c2c3be9f853bab74e710d9cce82e5 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:47:23 +1100 Subject: [PATCH 126/342] arm64: dts: apple: t6040-j616s: give the external display chains their PMGR parents Check the J616s PMGR power states against the ADT's device list: - DISPEXT0_SYS has two parents, FAB2_SOC and the DISPEXT rail. The DT had only the rail (the PMP report pmp-dispext0). It worked because ATC0..2_COMMON keep FAB2_SOC on. List both, as DISPEXT1_SYS already does. - FAB7_SOC's parent is AFI, as t6040-pmgr.dtsi describes it. The extdisp-usbc override moved it under FAB6_SOC because it misread the pmgr record (id2 134 is DISPEXT1_SYS; FAB7_SOC is 133). Drop the override and fix the comment. Both fabrics are always-on, so nothing changes at runtime. The power tree now matches the ADT. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../boot/dts/apple/t6040-j616s-extdisp-hdmi.dtsi | 3 ++- .../boot/dts/apple/t6040-j616s-extdisp-usbc.dtsi | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-hdmi.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-hdmi.dtsi index 0e4e59ca5bb3a..3213c6e8f615a 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-hdmi.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-hdmi.dtsi @@ -32,8 +32,9 @@ }; }; +/* ADT DISPEXT0_SYS parents: FAB2_SOC and the DISPEXT rail (PMP request). */ &ps_dispext0_sys { - power-domains = <&pmp_dispext0>; + power-domains = <&ps_fab2_soc>, <&pmp_dispext0>; }; &ps_dispext0_cpu { diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-usbc.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-usbc.dtsi index 47995f1bc8e7b..1bffe53b5ec83 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-usbc.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-extdisp-usbc.dtsi @@ -23,15 +23,10 @@ }; /* - * DISPEXT1_SYS sits on FAB7_SOC (ADT pmgr device id2 134, pmgr_aux 0x488, parent - * FAB6_SOC, off at boot), which t604x-pmgr.dtsi does not describe. m4.62 enabled - * DISPEXT1_SYS without it and the first DCPEXT1 register access (its DART) reset - * the SoC. DISPEXT0_SYS's parent FAB2_SOC is on anyway through ATC0..2_COMMON. + * DISPEXT1_SYS sits on FAB7_SOC (ADT pmgr id2 133, parent AFI as described + * in t6040-pmgr.dtsi, off at boot). m4.62 enabled DISPEXT1_SYS without it + * and the first DCPEXT1 register access (its DART) reset the SoC. */ -&ps_fab7_soc { - power-domains = <&ps_fab6_soc>; -}; - &ps_dispext1_sys { power-domains = <&ps_fab7_soc>, <&pmp_dispext1>; }; From 7764b26a7002e37f61b810d99c3b7154f391846f Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:47:24 +1100 Subject: [PATCH 127/342] arm64: dts: apple: t6040-j616s: keep the SIO's SPI, UART and DPA parents on The SIO firmware drives the SPI, UART and DP audio shims. On T8140 it crashes at boot if SPI_P and UART_P are off, and T6000 and T8112 make those states parents of SIO_CPU for that reason. On the J616s, SIO_CPU had only SIO as its parent, as in the ADT. SPI_P stayed on only because the QSPI controller never runtime-suspends, and UART_P was not described at all, so it stayed however iBoot left it. Make SPI_P, UART_P and DPA_P parents of SIO_CPU and describe UART_P. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi index 597feaa71ac51..e406a733c350d 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-j616s-dpaudio.dtsi @@ -86,7 +86,19 @@ }; }; +/* + * The SIO firmware drives the SPI, UART and DP audio shims, so keep their + * parents on while it runs, as on T6000, T8112 and T8140. The ADT lists + * only SIO as SIO_CPU's parent. Without this, SPI_P stays on only because + * the QSPI controller never runtime-suspends, and UART_P is left as iBoot + * set it; a T8140 SIO with SPI_P/UART_P off crashes at boot. + */ &ps_sio_cpu { + power-domains = <&ps_sio>, <&ps_spi_p>, <&ps_uart_p>, <&ps_dpa_p>; + status = "okay"; +}; + +&ps_uart_p { status = "okay"; }; From b24975d20e36fc24f909b074e2ca27f9eb8b55c5 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:47:24 +1100 Subject: [PATCH 128/342] arm64: dts: apple: t6040-j616s: describe the internal PCIe power states The ADT's apcie0 needs APCIE_GP, APCIE_SYS_GP and APCIE_PHY_SW on top of ANS and APCIE_ST0/1 and APCIE_SYS_ST0/1, which are always-on. The DT had the first three disabled and gave pcie0 no power domain, so Linux relied on iBoot leaving them on. pcie-apple keeps the internal links up through suspend-to-idle and does not retrain them after a power cycle, so describe the three states as always-on and give pcie0 APCIE_SYS_GP, whose chain covers APCIE_GP, FAB3_SOC and AFC. Gating these states would need multi-domain support in pcie-apple, with a cold restart of the port on resume. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index 0d7c60454d480..c263d1da558cc 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -280,3 +280,30 @@ &usb4_2_nhi { status = "okay"; }; + +/* + * The internal PCIe controller (Wi-Fi/Bluetooth, SD reader) needs APCIE_GP, + * APCIE_SYS_GP and APCIE_PHY_SW on top of the always-on ANS/APCIE_ST* + * states (ADT apcie0 clock-gates). iBoot leaves them on. The driver keeps + * internal links up through suspend-to-idle and cannot retrain them after + * a power cycle, so describe them as always-on: Linux now holds what it + * needs instead of relying on iBoot's state. + */ +&ps_apcie_gp { + apple,always-on; + status = "okay"; +}; + +&ps_apcie_sys_gp { + apple,always-on; + status = "okay"; +}; + +&ps_apcie_phy_sw { + apple,always-on; + status = "okay"; +}; + +&pcie0 { + power-domains = <&ps_apcie_sys_gp>; +}; From 0064b755c8de0abbe83cd2d2d97b35ba9260a95d Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:52:08 +1100 Subject: [PATCH 129/342] arm64: dts: apple: j316s, j413: enable the AOP accelerometer and gyroscope The bootloader now hands the accelerometer and gyroscope calibration of the M1 Pro (J316s) and M2 (J413) to the OS, as on the M4 Pro (aura#124). The ADT carries it on both machines in the same properties and format. Without it the aop_motion driver leaves the sensors off. Drop the disabled status from both service children. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6000-j316s.dts | 2 -- arch/arm64/boot/dts/apple/t8112-j413.dts | 2 -- 2 files changed, 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000-j316s.dts b/arch/arm64/boot/dts/apple/t6000-j316s.dts index 5fca6c4d4a8c9..453c383052f75 100644 --- a/arch/arm64/boot/dts/apple/t6000-j316s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j316s.dts @@ -75,12 +75,10 @@ &aop { accel { compatible = "apple,t6000-aop-accel", "apple,aop-accel"; - status = "disabled"; }; gyro { compatible = "apple,t6000-aop-gyro", "apple,aop-gyro"; - status = "disabled"; }; }; diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 6bea58173d2ab..a0f597d47f609 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -187,12 +187,10 @@ accel { compatible = "apple,t8112-aop-accel", "apple,aop-accel"; - status = "disabled"; }; gyro { compatible = "apple,t8112-aop-gyro", "apple,aop-gyro"; - status = "disabled"; }; }; From f709f16b15347aaf3edeff3298b6207bc5790eee Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:57:20 +1100 Subject: [PATCH 130/342] arm64: dts: apple: t600x: power the ISP sensor domains with the ISP The T600x ISP reaches its camera sensor interfaces through the four ISPSENS power states, and the Apple device tree gates them together with the ISP. The ISP node did not list them, so the ISPSENS domains had no consumer and stayed off while the camera ran. Append them to the ISP power-domains, as the T6041 ISP already does for its sensor domain. The driver keeps the first domain as its runtime PM link and switches the others on in order when the firmware boots, so the sensor domains come up last and go down first. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t600x-die0.dtsi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi index 63da88e035da3..cd50cd66cff39 100644 --- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi @@ -1013,7 +1013,9 @@ #endif <&ps_isp_set1>, <&ps_isp_fe>, <&ps_isp_set3>, <&ps_isp_set4>, <&ps_isp_set5>, <&ps_isp_set6>, - <&ps_isp_set7>, <&ps_isp_set8>; + <&ps_isp_set7>, <&ps_isp_set8>, + <&ps_ispsens0>, <&ps_ispsens1>, + <&ps_ispsens2>, <&ps_ispsens3>; apple,dart-vm-size = <0x0 0xa0000000>; status = "disabled"; From fb559cd5348d76e904b4683bc1e1f4a2fb2ae647 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:57:20 +1100 Subject: [PATCH 131/342] arm64: dts: apple: t600x-j314-j316: disable the PCIe-C tunnel on ATC3 On the 14-inch and 16-inch MacBook Pro the fourth Type-C PHY (ATC3) only drives the HDMI port. It has no USB4 controller (the board already drops usb4_3_acio), so there is no PCIe-C root complex or DART behind it, and the Apple device tree describes none. The USB DARTs on ATC3 are disabled for the same reason; mark apciec3 and its DART disabled too, so the DT describes only hardware that exists. No runtime change: nothing could reach these nodes without a port 3 USB4 controller. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi index 8055596720149..9dbbcd52d4ec4 100644 --- a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi @@ -744,6 +744,15 @@ status = "disabled"; }; +/* ATC3 has no USB4/Thunderbolt, so there is no PCIe-C tunnel behind it either */ +&apciec3_dart { + status = "disabled"; +}; + +&apciec3 { + status = "disabled"; +}; + &dwc3_3 { status = "disabled"; }; From 6fc482823a8348ac36486e14bf54787805df47aa Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:57:21 +1100 Subject: [PATCH 132/342] arm64: dts: apple: t6000: drop power states the M1 Pro does not have T6000 is a cut-down T6001. The Apple device tree for T6000 lists the AFNC3 fabric controllers and the USB-A AON domain as always on with no power state register, so the PMGR does not switch them. Disable the power-controller nodes inherited from the T6001 dtsi, so Linux does not manage them as switchable domains on this die. Nothing on T6000 uses these domains. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 6c5e086626bda..d4bd9a56fbc6e 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -91,6 +91,26 @@ <&ps_ane_set2>, <&ps_ane_set3>, <&ps_ane_set4>, <&ps_pms_sram>; }; +/* + * T6000 has no power state registers for the AFNC3 fabric controllers or + * the USB-A AON domain: they are always on without a PMGR switch. + */ +&ps_afnc3_ioa { + status = "disabled"; +}; + +&ps_afnc3_ls { + status = "disabled"; +}; + +&ps_afnc3_lw0 { + status = "disabled"; +}; + +&ps_gp_usb_aon { + status = "disabled"; +}; + #include "t6000-peripherals.dtsi" #include "t6000-aux-spmi.dtsi" From 895c1acc38981a663f2c9c8f8ca5618c0f3a5022 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:00:00 +1100 Subject: [PATCH 133/342] soc: apple: vote GPU activity to the PMP so memory leaves idle DVFS on t600x GPU reads on the M1 Max (t6001) top out at 241 GB/s on Linux; macOS reads 361 GB/s. Bit 9 of the PMP report PS-REQ word is the AGX power request: with it clear the PMP ignores the GPU bandwidth demand and keeps memory at its idle floor. With it set the same read microbenchmark reaches 368 GB/s. The GPU driver reports operations in flight with apple_pmp_agx_activity_begin()/end(). pmp-report sets bit 9 when the first operation starts and clears it 250 ms (pmp_report.agx_vote_idle_ms) after the last one ends, at GPU unbind, across system sleep and when the report goes away. A set that is not acknowledged is cleared and retried after a second; a PMP that does not run gets no write. The decisions are plain functions in pmp-agx-vote.h, covered by a host test suite with mutant controls (tools/asahi/pmp-agx-vote-tests.*). apple_pmp_report_set_request() is a locked, acknowledged update of one PS-REQ bit for clients outside this driver; it refuses the AGX bit on t600x so the vote stays its only writer. Off by default (pmp_report.agx_vote), apple,t6001 only. This is omacom/linux-aurora#334 (head b36d0192f408) squashed onto aurora-silicon integration/aurora; conflicts in the GPU unbind signature, the pmp-report.h stubs and bindings_helper.h resolved keeping both sides. The aurora-ci host-tests.json registration is left out (no such file here). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/gpu/drm/asahi/driver.rs | 6 + drivers/gpu/drm/asahi/gpu.rs | 5 + drivers/pmdomain/apple/pmp-agx-vote.h | 174 ++++++++++ drivers/pmdomain/apple/pmp-report.c | 292 ++++++++++++++++ include/linux/soc/apple/pmp-report.h | 37 ++ rust/bindings/bindings_helper.h | 1 + tools/asahi/pmp-agx-vote-tests.c | 474 ++++++++++++++++++++++++++ tools/asahi/pmp-agx-vote-tests.py | 130 +++++++ tools/asahi/t6030-pmp-graph-tests.c | 4 + 9 files changed, 1123 insertions(+) create mode 100644 drivers/pmdomain/apple/pmp-agx-vote.h create mode 100644 tools/asahi/pmp-agx-vote-tests.c create mode 100755 tools/asahi/pmp-agx-vote-tests.py diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index 93c52f1de9968..f3707ec05066a 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -238,6 +238,9 @@ impl platform::Driver for AsahiPlatformDriver { type Data<'bound> = AsahiPlatformDriverData<'bound>; fn unbind<'bound>(_pdev: &'bound platform::Device>, this: Pin<&Self::Data<'bound>>) { + // SAFETY: Takes no arguments, process context. Clears the T6001 AGX request in the PMP report if the pmp_report.agx_vote + // parameter set it; a no-op everywhere else. + unsafe { bindings::apple_pmp_agx_activity_release() }; if let Some(gpu) = this.g17.as_ref() { // Driver data is dropped after devres, so CPU control must happen in unbind. gpu.shutdown(); @@ -253,6 +256,9 @@ impl platform::Driver for AsahiPlatformDriver { debug::update_debug_flags(); crate::memacct::LEDGER.configure(); + // SAFETY: Takes no arguments, process context. Lets the T6001 AGX vote run again after an earlier unbind released it; a no-op everywhere else. + unsafe { bindings::apple_pmp_agx_activity_resume() }; + dev_info!(pdev.as_ref(), "Probing...\n"); let cfg = match info.ok_or(ENODEV)? { diff --git a/drivers/gpu/drm/asahi/gpu.rs b/drivers/gpu/drm/asahi/gpu.rs index 42fd1cb680adc..0a7a3e6ce065b 100644 --- a/drivers/gpu/drm/asahi/gpu.rs +++ b/drivers/gpu/drm/asahi/gpu.rs @@ -1276,6 +1276,9 @@ impl GpuManager::ver { .with(|raw, _inner| raw.pending_submissions.fetch_add(1, Ordering::Acquire)); mod_dev_dbg!(self.dev, "OP start (pending: {})\n", val + 1); + // SAFETY: Takes no arguments and does nothing unless pmp_report.agx_vote is set on a T6001. The matching end call is made + // by OpGuard's Drop, and the guard is created right below, so every path out of here (including a failed kick) pairs it. + unsafe { kernel::bindings::apple_pmp_agx_activity_begin() }; let guard = OpGuard(self.clone()); self.kick_firmware()?; Ok(guard) @@ -1801,5 +1804,7 @@ impl GpuManagerPriv for GpuManager::ver { .with(|raw, _inner| raw.pending_submissions.fetch_sub(1, Ordering::Release)); mod_dev_dbg!(self.dev, "OP end (pending: {})\n", val - 1); + // SAFETY: Pairs with the begin call in start_op(); callable from any context. + unsafe { kernel::bindings::apple_pmp_agx_activity_end() }; } } diff --git a/drivers/pmdomain/apple/pmp-agx-vote.h b/drivers/pmdomain/apple/pmp-agx-vote.h new file mode 100644 index 0000000000000..9a1f9ecebec7f --- /dev/null +++ b/drivers/pmdomain/apple/pmp-agx-vote.h @@ -0,0 +1,174 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * When the T6001 AGX request (PS-REQ bit 9 of the PMP report) is set and cleared. + * + * The GPU driver counts operations in flight (begin/end). The request is set when the first operation starts and cleared + * idle_ms after the last one ends, so a decode stream (a burst every ~10 ms) holds one vote and an idle GPU drops it. All state + * changes are in these functions; the caller serializes them with one spinlock and does the register write between + * agx_vote_decide() and agx_vote_applied(). Times are milliseconds from any wrapping clock. + */ +#ifndef PMP_AGX_VOTE_H +#define PMP_AGX_VOTE_H + +#ifdef __KERNEL__ +#include +/* jiffies_to_msecs() returns u32: the clock wraps every 49.7 days, and every compare below is done in 32 bits. */ +typedef u32 agx_ms_t; +typedef s32 agx_sms_t; +#else +#include +#include +typedef uint32_t agx_ms_t; +typedef int32_t agx_sms_t; +#endif + +/* How long the request is held after the last operation ends. w7X measured idle gaps of up to 111.5 ms inside one 9B generation, so 100 ms + * was not enough; 250 ms is about 2.2 times the largest gap seen. The parameter pmp_report.agx_vote_idle_ms overrides it at run time. */ +#define AGX_VOTE_IDLE_MS_DEFAULT 250 + +/* After a set that was not acknowledged (or a PMP that is not running), wait this long before trying again. */ +#define AGX_VOTE_RETRY_MS 1000 + +struct agx_vote { + bool enabled; /* the module parameter */ + bool voted; /* bit 9 is set and was acknowledged */ + bool stopped; /* released (GPU unbind, report removal, sleep): no new vote until agx_vote_resume() */ + unsigned int users; /* GPU operations in flight */ + agx_ms_t idle_ms; /* keep the vote this long after the last operation ends */ + agx_ms_t idle_at; /* when users last fell to 0 */ + unsigned int failures; /* consecutive failed sets; the backoff applies only while this is nonzero */ + agx_ms_t retry_at; /* with failures: no new set before this */ +}; + +enum agx_vote_action { + AGX_VOTE_NONE, + AGX_VOTE_SET, + AGX_VOTE_CLEAR, +}; + +static inline bool agx_vote_reached(agx_ms_t now, agx_ms_t t) +{ + return (agx_sms_t)(now - t) >= 0; +} + +/* A retry deadline more than one backoff window in the future cannot be real: an idle gap beyond half the + * 32-bit millisecond range makes the wrapped arithmetic read an expired deadline as future. Treat it as expired. */ +static inline bool agx_vote_retry_reached(const struct agx_vote *v, agx_ms_t now) +{ + return agx_vote_reached(now, v->retry_at) + || (agx_ms_t)(v->retry_at - now) > AGX_VOTE_RETRY_MS; +} + +/* An operation starts. now is the operation's start time in ms (any wrapping clock; the caller reads it + * under its lock). Returns the delay in ms until the reconcile step must run, in the same terms as + * agx_vote_end(): 1 runs it now, 0 means nothing is pending. A begin during a failed-set backoff returns 0 + * because next() already arms the retry from the failure state, and the caller's queueing can only pull a + * deadline earlier, never push it out; it returns 1 once the deadline has passed. */ +static inline agx_ms_t agx_vote_begin(struct agx_vote *v, agx_ms_t now) +{ + v->users++; + if (!v->enabled || v->stopped) + return 0; + if (v->voted) + return 0; + return (!v->failures || agx_vote_retry_reached(v, now)) ? 1 : v->retry_at - now; +} + +/* An operation ends. Returns the delay in ms after which the reconcile step must run, 0 when none is needed. */ +static inline agx_ms_t agx_vote_end(struct agx_vote *v, agx_ms_t now) +{ + if (!v->users) /* unbalanced end: ignored */ + return 0; + if (--v->users) + return 0; + v->idle_at = now; + if (!v->enabled || !v->voted) + return 0; + return v->idle_ms ? v->idle_ms : 1; +} + +/* What the reconcile step must do now. */ +static inline enum agx_vote_action agx_vote_decide(const struct agx_vote *v, agx_ms_t now) +{ + if (!v->enabled || v->stopped) + return v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE; + if (v->users) + return !v->voted && (!v->failures || agx_vote_retry_reached(v, now)) ? AGX_VOTE_SET : AGX_VOTE_NONE; + if (v->voted && agx_vote_reached(now, v->idle_at + v->idle_ms)) + return AGX_VOTE_CLEAR; + return AGX_VOTE_NONE; +} + +/* + * Delay in ms until the reconcile step must run again, 0 when no timer is needed. 1 when work is due now: an + * operation began while a clear was being written (begin saw voted still true and did not kick), or an end + * landed inside the SET write so the vote is set with an already-reached idle deadline. The caller must run the + * reconcile those cases would otherwise skip; it cannot read 1 as "nothing pending". + */ +static inline agx_ms_t agx_vote_next(const struct agx_vote *v, agx_ms_t now) +{ + agx_ms_t at; + + if (!v->enabled || v->stopped) + return 0; + if (v->users && !v->voted && !v->failures) + return 1; + if (v->users && !v->voted && v->failures) + at = agx_vote_retry_reached(v, now) ? now : v->retry_at; + else if (!v->users && v->voted) + at = v->idle_at + v->idle_ms; + else if (!v->users && !v->voted && v->failures) + /* The write outlasted the operation: arm the retry from the failure state + * itself. The caller clears failures when this reconcile finds nobody waiting + * (decide returns NONE), so it fires once. */ + at = agx_vote_retry_reached(v, now) ? now : v->retry_at; + else + return 0; + /* An already-reached deadline returns 1: there is work, due now. The SET-write race leaves exactly + * this state (voted, no user, deadline passed), and 0 here would strand the vote set forever. */ + return agx_vote_reached(now, at) ? 1 : at - now; +} + +/* Record the outcome of the register write for `action` (ret 0: acknowledged). */ +static inline void agx_vote_applied(struct agx_vote *v, enum agx_vote_action action, int ret, agx_ms_t now) +{ + if (action == AGX_VOTE_SET) { + if (ret) { + v->failures++; + v->retry_at = now + AGX_VOTE_RETRY_MS; + } else { + v->voted = true; + v->failures = 0; + } + } else if (action == AGX_VOTE_CLEAR) { + v->voted = false; /* the write was made; the caller logs an unacknowledged clear */ + } +} + +/* + * The GPU driver unbinds, the report goes away, or the system sleeps: drop the vote now and refuse new ones. True when bit 9 is set and the caller must + * write the clear. An operation that begins afterwards (an ioctl already past the unplug check) counts as a user but does not vote. + */ +static inline bool agx_vote_release(struct agx_vote *v) +{ + bool was_voted = v->voted; + + v->voted = false; + v->stopped = true; + return was_voted; +} + +/* Refuse new votes without touching the one that is set (the first step of a release, before the work item is waited out). */ +static inline void agx_vote_refuse(struct agx_vote *v) +{ + v->stopped = true; +} + +/* The GPU probes (or the report comes back, or the system resumes): votes are allowed again. True when work is already in flight and the caller must run the reconcile step. */ +static inline bool agx_vote_resume(struct agx_vote *v) +{ + v->stopped = false; + return v->enabled && v->users && !v->voted; +} + +#endif /* PMP_AGX_VOTE_H */ diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index b3dceb84afa5a..c61ab5c41b7a5 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -28,10 +28,12 @@ #include #include #include +#include #include #include #include +#include "pmp-agx-vote.h" #include "pmp-report-validation.h" #include "pmp-dram.h" #include "pmp-ane.h" @@ -152,6 +154,19 @@ static const struct attribute_group apple_pmp_dram_group = { }; static const struct apple_pmp_report_offsets apple_pmp_offsets_t6030; +static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x; + +/* T6001 AGX request (see the engine below set_state): AGX is soc-device record 9 on the T6001. */ +#define APPLE_PMP_T6001_AGX_ID 9 +static bool agx_vote; +static struct agx_vote apple_pmp_agx_vote_state = {.idle_ms = AGX_VOTE_IDLE_MS_DEFAULT}; +static DEFINE_SPINLOCK(apple_pmp_agx_vote_lock); +/* Serializes the vote work, the unbind release and the report's removal. */ +static DEFINE_MUTEX(apple_pmp_agx_vote_mutex); +static void apple_pmp_agx_vote_fn(struct work_struct *work); +static DECLARE_DELAYED_WORK(apple_pmp_agx_vote_work, apple_pmp_agx_vote_fn); +static void apple_pmp_agx_vote_stop(void); +static void apple_pmp_agx_vote_stop_new(void); /* Bound report regions, protected by RCU until managed teardown drains readers. */ static LIST_HEAD(apple_pmp_reports); @@ -376,6 +391,12 @@ static void apple_pmp_report_release(void *data) cancel_delayed_work_sync(&rep->ready_work); /* Withdraw child providers while their power callbacks can still use MMIO. */ of_platform_depopulate(rep->dev); + if (rep->offsets == &apple_pmp_offsets_t600x) { + apple_pmp_agx_vote_stop_new(); + cancel_delayed_work_sync(&apple_pmp_agx_vote_work); + guard(mutex)(&apple_pmp_agx_vote_mutex); + apple_pmp_agx_vote_stop(); + } mutex_lock(&apple_pmp_reports_lock); if (!list_empty(&rep->list)) list_del_rcu(&rep->list); @@ -1370,6 +1391,10 @@ static int apple_pmp_report_probe(struct platform_device *pdev) list_add_tail_rcu(&rep->list, &apple_pmp_reports); mutex_unlock(&apple_pmp_reports_lock); + /* A report that comes back (rebind) takes votes again; its removal refused them. */ + if (rep->offsets == &apple_pmp_offsets_t600x) + apple_pmp_agx_activity_resume(); + if (rep->offsets->fast_die || rep->start) rep->debugfs = debugfs_create_file(dev_name(dev), 0400, apple_pmp_report_debugfs, rep, @@ -1586,6 +1611,224 @@ static int apple_pmp_report_set_state(struct apple_pmp_report *rep, u32 id, 50000); } +/* + * T6001 AGX request. T2 showed that setting PS-REQ bit 9 (AGX, soc-device record 9) lifts the GPU read roof from 241 to 368 GB/s: the PMP + * leaves memory at its idle floor for a GPU that is busy but has not asked. The GPU driver reports operations in flight + * (apple_pmp_agx_activity_begin/end); the request is set while any operation runs and cleared agx_vote_idle_ms after the last one ends, at + * GPU unbind and when this report goes away. The decisions are in pmp-agx-vote.h (unit tested); this is the glue. + * Off by default (pmp_report.agx_vote): with it off nothing is written. + */ +static unsigned int agx_vote_idle_ms = AGX_VOTE_IDLE_MS_DEFAULT; + +static agx_ms_t apple_pmp_agx_now_ms(void) +{ + return jiffies_to_msecs(jiffies); +} + +/* + * Queue the reconcile step. agx_vote=1 on the kernel command line runs the parameter setter from parse_args(), before workqueue_init_early() has + * created system_dfl_wq; queueing on the NULL workqueue would oops in start_kernel(). Nothing is owed then: begin() and the work function read the + * parameter themselves, so the first GPU operation kicks. + */ +static void apple_pmp_agx_vote_kick(unsigned long delay_ms) +{ + struct workqueue_struct *wq = READ_ONCE(system_dfl_wq); + + if (!wq) + return; + mod_delayed_work(wq, &apple_pmp_agx_vote_work, msecs_to_jiffies(delay_ms)); +} + +static int apple_pmp_agx_vote_param_set(const char *val, const struct kernel_param *kp) +{ + int ret = param_set_bool(val, kp); + + if (!ret) + apple_pmp_agx_vote_kick(0); /* switching off clears at once, switching on votes if the GPU is busy */ + return ret; +} + +static const struct kernel_param_ops apple_pmp_agx_vote_ops = { + .set = apple_pmp_agx_vote_param_set, + .get = param_get_bool, +}; +module_param_cb(agx_vote, &apple_pmp_agx_vote_ops, &agx_vote, 0644); +MODULE_PARM_DESC(agx_vote, "T6001: set the AGX power request in the PMP report while the GPU has work in flight (default: off)"); +module_param(agx_vote_idle_ms, uint, 0644); +MODULE_PARM_DESC(agx_vote_idle_ms, "Keep the AGX request this many ms after the last GPU operation ends (default: 250)"); + +/* Write the AGX request of the bound T6001 report: -ENODEV without one, -EAGAIN (nothing written) when the PMP does not run. */ +static int apple_pmp_agx_write(bool enable, bool no_ack) +{ + struct apple_pmp_report *rep; + int ret = -ENODEV; + + if (!of_machine_is_compatible("apple,t6001")) + return ret; + rcu_read_lock(); + list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { + if (rep->offsets != &apple_pmp_offsets_t600x) + continue; + if (enable && !(readq(rep->base + rep->offsets->status) & PMP_REPORT_READY)) + ret = -EAGAIN; + else + ret = apple_pmp_report_set_state(rep, APPLE_PMP_T6001_AGX_ID, enable, no_ack); + break; + } + rcu_read_unlock(); + return ret; +} + +/* Refuse new votes (the stopped flag), without writing anything. */ +static void apple_pmp_agx_vote_stop_new(void) +{ + unsigned long flags; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + agx_vote_refuse(&apple_pmp_agx_vote_state); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); +} + +/* Clear a request that is still set. Caller holds apple_pmp_agx_vote_mutex. */ +static void apple_pmp_agx_vote_stop(void) +{ + unsigned long flags; + bool voted; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + voted = agx_vote_release(&apple_pmp_agx_vote_state); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (voted) + apple_pmp_agx_write(false, true); +} + +static void apple_pmp_agx_vote_fn(struct work_struct *work) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + enum agx_vote_action act; + unsigned long flags; + agx_ms_t now, next = 0; + int ret = 0; + + guard(mutex)(&apple_pmp_agx_vote_mutex); + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + v->idle_ms = READ_ONCE(agx_vote_idle_ms); + now = apple_pmp_agx_now_ms(); + act = agx_vote_decide(v, now); + if (act == AGX_VOTE_NONE && v->failures && !v->users && !v->voted && + agx_vote_retry_reached(v, now)) + v->failures = 0; /* the backoff fired with nobody waiting: it is spent */ + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + + if (act != AGX_VOTE_NONE) { + const bool set = act == AGX_VOTE_SET; + + ret = apple_pmp_agx_write(set, false); + if (ret == -ETIMEDOUT) { + pr_err("pmp_report: AGX request %s not acknowledged, clearing\n", set ? "set" : "clear"); + apple_pmp_agx_write(false, true); + } + if (!set) + ret = 0; /* a clear is final: the state is "not voted" whatever happened */ + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + agx_vote_applied(v, act, ret, now); + next = agx_vote_next(v, apple_pmp_agx_now_ms()); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + } else { + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + next = agx_vote_next(v, now); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + } + if (next) + apple_pmp_agx_vote_kick(next); +} + +void apple_pmp_agx_activity_begin(void) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + unsigned long flags; + agx_ms_t delay; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + delay = agx_vote_begin(v, apple_pmp_agx_now_ms()); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (delay) + apple_pmp_agx_vote_kick(delay); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_begin); + +void apple_pmp_agx_activity_end(void) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + unsigned long flags; + agx_ms_t delay; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + v->idle_ms = READ_ONCE(agx_vote_idle_ms); + delay = agx_vote_end(v, apple_pmp_agx_now_ms()); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (delay) + apple_pmp_agx_vote_kick(delay); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_end); + +/* + * The GPU driver unbinds: clear the request now instead of waiting out the idle time, so it is never left set past the GPU's + * power-domain release (the T6030 fix clears before it releases its vote). Process context. + */ +void apple_pmp_agx_activity_release(void) +{ + /* Stop first so that a begin() from now on cannot queue a set, then wait out a work item that already decided, then clear what it set. */ + apple_pmp_agx_vote_stop_new(); + cancel_delayed_work_sync(&apple_pmp_agx_vote_work); + guard(mutex)(&apple_pmp_agx_vote_mutex); + apple_pmp_agx_vote_stop(); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_release); + +/* The GPU probes again, the report comes back or the system resumes: allow votes, and vote now if operations are already in flight. Process context. */ +void apple_pmp_agx_activity_resume(void) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + unsigned long flags; + bool kick; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + kick = agx_vote_resume(v); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (kick) + apple_pmp_agx_vote_kick(0); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_resume); + +/* + * System sleep: withdraw the request before the devices suspend and decide again after resume. Whether bit 9 held through s2idle costs power is not + * measured (a held display request cost about 0.25 W on J514S), and the PMP may drop the word across sleep, which would leave voted true with nothing + * on the wire. Clearing and re-voting covers both. + */ +static int apple_pmp_agx_pm_notify(struct notifier_block *nb, unsigned long action, void *data) +{ + switch (action) { + case PM_SUSPEND_PREPARE: + case PM_HIBERNATION_PREPARE: + apple_pmp_agx_activity_release(); + break; + case PM_POST_SUSPEND: + case PM_POST_HIBERNATION: + apple_pmp_agx_activity_resume(); + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block apple_pmp_agx_pm_nb = { + .notifier_call = apple_pmp_agx_pm_notify, +}; + /* Find and check the report before taking the GPU vote; optionally update it. */ static int apple_pmp_report_t6030_gfx(struct device *supplier, const bool *enable) { @@ -1654,6 +1897,53 @@ static void apple_pmp_report_dvfs_write(struct apple_pmp_report *rep, u32 entry, writeq(val, rep->base + rep->offsets->update + 8 * entry); } +/** + * apple_pmp_report_set_request() - set or clear one bit of the PMP power request word of a bound report + * @report_np: device tree node of the report region (compatible apple,t6000-pmp-v2-report and its + * siblings) + * @id: bit number of the request, the index of the soc-device record, 0 to 63 (ANE0 is 10 and AGX + * is 9 on the T6001) + * @enable: set or clear the bit + * @no_ack: do not wait for the acknowledge + * + * One read-modify-write of the word, made under the report's lock: the same lock every report + * entry and the AGX vote take, so requests for different bits cannot lose each other. Unless + * @no_ack, waits (atomic poll, at most 50 ms) until the acknowledge word shows the bit as + * requested. A PMP that does not run has nothing to acknowledge: the request is written and 0 is + * returned, as for a report entry. + * + * The caller owns the bit it requests; this function does not arbitrate between callers of the + * same bit. On the T6001 bit 9 belongs to the AGX vote (pmp_report.agx_vote) and is refused here + * with -EBUSY. After -ETIMEDOUT the request was written but not acknowledged and stays in the + * word: the caller must clear it (@enable false, @no_ack true) before giving up. + * + * Context: process context (the acknowledge wait is a busy poll of up to 50 ms). + * Return: 0, -ENODEV if no report is bound to @report_np, -EINVAL if @id is out of range, + * -EBUSY for the T6001 AGX bit, -ETIMEDOUT if the acknowledge did not follow. + */ +int apple_pmp_report_set_request(const struct device_node *report_np, unsigned int id, + bool enable, bool no_ack) +{ + struct apple_pmp_report *rep; + int ret = -ENODEV; + + if (id > 63) + return -EINVAL; + rcu_read_lock(); + list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { + if (rep->dev->of_node == report_np) { + if (id == APPLE_PMP_T6001_AGX_ID && rep->offsets == &apple_pmp_offsets_t600x) + ret = -EBUSY; /* the AGX vote owns this bit */ + else + ret = apple_pmp_report_set_state(rep, id, enable, no_ack); + break; + } + } + rcu_read_unlock(); + return ret; +} +EXPORT_SYMBOL_GPL(apple_pmp_report_set_request); + static int apple_pmp_report_entry_set_state(struct generic_pm_domain *genpd, bool enable) { struct apple_pmp_report_entry *ent = genpd_to_apple_pmp_report_entry(genpd); @@ -1939,6 +2229,7 @@ MODULE_DEVICE_TABLE(of, apple_pmp_report_entry_of_match); static int __init apple_pmp_report_init(void) { + register_pm_notifier(&apple_pmp_agx_pm_nb); apple_pmp_report_debugfs = debugfs_create_dir("apple-pmp-report", NULL); platform_driver_register(&apple_pmp_report_entry_driver); platform_driver_register(&apple_pmp_report_driver); @@ -1947,6 +2238,7 @@ static int __init apple_pmp_report_init(void) static void __exit apple_pmp_report_exit(void) { + unregister_pm_notifier(&apple_pmp_agx_pm_nb); debugfs_remove_recursive(apple_pmp_report_debugfs); platform_driver_unregister(&apple_pmp_report_entry_driver); platform_driver_unregister(&apple_pmp_report_driver); diff --git a/include/linux/soc/apple/pmp-report.h b/include/linux/soc/apple/pmp-report.h index dd3373517bf90..66e97565edc1e 100644 --- a/include/linux/soc/apple/pmp-report.h +++ b/include/linux/soc/apple/pmp-report.h @@ -24,6 +24,21 @@ int apple_pmp_report_set_t6030_gfx(struct device *supplier, bool enable); int apple_pmp_report_wait_ready(struct device_node *entry, unsigned long timeout); int apple_pmp_report_fast_die_effort(const struct device_node *np, unsigned int lane, u8 *effort); +/* + * Set or clear one bit of the PMP power request word of the report bound to @report_np, under the + * report's lock, with the acknowledge wait (see pmp-report.c). + */ +int apple_pmp_report_set_request(const struct device_node *report_np, unsigned int id, + bool enable, bool no_ack); +/* + * T6001: the GPU driver reports each operation in flight. With the pmp_report.agx_vote parameter set, the AGX request (PS-REQ bit 9) is + * set while any operation runs and cleared agx_vote_idle_ms after the last one ends. Parameter off: no effect. Both may be called from + * any context. release() clears the request at once (GPU driver unbind), process context. + */ +void apple_pmp_agx_activity_begin(void); +void apple_pmp_agx_activity_end(void); +void apple_pmp_agx_activity_release(void); +void apple_pmp_agx_activity_resume(void); #else static inline int apple_pmp_report_ane_available(const struct device_node *np) { @@ -37,6 +52,22 @@ static inline int apple_pmp_report_ane_perf(const struct device_node *np, return -EOPNOTSUPP; } +static inline void apple_pmp_agx_activity_begin(void) +{ +} + +static inline void apple_pmp_agx_activity_end(void) +{ +} + +static inline void apple_pmp_agx_activity_resume(void) +{ +} + +static inline void apple_pmp_agx_activity_release(void) +{ +} + static inline int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int timeout_ms) { @@ -64,6 +95,12 @@ static inline int apple_pmp_report_fast_die_effort(const struct device_node *np, { return -ENODEV; } + +static inline int apple_pmp_report_set_request(const struct device_node *report_np, + unsigned int id, bool enable, bool no_ack) +{ + return -ENODEV; +} #endif #endif /* _LINUX_SOC_APPLE_PMP_REPORT_H_ */ diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 24d4840aabadb..405831d77da76 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -113,6 +113,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/asahi/pmp-agx-vote-tests.c b/tools/asahi/pmp-agx-vote-tests.c new file mode 100644 index 0000000000000..03a3374a5304f --- /dev/null +++ b/tools/asahi/pmp-agx-vote-tests.c @@ -0,0 +1,474 @@ +// Unit test and simulation of pmp-agx-vote.h: the policy that decides when the T6001 AGX request (PS-REQ bit 9) is set and cleared. +// A fake clock, a fake PMP bit and a fake timer drive the same transition functions the kernel glue calls. No kernel, no hardware. +#include +#include +#include +#include + +#include "pmp-agx-vote.h" + +struct sim { + struct agx_vote v; + uint32_t now; + bool bit; // the PMP's PS-REQ bit 9 + int sets, clears; // register writes that tried to set / clear it + int fail_sets; // the next N set attempts are not acknowledged + bool armed; + uint32_t timer_at; + int begin_in_write; // begin this many operations while the register write of the next reconcile is in progress + int end_in_write; // end this many operations while the register write of the next reconcile is in progress + int kicks; // reconciliations the operations asked for +}; + +static void arm(struct sim *s, uint32_t delay_ms) +{ + uint32_t at = s->now + delay_ms; + if (!s->armed || (int32_t)(at - s->timer_at) < 0) { + s->armed = true; + s->timer_at = at; + } +} + +static void begin(struct sim *s); +static void end(struct sim *s); + +// What the kernel work function does. +static void reconcile(struct sim *s) +{ + enum agx_vote_action act = agx_vote_decide(&s->v, s->now); + int ret = 0; + + s->armed = false; + if (act == AGX_VOTE_SET) { + s->sets++; + if (s->fail_sets > 0) { + s->fail_sets--; + ret = -110; + s->bit = false; // glue force-clears a request that was not acknowledged + } else { + s->bit = true; + } + } else if (act == AGX_VOTE_CLEAR) { + s->clears++; + s->bit = false; + } else if (s->v.failures && !s->v.users && !s->v.voted && + agx_vote_retry_reached(&s->v, s->now)) { + s->v.failures = 0; // the glue clears a spent backoff when the retry fires idle + } + while (s->end_in_write > 0) { + s->end_in_write--; + end(s); + } + while (s->begin_in_write > 0) { + s->begin_in_write--; + begin(s); + } + if (act != AGX_VOTE_NONE) + agx_vote_applied(&s->v, act, ret, s->now); + uint32_t next = agx_vote_next(&s->v, s->now); + if (next) + arm(s, next); +} + +static void begin(struct sim *s) +{ + agx_ms_t d = agx_vote_begin(&s->v, s->now); + if (d) { + s->kicks++; + /* delay 1 is "due now": the glue runs it within the same tick */ + arm(s, d == 1 ? 0 : d); + } +} + +static void end(struct sim *s) +{ + uint32_t d = agx_vote_end(&s->v, s->now); + if (d) + arm(s, d); +} + +static void advance_to(struct sim *s, uint32_t t) +{ + while (s->armed && (int32_t)(s->timer_at - t) <= 0) { + if ((int32_t)(s->timer_at - s->now) > 0) + s->now = s->timer_at; + reconcile(s); + } + s->now = t; +} + +static struct sim fresh(bool enabled, unsigned long idle_ms, uint32_t start) +{ + struct sim s = {.now = start}; + s.v.enabled = enabled; + s.v.idle_ms = idle_ms; + return s; +} + +#define CHECK(cond) do { if (!(cond)) { fprintf(stderr, "FAIL line %d: %s\n", __LINE__, #cond); exit(1); } } while (0) + +int main(void) +{ + // 1. parameter off: nothing is ever written, however much the GPU runs + { + struct sim s = fresh(false, 100, 1000); + for (int i = 0; i < 50; i++) { begin(&s); advance_to(&s, s.now + 4); end(&s); advance_to(&s, s.now + 7); } + advance_to(&s, s.now + 1000); + CHECK(s.sets == 0 && s.clears == 0 && !s.bit); + } + // 2. one operation: set at once, kept for idle_ms, then cleared + { + struct sim s = fresh(true, 100, 1000); + begin(&s); advance_to(&s, 1000); + CHECK(s.bit && s.sets == 1); + advance_to(&s, 1004); end(&s); + advance_to(&s, 1103); CHECK(s.bit); // 99 ms after the end: still voted + advance_to(&s, 1104); CHECK(!s.bit && s.clears == 1); // 100 ms after the end: dropped + } + // 3. decode-like bursts every 10.58 ms for one second: one set, no clear until the idle time after the last burst + { + struct sim s = fresh(true, 100, 5000); + uint32_t last_end = 0; + for (int i = 0; i < 95; i++) { + uint32_t t0 = 5000 + (uint32_t)(i * 10.58); + advance_to(&s, t0); begin(&s); + advance_to(&s, t0 + 4); end(&s); last_end = s.now; + } + CHECK(s.sets == 1 && s.clears == 0 && s.bit); + advance_to(&s, last_end + 99); CHECK(s.bit); + advance_to(&s, last_end + 100); CHECK(!s.bit && s.clears == 1 && s.sets == 1); + } + // 4. work arrives while the drop is pending: the drop is cancelled, then rescheduled from the new end + { + struct sim s = fresh(true, 100, 0); + begin(&s); advance_to(&s, 0); end(&s); + advance_to(&s, 50); begin(&s); + advance_to(&s, 100); CHECK(s.bit && s.clears == 0); + advance_to(&s, 120); end(&s); + advance_to(&s, 219); CHECK(s.bit); + advance_to(&s, 220); CHECK(!s.bit && s.clears == 1 && s.sets == 1); + } + // 5. a set that is not acknowledged is cleared again, not retried in a hot loop, and retried after the backoff + { + struct sim s = fresh(true, 100, 0); + s.fail_sets = 1; + begin(&s); advance_to(&s, 0); + CHECK(s.sets == 1 && !s.bit && !s.v.voted && s.v.failures == 1); + advance_to(&s, AGX_VOTE_RETRY_MS - 1); CHECK(s.sets == 1); + advance_to(&s, AGX_VOTE_RETRY_MS); CHECK(s.sets == 2 && s.bit && s.v.voted && s.v.failures == 0); + } + // 6. an end without a begin is ignored: no underflow, the next begin still works + { + struct sim s = fresh(true, 100, 0); + end(&s); end(&s); + CHECK(s.v.users == 0 && !s.armed); + begin(&s); advance_to(&s, 0); + CHECK(s.v.users == 1 && s.bit); + } + // 7. the parameter is switched off while voted and busy: cleared at the next reconcile, even with work in flight + { + struct sim s = fresh(true, 100, 0); + begin(&s); advance_to(&s, 0); CHECK(s.bit); + s.v.enabled = false; arm(&s, 0); advance_to(&s, 1); + CHECK(!s.bit && s.clears == 1 && !s.v.voted); + s.v.enabled = true; arm(&s, 0); advance_to(&s, 2); // switched on again with work still in flight + CHECK(s.bit && s.sets == 2); + } + // 8. zero idle time still waits one tick (no clear inside the end call's own tick) + { + struct sim s = fresh(true, 0, 0); + begin(&s); advance_to(&s, 0); end(&s); + CHECK(s.armed && s.bit); + advance_to(&s, 1); CHECK(!s.bit); + } + // 9. the millisecond clock wraps: idle_at + idle_ms overflows, the decision stays right + { + struct sim s = fresh(true, 100, UINT32_MAX - 50); + begin(&s); advance_to(&s, s.now); end(&s); + advance_to(&s, s.now + 99); CHECK(s.bit); + advance_to(&s, s.now + 1); CHECK(!s.bit && s.clears == 1); + } + // 10. release (GPU driver unbind): a held vote is cleared once, at once, and the idle timer is not needed afterwards + { + struct sim s = fresh(true, 100, 0); + begin(&s); advance_to(&s, 0); end(&s); + CHECK(s.bit && s.armed); + if (agx_vote_release(&s.v)) { s.clears++; s.bit = false; } + CHECK(!s.bit && s.clears == 1 && !s.v.voted); + advance_to(&s, 500); // the pending timer fires and finds nothing to do + CHECK(s.clears == 1 && !s.armed); + CHECK(!agx_vote_release(&s.v)); // a second release writes nothing + } + // 11. w7X's reproduction: jiffies_to_msecs is 32 bits wide, so a vote whose last operation ended at 0xFFFFFFF0 must still clear + // 100 ms later, after the clock has wrapped to 0x54 (a 64-bit compare of idle_at + idle_ms never decided it) + { + struct sim s = fresh(true, 100, 0xFFFFFFF0u); + begin(&s); advance_to(&s, s.now); end(&s); + CHECK(s.v.idle_at == 0xFFFFFFF0u); + advance_to(&s, 0xFFFFFFF0u + 99u); CHECK(s.bit && s.now == 0x53u); + advance_to(&s, 0x54u); CHECK(!s.bit && s.clears == 1); + CHECK(agx_vote_next(&s.v, s.now) == 0); + } + // 12. a retry deadline across the same wrap + { + struct sim s = fresh(true, 100, 0xFFFFFC00u); + s.fail_sets = 1; + begin(&s); advance_to(&s, s.now); + CHECK(s.sets == 1 && !s.bit); + advance_to(&s, 0xFFFFFC00u + AGX_VOTE_RETRY_MS - 1u); CHECK(s.sets == 1); + advance_to(&s, 0xFFFFFC00u + AGX_VOTE_RETRY_MS); CHECK(s.sets == 2 && s.bit); + } + // 13. the shipped default hold: w7X measured gaps of up to 111.5 ms inside one 9B generation (ctx 8192, once per process), over the old + // 100 ms hold. The default must ride through that gap with one vote, and still drop the vote after a long idle. + { + struct sim s = fresh(true, AGX_VOTE_IDLE_MS_DEFAULT, 1000); + CHECK(AGX_VOTE_IDLE_MS_DEFAULT >= 250); + begin(&s); advance_to(&s, s.now); end(&s); + advance_to(&s, s.now + 112); // the 111.5 ms interval rounded up + begin(&s); advance_to(&s, s.now); end(&s); + CHECK(s.sets == 1 && s.clears == 0 && s.bit); + advance_to(&s, s.now + AGX_VOTE_IDLE_MS_DEFAULT - 1); CHECK(s.bit); + advance_to(&s, s.now + 1); CHECK(!s.bit && s.clears == 1); + } + // 14. review finding 2: an operation begins while the clear is being written (voted is still true, so begin does not kick). After the clear is + // applied the vote must be set again without waiting for another operation. + { + struct sim s = fresh(true, 100, 0); + begin(&s); advance_to(&s, 0); end(&s); + CHECK(s.bit && s.armed); + s.begin_in_write = 1; + advance_to(&s, 100); // the idle hold expires: reconcile decides CLEAR, begin lands inside the write + CHECK(s.v.users == 1); + advance_to(&s, 101); // the owed set runs + CHECK(s.bit && s.v.voted && s.sets == 2 && s.clears == 1); + // the header alone, as the reviewer reproduced it: decide (CLEAR), begin, applied, next + struct agx_vote v = {.enabled = true, .voted = true, .idle_ms = 100, .idle_at = 0}; + CHECK(agx_vote_decide(&v, 100) == AGX_VOTE_CLEAR); + CHECK(!agx_vote_begin(&v, 100)); + agx_vote_applied(&v, AGX_VOTE_CLEAR, 0, 100); + CHECK(v.users == 1 && !v.voted); + CHECK(agx_vote_next(&v, 100) == 1); // not 0: a set is owed + CHECK(agx_vote_decide(&v, 101) == AGX_VOTE_SET); + } + // 15. review finding 3: after release (GPU unbind or report removal) no begin may vote again, until the GPU probes again + { + struct sim s = fresh(true, 100, 0); + begin(&s); advance_to(&s, 0); + CHECK(s.bit && s.v.users == 1); + if (agx_vote_release(&s.v)) { s.clears++; s.bit = false; } + CHECK(!s.bit && s.v.stopped && s.clears == 1); + end(&s); begin(&s); advance_to(&s, 50); // an ioctl already past the unplug check starts an operation + CHECK(!s.bit && s.sets == 1 && !s.armed); + CHECK(agx_vote_decide(&s.v, 50) == AGX_VOTE_NONE); + CHECK(agx_vote_next(&s.v, 50) == 0); + // a work item that was queued before the release finds nothing to set + arm(&s, 0); advance_to(&s, 51); + CHECK(!s.bit && s.sets == 1); + // the GPU probes again: the vote is allowed, and the operation still in flight gets its set + CHECK(agx_vote_resume(&s.v)); + arm(&s, 0); advance_to(&s, 52); + CHECK(s.bit && s.sets == 2 && !s.v.stopped); + } + // 16. review finding 4: system sleep. The vote is withdrawn before suspend and re-decided on resume: with work still in flight it is set + // again (the PMP may have dropped the word), with an idle GPU nothing is written. + { + struct sim s = fresh(true, 250, 0); + begin(&s); advance_to(&s, 0); + CHECK(s.bit); + if (agx_vote_release(&s.v)) { s.clears++; s.bit = false; } // suspend prepare + CHECK(!s.bit && s.v.stopped && s.clears == 1); + if (agx_vote_resume(&s.v)) arm(&s, 0); // resume + advance_to(&s, 10); + CHECK(s.bit && s.sets == 2 && s.v.voted); + end(&s); + if (agx_vote_release(&s.v)) { s.clears++; s.bit = false; } // a second sleep while idle inside the hold + CHECK(!s.bit && s.clears == 2); + CHECK(!agx_vote_resume(&s.v)); // idle: nothing is owed + advance_to(&s, 1000); + CHECK(!s.bit && s.sets == 2 && s.clears == 2); + begin(&s); advance_to(&s, 1001); // the next operation after resume votes as usual + CHECK(s.bit && s.sets == 3); + } + // 17. disabled and stopped never set, whatever begins + { + struct sim s = fresh(false, 100, 0); + s.v.stopped = true; + begin(&s); advance_to(&s, 1); + CHECK(!s.bit && s.sets == 0 && !s.armed); + CHECK(!agx_vote_resume(&s.v)); // disabled: resume owes nothing + } + // 18. mutants that survived the first review: begin() must itself refuse while stopped (not only decide()), a failed set must schedule the retry + // deadline and not the 1 ms owed-set kick (a 1 kHz spin for the whole 1000 ms window otherwise), and agx_vote_refuse() must stop votes. + { + struct agx_vote v = {.enabled = true, .idle_ms = 100}; + agx_vote_refuse(&v); + CHECK(v.stopped && !v.voted); + CHECK(!agx_vote_begin(&v, 0)); // a user, but no kick + CHECK(agx_vote_decide(&v, 0) == AGX_VOTE_NONE && agx_vote_next(&v, 0) == 0); + CHECK(agx_vote_resume(&v)); // work in flight: the reconcile step must run + struct agx_vote w = {.enabled = true, .idle_ms = 100}; + CHECK(agx_vote_begin(&w, 0)); + agx_vote_applied(&w, AGX_VOTE_SET, -110, 500); // the set was not acknowledged + CHECK(w.failures == 1 && w.retry_at == 500 + AGX_VOTE_RETRY_MS); + CHECK(agx_vote_next(&w, 500) == AGX_VOTE_RETRY_MS); // the retry deadline, not 1 ms + CHECK(agx_vote_next(&w, 500 + AGX_VOTE_RETRY_MS - 1) == 1); + } + // 19. w7X's wrap mutant: reached() must compare in signed 32-bit arithmetic, so a deadline that has + // wrapped into the low range is not "already reached" on the pre-wrap side + { + struct agx_vote v = {.enabled = true, .voted = true, .idle_ms = 100, .idle_at = 0xFFFFFFF0u}; + CHECK(agx_vote_decide(&v, 0xFFFFFFF8u) == AGX_VOTE_NONE); + CHECK(agx_vote_next(&v, 0xFFFFFFF8u) == 0x5Cu); + struct agx_vote w = {.enabled = true, .idle_ms = 100, .users = 1, .failures = 1, .retry_at = 0x54u}; + CHECK(agx_vote_decide(&w, 0xFFFFFFF8u) == AGX_VOTE_NONE); + } + // 20. chriskearney's race: the last end lands between decide (SET) and applied. end saw voted false and + // armed nothing; applied then sets the vote with no user and an already-reached idle deadline. The + // caller must still be told to run the reconcile that clears it. + { + // exactly the reviewer's interleaving, on the header alone: decide, then end, then the write lands + struct agx_vote v = {.enabled = true, .idle_ms = 0}; + CHECK(agx_vote_begin(&v, 5000) && v.users == 1); + CHECK(agx_vote_decide(&v, 5000) == AGX_VOTE_SET); + CHECK(agx_vote_end(&v, 5001) == 0); // the end during the write sees voted false: no timer + CHECK(v.users == 0); + agx_vote_applied(&v, AGX_VOTE_SET, 0, 5000); + CHECK(v.voted && v.users == 0); + CHECK(agx_vote_next(&v, 5001) == 1); // an already-reached deadline is due now, not "nothing" + CHECK(agx_vote_decide(&v, 5001) == AGX_VOTE_CLEAR); + agx_vote_applied(&v, AGX_VOTE_CLEAR, 0, 5001); + CHECK(!v.voted && agx_vote_next(&v, 5001) == 0); // and it settles + } + // 21. chriskearney's bound: an idle gap beyond half the 32-bit millisecond range makes the wrapped + // arithmetic read an expired retry deadline as future, which would keep the vote off for days. A retry + // deadline more than one backoff window in the future cannot be real, so it counts as reached. + { + struct sim s = fresh(true, 100, 0); + s.fail_sets = 1; + begin(&s); advance_to(&s, 0); + CHECK(s.v.failures == 1); + s.v.retry_at = 0x54u; + advance_to(&s, 0x54u + 0x80000005u); // the timer fires absurdly late + CHECK(s.bit && s.sets == 2 && s.v.failures == 0); // the vote is set again at once + // the header alone + struct agx_vote w = {.enabled = true, .users = 1, .failures = 1, .retry_at = 0x54u}; + CHECK(agx_vote_decide(&w, 0x54u + 0x80000005u) == AGX_VOTE_SET); + CHECK(agx_vote_next(&w, 0x54u + 0x80000005u) == 1); + CHECK(agx_vote_decide(&w, 0x54u + 0x80000000u) == AGX_VOTE_SET); + CHECK(agx_vote_next(&w, 0x54u + 0x80000000u) == 1); + } + // 22. the same review: during backoff begin must not ask for a reconciliation decide would refuse + // (every begin during the window kicked a NONE reconcile and the retry timer did the work anyway) + { + struct sim s = fresh(true, 100, 0); + s.fail_sets = 1; + begin(&s); advance_to(&s, 0); + CHECK(s.v.failures == 1 && s.armed); + int kicks = s.kicks; + uint32_t armed_at = s.timer_at; + for (int i = 0; i < 5; i++) + begin(&s); + CHECK(s.kicks == kicks + 5 && s.sets == 1); // each begin arms the same deadline, none reconciles early + CHECK(s.armed && s.timer_at == armed_at); // mod_delayed_work can only pull the deadline earlier + advance_to(&s, AGX_VOTE_RETRY_MS); + CHECK(s.sets == 2 && s.bit && s.v.failures == 0); + // the header alone + struct agx_vote v = {.enabled = true, .failures = 1, .retry_at = 100}; + CHECK(agx_vote_begin(&v, 0) == 100); // arms the remaining delay + CHECK(agx_vote_begin(&v, 100) == 1); // past the deadline: now + } + // 23. w7X's regression repro for the first cut of the backoff gate: a failed set whose retry timer fires + // while the GPU is idle left failures set forever, and begin never asked for the set again. The kick + // must come back once the deadline has passed. + { + struct sim s = fresh(true, 100, 0); + s.fail_sets = 1; + begin(&s); advance_to(&s, 0); + CHECK(s.v.failures == 1 && s.armed); + end(&s); // the operation ends long before the retry + advance_to(&s, AGX_VOTE_RETRY_MS); // the timer fires idle: nothing to do + CHECK(s.v.failures == 0 && !s.armed && !s.bit); // the spent backoff cleared at the idle fire + int kicks = s.kicks; + begin(&s); // a later operation: the kick must come back + advance_to(&s, s.now + 1); + CHECK(s.kicks == kicks + 1 && s.sets == 2 && s.bit && s.v.failures == 0); + // the header alone: inside the window no kick, past it the kick returns + struct agx_vote v = {.enabled = true, .failures = 1, .retry_at = 100}; + CHECK(agx_vote_begin(&v, 50) == 50); // arms the remaining delay + CHECK(agx_vote_begin(&v, 100) == 1); + } + // 24. chriskearney's second race at efff25c1: the last operation ends during a SET ack that then times + // out. applied records the failure with no user and no timer (next returns 0 on that path), and a begin + // before the retry deadline must arm the remaining delay instead of returning "no kick", or the retry + // never runs. The release/resume cycle must not drop it either. + { + struct agx_vote v = {.enabled = true, .idle_ms = 100}; + CHECK(agx_vote_begin(&v, 5000) == 1); + CHECK(agx_vote_decide(&v, 5000) == AGX_VOTE_SET); + CHECK(agx_vote_end(&v, 5001) == 0); // the end during the ack: no timer + agx_vote_applied(&v, AGX_VOTE_SET, -110, 5000); // the ack times out + CHECK(v.failures == 1 && agx_vote_next(&v, 5001) == 999); // next arms the retry from the failure state + unsigned delay = agx_vote_begin(&v, 5002); + CHECK(delay == 998); // the begin arms the remaining delay + CHECK(v.users == 1); + CHECK(agx_vote_decide(&v, 6000) == AGX_VOTE_SET); // the retry lands and sets + agx_vote_applied(&v, AGX_VOTE_SET, 0, 6000); + CHECK(v.voted && v.failures == 0 && agx_vote_next(&v, 6000) == 0); + // the cancel-on-release/resume variant: the retry survives the cycle + struct agx_vote w = {.enabled = true, .failures = 1, .retry_at = 6000}; + CHECK(!agx_vote_release(&w)); // idle release: no clear write + CHECK(!agx_vote_resume(&w)); // idle resume: still no immediate kick + CHECK(agx_vote_begin(&w, 6100) == 1); // past the deadline the kick is back + } + // 25. the residual w7X flagged on the delay contract: the end lands inside a failed SET write and no new + // operation starts. The write path arms nothing (users is already 0 when applied runs), so the work + // function must arm the retry from the failure state itself, and when the retry fires with nobody + // waiting it must clear the backoff instead of re-arming forever. + { + struct sim s = fresh(true, 100, 0); + s.fail_sets = 1; + s.end_in_write = 1; // the op ends inside the ack + begin(&s); advance_to(&s, 0); + CHECK(s.v.failures == 1 && s.v.users == 0 && s.bit == false); + CHECK(s.armed); // the retry is armed from the failure state + advance_to(&s, AGX_VOTE_RETRY_MS); + CHECK(s.v.failures == 0 && !s.armed && !s.bit); // the idle fire clears the backoff, once + advance_to(&s, AGX_VOTE_RETRY_MS + 500); + CHECK(!s.armed && s.sets == 1); // no re-arm, no hot loop + begin(&s); advance_to(&s, s.now + 1); + CHECK(s.sets == 2 && s.bit); // and a later operation votes as usual + // the header alone: next arms the remaining delay with no user and no pending timer + struct agx_vote v = {.enabled = true, .failures = 1, .retry_at = 6000}; + CHECK(agx_vote_next(&v, 5500) == 500); + CHECK(agx_vote_next(&v, 6000) == 1); + } + // 26. chriskearney's missing-retry-timer repro at c3487a52: the end lands inside a failed SET ack + // (no timer exists: applied ran with users 0) and the next operation begins before the retry + // deadline. The begin arms the remaining delay, the deadline is never pulled later, and the + // vote lands inside the new operation. A begin during the window cannot strand the retry even + // when the glue timer is already armed. + { + struct sim s = fresh(true, 250, 0); + s.fail_sets = 1; + s.end_in_write = 1; // the last end lands inside the ack poll + begin(&s); advance_to(&s, 0); + CHECK(s.v.failures == 1 && s.v.users == 0 && !s.bit); // the reviewer's steps 1 to 3 + advance_to(&s, AGX_VOTE_RETRY_MS); // the retry fires idle: spent backoff clears + CHECK(s.v.failures == 0 && !s.armed && !s.bit); + begin(&s); // step 4: the new sole operation, before any deadline + advance_to(&s, s.now + AGX_VOTE_RETRY_MS + 5000); // far past where the vote must have landed + CHECK(s.bit && s.v.voted && s.v.users == 1 && s.v.failures == 0); + // the header alone: begin inside the window arms the remaining delay (never 0), and a second + // begin cannot push the deadline later (mod_delayed_work only pulls it earlier) + struct agx_vote v = {.enabled = true, .failures = 1, .retry_at = 6000}; + CHECK(agx_vote_begin(&v, 5500) == 500); + CHECK(v.users == 1); + CHECK(agx_vote_begin(&v, 5500) == 500); // same begin time: the deadline is unchanged + CHECK(agx_vote_begin(&v, 6000) == 1); // at the deadline: reconcile now + // 1 ms before the deadline + struct agx_vote w = {.enabled = true, .failures = 1, .retry_at = 6000}; + CHECK(agx_vote_begin(&w, 5999) == 1); + } + printf("AGX-VOTE-SELFCHECK-OK\n"); + return 0; +} diff --git a/tools/asahi/pmp-agx-vote-tests.py b/tools/asahi/pmp-agx-vote-tests.py new file mode 100755 index 0000000000000..fbd57bc7003d2 --- /dev/null +++ b/tools/asahi/pmp-agx-vote-tests.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Host test for the T6001 AGX vote policy (drivers/pmdomain/apple/pmp-agx-vote.h). + +The policy is a header of static inline transition functions, so the suite +compiles tools/asahi/pmp-agx-vote-tests.c against a copy of that header: a +fake clock, a fake PMP bit and a fake timer drive the same begin, decide, +next and applied calls the kernel glue makes. No kernel, no hardware. + +--mutation NAME / --mutations apply textual mutants to the header copy and +require the suite to fail; like the other self-checking suites, exit status 0 +means every mutant was caught. --ref reads the header at a Git revision (a +pre-fix header fails the suite itself, which is the point of those cases). +""" +import argparse +import hashlib +import json +import os +from pathlib import Path +import shlex +import shutil +import subprocess + +ROOT = Path(__file__).resolve().parents[2] +HEADER = 'drivers/pmdomain/apple/pmp-agx-vote.h' + +# Each mutant removes one guard. The first two are the mutants that survived +# the first review round, when begin() did not refuse while stopped and the +# retry deadline was not distinguished from the 1 ms owed-set kick. +CONTROLS = [ + ('owed-set-branch', '\tif (v->users && !v->voted && !v->failures)\n\t\treturn 1;\n', ''), + ('owed-failures', 'if (v->users && !v->voted && !v->failures)\n\t\treturn 1;', 'if (v->users && !v->voted)\n\t\treturn 1;'), + ('stopped-in-begin', 'v->users++;\n if (!v->enabled || v->stopped)\n return 0;', 'v->users++;\n if (!v->enabled)\n return 0;'), + ('stopped-in-decide', 'if (!v->enabled || v->stopped)\n\t\treturn v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE;', + 'if (!v->enabled)\n\t\treturn v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE;'), + ('wrap-reached', 'return (agx_sms_t)(now - t) >= 0;', 'return now >= t;'), + ('set-write-ends', 'return agx_vote_reached(now, at) ? 1 : at - now;', 'return agx_vote_reached(now, at) ? 0 : at - now;'), + ('retry-dropped-when-idle', + '\telse if (!v->users && !v->voted && v->failures)\n' + '\t\t/* The write outlasted the operation: arm the retry from the failure state\n' + '\t\t * itself. The caller clears failures when this reconcile finds nobody waiting\n' + '\t\t * (decide returns NONE), so it fires once. */\n' + '\t\tat = agx_vote_retry_reached(v, now) ? now : v->retry_at;\n', ''), + ('begin-backoff-kick', 'return (!v->failures || agx_vote_retry_reached(v, now)) ? 1 : v->retry_at - now;', 'return (void)now, 1;'), + ('begin-no-retry-arm', 'return (!v->failures || agx_vote_retry_reached(v, now)) ? 1 : v->retry_at - now;', 'return (void)now, 0;'), + ('begin-drops-users', ' v->users++;\n if (!v->enabled || v->stopped)', ' if (!v->enabled || v->stopped)'), + ('retry-revival', '|| (agx_ms_t)(v->retry_at - now) > AGX_VOTE_RETRY_MS', ''), +] + + +def header_text(ref): + if ref: + return subprocess.check_output(['git', '-C', str(ROOT), 'show', f'{ref}:{HEADER}'], text=True) + return (ROOT / HEADER).read_text() + + +def compile_and_run(out, text): + out.mkdir(parents=True, exist_ok=True) + (out / 'pmp-agx-vote.h').write_text(text) + compiler = shlex.split(os.environ.get('CC', 'clang')) + command = compiler + ['-std=gnu11', '-g', '-O1', '-Wall', '-Wextra', '-Werror', + '-fsanitize=address,undefined', '-fno-omit-frame-pointer', + '-I', str(out), str(ROOT / 'tools/asahi/pmp-agx-vote-tests.c'), + '-o', str(out / 'vote')] + built = subprocess.run(command, capture_output=True, text=True) + (out / 'build.log').write_text(built.stdout + built.stderr) + if built.returncode: + return {'build_rc': built.returncode, 'run_rc': None, 'note': 'compilation failure is not regression evidence'} + prefix = ['setarch', '-R'] if shutil.which('setarch') else [] # ASan startup can crash under ASLR on a loaded host + ran = subprocess.run(prefix + [str(out / 'vote')], capture_output=True, text=True) + (out / 'run.log').write_text(ran.stdout + ran.stderr) + return {'build_rc': 0, 'run_rc': ran.returncode} + + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument('--ref', help='read the header at a Git revision (negative control)') + p.add_argument('--mutation', help='apply one named mutant and require the suite to fail') + p.add_argument('--mutations', action='store_true', help='apply every mutant and require each to fail') + p.add_argument('--output', required=True, type=Path) + args = p.parse_args() + args.output.mkdir(parents=True, exist_ok=False) + text = header_text(args.ref) + + base = compile_and_run(args.output, text) + print(Path(args.output / 'run.log').read_text() if base['run_rc'] is not None else Path(args.output / 'build.log').read_text()) + + mutations = [] + if args.mutations or args.mutation: + # A base failure would fail every mutant at the same case and read as caught. + # The negative control (--ref) has no passing base: the pre-fix header cannot compile this suite. + if not args.ref: + assert base['run_rc'] == 0, base + names = [c[0] for c in CONTROLS] if args.mutations else [args.mutation] + for name in names: + old, new = next((c[1], c[2]) for c in CONTROLS if c[0] == name) + count = text.count(old) + result = {} + result['applied'] = count == 1 + if count == 1: + result.update(compile_and_run(args.output / name, text.replace(old, new))) + else: + # A guard that does not exist in this revision cannot be removed: the + # behaviour the guard carries is absent, so the mutant survives there. + result.update({'build_rc': None, 'run_rc': 0, 'note': f'{HEADER} at this revision has no such line ({count} matches)'}) + result['name'] = name + mutations.append(result) + caught = result['applied'] and result['build_rc'] == 0 and result['run_rc'] not in (0, None) + log = args.output / name / ('run.log' if result.get('run_rc') is not None else 'build.log') + detail = log.read_text().strip().splitlines()[-1][:150] if log.exists() else result.get('note', '') + print(f"{name}: {'CAUGHT' if caught else 'SURVIVED'} | {detail}") + + if args.mutations: + assert all(m['applied'] and m['build_rc'] == 0 and m['run_rc'] not in (0, None) for m in mutations), mutations + print('PASS: every vote-policy case passed and every mutant caught') + return 0 + if args.mutation: + m = mutations[0] + assert m['applied'] and m['build_rc'] == 0 and m['run_rc'] not in (0, None), m + return 0 + + (args.output / 'receipt.json').write_text(json.dumps({ + 'source_ref': args.ref, 'source_sha256': hashlib.sha256(text.encode()).hexdigest(), + 'command': [], 'returncode': base['run_rc'] if base['run_rc'] is not None else base['build_rc'], + 'mutations': mutations}, indent=2) + '\n') + return bool(base['run_rc']) if base['run_rc'] is not None else bool(base['build_rc']) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/asahi/t6030-pmp-graph-tests.c b/tools/asahi/t6030-pmp-graph-tests.c index 5f6d0c4d6214b..f9f758cbf15e6 100644 --- a/tools/asahi/t6030-pmp-graph-tests.c +++ b/tools/asahi/t6030-pmp-graph-tests.c @@ -739,6 +739,10 @@ static const struct apple_pmp_start_ops apple_pmp_start_hw_ops = { hw_check, hw_bound }; static const struct apple_pmp_start_timing apple_pmp_start_timing = { 2, 0, 2, 2 }; +/* The extracted probe compares rep->offsets with the T6001 table and tells the AGX vote that a report came back. This harness has neither: the table is empty and + * never matches, and the call does nothing. */ +static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x; +static void apple_pmp_agx_activity_resume(void) {} #include "production.h" #if HOST_HAS_DRAM static int devm_device_add_group(struct device *dev, const struct attribute_group *group) From 131966c24a7185ae852a811ee74321a58275d676 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:00:58 +1100 Subject: [PATCH 134/342] arm64: dts: apple: t8140: watchdog IRQ and SMC I2C master parents from the ADT The J700 ADT gives the watchdog AIC interrupt 481, not 507. apple_wdt does not request it, so nothing changes at runtime; the description is now the one the hardware publishes. SMC_I2CM1 and SMC_I2CM2 hang off SMC_FABRIC in the ADT power tree, as SMC_I2CM0 already does in our tree. Give them the same parent. All three are always-on and SMC_FABRIC is on, so the live state does not change. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-pmgr.dtsi | 2 ++ arch/arm64/boot/dts/apple/t8140.dtsi | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi index a2be4fc980916..7aa9f2bd3a102 100644 --- a/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi @@ -655,6 +655,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "smc_i2cm1"; + power-domains = <&ps_smc_fabric>; apple,always-on; /* used by the SMC firmware */ }; @@ -664,6 +665,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "smc_i2cm2"; + power-domains = <&ps_smc_fabric>; apple,always-on; /* used by the SMC firmware */ }; diff --git a/arch/arm64/boot/dts/apple/t8140.dtsi b/arch/arm64/boot/dts/apple/t8140.dtsi index dbe9bd0d4e59c..b781dd756a2d2 100644 --- a/arch/arm64/boot/dts/apple/t8140.dtsi +++ b/arch/arm64/boot/dts/apple/t8140.dtsi @@ -830,7 +830,7 @@ reg = <0x3 0x082b0000 0x0 0x4000>; clocks = <&clkref>; interrupt-parent = <&aic>; - interrupts = ; + interrupts = ; }; nub_spmi0: spmi@308714000 { From a2fb0b2385dc434dbc678f6658c0eec7fd55b4ad Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:00:58 +1100 Subject: [PATCH 135/342] pmdomain: apple: pmp-report: vote GPU activity on T6000 too, by default T6000 has the AGX soc-device record and request bit of T6001 (soc-device 10, PS-REQ bit 9), and the J314s ships with the PMP running. There the PMP runs the fabric at p-state 3 and DCS at 6 and, without the AGX request, never raises them for the GPU. Holding bit 9 on a J316s booted with the J314s PMP profile (same T6000 SoC, same session, glmark2 800x600 offscreen): PMP off 9938 - 10117 PMP on 7222 - 7327 (-25%) PMP on, AGX request 11909 - 12086 (+19% over PMP off) ANE MobileNet stays at 3.67 ms (4.85 with the PMP off) and idle Total System Power at 5.28 W (6.69 W with the PMP off). Take apple,t6000 into the vote and turn it on by default. It writes only while the PMP runs, so boards that keep the PMP off are unchanged; pmp_report.agx_vote=0 still turns it off. The vote is Joshua Warren's (previous commit); this only widens and enables it. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/pmdomain/apple/pmp-report.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index c61ab5c41b7a5..a31b51683bfbb 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -158,7 +158,7 @@ static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x; /* T6001 AGX request (see the engine below set_state): AGX is soc-device record 9 on the T6001. */ #define APPLE_PMP_T6001_AGX_ID 9 -static bool agx_vote; +static bool agx_vote = true; static struct agx_vote apple_pmp_agx_vote_state = {.idle_ms = AGX_VOTE_IDLE_MS_DEFAULT}; static DEFINE_SPINLOCK(apple_pmp_agx_vote_lock); /* Serializes the vote work, the unbind release and the report's removal. */ @@ -1616,7 +1616,8 @@ static int apple_pmp_report_set_state(struct apple_pmp_report *rep, u32 id, * leaves memory at its idle floor for a GPU that is busy but has not asked. The GPU driver reports operations in flight * (apple_pmp_agx_activity_begin/end); the request is set while any operation runs and cleared agx_vote_idle_ms after the last one ends, at * GPU unbind and when this report goes away. The decisions are in pmp-agx-vote.h (unit tested); this is the glue. - * Off by default (pmp_report.agx_vote): with it off nothing is written. + * On by default (pmp_report.agx_vote): it only writes while the PMP runs, so a board that leaves the PMP off is unchanged; with it off + * nothing is written. T6000 has the same record and bit (soc-device 10, PS-REQ bit 9) as T6001. */ static unsigned int agx_vote_idle_ms = AGX_VOTE_IDLE_MS_DEFAULT; @@ -1653,17 +1654,17 @@ static const struct kernel_param_ops apple_pmp_agx_vote_ops = { .get = param_get_bool, }; module_param_cb(agx_vote, &apple_pmp_agx_vote_ops, &agx_vote, 0644); -MODULE_PARM_DESC(agx_vote, "T6001: set the AGX power request in the PMP report while the GPU has work in flight (default: off)"); +MODULE_PARM_DESC(agx_vote, "T6000/T6001: set the AGX power request in the PMP report while the GPU has work in flight (default: on)"); module_param(agx_vote_idle_ms, uint, 0644); MODULE_PARM_DESC(agx_vote_idle_ms, "Keep the AGX request this many ms after the last GPU operation ends (default: 250)"); -/* Write the AGX request of the bound T6001 report: -ENODEV without one, -EAGAIN (nothing written) when the PMP does not run. */ +/* Write the AGX request of the bound T6000/T6001 report: -ENODEV without one, -EAGAIN (nothing written) when the PMP does not run. */ static int apple_pmp_agx_write(bool enable, bool no_ack) { struct apple_pmp_report *rep; int ret = -ENODEV; - if (!of_machine_is_compatible("apple,t6001")) + if (!of_machine_is_compatible("apple,t6000") && !of_machine_is_compatible("apple,t6001")) return ret; rcu_read_lock(); list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { From e7d56a54f8fe7cadf12a69359cc32bc64ae80213 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:01:18 +1100 Subject: [PATCH 136/342] arm64: dts: apple: t600x: report the JPEG codecs to the PMP With APPLE_USE_PMP, put both JPEG codecs on their PMP report entry (soc-device JPEG0, request bit 19) as AVD, DCP and ISP already are, so the PMP knows when they work. On a J316s with the J314s PMP profile and the AGX vote, NV12 to JPEG encode runs 413-432 fps at 1080p (406-419 without the request) and 107 fps at 4K (105). Boards without APPLE_USE_PMP are unchanged. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000-peripherals.dtsi | 8 ++++++++ arch/arm64/boot/dts/apple/t600x-die0.dtsi | 2 ++ 2 files changed, 10 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi index 57a65f7d8db0d..354ec7f161a77 100644 --- a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi @@ -78,7 +78,11 @@ reg = <0x4 0x09000000 0x0 0x4000>; interrupt-parent = <&aic>; interrupts = ; +#ifdef APPLE_USE_PMP + power-domains = <&pmp_report_jpg>; +#else power-domains = <&ps_jpg>; +#endif clocks = <&peripheral_clocks 354>, <&peripheral_clocks 355>; iommus = <&jpeg0_dart 0>; status = "disabled"; @@ -99,7 +103,11 @@ reg = <0x4 0x09008000 0x0 0x4000>; interrupt-parent = <&aic>; interrupts = ; +#ifdef APPLE_USE_PMP + power-domains = <&pmp_report_jpg>; +#else power-domains = <&ps_jpg>; +#endif clocks = <&peripheral_clocks 354>, <&peripheral_clocks 355>; iommus = <&jpeg1_dart 0>; status = "disabled"; diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi index 63da88e035da3..f113ede85dd1a 100644 --- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi @@ -230,7 +230,9 @@ label = "pmp-jpg"; #power-domain-cells = <0>; power-domains = <&ps_jpg>; +#ifndef APPLE_USE_PMP status = "disabled"; +#endif }; pmp_report_scodec: report@14 { From fc1a72521871ac70ab1bd09fb55bfc49ade7f259 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:05:47 +1100 Subject: [PATCH 137/342] arm64: dts: apple: t8140-j700: enable the second JPEG engine The J700 ADT describes two JPEG engines, jpeg0 and jpeg1, each with its own DART (dart-jpeg0-h17p, dart-jpeg1-h17p) and a JPG0/JPG1 vote on the shared JPG power state. Only jpeg0 is enabled; jpeg1 has been described but disabled since the engines were added. apple-jpeg supports apple,t8140-jpeg, and the other Macs we ship already run both engines. Enable jpeg1 and its DART. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-j700.dts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index 5841470c3c28d..e4634a965e642 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -476,6 +476,14 @@ status = "okay"; }; +&jpeg1_dart { + status = "okay"; +}; + +&jpeg1 { + status = "okay"; +}; + &apr_dart { status = "okay"; }; From be38b34d2a7a6ae7cf322d6b11b1359acd3bc818 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:17:01 +1100 Subject: [PATCH 138/342] tools: asahi: run the AGX vote host suite with the other host tests Register pmp-agx-vote-tests.py (and its mutant run) in run-host-tests.py, which takes the place of the aurora-ci host-tests.json registration that omacom/linux-aurora#334 carries. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- tools/asahi/run-host-tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index e472c9d74cc10..b878404b2d9fa 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -148,6 +148,7 @@ def mutations(flag, names, base, expect=KILL): + [(out('--output') + ['--old-usb'], KILL), (out('--output') + ['--old-regulatory'], KILL)], 'pciec-policy-tests.py': [(out(), PASS)], 'pmgr-bus-tests.py': [([], PASS)], + 'pmp-agx-vote-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], 'pmp-j613-hwmon-tests.py': [([], PASS)], 'pmu-rtc-tests.py': [(out(), PASS)] + mutations('--mutation', ('ack-clobber', 'arm-ack', 'offset-seconds', From 3906fcf2c4b69f82fa3f57c92fde2d0867f4e739 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:22:45 +1100 Subject: [PATCH 139/342] dt-bindings: media: apple,isp: allow 18 power domains The T8112 ISP lists its system domain, the FE domain, twelve set domains and the four ISPSENS sensor domains: 18 in all. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/devicetree/bindings/media/apple,isp.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/apple,isp.yaml b/Documentation/devicetree/bindings/media/apple,isp.yaml index 8b3eb242358d6..6b3ed26aa9640 100644 --- a/Documentation/devicetree/bindings/media/apple,isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,isp.yaml @@ -57,7 +57,7 @@ properties: power-domains: minItems: 7 - maxItems: 16 + maxItems: 18 description: Register-backed power domains required by the ISP. memory-region: From b5a7a3efa1d3cd25c52415e5e5c887cfa6a5329c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:24:53 +1100 Subject: [PATCH 140/342] pmdomain: apple: pmp-report: T600x device performance requests in request classes A report entry can send a SOC-DEV-DVFS performance request with its power request (apple,dvfs), so far only as a level in the default lane, bits 4:0. T6000 devices also take their level in a request class: a four-bit lane at bits 35:32 (class 0x21) through 51:48 (class 0x25). Add apple,dvfs-request-class and build both the active and the release word from it, with KUnit checks of the encodings and the limits. Give the T600x offsets the update aperture and the SOC-DEV-DVFS range (PTD 0x108, 0x28 entries; the ANE level at 0x10c is one of them). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../power/apple,t8140-pmp-report.yaml | 8 ++++++ drivers/pmdomain/apple/pmp-report-test.c | 22 ++++++++++++++++ .../pmdomain/apple/pmp-report-validation.h | 26 +++++++++++++++++++ drivers/pmdomain/apple/pmp-report.c | 25 +++++++++++++----- 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml index 2a8dd3ddc532b..5b36d27734605 100644 --- a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml +++ b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml @@ -143,6 +143,14 @@ patternProperties: level (with the valid bit) to the entry once; before clearing the device request it writes level 0. + apple,dvfs-request-class: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0x21, 0x22, 0x23, 0x24, 0x25] + description: + Request class holding the level. Classes 0x21 through + 0x25 occupy the four-bit fields at bits 35:32 through 51:48. If + absent, apple,dvfs uses the default five-bit field at bits 4:0. + apple,always-on: type: boolean description: Report the device as on from probe. diff --git a/drivers/pmdomain/apple/pmp-report-test.c b/drivers/pmdomain/apple/pmp-report-test.c index d99ece1ac4b6f..204e19fbf28ce 100644 --- a/drivers/pmdomain/apple/pmp-report-test.c +++ b/drivers/pmdomain/apple/pmp-report-test.c @@ -254,6 +254,27 @@ static void pmp_bootargs_reject_integer_width(struct kunit *test) KUNIT_EXPECT_FALSE(test, apple_pmp_bootargs_valid(args, 29)); } +static void pmp_dvfs_words(struct kunit *test) +{ + u64 word; + + KUNIT_ASSERT_TRUE(test, apple_pmp_dvfs_word(0, 2, &word)); + KUNIT_EXPECT_EQ(test, word, 0x2000000000000002ULL); + KUNIT_ASSERT_TRUE(test, apple_pmp_dvfs_word(0x21, 0, &word)); + KUNIT_EXPECT_EQ(test, word, 0x2000000000000000ULL); + KUNIT_ASSERT_TRUE(test, apple_pmp_dvfs_word(0x21, 1, &word)); + KUNIT_EXPECT_EQ(test, word, 0x2000000100000000ULL); + KUNIT_ASSERT_TRUE(test, apple_pmp_dvfs_word(0x21, 2, &word)); + KUNIT_EXPECT_EQ(test, word, 0x2000000200000000ULL); + KUNIT_ASSERT_TRUE(test, apple_pmp_dvfs_word(0x25, 2, &word)); + KUNIT_EXPECT_EQ(test, word, 0x2002000000000000ULL); + KUNIT_EXPECT_FALSE(test, apple_pmp_dvfs_word(0x20, 1, &word)); + KUNIT_EXPECT_FALSE(test, apple_pmp_dvfs_word(0x26, 1, &word)); + KUNIT_EXPECT_FALSE(test, apple_pmp_dvfs_word(0x21, 0x10, &word)); + KUNIT_EXPECT_FALSE(test, apple_pmp_dvfs_word(0, 0x20, &word)); + KUNIT_EXPECT_FALSE(test, apple_pmp_dvfs_word(0x21, 1, NULL)); +} + static struct kunit_case apple_pmp_report_cases[] = { KUNIT_CASE(pmp_ranges_t6030), KUNIT_CASE(pmp_ranges_t8122), @@ -267,6 +288,7 @@ static struct kunit_case apple_pmp_report_cases[] = { KUNIT_CASE(pmp_bootargs_valid_ids), KUNIT_CASE(pmp_bootargs_reject_truncation), KUNIT_CASE(pmp_bootargs_reject_integer_width), + KUNIT_CASE(pmp_dvfs_words), {} }; diff --git a/drivers/pmdomain/apple/pmp-report-validation.h b/drivers/pmdomain/apple/pmp-report-validation.h index 94a682a9f18f2..c3e5ad495650b 100644 --- a/drivers/pmdomain/apple/pmp-report-validation.h +++ b/drivers/pmdomain/apple/pmp-report-validation.h @@ -7,12 +7,38 @@ #include #include +#define PMP_DVFS_VALID BIT_ULL(61) + #define PMP_SOC_DEVICE_SIZE 0x7c #define PMP_SOC_DEVICE_ACK BIT(1) #define PMP_PTD_RANGE_SIZE 32 #define PMP_PTD_RANGE_REQUEST 10 #define PMP_PTD_RANGE_ACK 11 +/* + * A SOC-DEV-DVFS request word: the valid bit, and the level either in the + * default five-bit lane at bits 4:0 or, for request classes 0x21 through + * 0x25, in the four-bit lane at bits 35:32 through 51:48. + */ +static inline bool apple_pmp_dvfs_word(u32 request_class, u32 level, u64 *word) +{ + u32 shift; + + if (!word) + return false; + if (!request_class) { + if (level > 0x1f) + return false; + *word = PMP_DVFS_VALID | level; + return true; + } + if (request_class < 0x21 || request_class > 0x25 || level > 0xf) + return false; + shift = 32 + 4 * (request_class - 0x21); + *word = PMP_DVFS_VALID | (u64)level << shift; + return true; +} + /* The PTD request read, request update and acknowledgment apertures. */ static inline bool apple_pmp_ranges_valid(const u8 *table, size_t len, u32 request_read, u32 request_write, diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index a31b51683bfbb..789cab1c29397 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -1415,6 +1415,9 @@ static int apple_pmp_report_probe(struct platform_device *pdev) static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x = { .tgt_read = 0xf80, .tgt_write = 0x107c0, + .update = 0x10000, + .dvfs_first = 0x108, + .dvfs_count = 0x28, .actual = 0x1000, .status = 0x10, }; @@ -1567,6 +1570,7 @@ struct apple_pmp_report_entry { */ bool dvfs; u32 dvfs_entry; + u64 dvfs_off; u64 dvfs_on; bool removed; }; @@ -1885,9 +1889,6 @@ int apple_pmp_report_set_t6030_gfx(struct device *supplier, bool enable) return apple_pmp_report_t6030_gfx(supplier, &enable); } EXPORT_SYMBOL_GPL(apple_pmp_report_set_t6030_gfx); -/* SOC-DEV-DVFS request words carry a valid bit; level 0 is the floor. */ -#define PMP_DVFS_VALID BIT_ULL(61) - /* * One 64-bit store of the whole request word. Never read a request entry * back after storing it: the read retires the pending PTD update before the @@ -1960,7 +1961,7 @@ static int apple_pmp_report_entry_set_state(struct generic_pm_domain *genpd, boo continue; /* The device request is admitted first and the level dropped first. */ if (ent->dvfs && !enable) - apple_pmp_report_dvfs_write(rep, ent->dvfs_entry, PMP_DVFS_VALID); + apple_pmp_report_dvfs_write(rep, ent->dvfs_entry, ent->dvfs_off); ret = apple_pmp_report_set_state(rep, ent->id, enable, ent->no_ack); if (ent->dvfs && enable && !ret) apple_pmp_report_dvfs_write(rep, ent->dvfs_entry, ent->dvfs_on); @@ -2118,18 +2119,28 @@ static int apple_pmp_report_entry_probe(struct platform_device *pdev) } ent->sleep_release = of_property_read_bool(node, "apple,release-for-sleep"); if (of_property_present(node, "apple,dvfs")) { + u32 request_class = 0; u32 dvfs[2]; + if (of_property_read_u32(node, "apple,dvfs-request-class", + &request_class) && + of_property_present(node, "apple,dvfs-request-class")) { + ret = dev_err_probe(dev, -EINVAL, + "invalid apple,dvfs-request-class\n"); + goto err_free; + } ret = of_property_read_u32_array(node, "apple,dvfs", dvfs, 2); - if (ret || !rep || !rep->offsets->update || dvfs[1] > 0x1f || + if (ret || of_property_count_u32_elems(node, "apple,dvfs") != 2 || + !rep || !rep->offsets->update || dvfs[0] < rep->offsets->dvfs_first || - dvfs[0] >= rep->offsets->dvfs_first + rep->offsets->dvfs_count) { + dvfs[0] >= rep->offsets->dvfs_first + rep->offsets->dvfs_count || + !apple_pmp_dvfs_word(request_class, 0, &ent->dvfs_off) || + !apple_pmp_dvfs_word(request_class, dvfs[1], &ent->dvfs_on)) { ret = dev_err_probe(dev, -EINVAL, "invalid apple,dvfs\n"); goto err_free; } ent->dvfs = true; ent->dvfs_entry = dvfs[0]; - ent->dvfs_on = PMP_DVFS_VALID | dvfs[1]; } ret = of_property_read_string(node, "label", &name); From 2795fdb85d3319bee2f32859b0497fbdeb8d1654 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:24:53 +1100 Subject: [PATCH 141/342] arm64: dts: apple: t6000: AVD and JPEG performance requests to the PMP With APPLE_USE_PMP the PMP runs the fabric and DCS low, and AVD and the JPEG codecs asked it for nothing: on a J316s with the J314s PMP profile, AVD decode ran about 40% slower than with the PMP off and 4K JPEG encode about 12% slower. Let their report entries send level 2 in request class 0x21 of SOC-DEV-DVFS entries 0x112 (AVD) and 0x114 (JPEG, shared by both codecs) while they are powered; the level is dropped before the power request. Only boards with APPLE_USE_PMP are affected. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 6c5e086626bda..291c854d8cabf 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -85,6 +85,24 @@ reg-names = "report", "ane-dvfs"; }; +#ifdef APPLE_USE_PMP +/* + * AVD and the JPEG codecs (one shared soc-device) also send the PMP a + * performance request while they are powered: level 2 (VMAX) in request + * class 0x21 of their SOC-DEV-DVFS entries, 0x112 and 0x114. The PMP then + * holds the SoC rail and fabric up for them. + */ +&pmp_report_avd_sys { + apple,dvfs = <0x112 2>; + apple,dvfs-request-class = <0x21>; +}; + +&pmp_report_jpg { + apple,dvfs = <0x114 2>; + apple,dvfs-request-class = <0x21>; +}; +#endif + &ane { apple,performance-controller = <&pmp_report>; power-domains = <&ps_ane_sys_cpu>, <&ps_ane_set1>, From b6c76e4a3ce5096b2e9ffe01d9393f803ac2e588 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:38:28 +1100 Subject: [PATCH 142/342] arm64: dts: apple: t8140: give the ISP power states their ADT parents The J700 ADT power tree chains the ISP states: ISP_SYS -> ISP_CPU -> CORE0/1, ISP_SYS -> ISP_FE -> DPRX, SECURE, STS0/1, PEARL, BE, and BE -> CLR, CVD -> CVM. None of the parents were described. The ISP driver attaches all of these domains and holds them on while its firmware is resident, so the parent links only order transitions the way the hardware requires. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-pmgr.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi index 7aa9f2bd3a102..7123e79b3498a 100644 --- a/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8140-pmgr.dtsi @@ -288,6 +288,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_cpu"; + power-domains = <&ps_isp_sys>; }; ps_isp_cpu_core0: power-controller@4008 { @@ -296,6 +297,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_cpu_core0"; + power-domains = <&ps_isp_cpu>; }; ps_isp_cpu_core1: power-controller@4010 { @@ -304,6 +306,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_cpu_core1"; + power-domains = <&ps_isp_cpu>; }; ps_isp_fe: power-controller@4018 { @@ -312,6 +315,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_fe"; + power-domains = <&ps_isp_sys>; }; ps_isp_dprx: power-controller@4020 { @@ -320,6 +324,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_dprx"; + power-domains = <&ps_isp_fe>; }; ps_isp_secure: power-controller@4028 { @@ -328,6 +333,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_secure"; + power-domains = <&ps_isp_fe>; }; ps_isp_sts0: power-controller@4030 { @@ -336,6 +342,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_sts0"; + power-domains = <&ps_isp_fe>; }; ps_isp_sts1: power-controller@4038 { @@ -344,6 +351,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_sts1"; + power-domains = <&ps_isp_fe>; }; ps_isp_pearl: power-controller@4040 { @@ -352,6 +360,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_pearl"; + power-domains = <&ps_isp_fe>; }; ps_isp_be: power-controller@4048 { @@ -360,6 +369,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_be"; + power-domains = <&ps_isp_fe>; }; ps_isp_clr: power-controller@4050 { @@ -368,6 +378,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_clr"; + power-domains = <&ps_isp_be>; }; ps_isp_cvd: power-controller@4058 { @@ -376,6 +387,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_cvd"; + power-domains = <&ps_isp_be>; }; ps_isp_cvm: power-controller@4060 { @@ -384,6 +396,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "isp_cvm"; + power-domains = <&ps_isp_cvd>; }; ps_disp_cpu: power-controller@10000 { compatible = "apple,t8140-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; From 7b73e8a2706b4ea1785e8b19976ce96ec885f168 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:12:30 +1100 Subject: [PATCH 143/342] EDAC: apple_soc: add T6000 platform error and event-log handlers Register the T6000 (M1 Pro) error-handler and event-log interrupt groups. The error-handler has 76 lines in 17 groups. Claim SEP, IOA, NI0-NI8 and NSR; leave AMCC, DCS, NSC and NSI unclaimed as on T6041. PMGR has no line on this SoC. All 28 event-log lines are claimed. T6000 uses the IRQ-only path, as T8140 does: the T6041 NI status offset has not been checked on this SoC, so no status window is mapped. Enable both nodes on T6000. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6000.dtsi | 9 ++++++++ drivers/edac/apple_soc_edac.c | 32 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index d4bd9a56fbc6e..725901e1ea630 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -114,6 +114,15 @@ #include "t6000-peripherals.dtsi" #include "t6000-aux-spmi.dtsi" +/* Platform error and event-log interrupt groups (apple_soc_edac). */ +&soc_errors { + status = "okay"; +}; + +&soc_events { + status = "okay"; +}; + &apr0_dart { status = "okay"; }; diff --git a/drivers/edac/apple_soc_edac.c b/drivers/edac/apple_soc_edac.c index 1626a19dcd8f0..24aec4c6abcd0 100644 --- a/drivers/edac/apple_soc_edac.c +++ b/drivers/edac/apple_soc_edac.c @@ -85,6 +85,25 @@ static const struct apple_soc_edac_range t6041_error_ranges[] = { { 68, 2, "ni6" }, }; +/* + * T6000 follows the T6041 policy: the AMCC, DCS, NSC and NSI lines stay + * unclaimed. PMGR has no interrupt line on this SoC. + */ +static const struct apple_soc_edac_range t6000_error_ranges[] = { + { 0, 8, "sep" }, + { 12, 4, "ioa" }, + { 32, 4, "ni0" }, + { 36, 3, "ni1" }, + { 39, 3, "ni2" }, + { 42, 2, "ni3" }, + { 44, 2, "ni4" }, + { 46, 4, "ni5" }, + { 50, 4, "ni6" }, + { 54, 4, "ni7" }, + { 58, 4, "ni8" }, + { 72, 4, "nsr" }, +}; + static const struct apple_soc_edac_range t8140_error_ranges[] = { { 4, 1, "pmgr" }, { 5, 9, "sep" }, @@ -98,6 +117,12 @@ static const struct apple_soc_edac_range t8140_error_ranges[] = { { 25, 1, "pio" }, }; +static const struct apple_soc_edac_hw t6000_error_hw = { + .ranges = t6000_error_ranges, + .nranges = ARRAY_SIZE(t6000_error_ranges), + .num_irqs = 76, +}; + static const struct apple_soc_edac_hw t6041_error_hw = { .ranges = t6041_error_ranges, .nranges = ARRAY_SIZE(t6041_error_ranges), @@ -111,6 +136,11 @@ static const struct apple_soc_edac_hw t8140_error_hw = { .num_irqs = 26, }; +static const struct apple_soc_edac_hw t6000_event_hw = { + .num_irqs = 28, + .event_log = true, +}; + static const struct apple_soc_edac_hw t6041_event_hw = { .num_irqs = 21, .event_log = true, @@ -353,8 +383,10 @@ static void apple_soc_edac_remove(struct platform_device *pdev) } static const struct of_device_id apple_soc_edac_of_match[] = { + { .compatible = "apple,t6000-error-handler", .data = &t6000_error_hw }, { .compatible = "apple,t6041-error-handler", .data = &t6041_error_hw }, { .compatible = "apple,t8140-error-handler", .data = &t8140_error_hw }, + { .compatible = "apple,t6000-event-log", .data = &t6000_event_hw }, { .compatible = "apple,t6041-event-log", .data = &t6041_event_hw }, { .compatible = "apple,t8140-event-log", .data = &t8140_event_hw }, { } From edc50a79270258f206000cdef9598ba747489714 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:35:45 +1100 Subject: [PATCH 144/342] EDAC: apple_soc: add the T8112 event-log handler Claim the 16 T8112 (M2) event-log lines and enable the node. The T8112 error-handler stays unclaimed: unlike T6000 and T6041, its ADT node does not describe which line belongs to which source group. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8112.dtsi | 5 +++++ drivers/edac/apple_soc_edac.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 3b733a4e61b1b..f431618ee6d2c 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -2654,6 +2654,11 @@ #include "t8112-peripherals.dtsi" +/* Event-log interrupt group (apple_soc_edac). */ +&m2_event_log_handler { + status = "okay"; +}; + /* Both JPEG encoders are SoC blocks with no board wiring. */ &m2_dart_jpeg0 { status = "okay"; diff --git a/drivers/edac/apple_soc_edac.c b/drivers/edac/apple_soc_edac.c index 24aec4c6abcd0..0733a2712d4a4 100644 --- a/drivers/edac/apple_soc_edac.c +++ b/drivers/edac/apple_soc_edac.c @@ -141,6 +141,11 @@ static const struct apple_soc_edac_hw t6000_event_hw = { .event_log = true, }; +static const struct apple_soc_edac_hw t8112_event_hw = { + .num_irqs = 16, + .event_log = true, +}; + static const struct apple_soc_edac_hw t6041_event_hw = { .num_irqs = 21, .event_log = true, @@ -388,6 +393,7 @@ static const struct of_device_id apple_soc_edac_of_match[] = { { .compatible = "apple,t8140-error-handler", .data = &t8140_error_hw }, { .compatible = "apple,t6000-event-log", .data = &t6000_event_hw }, { .compatible = "apple,t6041-event-log", .data = &t6041_event_hw }, + { .compatible = "apple,t8112-event-log", .data = &t8112_event_hw }, { .compatible = "apple,t8140-event-log", .data = &t8140_event_hw }, { } }; From cf04ed335f2c4d0f22f6547b0ba69473fa32e7ed Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:12:42 +1100 Subject: [PATCH 145/342] arm64: dts: apple: t6000: mark the video decoder dma-coherent The T6000 AVD is IO-coherent in both directions. This was measured on an M1 Pro (J316s) with every cache operation skipped (V4L2_MEMORY_FLAG_NON_COHERENT plus V4L2_BUF_FLAG_NO_CACHE_CLEAN and NO_CACHE_INVALIDATE), one picture in flight, H.264 and HEVC 1080p: - CPU-dirtied CAPTURE buffers decode bit-exact; - CPU-cached CAPTURE buffers read back bit-exact without an invalidate; - bitstream OUTPUT buffers written through a cacheable mapping and queued without a clean decode bit-exact. Without dma-coherent every decoded frame is mapped uncached. On this SoC a consumer that reads every frame gets about 0.2 GB/s from it. Results, same Mac, avd-bench, every frame checked against the software decode: stock dma-coherent h264 1080p, Q16 1047-1090 fps 1103-1112 fps hevc 1080p, Q16 1207-1229 fps 1221-1236 fps h264 1080p, Q1 286-293 fps 300 fps read every frame 197 MB/s 24821 MB/s (35.3 ms/frame) (0.28 ms/frame) decode + read, h264 28.2 fps 1110.6 fps There were no DART faults and every result is bit-exact. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t6000.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 725901e1ea630..c3c98ce5ec83b 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -111,6 +111,11 @@ status = "disabled"; }; +/* The video decoder is IO-coherent in both directions. */ +&avd { + dma-coherent; +}; + #include "t6000-peripherals.dtsi" #include "t6000-aux-spmi.dtsi" From 8ee6096f8b61eac1514e369e760b7ada7ac8e631 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:19:34 +1100 Subject: [PATCH 146/342] arm64: dts: apple: t8112-j413: add CPU thermal zones The MacBook Air (M2) is fanless, but its device tree had no thermal zone apart from the battery, so nothing throttled the CPU on heat before the SMC's own protection. Describe the SoC die temperatures the T8112 SMC reports as hwmon channels (die maximum, E cluster, four P-core sensors), make the SMC hwmon a thermal sensor provider and the CPUs cooling devices, and list the GPU and CPU die keys for the hwmon SoC die zone. The J413 gets the zones the J613 (MacBook Air, M3) uses: one per die sensor, each throttling both clusters with E weighted 3:1 and capped at state 3, with the J613 alert and control trips (58 C and 95 C). There is no critical trip: these keys read past 100 C for a second or two in boot load bursts, a critical trip there powers the Mac off, and the SMC keeps its own protection. The keys were mapped on a J413 by loading the E cluster, the P cluster and the GPU in turn: Te05 follows the E cluster, Tp01, Tp05, Tp09 and Tp0D follow the P cluster, and Tg0f, Tg0n and Tg0r follow the GPU. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-j413.dts | 227 +++++++++++++++++++++++ arch/arm64/boot/dts/apple/t8112.dtsi | 46 +++++ 2 files changed, 273 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 6bea58173d2ab..176e6a4784f2d 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -12,10 +12,12 @@ #include "t8112.dtsi" #include "t8112-jxxx.dtsi" #include +#include / { compatible = "apple,j413", "apple,t8112", "apple,arm-platform"; model = "Apple MacBook Air (13-inch, M2, 2022)"; + chassis-type = "laptop"; aliases { @@ -375,3 +377,228 @@ status = "disabled"; }; }; + +/ { + /* + * Fanless: every die sensor throttles both clusters, E weighted 3:1 + * and capped at state 3, as on the J613, with its alert and control + * trips. No critical trip: boot load bursts briefly read past 100 C, + * and the SMC keeps its own protection. + */ + thermal-zones { + cpu-e0-thermal { + polling-delay-passive = <500>; + polling-delay = <500>; + thermal-sensors = <&smc_hwmon 1>; /* Te05 */ + sustainable-power = <6000>; + + trips { + cpu_e0_alert: trip-alert { + temperature = <58000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_e0_control: trip-control { + temperature = <95000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_e0_control>; + cooling-device = + <&cpu_p0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + contribution = <1024>; + }; + + map1 { + trip = <&cpu_e0_control>; + cooling-device = + <&cpu_e0 THERMAL_NO_LIMIT 3>, + <&cpu_e1 THERMAL_NO_LIMIT 3>, + <&cpu_e2 THERMAL_NO_LIMIT 3>, + <&cpu_e3 THERMAL_NO_LIMIT 3>; + contribution = <3072>; + }; + }; + }; + + cpu-p0-thermal { + polling-delay-passive = <500>; + polling-delay = <500>; + thermal-sensors = <&smc_hwmon 2>; /* Tp01 */ + sustainable-power = <6000>; + + trips { + cpu_p0_alert: trip-alert { + temperature = <58000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p0_control: trip-control { + temperature = <95000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p0_control>; + cooling-device = + <&cpu_p0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + contribution = <1024>; + }; + + map1 { + trip = <&cpu_p0_control>; + cooling-device = + <&cpu_e0 THERMAL_NO_LIMIT 3>, + <&cpu_e1 THERMAL_NO_LIMIT 3>, + <&cpu_e2 THERMAL_NO_LIMIT 3>, + <&cpu_e3 THERMAL_NO_LIMIT 3>; + contribution = <3072>; + }; + }; + }; + + cpu-p1-thermal { + polling-delay-passive = <500>; + polling-delay = <500>; + thermal-sensors = <&smc_hwmon 3>; /* Tp05 */ + sustainable-power = <6000>; + + trips { + cpu_p1_alert: trip-alert { + temperature = <58000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p1_control: trip-control { + temperature = <95000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p1_control>; + cooling-device = + <&cpu_p0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + contribution = <1024>; + }; + + map1 { + trip = <&cpu_p1_control>; + cooling-device = + <&cpu_e0 THERMAL_NO_LIMIT 3>, + <&cpu_e1 THERMAL_NO_LIMIT 3>, + <&cpu_e2 THERMAL_NO_LIMIT 3>, + <&cpu_e3 THERMAL_NO_LIMIT 3>; + contribution = <3072>; + }; + }; + }; + + cpu-p2-thermal { + polling-delay-passive = <500>; + polling-delay = <500>; + thermal-sensors = <&smc_hwmon 4>; /* Tp09 */ + sustainable-power = <6000>; + + trips { + cpu_p2_alert: trip-alert { + temperature = <58000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p2_control: trip-control { + temperature = <95000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p2_control>; + cooling-device = + <&cpu_p0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + contribution = <1024>; + }; + + map1 { + trip = <&cpu_p2_control>; + cooling-device = + <&cpu_e0 THERMAL_NO_LIMIT 3>, + <&cpu_e1 THERMAL_NO_LIMIT 3>, + <&cpu_e2 THERMAL_NO_LIMIT 3>, + <&cpu_e3 THERMAL_NO_LIMIT 3>; + contribution = <3072>; + }; + }; + }; + + cpu-p3-thermal { + polling-delay-passive = <500>; + polling-delay = <500>; + thermal-sensors = <&smc_hwmon 5>; /* Tp0D */ + sustainable-power = <6000>; + + trips { + cpu_p3_alert: trip-alert { + temperature = <58000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p3_control: trip-control { + temperature = <95000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p3_control>; + cooling-device = + <&cpu_p0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + contribution = <1024>; + }; + + map1 { + trip = <&cpu_p3_control>; + cooling-device = + <&cpu_e0 THERMAL_NO_LIMIT 3>, + <&cpu_e1 THERMAL_NO_LIMIT 3>, + <&cpu_e2 THERMAL_NO_LIMIT 3>, + <&cpu_e3 THERMAL_NO_LIMIT 3>; + contribution = <3072>; + }; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index f9ead58538938..3b3d9b499f053 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -75,6 +75,7 @@ next-level-cache = <&l2_cache_0>; i-cache-size = <0x20000>; d-cache-size = <0x10000>; + #cooling-cells = <2>; }; cpu_e1: cpu@1 { @@ -89,6 +90,7 @@ next-level-cache = <&l2_cache_0>; i-cache-size = <0x20000>; d-cache-size = <0x10000>; + #cooling-cells = <2>; }; cpu_e2: cpu@2 { @@ -103,6 +105,7 @@ next-level-cache = <&l2_cache_0>; i-cache-size = <0x20000>; d-cache-size = <0x10000>; + #cooling-cells = <2>; }; cpu_e3: cpu@3 { @@ -117,6 +120,7 @@ next-level-cache = <&l2_cache_0>; i-cache-size = <0x20000>; d-cache-size = <0x10000>; + #cooling-cells = <2>; }; cpu_p0: cpu@10100 { @@ -131,6 +135,7 @@ next-level-cache = <&l2_cache_1>; i-cache-size = <0x30000>; d-cache-size = <0x20000>; + #cooling-cells = <2>; }; cpu_p1: cpu@10101 { @@ -145,6 +150,7 @@ next-level-cache = <&l2_cache_1>; i-cache-size = <0x30000>; d-cache-size = <0x20000>; + #cooling-cells = <2>; }; cpu_p2: cpu@10102 { @@ -159,6 +165,7 @@ next-level-cache = <&l2_cache_1>; i-cache-size = <0x30000>; d-cache-size = <0x20000>; + #cooling-cells = <2>; }; cpu_p3: cpu@10103 { @@ -173,6 +180,7 @@ next-level-cache = <&l2_cache_1>; i-cache-size = <0x30000>; d-cache-size = <0x20000>; + #cooling-cells = <2>; }; l2_cache_0: l2-cache-0 { @@ -1538,6 +1546,44 @@ smc_hwmon: hwmon { compatible = "apple,smc-hwmon"; + #thermal-sensor-cells = <1>; + /* + * The GPU keys read a fixed low value while the GPU + * is idle, then the CPU die keys. + */ + apple,soc-die-keys = "Tg0f", "Tg0n", "Tg0r", "Te05", + "Tp01", "Tp05", "Tp09", "Tp0D"; + + /* SoC die temperatures, first: thermal zones index them. */ + temperature-TCMz { + apple,key-id = "TCMz"; + label = "SoC Die Temperature"; + }; + + temperature-Te05 { + apple,key-id = "Te05"; + label = "E-cluster Temperature"; + }; + + temperature-Tp01 { + apple,key-id = "Tp01"; + label = "P-core 0 Temperature"; + }; + + temperature-Tp05 { + apple,key-id = "Tp05"; + label = "P-core 1 Temperature"; + }; + + temperature-Tp09 { + apple,key-id = "Tp09"; + label = "P-core 2 Temperature"; + }; + + temperature-Tp0D { + apple,key-id = "Tp0D"; + label = "P-core 3 Temperature"; + }; }; smc_rtc: rtc { From 8460aaf8a4836c9cada9a6ea576b288c8f22acad Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:46:51 +1100 Subject: [PATCH 147/342] arm64: dts: apple: adt-coverage: map the J700 power states we describe 61 J700 PMGR records were waived as virtual votes with no power-state register. Each one has a register and a power-controller node in our tree: the ISP sub-states, the AOP and audio states, and SMC_FABRIC. Map them to their nodes and drop their waivers. They were matched by PMGR group and register offset, and the labels were checked against the ADT names. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../dts/apple/adt-coverage/t8140-j700.txt | 122 +++++++++--------- .../boot/dts/apple/adt-coverage/waivers.txt | 61 --------- 2 files changed, 61 insertions(+), 122 deletions(-) diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t8140-j700.txt b/arch/arm64/boot/dts/apple/adt-coverage/t8140-j700.txt index cc87cbfe22276..c21a03f535c60 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t8140-j700.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t8140-j700.txt @@ -179,19 +179,19 @@ /arm-io/pmgr/power-devices/ATC0_COMMON 0x3007003e8 -> /soc/power-management@300700000/power-controller@3e8 /arm-io/pmgr/power-devices/ATC0_USB 0x3007003f0 -> /soc/power-management@300700000/power-controller@3f0 /arm-io/pmgr/power-devices/SEP 0x300700c00 -> /soc/power-management@300700000/power-controller@c00 -/arm-io/pmgr/power-devices/ISP_CPU - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CPU_CORE0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CPU_CORE1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_FE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DPRX - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_SECURE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_STS0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_STS1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_PEARL - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_BE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CLR - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CVD - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CVM - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/ISP_CPU 0x300704000 -> /soc/power-management@300700000/power-controller@4000 +/arm-io/pmgr/power-devices/ISP_CPU_CORE0 0x300704008 -> /soc/power-management@300700000/power-controller@4008 +/arm-io/pmgr/power-devices/ISP_CPU_CORE1 0x300704010 -> /soc/power-management@300700000/power-controller@4010 +/arm-io/pmgr/power-devices/ISP_FE 0x300704018 -> /soc/power-management@300700000/power-controller@4018 +/arm-io/pmgr/power-devices/DPRX 0x300704020 -> /soc/power-management@300700000/power-controller@4020 +/arm-io/pmgr/power-devices/ISP_SECURE 0x300704028 -> /soc/power-management@300700000/power-controller@4028 +/arm-io/pmgr/power-devices/ISP_STS0 0x300704030 -> /soc/power-management@300700000/power-controller@4030 +/arm-io/pmgr/power-devices/ISP_STS1 0x300704038 -> /soc/power-management@300700000/power-controller@4038 +/arm-io/pmgr/power-devices/ISP_PEARL 0x300704040 -> /soc/power-management@300700000/power-controller@4040 +/arm-io/pmgr/power-devices/ISP_BE 0x300704048 -> /soc/power-management@300700000/power-controller@4048 +/arm-io/pmgr/power-devices/ISP_CLR 0x300704050 -> /soc/power-management@300700000/power-controller@4050 +/arm-io/pmgr/power-devices/ISP_CVD 0x300704058 -> /soc/power-management@300700000/power-controller@4058 +/arm-io/pmgr/power-devices/ISP_CVM 0x300704060 -> /soc/power-management@300700000/power-controller@4060 /arm-io/pmgr/power-devices/VENC0_DMA 0x300708000 -> /soc/power-management@300700000/power-controller@8000 /arm-io/pmgr/power-devices/VENC0_PIPE4 0x300708008 -> /soc/power-management@300700000/power-controller@8008 /arm-io/pmgr/power-devices/VENC0_PIPE5 0x300708010 -> /soc/power-management@300700000/power-controller@8010 @@ -225,56 +225,56 @@ /arm-io/pmgr/power-devices/NUB_FABRIC 0x3082800a0 -> /soc/power-management@308280000/power-controller@a0 /arm-io/pmgr/power-devices/NUB_SRAM 0x3082800a8 -> /soc/power-management@308280000/power-controller@a8 /arm-io/pmgr/power-devices/DEBUG_SWITCH 0x3082800b0 -> /soc/power-management@308280000/power-controller@b0 -/arm-io/pmgr/power-devices/AOP_FILTER - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_GPIO - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_BASE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_FR - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SHIM - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_PIODMA - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP2_PIODMA - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_I2CM0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_I2CM1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_I2CM2 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_I2CM3 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SCM - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SPI0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SPI1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SPMI0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SPMI1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_HE_NRCS0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_HE_NRCS1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_CPU - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP2_CPU - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_FR - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_UART0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_UART1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_UART2 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AOP_SRAM - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_P - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_SENSE_PDMC - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_BASE_S_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_BASE_NS_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_MCA - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA0_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA1_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA2_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA3_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA4_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_MCA5_M - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_C - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_S_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_NS_A - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_RX0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_RX1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_RX2 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_RX3 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_RX4 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/AUDIO_LEAP_TX0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/AOP_FILTER 0x308284000 -> /soc/power-management@308280000/power-controller@4000 +/arm-io/pmgr/power-devices/AOP_GPIO 0x308284008 -> /soc/power-management@308280000/power-controller@4008 +/arm-io/pmgr/power-devices/AOP_BASE 0x308284010 -> /soc/power-management@308280000/power-controller@4010 +/arm-io/pmgr/power-devices/AOP_FR 0x308284018 -> /soc/power-management@308280000/power-controller@4018 +/arm-io/pmgr/power-devices/AUDIO_A 0x308284020 -> /soc/power-management@308280000/power-controller@4020 +/arm-io/pmgr/power-devices/AOP_SHIM 0x308284028 -> /soc/power-management@308280000/power-controller@4028 +/arm-io/pmgr/power-devices/AOP_PIODMA 0x308284030 -> /soc/power-management@308280000/power-controller@4030 +/arm-io/pmgr/power-devices/AOP2_PIODMA 0x308284038 -> /soc/power-management@308280000/power-controller@4038 +/arm-io/pmgr/power-devices/AOP_I2CM0 0x308284040 -> /soc/power-management@308280000/power-controller@4040 +/arm-io/pmgr/power-devices/AOP_I2CM1 0x308284048 -> /soc/power-management@308280000/power-controller@4048 +/arm-io/pmgr/power-devices/AOP_I2CM2 0x308284050 -> /soc/power-management@308280000/power-controller@4050 +/arm-io/pmgr/power-devices/AOP_I2CM3 0x308284058 -> /soc/power-management@308280000/power-controller@4058 +/arm-io/pmgr/power-devices/AOP_SCM 0x308284060 -> /soc/power-management@308280000/power-controller@4060 +/arm-io/pmgr/power-devices/AOP_SPI0 0x308284068 -> /soc/power-management@308280000/power-controller@4068 +/arm-io/pmgr/power-devices/AOP_SPI1 0x308284070 -> /soc/power-management@308280000/power-controller@4070 +/arm-io/pmgr/power-devices/AOP_SPMI0 0x308284078 -> /soc/power-management@308280000/power-controller@4078 +/arm-io/pmgr/power-devices/AOP_SPMI1 0x308284080 -> /soc/power-management@308280000/power-controller@4080 +/arm-io/pmgr/power-devices/AOP_HE_NRCS0 0x308284088 -> /soc/power-management@308280000/power-controller@4088 +/arm-io/pmgr/power-devices/AOP_HE_NRCS1 0x308284090 -> /soc/power-management@308280000/power-controller@4090 +/arm-io/pmgr/power-devices/AOP_CPU 0x308284098 -> /soc/power-management@308280000/power-controller@4098 +/arm-io/pmgr/power-devices/AOP2_CPU 0x3082840a0 -> /soc/power-management@308280000/power-controller@40a0 +/arm-io/pmgr/power-devices/AUDIO_FR 0x3082840a8 -> /soc/power-management@308280000/power-controller@40a8 +/arm-io/pmgr/power-devices/AOP_UART0 0x3082840b0 -> /soc/power-management@308280000/power-controller@40b0 +/arm-io/pmgr/power-devices/AOP_UART1 0x3082840b8 -> /soc/power-management@308280000/power-controller@40b8 +/arm-io/pmgr/power-devices/AOP_UART2 0x3082840c0 -> /soc/power-management@308280000/power-controller@40c0 +/arm-io/pmgr/power-devices/AOP_SRAM 0x3082840c8 -> /soc/power-management@308280000/power-controller@40c8 +/arm-io/pmgr/power-devices/AUDIO_P 0x3082840d0 -> /soc/power-management@308280000/power-controller@40d0 +/arm-io/pmgr/power-devices/AUDIO_LEAP_A 0x3082840d8 -> /soc/power-management@308280000/power-controller@40d8 +/arm-io/pmgr/power-devices/AUDIO_SENSE_PDMC 0x3082840e0 -> /soc/power-management@308280000/power-controller@40e0 +/arm-io/pmgr/power-devices/AUDIO_BASE_S_A 0x3082840e8 -> /soc/power-management@308280000/power-controller@40e8 +/arm-io/pmgr/power-devices/AUDIO_BASE_NS_A 0x3082840f0 -> /soc/power-management@308280000/power-controller@40f0 +/arm-io/pmgr/power-devices/AUDIO_LEAP_MCA 0x3082840f8 -> /soc/power-management@308280000/power-controller@40f8 +/arm-io/pmgr/power-devices/AUDIO_MCA0_M 0x308284100 -> /soc/power-management@308280000/power-controller@4100 +/arm-io/pmgr/power-devices/AUDIO_MCA1_M 0x308284108 -> /soc/power-management@308280000/power-controller@4108 +/arm-io/pmgr/power-devices/AUDIO_MCA2_M 0x308284110 -> /soc/power-management@308280000/power-controller@4110 +/arm-io/pmgr/power-devices/AUDIO_MCA3_M 0x308284118 -> /soc/power-management@308280000/power-controller@4118 +/arm-io/pmgr/power-devices/AUDIO_MCA4_M 0x308284120 -> /soc/power-management@308280000/power-controller@4120 +/arm-io/pmgr/power-devices/AUDIO_MCA5_M 0x308284128 -> /soc/power-management@308280000/power-controller@4128 +/arm-io/pmgr/power-devices/AUDIO_LEAP_C 0x308284130 -> /soc/power-management@308280000/power-controller@4130 +/arm-io/pmgr/power-devices/AUDIO_LEAP_S_A 0x308284138 -> /soc/power-management@308280000/power-controller@4138 +/arm-io/pmgr/power-devices/AUDIO_LEAP_NS_A 0x308284140 -> /soc/power-management@308280000/power-controller@4140 +/arm-io/pmgr/power-devices/AUDIO_LEAP_RX0 0x308284148 -> /soc/power-management@308280000/power-controller@4148 +/arm-io/pmgr/power-devices/AUDIO_LEAP_RX1 0x308284150 -> /soc/power-management@308280000/power-controller@4150 +/arm-io/pmgr/power-devices/AUDIO_LEAP_RX2 0x308284158 -> /soc/power-management@308280000/power-controller@4158 +/arm-io/pmgr/power-devices/AUDIO_LEAP_RX3 0x308284160 -> /soc/power-management@308280000/power-controller@4160 +/arm-io/pmgr/power-devices/AUDIO_LEAP_RX4 0x308284168 -> /soc/power-management@308280000/power-controller@4168 +/arm-io/pmgr/power-devices/AUDIO_LEAP_TX0 0x308284170 -> /soc/power-management@308280000/power-controller@4170 /arm-io/pmgr/power-devices/PDM0_AUDIO_REF - -> WAIVED: Virtual PMGR vote; no independent power-state register. /arm-io/pmgr/power-devices/PDM1_AUDIO_REF - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/SMC_FABRIC - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/SMC_FABRIC 0x308288000 -> /soc/power-management@308280000/power-controller@8000 /arm-io/pmgr/power-devices/SMC_GPIO - -> WAIVED: Virtual PMGR vote; no independent power-state register. /arm-io/pmgr/power-devices/SMC_AON - -> WAIVED: Virtual PMGR vote; no independent power-state register. /arm-io/pmgr/power-devices/SMC_UART0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. diff --git a/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt b/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt index 84e0a31edc326..097e09dd16bbe 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt @@ -608,30 +608,6 @@ t8140-j700 /arm-io/pmgr/power-devices/AMCC0_P3 | Virtual PMGR vote; no independe t8140-j700 /arm-io/pmgr/power-devices/ANE-SYS-V | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ANE-SYS-V-PMP | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ANE_CPU | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP2_CPU | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP2_PIODMA | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_BASE | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_CPU | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_FILTER | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_FR | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_GPIO | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_HE_NRCS0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_HE_NRCS1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_I2CM0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_I2CM1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_I2CM2 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_I2CM3 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_PIODMA | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SCM | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SHIM | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SPI0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SPI1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SPMI0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SPMI1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_SRAM | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_UART0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_UART1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AOP_UART2 | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/APCIE_SYS_ST-V | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ATC0-DCS-F1 | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ATC0-DCS-F2 | Virtual PMGR vote; no independent power-state register. @@ -642,29 +618,6 @@ t8140-j700 /arm-io/pmgr/power-devices/ATC0-USB-AUD-V | Virtual PMGR vote; no ind t8140-j700 /arm-io/pmgr/power-devices/ATC0-USB-DART | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/AUDIO-LLT-V | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/AUDIO-P-V | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_BASE_NS_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_BASE_S_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_FR | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_C | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_MCA | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_NS_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_RX0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_RX1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_RX2 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_RX3 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_RX4 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_S_A | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_LEAP_TX0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA0_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA1_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA2_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA3_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA4_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_MCA5_M | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_P | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/AUDIO_SENSE_PDMC | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/AUSB0_AONUSB-V | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/AVD-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/AVD-SOC-VNOM | Virtual PMGR vote; no independent power-state register. @@ -695,7 +648,6 @@ t8140-j700 /arm-io/pmgr/power-devices/DISP_INT_M3 | Virtual PMGR vote; no indepe t8140-j700 /arm-io/pmgr/power-devices/DISP_PPP | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/DP | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/DPEXT0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/DPRX | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/DPTX_PHY | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/DSG | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ECPU0_SRAM | Virtual PMGR vote; no independent power-state register. @@ -714,18 +666,6 @@ t8140-j700 /arm-io/pmgr/power-devices/ISP-CORE-V | Virtual PMGR vote; no indepen t8140-j700 /arm-io/pmgr/power-devices/ISP-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ISP-SOC-VNOM | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/ISP-SYS-V | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_BE | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CLR | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CPU | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CPU_CORE0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CPU_CORE1 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CVD | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_CVM | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_FE | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_PEARL | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_SECURE | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_STS0 | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/ISP_STS1 | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/JPG-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/JPG-SOC-VNOM | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/JPG0-V | Virtual PMGR vote; no independent power-state register. @@ -765,7 +705,6 @@ t8140-j700 /arm-io/pmgr/power-devices/SIO | Virtual PMGR vote; no independent po t8140-j700 /arm-io/pmgr/power-devices/SIO-CPU-V | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/SMC_AON | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/SMC_CPU | Virtual PMGR vote; no independent power-state register. -t8140-j700 /arm-io/pmgr/power-devices/SMC_FABRIC | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/SMC_FPWM0 | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/SMC_FPWM1 | Virtual PMGR vote; no independent power-state register. t8140-j700 /arm-io/pmgr/power-devices/SMC_FPWM2 | Virtual PMGR vote; no independent power-state register. From cee332dfa1be1d60362773835e743652023dfef7 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:53:28 +1100 Subject: [PATCH 148/342] arm64: dts: apple: t6000: leave the JPEG performance request out Measured on a J316s with the J314s PMP profile (same session): with level 2 in request class 0x21 of entry 0x114, JPEG encode at 1080p dropped from 405-432 fps to 287-303 fps, and 4K moved only from 106-107 to 111-114 fps (119 with the PMP off). AVD with its request runs 72-73 fps at 1080p and 18 fps at 4K, against 62-63 and 15-16 with the PMP off, so keep that one and drop the JPEG store until the JPEG request is understood. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 291c854d8cabf..b5d973a1fe231 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -87,20 +87,14 @@ #ifdef APPLE_USE_PMP /* - * AVD and the JPEG codecs (one shared soc-device) also send the PMP a - * performance request while they are powered: level 2 (VMAX) in request - * class 0x21 of their SOC-DEV-DVFS entries, 0x112 and 0x114. The PMP then - * holds the SoC rail and fabric up for them. + * AVD also sends the PMP a performance request while it is powered: level 2 + * (VMAX) in request class 0x21 of its SOC-DEV-DVFS entry 0x112. The PMP then + * holds the SoC rail and fabric up for it. */ &pmp_report_avd_sys { apple,dvfs = <0x112 2>; apple,dvfs-request-class = <0x21>; }; - -&pmp_report_jpg { - apple,dvfs = <0x114 2>; - apple,dvfs-request-class = <0x21>; -}; #endif &ane { From 46f876e27b994f092dde5ac99c353d99fc0d5099 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:14:55 +1100 Subject: [PATCH 149/342] tools: asahi: give the T6030 graph harness the entry release word The report entry now keeps the word it stores to release its performance request (dvfs_off) next to the active one; the harness copy of the entry struct follows. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- tools/asahi/t6030-pmp-graph-tests.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/asahi/t6030-pmp-graph-tests.c b/tools/asahi/t6030-pmp-graph-tests.c index f9f758cbf15e6..840d961ff8cbb 100644 --- a/tools/asahi/t6030-pmp-graph-tests.c +++ b/tools/asahi/t6030-pmp-graph-tests.c @@ -199,6 +199,7 @@ struct apple_pmp_report_entry { bool no_ack, dvfs, removed; bool sleep_release, released; u32 dvfs_entry; + u64 dvfs_off; u64 dvfs_on; }; #define PMP_DVFS_VALID BIT_ULL(61) From 04c6eca23ca9f8dbfbcf9b1d74c930877b1c403e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:25:50 +1100 Subject: [PATCH 150/342] arm64: dts: apple: t6000-j316s: enable PMP Let m1n1 start the PMP on the 16-inch M1 Pro, as on the J314s: the ANE, GPU and AVD now send it their performance requests. Same session, PMP off against on (aura-try RAM-only trial, this DTB): glmark2 800x600 offscreen 10002 - 10193 -> 12079 - 12187 (+20%) AVD 1080p / 4K decode 62 - 63 / 15 - 16 fps -> 71 - 72 / 17 - 18 fps ANE MobileNet 4.85 ms -> 3.67 ms idle, Total System Power 3.93 W -> 3.76 W JPEG encode 1080p 392 - 411 fps -> 387 - 405 fps JPEG encode 4K 118 - 119 fps -> 107 fps (-10%) Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000-j316s.dts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6000-j316s.dts b/arch/arm64/boot/dts/apple/t6000-j316s.dts index 5fca6c4d4a8c9..9e4bd2ae50b03 100644 --- a/arch/arm64/boot/dts/apple/t6000-j316s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j316s.dts @@ -9,6 +9,12 @@ /dts-v1/; +/* + * PMP manages system power states, as on the J314s: the ANE, GPU, AVD and + * JPEG send it their performance requests, and the board idles lower. + */ +#define APPLE_USE_PMP + #include "t6000.dtsi" #include "t600x-j314-j316.dtsi" From 3fd48163f275752f0cc44e396c40e68dadd15d0b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:08:00 +1100 Subject: [PATCH 151/342] arm64: dts: apple: t6000: JPEG performance request to the PMP at level 1 With APPLE_USE_PMP the JPEG codecs sent the PMP no performance request, and 4K NV12 to JPEG encode ran 106-107 fps against 118-119 with the PMP off (J316s with the J314s PMP profile, same session). Level 2 in request class 0x21 of entry 0x114 made 1080p slower (287-303 fps, from 392-411); level 1 restores both: 1080p 383-408 fps and 4K 117-118 fps. GPU, AVD and ANE rows are unchanged (glmark2 12168-12329, AVD 1080p 71 fps and 4K 17-18 fps, ANE 3.68 ms), and idle Total System Power is 3.90 W (3.93 W with the PMP off). Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000.dtsi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000.dtsi b/arch/arm64/boot/dts/apple/t6000.dtsi index 73fc025895aa8..6b11b4ac9a4d8 100644 --- a/arch/arm64/boot/dts/apple/t6000.dtsi +++ b/arch/arm64/boot/dts/apple/t6000.dtsi @@ -87,14 +87,20 @@ #ifdef APPLE_USE_PMP /* - * AVD also sends the PMP a performance request while it is powered: level 2 - * (VMAX) in request class 0x21 of its SOC-DEV-DVFS entry 0x112. The PMP then - * holds the SoC rail and fabric up for it. + * AVD and the JPEG codecs (one soc-device for both) also send the PMP a + * performance request while they are powered, in request class 0x21 of + * their SOC-DEV-DVFS entries: AVD level 2 (VMAX) at 0x112, JPEG level 1 + * (VNOM) at 0x114. The PMP then holds the SoC rail and fabric up for them. */ &pmp_report_avd_sys { apple,dvfs = <0x112 2>; apple,dvfs-request-class = <0x21>; }; + +&pmp_report_jpg { + apple,dvfs = <0x114 1>; + apple,dvfs-request-class = <0x21>; +}; #endif &ane { From 9330cb74656ac4e840a0ecc5c44477232e6929ad Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:17:19 +1100 Subject: [PATCH 152/342] soc: apple: aop: keep the firmware nCal on T8112 and T6000 The aop driver patches the AOP firmware boot arguments with nCal 0 on T8112 and T6000. The J413 (M2) image carries nCal 1. With 0 the firmware never announces its accelerometer and gyroscope services, so the aop_motion driver has nothing to bind to. With the image value kept, both services appear and report once the bootloader hands over their calibration. Make nCal optional per SoC. None leaves the image value in place. T8112 and T6000 use None. Every other SoC keeps the value it had: T6040/T8132 write 1, the others write 0. Tested on the M2 (J413) with aura#124 and the J413 accel/gyro children enabled. The firmware image value is 1. Accelerometer at rest: |a| 9.796 m/s^2 over 50 distinct samples. Gyroscope: 0.26 deg/s. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/soc/apple/aop.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index fdb2f1b8e825f..7f446caf407a8 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -1604,7 +1604,7 @@ impl AopData { fn patch_bootargs( &self, aop_mmio: &Mmio<'_, Region>, - patches: &[(u32, u64)], + patches: &[(u32, Option)], word_access: bool, ) -> Result<()> { let offset = aop_mmio.read32(BOOTARGS_OFFSET) as usize; @@ -1648,6 +1648,10 @@ impl AopData { if *k != key { continue; } + // `None` keeps the value the firmware image carries. + let Some(v) = v else { + break; + }; if len > mem::size_of::() { return Err(EINVAL); } @@ -2562,8 +2566,8 @@ struct AopDriver(Arc); struct AopHwConfig { ec0p: u64, - /// The `nCal` boot argument. - ncal: u64, + /// The `nCal` boot argument, or `None` to keep the firmware's own value. + ncal: Option, alig: u64, aopt: u64, /// Complete the firmware's boot arguments before starting it. @@ -2588,7 +2592,7 @@ struct AopHwConfig { const HW_CFG_T8103: AopHwConfig = AopHwConfig { ec0p: 0x020000, - ncal: 0, + ncal: Some(0), aopt: 1, alig: 128, patch_bootargs: true, @@ -2600,9 +2604,11 @@ const HW_CFG_T8103: AopHwConfig = AopHwConfig { bootargs_word_access: false, halt_on_failed_start: false, }; +/// `nCal` keeps the firmware's own value, as on T6040: the J413 image carries 1, +/// and with 0 the firmware never announces its accelerometer and gyroscope. const HW_CFG_T8112: AopHwConfig = AopHwConfig { ec0p: 0x020000, - ncal: 0, + ncal: None, aopt: 0, alig: 128, patch_bootargs: true, @@ -2614,9 +2620,10 @@ const HW_CFG_T8112: AopHwConfig = AopHwConfig { bootargs_word_access: false, halt_on_failed_start: false, }; +/// `nCal` keeps the firmware's own value, as on T8112. const HW_CFG_T6000: AopHwConfig = AopHwConfig { ec0p: 0x020000, - ncal: 0, + ncal: None, aopt: 0, alig: 64, patch_bootargs: true, @@ -2630,7 +2637,7 @@ const HW_CFG_T6000: AopHwConfig = AopHwConfig { }; const HW_CFG_T6020: AopHwConfig = AopHwConfig { ec0p: 0x0100_00000000, - ncal: 0, + ncal: Some(0), aopt: 0, alig: 64, patch_bootargs: true, @@ -2649,7 +2656,7 @@ const HW_CFG_T6020: AopHwConfig = AopHwConfig { /// and report interval but never send a report. const HW_CFG_T6040: AopHwConfig = AopHwConfig { ec0p: 0x0100_00000000, - ncal: 1, + ncal: Some(1), aopt: 0, alig: 64, patch_bootargs: true, @@ -2672,7 +2679,7 @@ const HW_CFG_T8132: AopHwConfig = HW_CFG_T6040; /// are started if they will. const HW_CFG_T8140: AopHwConfig = AopHwConfig { ec0p: 0, - ncal: 0, + ncal: Some(0), aopt: 0, alig: 0, patch_bootargs: false, @@ -2737,10 +2744,10 @@ impl platform::Driver for AopDriver { data.patch_bootargs( &aop_mmio, &[ - (from_fourcc(b"EC0p"), cfg.ec0p), + (from_fourcc(b"EC0p"), Some(cfg.ec0p)), (from_fourcc(b"nCal"), cfg.ncal), - (from_fourcc(b"alig"), cfg.alig), - (from_fourcc(b"AOPt"), cfg.aopt), + (from_fourcc(b"alig"), Some(cfg.alig)), + (from_fourcc(b"AOPt"), Some(cfg.aopt)), ], cfg.bootargs_word_access, )?; From fa13cbdc1103dc5a66ed109e033a4a6ec2307fd0 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sun, 8 Nov 2026 10:39:18 -0500 Subject: [PATCH 153/342] drm/apple: timestamp fixed ProMotion on legacy firmware Fixed 120 Hz internal ProMotion modes can have explicit zero VRR bounds. The parser sets needs_timestamps for these modes, but the legacy modeset path checks vrr instead. This leaves their swaps without the timestamps needed for 120 Hz presentation. Use needs_timestamps for the legacy path too, keeping the main-display guard so external displays retain their existing policy. Fixes: 9df36a2c42b6 ("drm/apple: keep ProMotion deadlines independent of VRR admission") Signed-off-by: DjDeveloperr --- drivers/gpu/drm/apple/iomfb_template.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index ad87814e9bb9b..1a648d2c613fd 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -3591,7 +3591,7 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp, dcp->output_pq = dcp->pq_requested && mode->pq.score >= 0; /* Built-in ProMotion panels require timestamps even in fixed-120 mode. */ - dcp->use_timestamps = mode->vrr && dcp->main_display; + dcp->use_timestamps = mode->needs_timestamps && dcp->main_display; cookie = kzalloc(sizeof(*cookie), GFP_KERNEL); if (!cookie) { From 79655ca290a29e06a73d86162a44c17e8e6d7e32 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:05:49 +1100 Subject: [PATCH 154/342] tools/asahi: aop-bootargs-tests: cover the optional nCal AopHwConfig.ncal is now an Option, and patch_bootargs() takes an optional value per key, so the generated harness no longer compiled. Pass Some() values to the existing cases, and add these: - a None key keeps the firmware value while the other keys are still patched; - the per-SoC table, extracted from aop.rs: T8112 and T6000 keep the image nCal, T6040 and T8132 write 1, and the others write 0. Each case also runs through patch_bootargs(). Negative controls: None written as 0, T8112 forced to 0, T6040 forced to 0 and T6000 forced to 1 must each fail. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/asahi/aop-bootargs-tests.py | 52 ++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tools/asahi/aop-bootargs-tests.py b/tools/asahi/aop-bootargs-tests.py index aba3842077664..d2e24ecb07eb2 100644 --- a/tools/asahi/aop-bootargs-tests.py +++ b/tools/asahi/aop-bootargs-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only OR MIT -"""Exercise production bootarg patching with synthetic MMIO.""" +"""Exercise production bootarg patching and the per-SoC nCal choice with synthetic MMIO.""" import argparse import os from pathlib import Path @@ -40,7 +40,10 @@ if offset+table.len()<=bytes.len(){bytes[offset..offset+table.len()].copy_from_slice(table);} Device{bytes:RefCell::new(bytes),writes:RefCell::new(Vec::new()),fail:Cell::new(false)} } -fn patch(dev:&Device,word:bool)->Result{Aop.patch_bootargs(&Mmio{dev,_p:PhantomData::>},&[(1,0x12345678),(2,0x87654321)],word)} +fn patch(dev:&Device,word:bool)->Result{Aop.patch_bootargs(&Mmio{dev,_p:PhantomData::>},&[(1,Some(0x12345678)),(2,Some(0x87654321))],word)} +fn patch_with(dev:&Device,patches:&[(u32,Option)])->Result{Aop.patch_bootargs(&Mmio{dev,_p:PhantomData::>},patches,true)} +fn from_fourcc(b:&[u8;4])->u32{u32::from_le_bytes(*b)} +CONFIGS fn main(){ let table:[u8;24]=[1,0,0,0,4,0,0,0,0,0,0,0,2,0,0,0,4,0,0,0,0,0,0,0]; for offset in 32..36 {for word in [false,true] { @@ -56,7 +59,21 @@ let d=fixture(35,&table);d.fail.set(true);assert_eq!(patch(&d,true),Err(EIO),"readback error ignored"); assert_eq!(patch(&fixture(35,&[]),true),Err(EINVAL));assert_eq!(patch(&fixture(35,&[]),false),Ok(())); assert_eq!(patch(&fixture(120,&table),true),Err(EINVAL)); - println!("PASS aligned/unaligned byte and word access, unchanged writes, malformed tables, bounds and failed readback"); + // None keeps the firmware value of its key and still patches the others. + let d=fixture(32,&table);let mut expected=d.bytes.borrow().clone();expected[32+8..32+12].copy_from_slice(&0x12345678u32.to_le_bytes()); + let fw=0x0badf00du32;d.bytes.borrow_mut()[32+20..32+24].copy_from_slice(&fw.to_le_bytes());expected[32+20..32+24].copy_from_slice(&fw.to_le_bytes()); + assert_eq!(patch_with(&d,&[(1,Some(0x12345678)),(2,None)]),Ok(()));assert_eq!(*d.bytes.borrow(),expected,"None overwrote the firmware value"); + // Per-SoC nCal: T8112 and T6000 keep the image value, T6040/T8132 write 1, the others write 0. + let ncal=from_fourcc(b"nCal"); + for (name,cfg,want) in [("T8103",&HW_CFG_T8103,None),("T8112",&HW_CFG_T8112,Some(1u32)),("T6000",&HW_CFG_T6000,Some(1)),("T6020",&HW_CFG_T6020,None),("T6040",&HW_CFG_T6040,None),("T8132",&HW_CFG_T8132,None),("T8140",&HW_CFG_T8140,None)] { + let expect=match name {"T8112"|"T6000"=>None,"T6040"|"T8132"=>Some(1u64),_=>Some(0u64)}; + assert_eq!(cfg.ncal,expect,"{} nCal choice",name); + let mut t=[0u8;12];t[0..4].copy_from_slice(&ncal.to_le_bytes());t[4..8].copy_from_slice(&4u32.to_le_bytes());t[8..12].copy_from_slice(&1u32.to_le_bytes()); + let d=fixture(32,&t);assert_eq!(patch_with(&d,&[(ncal,cfg.ncal)]),Ok(())); + let got=u32::from_le_bytes(d.bytes.borrow()[40..44].try_into().unwrap()); + let wanted=want.unwrap_or_else(||cfg.ncal.unwrap() as u32);assert_eq!(got,wanted,"{} nCal written",name); + } + println!("PASS aligned/unaligned byte and word access, unchanged writes, malformed tables, bounds, failed readback, None keeps the firmware value, per-SoC nCal"); } ''' @@ -72,13 +89,25 @@ def method(source): return source[start:end] +def configs(source): + start = source.index('struct AopHwConfig {') + end = source.index('kernel::of_device_table!', start) + return source[start:end] + + +def compile_run(rustc, p, binary, code): + p.write_text(code) + subprocess.run([rustc, '--edition=2021', str(p), '-o', str(binary)], check=True) + return subprocess.run([str(binary)], capture_output=True, text=True) + + def main(): parser = argparse.ArgumentParser() parser.add_argument('--source', type=Path, default=Path(__file__).resolve().parents[2] / 'drivers/soc/apple/aop.rs') args = parser.parse_args() production = method(args.source.read_text()) macros = ''.join('macro_rules! ' + name + ' {($($t:tt)*)=>{()};}\n' for name in ['dev_info', 'dev_err'] if name + '!' in production) - code = HARNESS.replace('METHOD', production).replace('struct Aop;', macros + 'struct Aop;') + code = HARNESS.replace('METHOD', production).replace('CONFIGS', configs(args.source.read_text())).replace('struct Aop;', macros + 'struct Aop;') with tempfile.TemporaryDirectory(prefix='aop-bootargs-') as tmp: p = Path(tmp) / 'test.rs' binary = p.with_suffix('') @@ -92,6 +121,21 @@ def main(): result = subprocess.run([str(binary)], capture_output=True, text=True) assert result.returncode != 0 and 'readback error ignored' in result.stderr print('PASS negative control: missing write verification') + keep = 'let Some(v) = v else {' + assert code.count(keep) == 1 + rustc = os.environ.get('RUSTC', 'rustc') + bad = code.replace(keep, 'let v = &v.unwrap_or(0); if false {') + result = compile_run(rustc, p, binary, bad) + assert result.returncode != 0 and 'None overwrote the firmware value' in result.stderr, result.stderr + print('PASS negative control: None written as 0') + for soc, val in (('T8112', 'Some(0)'), ('T6040', 'Some(0)'), ('T6000', 'Some(1)')): + start = code.index('const HW_CFG_%s: AopHwConfig' % soc) + at = code.index(' ncal: ', start) + line_end = code.index('\n', at) + bad = code[:at] + ' ncal: %s,' % val + code[line_end:] + result = compile_run(rustc, p, binary, bad) + assert result.returncode != 0 and '%s nCal choice' % soc in result.stderr, (soc, result.stderr) + print('PASS negative control: %s nCal %s' % (soc, val)) if __name__ == '__main__': From 7fd168f0148e48459ad201f4968ba4a1c1bc35cd Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:04:38 +1100 Subject: [PATCH 155/342] arm64: dts: apple: adt-coverage: fix the j413 and j316s PMGR waivers The J413 and J316s inventories waived some PMGR records as virtual votes with no power-state register. 22 J413 records and 13 J316s records do have a register. They were found by PMGR group and register offset, as for the J700. Three J413 records have a power-controller node in our tree: ISP_CPU_CORE0 and ISP_CPU_CORE1 are the isp_set1 and isp_set2 registers, and ANE_CPU is ane_sys_cpu. Map them to those nodes. The rest are display and SEP states: DISP0_* and DP on the DCP, DISPEXT*, DPEXT and DPTX_PHY on the DCPEXT, and SEP_EISP on the SEP. The ADT marks each one no_ps, so the macOS PMGR driver does not switch them either, and the coprocessor firmware does. Keep them waived, with that reason and their register address. The other 145 J413 and 155 J316s waivers are real virtual votes and stay as they are. MISSING stays 0 on both boards. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../dts/apple/adt-coverage/t6000-j316s.txt | 26 +++---- .../dts/apple/adt-coverage/t8112-j413.txt | 44 ++++++------ .../boot/dts/apple/adt-coverage/waivers.txt | 67 +++++++++---------- 3 files changed, 67 insertions(+), 70 deletions(-) diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt b/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt index 43aa7b24bb729..5baa84eeaa229 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt @@ -187,26 +187,26 @@ /arm-io/pmgr/power-devices/DISPEXT1_FE 0x28e080260 -> /soc/power-management@28e080000/power-controller@260 /arm-io/pmgr/power-devices/ANE_SYS 0x28e080268 -> /soc/power-management@28e080000/power-controller@268 /arm-io/pmgr/power-devices/AVD_SYS 0x28e080270 -> /soc/power-management@28e080000/power-controller@270 -/arm-io/pmgr/power-devices/DISPEXT0_BE - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT0_BE 0x28e080278 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/DISPEXT0_CPU0 0x28e080280 -> /soc/power-management@28e080000/power-controller@280 -/arm-io/pmgr/power-devices/DISPEXT0_GP0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT0_GP1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT0_PPP - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT1_BE - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT0_GP0 0x28e080288 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT0_GP1 0x28e080290 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT0_PPP 0x28e080298 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT1_BE 0x28e0802a0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/DISPEXT1_CPU0 0x28e0802a8 -> /soc/power-management@28e080000/power-controller@2a8 -/arm-io/pmgr/power-devices/DISPEXT1_GP0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT1_GP1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT1_PPP - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT1_GP0 0x28e0802b0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT1_GP1 0x28e0802b8 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT1_PPP 0x28e0802c0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/ANE_SYS_CPU 0x28e0802c8 -> /soc/power-management@28e080000/power-controller@2c8 -/arm-io/pmgr/power-devices/DISPEXT0_DP - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT0_DP 0x28e0802d0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/PMP 0x28e0802d8 -> /soc/power-management@28e080000/power-controller@2d8 /arm-io/pmgr/power-devices/PMS_SRAM 0x28e0802e0 -> /soc/power-management@28e080000/power-controller@2e0 /arm-io/pmgr/power-devices/APCIE_ST_SYS 0x28e0802e8 -> /soc/power-management@28e080000/power-controller@2e8 /arm-io/pmgr/power-devices/APCIE_ST1_SYS 0x28e0802f0 -> /soc/power-management@28e080000/power-controller@2f0 /arm-io/pmgr/power-devices/ATC2_COMMON 0x28e0802f8 -> /soc/power-management@28e080000/power-controller@2f8 /arm-io/pmgr/power-devices/ATC3_COMMON 0x28e080300 -> /soc/power-management@28e080000/power-controller@300 -/arm-io/pmgr/power-devices/DISPEXT0_DSC - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT1_DP - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT0_DSC 0x28e080308 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT1_DP 0x28e080310 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/USB 0x28e080318 -> /soc/power-management@28e080000/power-controller@318 /arm-io/pmgr/power-devices/APCIE_GP_SYS 0x28e080320 -> /soc/power-management@28e080000/power-controller@320 /arm-io/pmgr/power-devices/ATC0_CIO 0x28e080328 -> /soc/power-management@28e080000/power-controller@328 @@ -228,7 +228,7 @@ /arm-io/pmgr/power-devices/ATC3_CIO_PCIE 0x28e0803a8 -> /soc/power-management@28e080000/power-controller@3a8 /arm-io/pmgr/power-devices/ATC3_CIO_USB 0x28e0803b0 -> /soc/power-management@28e080000/power-controller@3b0 /arm-io/pmgr/power-devices/TRACE_FAB 0x28e0803b8 -> /soc/power-management@28e080000/power-controller@3b8 -/arm-io/pmgr/power-devices/DISPEXT1_DSC - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT1_DSC 0x28e0803c0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/CLVR_SPMI0 0x28e580100 -> /soc/power-management@28e580000/power-controller@100 /arm-io/pmgr/power-devices/CLVR_SPMI1 0x28e580108 -> /soc/power-management@28e580000/power-controller@108 /arm-io/pmgr/power-devices/CLVR_SPMI2 0x28e580110 -> /soc/power-management@28e580000/power-controller@110 @@ -320,7 +320,7 @@ /arm-io/pmgr/power-devices/GFX 0x28e5803c0 -> /soc/power-management@28e580000/power-controller@3c0 /arm-io/pmgr/power-devices/DISP0_BRC - -> WAIVED: Virtual PMGR vote; no independent power-state register. /arm-io/pmgr/power-devices/SEP 0x28e580c00 -> /soc/power-management@28e580000/power-controller@c00 -/arm-io/pmgr/power-devices/SEP_EISP - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/SEP_EISP 0x28e580c08 -> WAIVED: Power state with a register, switched by the SEP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/VENC_DMA 0x28e588000 -> /soc/power-management@28e580000/power-controller@8000 /arm-io/pmgr/power-devices/VENC_PIPE4 0x28e588008 -> /soc/power-management@28e580000/power-controller@8008 /arm-io/pmgr/power-devices/VENC_PIPE5 0x28e588010 -> /soc/power-management@28e580000/power-controller@8010 diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t8112-j413.txt b/arch/arm64/boot/dts/apple/adt-coverage/t8112-j413.txt index 8f679d077a214..ee97381307b1f 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t8112-j413.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t8112-j413.txt @@ -198,15 +198,15 @@ /arm-io/pmgr/power-devices/DISP0_FE 0x23b700378 -> /soc/power-management@23b700000/power-controller@378 /arm-io/pmgr/power-devices/DISPEXT_SYS 0x23b700380 -> /soc/power-management@23b700000/power-controller@380 /arm-io/pmgr/power-devices/DISPEXT_FE 0x23b700388 -> /soc/power-management@23b700000/power-controller@388 -/arm-io/pmgr/power-devices/DISPEXT_BE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT_GP0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT_GP1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT_GP2 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT_PPP - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DPEXT - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISPEXT_DSC - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISPEXT_BE 0x23b700390 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT_GP0 0x23b700398 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT_GP1 0x23b7003a0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT_GP2 0x23b7003a8 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT_PPP 0x23b7003b0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DPEXT 0x23b7003b8 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISPEXT_DSC 0x23b7003c0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/DISPEXT_CPU0 0x23b7003c8 -> /soc/power-management@23b700000/power-controller@3c8 -/arm-io/pmgr/power-devices/DPTX_PHY - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DPTX_PHY 0x23b7003d0 -> WAIVED: Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/DPTX_EXT_PHY 0x23b7003d8 -> /soc/power-management@23b700000/power-controller@3d8 /arm-io/pmgr/power-devices/DISPDFR_FE 0x23b7003e0 -> /soc/power-management@23b700000/power-controller@3e0 /arm-io/pmgr/power-devices/DISPDFR_BE 0x23b7003e8 -> /soc/power-management@23b700000/power-controller@3e8 @@ -236,26 +236,26 @@ /arm-io/pmgr/power-devices/ANE_SYS 0x23b7004a8 -> /soc/power-management@23b700000/power-controller@4a8 /arm-io/pmgr/power-devices/SCODEC 0x23b7004b0 -> /soc/power-management@23b700000/power-controller@4b0 /arm-io/pmgr/power-devices/SEP 0x23b700c00 -> /soc/power-management@23b700000/power-controller@c00 -/arm-io/pmgr/power-devices/SEP_EISP - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CPU_CORE0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/ISP_CPU_CORE1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/SEP_EISP 0x23b700c08 -> WAIVED: Power state with a register, switched by the SEP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/ISP_CPU_CORE0 0x23b704008 -> /soc/power-management@23b700000/power-controller@4008 +/arm-io/pmgr/power-devices/ISP_CPU_CORE1 0x23b704010 -> /soc/power-management@23b700000/power-controller@4010 /arm-io/pmgr/power-devices/VENC_DMA 0x23b708000 -> /soc/power-management@23b700000/power-controller@8000 /arm-io/pmgr/power-devices/VENC_PIPE4 0x23b708008 -> /soc/power-management@23b700000/power-controller@8008 /arm-io/pmgr/power-devices/VENC_PIPE5 0x23b708010 -> /soc/power-management@23b700000/power-controller@8010 /arm-io/pmgr/power-devices/VENC_ME0 0x23b708018 -> /soc/power-management@23b700000/power-controller@8018 /arm-io/pmgr/power-devices/VENC_ME1 0x23b708020 -> /soc/power-management@23b700000/power-controller@8020 -/arm-io/pmgr/power-devices/ANE_CPU - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/ANE_CPU 0x23b70c008 -> /soc/power-management@23b700000/power-controller@c008 /arm-io/pmgr/power-devices/DISP0_CPU0 0x23b710000 -> /soc/power-management@23b700000/power-controller@10000 -/arm-io/pmgr/power-devices/DISP0_BE - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DP - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_SPI - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_SPMI - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_GP0 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_GP1 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_GP2 - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_PPP - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_BRC - -> WAIVED: Virtual PMGR vote; no independent power-state register. -/arm-io/pmgr/power-devices/DISP0_BLC - -> WAIVED: Virtual PMGR vote; no independent power-state register. +/arm-io/pmgr/power-devices/DISP0_BE 0x23b710008 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DP 0x23b710010 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_SPI 0x23b710018 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_SPMI 0x23b710020 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_GP0 0x23b710028 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_GP1 0x23b710030 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_GP2 0x23b710038 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_PPP 0x23b710040 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_BRC 0x23b710048 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +/arm-io/pmgr/power-devices/DISP0_BLC 0x23b710050 -> WAIVED: Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. /arm-io/pmgr/power-devices/DEBUG_GATED 0x23d280058 -> /soc/power-management@23d280000/power-controller@58 /arm-io/pmgr/power-devices/NUB_SPMI0 0x23d280060 -> /soc/power-management@23d280000/power-controller@60 /arm-io/pmgr/power-devices/NUB_SPMI1 0x23d280068 -> /soc/power-management@23d280000/power-controller@68 diff --git a/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt b/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt index 097e09dd16bbe..d2f60ec751893 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/waivers.txt @@ -85,20 +85,20 @@ t6000-j316s /arm-io/pmgr/power-devices/DISP0_GP1 | Virtual PMGR vote; no indepen t6000-j316s /arm-io/pmgr/power-devices/DISP0_PPP | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/DISP0_SPI | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/DISP0_SPMI | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_BE | Virtual PMGR vote; no independent power-state register. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_BE | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_CPU0-V | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_DP | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_DSC | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_GP0 | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_GP1 | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_PPP | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_BE | Virtual PMGR vote; no independent power-state register. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_DP | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_DSC | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_GP0 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_GP1 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT0_PPP | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_BE | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_CPU0-V | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_DP | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_DSC | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_GP0 | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_GP1 | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_PPP | Virtual PMGR vote; no independent power-state register. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_DP | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_DSC | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_GP0 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_GP1 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t6000-j316s /arm-io/pmgr/power-devices/DISPEXT1_PPP | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t6000-j316s /arm-io/pmgr/power-devices/DP0-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/DP1-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/DP2-SOC-VMAX | Virtual PMGR vote; no independent power-state register. @@ -135,7 +135,7 @@ t6000-j316s /arm-io/pmgr/power-devices/SCODEC-SOC-VNOM | Virtual PMGR vote; no i t6000-j316s /arm-io/pmgr/power-devices/SCODEC-V | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/SEP-PEARL-V | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/SEP-V | Virtual PMGR vote; no independent power-state register. -t6000-j316s /arm-io/pmgr/power-devices/SEP_EISP | Virtual PMGR vote; no independent power-state register. +t6000-j316s /arm-io/pmgr/power-devices/SEP_EISP | Power state with a register, switched by the SEP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t6000-j316s /arm-io/pmgr/power-devices/SIO-CPU-V | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/SIO-DART | Virtual PMGR vote; no independent power-state register. t6000-j316s /arm-io/pmgr/power-devices/SMC_AON | Virtual PMGR vote; no independent power-state register. @@ -410,7 +410,6 @@ t6040-j616s /arm-io/pmgr/power-devices/VENC1-SYS-V | Virtual PMGR vote; no indep t6040-j616s /sacm | Logical firmware service or diagnostic view; represented through coprocessor discovery, not an independent AP device. t8112-j413 /arm-io/pmgr/power-devices/ANE-SYS-DART | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/ANE-SYS-V | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/ANE_CPU | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/AOP_ADMA0 | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/AOP_AUDIO_ADMA0 | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/AOP_AUDIO_SHIM | Virtual PMGR vote; no independent power-state register. @@ -474,28 +473,28 @@ t8112-j413 /arm-io/pmgr/power-devices/DFR-MIE-DPB | Virtual PMGR vote; no indepe t8112-j413 /arm-io/pmgr/power-devices/DISP-CARVE-OUT | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/DISP-FB-ACTIVE | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/DISP-MIE-DPB | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_BE | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_BLC | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_BRC | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP0 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP1 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP2 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_PPP | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_SPI | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISP0_SPMI | Virtual PMGR vote; no independent power-state register. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_BE | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_BLC | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_BRC | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP0 | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP1 | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_GP2 | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_PPP | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_SPI | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISP0_SPMI | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t8112-j413 /arm-io/pmgr/power-devices/DISPDFR-V | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_BE | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_DSC | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP0 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP1 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP2 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_PPP | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DP | Virtual PMGR vote; no independent power-state register. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_BE | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_DSC | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP0 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP1 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_GP2 | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DISPEXT_PPP | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DP | Power state with a register, switched by the DCP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t8112-j413 /arm-io/pmgr/power-devices/DP-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/DP0_VMAX-V | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/DP1_VMAX-V | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DPEXT | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/DPTX_PHY | Virtual PMGR vote; no independent power-state register. +t8112-j413 /arm-io/pmgr/power-devices/DPEXT | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. +t8112-j413 /arm-io/pmgr/power-devices/DPTX_PHY | Power state with a register, switched by the DCPEXT firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t8112-j413 /arm-io/pmgr/power-devices/ECPM_NRG | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/ECPU0_SRAM | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/ECPU1_SRAM | Virtual PMGR vote; no independent power-state register. @@ -510,8 +509,6 @@ t8112-j413 /arm-io/pmgr/power-devices/ISP-SOC-VMAX | Virtual PMGR vote; no indep t8112-j413 /arm-io/pmgr/power-devices/ISP-SOC-VNOM | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/ISP-SYS-DART | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/ISP-SYS-V | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/ISP_CPU_CORE0 | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/ISP_CPU_CORE1 | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/JPG-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/JPG-SOC-VNOM | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/JPG0-DART | Virtual PMGR vote; no independent power-state register. @@ -544,7 +541,7 @@ t8112-j413 /arm-io/pmgr/power-devices/SCDC_VNOM-V | Virtual PMGR vote; no indepe t8112-j413 /arm-io/pmgr/power-devices/SDEC-SOC-VMAX | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/SDEC-SOC-VNOM | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/SEP-PEARL-V | Virtual PMGR vote; no independent power-state register. -t8112-j413 /arm-io/pmgr/power-devices/SEP_EISP | Virtual PMGR vote; no independent power-state register. +t8112-j413 /arm-io/pmgr/power-devices/SEP_EISP | Power state with a register, switched by the SEP firmware. The ADT marks it no_ps, so the macOS PMGR driver leaves it alone too; no DT power controller. t8112-j413 /arm-io/pmgr/power-devices/SIO-CPU-DART | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/SIO-CPU-V | Virtual PMGR vote; no independent power-state register. t8112-j413 /arm-io/pmgr/power-devices/SMC_AON | Virtual PMGR vote; no independent power-state register. From 7a44c0a85d8fa66b2da2f38c3b42b67c3ba49963 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:33:44 +1100 Subject: [PATCH 156/342] spmi: apple: take the interrupt count from the SoC The controller numbers its peripheral interrupts first and puts the RX FIFO notification right after them. On t8103, t8112 and t8140 that is 256 peripheral interrupts with the notification at 256, which the driver hard-codes. The M1 Pro, Max and Ultra (t6000) controller has 192 peripheral interrupts and raises the notification as interrupt 192, as the firmware device tree for the nub SPMI bus lists it. With the nub SPMI controller described as an interrupt controller, the driver unmasked bit 256 and waited for a completion that never came, so every transfer on an M1 Pro timed out ("failed to wait for RX FIFO not empty") and the SMC RTC, the reboot nvmem cells and the PMU RTC all failed to read. Add the interrupt count to the per-SoC data, use it for the notification index, the mask/ack ranges and the domain bounds, and match apple,t6000-spmi with a 192-interrupt layout. Other SoCs keep 256. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/spmi/spmi-apple-controller.c | 48 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index fbdb9ba0e7f2a..58ada41ed96ec 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -34,10 +34,12 @@ #define SPMI_IRQ_MASK_BASE 0x20 #define SPMI_IRQ_ACK_BASE 0x60 -#define SPMI_NUM_PERIPHERAL_IRQS 256 -#define SPMI_NUM_IRQS (SPMI_NUM_PERIPHERAL_IRQS + 32) - -#define SPMI_IRQ_NOTIFY 256 +/* + * Peripheral interrupts come first. The RX FIFO notification sits right + * after them, followed by the controller's own fault interrupts, so the + * notification index is the number of peripheral interrupts. + */ +#define SPMI_MAX_PERIPHERAL_IRQS 256 /* SPMI_RSP_REG reply word */ #define SPMI_REPLY_FRAME_PARITY_STATUS GENMASK(31, 16) @@ -57,6 +59,7 @@ struct apple_spmi_hw { u32 reply; u32 rx_empty; bool legacy_irqs; + u32 num_irqs; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -65,6 +68,17 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .reply = SPMI_RSP_REG, .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, + .num_irqs = 256, +}; + +/* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ +static const struct apple_spmi_hw apple_spmi_t6000 = { + .status = SPMI_STATUS_REG, + .command = SPMI_CMD_REG, + .reply = SPMI_RSP_REG, + .rx_empty = SPMI_RX_FIFO_EMPTY, + .legacy_irqs = true, + .num_irqs = 192, }; static const struct apple_spmi_hw apple_spmi_gen4 = { @@ -81,7 +95,7 @@ struct apple_spmi { struct completion fifo_rx; struct irq_domain *irqd; raw_spinlock_t irq_mask_lock; - DECLARE_BITMAP(irq_mask_cache, SPMI_NUM_PERIPHERAL_IRQS); + DECLARE_BITMAP(irq_mask_cache, SPMI_MAX_PERIPHERAL_IRQS); int irq; bool notify_irq; bool prev_fail; @@ -190,7 +204,7 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid, u16 param, if (!spmi->hw->legacy_irqs) return -EIO; writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); - apple_spmi_irq_ack_raw(spmi, SPMI_IRQ_NOTIFY); + apple_spmi_irq_ack_raw(spmi, spmi->hw->num_irqs); spmi->prev_fail = false; } reinit_completion(&spmi->fifo_rx); @@ -335,12 +349,13 @@ static int apple_spmi_irq_domain_translate(struct irq_domain *irqd, unsigned long *hwirq, unsigned int *type) { + struct apple_spmi *spmi = irqd->host_data; u32 *args = fwspec->param; if (fwspec->param_count != 2) return -EINVAL; - if (args[0] >= SPMI_NUM_PERIPHERAL_IRQS) + if (args[0] >= spmi->hw->num_irqs) return -EINVAL; *hwirq = args[0]; *type = args[1] & IRQ_TYPE_SENSE_MASK; @@ -352,6 +367,7 @@ static int apple_spmi_irq_domain_alloc(struct irq_domain *irqd, unsigned int vir { unsigned int type = IRQ_TYPE_NONE; struct irq_fwspec *fwspec = arg; + struct apple_spmi *spmi = irqd->host_data; irq_hw_number_t hwirq; int i, ret; @@ -359,7 +375,7 @@ static int apple_spmi_irq_domain_alloc(struct irq_domain *irqd, unsigned int vir if (ret) return ret; - if (hwirq + nr_irqs > SPMI_NUM_PERIPHERAL_IRQS) + if (hwirq + nr_irqs > spmi->hw->num_irqs) return -EINVAL; for (i = 0; i < nr_irqs; i++) { @@ -394,18 +410,19 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) { struct apple_spmi *spmi = irq_desc_get_handler_data(desc); struct irq_chip *chip = irq_desc_get_chip(desc); + u32 notify = spmi->hw->num_irqs; bool handled = false; unsigned long val, offset, bit; chained_irq_enter(chip, desc); - val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (SPMI_IRQ_NOTIFY / 32) * 4); - if (val & BIT(SPMI_IRQ_NOTIFY % 32)) { - apple_spmi_irq_ack_raw(spmi, SPMI_IRQ_NOTIFY); + val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + if (val & BIT(notify % 32)) { + apple_spmi_irq_ack_raw(spmi, notify); complete(&spmi->fifo_rx); handled = true; } - for (offset = 0; offset < SPMI_NUM_PERIPHERAL_IRQS / 8; offset += sizeof(val)) { + for (offset = 0; offset < notify / 8; offset += sizeof(val)) { val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset); /** * because of other masters in the bus, we're going to get a multitude of @@ -428,7 +445,7 @@ static void apple_spmi_teardown_irq(void *data) { struct apple_spmi *spmi = data; - for (size_t offset = 0; offset < SPMI_NUM_IRQS / 8; offset += 4) + for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); synchronize_irq(spmi->irq); @@ -448,7 +465,7 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); - for (size_t offset = 0; offset < SPMI_NUM_IRQS / 8; offset += 4) { + for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); } @@ -462,7 +479,7 @@ static int apple_spmi_init_irq(struct platform_device *pdev, return ret; irq_set_chained_handler_and_data(spmi->irq, apple_spmi_irq_handler, spmi); - apple_spmi_irq_unmask_raw(spmi, SPMI_IRQ_NOTIFY); + apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); spmi->notify_irq = true; return 0; @@ -519,6 +536,7 @@ static int apple_spmi_probe(struct platform_device *pdev) static const struct of_device_id apple_spmi_match_table[] = { { .compatible = "apple,t8142-spmi", .data = &apple_spmi_gen4 }, { .compatible = "apple,t8103-spmi", .data = &apple_spmi_gen1 }, + { .compatible = "apple,t6000-spmi", .data = &apple_spmi_t6000 }, { .compatible = "apple,spmi", .data = &apple_spmi_gen1 }, {} }; From c85f88bc3866e5926c20fb3537fa150bd357490e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 01:33:58 +1100 Subject: [PATCH 157/342] arm64: dts: apple: t600x: describe the PMU RTC alarm Make the nub SPMI controller an interrupt controller and add the Maverick PMU RTC under the PMIC, so rtcwake can wake M1 Pro, Max and Ultra systems from s2idle. The PMU raises SPMI interrupt 2 for the alarm. Keep rtc0 on the SMC clock and give the alarm rtc1 on every t600x board. The t602x boards share the board files but not this PMU, so the aliases go in the t600x board files. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000-j314s.dts | 2 ++ arch/arm64/boot/dts/apple/t6000-j316s.dts | 2 ++ arch/arm64/boot/dts/apple/t6001-j314c.dts | 2 ++ arch/arm64/boot/dts/apple/t6001-j316c.dts | 2 ++ arch/arm64/boot/dts/apple/t6001-j375c.dts | 5 +++++ arch/arm64/boot/dts/apple/t6002-j375d.dts | 2 ++ arch/arm64/boot/dts/apple/t600x-die0.dtsi | 15 ++++++++++++++- 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6000-j314s.dts b/arch/arm64/boot/dts/apple/t6000-j314s.dts index a3c26b7819d43..2286e31c8f59a 100644 --- a/arch/arm64/boot/dts/apple/t6000-j314s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j314s.dts @@ -24,6 +24,8 @@ model = "Apple MacBook Pro (14-inch, M1 Pro, 2021)"; aliases { + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; sep = &sep; }; }; diff --git a/arch/arm64/boot/dts/apple/t6000-j316s.dts b/arch/arm64/boot/dts/apple/t6000-j316s.dts index 9e4bd2ae50b03..b08c10046e83c 100644 --- a/arch/arm64/boot/dts/apple/t6000-j316s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j316s.dts @@ -23,6 +23,8 @@ model = "Apple MacBook Pro (16-inch, M1 Pro, 2021)"; aliases { + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; sep = &sep; }; }; diff --git a/arch/arm64/boot/dts/apple/t6001-j314c.dts b/arch/arm64/boot/dts/apple/t6001-j314c.dts index 23be760ba6e49..1f7b1e4d2827c 100644 --- a/arch/arm64/boot/dts/apple/t6001-j314c.dts +++ b/arch/arm64/boot/dts/apple/t6001-j314c.dts @@ -17,6 +17,8 @@ model = "Apple MacBook Pro (14-inch, M1 Max, 2021)"; aliases { + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; sep = &sep; }; }; diff --git a/arch/arm64/boot/dts/apple/t6001-j316c.dts b/arch/arm64/boot/dts/apple/t6001-j316c.dts index d171d9c1200b8..f2aa92e7a79f3 100644 --- a/arch/arm64/boot/dts/apple/t6001-j316c.dts +++ b/arch/arm64/boot/dts/apple/t6001-j316c.dts @@ -17,6 +17,8 @@ model = "Apple MacBook Pro (16-inch, M1 Max, 2021)"; aliases { + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; sep = &sep; }; }; diff --git a/arch/arm64/boot/dts/apple/t6001-j375c.dts b/arch/arm64/boot/dts/apple/t6001-j375c.dts index 35cd50028b75b..dd0864540b9ba 100644 --- a/arch/arm64/boot/dts/apple/t6001-j375c.dts +++ b/arch/arm64/boot/dts/apple/t6001-j375c.dts @@ -15,6 +15,11 @@ / { compatible = "apple,j375c", "apple,t6001", "apple,arm-platform"; model = "Apple Mac Studio (M1 Max, 2022)"; + + aliases { + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; + }; }; &wifi0 { diff --git a/arch/arm64/boot/dts/apple/t6002-j375d.dts b/arch/arm64/boot/dts/apple/t6002-j375d.dts index a16df355852ef..a148a7325d9d4 100644 --- a/arch/arm64/boot/dts/apple/t6002-j375d.dts +++ b/arch/arm64/boot/dts/apple/t6002-j375d.dts @@ -18,6 +18,8 @@ aliases { atcphy4 = &atcphy0_die1; atcphy5 = &atcphy1_die1; + rtc0 = &smc_rtc; + rtc1 = &pmu_rtc; usb4-4-acio = &usb4_0_acio_die1; usb4-4-nhi = &usb4_0_nhi_die1; usb4-5-acio = &usb4_1_acio_die1; diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi index 6f028f884a703..5e1df81ed234e 100644 --- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi @@ -363,7 +363,7 @@ compatible = "apple,smc-hwmon"; }; - rtc { + smc_rtc: rtc { compatible = "apple,smc-rtc"; nvmem-cells = <&rtc_offset>; nvmem-cell-names = "rtc_offset"; @@ -409,11 +409,24 @@ reg = <0x2 0x920a1300 0x0 0x100>; #address-cells = <2>; #size-cells = <0>; + #interrupt-cells = <2>; + interrupt-controller; + interrupt-parent = <&aic>; + interrupts = ; pmic1: pmic@f { compatible = "apple,maverick-pmic", "apple,spmi-nvmem"; reg = <0xf SPMI_USID>; + pmu_rtc: rtc { + compatible = "apple,t6000-pmu-rtc"; + interrupt-parent = <&nub_spmi0>; + interrupts = <2 IRQ_TYPE_EDGE_RISING>; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + wakeup-source; + }; + nvmem-layout { compatible = "fixed-layout"; #address-cells = <1>; From 37888b11fb7a6a0faec665cdb95f6fd561847392 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:46:09 +1100 Subject: [PATCH 158/342] media: apple: add a probe-only driver for the scaler/CSC engine Every Apple silicon SoC has one or more MSR engines: memory-to-memory scalers with a programmable colour-space converter, chroma resampling, flip/rotate and alpha fill. macOS reaches them through IOSurfaceAccelerator and VideoToolbox; Linux has had no driver, so scaling and YUV/RGB conversion fall back to the CPU or GPU. Hardware-version 10 (M1) through 22 (A18 Pro) program the engine through MMIO and signal completion with an interrupt. This first step binds the existing apple,scaler nodes for T6041 (M4 Pro/Max) and T8140 (A18 Pro): it attaches the MSR power domains with runtime-PM links, requires the DART, reads the identity and idle state, clears and masks the interrupt and keeps the engine idle. The video device and job submission follow once the RGB path is qualified on hardware. The DT nodes stay disabled, so nothing changes on existing systems. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- MAINTAINERS | 8 + arch/arm64/configs/asahi.config | 1 + drivers/media/platform/apple/Kconfig | 1 + drivers/media/platform/apple/Makefile | 1 + drivers/media/platform/apple/scaler/Kconfig | 16 ++ drivers/media/platform/apple/scaler/Makefile | 4 + .../platform/apple/scaler/apple-scaler-drv.c | 227 ++++++++++++++++++ .../platform/apple/scaler/apple-scaler-regs.h | 37 +++ 8 files changed, 295 insertions(+) create mode 100644 drivers/media/platform/apple/scaler/Kconfig create mode 100644 drivers/media/platform/apple/scaler/Makefile create mode 100644 drivers/media/platform/apple/scaler/apple-scaler-drv.c create mode 100644 drivers/media/platform/apple/scaler/apple-scaler-regs.h diff --git a/MAINTAINERS b/MAINTAINERS index 78e5d506eff3a..fc20e250d5476 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2844,6 +2844,14 @@ S: Maintained F: Documentation/devicetree/bindings/spi/apple,qspi.yaml F: drivers/spi/spi-apple-qspi.c +ARM/APPLE SCALER DRIVER +M: Ryan Murray +L: linux-media@vger.kernel.org +S: Maintained +W: https://aurora-silicon.github.io +F: Documentation/devicetree/bindings/media/apple,scaler.yaml +F: drivers/media/platform/apple/scaler/ + ARM/ARTPEC MACHINE SUPPORT M: Jesper Nilsson M: Lars Persson diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 611fc646ffbcf..76919c3e257d8 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -60,6 +60,7 @@ CONFIG_VIDEO_APPLE_AVE=m CONFIG_VIDEO_APPLE_ISP=m CONFIG_VIDEO_APPLE_PRORES=m CONFIG_VIDEO_APPLE_JPEG=m +CONFIG_VIDEO_APPLE_SCALER=m CONFIG_DRM=y CONFIG_DRM_ASAHI=m CONFIG_DRM_ASAHI_G15=y diff --git a/drivers/media/platform/apple/Kconfig b/drivers/media/platform/apple/Kconfig index 2d7f7f9e176b4..83c6538fe6547 100644 --- a/drivers/media/platform/apple/Kconfig +++ b/drivers/media/platform/apple/Kconfig @@ -7,3 +7,4 @@ source "drivers/media/platform/apple/avd/Kconfig" source "drivers/media/platform/apple/ave/Kconfig" source "drivers/media/platform/apple/jpeg/Kconfig" source "drivers/media/platform/apple/prores/Kconfig" +source "drivers/media/platform/apple/scaler/Kconfig" diff --git a/drivers/media/platform/apple/Makefile b/drivers/media/platform/apple/Makefile index 0d5814d987671..eb0b9cb65952c 100644 --- a/drivers/media/platform/apple/Makefile +++ b/drivers/media/platform/apple/Makefile @@ -5,3 +5,4 @@ obj-y += avd/ obj-y += ave/ obj-y += jpeg/ obj-y += prores/ +obj-y += scaler/ diff --git a/drivers/media/platform/apple/scaler/Kconfig b/drivers/media/platform/apple/scaler/Kconfig new file mode 100644 index 0000000000000..a2b72a3fec804 --- /dev/null +++ b/drivers/media/platform/apple/scaler/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config VIDEO_APPLE_SCALER + tristate "Apple Silicon scaler and colour-space converter" + depends on VIDEO_DEV + depends on ARCH_APPLE || (COMPILE_TEST && 64BIT) + depends on OF_ADDRESS && IOMMU_API && PM + help + Driver for the memory-to-memory image scaler and colour-space + converter (MSR) in Apple silicon SoCs. This first version + identifies the engine, attaches its power domains, IOMMU and + interrupt, and keeps it idle; it does not yet expose a video + device. + + To compile this driver as a module, choose M here: the module + will be called apple-scaler. diff --git a/drivers/media/platform/apple/scaler/Makefile b/drivers/media/platform/apple/scaler/Makefile new file mode 100644 index 0000000000000..ab203c242b6d4 --- /dev/null +++ b/drivers/media/platform/apple/scaler/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_VIDEO_APPLE_SCALER) += apple-scaler.o +apple-scaler-y := apple-scaler-drv.o diff --git a/drivers/media/platform/apple/scaler/apple-scaler-drv.c b/drivers/media/platform/apple/scaler/apple-scaler-drv.c new file mode 100644 index 0000000000000..37fd72719bac1 --- /dev/null +++ b/drivers/media/platform/apple/scaler/apple-scaler-drv.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Apple silicon scaler and colour-space converter (MSR). + * + * Every Apple silicon SoC has one or more MSR engines: memory-to-memory + * scalers with a programmable colour-space converter, chroma resampling, + * flip/rotate and alpha fill. Hardware-version 10 (M1) through 22 (A18 Pro) + * are programmed directly through MMIO and report completion with an + * interrupt; later generations front the engine with firmware and are not + * handled here. + * + * This version only brings the engine up: it attaches the power domains, + * checks the IOMMU, identifies the hardware, takes the completion + * interrupt and keeps the engine idle. Jobs and the V4L2 mem2mem device + * come in later patches. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "apple-scaler-regs.h" + +#define ASC_NAME "apple-scaler" +#define ASC_MIN_REG_SIZE 0x28000 + +/** + * struct apple_scaler_variant - per-SoC engine description + * @hw_version: MSR hardware-version of this SoC (from the hardware description) + * @num_reg: number of register apertures the binding describes + */ +struct apple_scaler_variant { + u32 hw_version; + unsigned int num_reg; +}; + +struct apple_scaler { + struct device *dev; + void __iomem *regs; + const struct apple_scaler_variant *variant; + struct dev_pm_domain_list *pd_list; + struct reset_control *rst; + int irq; + u32 id; +}; + +static u32 asc_read(struct apple_scaler *asc, u32 reg) +{ + return readl_relaxed(asc->regs + reg); +} + +static void asc_write(struct apple_scaler *asc, u32 reg, u32 val) +{ + writel_relaxed(val, asc->regs + reg); +} + +/* + * No job is ever started yet, so any interrupt is unexpected: acknowledge + * it and report it. The handler only touches the engine while it is + * runtime-active, because a powered-down MSR must not be read. + */ +static irqreturn_t asc_irq(int irq, void *data) +{ + struct apple_scaler *asc = data; + u32 status; + + if (pm_runtime_get_if_active(asc->dev) <= 0) + return IRQ_NONE; + + status = asc_read(asc, ASC_IRQ_STATUS); + if (status) { + asc_write(asc, ASC_IRQ_STATUS, status); + dev_warn_ratelimited(asc->dev, "unexpected interrupt, status %#x\n", + status); + } + pm_runtime_put_autosuspend(asc->dev); + return status ? IRQ_HANDLED : IRQ_NONE; +} + +static int asc_identify(struct apple_scaler *asc) +{ + u32 running, status; + int ret; + + ret = pm_runtime_resume_and_get(asc->dev); + if (ret < 0) + return dev_err_probe(asc->dev, ret, "failed to power up\n"); + + asc->id = asc_read(asc, ASC_HW_VERSION); + running = asc_read(asc, ASC_IS_RUNNING); + status = asc_read(asc, ASC_IRQ_STATUS); + /* Nothing may be enabled until a job path owns the engine. */ + asc_write(asc, ASC_IRQ_ENABLE, 0); + if (status) + asc_write(asc, ASC_IRQ_STATUS, status); + + pm_runtime_put_sync_suspend(asc->dev); + + if (running) + dev_warn(asc->dev, "engine busy at probe (%#x)\n", running); + dev_info(asc->dev, "MSR hardware-version %u, id %#x, stale status %#x\n", + asc->variant->hw_version, asc->id, status); + return 0; +} + +static int asc_runtime_suspend(struct device *dev) +{ + return 0; +} + +static int asc_runtime_resume(struct device *dev) +{ + /* The engine loses its state when powered down; jobs program it fully. */ + return 0; +} + +static const struct dev_pm_ops asc_pm_ops = { + RUNTIME_PM_OPS(asc_runtime_suspend, asc_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) +}; + +static int asc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct apple_scaler *asc; + struct resource *res; + int ret; + + asc = devm_kzalloc(dev, sizeof(*asc), GFP_KERNEL); + if (!asc) + return -ENOMEM; + asc->dev = dev; + asc->variant = of_device_get_match_data(dev); + if (!asc->variant) + return -ENODEV; + platform_set_drvdata(pdev, asc); + + if (!device_iommu_mapped(dev)) + return dev_err_probe(dev, -ENODEV, "no IOMMU\n"); + + /* + * MSR-V and the ASE core domain below it; link both so they are on + * exactly while the engine is runtime-active. + */ + if (of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells") > 1) { + static const struct dev_pm_domain_attach_data pd_data = { + .pd_flags = PD_FLAG_DEV_LINK_ON, + }; + + ret = devm_pm_domain_attach_list(dev, &pd_data, &asc->pd_list); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to attach power domains\n"); + } else if (!dev->pm_domain) { + return dev_err_probe(dev, -ENODEV, "requires a power domain\n"); + } + + if (platform_get_resource(pdev, IORESOURCE_MEM, asc->variant->num_reg - 1) == NULL) + return dev_err_probe(dev, -EINVAL, "expected %u register ranges\n", + asc->variant->num_reg); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (resource_size(res) < ASC_MIN_REG_SIZE) + return dev_err_probe(dev, -EINVAL, "MSR aperture too small\n"); + asc->regs = devm_ioremap_resource(dev, res); + if (IS_ERR(asc->regs)) + return PTR_ERR(asc->regs); + + asc->rst = devm_reset_control_get_optional_exclusive(dev, NULL); + if (IS_ERR(asc->rst)) + return dev_err_probe(dev, PTR_ERR(asc->rst), "failed to get reset\n"); + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + + pm_runtime_set_autosuspend_delay(dev, 100); + pm_runtime_use_autosuspend(dev); + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + ret = asc_identify(asc); + if (ret) + return ret; + + /* Interrupt 0 is the MSR (completion/error); 1 is the PIODMA engine. */ + asc->irq = platform_get_irq(pdev, 0); + if (asc->irq < 0) + return asc->irq; + return devm_request_irq(dev, asc->irq, asc_irq, 0, dev_name(dev), asc); +} + +static const struct apple_scaler_variant apple_scaler_t6041 = { + .hw_version = 21, + .num_reg = 4, +}; + +static const struct apple_scaler_variant apple_scaler_t8140 = { + .hw_version = 22, + .num_reg = 4, +}; + +static const struct of_device_id asc_of_match[] = { + { .compatible = "apple,t6041-scaler", .data = &apple_scaler_t6041 }, + { .compatible = "apple,t8140-scaler", .data = &apple_scaler_t8140 }, + { } +}; +MODULE_DEVICE_TABLE(of, asc_of_match); + +static struct platform_driver asc_driver = { + .probe = asc_probe, + .driver = { + .name = ASC_NAME, + .of_match_table = asc_of_match, + .pm = pm_ptr(&asc_pm_ops), + }, +}; +module_platform_driver(asc_driver); + +MODULE_DESCRIPTION("Apple silicon scaler and colour-space converter"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-regs.h b/drivers/media/platform/apple/scaler/apple-scaler-regs.h new file mode 100644 index 0000000000000..7402b9a97752c --- /dev/null +++ b/drivers/media/platform/apple/scaler/apple-scaler-regs.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Apple silicon scaler/CSC (MSR) register map, global block. + * + * Offsets are bytes from the start of the MSR aperture (reg index 0). + * The global control registers are common to every direct-MMIO MSR + * generation (hardware-version 10 through 22). + */ +#ifndef APPLE_SCALER_REGS_H +#define APPLE_SCALER_REGS_H + +#include + +#define ASC_HW_VERSION 0x0000 +#define ASC_RESET 0x0004 +#define ASC_RESET_APIODMA 0x0008 +#define ASC_IS_RUNNING 0x000c +#define ASC_REG_FIFO_AVAIL 0x0014 +#define ASC_IRQ_ENABLE 0x0018 +#define ASC_IRQ_STATUS 0x001c +#define ASC_IRQ_DONE BIT(0) +#define ASC_IRQ_DEBUG_ERROR BIT(1) +#define ASC_IRQ_READ_ERROR BIT(3) +#define ASC_IRQ_WRITE_ERROR BIT(4) +#define ASC_IRQ_DECOMPRESS_ERROR BIT(9) +#define ASC_IRQ_CONTEXT_SWITCH BIT(10) +#define ASC_IRQ_AXI_ERROR BIT(12) +#define ASC_IRQ_ERRORS (ASC_IRQ_DEBUG_ERROR | ASC_IRQ_READ_ERROR | \ + ASC_IRQ_WRITE_ERROR | ASC_IRQ_DECOMPRESS_ERROR | \ + ASC_IRQ_AXI_ERROR) +#define ASC_FRAME_COUNT 0x0020 +#define ASC_START 0x0080 +#define ASC_PRE_START 0x0098 +#define ASC_DEBUG_STATUS 0x009c +#define ASC_TRANSFORM_ID 0x0110 + +#endif /* APPLE_SCALER_REGS_H */ From eabe8ca3a3a5482ef47b5f26e63409b721d3cb6b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:50:20 +1100 Subject: [PATCH 159/342] media: apple: scaler: add the format, CSC and ratio encodings The job path needs three pieces of register encoding that do not depend on the hardware being present, so add them with KUnit coverage first: - the formats the engine is known to take: 32-bit B,G,R,A (ARGB32 and XRGB32 in V4L2 terms), NV12/NV12M and P010, with their layout class, format code, subsampling descriptor and component order; - the colour-space converter: a 3x3 Q3.12 matrix with input and output offsets (2^-24 of full scale, 26-bit signed), derived from the Kr/Kb luma coefficients of BT.601, BT.709 and BT.2020 for limited and full range, in both directions; - the scaler ratio register, Q22 with the two lowest bits clear. The tests compare against the register values used for the same conversions in a capture of the engine on macOS 27 on an M4 Pro: all six matrices and the offsets match bit for bit. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../media/platform/apple/scaler/.kunitconfig | 14 ++ drivers/media/platform/apple/scaler/Kconfig | 9 + drivers/media/platform/apple/scaler/Makefile | 3 +- .../platform/apple/scaler/apple-scaler-hw.c | 192 ++++++++++++++++++ .../platform/apple/scaler/apple-scaler-hw.h | 84 ++++++++ .../platform/apple/scaler/apple-scaler-test.c | 158 ++++++++++++++ 6 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/apple/scaler/.kunitconfig create mode 100644 drivers/media/platform/apple/scaler/apple-scaler-hw.c create mode 100644 drivers/media/platform/apple/scaler/apple-scaler-hw.h create mode 100644 drivers/media/platform/apple/scaler/apple-scaler-test.c diff --git a/drivers/media/platform/apple/scaler/.kunitconfig b/drivers/media/platform/apple/scaler/.kunitconfig new file mode 100644 index 0000000000000..84cb41aee612d --- /dev/null +++ b/drivers/media/platform/apple/scaler/.kunitconfig @@ -0,0 +1,14 @@ +CONFIG_KUNIT=y +CONFIG_ARCH_APPLE=y +CONFIG_PM=y +CONFIG_PM_GENERIC_DOMAINS=y +CONFIG_OF=y +CONFIG_IOMMU_SUPPORT=y +CONFIG_APPLE_DART=y +CONFIG_IOMMU_DMA=y +CONFIG_MEDIA_SUPPORT=y +CONFIG_MEDIA_SUPPORT_FILTER=n +CONFIG_VIDEO_DEV=y +CONFIG_V4L_PLATFORM_DRIVERS=y +CONFIG_VIDEO_APPLE_SCALER=y +CONFIG_VIDEO_APPLE_SCALER_KUNIT_TEST=y diff --git a/drivers/media/platform/apple/scaler/Kconfig b/drivers/media/platform/apple/scaler/Kconfig index a2b72a3fec804..799707d9938d1 100644 --- a/drivers/media/platform/apple/scaler/Kconfig +++ b/drivers/media/platform/apple/scaler/Kconfig @@ -14,3 +14,12 @@ config VIDEO_APPLE_SCALER To compile this driver as a module, choose M here: the module will be called apple-scaler. + +config VIDEO_APPLE_SCALER_KUNIT_TEST + tristate "KUnit tests for the Apple scaler" if !KUNIT_ALL_TESTS + depends on KUNIT && VIDEO_APPLE_SCALER + default KUNIT_ALL_TESTS + help + Check the colour-conversion matrices, offsets, scale ratios and + format encodings the scaler driver programs. No hardware is + needed. diff --git a/drivers/media/platform/apple/scaler/Makefile b/drivers/media/platform/apple/scaler/Makefile index ab203c242b6d4..d6a9dcbe9b33e 100644 --- a/drivers/media/platform/apple/scaler/Makefile +++ b/drivers/media/platform/apple/scaler/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIDEO_APPLE_SCALER) += apple-scaler.o -apple-scaler-y := apple-scaler-drv.o +apple-scaler-y := apple-scaler-drv.o apple-scaler-hw.o +obj-$(CONFIG_VIDEO_APPLE_SCALER_KUNIT_TEST) += apple-scaler-test.o diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.c b/drivers/media/platform/apple/scaler/apple-scaler-hw.c new file mode 100644 index 0000000000000..2cbff1aee9e3d --- /dev/null +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Apple silicon scaler/CSC (MSR): format table, colour matrices and + * scale ratios in register encoding. + * + * The colour matrices are derived here from the luma coefficients the + * standards define (Kr, Kb), not looked up, so every encoding/range pair + * comes from one formula. The format codes and component orders are the + * values the engine is driven with for those layouts. + */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "apple-scaler-hw.h" + +#define ASC_SWIZZLE_IDENTITY 0x03020100 +#define ASC_SWIZZLE_CBCR 0x03000102 + +static const struct asc_format asc_formats[] = { + { + /* Bytes B, G, R, A in memory. */ + .fourcc = V4L2_PIX_FMT_ARGB32, .layout = 0x1, .code = 0x1e, + .sampling = 0x0, .swizzle = ASC_SWIZZLE_IDENTITY, .planes = 1, + .bpp = { 4 }, .hsub = 1, .vsub = 1, .alpha = true, + }, { + .fourcc = V4L2_PIX_FMT_XRGB32, .layout = 0x1, .code = 0x1e, + .sampling = 0x0, .swizzle = ASC_SWIZZLE_IDENTITY, .planes = 1, + .bpp = { 4 }, .hsub = 1, .vsub = 1, + }, { + .fourcc = V4L2_PIX_FMT_NV12M, .layout = 0xc, .code = 0x1, + .sampling = 0x6, .swizzle = ASC_SWIZZLE_CBCR, .planes = 2, + .bpp = { 1, 2 }, .hsub = 2, .vsub = 2, .yuv = true, + }, { + .fourcc = V4L2_PIX_FMT_NV12, .layout = 0xc, .code = 0x1, + .sampling = 0x6, .swizzle = ASC_SWIZZLE_CBCR, .planes = 2, + .bpp = { 1, 2 }, .hsub = 2, .vsub = 2, .yuv = true, + }, { + /* 10 bits in the top of each 16-bit sample. */ + .fourcc = V4L2_PIX_FMT_P010, .layout = 0xc, .code = 0x2, + .sampling = 0x12, .swizzle = ASC_SWIZZLE_CBCR, .planes = 2, + .bpp = { 2, 4 }, .hsub = 2, .vsub = 2, .yuv = true, + }, +}; + +const struct asc_format *asc_format_by_index(unsigned int index) +{ + return index < ARRAY_SIZE(asc_formats) ? &asc_formats[index] : NULL; +} +EXPORT_SYMBOL_IF_KUNIT(asc_format_by_index); + +const struct asc_format *asc_find_format(u32 fourcc) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(asc_formats); i++) + if (asc_formats[i].fourcc == fourcc) + return &asc_formats[i]; + return NULL; +} +EXPORT_SYMBOL_IF_KUNIT(asc_find_format); + +/* Luma coefficients Kr and Kb in units of 1/10000. */ +struct asc_luma { + s64 kr, kb; +}; + +static int asc_luma_coefs(enum v4l2_ycbcr_encoding enc, struct asc_luma *l) +{ + switch (enc) { + case V4L2_YCBCR_ENC_601: + case V4L2_YCBCR_ENC_XV601: + *l = (struct asc_luma){ 2990, 1140 }; + return 0; + case V4L2_YCBCR_ENC_709: + case V4L2_YCBCR_ENC_XV709: + *l = (struct asc_luma){ 2126, 722 }; + return 0; + case V4L2_YCBCR_ENC_BT2020: + *l = (struct asc_luma){ 2627, 593 }; + return 0; + default: + return -EINVAL; + } +} + +/* round(num / den) for signed num and positive den */ +static s64 asc_div_round(s64 num, s64 den) +{ + return num >= 0 ? div64_s64(num + den / 2, den) : -div64_s64(-num + den / 2, den); +} + +/* A coefficient num/den (with the range scale sn/sd applied) in Q3.12. */ +static s16 asc_q12(s64 num, s64 den, s64 sn, s64 sd) +{ + return (s16)asc_div_round(num * sn << ASC_CSC_COEF_SHIFT, den * sd); +} + +/* + * Offsets are in units of 2^-24 of full scale. The engine works on a + * 16-bit internal scale, so the limited-range black level (8-bit code 16) + * is 0x1010 there; the chroma midpoint is 0x8020 (10-bit code 512). These + * are the levels the engine is driven with on macOS for every encoding + * and depth. + */ +#define ASC_LUMA_BLACK (0x1010 << 8) +#define ASC_CHROMA_MID (0x8020 << 8) + +/** + * asc_csc_compute - colour conversion between Y'CbCr and R'G'B' + * @enc: Y'CbCr encoding (luma coefficients) + * @quant: range of the Y'CbCr side (the R'G'B' side is full range) + * @yuv_to_rgb: direction + * @csc: result in register encoding + * + * Return: 0, or -EINVAL for an encoding the matrix cannot express. + */ +int asc_csc_compute(enum v4l2_ycbcr_encoding enc, + enum v4l2_quantization quant, bool yuv_to_rgb, + struct asc_csc *csc) +{ + const s64 one = 10000; + bool limited = quant != V4L2_QUANTIZATION_FULL_RANGE; + /* Range scales: luma 219/255 and chroma 224/255 for limited range. */ + s64 yn = limited ? 219 : 1, yd = limited ? 255 : 1; + s64 cn = limited ? 224 : 1, cd = limited ? 255 : 1; + struct asc_luma l; + s64 kg; + int i; + + if (asc_luma_coefs(enc, &l)) + return -EINVAL; + kg = one - l.kr - l.kb; + memset(csc, 0, sizeof(*csc)); + + if (yuv_to_rgb) { + /* R = Y + 2(1-Kr) Cr, B = Y + 2(1-Kb) Cb, G from Y = Kr R + Kg G + Kb B */ + for (i = 0; i < 3; i++) + csc->coef[i][0] = asc_q12(1, 1, yd, yn); + csc->coef[0][2] = asc_q12(2 * (one - l.kr), one, cd, cn); + csc->coef[1][1] = asc_q12(-2 * l.kb * (one - l.kb), one * kg, cd, cn); + csc->coef[1][2] = asc_q12(-2 * l.kr * (one - l.kr), one * kg, cd, cn); + csc->coef[2][1] = asc_q12(2 * (one - l.kb), one, cd, cn); + csc->pre[0] = limited ? -ASC_LUMA_BLACK : 0; + csc->pre[1] = -ASC_CHROMA_MID; + csc->pre[2] = -ASC_CHROMA_MID; + } else { + /* Y = Kr R + Kg G + Kb B, Cb = (B - Y) / 2(1-Kb), Cr = (R - Y) / 2(1-Kr) */ + csc->coef[0][0] = asc_q12(l.kr, one, yn, yd); + csc->coef[0][1] = asc_q12(kg, one, yn, yd); + csc->coef[0][2] = asc_q12(l.kb, one, yn, yd); + csc->coef[1][0] = asc_q12(-l.kr, 2 * (one - l.kb), cn, cd); + csc->coef[1][1] = asc_q12(-kg, 2 * (one - l.kb), cn, cd); + csc->coef[1][2] = asc_q12(1, 2, cn, cd); + csc->coef[2][0] = asc_q12(1, 2, cn, cd); + csc->coef[2][1] = asc_q12(-kg, 2 * (one - l.kr), cn, cd); + csc->coef[2][2] = asc_q12(-l.kb, 2 * (one - l.kr), cn, cd); + csc->post[0] = limited ? ASC_LUMA_BLACK : 0; + csc->post[1] = ASC_CHROMA_MID; + csc->post[2] = ASC_CHROMA_MID; + } + return 0; +} +EXPORT_SYMBOL_IF_KUNIT(asc_csc_compute); + +u32 asc_csc_offset_reg(s32 offset) +{ + return (u32)offset & ASC_CSC_OFFSET_MASK; +} +EXPORT_SYMBOL_IF_KUNIT(asc_csc_offset_reg); + +/** + * asc_scale_ratio - one scaler ratio register value + * @in: input extent in pixels + * @out: output extent in pixels + * + * Return: in/out in Q22 with the two lowest bits clear, as the engine + * takes it; 0 if @out is 0. + */ +u32 asc_scale_ratio(u32 in, u32 out) +{ + if (!out) + return 0; + return (u32)div_u64((u64)in << ASC_RATIO_SHIFT, out) & ~3u; +} +EXPORT_SYMBOL_IF_KUNIT(asc_scale_ratio); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.h b/drivers/media/platform/apple/scaler/apple-scaler-hw.h new file mode 100644 index 0000000000000..3093aebc3d975 --- /dev/null +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Apple silicon scaler/CSC (MSR): pipeline field encodings. + * + * These helpers compute register values from V4L2 state. They touch no + * hardware, so KUnit checks them against the values the engine is known + * to accept. + */ +#ifndef APPLE_SCALER_HW_H +#define APPLE_SCALER_HW_H + +#include +#include + +/* Colour-space converter block. */ +#define ASC_CSC_CTRL 0x3800 +#define ASC_CSC_CTRL_BYPASS 0x000e0000 +#define ASC_CSC_CTRL_ENABLE 0x000e0003 +#define ASC_CSC_MODE 0x3804 +#define ASC_CSC_MODE_DEFAULT 0xc +#define ASC_CSC_PRE_OFFSET(i) (0x3808 + 4 * (i)) +#define ASC_CSC_COEF(row, col) (0x3814 + 4 * (3 * (row) + (col))) +#define ASC_CSC_POST_OFFSET(i) (0x3838 + 4 * (i)) + +/* Matrix coefficients are signed Q3.12. */ +#define ASC_CSC_COEF_SHIFT 12 +/* Offsets are signed fractions of full scale: 1.0 = 1 << 24, 26-bit field. */ +#define ASC_CSC_OFFSET_SHIFT 24 +#define ASC_CSC_OFFSET_MASK GENMASK(25, 0) + +/* Scale ratios are unsigned Q22. */ +#define ASC_RATIO_SHIFT 22 + +/** + * struct asc_csc - one colour conversion, in register encoding + * @coef: 3x3 matrix, row = output channel, column = input channel + * @pre: offsets added to the input channels before the matrix + * @post: offsets added to the output channels after the matrix + */ +struct asc_csc { + s16 coef[3][3]; + s32 pre[3]; + s32 post[3]; +}; + +/** + * struct asc_format - a pixel format the engine reads and writes + * @fourcc: V4L2 pixel format + * @layout: layout class (source 0x180 / destination 0x280) + * @code: format code (source 0x184; destination 0x284 without bit 15) + * @sampling: subsampling descriptor (source 0x188 / destination 0x288 without bit 15) + * @swizzle: component order (source 0x1f8 / destination 0x2d8) + * @planes: colour planes (each needs its own DMA address) + * @bpp: bytes per sample position of each plane, at that plane's resolution + * @hsub: horizontal chroma subsampling of plane 1 + * @vsub: vertical chroma subsampling of plane 1 + * @yuv: Y'CbCr format (needs the CSC to pair with RGB) + * @alpha: carries an alpha channel + */ +struct asc_format { + u32 fourcc; + u32 layout; + u32 code; + u32 sampling; + u32 swizzle; + u8 planes; + u8 bpp[2]; + u8 hsub; + u8 vsub; + bool yuv; + bool alpha; +}; + +const struct asc_format *asc_find_format(u32 fourcc); +const struct asc_format *asc_format_by_index(unsigned int index); + +int asc_csc_compute(enum v4l2_ycbcr_encoding enc, + enum v4l2_quantization quant, bool yuv_to_rgb, + struct asc_csc *csc); +u32 asc_csc_offset_reg(s32 offset); + +u32 asc_scale_ratio(u32 in, u32 out); + +#endif /* APPLE_SCALER_HW_H */ diff --git a/drivers/media/platform/apple/scaler/apple-scaler-test.c b/drivers/media/platform/apple/scaler/apple-scaler-test.c new file mode 100644 index 0000000000000..58f3b2f6f3469 --- /dev/null +++ b/drivers/media/platform/apple/scaler/apple-scaler-test.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * KUnit tests for the Apple scaler/CSC register encodings. + * + * The expected words are what the engine was driven with for the same + * conversions in our macOS capture (traces/display/20261108-msr-trace), + * and they equal the textbook BT.601/BT.709/BT.2020 matrices in Q3.12. + */ +#include +#include +#include +#include + +#include "apple-scaler-hw.h" + +struct asc_csc_case { + const char *name; + enum v4l2_ycbcr_encoding enc; + enum v4l2_quantization quant; + bool yuv_to_rgb; + u16 coef[9]; + u32 pre[3]; + u32 post[3]; +}; + +static const struct asc_csc_case asc_csc_cases[] = { + { "BT.709 limited to RGB", V4L2_YCBCR_ENC_709, V4L2_QUANTIZATION_LIM_RANGE, true, + { 0x12a1, 0x0000, 0x1caf, 0x12a1, 0xfc97, 0xf779, 0x12a1, 0x21cc, 0x0000 }, + { 0x03eff000, 0x037fe000, 0x037fe000 }, { 0, 0, 0 } }, + { "BT.601 limited to RGB", V4L2_YCBCR_ENC_601, V4L2_QUANTIZATION_LIM_RANGE, true, + { 0x12a1, 0x0000, 0x1989, 0x12a1, 0xf9bb, 0xf2fe, 0x12a1, 0x2047, 0x0000 }, + { 0x03eff000, 0x037fe000, 0x037fe000 }, { 0, 0, 0 } }, + { "BT.709 full to RGB", V4L2_YCBCR_ENC_709, V4L2_QUANTIZATION_FULL_RANGE, true, + { 0x1000, 0x0000, 0x1932, 0x1000, 0xfd01, 0xf883, 0x1000, 0x1db1, 0x0000 }, + { 0x00000000, 0x037fe000, 0x037fe000 }, { 0, 0, 0 } }, + { "BT.2020 limited to RGB", V4L2_YCBCR_ENC_BT2020, V4L2_QUANTIZATION_LIM_RANGE, true, + { 0x12a1, 0x0000, 0x1adc, 0x12a1, 0xfd01, 0xf598, 0x12a1, 0x2245, 0x0000 }, + { 0x03eff000, 0x037fe000, 0x037fe000 }, { 0, 0, 0 } }, + { "RGB to BT.709 limited", V4L2_YCBCR_ENC_709, V4L2_QUANTIZATION_LIM_RANGE, false, + { 0x02ec, 0x09d4, 0x00fe, 0xfe64, 0xfa95, 0x0707, 0x0707, 0xf99e, 0xff5b }, + { 0, 0, 0 }, { 0x00101000, 0x00802000, 0x00802000 } }, + { "RGB to BT.601 limited", V4L2_YCBCR_ENC_601, V4L2_QUANTIZATION_LIM_RANGE, false, + { 0x041c, 0x0811, 0x0191, 0xfda1, 0xfb58, 0x0707, 0x0707, 0xfa1e, 0xfedb }, + { 0, 0, 0 }, { 0x00101000, 0x00802000, 0x00802000 } }, +}; + +static void asc_csc_case_desc(const struct asc_csc_case *c, char *desc) +{ + strscpy(desc, c->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(asc_csc, asc_csc_cases, asc_csc_case_desc); + +static void asc_test_csc(struct kunit *test) +{ + const struct asc_csc_case *c = test->param_value; + struct asc_csc csc; + int i; + + KUNIT_ASSERT_EQ(test, asc_csc_compute(c->enc, c->quant, c->yuv_to_rgb, &csc), 0); + for (i = 0; i < 9; i++) + KUNIT_EXPECT_EQ_MSG(test, (u16)csc.coef[i / 3][i % 3], c->coef[i], + "coefficient %d", i); + for (i = 0; i < 3; i++) { + KUNIT_EXPECT_EQ_MSG(test, asc_csc_offset_reg(csc.pre[i]), c->pre[i], + "pre-offset %d", i); + KUNIT_EXPECT_EQ_MSG(test, asc_csc_offset_reg(csc.post[i]), c->post[i], + "post-offset %d", i); + } +} + +static void asc_test_csc_rejects(struct kunit *test) +{ + struct asc_csc csc; + + KUNIT_EXPECT_EQ(test, asc_csc_compute(V4L2_YCBCR_ENC_SMPTE240M, + V4L2_QUANTIZATION_LIM_RANGE, true, &csc), + -EINVAL); + KUNIT_EXPECT_EQ(test, asc_csc_compute(V4L2_YCBCR_ENC_BT2020_CONST_LUM, + V4L2_QUANTIZATION_LIM_RANGE, true, &csc), + -EINVAL); +} + +/* Every matrix row must reproduce white and black exactly (to rounding). */ +static void asc_test_csc_white(struct kunit *test) +{ + static const enum v4l2_ycbcr_encoding encs[] = { + V4L2_YCBCR_ENC_601, V4L2_YCBCR_ENC_709, V4L2_YCBCR_ENC_BT2020, + }; + struct asc_csc csc; + int e, row; + + for (e = 0; e < ARRAY_SIZE(encs); e++) { + KUNIT_ASSERT_EQ(test, asc_csc_compute(encs[e], V4L2_QUANTIZATION_FULL_RANGE, + false, &csc), 0); + /* RGB -> YCbCr: Y row sums to 1.0, chroma rows to 0. */ + KUNIT_EXPECT_LE(test, abs(csc.coef[0][0] + csc.coef[0][1] + csc.coef[0][2] - 4096), 1); + for (row = 1; row < 3; row++) + KUNIT_EXPECT_LE(test, abs(csc.coef[row][0] + csc.coef[row][1] + + csc.coef[row][2]), 1); + } +} + +static void asc_test_ratio(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, asc_scale_ratio(1920, 1920), 0x400000); + KUNIT_EXPECT_EQ(test, asc_scale_ratio(1920, 1280), 0x600000); + KUNIT_EXPECT_EQ(test, asc_scale_ratio(1280, 1920), 0x2aaaa8); + KUNIT_EXPECT_EQ(test, asc_scale_ratio(640, 1920), 0x155554); + KUNIT_EXPECT_EQ(test, asc_scale_ratio(1920, 640), 0xc00000); + KUNIT_EXPECT_EQ(test, asc_scale_ratio(1, 0), 0); +} + +static void asc_test_formats(struct kunit *test) +{ + const struct asc_format *f; + unsigned int i; + + f = asc_find_format(V4L2_PIX_FMT_NV12M); + KUNIT_ASSERT_NOT_NULL(test, f); + KUNIT_EXPECT_EQ(test, f->layout, 0xc); + KUNIT_EXPECT_EQ(test, f->code, 0x1); + KUNIT_EXPECT_EQ(test, f->sampling, 0x6); + KUNIT_EXPECT_EQ(test, f->swizzle, 0x03000102); + + f = asc_find_format(V4L2_PIX_FMT_ARGB32); + KUNIT_ASSERT_NOT_NULL(test, f); + KUNIT_EXPECT_EQ(test, f->code, 0x1e); + KUNIT_EXPECT_EQ(test, f->swizzle, 0x03020100); + + KUNIT_EXPECT_NULL(test, asc_find_format(V4L2_PIX_FMT_YUYV)); + + for (i = 0; (f = asc_format_by_index(i)); i++) { + KUNIT_EXPECT_GE(test, f->planes, 1); + KUNIT_EXPECT_LE(test, f->planes, 2); + KUNIT_EXPECT_EQ(test, f->yuv, f->layout != 0x1); + KUNIT_EXPECT_EQ(test, f->planes == 2, f->yuv); + } +} + +static struct kunit_case asc_test_cases[] = { + KUNIT_CASE_PARAM(asc_test_csc, asc_csc_gen_params), + KUNIT_CASE(asc_test_csc_rejects), + KUNIT_CASE(asc_test_csc_white), + KUNIT_CASE(asc_test_ratio), + KUNIT_CASE(asc_test_formats), + {} +}; + +static struct kunit_suite asc_test_suite = { + .name = "apple-scaler", + .test_cases = asc_test_cases, +}; +kunit_test_suite(asc_test_suite); + +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); +MODULE_DESCRIPTION("KUnit tests for the Apple scaler/CSC encodings"); +MODULE_LICENSE("GPL"); From 937b53d686221230b089bedeebff30be01b11811 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:54:46 +1100 Subject: [PATCH 160/342] media: apple: scaler: build the register list for same-size jobs Add the job builder the submission path will use: it turns a source image, a destination image and an optional colour matrix into the ordered register writes for one job, ending with the pre-start tag and START. It covers conversions without scaling, which are the common case (decoder output to RGB, RGB to encoder input): - read and write DMA: layout, format code, subsampling, plane addresses, strides, component order, picture and per-plane sizes; - alpha fill when the source has no alpha and the destination does; - chroma upsampling for 4:2:x sources and downsampling for 4:2:x destinations, ordered dither when going from 10 to 8 bits; - the scaler at 1:1 (filters off, unit Q22 ratios); - the CSC matrix, offsets and clamps; - the per-plane memory request words and control words the engine is driven with on every job. KUnit builds three 1080p jobs (NV12 BT.709 to ARGB32, ARGB32 to NV12, P010 BT.2020 to ARGB32) and checks that every register ends with the value the engine was given for the same job on macOS, and that nothing else is written. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../platform/apple/scaler/apple-scaler-hw.c | 233 ++++++++++++- .../platform/apple/scaler/apple-scaler-hw.h | 43 +++ .../platform/apple/scaler/apple-scaler-test.c | 324 ++++++++++++++++++ 3 files changed, 599 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.c b/drivers/media/platform/apple/scaler/apple-scaler-hw.c index 2cbff1aee9e3d..5eb645a776470 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-hw.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -45,7 +46,7 @@ static const struct asc_format asc_formats[] = { /* 10 bits in the top of each 16-bit sample. */ .fourcc = V4L2_PIX_FMT_P010, .layout = 0xc, .code = 0x2, .sampling = 0x12, .swizzle = ASC_SWIZZLE_CBCR, .planes = 2, - .bpp = { 2, 4 }, .hsub = 2, .vsub = 2, .yuv = true, + .bpp = { 2, 4 }, .hsub = 2, .vsub = 2, .yuv = true, .wide = true, }, }; @@ -190,3 +191,233 @@ u32 asc_scale_ratio(u32 in, u32 out) return (u32)div_u64((u64)in << ASC_RATIO_SHIFT, out) & ~3u; } EXPORT_SYMBOL_IF_KUNIT(asc_scale_ratio); + +/* + * Job programming. The engine takes the whole pipeline state for every + * job; nothing carries over from the previous one. The order below follows + * the pipeline (source, destination, chroma, scaler, CSC, memory system) + * and ends with the pre-start tag and START. + */ +struct asc_emit { + struct asc_reg *w; + unsigned int n, max; +}; + +static void asc_emit(struct asc_emit *e, u32 off, u32 val) +{ + if (e->n < e->max) + e->w[e->n] = (struct asc_reg){ off, val }; + e->n++; +} + +/* Source (read DMA) and destination (write DMA) register banks. */ +struct asc_dma_regs { + u32 layout, code, sampling, plane, stride, offset, swizzle, size; + u32 plane_width, plane_height; + u32 flag; /* or-ed into layout-adjacent words on the write side */ +}; + +static const struct asc_dma_regs asc_rdma = { + .layout = 0x180, .code = 0x184, .sampling = 0x188, .plane = 0x198, + .stride = 0x1d8, .offset = 0x1e8, .swizzle = 0x1f8, .size = 0x1fc, + .plane_width = 0x234, .plane_height = 0x244, .flag = 0, +}; + +static const struct asc_dma_regs asc_wdma = { + .layout = 0x280, .code = 0x284, .sampling = 0x288, .plane = 0x290, + .stride = 0x2c0, .offset = 0x2cc, .swizzle = 0x2d8, .size = 0x2dc, + .plane_width = 0x308, .plane_height = 0x314, .flag = BIT(15), +}; + +static void asc_emit_image(struct asc_emit *e, const struct asc_dma_regs *r, + const struct asc_image *img) +{ + const struct asc_format *f = img->fmt; + /* Plane 2 is never used; the engine still takes it at luma size. */ + u32 pw[3] = { img->width, img->width / f->hsub, img->width }; + u32 ph[3] = { img->height, img->height / f->vsub, img->height }; + unsigned int i, nplanes = f->planes == 1 ? 3 : f->planes; + + asc_emit(e, r->layout, f->layout); + asc_emit(e, r->code, r->flag | f->code); + asc_emit(e, r->sampling, r->flag | f->sampling); + if (r->flag) + asc_emit(e, r->sampling + 4, r->flag); + else { + asc_emit(e, r->sampling + 4, 0); + asc_emit(e, r->sampling + 8, 0); + } + for (i = 0; i < nplanes; i++) { + u64 dva = i < f->planes ? img->dva[i] : 0; + + asc_emit(e, r->plane + 8 * i, lower_32_bits(dva)); + asc_emit(e, r->plane + 8 * i + 4, upper_32_bits(dva)); + asc_emit(e, r->stride + 4 * i, i < f->planes ? img->stride[i] : 0); + } + for (i = 0; i < 3; i++) + asc_emit(e, r->offset + 4 * i, 0); + asc_emit(e, r->swizzle, f->swizzle); + asc_emit(e, r->size, img->width); + asc_emit(e, r->size + 4, img->height); + for (i = 0; i < 3; i++) { + asc_emit(e, r->plane_width + 4 * i, f->planes == 1 ? img->width : pw[i]); + asc_emit(e, r->plane_height + 4 * i, f->planes == 1 ? img->height : ph[i]); + } +} + +/* Per-plane memory request words, as the engine is driven on macOS. */ +static void asc_emit_memory(struct asc_emit *e, const struct asc_job *job) +{ + const struct asc_format *s = job->src.fmt, *d = job->dst.fmt; + u32 wide = s->wide ? BIT(1) : 0; + unsigned int i; + + for (i = 0; i < 4; i++) { + asc_emit(e, 0x204 + 4 * i, 0x0007d311); + asc_emit(e, 0x214 + 4 * i, 0x00000707); + asc_emit(e, 0x224 + 4 * i, 0x00000020); + } + for (i = 0; i < 3; i++) { + asc_emit(e, 0x2e4 + 4 * i, 0x000ac211); + asc_emit(e, 0x2f0 + 4 * i, 0x0c0ac207); + asc_emit(e, 0x2fc + 4 * i, 0x04000620); + } + asc_emit(e, 0x254, 1); + + for (i = 0; i < 4; i++) + asc_emit(e, 0x13800 + 4 * i, 0); + asc_emit(e, 0x13810, 0x8 | wide); + asc_emit(e, 0x13814, (s->yuv ? 0x28 : 0x8) | wide); + asc_emit(e, 0x13818, (s->yuv ? 0x28 : 0x8) | wide); + asc_emit(e, 0x1381c, s->yuv ? 0x20 : 0x8); + asc_emit(e, 0x13c04, 0); + asc_emit(e, 0x13c10, 0x8); + asc_emit(e, 0x13c14, d->yuv ? 0x28 : 0x8); + asc_emit(e, 0x13c18, d->yuv ? 0x28 : 0x8); + asc_emit(e, 0x13c1c, d->yuv ? 0x20 : 0x8); + asc_emit(e, 0x13c00, 1); +} + +static void asc_emit_chroma(struct asc_emit *e, const struct asc_job *job) +{ + /* Upsampler interpolation weights, 0x800 = one half. */ + static const u32 up[8] = { 0, 0x800, 0x800, 0, 0, 0x800, 0x800, 0 }; + /* 2x2 ordered-dither index pattern, repeated over 4x4. */ + static const u32 dither[16] = { 0, 2, 0, 2, 3, 1, 3, 1, 0, 2, 0, 2, 3, 1, 3, 1 }; + const struct asc_format *s = job->src.fmt, *d = job->dst.fmt; + unsigned int i; + + asc_emit(e, 0x800, s->yuv && s->hsub > 1 ? 0xd : 0xc); + if (s->yuv && s->hsub > 1) + for (i = 0; i < ARRAY_SIZE(up); i++) + asc_emit(e, 0x804 + 4 * i, up[i]); + asc_emit(e, 0x824, 0xc); + asc_emit(e, 0x900, d->yuv && d->hsub > 1 ? 0x00010103 : 0); + if (s->wide && !d->wide) { + asc_emit(e, 0xa00, 0x02020200); + for (i = 0; i < ARRAY_SIZE(dither); i++) + asc_emit(e, 0xa80 + 4 * i, dither[i]); + } else { + asc_emit(e, 0xa00, 0); + } +} + +/* Scaler at 1:1: polyphase filters off, unit ratios, zero initial phase. */ +static void asc_emit_unscaled(struct asc_emit *e, const struct asc_job *job) +{ + static const u32 base[2] = { 0x1000, 0x2000 }; + u32 flags = job->src.fmt->yuv && job->src.fmt->hsub > 1 ? BIT(1) : 0; + u32 one = 1u << ASC_RATIO_SHIFT; + unsigned int i; + + for (i = 0; i < 2; i++) { + asc_emit(e, base[i], flags); + asc_emit(e, base[i] + 0x04, 0); + asc_emit(e, base[i] + 0x08, 0); + asc_emit(e, base[i] + 0x0c, one); + asc_emit(e, base[i] + 0x10, one); + asc_emit(e, base[i] + 0x14, one); + asc_emit(e, base[i] + 0x18, one); + asc_emit(e, base[i] + 0x1c, 0); + asc_emit(e, base[i] + 0x20, one); + asc_emit(e, base[i] + 0x24, one); + } + asc_emit(e, 0x480, 0); +} + +static void asc_emit_csc(struct asc_emit *e, const struct asc_csc *csc) +{ + unsigned int r, c; + + asc_emit(e, ASC_CSC_MODE, ASC_CSC_MODE_DEFAULT); + for (c = 0; c < 3; c++) + asc_emit(e, ASC_CSC_PRE_OFFSET(c), asc_csc_offset_reg(csc->pre[c])); + for (r = 0; r < 3; r++) + for (c = 0; c < 3; c++) + asc_emit(e, ASC_CSC_COEF(r, c), (u16)csc->coef[r][c]); + for (c = 0; c < 3; c++) + asc_emit(e, ASC_CSC_POST_OFFSET(c), asc_csc_offset_reg(csc->post[c])); + /* Output clamps: full signed range on every channel. */ + for (c = 0; c < 3; c++) { + asc_emit(e, 0xa98c + 4 * c, 0x80000001); + asc_emit(e, 0xa998 + 4 * c, 0x7fffffff); + asc_emit(e, 0xa9a4 + 4 * c, 0x80000001); + asc_emit(e, 0xa9b0 + 4 * c, 0x7fffffff); + } + asc_emit(e, ASC_CSC_CTRL, ASC_CSC_CTRL_ENABLE); +} + +/* Control words the engine is driven with for every job on macOS. */ +static const struct asc_reg asc_job_fixed[] = { + { 0x000e4, 0x00000000 }, { 0x000e8, 0x00000038 }, { 0x00124, 0x00000000 }, + { 0x00380, 0x00000000 }, { 0x03000, 0x00000000 }, { 0x07418, 0xffffffff }, + { 0x16000, 0x00000000 }, { 0x16004, 0x244024c0 }, { 0x16080, 0x00000000 }, + { 0x16084, 0x0b710367 }, { 0x16088, 0x00000128 }, { 0x16504, 0x02000500 }, + { 0x16508, 0x00003200 }, { 0x1651c, 0x00851400 }, { 0x16534, 0x00000008 }, + { 0x16568, 0x00250500 }, { 0x16588, 0x00496513 }, { 0x16600, 0x00000015 }, + { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, { 0x2e300, 0x03804038 }, + { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, { 0x2e30c, 0x02550255 }, + { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, { 0x2e318, 0x02550000 }, +}; + +/** + * asc_job_build - register writes for one job, in order + * @job: the conversion; source and destination must be the same size + * @w: output array + * @max: capacity of @w + * + * Return: number of writes, -EINVAL for a job this path cannot run, or + * -ENOSPC if @w is too small. + */ +int asc_job_build(const struct asc_job *job, struct asc_reg *w, unsigned int max) +{ + const struct asc_format *s = job->src.fmt, *d = job->dst.fmt; + struct asc_emit e = { .w = w, .max = max }; + unsigned int i; + + if (!s || !d || job->src.width != job->dst.width || + job->src.height != job->dst.height) + return -EINVAL; + /* Y'CbCr <-> R'G'B' needs a matrix; same-family jobs must not have one. */ + if ((s->yuv != d->yuv) != !!job->csc) + return -EINVAL; + + asc_emit(&e, ASC_CSC_CTRL, ASC_CSC_CTRL_BYPASS); + asc_emit_image(&e, &asc_rdma, &job->src); + asc_emit_image(&e, &asc_wdma, &job->dst); + asc_emit_memory(&e, job); + /* Alpha fill: constant opaque alpha when the source has none. */ + asc_emit(&e, 0x8c, (d->alpha && !s->alpha ? BIT(31) : 0) | 0xffff); + asc_emit_chroma(&e, job); + asc_emit_unscaled(&e, job); + if (job->csc) + asc_emit_csc(&e, job->csc); + for (i = 0; i < ARRAY_SIZE(asc_job_fixed); i++) + asc_emit(&e, asc_job_fixed[i].off, asc_job_fixed[i].val); + asc_emit(&e, 0x110, job->transform_id); + asc_emit(&e, 0x098, 0xfffffffe); + asc_emit(&e, 0x080, 1); + + return e.n <= max ? e.n : -ENOSPC; +} +EXPORT_SYMBOL_IF_KUNIT(asc_job_build); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.h b/drivers/media/platform/apple/scaler/apple-scaler-hw.h index 3093aebc3d975..cf371272dce66 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-hw.h +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.h @@ -56,6 +56,7 @@ struct asc_csc { * @vsub: vertical chroma subsampling of plane 1 * @yuv: Y'CbCr format (needs the CSC to pair with RGB) * @alpha: carries an alpha channel + * @wide: samples are 16 bits in memory (more than 8 significant bits) */ struct asc_format { u32 fourcc; @@ -69,8 +70,50 @@ struct asc_format { u8 vsub; bool yuv; bool alpha; + bool wide; }; +/* One register write: byte offset in the MSR aperture and value. */ +struct asc_reg { + u32 off; + u32 val; +}; + +#define ASC_MAX_PLANES 2 +#define ASC_JOB_MAX_WRITES 224 + +/** + * struct asc_image - one side of a job + * @fmt: pixel format + * @width: width in pixels + * @height: height in pixels + * @dva: DMA address of each colour plane + * @stride: bytes per line of each colour plane + */ +struct asc_image { + const struct asc_format *fmt; + u32 width; + u32 height; + u64 dva[ASC_MAX_PLANES]; + u32 stride[ASC_MAX_PLANES]; +}; + +/** + * struct asc_job - a complete conversion + * @src: image read + * @dst: image written + * @csc: colour conversion, or NULL to pass components through + * @transform_id: tag the engine carries for this job + */ +struct asc_job { + struct asc_image src; + struct asc_image dst; + const struct asc_csc *csc; + u32 transform_id; +}; + +int asc_job_build(const struct asc_job *job, struct asc_reg *w, unsigned int max); + const struct asc_format *asc_find_format(u32 fourcc); const struct asc_format *asc_format_by_index(unsigned int index); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-test.c b/drivers/media/platform/apple/scaler/apple-scaler-test.c index 58f3b2f6f3469..4e61ad54e59a9 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-test.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-test.c @@ -12,6 +12,7 @@ #include #include "apple-scaler-hw.h" +#include "apple-scaler-regs.h" struct asc_csc_case { const char *name; @@ -138,12 +139,335 @@ static void asc_test_formats(struct kunit *test) } } + +/* + * Final register state of three jobs as the engine was driven on macOS + * (1920x1080, same size): NV12 BT.709 limited -> ARGB32, ARGB32 -> NV12 + * BT.709 limited, P010 BT.2020 limited -> ARGB32. The CSC matrix words + * (0x3814..0x3834) are covered by asc_test_csc. + */ +static const struct asc_reg asc_expect_nv12_709_argb[] = { + { 0x00080, 0x00000001 }, { 0x0008c, 0x8000ffff }, { 0x00098, 0xfffffffe }, + { 0x000e4, 0x00000000 }, { 0x000e8, 0x00000038 }, { 0x00110, 0x00000094 }, + { 0x00124, 0x00000000 }, { 0x00180, 0x0000000c }, { 0x00184, 0x00000001 }, + { 0x00188, 0x00000006 }, { 0x0018c, 0x00000000 }, { 0x00190, 0x00000000 }, + { 0x00198, 0x007f0200 }, { 0x0019c, 0x00000100 }, { 0x001a0, 0x009ea600 }, + { 0x001a4, 0x00000100 }, { 0x001d8, 0x00000780 }, { 0x001dc, 0x00000780 }, + { 0x001e8, 0x00000000 }, { 0x001ec, 0x00000000 }, { 0x001f0, 0x00000000 }, + { 0x001f8, 0x03000102 }, { 0x001fc, 0x00000780 }, { 0x00200, 0x00000438 }, + { 0x00204, 0x0007d311 }, { 0x00208, 0x0007d311 }, { 0x0020c, 0x0007d311 }, + { 0x00210, 0x0007d311 }, { 0x00214, 0x00000707 }, { 0x00218, 0x00000707 }, + { 0x0021c, 0x00000707 }, { 0x00220, 0x00000707 }, { 0x00224, 0x00000020 }, + { 0x00228, 0x00000020 }, { 0x0022c, 0x00000020 }, { 0x00230, 0x00000020 }, + { 0x00234, 0x00000780 }, { 0x00238, 0x000003c0 }, { 0x0023c, 0x00000780 }, + { 0x00244, 0x00000438 }, { 0x00248, 0x0000021c }, { 0x0024c, 0x00000438 }, + { 0x00254, 0x00000001 }, { 0x00280, 0x00000001 }, { 0x00284, 0x0000801e }, + { 0x00288, 0x00008000 }, { 0x0028c, 0x00008000 }, { 0x00290, 0x00000000 }, + { 0x00294, 0x00000100 }, { 0x00298, 0x00000000 }, { 0x0029c, 0x00000000 }, + { 0x002a0, 0x00000000 }, { 0x002a4, 0x00000000 }, { 0x002c0, 0x00001e00 }, + { 0x002c4, 0x00000000 }, { 0x002c8, 0x00000000 }, { 0x002cc, 0x00000000 }, + { 0x002d0, 0x00000000 }, { 0x002d4, 0x00000000 }, { 0x002d8, 0x03020100 }, + { 0x002dc, 0x00000780 }, { 0x002e0, 0x00000438 }, { 0x002e4, 0x000ac211 }, + { 0x002e8, 0x000ac211 }, { 0x002ec, 0x000ac211 }, { 0x002f0, 0x0c0ac207 }, + { 0x002f4, 0x0c0ac207 }, { 0x002f8, 0x0c0ac207 }, { 0x002fc, 0x04000620 }, + { 0x00300, 0x04000620 }, { 0x00304, 0x04000620 }, { 0x00308, 0x00000780 }, + { 0x0030c, 0x00000780 }, { 0x00310, 0x00000780 }, { 0x00314, 0x00000438 }, + { 0x00318, 0x00000438 }, { 0x0031c, 0x00000438 }, { 0x00380, 0x00000000 }, + { 0x00480, 0x00000000 }, { 0x00800, 0x0000000d }, { 0x00804, 0x00000000 }, + { 0x00808, 0x00000800 }, { 0x0080c, 0x00000800 }, { 0x00810, 0x00000000 }, + { 0x00814, 0x00000000 }, { 0x00818, 0x00000800 }, { 0x0081c, 0x00000800 }, + { 0x00820, 0x00000000 }, { 0x00824, 0x0000000c }, { 0x00900, 0x00000000 }, + { 0x00a00, 0x00000000 }, { 0x01000, 0x00000002 }, { 0x01004, 0x00000000 }, + { 0x01008, 0x00000000 }, { 0x0100c, 0x00400000 }, { 0x01010, 0x00400000 }, + { 0x01014, 0x00400000 }, { 0x01018, 0x00400000 }, { 0x0101c, 0x00000000 }, + { 0x01020, 0x00400000 }, { 0x01024, 0x00400000 }, { 0x02000, 0x00000002 }, + { 0x02004, 0x00000000 }, { 0x02008, 0x00000000 }, { 0x0200c, 0x00400000 }, + { 0x02010, 0x00400000 }, { 0x02014, 0x00400000 }, { 0x02018, 0x00400000 }, + { 0x0201c, 0x00000000 }, { 0x02020, 0x00400000 }, { 0x02024, 0x00400000 }, + { 0x03000, 0x00000000 }, { 0x03800, 0x000e0003 }, { 0x03804, 0x0000000c }, + { 0x03808, 0x03eff000 }, { 0x0380c, 0x037fe000 }, { 0x03810, 0x037fe000 }, + { 0x03838, 0x00000000 }, { 0x0383c, 0x00000000 }, { 0x03840, 0x00000000 }, + { 0x07418, 0xffffffff }, { 0x0a98c, 0x80000001 }, { 0x0a990, 0x80000001 }, + { 0x0a994, 0x80000001 }, { 0x0a998, 0x7fffffff }, { 0x0a99c, 0x7fffffff }, + { 0x0a9a0, 0x7fffffff }, { 0x0a9a4, 0x80000001 }, { 0x0a9a8, 0x80000001 }, + { 0x0a9ac, 0x80000001 }, { 0x0a9b0, 0x7fffffff }, { 0x0a9b4, 0x7fffffff }, + { 0x0a9b8, 0x7fffffff }, { 0x13800, 0x00000000 }, { 0x13804, 0x00000000 }, + { 0x13808, 0x00000000 }, { 0x1380c, 0x00000000 }, { 0x13810, 0x00000008 }, + { 0x13814, 0x00000028 }, { 0x13818, 0x00000028 }, { 0x1381c, 0x00000020 }, + { 0x13c00, 0x00000001 }, { 0x13c04, 0x00000000 }, { 0x13c10, 0x00000008 }, + { 0x13c14, 0x00000008 }, { 0x13c18, 0x00000008 }, { 0x13c1c, 0x00000008 }, + { 0x16000, 0x00000000 }, { 0x16004, 0x244024c0 }, { 0x16080, 0x00000000 }, + { 0x16084, 0x0b710367 }, { 0x16088, 0x00000128 }, { 0x16504, 0x02000500 }, + { 0x16508, 0x00003200 }, { 0x1651c, 0x00851400 }, { 0x16534, 0x00000008 }, + { 0x16568, 0x00250500 }, { 0x16588, 0x00496513 }, { 0x16600, 0x00000015 }, + { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, { 0x2e300, 0x03804038 }, + { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, { 0x2e30c, 0x02550255 }, + { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, { 0x2e318, 0x02550000 }, +}; + +static const struct asc_reg asc_expect_argb_nv12_709[] = { + { 0x00080, 0x00000001 }, { 0x0008c, 0x0000ffff }, { 0x00098, 0xfffffffe }, + { 0x000e4, 0x00000000 }, { 0x000e8, 0x00000038 }, { 0x00110, 0x000000b4 }, + { 0x00124, 0x00000000 }, { 0x00180, 0x00000001 }, { 0x00184, 0x0000001e }, + { 0x00188, 0x00000000 }, { 0x0018c, 0x00000000 }, { 0x00190, 0x00000000 }, + { 0x00198, 0x00300000 }, { 0x0019c, 0x00000100 }, { 0x001a0, 0x00000000 }, + { 0x001a4, 0x00000000 }, { 0x001a8, 0x00000000 }, { 0x001ac, 0x00000000 }, + { 0x001d8, 0x00001e00 }, { 0x001dc, 0x00000000 }, { 0x001e0, 0x00000000 }, + { 0x001e8, 0x00000000 }, { 0x001ec, 0x00000000 }, { 0x001f0, 0x00000000 }, + { 0x001f8, 0x03020100 }, { 0x001fc, 0x00000780 }, { 0x00200, 0x00000438 }, + { 0x00204, 0x0007d311 }, { 0x00208, 0x0007d311 }, { 0x0020c, 0x0007d311 }, + { 0x00210, 0x0007d311 }, { 0x00214, 0x00000707 }, { 0x00218, 0x00000707 }, + { 0x0021c, 0x00000707 }, { 0x00220, 0x00000707 }, { 0x00224, 0x00000020 }, + { 0x00228, 0x00000020 }, { 0x0022c, 0x00000020 }, { 0x00230, 0x00000020 }, + { 0x00234, 0x00000780 }, { 0x00238, 0x00000780 }, { 0x0023c, 0x00000780 }, + { 0x00244, 0x00000438 }, { 0x00248, 0x00000438 }, { 0x0024c, 0x00000438 }, + { 0x00254, 0x00000001 }, { 0x00280, 0x0000000c }, { 0x00284, 0x00008001 }, + { 0x00288, 0x00008006 }, { 0x0028c, 0x00008000 }, { 0x00290, 0x00000200 }, + { 0x00294, 0x00000100 }, { 0x00298, 0x001fa600 }, { 0x0029c, 0x00000100 }, + { 0x002c0, 0x00000780 }, { 0x002c4, 0x00000780 }, { 0x002cc, 0x00000000 }, + { 0x002d0, 0x00000000 }, { 0x002d4, 0x00000000 }, { 0x002d8, 0x03000102 }, + { 0x002dc, 0x00000780 }, { 0x002e0, 0x00000438 }, { 0x002e4, 0x000ac211 }, + { 0x002e8, 0x000ac211 }, { 0x002ec, 0x000ac211 }, { 0x002f0, 0x0c0ac207 }, + { 0x002f4, 0x0c0ac207 }, { 0x002f8, 0x0c0ac207 }, { 0x002fc, 0x04000620 }, + { 0x00300, 0x04000620 }, { 0x00304, 0x04000620 }, { 0x00308, 0x00000780 }, + { 0x0030c, 0x000003c0 }, { 0x00310, 0x00000780 }, { 0x00314, 0x00000438 }, + { 0x00318, 0x0000021c }, { 0x0031c, 0x00000438 }, { 0x00380, 0x00000000 }, + { 0x00480, 0x00000000 }, { 0x00800, 0x0000000c }, { 0x00824, 0x0000000c }, + { 0x00900, 0x00010103 }, { 0x00a00, 0x00000000 }, { 0x01000, 0x00000000 }, + { 0x01004, 0x00000000 }, { 0x01008, 0x00000000 }, { 0x0100c, 0x00400000 }, + { 0x01010, 0x00400000 }, { 0x01014, 0x00400000 }, { 0x01018, 0x00400000 }, + { 0x0101c, 0x00000000 }, { 0x01020, 0x00400000 }, { 0x01024, 0x00400000 }, + { 0x02000, 0x00000000 }, { 0x02004, 0x00000000 }, { 0x02008, 0x00000000 }, + { 0x0200c, 0x00400000 }, { 0x02010, 0x00400000 }, { 0x02014, 0x00400000 }, + { 0x02018, 0x00400000 }, { 0x0201c, 0x00000000 }, { 0x02020, 0x00400000 }, + { 0x02024, 0x00400000 }, { 0x03000, 0x00000000 }, { 0x03800, 0x000e0003 }, + { 0x03804, 0x0000000c }, { 0x03808, 0x00000000 }, { 0x0380c, 0x00000000 }, + { 0x03810, 0x00000000 }, { 0x03838, 0x00101000 }, { 0x0383c, 0x00802000 }, + { 0x03840, 0x00802000 }, { 0x07418, 0xffffffff }, { 0x0a98c, 0x80000001 }, + { 0x0a990, 0x80000001 }, { 0x0a994, 0x80000001 }, { 0x0a998, 0x7fffffff }, + { 0x0a99c, 0x7fffffff }, { 0x0a9a0, 0x7fffffff }, { 0x0a9a4, 0x80000001 }, + { 0x0a9a8, 0x80000001 }, { 0x0a9ac, 0x80000001 }, { 0x0a9b0, 0x7fffffff }, + { 0x0a9b4, 0x7fffffff }, { 0x0a9b8, 0x7fffffff }, { 0x13800, 0x00000000 }, + { 0x13804, 0x00000000 }, { 0x13808, 0x00000000 }, { 0x1380c, 0x00000000 }, + { 0x13810, 0x00000008 }, { 0x13814, 0x00000008 }, { 0x13818, 0x00000008 }, + { 0x1381c, 0x00000008 }, { 0x13c00, 0x00000001 }, { 0x13c04, 0x00000000 }, + { 0x13c10, 0x00000008 }, { 0x13c14, 0x00000028 }, { 0x13c18, 0x00000028 }, + { 0x13c1c, 0x00000020 }, { 0x16000, 0x00000000 }, { 0x16004, 0x244024c0 }, + { 0x16080, 0x00000000 }, { 0x16084, 0x0b710367 }, { 0x16088, 0x00000128 }, + { 0x16504, 0x02000500 }, { 0x16508, 0x00003200 }, { 0x1651c, 0x00851400 }, + { 0x16534, 0x00000008 }, { 0x16568, 0x00250500 }, { 0x16588, 0x00496513 }, + { 0x16600, 0x00000015 }, { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, + { 0x2e300, 0x03804038 }, { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, + { 0x2e30c, 0x02550255 }, { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, + { 0x2e318, 0x02550000 }, +}; + +static const struct asc_reg asc_expect_p010_2020_argb[] = { + { 0x00080, 0x00000001 }, { 0x0008c, 0x8000ffff }, { 0x00098, 0xfffffffe }, + { 0x000e4, 0x00000000 }, { 0x000e8, 0x00000038 }, { 0x00110, 0x000000bc }, + { 0x00124, 0x00000000 }, { 0x00180, 0x0000000c }, { 0x00184, 0x00000002 }, + { 0x00188, 0x00000012 }, { 0x0018c, 0x00000000 }, { 0x00190, 0x00000000 }, + { 0x00198, 0x007f0200 }, { 0x0019c, 0x00000100 }, { 0x001a0, 0x00be4a00 }, + { 0x001a4, 0x00000100 }, { 0x001d8, 0x00000f00 }, { 0x001dc, 0x00000f00 }, + { 0x001e8, 0x00000000 }, { 0x001ec, 0x00000000 }, { 0x001f0, 0x00000000 }, + { 0x001f8, 0x03000102 }, { 0x001fc, 0x00000780 }, { 0x00200, 0x00000438 }, + { 0x00204, 0x0007d311 }, { 0x00208, 0x0007d311 }, { 0x0020c, 0x0007d311 }, + { 0x00210, 0x0007d311 }, { 0x00214, 0x00000707 }, { 0x00218, 0x00000707 }, + { 0x0021c, 0x00000707 }, { 0x00220, 0x00000707 }, { 0x00224, 0x00000020 }, + { 0x00228, 0x00000020 }, { 0x0022c, 0x00000020 }, { 0x00230, 0x00000020 }, + { 0x00234, 0x00000780 }, { 0x00238, 0x000003c0 }, { 0x0023c, 0x00000780 }, + { 0x00244, 0x00000438 }, { 0x00248, 0x0000021c }, { 0x0024c, 0x00000438 }, + { 0x00254, 0x00000001 }, { 0x00280, 0x00000001 }, { 0x00284, 0x0000801e }, + { 0x00288, 0x00008000 }, { 0x0028c, 0x00008000 }, { 0x00290, 0x00000000 }, + { 0x00294, 0x00000100 }, { 0x00298, 0x00000000 }, { 0x0029c, 0x00000000 }, + { 0x002a0, 0x00000000 }, { 0x002a4, 0x00000000 }, { 0x002c0, 0x00001e00 }, + { 0x002c4, 0x00000000 }, { 0x002c8, 0x00000000 }, { 0x002cc, 0x00000000 }, + { 0x002d0, 0x00000000 }, { 0x002d4, 0x00000000 }, { 0x002d8, 0x03020100 }, + { 0x002dc, 0x00000780 }, { 0x002e0, 0x00000438 }, { 0x002e4, 0x000ac211 }, + { 0x002e8, 0x000ac211 }, { 0x002ec, 0x000ac211 }, { 0x002f0, 0x0c0ac207 }, + { 0x002f4, 0x0c0ac207 }, { 0x002f8, 0x0c0ac207 }, { 0x002fc, 0x04000620 }, + { 0x00300, 0x04000620 }, { 0x00304, 0x04000620 }, { 0x00308, 0x00000780 }, + { 0x0030c, 0x00000780 }, { 0x00310, 0x00000780 }, { 0x00314, 0x00000438 }, + { 0x00318, 0x00000438 }, { 0x0031c, 0x00000438 }, { 0x00380, 0x00000000 }, + { 0x00480, 0x00000000 }, { 0x00800, 0x0000000d }, { 0x00804, 0x00000000 }, + { 0x00808, 0x00000800 }, { 0x0080c, 0x00000800 }, { 0x00810, 0x00000000 }, + { 0x00814, 0x00000000 }, { 0x00818, 0x00000800 }, { 0x0081c, 0x00000800 }, + { 0x00820, 0x00000000 }, { 0x00824, 0x0000000c }, { 0x00900, 0x00000000 }, + { 0x00a00, 0x02020200 }, { 0x00a80, 0x00000000 }, { 0x00a84, 0x00000002 }, + { 0x00a88, 0x00000000 }, { 0x00a8c, 0x00000002 }, { 0x00a90, 0x00000003 }, + { 0x00a94, 0x00000001 }, { 0x00a98, 0x00000003 }, { 0x00a9c, 0x00000001 }, + { 0x00aa0, 0x00000000 }, { 0x00aa4, 0x00000002 }, { 0x00aa8, 0x00000000 }, + { 0x00aac, 0x00000002 }, { 0x00ab0, 0x00000003 }, { 0x00ab4, 0x00000001 }, + { 0x00ab8, 0x00000003 }, { 0x00abc, 0x00000001 }, { 0x01000, 0x00000002 }, + { 0x01004, 0x00000000 }, { 0x01008, 0x00000000 }, { 0x0100c, 0x00400000 }, + { 0x01010, 0x00400000 }, { 0x01014, 0x00400000 }, { 0x01018, 0x00400000 }, + { 0x0101c, 0x00000000 }, { 0x01020, 0x00400000 }, { 0x01024, 0x00400000 }, + { 0x02000, 0x00000002 }, { 0x02004, 0x00000000 }, { 0x02008, 0x00000000 }, + { 0x0200c, 0x00400000 }, { 0x02010, 0x00400000 }, { 0x02014, 0x00400000 }, + { 0x02018, 0x00400000 }, { 0x0201c, 0x00000000 }, { 0x02020, 0x00400000 }, + { 0x02024, 0x00400000 }, { 0x03000, 0x00000000 }, { 0x03800, 0x000e0003 }, + { 0x03804, 0x0000000c }, { 0x03808, 0x03eff000 }, { 0x0380c, 0x037fe000 }, + { 0x03810, 0x037fe000 }, { 0x03838, 0x00000000 }, { 0x0383c, 0x00000000 }, + { 0x03840, 0x00000000 }, { 0x07418, 0xffffffff }, { 0x0a98c, 0x80000001 }, + { 0x0a990, 0x80000001 }, { 0x0a994, 0x80000001 }, { 0x0a998, 0x7fffffff }, + { 0x0a99c, 0x7fffffff }, { 0x0a9a0, 0x7fffffff }, { 0x0a9a4, 0x80000001 }, + { 0x0a9a8, 0x80000001 }, { 0x0a9ac, 0x80000001 }, { 0x0a9b0, 0x7fffffff }, + { 0x0a9b4, 0x7fffffff }, { 0x0a9b8, 0x7fffffff }, { 0x13800, 0x00000000 }, + { 0x13804, 0x00000000 }, { 0x13808, 0x00000000 }, { 0x1380c, 0x00000000 }, + { 0x13810, 0x0000000a }, { 0x13814, 0x0000002a }, { 0x13818, 0x0000002a }, + { 0x1381c, 0x00000020 }, { 0x13c00, 0x00000001 }, { 0x13c04, 0x00000000 }, + { 0x13c10, 0x00000008 }, { 0x13c14, 0x00000008 }, { 0x13c18, 0x00000008 }, + { 0x13c1c, 0x00000008 }, { 0x16000, 0x00000000 }, { 0x16004, 0x244024c0 }, + { 0x16080, 0x00000000 }, { 0x16084, 0x0b710367 }, { 0x16088, 0x00000128 }, + { 0x16504, 0x02000500 }, { 0x16508, 0x00003200 }, { 0x1651c, 0x00851400 }, + { 0x16534, 0x00000008 }, { 0x16568, 0x00250500 }, { 0x16588, 0x00496513 }, + { 0x16600, 0x00000015 }, { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, + { 0x2e300, 0x03804038 }, { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, + { 0x2e30c, 0x02550255 }, { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, + { 0x2e318, 0x02550000 }, +}; + + +struct asc_job_case { + const char *name; + u32 src, dst; + enum v4l2_ycbcr_encoding enc; + const struct asc_reg *expect; + unsigned int n; +}; + +#define ASC_JOB_CASE(_n, _s, _d, _e, _x) \ + { _n, _s, _d, _e, _x, ARRAY_SIZE(_x) } + +static const struct asc_job_case asc_job_cases[] = { + ASC_JOB_CASE("NV12 BT.709 to ARGB32", V4L2_PIX_FMT_NV12M, V4L2_PIX_FMT_ARGB32, + V4L2_YCBCR_ENC_709, asc_expect_nv12_709_argb), + ASC_JOB_CASE("ARGB32 to NV12 BT.709", V4L2_PIX_FMT_ARGB32, V4L2_PIX_FMT_NV12M, + V4L2_YCBCR_ENC_709, asc_expect_argb_nv12_709), + ASC_JOB_CASE("P010 BT.2020 to ARGB32", V4L2_PIX_FMT_P010, V4L2_PIX_FMT_ARGB32, + V4L2_YCBCR_ENC_BT2020, asc_expect_p010_2020_argb), +}; + +static void asc_job_case_desc(const struct asc_job_case *c, char *desc) +{ + strscpy(desc, c->name, KUNIT_PARAM_DESC_SIZE); +} + +KUNIT_ARRAY_PARAM(asc_job, asc_job_cases, asc_job_case_desc); + +static u32 asc_expect_get(const struct asc_job_case *c, u32 off) +{ + unsigned int i; + + for (i = 0; i < c->n; i++) + if (c->expect[i].off == off) + return c->expect[i].val; + return 0; +} + +static void asc_image_from_expect(const struct asc_job_case *c, struct asc_image *img, + u32 fourcc, u32 plane, u32 stride) +{ + unsigned int i; + + img->fmt = asc_find_format(fourcc); + img->width = 1920; + img->height = 1080; + for (i = 0; i < ASC_MAX_PLANES; i++) { + img->dva[i] = asc_expect_get(c, plane + 8 * i) | + (u64)asc_expect_get(c, plane + 8 * i + 4) << 32; + img->stride[i] = asc_expect_get(c, stride + 4 * i); + } +} + +static bool asc_is_matrix(u32 off) +{ + return off >= ASC_CSC_COEF(0, 0) && off <= ASC_CSC_COEF(2, 2); +} + +static void asc_test_job(struct kunit *test) +{ + const struct asc_job_case *c = test->param_value; + struct asc_reg *w; + struct asc_csc csc; + struct asc_job job = {}; + unsigned int i, j; + int n; + + w = kunit_kcalloc(test, ASC_JOB_MAX_WRITES, sizeof(*w), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, w); + + asc_image_from_expect(c, &job.src, c->src, 0x198, 0x1d8); + asc_image_from_expect(c, &job.dst, c->dst, 0x290, 0x2c0); + KUNIT_ASSERT_NOT_NULL(test, job.src.fmt); + KUNIT_ASSERT_NOT_NULL(test, job.dst.fmt); + KUNIT_ASSERT_EQ(test, asc_csc_compute(c->enc, V4L2_QUANTIZATION_LIM_RANGE, + job.src.fmt->yuv, &csc), 0); + job.csc = &csc; + job.transform_id = asc_expect_get(c, ASC_TRANSFORM_ID); + + n = asc_job_build(&job, w, ASC_JOB_MAX_WRITES); + KUNIT_ASSERT_GT(test, n, 0); + + /* START last, the pre-start tag right before it. */ + KUNIT_EXPECT_EQ(test, w[n - 1].off, ASC_START); + KUNIT_EXPECT_EQ(test, w[n - 1].val, 1); + KUNIT_EXPECT_EQ(test, w[n - 2].off, ASC_PRE_START); + + /* Every register macOS set ends with the same value... */ + for (i = 0; i < c->n; i++) { + u32 val = 0; + bool found = false; + + for (j = 0; j < n; j++) + if (w[j].off == c->expect[i].off) { + val = w[j].val; + found = true; + } + KUNIT_EXPECT_TRUE_MSG(test, found, "%#x not written", c->expect[i].off); + KUNIT_EXPECT_EQ_MSG(test, val, c->expect[i].val, "register %#x", + c->expect[i].off); + } + /* ...and nothing else is written. */ + for (j = 0; j < n; j++) { + bool known = asc_is_matrix(w[j].off); + + for (i = 0; i < c->n && !known; i++) + known = c->expect[i].off == w[j].off; + KUNIT_EXPECT_TRUE_MSG(test, known, "unexpected write %#x", w[j].off); + } +} + +static void asc_test_job_rejects(struct kunit *test) +{ + struct asc_reg *w = kunit_kcalloc(test, ASC_JOB_MAX_WRITES, sizeof(*w), GFP_KERNEL); + struct asc_csc csc; + struct asc_job job = { + .src = { .fmt = asc_find_format(V4L2_PIX_FMT_NV12M), .width = 64, .height = 64 }, + .dst = { .fmt = asc_find_format(V4L2_PIX_FMT_ARGB32), .width = 64, .height = 64 }, + }; + + KUNIT_ASSERT_NOT_NULL(test, w); + /* Y'CbCr to RGB without a matrix */ + KUNIT_EXPECT_EQ(test, asc_job_build(&job, w, ASC_JOB_MAX_WRITES), -EINVAL); + KUNIT_ASSERT_EQ(test, asc_csc_compute(V4L2_YCBCR_ENC_709, + V4L2_QUANTIZATION_LIM_RANGE, true, &csc), 0); + job.csc = &csc; + KUNIT_EXPECT_GT(test, asc_job_build(&job, w, ASC_JOB_MAX_WRITES), 0); + KUNIT_EXPECT_EQ(test, asc_job_build(&job, w, 8), -ENOSPC); + /* scaling is not handled by this path yet */ + job.dst.width = 32; + KUNIT_EXPECT_EQ(test, asc_job_build(&job, w, ASC_JOB_MAX_WRITES), -EINVAL); +} + static struct kunit_case asc_test_cases[] = { KUNIT_CASE_PARAM(asc_test_csc, asc_csc_gen_params), KUNIT_CASE(asc_test_csc_rejects), KUNIT_CASE(asc_test_csc_white), KUNIT_CASE(asc_test_ratio), KUNIT_CASE(asc_test_formats), + KUNIT_CASE_PARAM(asc_test_job, asc_job_gen_params), + KUNIT_CASE(asc_test_job_rejects), {} }; From 1bb49d722fbe79c1a276669fc3a0e3d8c5338e3c Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 02:58:01 +1100 Subject: [PATCH 161/342] media: apple: scaler: add the mem2mem device for same-size conversion Expose the engine as a V4L2 memory-to-memory device. The OUTPUT queue takes NV12, NV12M, P010, ARGB32 or XRGB32, the CAPTURE queue any of them at the same size. Y'CbCr to R'G'B' and back uses the colorimetry of the Y'CbCr side (BT.601, BT.709 or BT.2020, limited or full range); the R'G'B' side is full range and keeps the primaries and transfer function, since the engine only changes the encoding. Each job is written with MMIO in one go from the register list the job builder produces, START last. Completion and errors arrive on the MSR interrupt; an error or a 500 ms timeout fails the job and resets the engine through its power-domain reset before the next one. Interrupts are enabled on the first job after every power-up. Not yet tested on hardware: the DT nodes stay disabled until the qualification run. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/media/platform/apple/scaler/Kconfig | 11 +- .../platform/apple/scaler/apple-scaler-drv.c | 661 +++++++++++++++++- 2 files changed, 635 insertions(+), 37 deletions(-) diff --git a/drivers/media/platform/apple/scaler/Kconfig b/drivers/media/platform/apple/scaler/Kconfig index 799707d9938d1..dcfb18859d689 100644 --- a/drivers/media/platform/apple/scaler/Kconfig +++ b/drivers/media/platform/apple/scaler/Kconfig @@ -5,12 +5,13 @@ config VIDEO_APPLE_SCALER depends on VIDEO_DEV depends on ARCH_APPLE || (COMPILE_TEST && 64BIT) depends on OF_ADDRESS && IOMMU_API && PM + select V4L2_MEM2MEM_DEV + select VIDEOBUF2_DMA_CONTIG help - Driver for the memory-to-memory image scaler and colour-space - converter (MSR) in Apple silicon SoCs. This first version - identifies the engine, attaches its power domains, IOMMU and - interrupt, and keeps it idle; it does not yet expose a video - device. + V4L2 memory-to-memory driver for the image scaler and + colour-space converter (MSR) in Apple silicon SoCs (M1 to M4 + generations and A18 Pro). It converts between Y'CbCr (NV12, + P010) and 32-bit RGB at the same size; scaling follows. To compile this driver as a module, choose M here: the module will be called apple-scaler. diff --git a/drivers/media/platform/apple/scaler/apple-scaler-drv.c b/drivers/media/platform/apple/scaler/apple-scaler-drv.c index 37fd72719bac1..17e901c7e686a 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-drv.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-drv.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Apple silicon scaler and colour-space converter (MSR). + * Apple silicon scaler and colour-space converter (MSR), V4L2 mem2mem. * * Every Apple silicon SoC has one or more MSR engines: memory-to-memory * scalers with a programmable colour-space converter, chroma resampling, @@ -9,26 +9,44 @@ * interrupt; later generations front the engine with firmware and are not * handled here. * - * This version only brings the engine up: it attaches the power domains, - * checks the IOMMU, identifies the hardware, takes the completion - * interrupt and keeps the engine idle. Jobs and the V4L2 mem2mem device - * come in later patches. + * The OUTPUT queue takes the source image, the CAPTURE queue the result. + * This version converts between formats at the same size: Y'CbCr <-> + * R'G'B' with the colorimetry of the Y'CbCr side, chroma resampling and + * alpha fill. Scaling comes once the filter path is qualified. */ #include #include #include #include #include +#include #include #include #include #include #include - +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "apple-scaler-hw.h" #include "apple-scaler-regs.h" #define ASC_NAME "apple-scaler" #define ASC_MIN_REG_SIZE 0x28000 +#define ASC_MIN_SIZE 16 +#define ASC_MAX_SIZE 16384 +#define ASC_STRIDE_ALIGN 128 +#define ASC_JOB_TIMEOUT_MS 500 /** * struct apple_scaler_variant - per-SoC engine description @@ -46,10 +64,35 @@ struct apple_scaler { const struct apple_scaler_variant *variant; struct dev_pm_domain_list *pd_list; struct reset_control *rst; + struct mutex lock; /* serialises ioctls and queue state */ + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct v4l2_m2m_dev *m2m_dev; int irq; u32 id; + + spinlock_t hw_lock; /* protects the fields below */ + struct apple_scaler_ctx *active; + bool need_init; + bool need_reset; + u32 transform_id; + struct delayed_work watchdog; + struct asc_reg writes[ASC_JOB_MAX_WRITES]; }; +struct apple_scaler_ctx { + struct v4l2_fh fh; + struct apple_scaler *asc; + struct v4l2_pix_format_mplane src; /* OUTPUT queue */ + struct v4l2_pix_format_mplane dst; /* CAPTURE queue */ + u32 sequence; +}; + +static struct apple_scaler_ctx *asc_file_to_ctx(struct file *file) +{ + return container_of(file_to_v4l2_fh(file), struct apple_scaler_ctx, fh); +} + static u32 asc_read(struct apple_scaler *asc, u32 reg) { return readl_relaxed(asc->regs + reg); @@ -60,29 +103,549 @@ static void asc_write(struct apple_scaler *asc, u32 reg, u32 val) writel_relaxed(val, asc->regs + reg); } -/* - * No job is ever started yet, so any interrupt is unexpected: acknowledge - * it and report it. The handler only touches the engine while it is - * runtime-active, because a powered-down MSR must not be read. - */ +/* ---- hardware --------------------------------------------------------- */ + +/* After power-up: clear stale status and enable completion and errors. */ +static void asc_hw_init(struct apple_scaler *asc) +{ + asc_write(asc, ASC_IRQ_STATUS, asc_read(asc, ASC_IRQ_STATUS)); + asc_write(asc, ASC_IRQ_ENABLE, ASC_IRQ_DONE | ASC_IRQ_ERRORS); + asc->need_init = false; +} + +static void asc_finish(struct apple_scaler *asc, struct apple_scaler_ctx *ctx, int err) +{ + struct v4l2_m2m_ctx *m2m = ctx->fh.m2m_ctx; + enum vb2_buffer_state state = err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE; + struct vb2_v4l2_buffer *src, *dst; + unsigned int i; + + src = v4l2_m2m_src_buf_remove(m2m); + dst = v4l2_m2m_dst_buf_remove(m2m); + if (src && dst) { + for (i = 0; i < dst->vb2_buf.num_planes; i++) + vb2_set_plane_payload(&dst->vb2_buf, i, + err ? 0 : ctx->dst.plane_fmt[i].sizeimage); + v4l2_m2m_buf_copy_metadata(src, dst); + dst->sequence = ctx->sequence++; + v4l2_m2m_buf_done(src, state); + v4l2_m2m_buf_done(dst, state); + } + pm_runtime_put_autosuspend(asc->dev); + v4l2_m2m_job_finish(asc->m2m_dev, m2m); +} + +/* A failed job leaves the engine in an unknown state: reset before the next. */ +static void asc_recover(struct apple_scaler *asc) +{ + asc->need_reset = true; + asc->need_init = true; +} + static irqreturn_t asc_irq(int irq, void *data) { struct apple_scaler *asc = data; + struct apple_scaler_ctx *ctx; u32 status; + int err = 0; if (pm_runtime_get_if_active(asc->dev) <= 0) return IRQ_NONE; + spin_lock(&asc->hw_lock); status = asc_read(asc, ASC_IRQ_STATUS); - if (status) { - asc_write(asc, ASC_IRQ_STATUS, status); - dev_warn_ratelimited(asc->dev, "unexpected interrupt, status %#x\n", - status); + if (!status) { + spin_unlock(&asc->hw_lock); + pm_runtime_put_noidle(asc->dev); + return IRQ_NONE; } - pm_runtime_put_autosuspend(asc->dev); - return status ? IRQ_HANDLED : IRQ_NONE; + asc_write(asc, ASC_IRQ_STATUS, status); + ctx = asc->active; + if (!ctx || !(status & (ASC_IRQ_DONE | ASC_IRQ_ERRORS))) { + spin_unlock(&asc->hw_lock); + dev_warn_ratelimited(asc->dev, "unexpected interrupt, status %#x\n", status); + pm_runtime_put_noidle(asc->dev); + return IRQ_HANDLED; + } + asc->active = NULL; + if (status & ASC_IRQ_ERRORS) { + dev_err_ratelimited(asc->dev, "job failed: status %#x debug %#x\n", + status, asc_read(asc, ASC_DEBUG_STATUS)); + err = -EIO; + } + spin_unlock(&asc->hw_lock); + pm_runtime_put_noidle(asc->dev); + + cancel_delayed_work(&asc->watchdog); + if (err) + asc_recover(asc); + asc_finish(asc, ctx, err); + return IRQ_HANDLED; +} + +static void asc_watchdog(struct work_struct *work) +{ + struct apple_scaler *asc = container_of(work, struct apple_scaler, watchdog.work); + struct apple_scaler_ctx *ctx; + unsigned long flags; + + spin_lock_irqsave(&asc->hw_lock, flags); + ctx = asc->active; + asc->active = NULL; + if (ctx) + asc_write(asc, ASC_IRQ_ENABLE, 0); + spin_unlock_irqrestore(&asc->hw_lock, flags); + if (ctx) { + dev_err(asc->dev, "job timed out (running %#x)\n", + asc_read(asc, ASC_IS_RUNNING)); + asc_recover(asc); + asc_finish(asc, ctx, -ETIMEDOUT); + } +} + +static void asc_image(struct asc_image *img, const struct v4l2_pix_format_mplane *pix, + struct vb2_buffer *vb) +{ + unsigned int i; + + img->fmt = asc_find_format(pix->pixelformat); + img->width = pix->width; + img->height = pix->height; + for (i = 0; i < img->fmt->planes; i++) { + if (pix->num_planes > 1) { + img->dva[i] = vb2_dma_contig_plane_dma_addr(vb, i); + img->stride[i] = pix->plane_fmt[i].bytesperline; + } else { + /* Chroma follows luma in the same buffer, at the same stride. */ + img->dva[i] = vb2_dma_contig_plane_dma_addr(vb, 0) + + (u64)i * pix->plane_fmt[0].bytesperline * pix->height; + img->stride[i] = pix->plane_fmt[0].bytesperline; + } + } +} + +static void asc_device_run(void *priv) +{ + struct apple_scaler_ctx *ctx = priv; + struct apple_scaler *asc = ctx->asc; + struct vb2_v4l2_buffer *src, *dst; + struct asc_job job = {}; + struct asc_csc csc; + unsigned long flags; + int n, ret; + + src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); + dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); + ret = pm_runtime_resume_and_get(asc->dev); + if (ret < 0) { + pm_runtime_get_noresume(asc->dev); + asc_finish(asc, ctx, ret); + return; + } + + if (asc->need_reset) { + ret = asc->rst ? reset_control_reset(asc->rst) : 0; + if (ret) { + dev_err_ratelimited(asc->dev, "engine reset failed: %d\n", ret); + asc_finish(asc, ctx, ret); + return; + } + asc->need_reset = false; + } + + asc_image(&job.src, &ctx->src, &src->vb2_buf); + asc_image(&job.dst, &ctx->dst, &dst->vb2_buf); + if (job.src.fmt->yuv != job.dst.fmt->yuv) { + const struct v4l2_pix_format_mplane *y = job.src.fmt->yuv ? &ctx->src : &ctx->dst; + + ret = asc_csc_compute(y->ycbcr_enc, y->quantization, job.src.fmt->yuv, &csc); + if (ret) { + asc_finish(asc, ctx, ret); + return; + } + job.csc = &csc; + } + + spin_lock_irqsave(&asc->hw_lock, flags); + /* Job tags as the engine is driven on macOS: a counter above bit 3, bit 2 set. */ + job.transform_id = (++asc->transform_id << 3) | BIT(2); + n = asc_job_build(&job, asc->writes, ARRAY_SIZE(asc->writes)); + if (n < 0) { + spin_unlock_irqrestore(&asc->hw_lock, flags); + asc_finish(asc, ctx, n); + return; + } + if (asc->need_init) + asc_hw_init(asc); + asc->active = ctx; + /* Buffers must be visible to the engine before START, the last write. */ + dma_wmb(); + for (int i = 0; i < n; i++) + writel(asc->writes[i].val, asc->regs + asc->writes[i].off); + spin_unlock_irqrestore(&asc->hw_lock, flags); + schedule_delayed_work(&asc->watchdog, msecs_to_jiffies(ASC_JOB_TIMEOUT_MS)); +} + +static const struct v4l2_m2m_ops asc_m2m_ops = { + .device_run = asc_device_run, +}; + +/* ---- formats ---------------------------------------------------------- */ + +/* + * Fill in a format the engine can take. The CAPTURE side has the OUTPUT + * size (no scaling yet). The Y'CbCr side of a conversion carries the + * colorimetry; the R'G'B' side is full range with the same primaries and + * transfer function, since the engine converts only the encoding. + */ +static void asc_fill(struct v4l2_pix_format_mplane *pix, const struct v4l2_pix_format_mplane *ref, + u32 default_fourcc) +{ + const struct asc_format *f = asc_find_format(pix->pixelformat); + u32 w = ref ? ref->width : pix->width, h = ref ? ref->height : pix->height; + struct v4l2_pix_format_mplane in = *pix; + + if (!f) + f = asc_find_format(default_fourcc); + w = clamp_t(u32, ALIGN(w, f->hsub), ASC_MIN_SIZE, ASC_MAX_SIZE); + h = clamp_t(u32, ALIGN(h, f->vsub), ASC_MIN_SIZE, ASC_MAX_SIZE); + + memset(pix, 0, sizeof(*pix)); + v4l2_fill_pixfmt_mp_aligned(pix, f->fourcc, w, h, ASC_STRIDE_ALIGN); + pix->field = V4L2_FIELD_NONE; + + if (ref && ref->colorspace != V4L2_COLORSPACE_DEFAULT) { + pix->colorspace = ref->colorspace; + pix->xfer_func = ref->xfer_func; + } else { + pix->colorspace = in.colorspace ?: V4L2_COLORSPACE_REC709; + pix->xfer_func = in.xfer_func; + } + if (f->yuv) { + pix->ycbcr_enc = in.ycbcr_enc; + if (ref && v4l2_is_format_yuv(v4l2_format_info(ref->pixelformat))) + pix->ycbcr_enc = ref->ycbcr_enc; + if (pix->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) + pix->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix->colorspace); + /* Only the encodings the matrix can express. */ + if (pix->ycbcr_enc != V4L2_YCBCR_ENC_601 && pix->ycbcr_enc != V4L2_YCBCR_ENC_709 && + pix->ycbcr_enc != V4L2_YCBCR_ENC_BT2020) + pix->ycbcr_enc = V4L2_YCBCR_ENC_709; + pix->quantization = in.quantization; + if (ref && v4l2_is_format_yuv(v4l2_format_info(ref->pixelformat))) + pix->quantization = ref->quantization; + if (pix->quantization == V4L2_QUANTIZATION_DEFAULT) + pix->quantization = V4L2_QUANTIZATION_LIM_RANGE; + } else { + pix->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; + pix->quantization = V4L2_QUANTIZATION_FULL_RANGE; + } + if (pix->xfer_func == V4L2_XFER_FUNC_DEFAULT) + pix->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix->colorspace); +} + +static int asc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) +{ + strscpy(cap->driver, ASC_NAME, sizeof(cap->driver)); + strscpy(cap->card, "Apple scaler/CSC", sizeof(cap->card)); + return 0; +} + +static int asc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtdesc *f) +{ + const struct asc_format *fmt = asc_format_by_index(f->index); + + if (!fmt) + return -EINVAL; + f->pixelformat = fmt->fourcc; + return 0; +} + +static int asc_enum_framesizes(struct file *file, void *priv, struct v4l2_frmsizeenum *fs) +{ + const struct asc_format *f = asc_find_format(fs->pixel_format); + + if (fs->index || !f) + return -EINVAL; + fs->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fs->stepwise = (struct v4l2_frmsize_stepwise){ + ASC_MIN_SIZE, ASC_MAX_SIZE, f->hsub, ASC_MIN_SIZE, ASC_MAX_SIZE, f->vsub, + }; + return 0; +} + +static int asc_g_fmt_out(struct file *file, void *priv, struct v4l2_format *f) +{ + f->fmt.pix_mp = asc_file_to_ctx(file)->src; + return 0; +} + +static int asc_g_fmt_cap(struct file *file, void *priv, struct v4l2_format *f) +{ + f->fmt.pix_mp = asc_file_to_ctx(file)->dst; + return 0; +} + +static int asc_try_fmt_out(struct file *file, void *priv, struct v4l2_format *f) +{ + asc_fill(&f->fmt.pix_mp, NULL, V4L2_PIX_FMT_NV12M); + return 0; +} + +static int asc_try_fmt_cap(struct file *file, void *priv, struct v4l2_format *f) +{ + asc_fill(&f->fmt.pix_mp, &asc_file_to_ctx(file)->src, V4L2_PIX_FMT_ARGB32); + return 0; +} + +static int asc_s_fmt_out(struct file *file, void *priv, struct v4l2_format *f) +{ + struct apple_scaler_ctx *ctx = asc_file_to_ctx(file); + + if (vb2_is_busy(v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx)) || + vb2_is_busy(v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx))) + return -EBUSY; + asc_fill(&f->fmt.pix_mp, NULL, V4L2_PIX_FMT_NV12M); + ctx->src = f->fmt.pix_mp; + asc_fill(&ctx->dst, &ctx->src, V4L2_PIX_FMT_ARGB32); + return 0; +} + +static int asc_s_fmt_cap(struct file *file, void *priv, struct v4l2_format *f) +{ + struct apple_scaler_ctx *ctx = asc_file_to_ctx(file); + + if (vb2_is_busy(v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx))) + return -EBUSY; + asc_fill(&f->fmt.pix_mp, &ctx->src, V4L2_PIX_FMT_ARGB32); + ctx->dst = f->fmt.pix_mp; + return 0; +} + +static const struct v4l2_ioctl_ops asc_ioctl_ops = { + .vidioc_querycap = asc_querycap, + .vidioc_enum_fmt_vid_out = asc_enum_fmt, + .vidioc_enum_fmt_vid_cap = asc_enum_fmt, + .vidioc_enum_framesizes = asc_enum_framesizes, + .vidioc_g_fmt_vid_out_mplane = asc_g_fmt_out, + .vidioc_g_fmt_vid_cap_mplane = asc_g_fmt_cap, + .vidioc_try_fmt_vid_out_mplane = asc_try_fmt_out, + .vidioc_try_fmt_vid_cap_mplane = asc_try_fmt_cap, + .vidioc_s_fmt_vid_out_mplane = asc_s_fmt_out, + .vidioc_s_fmt_vid_cap_mplane = asc_s_fmt_cap, + + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, + .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, + + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +/* ---- queues ----------------------------------------------------------- */ + +static struct v4l2_pix_format_mplane *asc_q_fmt(struct apple_scaler_ctx *ctx, u32 type) +{ + return V4L2_TYPE_IS_OUTPUT(type) ? &ctx->src : &ctx->dst; } +static int asc_queue_setup(struct vb2_queue *q, unsigned int *nbufs, unsigned int *nplanes, + unsigned int sizes[], struct device *alloc_devs[]) +{ + struct v4l2_pix_format_mplane *pix = asc_q_fmt(vb2_get_drv_priv(q), q->type); + unsigned int i; + + if (*nplanes) { + if (*nplanes != pix->num_planes) + return -EINVAL; + for (i = 0; i < *nplanes; i++) + if (sizes[i] < pix->plane_fmt[i].sizeimage) + return -EINVAL; + return 0; + } + *nplanes = pix->num_planes; + for (i = 0; i < *nplanes; i++) + sizes[i] = pix->plane_fmt[i].sizeimage; + return 0; +} + +static int asc_buf_prepare(struct vb2_buffer *vb) +{ + struct v4l2_pix_format_mplane *pix = asc_q_fmt(vb2_get_drv_priv(vb->vb2_queue), vb->type); + unsigned int i; + + for (i = 0; i < pix->num_planes; i++) { + if (vb2_plane_size(vb, i) < pix->plane_fmt[i].sizeimage) + return -EINVAL; + if (vb2_dma_contig_plane_dma_addr(vb, i) & (ASC_STRIDE_ALIGN - 1)) + return -EINVAL; + if (V4L2_TYPE_IS_OUTPUT(vb->type)) + vb2_set_plane_payload(vb, i, pix->plane_fmt[i].sizeimage); + else + vb2_set_plane_payload(vb, i, 0); + } + return 0; +} + +static void asc_buf_queue(struct vb2_buffer *vb) +{ + struct apple_scaler_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); + + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, to_vb2_v4l2_buffer(vb)); +} + +static int asc_start_streaming(struct vb2_queue *q, unsigned int count) +{ + struct apple_scaler_ctx *ctx = vb2_get_drv_priv(q); + + if (V4L2_TYPE_IS_OUTPUT(q->type)) + ctx->sequence = 0; + return 0; +} + +static void asc_stop_streaming(struct vb2_queue *q) +{ + struct apple_scaler_ctx *ctx = vb2_get_drv_priv(q); + struct vb2_v4l2_buffer *vbuf; + + for (;;) { + vbuf = V4L2_TYPE_IS_OUTPUT(q->type) ? v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx) : + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); + if (!vbuf) + break; + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); + } +} + +static const struct vb2_ops asc_qops = { + .queue_setup = asc_queue_setup, + .buf_prepare = asc_buf_prepare, + .buf_queue = asc_buf_queue, + .start_streaming = asc_start_streaming, + .stop_streaming = asc_stop_streaming, +}; + +static int asc_init_queue(struct apple_scaler_ctx *ctx, struct vb2_queue *q, u32 type) +{ + q->type = type; + q->io_modes = VB2_MMAP | VB2_DMABUF; + q->drv_priv = ctx; + q->buf_struct_size = sizeof(struct v4l2_m2m_buffer); + q->ops = &asc_qops; + q->mem_ops = &vb2_dma_contig_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; + q->lock = &ctx->asc->lock; + q->dev = ctx->asc->dev; + return vb2_queue_init(q); +} + +static int asc_queue_init(void *priv, struct vb2_queue *src, struct vb2_queue *dst) +{ + int ret = asc_init_queue(priv, src, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); + + return ret ?: asc_init_queue(priv, dst, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); +} + +/* ---- file operations -------------------------------------------------- */ + +static int asc_open(struct file *file) +{ + struct apple_scaler *asc = video_drvdata(file); + struct apple_scaler_ctx *ctx; + int ret; + + ctx = kzalloc_obj(*ctx); + if (!ctx) + return -ENOMEM; + ctx->asc = asc; + ctx->src.width = 1920; + ctx->src.height = 1080; + ctx->src.pixelformat = V4L2_PIX_FMT_NV12M; + asc_fill(&ctx->src, NULL, V4L2_PIX_FMT_NV12M); + ctx->dst.pixelformat = V4L2_PIX_FMT_ARGB32; + asc_fill(&ctx->dst, &ctx->src, V4L2_PIX_FMT_ARGB32); + v4l2_fh_init(&ctx->fh, video_devdata(file)); + + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(asc->m2m_dev, ctx, asc_queue_init); + if (IS_ERR(ctx->fh.m2m_ctx)) { + ret = PTR_ERR(ctx->fh.m2m_ctx); + v4l2_fh_exit(&ctx->fh); + kfree(ctx); + return ret; + } + v4l2_fh_add(&ctx->fh, file); + return 0; +} + +static int asc_release(struct file *file) +{ + struct apple_scaler_ctx *ctx = asc_file_to_ctx(file); + struct apple_scaler *asc = ctx->asc; + + mutex_lock(&asc->lock); + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); + mutex_unlock(&asc->lock); + v4l2_fh_del(&ctx->fh, file); + v4l2_fh_exit(&ctx->fh); + kfree(ctx); + return 0; +} + +static const struct v4l2_file_operations asc_fops = { + .owner = THIS_MODULE, + .open = asc_open, + .release = asc_release, + .poll = v4l2_m2m_fop_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = v4l2_m2m_fop_mmap, +}; + +/* ---- power management and probe --------------------------------------- */ + +static int asc_runtime_suspend(struct device *dev) +{ + return 0; +} + +static int asc_runtime_resume(struct device *dev) +{ + struct apple_scaler *asc = dev_get_drvdata(dev); + + /* The engine loses its state when powered down. */ + asc->need_init = true; + return 0; +} + +static int asc_suspend(struct device *dev) +{ + struct apple_scaler *asc = dev_get_drvdata(dev); + + v4l2_m2m_suspend(asc->m2m_dev); + return pm_runtime_force_suspend(dev); +} + +static int asc_resume(struct device *dev) +{ + struct apple_scaler *asc = dev_get_drvdata(dev); + int ret = pm_runtime_force_resume(dev); + + if (ret) + return ret; + v4l2_m2m_resume(asc->m2m_dev); + return 0; +} + +static const struct dev_pm_ops asc_pm_ops = { + RUNTIME_PM_OPS(asc_runtime_suspend, asc_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(asc_suspend, asc_resume) +}; + static int asc_identify(struct apple_scaler *asc) { u32 running, status; @@ -95,7 +658,7 @@ static int asc_identify(struct apple_scaler *asc) asc->id = asc_read(asc, ASC_HW_VERSION); running = asc_read(asc, ASC_IS_RUNNING); status = asc_read(asc, ASC_IRQ_STATUS); - /* Nothing may be enabled until a job path owns the engine. */ + /* Masked until the first job enables it. */ asc_write(asc, ASC_IRQ_ENABLE, 0); if (status) asc_write(asc, ASC_IRQ_STATUS, status); @@ -109,26 +672,21 @@ static int asc_identify(struct apple_scaler *asc) return 0; } -static int asc_runtime_suspend(struct device *dev) +static void asc_cleanup(void *data) { - return 0; -} + struct apple_scaler *asc = data; -static int asc_runtime_resume(struct device *dev) -{ - /* The engine loses its state when powered down; jobs program it fully. */ - return 0; + cancel_delayed_work_sync(&asc->watchdog); + if (asc->m2m_dev) + v4l2_m2m_release(asc->m2m_dev); + v4l2_device_unregister(&asc->v4l2_dev); } -static const struct dev_pm_ops asc_pm_ops = { - RUNTIME_PM_OPS(asc_runtime_suspend, asc_runtime_resume, NULL) - SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) -}; - static int asc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct apple_scaler *asc; + struct video_device *vdev; struct resource *res; int ret; @@ -139,6 +697,10 @@ static int asc_probe(struct platform_device *pdev) asc->variant = of_device_get_match_data(dev); if (!asc->variant) return -ENODEV; + mutex_init(&asc->lock); + spin_lock_init(&asc->hw_lock); + INIT_DELAYED_WORK(&asc->watchdog, asc_watchdog); + asc->need_init = true; platform_set_drvdata(pdev, asc); if (!device_iommu_mapped(dev)) @@ -161,7 +723,7 @@ static int asc_probe(struct platform_device *pdev) return dev_err_probe(dev, -ENODEV, "requires a power domain\n"); } - if (platform_get_resource(pdev, IORESOURCE_MEM, asc->variant->num_reg - 1) == NULL) + if (!platform_get_resource(pdev, IORESOURCE_MEM, asc->variant->num_reg - 1)) return dev_err_probe(dev, -EINVAL, "expected %u register ranges\n", asc->variant->num_reg); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -193,7 +755,41 @@ static int asc_probe(struct platform_device *pdev) asc->irq = platform_get_irq(pdev, 0); if (asc->irq < 0) return asc->irq; - return devm_request_irq(dev, asc->irq, asc_irq, 0, dev_name(dev), asc); + ret = devm_request_irq(dev, asc->irq, asc_irq, 0, dev_name(dev), asc); + if (ret) + return ret; + + ret = v4l2_device_register(dev, &asc->v4l2_dev); + if (ret) + return ret; + ret = devm_add_action_or_reset(dev, asc_cleanup, asc); + if (ret) + return ret; + asc->m2m_dev = v4l2_m2m_init(&asc_m2m_ops); + if (IS_ERR(asc->m2m_dev)) { + ret = PTR_ERR(asc->m2m_dev); + asc->m2m_dev = NULL; + return ret; + } + + vdev = &asc->vdev; + strscpy(vdev->name, ASC_NAME, sizeof(vdev->name)); + vdev->fops = &asc_fops; + vdev->ioctl_ops = &asc_ioctl_ops; + vdev->release = video_device_release_empty; + vdev->lock = &asc->lock; + vdev->v4l2_dev = &asc->v4l2_dev; + vdev->vfl_dir = VFL_DIR_M2M; + vdev->device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; + video_set_drvdata(vdev, asc); + return video_register_device(vdev, VFL_TYPE_VIDEO, -1); +} + +static void asc_remove(struct platform_device *pdev) +{ + struct apple_scaler *asc = platform_get_drvdata(pdev); + + video_unregister_device(&asc->vdev); } static const struct apple_scaler_variant apple_scaler_t6041 = { @@ -215,6 +811,7 @@ MODULE_DEVICE_TABLE(of, asc_of_match); static struct platform_driver asc_driver = { .probe = asc_probe, + .remove = asc_remove, .driver = { .name = ASC_NAME, .of_match_table = asc_of_match, From 8e57d48456ec0e11ab5f10d56149c3e1c9d62918 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 03:23:14 +1100 Subject: [PATCH 162/342] media: apple: scaler: pulse the engine reset before the first job After every power-up and after a failed job, wait for the engine to go idle, write RESET 1 then 0 without reading anything in between (the register file does not answer while reset is held), wait for idle again, then clear stale status and enable the done and error interrupts. Only if the engine never goes idle fall back to the PMGR reset of its power domain and retry once; otherwise fail the job. This is the start-up order the engine expects on every generation from M1 Max onwards. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- .../platform/apple/scaler/apple-scaler-drv.c | 44 ++++++++++++++----- .../platform/apple/scaler/apple-scaler-regs.h | 1 + 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/apple/scaler/apple-scaler-drv.c b/drivers/media/platform/apple/scaler/apple-scaler-drv.c index 17e901c7e686a..6a8d5f8438ce8 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-drv.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-drv.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ #define ASC_MAX_SIZE 16384 #define ASC_STRIDE_ALIGN 128 #define ASC_JOB_TIMEOUT_MS 500 +#define ASC_IDLE_TIMEOUT_US 10000 /** * struct apple_scaler_variant - per-SoC engine description @@ -74,7 +76,6 @@ struct apple_scaler { spinlock_t hw_lock; /* protects the fields below */ struct apple_scaler_ctx *active; bool need_init; - bool need_reset; u32 transform_id; struct delayed_work watchdog; struct asc_reg writes[ASC_JOB_MAX_WRITES]; @@ -105,12 +106,30 @@ static void asc_write(struct apple_scaler *asc, u32 reg, u32 val) /* ---- hardware --------------------------------------------------------- */ -/* After power-up: clear stale status and enable completion and errors. */ -static void asc_hw_init(struct apple_scaler *asc) +/* + * After power-up or a failed job: wait for idle, pulse the engine reset + * (no register may be read while it is held), clear stale status and + * enable completion and errors. + */ +static int asc_hw_init(struct apple_scaler *asc) { + u32 v; + int ret; + + ret = readl_relaxed_poll_timeout(asc->regs + ASC_IS_RUNNING, v, !(v & BIT(0)), + 10, ASC_IDLE_TIMEOUT_US); + if (ret) + return ret; + asc_write(asc, ASC_RESET, ASC_RESET_ENGINE); + asc_write(asc, ASC_RESET, 0); + ret = readl_relaxed_poll_timeout(asc->regs + ASC_IS_RUNNING, v, !(v & BIT(0)), + 10, ASC_IDLE_TIMEOUT_US); + if (ret) + return ret; asc_write(asc, ASC_IRQ_STATUS, asc_read(asc, ASC_IRQ_STATUS)); asc_write(asc, ASC_IRQ_ENABLE, ASC_IRQ_DONE | ASC_IRQ_ERRORS); asc->need_init = false; + return 0; } static void asc_finish(struct apple_scaler *asc, struct apple_scaler_ctx *ctx, int err) @@ -138,7 +157,6 @@ static void asc_finish(struct apple_scaler *asc, struct apple_scaler_ctx *ctx, i /* A failed job leaves the engine in an unknown state: reset before the next. */ static void asc_recover(struct apple_scaler *asc) { - asc->need_reset = true; asc->need_init = true; } @@ -243,14 +261,20 @@ static void asc_device_run(void *priv) return; } - if (asc->need_reset) { - ret = asc->rst ? reset_control_reset(asc->rst) : 0; + /* + * Engine reset and interrupt setup, once per power-up and after any + * failure. If the engine does not go idle, fall back to the PMGR reset + * of its power domain and try once more. + */ + if (asc->need_init) { + ret = asc_hw_init(asc); + if (ret && asc->rst && !reset_control_reset(asc->rst)) + ret = asc_hw_init(asc); if (ret) { - dev_err_ratelimited(asc->dev, "engine reset failed: %d\n", ret); - asc_finish(asc, ctx, ret); + dev_err_ratelimited(asc->dev, "engine does not go idle: %d\n", ret); + asc_finish(asc, ctx, -EIO); return; } - asc->need_reset = false; } asc_image(&job.src, &ctx->src, &src->vb2_buf); @@ -275,8 +299,6 @@ static void asc_device_run(void *priv) asc_finish(asc, ctx, n); return; } - if (asc->need_init) - asc_hw_init(asc); asc->active = ctx; /* Buffers must be visible to the engine before START, the last write. */ dma_wmb(); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-regs.h b/drivers/media/platform/apple/scaler/apple-scaler-regs.h index 7402b9a97752c..6abbcb7759394 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-regs.h +++ b/drivers/media/platform/apple/scaler/apple-scaler-regs.h @@ -13,6 +13,7 @@ #define ASC_HW_VERSION 0x0000 #define ASC_RESET 0x0004 +#define ASC_RESET_ENGINE BIT(0) #define ASC_RESET_APIODMA 0x0008 #define ASC_IS_RUNNING 0x000c #define ASC_REG_FIFO_AVAIL 0x0014 From 1e46c8f78251bc267552a2f5004e6dacf1001cee Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:14:09 +1100 Subject: [PATCH 163/342] arm64: dts: apple: t6040: debounce the GPU zones critical trips The seven GPU zones (Tg05, Tg0S, Tg0Y, Tg0k, Tg0z, Tg1V, Tg1l) shut the Mac down on the first 1 s SMC sample at or above 118 C. The CPU and die zones in the same file already need three samples (critical-samples), because single SMC samples on these Macs jump by several degrees during load transients. Give the GPU zones the same rule. On a J616s the GPU keys read real values only while the GPU is powered (glmark2: Tg05 49 to 53 C, about 8 C above Tp0G) and fall to -4 to 4 C on the first sample after the firmware powers the GPU off. The transition samples measured at 1 Hz stay in range (no spikes), so the debounce only guards against noise; it does not hide a real excursion, which still shuts down after three seconds. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi b/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi index 74af4a032b1d8..1dab69b0f9a0e 100644 --- a/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi @@ -172,8 +172,9 @@ * throttle only the cluster their sensor sits on. The 1 s samples * jump by about 10 C, so the zones are integral-led. * - GPU zones: the GPU firmware limits itself from 101 C; these shed - * CPU power from the same point (on at 90 C) and shut down at 118 C. - * A powered-off GPU reads -4 to 4 C. + * CPU power from the same point (on at 90 C) and shut down at 118 C + * after three samples, as the CPU zones do. A powered-off GPU reads + * -4 to 4 C. * - Hot at 120 C only reports; critical is the ADT's 125 C sochot * level, after three samples (critical-samples). * - The fans stay with the SMC, as on macOS: no active trips. @@ -1000,6 +1001,7 @@ gpu0-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 17>; /* Tg05 */ @@ -1058,6 +1060,7 @@ gpu1-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 18>; /* Tg0S */ @@ -1116,6 +1119,7 @@ gpu2-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 19>; /* Tg0Y */ @@ -1174,6 +1178,7 @@ gpu3-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 20>; /* Tg0k */ @@ -1232,6 +1237,7 @@ gpu4-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 21>; /* Tg0z */ @@ -1290,6 +1296,7 @@ gpu5-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 22>; /* Tg1V */ @@ -1348,6 +1355,7 @@ gpu6-thermal { polling-delay-passive = <1000>; polling-delay = <1000>; + critical-samples = <3>; sustainable-power = <51300>; thermal-sensors = <&smc_hwmon 23>; /* Tg1l */ From 97bc174a0e86cf91f7fd718482524ca48a950031 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:39:24 +1100 Subject: [PATCH 164/342] hwmon: macsmc: report the M4 Pro GPU sensors' powered-down placeholders as no data On the M4 Pro (T6040) the SMC publishes every GPU temperature key (Tg*) only while the GPU is powered. When the GPU firmware powers the GPU off at idle, the next 1 Hz SMC update replaces each key with a placeholder: -4.0 C on the base keys, 0, 2.2 or 3.9 C on the others. Linux reported those as temperatures: `sensors` showed a 3.9 C GPU, and the seven GPU thermal zones fed it to the power allocator as a reading. Describe the placeholder range in the device tree: apple,no-data-below-millicelsius on a sensor node makes macsmc-hwmon return -ENODATA for a reading below it, so userspace sees no reading instead of a false one. The hwmon thermal bridge turns -ENODATA into THERMAL_TEMP_INVALID, which the thermal core already treats as "no valid temperature this time": the zone keeps polling and its last real temperature, and the update is skipped. Without that, the core would back off on the error and eventually disable the zone as broken, so it could not trip when the GPU powered up again. The 22 Tg* sensors of the T604x MacBook Pros get a 10 C threshold. The real readings measured on a J616s are 36-75 C, and a powered GPU does not run below 10 C. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../bindings/hwmon/apple,smc-hwmon.yaml | 9 +++++++++ .../boot/dts/apple/t6040-gpu-thermal.dtsi | 7 +++++++ arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi | 15 +++++++++++++++ drivers/hwmon/hwmon.c | 9 +++++++++ drivers/hwmon/macsmc-hwmon.c | 18 +++++++++++++++--- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml index fcfe475d4dcf2..e98bdcc7b7897 100644 --- a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml +++ b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml @@ -33,6 +33,15 @@ $defs: label: description: Human-readable name for the sensor + apple,no-data-below-millicelsius: + $ref: /schemas/types.yaml#/definitions/int32 + description: + The SMC publishes a placeholder below this temperature, in + millidegrees Celsius, while the sensor is powered down (the GPU + temperature sensors of the M4 Pro read -4 to 4 C while the GPU is + off). Such readings are reported as no data instead of as a + temperature, and a thermal zone on the sensor skips them. + required: - apple,key-id diff --git a/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi b/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi index 1dab69b0f9a0e..6d719c7532867 100644 --- a/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-gpu-thermal.dtsi @@ -1507,35 +1507,42 @@ temperature-Tg05 { apple,key-id = "Tg05"; label = "GPU Tg05"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0S { apple,key-id = "Tg0S"; label = "GPU Tg0S"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0Y { apple,key-id = "Tg0Y"; label = "GPU Tg0Y"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0k { apple,key-id = "Tg0k"; label = "GPU Tg0k"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0z { apple,key-id = "Tg0z"; label = "GPU Tg0z"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1V { apple,key-id = "Tg1V"; label = "GPU Tg1V"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1l { apple,key-id = "Tg1l"; label = "GPU Tg1l"; + apple,no-data-below-millicelsius = <10000>; }; }; diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi index 864e87400bb87..c431dec0f3c4f 100644 --- a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi @@ -1011,76 +1011,91 @@ temperature-Tg04 { apple,key-id = "Tg04"; label = "GPU Tg04"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0K { apple,key-id = "Tg0K"; label = "GPU Tg0K"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0L { apple,key-id = "Tg0L"; label = "GPU Tg0L"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0R { apple,key-id = "Tg0R"; label = "GPU Tg0R"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0X { apple,key-id = "Tg0X"; label = "GPU Tg0X"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0d { apple,key-id = "Tg0d"; label = "GPU Tg0d"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0e { apple,key-id = "Tg0e"; label = "GPU Tg0e"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0j { apple,key-id = "Tg0j"; label = "GPU Tg0j"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg0y { apple,key-id = "Tg0y"; label = "GPU Tg0y"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1E { apple,key-id = "Tg1E"; label = "GPU Tg1E"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1F { apple,key-id = "Tg1F"; label = "GPU Tg1F"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1U { apple,key-id = "Tg1U"; label = "GPU Tg1U"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1c { apple,key-id = "Tg1c"; label = "GPU Tg1c"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1d { apple,key-id = "Tg1d"; label = "GPU Tg1d"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tg1k { apple,key-id = "Tg1k"; label = "GPU Tg1k"; + apple,no-data-below-millicelsius = <10000>; }; temperature-Tp00 { diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 10d2df3efdfae..96381f929842b 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -171,6 +171,15 @@ static int hwmon_thermal_get_temp(struct thermal_zone_device *tz, int *temp) ret = hwdev->chip->ops->read(tdata->dev, hwmon_temp, hwmon_temp_input, tdata->index, &t); + /* + * -ENODATA: the sensor has no reading right now (for example it is + * powered down). Let the zone skip this update and keep polling, + * instead of backing off and eventually disabling it as broken. + */ + if (ret == -ENODATA) { + *temp = THERMAL_TEMP_INVALID; + return 0; + } if (ret < 0) return ret; diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c index 0e146c0fa68fc..d0206489fa372 100644 --- a/drivers/hwmon/macsmc-hwmon.c +++ b/drivers/hwmon/macsmc-hwmon.c @@ -74,6 +74,9 @@ struct macsmc_hwmon_sensor { u32 attrs; /* Part of the SoC die temperature zone. */ bool die; + /* Readings below no_data_below are powered-down placeholders, not temperatures. */ + bool has_no_data_below; + s32 no_data_below; }; struct macsmc_hwmon_fan { @@ -616,10 +619,15 @@ static int macsmc_hwmon_read(struct device *dev, enum hwmon_sensor_types type, int ret = 0; switch (type) { - case hwmon_temp: - ret = macsmc_hwmon_read_key(hwmon->smc, - &hwmon->temp.sensors[channel], 1000, val); + case hwmon_temp: { + struct macsmc_hwmon_sensor *sensor = &hwmon->temp.sensors[channel]; + + ret = macsmc_hwmon_read_key(hwmon->smc, sensor, 1000, val); + /* A powered-down sensor's placeholder is not a temperature. */ + if (!ret && sensor->has_no_data_below && *val < sensor->no_data_below) + ret = -ENODATA; break; + } case hwmon_in: ret = macsmc_hwmon_read_key(hwmon->smc, &hwmon->volt.sensors[channel], 1000, val); @@ -778,6 +786,10 @@ static int macsmc_hwmon_create_sensor(struct device *dev, struct apple_smc *smc, else strscpy_pad(sensor->label, label, sizeof(sensor->label)); + sensor->has_no_data_below = + !of_property_read_s32(sensor_node, "apple,no-data-below-millicelsius", + &sensor->no_data_below); + return 0; } From b724b53d26b90e520d23b3a865c732df1dbd10d5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 21:14:17 +1100 Subject: [PATCH 165/342] PCI: apple: attach and retain all host power domains in s2idle Devices with multiple power-domains entries are not attached by the platform bus. Attach each domain with an active device link before touching the controller, while leaving the single-domain attachment to the bus. Preallocate one notifier per attached domain and extend the PCIe-C sleep hold to cover all of them. Internal hosts leave their links running in suspend-to-idle and cannot recover from a power cycle, so veto power-off on every domain until resume. Unwind partial holds on error and abort suspend rather than lose an internal link. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/pci/controller/pcie-apple.c | 136 +++++++++++++++++++++------- 1 file changed, 101 insertions(+), 35 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 6ad3376dcf75e..409b95e68e1a9 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -214,7 +214,7 @@ struct hw_info { bool msimap_by_vector; /* * In suspend-to-idle a tunnel host whose power domain is not always-on - * keeps its link while the domain stays on, see apple_pcie_hold_domain(). + * keeps its link while the domain stays on, see apple_pcie_hold_domains(). */ bool s2idle_hold_domain; /* AppleT8152PCIePort::_initializeRefclkBuffer clears REFBUF_OFF. */ @@ -391,6 +391,12 @@ bool apple_pcie_tunnel_needs_cold_init(struct device_node *np) } EXPORT_SYMBOL_GPL(apple_pcie_tunnel_needs_cold_init); +struct apple_pcie_pd { + struct device *dev; + struct notifier_block nb; + unsigned int vetoed; +}; + struct apple_pcie { struct mutex lock; struct device *dev; @@ -413,10 +419,10 @@ struct apple_pcie { bool bus_stopped; bool reset_on_resume; bool link_kept; - /* a power domain that is not always-on, held on for this sleep */ - struct notifier_block pd_nb; - bool pd_held; - unsigned int pd_vetoed; + struct dev_pm_domain_list *pd_list; + struct apple_pcie_pd *pds; + unsigned int num_pds; + unsigned int pd_held; bool resume_failed; /* cleared only by teardown and reprobe */ struct reset_control *reset; u16 managed_sids; @@ -3101,6 +3107,42 @@ static int apple_pcie_neo_enumerate(struct pci_host_bridge *bridge) return ret; } +static int apple_pcie_attach_domains(struct apple_pcie *pcie) +{ + struct device *dev = pcie->dev; + struct dev_pm_domain_attach_data data = { + .pd_flags = PD_FLAG_DEV_LINK_ON, + }; + int count, ret, i; + + if (!of_property_present(dev->of_node, "power-domains")) + return 0; + + count = of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells"); + if (count < 0) + return count; + if (count > 1) { + ret = devm_pm_domain_attach_list(dev, &data, &pcie->pd_list); + if (ret < 0) + return ret; + if (ret != count) + return -ENODEV; + } else if (!dev->pm_domain) { + return 0; + } + + /* A single domain is already attached by the platform bus. */ + pcie->pds = devm_kcalloc(dev, count, sizeof(*pcie->pds), GFP_KERNEL); + if (!pcie->pds) + return -ENOMEM; + pcie->num_pds = count; + for (i = 0; i < count; i++) + pcie->pds[i].dev = pcie->pd_list ? pcie->pd_list->pd_devs[i] : dev; + + return 0; +} + static int apple_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -3148,6 +3190,10 @@ static int apple_pcie_probe(struct platform_device *pdev) pcie = pci_host_bridge_priv(bridge); pcie->dev = dev; pcie->hw = hw; + ret = apple_pcie_attach_domains(pcie); + if (ret) + return dev_err_probe(dev, ret, "Failed to attach power domains\n"); + if (of_property_present(dev->of_node, "apple,managed-sids")) { u32 ids[15]; int count = of_property_count_u32_elems(dev->of_node, "apple,managed-sids"); @@ -3828,46 +3874,63 @@ static bool apple_pcie_tunnel_link_healthy(struct apple_pcie *pcie) */ static int apple_pcie_pd_notify(struct notifier_block *nb, unsigned long action, void *data) { - struct apple_pcie *pcie = container_of(nb, struct apple_pcie, pd_nb); + struct apple_pcie_pd *pd = container_of(nb, struct apple_pcie_pd, nb); if (action != GENPD_NOTIFY_PRE_OFF) return NOTIFY_OK; - pcie->pd_vetoed++; + pd->vetoed++; return notifier_from_errno(-EBUSY); } +static void apple_pcie_release_domains(struct apple_pcie *pcie) +{ + unsigned int vetoed = 0; + struct apple_pcie_pd *pd; + + if (!pcie->pd_held) + return; + while (pcie->pd_held) { + pd = &pcie->pds[--pcie->pd_held]; + dev_pm_genpd_remove_notifier(pd->dev); + vetoed += pd->vetoed; + } + dev_dbg(pcie->dev, "PCIe power domains released after suspend-to-idle (%u power-offs refused)\n", + vetoed); +} + /* - * Hold a power domain that is not always-on through this sleep. ACIO keeps + * Hold every attached domain through this sleep. Internal links are left + * running and cannot be retrained after a power cycle. ACIO keeps * the domain of its PCIe-C host on for as long as a cable is connected (its * power-domain devices are syscore devices, which system sleep leaves * alone), so a host with a link up finds its domain on here, and the veto * makes sure it stays on. A domain that is already off has no link to keep. */ -static int apple_pcie_hold_domain(struct apple_pcie *pcie) +static int apple_pcie_hold_domains(struct apple_pcie *pcie) { + struct apple_pcie_pd *pd; int ret; - pcie->pd_vetoed = 0; - pcie->pd_nb.notifier_call = apple_pcie_pd_notify; - ret = dev_pm_genpd_add_notifier(pcie->dev, &pcie->pd_nb); - if (ret) - return ret; - if (!dev_pm_genpd_is_on(pcie->dev)) { - dev_pm_genpd_remove_notifier(pcie->dev); + if (!pcie->num_pds) return -ENODEV; + while (pcie->pd_held < pcie->num_pds) { + pd = &pcie->pds[pcie->pd_held]; + pd->vetoed = 0; + pd->nb.notifier_call = apple_pcie_pd_notify; + ret = dev_pm_genpd_add_notifier(pd->dev, &pd->nb); + if (ret) + goto err_release; + pcie->pd_held++; + if (!dev_pm_genpd_is_on(pd->dev)) { + ret = -ENODEV; + goto err_release; + } } - pcie->pd_held = true; return 0; -} -static void apple_pcie_release_domain(struct apple_pcie *pcie) -{ - if (!pcie->pd_held) - return; - dev_pm_genpd_remove_notifier(pcie->dev); - pcie->pd_held = false; - dev_dbg(pcie->dev, "PCIe-C power domain released after suspend-to-idle (%u power-offs refused)\n", - pcie->pd_vetoed); +err_release: + apple_pcie_release_domains(pcie); + return ret; } /* @@ -3876,7 +3939,7 @@ static void apple_pcie_release_domain(struct apple_pcie *pcie) * and resume like any other PCIe device; nothing has to be re-trained. * The host's power domain must stay on for that: an always-on one does; * on a host that opts in (s2idle_hold_domain), any other is held on for the - * sleep (apple_pcie_hold_domain()). + * sleep (apple_pcie_hold_domains()). */ static bool apple_pcie_keep_link(struct apple_pcie *pcie) { @@ -3891,7 +3954,7 @@ static bool apple_pcie_keep_link(struct apple_pcie *pcie) if (!pcie->power_retained) { if (!pcie->hw->s2idle_hold_domain) return false; - ret = apple_pcie_hold_domain(pcie); + ret = apple_pcie_hold_domains(pcie); if (ret) { dev_dbg(pcie->dev, "PCIe-C power domain not held (%d): link not kept\n", ret); @@ -3900,7 +3963,7 @@ static bool apple_pcie_keep_link(struct apple_pcie *pcie) } if (apple_pcie_tunnel_link_healthy(pcie)) return true; - apple_pcie_release_domain(pcie); + apple_pcie_release_domains(pcie); return false; } @@ -3948,12 +4011,15 @@ static int apple_pcie_suspend_noirq(struct device *dev) /* * The managed radio has no suspend boundary of its own; suspend-to-idle - * leaves it in place like any other internal port (no power domain). + * leaves it in place like any other internal port. */ - if (pcie->managed_sids) - return pm_suspend_target_state == PM_SUSPEND_TO_IDLE ? 0 : -EBUSY; - if (!pcie->hw->tunneled) + if (pcie->managed_sids && pm_suspend_target_state != PM_SUSPEND_TO_IDLE) + return -EBUSY; + if (!pcie->hw->tunneled) { + if (pm_suspend_no_platform() && pcie->num_pds) + return apple_pcie_hold_domains(pcie); return 0; + } pcie->reset_on_resume = false; pcie->link_kept = apple_pcie_keep_link(pcie); if (!pcie->link_kept) @@ -4008,10 +4074,10 @@ static int apple_pcie_resume_noirq(struct device *dev) struct apple_pcie_port *port; int ret; + /* The domain's hold for the sleep ends first, whatever follows. */ + apple_pcie_release_domains(pcie); if (!pcie->hw->tunneled) return 0; - /* The domain's hold for the sleep ends first, whatever follows. */ - apple_pcie_release_domain(pcie); if (pcie->resume_failed) return -EIO; /* From 930c1893972475e19b6a7e98411ff5872f4b46ef Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 21:15:15 +1100 Subject: [PATCH 166/342] arm64: dts: apple: complete the J616s and M2 internal PCIe power chains The internal host needs both the general-purpose and storage/PHY chains listed by the ADT clock gates. On J616s APCIE_SYS_GP reaches APCIE_GP, while APCIE_PHY_SW reaches both storage chains and ANS. On T8112 APCIE_ST adds the ANS/storage chain that NVMe happens to keep powered today. Keep the J616s interim always-on states until the host can cold-initialize its internal links after resume. Assisted-by: LLM Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t6040-j616s.dts | 2 +- arch/arm64/boot/dts/apple/t8112.dtsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index c263d1da558cc..4380094b8e071 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -305,5 +305,5 @@ }; &pcie0 { - power-domains = <&ps_apcie_sys_gp>; + power-domains = <&ps_apcie_sys_gp>, <&ps_apcie_phy_sw>; }; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index fbfe2a632e92a..e6e7b726e53c6 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -2560,7 +2560,7 @@ ranges = <0x43000000 0x6 0xa0000000 0x6 0xa0000000 0x0 0x20000000>, <0x02000000 0x0 0xc0000000 0x6 0xc0000000 0x0 0x40000000>; - power-domains = <&ps_apcie_gp>; + power-domains = <&ps_apcie_gp>, <&ps_apcie_st>; pinctrl-0 = <&pcie_pins>; pinctrl-names = "default"; From 5c96ab0a5f97ab0b1338f03a16d4df33e710c0c5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 21:15:29 +1100 Subject: [PATCH 167/342] arm64: dts: apple: attach the Neo internal PCIe host to its full power chain The T8140 ADT gates APCIE_GP, APCIE_SYS_GP, APCIE_ST, APCIE_SYS_ST, ANS and APCIE_PHY_SW for apcie0. APCIE_PHY_SW already has all of the other domains as ancestors, so attach the host to that leaf instead of APCIE_GP alone. This removes its dependency on NVMe keeping the storage and PHY chain on. The host retains this chain during suspend-to-idle while the radio wake path leaves the internal link running. Assisted-by: LLM Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8140.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8140.dtsi b/arch/arm64/boot/dts/apple/t8140.dtsi index b781dd756a2d2..4242e655a3af7 100644 --- a/arch/arm64/boot/dts/apple/t8140.dtsi +++ b/arch/arm64/boot/dts/apple/t8140.dtsi @@ -1206,7 +1206,7 @@ #size-cells = <2>; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; - power-domains = <&ps_apcie_gp>; + power-domains = <&ps_apcie_phy_sw>; status = "disabled"; pcie0_port0: pci@0,0 { From 9e86c161a811d528bac6a47c43b255ceeab4a502 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 15:00:56 +1100 Subject: [PATCH 168/342] rtc: apple-pmu: clear Maverick control event latch Maverick keeps a second fired-event latch in control bit 1, next to the event register. The arm path preserved that bit, so after one alarm had fired (or firmware had left the latch set) the alarm was armed as 0x43. The comparator still matched and cleared ARM, but no new event edge latched and the SPMI interrupt never fired. Clear the control event bit on every control write, so the alarm is armed as 0x41 and each match raises interrupt 2. On a J316s (M1 Pro) with this series, two awake alarms each raised the RTC interrupt once and cleared wakealarm, and six 15 s s2idle suspends woke on the RTC interrupt after 15.5-16.0 s. Extend the host model with Maverick's write-zero-to-clear control latch and its stale-edge suppression. Stowe keeps its exact control value checks, so the T8112 path is unchanged. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/rtc/rtc-apple-pmu.c | 4 +++ tools/asahi/pmu-rtc-tests.py | 49 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/rtc-apple-pmu.c b/drivers/rtc/rtc-apple-pmu.c index d324234cf807b..6043d7ee87a84 100644 --- a/drivers/rtc/rtc-apple-pmu.c +++ b/drivers/rtc/rtc-apple-pmu.c @@ -30,6 +30,7 @@ struct apple_pmu_rtc_hw { u16 mask; u16 event; u8 event_bit; + u8 control_event_bit; u8 monitor_bit; bool offset_in_seconds; }; @@ -73,6 +74,7 @@ static const struct apple_pmu_rtc_hw apple_pmu_rtc_maverick = { .mask = 0x14c2, .event = 0x14c0, .event_bit = BIT(0), + .control_event_bit = BIT(1), .monitor_bit = BIT(0), }; @@ -177,6 +179,8 @@ static int apple_pmu_rtc_arm(struct apple_pmu_rtc *rtc, bool enable) /* Do not acknowledge a shared W1C event as a side effect of RMW. */ if (rtc->hw->event == rtc->hw->control) control &= ~rtc->hw->event_bit; + /* Maverick clears its additional fired latch when this bit is zero. */ + control &= ~rtc->hw->control_event_bit; control &= ~APPLE_PMU_RTC_ARM; if (enable) control |= APPLE_PMU_RTC_ARM; diff --git a/tools/asahi/pmu-rtc-tests.py b/tools/asahi/pmu-rtc-tests.py index 3c85238cc6343..469cacc4b3082 100644 --- a/tools/asahi/pmu-rtc-tests.py +++ b/tools/asahi/pmu-rtc-tests.py @@ -21,6 +21,8 @@ 'event-bit': ('.event_bit = BIT(1)', '.event_bit = BIT(0)'), 'wrong-control': ('.control = 0x2000', '.control = 0xf800'), 'maverick-event': ('.event = 0x14c0', '.event = 0x140c'), + 'control-event-clear': ('control &= ~rtc->hw->control_event_bit;', + 'control |= rtc->hw->control_event_bit;'), 'stowe-offset': ('static const struct apple_pmu_rtc_hw apple_pmu_rtc_stowe = {', 'static const struct apple_pmu_rtc_hw apple_pmu_rtc_stowe = {\n\t.offset_in_seconds = true,'), } @@ -62,7 +64,11 @@ struct rtc_device { int events; }; struct device { void *data; bool wake; int wake_events; }; struct nvmem_cell { u8 data[8]; size_t bytes; int error; }; -struct regmap { u8 bytes[65536]; unsigned ctrl, counter, compare, mask, event, bit; int ops, fail; }; +struct regmap { + u8 bytes[65536]; + unsigned ctrl, counter, compare, mask, event, bit, control_event; + int ops, fail; +}; static int disabled, pm_suspend_target_state = PM_SUSPEND_TO_IDLE; static inline __attribute__((unused)) s64 sign_extend64(u64 v, int bit) { return (s64)(v << (63 - bit)) >> (63 - bit); } static u64 get_unaligned_le64(const void *p) { u64 v; memcpy(&v, p, 8); return v; } @@ -94,6 +100,10 @@ if (reg == m->event) { /* W1C event, normal R/W bits in the same byte. */ m->bytes[reg] = (v & ~m->bit) | (m->bytes[reg] & m->bit & ~v); + } else if (reg == m->ctrl && m->control_event) { + /* Maverick's control-side event latch is cleared by writing zero. */ + m->bytes[reg] = (v & ~m->control_event) | + (m->bytes[reg] & m->control_event & v); } else m->bytes[reg] = v; return 0; } @@ -113,6 +123,17 @@ assert(!(m->bytes[m->ctrl] & 0x40) && (m->bytes[m->mask] & 1)); memcpy(m->bytes + reg, v, n); return 0; } +static bool fire_alarm(struct regmap *m) { + assert(m->bytes[m->ctrl] & 0x40); + m->bytes[m->ctrl] &= ~0x40; + if (m->control_event) { + /* A stale control latch suppresses the next separate-event edge. */ + if (m->bytes[m->ctrl] & m->control_event) return false; + m->bytes[m->ctrl] |= m->control_event; + } + m->bytes[m->event] |= m->bit; + return true; +} ''' CASES = r''' @@ -137,7 +158,7 @@ [STOWE] = {.ctrl = 0xf800, .counter = 0xf802, .compare = 0xf808, .mask = 0xf80e, .event = 0xf80c, .bit = 1}, [MAVERICK] = {.ctrl = 0x1401, .counter = 0x1406, .compare = 0x140c, .mask = 0x14c2, - .event = 0x14c0, .bit = 1}, + .event = 0x14c0, .bit = 1, .control_event = 2}, }; static const struct apple_pmu_rtc_hw *hw[] = { [BAKU] = &apple_pmu_rtc_baku, [ABBEY] = &apple_pmu_rtc_abbey, @@ -149,8 +170,9 @@ rtc = (struct apple_pmu_rtc){.hw = hw[v], .map = &map, .offset = &offset, .clock = &clock_model}; dev = (struct device){.data = &rtc, .wake = true}; disabled = 0; - /* Keep an unrelated writable bit, and Abbey's monitor bit. */ + /* Keep an unrelated writable bit, and each variant's monitor bit. */ map.bytes[map.ctrl] = a ? 0x81 : 0x80; + if (v == MAVERICK) map.bytes[map.ctrl] = 0x03; set_counter(100ULL << 16); set_offset(a ? 1000LL * 32768 + 16384 : 1000); } @@ -161,20 +183,29 @@ struct rtc_wkalrm alarm = {.time.seconds = 1130, .enabled = true}, readback; s64 ticks; reset(v); + if (v == MAVERICK) { + /* A stale 0x03 latch suppresses a new edge until control bit 1 clears. */ + assert(map.bytes[map.ctrl] == 0x03 && !(map.bytes[map.event] & map.bit)); + map.bytes[map.ctrl] |= 0x40; + assert(!fire_alarm(&map)); + assert(map.bytes[map.ctrl] == 0x03 && !(map.bytes[map.event] & map.bit)); + } assert(!apple_pmu_rtc_read_time(&dev, &time) && time.seconds == 1100); set_counter((100ULL << 16) + 49152); assert(!apple_pmu_rtc_read_time(&dev, &time) && time.seconds == (a ? 1101 : 1100)); assert(!apple_pmu_rtc_set_alarm(&dev, &alarm)); assert(comparator() == 130 && (map.bytes[map.ctrl] & 0x40)); - assert(map.bytes[map.ctrl] == (a ? 0xc1 : 0xc0)); + assert(map.bytes[map.ctrl] == (v == MAVERICK ? 0x41 : (a ? 0xc1 : 0xc0))); assert(!(map.bytes[map.mask] & 1)); assert(!apple_pmu_rtc_read_alarm(&dev, &readback)); assert(readback.time.seconds == 1130 && readback.enabled && !readback.pending); /* Acknowledge without changing ARM, monitor or the unrelated bit. */ - map.bytes[map.event] |= map.bit; + assert(fire_alarm(&map)); + if (v == MAVERICK) assert(map.bytes[map.ctrl] == 0x03); assert(!apple_pmu_rtc_ack_alarm(&rtc)); - assert(map.bytes[map.ctrl] == (a ? 0xc1 : 0xc0)); + assert(map.bytes[map.ctrl] == (a ? (v == MAVERICK ? 0x03 : 0x81) : 0x80)); assert(!(map.bytes[map.event] & map.bit)); + assert(!apple_pmu_rtc_arm(&rtc, true)); /* An ordinary control write must not consume a latched event. */ map.bytes[map.event] |= map.bit; assert(!apple_pmu_rtc_arm(&rtc, false)); @@ -182,12 +213,12 @@ assert(!apple_pmu_rtc_read_alarm(&dev, &readback) && readback.pending); assert(apple_pmu_rtc_interrupt(7, &dev) == IRQ_HANDLED); assert(clock_model.events == 1 && dev.wake_events == 1); - assert(map.bytes[map.ctrl] == (a ? 0x81 : 0x80)); + assert(map.bytes[map.ctrl] == (v == MAVERICK ? 0x01 : (a ? 0x81 : 0x80))); assert(!(map.bytes[map.event] & map.bit) && (map.bytes[map.mask] & 1)); assert(apple_pmu_rtc_interrupt(7, &dev) == IRQ_NONE && clock_model.events == 1); /* Repeat arm/fire; no stuck status or stale IRQ after the first alarm. */ assert(!apple_pmu_rtc_alarm_enable(&dev, 1)); - map.bytes[map.event] |= map.bit; + assert(fire_alarm(&map)); dev.wake = false; assert(apple_pmu_rtc_interrupt(7, &dev) == IRQ_HANDLED); assert(clock_model.events == 2 && dev.wake_events == 1); @@ -218,7 +249,7 @@ assert(!apple_pmu_rtc_set_alarm(&dev, &alarm)); map.ops = 0; assert(!apple_pmu_rtc_init_alarm(&rtc) && (map.bytes[map.ctrl] & 0x40)); - set_counter(131ULL << 16); map.bytes[map.event] |= map.bit; + set_counter(131ULL << 16); assert(fire_alarm(&map)); assert(!apple_pmu_rtc_init_alarm(&rtc)); assert(!(map.bytes[map.ctrl] & 0x40) && !(map.bytes[map.event] & map.bit)); assert(map.bytes[map.mask] & 1); From f31c0a338df5bf085d4e9d6b1d8cdbc540a6c987 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 21:19:01 +1100 Subject: [PATCH 169/342] PCI: apple: preserve probe without power-management support The domain-attachment helper is a no-op without CONFIG_PM. Keep the host usable in that configuration instead of treating its zero return as a missing domain. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/pci/controller/pcie-apple.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 409b95e68e1a9..7857378340110 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -3115,6 +3115,8 @@ static int apple_pcie_attach_domains(struct apple_pcie *pcie) }; int count, ret, i; + if (!IS_ENABLED(CONFIG_PM)) + return 0; if (!of_property_present(dev->of_node, "power-domains")) return 0; From bf15de581c59ec264c8291183cfee28c279bea02 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:41:42 +1100 Subject: [PATCH 170/342] media: apple: scaler: support the T6000 and T8112 engines The fixed job words at 0x2e300-0x2e318 belong to the MSR20 generation (M4, M4 Pro/Max, A18 Pro). Older engines have a 0x28000 aperture, so writing them faults. Move those words to a table that only MSR20 variants emit, and refuse a job whose register list does not fit the aperture instead of writing past it. Add the T8112 (hardware-version 13) and T6000 (hardware-version 12) engines. Both have three register ranges and run the same jobs as the MSR20 engines without that control block. Tested with msrv4l2, which converts NV12, NV12M and P010 to ARGB32 and ARGB32 to NV12M at 1080p, 20 jobs each, against a software reference: M2 (T8112) PASS, max error 1, about 1.0 ms per job M1 Pro (T6000) PASS, max error 1, about 2.15 ms per job No DART faults; the engine runtime-suspends when idle. KUnit apple-scaler 14/14 passes. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../platform/apple/scaler/apple-scaler-drv.c | 30 +++++++++++++++++++ .../platform/apple/scaler/apple-scaler-hw.c | 18 +++++++++-- .../platform/apple/scaler/apple-scaler-hw.h | 1 + .../platform/apple/scaler/apple-scaler-test.c | 1 + 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/apple/scaler/apple-scaler-drv.c b/drivers/media/platform/apple/scaler/apple-scaler-drv.c index 6a8d5f8438ce8..e65a7385407d0 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-drv.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-drv.c @@ -54,15 +54,18 @@ * struct apple_scaler_variant - per-SoC engine description * @hw_version: MSR hardware-version of this SoC (from the hardware description) * @num_reg: number of register apertures the binding describes + * @msr20: the engine has the MSR20-generation control block */ struct apple_scaler_variant { u32 hw_version; unsigned int num_reg; + bool msr20; }; struct apple_scaler { struct device *dev; void __iomem *regs; + resource_size_t regs_size; const struct apple_scaler_variant *variant; struct dev_pm_domain_list *pd_list; struct reset_control *rst; @@ -106,6 +109,7 @@ static void asc_write(struct apple_scaler *asc, u32 reg, u32 val) /* ---- hardware --------------------------------------------------------- */ + /* * After power-up or a failed job: wait for idle, pulse the engine reset * (no register may be read while it is held), clear stale status and @@ -293,12 +297,23 @@ static void asc_device_run(void *priv) spin_lock_irqsave(&asc->hw_lock, flags); /* Job tags as the engine is driven on macOS: a counter above bit 3, bit 2 set. */ job.transform_id = (++asc->transform_id << 3) | BIT(2); + job.msr20 = asc->variant->msr20; n = asc_job_build(&job, asc->writes, ARRAY_SIZE(asc->writes)); if (n < 0) { spin_unlock_irqrestore(&asc->hw_lock, flags); asc_finish(asc, ctx, n); return; } + /* The job list must fit this engine's register aperture. */ + for (int i = 0; i < n; i++) { + if (asc->writes[i].off + sizeof(u32) > asc->regs_size) { + spin_unlock_irqrestore(&asc->hw_lock, flags); + dev_err_ratelimited(asc->dev, "job register %#x is outside the aperture\n", + asc->writes[i].off); + asc_finish(asc, ctx, -EINVAL); + return; + } + } asc->active = ctx; /* Buffers must be visible to the engine before START, the last write. */ dma_wmb(); @@ -754,6 +769,7 @@ static int asc_probe(struct platform_device *pdev) asc->regs = devm_ioremap_resource(dev, res); if (IS_ERR(asc->regs)) return PTR_ERR(asc->regs); + asc->regs_size = resource_size(res); asc->rst = devm_reset_control_get_optional_exclusive(dev, NULL); if (IS_ERR(asc->rst)) @@ -814,17 +830,31 @@ static void asc_remove(struct platform_device *pdev) video_unregister_device(&asc->vdev); } +static const struct apple_scaler_variant apple_scaler_t6000 = { + .hw_version = 12, + .num_reg = 3, +}; + +static const struct apple_scaler_variant apple_scaler_t8112 = { + .hw_version = 13, + .num_reg = 3, +}; + static const struct apple_scaler_variant apple_scaler_t6041 = { .hw_version = 21, .num_reg = 4, + .msr20 = true, }; static const struct apple_scaler_variant apple_scaler_t8140 = { .hw_version = 22, .num_reg = 4, + .msr20 = true, }; static const struct of_device_id asc_of_match[] = { + { .compatible = "apple,t6000-scaler", .data = &apple_scaler_t6000 }, + { .compatible = "apple,t8112-scaler", .data = &apple_scaler_t8112 }, { .compatible = "apple,t6041-scaler", .data = &apple_scaler_t6041 }, { .compatible = "apple,t8140-scaler", .data = &apple_scaler_t8140 }, { } diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.c b/drivers/media/platform/apple/scaler/apple-scaler-hw.c index 5eb645a776470..ff6d7751135cc 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-hw.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.c @@ -375,9 +375,18 @@ static const struct asc_reg asc_job_fixed[] = { { 0x16084, 0x0b710367 }, { 0x16088, 0x00000128 }, { 0x16504, 0x02000500 }, { 0x16508, 0x00003200 }, { 0x1651c, 0x00851400 }, { 0x16534, 0x00000008 }, { 0x16568, 0x00250500 }, { 0x16588, 0x00496513 }, { 0x16600, 0x00000015 }, - { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, { 0x2e300, 0x03804038 }, - { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, { 0x2e30c, 0x02550255 }, - { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, { 0x2e318, 0x02550000 }, + { 0x16800, 0x00000000 }, { 0x25080, 0x00000000 }, +}; + +/* + * The MSR20 generation (M4, M4 Pro/Max, A18 Pro) has a control block at + * 0x2e300 beyond the 0x28000 aperture of older engines. Engines without + * it run the same jobs with only the common words above. + */ +static const struct asc_reg asc_job_fixed_msr20[] = { + { 0x2e300, 0x03804038 }, { 0x2e304, 0xa0a0a0a0 }, { 0x2e308, 0x02550000 }, + { 0x2e30c, 0x02550255 }, { 0x2e310, 0x00000000 }, { 0x2e314, 0x00100008 }, + { 0x2e318, 0x02550000 }, }; /** @@ -414,6 +423,9 @@ int asc_job_build(const struct asc_job *job, struct asc_reg *w, unsigned int max asc_emit_csc(&e, job->csc); for (i = 0; i < ARRAY_SIZE(asc_job_fixed); i++) asc_emit(&e, asc_job_fixed[i].off, asc_job_fixed[i].val); + if (job->msr20) + for (i = 0; i < ARRAY_SIZE(asc_job_fixed_msr20); i++) + asc_emit(&e, asc_job_fixed_msr20[i].off, asc_job_fixed_msr20[i].val); asc_emit(&e, 0x110, job->transform_id); asc_emit(&e, 0x098, 0xfffffffe); asc_emit(&e, 0x080, 1); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-hw.h b/drivers/media/platform/apple/scaler/apple-scaler-hw.h index cf371272dce66..b598fb08cd397 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-hw.h +++ b/drivers/media/platform/apple/scaler/apple-scaler-hw.h @@ -110,6 +110,7 @@ struct asc_job { struct asc_image dst; const struct asc_csc *csc; u32 transform_id; + bool msr20; /* engine has the MSR20-generation control block */ }; int asc_job_build(const struct asc_job *job, struct asc_reg *w, unsigned int max); diff --git a/drivers/media/platform/apple/scaler/apple-scaler-test.c b/drivers/media/platform/apple/scaler/apple-scaler-test.c index 4e61ad54e59a9..ddf8f633a469b 100644 --- a/drivers/media/platform/apple/scaler/apple-scaler-test.c +++ b/drivers/media/platform/apple/scaler/apple-scaler-test.c @@ -405,6 +405,7 @@ static void asc_test_job(struct kunit *test) job.src.fmt->yuv, &csc), 0); job.csc = &csc; job.transform_id = asc_expect_get(c, ASC_TRANSFORM_ID); + job.msr20 = true; /* traced on the J616s (MSR21) */ n = asc_job_build(&job, w, ASC_JOB_MAX_WRITES); KUNIT_ASSERT_GT(test, n, 0); From 133d87b4cd690ebb1c3d70e63d132d7ad4b36596 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:41:42 +1100 Subject: [PATCH 171/342] arm64: dts: apple: t8112: enable the scaler The scaler (MSR, hardware-version 13) and its DART work on the M2 with apple-scaler. Enable both for all T8112 boards. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-peripherals.dtsi | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi index 1869b990d571f..f9cda024c5621 100644 --- a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi @@ -180,7 +180,6 @@ ; iommus = <&m2_dart_scaler 0>, <&m2_dart_scaler 1>; power-domains = <&ps_msr>, <&ps_msr_ase_core>; - status = "disabled"; }; m2_dart_scaler: iommu@263200000 { @@ -190,7 +189,6 @@ interrupts = ; power-domains = <&ps_msr>; #iommu-cells = <1>; - status = "disabled"; }; m2_jpeg0: jpeg@265000000 { From 7fc06c420370769c7fb7fa67e99f7b31d63da205 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:42:35 +1100 Subject: [PATCH 172/342] HID: magicmouse: hold the multitouch enable work across system sleep reset_resume re-arms the work that puts the trackpad back into multitouch mode 500 ms after resume. When the next suspend starts within that window, the work is still pending: its timer fires during the following suspend or resume, before the SPI HID transport is powered again, and the feature report fails with -ENODEV ("unable to request touch data (-19)"). The touch mode is then not restored after that resume. Cancel the work in suspend. reset_resume schedules it again as before; a plain resume, where the device kept its state, re-queues it only if suspend stopped it while it was pending. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/hid/hid-magicmouse.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index e909a698ac106..e7373d36b141b 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -284,6 +284,7 @@ struct effect_job { * @haptic_deep_down: The host-derived click is in its deep stage. * @hdev: Pointer to the underlying HID device. * @work: Workqueue to handle initialization retry for quirky devices. + * @work_held: @work was pending at suspend and must run again on resume. * @battery_timer: Timer for obtaining battery level information. * @input_ops: Input ops based on device type. */ @@ -324,6 +325,7 @@ struct magicmouse_sc { struct hid_device *hdev; struct delayed_work work; + bool work_held; struct timer_list battery_timer; struct magicmouse_input_ops input_ops; }; @@ -2553,12 +2555,34 @@ static void magicmouse_remove(struct hid_device *hdev) } #ifdef CONFIG_PM -static int magicmouse_resume(struct hid_device *hdev) +static int magicmouse_suspend(struct hid_device *hdev, pm_message_t message) { struct magicmouse_sc *msc = hid_get_drvdata(hdev); + /* + * The multitouch enable work sends a feature report. The transport + * powers down right after its children suspend, and the work's timer + * can fire while the system is still suspending or before the + * transport has resumed, so stop it here and re-arm it on resume. + */ if (msc) - magicmouse_haptic_forget_mode(msc); + msc->work_held = cancel_delayed_work_sync(&msc->work); + return 0; +} + +static int magicmouse_resume(struct hid_device *hdev) +{ + struct magicmouse_sc *msc = hid_get_drvdata(hdev); + + if (!msc) + return 0; + + /* The device kept its state, so only finish what suspend stopped. */ + if (msc->work_held) { + msc->work_held = false; + schedule_delayed_work(&msc->work, msecs_to_jiffies(10)); + } + magicmouse_haptic_forget_mode(msc); return 0; } @@ -2570,6 +2594,8 @@ static int magicmouse_reset_resume(struct hid_device *hdev) * enable report. Only the HID_TYPE_USBMOUSE interface accepts it, and * it must be deferred. Sending it inline here is too early. */ + if (msc) + msc->work_held = false; if (msc && (hdev->type == HID_TYPE_USBMOUSE || hdev->bus == BUS_SPI)) schedule_delayed_work(&msc->work, msecs_to_jiffies(500)); @@ -2648,6 +2674,7 @@ static struct hid_driver magicmouse_driver = { .input_mapping = magicmouse_input_mapping, .input_configured = magicmouse_input_configured, #ifdef CONFIG_PM + .suspend = magicmouse_suspend, .resume = magicmouse_resume, .reset_resume = magicmouse_reset_resume, #endif From add3b8dda9149bf610eef72f7c8dc2724f628b02 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:47:36 +1100 Subject: [PATCH 173/342] arm64: dts: apple: t6000: enable the scaler The scaler (MSR, hardware-version 12) and its DART work on the M1 Pro with apple-scaler. Enable both on the T6000 (M1 Pro) boards. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000-peripherals.dtsi | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi index 354ec7f161a77..8dbf14d92da28 100644 --- a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi @@ -135,7 +135,6 @@ clocks = <&peripheral_clocks 356>; iommus = <&scaler0_dart 0>, <&scaler0_dart 1>; resets = <&ps_msr0>; - status = "disabled"; }; scaler0_dart: iommu@40b200000 { @@ -145,7 +144,6 @@ interrupts = ; power-domains = <&ps_msr0>; #iommu-cells = <1>; - status = "disabled"; }; ave0_dma: dma-controller@40d020000 { From ec4467e80b4d2f6a616edde1baf322f071f5fab5 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:07:06 +1100 Subject: [PATCH 174/342] EDAC: apple_soc: add the T8112 error handler The T8112 error handler has 19 interrupts: one AMCC aggregate line, two SEP lines (memory protection and clock/process monitor) and sixteen DCS lines (eight channels and their calibration partners). Claim the SEP lines and leave AMCC and DCS unclaimed, as on T6000 and T6041. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/edac/apple_soc_edac.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/edac/apple_soc_edac.c b/drivers/edac/apple_soc_edac.c index 0733a2712d4a4..a72e7f4dc351a 100644 --- a/drivers/edac/apple_soc_edac.c +++ b/drivers/edac/apple_soc_edac.c @@ -104,6 +104,15 @@ static const struct apple_soc_edac_range t6000_error_ranges[] = { { 72, 4, "nsr" }, }; +/* + * T8112: one AMCC aggregate line (0), two SEP lines (1-2) and sixteen DCS + * lines (3-18, eight channels plus their calibration partners). AMCC and + * DCS stay unclaimed, as on T6000 and T6041. + */ +static const struct apple_soc_edac_range t8112_error_ranges[] = { + { 1, 2, "sep" }, +}; + static const struct apple_soc_edac_range t8140_error_ranges[] = { { 4, 1, "pmgr" }, { 5, 9, "sep" }, @@ -130,6 +139,12 @@ static const struct apple_soc_edac_hw t6041_error_hw = { .num_status_regs = T6041_NI_REGS, }; +static const struct apple_soc_edac_hw t8112_error_hw = { + .ranges = t8112_error_ranges, + .nranges = ARRAY_SIZE(t8112_error_ranges), + .num_irqs = 19, +}; + static const struct apple_soc_edac_hw t8140_error_hw = { .ranges = t8140_error_ranges, .nranges = ARRAY_SIZE(t8140_error_ranges), @@ -390,6 +405,7 @@ static void apple_soc_edac_remove(struct platform_device *pdev) static const struct of_device_id apple_soc_edac_of_match[] = { { .compatible = "apple,t6000-error-handler", .data = &t6000_error_hw }, { .compatible = "apple,t6041-error-handler", .data = &t6041_error_hw }, + { .compatible = "apple,t8112-error-handler", .data = &t8112_error_hw }, { .compatible = "apple,t8140-error-handler", .data = &t8140_error_hw }, { .compatible = "apple,t6000-event-log", .data = &t6000_event_hw }, { .compatible = "apple,t6041-event-log", .data = &t6041_event_hw }, From 3a3b903ef8fcc7660621a19f260c63c4f2025ace Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:07:06 +1100 Subject: [PATCH 175/342] arm64: dts: apple: t8112: enable the error handler apple_soc_edac now matches the T8112 error handler. Enable it. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-peripherals.dtsi | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi index 1869b990d571f..8c46aa005ddad 100644 --- a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi @@ -42,7 +42,6 @@ , , ; - status = "disabled"; }; m2_mcc: memory-controller@200100000 { From 12cf63fc46ce01cbe6b32db427c4a6a274c6a61a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:07:33 +1100 Subject: [PATCH 176/342] tools/asahi: model the magicmouse suspend callback in mtp-pm-tests The MTP PM model now runs the production magicmouse_suspend() from the transport's suspend notification. It checks that pending multitouch enable work is cancelled at suspend and queued once on resume, and that idle work stays idle. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/asahi/mtp-pm-tests.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/asahi/mtp-pm-tests.py b/tools/asahi/mtp-pm-tests.py index 7d5b84d662ef0..4f4d183021905 100644 --- a/tools/asahi/mtp-pm-tests.py +++ b/tools/asahi/mtp-pm-tests.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only -"""Run production MTP PM and magicmouse resume callbacks without a device. +"""Run production MTP PM and magicmouse suspend/resume callbacks without a device. -Checks notification order, suspend rollback, resume-error handling and the -actuator mode cache. The old transport must compile and fail at runtime. +Checks notification order, suspend rollback, resume-error handling, the +actuator mode cache and the multitouch enable work held across sleep. The old transport must compile and fail at runtime. """ import argparse import os @@ -37,7 +37,13 @@ def function(source, name): #define READ_ONCE(x) (x) #define WRITE_ONCE(x,v) ((x) = (v)) struct haptics { int mode; }; -struct magicmouse_sc { struct haptics *haptics; bool haptic_button_down, haptic_deep_down; }; +struct delayed_work { bool pending; unsigned queued; }; +struct magicmouse_sc { struct haptics *haptics; bool haptic_button_down, haptic_deep_down; + struct delayed_work work; bool work_held; }; +typedef int pm_message_t; +static unsigned long msecs_to_jiffies(unsigned m) { return m; } +static bool cancel_delayed_work_sync(struct delayed_work *w) { bool p = w->pending; w->pending = false; return p; } +static bool schedule_delayed_work(struct delayed_work *w, unsigned long d) { w->queued++; w->pending = true; return true; } struct hid_device { struct magicmouse_sc *data; int id; }; struct dchid_iface { struct hid_device *hid; }; struct dockchannel_hid { struct dchid_iface *ifaces[MAX_INTERFACES]; bool suspended; }; @@ -53,6 +59,8 @@ def function(source, name): static int hid_driver_suspend(struct hid_device *h, int state) { assert(state == PMSG_SUSPEND && !transport->suspended); suspends[h->id]++; + if (h->id != suspend_error_at) + magicmouse_suspend(h, state); return h->id == suspend_error_at ? -EBUSY : 0; } ''' @@ -97,7 +105,14 @@ def function(source, name): assert(!dockchannel_hid_resume(&d)); assert(hap.mode == HID_HAPTIC_MODE_DEVICE); } - puts("MTP PM: HID notifications, rollback, all-interface resume and haptic cache passed"); + /* Pending multitouch enable work is held across sleep and re-queued once. */ + m.work.pending = true; m.work.queued = 0; + assert(!dockchannel_hid_suspend(&d) && !m.work.pending && m.work_held); + assert(!dockchannel_hid_resume(&d) && m.work.pending && !m.work_held && m.work.queued == 1); + m.work.pending = false; + assert(!dockchannel_hid_suspend(&d) && !m.work_held); + assert(!dockchannel_hid_resume(&d) && !m.work.pending && m.work.queued == 1); + puts("MTP PM: HID notifications, rollback, all-interface resume, haptic cache and held enable work passed"); } ''' @@ -115,7 +130,8 @@ def main(): out = Path(args.out or tmp) out.mkdir(parents=True, exist_ok=True) c, exe = out/'mtp-pm.c', out/'mtp-pm' - c.write_text(PREFIX + function(mouse, 'magicmouse_haptic_forget_mode') + '\n' + + c.write_text(PREFIX.replace('static int hid_driver_suspend', function(mouse, 'magicmouse_suspend') + '\nstatic int hid_driver_suspend', 1) + + function(mouse, 'magicmouse_haptic_forget_mode') + '\n' + function(mouse, 'magicmouse_resume') + MIDDLE + function(source, 'dockchannel_hid_suspend') + '\n' + function(source, 'dockchannel_hid_resume') + CASES) From 09458b01af1c31919327cad070f17810ade588c3 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:19:01 +1100 Subject: [PATCH 177/342] thunderbolt: Unregister XDomains when the domain is removed Since XDomains are removed from the bus without holding tb->lock, tb_xdomain_remove() only takes an XDomain out of the topology; the caller unregisters it later with tb_domain_unregister_unplugged_xdomains(). tb_domain_remove() never does that. Stopping the connection manager removes the root switch, which marks every XDomain unplugged and calls tb_xdomain_remove(), but the XDomain stays registered on the bus and its service drivers stay bound. When the domain is then freed, a bound thunderbolt-net keeps its protocol handler on the global list with xd->tb pointing at the freed domain. A host router driver that removes and re-adds its domain when the link restarts (the Apple ACIO driver does so when the partner reboots) then gets a new domain with the same index: adding the new XDomain fails with a duplicate "0-1" sysfs name, and the stale thunderbolt-net answers the partner's ThunderboltIP login, which now arrives on the new control channel, through the freed one: Unable to handle kernel paging request at virtual address ... pc : queued_spin_lock_slowpath+0x18c/0x5d0 Call trace: queued_spin_lock_slowpath+0x18c/0x5d0 (P) _raw_spin_lock_irqsave+0x9c/0xa8 __mutex_unlock_slowpath+0x90/0x338 mutex_unlock+0x34/0x70 tb_cfg_request+0x218/0x250 [thunderbolt] tb_xdomain_response+0x74/0xb0 [thunderbolt] tbnet_login_response+0x9c/0x238 [thunderbolt_net] tbnet_handle_packet+0xd0/0x358 [thunderbolt_net] tb_xdomain_handle_request+0xf0/0x1f0 [thunderbolt] tb_domain_event_cb+0x60/0xa8 [thunderbolt] tb_ctl_handle_event+0x38/0x170 [thunderbolt] tb_ctl_rx_callback+0x1b8/0x528 [thunderbolt] ring_work+0x138/0x280 [thunderbolt] Unregister the unplugged XDomains in tb_domain_remove() once tb->lock is dropped and the domain workqueue is drained, before the connection manager is deinitialized and the domain device goes away. The control channel is already stopped at that point, so requests the service drivers send while unbinding (thunderbolt-net's logout) fail with -ENOTCONN instead of waiting for a timeout. Fixes: a8937f35cf39 ("thunderbolt: Remove XDomain from the bus without holding tb->lock") Closes: https://github.com/aurora-silicon/linux/issues/1318 Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/thunderbolt/domain.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c index 56ffea80c5981..72b227997fab7 100644 --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c @@ -510,6 +510,17 @@ void tb_domain_remove(struct tb *tb) flush_workqueue(tb->wq); + /* + * Stopping the connection manager removed the XDomains from the + * topology and marked them unplugged, but they are still on the bus + * with their service drivers bound. Unregister them now: a service + * driver keeps its protocol handler registered until it is unbound + * and would otherwise keep answering XDomain requests through + * tb->ctl after the domain is gone. The control channel is stopped, + * so whatever the service drivers send while unbinding fails at once. + */ + tb_domain_unregister_unplugged_xdomains(tb); + if (tb->cm_ops->deinit) tb->cm_ops->deinit(tb); From 758521bd2d2a9b5e635e7d3ec2eee052a0934c72 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:19:23 +1100 Subject: [PATCH 178/342] net: thunderbolt: Unregister the protocol handler before the netdev tbnet_remove() unregisters the network device first and the ThunderboltIP protocol handler after it. In between, a login or logout packet from the remote host still reaches tbnet_handle_packet(), which can queue login, connect or disconnect work for a device that is being torn down. A logout queues the disconnect work without checking whether the interface is up, and nothing cancels it after tbnet_stop() has run, so it can run after free_netdev(). Take the handler off the list first, then unregister the netdev, and cancel any disconnect work that is still pending before freeing it. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/net/thunderbolt/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c index de56fc2722994..8f3a05e07d717 100644 --- a/drivers/net/thunderbolt/main.c +++ b/drivers/net/thunderbolt/main.c @@ -1521,8 +1521,16 @@ static void tbnet_remove(struct tb_service *svc) { struct tbnet *net = tb_service_get_drvdata(svc); - unregister_netdev(net->dev); + /* + * Take the protocol handler off the list before the interface goes + * down, so that ThunderboltIP packets arriving during the teardown + * no longer reach this device and queue new login, connect or + * disconnect work for it. + */ tb_unregister_protocol_handler(&net->handler); + unregister_netdev(net->dev); + /* A logout received while the interface was down queued this. */ + cancel_work_sync(&net->disconnect_work); free_netdev(net->dev); } From c0da15fe572c1b442568dab3c2ed91069264bb89 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:28:10 +1100 Subject: [PATCH 179/342] arm64: dts: apple: t8140: enable the scaler The scaler (MSR, hardware-version 22) and its DART work on the J700 with apple-scaler. Enable both. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-peripherals.dtsi | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi index 3d5bfc2d9e2a5..f73a86c0f4326 100644 --- a/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi @@ -161,7 +161,6 @@ <&scaler0_dart 1>; clocks = <&peripheral_clocks 374>; resets = <&ps_msr>; - status = "disabled"; }; /* ADT /arm-io/aop2. */ @@ -428,7 +427,6 @@ interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_msr>; - status = "disabled"; }; /* ADT /arm-io/dart-rsm. */ From 5095d596083e6539f2e957273d0738432fd6fef8 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:30:27 +1100 Subject: [PATCH 180/342] dt-bindings: nfc: apple,stockholm-spmi: name the known interrupts, add VEN Three of the seven endpoint interrupts have a known role: the transport error (3), host wake (5) and receive data ready (6). Name all seven so that a driver can request them by name, and describe the VEN enable line. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../bindings/net/nfc/apple,stockholm-spmi.yaml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/net/nfc/apple,stockholm-spmi.yaml b/Documentation/devicetree/bindings/net/nfc/apple,stockholm-spmi.yaml index 8a60fd5c95946..9ef7dab4092bf 100644 --- a/Documentation/devicetree/bindings/net/nfc/apple,stockholm-spmi.yaml +++ b/Documentation/devicetree/bindings/net/nfc/apple,stockholm-spmi.yaml @@ -11,8 +11,8 @@ maintainers: description: | The endpoint occupies an SPMI follower address and exports seven event - interrupts. Event roles and the firmware-controlled enable sequence are - unqualified. This description does not select the later NCI transport. + interrupts, of which three have a known role: the transport error, host + wake and receive data ready. VEN enables the controller. properties: compatible: @@ -30,6 +30,20 @@ properties: minItems: 7 maxItems: 7 + interrupt-names: + items: + - const: event0 + - const: event1 + - const: event2 + - const: error + - const: event4 + - const: host-wake + - const: data-ready + + enable-gpios: + maxItems: 1 + description: VEN, the controller enable line. + required: - compatible - reg From dc53956611b6bd68571979f4c6525b709eff9c61 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:30:28 +1100 Subject: [PATCH 181/342] nfc: apple-stockholm: support the M1/M2-generation controller The T6000 and T8112 Stockholm follower uses the same register map as the model-96 part, with follower ID 0x1c and IRQ base 0xa0. Its commands are not acknowledged until about 10 ms after VEN rises. Add it as a second model for the apple,t6000- and apple,t8112-stockholm-spmi compatibles. The T8112 AOP SPMI controller has no AP interrupt, so neither do its followers. In that case check that the follower answers, then park VEN low. Tested on the M2: "follower 0x1c present, no interrupt path; parked off" on every load. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/nfc/apple-stockholm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/nfc/apple-stockholm.c b/drivers/nfc/apple-stockholm.c index d4810655bfc81..65731cf9b289a 100644 --- a/drivers/nfc/apple-stockholm.c +++ b/drivers/nfc/apple-stockholm.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,20 @@ static const struct stockholm_model stockholm_model96 = { .startup_delay_us = 10000, }; +/* M1/M2 generation (T6000, T8112): the legacy follower, same map. */ +static const struct stockholm_model stockholm_model_b2 = { + .tx_reg = 0x1000, + .rx_reg = 0x80, + .id_reg = 0x100, + .irq_reg = 0x105, + .standby_reg = 0x0, + .follower_id = 0x1c, + .irq_base = 0xa0, + .standby_off = 0x14, + /* Commands are not acknowledged until about 10 ms after VEN rises. */ + .startup_delay_us = 10000, +}; + struct stockholm { struct spmi_device *sdev; const struct stockholm_model *model; @@ -408,6 +423,24 @@ static int stockholm_probe(struct spmi_device *sdev) return dev_err_probe(dev, PTR_ERR(st->enable_gpio), "failed to get VEN GPIO\n"); + /* + * The T8112 AOP SPMI controller has no AP interrupt, so its followers + * have none either. Check that the controller answers and park it. + */ + if (!of_property_present(sdev->ctrl->dev.of_node, "interrupts")) { + ret = stockholm_power_on(st); + if (ret) + return dev_err_probe(dev, ret, "failed to raise VEN\n"); + ret = stockholm_check_follower(st); + err = stockholm_park(st); + if (err) + return dev_err_probe(dev, err, "failed to park VEN low\n"); + if (!ret) + dev_info(dev, "follower %#04x present, no interrupt path; parked off\n", + st->model->follower_id); + return ret; + } + st->data_irq = stockholm_request_irq(st, "data-ready", stockholm_data_irq); if (st->data_irq < 0) @@ -442,6 +475,8 @@ static int stockholm_probe(struct spmi_device *sdev) static const struct of_device_id stockholm_of_match[] = { { .compatible = "apple,stockholm-nci", .data = &stockholm_model96 }, + { .compatible = "apple,t6000-stockholm-spmi", .data = &stockholm_model_b2 }, + { .compatible = "apple,t8112-stockholm-spmi", .data = &stockholm_model_b2 }, {} }; MODULE_DEVICE_TABLE(of, stockholm_of_match); From f336903141a3ab3905ee2c4223f1d0b7f8e1cb7e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:30:28 +1100 Subject: [PATCH 182/342] arm64: dts: apple: t8112-j413: enable the NFC controller Enable the AOP SPMI bus and the Stockholm NFC controller on it, with VEN on SMC GPIO 15. apple-stockholm finds the controller and keeps it off. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-j413.dts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 9c9e7532ae048..1914dd2361bfd 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -357,9 +357,15 @@ }; }; +/* NFC controller (Stockholm): identified once, then kept off. */ +&smc_gpio { + apple,output-templates = <0xf 0x00800000>; +}; + &aop_spmi1 { interrupt-controller; #interrupt-cells = <2>; + status = "okay"; nfc@c { compatible = "apple,t8112-stockholm-spmi", "apple,stockholm-spmi"; @@ -372,7 +378,9 @@ <164 IRQ_TYPE_NONE>, <165 IRQ_TYPE_NONE>, <166 IRQ_TYPE_NONE>; - status = "disabled"; + interrupt-names = "event0", "event1", "event2", "error", + "event4", "host-wake", "data-ready"; + enable-gpios = <&smc_gpio 15 GPIO_ACTIVE_HIGH>; }; }; From 4a7c0cffef4578ae258b77f165adeb512a6bd365 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:35:19 +1100 Subject: [PATCH 183/342] thunderbolt: Refuse XDomain DMA paths once the XDomain is unplugged tb_approve_xdomain_paths() looks up the destination and NHI ports before it takes tb->lock. A service driver can still ask for paths while the domain is being stopped: thunderbolt-net enables them from its connected work, which a ThunderboltIP login queued just before the control channel was stopped. By then tb_stop() may have removed the routers and cleared tb->root_switch, so tb_switch_find_port() follows a NULL pointer, and the XDomain's parent router is a removed switch. Take tb->lock first and return -ENODEV when the XDomain is unplugged or the root switch is gone. tb_disconnect_xdomain_paths() already skips an unplugged XDomain the same way. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/thunderbolt/tb.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index a4d439f2394df..19c1389c63d87 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -3161,12 +3161,22 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, struct tb_switch *sw; int ret; + mutex_lock(&tb->lock); + + /* + * A service driver can still ask for paths after the XDomain was + * unplugged or while the domain is being stopped, when the router + * may already be gone and tb->root_switch is NULL. + */ + if (xd->is_unplugged || !tb->root_switch) { + mutex_unlock(&tb->lock); + return -ENODEV; + } + sw = tb_to_switch(xd->dev.parent); dst_port = tb_port_at(xd->route, sw); nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); - mutex_lock(&tb->lock); - /* * When tunneling DMA paths the link should not enter CL states * so disable them now. From 653f5375f4d33aba76c3636775060e49e5c3816c Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:24:07 -0800 Subject: [PATCH 184/342] dt-bindings: pci: apple,pcie: Add T6050 hosts adopted from the boot loader Add apple,t6050-pcie, a T6050 (M5 Ultra) PCIe host whose root ports the boot loader powered, trained and left running. Each such port is marked apple,link-trained-by-bootloader and named by its port, phy and intr2axi register ranges and its port interrupt; the host's local MSI map starts at apple,msi-vector-base. The OS adopts the trained state and never resets, retrains or changes the port's power: reset-gpios, pwren-gpios and power-domains are not allowed on it. Also name nonposted-mmio, which these hosts take. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 245231ecfc3a9..5823cc0ff837a 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -98,11 +98,11 @@ properties: reg: minItems: 3 - maxItems: 11 + maxItems: 14 reg-names: minItems: 3 - maxItems: 11 + maxItems: 14 ranges: minItems: 2 @@ -128,8 +128,7 @@ properties: apple,msi-vector-base: $ref: /schemas/types.yaml#/definitions/uint32 description: - First vector of this PCIe-C controller's slice of the MSI window it - shares with the internal PCIe controller. + First global vector targeted by this controller's local MSI map. iommu-map: true iommu-map-mask: true @@ -234,6 +233,48 @@ allOf: - apple,msi-vector-base - $ref: /schemas/pci/pci-host-bridge.yaml# - $ref: /schemas/interrupt-controller/msi-controller.yaml# + - if: + properties: + compatible: + contains: + const: apple,t6050-pcie + then: + properties: + reg: + minItems: 5 + maxItems: 14 + reg-names: + description: + config and rc, then port, phy and intr2axi for each + bootloader-trained root port 00:.0. + minItems: 5 + maxItems: 14 + items: + pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" + interrupts: + maxItems: 4 + interrupt-names: + items: + pattern: "^port[0-3]$" + apple,msi-vector-base: + const: 64 + power-domains: false + required: + - interrupt-names + - apple,msi-vector-base + - iommu-map + patternProperties: + "^pci@": + properties: + reset-gpios: false + pwren-gpios: false + required: + - apple,link-trained-by-bootloader + else: + patternProperties: + "^pci@": + properties: + apple,link-trained-by-bootloader: false - if: properties: compatible: @@ -390,10 +431,10 @@ allOf: properties: reg: minItems: 5 - maxItems: 11 + maxItems: 14 reg-names: minItems: 5 - maxItems: 11 + maxItems: 14 items: enum: [config, rc, port0, phy0, intr2axi0, port1, phy1, intr2axi1, port2, phy2, intr2axi2, port3, phy3, @@ -420,6 +461,8 @@ allOf: maxItems: 3 else: properties: + reg: + maxItems: 10 reg-names: minItems: 3 items: From ca6cac821eb3605ae935f1277f66f4ce5d668d72 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:25:06 -0800 Subject: [PATCH 185/342] PCI: apple: Adopt T6050 root ports the boot loader trained On the M5 Ultra (T6050, J775D) running Linux on the hardware, the boot loader brings up the internal PCIe host's ports itself: it powers the shared PHY, trains each port's link and leaves it up, with the endpoint idle. Port 2 carries the onboard RTL8127 Ethernet controller and port 3 the ASM3142 xHCI behind the rear USB-A ports. Repeating the reset and training sequence from Linux is not needed and not known to be safe on this SoC. Add apple,t6050-pcie, a host whose root ports marked apple,link-trained-by-bootloader are adopted as they are: no reset, no tunable replay, no clock or power change and no retraining. Every resource comes from the DT by the port's index (port, phy, intr2axi, interrupt port, the iommu-map entry for the endpoint's RID). Before the first PCIe register write the driver checks that the link is up and not retraining at Gen3 x1, that the boot loader numbered the root port's buses (primary 0, one secondary), that the endpoint on it is device 0 function 0 with DMA and MSI off and a well-formed capability list, and that the port's RID table holds no valid entry. A port that fails a check is left alone and the others are still adopted. Then the endpoint's RID is routed to its SID, the host's MSI map is set up from apple,msi-vector-base, and only the adopted root ports and the endpoint behind each are enumerated. The links cannot be recovered by a user reset or removal, since the boot loader owns them. No other SoC sets adopt_link. Testing: on J775D, every boot adopts port 2 (RTL8127, DHCP and SSH over it on every boot) and port 3 (ASM3142, a USB keyboard and mouse driving the desktop session). Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 283 ++++++++++++++++++++++++++-- 1 file changed, 270 insertions(+), 13 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 6ad3376dcf75e..b0a4a549cdd9e 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -207,6 +207,7 @@ struct hw_info { u32 pwren_on_ms; bool sid_indexed_rid2sid; bool retain_clocks; + bool adopt_link; bool root_bus_only; bool tunneled; bool tunnel_intr2axi; @@ -281,6 +282,24 @@ static const struct hw_info t8152_hw = { .pipe_rst = true, }; +/* + * Bare-metal T6050 adoption only. Firmware owns power, PHY, reset and training. + * The 64-entry route table is never probed with test writes. + */ +static const struct hw_info t6050_hw = { + .port_msiaddr = PORT_T602X_MSIADDR, + .port_msiaddr_hi = PORT_T602X_MSIADDR_HI, + .port_perst = PORT_T602X_PERST, + .port_rid2sid = PORT_T602X_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .max_rid2sid = 64, + .retain_clocks = true, + .adopt_link = true, +}; + +#define T6050_ROUTE(rid, sid) (PORT_RID2SID_VALID | \ + ((sid) << PORT_RID2SID_SID_SHIFT) | (rid)) + static const struct hw_info t8103_pciec_hw = { .port_msiaddr = PORT_MSIADDR, .port_perst = PORT_PERST, @@ -456,6 +475,10 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; + bool adopted_route; + void __iomem *intr2axi; /* adopt_link: this port's */ + u16 adopted_rid; /* adopt_link: secondary bus << 8 */ + u32 adopted_sid; }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -767,9 +790,20 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) struct apple_pcie *pcie = port->pcie; u32 val = 0; - /* FIXME: consider moving each interrupt under each port */ - port->irq = irq_of_parse_and_map(to_of_node(dev_fwnode(port->pcie->dev)), - port->idx); + if (pcie->hw->adopt_link) { + char name[16]; + int irq; + + snprintf(name, sizeof(name), "port%d", port->idx); + irq = of_irq_get_byname(pcie->dev->of_node, name); + + if (irq <= 0) + return irq ?: -ENXIO; + port->irq = irq; + } else { + /* FIXME: consider moving each interrupt under each port */ + port->irq = irq_of_parse_and_map(pcie->dev->of_node, port->idx); + } if (!port->irq) return -ENXIO; @@ -782,6 +816,9 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) return -ENOMEM; } + if (pcie->hw->adopt_link) + apple_pcie_port_writel(port, 0, PORT_MSICFG); + /* Disable all interrupts */ apple_pcie_port_writel(port, ~0, PORT_INTMSK); apple_pcie_port_writel(port, ~0, PORT_INTSTAT); @@ -815,7 +852,22 @@ static int apple_pcie_port_setup_irq(struct apple_pcie_port *port) val = ilog2(pcie->nvecs) << PORT_MSICFG_L2MSINUM_SHIFT; } + if (pcie->hw->adopt_link) { + if (apple_pcie_port_readl(port, pcie->hw->port_msiaddr) != DOORBELL_ADDR || + apple_pcie_port_readl(port, pcie->hw->port_msiaddr_hi)) + return -EIO; + for (int i = 0; i < pcie->nvecs; i++) + if (apple_pcie_port_readl(port, pcie->hw->port_msimap + 4 * i) != + (PORT_MSIMAP_ENABLE | (pcie->msi_vector_base + i))) + return -EIO; + /* Enable command is not readable; +0x84 is only a completion read. */ + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + readl(port->intr2axi + 0x84); + } apple_pcie_port_writel(port, val | PORT_MSICFG_EN, PORT_MSICFG); + if (pcie->hw->adopt_link && + !(apple_pcie_port_readl(port, PORT_MSICFG) & PORT_MSICFG_EN)) + return -EIO; return 0; } @@ -831,6 +883,8 @@ static irqreturn_t apple_pcie_port_irq(int irq, void *data) complete_all(&port->pcie->event); break; case PORT_INT_LINK_DOWN: + if (port->pcie->hw->adopt_link) + WRITE_ONCE(port->link_failed, true); /* A later link-up alone does not prove downstream state survived. */ if (port->pcie->hw->tunneled && READ_ONCE(port->started)) { WRITE_ONCE(port->link_failed, true); @@ -1509,9 +1563,18 @@ static void apple_pcie_port_teardown(struct apple_pcie_port *port) apple_pcie_port_disable_irq(port); /* Busy managed admission has not acquired or programmed this IRQ block. */ - if (port->base && (!port->pcie->managed_sids || port->domain)) + if (port->base && + (port->domain || + (!port->pcie->managed_sids && !port->pcie->hw->adopt_link))) apple_pcie_port_writel(port, ~0, PORT_INTMSK); + if (port->pcie->hw->adopt_link && port->domain) + apple_pcie_port_writel(port, 0, PORT_MSICFG); + if (port->adopted_route) { + apple_pcie_rid2sid_write(port, port->adopted_sid, 0); + port->adopted_route = false; + } + if (port->pcie->hw->tunneled && (port->started || port->needs_stop)) apple_pcie_tunnel_stop(port); @@ -1595,6 +1658,134 @@ static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port, return apple_pcie_port_readl(port, offset); } +/* + * Qualified J775D handoff of one bootloader-trained port: its root port + * 00:.0 and the single endpoint on its secondary bus, with DMA and + * endpoint MSI disabled. Every resource comes from the DT by the port's index + * (port, phy, intr2axi, interrupt port, the iommu-map entry for the + * endpoint's RID). All checks precede the first PCIe register write. + */ +static int apple_pcie_adopt_link(struct apple_pcie_port *port) +{ + static const char *const names[] = { "port%d", "phy%d", "intr2axi%d" }; + struct apple_pcie *pcie = port->pcie; + struct platform_device *pdev = to_platform_device(pcie->dev); + struct of_phandle_args iommu = {}; + void __iomem *rp, *ep; + char name[16]; + u32 value, bus; + u8 cap; + bool msi = false; + int ret, i; + + if (pcie->cfg->busr.start != 0 || + !platform_get_resource_byname(pdev, IORESOURCE_MEM, "config") || + !platform_get_resource_byname(pdev, IORESOURCE_MEM, "rc")) + return -EINVAL; + for (i = 0; i < ARRAY_SIZE(names); i++) { + snprintf(name, sizeof(name), names[i], port->idx); + if (!platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) + return -EINVAL; + } + + if (!(readl(pcie->base + CORE_RC_CTL) & CORE_RC_CTL_RUN) || + !(readl(pcie->base + CORE_RC_STAT) & CORE_RC_STAT_READY) || + !(apple_pcie_port_readl(port, PORT_STATUS) & PORT_STATUS_READY) || + (apple_pcie_port_readl(port, PORT_LINKSTS) & + (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP || + !(apple_pcie_port_readl(port, PORT_LTSSMCTL) & PORT_LTSSMCTL_START) || + (apple_pcie_port_readl(port, PORT_APPCLK) & 0x101) != 0x101 || + (apple_pcie_port_readl(port, pcie->hw->port_perst) & 0x10001) != 1 || + (readl(port->phy + PHY_LANE_CFG) & 0x1000061f) != 0x60f) + return -ENOLINK; + + /* The bootloader numbered the root port's buses: primary 0, one secondary. */ + rp = pcie->cfg->win + (PCI_DEVFN(port->idx, 0) << 12); + value = readl(rp + PCI_PRIMARY_BUS); + bus = (value >> 8) & 0xff; + if (readl(rp) != 0x100c106b || (value & 0xff) != 0 || !bus || + ((value >> 16) & 0xff) != bus || bus > pcie->cfg->busr.end || + (readw(rp + PCI_BRIDGE_CONTROL) & PCI_BRIDGE_CTL_BUS_RESET)) + return -ENODEV; + ep = pcie->cfg->win + (bus << 20); + value = readl(ep); + if (value == 0xffffffff || !(value & 0xffff) || + (readb(ep + PCI_HEADER_TYPE) & 0x7f) != PCI_HEADER_TYPE_NORMAL || + (readw(ep + PCI_COMMAND) & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | + PCI_COMMAND_MASTER))) + return -ENODEV; + + port->adopted_rid = bus << 8; + ret = of_map_iommu_id(pcie->dev->of_node, port->adopted_rid, &iommu); + if (ret) + return ret; + ret = iommu.args_count == 1 && iommu.args[0] && + iommu.args[0] < pcie->hw->max_rid2sid && + of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; + port->adopted_sid = iommu.args[0]; + of_node_put(iommu.np); + if (ret) + return ret; + + snprintf(name, sizeof(name), "intr2axi%d", port->idx); + port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); + if (IS_ERR(port->intr2axi)) + return PTR_ERR(port->intr2axi); + + /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ + cap = readb(rp + PCI_CAPABILITY_LIST); + for (i = 0; cap && i < 48; i++) { + if (cap < 0x40 || (cap & 3)) + return -EINVAL; + if (readb(rp + cap + PCI_CAP_LIST_ID) == PCI_CAP_ID_EXP) + break; + cap = readb(rp + cap + PCI_CAP_LIST_NEXT); + } + if (!cap || i == 48) + return -EINVAL; + value = readw(rp + cap + PCI_EXP_LNKSTA); + if ((value & (PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != + (PCI_EXP_LNKSTA_CLS_8_0GB | (1 << PCI_EXP_LNKSTA_NLW_SHIFT))) + return -ENOLINK; + + /* Refuse an active endpoint or malformed capability chain. */ + cap = readb(ep + PCI_CAPABILITY_LIST); + for (i = 0; cap && i < 48; i++) { + if (cap < 0x40 || (cap & 3)) + return -EINVAL; + value = readw(ep + cap + PCI_MSI_FLAGS); + switch (readb(ep + cap + PCI_CAP_LIST_ID)) { + case PCI_CAP_ID_MSI: + if (value & PCI_MSI_FLAGS_ENABLE) + return -EBUSY; + msi = true; + break; + case PCI_CAP_ID_MSIX: + if (value & PCI_MSIX_FLAGS_ENABLE) + return -EBUSY; + msi = true; + break; + } + cap = readb(ep + cap + PCI_CAP_LIST_NEXT); + } + if (cap || !msi) + return -EINVAL; + + for (i = 0; i < pcie->hw->max_rid2sid; i++) + if (apple_pcie_port_readl(port, port_rid2sid_offset(port, i)) & + PORT_RID2SID_VALID) + return -EBUSY; + + /* The route goes in the slot whose index is the SID, as on J775D's adopted ports. */ + value = T6050_ROUTE(port->adopted_rid, port->adopted_sid); + port->adopted_route = true; + if (apple_pcie_rid2sid_write(port, port->adopted_sid, value) != value) + return -EIO; + dev_info(pcie->dev, "adopted port %d, RID %04x -> SID %u, slot %u\n", + port->idx, port->adopted_rid, port->adopted_sid, port->adopted_sid); + return 0; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) @@ -1881,6 +2072,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, goto err_teardown; } } + } else if (pcie->hw->adopt_link) { + ret = apple_pcie_adopt_link(port); + if (ret) + goto err_teardown; } else { if (pcie->hw->retain_clocks) rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK); @@ -1922,9 +2117,8 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, if (ret) goto err_teardown; - if (pcie->managed_sids) { + if (pcie->managed_sids || pcie->hw->adopt_link) goto rid2sid_ready; - } /* Reset all RID/SID mappings, and check for RAZ/WI registers */ for (i = 0; i < pcie->hw->max_rid2sid; i++) { @@ -1949,6 +2143,10 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie, unsigned long timeout, left = 0; int attempt, attempts = 1; + if (pcie->hw->adopt_link) { + ret = -ENOLINK; + goto err_teardown; + } if (pcie->hw->tunneled) { if (pcie->kernel_init) { apple_pcie_tunnel_apply_tunable(port->base, @@ -2095,6 +2293,17 @@ static int apple_msi_init(struct apple_pcie *pcie) return ret; } + if (pcie->hw->adopt_link) { + ret = of_property_read_u32(to_of_node(fwnode), "apple,msi-vector-base", + &pcie->msi_vector_base); + if (ret || pcie->msi_vector_base != 64 || + (pcie->nvecs != 32 && pcie->nvecs != 64) || + args.args_count != 4 || args.args[0] != 0 || args.args[1] != 0 || + args.args[2] != 1888 || args.args[3] != IRQ_TYPE_EDGE_RISING || + DOORBELL_ADDR != 0xfffff000) + goto invalid_slice; + } + /* * The controller-wide ADT count (512) is not a per-host allocation. * Internal PCIe owns vectors 0..31. Each PCIe-C bridge owns a distinct @@ -2218,7 +2427,7 @@ static int apple_msi_init(struct apple_pcie *pcie) invalid_slice: of_node_put(args.np); return dev_err_probe(pcie->dev, -EINVAL, - "invalid or missing PCIe-C MSI slice\n"); + "invalid or missing MSI slice\n"); } static void apple_pcie_cleanup(void *data) @@ -2419,6 +2628,11 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d of_node_put(iommu_spec.np); sid = iommu_spec.args[0]; + if (pcie->hw->adopt_link) + return rid == port->adopted_rid && sid == port->adopted_sid && + !READ_ONCE(port->link_failed) && + apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)) == + T6050_ROUTE(rid, sid) ? 0 : -ENODEV; mutex_lock(&port->pcie->lock); if (port->pcie->managed_sids || port->pcie->hw->sid_indexed_rid2sid) { @@ -2485,7 +2699,7 @@ static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci int idx; port = apple_pcie_get_port(pdev); - if (!port) + if (!port || port->pcie->hw->adopt_link) return; mutex_lock(&port->pcie->lock); @@ -2526,9 +2740,13 @@ static int apple_pcie_init(struct pci_config_window *cfg) ret = apple_pcie_setup_port(pcie, of_port); if (ret) { dev_err(dev, "Port %pOF setup fail: %d\n", of_port, ret); - return ret; + /* Adopted ports are independent: one refused leaves the others. */ + if (!pcie->hw->adopt_link) + return ret; } } + if (pcie->hw->adopt_link && list_empty(&pcie->ports)) + return -ENODEV; /* The bus scan follows this callback. */ apple_pcie_tunnel_wait_ready(pcie); @@ -2548,6 +2766,27 @@ static void __iomem *apple_pcie_map_bus(struct pci_bus *bus, struct apple_pcie *pcie = apple_pcie_lookup(cfg->parent); struct apple_pcie_port *port; + if (pcie->hw->adopt_link) { + /* Only adopted ports' root ports, and the one endpoint behind each. */ + list_for_each_entry(port, &pcie->ports, entry) { + if (bus->number == 0) { + if (devfn == PCI_DEVFN(port->idx, 0)) + return pci_ecam_map_bus(bus, devfn, where); + continue; + } + if (bus->number != port->adopted_rid >> 8) + continue; + if (devfn || READ_ONCE(port->link_failed)) + return NULL; + if ((apple_pcie_port_readl(port, PORT_LINKSTS) & + (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP) { + WRITE_ONCE(port->link_failed, true); + return NULL; + } + return pci_ecam_map_bus(bus, devfn, where); + } + return NULL; + } if (!pcie->hw->root_bus_only) return pci_ecam_map_bus(bus, devfn, where); @@ -3121,7 +3360,22 @@ static int apple_pcie_probe(struct platform_device *pdev) * reset-gpios provider here rejects the valid synthesized port before * the tunneled setup path can consume that handoff. */ - if (!hw->tunneled) { + if (hw->adopt_link) { + if (!of_get_available_child_count(dev->of_node) || + of_property_present(dev->of_node, "power-domains")) + return -EINVAL; + for_each_available_child_of_node_scoped(dev->of_node, child) { + u32 reg; + + /* A root port 00:.0 on bus 0, n a GP port */ + if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || + !(reg >> 11) || (reg >> 11) > 3 || + !of_property_read_bool(child, "apple,link-trained-by-bootloader") || + of_property_present(child, "reset-gpios") || + of_property_present(child, "pwren-gpios")) + return -EINVAL; + } + } else if (!hw->tunneled) { /* Check for probe dependencies for all ports first */ for_each_available_child_of_node(dev->of_node, of_port) { ret = apple_pcie_probe_port(of_port); @@ -3164,15 +3418,15 @@ static int apple_pcie_probe(struct platform_device *pdev) return ret; } pcie->piodma_supplier = piodma_supplier; - /* Only this retained-DMA radio hierarchy forbids user reset/removal. */ - if (piodma_supplier || pcie->managed_sids) { + /* Firmware-owned links cannot be recovered by user reset/removal. */ + if (piodma_supplier || pcie->managed_sids || hw->adopt_link) { bridge->no_user_remove = true; bridge->reset_sensitive = true; bridge->native_pcie_hotplug = false; bridge->native_shpc_hotplug = false; bridge->native_aer = false; bridge->native_dpc = false; - dev_dbg(dev, "radio host: automatic AER/DPC recovery disabled for retained DMA\n"); + dev_dbg(dev, "firmware-owned host: automatic AER/DPC recovery disabled\n"); } if (hw->root_bus_only && !piodma_supplier) dev_info(dev, "root-port probe only; downstream config is blocked\n"); @@ -3952,6 +4206,8 @@ static int apple_pcie_suspend_noirq(struct device *dev) */ if (pcie->managed_sids) return pm_suspend_target_state == PM_SUSPEND_TO_IDLE ? 0 : -EBUSY; + if (pcie->hw->adopt_link) + return -EBUSY; if (!pcie->hw->tunneled) return 0; pcie->reset_on_resume = false; @@ -4095,6 +4351,7 @@ static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t8152-pcie", .data = &t8152_hw }, { .compatible = "apple,t6020-pcie", .data = &t602x_hw }, { .compatible = "apple,t8140-pcie", .data = &t8140_hw }, + { .compatible = "apple,t6050-pcie", .data = &t6050_hw }, { .compatible = "apple,pcie", .data = &t8103_hw }, { } }; From 3bb54de2de84878e43f60f4192e25ae5a702700e Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:16 -0400 Subject: [PATCH 186/342] PCI: Add pci_trylock_rescan_remove() A driver's work item that rescans or resets part of a bus takes the rescan/remove lock. When the device is being removed, the remover holds that lock while it cancels the work, so a worker that blocks on the lock deadlocks against its own cancellation. Add pci_trylock_rescan_remove(), which takes the rescan/remove lock only if it is free. A worker that cannot get it returns and retries later, and the remover's cancellation completes. Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/probe.c | 7 +++++++ include/linux/pci.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 27008e2ea5afc..d625dd5e778a8 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3517,6 +3517,13 @@ void pci_lock_rescan_remove(void) } EXPORT_SYMBOL_GPL(pci_lock_rescan_remove); +/* Work cancelled by removal must not wait on the remover's own lock. */ +bool pci_trylock_rescan_remove(void) +{ + return mutex_trylock(&pci_rescan_remove_lock); +} +EXPORT_SYMBOL_GPL(pci_trylock_rescan_remove); + void pci_unlock_rescan_remove(void) { mutex_unlock(&pci_rescan_remove_lock); diff --git a/include/linux/pci.h b/include/linux/pci.h index 5cec6d838b3f7..c0d76d93a78f5 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1559,6 +1559,7 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev); /* Functions for PCI Hotplug drivers to use */ unsigned int pci_rescan_bus(struct pci_bus *bus); void pci_lock_rescan_remove(void); +bool pci_trylock_rescan_remove(void); void pci_unlock_rescan_remove(void); /* Vital Product Data routines */ From d3ea57796c57270272dd218f2e5ba182158d438f Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 20:45:53 -0500 Subject: [PATCH 187/342] PCI: apple: Add the T6050 port reset, enable, configure and train sequences An adopted T6050 port is left as the boot loader trained it, but an endpoint that has to come back on a retrained link (the N1 on port 0, after its ROM boot) needs the host to take the port down and bring it up again. Add the sequences for that, on the port's own register blocks (port, phy and intr2axi) and the root port's config space: - Disable: wait for the link to leave L1 and go idle, assert the port's PERST# through its handshake, then stop the lane clocks and the port's application clock. - Enable: the port reset table, which also clears the RID2SID and MSI map tables, the port's tunables, then the application clock and the PERST# release handshake, until the port is ready and its link idle. - Configure: with the root complex's read-only registers opened, its tunables and the per-rate shadow tunables, then a Gen3 x1 link (target speed, link width and capability) and a directed speed change; Intr2AXI enabled. - Train: the lane's reference clocks, the endpoint's PERST# released through its pad, the LTSSM started, then the 100 ms wait after link up. The tunables are the lists the boot loader copies onto the root port node, groups of (offset, 4, mask, value); a list it did not copy is skipped. The root-port reset that runs the sequences follows; until then they are marked __maybe_unused. Co-developed-by: Dj Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 340 ++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index b0a4a549cdd9e..521bc1738ae39 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -186,6 +186,20 @@ MODULE_PARM_DESC(link_up_timeout, "PCIe link training timeout in milliseconds"); #define PORT_MSIMAP_ENABLE BIT(31) #define PORT_MSIMAP_TARGET GENMASK(7, 0) +/* T6050: the root port's port logic, laid out as DesignWare's */ +#define RC_T6050_PORT_LINK_CTRL 0x710 +#define RC_T6050_LINK_MODE GENMASK(21, 16) +#define RC_T6050_PORT_DEBUG0 0x728 +#define RC_T6050_LTSSM_STATE GENMASK(5, 0) +#define RC_T6050_LTSSM_L1_IDLE 0x14 +#define RC_T6050_LINK_WIDTH_SPEED_CTRL 0x80c +#define RC_T6050_LINK_WIDTH GENMASK(12, 8) +#define RC_T6050_SPEED_CHANGE BIT(17) +#define RC_T6050_GEN3_RELATED 0x890 +#define RC_T6050_RATE_SHADOW_SEL GENMASK(25, 24) +#define RC_T6050_MISC_CONTROL_1 0x8bc +#define RC_T6050_DBI_RO_WR_EN BIT(0) + /* * The doorbell address must be in the bottom 4GB because the base register * is only 32 bits wide. Exclude it from the IOVA range and share the same @@ -479,6 +493,7 @@ struct apple_pcie_port { void __iomem *intr2axi; /* adopt_link: this port's */ u16 adopted_rid; /* adopt_link: secondary bus << 8 */ u32 adopted_sid; + void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -1786,6 +1801,331 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) return 0; } +/* + * T6050 port bring-up, for an adopted port whose endpoint must come back on a + * retrained link: port disable, the port reset table, port enable, root complex + * configuration for Gen3 x1, then the lane PHY, PERST# and the LTSSM. The port's + * registers are its port, phy and intr2axi blocks; the root complex's + * are the root port's config space. The boot loader copies the port's tunables + * onto its node. + */ +static const struct apple_pcie_reset_reg apple_pcie_t6050_reset_regs[] = { + { 0x088, 0x00000110 }, + { 0x100, 0xffffffff }, + { 0x148, 0xffffffff }, + { 0x210, 0xffffffff }, + { 0x080, 0x00000000 }, + { 0x084, 0x00000000 }, + { 0x104, 0xfffffff0 }, + { 0x124, 0x00000100 }, + { 0x16c, 0x00000000 }, + { 0x13c, 0x00000000 }, + { 0x800, 0x00100100 }, + { 0x808, 0x001001ff }, + { 0x82c, 0x00010000 }, +}; + +/* Written after the RID2SID and MSI map tables are cleared */ +static const struct apple_pcie_reset_reg apple_pcie_t6050_reset_regs_late[] = { + { 0x130, 0x03020000 }, + { 0x140, 0x00000010 }, + { 0x144, 0x00253770 }, + { 0x21c, 0x00000000 }, + { 0x834, 0x00000000 }, + { 0x83c, 0x00000000 }, +}; + +static void apple_pcie_t6050_rmw(void __iomem *addr, u32 clear, u32 set) +{ + writel((readl(addr) & ~clear) | set, addr); +} + +static int apple_pcie_t6050_rc_rmw(struct pci_dev *rp, int where, u32 clear, u32 set) +{ + u32 value; + int ret; + + ret = pci_read_config_dword(rp, where, &value); + if (!ret) + ret = pci_write_config_dword(rp, where, (value & ~clear) | set); + return pcibios_err_to_errno(ret); +} + +static int apple_pcie_t6050_wait(struct apple_pcie_port *port, void __iomem *base, + u32 offset, u32 mask, u32 value, unsigned int timeout_us) +{ + u32 stat; + int ret; + + ret = readl_poll_timeout(base + offset, stat, (stat & mask) == value, 1, timeout_us); + if (ret) + dev_err(port->pcie->dev, "port %d: %#x = %#x, waiting for %#x/%#x\n", + port->idx, offset, stat, value, mask); + return ret; +} + +/* + * A tunable list the boot loader copies onto the root port node, groups of + * (offset, 4, mask, value): for the port's registers, or with @rp for the root + * port's config space. A list it did not copy is skipped. + */ +static int apple_pcie_t6050_tune(struct apple_pcie_port *port, struct pci_dev *rp, + const char *name) +{ + u32 cells[64]; + int count, ret, i; + + if (!of_property_present(port->np, name)) + return 0; + count = of_property_count_u32_elems(port->np, name); + if (count <= 0 || count > ARRAY_SIZE(cells) || count % 4) + return -EINVAL; + ret = of_property_read_u32_array(port->np, name, cells, count); + if (ret) + return ret; + for (i = 0; i < count; i += 4) + if (cells[i + 1] != 4 || (cells[i] & 3) || + cells[i] >= (rp ? PCI_CFG_SPACE_EXP_SIZE : SZ_16K)) + return -EINVAL; + + for (i = 0; i < count; i += 4) { + if (!rp) { + apple_pcie_t6050_rmw(port->base + cells[i], cells[i + 2], cells[i + 3]); + continue; + } + ret = apple_pcie_t6050_rc_rmw(rp, cells[i], cells[i + 2], cells[i + 3]); + if (ret) + return ret; + } + return 0; +} + +/* PERST# through its pad: a GPIO output (function bits cleared) at the level asked for */ +static int apple_pcie_t6050_perst(struct apple_pcie_port *port, bool asserted) +{ + u32 old, value; + + old = readl(port->perst); + if (old & BIT(21)) + return -EIO; + value = (old & ~0x27f) | 0x202 | !asserted; + /* The input enable (bit 9) goes on after the rest */ + writel((value & ~0x200) | (old & 0x200), port->perst); + if (!(old & 0x200)) + writel(value, port->perst); + return (readl(port->perst) ^ value) & 0x27f ? -EIO : 0; +} + +/* Let the link go idle, hold the endpoint in reset and stop the port and its lane clocks */ +static int apple_pcie_t6050_port_disable(struct apple_pcie_port *port, struct pci_dev *rp) +{ + void __iomem *perst = port->base + PORT_T602X_PERST; + void __iomem *lane = port->phy + PHY_LANE_CFG; + u32 stat; + int ret, err; + + if (!(readl(port->base + PORT_STATUS) & BIT(2))) { + ret = apple_pcie_t6050_wait(port, port->base, 0x820, BIT(2), BIT(2), 10000); + if (ret) + return ret; + } + ret = readl_poll_timeout_atomic(port->base + 0x820, stat, + !(stat & GENMASK(8, 0)) || !(stat & GENMASK(23, 16)), + 1, 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + 0x13c, 0, BIT(8)); + + /* The link out of L1 */ + ret = read_poll_timeout_atomic(pci_read_config_dword, err, + err || FIELD_GET(RC_T6050_LTSSM_STATE, stat) != + RC_T6050_LTSSM_L1_IDLE, + 5, 5000, false, rp, RC_T6050_PORT_DEBUG0, &stat); + if (ret || err) + return ret ?: pcibios_err_to_errno(err); + + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(0), BIT(0), 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, BIT(24)); + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(16), BIT(16), 2000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, BIT(16)); + udelay(1); + apple_pcie_t6050_rmw(perst, PORT_PERST_OFF, 0); + udelay(1); + apple_pcie_t6050_rmw(perst, BIT(24), 0); + apple_pcie_t6050_rmw(port->base + 0x13c, BIT(8), 0); + + apple_pcie_t6050_rmw(lane, BIT(31), 0); + apple_pcie_t6050_rmw(lane, BIT(10), 0); + apple_pcie_t6050_rmw(lane, BIT(9), 0); + apple_pcie_t6050_rmw(lane, 0, BIT(4)); + apple_pcie_t6050_rmw(lane, PHY_LANE_CFG_REFCLK0REQ, 0); + apple_pcie_t6050_rmw(lane, PHY_LANE_CFG_REFCLK1REQ, 0); + + writel(~0, port->base + PORT_INTSTAT); + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, PORT_APPCLK_EN, 0); + return apple_pcie_t6050_wait(port, port->base, PORT_STATUS, PORT_STATUS_READY, 0, + 250000); +} + +/* The port reset table, then the port clocked and out of reset, ready to train */ +static int apple_pcie_t6050_port_enable(struct apple_pcie_port *port) +{ + void __iomem *perst = port->base + PORT_T602X_PERST; + u32 stat; + int ret, i; + + for (i = 0; i < ARRAY_SIZE(apple_pcie_t6050_reset_regs); i++) + writel(apple_pcie_t6050_reset_regs[i].value, + port->base + apple_pcie_t6050_reset_regs[i].offset); + for (i = 0; i < port->pcie->hw->max_rid2sid; i++) + writel(0, port->base + port_rid2sid_offset(port, i)); + for (i = 0; i < 256; i++) + writel(0, port->base + PORT_T602X_MSIMAP + 4 * i); + for (i = 0; i < ARRAY_SIZE(apple_pcie_t6050_reset_regs_late); i++) + writel(apple_pcie_t6050_reset_regs_late[i].value, + port->base + apple_pcie_t6050_reset_regs_late[i].offset); + + if (!(readl(perst) & BIT(16))) + return -EIO; + ret = apple_pcie_t6050_tune(port, NULL, "apple,apcie-config-tunables"); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, 0, PORT_APPCLK_EN); + + ret = readl_poll_timeout_atomic(port->base + 0xa8, stat, + (stat & (BIT(16) | BIT(0))) != (BIT(16) | BIT(0)), + 1, 10000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, 0, PORT_PERST_OFF); + ret = apple_pcie_t6050_wait(port, port->base, 0xa8, BIT(0), BIT(0), 20000); + if (ret) + return ret; + apple_pcie_t6050_rmw(perst, BIT(16), 0); + ret = apple_pcie_t6050_wait(port, port->base, PORT_STATUS, PORT_STATUS_READY, + PORT_STATUS_READY, 250000); + if (ret) + return ret; + + apple_pcie_t6050_rmw(port->base + PORT_APPCLK, 0, PORT_APPCLK_CGDIS); + return apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, PORT_LINKSTS_BUSY, 0, + 250000); +} + +/* Root complex tunables and a Gen3 x1 link, with the read-only registers opened for it */ +static int apple_pcie_t6050_port_configure(struct apple_pcie_port *port, struct pci_dev *rp) +{ + static const char * const shadow[] = { + "apple,pcie-rc-gen3-shadow-tunables", + "apple,pcie-rc-gen4-shadow-tunables", + "apple,pcie-rc-gen5-shadow-tunables", + }; + static const u32 shadow_sel[] = { 0, BIT(24), 0 }; + int cap = pci_pcie_cap(rp); + u32 value; + u16 ctl2; + int ret, err, i; + + if (!cap) + return -EIO; + ret = apple_pcie_t6050_rc_rmw(rp, RC_T6050_MISC_CONTROL_1, 0, RC_T6050_DBI_RO_WR_EN); + if (ret) + return ret; + ret = apple_pcie_t6050_tune(port, rp, "apple,pcie-rc-tunables"); + if (ret) + goto lock; + for (i = 0; i < ARRAY_SIZE(shadow); i++) { + ret = apple_pcie_t6050_rc_rmw(rp, RC_T6050_GEN3_RELATED, + RC_T6050_RATE_SHADOW_SEL, shadow_sel[i]) ?: + apple_pcie_t6050_tune(port, rp, shadow[i]); + if (ret) + goto lock; + } + ret = apple_pcie_t6050_rc_rmw(rp, 0x194, 0, BIT(0)); + if (ret) + goto lock; + + ret = pcibios_err_to_errno(pci_read_config_dword(rp, cap + PCI_EXP_LNKCAP2, &value)); + if (ret) + goto lock; + if (!(value & PCI_EXP_LNKCAP2_SLS_8_0GB)) { + ret = -EIO; + goto lock; + } + ret = pcibios_err_to_errno(pci_read_config_word(rp, cap + PCI_EXP_LNKCTL2, &ctl2)) ?: + pcibios_err_to_errno(pci_write_config_word(rp, cap + PCI_EXP_LNKCTL2, + (ctl2 & ~PCI_EXP_LNKCTL2_TLS) | + PCI_EXP_LNKCTL2_TLS_8_0GT)) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_PORT_LINK_CTRL, RC_T6050_LINK_MODE, + FIELD_PREP(RC_T6050_LINK_MODE, 1)) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_LINK_WIDTH_SPEED_CTRL, RC_T6050_LINK_WIDTH, + FIELD_PREP(RC_T6050_LINK_WIDTH, 1)) ?: + apple_pcie_t6050_rc_rmw(rp, cap + PCI_EXP_LNKCAP, PCI_EXP_LNKCAP_MLW, + FIELD_PREP(PCI_EXP_LNKCAP_MLW, 1)); +lock: + err = apple_pcie_t6050_rc_rmw(rp, RC_T6050_MISC_CONTROL_1, RC_T6050_DBI_RO_WR_EN, 0); + ret = ret ?: err; + if (ret) + return ret; + + ret = apple_pcie_t6050_rc_rmw(rp, cap + PCI_EXP_LNKCTL, 0, PCI_EXP_LNKCTL_LBMIE) ?: + apple_pcie_t6050_rc_rmw(rp, RC_T6050_LINK_WIDTH_SPEED_CTRL, 0, RC_T6050_SPEED_CHANGE); + if (ret) + return ret; + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + return 0; +} + +/* Disable, reset, enable and configure an adopted port whose endpoint is held in PERST# */ +static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port *port, + struct pci_dev *rp) +{ + return apple_pcie_t6050_port_disable(port, rp) ?: + apple_pcie_t6050_port_enable(port) ?: + apple_pcie_t6050_port_configure(port, rp); +} + +/* Lane clocks, PERST# released, then the LTSSM to link up */ +static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *port) +{ + void __iomem *lane = port->phy + PHY_LANE_CFG; + int ret; + + apple_pcie_t6050_rmw(lane, 0, PHY_LANE_CFG_REFCLK0REQ); + ret = apple_pcie_t6050_wait(port, port->phy, PHY_LANE_CFG, PHY_LANE_CFG_REFCLK0ACK, + PHY_LANE_CFG_REFCLK0ACK, 500000); + if (ret) + return ret; + apple_pcie_t6050_rmw(lane, 0, PHY_LANE_CFG_REFCLK1REQ); + ret = apple_pcie_t6050_wait(port, port->phy, PHY_LANE_CFG, PHY_LANE_CFG_REFCLK1ACK, + PHY_LANE_CFG_REFCLK1ACK, 500000); + if (ret) + return ret; + apple_pcie_t6050_rmw(lane, BIT(4), 0); + udelay(1); + apple_pcie_t6050_rmw(lane, 0, BIT(9)); + apple_pcie_t6050_rmw(lane, 0, BIT(10)); + + /* Tperst-clk is at least 100 us (PCIe CEM r5.0, 2.9.2) */ + usleep_range(100, 110); + ret = apple_pcie_t6050_perst(port, false); + if (ret) + return ret; + apple_pcie_t6050_rmw(port->base + PORT_LTSSMCTL, 0, PORT_LTSSMCTL_START); + ret = apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, PORT_LINKSTS_UP, + PORT_LINKSTS_UP, 500000); + if (ret) + return ret; + + /* Wait for 100ms after the link trains (PCIe r5.0, 6.6.1) */ + msleep(100); + return 0; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) From 554bacbb3baa639642aef86ae09c2adfe4e07f24 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 188/342] PCI: apple: Adopt T6050 port 0's multi-function N1 and reset its root port The N1 Wi-Fi/Bluetooth sits on apcie0 port 0, which the bootloader now trains like ports 2 and 3. Two things the adoption assumed do not hold for it: - It is multi-function. In its ROM personality only function 0 answers; after its firmware starts, Control, Alpha and Beta (0-2) do. Each function's RID is routed to its own DART stream from the iommu-map (slot == SID) when it is enabled, instead of the one route set at adoption; config accesses on the adopted bus reach every function of device 0; teardown clears every slot it routed. Port 0 is accepted. - Its ROM links at Gen1. Adoption takes an x1 link at Gen1 to Gen3 (the bootloader's target), not only Gen3; the endpoint picks the speed. - After the ROM boot it must come back on a retrained link. The host provides reset_root_port for an adopted port that names its PERST# pad (perst): PME_Turn_Off to L2, PERST#, then the T6050 port disable, reset, enable, configure and train sequences, with the routes and the MSI map rewritten in between. Tunables the boot loader copied onto the root port node are applied; absent ones are skipped. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 9 +- drivers/pci/controller/pcie-apple.c | 218 ++++++++++++++---- 2 files changed, 184 insertions(+), 43 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 5823cc0ff837a..2446facb91d3a 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -242,15 +242,16 @@ allOf: properties: reg: minItems: 5 - maxItems: 14 + maxItems: 18 reg-names: description: config and rc, then port, phy and intr2axi for each - bootloader-trained root port 00:.0. + bootloader-trained root port 00:.0, and perst (its PERST# + pad) for a port whose endpoint needs a root-port reset. minItems: 5 - maxItems: 14 + maxItems: 18 items: - pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" + pattern: "^(config|rc|(port|phy|intr2axi|perst)[0-3])$" interrupts: maxItems: 4 interrupt-names: diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 521bc1738ae39..9a99347476bc4 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -489,14 +489,14 @@ struct apple_pcie_port { bool needs_stop; bool link_failed; bool irq_disabled; - bool adopted_route; void __iomem *intr2axi; /* adopt_link: this port's */ - u16 adopted_rid; /* adopt_link: secondary bus << 8 */ - u32 adopted_sid; + u8 adopted_bus; /* adopt_link: the secondary bus */ + unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); +static struct apple_pcie *apple_pcie_lookup(struct device *dev); static int apple_pcie_radio_check_cold(struct apple_pcie_port *port); static void rmw_set(u32 set, void __iomem *addr) @@ -1585,9 +1585,12 @@ static void apple_pcie_port_teardown(struct apple_pcie_port *port) if (port->pcie->hw->adopt_link && port->domain) apple_pcie_port_writel(port, 0, PORT_MSICFG); - if (port->adopted_route) { - apple_pcie_rid2sid_write(port, port->adopted_sid, 0); - port->adopted_route = false; + if (port->adopted_slots) { + int slot; + + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + apple_pcie_rid2sid_write(port, slot, 0); + port->adopted_slots = 0; } if (port->pcie->hw->tunneled && (port->started || port->needs_stop)) @@ -1673,9 +1676,60 @@ static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port, return apple_pcie_port_readl(port, offset); } +/* + * The DART stream an adopted port's function `rid` maps to: one T6050 DART stream, nonzero + * and below the RID2SID table size (slot == SID), from the host's iommu-map. + */ +static int apple_pcie_adopted_sid(struct apple_pcie_port *port, u32 rid, u32 *sid) +{ + struct apple_pcie *pcie = port->pcie; + struct of_phandle_args iommu = {}; + int ret; + + if (rid >> 8 != port->adopted_bus) { + /* The PCI core numbers root ports' buses in devfn order: the bootloader must too */ + dev_err(pcie->dev, "port %d: RID %04x is off bus %02x, which the bootloader numbered\n", + port->idx, rid, port->adopted_bus); + return -ENODEV; + } + ret = of_map_iommu_id(pcie->dev->of_node, rid, &iommu); + if (ret) + return ret; + ret = iommu.args_count == 1 && iommu.args[0] && + iommu.args[0] < pcie->hw->max_rid2sid && + iommu.args[0] < BITS_PER_LONG && + of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; + *sid = iommu.args[0]; + of_node_put(iommu.np); + return ret; +} + +/* Route an adopted port's function `rid` to its stream, or confirm the route is in place. */ +static int apple_pcie_adopted_route(struct apple_pcie_port *port, u32 rid) +{ + u32 sid, value, cur; + int ret = apple_pcie_adopted_sid(port, rid, &sid); + + if (ret) + return ret; + value = T6050_ROUTE(rid, sid); + cur = apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)); + if (cur == value && test_bit(sid, &port->adopted_slots)) + return 0; + if (cur & PORT_RID2SID_VALID) + return -EBUSY; + set_bit(sid, &port->adopted_slots); + if (apple_pcie_rid2sid_write(port, sid, value) != value) + return -EIO; + dev_info(port->pcie->dev, "port %d: RID %04x -> SID %u, slot %u\n", + port->idx, rid, sid, sid); + return 0; +} + /* * Qualified J775D handoff of one bootloader-trained port: its root port - * 00:.0 and the single endpoint on its secondary bus, with DMA and + * 00:.0 and the endpoint on its secondary bus (function 0 routed here; a + * multi-function endpoint's other functions when they are enabled), with DMA and * endpoint MSI disabled. Every resource comes from the DT by the port's index * (port, phy, intr2axi, interrupt port, the iommu-map entry for the * endpoint's RID). All checks precede the first PCIe register write. @@ -1685,7 +1739,6 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) static const char *const names[] = { "port%d", "phy%d", "intr2axi%d" }; struct apple_pcie *pcie = port->pcie; struct platform_device *pdev = to_platform_device(pcie->dev); - struct of_phandle_args iommu = {}; void __iomem *rp, *ep; char name[16]; u32 value, bus; @@ -1730,15 +1783,8 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) PCI_COMMAND_MASTER))) return -ENODEV; - port->adopted_rid = bus << 8; - ret = of_map_iommu_id(pcie->dev->of_node, port->adopted_rid, &iommu); - if (ret) - return ret; - ret = iommu.args_count == 1 && iommu.args[0] && - iommu.args[0] < pcie->hw->max_rid2sid && - of_device_is_compatible(iommu.np, "apple,t6050-dart") ? 0 : -EINVAL; - port->adopted_sid = iommu.args[0]; - of_node_put(iommu.np); + port->adopted_bus = bus; + ret = apple_pcie_adopted_sid(port, bus << 8, &value); if (ret) return ret; @@ -1746,6 +1792,13 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); if (IS_ERR(port->intr2axi)) return PTR_ERR(port->intr2axi); + /* Only a port whose endpoint needs a root-port reset names its PERST# pad */ + snprintf(name, sizeof(name), "perst%d", port->idx); + if (platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) { + port->perst = devm_platform_ioremap_resource_byname(pdev, name); + if (IS_ERR(port->perst)) + return PTR_ERR(port->perst); + } /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ cap = readb(rp + PCI_CAPABILITY_LIST); @@ -1758,9 +1811,14 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) } if (!cap || i == 48) return -EINVAL; + /* + * x1 at up to the Gen3 target the bootloader set. The endpoint picks the speed: the N1's + * ROM personality links at Gen1 and comes back at Gen3 after its root-port reset. + */ value = readw(rp + cap + PCI_EXP_LNKSTA); - if ((value & (PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != - (PCI_EXP_LNKSTA_CLS_8_0GB | (1 << PCI_EXP_LNKSTA_NLW_SHIFT))) + if ((value & (PCI_EXP_LNKSTA_NLW | PCI_EXP_LNKSTA_LT)) != (1 << PCI_EXP_LNKSTA_NLW_SHIFT) || + (value & PCI_EXP_LNKSTA_CLS) < PCI_EXP_LNKSTA_CLS_2_5GB || + (value & PCI_EXP_LNKSTA_CLS) > PCI_EXP_LNKSTA_CLS_8_0GB) return -ENOLINK; /* Refuse an active endpoint or malformed capability chain. */ @@ -1792,13 +1850,10 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) return -EBUSY; /* The route goes in the slot whose index is the SID, as on J775D's adopted ports. */ - value = T6050_ROUTE(port->adopted_rid, port->adopted_sid); - port->adopted_route = true; - if (apple_pcie_rid2sid_write(port, port->adopted_sid, value) != value) - return -EIO; - dev_info(pcie->dev, "adopted port %d, RID %04x -> SID %u, slot %u\n", - port->idx, port->adopted_rid, port->adopted_sid, port->adopted_sid); - return 0; + ret = apple_pcie_adopted_route(port, bus << 8); + if (!ret) + dev_info(pcie->dev, "adopted port %d, endpoint %02x:00\n", port->idx, bus); + return ret; } /* @@ -2081,8 +2136,7 @@ static int apple_pcie_t6050_port_configure(struct apple_pcie_port *port, struct } /* Disable, reset, enable and configure an adopted port whose endpoint is held in PERST# */ -static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port *port, - struct pci_dev *rp) +static int apple_pcie_t6050_port_restart(struct apple_pcie_port *port, struct pci_dev *rp) { return apple_pcie_t6050_port_disable(port, rp) ?: apple_pcie_t6050_port_enable(port) ?: @@ -2090,7 +2144,7 @@ static int __maybe_unused apple_pcie_t6050_port_restart(struct apple_pcie_port * } /* Lane clocks, PERST# released, then the LTSSM to link up */ -static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *port) +static int apple_pcie_t6050_port_train(struct apple_pcie_port *port) { void __iomem *lane = port->phy + PHY_LANE_CFG; int ret; @@ -2126,6 +2180,87 @@ static int __maybe_unused apple_pcie_t6050_port_train(struct apple_pcie_port *po return 0; } +/* + * Root-port reset of an adopted T6050 port, for an endpoint that must come back on a + * retrained link (the N1 after its ROM boot): PME_Turn_Off to L2, PERST# asserted, the + * port disabled, reset, enabled and configured, its routes and MSI map rewritten, then the + * lane PHY, PERST# release and LTSSM to a Gen3 x1 link. The caller has quiesced the + * endpoint and saved the root port's state; the PCI core restores it. + */ +static int apple_pcie_t6050_reset_root_port(struct pci_host_bridge *bridge, + struct pci_dev *rp) +{ + struct pci_config_window *cfg = rp->sysdata; + struct apple_pcie *pcie = apple_pcie_lookup(cfg->parent); + struct apple_pcie_port *port = NULL, *p; + u32 routes[BITS_PER_LONG], value; + int ret, slot, i; + + if (!pcie || !pcie->hw->adopt_link || !pci_is_root_bus(rp->bus)) + return -EOPNOTSUPP; + list_for_each_entry(p, &pcie->ports, entry) + if (p->idx == PCI_SLOT(rp->devfn)) + port = p; + if (!port || !port->perst || !port->intr2axi) + return -EOPNOTSUPP; + + mutex_lock(&pcie->lock); + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + routes[slot] = apple_pcie_port_readl(port, port_rid2sid_offset(port, slot)); + + /* Bridge decoding off and the secondary bus unnumbered while the link is down */ + ret = pcibios_err_to_errno(pci_write_config_word(rp, PCI_COMMAND, 0)) ?: + pcibios_err_to_errno(pci_read_config_dword(rp, PCI_PRIMARY_BUS, &value)) ?: + pcibios_err_to_errno(pci_write_config_dword(rp, PCI_PRIMARY_BUS, + value & 0xff0000ff)); + if (ret) + goto out; + /* PME_Turn_Off, then L2 */ + apple_pcie_port_writel(port, apple_pcie_port_readl(port, PORT_APPCLK) | 0x100, PORT_APPCLK); + apple_pcie_port_writel(port, 0x11, 0x88); + ret = apple_pcie_t6050_wait(port, port->base, 0x88, 1, 0, 500000) ?: + apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, BIT(6), BIT(6), 500000); + if (ret) + goto out; + WRITE_ONCE(port->link_failed, true); + ret = apple_pcie_t6050_perst(port, true); + if (ret) + goto out; + writel(readl(port->phy) & ~BIT(31), port->phy); + ret = apple_pcie_t6050_port_restart(port, rp); + if (ret) + goto out; + + /* The reset table cleared the routes and the MSI setup: put back what Linux set */ + for_each_set_bit(slot, &port->adopted_slots, BITS_PER_LONG) + if (apple_pcie_rid2sid_write(port, slot, routes[slot]) != routes[slot]) + ret = -EIO; + apple_pcie_port_writel(port, lower_32_bits(DOORBELL_ADDR), pcie->hw->port_msiaddr); + if (pcie->hw->port_msiaddr_hi) + apple_pcie_port_writel(port, 0, pcie->hw->port_msiaddr_hi); + for (i = 0; i < pcie->nvecs; i++) + apple_pcie_port_writel(port, FIELD_PREP(PORT_MSIMAP_TARGET, pcie->msi_vector_base + i) | + PORT_MSIMAP_ENABLE, pcie->hw->port_msimap + 4 * i); + writel(PCIEC_INTR2AXI_ENABLE, port->intr2axi + PCIEC_INTR2AXI_CTRL); + readl(port->intr2axi + 0x84); + apple_pcie_port_writel(port, PORT_MSICFG_EN, PORT_MSICFG); + if (ret) + goto out; + + ret = apple_pcie_t6050_port_train(port); + if (ret) + goto out; + /* Link interrupts stay masked after the reset table: the link is checked on access */ + apple_pcie_port_writel(port, ~0, PORT_INTSTAT); + WRITE_ONCE(port->link_failed, false); + dev_info(pcie->dev, "port %d: link retrained after a root-port reset\n", port->idx); +out: + mutex_unlock(&pcie->lock); + if (ret) + dev_err(pcie->dev, "port %d: root-port reset stopped: %d\n", port->idx, ret); + return ret; +} + static int apple_pcie_setup_link(struct apple_pcie *pcie, struct apple_pcie_port *port, struct device_node *np) @@ -2968,11 +3103,14 @@ static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_d of_node_put(iommu_spec.np); sid = iommu_spec.args[0]; - if (pcie->hw->adopt_link) - return rid == port->adopted_rid && sid == port->adopted_sid && - !READ_ONCE(port->link_failed) && - apple_pcie_port_readl(port, port_rid2sid_offset(port, sid)) == - T6050_ROUTE(rid, sid) ? 0 : -ENODEV; + if (pcie->hw->adopt_link) { + if (READ_ONCE(port->link_failed)) + return -ENODEV; + mutex_lock(&pcie->lock); + err = apple_pcie_adopted_route(port, rid); + mutex_unlock(&pcie->lock); + return err; + } mutex_lock(&port->pcie->lock); if (port->pcie->managed_sids || port->pcie->hw->sid_indexed_rid2sid) { @@ -3107,16 +3245,16 @@ static void __iomem *apple_pcie_map_bus(struct pci_bus *bus, struct apple_pcie_port *port; if (pcie->hw->adopt_link) { - /* Only adopted ports' root ports, and the one endpoint behind each. */ + /* Only adopted ports' root ports, and the endpoint behind each. */ list_for_each_entry(port, &pcie->ports, entry) { if (bus->number == 0) { if (devfn == PCI_DEVFN(port->idx, 0)) return pci_ecam_map_bus(bus, devfn, where); continue; } - if (bus->number != port->adopted_rid >> 8) + if (bus->number != port->adopted_bus) continue; - if (devfn || READ_ONCE(port->link_failed)) + if (PCI_SLOT(devfn) || READ_ONCE(port->link_failed)) return NULL; if ((apple_pcie_port_readl(port, PORT_LINKSTS) & (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP) { @@ -3707,9 +3845,9 @@ static int apple_pcie_probe(struct platform_device *pdev) for_each_available_child_of_node_scoped(dev->of_node, child) { u32 reg; - /* A root port 00:.0 on bus 0, n a GP port */ + /* A root port 00:.0 on bus 0, n a GP port (0-3) */ if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || - !(reg >> 11) || (reg >> 11) > 3 || + (reg >> 11) > 3 || !of_property_read_bool(child, "apple,link-trained-by-bootloader") || of_property_present(child, "reset-gpios") || of_property_present(child, "pwren-gpios")) @@ -3832,6 +3970,8 @@ static int apple_pcie_probe(struct platform_device *pdev) } } + if (hw->adopt_link) + bridge->reset_root_port = apple_pcie_t6050_reset_root_port; ret = pci_host_common_init(pdev, bridge, &apple_pcie_cfg_ecam_ops); if (ret) { apple_pcie_cleanup(pcie); From 5843113c59c0cb0dad812414dedfaaa51888cae4 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 23:53:26 -0800 Subject: [PATCH 189/342] PCI: apple: Drive T6050 port 0's PERST# through the pin controller The adopted port 0 named its PERST# pad as a 4-byte reg of the host (perst0, one word inside the pin controller's block) and wrote it raw. With the pin controller in the device tree the two nodes claim the same MMIO word, and whichever probes second fails: when pinctrl wins, the host's port setup stops with -EBUSY and no port is adopted, so the Ethernet and USB behind ports 2 and 3 are gone with it. One owner for the pad: the pin controller. The port node carries reset-gpios, as every other Apple host's port nodes do, and the host takes the line as the bootloader left it (GPIOD_ASIS: probe never touches a trained link's reset) and drives it only in the root-port reset, as a GPIO output at the logical level the reset asks for. The raw pad write set the same things (function bits cleared, mode output, the data bit) plus the pad's input enable, which the pin controller leaves as the bootloader set it. Probe asks for the line before any port is set up, so a host whose pin controller is not up yet defers instead of adopting nothing; an adopted port without reset-gpios has no reset, as before (reset_root_port answers -EOPNOTSUPP). The perst reg, its binding entry and the raw pad write go; the binding allows reset-gpios on an adopted port again. Probe names the port whose line it cannot have, as the probe of the other hosts' ports does: a line the pin controller reserves (gpio-reserved-ranges) is refused with -EINVAL, which the host's probe otherwise returned with no word of which port or property. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/pci/apple,pcie.yaml | 15 +++--- drivers/pci/controller/pcie-apple.c | 49 +++++++++++-------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 2446facb91d3a..64f0a2d43e9aa 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -242,16 +242,15 @@ allOf: properties: reg: minItems: 5 - maxItems: 18 + maxItems: 14 reg-names: description: config and rc, then port, phy and intr2axi for each - bootloader-trained root port 00:.0, and perst (its PERST# - pad) for a port whose endpoint needs a root-port reset. + bootloader-trained root port 00:.0. minItems: 5 - maxItems: 18 + maxItems: 14 items: - pattern: "^(config|rc|(port|phy|intr2axi|perst)[0-3])$" + pattern: "^(config|rc|(port|phy|intr2axi)[0-3])$" interrupts: maxItems: 4 interrupt-names: @@ -267,7 +266,11 @@ allOf: patternProperties: "^pci@": properties: - reset-gpios: false + reset-gpios: + description: + The PERST# line of a port whose endpoint needs a root-port + reset after the bootloader trained the link. Left as the + bootloader set it until that reset. pwren-gpios: false required: - apple,link-trained-by-bootloader diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 9a99347476bc4..a28781a22ed0d 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -473,7 +473,7 @@ struct apple_pcie_port { struct device_node *np; void __iomem *base; void __iomem *phy; - /* PERST# of a conventional port with a single reset line. */ + /* PERST# of a conventional or adopted port with a single reset line. */ struct gpio_desc *perst; struct irq_domain *domain; struct list_head entry; @@ -492,7 +492,6 @@ struct apple_pcie_port { void __iomem *intr2axi; /* adopt_link: this port's */ u8 adopted_bus; /* adopt_link: the secondary bus */ unsigned long adopted_slots; /* adopt_link: RID2SID slots routed (slot == SID) */ - void __iomem *perst; /* adopt_link: the PERST# pad, for a root-port reset */ }; static int apple_pcie_managed_admit(struct apple_pcie_port *port); @@ -1792,12 +1791,18 @@ static int apple_pcie_adopt_link(struct apple_pcie_port *port) port->intr2axi = devm_platform_ioremap_resource_byname(pdev, name); if (IS_ERR(port->intr2axi)) return PTR_ERR(port->intr2axi); - /* Only a port whose endpoint needs a root-port reset names its PERST# pad */ - snprintf(name, sizeof(name), "perst%d", port->idx); - if (platform_get_resource_byname(pdev, IORESOURCE_MEM, name)) { - port->perst = devm_platform_ioremap_resource_byname(pdev, name); - if (IS_ERR(port->perst)) + /* + * Only a port whose endpoint needs a root-port reset names its PERST# line + * (reset-gpios, on the port node as on every other Apple host). The pin + * controller owns the pad; the line is taken as the bootloader left it, + * released, and driven only by the reset. + */ + port->perst = devm_fwnode_gpiod_get(pcie->dev, of_fwnode_handle(port->np), "reset", + GPIOD_ASIS, "PERST#"); + if (IS_ERR(port->perst)) { + if (PTR_ERR(port->perst) != -ENOENT) return PTR_ERR(port->perst); + port->perst = NULL; } /* The currently qualified handoff is Gen3 x1, with no retrain in progress. */ @@ -1955,20 +1960,14 @@ static int apple_pcie_t6050_tune(struct apple_pcie_port *port, struct pci_dev *r return 0; } -/* PERST# through its pad: a GPIO output (function bits cleared) at the level asked for */ +/* + * PERST# through the pin controller: the pad as a GPIO output (its function bits + * cleared, mode output) at the line's logical level, which the DT's + * GPIO_ACTIVE_LOW turns into the pad level. + */ static int apple_pcie_t6050_perst(struct apple_pcie_port *port, bool asserted) { - u32 old, value; - - old = readl(port->perst); - if (old & BIT(21)) - return -EIO; - value = (old & ~0x27f) | 0x202 | !asserted; - /* The input enable (bit 9) goes on after the rest */ - writel((value & ~0x200) | (old & 0x200), port->perst); - if (!(old & 0x200)) - writel(value, port->perst); - return (readl(port->perst) ^ value) & 0x27f ? -EIO : 0; + return gpiod_direction_output(port->perst, asserted); } /* Let the link go idle, hold the endpoint in reset and stop the port and its lane clocks */ @@ -3849,9 +3848,19 @@ static int apple_pcie_probe(struct platform_device *pdev) if (of_property_read_u32(child, "reg", ®) || reg & ~0xf800 || (reg >> 11) > 3 || !of_property_read_bool(child, "apple,link-trained-by-bootloader") || - of_property_present(child, "reset-gpios") || of_property_present(child, "pwren-gpios")) return -EINVAL; + /* + * A port whose endpoint needs a root-port reset names its PERST# + * line: probe waits for the line's controller before any port is + * touched (a failed adoption would otherwise swallow the deferral). + */ + if (of_property_present(child, "reset-gpios")) { + ret = apple_pcie_probe_port(child); + if (ret) + return dev_err_probe(dev, ret, "Port %pOF probe fail\n", + child); + } } } else if (!hw->tunneled) { /* Check for probe dependencies for all ports first */ From 704b66f70f2ad14fd61f7ebbf4c3a7943f220fad Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 01:06:09 -0500 Subject: [PATCH 190/342] selftests: apple: Preserve multiline PCIe macros in policy tests The PCIe-C policy test extracts driver macro definitions to compile its production-code fixture. Taking only the first physical line truncates T6050_ROUTE and joins the following directive to its trailing backslash, so the fixture fails to compile after the T6050 host support is added. Copy continuation lines along with their define. The production fixture and both negative controls now pass. Developed with Claude Code. Signed-off-by: Erik Bourget --- tools/asahi/pciec-policy-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index a399c7ef6e023..a5a8fb96e143d 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -144,7 +144,7 @@ def main(): args = parser.parse_args() pci = (ROOT / 'drivers/pci/controller/pcie-apple.c').read_text() acio = (ROOT / 'drivers/thunderbolt/apple.c').read_text() - defines = '\n'.join(re.findall(r'^#define .*$', pci, re.M)) + defines = '\n'.join(re.findall(r'^#define (?:[^\n]*\\\n)*[^\n]*$', pci, re.M)) info = pci[pci.index('struct hw_info {'):pci.index('static const struct of_device_id apple_pcie_of_match[];')] matches = re.search(r'static const struct of_device_id apple_pcie_of_match\[\] = \{.*?\n\};', pci, re.S)[0] production = '\n'.join((defines, info, matches, From d1ccc586855d3a5bfc356ea20aa04c7402f73b7d Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:18 -0400 Subject: [PATCH 191/342] phy: apple: Add T6050 DisplayPort and USB combo PHY Add the T6050 DisplayPort/USB combo PHY and four-clock display crossbar profile. Carry the current Type-C, USB2, USB3 PIPE sequencing, and teardown behavior from the published T6050 source. Source snapshot: t6050-gpu ee68abb105200e99636a5edfc647a5cfc1d89954 Integration base: 9cbdd0734d9e186c5f5f5949a21b909d10c2571b Signed-off-by: Dj Signed-off-by: Erik Bourget --- .../bindings/mux/apple,display-crossbar.yaml | 6 +- .../bindings/phy/apple,t6050-dp-phy.yaml | 224 +++++ drivers/mux/apple-display-crossbar.c | 301 ++++++- drivers/phy/apple/Kconfig | 13 + drivers/phy/apple/Makefile | 2 + drivers/phy/apple/atc-t6050-combo.h | 394 +++++++++ drivers/phy/apple/atc-t6050-dp.c | 806 ++++++++++++++++++ drivers/phy/apple/atc-t6050-typec-data.h | 700 +++++++++++++++ .../apple/usb-t6050/apple_t6050_usb2_reset.h | 23 + .../apple/usb-t6050/apple_t6050_usb3_bist.h | 59 ++ .../apple/usb-t6050/apple_t6050_usb3_pipe.h | 136 +++ .../phy/apple/usb-t6050/apple_t6050_usb_phy.h | 286 +++++++ 12 files changed, 2942 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml create mode 100644 drivers/phy/apple/atc-t6050-combo.h create mode 100644 drivers/phy/apple/atc-t6050-dp.c create mode 100644 drivers/phy/apple/atc-t6050-typec-data.h create mode 100644 drivers/phy/apple/usb-t6050/apple_t6050_usb2_reset.h create mode 100644 drivers/phy/apple/usb-t6050/apple_t6050_usb3_bist.h create mode 100644 drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h create mode 100644 drivers/phy/apple/usb-t6050/apple_t6050_usb_phy.h diff --git a/Documentation/devicetree/bindings/mux/apple,display-crossbar.yaml b/Documentation/devicetree/bindings/mux/apple,display-crossbar.yaml index 245f520044e64..5597c9c1489ea 100644 --- a/Documentation/devicetree/bindings/mux/apple,display-crossbar.yaml +++ b/Documentation/devicetree/bindings/mux/apple,display-crossbar.yaml @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) AND GPL-2.0-only %YAML 1.2 --- $id: http://devicetree.org/schemas/mux/apple,display-crossbar.yaml# @@ -11,8 +11,8 @@ maintainers: description: Routes display pipelines to the DisplayPort transmitters and inputs - of an Apple Type-C PHY. Each crossbar exposes three mux controls, - selected by the consumer's mux specifier. + of an Apple Type-C PHY. Older layouts expose three mux controls; the T8142/T6050 layout + exposes five. The consumer selects an output using the mux specifier. allOf: - $ref: mux-controller.yaml# diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml new file mode 100644 index 0000000000000..52cb96f4a965b --- /dev/null +++ b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml @@ -0,0 +1,224 @@ +# SPDX-License-Identifier: GPL-2.0-only +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/apple,t6050-dp-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T6050 DisplayPort and Type-C combo PHY + +maintainers: + - Dj + +description: | + Fixed four-lane DisplayPort PHY for HDMI bridges, or one shared owner of + Type-C USB2, USB3 and DisplayPort alternate mode. DisplayPort supports RBR + through HBR3 without spread-spectrum clocking. The combo provider serializes + controller shutdown, PIPE handoff, orientation and alternate-mode changes. + Register resources, power domains and board tunables come from the producer. + +properties: + compatible: + enum: + - apple,t6050-dp-phy + - apple,t6050-combo-phy + + reg: + minItems: 6 + maxItems: 11 + + reg-names: + minItems: 6 + maxItems: 11 + + '#phy-cells': + enum: [0, 1] + + '#reset-cells': + const: 1 + + apple,port-index: + enum: [1, 2] + description: Native Type-C port; the debug/proxy port is excluded + + apple,guest-port-reserved: + type: boolean + description: The boot producer has excluded this port from host ownership + + mode-switch: true + orientation-switch: true + + mboxes: + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/properties/port + + apple,tunable-aus40cmn-shm: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples for the common analog bank + + apple,tunable-cio4pll: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples for the CIO PLL bank + + apple,tunable-usb2-default: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples for the USB2 PHY bank + + apple,tunable-usb2-host: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples for the USB2 host bank + + apple,tunable-pipe-default: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples for the PIPE handler + + power-domains: + minItems: 3 + maxItems: 3 + + power-domain-names: + items: + - const: usb-aon + - const: common + - const: wrapper + + apple,tunable-axi2af: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-fabric: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-common-cfg: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-lioa: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-lane0-rx-clock: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-lane1-rx-clock: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-lane0-rx-eq: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-lane1-rx-eq: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + + apple,tunable-auspll: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Offset, mask and value tuples within the named bank + +patternProperties: + '^apple,dp-training-table(-rbr|-hbr|-hbr2|-hbr3)?$': + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 16 + maxItems: 16 + description: Drive presets indexed by voltage swing times four plus pre-emphasis + +required: + - compatible + - reg + - reg-names + - '#phy-cells' + - power-domains + - power-domain-names + - apple,tunable-axi2af + - apple,tunable-fabric + - apple,tunable-common-cfg + - apple,tunable-lioa + - apple,tunable-lane0-rx-clock + - apple,tunable-lane1-rx-clock + - apple,tunable-lane0-rx-eq + - apple,tunable-lane1-rx-eq + - apple,tunable-auspll + +allOf: + - if: + properties: + compatible: + const: apple,t6050-combo-phy + then: + properties: + '#phy-cells': + const: 1 + reg: + minItems: 11 + maxItems: 11 + reg-names: + items: + - const: core + - const: usb2phy + - const: usb2-digital + - const: reset + - const: fabric + - const: axi2af + - const: lioa + - const: common-cfg + - const: usb-control + - const: firmware-data + - const: pipehandler + required: + - '#reset-cells' + - apple,port-index + - apple,guest-port-reserved + - mode-switch + - orientation-switch + - mboxes + - apple,tunable-aus40cmn-shm + - apple,tunable-cio4pll + - apple,tunable-usb2-default + - apple,tunable-usb2-host + - apple,tunable-pipe-default + else: + properties: + '#phy-cells': + const: 0 + if: + required: + - mode-switch + then: + properties: + reg: + minItems: 8 + maxItems: 8 + reg-names: + items: + - const: core + - const: reset + - const: fabric + - const: axi2af + - const: lioa + - const: common-cfg + - const: usb-control + - const: firmware-data + required: + - orientation-switch + - mboxes + - apple,tunable-aus40cmn-shm + - apple,tunable-cio4pll + else: + properties: + reg: + minItems: 6 + maxItems: 6 + reg-names: + items: + - const: core + - const: reset + - const: fabric + - const: axi2af + - const: lioa + - const: common-cfg + +additionalProperties: false diff --git a/drivers/mux/apple-display-crossbar.c b/drivers/mux/apple-display-crossbar.c index 65107c7de3800..223d7b813dc15 100644 --- a/drivers/mux/apple-display-crossbar.c +++ b/drivers/mux/apple-display-crossbar.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT +// SPDX-License-Identifier: (GPL-2.0-only OR MIT) AND GPL-2.0-only /* * Apple Silicon Display Crossbar multiplexer driver * @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -90,7 +93,10 @@ enum { MUX_DPPHY = 0, MUX_DPIN0 = 1, MUX_DPIN1 = 2, MUX_MAX = 3 }; static const char *apple_dpxbar_names[MUX_MAX] = { "dpphy", "dpin0", "dpin1" }; +enum { T8142_MUX_MAX = 5 }; + struct apple_dpxbar_hw { + unsigned int n_mux; unsigned int n_ufp; u32 tunable; const struct mux_control_ops *ops; @@ -108,12 +114,16 @@ struct apple_dpxbar { struct device *dev; const struct apple_dpxbar_hw *hw; void __iomem *regs; - int selected_dispext[MUX_MAX]; + int selected_dispext[T8142_MUX_MAX]; /* T6030 programs all its outputs itself, see apple_dpxbar_t6030_link() */ bool t6030_dpin; /* outputs holding a runtime PM reference (runtime_pm crossbars) */ unsigned long rpm_held; bool tunnel_link_up[MUX_MAX]; + u8 pclk[T8142_MUX_MAX]; + bool uhbr[T8142_MUX_MAX]; + bool enabled[T8142_MUX_MAX]; + bool faulted; spinlock_t lock; }; @@ -880,6 +890,225 @@ int apple_dpxbar_tunnel_select_source(struct mux_control *mux, int state) } EXPORT_SYMBOL_GPL(apple_dpxbar_tunnel_select_source); +/* + * T8142 (also used by T6050) has four pixel clocks and five outputs. + * Keep selection separate from clock activation: the PHY/DP IN owner supplies + * its actual clock and coding before link_up(), after configuring that clock. + * Only the four two-port external display sources are described here; AUX + * sources use a different selector-to-clock-bit mapping. + */ +static const u8 t8142_dest_shift[T8142_MUX_MAX] = { 8, 0, 4, 12, 16 }; +static const u8 t8142_select_shift[T8142_MUX_MAX] = { 8, 0, 4, 24, 0 }; +static const u8 t8142_select_shift2[T8142_MUX_MAX] = { 20, 12, 16, 28, 4 }; + +static int t8142_link_down(struct apple_dpxbar *xbar, unsigned int index) +{ + u32 src, dst, clock, value; + int ret; + + if (!xbar->enabled[index]) + return 0; + src = BIT(xbar->selected_dispext[index]); + dst = BIT(t8142_dest_shift[index]); + clock = xbar->pclk[index] - 1; + + dpxbar_clear32(xbar, 0x3c, src); + dpxbar_clear32(xbar, 0x00, src); + dpxbar_clear32(xbar, 0x0c + 4 * clock, src); + dpxbar_clear32(xbar, 0x24 + 4 * clock, dst); + udelay(1); + ret = readl_poll_timeout_atomic(xbar->regs + 0x800, value, + !(value & src), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + ret = readl_poll_timeout_atomic(xbar->regs + 0x808 + 4 * clock, value, + !(value & src), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + ret = readl_poll_timeout_atomic(xbar->regs + 0x81c + 4 * clock, value, + !(value & dst), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + dpxbar_clear32(xbar, 0x08, src); + dpxbar_clear32(xbar, 0x20, 7 << (3 * xbar->selected_dispext[index])); + dpxbar_clear32(xbar, 0x38, 7 << t8142_dest_shift[index]); + dpxbar_set32(xbar, 0x04, src); + dpxbar_set32(xbar, 0x1c, src); + dpxbar_set32(xbar, 0x34, dst); + xbar->enabled[index] = false; + return 0; +} + +static int t8142_link_up(struct apple_dpxbar *xbar, unsigned int index) +{ + int state = xbar->selected_dispext[index]; + u32 clock, select, src, dst, value; + int ret; + + if (state < 0) + return -ENODEV; + if (!xbar->pclk[index]) + return -EINVAL; + if (xbar->enabled[index]) + return 0; + + /* The coding bit is shared by every output using this pixel clock. */ + for (unsigned int i = 0; i < T8142_MUX_MAX; i++) + if (i != index && xbar->enabled[i] && + xbar->pclk[i] == xbar->pclk[index] && + xbar->uhbr[i] != xbar->uhbr[index]) + return -EBUSY; + + clock = xbar->pclk[index] - 1; + select = 2 * clock + 1; + src = BIT(state); + dst = BIT(t8142_dest_shift[index]); + dpxbar_clear32(xbar, 0x04, src); + dpxbar_clear32(xbar, 0x1c, src); + dpxbar_clear32(xbar, 0x34, dst); + udelay(1); + ret = readl_poll_timeout_atomic(xbar->regs + 0x804, value, + !(value & src), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + ret = readl_poll_timeout_atomic(xbar->regs + 0x818, value, + !(value & src), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + ret = readl_poll_timeout_atomic(xbar->regs + 0x82c, value, + !(value & dst), 1, 1000); + if (ret) { + xbar->faulted = true; + return ret; + } + dpxbar_set32(xbar, 0x08, src); + dpxbar_mask32(xbar, 0x20, 7 << (3 * state), select << (3 * state)); + dpxbar_mask32(xbar, 0x38, 7 << t8142_dest_shift[index], + select << t8142_dest_shift[index]); + dpxbar_mask32(xbar, 0x48, BIT(clock), xbar->uhbr[index] ? BIT(clock) : 0); + dpxbar_set32(xbar, 0x00, src); + dpxbar_set32(xbar, 0x0c + 4 * clock, src); + dpxbar_set32(xbar, 0x24 + 4 * clock, dst); + dpxbar_set32(xbar, 0x4c, dst); + dpxbar_set32(xbar, 0x3c, src); + xbar->enabled[index] = true; + return 0; +} + +static int apple_dpxbar_set_t8142(struct mux_control *mux, int state) +{ + struct apple_dpxbar *xbar = mux_chip_priv(mux->chip); + unsigned int index = mux_control_get_index(mux); + unsigned long flags; + u32 mask, value; + int ret = 0; + + if (state != MUX_IDLE_DISCONNECT && + (state < 0 || state >= 8 || (index == MUX_DPPHY && (state & 1)))) + return -EINVAL; + + spin_lock_irqsave(&xbar->lock, flags); + if (xbar->faulted) { + ret = -EIO; + goto out; + } + if (state >= 0) { + for (unsigned int i = 0; i < T8142_MUX_MAX; i++) { + if (i != index && xbar->selected_dispext[i] == state) { + spin_unlock_irqrestore(&xbar->lock, flags); + return -EBUSY; + } + } + } + + if (xbar->selected_dispext[index] == state) + goto out; + if (xbar->selected_dispext[index] >= 0) { + ret = t8142_link_down(xbar, index); + if (ret) + goto out; + } + + /* No implicit clock choice or activation when selecting a new source. */ + xbar->pclk[index] = 0; + xbar->selected_dispext[index] = state; + if (state >= 0) { + mask = (0xfU << t8142_select_shift[index]) | + (0xfU << t8142_select_shift2[index]); + value = ((u32)state << t8142_select_shift[index]) | + ((u32)state << t8142_select_shift2[index]); + dpxbar_mask32(xbar, index == 4 ? 0x40 : 0x44, mask, value); + } +out: + spin_unlock_irqrestore(&xbar->lock, flags); + return ret; +} + +static const struct mux_control_ops apple_dpxbar_t8142_ops = { + .set = apple_dpxbar_set_t8142, +}; + +/* Caller holds the mux selection throughout configuration and activation. */ +int apple_dpxbar_link_configure(struct mux_control *mux, unsigned int pclk, bool uhbr) +{ + struct apple_dpxbar *xbar; + unsigned int index; + unsigned long flags; + int ret = 0; + + if (!mux || mux->chip->ops != &apple_dpxbar_t8142_ops) + return -EOPNOTSUPP; + if (pclk < 1 || pclk > 4) + return -EINVAL; + xbar = mux_chip_priv(mux->chip); + index = mux_control_get_index(mux); + spin_lock_irqsave(&xbar->lock, flags); + if (xbar->faulted) + ret = -EIO; + else if (xbar->selected_dispext[index] < 0) + ret = -ENODEV; + else if (xbar->enabled[index]) + ret = -EBUSY; + else { + xbar->pclk[index] = pclk; + xbar->uhbr[index] = uhbr; + } + spin_unlock_irqrestore(&xbar->lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(apple_dpxbar_link_configure); + +static int apple_dpxbar_t8142_link(struct mux_control *mux, bool up) +{ + struct apple_dpxbar *xbar = mux_chip_priv(mux->chip); + unsigned int index = mux_control_get_index(mux); + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&xbar->lock, flags); + if (xbar->faulted) + ret = -EIO; + else if (xbar->selected_dispext[index] < 0) + ret = -ENODEV; + else if (up) + ret = t8142_link_up(xbar, index); + else + ret = t8142_link_down(xbar, index); + spin_unlock_irqrestore(&xbar->lock, flags); + return ret; +} + + static int apple_dpxbar_t602x_link_up(struct mux_control *mux) { struct apple_dpxbar *xbar; @@ -961,6 +1190,9 @@ static int apple_dpxbar_t6030_link_set(struct mux_control *mux, bool up) int apple_dpxbar_link_up(struct mux_control *mux) { + if (mux && mux->chip->ops == &apple_dpxbar_t8142_ops) + return apple_dpxbar_t8142_link(mux, true); + if (!mux) return -EINVAL; if (mux->chip->ops == &apple_dpxbar_t602x_ops) { @@ -1009,6 +1241,9 @@ static int apple_dpxbar_t602x_link_down(struct mux_control *mux) int apple_dpxbar_link_down(struct mux_control *mux) { + if (mux && mux->chip->ops == &apple_dpxbar_t8142_ops) + return apple_dpxbar_t8142_link(mux, false); + if (!mux) return -EINVAL; if (mux->chip->ops == &apple_dpxbar_t602x_ops) { @@ -1022,6 +1257,39 @@ int apple_dpxbar_link_down(struct mux_control *mux) } EXPORT_SYMBOL_GPL(apple_dpxbar_link_down); +static void apple_dpxbar_domain_release(void *data) +{ + struct device *pd = data; + + pm_runtime_put_sync_suspend(pd); + dev_pm_domain_detach(pd, true); +} + +static int apple_dpxbar_domains(struct device *dev) +{ + static const char * const names[] = { "usb-aon", "common" }; + int ret; + + /* Older handoff-only trees have no Linux-managed domains. */ + if (!of_property_present(dev->of_node, "power-domain-names")) + return 0; + for (unsigned int i = 0; i < ARRAY_SIZE(names); i++) { + struct device *pd = dev_pm_domain_attach_by_name(dev, names[i]); + + if (IS_ERR_OR_NULL(pd)) + return pd ? PTR_ERR(pd) : -ENODEV; + ret = pm_runtime_resume_and_get(pd); + if (ret < 0) { + dev_pm_domain_detach(pd, true); + return ret; + } + ret = devm_add_action_or_reset(dev, apple_dpxbar_domain_release, pd); + if (ret) + return ret; + } + return 0; +} + static int apple_dpxbar_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1031,7 +1299,16 @@ static int apple_dpxbar_probe(struct platform_device *pdev) int ret; hw = of_device_get_match_data(dev); - mux_chip = devm_mux_chip_alloc(dev, MUX_MAX, sizeof(*dpxbar)); + if (hw->ops == &apple_dpxbar_t8142_ops) { + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + if (!res || resource_size(res) < 0x830) + return -EINVAL; + ret = apple_dpxbar_domains(dev); + if (ret) + return dev_err_probe(dev, ret, "cannot power crossbar controls\n"); + } + mux_chip = devm_mux_chip_alloc(dev, hw->n_mux, sizeof(*dpxbar)); if (IS_ERR(mux_chip)) return PTR_ERR(mux_chip); @@ -1052,14 +1329,14 @@ static int apple_dpxbar_probe(struct platform_device *pdev) return ret; } - if (!hw->no_tunable && + if (hw->ops == &apple_dpxbar_ops && !hw->no_tunable && !of_device_is_compatible(dev->of_node, "apple,t6020-display-crossbar")) { readl(dpxbar->regs + UNK_TUNABLE); writel(hw->tunable, dpxbar->regs + UNK_TUNABLE); readl(dpxbar->regs + UNK_TUNABLE); } - for (unsigned int i = 0; i < MUX_MAX; ++i) { + for (unsigned int i = 0; i < hw->n_mux; ++i) { mux_chip->mux[i].states = hw->n_ufp; mux_chip->mux[i].idle_state = MUX_IDLE_DISCONNECT; dpxbar->selected_dispext[i] = -1; @@ -1124,18 +1401,21 @@ static int apple_dpxbar_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(apple_dpxbar_pm_ops, NULL, apple_dpxbar_resume); static const struct apple_dpxbar_hw apple_dpxbar_hw_t8103 = { + .n_mux = MUX_MAX, .n_ufp = 2, .tunable = 0, .ops = &apple_dpxbar_ops, }; static const struct apple_dpxbar_hw apple_dpxbar_hw_t8112 = { + .n_mux = MUX_MAX, .n_ufp = 4, .tunable = 4278196325, .ops = &apple_dpxbar_ops, }; static const struct apple_dpxbar_hw apple_dpxbar_hw_t6000 = { + .n_mux = MUX_MAX, .n_ufp = 9, .tunable = 5, .ops = &apple_dpxbar_ops, @@ -1143,6 +1423,7 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t6000 = { }; static const struct apple_dpxbar_hw apple_dpxbar_hw_t6020 = { + .n_mux = MUX_MAX, .n_ufp = 9, .ops = &apple_dpxbar_t602x_ops, }; @@ -1155,6 +1436,7 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t6020 = { * The ADT lists nine UFP endpoints (dispext0-3, scodec0 and the DP IN ports). */ static const struct apple_dpxbar_hw apple_dpxbar_hw_t6041 = { + .n_mux = MUX_MAX, .n_ufp = 9, .ops = &apple_dpxbar_t602x_ops, .t6030_flow = true, @@ -1170,6 +1452,7 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t6041 = { * output is selected; probe touches no register. */ static const struct apple_dpxbar_hw apple_dpxbar_hw_t8132 = { + .n_mux = MUX_MAX, .n_ufp = 9, .ops = &apple_dpxbar_t602x_ops, .t6030_flow = true, @@ -1177,7 +1460,15 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t8132 = { .runtime_pm = true, }; +static const struct apple_dpxbar_hw apple_dpxbar_hw_t8142 = { + .n_mux = T8142_MUX_MAX, + .n_ufp = 8, + .ops = &apple_dpxbar_t8142_ops, +}; + static const struct of_device_id apple_dpxbar_ids[] = { + { .compatible = "apple,t6050-display-crossbar", .data = &apple_dpxbar_hw_t8142 }, + { .compatible = "apple,t8142-display-crossbar", .data = &apple_dpxbar_hw_t8142 }, { .compatible = "apple,t8103-display-crossbar", .data = &apple_dpxbar_hw_t8103, diff --git a/drivers/phy/apple/Kconfig b/drivers/phy/apple/Kconfig index 5348987cf1dc8..36ed85b7935f2 100644 --- a/drivers/phy/apple/Kconfig +++ b/drivers/phy/apple/Kconfig @@ -62,3 +62,16 @@ config PHY_APPLE_DPTX such as the M2. This driver provides support for DisplayPort and is used on the Mac mini (M2 and M2 Pro, 2023). + +config PHY_APPLE_T6050_DP + tristate "Apple T6050 DisplayPort and Type-C combo PHY" + depends on ARCH_APPLE || COMPILE_TEST + depends on OF && PM && TYPEC + select GENERIC_PHY + select APPLE_TUNABLE + select APPLE_RTKIT + select RESET_CONTROLLER + help + Fixed HDMI bridges and Type-C USB host/DisplayPort alternate mode. + One owner coordinates the shared PHY, firmware, PIPE and USB2 state. + Requires named register banks, power domains and firmware tunables. diff --git a/drivers/phy/apple/Makefile b/drivers/phy/apple/Makefile index e7156408e792f..e0b94bb1dcaa5 100644 --- a/drivers/phy/apple/Makefile +++ b/drivers/phy/apple/Makefile @@ -8,3 +8,5 @@ phy-apple-t6040-usb2-y := t6040-usb2.o obj-$(CONFIG_PHY_APPLE_DPTX) += phy-apple-dptx.o phy-apple-dptx-y += dptx.o + +obj-$(CONFIG_PHY_APPLE_T6050_DP) += atc-t6050-dp.o diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h new file mode 100644 index 0000000000000..1066748dc1afe --- /dev/null +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -0,0 +1,394 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* One Type-C owner reuses the established DP and USB backend sequences. + * All calls below hold dp->lock; only PHY power_off authorizes PIPE teardown + * while the controller reset is deasserted. Lane changes require reset/off. + */ +static u32 combo_read(void *ctx, unsigned int bank, unsigned int offset) +{ + struct t6050_dp *dp = ctx; + return readl(dp->banks[bank] + offset); +} +static void combo_write(void *ctx, unsigned int bank, unsigned int offset, u32 value) +{ + struct t6050_dp *dp = ctx; + writel(value, dp->banks[bank] + offset); +} +static int combo_poll(void *ctx, unsigned int bank, unsigned int offset, + unsigned int mask, unsigned int expected, unsigned int usec) +{ + struct t6050_dp *dp = ctx; + u32 value; + return readl_poll_timeout(dp->banks[bank] + offset, value, + (value & mask) == expected, + (bank == 44 || bank == 35 || usec <= 1000) ? 1 : 1000, usec); +} +static void combo_delay(void *ctx, unsigned int usec) { udelay(usec); } +static void combo_pause(void *ctx, unsigned int nsec) { ndelay(nsec); } +static void combo_sleep(void *ctx, unsigned int msec) { msleep(msec); } +static int combo_wrapper(void *ctx, unsigned int active) +{ + struct t6050_dp *dp = ctx; + return atc_domain_set(&dp->domain[2], active); +} +static int combo_firmware(void *ctx, unsigned int active) +{ + return atc_firmware(ctx, active); +} +static int combo_tunable(void *ctx, unsigned int bank, const char *name) +{ + static const struct { u8 bank, index; const char *name; } common[] = { + {41, 0, "tunable_ATC0AXI2AF"}, {40, 1, "tunable_ATC_FABRIC"}, + {43, 2, "tunable_ATC_COMMON_CFG"}, {42, 3, "tunable_ATC0AXI2AF_LIOA"}, + {20, 4, "tunable_LN0_RX_CFG_TX_OF_RXCLK"}, {29, 5, "tunable_LN1_RX_CFG_TX_OF_RXCLK"}, + {18, 6, "tunable_LN0_RX_EQ_DFLT"}, {27, 7, "tunable_LN1_RX_EQ_DFLT"}, + {8, 8, "tunable_AUSPLL_CORE"}, {5, 9, "tunable_AUS40CMN_SHM"}, + {10, 10, "tunable_CIO4PLL_CORE"}, + }; + struct t6050_dp *dp = ctx; + + if (bank == 0 && !strcmp(name, "tunable_USB2PHY_DFLT")) { + apple_tunable_apply(dp->banks[0], dp->usb2_default); + return 0; + } + if (bank == 0 && !strcmp(name, "tunable_USB2PHY_HOST")) { + apple_tunable_apply(dp->banks[0], dp->usb2_host); + return 0; + } + for (unsigned int i = 0; i < ARRAY_SIZE(common); i++) + if (bank == common[i].bank && !strcmp(name, common[i].name)) { + apple_tunable_apply(dp->banks[bank], dp->tunables[common[i].index]); + return 0; + } + return -EINVAL; +} + +static int combo_quiesce(void *ctx) +{ + struct t6050_dp *dp = ctx; + int ret = 0; + + if (dp->usb_prepared) { + ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb3_shutdown); + if (!ret) + dp->usb_prepared = false; + } else if (dp->enabled) { + /* Multifunction has a distinct native shutdown; never run the + * USB-only analog sequence over live DisplayPort lane state. */ + ret = atc_stop(dp); + } + return ret; +} + +static int combo_stop(struct t6050_dp *dp) +{ + int ret; + + lockdep_assert_held(&dp->lock); + if (dp->faulted) + return -EIO; + if (dp->controller_active || dp->pipe_active) + return -EBUSY; + ret = combo_quiesce(dp); + if (!ret && dp->usb2_active) { + ret = apple_t6050_usb2_stop(&dp->usb_platform); + if (!ret) + dp->usb2_active = false; + } + if (!ret) + ret = atc_domain_set(&dp->domain[1], false); + if (!ret) + ret = atc_domain_set(&dp->domain[0], false); + if (ret) { + dp->faulted = true; + return ret < 0 ? ret : -EIO; + } + dp->combo_mode = COMBO_SAFE; + return 0; +} + +static int combo_start(struct t6050_dp *dp, enum combo_mode mode) +{ + int ret; + + lockdep_assert_held(&dp->lock); + if (dp->faulted) + return -EIO; + if (dp->orientation == TYPEC_ORIENTATION_NONE) + return -ENOLINK; + ret = atc_domain_set(&dp->domain[0], true); + if (!ret) + ret = atc_domain_set(&dp->domain[1], true); + if (!ret) + ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb2_host); + if (!ret) + dp->usb2_active = true; + if (!ret && mode == COMBO_USB) { + ret = dp->reverse ? + APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb3_init_reverse) : + APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb3_init_normal); + if (!ret) + dp->usb_prepared = true; + } else if (!ret) { + dp->multifunction = mode == COMBO_DP2; + ret = atc_start(dp); + } + if (ret) { + /* A partial shared transition has no cold-start ownership proof. */ + dp->faulted = true; + return ret < 0 ? ret : -EIO; + } + dp->combo_mode = mode; + return 0; +} + +static int combo_orientation(struct t6050_dp *dp, enum typec_orientation orientation) +{ + int ret; + + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (orientation != TYPEC_ORIENTATION_NONE && orientation != TYPEC_ORIENTATION_NORMAL && + orientation != TYPEC_ORIENTATION_REVERSE) + return -EINVAL; + if (dp->orientation == orientation) + return 0; + ret = combo_stop(dp); + if (!ret) { + dp->orientation = orientation; + dp->reverse = orientation == TYPEC_ORIENTATION_REVERSE; + } + return ret; +} + +static int combo_mux(struct t6050_dp *dp, struct typec_mux_state *state) +{ + enum combo_mode mode; + int ret; + + if (state->mode == TYPEC_STATE_SAFE) + mode = COMBO_SAFE; + else if (state->mode == TYPEC_STATE_USB && !state->alt) + mode = COMBO_USB; + else if (state->alt && state->alt->svid == USB_TYPEC_DP_SID) { + switch (state->mode) { + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_E: mode = COMBO_DP4; break; + case TYPEC_DP_STATE_D: mode = COMBO_DP2; break; + default: return -EOPNOTSUPP; + } + } else { + return -EOPNOTSUPP; + } + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (mode == dp->combo_mode && + (mode == COMBO_SAFE || dp->usb_prepared || dp->enabled)) + return 0; + if (mode != COMBO_SAFE && dp->orientation == TYPEC_ORIENTATION_NONE) + return -ENOLINK; + ret = combo_stop(dp); + if (ret || mode == COMBO_SAFE) + return ret; + return combo_start(dp, mode); +} + +static int combo_usb2_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + int ret; + + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (mode != PHY_MODE_USB_HOST) + return -EOPNOTSUPP; + if (!dp->usb_prepared && !dp->enabled) + return -ENOLINK; + if (dp->usb2_active) + return 0; + ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb2_host); + if (ret) + dp->faulted = true; + else + dp->usb2_active = true; + return ret; +} + +static int combo_usb2_reset(struct phy *phy) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + int ret; + + guard(mutex)(&dp->lock); + if (dp->faulted || !dp->usb2_active) + return -ENOLINK; + ret = apple_t6050_usb2_port_reset(&dp->usb_io, dp, combo_sleep); + if (ret) + dp->faulted = true; + return ret ? -EIO : 0; +} + +static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + int ret; + + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (mode != PHY_MODE_USB_HOST) + return -EOPNOTSUPP; + if (!dp->controller_active || !dp->usb2_active) + return -ENOLINK; + /* Four DP lanes leave DWC3 on its established dummy PIPE; USB2 still + * uses its independent D+/D- PHY. Do not switch USB3 onto DP lanes. */ + if (dp->combo_mode == COMBO_DP4 && dp->enabled) + return 0; + if (!dp->usb_prepared && !(dp->combo_mode == COMBO_DP2 && dp->enabled)) + return -ENOLINK; + if (dp->pipe_active) + return (readl(dp->banks[44] + 0xc) & 0x73) == 0x10 ? 0 : -EIO; + apple_tunable_apply(dp->banks[44], dp->pipe_default); + ret = apple_t6050_usb3_pipe_switch(&dp->usb_io); + if (ret) + dp->faulted = true; + else + dp->pipe_active = true; + return ret ? -EIO : 0; +} + +static int combo_usb3_poweroff(struct phy *phy) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + int ret = 0; + + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + /* DWC3 calls power_off only after host/gadget shutdown and SUSPHY. + * PIPE must select its dummy producer before the controller is reset. */ + if (dp->pipe_active) { + ret = apple_t6050_usb3_pipe_stop(&dp->usb_io, combo_quiesce, dp); + if (!ret) + dp->pipe_active = false; + } + if (!ret && dp->usb2_active) { + ret = apple_t6050_usb2_stop(&dp->usb_platform); + if (!ret) + dp->usb2_active = false; + } + if (ret) + dp->faulted = true; + return ret ? -EIO : 0; +} +static const struct phy_ops combo_usb2_ops = { + .set_mode = combo_usb2_mode, .reset = combo_usb2_reset, .owner = THIS_MODULE, +}; +static const struct phy_ops combo_usb3_ops = { + .set_mode = combo_usb3_mode, .power_off = combo_usb3_poweroff, .owner = THIS_MODULE, +}; + +static int combo_reset_assert(struct reset_controller_dev *reset, unsigned long id) +{ + struct t6050_dp *dp = container_of(reset, struct t6050_dp, reset); + int ret; + + guard(mutex)(&dp->lock); + if (id || dp->pipe_active) + return -EBUSY; + if (dp->faulted) + return -EIO; + apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 1, 0); + apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 0x10, 0x10); + ret = apple_t6050_usb3_pipe_cold_dummy(&dp->usb_io); + if (ret) + dp->faulted = true; + else + dp->controller_active = false; + return ret ? -EIO : 0; +} +static int combo_reset_deassert(struct reset_controller_dev *reset, unsigned long id) +{ + struct t6050_dp *dp = container_of(reset, struct t6050_dp, reset); + + guard(mutex)(&dp->lock); + if (id) + return -EINVAL; + if (dp->faulted || !dp->usb2_active) + return -ENOLINK; + apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 0x10, 0); + apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 1, 1); + dp->controller_active = true; + return 0; +} +static const struct reset_control_ops combo_reset_ops = { + .assert = combo_reset_assert, .deassert = combo_reset_deassert, +}; + +static struct phy *combo_xlate(struct device *dev, const struct of_phandle_args *args) +{ + struct t6050_dp *dp = dev_get_drvdata(dev); + if (args->args_count != 1) + return ERR_PTR(-EINVAL); + switch (args->args[0]) { + case PHY_TYPE_USB2: return dp->combo_phy[0]; + case PHY_TYPE_USB3: return dp->combo_phy[1]; + case PHY_TYPE_DP: return dp->combo_phy[2]; + default: return ERR_PTR(-EINVAL); + } +} + +static int combo_setup(struct platform_device *pdev, struct t6050_dp *dp) +{ + static const struct { u8 bank; u32 minimum; const char *name; } extra[] = { + {0, 0x20, "usb2phy"}, {1, 0x24, "usb2-digital"}, {44, 0x48, "pipehandler"}, + }; + struct device *dev = dp->dev; + int ret; + + for (unsigned int i = 0; i < ARRAY_SIZE(extra); i++) { + struct resource *res = platform_get_resource_byname(pdev, IORESOURCE_MEM, extra[i].name); + if (!res || resource_size(res) < extra[i].minimum) + return -EINVAL; + dp->banks[extra[i].bank] = devm_ioremap_resource(dev, res); + if (IS_ERR(dp->banks[extra[i].bank])) + return PTR_ERR(dp->banks[extra[i].bank]); + dp->resources[extra[i].bank] = *res; + } + dp->usb2_default = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2-default", &dp->resources[0]); + if (IS_ERR(dp->usb2_default)) + return PTR_ERR(dp->usb2_default); + dp->usb2_host = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2-host", &dp->resources[0]); + if (IS_ERR(dp->usb2_host)) + return PTR_ERR(dp->usb2_host); + dp->pipe_default = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-pipe-default", &dp->resources[44]); + if (IS_ERR(dp->pipe_default)) + return PTR_ERR(dp->pipe_default); + dp->usb_io = (struct apple_t6050_usb_io) { + .context = dp, .read = combo_read, .write = combo_write, + .poll = combo_poll, .delay = combo_delay, + }; + dp->usb_platform = (struct apple_t6050_usb_platform) { + .context = dp, .io = &dp->usb_io, .wrapper_power = combo_wrapper, + .firmware = combo_firmware, .tunable = combo_tunable, .pause_ns = combo_pause, + }; + dp->reset = (struct reset_controller_dev) { + .owner = THIS_MODULE, .ops = &combo_reset_ops, .dev = dev, + .of_node = dev->of_node, .nr_resets = 1, + }; + ret = devm_reset_controller_register(dev, &dp->reset); + if (ret) + return ret; + for (unsigned int i = 0; i < 2; i++) { + dp->combo_phy[i] = devm_phy_create(dev, NULL, i ? &combo_usb3_ops : &combo_usb2_ops); + if (IS_ERR(dp->combo_phy[i])) + return PTR_ERR(dp->combo_phy[i]); + phy_set_drvdata(dp->combo_phy[i], dp); + } + return 0; +} diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c new file mode 100644 index 0000000000000..cafee096a6250 --- /dev/null +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -0,0 +1,806 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* T6050 DisplayPort PHY for fixed bridges and Type-C DP alternate mode. */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "usb-t6050/apple_t6050_usb_phy.h" +#include "usb-t6050/apple_t6050_usb3_pipe.h" +#include "usb-t6050/apple_t6050_usb2_reset.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum atc_operation { ATC_MASK, ATC_TUNABLE, ATC_DELAY, ATC_POLL, ATC_POWER, ATC_FIRMWARE }; +struct atc_op { + u8 op, bank; + u16 offset; + u32 mask, value, timeout; +}; +struct atc_rate_op { + struct atc_op op; + u8 rates; + u32 values[4]; +}; +#include "atc-t6050-dp-data.h" +#include "atc-t6050-typec-data.h" + +static const struct { u8 bank; u32 offset; } core_banks[] = { + {2, 0}, {3, 0x400}, {4, 0x800}, {5, 0xa00}, {6, 0x1000}, + {7, 0x3000}, {8, 0x3200}, {9, 0x3800}, {10, 0x3a00}, + {14, 0x7000}, {16, 0x9000}, {18, 0xb000}, {19, 0xc000}, + {20, 0xd000}, {21, 0xe000}, {22, 0xf000}, {25, 0x19000}, + {27, 0x1b000}, {28, 0x1c000}, {29, 0x1d000}, {30, 0x1e000}, + {31, 0x1f000}, {33, 0x28000}, {34, 0x28400}, {35, 0x29000}, +}; +static const struct { u8 bank; const char *name; } extra_banks[] = { + {39, "reset"}, {40, "fabric"}, {41, "axi2af"}, + {42, "lioa"}, {43, "common-cfg"}, + {38, "usb-control"}, +}; +static const struct { u8 bank; const char *name; } tunable_names[] = { + {41, "apple,tunable-axi2af"}, {40, "apple,tunable-fabric"}, + {43, "apple,tunable-common-cfg"}, {42, "apple,tunable-lioa"}, + {20, "apple,tunable-lane0-rx-clock"}, {29, "apple,tunable-lane1-rx-clock"}, + {18, "apple,tunable-lane0-rx-eq"}, {27, "apple,tunable-lane1-rx-eq"}, + {8, "apple,tunable-auspll"}, + {5, "apple,tunable-aus40cmn-shm"}, {10, "apple,tunable-cio4pll"}, +}; +static const unsigned int link_rates[] = {1620, 2700, 5400, 8100}; +static const char * const training_names[] = { + "apple,dp-training-table-rbr", "apple,dp-training-table-hbr", + "apple,dp-training-table-hbr2", "apple,dp-training-table-hbr3", +}; +struct atc_domain { + struct device *dev; + bool active; +}; +enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2 }; +struct t6050_dp { + bool combo, usb_prepared, usb2_active, pipe_active, controller_active; + enum combo_mode combo_mode; + enum typec_orientation orientation; + struct phy *combo_phy[3]; + struct reset_controller_dev reset; + struct apple_t6050_usb_io usb_io; + struct apple_t6050_usb_platform usb_platform; + struct apple_tunable *usb2_default, *usb2_host, *pipe_default; + struct device *dev; + struct mutex lock; + void __iomem *banks[45]; + struct resource resources[45]; + struct apple_tunable *tunables[ARRAY_SIZE(tunable_names)]; + struct atc_domain domain[3]; /* USB AON, common, wrapper: native order. */ + u32 training[4][16]; + u32 voltage[4], pre[4]; + int rate; + bool enabled, faulted; + bool typec, reverse, multifunction; + struct apple_rtkit *rtkit; + void __iomem *fw_data; + bool fw_running; +}; + +static int atc_domain_set(struct atc_domain *pd, bool active) +{ + int ret; + + if (pd->active == active) + return 0; + if (active) { + ret = pm_runtime_resume_and_get(pd->dev); + if (ret < 0) + return ret; + } else { + ret = pm_runtime_put_sync_suspend(pd->dev); + if (ret < 0) { + /* put decremented usage even when suspend failed. */ + pm_runtime_get_noresume(pd->dev); + return ret; + } + } + pd->active = active; + return 0; +} + +static void atc_domain_release(void *data) +{ + struct atc_domain *pd = data; + + if (pd->active) + pm_runtime_put_sync_suspend(pd->dev); + dev_pm_domain_detach(pd->dev, true); +} + +/* The bootloader preloads CIO80 firmware into local SRAM. The firmware's + * data segment is 0x10000000..0x10010000, not guest system RAM. */ +static int atc_fw_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) +{ + struct t6050_dp *dp = cookie; + + if (bfr->iova < 0x10000000 || + bfr->size > 0x10000 || bfr->iova - 0x10000000 > 0x10000 - bfr->size) { + dev_err(dp->dev, "unsupported PHY firmware buffer %llx size %zx\n", + (unsigned long long)bfr->iova, bfr->size); + return -EINVAL; + } + bfr->iomem = dp->fw_data + (bfr->iova - 0x10000000); + bfr->is_mapped = true; + return 0; +} + +static void atc_fw_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +{ + /* SRAM is owned by the PHY and mapped for the device lifetime. */ +} + +static void atc_fw_message(void *cookie, u8 endpoint, u64 message) +{ + struct t6050_dp *dp = cookie; + + dev_dbg(dp->dev, "PHY firmware ep%x: %016llx\n", endpoint, message); +} + +static void atc_fw_crashed(void *cookie, const void *log, size_t size) +{ + struct t6050_dp *dp = cookie; + + WRITE_ONCE(dp->faulted, true); + dev_err(dp->dev, "PHY firmware crashed\n"); +} + +static const struct apple_rtkit_ops atc_fw_ops = { + .shmem_setup = atc_fw_shmem_setup, + .shmem_destroy = atc_fw_shmem_destroy, + .recv_message = atc_fw_message, + .crashed = atc_fw_crashed, +}; + +static int atc_firmware(struct t6050_dp *dp, bool start) +{ + int ret; + + if (!dp->rtkit) + return -ENODEV; + if (dp->fw_running == start) + return 0; + if (start) { + /* Native coprocessor run, after its +0x40 firmware enable. */ + writel(BIT(4), dp->banks[38] + 0x28); + ret = apple_rtkit_wake(dp->rtkit); + if (!ret) + ret = apple_rtkit_start_ep(dp->rtkit, 0x20); + } else { + /* CIO80PhyMBI::sendPowerDown, then the RTBuddy power transition. */ + ret = apple_rtkit_send_message(dp->rtkit, 0x20, BIT_ULL(56), NULL, false); + if (!ret) + ret = apple_rtkit_shutdown(dp->rtkit); + if (!ret) + writel((u32)~BIT(4), dp->banks[38] + 0x28); + } + if (ret) + dev_err(dp->dev, "PHY firmware %s failed: %d\n", start ? "start" : "stop", ret); + else + dp->fw_running = start; + return ret; +} + +static int atc_validate_step(struct t6050_dp *dp, const struct atc_op *s) +{ + if (s->op == ATC_DELAY) + return s->value <= 10000 ? 0 : -EINVAL; + if (s->op == ATC_POWER) + return s->value <= 1 ? 0 : -EINVAL; + if (s->op == ATC_FIRMWARE) + return dp->typec && s->value <= 1 ? 0 : -EINVAL; + if (s->bank >= ARRAY_SIZE(dp->banks) || !dp->banks[s->bank] || + s->offset % 4 || s->offset + 4 > resource_size(&dp->resources[s->bank])) + return -EINVAL; + if (s->op == ATC_TUNABLE) + return s->value < ARRAY_SIZE(tunable_names) && + tunable_names[s->value].bank == s->bank ? 0 : -EINVAL; + if (s->op == ATC_MASK || s->op == ATC_POLL) + return s->value & ~s->mask ? -EINVAL : 0; + return -EINVAL; +} + +static int atc_step(struct t6050_dp *dp, const struct atc_op *s) +{ + void __iomem *reg; + u32 value; + int ret = atc_validate_step(dp, s); + + if (ret) + return ret; + if (s->op == ATC_DELAY) { + udelay(s->value); + return 0; + } + if (s->op == ATC_FIRMWARE) + return atc_firmware(dp, s->value); + if (s->op == ATC_POWER) + return atc_domain_set(&dp->domain[2], s->value); + if (s->bank >= ARRAY_SIZE(dp->banks) || !dp->banks[s->bank] || + s->offset + 4 > resource_size(&dp->resources[s->bank])) + return -EINVAL; + reg = dp->banks[s->bank] + s->offset; + switch (s->op) { + case ATC_MASK: + value = readl(reg); + writel((value & ~s->mask) | s->value, reg); + return 0; + case ATC_TUNABLE: + if (s->value >= ARRAY_SIZE(dp->tunables)) + return -EINVAL; + apple_tunable_apply(dp->banks[s->bank], dp->tunables[s->value]); + return 0; + case ATC_POLL: + ret = readl_poll_timeout(reg, value, (value & s->mask) == s->value, + s->timeout > 1000 ? 1000 : 1, s->timeout); + if (ret) + dev_err(dp->dev, "bank%u+%x timeout: %x & %x != %x\n", + s->bank, s->offset, value, s->mask, s->value); + return ret; + default: + return -EINVAL; + } +} + +static int atc_sequence(struct t6050_dp *dp, const struct atc_op *s, size_t count) +{ + for (size_t i = 0; i < count; i++) { + int ret = atc_step(dp, &s[i]); + + if (ret) { + dp->faulted = true; + return ret; + } + } + return 0; +} +#define ATC_SEQUENCE(dp, seq) atc_sequence(dp, seq, ARRAY_SIZE(seq)) + +static int atc_link_rate(struct t6050_dp *dp, int rate) +{ + const struct atc_rate_op *on = dp_link_on; + size_t nr_on = ARRAY_SIZE(dp_link_on); + int ret; + + if (dp->multifunction) { + on = dp->reverse ? dp_group0_on : dp_group1_on; + nr_on = dp->reverse ? ARRAY_SIZE(dp_group0_on) : ARRAY_SIZE(dp_group1_on); + } + if (dp->rate == rate) + return 0; + if (dp->rate >= 0) { + if (dp->multifunction) + ret = dp->reverse ? ATC_SEQUENCE(dp, dp_group0_off) : + ATC_SEQUENCE(dp, dp_group1_off); + else + ret = ATC_SEQUENCE(dp, dp_link_off); + if (ret) + return ret; + dp->rate = -1; + } + if (rate < 0) + return 0; + for (size_t i = 0; i < nr_on; i++) { + struct atc_op op = on[i].op; + + if (!(on[i].rates & BIT(rate))) + continue; + op.value = on[i].values[rate]; + ret = atc_step(dp, &op); + if (ret) { + dp->faulted = true; + return ret; + } + } + dp->rate = rate; + memset(dp->voltage, 0, sizeof(dp->voltage)); + memset(dp->pre, 0, sizeof(dp->pre)); + return 0; +} + +static int atc_start(struct t6050_dp *dp) +{ + int ret; + + if (dp->faulted) + return -EIO; + if (dp->enabled) + return 0; + ret = atc_domain_set(&dp->domain[0], true); + if (ret) + return ret; + ret = atc_domain_set(&dp->domain[1], true); + if (ret) { + atc_domain_set(&dp->domain[0], false); + return ret; + } + if (dp->multifunction) + ret = dp->reverse ? ATC_SEQUENCE(dp, mf_reverse_init) : + ATC_SEQUENCE(dp, mf_normal_init); + else + ret = dp->reverse ? ATC_SEQUENCE(dp, dp_reverse_init) : + ATC_SEQUENCE(dp, dp_init); + if (!ret) + ret = ATC_SEQUENCE(dp, aux_on); + if (ret) + return ret; + dp->enabled = true; + return 0; +} + +static int atc_stop(struct t6050_dp *dp) +{ + int ret; + + if (dp->faulted) + return -EIO; + if (!dp->enabled) + return 0; + ret = atc_link_rate(dp, -1); + if (!ret) + ret = ATC_SEQUENCE(dp, aux_off); + if (!ret) + ret = dp->multifunction ? ATC_SEQUENCE(dp, mf_poweroff) : + ATC_SEQUENCE(dp, dp_poweroff); + if (ret) + return ret; + dp->enabled = false; + /* Combo owns domain shutdown after USB2 and PIPE have also quiesced. */ + if (dp->combo) + return 0; + ret = atc_domain_set(&dp->domain[1], false); + if (!ret) + ret = atc_domain_set(&dp->domain[0], false); + return ret; +} + +static void atc_mask(void __iomem *reg, u32 mask, u32 value) +{ + writel((readl(reg) & ~mask) | value, reg); +} + +static void atc_drive(struct t6050_dp *dp, unsigned int lane, u32 preset) +{ + /* Native DP lane order is RX/TX in each orientation-selected group. */ + unsigned int group = (lane < 2 ? 1 : 0) ^ dp->reverse; + bool tx = lane & 1; + void __iomem *base = dp->banks[(tx ? 21 : 20) + 9 * group]; + u32 ctrl = ((preset >> 2) & 0xf) | ((preset & 3) << 14); + u32 eq = ((preset >> 5) & 0x7fffe) | 1; + + if (tx) + atc_mask(base + 0x100, BIT(20), BIT(20)); + atc_mask(base + (tx ? 0x58 : 0x68), 0xc00f, ctrl); + atc_mask(base + (tx ? 0x104 : 0xac), BIT(29), BIT(29)); + atc_mask(base + (tx ? 0x100 : 0xa8), 0x7ffff, eq); +} + +#include "atc-t6050-combo.h" + +static int t6050_dp_set_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + + guard(mutex)(&dp->lock); + if (mode == PHY_MODE_DP) + return dp->typec ? (dp->enabled ? 0 : -ENOLINK) : atc_start(dp); + if (mode == PHY_MODE_INVALID) + return dp->combo ? atc_link_rate(dp, -1) : atc_stop(dp); + return -EINVAL; +} + +static int t6050_dp_validate(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + + guard(mutex)(&dp->lock); + if (mode != PHY_MODE_DP) + return -EINVAL; + memset(opts, 0, sizeof(*opts)); + opts->dp.lanes = dp->multifunction ? 2 : 4; + opts->dp.link_rate = 8100; + opts->dp.ssc = 0; + return 0; +} + +static int t6050_dp_configure(struct phy *phy, union phy_configure_opts *opts) +{ + struct t6050_dp *dp = phy_get_drvdata(phy); + struct phy_configure_opts_dp *cfg = &opts->dp; + int rate = -1, ret; + + /* Validate the whole request before altering a running transmitter. */ + if (cfg->set_rate && cfg->link_rate) { + for (unsigned int i = 0; i < ARRAY_SIZE(link_rates); i++) + if (cfg->link_rate == link_rates[i]) + rate = i; + if (rate < 0 || cfg->ssc) + return -EINVAL; + } + if ((cfg->set_lanes || cfg->set_voltages) && + cfg->lanes != 0 && cfg->lanes != 1 && cfg->lanes != 2 && cfg->lanes != 4) + return -EINVAL; + if (cfg->set_voltages) + for (unsigned int i = 0; i < cfg->lanes; i++) + if (cfg->voltage[i] > 3 || cfg->pre[i] > 3 || + cfg->voltage[i] + cfg->pre[i] > 3) + return -EINVAL; + if (cfg->set_voltages && cfg->set_rate && rate < 0 && cfg->lanes) + return -EINVAL; + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (!dp->enabled) + return -EPIPE; + if ((cfg->set_lanes || cfg->set_voltages) && dp->multifunction && cfg->lanes > 2) + return -EINVAL; + if (cfg->set_rate) { + ret = atc_link_rate(dp, rate); + if (ret) + return ret; + } + /* Native setActiveLaneCount is a no-op; DCP controls the active count. */ + if (cfg->set_voltages) { + if (dp->rate < 0) + return -EPIPE; + for (unsigned int i = 0; i < cfg->lanes; i++) { + u32 preset = dp->training[dp->rate][4 * cfg->voltage[i] + cfg->pre[i]]; + + atc_drive(dp, i, preset); + dp->voltage[i] = cfg->voltage[i]; + dp->pre[i] = cfg->pre[i]; + } + } + return 0; +} + +static const struct phy_ops t6050_dp_ops = { + .set_mode = t6050_dp_set_mode, + .validate = t6050_dp_validate, + .configure = t6050_dp_configure, + .owner = THIS_MODULE, +}; + +int apple_dp_phy_link_config(struct phy *phy, unsigned int *pclk, bool *uhbr) +{ + struct t6050_dp *dp; + + if (!phy || phy->ops != &t6050_dp_ops) + return -EOPNOTSUPP; + dp = phy_get_drvdata(phy); + guard(mutex)(&dp->lock); + if (dp->faulted) + return -EIO; + if (!dp->enabled || dp->rate < 0) + return -ENOLINK; + /* Native direct DPPHY uses logical clock0, mapped to xbar PCLK1. + * The other four logical clocks are separately managed tunnel clocks. */ + *pclk = 1; + *uhbr = false; + return 0; +} +EXPORT_SYMBOL_GPL(apple_dp_phy_link_config); + +/* The connector sets orientation before changing the alternate-mode mux. */ +static int t6050_set_orientation(struct t6050_dp *dp, + enum typec_orientation orientation) +{ + bool reverse = orientation == TYPEC_ORIENTATION_REVERSE; + int ret; + + if (dp->combo) + return combo_orientation(dp, orientation); + guard(mutex)(&dp->lock); + if (orientation == TYPEC_ORIENTATION_NONE) + return atc_stop(dp); + if (dp->reverse == reverse) + return 0; + ret = atc_stop(dp); + if (!ret) + dp->reverse = reverse; + return ret; +} + +static int t6050_set_typec_mode(struct t6050_dp *dp, struct typec_mux_state *state) +{ + bool multifunction; + int ret; + + if (dp->combo) + return combo_mux(dp, state); + guard(mutex)(&dp->lock); + if (state->mode == TYPEC_STATE_SAFE) + return atc_stop(dp); + /* USB-only and USB4 require their controller's separate PHY interface. */ + if (!state->alt || state->alt->svid != USB_TYPEC_DP_SID) + return -EOPNOTSUPP; + switch (state->mode) { + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_E: + multifunction = false; + break; + case TYPEC_DP_STATE_D: + multifunction = true; + break; + default: + return -EOPNOTSUPP; + } + if (dp->enabled && dp->multifunction == multifunction) + return 0; + ret = atc_stop(dp); + if (ret) + return ret; + dp->multifunction = multifunction; + ret = atc_start(dp); + if (!ret) + dev_info(dp->dev, "Type-C DP: %u lanes, %s orientation\n", + multifunction ? 2 : 4, dp->reverse ? "reverse" : "normal"); + return ret; +} + +static int t6050_typec_orientation(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + return t6050_set_orientation(typec_switch_get_drvdata(sw), orientation); +} + +static int t6050_typec_mode(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + return t6050_set_typec_mode(typec_mux_get_drvdata(mux), state); +} + +static void t6050_typec_switch_release(void *data) +{ + typec_switch_unregister(data); +} + +static void t6050_typec_mux_release(void *data) +{ + typec_mux_unregister(data); +} + +static int t6050_typec_register(struct t6050_dp *dp) +{ + struct typec_switch_desc sw_desc = { + .fwnode = dev_fwnode(dp->dev), .drvdata = dp, + .set = t6050_typec_orientation, + }; + struct typec_mux_desc mux_desc = { + .fwnode = dev_fwnode(dp->dev), .drvdata = dp, + .set = t6050_typec_mode, + }; + struct typec_switch_dev *sw; + struct typec_mux_dev *mux; + int ret; + + sw = typec_switch_register(dp->dev, &sw_desc); + if (IS_ERR(sw)) + return PTR_ERR(sw); + ret = devm_add_action_or_reset(dp->dev, t6050_typec_switch_release, sw); + if (ret) + return ret; + mux = typec_mux_register(dp->dev, &mux_desc); + if (IS_ERR(mux)) + return PTR_ERR(mux); + return devm_add_action_or_reset(dp->dev, t6050_typec_mux_release, mux); +} + +static int t6050_dp_probe(struct platform_device *pdev) +{ + static const char * const domains[] = {"usb-aon", "common", "wrapper"}; + struct device *dev = &pdev->dev; + struct t6050_dp *dp; + struct phy_provider *provider; + struct phy *phy; + struct resource *core; + void __iomem *base; + int ret; + + dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); + if (!dp) + return -ENOMEM; + dp->dev = dev; + dp->combo = of_device_is_compatible(dev->of_node, "apple,t6050-combo-phy"); + if (dp->combo) { + u32 port; + if (of_property_read_u32(dev->of_node, "apple,port-index", &port) || + (port != 1 && port != 2) || + !of_property_present(dev->of_node, "apple,guest-port-reserved") || + !of_property_present(dev->of_node, "mode-switch")) + return -EINVAL; + } + dp->typec = of_property_present(dev->of_node, "mode-switch"); + dp->rate = -1; + mutex_init(&dp->lock); + platform_set_drvdata(pdev, dp); + core = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!core || resource_size(core) < (dp->combo ? 0x2c000 : 0x2c400)) + return -EINVAL; + base = devm_ioremap_resource(dev, core); + if (IS_ERR(base)) + return PTR_ERR(base); + for (unsigned int i = 0; i < ARRAY_SIZE(core_banks); i++) { + u8 bank = core_banks[i].bank; + + dp->banks[bank] = base + core_banks[i].offset; + dp->resources[bank] = *core; + dp->resources[bank].start += core_banks[i].offset; + dp->resources[bank].end = core->end; + } + for (unsigned int i = 0; i < ARRAY_SIZE(extra_banks); i++) { + u8 bank = extra_banks[i].bank; + struct resource *res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + extra_banks[i].name); + + if (bank == 38 && !dp->typec) + continue; + if (!res || resource_size(res) < 4) + return -EINVAL; + dp->banks[bank] = devm_ioremap_resource(dev, res); + if (IS_ERR(dp->banks[bank])) + return PTR_ERR(dp->banks[bank]); + dp->resources[bank] = *res; + } + /* Check every register step before any domain is enabled. */ + { + static const struct { const struct atc_op *ops; size_t count; } sequences[] = { + { dp_init, ARRAY_SIZE(dp_init) }, + { aux_on, ARRAY_SIZE(aux_on) }, + { aux_off, ARRAY_SIZE(aux_off) }, + { dp_link_off, ARRAY_SIZE(dp_link_off) }, + { dp_poweroff, ARRAY_SIZE(dp_poweroff) }, + }; + + for (unsigned int i = 0; i < ARRAY_SIZE(sequences); i++) + for (size_t j = 0; j < sequences[i].count; j++) { + ret = atc_validate_step(dp, &sequences[i].ops[j]); + if (ret) + return ret; + } + for (unsigned int i = 0; i < ARRAY_SIZE(dp_link_on); i++) + for (unsigned int rate = 0; rate < ARRAY_SIZE(link_rates); rate++) { + struct atc_op op = dp_link_on[i].op; + + if (!(dp_link_on[i].rates & BIT(rate))) + continue; + op.value = dp_link_on[i].values[rate]; + ret = atc_validate_step(dp, &op); + if (ret) + return ret; + } + } + if (dp->typec) { + static const struct { const struct atc_op *ops; size_t count; } sequences[] = { + { dp_reverse_init, ARRAY_SIZE(dp_reverse_init) }, + { mf_normal_init, ARRAY_SIZE(mf_normal_init) }, + { mf_reverse_init, ARRAY_SIZE(mf_reverse_init) }, + { mf_poweroff, ARRAY_SIZE(mf_poweroff) }, + { dp_group0_off, ARRAY_SIZE(dp_group0_off) }, + { dp_group1_off, ARRAY_SIZE(dp_group1_off) }, + }; + const struct atc_rate_op *rates[] = { dp_group0_on, dp_group1_on }; + const size_t counts[] = { ARRAY_SIZE(dp_group0_on), ARRAY_SIZE(dp_group1_on) }; + + for (unsigned int i = 0; i < ARRAY_SIZE(sequences); i++) + for (size_t j = 0; j < sequences[i].count; j++) { + ret = atc_validate_step(dp, &sequences[i].ops[j]); + if (ret) + return ret; + } + for (unsigned int group = 0; group < ARRAY_SIZE(rates); group++) + for (size_t i = 0; i < counts[group]; i++) + for (unsigned int rate = 0; rate < ARRAY_SIZE(link_rates); rate++) { + struct atc_op op = rates[group][i].op; + if (!(rates[group][i].rates & BIT(rate))) + continue; + op.value = rates[group][i].values[rate]; + ret = atc_validate_step(dp, &op); + if (ret) + return ret; + } + } + for (unsigned int i = 0; i < ARRAY_SIZE(tunable_names); i++) { + if (i >= 9 && !dp->typec) + continue; + dp->tunables[i] = devm_apple_tunable_parse(dev, dev->of_node, + tunable_names[i].name, &dp->resources[tunable_names[i].bank]); + if (IS_ERR(dp->tunables[i])) + return dev_err_probe(dev, PTR_ERR(dp->tunables[i]), + "missing or invalid %s\n", tunable_names[i].name); + } + for (unsigned int i = 0; i < ARRAY_SIZE(training_names); i++) { + const char *name = training_names[i]; + + if (!of_property_present(dev->of_node, name)) + name = "apple,dp-training-table"; + if (!of_property_present(dev->of_node, name)) { + memcpy(dp->training[i], dp_training_default, sizeof(dp_training_default)); + continue; + } + if (of_property_count_u32_elems(dev->of_node, name) != 16) + return -EINVAL; + ret = of_property_read_u32_array(dev->of_node, name, dp->training[i], 16); + if (ret) + return ret; + } + /* Three named domains prevent automatic wrapper enable at probe time. */ + if (of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells") != 3) + return -EINVAL; + for (unsigned int i = 0; i < ARRAY_SIZE(domains); i++) { + dp->domain[i].dev = dev_pm_domain_attach_by_name(dev, domains[i]); + if (IS_ERR_OR_NULL(dp->domain[i].dev)) + return dev_err_probe(dev, dp->domain[i].dev ? PTR_ERR(dp->domain[i].dev) : -ENODEV, + "cannot attach %s domain\n", domains[i]); + ret = devm_add_action_or_reset(dev, atc_domain_release, &dp->domain[i]); + if (ret) + return ret; + } + if (dp->typec) { + dp->fw_data = devm_platform_ioremap_resource_byname(pdev, "firmware-data"); + if (IS_ERR(dp->fw_data)) + return PTR_ERR(dp->fw_data); + dp->rtkit = devm_apple_rtkit_init(dev, dp, NULL, 0, &atc_fw_ops); + if (IS_ERR(dp->rtkit)) + return dev_err_probe(dev, PTR_ERR(dp->rtkit), "cannot initialize PHY firmware IPC\n"); + } + if (dp->combo) { + ret = combo_setup(pdev, dp); + if (ret) + return ret; + } + phy = devm_phy_create(dev, NULL, &t6050_dp_ops); + if (IS_ERR(phy)) + return PTR_ERR(phy); + phy_set_drvdata(phy, dp); + dp->combo_phy[2] = phy; + provider = devm_of_phy_provider_register(dev, dp->combo ? combo_xlate : of_phy_simple_xlate); + if (IS_ERR(provider)) + return PTR_ERR(provider); + return dp->typec ? t6050_typec_register(dp) : 0; +} + +static void t6050_dp_shutdown(struct platform_device *pdev) +{ + struct t6050_dp *dp = platform_get_drvdata(pdev); + + guard(mutex)(&dp->lock); + if (dp->combo ? combo_stop(dp) : atc_stop(dp)) + dev_warn(dp->dev, "PHY shutdown incomplete after an earlier error\n"); +} + +static const struct of_device_id t6050_dp_match[] = { + { .compatible = "apple,t6050-dp-phy" }, + { .compatible = "apple,t6050-combo-phy" }, + {}, +}; +MODULE_DEVICE_TABLE(of, t6050_dp_match); +static struct platform_driver t6050_dp_driver = { + .probe = t6050_dp_probe, + .remove = t6050_dp_shutdown, + .shutdown = t6050_dp_shutdown, + .driver = { + .name = "apple-t6050-dp-phy", + .of_match_table = t6050_dp_match, + }, +}; +module_platform_driver(t6050_dp_driver); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Apple T6050 DisplayPort and Type-C USB combo PHY"); diff --git a/drivers/phy/apple/atc-t6050-typec-data.h b/drivers/phy/apple/atc-t6050-typec-data.h new file mode 100644 index 0000000000000..096307b657c08 --- /dev/null +++ b/drivers/phy/apple/atc-t6050-typec-data.h @@ -0,0 +1,700 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* Native firmware27 Type-C DP recipes; board tunables remain DT data. */ +static const struct atc_op dp_reverse_init[] = { + { ATC_MASK, 39, 0x0, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x1, 0x1, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x2, 0x2, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x2, 0x2, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POWER, 2, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x2c, 0x1, 0x0, 0 }, + { ATC_POLL, 39, 0x4, 0x100, 0x0, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x8, 0x8, 0 }, + { ATC_TUNABLE, 41, 0x0, 0x0, 0x0, 0 }, + { ATC_TUNABLE, 40, 0x0, 0x0, 0x1, 0 }, + { ATC_TUNABLE, 43, 0x0, 0x0, 0x2, 0 }, + { ATC_TUNABLE, 42, 0x0, 0x0, 0x3, 0 }, + { ATC_TUNABLE, 20, 0x0, 0x0, 0x4, 0 }, + { ATC_TUNABLE, 29, 0x0, 0x0, 0x5, 0 }, + { ATC_TUNABLE, 18, 0x0, 0x0, 0x6, 0 }, + { ATC_TUNABLE, 27, 0x0, 0x0, 0x7, 0 }, + { ATC_MASK, 4, 0x0, 0x3f0, 0x1c0, 0 }, + { ATC_MASK, 4, 0x18, 0xf000, 0x3000, 0 }, + { ATC_MASK, 9, 0x88, 0xff, 0x27, 0 }, + { ATC_MASK, 33, 0x4, 0x38, 0x8, 0 }, + { ATC_MASK, 10, 0xdc, 0x3ff0, 0x1760, 0 }, + { ATC_MASK, 21, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 30, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 20, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 29, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_TUNABLE, 8, 0x0, 0x0, 0x8, 0 }, + { ATC_MASK, 2, 0x6c, 0x3c000fc, 0x48, 0 }, + { ATC_MASK, 2, 0x78, 0x1f, 0x14, 0 }, + { ATC_MASK, 2, 0x78, 0x3ffe0, 0x100, 0 }, + { ATC_MASK, 2, 0x6c, 0x3, 0x2, 0 }, + { ATC_MASK, 2, 0xc, 0x2a, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 39, 0x0, 0x10, 0x10, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x64, 0 }, +}; + +static const struct atc_op mf_normal_init[] = { + { ATC_MASK, 39, 0x0, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x1, 0x1, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x2, 0x2, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x2, 0x2, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POWER, 2, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x2c, 0x1, 0x0, 0 }, + { ATC_POLL, 39, 0x4, 0x100, 0x0, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x8, 0x8, 0 }, + { ATC_TUNABLE, 41, 0x0, 0x0, 0x0, 0 }, + { ATC_TUNABLE, 40, 0x0, 0x0, 0x1, 0 }, + { ATC_TUNABLE, 43, 0x0, 0x0, 0x2, 0 }, + { ATC_TUNABLE, 42, 0x0, 0x0, 0x3, 0 }, + { ATC_TUNABLE, 20, 0x0, 0x0, 0x4, 0 }, + { ATC_TUNABLE, 29, 0x0, 0x0, 0x5, 0 }, + { ATC_TUNABLE, 18, 0x0, 0x0, 0x6, 0 }, + { ATC_TUNABLE, 27, 0x0, 0x0, 0x7, 0 }, + { ATC_TUNABLE, 5, 0x0, 0x0, 0x9, 0 }, + { ATC_TUNABLE, 8, 0x0, 0x0, 0x8, 0 }, + { ATC_TUNABLE, 10, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 4, 0x0, 0x3f0, 0x1c0, 0 }, + { ATC_MASK, 4, 0x18, 0xf000, 0x3000, 0 }, + { ATC_MASK, 9, 0x88, 0xff, 0x27, 0 }, + { ATC_MASK, 33, 0x4, 0x38, 0x8, 0 }, + { ATC_MASK, 10, 0xdc, 0x3ff0, 0x1760, 0 }, + { ATC_MASK, 21, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 30, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 20, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 29, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_TUNABLE, 8, 0x0, 0x0, 0x8, 0 }, + { ATC_MASK, 2, 0x6c, 0x28000fc, 0x44, 0 }, + { ATC_MASK, 2, 0x78, 0x1ffff, 0x110, 0 }, + { ATC_MASK, 2, 0x6c, 0x3, 0x2, 0 }, + { ATC_MASK, 2, 0xc, 0x2a, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x40, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x10000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x100, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x1000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x40, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x400, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x8, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 38, 0x40, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_FIRMWARE, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1388, 0 }, + { ATC_POLL, 2, 0x260, 0x400, 0x400, 1000000 }, + { ATC_MASK, 39, 0x0, 0x10, 0x10, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x64, 0 }, +}; + +static const struct atc_op mf_reverse_init[] = { + { ATC_MASK, 39, 0x0, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x1, 0x1, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x2, 0x2, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x2, 0x2, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POWER, 2, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x2c, 0x1, 0x0, 0 }, + { ATC_POLL, 39, 0x4, 0x100, 0x0, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x8, 0x8, 0 }, + { ATC_TUNABLE, 41, 0x0, 0x0, 0x0, 0 }, + { ATC_TUNABLE, 40, 0x0, 0x0, 0x1, 0 }, + { ATC_TUNABLE, 43, 0x0, 0x0, 0x2, 0 }, + { ATC_TUNABLE, 42, 0x0, 0x0, 0x3, 0 }, + { ATC_TUNABLE, 20, 0x0, 0x0, 0x4, 0 }, + { ATC_TUNABLE, 29, 0x0, 0x0, 0x5, 0 }, + { ATC_TUNABLE, 18, 0x0, 0x0, 0x6, 0 }, + { ATC_TUNABLE, 27, 0x0, 0x0, 0x7, 0 }, + { ATC_TUNABLE, 5, 0x0, 0x0, 0x9, 0 }, + { ATC_TUNABLE, 8, 0x0, 0x0, 0x8, 0 }, + { ATC_TUNABLE, 10, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 4, 0x0, 0x3f0, 0x1c0, 0 }, + { ATC_MASK, 4, 0x18, 0xf000, 0x3000, 0 }, + { ATC_MASK, 9, 0x88, 0xff, 0x27, 0 }, + { ATC_MASK, 33, 0x4, 0x38, 0x8, 0 }, + { ATC_MASK, 10, 0xdc, 0x3ff0, 0x1760, 0 }, + { ATC_MASK, 21, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 30, 0xcc, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 20, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_MASK, 29, 0x90, 0x1f80000, 0x380000, 0 }, + { ATC_TUNABLE, 8, 0x0, 0x0, 0x8, 0 }, + { ATC_MASK, 2, 0x6c, 0x14000fc, 0x28, 0 }, + { ATC_MASK, 2, 0x78, 0x1ffff, 0x111, 0 }, + { ATC_MASK, 2, 0x6c, 0x3, 0x2, 0 }, + { ATC_MASK, 2, 0xc, 0x2a, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x8, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x80, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x20000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x200, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x2000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x80, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x8, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x800, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x8, 0x2, 0x2, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 38, 0x40, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_FIRMWARE, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1388, 0 }, + { ATC_POLL, 2, 0x260, 0x400, 0x400, 1000000 }, + { ATC_MASK, 39, 0x0, 0x10, 0x10, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x64, 0 }, +}; + +static const struct atc_op mf_poweroff[] = { + { ATC_MASK, 35, 0x4, 0x1, 0x1, 0 }, + { ATC_MASK, 35, 0x10c, 0x100000, 0x0, 0 }, + { ATC_MASK, 35, 0x110, 0x60, 0x20, 0 }, + { ATC_MASK, 35, 0x4, 0x8, 0x8, 0 }, + { ATC_MASK, 35, 0x4, 0x8, 0x0, 0 }, + { ATC_POLL, 35, 0x104, 0x100, 0x100, 1000000 }, + { ATC_MASK, 35, 0x10c, 0x1e000000, 0x4000000, 0 }, + { ATC_MASK, 35, 0x110, 0x600, 0x200, 0 }, + { ATC_MASK, 35, 0x4, 0x8, 0x8, 0 }, + { ATC_MASK, 35, 0x4, 0x8, 0x0, 0 }, + { ATC_POLL, 35, 0x104, 0x100, 0x100, 1000000 }, + { ATC_MASK, 35, 0x4, 0x1, 0x0, 0 }, + { ATC_MASK, 2, 0x120, 0x100, 0x100, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x200, 0x200, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x20, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 5, 0x0, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x10, 0x10, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xc8, 0 }, + { ATC_FIRMWARE, 0, 0x0, 0x0, 0x0, 0 }, + { ATC_POWER, 2, 0x0, 0x0, 0x0, 0 }, + { ATC_MASK, 39, 0x2c, 0x1, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x100, 0x100, 1000 }, + { ATC_MASK, 39, 0x0, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x8, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x4, 0x4, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x2, 0x0, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x0, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_POLL, 39, 0x4, 0x1, 0x0, 1000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 39, 0x8, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, +}; + +static const struct atc_op dp_group0_off[] = { + { ATC_MASK, 39, 0x14, 0x1007, 0x7, 0 }, + { ATC_MASK, 39, 0x18, 0x1, 0x0, 0 }, + { ATC_POLL, 39, 0x1c, 0x1, 0x0, 5000 }, + { ATC_MASK, 14, 0x0, 0x1, 0x1, 0 }, + { ATC_MASK, 22, 0x1c, 0xc00000, 0xc00000, 0 }, + { ATC_MASK, 22, 0x10, 0x600, 0x400, 0 }, + { ATC_MASK, 22, 0x4, 0x30000000, 0x20000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 22, 0x44, 0x100000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 22, 0x44, 0x400000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 22, 0x44, 0x4000000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 22, 0x44, 0x1000000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 22, 0x44, 0x1000, 0x0, 0 }, + { ATC_MASK, 2, 0x120, 0x100, 0x100, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 19, 0x44, 0x6000000, 0x4000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 19, 0x44, 0x18000000, 0x10000000, 0 }, + { ATC_MASK, 19, 0x24, 0xc0000000, 0x80000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 19, 0x24, 0x30000000, 0x20000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 19, 0x28, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 19, 0x40, 0xc000, 0xc000, 0 }, + { ATC_MASK, 16, 0x1d0, 0x3, 0x1, 0 }, + { ATC_MASK, 19, 0x40, 0x10000, 0x0, 0 }, + { ATC_MASK, 2, 0xc, 0x4000, 0x4000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x40, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x400, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 14, 0x0, 0xc, 0x8, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x40000, 0x40000, 0 }, + { ATC_MASK, 3, 0x8, 0x1, 0x1, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x80000, 0x0, 0 }, + { ATC_MASK, 3, 0x8, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x80000, 0x80000, 0 }, + { ATC_MASK, 3, 0x8, 0x2, 0x2, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x40000, 0x0, 0 }, + { ATC_MASK, 3, 0x8, 0x1, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x7, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x8, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x100, 500000 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x0, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x0, 500000 }, + { ATC_POLL, 14, 0x34, 0x8, 0x0, 500000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 6, 0x34, 0xf, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x7, 0x0, 0 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x8, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x100, 500000 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x0, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x0, 500000 }, + { ATC_MASK, 8, 0x0, 0xaaa, 0x0, 0 }, +}; + +static const struct atc_rate_op dp_group0_on[] = { + { { ATC_MASK, 39, 0x14, 0x7, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 39, 0x18, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x6c, 0x1c, 0, 0 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_MASK, 14, 0x0, 0x40fff0, 0, 0 }, 0xf, { 0x1110, 0x1110, 0x1110, 0x1110 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x1, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x1, { 0x1e0e021c, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x1, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x1, { 0x156600, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x1, { 0x70000, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x1, { 0x1, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x2, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x2, { 0x0, 0x1e0e01c2, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x2, { 0x0, 0x7fffffe, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x2, { 0x0, 0x155200, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x2, { 0x0, 0x70000, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x2, { 0x0, 0x1, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x4, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x1e0e01c2, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x7fffffe, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x554800, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x4, { 0x0, 0x0, 0x70000, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x4, { 0x0, 0x0, 0x1, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x1e0e02a3 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0xbff7ffc } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x564800 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x70000 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x1 } }, + { { ATC_MASK, 8, 0x0, 0xaaa, 0, 0 }, 0xf, { 0xaaa, 0xaaa, 0xaaa, 0xaaa } }, + { { ATC_MASK, 6, 0x30, 0x4000, 0, 0 }, 0xf, { 0x4000, 0x4000, 0x4000, 0x4000 } }, + { { ATC_MASK, 6, 0x34, 0xf, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 6, 0x18, 0x1fe000, 0, 0 }, 0xf, { 0x2000, 0x2000, 0x2000, 0x2000 } }, + { { ATC_MASK, 6, 0x20, 0x1, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 6, 0x1c, 0x7, 0, 0 }, 0xf, { 0x7, 0x7, 0x7, 0x7 } }, + { { ATC_MASK, 6, 0x1c, 0x8, 0, 0 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_POLL, 6, 0x2c, 0xff00, 0, 500000 }, 0xf, { 0x100, 0x100, 0x100, 0x100 } }, + { { ATC_MASK, 6, 0x1c, 0x8, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 6, 0x2c, 0xff00, 0, 500000 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 14, 0x34, 0x8, 0, 500000 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_MASK, 19, 0x3c, 0x18000, 0, 0 }, 0xf, { 0x10000, 0x10000, 0x10000, 0x10000 } }, + { { ATC_MASK, 14, 0x0, 0xc, 0, 0 }, 0xf, { 0xc, 0xc, 0xc, 0xc } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x10, 0, 0 }, 0xf, { 0x10, 0x10, 0x10, 0x10 } }, + { { ATC_MASK, 2, 0x120, 0x40, 0, 0 }, 0xf, { 0x40, 0x40, 0x40, 0x40 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x4, 0, 0 }, 0xf, { 0x4, 0x4, 0x4, 0x4 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x100, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 2, 0x120, 0x400, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0xfffffc0, 0, 0 }, 0xf, { 0xaafb800, 0xaafb800, 0xaafb800, 0xaafb800 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0x1000000, 0, 0 }, 0xf, { 0x1000000, 0x1000000, 0x1000000, 0x1000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0x4000000, 0, 0 }, 0xf, { 0x4000000, 0x4000000, 0x4000000, 0x4000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0x7c0, 0, 0 }, 0xf, { 0x300, 0x300, 0x300, 0x300 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0x6c000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 21, 0x100, 0x100000, 0, 0 }, 0xf, { 0x100000, 0x100000, 0x100000, 0x100000 } }, + { { ATC_MASK, 21, 0x58, 0xc00f, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 21, 0x104, 0x20000000, 0, 0 }, 0xf, { 0x20000000, 0x20000000, 0x20000000, 0x20000000 } }, + { { ATC_MASK, 21, 0x100, 0x7ffff, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 22, 0x44, 0x100000, 0, 0 }, 0x7, { 0x100000, 0x100000, 0x100000, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0x7, { 0x1, 0x1, 0x1, 0x0 } }, + { { ATC_MASK, 22, 0x44, 0x400000, 0, 0 }, 0x7, { 0x400000, 0x400000, 0x400000, 0x0 } }, + { { ATC_MASK, 22, 0x4, 0x3000000, 0, 0 }, 0xf, { 0x2000000, 0x2000000, 0x2000000, 0x2000000 } }, + { { ATC_MASK, 22, 0x4, 0x30000000, 0, 0 }, 0xf, { 0x30000000, 0x30000000, 0x30000000, 0x30000000 } }, + { { ATC_MASK, 22, 0xc, 0x7000000, 0, 0 }, 0x1, { 0x5000000, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 22, 0xc, 0x7000000, 0, 0 }, 0xe, { 0x0, 0x4000000, 0x4000000, 0x4000000 } }, + { { ATC_MASK, 22, 0x8, 0x3, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 22, 0x10, 0x600, 0, 0 }, 0xf, { 0x600, 0x600, 0x600, 0x600 } }, + { { ATC_MASK, 22, 0x1c, 0xc00000, 0, 0 }, 0xf, { 0x800000, 0x800000, 0x800000, 0x800000 } }, + { { ATC_MASK, 19, 0xf4, 0x3000, 0, 0 }, 0xf, { 0x3000, 0x3000, 0x3000, 0x3000 } }, + { { ATC_MASK, 16, 0x188, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 16, 0x1d4, 0x700, 0, 0 }, 0xf, { 0x300, 0x300, 0x300, 0x300 } }, + { { ATC_MASK, 19, 0x24, 0x3f0000, 0, 0 }, 0xf, { 0x2a0000, 0x2a0000, 0x2a0000, 0x2a0000 } }, + { { ATC_MASK, 19, 0x3c, 0x18000, 0, 0 }, 0xf, { 0x10000, 0x10000, 0x10000, 0x10000 } }, + { { ATC_MASK, 19, 0x78, 0xc0000, 0, 0 }, 0xf, { 0x80000, 0x80000, 0x80000, 0x80000 } }, + { { ATC_MASK, 19, 0x7c, 0xc0, 0, 0 }, 0xf, { 0x80, 0x80, 0x80, 0x80 } }, + { { ATC_MASK, 19, 0x84, 0xc000, 0, 0 }, 0xf, { 0x8000, 0x8000, 0x8000, 0x8000 } }, + { { ATC_MASK, 19, 0xd4, 0x600000, 0, 0 }, 0xf, { 0x400000, 0x400000, 0x400000, 0x400000 } }, + { { ATC_MASK, 19, 0xd8, 0x300, 0, 0 }, 0xf, { 0x200, 0x200, 0x200, 0x200 } }, + { { ATC_MASK, 19, 0x40, 0xc00, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_MASK, 19, 0x48, 0x600, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_MASK, 19, 0x28, 0x1ff030, 0, 0 }, 0xf, { 0x11c020, 0x11c020, 0x11c020, 0x11c020 } }, + { { ATC_MASK, 19, 0x2c, 0xfc, 0, 0 }, 0xf, { 0xb0, 0xb0, 0xb0, 0xb0 } }, + { { ATC_MASK, 19, 0x28, 0xe00, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_MASK, 19, 0x28, 0x1c0, 0, 0 }, 0xf, { 0x180, 0x180, 0x180, 0x180 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x10, 0x10, 0, 0 }, 0xf, { 0x10, 0x10, 0x10, 0x10 } }, + { { ATC_MASK, 2, 0x10, 0x40, 0, 0 }, 0xf, { 0x40, 0x40, 0x40, 0x40 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x10, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x10, 0x4, 0, 0 }, 0xf, { 0x4, 0x4, 0x4, 0x4 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x400, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_MASK, 2, 0xc, 0x1000, 0, 0 }, 0xf, { 0x1000, 0x1000, 0x1000, 0x1000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x40, 0, 0 }, 0xf, { 0x40, 0x40, 0x40, 0x40 } }, + { { ATC_MASK, 2, 0xc, 0x100, 0, 0 }, 0xf, { 0x100, 0x100, 0x100, 0x100 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x4000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 2, 0xc, 0x10000, 0, 0 }, 0xf, { 0x10000, 0x10000, 0x10000, 0x10000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 16, 0x1d0, 0x3, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 16, 0x1d0, 0x2, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x40, 0x30000, 0, 0 }, 0xf, { 0x30000, 0x30000, 0x30000, 0x30000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x40, 0xc000, 0, 0 }, 0xf, { 0xc000, 0xc000, 0xc000, 0xc000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x3010, 0, 0 }, 0xf, { 0x1010, 0x1010, 0x1010, 0x1010 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x600, 0, 0 }, 0xf, { 0x200, 0x200, 0x200, 0x200 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x3000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x24, 0x30000000, 0, 0 }, 0xf, { 0x30000000, 0x30000000, 0x30000000, 0x30000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x24, 0xc0000000, 0, 0 }, 0xf, { 0xc0000000, 0xc0000000, 0xc0000000, 0xc0000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x600, 0, 0 }, 0xf, { 0x600, 0x600, 0x600, 0x600 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x600, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x28, 0x600, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 19, 0x44, 0x18000000, 0, 0 }, 0xf, { 0x18000000, 0x18000000, 0x18000000, 0x18000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 19, 0x40, 0x38, 0, 0 }, 0x1, { 0x28, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 19, 0x40, 0x38, 0, 0 }, 0xe, { 0x0, 0x20, 0x20, 0x20 } }, + { { ATC_MASK, 19, 0x44, 0x60000000, 0, 0 }, 0xf, { 0x40000000, 0x40000000, 0x40000000, 0x40000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 19, 0x44, 0x6000000, 0, 0 }, 0xf, { 0x6000000, 0x6000000, 0x6000000, 0x6000000 } }, + { { ATC_MASK, 19, 0x40, 0xc000, 0, 0 }, 0xf, { 0x8000, 0x8000, 0x8000, 0x8000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 20, 0x68, 0xc00f, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 20, 0xac, 0x20000000, 0, 0 }, 0xf, { 0x20000000, 0x20000000, 0x20000000, 0x20000000 } }, + { { ATC_MASK, 20, 0xa8, 0x7ffff, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 20, 0x18, 0x38, 0, 0 }, 0xf, { 0x20, 0x20, 0x20, 0x20 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 14, 0x0, 0x1, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 39, 0x1c, 0x1, 0, 5000 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, +}; + +static const struct atc_op dp_group1_off[] = { + { ATC_MASK, 39, 0x14, 0x1007, 0x7, 0 }, + { ATC_MASK, 39, 0x18, 0x1, 0x0, 0 }, + { ATC_POLL, 39, 0x1c, 0x1, 0x0, 5000 }, + { ATC_MASK, 14, 0x0, 0x1, 0x1, 0 }, + { ATC_MASK, 31, 0x1c, 0xc00000, 0xc00000, 0 }, + { ATC_MASK, 31, 0x10, 0x600, 0x400, 0 }, + { ATC_MASK, 31, 0x4, 0x30000000, 0x20000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 31, 0x44, 0x100000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 31, 0x44, 0x400000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 31, 0x44, 0x4000000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 31, 0x44, 0x1000000, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 31, 0x44, 0x1000, 0x0, 0 }, + { ATC_MASK, 2, 0x120, 0x200, 0x200, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x120, 0x20, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 28, 0x44, 0x6000000, 0x4000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 28, 0x44, 0x18000000, 0x10000000, 0 }, + { ATC_MASK, 28, 0x24, 0xc0000000, 0x80000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 28, 0x24, 0x30000000, 0x20000000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 28, 0x28, 0x10, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 28, 0x40, 0xc000, 0xc000, 0 }, + { ATC_MASK, 25, 0x1d0, 0x3, 0x1, 0 }, + { ATC_MASK, 28, 0x40, 0x10000, 0x0, 0 }, + { ATC_MASK, 2, 0xc, 0x8000, 0x8000, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x80, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0xc, 0x800, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x2, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x10, 0x20, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 14, 0x0, 0xc, 0x8, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x400000, 0x400000, 0 }, + { ATC_MASK, 3, 0x8, 0x4, 0x4, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x800000, 0x0, 0 }, + { ATC_MASK, 3, 0x8, 0x8, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x800000, 0x800000, 0 }, + { ATC_MASK, 3, 0x8, 0x8, 0x8, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 2, 0x160, 0x400000, 0x0, 0 }, + { ATC_MASK, 3, 0x8, 0x4, 0x0, 0 }, + { ATC_DELAY, 0, 0x0, 0x0, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x7, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x8, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x100, 500000 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x0, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x0, 500000 }, + { ATC_POLL, 14, 0x34, 0x8, 0x0, 500000 }, + { ATC_DELAY, 0, 0x0, 0x0, 0xa, 0 }, + { ATC_MASK, 6, 0x34, 0xf, 0x1, 0 }, + { ATC_MASK, 6, 0x1c, 0x7, 0x0, 0 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x8, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x100, 500000 }, + { ATC_MASK, 6, 0x1c, 0x8, 0x0, 0 }, + { ATC_POLL, 6, 0x2c, 0xff00, 0x0, 500000 }, + { ATC_MASK, 8, 0x0, 0xaaa, 0x0, 0 }, +}; + +static const struct atc_rate_op dp_group1_on[] = { + { { ATC_MASK, 39, 0x14, 0x7, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 39, 0x18, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x6c, 0xe0, 0, 0 }, 0xf, { 0x40, 0x40, 0x40, 0x40 } }, + { { ATC_MASK, 14, 0x0, 0x40fff0, 0, 0 }, 0xf, { 0x1110, 0x1110, 0x1110, 0x1110 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x1, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x1, { 0x1e0e021c, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x1, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x1, { 0x156600, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x1, { 0x70000, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x1, { 0x1, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x2, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x2, { 0x0, 0x1e0e01c2, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x2, { 0x0, 0x7fffffe, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x2, { 0x0, 0x155200, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x2, { 0x0, 0x70000, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x2, { 0x0, 0x1, 0x0, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x4, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x1e0e01c2, 0x0 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x7fffffe, 0x0 } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x4, { 0x0, 0x0, 0x554800, 0x0 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x4, { 0x0, 0x0, 0x70000, 0x0 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x4, { 0x0, 0x0, 0x1, 0x0 } }, + { { ATC_MASK, 8, 0x34, 0x3, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 7, 0x80, 0xffffffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x1e0e02a3 } }, + { { ATC_MASK, 7, 0x84, 0xfffffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0xbff7ffc } }, + { { ATC_MASK, 7, 0x88, 0x7fffff, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x564800 } }, + { { ATC_MASK, 8, 0x8, 0x1f0000, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x70000 } }, + { { ATC_MASK, 8, 0x18, 0x1, 0, 0 }, 0x8, { 0x0, 0x0, 0x0, 0x1 } }, + { { ATC_MASK, 8, 0x0, 0xaaa, 0, 0 }, 0xf, { 0xaaa, 0xaaa, 0xaaa, 0xaaa } }, + { { ATC_MASK, 6, 0x30, 0x4000, 0, 0 }, 0xf, { 0x4000, 0x4000, 0x4000, 0x4000 } }, + { { ATC_MASK, 6, 0x34, 0xf, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 6, 0x18, 0x1fe000, 0, 0 }, 0xf, { 0x2000, 0x2000, 0x2000, 0x2000 } }, + { { ATC_MASK, 6, 0x20, 0x1, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 6, 0x1c, 0x7, 0, 0 }, 0xf, { 0x7, 0x7, 0x7, 0x7 } }, + { { ATC_MASK, 6, 0x1c, 0x8, 0, 0 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_POLL, 6, 0x2c, 0xff00, 0, 500000 }, 0xf, { 0x100, 0x100, 0x100, 0x100 } }, + { { ATC_MASK, 6, 0x1c, 0x8, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 6, 0x2c, 0xff00, 0, 500000 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 14, 0x34, 0x8, 0, 500000 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_MASK, 28, 0x3c, 0x18000, 0, 0 }, 0xf, { 0x10000, 0x10000, 0x10000, 0x10000 } }, + { { ATC_MASK, 14, 0x0, 0xc, 0, 0 }, 0xf, { 0xc, 0xc, 0xc, 0xc } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x20, 0, 0 }, 0xf, { 0x20, 0x20, 0x20, 0x20 } }, + { { ATC_MASK, 2, 0x120, 0x80, 0, 0 }, 0xf, { 0x80, 0x80, 0x80, 0x80 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x2, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 2, 0x120, 0x8, 0, 0 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x120, 0x200, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 2, 0x120, 0x800, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0xfffffc0, 0, 0 }, 0xf, { 0xaafb800, 0xaafb800, 0xaafb800, 0xaafb800 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0x1000000, 0, 0 }, 0xf, { 0x1000000, 0x1000000, 0x1000000, 0x1000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0x4000000, 0, 0 }, 0xf, { 0x4000000, 0x4000000, 0x4000000, 0x4000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0x7c0, 0, 0 }, 0xf, { 0x300, 0x300, 0x300, 0x300 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0x6c000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 30, 0x100, 0x100000, 0, 0 }, 0xf, { 0x100000, 0x100000, 0x100000, 0x100000 } }, + { { ATC_MASK, 30, 0x58, 0xc00f, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 30, 0x104, 0x20000000, 0, 0 }, 0xf, { 0x20000000, 0x20000000, 0x20000000, 0x20000000 } }, + { { ATC_MASK, 30, 0x100, 0x7ffff, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 31, 0x44, 0x100000, 0, 0 }, 0x7, { 0x100000, 0x100000, 0x100000, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0x7, { 0x1, 0x1, 0x1, 0x0 } }, + { { ATC_MASK, 31, 0x44, 0x400000, 0, 0 }, 0x7, { 0x400000, 0x400000, 0x400000, 0x0 } }, + { { ATC_MASK, 31, 0x4, 0x3000000, 0, 0 }, 0xf, { 0x2000000, 0x2000000, 0x2000000, 0x2000000 } }, + { { ATC_MASK, 31, 0x4, 0x30000000, 0, 0 }, 0xf, { 0x30000000, 0x30000000, 0x30000000, 0x30000000 } }, + { { ATC_MASK, 31, 0xc, 0x7000000, 0, 0 }, 0x1, { 0x5000000, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 31, 0xc, 0x7000000, 0, 0 }, 0xe, { 0x0, 0x4000000, 0x4000000, 0x4000000 } }, + { { ATC_MASK, 31, 0x8, 0x3, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 31, 0x10, 0x600, 0, 0 }, 0xf, { 0x600, 0x600, 0x600, 0x600 } }, + { { ATC_MASK, 31, 0x1c, 0xc00000, 0, 0 }, 0xf, { 0x800000, 0x800000, 0x800000, 0x800000 } }, + { { ATC_MASK, 28, 0xf4, 0x3000, 0, 0 }, 0xf, { 0x3000, 0x3000, 0x3000, 0x3000 } }, + { { ATC_MASK, 25, 0x188, 0x1, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 25, 0x1d4, 0x700, 0, 0 }, 0xf, { 0x300, 0x300, 0x300, 0x300 } }, + { { ATC_MASK, 28, 0x24, 0x3f0000, 0, 0 }, 0xf, { 0x2a0000, 0x2a0000, 0x2a0000, 0x2a0000 } }, + { { ATC_MASK, 28, 0x3c, 0x18000, 0, 0 }, 0xf, { 0x10000, 0x10000, 0x10000, 0x10000 } }, + { { ATC_MASK, 28, 0x78, 0xc0000, 0, 0 }, 0xf, { 0x80000, 0x80000, 0x80000, 0x80000 } }, + { { ATC_MASK, 28, 0x7c, 0xc0, 0, 0 }, 0xf, { 0x80, 0x80, 0x80, 0x80 } }, + { { ATC_MASK, 28, 0x84, 0xc000, 0, 0 }, 0xf, { 0x8000, 0x8000, 0x8000, 0x8000 } }, + { { ATC_MASK, 28, 0xd4, 0x600000, 0, 0 }, 0xf, { 0x400000, 0x400000, 0x400000, 0x400000 } }, + { { ATC_MASK, 28, 0xd8, 0x300, 0, 0 }, 0xf, { 0x200, 0x200, 0x200, 0x200 } }, + { { ATC_MASK, 28, 0x40, 0xc00, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_MASK, 28, 0x48, 0x600, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_MASK, 28, 0x28, 0x1ff030, 0, 0 }, 0xf, { 0x11c020, 0x11c020, 0x11c020, 0x11c020 } }, + { { ATC_MASK, 28, 0x2c, 0xfc, 0, 0 }, 0xf, { 0xb0, 0xb0, 0xb0, 0xb0 } }, + { { ATC_MASK, 28, 0x28, 0xe00, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_MASK, 28, 0x28, 0x1c0, 0, 0 }, 0xf, { 0x180, 0x180, 0x180, 0x180 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x10, 0x20, 0, 0 }, 0xf, { 0x20, 0x20, 0x20, 0x20 } }, + { { ATC_MASK, 2, 0x10, 0x80, 0, 0 }, 0xf, { 0x80, 0x80, 0x80, 0x80 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0x10, 0x2, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 2, 0x10, 0x8, 0, 0 }, 0xf, { 0x8, 0x8, 0x8, 0x8 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x800, 0, 0 }, 0xf, { 0x800, 0x800, 0x800, 0x800 } }, + { { ATC_MASK, 2, 0xc, 0x2000, 0, 0 }, 0xf, { 0x2000, 0x2000, 0x2000, 0x2000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x80, 0, 0 }, 0xf, { 0x80, 0x80, 0x80, 0x80 } }, + { { ATC_MASK, 2, 0xc, 0x200, 0, 0 }, 0xf, { 0x200, 0x200, 0x200, 0x200 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 2, 0xc, 0x8000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 2, 0xc, 0x20000, 0, 0 }, 0xf, { 0x20000, 0x20000, 0x20000, 0x20000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 25, 0x1d0, 0x3, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 25, 0x1d0, 0x2, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x40, 0x30000, 0, 0 }, 0xf, { 0x30000, 0x30000, 0x30000, 0x30000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x40, 0xc000, 0, 0 }, 0xf, { 0xc000, 0xc000, 0xc000, 0xc000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x3010, 0, 0 }, 0xf, { 0x1010, 0x1010, 0x1010, 0x1010 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x600, 0, 0 }, 0xf, { 0x200, 0x200, 0x200, 0x200 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x3000, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x24, 0x30000000, 0, 0 }, 0xf, { 0x30000000, 0x30000000, 0x30000000, 0x30000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x24, 0xc0000000, 0, 0 }, 0xf, { 0xc0000000, 0xc0000000, 0xc0000000, 0xc0000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x600, 0, 0 }, 0xf, { 0x600, 0x600, 0x600, 0x600 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x600, 0, 0 }, 0xf, { 0x400, 0x400, 0x400, 0x400 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x28, 0x600, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 28, 0x44, 0x18000000, 0, 0 }, 0xf, { 0x18000000, 0x18000000, 0x18000000, 0x18000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x2, 0x2, 0x2, 0x2 } }, + { { ATC_MASK, 28, 0x40, 0x38, 0, 0 }, 0x1, { 0x28, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 28, 0x40, 0x38, 0, 0 }, 0xe, { 0x0, 0x20, 0x20, 0x20 } }, + { { ATC_MASK, 28, 0x44, 0x60000000, 0, 0 }, 0xf, { 0x40000000, 0x40000000, 0x40000000, 0x40000000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 28, 0x44, 0x6000000, 0, 0 }, 0xf, { 0x6000000, 0x6000000, 0x6000000, 0x6000000 } }, + { { ATC_MASK, 28, 0x40, 0xc000, 0, 0 }, 0xf, { 0x8000, 0x8000, 0x8000, 0x8000 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 29, 0x68, 0xc00f, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_MASK, 29, 0xac, 0x20000000, 0, 0 }, 0xf, { 0x20000000, 0x20000000, 0x20000000, 0x20000000 } }, + { { ATC_MASK, 29, 0xa8, 0x7ffff, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 29, 0x18, 0x38, 0, 0 }, 0xf, { 0x20, 0x20, 0x20, 0x20 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_DELAY, 0, 0x0, 0x0, 0, 0 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, + { { ATC_MASK, 14, 0x0, 0x1, 0, 0 }, 0xf, { 0x0, 0x0, 0x0, 0x0 } }, + { { ATC_POLL, 39, 0x1c, 0x1, 0, 5000 }, 0xf, { 0x1, 0x1, 0x1, 0x1 } }, +}; diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb2_reset.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb2_reset.h new file mode 100644 index 0000000000000..503cbb537f865 --- /dev/null +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb2_reset.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: MIT */ +#ifndef APPLE_T6050_USB2_RESET_H +#define APPLE_T6050_USB2_RESET_H +#include "apple_t6050_usb3_bist.h" + +/* Native T6050 Type-C PHY USB2 port reset block, native27: + * bank0+4 bit1 assert, sleep 5 ms, release. + * Caller holds exclusive PHY ownership with its USB power domains active. + * sleep_ms is supplied by the OS frontend; there is no packet-path polling. */ +static inline int apple_t6050_usb2_port_reset( + const struct apple_t6050_usb_io *io, void *sleep_context, + void (*sleep_ms)(void *, unsigned int)) +{ + if (!io || !io->read || !io->write || !sleep_ms) + return -1; + apple_t6050_usb_mask(io, 0, 4, 2U, 2U); + if (!(io->read(io->context, 0, 4) & 2U)) + return -1; + sleep_ms(sleep_context, 5); + apple_t6050_usb_mask(io, 0, 4, 2U, 0); + return io->read(io->context, 0, 4) & 2U ? -1 : 0; +} +#endif diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_bist.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_bist.h new file mode 100644 index 0000000000000..3af8fcf2a3a13 --- /dev/null +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_bist.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: MIT */ +/* T6050-specific native PHY recipe; no Windows/Linux frontend policy. */ +#ifndef APPLE_T6050_USB3_BIST_H +#define APPLE_T6050_USB3_BIST_H +struct apple_t6050_usb_io { + void *context; + unsigned int (*read)(void *, unsigned int bank, unsigned int offset); + void (*write)(void *, unsigned int bank, unsigned int offset, unsigned int value); + int (*poll)(void *, unsigned int bank, unsigned int offset, unsigned int mask, unsigned int value, unsigned int usec); + void (*delay)(void *, unsigned int usec); +}; +static inline void apple_t6050_usb_mask(const struct apple_t6050_usb_io *io, unsigned int bank, unsigned int offset, unsigned int mask, unsigned int value) +{ io->write(io->context, bank, offset, (io->read(io->context, bank, offset) & ~mask) | value); } +static inline int apple_t6050_usb_bist_off(const struct apple_t6050_usb_io *io) +{ + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x110, 0x660, 0x0); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x8); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x0); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x1, 0x0); + return 0; +} +static inline int apple_t6050_usb_bist_on(const struct apple_t6050_usb_io *io) +{ + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x1, 0x1); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x10c, 0x1e100000, 0x4100000); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x110, 0x660, 0x220); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x8); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x0); + if (io->poll(io->context, 35, 0x104, 0x100, 0x0, 20000)) return -1; + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x8, 0x20, 0x20); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x8, 0x20, 0x0); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x10c, 0x1e000000, 0x6000000); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x110, 0x600, 0x200); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x8); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x4, 0x8, 0x0); + if (io->poll(io->context, 35, 0x104, 0x40, 0x40, 130000)) return -1; + if (io->poll(io->context, 35, 0x104, 0x100, 0x0, 1000)) return -1; + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x8, 0x20, 0x20); + /* native sequence step */ + apple_t6050_usb_mask(io, 35, 0x8, 0x20, 0x0); + return 0; +} +#endif diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h new file mode 100644 index 0000000000000..953a42dbc7aab --- /dev/null +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -0,0 +1,136 @@ +/* SPDX-License-Identifier: MIT */ +/* Platform backend for native direct USB3, not a Type-C policy engine. + * The caller owns the port, has powered the PHY/firmware for native USB3, + * completed DWC3 core init and enabled SUSPHY, and has valid DART mappings. + * Bank 35 is T6050's ADT PHY reg[35]. Bank 44 is usb-drdN reg[3]. + * The first left/debug port must never reach this backend. + */ +#ifndef APPLE_T6050_USB3_PIPE_H +#define APPLE_T6050_USB3_PIPE_H +#include "apple_t6050_usb3_bist.h" + +/* Cold controller setup while RESET_N is clear. Linux's existing ATC + * frontend supplies a dummy PIPE clock before DWC3 reads its core registers. + * T6050 uses the native-RE 6:4 clock field and dummy encoding 0x42. + * This is not an active producer handoff; never use it for USB4 teardown. + */ +static inline int +apple_t6050_usb3_pipe_cold_dummy(const struct apple_t6050_usb_io *io) +{ + unsigned int mux; + if (!io || !io->read || !io->write || !io->delay) + return -1; + if (io->read(io->context, 44, 0x1c) & 1) + return -1; + mux = io->read(io->context, 44, 0x0c) & 0x73; + if (mux != 0 && mux != 2 && mux != 0x42) + return -1; + if (mux == 0x42) + return 0; + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0); + io->delay(io->context, 10); + apple_t6050_usb_mask(io, 44, 0x0c, 3, 2); + io->delay(io->context, 10); + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0x40); + io->delay(io->context, 10); + return (io->read(io->context, 44, 0x0c) & 0x73) == 0x42 ? 0 : -1; +} + +static inline int +apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) +{ + unsigned int aon, mux; + int result = -1, locked = 0, bist = 0; + + if (!io || !io->read || !io->write || !io->poll || !io->delay) + return -1; + aon = io->read(io->context, 44, 0x1c); + mux = io->read(io->context, 44, 0x0c) & 0x73; + /* Never reroute an active USB4 producer or guess an unknown state. */ + if (!(aon & 1) || (mux != 0x42 && mux != 0x10)) + return -1; + + /* Native T8142 xHCI USB3 mode switch, native27 T6050-compatible path. */ + apple_t6050_usb_mask(io, 44, 0x04, 0x0e, 0); + apple_t6050_usb_mask(io, 44, 0x00, 1, 1); + apple_t6050_usb_mask(io, 44, 0x10, 1, 1); + locked = 1; + if (io->poll(io->context, 44, 0x14, 1, 1, 6000)) + goto out; + + bist = 1; + if (apple_t6050_usb_bist_on(io)) + goto out; + apple_t6050_usb_mask(io, 44, 0x20, 0x100f, 3); + if (io->poll(io->context, 44, 0x20, 0xf, 3, 1000)) + goto out; + if (apple_t6050_usb_bist_off(io)) + goto out; + bist = 0; + + /* T6050 clock bits are 6:4, not the older 5:3. Native USB3 is 0x10. */ + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0); + io->delay(io->context, 5); + apple_t6050_usb_mask(io, 44, 0x0c, 0x73, 0); + apple_t6050_usb_mask(io, 44, 0x0c, 0x73, 0x10); + result = (io->read(io->context, 44, 0x0c) & 0x73) == 0x10 ? 0 : -1; + +out: + if (bist && apple_t6050_usb_bist_off(io)) + result = -1; + apple_t6050_usb_mask(io, 44, 0x00, 5, 0); + if (locked) { + apple_t6050_usb_mask(io, 44, 0x10, 1, 0); + if (io->poll(io->context, 44, 0x14, 1, 0, 6000)) + result = -1; + } + return result; +} + +/* The native close() call quiesces the ACIO PHY while PIPE is locked, + * before selecting the dummy producer. The caller supplies that lifecycle + * operation; merely changing MUX is not a complete disconnect sequence. + */ +static inline int +apple_t6050_usb3_pipe_stop(const struct apple_t6050_usb_io *io, + int (*quiesce)(void *), void *context) +{ + unsigned int mux; + int result = -1; + + if (!io || !io->read || !io->write || !io->poll || !io->delay || !quiesce) + return -1; + mux = io->read(io->context, 44, 0x0c) & 0x73; + if (mux != 0x10 && mux != 0x42) + return -1; + apple_t6050_usb_mask(io, 44, 0x04, 0x0e, 0); + apple_t6050_usb_mask(io, 44, 0x00, 1, 1); + apple_t6050_usb_mask(io, 44, 0x00, 4, 4); + apple_t6050_usb_mask(io, 44, 0x10, 1, 1); + /* Native mode0-from2 waits 150 ms, logs a missing lock ACK, and + * continues teardown, as the saved native driver does. + * The caller has already stopped the controller's DMA/PIPE consumer; + * this is not the active-producer handoff used by pipe_switch(). + * The nonselected override, final mux readback and unlock checks below + * remain mandatory, as does successful PHY quiescence. + */ + io->poll(io->context, 44, 0x14, 1, 1, 150000); + if (quiesce(context)) + goto out; + apple_t6050_usb_mask(io, 44, 0x20, 0x100f, 0x1002); + if (io->poll(io->context, 44, 0x20, 0xf, 2, 1000)) + goto out; + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0); + io->delay(io->context, 5); + apple_t6050_usb_mask(io, 44, 0x0c, 3, 2); + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0x40); + result = (io->read(io->context, 44, 0x0c) & 0x73) == 0x42 ? 0 : -1; +out: + apple_t6050_usb_mask(io, 44, 0x00, 1, 0); + apple_t6050_usb_mask(io, 44, 0x00, 4, 0); + apple_t6050_usb_mask(io, 44, 0x10, 1, 0); + if (io->poll(io->context, 44, 0x14, 1, 0, 6000)) + result = -1; + return result; +} +#endif diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb_phy.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb_phy.h new file mode 100644 index 0000000000000..5c96da7d82c2d --- /dev/null +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb_phy.h @@ -0,0 +1,286 @@ +/* SPDX-License-Identifier: MIT */ +/* Generated by generate-phy.py; modeled ACKs are not hardware proof. */ +#ifndef APPLE_T6050_USB_PHY_H +#define APPLE_T6050_USB_PHY_H +#include "apple_t6050_usb3_bist.h" +struct apple_t6050_usb_platform { + const struct apple_t6050_usb_io *io; + void *context; + int (*wrapper_power)(void *, unsigned int); + int (*firmware)(void *, unsigned int); + int (*tunable)(void *, unsigned int, const char *); + void (*pause_ns)(void *, unsigned int); +}; +enum apple_t6050_usb_op { T6050_MASK, T6050_POLL, T6050_DELAY, + T6050_POWER, T6050_FIRMWARE, T6050_TUNABLE }; +struct apple_t6050_usb_step { + unsigned int op, bank, offset, mask, value, timeout; + const char *name; +}; +static const struct apple_t6050_usb_step apple_t6050_usb2_host[] = { + { T6050_TUNABLE, 0, 0x0, 0x0, 0x0, 0, "tunable_USB2PHY_DFLT" }, + { T6050_TUNABLE, 0, 0x0, 0x0, 0x0, 0, "tunable_USB2PHY_HOST" }, + { T6050_DELAY, 0, 0x0, 0x0, 0x2710, 0, 0 }, + { T6050_MASK, 0, 0x4, 0x8, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_MASK, 0, 0x4, 0x1, 0x0, 0, 0 }, + { T6050_MASK, 0, 0x4, 0x2, 0x0, 0, 0 }, + { T6050_MASK, 1, 0x0, 0x9, 0x9, 0, 0 }, + { T6050_MASK, 0, 0x4, 0x4, 0x4, 0, 0 }, + { T6050_MASK, 0, 0x1c, 0x20000000, 0x0, 0, 0 }, + { T6050_MASK, 0, 0x1c, 0x40000000, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1e, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1388, 0, 0 }, + { T6050_MASK, 0, 0x0, 0x7, 0x2, 0, 0 }, +}; +static const struct apple_t6050_usb_step apple_t6050_usb3_init_normal[] = { + { T6050_MASK, 39, 0x0, 0x1, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x1, 0x1, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x2, 0x2, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x2, 0x2, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POWER, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x2c, 0x1, 0x0, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x100, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x8, 0x8, 0, 0 }, + { T6050_TUNABLE, 41, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF" }, + { T6050_TUNABLE, 40, 0x0, 0x0, 0x0, 0, "tunable_ATC_FABRIC" }, + { T6050_TUNABLE, 43, 0x0, 0x0, 0x0, 0, "tunable_ATC_COMMON_CFG" }, + { T6050_TUNABLE, 42, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF_LIOA" }, + { T6050_TUNABLE, 20, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_CFG_TX_OF_RXCLK" }, + { T6050_TUNABLE, 29, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_CFG_TX_OF_RXCLK" }, + { T6050_TUNABLE, 18, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_EQ_DFLT" }, + { T6050_TUNABLE, 27, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_EQ_DFLT" }, + { T6050_TUNABLE, 5, 0x0, 0x0, 0x0, 0, "tunable_AUS40CMN_SHM" }, + { T6050_TUNABLE, 8, 0x0, 0x0, 0x0, 0, "tunable_AUSPLL_CORE" }, + { T6050_TUNABLE, 10, 0x0, 0x0, 0x0, 0, "tunable_CIO4PLL_CORE" }, + { T6050_MASK, 4, 0x0, 0x3f0, 0x1c0, 0, 0 }, + { T6050_MASK, 4, 0x18, 0xf000, 0x3000, 0, 0 }, + { T6050_MASK, 9, 0x88, 0xff, 0x27, 0, 0 }, + { T6050_MASK, 33, 0x4, 0x38, 0x8, 0, 0 }, + { T6050_MASK, 10, 0xdc, 0x3ff0, 0x1760, 0, 0 }, + { T6050_MASK, 21, 0xcc, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 30, 0xcc, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 20, 0x90, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 29, 0x90, 0x1f80000, 0x380000, 0, 0 }, + { T6050_TUNABLE, 8, 0x0, 0x0, 0x0, 0, "tunable_AUSPLL_CORE" }, + { T6050_MASK, 2, 0x6c, 0x28000fc, 0x44, 0, 0 }, + { T6050_MASK, 2, 0x78, 0x1ffff, 0x110, 0, 0 }, + { T6050_MASK, 2, 0x6c, 0x3, 0x2, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x2a, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x10, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x10, 0x40, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x10000, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x100, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x1000, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x40, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x400, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x8, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_MASK, 38, 0x40, 0x1, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_FIRMWARE, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1388, 0, 0 }, + { T6050_POLL, 2, 0x260, 0x400, 0x400, 1000000, 0 }, + { T6050_MASK, 39, 0x0, 0x10, 0x10, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x64, 0, 0 }, +}; +static const struct apple_t6050_usb_step apple_t6050_usb3_init_reverse[] = { + { T6050_MASK, 39, 0x0, 0x1, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x1, 0x1, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x2, 0x2, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x2, 0x2, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POWER, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x2c, 0x1, 0x0, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x100, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x8, 0x8, 0, 0 }, + { T6050_TUNABLE, 41, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF" }, + { T6050_TUNABLE, 40, 0x0, 0x0, 0x0, 0, "tunable_ATC_FABRIC" }, + { T6050_TUNABLE, 43, 0x0, 0x0, 0x0, 0, "tunable_ATC_COMMON_CFG" }, + { T6050_TUNABLE, 42, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF_LIOA" }, + { T6050_TUNABLE, 20, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_CFG_TX_OF_RXCLK" }, + { T6050_TUNABLE, 29, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_CFG_TX_OF_RXCLK" }, + { T6050_TUNABLE, 18, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_EQ_DFLT" }, + { T6050_TUNABLE, 27, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_EQ_DFLT" }, + { T6050_TUNABLE, 5, 0x0, 0x0, 0x0, 0, "tunable_AUS40CMN_SHM" }, + { T6050_TUNABLE, 8, 0x0, 0x0, 0x0, 0, "tunable_AUSPLL_CORE" }, + { T6050_TUNABLE, 10, 0x0, 0x0, 0x0, 0, "tunable_CIO4PLL_CORE" }, + { T6050_MASK, 4, 0x0, 0x3f0, 0x1c0, 0, 0 }, + { T6050_MASK, 4, 0x18, 0xf000, 0x3000, 0, 0 }, + { T6050_MASK, 9, 0x88, 0xff, 0x27, 0, 0 }, + { T6050_MASK, 33, 0x4, 0x38, 0x8, 0, 0 }, + { T6050_MASK, 10, 0xdc, 0x3ff0, 0x1760, 0, 0 }, + { T6050_MASK, 21, 0xcc, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 30, 0xcc, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 20, 0x90, 0x1f80000, 0x380000, 0, 0 }, + { T6050_MASK, 29, 0x90, 0x1f80000, 0x380000, 0, 0 }, + { T6050_TUNABLE, 8, 0x0, 0x0, 0x0, 0, "tunable_AUSPLL_CORE" }, + { T6050_MASK, 2, 0x6c, 0x14000fc, 0x28, 0, 0 }, + { T6050_MASK, 2, 0x78, 0x1ffff, 0x111, 0, 0 }, + { T6050_MASK, 2, 0x6c, 0x3, 0x2, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x2a, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x10, 0x8, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x10, 0x80, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x20000, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x200, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x2000, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x80, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x8, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x800, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x8, 0x2, 0x2, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_MASK, 38, 0x40, 0x1, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_FIRMWARE, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1388, 0, 0 }, + { T6050_POLL, 2, 0x260, 0x400, 0x400, 1000000, 0 }, + { T6050_MASK, 39, 0x0, 0x10, 0x10, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x64, 0, 0 }, +}; +static const struct apple_t6050_usb_step apple_t6050_usb3_shutdown[] = { + { T6050_MASK, 35, 0x4, 0x1, 0x1, 0, 0 }, + { T6050_MASK, 35, 0x10c, 0x100000, 0x0, 0, 0 }, + { T6050_MASK, 35, 0x110, 0x60, 0x20, 0, 0 }, + { T6050_MASK, 35, 0x4, 0x8, 0x8, 0, 0 }, + { T6050_MASK, 35, 0x4, 0x8, 0x0, 0, 0 }, + { T6050_POLL, 35, 0x104, 0x100, 0x100, 1000000, 0 }, + { T6050_MASK, 35, 0x10c, 0x1e000000, 0x4000000, 0, 0 }, + { T6050_MASK, 35, 0x110, 0x600, 0x200, 0, 0 }, + { T6050_MASK, 35, 0x4, 0x8, 0x8, 0, 0 }, + { T6050_MASK, 35, 0x4, 0x8, 0x0, 0, 0 }, + { T6050_POLL, 35, 0x104, 0x100, 0x100, 1000000, 0 }, + { T6050_MASK, 35, 0x4, 0x1, 0x0, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x100, 0x100, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x10, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x200, 0x200, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0x120, 0x20, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 5, 0x0, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x10, 0x10, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0xc8, 0, 0 }, + { T6050_FIRMWARE, 0, 0x0, 0x0, 0x0, 0, 0 }, + { T6050_POWER, 0, 0x0, 0x0, 0x0, 0, 0 }, + { T6050_MASK, 39, 0x2c, 0x1, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x100, 0x100, 1000, 0 }, + { T6050_MASK, 39, 0x0, 0x10, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x8, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x4, 0x4, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x2, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x1, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x8, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, +}; + +static inline int +apple_t6050_usb_phy_run(const struct apple_t6050_usb_platform *p, + const struct apple_t6050_usb_step *steps, unsigned int count) +{ + if (!p || !p->io || !p->io->read || !p->io->write || + !p->io->poll || !p->io->delay || !p->wrapper_power || + !p->firmware || !p->tunable) + return -1; + for (unsigned int i = 0; i < count; i++) { + const struct apple_t6050_usb_step *s = &steps[i]; + int ret = 0; + switch (s->op) { + case T6050_MASK: + apple_t6050_usb_mask(p->io, s->bank, s->offset, s->mask, s->value); + break; + case T6050_POLL: + ret = p->io->poll(p->io->context, s->bank, s->offset, + s->mask, s->value, s->timeout); + break; + case T6050_DELAY: p->io->delay(p->io->context, s->value); break; + case T6050_POWER: ret = p->wrapper_power(p->context, s->value); break; + case T6050_FIRMWARE: ret = p->firmware(p->context, s->value); break; + case T6050_TUNABLE: ret = p->tunable(p->context, s->bank, s->name); break; + default: return -1; + } + if (ret) + return ret; + } + return 0; +} +#define APPLE_T6050_USB_RUN(p, steps) \ + apple_t6050_usb_phy_run((p), (steps), sizeof(steps) / sizeof((steps)[0])) + +/* Native shutdown first asserts PORT_RESET only if it was not already set. + * The 5 ms wait belongs to that transition, not every redundant stop call. + * Preserve IOPause(500 ns), whose unit differs from IODelay(microseconds). + */ +static inline int apple_t6050_usb2_stop(const struct apple_t6050_usb_platform *p) +{ + if (!p || !p->io || !p->io->read || !p->io->write || + !p->io->delay || !p->pause_ns) + return -1; + if (!(p->io->read(p->io->context, 0, 4) & 2)) { + apple_t6050_usb_mask(p->io, 0, 4, 2, 2); + p->io->delay(p->io->context, 5000); + } + apple_t6050_usb_mask(p->io, 0, 0, 7, 4); + apple_t6050_usb_mask(p->io, 0, 4, 8, 8); + apple_t6050_usb_mask(p->io, 0, 4, 1, 1); + apple_t6050_usb_mask(p->io, 0, 0x1c, 0x20000000, 0x20000000); + apple_t6050_usb_mask(p->io, 0, 0x1c, 0x40000000, 0x40000000); + p->pause_ns(p->context, 500); + return 0; +} +#endif From ad990d38db1b3ba42bc9a5023defa866e3b42606 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 14:19:46 -0800 Subject: [PATCH 192/342] dt-bindings: phy: apple,t6050-dp-phy: Allow the USB domain on combo PHYs The combo PHY's USB2 PHY and digital banks are in the USB controller's power domain. Let a combo PHY name it fourth, as "usb", so the PHY can hold it on a port with no USB controller bound. The fixed DisplayPort PHY keeps exactly three domains. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- .../devicetree/bindings/phy/apple,t6050-dp-phy.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml index 52cb96f4a965b..b055369faf9f6 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml @@ -74,14 +74,20 @@ properties: description: Offset, mask and value tuples for the PIPE handler power-domains: + description: + A combo PHY may name the USB controller's domain fourth ("usb"). Its + USB2 PHY and digital banks are in that domain, and the PHY then holds it + while it runs, also on a port with no USB controller bound. minItems: 3 - maxItems: 3 + maxItems: 4 power-domain-names: + minItems: 3 items: - const: usb-aon - const: common - const: wrapper + - const: usb apple,tunable-axi2af: $ref: /schemas/types.yaml#/definitions/uint32-array @@ -184,6 +190,10 @@ allOf: properties: '#phy-cells': const: 0 + power-domains: + maxItems: 3 + power-domain-names: + maxItems: 3 if: required: - mode-switch From 42b87ef7de672fdab3cc5fc4175e976c8840f807 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 14:19:48 -0800 Subject: [PATCH 193/342] phy: apple: t6050: Hold the USB domain for the combo PHY's USB2 banks The combo PHY's USB2 PHY and digital banks are in the USB controller's power domain. Only a bound USB controller holds that domain, so on a port with no controller (a DisplayPort-only port, as on J775D with Linux on the hardware) the first Type-C mode switch wrote an unclocked bank and took an SError. A combo PHY node may now name that domain as a fourth power domain, "usb". When it does, the PHY holds it from combo start to combo stop, after the common domain on the way up and before it on the way down. Nodes that name three domains probe and run exactly as before, and the fixed DisplayPort PHY still takes exactly three. Testing: on J775D (M5 Ultra), with the fourth domain named on each combo port, Type-C mode switches and DisplayPort on the rear ports ran without an SError on every boot since 2026-10-30. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 8 ++++++++ drivers/phy/apple/atc-t6050-dp.c | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 1066748dc1afe..3c3454ceb64de 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -94,6 +94,8 @@ static int combo_stop(struct t6050_dp *dp) if (!ret) dp->usb2_active = false; } + if (!ret && dp->ndomains > 3) + ret = atc_domain_set(&dp->domain[3], false); if (!ret) ret = atc_domain_set(&dp->domain[1], false); if (!ret) @@ -118,6 +120,12 @@ static int combo_start(struct t6050_dp *dp, enum combo_mode mode) ret = atc_domain_set(&dp->domain[0], true); if (!ret) ret = atc_domain_set(&dp->domain[1], true); + /* + * The USB2 PHY and digital banks are unclocked without the USB domain, + * which a USB controller holds only while one is bound to this port. + */ + if (!ret && dp->ndomains > 3) + ret = atc_domain_set(&dp->domain[3], true); if (!ret) ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb2_host); if (!ret) diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index cafee096a6250..4479153919488 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -83,7 +83,9 @@ struct t6050_dp { void __iomem *banks[45]; struct resource resources[45]; struct apple_tunable *tunables[ARRAY_SIZE(tunable_names)]; - struct atc_domain domain[3]; /* USB AON, common, wrapper: native order. */ + /* USB AON, common, wrapper: native order; a combo may add USB. */ + struct atc_domain domain[4]; + unsigned int ndomains; u32 training[4][16]; u32 voltage[4], pre[4]; int rate; @@ -605,14 +607,14 @@ static int t6050_typec_register(struct t6050_dp *dp) static int t6050_dp_probe(struct platform_device *pdev) { - static const char * const domains[] = {"usb-aon", "common", "wrapper"}; + static const char * const domains[] = {"usb-aon", "common", "wrapper", "usb"}; struct device *dev = &pdev->dev; struct t6050_dp *dp; struct phy_provider *provider; struct phy *phy; struct resource *core; void __iomem *base; - int ret; + int ndomains, ret; dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); if (!dp) @@ -741,10 +743,16 @@ static int t6050_dp_probe(struct platform_device *pdev) if (ret) return ret; } - /* Three named domains prevent automatic wrapper enable at probe time. */ - if (of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells") != 3) + /* + * Named domains prevent automatic wrapper enable at probe time. A combo + * PHY may also name the USB controller's domain, which its USB2 banks + * are in (combo_start()). + */ + ndomains = of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells"); + if (ndomains != 3 && !(dp->combo && ndomains == 4)) return -EINVAL; - for (unsigned int i = 0; i < ARRAY_SIZE(domains); i++) { + dp->ndomains = ndomains; + for (unsigned int i = 0; i < dp->ndomains; i++) { dp->domain[i].dev = dev_pm_domain_attach_by_name(dev, domains[i]); if (IS_ERR_OR_NULL(dp->domain[i].dev)) return dev_err_probe(dev, dp->domain[i].dev ? PTR_ERR(dp->domain[i].dev) : -ENODEV, From 4ef9db44d4d951531b431a4d8ed26bbd1f720e33 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 17:06:32 -0800 Subject: [PATCH 194/342] dt-bindings: phy: apple,t6050-dp-phy: Type apple,port-index as uint32 apple,port-index has an enum but no type, so dtschema cannot decode the cell and every combo PHY node fails with "b'\x00\x00\x00\x02' is not one of [1, 2]" and a core-schema type error, whatever port it names. Give it the uint32 type. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml index b055369faf9f6..fdc2e60461700 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml @@ -37,6 +37,7 @@ properties: const: 1 apple,port-index: + $ref: /schemas/types.yaml#/definitions/uint32 enum: [1, 2] description: Native Type-C port; the debug/proxy port is excluded From 8b23bd4d3468912947de0790651739028b6d30b9 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 195/342] usb: dwc3: apple: Add the bare-metal T6050 controller Add apple,t6050-dwc3, the T6050 (J775D) DWC3 on bare metal. It uses the shared tunable table, extended with the tables Diljit Singh's T6050 USB support applies, in the same order: the T6040 tables plus CIO (the Apple region from 0xcd20, after the fixed CIO values), bulk fabric and AUSBC debug (the optional drd-bulk and drd-ausbc regions). It is host-only, like T6040. The USB2 port reset follows the root hub's start (a no-op without a PHY reset op), and a USB3 PHY failure is fatal, as on T8132. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- .../devicetree/bindings/usb/apple,dwc3.yaml | 36 ++++++- drivers/usb/dwc3/dwc3-apple.c | 95 +++++++++++++++---- 2 files changed, 107 insertions(+), 24 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml index 706d2866f61ba..7745fef5b686f 100644 --- a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml @@ -35,6 +35,23 @@ allOf: required: - resets - usb-role-switch + - if: + properties: + compatible: + contains: + const: apple,t6050-dwc3 + then: + properties: + reg: + minItems: 3 + reg-names: + minItems: 3 + else: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 $defs: apple,tunable: @@ -48,7 +65,7 @@ $defs: - description: Bits to be set after applying the mask description: > Controller table from the device's Apple device tree, applied after - every core reset (T6040). + every core reset (T6040, T6050). properties: compatible: @@ -74,7 +91,9 @@ properties: items: - description: Core DWC3 region - description: Apple-specific DWC3 region - - description: Controller configuration block (T6040) + - description: Controller configuration block (T6040, T6050) + - description: Bulk fabric block (T6050) + - description: AUSBC debug block (T6050) reg-names: minItems: 2 @@ -82,6 +101,8 @@ properties: - const: dwc3-core - const: dwc3-apple - const: drd-cfg + - const: drd-bulk + - const: drd-ausbc interrupts: maxItems: 1 @@ -118,7 +139,16 @@ properties: apple,tunable-cio: $ref: "#/$defs/apple,tunable" description: - Tunables applied to the CIO (USB4 tunnel) registers of the Apple region. + Tunables applied to the CIO registers of the Apple region, from offset + 0x20 of that region, after the driver's fixed CIO values. + + apple,tunable-bulk: + $ref: "#/$defs/apple,tunable" + description: Tunables applied to the drd-bulk region. + + apple,tunable-ausbc: + $ref: "#/$defs/apple,tunable" + description: Tunables applied to the drd-ausbc region. required: - compatible diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index f16aa6f21014b..f2484ee172862 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -100,7 +100,8 @@ * enum dwc3_apple_state is defined in dwc3-apple-state.h. */ -#define DWC3_APPLE_NR_TUNABLES 5 +#define DWC3_APPLE_NR_TUNABLES 8 +#define DWC3_APPLE_NR_DRD_REGS 3 /** * struct dwc3_apple - Apple-specific DWC3 USB controller @@ -127,7 +128,8 @@ * @rpm_held: The glue holds a runtime PM reference for the running core * @pre_core_rpm: Runtime PM is the glue's own until the first core bring-up * @dt_dis_u3_susphy: The device tree keeps USB3 PHY suspend off itself - * @drd_cfg: The controller's configuration block (optional, for its tunable) + * @drd_regs: The controller's optional blocks outside dwc3-core (drd-cfg, drd-bulk, drd-ausbc), + * mapped for their tunables * @tunables: Controller tunables from the device tree, see dwc3_apple_tunable_list */ struct dwc3_apple { @@ -158,7 +160,7 @@ struct dwc3_apple { bool pre_core_rpm; bool dt_dis_u3_susphy; - void __iomem *drd_cfg; + void __iomem *drd_regs[DWC3_APPLE_NR_DRD_REGS]; struct apple_tunable *tunables[DWC3_APPLE_NR_TUNABLES]; }; @@ -232,22 +234,43 @@ enum dwc3_apple_tunable_block { DWC3_APPLE_TUNABLE_GLOBALS, /* DWC3_GLOBALS_REGS_START */ DWC3_APPLE_TUNABLE_LINK, /* dwc3-core + 0xd000 */ DWC3_APPLE_TUNABLE_DBG, /* dwc3-core + 0xd800 */ + DWC3_APPLE_TUNABLE_CIO, /* dwc3-core + 0xcd20, in dwc3-apple */ + /* The optional blocks outside dwc3-core, in drd_regs[] order */ DWC3_APPLE_TUNABLE_DRD_CFG, /* drd-cfg */ + DWC3_APPLE_TUNABLE_DRD_BULK, /* drd-bulk */ + DWC3_APPLE_TUNABLE_DRD_AUSBC, /* drd-ausbc */ + DWC3_APPLE_NR_TUNABLE_BLOCKS }; +static const char * const dwc3_apple_drd_reg_names[DWC3_APPLE_NR_DRD_REGS] = { + "drd-cfg", "drd-bulk", "drd-ausbc", +}; + +static_assert(DWC3_APPLE_NR_TUNABLE_BLOCKS - DWC3_APPLE_TUNABLE_DRD_CFG == DWC3_APPLE_NR_DRD_REGS); + #define DWC3_APPLE_LINK_REGS_START 0xd000 #define DWC3_APPLE_DBG_REGS_START 0xd800 #define DWC3_APPLE_LINK_DBG_SIZE 0x800 +/* The CIO registers, the fixed ones of dwc3_apple_setup_cio() included */ +#define DWC3_APPLE_CIO_REGS_START 0xcd20 +/* + * In the order they are applied. A table is optional, and one for a block that the device tree + * does not describe is refused. The CIO table follows dwc3_apple_setup_cio() and overrides its + * fixed values (T6050). + */ static const struct { const char *prop; enum dwc3_apple_tunable_block block; } dwc3_apple_tunable_list[] = { + { "apple,tunable-bulk", DWC3_APPLE_TUNABLE_DRD_BULK }, { "apple,tunable-gbl-default", DWC3_APPLE_TUNABLE_GLOBALS }, { "apple,tunable-gbl-host", DWC3_APPLE_TUNABLE_GLOBALS }, + { "apple,tunable-cio", DWC3_APPLE_TUNABLE_CIO }, { "apple,tunable-dbg", DWC3_APPLE_TUNABLE_DBG }, { "apple,tunable-cfg-host", DWC3_APPLE_TUNABLE_DRD_CFG }, { "apple,tunable-link", DWC3_APPLE_TUNABLE_LINK }, + { "apple,tunable-ausbc", DWC3_APPLE_TUNABLE_DRD_AUSBC }, }; static_assert(ARRAY_SIZE(dwc3_apple_tunable_list) == DWC3_APPLE_NR_TUNABLES); @@ -262,8 +285,14 @@ static void __iomem *dwc3_apple_tunable_base(struct dwc3_apple *appledwc, return appledwc->apple_regs + DWC3_APPLE_LINK_REGS_START - APPLE_DWC3_REGS_START; case DWC3_APPLE_TUNABLE_DBG: return appledwc->apple_regs + DWC3_APPLE_DBG_REGS_START - APPLE_DWC3_REGS_START; + case DWC3_APPLE_TUNABLE_CIO: + return appledwc->apple_regs + DWC3_APPLE_CIO_REGS_START - APPLE_DWC3_REGS_START; case DWC3_APPLE_TUNABLE_DRD_CFG: - return appledwc->drd_cfg; + case DWC3_APPLE_TUNABLE_DRD_BULK: + case DWC3_APPLE_TUNABLE_DRD_AUSBC: + return appledwc->drd_regs[block - DWC3_APPLE_TUNABLE_DRD_CFG]; + case DWC3_APPLE_NR_TUNABLE_BLOCKS: + break; } return NULL; } @@ -281,8 +310,9 @@ static void dwc3_apple_apply_tunables(struct dwc3_apple *appledwc) /* The tunables are optional; a malformed one fails the probe. */ static int dwc3_apple_parse_tunables(struct dwc3_apple *appledwc, struct platform_device *pdev) { - struct resource *core = appledwc->mmio_resource, *drd_cfg; - struct resource blocks[] = { + struct resource *core = appledwc->mmio_resource; + /* A block the device tree does not describe stays empty, and its table is refused. */ + struct resource blocks[DWC3_APPLE_NR_TUNABLE_BLOCKS] = { [DWC3_APPLE_TUNABLE_GLOBALS] = DEFINE_RES_MEM(core->start + DWC3_GLOBALS_REGS_START, DWC3_GLOBALS_REGS_END - DWC3_GLOBALS_REGS_START + 1), @@ -290,17 +320,24 @@ static int dwc3_apple_parse_tunables(struct dwc3_apple *appledwc, struct platfor DWC3_APPLE_LINK_DBG_SIZE), [DWC3_APPLE_TUNABLE_DBG] = DEFINE_RES_MEM(core->start + DWC3_APPLE_DBG_REGS_START, DWC3_APPLE_LINK_DBG_SIZE), - [DWC3_APPLE_TUNABLE_DRD_CFG] = DEFINE_RES_MEM(0, 0), + [DWC3_APPLE_TUNABLE_CIO] = DEFINE_RES_MEM(core->start + DWC3_APPLE_CIO_REGS_START, + APPLE_DWC3_REGS_END - + DWC3_APPLE_CIO_REGS_START + 1), }; struct device *dev = appledwc->dev; int i; - drd_cfg = platform_get_resource_byname(pdev, IORESOURCE_MEM, "drd-cfg"); - if (drd_cfg) { - appledwc->drd_cfg = devm_ioremap_resource(dev, drd_cfg); - if (IS_ERR(appledwc->drd_cfg)) - return PTR_ERR(appledwc->drd_cfg); - blocks[DWC3_APPLE_TUNABLE_DRD_CFG] = *drd_cfg; + for (i = 0; i < DWC3_APPLE_NR_DRD_REGS; i++) { + struct resource *res; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + dwc3_apple_drd_reg_names[i]); + if (!res) + continue; + appledwc->drd_regs[i] = devm_ioremap_resource(dev, res); + if (IS_ERR(appledwc->drd_regs[i])) + return PTR_ERR(appledwc->drd_regs[i]); + blocks[DWC3_APPLE_TUNABLE_DRD_CFG + i] = *res; } for (i = 0; i < ARRAY_SIZE(dwc3_apple_tunable_list); i++) { @@ -628,8 +665,13 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat dwc3_enable_susphy(&appledwc->dwc, true); ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); if (ret) { - /* A failed T8132 BIST or PIPE handoff must not start xHCI. */ - if (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) + /* + * A failed T8132 BIST or PIPE handoff must not start xHCI. Neither must a failed + * T6050 one: that PHY reports a port left on USB2 (four DisplayPort lanes) as + * success, and its errors leave the PIPE without a known producer. + */ + if (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3") || + of_device_is_compatible(appledwc->dev->of_node, "apple,t6050-dwc3")) return ret; dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); } else if (host && appledwc->usb3_phy && @@ -648,18 +690,19 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat } /* - * No device mode: the T6040 USB2 PHY implements host mode only (phy-apple-t6040-usb2), and a - * kernel built without gadget support turns dwc3_gadget_init() into a stub that succeeds. Such a - * controller must not follow a USB_ROLE_DEVICE request from the Type-C port controller (a charger - * or a host on the other end), or the core would end up in device mode on top of a PHY powered - * in host mode. + * No device mode: the T6040 USB2 PHY (phy-apple-t6040-usb2) and the T6050 Type-C PHY implement + * host mode only, and a kernel built without gadget support turns dwc3_gadget_init() into a stub + * that succeeds. Such a controller must not follow a USB_ROLE_DEVICE request from the Type-C port + * controller (a charger or a host on the other end), or the core would end up in device mode on + * top of a PHY powered in host mode. */ static bool dwc3_apple_host_only(struct device *dev) { if (!IS_ENABLED(CONFIG_USB_DWC3_GADGET) && !IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) return true; - return of_device_is_compatible(dev->of_node, "apple,t6040-dwc3"); + return of_device_is_compatible(dev->of_node, "apple,t6040-dwc3") || + of_device_is_compatible(dev->of_node, "apple,t6050-dwc3"); } static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state state) @@ -691,6 +734,16 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st dev_err(appledwc->dev, "Failed to initialize host, ret=%d\n", ret); goto core_exit; } + /* + * A USB2 PHY with a port reset (the T6050 Type-C PHY) takes it once the root hub is + * up; for the other PHYs, which have none, this is a no-op. + */ + ret = phy_reset(appledwc->usb2_phy); + if (ret) { + dev_err(appledwc->dev, "Failed to reset the USB2 port, ret=%d\n", ret); + dwc3_host_exit(&appledwc->dwc); + goto core_exit; + } break; case DWC3_APPLE_DEVICE: ret = dwc3_gadget_init(&appledwc->dwc); From 84bb560eae24d18e014da4ab3450e125ab70b157 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:03:34 -0500 Subject: [PATCH 196/342] dt-bindings: soc: apple: apple,sep: Take the T6050 SEP through its mailbox node The T6050 SEP was described from the ADT with its four mailbox interrupts on its own node and had to stay disabled. Its mailbox is an ASC v4 mailbox at the SEP + 0x8000, as on the other SoCs, so describe it as its own node there and require mboxes for every SEP. T6050 keeps its second reg and its clock. Signed-off-by: Diljit Singh --- .../bindings/soc/apple/apple,sep.yaml | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,sep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,sep.yaml index 4ab4e2439b7aa..1a20d2ce27eb5 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,sep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,sep.yaml @@ -39,12 +39,6 @@ properties: mbox-names: const: mbox - interrupts: - maxItems: 4 - description: - The coprocessor's mailbox interrupts, on a SoC whose SEP mailbox is not - described as a separate node. - clocks: maxItems: 1 @@ -83,6 +77,8 @@ required: - compatible - reg - iommus + - mboxes + - mbox-names allOf: - if: @@ -91,26 +87,12 @@ allOf: contains: const: apple,t6050-sep then: - description: - The T6050 SEP is described from the ADT and stays disabled until its - mailbox and firmware handoff are supported. properties: reg: minItems: 2 - interrupts: - minItems: 4 - status: - const: disabled - required: - - interrupts - - status else: properties: - interrupts: false clocks: false - required: - - mboxes - - mbox-names additionalProperties: false From 7bdc93485d2db05dbc422cae019480d4686aa558 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:03:35 -0500 Subject: [PATCH 197/342] arm64: dts: apple: t6050: Add the SEP's mailbox and DART window iBoot hands over a running SEP on the M5 Pro (sepfw-booted in the J714sAP ADT). Describe what apple_sep needs to attach to it: the ASC v4 mailbox at the SEP + 0x8000, with the first four ADT interrupts in mailbox order (533 to 536: send empty, send not empty, receive empty, receive not empty), and the DMA window iBoot programmed in the SEP DART (dart-sep vm-base-0 0x10000004000, vm-size-0 0xffff0000), which T8140 has too. Everything stays disabled: a board enables the mailbox, and apple_sep enables the SEP and its DART when it loads. Signed-off-by: Diljit Singh --- .../boot/dts/apple/t6050-peripherals.dtsi | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index eef667d647d3d..c2faa9065b0f7 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2200,25 +2200,44 @@ status = "disabled"; }; + /* iBoot hands over a running SEP; apple_sep enables it and its DART when it loads. */ sep: sep@502600000 { compatible = "apple,t6050-sep", "apple,sep"; reg = <0x5 0x2600000 0x0 0x88000>, <0x5 0x2050000 0x0 0x4000>; - interrupts = , - , - , - ; + mboxes = <&sep_mbox>; + mbox-names = "mbox"; iommus = <&sep_dart 0>; power-domains = <&ps_sep>; clocks = <&peripheral_clocks 447>; status = "disabled"; }; + /* The ASC v4 mailbox at sep + 0x8000; the first four ADT interrupts in mailbox order */ + sep_mbox: mailbox@502608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x5 0x2608000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + sep_dart: iommu@500b80000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; reg = <0x5 0xb80000 0x0 0x20000>; interrupts = ; #iommu-cells = <1>; + /* + * The window iBoot programmed (ADT dart-sep vm-base-0, vm-size-0), which + * already carries the BIT(40) alias the DART translates. + */ + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; status = "disabled"; }; From fcd9b17e92585cb89b6f9f1c91d12723701ee985 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:03:36 -0500 Subject: [PATCH 198/342] soc: apple: sep: Add the M5 Pro (J714s) profile The J714sAP ADT (26A428) describes the enclave as J616s's: pre-booted (sepfw-booted), an iop-sep,ascwrap-v6 SEP behind a DART whose window starts at the BIT(40) alias (vm-base-0 0x10000004000, 0xffff0000 long), and J700's Mesa sensor (sensor-id 0x3356) on spi2, here at 0x505108000, 8 MHz, chip select 0. Take T6040's profile with that sensor bus. Signed-off-by: Diljit Singh --- drivers/soc/apple/profile.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index b824b00c16042..5accaf70cb404 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -26,6 +26,8 @@ //! the T8140 SEP DART aperture above 4 GiB. //! * `T6040` / J616s (MacBook Pro 16", M4 Pro): iBoot boots sepOS, so the //! driver uses the warm registration path; the sensor is the J700 part. +//! * `T6050` / J714s (MacBook Pro 14", M5 Pro): T6040's SEP and sensor, with +//! the sensor's bus at its own address. // The boot handshake, identity source, sensor and DART fields are consumed by // the boot-endpoint, identity and sensor-transport paths. @@ -457,6 +459,21 @@ pub(crate) const T6041: PlatformProfile = PlatformProfile { ..T6040 }; +/// MacBook Pro 14" M5 Pro (J714s). The J714sAP ADT (26A428) records a +/// pre-booted SEP (`sepfw-booted`), an `iop-sep,ascwrap-v6` SEP whose DART +/// aperture starts at the BIT(40) alias (`vm-base-0` 0x10000004000, +/// `vm-size-0` 0xffff0000), and the Mesa sensor J700 carries (`sensor-id` +/// 0x3356) on spi2 at `0x505108000`, 8 MHz, chip select 0. That is J616s's +/// SEP, so T6040's profile with this sensor bus. +pub(crate) const T6050: PlatformProfile = PlatformProfile { + name: "T6050/J714s", + sensor: SensorProfile { + controller_base: 0x5_0510_8000, + ..T6040.sensor + }, + ..T6040 +}; + /// MacBook Air M4 (J713). The J713 ADT (26.6.2, 25G83) puts the Mesa sensor /// on spi2 at `0x3ad108000`, 8 MHz, chip select 0, with power on the NUB GPIO /// controller (pin 28) and data-ready on AP GPIO 199. The SEP is @@ -663,6 +680,9 @@ fn select( if has(b"apple,t6041") && has(b"apple,j616c") { return Ok(&T6041); } + if has(b"apple,t6050") && has(b"apple,j714s") { + return Ok(&T6050); + } // Only the M4 MacBook Airs: the other T8132 Macs are unread. if has(b"apple,t8132") && (has(b"apple,j713") || has(b"apple,j715")) { return Ok(&T8132); @@ -745,6 +765,8 @@ mod tests { assert_eq!(picked(&[b"apple,j614s", b"apple,t6040"]), Some(T6040.name)); assert_eq!(picked(&[b"apple,j616c", b"apple,t6041"]), Some(T6041.name)); assert_eq!(picked(&[b"apple,j713", b"apple,t6041"]), None); + assert_eq!(picked(&[b"apple,j714s", b"apple,t6050"]), Some(T6050.name)); + assert_eq!(picked(&[b"apple,t6050"]), None); } /// Touch ID has one path for every Mac. The retry limits, the lock @@ -755,7 +777,7 @@ mod tests { /// profile naming one of the known Mesa revisions. #[test] fn every_touch_id_mac_gets_a_sensor_the_shared_path_decodes() { - let macs: [&[&[u8]]; 14] = [ + let macs: [&[&[u8]]; 15] = [ &[b"apple,j313", b"apple,t8103"], &[b"apple,j316s", b"apple,t6000"], &[b"apple,j316c", b"apple,t6001"], @@ -770,6 +792,7 @@ mod tests { &[b"apple,j616c", b"apple,t6041"], &[b"apple,j713", b"apple,t8132"], &[b"apple,j700", b"apple,t8140"], + &[b"apple,j714s", b"apple,t6050"], ]; for compatibles in macs { let has = |c: &[u8]| compatibles.iter().any(|x| *x == c); @@ -829,6 +852,7 @@ mod dart_window_tests { &T8122, &T6040, &T6041, + &T6050, &T8132, ] { assert_eq!(offset(profile.dart_window), 1 << 40); From 208b1496c2036506cea526f8b19abc7ffca52c14 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:46:48 -0500 Subject: [PATCH 199/342] arm64: dts: apple: t6050: Leave the SEP's power domain to its firmware iBoot starts the enclave, and the enclave gates its own domain for a sleep (DEV_DISABLE in the state word, which macOS clears at the wake). Its state word idles at actual 0 under auto-enable while it runs, so the pwrstate driver would take it for off and write it. Mark it firmware-owned: genpd keeps it on and never touches the register, and the SEP driver reads the word itself. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-peripherals.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index c2faa9065b0f7..e82926b257398 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -545,6 +545,7 @@ power-domains = <&ps_fab8_soc>; status = "disabled"; }; + /* The enclave runs from iBoot and gates its own domain: never Linux's to change. */ ps_sep: power-controller@298 { compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; reg = <0x298 4>; @@ -552,6 +553,7 @@ #reset-cells = <0>; label = "sep"; power-domains = <&ps_fab8_soc>; + apple,firmware-owned; status = "disabled"; }; ps_sio_cpu: power-controller@2a0 { From 8c09eadb70516dda2b41d876c5487a13b9837897 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:56:14 +1100 Subject: [PATCH 200/342] arm64: dts: apple: t8140-j700: Enable the AOP and always-on GPIO banks Enable the two GPIO banks the AP can reach next to the AOP: - pinctrl@310824000 (aop-gpio, 57 pins) with only the host interrupt groups 4-6 (AIC 384-386) and apple,irq-group-base = <4>, so the chained handler never reads the pending bits of the groups the AOP firmware programs. - pinctrl@3081f0000 (nub-gpio, 30 pins) without interrupts, the shape the J616s runs, and line 20 (the secure-repair enable) in gpio-reserved-ranges so it can be neither requested nor accessed through the regmap. No consumer requests a line. Both power states are always-on. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-j700.dts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index e4634a965e642..bbaf941493c2f 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -699,6 +699,30 @@ status = "okay"; }; +/* + * The AOP's GPIO bank. The AOP keeps interrupt groups 0-3; the AP's are 4-6 + * (AIC 384-386). No consumer requests a line yet. + */ +&pinctrl_aop { + interrupts = , + , + ; + apple,irq-group-base = <4>; + status = "okay"; +}; + +/* + * The always-on GPIO bank, as on the J616s: the AP takes none of its + * interrupts. Line 20 is the secure-repair enable and is never requested. + */ +&pinctrl_nub { + gpio-reserved-ranges = <20 1>; + status = "okay"; + /delete-property/ interrupt-controller; + /delete-property/ #interrupt-cells; + /delete-property/ interrupts; +}; + &smc_gpio { apple,pcio-templates = <10 0x800000 0xa0000>; }; From 78a9f60f8e5f9720dfed07c2c3918932ffc8b6eb Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:56:49 +1100 Subject: [PATCH 201/342] dt-bindings: pwm: apple,s5l-fpwm: Allow the controller interrupt Each FPWM instance has its own interrupt line. Allow one optional interrupts entry so nodes can describe it; the driver does not use it. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml b/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml index 6988fb5da2d95..f7dcfa5bb4d29 100644 --- a/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml +++ b/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml @@ -36,6 +36,9 @@ properties: clocks: maxItems: 1 + interrupts: + maxItems: 1 + power-domains: maxItems: 1 From 44672bdce7c2157a891de6736655b4ed58760e75 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:56:49 +1100 Subject: [PATCH 202/342] arm64: dts: apple: t8112-j413, t8140-j700: Enable the spare FPWM0 channel The T8112 block at 0x235040000 sits next to FPWM1 (the keyboard backlight) and is gated by FPWM0. Describe it as an FPWM instance for pwm-apple and enable it on the J413. Enable the T8140 FPWM0 on the J700. No consumer references either channel: each shows up as a one-channel pwmchip that stays disabled until a user configures it. Probe only reads the control register. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-j413.dts | 5 +++++ arch/arm64/boot/dts/apple/t8112-peripherals.dtsi | 10 ++++++++-- arch/arm64/boot/dts/apple/t8140-j700.dts | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 9c9e7532ae048..a596e8f8c53e0 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -168,6 +168,11 @@ status = "okay"; }; +/* A spare PWM channel for developers; no consumer is known. */ +&fpwm0 { + status = "okay"; +}; + &fpwm1 { status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi index 1869b990d571f..03d32043891eb 100644 --- a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi @@ -72,12 +72,18 @@ status = "disabled"; }; - m2_pwm: pwm@235040000 { - compatible = "apple,t8112-pwm", "apple,pwm"; + /* + * The FPWM0 instance, next to the keyboard backlight's FPWM1. No board + * wires it to anything known: a spare PWM channel with no consumer. + */ + fpwm0: pwm@235040000 { + compatible = "apple,t8112-fpwm", "apple,s5l-fpwm"; reg = <0x2 0x35040000 0x0 0x4000>; interrupt-parent = <&aic>; interrupts = ; power-domains = <&ps_fpwm0>; + clocks = <&clkref>; + #pwm-cells = <2>; status = "disabled"; }; diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index bbaf941493c2f..4b5697595bc3b 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -695,6 +695,11 @@ }; }; +/* A spare PWM channel for developers; no consumer is known. */ +&fpwm0 { + status = "okay"; +}; + &smc { status = "okay"; }; From 498e9b1a3ab1fb2c3f637ecb5f82c110bf987f4b Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 23:01:02 +1100 Subject: [PATCH 203/342] selftests: apple: Model phy_reset() in the dwc3-apple host tests dwc3_apple_init() now resets the USB2 port through phy_reset() once the host is up. The dwc3 teardown model extracts dwc3_apple_init() and the PHY core functions it calls, so it needs phy_reset() and a reset member in its phy_ops; none of its PHYs has one, as on every SoC before T6050. neo-stability-tests also builds dwc3_apple_init() against a reduced dwc3_apple. Give it the usb2_phy member and a no-op phy_reset(). Assisted-by: LLM Signed-off-by: Ryan Murray --- tools/asahi/neo-stability-tests.py | 4 +++- tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c | 1 + tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/asahi/neo-stability-tests.py b/tools/asahi/neo-stability-tests.py index 067a9d502801c..1d0a5302af4ce 100644 --- a/tools/asahi/neo-stability-tests.py +++ b/tools/asahi/neo-stability-tests.py @@ -80,7 +80,7 @@ def function(source, name): enum dwc3_apple_state {DWC3_APPLE_PROBE_PENDING,DWC3_APPLE_NO_CABLE,DWC3_APPLE_HOST,DWC3_APPLE_DEVICE,DWC3_APPLE_SUSPENDED}; #define DWC3_GCTL_PRTCAP_HOST 1 struct dwc3 {int num_usb3_ports,num_usb2_ports;int usb3_generic_phy[2],usb2_generic_phy[2],usb3_phy,usb2_phy;int current_dr_role;bool dis_u3_susphy_quirk;}; -struct dwc3_apple {struct device*dev;struct dwc3 dwc;int lock,reset;enum dwc3_apple_state state;bool fixed_hub,host_only,rpm_held,core_active,core_exit_pending,reset_pending,dt_dis_u3_susphy;unsigned usb3_power_off_pending,usb2_power_off_pending;}; +struct dwc3_apple {struct device*dev;struct dwc3 dwc;int lock,reset;enum dwc3_apple_state state;bool fixed_hub,host_only,rpm_held,core_active,core_exit_pending,reset_pending,dt_dis_u3_susphy;unsigned usb3_power_off_pending,usb2_power_off_pending;int usb2_phy;}; static int core_error,host_error,gadget_error,reset_error,role_error,start_role; static unsigned rpm_puts; /* A started core holds the glue runtime PM reference until core_stop drops it. */ @@ -98,6 +98,8 @@ def function(source, name): #define BIT(x) (1UL << (x)) static void dwc3_event_buffers_cleanup(struct dwc3*d){} static int phy_power_off(int p){return 0;} +/* Only the T6050 Type-C USB2 PHY has a port reset; for the PHYs here it is a no-op. */ +static int phy_reset(int p){return 0;} static void usb_phy_set_suspend(int p,int suspend){} static void dwc3_core_exit_after_phy_power_off(struct dwc3*d){core_exits++;} static u16 get_unaligned_le16(const u8*p){return p[0]|p[1]<<8;} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index 806ec38dd7fd4..4c9f0ac4faad6 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -36,6 +36,7 @@ struct phy_ops { int (*exit)(struct phy *); int (*power_on)(struct phy *); int (*power_off)(struct phy *); + int (*reset)(struct phy *); }; struct phy { struct apple_atcphy *data; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index f42f8251fee56..0bf6edeac8c19 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1091,7 +1091,7 @@ def fn(n, name): 'atcphy_usb2_init', 'atcphy_usb3_power_off', 'atcphy_usb3_route', 'atcphy_usb3_set_mode', 'atcphy_usb2_power_off', '_atcphy_dwc3_reset_assert', 'atcphy_dwc3_reset_assert', 'atcphy_mux_set'), - 'phy': ('phy_init', 'phy_exit', 'phy_power_on', 'phy_power_off'), + 'phy': ('phy_init', 'phy_exit', 'phy_reset', 'phy_power_on', 'phy_power_off'), 'core': ('dwc3_phy_power_on', 'dwc3_phy_power_off', 'dwc3_phy_exit', 'dwc3_core_exit'), 'apple': ('dwc3_apple_host_before_core_init', 'dwc3_apple_core_stop', 'dwc3_apple_core_init', 'dwc3_apple_core_start', 'dwc3_apple_init', 'dwc3_apple_exit', 'dwc3_usb_role_switch_set'), From 44826a01ea0b34b1745b5255eb72985e7e9b7ab9 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 204/342] phy: apple: t6050: Enable the dummy PIPE PHY for the USB3 lock The PIPE lock that starts the USB3 handoff is acknowledged only while the combo PHY's dummy PIPE PHY is enabled (pipehandler NONSELECTED_OVERRIDE bit 15), as on the earlier ATC PHYs (T8122, T8140), and the bit resets to clear with the controller's domain. Without it the lock timed out, the PHY faulted and rear port 2 had no USB at all. Enable it before the controller leaves reset. Each PIPE-switch step returns its own code, and every fault of the PHY is logged with its reason (the pipehandler registers for PIPE faults); dwc3-apple logs a fatal USB3 PHY failure. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 37 ++++++++++++++++--- .../apple/usb-t6050/apple_t6050_usb3_pipe.h | 19 +++++++--- drivers/usb/dwc3/dwc3-apple.c | 4 +- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 3c3454ceb64de..6a9d97d233dcd 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -79,6 +79,17 @@ static int combo_quiesce(void *ctx) return ret; } +/* The pipehandler bank is the controller's: read it only while the controller holds its domain. */ +static void combo_pipe_fault(struct t6050_dp *dp, const char *what, int ret) +{ + dev_err(dp->dev, "%s failed (%d): pipe 00=%08x 04=%08x 0c=%08x 10=%08x 14=%08x 1c=%08x 20=%08x\n", + what, ret, readl(dp->banks[44]), readl(dp->banks[44] + 0x4), + readl(dp->banks[44] + 0xc), readl(dp->banks[44] + 0x10), + readl(dp->banks[44] + 0x14), readl(dp->banks[44] + 0x1c), + readl(dp->banks[44] + 0x20)); + dp->faulted = true; +} + static int combo_stop(struct t6050_dp *dp) { int ret; @@ -101,6 +112,7 @@ static int combo_stop(struct t6050_dp *dp) if (!ret) ret = atc_domain_set(&dp->domain[0], false); if (ret) { + dev_err(dp->dev, "stop failed (%d)\n", ret); dp->faulted = true; return ret < 0 ? ret : -EIO; } @@ -142,6 +154,7 @@ static int combo_start(struct t6050_dp *dp, enum combo_mode mode) } if (ret) { /* A partial shared transition has no cold-start ownership proof. */ + dev_err(dp->dev, "start of mode %d failed (%d)\n", mode, ret); dp->faulted = true; return ret < 0 ? ret : -EIO; } @@ -217,10 +230,12 @@ static int combo_usb2_mode(struct phy *phy, enum phy_mode mode, int submode) if (dp->usb2_active) return 0; ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb2_host); - if (ret) + if (ret) { + dev_err(dp->dev, "USB2 host start failed (%d)\n", ret); dp->faulted = true; - else + } else { dp->usb2_active = true; + } return ret; } @@ -233,8 +248,10 @@ static int combo_usb2_reset(struct phy *phy) if (dp->faulted || !dp->usb2_active) return -ENOLINK; ret = apple_t6050_usb2_port_reset(&dp->usb_io, dp, combo_sleep); - if (ret) + if (ret) { + dev_err(dp->dev, "USB2 port reset failed (%d)\n", ret); dp->faulted = true; + } return ret ? -EIO : 0; } @@ -261,7 +278,7 @@ static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) apple_tunable_apply(dp->banks[44], dp->pipe_default); ret = apple_t6050_usb3_pipe_switch(&dp->usb_io); if (ret) - dp->faulted = true; + combo_pipe_fault(dp, "USB3 PIPE switch", ret); else dp->pipe_active = true; return ret ? -EIO : 0; @@ -287,8 +304,10 @@ static int combo_usb3_poweroff(struct phy *phy) if (!ret) dp->usb2_active = false; } - if (ret) + if (ret) { + dev_err(dp->dev, "USB3 power-off failed (%d)\n", ret); dp->faulted = true; + } return ret ? -EIO : 0; } static const struct phy_ops combo_usb2_ops = { @@ -312,7 +331,7 @@ static int combo_reset_assert(struct reset_controller_dev *reset, unsigned long apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 0x10, 0x10); ret = apple_t6050_usb3_pipe_cold_dummy(&dp->usb_io); if (ret) - dp->faulted = true; + combo_pipe_fault(dp, "dummy PIPE park", ret); else dp->controller_active = false; return ret ? -EIO : 0; @@ -326,6 +345,12 @@ static int combo_reset_deassert(struct reset_controller_dev *reset, unsigned lon return -EINVAL; if (dp->faulted || !dp->usb2_active) return -ENOLINK; + /* + * The PIPE lock that starts the USB3 handoff is acknowledged only while the dummy PHY + * behind the mux is enabled (NONSELECTED_OVERRIDE bit 15), as on the earlier ATC PHYs. + * The bit resets to clear with the controller's domain, so set it for every session. + */ + apple_t6050_usb_mask(&dp->usb_io, 44, 0x20, BIT(15), BIT(15)); apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 0x10, 0); apple_t6050_usb_mask(&dp->usb_io, 44, 0x1c, 1, 1); dp->controller_active = true; diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h index 953a42dbc7aab..f70f6f1090381 100644 --- a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -36,6 +36,11 @@ apple_t6050_usb3_pipe_cold_dummy(const struct apple_t6050_usb_io *io) return (io->read(io->context, 44, 0x0c) & 0x73) == 0x42 ? 0 : -1; } +/* + * Returns 0, or the failing step: -2 the PIPE was not parked on a known producer, -3 the lock was + * not acknowledged, -4..-6 the BIST, -7 the mux did not read back USB3, -8 the BIST did not stop, + * -9 the lock release was not acknowledged. Up to -6 the mux is untouched. + */ static inline int apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) { @@ -48,22 +53,26 @@ apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) mux = io->read(io->context, 44, 0x0c) & 0x73; /* Never reroute an active USB4 producer or guess an unknown state. */ if (!(aon & 1) || (mux != 0x42 && mux != 0x10)) - return -1; + return -2; /* Native T8142 xHCI USB3 mode switch, native27 T6050-compatible path. */ apple_t6050_usb_mask(io, 44, 0x04, 0x0e, 0); apple_t6050_usb_mask(io, 44, 0x00, 1, 1); apple_t6050_usb_mask(io, 44, 0x10, 1, 1); locked = 1; + result = -3; if (io->poll(io->context, 44, 0x14, 1, 1, 6000)) goto out; bist = 1; + result = -4; if (apple_t6050_usb_bist_on(io)) goto out; apple_t6050_usb_mask(io, 44, 0x20, 0x100f, 3); + result = -5; if (io->poll(io->context, 44, 0x20, 0xf, 3, 1000)) goto out; + result = -6; if (apple_t6050_usb_bist_off(io)) goto out; bist = 0; @@ -73,16 +82,16 @@ apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) io->delay(io->context, 5); apple_t6050_usb_mask(io, 44, 0x0c, 0x73, 0); apple_t6050_usb_mask(io, 44, 0x0c, 0x73, 0x10); - result = (io->read(io->context, 44, 0x0c) & 0x73) == 0x10 ? 0 : -1; + result = (io->read(io->context, 44, 0x0c) & 0x73) == 0x10 ? 0 : -7; out: if (bist && apple_t6050_usb_bist_off(io)) - result = -1; + result = -8; apple_t6050_usb_mask(io, 44, 0x00, 5, 0); if (locked) { apple_t6050_usb_mask(io, 44, 0x10, 1, 0); - if (io->poll(io->context, 44, 0x14, 1, 0, 6000)) - result = -1; + if (io->poll(io->context, 44, 0x14, 1, 0, 6000) && !result) + result = -9; } return result; } diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index f2484ee172862..f66370e6b5f88 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -671,8 +671,10 @@ static int dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_stat * success, and its errors leave the PIPE without a known producer. */ if (of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3") || - of_device_is_compatible(appledwc->dev->of_node, "apple,t6050-dwc3")) + of_device_is_compatible(appledwc->dev->of_node, "apple,t6050-dwc3")) { + dev_err(appledwc->dev, "USB3 PHY setup failed, err=%d\n", ret); return ret; + } dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); } else if (host && appledwc->usb3_phy && of_device_is_compatible(appledwc->dev->of_node, "apple,t8132-dwc3")) { From 4e780eb1f424544e685674f2460dd0f0cbdf1860 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 205/342] phy: apple: t6050: Stay on USB2 when the PIPE never left the dummy A USB3 PIPE switch can fail before the mux moves, with the PIPE still on its dummy producer. The PHY then faulted and lost USB2 with it. Leave the port on USB2 in that case, as four DisplayPort lanes do. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 6a9d97d233dcd..d4aa80de61ac8 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -277,6 +277,11 @@ static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) return (readl(dp->banks[44] + 0xc) & 0x73) == 0x10 ? 0 : -EIO; apple_tunable_apply(dp->banks[44], dp->pipe_default); ret = apple_t6050_usb3_pipe_switch(&dp->usb_io); + if (ret >= -6 && ret < 0 && (readl(dp->banks[44] + 0xc) & 0x73) == 0x42) { + /* The PIPE never left its dummy producer: the port stays USB2, as with four DP lanes. */ + dev_warn(dp->dev, "USB3 PIPE switch failed (%d), the port runs USB2 only\n", ret); + return 0; + } if (ret) combo_pipe_fault(dp, "USB3 PIPE switch", ret); else From 931f247beeb2cdc67b078f511e3825373e1f95c1 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 01:50:54 -0800 Subject: [PATCH 206/342] phy: apple: t6050: Accept every Type-C port but the debug port The combo PHY refused any apple,port-index other than 1 or 2, the two ports a guest description produced. Nothing else in the driver reads the index: the firmware buffer, banks and sequences are port-agnostic. Validate it against the board's port set instead: 1 to 5, with 0 (the port that carries the boot loader's debug link) still excluded, here and in the binding. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml | 4 ++-- drivers/phy/apple/atc-t6050-dp.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml index fdc2e60461700..8cbfe94b62ecd 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml @@ -38,8 +38,8 @@ properties: apple,port-index: $ref: /schemas/types.yaml#/definitions/uint32 - enum: [1, 2] - description: Native Type-C port; the debug/proxy port is excluded + enum: [1, 2, 3, 4, 5] + description: Type-C port; the debug port (0) is excluded apple,guest-port-reserved: type: boolean diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 4479153919488..01c666bb9e7dc 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -623,8 +623,9 @@ static int t6050_dp_probe(struct platform_device *pdev) dp->combo = of_device_is_compatible(dev->of_node, "apple,t6050-combo-phy"); if (dp->combo) { u32 port; + /* Every Type-C port but 0, the debug port that carries the boot link. */ if (of_property_read_u32(dev->of_node, "apple,port-index", &port) || - (port != 1 && port != 2) || + port < 1 || port > 5 || !of_property_present(dev->of_node, "apple,guest-port-reserved") || !of_property_present(dev->of_node, "mode-switch")) return -EINVAL; From 03a0475542f1a47ffdc5cb4b452a5086b31b1ec8 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:22:09 -0500 Subject: [PATCH 207/342] arm64: dts: apple: j716c: Add the right USB-C port (ATC2) Describe the right-hand USB-C port: its SN201202x PD controller, the ATC2 combo PHY, usb-drd2 and its DARTs, and their power domains. On J716c the port's HPM is ADT /arm-io/nub-spmi-a1/hpm2 (SPMI address 0xc, port-location "right"), on its own SPMI bus, not on nub-spmi-a0 at address 8 as on J775D; on J716c that address is hpm5 (port-type 0x11), not a port's controller. Add nub-spmi-a1 to t6050-max.dtsi, polled as nub-spmi-a0 is, put the HPM on it, and enable the ATC2 chain that J775D leaves to the display handoff. Add the atcphy2 alias so that the boot loader fills the PHY's tunables from /arm-io/atc-phy2, and turn dcpext0's Type-C route off with dcpext0: a mode-switch endpoint whose mux is never registered would defer the PD controller forever. Developed with Claude Code. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 122 +++++++++++++++++- arch/arm64/boot/dts/apple/t6050-max.dtsi | 13 ++ .../boot/dts/apple/t6050-peripherals.dtsi | 2 +- 3 files changed, 135 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 33fd4e1c9b03c..550aef6f8768f 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -13,6 +13,7 @@ /dts-v1/; +#define T6050_J716C #include "t6050-max.dtsi" / { @@ -220,5 +221,124 @@ apple,output-commands = /bits/ 64 <0x001a000000000000 0x000f000000800000 0x011c000000010000>; }; -#define T6050_J716C #include "t6050-peripherals.dtsi" + +/* + * ==== The right USB-C port (ATC2) ==== + * + * ADT /arm-io/nub-spmi-a1/hpm2 (SN201202x, SPMI address 0xc, port-number 3, port-location + * "right", acio-parent acio2), atc-phy2, usb-drd2 and dart-usb2. The HPM is on its own bus, + * nub-spmi-a1, and nothing hands the port off, so the chain is enabled outright. Aura's + * kboot_setup_atc() fills the PHY's tunables through the atcphy2 alias. + */ +/ { + aliases { + atcphy2 = &atc2_phy; + }; +}; + +&ps_atc2_common { + status = "okay"; +}; + +&ps_atc2_usb_aon { + status = "okay"; +}; + +&ps_atc2_phymxwrap { + status = "okay"; +}; + +&ps_atc2_usb { + status = "okay"; +}; + +&atc2_phy_mbox { + status = "okay"; +}; + +&atc2_phy { + status = "okay"; + + port { + atc2_phy_ep: endpoint { + remote-endpoint = <&hpm2_ss>; + }; + }; +}; + +&usb_drd2 { + status = "okay"; + + port { + usb_drd2_hs: endpoint { + remote-endpoint = <&hpm2_hs>; + }; + }; +}; + +&usb_drd2_dart_0 { + status = "okay"; +}; + +&usb_drd2_dart_1 { + status = "okay"; +}; + +/* + * dcpext0's Type-C route stays off with dcpext0: a mode-switch endpoint whose mux is never + * registered would defer the PD controller forever. + */ +&dcpext0 { + typec-routes { + route@0 { + status = "disabled"; + + port { + dcpext0_typec: endpoint { + remote-endpoint = <&hpm2_dp>; + }; + }; + }; + }; +}; + +&nub_spmi_a1 { + hpm2: usb-pd@c { + compatible = "apple,sn201202x"; + reg = <0xc SPMI_USID>; + + connector { + compatible = "usb-c-connector"; + label = "USB-C Right"; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + hpm2_hs: endpoint { + remote-endpoint = <&usb_drd2_hs>; + }; + }; + + port@1 { + reg = <1>; + hpm2_ss: endpoint { + remote-endpoint = <&atc2_phy_ep>; + }; + }; + + port@2 { + reg = <2>; + hpm2_dp: endpoint { + remote-endpoint = <&dcpext0_typec>; + }; + }; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index 760094fce8097..55cf22a98e2a2 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -115,4 +115,17 @@ interrupt-controller; #interrupt-cells = <2>; }; + +#ifdef T6050_J716C + /* + * /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, generation 4, a bus of USB-C PD controllers (the + * board's). They are polled, as on nub-spmi-a0, so the bus takes no interrupt. + */ + nub_spmi_a1: spmi@28a1a8000 { + compatible = "apple,t6050-spmi", "apple,t8142-spmi"; + reg = <0x2 0x8a1a8000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + }; +#endif }; diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index eef667d647d3d..ae450252f2acb 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -1319,7 +1319,7 @@ }; #endif -#if defined(T6050_J714C) || defined(T6050_J714S) || defined(T6050_J716C) || defined(T6050_K114C) || defined(T6050_K114S) || defined(T6050_K116C) || defined(T6050_K116S) +#if defined(T6050_J714C) || defined(T6050_J714S) || defined(T6050_K114C) || defined(T6050_K114S) || defined(T6050_K116C) || defined(T6050_K116S) nub_spmi_a1: spmi@28a1a8000 { compatible = "apple,t6050-spmi", "apple,t8142-spmi"; reg = <0x2 0x8a1a8000 0x0 0x4000>, From a1d086a6f287ddb74788f6a634ecfc4de343c4e8 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:35:50 -0500 Subject: [PATCH 208/342] phy: apple: t6050: carry on when the PIPE lock is not acknowledged On J716c the PIPE handler does not acknowledge the lock request when the controller switches from the dummy producer to USB3, even with the dummy PHY behind the mux enabled. The switch then fails and the port falls back to USB2. The switch works without the ACK. Wait 6 ms for the lock ACK, and for an unlock ACK to clear, then log the PIPE handler state if it is missing and complete the switch. With this, USB3 comes up on that port. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 12 +++++++++++- .../phy/apple/usb-t6050/apple_t6050_usb3_pipe.h | 14 ++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index d4aa80de61ac8..1da782c4f9de4 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -18,9 +18,19 @@ static int combo_poll(void *ctx, unsigned int bank, unsigned int offset, { struct t6050_dp *dp = ctx; u32 value; - return readl_poll_timeout(dp->banks[bank] + offset, value, + int ret = readl_poll_timeout(dp->banks[bank] + offset, value, (value & mask) == expected, (bank == 44 || bank == 35 || usec <= 1000) ? 1 : 1000, usec); + + /* The PIPE switch carries on without the lock ACK; say so. */ + if (ret && bank == 44 && offset == 0x14 && usec == 6000) + dev_warn(dp->dev, + "PIPE %slock not acknowledged; continuing (override=%x values=%x mux=%x req=%x ack=%x aon=%x nonsel=%x)\n", + expected ? "" : "un", readl(dp->banks[44]), + readl(dp->banks[44] + 4), readl(dp->banks[44] + 0xc), + readl(dp->banks[44] + 0x10), value, + readl(dp->banks[44] + 0x1c), readl(dp->banks[44] + 0x20)); + return ret; } static void combo_delay(void *ctx, unsigned int usec) { udelay(usec); } static void combo_pause(void *ctx, unsigned int nsec) { ndelay(nsec); } diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h index f70f6f1090381..812227cac03e9 100644 --- a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -37,9 +37,10 @@ apple_t6050_usb3_pipe_cold_dummy(const struct apple_t6050_usb_io *io) } /* - * Returns 0, or the failing step: -2 the PIPE was not parked on a known producer, -3 the lock was - * not acknowledged, -4..-6 the BIST, -7 the mux did not read back USB3, -8 the BIST did not stop, - * -9 the lock release was not acknowledged. Up to -6 the mux is untouched. + * Returns 0, or the failing step: -2 the PIPE was not parked on a known producer, -4..-6 the + * BIST, -7 the mux did not read back USB3, -8 the BIST did not stop. Up to -6 the mux is + * untouched. A lock or unlock that is not acknowledged within 6 ms is not fatal: it is logged + * and the switch carries on. On J716c the lock ACK does not come. */ static inline int apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) @@ -60,9 +61,7 @@ apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) apple_t6050_usb_mask(io, 44, 0x00, 1, 1); apple_t6050_usb_mask(io, 44, 0x10, 1, 1); locked = 1; - result = -3; - if (io->poll(io->context, 44, 0x14, 1, 1, 6000)) - goto out; + io->poll(io->context, 44, 0x14, 1, 1, 6000); bist = 1; result = -4; @@ -90,8 +89,7 @@ apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) apple_t6050_usb_mask(io, 44, 0x00, 5, 0); if (locked) { apple_t6050_usb_mask(io, 44, 0x10, 1, 0); - if (io->poll(io->context, 44, 0x14, 1, 0, 6000) && !result) - result = -9; + io->poll(io->context, 44, 0x14, 1, 0, 6000); } return result; } From 1856c663bd2501de5e7f3aa86d3216ab3c34d071 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 2 Nov 2026 23:41:32 -0500 Subject: [PATCH 209/342] reset: apple-cio: add the T6050 CIO reconfig request On T6050 the CPU wrapper of each USB4 router is clocked through the CIO reconfig request (the router CPU's clock gate CIOn_RECONFIG_V). Until it has run, any access to the wrapper faults. The request register uses the T8142 bit positions (request BIT(2 * port), four ports) and sits at offset 0x60 of a page in the die's PMGR block, 0x280620000 on die 0. Its odd bit is a done flag rather than a busy flag: it is set once the request is taken, then request and done clear by themselves about 4 ms later. The wrapper takes an SError when it is accessed before they clear. Wait for both bits to clear (a reconfiguration still under way), store the request, wait for the done flag, then wait for both bits to clear again. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/reset/apple,t8103-cio-reset.yaml | 3 + drivers/reset/reset-apple-cio.c | 65 +++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index a7bc6bf4885c9..5d7e40b564f91 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -22,6 +22,9 @@ description: | On t8142, a standalone register page contains a shared request register with alternating request and busy bits for four ports. + On t6050 the same request register sits at offset 0x60 of a page in the + die's PMGR block. + In all cases the reset id is the CIO port index on the die. properties: diff --git a/drivers/reset/reset-apple-cio.c b/drivers/reset/reset-apple-cio.c index af299473a6c87..e5755ebb39aff 100644 --- a/drivers/reset/reset-apple-cio.c +++ b/drivers/reset/reset-apple-cio.c @@ -37,7 +37,12 @@ * separate 16 KiB page at 0x350780000, so the register is 0x350780008. The * device tree describes that page as its own syscon. t8122 is unresolved. * - * On t8142, RegMap 0x62 is a separate MMIO region at 0x380780000. + * On t8142, RegMap 0x62 is a separate MMIO region at 0x380780000. On t6050 + * the register is at +0x60 in a page of the die's PMGR block (0x280620000 + * on die 0). There the odd bit is a done flag rather than a busy flag: it + * is set once the request is taken, then request and done clear by + * themselves within a few ms. Only after that is the port's CPU wrapper + * accessible. * The t8132 layout has not been decoded. * * Reference firmware polls the busy bits, stores the request, then polls @@ -56,6 +61,8 @@ #define APPLE_CIO_RESET_POLL_US 100 #define APPLE_CIO_RESET_TIMEOUT_US 100000 +/* A t6050 reconfiguration takes a few ms; allow ample margin. */ +#define APPLE_CIO_RESET_T6050_TIMEOUT_US 192000 #define T8103_CIO_CTRL_STRIDE 0x4000 #define T8103_CIO_CTRL_INIT_REQ BIT(0) @@ -75,6 +82,7 @@ struct apple_cio_reset; struct apple_cio_reset_variant { unsigned int nr_resets; bool pmgr_child; + u32 ctrl; /* request register, t8142 layout */ int (*deassert)(struct apple_cio_reset *priv, unsigned long id); }; @@ -174,19 +182,19 @@ static int t8142_cio_deassert(struct apple_cio_reset *priv, unsigned long id) guard(mutex)(&priv->lock); /* Serialize all four ports sharing the request register. */ - ret = regmap_read_poll_timeout(priv->regmap, T8142_CIO_CTRL, val, + ret = regmap_read_poll_timeout(priv->regmap, priv->variant->ctrl, val, !(val & T8142_CIO_CTRL_BUSY_MASK), APPLE_CIO_RESET_POLL_US, APPLE_CIO_RESET_TIMEOUT_US); if (ret) return ret; - ret = regmap_write(priv->regmap, T8142_CIO_CTRL, + ret = regmap_write(priv->regmap, priv->variant->ctrl, T8142_CIO_CTRL_INIT_REQ(id)); if (ret) return ret; - return regmap_read_poll_timeout(priv->regmap, T8142_CIO_CTRL, val, + return regmap_read_poll_timeout(priv->regmap, priv->variant->ctrl, val, !(val & T8142_CIO_CTRL_INIT_BUSY(id)), APPLE_CIO_RESET_POLL_US, APPLE_CIO_RESET_TIMEOUT_US); @@ -194,9 +202,54 @@ static int t8142_cio_deassert(struct apple_cio_reset *priv, unsigned long id) static const struct apple_cio_reset_variant apple_t8142_cio_reset = { .nr_resets = 4, + .ctrl = T8142_CIO_CTRL, .deassert = t8142_cio_deassert, }; +static int t6050_cio_deassert(struct apple_cio_reset *priv, unsigned long id) +{ + u32 mask = T8142_CIO_CTRL_INIT_REQ(id) | T8142_CIO_CTRL_INIT_BUSY(id); + u32 val; + int ret; + + guard(mutex)(&priv->lock); + + /* Let a reconfiguration still under way finish first. */ + ret = regmap_read_poll_timeout(priv->regmap, priv->variant->ctrl, val, + !(val & mask), APPLE_CIO_RESET_POLL_US, + APPLE_CIO_RESET_T6050_TIMEOUT_US); + if (ret) + return ret; + + ret = regmap_write(priv->regmap, priv->variant->ctrl, + T8142_CIO_CTRL_INIT_REQ(id)); + if (ret) + return ret; + + ret = regmap_read_poll_timeout(priv->regmap, priv->variant->ctrl, val, + val & T8142_CIO_CTRL_INIT_BUSY(id), + APPLE_CIO_RESET_POLL_US, + APPLE_CIO_RESET_T6050_TIMEOUT_US); + if (ret) + return ret; + + /* + * The CPU wrapper is usable only once the reconfiguration is over, when + * the request and done bits clear again, a few ms later. An access + * before that takes an SError. + */ + return regmap_read_poll_timeout(priv->regmap, priv->variant->ctrl, val, + !(val & mask), APPLE_CIO_RESET_POLL_US, + APPLE_CIO_RESET_T6050_TIMEOUT_US); +} + +/* The t8142 bit layout in a register mapped on its own, with a done flag. */ +static const struct apple_cio_reset_variant apple_t6050_cio_reset = { + .nr_resets = 4, + .ctrl = 0x60, + .deassert = t6050_cio_deassert, +}; + static const struct apple_cio_reset_variant apple_t8103_cio_reset = { .nr_resets = 2, .deassert = t8103_cio_deassert, @@ -277,6 +330,10 @@ static int apple_cio_reset_probe(struct platform_device *pdev) } static const struct of_device_id apple_cio_reset_match[] = { + { + .compatible = "apple,t6050-cio-reset", + .data = &apple_t6050_cio_reset, + }, { .compatible = "apple,t8142-cio-reset", .data = &apple_t8142_cio_reset, From 4aee080f4ed7f9a5eee673772f1dc8aa8906a4da Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 18:08:07 -0500 Subject: [PATCH 210/342] dt-bindings: phy: apple,t6050-dp-phy: Add the CIO tunables The CIO (USB4/Thunderbolt) mode has its own firmware register and receiver tunables. They are optional: an absent one is skipped. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/phy/apple,t6050-dp-phy.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml index 8cbfe94b62ecd..3b22c3f19ee9b 100644 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml @@ -126,6 +126,28 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32-array description: Offset, mask and value tuples within the named bank + apple,tunable-uc-regs-cio: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + Offset, mask and value tuples for the PHY firmware's registers in CIO + (USB4/Thunderbolt) mode. Optional; an absent CIO tunable is skipped. + + apple,tunable-lane0-rx-top-cio: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: As apple,tunable-uc-regs-cio, for lane 0's receiver top bank + + apple,tunable-lane1-rx-top-cio: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: As apple,tunable-uc-regs-cio, for lane 1's receiver top bank + + apple,tunable-lane0-rx-eq-cio: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: As apple,tunable-uc-regs-cio, for lane 0's receiver equalizer + + apple,tunable-lane1-rx-eq-cio: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: As apple,tunable-uc-regs-cio, for lane 1's receiver equalizer + patternProperties: '^apple,dp-training-table(-rbr|-hbr|-hbr2|-hbr3)?$': $ref: /schemas/types.yaml#/definitions/uint32-array From 8726ee82db1b8939997fa9468ddc962f56348f19 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:29:27 -0500 Subject: [PATCH 211/342] phy: apple: t6050: add the CIO (USB4/Thunderbolt) mode The T6050 combo PHY rejects TYPEC_MODE_USB4 and the Thunderbolt alternate mode, so a USB4 dock that the PD controller has already entered USB4 with gets no link: the PHY is never configured and DWC3 cannot start. Add the CIO mode as a step recipe in the style of the USB ones: - the mode-independent power-up; - the common tunables, then the CIO set (AUS40CMN_SHM, AUSPLL_CORE, CIO4PLL_CORE) and the CIO80 set (UC_REGS_CIO, LN0/LN1_RX_TOP_CIO, LN0/LN1_RX_EQ_CIO), with no USB or DP lane masks; - the crossbar in CIO, where orientation only selects TOP +0x78 bit 0; - the sleep-control release of both lanes; - the firmware start, UC_TNBL_DONE and the ACIOPHY reset release, without the PIPE BIST and the ATCPHY_CFG +0x8 orientation bit. The shutdown powers both transmitters and receivers down, shuts the common block down, stops the firmware and runs the usual sleep, clamp and reset sequence. USB2 runs beside the link, so the USB2 PHY is brought up as for USB. USB3 arrives through a tunnel later; in CIO the USB3 PHY set_mode leaves DWC3 on its dummy PIPE producer until a tunnel exists. The five CIO80 tunables are optional DT properties (apple,tunable-uc-regs-cio, -lane0/1-rx-top-cio, -lane0/1-rx-eq-cio); a missing one is skipped. On J716c only the RX_TOP pair is non-empty. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 55 ++++- drivers/phy/apple/atc-t6050-dp.c | 7 +- .../phy/apple/usb-t6050/apple_t6050_cio_phy.h | 189 ++++++++++++++++++ 3 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 drivers/phy/apple/usb-t6050/apple_t6050_cio_phy.h diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 1da782c4f9de4..c57779075ec05 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -54,6 +54,11 @@ static int combo_tunable(void *ctx, unsigned int bank, const char *name) {8, 8, "tunable_AUSPLL_CORE"}, {5, 9, "tunable_AUS40CMN_SHM"}, {10, 10, "tunable_CIO4PLL_CORE"}, }; + static const struct { u8 bank, index; const char *name; } cio[] = { + {3, 0, "tunable_UC_REGS_CIO_DFLT"}, {16, 1, "tunable_LN0_RX_TOP_CIO_DFLT"}, + {25, 2, "tunable_LN1_RX_TOP_CIO_DFLT"}, {18, 3, "tunable_LN0_RX_EQ_CIO_DFLT"}, + {27, 4, "tunable_LN1_RX_EQ_CIO_DFLT"}, + }; struct t6050_dp *dp = ctx; if (bank == 0 && !strcmp(name, "tunable_USB2PHY_DFLT")) { @@ -69,6 +74,12 @@ static int combo_tunable(void *ctx, unsigned int bank, const char *name) apple_tunable_apply(dp->banks[bank], dp->tunables[common[i].index]); return 0; } + /* A missing CIO80 tunable is skipped. */ + for (unsigned int i = 0; i < ARRAY_SIZE(cio); i++) + if (bank == cio[i].bank && !strcmp(name, cio[i].name)) { + apple_tunable_apply(dp->banks[bank], dp->cio_tunables[cio[i].index]); + return 0; + } return -EINVAL; } @@ -81,6 +92,10 @@ static int combo_quiesce(void *ctx) ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb3_shutdown); if (!ret) dp->usb_prepared = false; + } else if (dp->cio_prepared) { + ret = APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_cio_shutdown); + if (!ret) + dp->cio_prepared = false; } else if (dp->enabled) { /* Multifunction has a distinct native shutdown; never run the * USB-only analog sequence over live DisplayPort lane state. */ @@ -158,6 +173,19 @@ static int combo_start(struct t6050_dp *dp, enum combo_mode mode) APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_usb3_init_normal); if (!ret) dp->usb_prepared = true; + } else if (!ret && mode == COMBO_CIO) { + ktime_t start = ktime_get(); + + /* USB2 stays native beside a USB4/TBT link; USB3 comes tunnelled. */ + ret = dp->reverse ? + APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_cio_init_reverse) : + APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_cio_init_normal); + if (!ret) + dp->cio_prepared = true; + dev_info(dp->dev, "CIO mode %s (%d), %s orientation, %lld ms\n", + ret ? "failed" : "up: UC_TNBL_DONE", ret, + dp->reverse ? "reverse" : "normal", + ktime_ms_delta(ktime_get(), start)); } else if (!ret) { dp->multifunction = mode == COMBO_DP2; ret = atc_start(dp); @@ -201,6 +229,11 @@ static int combo_mux(struct t6050_dp *dp, struct typec_mux_state *state) mode = COMBO_SAFE; else if (state->mode == TYPEC_STATE_USB && !state->alt) mode = COMBO_USB; + else if (!state->alt && state->mode == TYPEC_MODE_USB4) + mode = COMBO_CIO; + else if (state->alt && state->alt->svid == USB_TYPEC_TBT_SID && + state->mode == TYPEC_TBT_MODE) + mode = COMBO_CIO; else if (state->alt && state->alt->svid == USB_TYPEC_DP_SID) { switch (state->mode) { case TYPEC_DP_STATE_C: @@ -215,7 +248,7 @@ static int combo_mux(struct t6050_dp *dp, struct typec_mux_state *state) if (dp->faulted) return -EIO; if (mode == dp->combo_mode && - (mode == COMBO_SAFE || dp->usb_prepared || dp->enabled)) + (mode == COMBO_SAFE || dp->usb_prepared || dp->cio_prepared || dp->enabled)) return 0; if (mode != COMBO_SAFE && dp->orientation == TYPEC_ORIENTATION_NONE) return -ENOLINK; @@ -235,7 +268,7 @@ static int combo_usb2_mode(struct phy *phy, enum phy_mode mode, int submode) return -EIO; if (mode != PHY_MODE_USB_HOST) return -EOPNOTSUPP; - if (!dp->usb_prepared && !dp->enabled) + if (!dp->usb_prepared && !dp->cio_prepared && !dp->enabled) return -ENOLINK; if (dp->usb2_active) return 0; @@ -281,6 +314,10 @@ static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) * uses its independent D+/D- PHY. Do not switch USB3 onto DP lanes. */ if (dp->combo_mode == COMBO_DP4 && dp->enabled) return 0; + /* In CIO the lanes carry USB4/TBT. DWC3 keeps its dummy PIPE until a + * USB3 tunnel hands PIPE to the router; native USB3 mode is 0 too. */ + if (dp->combo_mode == COMBO_CIO && dp->cio_prepared) + return 0; if (!dp->usb_prepared && !(dp->combo_mode == COMBO_DP2 && dp->enabled)) return -ENOLINK; if (dp->pipe_active) @@ -390,6 +427,12 @@ static struct phy *combo_xlate(struct device *dev, const struct of_phandle_args static int combo_setup(struct platform_device *pdev, struct t6050_dp *dp) { + /* Same order as the cio[] table in combo_tunable(). */ + static const struct { u8 bank; const char *name; } cio_tunables[] = { + {3, "apple,tunable-uc-regs-cio"}, {16, "apple,tunable-lane0-rx-top-cio"}, + {25, "apple,tunable-lane1-rx-top-cio"}, {18, "apple,tunable-lane0-rx-eq-cio"}, + {27, "apple,tunable-lane1-rx-eq-cio"}, + }; static const struct { u8 bank; u32 minimum; const char *name; } extra[] = { {0, 0x20, "usb2phy"}, {1, 0x24, "usb2-digital"}, {44, 0x48, "pipehandler"}, }; @@ -417,6 +460,14 @@ static int combo_setup(struct platform_device *pdev, struct t6050_dp *dp) "apple,tunable-pipe-default", &dp->resources[44]); if (IS_ERR(dp->pipe_default)) return PTR_ERR(dp->pipe_default); + for (unsigned int i = 0; i < ARRAY_SIZE(cio_tunables); i++) { + struct apple_tunable *t = devm_apple_tunable_parse(dev, dev->of_node, + cio_tunables[i].name, &dp->resources[cio_tunables[i].bank]); + + if (IS_ERR(t) && PTR_ERR(t) != -ENOENT) + return PTR_ERR(t); + dp->cio_tunables[i] = IS_ERR(t) ? NULL : t; + } dp->usb_io = (struct apple_t6050_usb_io) { .context = dp, .read = combo_read, .write = combo_write, .poll = combo_poll, .delay = combo_delay, diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 01c666bb9e7dc..e6941cf86c8ad 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -14,6 +14,7 @@ #include "usb-t6050/apple_t6050_usb_phy.h" #include "usb-t6050/apple_t6050_usb3_pipe.h" #include "usb-t6050/apple_t6050_usb2_reset.h" +#include "usb-t6050/apple_t6050_cio_phy.h" #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include enum atc_operation { ATC_MASK, ATC_TUNABLE, ATC_DELAY, ATC_POLL, ATC_POWER, ATC_FIRMWARE }; struct atc_op { @@ -68,9 +70,9 @@ struct atc_domain { struct device *dev; bool active; }; -enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2 }; +enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2, COMBO_CIO }; struct t6050_dp { - bool combo, usb_prepared, usb2_active, pipe_active, controller_active; + bool combo, usb_prepared, usb2_active, pipe_active, controller_active, cio_prepared; enum combo_mode combo_mode; enum typec_orientation orientation; struct phy *combo_phy[3]; @@ -78,6 +80,7 @@ struct t6050_dp { struct apple_t6050_usb_io usb_io; struct apple_t6050_usb_platform usb_platform; struct apple_tunable *usb2_default, *usb2_host, *pipe_default; + struct apple_tunable *cio_tunables[5]; /* optional; empty on J716c except RX_TOP */ struct device *dev; struct mutex lock; void __iomem *banks[45]; diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_cio_phy.h b/drivers/phy/apple/usb-t6050/apple_t6050_cio_phy.h new file mode 100644 index 0000000000000..4af28f8c2ccff --- /dev/null +++ b/drivers/phy/apple/usb-t6050/apple_t6050_cio_phy.h @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: MIT */ +/* ACIO80 PHY CIO (USB4/Thunderbolt) mode. + * + * The bring-up runs the mode-independent power-up (the USB recipes' first + * block), the common and CIO/CIO80 tunables, the crossbar, the sleep-control + * release and the firmware start. CIO applies no DP or USB lane masks, + * no DP clock switch and no orientation bit in ATCPHY_CFG +0x8; orientation + * only selects ACIOPHY_TOP +0x78 bit 0. Both lanes are released. + * Spread-spectrum stays on. + */ +#ifndef APPLE_T6050_CIO_PHY_H +#define APPLE_T6050_CIO_PHY_H +#include "apple_t6050_usb_phy.h" + +/* The power-up and reset release, identical to the USB recipes. */ +#define APPLE_T6050_CIO_POWERUP \ + { T6050_MASK, 39, 0x0, 0x1, 0x1, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_POLL, 39, 0x4, 0x1, 0x1, 1000, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 39, 0x0, 0x2, 0x2, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_POLL, 39, 0x4, 0x2, 0x2, 1000, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 39, 0x0, 0x4, 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_POWER, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 39, 0x2c, 0x1, 0x0, 0, 0 }, \ + { T6050_POLL, 39, 0x4, 0x100, 0x0, 1000, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 39, 0x0, 0x8, 0x8, 0, 0 } + +/* The common tunables, then the CIO set and the CIO80 set. An absent CIO80 + * tunable is skipped. + */ +#define APPLE_T6050_CIO_TUNABLES \ + { T6050_TUNABLE, 41, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF" }, \ + { T6050_TUNABLE, 40, 0x0, 0x0, 0x0, 0, "tunable_ATC_FABRIC" }, \ + { T6050_TUNABLE, 43, 0x0, 0x0, 0x0, 0, "tunable_ATC_COMMON_CFG" }, \ + { T6050_TUNABLE, 42, 0x0, 0x0, 0x0, 0, "tunable_ATC0AXI2AF_LIOA" }, \ + { T6050_TUNABLE, 20, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_CFG_TX_OF_RXCLK" }, \ + { T6050_TUNABLE, 29, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_CFG_TX_OF_RXCLK" }, \ + { T6050_TUNABLE, 18, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_EQ_DFLT" }, \ + { T6050_TUNABLE, 27, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_EQ_DFLT" }, \ + { T6050_TUNABLE, 5, 0x0, 0x0, 0x0, 0, "tunable_AUS40CMN_SHM" }, \ + { T6050_TUNABLE, 8, 0x0, 0x0, 0x0, 0, "tunable_AUSPLL_CORE" }, \ + { T6050_TUNABLE, 10, 0x0, 0x0, 0x0, 0, "tunable_CIO4PLL_CORE" }, \ + { T6050_TUNABLE, 3, 0x0, 0x0, 0x0, 0, "tunable_UC_REGS_CIO_DFLT" }, \ + { T6050_TUNABLE, 16, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_TOP_CIO_DFLT" }, \ + { T6050_TUNABLE, 25, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_TOP_CIO_DFLT" }, \ + { T6050_TUNABLE, 18, 0x0, 0x0, 0x0, 0, "tunable_LN0_RX_EQ_CIO_DFLT" }, \ + { T6050_TUNABLE, 27, 0x0, 0x0, 0x0, 0, "tunable_LN1_RX_EQ_CIO_DFLT" } + +/* The crossbar: clear the lane selects, set the orientation bit (+0x78) + * and select CIO. + */ +#define APPLE_T6050_CIO_XBAR(reverse) \ + { T6050_MASK, 2, 0x6c, 0xfc, 0x0, 0, 0 }, \ + { T6050_MASK, 2, 0x78, 0x1f, (reverse), 0, 0 }, \ + { T6050_MASK, 2, 0x6c, 0x3, 0x2, 0, 0 } + +/* Power a lane's receiver up, then release its transmitter overrides. */ +#define APPLE_T6050_CIO_LANE(l) \ + { T6050_MASK, 2, 0x10, 0x10 << (l), 0x10 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x10, 0x40 << (l), 0x40 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x10, 0x1 << (l), 0x1 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x10, 0x4 << (l), 0x4 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x400 << (l), 0x400 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x1000 << (l), 0x1000 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x40 << (l), 0x40 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x100 << (l), 0x100 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x4000 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x10000 << (l), 0x10000 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x120, 0x40 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x120, 0x4 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x120, 0x400 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 } + +/* The sleep-control release: the common block's overrides, then both lanes. */ +#define APPLE_T6050_CIO_SLPCTRL \ + { T6050_MASK, 2, 0xc, 0x2a, 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + APPLE_T6050_CIO_LANE(0), \ + APPLE_T6050_CIO_LANE(1) + +/* Start the PHY firmware, wait for UC_TNBL_DONE and + * deassert the ACIOPHY reset. No PIPE BIST and no ATCPHY_CFG +0x8 write. + */ +#define APPLE_T6050_CIO_START \ + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, \ + { T6050_MASK, 38, 0x40, 0x1, 0x1, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, \ + { T6050_FIRMWARE, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0xa, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1388, 0, 0 }, \ + { T6050_POLL, 2, 0x260, 0x400, 0x400, 1000000, 0 }, \ + { T6050_MASK, 39, 0x0, 0x10, 0x10, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x64, 0, 0 } + +static const struct apple_t6050_usb_step apple_t6050_cio_init_normal[] = { + APPLE_T6050_CIO_POWERUP, + APPLE_T6050_CIO_TUNABLES, + APPLE_T6050_CIO_XBAR(0x0), + APPLE_T6050_CIO_SLPCTRL, + APPLE_T6050_CIO_START, +}; + +static const struct apple_t6050_usb_step apple_t6050_cio_init_reverse[] = { + APPLE_T6050_CIO_POWERUP, + APPLE_T6050_CIO_TUNABLES, + APPLE_T6050_CIO_XBAR(0x1), + APPLE_T6050_CIO_SLPCTRL, + APPLE_T6050_CIO_START, +}; + +/* Power a lane's transmitter down. */ +#define APPLE_T6050_CIO_TX_DOWN(l) \ + { T6050_MASK, 2, 0x120, 0x100 << (l), 0x100 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x120, 0x1 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x120, 0x10 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 } + +/* Power a lane's receiver down; CIO powers the receivers down, USB does not. */ +#define APPLE_T6050_CIO_RX_DOWN(l) \ + { T6050_MASK, 2, 0xc, 0x4000 << (l), 0x4000 << (l), 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x40 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0xc, 0x400 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x10, 0x1 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, \ + { T6050_MASK, 2, 0x10, 0x10 << (l), 0x0, 0, 0 }, \ + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 } + +/* The shutdown: both lanes down without the PIPE BIST, the firmware + * power-down, then the USB recipes' sleep, clamp and reset sequence. + */ +static const struct apple_t6050_usb_step apple_t6050_cio_shutdown[] = { + APPLE_T6050_CIO_TX_DOWN(0), + APPLE_T6050_CIO_TX_DOWN(1), + { T6050_MASK, 5, 0x0, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x10, 0x10, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 2, 0xc, 0x4, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + APPLE_T6050_CIO_RX_DOWN(0), + APPLE_T6050_CIO_RX_DOWN(1), + { T6050_DELAY, 0, 0x0, 0x0, 0xc8, 0, 0 }, + { T6050_FIRMWARE, 0, 0x0, 0x0, 0x0, 0, 0 }, + { T6050_POWER, 0, 0x0, 0x0, 0x0, 0, 0 }, + { T6050_MASK, 39, 0x2c, 0x1, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x100, 0x100, 1000, 0 }, + { T6050_MASK, 39, 0x0, 0x10, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x8, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x4, 0x4, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x2, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x2, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x0, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_POLL, 39, 0x4, 0x1, 0x0, 1000, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, + { T6050_MASK, 39, 0x8, 0x1, 0x0, 0, 0 }, + { T6050_DELAY, 0, 0x0, 0x0, 0x1, 0, 0 }, +}; +#endif From 024beea2bff7b3aed7af357dcf713465f1c93235 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 18:08:06 -0500 Subject: [PATCH 212/342] dt-bindings: thunderbolt: apple: Add the T6050 router and NHI The T6050 host router has the T8132 MxWrap CPU wrapper and LSTX pin, four ACIO power domains instead of three, and a PCIe router AP firmware block with its own tunables. Its NHI has a single register range, one DART stream per ring, and an SRAM parity interrupt after its 24 ring interrupts. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../thunderbolt/apple,t8103-usb4-acio.yaml | 48 +++++++++++++++++-- .../thunderbolt/apple,t8103-usb4-nhi.yaml | 20 +++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index d9dd4cd1aa756..fe61df65c5c27 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -52,7 +52,8 @@ properties: PCIe adapter configuration space of the USB4 router. Present where the root complex exposes the adapter separately, so that the tunnel can be configured before a PCIe-C link is brought up. - - description: MxWrap co-processor control registers + - description: MxWrap co-processor control registers, on T8132 and T6050 + - description: PCIe router AP firmware registers, on T6050 reg-names: oneOf: @@ -62,6 +63,7 @@ properties: - const: sram - const: pcie-adapter - const: cpu + - const: router-ap-fw - description: T6050, which has no separate PCIe adapter window items: - const: rc @@ -87,12 +89,12 @@ properties: power-domains: minItems: 3 - maxItems: 4 + maxItems: 5 description: | - The first three domains power the ACIO co-processor complex. When - apple,pcie-tunnel is present, the fourth domain powers its PCIe-C + The first three domains (four on T6050, the fourth being the routers' + shared audio (AUSS) domain) power the ACIO co-processor complex. When + apple,pcie-tunnel is present, the domain after them powers its PCIe-C controller and is enabled only after the USB4 PCIe tunnel is active. - On T6050 the fourth domain is the routers' shared audio (AUSS) domain. thunderbolt-switch: type: boolean @@ -135,6 +137,18 @@ properties: named by the pcie-adapter reg entry. Only meaningful where that entry is present. + apple,tunable-router-ap-fw: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: Register offset + - description: Mask of bits to clear + - description: Bits to set + description: | + As apple,tunable-rc, but applied to the PCIe router AP firmware + registers named by the router-ap-fw reg entry, with the other router + tunables once the co-processor firmware is ready. + '#address-cells': const: 1 @@ -216,6 +230,16 @@ allOf: minItems: 4 reg-names: minItems: 4 + - if: + properties: + compatible: + contains: + enum: + - apple,t6040-usb4-acio + - apple,t6050-usb4-acio + - apple,t8132-usb4-acio + then: + properties: pinctrl-names: items: - const: lstx @@ -237,6 +261,20 @@ allOf: required: - iommu@a80000 - nhi@f00000 + - if: + properties: + compatible: + contains: + const: apple,t6050-usb4-acio + then: + properties: + power-domains: + minItems: 4 + else: + properties: + power-domains: + maxItems: 4 + apple,tunable-router-ap-fw: false additionalProperties: false diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml index ede4cea33eb2d..28718fed167c5 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml @@ -52,10 +52,12 @@ properties: interrupts: description: One interrupt for each of the 12 transmit rings followed by one for each - of the 12 receive rings. - maxItems: 24 + of the 12 receive rings. On T6050 an SRAM parity interrupt follows them. + minItems: 24 + maxItems: 25 interrupt-names: + minItems: 24 items: - const: txring0 - const: txring1 @@ -81,6 +83,7 @@ properties: - const: rxring9 - const: rxring10 - const: rxring11 + - const: parity iommus: minItems: 1 @@ -177,4 +180,17 @@ allOf: iommus: maxItems: 1 + - if: + properties: + compatible: + not: + contains: + const: apple,t6050-usb4-nhi + then: + properties: + interrupts: + maxItems: 24 + interrupt-names: + maxItems: 24 + additionalProperties: false From ea31a9a60c40b660641dc5368d5b3fca8968c6f4 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:31:48 -0500 Subject: [PATCH 213/342] thunderbolt: apple: support the T6050 host routers The M5 Max (T6050) host routers are Type 7 routers with an MxWrap CPU wrapper, close to the M3 ones. They differ at start: - The wrapper is only clocked once the CIO reset (the reconfig request) has run; any access before it faults. The reset is required, as on the other generations, and runs before the wrapper is touched. - The CPU is released with a plain store of the RUN value rather than a read-modify-write, and halted again when the router stops. - Both the rc block and the wrapper take an external abort when read before the CPU runs, so the M3_CTRL start of the other generations is skipped and their state is not logged. The rc block is first touched to hand LSTX over, once RTKit is up. - The router takes the LSTX pin over only once its RTKit is up: write the LSTX control from the level the AP held, then mux the pin to the router. While the router is off, hold the pin as a GPIO at the level the router last drove. - The PCIe router AP firmware tunable is applied with the other router tunables once the firmware is ready. - The router firmware trains Gen4 links only when the cable word says the cable is Gen4. For a USB4 Gen4 cable from Enter_USB it expects 0x801 (present and Gen4), without the 20 Gb/s bit. - The NHI has a named SRAM parity interrupt after its 24 ring interrupts, which is not a ring. Match apple,t6050-usb4-acio and apple,t6050-usb4-nhi. DisplayPort tunnels stay off on T6050 for now. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/thunderbolt/apple.c | 158 +++++++++++++++++++++++++++++++++--- 1 file changed, 145 insertions(+), 13 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 3374e0d3e794f..0b0c25d5adb69 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -141,6 +141,17 @@ struct apple_cio_hw { bool strict_fw_ready; /* Keep the links of the host router out of CL states. */ bool no_host_clx; + /* Type 7 router: Enter_USB cable words, bootloader RC tuning, Type 7 NHI. */ + bool type7; + /* + * Release the CPU with a plain store of the RUN value rather than a + * read-modify-write, and halt it again when the router stops. + */ + bool run_store; + /* Hold LSTX low as a GPIO from probe until the router first takes it. */ + bool lstx_hold_from_probe; + /* The router trains Gen4 only on a cable word that says Gen4. */ + bool gen4_cable; const struct apple_dpin_policy *dp; }; @@ -178,11 +189,30 @@ static const struct apple_cio_hw apple_cio_t8132_hw = { /* Type 7 uses its existing ready-state check and has no qualified DP route. */ static const struct apple_cio_hw apple_cio_t8142_hw = { + .type7 = true, + .dp = &apple_dpin_disabled, +}; + +/* + * T6050 is Type 7 with an MxWrap CPU wrapper that is only clocked once the + * CIO reset (the reconfig request) has run. Its CPU is released with a plain + * store of RUN; as on T8132 it takes LSTX over only once its RTKit is up, and + * the AP holds the pin while the router is off. DP tunnels stay off for now. + */ +static const struct apple_cio_hw apple_cio_t6050_hw = { + .mxwrap = true, + .type7 = true, + .run_store = true, + .lstx_after_boot = true, + .lstx_hold_from_probe = true, + .strict_fw_ready = true, + .gen4_cable = true, .dp = &apple_dpin_disabled, }; static const struct apple_cio_hw apple_cio_t6040_hw = { .mxwrap = true, + .type7 = true, .lstx_explicit = true, .skip_run = true, .lstx_after_boot = true, @@ -256,6 +286,10 @@ MODULE_PARM_DESC(s2idle_teardown, #define TB_VSE_CAP_APPLE_CABLE_INFO_20_GBPS BIT(4) #define TB_VSE_CAP_APPLE_CABLE_INFO_LEGACY_ADAPTER BIT(9) #define TB_VSE_CAP_APPLE_CABLE_INFO_TBT2_3 BIT(10) +#define TB_VSE_CAP_APPLE_CABLE_INFO_GEN4 BIT(11) + +/* Enter_USB cable speed: USB PD 3.2 adds USB4 Gen4 after Gen3. */ +#define APPLE_EUDO_CABLE_SPEED_USB4_GEN4 4 static unsigned int dpin_mode_value = 8; module_param(dpin_mode_value, uint, 0644); @@ -306,6 +340,10 @@ struct apple_cio { struct apple_tunable *rc_tunable; void __iomem *pcie_adapter_base; struct apple_tunable *pcie_adapter_tunable; + void __iomem *router_ap_fw_base; + struct apple_tunable *router_ap_fw_tunable; + /* A run_store router CPU that apple_cio_start() released */ + bool cpu_running; struct resource *sram_res; void __iomem *sram_base; @@ -1108,6 +1146,10 @@ static int apple_nhi_probe_irqs(struct apple_nhi *anhi) n_irqs = platform_irq_count(anhi->pdev); if (n_irqs < 0) return dev_err_probe(anhi->dev, n_irqs, "platform_irq_count failed\n"); + /* T6050 adds a named SRAM parity interrupt after the ring interrupts. */ + if (n_irqs > 0 && + platform_get_irq_byname_optional(anhi->pdev, "parity") > 0) + n_irqs--; if (n_irqs == 0) { dev_err(anhi->dev, "No interrupts found\n"); return -EINVAL; @@ -2084,9 +2126,13 @@ static int apple_nhi_probe(struct platform_device *pdev) int cap_apple; int ret = 0; + /* The T6050 router is the Type 7 one released by a RUN store. */ if (acio->type7 != (of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || - of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi"))) { + of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi") || + of_device_is_compatible(pdev->dev.of_node, "apple,t6050-usb4-nhi")) || + acio->hw->run_store != + !!of_device_is_compatible(pdev->dev.of_node, "apple,t6050-usb4-nhi")) { ret = dev_err_probe(&pdev->dev, -EINVAL, "ACIO/NHI generation mismatch\n"); goto err; } @@ -2515,6 +2561,9 @@ static const struct of_device_id apple_nhi_match[] = { { .compatible = "apple,t6040-usb4-nhi", }, + { + .compatible = "apple,t6050-usb4-nhi", + }, { .compatible = "apple,t8142-usb4-nhi", }, @@ -2648,6 +2697,22 @@ static int apple_cio_lstx_release(struct apple_cio *acio) return pinctrl_select_state(acio->pinctrl, acio->lstx_pins); } +/* + * Halt a run_store router CPU that apple_cio_start() released. Its wrapper is + * only clocked after the CIO reset, so never touch it otherwise. + */ +static void apple_cio_cpu_halt(struct apple_cio *acio) +{ + u32 val; + + if (!acio->hw->run_store || !acio->cpu_running) + return; + acio->cpu_running = false; + val = readl(acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); + writel(val & ~APPLE_MXWRAP_CPU_CTRL_RUN, + acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); +} + /** * apple_cio_stop - Stop and power down the ACIO complex * @acio: ACIO complex to stop @@ -2672,6 +2737,7 @@ static void apple_cio_stop(struct apple_cio *acio) "Failed to shutdown M3 RTKit, continuing ACIO shutdown anyway\n"); apple_rtkit_free(acio->rtk); acio->rtk = NULL; + apple_cio_cpu_halt(acio); /* High only if the router left it driven high with the cable still in */ if (acio->hw->lstx_after_boot) @@ -2691,9 +2757,15 @@ static void apple_cio_stop(struct apple_cio *acio) acio->resume_link_failed = false; } -/* Only called while the ACIO power domains are on. */ +/* + * Only called while the ACIO power domains are on. Neither a T6050 router's rc + * block nor its CPU wrapper is known to be readable while it starts (see + * apple_cio_start()), so log nothing for it. + */ static void apple_cio_log_state(struct apple_cio *acio, const char *when) { + if (acio->hw->run_store) + return; if (acio->cpu_base) dev_info(acio->dev, "%s: LSTX 0x%08x, FW state 0x%08x, CPU ctrl 0x%08x, status 0x%08x\n", when, readl(acio->rc_base + APPLE_CIO_M3_CTRL), @@ -2809,7 +2881,11 @@ static int apple_cio_start(struct apple_cio *acio) * them with a bare store. */ if (acio->hw->lstx_after_boot) { - /* Written below, once RTKit is up. */ + /* + * Written below, once RTKit is up. A T6050 CPU is started through + * its wrapper below, and its rc block takes an external abort until + * the CPU runs, so M3_CTRL is left alone here. + */ } else if (acio->hw->lstx_explicit) { writel(APPLE_CIO_LSTX_CTRL_ENABLE | APPLE_CIO_LSTX_CTRL_LEVEL, acio->rc_base + APPLE_CIO_M3_CTRL); @@ -2820,9 +2896,21 @@ static int apple_cio_start(struct apple_cio *acio) if (acio->hw->mxwrap && !acio->hw->skip_run) { apple_cio_log_state(acio, "before RUN"); - val = readl(acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); - writel(val | APPLE_MXWRAP_CPU_CTRL_RUN, - acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); + if (acio->hw->run_store) { + /* + * The CIO reset above clocks the wrapper; the CPU runs the + * image the boot loader left in its SRAM once RUN is set. + * The run value is stored outright, not merged. + */ + writel(APPLE_MXWRAP_CPU_CTRL_RUN, + acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); + acio->cpu_running = true; + apple_cio_log_state(acio, "after RUN"); + } else { + val = readl(acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); + writel(val | APPLE_MXWRAP_CPU_CTRL_RUN, + acio->cpu_base + APPLE_MXWRAP_CPU_CTRL); + } } acio->rtk = apple_rtkit_init(acio->dev, acio, NULL, 0, &apple_cio_rtkit_ops); @@ -2881,6 +2969,8 @@ static int apple_cio_start(struct apple_cio *acio) apple_tunable_apply(acio->pcie_adapter_base, acio->pcie_adapter_tunable); } + /* The router AP firmware tunable goes with the others once the firmware is ready. */ + apple_tunable_apply(acio->router_ap_fw_base, acio->router_ap_fw_tunable); /* * Bring up devices which are part of ACIO and are now accessible by the main SoC @@ -2918,6 +3008,7 @@ static int apple_cio_start(struct apple_cio *acio) apple_rtkit_free(acio->rtk); remove_links: acio->rtk = NULL; + apple_cio_cpu_halt(acio); /* Cut power to reset the entire block */ for (i = 0; i < acio->pd_list->num_pds; i++) { if (acio->pd_list->pd_links[i]) @@ -3131,7 +3222,16 @@ static int apple_cio_tbt_switch_set(struct typec_thunderbolt_switch_dev *sw, acio->target_cable_info = TB_VSE_CAP_APPLE_CABLE_INFO_PRESENT; if (FIELD_GET(EUDO_CABLE_TYPE_MASK, data->usb4.eudo) != EUDO_CABLE_TYPE_PASSIVE) acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_ACTIVE_CABLE; - if (FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >= EUDO_CABLE_SPEED_USB4_GEN3) + /* + * The T6050 router firmware trains Gen4 only on a Gen4 cable, and + * takes Gen4 alone: no 20 Gb/s bit beside it. + */ + if (acio->hw->gen4_cable && + FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >= + APPLE_EUDO_CABLE_SPEED_USB4_GEN4) + acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_GEN4; + else if (FIELD_GET(EUDO_CABLE_SPEED_MASK, data->usb4.eudo) >= + EUDO_CABLE_SPEED_USB4_GEN3) acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_20_GBPS; if (data->orientation == TYPEC_ORIENTATION_REVERSE) acio->target_cable_info |= TB_VSE_CAP_APPLE_CABLE_INFO_ORIENTATION_REVERSE; @@ -3335,16 +3435,15 @@ static int apple_cio_probe(struct platform_device *pdev) init_completion(&acio->nhi_boot_completion); acio->dev = &pdev->dev; acio->np = dev->of_node; - acio->type7 = of_device_is_compatible(acio->np, "apple,t8142-usb4-acio") || - of_device_is_compatible(acio->np, "apple,t6040-usb4-acio"); - if (acio->type7 && - of_property_count_u32_elems(acio->np, "apple,tunable-rc") <= 0) - return dev_err_probe(dev, -EINVAL, "Missing bootloader RC tuning\n"); - acio->hw = of_device_get_match_data(dev); if (!acio->hw) return -EINVAL; + acio->type7 = acio->hw->type7; + if (acio->type7 && + of_property_count_u32_elems(acio->np, "apple,tunable-rc") <= 0) + return dev_err_probe(dev, -EINVAL, "Missing bootloader RC tuning\n"); + if (acio->hw->mxwrap) { struct resource *cpu_res; @@ -3367,6 +3466,9 @@ static int apple_cio_probe(struct platform_device *pdev) acio->lstx_pins = NULL; acio->lstx_hold = acio->lstx_pins && of_property_present(dev->of_node, "lstx-gpios"); + /* Hold the line low until the router first takes it. */ + if (acio->hw->lstx_hold_from_probe) + apple_cio_lstx_hold(acio, false); } acio->pcie_tunnel_np = of_parse_phandle(dev->of_node, "apple,pcie-tunnel", 0); @@ -3435,6 +3537,32 @@ static int apple_cio_probe(struct platform_device *pdev) } } + { + struct resource *ap_fw; + + ap_fw = platform_get_resource_byname(pdev, IORESOURCE_MEM, "router-ap-fw"); + if (ap_fw) { + acio->router_ap_fw_base = devm_ioremap_resource(dev, ap_fw); + if (IS_ERR(acio->router_ap_fw_base)) + return dev_err_probe(dev, PTR_ERR(acio->router_ap_fw_base), + "Unable to map router AP firmware regs\n"); + acio->router_ap_fw_tunable = + devm_apple_tunable_parse(dev, acio->np, + "apple,tunable-router-ap-fw", ap_fw); + if (IS_ERR(acio->router_ap_fw_tunable)) { + if (PTR_ERR(acio->router_ap_fw_tunable) != -ENOENT) + return dev_err_probe(dev, + PTR_ERR(acio->router_ap_fw_tunable), + "Unable to load router AP firmware tunable\n"); + acio->router_ap_fw_tunable = NULL; + } + } + } + + /* + * On T6050 this is the CIO reconfig request, which also clocks the + * router CPU's wrapper: nothing may touch the wrapper before it. + */ acio->reset = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(acio->reset)) return dev_err_probe(dev, PTR_ERR(acio->reset), "Unable to get CIO reset\n"); @@ -3548,6 +3676,10 @@ static const struct of_device_id apple_acio_match[] = { .compatible = "apple,t6040-usb4-acio", .data = &apple_cio_t6040_hw, }, + { + .compatible = "apple,t6050-usb4-acio", + .data = &apple_cio_t6050_hw, + }, { .compatible = "apple,t8142-usb4-acio", .data = &apple_cio_t8142_hw, From ab6654bbbc8e6204c7d3a78eebce8fbd9a4267da Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 18:08:06 -0500 Subject: [PATCH 214/342] dt-bindings: iommu: apple,dart: Describe the setup of a DART nothing initialises A T8110 DART that no boot loader sets up, such as a USB4 router's or its PCIe-C tunnel's, needs the device tree to describe what the boot loader otherwise does: its tunables, its bypass streams, every error reported and the context cache flushed. Add apple,full-error-reporting and apple,ctc-flush, and extend apple,bypass-sids beyond the PCIe-C tunnel DARTs. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../devicetree/bindings/iommu/apple,dart.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 9ba41ab9806d2..0c91127ba8505 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -151,9 +151,25 @@ properties: items: maximum: 255 description: - Reserved streams of a USB4 PCIe tunnel DART that its PCIe-C port issues + Streams set to bypass after every reset of the DART, outside any domain. + On a USB4 PCIe tunnel DART, the reserved streams its PCIe-C port issues its own writes on, such as the interrupt controller writes its MSIs - turn into. They are set to bypass after every reset of the DART. + turn into. On a T8110 DART that nothing initialises before Linux, such + as a USB4 router's, the streams its co-processor uses without + translation. + + apple,full-error-reporting: + type: boolean + description: + Unmask every error and enable the error interrupt for every stream, + with the registers of the DART's revision, and leave the DART unlocked + on error. For a T8110 DART that nothing initialises before Linux. + + apple,ctc-flush: + type: boolean + description: + Flush the DART's context cache after a stream flush, where the DART + has one. For a T8110 DART that nothing initialises before Linux. apple,remap-streams: $ref: /schemas/types.yaml#/definitions/uint32-matrix From 331043fa765040e3e2b370894660e191ff3d45e4 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:34:56 -0500 Subject: [PATCH 215/342] iommu: apple-dart: set up a T8110 DART that nothing initialised A T8110 DART that the boot loader leaves alone, such as the M5 Max USB4 router's, comes up with its tunables unapplied, its errors masked and no stream in bypass. Its own driver otherwise only clears the streams, enables them and flushes the TLBs. Let the device tree describe the rest, for non-tunneled T8110 DARTs: - apple,tunable: the DART's own tunables, applied at every reset before the first stream is configured. Client partition registers (0x800..0xfff) are skipped unless PARAMS1 bit 29 says they exist. - apple,bypass-sids: streams set to bypass translation at every reset, outside any domain. - apple,full-error-reporting: unmask every error and enable the error interrupt for every stream with the registers of the DART's revision (the error mask moved to 0x4060 in 2.2; status, enable and the per-stream enables moved from 0x700 to 0x4200 in 2.4), and leave the DART unlocked on error. On 2.4 the interrupt handler also reports and acknowledges the error status. - apple,ctc-flush: where PARAMS2 bit 4 says there is a context cache, flush it (0x600) after a V2 stream flush, which leaves it alone. Log the identification registers of a DART set up this way at probe. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/iommu/apple-dart.c | 165 +++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index d5b60c897a4c2..eb79cad148163 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -190,6 +190,26 @@ #define DART_T8110_ENABLE_STREAMS 0xc00 #define DART_T8110_DISABLE_STREAMS 0xc20 +/* + * Revision 2.2 and later moved the error mask; 2.4 also moved the error + * status, the error interrupt enable and the per-stream error enables. + */ +#define DART_T8110_V2_ERROR_MASK 0x4060 +#define DART_T8110_ERR_IRQ_STATUS 0x704 +#define DART_T8110_ERR_IRQ_ENABLE 0x700 +#define DART_T8110_ERR_SID_ENABLE(i) (0x720 + 4 * (i)) +#define DART_T8110_V24_ERR_IRQ_STATUS 0x4204 +#define DART_T8110_V24_ERR_IRQ_ENABLE 0x4200 +#define DART_T8110_V24_ERR_SID_ENABLE(i) (0x4220 + 4 * (i)) + +/* PARAMS1 bit 29: client partitions (the 0x800.. registers) exist. */ +#define DART_T8110_PARAMS1_CLIENT_PARTITIONS BIT(29) +#define DART_T8110_CLIENT_PARTITION_BASE 0x800 +#define DART_T8110_CLIENT_PARTITION_END 0x1000 +/* PARAMS2 bit 4: a translation context cache that a full flush leaves alone. */ +#define DART_T8110_PARAMS2_CTC BIT(4) +#define DART_T8110_CTC_FLUSH 0x600 + #define DART_T8110_TCR 0x1000 #define DART_T8110_TCR_REMAP GENMASK(11, 8) #define DART_T8110_TCR_REMAP_ENABLE BIT(7) @@ -311,6 +331,16 @@ struct apple_dart { struct apple_tunable *tunables; u16 version; + /* + * Set up from the device tree for a DART nothing else initialised: + * tunables applied at every reset, streams kept in static bypass, every + * error reported, and the context cache flushed after a full TLB flush. + */ + DECLARE_BITMAP(static_bypass, DART_MAX_STREAMS); + bool full_errors; + bool ctc_flush; + bool client_partitions; + /* J713 internal display DARTs, borrowed from the running DCP. */ struct apple_dart_dcp *dcp; struct apple_dart_dcp *frontend[2]; @@ -1377,6 +1407,10 @@ apple_dart_t8110_hw_tlb_command_range(struct apple_dart_stream_map *stream_map, if (ret) break; } + /* A V2 flush leaves the context cache alone: flush all of it after. */ + if (!ret && dart->ctc_flush && dart->version >= 0x0202 && + command == DART_T8110_TLB_CMD_OP_FLUSH_SID) + apple_dart_writel(dart, 0, DART_T8110_CTC_FLUSH); spin_unlock_irqrestore(&dart->lock, flags); if (ret) dev_err_ratelimited(dart->dev, @@ -1750,6 +1784,59 @@ apple_dart_t8110_hw_enable_remap(struct apple_dart *dart, int sid, int remap_to) * acknowledge the errors latched so far, unlock a DART that locks on errors, * unmask the error interrupt and flush the TLBs. */ +/* + * Unmask every error and enable its interrupt for each stream, with the + * registers of this revision: the T8110 reset value leaves them masked on + * 2.2 and later, where the error mask is no longer at ERROR_MASK. + */ +static void apple_dart_t8110_enable_errors(struct apple_dart *dart) +{ + bool v24 = dart->version >= 0x0204; + unsigned int i; + + apple_dart_writel(dart, 0, dart->version >= 0x0202 ? + DART_T8110_V2_ERROR_MASK : DART_T8110_ERROR_MASK); + apple_dart_readl(dart, dart->version >= 0x0202 ? + DART_T8110_V2_ERROR_MASK : DART_T8110_ERROR_MASK); + apple_dart_writel(dart, U32_MAX, v24 ? DART_T8110_V24_ERR_IRQ_STATUS : + DART_T8110_ERR_IRQ_STATUS); + apple_dart_writel(dart, U32_MAX, v24 ? DART_T8110_V24_ERR_IRQ_ENABLE : + DART_T8110_ERR_IRQ_ENABLE); + for (i = 0; i < DIV_ROUND_UP(dart->num_streams, 32); i++) { + u32 sids = dart->num_streams >= 32 * (i + 1) ? U32_MAX : + GENMASK(dart->num_streams - 32 * i - 1, 0); + + apple_dart_writel(dart, sids, v24 ? DART_T8110_V24_ERR_SID_ENABLE(i) : + DART_T8110_ERR_SID_ENABLE(i)); + } + /* No lock on error: the driver acknowledges and carries on. */ + apple_dart_writel(dart, 0, DART_T8110_DIAG_LOCK); +} + +/* + * Apply the DART's own tunables. Client partition registers exist only where + * PARAMS1 says so; a write to one that does not exist is skipped. + */ +static void apple_dart_apply_own_tunables(struct apple_dart *dart) +{ + size_t i; + + for (i = 0; i < dart->tunables->sz; ++i) { + u32 offset = dart->tunables->values[i].offset; + u32 old_value, value; + + if (offset >= DART_T8110_CLIENT_PARTITION_BASE && + offset < DART_T8110_CLIENT_PARTITION_END && + !dart->client_partitions) + continue; + old_value = apple_dart_readl(dart, offset); + value = old_value & ~dart->tunables->values[i].mask; + value |= dart->tunables->values[i].value; + if (value != old_value) + apple_dart_writel(dart, value, offset); + } +} + static int apple_dart_hw_finish_reset(struct apple_dart *dart) { struct apple_dart_stream_map stream_map = { .dart = dart }; @@ -1795,6 +1882,9 @@ static int apple_dart_hw_finish_reset(struct apple_dart *dart) if (ret) dev_err(dart->dev, "failed to flush the TLBs after reset: %d\n", ret); + if (dart->full_errors) + apple_dart_t8110_enable_errors(dart); + return ret; } @@ -2012,10 +2102,18 @@ static int apple_dart_hw_reset(struct apple_dart *dart) bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS); bitmap_set(stream_map.sidmap, 0, dart->num_streams); + /* Before the first stream is configured. */ + if (!dart->tunneled && dart->tunables) + apple_dart_apply_own_tunables(dart); + apple_dart_hw_disable_dma(&stream_map); apple_dart_hw_clear_all_ttbrs(&stream_map); apple_dart_hw_apply_remaps(dart); + /* Streams that bypass translation for good, outside any domain. */ + for_each_set_bit(i, dart->static_bypass, dart->num_streams) + apple_dart_writel(dart, DART_T8110_TCR_BYPASS_DART, DART_TCR(dart, i)); + /* enable all streams globally since TCR is used to control isolation */ for (i = 0; i < BITS_TO_U32(dart->num_streams); i++) apple_dart_writel(dart, U32_MAX, @@ -3855,6 +3953,17 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) readl(dart->regs + DART_T8110_EXCEPTION(0)); } + /* With every error enabled, 2.4 latches the rest in its own status. */ + if (dart->full_errors && dart->version >= 0x0204) { + u32 status = readl(dart->regs + DART_T8110_V24_ERR_IRQ_STATUS); + + if (status) { + dev_err_ratelimited(dart->dev, "error status: 0x%08x\n", status); + writel(status, dart->regs + DART_T8110_V24_ERR_IRQ_STATUS); + ret = IRQ_HANDLED; + } + } + if (dart->version >= 0x0203) { block_error = readl(dart->regs + DART_T8110_BLOCK_ERROR); if (apple_dart_t8110_v2_block_pending(dart->version, block_error)) { @@ -4127,6 +4236,56 @@ static bool apple_dart_has_live_rtkit_client(struct device_node *np) return false; } +/* + * The setup a T8110 DART needs when nothing initialised it before Linux: + * apple,tunable (applied at every reset), apple,bypass-sids (streams kept in + * static bypass), apple,full-error-reporting and apple,ctc-flush. Log the + * identification registers of such a DART. + */ +static int apple_dart_parse_own_setup(struct apple_dart *dart, struct resource *res, + const u32 *params) +{ + struct device *dev = dart->dev; + struct device_node *np = dev->of_node; + int count, i; + u32 sid; + + dart->full_errors = of_property_read_bool(np, "apple,full-error-reporting"); + dart->ctc_flush = of_property_read_bool(np, "apple,ctc-flush") && + (params[1] & DART_T8110_PARAMS2_CTC); + dart->client_partitions = params[0] & DART_T8110_PARAMS1_CLIENT_PARTITIONS; + + if (of_property_present(np, "apple,tunable")) { + dart->tunables = devm_apple_tunable_parse(dev, np, "apple,tunable", res); + if (IS_ERR(dart->tunables)) + return dev_err_probe(dev, PTR_ERR(dart->tunables), + "failed to parse DART tunables\n"); + } + + count = of_property_count_u32_elems(np, "apple,bypass-sids"); + for (i = 0; i < count; i++) { + if (of_property_read_u32_index(np, "apple,bypass-sids", i, &sid) || + sid >= dart->num_streams) + return dev_err_probe(dev, -EINVAL, "invalid bypass stream\n"); + __set_bit(sid, dart->static_bypass); + } + + if (dart->tunables || count > 0 || dart->full_errors || + of_property_read_bool(np, "apple,ctc-flush")) + dev_info(dev, + "params %08x %08x %08x %08x, version %04x, %u streams, AS %u -> %u, protect %08x/%08x, diag lock %08x; %zu tunables%s, %d bypass streams, CTC flush %s\n", + params[0], params[1], params[2], params[3], dart->version, + dart->num_streams, dart->ias, dart->oas, + apple_dart_readl(dart, DART_T8110_PROTECT), + apple_dart_readl(dart, DART_T8110_PROTECT_LOCK), + apple_dart_readl(dart, DART_T8110_DIAG_LOCK), + dart->tunables ? dart->tunables->sz : 0, + dart->tunables && !dart->client_partitions ? + " (no client partitions)" : "", + max(count, 0), dart->ctc_flush ? "on" : "off"); + return 0; +} + static int apple_dart_probe(struct platform_device *pdev) { int ret, sid; @@ -4433,6 +4592,12 @@ static int apple_dart_probe(struct platform_device *pdev) } params_done: + if (!tunneled && dart->hw->type == DART_T8110) { + ret = apple_dart_parse_own_setup(dart, res, dart_params); + if (ret) + goto err_clk_disable; + } + dart->dma_min = 0; dart->dma_max = DMA_BIT_MASK(dart->ias); dart->dma_offset = 0; From 1102e101fc521998854f047da156d9089ae909ec Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Tue, 3 Nov 2026 22:35:02 -0500 Subject: [PATCH 216/342] arm64: dts: apple: j716c: Add the right port's USB4/Thunderbolt router Describe the USB4/Thunderbolt host router behind the right-hand USB-C port (ADT /arm-io/acio2, acio-cpu2 and dart-acio2). In t6050-max.dtsi: - the ATC2_CIO, ATC2_CIO_PCIE, ATC2_CIO_USB and ATC2_CIO_AUSS power domains; - the router CPU's mailbox and the router's LSTX pin function on the AOP GPIO controller; - the router itself, with its DART and NHI as children, so that both are populated only once the router runs: nothing is touched at boot; - the DART's stream 15 in bypass, full error reporting and the context cache flush. In the board: AUSS, kept as the boot loader leaves it, the CIO reconfig request (port 2 of the die's CIO reset), the AOP GPIO controller with only the LSTX pin exposed, the PHY's CIO80 RX_TOP tunables, the link from the PD controller to the router, and, until the boot loader fills them, this board's router, NHI and DART tunables and host DROM, from its ADT. The router node is named acio@: the boot loader disables a cio@ node unless its first register is the third register of the matching /arm-io/acioN, which on T6050 is not the router's rc block. Developed with Claude Code. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 221 ++++++++++++++++++++++ arch/arm64/boot/dts/apple/t6050-max.dtsi | 178 +++++++++++++++++ 2 files changed, 399 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 550aef6f8768f..abdf7ca85b592 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -342,3 +342,224 @@ }; }; }; + +/* + * ==== The right USB-C port's USB4/Thunderbolt router (ATC2) ==== + * + * Until the boot loader fills them, the router, NHI, PHY CIO and DART tunables and the host + * DROM are this board's, from its ADT (the DROM's router UUID from an earlier boot). + */ +/* ATC2_CIO_AUSS's other parent; kept as the boot loader leaves it */ +&ps_auss { + status = "okay"; +}; + +/* The CIO reconfig request, port 2 (clock gate CIO2_RECONFIG_V) */ +&cio_reconfig0 { + status = "okay"; +}; + +/* The PHY's CIO80 RX_TOP tunables (ADT tunable_LN0/LN1_RX_TOP_CIO_DFLT); the other three are empty */ +&atc2_phy { + apple,tunable-lane0-rx-top-cio = <0x35c 0xe00 0x0>; + apple,tunable-lane1-rx-top-cio = <0x35c 0xe00 0x0>; +}; + +/* Only the router's LSTX pin (81) of the AOP GPIO controller is exposed. */ +&pinctrl_aop { + gpio-reserved-ranges = <0 81>, <82 3>; + status = "okay"; +}; + +&hpm2 { + connector { + ports { + port@3 { + reg = <3>; + hpm2_usb4: endpoint { + remote-endpoint = <&acio2_tbt>; + }; + }; + }; + }; +}; + +&acio2 { + apple,tunable-rc = <0x0 0xfff0 0x4020>, + <0x2c 0x4 0x0>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0x70007 0x40004>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = <0x8 0xff2 0x482>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + acio2_tbt: endpoint { + remote-endpoint = <&hpm2_usb4>; + }; + }; + }; +}; + +&acio2_dart { + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>; +}; + +&acio2_nhi { + apple,tunable-nhi = <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x3 0x2>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x3 0x2>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + apple,thunderbolt-drom = [ff 92 e6 6e ee 18 7c ac 05 90 19 c3 8c 00 5c 00 + 00 00 00 00 00 00 08 81 82 02 82 00 00 00 08 82 + 92 01 82 00 00 00 03 83 20 08 84 00 00 00 00 00 + 00 08 85 00 00 00 00 00 00 05 86 09 01 00 08 87 + 00 00 00 00 00 00 05 88 09 01 00 05 89 09 01 00 + 05 8a 09 01 00 0e 01 41 70 70 6c 65 2c 20 49 6e + 63 2e 00 06 02 69 4f 53 00 00 00 00]; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index 55cf22a98e2a2..87bd77e4b4b99 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -129,3 +129,181 @@ }; #endif }; + +#ifdef T6050_J716C +/* + * ATC2's USB4/Thunderbolt router (ADT /arm-io/acio2, acio-cpu2 and dart-acio2), powered per + * connection: the PHY enters CIO mode, then the router's domains come on (ATC2_CIO, _PCIE, _USB, + * _AUSS), the CIO reset (reconfig request) clocks the CPU wrapper, the CPU runs from the image the + * boot loader left in its SRAM, and once its firmware is ready the DART and the NHI are populated. + * Nothing here is touched at boot. The router is named acio@: the boot loader disables a cio@ node + * unless its first register is the third register of the matching /arm-io/acioN, which on T6050 + * is not the router's rc block. The board gives the tunables and the host DROM until the boot + * loader fills them. + */ +&pmgr0 { + ps_atc2_cio: power-controller@2e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e8 4>; + label = "atc2_cio"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc2_common>; + }; + + ps_atc2_cio_pcie: power-controller@3f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f8 4>; + label = "atc2_cio_pcie"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc2_cio>; + }; + + ps_atc2_cio_usb: power-controller@400 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x400 4>; + label = "atc2_cio_usb"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc2_cio>; + }; + + ps_atc2_cio_auss: power-controller@408 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x408 4>; + label = "atc2_cio_auss"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc2_cio>, <&ps_auss>; + }; +}; + +/* LSTX: /arm-io/acio2 gpio-lstx, AOP GPIO pin 81 (0x51), function 1 for the router */ +&pinctrl_aop { + acio2_lstx_pins: acio2-lstx-pins { + pinmux = <0x10051>; /* APPLE_PINMUX(81, 1) */ + }; +}; + +&die0 { + /* /arm-io/acio-cpu2 reg[0]: the router CPU's mailbox, inside its wrapper */ + acio2_mbox: mailbox@381108000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x81108000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* + * /arm-io/acio2: rc (reg[1]), the RTKit data segment in its SRAM, the PCIe adapter, + * acio-cpu2 reg[1] (the CPU wrapper) and the PCIe router AP firmware block. + */ + acio2: acio@381ac0000 { + compatible = "apple,t6050-usb4-acio"; + reg = <0x3 0x81ac0000 0x0 0xc000>, + <0x3 0x81080000 0x0 0x26000>, + <0x3 0x81e44000 0x0 0x4000>, + <0x3 0x81100000 0x0 0x4000>, + <0x3 0x81c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "cpu", "router-ap-fw"; + mboxes = <&acio2_mbox>; + resets = <&cio_reconfig0 2>; + power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, + <&ps_atc2_cio_usb>, <&ps_atc2_cio_auss>; + thunderbolt-switch; + pinctrl-0 = <&acio2_lstx_pins>; + pinctrl-names = "lstx"; + lstx-gpios = <&pinctrl_aop 81 GPIO_ACTIVE_HIGH>; + + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x3 0x81000000 0x1000000>; + nonposted-mmio; + + /* + * /arm-io/dart-acio2, populated with the NHI once the router runs, so that it is + * first read with the router up. Nothing initialises it before Linux: its tunables + * (dart-tunables-instance-0), stream 15 (bypass-15) in bypass, every error + * reported and the context cache flushed. vm-base 0x100_0000_0000. + */ + acio2_dart: iommu@a80000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + reg = <0xa80000 0xc000>; + interrupts = ; + power-domains = <&ps_atc2_cio>; + #iommu-cells = <1>; + apple,dma-range = <0x100 0x4000 0x0 0xffff0000>; + apple,bypass-sids = <15>; + apple,full-error-reporting; + apple,ctc-flush; + }; + + /* Interrupts 0x66b.. are the TX rings and 0x677.. the RX rings */ + acio2_nhi: nhi@f00000 { + compatible = "apple,t6050-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", "rxring9", "rxring10", "rxring11", + "parity"; + iommus = <&acio2_dart 0>, + <&acio2_dart 1>, + <&acio2_dart 2>, + <&acio2_dart 3>, + <&acio2_dart 4>, + <&acio2_dart 5>, + <&acio2_dart 6>, + <&acio2_dart 7>, + <&acio2_dart 8>, + <&acio2_dart 9>, + <&acio2_dart 10>, + <&acio2_dart 11>, + <&acio2_dart 16>, + <&acio2_dart 17>, + <&acio2_dart 18>, + <&acio2_dart 19>, + <&acio2_dart 20>, + <&acio2_dart 21>, + <&acio2_dart 22>, + <&acio2_dart 23>, + <&acio2_dart 24>, + <&acio2_dart 25>, + <&acio2_dart 26>, + <&acio2_dart 27>; + }; + }; +}; +#endif From a0b688d65a3055183ed38a19376d8c060474e9c9 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 08:46:58 -0500 Subject: [PATCH 217/342] phy: apple: t6050: park the PIPE from a dummy producer on any clock At the first controller reset the USB3 PIPE mux is expected unset (0), on the dummy producer (2) or already parked (0x42). When nothing has reset the controller domain since boot, as on a boot without the SPTM, the mux reads 0x22: the dummy producer on another clock. The park then refused it and dwc3 failed to probe. The park clears the clock field before it selects the dummy producer and its clock, so start from any clock while the producer is the dummy one. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h index 812227cac03e9..f5962152444bf 100644 --- a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -23,7 +23,9 @@ apple_t6050_usb3_pipe_cold_dummy(const struct apple_t6050_usb_io *io) if (io->read(io->context, 44, 0x1c) & 1) return -1; mux = io->read(io->context, 44, 0x0c) & 0x73; - if (mux != 0 && mux != 2 && mux != 0x42) + /* Unset, or already on the dummy producer (1:0 = 2) with any clock: when nothing + * has reset the controller domain since boot, the mux can read 0x22. */ + if (mux != 0 && (mux & 3) != 2) return -1; if (mux == 0x42) return 0; From 178e80cc2f0c09f601919110709d604e6f744268 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 10:49:52 -0500 Subject: [PATCH 218/342] thunderbolt: Ignore DROM entries for ports the router does not implement The host DROM of the M5 Max USB4 router lists port 8, which the router reports as not implemented. Reading its port config fails with -ENODEV, which made the whole DROM unusable and left the host router without one, so the NHI failed to probe. Skip such entries, as is already done for entries past the last port. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/thunderbolt/eeprom.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c index 389de7df84f65..f2d56acb21a10 100644 --- a/drivers/thunderbolt/eeprom.c +++ b/drivers/thunderbolt/eeprom.c @@ -381,6 +381,12 @@ static int tb_drom_parse_entry_port(struct tb_switch *sw, return 0; res = tb_port_read(port, &type, TB_CFG_PORT, 2, 1); + /* Listed, but not implemented by this router: skip it as well */ + if (res == -ENODEV) { + tb_sw_dbg(sw, "DROM entry for unimplemented port %u ignored\n", + header->index); + return 0; + } if (res) return res; type &= 0xffffff; From a1d6ef9718682a2a321798783e636c724a0cf913 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 12:17:36 -0500 Subject: [PATCH 219/342] phy: apple: t6050: restart the PHY firmware on its original data The PHY firmware is preloaded by the boot loader, data segment included, and keeps its state in that segment. Restarted after a stop, it ran on what its last run had left there and never finished calibrating the lanes: UC_TNBL_DONE did not come, and every second connection of a port failed, in USB as in CIO mode, until reboot. Save the data SRAM when the firmware is first started and put it back before every later start. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-dp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index e6941cf86c8ad..57d0587cdaf24 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -97,6 +97,7 @@ struct t6050_dp { struct apple_rtkit *rtkit; void __iomem *fw_data; bool fw_running; + void *fw_data_saved; /* the firmware data SRAM as the first start found it */ }; static int atc_domain_set(struct atc_domain *pd, bool active) @@ -183,6 +184,20 @@ static int atc_firmware(struct t6050_dp *dp, bool start) if (dp->fw_running == start) return 0; if (start) { + /* + * The firmware is the boot loader's, preloaded with its data segment, and keeps + * its state there: restarted on the state its last run left, it never finishes + * calibrating the lanes (UC_TNBL_DONE). Give every start the data segment the + * first one found. The PHY's domains are on here, so the SRAM is accessible. + */ + if (!dp->fw_data_saved) { + dp->fw_data_saved = devm_kmalloc(dp->dev, 0x10000, GFP_KERNEL); + if (!dp->fw_data_saved) + return -ENOMEM; + memcpy_fromio(dp->fw_data_saved, dp->fw_data, 0x10000); + } else { + memcpy_toio(dp->fw_data, dp->fw_data_saved, 0x10000); + } /* Native coprocessor run, after its +0x40 firmware enable. */ writel(BIT(4), dp->banks[38] + 0x28); ret = apple_rtkit_wake(dp->rtkit); From 625229d3881c6a2319a524a1029ef5b3c884bcab Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 12:21:55 -0500 Subject: [PATCH 220/342] phy: apple: t6050: carry USB3 over a USB4 router's tunnel In CIO mode the lanes carry USB4/TBT, and USB3 reaches DWC3 through the router's USB3 adapter. DWC3 was left on its dummy PIPE producer, so a USB3 tunnel came up with nothing on the host side. When DWC3 asks for USB3 in CIO mode, move its PIPE mux to the tunnel producer (0x21: PIPE mode 1, clock 2) under the PIPE lock, as the older Apple PHYs do in USB4 mode. A lock that is not acknowledged is not fatal, as for native USB3. On power-off the PIPE goes back to the dummy producer while the CIO PHY is left to the router. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-combo.h | 38 +++++++++++++++-- drivers/phy/apple/atc-t6050-dp.c | 1 + .../apple/usb-t6050/apple_t6050_usb3_pipe.h | 42 ++++++++++++++++++- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index c57779075ec05..185f71cd6e138 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -298,6 +298,34 @@ static int combo_usb2_reset(struct phy *phy) return ret ? -EIO : 0; } +/* A tunnelled PIPE leaves the CIO PHY to the router: nothing to quiesce on the PHY side. */ +static int combo_pipe_keep(void *ctx) +{ + return 0; +} + +/* + * In CIO mode the lanes carry USB4/TBT and USB3 reaches DWC3 through the router's USB3 adapter: + * move DWC3 from its dummy PIPE producer to the tunnel producer, as is done on the older PHYs. + */ +static int combo_pipe_tunnel(struct t6050_dp *dp) +{ + int ret; + + lockdep_assert_held(&dp->lock); + if (dp->pipe_active) + return dp->pipe_tunnel ? 0 : -EBUSY; + ret = apple_t6050_usb3_pipe_tunnel(&dp->usb_io); + if (ret) { + combo_pipe_fault(dp, "USB3 tunnel PIPE switch", ret); + return -EIO; + } + dp->pipe_active = true; + dp->pipe_tunnel = true; + dev_info(dp->dev, "USB3 PIPE on the USB4 tunnel\n"); + return 0; +} + static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) { struct t6050_dp *dp = phy_get_drvdata(phy); @@ -314,10 +342,8 @@ static int combo_usb3_mode(struct phy *phy, enum phy_mode mode, int submode) * uses its independent D+/D- PHY. Do not switch USB3 onto DP lanes. */ if (dp->combo_mode == COMBO_DP4 && dp->enabled) return 0; - /* In CIO the lanes carry USB4/TBT. DWC3 keeps its dummy PIPE until a - * USB3 tunnel hands PIPE to the router; native USB3 mode is 0 too. */ if (dp->combo_mode == COMBO_CIO && dp->cio_prepared) - return 0; + return combo_pipe_tunnel(dp); if (!dp->usb_prepared && !(dp->combo_mode == COMBO_DP2 && dp->enabled)) return -ENOLINK; if (dp->pipe_active) @@ -347,7 +373,10 @@ static int combo_usb3_poweroff(struct phy *phy) /* DWC3 calls power_off only after host/gadget shutdown and SUSPHY. * PIPE must select its dummy producer before the controller is reset. */ if (dp->pipe_active) { - ret = apple_t6050_usb3_pipe_stop(&dp->usb_io, combo_quiesce, dp); + ret = apple_t6050_usb3_pipe_stop(&dp->usb_io, + dp->pipe_tunnel ? combo_pipe_keep : combo_quiesce, dp); + if (!ret) + dp->pipe_tunnel = false; if (!ret) dp->pipe_active = false; } @@ -491,3 +520,4 @@ static int combo_setup(struct platform_device *pdev, struct t6050_dp *dp) } return 0; } + diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 57d0587cdaf24..3eadc358589ff 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -73,6 +73,7 @@ struct atc_domain { enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2, COMBO_CIO }; struct t6050_dp { bool combo, usb_prepared, usb2_active, pipe_active, controller_active, cio_prepared; + bool pipe_tunnel; /* the active PIPE is a USB4 router's USB3 tunnel */ enum combo_mode combo_mode; enum typec_orientation orientation; struct phy *combo_phy[3]; diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h index f5962152444bf..30e462e416580 100644 --- a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -96,6 +96,46 @@ apple_t6050_usb3_pipe_switch(const struct apple_t6050_usb_io *io) return result; } +/* + * Move a running DWC3 from the dummy producer (0x42) to a USB4 router's USB3 tunnel (0x21: PIPE mode 1, + * clock 2), once the tunnel is active. As for native USB3, the PIPE is locked only when DWC3 is out of + * reset, and a lock that is not acknowledged within 6 ms is not fatal. + * Returns 0, -2 if the PIPE is on another producer, or -7 if the mux did not read back the tunnel. + */ +static inline int +apple_t6050_usb3_pipe_tunnel(const struct apple_t6050_usb_io *io) +{ + unsigned int mux; + int locked; + + if (!io || !io->read || !io->write || !io->poll || !io->delay) + return -1; + mux = io->read(io->context, 44, 0x0c) & 0x73; + if (mux == 0x21) + return 0; + if (mux != 0x42) + return -2; + locked = io->read(io->context, 44, 0x1c) & 1; + + apple_t6050_usb_mask(io, 44, 0x04, 0x0e, 0); + apple_t6050_usb_mask(io, 44, 0x00, 1, 1); + if (locked) { + apple_t6050_usb_mask(io, 44, 0x10, 1, 1); + io->poll(io->context, 44, 0x14, 1, 1, 6000); + } + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0); + io->delay(io->context, 5); + apple_t6050_usb_mask(io, 44, 0x0c, 3, 1); + apple_t6050_usb_mask(io, 44, 0x0c, 0x70, 0x20); + apple_t6050_usb_mask(io, 44, 0x00, 1, 0); + apple_t6050_usb_mask(io, 44, 0x00, 4, 0); + if (locked) { + apple_t6050_usb_mask(io, 44, 0x10, 1, 0); + io->poll(io->context, 44, 0x14, 1, 0, 6000); + } + return (io->read(io->context, 44, 0x0c) & 0x73) == 0x21 ? 0 : -7; +} + /* The native close() call quiesces the ACIO PHY while PIPE is locked, * before selecting the dummy producer. The caller supplies that lifecycle * operation; merely changing MUX is not a complete disconnect sequence. @@ -110,7 +150,7 @@ apple_t6050_usb3_pipe_stop(const struct apple_t6050_usb_io *io, if (!io || !io->read || !io->write || !io->poll || !io->delay || !quiesce) return -1; mux = io->read(io->context, 44, 0x0c) & 0x73; - if (mux != 0x10 && mux != 0x42) + if (mux != 0x10 && mux != 0x21 && mux != 0x42) return -1; apple_t6050_usb_mask(io, 44, 0x04, 0x0e, 0); apple_t6050_usb_mask(io, 44, 0x00, 1, 1); From 37f3967b602a092e7016cdc0e293a5b1b62f19ac Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 18:08:07 -0500 Subject: [PATCH 221/342] dt-bindings: pci: apple,pcie: Add the T6050 PCIe-C tunnel The T6050 PCIe-C root port has the T600x register layout and is always initialized by the kernel. Developed with Claude Code. Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/pci/apple,pcie.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 64f0a2d43e9aa..36cf94442e064 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -75,6 +75,7 @@ properties: - const: apple,t8112-pciec - const: apple,t8103-pciec - const: apple,t6000-pciec + - const: apple,t6050-pciec - items: - const: apple,t8132-pciec - const: apple,t8122-pciec @@ -318,6 +319,7 @@ allOf: - apple,t8103-pciec - apple,t6000-pciec - apple,t6040-pciec + - apple,t6050-pciec then: properties: reg: From b1ffa4722f3d2a10872e1b7f1501a58af0de0e0d Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 12:54:13 -0500 Subject: [PATCH 222/342] PCI: apple: support the T6050 PCIe-C tunnel T6050 PCIe-C is the T8103 tunnel root port with a larger RID2SID table, a different MSI layout and no reset sequence of its own: - RID2SID has 256 entries, which run over the T8103 tunnel block: the posted request counters, TUNCTRL and TUNSTAT move up by 0x700, to 0x1080..0x108c. The release, assert and acknowledge paths use them. - The MSI doorbell takes its high word at 0x16c. MSIs go through the T602x map, indexed by the vector the endpoint sends: the bridge's slice of the window it shares with the internal host, vector n at AIC 1824 + n. Endpoints get base + i as their MSI data. - Nothing hands the port over, so it is always cold-initialized, as the T600x/T602x ports are with pcie_apple.tunnel_kernel_init: debug, fabric and port tunables, PERST and APPCLK, RUN, then the root port's tunables, before the router populates the DART. There is no port reset table to replay and no PMGR reset; only RID2SID is cleared. - The root port's ACK latency limit (0x700) and flow control update timer (0x73c) depend on the max payload size. Set them after every link-up and whenever the root port's DevCtl is written. The parity error interrupt is left alone. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 118 +++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index a28781a22ed0d..c19f271e40d2b 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -200,6 +200,21 @@ MODULE_PARM_DESC(link_up_timeout, "PCIe link training timeout in milliseconds"); #define RC_T6050_MISC_CONTROL_1 0x8bc #define RC_T6050_DBI_RO_WR_EN BIT(0) +/* + * T6050 PCIe-C: the 256-entry RID2SID table runs over the T8103 tunnel block, + * which moves up by 0x700 (posted request counters, TUNCTRL and TUNSTAT). + */ +#define PORT_T6050_TUNCTRL 0x1088 + +/* T6050 PCIe-C root port config space: the MPS-dependent link timers */ +#define PCIEC_RP_DEVCAP 0x074 +#define PCIEC_RP_DEVCTL 0x078 +#define PCIEC_RP_ACK_LATENCY 0x700 +#define PCIEC_RP_FC_TIMER 0x73c +#define PCIEC_RP_FC_TIMER_KEEP 0x6000ffff +#define PCIEC_RP_FC_TIMER_LIMIT GENMASK(28, 16) +#define PCIEC_RP_FC_TIMER_EN BIT(31) + /* * The doorbell address must be in the bottom 4GB because the base register * is only 32 bits wide. Exclude it from the IOVA range and share the same @@ -239,6 +254,8 @@ struct hw_info { * lane PIPE reset status, then release PORT_T8152_PIPE_RST. */ bool pipe_rst; + bool no_port_reset; + bool mps_timers; }; static const struct hw_info t8103_hw = { @@ -384,6 +401,32 @@ static const struct hw_info t6040_pciec_hw = { .s2idle_hold_domain = true, }; +/* + * T6050 PCIe-C keeps the t8103 doorbell, PERST and RID2SID registers, with + * the doorbell's high word at 0x16c and 256 RID2SID entries. MSIs go through + * the t602x map, indexed by the vector the endpoint sends: the bridge's slice + * of the shared window, not a local index. The port has no reset sequence of + * its own, and the root port's ACK latency and flow control timers follow + * the max payload size. + * + * Nothing hands the port over: apple,pciec-kernel-init brings it up with the + * T600x Intr2AXI sequence. + */ +static const struct hw_info t6050_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = PORT_T6050_TUNCTRL, + .max_rid2sid = 256, + .tunneled = true, + .tunnel_intr2axi = true, + .no_port_reset = true, + .msimap_by_vector = true, + .mps_timers = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -1076,6 +1119,10 @@ static void apple_pcie_tunnel_reset_hardware(struct apple_pcie_port *port) { int i; + /* T6050 has no such sequence: only its RID2SID table is cleared. */ + if (port->pcie->hw->no_port_reset) + goto clear_rid2sid; + for (i = 0; i < ARRAY_SIZE(apple_pcie_tunnel_reset_regs); i++) { u32 value = apple_pcie_tunnel_reset_regs[i].value; @@ -1103,6 +1150,7 @@ static void apple_pcie_tunnel_reset_hardware(struct apple_pcie_port *port) apple_pcie_port_writel(port, value, apple_pcie_tunnel_reset_regs[i].offset); } +clear_rid2sid: for (i = 0; i < port->pcie->hw->max_rid2sid; i++) apple_pcie_rid2sid_write(port, i, 0); if (port->pcie->hw->t8132_reset) @@ -1175,8 +1223,8 @@ static int apple_pcie_tunnel_reinitialize(struct apple_pcie_port *port) /* * Bring up a port selected by apple,pciec-kernel-init that no firmware - * handoff left running: tunables and the reset table, then PERST and APPCLK, - * and only then the root-port config-space + * handoff left running: tunables and the reset table (T6050 has none), + * then PERST and APPCLK, and only then the root-port config-space * tunables. Stop before releasing the tunnel reset or starting link * training. */ @@ -1301,10 +1349,48 @@ static void apple_pcie_tunnel_restore_irq_hw(struct apple_pcie_port *port) */ #define APPLE_PCIE_TUNNEL_READY_MS 1000 +/* + * The T6050 PCIe-C root port's ACK latency limit (0x700, low half) and flow + * control update timer (0x73c, bits 28:16) are sized for the max payload + * size. Each word holds both, for MPS 128, 256 and 512. + */ +static const u32 apple_pcie_mps_timers[] = { + 0x003c003c, 0x005a005a, 0x006b006b, +}; + +static void apple_pcie_update_mps_timers(struct apple_pcie *pcie, u32 mps) +{ + void __iomem *rp = pcie->cfg->win; + u32 cap, word, val; + + cap = apple_pcie_tunnel_readl(rp, PCIEC_RP_DEVCAP) & PCI_EXP_DEVCAP_PAYLOAD; + if (mps > cap || mps >= ARRAY_SIZE(apple_pcie_mps_timers)) { + dev_warn(pcie->dev, "no link timers for a %u-byte MPS\n", 128 << mps); + return; + } + + word = apple_pcie_mps_timers[mps]; + writew_relaxed(lower_16_bits(word), rp + PCIEC_RP_ACK_LATENCY); + /* Complete the write, as apple_pcie_tunnel_writel() does. */ + mb(); + isb(); + val = apple_pcie_tunnel_readl(rp, PCIEC_RP_FC_TIMER); + val &= PCIEC_RP_FC_TIMER_KEEP; + val |= FIELD_PREP(PCIEC_RP_FC_TIMER_LIMIT, upper_16_bits(word)) | + PCIEC_RP_FC_TIMER_EN; + apple_pcie_tunnel_writel(rp, val, PCIEC_RP_FC_TIMER); +} + +/* Process context: the link of a tunnel came up. */ static void apple_pcie_tunnel_link_up(struct apple_pcie *pcie) { WRITE_ONCE(pcie->tunnel_ready_at, jiffies + msecs_to_jiffies(APPLE_PCIE_TUNNEL_READY_MS)); + if (pcie->hw->mps_timers) + apple_pcie_update_mps_timers(pcie, + FIELD_GET(PCI_EXP_DEVCTL_PAYLOAD, + apple_pcie_tunnel_readl(pcie->cfg->win, + PCIEC_RP_DEVCTL))); } /* Call before scanning the bus behind a tunnel; elapsed time counts. */ @@ -2778,6 +2864,23 @@ static int apple_msi_init(struct apple_pcie *pcie) goto invalid_slice; } + /* + * T6050's PCIe hosts share one MSI window, vector n at AIC 1824 + n. + * The internal host's bridges own vectors 0..127 and each PCIe-C + * bridge a 32-vector slice of the rest. + */ + if (pcie->hw == &t6050_pciec_hw) { + ret = of_property_read_u32(to_of_node(fwnode), "apple,msi-vector-base", + &pcie->msi_vector_base); + if (ret || pcie->msi_vector_base < 128 || pcie->msi_vector_base % 32 || + pcie->nvecs != 32 || + pcie->msi_vector_base + pcie->nvecs > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 || + args.args_count != 4 || args.args[0] != 0 || args.args[1] != 0 || + args.args[2] != 1824 + pcie->msi_vector_base || + args.args[3] != IRQ_TYPE_EDGE_RISING || DOORBELL_ADDR != 0xfffff000) + goto invalid_slice; + } + /* * The controller-wide ADT count (512) is not a per-host allocation. * Internal PCIe owns vectors 0..31. Each PCIe-C bridge owns a distinct @@ -3294,11 +3397,17 @@ static int apple_pcie_config_write(struct pci_bus *bus, unsigned int devfn, int ret; ret = pci_generic_config_write(bus, devfn, where, size, val); - if (ret || !pcie || !pcie->kernel_init) + if (ret || !pcie) return ret; - /* Root-port prefetchable window. The port block has to be told too. */ if (bus->number != cfg->busr.start || devfn) return ret; + /* The root port's link timers follow its max payload size. */ + if (pcie->hw->mps_timers && where == PCIEC_RP_DEVCTL) + apple_pcie_update_mps_timers(pcie, + FIELD_GET(PCI_EXP_DEVCTL_PAYLOAD, val)); + if (!pcie->kernel_init) + return ret; + /* Root-port prefetchable window. The port block has to be told too. */ if (where < 0x24 || where >= 0x30) return ret; @@ -4830,6 +4939,7 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, + { .compatible = "apple,t6050-pciec", .data = &t6050_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, From 79432bf9312e383e5f9e7688c26a5b6f93bd0b9d Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 12:54:13 -0500 Subject: [PATCH 223/342] thunderbolt: apple: recognize the T6050 PCIe-C host A router finds its PCIe-C host among the children of its apple,pcie-tunnel node by compatible: to tell whether the port gets initialized, to map its Intr2AXI bridge, to find its reset and to find the bound host once a tunnel is up. Accept apple,t6050-pciec there too. The T6050 port has no reset of its own, and the kernel cold-initializes it, which apple_pcie_tunnel_needs_cold_init() reports. Other SoCs see no change. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/thunderbolt/apple.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 0b0c25d5adb69..9cfd12a33dc06 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -935,7 +935,8 @@ static bool apple_cio_pciec_eligible(const struct device_node *np) { return of_device_is_compatible(np, "apple,t6040-pciec") || of_device_is_compatible(np, "apple,t8103-pciec") || - of_device_is_compatible(np, "apple,t6000-pciec"); + of_device_is_compatible(np, "apple,t6000-pciec") || + of_device_is_compatible(np, "apple,t6050-pciec"); } static bool From ec5485290aa55c484af18f623f2e30d98bb2c442 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 12:54:14 -0500 Subject: [PATCH 224/342] arm64: dts: apple: j716c: Add the right port's PCIe tunnel Describe the PCIe-C root port behind the right port's router and its DART, in a node the router points at with apple,pcie-tunnel and populates once it has enabled a PCIe tunnel, and the ATC2_PCIE power state they sit in, in t6050-max.dtsi. The router powers ATC2_PCIE with its other domains, so the port can be cold-initialized before its children are populated. Nothing initialises the DART, so like the router's it carries full error reporting and its two bypass streams, 253 and 255, on which the port issues its own writes, MSIs included; the board gives its tunables and the port's. Its container is not named usb4-pcie-tunnel-N, which would give it the fixed 64-stream topology of the older tunnel DARTs instead of the 256 streams it reports. The bridge's MSIs are vectors 192-223 of the window shared with the internal host. Developed with Claude Code. Signed-off-by: Erik Bourget --- arch/arm64/boot/dts/apple/t6050-j716c.dts | 58 ++++++++++ arch/arm64/boot/dts/apple/t6050-max.dtsi | 103 +++++++++++++++++- .../boot/dts/apple/t6050-peripherals.dtsi | 2 + 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index abdf7ca85b592..55af2f818a954 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -563,3 +563,61 @@ 05 8a 09 01 00 0e 01 41 70 70 6c 65 2c 20 49 6e 63 2e 00 06 02 69 4f 53 00 00 00 00]; }; + +/* ==== The right USB-C port's PCIe tunnel (ATC2): this board's tunables ==== */ +&apciec2_dart { + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>; +}; + +&apciec2 { + apple,tunable-debug = <0x1000 0x1 0x0>; + apple,tunable-rc = <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2020f060>, + <0x8bc 0x1 0x0>; + apple,tunable-fabric = <0x4 0x3f003f 0x240024>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x1e0>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0xf1 0x1>, + <0x74 0x801f 0x4>, + <0x7c 0x801f 0x4>, + <0x84 0x1 0x1>, + <0x88 0x1 0x1>, + <0x8c 0x801f 0x4>, + <0x94 0x1 0x1>, + <0x98 0x801f 0x4>, + <0xa0 0x1 0x1>, + <0xa4 0x801f 0x4>, + <0xac 0x1 0x1>, + <0xb0 0x1 0x1>, + <0xb4 0x801f 0x4>, + <0xbc 0x801f 0x4>, + <0xc4 0x801f 0x4>; +}; + +&apciec2_port { + apple,tunable = <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index 87bd77e4b4b99..c04b66519953c 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -214,9 +214,11 @@ reg-names = "rc", "sram", "pcie-adapter", "cpu", "router-ap-fw"; mboxes = <&acio2_mbox>; resets = <&cio_reconfig0 2>; + /* ATC2_PCIE last: the PCIe tunnel root port, set up before it is populated */ power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, - <&ps_atc2_cio_usb>, <&ps_atc2_cio_auss>; + <&ps_atc2_cio_usb>, <&ps_atc2_cio_auss>, <&ps_atc2_pcie>; thunderbolt-switch; + apple,pcie-tunnel = <&acio2_pcie_tunnel>; pinctrl-0 = <&acio2_lstx_pins>; pinctrl-names = "lstx"; lstx-gpios = <&pinctrl_aop 81 GPIO_ACTIVE_HIGH>; @@ -306,4 +308,103 @@ }; }; }; + +/* + * ATC2's PCIe tunnel: /arm-io/apciec2 and dart-apciec2, the PCIe-C root port behind the router's + * PCIe down adapter, and its DART. The router populates both once it has enabled a PCIe tunnel, + * after the kernel has cold-initialized the port: no boot loader sets it up, and it has no reset + * line of its own. Both sit in ATC2_PCIE, which the router powers with its own domains and the + * host keeps on once it is bound. + * + * The container is not a usb4-pcie-tunnel-N node, whose DART would get the fixed 64-stream + * topology of the earlier tunnel DARTs: this one is read like any T8110 DART. Nothing + * initialises it before Linux, so like the router's it carries every error reported and its + * bypass streams, 253 and 255, which carry the port's own writes (MSIs); the board gives its + * tunables, and the port's. + * + * MSIs use the bridge's 32-vector slice (192-223) of the window shared with the internal host. + */ +&pmgr0 { + /* With the ATC2 USB always-on clock gate, which has no state register of its own */ + ps_atc2_pcie: power-controller@2f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + label = "atc2_pcie"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_atc2_common>, <&ps_atc2_usb_aon>; + }; +}; + +/ { + acio2_pcie_tunnel: pcie-tunnel-2 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + apciec2_dart: iommu@384000000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + reg = <0x3 0x84000000 0x0 0x20000>; + interrupts = ; + power-domains = <&ps_atc2_pcie>; + #iommu-cells = <1>; + apple,bypass-sids = <253 255>; + apple,full-error-reporting; + apple,ctc-flush; + }; + + apciec2: pcie@1c70000000 { + compatible = "apple,t6050-pciec"; + device_type = "pci"; + reg = <0x1c 0x70000000 0x0 0x10000000>, + <0x3 0x84034000 0x0 0x4000>, + <0x3 0x84020000 0x0 0x8000>, + <0x3 0x84038000 0x0 0x4000>, + <0x3 0x84060000 0x0 0x4000>, + <0x3 0x8402c000 0x0 0x4000>, + <0x3 0x84028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + /* The port's: link events and INTx */ + interrupts = ; + interrupt-names = "port0"; + power-domains = <&ps_atc2_pcie>; + /* No boot loader hands the port over: the kernel cold-initializes it. */ + apple,pciec-kernel-init; + + msi-controller; + msi-parent = <&apciec2>; + msi-ranges = <&aic AIC_IRQ 0 2016 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <192>; + + iommu-map = <0x0 &apciec2_dart 0x0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <3>; + bus-range = <0x0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x10 0x0 0x10 0x0 0x2 0x0>, + <0x02000000 0x0 0x00100000 0x12 0x00100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0x12 0x40000000 0x0 0x40000000>; + + apciec2_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + + #address-cells = <3>; + #size-cells = <2>; + ranges; + + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &apciec2_port 0 0 0 0>, + <0 0 0 2 &apciec2_port 0 0 0 1>, + <0 0 0 3 &apciec2_port 0 0 0 2>, + <0 0 0 4 &apciec2_port 0 0 0 3>; + }; + }; + }; +}; #endif diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index ae450252f2acb..05526b53d8bfb 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -1469,6 +1469,7 @@ status = "disabled"; }; +#ifndef T6050_J716C apciec2_dart: iommu@384000000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; reg = <0x3 0x84000000 0x0 0x20000>; @@ -1476,6 +1477,7 @@ #iommu-cells = <1>; status = "disabled"; }; +#endif apciec2_piodma: dma-controller@384068000 { compatible = "apple,t6050-pciec-piodma", "apple,pciec-piodma"; From 5a99d43ab4c88986cb30bec2946333c6e023f5c6 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 19:49:04 -0500 Subject: [PATCH 225/342] mux: apple-display-crossbar: Accept busy T6050 connection status T6050 can report a busy crossbar connection after selecting a valid output. Log that status while retaining the selected route, so an active USB4 DisplayPort tunnel can complete its display setup. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/mux/apple-display-crossbar.c | 86 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/mux/apple-display-crossbar.c b/drivers/mux/apple-display-crossbar.c index 223d7b813dc15..f45d296eebef4 100644 --- a/drivers/mux/apple-display-crossbar.c +++ b/drivers/mux/apple-display-crossbar.c @@ -108,6 +108,8 @@ struct apple_dpxbar_hw { bool no_tunable; /* power domain held only while an output is selected */ bool runtime_pm; + /* T8142 layout: a connection status still busy after its poll is only logged */ + bool status_log_only; }; struct apple_dpxbar { @@ -901,9 +903,33 @@ static const u8 t8142_dest_shift[T8142_MUX_MAX] = { 8, 0, 4, 12, 16 }; static const u8 t8142_select_shift[T8142_MUX_MAX] = { 8, 0, 4, 24, 0 }; static const u8 t8142_select_shift2[T8142_MUX_MAX] = { 20, 12, 16, 28, 4 }; +/* + * Wait up to 1 ms for @mask to clear in status word @reg. Where the hardware + * only reports these bits (T6050), one still set is logged and the change + * goes on; elsewhere the crossbar is taken as faulted. + */ +static int t8142_settle(struct apple_dpxbar *xbar, unsigned int reg, u32 mask, + unsigned int index, const char *what) +{ + u32 value; + int ret; + + ret = readl_poll_timeout_atomic(xbar->regs + reg, value, !(value & mask), 1, 1000); + if (!ret) + return 0; + if (xbar->hw->status_log_only) { + dev_warn_ratelimited(xbar->dev, + "output %u %s: status +%#x = %#x, %#x still set; going on\n", + index, what, reg, value, mask); + return 0; + } + xbar->faulted = true; + return ret; +} + static int t8142_link_down(struct apple_dpxbar *xbar, unsigned int index) { - u32 src, dst, clock, value; + u32 src, dst, clock; int ret; if (!xbar->enabled[index]) @@ -917,24 +943,13 @@ static int t8142_link_down(struct apple_dpxbar *xbar, unsigned int index) dpxbar_clear32(xbar, 0x0c + 4 * clock, src); dpxbar_clear32(xbar, 0x24 + 4 * clock, dst); udelay(1); - ret = readl_poll_timeout_atomic(xbar->regs + 0x800, value, - !(value & src), 1, 1000); - if (ret) { - xbar->faulted = true; - return ret; - } - ret = readl_poll_timeout_atomic(xbar->regs + 0x808 + 4 * clock, value, - !(value & src), 1, 1000); - if (ret) { - xbar->faulted = true; - return ret; - } - ret = readl_poll_timeout_atomic(xbar->regs + 0x81c + 4 * clock, value, - !(value & dst), 1, 1000); - if (ret) { - xbar->faulted = true; + ret = t8142_settle(xbar, 0x800, src, index, "link down"); + if (!ret) + ret = t8142_settle(xbar, 0x808 + 4 * clock, src, index, "link down"); + if (!ret) + ret = t8142_settle(xbar, 0x81c + 4 * clock, dst, index, "link down"); + if (ret) return ret; - } dpxbar_clear32(xbar, 0x08, src); dpxbar_clear32(xbar, 0x20, 7 << (3 * xbar->selected_dispext[index])); dpxbar_clear32(xbar, 0x38, 7 << t8142_dest_shift[index]); @@ -948,7 +963,7 @@ static int t8142_link_down(struct apple_dpxbar *xbar, unsigned int index) static int t8142_link_up(struct apple_dpxbar *xbar, unsigned int index) { int state = xbar->selected_dispext[index]; - u32 clock, select, src, dst, value; + u32 clock, select, src, dst; int ret; if (state < 0) @@ -973,24 +988,13 @@ static int t8142_link_up(struct apple_dpxbar *xbar, unsigned int index) dpxbar_clear32(xbar, 0x1c, src); dpxbar_clear32(xbar, 0x34, dst); udelay(1); - ret = readl_poll_timeout_atomic(xbar->regs + 0x804, value, - !(value & src), 1, 1000); - if (ret) { - xbar->faulted = true; - return ret; - } - ret = readl_poll_timeout_atomic(xbar->regs + 0x818, value, - !(value & src), 1, 1000); - if (ret) { - xbar->faulted = true; - return ret; - } - ret = readl_poll_timeout_atomic(xbar->regs + 0x82c, value, - !(value & dst), 1, 1000); - if (ret) { - xbar->faulted = true; + ret = t8142_settle(xbar, 0x804, src, index, "link up"); + if (!ret) + ret = t8142_settle(xbar, 0x818, src, index, "link up"); + if (!ret) + ret = t8142_settle(xbar, 0x82c, dst, index, "link up"); + if (ret) return ret; - } dpxbar_set32(xbar, 0x08, src); dpxbar_mask32(xbar, 0x20, 7 << (3 * state), select << (3 * state)); dpxbar_mask32(xbar, 0x38, 7 << t8142_dest_shift[index], @@ -1466,8 +1470,16 @@ static const struct apple_dpxbar_hw apple_dpxbar_hw_t8142 = { .ops = &apple_dpxbar_t8142_ops, }; +/* T6050: the T8142 layout; a status that stays busy is logged after settling. */ +static const struct apple_dpxbar_hw apple_dpxbar_hw_t6050 = { + .n_mux = T8142_MUX_MAX, + .n_ufp = 8, + .ops = &apple_dpxbar_t8142_ops, + .status_log_only = true, +}; + static const struct of_device_id apple_dpxbar_ids[] = { - { .compatible = "apple,t6050-display-crossbar", .data = &apple_dpxbar_hw_t8142 }, + { .compatible = "apple,t6050-display-crossbar", .data = &apple_dpxbar_hw_t6050 }, { .compatible = "apple,t8142-display-crossbar", .data = &apple_dpxbar_hw_t8142 }, { .compatible = "apple,t8103-display-crossbar", From 0c906ebf668b7e481c62342a116524b6eedb02a8 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 20:05:40 -0500 Subject: [PATCH 226/342] usb: typec: tipd: Restore J716c dock USB across boot Reinitialize an inherited J716c boot-port USB2 connection before its first connect notification, after suppliers and the Type-C port exist. Limit the operation to the board property and normal host operation; exclude the debug bridge modes. Allow SN201202x up to five seconds to wake so a connected dock can restore its USB hub after boot. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/usb/apple,sn201202x.yaml | 7 ++ drivers/usb/typec/tipd/core.c | 68 ++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml index c2d2eb1068ea8..282d26ae0c6d2 100644 --- a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml +++ b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml @@ -44,6 +44,13 @@ properties: connector: $ref: /schemas/connector/usb-connector.yaml# + apple,reset-inherited-usb2-connection: + type: boolean + description: + The boot USB port retains a USB2 repeater connection that cannot be + recovered by resetting the host PHY. Renegotiate a normal application + connection before starting the host controllers. Debug routes are preserved. + required: - compatible - reg diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 74c820dd0be24..5d157996b214a 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2017,7 +2017,14 @@ static int cd321x_switch_power_state(struct tps6598x *tps, u8 target_state) if (state == target_state) return 0; - ret = tps6598x_exec_cmd(tps, "SSPS", sizeof(u8), &target_state, 0, NULL); + /* SN201202x can still be negotiating an attached dock while waking. */ + if (target_state == TPS_SYSTEM_POWER_STATE_S0 && + device_is_compatible(tps->dev, "apple,sn201202x")) + ret = tps6598x_exec_cmd_tmo(tps, "SSPS", sizeof(target_state), + &target_state, 0, NULL, 5000, 0); + else + ret = tps6598x_exec_cmd(tps, "SSPS", sizeof(target_state), + &target_state, 0, NULL); if (ret) return ret; @@ -2905,6 +2912,61 @@ static int cd321x_remove(struct tps6598x *tps) return 0; } +static int cd321x_reset_inherited_connection(struct tps6598x *tps, u32 *status) +{ + /* J716c's port-controller key is the reversed target identifier J716. */ + static const u8 key[] = { '6', '1', '7', 'J' }; + static const u8 locked[4]; + u8 delay = 5, result; + unsigned long timeout; + int ret, lock_ret, mode; + + if (!device_property_read_bool(tps->dev, "apple,reset-inherited-usb2-connection") || + !of_machine_is_compatible("apple,j716c") || + !device_is_compatible(tps->dev, "apple,sn201202x") || + tps->dbma_at_probe || !(*status & TPS_STATUS_PLUG_PRESENT) || + !TPS_STATUS_TO_TYPEC_DATAROLE(*status)) + return 0; + mode = tps6598x_check_mode(tps); + if (mode != TPS_MODE_APP && mode != TPS_MODE_APP1) + return 0; + + /* All suppliers are available, but no USB or router session has started. */ + ret = tps6598x_exec_cmd(tps, "LOCK", sizeof(key), key, sizeof(result), &result); + if (ret) + return ret; + if (result) { + ret = -EIO; + goto relock; + } + + /* Nonzero DISC delay restores normal CC detection automatically. */ + ret = tps6598x_exec_cmd(tps, "DISC", sizeof(delay), &delay, 0, NULL); + if (!ret) { + msleep(5100); + timeout = jiffies + msecs_to_jiffies(2000); + do { + mode = tps6598x_check_mode(tps); + if (mode == TPS_MODE_APP || mode == TPS_MODE_APP1) + break; + msleep(20); + } while (time_before(jiffies, timeout)); + if (mode != TPS_MODE_APP && mode != TPS_MODE_APP1) + ret = mode < 0 ? mode : -ETIMEDOUT; + } +relock: + /* CC/PD negotiation may still be finishing when application mode returns. */ + lock_ret = tps6598x_exec_cmd_tmo(tps, "LOCK", sizeof(locked), locked, 0, NULL, + 5000, 0); + if (ret || lock_ret) + return ret ?: lock_ret; + if (!tps6598x_read_status(tps, status)) + return -EIO; + tps->status = *status; + dev_info(tps->dev, "reinitialized inherited USB2 connection\n"); + return 0; +} + int tipd_init(struct tps6598x *tps) { struct fwnode_handle *fwnode; @@ -3017,6 +3079,10 @@ int tipd_init(struct tps6598x *tps) } } + ret = cd321x_reset_inherited_connection(tps, &status); + if (ret) + goto err_disconnect; + if (status & TPS_STATUS_PLUG_PRESENT) { ret = -EINVAL; if (!tps->data->read_power_status(tps)) From 371a42c0dfda5def5478b79634971ec14688a551 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 9 Nov 2026 23:01:09 +1100 Subject: [PATCH 227/342] selftests: apple-dcp: Stub the inherited-connection reset in the tipd probe test tipd_init() now calls cd321x_reset_inherited_connection() before it reads the plug state. The probe-transaction model extracts tipd_init() with device_property_read_bool() returning false, for which the real function returns 0 without touching the controller, so stub it that way. Assisted-by: LLM Signed-off-by: Ryan Murray --- tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py index b41f7e2f80689..631237b2ac7b3 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/transaction.py @@ -397,6 +397,7 @@ def probe(root): static int register_port(struct tps6598x *t,struct fwnode_handle *f) { (void)t;(void)f;return register_error; } static bool read_data_status(struct tps6598x *t) { (void)t;return true; } static int connect(struct tps6598x *t,u32 status) { (void)t;(void)status;return connect_error; } +static int cd321x_reset_inherited_connection(struct tps6598x *t,u32 *s) { (void)t;(void)s;return 0; } """ helpers += '\n#define of_machine_is_compatible(name) (!strcmp((name), \"apple,t8140\"))\n#define BIT_ULL(n) (1ULL << (n))\n#define SN201202X_INT_DP_SID_UPDATE BIT_ULL(37)\n' helpers += block(core, 'static bool cd321x_uses_dp_sid(') + '\n' + block(core, 'static u64 cd321x_irq_mask(') + '\n' From b4d99c2f65664836da862c9bfae497d22e38e0b9 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 22:04:50 -0500 Subject: [PATCH 228/342] usb: typec: tipd: Wait for the inherited disconnect task An attached J716c dock can leave DISC running beyond the default one-second command timeout. Probe then attempts LOCK while DISC still owns the command register, receives EBUSY, and abandons the port even though a later reprobe works. Allow five seconds for DISC to acknowledge, matching the surrounding startup operations. Keep the automatic CC restore delay and the post-command application-mode check unchanged. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/usb/typec/tipd/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 5d157996b214a..a6eb842552f1e 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2940,8 +2940,13 @@ static int cd321x_reset_inherited_connection(struct tps6598x *tps, u32 *status) goto relock; } - /* Nonzero DISC delay restores normal CC detection automatically. */ - ret = tps6598x_exec_cmd(tps, "DISC", sizeof(delay), &delay, 0, NULL); + /* + * Nonzero DISC delay restores normal CC detection automatically. The + * task can take more than a second to acknowledge at boot; wait for it + * before issuing LOCK, which a still-busy controller would reject. + */ + ret = tps6598x_exec_cmd_tmo(tps, "DISC", sizeof(delay), &delay, 0, NULL, + 5000, 0); if (!ret) { msleep(5100); timeout = jiffies + msecs_to_jiffies(2000); From a442efa4477ad2f39086f53c854839cc3e0a09fb Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 22:32:16 -0500 Subject: [PATCH 229/342] usb: typec: tipd: preserve dry result during LDCM startup An empty SN201202x port can take 1.6 seconds to acknowledge LDCM at startup. Allow five seconds so a command still running is not treated as a failed mitigation change. Removing mitigation can start a new measurement after a valid dry snapshot. Preserve that result while the new measurement is in progress, as the existing entry path does for a published result. Re-enabling mitigation immediately can hold the detector in the measuring state and permanently suppress a later dock attachment. Keep failures and liquid results mitigated. Exercise the dry-to-measuring transition from every previous state and the failed re-read path in KUnit. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/usb/typec/tipd/core.c | 5 +- drivers/usb/typec/tipd/sn201202x-pm-test.c | 53 ++++++++++++++++++++++ drivers/usb/typec/tipd/spmi.c | 18 +++++++- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index a6eb842552f1e..25325dde72a8c 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -3078,8 +3078,9 @@ int tipd_init(struct tps6598x *tps) if (tps->contaminant_ops) { ret = tps->contaminant_ops->update(tps); if (ret) { - dev_warn(tps->dev, - "connector contaminant state unavailable: %d\n", ret); + if (ret != -EINPROGRESS) + dev_warn(tps->dev, + "connector contaminant state unavailable: %d\n", ret); ret = 0; } } diff --git a/drivers/usb/typec/tipd/sn201202x-pm-test.c b/drivers/usb/typec/tipd/sn201202x-pm-test.c index 68e36f6d951c8..ae55166c33179 100644 --- a/drivers/usb/typec/tipd/sn201202x-pm-test.c +++ b/drivers/usb/typec/tipd/sn201202x-pm-test.c @@ -826,6 +826,57 @@ static void sn201202x_ldcm_dry_order_test(struct kunit *test) sn201202x_ldcm_test_actions(test, &t, actions, ARRAY_SIZE(actions)); } +static void sn201202x_ldcm_dry_then_busy_test(struct kunit *test) +{ + static const enum typec_contaminant last[] = { + TYPEC_CONTAMINANT_UNKNOWN, + TYPEC_CONTAMINANT_NONE, + TYPEC_CONTAMINANT_LIQUID, + }; + const enum sn201202x_ldcm_test_action actions[] = { + LDCM_TEST_READ, + LDCM_TEST_MITIGATE_OFF, + LDCM_TEST_READ, + LDCM_TEST_PUBLISH_NONE, + }; + unsigned int i; + + /* Removing mitigation can start a measurement after a fresh dry result. */ + for (i = 0; i < ARRAY_SIZE(last); i++) { + struct sn201202x_ldcm_test t = { + .reads = { TYPEC_CONTAMINANT_NONE, TYPEC_CONTAMINANT_UNKNOWN }, + }; + + KUNIT_EXPECT_EQ(test, sn201202x_ldcm_update_state(&t, + &sn201202x_ldcm_test_ops, + last[i]), + -EINPROGRESS); + sn201202x_ldcm_test_actions(test, &t, actions, + ARRAY_SIZE(actions)); + } +} + +static void sn201202x_ldcm_dry_then_read_failure_test(struct kunit *test) +{ + const enum sn201202x_ldcm_test_action actions[] = { + LDCM_TEST_READ, + LDCM_TEST_MITIGATE_OFF, + LDCM_TEST_READ, + LDCM_TEST_MITIGATE_ON, + LDCM_TEST_PUBLISH_UNKNOWN, + }; + struct sn201202x_ldcm_test t = { + .reads = { TYPEC_CONTAMINANT_NONE, TYPEC_CONTAMINANT_UNKNOWN }, + .read_rets = { 0, -EIO }, + }; + + /* A failed second read must still mitigate, even after a dry result. */ + KUNIT_EXPECT_EQ(test, sn201202x_ldcm_update_state(&t, + &sn201202x_ldcm_test_ops, + TYPEC_CONTAMINANT_UNKNOWN), -EIO); + sn201202x_ldcm_test_actions(test, &t, actions, ARRAY_SIZE(actions)); +} + static void sn201202x_ldcm_dry_race_test(struct kunit *test) { const enum sn201202x_ldcm_test_action actions[] = { @@ -945,6 +996,8 @@ static struct kunit_case sn201202x_pm_cases[] = { KUNIT_CASE(sn201202x_ldcm_read_failure_order_test), KUNIT_CASE(sn201202x_ldcm_mitigation_failure_order_test), KUNIT_CASE(sn201202x_ldcm_dry_order_test), + KUNIT_CASE(sn201202x_ldcm_dry_then_busy_test), + KUNIT_CASE(sn201202x_ldcm_dry_then_read_failure_test), KUNIT_CASE(sn201202x_ldcm_dry_race_test), KUNIT_CASE(sn201202x_ldcm_dry_race_mitigation_failure_test), KUNIT_CASE(sn201202x_ldcm_busy_keeps_result_test), diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c index 32c3778871013..0ea062474dc0f 100644 --- a/drivers/usb/typec/tipd/spmi.c +++ b/drivers/usb/typec/tipd/spmi.c @@ -300,9 +300,13 @@ static int sn201202x_ldcm_set_mitigation(void *ctx, bool enable) if (sn->ldcm_mitigation_known && sn->ldcm_mitigated == enable) return 0; - /* Successful task completion is the controller's mitigation ACK. */ + /* + * Successful task completion is the controller's mitigation ACK. + * Startup commands can take more than a second on SN201202x. Wait for + * completion before a retry can request the opposite mitigation state. + */ ret = tps6598x_exec_cmd_tmo(tps, "LDCM", sizeof(command), &command, - 0, NULL, 1000, 0); + 0, NULL, 5000, 0); sn->ldcm_mitigation_known = !ret; if (!ret) sn->ldcm_mitigated = enable; @@ -354,6 +358,16 @@ sn201202x_ldcm_update_state(void *ctx, const struct sn201202x_ldcm_ops *ops, /* Do not report dry if liquid appeared while mitigation was removed. */ read_ret = ops->read(ctx, &contaminant); + if (!read_ret && contaminant == TYPEC_CONTAMINANT_UNKNOWN) { + /* + * Removing mitigation can start another measurement. The dry + * snapshot above is still the latest result; preserve it just + * as we preserve a previously published result at entry. Forcing + * mitigation back on here can prevent the measurement finishing. + */ + ops->publish(ctx, TYPEC_CONTAMINANT_NONE); + return -EINPROGRESS; + } if (read_ret || contaminant != TYPEC_CONTAMINANT_NONE) { ret = ops->set_mitigation(ctx, true); if (ret) { From 0471ea2c525c8e6d041479c60593e60f0ad90158 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 22:46:40 -0500 Subject: [PATCH 230/342] usb: typec: tipd: disable LDCM work during removal Reset recovery can invalidate the detector after tipd_remove cancels its work but before cd321x_remove drains resume work. Disable delayed work permanently at removal so this late producer cannot restart it after driver resources are released. Exercise the production stop and invalidate callbacks in KUnit. The regression test runs the callback after cancellation on the old implementation and passes when work is disabled. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/usb/typec/tipd/sn201202x-pm-test.c | 50 ++++++++++++++++++++++ drivers/usb/typec/tipd/spmi.c | 6 ++- drivers/usb/typec/tipd/tps6598x.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tipd/sn201202x-pm-test.c b/drivers/usb/typec/tipd/sn201202x-pm-test.c index ae55166c33179..7fab562ea81d8 100644 --- a/drivers/usb/typec/tipd/sn201202x-pm-test.c +++ b/drivers/usb/typec/tipd/sn201202x-pm-test.c @@ -982,6 +982,55 @@ static void sn201202x_ldcm_read_failure_with_result_test(struct kunit *test) sn201202x_ldcm_test_actions(test, &t, actions, ARRAY_SIZE(actions)); } +struct sn201202x_ldcm_stop_test { + struct sn201202x sn; + atomic_t runs; +}; + +static void sn201202x_ldcm_test_work(struct work_struct *work) +{ + struct sn201202x *sn = container_of(to_delayed_work(work), + struct sn201202x, ldcm_work); + struct sn201202x_ldcm_stop_test *t = container_of(sn, + struct sn201202x_ldcm_stop_test, sn); + + atomic_inc(&t->runs); +} + +static void sn201202x_ldcm_test_cancel(void *data) +{ + cancel_delayed_work_sync(data); +} + +static void sn201202x_ldcm_stop_requeue_test(struct kunit *test) +{ + struct sn201202x_ldcm_stop_test *t; + struct tps6598x *tps; + int ret; + + t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, t); + tps = &t->sn.cd.tps; + mutex_init(&tps->lock); + atomic_set(&t->runs, 0); + INIT_DELAYED_WORK(&t->sn.ldcm_work, sn201202x_ldcm_test_work); + ret = kunit_add_action_or_reset(test, sn201202x_ldcm_test_cancel, &t->sn.ldcm_work); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* Removal must cancel a pending retry and prevent later producers. */ + mod_delayed_work(system_freezable_wq, &t->sn.ldcm_work, 60 * HZ); + sn201202x_contaminant_ops.stop(tps); + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&t->sn.ldcm_work)); + + /* Reset recovery can still invalidate the detector before it is drained. */ + mutex_lock(&tps->lock); + sn201202x_contaminant_ops.invalidate(tps); + mutex_unlock(&tps->lock); + flush_delayed_work(&t->sn.ldcm_work); + KUNIT_EXPECT_EQ(test, atomic_read(&t->runs), 0); + KUNIT_EXPECT_FALSE(test, delayed_work_pending(&t->sn.ldcm_work)); +} + static struct kunit_case sn201202x_pm_cases[] = { KUNIT_CASE(sn201202x_sleep_cycle_test), KUNIT_CASE(sn201202x_failed_wakeup_test), @@ -1003,6 +1052,7 @@ static struct kunit_case sn201202x_pm_cases[] = { KUNIT_CASE(sn201202x_ldcm_busy_keeps_result_test), KUNIT_CASE(sn201202x_ldcm_busy_without_result_test), KUNIT_CASE(sn201202x_ldcm_read_failure_with_result_test), + KUNIT_CASE(sn201202x_ldcm_stop_requeue_test), KUNIT_CASE(sn201202x_idle_sleep_test), KUNIT_CASE(sn201202x_atomic_access_test), KUNIT_CASE(sn201202x_idle_sleep_retry_test), diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c index 0ea062474dc0f..30d472c3d83a4 100644 --- a/drivers/usb/typec/tipd/spmi.c +++ b/drivers/usb/typec/tipd/spmi.c @@ -467,16 +467,18 @@ static void sn201202x_ldcm_invalidate(struct tps6598x *tps) static void sn201202x_ldcm_stop(struct tps6598x *tps) { - cancel_delayed_work_sync(&tps_to_sn(tps)->ldcm_work); + /* Reset recovery is drained later and may still try to queue an update. */ + disable_delayed_work_sync(&tps_to_sn(tps)->ldcm_work); } -static const struct tipd_contaminant_ops sn201202x_contaminant_ops = { +VISIBLE_IF_KUNIT const struct tipd_contaminant_ops sn201202x_contaminant_ops = { .update = sn201202x_ldcm_update, .refresh = sn201202x_ldcm_refresh, .event = sn201202x_ldcm_event, .invalidate = sn201202x_ldcm_invalidate, .stop = sn201202x_ldcm_stop, }; +EXPORT_SYMBOL_IF_KUNIT(sn201202x_contaminant_ops); static struct regmap *__devm_regmap_init_sn201202x(struct spmi_device *sdev, const struct regmap_config *config, diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index c39feab87c20f..20b6b73436a29 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -564,6 +564,7 @@ int sn201202x_runtime_resume(struct device *dev); void sn201202x_idle_sleep_start(struct tps6598x *tps); void sn201202x_idle_sleep_stop(struct tps6598x *tps); extern const struct regmap_bus regmap_sn201202x; +extern const struct tipd_contaminant_ops sn201202x_contaminant_ops; u32 sn201202x_sleep_links(const struct cd321x_sleep_state *st); enum typec_contaminant sn201202x_ldcm_decode(const u8 status[SN201202X_LDCM_STATUS_LEN]); From 10ada134e51a575b25f3cd9c45fea27841edab3f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 07:06:54 -0500 Subject: [PATCH 231/342] pmdomain: apple: pmc: Add T6050 The boot loader leaves every PMC rail of the T6050 with no voter agent enabled, so nothing raises the DRAM controller (DCS) or the SoC fabric above state 0. On the M5 Pro a CPU memcpy then caps at about 42 GB/s for 1 to 12 threads and dependent DRAM loads take 310 ns. T6050 uses the T8140 voter layout with five agents (PMP, CLPC, GFX, AP and the second die's PMP1, from the ADT's voter-agent) and the pending word after each floor word that T8132 has. Its rails are DCS, SOC, DISP and DISP2 (voter-rail-data); the PMP's dvfs-domain lists DCS states 0-6 and fabric states 0-3. As on T6040, agents are enabled on DCS and SOC only. Tested on J714s: the PMC enables the CLPC and AP agents on DCS and SOC (enable words 0xa). With the AP's floor swept by hand, 12-thread memcpy reads 46, 81, 108, 149, 159, 167 and 171 GB/s at DCS 0-6, and 177 GB/s at DCS 6 with fabric 2 or 3; DRAM latency falls from 324 to 135 ns. The layout follows Jeff Queisser's J775D (M5 Ultra) series. Signed-off-by: Diljit Singh --- drivers/pmdomain/apple/pmc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index 3765e9a775ff7..e7189b4a9590a 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -1385,7 +1385,29 @@ static const struct apple_pmc_hw apple_pmc_hw_t8152 = { .ap_agent = 3, }; +/* + * T6050 (M5 Pro/Max): the T8140 layout with five agents (PMP, CLPC, GFX, AP + * and the second die's PMP1, ADT voter-agent) and the T8132 pending word + * after each floor word. Rails DCS, SOC, DISP and DISP2; the PMP's + * dvfs-domain lists DCS states 0-6 and fabric states 0-3. The boot loader + * enables no agent on any rail. Agents are enabled on DCS and SOC only, as + * on T6040. + */ +static const struct apple_pmc_hw apple_pmc_hw_t6050 = { + .agent_stride = 0x4000, + .agents = 5, + .rails = 4, + .agent_state = 0x0, + .rail_enable = 0x2000, + .dcs_rail = 0, + .dcs_max = 6, + .agent_rails = GENMASK(1, 0), + .ap_agent = 3, + .has_pending = true, +}; + static const struct of_device_id apple_pmc_of_match[] = { + { .compatible = "apple,t6050-pmc", .data = &apple_pmc_hw_t6050 }, { .compatible = "apple,t8132-pmc", .data = &apple_pmc_hw_t8132 }, { .compatible = "apple,t8140-pmc", .data = &apple_pmc_hw_t8140 }, { .compatible = "apple,t8142-pmc", .data = &apple_pmc_hw_t8142 }, From 68e0bebd3dbf60c7c6cc7a7745cdcc7fccd11b96 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 07:06:55 -0500 Subject: [PATCH 232/342] arm64: dts: apple: t6050: Link the GPU to the CLPC The GPU driver reports its work in flight to the CLPC named by apple,clpc, which then holds the DRAM controller and fabric floors up while there is some. Without the link, GPU work gets no floor and bandwidth-bound work runs at about a tenth of macOS's rate. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-peripherals.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index eef667d647d3d..f04009130a73c 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -3139,6 +3139,8 @@ , ; power-domains = <&ps_gfx>; + /* Raises the DRAM and fabric floors while GPU work is in flight */ + apple,clpc = <&clpc>; status = "disabled"; }; From 0e3325d9a65b6ae2f942d15998c657368e2b96dc Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 07:06:55 -0500 Subject: [PATCH 233/342] soc: apple: clpc: Add T6050 T6050 has DCS states 0-6 on rail 0 and fabric states 0-3 on rail 1. As on T6040, a cluster requests a state after three busy samples in a row (12 ms), and the GPU driver reports its work in flight, which gets the top of the map while there is some. Idle releases the floor. Tested on J714s (M5 Pro), with the T6050 cpufreq profile loaded: - CPU: a busy cluster at its top state holds DCS 6 / fabric 3; idle clusters at 300 MHz hold nothing. 12-thread memcpy reads 252 GB/s and DRAM latency is 109 ns, against 42 GB/s and 310 ns with neither the floor nor cpufreq (177 GB/s and 135 ns with the floor alone). - GPU (gpubench against macOS 27.2): bandwidth-bound compute 3165 -> 486 us per submission (9.5x -> 1.46x macOS, 42 -> 276 GB/s), buffer copies 3165 -> 486 us (7.0x -> 1.07x), light compute 124 -> 54 us (38 us with cpufreq); ALU and fill stay at macOS's rate. - Holding DCS 6 / fabric 3 at idle costs 1.4 W of system power, which the release avoids. Signed-off-by: Diljit Singh --- drivers/soc/apple/clpc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index 6dfd277463a13..1c590aa538f23 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -265,6 +265,7 @@ int apple_clpc_gpu_get(struct device *dev, struct apple_clpc_gpu **out) if (!np) return of_find_property(dev->of_node, "apple,clpc", NULL) ? -EINVAL : 0; if (!of_device_is_compatible(np, "apple,t6041-clpc") && + !of_device_is_compatible(np, "apple,t6050-clpc") && !of_device_is_compatible(np, "apple,t8132-clpc") && !of_device_is_compatible(np, "apple,t8140-clpc") && !of_device_is_compatible(np, "apple,t8142-clpc")) { @@ -1669,7 +1670,27 @@ static const struct apple_clpc_hw apple_clpc_hw_t8152 = { }, }; +/* + * T6050 (M5 Pro/Max): DCS states 0-6 on rail 0, fabric states 0-3 on rail 1. + * The boot loader enables no agent on either rail, so without this floor + * the DRAM controller and the fabric stay at state 0: CPU memcpy caps at + * about 34 GB/s on the M5 Pro. A busy cluster in the upper half of its range + * asks for the top states; three busy samples in a row (12 ms) are needed, + * as on T6040. The GPU driver reports its work in flight and gets the top + * of the map while it has some. + */ +static const struct apple_clpc_hw apple_clpc_hw_t6050 = { + .rail = { [APPLE_CLPC_DCS] = 0, [APPLE_CLPC_SOC] = 1 }, + .map = { + [APPLE_CLPC_DCS] = { 2, 4, 6, 6 }, + [APPLE_CLPC_SOC] = { 1, 2, 3, 3 }, + }, + .sustain = 3, + .gpu_input = true, +}; + static const struct of_device_id apple_clpc_of_match[] = { + { .compatible = "apple,t6050-clpc", .data = &apple_clpc_hw_t6050 }, { .compatible = "apple,t8132-clpc", .data = &apple_clpc_hw_t8132 }, { .compatible = "apple,t8140-clpc", .data = &apple_clpc_hw_t8140 }, { .compatible = "apple,t8142-clpc", .data = &apple_clpc_hw_t8142 }, From ed7f7d392e89355d8636eab35cbdb9372822b9a1 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:17:02 +0100 Subject: [PATCH 234/342] iommu: apple-dart: generalize the external display power gating An adopted J713 external display DART can be unpowered across sleep, so its registers are used only with its power confirmed: apple_dart_dispext_get() counts a use, an invalidation waits for the uses and marks the DART unconfirmed until a state check after power-up. The internal display DARTs can lose power the same way once their DCP powers its domains down. Give the gate its own flag, power_gated, set for the external display DARTs as before, and rename its state and helpers from dispext_* to pm_*. The external display DART's adoption, frontends, fault handling and state check stay as they are. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/iommu/apple-dart-dcp-shared.h | 12 ++-- drivers/iommu/apple-dart-dcp.h | 75 ++++++++++++------------ drivers/iommu/apple-dart.c | 82 +++++++++++++++------------ 3 files changed, 89 insertions(+), 80 deletions(-) diff --git a/drivers/iommu/apple-dart-dcp-shared.h b/drivers/iommu/apple-dart-dcp-shared.h index f597edd6b6128..2396ac5e1d33c 100644 --- a/drivers/iommu/apple-dart-dcp-shared.h +++ b/drivers/iommu/apple-dart-dcp-shared.h @@ -378,7 +378,7 @@ int apple_dart_dcp_dispext_stream_ok(struct device *piodma, unsigned int sid) if (apple_dart_dispext_retired(pio->dart)) return -EIO; /* Its power not confirmed since sleep: usable later, not now. */ - return apple_dart_dispext_unconfirmed(pio->dart) ? -EAGAIN : 0; + return apple_dart_pm_unconfirmed(pio->dart) ? -EAGAIN : 0; } EXPORT_SYMBOL_GPL(apple_dart_dcp_dispext_stream_ok); @@ -807,7 +807,7 @@ static int __apple_dart_dcp_shared_map(struct device *dev, struct device *piodma /* * J713 external DCP: the external display DART operations above, each - * inside one use of the DART's registers (apple_dart_dispext_get()): with + * inside one use of the DART's registers (apple_dart_pm_get()): with * its power not confirmed since sleep, -EAGAIN before any step, nothing * published, nothing retired. A sleep waits for a use under way to end, so * no step of it (its flushes included) runs unconfirmed. @@ -824,12 +824,12 @@ static struct apple_dart *apple_dart_dcp_dispext_gate(struct device *piodma) struct apple_dart *__gd = apple_dart_dcp_dispext_gate(piodma); \ typeof(call) __ret; \ \ - if (__gd && !apple_dart_dispext_get(__gd)) { \ + if (__gd && !apple_dart_pm_get(__gd)) { \ __ret = (typeof(call))-EAGAIN; \ } else { \ __ret = (call); \ if (__gd) \ - apple_dart_dispext_put(__gd); \ + apple_dart_pm_put(__gd); \ } \ __ret; \ }) @@ -863,11 +863,11 @@ void *apple_dart_dcp_dispext_scanout_alloc(struct device *piodma, size_t size, u struct apple_dart *dart = apple_dart_dcp_dispext_gate(piodma); void *ret; - if (dart && !apple_dart_dispext_get(dart)) + if (dart && !apple_dart_pm_get(dart)) return ERR_PTR(-EAGAIN); ret = __apple_dart_dcp_dispext_scanout_alloc(piodma, size, dva); if (dart) - apple_dart_dispext_put(dart); + apple_dart_pm_put(dart); return ret; } EXPORT_SYMBOL_GPL(apple_dart_dcp_dispext_scanout_alloc); diff --git a/drivers/iommu/apple-dart-dcp.h b/drivers/iommu/apple-dart-dcp.h index 6e74f56c5132c..b65115f08d6ec 100644 --- a/drivers/iommu/apple-dart-dcp.h +++ b/drivers/iommu/apple-dart-dcp.h @@ -68,65 +68,66 @@ struct apple_dart_dcp { } while (0) /* - * J713 external display DART: its power not confirmed since sleep (from - * suspend until its firmware powers it up again): no register of it may be - * read or written, and nothing is retired for that. + * A power-gated display DART (see struct apple_dart): its power not + * confirmed since it may have gone off (from sleep, or from a power-down by + * its DCP, until it is confirmed on again): no register of it may be read or + * written, and nothing is retired for that. */ -static inline bool apple_dart_dispext_unconfirmed(const struct apple_dart *dart) +static inline bool apple_dart_pm_unconfirmed(const struct apple_dart *dart) { - return dart->dispext && READ_ONCE(dart->dispext_unverified); + return dart->power_gated && READ_ONCE(dart->pm_unverified); } /* - * A use of an external display DART's registers, taken at the start of an + * A use of a power-gated display DART's registers, taken at the start of an * operation and dropped at its end, and only with its power confirmed: - * false (the caller returns -EAGAIN, nothing retired) from sleep until its - * next confirmed power-up. Inside it the operation's steps, flushes included, - * run unchecked: an invalidation (sleep) waits for it to end. Any other - * DART: always true, no count. + * false (the caller returns -EAGAIN, nothing retired) from the moment it may + * go off until its next confirmed power-up. Inside it the operation's steps, + * flushes included, run unchecked: an invalidation waits for it to end. Any + * other DART: always true, no count. */ -static inline bool apple_dart_dispext_get(struct apple_dart *dart) +static inline bool apple_dart_pm_get(struct apple_dart *dart) { unsigned long flags; bool ok; - if (!dart->dispext) + if (!dart->power_gated) return true; - spin_lock_irqsave(&dart->dispext_pm_lock, flags); - ok = !dart->dispext_unverified; + spin_lock_irqsave(&dart->pm_gate_lock, flags); + ok = !dart->pm_unverified; if (ok) - dart->dispext_users++; - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); + dart->pm_users++; + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); return ok; } -static inline void apple_dart_dispext_put(struct apple_dart *dart) +static inline void apple_dart_pm_put(struct apple_dart *dart) { unsigned long flags; - if (!dart->dispext) + if (!dart->power_gated) return; - spin_lock_irqsave(&dart->dispext_pm_lock, flags); - if (!--dart->dispext_users) - wake_up_all(&dart->dispext_wq); - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); + spin_lock_irqsave(&dart->pm_gate_lock, flags); + if (!--dart->pm_users) + wake_up_all(&dart->pm_wq); + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); } /* - * Sleep: no power confirmed from now on, a new generation (a check - * still under way confirms nothing), and every use in flight waited for. - * @suspend: asleep until the matching resume (no check runs then). + * Sleep or a power-down: no power confirmed from now on, a new generation (a + * check still under way confirms nothing), and every use in flight waited + * for. @suspend: asleep until the matching resume (no check runs then). */ -static inline void apple_dart_dispext_invalidate(struct apple_dart *dart, bool suspend) +static inline void apple_dart_pm_invalidate(struct apple_dart *dart, bool suspend) { unsigned long flags; - spin_lock_irqsave(&dart->dispext_pm_lock, flags); - dart->dispext_unverified = true; - dart->dispext_sleeping = suspend; - dart->dispext_gen++; - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); - wait_event(dart->dispext_wq, !READ_ONCE(dart->dispext_users)); + spin_lock_irqsave(&dart->pm_gate_lock, flags); + dart->pm_unverified = true; + dart->pm_sleeping = suspend; + dart->pm_gen++; + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); + wait_event(dart->pm_wq, !READ_ONCE(dart->pm_users)); } /* Every borrowed stream of @dart, for one reason. */ @@ -207,7 +208,7 @@ static bool apple_dart_dcp_registers(struct apple_dart_dcp *dcp) struct apple_dart *dart = dcp->dart; u32 protect, ttbr, tcr, streams; - /* An external display DART's callers hold a use of it (apple_dart_dispext_get()). */ + /* An external display DART's callers hold a use of it (apple_dart_pm_get()). */ if (READ_ONCE(dcp->failed)) return false; protect = readl(dart->regs + DART_T8110_PROTECT); @@ -643,7 +644,7 @@ static phys_addr_t apple_dart_dcp_translate(struct apple_dart_dcp *dcp, u64 iova * An external display DART's registers only inside a use of them (its * power confirmed, a sleep waits for it): none, no lookup. */ - if (dcp->failed || !apple_dart_dispext_get(dcp->dart)) + if (dcp->failed || !apple_dart_pm_get(dcp->dart)) goto out; used = true; if (!apple_dart_dcp_registers(dcp)) @@ -675,7 +676,7 @@ static phys_addr_t apple_dart_dcp_translate(struct apple_dart_dcp *dcp, u64 iova out: spin_unlock_irqrestore(&dcp->lock, flags); if (used) - apple_dart_dispext_put(dcp->dart); + apple_dart_pm_put(dcp->dart); return phys; } @@ -1375,13 +1376,13 @@ static size_t apple_dart_dcp_unmap(struct apple_dart_dcp *dcp, u64 iova, * has no generic DMA user (its host mappings are the private window and * scanout APIs, which never come through here). */ - if (!apple_dart_dispext_get(dcp->dart)) { + if (!apple_dart_pm_get(dcp->dart)) { dev_err_ratelimited(dcp->dart->dev, "SID%u unmap at %llx while unconfirmed since sleep: refused\n", dcp->sid, iova); return 0; } unmapped = __apple_dart_dcp_unmap(dcp, iova, size, count, gather); - apple_dart_dispext_put(dcp->dart); + apple_dart_pm_put(dcp->dart); return unmapped; } diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index d5b60c897a4c2..ed6a33e187fc0 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -320,20 +320,27 @@ struct apple_dart { /* A J713 external display DART, borrowed from its external DCP */ bool dispext; /* - * J713 external display DART: its power confirmation across - * sleep, under dispext_pm_lock (a spinlock: only these fields, never + * A display DART whose power can go away under its borrowed streams: + * an external display DART across sleep (its firmware powers it), or an + * internal one powered down by its DCP. Its registers are used only + * with its power confirmed (apple_dart_pm_get()). + */ + bool power_gated; + /* + * Power-gated display DART: its power confirmation across + * sleep, under pm_gate_lock (a spinlock: only these fields, never * across a register access): unverified from suspend until a state * check at a D572(1) of the current generation, which every suspend * and resume moves on; sleeping between suspend and resume; and the - * register uses in flight (apple_dart_dispext_get()), which an - * invalidation waits for (dispext_wq). + * register uses in flight (apple_dart_pm_get()), which an + * invalidation waits for (pm_wq). */ - spinlock_t dispext_pm_lock; - bool dispext_unverified; - bool dispext_sleeping; - u64 dispext_gen; - unsigned int dispext_users; - wait_queue_head_t dispext_wq; + spinlock_t pm_gate_lock; /* the pm_* fields below */ + bool pm_unverified; + bool pm_sleeping; + u64 pm_gen; + unsigned int pm_users; + wait_queue_head_t pm_wq; u32 dispext_protect, dispext_lock; /* PROTECT and PROTECT_LOCK as adopted */ /* Retained radio/display state left in place across suspend-to-idle. */ bool s2idle_kept; @@ -1576,10 +1583,10 @@ static int apple_dart_dcp_invalidate_tlb_gated(struct apple_dart_stream_map *str { int ret; - if (!apple_dart_dispext_get(stream_map->dart)) + if (!apple_dart_pm_get(stream_map->dart)) return -EAGAIN; ret = apple_dart_dcp_invalidate_tlb(stream_map); - apple_dart_dispext_put(stream_map->dart); + apple_dart_pm_put(stream_map->dart); return ret; } @@ -2036,10 +2043,10 @@ static int apple_dart_dcp_domain_flush(struct apple_dart_domain *domain) struct apple_dart *dart = domain->dcp->dart; int ret; - if (!apple_dart_dispext_get(dart)) + if (!apple_dart_pm_get(dart)) return -EAGAIN; ret = __apple_dart_dcp_domain_flush(domain); - apple_dart_dispext_put(dart); + apple_dart_pm_put(dart); return ret; } @@ -2785,11 +2792,11 @@ static struct iommu_device *apple_dart_probe_device(struct device *dev) int ret = -EINVAL; /* An external display DART's registers only inside a use. */ - if (borrowed && !apple_dart_dispext_get(borrowed->dart)) { + if (borrowed && !apple_dart_pm_get(borrowed->dart)) { ret = -EAGAIN; } else if (borrowed) { ret = apple_dart_dcp_validate(borrowed, dev); - apple_dart_dispext_put(borrowed->dart); + apple_dart_pm_put(borrowed->dart); } if (ret) return ERR_PTR(ret); @@ -3054,7 +3061,7 @@ static int apple_dart_of_xlate(struct device *dev, #if IS_ENABLED(CONFIG_APPLE_DART_J713_DCP) /* * The check, inside a use of the DART's registers (on an external display - * DART, apple_dart_dispext_get() by the caller). + * DART, apple_dart_pm_get() by the caller). */ static int __apple_dart_dcp_check(struct device *dev) { @@ -3126,10 +3133,10 @@ int apple_dart_dcp_check(struct device *dev) if (!domain || domain->owner != &apple_dart_iommu_ops || !to_dart_domain(domain)->dcp) return __apple_dart_dcp_check(dev); dart = to_dart_domain(domain)->dcp->dart; - if (!apple_dart_dispext_get(dart)) + if (!apple_dart_pm_get(dart)) return -EAGAIN; ret = __apple_dart_dcp_check(dev); - apple_dart_dispext_put(dart); + apple_dart_pm_put(dart); return ret; } EXPORT_SYMBOL_GPL(apple_dart_dcp_check); @@ -4261,8 +4268,9 @@ static int apple_dart_probe(struct platform_device *pdev) spin_lock_init(&dart->managed_lock); dart->preserve_display = j713_display || j713_dcpext || j713_dispext; dart->dispext = j713_dispext; - spin_lock_init(&dart->dispext_pm_lock); - init_waitqueue_head(&dart->dispext_wq); + dart->power_gated = j713_dispext; + spin_lock_init(&dart->pm_gate_lock); + init_waitqueue_head(&dart->pm_wq); if (j713_dcpext) dart->dcp_instance = &dcp_adt_external[res->start == 0x48a340000ULL]; else if (j713_dispext) @@ -5061,7 +5069,7 @@ static __maybe_unused int apple_dart_suspend(struct device *dev) if (pm_suspend_target_state != PM_SUSPEND_TO_IDLE) return -EBUSY; if (apple_dart_has_borrowed(dart)) - apple_dart_dispext_invalidate(dart, true); + apple_dart_pm_invalidate(dart, true); return 0; } /* @@ -5183,13 +5191,13 @@ static __maybe_unused int apple_dart_resume(struct device *dev) /* * An adopted external display DART may be off now, its display with it, * and nothing confirms otherwise: no register of it is read or written - * (apple_dart_dispext_unconfirmed()) until its firmware powers it up + * (apple_dart_pm_unconfirmed()) until its firmware powers it up * again; the state check then (apple_dart_dcp_dispext_state()) runs * first: kept, it goes on; lost, it is retired, saying so. */ if (dart->dispext) { if (apple_dart_has_borrowed(dart)) { - apple_dart_dispext_invalidate(dart, false); + apple_dart_pm_invalidate(dart, false); dev_dbg(dev, "external display DART unconfirmed after sleep\n"); } return 0; @@ -5290,16 +5298,16 @@ static int apple_dart_dispext_verify(struct apple_dart *dart, const char *when) * not while asleep (between suspend and resume nothing confirms its * power), and an invalidation meanwhile waits for it to end. */ - spin_lock_irqsave(&dart->dispext_pm_lock, flags); - if (dart->dispext_sleeping) { - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); + spin_lock_irqsave(&dart->pm_gate_lock, flags); + if (dart->pm_sleeping) { + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); dev_dbg(dart->dev, "external display DART %s during sleep: not checked\n", when); return -EAGAIN; } - gen = dart->dispext_gen; - was = dart->dispext_unverified; - dart->dispext_users++; - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); + gen = dart->pm_gen; + was = dart->pm_unverified; + dart->pm_users++; + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); protect = readl(dart->regs + DART_T8110_PROTECT); lock = readl(dart->regs + DART_T8110_PROTECT_LOCK); @@ -5319,14 +5327,14 @@ static int apple_dart_dispext_verify(struct apple_dart *dart, const char *when) kept &= (protect & lock & DART_T8110_PROTECT_TTBR_TCR) == (dart->dispext_protect & dart->dispext_lock & DART_T8110_PROTECT_TTBR_TCR); - spin_lock_irqsave(&dart->dispext_pm_lock, flags); + spin_lock_irqsave(&dart->pm_gate_lock, flags); /* Only a check of the current generation confirms: a sleep since voids it. */ - current_gen = gen == dart->dispext_gen; + current_gen = gen == dart->pm_gen; if (kept && current_gen) - dart->dispext_unverified = false; - if (!--dart->dispext_users) - wake_up_all(&dart->dispext_wq); - spin_unlock_irqrestore(&dart->dispext_pm_lock, flags); + dart->pm_unverified = false; + if (!--dart->pm_users) + wake_up_all(&dart->pm_wq); + spin_unlock_irqrestore(&dart->pm_gate_lock, flags); dev_dbg(dart->dev, "external display DART %s: protect %08x lock %08x (adopted %08x/%08x): state %s%s%s\n", when, protect, lock, dart->dispext_protect, dart->dispext_lock, From e794d107fcdc9ec1149883816be5a9ba870e7dd6 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:41:57 +0100 Subject: [PATCH 235/342] dt-bindings: iommu: apple,dart: describe the clock protection slice On T8132 a power state register of a display power domain is guarded by a "clock protection" slice in the PS_PROT register bank. While the slice is enabled, a write that powers the domain's CPU down faults. The native DART power-down disables the DART's streams, flushes it and then clears the slice; power-up sets it again. Add apple,clock-protection to the DART binding: a phandle to the PS_PROT bank and the DART's slice in it. The bank is shared by several DARTs, so describe it as a syscon and add its compatible to the syscon binding. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- .../devicetree/bindings/iommu/apple,dart.yaml | 13 +++++++++++++ Documentation/devicetree/bindings/mfd/syscon.yaml | 1 + 2 files changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 9ba41ab9806d2..73a3e1764fcd8 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -132,6 +132,19 @@ properties: handoff. Linux retains occupied root slots and excludes their entire IOVA spans from allocation. This does not assert immutable descendants. + apple,clock-protection: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: PS_PROT (clock protection) register bank + - description: Index of this DART's slice in the bank + description: > + The clock protection slice that guards a power state register of the + power domain of this DART. Its consumer may power that domain down: the + DART's streams are then disabled and flushed, and the slice disabled, + before the domain powers off, and the slice is enabled again when it + powers up. Only the J713 internal display DARTs use it. + apple,tunable: $ref: /schemas/types.yaml#/definitions/uint32-matrix items: diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml b/Documentation/devicetree/bindings/mfd/syscon.yaml index 945a168b613db..4c6bfa4986ea0 100644 --- a/Documentation/devicetree/bindings/mfd/syscon.yaml +++ b/Documentation/devicetree/bindings/mfd/syscon.yaml @@ -46,6 +46,7 @@ properties: - apm,xgene-mcb - apm,xgene-rb - apm,xgene-scu + - apple,t8132-ps-prot - atmel,sama5d2-sfrbu - atmel,sama5d3-nfc-io - atmel,sama5d3-sfrbu From d584152cb4b50d9b7f4346f74c773b6a247b405c Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:41:57 +0100 Subject: [PATCH 236/342] iommu: apple-dart: power down the J713 internal display DARTs The J713 internal display DARTs are borrowed from the running DCP and stay powered: the DCP keeps the display domains on. To let the DCP power the domains down while the display is off, add apple_dart_dcp_power_off() and apple_dart_dcp_power_on() for a DART that has a clock protection slice (apple,clock-protection). Power-down, with the DCP CPU stopped and the DART's masters idle, marks the DART's power unconfirmed (apple_dart_pm_get() refuses from then on and the uses in flight are waited for) and gates its commands. Then, as the native DART power-down does, it requires no fault, waits up to 1 ms for the TLB command and outstanding transactions to drain, disables the enabled streams, flushes with the power-down TLB command (V2 | STT) and clears the clock protection slice. It saves the translations, their lock and the stream enables first. apple_dart_dcp_power_check() says, changing nothing, whether a power-down can run, so that the DCP can ask before it starts. Power-up restores the slice, requires the streams still disabled and the translations and their lock as saved (a DART that lost them is not rebuilt), flushes, enables the saved streams and confirms the power. A failure in either direction retires the DART's borrowed streams, as other display DART failures do; nothing is retried. While the DART is down its generic DMA streams, the display's SID0 and the DCP's SID23, keep working on their page tables: unmap, the flush after a map and translation use the tables in memory and no register, and the power-up flushes before it enables the streams. The DART's powered-down state changes only with the locks of all its borrowed streams held, so the power-up's flush and its confirmed power are one step for those updates. System resume leaves a powered-down DART alone; its gated commands already keep suspend and the fault handler off its registers. KUnit: a full cycle against RAM registers and a RAM-backed PS_PROT bank, a DART that comes back without its translations, refusals for a locked bank, a stream that stays enabled, a transaction that does not drain and a pending fault, and a SID0 stream whose unmap, flush and translation use only its page tables while the DART is down. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/iommu/Kconfig | 1 + drivers/iommu/apple-dart-dcp.h | 59 +++++- drivers/iommu/apple-dart-test.c | 194 ++++++++++++++++++++ drivers/iommu/apple-dart.c | 316 +++++++++++++++++++++++++++++++- include/linux/soc/apple/dart.h | 12 ++ 5 files changed, 577 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 03a3c6d3759e1..dd2dd23043b54 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -319,6 +319,7 @@ config APPLE_DART config APPLE_DART_J713_DCP bool "Retained J713 display DART support" depends on APPLE_DART=y && ARM64_16K_PAGES + select MFD_SYSCON help Adopt the qualified running J713 internal display DARTs. Their firmware-visible allocations, page tables and noncoherent CPU diff --git a/drivers/iommu/apple-dart-dcp.h b/drivers/iommu/apple-dart-dcp.h index b65115f08d6ec..49ed48c2f3de6 100644 --- a/drivers/iommu/apple-dart-dcp.h +++ b/drivers/iommu/apple-dart-dcp.h @@ -130,6 +130,36 @@ static inline void apple_dart_pm_invalidate(struct apple_dart *dart, bool suspen wait_event(dart->pm_wq, !READ_ONCE(dart->pm_users)); } +/* + * The locks of every borrowed stream of @dart, in a fixed order (SID23, then + * SID0, then SID16). An internal display DART's host_off changes only with + * all of them held, so under any one of them it is stable: while it is set, + * the DART's DCP has it powered down (or powering down), and its generic DMA + * streams (SID0, SID23) update their page tables in memory only, with no + * register used; its power-up flushes every translation, with these locks + * held, before it enables the streams again. + */ +static void apple_dart_host_lock(struct apple_dart *dart, unsigned long *flags) +{ + struct apple_dart_dcp *streams[] = { dart->dcp, dart->frontend[0], dart->frontend[1] }; + unsigned int held = 0; + + local_irq_save(*flags); + for (unsigned int i = 0; i < ARRAY_SIZE(streams); i++) + if (streams[i]) + spin_lock_nested(&streams[i]->lock, held++); +} + +static void apple_dart_host_unlock(struct apple_dart *dart, unsigned long flags) +{ + struct apple_dart_dcp *streams[] = { dart->frontend[1], dart->frontend[0], dart->dcp }; + + for (unsigned int i = 0; i < ARRAY_SIZE(streams); i++) + if (streams[i]) + spin_unlock(&streams[i]->lock); + local_irq_restore(flags); +} + /* Every borrowed stream of @dart, for one reason. */ #define apple_dart_fail_borrowed(dart, fmt, ...) \ do { \ @@ -640,6 +670,18 @@ static phys_addr_t apple_dart_dcp_translate(struct apple_dart_dcp *dcp, u64 iova phys = dcp_dart_pte_phys(pte) | (iova & (DCP_DART_PAGE - 1)); goto out; } + /* + * Powered down by its DCP (stable under this lock): no register, so + * only the host-owned leaves, which expected[] mirrors. + */ + if (READ_ONCE(dcp->dart->host_off)) { + if (!test_bit(root, dcp->foreign) && dcp->expected[root]) { + pte = dcp->expected[root][leaf]; + if (pte) + phys = dcp_dart_pte_phys(pte) | (iova & (DCP_DART_PAGE - 1)); + } + goto out; + } /* * An external display DART's registers only inside a use of them (its * power confirmed, a sleep waits for it): none, no lookup. @@ -1367,6 +1409,14 @@ static size_t apple_dart_dcp_unmap(struct apple_dart_dcp *dcp, u64 iova, { size_t unmapped; + /* + * An internal display DART that its DCP powers down: no use of its + * registers is needed. Under the stream's lock __apple_dart_dcp_unmap() + * sees whether the DART is powered (apple_dart_host_lock()), and while it + * is not, only updates the page tables. + */ + if (dcp->dart->ps_prot) + return __apple_dart_dcp_unmap(dcp, iova, size, count, gather); /* * On an external display DART, only inside a use of its registers. * Returning 0 (nothing unmapped) is not safe for general DMA teardown: @@ -1420,8 +1470,13 @@ static size_t __apple_dart_dcp_unmap(struct apple_dart_dcp *dcp, u64 iova, while (cleared < count && dcp->table[root][leaf + cleared]) WRITE_ONCE(dcp->table[root][leaf + cleared++], 0); dma_wmb(); - /* Strict SID0: invalidate before the IOVA or its pages can be reused. */ - if (cleared && dcp->sid == 0 && apple_dart_dcp_flush(dcp)) { + /* + * Strict SID0: invalidate before the IOVA or its pages can be reused. + * Not while its DCP has the DART powered down: nothing is cached then, + * and the power-up flushes before it enables the streams. + */ + if (cleared && dcp->sid == 0 && !READ_ONCE(dcp->dart->host_off) && + apple_dart_dcp_flush(dcp)) { /* A stale translation may survive: republish the leaves and keep the pages. */ for (size_t i = 0; i < cleared; i++) WRITE_ONCE(dcp->table[root][leaf + i], dcp->expected[root][leaf + i]); diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 5f512e18bfd50..b3c95c3067e45 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -963,6 +963,194 @@ static void apple_dart_test_strict_engines(struct kunit *test) "%s", lazy[i]); } +#if IS_ENABLED(CONFIG_APPLE_DART_J713_DCP) +#define APPLE_DART_TEST_PS_SLICE 42 + +static void apple_dart_test_regmap_exit(void *map) +{ + regmap_exit(map); +} + +/* An internal display DART with one live stream and a PS_PROT bank in RAM. */ +static struct apple_dart *apple_dart_test_host_dart(struct kunit *test) +{ + static const struct regmap_config cfg = { + .reg_bits = 32, .val_bits = 32, .reg_stride = 4, + .max_register = APPLE_PS_PROT_SLICE(APPLE_PS_PROT_SLICES - 1), + }; + static atomic_t instance = ATOMIC_INIT(0); + struct apple_dart *dart; + char name[40]; + void *bank; + + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + /* Device names must be unique: a test may set up several. */ + snprintf(name, sizeof(name), "apple-dart-host-power-%d", atomic_inc_return(&instance)); + dart->dev = kunit_device_register(test, name); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->dev); + dev_set_drvdata(dart->dev, dart); + /* Up to the exception registers at 0x4000, which a 0x0203 DART reads. */ + dart->regs = (__force void __iomem *)kunit_kzalloc(test, APPLE_DART_TEST_REGS_SIZE, + GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart->regs); + dart->hw = &apple_dart_hw_t8110; + dart->num_streams = 2; + dart->pgsize = SZ_16K; + dart->version = 0x0203; + dart->power_gated = true; + spin_lock_init(&dart->lock); + spin_lock_init(&dart->pm_gate_lock); + init_waitqueue_head(&dart->pm_wq); + pm_runtime_set_active(dart->dev); + pm_runtime_enable(dart->dev); + + bank = kunit_kzalloc(test, APPLE_PS_PROT_SLICE(APPLE_PS_PROT_SLICES), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bank); + dart->ps_prot = regmap_init_mmio(NULL, (__force void __iomem *)bank, &cfg); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->ps_prot); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, apple_dart_test_regmap_exit, + dart->ps_prot), 0); + dart->ps_prot_slice = APPLE_DART_TEST_PS_SLICE; + regmap_write(dart->ps_prot, APPLE_PS_PROT_ENABLE, 1); + regmap_write(dart->ps_prot, APPLE_PS_PROT_SLICE(APPLE_DART_TEST_PS_SLICE), 0x12); + + writel(1 << 16, dart->regs + DART_PARAMS2); /* one port */ + writel(DART_T8110_TCR_TRANSLATE_ENABLE, dart->regs + DART_TCR(dart, 1)); + writel(dart->hw->ttbr_valid | 0x1234, dart->regs + DART_TTBR(dart, 1, 0)); + writel(DART_T8110_PROTECT_TTBR_TCR, dart->regs + DART_T8110_PROTECT); + writel(DART_T8110_PROTECT_TTBR_TCR, dart->regs + DART_T8110_PROTECT_LOCK); + return dart; +} + +static u32 apple_dart_test_slice(struct apple_dart *dart) +{ + u32 value = 0; + + regmap_read(dart->ps_prot, APPLE_PS_PROT_SLICE(dart->ps_prot_slice), &value); + return value; +} + +static void apple_dart_test_host_power_cycle(struct kunit *test) +{ + struct apple_dart *dart = apple_dart_test_host_dart(test); + + KUNIT_ASSERT_EQ(test, apple_dart_host_power_off(dart), 0); + KUNIT_EXPECT_TRUE(test, READ_ONCE(dart->host_off)); + KUNIT_EXPECT_TRUE(test, READ_ONCE(dart->commands_gated)); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), DART_T8110_TLB_CMD_POWERDOWN); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x2U); + /* Its registers are not used until power-up. */ + KUNIT_EXPECT_FALSE(test, apple_dart_pm_get(dart)); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_off(dart), -EALREADY); + + KUNIT_ASSERT_EQ(test, apple_dart_host_power_on(dart), 0); + KUNIT_EXPECT_FALSE(test, READ_ONCE(dart->host_off)); + KUNIT_EXPECT_FALSE(test, READ_ONCE(dart->commands_gated)); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), DART_T8110_TLB_CMD_V2); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U); + KUNIT_EXPECT_TRUE(test, apple_dart_pm_get(dart)); + apple_dart_pm_put(dart); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_on(dart), -EALREADY); +} + +static void apple_dart_test_host_power_lost(struct kunit *test) +{ + struct apple_dart *dart = apple_dart_test_host_dart(test); + + KUNIT_ASSERT_EQ(test, apple_dart_host_power_off(dart), 0); + /* Power came back with a reset DART: not rebuilt, not used. */ + writel(0, dart->regs + DART_TTBR(dart, 1, 0)); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_on(dart), -EIO); + KUNIT_EXPECT_TRUE(test, READ_ONCE(dart->host_off)); + KUNIT_EXPECT_FALSE(test, apple_dart_pm_get(dart)); +} + +static void apple_dart_test_host_power_refused(struct kunit *test) +{ + struct apple_dart *dart = apple_dart_test_host_dart(test); + + regmap_write(dart->ps_prot, APPLE_PS_PROT_LOCK, 1); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_off(dart), -EPERM); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), 0U); + + dart = apple_dart_test_host_dart(test); + /* A stream that stays enabled: the flush and the slice are left alone. */ + writel(BIT(1), dart->regs + DART_T8110_ENABLE_STREAMS); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_off(dart), -EIO); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_DISABLE_STREAMS), BIT(1)); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), 0U); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U); + + /* An outstanding transaction that does not drain in time. */ + dart = apple_dart_test_host_dart(test); + writel(1, dart->regs + DART_T8110_OUTSTANDING(0)); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_off(dart), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U); + + /* A pending fault is not waited for. */ + dart = apple_dart_test_host_dart(test); + writel(1, dart->regs + DART_T8110_EXCEPTION(0)); + KUNIT_EXPECT_EQ(test, apple_dart_host_power_off(dart), -EIO); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), 0U); + KUNIT_EXPECT_EQ(test, apple_dart_test_slice(dart), 0x12U); +} + +/* + * Generic SID0 DMA while the DCP has the DART powered down: translations, + * flushes and unmaps use the page tables only, and the power-up flushes. + */ +static void apple_dart_test_host_power_tables(struct kunit *test) +{ + const u64 iova = DCP_DART_ALIAS + 3 * DCP_DART_SLICE + 5 * DCP_DART_PAGE; + const unsigned int root = (iova >> 25) & 2047, leaf = (iova >> 14) & 2047; + const u64 pte = (0x12340000ULL >> 4) | 1 | (0xfffULL << 40); + struct apple_dart *dart = apple_dart_test_host_dart(test); + struct iommu_iotlb_gather gather; + struct apple_dart_domain *domain; + struct apple_dart_dcp *dcp; + + dcp = kunit_kzalloc(test, sizeof(*dcp), GFP_KERNEL); + domain = kunit_kzalloc(test, sizeof(*domain), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dcp); + KUNIT_ASSERT_NOT_NULL(test, domain); + dcp->dart = dart; + spin_lock_init(&dcp->lock); + dcp->root = kunit_kzalloc(test, DCP_DART_ENTRIES * sizeof(u64), GFP_KERNEL); + dcp->table[root] = kunit_kzalloc(test, DCP_DART_ENTRIES * sizeof(u64), GFP_KERNEL); + dcp->expected[root] = kunit_kzalloc(test, DCP_DART_ENTRIES * sizeof(u64), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dcp->root); + KUNIT_ASSERT_NOT_NULL(test, dcp->table[root]); + KUNIT_ASSERT_NOT_NULL(test, dcp->expected[root]); + dcp->root[root] = 0x5670001; + dcp->entry[root] = dcp->root[root]; + dcp->table[root][leaf] = pte; + dcp->expected[root][leaf] = pte; + dart->frontend[0] = dcp; + domain->dcp = dcp; + + KUNIT_ASSERT_EQ(test, apple_dart_host_power_off(dart), 0); + writel(0, dart->regs + DART_T8110_TLB_CMD); /* Any later command shows here. */ + + KUNIT_EXPECT_EQ(test, apple_dart_dcp_translate(dcp, iova + 0x123), + dcp_dart_pte_phys(pte) | 0x123); + KUNIT_EXPECT_EQ(test, apple_dart_dcp_domain_flush(domain), 0); + iommu_iotlb_gather_init(&gather); + KUNIT_EXPECT_EQ(test, apple_dart_dcp_unmap(dcp, iova, DCP_DART_PAGE, 1, &gather), + (size_t)DCP_DART_PAGE); + KUNIT_EXPECT_EQ(test, dcp->table[root][leaf], 0ULL); + KUNIT_EXPECT_EQ(test, dcp->expected[root][leaf], 0ULL); + KUNIT_EXPECT_EQ(test, apple_dart_dcp_translate(dcp, iova), (phys_addr_t)0); + KUNIT_EXPECT_FALSE(test, READ_ONCE(dcp->failed)); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), 0U); + + KUNIT_ASSERT_EQ(test, apple_dart_host_power_on(dart), 0); + KUNIT_EXPECT_EQ(test, readl(dart->regs + DART_T8110_TLB_CMD), DART_T8110_TLB_CMD_V2); + KUNIT_EXPECT_FALSE(test, READ_ONCE(dart->host_off)); +} +#endif + static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_iommu_specifiers), @@ -989,6 +1177,12 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_resume_reset_retry), KUNIT_CASE(apple_dart_test_resume_retained_bypass_t8103), KUNIT_CASE(apple_dart_test_resume_retained_bypass_t8110), +#if IS_ENABLED(CONFIG_APPLE_DART_J713_DCP) + KUNIT_CASE(apple_dart_test_host_power_cycle), + KUNIT_CASE(apple_dart_test_host_power_lost), + KUNIT_CASE(apple_dart_test_host_power_refused), + KUNIT_CASE(apple_dart_test_host_power_tables), +#endif {} }; diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index ed6a33e187fc0..60c14b261c358 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -190,6 +192,27 @@ #define DART_T8110_ENABLE_STREAMS 0xc00 #define DART_T8110_DISABLE_STREAMS 0xc20 +/* Per-port outstanding transactions; the port counts are in PARAMS2. */ +#define DART_T8110_OUTSTANDING(port) (0x230 + 4 * (port)) +#define DART_T8110_PARAMS2_READ_PORTS GENMASK(18, 16) +#define DART_T8110_PARAMS2_WRITE_PORTS GENMASK(22, 20) +/* How long the power-down and power-up wait for transactions to drain. */ +#define DART_T8110_IDLE_TIMEOUT_US 1000 +/* TLB command of the power-down path: flush everything, also stream table state. */ +#define DART_T8110_TLB_CMD_POWERDOWN (DART_T8110_TLB_CMD_V2 | DART_T8110_TLB_CMD_STT) + +/* + * PS_PROT ("clock protection") bank: one slice per protected DART. An + * enabled slice (bit 4) guards a power-state register of the DART's power + * domain; the native DART power-down clears bit 4 after its streams are + * disabled and flushed, and power-up sets it again. + */ +#define APPLE_PS_PROT_ENABLE 0x20 +#define APPLE_PS_PROT_LOCK 0x24 +#define APPLE_PS_PROT_SLICE(n) (0x100 + 0x40 * (n)) +#define APPLE_PS_PROT_SLICES 64 +#define APPLE_PS_PROT_SLICE_ON BIT(4) + #define DART_T8110_TCR 0x1000 #define DART_T8110_TCR_REMAP GENMASK(11, 8) #define DART_T8110_TCR_REMAP_ENABLE BIT(7) @@ -326,6 +349,17 @@ struct apple_dart { * with its power confirmed (apple_dart_pm_get()). */ bool power_gated; + /* + * Internal display DART: powered down by its DCP (from + * apple_dart_dcp_power_off() until apple_dart_dcp_power_on(); changed + * only under apple_dart_host_lock()), with what the power-up checks + * and restores. + */ + bool host_off; + u32 off_streams, off_protect, off_lock; + /* Its clock-protection slice in the PS_PROT bank, if it has one. */ + struct regmap *ps_prot; + u32 ps_prot_slice, ps_prot_saved; /* * Power-gated display DART: its power confirmation across * sleep, under pm_gate_lock (a spinlock: only these fields, never @@ -2036,15 +2070,23 @@ static int __apple_dart_dcp_domain_flush(struct apple_dart_domain *domain); /* * Borrowed DCP domains have no io-pgtable; their flush ignores the range. * On an external display DART only with its power confirmed: -EAGAIN - * (nothing retired) from sleep until its next confirmed power-up. + * (nothing retired) from sleep until its next confirmed power-up. An + * internal display DART that its DCP has powered down needs none: nothing + * is cached, and its power-up flushes every update made before it (they + * hold the stream's lock, which the power-up takes; apple_dart_host_lock()). + * A power-up that completed meanwhile confirmed the power in the same step. */ static int apple_dart_dcp_domain_flush(struct apple_dart_domain *domain) { struct apple_dart *dart = domain->dcp->dart; int ret; - if (!apple_dart_pm_get(dart)) - return -EAGAIN; + if (!apple_dart_pm_get(dart)) { + if (READ_ONCE(dart->host_off)) + return 0; + if (!dart->ps_prot || !apple_dart_pm_get(dart)) + return -EAGAIN; + } ret = __apple_dart_dcp_domain_flush(domain); apple_dart_pm_put(dart); return ret; @@ -4269,6 +4311,18 @@ static int apple_dart_probe(struct platform_device *pdev) dart->preserve_display = j713_display || j713_dcpext || j713_dispext; dart->dispext = j713_dispext; dart->power_gated = j713_dispext; + if (j713_display && of_property_present(dev->of_node, "apple,clock-protection")) { + /* Its DCP can power it down: see apple_dart_dcp_power_off(). */ + dart->ps_prot = syscon_regmap_lookup_by_phandle_args(dev->of_node, + "apple,clock-protection", + 1, &dart->ps_prot_slice); + if (IS_ERR(dart->ps_prot)) + return dev_err_probe(dev, PTR_ERR(dart->ps_prot), + "clock-protection bank\n"); + if (dart->ps_prot_slice >= APPLE_PS_PROT_SLICES) + return -EINVAL; + dart->power_gated = true; + } spin_lock_init(&dart->pm_gate_lock); init_waitqueue_head(&dart->pm_wq); if (j713_dcpext) @@ -5188,6 +5242,9 @@ static __maybe_unused int apple_dart_resume(struct device *dev) /* No reset or restore: see apple_dart_suspend(). */ if (dart->cold_ane) return 0; + /* Powered down by its DCP, which restores it at power-up. */ + if (READ_ONCE(dart->host_off)) + return 0; /* * An adopted external display DART may be off now, its display with it, * and nothing confirms otherwise: no register of it is read or written @@ -5278,6 +5335,259 @@ static const struct of_device_id apple_dart_of_match[] = { MODULE_DEVICE_TABLE(of, apple_dart_of_match); #if IS_ENABLED(CONFIG_APPLE_DART_J713_DCP) +/* The internal display DART of a DCP consumer (its firmware or display stream). */ +static struct apple_dart *apple_dart_dcp_consumer(struct device *dev) +{ + struct iommu_domain *domain = iommu_get_domain_for_dev(dev); + struct apple_dart_domain *dd; + + if (!domain || domain->owner != &apple_dart_iommu_ops) + return NULL; + dd = to_dart_domain(domain); + if (!dd->dcp || dd->dcp->owner != dev || dd->dcp->dart->dispext || + !dd->dcp->dart->ps_prot) + return NULL; + return dd->dcp->dart; +} + +static int apple_dart_tlb_command(struct apple_dart *dart, u32 command) +{ + u32 status; + + writel(command, dart->regs + DART_T8110_TLB_CMD); + return readl_poll_timeout_atomic(dart->regs + DART_T8110_TLB_CMD, status, + !(status & DART_T8110_TLB_CMD_BUSY), 1, + DART_STREAM_COMMAND_BUSY_TIMEOUT); +} + +/* + * Nothing in flight: no fault (-EIO), and no TLB command or outstanding + * transaction (-EBUSY, which can drain). + */ +static int apple_dart_idle(struct apple_dart *dart) +{ + u32 params = readl(dart->regs + DART_PARAMS2); + unsigned int ports = max(FIELD_GET(DART_T8110_PARAMS2_READ_PORTS, params), + FIELD_GET(DART_T8110_PARAMS2_WRITE_PORTS, params)); + + if (!ports || ports > 4 || apple_dart_fault_pending(dart)) + return -EIO; + if (readl(dart->regs + DART_T8110_TLB_CMD) & DART_T8110_TLB_CMD_BUSY) + return -EBUSY; + for (unsigned int port = 0; port < ports; port++) + if (readl(dart->regs + DART_T8110_OUTSTANDING(port))) + return -EBUSY; + return 0; +} + +/* Idle, giving transactions and a command just issued time to drain. */ +static int apple_dart_wait_idle(struct apple_dart *dart) +{ + int ret, idle; + + ret = read_poll_timeout_atomic(apple_dart_idle, idle, idle != -EBUSY, 1, + DART_T8110_IDLE_TIMEOUT_US, false, dart); + return ret ?: idle; +} + +/* Its PS_PROT bank enabled and not locked: its slice can be switched. */ +static int apple_dart_ps_prot_usable(struct apple_dart *dart) +{ + u32 enable, lock; + int ret; + + ret = regmap_read(dart->ps_prot, APPLE_PS_PROT_ENABLE, &enable) ?: + regmap_read(dart->ps_prot, APPLE_PS_PROT_LOCK, &lock); + if (!ret && (!(enable & BIT(0)) || (lock & BIT(0)))) + ret = -EPERM; + return ret; +} + +static int apple_dart_ps_prot_set(struct apple_dart *dart, u32 value) +{ + unsigned int reg = APPLE_PS_PROT_SLICE(dart->ps_prot_slice), now; + int ret; + + ret = regmap_write(dart->ps_prot, reg, value); + if (!ret) + ret = regmap_read(dart->ps_prot, reg, &now); + return ret ?: now == value ? 0 : -EIO; +} + +/* + * Whether apple_dart_dcp_power_off() can run for @dev's DART, changing + * nothing: its DCP asks before the first step of its power-down. + */ +int apple_dart_dcp_power_check(struct device *dev) +{ + struct apple_dart *dart = apple_dart_dcp_consumer(dev); + struct apple_dart_dcp *streams[3]; + + if (!dart) + return -ENODEV; + if (READ_ONCE(dart->host_off)) + return -EALREADY; + streams[0] = dart->dcp; + streams[1] = dart->frontend[0]; + streams[2] = dart->frontend[1]; + for (unsigned int i = 0; i < ARRAY_SIZE(streams); i++) + if (streams[i] && READ_ONCE(streams[i]->failed)) + return -EIO; + return apple_dart_ps_prot_usable(dart); +} +EXPORT_SYMBOL_GPL(apple_dart_dcp_power_check); + +/* + * J713 internal display DART, before its DCP powers the display domains + * down (its DCP CPU stopped, the DART's masters idle): as the native DART + * power-down does, disable its enabled streams, flush with the power-down + * TLB command and clear its clock-protection slice. From here until + * apple_dart_dcp_power_on() its registers are not used: its commands are + * gated, its generic DMA streams update their page tables in memory only + * (apple_dart_host_lock()) and system sleep leaves it alone. On failure its + * borrowed streams are retired. + * @dev is a consumer: the DCP (firmware DART) or its PIODMA (display DART). + */ +static int apple_dart_host_power_off(struct apple_dart *dart) +{ + unsigned long flags; + u32 enabled; + const char *why; + int ret; + + if (READ_ONCE(dart->host_off)) + return -EALREADY; + /* + * Page-table updates stay in memory from now on; then no use of its + * registers either, and the uses in flight are waited for. + */ + apple_dart_host_lock(dart, &flags); + WRITE_ONCE(dart->host_off, true); + apple_dart_host_unlock(dart, flags); + apple_dart_pm_invalidate(dart, false); + apple_dart_quiesce_commands(dart->dev); + + why = "not idle"; + ret = apple_dart_wait_idle(dart); + if (ret) + goto fail; + why = "clock protection"; + ret = apple_dart_ps_prot_usable(dart) ?: + regmap_read(dart->ps_prot, APPLE_PS_PROT_SLICE(dart->ps_prot_slice), + &dart->ps_prot_saved); + if (ret) + goto fail; + + /* What power-up checks: the translations and their lock, and the streams. */ + apple_dart_save_state(dart); + dart->off_protect = readl(dart->regs + DART_T8110_PROTECT); + dart->off_lock = readl(dart->regs + DART_T8110_PROTECT_LOCK); + dart->off_streams = readl(dart->regs + DART_T8110_ENABLE_STREAMS); + + why = "stream disable"; + writel(dart->off_streams, dart->regs + DART_T8110_DISABLE_STREAMS); + enabled = readl(dart->regs + DART_T8110_ENABLE_STREAMS); + ret = enabled ? -EIO : 0; + if (ret) + goto fail; + why = "power-down flush"; + ret = apple_dart_tlb_command(dart, DART_T8110_TLB_CMD_POWERDOWN) ?: + apple_dart_wait_idle(dart); + if (ret) + goto fail; + if (dart->ps_prot_saved & APPLE_PS_PROT_SLICE_ON) { + why = "clock protection off"; + ret = apple_dart_ps_prot_set(dart, dart->ps_prot_saved & ~APPLE_PS_PROT_SLICE_ON); + if (ret) + goto fail; + } + dev_dbg(dart->dev, "powered down: streams %08x, clock protection %08x\n", + dart->off_streams, dart->ps_prot_saved); + return 0; +fail: + apple_dart_fail_borrowed(dart, "power-down: %s (%d)", why, ret); + return ret; +} + +int apple_dart_dcp_power_off(struct device *dev) +{ + struct apple_dart *dart = apple_dart_dcp_consumer(dev); + + return dart ? apple_dart_host_power_off(dart) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_dart_dcp_power_off); + +/* + * After its DCP powered the display domains up again, before the DCP CPU + * runs: restore the clock-protection slice, check that the DART kept its + * translations and their lock (it is not rebuilt), flush, and enable the + * streams that were enabled at power-down. Its registers are then usable + * again. On failure its borrowed streams are retired. + */ +static int apple_dart_host_power_on(struct apple_dart *dart) +{ + unsigned long flags; + const char *why; + int ret; + + if (!READ_ONCE(dart->host_off)) + return -EALREADY; + why = "clock protection on"; + ret = apple_dart_ps_prot_set(dart, dart->ps_prot_saved); + if (ret) + goto fail; + why = "state lost"; + ret = -EIO; + if (readl(dart->regs + DART_T8110_ENABLE_STREAMS) || + readl(dart->regs + DART_T8110_PROTECT) != dart->off_protect || + readl(dart->regs + DART_T8110_PROTECT_LOCK) != dart->off_lock || + !apple_dart_state_retained(dart)) + goto fail; + why = "commands"; + ret = apple_dart_resume_commands(dart->dev); + if (ret) + goto fail; + + /* + * The flush, the streams and the confirmed power are one step for the + * streams' page-table updates (apple_dart_host_lock()): the flush covers + * every update made while the DART was down, and every later update + * finds it powered. + */ + apple_dart_host_lock(dart, &flags); + why = "flush"; + ret = apple_dart_wait_idle(dart) ?: + apple_dart_tlb_command(dart, DART_T8110_TLB_CMD_V2); + if (!ret) { + why = "stream enable"; + writel(dart->off_streams, dart->regs + DART_T8110_ENABLE_STREAMS); + if (readl(dart->regs + DART_T8110_ENABLE_STREAMS) != dart->off_streams) + ret = -EIO; + } + if (!ret) { + WRITE_ONCE(dart->host_off, false); + spin_lock(&dart->pm_gate_lock); + dart->pm_unverified = false; + spin_unlock(&dart->pm_gate_lock); + } + apple_dart_host_unlock(dart, flags); + if (ret) + goto fail; + dev_dbg(dart->dev, "powered up: state kept, streams %08x\n", dart->off_streams); + return 0; +fail: + apple_dart_fail_borrowed(dart, "power-up: %s (%d)", why, ret); + return ret; +} + +int apple_dart_dcp_power_on(struct device *dev) +{ + struct apple_dart *dart = apple_dart_dcp_consumer(dev); + + return dart ? apple_dart_host_power_on(dart) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_dart_dcp_power_on); + /* * J713 external DCP: whether an adopted external display DART kept its * state, its power on (the caller's to know): the TTBR/TCR lock (PROTECT diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index ce81d6ec5bcd3..10d05a7cc042b 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -38,6 +38,15 @@ int apple_dart_dcp_dispext_stream_ok(struct device *piodma, unsigned int sid); void *apple_dart_dcp_dispext_scanout_alloc(struct device *piodma, size_t size, u64 *dva); /* An adopted external display DART's state after its power-up; reads only. */ int apple_dart_dcp_dispext_state(struct device_node *consumer); +/* + * Internal display DART of a DCP consumer (the DCP or its PIODMA), around a + * power-down of the display domains by the DCP: streams off, flushed and + * clock protection cleared before; state checked and streams back after. + * The check says, changing nothing, whether the power-off can run now. + */ +int apple_dart_dcp_power_check(struct device *dev); +int apple_dart_dcp_power_off(struct device *dev); +int apple_dart_dcp_power_on(struct device *dev); /* * Remappable host windows in SID0 of an external display DART: one @@ -56,6 +65,9 @@ void *apple_dart_dcp_scanout_alloc(struct device *dev, size_t size, dma_addr_t * #else static inline int apple_dart_dcp_check(struct device *dev) { return -EOPNOTSUPP; } +static inline int apple_dart_dcp_power_check(struct device *dev) { return -EOPNOTSUPP; } +static inline int apple_dart_dcp_power_off(struct device *dev) { return -EOPNOTSUPP; } +static inline int apple_dart_dcp_power_on(struct device *dev) { return -EOPNOTSUPP; } static inline int apple_dart_dcp_check_buffer(struct device *dev, dma_addr_t iova, size_t size) { return -EOPNOTSUPP; From 41e83511551d6a18b36c93bd91eeaf59fbf2f4e8 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:50:08 +0100 Subject: [PATCH 237/342] dt-bindings: power: apple,pmgr-pwrstate: consumer-switched states The J713 display coprocessor's CPU, frontend and system power states are firmware-owned: the OS keeps them on and never touches their registers. macOS powers them off while the display is asleep, after stopping the coprocessor, and on again before restarting it, with a retention workaround on the CPU state. Add apple,consumer-switched for a firmware-owned state that its consumer may power off and on through the PMGR driver, and apple,retention-workaround for the PMGR registers to set while it is off: triplets of offset, mask and value. A chain of such states powers off child first and on parent first. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- .../bindings/power/apple,pmgr-pwrstate.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index d9cf0b9129926..8281b883bd2ac 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -28,6 +28,19 @@ allOf: apple,force-disable: false apple,force-reset: false apple,externally-clocked: false + apple,consumer-switched: false + - if: + required: + - apple,consumer-switched + then: + required: + - apple,firmware-owned + - if: + required: + - apple,retention-workaround + then: + required: + - apple,consumer-switched description: | Apple SoCs include PMGR blocks responsible for power management, @@ -132,6 +145,32 @@ properties: the power-state register. type: boolean + apple,consumer-switched: + description: + With apple,firmware-owned, the consumer of this domain may power it + off and on again around stopping its coprocessor, through the PMGR + driver, which then writes the state register. The OS otherwise treats + the domain as firmware-owned and always on. A chain of such domains + (this one and its consumer-switched parents) is powered off child first + and on parent first. + type: boolean + + apple,retention-workaround: + description: + PMGR registers to set while this consumer-switched domain is off, and + to restore afterwards, as triplets of the offset in the PMGR register + block, a mask and the masked value while the domain is off. They are + set after automatic power management of the domain is disabled and + before it powers off, and restored after it powers on and before + automatic power management is enabled again. + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset + - description: mask + - description: value while the domain is off + maxItems: 4 + apple,inherited-on: description: | On T8132, the boot loader hands over an active domain whose state From ca61e0808c44088f4d17b2c6ea4af685fa4b0303 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:50:08 +0100 Subject: [PATCH 238/342] pmdomain: apple: pmgr-pwrstate: let a consumer switch firmware-owned states Add apple_pmgr_ps_consumer_off() and apple_pmgr_ps_consumer_on() for the chain of apple,consumer-switched power states that starts at a consumer's power domain: off child first, on parent first. genpd still sees the states as firmware-owned and always on; the consumer has stopped its coprocessor before power-off and restarts it after power-on. Each state follows the native sequence. Power-off requires the state fully on and not in reset, disables automatic power management while staying on (when it was enabled), sets the apple,retention-workaround registers and then power gates, clearing the history bits. Power-on powers on with automatic power management disabled, gives the retention registers' workaround bits back the values they had (no other bit: power-off changed none) and then automatic power management as it was. Every write is read back or waited for; a failure leaves the state failed until reboot, and nothing is retried. A state that is not fully on is refused without being touched. apple_pmgr_ps_consumer_check() says, changing nothing, whether the chain can be powered off at all: consumer-switched, not failed and not off. Whether a state is fully on is known only at power-off: under automatic power management the J713 DCP CPU state reads level 0 while its CPU idles. KUnit: the J713 DCP CPU state reproduces the native power-off and power-on writes as captured on macOS, and keeps retention bits outside the workaround that change while it is off; a state without automatic power management or retention keeps its other bits; and a state that is not on, one whose actual state does not follow and a retention register that does not take its value are refused or failed. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/pmdomain/apple/pmgr-pwrstate-test.c | 191 +++++++++++++ drivers/pmdomain/apple/pmgr-pwrstate.c | 283 ++++++++++++++++++++ include/linux/soc/apple/pmgr-pwrstate.h | 14 + 3 files changed, 488 insertions(+) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate-test.c b/drivers/pmdomain/apple/pmgr-pwrstate-test.c index 67698ccfc74aa..66fb065523dee 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate-test.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate-test.c @@ -357,6 +357,193 @@ static void pmgr_ps_power_on_no_reset_test(struct kunit *test) KUNIT_EXPECT_EQ(test, r->reset_writes, 0U); } +/* + * Consumer-switched states: a state word at offset 0 whose actual state + * follows the target (the history bits are set by a power-gate and cleared + * by writing them), retention registers as plain words, and a write log. + */ +struct pmgr_ps_test_bank { + u32 word[0x30000 / 4]; + bool stuck; /* the actual state no longer follows the target */ + bool ignore_retention; /* retention writes are dropped */ + unsigned int nr_log; + struct { u32 reg, val; } log[16]; +}; + +static int pmgr_ps_test_bank_read(void *ctx, unsigned int reg, unsigned int *val) +{ + struct pmgr_ps_test_bank *b = ctx; + + *val = b->word[reg / 4]; + return 0; +} + +static int pmgr_ps_test_bank_write(void *ctx, unsigned int reg, unsigned int val) +{ + struct pmgr_ps_test_bank *b = ctx; + u32 old = b->word[reg / 4], target, cleared; + + if (b->nr_log < ARRAY_SIZE(b->log)) { + b->log[b->nr_log].reg = reg; + b->log[b->nr_log++].val = val; + } + if (reg) { + if (!b->ignore_retention) + b->word[reg / 4] = val; + return 0; + } + target = FIELD_GET(APPLE_PMGR_PS_TARGET, val); + cleared = val & APPLE_PMGR_FLAGS; /* written as 1: cleared */ + val &= ~(APPLE_PMGR_PS_ACTUAL | APPLE_PMGR_FLAGS); + val |= old & APPLE_PMGR_FLAGS & ~cleared; + val |= FIELD_PREP(APPLE_PMGR_PS_ACTUAL, + b->stuck ? FIELD_GET(APPLE_PMGR_PS_ACTUAL, old) : target); + if (!b->stuck && target == APPLE_PMGR_PS_PWRGATE) + val |= APPLE_PMGR_FLAGS; + b->word[0] = val; + return 0; +} + +static const struct regmap_config pmgr_ps_test_bank_regmap = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .max_register = 0x30000 - 4, + .reg_read = pmgr_ps_test_bank_read, + .reg_write = pmgr_ps_test_bank_write, + .fast_io = true, +}; + +/* The J713 DCP CPU state: AUTO on, with its two retention workaround words. */ +static struct apple_pmgr_ps *pmgr_ps_test_consumer(struct kunit *test, u32 word, + struct pmgr_ps_test_bank **bank) +{ + static atomic_t instance = ATOMIC_INIT(0); + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps; + struct device *dev; + char name[32]; + + b = kunit_kzalloc(test, sizeof(*b), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, b); + b->word[0] = word; + b->word[0x2504c / 4] = 0; + b->word[0x25070 / 4] = 1; + snprintf(name, sizeof(name), "apple-pmgr-consumer-%d", atomic_inc_return(&instance)); + dev = kunit_device_register(test, name); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + ps = kunit_kzalloc(test, sizeof(*ps), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, ps); + ps->dev = dev; + ps->genpd.name = "disp-cpu"; + ps->firmware_owned = true; + ps->consumer_switched = true; + ps->nr_retention = 2; + ps->retention[0].offset = 0x2504c; + ps->retention[0].mask = 3; + ps->retention[0].value = 3; + ps->retention[1].offset = 0x25070; + ps->retention[1].mask = 1; + ps->retention[1].value = 0; + ps->regmap = devm_regmap_init(dev, NULL, b, &pmgr_ps_test_bank_regmap); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ps->regmap); + *bank = b; + return ps; +} + +static void pmgr_ps_test_expect_log(struct kunit *test, struct pmgr_ps_test_bank *b, + const u32 (*want)[2], unsigned int n) +{ + KUNIT_ASSERT_EQ(test, b->nr_log, n); + for (unsigned int i = 0; i < n; i++) { + KUNIT_EXPECT_EQ_MSG(test, b->log[i].reg, want[i][0], "write %u", i); + KUNIT_EXPECT_EQ_MSG(test, b->log[i].val, want[i][1], "write %u", i); + } + b->nr_log = 0; +} + +/* The native J713 DCP CPU writes, as captured on macOS, in order. */ +static void pmgr_ps_consumer_native_test(struct kunit *test) +{ + static const u32 off[][2] = { + { 0, 0x0f0000ff }, { 0x2504c, 3 }, { 0x25070, 0 }, { 0, 0x0f0003f0 }, + }; + static const u32 on[][2] = { + { 0, 0x0f00000f }, { 0x2504c, 0 }, { 0x25070, 1 }, { 0, 0x1f00000f }, + }; + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps = pmgr_ps_test_consumer(test, 0x1f0003ff, &b); + + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), 0); + pmgr_ps_test_expect_log(test, b, off, ARRAY_SIZE(off)); + KUNIT_EXPECT_EQ(test, b->word[0] & (APPLE_PMGR_PS_TARGET | APPLE_PMGR_PS_ACTUAL), 0U); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), -EALREADY); + + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), 0); + pmgr_ps_test_expect_log(test, b, on, ARRAY_SIZE(on)); + KUNIT_EXPECT_EQ(test, b->word[0] & ~APPLE_PMGR_FLAGS, 0x1f0000ffU); + KUNIT_EXPECT_EQ(test, b->word[0x2504c / 4], 0U); + KUNIT_EXPECT_EQ(test, b->word[0x25070 / 4], 1U); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), -EALREADY); +} + +/* Retention bits outside the workaround's mask that change while off are kept. */ +static void pmgr_ps_consumer_retention_mask_test(struct kunit *test) +{ + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps = pmgr_ps_test_consumer(test, 0x1f0003ff, &b); + + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), 0); + b->word[0x2504c / 4] |= 0x100; + b->word[0x25070 / 4] |= 0x10; + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), 0); + KUNIT_EXPECT_EQ(test, b->word[0x2504c / 4], 0x100U); + KUNIT_EXPECT_EQ(test, b->word[0x25070 / 4], 0x11U); +} + +/* FE and SYS: no AUTO and no retention; other bits are kept. */ +static void pmgr_ps_consumer_plain_test(struct kunit *test) +{ + static const u32 off[][2] = { { 0, 0x23f0 } }; + static const u32 on[][2] = { { 0, 0x200f } }; + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps = pmgr_ps_test_consumer(test, 0x20ff, &b); + + ps->nr_retention = 0; + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), 0); + pmgr_ps_test_expect_log(test, b, off, ARRAY_SIZE(off)); + KUNIT_ASSERT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), 0); + pmgr_ps_test_expect_log(test, b, on, ARRAY_SIZE(on)); +} + +static void pmgr_ps_consumer_refused_test(struct kunit *test) +{ + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps; + + /* Not fully on: left alone, and not failed. */ + ps = pmgr_ps_test_consumer(test, 0x1f000044, &b); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), -EBUSY); + KUNIT_EXPECT_EQ(test, b->nr_log, 0U); + KUNIT_EXPECT_FALSE(test, ps->consumer_failed); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), -EALREADY); + + /* The actual state does not follow: failed, and stays failed. */ + ps = pmgr_ps_test_consumer(test, 0x1f0003ff, &b); + b->stuck = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), -ETIMEDOUT); + KUNIT_EXPECT_TRUE(test, ps->consumer_failed); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_on(ps), -EIO); + + /* A retention register that does not take the value: failed before power-off. */ + ps = pmgr_ps_test_consumer(test, 0x1f0003ff, &b); + b->ignore_retention = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_consumer_state_off(ps), -EIO); + KUNIT_EXPECT_TRUE(test, ps->consumer_failed); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_TARGET, b->word[0]), + APPLE_PMGR_PS_ACTIVE); +} + static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_power_on_test), KUNIT_CASE(pmgr_ps_power_off_undo_test), @@ -372,6 +559,10 @@ static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_power_on_latch_sleep_test), KUNIT_CASE(pmgr_ps_power_on_latch_sticky_test), KUNIT_CASE(pmgr_ps_power_on_no_reset_test), + KUNIT_CASE(pmgr_ps_consumer_native_test), + KUNIT_CASE(pmgr_ps_consumer_retention_mask_test), + KUNIT_CASE(pmgr_ps_consumer_plain_test), + KUNIT_CASE(pmgr_ps_consumer_refused_test), {} }; diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 688842390a6a2..d6b0cc28b6c2c 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -41,6 +41,14 @@ #define APPLE_PMGR_PS_PWRGATE 0x0 #define APPLE_PMGR_PS_SET_TIMEOUT 100 +#define APPLE_PMGR_PS_CONSUMER_TIMEOUT 1000 +#define APPLE_PMGR_PS_MAX_RETENTION 4 +#define APPLE_PMGR_PS_MAX_CHAIN 4 + +#define APPLE_PMGR_PS_LEVELS (APPLE_PMGR_PS_TARGET | APPLE_PMGR_PS_ACTUAL) +/* Target and actual state both on (or both power gated). */ +#define APPLE_PMGR_PS_ALL_ON (FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_ACTIVE) | \ + FIELD_PREP(APPLE_PMGR_PS_ACTUAL, APPLE_PMGR_PS_ACTIVE)) #define APPLE_PMGR_PS_PARENT_TIMEOUT 10000 #define APPLE_PMGR_RESET_TIME 1 #define APPLE_PMGR_T8132_RESET_TIME 10 @@ -67,6 +75,20 @@ struct apple_pmgr_ps { bool strict_state; bool wait_parent; u32 reset_time_us; + /* + * apple,consumer-switched: firmware-owned, but powered off and on by its + * consumer (apple_pmgr_ps_consumer_off()). The state word before + * power-off, and the retention workaround registers with their values + * before power-off. A failed transition leaves it failed until reboot. + */ + bool consumer_switched; + bool consumer_off; + bool consumer_failed; + u32 consumer_saved; + unsigned int nr_retention; + struct { + u32 offset, mask, value, saved; + } retention[APPLE_PMGR_PS_MAX_RETENTION]; }; #define genpd_to_apple_pmgr_ps(_genpd) container_of(_genpd, struct apple_pmgr_ps, genpd) @@ -649,6 +671,28 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) * vote and never read, reset or change the hardware state. */ ps->firmware_owned = of_property_read_bool(node, "apple,firmware-owned"); + ps->consumer_switched = of_property_read_bool(node, "apple,consumer-switched"); + if (ps->consumer_switched) { + int n = of_property_count_u32_elems(node, "apple,retention-workaround"); + + if (!ps->firmware_owned || + (n > 0 && (n % 3 || n / 3 > APPLE_PMGR_PS_MAX_RETENTION))) + return dev_err_probe(dev, -EINVAL, "bad consumer-switched policy\n"); + for (int i = 0; n > 0 && i < n / 3; i++) { + of_property_read_u32_index(node, "apple,retention-workaround", 3 * i, + &ps->retention[i].offset); + of_property_read_u32_index(node, "apple,retention-workaround", 3 * i + 1, + &ps->retention[i].mask); + of_property_read_u32_index(node, "apple,retention-workaround", 3 * i + 2, + &ps->retention[i].value); + if (ps->retention[i].value & ~ps->retention[i].mask) + return dev_err_probe(dev, -EINVAL, "bad retention workaround\n"); + } + ps->nr_retention = n > 0 ? n / 3 : 0; + } else if (of_property_present(node, "apple,retention-workaround")) { + return dev_err_probe(dev, -EINVAL, + "retention workaround needs a consumer switch\n"); + } ps->sleep_retained = of_property_read_bool(node, "apple,sleep-retained"); /* * Only T8132 hands over inherited-on domains with this contract. Older @@ -794,6 +838,245 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) return ret; } +static struct platform_driver apple_pmgr_ps_driver; + +/* Wait for the masked state word to read @want; @cur gets the last value. */ +static int apple_pmgr_ps_wait(struct apple_pmgr_ps *ps, u32 mask, u32 want, u32 *cur) +{ + return regmap_read_poll_timeout_atomic(ps->regmap, ps->offset, *cur, + (*cur & mask) == want, 1, + APPLE_PMGR_PS_CONSUMER_TIMEOUT); +} + +/* Write a retention register and read it back. */ +static int apple_pmgr_ps_retention_set(struct apple_pmgr_ps *ps, unsigned int i, u32 value) +{ + u32 now; + int ret; + + ret = regmap_write(ps->regmap, ps->retention[i].offset, value); + if (!ret) + ret = regmap_read(ps->regmap, ps->retention[i].offset, &now); + return ret ?: now == value ? 0 : -EIO; +} + +/* Fully on (target and actual), and not in reset, busy or disabled. */ +static bool apple_pmgr_ps_consumer_ready(u32 reg) +{ + return (reg & APPLE_PMGR_PS_LEVELS) == APPLE_PMGR_PS_ALL_ON && + !(reg & (APPLE_PMGR_RESET | APPLE_PMGR_PS_RESET | APPLE_PMGR_BUSY | + APPLE_PMGR_DEV_DISABLE)); +} + +/* + * The native power-off of a consumer-switched state: from fully on, disable + * automatic power management while staying on, set the retention workaround, + * then power off (clearing the history bits) and wait for it. + */ +static int apple_pmgr_ps_consumer_state_off(struct apple_pmgr_ps *ps) +{ + u32 reg, cur; + int ret; + + if (ps->consumer_failed) + return -EIO; + if (ps->consumer_off) + return -EALREADY; + ret = regmap_read(ps->regmap, ps->offset, ®); + if (ret) + goto fail; + if (!apple_pmgr_ps_consumer_ready(reg)) + return -EBUSY; /* Not touched: not a failure of this state. */ + for (unsigned int i = 0; i < ps->nr_retention; i++) { + ret = regmap_read(ps->regmap, ps->retention[i].offset, &ps->retention[i].saved); + if (ret) + goto fail; + } + ps->consumer_saved = reg; + reg &= ~(APPLE_PMGR_AUTO_ENABLE | APPLE_PMGR_FLAGS); + if (ps->consumer_saved & APPLE_PMGR_AUTO_ENABLE) { + ret = regmap_write(ps->regmap, ps->offset, reg); + if (!ret) + ret = apple_pmgr_ps_wait(ps, APPLE_PMGR_AUTO_ENABLE | APPLE_PMGR_PS_LEVELS, + APPLE_PMGR_PS_ALL_ON, &cur); + if (ret) + goto fail; + } + for (unsigned int i = 0; i < ps->nr_retention; i++) { + ret = apple_pmgr_ps_retention_set(ps, i, (ps->retention[i].saved & + ~ps->retention[i].mask) | + ps->retention[i].value); + if (ret) + goto fail; + } + ps->consumer_off = true; + reg = (reg & ~APPLE_PMGR_PS_TARGET) | APPLE_PMGR_FLAGS | + FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_PWRGATE); + ret = regmap_write(ps->regmap, ps->offset, reg); + if (!ret) + ret = apple_pmgr_ps_wait(ps, APPLE_PMGR_PS_LEVELS | APPLE_PMGR_AUTO_ENABLE, 0, + &cur); + if (ret) + goto fail; + dev_dbg(ps->dev, "PS %s: consumer power-off: %#x -> %#x\n", ps->genpd.name, + ps->consumer_saved, cur); + return 0; +fail: + ps->consumer_failed = true; + dev_err(ps->dev, "PS %s: consumer power-off failed: %d\n", ps->genpd.name, ret); + return ret; +} + +/* + * The native power-on: power on with automatic power management disabled, + * give the retention registers' workaround bits back the values they had + * (only those: power-off changed no other), then automatic power management + * as it was. + */ +static int apple_pmgr_ps_consumer_state_on(struct apple_pmgr_ps *ps) +{ + u32 reg, cur, now; + int ret; + + if (ps->consumer_failed) + return -EIO; + if (!ps->consumer_off) + return -EALREADY; + reg = (ps->consumer_saved & ~(APPLE_PMGR_AUTO_ENABLE | APPLE_PMGR_FLAGS | + APPLE_PMGR_BUSY | APPLE_PMGR_PS_ACTUAL)) | + FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_ACTIVE); + ret = regmap_write(ps->regmap, ps->offset, reg); + if (!ret) + ret = apple_pmgr_ps_wait(ps, APPLE_PMGR_PS_LEVELS, APPLE_PMGR_PS_ALL_ON, &cur); + if (ret) + goto fail; + for (unsigned int i = 0; i < ps->nr_retention; i++) { + u32 mask = ps->retention[i].mask; + + ret = regmap_read(ps->regmap, ps->retention[i].offset, &now); + if (!ret) + ret = apple_pmgr_ps_retention_set(ps, i, (now & ~mask) | + (ps->retention[i].saved & mask)); + if (ret) + goto fail; + } + if (ps->consumer_saved & APPLE_PMGR_AUTO_ENABLE) { + ret = regmap_write(ps->regmap, ps->offset, reg | APPLE_PMGR_AUTO_ENABLE); + if (!ret) + ret = apple_pmgr_ps_wait(ps, APPLE_PMGR_AUTO_ENABLE, APPLE_PMGR_AUTO_ENABLE, + &cur); + if (ret) + goto fail; + } + ps->consumer_off = false; + dev_dbg(ps->dev, "PS %s: consumer power-on: %#x\n", ps->genpd.name, cur); + return 0; +fail: + ps->consumer_failed = true; + dev_err(ps->dev, "PS %s: consumer power-on failed: %d\n", ps->genpd.name, ret); + return ret; +} + +/* The consumer-switched states from @consumer's domain up, child first. */ +static int apple_pmgr_ps_consumer_chain(struct device *consumer, + struct apple_pmgr_ps **chain) +{ + struct device_node *np = of_parse_phandle(consumer->of_node, "power-domains", 0); + int n = 0; + + while (np) { + struct platform_device *pdev = of_find_device_by_node(np); + struct apple_pmgr_ps *ps = NULL; + struct device_node *parent; + + if (pdev && pdev->dev.driver == &apple_pmgr_ps_driver.driver) + ps = platform_get_drvdata(pdev); + if (pdev) + put_device(&pdev->dev); + if (!ps || !ps->consumer_switched || n == APPLE_PMGR_PS_MAX_CHAIN) { + of_node_put(np); + break; + } + chain[n++] = ps; + parent = of_parse_phandle(np, "power-domains", 0); + of_node_put(np); + np = parent; + } + return n ?: -ENODEV; +} + +static int apple_pmgr_ps_consumer_switch(struct apple_pmgr_ps *ps, bool on) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&ps->genpd.slock, flags); + ret = on ? apple_pmgr_ps_consumer_state_on(ps) : apple_pmgr_ps_consumer_state_off(ps); + spin_unlock_irqrestore(&ps->genpd.slock, flags); + return ret; +} + +/* + * Whether apple_pmgr_ps_consumer_off() can run for @consumer, changing + * nothing: the whole chain consumer-switched, not failed and not off. Not + * whether each state is fully on: under automatic power management the + * J713 DCP CPU state reads level 0 while its CPU idles, and is fully on + * again once the CPU has been stopped, which the power-off then requires. + */ +int apple_pmgr_ps_consumer_check(struct device *consumer) +{ + struct apple_pmgr_ps *chain[APPLE_PMGR_PS_MAX_CHAIN]; + int n = apple_pmgr_ps_consumer_chain(consumer, chain), ret = 0; + + if (n < 0) + return n; + for (int i = 0; i < n && !ret; i++) { + struct apple_pmgr_ps *ps = chain[i]; + unsigned long flags; + + spin_lock_irqsave(&ps->genpd.slock, flags); + if (ps->consumer_failed) + ret = -EIO; + else if (ps->consumer_off) + ret = -EALREADY; + spin_unlock_irqrestore(&ps->genpd.slock, flags); + } + return ret; +} +EXPORT_SYMBOL_GPL(apple_pmgr_ps_consumer_check); + +int apple_pmgr_ps_consumer_off(struct device *consumer) +{ + struct apple_pmgr_ps *chain[APPLE_PMGR_PS_MAX_CHAIN]; + int n = apple_pmgr_ps_consumer_chain(consumer, chain), ret; + + if (n < 0) + return n; + for (int i = 0; i < n; i++) { + ret = apple_pmgr_ps_consumer_switch(chain[i], false); + if (ret) + return ret; + } + return 0; +} +EXPORT_SYMBOL_GPL(apple_pmgr_ps_consumer_off); + +int apple_pmgr_ps_consumer_on(struct device *consumer) +{ + struct apple_pmgr_ps *chain[APPLE_PMGR_PS_MAX_CHAIN]; + int n = apple_pmgr_ps_consumer_chain(consumer, chain), ret; + + if (n < 0) + return n; + for (int i = n - 1; i >= 0; i--) { + ret = apple_pmgr_ps_consumer_switch(chain[i], true); + if (ret) + return ret; + } + return 0; +} +EXPORT_SYMBOL_GPL(apple_pmgr_ps_consumer_on); + static const struct of_device_id apple_pmgr_ps_of_match[] = { { .compatible = "apple,t8103-pmgr-pwrstate" }, { .compatible = "apple,pmgr-pwrstate" }, diff --git a/include/linux/soc/apple/pmgr-pwrstate.h b/include/linux/soc/apple/pmgr-pwrstate.h index 63311cfd7d979..e09a7ee3e031c 100644 --- a/include/linux/soc/apple/pmgr-pwrstate.h +++ b/include/linux/soc/apple/pmgr-pwrstate.h @@ -4,12 +4,26 @@ #include +struct device; struct device_node; #if IS_ENABLED(CONFIG_APPLE_PMGR_PWRSTATE) int apple_pmgr_ps_cycle(struct device_node *np); +/* + * Power off (child first) or on (parent first) the chain of + * apple,consumer-switched power states that starts at @consumer's power + * domain. The consumer has stopped its coprocessor before power-off and + * starts it again after power-on. The check says, changing nothing, whether + * the power-off can run now. + */ +int apple_pmgr_ps_consumer_check(struct device *consumer); +int apple_pmgr_ps_consumer_off(struct device *consumer); +int apple_pmgr_ps_consumer_on(struct device *consumer); #else static inline int apple_pmgr_ps_cycle(struct device_node *np) { return -EOPNOTSUPP; } +static inline int apple_pmgr_ps_consumer_check(struct device *consumer) { return -EOPNOTSUPP; } +static inline int apple_pmgr_ps_consumer_off(struct device *consumer) { return -EOPNOTSUPP; } +static inline int apple_pmgr_ps_consumer_on(struct device *consumer) { return -EOPNOTSUPP; } #endif #endif From 71f705417c1be929d9d787655f316d50eb8078a4 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:56:12 +0100 Subject: [PATCH 239/342] dt-bindings: power: apple,pmc: consumer-switched interface enables A display pipe's BWR and boost interface enables are described as a power domain between the pipe's SYS and FE power states. The J713 internal display's power states are firmware-owned and on from boot, while the boot loader leaves only its boost enable set, so its enables cannot be such a domain; macOS clears them before powering the pipe down and sets them again after powering it up. Add apple,consumer-switched for an interface node that is not a power domain: the display coprocessor that refers to it clears its bits before it powers the pipe down and restores them after it powers the pipe up. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- .../devicetree/bindings/power/apple,pmc.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/power/apple,pmc.yaml b/Documentation/devicetree/bindings/power/apple,pmc.yaml index 85b54bc769bfa..24f77b80d6495 100644 --- a/Documentation/devicetree/bindings/power/apple,pmc.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmc.yaml @@ -214,12 +214,28 @@ patternProperties: maximum: 31 description: Bit of the pipe in the boost interface enable word. + apple,consumer-switched: + type: boolean + description: | + Not a power domain. The pipe's power is firmware-owned, and the + display coprocessor that refers to this node (apple,pmc-interface) + clears the bits before it powers the pipe down and gives them back + the values they had after it powers the pipe up again. + required: - - '#power-domain-cells' - - power-domains - apple,bwr-bit - apple,boost-bit + oneOf: + - required: + - '#power-domain-cells' + - power-domains + - required: + - apple,consumer-switched + properties: + '#power-domain-cells': false + power-domains: false + '^performance-controller@[0-9a-f]+$': type: object description: The host performance controller's voter agent. From 7d88b7239ebb269ee1cea176f3344a30960c299c Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 17:56:12 +0100 Subject: [PATCH 240/342] pmdomain: apple: pmc: let a consumer switch a pipe's interface enables An interface node with apple,consumer-switched keeps its BWR and boost bits reserved but is not a genpd domain. Add apple_pmc_interface_consumer_off() and apple_pmc_interface_consumer_on() for the consumer that names it in apple,pmc-interface: off saves both bits and clears the boost, then the BWR enable, as a pipe's power-down does; on gives both back the values they had. If the BWR enable does not take the change on the way off, the boost enable gets its old value back. Nothing is retried, and the bits of other pipes are left alone. As for the other interface domains, the bits return to their values at probe when the PMC goes away. apple_pmc_interface_consumer_check() says, changing nothing, whether the bits can be cleared now. KUnit: the internal display's bits with the boost enable only (as Linux finds them) and with both set (as macOS keeps them), next to dispext0's boost bit, and a BWR enable that does not clear. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/pmdomain/apple/pmc-test.c | 60 ++++++++++++++ drivers/pmdomain/apple/pmc.c | 125 +++++++++++++++++++++++++++++- include/linux/soc/apple/pmc.h | 23 ++++++ 3 files changed, 207 insertions(+), 1 deletion(-) diff --git a/drivers/pmdomain/apple/pmc-test.c b/drivers/pmdomain/apple/pmc-test.c index d563a178dc0e8..4e7f19d47317a 100644 --- a/drivers/pmdomain/apple/pmc-test.c +++ b/drivers/pmdomain/apple/pmc-test.c @@ -355,6 +355,64 @@ static void apple_pmc_test_interface_stuck(struct kunit *test) test->priv = NULL; } +/* + * The internal display's consumer-switched interface (BWR and boost bit 0): + * off clears its bits only, on gives back the values they had, whether the + * boot loader left both set or only the boost enable. + */ +static void apple_pmc_test_interface_consumer(struct kunit *test) +{ + struct apple_pmc *pmc = apple_pmc_test_alloc(test); + struct apple_pmc_domain dom = { + .pmc = pmc, .interface = true, .bwr_bit = 0, .boost_bit = 0, + .consumer_switched = true, + }; + const struct apple_pmc_hw *hw = &apple_pmc_hw_t8132; + + pmc->hw = hw; + /* As Linux finds them: the boost enable only, next to dispext0's. */ + writel(BIT(0) | BIT(1), pmc->rails + hw->boost_enable); + KUNIT_EXPECT_EQ(test, apple_pmc_interface_consumer_set(&dom, true), -EALREADY); + KUNIT_ASSERT_EQ(test, apple_pmc_interface_consumer_set(&dom, false), 0); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->bwr_enable), 0U); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->boost_enable), BIT(1)); + KUNIT_EXPECT_EQ(test, apple_pmc_interface_consumer_set(&dom, false), -EALREADY); + KUNIT_ASSERT_EQ(test, apple_pmc_interface_consumer_set(&dom, true), 0); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->bwr_enable), 0U); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->boost_enable), BIT(0) | BIT(1)); + + /* As macOS keeps them while the display is on: both set. */ + writel(BIT(0), pmc->rails + hw->bwr_enable); + KUNIT_ASSERT_EQ(test, apple_pmc_interface_consumer_set(&dom, false), 0); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->bwr_enable), 0U); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->boost_enable), BIT(1)); + KUNIT_ASSERT_EQ(test, apple_pmc_interface_consumer_set(&dom, true), 0); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->bwr_enable), BIT(0)); + KUNIT_EXPECT_EQ(test, readl(pmc->rails + hw->boost_enable), BIT(0) | BIT(1)); +} + +/* A BWR enable that does not clear: the boost enable goes back, still on. */ +static void apple_pmc_test_interface_consumer_stuck(struct kunit *test) +{ + struct apple_pmc *pmc = apple_pmc_test_alloc(test); + struct apple_pmc_domain dom = { + .pmc = pmc, .interface = true, .bwr_bit = 0, .boost_bit = 0, + .consumer_switched = true, + }; + const struct apple_pmc_hw *hw = &apple_pmc_hw_t8132; + struct apple_pmc_test_stuck stuck = { .offset = hw->bwr_enable, .value = BIT(0) }; + + pmc->hw = hw; + writel(BIT(0), pmc->rails + hw->boost_enable); + test->priv = &stuck; + kunit_activate_static_stub(test, apple_pmc_interface_read, apple_pmc_test_stuck_read); + KUNIT_EXPECT_EQ(test, apple_pmc_interface_consumer_set(&dom, false), -EIO); + KUNIT_EXPECT_FALSE(test, dom.consumer_off); + KUNIT_EXPECT_EQ(test, apple_pmc_interface_read(pmc, hw->boost_enable), BIT(0)); + kunit_deactivate_static_stub(test, apple_pmc_interface_read); + test->priv = NULL; +} + static void apple_pmc_test_genpd_remove(void *genpd) { pm_genpd_remove(genpd); @@ -497,6 +555,8 @@ static struct kunit_case apple_pmc_test_cases[] = { KUNIT_CASE(apple_pmc_test_floor_pending_timeout), KUNIT_CASE(apple_pmc_test_interface), KUNIT_CASE(apple_pmc_test_interface_stuck), + KUNIT_CASE(apple_pmc_test_interface_consumer), + KUNIT_CASE(apple_pmc_test_interface_consumer_stuck), KUNIT_CASE(apple_pmc_test_interface_genpd), KUNIT_CASE(apple_pmc_test_interface_boot_state), {} diff --git a/drivers/pmdomain/apple/pmc.c b/drivers/pmdomain/apple/pmc.c index 3765e9a775ff7..40392c9d46603 100644 --- a/drivers/pmdomain/apple/pmc.c +++ b/drivers/pmdomain/apple/pmc.c @@ -152,6 +152,10 @@ struct apple_pmc { * @interface: the domain is a display pipe's BWR and boost interface enables * @bwr_bit: with @interface, the bit in the BWR interface enable word * @boost_bit: with @interface, the bit in the boost interface enable word + * @consumer_switched: with @interface, not a genpd domain: its consumer clears + * and restores its bits (apple_pmc_interface_consumer_off()) + * @consumer_off: with @consumer_switched, cleared by its consumer, and the + * bits it had then (@consumer_bwr, @consumer_boost); protected by pmc->lock */ struct apple_pmc_domain { struct generic_pm_domain genpd; @@ -168,6 +172,10 @@ struct apple_pmc_domain { bool interface; unsigned int bwr_bit; unsigned int boost_bit; + bool consumer_switched; + bool consumer_off; + bool consumer_bwr; + bool consumer_boost; bool provider; }; @@ -766,6 +774,107 @@ static int apple_pmc_interface_set(struct apple_pmc_domain *dom, bool on) return ret; } +/* + * A consumer-switched interface: off clears the boost, then the BWR enable, + * as a pipe's power-down does, after saving both; on gives both back what + * they had then. If the BWR enable does not take the change on the way off, + * the boost enable gets its old value back. Nothing is retried. + */ +static int apple_pmc_interface_consumer_set(struct apple_pmc_domain *dom, bool on) +{ + struct apple_pmc *pmc = dom->pmc; + const struct apple_pmc_hw *hw = pmc->hw; + unsigned long flags; + int ret; + + raw_spin_lock_irqsave(&pmc->lock, flags); + if (on != dom->consumer_off) { + ret = -EALREADY; + } else if (on) { + ret = apple_pmc_interface_update(pmc, hw->boost_enable, dom->boost_bit, + dom->consumer_boost); + if (!ret) + ret = apple_pmc_interface_update(pmc, hw->bwr_enable, dom->bwr_bit, + dom->consumer_bwr); + if (!ret) + dom->consumer_off = false; + } else { + dom->consumer_bwr = apple_pmc_interface_read(pmc, hw->bwr_enable) & + BIT(dom->bwr_bit); + dom->consumer_boost = apple_pmc_interface_read(pmc, hw->boost_enable) & + BIT(dom->boost_bit); + ret = apple_pmc_interface_update(pmc, hw->boost_enable, dom->boost_bit, false); + if (!ret) { + ret = apple_pmc_interface_update(pmc, hw->bwr_enable, dom->bwr_bit, false); + if (ret) + apple_pmc_interface_update(pmc, hw->boost_enable, dom->boost_bit, + dom->consumer_boost); + } + if (!ret) + dom->consumer_off = true; + } + raw_spin_unlock_irqrestore(&pmc->lock, flags); + + return ret; +} + +static struct platform_driver apple_pmc_driver; + +/* The consumer-switched interface named by @consumer's apple,pmc-interface. */ +static struct apple_pmc_domain *apple_pmc_consumer_interface(struct device *consumer) +{ + struct device_node *np = of_parse_phandle(consumer->of_node, "apple,pmc-interface", 0); + struct apple_pmc_domain *dom, *found = NULL; + struct platform_device *pdev; + struct apple_pmc *pmc = NULL; + + if (!np) + return NULL; + pdev = of_find_device_by_node(np->parent); + if (pdev && pdev->dev.driver == &apple_pmc_driver.driver) + pmc = platform_get_drvdata(pdev); + if (pmc) + list_for_each_entry(dom, &pmc->domains, list) + if (dom->np == np && dom->consumer_switched) + found = dom; + if (pdev) + put_device(&pdev->dev); + of_node_put(np); + return found; +} + +/* Whether apple_pmc_interface_consumer_off() can run for @consumer now, changing nothing. */ +int apple_pmc_interface_consumer_check(struct device *consumer) +{ + struct apple_pmc_domain *dom = apple_pmc_consumer_interface(consumer); + unsigned long flags; + int ret; + + if (!dom) + return -ENODEV; + raw_spin_lock_irqsave(&dom->pmc->lock, flags); + ret = dom->consumer_off ? -EALREADY : 0; + raw_spin_unlock_irqrestore(&dom->pmc->lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(apple_pmc_interface_consumer_check); + +int apple_pmc_interface_consumer_off(struct device *consumer) +{ + struct apple_pmc_domain *dom = apple_pmc_consumer_interface(consumer); + + return dom ? apple_pmc_interface_consumer_set(dom, false) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_pmc_interface_consumer_off); + +int apple_pmc_interface_consumer_on(struct device *consumer) +{ + struct apple_pmc_domain *dom = apple_pmc_consumer_interface(consumer); + + return dom ? apple_pmc_interface_consumer_set(dom, true) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_pmc_interface_consumer_on); + static int apple_pmc_domain_power_on(struct generic_pm_domain *genpd) { struct apple_pmc_domain *dom = genpd_to_apple_pmc_domain(genpd); @@ -794,6 +903,8 @@ static int apple_pmc_domain_power_off(struct generic_pm_domain *genpd) static void apple_pmc_domain_free(struct apple_pmc_domain *dom) { + if (dom->consumer_switched) + goto free; if (dom->provider) of_genpd_del_provider(dom->np); if (pm_genpd_remove(&dom->genpd)) { @@ -802,6 +913,7 @@ static void apple_pmc_domain_free(struct apple_pmc_domain *dom) dom->genpd.name); return; } +free: of_node_put(dom->np); kfree(dom->genpd.name); kfree(dom); @@ -1011,6 +1123,15 @@ static int apple_pmc_interface_add(struct apple_pmc *pmc, struct device_node *np return -ENOMEM; } + /* Its consumer clears and restores its bits: no genpd domain. */ + dom->consumer_switched = of_property_read_bool(np, "apple,consumer-switched"); + if (dom->consumer_switched) { + list_add_tail(&dom->list, &pmc->domains); + pmc->bwr_bits |= BIT(bwr); + pmc->boost_bits |= BIT(boost); + return 0; + } + ret = apple_pmc_interface_init(pmc, dom); if (ret) { of_node_put(dom->np); @@ -1280,7 +1401,9 @@ static int apple_pmc_probe(struct platform_device *pdev) } for_each_available_child_of_node(np, child) { - if (!of_property_present(child, "#power-domain-cells")) + /* A consumer-switched interface is no power domain, but still ours. */ + if (!of_property_present(child, "#power-domain-cells") && + !of_property_read_bool(child, "apple,consumer-switched")) continue; if (of_property_present(child, "apple,rail")) ret = apple_pmc_floor_add(pmc, child); diff --git a/include/linux/soc/apple/pmc.h b/include/linux/soc/apple/pmc.h index be391b83d9752..da0635015f52d 100644 --- a/include/linux/soc/apple/pmc.h +++ b/include/linux/soc/apple/pmc.h @@ -26,7 +26,30 @@ bool apple_pmc_voter_enabled(struct device *pmc, unsigned int agent, u32 apple_pmc_floor_read(struct device *pmc, unsigned int agent); int apple_pmc_floor_update(struct device *pmc, unsigned int agent, u32 mask, u32 value); +/* + * Clear, and later restore, the display pipe interface enables named by + * @consumer's apple,pmc-interface (an apple,consumer-switched interface). + * The check says, changing nothing, whether they can be cleared now. + */ +int apple_pmc_interface_consumer_check(struct device *consumer); +int apple_pmc_interface_consumer_off(struct device *consumer); +int apple_pmc_interface_consumer_on(struct device *consumer); #else +static inline int apple_pmc_interface_consumer_check(struct device *consumer) +{ + return -EOPNOTSUPP; +} + +static inline int apple_pmc_interface_consumer_off(struct device *consumer) +{ + return -EOPNOTSUPP; +} + +static inline int apple_pmc_interface_consumer_on(struct device *consumer) +{ + return -EOPNOTSUPP; +} + static inline unsigned int apple_pmc_rail_count(struct device *pmc) { return 0; From 6fde3b9bb23974eb2b86e723aa74edbbb0fedf24 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:02:08 +0100 Subject: [PATCH 241/342] soc: apple: pmp-display: let the J713 DCP release its DISP vote The J713 DCP takes its PMP DISP vote (power command 0x0f, logical device 8, state 1) when it activates, and the vote is held until reboot. macOS releases it after stopping the DCP and before powering the display domains down, and takes it again before powering them up. Add apple_pmp_j713_display_put(): the same power command with state 0, sent through the PMP owner's serialized request path (which consumes the exact reply), after which apple_pmp_j713_display_get() takes the vote again. The Rust owner forwards the release word to apple_pmp_set_device_power(), which already handles state 0. One request is in flight at a time, as before. A release that was not transmitted leaves the vote held; one whose outcome is unknown leaves it neither held nor available again, so the display cannot come back up on a vote that may be gone. Other accepted votes are kept. apple_pmp_j713_display_check_release() says, changing nothing, whether the vote can be released now and taken again later: held, nothing in flight, and admission open, as the later get is a new request and a failed untagged request closes admission. The DCP asks before it powers down. Host test: release and retake, a release with nothing held, one while another request is pending, one that was not sent and one without a reply, and the release check, also with admission closed by another request. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/soc/apple/pmp-display.c | 132 +++++++++++++++++- drivers/soc/apple/pmp.rs | 2 + include/linux/soc/apple/pmp-display.h | 9 +- .../drivers/gpu/apple-dcp/m4-error-paths.py | 45 +++++- 4 files changed, 178 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/pmp-display.c b/drivers/soc/apple/pmp-display.c index fed0b13bdfe83..b32e155ec09f0 100644 --- a/drivers/soc/apple/pmp-display.c +++ b/drivers/soc/apple/pmp-display.c @@ -24,6 +24,8 @@ /* AGX: command 0x0f, logical device 5, state 1. The reply carries no tag. */ #define PMP_AGX_REQUEST 0x0020f50100000000ULL #define PMP_DISP_REQUEST 0x0020f80100000000ULL +/* DISP, state 0: released while its DCP has powered the display domains down. */ +#define PMP_DISP_RELEASE 0x0020f80000000000ULL #define PMP_POWER_REPLY 0x0021000000000000ULL #define PMP_ENDPOINT 0x20 @@ -41,6 +43,8 @@ struct pmp_power_vote { /* A failed PMP owner invalidates every accepted vote as well. */ int provider_error; enum pmp_power_kind pending; + /* The pending request releases its vote rather than taking it. */ + bool releasing; bool held[PMP_POWER_COUNT]; }; @@ -48,7 +52,11 @@ static void pmp_vote_fail(struct pmp_power_vote *s, int error) { if (!s->error) s->error = error < 0 ? error : -EIO; + /* A release with an unknown outcome no longer counts as held. */ + if (s->pending && s->releasing) + s->held[s->pending] = false; s->pending = PMP_POWER_NONE; + s->releasing = false; } /* The Rust owner latches every ambiguous transaction as a provider failure. @@ -57,10 +65,12 @@ static void pmp_vote_fail(struct pmp_power_vote *s, int error) */ static void pmp_vote_send_failed(struct pmp_power_vote *s) { - if (s->provider_error) + if (s->provider_error) { pmp_vote_fail(s, s->provider_error); - else + } else { s->pending = PMP_POWER_NONE; + s->releasing = false; + } } /* One means send the request, zero means the same retained vote is held. */ @@ -80,6 +90,52 @@ static int pmp_vote_begin(struct pmp_power_vote *s, enum pmp_power_kind kind) return 1; } +/* One means send the release, zero means the vote is not held. */ +static int pmp_vote_begin_release(struct pmp_power_vote *s, enum pmp_power_kind kind) +{ + if (kind <= PMP_POWER_NONE || kind >= PMP_POWER_COUNT) + return -EINVAL; + if (s->provider_error) + return s->provider_error; + if (!s->held[kind]) + return 0; + if (s->error) + return s->error; + if (s->pending) + return -EBUSY; + s->pending = kind; + s->releasing = true; + return 1; +} + +/* + * Whether a vote can be released now and taken again later, changing + * nothing: held, no request in flight, and admission open (a failed untagged + * request closes it, and the later get is a new request). + */ +static int pmp_vote_check_release(struct pmp_power_vote *s, enum pmp_power_kind kind) +{ + if (kind <= PMP_POWER_NONE || kind >= PMP_POWER_COUNT) + return -EINVAL; + if (s->provider_error) + return s->provider_error; + if (!s->held[kind]) + return -ENODEV; + if (s->error) + return s->error; + return s->pending ? -EBUSY : 0; +} + +/* Released, or the outcome is unknown and admission is closed. */ +static int pmp_vote_finish_release(struct pmp_power_vote *s, enum pmp_power_kind kind) +{ + if (s->provider_error) + return s->provider_error; + if (s->pending == kind && s->releasing) + pmp_vote_fail(s, -ETIMEDOUT); + return s->held[kind] || s->error ? s->error ?: -EIO : 0; +} + /* Accepted votes are retained even if a different untagged request fails. */ static int pmp_vote_check(struct pmp_power_vote *s, enum pmp_power_kind kind) { @@ -110,8 +166,9 @@ static void pmp_vote_reply(struct pmp_power_vote *s, u8 endpoint, u64 word) pmp_vote_fail(s, -EPROTO); return; } - s->held[s->pending] = true; + s->held[s->pending] = !s->releasing; s->pending = PMP_POWER_NONE; + s->releasing = false; } static inline bool j713_disp_table(const void *data, size_t size) @@ -338,7 +395,7 @@ static int pmp_power_prepare(struct device *consumer, enum pmp_power_kind kind) return ret; } -static int pmp_power_check(struct device *consumer, enum pmp_power_kind kind) +static int pmp_power_check(struct device *consumer, enum pmp_power_kind kind, bool release) { struct apple_pmp_display *p = pmp_power_consumer(consumer, kind); unsigned long flags; @@ -347,7 +404,7 @@ static int pmp_power_check(struct device *consumer, enum pmp_power_kind kind) if (IS_ERR(p)) return PTR_ERR(p); spin_lock_irqsave(&p->lock, flags); - ret = pmp_vote_check(&p->vote, kind); + ret = release ? pmp_vote_check_release(&p->vote, kind) : pmp_vote_check(&p->vote, kind); spin_unlock_irqrestore(&p->lock, flags); return ret; } @@ -405,6 +462,55 @@ static int pmp_power_get(struct device *consumer, enum pmp_power_kind kind) return ret; } +/* + * Release the DISP vote while the consumer has powered the display domains + * down; apple_pmp_j713_display_get() takes it again before power-up. An + * ambiguous release closes admission: the vote is then neither held nor + * taken again. + */ +static int pmp_power_put(struct device *consumer, enum pmp_power_kind kind) +{ + struct apple_pmp_display *p = pmp_power_consumer(consumer, kind); + unsigned long flags; + int ret; + + if (IS_ERR(p)) + return PTR_ERR(p); + if (kind != PMP_POWER_DISP) + return -EINVAL; + device_lock(p->dev); + mutex_lock(&p->request); + if (p->dev->driver != p->driver || !dev_get_drvdata(p->dev)) { + ret = -ENODEV; + apple_pmp_display_fail(p, ret); + goto out; + } + spin_lock_irqsave(&p->lock, flags); + reinit_completion(&p->reply); + ret = pmp_vote_begin_release(&p->vote, kind); + spin_unlock_irqrestore(&p->lock, flags); + if (ret <= 0) + goto out; + ret = p->send(p->cookie, PMP_DISP_RELEASE); + if (ret) { + spin_lock_irqsave(&p->lock, flags); + pmp_vote_send_failed(&p->vote); + spin_unlock_irqrestore(&p->lock, flags); + goto out; + } + spin_lock_irqsave(&p->lock, flags); + pmp_vote_reply(&p->vote, PMP_ENDPOINT, PMP_POWER_REPLY); + ret = pmp_vote_finish_release(&p->vote, kind); + spin_unlock_irqrestore(&p->lock, flags); + if (!ret) + dev_dbg(p->dev, "Retained DISP vote released: request=%016llx\n", + PMP_DISP_RELEASE); +out: + mutex_unlock(&p->request); + device_unlock(p->dev); + return ret; +} + /* Probe creates the retained supplier links; get/check never change owners. */ int apple_pmp_j713_display_prepare(struct device *consumer) { @@ -420,13 +526,19 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_prepare); int apple_pmp_j713_display_check(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_DISP) : -ENODEV; + return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_DISP, false) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_display_check); +int apple_pmp_j713_display_check_release(struct device *consumer) +{ + return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_DISP, true) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_pmp_j713_display_check_release); + int apple_pmp_j713_gpu_check(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_AGX) : -ENODEV; + return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_AGX, false) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_check); @@ -436,6 +548,12 @@ int apple_pmp_j713_display_get(struct device *consumer) } EXPORT_SYMBOL_GPL(apple_pmp_j713_display_get); +int apple_pmp_j713_display_put(struct device *consumer) +{ + return apple_pmp_j713_board() ? pmp_power_put(consumer, PMP_POWER_DISP) : -ENODEV; +} +EXPORT_SYMBOL_GPL(apple_pmp_j713_display_put); + int apple_pmp_j713_gpu_get(struct device *consumer) { return apple_pmp_j713_board() ? pmp_power_get(consumer, PMP_POWER_AGX) : -ENODEV; diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index 2212509efd82c..39cc8821e0ba4 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -487,6 +487,8 @@ unsafe extern "C" fn display_send(cookie: *const kernel::ffi::c_void, word: u64) match word { 0x0020f50100000000 => unsafe { bindings::apple_pmp_set_device_power(0x0f, 5, 1) }, 0x0020f80100000000 => unsafe { bindings::apple_pmp_set_device_power(0x0f, 8, 1) }, + // DISP released while its DCP has powered the display domains down. + 0x0020f80000000000 => unsafe { bindings::apple_pmp_set_device_power(0x0f, 8, 0) }, _ => EINVAL.to_errno(), } } diff --git a/include/linux/soc/apple/pmp-display.h b/include/linux/soc/apple/pmp-display.h index 7db16206d4e8a..e65effb337aa8 100644 --- a/include/linux/soc/apple/pmp-display.h +++ b/include/linux/soc/apple/pmp-display.h @@ -31,12 +31,17 @@ void apple_pmp_display_fail(struct apple_pmp_display *display, int error); struct apple_pmp_display *apple_pmp_display_bound_owner(struct device *dev); /* J713 votes share the existing PMP owner's untagged request stream. - * Prepare is probe-only; accepted DISP/AGX votes and supplier links persist - * until reboot. + * Prepare is probe-only; supplier links persist until reboot, and so do + * accepted votes, except that the DCP releases its DISP vote while it has + * powered the display domains down (put) and takes it again (get). Before + * that it asks, changing nothing, whether the vote can be released now and + * taken again later (check_release). */ int apple_pmp_j713_display_prepare(struct device *consumer); int apple_pmp_j713_display_get(struct device *consumer); +int apple_pmp_j713_display_put(struct device *consumer); int apple_pmp_j713_display_check(struct device *consumer); +int apple_pmp_j713_display_check_release(struct device *consumer); int apple_pmp_j713_gpu_prepare(struct device *consumer); int apple_pmp_j713_gpu_get(struct device *consumer); int apple_pmp_j713_gpu_check(struct device *consumer); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/m4-error-paths.py b/tools/testing/selftests/drivers/gpu/apple-dcp/m4-error-paths.py index e57b10a738947..027eec2ecbc1a 100755 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/m4-error-paths.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/m4-error-paths.py @@ -59,7 +59,8 @@ def main(): votes += definition(pmp, 'enum pmp_power_kind {') + ';\n' votes += definition(pmp, 'struct pmp_power_vote {') + ';\n' for function in ('static void pmp_vote_fail(', 'static void pmp_vote_send_failed(', - 'static int pmp_vote_begin(', + 'static int pmp_vote_begin(', 'static int pmp_vote_begin_release(', + 'static int pmp_vote_check_release(', 'static int pmp_vote_finish_release(', 'static int pmp_vote_check(', 'static int pmp_vote_finish(', 'static void pmp_vote_reply('): votes += definition(pmp, function) + '\n' @@ -111,6 +112,48 @@ def main(): pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); assert(pmp_vote_check(&s, PMP_POWER_DISP) == 0); assert(pmp_vote_begin(&s, PMP_POWER_AGX) == -EPROTO); + + /* The DCP releases DISP while its domains are down and takes it again. */ + s = (struct pmp_power_vote){0}; + assert(pmp_vote_check_release(&s, PMP_POWER_DISP) == -ENODEV); /* not held */ + assert(pmp_vote_begin_release(&s, PMP_POWER_DISP) == 0); /* not held */ + assert(pmp_vote_begin(&s, PMP_POWER_DISP) == 1); + assert(pmp_vote_check_release(&s, PMP_POWER_DISP) == -ENODEV); /* still pending */ + pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); + assert(pmp_vote_check_release(&s, PMP_POWER_DISP) == 0); + assert(pmp_vote_begin_release(&s, PMP_POWER_DISP) == 1); + pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); + assert(pmp_vote_finish_release(&s, PMP_POWER_DISP) == 0); + assert(!s.held[PMP_POWER_DISP] && !s.releasing && !s.error); + assert(pmp_vote_check(&s, PMP_POWER_DISP) == -ENODEV); + assert(pmp_vote_begin(&s, PMP_POWER_DISP) == 1); + pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); + assert(pmp_vote_finish(&s, PMP_POWER_DISP) == 0); + /* One request at a time. */ + assert(pmp_vote_begin(&s, PMP_POWER_AGX) == 1); + assert(pmp_vote_check_release(&s, PMP_POWER_DISP) == -EBUSY); + assert(pmp_vote_begin_release(&s, PMP_POWER_DISP) == -EBUSY); + pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); + assert(s.held[PMP_POWER_AGX] && s.held[PMP_POWER_DISP]); + /* Not transmitted: the vote is still held. */ + assert(pmp_vote_begin_release(&s, PMP_POWER_DISP) == 1); + pmp_vote_send_failed(&s); + assert(s.held[PMP_POWER_DISP] && !s.releasing && !s.error); + /* No reply: neither held nor taken again; AGX stays held. */ + assert(pmp_vote_begin_release(&s, PMP_POWER_DISP) == 1); + assert(pmp_vote_finish_release(&s, PMP_POWER_DISP) == -ETIMEDOUT); + assert(!s.held[PMP_POWER_DISP] && !s.releasing); + assert(pmp_vote_begin(&s, PMP_POWER_DISP) == -ETIMEDOUT); + assert(pmp_vote_check(&s, PMP_POWER_AGX) == 0); + + /* Admission closed by another request: DISP stays held, but is not released. */ + s = (struct pmp_power_vote){0}; + assert(pmp_vote_begin(&s, PMP_POWER_DISP) == 1); + pmp_vote_reply(&s, PMP_ENDPOINT, PMP_POWER_REPLY); + assert(pmp_vote_begin(&s, PMP_POWER_AGX) == 1); + assert(pmp_vote_finish(&s, PMP_POWER_AGX) == -ETIMEDOUT); + assert(pmp_vote_check(&s, PMP_POWER_DISP) == 0); + assert(pmp_vote_check_release(&s, PMP_POWER_DISP) == -ETIMEDOUT); return 0; } ''' From c94d8ff4cf90d79156b925cecacc5002946d7059 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:37:47 +0100 Subject: [PATCH 242/342] soc: apple: rtkit: wake a co-processor with its retained session apple_rtkit_idle() leaves a co-processor's firmware, endpoints and shared buffers in place, but waking it again goes through INIT and starts the system endpoints anew. The J713 DCP is to stop its CPU after the idle handshake, power its domains down and start the CPU again later. Its firmware then says HELLO by itself, and macOS answers the endpoint map with the endpoints that are still running, without INIT and without starting any endpoint. Add apple_rtkit_wake_retained(). From the idle state, with RX held by the caller since the idle, it restores the mailbox (apple_mbox_restore(), as its power domain may have been off), resumes RX and lets the caller start the CPU. While it runs, the endpoint map is answered with the endpoints started in this session, which RTKit now records, and nothing is started again; a started endpoint missing from the map fails the wake. A co-processor that first reports QUIESCED gets one ON request, any other IOP state before ON fails the wake. The usual boot wait then requires IOP ON and requests AP ON. Nothing is allocated, freed or reinitialized. A signal to the caller does not interrupt the wake's waits: the CPU is running by then, and nothing would undo that. An unexpected IOP state ends whichever wait the wake is in, the map or IOP ON after it. A last map part cannot echo endpoint 32 * base, as bit 0 of the reply is also MORE: such a wake fails. The DCP's map has two parts, with its endpoint 0 in the first. Also accept management message 0xc, which some co-processors send once idle after the IOP IDLE request, instead of warning about it. apple_mbox_restore() sets the mailbox-level enables of a started mailbox again, as apple_mbox_start() does. Host test: the retained endpoint map replies for the DCP's map, a missing started endpoint, a last part that cannot be echoed, QUIESCED before ON, an unexpected state before and after the map, the unchanged acknowledgment outside a retained wake, and which waits a signal can interrupt. The OSLog test's RTKit stub gains the started endpoint bitmap. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/soc/apple/mailbox.c | 60 +++++--- drivers/soc/apple/rtkit-internal.h | 9 ++ drivers/soc/apple/rtkit.c | 147 +++++++++++++++++++- include/linux/soc/apple/mailbox.h | 1 + include/linux/soc/apple/rtkit.h | 8 ++ tools/asahi/rtkit-oslog-tests.py | 2 +- tools/asahi/rtkit-retained-tests.py | 203 ++++++++++++++++++++++++++++ tools/asahi/run-host-tests.py | 1 + 8 files changed, 410 insertions(+), 21 deletions(-) create mode 100755 tools/asahi/rtkit-retained-tests.py diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index c13c03f9d92ab..21ae3a51f9966 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -957,25 +957,10 @@ static void apple_mbox_v8_rx_stop(struct apple_mbox *mbox) cancel_delayed_work_sync(&priv->rx_poll_work); } -int apple_mbox_start(struct apple_mbox *mbox) +/* The mailbox-level enables, which the mailbox's power domain does not keep. */ +static void apple_mbox_enable_hw(struct apple_mbox *mbox) { u32 control; - int ret = 0; - - mutex_lock(&mbox->lifecycle_lock); - if (mbox->removing) { - ret = -ENODEV; - goto out_unlock; - } - if (mbox->active) - goto out_unlock; - - ret = pm_runtime_resume_and_get(mbox->dev); - if (ret) { - dev_err(mbox->dev, "mailbox start: runtime resume failed: %d\n", ret); - apple_mbox_clear_resume_error(mbox); - goto out_unlock; - } if (mbox->hw->ap_initializes_mailboxes) { /* The primary T8140 outbox requires its enable bit before use. */ @@ -996,6 +981,28 @@ int apple_mbox_start(struct apple_mbox *mbox) mbox->hw->irq_bit_send_empty, mbox->regs + mbox->hw->irq_enable); } +} + +int apple_mbox_start(struct apple_mbox *mbox) +{ + int ret = 0; + + mutex_lock(&mbox->lifecycle_lock); + if (mbox->removing) { + ret = -ENODEV; + goto out_unlock; + } + if (mbox->active) + goto out_unlock; + + ret = pm_runtime_resume_and_get(mbox->dev); + if (ret) { + dev_err(mbox->dev, "mailbox start: runtime resume failed: %d\n", ret); + apple_mbox_clear_resume_error(mbox); + goto out_unlock; + } + + apple_mbox_enable_hw(mbox); if (apple_mbox_has_rx_poller(mbox)) { WRITE_ONCE(mbox->active, true); @@ -1036,6 +1043,25 @@ void apple_mbox_stop(struct apple_mbox *mbox) } EXPORT_SYMBOL(apple_mbox_stop); +/* + * The mailbox's power domain was off while it stayed started (its consumer + * powered its co-processor down and up again around it): set the + * mailbox-level enables again before the co-processor runs. + */ +int apple_mbox_restore(struct apple_mbox *mbox) +{ + int ret = 0; + + mutex_lock(&mbox->lifecycle_lock); + if (mbox->removing || !mbox->active) + ret = -ENODEV; + else + apple_mbox_enable_hw(mbox); + mutex_unlock(&mbox->lifecycle_lock); + return ret; +} +EXPORT_SYMBOL(apple_mbox_restore); + void apple_mbox_hold_rx(struct apple_mbox *mbox) { disable_irq(mbox->irq_recv_not_empty); diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h index 2ad4d96bec768..577f68fad529c 100644 --- a/drivers/soc/apple/rtkit-internal.h +++ b/drivers/soc/apple/rtkit-internal.h @@ -65,6 +65,15 @@ struct apple_rtkit { struct work_struct sync_ack_work; DECLARE_BITMAP(endpoints, APPLE_RTKIT_MAX_ENDPOINTS); + /* Endpoints started in this session; kept by a retained wake. */ + DECLARE_BITMAP(started, APPLE_RTKIT_MAX_ENDPOINTS); + /* + * apple_rtkit_wake_retained() in progress: the endpoint map is answered + * with the started endpoints and nothing is started again; a QUIESCED + * report gets one ON request. + */ + bool retained_wake; + bool retained_on_sent; struct apple_rtkit_shmem ioreport_buffer; struct apple_rtkit_shmem coreanalytics_buffer; diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 3b821415d54d8..b6b27a713442a 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -45,6 +45,8 @@ enum { APPLE_RTKIT_MGMT_EPMAP_REPLY = 8, APPLE_RTKIT_MGMT_SET_AP_PWR_STATE = 0xb, APPLE_RTKIT_MGMT_SET_AP_PWR_STATE_ACK = 0xb, + /* Sent by some co-processors once idle after an IOP IDLE request. */ + APPLE_RTKIT_MGMT_IDLE_NOTIFY = 0xc, }; #define APPLE_RTKIT_MGMT_HELLO_MINVER GENMASK_ULL(15, 0) @@ -229,6 +231,55 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) complete_all(&rtk->epmap_completion); } +/* + * Endpoint map of a retained wake: the endpoints and their buffers are still + * set up, so answer with the started endpoints of this part of the map, as + * the native retained wake does, and start nothing. A started endpoint that + * the firmware no longer offers fails the wake. + */ +static void apple_rtkit_management_rx_epmap_retained(struct apple_rtkit *rtk, u64 msg, + u32 base, unsigned long bitmap) +{ + unsigned long started = 0; + u64 reply; + int i; + + for (i = 0; i < 32 && 32 * base + i < APPLE_RTKIT_MAX_ENDPOINTS; i++) + if (test_bit(32 * base + i, rtk->started)) + started |= BIT(i); + if (started & ~bitmap) { + dev_err(rtk->dev, "RTKit: retained endpoints %#lx missing from map %#lx (base %u)\n", + started & ~bitmap, bitmap, base); + rtk->boot_result = -EPROTO; + complete_all(&rtk->epmap_completion); + return; + } + /* + * Bit 0 of a reply is also MORE: a last part cannot echo endpoint + * 32 * base there. The DCP's map has two parts, and its endpoint 0 + * (management) is in the first. + */ + if ((msg & APPLE_RTKIT_MGMT_EPMAP_LAST) && (started & APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE)) { + dev_err(rtk->dev, "RTKit: retained endpoint %u cannot be echoed in the last map part\n", + 32 * base); + rtk->boot_result = -EPROTO; + complete_all(&rtk->epmap_completion); + return; + } + + reply = FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, base) | started; + if (msg & APPLE_RTKIT_MGMT_EPMAP_LAST) + reply |= APPLE_RTKIT_MGMT_EPMAP_LAST; + else + reply |= APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE; + apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_EPMAP_REPLY, reply); + + if (msg & APPLE_RTKIT_MGMT_EPMAP_LAST) { + rtk->boot_result = 0; + complete_all(&rtk->epmap_completion); + } +} + static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) { int i, ep, ret; @@ -261,6 +312,11 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) } } + if (rtk->retained_wake) { + apple_rtkit_management_rx_epmap_retained(rtk, msg, base, bitmap); + return; + } + reply = FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, base); if (msg & APPLE_RTKIT_MGMT_EPMAP_LAST) reply |= APPLE_RTKIT_MGMT_EPMAP_LAST; @@ -330,6 +386,28 @@ static void apple_rtkit_management_rx_iop_pwr_ack(struct apple_rtkit *rtk, rtk->iop_power_state, new_state); rtk->iop_power_state = new_state; + /* + * A retained wake: a co-processor may report QUIESCED when it starts + * running and wait for an ON request before its HELLO. Ask once, and + * wait for ON. + */ + if (rtk->retained_wake && new_state != APPLE_RTKIT_PWR_STATE_ON) { + if (new_state == APPLE_RTKIT_PWR_STATE_QUIESCED && !rtk->retained_on_sent) { + rtk->retained_on_sent = true; + apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE, + FIELD_PREP(APPLE_RTKIT_MGMT_PWR_STATE, + APPLE_RTKIT_PWR_STATE_ON)); + return; + } + dev_err(rtk->dev, "RTKit: unexpected IOP power state 0x%x on retained wake\n", + new_state); + /* Whichever wait the wake is in: the map, or IOP ON after it. */ + rtk->boot_result = -EPROTO; + complete_all(&rtk->epmap_completion); + complete_all(&rtk->iop_pwr_ack_completion); + return; + } + complete_all(&rtk->iop_pwr_ack_completion); } @@ -362,6 +440,9 @@ static void apple_rtkit_management_rx(struct apple_rtkit *rtk, u64 msg) case APPLE_RTKIT_MGMT_SET_AP_PWR_STATE_ACK: apple_rtkit_management_rx_ap_pwr_ack(rtk, msg); break; + case APPLE_RTKIT_MGMT_IDLE_NOTIFY: + dev_dbg(rtk->dev, "RTKit: co-processor idle\n"); + break; default: dev_warn( rtk->dev, @@ -1245,6 +1326,8 @@ int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint) endpoint); ret = apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_STARTEP, msg); } + if (!ret) + set_bit(endpoint, rtk->started); return ret; } EXPORT_SYMBOL_GPL(apple_rtkit_start_ep); @@ -1423,6 +1506,7 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints); + set_bit(APPLE_RTKIT_EP_MGMT, rtk->started); if (mbox_name) rtk->mbox = apple_mbox_get_byname(dev, mbox_name); @@ -1487,6 +1571,18 @@ EXPORT_SYMBOL_GPL(apple_rtkit_init_adopted); static int apple_rtkit_wait_for_completion(struct apple_rtkit *rtk, struct completion *c); +/* + * A retained wake is not interrupted by a signal to its caller: it has + * already started the co-processor's CPU, and nothing would undo that. + */ +static long apple_rtkit_wait_timeout(struct apple_rtkit *rtk, struct completion *c, + unsigned long timeout) +{ + if (READ_ONCE(rtk->retained_wake)) + return wait_for_completion_timeout(c, timeout); + return wait_for_completion_interruptible_timeout(c, timeout); +} + /* * apple,sync-syslog-ack (AsahiLinux/linux#607): the mailbox can leave * messages queued without another interrupt during bootstrap, so poll it @@ -1507,8 +1603,7 @@ static int apple_rtkit_wait(struct apple_rtkit *rtk, struct completion *c) if (ret < 0) return ret; - t = wait_for_completion_interruptible_timeout(c, - msecs_to_jiffies(10)); + t = apple_rtkit_wait_timeout(rtk, c, msecs_to_jiffies(10)); if (t < 0) return t; if (t > 0) @@ -1535,7 +1630,7 @@ static int apple_rtkit_wait_for_completion(struct apple_rtkit *rtk, unsigned long timeout = msecs_to_jiffies(rtk->handshake_timeout_ms); long t; - t = wait_for_completion_interruptible_timeout(c, timeout); + t = apple_rtkit_wait_timeout(rtk, c, timeout); if (t < 0) return t; else if (t == 0) @@ -1580,6 +1675,8 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk) bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints); + bitmap_zero(rtk->started, APPLE_RTKIT_MAX_ENDPOINTS); + set_bit(APPLE_RTKIT_EP_MGMT, rtk->started); reinit_completion(&rtk->epmap_completion); reinit_completion(&rtk->coreanalytics_completion); @@ -1697,6 +1794,9 @@ static int apple_rtkit_boot_common(struct apple_rtkit *rtk, bool early_ap_power) dev_err(rtk->dev, "RTKit: IOP power acknowledgment failed: %d\n", ret); return ret; } + /* A retained wake fails on any IOP state but ON (still 0 otherwise). */ + if (rtk->boot_result) + return rtk->boot_result; return early_ap_power ? 0 : apple_rtkit_set_ap_power_state(rtk, APPLE_RTKIT_PWR_STATE_ON); @@ -1831,6 +1931,47 @@ int apple_rtkit_wake_early_ap(struct apple_rtkit *rtk) } EXPORT_SYMBOL_GPL(apple_rtkit_wake_early_ap); +/* + * Wake a co-processor whose CPU was stopped after apple_rtkit_idle(), with + * its firmware, endpoints and shared buffers kept (and its power domain + * possibly off meanwhile). The caller holds RX since the idle; this restores + * the mailbox, resumes RX and calls @start, which starts the CPU. The + * firmware then says HELLO (possibly after reporting QUIESCED, which gets an + * ON request) and sends its endpoint map, answered with the started + * endpoints; no INIT is sent and nothing is started or allocated again. + * Then IOP ON is awaited and AP ON requested, as for any boot. + */ +int apple_rtkit_wake_retained(struct apple_rtkit *rtk, int (*start)(void *), void *ctx) +{ + int ret; + + if (apple_rtkit_is_running(rtk) || rtk->crashed || rtk->shutting_down || + rtk->iop_power_state != APPLE_RTKIT_PWR_STATE_IDLE || !start) + return -EINVAL; + + reinit_completion(&rtk->epmap_completion); + reinit_completion(&rtk->iop_pwr_ack_completion); + reinit_completion(&rtk->ap_pwr_ack_completion); + rtk->boot_result = -EINPROGRESS; + rtk->retained_on_sent = false; + WRITE_ONCE(rtk->retained_wake, true); + + ret = apple_mbox_restore(rtk->mbox); + if (ret) + goto out; + apple_rtkit_resume_rx(rtk); + ret = start(ctx); + if (ret) + goto out; + ret = apple_rtkit_boot_common(rtk, false); +out: + WRITE_ONCE(rtk->retained_wake, false); + if (ret) + dev_err(rtk->dev, "RTKit: retained wake failed: %d\n", ret); + return ret; +} +EXPORT_SYMBOL_GPL(apple_rtkit_wake_retained); + void apple_rtkit_free(struct apple_rtkit *rtk) { apple_rtkit_stop_rx(rtk); diff --git a/include/linux/soc/apple/mailbox.h b/include/linux/soc/apple/mailbox.h index 7a07772cc5967..d7fc9dd4134f1 100644 --- a/include/linux/soc/apple/mailbox.h +++ b/include/linux/soc/apple/mailbox.h @@ -100,6 +100,7 @@ struct apple_mbox *apple_mbox_get_byname(struct device *dev, const char *name); int apple_mbox_start(struct apple_mbox *mbox); void apple_mbox_stop(struct apple_mbox *mbox); +int apple_mbox_restore(struct apple_mbox *mbox); int apple_mbox_poll(struct apple_mbox *mbox); /* * Leave received messages in the hardware FIFO, without an interrupt, until diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 86cdb8426488d..ac646240f8587 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -234,6 +234,14 @@ int apple_rtkit_wake(struct apple_rtkit *rtk); /* Wake helpers which require AP readiness before their IOP power acknowledgment. */ int apple_rtkit_wake_early_ap(struct apple_rtkit *rtk); +/* + * Wake a co-processor stopped after apple_rtkit_idle() with its firmware, + * endpoints and buffers kept: restore the mailbox, resume RX, call @start to + * start its CPU, then complete HELLO, the endpoint map (with the started + * endpoints, no INIT and no new endpoint start) and IOP/AP ON. + */ +int apple_rtkit_wake_retained(struct apple_rtkit *rtk, int (*start)(void *), void *ctx); + /* * Shutdown the co-processor */ diff --git a/tools/asahi/rtkit-oslog-tests.py b/tools/asahi/rtkit-oslog-tests.py index 160c163758d54..87c3654fb8328 100644 --- a/tools/asahi/rtkit-oslog-tests.py +++ b/tools/asahi/rtkit-oslog-tests.py @@ -49,7 +49,7 @@ def function(source, name): int sync_ack_fifo; bool sync_syslog_ack, oslog_inherited, syslog_inherited, crashlog_inherited, crashed, shutting_down; unsigned iop_power_state, ap_power_state; - unsigned long endpoints[4]; + unsigned long endpoints[4], started[4]; char *syslog_msg_buffer; size_t syslog_n_entries, syslog_msg_size; int epmap_completion, iop_pwr_ack_completion, ap_pwr_ack_completion, coreanalytics_completion; diff --git a/tools/asahi/rtkit-retained-tests.py b/tools/asahi/rtkit-retained-tests.py new file mode 100755 index 0000000000000..b79a9cd542bd2 --- /dev/null +++ b/tools/asahi/rtkit-retained-tests.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Check the retained-wake endpoint map reply and IOP power acknowledgment.""" +import argparse +from pathlib import Path +import re +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +DRIVER = 'drivers/soc/apple/rtkit.c' + + +def function(source, name): + match = re.search(r'^(?:static )?(?:void|int|long) ' + name + r'\(', source, re.M) + assert match, name + opening = source.index('{', match.end()) + depth, end = 1, opening + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[match.start():end] + '\n' + + +def constants(source): + out = [] + for line in source.splitlines(): + if re.match(r'#define APPLE_RTKIT_MGMT_(TYPE|EPMAP_\w+|PWR_STATE)\b', line): + out.append(line) + enum = re.search(r'enum \{\n\tAPPLE_RTKIT_MGMT_HELLO = 1,.*?\n\};', source, re.S) + states = re.search(r'enum \{\n\tAPPLE_RTKIT_PWR_STATE_OFF.*?\n\};', source, re.S) + assert enum and states + return '\n'.join(out) + '\n' + enum.group(0) + '\n' + states.group(0) + '\n' + + +PREFIX = r''' +#include +#include +#include +#include +#include +typedef uint8_t u8; typedef uint32_t u32; typedef uint64_t u64; +#define BIT(n) (1UL << (n)) +#define BIT_ULL(n) (1ULL << (n)) +#define GENMASK_ULL(h,l) ((~0ULL << (l)) & (~0ULL >> (63-(h)))) +#define FIELD_GET(m,v) (((v) & (m)) >> __builtin_ctzll(m)) +#define FIELD_PREP(m,v) (((u64)(v) << __builtin_ctzll(m)) & (m)) +#define APPLE_RTKIT_MAX_ENDPOINTS 256 +#define dev_err(...) ((void)0) +#define dev_dbg(...) ((void)0) +struct apple_rtkit { + void *dev; + unsigned long started[APPLE_RTKIT_MAX_ENDPOINTS / 64]; + bool retained_wake, retained_on_sent; + int boot_result; + unsigned int iop_power_state; + int epmap_completion, iop_pwr_ack_completion; +}; +static bool test_bit(unsigned n, const unsigned long *b) { return b[n / 64] >> (n % 64) & 1; } +static void set_bit(unsigned n, unsigned long *b) { b[n / 64] |= 1UL << (n % 64); } +static void complete_all(int *c) { (*c)++; } +static unsigned sent; +static u8 sent_type; +static u64 sent_data; +static int apple_rtkit_management_send(struct apple_rtkit *rtk, u8 type, u64 data) +{ + (void)rtk; sent++; sent_type = type; sent_data = data; return 0; +} +/* A signal is pending for every interruptible wait. */ +#define ERESTARTSYS 512 +#define READ_ONCE(x) (x) +struct completion { int unused; }; +static unsigned waited_uninterruptible, waited_interruptible; +static unsigned long wait_for_completion_timeout(struct completion *c, unsigned long t) +{ + (void)c; waited_uninterruptible++; return t; +} +static long wait_for_completion_interruptible_timeout(struct completion *c, unsigned long t) +{ + (void)c; (void)t; waited_interruptible++; return -ERESTARTSYS; +} +''' + +MAIN = r''' +static struct apple_rtkit fresh(void) +{ + struct apple_rtkit r = { .retained_wake = true, .boot_result = -EINPROGRESS }; + + /* Management, syslog, crashlog, debug, ioreport, oslog, tracekit, DCP 0x37. */ + for (unsigned ep = 0; ep < 11; ep++) + if ((0x51dUL >> ep) & 1) + set_bit(ep, r.started); + set_bit(0x37, r.started); + sent = 0; + return r; +} + +int main(void) +{ + struct apple_rtkit r = fresh(); + u64 map0 = FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, 0) | 0x51d; + u64 map1 = APPLE_RTKIT_MGMT_EPMAP_LAST | FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, 1) | + 0x00867f3f; + + /* Each part of the map: exactly the started endpoints, MORE until the last. */ + apple_rtkit_management_rx_epmap_retained(&r, map0, 0, 0x51d); + assert(sent == 1 && sent_type == APPLE_RTKIT_MGMT_EPMAP_REPLY); + assert(sent_data == (0x51d | APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE)); + assert(r.epmap_completion == 0 && r.boot_result == -EINPROGRESS); + apple_rtkit_management_rx_epmap_retained(&r, map1, 1, 0x00867f3f); + assert(sent == 2 && sent_data == (APPLE_RTKIT_MGMT_EPMAP_LAST | + FIELD_PREP(APPLE_RTKIT_MGMT_EPMAP_BASE, 1) | BIT(0x37 - 32))); + assert(r.epmap_completion == 1 && r.boot_result == 0); + + /* A started endpoint missing from the map fails the wake; nothing is sent. */ + r = fresh(); + apple_rtkit_management_rx_epmap_retained(&r, map1 & ~(u64)BIT(0x37 - 32), 1, + 0x00867f3f & ~BIT(0x37 - 32)); + assert(sent == 0 && r.boot_result == -EPROTO && r.epmap_completion == 1); + + /* QUIESCED gets one ON request, then ON completes. */ + r = fresh(); + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_QUIESCED); + assert(sent == 1 && sent_type == APPLE_RTKIT_MGMT_SET_IOP_PWR_STATE); + assert(sent_data == APPLE_RTKIT_PWR_STATE_ON && r.iop_pwr_ack_completion == 0); + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_ON); + assert(sent == 1 && r.iop_pwr_ack_completion == 1); + assert(r.iop_power_state == APPLE_RTKIT_PWR_STATE_ON); + + /* A last part cannot echo endpoint 32 * base: bit 0 is also MORE. */ + r = fresh(); + set_bit(32, r.started); + apple_rtkit_management_rx_epmap_retained(&r, map1, 1, 0x00867f3f); + assert(sent == 0 && r.boot_result == -EPROTO && r.epmap_completion == 1); + + /* + * A second QUIESCED, or any other state, fails the wake, before the map + * or while the wake waits for IOP ON after it. + */ + r = fresh(); + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_QUIESCED); + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_QUIESCED); + assert(sent == 1 && r.boot_result == -EPROTO); + assert(r.epmap_completion == 1 && r.iop_pwr_ack_completion == 1); + r = fresh(); + apple_rtkit_management_rx_epmap_retained(&r, map0, 0, 0x51d); + apple_rtkit_management_rx_epmap_retained(&r, map1, 1, 0x00867f3f); + assert(r.epmap_completion == 1 && r.boot_result == 0); + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_IDLE); + assert(r.boot_result == -EPROTO && r.iop_pwr_ack_completion == 1); + + /* Outside a retained wake every acknowledgment completes, as before. */ + r = fresh(); + r.retained_wake = false; + apple_rtkit_management_rx_iop_pwr_ack(&r, APPLE_RTKIT_PWR_STATE_QUIESCED); + assert(sent == 0 && r.iop_pwr_ack_completion == 1); + assert(r.iop_power_state == APPLE_RTKIT_PWR_STATE_QUIESCED); + + /* A retained wake waits through a signal; other waits stay interruptible. */ + struct completion c; + r = fresh(); + assert(apple_rtkit_wait_timeout(&r, &c, 7) == 7); + assert(waited_uninterruptible == 1 && waited_interruptible == 0); + r.retained_wake = false; + assert(apple_rtkit_wait_timeout(&r, &c, 7) == -ERESTARTSYS); + assert(waited_uninterruptible == 1 && waited_interruptible == 1); + + puts("PASS retained endpoint map replies, IOP acknowledgments and waits"); + return 0; +} +''' + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--out', type=Path, help='keep build and result files here') + parser.add_argument('--cc', default='cc') + args = parser.parse_args() + source = (ROOT / DRIVER).read_text() + code = PREFIX + constants(source) + code += function(source, 'apple_rtkit_management_rx_epmap_retained') + code += function(source, 'apple_rtkit_management_rx_iop_pwr_ack') + code += function(source, 'apple_rtkit_wait_timeout') + MAIN + + def run(out): + out.mkdir(parents=True, exist_ok=True) + cfile, exe = out / 'retained.c', out / 'retained' + cfile.write_text(code) + subprocess.run([args.cc, '-std=gnu11', '-O1', '-g', '-Wall', '-Wextra', '-Werror', + '-Wno-unused-parameter', '-fsanitize=address,undefined', + '-fno-sanitize-recover=all', str(cfile), '-o', str(exe)], check=True) + result = subprocess.run([str(exe)], capture_output=True, text=True) + print(result.stdout or result.stderr, end='') + return result.returncode + + if args.out: + return run(args.out) + with tempfile.TemporaryDirectory(prefix='rtkit-retained-') as out: + return run(Path(out)) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index b878404b2d9fa..2da6ddc68cd13 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -157,6 +157,7 @@ def mutations(flag, names, base, expect=KILL): 'qspi-nvram-tests.py': [(out('--output'), PASS)], 'rtkit-oslog-tests.py': [(out(), PASS)] + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), + 'rtkit-retained-tests.py': [(out(), PASS)], 't6030-clock-tests.py': [(out(), PASS)], 't6030-display-admission-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], 't6030-display-linkage-tests.py': [(out('--output') + ['--conf', '{conf}'], PASS)], From 82ed2d32df0911850f6e3cbe61344fd7f301da99 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:48:15 +0100 Subject: [PATCH 243/342] drm/apple: m4: power the internal DCP and its domains down while blanked On DPMS off the J713 internal display gets setPowerState(0) (A473), which stops its pipe, but the DCP keeps running and its CPU, frontend and system power domains stay on. macOS goes further for display sleep: it releases the AP link, idles RTKit, stops the DCP CPU and powers the three domains off, and on wake starts the CPU again on the retained firmware. Do the same once the display has been blanked for appledrm.power_gate_ms (0, the default, never), and before system sleep while blanked. First, changing nothing, ask every provider whether it can take part: both display DARTs, the PMP vote, the PMC interface and the PMGR states. If one cannot, the display just stays logically off. Then: A500, drain the callbacks, apple_rtkit_idle() and hold RX, stop the CPU (after its idle status), take in anything the firmware sent meanwhile (anything there fails the session, before a power-down), power down both display DARTs (streams off, power-down flush, clock protection off), release the PMP DISP vote, clear the PMC interface enables and power the consumer-switched CPU, frontend and system states off. The first frame afterwards reverses it before setPowerState(1), in macOS's order: domains, PMP vote, PMC enables, DARTs (state checked, streams back), then RTKit's retained wake, which restarts the CPU and gets HELLO, the endpoint map and IOP/AP ON without INIT, and the display preparation macOS sends (A414, A412). A frame cancels a power-down not yet started; a power-down under way finishes first. While the domains are down no register of the DCP, its mailbox or its DARTs is used: health checks, status and resume leave them alone, and resume leaves the display down until the next frame. Any failure fails the session, as other DCP failures do, but none refuses system sleep: the power-down is a saving, not a condition of sleep. Setting power_gate_ms to 0 also stops a power-down already scheduled. Only an internal J713 DCP whose node names its PMC interface (apple,pmc-interface) does this. debugfs iomfb_m4 shows the gate state, the number of power-downs and the last power-down and power-up times. On a J713 with power_gate_ms=3000, 204 power-downs and power-ups in one boot completed without an error, one of them started by a suspend 1.5 s after the blank: the display domains read back level 0 while off, stayed off across suspend-to-idle, and the display came back with a completed frame each time. Awake with DPMS off it draws about 15 mW less than setPowerState(0) alone (8 alternating pairs); one pair of suspend-to-idle runs differed by about 10 mW. It is a prerequisite for deeper SoC sleep with the display off. Host test: m4-dpms-retirement covers the power-down scheduling, its absence when not enabled, the power-up before setPowerState(1) and a power-up that fails; m4-power-gate the order of both sequences, a provider that refuses (nothing changes), a late firmware message (the session fails before any power-down) and power_gate_ms turned off after the blank. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- drivers/gpu/drm/apple/dcp.c | 4 +- drivers/gpu/drm/apple/iomfb_m4.c | 308 +++++++++++++++++- .../selftests/drivers/gpu/apple-dcp/m4.py | 194 +++++++++++ .../selftests/drivers/gpu/apple-dcp/run.py | 1 + 4 files changed, 503 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index f233c079997cc..d098c43dbe72b 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6683,7 +6683,9 @@ static int dcp_platform_suspend(struct device *dev) /* * T8132: setPowerState powers the display down; the coprocessor keeps - * running and its power domains stay on, as below. + * running and its power domains stay on, as below, unless the internal + * display is blanked with appledrm.power_gate_ms set: then the + * coprocessor and its domains are powered down too (iomfb_m4_suspend()). */ if (iomfb_is_m4(dcp)) { int ret = iomfb_m4_suspend(dcp); diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index 48b7179c439e4..b6b301a20ab20 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -24,11 +24,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -39,6 +41,8 @@ #include #include #include +#include +#include #include "afk.h" #include "dcp.h" @@ -82,6 +86,32 @@ module_param_cb(idle_cache_ms, &idle_cache_ms_ops, &idle_cache_ms, 0644); MODULE_PARM_DESC(idle_cache_ms, "J713: cache a static frame after this many ms without a flip (0: never, at most 60000; applies from the next swap)"); +static unsigned int power_gate_ms; + +static int power_gate_ms_set(const char *val, const struct kernel_param *kp) +{ + return param_set_uint_minmax(val, kp, 0, 600000); +} + +static const struct kernel_param_ops power_gate_ms_ops = { + .set = power_gate_ms_set, + .get = param_get_uint, +}; + +module_param_cb(power_gate_ms, &power_gate_ms_ops, &power_gate_ms, 0644); +MODULE_PARM_DESC(power_gate_ms, + "J713: power the display coprocessor and its domains down after this many ms blanked, and before system sleep (0: never, at most 600000)"); + +/* + * DCP CPU control and status, in the coprocessor's ASC block. The idle bit + * is dcp.c's APPLE_DCP_COPROC_CPU_STATUS_IDLE; macOS read status 0x6e at + * its idle check before clearing RUN. + */ +#define DCP_M4_CPU_CONTROL 0x44 +#define DCP_M4_CPU_RUN BIT(4) +#define DCP_M4_CPU_STATUS 0x48 +#define DCP_M4_CPU_STATUS_IDLE BIT(5) + /* One timing of an external sink for its DRM connector. */ struct iomfb_m4_ext_mode { struct drm_display_mode mode; @@ -153,6 +183,17 @@ struct iomfb_m4 { bool display_off; /* setPowerState(0) while blanked, until the next frame */ u64 display_off_cycles; s64 display_off_us, display_off_us_max, display_on_us, display_on_us_max; + /* + * Internal J713 DCP that can power its CPU and display domains down + * while blanked (apple,pmc-interface; power_gate_ms), and whether they + * are down: then no register of the DCP, its mailbox or its display + * DARTs is used until iomfb_m4_power_ungate(). + */ + bool gate_capable; + bool gated; + struct delayed_work gate_work; + u64 gate_cycles; + s64 gate_off_us, gate_on_us; /* Exact completed successor or blank is the only framebuffer retirement. */ struct drm_framebuffer *active_fb; struct drm_framebuffer *uncertain_fb; @@ -216,6 +257,9 @@ static void dcp_m4_runtime_wake(struct iomfb_m4 *dcp); struct dcp_m4_runtime; static void dcp_m4_ext_async_work(struct work_struct *work); static int dcp_m4_set_power_state(struct iomfb_m4 *dcp, bool on); +static int iomfb_m4_power_gate(struct iomfb_m4 *dcp); +static int iomfb_m4_power_ungate(struct iomfb_m4 *dcp); +static void iomfb_m4_gate_work(struct work_struct *work); static void dcp_m4_runtime_receive(struct iomfb_m4 *dcp, u64 word); static int dcp_m4_dart_check(struct device *dev) @@ -1025,6 +1069,10 @@ static int dcp_m4_runtime_health(struct dcp_m4_runtime *r) struct iomfb_m4 *dcp = r->dcp; int ret = READ_ONCE(dcp->error); + /* Powered down by its owner: only the failure latch. */ + if (READ_ONCE(dcp->gated)) + return ret; + if (!ret && (!(readl(dcp->coproc + 0x44) & BIT(4)) || dcp_m4_dart_check(dcp->dev) || (!dcp->external && dcp_m4_dart_check(&dcp->piodma->dev)))) ret = -EIO; @@ -1977,6 +2025,14 @@ static void dcp_m4_runtime_idle(struct work_struct *work) int ret; mutex_lock(&dcp->lock); + /* + * Powered down (iomfb_m4_power_gate()): nothing arrives then, and + * nothing may reach the stopped firmware or its powered-down DARTs. + */ + if (READ_ONCE(dcp->gated)) { + mutex_unlock(&dcp->lock); + return; + } ret = dcp_m4_runtime_drain(r, 32); if (ret < 0) { dcp_m4_transaction_fail(&dcp->transaction, ret); @@ -2587,6 +2643,7 @@ int iomfb_m4_init(struct apple_dcp *owner) INIT_WORK(&dcp->ext_put_work, iomfb_m4_ext_put_work); init_waitqueue_head(&dcp->ext_settle_wq); INIT_DELAYED_WORK(&dcp->idle_cache, iomfb_m4_idle_cache_work); + INIT_DELAYED_WORK(&dcp->gate_work, iomfb_m4_gate_work); if (!request_mem_region(res->start, resource_size(res), dev_name(dev))) { ret = -EBUSY; goto release; @@ -2613,6 +2670,9 @@ int iomfb_m4_init(struct apple_dcp *owner) if (ret) return ret; dcp->external = external; + /* The internal display's power-down: its PMC interface names the rest. */ + dcp->gate_capable = !external && apple_pmp_j713_board() && + of_property_present(dev->of_node, "apple,pmc-interface"); owner->v26_6 = dcp; owner->rtk = dcp->rtkit; owner->coproc_reg = dcp->coproc; @@ -3254,12 +3314,16 @@ int iomfb_m4_present(struct apple_dcp *owner, struct drm_framebuffer *fb, fb->pitches[0], fb->format->format == DRM_FORMAT_ARGB8888); if (ret) return ret; + /* A power-down not yet started is not needed; one under way finishes first. */ + cancel_delayed_work(&dcp->gate_work); mutex_lock(&dcp->lock); ret = dcp_m4_runtime_live(dcp->runtime); if (!ret && dcp->powered_off) ret = -EAGAIN; if (!ret) ret = iomfb_m4_check_frame(&frame); + if (!ret && dcp->gated) + ret = iomfb_m4_power_ungate(dcp); /* The first frame after a blank powers the display back up. */ if (!ret && dcp->display_off) { ktime_t start = ktime_get(); @@ -3332,6 +3396,11 @@ int iomfb_m4_blank(struct apple_dcp *owner) dcp->display_off_us = ktime_us_delta(ktime_get(), start); dcp->display_off_us_max = max(dcp->display_off_us, dcp->display_off_us_max); + unsigned int gate_ms = READ_ONCE(power_gate_ms); + + if (dcp->gate_capable && gate_ms) + mod_delayed_work(system_dfl_wq, &dcp->gate_work, + msecs_to_jiffies(gate_ms)); } } } @@ -3381,6 +3450,222 @@ static int dcp_m4_set_power_state(struct iomfb_m4 *dcp, bool on) return ret; } +/* Stop or start the DCP CPU; stopping waits for its idle status first. */ +static int iomfb_m4_cpu_run(struct iomfb_m4 *dcp, bool run) +{ + u32 control = readl(dcp->coproc + DCP_M4_CPU_CONTROL), status; + int ret; + + if (!!(control & DCP_M4_CPU_RUN) == run) + return -EBUSY; + if (!run) { + ret = readl_poll_timeout(dcp->coproc + DCP_M4_CPU_STATUS, status, + status & DCP_M4_CPU_STATUS_IDLE, 100, 100000); + if (ret) + return ret; + } + control = run ? control | DCP_M4_CPU_RUN : control & ~DCP_M4_CPU_RUN; + writel(control, dcp->coproc + DCP_M4_CPU_CONTROL); + return readl(dcp->coproc + DCP_M4_CPU_CONTROL) == control ? 0 : -EIO; +} + +static int iomfb_m4_cpu_start(void *data) +{ + return iomfb_m4_cpu_run(data, true); +} + +/* + * Whether every provider of the power-down can take part now, changing + * nothing: its display DARTs, the PMP vote (held, and releasable without + * losing it), the PMC interface enables and the PMGR states. + */ +static int iomfb_m4_gate_check(struct iomfb_m4 *dcp) +{ + return apple_dart_dcp_power_check(dcp->dev) ?: + apple_dart_dcp_power_check(&dcp->piodma->dev) ?: + apple_pmp_j713_display_check_release(dcp->dev) ?: + apple_pmc_interface_consumer_check(dcp->dev) ?: + apple_pmgr_ps_consumer_check(dcp->dev); +} + +/* + * After the blank's setPowerState(0), power the DCP and the display domains + * down as macOS does for display sleep: release the AP link (A500), let RTKit + * idle, stop the CPU, then power down its display DARTs, release its PMP + * vote, clear its PMC interface enables and power its CPU, frontend and + * system domains off. Firmware, endpoints and shared buffers stay in place + * for iomfb_m4_power_ungate(). Before the first step every provider is + * asked whether it can take part: if one cannot, nothing changes and the + * display just stays logically off. A failure after that fails the session. + */ +static int iomfb_m4_power_gate(struct iomfb_m4 *dcp) +{ + struct dcp_m4_runtime *r = dcp->runtime; + ktime_t start = ktime_get(); + unsigned long flags; + __le32 zero = 0; + const char *step; + int ret; + + lockdep_assert_held(&dcp->lock); + if (!dcp->gate_capable || dcp->gated || !dcp->display_off || dcp->powered_off || + dcp->active_fb || dcp->active_frame.dva || dcp->transaction.calls) + return -EBUSY; + ret = dcp_m4_runtime_live(r); + if (ret) + return ret; + ret = iomfb_m4_gate_check(dcp); + if (ret) { + dev_dbg(dcp->dev, "display power-down not possible now (%d): stays logically off\n", + ret); + return ret; + } + + step = "A500"; + ret = dcp_m4_runtime_call(r, 500, false, &zero, sizeof(zero), NULL, 0); + if (!ret) { + step = "drain"; + ret = dcp_m4_runtime_drain(r, 64); + if (ret > 0 || (!ret && r->count)) + ret = -EBUSY; + } + if (!ret) { + step = "RTKit idle"; + ret = apple_rtkit_idle(dcp->rtkit); + } + if (ret) + goto fail; + apple_rtkit_hold_rx(dcp->rtkit); + step = "CPU stop"; + ret = iomfb_m4_cpu_run(dcp, false); + if (ret) + goto fail; + /* + * The stopped CPU sends nothing more. A message it sent during the idle + * handshake would be handled after the power-down, by firmware that is + * stopped and through DARTs that are off: take everything in now, and + * fail here, with nothing powered down, if anything arrived. + */ + step = "late message"; + ret = apple_rtkit_poll(dcp->rtkit); + if (ret >= 0) { + apple_rtkit_flush_rx(dcp->rtkit); + spin_lock_irqsave(&dcp->state_lock, flags); + ret = r->count ? -EBUSY : 0; + spin_unlock_irqrestore(&dcp->state_lock, flags); + } + if (ret) + goto fail; + + /* From here on nothing may use the DCP's or its DARTs' registers. */ + WRITE_ONCE(dcp->gated, true); + step = "DART"; + ret = apple_dart_dcp_power_off(dcp->dev); + if (!ret) + ret = apple_dart_dcp_power_off(&dcp->piodma->dev); + if (!ret) { + step = "PMP"; + ret = apple_pmp_j713_display_put(dcp->dev); + } + if (!ret) { + step = "PMC"; + ret = apple_pmc_interface_consumer_off(dcp->dev); + } + if (!ret) { + step = "PMGR"; + ret = apple_pmgr_ps_consumer_off(dcp->dev); + } + if (ret) + goto fail; + dcp->gate_cycles++; + dcp->gate_off_us = ktime_us_delta(ktime_get(), start); + return 0; +fail: + dev_err(dcp->dev, "display power-down failed at %s: %d\n", step, ret); + dcp_m4_failed(dcp, ret); + return ret; +} + +/* + * Power the DCP back up for the first frame after a gated blank, in macOS's + * order: the domains, the PMP vote, the PMC interface enables, then the + * display DARTs, then the CPU through RTKit's retained wake, and the display + * preparation macOS sends before setPowerState(1). A failure fails the + * session. + */ +static int iomfb_m4_power_ungate(struct iomfb_m4 *dcp) +{ + struct dcp_m4_runtime *r = dcp->runtime; + ktime_t start = ktime_get(); + u8 prepare[8] = {}, prepared[8] = {}; + __le32 main_display = 0; + const char *step; + int ret; + + lockdep_assert_held(&dcp->lock); + if (!dcp->gated) + return 0; + step = "PMGR"; + ret = apple_pmgr_ps_consumer_on(dcp->dev); + if (!ret) { + step = "PMP"; + ret = apple_pmp_j713_display_get(dcp->dev); + } + if (!ret) { + step = "PMC"; + ret = apple_pmc_interface_consumer_on(dcp->dev); + } + if (!ret) { + step = "DART"; + ret = apple_dart_dcp_power_on(dcp->dev); + } + if (!ret) + ret = apple_dart_dcp_power_on(&dcp->piodma->dev); + if (!ret) { + step = "RTKit wake"; + ret = apple_rtkit_wake_retained(dcp->rtkit, iomfb_m4_cpu_start, dcp); + } + if (ret) + goto fail; + WRITE_ONCE(dcp->gated, false); + + step = "A414"; + ret = dcp_m4_runtime_call(r, 414, false, prepare, sizeof(prepare), + prepared, sizeof(prepared)); + if (!ret && get_unaligned_le32(prepared + 4)) + ret = -EREMOTEIO; + if (!ret) { + step = "A412"; + ret = dcp_m4_runtime_call(r, 412, false, NULL, 0, &main_display, + sizeof(main_display)); + } + if (!ret && le32_to_cpu(main_display) != 1) + ret = -EREMOTEIO; + if (ret) + goto fail; + dcp->gate_on_us = ktime_us_delta(ktime_get(), start); + return 0; +fail: + dev_err(dcp->dev, "display power-up failed at %s: %d\n", step, ret); + dcp_m4_failed(dcp, ret); + return ret; +} + +static void iomfb_m4_gate_work(struct work_struct *work) +{ + struct iomfb_m4 *dcp = container_of(to_delayed_work(work), struct iomfb_m4, gate_work); + + mutex_lock(&dcp->lock); + /* + * Still blanked and not yet down: a frame since then cancels it, and so + * does turning the power-down off meanwhile (power_gate_ms = 0). + */ + if (dcp->runtime && dcp->display_off && !dcp->gated && !READ_ONCE(dcp->error) && + !READ_ONCE(dcp->owner->quiescing) && READ_ONCE(power_gate_ms)) + iomfb_m4_power_gate(dcp); + mutex_unlock(&dcp->lock); +} + /* A364: the firmware's record of a timing and colour pair. */ struct dcp_m4_mode_info_req { u8 mode[0x64]; @@ -4976,14 +5261,23 @@ int iomfb_m4_suspend(struct apple_dcp *owner) } if (!dcp || !dcp->runtime) return -ENODEV; + cancel_delayed_work_sync(&dcp->gate_work); mutex_lock(&dcp->lock); /* Also the startup surface, shown before the first frame */ if (dcp->active_fb || dcp->active_frame.dva) { dev_warn(dcp->dev, "panel still scanning out: refusing system sleep\n"); ret = -EBUSY; } else if (dcp->display_off) { - /* Already powered down by the blank; the next frame powers it up. */ + /* + * Already powered down by the blank; the next frame powers it up. + * Power the DCP and its domains down too, if it may. That is an + * extra saving, not a condition of sleep: a power-down that cannot + * start leaves the display logically off, and one that fails has + * failed the session already; neither refuses the sleep. + */ ret = 0; + if (dcp->gate_capable && READ_ONCE(power_gate_ms) && !dcp->gated) + iomfb_m4_power_gate(dcp); } else { ret = dcp_m4_set_power_state(dcp, false); if (!ret) @@ -5011,7 +5305,10 @@ int iomfb_m4_resume(struct apple_dcp *owner) if (!dcp || !dcp->runtime) return -ENODEV; mutex_lock(&dcp->lock); - if (dcp->powered_off) { + if (dcp->gated) { + /* Stays down until the next frame. */ + ret = 0; + } else if (dcp->powered_off) { ret = dcp_m4_set_power_state(dcp, true); if (!ret) dcp->powered_off = false; @@ -5079,6 +5376,7 @@ void iomfb_m4_quiesce(struct apple_dcp *owner) flush_workqueue(dcp->runtime->wq); /* After the flush, as drained callbacks can queue it. */ cancel_delayed_work_sync(&dcp->idle_cache); + cancel_delayed_work_sync(&dcp->gate_work); } static int iomfb_m4_status_show(struct seq_file *s, void *unused) @@ -5097,7 +5395,11 @@ static int iomfb_m4_status_show(struct seq_file *s, void *unused) dcp_m4_failed(dcp, health); seq_printf(s, "firmware=26.6.2 ready=%u qualified=%u error=%d run=%u health=%d\n", dcp->ready, r && r->qualified, dcp->error, - !!(readl(dcp->coproc + 0x44) & BIT(4)), health); + !dcp->gated && !!(readl(dcp->coproc + DCP_M4_CPU_CONTROL) & DCP_M4_CPU_RUN), + health); + seq_printf(s, "gate_capable=%u gated=%u gate_cycles=%llu gate_off_us=%lld gate_on_us=%lld\n", + dcp->gate_capable, dcp->gated, dcp->gate_cycles, dcp->gate_off_us, + dcp->gate_on_us); seq_printf(s, "startup=%u background=%u power=%u scanout=%u callbacks=%u\n", r && r->done, r && r->background_done, r && r->power_done, r && r->scanout_done, r ? r->callbacks : 0); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py b/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py index 4d0e9c50a1082..622957c3b6837 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/m4.py @@ -493,6 +493,148 @@ def dart(root): ''' +def gate(root): + """The physical power-down and power-up of the internal DCP: their order, + the providers asked before the first step, and a late firmware message.""" + backend = (root / APPLE / 'iomfb_m4.c').read_text() + return PREFIX + r''' +#define READ_ONCE(x) (x) +#define WRITE_ONCE(x,v) ((x)=(v)) +#define container_of(p,t,m) ((t *)((char *)(p) - __builtin_offsetof(t,m))) +#define le32_to_cpu(x) (x) +#define dev_dbg(...) ((void)0) +#define dev_err(d,...) ((void)(d),(void)fprintf(stderr,__VA_ARGS__)) +#define spin_lock_irqsave(p,f) do { (void)(p); (f)=0; } while(0) +#define spin_unlock_irqrestore(p,f) do { (void)(p); (void)(f); } while(0) +typedef u32 __le32; +typedef int64_t s64; +typedef s64 ktime_t; +static ktime_t clock_ns; +static ktime_t ktime_get(void) { return clock_ns += 1000; } +static s64 ktime_us_delta(ktime_t later,ktime_t earlier) { return (later-earlier)/1000; } +struct device { int unused; }; +struct platform_device { struct device dev; }; +struct apple_rtkit { int unused; }; +struct work_struct { int unused; }; +struct delayed_work { struct work_struct work; }; +#define to_delayed_work(w) container_of(w,struct delayed_work,work) +struct apple_dcp { bool quiescing; }; +struct dcp_m4_frame { u64 dva; }; +struct dcp_m4_transaction { unsigned calls; }; +struct iomfb_m4; +struct dcp_m4_runtime { struct iomfb_m4 *dcp; unsigned count; }; +struct iomfb_m4 { + struct apple_dcp *owner; + struct device *dev; + struct platform_device *piodma; + struct apple_rtkit *rtkit; + struct dcp_m4_runtime *runtime; + int lock,state_lock,error; + struct dcp_m4_transaction transaction; + struct dcp_m4_frame active_frame; + void *active_fb; + bool gate_capable,gated,display_off,powered_off; + struct delayed_work gate_work; + u64 gate_cycles; + s64 gate_off_us,gate_on_us; +}; +static unsigned power_gate_ms; +static struct iomfb_m4 *the_dcp; +/* Every step taken, in order. */ +static char steps[512]; +static void trace(const char *s) { strcat(steps,s); strcat(steps," "); } +static int refuse; /* the provider check that refuses (1..5), or 0 */ +static bool late_word; /* a DCP message arrives during the idle handshake */ +static void mutex_lock(int *l) { assert(!*l); *l=1; } +static void mutex_unlock(int *l) { assert(*l==1); *l=0; } +static void lockdep_assert_held(int *l) { assert(*l==1); } +static void dcp_m4_failed(struct iomfb_m4 *dcp,int error) { if(!dcp->error) dcp->error=error; } +static int dcp_m4_runtime_live(struct dcp_m4_runtime *r) { return r->dcp->error; } +static int dcp_m4_runtime_call(void *cookie,unsigned int method,bool remote, + const void *input,u32 input_size,void *output,u32 output_size) +{ + char name[16]; + (void)cookie; (void)remote; (void)input; (void)input_size; + snprintf(name,sizeof(name),"A%u",method); trace(name); + if(output) memset(output,0,output_size); + if(method==412) { assert(output_size==4); put_unaligned_le32(1,output); } + return 0; +} +static int dcp_m4_runtime_drain(struct dcp_m4_runtime *r,unsigned budget) +{ (void)r; (void)budget; trace("drain"); return 0; } +static int apple_rtkit_idle(struct apple_rtkit *rtk) { (void)rtk; trace("idle"); return 0; } +static void apple_rtkit_hold_rx(struct apple_rtkit *rtk) { (void)rtk; trace("hold"); } +static int apple_rtkit_poll(struct apple_rtkit *rtk) { (void)rtk; trace("poll"); return 0; } +static void apple_rtkit_flush_rx(struct apple_rtkit *rtk) +{ (void)rtk; trace("flush"); if(late_word) the_dcp->runtime->count++; } +static int iomfb_m4_cpu_run(struct iomfb_m4 *dcp,bool run) { (void)dcp; trace(run?"run":"stop"); return 0; } +static int iomfb_m4_cpu_start(void *data) { return iomfb_m4_cpu_run(data,true); } +static int apple_rtkit_wake_retained(struct apple_rtkit *rtk,int (*start)(void *),void *ctx) +{ (void)rtk; trace("wake"); return start(ctx); } +static bool dcp_dev(struct device *dev) { return dev==the_dcp->dev; } +static int apple_dart_dcp_power_check(struct device *dev) { return refuse==(dcp_dev(dev)?1:2)?-EAGAIN:0; } +static int apple_pmp_j713_display_check_release(struct device *dev) { (void)dev; return refuse==3?-ETIMEDOUT:0; } +static int apple_pmc_interface_consumer_check(struct device *dev) { (void)dev; return refuse==4?-ENODEV:0; } +static int apple_pmgr_ps_consumer_check(struct device *dev) { (void)dev; return refuse==5?-EBUSY:0; } +static int apple_dart_dcp_power_off(struct device *dev) { trace(dcp_dev(dev)?"dart-off":"piodma-off"); return 0; } +static int apple_dart_dcp_power_on(struct device *dev) { trace(dcp_dev(dev)?"dart-on":"piodma-on"); return 0; } +static int apple_pmp_j713_display_put(struct device *dev) { (void)dev; trace("pmp-put"); return 0; } +static int apple_pmp_j713_display_get(struct device *dev) { (void)dev; trace("pmp-get"); return 0; } +static int apple_pmc_interface_consumer_off(struct device *dev) { (void)dev; trace("pmc-off"); return 0; } +static int apple_pmc_interface_consumer_on(struct device *dev) { (void)dev; trace("pmc-on"); return 0; } +static int apple_pmgr_ps_consumer_off(struct device *dev) { (void)dev; trace("pmgr-off"); return 0; } +static int apple_pmgr_ps_consumer_on(struct device *dev) { (void)dev; trace("pmgr-on"); return 0; } +''' + '\n'.join(block(backend, name) for name in ( + 'static int iomfb_m4_gate_check(', 'static int iomfb_m4_power_gate(', + 'static int iomfb_m4_power_ungate(', 'static void iomfb_m4_gate_work(')) + r''' +int main(void) +{ + struct apple_dcp owner={0}; + struct device dev={0}; + struct platform_device piodma={{0}}; + struct apple_rtkit rtk={0}; + struct iomfb_m4 dcp={.owner=&owner,.dev=&dev,.piodma=&piodma,.rtkit=&rtk, + .gate_capable=true,.display_off=true}; + struct dcp_m4_runtime r={.dcp=&dcp}; + + dcp.runtime=&r; the_dcp=&dcp; + /* Turned off after the blank: the queued power-down does nothing. */ + iomfb_m4_gate_work(&dcp.gate_work.work); + assert(!steps[0] && !dcp.gated); + /* Wanted: the whole power-down, in its order. */ + power_gate_ms=1000; + iomfb_m4_gate_work(&dcp.gate_work.work); + assert(!strcmp(steps,"A500 drain idle hold stop poll flush dart-off piodma-off " + "pmp-put pmc-off pmgr-off ")); + assert(dcp.gated && !dcp.error && dcp.gate_cycles==1 && !dcp.lock); + + /* The power-up, in macOS's order: domains, PMP vote, PMC enables, DARTs, CPU. */ + steps[0]=0; dcp.lock=1; + assert(!iomfb_m4_power_ungate(&dcp)); + assert(!strcmp(steps,"pmgr-on pmp-get pmc-on dart-on piodma-on wake run A414 A412 ")); + assert(!dcp.gated && !dcp.error); + + /* A provider that cannot take part now: no step at all, and no failure. */ + for(refuse=1;refuse<=5;refuse++) { + steps[0]=0; + assert(iomfb_m4_power_gate(&dcp)<0); + assert(!steps[0] && !dcp.gated && !dcp.error); + } + refuse=0; + + /* A message from the idle handshake: failed with nothing powered down. */ + steps[0]=0; late_word=true; + assert(iomfb_m4_power_gate(&dcp)==-EBUSY); + assert(!strcmp(steps,"A500 drain idle hold stop poll flush ")); + assert(!dcp.gated && dcp.error==-EBUSY); + dcp.lock=0; + puts("PASS the power-down and power-up keep their order, a refusing provider changes nothing, " + "and a late message fails before anything is powered down"); + return 0; +} +''' + + def blank(root): backend = (root / APPLE / 'iomfb_m4.c').read_text() backlight = (root / APPLE / 'dcp_backlight.c').read_text() @@ -551,7 +693,16 @@ def blank(root): bool display_off; u64 display_off_cycles; s64 display_off_us,display_off_us_max,display_on_us,display_on_us_max; + bool gate_capable,gated; + int gate_work; }; +/* The power-down after a blank: its scheduling and the power-up before ON. */ +static unsigned power_gate_ms,scheduled,cancelled,ungates,ungate_error,ons_at_ungate; +#define system_dfl_wq NULL +static unsigned long msecs_to_jiffies(unsigned ms) { return ms; } +static bool mod_delayed_work(void *wq,int *work,unsigned long delay) +{ (void)wq; (void)work; assert(delay==power_gate_ms); scheduled++; return true; } +static bool cancel_delayed_work(int *work) { (void)work; cancelled++; return false; } static void mutex_lock(int *lock) { assert(!*lock); *lock=1; } static void mutex_unlock(int *lock) { assert(*lock==1); *lock=0; } static void lockdep_assert_held(int *lock) { assert(*lock==1); } @@ -568,6 +719,13 @@ def blank(root): static int dcp_m4_set_power_state(struct iomfb_m4 *dcp,bool on) { assert(dcp->lock==1); if(on) power_ons++; else power_offs++; return 0; } static int dcp_m4_runtime_live(struct dcp_m4_runtime *r) { return r->dcp->error; } +static int iomfb_m4_power_ungate(struct iomfb_m4 *dcp) +{ + assert(dcp->lock==1 && dcp->gated && dcp->display_off); + ons_at_ungate=power_ons; ungates++; + if(ungate_error) { dcp_m4_failed(dcp,ungate_error); return ungate_error; } + dcp->gated=false; return 0; +} static int iomfb_m4_check_frame(const struct dcp_m4_frame *f) { return dcp_m4_frame_check(f); } static unsigned order,failure,publications; @@ -640,6 +798,42 @@ def blank(root): assert(fb.refs==2 && next.refs==2 && dcp.active_fb==&fb && dcp.uncertain_fb==&next); failure=0; } + /* Not opted in: a blank schedules no power-down; a frame still cancels one. */ + { + struct drm_format_info fmt={.format=DRM_FORMAT_XRGB8888,.num_planes=1}; + struct drm_framebuffer fb={.format=&fmt,.width=2560,.height=1664,.pitches={10240},.refs=1}; + struct apple_dcp owner={0}; + struct iomfb_m4 dcp={.owner=&owner}; + struct dcp_m4_runtime runtime={.dcp=&dcp}; + unsigned c; + owner.v26_6=&dcp; dcp.runtime=&runtime; + assert(!dcp_bl_init(&owner.backlight.state,500,true,120,false,0)); + c=cancelled; + assert(!iomfb_m4_present(&owner,&fb,0x10000100000ULL,0x2000000)); + assert(cancelled==c+1); + assert(!iomfb_m4_blank(&owner) && scheduled==0); + dcp.gate_capable=true; + assert(!iomfb_m4_present(&owner,&fb,0x10000100000ULL,0x2000000)); + assert(!iomfb_m4_blank(&owner) && scheduled==0); /* power_gate_ms is 0 */ + + /* Opted in: one power-down after the blank, after power_gate_ms. */ + power_gate_ms=1000; + assert(!iomfb_m4_present(&owner,&fb,0x10000100000ULL,0x2000000)); + assert(!iomfb_m4_blank(&owner) && scheduled==1); + /* Powered down: the next frame powers it up first, then setPowerState(1). */ + dcp.gated=true; + unsigned ons=power_ons; + assert(!iomfb_m4_present(&owner,&fb,0x10000100000ULL,0x2000000)); + assert(ungates==1 && ons_at_ungate==ons && power_ons==ons+1); + assert(!dcp.gated && !dcp.display_off && dcp.active_fb==&fb); + /* A failed power-up refuses the frame; the session is failed by it. */ + assert(!iomfb_m4_blank(&owner) && scheduled==2); + dcp.gated=true; ungate_error=-EIO; ons=power_ons; + assert(iomfb_m4_present(&owner,&fb,0x10000100000ULL,0x2000000)==-EIO); + assert(ungates==2 && power_ons==ons && dcp.error==-EIO && dcp.display_off); + assert(fb.refs==1 && !dcp.active_fb); + ungate_error=0; power_gate_ms=0; + } puts("PASS DPMS-off blank carries zero before delayed work and completes only after both exact receipts"); puts("PASS actual present/blank retain active+uncertain DMA framebuffer references across a missing receipt"); puts("PASS a present while the display is powered off for sleep is refused without a reference"); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py index ac69a16514c3e..18374e2337a58 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/run.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/run.py @@ -83,6 +83,7 @@ def main(): ('m4', 'm4-common-plane', m4.plane, ((),), ('-Wno-unused-function', '-Wno-unused-const-variable')), ('m4', 'm4-producer-retirement', m4.prepare, ((),), ('-Wno-unused-function',)), ('m4', 'm4-dpms-retirement', m4.blank, ((),), ('-Wno-unused-function', '-Wno-unused-const-variable')), + ('m4', 'm4-power-gate', m4.gate, ((),), ('-Wno-unused-function',)), ('m4', 'm4-dart-consumer', m4.dart, ((),), ('-Wno-unused-function',)), ('m4', 'm4-panel-timing', m4.timing, ((),), ('-Wno-unused-function', '-Wno-unused-const-variable')), ('boot', 'oslog-events', boot.oslog, ((),), ()), From 539735dc5b714f1d85a251324a361fe46ddaeb83 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:57:33 +0100 Subject: [PATCH 244/342] dt-bindings: display: apple,dcp: name the display pipe's PMC interface A DCP that powers its display domains down while the display is off clears its pipe's PMC interface enables first and restores them after powering the domains up. Add apple,pmc-interface, a phandle to the pipe's apple,consumer-switched PMC interface node. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- Documentation/devicetree/bindings/display/apple,dcp.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 3db18e058dce3..b45a737748180 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -274,6 +274,14 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 description: Height in pixels reserved for the display notch. + apple,pmc-interface: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PMC interface enables of this coprocessor's display pipe, an + apple,consumer-switched interface node. The coprocessor clears them + before it powers its display domains down while the display is off, + and restores them after it powers them up again. + apple,pmp-report: $ref: /schemas/types.yaml#/definitions/phandle description: From 5e31b3588f813b6a8ab5dfbf4db9671464a5b486 Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:57:33 +0100 Subject: [PATCH 245/342] arm64: dts: apple: t8132: describe the display power-down resources Describe what a power-down of the internal display domains needs on T8132: - the PMGR register block up to the display CPU's power-gate retention registers at 0x2504c and 0x25070; - the PS_PROT bank of clock protection slices, as a syscon; - the internal display pipe's PMC interface enables (BWR and boost bit 0), as a consumer-switched interface, since its power states are firmware-owned rather than a power domain. No consumer uses them yet. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- arch/arm64/boot/dts/apple/t8132-memory.dtsi | 12 ++++++++++++ arch/arm64/boot/dts/apple/t8132.dtsi | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8132-memory.dtsi b/arch/arm64/boot/dts/apple/t8132-memory.dtsi index c6cafa8219d2a..e0de465b9ffe1 100644 --- a/arch/arm64/boot/dts/apple/t8132-memory.dtsi +++ b/arch/arm64/boot/dts/apple/t8132-memory.dtsi @@ -24,6 +24,18 @@ * boost interface enables. The PMC ignores a pipe's bandwidth * and display clock votes while they are clear. */ + /* + * The internal display pipe's enables. Its power states are + * firmware-owned, so they are not a power domain: its DCP + * clears them before powering the pipe down and restores them. + */ + pmc_disp0: interface-disp0 { + label = "disp0-interface"; + apple,consumer-switched; + apple,bwr-bit = <0>; + apple,boost-bit = <0>; + }; + pmc_dispext0: interface-dispext0 { label = "dispext0-interface"; #power-domain-cells = <0>; diff --git a/arch/arm64/boot/dts/apple/t8132.dtsi b/arch/arm64/boot/dts/apple/t8132.dtsi index 35490237bba94..d6a01e1473200 100644 --- a/arch/arm64/boot/dts/apple/t8132.dtsi +++ b/arch/arm64/boot/dts/apple/t8132.dtsi @@ -474,10 +474,17 @@ compatible = "apple,t8132-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; #address-cells = <1>; #size-cells = <1>; - reg = <0x3 0x80700000 0 0x14000>; + /* Up to the display CPU's power-gate retention registers. */ + reg = <0x3 0x80700000 0 0x26000>; /* child nodes are added in t8132-pmgr.dtsi */ }; + /* Clock protection slices guarding power states of DART domains. */ + ps_prot: syscon@38079c000 { + compatible = "apple,t8132-ps-prot", "syscon"; + reg = <0x3 0x8079c000 0 0x4000>; + }; + aic: interrupt-controller@381000000 { compatible = "apple,t8132-aic3", "apple,t8122-aic3"; #interrupt-cells = <3>; From 23885d96c8087a1c149874ea2e563d8370079ca1 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:58:28 -0500 Subject: [PATCH 246/342] arm64: dts: apple: t6050: Put the SEP in die 0's soc node The boot loader finds the SEP by the path a board's sep alias gives. The inventory puts it in the unit-less soc node, and "/soc" names soc@200000000 first, so such a path never reaches it, and the loader could not reserve the SEP firmware or add its manifests. Move the SEP, its mailbox and its DART into die 0's soc node, whose ranges cover them. Signed-off-by: Diljit Singh --- .../dts/apple/adt-coverage/t6050-j716s.txt | 16 ++-- .../dts/apple/adt-coverage/t6050-j873s.txt | 16 ++-- .../boot/dts/apple/t6050-peripherals.dtsi | 88 ++++++++++--------- 3 files changed, 63 insertions(+), 57 deletions(-) diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t6050-j716s.txt b/arch/arm64/boot/dts/apple/adt-coverage/t6050-j716s.txt index 096aa6df9a804..82218ccb772ab 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t6050-j716s.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t6050-j716s.txt @@ -1268,14 +1268,14 @@ /arm-io/dart-pmp1 - -> MISSING /arm-io/dart-pmp1/mapper-pmp1 - -> WAIVED: IOMMU stream, described by iommus or iommu-map; DART hardware is inventoried separately. /arm-io/dart-pmp1/mapper-pmp1-ptd-fwd - -> WAIVED: IOMMU stream, described by iommus or iommu-map; DART hardware is inventoried separately. -/arm-io/sep 0x502600000 -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/Sandcat - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/xART - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/InvalidateHmac - -> /soc/sep@502600000 -/arm-io/dart-sep 0x500b80000 -> /soc/iommu@500b80000 -/arm-io/dart-sep/mapper-sep - -> /soc/iommu@500b80000 -/arm-io/dart-sep/mapper-sep-exclave - -> /soc/iommu@500b80000 +/arm-io/sep 0x502600000 -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/Sandcat - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/xART - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/InvalidateHmac - -> /soc@200000000/sep@502600000 +/arm-io/dart-sep 0x500b80000 -> /soc@200000000/iommu@500b80000 +/arm-io/dart-sep/mapper-sep - -> /soc@200000000/iommu@500b80000 +/arm-io/dart-sep/mapper-sep-exclave - -> /soc@200000000/iommu@500b80000 /arm-io/esm 0x54267c000 -> MISSING /arm-io/ans 0x419600000 -> /soc@200000000/nvme@45dcc0000 /arm-io/ans/iop-ans-nub - -> /soc@200000000/nvme@45dcc0000 diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t6050-j873s.txt b/arch/arm64/boot/dts/apple/adt-coverage/t6050-j873s.txt index 939c40a8c931d..c014ce038d1f0 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t6050-j873s.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t6050-j873s.txt @@ -1192,14 +1192,14 @@ /arm-io/dart-pmp1 - -> MISSING /arm-io/dart-pmp1/mapper-pmp1 - -> WAIVED: IOMMU stream, described by iommus or iommu-map; DART hardware is inventoried separately. /arm-io/dart-pmp1/mapper-pmp1-ptd-fwd - -> WAIVED: IOMMU stream, described by iommus or iommu-map; DART hardware is inventoried separately. -/arm-io/sep 0x502600000 -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/Sandcat - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/xART - -> /soc/sep@502600000 -/arm-io/sep/iop-sep-nub/InvalidateHmac - -> /soc/sep@502600000 -/arm-io/dart-sep 0x500b80000 -> /soc/iommu@500b80000 -/arm-io/dart-sep/mapper-sep - -> /soc/iommu@500b80000 -/arm-io/dart-sep/mapper-sep-exclave - -> /soc/iommu@500b80000 +/arm-io/sep 0x502600000 -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/Sandcat - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/xART - -> /soc@200000000/sep@502600000 +/arm-io/sep/iop-sep-nub/InvalidateHmac - -> /soc@200000000/sep@502600000 +/arm-io/dart-sep 0x500b80000 -> /soc@200000000/iommu@500b80000 +/arm-io/dart-sep/mapper-sep - -> /soc@200000000/iommu@500b80000 +/arm-io/dart-sep/mapper-sep-exclave - -> /soc@200000000/iommu@500b80000 /arm-io/esm 0x54267c000 -> MISSING /arm-io/ans 0x419600000 -> /soc@200000000/nvme@45dcc0000 /arm-io/ans/iop-ans-nub - -> /soc@200000000/nvme@45dcc0000 diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index e82926b257398..7507a40008c23 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2202,47 +2202,6 @@ status = "disabled"; }; - /* iBoot hands over a running SEP; apple_sep enables it and its DART when it loads. */ - sep: sep@502600000 { - compatible = "apple,t6050-sep", "apple,sep"; - reg = <0x5 0x2600000 0x0 0x88000>, - <0x5 0x2050000 0x0 0x4000>; - mboxes = <&sep_mbox>; - mbox-names = "mbox"; - iommus = <&sep_dart 0>; - power-domains = <&ps_sep>; - clocks = <&peripheral_clocks 447>; - status = "disabled"; - }; - - /* The ASC v4 mailbox at sep + 0x8000; the first four ADT interrupts in mailbox order */ - sep_mbox: mailbox@502608000 { - compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; - reg = <0x5 0x2608000 0x0 0x4000>; - interrupts = , - , - , - ; - interrupt-names = "send-empty", "send-not-empty", - "recv-empty", "recv-not-empty"; - #mbox-cells = <0>; - status = "disabled"; - }; - - sep_dart: iommu@500b80000 { - compatible = "apple,t6050-dart", "apple,t8110-dart"; - reg = <0x5 0xb80000 0x0 0x20000>; - interrupts = ; - #iommu-cells = <1>; - /* - * The window iBoot programmed (ADT dart-sep vm-base-0, vm-size-0), which - * already carries the BIT(40) alias the DART translates. - */ - apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; - apple,dma-offset = /bits/ 64 <0x0>; - status = "disabled"; - }; - aon_ptd: aon-ptd@28cdc0000 { compatible = "apple,t6050-aon-ptd", "apple,aon-ptd"; reg = <0x2 0x8cdc0000 0x0 0x4000>, @@ -3417,4 +3376,51 @@ +}; + +/* + * The SEP sits in die 0's soc node, not in the unit-less soc above: the boot loader + * resolves the sep alias by path, and "/soc" names soc@200000000 first. + */ +&die0 { + /* iBoot hands over a running SEP; apple_sep enables it and its DART when it loads. */ + sep: sep@502600000 { + compatible = "apple,t6050-sep", "apple,sep"; + reg = <0x5 0x2600000 0x0 0x88000>, + <0x5 0x2050000 0x0 0x4000>; + mboxes = <&sep_mbox>; + mbox-names = "mbox"; + iommus = <&sep_dart 0>; + power-domains = <&ps_sep>; + clocks = <&peripheral_clocks 447>; + status = "disabled"; + }; + + /* The ASC v4 mailbox at sep + 0x8000; the first four ADT interrupts in mailbox order */ + sep_mbox: mailbox@502608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x5 0x2608000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + status = "disabled"; + }; + + sep_dart: iommu@500b80000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + reg = <0x5 0xb80000 0x0 0x20000>; + interrupts = ; + #iommu-cells = <1>; + /* + * The window iBoot programmed (ADT dart-sep vm-base-0, vm-size-0), which + * already carries the BIT(40) alias the DART translates. + */ + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; + status = "disabled"; + }; }; From c7a700e63d119497ccde4aa06c4a1f38a0583d6d Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 06:56:20 -0500 Subject: [PATCH 247/342] arm64: dts: apple: t6050-j714s: Point the boot loader at the SEP The boot loader finds the SEP through the sep alias: it reserves the SEP firmware (ADT memory-map SEPFW) and adds the iBoot and local policy manifests the enclave needs to open the machine's secure storage. Without them apple_sep refuses to attach. J616s has the same alias. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-j714s.dts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-j714s.dts b/arch/arm64/boot/dts/apple/t6050-j714s.dts index 9cd9ee94ab32b..d98f6ac1d63a0 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714s.dts @@ -20,6 +20,11 @@ model = "Apple MacBook Pro (14-inch, M5 Pro, 2026)"; chassis-type = "laptop"; + aliases { + /* the boot loader reserves the SEP firmware and adds its manifests through this alias */ + sep = &sep; + }; + chosen { #address-cells = <2>; #size-cells = <2>; From b0517f95c68b364a6513d78451d5b487f740cfdc Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 07:32:34 -0500 Subject: [PATCH 248/342] soc: apple: pmp: Add T6050 The T6050 PMP DART's window starts at 1 TiB and spans 64 GiB (ADT dart-pmp0 vm-base and vm-size), as T8142's does, so the firmware gets a 42-bit DMA mask. iBoot loads the firmware without starting it; the driver starts it as on the other SoCs. Unlike T8142's, this firmware never readies endpoint 7 (CoreAnalytics): waiting for it fails the probe with -ETIME, so it isn't started. Tested on J714s (M5 Pro) with the PMP described as in the following commit and enabled, board-id, DRAM vendor, PMC boot arguments and the ADT's iop-pmp0-nub properties as tunables: "PMP firmware and endpoint ready" 1.6 ms after RTKit init, and a PMC gated on it binds. With endpoint 7 started the probe failed with -62. Signed-off-by: Diljit Singh --- drivers/soc/apple/pmp.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index 2212509efd82c..58aa64cee28c5 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -701,6 +701,14 @@ const HW_CFG_T8142: PmpHwConfig = PmpHwConfig { coreanalytics: Ep7::Always, }; +/// T6050: the DART window starts at 1 TiB (ADT dart-pmp0 vm-base) and spans +/// 64 GiB, as on T8142. Its firmware never readies endpoint 7 (-ETIME). +const HW_CFG_T6050: PmpHwConfig = PmpHwConfig { + dma_mask: Some(DmaMask::new::<42>()), + check_bootargs_uuid: false, + coreanalytics: Ep7::No, +}; + const HW_CFG_T8132: PmpHwConfig = PmpHwConfig { dma_mask: None, check_bootargs_uuid: false, @@ -722,6 +730,7 @@ kernel::of_device_table!( (of::DeviceId::new(c"apple,t8140-pmp-v2"), &HW_CFG_T8140), (of::DeviceId::new(c"apple,t8142-pmp-v2"), &HW_CFG_T8142), (of::DeviceId::new(c"apple,t6041-pmp-v2"), &HW_CFG_T6041), + (of::DeviceId::new(c"apple,t6050-pmp-v2"), &HW_CFG_T6050), (of::DeviceId::new(c"apple,t6000-pmp-v2"), &HW_CFG_DEFAULT), ] ); From c72b3e4309e98856dbedc29c5f9c1e0ba219b13d Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 07:32:34 -0500 Subject: [PATCH 249/342] arm64: dts: apple: t6050: Describe the PMP for its driver The PMP driver maps the firmware's SRAM as "pmp" (ADT pmp0 reg[2]) and the ASC as "asc" (reg[0]), talks through the ASC mailbox at +0x8000 and allocates through its DART, whose window starts at 1 TiB and spans 64 GiB (ADT dart-pmp0 vm-base, vm-size). Describe them that way; the mailbox interrupts are the ADT's four in ascending order, as for the other T6050 ASC mailboxes. Everything stays disabled: a board enables the PMP once it supplies the boot arguments and firmware properties. Signed-off-by: Diljit Singh --- .../boot/dts/apple/t6050-peripherals.dtsi | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index eef667d647d3d..c4be3fcf47ca7 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2176,27 +2176,42 @@ status = "disabled"; }; + /* ADT pmp0 reg[2] (firmware SRAM) and reg[0] (ASC); iBoot loads the firmware, the OS starts it */ pmp0: pmp@284e00000 { compatible = "apple,t6050-pmp-v2", "apple,t6000-pmp-v2"; - reg = <0x2 0x84e00000 0x0 0x88000>, - <0x2 0x84850000 0x0 0x4000>, - <0x2 0x84500000 0x0 0x100000>, - <0x2 0x84250000 0x0 0x4000>; - interrupts = , - , - , - ; + reg = <0x2 0x84500000 0x0 0x100000>, + <0x2 0x84e00000 0x0 0x4000>; + reg-names = "pmp", "asc"; + mboxes = <&pmp0_mbox>; + mbox-names = "mbox"; iommus = <&pmp0_dart 0>; power-domains = <&ps_pmp>, <&ps_pms_sram>; status = "disabled"; }; + pmp0_mbox: mailbox@284e08000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x2 0x84e08000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + power-domains = <&ps_pmp>; + status = "disabled"; + }; + pmp0_dart: iommu@2841a0000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; reg = <0x2 0x841a0000 0x0 0xc000>, <0x2 0x841b0000 0x0 0x4000>; interrupts = ; #iommu-cells = <1>; + /* ADT dart-pmp0 vm-base, vm-size */ + apple,dma-range = /bits/ 64 <0x10000000000 0x1000000000>; + power-domains = <&ps_pmp>; status = "disabled"; }; From 90eb7840c1517e2e1cf0bfb0cd222531a76e9e8c Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Fri, 6 Nov 2026 18:57:33 +0100 Subject: [PATCH 250/342] arm64: dts: apple: t8132-j713: let the DCP power its display domains down Let the internal DCP power its display down while blanked (appledrm.power_gate_ms): - the display CPU, frontend and system power states are consumer-switched, the CPU with the retention workaround macOS sets while it is off (0x3 in 0x2504c, 0x0 in 0x25070); - the DCP firmware DART and the display frontend DART name their clock protection slices, 42 and 8, as the ADT does; - the DCP names the internal pipe's PMC interface. The power states are in the policy the J715 shares, where nothing uses them yet: only the J713 names the PMC interface, and the J715 is untested. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Bartosz Nitka --- arch/arm64/boot/dts/apple/t8132-j713-pmgr.dtsi | 6 ++++++ arch/arm64/boot/dts/apple/t8132-j713.dts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8132-j713-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8132-j713-pmgr.dtsi index 7f0e91c4002eb..e6a1ab6ebeb34 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713-pmgr.dtsi +++ b/arch/arm64/boot/dts/apple/t8132-j713-pmgr.dtsi @@ -105,13 +105,16 @@ status = "disabled"; }; +/* The DCP powers these down while the display is off. */ &ps_disp_sys { apple,firmware-owned; + apple,consumer-switched; status = "okay"; }; &ps_disp_fe { apple,firmware-owned; + apple,consumer-switched; status = "okay"; }; @@ -531,6 +534,9 @@ &ps_disp_cpu { apple,firmware-owned; + apple,consumer-switched; + /* Power-gate retention workaround, as macOS sets it while off. */ + apple,retention-workaround = <0x2504c 0x3 0x3>, <0x25070 0x1 0x0>; status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index b4a0813268ebf..94bfc49c5e279 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -150,3 +150,19 @@ firmware-name = "apple/mesacal-j713.bin", "apple/msrk-j713.bin"; }; +/* + * The DCP powers its display domains down while blanked + * (appledrm.power_gate_ms): the clock protection slices of its DARTs, as the + * ADT has them, and the internal pipe's PMC interface. + */ +&dcp_dart { + apple,clock-protection = <&ps_prot 42>; +}; + +&disp0_dart { + apple,clock-protection = <&ps_prot 8>; +}; + +&dcp { + apple,pmc-interface = <&pmc_disp0>; +}; From 7f520fa2006068602587206edc2f86c846319a75 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:54:09 +1100 Subject: [PATCH 251/342] dt-bindings: pci: apple,pcie: allow a second power domain The internal PCIe controller on T6040 and T8112 needs two power domain chains to stay on while its links are up. Allow up to two entries. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/devicetree/bindings/pci/apple,pcie.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 245231ecfc3a9..bbf26a8960b43 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -135,7 +135,13 @@ properties: iommu-map-mask: true power-domains: - maxItems: 1 + description: + The power domains the controller needs. Internal controllers on some + SoCs sit behind two separate domain chains (for example the PCIe + system and PHY domains), all of which must stay on while the links + are up. + minItems: 1 + maxItems: 2 resets: description: From a9a6b2fbe9ae64946710b20e76bb0d48c5d4a0ed Mon Sep 17 00:00:00 2001 From: "Michal S." Date: Mon, 9 Nov 2026 13:15:40 +0000 Subject: [PATCH 252/342] wifi: brcmfmac: preserve the requested RSNE for WCC SAE offload Clearing wpaie in the common SAE path discards userspace cipher constraints. On BCM4388, WCC firmware then constructs a GCMP-256 association RSNE for a CCMP-only request, which supplicant rejects with reason 19. Retaining the requested RSNE produces a CCMP SAE connection, and firmware still appends its PMKID. Keep CYW station/client RSNE clearing in its firmware vendor callback. Leave AP password setup unchanged and propagate clearing failures. Cover the production CONNECT offload stage and WCC/CYW callbacks with 13 host controls and an original-code negative control. Hardware validation is limited to J614s. Signed-off-by: Michal S. Assisted-By: LLM --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 7 - .../broadcom/brcm80211/brcmfmac/cyw/core.c | 10 + tools/asahi/brcmf-sae-vendor-tests.py | 325 ++++++++++++++++++ tools/asahi/run-host-tests.py | 2 + 4 files changed, 337 insertions(+), 7 deletions(-) create mode 100755 tools/asahi/brcmf-sae-vendor-tests.py diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 65d38c4b0952b..398d252c3928a 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -2595,13 +2595,6 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, err = brcmf_set_pmk(ifp, params->crypto.psk, BRCMF_WSEC_MAX_PSK_LEN); else if (profile->use_fwsup == BRCMF_PROFILE_FWSUP_SAE) { - /* clean up user-space RSNE */ - if (brcmf_fil_iovar_data_set(ifp, "wpaie", NULL, 0)) { - bphy_err( - drvr, - "failed to clean up user-space RSNE\n"); - goto done; - } err = brcmf_fwvid_set_sae_password(ifp, ¶ms->crypto); if (!err && params->crypto.psk) err = brcmf_set_pmk(ifp, params->crypto.psk, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c index 6d5098f6f00f9..ababf34df8b0f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cyw/core.c @@ -31,6 +31,16 @@ static int brcmf_cyw_set_sae_pwd(struct brcmf_if *ifp, u16 pwd_len = crypto->sae_pwd_len; int err; + /* CYW firmware generates the station RSNE during SAE offload. */ + if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION || + ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) { + err = brcmf_fil_iovar_data_set(ifp, "wpaie", NULL, 0); + if (err) { + bphy_err(drvr, "failed to clean up user-space RSNE\n"); + return err; + } + } + if (pwd_len > BRCMF_WSEC_MAX_SAE_PASSWORD_LEN) { bphy_err(drvr, "sae_password must be less than %d\n", BRCMF_WSEC_MAX_SAE_PASSWORD_LEN); diff --git a/tools/asahi/brcmf-sae-vendor-tests.py b/tools/asahi/brcmf-sae-vendor-tests.py new file mode 100755 index 0000000000000..1d8052c5ecdac --- /dev/null +++ b/tools/asahi/brcmf-sae-vendor-tests.py @@ -0,0 +1,325 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Exercise SAE offload RSNE handling through the firmware vendor callbacks.""" + +import argparse +import importlib.util +import json +import os +import re +import subprocess +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DRIVER = Path("drivers/net/wireless/broadcom/brcm80211/brcmfmac") +spec = importlib.util.spec_from_file_location( + "association", ROOT / "tools/asahi/brcmf-assoc-tests.py" +) +association = importlib.util.module_from_spec(spec) +spec.loader.exec_module(association) + +PREFIX = r""" + +#include +#include +#include +#include +#include +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint16_t __le16; +#define BIT(n) (1U << (n)) +#define WARN_ON(condition) (condition) +#define brcmf_dbg(...) ((void)0) +#define bphy_err(context, ...) ((void)(context)) +#define BRCMF_FEAT_FWSUP 1 +enum { + NL80211_IFTYPE_STATION, + NL80211_IFTYPE_P2P_CLIENT, + NL80211_IFTYPE_AP, + NL80211_IFTYPE_P2P_GO +}; +struct cfg80211_crypto_settings { + const u8 *sae_pwd, *psk; + u16 sae_pwd_len; +}; +struct cfg80211_connect_params { + struct cfg80211_crypto_settings crypto; +}; +struct brcmf_if; +struct brcmf_fwvid_ops { + int (*set_sae_password)(struct brcmf_if *, + struct cfg80211_crypto_settings *); +}; +struct brcmf_pub { + const struct brcmf_fwvid_ops *vops; +}; +struct brcmf_profile { + int use_fwsup; +}; +struct brcmf_vif { + struct { + int iftype; + } wdev; + struct brcmf_profile profile; +}; +struct brcmf_if { + struct brcmf_pub *drvr; + struct brcmf_vif *vif; +}; +enum { CLEAR_RSNE, CYW_PASSWORD, WCC_PASSWORD, SET_PMK }; +static int commands[8], count; +static int clear_error, password_error, pmk_error, sup_error; +static bool fwsup; +static u16 cpu_to_le16(u16 value) +{ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return value; +#else + return __builtin_bswap16(value); +#endif +} +static bool brcmf_feat_is_enabled(struct brcmf_if *ifp, int feature) +{ + (void)ifp; + assert(feature == BRCMF_FEAT_FWSUP); + return fwsup; +} +static int brcmf_fil_iovar_int_set(struct brcmf_if *ifp, const char *name, + int value) +{ + (void)ifp; + assert(!strcmp(name, "sup_wpa") && (value == 0 || value == 1)); + return sup_error; +} +static int brcmf_fil_iovar_data_set(struct brcmf_if *ifp, const char *name, + const void *data, unsigned int length) +{ + (void)ifp; + assert(count < 8); + if (!strcmp(name, "wpaie")) { + assert(!data && !length); + commands[count++] = CLEAR_RSNE; + return clear_error; + } + assert(!strcmp(name, "sae_password") && data && length); + commands[count++] = CYW_PASSWORD; + return password_error; +} +static int brcmf_set_wsec(struct brcmf_if *ifp, const u8 *password, u16 length, + unsigned int flags) +{ + (void)ifp; + assert(password && length == 8 && flags == BRCMF_WSEC_PASSPHRASE); + commands[count++] = WCC_PASSWORD; + return password_error; +} +static int brcmf_set_pmk(struct brcmf_if *ifp, const u8 *pmk, u16 length) +{ + (void)ifp; + assert(pmk && length == BRCMF_WSEC_MAX_PSK_LEN); + commands[count++] = SET_PMK; + return pmk_error; +} +""" + +MAIN = r""" + +static const struct brcmf_fwvid_ops wcc = { .set_sae_password = + brcmf_wcc_set_sae_pwd }; +static const struct brcmf_fwvid_ops cyw = { .set_sae_password = + brcmf_cyw_set_sae_pwd }; +static struct brcmf_pub pub; +static struct brcmf_vif vif; +static struct brcmf_if ifp = { &pub, &vif }; +static struct cfg80211_connect_params params; +static const u8 password[] = "test-sae"; +static const u8 pmk[BRCMF_WSEC_MAX_PSK_LEN]; +static void reset(const struct brcmf_fwvid_ops *vendor, int type) +{ + pub.vops = vendor; + vif.wdev.iftype = type; + vif.profile.use_fwsup = BRCMF_PROFILE_FWSUP_SAE; + params.crypto = (struct cfg80211_crypto_settings){ + .sae_pwd = password, + .sae_pwd_len = sizeof(password) - 1, + }; + count = clear_error = password_error = pmk_error = sup_error = 0; + fwsup = true; +} +int main(void) +{ + unsigned int controls = 0; + reset(&wcc, NL80211_IFTYPE_STATION); + assert(!offload_setup(&ifp, ¶ms)); + assert(count == 1 && commands[0] == WCC_PASSWORD); + controls++; + + const int types[] = { NL80211_IFTYPE_STATION, NL80211_IFTYPE_P2P_CLIENT, + NL80211_IFTYPE_AP, NL80211_IFTYPE_P2P_GO }; + for (unsigned int i = 0; i < 4; i++) { + reset(&cyw, types[i]); + if (i < 2) { + assert(!offload_setup(&ifp, ¶ms)); + assert(count == 2 && commands[0] == CLEAR_RSNE && + commands[1] == CYW_PASSWORD); + } else { + assert(!brcmf_fwvid_set_sae_password(&ifp, + ¶ms.crypto)); + assert(count == 1 && commands[0] == CYW_PASSWORD); + } + controls++; + } + reset(&cyw, NL80211_IFTYPE_STATION); + clear_error = -EIO; + assert(offload_setup(&ifp, ¶ms) == -EIO); + assert(count == 1 && commands[0] == CLEAR_RSNE); + controls++; + + reset(&cyw, NL80211_IFTYPE_STATION); + password_error = -EIO; + params.crypto.psk = pmk; + assert(offload_setup(&ifp, ¶ms) == -EIO); + assert(count == 2 && commands[1] == CYW_PASSWORD); + controls++; + + reset(&wcc, NL80211_IFTYPE_STATION); + password_error = -EIO; + assert(offload_setup(&ifp, ¶ms) == -EIO); + assert(count == 1 && commands[0] == WCC_PASSWORD); + controls++; + + reset(&wcc, NL80211_IFTYPE_STATION); + params.crypto.psk = pmk; + assert(!offload_setup(&ifp, ¶ms)); + assert(count == 2 && commands[0] == WCC_PASSWORD && + commands[1] == SET_PMK); + controls++; + + reset(&wcc, NL80211_IFTYPE_STATION); + params.crypto.psk = pmk; + pmk_error = -EIO; + assert(offload_setup(&ifp, ¶ms) == -EIO); + assert(count == 2 && commands[1] == SET_PMK); + controls++; + + reset(&wcc, NL80211_IFTYPE_STATION); + vif.profile.use_fwsup = BRCMF_PROFILE_FWSUP_NONE; + params.crypto.psk = pmk; + assert(!offload_setup(&ifp, ¶ms)); + assert(count == 1 && commands[0] == SET_PMK); + controls++; + + reset(NULL, NL80211_IFTYPE_STATION); + assert(offload_setup(&ifp, ¶ms) == -EOPNOTSUPP); + assert(!count); + controls++; + + reset(&wcc, NL80211_IFTYPE_STATION); + sup_error = -EIO; + assert(offload_setup(&ifp, ¶ms) == -EIO && !count); + controls++; + + printf("%u SAE vendor setup controls passed\n", controls); + return 0; +} +""" + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--ref") + parser.add_argument("--out", type=Path) + args = parser.parse_args() + + def read(name): + path = DRIVER / name + if args.ref: + return subprocess.check_output( + ["git", "show", f"{args.ref}:{path}"], cwd=ROOT, text=True + ) + return (ROOT / path).read_text() + + cfg = read("cfg80211.c") + header = read("cfg80211.h") + types = read("fwil_types.h") + start = header.index("enum brcmf_profile_fwsup {") + constants = re.findall( + r"^#define\s+(?:BRCMF_WSEC_MAX_(?:PSK_LEN|SAE_PASSWORD_LEN)|BRCMF_WSEC_PASSPHRASE)\s+.*$", + types, + re.M, + ) + # Execute the production CONNECT offload stage, including its error exits. + connect = association.function(cfg, "brcmf_cfg80211_connect") + start_block = connect.index("\tif (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_FWSUP)) {") + opening = connect.index("{", start_block) + depth, end = 1, opening + 1 + while depth: + depth += (connect[end] == "{") - (connect[end] == "}") + end += 1 + setup = """ +static int offload_setup(struct brcmf_if *ifp, struct cfg80211_connect_params *params) +{ + struct brcmf_pub *drvr = ifp->drvr; + struct brcmf_profile *profile = &ifp->vif->profile; + int err = 0; +""" + connect[start_block:end] + "\ndone:\n return err;\n}\n" + parts = [ + "\n".join(constants), + PREFIX, + header[start : header.index("};", start) + 2], + association.structure(types, "brcmf_wsec_sae_pwd_le"), + association.function(read("cyw/core.c"), "brcmf_cyw_set_sae_pwd"), + association.function(read("wcc/core.c"), "brcmf_wcc_set_sae_pwd"), + association.function(read("fwvid.h"), "brcmf_fwvid_set_sae_password"), + setup, + MAIN, + ] + + def run(out): + out.mkdir(parents=True, exist_ok=True) + source, binary = out / "controls.c", out / "controls" + source.write_text("\n".join(parts)) + subprocess.run( + [ + os.environ.get("CC", "clang"), + "-std=gnu11", + "-O1", + "-g", + "-Wall", + "-Wextra", + "-Werror", + "-fsanitize=address,undefined", + "-fno-sanitize-recover=all", + str(source), + "-o", + str(binary), + ], + check=True, + ) + result = subprocess.run([str(binary)], capture_output=True, text=True) + (out / "results.json").write_text( + json.dumps( + { + "exit": result.returncode, + "stdout": result.stdout, + "stderr": result.stderr, + "limits": "CONNECT offload stage and vendor callbacks with host firmware stubs; no radio.", + }, + indent=2, + ) + + "\n" + ) + print(result.stdout or result.stderr, end="") + return result.returncode != 0 + + if args.out: + return run(args.out.resolve()) + with tempfile.TemporaryDirectory(prefix="brcmf-sae-vendor-") as out: + return run(Path(out)) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 9c7816cdba386..e999457ca8d04 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -93,6 +93,8 @@ def mutations(flag, names, base, expect=KILL): 'brcmf-pcie-dma-tests.py': [(out('--output'), PASS)] + mutations('--mutation', ('narrow-stream', 'ignore-aperture', 'revision-wide'), out('--output')), 'brcmf-roam-tests.py': [(out(), PASS)], + 'brcmf-sae-vendor-tests.py': [(out(), PASS)] + + [(out() + ['--ref', '9260e1f021e075713931f3c23c0a5fa1da936b0b'], KILL)], 'brcmf-suspend-tests.py': [(out(), PASS)] + mutations('--mutation', ('country-gate', 'queue-reasons', 'worker-gate', 'resume-order', 'tx-drain'), out()), From fdc0471b71abb18c1affb79bec67dac2ae0c75c2 Mon Sep 17 00:00:00 2001 From: "Michal S." Date: Mon, 9 Nov 2026 13:15:40 +0000 Subject: [PATCH 253/342] wifi: brcmfmac: use firmware join scan budgets with AWDL On BCM4388, fixed channel-directed join dwell and probe budgets can stall association with AWDL enabled. Use documented firmware defaults when an AWDL interface shares the radio, preserving channel and BSSID hints and the existing budget without AWDL. Keep AWDL configuration and lifecycle intact. Test both join formats and register an original-code negative control. J614s boot, reconnect and subsequent AirDrop transfer passed; quick firmware join failures requiring automatic retries remain unresolved. Signed-off-by: Michal S. Assisted-By: LLM --- .../broadcom/brcm80211/brcmfmac/core.c | 21 ++ .../broadcom/brcm80211/brcmfmac/core.h | 1 + .../broadcom/brcm80211/brcmfmac/join_param.c | 13 +- tools/asahi/brcmf-join-scan-tests.py | 302 ++++++++++++++++++ tools/asahi/run-host-tests.py | 2 + 5 files changed, 332 insertions(+), 7 deletions(-) create mode 100755 tools/asahi/brcmf-join-scan-tests.py diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c index 2b6ec64fe0bbc..329c40dac2db7 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c @@ -767,6 +767,27 @@ static const struct net_device_ops brcmf_netdev_ops_pri = { .ndo_set_rx_mode = brcmf_netdev_set_multicast_list }; +bool brcmf_has_awdl_interface(struct brcmf_pub *drvr) +{ + struct net_device *ndev; + struct brcmf_if *ifp; + bool present = false; + + rcu_read_lock(); + for_each_netdev_rcu(wiphy_net(drvr->wiphy), ndev) { + if (ndev->netdev_ops != &brcmf_netdev_ops_awdl) + continue; + ifp = netdev_priv(ndev); + if (ifp->drvr == drvr) { + present = true; + break; + } + } + rcu_read_unlock(); + + return present; +} + int brcmf_net_attach(struct brcmf_if *ifp, bool locked) { struct brcmf_pub *drvr = ifp->drvr; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h index 229c24abad328..f7b31b17becfb 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.h @@ -283,6 +283,7 @@ char *brcmf_ifname(struct brcmf_if *ifp); struct brcmf_if *brcmf_get_ifp(struct brcmf_pub *drvr, int ifidx); void brcmf_configure_arp_nd_offload(struct brcmf_if *ifp, bool enable); int brcmf_net_attach(struct brcmf_if *ifp, bool locked); +bool brcmf_has_awdl_interface(struct brcmf_pub *drvr); struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bsscfgidx, s32 ifidx, bool is_p2pdev, const char *name, u8 *mac_addr); void brcmf_remove_interface(struct brcmf_if *ifp, bool locked); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/join_param.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/join_param.c index 4f026571c7e7e..5dba0fc7968ff 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/join_param.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/join_param.c @@ -118,14 +118,15 @@ brcmf_get_prepped_struct_for_ibss_v1(struct brcmf_cfg80211_info *cfg, } static void -brcmf_joinscan_set_common_v0v1_params(struct brcmf_join_scan_params_le *scan_le, - bool have_channel) +brcmf_joinscan_set_common_v0v1_params(struct brcmf_cfg80211_info *cfg, + struct brcmf_join_scan_params_le *scan_le) { /* Set up join scan parameters */ scan_le->scan_type = 0; scan_le->home_time = cpu_to_le32(-1); - if (have_channel) { + /* Let firmware budget the scan around AWDL availability windows. */ + if (cfg->channel && !brcmf_has_awdl_interface(cfg->pub)) { /* Increase dwell time to receive probe response or detect * beacon from target AP at a noisy air only during connect * command. @@ -166,8 +167,7 @@ brcmf_get_struct_for_connect_v0(struct brcmf_cfg80211_info *cfg, } brcmf_joinscan_set_ssid(&ext_v0->ssid_le, params->ssid, params->ssid_len); - brcmf_joinscan_set_common_v0v1_params(&ext_v0->scan_le, - cfg->channel != 0); + brcmf_joinscan_set_common_v0v1_params(cfg, &ext_v0->scan_le); brcmf_joinscan_set_bssid(ext_v0->assoc_le.bssid, params->bssid); if (cfg->channel) { struct ieee80211_channel *chan = params->channel_hint ? @@ -201,8 +201,7 @@ brcmf_get_struct_for_connect_v1(struct brcmf_cfg80211_info *cfg, ext_v1->assoc_le.version = cpu_to_le16(1); brcmf_joinscan_set_ssid(&ext_v1->ssid_le, params->ssid, params->ssid_len); - brcmf_joinscan_set_common_v0v1_params(&ext_v1->scan_le, - cfg->channel != 0); + brcmf_joinscan_set_common_v0v1_params(cfg, &ext_v1->scan_le); brcmf_joinscan_set_bssid(ext_v1->assoc_le.bssid, params->bssid); if (cfg->channel) { struct ieee80211_channel *chan = params->channel_hint ? diff --git a/tools/asahi/brcmf-join-scan-tests.py b/tools/asahi/brcmf-join-scan-tests.py new file mode 100755 index 0000000000000..2ce46e52e55e0 --- /dev/null +++ b/tools/asahi/brcmf-join-scan-tests.py @@ -0,0 +1,302 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Exercise the v0/v1 join constructors with and without AWDL.""" + +import argparse +import json +import os +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DRIVER = Path("drivers/net/wireless/broadcom/brcm80211/brcmfmac") + +PREFIX = r""" + +#include +#include +#include +#include +#include +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint16_t __le16; +typedef uint32_t __le32; +#define ETH_ALEN 6 +#define IEEE80211_MAX_SSID_LEN 32 +#define GFP_KERNEL 0 +#define bphy_err(...) ((void)0) +#define brcmf_dbg(...) ((void)0) +#define min_t(type, a, b) ((type)(a) < (type)(b) ? (type)(a) : (type)(b)) +#define struct_size(p, member, count) \ + (sizeof(*(p)) + sizeof((p)->member[0]) * (count)) +static uint16_t cpu_to_le16(uint16_t value) +{ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return value; +#else + return __builtin_bswap16(value); +#endif +} +static uint32_t cpu_to_le32(uint32_t value) +{ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return value; +#else + return __builtin_bswap32(value); +#endif +} +#define le32_to_cpu(value) cpu_to_le32(value) +struct brcmf_pub { + bool awdl; +}; +struct brcmf_cfg80211_info { + u32 channel; + unsigned int d11inf; + struct brcmf_pub *pub; +}; +struct ieee80211_channel { + u16 chanspec; +}; +struct cfg80211_connect_params { + const u8 *ssid; + size_t ssid_len; + const u8 *bssid; + struct ieee80211_channel *channel, *channel_hint; +}; +bool brcmf_has_awdl_interface(struct brcmf_pub *pub) +{ + return pub->awdl; +} +static void *kzalloc(size_t size, int flags) +{ + (void)flags; + return calloc(1, size); +} +static void eth_broadcast_addr(u8 *address) +{ + memset(address, 0xff, ETH_ALEN); +} +static u16 channel_to_chanspec(unsigned int *d11inf, + struct ieee80211_channel *channel) +{ + (void)d11inf; + return channel->chanspec; +} +""" + +MAIN = r""" + +int main(void) +{ + const u8 ssid[] = "test"; + const u8 bssid[ETH_ALEN] = { 0x02, 0, 0, 0, 0, 1 }; + struct ieee80211_channel channel = { .chanspec = 0xd034 }; + unsigned int controls = 0; + + for (int version = 0; version <= 1; version++) { + for (int selection = 0; selection < 3; selection++) { + for (int awdl = 0; awdl <= 1; awdl++) { + struct brcmf_pub pub = { .awdl = awdl }; + struct brcmf_cfg80211_info cfg = { + .channel = selection ? 52 : 0, + .pub = &pub, + }; + struct cfg80211_connect_params params = { + .ssid = ssid, + .ssid_len = sizeof(ssid) - 1, + .bssid = bssid, + .channel_hint = selection == 1 ? + &channel : + NULL, + .channel = selection == 2 ? &channel : + NULL, + }; + u32 size; + struct brcmf_ext_join_params_le *v0 = NULL; + struct brcmf_ext_join_params_v1_le *v1 = NULL; + struct brcmf_join_scan_params_le *scan; + struct brcmf_ssid_le *sent_ssid; + const u8 *sent_bssid; + u32 channels; + u16 chanspec = 0; + bool extended = selection && !awdl; + + if (version) { + v1 = brcmf_get_struct_for_connect_v1( + &cfg, &size, ¶ms); + assert(v1); + assert(v1->version == cpu_to_le16(1)); + assert(v1->assoc_le.version == + cpu_to_le16(1)); + assert(v1->assoc_le.flags == 0); + scan = &v1->scan_le; + sent_ssid = &v1->ssid_le; + sent_bssid = v1->assoc_le.bssid; + channels = le32_to_cpu( + v1->assoc_le.chanspec_num); + if (selection) + chanspec = + v1->assoc_le + .chanspec_list[0]; + assert(size == + sizeof(*v1) + + (selection ? + sizeof(u16) : + 0)); + } else { + v0 = brcmf_get_struct_for_connect_v0( + &cfg, &size, ¶ms); + assert(v0); + scan = &v0->scan_le; + sent_ssid = &v0->ssid_le; + sent_bssid = v0->assoc_le.bssid; + channels = le32_to_cpu( + v0->assoc_le.chanspec_num); + if (selection) + chanspec = + v0->assoc_le + .chanspec_list[0]; + assert(size == + sizeof(*v0) + + (selection ? + sizeof(u16) : + 0)); + } + + assert(scan->scan_type == 0); + assert(scan->home_time == cpu_to_le32(-1)); + assert(scan->active_time == + cpu_to_le32(extended ? 320 : -1)); + assert(scan->passive_time == + cpu_to_le32(extended ? 400 : -1)); + assert(scan->nprobes == + cpu_to_le32(extended ? 16 : -1)); + assert(channels == (selection ? 1U : 0U)); + if (selection) + assert(chanspec == + cpu_to_le16(channel.chanspec)); + assert(le32_to_cpu(sent_ssid->SSID_len) == + sizeof(ssid) - 1); + assert(!memcmp(sent_ssid->SSID, ssid, + sizeof(ssid) - 1)); + assert(!memcmp(sent_bssid, bssid, ETH_ALEN)); + free(version ? (void *)v1 : (void *)v0); + controls++; + } + } + } + printf("%u join scan controls passed\n", controls); + return 0; +} +""" + + +def function(source, name): + match = re.search(r"^static\s+void\s*\*?\s*" + name + r"\(", source, re.M) + if not match: + raise ValueError(name) + opening = source.index("{", match.end()) + depth, end = 1, opening + 1 + while depth: + depth += (source[end] == "{") - (source[end] == "}") + end += 1 + return source[match.start() : end] + "\n" + + +def structure(source, name): + match = re.search(r"struct " + name + r"\s*\{", source) + if not match: + raise ValueError(name) + end = source.index("};", match.end()) + 2 + return source[match.start() : end] + "\n" + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--root", type=Path, default=ROOT) + parser.add_argument("--ref", help="Git source revision to exercise") + parser.add_argument("--out", type=Path, help="retain executable and results") + parser.add_argument("--cc", default=os.environ.get("CC", "clang")) + args = parser.parse_args() + + def read(name): + path = DRIVER / name + if args.ref: + return subprocess.check_output( + ["git", "show", f"{args.ref}:{path}"], cwd=args.root, text=True + ) + return (args.root / path).read_text() + + source = read("join_param.c") + types = read("fwil_types.h") + constants = "\n".join(re.findall(r"^#define BRCMF_SCAN_JOIN_.*$", source, re.M)) + structures = "".join( + structure(types, name) + for name in [ + "brcmf_ssid_le", + "brcmf_join_scan_params_le", + "brcmf_assoc_params_le", + "brcmf_assoc_params_v1_le", + "brcmf_ext_join_params_le", + "brcmf_ext_join_params_v1_le", + ] + ) + bodies = "".join( + function(source, name) + for name in [ + "brcmf_joinscan_set_ssid", + "brcmf_joinscan_set_bssid", + "brcmf_joinscan_set_single_chanspec_from_channel", + "brcmf_joinscan_set_common_v0v1_params", + "brcmf_get_struct_for_connect_v0", + "brcmf_get_struct_for_connect_v1", + ] + ) + code = PREFIX + constants + "\n" + structures + bodies + MAIN + + def run(out): + out.mkdir(parents=True, exist_ok=True) + src, exe = out / "controls.c", out / "controls" + src.write_text(code) + subprocess.run( + [ + args.cc, + "-std=gnu11", + "-O1", + "-g", + "-Wall", + "-Wextra", + "-Werror", + "-fsanitize=address,undefined", + "-fno-sanitize-recover=all", + str(src), + "-o", + str(exe), + ], + check=True, + ) + result = subprocess.run([str(exe)], capture_output=True, text=True, cwd=out) + receipt = { + "exit": result.returncode, + "stdout": result.stdout, + "stderr": result.stderr, + "limits": "Join constructors run with host stubs; no firmware or radio.", + } + (out / "results.json").write_text(json.dumps(receipt, indent=2) + "\n") + sys.stdout.write(result.stdout or result.stderr) + return result.returncode != 0 + + if args.out: + return run(args.out.resolve()) + with tempfile.TemporaryDirectory(prefix="brcmf-join-scan-") as out: + return run(Path(out)) + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index b878404b2d9fa..49e9b5540107c 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -88,6 +88,8 @@ def mutations(flag, names, base, expect=KILL): # The old revision reports a failed join against the last associated BSS. 'brcmf-join-bssid-tests.py': [(out(), PASS)] + mutations('--mutation', ('stale-target', 'zero-named', 'no-call', 'lost-bss-success'), out()), + 'brcmf-join-scan-tests.py': [(out(), PASS)] + + [(out() + ['--ref', '33bec4016c466985bfbb5ff4c2089fcab8242dcf'], KILL)], 'brcmf-pcie-dma-tests.py': [(out('--output'), PASS)] + mutations('--mutation', ('narrow-stream', 'ignore-aperture', 'revision-wide'), out('--output')), 'brcmf-roam-tests.py': [(out(), PASS)], From 5ad2c72abf9864c3b5b1c87266a16b7e4abd3517 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 08:46:47 -0500 Subject: [PATCH 254/342] cpufreq: apple: Add the T6050 thermal-owned profile The T6050 clusters' DVFS command register reads back the last request it accepted, not a measured state, so the profile verifies each transition against that readback, with a 2 ms timeout. On this chip the firmware owns the clusters' thermal limits; the profile refuses a cluster whose node doesn't say so (apple,firmware-managed-thermal), and the binding requires that property for apple,t6050-cluster-cpufreq. Tested on J714s (M5 Pro, bare metal under aura Stage 2): all three clusters bind (M 300-4380 MHz, P 300-4608 MHz, schedutil) with no DVFS error; idle clusters sit at 300 MHz and loaded ones at their top state. Clocks measured with a dependent add chain go from iBoot's 2.65/1.34/ 1.31 GHz to 4.29/4.38/4.60 GHz (with WFI idle); one-thread work is 1.6x faster on M and 3.4x on P, and idle system power drops from 20.1 to 7.2-7.9 W while idle still spins under idle=nop. Carried for the bare-metal kit by Erik Bourget (#944). Signed-off-by: Diljit Singh --- .../cpufreq/apple,cluster-cpufreq.yaml | 10 ++++++++ drivers/cpufreq/apple-soc-cpufreq.c | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml b/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml index 807eb00b967eb..b7ed80708377e 100644 --- a/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml +++ b/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml @@ -84,6 +84,16 @@ required: - reg - '#performance-domain-cells' +allOf: + - if: + properties: + compatible: + contains: + const: apple,t6050-cluster-cpufreq + then: + required: + - apple,firmware-managed-thermal + additionalProperties: false examples: diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c index 85e592faa0538..fb87ae6ae137a 100644 --- a/drivers/cpufreq/apple-soc-cpufreq.c +++ b/drivers/cpufreq/apple-soc-cpufreq.c @@ -206,6 +206,7 @@ struct apple_soc_cpufreq_info { /* Fail closed when the DT describes no fast die-temperature limit. */ bool needs_thermal_policy; bool needs_thermal_owner; + bool needs_firmware_thermal_control; u32 transition_timeout_us; /* Highest P-state allowed without a thermal policy; 0 if not capped. */ u32 max_unmanaged_pstate; @@ -340,6 +341,16 @@ static const struct apple_soc_cpufreq_info soc_t8132_info = { .ps1_shift = APPLE_DVFS_CMD_PS1_SHIFT, }; +/* Command-state readback, not a measurement of the clock frequency. */ +static const struct apple_soc_cpufreq_info soc_t6050_info = { + .verify_transition = true, + .needs_firmware_thermal_control = true, + .transition_timeout_us = 2000, + .max_pstate = 31, + .ps1_mask = APPLE_DVFS_CMD_PS1, + .ps1_shift = APPLE_DVFS_CMD_PS1_SHIFT, +}; + static const struct apple_soc_cpufreq_info soc_default_info = { .has_ps2 = false, .max_pstate = 15, @@ -373,6 +384,10 @@ static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = { .compatible = "apple,t8140-cluster-cpufreq", .data = &soc_t8140_info, }, + { + .compatible = "apple,t6050-cluster-cpufreq", + .data = &soc_t6050_info, + }, { .compatible = "apple,t8142-cluster-cpufreq", .data = &soc_t8142_info, @@ -1355,6 +1370,14 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) goto out_free_priv; } + /* The boot producer must retain and qualify firmware thermal control. */ + if (info->needs_firmware_thermal_control && + !of_property_read_bool(cluster, "apple,firmware-managed-thermal")) { + dev_err(cpu_dev, "firmware thermal ownership is not declared\n"); + ret = -ENODEV; + goto out_iounmap; + } + ret = dev_pm_opp_of_cpumask_add_table(policy->cpus); if (ret < 0) { dev_err(cpu_dev, "%s: failed to add OPP table: %d\n", __func__, ret); From 227ed461886c243a633535468d3549e267440094 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:48:16 +1100 Subject: [PATCH 255/342] soc: apple: sep: Report endpoints, timing, identity and errors in diag macOS lists every SEP endpoint as its own service (sep-endpoint,cntl, sep-endpoint,sks, ...), but diag only had a count, and the names were only in two info lines per endpoint in the kernel log: 24 lines on every boot, gone again once the ring wrapped. Several states had no report at all: where the OS identity for the xART exchange came from, whether the hwrng survey registered, how long the bring-up took, and the xART requests the driver failed, which did not log. Add, keeping every existing attribute and value as it was: - endpoint_names: the advertised endpoints by their four-character names, in endpoint order; - attach_ms, ready_ms: milliseconds from probe to the attach decision and to the end of the boot-time bring-up; - os_identity: explicit, chosen or unavailable; - hwrng: pending, registered or failed; - xarm_failures: every xART request answered with the failure status, the guard's refusals included; the first is now logged; - unhandled_messages: messages on endpoints without a handler, logged only the first few times; - sleep, sleeps: held between the PM prepare and post events, and the number of completed sleep cycles. The per-message discovery trace moves to debug level, and one line replaces it at the end of the bring-up: ready in 4106 ms: 12 endpoints (cntl sbio scrd sse hdcp xars sks xarm hibe pnon skdl stac), key store open The attributes are only added, so the diag ABI stays at 2. Each read still only loads cached words and sends nothing to the SEP. Assisted-by: LLM Signed-off-by: Ryan Murray --- .../ABI/testing/sysfs-driver-apple-sep | 96 +++++++ drivers/soc/apple/diag.rs | 58 ++++ drivers/soc/apple/diag_shim.c | 248 ++++++++++++++++++ drivers/soc/apple/pm_shim.c | 2 + drivers/soc/apple/sep.rs | 62 ++++- drivers/soc/apple/shim.h | 17 ++ 6 files changed, 469 insertions(+), 14 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-apple-sep b/Documentation/ABI/testing/sysfs-driver-apple-sep index b48d26187f67d..2bddd85d523d4 100644 --- a/Documentation/ABI/testing/sysfs-driver-apple-sep +++ b/Documentation/ABI/testing/sysfs-driver-apple-sep @@ -359,3 +359,99 @@ Description: tools/aurora-sep/XART-SAFETY.md. During a boot the value can only move from "unverified" to "blocked", once the guard refuses a write. + +What: /sys/bus/platform/devices/.sep/diag/attach_ms +What: /sys/bus/platform/devices/.sep/diag/ready_ms +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) How long the bring-up took, as unsigned decimal + milliseconds counted from probe on the boot-time clock. + attach_ms is the time to the attach decision (see attach); + ready_ms is the time to the end of the boot-time bring-up, + when keystore is decided. Each reads "0" until its decision + is made. A large ready_ms with keystore "open" is an enclave + that was slow to advertise the key store; the driver waits + up to 90 s for it. + +What: /sys/bus/platform/devices/.sep/diag/endpoint_names +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) The endpoints the SEP has advertised, as the + four-character names their descriptors carry with trailing + spaces dropped, separated by single spaces, in endpoint + number order, for example "cntl sbio scrd sse hdcp xars sks + xarm hibe pnon skdl stac". A name that is not lower-case + letters and digits is shown as the endpoint number in two + hex digits. Empty until the first endpoint is advertised; + discovery goes on after the attach, so the list can still + grow, like endpoints. + +What: /sys/bus/platform/devices/.sep/diag/os_identity +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) Where the OS identity that the driver gives the + enclave's xART exchange came from. Decided at the attach. + + =========== ========================================= + unknown Not decided yet. + explicit The os_uuid_hi and os_uuid_lo parameters. + chosen /chosen/apfs-preboot-uuid, as the boot + loader passed it. + unavailable Neither; the enclave is told the identity + is unavailable and its xART records for + this OS cannot be found. + =========== ========================================= + +What: /sys/bus/platform/devices/.sep/diag/hwrng +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) The enclave's random number source. "pending" until + the survey after the bring-up decides, then "registered" + (it is an hwrng, named apple-sep) or "failed" (the survey + gave up; the kernel log says why). + +What: /sys/bus/platform/devices/.sep/diag/xarm_failures +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) How many of the enclave's xART requests the driver has + answered with the failure status since probe, as an unsigned + decimal: a store read or write that failed, a bad checksum, + an unknown request, a buffer that was not ready, and the + writes the xART guard refused (also counted in + xart_guard_refusals). The first is logged; this counts them + all. Anything above xart_guard_refusals is a failure that + was not the guard's choice. + +What: /sys/bus/platform/devices/.sep/diag/unhandled_messages +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) How many messages arrived on an endpoint the driver has + no handler for, as an unsigned decimal. The first few are + logged. Normally 0. + +What: /sys/bus/platform/devices/.sep/diag/sleep +What: /sys/bus/platform/devices/.sep/diag/sleeps +Date: November 2026 +KernelVersion: 7.3 +Contact: Ryan Murray +Description: + (RO) The driver's view of system sleep. sleep reads "held" + from the PM notifier's prepare event to its post event, + while Touch ID captures and entropy requests are held, and + "awake" otherwise. sleeps counts completed prepare/post + pairs since probe, aborted suspends included. The enclave's + power domains stay on across sleep, so every other attribute + keeps its value over a suspend; a reader checking that the + enclave still answers after a resume reads the hwrng. diff --git a/drivers/soc/apple/diag.rs b/drivers/soc/apple/diag.rs index 1b6fdd2288c52..c1eae7458e64d 100644 --- a/drivers/soc/apple/diag.rs +++ b/drivers/soc/apple/diag.rs @@ -43,6 +43,12 @@ extern "C" { fn sep_diag_set_xart_guard(level: c_uint, list_loaded: bool, matching: c_int); fn sep_diag_xart_guard_refused(matching: c_int); fn sep_diag_bringup_ended(); + fn sep_diag_set_endpoint(id: u8, name: u32); + fn sep_diag_set_os_identity(source: c_int); + fn sep_diag_set_hwrng(registered: bool); + fn sep_diag_xarm_failed() -> c_uint; + fn sep_diag_unhandled() -> c_uint; + fn sep_diag_log_summary(dev: *mut c_void); } /// The identity keybag, as `SEP_DIAG_KEYBAG_*` in `shim.h` spells it. @@ -53,6 +59,18 @@ pub(crate) enum Keybag { Failed = 3, } +/// Where the OS identity the driver answers xART's GET_OS_UUID with came from, +/// as `SEP_DIAG_OS_IDENTITY_*` in `shim.h` spells it. +#[derive(Clone, Copy)] +pub(crate) enum OsIdentity { + /// The `os_uuid_hi`/`os_uuid_lo` parameters. + Explicit = 1, + /// `/chosen/apfs-preboot-uuid`. + Chosen = 2, + /// Neither: GET_OS_UUID is answered "unavailable". + Unavailable = 3, +} + /// The enrolled fingerprints at attach, as `SEP_DIAG_RESTORE_*` in `shim.h` /// spells it. #[derive(Clone, Copy)] @@ -209,3 +227,43 @@ pub(crate) fn bringup_ended() { // SAFETY: no preconditions; updates two words. unsafe { sep_diag_bringup_ended() }; } + +/// An endpoint the SEP advertised, with the four-character name its +/// descriptor carries in the upper half of `msg0`. +pub(crate) fn endpoint(id: u8, name: u32) { + // SAFETY: no preconditions; stores one word and sets one bit. + unsafe { sep_diag_set_endpoint(id, name) }; +} + +pub(crate) fn os_identity(source: OsIdentity) { + // SAFETY: no preconditions; stores one word. + unsafe { sep_diag_set_os_identity(source as c_int) }; +} + +/// The hwrng survey registered the enclave's entropy source, or gave up. +pub(crate) fn hwrng(registered: bool) { + // SAFETY: no preconditions; stores one word. + unsafe { sep_diag_set_hwrng(registered) }; +} + +/// The driver answered an xART request with the failure status. Returns how +/// many it has answered so since probe, this one included. +pub(crate) fn xarm_failed() -> u32 { + // SAFETY: no preconditions; updates one word. + unsafe { sep_diag_xarm_failed() } +} + +/// A message arrived on an endpoint the driver has no handler for. Returns +/// how many have, this one included. +pub(crate) fn unhandled() -> u32 { + // SAFETY: no preconditions; updates one word. + unsafe { sep_diag_unhandled() } +} + +/// Logs the one-line summary of the boot-time bring-up. Call it after +/// [`bringup_ended`]. +pub(crate) fn log_summary(dev: &device::Device) { + // SAFETY: `dev` is the bound SEP device for the duration of the call; the + // shim only passes it to `dev_info()` and keeps no reference. + unsafe { sep_diag_log_summary(dev.as_raw().cast()) }; +} diff --git a/drivers/soc/apple/diag_shim.c b/drivers/soc/apple/diag_shim.c index 5c54d5d8410b3..fe405306d7969 100644 --- a/drivers/soc/apple/diag_shim.c +++ b/drivers/soc/apple/diag_shim.c @@ -15,7 +15,11 @@ * the state before the driver has decided anything. */ #include +#include +#include +#include #include +#include #include #include #include @@ -58,6 +62,9 @@ #define SEP_DIAG_TOUCHID_STARTED 3 #define SEP_DIAG_TOUCHID_FAILED 4 +/* The SEP's endpoint numbers are one byte. */ +#define SEP_DIAG_MAX_EP 256 + static struct { /* Set at probe, before the group is added. */ char profile[32]; @@ -78,6 +85,26 @@ static struct { atomic_t restore; atomic_t xart_refusals; atomic_t matching; + + /* Boot-time clock at probe, and at the attach and bring-up decisions. */ + u64 probe_ns; + atomic64_t attach_ns; + atomic64_t ready_ns; + + /* + * The four-character name each endpoint advertised, by endpoint number. + * A name is stored before its bit is set, so a reader that sees the bit + * sees the name. + */ + u32 ep_name[SEP_DIAG_MAX_EP]; + DECLARE_BITMAP(ep_seen, SEP_DIAG_MAX_EP); + + atomic_t os_identity; + atomic_t hwrng; + atomic_t xarm_failures; + atomic_t unhandled; + atomic_t sleeps; + atomic_t sleeping; } sep_diag; static unsigned int sep_diag_sensor(void) @@ -340,6 +367,149 @@ static ssize_t matching_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(matching); +/* Milliseconds from probe to a decision, or 0 while it is still pending. */ +static unsigned int sep_diag_ms_since_probe(atomic64_t *at) +{ + u64 t = atomic64_read(at); + + if (!t || t < sep_diag.probe_ns) + return 0; + return (unsigned int)min_t(u64, div_u64(t - sep_diag.probe_ns, + NSEC_PER_MSEC), UINT_MAX); +} + +static ssize_t attach_ms_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%u\n", sep_diag_ms_since_probe(&sep_diag.attach_ns)); +} +static DEVICE_ATTR_RO(attach_ms); + +static ssize_t ready_ms_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%u\n", sep_diag_ms_since_probe(&sep_diag.ready_ns)); +} +static DEVICE_ATTR_RO(ready_ms); + +/* + * An endpoint's name as the SEP spells it, trailing spaces dropped ("sks "). + * A name with a byte that is not a lower-case letter or digit is shown as its + * number, so the list stays one line of space-separated tokens. + */ +static int sep_diag_ep_name(unsigned int id, char out[5]) +{ + u32 name = READ_ONCE(sep_diag.ep_name[id]); + int len = 0, i; + + for (i = 0; i < 4; i++) { + char c = (char)(name >> (24 - 8 * i)); + + if (c == ' ' && len == i) + break; + if (!(islower(c) || isdigit(c)) || len != i) + return scnprintf(out, 5, "%02x", id); + out[len++] = c; + } + if (!len) + return scnprintf(out, 5, "%02x", id); + out[len] = '\0'; + return len; +} + +static ssize_t endpoint_names_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned int id; + ssize_t n = 0; + + for_each_set_bit(id, sep_diag.ep_seen, SEP_DIAG_MAX_EP) { + char name[5]; + + /* Pairs with the barrier in sep_diag_set_endpoint(). */ + smp_rmb(); + sep_diag_ep_name(id, name); + n += sysfs_emit_at(buf, n, "%s%s", n ? " " : "", name); + } + n += sysfs_emit_at(buf, n, "\n"); + return n; +} +static DEVICE_ATTR_RO(endpoint_names); + +static ssize_t os_identity_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + const char *state; + + switch (atomic_read(&sep_diag.os_identity)) { + case SEP_DIAG_OS_IDENTITY_EXPLICIT: + state = "explicit"; + break; + case SEP_DIAG_OS_IDENTITY_CHOSEN: + state = "chosen"; + break; + case SEP_DIAG_OS_IDENTITY_UNAVAILABLE: + state = "unavailable"; + break; + default: + state = "unknown"; + break; + } + return sysfs_emit(buf, "%s\n", state); +} +static DEVICE_ATTR_RO(os_identity); + +static ssize_t hwrng_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + const char *state; + + switch (atomic_read(&sep_diag.hwrng)) { + case SEP_DIAG_HWRNG_REGISTERED: + state = "registered"; + break; + case SEP_DIAG_HWRNG_FAILED: + state = "failed"; + break; + default: + state = "pending"; + break; + } + return sysfs_emit(buf, "%s\n", state); +} +static DEVICE_ATTR_RO(hwrng); + +static ssize_t xarm_failures_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", + (unsigned int)atomic_read(&sep_diag.xarm_failures)); +} +static DEVICE_ATTR_RO(xarm_failures); + +static ssize_t unhandled_messages_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", + (unsigned int)atomic_read(&sep_diag.unhandled)); +} +static DEVICE_ATTR_RO(unhandled_messages); + +static ssize_t sleeps_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%u\n", (unsigned int)atomic_read(&sep_diag.sleeps)); +} +static DEVICE_ATTR_RO(sleeps); + +static ssize_t sleep_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "%s\n", + atomic_read(&sep_diag.sleeping) ? "held" : "awake"); +} +static DEVICE_ATTR_RO(sleep); + static struct attribute *sep_diag_attrs[] = { &dev_attr_abi.attr, &dev_attr_profile.attr, @@ -358,6 +528,15 @@ static struct attribute *sep_diag_attrs[] = { &dev_attr_xart_guard_list.attr, &dev_attr_xart_guard_refusals.attr, &dev_attr_matching.attr, + &dev_attr_attach_ms.attr, + &dev_attr_ready_ms.attr, + &dev_attr_endpoint_names.attr, + &dev_attr_os_identity.attr, + &dev_attr_hwrng.attr, + &dev_attr_xarm_failures.attr, + &dev_attr_unhandled_messages.attr, + &dev_attr_sleeps.attr, + &dev_attr_sleep.attr, NULL }; @@ -379,12 +558,14 @@ int sep_diag_register(struct device *dev, const char *profile, sep_diag.cold = cold; sep_diag.sepos13 = sepos13; sep_diag.xart = xart; + sep_diag.probe_ns = ktime_get_boottime_ns(); return devm_device_add_group(dev, &sep_diag_group); } void sep_diag_set_attach(bool attached) { + atomic64_cmpxchg(&sep_diag.attach_ns, 0, ktime_get_boottime_ns()); atomic_set(&sep_diag.attach, attached ? SEP_DIAG_ATTACH_ATTACHED : SEP_DIAG_ATTACH_FAILED); } @@ -394,6 +575,72 @@ void sep_diag_set_endpoints(unsigned int count) atomic_set(&sep_diag.endpoints, count); } +void sep_diag_set_endpoint(u8 id, u32 name) +{ + WRITE_ONCE(sep_diag.ep_name[id], name); + /* The name is visible before the bit; see endpoint_names_show(). */ + smp_wmb(); + set_bit(id, sep_diag.ep_seen); +} + +void sep_diag_set_os_identity(int source) +{ + atomic_set(&sep_diag.os_identity, source); +} + +void sep_diag_set_hwrng(bool registered) +{ + atomic_set(&sep_diag.hwrng, registered ? SEP_DIAG_HWRNG_REGISTERED : + SEP_DIAG_HWRNG_FAILED); +} + +unsigned int sep_diag_xarm_failed(void) +{ + return (unsigned int)atomic_inc_return(&sep_diag.xarm_failures); +} + +unsigned int sep_diag_unhandled(void) +{ + return (unsigned int)atomic_inc_return(&sep_diag.unhandled); +} + +/* From the PM notifier (pm_shim.c), which runs its calls one at a time. */ +void sep_diag_sleep(bool entering) +{ + if (entering) { + atomic_set(&sep_diag.sleeping, 1); + } else if (atomic_xchg(&sep_diag.sleeping, 0)) { + atomic_inc(&sep_diag.sleeps); + } +} + +/* + * One line for the kernel log when the boot-time bring-up has ended: what the + * per-endpoint discovery lines (now debug level) used to show, and the states + * a reader would otherwise collect from several attributes. + */ +void sep_diag_log_summary(struct device *dev) +{ + char names[192]; + unsigned int id; + size_t n = 0; + + names[0] = '\0'; + for_each_set_bit(id, sep_diag.ep_seen, SEP_DIAG_MAX_EP) { + char name[5]; + + smp_rmb(); + sep_diag_ep_name(id, name); + n += scnprintf(names + n, sizeof(names) - n, "%s%s", + n ? " " : "", name); + } + dev_info(dev, "ready in %u ms: %u endpoints (%s), key store %s\n", + sep_diag_ms_since_probe(&sep_diag.ready_ns), + (unsigned int)atomic_read(&sep_diag.endpoints), names, + atomic_read(&sep_diag.keystore) == SEP_DIAG_KEYSTORE_OPEN ? + "open" : "closed"); +} + void sep_diag_set_keystore_open(void) { atomic_set(&sep_diag.keystore, SEP_DIAG_KEYSTORE_OPEN); @@ -501,6 +748,7 @@ void sep_diag_xart_guard_refused(int matching) */ void sep_diag_bringup_ended(void) { + atomic64_cmpxchg(&sep_diag.ready_ns, 0, ktime_get_boottime_ns()); atomic_cmpxchg(&sep_diag.keystore, SEP_DIAG_KEYSTORE_UNKNOWN, SEP_DIAG_KEYSTORE_CLOSED); atomic_cmpxchg(&sep_diag.touchid, SEP_DIAG_TOUCHID_PENDING, diff --git a/drivers/soc/apple/pm_shim.c b/drivers/soc/apple/pm_shim.c index 884ecbb354a06..76846ad5aaac3 100644 --- a/drivers/soc/apple/pm_shim.c +++ b/drivers/soc/apple/pm_shim.c @@ -28,12 +28,14 @@ static int sep_pm_notify(struct notifier_block *nb, unsigned long action, case PM_SUSPEND_PREPARE: case PM_HIBERNATION_PREPARE: case PM_RESTORE_PREPARE: + sep_diag_sleep(true); event(true); return NOTIFY_OK; case PM_POST_SUSPEND: case PM_POST_HIBERNATION: case PM_POST_RESTORE: event(false); + sep_diag_sleep(false); return NOTIFY_OK; default: return NOTIFY_DONE; diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index 1f436a983271f..ff21f59e65b01 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -91,6 +91,9 @@ use kernel::{ }; const SETTLE_MS: time::Msecs = 200; +/// Messages on an endpoint without a handler are logged this many times per +/// boot; diag/unhandled_messages counts them all. +const UNHANDLED_LOG_LIMIT: u32 = 4; const FIRST_RESPONSE_MS: time::Msecs = 3000; const RNG_SURVEY_ATTEMPTS: u32 = 5; @@ -1546,11 +1549,14 @@ impl SepData { }; this.rng_survey_attempts.store(attempt, Relaxed); match next { - control::Survey::Registered => dev_info!( - this.dev, - "hwrng: registered after ready-phase survey (attempt {})\n", - attempt - ), + control::Survey::Registered => { + diag::hwrng(true); + dev_info!( + this.dev, + "hwrng: registered after ready-phase survey (attempt {})\n", + attempt + ) + } // Asleep, or holding back after a request that went unanswered: // this attempt did not ask the enclave anything. control::Survey::Held => Self::arm_settle(this), @@ -1558,12 +1564,15 @@ impl SepData { dev_warn!(this.dev, "hwrng: survey attempt {} failed ({:?}); retrying\n", attempt, e); Self::arm_settle(this); } - control::Survey::GiveUp(e) => dev_err!( - this.dev, - "hwrng: survey failed after {} attempts ({:?})\n", - attempt, - e - ), + control::Survey::GiveUp(e) => { + diag::hwrng(false); + dev_err!( + this.dev, + "hwrng: survey failed after {} attempts ({:?})\n", + attempt, + e + ) + } } } @@ -1677,14 +1686,17 @@ impl SepData { match os_identity::select(hi, lo, dt::preboot_uuid) { os_identity::Selection::Explicit(uuid) => { self.xarm.lock().os_uuid = Some(uuid); + diag::os_identity(diag::OsIdentity::Explicit); dev_info!(self.dev, "xART: using explicit OS identity\n"); } os_identity::Selection::Chosen(uuid) => { self.xarm.lock().os_uuid = Some(uuid); + diag::os_identity(diag::OsIdentity::Chosen); dev_info!(self.dev, "xART: using /chosen/apfs-preboot-uuid\n"); } os_identity::Selection::Unavailable => { self.xarm.lock().os_uuid = None; + diag::os_identity(diag::OsIdentity::Unavailable); dev_warn!(self.dev, "xART: /chosen/apfs-preboot-uuid is unavailable\n"); } } @@ -1885,6 +1897,15 @@ impl SepData { } fn send_xarm_reply(&self, reply: &crate::xarm::XarmReply) { + // Each of these used to fail the enclave's request without a trace. + // Count them all and log the first, so a refusal is never silent. + if reply.status == xarm::STATUS_FAILED && diag::xarm_failed() == 1 { + dev_warn!( + self.dev, + "xART: answered a request (tag {:#04x}) with the failure status; diag/xarm_failures counts them\n", + reply.tag + ); + } let msg = crate::xarm::encode_xarm_reply(reply); let _ = self.send(msg); } @@ -2513,6 +2534,7 @@ impl SepData { this.run_bringup(); diag::bringup_ended(); + diag::log_summary(&this.dev); this.finish_bringup(); Self::arm_settle(this); } @@ -2585,7 +2607,13 @@ impl SepData { proto::EP_BOOT => self.on_boot(msg), - ep => dev_info!(self.dev, "rx: unhandled endpoint {:#04x} (msg0 {:#018x})\n", ep, msg.msg0), + ep => { + // Counted in diag/unhandled_messages; logged the first few + // times only, so a chatty endpoint cannot flood the log. + if diag::unhandled() <= UNHANDLED_LOG_LIMIT { + dev_info!(self.dev, "rx: unhandled endpoint {:#04x} (msg0 {:#018x})\n", ep, msg.msg0); + } + } } } @@ -2621,7 +2649,13 @@ impl SepData { proto::DISCOVER_TYPE_DESCRIPTOR | proto::DISCOVER_TYPE_CONFIG => { let _ = table.slot(f.param); diag::endpoints(table.eps.len()); - dev_info!( + if f.ty == proto::DISCOVER_TYPE_DESCRIPTOR { + diag::endpoint(f.param, (msg.msg0 >> 32) as u32); + } + // One summary line follows at the end of the bring-up, and + // diag/endpoint_names lists them; keep the per-message trace + // at debug level. + dev_dbg!( self.dev, "discover: endpoint {:#04x} (type {}, msg0 {:#018x}); {} known\n", f.param, @@ -2630,7 +2664,7 @@ impl SepData { table.eps.len() ); } - ty => dev_info!(self.dev, "discover: other type {} (msg0 {:#018x})\n", ty, msg.msg0), + ty => dev_dbg!(self.dev, "discover: other type {} (msg0 {:#018x})\n", ty, msg.msg0), } } diff --git a/drivers/soc/apple/shim.h b/drivers/soc/apple/shim.h index ca0d3d8a797ee..d58ae573fbbad 100644 --- a/drivers/soc/apple/shim.h +++ b/drivers/soc/apple/shim.h @@ -175,6 +175,16 @@ int sep_sensor_irq_wait(unsigned int timeout_ms); #define SEP_DIAG_MATCHING_UNVERIFIED 2 #define SEP_DIAG_MATCHING_BLOCKED 3 +/* Mirrored by diag.rs (OsIdentity). */ +#define SEP_DIAG_OS_IDENTITY_UNKNOWN 0 +#define SEP_DIAG_OS_IDENTITY_EXPLICIT 1 +#define SEP_DIAG_OS_IDENTITY_CHOSEN 2 +#define SEP_DIAG_OS_IDENTITY_UNAVAILABLE 3 + +#define SEP_DIAG_HWRNG_PENDING 0 +#define SEP_DIAG_HWRNG_REGISTERED 1 +#define SEP_DIAG_HWRNG_FAILED 2 + struct device; int sep_diag_register(struct device *dev, const char *profile, @@ -194,6 +204,13 @@ void sep_diag_set_xart_guard(unsigned int level, bool list_loaded, int matching); void sep_diag_xart_guard_refused(int matching); void sep_diag_bringup_ended(void); +void sep_diag_set_endpoint(u8 id, u32 name); +void sep_diag_set_os_identity(int source); +void sep_diag_set_hwrng(bool registered); +unsigned int sep_diag_xarm_failed(void); +unsigned int sep_diag_unhandled(void); +void sep_diag_sleep(bool entering); +void sep_diag_log_summary(struct device *dev); /* -- bio_shim.c --------------------------------------------------------- */ From 9bba309e315895577fcd837b8d25901168c40cec Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:57:57 +1100 Subject: [PATCH 256/342] soc: apple: sep: Log a lock-state change once The enclave sends a lock-state notification after each query, so the same state for the same user reached the log at info level ten to forty times a boot (38 lines on a J316s boot with two users). Keep the line for a change of state or user; a repeat of the last notification is logged at debug level. The state itself is recorded as before. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/soc/apple/sbio.rs | 43 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 8d977de6a1cda..b2847c7f96d80 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -4359,25 +4359,36 @@ impl SepData { fn on_lock_state_notification(&self, word: u64) { let state = (word >> proto::MSG_TYPE_SHIFT) as u16; let user = (word >> proto::MSG_DATA_SHIFT) as u32; - self.bio_lock_state - .store(u64::from(state) | (u64::from(user) << 16), Relaxed); + let word = u64::from(state) | (u64::from(user) << 16); + let previous = self.bio_lock_state.xchg(word, Relaxed); self.bio_lock_state_seq.fetch_add(1, Relaxed); let lockout = if state & LOCK_STATE_NEEDS_PASSWORD != 0 { "set" } else { "clear" }; let n = lock_state_names(state); - dev_info!( - self.dev, - "sbio: lock state of user {} is {:#06x} (lockout {}:{}{}{}{}{}{}{})\n", - user, - state, - lockout, - n[0], - n[1], - n[2], - n[3], - n[4], - n[5], - n[6] - ); + // The enclave repeats the same state after each query; log a change + // once, and a repeat of the last notification only at debug level. + if previous != word { + dev_info!( + self.dev, + "sbio: lock state of user {} is {:#06x} (lockout {}:{}{}{}{}{}{}{})\n", + user, + state, + lockout, + n[0], + n[1], + n[2], + n[3], + n[4], + n[5], + n[6] + ); + } else { + dev_dbg!( + self.dev, + "sbio: lock state of user {} is still {:#06x}\n", + user, + state + ); + } self.sbio_wq.notify_all(); } From 2828b2f987f260b9067fca8988d5eaec7d273925 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:58:32 +1100 Subject: [PATCH 257/342] tools/aurora-sep: Add aurora-sep status, a self-check of the SEP state Users and the test suites had no single place to see whether the SEP came up as it should. The answer was spread over seventeen diag attributes, the device nodes, the hwrng and the kernel log, and only aurora-sep-ready looked at part of it, for Touch ID. aurora-sep status checks each state the driver reports and prints PASS, WARN, FAIL or INFO with the value and what it means: attach, the endpoints by name against the twelve every supported SEP advertises (the set macOS lists), bring-up time, key store, keybag, xART, OS identity and the MacBook Neo's os_uuid pin, hwrng, Touch ID, sensor, restore, matching, xART guard refusals, failed xART requests, unhandled messages, sleep, aurora-sep-ready.service, and the apple_sep error and warning lines of the boot. It exits 1 if a check failed and 2 without a SEP. --json and --summary are for test suites. It only reads, and never opens /dev/sep-bio, which would activate Touch ID. As root it reads 32 bytes from /dev/hwrng when the enclave is the current hwrng, which shows the enclave still answers, after a resume too. On kernels without the newer attributes it checks what they have. Installed as /usr/bin/aurora-sep by the Fedora and Arch packages. The tests run it against a synthetic sysfs, one broken state at a time. Assisted-by: LLM Signed-off-by: Ryan Murray --- tools/aurora-sep/README.md | 20 + tools/aurora-sep/aurora-sep | 363 ++++++++++++++++++ .../packaging/arch/aurora-sep/PKGBUILD | 5 +- .../packaging/fedora/aurora-sep.spec | 3 + .../tests/test_aurora_sep_status.py | 182 +++++++++ 5 files changed, 572 insertions(+), 1 deletion(-) create mode 100755 tools/aurora-sep/aurora-sep create mode 100644 tools/aurora-sep/tests/test_aurora_sep_status.py diff --git a/tools/aurora-sep/README.md b/tools/aurora-sep/README.md index 15772498d4225..715a91171503d 100644 --- a/tools/aurora-sep/README.md +++ b/tools/aurora-sep/README.md @@ -198,6 +198,26 @@ lock screen then selects `omarchy-lock-fingerprint` automatically and accepts Touch ID through fprintd. Hyprlock's separate fingerprint switch is not used by the Quickshell lock screen. +## Checking the SEP state + +`aurora-sep status` prints every state the driver reports, one line each +with PASS, WARN, FAIL or INFO: the attach, the twelve endpoints by name +(macOS lists the same twelve as `sep-endpoint,` services), the +bring-up time, the key store and identity keybag, xART, the OS identity +(and the os_uuid pin on the MacBook Neo), the hwrng, Touch ID, the sensor, +the fingerprint restore and matching, the xART guard, failed xART +requests, unhandled messages, sleep, `aurora-sep-ready.service` and the +apple_sep error and warning lines of this boot. It exits 1 if anything +FAILed. `--summary` prints only the last line, `--quiet` hides PASS and +INFO lines and `--json` prints the report as JSON. + +It only reads: it never opens `/dev/sep-bio`, since that activates Touch +ID. Run as root and with the enclave as the current hwrng, it reads 32 +bytes from `/dev/hwrng`, which shows that the enclave still answers, also +after a resume; `--no-live` skips that. The kernel log check needs root. +Older kernels without some of the diag attributes are checked on what +they have (the endpoint count instead of the names, for example). + ## Packages `packaging/` builds `aurora-sep`, with the loader, its service and the fprintd diff --git a/tools/aurora-sep/aurora-sep b/tools/aurora-sep/aurora-sep new file mode 100755 index 0000000000000..00e3adc4979de --- /dev/null +++ b/tools/aurora-sep/aurora-sep @@ -0,0 +1,363 @@ +#!/usr/bin/python3 -I +# SPDX-License-Identifier: GPL-2.0-only +"""aurora-sep: report the Secure Enclave (SEP) state on an Aurora kernel. + + aurora-sep status [--json] [--summary] [--no-live] [--quiet] + +`status` checks every state the apple_sep driver reports and prints one +line per check: PASS, WARN, FAIL or INFO, the value, and what it means. +It reads the driver's diag attributes, the device nodes, the hwrng and +the kernel log. It never opens /dev/sep-bio (that activates Touch ID) +and never writes anything. With root and the enclave as the current +hwrng it reads 32 random bytes from /dev/hwrng, which proves the enclave +still answers (after a resume, too); --no-live skips that. + +Exit status: 0 when nothing FAILed, 1 when something did, 2 when this is +not a Mac with a SEP driver. + +Environment, for tests: AURORA_SEP_SYSFS (default /sys/bus/platform/devices), +AURORA_SEP_ROOT (prefix for /proc, /dev and /sys/class paths, default ""), +AURORA_SEP_NO_SYSTEM=1 (skip systemctl and the kernel log). +""" + +import json +import os +import subprocess +import sys + +SYSFS = os.environ.get("AURORA_SEP_SYSFS", "/sys/bus/platform/devices") +ROOT = os.environ.get("AURORA_SEP_ROOT", "") +# Tests set this to keep systemctl and the journal of the machine out of it. +NO_SYSTEM = os.environ.get("AURORA_SEP_NO_SYSTEM") == "1" + +# The endpoints every supported SEP advertises. macOS lists the same twelve +# (ioreg: sep-endpoint, under AppleSEPManager) on M1 Pro, M2 and later. +EXPECTED_ENDPOINTS = ["cntl", "hdcp", "hibe", "pnon", "sbio", "scrd", + "skdl", "sks", "sse", "stac", "xarm", "xars"] +# The ones the driver serves itself; the rest have no Linux client yet. +SERVED = {"cntl": "control, hwrng", "xarm": "xART store", "sks": "key store", + "sbio": "Touch ID", "scrd": "credentials"} + +# A bring-up slower than this is reported (the driver waits up to 90 s). +READY_WARN_MS = 15000 + +PASS, WARN, FAIL, INFO = "PASS", "WARN", "FAIL", "INFO" + + +def path(p): + return ROOT + p + + +def read(p): + try: + with open(p, encoding="ascii", errors="replace") as f: + return f.read().strip() + except OSError: + return None + + +class Report: + def __init__(self): + self.rows = [] + + def add(self, verdict, name, value, why=""): + self.rows.append({"check": name, "verdict": verdict, + "value": "" if value is None else str(value), + "detail": why}) + + def count(self, verdict): + return sum(1 for r in self.rows if r["verdict"] == verdict) + + +def find_sep(): + try: + names = sorted(os.listdir(SYSFS)) + except OSError: + return None + for n in names: + if n.endswith(".sep"): + return os.path.join(SYSFS, n) + return None + + +def compatible(): + raw = None + try: + with open(path("/proc/device-tree/compatible"), "rb") as f: + raw = f.read() + except OSError: + return [] + return [c.decode("ascii", "replace") for c in raw.split(b"\0") if c] + + +def kernel_log_levels(): + """(err, warning) apple_sep line counts, or None.""" + res = [] + for prio in ("err", "warning"): + try: + out = subprocess.run(["journalctl", "-k", "-b", "-p", prio, "-o", + "cat", "--no-pager", "-q"], + capture_output=True, text=True, timeout=20, + check=False) + except (OSError, subprocess.TimeoutExpired): + return None + if out.returncode != 0: + return None + res.append([l for l in out.stdout.splitlines() + if "apple_sep" in l or "sep sensor" in l]) + return res + + +def status(live=True): + r = Report() + dev = find_sep() + if dev is None: + r.add(FAIL, "sep-device", "absent", + "no .sep platform device: not an Apple silicon Mac, or the DT has no SEP node") + return r, 2 + drv = os.path.basename(os.path.realpath(os.path.join(dev, "driver"))) \ + if os.path.exists(os.path.join(dev, "driver")) else None + if drv != "apple_sep": + r.add(FAIL, "driver", drv or "unbound", + "apple_sep is not bound to the SEP (module not loaded, or probe failed)") + return r, 1 + r.add(PASS, "driver", "apple_sep bound to " + os.path.basename(dev)) + + diag = os.path.join(dev, "diag") + if not os.path.isdir(diag): + r.add(FAIL, "diag", "absent", "this kernel has no diag attributes; too old to check") + return r, 1 + + def d(name): + return read(os.path.join(diag, name)) + + r.add(INFO, "profile", d("profile"), "platform profile the driver chose") + r.add(INFO, "bootstrap", d("boot"), "cold: the driver boots the SEP; warm: iBoot left it running") + r.add(INFO, "protocol", d("protocol"), "key-store protocol") + + attach = d("attach") + if attach == "attached": + r.add(PASS, "attach", attach, "the SEP advertised its endpoints") + elif attach == "pending": + r.add(FAIL, "attach", attach, "the SEP has not answered the driver") + else: + r.add(FAIL, "attach", attach, "the SEP advertised no endpoint") + + names = d("endpoint_names") + count = d("endpoints") + if names is not None: + have = names.split() + missing = [e for e in EXPECTED_ENDPOINTS if e not in have] + extra = [e for e in have if e not in EXPECTED_ENDPOINTS] + if missing: + r.add(FAIL, "endpoints", "%d: %s" % (len(have), names), + "missing " + " ".join(missing)) + else: + r.add(PASS, "endpoints", "%d: %s" % (len(have), names), + "all %d expected endpoints, as macOS lists them" % len(EXPECTED_ENDPOINTS) + + ("; also " + " ".join(extra) if extra else "")) + unserved = [e for e in have if e not in SERVED] + r.add(INFO, "endpoint-clients", + ", ".join("%s=%s" % (e, SERVED[e]) for e in have if e in SERVED), + "no Linux client yet: " + " ".join(unserved) if unserved else "") + elif count is not None: + n = int(count) if count.isdigit() else 0 + r.add(PASS if n >= len(EXPECTED_ENDPOINTS) else FAIL, "endpoints", n, + "expected %d (this kernel does not list names)" % len(EXPECTED_ENDPOINTS)) + + for name, why in (("attach_ms", "probe to attach"), + ("ready_ms", "probe to the end of the bring-up")): + v = d(name) + if v is None: + continue + ms = int(v) if v.isdigit() else 0 + if ms == 0: + r.add(WARN, name, v, why + ": not decided yet") + elif name == "ready_ms" and ms > READY_WARN_MS: + r.add(WARN, name, v, why + ": slow (over %d ms)" % READY_WARN_MS) + else: + r.add(INFO, name, v, why) + + ks = d("keystore") + r.add(PASS if ks == "open" else FAIL, "keystore", ks, + {"open": "key store open", "closed": "the bring-up ended without the key store", + "unknown": "bring-up still running"}.get(ks, "")) + + kb = d("keybag") + xart = d("xart") + if kb == "present": + r.add(PASS, "keybag", kb, "identity keybag present") + elif kb == "missing": + r.add(WARN, "keybag", kb, "no identity keybag: Touch ID is not provisioned on this install") + else: + r.add(FAIL, "keybag", kb, "identity keybag failed or undecided") + + if xart == "enabled": + r.add(PASS, "xart", xart, "the enclave's state writes reach the disk") + else: + r.add(WARN, "xart", xart, "xART writes are off (xart_writes=0): enrol and verify are refused") + + osid = d("os_identity") + if osid is not None: + if osid in ("explicit", "chosen"): + r.add(PASS, "os-identity", osid, "the xART exchange has an OS identity") + else: + r.add(FAIL, "os-identity", osid, "no OS identity: the enclave cannot find this OS's xART records") + comp = compatible() + cmdline = read(path("/proc/cmdline")) or "" + if "apple,j700" in comp: + pinned = "apple_sep.os_uuid_hi=" in cmdline and "apple_sep.os_uuid_lo=" in cmdline + r.add(PASS if pinned else FAIL, "os-uuid-pin", "present" if pinned else "missing", + "the MacBook Neo needs the os_uuid pin on every boot entry") + for p in ("xarm_trace", "sensor_trace"): + if "apple_sep.%s=1" % p in cmdline: + r.add(WARN, "cmdline-" + p, "on", "debug tracing is on in the boot entry (log noise)") + + hw = d("hwrng") + cur = read(path("/sys/class/misc/hw_random/rng_current")) + avail = read(path("/sys/class/misc/hw_random/rng_available")) or "" + if hw is not None: + r.add(PASS if hw == "registered" else (WARN if hw == "pending" else FAIL), + "hwrng", hw, "the enclave's random source") + elif "apple-sep" in avail.split(): + r.add(PASS, "hwrng", "registered", "apple-sep is an available hwrng") + else: + r.add(FAIL, "hwrng", "absent", "apple-sep is not an hwrng") + if live: + if cur == "apple-sep" and os.access(path("/dev/hwrng"), os.R_OK): + try: + with open(path("/dev/hwrng"), "rb", buffering=0) as f: + got = f.read(32) + ok = len(got) == 32 and any(got) + r.add(PASS if ok else FAIL, "live", "%d bytes" % len(got), + "the enclave answered an entropy request now" if ok + else "the enclave did not answer an entropy request") + except OSError as e: + r.add(FAIL, "live", "error", "reading /dev/hwrng: %s" % e.strerror) + elif cur == "apple-sep": + r.add(INFO, "live", "skipped", "needs root to read /dev/hwrng") + else: + r.add(INFO, "live", "skipped", "the current hwrng is %s, not apple-sep" % (cur or "none")) + + for node, why in (("/dev/sep-bio", "Touch ID"), ("/dev/sep-key", "enclave keys")): + if os.path.exists(path(node)): + r.add(PASS, "node" + node[4:], "present", why) + else: + r.add(WARN if ks != "open" else FAIL, "node" + node[4:], "absent", why) + + tid = d("touchid") + sensor = d("sensor") + sattach = d("sensor_attach") + restore = d("restore") + match = d("matching") + if tid == "ready": + r.add(PASS, "touchid", tid, "Touch ID activated and the sensor online") + elif tid == "unknown": + r.add(WARN, "touchid", tid, "not activated yet (aurora-sep-ready.service opens /dev/sep-bio at boot)") + elif tid == "failed" and kb == "missing": + r.add(WARN, "touchid", tid, "not provisioned (no identity keybag)") + else: + r.add(FAIL, "touchid", tid, "Touch ID cannot work this boot") + r.add(PASS if sensor == "online" else (WARN if sensor in ("bound", "unbound") and tid != "ready" else FAIL), + "sensor", sensor, "fingerprint sensor on SPI") + if sattach is not None: + r.add(PASS if sattach == "attached" else (WARN if sattach in ("unknown", "retrying") else FAIL), + "sensor-attach", sattach, "") + if restore is not None: + r.add(PASS if restore in ("restored", "empty") else (WARN if restore == "unknown" else FAIL), + "restore", restore, {"restored": "enrolled fingerprints restored", + "empty": "no fingerprint enrolled", + "unproven": "fingerprints listed but not proven: matching refused"}.get(restore, "")) + if match is not None: + r.add({"usable": PASS, "unverified": PASS, "blocked": FAIL}.get(match, WARN), + "matching", match, + {"usable": "a match can save its state", + "unverified": "the xART guard runs and has refused nothing", + "blocked": "a match cannot save its state; see XART-SAFETY.md"}.get(match, "")) + + refusals = d("xart_guard_refusals") + failures = d("xarm_failures") + ref = int(refusals) if refusals and refusals.isdigit() else 0 + if refusals is not None: + r.add(PASS if ref == 0 else WARN, "xart-guard-refusals", refusals, + "xART guard level %s" % d("xart_guard")) + if failures is not None: + fail = int(failures) if failures.isdigit() else 0 + r.add(PASS if fail <= ref else FAIL, "xarm-failures", failures, + "xART requests the driver failed (guard refusals included)") + unh = d("unhandled_messages") + if unh is not None: + r.add(PASS if unh == "0" else WARN, "unhandled-messages", unh, + "messages on endpoints without a handler") + + sl = d("sleep") + if sl is not None: + r.add(PASS if sl == "awake" else WARN, "sleep", sl, "sleep cycles since probe: %s" % d("sleeps")) + + if NO_SYSTEM: + return r, (1 if r.count(FAIL) else 0) + + unit = None + try: + out = subprocess.run(["systemctl", "show", "-p", "Result", "-p", "ActiveState", + "-p", "LoadState", "aurora-sep-ready.service"], + capture_output=True, text=True, timeout=10, check=False) + props = dict(l.split("=", 1) for l in out.stdout.splitlines() if "=" in l) + if props.get("LoadState") == "loaded": + unit = props.get("Result"), props.get("ActiveState") + except (OSError, subprocess.TimeoutExpired): + pass + if unit and unit[1]: + r.add(PASS if unit[0] == "success" else FAIL, "aurora-sep-ready", + "%s/%s" % (unit[1], unit[0]), "boot-time Touch ID activation") + + levels = kernel_log_levels() + if levels is None: + r.add(INFO, "kernel-log", "unreadable", "run as root to check the kernel log") + else: + errs, warns = levels + r.add(PASS if not errs else FAIL, "log-errors", len(errs), + errs[0][:160] if errs else "no apple_sep error lines this boot") + r.add(PASS if not warns else WARN, "log-warnings", len(warns), + warns[0][:160] if warns else "no apple_sep warning lines this boot") + + return r, (1 if r.count(FAIL) else 0) + + +def main(argv): + args = argv[1:] + if not args or args[0] in ("-h", "--help", "help"): + print(__doc__.strip()) + return 0 if args else 2 + if args[0] != "status": + print("aurora-sep: unknown command %r (try: aurora-sep status)" % args[0], file=sys.stderr) + return 2 + opts = set(args[1:]) + unknown = opts - {"--json", "--summary", "--no-live", "--quiet"} + if unknown: + print("aurora-sep: unknown option %s" % " ".join(sorted(unknown)), file=sys.stderr) + return 2 + rep, rc = status(live="--no-live" not in opts) + totals = {v: rep.count(v) for v in (PASS, WARN, FAIL, INFO)} + if "--json" in opts: + json.dump({"result": "FAIL" if rep.count(FAIL) else "PASS", + "totals": totals, "checks": rep.rows}, sys.stdout, indent=1) + print() + return rc + if "--summary" not in opts: + for row in rep.rows: + if "--quiet" in opts and row["verdict"] in (PASS, INFO): + continue + line = "%-4s %-20s %s" % (row["verdict"], row["check"], row["value"]) + if row["detail"]: + line += " (" + row["detail"] + ")" + print(line) + bad = [row["check"] for row in rep.rows if row["verdict"] == FAIL] + print("aurora-sep: %s pass %d warn %d fail %d%s" % ( + "FAIL" if bad else "PASS", totals[PASS], totals[WARN], totals[FAIL], + (" [" + " ".join(bad) + "]") if bad else "")) + return rc + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD index 013c7fe5df861..379484f162cbb 100644 --- a/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD +++ b/tools/aurora-sep/packaging/arch/aurora-sep/PKGBUILD @@ -34,7 +34,8 @@ source=(load-driver README.md XART-SAFETY.md OS-IDENTITY.md - sep-bio-identities) + sep-bio-identities + aurora-sep) sha256sums=('SKIP' 'SKIP' 'SKIP' @@ -49,6 +50,7 @@ sha256sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' + 'SKIP' 'SKIP') # A unit and the helper it runs ($1, installed as $3), pointed at the @@ -83,5 +85,6 @@ package() { install -Dm644 logind-aurora-sep.conf \ "$pkgdir/usr/lib/systemd/logind.conf.d/50-aurora-sep.conf" install -Dm755 sep-bio-identities "$pkgdir/usr/bin/sep-bio-identities" + install -Dm755 aurora-sep "$pkgdir/usr/bin/aurora-sep" install -Dm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md XART-SAFETY.md OS-IDENTITY.md } diff --git a/tools/aurora-sep/packaging/fedora/aurora-sep.spec b/tools/aurora-sep/packaging/fedora/aurora-sep.spec index 359ec582e1877..15a5b2a1bf2e0 100644 --- a/tools/aurora-sep/packaging/fedora/aurora-sep.spec +++ b/tools/aurora-sep/packaging/fedora/aurora-sep.spec @@ -30,6 +30,7 @@ Source11: aurora_sep.te Source12: aurora_sep.fc Source13: OS-IDENTITY.md Source16: sep-bio-identities +Source17: aurora-sep BuildArch: noarch BuildRequires: systemd-rpm-macros @@ -99,6 +100,7 @@ sed 's|@FPRINTD@|%{_libexecdir}/fprintd|' %{SOURCE7} \ install -Dpm 0644 %{SOURCE8} \ %{buildroot}%{_prefix}/lib/systemd/logind.conf.d/50-aurora-sep.conf install -Dpm 0755 %{SOURCE16} %{buildroot}%{_bindir}/sep-bio-identities +install -Dpm 0755 %{SOURCE17} %{buildroot}%{_bindir}/aurora-sep # Load the driver at boot, so the enclave is up before the login screen asks. install -d %{buildroot}%{_presetdir} echo 'enable aurora-sep.service' >%{buildroot}%{_presetdir}/80-aurora-sep.preset @@ -140,6 +142,7 @@ fi %{_libexecdir}/aurora-sep-ready %{_libexecdir}/aurora-sep-greeter-fingerprint %{_bindir}/sep-bio-identities +%{_bindir}/aurora-sep %{_sbindir}/aurora-sep-policy-change %{_unitdir}/aurora-sep.service %{_unitdir}/aurora-sep-ready.service diff --git a/tools/aurora-sep/tests/test_aurora_sep_status.py b/tools/aurora-sep/tests/test_aurora_sep_status.py new file mode 100644 index 0000000000000..d99ffdd7d783e --- /dev/null +++ b/tools/aurora-sep/tests/test_aurora_sep_status.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""aurora-sep status: one verdict per SEP state, from a synthetic sysfs. + +The healthy values are the ones a fleet44 boot reports on the M1 Pro, M2, +J616s and MacBook Neo; each test then breaks one state and checks that the +tool names it and exits 1. +""" + +import json +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parents[1] / "aurora-sep" + +HEALTHY = { + "abi": "2", "profile": "T8112/J415", "boot": "warm", "protocol": "variant5", + "xart": "enabled", "attach": "attached", "endpoints": "12", + "endpoint_names": "cntl sbio scrd sse hdcp xars sks xarm hibe pnon skdl stac", + "attach_ms": "845", "ready_ms": "4444", "keystore": "open", + "keybag": "present", "sensor": "online", "touchid": "ready", + "sensor_attach": "attached", "restore": "restored", "xart_guard": "1", + "xart_guard_list": "loaded", "xart_guard_refusals": "0", + "matching": "unverified", "os_identity": "explicit", "hwrng": "registered", + "xarm_failures": "0", "unhandled_messages": "0", "sleep": "awake", + "sleeps": "3", +} + + +class StatusTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.root = Path(self.tmp.name) + self.devices = self.root / "devices" + self.sep = self.devices / "25e400000.sep" + self.diag = self.sep / "diag" + self.diag.mkdir(parents=True) + drv = self.root / "drivers" / "apple_sep" + drv.mkdir(parents=True) + (self.sep / "driver").symlink_to(drv) + for name, value in HEALTHY.items(): + self.set(name, value) + (self.root / "proc" / "device-tree").mkdir(parents=True) + self.compatible(b"apple,j413\0apple,t8112\0apple,arm-platform\0") + (self.root / "proc" / "cmdline").write_text("root=UUID=x ro quiet\n") + rng = self.root / "sys" / "class" / "misc" / "hw_random" + rng.mkdir(parents=True) + (rng / "rng_available").write_text("apple-sep\n") + (rng / "rng_current").write_text("apple-sep\n") + (self.root / "dev").mkdir() + for node in ("sep-bio", "sep-key"): + (self.root / "dev" / node).write_text("") + (self.root / "dev" / "hwrng").write_bytes(bytes(range(1, 33))) + + def tearDown(self): + self.tmp.cleanup() + + def set(self, name, value): + path = self.diag / name + if value is None: + path.unlink(missing_ok=True) + else: + path.write_text(value + "\n") + + def compatible(self, raw): + (self.root / "proc" / "device-tree" / "compatible").write_bytes(raw) + + def run_status(self, *args): + env = dict(os.environ, AURORA_SEP_SYSFS=str(self.devices), + AURORA_SEP_ROOT=str(self.root), AURORA_SEP_NO_SYSTEM="1") + out = subprocess.run([sys.executable, "-I", str(SCRIPT), "status", "--json", *args], + capture_output=True, text=True, env=env, timeout=30) + report = json.loads(out.stdout) + verdicts = {row["check"]: row["verdict"] for row in report["checks"]} + return out.returncode, report, verdicts + + def test_healthy_boot_passes(self): + rc, report, v = self.run_status() + self.assertEqual(rc, 0, report) + self.assertEqual(report["result"], "PASS") + self.assertEqual(report["totals"]["FAIL"], 0) + self.assertEqual(v["endpoints"], "PASS") + self.assertEqual(v["live"], "PASS") + + def test_a_missing_endpoint_fails(self): + self.set("endpoint_names", "cntl sbio scrd sse hdcp xars xarm hibe pnon skdl stac") + rc, report, v = self.run_status() + self.assertEqual(rc, 1) + self.assertEqual(v["endpoints"], "FAIL") + row = [r for r in report["checks"] if r["check"] == "endpoints"][0] + self.assertIn("missing sks", row["detail"]) + + def test_an_old_kernel_falls_back_to_the_count(self): + for name in ("endpoint_names", "attach_ms", "ready_ms", "os_identity", + "hwrng", "xarm_failures", "unhandled_messages", "sleep", "sleeps"): + self.set(name, None) + rc, _, v = self.run_status() + self.assertEqual(rc, 0) + self.assertEqual(v["endpoints"], "PASS") + self.assertEqual(v["hwrng"], "PASS") + self.set("endpoints", "7") + rc, _, v = self.run_status() + self.assertEqual((rc, v["endpoints"]), (1, "FAIL")) + + def test_a_closed_key_store_fails(self): + self.set("keystore", "closed") + rc, _, v = self.run_status() + self.assertEqual((rc, v["keystore"]), (1, "FAIL")) + + def test_a_driver_failure_beyond_the_guard_fails(self): + self.set("xart_guard_refusals", "2") + self.set("xarm_failures", "2") + rc, _, v = self.run_status() + self.assertEqual(v["xarm-failures"], "PASS") + self.assertEqual(v["xart-guard-refusals"], "WARN") + self.set("xarm_failures", "3") + rc, _, v = self.run_status() + self.assertEqual((rc, v["xarm-failures"]), (1, "FAIL")) + + def test_no_os_identity_fails(self): + self.set("os_identity", "unavailable") + rc, _, v = self.run_status() + self.assertEqual((rc, v["os-identity"]), (1, "FAIL")) + + def test_the_neo_needs_its_pin(self): + self.compatible(b"apple,j700\0apple,t8140\0apple,arm-platform\0") + rc, _, v = self.run_status() + self.assertEqual((rc, v["os-uuid-pin"]), (1, "FAIL")) + (self.root / "proc" / "cmdline").write_text( + "ro apple_sep.os_uuid_hi=1 apple_sep.os_uuid_lo=2\n") + rc, _, v = self.run_status() + self.assertEqual((rc, v["os-uuid-pin"]), (0, "PASS")) + + def test_a_silent_enclave_fails_the_live_check(self): + (self.root / "dev" / "hwrng").write_bytes(b"") + rc, _, v = self.run_status() + self.assertEqual((rc, v["live"]), (1, "FAIL")) + rc, _, v = self.run_status("--no-live") + self.assertEqual(rc, 0) + self.assertNotIn("live", v) + + def test_unprovisioned_touch_id_warns(self): + self.set("keybag", "missing") + self.set("touchid", "failed") + self.set("sensor", "unbound") + self.set("sensor_attach", "unknown") + self.set("restore", "unknown") + rc, report, v = self.run_status() + self.assertEqual(rc, 0, report) + self.assertEqual((v["keybag"], v["touchid"]), ("WARN", "WARN")) + + def test_blocked_matching_fails(self): + self.set("matching", "blocked") + rc, _, v = self.run_status() + self.assertEqual((rc, v["matching"]), (1, "FAIL")) + + def test_no_sep_device_exits_2(self): + os.unlink(self.sep / "driver") + for f in self.diag.iterdir(): + f.unlink() + self.diag.rmdir() + self.sep.rmdir() + rc, report, _ = self.run_status() + self.assertEqual(rc, 2) + self.assertEqual(report["result"], "FAIL") + + def test_summary_is_one_line(self): + env = dict(os.environ, AURORA_SEP_SYSFS=str(self.devices), + AURORA_SEP_ROOT=str(self.root), AURORA_SEP_NO_SYSTEM="1") + out = subprocess.run([sys.executable, "-I", str(SCRIPT), "status", "--summary"], + capture_output=True, text=True, env=env, timeout=30) + self.assertEqual(out.returncode, 0) + self.assertEqual(len(out.stdout.splitlines()), 1) + self.assertTrue(out.stdout.startswith("aurora-sep: PASS")) + + +if __name__ == "__main__": + unittest.main() From 728bb25e573c82cfd0f9edd123b9150f5dec4b82 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:59:14 +1100 Subject: [PATCH 258/342] soc: apple: sep: log a capture without a finger at info level A Touch ID capture that ends without a frame means nobody touched the sensor before the capture window closed. Verify answers with a retry and PLACE guidance and enrol counts it as no finger; neither is a driver or hardware problem. Every PAM prompt that times out or is answered with the password logged a kernel warning, so the warning count of a normal session grew with each unused prompt. Log both at info level. Sensor faults during a capture stay errors. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/sbio.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index 8d977de6a1cda..2da07846c2cd3 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -2913,7 +2913,7 @@ impl SepData { let advertised = match self.await_capture() { CaptureWait::Ready(n) => n, CaptureWait::Timeout => { - dev_warn!(self.dev, "verify: the capture ended without a frame\n"); + dev_info!(self.dev, "verify: the capture ended without a frame\n"); // No finger came: nothing was compared, so ask again rather // than report an error. PLACE names the cause. self.retry_cause(bio::Guidance::Place); @@ -4024,7 +4024,7 @@ impl SepData { let available = match self.await_capture() { CaptureWait::Ready(n) => n, CaptureWait::Timeout => { - dev_warn!(self.dev, "enrol: capture {} ended without a frame\n", counter); + dev_info!(self.dev, "enrol: capture {} ended without a frame\n", counter); return ImageOutcome::NoFinger; } CaptureWait::Fault(state) => { From 7be62fbfde6a8a280b52b975126cb08f33498e59 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:05:29 +1100 Subject: [PATCH 259/342] dt-bindings: hwmon: apple,smc-hwmon: no-data-below takes the standard unit type A -millicelsius property already has its type from the dtschema unit suffixes (an int32 array). Describe it as a single value instead of redefining the type, which made every user fail validation. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml index e98bdcc7b7897..a4e4dfd3c0886 100644 --- a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml +++ b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml @@ -34,7 +34,7 @@ $defs: description: Human-readable name for the sensor apple,no-data-below-millicelsius: - $ref: /schemas/types.yaml#/definitions/int32 + maxItems: 1 description: The SMC publishes a placeholder below this temperature, in millidegrees Celsius, while the sensor is powered down (the GPU From 33a82d7d9c6d8168b8c215000bdb5173f0c2ffd8 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:53:09 +1100 Subject: [PATCH 260/342] arm64: dts: apple: t600x-j314-j316: add the GPU temperature sensors The M1 Pro and M1 Max MacBook Pros exposed no GPU temperature. Their SMC has four GPU keys: Tg04 and Tg0C, and Tg05 and Tg0D, which read Tg04 and Tg0C plus a fixed 9.2 C. Measured on a J316s (M1 Pro): 33.9-44.3 C during a glmark2 run. Like the M4 Pro, the SMC publishes them only while the GPU is powered. With the GPU off at idle, Tg04/Tg0C read 0 C and Tg05/Tg0D 9.2 C. Mark those placeholders as no data: below 10 C on Tg04/Tg0C, and below 15 C on the offset keys, whose real readings sit 9.2 C above the base keys. They are read-only hwmon channels with no thermal zone or trip. Keys a machine lacks are skipped. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../arm64/boot/dts/apple/t600x-j314-j316.dtsi | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi index 9dbbcd52d4ec4..9a5f76f4fb069 100644 --- a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi @@ -997,6 +997,37 @@ #include "spi1-nvram.dtsi" #include "hwmon-laptop.dtsi" #include "hwmon-fan-dual.dtsi" + +/* + * GPU temperatures. The SMC publishes them only while the GPU is powered: + * with the GPU off, Tg04/Tg0C read 0 C and Tg05/Tg0D read 9.2 C (they + * track Tg04/Tg0C plus a fixed 9.2 C). Those placeholders are no data. + */ +&smc_hwmon { + temperature-Tg04 { + apple,key-id = "Tg04"; + label = "GPU Tg04"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg05 { + apple,key-id = "Tg05"; + label = "GPU Tg05"; + apple,no-data-below-millicelsius = <15000>; + }; + + temperature-Tg0C { + apple,key-id = "Tg0C"; + label = "GPU Tg0C"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0D { + apple,key-id = "Tg0D"; + label = "GPU Tg0D"; + apple,no-data-below-millicelsius = <15000>; + }; +}; #include "isp-imx558.dtsi" &isp { From 3e7a79c567fc388652c7dc8b9cc786f2652cf997 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:53:10 +1100 Subject: [PATCH 261/342] arm64: dts: apple: t8140-j700: add the GPU temperature sensors The J700 exposed no GPU temperature. Its SMC has eight GPU keys (Tg04, Tg05, Tg0C, Tg0D, Tg0K, Tg0L, Tg0d, Tg0e): 57-67 C on a J700 during a glmark2 run. As on the M4 Pro, the SMC publishes them only while the GPU is powered; with the GPU off at idle they read placeholders between -4.0 and 0.2 C. Mark readings below 10 C as no data. They are read-only hwmon channels with no thermal zone or trip, added after the existing temperature nodes so the channel numbers the thermal zones use do not move. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8140-j700.dts | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index e4634a965e642..a9acaf70b90d5 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -1117,6 +1117,59 @@ label = "SMC Tsx1"; }; + /* + * GPU temperatures, last so the indexed channels above keep their + * numbers. The SMC publishes them only while the GPU is powered; with + * the GPU off they read -4.0 to 0.2 C placeholders, which are no data. + */ + temperature-Tg04 { + apple,key-id = "Tg04"; + label = "GPU Tg04"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg05 { + apple,key-id = "Tg05"; + label = "GPU Tg05"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0C { + apple,key-id = "Tg0C"; + label = "GPU Tg0C"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0D { + apple,key-id = "Tg0D"; + label = "GPU Tg0D"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0K { + apple,key-id = "Tg0K"; + label = "GPU Tg0K"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0L { + apple,key-id = "Tg0L"; + label = "GPU Tg0L"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0d { + apple,key-id = "Tg0d"; + label = "GPU Tg0d"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0e { + apple,key-id = "Tg0e"; + label = "GPU Tg0e"; + apple,no-data-below-millicelsius = <10000>; + }; + /* * Current, power and voltage rails: every other read-only float * I*, P* and V* key in the J700 SMC's key table. The units follow From 94c25f2c5b861ef6416d8d0c8a30153592687bfc Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:06:03 +1100 Subject: [PATCH 262/342] net: thunderbolt: Do not block the control channel on a login request tbnet_handle_packet() is the ThunderboltIP protocol handler. It is called from tb_xdomain_handle_request(), i.e. from the control channel Rx ring callback. For a login request it sends the response and then takes connection_lock to update the login state. tbnet_connected_work() holds connection_lock for the whole connection setup, including tb_xdomain_enable_paths(). Programming the DMA paths reads and writes the host router config space through the same control channel. When the remote host sends a second login request while we are connecting, which happens whenever both ends start logging in at the same time (for example after "ip link set thunderbolt0 down/up" on the remote end), the handler blocks on connection_lock, the control channel Rx ring stops making progress and the HOPS read in tb_path_activate() times out: thunderbolt-net 0-1.0 thunderbolt0: login successful, enabling paths ... activating DMA RX path from 0:1 to 0:7 thunderbolt-net 0-1.0 thunderbolt0: remote login request received thunderbolt-net 0-1.0 thunderbolt0: remote login response sent ... 0: timeout reading config space 0 from 0x10 ... 0: timeout reading config space 0 from 0x10 ... DMA RX path activation failed: -110 thunderbolt-net 0-1.0 thunderbolt0: failed to enable DMA paths On an Apple M4 Pro (T6040) host connected to an M2 this happened in 7 of 17 remote down/up cycles; the host router never answered a config read again until the link was reset, so the network did not come back. Every failing cycle had a second login request arriving within microseconds of the RX path activation, none of the passing ones did. Record the request under a spinlock in the handler and answer it from a worker instead. The worker takes connection_lock, so the response is also no longer transmitted on the control channel in the middle of the path setup. A newer request replaces one that has not been answered yet. The Rx HopID is only updated while the rings are stopped, since the one in use is released at teardown. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/net/thunderbolt/main.c | 122 ++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 23 deletions(-) diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c index 8f3a05e07d717..dcac37524056b 100644 --- a/drivers/net/thunderbolt/main.c +++ b/drivers/net/thunderbolt/main.c @@ -150,6 +150,22 @@ struct tbnet_ring { struct page_pool *pool; }; +/** + * struct tbnet_login_rx - Remote login request waiting for an answer + * @pending: A request has been received and not answered yet + * @route: Route the request came from + * @sequence: Sequence number of the request + * @command_id: Command ID of the request + * @transmit_path: HopID the remote host transmits on + */ +struct tbnet_login_rx { + bool pending; + u64 route; + u8 sequence; + u32 command_id; + int transmit_path; +}; + /** * struct tbnet - ThunderboltIP network driver private data * @svc: XDomain service the driver is bound to @@ -172,6 +188,9 @@ struct tbnet_ring { * teardown and NAPI enable state. * @login_retries: Number of login retries currently done * @login_work: Worker to send ThunderboltIP login packets + * @login_rx_lock: Protects @login_rx + * @login_rx: Latest remote login request that has not been answered yet + * @login_rx_work: Worker that answers @login_rx * @rx_refill_work: Worker to reschedule Rx polling after a refill failure * @connected_work: Worker that finalizes the ThunderboltIP connection * setup and enables DMA paths for high speed data @@ -205,6 +224,9 @@ struct tbnet { struct mutex connection_lock; int login_retries; struct delayed_work login_work; + spinlock_t login_rx_lock; + struct tbnet_login_rx login_rx; + struct work_struct login_rx_work; struct delayed_work rx_refill_work; struct work_struct connected_work; struct work_struct disconnect_work; @@ -333,6 +355,10 @@ static void start_login(struct tbnet *net) static void stop_login(struct tbnet *net) { + cancel_work_sync(&net->login_rx_work); + spin_lock(&net->login_rx_lock); + net->login_rx.pending = false; + spin_unlock(&net->login_rx_lock); cancel_delayed_work_sync(&net->login_work); cancel_work_sync(&net->connected_work); @@ -484,29 +510,27 @@ static int tbnet_handle_packet(const void *buf, size_t size, void *data) if (!netif_running(net->dev)) break; - ret = tbnet_login_response(net, route, sequence, - pkg->hdr.command_id); - if (!ret) { - netdev_dbg(net->dev, "remote login response sent\n"); - - mutex_lock(&net->connection_lock); - net->login_received = true; - net->remote_transmit_path = pkg->transmit_path; - - /* If we reached the number of max retries or - * previous logout, schedule another round of - * login retries - */ - if (net->login_retries >= TBNET_LOGIN_RETRIES || - !net->login_sent) { - net->login_retries = 0; - queue_delayed_work(system_long_wq, - &net->login_work, 0); - } - mutex_unlock(&net->connection_lock); - - queue_work(system_long_wq, &net->connected_work); - } + /* + * This runs in the control channel Rx path. Answering the + * request and updating the login state needs + * @connection_lock, which tbnet_connected_work() holds + * while it programs the DMA paths through this same + * control channel. Waiting for the lock here stalls the + * channel, so those config space accesses time out. The + * remote host can send a second login request while we + * are connecting (both ends log in at once), so hand the + * request to a worker. A newer request replaces one that + * has not been answered yet. + */ + spin_lock(&net->login_rx_lock); + net->login_rx.route = route; + net->login_rx.sequence = sequence; + net->login_rx.command_id = command_id; + net->login_rx.transmit_path = pkg->transmit_path; + net->login_rx.pending = true; + spin_unlock(&net->login_rx_lock); + + queue_work(system_long_wq, &net->login_rx_work); break; case TBIP_LOGOUT: @@ -733,6 +757,53 @@ static void tbnet_connected_work(struct work_struct *work) mutex_unlock(&net->connection_lock); } +static void tbnet_login_rx_work(struct work_struct *work) +{ + struct tbnet *net = container_of(work, typeof(*net), login_rx_work); + struct tbnet_login_rx req; + int ret; + + spin_lock(&net->login_rx_lock); + req = net->login_rx; + net->login_rx.pending = false; + spin_unlock(&net->login_rx_lock); + + if (!req.pending || !netif_running(net->dev)) + return; + + /* + * Answer under @connection_lock so that the response does not go + * out on the control channel while tbnet_connected_work() is + * programming the DMA paths. + */ + mutex_lock(&net->connection_lock); + ret = tbnet_login_response(net, req.route, req.sequence, + req.command_id); + if (ret) { + mutex_unlock(&net->connection_lock); + netdev_warn(net->dev, "failed to send ThunderboltIP response\n"); + return; + } + + netdev_dbg(net->dev, "remote login response sent\n"); + + net->login_received = true; + /* The Rx HopID in use is released at teardown, keep it until then */ + if (!net->rings_started) + net->remote_transmit_path = req.transmit_path; + + /* If we reached the number of max retries or previous logout, + * schedule another round of login retries + */ + if (net->login_retries >= TBNET_LOGIN_RETRIES || !net->login_sent) { + net->login_retries = 0; + queue_delayed_work(system_long_wq, &net->login_work, 0); + } + mutex_unlock(&net->connection_lock); + + queue_work(system_long_wq, &net->connected_work); +} + static void tbnet_login_work(struct work_struct *work) { struct tbnet *net = container_of(work, typeof(*net), login_work.work); @@ -1461,6 +1532,8 @@ static int tbnet_probe(struct tb_service *svc) INIT_DELAYED_WORK(&net->login_work, tbnet_login_work); INIT_DELAYED_WORK(&net->rx_refill_work, tbnet_rx_refill_work); INIT_WORK(&net->connected_work, tbnet_connected_work); + INIT_WORK(&net->login_rx_work, tbnet_login_rx_work); + spin_lock_init(&net->login_rx_lock); INIT_WORK(&net->disconnect_work, tbnet_disconnect_work); mutex_init(&net->connection_lock); spin_lock_init(&net->poll_lock); @@ -1531,6 +1604,7 @@ static void tbnet_remove(struct tb_service *svc) unregister_netdev(net->dev); /* A logout received while the interface was down queued this. */ cancel_work_sync(&net->disconnect_work); + cancel_work_sync(&net->login_rx_work); free_netdev(net->dev); } @@ -1551,6 +1625,8 @@ static int tbnet_suspend(struct device *dev) } tb_unregister_protocol_handler(&net->handler); + /* A login request may have arrived before the handler went away */ + cancel_work_sync(&net->login_rx_work); return 0; } From 9251a1cf428ec4c51217f725996aa3e4170457da Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:06:38 +1100 Subject: [PATCH 263/342] net: thunderbolt: Log in again when the DMA paths could not be enabled When tb_xdomain_enable_paths() fails, tbnet_connected_work() stops the rings and clears login_sent, and nothing else happens. If the remote end got its own paths up it keeps its carrier on and does not send another login request, so the link stays down until one of the ends is restarted. Queue a new login after TBNET_LOGIN_DELAY when connecting fails, up to three times per login round, so that a transient failure recovers on its own. A successful connection and start_login() reset the count. stop_login() cancels the login work a second time after the connect work is gone, since a failing connect attempt can queue it again. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/net/thunderbolt/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c index dcac37524056b..f4d63584e6efe 100644 --- a/drivers/net/thunderbolt/main.c +++ b/drivers/net/thunderbolt/main.c @@ -34,6 +34,7 @@ #define TBNET_RING_SIZE 256 #define TBNET_LOGIN_RETRIES 60 +#define TBNET_CONNECT_RETRIES 3 #define TBNET_LOGOUT_RETRIES 10 #define TBNET_THROTTLING 128000 #define TBNET_E2E BIT(0) @@ -187,6 +188,8 @@ struct tbnet_login_rx { * @connection_lock: Lock serializing login state, connection setup, * teardown and NAPI enable state. * @login_retries: Number of login retries currently done + * @connect_retries: Number of new logins started after the DMA paths + * could not be enabled * @login_work: Worker to send ThunderboltIP login packets * @login_rx_lock: Protects @login_rx * @login_rx: Latest remote login request that has not been answered yet @@ -223,6 +226,7 @@ struct tbnet { int remote_transmit_path; struct mutex connection_lock; int login_retries; + int connect_retries; struct delayed_work login_work; spinlock_t login_rx_lock; struct tbnet_login_rx login_rx; @@ -347,6 +351,7 @@ static void start_login(struct tbnet *net) mutex_lock(&net->connection_lock); net->login_sent = false; net->login_received = false; + net->connect_retries = 0; mutex_unlock(&net->connection_lock); queue_delayed_work(system_long_wq, &net->login_work, @@ -361,6 +366,8 @@ static void stop_login(struct tbnet *net) spin_unlock(&net->login_rx_lock); cancel_delayed_work_sync(&net->login_work); cancel_work_sync(&net->connected_work); + /* A failed connection attempt may have started another login */ + cancel_delayed_work_sync(&net->login_work); netdev_dbg(net->dev, "login stopped\n"); } @@ -679,6 +686,21 @@ static void tbnet_connect_failed_locked(struct tbnet *net) /* Leave login_received set: only the peer can make it true again. */ lockdep_assert_held(&net->connection_lock); net->login_sent = false; + + /* + * The remote end may already consider the connection up and then + * never logs in again, so nothing would retry. Start a new login + * after a delay, a few times. + */ + if (netif_running(net->dev) && + net->connect_retries < TBNET_CONNECT_RETRIES) { + net->connect_retries++; + netdev_dbg(net->dev, "connection failed, new login in %u ms (%d/%d)\n", + TBNET_LOGIN_DELAY, net->connect_retries, + TBNET_CONNECT_RETRIES); + queue_delayed_work(system_long_wq, &net->login_work, + msecs_to_jiffies(TBNET_LOGIN_DELAY)); + } } static void tbnet_connected_work(struct work_struct *work) @@ -738,6 +760,7 @@ static void tbnet_connected_work(struct work_struct *work) goto err_stop_rings; } + net->connect_retries = 0; netif_carrier_on(net->dev); netif_start_queue(net->dev); From e847be17c139b0aff6f272fd5a741a4bb8de4d57 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:11:48 +1100 Subject: [PATCH 264/342] thunderbolt: apple: Restart the port when the peer link is lost When the peer on the USB4 port drops the link but the cable stays attached, the ACIO firmware puts the port group into its dead end state and waits for the host to power the block off: ... lane_init.c:1110: SBX disconnected! ... port_group.c:1528: Port Group - entering Dead End state thunderbolt-apple-nhi 381f00000.nhi: 0:1: xdomain unplugged ... port_group.c:1511: ACIO was not powered off after 2 seconds in Dead-End state ... (repeated every 2 s) A peer that reboots or powers off is reported by the Type-C controller as a cable change about 0.5 s later, which stops and restarts the ACIO, so the port recovers. When no cable change follows, for example when the peer resets its own port right after the lanes were bonded, nothing restarts it and the port stays down until a reboot. This was seen on an M4 Pro (T6040) connected to an M2 in 1 of 17 M2 reboots: the link came up while the M2 was booting, the M2 reset its port 0.5 s after bonding, and the M4 Pro port never trained again. Add a link_lost hook to struct tb_nhi_ops that the software connection manager calls when the router or host on a host router lane adapter is unplugged. The Apple NHI arms a 3 s check. If the cable is still attached, the port was not restarted meanwhile and no peer came back, it asks CD321x to revalidate the cable with a failed connection check, which cycles the ACIO and the PHY. Do this at most three times until a peer is found again. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/thunderbolt/apple.c | 113 +++++++++++++++++++++++++++++++++++- drivers/thunderbolt/nhi.h | 5 ++ drivers/thunderbolt/tb.c | 11 ++++ 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 3374e0d3e794f..d026801b283f9 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -217,6 +217,14 @@ static const struct apple_cio_hw apple_cio_t6040_hw = { #define APPLE_CIO_SLEEP_RESTART_FALLBACK_MS 10000 /* How long a forced cable cycle may take before it no longer counts. */ #define APPLE_CIO_RESUME_RECOVERY_WINDOW_MS 30000 +/* + * After a peer drops the link without the cable going away, the ACIO + * firmware parks the port and waits for the host to power it off. A peer + * that reboots or goes away electrically is reported as a cable change + * within about 0.5 s and restarts the port anyway. + */ +#define APPLE_CIO_LINK_LOST_MS 3000 +#define APPLE_CIO_LINK_LOST_CYCLES 3 static bool resume_recovery; module_param(resume_recovery, bool, 0644); @@ -325,6 +333,12 @@ struct apple_cio { bool resume_recovery_failed; /* terminal recovery failure */ bool resume_link_failed; /* protected by lock */ bool resume_link_pending; /* set by NHI resume, consumed by ACIO complete */ + struct delayed_work link_lost_work; + unsigned int start_gen; /* protected by lock: bumped by every start */ + unsigned int link_lost_gen; /* start_gen when the peer went away */ + unsigned int link_lost_cycles; /* protected by lock */ + u64 link_lost_cycle_activity; /* remote activity at the last cycle */ + bool link_lost_restart; /* protected by lock: cycle requested */ struct notifier_block pm_notifier; struct delayed_work sleep_restart_work; enum { @@ -2053,8 +2067,27 @@ static bool apple_nhi_add_links(struct tb_nhi *nhi) return true; } +/* + * Called with the domain lock held when the peer on a host router lane + * adapter went away: only (re)arm the check. + */ +static void apple_nhi_link_lost(struct tb_nhi *nhi) +{ + struct apple_nhi *anhi = nhi_to_anhi(nhi); + struct apple_cio *acio = anhi->acio; + u64 activity = atomic64_read(&anhi->tb->remote_activity); + + /* A peer was found since the last cycle: that cycle worked */ + if (activity != READ_ONCE(acio->link_lost_cycle_activity)) + WRITE_ONCE(acio->link_lost_cycles, 0); + WRITE_ONCE(acio->link_lost_gen, READ_ONCE(acio->start_gen)); + mod_delayed_work(system_freezable_wq, &acio->link_lost_work, + msecs_to_jiffies(APPLE_CIO_LINK_LOST_MS)); +} + static const struct tb_nhi_ops apple_nhi_ops = { .add_links = apple_nhi_add_links, + .link_lost = apple_nhi_link_lost, .request_ring_irq = apple_nhi_request_irq, .release_ring_irq = apple_nhi_release_irq, .ring_interrupt_active = apple_nhi_ring_interrupt_active, @@ -2689,6 +2722,7 @@ static void apple_cio_stop(struct apple_cio *acio) acio->current_cable_info = 0; acio->resume_link_failed = false; + acio->link_lost_restart = false; } /* Only called while the ACIO power domains are on. */ @@ -2905,6 +2939,7 @@ static int apple_cio_start(struct apple_cio *acio) } acio->current_cable_info = acio->target_cable_info; + acio->start_gen++; return 0; err_depopulate: @@ -2935,7 +2970,7 @@ static int apple_cio_check_connection(struct apple_cio *acio) lockdep_assert_held(&acio->lock); /* Ask CD321x to cycle ACIO and the PHY using a fresh cable snapshot. */ - if (acio->resume_link_failed) + if (acio->resume_link_failed || acio->link_lost_restart) return -ENOLINK; guard(mutex)(&acio->pcie_tunnel_lock); if (!READ_ONCE(acio->nhi_pdev) || acio->pcie_tunnel_stopping || @@ -3000,6 +3035,79 @@ static int apple_cio_link_connected(struct apple_cio *acio) return verdict; } +/* Whether a router or host is connected to a lane adapter of the host router */ +static bool apple_cio_has_peer(struct apple_cio *acio, u64 *activity) +{ + struct platform_device *pdev = READ_ONCE(acio->nhi_pdev); + struct apple_nhi *anhi; + struct tb_port *port; + bool peer = true; + + lockdep_assert_held(&acio->lock); + if (!pdev) + return true; + device_lock(&pdev->dev); + anhi = platform_get_drvdata(pdev); + if (!pdev->dev.driver || !anhi || !anhi->tb) + goto unlock; + + scoped_guard(mutex, &anhi->tb->lock) { + *activity = atomic64_read(&anhi->tb->remote_activity); + peer = false; + tb_switch_for_each_port(anhi->tb->root_switch, port) { + if (!tb_port_is_null(port)) + continue; + if ((port->xdomain && !port->xdomain->is_unplugged) || + (port->remote && !port->remote->sw->is_unplugged)) + peer = true; + } + } +unlock: + device_unlock(&pdev->dev); + return peer; +} + +/* + * The peer dropped the link but the cable is still attached and no cable + * change followed. The firmware leaves the port down until it is powered + * off, so have CD321x cycle it with a fresh cable snapshot, a few times. + */ +static void apple_cio_link_lost_work(struct work_struct *work) +{ + struct apple_cio *acio = container_of(to_delayed_work(work), + struct apple_cio, link_lost_work); + u64 activity = 0; + bool notify = false; + + scoped_guard(mutex, &acio->lock) { + if (acio->removing || !acio->current_cable_info || + !acio->target_cable_info || + acio->sleep_phase != APPLE_CIO_SLEEP_OPEN || + acio->resume_recovery_failed || + acio->start_gen != READ_ONCE(acio->link_lost_gen)) + return; + if (apple_cio_has_peer(acio, &activity)) + return; + if (acio->link_lost_cycles >= APPLE_CIO_LINK_LOST_CYCLES) { + dev_warn(acio->dev, + "peer link still down after %u port restarts, leaving the port alone\n", + acio->link_lost_cycles); + return; + } + acio->link_lost_cycles++; + WRITE_ONCE(acio->link_lost_cycle_activity, activity); + acio->link_lost_restart = true; + dev_info(acio->dev, + "peer link lost with the cable attached, restarting the port (%u/%u)\n", + acio->link_lost_cycles, APPLE_CIO_LINK_LOST_CYCLES); + notify = true; + } + + /* CD321x may tear down the NHI: never notify under either driver lock. */ + if (notify) + typec_thunderbolt_switch_notify(acio->tbt_switch); +} + static void apple_cio_resume_link_work(struct work_struct *work) { struct apple_cio *acio = container_of(to_delayed_work(work), @@ -3043,6 +3151,7 @@ static int apple_cio_prepare(struct device *dev) /* Drain before taking lock; the worker acquires it to check the link. */ cancel_delayed_work_sync(&acio->resume_link_work); + cancel_delayed_work_sync(&acio->link_lost_work); scoped_guard(mutex, &acio->lock) { WRITE_ONCE(acio->resume_link_pending, false); acio->resume_link_failed = false; @@ -3331,6 +3440,7 @@ static int apple_cio_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&acio->pcie_tunnel_work, apple_cio_pcie_tunnel_work); INIT_DELAYED_WORK(&acio->resume_link_work, apple_cio_resume_link_work); + INIT_DELAYED_WORK(&acio->link_lost_work, apple_cio_link_lost_work); INIT_DELAYED_WORK(&acio->sleep_restart_work, apple_cio_sleep_restart_work); init_completion(&acio->nhi_boot_completion); acio->dev = &pdev->dev; @@ -3531,6 +3641,7 @@ static void apple_cio_remove(struct platform_device *pdev) disable_delayed_work_sync(&acio->sleep_restart_work); disable_delayed_work_sync(&acio->resume_link_work); + disable_delayed_work_sync(&acio->link_lost_work); /* The worker can notify this switch; stop current and future enqueues. */ disable_delayed_work_sync(&acio->pcie_tunnel_work); /* A set may hold the switch read lock while waiting for acio->lock. */ diff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h index 75795fbf865a1..dbf1e4b407c52 100644 --- a/drivers/thunderbolt/nhi.h +++ b/drivers/thunderbolt/nhi.h @@ -106,6 +106,10 @@ struct tb_nhi_ring_layout { * %true if the host orders all of its tunneled native ports, so * none is left without a link. * @is_present: Whether the device is currently present on the parent bus + * @link_lost: Called with the domain lock held when the router or host + * connected to a lane adapter of the host router is unplugged. + * Lets the NHI recover a port whose link went down while the + * cable stays attached. * @init_interrupts: NHI specific interrupt initialization hook * @reset_interface: Resets the host interface */ @@ -134,6 +138,7 @@ struct tb_nhi_ops { struct tb_port *out, u64 generation); bool (*add_links)(struct tb_nhi *nhi); bool (*is_present)(struct tb_nhi *nhi); + void (*link_lost)(struct tb_nhi *nhi); void (*dp_tunnel_changed)(struct tb_nhi *nhi, u8 in_port, u64 generation, bool active); bool (*dp_tunnel_awaits_display)(struct tb_nhi *nhi, struct tb_port *in); int (*init_interrupts)(struct tb_nhi *nhi); diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c index 19c1389c63d87..ad59f4ede6bfc 100644 --- a/drivers/thunderbolt/tb.c +++ b/drivers/thunderbolt/tb.c @@ -3258,6 +3258,15 @@ static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd, /* hotplug handling */ +/* The partner on a host router lane adapter went away */ +static void tb_host_link_lost(struct tb *tb, struct tb_port *port) +{ + if (tb_route(port->sw) || !tb_port_is_null(port)) + return; + if (tb->nhi->ops && tb->nhi->ops->link_lost) + tb->nhi->ops->link_lost(tb->nhi); +} + /* * tb_handle_hotplug() - handle hotplug event * @@ -3322,6 +3331,7 @@ static void tb_handle_hotplug(struct work_struct *work) tb_recalc_estimated_bandwidth(tb); tb_tunnel_dp(tb); tb_dp_host_tunnel_gone(tb, dp_up); + tb_host_link_lost(tb, port); } else if (port->xdomain) { struct tb_xdomain *xd = tb_xdomain_get(port->xdomain); @@ -3339,6 +3349,7 @@ static void tb_handle_hotplug(struct work_struct *work) __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1); tb_xdomain_put(xd); tb_port_unconfigure_xdomain(port); + tb_host_link_lost(tb, port); } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) { tb_dp_resource_unavailable(tb, port, "adapter unplug"); /* A display went: the DP tunnel left may take a higher rate. */ From d39547b6a405c448d20a9e09c35307ce1957eb5e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:01:34 +1100 Subject: [PATCH 265/342] drm/asahi: agx_stats: skip the idle gap in the first busy window busy_ns integrates Utilization windows: each message closes the window that started at the previous one and counts it at its busy percentage. The firmware sends no Utilization while the GPU is powered off, so the first message after power-up spanned the whole idle gap and counted it at the new load. On T6000 and T8112 busy_ns rose 2.4-2.6 s above elapsed time in the first window of a load that followed idle. Drop the window baseline when PowerOff or PowerOn arrives, so the first Utilization after power-up only starts a window. Move the integration into a small BusyIntegrator (stats_busy.rs) with KUnit cases for the weighting, the whole-second split, the power gap, a timestamp that goes back and saturation; tools/asahi/agx-stats-busy-tests.py runs them on the host, with a negative control that removes the baseline drop. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/asahi/asahi_core.rs | 1 + drivers/gpu/drm/asahi/channel.rs | 56 +++++--------- drivers/gpu/drm/asahi/stats.rs | 6 +- drivers/gpu/drm/asahi/stats_busy.rs | 114 ++++++++++++++++++++++++++++ tools/asahi/agx-stats-busy-tests.py | 64 ++++++++++++++++ tools/asahi/run-host-tests.py | 1 + 6 files changed, 203 insertions(+), 39 deletions(-) create mode 100644 drivers/gpu/drm/asahi/stats_busy.rs create mode 100755 tools/asahi/agx-stats-busy-tests.py diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index 1a5cf1ba9a7c1..a9ed7a204b3b8 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -40,6 +40,7 @@ mod queue; mod regs; mod slotalloc; mod stats; +mod stats_busy; mod stats_raw; mod sysfs_exports; mod timestamp; diff --git a/drivers/gpu/drm/asahi/channel.rs b/drivers/gpu/drm/asahi/channel.rs index 5a14982dca053..dbb84f288087b 100644 --- a/drivers/gpu/drm/asahi/channel.rs +++ b/drivers/gpu/drm/asahi/channel.rs @@ -595,13 +595,11 @@ pub(crate) struct StatsChannel { /// Last raw sample of every statistics kind, shared with the export /// through `crate::stats_raw`. raw: Arc>, - /// Rate of firmware stats-message timestamps (Hz). All stats timestamps - /// run on the chip base clock (`HwConfig::base_clock_hz`, 24 MHz on every - /// supported SoC), not nanoseconds. - ts_hz: u64, - /// Last `Utilization` message timestamp (raw base-clock ticks), for - /// utilization-weighted `busy_ns` integration. - last_util_ts: u64, + /// Utilization-weighted `busy_ns` integration across `Utilization` + /// windows. All stats timestamps run on the chip base clock + /// (`HwConfig::base_clock_hz`, 24 MHz on every supported SoC), not + /// nanoseconds. + busy: crate::stats_busy::BusyIntegrator, } #[versions(AGX)] @@ -619,8 +617,7 @@ impl StatsChannel::ver { ch: RxChannel::::new(alloc, 0x100)?, snap, raw, - ts_hz, - last_util_ts: 0, + busy: crate::stats_busy::BusyIntegrator::new(ts_hz), }) } @@ -666,37 +663,20 @@ impl StatsChannel::ver { // across a saturated 30 s matmul and 0-2 on // an idle desktop, while FwBusy timestamp // deltas (the prior producer) covered 0.17% - // of that matmul. The timestamps are base- - // clock ticks (24 MHz), so convert to ns - // once here. The kernel runtime has no - // 128-bit division, so split whole seconds - // from the tick remainder: whole seconds - // contribute util * 1e7 ns each (1e9 / 100 - // exactly), the remainder contributes - // rem * util * 1e9 / (100 * ts_hz), which - // cannot overflow u64 (rem < ts_hz <= 24e6 - // on supported SoCs). - let util = u64::from( - [*util1, *util2, *util3, *util4] - .into_iter() - .max() - .unwrap_or(0) - .min(100), - ); - let ts = timestamp.0; - if self.last_util_ts != 0 && ts > self.last_util_ts { - let delta = ts - self.last_util_ts; - let whole_s = delta / self.ts_hz; - let rem = delta % self.ts_hz; - let busy = whole_s - .saturating_mul(util) - .saturating_mul(10_000_000) - .saturating_add( - rem * util * 1_000_000_000 / (100 * self.ts_hz), - ); + // of that matmul. + let util = [*util1, *util2, *util3, *util4] + .into_iter() + .max() + .unwrap_or(0); + let busy = self.busy.utilization(timestamp.0, util); + if busy != 0 { self.snap.busy_ns.fetch_add(busy, Ordering::Relaxed); } - self.last_util_ts = ts; + } + // No Utilization is sent while the GPU is off: + // the next window must not span the gap. + StatsMsg::ver::PowerOn { .. } | StatsMsg::ver::PowerOff { .. } => { + self.busy.power_changed(); } StatsMsg::ver::PowerState { pstate, .. } => { self.snap.pstate.store(*pstate, Ordering::Relaxed); diff --git a/drivers/gpu/drm/asahi/stats.rs b/drivers/gpu/drm/asahi/stats.rs index 387ff578369a8..b8636d4c5eb70 100644 --- a/drivers/gpu/drm/asahi/stats.rs +++ b/drivers/gpu/drm/asahi/stats.rs @@ -26,7 +26,11 @@ //! derived from successive `Utilization` windows (busiest subqueue //! percentage x window duration; the firmware timestamps are base-clock //! ticks, 24 MHz, converted with `HwConfig::base_clock_hz`). Monotonic and -//! bounded by elapsed time. Saturates at u64::MAX. +//! bounded by elapsed time. Saturates at u64::MAX. A window only counts +//! while the GPU stayed powered: `PowerOff`/`PowerOn` drop the baseline, +//! so the idle gap before the first window after power-up is not credited +//! at that window's (busy) percentage. See +//! [`crate::stats_busy::BusyIntegrator`]. //! - `jobs`: completed submissions since boot, counted at submission //! completion (`JobFence::command_complete`). //! diff --git a/drivers/gpu/drm/asahi/stats_busy.rs b/drivers/gpu/drm/asahi/stats_busy.rs new file mode 100644 index 0000000000000..b354d3d0ca5e8 --- /dev/null +++ b/drivers/gpu/drm/asahi/stats_busy.rs @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Utilization-weighted busy time for the legacy `agx_stats` `busy_ns` field. + +/// Integrates `Utilization` windows into utilization-weighted busy time. +/// +/// Each `Utilization` message carries a base-clock timestamp and the busy +/// percentage of the window that ends there; the window starts at the +/// previous message. The firmware sends no `Utilization` while the GPU is +/// powered off, so the first message after power-up would otherwise span +/// the whole idle gap and credit it at the new, typically 100%, load (the +/// first window after idle read 2.4-2.6 s too high on T6000 and T8112). +/// `PowerOff` and `PowerOn` therefore drop the baseline: the first window +/// after power-up only sets it. That loses at most the one short window in +/// which the GPU powered up, instead of crediting the idle gap. +pub(crate) struct BusyIntegrator { + ts_hz: u64, + last_ts: Option, +} + +impl BusyIntegrator { + /// `ts_hz` is the rate of the firmware timestamps (the chip base clock). + pub(crate) fn new(ts_hz: u64) -> Self { + Self { + ts_hz: ts_hz.max(1), + last_ts: None, + } + } + + /// The GPU powered off or on: the next window has no valid start. + pub(crate) fn power_changed(&mut self) { + self.last_ts = None; + } + + /// Account one `Utilization` message at `ts` (base-clock ticks) with + /// busiest-subqueue percentage `util`; returns the busy nanoseconds of + /// the window it closes. + /// + /// The kernel runtime has no 128-bit division, so whole seconds + /// contribute `util * 1e7` ns each (1e9 / 100 exactly) and the tick + /// remainder `rem * util * 1e9 / (100 * ts_hz)`, which cannot overflow + /// u64 (rem < ts_hz <= 24e6 on supported SoCs). + pub(crate) fn utilization(&mut self, ts: u64, util: u32) -> u64 { + let util = u64::from(util.min(100)); + let busy = match self.last_ts { + Some(last) if ts > last => { + let delta = ts - last; + let whole_s = delta / self.ts_hz; + let rem = delta % self.ts_hz; + whole_s + .saturating_mul(util) + .saturating_mul(10_000_000) + .saturating_add(rem * util * 1_000_000_000 / (100 * self.ts_hz)) + } + _ => 0, + }; + self.last_ts = Some(ts); + busy + } +} + +#[kernel::macros::kunit_tests(asahi_stats_busy)] +mod tests { + use super::*; + + const HZ: u64 = 24_000_000; + + #[test] + fn windows_are_weighted_by_utilization() { + let mut b = BusyIntegrator::new(HZ); + assert_eq!(b.utilization(1_000, 100), 0); + // 10 ms at 100%, then 10 ms at 50%. + assert_eq!(b.utilization(1_000 + 240_000, 100), 10_000_000); + assert_eq!(b.utilization(1_000 + 480_000, 50), 5_000_000); + // Over 100% is clamped. + assert_eq!(b.utilization(1_000 + 720_000, 250), 10_000_000); + } + + #[test] + fn long_windows_split_whole_seconds() { + let mut b = BusyIntegrator::new(HZ); + b.utilization(0, 0); + // 2.5 s at 100%. A first timestamp of 0 is a valid baseline. + assert_eq!(b.utilization(60_000_000, 100), 2_500_000_000); + } + + #[test] + fn idle_gap_after_power_off_is_not_credited() { + let mut b = BusyIntegrator::new(HZ); + b.utilization(HZ, 0); + // PowerOff, then PowerOn 2.5 s later. + b.power_changed(); + b.power_changed(); + // First window after power-up: baseline only. + assert_eq!(b.utilization(HZ + 60_000_000 + 240_000, 100), 0); + assert_eq!(b.utilization(HZ + 60_000_000 + 480_000, 100), 10_000_000); + } + + #[test] + fn a_timestamp_that_goes_back_only_rebases() { + let mut b = BusyIntegrator::new(HZ); + b.utilization(5 * HZ, 100); + assert_eq!(b.utilization(HZ, 100), 0); + assert_eq!(b.utilization(HZ + 240_000, 100), 10_000_000); + assert_eq!(b.utilization(HZ + 240_000, 100), 0); + } + + #[test] + fn huge_windows_saturate() { + let mut b = BusyIntegrator::new(1); + b.utilization(1, 100); + assert_eq!(b.utilization(u64::MAX, 100), u64::MAX); + } +} diff --git a/tools/asahi/agx-stats-busy-tests.py b/tools/asahi/agx-stats-busy-tests.py new file mode 100755 index 0000000000000..8854add06bc0c --- /dev/null +++ b/tools/asahi/agx-stats-busy-tests.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Run the agx_stats busy_ns integrator's KUnit cases on the host. + +BusyIntegrator (drivers/gpu/drm/asahi/stats_busy.rs) turns the firmware's +Utilization windows into busy_ns. The cases pin that a window is weighted by +its utilization, that whole seconds are split from the tick remainder, and +that a PowerOff/PowerOn drops the baseline so the idle gap is never credited. + +--negative-control turns power_changed() into a no-op and requires the cases +to fail, so the harness is shown to catch the over-count it guards against. +""" + +import argparse +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +STATS = ROOT / "drivers/gpu/drm/asahi/stats_busy.rs" +ATTR = "#[kernel::macros::kunit_tests(asahi_stats_busy)]" + + +def source(negative): + text = STATS.read_text() + start = text.index("pub(crate) struct BusyIntegrator") + body = text[start:] + assert ATTR in body, "KUnit suite attribute moved" + body = body.replace(ATTR, "#[cfg(test)]") + if negative: + old = " self.last_ts = None;\n" + assert body.count(old) == 1 + body = body.replace(old, "") + return "#![allow(dead_code)]\n" + body + + +def run(negative): + with tempfile.TemporaryDirectory(prefix="asahi-busy-") as tmp: + main = Path(tmp) / "main.rs" + main.write_text(source(negative)) + binary = Path(tmp) / "test" + subprocess.run(["rustc", "--edition=2021", "--test", "-Dwarnings", str(main), "-o", str(binary)], + check=True) + return subprocess.run([str(binary), "--test-threads=1"], + capture_output=negative).returncode + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--negative-control", action="store_true") + args = parser.parse_args() + rc = run(args.negative_control) + if args.negative_control: + if rc == 0: + print("negative control: the cases passed without the baseline drop") + return 1 + print("negative control: the cases fail without the baseline drop (expected)") + return 0 + return rc + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index b878404b2d9fa..1937bd816f795 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -71,6 +71,7 @@ def mutations(flag, names, base, expect=KILL): 'apple-dart-fw-tests.py': [(out(), PASS)], 'apple-dart-range-tests.py': [([], PASS)], 'asahi-stats-raw-tests.py': [([], PASS)], + 'agx-stats-busy-tests.py': [([], PASS), (['--negative-control'], PASS)], 'atc-usb3-tests.py': [(out(), PASS), (out() + ['--mutations'], PASS)], 'avd-av1-tail-tests.py': [(out(), PASS)] + [(out() + ['--case', c], PASS) for c in ('copy', 'seed', 'aligned')] From 6c8b0f71ed35db01b335b82d3e31c76d3b9a44e2 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:13:52 +1100 Subject: [PATCH 266/342] usb: typec: tipd: Take the USB4 router again after it rebinds CD321x looks up the USB4/Thunderbolt switch of its router once, at probe (or when the router binds late). When the router driver unbinds and binds again, for example "echo 381ac0000.cio > .../unbind" and "bind" for the Apple ACIO, the old switch is unregistered and the router registers a new one. CD321x keeps the old handle, every cable update then fails with -ENODEV, it ends with "cable revalidation failed", and the port never comes back: the ACIO is not started again, there is no NHI and no link until a reboot. Add typec_thunderbolt_switch_is_live() so that a consumer can tell that the provider of its handle went away. Watch for switch registration on every port with a router, not only on a port that probed without it. When the router registers a switch while the one in use is gone, move the notifier to the new switch, drop the old handle and reapply the cable state as for a router that binds late. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/usb/typec/mux.c | 20 ++++++++++++ drivers/usb/typec/tipd/cd321x-tbt-test.c | 40 ++++++++++++++++++++++++ drivers/usb/typec/tipd/core.c | 33 ++++++++++++++----- include/linux/usb/typec_mux.h | 7 +++++ 4 files changed, 93 insertions(+), 7 deletions(-) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index db28d50cf61b6..71293c645c51b 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -866,6 +866,26 @@ void typec_thunderbolt_switch_put(struct typec_thunderbolt_switch *sw) } EXPORT_SYMBOL_GPL(typec_thunderbolt_switch_put); +/** + * typec_thunderbolt_switch_is_live - Whether the switch provider is still bound + * @sw: USB4/Thunderbolt switch + * + * A handle outlives the provider: once the provider unregisters its switch, + * typec_thunderbolt_switch_set() fails with -ENODEV. A provider that binds + * again registers a new switch, which must be looked up again. + * + * Return: %true if @sw is valid and its provider is still registered. + */ +bool typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw) +{ + if (IS_ERR_OR_NULL(sw)) + return false; + + guard(rwsem_read)(&sw->sw_dev->set_lock); + return sw->sw_dev->set; +} +EXPORT_SYMBOL_GPL(typec_thunderbolt_switch_is_live); + /** * typec_thunderbolt_switch_set - Forward cable details to USB4/Thunderbolt switch * @sw: USB4/Thunderbolt switch diff --git a/drivers/usb/typec/tipd/cd321x-tbt-test.c b/drivers/usb/typec/tipd/cd321x-tbt-test.c index ee46db0734c41..5ed8a2ab136ce 100644 --- a/drivers/usb/typec/tipd/cd321x-tbt-test.c +++ b/drivers/usb/typec/tipd/cd321x-tbt-test.c @@ -367,6 +367,45 @@ static void cd321x_tbt_router_binds_after_removal_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, cd->tbt_notifier_registered); } +/* A router that unbinds and binds again is taken again; the cable is reread. */ +static void cd321x_tbt_router_rebinds_test(struct kunit *test) +{ + struct cd321x *cd = cd321x_tbt_test_late_port(test); + struct typec_thunderbolt_switch_desc desc = { + .fwnode = software_node_fwnode(&cd321x_test_router), + .set = cd321x_tbt_test_set, + .name = "router-first", + }; + struct typec_thunderbolt_switch_dev *sw_dev; + struct device *router; + int ret; + + router = kunit_device_register(test, "router-first"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, router); + sw_dev = typec_thunderbolt_switch_register(router, &desc); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sw_dev); + + ret = cd321x_tbt_watch_late(cd, software_node_fwnode(&cd321x_test_connector)); + KUNIT_ASSERT_EQ(test, ret, 0); + flush_work(&cd->tbt_attach_work); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cd->tbt_switch); + KUNIT_EXPECT_TRUE(test, typec_thunderbolt_switch_is_live(cd->tbt_switch)); + KUNIT_EXPECT_EQ(test, atomic_read(&cd->restore_event), 1); + atomic_set(&cd->restore_event, 0); + + typec_thunderbolt_switch_unregister(sw_dev); + KUNIT_EXPECT_FALSE(test, typec_thunderbolt_switch_is_live(cd->tbt_switch)); + + cd321x_tbt_test_add_router(test, &cd321x_test_router); + flush_work(&cd->tbt_attach_work); + KUNIT_EXPECT_TRUE(test, typec_thunderbolt_switch_is_live(cd->tbt_switch)); + KUNIT_EXPECT_TRUE(test, cd->tbt_notifier_registered); + KUNIT_EXPECT_EQ(test, atomic_read(&cd->restore_event), 1); + + cd321x_tbt_test_release_port(cd); + KUNIT_EXPECT_FALSE(test, cd->tbt_notifier_registered); +} + static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_no_router_test), KUNIT_CASE(cd321x_tbt_router_bound_test), @@ -376,6 +415,7 @@ static struct kunit_case cd321x_tbt_cases[] = { KUNIT_CASE(cd321x_tbt_router_bound_before_watch_test), KUNIT_CASE(cd321x_tbt_other_router_binds_test), KUNIT_CASE(cd321x_tbt_router_binds_after_removal_test), + KUNIT_CASE(cd321x_tbt_router_rebinds_test), {} }; diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 74c820dd0be24..6d249a0919ac5 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -2235,20 +2235,25 @@ cd321x_tbt_switch_get(struct device *dev, struct fwnode_handle *fwnode, EXPORT_SYMBOL_IF_KUNIT(cd321x_tbt_switch_get); /* - * Take a router that bound after the port gave up on it. An attached cable - * raises no new event, so reapply it through the router as after system sleep. + * Take a router that bound after the port gave up on it, or that unbound and + * bound again. An attached cable raises no new event, so reapply it through + * the router as after system sleep. */ static void cd321x_tbt_attach_work(struct work_struct *work) { struct cd321x *cd321x = container_of(work, struct cd321x, tbt_attach_work); struct tps6598x *tps = &cd321x->tps; - struct typec_thunderbolt_switch *sw; + struct typec_thunderbolt_switch *sw, *old; int ret; scoped_guard(mutex, &tps->lock) { - if (cd321x->tbt_switch || cd321x->pm.phase == CD321X_PM_REMOVED) + if (cd321x->pm.phase == CD321X_PM_REMOVED) + return; + /* The router this port uses is still bound. */ + if (typec_thunderbolt_switch_is_live(cd321x->tbt_switch)) return; + old = cd321x->tbt_switch; } /* Another port's router, or this one is not usable yet: keep watching. */ @@ -2256,6 +2261,13 @@ static void cd321x_tbt_attach_work(struct work_struct *work) if (IS_ERR_OR_NULL(sw)) return; + /* The router went away: its switch sends nothing more, stop listening. */ + if (old && cd321x->tbt_notifier_registered) { + typec_thunderbolt_switch_unregister_notifier(old, + &cd321x->tbt_notifier); + cd321x->tbt_notifier_registered = false; + } + ret = typec_thunderbolt_switch_register_notifier(sw, &cd321x->tbt_notifier); if (ret) { @@ -2269,7 +2281,9 @@ static void cd321x_tbt_attach_work(struct work_struct *work) cd321x->tbt_switch = sw; cd321x->tbt_notifier_registered = true; } - dev_info(tps->dev, "USB4/Thunderbolt router bound, reapplying the cable state\n"); + typec_thunderbolt_switch_put(old); + dev_info(tps->dev, "USB4/Thunderbolt router bound%s, reapplying the cable state\n", + old ? " again" : ""); atomic_set(&cd321x->restore_event, 1); mod_delayed_work(system_freezable_wq, &cd321x->resume_work, 0); } @@ -2396,8 +2410,13 @@ cd321x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) goto err_put_switch; cd321x->tbt_notifier_registered = true; - /* Keep the port without the router rather than fail it: see above. */ - if (tbt_late && cd321x_tbt_watch_late(cd321x, fwnode)) + /* + * Keep the port without the router rather than fail it: see above. A + * router that is there can also unbind and bind again, which gives it + * a new switch: watch for that as well. + */ + if ((tbt_late || cd321x->tbt_switch) && + cd321x_tbt_watch_late(cd321x, fwnode)) dev_warn(tps->dev, "cannot watch for the USB4/Thunderbolt router\n"); return 0; diff --git a/include/linux/usb/typec_mux.h b/include/linux/usb/typec_mux.h index ea0d697629611..9d1df67201239 100644 --- a/include/linux/usb/typec_mux.h +++ b/include/linux/usb/typec_mux.h @@ -253,6 +253,7 @@ struct typec_thunderbolt_switch_desc { struct typec_thunderbolt_switch * fwnode_typec_thunderbolt_switch_get(struct fwnode_handle *fwnode); void typec_thunderbolt_switch_put(struct typec_thunderbolt_switch *sw); +bool typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw); int typec_thunderbolt_switch_set(struct typec_thunderbolt_switch *sw, const struct typec_thunderbolt_switch_data *data); int typec_thunderbolt_switch_register_notifier(struct typec_thunderbolt_switch *sw, @@ -302,6 +303,12 @@ typec_thunderbolt_switch_register(struct device *parent, return ERR_PTR(-EOPNOTSUPP); } +static inline bool +typec_thunderbolt_switch_is_live(struct typec_thunderbolt_switch *sw) +{ + return false; +} + static inline int typec_thunderbolt_switch_register_notifier(struct typec_thunderbolt_switch *sw, struct notifier_block *nb) From 44230fbda0585b47bc74dbc0dbd0bcea7585fe0e Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 09:26:22 -0500 Subject: [PATCH 267/342] soc: apple: display-gate: adopt the M4 Max internal display handoff aura hands the M4 Max's internal display over the way it hands over the M4 Pro's: the DCP, the display subsystem and the DCP's piodma carry apple,t6041-handoff, the DCP names the 26.6.2 firmware, and the streams sit on the same DARTs. The M4 Max gate only enabled the external chains, so a handoff there was ignored and the panel stayed on simpledrm. Run the M4 Pro's internal display check on the M4 Max first. With the handoff and a running DCP it enables the DARTs, the mailbox, the display subsystem, the DCP and the panel; without it nothing changes. The external chains still need an enabled display subsystem, now the one this handoff enables, and still only add their DARTs to it. Link: https://github.com/aurora-silicon/linux/issues/1332 Signed-off-by: Diljit Singh --- drivers/soc/apple/display-gate-test.c | 5 ++-- drivers/soc/apple/display-gate.c | 39 +++++++++++++++++--------- drivers/soc/apple/t6041-gate-test.dtso | 5 ++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index c767a064e9280..a732f844683b8 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -20,8 +20,9 @@ * leaves the internal panel alone. * - T6041 on the J616c (t6041-gate-test.dtso): no PMP; each external chain * is enabled once its processor has firmware memory, one without it or - * already enabled stays as it is, and the display subsystem is never - * written. + * already enabled stays as it is, and the chains never write the display + * subsystem's status. The tree has no dcp alias, so the internal display + * handoff finds nothing to adopt. * Included at the end of display-gate.c. * * The test trees are applied once and stay: the gate gives some properties diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index bdb4b6dac2031..73c56cc29ca21 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -78,11 +78,12 @@ * driver of its own, t6041-display-gate.c, by Ryan Murray and František * Balázsy. * - * On the M4 Max (J616c, apple,t6041) the PMP never runs: iBoot leaves the - * external chains powered and the boot loader fills each external display - * processor's firmware memory. The gate enables a chain once its processor has - * that memory, before any device exists (see gate_t6041_max_run()), and never - * touches the internal display. + * On the M4 Max (J614c and J616c, apple,t6041) the internal display is + * handed over and enabled as on the M4 Pro. The PMP never runs there: iBoot + * leaves the external chains powered and the boot loader fills each external + * display processor's firmware memory. The gate enables a chain once its + * processor has that memory and the display subsystem is enabled, before any + * device exists (see gate_t6041_max_run()). */ #define pr_fmt(fmt) fmt @@ -336,11 +337,17 @@ static const struct gate_soc gate_t6041 __initconst = { static void __init gate_t6041_max_run(void); -/* T6041 (M4 Max): no PMP; the external chains follow the boot loader's firmware memory. */ +/* + * T6041 (M4 Max): the M4 Pro's internal display handoff; no PMP, so the + * external chains follow the boot loader's firmware memory. + */ static const struct gate_soc gate_t6041_max __initconst = { .machine = "apple,t6041", .prefix = "apple-t6041-display: ", .name = "T6041", + .dcp_compat = "apple,t6041-dcp", + .display_compat = "apple,display-subsystem", + .marker = "apple,t6041-handoff", .run = gate_t6041_max_run, }; @@ -3030,12 +3037,13 @@ static int __init t6041_max_apply(unsigned int i, struct device_node *display) } /* - * Each chain is enabled in one changeset, once its processor has firmware - * memory. A chain that has none, or is not all there and disabled (a boot - * loader that enabled it itself), stays as it is, and the other chain does not - * depend on it. The display subsystem only gains the DART of an enabled chain: - * its status is never written, so the internal display stays as the boot - * loader left it whatever happens here. + * The internal display first, as on the M4 Pro: an accepted handoff enables + * the display subsystem with the DCP. Then each external chain is enabled in + * one changeset, once its processor has firmware memory. A chain that has + * none, or is not all there and disabled (a boot loader that enabled it + * itself), stays as it is, and the other chain does not depend on it. The + * chains need the display subsystem enabled, by the handoff or by the boot + * loader, and only add their DARTs to it: its status is not written here. */ static void __init gate_t6041_max_run(void) { @@ -3046,10 +3054,15 @@ static void __init gate_t6041_max_run(void) if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) return; + gate_t6041_internal(); staged_prefix = gate_soc->prefix; display = of_find_node_by_path("/display-subsystem"); - if (!display || !of_device_is_available(display)) { + if (!display) { staged_err("no display subsystem, nothing enabled\n"); + return; + } + if (!of_device_is_available(display)) { + staged_info("display subsystem not enabled, external displays left off\n"); of_node_put(display); return; } diff --git a/drivers/soc/apple/t6041-gate-test.dtso b/drivers/soc/apple/t6041-gate-test.dtso index 96c0eaa541ced..d12929a73c0c9 100644 --- a/drivers/soc/apple/t6041-gate-test.dtso +++ b/drivers/soc/apple/t6041-gate-test.dtso @@ -7,8 +7,9 @@ * heap regions of both processors are the boot loader's disabled * placeholders, the text region the one it adds. * - * The display subsystem is the only node that is enabled. It sits at the - * root, as on the J616c, so a tree that has one does not get this applied. + * The display subsystem is the only node that is enabled, as the internal + * display handoff leaves it. It sits at the root, as on the J616c, so a tree + * that has one does not get this applied. */ /dts-v1/; From ffcc24f462200bccd83b0b3ff046ffc6a00c4caa Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 09:26:24 -0500 Subject: [PATCH 268/342] arm64: dts: apple: t6041-j614c-j616c: leave the internal display to the handoff The J614c/J616c tree enabled /display-subsystem itself. aura refuses to hand over a display whose nodes are already enabled ("display is not status "disabled"", linux#1332), so the panel stayed on simpledrm. Keep the display subsystem disabled, and the panel with it, as the J616s tree does. The display gate enables them with the DCP once the boot loader has handed the display over. Without a handoff the display subsystem now stays disabled, and the external chains, which need it, stay off too. aura publishes the external processors' firmware memory only together with the panel handoff, so nothing that worked with aura before is lost. A loader that fills that memory without handing the panel over loses the external displays until it hands the panel over as well. Link: https://github.com/aurora-silicon/linux/issues/1332 Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi b/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi index de5eed04aed63..98337a09a596f 100644 --- a/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi +++ b/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi @@ -448,9 +448,13 @@ status = "okay"; }; +/* + * As on the J616s, the display gate enables the display subsystem, the DCP, + * its DARTs, mailbox and panel once the boot loader has handed the internal + * display over (apple,t6041-handoff); otherwise the boot framebuffer stays. + */ &display { phandle = <&display>; - status = "okay"; }; &dcp { @@ -459,6 +463,7 @@ panel: panel { apple,max-brightness = <500>; + status = "disabled"; }; }; From 579bcc38d686758d9f18470bd404a27f82786df1 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 09:45:40 -0500 Subject: [PATCH 269/342] drm/asahi: run the 25G83 build on the 40-core M4 Max The macOS 26.6.2 boot firmware (iBoot mBoot-18000.161.10) loads the 25G83 GPU firmware on the M4 Max as well. integration/aurora admits only 25F84 there, so a 40-core J614c booting through a 26.6.2 stub has no GPU (linux#1332). A firmware build can now carry the SoC configuration it runs with. Once the build is identified, that configuration replaces the probed one. This is the mechanism linux#1050 proposes, so its 32-core profile can build on it. T6041 gains a 25G83 build. Its configuration is the 40-core 25F84 profile with two changes: - the 25G83 variant, with the four-cluster tiler values (TA mode 1) that 25F84 uses on this machine and #1050 uses for 25G83; - the 25G83 register map. It has the same 25 windows (slot 3 holds the 40-core part's eight memory controllers), laid out the way 25G83 lays them out on the M4 Pro: from +0x200000, each window followed by a 16K guard page, with no reserved slots. This rule reproduces both known 25G83 maps, the M4 Pro's (four controllers) and #1050's 32-core M4 Max map (six). A compile-time check holds the M4 Pro's map and the new one to the rule, and the new one to 25F84's windows. The rest comes from the 25F84 profile: 40 cores in four clusters, the operand-state and deflake layouts, the 160-block compute pool, the hardware data and power words, and region C. The core count check stays, so a 32-core part is refused with this configuration. The build admits one loaded image: the only T6041 25G83 image measured so far (sha256 aa113ed6...effc5, measured on #1050's 32-core J616C). iBoot fills part of the loaded TEXT for each Mac (three J616s loaded three different T6040 images), so a 40-core Mac most likely loads a different one. If so, its "unsupported GPU firmware build" line gives the sha256 to add. KUnit tests cover the identities of both T6041 builds, the 25G83 configuration, and the render policy of both builds. The host model of the build selector now returns the build's configuration, and the T6041 initdata host test also builds the 25G83 objects. Not run on hardware. Link: https://github.com/aurora-silicon/linux/issues/1332 Link: https://github.com/aurora-silicon/linux/pull/1050 Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/fwid.rs | 32 ++++ drivers/gpu/drm/asahi/g17/fw/render.rs | 38 ++++- drivers/gpu/drm/asahi/g17/fw/variant.rs | 3 + drivers/gpu/drm/asahi/g17/mod.rs | 15 +- drivers/gpu/drm/asahi/hw/t6040.rs | 1 + drivers/gpu/drm/asahi/hw/t6041.rs | 158 +++++++++++++++++--- drivers/gpu/drm/asahi/hw/t604x.rs | 18 +++ tools/asahi/g17-firmware-selection-tests.py | 24 ++- tools/asahi/g17-t6041-initdata-tests.py | 18 ++- 9 files changed, 264 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index 34c65a0d8a097..514f09539dc73 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -247,6 +247,38 @@ mod tests { assert!(measured(build.images, 0x138000, [0x59839, 0x5991c], [0; 32]).is_none()); } + #[test] + fn t6041_builds_admit_only_their_own_images() { + let crate::g17::fw::variant::Firmware::Identified(builds) = + crate::hw::t6041::CONFIG.firmware + else { + panic!("T6041 must identify its loaded firmware"); + }; + assert_eq!(builds.len(), 2); + for (i, build) in builds.iter().enumerate() { + let other = &builds[1 - i]; + for image in build.images { + let (entropy, digest) = (image.entropy, image.text_sha256); + let found = measured(build.images, image.data_size, entropy, digest); + assert!(core::ptr::eq(found.unwrap(), image)); + assert!(measured(other.images, image.data_size, entropy, digest).is_none()); + assert!(measured(build.images, 0x13c000, entropy, digest).is_none()); + } + } + // Only the 25G83 build runs its own configuration: the 25G83 register map, 40 cores. + assert!(builds[0].config.is_none()); + let g83 = builds[1].config.unwrap(); + let map = &crate::hw::t6041::REGISTER_WINDOWS_25G83; + assert_eq!(g83.windows.len(), map.len()); + for (window, expected) in g83.windows.iter().zip(map.iter()) { + assert_eq!((window.slot, window.va), (expected.slot, expected.va)); + } + assert!(g83.reserved_slots.is_empty()); + let cores = crate::hw::t6041::CONFIG.core_layout.cores; + assert_eq!(g83.core_layout.cores, cores); + assert_eq!(cores, Some((4, 40))); + } + #[cfg(CONFIG_DRM_ASAHI_G16)] #[test] fn j713_accepts_both_loaded_images() { diff --git a/drivers/gpu/drm/asahi/g17/fw/render.rs b/drivers/gpu/drm/asahi/g17/fw/render.rs index 8fcc25500ab2d..f63821c904fd2 100644 --- a/drivers/gpu/drm/asahi/g17/fw/render.rs +++ b/drivers/gpu/drm/asahi/g17/fw/render.rs @@ -1629,14 +1629,38 @@ mod ta_mode_tests { } } + /// The variants of the builds T6041 admits: 25F84, then 25G83. + fn t6041_variants() -> [&'static Variant; 2] { + let Firmware::Identified(builds) = crate::hw::t6041::CONFIG.firmware else { + panic!("T6041 must identify its loaded firmware"); + }; + assert_eq!(builds.len(), 2); + [builds[0].variant, builds[1].variant] + } + + /// The TA mode of every admitted T6041 build. + fn t6041_ta_mode_1() -> bool { + let [f84, g83] = t6041_variants(); + assert_eq!(f84.ta_mode_1, g83.ta_mode_1); + f84.ta_mode_1 + } + #[test] - fn policy_is_local_to_the_admitted_t6041_build() { - let max = selected(&crate::hw::t6041::CONFIG.firmware); + fn policy_is_local_to_the_admitted_t6041_builds() { + let [f84, g83] = t6041_variants(); let pro = selected(&crate::hw::t6040::CONFIG.firmware); - assert_eq!(max.compute, crate::g17::fw::compute::ComputeProgram::V25F84); - assert!(max.split_firmware_area); - assert_eq!(max.programs, RegisterPrograms::V25G83); - assert!(max.ta_mode_1); + assert_eq!(f84.compute, crate::g17::fw::compute::ComputeProgram::V25F84); + assert!(f84.split_firmware_area); + // 25G83 keeps the M4 Pro's queue and compute rules on the M4 Max. + assert_eq!(g83.compute, pro.compute); + assert_eq!(g83.split_firmware_area, pro.split_firmware_area); + assert_eq!(g83.opening_record, pro.opening_record); + assert_eq!(g83.qid_floor, pro.qid_floor); + assert_eq!(g83.registration, pro.registration); + for max in [f84, g83] { + assert_eq!(max.programs, RegisterPrograms::V25G83); + assert!(max.ta_mode_1); + } assert!(!pro.ta_mode_1); assert!(!V25F84.ta_mode_1); assert!(!V25G83.ta_mode_1); @@ -1704,7 +1728,7 @@ mod ta_mode_tests { for scs in [false, true] { let mut args = args(&pass, &resources, scs); let (before, count) = ta_registers_25g83(&args, &geometry, &words).unwrap(); - args.ta_mode_1 = selected(&crate::hw::t6041::CONFIG.firmware).ta_mode_1; + args.ta_mode_1 = t6041_ta_mode_1(); let (after, new_count) = ta_registers_25g83(&args, &geometry, &words).unwrap(); assert_eq!(count, 83 + usize::from(scs)); assert_eq!(new_count, count); diff --git a/drivers/gpu/drm/asahi/g17/fw/variant.rs b/drivers/gpu/drm/asahi/g17/fw/variant.rs index c5287e66a641d..222473a8b8c36 100644 --- a/drivers/gpu/drm/asahi/g17/fw/variant.rs +++ b/drivers/gpu/drm/asahi/g17/fw/variant.rs @@ -89,6 +89,9 @@ pub(crate) struct Build { pub(crate) images: &'static [crate::fwid::FirmwareBuild], /// Layouts and rules of the build. pub(crate) variant: &'static Variant, + /// The SoC configuration this build runs with, which replaces the probed one once the + /// build is identified; `None` keeps the probed configuration. + pub(crate) config: Option<&'static crate::g17::Config>, } /// How a SoC's firmware build is determined. diff --git a/drivers/gpu/drm/asahi/g17/mod.rs b/drivers/gpu/drm/asahi/g17/mod.rs index ffb0c20d0267f..df5a31f621a3c 100644 --- a/drivers/gpu/drm/asahi/g17/mod.rs +++ b/drivers/gpu/drm/asahi/g17/mod.rs @@ -1173,7 +1173,9 @@ impl Gpu { } else { None }; - let variant = Self::firmware_variant(dev, &cfg.firmware)?; + let (variant, build_cfg) = Self::firmware_variant(dev, &cfg.firmware)?; + // A build with its own configuration of the SoC runs with that one. + let cfg = build_cfg.unwrap_or(cfg); let id = regs.get_g17_id()?; if let Some(calibration) = calibration { calibration.check_cores(&id.core_masks)?; @@ -1324,14 +1326,15 @@ impl Gpu { Ok(gpu) } - /// Returns the variant of the loaded firmware build. An identified SoC refuses a build it - /// does not know, before anything is written to the GPU. + /// Returns the variant of the loaded firmware build and the configuration it runs with, if + /// it has its own. An identified SoC refuses a build it does not know, before anything is + /// written to the GPU. fn firmware_variant( dev: &AsahiDrmDevice, firmware: &fw::variant::Firmware, - ) -> Result<&'static fw::Variant> { + ) -> Result<(&'static fw::Variant, Option<&'static Config>)> { let builds = match firmware { - fw::variant::Firmware::Fixed(variant) => return Ok(variant), + fw::variant::Firmware::Fixed(variant) => return Ok((variant, None)), fw::variant::Firmware::Identified(builds) => builds, }; let version = Self::os_firmware_version(dev); @@ -1346,7 +1349,7 @@ impl Gpu { for build in Iterator::chain(preferred, others) { if Self::identify_image(dev, build).is_ok() { dev_info!(dev.as_ref(), "GPU firmware: {}\n", build.name); - return Ok(build.variant); + return Ok((build.variant, build.config)); } } dev_err!( diff --git a/drivers/gpu/drm/asahi/hw/t6040.rs b/drivers/gpu/drm/asahi/hw/t6040.rs index d531e20c7e9f9..5f6b9944a811e 100644 --- a/drivers/gpu/drm/asahi/hw/t6040.rs +++ b/drivers/gpu/drm/asahi/hw/t6040.rs @@ -100,6 +100,7 @@ pub(crate) const CONFIG: Config = Config { }, ], variant: &fw::variant::V25G83, + config: None, }]), // Measured on the 20-core M4 Pro; the alternative below remains experimental. core_layout: CoreLayout { diff --git a/drivers/gpu/drm/asahi/hw/t6041.rs b/drivers/gpu/drm/asahi/hw/t6041.rs index 8be466f7842ab..956aa0cc7728b 100644 --- a/drivers/gpu/drm/asahi/hw/t6041.rs +++ b/drivers/gpu/drm/asahi/hw/t6041.rs @@ -9,7 +9,9 @@ use crate::hw::{GpuGen, GpuVariant}; use super::t604x::{instances, window}; use crate::mmu::UatQuirks; -pub(crate) const CONFIG: Config = Config { +/// What the configurations of both firmware builds share: the 40-core M4 Max measured with +/// 25F84. Only the register map is the build's own. +const BASE: Config = Config { chip_id: CHIP_ID, identity: Identity { family: 0xa, @@ -46,26 +48,7 @@ pub(crate) const CONFIG: Config = Config { fabric_bridge: false, recovery_slot_keys: None, gpu_generation: GpuGen::G16, - firmware: fw::variant::Firmware::Identified(&[fw::variant::Build { - os_version: [26, 5, 2], - name: "macOS 26.5.2 (25F84, iBoot mBoot-18000.121.3)", - images: &[crate::fwid::FirmwareBuild { - name: "Apple GFX 25F84 for T6041 (normalized loaded image)", - text_size: 0x60000, - data_size: 0x138000, - entropy: [0x5983a, 0x5991d], - text_sha256: [ - 0x6d, 0xa4, 0xd4, 0x42, 0x35, 0x35, 0x14, 0x44, 0xf6, 0xec, 0x00, 0x33, 0xf1, 0x9c, - 0xbf, 0x98, 0xd3, 0x43, 0x91, 0x28, 0x83, 0xe4, 0xe2, 0x94, 0xc1, 0x8b, 0xb8, 0xb8, - 0xa3, 0xc1, 0x83, 0xe8, - ], - }], - // macOS writes these tiler segment values on this machine, not the two-cluster ones. - variant: &fw::variant::Variant { - ta_mode_1: true, - ..fw::variant::V25F84 - }, - }]), + firmware: fw::variant::Firmware::Identified(&[]), core_layout: CoreLayout { cores: Some((4, 40)), alternate_core_masks: None, @@ -75,6 +58,76 @@ pub(crate) const CONFIG: Config = Config { }, }; +/// The 40-core M4 Max. 25F84 runs this configuration; 25G83 runs [`CONFIG_25G83`]. +pub(crate) const CONFIG: Config = Config { + firmware: fw::variant::Firmware::Identified(&BUILDS), + ..BASE +}; + +const BUILDS: [fw::variant::Build; 2] = [ + BUILD_25F84, + fw::variant::Build { + config: Some(&CONFIG_25G83), + ..BUILD_25G83 + }, +]; + +const BUILD_25F84: fw::variant::Build = fw::variant::Build { + os_version: [26, 5, 2], + name: "macOS 26.5.2 (25F84, iBoot mBoot-18000.121.3)", + images: &[crate::fwid::FirmwareBuild { + name: "Apple GFX 25F84 for T6041 (normalized loaded image)", + text_size: 0x60000, + data_size: 0x138000, + entropy: [0x5983a, 0x5991d], + text_sha256: [ + 0x6d, 0xa4, 0xd4, 0x42, 0x35, 0x35, 0x14, 0x44, 0xf6, 0xec, 0x00, 0x33, 0xf1, 0x9c, + 0xbf, 0x98, 0xd3, 0x43, 0x91, 0x28, 0x83, 0xe4, 0xe2, 0x94, 0xc1, 0x8b, 0xb8, 0xb8, + 0xa3, 0xc1, 0x83, 0xe8, + ], + }], + // macOS writes these tiler segment values on this machine, not the two-cluster ones. + variant: &fw::variant::Variant { + ta_mode_1: true, + ..fw::variant::V25F84 + }, + config: None, +}; + +/// The macOS 26.6.2 boot firmware (iBoot mBoot-18000.161.10) loads the 25G83 build the M4 Pro +/// runs. iBoot fills part of the loaded TEXT for each Mac, so each admitted image is a +/// measurement. The one listed is the only T6041 image measured so far, on a 32-core J616C +/// (linux#1050); there the core count check of [`CONFIG_25G83`] refuses the GPU. +const BUILD_25G83: fw::variant::Build = fw::variant::Build { + os_version: [26, 6, 2], + name: "macOS 26.6.2 (25G83, iBoot mBoot-18000.161.10)", + images: &[crate::fwid::FirmwareBuild { + name: "Apple GFX 25G83 for T6041 (normalized loaded image, 32-core J616C)", + text_size: 0x60000, + data_size: 0x138000, + entropy: [0x59839, 0x5991c], + text_sha256: [ + 0xaa, 0x11, 0x3e, 0xd6, 0x20, 0x79, 0xbc, 0xfd, 0xee, 0xf0, 0xf8, 0x6c, 0x2a, 0x8d, + 0x7e, 0xae, 0x9f, 0x90, 0x7b, 0x03, 0xbe, 0x28, 0xcc, 0xf2, 0x98, 0xc9, 0x43, 0x95, + 0x1d, 0x0e, 0xff, 0xc5, + ], + }], + // Four clusters: the tiler segment values of 25F84 on this machine. + variant: &fw::variant::Variant { + ta_mode_1: true, + ..fw::variant::V25G83 + }, + config: None, +}; + +/// The 40-core M4 Max on 25G83: the 25F84 configuration with the 25G83 register map. +const CONFIG_25G83: Config = Config { + windows: ®ISTER_WINDOWS_25G83, + reserved_slots: &[], + firmware: fw::variant::Firmware::Identified(&[BUILD_25G83]), + ..BASE +}; + pub(crate) const CHIP_ID: u32 = 0x6041; pub(crate) const REGISTER_WINDOWS: [RegisterWindow; 25] = [ @@ -113,6 +166,69 @@ pub(crate) const REGISTER_WINDOWS: [RegisterWindow; 25] = [ window(43, 0x2_88e6_0000, 0x2f_8000, 0x58, 0xe6_0000, 2), ]; +/// The register map of the 25G83 build: the windows of [`REGISTER_WINDOWS`] (slot 3 holds the +/// eight memory controllers) laid out as 25G83 lays them out on the M4 Pro +/// ([`super::t6040::REGISTER_WINDOWS`]), from `+0x20_0000`, each window followed by a 16K +/// guard page, with no reserved slots. The windows after slot 3 lie 0x60000 further than the M4 +/// Pro's, for its four more controllers. +pub(crate) const REGISTER_WINDOWS_25G83: [RegisterWindow; 25] = [ + window(0, 0x5_0241_4000, 0x20_0000, 0x4000, 0, 2), + instances( + window(3, 0x2_201c_4000, 0x20_8000, 0x1_8000, 0, 2), + 8, + 0x200_0000, + ), + window(4, 0x5_0244_c000, 0x2c_c000, 0x4000, 0, 0), + window(9, 0x5_003d_0000, 0x2d_4000, 0x4000, 0, 2), + window(10, 0x5_003c_0000, 0x2d_c000, 0x4000, 0, 0), + window(11, 0x5_003d_8000, 0x2e_4000, 0x4000, 0, 2), + window(12, 0x4_8565_c000, 0x2e_c000, 0x4000, 0, 2), + window(14, 0x5_0040_0000, 0x2f_4000, 0x1_0000, 0, 0), + window(15, 0x5_0cdc_0000, 0x30_8000, 0x4000, 0, 0), + window(17, 0x2_8800_0000, 0x31_0000, 0x2_1400, 0, 2), + instances( + window(20, 0x2_8b00_0000, 0x33_8000, 0x4_0000, 0, 2), + 4, + 0x20_0000, + ), + window(22, 0x2_8900_0000, 0x43_c000, 0x8000, 0, 2), + window(26, 0x2_88d0_4000, 0x44_8000, 0x8000, 0xd0_4000, 2), + window(28, 0x2_88d5_8000, 0x45_4000, 0x8000, 0xd5_8000, 2), + window(29, 0x2_88d1_0000, 0x46_0000, 0x4000, 0xd1_0000, 2), + window(31, 0x2_88d4_0000, 0x46_8000, 0x4000, 0xd4_0000, 2), + window(32, 0x2_88d6_0000, 0x47_0000, 0x2_0000, 0xd6_0000, 2), + window(33, 0x2_88d4_4000, 0x49_4000, 0x4000, 0xd4_4000, 2), + window(34, 0x2_88d4_c000, 0x49_c000, 0x200, 0xd4_c000, 2), + window(35, 0x2_88e0_0000, 0x4a_4000, 0x4000, 0xe0_0000, 2), + window(37, 0x2_88e4_0000, 0x4a_c000, 0x4000, 0xe4_0000, 2), + window(39, 0x2_88e0_8000, 0x4b_4000, 0x8000, 0, 2), + window(40, 0x2_88e1_c000, 0x4c_0000, 0x4000, 0xe1_c000, 2), + window(41, 0x2_88e1_f800, 0x4c_b800, 0x4000, 0, 2), + window(43, 0x2_88e6_0000, 0x4d_4000, 0x58, 0xe6_0000, 2), +]; + +// The 25G83 map holds the 25F84 windows, laid out as 25G83 lays out the M4 Pro's. +const _: () = { + assert!(super::t604x::laid_out_25g83( + &super::t6040::REGISTER_WINDOWS + )); + assert!(super::t604x::laid_out_25g83(®ISTER_WINDOWS_25G83)); + let mut index = 0; + while index < REGISTER_WINDOWS.len() { + let (f84, g83) = (®ISTER_WINDOWS[index], ®ISTER_WINDOWS_25G83[index]); + assert!( + f84.slot == g83.slot + && f84.phys == g83.phys + && f84.size == g83.size + && f84.unk_18 == g83.unk_18 + && f84.unk_20 == g83.unk_20 + && f84.instances == g83.instances + && f84.phys_stride == g83.phys_stride + ); + index += 1; + } +}; + const RESERVED_SLOTS: [usize; 14] = [2, 5, 6, 7, 8, 27, 30, 38, 42, 46, 47, 48, 49, 52]; pub(crate) const PERF: PerfConfig = PerfConfig { diff --git a/drivers/gpu/drm/asahi/hw/t604x.rs b/drivers/gpu/drm/asahi/hw/t604x.rs index 961cef76cf4aa..6021419eeb1dd 100644 --- a/drivers/gpu/drm/asahi/hw/t604x.rs +++ b/drivers/gpu/drm/asahi/hw/t604x.rs @@ -31,3 +31,21 @@ pub(super) const fn instances(window: RegisterWindow, instances: u32, phys_strid ..window } } + +/// Whether `windows` are laid out as the 25G83 build lays out its register map: in order from +/// `+0x20_0000`, the pages of each window's instances followed by a 16K guard page. +pub(super) const fn laid_out_25g83(windows: &[RegisterWindow]) -> bool { + let mut next = MMIO_APERTURE + 0x20_0000; + let mut index = 0; + while index < windows.len() { + let window = &windows[index]; + let page_offset = window.phys & 0x3fff; + if window.va != next + page_offset { + return false; + } + let pages = (page_offset + window.size as u64 + 0x3fff) & !0x3fff; + next += pages * window.instances as u64 + 0x4000; + index += 1; + } + true +} diff --git a/tools/asahi/g17-firmware-selection-tests.py b/tools/asahi/g17-firmware-selection-tests.py index 771c9c19c6e1e..2a3cae91fdb08 100644 --- a/tools/asahi/g17-firmware-selection-tests.py +++ b/tools/asahi/g17-firmware-selection-tests.py @@ -34,6 +34,7 @@ def method(source, signature): image: u32, checked: std::cell::RefCell>, } +struct Config(u32); mod fw { pub struct Variant(pub u32); pub mod variant { @@ -43,6 +44,7 @@ def method(source, signature): pub name: &'static str, pub image: u32, pub variant: &'static Variant, + pub config: Option<&'static crate::Config>, } pub enum Firmware { Fixed(&'static Variant), Identified(&'static [Build]) } } @@ -60,9 +62,11 @@ def method(source, signature): } static FIRST: fw::Variant = fw::Variant(1); static SECOND: fw::Variant = fw::Variant(2); +static OWN: Config = Config(7); static BUILDS: [fw::variant::Build; 2] = [ - fw::variant::Build { os_version: [26,6,2], name: "first", image: 1, variant: &FIRST }, - fw::variant::Build { os_version: [27,0,0], name: "second", image: 2, variant: &SECOND }, + fw::variant::Build { os_version: [26,6,2], name: "first", image: 1, variant: &FIRST, config: None }, + fw::variant::Build { os_version: [27,0,0], name: "second", image: 2, variant: &SECOND, + config: Some(&OWN) }, ]; fn device(version: Option<[u32; 3]>, image: u32) -> AsahiDrmDevice { AsahiDrmDevice { version, image, checked: std::cell::RefCell::new(Vec::new()) } @@ -71,18 +75,26 @@ def method(source, signature): use fw::variant::Firmware; for version in [None, Some([26,6,2]), Some([26,7,0]), Some([99,0,0])] { let dev = device(version, 1); - assert_eq!(Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).unwrap().0, 1); + let (variant, config) = Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).unwrap(); + assert_eq!(variant.0, 1); + assert!(config.is_none(), "a build without its own configuration keeps the probed one"); } let dev = device(Some([27,0,0]), 1); - assert_eq!(Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).unwrap().0, 1); + assert_eq!(Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).unwrap().0.0, 1); assert_eq!(*dev.checked.borrow(), [2,1], "the OS version only orders the candidates"); + let dev = device(None, 2); + let (variant, config) = Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).unwrap(); + assert_eq!((variant.0, config.map(|c| c.0)), (2, Some(7)), "the identified build's configuration"); let dev = device(Some([26,6,2]), 9); assert!(Gpu::firmware_variant(&dev, &Firmware::Identified(&BUILDS)).is_err()); assert_eq!(*dev.checked.borrow(), [1,2]); let dev = device(None, 9); - assert_eq!(Gpu::firmware_variant(&dev, &Firmware::Fixed(&SECOND)).unwrap().0, 2); + let (variant, config) = Gpu::firmware_variant(&dev, &Firmware::Fixed(&SECOND)).unwrap(); + assert_eq!(variant.0, 2); + assert!(config.is_none()); assert!(dev.checked.borrow().is_empty(), "fixed Neo admission is unchanged"); - println!("PASS G17 selection: exact image required, OS hint optional, fixed Neo unchanged"); + println!("PASS G17 selection: exact image required, OS hint optional, build configuration \ + follows the image, fixed Neo unchanged"); } ''' diff --git a/tools/asahi/g17-t6041-initdata-tests.py b/tools/asahi/g17-t6041-initdata-tests.py index 05ddc6b145d9d..a48174df48547 100644 --- a/tools/asahi/g17-t6041-initdata-tests.py +++ b/tools/asahi/g17-t6041-initdata-tests.py @@ -102,6 +102,7 @@ def item(source, start): ] T6041_ITEMS = SOC_ITEMS + [ + "pub(crate) const REGISTER_WINDOWS_25G83", "const RESERVED_SLOTS", "const MAX_POWER_MW", "const CHIP: ", @@ -190,9 +191,20 @@ def aux(name, rows): &t6041::RESERVED_SLOTS, &t6041::PERF, &T6041_OPPS, &T6041_AUX, &t6041::CHIP, &t6041::REGION_C, 40); println!("T6041 initialization objects built"); - std::fs::write(format!("{}/t6041-hwdata.bin", out), hw).unwrap(); - std::fs::write(format!("{}/t6041-power-config.bin", out), power).unwrap(); - std::fs::write(format!("{}/t6041-region-c.bin", out), region).unwrap(); + std::fs::write(format!("{}/t6041-hwdata.bin", out), &hw).unwrap(); + std::fs::write(format!("{}/t6041-power-config.bin", out), &power).unwrap(); + std::fs::write(format!("{}/t6041-region-c.bin", out), ®ion).unwrap(); + // 25G83: the same configuration with its own register map. + let (hw_g83, power_g83, region_g83) = build(t6041::CHIP_ID, &t6041::REGISTER_WINDOWS_25G83, + &[], &t6041::PERF, &T6041_OPPS, &T6041_AUX, &t6041::CHIP, &t6041::REGION_C, 40); + println!("T6041 25G83 initialization objects built"); + assert_eq!(power_g83, power, "the register map changes only the hardware data"); + assert_eq!(region_g83, region, "the register map changes only the hardware data"); + let map = 0x640..0x640 + REGISTER_MAP_SLOTS * core::mem::size_of::(); + let outside = |a: &[u8], b: &[u8]| a.iter().zip(b).enumerate() + .filter(|(i, (x, y))| x != y && !map.contains(i)).count(); + assert_eq!(outside(&hw_g83, &hw), 0, "the 25G83 hardware data differs only in its register map"); + std::fs::write(format!("{}/t6041-25g83-hwdata.bin", out), &hw_g83).unwrap(); } """ From 904c734881080a529a6a791bd678e57102d95213 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 09:47:13 -0500 Subject: [PATCH 270/342] tools/asahi: Model the late crashlog work in the OSLog test apple_rtkit_reinit() now cancels the late crashlog read (cancel_delayed_work_sync(&rtk->crashlog_late_work)). The OSLog test extracts that function, so give its mock struct apple_rtkit the field and add a no-op cancel_delayed_work_sync(). Older sources don't use either, so the --ref runs still build. Signed-off-by: Diljit Singh --- tools/asahi/rtkit-oslog-tests.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/asahi/rtkit-oslog-tests.py b/tools/asahi/rtkit-oslog-tests.py index 160c163758d54..df50c90350b81 100644 --- a/tools/asahi/rtkit-oslog-tests.py +++ b/tools/asahi/rtkit-oslog-tests.py @@ -41,6 +41,7 @@ def function(source, name): #define spin_unlock_irqrestore(l,f) ((void)(l), (void)(f)) struct apple_rtkit_shmem { size_t size; }; struct mailbox { int rx_lock; void (*rx)(void); }; +struct delayed_work { int pending; }; struct apple_rtkit { void *dev, *wq; struct mailbox *mbox; @@ -53,6 +54,7 @@ def function(source, name): char *syslog_msg_buffer; size_t syslog_n_entries, syslog_msg_size; int epmap_completion, iop_pwr_ack_completion, ap_pwr_ack_completion, coreanalytics_completion; + struct delayed_work crashlog_late_work; }; static unsigned sent, warnings, errors, requests, detachments, flushes, freed, checks; static int send_error, setup_error, start_error; @@ -70,6 +72,7 @@ def function(source, name): static void apple_rtkit_rx(void) {} static void apple_rtkit_detach_rx(struct apple_rtkit *r) { ++detachments; r->shutting_down=true; } static void flush_workqueue(void *w) { (void)w; ++flushes; } +#define cancel_delayed_work_sync(w) ((void)(w), false) static void apple_rtkit_free_buffer(struct apple_rtkit *r, struct apple_rtkit_shmem *b) { (void)r; ++freed; b->size=0; } #define kfree(p) ((void)(p)) From b16f72bce3d9a51bff7176d908835b0faa48c86a Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:23:17 -0800 Subject: [PATCH 271/342] dt-bindings: iommu: apple,sart: Add the T6050 SART The T6050 (M5 Ultra) SART keeps SARTv3's entries but moves the address and size arrays, so it is not compatible with apple,t6000-sart and has no fallback. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/iommu/apple,sart.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index 493e48de06a92..19ffe1bf167f7 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -26,6 +26,9 @@ description: SART3, first seen in M1 Pro/Max, extends both the address space and filter entry size to 42 bit. + SART4, seen on M5 Ultra (T6050), keeps SART3's entries but moves the + address and size arrays, so it has no SART3 fallback. + properties: compatible: oneOf: From f44022cdf8ae8602912e3d8345d38edf6a0ae4a9 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:21:36 -0800 Subject: [PATCH 272/342] soc: apple: sart: Add SARTv4 for T6050 The SART that filters the T6050 (M5 Ultra) ANS's DMA keeps SARTv3's entry format (config, page address and size, 4 KiB units) but moves the address and size arrays from 0x40/0x80 to 0x60/0xc0. Read on J775D before Linux started: the config words at 0x00+4i and seven live entries whose addresses at 0x60+4i and sizes at 0xc0+4i name ANS's MMIO and two DRAM ranges. Let the v3 ops carry the array offsets, so v3 and v4 share one implementation, and match apple,t6050-sart with the v4 offsets. There is no v3 fallback compatible: a v3 driver would read the wrong registers. Log the number of entries the boot loader left (protected) at debug level. v2 and v3 SARTs keep their offsets. Testing: on J775D, every boot since protects the seven entries the boot loader left, and ANS's NVMe runs behind it (Linux boots from and writes to its NVMe partition). Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/soc/apple/sart.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index 6cedcb867c61b..8270a5a731f2c 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -54,15 +55,19 @@ /* SARTv3 registers */ #define APPLE_SART3_CONFIG(idx) (0x00 + 4 * (idx)) -#define APPLE_SART3_PADDR(idx) (0x40 + 4 * (idx)) +#define APPLE_SART3_PADDR 0x40 #define APPLE_SART3_PADDR_SHIFT 12 -#define APPLE_SART3_SIZE(idx) (0x80 + 4 * (idx)) +#define APPLE_SART3_SIZE 0x80 #define APPLE_SART3_SIZE_SHIFT 12 #define APPLE_SART3_SIZE_MAX GENMASK(29, 0) #define APPLE_SART3_FLAGS_ALLOW 0xff +/* SARTv4 (M5): SARTv3's entries, with the address and size arrays moved up */ +#define APPLE_SART4_PADDR 0x60 +#define APPLE_SART4_SIZE 0xc0 + struct apple_sart_ops { void (*get_entry)(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size); @@ -70,6 +75,9 @@ struct apple_sart_ops { phys_addr_t paddr_shifted, size_t size_shifted); /* This is probably a bitfield but the exact meaning of each bit is unknown. */ unsigned int flags_allow; + /* SARTv3/v4: where the address and size arrays start */ + unsigned int paddr_reg; + unsigned int size_reg; unsigned int size_shift; unsigned int paddr_shift; size_t size_max; @@ -179,8 +187,8 @@ static struct apple_sart_ops sart_ops_v2 = { static void sart3_get_entry(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size) { - phys_addr_t paddr_ = readl(sart->regs + APPLE_SART3_PADDR(index)); - size_t size_ = readl(sart->regs + APPLE_SART3_SIZE(index)); + phys_addr_t paddr_ = readl(sart->regs + sart->ops->paddr_reg + 4 * index); + size_t size_ = readl(sart->regs + sart->ops->size_reg + 4 * index); *flags = readl(sart->regs + APPLE_SART3_CONFIG(index)); *size = size_ << APPLE_SART3_SIZE_SHIFT; @@ -190,8 +198,8 @@ static void sart3_get_entry(struct apple_sart *sart, int index, u8 *flags, static void sart3_set_entry(struct apple_sart *sart, int index, u8 flags, phys_addr_t paddr_shifted, size_t size_shifted) { - writel(paddr_shifted, sart->regs + APPLE_SART3_PADDR(index)); - writel(size_shifted, sart->regs + APPLE_SART3_SIZE(index)); + writel(paddr_shifted, sart->regs + sart->ops->paddr_reg + 4 * index); + writel(size_shifted, sart->regs + sart->ops->size_reg + 4 * index); writel(flags, sart->regs + APPLE_SART3_CONFIG(index)); } @@ -199,6 +207,19 @@ static struct apple_sart_ops sart_ops_v3 = { .get_entry = sart3_get_entry, .set_entry = sart3_set_entry, .flags_allow = APPLE_SART3_FLAGS_ALLOW, + .paddr_reg = APPLE_SART3_PADDR, + .size_reg = APPLE_SART3_SIZE, + .size_shift = APPLE_SART3_SIZE_SHIFT, + .paddr_shift = APPLE_SART3_PADDR_SHIFT, + .size_max = APPLE_SART3_SIZE_MAX, +}; + +static struct apple_sart_ops sart_ops_v4 = { + .get_entry = sart3_get_entry, + .set_entry = sart3_set_entry, + .flags_allow = APPLE_SART3_FLAGS_ALLOW, + .paddr_reg = APPLE_SART4_PADDR, + .size_reg = APPLE_SART4_SIZE, .size_shift = APPLE_SART3_SIZE_SHIFT, .paddr_shift = APPLE_SART3_PADDR_SHIFT, .size_max = APPLE_SART3_SIZE_MAX, @@ -236,6 +257,7 @@ static int apple_sart_probe(struct platform_device *pdev) i, flags, &paddr, size); set_bit(i, &sart->protected_entries); } + dev_dbg(dev, "%lu bootloader entries protected\n", hweight_long(sart->protected_entries)); platform_set_drvdata(pdev, sart); return 0; @@ -409,6 +431,10 @@ static void apple_sart_shutdown(struct platform_device *pdev) } static const struct of_device_id apple_sart_of_match[] = { + { + .compatible = "apple,t6050-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t6000-sart", .data = &sart_ops_v3, From 1bcd370f7577791426029de73555c243e170f920 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:23:05 -0800 Subject: [PATCH 273/342] nvme: apple: Add the T6050 ANS on bare metal Add apple,t6050-nvme-ans2 for the M5 Ultra's ANS when Linux runs on the hardware. Its layout is T6040's, as the ADT and the registers read before Linux started show: a 64 KiB "nvme" block, a separate NVMMU and linear submission queues. The controller reports 254 queue entries (CAP.MQES 0xfd); the profile uses T6040's 64. FUA writes are not shown durable here, so the profile flushes instead (NVME_QUIRK_BROKEN_FUA). The boot loader leaves ANS's firmware running and the controller shut down (CC.EN 0, CSTS.RDY 0). The driver adopts that session, and, like every post-M4 ANS without cold_reset, never resets it through PMGR, so the profile sets reset_optional, a hardware-profile flag that takes the controller reset as optional, and the binding requires no reset for it. Every other profile still requires its reset. Testing: on J775D, every boot since 2026-10-30 adopts ANS's running firmware and enables the controller with this profile; Linux runs from its NVMe root partition (ext4) through daily builds and reboots without an NVMe error. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/nvme/host/apple.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 732d7b63be3d4..2164b13f4e787 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -210,6 +210,8 @@ struct apple_nvme_hw { bool needs_ioq_registers; /* T8132 needs a PMGR reset when starting a stopped coprocessor. */ bool cold_reset; + /* The ANS is never reset through PMGR here, so no reset is named. */ + bool reset_optional; u32 max_queue_depth; unsigned long quirks; }; @@ -2407,7 +2409,9 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) goto out_detach_genpd; } - anv->reset = devm_reset_control_array_get_exclusive(anv->dev); + anv->reset = anv->hw->reset_optional ? + devm_reset_control_array_get_optional_exclusive(anv->dev) : + devm_reset_control_array_get_exclusive(anv->dev); if (IS_ERR(anv->reset)) { ret = dev_err_probe(dev, PTR_ERR(anv->reset), "Failed to get reset control"); @@ -2776,8 +2780,26 @@ static const struct apple_nvme_hw apple_nvme_t6040_hw = { .quirks = NVME_QUIRK_NO_APST, }; +/* + * T6050 (M5 Ultra) ANS on bare metal: T6040's split layout (a 64 KiB "nvme" + * block, a separate NVMMU, linear submission queues), 64 queue entries. Like + * every post-M4 ANS without cold_reset it is never reset through PMGR, so no + * reset is named. + */ +static const struct apple_nvme_hw apple_nvme_t6050_hw = { + .has_lsq_nvmmu = true, + .has_separate_nvmmu = true, + .needs_ioq_registers = true, + .lsq_in_nvmmu = true, + .reset_optional = true, + .max_queue_depth = 64, + /* FUA is not shown durable on this ANS: flush instead. */ + .quirks = NVME_QUIRK_NO_APST | NVME_QUIRK_BROKEN_FUA, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t6041-nvme-ans2", .data = &apple_nvme_t6040_hw }, + { .compatible = "apple,t6050-nvme-ans2", .data = &apple_nvme_t6050_hw }, { .compatible = "apple,t8015-nvme-ans2", .data = &apple_nvme_t8015_hw }, { .compatible = "apple,t8103-nvme-ans2", .data = &apple_nvme_t8103_hw }, { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, From e6e2873d43060788fe591a3e75b92e80c2bb3b79 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:23:19 -0800 Subject: [PATCH 274/342] dt-bindings: nvme: apple: Allow the boot loader's RTKit handoff on T6050 The boot loader leaves the T6050 ANS's firmware running with the controller disabled and, as on T8132 and T8140, adds apple,rtkit-handoff to the node so the kernel adopts that RTKit session instead of starting the co-processor again. The T6050 profile relies on that adoption. Allow the property on apple,t6050-nvme-ans2. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index 3d08734f0ee74..7f289a02d4b21 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -117,6 +117,7 @@ allOf: not: contains: enum: + - apple,t6050-nvme-ans2 - apple,t8132-nvme-ans2 - apple,t8140-nvme-ans2 then: From 4954d7062a3e96b36013c04bae6501a91d28340b Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:18 -0400 Subject: [PATCH 275/342] mfd: macsmc: Support T6050 power and pcIO consumers Add the T6050 SMC consumer profile, described pcIO GPIO outputs, power-supply identity sizing, and charging policy. Preserve the newer shared SRAM accessor and metadata serialization. Source snapshot: t6050-gpu ee68abb105200e99636a5edfc647a5cfc1d89954 Integration base: 9cbdd0734d9e186c5f5f5949a21b909d10c2571b Signed-off-by: Dj Signed-off-by: Erik Bourget --- .../devicetree/bindings/mfd/apple,smc.yaml | 2 +- drivers/gpio/gpio-macsmc.c | 77 ++++++++++++++++++- drivers/mfd/macsmc.c | 35 +++++++-- drivers/power/supply/macsmc-power.c | 41 ++++++++-- 4 files changed, 141 insertions(+), 14 deletions(-) diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml index 050ac9c6388ca..c35e7d0e10faa 100644 --- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml @@ -1,4 +1,4 @@ -# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) AND GPL-2.0-only %YAML 1.2 --- $id: http://devicetree.org/schemas/mfd/apple,smc.yaml# diff --git a/drivers/gpio/gpio-macsmc.c b/drivers/gpio/gpio-macsmc.c index 5f43b79b6013c..6a26f900bba28 100644 --- a/drivers/gpio/gpio-macsmc.c +++ b/drivers/gpio/gpio-macsmc.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT +// SPDX-License-Identifier: (GPL-2.0-only OR MIT) AND GPL-2.0-only /* * Apple SMC GPIO driver * Copyright The Asahi Linux Contributors @@ -16,6 +16,7 @@ #include #include #include +#include #define MAX_GPIO 64 @@ -103,6 +104,7 @@ struct macsmc_gpio { struct apple_smc *smc; struct gpio_chip gc; + u64 *output_commands; int first_index; smc_key base_key; @@ -383,6 +385,76 @@ static int macsmc_gpio_init_valid_mask(struct gpio_chip *gc, return 0; } +/* Each DT template identifies one output; its low 16 bits carry the value. */ +static int macsmc_pcio_set(struct gpio_chip *gc, unsigned int offset, int value) +{ + struct macsmc_gpio *smcgp = gpiochip_get_data(gc); + u8 command[8]; + int ret; + + put_unaligned_le64(smcgp->output_commands[offset] | !!value, command); + ret = apple_smc_write(smcgp->smc, SMC_KEY(pcIO), command, sizeof(command)); + /* SMC writes return status, not a byte count. */ + return ret < 0 ? ret : 0; +} + +static int macsmc_pcio_get(struct gpio_chip *gc, unsigned int offset) +{ + /* The native output command has no established input/readback operation. */ + return -EOPNOTSUPP; +} + +static int macsmc_pcio_get_direction(struct gpio_chip *gc, unsigned int offset) +{ + return GPIO_LINE_DIRECTION_OUT; +} + +static int macsmc_pcio_probe(struct macsmc_gpio *smcgp) +{ + struct device *dev = smcgp->dev; + struct apple_smc_key_info info; + int count, ret; + + /* A board that uses none of the outputs leaves the list out. */ + if (!of_property_present(dev->of_node, "apple,output-commands")) + return -ENODEV; + + ret = apple_smc_get_key_info(smcgp->smc, SMC_KEY(pcIO), &info); + if (ret < 0) + return ret; + if (info.size != 8 || !(info.flags & APPLE_SMC_WRITABLE)) + return dev_err_probe(dev, -EINVAL, "pcIO is not an eight-byte output key\n"); + count = of_property_count_u64_elems(dev->of_node, "apple,output-commands"); + if (count <= 0 || count > MAX_GPIO) + return -EINVAL; + smcgp->output_commands = devm_kcalloc(dev, count, sizeof(u64), GFP_KERNEL); + if (!smcgp->output_commands) + return -ENOMEM; + ret = of_property_read_u64_array(dev->of_node, "apple,output-commands", + smcgp->output_commands, count); + if (ret) + return ret; + for (int i = 0; i < count; i++) { + if (smcgp->output_commands[i] & 0xffff) + return -EINVAL; + for (int j = 0; j < i; j++) + if (smcgp->output_commands[i] == smcgp->output_commands[j]) + return -EINVAL; + } + + smcgp->gc.label = "macsmc-pcio-output"; + smcgp->gc.owner = THIS_MODULE; + smcgp->gc.get = macsmc_pcio_get; + smcgp->gc.set = macsmc_pcio_set; + smcgp->gc.direction_output = macsmc_pcio_set; + smcgp->gc.get_direction = macsmc_pcio_get_direction; + smcgp->gc.can_sleep = true; + smcgp->gc.ngpio = count; + smcgp->gc.base = -1; + smcgp->gc.parent = dev; + return devm_gpiochip_add_data(dev, &smcgp->gc, smcgp); +} + struct macsmc_gpio_of_match_data { smc_key base_key; }; @@ -449,6 +521,8 @@ static int macsmc_gpio_probe(struct platform_device *pdev) smcgp->dev = &pdev->dev; smcgp->smc = smc; + if (device_is_compatible(&pdev->dev, "apple,smc-pcio-gpio")) + return macsmc_pcio_probe(smcgp); smcgp->base_key = data ? data->base_key : _SMC_KEY("gP\0\0"); smcgp->j700_pcio = of_machine_is_compatible("apple,j700") && device_is_compatible(&pdev->dev, "apple,smc-gpio"); @@ -498,6 +572,7 @@ static const struct macsmc_gpio_of_match_data macsmc_gpio_low_data = { }; static const struct of_device_id macsmc_gpio_of_table[] = { + { .compatible = "apple,smc-pcio-gpio" }, { .compatible = "apple,smc-gpio", .data = &macsmc_gpio_up_data, diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 546e5cdbb72ad..80f965194bc3a 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT +// SPDX-License-Identifier: (GPL-2.0-only OR MIT) AND GPL-2.0-only /* * Apple SMC (System Management Controller) MFD driver * @@ -59,6 +59,16 @@ static const struct mfd_cell apple_smc_devs[] = { MFD_CELL_OF("macsmc-rtc", NULL, NULL, 0, 0, "apple,smc-rtc"), }; +/* This profile exposes notifications and the explicitly described outputs. */ +static const struct mfd_cell apple_smc_t6050_devs[] = { + MFD_CELL_NAME("macsmc-input"), + MFD_CELL_NAME("macsmc-power"), + MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"), +}; + +static const struct mfd_cell apple_smc_pcio_dev = + MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-pcio-gpio"); + /* The second GPIO bank ('gp' keys) only exists on some SMCs. */ static const struct mfd_cell apple_smc_low_gpio_dev = MFD_CELL_OF("macsmc-low-gpio", NULL, NULL, 0, 0, "apple,smc-low-gpio"); @@ -250,8 +260,8 @@ int apple_smc_get_key_info(struct apple_smc *smc, smc_key key, struct apple_smc_ u8 key_info[6]; int ret; + /* Keep the shared reply buffer stable until its metadata is copied. */ guard(mutex)(&smc->mutex); - ret = apple_smc_cmd_locked(smc, SMC_MSG_GET_KEY_INFO, key, 0, 0, NULL); if (ret >= 0 && info) { apple_smc_read_sram(smc, key_info, sizeof(key_info)); @@ -559,12 +569,26 @@ static int apple_smc_probe(struct platform_device *pdev) if (ret) return ret; - ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, - apple_smc_devs, ARRAY_SIZE(apple_smc_devs), - NULL, 0, NULL); + if (of_device_is_compatible(dev->of_node, "apple,t6050-smc")) + ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, + apple_smc_t6050_devs, + ARRAY_SIZE(apple_smc_t6050_devs), NULL, 0, NULL); + else + ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, + apple_smc_devs, ARRAY_SIZE(apple_smc_devs), + NULL, 0, NULL); if (ret) return dev_err_probe(smc->dev, ret, "Failed to register sub-devices"); + np = of_get_compatible_child(dev->of_node, "apple,smc-pcio-gpio"); + if (np) { + of_node_put(np); + ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, + &apple_smc_pcio_dev, 1, NULL, 0, NULL); + if (ret) + return dev_err_probe(dev, ret, "Failed to register pcIO outputs\n"); + } + /* * Register the second GPIO bank only where the device tree describes * it: the MFD core would otherwise create an unbound device and warn @@ -585,6 +609,7 @@ static int apple_smc_probe(struct platform_device *pdev) static const struct of_device_id apple_smc_of_match[] = { { .compatible = "apple,t8152-smc" }, + { .compatible = "apple,t6050-smc" }, { .compatible = "apple,t8103-smc" }, { .compatible = "apple,smc" }, {}, diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c index 1bc23703654a4..1e306c7bb3f6c 100644 --- a/drivers/power/supply/macsmc-power.c +++ b/drivers/power/supply/macsmc-power.c @@ -960,10 +960,34 @@ static int macsmc_power_event(struct notifier_block *nb, unsigned long event, vo return NOTIFY_DONE; } +static int macsmc_read_identity(struct apple_smc *smc, smc_key key, + char *out, size_t capacity) +{ + struct apple_smc_key_info info; + int ret; + + if (!capacity) + return -EINVAL; + out[0] = '\0'; + ret = apple_smc_get_key_info(smc, key, &info); + if (ret < 0) + return ret; + if (!info.size || info.size >= capacity || !(info.flags & APPLE_SMC_READABLE)) + return -EINVAL; + /* SMC read requests must describe this key, not the destination buffer. */ + ret = apple_smc_read(smc, key, out, info.size); + if (ret != info.size) { + out[0] = '\0'; + return ret < 0 ? ret : -EIO; + } + out[info.size] = '\0'; + return 0; +} + static int macsmc_power_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent); + struct apple_smc *smc; struct power_supply_config psy_cfg = {}; struct apple_smc_key_info info; struct macsmc_power *power; @@ -976,6 +1000,9 @@ static int macsmc_power_probe(struct platform_device *pdev) enum power_supply_property *props; size_t nprops; + if (!dev->parent) + return dev_err_probe(dev, -ENODEV, "Missing SMC parent\n"); + smc = dev_get_drvdata(dev->parent); if (!smc) return -ENODEV; @@ -1121,12 +1148,12 @@ static int macsmc_power_probe(struct platform_device *pdev) power->batt_desc.num_properties = nprops; /* Fetch identity strings */ - apple_smc_read(smc, SMC_KEY(BMDN), power->model_name, - sizeof(power->model_name) - 1); - apple_smc_read(smc, SMC_KEY(BMSN), power->serial_number, - sizeof(power->serial_number) - 1); - apple_smc_read(smc, SMC_KEY(BMDT), power->mfg_date, - sizeof(power->mfg_date) - 1); + macsmc_read_identity(smc, SMC_KEY(BMDN), power->model_name, + sizeof(power->model_name)); + macsmc_read_identity(smc, SMC_KEY(BMSN), power->serial_number, + sizeof(power->serial_number)); + macsmc_read_identity(smc, SMC_KEY(BMDT), power->mfg_date, + sizeof(power->mfg_date)); apple_smc_read_u8(power->smc, SMC_KEY(BNCB), &power->num_cells); power->nominal_voltage_mv = MACSMC_NOMINAL_CELL_VOLTAGE_MV * power->num_cells; From 853ccc6231b615d39ea101dd436f65c148bdf195 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 276/342] mfd: macsmc: Register T6050's reboot and RTC cells where the DT has them The T6050 profile (Aurora's t6050/smc) registers input, power and hwmon only, so a T6050 kernel that owns the machine (J775D on bare metal) had no SMC restart or power-off and no RTC: poweroff halted Linux and left the machine on. Add macsmc-reboot and macsmc-rtc to the T6050 profile as cells that are registered only where the device tree has their child node, the rule the pcIO outputs and the second GPIO bank already follow; those two blocks become one table and one helper. A T6050 device tree without reboot or rtc children registers exactly what it did, and other SMCs are unchanged (same cells in the same order; the registration failure messages now name the cell). Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/mfd/macsmc.c | 80 +++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 80f965194bc3a..927ddaa00e0df 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -66,12 +66,47 @@ static const struct mfd_cell apple_smc_t6050_devs[] = { MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"), }; -static const struct mfd_cell apple_smc_pcio_dev = - MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-pcio-gpio"); +/* + * Cells registered only where the device tree describes them: the MFD core would otherwise + * create an unbound device and warn that it found no node on every SMC without one. The pcIO + * outputs and the second GPIO bank ('gp' keys) only exist on some SMCs. + */ +static const struct mfd_cell apple_smc_described_devs[] = { + MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-pcio-gpio"), + MFD_CELL_OF("macsmc-low-gpio", NULL, NULL, 0, 0, "apple,smc-low-gpio"), +}; -/* The second GPIO bank ('gp' keys) only exists on some SMCs. */ -static const struct mfd_cell apple_smc_low_gpio_dev = - MFD_CELL_OF("macsmc-low-gpio", NULL, NULL, 0, 0, "apple,smc-low-gpio"); +/* + * T6050's reboot/power-off and RTC, for a kernel that owns the machine (J775D, booted bare + * metal). Registered only where the device tree describes them, so a T6050 device tree without + * them registers what it did before. + */ +static const struct mfd_cell apple_smc_t6050_described_devs[] = { + MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"), + MFD_CELL_OF("macsmc-rtc", NULL, NULL, 0, 0, "apple,smc-rtc"), +}; + +static int apple_smc_add_described_devices(struct apple_smc *smc, const struct mfd_cell *cells, + size_t count) +{ + struct device_node *np; + size_t i; + int ret; + + for (i = 0; i < count; i++) { + np = of_get_compatible_child(smc->dev->of_node, cells[i].of_compatible); + if (!np) + continue; + of_node_put(np); + ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, &cells[i], 1, + NULL, 0, NULL); + if (ret) + return dev_err_probe(smc->dev, ret, "Failed to register %s\n", + cells[i].name); + } + + return 0; +} /* T8152 currently exposes read-only telemetry; firmware owns fan control. */ static const struct mfd_cell apple_smc_telemetry_devs[] = { @@ -493,9 +528,9 @@ static void apple_smc_disable_notifications(void *data) static int apple_smc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *np; struct apple_smc *smc; __be32 count = 0; + bool t6050; int ret; smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL); @@ -569,7 +604,8 @@ static int apple_smc_probe(struct platform_device *pdev) if (ret) return ret; - if (of_device_is_compatible(dev->of_node, "apple,t6050-smc")) + t6050 = of_device_is_compatible(dev->of_node, "apple,t6050-smc"); + if (t6050) ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, apple_smc_t6050_devs, ARRAY_SIZE(apple_smc_t6050_devs), NULL, 0, NULL); @@ -580,31 +616,13 @@ static int apple_smc_probe(struct platform_device *pdev) if (ret) return dev_err_probe(smc->dev, ret, "Failed to register sub-devices"); - np = of_get_compatible_child(dev->of_node, "apple,smc-pcio-gpio"); - if (np) { - of_node_put(np); - ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, - &apple_smc_pcio_dev, 1, NULL, 0, NULL); - if (ret) - return dev_err_probe(dev, ret, "Failed to register pcIO outputs\n"); - } - - /* - * Register the second GPIO bank only where the device tree describes - * it: the MFD core would otherwise create an unbound device and warn - * that it found no node on every SMC without one. - */ - np = of_get_compatible_child(dev->of_node, "apple,smc-low-gpio"); - if (np) { - of_node_put(np); - ret = devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, - &apple_smc_low_gpio_dev, 1, NULL, 0, NULL); - if (ret) - return dev_err_probe(smc->dev, ret, - "Failed to register the second GPIO bank"); - } + ret = apple_smc_add_described_devices(smc, apple_smc_described_devs, + ARRAY_SIZE(apple_smc_described_devs)); + if (ret || !t6050) + return ret; - return 0; + return apple_smc_add_described_devices(smc, apple_smc_t6050_described_devs, + ARRAY_SIZE(apple_smc_t6050_described_devs)); } static const struct of_device_id apple_smc_of_match[] = { From ad0f93637543787d6156515baf9a38422add5c29 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 277/342] hwmon: macsmc: Let discovered temperatures join the SoC die zone apple,soc-die-keys adds a "SoC die " channel per listed key for the macsmc_soc_die zone, and apple,discover-temperatures refuses to run once any temperature channel exists, so a machine that discovers its temperatures (T8142, J775D) could not have the zone: the probe failed with -EINVAL. With discovery, a listed key now adds no channel; the channel discovery creates for it (labelled with the key) is marked for the zone instead. Machines that set only one of the two properties are unchanged. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- .../bindings/hwmon/apple,smc-hwmon.yaml | 4 +++- Documentation/hwmon/macsmc-hwmon.rst | 2 ++ drivers/hwmon/macsmc-hwmon.c | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml index a4e4dfd3c0886..5ba2a01b323e5 100644 --- a/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml +++ b/Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml @@ -62,7 +62,9 @@ properties: follow the temperature-* children in the listed order and are labelled "SoC die ". Keys absent from the running firmware or with an unsupported format are skipped. These channels do not change the indices - used by thermal-sensors references to temperature-* children. + used by thermal-sensors references to temperature-* children. With + apple,discover-temperatures, a listed key adds no channel; its + discovered channel (labelled with the key) supplies the zone. apple,thermal-pressure-key: $ref: /schemas/types.yaml#/definitions/string diff --git a/Documentation/hwmon/macsmc-hwmon.rst b/Documentation/hwmon/macsmc-hwmon.rst index b0c78c3412088..23baece30154a 100644 --- a/Documentation/hwmon/macsmc-hwmon.rst +++ b/Documentation/hwmon/macsmc-hwmon.rst @@ -43,6 +43,8 @@ Only readable four-byte floating-point keys are used. When thermal support is enabled, their hottest reading supplies the ``macsmc_soc_die`` thermal zone. A failed or implausible reading fails the zone read rather than reporting a partial result. Keys absent from the firmware are skipped. +With ``apple,discover-temperatures`` the listed keys add no channels: the +discovered channel of each listed key, labelled with the key, joins the zone. The optional ``apple,thermal-pressure-key`` on the same node describes a readable signed 32-bit firmware thermal pressure level. Neither feature needs diff --git a/drivers/hwmon/macsmc-hwmon.c b/drivers/hwmon/macsmc-hwmon.c index d0206489fa372..ddf287a190efa 100644 --- a/drivers/hwmon/macsmc-hwmon.c +++ b/drivers/hwmon/macsmc-hwmon.c @@ -901,6 +901,9 @@ static int macsmc_hwmon_discover_temperatures(struct macsmc_hwmon *hwmon) if (!smc->key_count || smc->key_count > U16_MAX) return -EINVAL; + ret = of_property_count_strings(hwmon->dev->of_node, "apple,soc-die-keys"); + hwmon->die_listed = ret > 0 ? ret : 0; + hwmon->temp.sensors = devm_kcalloc(hwmon->dev, smc->key_count, sizeof(*sensor), GFP_KERNEL); if (!hwmon->temp.sensors) @@ -934,6 +937,12 @@ static int macsmc_hwmon_discover_temperatures(struct macsmc_hwmon *hwmon) /* Key identity only: do not invent locations or calibration. */ snprintf(sensor->label, sizeof(sensor->label), "%c%c%c%c", key >> 24, (key >> 16) & 0xff, (key >> 8) & 0xff, key & 0xff); + /* A listed SoC die key keeps its discovered channel and joins the die zone. */ + if (of_property_match_string(hwmon->dev->of_node, "apple,soc-die-keys", + sensor->label) >= 0) { + sensor->die = true; + hwmon->die_count++; + } } return 0; @@ -1117,7 +1126,11 @@ static int macsmc_hwmon_populate_sensors(struct macsmc_hwmon *hwmon, for_each_child_of_node_with_prefix(hwmon_node, key_node, "temperature-") { n_temperature++; } - n_temperature += n_die_keys; + /* With discovery, listed die keys mark discovered channels instead (see there). */ + if (!of_property_read_bool(hwmon_node, "apple,discover-temperatures")) + n_temperature += n_die_keys; + else + n_die_keys = 0; if (n_temperature) { hwmon->temp.sensors = devm_kcalloc(hwmon->dev, n_temperature, From 4d11bfdc0ef5e960fd4712854bdc34fbdb2ee955 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 01:35:36 -0800 Subject: [PATCH 278/342] power: reset: macsmc-reboot: Add ac_power_mode, with power-on at connect Expose the PMU's power-on policy byte as the ac_power_mode attribute Asahi's downstream driver had, with a third mode. The byte has two policy bits: bit 0 keeps the machine off when power returns after a loss, bit 5 keeps it off when power is connected. Asahi's driver wrote the whole byte (0x02 restore, 0x03 off), which clears bit 5: on machines whose PMU powers on at connect that write means "always", the opposite of "off". Change only the two bits and leave the rest to the PMU: off bit 0 and bit 5 set restore bit 5 set, bit 0 clear always bit 5 clear (bit 0 set) The pm_setting cell is optional; the attribute appears only with it. The binding takes it as a fifth cell, as the t600x/t602x device trees already list it. Based on Asahi's ac_power_mode (marcan). Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- .../ABI/testing/sysfs-driver-macsmc-reboot | 16 +++ drivers/power/reset/macsmc-reboot.c | 118 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-macsmc-reboot diff --git a/Documentation/ABI/testing/sysfs-driver-macsmc-reboot b/Documentation/ABI/testing/sysfs-driver-macsmc-reboot new file mode 100644 index 0000000000000..8a485592fedba --- /dev/null +++ b/Documentation/ABI/testing/sysfs-driver-macsmc-reboot @@ -0,0 +1,16 @@ +What: /sys/bus/platform/drivers/macsmc-reboot//ac_power_mode +Date: November 2026 +KernelVersion: 7.4 +Description: + What the machine does when external power arrives, as kept in + the PMU (present only when the device tree gives the reboot + node a pm_setting cell). Reading lists the modes with the + current one in brackets; writing a mode name sets it: + + off: + stay off + restore: + power on after a power loss if the machine was on + always: + power on whenever power is connected (the 2024 and later + desktops; other machines may ignore it) diff --git a/drivers/power/reset/macsmc-reboot.c b/drivers/power/reset/macsmc-reboot.c index 7688cfd4ed60d..a2e1422e05bd8 100644 --- a/drivers/power/reset/macsmc-reboot.c +++ b/drivers/power/reset/macsmc-reboot.c @@ -8,10 +8,12 @@ #include #include #include +#include #include #include #include #include +#include struct macsmc_reboot_nvmem { struct nvmem_cell *shutdown_flag; @@ -33,10 +35,39 @@ enum boot_stage { BOOT_STAGE_KERNEL_STARTED = 0x30, /* Normal OS booting */ }; +/* + * The PMU's power-on policy byte: bit 0 set keeps the machine off when power returns after a + * loss, bit 5 set keeps it off when power is connected (bit 5 clear powers it on at connect + * whatever bit 0 says). Changes are read-modify-write: the other bits are the PMU's. + */ +#define PM_SETTING_NO_RESTORE BIT(0) +#define PM_SETTING_NO_POWER_ON_CONNECT BIT(5) +#define PM_SETTING_AC_POWER_MASK (PM_SETTING_NO_RESTORE | PM_SETTING_NO_POWER_ON_CONNECT) + +enum ac_power_mode { + AC_POWER_OFF, /* stay off */ + AC_POWER_RESTORE, /* power on after a power loss if it was on */ + AC_POWER_ALWAYS, /* power on whenever power is connected */ +}; + +static const char * const ac_power_modes[] = { + [AC_POWER_OFF] = "off", + [AC_POWER_RESTORE] = "restore", + [AC_POWER_ALWAYS] = "always", +}; + +static const u8 ac_power_mode_bits[] = { + [AC_POWER_OFF] = PM_SETTING_NO_RESTORE | PM_SETTING_NO_POWER_ON_CONNECT, + [AC_POWER_RESTORE] = PM_SETTING_NO_POWER_ON_CONNECT, + [AC_POWER_ALWAYS] = PM_SETTING_NO_RESTORE, +}; + struct macsmc_reboot { struct device *dev; struct apple_smc *smc; struct notifier_block reboot_notify; + struct nvmem_cell *pm_setting; + struct mutex pm_setting_lock; union { struct macsmc_reboot_nvmem nvm; @@ -198,6 +229,80 @@ static void macsmc_power_init_error_counts(struct macsmc_reboot *reboot) dev_err(reboot->dev, "Failed to reset boot_error_count\n"); } +static enum ac_power_mode macsmc_ac_power_mode(u8 val) +{ + if (!(val & PM_SETTING_NO_POWER_ON_CONNECT)) + return AC_POWER_ALWAYS; + if (val & PM_SETTING_NO_RESTORE) + return AC_POWER_OFF; + return AC_POWER_RESTORE; +} + +static ssize_t ac_power_mode_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct macsmc_reboot *reboot = dev_get_drvdata(dev); + enum ac_power_mode mode; + int val, i, len = 0; + + val = nvmem_cell_get_u8(reboot->pm_setting); + if (val < 0) + return val; + mode = macsmc_ac_power_mode(val); + + for (i = 0; i < ARRAY_SIZE(ac_power_modes); i++) + len += sysfs_emit_at(buf, len, i == mode ? "[%s] " : "%s ", ac_power_modes[i]); + buf[len - 1] = '\n'; + + return len; +} + +static ssize_t ac_power_mode_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t n) +{ + struct macsmc_reboot *reboot = dev_get_drvdata(dev); + int mode, val, ret; + u8 new; + + mode = sysfs_match_string(ac_power_modes, buf); + if (mode < 0) + return mode; + + mutex_lock(&reboot->pm_setting_lock); + val = nvmem_cell_get_u8(reboot->pm_setting); + if (val < 0) { + ret = val; + goto out; + } + new = (val & ~PM_SETTING_AC_POWER_MASK) | ac_power_mode_bits[mode]; + ret = new == val ? 0 : nvmem_cell_set_u8(reboot->pm_setting, new); + if (!ret && new != val) + dev_info(dev, "PM setting %02x => %02x (ac_power_mode %s)\n", val, new, + ac_power_modes[mode]); +out: + mutex_unlock(&reboot->pm_setting_lock); + + return ret < 0 ? ret : n; +} +static DEVICE_ATTR_RW(ac_power_mode); + +static struct attribute *macsmc_reboot_attrs[] = { + &dev_attr_ac_power_mode.attr, + NULL +}; + +static umode_t macsmc_reboot_attr_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct macsmc_reboot *reboot = dev_get_drvdata(kobj_to_dev(kobj)); + + return reboot && reboot->pm_setting ? attr->mode : 0; +} + +static const struct attribute_group macsmc_reboot_group = { + .attrs = macsmc_reboot_attrs, + .is_visible = macsmc_reboot_attr_visible, +}; +__ATTRIBUTE_GROUPS(macsmc_reboot); + static int macsmc_reboot_probe(struct platform_device *pdev) { struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent); @@ -237,6 +342,18 @@ static int macsmc_reboot_probe(struct platform_device *pdev) reboot->nvm_cells[i] = cell; } + /* Optional: the power-on policy byte, for ac_power_mode */ + mutex_init(&reboot->pm_setting_lock); + reboot->pm_setting = devm_nvmem_cell_get(&pdev->dev, "pm_setting"); + if (IS_ERR(reboot->pm_setting)) { + ret = PTR_ERR(reboot->pm_setting); + if (ret == -EPROBE_DEFER) + return ret; + if (ret != -ENOENT) + dev_warn(&pdev->dev, "Missing NVMEM cell pm_setting (%d)\n", ret); + reboot->pm_setting = NULL; + } + /* Set the boot_stage to indicate we're running the OS kernel */ if (reboot->nvm.boot_stage && nvmem_cell_set_u8(reboot->nvm.boot_stage, BOOT_STAGE_KERNEL_STARTED) < 0) @@ -287,6 +404,7 @@ static struct platform_driver macsmc_reboot_driver = { .driver = { .name = "macsmc-reboot", .of_match_table = macsmc_reboot_of_table, + .dev_groups = macsmc_reboot_groups, }, .probe = macsmc_reboot_probe, }; From 0f2bdecdbfd1a9f6562ff367cb2d728e535fcd9e Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 09:50:46 -0500 Subject: [PATCH 279/342] dt-bindings: phy: Drop the duplicate T6050 combo PHY schema integration/aurora already describes apple,t6050-dp-phy and apple,t6050-combo-phy in apple,combo-phy.yaml, with matrix-typed tunables, the CIO tunables and the optional "usb" domain. The copy in apple,t6050-dp-phy.yaml claims the same compatibles, so dt-validate reports a duplicate schema, picks up its uint32-array types and its required tunables, and every T6050 combo PHY node that the boot loader fills in (J714s, J716s, J775c/d, J873s, K114/K116) fails validation. Remove the copy, as erikwb's restacked #1268 does, so each compatible has one schema. Signed-off-by: Diljit Singh --- .../bindings/phy/apple,t6050-dp-phy.yaml | 257 ------------------ 1 file changed, 257 deletions(-) delete mode 100644 Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml deleted file mode 100644 index 3b22c3f19ee9b..0000000000000 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ /dev/null @@ -1,257 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/phy/apple,t6050-dp-phy.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple T6050 DisplayPort and Type-C combo PHY - -maintainers: - - Dj - -description: | - Fixed four-lane DisplayPort PHY for HDMI bridges, or one shared owner of - Type-C USB2, USB3 and DisplayPort alternate mode. DisplayPort supports RBR - through HBR3 without spread-spectrum clocking. The combo provider serializes - controller shutdown, PIPE handoff, orientation and alternate-mode changes. - Register resources, power domains and board tunables come from the producer. - -properties: - compatible: - enum: - - apple,t6050-dp-phy - - apple,t6050-combo-phy - - reg: - minItems: 6 - maxItems: 11 - - reg-names: - minItems: 6 - maxItems: 11 - - '#phy-cells': - enum: [0, 1] - - '#reset-cells': - const: 1 - - apple,port-index: - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [1, 2, 3, 4, 5] - description: Type-C port; the debug port (0) is excluded - - apple,guest-port-reserved: - type: boolean - description: The boot producer has excluded this port from host ownership - - mode-switch: true - orientation-switch: true - - mboxes: - maxItems: 1 - - port: - $ref: /schemas/graph.yaml#/properties/port - - apple,tunable-aus40cmn-shm: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the common analog bank - - apple,tunable-cio4pll: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the CIO PLL bank - - apple,tunable-usb2-default: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the USB2 PHY bank - - apple,tunable-usb2-host: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the USB2 host bank - - apple,tunable-pipe-default: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the PIPE handler - - power-domains: - description: - A combo PHY may name the USB controller's domain fourth ("usb"). Its - USB2 PHY and digital banks are in that domain, and the PHY then holds it - while it runs, also on a port with no USB controller bound. - minItems: 3 - maxItems: 4 - - power-domain-names: - minItems: 3 - items: - - const: usb-aon - - const: common - - const: wrapper - - const: usb - - apple,tunable-axi2af: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-fabric: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-common-cfg: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lioa: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane0-rx-clock: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane1-rx-clock: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane0-rx-eq: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane1-rx-eq: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-auspll: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-uc-regs-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: - Offset, mask and value tuples for the PHY firmware's registers in CIO - (USB4/Thunderbolt) mode. Optional; an absent CIO tunable is skipped. - - apple,tunable-lane0-rx-top-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 0's receiver top bank - - apple,tunable-lane1-rx-top-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 1's receiver top bank - - apple,tunable-lane0-rx-eq-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 0's receiver equalizer - - apple,tunable-lane1-rx-eq-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 1's receiver equalizer - -patternProperties: - '^apple,dp-training-table(-rbr|-hbr|-hbr2|-hbr3)?$': - $ref: /schemas/types.yaml#/definitions/uint32-array - minItems: 16 - maxItems: 16 - description: Drive presets indexed by voltage swing times four plus pre-emphasis - -required: - - compatible - - reg - - reg-names - - '#phy-cells' - - power-domains - - power-domain-names - - apple,tunable-axi2af - - apple,tunable-fabric - - apple,tunable-common-cfg - - apple,tunable-lioa - - apple,tunable-lane0-rx-clock - - apple,tunable-lane1-rx-clock - - apple,tunable-lane0-rx-eq - - apple,tunable-lane1-rx-eq - - apple,tunable-auspll - -allOf: - - if: - properties: - compatible: - const: apple,t6050-combo-phy - then: - properties: - '#phy-cells': - const: 1 - reg: - minItems: 11 - maxItems: 11 - reg-names: - items: - - const: core - - const: usb2phy - - const: usb2-digital - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - - const: usb-control - - const: firmware-data - - const: pipehandler - required: - - '#reset-cells' - - apple,port-index - - apple,guest-port-reserved - - mode-switch - - orientation-switch - - mboxes - - apple,tunable-aus40cmn-shm - - apple,tunable-cio4pll - - apple,tunable-usb2-default - - apple,tunable-usb2-host - - apple,tunable-pipe-default - else: - properties: - '#phy-cells': - const: 0 - power-domains: - maxItems: 3 - power-domain-names: - maxItems: 3 - if: - required: - - mode-switch - then: - properties: - reg: - minItems: 8 - maxItems: 8 - reg-names: - items: - - const: core - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - - const: usb-control - - const: firmware-data - required: - - orientation-switch - - mboxes - - apple,tunable-aus40cmn-shm - - apple,tunable-cio4pll - else: - properties: - reg: - minItems: 6 - maxItems: 6 - reg-names: - items: - - const: core - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - -additionalProperties: false From b092bd463ed0f21e7b755b19fda3e611ae790755 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 09:51:43 -0500 Subject: [PATCH 280/342] dt-bindings: soc: apple: pmp: Describe the T6050 PMP with its mailbox The T6050 PMP node now has the form its driver uses on the other SoCs: the firmware SRAM and ASC views named "pmp" and "asc", and the ASC mailbox, with the mailbox interrupts moving to that node. Describe it that way, keeping the second power domain (PMS SRAM). The node is no longer required to stay disabled. Signed-off-by: Diljit Singh --- .../bindings/soc/apple/apple,pmp.yaml | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml index bcbd0ecf4568a..4ae4380167632 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml @@ -60,7 +60,7 @@ properties: interrupts: maxItems: 4 - description: Coprocessor mailbox and status interrupts, on T6050 in ADT order. + description: Coprocessor mailbox and status interrupts. iommus: maxItems: 1 @@ -148,23 +148,19 @@ allOf: const: apple,t6050-pmp-v2 then: description: - The T6050 PMP is described from the ADT and stays disabled until its - firmware handoff is supported; its mailbox is not described yet. + The T6050 PMP's firmware SRAM and ASC views and its ASC mailbox. It + also holds the PMS SRAM's power domain. properties: reg: - minItems: 4 - maxItems: 4 - interrupts: - minItems: 4 - maxItems: 4 + maxItems: 2 power-domains: minItems: 2 - status: - const: disabled + interrupts: false required: - - interrupts + - reg-names + - mboxes + - mbox-names - power-domains - - status else: properties: reg: From 0387d4c03a869a9a21e07fac23b228c105b12c72 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:06:03 +1100 Subject: [PATCH 281/342] dt-bindings: spmi: apple,spmi: an interrupt controller may have no AP line The T8112 AOP SPMI controllers demultiplex follower interrupts but have no interrupt line to the AP. Require #interrupt-cells with interrupt-controller, but not interrupts. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- Documentation/devicetree/bindings/spmi/apple,spmi.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml index 5c9e77075b303..48706095da208 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -53,7 +53,12 @@ properties: maxItems: 1 description: Optional, operates in polled mode if not present - interrupt-controller: true + interrupt-controller: + description: + The controller demultiplexes follower interrupts. Some instances (the + T8112 AOP controllers) have no interrupt line to the AP. Follower + interrupts are then described but cannot be delivered, and drivers + fall back to polling or stay idle. "#interrupt-cells": const: 2 @@ -68,7 +73,6 @@ required: dependentRequired: interrupt-controller: - "#interrupt-cells" - - interrupts unevaluatedProperties: false From c6773e9de5a9780081e5c40eb5812c4f5341f9b5 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 10:10:53 -0500 Subject: [PATCH 282/342] pmdomain: apple: pmp-report: Add T6050 The T6050 PMP nub's ptd-range lists the PTD entries T6041 has, at the same places: PMP-STATUS 1, SOC-DEV-PS-REQ 480, SOC-DEV-PS-ACK 488 and FAST-DIE-CE 600 with three lanes. Use T6041's offsets. Tested on J714s (M5 Pro) with the report at 0x284240000 and always-on requests for the three CPU clusters, the internal display and ANS: the driver reads "PMP running (status 0x1)" and writes requests 0x1000047000, the PMP acknowledges every bit, and its PMC vote drops from the static DCS 5 / fabric 1 iBoot leaves to 0 and stays there at idle and under CPU and GPU load. Signed-off-by: Diljit Singh --- .../devicetree/bindings/power/apple,t8140-pmp-report.yaml | 2 ++ drivers/pmdomain/apple/pmp-report.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml index 5b36d27734605..ec06771e3a534 100644 --- a/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml +++ b/Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml @@ -50,6 +50,7 @@ properties: - apple,t6020-pmp-v2-report - apple,t6030-pmp-v2-report - apple,t6041-pmp-v2-report + - apple,t6050-pmp-v2-report - apple,t8112-pmp-v2-report - apple,t8122-pmp-v2-report - apple,t8140-pmp-v2-report @@ -113,6 +114,7 @@ patternProperties: - apple,t6030-pmp-v2-report-entry - apple,t6031-pmp-v2-report-entry - apple,t6041-pmp-v2-report-entry + - apple,t6050-pmp-v2-report-entry - apple,t8112-pmp-v2-report-entry - apple,t8122-pmp-v2-report-entry - const: apple,t6000-pmp-v2-report-entry diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 789cab1c29397..11178eef8fe7c 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -1537,6 +1537,8 @@ static const struct of_device_id apple_pmp_report_of_match[] = { { .compatible = "apple,t6030-pmp-v2-report", .data = &apple_pmp_offsets_t6030 }, { .compatible = "apple,t6031-pmp-v2-report", .data = &apple_pmp_offsets_t6031 }, { .compatible = "apple,t6041-pmp-v2-report", .data = &apple_pmp_offsets_t6041 }, + /* T6050: the ADT's ptd-range lists T6041's entries at the same places. */ + { .compatible = "apple,t6050-pmp-v2-report", .data = &apple_pmp_offsets_t6041 }, { .compatible = "apple,t8112-pmp-v2-report", .data = &apple_pmp_offsets_t8112 }, { .compatible = "apple,t8122-pmp-v2-report", .data = &apple_pmp_offsets_t8122 }, { .compatible = "apple,t8132-pmp-v2-report", .data = &apple_pmp_offsets_t8132 }, From aaa8797c3ce3e2b459ec04da691be594208d9b37 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 10:10:53 -0500 Subject: [PATCH 283/342] arm64: dts: apple: t6050: Describe the PMP report The host tells the PMP which soc-devices are on through the PTD: the read aperture at 0x284240000, and the update page 0x10000 above it, which is pmp0's ptd-update register (ADT reg[3]); together they are the PMGR's ADT reg[7]. Describe it with always-on requests for the three CPU clusters, the internal display and storage, the entries it was tested with. It stays disabled with the PMP. Signed-off-by: Diljit Singh --- .../boot/dts/apple/t6050-peripherals.dtsi | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index c4be3fcf47ca7..72c24739a5a51 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2203,6 +2203,69 @@ status = "disabled"; }; + /* + * PMP report (PTD): reads 16 bytes per entry from the base, writes 8 bytes per entry from + * base + 0x10000, which is pmp0's ptd-update register (ADT pmp0 reg[3]); together they are + * /arm-io/pmgr reg[7]. Entries are PMP soc-devices; an entry's reg is its soc-device ID - 1 + * (ADT iop-pmp0-nub soc-device). Without requests the running PMP keeps the vote iBoot left. + */ + pmp0_report: pmp-report@284240000 { + compatible = "apple,t6050-pmp-v2-report"; + reg = <0x2 0x84240000 0x0 0x20000>; + power-domains = <&ps_pms_sram>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + + /* The CPU clusters: MACC0, MACC1, PACC */ + report@c { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0xc>; + label = "pmp-macc0"; + #power-domain-cells = <0>; + apple,always-on; + }; + + report@d { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0xd>; + label = "pmp-macc1"; + #power-domain-cells = <0>; + apple,always-on; + }; + + report@e { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0xe>; + label = "pmp-pacc"; + #power-domain-cells = <0>; + apple,always-on; + }; + + /* The internal display (DISPINT) */ + report@12 { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0x12>; + label = "pmp-dispint"; + #power-domain-cells = <0>; + apple,always-on; + }; + + /* Storage (ANS) */ + report@24 { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0x24>; + label = "pmp-ans"; + #power-domain-cells = <0>; + apple,always-on; + }; + }; + pmp0_dart: iommu@2841a0000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; reg = <0x2 0x841a0000 0x0 0xc000>, From 8e704cbd0700b3b9d99d58633bd3361367fff126 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:00:24 +1100 Subject: [PATCH 284/342] arm64: dts: apple: expose the boot NOR system regions read-only The boot NOR below the nvram partition holds the iBoot firmware images and the syscfg factory data on the M1 and M2 family layout, and the syscfg data alone on J700. Describe that range as a read-only MTD partition so it can be inspected without risking a write. The new partition follows nvram in the node list so the nvram MTD index does not change. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> (cherry picked from commit 91d007d7faeab646ead12b5be273a38b5ac8eefa) --- arch/arm64/boot/dts/apple/spi1-nvram.dtsi | 10 ++++++++++ arch/arm64/boot/dts/apple/t8140-j700.dts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/arm64/boot/dts/apple/spi1-nvram.dtsi b/arch/arm64/boot/dts/apple/spi1-nvram.dtsi index 268d9ffb94044..aa7799a26d6d7 100644 --- a/arch/arm64/boot/dts/apple/spi1-nvram.dtsi +++ b/arch/arm64/boot/dts/apple/spi1-nvram.dtsi @@ -43,6 +43,16 @@ reg = <0x0 0x0>; status = "disabled"; }; + + /* + * iBoot firmware and the syscfg factory data. Listed + * after nvram so the nvram MTD index stays the same. + */ + partition@0 { + label = "firmware"; + reg = <0x0 0x700000>; + read-only; + }; }; }; }; diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index a9acaf70b90d5..54bc359a0e9de 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -540,6 +540,16 @@ label = "nvram"; reg = <0x24000 0x1d0000>; }; + + /* + * syscfg factory data. Listed after nvram so the nvram + * MTD index stays the same. + */ + partition@0 { + label = "syscfg"; + reg = <0x0 0x24000>; + read-only; + }; }; }; }; From a58009c15c038759cd2d789f8209e4fa51c32d10 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:15:21 +1100 Subject: [PATCH 285/342] arm64: dts: apple: t8112-j413: enable the read-only aux PMIC view Enable the auxiliary PMIC SPMI bus. The Vale PMIC on it is exported as a read-only apple-spmi-nvmem device. The bus has no interrupt, so the controller polls, makes no register writes at probe, and no SPMI transaction happens until the NVMEM device is read. Tested on the M2: 4 KiB read in 256-byte pages with no SPMI errors, page 0 stable on re-read. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8112-j413.dts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 9c9e7532ae048..15629b518e467 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -306,11 +306,12 @@ }; &nub_spmi1 { + status = "okay"; + pmic@e { compatible = "apple,vale-pmic", "apple,spmi-nvmem"; reg = <0xe SPMI_USID>; read-only; - status = "disabled"; }; }; From a125bb5557b4907ecb433acccb93007654b567bb Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:08:20 +1100 Subject: [PATCH 286/342] nvmem: apple-spmi-nvmem: make the sysfs file root-only The nvmem file of an SPMI follower reads PMIC registers on the bus. Restrict it to root, like the other register-backed nvmem providers. In-kernel cell consumers are unaffected. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> (cherry picked from commit 320c84189a2c58ce0f17a7af6df27313c2a9aaa4) --- drivers/nvmem/apple-spmi-nvmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvmem/apple-spmi-nvmem.c b/drivers/nvmem/apple-spmi-nvmem.c index 755c429730dce..b31b8212d3fcc 100644 --- a/drivers/nvmem/apple-spmi-nvmem.c +++ b/drivers/nvmem/apple-spmi-nvmem.c @@ -46,6 +46,8 @@ static int apple_spmi_nvmem_probe(struct spmi_device *sdev) .word_size = 1, .stride = 1, .size = 0xffff, + /* PMIC registers: only root may read them through sysfs. */ + .root_only = true, .reg_read = apple_spmi_nvmem_read, .reg_write = apple_spmi_nvmem_write, }; From 8fbdc1d40e3b35dd0fba9b16e842cc9a34221a10 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:27:32 +1100 Subject: [PATCH 287/342] arm64: dts: apple: t8112-j413: add the GPU temperature sensors The M2 MacBook Air exposed no GPU temperature channel. Its SMC has six GPU keys: Tg0e, Tg0m and Tg0q, and Tg0f, Tg0n and Tg0r, which read the first three plus a fixed 4.6 C. Measured on a J413: 37.9-44.3 C during a glmark2 run. As on the M4 Pro, the SMC publishes them only while the GPU is powered. With the GPU off at idle they read 0 C and 4.6 C. Mark readings below 10 C as no data. They are read-only hwmon channels with no thermal zone or trip, added after the channels the thermal zones index. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-j413.dts | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index 9c9e7532ae048..720468c0cd3d3 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -272,6 +272,50 @@ }; #include "hwmon-laptop.dtsi" + +/* + * GPU temperatures, after the channels the thermal zones index. The SMC + * publishes them only while the GPU is powered: with the GPU off, Tg0e, + * Tg0m and Tg0q read 0 C and Tg0f, Tg0n and Tg0r 4.6 C (they track the + * first three plus a fixed 4.6 C). Those placeholders are no data. + */ +&smc_hwmon { + temperature-Tg0e { + apple,key-id = "Tg0e"; + label = "GPU Tg0e"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0f { + apple,key-id = "Tg0f"; + label = "GPU Tg0f"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0m { + apple,key-id = "Tg0m"; + label = "GPU Tg0m"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0n { + apple,key-id = "Tg0n"; + label = "GPU Tg0n"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0q { + apple,key-id = "Tg0q"; + label = "GPU Tg0q"; + apple,no-data-below-millicelsius = <10000>; + }; + + temperature-Tg0r { + apple,key-id = "Tg0r"; + label = "GPU Tg0r"; + apple,no-data-below-millicelsius = <10000>; + }; +}; /* * Mesa fingerprint sensor on spi2. The J413 platform device tree * (/arm-io/spi2/mesa) describes it as J415's does: power on AP GPIO 178, From 923e129a86a861bd16b2c8a58793d635799719be Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Mon, 2 Nov 2026 02:26:16 -0800 Subject: [PATCH 288/342] serial: apple-dockchannel: Never wait for a reader with apple,tx-never-wait The DockChannel console drains only while a debug USB host reads the channel. With none attached, as on an M5 Ultra Mac Studio (J775D) that boots unattended, the TX FIFO stays full: the write loops spun up to 10000 reads of TX_FREE per character and every close waited for output that could not drain, so boot and every console write stalled. With apple,tx-never-wait, console writes (the driver's and the early console's) send what TX_FREE says fits and drop the rest, tty output is sent from the drain timer and dropped after two ticks without room, a close does not wait, and tx_empty reports empty. Without the property, every other DockChannel Mac's driver and early console behave as before. Testing: J775D boots unattended to its login with nothing reading the channel (the property set), and with a reader attached the console carries the whole boot log. Signed-off-by: Jeff Queisser Co-Authored-By: Claude Opus 5.5 Signed-off-by: Erik Bourget --- drivers/tty/serial/apple_dockchannel.h | 73 +++++++++ .../tty/serial/apple_dockchannel_early_uart.c | 31 +++- drivers/tty/serial/apple_dockchannel_uart.c | 155 +++++++++++++++--- 3 files changed, 226 insertions(+), 33 deletions(-) create mode 100644 drivers/tty/serial/apple_dockchannel.h diff --git a/drivers/tty/serial/apple_dockchannel.h b/drivers/tty/serial/apple_dockchannel.h new file mode 100644 index 0000000000000..97fcccc6a5a57 --- /dev/null +++ b/drivers/tty/serial/apple_dockchannel.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple DockChannel UART: console output shared by the earlycon and the driver. + */ +#ifndef _APPLE_DOCKCHANNEL_H +#define _APPLE_DOCKCHANNEL_H + +#include +#include +#include + +#define DOCKCHANNEL_TX8 0x04 +#define DOCKCHANNEL_TX_FREE 0x14 +#define DOCKCHANNEL_TX_RETRIES 10000 + +/* + * Whether console and tty output never wait for a reader: the DT property + * apple,tx-never-wait on the UART node, which only J775D (t6050-j775d.dts) + * sets, where unattended boots run with nothing reading the channel. Every + * other DockChannel Mac keeps waiting for room as before. Before widening + * it (or making it the default), check on one other DockChannel Mac with a + * slow attached reader (m1n1 proxy, USB debug) that long printk lines and tty + * output still arrive whole. + */ +#define DOCKCHANNEL_NEVER_WAIT "apple,tx-never-wait" + +/* Waiting for room, at most DOCKCHANNEL_TX_RETRIES reads per character. */ +static inline void dockchannel_wait_putc(void __iomem *data, unsigned char c) +{ + unsigned int retries = DOCKCHANNEL_TX_RETRIES; + + while (readl(data + DOCKCHANNEL_TX_FREE) == 0 && --retries) + cpu_relax(); + if (!retries) + return; + + writel(c, data + DOCKCHANNEL_TX8); +} + +/* + * With DOCKCHANNEL_NEVER_WAIT: the channel drains only while a debug USB host + * reads it; with none, the TX FIFO stays full for good. So console output + * never waits for room: each + * write sends what TX_FREE says fits and drops the rest. One write reads + * TX_FREE again when the room it read runs out, and stops reading once it + * reads 0. Callers serialize writes, so the room read stays true. + */ +struct dockchannel_tx { + u32 room; + bool full; +}; + +static inline void dockchannel_tx_begin(struct dockchannel_tx *tx) +{ + tx->room = 0; + tx->full = false; +} + +static inline void dockchannel_console_putc(void __iomem *data, + struct dockchannel_tx *tx, + unsigned char c) +{ + if (!tx->room && !tx->full) { + tx->room = readl(data + DOCKCHANNEL_TX_FREE); + tx->full = !tx->room; + } + if (!tx->room) + return; + tx->room--; + writel(c, data + DOCKCHANNEL_TX8); +} + +#endif diff --git a/drivers/tty/serial/apple_dockchannel_early_uart.c b/drivers/tty/serial/apple_dockchannel_early_uart.c index 1048dde41d794..6c427189d34be 100644 --- a/drivers/tty/serial/apple_dockchannel_early_uart.c +++ b/drivers/tty/serial/apple_dockchannel_early_uart.c @@ -8,22 +8,33 @@ #include #include +#include +#include #include -#define DOCKCHANNEL_TX8 0x04 -#define DOCKCHANNEL_TX_FREE 0x14 -#define DOCKCHANNEL_TX_RETRIES 10000 +#include "apple_dockchannel.h" + +static struct dockchannel_tx dockchannel_early_tx; +static bool dockchannel_early_never_wait; static void dockchannel_uart_putc(struct uart_port *port, unsigned char c) { - unsigned int retries = DOCKCHANNEL_TX_RETRIES; + if (dockchannel_early_never_wait) + dockchannel_console_putc(port->membase, &dockchannel_early_tx, c); + else + dockchannel_wait_putc(port->membase, c); +} - while (readl(port->membase + DOCKCHANNEL_TX_FREE) == 0 && --retries) - cpu_relax(); - if (!retries) - return; +/* The DT's DockChannel UART node asks for DOCKCHANNEL_NEVER_WAIT (flat DT). */ +static bool __init dockchannel_uart_early_never_wait(void) +{ + const void *fdt = initial_boot_params; + int node; - writel(c, port->membase + DOCKCHANNEL_TX8); + if (!fdt) + return false; + node = fdt_node_offset_by_compatible(fdt, -1, "apple,dockchannel-uart"); + return node >= 0 && fdt_getprop(fdt, node, DOCKCHANNEL_NEVER_WAIT, NULL); } static void dockchannel_uart_early_write(struct console *con, const char *s, @@ -31,6 +42,7 @@ static void dockchannel_uart_early_write(struct console *con, const char *s, { struct earlycon_device *dev = con->data; + dockchannel_tx_begin(&dockchannel_early_tx); uart_console_write(&dev->port, s, n, dockchannel_uart_putc); } @@ -42,6 +54,7 @@ static int __init dockchannel_uart_early_setup(struct earlycon_device *device, if (!port->mapbase) return -ENODEV; + dockchannel_early_never_wait = dockchannel_uart_early_never_wait(); device->con->write = dockchannel_uart_early_write; return 0; } diff --git a/drivers/tty/serial/apple_dockchannel_uart.c b/drivers/tty/serial/apple_dockchannel_uart.c index c015d916ac432..d4255cb949848 100644 --- a/drivers/tty/serial/apple_dockchannel_uart.c +++ b/drivers/tty/serial/apple_dockchannel_uart.c @@ -16,6 +16,8 @@ #include #include +#include "apple_dockchannel.h" + #define FIFO_SIZE 0x800 #define IRQ_MASK 0x0 @@ -44,7 +46,13 @@ * that is about 115 bytes per poll, far below the FIFO size. */ #define SW_DRAIN_MS 10 -#define TX_RETRIES 10000 +/* + * TX never waits for FIFO room: what does not fit stays in the xmit buffer + * and the timer sends it as room appears. After this many ticks with no room + * at all, nothing is reading the channel: drop what is queued, so writers do + * not block on a reader that may never come. + */ +#define TX_STUCK_TICKS 2 struct dcuart_port { struct uart_port port; @@ -57,6 +65,12 @@ struct dcuart_port { struct timer_list drain_timer; /* Serializes IRQ mask updates and RX FIFO draining. */ spinlock_t lock; + /* DOCKCHANNEL_NEVER_WAIT: TX never waits for room (J775D only). */ + bool never_wait; + /* One console write's view of the TX FIFO (dockchannel_console_putc). */ + struct dockchannel_tx console_tx; + /* Timer ticks in a row that found TX output queued and no FIFO room. */ + unsigned int tx_stuck_ticks; }; static struct uart_driver dcuart_drv; @@ -97,22 +111,38 @@ static void dcuart_irq_disable(struct dcuart_port *dcuart, u32 bits) static void dcuart_putc(struct uart_port *port, unsigned char c) { - unsigned int retries = TX_RETRIES; + struct dcuart_port *dcuart = container_of(port, struct dcuart_port, port); - while (readl(port->membase + DATA_TX_FREE) == 0 && --retries) - cpu_relax(); - if (!retries) - return; - - writel(c, port->membase + DATA_TX8); + if (dcuart->never_wait) + dockchannel_console_putc(port->membase, &dcuart->console_tx, c); + else + dockchannel_wait_putc(port->membase, c); } static void dcuart_write(struct console *co, const char *s, unsigned int n) { struct dcuart_port *dcuart = dcuart_ports[co->index]; + struct uart_port *port = &dcuart->port; + unsigned long flags; + bool locked = true; + + if (!dcuart->never_wait) { + uart_console_write(port, s, n, dcuart_putc); + return; + } + + /* The TX path writes the same FIFO, and the room read must stay true. */ + if (oops_in_progress) + locked = uart_port_trylock_irqsave(port, &flags); + else + uart_port_lock_irqsave(port, &flags); + + dockchannel_tx_begin(&dcuart->console_tx); + uart_console_write(port, s, n, dcuart_putc); - uart_console_write(&dcuart->port, s, n, dcuart_putc); + if (locked) + uart_port_unlock_irqrestore(port, flags); } static int dcuart_console_setup(struct console *co, char *options) @@ -198,39 +228,106 @@ static irqreturn_t dcuart_interrupt(int irq, void *data) return IRQ_HANDLED; } +/* + * Send what the TX FIFO has room for, without waiting. From the timer (tick), + * also count ticks without room and drop the queue after TX_STUCK_TICKS. + * Called with the port lock held. Returns the bytes left queued. + */ +static unsigned int dcuart_tx_chars(struct dcuart_port *dcuart, bool tick) +{ + struct uart_port *port = &dcuart->port; + struct tty_port *tport = &port->state->port; + unsigned int queued = kfifo_len(&tport->xmit_fifo), pending; + u8 ch; + + if (!queued && !port->x_char) + return 0; + + pending = uart_port_tx_limited(port, ch, readl(port->membase + DATA_TX_FREE), + true, writel(ch, port->membase + DATA_TX8), ({})); + if (!pending || pending < queued) { + dcuart->tx_stuck_ticks = 0; + return pending; + } + if (!tick || ++dcuart->tx_stuck_ticks < TX_STUCK_TICKS) + return pending; + + kfifo_reset_out(&tport->xmit_fifo); + dcuart->tx_stuck_ticks = 0; + uart_write_wakeup(port); + return 0; +} + static void dcuart_drain_timer(struct timer_list *t) { struct dcuart_port *dcuart = timer_container_of(dcuart, t, drain_timer); + struct uart_port *port = &dcuart->port; unsigned long flags; - bool got; + unsigned int pending; - spin_lock_irqsave(&dcuart->lock, flags); - got = dcuart_drain_rx(dcuart); - spin_unlock_irqrestore(&dcuart->lock, flags); + if (!dcuart->never_wait) { + bool got; - if (got) - tty_flip_buffer_push(&dcuart->port.state->port); - mod_timer(&dcuart->drain_timer, jiffies + msecs_to_jiffies(SW_DRAIN_MS)); + spin_lock_irqsave(&dcuart->lock, flags); + got = dcuart_drain_rx(dcuart); + spin_unlock_irqrestore(&dcuart->lock, flags); + + if (got) + tty_flip_buffer_push(&port->state->port); + mod_timer(&dcuart->drain_timer, jiffies + msecs_to_jiffies(SW_DRAIN_MS)); + return; + } + + if (dcuart->sw_drain) { + bool got; + + spin_lock_irqsave(&dcuart->lock, flags); + got = dcuart_drain_rx(dcuart); + spin_unlock_irqrestore(&dcuart->lock, flags); + + if (got) + tty_flip_buffer_push(&port->state->port); + } + + uart_port_lock_irqsave(port, &flags); + pending = dcuart_tx_chars(dcuart, true); + uart_port_unlock_irqrestore(port, flags); + + if (dcuart->sw_drain || pending) + mod_timer(&dcuart->drain_timer, jiffies + msecs_to_jiffies(SW_DRAIN_MS)); } +/* + * Bytes in the FIFO stay there for a host to read whenever it comes; a full + * FIFO means none is reading, not that a transmission is in progress. So + * report empty: a close or tcdrain must not wait for a reader (it waited + * twice the port timeout, 0.4 s, on every close of an unread channel). + */ static unsigned int dcuart_tx_empty(struct uart_port *port) { - return (readl(port->membase + DATA_TX_FREE) != 0) ? - TIOCSER_TEMT : - 0; + if (!port_to_dc(port)->never_wait) + return (readl(port->membase + DATA_TX_FREE) != 0) ? TIOCSER_TEMT : 0; + return TIOCSER_TEMT; } static void dcuart_start_tx(struct uart_port *port) { - char ch; - struct tty_port *tport = &port->state->port; + struct dcuart_port *dcuart = port_to_dc(port); + + if (!dcuart->never_wait) { + struct tty_port *tport = &port->state->port; + char ch; - if (!kfifo_is_empty(&tport->xmit_fifo)) { while (kfifo_get(&tport->xmit_fifo, &ch)) { dcuart_putc(port, ch); port->icount.tx++; } + return; } + + /* The rest goes from the timer, which the RX poll keeps running anyway. */ + if (dcuart_tx_chars(dcuart, false) && !timer_pending(&dcuart->drain_timer)) + mod_timer(&dcuart->drain_timer, jiffies + msecs_to_jiffies(SW_DRAIN_MS)); } static void dcuart_stop_tx(struct uart_port *port) @@ -258,6 +355,14 @@ static int dcuart_startup(struct uart_port *port) struct dcuart_port *dcuart = port_to_dc(port); unsigned long flags; + /* + * A close waits for the xmit buffer to empty, which on an unread + * channel takes until the timer drops it (systemd closes the console + * after every status line: 30 ms each). Never wait for a reader. + */ + if (dcuart->never_wait) + port->state->port.closing_wait = ASYNC_CLOSING_WAIT_NONE; + spin_lock_irqsave(&dcuart->lock, flags); dcuart_irq_disable(dcuart, dcuart->irq_tx | dcuart->irq_rx); writel_relaxed(1, dcuart->config_base + CONFIG_RX_THRESH); @@ -278,9 +383,10 @@ static void dcuart_shutdown(struct uart_port *port) struct dcuart_port *dcuart = port_to_dc(port); unsigned long flags; - if (dcuart->sw_drain) + /* With never_wait the timer also sends TX in IRQ mode. */ + if (dcuart->sw_drain || dcuart->never_wait) timer_delete_sync(&dcuart->drain_timer); - else + if (!dcuart->sw_drain) disable_irq(port->irq); spin_lock_irqsave(&dcuart->lock, flags); @@ -376,6 +482,7 @@ static int dcuart_probe(struct platform_device *pdev) dcuart->irq_tx = IRQ_TX(channel); dcuart->irq_rx = IRQ_RX(channel); dcuart->sw_drain = of_property_read_bool(pdev->dev.of_node, "apple,sw-drain"); + dcuart->never_wait = of_property_read_bool(pdev->dev.of_node, DOCKCHANNEL_NEVER_WAIT); timer_setup(&dcuart->drain_timer, dcuart_drain_timer, 0); dcuart->irq_base = devm_platform_ioremap_resource_byname(pdev, "irq"); From 9bae877594f50061812ed0a4cbb369f984f51939 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:38:05 +1100 Subject: [PATCH 289/342] soc: apple: sep: Remember the logged lock state per user The enclave alternates notifications for the users it knows (the system user 501 and the Linux users), so comparing with the previous notification alone still logged a repeat of each user's state: nine lines on an M2 boot, three of them the same state of user 501. Keep the last logged state of up to four users and log a notification only when it changes that user's state. Assisted-by: LLM Signed-off-by: Ryan Murray --- drivers/soc/apple/sbio.rs | 33 +++++++++++++++++++++++++++++---- drivers/soc/apple/sep.rs | 8 ++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/soc/apple/sbio.rs b/drivers/soc/apple/sbio.rs index b2847c7f96d80..b1f703cf805ab 100644 --- a/drivers/soc/apple/sbio.rs +++ b/drivers/soc/apple/sbio.rs @@ -4360,13 +4360,13 @@ impl SepData { let state = (word >> proto::MSG_TYPE_SHIFT) as u16; let user = (word >> proto::MSG_DATA_SHIFT) as u32; let word = u64::from(state) | (u64::from(user) << 16); - let previous = self.bio_lock_state.xchg(word, Relaxed); + self.bio_lock_state.store(word, Relaxed); self.bio_lock_state_seq.fetch_add(1, Relaxed); let lockout = if state & LOCK_STATE_NEEDS_PASSWORD != 0 { "set" } else { "clear" }; let n = lock_state_names(state); - // The enclave repeats the same state after each query; log a change - // once, and a repeat of the last notification only at debug level. - if previous != word { + // The enclave repeats a user's state after each query; log each + // user's state when it changes, and a repeat only at debug level. + if self.lock_state_changed(word) { dev_info!( self.dev, "sbio: lock state of user {} is {:#06x} (lockout {}:{}{}{}{}{}{}{})\n", @@ -4392,6 +4392,31 @@ impl SepData { self.sbio_wq.notify_all(); } + /// Records `word` (state and user, as in `bio_lock_state`) as the last + /// lock state logged for its user. Returns false if it is that user's + /// last logged state already. A user not in the table takes the slot of + /// one that is, in turn, so a new user is always logged. + fn lock_state_changed(&self, word: u64) -> bool { + let user = word >> 16; + let slots = &self.bio_lock_logged; + let mut free = None; + for (i, slot) in slots.iter().enumerate() { + let seen = slot.load(Relaxed); + if seen == 0 { + free.get_or_insert(i); + } else if seen >> 16 == user { + if seen == word { + return false; + } + slot.store(word, Relaxed); + return true; + } + } + let i = free.unwrap_or_else(|| (self.bio_lock_state_seq.load(Relaxed) as usize) % slots.len()); + slots[i].store(word, Relaxed); + true + } + /// Waits up to `timeout_ms` for a lock-state notification for `user` /// newer than `since` (a `bio_lock_state_seq` value). Returns its state. fn await_lock_state(&self, user: u32, since: u32, timeout_ms: u32) -> Option { diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index ff21f59e65b01..a2bd2d5dfb4c7 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -94,6 +94,9 @@ const SETTLE_MS: time::Msecs = 200; /// Messages on an endpoint without a handler are logged this many times per /// boot; diag/unhandled_messages counts them all. const UNHANDLED_LOG_LIMIT: u32 = 4; +/// Users whose last logged lock state is remembered (a Mac has the system +/// user 501 and one or two Linux users). +pub(crate) const LOCK_STATE_LOG_USERS: usize = 4; const FIRST_RESPONSE_MS: time::Msecs = 3000; const RNG_SURVEY_ATTEMPTS: u32 = 5; @@ -827,6 +830,10 @@ struct SepData { // from a stale one. bio_lock_state: Atomic, bio_lock_state_seq: Atomic, + // The last state logged for each of the most recent users, in the same + // layout, so a repeated notification is not logged again. Notifications + // are handled one at a time, on the receive path. + bio_lock_logged: [Atomic; LOCK_STATE_LOG_USERS], #[pin] store: Mutex>, @@ -1092,6 +1099,7 @@ impl SepData { match_scope_misses: Atomic::new(0), bio_lock_state: Atomic::new(0), bio_lock_state_seq: Atomic::new(0), + bio_lock_logged: [Atomic::new(0), Atomic::new(0), Atomic::new(0), Atomic::new(0)], store <- new_mutex!(store), host_store <- new_mutex!(host_store), xarm <- new_mutex!(XarmState::new()), From 03a7731770cbe862b158aa797d7c622f13de0ebc Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Mon, 9 Nov 2026 22:58:05 +1100 Subject: [PATCH 290/342] dt-bindings: serial: apple,dockchannel-uart: add the T6000 compatible T6000 has the same DockChannel serial channel as T8112: separate data and FIFO configuration windows, a shared interrupt window, and receive data that has to be drained in software. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../devicetree/bindings/serial/apple,dockchannel-uart.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml b/Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml index 5891ba9a6cf13..2583b3a4f7306 100644 --- a/Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml +++ b/Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml @@ -23,6 +23,7 @@ properties: - const: apple,dockchannel-uart - items: - enum: + - apple,t6000-dockchannel-uart - apple,t8112-dockchannel-uart - apple,t6020-dockchannel-uart - apple,t6021-dockchannel-uart From 5624f61ed1cbd13be2cf26f71f7d40a45f8c5d69 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:54:42 +1100 Subject: [PATCH 291/342] soc: apple: add read-only debugfs views of debug registers Add root-only debugfs views of the apple,aic-timebase and apple,debug-dock register blocks: a "regs" file that reads exactly the 32-bit words the reader asks for, and a "snapshot" file that reads the first words of the window between two reads of the arch counter, so a counter in the window can be checked against CNTVCT. The driver writes no device register and requests no interrupt; registers are only read when a file is read. Builds with W=1 and is checkpatch --strict clean. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/Kconfig | 12 +++ drivers/soc/apple/Makefile | 3 + drivers/soc/apple/dbgview.c | 190 ++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 drivers/soc/apple/dbgview.c diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 4639f5b8ab9bf..af4afabca59e0 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -4,6 +4,18 @@ if ARCH_APPLE || COMPILE_TEST menu "Apple SoC drivers" +config APPLE_DBGVIEW + tristate "Apple SoC read-only debug register views" + depends on ARCH_APPLE || COMPILE_TEST + depends on ARM64 && OF && DEBUG_FS + help + Root-only debugfs views of Apple SoC debug register blocks: the + interrupt controller timebase and the debug dock connection + status. The driver only reads registers, and only when a debugfs + file is read. + + Say m here if you debug an Apple SoC. + config APPLE_DOCKCHANNEL tristate "Apple DockChannel FIFO" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 57d06930401c4..4cb853ad128e4 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_APPLE_DBGVIEW) += apple-dbgview.o +apple-dbgview-y = dbgview.o + obj-$(CONFIG_APPLE_DOCKCHANNEL) += apple-dockchannel.o apple-dockchannel-y = dockchannel.o diff --git a/drivers/soc/apple/dbgview.c b/drivers/soc/apple/dbgview.c new file mode 100644 index 0000000000000..f9824df5d18be --- /dev/null +++ b/drivers/soc/apple/dbgview.c @@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple SoC read-only debug register views + * + * Root-only debugfs views of register blocks that only debug tools use: + * + * - apple,aic-timebase: the timebase aperture of the interrupt controller + * - apple,debug-dock: the debug dock connection status register + * + * The driver never writes a device register and requests no interrupt. + * Registers are read only when a debugfs file is read. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static unsigned int snap_bytes = 0x40; +module_param(snap_bytes, uint, 0444); +MODULE_PARM_DESC(snap_bytes, "Bytes of an MMIO view read by its snapshot file"); + +struct dbgview { + void __iomem *base; + resource_size_t size; + struct dentry *dir; +}; + +static struct dentry *dbgview_root; + +static u64 dbgview_cntvct(void) +{ + return __arch_counter_get_cntvct_stable(); +} + +static ssize_t dbgview_regs_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct dbgview *dv = file->private_data; + loff_t pos = *ppos; + size_t len, i; + u32 *buf; + + if (pos < 0 || !IS_ALIGNED(pos, 4)) + return -EINVAL; + if (pos >= dv->size) + return 0; + + len = min_t(size_t, count, dv->size - pos); + len = min_t(size_t, len, PAGE_SIZE); + len = ALIGN_DOWN(len, 4); + if (!len) + return -EINVAL; + + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + for (i = 0; i < len / 4; i++) + buf[i] = readl(dv->base + pos + i * 4); + + if (copy_to_user(ubuf, buf, len)) { + kfree(buf); + return -EFAULT; + } + kfree(buf); + + *ppos = pos + len; + return len; +} + +static const struct file_operations dbgview_regs_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = dbgview_regs_read, + .llseek = default_llseek, +}; + +static int dbgview_snapshot_show(struct seq_file *s, void *unused) +{ + struct dbgview *dv = s->private; + size_t words = min_t(size_t, snap_bytes, dv->size) / 4; + unsigned long flags; + u64 before, after; + u32 *val; + size_t i; + + val = kzalloc_objs(*val, max_t(size_t, words, 1)); + if (!val) + return -ENOMEM; + + /* Bracket the reads by the arch counter with nothing in between. */ + local_irq_save(flags); + before = dbgview_cntvct(); + for (i = 0; i < words; i++) + val[i] = readl(dv->base + i * 4); + after = dbgview_cntvct(); + local_irq_restore(flags); + + seq_printf(s, "cntvct_before %016llx\n", before); + for (i = 0; i < words; i++) + seq_printf(s, "%04zx %08x\n", i * 4, val[i]); + seq_printf(s, "cntvct_after %016llx\n", after); + seq_printf(s, "cntfrq %u\n", arch_timer_get_cntfrq()); + + kfree(val); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(dbgview_snapshot); + +static int dbgview_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct dbgview *dv; + + dv = devm_kzalloc(dev, sizeof(*dv), GFP_KERNEL); + if (!dv) + return -ENOMEM; + + dv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(dv->base)) + return PTR_ERR(dv->base); + dv->size = resource_size(res); + + dv->dir = debugfs_create_dir(dev_name(dev), dbgview_root); + + debugfs_create_file_size("regs", 0400, dv->dir, dv, + &dbgview_regs_fops, dv->size); + debugfs_create_file("snapshot", 0400, dv->dir, dv, + &dbgview_snapshot_fops); + + platform_set_drvdata(pdev, dv); + return 0; +} + +static void dbgview_remove(struct platform_device *pdev) +{ + struct dbgview *dv = platform_get_drvdata(pdev); + + debugfs_remove_recursive(dv->dir); +} + +static const struct of_device_id dbgview_of_match[] = { + { .compatible = "apple,aic-timebase" }, + { .compatible = "apple,debug-dock" }, + { } +}; +MODULE_DEVICE_TABLE(of, dbgview_of_match); + +static struct platform_driver dbgview_driver = { + .driver = { + .name = "apple-dbgview", + .of_match_table = dbgview_of_match, + }, + .probe = dbgview_probe, + .remove = dbgview_remove, +}; + +static int __init dbgview_init(void) +{ + int ret; + + dbgview_root = debugfs_create_dir("apple-dbgview", NULL); + ret = platform_driver_register(&dbgview_driver); + if (ret) + debugfs_remove_recursive(dbgview_root); + return ret; +} +module_init(dbgview_init); + +static void __exit dbgview_exit(void) +{ + platform_driver_unregister(&dbgview_driver); + debugfs_remove_recursive(dbgview_root); +} +module_exit(dbgview_exit); + +MODULE_AUTHOR("Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>"); +MODULE_DESCRIPTION("Apple SoC read-only debug register views"); +MODULE_LICENSE("Dual MIT/GPL"); From cae57aa17f8c90b8792b06cb4b8aae46c080c4f9 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:54:53 +1100 Subject: [PATCH 292/342] arm64: dts: apple: t8112: expose the DockChannel UART and AIC timebase Enable the DebugUSB DockChannel serial channel as a second, non-console serial port (ttyDC), and the AIC timebase aperture. The console stays on the S5L UART: stdout-path is unchanged, and the DockChannel port is only opened by a user. Tested on J413: ttyDC0 bound and not a console, a TX marker reaches the host, and the timebase word at 0x20 tracks CNTVCT at a 1.0 ratio. The full suite (12 sleep cycles, 3 s2idle RTC wakes) showed no change against the default kernel. dtc W=1 and CHECK_DTBS report nothing for the changed nodes. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-peripherals.dtsi | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi index c370343fcb668..db97f50178b28 100644 --- a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi @@ -89,7 +89,6 @@ m2_aic_timebase: timer@23b0dc000 { compatible = "apple,t8112-aic-timebase", "apple,aic-timebase"; reg = <0x2 0x3b0dc000 0x0 0x1000>; - status = "disabled"; }; m2_dwi: dwi@23b200000 { @@ -147,7 +146,6 @@ <0x2 0x3d10c000 0x0 0x1000>; interrupt-parent = <&aic>; interrupts = ; - status = "disabled"; apple,sw-drain; }; From 4e50830ecb40905838e56051bf3bb91e7aef464b Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:54:55 +1100 Subject: [PATCH 293/342] arm64: dts: apple: t600x: describe the DockChannel UART as a serial port The DockChannel block at 0x29250c000 carries the DebugUSB serial channel; it has no FIFO bus consumer on these SoCs. Describe it as an apple,dockchannel-uart with its data, FIFO configuration and interrupt windows and software RX drain. On T6000, enable it as a non-console serial port (ttyDC) and enable the AIC timebase aperture. T6001 and T6002 keep the port disabled. Tested on J316s: ttyDC0 bound and not a console, a TX marker reaches the host, and the timebase word at 0x20 tracks CNTVCT at a 1.0 ratio. dtc W=1 and CHECK_DTBS report nothing for the changed nodes. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../boot/dts/apple/t6000-peripherals.dtsi | 21 ++++++++----------- .../boot/dts/apple/t6001-peripherals.dtsi | 17 +++++++-------- .../boot/dts/apple/t6002-peripherals.dtsi | 17 +++++++-------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi index 8dbf14d92da28..0700ad51ec3c1 100644 --- a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT -/* Disabled resource descriptions for T6000. */ +/* Additional T6000 hardware resources. Keep unqualified blocks disabled. */ &{/soc} { ane0_dma: dma-controller@285804000 { @@ -14,7 +14,6 @@ aic_timebase: timer@28e148000 { compatible = "apple,t6000-aic-timebase", "apple,aic-timebase"; reg = <0x2 0x8e148000 0x0 0x1000>; - status = "disabled"; }; dwi: bus-controller@28e208000 { @@ -26,18 +25,16 @@ status = "disabled"; }; - dockchannel_uart: fifo@29250c000 { - compatible = "apple,t6000-dockchannel", "apple,dockchannel"; - reg = <0x2 0x9250c000 0x0 0x18>; + /* The DebugUSB DockChannel serial channel; RX is drained in software. */ + dockchannel_uart: serial@29252c000 { + compatible = "apple,t6000-dockchannel-uart", "apple,dockchannel-uart"; + reg = <0x2 0x9252c000 0x0 0x4000>, + <0x2 0x92528000 0x0 0x4000>, + <0x2 0x9250c000 0x0 0x18>; + reg-names = "data", "config", "irq"; interrupt-parent = <&aic>; interrupts = ; - reg-names = "irq"; - ranges = <0 0x2 0x92528000 0x10004>; - #address-cells = <1>; - #size-cells = <1>; - interrupt-controller; - #interrupt-cells = <2>; - status = "disabled"; + apple,sw-drain; }; apr0: video-codec@311000000 { diff --git a/arch/arm64/boot/dts/apple/t6001-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6001-peripherals.dtsi index 51b94d55a5a9b..8184537da866e 100644 --- a/arch/arm64/boot/dts/apple/t6001-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6001-peripherals.dtsi @@ -26,17 +26,16 @@ status = "disabled"; }; - dockchannel_uart: fifo@29250c000 { - compatible = "apple,t6000-dockchannel", "apple,dockchannel"; - reg = <0x2 0x9250c000 0x0 0x18>; + /* The DebugUSB DockChannel serial channel; RX is drained in software. */ + dockchannel_uart: serial@29252c000 { + compatible = "apple,t6000-dockchannel-uart", "apple,dockchannel-uart"; + reg = <0x2 0x9252c000 0x0 0x4000>, + <0x2 0x92528000 0x0 0x4000>, + <0x2 0x9250c000 0x0 0x18>; + reg-names = "data", "config", "irq"; interrupt-parent = <&aic>; interrupts = ; - reg-names = "irq"; - ranges = <0 0x2 0x92528000 0x10004>; - #address-cells = <1>; - #size-cells = <1>; - interrupt-controller; - #interrupt-cells = <2>; + apple,sw-drain; status = "disabled"; }; diff --git a/arch/arm64/boot/dts/apple/t6002-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6002-peripherals.dtsi index ba6616910477e..ad89730134583 100644 --- a/arch/arm64/boot/dts/apple/t6002-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6002-peripherals.dtsi @@ -26,17 +26,16 @@ status = "disabled"; }; - dockchannel_uart: fifo@29250c000 { - compatible = "apple,t6000-dockchannel", "apple,dockchannel"; - reg = <0x2 0x9250c000 0x0 0x18>; + /* The DebugUSB DockChannel serial channel; RX is drained in software. */ + dockchannel_uart: serial@29252c000 { + compatible = "apple,t6000-dockchannel-uart", "apple,dockchannel-uart"; + reg = <0x2 0x9252c000 0x0 0x4000>, + <0x2 0x92528000 0x0 0x4000>, + <0x2 0x9250c000 0x0 0x18>; + reg-names = "data", "config", "irq"; interrupt-parent = <&aic>; interrupts = ; - reg-names = "irq"; - ranges = <0 0x2 0x92528000 0x10004>; - #address-cells = <1>; - #size-cells = <1>; - interrupt-controller; - #interrupt-cells = <2>; + apple,sw-drain; status = "disabled"; }; From dbe881e3847a30413d68d14762ad4842aaac7171 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:31:48 +1100 Subject: [PATCH 294/342] drm/asahi: finish an exiting client's work before its mappings go Killing a Vulkan client with rendering in flight on T8112 (and once on T6000) gave a firmware timeout with a read fault on an unmapped address of the client's VM (UL1C or dVDM_CSD), then recovery. SIGTERM of gpubench-vk render.heavy fill 1080p at depth 4 reproduces it on the first try. The legacy (G13/G14) VMs carry no job lifetime. When the client's DRM file goes away, DRM first closes its GEM handles, and closing a handle unmaps the object from the client's VMs at once; File then drops the VMs, which unmaps the rest of the user range, before its queues. All of it happens while the client's jobs still run in the firmware. Give the queue trait a drain() hook. The legacy queue waits there, for at most 5 s, on the finished fence of its last submitted job; the jobs of one queue complete in order, so that fence covers all of them. The first GEM handle close of an exiting task drains every queue of the file once, and the queues now drop before the VMs and wait the same way (also when destroyed by ioctl). G15 and later VMs keep user mappings until their jobs release them, so their queues keep the no-op drain. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/gpu/drm/asahi/file.rs | 46 ++++++++++++++++++++++++++-- drivers/gpu/drm/asahi/queue/mod.rs | 48 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/file.rs b/drivers/gpu/drm/asahi/file.rs index 244dca39e41ac..3778ee5a4aa68 100644 --- a/drivers/gpu/drm/asahi/file.rs +++ b/drivers/gpu/drm/asahi/file.rs @@ -33,6 +33,7 @@ use core::mem::MaybeUninit; use core::ops::Deref; use core::ops::Range; use core::ptr::addr_of_mut; +use core::sync::atomic::{AtomicBool, Ordering}; use kernel::bindings; use kernel::dma_fence::RawDmaFence; use kernel::drm::gem::BaseObject; @@ -269,16 +270,20 @@ pub(crate) struct File { id: u64, /// Available VM range for the user user_range: Range, - // #[pin] - vms: xarray::XArray>, + // Fields drop in order: the queues go first, so that a closing client's submitted work + // can finish before its VMs unmap the user ranges. // #[pin] queues: xarray::XArray>>>, // #[pin] + vms: xarray::XArray>, + // #[pin] objects: xarray::XArray>, /// GPU memory this client created and holds. mem: Arc, /// Completed engine time, retained by queues after handle destruction. usage: Arc, + /// The queues were drained once for an exiting task. + drained: AtomicBool, } /// Convenience type alias for our DRM `File` type. @@ -371,6 +376,7 @@ impl File { (*slot).user_range = user_range; addr_of_mut!((*slot).mem).write(mem); addr_of_mut!((*slot).usage).write(usage); + addr_of_mut!((*slot).drained).write(AtomicBool::new(false)); Ok(()) }) } @@ -1151,7 +1157,43 @@ impl File { Ok(0) } + /// Waits for the submitted work of every queue of `file`, once, when its task exits. + /// + /// An exiting or killed client's DRM file closes its GEM handles before the driver sees + /// the file go, and closing a handle unmaps the object at once from VMs that do not track + /// jobs (G13/G14). Work the client left running would then fault on the unmapped memory + /// and time out in the firmware. A live client unmaps only what its work no longer uses. + fn drain_queues_on_exit(file: &DrmFile) { + // SAFETY: `current` is valid for the running task. + let exiting = + unsafe { (*kernel::task::Task::current_raw()).flags } & bindings::PF_EXITING != 0; + if !exiting || file.inner().drained.swap(true, Ordering::AcqRel) { + return; + } + let mut index = 0; + loop { + // Clone since we can't hold the xarray spinlock while waiting. + let Some((idx, queue)) = + file.inner() + .queues() + .find(index, usize::MAX) + .map(|(idx, guard)| { + let queue: Arc>> = guard.borrow().into(); + (idx, queue) + }) + else { + break; + }; + queue.lock().drain(); + if idx == usize::MAX { + break; + } + index = idx + 1; + } + } + pub(crate) fn unbind_gem_object(file: &DrmFile, bo: &gem::Object) -> Result { + Self::drain_queues_on_exit(file); // TODO: use iter() let mut index = 0; loop { diff --git a/drivers/gpu/drm/asahi/queue/mod.rs b/drivers/gpu/drm/asahi/queue/mod.rs index aa5dc1fba4723..b82abf9602762 100644 --- a/drivers/gpu/drm/asahi/queue/mod.rs +++ b/drivers/gpu/drm/asahi/queue/mod.rs @@ -82,6 +82,10 @@ pub(crate) trait Queue: Send + Sync { cmdbuf_raw: &[u8], objects: Pin<&xarray::XArray>>, ) -> Result; + + /// Waits for the work submitted so far to finish, before the mappings of a closing + /// client go. Queues whose VMs keep user mappings for accepted jobs need not wait. + fn drain(&mut self) {} } #[versions(AGX)] @@ -142,6 +146,8 @@ pub(crate) struct Queue { fence_ctx: FenceContexts, inner: QueueInner::ver, stats: Arc, + /// Finished fence of the last submitted job, waited for when the queue goes away. + last_out: Option, } #[versions(AGX)] @@ -551,6 +557,7 @@ impl Queue::ver { q_comp: None, fence_ctx: FenceContexts::new(1, QUEUE_NAME, QUEUE_CLASS_KEY)?, stats, + last_out: None, inner: QueueInner::ver { dev: dev.clone(), ualloc, @@ -680,8 +687,40 @@ fn build_attachments(reader: &mut Reader<'_>, size: usize) -> Result( &mut self, reg_data: &AsahiRegData<'drm>, @@ -1008,6 +1047,7 @@ impl Queue for Queue::ver { mod_dev_dbg!(self.dev, "Queue {}: Arming job {}\n", self.inner.id, job.id); let mut job = job.arm(); let out_fence = job.fences().finished(); + self.last_out = Some(out_fence.clone()); mod_dev_dbg!( self.dev, "Queue {}: Pushing job {}\n", @@ -1039,5 +1079,13 @@ impl Queue for Queue::ver { impl Drop for Queue::ver { fn drop(&mut self) { mod_dev_dbg!(self.dev, "[Queue {}] Dropping queue\n", self.inner.id); + // A client that exits or is killed drops its queues with jobs still queued or running + // on the GPU, and its VMs right after (see `file::File`). Those VMs do not track jobs: + // dropping one unmaps the user range at once, and the firmware then faults on the + // next access of the running job and times out. Let the submitted work finish first. + self.wait_submitted(); } } + +/// How long a closing queue waits for its submitted work to finish. +const QUEUE_CLOSE_WAIT_MS: u32 = 5000; From 10b32030d2b92b0ee2f137e8836a5c321518df7f Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:00:51 +1100 Subject: [PATCH 295/342] soc: apple: Add read-only register views The memory cache controller has no functional driver on T8112 and T6000, but its carveout and cache status registers are useful when studying the hardware. Add a driver that exposes a fixed list of registers per block as a root-only debugfs file under /sys/kernel/debug/apple-regview//regs. It never writes to the hardware and does not request the memory regions, since other drivers may own parts of the same windows. The list for the memory cache controller on T8112 and T6000 holds the carveout start, end and enable registers of plane 0 and the cache status register of every plane. The boot loader reads these registers on every boot of these SoCs, so reading them is known to be harmless. Tested with a W=1 build, in tree and as an out-of-tree module against a 7.3 kernel. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- drivers/soc/apple/Kconfig | 12 ++ drivers/soc/apple/Makefile | 3 + drivers/soc/apple/regview.c | 237 ++++++++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 drivers/soc/apple/regview.c diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 4639f5b8ab9bf..6081f8ad5c35b 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -238,6 +238,18 @@ config APPLE_T8132_PLATFORM_KUNIT_TEST tree without enabling any Apple hardware drivers. These tests only read metadata and never access the described MMIO resources. +config APPLE_REGVIEW + tristate "Apple SoC read-only register views" + depends on ARCH_APPLE || COMPILE_TEST + depends on OF && DEBUG_FS + help + Exposes fixed lists of registers of Apple SoC blocks that have no + functional driver, such as the memory cache controller, as + read-only files under /sys/kernel/debug/apple-regview. The driver never writes to these + blocks. Only registers known to be safe to read are listed. + + This is a development aid. If unsure, say 'n'. + config APPLE_CLPC tristate "Apple host performance controller floors" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 57d06930401c4..a98ceda2fdd5f 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -56,4 +56,7 @@ apple-mcc-y := mcc.o obj-$(CONFIG_APPLE_CLPC) += clpc.o +obj-$(CONFIG_APPLE_REGVIEW) += apple-regview.o +apple-regview-y := regview.o + obj-$(CONFIG_APPLE_SART_APIF) += apple-sart-apif.o diff --git a/drivers/soc/apple/regview.c b/drivers/soc/apple/regview.c new file mode 100644 index 0000000000000..9bbd6fbf277e8 --- /dev/null +++ b/drivers/soc/apple/regview.c @@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple SoC read-only register views + * + * Exposes fixed, per-block lists of 32-bit registers through debugfs so that + * blocks without a functional driver can be inspected. The driver never + * writes to the hardware. Each list names only registers that are known to + * be safe to read: + * + * - memory cache controller (T8112, T6000): the carveout bounds and enables + * of plane 0 and the cache status of every plane. The boot loader reads + * exactly these registers on every boot of these SoCs. + * + * Copyright The Asahi Linux Contributors + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* One run of 32-bit registers inside one DT reg entry. */ +struct apple_regview_range { + u8 reg; /* index into the node's reg property */ + u32 offset; /* byte offset from the start of that entry */ + u32 count; /* number of 32-bit registers */ + u32 stride; /* byte distance between registers; 0 means 4 */ + const char *name; +}; + +struct apple_regview_hw { + const struct apple_regview_range *ranges; + unsigned int nr_ranges; + unsigned int nr_regs; /* reg entries the node must have */ +}; + +struct apple_regview_map { + void __iomem *base; + resource_size_t size; +}; + +static struct dentry *apple_regview_root; + +struct apple_regview { + struct device *dev; + const struct apple_regview_hw *hw; + struct apple_regview_map *maps; + struct dentry *dir; +}; + +#define MCC_PLANE_STRIDE 0x40000 +#define MCC_PLANE_CACHE_STATUS 0x1c04 +#define MCC_TZ_BASE 0x6a0 +#define MCC_TZ_STRIDE 0x10 +#define MCC_TZ_REGIONS 4 + +/* + * Plane 0 carveout start, end and enable of each region, then the cache + * status of each plane. + */ +static const struct apple_regview_range apple_regview_t8112_mcc[] = { + /* T8112: reg[1] holds the four planes. */ + { 1, MCC_TZ_BASE + 0x0, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-start" }, + { 1, MCC_TZ_BASE + 0x4, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-end" }, + { 1, MCC_TZ_BASE + 0x8, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-enable" }, + { 1, MCC_PLANE_CACHE_STATUS, 4, MCC_PLANE_STRIDE, "cache-status" }, +}; + +static const struct apple_regview_hw apple_regview_t8112_mcc_hw = { + .ranges = apple_regview_t8112_mcc, + .nr_ranges = ARRAY_SIZE(apple_regview_t8112_mcc), + .nr_regs = 2, +}; + +/* T6000: one reg entry per controller, each with four planes at offset 0. */ +static const struct apple_regview_range apple_regview_t6000_mcc[] = { + { 0, MCC_TZ_BASE + 0x0, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-start" }, + { 0, MCC_TZ_BASE + 0x4, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-end" }, + { 0, MCC_TZ_BASE + 0x8, MCC_TZ_REGIONS, MCC_TZ_STRIDE, "tz-enable" }, + { 0, MCC_PLANE_CACHE_STATUS, 4, MCC_PLANE_STRIDE, "cache-status" }, + { 1, MCC_PLANE_CACHE_STATUS, 4, MCC_PLANE_STRIDE, "cache-status" }, + { 2, MCC_PLANE_CACHE_STATUS, 4, MCC_PLANE_STRIDE, "cache-status" }, + { 3, MCC_PLANE_CACHE_STATUS, 4, MCC_PLANE_STRIDE, "cache-status" }, +}; + +static const struct apple_regview_hw apple_regview_t6000_mcc_hw = { + .ranges = apple_regview_t6000_mcc, + .nr_ranges = ARRAY_SIZE(apple_regview_t6000_mcc), + .nr_regs = 4, +}; + +static u32 apple_regview_stride(const struct apple_regview_range *r) +{ + return r->stride ? r->stride : 4; +} + +static int apple_regview_check(const struct apple_regview *rv) +{ + const struct apple_regview_hw *hw = rv->hw; + unsigned int i; + + for (i = 0; i < hw->nr_ranges; i++) { + const struct apple_regview_range *r = &hw->ranges[i]; + u64 last; + + if (r->reg >= hw->nr_regs || !r->count) + return -EINVAL; + last = r->offset + (u64)(r->count - 1) * apple_regview_stride(r) + 4; + if (last > rv->maps[r->reg].size) + return -EINVAL; + } + + return 0; +} + +static int apple_regview_show(struct seq_file *s, void *unused) +{ + struct apple_regview *rv = s->private; + const struct apple_regview_hw *hw = rv->hw; + unsigned int i, j; + + for (i = 0; i < hw->nr_ranges; i++) { + const struct apple_regview_range *r = &hw->ranges[i]; + const struct apple_regview_map *map = &rv->maps[r->reg]; + u32 stride = apple_regview_stride(r); + + for (j = 0; j < r->count; j++) { + u32 off = r->offset + j * stride; + + seq_printf(s, "%u+0x%07x %s[%u]: 0x%08x\n", + r->reg, off, r->name, j, + readl_relaxed(map->base + off)); + } + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(apple_regview); + +static void apple_regview_remove_debugfs(void *data) +{ + debugfs_remove_recursive(data); +} + +static int apple_regview_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct apple_regview *rv; + unsigned int i; + int ret; + + rv = devm_kzalloc(dev, sizeof(*rv), GFP_KERNEL); + if (!rv) + return -ENOMEM; + + rv->dev = dev; + rv->hw = of_device_get_match_data(dev); + if (!rv->hw) + return -ENODEV; + + rv->maps = devm_kcalloc(dev, rv->hw->nr_regs, sizeof(*rv->maps), + GFP_KERNEL); + if (!rv->maps) + return -ENOMEM; + + for (i = 0; i < rv->hw->nr_regs; i++) { + struct resource res; + + ret = of_address_to_resource(dev->of_node, i, &res); + if (ret) + return dev_err_probe(dev, ret, "missing reg %u\n", i); + if (resource_size(&res) & 3) + return dev_err_probe(dev, -EINVAL, "reg %u not word sized\n", i); + + /* + * Mapping does not touch the hardware. Other drivers may own + * parts of these windows, so they are not requested. + */ + rv->maps[i].base = devm_ioremap(dev, res.start, resource_size(&res)); + if (!rv->maps[i].base) + return -ENOMEM; + rv->maps[i].size = resource_size(&res); + } + + ret = apple_regview_check(rv); + if (ret) + return dev_err_probe(dev, ret, "register list exceeds the apertures\n"); + + rv->dir = debugfs_create_dir(dev_name(dev), apple_regview_root); + debugfs_create_file("regs", 0400, rv->dir, rv, &apple_regview_fops); + + return devm_add_action_or_reset(dev, apple_regview_remove_debugfs, + rv->dir); +} + +static const struct of_device_id apple_regview_of_match[] = { + { .compatible = "apple,t8112-mcc", .data = &apple_regview_t8112_mcc_hw }, + { .compatible = "apple,t6000-mcc", .data = &apple_regview_t6000_mcc_hw }, + {} +}; +MODULE_DEVICE_TABLE(of, apple_regview_of_match); + +static struct platform_driver apple_regview_driver = { + .driver = { + .name = "apple-regview", + .of_match_table = apple_regview_of_match, + }, + .probe = apple_regview_probe, +}; + +static int __init apple_regview_init(void) +{ + int ret; + + apple_regview_root = debugfs_create_dir("apple-regview", NULL); + ret = platform_driver_register(&apple_regview_driver); + if (ret) + debugfs_remove_recursive(apple_regview_root); + return ret; +} +module_init(apple_regview_init); + +static void __exit apple_regview_exit(void) +{ + platform_driver_unregister(&apple_regview_driver); + debugfs_remove_recursive(apple_regview_root); +} +module_exit(apple_regview_exit); + +MODULE_DESCRIPTION("Apple SoC read-only register views"); +MODULE_LICENSE("Dual MIT/GPL"); From 3013fe0e4259d52caaf2d4d2223db5b810fb2386 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:00:52 +1100 Subject: [PATCH 296/342] arm64: dts: apple: t8112, t6000: Enable the MCC node Let the read-only register view bind to the memory cache controller. Tested on J413 and J316s: the view binds, every listed register reads back stable across reads, the carveouts and cache status match what the boot loader set up, and the test suite (J413: full, with 12 sleep cycles; J316s: quick) shows no change against the default kernel. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t6000-peripherals.dtsi | 1 - arch/arm64/boot/dts/apple/t8112-peripherals.dtsi | 1 - 2 files changed, 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi index 8dbf14d92da28..633ecabec7d30 100644 --- a/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6000-peripherals.dtsi @@ -249,7 +249,6 @@ <0x2 0x01000000 0x0 0x1000000>, <0x2 0x02000000 0x0 0x1000000>, <0x2 0x03000000 0x0 0x1000000>; - status = "disabled"; }; soc_events: event-log@28e080000 { diff --git a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi index c370343fcb668..4126826bbaa4f 100644 --- a/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8112-peripherals.dtsi @@ -51,7 +51,6 @@ <0x2 0x1000000 0x0 0x2000000>, <0x2 0xf00000 0x0 0x100000>, <0x2 0x3b3c0000 0x0 0x20000>; - status = "disabled"; }; m2_aft: fabric-tracker@200110000 { From e2f51c7ae111f49ea1173806de5dba88b7070a27 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:05:47 +1100 Subject: [PATCH 297/342] arm64: dts: apple: t600x-j314-j316: document the I2C4 0x20 client as do-not-touch The I2C4 client at 0x20 is unidentified, and a bare read of an unknown device can change its state. Say in the DT that it stays disabled and is never probed, scanned or read; SD card detection does not use it. No change to the compiled DTB. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t600x-j314-j316-control.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t600x-j314-j316-control.dtsi b/arch/arm64/boot/dts/apple/t600x-j314-j316-control.dtsi index 39de40bcac695..e4415e7d9d405 100644 --- a/arch/arm64/boot/dts/apple/t600x-j314-j316-control.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-j314-j316-control.dtsi @@ -2,6 +2,11 @@ /* Populated board control clients. Transport ownership is not transferred. */ &i2c4 { + /* + * Unidentified client: a bare read may change its state. Keep it + * disabled, and never probe, scan or read address 0x20. SD card + * detection does not use it. + */ sd_card_control: sd-card-control@20 { compatible = "apple,t6000-sd-card-control", "apple,sd-card-control"; reg = <0x20>; From 0bc4f95b94c073af04a68b2f9eb77954067220b1 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:25:19 +1100 Subject: [PATCH 298/342] arm64: dts: apple: adt-coverage: t6000-j316s: map the DockChannel UART to its serial node The DockChannel block is now described as serial@29252c000, so the coverage manifest points the ADT dockchannel-uart node there. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt b/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt index 5baa84eeaa229..d1064fbbb2a0d 100644 --- a/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt +++ b/arch/arm64/boot/dts/apple/adt-coverage/t6000-j316s.txt @@ -566,7 +566,7 @@ /arm-io/smc/iop-smc-nub/smc-charger-util - -> /soc/smc@290400000 /arm-io/uart0 0x39b200000 -> /soc/serial@39b200000 /arm-io/uart0/debug-console - -> /soc/serial@39b200000 -/arm-io/dockchannel-uart 0x29250c000 -> /soc/fifo@29250c000 +/arm-io/dockchannel-uart 0x29250c000 -> /soc/serial@29252c000 /arm-io/spi1 0x39b104000 -> /soc/spi@39b104000 /arm-io/spi1/spinor /arm-io/spi1@0x0 -> /soc/spi@39b104000/flash@0 /arm-io/spi1/spinor/firmware - -> WAIVED: Firmware flash partition; parent flash hardware is inventoried separately. From c8b611e112433b6201b97e8557fd01b20322a332 Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:19 -0400 Subject: [PATCH 299/342] net: apple: Add T6050 N1 firmware and ACIPC transport Keep this transport alongside the current J813/J873 implementation. Select it only for a T6050 host, with separate objects and private helper names so both implementations can be built and registered together. Boot the N1 firmware and expose its shared ACIPC transport behind the T6050 PCIe host. After the ROM boot, isolate and quiesce function 0, put it in D3hot with PME enabled, let the host's root-port reset take the link through L2, PERST# and retraining, then restore the root port's and the endpoint's state. Keep firmware and calibration as external inputs, and retain supplier lifetime for the separate Wi-Fi and Bluetooth consumers. Source snapshot: t6050-gpu ee68abb105200e99636a5edfc647a5cfc1d89954 Integration base: 9cbdd0734d9e186c5f5f5949a21b909d10c2571b Signed-off-by: Dj Co-developed-by: Jeff Queisser Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/net/wireless/apple,centauri.yaml | 4 +- drivers/net/wireless/apple/Kconfig | 12 + drivers/net/wireless/apple/Makefile | 2 +- drivers/net/wireless/apple/centauri/Makefile | 1 + .../wireless/apple/centauri/centauri_pci.c | 6 + .../wireless/apple/centauri/t6050/Makefile | 4 + .../apple/centauri/t6050/centauri_ipc.c | 519 ++++++++++++++++++ .../apple/centauri/t6050/centauri_pci.c | 428 +++++++++++++++ .../apple/centauri/t6050/centauri_t6050.h | 87 +++ 9 files changed, 1060 insertions(+), 3 deletions(-) create mode 100644 drivers/net/wireless/apple/centauri/t6050/Makefile create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_pci.c create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h diff --git a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml index 4e46c3573edbf..f73dd9afceca1 100644 --- a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml +++ b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml @@ -13,8 +13,8 @@ description: | PCI function zero owns the shared N1 firmware bootstrap. The boot producer supplies the personalized FTAB filename and packed firmware platform ID. The endpoint must be left in its stopped ROM personality with DMA and MSI - quiesced. A supported APIF PCI host performs the isolated port reset after - ROM bootstrap. This binding does not authorize adopting an existing live + quiesced. The host's root-port reset retrains the link after the ROM + bootstrap. This binding does not authorize adopting an existing live firmware session or releasing another owner's retained DART streams. properties: diff --git a/drivers/net/wireless/apple/Kconfig b/drivers/net/wireless/apple/Kconfig index d3ead4d9259e7..344099f427c5e 100644 --- a/drivers/net/wireless/apple/Kconfig +++ b/drivers/net/wireless/apple/Kconfig @@ -22,4 +22,16 @@ config APPLE_CENTAURI This driver does not include Bluetooth HCI support. To build as a module, choose M; the module is apple_centauri. + +config APPLE_CENTAURI_T6050 + tristate "Apple N1 Centauri T6050 firmware and IPC transport" + depends on ARCH_APPLE || COMPILE_TEST + depends on PCI && CFG80211 && PCIE_APPLE + select FW_LOADER + help + Boot the N1 firmware on a T6050 host that provides root-port reset. + The transport starts automatically from its device-tree firmware, + platform and protocol properties. It binds only behind a T6050 host; + the J813/J873 transport remains available independently. + endif diff --git a/drivers/net/wireless/apple/Makefile b/drivers/net/wireless/apple/Makefile index ca72cd0b4da06..969c58e0ebe98 100644 --- a/drivers/net/wireless/apple/Makefile +++ b/drivers/net/wireless/apple/Makefile @@ -1,2 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_APPLE_CENTAURI) += centauri/ +obj-y += centauri/ diff --git a/drivers/net/wireless/apple/centauri/Makefile b/drivers/net/wireless/apple/centauri/Makefile index 1a17e5283e227..235e1090294dc 100644 --- a/drivers/net/wireless/apple/centauri/Makefile +++ b/drivers/net/wireless/apple/centauri/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_CENTAURI) += apple_centauri.o apple_centauri-y := centauri_pci.o centauri_port.o centauri_ipc.o centauri_wifi.o +obj-$(CONFIG_APPLE_CENTAURI_T6050) += t6050/ diff --git a/drivers/net/wireless/apple/centauri/centauri_pci.c b/drivers/net/wireless/apple/centauri/centauri_pci.c index 86ad99c48db2e..57fefbc840c6f 100644 --- a/drivers/net/wireless/apple/centauri/centauri_pci.c +++ b/drivers/net/wireless/apple/centauri/centauri_pci.c @@ -197,6 +197,12 @@ static int centauri_probe(struct pci_dev *pdev, const struct pci_device_id *id) dma_addr_t dma; void *page; int ret; + struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); + + /* The T6050 transport owns every function behind an adopted host. */ + if (bridge && bridge->dev.parent && + of_device_is_compatible(bridge->dev.parent->of_node, "apple,t6050-pcie")) + return -ENODEV; c = devm_kzalloc(&pdev->dev, sizeof(*c), GFP_KERNEL); if (!c) diff --git a/drivers/net/wireless/apple/centauri/t6050/Makefile b/drivers/net/wireless/apple/centauri/t6050/Makefile new file mode 100644 index 0000000000000..ec75629ea1272 --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_APPLE_CENTAURI_T6050) += apple_centauri_t6050.o +apple_centauri_t6050-y := centauri_pci.o centauri_ipc.o +apple_centauri_t6050-$(CONFIG_APPLE_CENTAURI_T6050_WIFI) += centauri_wifi.o diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c b/drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c new file mode 100644 index 0000000000000..2ff1fbf61b85a --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_ipc.c @@ -0,0 +1,519 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "centauri_t6050.h" + +struct cen_buffer { + struct list_head list; + struct device *owner; + void *cpu; + dma_addr_t dma; + size_t size; +}; + +struct cen_context { + struct cen_buffer *buffer, *messages; + u32 index[4], mtr, mcr; + u16 tr_count, cr_count, message_head; +}; + +struct centauri_t6050_ipc { + struct list_head buffers; + struct pci_dev *function[3]; + bool enabled[3], owned[3]; + bool alpha_pm_domain; + void __iomem *bar[3]; + struct cen_context control, alpha; + struct cen_buffer *secondary, *window, *cchi_rx, *cchi_tx, *debug_rx; + u16 cchi_head, cchi_tail; +}; + +static struct cen_buffer *buffer_alloc(struct centauri_t6050 *c, unsigned int function, + size_t size) +{ + struct cen_buffer *buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); + + if (!buffer) + return NULL; + buffer->owner = get_device(&c->ipc->function[function]->dev); + buffer->size = PAGE_ALIGN(size); + buffer->cpu = dma_alloc_coherent(buffer->owner, buffer->size, &buffer->dma, GFP_KERNEL); + if (!buffer->cpu) { + put_device(buffer->owner); + kfree(buffer); + return NULL; + } + memset(buffer->cpu, 0, buffer->size); + list_add_tail(&buffer->list, &c->ipc->buffers); + return buffer; +} + +static int ftab_entry(const void *image, size_t size, const char tag[4], + u32 *offset, u32 *length, bool sparse) +{ + u32 count, i, off, len; + const u8 *table = image; + + if (size < 0x30 || memcmp(table + 0x24, "ftab", 4)) + return -EINVAL; + count = get_unaligned_le32(table + 0x28); + if (!count || count > 256 || 0x30 + count * 16 > size) + return -EINVAL; + for (i = 0; i < count; i++) { + const u8 *entry = table + 0x30 + 16 * i; + + if (memcmp(entry, tag, 4)) + continue; + off = get_unaligned_le32(entry + 4); + len = get_unaligned_le32(entry + 8); + if (off < 0x30 + count * 16 || !len || (u64)off + len > (sparse ? SZ_64M : size)) + return -EINVAL; + *offset = off; + *length = len; + return 0; + } + return -ENOENT; +} + +static int secondary_init(struct centauri_t6050 *c) +{ + u32 offset, length, count, i, required; + const u8 *seed; + int ret; + + ret = ftab_entry(c->firmware, c->firmware_size, "2ftb", &offset, &length, false); + if (ret) + return ret; + seed = c->firmware + offset; + if (length < 0x30 || memcmp(seed + 0x24, "ftab", 4)) + return -EINVAL; + count = get_unaligned_le32(seed + 0x28); + if (!count || count > 256 || 0x30 + 16 * count != length) + return -EINVAL; + required = length; + for (i = 0; i < count; i++) { + u64 end = (u64)get_unaligned_le32(seed + 0x34 + i * 16) + + get_unaligned_le32(seed + 0x38 + i * 16); + + if (end > SZ_64M) + return -EINVAL; + required = max_t(u32, required, end); + } + c->ipc->secondary = buffer_alloc(c, 0, required); + if (!c->ipc->secondary) + return -ENOMEM; + memcpy(c->ipc->secondary->cpu, seed, length); + dma_wmb(); + ret = pci_write_config_dword(c->pdev, 0xf88, lower_32_bits(c->ipc->secondary->dma)); + if (!ret) + ret = pci_write_config_dword(c->pdev, 0xf8c, upper_32_bits(c->ipc->secondary->dma)); + if (!ret) + ret = pci_write_config_dword(c->pdev, 0xf90, required); + if (ret) + return pcibios_err_to_errno(ret); + + return 0; +} + +static int context_init(struct centauri_t6050 *c, struct cen_context *ctx, + unsigned int function, u16 tr, u16 cr, dma_addr_t scratch, size_t scratch_size) +{ + u8 *header; + dma_addr_t dma; + int i; + + ctx->buffer = buffer_alloc(c, function, SZ_32K); + ctx->messages = buffer_alloc(c, function, SZ_16K); + if (!ctx->buffer || !ctx->messages) + return -ENOMEM; + ctx->tr_count = tr; + ctx->cr_count = cr; + ctx->index[0] = 0x78; + ctx->index[1] = ctx->index[0] + cr * 2; + ctx->index[2] = ctx->index[1] + tr * 2; + ctx->index[3] = ctx->index[2] + cr * 2; + ctx->mtr = ALIGN(ctx->index[3] + tr * 2, tr == 192 ? 16 : 2); + ctx->mcr = ALIGN(ctx->mtr + 256, 4); + header = ctx->buffer->cpu; + dma = ctx->buffer->dma; + put_unaligned_le16(768, header); + put_unaligned_le16(0x68, header + 2); + put_unaligned_le64(dma + 0x68, header + 8); + for (i = 0; i < 4; i++) + put_unaligned_le64(dma + ctx->index[i], header + 0x10 + 8 * i); + put_unaligned_le16(cr, header + 0x30); + put_unaligned_le16(tr, header + 0x32); + put_unaligned_le64(dma + ctx->mcr, header + 0x34); + put_unaligned_le64(dma + ctx->mtr, header + 0x3c); + put_unaligned_le16(16, header + 0x44); + put_unaligned_le16(16, header + 0x46); + put_unaligned_le64(scratch ?: dma + ALIGN(ctx->mcr + 256, 8), header + 0x58); + put_unaligned_le64(scratch_size, header + 0x60); + dma_wmb(); + return 0; +} + +static int handshake(void __iomem *bar, struct cen_context *ctx, + u32 status, u32 address, u32 control) +{ + u32 value; + int ret; + + writel(1, bar + control); + ret = readl_poll_timeout(bar + status, value, value == 1, 100, 2000000); + if (ret) { + pr_err("centauri_t6050: IPC init timeout status@%#x=%#x control@%#x=%#x context=%pad\n", + status, value, control, readl(bar + control), &ctx->buffer->dma); + return ret; + } + writel(lower_32_bits(ctx->buffer->dma), bar + address); + writel(upper_32_bits(ctx->buffer->dma), bar + address + 4); + dma_wmb(); + writel(2, bar + control); + ret = readl_poll_timeout(bar + status, value, value == 2, 100, 2000000); + if (ret) + pr_err("centauri_t6050: IPC run timeout status@%#x=%#x control@%#x=%#x context=%pad\n", + status, value, control, readl(bar + control), &ctx->buffer->dma); + return ret; +} + +static int message(struct cen_context *ctx, void __iomem *doorbell, + const void *payload, size_t length) +{ + u16 head = ctx->message_head; + u8 *descriptor; + u16 tail; + int ret; + + if (head >= 15 || !length || length > 512) + return -ENOSPC; + memcpy(ctx->messages->cpu + 512 * (head + 1), payload, length); + descriptor = ctx->buffer->cpu + ctx->mtr + head * 16; + put_unaligned_le32(1 | (length << 8), descriptor); + put_unaligned_le64(ctx->messages->dma + 512 * (head + 1), descriptor + 4); + put_unaligned_le32(head + 1, descriptor + 12); + dma_wmb(); + writel(head + 1, doorbell); + ret = read_poll_timeout(READ_ONCE, tail, le16_to_cpu(tail) == head + 1, + 100, 1200000, false, *(__le16 *)(ctx->buffer->cpu + ctx->index[1])); + dma_rmb(); + ctx->message_head++; + return ret; +} + +static int open_transfer(struct centauri_t6050 *c, u16 id, struct cen_buffer *buffer, + u16 footer) +{ + u8 msg[0x34] = { 1 }; + u32 words = footer >> 2, shift = min_t(u32, __ffs(words), 4); + + msg[2] = words >> shift; + msg[3] = shift << 4; + put_unaligned_le16(id, msg + 4); + put_unaligned_le64(buffer->dma, msg + 8); + put_unaligned_le64(~0ULL, msg + 0x10); + put_unaligned_le16(16, msg + 0x18); + put_unaligned_le16(0xffff, msg + 0x1a); + put_unaligned_le16(id, msg + 0x1c); + put_unaligned_le16(0x40, msg + 0x1e); + return message(&c->ipc->control, c->bar + 0x9000, msg, sizeof(msg)); +} + +static int cchi_init(struct centauri_t6050 *c) +{ + struct centauri_t6050_ipc *ipc = c->ipc; + u8 config[4] = {9, 0, 0xff, 0xff}, *entry; + u16 tail; + int i, ret; + + ipc->cchi_rx = buffer_alloc(c, 0, SZ_32K); + ipc->cchi_tx = buffer_alloc(c, 0, SZ_32K); + ipc->debug_rx = buffer_alloc(c, 0, SZ_16K); + if (!ipc->cchi_rx || !ipc->cchi_tx || !ipc->debug_rx) + return -ENOMEM; + ret = message(&ipc->control, c->bar + 0x9000, config, sizeof(config)); + if (ret) + return ret; + ret = open_transfer(c, 4, ipc->cchi_rx, 1024); + if (!ret) + ret = open_transfer(c, 3, ipc->cchi_tx, 1024); + if (!ret) + ret = open_transfer(c, 5, ipc->debug_rx, 256); + if (ret) + return ret; + for (i = 0; i < 15; i++) { + entry = ipc->cchi_rx->cpu + i * 1040; + put_unaligned_le32(1 | (1024 << 8), entry); + put_unaligned_le32(i + 1, entry + 12); + entry = ipc->debug_rx->cpu + i * 272; + put_unaligned_le32(1 | (256 << 8), entry); + put_unaligned_le32(i + 1, entry + 12); + } + dma_wmb(); + writel(15, c->bar + 0x9010); + writel(15, c->bar + 0x9014); + entry = ipc->cchi_tx->cpu; + put_unaligned_le32(1 | (64 << 8), entry); + put_unaligned_le32(1, entry + 12); + put_unaligned_le16(64, entry + 16); + dma_wmb(); + writel(1, c->bar + 0x900c); + ret = read_poll_timeout(READ_ONCE, tail, le16_to_cpu(tail) != 0, + 100, 2000000, false, + *(__le16 *)(ipc->control.buffer->cpu + ipc->control.index[1] + 4 * 2)); + dma_rmb(); + if (ret) + return ret; + entry = ipc->cchi_rx->cpu; + if ((get_unaligned_le32(entry) >> 8) < 8 || entry[18] || entry[19]) + return -EPROTO; + ipc->cchi_head = ipc->cchi_tail = 1; + return 0; +} + +static int memswap_handoff(struct centauri_t6050 *c, unsigned int function, const char tag[4]) +{ + struct cen_buffer *secondary = c->ipc->secondary, *working; + u32 offset, size; + int ret; + + ret = ftab_entry(secondary->cpu, secondary->size, tag, &offset, &size, false); + if (ret) + return ret; + working = buffer_alloc(c, function, size); + if (!working) + return -ENOMEM; + dma_rmb(); + memcpy(working->cpu, secondary->cpu + offset, size); + dma_wmb(); + ret = pci_write_config_dword(c->ipc->function[function], 0xf88, lower_32_bits(working->dma)); + if (!ret) + ret = pci_write_config_dword(c->ipc->function[function], 0xf8c, upper_32_bits(working->dma)); + if (!ret) + ret = pci_write_config_dword(c->ipc->function[function], 0xf90, size); + if (ret) + return pcibios_err_to_errno(ret); + return 0; +} + +static struct dev_pm_domain centauri_t6050_alpha_pm_domain; + +static int enumerate_functions(struct centauri_t6050 *c) +{ + struct centauri_t6050_ipc *ipc = c->ipc; + int i, ret; + + c->pdev->multifunction = 1; + pci_rescan_bus(c->pdev->bus); + for (i = 0; i < 3; i++) { + ipc->function[i] = pci_get_domain_bus_and_slot(pci_domain_nr(c->pdev->bus), + c->pdev->bus->number, PCI_DEVFN(PCI_SLOT(c->pdev->devfn), i)); + if (!ipc->function[i] || ipc->function[i]->vendor != PCI_VENDOR_ID_APPLE || + (i && ipc->function[i]->device != 0x1901 + i)) + return -ENODEV; + if (ipc->function[i]->cfg_size < 0xf94 || + !(pci_resource_flags(ipc->function[i], 0) & IORESOURCE_MEM) || + pci_resource_len(ipc->function[i], 0) < (i ? 0x2000 : 0x9080)) + return -ENODEV; + if (i && ipc->function[i]->dev.driver) + return -EBUSY; + ipc->owned[i] = true; + ipc->bar[i] = pci_iomap(ipc->function[i], 0, 0); + if (!ipc->bar[i]) + return -ENOMEM; + if (i) { + ret = pci_enable_device_mem(ipc->function[i]); + if (ret) + return ret; + ipc->enabled[i] = true; + } + if (i == 1 && !ipc->function[i]->dev.driver) { + dev_pm_domain_set(&ipc->function[i]->dev, ¢auri_t6050_alpha_pm_domain); + ipc->alpha_pm_domain = true; + } + ret = dma_set_mask_and_coherent(&ipc->function[i]->dev, DMA_BIT_MASK(40)); + if (ret) + return ret; + if (i == 1) { + ret = centauri_t6050_request_irqs(&c->alpha_irqs, ipc->function[i], + 16, centauri_t6050_alpha_irq, c); + if (ret) + return ret; + } + pci_set_master(ipc->function[i]); + } + return 0; +} + +static int centauri_t6050_start_ipc_locked(struct centauri_t6050 *c) +{ + struct centauri_t6050_ipc *ipc; + u32 stage; + int ret; + + if (!c->firmware || !c->link_ready || c->ipc || readl(c->bar + 0x8000) != 1) + return -EBUSY; + ipc = kzalloc(sizeof(*ipc), GFP_KERNEL); + if (!ipc) + return -ENOMEM; + INIT_LIST_HEAD(&ipc->buffers); + c->ipc = ipc; + ret = enumerate_functions(c); + if (ret) + goto failed; + ret = secondary_init(c); + if (ret) + goto failed; + ret = context_init(c, &ipc->control, 0, 13, 1, 0, 0); + if (ret) + goto failed; + writel(lower_32_bits(c->descriptor_dma), c->bar + 0x8044); + writel(upper_32_bits(c->descriptor_dma), c->bar + 0x8048); + writel(0x20, c->bar + 0x804c); + writel(0x62746632, c->bar + 0x8074); + dma_wmb(); + writel(1, c->bar + 0x9070); + ret = readl_poll_timeout(c->bar + 0x8000, stage, stage == 2 || stage == 3, 100, 3000000); + if (ret || stage != 2) { + ret = ret ?: -EIO; + goto failed; + } + ret = handshake(c->bar, &ipc->control, 0x8050, 0x8054, 0x907c); + if (ret) + goto failed; + ret = memswap_handoff(c, 0, "mswc"); + if (!ret) + ret = memswap_handoff(c, 2, "mswb"); + if (!ret) + ret = memswap_handoff(c, 1, "msww"); + if (ret) + goto failed; + ret = cchi_init(c); + if (ret) + goto failed; + ret = readl_poll_timeout(ipc->bar[1] + 8, stage, stage == 2 || stage == 3, 100, 2000000); + if (ret || stage != 2) { + ret = ret ?: -EIO; + goto failed; + } + ipc->window = buffer_alloc(c, 1, CEN_ALPHA_WINDOW_SIZE); + if (!ipc->window) { + ret = -ENOMEM; + goto failed; + } + ret = context_init(c, &ipc->alpha, 1, 192, 234, + ipc->window->dma + CEN_ALPHA_SCRATCH_OFFSET, CEN_ALPHA_SCRATCH_SIZE); + if (ret) + goto failed; + writel(lower_32_bits(ipc->window->dma), ipc->bar[1] + 0x18); + writel(upper_32_bits(ipc->window->dma), ipc->bar[1] + 0x1c); + writel(CEN_ALPHA_WINDOW_SIZE, ipc->bar[1] + 0x20); + ret = handshake(ipc->bar[1], &ipc->alpha, 0xc, 0x10, 0x1028); + if (ret) + goto failed; + ret = centauri_t6050_wifi_register(c); + if (ret) + return ret; + + /* Publish usable shared firmware before the Beta consumer probes. */ + smp_store_release(&c->ready, true); + ret = device_attach(&ipc->function[2]->dev); + if (ret < 0) + dev_warn(&c->pdev->dev, "Beta driver attachment failed: %d\n", ret); + return 0; +failed: + dev_err(&c->pdev->dev, "IPC bootstrap failed: %d (Control stage=%#x)\n", + ret, readl(c->bar + 0x8000)); + if (ipc->bar[1]) + dev_err(&c->pdev->dev, "Alpha stage=%#x IPC=%#x window=%#x/%#x/%#x\n", + readl(ipc->bar[1] + 8), readl(ipc->bar[1] + 0xc), + readl(ipc->bar[1] + 0x18), readl(ipc->bar[1] + 0x1c), readl(ipc->bar[1] + 0x20)); + if (ipc->bar[2]) + dev_err(&c->pdev->dev, "Beta stage=%#x IPC=%#x\n", + readl(ipc->bar[2] + 0x18), readl(ipc->bar[2] + 0x1c)); + + return ret; +} + +int centauri_t6050_start_ipc(struct centauri_t6050 *c) +{ + int ret; + + if (!pci_trylock_rescan_remove()) + return -EAGAIN; + ret = READ_ONCE(c->removing) ? -ECANCELED : centauri_t6050_start_ipc_locked(c); + pci_unlock_rescan_remove(); + return ret; +} + +void centauri_t6050_free_ipc(struct centauri_t6050 *c) +{ + struct centauri_t6050_ipc *ipc = c->ipc; + struct cen_buffer *buffer, *next; + int i; + + if (!ipc) + return; + if (ipc->owned[2]) + device_release_driver(&ipc->function[2]->dev); + centauri_t6050_wifi_unregister(c); + centauri_t6050_free_irqs(&c->alpha_irqs); + for (i = 0; i < 3; i++) { + if (!ipc->owned[i]) + continue; + pci_clear_master(ipc->function[i]); + } + for (i = 0; i < 3; i++) { + if (ipc->owned[i] && !centauri_t6050_stop_dma(ipc->function[i])) { + dev_warn(&c->pdev->dev, + "retaining IPC DMA after pending transaction timeout\n"); + return; + } + } + list_for_each_entry_safe(buffer, next, &ipc->buffers, list) { + memzero_explicit(buffer->cpu, buffer->size); + dma_free_coherent(buffer->owner, buffer->size, buffer->cpu, buffer->dma); + put_device(buffer->owner); + list_del(&buffer->list); + kfree(buffer); + } + if (ipc->alpha_pm_domain) + dev_pm_domain_set(&ipc->function[1]->dev, NULL); + for (i = 0; i < 3; i++) { + if (ipc->bar[i]) + pci_iounmap(ipc->function[i], ipc->bar[i]); + if (ipc->enabled[i]) + pci_disable_device(ipc->function[i]); + pci_dev_put(ipc->function[i]); + } + kfree(ipc); + c->ipc = NULL; +} + +int centauri_t6050_alpha_resources(struct centauri_t6050 *c, struct cen_alpha_resources *resources) +{ + struct centauri_t6050_ipc *ipc = c->ipc; + + if (!ipc || !ipc->window || !ipc->alpha.buffer || !ipc->alpha.messages) + return -ENODEV; + resources->pdev = ipc->function[1]; + resources->context = ipc->alpha.buffer->cpu; + resources->context_dma = ipc->alpha.buffer->dma; + resources->messages = ipc->alpha.messages->cpu; + resources->messages_dma = ipc->alpha.messages->dma; + resources->window = ipc->window->cpu; + resources->window_dma = ipc->window->dma; + resources->bar = ipc->bar[1]; + memcpy(resources->index, ipc->alpha.index, sizeof(resources->index)); + resources->mtr = ipc->alpha.mtr; + resources->mcr = ipc->alpha.mcr; + return 0; +} diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c new file mode 100644 index 0000000000000..9fd9d5bd1d8e8 --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_pci.c @@ -0,0 +1,428 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "centauri_t6050.h" + +static struct pci_driver centauri_t6050_driver; + +bool apple_centauri_control_ready(struct pci_dev *pdev) +{ + struct centauri_t6050 *c; + + if (pdev->driver != ¢auri_t6050_driver) + return false; + c = pci_get_drvdata(pdev); + return c && !READ_ONCE(c->removing) && smp_load_acquire(&c->ready); +} +EXPORT_SYMBOL_GPL(apple_centauri_control_ready); + +/* No DMA backing is released without verified bus-master shutdown. */ +bool centauri_t6050_stop_dma(struct pci_dev *pdev) +{ + u16 command; + int ret; + + pci_clear_master(pdev); + ret = pci_read_config_word(pdev, PCI_COMMAND, &command); + if (ret || (command & PCI_COMMAND_MASTER)) + return false; + return pci_wait_for_pending_transaction(pdev); +} + +void centauri_t6050_free_irqs(struct centauri_t6050_irqs *irqs) +{ + if (!irqs->pdev) + return; + while (irqs->count) + free_irq(pci_irq_vector(irqs->pdev, --irqs->count), irqs->data); + pci_free_irq_vectors(irqs->pdev); + irqs->pdev = NULL; +} + +int centauri_t6050_request_irqs(struct centauri_t6050_irqs *irqs, struct pci_dev *pdev, + unsigned int count, irq_handler_t handler, void *data) +{ + int ret; + + ret = pci_alloc_irq_vectors(pdev, count, count, PCI_IRQ_MSI); + if (ret < 0) + return ret; + irqs->pdev = pdev; + irqs->data = data; + for (irqs->count = 0; irqs->count < count; irqs->count++) { + ret = request_irq(pci_irq_vector(pdev, irqs->count), handler, 0, + "centauri_t6050", data); + if (ret) { + centauri_t6050_free_irqs(irqs); + return ret; + } + } + return 0; +} + +static irqreturn_t centauri_t6050_control_irq(int irq, void *data) +{ + return IRQ_HANDLED; +} + +static void centauri_t6050_free_boot(struct centauri_t6050 *c) +{ + struct device *dev = &c->pdev->dev; + + if (!c->link_ready && c->boot_attempted) { + while (c->alpha_irqs.count) + free_irq(pci_irq_vector(c->alpha_irqs.pdev, --c->alpha_irqs.count), c); + while (c->irqs.count) + free_irq(pci_irq_vector(c->pdev, --c->irqs.count), c); + dev_warn(dev, "retaining DMA buffers after failed link transition; reboot required\n"); + return; + } + + centauri_t6050_free_ipc(c); + centauri_t6050_free_irqs(&c->irqs); + if (c->ipc || !centauri_t6050_stop_dma(c->pdev)) { + dev_warn(dev, "retaining boot DMA until outstanding transactions stop\n"); + return; + } + if (c->firmware) + dma_free_coherent(dev, c->firmware_size, c->firmware, c->firmware_dma); + if (c->descriptor) + dma_free_coherent(dev, SZ_16K, c->descriptor, c->descriptor_dma); + c->firmware = NULL; + c->descriptor = NULL; +} + +static int centauri_t6050_rom_boot(struct centauri_t6050 *c) +{ + const struct firmware *fw; + struct device *dev = &c->pdev->dev; + u32 stage; + int ret; + + if (c->pdev->device != 0x1900 && c->pdev->device != 0x1901) + return -ENODEV; + if (!c->link_ready || c->boot_attempted) + return -EBUSY; + stage = readl(c->bar + 0x8000); + if (stage != 0) + return -EBUSY; + + ret = request_firmware_direct(&fw, c->firmware_name, dev); + if (ret) { + dev_err(dev, "required firmware %s unavailable: %d\n", c->firmware_name, ret); + return ret; + } + if (READ_ONCE(c->removing)) { + ret = -ECANCELED; + goto release; + } + if (fw->size < 0x30 || fw->size > SZ_64M || + memcmp(fw->data + 0x20, "rkosftab", 8)) { + ret = -EINVAL; + goto release; + } + c->firmware_size = PAGE_ALIGN(fw->size); + c->firmware = dma_alloc_coherent(dev, c->firmware_size, &c->firmware_dma, GFP_KERNEL); + c->descriptor = dma_alloc_coherent(dev, SZ_16K, &c->descriptor_dma, GFP_KERNEL); + if (!c->firmware || !c->descriptor) { + ret = -ENOMEM; + goto free_buffers; + } + memset(c->firmware, 0, c->firmware_size); + memcpy(c->firmware, fw->data, fw->size); + memset(c->descriptor, 0, SZ_16K); + + put_unaligned_le64(c->firmware_dma, c->descriptor); + put_unaligned_le32(ALIGN(fw->size, SZ_4K), c->descriptor + 8); + ret = centauri_t6050_request_irqs(&c->irqs, c->pdev, 4, + centauri_t6050_control_irq, c); + if (ret) + goto free_buffers; + pci_set_master(c->pdev); + writel(c->platform_id, c->bar + 0x807c); + writel(0, c->bar + 0x803c); + writel(lower_32_bits(c->descriptor_dma), c->bar + 0x8044); + writel(upper_32_bits(c->descriptor_dma), c->bar + 0x8048); + writel(0x20, c->bar + 0x804c); + dma_wmb(); + c->boot_attempted = true; + writel(1, c->bar + 0x9000); + ret = readl_poll_timeout(c->bar + 0x8040, c->image_response, + READ_ONCE(c->removing) || c->image_response != 0, 20000, 20000000); + if (READ_ONCE(c->removing)) { + ret = -ECANCELED; + goto release; + } + if (!ret && c->image_response != 1) + ret = -EIO; + if (!ret) + ret = readl_poll_timeout(c->bar + 0x8000, stage, + READ_ONCE(c->removing) || stage != 0, 20000, 20000000); + else + stage = readl(c->bar + 0x8000); + if (READ_ONCE(c->removing)) + ret = -ECANCELED; + dma_rmb(); + + if (!ret && stage != 4) + ret = -EIO; + goto release; +free_buffers: + centauri_t6050_free_boot(c); +release: + release_firmware(fw); + return ret; +} + +/* + * After the ROM boot the N1 runs its firmware from host memory and must come back on a + * retrained link: the isolated function 0 is quiesced, put in D3hot with PME enabled + * (the host's PME_Turn_Off then takes the link to L2), the host resets and retrains the + * root port (PERST# asserted and released around it; the firmware keeps running), and the + * root port's and the endpoint's state are restored. + */ +static int centauri_t6050_port_cycle(struct pci_dev *endpoint) +{ + struct pci_host_bridge *host = pci_find_host_bridge(endpoint->bus); + struct pci_dev *bridge = endpoint->bus->self, *sibling; + u16 command, pmctrl; + u32 identity; + int ret, pm; + + if (!host->reset_root_port || !bridge || !pci_is_root_bus(bridge->bus)) + return -EOPNOTSUPP; + pm = endpoint->pm_cap; + if (!pm) + return -ENODEV; + if (!pci_trylock_rescan_remove()) + return -EAGAIN; + list_for_each_entry(sibling, &endpoint->bus->devices, bus_list) { + if (sibling != endpoint) { + ret = -EBUSY; + goto out; + } + } + ret = pci_save_state(bridge) ?: pci_save_state(endpoint); + if (ret) + goto out; + ret = pcibios_err_to_errno(pci_read_config_word(endpoint, PCI_COMMAND, &command)); + if (ret) + goto out; + if (!centauri_t6050_stop_dma(endpoint)) { + ret = -EBUSY; + goto stopped; + } + ret = pcibios_err_to_errno(pci_read_config_word(endpoint, pm + PCI_PM_CTRL, &pmctrl)); + if (ret) + goto stopped; + ret = pcibios_err_to_errno(pci_write_config_word(endpoint, pm + PCI_PM_CTRL, + (pmctrl & ~PCI_PM_CTRL_STATE_MASK) | PCI_D3hot | PCI_PM_CTRL_PME_ENABLE)); + if (ret) + goto stopped; + usleep_range(10000, 11000); + + ret = host->reset_root_port(host, bridge); + if (ret) + goto stopped; + pci_restore_state(bridge); + ret = pcibios_err_to_errno(pci_read_config_dword(endpoint, PCI_VENDOR_ID, &identity)); + if (!ret && identity != 0x1900106b && identity != 0x1901106b) + ret = -ENODEV; + if (ret) + goto stopped; + pci_restore_state(endpoint); + ret = pcibios_err_to_errno(pci_write_config_word(endpoint, pm + PCI_PM_CTRL, + pmctrl & ~PCI_PM_CTRL_STATE_MASK)); + if (ret) + goto stopped; + usleep_range(10000, 11000); + ret = pcibios_err_to_errno(pci_write_config_word(endpoint, PCI_COMMAND, command)); + if (!ret) + goto out; +stopped: + /* A partial transition never restores endpoint DMA or bridge decoding. */ + pci_clear_master(endpoint); + pci_write_config_word(bridge, PCI_COMMAND, 0); + pci_err(endpoint, "N1 port cycle stopped: %d\n", ret); +out: + pci_unlock_rescan_remove(); + return ret; +} + +static int centauri_t6050_cycle(struct centauri_t6050 *c) +{ + int ret; + + if (!c->firmware || !c->link_ready || readl(c->bar + 0x8000) != 4) + return -EBUSY; + c->link_ready = false; + ret = centauri_t6050_port_cycle(c->pdev); + if (ret == -EAGAIN) { + c->link_ready = true; + } else if (!ret) { + pci_restore_msi_state(c->pdev); + c->link_ready = true; + } + return ret; +} + +static void centauri_t6050_boot_worker(struct work_struct *work) +{ + struct centauri_t6050 *c = container_of(to_delayed_work(work), struct centauri_t6050, boot_work); + bool retry = false; + int ret; + + mutex_lock(&c->boot_lock); + while (!READ_ONCE(c->removing)) { + switch (c->boot_phase) { + case CEN_BOOT_ROM: + ret = centauri_t6050_rom_boot(c); + if (!ret) + c->boot_phase = readl(c->bar + 0x8000) == 1 ? + CEN_BOOT_IPC : CEN_BOOT_CYCLE; + break; + case CEN_BOOT_CYCLE: + ret = centauri_t6050_cycle(c); + if (!ret) + c->boot_phase = CEN_BOOT_IPC; + break; + case CEN_BOOT_IPC: + ret = centauri_t6050_start_ipc(c); + if (!ret) + c->boot_phase = CEN_BOOT_READY; + break; + default: + goto out; + } + if (ret == -EAGAIN && (c->boot_phase == CEN_BOOT_CYCLE || + (c->boot_phase == CEN_BOOT_IPC && !c->ipc))) { + retry = true; + break; + } + if (ret) { + dev_err(&c->pdev->dev, "N1 automatic startup failed in phase%u: %d\n", + c->boot_phase, ret); + c->boot_phase = CEN_BOOT_FAILED; + break; + } + } +out: + if (READ_ONCE(c->removing)) + c->boot_phase = CEN_BOOT_STOPPED; + mutex_unlock(&c->boot_lock); + if (retry && !READ_ONCE(c->removing)) + queue_delayed_work(system_long_wq, &c->boot_work, msecs_to_jiffies(20)); +} + +static int centauri_t6050_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct centauri_t6050 *c; + int ret; + struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); + + if (!bridge || !bridge->dev.parent || + !of_device_is_compatible(bridge->dev.parent->of_node, "apple,t6050-pcie")) + return -ENODEV; + if (PCI_FUNC(pdev->devfn) != 0) + return -ENODEV; + c = devm_kzalloc(&pdev->dev, sizeof(*c), GFP_KERNEL); + if (!c) + return -ENOMEM; + c->pdev = pdev; + c->link_ready = true; + mutex_init(&c->boot_lock); + INIT_DELAYED_WORK(&c->boot_work, centauri_t6050_boot_worker); + c->boot_phase = CEN_BOOT_ROM; + ret = device_property_read_string(&pdev->dev, "firmware-name", &c->firmware_name); + if (ret) + return dev_err_probe(&pdev->dev, ret, "missing personalized firmware name\n"); + ret = device_property_read_u32(&pdev->dev, "apple,centauri-platform-id", &c->platform_id); + if (ret) + return ret; + ret = device_property_read_u32(&pdev->dev, "apple,centauri-protocol", &c->protocol); + if (ret || c->protocol != 27) + return -EINVAL; + ret = pcim_enable_device(pdev); + if (ret) + return ret; + c->size = pci_resource_len(pdev, 0); + if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) || + c->size < 0x9080) + return dev_err_probe(&pdev->dev, -ENODEV, "invalid ACIPC BAR0\n"); + ret = pcim_iomap_regions(pdev, BIT(0), "apple_centauri_t6050"); + if (ret) + return ret; + c->bar = pcim_iomap_table(pdev)[0]; + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); + if (ret) + return dev_err_probe(&pdev->dev, ret, "40-bit DMA unavailable\n"); + + pci_clear_master(pdev); + pci_set_drvdata(pdev, c); + queue_delayed_work(system_long_wq, &c->boot_work, 0); + return 0; +} + +static void centauri_t6050_remove(struct pci_dev *pdev) +{ + struct centauri_t6050 *c = pci_get_drvdata(pdev); + + WRITE_ONCE(c->removing, true); + cancel_delayed_work_sync(&c->boot_work); + mutex_lock(&c->boot_lock); + centauri_t6050_wifi_unregister(c); + centauri_t6050_free_boot(c); + c->boot_phase = CEN_BOOT_STOPPED; + mutex_unlock(&c->boot_lock); +} + +static int centauri_t6050_suspend(struct device *dev) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct centauri_t6050 *c = pci_get_drvdata(pdev); + + guard(mutex)(&c->boot_lock); + if (c->boot_phase != CEN_BOOT_READY) + return -EBUSY; + return pci_save_state(pdev); +} + +static int centauri_t6050_resume(struct device *dev) +{ + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(centauri_t6050_pm_ops, centauri_t6050_suspend, centauri_t6050_resume); + +static const struct pci_device_id centauri_t6050_ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1900) }, + { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1901) }, + { } +}; +MODULE_DEVICE_TABLE(pci, centauri_t6050_ids); + +static struct pci_driver centauri_t6050_driver = { + .name = "apple_centauri_t6050", + .id_table = centauri_t6050_ids, + .probe = centauri_t6050_probe, + .remove = centauri_t6050_remove, + .shutdown = centauri_t6050_remove, + .driver.pm = pm_sleep_ptr(¢auri_t6050_pm_ops), +}; + +module_pci_driver(centauri_t6050_driver); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Apple N1 Centauri PCI firmware and ACIPC transport"); diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h new file mode 100644 index 0000000000000..dfc9c013596fb --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_t6050.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef AURORA_CENTAURI_T6050_H +#define AURORA_CENTAURI_T6050_H +#include +#include +#include +#include +#include +#include + +#define CEN_ALPHA_WINDOW_SIZE SZ_32M +#define CEN_ALPHA_SCRATCH_OFFSET SZ_8M +#define CEN_ALPHA_SCRATCH_SIZE (5 * SZ_1M) + +struct centauri_t6050_ipc; +struct centauri_t6050_wifi; +struct centauri_t6050_irqs { + struct pci_dev *pdev; + void *data; + unsigned int count; +}; + +struct cen_alpha_resources { + struct pci_dev *pdev; + void *context, *messages, *window; + dma_addr_t context_dma, messages_dma, window_dma; + void __iomem *bar; + u32 index[4], mtr, mcr; +}; +enum centauri_t6050_boot_phase { + CEN_BOOT_ROM, + CEN_BOOT_CYCLE, + CEN_BOOT_IPC, + CEN_BOOT_READY, + CEN_BOOT_FAILED, + CEN_BOOT_STOPPED, +}; + +struct centauri_t6050 { + struct pci_dev *pdev; + void __iomem *bar; + resource_size_t size; + u32 platform_id, protocol; + const char *firmware_name; + struct dentry *debug; + struct mutex boot_lock; + struct delayed_work boot_work; + enum centauri_t6050_boot_phase boot_phase; + bool removing, ready; + void *firmware, *descriptor; + struct centauri_t6050_irqs irqs, alpha_irqs; + dma_addr_t firmware_dma, descriptor_dma; + size_t firmware_size; + u32 image_response; + bool boot_attempted; + bool link_ready; + struct centauri_t6050_ipc *ipc; + struct centauri_t6050_wifi *wifi; +}; + +int centauri_t6050_request_irqs(struct centauri_t6050_irqs *irqs, struct pci_dev *pdev, + unsigned int count, irq_handler_t handler, void *data); +void centauri_t6050_free_irqs(struct centauri_t6050_irqs *irqs); + +int centauri_t6050_start_ipc(struct centauri_t6050 *c); +void centauri_t6050_free_ipc(struct centauri_t6050 *c); +int centauri_t6050_alpha_resources(struct centauri_t6050 *c, struct cen_alpha_resources *resources); +bool centauri_t6050_stop_dma(struct pci_dev *pdev); + +#if IS_ENABLED(CONFIG_APPLE_CENTAURI_T6050_WIFI) +irqreturn_t centauri_t6050_alpha_irq(int irq, void *data); +int centauri_t6050_wifi_register(struct centauri_t6050 *c); +void centauri_t6050_wifi_unregister(struct centauri_t6050 *c); +#else +static inline irqreturn_t centauri_t6050_alpha_irq(int irq, void *data) +{ + return IRQ_HANDLED; +} +static inline int centauri_t6050_wifi_register(struct centauri_t6050 *c) +{ + return 0; +} +static inline void centauri_t6050_wifi_unregister(struct centauri_t6050 *c) +{ +} +#endif +#endif From 6ff5f42b7248e0085439fc8cb64934ea3c1a3283 Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:19 -0400 Subject: [PATCH 300/342] wifi: apple: Add N1 protocol-27 station support Add the N1 protocol-27 cfg80211 station interface, Alpha command/data rings, scanning, and WPA2-PSK/CCMP connections. The shared firmware and PCIe transport are supplied by the sibling core PR. Source snapshot: t6050-gpu ee68abb105200e99636a5edfc647a5cfc1d89954 Integration base: 9cbdd0734d9e186c5f5f5949a21b909d10c2571b Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/net/wireless/apple/Kconfig | 7 + .../apple/centauri/t6050/centauri_wifi.c | 1736 +++++++++++++++++ 2 files changed, 1743 insertions(+) create mode 100644 drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c diff --git a/drivers/net/wireless/apple/Kconfig b/drivers/net/wireless/apple/Kconfig index 344099f427c5e..d9b13a9785de2 100644 --- a/drivers/net/wireless/apple/Kconfig +++ b/drivers/net/wireless/apple/Kconfig @@ -34,4 +34,11 @@ config APPLE_CENTAURI_T6050 platform and protocol properties. It binds only behind a T6050 host; the J813/J873 transport remains available independently. +config APPLE_CENTAURI_T6050_WIFI + bool "T6050 N1 Centauri cfg80211 station interface" + depends on APPLE_CENTAURI_T6050 + default y + help + Add scanning and station connections for the T6050 protocol profile. + endif diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c new file mode 100644 index 0000000000000..6779271fc83f4 --- /dev/null +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -0,0 +1,1736 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include "centauri_t6050.h" + +#define CR_BASE 0x100000 +#define TR_BASE 0x400000 +#define RING_SPAN 0x20000 +#define TX_BUFFER 0x600000 +#define BUFFER_SIZE 2048 + +#define DATA_RX_BUFFER SZ_16M +#define DATA_TX_BUFFER (SZ_16M + SZ_8M) +#define DATA_RX_SLOTS 2048 +#define DATA_TX_SLOTS 2048 +#define DATA_TX_QUEUE_LIMIT DATA_TX_SLOTS + +static_assert(DATA_TX_BUFFER >= + CEN_ALPHA_SCRATCH_OFFSET + CEN_ALPHA_SCRATCH_SIZE); +static_assert(DATA_RX_BUFFER >= + CEN_ALPHA_SCRATCH_OFFSET + CEN_ALPHA_SCRATCH_SIZE); +static_assert(DATA_RX_BUFFER + DATA_RX_SLOTS * 4096 <= DATA_TX_BUFFER); +static_assert(DATA_TX_BUFFER + DATA_TX_SLOTS * BUFFER_SIZE <= + CEN_ALPHA_WINDOW_SIZE); + +struct centauri_t6050_wifi { + struct centauri_t6050 *control; + struct cen_alpha_resources a; + struct wiphy *wiphy; + struct wireless_dev wdev; + struct net_device *netdev; + struct work_struct scan_work; + struct work_struct connect_work; + struct work_struct link_work; + bool irq_ready; + struct cfg80211_scan_request *scan_request; + struct mutex lock; /* Serializes firmware commands and ring consumers. */ + + u16 main_head, command_head, sequence; + u32 rx_seen[5]; + u16 rx_next[5], rx_head[5]; + u16 reply_sequence, reply_status; + u32 reply_command, channels_seen, scans_done, beacons_seen; + bool reply_valid, registered, configured; + bool stopping, command_failed; + bool scan_abort, connect_abort; + u8 scan_sequence; + bool connecting, connected, connect_event, disconnect_event; + bool disconnect_pending; + u16 connect_status; + u8 bssid[ETH_ALEN], connect_payload[1024], request_ie[256]; + size_t connect_size, request_ie_size; + u32 data_rx_received, data_rx_reposted, data_rx_bad; + struct sk_buff_head data_tx_queue; + u16 data_tx_length[DATA_TX_SLOTS]; + bool data_tx_busy[DATA_TX_SLOTS]; + u32 data_tx_submitted, data_tx_completed, data_tx_failed; + u32 data_tx_coalesced, data_tx_bad; + s8 station_signal; + bool station_signal_valid; + unsigned long station_signal_at, connected_at; + struct net_device_stats station_start; + u8 country[3]; + bool country_valid; + u32 data_rings_open; + bool data_failed; + struct ieee80211_supported_band bands[2]; + struct ieee80211_channel channels[39]; +}; + +static int query_link_status(struct centauri_t6050_wifi *wifi); + +static const u32 rx_buffer[5] = { 0, 0, 0x620000, 0x680000, 0x700000 }; +static const u16 ring_size[5] = { 0, 64, 192, 96, 192 }; +static const u16 five_ghz[] = { + 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, + 120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 161, 165, +}; +static struct ieee80211_rate rates[] = { + { .bitrate = 10 }, { .bitrate = 20 }, { .bitrate = 55 }, + { .bitrate = 110 }, { .bitrate = 60 }, { .bitrate = 90 }, + { .bitrate = 120 }, { .bitrate = 180 }, { .bitrate = 240 }, + { .bitrate = 360 }, { .bitrate = 480 }, { .bitrate = 540 }, +}; + +static const u32 akm_suites[] = { WLAN_AKM_SUITE_PSK }; + +static const u32 cipher_suites[] = { + WLAN_CIPHER_SUITE_CCMP, + WLAN_CIPHER_SUITE_AES_CMAC, +}; + +static u16 index_read(struct centauri_t6050_wifi *wifi, unsigned int array, + unsigned int index) +{ + return le16_to_cpu(READ_ONCE(*( + __le16 *)(wifi->a.context + wifi->a.index[array] + 2 * index))); +} + +static void index_write(struct centauri_t6050_wifi *wifi, unsigned int array, + unsigned int index, u16 value) +{ + WRITE_ONCE( + *(__le16 *)(wifi->a.context + wifi->a.index[array] + 2 * index), + cpu_to_le16(value)); +} + +static void completions(struct centauri_t6050_wifi *wifi) +{ + unsigned int vector; + + for (vector = 0; vector <= 4; vector++) + index_write(wifi, 2, vector, index_read(wifi, 0, vector)); + dma_wmb(); +} + +static int alpha_message(struct centauri_t6050_wifi *wifi, const void *message, + size_t size) +{ + u16 head = wifi->main_head; + u8 *descriptor; + unsigned long deadline = jiffies + msecs_to_jiffies(2000); + + if (head >= 15 || size > 512) + return -ENOSPC; + memcpy(wifi->a.messages + (head + 1) * 512, message, size); + descriptor = wifi->a.context + wifi->a.mtr + 16 * head; + put_unaligned_le32(1 | (size << 8), descriptor); + put_unaligned_le64(wifi->a.messages_dma + (head + 1) * 512, + descriptor + 4); + put_unaligned_le32(head + 1, descriptor + 12); + index_write(wifi, 3, 0, head + 1); + if (head) + index_write(wifi, 3, 8, head + 1); + dma_wmb(); + wifi->main_head++; + writel(1, wifi->a.bar + 0x1004); + do { + if (readl(wifi->a.bar + 8) != 2) + return -EIO; + if (index_read(wifi, 1, 0) >= head + 1) { + dma_rmb(); + completions(wifi); + return 0; + } + usleep_range(100, 200); + } while (time_before(jiffies, deadline)); + return -ETIMEDOUT; +} + +static int open_pair(struct centauri_t6050_wifi *wifi, u16 id) +{ + u8 cr[0x2c] = { 2 }, tr[0x34] = { 1 }; + int ret; + + put_unaligned_le32(id | (id << 16), cr + 4); + put_unaligned_le64(wifi->a.window_dma + CR_BASE + (id - 1) * RING_SPAN, + cr + 8); + put_unaligned_le16(1024, cr + 0x10); + put_unaligned_le16(0xffff, cr + 0x12); + ret = alpha_message(wifi, cr, sizeof(cr)); + if (ret) + return ret; + put_unaligned_le32(id | (id << 16), tr + 4); + put_unaligned_le64(wifi->a.window_dma + TR_BASE + (id - 1) * RING_SPAN, + tr + 8); + put_unaligned_le64(~0ULL, tr + 0x10); + put_unaligned_le16(ring_size[id], tr + 0x18); + put_unaligned_le16(id, tr + 0x1a); + put_unaligned_le16(id, tr + 0x1c); + put_unaligned_le16(0x40, tr + 0x1e); + put_unaligned_le16(2, tr + 0x24); + return alpha_message(wifi, tr, sizeof(tr)); +} + +static void report_beacon(struct centauri_t6050_wifi *wifi, const u8 *payload, + size_t size) +{ + const u8 *frame, *ie, *end; + struct ieee80211_channel *channel; + struct cfg80211_bss *bss; + u16 frame_size; + int number = 0, frequency, signal; + enum nl80211_band band; + + if (!wifi->registered || size < 0x60 + 36) + return; + + frame_size = size - 0x60; + frame = payload + 0x60; + if (!ieee80211_is_beacon(*(__le16 *)frame) && + !ieee80211_is_probe_resp(*(__le16 *)frame)) + return; + end = frame + frame_size; + for (ie = frame + 36; ie + 2 <= end && ie + 2 + ie[1] <= end; + ie += 2 + ie[1]) { + if ((ie[0] == WLAN_EID_DS_PARAMS || + ie[0] == WLAN_EID_HT_OPERATION) && + ie[1]) + number = ie[2]; + } + if (!number) + return; + band = number <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; + frequency = ieee80211_channel_to_frequency(number, band); + channel = ieee80211_get_channel(wifi->wiphy, frequency); + if (!channel) + return; + signal = max_t(s8, payload[0x16], payload[0x17]); + if (signal >= 0 || signal < -127) + signal = -95; + bss = cfg80211_inform_bss_frame(wifi->wiphy, channel, + (struct ieee80211_mgmt *)frame, + frame_size, signal * 100, GFP_KERNEL); + if (bss) { + wifi->beacons_seen++; + cfg80211_put_bss(wifi->wiphy, bss); + } +} + +static void post_receive(struct centauri_t6050_wifi *wifi, unsigned int ring, + u16 slot) +{ + u8 *descriptor = + wifi->a.window + TR_BASE + (ring - 1) * RING_SPAN + slot * 16; + u32 offset = rx_buffer[ring] + slot * BUFFER_SIZE; + + memset(wifi->a.window + offset, 0, BUFFER_SIZE); + put_unaligned_le32(1 | (BUFFER_SIZE << 8), descriptor); + put_unaligned_le64(wifi->a.window_dma + offset, descriptor + 4); + put_unaligned_le32(slot + 1, descriptor + 12); +} + +static bool data_rx_frame(const u8 *packet, unsigned int capacity, + unsigned int length, u32 footer, unsigned int *offset, + unsigned int *frame_length) +{ + unsigned int padding = (footer >> 12) & 15; + + if (!(footer & BIT(7))) + return false; + if (length < padding + ETH_HLEN || length > capacity) + return false; + if (footer & BIT(24)) { + if (capacity < 4) + return false; + *offset = get_unaligned_le16(packet + 2); + } else { + *offset = padding; + } + *frame_length = length - padding; + return *offset <= capacity && *frame_length <= capacity - *offset; +} + +static void drain_data_rx(struct centauri_t6050_wifi *wifi) +{ + u16 head, tail, post; + unsigned int processed = 0; + + if (!(wifi->data_rings_open & BIT(4)) || readl(wifi->a.bar + 8) != 2) + return; + head = index_read(wifi, 0, 207); + tail = index_read(wifi, 2, 207); + post = index_read(wifi, 3, 12); + if (head >= DATA_RX_SLOTS || tail >= DATA_RX_SLOTS || + post >= DATA_RX_SLOTS) { + wifi->data_rx_bad++; + return; + } + dma_rmb(); + while (tail != head && processed < (DATA_RX_SLOTS - 1)) { + u8 *completion = wifi->a.window + 0x240000 + tail * 32; + u32 header = get_unaligned_le32(completion); + u32 info = get_unaligned_le32(completion + 4); + u16 cookie = info & 0xffff, length = info >> 16; + u16 next = (post + 1) % DATA_RX_SLOTS; + u8 *packet, *descriptor; + u32 buffer; + + if ((header >> 16) != 12 || !cookie || + cookie > (DATA_RX_SLOTS - 1) || length > 4096 || + get_unaligned_le32(completion + 8)) { + wifi->data_rx_bad++; + break; + } + + if (next == index_read(wifi, 1, 12)) + break; + buffer = DATA_RX_BUFFER + (cookie - 1) * 4096; + packet = wifi->a.window + buffer; + + wifi->data_rx_received++; + if (wifi->connected && netif_running(wifi->netdev)) { + u32 footer = get_unaligned_le32(completion + 12); + unsigned int offset, frame_length; + struct sk_buff *skb = NULL; + + if (data_rx_frame(packet, 4096, length, footer, &offset, + &frame_length)) + skb = netdev_alloc_skb_ip_align(wifi->netdev, + frame_length); + if (skb) { + skb_put_data(skb, packet + offset, + frame_length); + skb->protocol = + eth_type_trans(skb, wifi->netdev); + skb->ip_summed = CHECKSUM_NONE; + wifi->netdev->stats.rx_packets++; + wifi->netdev->stats.rx_bytes += frame_length; + netif_rx(skb); + } else { + wifi->netdev->stats.rx_dropped++; + } + } else { + wifi->netdev->stats.rx_dropped++; + } + descriptor = wifi->a.window + 0x520000 + post * 16; + put_unaligned_le32(1 | (4096 << 8), descriptor); + put_unaligned_le64(wifi->a.window_dma + buffer, descriptor + 4); + put_unaligned_le32(cookie, descriptor + 12); + wifi->data_rx_reposted++; + tail = (tail + 1) % DATA_RX_SLOTS; + post = next; + processed++; + } + if (processed) { + dma_wmb(); + index_write(wifi, 2, 207, tail); + index_write(wifi, 3, 12, post); + dma_wmb(); + writel(1, wifi->a.bar + 0x1050); + } +} + +static bool data_tx_completion_span(u16 cookie, u16 wire_count, u8 flags, + unsigned int *first, u16 *count) +{ + bool counted = (flags & BIT(0)) || (flags & 0x0e) == 8; + + if (!cookie || cookie > DATA_TX_SLOTS || counted != !!wire_count || + wire_count >= DATA_TX_SLOTS) + return false; + *count = counted ? wire_count : 1; + *first = (cookie + DATA_TX_SLOTS - *count) % DATA_TX_SLOTS; + return true; +} + +static void drain_data_tx(struct centauri_t6050_wifi *wifi) +{ + u16 head, tail, post; + unsigned int budget = DATA_TX_SLOTS; + bool posted = false, completed = false; + + if (wifi->command_failed || !(wifi->data_rings_open & BIT(5)) || + readl(wifi->a.bar + 8) != 2) + return; + head = index_read(wifi, 0, 192); + tail = index_read(wifi, 2, 192); + post = index_read(wifi, 3, 25); + if (head >= 2048 || tail >= 2048 || post >= DATA_TX_SLOTS) + return; + dma_rmb(); + while (tail != head && budget--) { + u8 *entry = wifi->a.window + 0x200000 + tail * 32; + u16 ring = get_unaligned_le32(entry) >> 16; + u16 cookie = get_unaligned_le16(entry + 4); + u16 count = get_unaligned_le16(entry + 9); + u8 status = entry[12]; + + if (ring == 25) { + unsigned int first, i; + + if (!data_tx_completion_span(cookie, count, entry[1], + &first, &count)) { + wifi->data_tx_bad++; + break; + } + for (i = 0; i < count; i++) + if (!wifi->data_tx_busy[(first + i) % + DATA_TX_SLOTS]) + break; + if (i != count) { + wifi->data_tx_bad++; + break; + } + if (count > 1) + wifi->data_tx_coalesced++; + for (i = 0; i < count; i++) { + unsigned int slot = (first + i) % DATA_TX_SLOTS; + + wifi->data_tx_completed++; + if (status == 0 || status == 0x83) { + wifi->netdev->stats.tx_packets++; + wifi->netdev->stats.tx_bytes += + wifi->data_tx_length[slot]; + } else { + wifi->data_tx_failed++; + wifi->netdev->stats.tx_errors++; + } + wifi->data_tx_busy[slot] = false; + } + } + tail = (tail + 1) % 2048; + completed = true; + } + if (completed) + index_write(wifi, 2, 192, tail); + budget = DATA_TX_SLOTS - 1; + while (wifi->connected && !READ_ONCE(wifi->stopping) && + netif_running(wifi->netdev) && budget--) { + u16 next = (post + 1) % DATA_TX_SLOTS; + u32 buffer = DATA_TX_BUFFER + post * BUFFER_SIZE; + u8 *descriptor = wifi->a.window + 0x540000 + post * 32; + struct sk_buff *skb; + u64 metadata = 6ULL << 27; + + if (wifi->data_tx_busy[post] || next == index_read(wifi, 1, 25)) + break; + skb = skb_dequeue(&wifi->data_tx_queue); + if (!skb) + break; + + if (skb_copy_bits(skb, 0, wifi->a.window + buffer, skb->len)) { + wifi->netdev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + continue; + } + memset(descriptor, 0, 32); + put_unaligned_le32(3 | (skb->len << 8), descriptor); + put_unaligned_le64(wifi->a.window_dma + buffer, descriptor + 4); + put_unaligned_le16(post + 1, descriptor + 12); + + metadata |= 4ULL << 15; + put_unaligned_le64(metadata, descriptor + 16); + put_unaligned_le64(2000000, descriptor + 24); + wifi->data_tx_length[post] = skb->len; + wifi->data_tx_busy[post] = true; + wifi->data_tx_submitted++; + dev_kfree_skb_any(skb); + post = next; + posted = true; + } + if (posted || completed) { + dma_wmb(); + if (posted) + index_write(wifi, 3, 25, post); + dma_wmb(); + writel(1, wifi->a.bar + 0x1030); + } + if (wifi->connected && !READ_ONCE(wifi->stopping) && + netif_running(wifi->netdev) && + skb_queue_len(&wifi->data_tx_queue) < DATA_TX_QUEUE_LIMIT) + netif_wake_queue(wifi->netdev); +} + +static bool link_signal_read(const u8 *packet, size_t size, s8 *signal) +{ + size_t pos = 32; + + while (pos <= size && size - pos >= 4) { + u16 tag = get_unaligned_le16(packet + pos); + u16 length = get_unaligned_le16(packet + pos + 2); + + if (length > size - pos - 4) + return false; + if (tag == 268 && length >= 115) { + *signal = (s8)packet[pos + 5]; + return *signal != 0; + } + pos += 4 + length; + } + return false; +} + +static void drain(struct centauri_t6050_wifi *wifi) +{ + unsigned int ring; + bool posted = false; + + for (ring = 2; ring <= 4; ring++) { + unsigned int budget = ring_size[ring]; + + while (budget--) { + u16 slot = wifi->rx_next[ring], size, status, sequence; + u32 command, wire_command; + u8 *descriptor = wifi->a.window + TR_BASE + + (ring - 1) * RING_SPAN + slot * 16; + u8 *packet = wifi->a.window + rx_buffer[ring] + + slot * BUFFER_SIZE; + + if (!(READ_ONCE(descriptor[15]) & 4)) + break; + dma_rmb(); + size = get_unaligned_le16(packet + 0x10); + status = get_unaligned_le16(packet + 0xe); + sequence = get_unaligned_le16(packet + 0x12); + wire_command = get_unaligned_le32(packet + 0x14); + command = wire_command & ~BIT(30); + wifi->rx_seen[ring]++; + wifi->rx_next[ring] = (slot + 1) % ring_size[ring]; + if (size < 24 || size > BUFFER_SIZE) + goto refill; + if (ring == 4) { + report_beacon(wifi, packet + 24, size - 24); + } else if (command & BIT(31)) { + if (command == 0x80000030) + wifi->channels_seen++; + if (command == 0x80000005) + wifi->scans_done++; + if (command == 0x80000000 && wifi->connecting) { + wifi->connect_event = true; + wifi->connect_status = status; + } + if (command == 0x80000003 || + command == 0x80000004) + wifi->disconnect_event = true; + if (command == 0x80000004) + wifi->disconnect_pending = false; + + } else { + wifi->reply_valid = true; + wifi->reply_sequence = sequence; + wifi->reply_status = status; + + wifi->reply_command = wire_command; + if (command == 10) { + wifi->country_valid = !status && + size >= 27; + if (wifi->country_valid) + memcpy(wifi->country, + packet + 24, 3); + } + + if (command == 20 && !status) { + wifi->station_signal_valid = + link_signal_read( + packet, size, + &wifi->station_signal); + wifi->station_signal_at = jiffies; + } + } +refill: + post_receive(wifi, ring, wifi->rx_head[ring]); + wifi->rx_head[ring] = + (wifi->rx_head[ring] + 1) % ring_size[ring]; + dma_wmb(); + index_write(wifi, 3, ring, wifi->rx_head[ring]); + posted = true; + } + } + completions(wifi); + if (posted) + writel(1, wifi->a.bar + 0x1004); + drain_data_rx(wifi); + drain_data_tx(wifi); +} + +/* Caller holds wifi->lock. Unknown completion keeps DMA payloads owned. */ +static void command_fault(struct centauri_t6050_wifi *wifi) +{ + wifi->command_failed = true; + wifi->configured = false; + wifi->data_failed = true; + netif_stop_queue(wifi->netdev); + if (smp_load_acquire(&wifi->irq_ready)) + schedule_work(&wifi->link_work); +} + +static bool command_payload_consumed(struct centauri_t6050_wifi *wifi, u16 slot) +{ + if (slot >= ring_size[1] || + index_read(wifi, 1, 1) != (slot + 1) % ring_size[1]) + return false; + dma_rmb(); + return true; +} + +static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload, + size_t size) +{ + u16 slot = wifi->command_head, sequence = ++wifi->sequence; + u32 stage; + u8 *packet, *descriptor; + unsigned long deadline = jiffies + msecs_to_jiffies(1500); + + if (wifi->command_failed) + return -EIO; + if (size > BUFFER_SIZE - 24) + return -EMSGSIZE; + if ((slot + 1) % ring_size[1] == index_read(wifi, 1, 1)) + return -ENOSPC; + packet = wifi->a.window + TX_BUFFER + slot * BUFFER_SIZE; + memset(packet, 0, 24 + size); + put_unaligned_le16(24 + size, packet + 0x10); + put_unaligned_le16(sequence, packet + 0x12); + put_unaligned_le32(id, packet + 0x14); + if (size) + memcpy(packet + 24, payload, size); + descriptor = wifi->a.window + TR_BASE + slot * 16; + put_unaligned_le32(1 | ((24 + size) << 8), descriptor); + put_unaligned_le64(wifi->a.window_dma + TX_BUFFER + slot * BUFFER_SIZE, + descriptor + 4); + put_unaligned_le32(slot + 1, descriptor + 12); + dma_wmb(); + wifi->command_head = (slot + 1) % ring_size[1]; + index_write(wifi, 3, 1, wifi->command_head); + wifi->reply_valid = false; + dma_wmb(); + writel(1, wifi->a.bar + 0x1004); + do { + if (READ_ONCE(wifi->stopping) || + READ_ONCE(wifi->control->removing)) { + command_fault(wifi); + return -ECANCELED; + } + drain(wifi); + stage = readl(wifi->a.bar + 8); + if (stage != 2) { + dev_err(&wifi->control->pdev->dev, + "Wi-Fi command %#x lost transport: stage=%#x sequence=%u rx=%u\n", + id, stage, sequence, wifi->rx_seen[2]); + command_fault(wifi); + return -EIO; + } + + if (wifi->reply_valid && wifi->reply_sequence == sequence && + (wifi->reply_command & ~BIT(30)) == id) { + return wifi->reply_status ? -EREMOTEIO : 0; + } + usleep_range(500, 1000); + } while (time_before(jiffies, deadline)); + dev_err(&wifi->control->pdev->dev, + "Wi-Fi command %#x timed out (rx=%u)\n", id, wifi->rx_seen[2]); + command_fault(wifi); + return -ETIMEDOUT; +} + +static int station_configure(struct centauri_t6050_wifi *wifi, const u8 *address) +{ + u8 start[5 + 4 + 3 * ETH_ALEN] = { 0, 0x0b, 0, 0, 0 }; + size_t start_size = 5; + int ret; + + ret = command(wifi, 1, address, ETH_ALEN); + if (!ret) + ret = command(wifi, 2, start, start_size); + return ret; +} + +static int radio_start(struct centauri_t6050_wifi *wifi) +{ + unsigned int ring, slot; + int ret; + + for (ring = 1; ring <= 4; ring++) { + ret = open_pair(wifi, ring); + if (ret) + return ret; + } + for (ring = 2; ring <= 4; ring++) { + for (slot = 0; slot < ring_size[ring] - 1; slot++) + post_receive(wifi, ring, slot); + wifi->rx_head[ring] = ring_size[ring] - 1; + dma_wmb(); + index_write(wifi, 3, ring, ring_size[ring] - 1); + } + dma_wmb(); + writel(1, wifi->a.bar + 0x1004); + msleep(400); + ret = command(wifi, 0, NULL, 0); + if (!ret) + ret = station_configure(wifi, wifi->netdev->dev_addr); + if (ret) + return ret; + msleep(1000); + wifi->configured = true; + return 0; +} + +#define CEN_SCAN_CHANNELS_MAX 59 +static int scan_profile27(struct centauri_t6050_wifi *wifi) +{ + struct cfg80211_scan_request *request = wifi->scan_request; + u8 scan[14 + 5 + 4 * CEN_SCAN_CHANNELS_MAX + 9 + 4 + 2 + 32]; + unsigned int next = 0; + + if (!request || !request->n_channels || request->n_ssids > 1) + return -EINVAL; + while (next < request->n_channels) { + u8 channels[1 + 4 * CEN_SCAN_CHANNELS_MAX] = {}; + u8 options[5] = { 0, 0, 1, 0, 0 }; + unsigned int count = 0; + u32 done = wifi->scans_done; + size_t size = 14; + unsigned long deadline; + int ret; + bool abort_sent = false; + + if (READ_ONCE(wifi->scan_abort)) + return -ECANCELED; + memset(scan, 0, sizeof(scan)); + scan[0] = (++wifi->scan_sequence) & 0x1f; + scan[3] = 0x80; + scan[5] = 2; + scan[7] = 0x10; + + put_unaligned_le16(40, scan + 8); + put_unaligned_le16(40, scan + 10); + put_unaligned_le16(110, scan + 12); + while (next < request->n_channels && + count < CEN_SCAN_CHANNELS_MAX) { + struct ieee80211_channel *channel = + request->channels[next++]; + unsigned int number; + + /* The passive-scan wire mode is not established for this profile. */ + if (channel->flags & + (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_NO_IR)) + continue; + if (channel->band != NL80211_BAND_2GHZ && + channel->band != NL80211_BAND_5GHZ) + return -EOPNOTSUPP; + number = ieee80211_frequency_to_channel( + channel->center_freq); + if (!number || number > 255) + return -EINVAL; + channels[1 + 4 * count] = number; + channels[2 + 4 * count] = channel->band == + NL80211_BAND_5GHZ; + count++; + } + if (!count) + continue; + channels[0] = count; + put_unaligned_le16(260, scan + size); + put_unaligned_le16(1 + 4 * count, scan + size + 2); + memcpy(scan + size + 4, channels, 1 + 4 * count); + size += 5 + 4 * count; + put_unaligned_le16(357, scan + size); + put_unaligned_le16(sizeof(options), scan + size + 2); + memcpy(scan + size + 4, options, sizeof(options)); + size += 4 + sizeof(options); + if (request->n_ssids) { + const struct cfg80211_ssid *ssid = &request->ssids[0]; + + if (ssid->ssid_len > 32) + return -EINVAL; + + scan[2] = !!ssid->ssid_len; + put_unaligned_le16(258, scan + size); + put_unaligned_le16(2 + ssid->ssid_len, scan + size + 2); + scan[size + 4] = ssid->ssid_len ? 5 : 4; + scan[size + 5] = ssid->ssid_len; + memcpy(scan + size + 6, ssid->ssid, ssid->ssid_len); + size += 6 + ssid->ssid_len; + } + ret = command(wifi, 65551, scan, size); + if (ret) + return ret; + deadline = jiffies + + msecs_to_jiffies(max(8000U, count * 220 + 2000)); + do { + drain(wifi); + if (READ_ONCE(wifi->stopping) || + readl(wifi->a.bar + 8) != 2) + return -EIO; + if (wifi->scans_done != done) + break; + if (READ_ONCE(wifi->scan_abort) && !abort_sent) { + ret = command(wifi, 65537, NULL, 0); + if (ret) + return ret; + abort_sent = true; + } + usleep_range(1000, 2000); + } while (time_before(jiffies, deadline)); + if (wifi->scans_done == done) { + command(wifi, 65537, NULL, 0); + return -ETIMEDOUT; + } + if (READ_ONCE(wifi->scan_abort)) + return -ECANCELED; + } + return 0; +} + +static void scan_worker(struct work_struct *work) +{ + struct centauri_t6050_wifi *wifi = + container_of(work, struct centauri_t6050_wifi, scan_work); + struct cfg80211_scan_info info = {}; + struct cfg80211_scan_request *request; + int ret = 0; + + mutex_lock(&wifi->lock); + if (READ_ONCE(wifi->scan_abort) || READ_ONCE(wifi->stopping)) { + ret = -ECANCELED; + goto completed; + } + { + ret = scan_profile27(wifi); + goto completed; + } +completed: + info.aborted = !!ret || READ_ONCE(wifi->scan_abort) || + READ_ONCE(wifi->stopping); + request = wifi->scan_request; + wifi->scan_request = NULL; + mutex_unlock(&wifi->lock); + if (request) + cfg80211_scan_done(request, &info); +} + +static int wifi_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + int ret = 0; + + mutex_lock(&wifi->lock); + if (READ_ONCE(wifi->stopping)) + ret = -ENODEV; + else if (wifi->command_failed) + ret = -EIO; + else if (!wifi->configured) + ret = -ENETDOWN; + else if (wifi->scan_request || wifi->connecting || + wifi->disconnect_pending) + ret = -EBUSY; + else { + WRITE_ONCE(wifi->scan_abort, false); + wifi->scan_request = request; + schedule_work(&wifi->scan_work); + } + mutex_unlock(&wifi->lock); + return ret; +} + +static void wifi_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + + if (wdev == &wifi->wdev) + WRITE_ONCE(wifi->scan_abort, true); +} + +static void cancel_scan(struct centauri_t6050_wifi *wifi) +{ + struct cfg80211_scan_info info = { .aborted = true }; + struct cfg80211_scan_request *request; + + WRITE_ONCE(wifi->scan_abort, true); + cancel_work_sync(&wifi->scan_work); + mutex_lock(&wifi->lock); + request = wifi->scan_request; + wifi->scan_request = NULL; + mutex_unlock(&wifi->lock); + + if (request) + cfg80211_scan_done(request, &info); +} + +static void cancel_connect_locked(struct centauri_t6050_wifi *wifi) +{ + if (!wifi->connecting) + return; + wifi->connecting = false; + wifi->connected = false; + memzero_explicit(wifi->connect_payload, sizeof(wifi->connect_payload)); + cfg80211_connect_timeout(wifi->netdev, wifi->bssid, wifi->request_ie, + wifi->request_ie_size, GFP_KERNEL, + NL80211_TIMEOUT_UNSPECIFIED); +} + +static int rsn_caps_offset(const u8 *body, size_t size) +{ + size_t offset = 6; + u16 count; + unsigned int i; + + for (i = 0; i < 2; i++) { + if (offset + 2 > size) + return -EINVAL; + count = get_unaligned_le16(body + offset); + offset += 2 + 4 * count; + if (offset > size) + return -EINVAL; + } + return offset + 2 <= size ? offset : -EINVAL; +} + +static int rsn_psk_offset(const u8 *body, size_t size) +{ + size_t offset, end; + u16 count; + unsigned int i; + + if (size < 8 || get_unaligned_le16(body) != 1) + return -EINVAL; + count = get_unaligned_le16(body + 6); + if (!count) + return -EINVAL; + offset = 8 + 4 * count; + if (offset + 2 > size) + return -EINVAL; + count = get_unaligned_le16(body + offset); + end = offset + 2 + 4 * count; + if (!count || end + 2 > size) + return -EINVAL; + for (i = 0; i < count; i++) + if (get_unaligned_be32(body + offset + 2 + 4 * i) == + WLAN_AKM_SUITE_PSK) + return offset; + return -EOPNOTSUPP; +} + +static int select_psk_rsn(const struct cfg80211_crypto_settings *crypto, + const u8 *body, size_t size, u8 *selected) +{ + size_t tail; + unsigned int i; + int offset; + + for (i = 0; i < crypto->n_akm_suites; i++) + if (crypto->akm_suites[i] == WLAN_AKM_SUITE_PSK) + break; + if (i == crypto->n_akm_suites) + return -EOPNOTSUPP; + offset = rsn_psk_offset(body, size); + if (offset < 0) + return offset; + + if (get_unaligned_be32(body + 2) != WLAN_CIPHER_SUITE_CCMP || + get_unaligned_le16(body + 6) != 1 || + get_unaligned_be32(body + 8) != WLAN_CIPHER_SUITE_CCMP) + return -EOPNOTSUPP; + tail = offset + 2 + 4 * get_unaligned_le16(body + offset); + memcpy(selected, body, offset); + put_unaligned_le16(1, selected + offset); + put_unaligned_be32(WLAN_AKM_SUITE_PSK, selected + offset + 2); + memcpy(selected + offset + 6, body + tail, size - tail); + return offset + 6 + size - tail; +} + +static void append_tlv(u8 *payload, size_t *size, u16 tag, const void *data, + u16 length) +{ + put_unaligned_le16(tag, payload + *size); + put_unaligned_le16(length, payload + *size + 2); + memcpy(payload + *size + 4, data, length); + *size += 4 + length; +} + +static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, + struct cfg80211_connect_params *params) +{ + static const u8 mld_defaults[14] = { + 1, 0, 1, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 3, 0, 0, + }; + + static const __le32 connection_timeouts[] = { + cpu_to_le32(260), cpu_to_le32(6000), cpu_to_le32(2000), + cpu_to_le32(15000), cpu_to_le32(300), + }; + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + struct cfg80211_bss *bss; + const struct cfg80211_bss_ies *ies; + const u8 *rsn, *ap_rsn; + u8 rsn_body[255], ssid[35], zero[20] = {}, pmf; + u8 *payload = wifi->connect_payload; + size_t size = 130, rsn_size, rsn_prefix, rsn_tail; + u16 caps = 0; + int ret = 0, offset; + + if (!params->ssid_len || params->ssid_len > 32 || !params->crypto.psk || + params->crypto.n_ciphers_pairwise != 1 || + params->crypto.ciphers_pairwise[0] != WLAN_CIPHER_SUITE_CCMP || + params->crypto.cipher_group != WLAN_CIPHER_SUITE_CCMP || + params->ie_len > sizeof(wifi->request_ie)) + return -EOPNOTSUPP; + rsn = cfg80211_find_ie(WLAN_EID_RSN, params->ie, params->ie_len); + if (!rsn) + return -EINVAL; + ret = select_psk_rsn(¶ms->crypto, rsn + 2, rsn[1], rsn_body); + if (ret < 0) + return ret; + rsn_size = ret; + ret = 0; + mutex_lock(&wifi->lock); + if (READ_ONCE(wifi->stopping)) { + ret = -ENODEV; + goto out; + } + if (!wifi->configured || wifi->connecting || wifi->connected || + wifi->scan_request || wifi->disconnect_pending) { + ret = -EBUSY; + goto out; + } + + bss = cfg80211_get_bss(wiphy, params->channel, params->bssid, + params->ssid, params->ssid_len, + IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ON); + if (!bss) { + ret = -ENOENT; + goto out; + } + + rcu_read_lock(); + ies = rcu_dereference(bss->ies); + ap_rsn = ies ? cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len) : + NULL; + if (!ap_rsn) { + ret = -EINVAL; + } else { + ret = rsn_psk_offset(ap_rsn + 2, ap_rsn[1]); + if (ret >= 0) { + offset = rsn_caps_offset(ap_rsn + 2, ap_rsn[1]); + caps = get_unaligned_le16(ap_rsn + 2 + offset); + ret = 0; + } + } + rcu_read_unlock(); + if (ret) { + cfg80211_put_bss(wiphy, bss); + goto out; + } + offset = rsn_caps_offset(rsn_body, rsn_size); + put_unaligned_le16(caps, rsn_body + offset); + pmf = !!(caps & BIT(7)); + memset(payload, 0, sizeof(wifi->connect_payload)); + payload[0] = 1; + memcpy(payload + 1, bss->bssid, ETH_ALEN); + memcpy(wifi->bssid, bss->bssid, ETH_ALEN); + payload[7] = ieee80211_frequency_to_channel(bss->channel->center_freq); + + payload[8] = bss->channel->band == NL80211_BAND_2GHZ ? 0 : 1; + payload[0x47] = 4; + + put_unaligned_le16(4, payload + 0x48); + put_unaligned_le16(32, payload + 0x4a); + memcpy(payload + 0x4c, params->crypto.psk, 32); + + append_tlv(payload, &size, 304, zero, 1); + append_tlv(payload, &size, 63763, connection_timeouts, + sizeof(connection_timeouts)); + ssid[0] = 1; + ssid[1] = 4; + ssid[2] = params->ssid_len; + memcpy(ssid + 3, params->ssid, params->ssid_len); + append_tlv(payload, &size, 342, ssid, 3 + params->ssid_len); + append_tlv(payload, &size, WLAN_EID_RSN, rsn_body, rsn_size); + + append_tlv(payload, &size, 316, &pmf, 1); + append_tlv(payload, &size, 376, mld_defaults, sizeof(mld_defaults)); + wifi->connect_size = size; + + rsn_prefix = rsn - params->ie; + rsn_tail = rsn_prefix + 2 + rsn[1]; + memcpy(wifi->request_ie, params->ie, rsn_prefix); + wifi->request_ie[rsn_prefix] = WLAN_EID_RSN; + wifi->request_ie[rsn_prefix + 1] = rsn_size; + memcpy(wifi->request_ie + rsn_prefix + 2, rsn_body, rsn_size); + memcpy(wifi->request_ie + rsn_prefix + 2 + rsn_size, + params->ie + rsn_tail, params->ie_len - rsn_tail); + wifi->request_ie_size = params->ie_len - rsn[1] + rsn_size; + WRITE_ONCE(wifi->connect_abort, false); + wifi->connecting = true; + wifi->connect_status = 0; + wifi->connect_event = wifi->disconnect_event = false; + cfg80211_put_bss(wiphy, bss); + schedule_work(&wifi->connect_work); +out: + mutex_unlock(&wifi->lock); + return ret; +} + +static void connect_worker(struct work_struct *work) +{ + struct centauri_t6050_wifi *wifi = + container_of(work, struct centauri_t6050_wifi, connect_work); + unsigned long deadline; + u16 slot, status; + int ret; + + mutex_lock(&wifi->lock); + if (READ_ONCE(wifi->connect_abort) || READ_ONCE(wifi->stopping)) { + cancel_connect_locked(wifi); + mutex_unlock(&wifi->lock); + return; + } + slot = wifi->command_head; + ret = command(wifi, 131072, wifi->connect_payload, wifi->connect_size); + memzero_explicit(wifi->connect_payload, sizeof(wifi->connect_payload)); + deadline = jiffies + msecs_to_jiffies(15000); + while (!ret && !wifi->connect_event && + !READ_ONCE(wifi->connect_abort) && !READ_ONCE(wifi->stopping) && + time_before(jiffies, deadline)) { + drain(wifi); + + if (wifi->disconnect_event) + ret = -ENOTCONN; + if (readl(wifi->a.bar + 8) != 2) + ret = -EIO; + usleep_range(1000, 2000); + } + if (READ_ONCE(wifi->connect_abort) || READ_ONCE(wifi->stopping)) + ret = -ECANCELED; + else if (!ret && !wifi->connect_event) + ret = -ETIMEDOUT; + status = !ret && wifi->connect_status == 0 ? + WLAN_STATUS_SUCCESS : + WLAN_STATUS_UNSPECIFIED_FAILURE; + wifi->connecting = false; + wifi->connected = status == WLAN_STATUS_SUCCESS; + wifi->station_signal_valid = false; + if (wifi->connected) { + wifi->connected_at = jiffies; + wifi->station_signal_at = jiffies - HZ; + wifi->station_start = wifi->netdev->stats; + } + + if (command_payload_consumed(wifi, slot)) + memzero_explicit(wifi->a.window + TX_BUFFER + + slot * BUFFER_SIZE, + BUFFER_SIZE); + + if (ret == -ECANCELED || ret == -ETIMEDOUT) + cfg80211_connect_timeout(wifi->netdev, wifi->bssid, + wifi->request_ie, + wifi->request_ie_size, GFP_KERNEL, + NL80211_TIMEOUT_UNSPECIFIED); + else + cfg80211_connect_result(wifi->netdev, wifi->bssid, + wifi->request_ie, wifi->request_ie_size, + NULL, 0, status, GFP_KERNEL); + if (status == WLAN_STATUS_SUCCESS && !READ_ONCE(wifi->stopping)) { + cfg80211_port_authorized(wifi->netdev, wifi->bssid, NULL, 0, + GFP_KERNEL); + netif_carrier_on(wifi->netdev); + if (wifi->data_rings_open & BIT(5)) + netif_wake_queue(wifi->netdev); + schedule_work(&wifi->link_work); + } + mutex_unlock(&wifi->lock); +} + +irqreturn_t centauri_t6050_alpha_irq(int irq, void *data) +{ + struct centauri_t6050 *c = data; + struct centauri_t6050_wifi *wifi = smp_load_acquire(&c->wifi); + + if (wifi && smp_load_acquire(&wifi->irq_ready) && + !READ_ONCE(wifi->stopping)) + schedule_work(&wifi->link_work); + return IRQ_HANDLED; +} + +static void link_worker(struct work_struct *work) +{ + struct centauri_t6050_wifi *wifi = + container_of(work, struct centauri_t6050_wifi, link_work); + bool disconnected, was_connected; + + mutex_lock(&wifi->lock); + was_connected = wifi->connected; + drain(wifi); + disconnected = wifi->command_failed || wifi->disconnect_event || + READ_ONCE(wifi->stopping) || readl(wifi->a.bar + 8) != 2; + if (disconnected) + wifi->connected = false; + if (disconnected && was_connected) { + netif_stop_queue(wifi->netdev); + skb_queue_purge(&wifi->data_tx_queue); + netif_carrier_off(wifi->netdev); + cfg80211_disconnected(wifi->netdev, WLAN_REASON_UNSPECIFIED, + NULL, 0, false, GFP_KERNEL); + } + mutex_unlock(&wifi->lock); +} + +static int wait_disconnect(struct centauri_t6050_wifi *wifi) +{ + unsigned long deadline = jiffies + msecs_to_jiffies(5000); + + while (wifi->disconnect_pending) { + drain(wifi); + if (READ_ONCE(wifi->stopping) || readl(wifi->a.bar + 8) != 2) + return -EIO; + if (!wifi->disconnect_pending) + break; + if (time_after_eq(jiffies, deadline)) + return -ETIMEDOUT; + usleep_range(500, 1000); + } + return 0; +} + +static int wifi_disconnect(struct wiphy *wiphy, struct net_device *netdev, + u16 reason) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + u8 payload[16] = {}; + bool connected; + u16 reply_status; + int ret; + + WRITE_ONCE(wifi->connect_abort, true); + cancel_scan(wifi); + cancel_work_sync(&wifi->connect_work); + mutex_lock(&wifi->lock); + cancel_connect_locked(wifi); + put_unaligned_le16(reason, payload); + put_unaligned_le16(328, payload + 8); + put_unaligned_le16(4, payload + 10); + + put_unaligned_le32(10, payload + 12); + wifi->disconnect_pending = !READ_ONCE(wifi->stopping); + ret = READ_ONCE(wifi->stopping) ? + 0 : + command(wifi, 131073, payload, sizeof(payload)); + reply_status = wifi->reply_status; + if (!ret && wifi->disconnect_pending && (wifi->reply_command & BIT(30))) + ret = wait_disconnect(wifi); + else if (ret != -EIO && ret != -ETIMEDOUT) + wifi->disconnect_pending = false; + + connected = wifi->connected; + wifi->connected = false; + netif_stop_queue(netdev); + skb_queue_purge(&wifi->data_tx_queue); + netif_carrier_off(netdev); + if (connected) + cfg80211_disconnected(netdev, reason, NULL, 0, true, + GFP_KERNEL); + mutex_unlock(&wifi->lock); + cancel_work_sync(&wifi->link_work); + return ret == -EREMOTEIO && reply_status == 326 ? 0 : ret; +} + +static int wifi_power_mgmt(struct wiphy *wiphy, struct net_device *netdev, + bool enabled, int timeout) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + u8 mode = enabled ? 0 : 3; + int ret; + + mutex_lock(&wifi->lock); + ret = wifi->configured ? command(wifi, 7, &mode, sizeof(mode)) : + -ENETDOWN; + mutex_unlock(&wifi->lock); + return ret; +} + +static void wifi_regulatory(struct wiphy *wiphy, + struct regulatory_request *request) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + u8 country[3] = { request->alpha2[0], request->alpha2[1], 1 }; + int ret; + + if (country[0] < 'A' || country[0] > 'Z' || country[1] < 'A' || + country[1] > 'Z') + return; + mutex_lock(&wifi->lock); + if (wifi->configured) { + ret = command(wifi, 9, country, sizeof(country)); + if (ret) + dev_err(&wifi->control->pdev->dev, + "firmware country update failed: %d\n", ret); + } + mutex_unlock(&wifi->lock); +} + +static void fill_station(struct centauri_t6050_wifi *wifi, struct station_info *sinfo) +{ + const struct net_device_stats *stats = &wifi->netdev->stats; + + if (time_after_eq(jiffies, wifi->station_signal_at + HZ)) { + wifi->station_signal_valid = false; + wifi->station_signal_at = jiffies; + query_link_status(wifi); + } + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) | + BIT_ULL(NL80211_STA_INFO_RX_BYTES64) | + BIT_ULL(NL80211_STA_INFO_TX_BYTES64) | + BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | + BIT_ULL(NL80211_STA_INFO_TX_PACKETS); + sinfo->connected_time = (jiffies - wifi->connected_at) / HZ; + sinfo->rx_bytes = stats->rx_bytes - wifi->station_start.rx_bytes; + sinfo->tx_bytes = stats->tx_bytes - wifi->station_start.tx_bytes; + sinfo->rx_packets = stats->rx_packets - wifi->station_start.rx_packets; + sinfo->tx_packets = stats->tx_packets - wifi->station_start.tx_packets; + if (wifi->station_signal_valid) { + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); + sinfo->signal = wifi->station_signal; + } +} + +static int wifi_get_station(struct wiphy *wiphy, struct wireless_dev *wdev, + const u8 *mac, struct station_info *sinfo) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + int ret = 0; + + mutex_lock(&wifi->lock); + if (wdev != &wifi->wdev || !wifi->connected || + READ_ONCE(wifi->stopping) || !ether_addr_equal(mac, wifi->bssid)) + ret = -ENOENT; + else + fill_station(wifi, sinfo); + mutex_unlock(&wifi->lock); + return ret; +} + +static int wifi_dump_station(struct wiphy *wiphy, struct wireless_dev *wdev, + int index, u8 *mac, struct station_info *sinfo) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + int ret = 0; + + mutex_lock(&wifi->lock); + if (index || wdev != &wifi->wdev || !wifi->connected || + READ_ONCE(wifi->stopping)) + ret = -ENOENT; + else { + ether_addr_copy(mac, wifi->bssid); + fill_station(wifi, sinfo); + } + mutex_unlock(&wifi->lock); + return ret; +} + +static const struct cfg80211_ops wifi_ops = { + .scan = wifi_scan, + .abort_scan = wifi_abort_scan, + .connect = wifi_connect, + .disconnect = wifi_disconnect, + .set_power_mgmt = wifi_power_mgmt, + .get_station = wifi_get_station, + .dump_station = wifi_dump_station, +}; + +static int data_start(struct centauri_t6050_wifi *wifi); + +static int net_open(struct net_device *netdev) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)netdev_priv(netdev); + int ret; + + netif_carrier_off(netdev); + netif_stop_queue(netdev); + mutex_lock(&wifi->lock); + ret = wifi->configured ? data_start(wifi) : -ENETDOWN; + mutex_unlock(&wifi->lock); + return ret; +} + +static int net_stop(struct net_device *netdev) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)netdev_priv(netdev); + + cancel_scan(wifi); + netif_stop_queue(netdev); + skb_queue_purge(&wifi->data_tx_queue); + return 0; +} + +static netdev_tx_t net_transmit(struct sk_buff *skb, struct net_device *netdev) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)netdev_priv(netdev); + + if (READ_ONCE(wifi->stopping) || !READ_ONCE(wifi->connected) || + skb->len < ETH_HLEN || skb->len > BUFFER_SIZE) { + netdev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + if (skb_queue_len(&wifi->data_tx_queue) >= DATA_TX_QUEUE_LIMIT) { + netif_stop_queue(netdev); + return NETDEV_TX_BUSY; + } + skb_queue_tail(&wifi->data_tx_queue, skb); + if (skb_queue_len(&wifi->data_tx_queue) >= DATA_TX_QUEUE_LIMIT) + netif_stop_queue(netdev); + schedule_work(&wifi->link_work); + return NETDEV_TX_OK; +} + +static int station_reconfigure(struct centauri_t6050_wifi *wifi, const u8 *address) +{ + const u8 stop[5] = {}; + int ret; + + wifi->configured = false; + ret = command(wifi, 3, stop, sizeof(stop)); + if (!ret) + ret = station_configure(wifi, address); + if (!ret) + wifi->configured = true; + return ret; +} + +static int net_set_mac_address(struct net_device *netdev, void *data) +{ + struct centauri_t6050_wifi *wifi = + *(struct centauri_t6050_wifi **)netdev_priv(netdev); + struct sockaddr *address = data; + int ret, restore; + + ret = eth_prepare_mac_addr_change(netdev, data); + if (ret) + return ret; + mutex_lock(&wifi->lock); + if (READ_ONCE(wifi->stopping)) { + ret = -ENODEV; + goto out; + } + if (!wifi->configured) { + ret = -ENETDOWN; + goto out; + } + if (wifi->connecting || wifi->connected || wifi->scan_request || + wifi->disconnect_pending) { + ret = -EBUSY; + goto out; + } + if (ether_addr_equal(netdev->dev_addr, address->sa_data)) + goto out; + + ret = station_reconfigure(wifi, (const u8 *)address->sa_data); + if (!ret) { + eth_commit_mac_addr_change(netdev, data); + } else { + restore = station_reconfigure(wifi, netdev->dev_addr); + if (restore) + dev_err(&wifi->control->pdev->dev, + "Wi-Fi MAC restore failed: %d (change: %d)\n", + restore, ret); + } +out: + mutex_unlock(&wifi->lock); + return ret; +} + +static const struct net_device_ops net_ops = { + .ndo_open = net_open, + .ndo_stop = net_stop, + .ndo_start_xmit = net_transmit, + .ndo_validate_addr = eth_validate_addr, + .ndo_set_mac_address = net_set_mac_address, +}; + +static int data_ring_open(struct centauri_t6050_wifi *wifi, unsigned int id) +{ + u8 message[0x34 + 10] = { 0 }; + unsigned int vector, offset, size, bit, doorbell, irq; + bool transfer = false; + int ret; + + lockdep_assert_held(&wifi->lock); + if (wifi->data_failed) + return -EIO; + if (id == 76) { + vector = 192; + offset = 0x200000; + size = 2048; + bit = 0; + doorbell = 18; + irq = 3; + } else if (id == 14) { + vector = 206; + offset = 0x220000; + size = 256; + bit = 1; + doorbell = 11; + irq = 8; + } else if (id == 15) { + vector = 207; + offset = 0x240000; + size = DATA_RX_SLOTS; + bit = 2; + doorbell = 11; + irq = 8; + } else if (id == 24 || id == 25 || id == 12) { + transfer = true; + vector = id; + offset = id == 12 ? 0x520000 : id == 24 ? 0x500000 : 0x540000; + size = id == 12 ? DATA_RX_SLOTS : DATA_TX_SLOTS; + bit = id == 12 ? 4 : id == 24 ? 3 : 5; + doorbell = id == 12 ? 11 : 18; + irq = id == 12 ? 8 : 3; + } else { + return -EINVAL; + } + if (readl(wifi->a.bar + 8) != 2) { + ret = -EIO; + goto out; + } + if (wifi->data_rings_open & BIT(bit)) + return 0; + if (wifi->connecting || wifi->scan_request) { + ret = -EBUSY; + goto out; + } + memset(wifi->a.window + offset, 0, size * 32); + index_write(wifi, transfer ? 1 : 0, vector, 0); + index_write(wifi, transfer ? 3 : 2, vector, 0); + message[0] = transfer ? 1 : 2; + message[2] = transfer && id == 12 ? 0 : 4; + put_unaligned_le16(id, message + 4); + put_unaligned_le16(vector, message + 6); + put_unaligned_le64(wifi->a.window_dma + offset, message + 8); + if (transfer) { + put_unaligned_le64(~0ULL, message + 0x10); + put_unaligned_le16(size, message + 0x18); + put_unaligned_le16(id == 12 ? 12 : 76, message + 0x1a); + put_unaligned_le16(doorbell, message + 0x1c); + put_unaligned_le16(id == 12 ? 0x220 : 0, message + 0x1e); + put_unaligned_le32(16, message + 0x20); + put_unaligned_le16(irq, message + 0x24); + } else { + put_unaligned_le16(size, message + 0x10); + put_unaligned_le16(id == 15 ? 12 : 0xffff, message + 0x12); + put_unaligned_le16(doorbell, message + 0x14); + put_unaligned_le32(1, message + 0x18); + put_unaligned_le16(irq, message + 0x1c); + } + + ret = alpha_message(wifi, message, (transfer ? 0x34 : 0x2c) + 10); + if (!ret && readl(wifi->a.bar + 8) != 2) + ret = -EIO; + if (ret) { + wifi->data_failed = true; + goto out; + } + wifi->data_rings_open |= BIT(bit); + if (transfer && id == 12) { + unsigned int slot; + + for (slot = 0; slot < size - 1; slot++) { + u8 *descriptor = wifi->a.window + offset + slot * 16; + u32 buffer = DATA_RX_BUFFER + slot * 4096; + + memset(wifi->a.window + buffer, 0, 4096); + put_unaligned_le32(1 | (4096 << 8), descriptor); + put_unaligned_le64(wifi->a.window_dma + buffer, + descriptor + 4); + put_unaligned_le32(slot + 1, descriptor + 12); + } + dma_wmb(); + index_write(wifi, 3, vector, size - 1); + dma_wmb(); + writel(1, wifi->a.bar + 0x1050); + } +out: + return ret; +} + +static int data_start(struct centauri_t6050_wifi *wifi) +{ + static const unsigned int rings[] = { 76, 15, 12, 25 }; + int ret; + + for (unsigned int i = 0; i < ARRAY_SIZE(rings); i++) { + ret = data_ring_open(wifi, rings[i]); + if (ret) + return ret; + } + return 0; +} + +static int query_link_status(struct centauri_t6050_wifi *wifi) +{ + return wifi->configured ? command(wifi, 20, NULL, 0) : -ENETDOWN; +} + +int centauri_t6050_wifi_register(struct centauri_t6050 *c) +{ + struct centauri_t6050_wifi *wifi; + u8 address[ETH_ALEN]; + unsigned int i; + int ret; + + wifi = kzalloc_obj(*wifi); + if (!wifi) + return -ENOMEM; + wifi->control = c; + mutex_init(&wifi->lock); + skb_queue_head_init(&wifi->data_tx_queue); + INIT_WORK(&wifi->scan_work, scan_worker); + INIT_WORK(&wifi->connect_work, connect_worker); + INIT_WORK(&wifi->link_work, link_worker); + smp_store_release(&c->wifi, wifi); + ret = centauri_t6050_alpha_resources(c, &wifi->a); + if (ret) + goto failed; + wifi->wiphy = wiphy_new(&wifi_ops, sizeof(struct centauri_t6050_wifi *)); + wifi->netdev = alloc_etherdev(sizeof(struct centauri_t6050_wifi *)); + if (!wifi->wiphy || !wifi->netdev) { + ret = -ENOMEM; + goto failed; + } + *(struct centauri_t6050_wifi **)wiphy_priv(wifi->wiphy) = wifi; + *(struct centauri_t6050_wifi **)netdev_priv(wifi->netdev) = wifi; + set_wiphy_dev(wifi->wiphy, &c->pdev->dev); + wifi->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); + wifi->wiphy->max_scan_ssids = 1; + wifi->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; + wifi->wiphy->reg_notifier = wifi_regulatory; + wifi->wiphy->cipher_suites = cipher_suites; + wifi->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); + wifi->wiphy->akm_suites = akm_suites; + wifi->wiphy->n_akm_suites = ARRAY_SIZE(akm_suites); + wiphy_ext_feature_set(wifi->wiphy, + NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK); + for (i = 0; i < 13; i++) { + wifi->channels[i].band = NL80211_BAND_2GHZ; + wifi->channels[i].hw_value = i + 1; + wifi->channels[i].center_freq = ieee80211_channel_to_frequency( + i + 1, NL80211_BAND_2GHZ); + wifi->channels[i].max_power = 20; + } + for (i = 0; i < ARRAY_SIZE(five_ghz); i++) { + wifi->channels[13 + i].band = NL80211_BAND_5GHZ; + wifi->channels[13 + i].hw_value = five_ghz[i]; + wifi->channels[13 + i].center_freq = + ieee80211_channel_to_frequency(five_ghz[i], + NL80211_BAND_5GHZ); + wifi->channels[13 + i].max_power = 20; + } + wifi->bands[0].channels = wifi->channels; + wifi->bands[0].n_channels = 13; + wifi->bands[0].bitrates = rates; + wifi->bands[0].n_bitrates = ARRAY_SIZE(rates); + wifi->bands[1].channels = wifi->channels + 13; + wifi->bands[1].n_channels = ARRAY_SIZE(five_ghz); + wifi->bands[1].bitrates = rates + 4; + wifi->bands[1].n_bitrates = ARRAY_SIZE(rates) - 4; + wifi->wiphy->bands[NL80211_BAND_2GHZ] = &wifi->bands[0]; + wifi->wiphy->bands[NL80211_BAND_5GHZ] = &wifi->bands[1]; + + ret = eth_platform_get_mac_address(&wifi->a.pdev->dev, address); + if (!ret) { + eth_hw_addr_set(wifi->netdev, address); + ether_addr_copy(wifi->wiphy->perm_addr, address); + } else if (ret == -EPROBE_DEFER) { + goto failed; + } else { + eth_hw_addr_random(wifi->netdev); + dev_warn( + &wifi->a.pdev->dev, + "No valid factory MAC property; using a random address\n"); + } + ret = wiphy_register(wifi->wiphy); + if (ret) + goto failed; + wifi->registered = true; + wifi->wdev.wiphy = wifi->wiphy; + wifi->wdev.iftype = NL80211_IFTYPE_STATION; + wifi->wdev.netdev = wifi->netdev; + wifi->netdev->ieee80211_ptr = &wifi->wdev; + wifi->netdev->netdev_ops = &net_ops; + SET_NETDEV_DEV(wifi->netdev, &c->pdev->dev); + strscpy(wifi->netdev->name, "wlan%d", IFNAMSIZ); + wifi->netdev->max_mtu = ETH_DATA_LEN; + + ret = radio_start(wifi); + if (ret) { + dev_err(&c->pdev->dev, + "Wi-Fi ring/interface setup failed: %d\n", ret); + goto failed; + } + ret = register_netdev(wifi->netdev); + if (ret) + goto failed; + smp_store_release(&wifi->irq_ready, true); + schedule_work(&wifi->link_work); + + return 0; +failed: + centauri_t6050_wifi_unregister(c); + return ret; +} + +void centauri_t6050_wifi_unregister(struct centauri_t6050 *c) +{ + struct centauri_t6050_wifi *wifi = c->wifi; + + if (!wifi) + return; + WRITE_ONCE(wifi->stopping, true); + WRITE_ONCE(wifi->connect_abort, true); + WRITE_ONCE(wifi->scan_abort, true); + smp_store_release(&c->wifi, NULL); + + for (unsigned int i = 0; i < c->alpha_irqs.count; i++) + synchronize_irq(pci_irq_vector(c->alpha_irqs.pdev, i)); + if (wifi->netdev && wifi->netdev->reg_state == NETREG_REGISTERED) + netif_tx_disable(wifi->netdev); + + cancel_scan(wifi); + cancel_work_sync(&wifi->connect_work); + cancel_work_sync(&wifi->link_work); + mutex_lock(&wifi->lock); + cancel_connect_locked(wifi); + mutex_unlock(&wifi->lock); + skb_queue_purge(&wifi->data_tx_queue); + if (wifi->netdev && wifi->netdev->reg_state == NETREG_REGISTERED) + unregister_netdev(wifi->netdev); + if (wifi->registered) + wiphy_unregister(wifi->wiphy); + if (wifi->wiphy) + wiphy_free(wifi->wiphy); + if (wifi->netdev) + free_netdev(wifi->netdev); + memzero_explicit(wifi, sizeof(*wifi)); + kfree(wifi); +} From 260b0bacee6015b8d2fc6bfc9afda2f633ad05b6 Mon Sep 17 00:00:00 2001 From: Dj Date: Mon, 26 Oct 2026 02:34:20 -0400 Subject: [PATCH 301/342] Bluetooth: Add T6050 N1 protocol-27 HCI and ACL transport Keep the J813/J873 transport intact. Give the T6050 driver its own module name and reject other hosts before creating a supplier link. Add the N1 protocol-27 Beta HCI/ACL transport and its Control-supplier lifetime. Carry the bounded HCI command-cache reset hook while preserving standard status and command-credit semantics. Source snapshot: t6050-gpu ee68abb105200e99636a5edfc647a5cfc1d89954 Integration base: 9cbdd0734d9e186c5f5f5949a21b909d10c2571b Signed-off-by: Dj Developed with Claude Code. Signed-off-by: Erik Bourget --- .../net/bluetooth/apple,centauri.yaml | 38 + drivers/bluetooth/Kconfig | 8 + drivers/bluetooth/Makefile | 1 + drivers/bluetooth/btcentauri_t6050.c | 942 ++++++++++++++++++ include/net/bluetooth/hci_core.h | 2 + net/bluetooth/hci_sync.c | 9 + 6 files changed, 1000 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml create mode 100644 drivers/bluetooth/btcentauri_t6050.c diff --git a/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml b/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml new file mode 100644 index 0000000000000..f8a1895145da4 --- /dev/null +++ b/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0-only +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/bluetooth/apple,centauri.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple N1 Centauri Beta Bluetooth PCI function + +maintainers: + - Dj + +description: | + PCI function two is the Beta Bluetooth HCI/ACL transport. It depends on + the Control function in the same PCI slot, which boots the shared N1 + firmware using the protocol profile described on its own DT node. + The factory address is supplied in network byte order for the firmware + address-provisioning command; HCI returns the standard Bluetooth order. + +properties: + compatible: + const: pci106b,1903 + + reg: + maxItems: 1 + description: Standard five-cell PCI function address + + local-mac-address: + $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 6 + maxItems: 6 + description: Factory Bluetooth public address in network byte order + +required: + - compatible + - reg + - local-mac-address + +additionalProperties: false diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 832e2d3019ecc..002a8985ca04f 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -520,4 +520,12 @@ config BT_CENTAURI Say M to build the btcentauri module for bring-up testing. +config BT_HCICENTAURI + tristate "Apple N1 Centauri T6050 Bluetooth" + depends on PCI && APPLE_CENTAURI_T6050 + help + Protocol-27 Beta HCI and ACL transport using the T6050 Control + supplier and a device-tree factory address. This can coexist with + the J813/J873 Bluetooth transport. SCO and ISO are not implemented. + endmenu diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index eb3b4de799a3b..4f2f47e39eb43 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile @@ -59,3 +59,4 @@ obj-$(CONFIG_BT_CENTAURI) += btcentauri.o obj-$(CONFIG_BT_MTK7932_PCIE) += mt7932_bt_pcie.o CONTEXT_ANALYSIS := y +obj-$(CONFIG_BT_HCICENTAURI) += btcentauri_t6050.o diff --git a/drivers/bluetooth/btcentauri_t6050.c b/drivers/bluetooth/btcentauri_t6050.c new file mode 100644 index 0000000000000..543ca329a17bc --- /dev/null +++ b/drivers/bluetooth/btcentauri_t6050.c @@ -0,0 +1,942 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CEN_ARENA_SIZE SZ_1M +#define CEN_MTR 0x2000 +#define CEN_MCR 0x2200 +#define CEN_MESSAGES 0x4000 +#define CEN_RX 0x8000 +#define CEN_TX 0xa000 +#define CEN_FOOTER 260 +#define CEN_STRIDE (16 + CEN_FOOTER) +#define CEN_RX_SLOTS 17 +#define CEN_TX_SLOTS 5 +#define CEN_LE_RX 0xc000 +#define CEN_LE_TX 0xe000 +#define CEN_LE_FOOTER 256 +#define CEN_LE_STRIDE (16 + CEN_LE_FOOTER) +#define CEN_LE_SLOTS 17 +#define CEN_MESSAGE_SLOTS 16 +#define CEN_AUX_BASE 0x20000 +#define CEN_CAPTURE_SIZE SZ_1M + +#define CEN_OP_READ_PROP_FEATURES 0xffa3 +#define CEN_OP_CREATE_CONN 0xff7b +#define CEN_OP_FLUSH_DUPLICATES 0xff3f +#define CEN_PROP_CREATE_CONN BIT(9) + +struct cen_aux_spec { + u16 id, slots, footer; + bool receive; +}; + +static const struct cen_aux_spec cen_aux_specs[] = { + { 2, 9, 2592, false }, { 3, 9, 724, false }, { 5, 9, 260, false }, + { 6, 5, 1024, false }, { 8, 9, 2592, true }, { 9, 9, 724, true }, + { 11, 9, 268, true }, { 12, 128, 1024, true }, { 13, 17, 260, true }, + { 14, 9, 1304, false }, { 15, 9, 1304, true }, +}; + +struct cen_aux_state { + u32 offset; + u16 head, post; + bool opened; +}; + +struct cen_bt { + struct pci_dev *pdev; + struct hci_dev *hdev; + void __iomem *bar; + u8 *arena; + dma_addr_t dma; + struct mutex lock; + struct work_struct io_work; + unsigned int irq_count; + bool irq_vectors; + struct sk_buff_head txq; + struct sk_buff_head acl_txq, le_txq; + u16 acl_tx_head, le_tx_head; + u16 message_head, message_tag, tx_head, rx_head, rx_post; + u16 le_rx_head, le_rx_post; + struct cen_aux_state aux[ARRAY_SIZE(cen_aux_specs)]; + bool ipc_requested, running; + u8 native_startup_steps; + bool connection_command_supported, connection_status_pending; +}; + +static u16 cen_tail(struct cen_bt *bt, u16 ring) +{ + return le16_to_cpu(READ_ONCE(*(__le16 *)(bt->arena + 0x7a + ring * 2))); +} + +static void cen_post(struct cen_bt *bt, u16 ring, u16 value) +{ + put_unaligned_le16(value, bt->arena + 0xa8 + ring * 2); + dma_wmb(); + writel(value, bt->bar + 0x1000 + ring * 4); +} + +static int cen_message(struct cen_bt *bt, const void *data, size_t length) +{ + u16 head = bt->message_head, tail, + next = (head + 1) % CEN_MESSAGE_SLOTS; + u16 tag = bt->message_tag + 1; + u8 *descriptor = bt->arena + CEN_MTR + head * 16; + u8 *completion = bt->arena + CEN_MCR + head * 32; + int ret; + + if (head >= CEN_MESSAGE_SLOTS || !length || length > 512) + return -EINVAL; + memset(descriptor, 0, 16); + memset(completion, 0, 32); + memcpy(bt->arena + CEN_MESSAGES + head * 512, data, length); + put_unaligned_le32(1 | (length << 8), descriptor); + put_unaligned_le64(bt->dma + CEN_MESSAGES + head * 512, descriptor + 4); + put_unaligned_le16(tag, descriptor + 12); + cen_post(bt, 0, next); + ret = read_poll_timeout(cen_tail, tail, tail == next, 100, 1500000, + false, bt, 0); + if (ret) + return ret; + + ret = read_poll_timeout(le16_to_cpu, tail, tail == next, 100, 1500000, + false, + READ_ONCE(*(__le16 *)(bt->arena + 0x78))); + if (ret) + return ret; + dma_rmb(); + if (get_unaligned_le16(completion + 4) != tag || + get_unaligned_le16(completion + 6) != length || + get_unaligned_le32(completion + 8)) + return -EPROTO; + bt->message_head = next; + bt->message_tag = tag; + put_unaligned_le16(bt->message_head, bt->arena + 0xa6); + dma_wmb(); + return 0; +} + +static int cen_open_ring(struct cen_bt *bt, u16 id, u16 slots, u32 offset, + u16 footer) +{ + u8 message[0x34] = { 1 }; + u32 words = footer / 4, shift = 0; + + if (!words || footer % 4) + return -EINVAL; + if (words > 255) + shift = min_t(u32, __ffs(words), 4); + if ((words >> shift) > 255) + return -EINVAL; + message[2] = words >> shift; + message[3] = shift << 4; + put_unaligned_le16(id, message + 4); + put_unaligned_le64(bt->dma + offset, message + 8); + put_unaligned_le64(~0ULL, message + 0x10); + put_unaligned_le16(slots, message + 0x18); + put_unaligned_le16(0xffff, message + 0x1a); + put_unaligned_le16(id, message + 0x1c); + put_unaligned_le16(0x40, message + 0x1e); + return cen_message(bt, message, sizeof(message)); +} + +static void cen_rx_buffer(struct cen_bt *bt, u16 slot) +{ + u8 *descriptor = bt->arena + CEN_RX + slot * CEN_STRIDE; + + memset(descriptor, 0, CEN_STRIDE); + put_unaligned_le32(1 | (CEN_FOOTER << 8), descriptor); + put_unaligned_le16(slot + 1, descriptor + 12); +} + +static void cen_le_rx_buffer(struct cen_bt *bt, u16 slot) +{ + u8 *descriptor = bt->arena + CEN_LE_RX + slot * CEN_LE_STRIDE; + + memset(descriptor, 0, CEN_LE_STRIDE); + put_unaligned_le32(1 | (CEN_LE_FOOTER << 8), descriptor); + put_unaligned_le16(slot + 1, descriptor + 12); +} + +static int cen_receive_acl(struct cen_bt *bt, const u8 *data, u32 length) +{ + struct sk_buff *skb; + u32 packet_length, pos; + + if (length < HCI_ACL_HDR_SIZE) + return -EPROTO; + packet_length = HCI_ACL_HDR_SIZE + get_unaligned_le16(data + 2); + if (packet_length > length) + return -EPROTO; + + for (pos = packet_length; pos < length;) { + if (!data[pos]) + break; + if (data[pos] == 1) + pos++; + else if (data[pos] == 2 && length - pos >= 9) + pos += 9; + else + return -EPROTO; + } + skb = bt_skb_alloc(packet_length, GFP_KERNEL); + if (!skb) { + bt->hdev->stat.err_rx++; + return 0; + } + skb_put_data(skb, data, packet_length); + hci_skb_pkt_type(skb) = HCI_ACLDATA_PKT; + bt->hdev->stat.byte_rx += packet_length; + hci_recv_frame(bt->hdev, skb); + return 0; +} + +static void cen_aux_rx_buffer(struct cen_bt *bt, unsigned int index, u16 slot) +{ + const struct cen_aux_spec *spec = &cen_aux_specs[index]; + u8 *descriptor = + bt->arena + bt->aux[index].offset + slot * (16 + spec->footer); + + memset(descriptor, 0, 16 + spec->footer); + put_unaligned_le32(1 | (spec->footer << 8), descriptor); + put_unaligned_le16(slot + 1, descriptor + 12); +} + +static bool cen_aux_required(u16 id) +{ + return id == 2 || id == 8; +} + +static int cen_aux_start(struct cen_bt *bt) +{ + u32 offset = CEN_AUX_BASE; + unsigned int i, slot; + int ret; + + for (i = 0; i < ARRAY_SIZE(cen_aux_specs); i++) { + const struct cen_aux_spec *spec = &cen_aux_specs[i]; + struct cen_aux_state *state = &bt->aux[i]; + u32 length = spec->slots * (16U + spec->footer); + + if (offset > CEN_ARENA_SIZE || length > CEN_ARENA_SIZE - offset) + return -ENOSPC; + state->offset = offset; + offset = ALIGN(offset + length, SZ_4K); + if (!cen_aux_required(spec->id)) + continue; + ret = cen_open_ring(bt, spec->id, spec->slots, state->offset, + spec->footer); + if (ret) { + dev_err(&bt->pdev->dev, + "Auxiliary ring %u open failed: %d\n", spec->id, + ret); + return ret; + } + state->opened = true; + if (!spec->receive) + continue; + for (slot = 0; slot < spec->slots - 1; slot++) + cen_aux_rx_buffer(bt, i, slot); + state->post = spec->slots - 1; + cen_post(bt, spec->id, state->post); + } + return 0; +} + +static int cen_aux_drain(struct cen_bt *bt, bool repost) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(cen_aux_specs); i++) { + const struct cen_aux_spec *spec = &cen_aux_specs[i]; + struct cen_aux_state *state = &bt->aux[i]; + u16 tail; + int budget = spec->slots; + + if (!state->opened || !spec->receive) + continue; + tail = cen_tail(bt, spec->id); + if (tail >= spec->slots) + return -EPROTO; + while (state->head != tail && budget--) { + u8 *descriptor = bt->arena + state->offset + + state->head * (16 + spec->footer); + u32 length; + + dma_rmb(); + length = get_unaligned_le32(descriptor) >> 8; + if (length > spec->footer) + return -EPROTO; + if (repost && spec->id == 8 && + cen_receive_acl(bt, descriptor + 16, length)) + return -EPROTO; + state->head = (state->head + 1) % spec->slots; + if (repost) { + cen_aux_rx_buffer(bt, i, state->post); + state->post = (state->post + 1) % spec->slots; + cen_post(bt, spec->id, state->post); + } + } + } + return 0; +} + +static int cen_start(struct cen_bt *bt) +{ + static const u16 indices[] = { 0x78, 0x7a, 0xa6, 0xa8 }; + u8 config[4] = { 9, 0, 0xff, 0xff }; + u32 status; + int i, ret; + + put_unaligned_le16(0x300, bt->arena); + put_unaligned_le16(0x68, bt->arena + 2); + put_unaligned_le64(bt->dma + 0x68, bt->arena + 8); + for (i = 0; i < ARRAY_SIZE(indices); i++) + put_unaligned_le64(bt->dma + indices[i], + bt->arena + 0x10 + i * 8); + put_unaligned_le16(1, bt->arena + 0x30); + put_unaligned_le16(22, bt->arena + 0x32); + put_unaligned_le64(bt->dma + CEN_MCR, bt->arena + 0x34); + put_unaligned_le64(bt->dma + CEN_MTR, bt->arena + 0x3c); + put_unaligned_le16(16, bt->arena + 0x44); + put_unaligned_le16(16, bt->arena + 0x46); + + bt->arena[0x53] = 4; + put_unaligned_le64(bt->dma + 0x10000, bt->arena + 0x58); + pci_set_master(bt->pdev); + writel(lower_32_bits(bt->dma), bt->bar + 0xc); + writel(upper_32_bits(bt->dma), bt->bar + 0x10); + writel(CEN_ARENA_SIZE, bt->bar + 0x14); + bt->ipc_requested = true; + writel(1, bt->bar + 0x107c); + ret = readl_poll_timeout(bt->bar, status, status == 1, 100, 2000000); + if (ret) + return ret; + dma_wmb(); + writel(lower_32_bits(bt->dma), bt->bar + 4); + writel(upper_32_bits(bt->dma), bt->bar + 8); + writel(2, bt->bar + 0x107c); + ret = readl_poll_timeout(bt->bar, status, status == 2, 100, 2000000); + if (ret) + return ret; + ret = cen_message(bt, config, sizeof(config)); + if (!ret) + ret = cen_open_ring(bt, 7, CEN_RX_SLOTS, CEN_RX, CEN_FOOTER); + if (!ret) + ret = cen_open_ring(bt, 1, CEN_TX_SLOTS, CEN_TX, CEN_FOOTER); + if (!ret) + ret = cen_open_ring(bt, 10, CEN_LE_SLOTS, CEN_LE_RX, + CEN_LE_FOOTER); + if (!ret) + ret = cen_open_ring(bt, 4, CEN_LE_SLOTS, CEN_LE_TX, + CEN_LE_FOOTER); + if (ret) + return ret; + for (i = 0; i < CEN_RX_SLOTS - 1; i++) + cen_rx_buffer(bt, i); + bt->rx_post = CEN_RX_SLOTS - 1; + cen_post(bt, 7, bt->rx_post); + { + for (i = 0; i < CEN_LE_SLOTS - 1; i++) + cen_le_rx_buffer(bt, i); + bt->le_rx_post = CEN_LE_SLOTS - 1; + cen_post(bt, 10, bt->le_rx_post); + } + return cen_aux_start(bt); +} + +static int cen_transmit(struct cen_bt *bt, struct sk_buff_head *queue, u16 ring, + u16 slots, u32 offset, u16 footer, u16 *head) +{ + struct sk_buff *skb; + u16 tail, next; + u8 *descriptor; + u32 wire_length; + + while (!skb_queue_empty(queue)) { + tail = cen_tail(bt, ring); + if (tail >= slots) + return -EPROTO; + next = (*head + 1) % slots; + if (next == tail) + break; + dma_rmb(); + skb = skb_dequeue(queue); + if (!skb) + break; + descriptor = bt->arena + offset + *head * (16 + footer); + memset(descriptor, 0, 16 + footer); + put_unaligned_le16(*head + 1, descriptor + 12); + memcpy(descriptor + 16, skb->data, skb->len); + wire_length = skb->len; + if (ring == 1 && READ_ONCE(bt->connection_command_supported) && + get_unaligned_le16(skb->data) == HCI_OP_CREATE_CONN) { + u8 *command = descriptor + 16; + + put_unaligned_le16(CEN_OP_CREATE_CONN, command); + command[2] = 15; + command[HCI_COMMAND_HDR_SIZE + 9] = 0; + command[HCI_COMMAND_HDR_SIZE + 12] = 0; + wire_length = HCI_COMMAND_HDR_SIZE + 15; + bt->connection_status_pending = true; + } + put_unaligned_le32(1 | (wire_length << 8), descriptor); + *head = next; + cen_post(bt, ring, next); + if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT) + bt->hdev->stat.cmd_tx++; + else + bt->hdev->stat.acl_tx++; + bt->hdev->stat.byte_tx += wire_length; + kfree_skb(skb); + } + return 0; +} + +static void cen_fixup_scan_response(u8 *event, size_t length) +{ + struct hci_ev_le_ext_adv_info *info; + size_t offset = HCI_EVENT_HDR_SIZE + 2; + u8 count; + + if (length < offset || event[0] != HCI_EV_LE_META || + event[HCI_EVENT_HDR_SIZE] != HCI_EV_LE_EXT_ADV_REPORT) + return; + count = event[HCI_EVENT_HDR_SIZE + 1]; + while (count-- && length - offset >= sizeof(*info)) { + u16 type; + + info = (void *)(event + offset); + if (info->length > length - offset - sizeof(*info)) + return; + type = get_unaligned_le16(&info->type); + if ((type & LE_EXT_ADV_EVT_TYPE_MASK) == + (LE_EXT_ADV_LEGACY_PDU | LE_EXT_ADV_SCAN_RSP)) + put_unaligned_le16(type | LE_EXT_ADV_SCAN_IND, + &info->type); + offset += sizeof(*info) + info->length; + } +} + +static void cen_io_work(struct work_struct *work) +{ + struct cen_bt *bt = container_of(work, struct cen_bt, io_work); + struct hci_dev *hdev = bt->hdev; + struct sk_buff *skb; + u16 tail; + u8 *descriptor; + u32 length; + int budget = CEN_RX_SLOTS; + + mutex_lock(&bt->lock); + if (!bt->running) + goto unlock; + if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 2) { + if (readl(bt->bar) == 2) + cen_aux_drain(bt, false); + goto protocol_error; + } + if (cen_aux_drain(bt, true)) + goto protocol_error; + { + tail = cen_tail(bt, 10); + if (tail >= CEN_LE_SLOTS) + goto protocol_error; + while (bt->le_rx_head != tail && budget--) { + dma_rmb(); + descriptor = bt->arena + CEN_LE_RX + + bt->le_rx_head * CEN_LE_STRIDE; + length = get_unaligned_le32(descriptor) >> 8; + if (length > CEN_LE_FOOTER) + goto protocol_error; + if (cen_receive_acl(bt, descriptor + 16, length)) + goto protocol_error; + bt->le_rx_head = (bt->le_rx_head + 1) % CEN_LE_SLOTS; + cen_le_rx_buffer(bt, bt->le_rx_post); + bt->le_rx_post = (bt->le_rx_post + 1) % CEN_LE_SLOTS; + cen_post(bt, 10, bt->le_rx_post); + } + budget = CEN_RX_SLOTS; + } + tail = cen_tail(bt, 7); + if (tail >= CEN_RX_SLOTS) + goto protocol_error; + while (bt->rx_head != tail && budget--) { + dma_rmb(); + descriptor = bt->arena + CEN_RX + bt->rx_head * CEN_STRIDE; + length = get_unaligned_le32(descriptor) >> 8; + if (length < HCI_EVENT_HDR_SIZE || length > CEN_FOOTER || + length != descriptor[17] + HCI_EVENT_HDR_SIZE) + goto protocol_error; + skb = bt_skb_alloc(length, GFP_KERNEL); + if (skb) { + skb_put_data(skb, descriptor + 16, length); + cen_fixup_scan_response(skb->data, skb->len); + + if (bt->connection_status_pending && length == 6 && + skb->data[0] == HCI_EV_CMD_STATUS && + get_unaligned_le16(skb->data + 4) == + CEN_OP_CREATE_CONN) { + put_unaligned_le16(HCI_OP_CREATE_CONN, + skb->data + 4); + bt->connection_status_pending = false; + } + + if (READ_ONCE(bt->connection_command_supported) && + length == + HCI_EVENT_HDR_SIZE + + sizeof(struct hci_ev_conn_complete) && + skb->data[0] == HCI_EV_CONN_COMPLETE && + (skb->data[11] & 0xfe) == 0xf0) { + skb->data[11] = ACL_LINK; + } + hci_skb_pkt_type(skb) = HCI_EVENT_PKT; + hdev->stat.byte_rx += length; + hci_recv_frame(hdev, skb); + } else { + hdev->stat.err_rx++; + } + bt->rx_head = (bt->rx_head + 1) % CEN_RX_SLOTS; + cen_rx_buffer(bt, bt->rx_post); + bt->rx_post = (bt->rx_post + 1) % CEN_RX_SLOTS; + cen_post(bt, 7, bt->rx_post); + } + if (cen_transmit(bt, &bt->txq, 1, CEN_TX_SLOTS, CEN_TX, CEN_FOOTER, + &bt->tx_head)) + goto protocol_error; + + if ((cen_transmit(bt, &bt->acl_txq, 2, cen_aux_specs[0].slots, + bt->aux[0].offset, cen_aux_specs[0].footer, + &bt->acl_tx_head) || + cen_transmit(bt, &bt->le_txq, 4, CEN_LE_SLOTS, CEN_LE_TX, + CEN_LE_FOOTER, &bt->le_tx_head))) + goto protocol_error; + goto unlock; +protocol_error: + bt->running = false; + hdev->stat.err_rx++; + dev_err(&bt->pdev->dev, + "Beta transport stopped (exec=%u ipc=%u); interrupt processing stopped\n", + readl(bt->bar + 0x18), readl(bt->bar)); +unlock: + mutex_unlock(&bt->lock); +} + +static int cen_hci_open(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + + mutex_lock(&bt->lock); + bt->running = true; + schedule_work(&bt->io_work); + mutex_unlock(&bt->lock); + return 0; +} + +static int cen_hci_close(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + + mutex_lock(&bt->lock); + bt->running = false; + bt->connection_status_pending = false; + mutex_unlock(&bt->lock); + cancel_work_sync(&bt->io_work); + skb_queue_purge(&bt->txq); + skb_queue_purge(&bt->acl_txq); + skb_queue_purge(&bt->le_txq); + return 0; +} + +static int cen_vendor_command(struct hci_dev *hdev, u16 opcode, + const void *data, u8 length) +{ + struct sk_buff *skb; + int ret; + + skb = __hci_cmd_sync(hdev, opcode, length, data, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) + return PTR_ERR(skb); + ret = skb->len < 1 ? -EPROTO : -bt_to_errno(skb->data[0]); + kfree_skb(skb); + return ret; +} + +static int cen_hci_reset_dup_filter(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + static const u8 flags; + int ret; + + ret = __hci_cmd_sync_status(hdev, CEN_OP_FLUSH_DUPLICATES, + sizeof(flags), &flags, HCI_CMD_TIMEOUT); + if (ret) { + bt_dev_warn(hdev, "Duplicate filter reset failed: %d", ret); + return ret; + } + return 0; +} + +static int cen_hci_post_init(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + struct sk_buff *skb; + u32 features; + int ret; + + WRITE_ONCE(bt->connection_command_supported, false); + skb = __hci_cmd_sync(hdev, CEN_OP_READ_PROP_FEATURES, 0, NULL, + HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) + return PTR_ERR(skb); + ret = skb->len == 5 ? -bt_to_errno(skb->data[0]) : -EPROTO; + features = skb->len == 5 ? get_unaligned_le32(skb->data + 1) : 0; + kfree_skb(skb); + if (!ret && !(features & CEN_PROP_CREATE_CONN)) + ret = -EOPNOTSUPP; + if (ret) { + bt_dev_warn(hdev, "Firmware connection command unavailable: %d", + ret); + return 0; + } + WRITE_ONCE(bt->connection_command_supported, true); + return 0; +} + +static int cen_hci_setup(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + u8 address[6], init_done[16], seed[24]; + int ret; + + if (device_property_count_u8(&bt->pdev->dev, "local-mac-address") != 6) + return -EINVAL; + ret = device_property_read_u8_array(&bt->pdev->dev, "local-mac-address", + address, sizeof(address)); + if (ret) + return ret; + if (is_zero_ether_addr(address) || is_broadcast_ether_addr(address)) + return -EINVAL; + ret = get_random_bytes_wait(seed, sizeof(seed)); + if (ret) + return ret; + memset(init_done, 0xff, sizeof(init_done)); + ret = cen_vendor_command(hdev, 0xfc06, address, sizeof(address)); + if (ret) + goto out; + WRITE_ONCE(bt->native_startup_steps, 1); + ret = cen_vendor_command(hdev, 0xff0b, init_done, sizeof(init_done)); + if (ret) + goto out; + WRITE_ONCE(bt->native_startup_steps, 2); + ret = cen_vendor_command(hdev, 0xfe44, seed, sizeof(seed)); + if (!ret) + WRITE_ONCE(bt->native_startup_steps, 3); +out: + memzero_explicit(seed, sizeof(seed)); + if (ret) + bt_dev_err( + hdev, + "Firmware initialization stopped after %u commands: %d", + bt->native_startup_steps, ret); + return ret; +} + +static int cen_hci_flush(struct hci_dev *hdev) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + + skb_queue_purge(&bt->txq); + skb_queue_purge(&bt->acl_txq); + skb_queue_purge(&bt->le_txq); + return 0; +} + +static int cen_hci_send(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct cen_bt *bt = hci_get_drvdata(hdev); + struct sk_buff_head *queue = &bt->txq; + struct hci_conn *conn; + u16 handle; + u8 link_type; + int ret = 0; + + if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT && + (skb->len < HCI_COMMAND_HDR_SIZE || + skb->len != HCI_COMMAND_HDR_SIZE + skb->data[2])) + return -EMSGSIZE; + if (hci_skb_pkt_type(skb) == HCI_ACLDATA_PKT) { + if (skb->len < HCI_ACL_HDR_SIZE || + skb->len != HCI_ACL_HDR_SIZE + + get_unaligned_le16(skb->data + 2)) { + ret = -EMSGSIZE; + goto out; + } + handle = get_unaligned_le16(skb->data); + rcu_read_lock(); + conn = hci_conn_hash_lookup_handle(hdev, hci_handle(handle)); + link_type = conn ? conn->type : 0xff; + rcu_read_unlock(); + if (link_type == LE_LINK && (handle & 0x3000) != 0x3000) { + queue = &bt->le_txq; + if (skb->len > CEN_LE_FOOTER) + ret = -EMSGSIZE; + } else if (link_type == ACL_LINK) { + queue = &bt->acl_txq; + if (skb->len > cen_aux_specs[0].footer) + ret = -EMSGSIZE; + } else { + ret = -EOPNOTSUPP; + } + if (ret) + goto out; + } else if (hci_skb_pkt_type(skb) != HCI_COMMAND_PKT) { + ret = -EOPNOTSUPP; + goto out; + } else if (skb->len < HCI_COMMAND_HDR_SIZE || skb->len > CEN_FOOTER || + skb->len != HCI_COMMAND_HDR_SIZE + skb->data[2]) { + ret = -EMSGSIZE; + goto out; + } + if (hci_skb_pkt_type(skb) == HCI_COMMAND_PKT) { + u16 opcode = get_unaligned_le16(skb->data); + + if (opcode == CEN_OP_CREATE_CONN) { + ret = -EOPNOTSUPP; + goto out; + } + if (opcode == HCI_OP_CREATE_CONN && + skb->len != HCI_COMMAND_HDR_SIZE + + sizeof(struct hci_cp_create_conn)) { + ret = -EMSGSIZE; + goto out; + } + } + mutex_lock(&bt->lock); + if (!bt->running) + ret = -ENETDOWN; + else if (skb_queue_len(queue) >= 64) + ret = -ENOBUFS; + else { + skb_queue_tail(queue, skb); + schedule_work(&bt->io_work); + } + mutex_unlock(&bt->lock); + if (!ret) + return 0; +out: + + return ret; +} + +static irqreturn_t cen_irq(int irq, void *data) +{ + struct cen_bt *bt = data; + + if (READ_ONCE(bt->running)) + schedule_work(&bt->io_work); + return IRQ_HANDLED; +} + +static void cen_free_irqs(struct cen_bt *bt) +{ + while (bt->irq_count) + free_irq(pci_irq_vector(bt->pdev, --bt->irq_count), bt); + if (bt->irq_vectors) { + pci_free_irq_vectors(bt->pdev); + bt->irq_vectors = false; + } +} + +static int cen_request_irqs(struct cen_bt *bt) +{ + int ret = pci_alloc_irq_vectors(bt->pdev, 2, 2, PCI_IRQ_MSI); + + if (ret < 0) + return ret; + bt->irq_vectors = true; + for (bt->irq_count = 0; bt->irq_count < 2; bt->irq_count++) { + ret = request_irq(pci_irq_vector(bt->pdev, bt->irq_count), + cen_irq, 0, "btcentauri_t6050", bt); + if (ret) { + cen_free_irqs(bt); + return ret; + } + } + return 0; +} + +static void cen_stop(struct cen_bt *bt) +{ + u16 command; + int ret; + + pci_clear_master(bt->pdev); + cen_free_irqs(bt); + cancel_work_sync(&bt->io_work); + + ret = pci_read_config_word(bt->pdev, PCI_COMMAND, &command); + if (bt->ipc_requested || ret || (command & PCI_COMMAND_MASTER) || + !pci_wait_for_pending_transaction(bt->pdev)) + dev_warn( + &bt->pdev->dev, + "Beta detach requires fresh firmware boot; retaining DMA arena\n"); + else + dma_free_coherent(&bt->pdev->dev, CEN_ARENA_SIZE, bt->arena, + bt->dma); +} + +static int cen_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct cen_bt *bt; + struct hci_dev *hdev; + int ret; + struct pci_dev *control; + struct device_link *link; + struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); + + if (!bridge || !bridge->dev.parent || + !of_device_is_compatible(bridge->dev.parent->of_node, "apple,t6050-pcie") || + PCI_FUNC(pdev->devfn) != 2) + return -ENODEV; + control = pci_get_domain_bus_and_slot( + pci_domain_nr(pdev->bus), pdev->bus->number, + PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); + if (!control) + return -EPROBE_DEFER; + link = device_link_add(&pdev->dev, &control->dev, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!link) { + pci_dev_put(control); + return -ENOMEM; + } + ret = apple_centauri_control_ready(control) ? 0 : -EPROBE_DEFER; + pci_dev_put(control); + if (ret) + return ret; + bt = devm_kzalloc(&pdev->dev, sizeof(*bt), GFP_KERNEL); + if (!bt) + return -ENOMEM; + bt->pdev = pdev; + mutex_init(&bt->lock); + skb_queue_head_init(&bt->txq); + skb_queue_head_init(&bt->acl_txq); + skb_queue_head_init(&bt->le_txq); + INIT_WORK(&bt->io_work, cen_io_work); + ret = pcim_enable_device(pdev); + if (ret) + return ret; + if (pci_resource_len(pdev, 0) != SZ_64K) + return -ENODEV; + ret = pcim_iomap_regions(pdev, BIT(0), "btcentauri_t6050"); + if (ret) + return ret; + bt->bar = pcim_iomap_table(pdev)[0]; + if (readl(bt->bar + 0x18) != 2 || readl(bt->bar) != 0) + return dev_err_probe( + &pdev->dev, -EBUSY, + "Beta requires running firmware and unowned IPC (exec=%u ipc=%u)\n", + readl(bt->bar + 0x18), readl(bt->bar)); + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); + if (ret) + return ret; + bt->arena = dma_alloc_coherent(&pdev->dev, CEN_ARENA_SIZE, &bt->dma, + GFP_KERNEL); + if (!bt->arena) + return -ENOMEM; + memset(bt->arena, 0, CEN_ARENA_SIZE); + ret = cen_request_irqs(bt); + if (ret) + goto stop; + ret = cen_start(bt); + if (ret) { + dev_err(&pdev->dev, "Beta IPC initialization failed: %d\n", + ret); + goto stop; + } + hdev = hci_alloc_dev(); + if (!hdev) { + ret = -ENOMEM; + goto stop; + } + bt->hdev = hdev; + hdev->bus = HCI_PCI; + hdev->open = cen_hci_open; + hdev->close = cen_hci_close; + hdev->flush = cen_hci_flush; + hdev->send = cen_hci_send; + hdev->setup = cen_hci_setup; + hdev->post_init = cen_hci_post_init; + hdev->reset_dup_filter = cen_hci_reset_dup_filter; + + hci_set_quirk(hdev, HCI_QUIRK_FIXUP_LE_EXT_ADV_REPORT_PHY); + SET_HCIDEV_DEV(hdev, &pdev->dev); + hci_set_drvdata(hdev, bt); + pci_set_drvdata(pdev, bt); + ret = hci_register_dev(hdev); + if (ret) { + hci_free_dev(hdev); + goto stop; + } + return 0; +stop: + cen_stop(bt); + return ret; +} + +static void cen_remove(struct pci_dev *pdev) +{ + struct cen_bt *bt = pci_get_drvdata(pdev); + hci_unregister_dev(bt->hdev); + cen_hci_close(bt->hdev); + cen_free_irqs(bt); + cancel_work_sync(&bt->io_work); + hci_free_dev(bt->hdev); + cen_stop(bt); +} + +static int cen_suspend(struct device *dev) +{ + return pci_save_state(to_pci_dev(dev)); +} + +static int cen_resume(struct device *dev) +{ + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(cen_pm_ops, cen_suspend, cen_resume); + +static const struct pci_device_id cen_ids[] = { + { PCI_DEVICE(PCI_VENDOR_ID_APPLE, 0x1903) }, + {} +}; +MODULE_DEVICE_TABLE(pci, cen_ids); + +static struct pci_driver cen_driver = { + .name = "btcentauri_t6050", + .id_table = cen_ids, + .probe = cen_probe, + .remove = cen_remove, + .driver.pm = pm_sleep_ptr(&cen_pm_ops), +}; +module_pci_driver(cen_driver); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Apple N1 protocol-27 Bluetooth transport"); diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 68ff959be8cab..0502328425df6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -666,6 +666,8 @@ struct hci_dev { struct bt_codec *codec, __u8 *vnd_len, __u8 **vnd_data); u8 (*classify_pkt_type)(struct hci_dev *hdev, struct sk_buff *skb); + /* Called in command-sync context before enabling duplicate-filtered scanning. */ + int (*reset_dup_filter)(struct hci_dev *hdev); }; #define hci_set_quirk(hdev, nr) set_bit((nr), (hdev)->quirk_flags) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 0b4dfda2bbed8..34027b50941ab 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2306,6 +2306,15 @@ static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, { struct hci_cp_le_set_scan_enable cp; + /* Firmware duplicate caches may need an explicit reset between scans. */ + if (val && filter_dup != LE_SCAN_FILTER_DUP_DISABLE && + !hci_dev_test_flag(hdev, HCI_MESH) && hdev->reset_dup_filter) { + int err = hdev->reset_dup_filter(hdev); + + if (err) + return err; + } + if (use_ext_scan(hdev)) return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); From 039a2dfccde96dde4aab3507271e9dabf4bea6c7 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 4 Nov 2026 19:50:12 -0500 Subject: [PATCH 302/342] Bluetooth: btcentauri: Drop an unused variable cen_hci_reset_dup_filter() never uses the driver data it looks up, and clang warns about it. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/bluetooth/btcentauri_t6050.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/bluetooth/btcentauri_t6050.c b/drivers/bluetooth/btcentauri_t6050.c index 543ca329a17bc..12efa0d0fd2d1 100644 --- a/drivers/bluetooth/btcentauri_t6050.c +++ b/drivers/bluetooth/btcentauri_t6050.c @@ -581,7 +581,6 @@ static int cen_vendor_command(struct hci_dev *hdev, u16 opcode, static int cen_hci_reset_dup_filter(struct hci_dev *hdev) { - struct cen_bt *bt = hci_get_drvdata(hdev); static const u8 flags; int ret; From cd1748d180f49424757dd4b49d59c8ada0b3d39d Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Wed, 4 Nov 2026 11:59:40 -0800 Subject: [PATCH 303/342] Bluetooth: btcentauri: Take the factory address from local-bd-address Boot loaders fill the standard local-bd-address property from the bluetooth0 alias. Take the factory address from it (least significant byte first), falling back to local-mac-address, and let the binding accept either. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../net/bluetooth/apple,centauri.yaml | 12 +++++++- drivers/bluetooth/btcentauri_t6050.c | 28 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml b/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml index f8a1895145da4..6b1a33cac7aa4 100644 --- a/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml +++ b/Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml @@ -24,15 +24,25 @@ properties: maxItems: 1 description: Standard five-cell PCI function address + local-bd-address: + $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 6 + maxItems: 6 + description: Factory Bluetooth public address, least significant byte + first (the standard Bluetooth property a boot loader fills) + local-mac-address: $ref: /schemas/types.yaml#/definitions/uint8-array minItems: 6 maxItems: 6 description: Factory Bluetooth public address in network byte order +oneOf: + - required: [local-bd-address] + - required: [local-mac-address] + required: - compatible - reg - - local-mac-address additionalProperties: false diff --git a/drivers/bluetooth/btcentauri_t6050.c b/drivers/bluetooth/btcentauri_t6050.c index 12efa0d0fd2d1..1d701d218a512 100644 --- a/drivers/bluetooth/btcentauri_t6050.c +++ b/drivers/bluetooth/btcentauri_t6050.c @@ -619,16 +619,36 @@ static int cen_hci_post_init(struct hci_dev *hdev) return 0; } +/* + * The factory address in network byte order, for the firmware's provisioning command: from + * the standard local-bd-address (least significant byte first, as boot loaders fill it from + * the bluetooth0 alias), else from local-mac-address (already in network order). + */ +static int cen_bt_address(struct device *dev, u8 address[6]) +{ + u8 bd[6]; + int i, ret; + + if (device_property_count_u8(dev, "local-bd-address") == 6) { + ret = device_property_read_u8_array(dev, "local-bd-address", bd, sizeof(bd)); + if (ret) + return ret; + for (i = 0; i < 6; i++) + address[i] = bd[5 - i]; + return 0; + } + if (device_property_count_u8(dev, "local-mac-address") != 6) + return -EINVAL; + return device_property_read_u8_array(dev, "local-mac-address", address, 6); +} + static int cen_hci_setup(struct hci_dev *hdev) { struct cen_bt *bt = hci_get_drvdata(hdev); u8 address[6], init_done[16], seed[24]; int ret; - if (device_property_count_u8(&bt->pdev->dev, "local-mac-address") != 6) - return -EINVAL; - ret = device_property_read_u8_array(&bt->pdev->dev, "local-mac-address", - address, sizeof(address)); + ret = cen_bt_address(&bt->pdev->dev, address); if (ret) return ret; if (is_zero_ether_addr(address) || is_broadcast_ether_addr(address)) From 992d14dd687432c9551aedfe26da22d7f9ae6a9f Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 12:42:00 -0800 Subject: [PATCH 304/342] wifi: apple: centauri: Connect to the BSS the request names A connect request carries the BSSID and channel the client chose from its own scan results. The driver looked the target up in cfg80211's scan list instead and refused the connect with -ENOENT when the entry was not there. iwd runs a requested scan as channel subsets, each with the flush flag, and at the end of each subset cfg80211 expires every BSS that subset did not see, on every band. After a last subset of 2.4 GHz channels with no access point, the list holds none of the network's BSSes while iwd's own list holds all of them, so every connect right after such a scan failed until a later unflushed scan refilled cfg80211's list. - The target is the request's BSSID and channel, or its hints. The scan entry is looked up only when the request names neither. - The RSN capabilities sent to the firmware are the station's own, from the request's RSN element (the client's MFP choice), rather than the AP's from the scan entry. - A successful connect is reported against cfg80211's entry for the target. When the client's scans expired it, one is informed from the request (BSSID, channel, SSID), and the AP's beacons, which the firmware reports once associated, fill in its elements. - Scan and connect failures name the firmware's status: a refused command, a connect or disconnect event with a non-zero status, a scan whose completion event carries one, or no event at all. command() still returns -EREMOTEIO for a refusal. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../apple/centauri/t6050/centauri_wifi.c | 164 +++++++++++++----- 1 file changed, 122 insertions(+), 42 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index 6779271fc83f4..be1040b513f0b 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -54,9 +54,11 @@ struct centauri_t6050_wifi { u8 scan_sequence; bool connecting, connected, connect_event, disconnect_event; bool disconnect_pending; - u16 connect_status; + u16 connect_status, scan_status, disconnect_status; + struct ieee80211_channel *connect_channel; u8 bssid[ETH_ALEN], connect_payload[1024], request_ie[256]; - size_t connect_size, request_ie_size; + u8 ssid[IEEE80211_MAX_SSID_LEN]; + size_t connect_size, request_ie_size, ssid_len; u32 data_rx_received, data_rx_reposted, data_rx_bad; struct sk_buff_head data_tx_queue; u16 data_tx_length[DATA_TX_SLOTS]; @@ -512,15 +514,19 @@ static void drain(struct centauri_t6050_wifi *wifi) } else if (command & BIT(31)) { if (command == 0x80000030) wifi->channels_seen++; - if (command == 0x80000005) + if (command == 0x80000005) { wifi->scans_done++; + wifi->scan_status = status; + } if (command == 0x80000000 && wifi->connecting) { wifi->connect_event = true; wifi->connect_status = status; } if (command == 0x80000003 || - command == 0x80000004) + command == 0x80000004) { wifi->disconnect_event = true; + wifi->disconnect_status = status; + } if (command == 0x80000004) wifi->disconnect_pending = false; @@ -632,7 +638,12 @@ static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload if (wifi->reply_valid && wifi->reply_sequence == sequence && (wifi->reply_command & ~BIT(30)) == id) { - return wifi->reply_status ? -EREMOTEIO : 0; + if (!wifi->reply_status) + return 0; + dev_dbg(&wifi->control->pdev->dev, + "Wi-Fi command %#x: firmware status %u\n", id, + wifi->reply_status); + return -EREMOTEIO; } usleep_range(500, 1000); } while (time_before(jiffies, deadline)); @@ -642,6 +653,19 @@ static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload return -ETIMEDOUT; } +/* Caller holds wifi->lock; ret is what command() returned for the request. */ +static void command_refused(struct centauri_t6050_wifi *wifi, const char *what, + int ret) +{ + if (ret == -EREMOTEIO) + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi %s refused: firmware status %u\n", what, + wifi->reply_status); + else + dev_warn(&wifi->control->pdev->dev, "Wi-Fi %s failed: %d\n", + what, ret); +} + static int station_configure(struct centauri_t6050_wifi *wifi, const u8 *address) { u8 start[5 + 4 + 3 * ETH_ALEN] = { 0, 0x0b, 0, 0, 0 }; @@ -762,8 +786,10 @@ static int scan_profile27(struct centauri_t6050_wifi *wifi) size += 6 + ssid->ssid_len; } ret = command(wifi, 65551, scan, size); - if (ret) + if (ret) { + command_refused(wifi, "scan", ret); return ret; + } deadline = jiffies + msecs_to_jiffies(max(8000U, count * 220 + 2000)); do { @@ -782,9 +808,16 @@ static int scan_profile27(struct centauri_t6050_wifi *wifi) usleep_range(1000, 2000); } while (time_before(jiffies, deadline)); if (wifi->scans_done == done) { + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi scan of %u channels: no completion event\n", + count); command(wifi, 65537, NULL, 0); return -ETIMEDOUT; } + if (wifi->scan_status && !abort_sent) + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi scan of %u channels ended with firmware status %u\n", + count, wifi->scan_status); if (READ_ONCE(wifi->scan_abort)) return -ECANCELED; } @@ -959,6 +992,13 @@ static void append_tlv(u8 *payload, size_t *size, u16 tag, const void *data, *size += 4 + length; } +/* + * The connect request names its target: nl80211 clients pass the BSSID and + * channel they chose from their own scan results. The kernel's scan entry for + * it may already be gone (a client's flushed scan expires every BSS its last + * channel subset did not see), so the entry is looked up only when the + * request names no target. + */ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_connect_params *params) { @@ -973,13 +1013,14 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, }; struct centauri_t6050_wifi *wifi = *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); + const u8 *bssid = params->bssid ?: params->bssid_hint; + struct ieee80211_channel *channel = + params->channel ?: params->channel_hint; struct cfg80211_bss *bss; - const struct cfg80211_bss_ies *ies; - const u8 *rsn, *ap_rsn; + const u8 *rsn; u8 rsn_body[255], ssid[35], zero[20] = {}, pmf; u8 *payload = wifi->connect_payload; size_t size = 130, rsn_size, rsn_prefix, rsn_tail; - u16 caps = 0; int ret = 0, offset; if (!params->ssid_len || params->ssid_len > 32 || !params->crypto.psk || @@ -995,6 +1036,12 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, if (ret < 0) return ret; rsn_size = ret; + /* The station's own RSN capabilities go to the firmware; bit 7 is MFPC. */ + offset = rsn_caps_offset(rsn_body, rsn_size); + if (offset < 0) + return -EINVAL; + pmf = !!(get_unaligned_le16(rsn_body + offset) & + BIT(7)); ret = 0; mutex_lock(&wifi->lock); if (READ_ONCE(wifi->stopping)) { @@ -1007,43 +1054,34 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, goto out; } - bss = cfg80211_get_bss(wiphy, params->channel, params->bssid, - params->ssid, params->ssid_len, - IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ON); - if (!bss) { - ret = -ENOENT; - goto out; - } - - rcu_read_lock(); - ies = rcu_dereference(bss->ies); - ap_rsn = ies ? cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len) : - NULL; - if (!ap_rsn) { - ret = -EINVAL; + if (bssid && channel) { + memcpy(wifi->bssid, bssid, ETH_ALEN); } else { - ret = rsn_psk_offset(ap_rsn + 2, ap_rsn[1]); - if (ret >= 0) { - offset = rsn_caps_offset(ap_rsn + 2, ap_rsn[1]); - caps = get_unaligned_le16(ap_rsn + 2 + offset); - ret = 0; + bss = cfg80211_get_bss(wiphy, channel, bssid, params->ssid, + params->ssid_len, IEEE80211_BSS_TYPE_ESS, + IEEE80211_PRIVACY_ON); + if (!bss) { + ret = -ENOENT; + goto out; } - } - rcu_read_unlock(); - if (ret) { + memcpy(wifi->bssid, bss->bssid, ETH_ALEN); + channel = bss->channel; cfg80211_put_bss(wiphy, bss); + } + if (channel->band != NL80211_BAND_2GHZ && + channel->band != NL80211_BAND_5GHZ) { + ret = -EOPNOTSUPP; goto out; } - offset = rsn_caps_offset(rsn_body, rsn_size); - put_unaligned_le16(caps, rsn_body + offset); - pmf = !!(caps & BIT(7)); + wifi->connect_channel = channel; + memcpy(wifi->ssid, params->ssid, params->ssid_len); + wifi->ssid_len = params->ssid_len; memset(payload, 0, sizeof(wifi->connect_payload)); payload[0] = 1; - memcpy(payload + 1, bss->bssid, ETH_ALEN); - memcpy(wifi->bssid, bss->bssid, ETH_ALEN); - payload[7] = ieee80211_frequency_to_channel(bss->channel->center_freq); + memcpy(payload + 1, wifi->bssid, ETH_ALEN); + payload[7] = ieee80211_frequency_to_channel(channel->center_freq); - payload[8] = bss->channel->band == NL80211_BAND_2GHZ ? 0 : 1; + payload[8] = channel->band == NL80211_BAND_2GHZ ? 0 : 1; payload[0x47] = 4; put_unaligned_le16(4, payload + 0x48); @@ -1077,13 +1115,37 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, wifi->connecting = true; wifi->connect_status = 0; wifi->connect_event = wifi->disconnect_event = false; - cfg80211_put_bss(wiphy, bss); schedule_work(&wifi->connect_work); out: mutex_unlock(&wifi->lock); return ret; } +/* + * cfg80211 records a connection against a BSS entry. When the client's scans + * have expired the target's, inform one from the request until its beacons + * (reported on ring 4 once associated) replace the elements. + */ +static struct cfg80211_bss *connected_bss(struct centauri_t6050_wifi *wifi) +{ + struct cfg80211_bss *bss; + u8 ie[2 + IEEE80211_MAX_SSID_LEN]; + + bss = cfg80211_get_bss(wifi->wiphy, wifi->connect_channel, wifi->bssid, + NULL, 0, IEEE80211_BSS_TYPE_ESS, + IEEE80211_PRIVACY_ANY); + if (bss) + return bss; + ie[0] = WLAN_EID_SSID; + ie[1] = wifi->ssid_len; + memcpy(ie + 2, wifi->ssid, wifi->ssid_len); + return cfg80211_inform_bss(wifi->wiphy, wifi->connect_channel, + CFG80211_BSS_FTYPE_UNKNOWN, wifi->bssid, 0, + WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, + 100, ie, 2 + wifi->ssid_len, -95 * 100, + GFP_KERNEL); +} + static void connect_worker(struct work_struct *work) { struct centauri_t6050_wifi *wifi = @@ -1117,6 +1179,20 @@ static void connect_worker(struct work_struct *work) ret = -ECANCELED; else if (!ret && !wifi->connect_event) ret = -ETIMEDOUT; + if (ret == -ENOTCONN) + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi connect to %pM: disconnect event, firmware status %u\n", + wifi->bssid, wifi->disconnect_status); + else if (ret == -ETIMEDOUT) + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi connect to %pM: no connect event\n", + wifi->bssid); + else if (ret && ret != -ECANCELED) + command_refused(wifi, "connect", ret); + else if (!ret && wifi->connect_status) + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi connect to %pM failed: firmware status %u\n", + wifi->bssid, wifi->connect_status); status = !ret && wifi->connect_status == 0 ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE; @@ -1140,9 +1216,13 @@ static void connect_worker(struct work_struct *work) wifi->request_ie_size, GFP_KERNEL, NL80211_TIMEOUT_UNSPECIFIED); else - cfg80211_connect_result(wifi->netdev, wifi->bssid, - wifi->request_ie, wifi->request_ie_size, - NULL, 0, status, GFP_KERNEL); + cfg80211_connect_bss(wifi->netdev, wifi->bssid, + status == WLAN_STATUS_SUCCESS ? + connected_bss(wifi) : + NULL, + wifi->request_ie, wifi->request_ie_size, + NULL, 0, status, GFP_KERNEL, + NL80211_TIMEOUT_UNSPECIFIED); if (status == WLAN_STATUS_SUCCESS && !READ_ONCE(wifi->stopping)) { cfg80211_port_authorized(wifi->netdev, wifi->bssid, NULL, 0, GFP_KERNEL); From 725275181fb923b03edf0aaa3e90a2b4f88b6761 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 12:42:00 -0800 Subject: [PATCH 305/342] wifi: apple: centauri: Read the firmware's channel list and capabilities The firmware owns the radio's channel list, its per-country rules and its capabilities; the driver registered a fixed 2.4/5 GHz table and never asked. Read the firmware's two reports once the interface is configured: system command 19, the channels the hardware supports, and system command 8, the system capabilities. Both are kept as read in debugfs (ieee80211/phyN/hw_channels and system_caps) and their sizes are logged. The band table is built from them next. command() gains a reply buffer, command_reply(): the payload of the reply to the command that asked is copied there, in place of the ring consumer's per-command copies. query_link_status() parses the interface status reply (20) from it; the copy of the country reply (10), which nothing requested, goes. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../apple/centauri/t6050/centauri_wifi.c | 142 ++++++++++++++---- 1 file changed, 110 insertions(+), 32 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index be1040b513f0b..465f5743cc137 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include #include #include @@ -15,6 +16,7 @@ #define RING_SPAN 0x20000 #define TX_BUFFER 0x600000 #define BUFFER_SIZE 2048 +#define REPLY_SIZE (BUFFER_SIZE - 24) #define DATA_RX_BUFFER SZ_16M #define DATA_TX_BUFFER (SZ_16M + SZ_8M) @@ -46,9 +48,11 @@ struct centauri_t6050_wifi { u16 main_head, command_head, sequence; u32 rx_seen[5]; u16 rx_next[5], rx_head[5]; - u16 reply_sequence, reply_status; + u16 reply_sequence, reply_status, reply_capture; u32 reply_command, channels_seen, scans_done, beacons_seen; bool reply_valid, registered, configured; + u8 *reply_buffer; + size_t reply_capacity, reply_size; bool stopping, command_failed; bool scan_abort, connect_abort; u8 scan_sequence; @@ -69,12 +73,14 @@ struct centauri_t6050_wifi { bool station_signal_valid; unsigned long station_signal_at, connected_at; struct net_device_stats station_start; - u8 country[3]; - bool country_valid; u32 data_rings_open; bool data_failed; struct ieee80211_supported_band bands[2]; struct ieee80211_channel channels[39]; + /* The firmware's own reports, read at bring-up (system commands 19 and 8). */ + u8 hw_channels[REPLY_SIZE], system_caps[REPLY_SIZE]; + struct debugfs_blob_wrapper hw_channels_blob, system_caps_blob; + u8 link_status[REPLY_SIZE]; }; static int query_link_status(struct centauri_t6050_wifi *wifi); @@ -462,9 +468,10 @@ static void drain_data_tx(struct centauri_t6050_wifi *wifi) netif_wake_queue(wifi->netdev); } +/* The interface status reply: 8 fixed bytes, then TLVs. */ static bool link_signal_read(const u8 *packet, size_t size, s8 *signal) { - size_t pos = 32; + size_t pos = 8; while (pos <= size && size - pos >= 4) { u16 tag = get_unaligned_le16(packet + pos); @@ -536,20 +543,12 @@ static void drain(struct centauri_t6050_wifi *wifi) wifi->reply_status = status; wifi->reply_command = wire_command; - if (command == 10) { - wifi->country_valid = !status && - size >= 27; - if (wifi->country_valid) - memcpy(wifi->country, - packet + 24, 3); - } - - if (command == 20 && !status) { - wifi->station_signal_valid = - link_signal_read( - packet, size, - &wifi->station_signal); - wifi->station_signal_at = jiffies; + if (wifi->reply_buffer && + sequence == wifi->reply_capture) { + wifi->reply_size = size - 24; + memcpy(wifi->reply_buffer, packet + 24, + min(wifi->reply_size, + wifi->reply_capacity)); } } refill: @@ -588,10 +587,17 @@ static bool command_payload_consumed(struct centauri_t6050_wifi *wifi, u16 slot) return true; } -static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload, - size_t size) +/* + * Send one command and wait for its reply. With a reply buffer, the reply's + * payload is copied there (up to *reply_size bytes) and *reply_size becomes + * the payload's length. + */ +static int command_reply(struct centauri_t6050_wifi *wifi, u32 id, + const void *payload, size_t size, void *reply, + size_t *reply_size) { u16 slot = wifi->command_head, sequence = ++wifi->sequence; + int ret; u32 stage; u8 *packet, *descriptor; unsigned long deadline = jiffies + msecs_to_jiffies(1500); @@ -618,13 +624,18 @@ static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload wifi->command_head = (slot + 1) % ring_size[1]; index_write(wifi, 3, 1, wifi->command_head); wifi->reply_valid = false; + wifi->reply_buffer = reply; + wifi->reply_capacity = reply ? *reply_size : 0; + wifi->reply_capture = sequence; + wifi->reply_size = 0; dma_wmb(); writel(1, wifi->a.bar + 0x1004); do { if (READ_ONCE(wifi->stopping) || READ_ONCE(wifi->control->removing)) { command_fault(wifi); - return -ECANCELED; + ret = -ECANCELED; + goto out; } drain(wifi); stage = readl(wifi->a.bar + 8); @@ -633,24 +644,38 @@ static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload "Wi-Fi command %#x lost transport: stage=%#x sequence=%u rx=%u\n", id, stage, sequence, wifi->rx_seen[2]); command_fault(wifi); - return -EIO; + ret = -EIO; + goto out; } if (wifi->reply_valid && wifi->reply_sequence == sequence && (wifi->reply_command & ~BIT(30)) == id) { - if (!wifi->reply_status) - return 0; - dev_dbg(&wifi->control->pdev->dev, - "Wi-Fi command %#x: firmware status %u\n", id, - wifi->reply_status); - return -EREMOTEIO; + ret = 0; + if (wifi->reply_status) { + dev_dbg(&wifi->control->pdev->dev, + "Wi-Fi command %#x: firmware status %u\n", + id, wifi->reply_status); + ret = -EREMOTEIO; + } + if (reply) + *reply_size = wifi->reply_size; + goto out; } usleep_range(500, 1000); } while (time_before(jiffies, deadline)); dev_err(&wifi->control->pdev->dev, "Wi-Fi command %#x timed out (rx=%u)\n", id, wifi->rx_seen[2]); command_fault(wifi); - return -ETIMEDOUT; + ret = -ETIMEDOUT; +out: + wifi->reply_buffer = NULL; + return ret; +} + +static int command(struct centauri_t6050_wifi *wifi, u32 id, const void *payload, + size_t size) +{ + return command_reply(wifi, id, payload, size, NULL, NULL); } /* Caller holds wifi->lock; ret is what command() returned for the request. */ @@ -678,6 +703,46 @@ static int station_configure(struct centauri_t6050_wifi *wifi, const u8 *address return ret; } +/* + * The firmware owns the radio's channel list and capabilities: system + * commands 19 (the channels the hardware supports) and 8 (the system + * capabilities) report them once the interface is configured. Kept as + * read, in debugfs. + */ +static void firmware_report(struct centauri_t6050_wifi *wifi, u32 id, u8 *buffer, + struct debugfs_blob_wrapper *blob) +{ + size_t size = REPLY_SIZE; + int ret; + + ret = command_reply(wifi, id, NULL, 0, buffer, &size); + if (ret) { + command_refused(wifi, id == 19 ? "channel list" : "capabilities", + ret); + size = 0; + } else if (size > REPLY_SIZE) { + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi command %u reply of %zu bytes truncated\n", id, + size); + size = REPLY_SIZE; + } + blob->data = buffer; + blob->size = size; +} + +static void firmware_reports(struct centauri_t6050_wifi *wifi) +{ + firmware_report(wifi, 19, wifi->hw_channels, &wifi->hw_channels_blob); + firmware_report(wifi, 8, wifi->system_caps, &wifi->system_caps_blob); + dev_info(&wifi->control->pdev->dev, + "Wi-Fi firmware channel list: %lu bytes, capabilities: %lu bytes\n", + wifi->hw_channels_blob.size, wifi->system_caps_blob.size); + debugfs_create_blob("hw_channels", 0400, wifi->wiphy->debugfsdir, + &wifi->hw_channels_blob); + debugfs_create_blob("system_caps", 0400, wifi->wiphy->debugfsdir, + &wifi->system_caps_blob); +} + static int radio_start(struct centauri_t6050_wifi *wifi) { unsigned int ring, slot; @@ -704,8 +769,9 @@ static int radio_start(struct centauri_t6050_wifi *wifi) if (ret) return ret; msleep(1000); - wifi->configured = true; - return 0; + firmware_reports(wifi); + wifi->configured = !wifi->command_failed; + return wifi->configured ? 0 : -EIO; } #define CEN_SCAN_CHANNELS_MAX 59 @@ -1669,7 +1735,19 @@ static int data_start(struct centauri_t6050_wifi *wifi) static int query_link_status(struct centauri_t6050_wifi *wifi) { - return wifi->configured ? command(wifi, 20, NULL, 0) : -ENETDOWN; + size_t size = sizeof(wifi->link_status); + int ret; + + if (!wifi->configured) + return -ENETDOWN; + ret = command_reply(wifi, 20, NULL, 0, wifi->link_status, &size); + if (!ret) + wifi->station_signal_valid = + link_signal_read(wifi->link_status, + min(size, sizeof(wifi->link_status)), + &wifi->station_signal); + wifi->station_signal_at = jiffies; + return ret; } int centauri_t6050_wifi_register(struct centauri_t6050 *c) From f737e8de074a36e40b59b315bf2d26f6618e796f Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 13:03:01 -0800 Subject: [PATCH 306/342] wifi: apple: centauri: Take the bands from the firmware's channel list The driver registered a fixed table: 2.4 GHz channels 1-13 and 25 5 GHz channels, every one at 20 dBm, and no 6 GHz band. The firmware reports which channels the current country allows (system command 19), at each width and with passive and radar flags, and its own capability elements (system command 8). Before a country is set it reports 2.4 and 5 GHz only; under US rules it reports 167 entries, 6 GHz channels 1-233 among them. - The band plan (2.4 GHz 1-14, 5 GHz 36-177, 6 GHz 1-233) is registered once, and the firmware's list is applied over cfg80211's rules: a channel it leaves out is disabled, its passive and radar flags become NO_IR and RADAR, and a width no entry covers is not used. The power limit is left to the regulatory domain and the firmware. - The regulatory notifier sets the country (command 9, as before), then reads the list again and applies it, after every regulatory change. - 6 GHz is registered with the HE capabilities element the firmware reports, and 6 GHz band capabilities from its VHT element; without an HE element there is no 6 GHz band. The radio is started before the wiphy is registered, since the bands come from it. - One band encoding, firmware_band(), for scan, connect and beacons. 6 GHz beacons carry neither DS parameters nor HT operation, so they take their channel from the HE operation's 6 GHz information. - Scans include the listen-only channels (radar channels, and all of 6 GHz under US rules) with the firmware's passive and radar bits, as its channel list encodes them, instead of skipping them. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../apple/centauri/t6050/centauri_wifi.c | 319 ++++++++++++++---- 1 file changed, 257 insertions(+), 62 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index 465f5743cc137..e89c280a5bdc4 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -1,10 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include #include #include #include #include +#include #include #include #include @@ -17,6 +19,8 @@ #define TX_BUFFER 0x600000 #define BUFFER_SIZE 2048 #define REPLY_SIZE (BUFFER_SIZE - 24) +/* The band plan: 2.4 GHz 1-14, 5 GHz 36-64, 100-144 and 149-177, 6 GHz 1-233. */ +#define CEN_CHANNELS (14 + 28 + 59) #define DATA_RX_BUFFER SZ_16M #define DATA_TX_BUFFER (SZ_16M + SZ_8M) @@ -75,8 +79,9 @@ struct centauri_t6050_wifi { struct net_device_stats station_start; u32 data_rings_open; bool data_failed; - struct ieee80211_supported_band bands[2]; - struct ieee80211_channel channels[39]; + struct ieee80211_supported_band bands[3]; + struct ieee80211_channel channels[CEN_CHANNELS]; + struct ieee80211_sband_iftype_data iftype_6ghz; /* The firmware's own reports, read at bring-up (system commands 19 and 8). */ u8 hw_channels[REPLY_SIZE], system_caps[REPLY_SIZE]; struct debugfs_blob_wrapper hw_channels_blob, system_caps_blob; @@ -87,9 +92,13 @@ static int query_link_status(struct centauri_t6050_wifi *wifi); static const u32 rx_buffer[5] = { 0, 0, 0x620000, 0x680000, 0x700000 }; static const u16 ring_size[5] = { 0, 64, 192, 96, 192 }; -static const u16 five_ghz[] = { - 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, - 120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 161, 165, +static const struct { + enum nl80211_band band; + u8 first, last, step; +} band_plan[] = { + { NL80211_BAND_2GHZ, 1, 14, 1 }, { NL80211_BAND_5GHZ, 36, 64, 4 }, + { NL80211_BAND_5GHZ, 100, 144, 4 }, { NL80211_BAND_5GHZ, 149, 177, 4 }, + { NL80211_BAND_6GHZ, 1, 233, 4 }, }; static struct ieee80211_rate rates[] = { { .bitrate = 10 }, { .bitrate = 20 }, { .bitrate = 55 }, @@ -105,6 +114,21 @@ static const u32 cipher_suites[] = { WLAN_CIPHER_SUITE_AES_CMAC, }; +/* The firmware's band numbers: 0 is 2.4 GHz, 1 is 5 GHz, 2 is 6 GHz. */ +static int firmware_band(enum nl80211_band band) +{ + switch (band) { + case NL80211_BAND_2GHZ: + return 0; + case NL80211_BAND_5GHZ: + return 1; + case NL80211_BAND_6GHZ: + return 2; + default: + return -EOPNOTSUPP; + } +} + static u16 index_read(struct centauri_t6050_wifi *wifi, unsigned int array, unsigned int index) { @@ -196,7 +220,7 @@ static void report_beacon(struct centauri_t6050_wifi *wifi, const u8 *payload, struct cfg80211_bss *bss; u16 frame_size; int number = 0, frequency, signal; - enum nl80211_band band; + enum nl80211_band band = NL80211_BAND_2GHZ; if (!wifi->registered || size < 0x60 + 36) return; @@ -211,12 +235,26 @@ static void report_beacon(struct centauri_t6050_wifi *wifi, const u8 *payload, ie += 2 + ie[1]) { if ((ie[0] == WLAN_EID_DS_PARAMS || ie[0] == WLAN_EID_HT_OPERATION) && - ie[1]) + ie[1]) { number = ie[2]; + band = number <= 14 ? NL80211_BAND_2GHZ : + NL80211_BAND_5GHZ; + } else if (ie[0] == WLAN_EID_EXTENSION && ie[1] > 1 && + ie[2] == WLAN_EID_EXT_HE_OPERATION && + ie[1] - 1 >= sizeof(struct ieee80211_he_operation) && + ie[1] >= ieee80211_he_oper_size(ie + 3)) { + /* 6 GHz beacons carry neither: the HE operation names the channel. */ + const struct ieee80211_he_6ghz_oper *oper = + ieee80211_he_6ghz_oper((const void *)(ie + 3)); + + if (oper && !number) { + number = oper->primary; + band = NL80211_BAND_6GHZ; + } + } } if (!number) return; - band = number <= 14 ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; frequency = ieee80211_channel_to_frequency(number, band); channel = ieee80211_get_channel(wifi->wiphy, frequency); if (!channel) @@ -730,6 +768,137 @@ static void firmware_report(struct centauri_t6050_wifi *wifi, u32 id, u8 *buffer blob->size = size; } +/* + * The channel list: a count, then one 4-byte entry per channel the current + * country allows at each width: the channel number (the center channel for + * 40-160 MHz), then the band in bits 0-1, the width (20 << n MHz) in bits 2-3 + * and the flags in bits 4-7, then two bytes this driver does not use (a + * width mask and, on 6 GHz, power-mode bits). Scan requests take the same + * band and flag bits. + */ +#define CHANNEL_PASSIVE BIT(4) +#define CHANNEL_RADAR BIT(6) + +static const u8 *channel_entry(const u8 *list, size_t size, int band, + unsigned int width, unsigned int number) +{ + unsigned int count = size ? list[0] : 0, i, span = 2 * (1 << width) - 2; + + if (1 + 4 * count > size) + count = size ? (size - 1) / 4 : 0; + for (i = 0; i < count; i++) { + const u8 *entry = list + 1 + 4 * i; + + if ((entry[1] & 3) != band || ((entry[1] >> 2) & 3) != width) + continue; + if (number + span >= entry[0] && number <= entry[0] + span) + return entry; + } + return NULL; +} + +/* + * The firmware's list decides which channels exist and how: a band-plan + * channel it leaves out is disabled, its flags mark the rest, and a width no + * entry covers is not used. Applied over what cfg80211's regulatory domain + * set, after every change of it (the notifier) and at bring-up. + */ +static void channels_apply(struct centauri_t6050_wifi *wifi) +{ + const u8 *list = wifi->hw_channels; + size_t size = wifi->hw_channels_blob.size; + unsigned int counted[3] = {}, i; + + if (!size) + return; + for (i = 0; i < CEN_CHANNELS; i++) { + struct ieee80211_channel *channel = &wifi->channels[i]; + int band = firmware_band(channel->band); + const u8 *entry = channel_entry(list, size, band, 0, + channel->hw_value); + + if (!entry) { + channel->flags |= IEEE80211_CHAN_DISABLED; + continue; + } + if (entry[1] & CHANNEL_PASSIVE) + channel->flags |= IEEE80211_CHAN_NO_IR; + if (entry[1] & CHANNEL_RADAR) + channel->flags |= IEEE80211_CHAN_RADAR; + if (!channel_entry(list, size, band, 1, channel->hw_value)) + channel->flags |= IEEE80211_CHAN_NO_HT40; + if (!channel_entry(list, size, band, 2, channel->hw_value)) + channel->flags |= IEEE80211_CHAN_NO_80MHZ; + if (!channel_entry(list, size, band, 3, channel->hw_value)) + channel->flags |= IEEE80211_CHAN_NO_160MHZ; + if (!(channel->flags & IEEE80211_CHAN_DISABLED)) + counted[band]++; + } + dev_info(&wifi->control->pdev->dev, + "Wi-Fi firmware channels: 2.4 GHz %u, 5 GHz %u, 6 GHz %u (%u entries)\n", + counted[0], counted[1], counted[2], list[0]); +} + +/* + * 6 GHz needs HE: the station's HE capabilities element as the firmware + * reports it (capabilities TLV 0xff), with the 6 GHz band capabilities taken + * from its VHT element (TLV 0xbf). Without them the band is not registered. + */ +static bool he_6ghz_from_firmware(struct centauri_t6050_wifi *wifi) +{ + struct ieee80211_sband_iftype_data *data = &wifi->iftype_6ghz; + struct ieee80211_sta_he_cap *he = &data->he_cap; + const u8 *caps = wifi->system_caps, *he_elem = NULL, *vht = NULL; + size_t size = wifi->system_caps_blob.size, pos = 0, mcs; + u32 vht_cap = 0; + + while (pos + 4 <= size) { + u16 tag = get_unaligned_le16(caps + pos); + u16 length = get_unaligned_le16(caps + pos + 2); + const u8 *value = caps + pos + 4; + + if (length > size - pos - 4) + break; + if (tag == WLAN_EID_EXTENSION && length >= 3 + 6 + 11 + 4 && + value[0] == WLAN_EID_EXTENSION && value[1] == length - 2 && + value[2] == WLAN_EID_EXT_HE_CAPABILITY) + he_elem = value; + if (tag == WLAN_EID_VHT_CAPABILITY && length >= 2 + 12 && + value[0] == WLAN_EID_VHT_CAPABILITY) + vht = value; + pos += 4 + length; + } + if (!he_elem) + return false; + memcpy(&he->he_cap_elem, he_elem + 3, sizeof(he->he_cap_elem)); + mcs = he_elem[1] - 1 - sizeof(he->he_cap_elem); + memcpy(&he->he_mcs_nss_supp, he_elem + 3 + sizeof(he->he_cap_elem), + min(mcs, sizeof(he->he_mcs_nss_supp))); + if (mcs > sizeof(he->he_mcs_nss_supp)) + memcpy(he->ppe_thres, + he_elem + 3 + sizeof(he->he_cap_elem) + + sizeof(he->he_mcs_nss_supp), + min(mcs - sizeof(he->he_mcs_nss_supp), + sizeof(he->ppe_thres))); + he->has_he = true; + if (vht) + vht_cap = get_unaligned_le32(vht + 2); + data->he_6ghz_capa.capa = cpu_to_le16( + u16_encode_bits(u32_get_bits(vht_cap, + IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK), + IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) | + u16_encode_bits(vht_cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK, + IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN) | + u16_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED, + IEEE80211_HE_6GHZ_CAP_SM_PS) | + (vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN ? + IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS : 0) | + (vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN ? + IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS : 0)); + data->types_mask = BIT(NL80211_IFTYPE_STATION); + return true; +} + static void firmware_reports(struct centauri_t6050_wifi *wifi) { firmware_report(wifi, 19, wifi->hw_channels, &wifi->hw_channels_blob); @@ -737,10 +906,45 @@ static void firmware_reports(struct centauri_t6050_wifi *wifi) dev_info(&wifi->control->pdev->dev, "Wi-Fi firmware channel list: %lu bytes, capabilities: %lu bytes\n", wifi->hw_channels_blob.size, wifi->system_caps_blob.size); - debugfs_create_blob("hw_channels", 0400, wifi->wiphy->debugfsdir, - &wifi->hw_channels_blob); - debugfs_create_blob("system_caps", 0400, wifi->wiphy->debugfsdir, - &wifi->system_caps_blob); +} + +/* The band plan, with the firmware's legacy rates (CCK on 2.4 GHz only). */ +static void bands_init(struct centauri_t6050_wifi *wifi) +{ + unsigned int i, n = 0, c; + + for (i = 0; i < ARRAY_SIZE(band_plan); i++) { + enum nl80211_band band = band_plan[i].band; + struct ieee80211_supported_band *sband = + &wifi->bands[firmware_band(band)]; + + if (!sband->channels) + sband->channels = wifi->channels + n; + for (c = band_plan[i].first; c <= band_plan[i].last; + c += band_plan[i].step) { + wifi->channels[n].band = band; + wifi->channels[n].hw_value = c; + wifi->channels[n].center_freq = + ieee80211_channel_to_frequency(c, band); + sband->n_channels++; + n++; + } + sband->band = band; + sband->bitrates = band == NL80211_BAND_2GHZ ? rates : rates + 4; + sband->n_bitrates = band == NL80211_BAND_2GHZ ? + ARRAY_SIZE(rates) : + ARRAY_SIZE(rates) - 4; + } + wifi->wiphy->bands[NL80211_BAND_2GHZ] = &wifi->bands[0]; + wifi->wiphy->bands[NL80211_BAND_5GHZ] = &wifi->bands[1]; + if (he_6ghz_from_firmware(wifi)) { + _ieee80211_set_sband_iftype_data(&wifi->bands[2], + &wifi->iftype_6ghz, 1); + wifi->wiphy->bands[NL80211_BAND_6GHZ] = &wifi->bands[2]; + } else { + dev_warn(&wifi->control->pdev->dev, + "Wi-Fi: no HE capabilities from the firmware; no 6 GHz band\n"); + } } static int radio_start(struct centauri_t6050_wifi *wifi) @@ -809,21 +1013,25 @@ static int scan_profile27(struct centauri_t6050_wifi *wifi) struct ieee80211_channel *channel = request->channels[next++]; unsigned int number; + int band; - /* The passive-scan wire mode is not established for this profile. */ - if (channel->flags & - (IEEE80211_CHAN_DISABLED | IEEE80211_CHAN_NO_IR)) + if (channel->flags & IEEE80211_CHAN_DISABLED) continue; - if (channel->band != NL80211_BAND_2GHZ && - channel->band != NL80211_BAND_5GHZ) - return -EOPNOTSUPP; + band = firmware_band(channel->band); + if (band < 0) + return band; number = ieee80211_frequency_to_channel( channel->center_freq); if (!number || number > 255) return -EINVAL; channels[1 + 4 * count] = number; - channels[2 + 4 * count] = channel->band == - NL80211_BAND_5GHZ; + channels[2 + 4 * count] = band; + /* Flagged as in the firmware's channel list: listen only. */ + if (channel->flags & + (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) + channels[2 + 4 * count] |= CHANNEL_PASSIVE; + if (channel->flags & IEEE80211_CHAN_RADAR) + channels[2 + 4 * count] |= CHANNEL_RADAR; count++; } if (!count) @@ -1087,7 +1295,7 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, u8 rsn_body[255], ssid[35], zero[20] = {}, pmf; u8 *payload = wifi->connect_payload; size_t size = 130, rsn_size, rsn_prefix, rsn_tail; - int ret = 0, offset; + int ret = 0, offset, band; if (!params->ssid_len || params->ssid_len > 32 || !params->crypto.psk || params->crypto.n_ciphers_pairwise != 1 || @@ -1134,11 +1342,11 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, channel = bss->channel; cfg80211_put_bss(wiphy, bss); } - if (channel->band != NL80211_BAND_2GHZ && - channel->band != NL80211_BAND_5GHZ) { - ret = -EOPNOTSUPP; + ret = firmware_band(channel->band); + if (ret < 0) goto out; - } + band = ret; + ret = 0; wifi->connect_channel = channel; memcpy(wifi->ssid, params->ssid, params->ssid_len); wifi->ssid_len = params->ssid_len; @@ -1147,7 +1355,7 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, memcpy(payload + 1, wifi->bssid, ETH_ALEN); payload[7] = ieee80211_frequency_to_channel(channel->center_freq); - payload[8] = channel->band == NL80211_BAND_2GHZ ? 0 : 1; + payload[8] = band; payload[0x47] = 4; put_unaligned_le16(4, payload + 0x48); @@ -1415,18 +1623,22 @@ static void wifi_regulatory(struct wiphy *wiphy, struct centauri_t6050_wifi *wifi = *(struct centauri_t6050_wifi **)wiphy_priv(wiphy); u8 country[3] = { request->alpha2[0], request->alpha2[1], 1 }; + bool named = country[0] >= 'A' && country[0] <= 'Z' && + country[1] >= 'A' && country[1] <= 'Z'; int ret; - if (country[0] < 'A' || country[0] > 'Z' || country[1] < 'A' || - country[1] > 'Z') - return; mutex_lock(&wifi->lock); - if (wifi->configured) { + if (wifi->configured && named) { ret = command(wifi, 9, country, sizeof(country)); if (ret) dev_err(&wifi->control->pdev->dev, "firmware country update failed: %d\n", ret); + else + firmware_report(wifi, 19, wifi->hw_channels, + &wifi->hw_channels_blob); } + /* cfg80211 has just recomputed the channel flags from its own rules. */ + channels_apply(wifi); mutex_unlock(&wifi->lock); } @@ -1754,7 +1966,6 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) { struct centauri_t6050_wifi *wifi; u8 address[ETH_ALEN]; - unsigned int i; int ret; wifi = kzalloc_obj(*wifi); @@ -1789,31 +2000,6 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) wifi->wiphy->n_akm_suites = ARRAY_SIZE(akm_suites); wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK); - for (i = 0; i < 13; i++) { - wifi->channels[i].band = NL80211_BAND_2GHZ; - wifi->channels[i].hw_value = i + 1; - wifi->channels[i].center_freq = ieee80211_channel_to_frequency( - i + 1, NL80211_BAND_2GHZ); - wifi->channels[i].max_power = 20; - } - for (i = 0; i < ARRAY_SIZE(five_ghz); i++) { - wifi->channels[13 + i].band = NL80211_BAND_5GHZ; - wifi->channels[13 + i].hw_value = five_ghz[i]; - wifi->channels[13 + i].center_freq = - ieee80211_channel_to_frequency(five_ghz[i], - NL80211_BAND_5GHZ); - wifi->channels[13 + i].max_power = 20; - } - wifi->bands[0].channels = wifi->channels; - wifi->bands[0].n_channels = 13; - wifi->bands[0].bitrates = rates; - wifi->bands[0].n_bitrates = ARRAY_SIZE(rates); - wifi->bands[1].channels = wifi->channels + 13; - wifi->bands[1].n_channels = ARRAY_SIZE(five_ghz); - wifi->bands[1].bitrates = rates + 4; - wifi->bands[1].n_bitrates = ARRAY_SIZE(rates) - 4; - wifi->wiphy->bands[NL80211_BAND_2GHZ] = &wifi->bands[0]; - wifi->wiphy->bands[NL80211_BAND_5GHZ] = &wifi->bands[1]; ret = eth_platform_get_mac_address(&wifi->a.pdev->dev, address); if (!ret) { @@ -1827,10 +2013,25 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) &wifi->a.pdev->dev, "No valid factory MAC property; using a random address\n"); } + /* The bands come from the firmware's reports: start the radio first. */ + ret = radio_start(wifi); + if (ret) { + dev_err(&c->pdev->dev, + "Wi-Fi ring/interface setup failed: %d\n", ret); + goto failed; + } + bands_init(wifi); ret = wiphy_register(wifi->wiphy); if (ret) goto failed; wifi->registered = true; + debugfs_create_blob("hw_channels", 0400, wifi->wiphy->debugfsdir, + &wifi->hw_channels_blob); + debugfs_create_blob("system_caps", 0400, wifi->wiphy->debugfsdir, + &wifi->system_caps_blob); + rtnl_lock(); + channels_apply(wifi); + rtnl_unlock(); wifi->wdev.wiphy = wifi->wiphy; wifi->wdev.iftype = NL80211_IFTYPE_STATION; wifi->wdev.netdev = wifi->netdev; @@ -1840,12 +2041,6 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) strscpy(wifi->netdev->name, "wlan%d", IFNAMSIZ); wifi->netdev->max_mtu = ETH_DATA_LEN; - ret = radio_start(wifi); - if (ret) { - dev_err(&c->pdev->dev, - "Wi-Fi ring/interface setup failed: %d\n", ret); - goto failed; - } ret = register_netdev(wifi->netdev); if (ret) goto failed; From 5663c0e8b696bdfe3a120443d3ded63a5c35d812 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Tue, 3 Nov 2026 13:03:01 -0800 Subject: [PATCH 307/342] wifi: apple: centauri: Support WPA3-Personal through the firmware's SAE The firmware runs SAE itself from the password. Offer SAE (AKM 00-0F-AC:8, SAE offload). The connect command carries one authentication and AKM pair: a request that offers SAE with a password sends SAE authentication (3) and AKM 8, with the password in TLV 313 as a 16-bit length and its bytes, and no PMK; one that offers PSK with a PMK sends open authentication and AKM 4 as before. Management frame protection travels in the station's RSN element only. TLV 316 is the security roaming groups bitmap, not a PMF flag: send 0 (no roaming groups), and TLV 304 (the join mode) as 5 for every join. 6 GHz admits WPA3-Personal only with management frame protection, so a 6 GHz connect without both is refused. Signed-off-by: Jeff Queisser Developed with Claude Code. Signed-off-by: Erik Bourget --- .../apple/centauri/t6050/centauri_wifi.c | 95 +++++++++++++++---- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index e89c280a5bdc4..5deffa85c8168 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -107,7 +107,7 @@ static struct ieee80211_rate rates[] = { { .bitrate = 360 }, { .bitrate = 480 }, { .bitrate = 540 }, }; -static const u32 akm_suites[] = { WLAN_AKM_SUITE_PSK }; +static const u32 akm_suites[] = { WLAN_AKM_SUITE_PSK, WLAN_AKM_SUITE_SAE }; static const u32 cipher_suites[] = { WLAN_CIPHER_SUITE_CCMP, @@ -1204,7 +1204,8 @@ static int rsn_caps_offset(const u8 *body, size_t size) return offset + 2 <= size ? offset : -EINVAL; } -static int rsn_psk_offset(const u8 *body, size_t size) +/* The offset of the RSN element's AKM list when it offers akm. */ +static int rsn_akm_offset(const u8 *body, size_t size, u32 akm) { size_t offset, end; u16 count; @@ -1223,25 +1224,25 @@ static int rsn_psk_offset(const u8 *body, size_t size) if (!count || end + 2 > size) return -EINVAL; for (i = 0; i < count; i++) - if (get_unaligned_be32(body + offset + 2 + 4 * i) == - WLAN_AKM_SUITE_PSK) + if (get_unaligned_be32(body + offset + 2 + 4 * i) == akm) return offset; return -EOPNOTSUPP; } -static int select_psk_rsn(const struct cfg80211_crypto_settings *crypto, - const u8 *body, size_t size, u8 *selected) +/* The station's RSN element with akm as its only AKM. */ +static int select_rsn(const struct cfg80211_crypto_settings *crypto, u32 akm, + const u8 *body, size_t size, u8 *selected) { size_t tail; unsigned int i; int offset; for (i = 0; i < crypto->n_akm_suites; i++) - if (crypto->akm_suites[i] == WLAN_AKM_SUITE_PSK) + if (crypto->akm_suites[i] == akm) break; if (i == crypto->n_akm_suites) return -EOPNOTSUPP; - offset = rsn_psk_offset(body, size); + offset = rsn_akm_offset(body, size, akm); if (offset < 0) return offset; @@ -1252,11 +1253,38 @@ static int select_psk_rsn(const struct cfg80211_crypto_settings *crypto, tail = offset + 2 + 4 * get_unaligned_le16(body + offset); memcpy(selected, body, offset); put_unaligned_le16(1, selected + offset); - put_unaligned_be32(WLAN_AKM_SUITE_PSK, selected + offset + 2); + put_unaligned_be32(akm, selected + offset + 2); memcpy(selected + offset + 6, body + tail, size - tail); return offset + 6 + size - tail; } +/* + * The connect command carries one authentication and AKM pair, in the bytes + * at 0x46 and 0x47: WPA2-Personal is open authentication with AKM 4 and the + * PMK at 0x4c, WPA3-Personal is SAE authentication with AKM 8 and the + * password in TLV 313, which the firmware runs SAE from. + */ +#define CONNECT_AUTH_OPEN 0 +#define CONNECT_AUTH_SAE 3 +#define CONNECT_AKM_PSK 4 +#define CONNECT_AKM_SAE 8 + +/* The AKM of the client's request whose credential it supplies, SAE first. */ +static u32 connect_akm(const struct cfg80211_crypto_settings *crypto) +{ + bool psk = false; + unsigned int i; + + for (i = 0; i < crypto->n_akm_suites; i++) { + if (crypto->akm_suites[i] == WLAN_AKM_SUITE_SAE && + crypto->sae_pwd_len) + return WLAN_AKM_SUITE_SAE; + if (crypto->akm_suites[i] == WLAN_AKM_SUITE_PSK && crypto->psk) + psk = true; + } + return psk ? WLAN_AKM_SUITE_PSK : 0; +} + static void append_tlv(u8 *payload, size_t *size, u16 tag, const void *data, u16 length) { @@ -1281,6 +1309,10 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, 0xff, 0xff, 0xff, 0xff, 3, 0, 0, }; + /* TLV 304: the join mode, 5 for every join. */ + static const u8 join_mode = 5; + /* TLV 316: no security roaming groups. */ + static const u8 roaming; static const __le32 connection_timeouts[] = { cpu_to_le32(260), cpu_to_le32(6000), cpu_to_le32(2000), cpu_to_le32(15000), cpu_to_le32(300), @@ -1292,12 +1324,16 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, params->channel ?: params->channel_hint; struct cfg80211_bss *bss; const u8 *rsn; - u8 rsn_body[255], ssid[35], zero[20] = {}, pmf; + u8 rsn_body[255], ssid[35]; u8 *payload = wifi->connect_payload; size_t size = 130, rsn_size, rsn_prefix, rsn_tail; int ret = 0, offset, band; + u32 akm = connect_akm(¶ms->crypto); + bool sae = akm == WLAN_AKM_SUITE_SAE, mfpc; + u8 password[2 + SAE_PASSWORD_MAX_LEN]; - if (!params->ssid_len || params->ssid_len > 32 || !params->crypto.psk || + if (!params->ssid_len || params->ssid_len > 32 || !akm || + params->crypto.sae_pwd_len > SAE_PASSWORD_MAX_LEN || params->crypto.n_ciphers_pairwise != 1 || params->crypto.ciphers_pairwise[0] != WLAN_CIPHER_SUITE_CCMP || params->crypto.cipher_group != WLAN_CIPHER_SUITE_CCMP || @@ -1306,16 +1342,18 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, rsn = cfg80211_find_ie(WLAN_EID_RSN, params->ie, params->ie_len); if (!rsn) return -EINVAL; - ret = select_psk_rsn(¶ms->crypto, rsn + 2, rsn[1], rsn_body); + ret = select_rsn(¶ms->crypto, akm, rsn + 2, rsn[1], rsn_body); if (ret < 0) return ret; rsn_size = ret; - /* The station's own RSN capabilities go to the firmware; bit 7 is MFPC. */ + /* + * The station's own RSN element carries its management frame + * protection to the firmware; bit 7 of its capabilities is MFPC. + */ offset = rsn_caps_offset(rsn_body, rsn_size); if (offset < 0) return -EINVAL; - pmf = !!(get_unaligned_le16(rsn_body + offset) & - BIT(7)); + mfpc = get_unaligned_le16(rsn_body + offset) & BIT(7); ret = 0; mutex_lock(&wifi->lock); if (READ_ONCE(wifi->stopping)) { @@ -1347,6 +1385,11 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, goto out; band = ret; ret = 0; + /* 6 GHz admits WPA3-Personal only with management frame protection. */ + if (channel->band == NL80211_BAND_6GHZ && (!sae || !mfpc)) { + ret = -EOPNOTSUPP; + goto out; + } wifi->connect_channel = channel; memcpy(wifi->ssid, params->ssid, params->ssid_len); wifi->ssid_len = params->ssid_len; @@ -1356,13 +1399,16 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, payload[7] = ieee80211_frequency_to_channel(channel->center_freq); payload[8] = band; - payload[0x47] = 4; + payload[0x46] = sae ? CONNECT_AUTH_SAE : CONNECT_AUTH_OPEN; + payload[0x47] = sae ? CONNECT_AKM_SAE : CONNECT_AKM_PSK; put_unaligned_le16(4, payload + 0x48); - put_unaligned_le16(32, payload + 0x4a); - memcpy(payload + 0x4c, params->crypto.psk, 32); + if (!sae) { + put_unaligned_le16(32, payload + 0x4a); + memcpy(payload + 0x4c, params->crypto.psk, 32); + } - append_tlv(payload, &size, 304, zero, 1); + append_tlv(payload, &size, 304, &join_mode, 1); append_tlv(payload, &size, 63763, connection_timeouts, sizeof(connection_timeouts)); ssid[0] = 1; @@ -1371,8 +1417,16 @@ static int wifi_connect(struct wiphy *wiphy, struct net_device *netdev, memcpy(ssid + 3, params->ssid, params->ssid_len); append_tlv(payload, &size, 342, ssid, 3 + params->ssid_len); append_tlv(payload, &size, WLAN_EID_RSN, rsn_body, rsn_size); + if (sae) { + put_unaligned_le16(params->crypto.sae_pwd_len, password); + memcpy(password + 2, params->crypto.sae_pwd, + params->crypto.sae_pwd_len); + append_tlv(payload, &size, 313, password, + 2 + params->crypto.sae_pwd_len); + memzero_explicit(password, sizeof(password)); + } - append_tlv(payload, &size, 316, &pmf, 1); + append_tlv(payload, &size, 316, &roaming, 1); append_tlv(payload, &size, 376, mld_defaults, sizeof(mld_defaults)); wifi->connect_size = size; @@ -2000,6 +2054,7 @@ int centauri_t6050_wifi_register(struct centauri_t6050 *c) wifi->wiphy->n_akm_suites = ARRAY_SIZE(akm_suites); wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK); + wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_SAE_OFFLOAD); ret = eth_platform_get_mac_address(&wifi->a.pdev->dev, address); if (!ret) { From b4ef30560a000e051a4784fb70f77dfef84f8386 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 05:25:55 -0500 Subject: [PATCH 308/342] wifi: apple: centauri: t6050: tell the firmware the host is awake before a join Without the host power state the N1 Alpha firmware treats the host as asleep, powers the PHYs down and traps. Before the first join of a firmware boot, send command 6 with a zero body (host power state awake), command 43 (packet lifetime) and command 52 (control profile). Each is sent once per firmware boot and retried at the next join if it fails. The host_setup parameter (default on) turns this off. This is Joshua Warren's fix from the J813/J873 N1 driver (linux-aurora 1242f12e876b), which Erik Bourget ported to the T6050 driver as aurora-silicon/linux#828. #828 targets t6050/centauri-wifi's centauri/centauri_wifi.c; with the T6050 transport now in centauri/t6050/, the same change goes here. Signed-off-by: Diljit Singh --- .../apple/centauri/t6050/centauri_wifi.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c index 5deffa85c8168..20d86b4e50ef1 100644 --- a/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c @@ -36,6 +36,11 @@ static_assert(DATA_RX_BUFFER + DATA_RX_SLOTS * 4096 <= DATA_TX_BUFFER); static_assert(DATA_TX_BUFFER + DATA_TX_SLOTS * BUFFER_SIZE <= CEN_ALPHA_WINDOW_SIZE); +static bool host_setup = true; +module_param(host_setup, bool, 0644); +MODULE_PARM_DESC(host_setup, + "Before a join, tell the firmware the host is awake (command 6) and apply the reference TX defaults (commands 43 and 52); 1 = on (default)"); + struct centauri_t6050_wifi { struct centauri_t6050 *control; struct cen_alpha_resources a; @@ -79,6 +84,9 @@ struct centauri_t6050_wifi { struct net_device_stats station_start; u32 data_rings_open; bool data_failed; + /* Sent once per firmware boot, before the first join (host_setup). */ + bool host_awake_sent; + u8 tx_defaults_applied; struct ieee80211_supported_band bands[3]; struct ieee80211_channel channels[CEN_CHANNELS]; struct ieee80211_sband_iftype_data iftype_6ghz; @@ -1474,6 +1482,43 @@ static struct cfg80211_bss *connected_bss(struct centauri_t6050_wifi *wifi) GFP_KERNEL); } +/* + * Without the host power state the firmware treats the host as asleep, powers + * the PHYs down and traps. Called with wifi->lock held. + */ +static void host_setup_commands(struct centauri_t6050_wifi *wifi) +{ + static const u8 awake[3] = {}; + static const u8 control_profile[] = { 0x54, 1, 10, 0, 0, 8, 0, 0, + 0xff, 0xff, 0xff, 0xff, 1, 1 }; + struct device *dev = &wifi->control->pdev->dev; + u8 lifetime[20] = {}; + int ret, i; + + if (!host_setup) + return; + if (!wifi->host_awake_sent) { + ret = command(wifi, 6, awake, sizeof(awake)); + dev_info(dev, "host power state awake: rc=%d status=%u\n", ret, + wifi->reply_status); + wifi->host_awake_sent = !ret; + } + if (!(wifi->tx_defaults_applied & BIT(0))) { + for (i = 0; i < 4; i++) + put_unaligned_le32(2000000, lifetime + 4 + 4 * i); + ret = command(wifi, 43, lifetime, sizeof(lifetime)); + if (!ret) + wifi->tx_defaults_applied |= BIT(0); + dev_info(dev, "TX packet lifetime defaults: rc=%d\n", ret); + } + if (!(wifi->tx_defaults_applied & BIT(1))) { + ret = command(wifi, 52, control_profile, sizeof(control_profile)); + if (!ret) + wifi->tx_defaults_applied |= BIT(1); + dev_info(dev, "TX control profile defaults: rc=%d\n", ret); + } +} + static void connect_worker(struct work_struct *work) { struct centauri_t6050_wifi *wifi = @@ -1488,6 +1533,7 @@ static void connect_worker(struct work_struct *work) mutex_unlock(&wifi->lock); return; } + host_setup_commands(wifi); slot = wifi->command_head; ret = command(wifi, 131072, wifi->connect_payload, wifi->connect_size); memzero_explicit(wifi->connect_payload, sizeof(wifi->connect_payload)); From d0c84b3e211906de73e74f0c12d4416d2452bf72 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sat, 7 Nov 2026 23:52:23 -0500 Subject: [PATCH 309/342] PCI: apple: Allow retained-link s2idle on J716c The adopted J716c radio host currently rejects every noirq suspend. Its radio drivers save PCI state without entering D3, and the native host and DART retain the running hierarchy during suspend-to-idle. Allow this path only for J716c s2idle when the controller and ports are healthy and all PCI devices are accessible in D0. Validate the retained hierarchy again on resume and block downstream configuration access if validation fails. Leave existing behavior for managed-SID hosts, other adopted platforms and deeper sleep unchanged. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/pci/controller/pcie-apple.c | 74 ++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index c19f271e40d2b..eda231e2ea0b3 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -4794,6 +4794,59 @@ static void apple_pcie_stop_for_sleep(struct device *dev) apple_pcie_tunnel_hierarchy_lost(dev); } +/* + * The J716c radio drivers save PCI state without entering D3. The PCI core + * keeps the root port in D0 as well. Its host and DART have no switchable + * power domains, and the DART saves its live translations without stopping + * them. For s2idle, retain that running hierarchy instead of resetting it. + * + * Check hardware PMCSR rather than current_state: the PCI core may mark a + * driverless root port PCI_UNKNOWN even though its hardware remains in D0. + */ +static int apple_pcie_check_d0(struct pci_dev *pdev, void *data) +{ + int *error = data; + u16 value; + + if (pci_read_config_word(pdev, PCI_VENDOR_ID, &value) || + value != pdev->vendor) { + *error = -ENODEV; + } else if (pdev->pm_cap && + (pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &value) || + (value & PCI_PM_CTRL_STATE_MASK) != PCI_D0)) { + *error = -EBUSY; + } + if (*error) + pci_err(pdev, "adopted link requires accessible D0 devices for s2idle\n"); + return *error; +} + +static int apple_pcie_check_adopted_s2idle(struct apple_pcie *pcie) +{ + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + struct apple_pcie_port *port; + int error = 0; + + /* Other adopted platforms and deeper sleep remain unqualified. */ + if (!of_machine_is_compatible("apple,j716c") || !pm_suspend_no_platform()) + return -EBUSY; + + if (!(readl(pcie->base + CORE_RC_CTL) & CORE_RC_CTL_RUN) || + !(readl(pcie->base + CORE_RC_STAT) & CORE_RC_STAT_READY)) + return -ENOLINK; + + list_for_each_entry(port, &pcie->ports, entry) { + if (READ_ONCE(port->link_failed) || + !(apple_pcie_port_readl(port, PORT_STATUS) & PORT_STATUS_READY) || + (apple_pcie_port_readl(port, PORT_LINKSTS) & + (PORT_LINKSTS_UP | PORT_LINKSTS_BUSY)) != PORT_LINKSTS_UP || + (apple_pcie_port_readl(port, PORT_INTSTAT) & BIT(PORT_INT_LINK_DOWN))) + return -ENOLINK; + } + pci_walk_bus(bridge->bus, apple_pcie_check_d0, &error); + return error; +} + static int apple_pcie_suspend_noirq(struct device *dev) { struct apple_pcie *pcie = apple_pcie_lookup(dev); @@ -4804,8 +4857,12 @@ static int apple_pcie_suspend_noirq(struct device *dev) */ if (pcie->managed_sids) return pm_suspend_target_state == PM_SUSPEND_TO_IDLE ? 0 : -EBUSY; - if (pcie->hw->adopt_link) - return -EBUSY; + if (pcie->hw->adopt_link) { + int ret = apple_pcie_check_adopted_s2idle(pcie); + + pcie->link_kept = !ret; + return ret; + } if (!pcie->hw->tunneled) return 0; pcie->reset_on_resume = false; @@ -4862,6 +4919,19 @@ static int apple_pcie_resume_noirq(struct device *dev) struct apple_pcie_port *port; int ret; + if (pcie->hw->adopt_link) { + if (!pcie->link_kept) + return 0; + pcie->link_kept = false; + ret = apple_pcie_check_adopted_s2idle(pcie); + if (ret) { + /* Block downstream config access if the retained link was lost. */ + list_for_each_entry(port, &pcie->ports, entry) + WRITE_ONCE(port->link_failed, true); + dev_err(dev, "adopted link lost during suspend-to-idle: %d\n", ret); + } + return ret; + } if (!pcie->hw->tunneled) return 0; /* The domain's hold for the sleep ends first, whatever follows. */ From 4df5c8c23e0e1b633796efe4061c4852b0754ec9 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 14:49:09 -0500 Subject: [PATCH 310/342] arm64: dts: apple: Describe the J716c camera capture resources Provide the J716c ISP's named register windows, host DART streams, sensor preset and power gates. Reuse the existing hardware inventory nodes and add the aliases needed by the loader. Leave the camera and its DARTs disabled until the loader reserves the required memory and supplies the runtime properties. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../arm64/boot/dts/apple/t6050-j716c-isp.dtsi | 146 ++++++++++++++++++ arch/arm64/boot/dts/apple/t6050-j716c.dts | 2 + 2 files changed, 148 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t6050-j716c-isp.dtsi diff --git a/arch/arm64/boot/dts/apple/t6050-j716c-isp.dtsi b/arch/arm64/boot/dts/apple/t6050-j716c-isp.dtsi new file mode 100644 index 0000000000000..b6b1675d26022 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-j716c-isp.dtsi @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* J716c camera: enabled only after the loader reserves the current firmware. */ +/ { + aliases { + isp = &isp0; + isp-dart0 = &isp0_dart; + isp-dart1 = &isp0_dart1; + isp-dart2 = &isp0_dart2; + }; +}; + +&isp0 { + /delete-property/ clocks; + compatible = "apple,t6050-isp", "apple,isp"; + reg = <0x5 0x80000000 0 0x1604000>, + <0x5 0x82924000 0 0x40>, + <0x5 0x829241d0 0 0x20>, + <0x5 0x82924464 0 0x10>, + <0x5 0xc3b50000 0 0x8000>; + reg-names = "coproc", "mbox", "gpio", "mbox2", "wdt"; + interrupts = ; + iommus = <&isp0_dart 0>, <&isp0_dart 12>, + <&isp0_dart1 0>, <&isp0_dart1 12>, + <&isp0_dart2 0>, <&isp0_dart2 12>; + power-domains = <&ps_isp_sys>, <&ps_isp_cpu>, <&ps_isp_fe>, + <&ps_ispsens0>, <&ps_isp_dprx>, <&ps_isp_secure>, + <&ps_isp_be>, <&ps_isp_clr>; + apple,dart-vm-size = /bits/ 64 <0xde000000>; + status = "disabled"; + sensor-presets { + preset0 { + apple,config-index = <5>; + apple,input-size = <1920 2160>; + apple,output-size = <1920 1080>; + apple,crop = <0 0 1920 1080>; + }; + }; +}; + +&isp0_dart { + compatible = "apple,t6050-isp-dart", "apple,t8110-dart"; + reg = <0x5 0x828c0000 0 0xc000>, <0x5 0x828d0000 0 0x4000>; + reg-names = "dart", "dapf"; + #iommu-cells = <1>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + status = "disabled"; +}; + +&isp0_dart1 { + compatible = "apple,t6050-isp-dart", "apple,t8110-dart"; + reg = <0x5 0x828e0000 0 0xc000>; + reg-names = "dart"; + #iommu-cells = <1>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + status = "disabled"; +}; + +&isp0_dart2 { + compatible = "apple,t6050-isp-dart", "apple,t8110-dart"; + reg = <0x5 0x82900000 0 0xc000>; + reg-names = "dart"; + #iommu-cells = <1>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + status = "disabled"; +}; + +&pmgr1 { + ps_isp_cpu: power-controller@3b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_cpu"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; + ps_isp_fe: power-controller@3b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_fe"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; + ps_isp_dprx: power-controller@3d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_dprx"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; + ps_isp_secure: power-controller@3e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_secure"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; + ps_isp_be: power-controller@3e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_be"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; + ps_isp_clr: power-controller@3f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "isp_clr"; + apple,no-auto-pm; + power-domains = <&ps_isp_sys>; + }; +}; + +&ps_fab9_soc { + /delete-property/ power-domains; + apple,no-auto-pm; + apple,firmware-owned; + status = "okay"; +}; + +&ps_isp_sys { + apple,no-auto-pm; + apple,always-on; + status = "okay"; +}; + +&ps_ispsens0 { + apple,no-auto-pm; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 55af2f818a954..25ba638862ca0 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -621,3 +621,5 @@ apple,tunable = <0x140 0x1 0x1>, <0x2a0 0x7e 0xa>; }; + +#include "t6050-j716c-isp.dtsi" From 955b69739397d6bf969fb8877bbb2cd90b87fc09 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 04:30:48 -0500 Subject: [PATCH 311/342] arm64: dts: apple: Describe the J714s camera capture resources The 14-inch M5 Pro has the same T6050 camera as J716c. The J714sAP ADT describes the same ISP registers, the three DARTs with host streams 0 and 12, the same DAPF filter mask (0xcc3) and the same two firmware segments. Only the sensor type differs (0x74 instead of 0x75), and the loader supplies that. Include the J716c camera description. Tested on J714s: the ISP and its DARTs bind, and the camera streams 1920x1080 NV12 at 30 fps. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-j714s.dts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-j714s.dts b/arch/arm64/boot/dts/apple/t6050-j714s.dts index d98f6ac1d63a0..b95609c723f32 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714s.dts @@ -46,3 +46,6 @@ #define T6050_J714S #include "t6050-peripherals.dtsi" + +/* The same T6050 camera as J716c (J714sAP ADT); the loader sets the J714s sensor type. */ +#include "t6050-j716c-isp.dtsi" From eade37eae073ee1fda8c171a7c92af84efe46539 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 12:03:38 -0500 Subject: [PATCH 312/342] arm64: dts: apple: t8142-j813: share the SoC nodes J815 also has Move the CPU performance states, cluster controllers, PMC, SMC and MTP nodes out of the J813 files into t8142-j813-j815.dtsi, which also pulls in the J813 CPU idle, NVMe and power includes. The J813 and J815 ADTs (25G83) describe all of these identically. Each board names its own trackpad firmware and keeps its own MTP DART. The J813 DTB keeps the same nodes, properties and values. Only node order and phandle numbers change, and dtbs_check reports the same warnings as before. The J813 power include now includes the SPMI binding header itself, because it no longer follows the USB include. Signed-off-by: Diljit Singh --- .../arm64/boot/dts/apple/t8142-j813-j815.dtsi | 302 ++++++++++++++++++ .../dts/apple/t8142-j813-peripherals.dtsi | 97 ------ .../boot/dts/apple/t8142-j813-power.dtsi | 1 + arch/arm64/boot/dts/apple/t8142-j813.dts | 195 +---------- 4 files changed, 310 insertions(+), 285 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi diff --git a/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi new file mode 100644 index 0000000000000..811e017460685 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Shared by the 13- and 15-inch M5 MacBook Air (J813, J815). + * + * The J813 and J815 ADTs (25G83) describe the same CPU performance states, + * cluster controllers, PMC, SMC, MTP, ANS, watchdog and PMU. Each board + * supplies the CPUs, AIC, PMGR and MTP DART these nodes use, and names its + * trackpad firmware (the multi-touch hid-merge-personality differs). + */ +#include + +/ { + aliases { + mtp = &mtp; + keyboard = &keyboard; + }; + + /* State 1 is 300 MHz; firmware SRAM OPP tables begin at state 2. */ + /* Cap each cluster at its measured J813 firmware handoff state. */ + ecluster_opp: opp-table-0 { + compatible = "operating-points-v2"; + opp-shared; + + opp-300000000 { + opp-hz = /bits/ 64 <300000000>; + opp-level = <1>; + }; + + opp-972000000 { + opp-hz = /bits/ 64 <972000000>; + opp-level = <2>; + }; + + opp-1152000000 { + opp-hz = /bits/ 64 <1152000000>; + opp-level = <3>; + }; + + opp-1584000000 { + opp-hz = /bits/ 64 <1584000000>; + opp-level = <4>; + }; + + opp-1992000000 { + opp-hz = /bits/ 64 <1992000000>; + opp-level = <5>; + }; + + opp-2352000000 { + opp-hz = /bits/ 64 <2352000000>; + opp-level = <6>; + }; + + opp-2700000000 { + opp-hz = /bits/ 64 <2700000000>; + opp-level = <7>; + }; + + opp-2964000000 { + opp-hz = /bits/ 64 <2964000000>; + opp-level = <8>; + }; + }; + + pcluster_opp: opp-table-1 { + compatible = "operating-points-v2"; + opp-shared; + + opp-300000000 { + opp-hz = /bits/ 64 <300000000>; + opp-level = <1>; + }; + + opp-1308000000 { + opp-hz = /bits/ 64 <1308000000>; + opp-level = <2>; + }; + + opp-1608000000 { + opp-hz = /bits/ 64 <1608000000>; + opp-level = <3>; + }; + + opp-1932000000 { + opp-hz = /bits/ 64 <1932000000>; + opp-level = <4>; + }; + + opp-2220000000 { + opp-hz = /bits/ 64 <2220000000>; + opp-level = <5>; + }; + + opp-2508000000 { + opp-hz = /bits/ 64 <2508000000>; + opp-level = <6>; + }; + + opp-2820000000 { + opp-hz = /bits/ 64 <2820000000>; + opp-level = <7>; + }; + + opp-3072000000 { + opp-hz = /bits/ 64 <3072000000>; + opp-level = <8>; + }; + + opp-3300000000 { + opp-hz = /bits/ 64 <3300000000>; + opp-level = <9>; + }; + + opp-3516000000 { + opp-hz = /bits/ 64 <3516000000>; + opp-level = <10>; + }; + + /* ADT levels 11-20, measured on J813 (level 19, 4416 MHz, is below + * level 18 and left out). The SoC throttles them when hot. */ + opp-3720000000 { + opp-hz = /bits/ 64 <3720000000>; + opp-level = <11>; + }; + + opp-3876000000 { + opp-hz = /bits/ 64 <3876000000>; + opp-level = <12>; + }; + + opp-4020000000 { + opp-hz = /bits/ 64 <4020000000>; + opp-level = <13>; + }; + + opp-4176000000 { + opp-hz = /bits/ 64 <4176000000>; + opp-level = <14>; + }; + + opp-4248000000 { + opp-hz = /bits/ 64 <4248000000>; + opp-level = <15>; + }; + + opp-4272000000 { + opp-hz = /bits/ 64 <4272000000>; + opp-level = <16>; + }; + + opp-4332000000 { + opp-hz = /bits/ 64 <4332000000>; + opp-level = <17>; + }; + + opp-4428000000 { + opp-hz = /bits/ 64 <4428000000>; + opp-level = <18>; + }; + + opp-4464000000 { + opp-hz = /bits/ 64 <4464000000>; + opp-level = <20>; + }; + }; +}; + +&{/soc} { + cpufreq_e: performance-controller@210e20000 { + compatible = "apple,t8142-cluster-cpufreq"; + reg = <0x2 0x10e20000 0 0x1000>; + #performance-domain-cells = <0>; + }; + + cpufreq_p: performance-controller@211e20000 { + compatible = "apple,t8142-cluster-cpufreq"; + reg = <0x2 0x11e20000 0 0x1000>; + #performance-domain-cells = <0>; + }; + + /* + * PMC voter interface (AppleT8142PMC, ADT pmc-pmgr 31 + 0x700000): + * floors at 0x382700000 + agent * 0x4000, per-agent states at + * +0x106000, rail enables at +0x108000. Agents (ADT voter-agent): + * PMP 0, CLPC 1, GFX 2, AP 3. iBoot leaves every enable at 0, so + * no vote is honoured and DRAM and fabric stay at their lowest + * states (CPU DRAM latency 171 ns instead of 70 ns). + */ + pmc: power-management@382700000 { + compatible = "apple,t8142-pmc"; + reg = <0x3 0x82700000 0x0 0x10000>, + <0x3 0x82806000 0x0 0x3000>; + reg-names = "voters", "rails"; + #address-cells = <1>; + #size-cells = <0>; + /* PMP, CLPC and AP agents */ + apple,static-voters = <0 1 3>; + + clpc: performance-controller@1 { + compatible = "apple,t8142-clpc"; + reg = <1>; + }; + }; + + smc_mbox: mailbox@38c608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0x8c608000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + smc: smc@38c600000 { + compatible = "apple,t8142-smc", "apple,t8103-smc"; + reg = <3 0x8c600000 0 0x4000>, <3 0x8de00000 0 0x120000>; + reg-names = "smc", "sram"; + mboxes = <&smc_mbox>; + + hwmon { + compatible = "apple,smc-hwmon"; + apple,discover-temperatures; + }; + + smc_gpio: gpio { + compatible = "apple,smc-gpio"; + gpio-controller; + #gpio-cells = <2>; + }; + }; + + mtp: mtp@394600000 { + compatible = "apple,t8142-mtp", "apple,t8142-rtk-helper-asc4", + "apple,mtp", "apple,rtk-helper-asc4"; + /* The second region is firmware SRAM, not the ASC control window. */ + reg = <3 0x94600000 0 0x4000>, <3 0x94c00000 0 0x100000>; + reg-names = "asc", "sram"; + mboxes = <&mtp_mbox>; + iommus = <&mtp_dart 0>; + }; + + mtp_mbox: mailbox@394608000 { + compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <3 0x94608000 0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + mtp_dockchannel: fifo@394b14000 { + compatible = "apple,t8142-dockchannel", "apple,dockchannel"; + reg = <3 0x94b14000 0 0x1000>; + reg-names = "irq"; + interrupts = ; + ranges = <0 3 0x94b28000 0x20000>; + nonposted-mmio; + #address-cells = <1>; + #size-cells = <1>; + interrupt-controller; + #interrupt-cells = <2>; + + mtp_hid: input@8000 { + compatible = "apple,dockchannel-hid"; + reg = <0x8000 0x1000>, <0xc000 0x1000>, + <0x0000 0x1000>, <0x4000 0x1000>; + reg-names = "config", "data", "rmt-config", "rmt-data"; + iommus = <&mtp_dart 0>; + interrupt-parent = <&mtp_dockchannel>; + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>, <3 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "tx", "rx"; + apple,fifo-size = <0x800>; + apple,helper-cpu = <&mtp>; + /* + * ADT dockchannel-mtp/mtp-transport/multi-touch: + * function-afe-reset = smc-pmu pKW4('gP1c'), SMC GPIO 28. + * The MTP firmware cannot reach the AFE on its own ("No + * HINT_L"): after macOS left it running the trackpad + * worked, after a Linux warm reboot it stayed in reset. + */ + apple,afe-reset-gpios = <&smc_gpio 28 GPIO_ACTIVE_LOW>; + + stm { }; + + /* Each board names its own trackpad firmware. */ + multi-touch { + apple,power-method = <2>; + }; + + /* Layout is filled by the loader using this machine's own data. */ + keyboard: keyboard { }; + }; + }; +}; + +#include "t8142-j813-psci-idle.dtsi" +#include "t8142-j813-nvme.dtsi" +#include "t8142-j813-power.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8142-j813-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-peripherals.dtsi index 5ca6fed62568a..32415bdaa874b 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-peripherals.dtsi @@ -1,11 +1,8 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT -#include #include / { aliases { - mtp = &mtp; - keyboard = &keyboard; nvram = &nvram; }; @@ -172,56 +169,6 @@ #pwm-cells = <2>; }; - smc_mbox: mailbox@38c608000 { - compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; - reg = <3 0x8c608000 0 0x4000>; - interrupts = , - , - , - ; - interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; - #mbox-cells = <0>; - }; - - smc: smc@38c600000 { - compatible = "apple,t8142-smc", "apple,t8103-smc"; - reg = <3 0x8c600000 0 0x4000>, <3 0x8de00000 0 0x120000>; - reg-names = "smc", "sram"; - mboxes = <&smc_mbox>; - - hwmon { - compatible = "apple,smc-hwmon"; - apple,discover-temperatures; - }; - - smc_gpio: gpio { - compatible = "apple,smc-gpio"; - gpio-controller; - #gpio-cells = <2>; - }; - }; - - mtp: mtp@394600000 { - compatible = "apple,t8142-mtp", "apple,t8142-rtk-helper-asc4", - "apple,mtp", "apple,rtk-helper-asc4"; - /* The second region is firmware SRAM, not the ASC control window. */ - reg = <3 0x94600000 0 0x4000>, <3 0x94c00000 0 0x100000>; - reg-names = "asc", "sram"; - mboxes = <&mtp_mbox>; - iommus = <&mtp_dart 0>; - }; - - mtp_mbox: mailbox@394608000 { - compatible = "apple,t8142-asc-mailbox", "apple,asc-mailbox-v4"; - reg = <3 0x94608000 0 0x4000>; - interrupts = , - , - , - ; - interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; - #mbox-cells = <0>; - }; - mtp_dart: iommu@394800000 { compatible = "apple,t8142-dart", "apple,t8110-dart"; reg = <3 0x94800000 0 0xc000>; @@ -230,49 +177,5 @@ /* Keep host allocations clear of firmware's low IOVA mappings. */ apple,dma-range = <0 0x02000000 0 0x10000000>; }; - - mtp_dockchannel: fifo@394b14000 { - compatible = "apple,t8142-dockchannel", "apple,dockchannel"; - reg = <3 0x94b14000 0 0x1000>; - reg-names = "irq"; - interrupts = ; - ranges = <0 3 0x94b28000 0x20000>; - nonposted-mmio; - #address-cells = <1>; - #size-cells = <1>; - interrupt-controller; - #interrupt-cells = <2>; - - mtp_hid: input@8000 { - compatible = "apple,dockchannel-hid"; - reg = <0x8000 0x1000>, <0xc000 0x1000>, - <0x0000 0x1000>, <0x4000 0x1000>; - reg-names = "config", "data", "rmt-config", "rmt-data"; - iommus = <&mtp_dart 0>; - interrupt-parent = <&mtp_dockchannel>; - interrupts = <2 IRQ_TYPE_LEVEL_HIGH>, <3 IRQ_TYPE_LEVEL_HIGH>; - interrupt-names = "tx", "rx"; - apple,fifo-size = <0x800>; - apple,helper-cpu = <&mtp>; - /* - * ADT dockchannel-mtp/mtp-transport/multi-touch: - * function-afe-reset = smc-pmu pKW4('gP1c'), SMC GPIO 28. - * The MTP firmware cannot reach the AFE on its own ("No - * HINT_L"): after macOS left it running the trackpad - * worked, after a Linux warm reboot it stayed in reset. - */ - apple,afe-reset-gpios = <&smc_gpio 28 GPIO_ACTIVE_LOW>; - - stm { }; - - multi-touch { - firmware-name = "apple/tpmtfw-j813.bin"; - apple,power-method = <2>; - }; - - /* Layout is filled by the loader using this machine's own data. */ - keyboard: keyboard { }; - }; - }; }; #include "t8142-j813-pmp-tunables.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8142-j813-power.dtsi b/arch/arm64/boot/dts/apple/t8142-j813-power.dtsi index fa080be75e8fa..353cb55763765 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813-power.dtsi +++ b/arch/arm64/boot/dts/apple/t8142-j813-power.dtsi @@ -3,6 +3,7 @@ * Apple MacBook Air (13-inch, M5) J813: SMC power off / restart, the PMU on * SPMI and the watchdog. */ +#include &{/soc} { /* ADT /arm-io/wdt (wdt,t8142): restart (and the SMC's fallback). */ diff --git a/arch/arm64/boot/dts/apple/t8142-j813.dts b/arch/arm64/boot/dts/apple/t8142-j813.dts index 59788190b1933..21b1688e83f8a 100644 --- a/arch/arm64/boot/dts/apple/t8142-j813.dts +++ b/arch/arm64/boot/dts/apple/t8142-j813.dts @@ -165,155 +165,6 @@ interrupt-names = "phys", "virt", "hyp-phys", "hyp-virt"; }; - /* State 1 is 300 MHz; firmware SRAM OPP tables begin at state 2. */ - /* Cap each cluster at its measured J813 firmware handoff state. */ - ecluster_opp: opp-table-0 { - compatible = "operating-points-v2"; - opp-shared; - - opp-300000000 { - opp-hz = /bits/ 64 <300000000>; - opp-level = <1>; - }; - - opp-972000000 { - opp-hz = /bits/ 64 <972000000>; - opp-level = <2>; - }; - - opp-1152000000 { - opp-hz = /bits/ 64 <1152000000>; - opp-level = <3>; - }; - - opp-1584000000 { - opp-hz = /bits/ 64 <1584000000>; - opp-level = <4>; - }; - - opp-1992000000 { - opp-hz = /bits/ 64 <1992000000>; - opp-level = <5>; - }; - - opp-2352000000 { - opp-hz = /bits/ 64 <2352000000>; - opp-level = <6>; - }; - - opp-2700000000 { - opp-hz = /bits/ 64 <2700000000>; - opp-level = <7>; - }; - - opp-2964000000 { - opp-hz = /bits/ 64 <2964000000>; - opp-level = <8>; - }; - }; - - pcluster_opp: opp-table-1 { - compatible = "operating-points-v2"; - opp-shared; - - opp-300000000 { - opp-hz = /bits/ 64 <300000000>; - opp-level = <1>; - }; - - opp-1308000000 { - opp-hz = /bits/ 64 <1308000000>; - opp-level = <2>; - }; - - opp-1608000000 { - opp-hz = /bits/ 64 <1608000000>; - opp-level = <3>; - }; - - opp-1932000000 { - opp-hz = /bits/ 64 <1932000000>; - opp-level = <4>; - }; - - opp-2220000000 { - opp-hz = /bits/ 64 <2220000000>; - opp-level = <5>; - }; - - opp-2508000000 { - opp-hz = /bits/ 64 <2508000000>; - opp-level = <6>; - }; - - opp-2820000000 { - opp-hz = /bits/ 64 <2820000000>; - opp-level = <7>; - }; - - opp-3072000000 { - opp-hz = /bits/ 64 <3072000000>; - opp-level = <8>; - }; - - opp-3300000000 { - opp-hz = /bits/ 64 <3300000000>; - opp-level = <9>; - }; - - opp-3516000000 { - opp-hz = /bits/ 64 <3516000000>; - opp-level = <10>; - }; - - /* ADT levels 11-20, measured on J813 (level 19, 4416 MHz, is below - * level 18 and left out). The SoC throttles them when hot. */ - opp-3720000000 { - opp-hz = /bits/ 64 <3720000000>; - opp-level = <11>; - }; - - opp-3876000000 { - opp-hz = /bits/ 64 <3876000000>; - opp-level = <12>; - }; - - opp-4020000000 { - opp-hz = /bits/ 64 <4020000000>; - opp-level = <13>; - }; - - opp-4176000000 { - opp-hz = /bits/ 64 <4176000000>; - opp-level = <14>; - }; - - opp-4248000000 { - opp-hz = /bits/ 64 <4248000000>; - opp-level = <15>; - }; - - opp-4272000000 { - opp-hz = /bits/ 64 <4272000000>; - opp-level = <16>; - }; - - opp-4332000000 { - opp-hz = /bits/ 64 <4332000000>; - opp-level = <17>; - }; - - opp-4428000000 { - opp-hz = /bits/ 64 <4428000000>; - opp-level = <18>; - }; - - opp-4464000000 { - opp-hz = /bits/ 64 <4464000000>; - opp-level = <20>; - }; - }; - clkref: clock-ref { compatible = "fixed-clock"; #clock-cells = <0>; @@ -327,42 +178,6 @@ ranges; nonposted-mmio; - cpufreq_e: performance-controller@210e20000 { - compatible = "apple,t8142-cluster-cpufreq"; - reg = <0x2 0x10e20000 0 0x1000>; - #performance-domain-cells = <0>; - }; - - cpufreq_p: performance-controller@211e20000 { - compatible = "apple,t8142-cluster-cpufreq"; - reg = <0x2 0x11e20000 0 0x1000>; - #performance-domain-cells = <0>; - }; - - /* - * PMC voter interface (AppleT8142PMC, ADT pmc-pmgr 31 + 0x700000): - * floors at 0x382700000 + agent * 0x4000, per-agent states at - * +0x106000, rail enables at +0x108000. Agents (ADT voter-agent): - * PMP 0, CLPC 1, GFX 2, AP 3. iBoot leaves every enable at 0, so - * no vote is honoured and DRAM and fabric stay at their lowest - * states (CPU DRAM latency 171 ns instead of 70 ns). - */ - pmc: power-management@382700000 { - compatible = "apple,t8142-pmc"; - reg = <0x3 0x82700000 0x0 0x10000>, - <0x3 0x82806000 0x0 0x3000>; - reg-names = "voters", "rails"; - #address-cells = <1>; - #size-cells = <0>; - /* PMP, CLPC and AP agents */ - apple,static-voters = <0 1 3>; - - clpc: performance-controller@1 { - compatible = "apple,t8142-clpc"; - reg = <1>; - }; - }; - aic: interrupt-controller@381000000 { compatible = "apple,t8142-aic3", "apple,t8122-aic3"; interrupt-controller; @@ -396,15 +211,19 @@ #include "t8142-j813-display.dtsi" #include "t8142-j813-gpu.dtsi" #include "t8142-j813-peripherals.dtsi" +#include "t8142-j813-j815.dtsi" #include "t8142-j813-usb.dtsi" #include "t8142-j813-avd.dtsi" #include "t8142-j813-isp.dtsi" -#include "t8142-j813-psci-idle.dtsi" -#include "t8142-j813-nvme.dtsi" #include "t8142-j813-n1.dtsi" -#include "t8142-j813-power.dtsi" #include "t8142-j813-audio.dtsi" #include "t8142-peripherals.dtsi" +&mtp_hid { + multi-touch { + firmware-name = "apple/tpmtfw-j813.bin"; + }; +}; + /* Unexposed chassis port instances remain described and disabled. */ From 491bc1b67bd0922821cd5b855dd08bc158906da9 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Mon, 9 Nov 2026 12:03:38 -0500 Subject: [PATCH 313/342] arm64: dts: apple: t8142-j815: boot with the keyboard and trackpad The J815 tree only had the T8142 inventory: CPUs, the timer and the AIC were disabled and there was no /chosen. aura stops on the missing /chosen, and Linux could not run without a timer or an interrupt controller, so no J815 has booted from this tree. Enable the CPUs, timer, AIC, DockChannel UART, PMGR and MTP DART from the inventory. Add /chosen with the boot framebuffer and the J813 UART aliases. Include the nodes shared with J813: CPU performance states, PMC, SMC, MTP, NVMe, watchdog and PMU. The trackpad uses apple/tpmtfw-j815.bin: the J815 multi-touch hid-merge-personality is C1FD3,3, against C1FD1,4 on J813. The model name comes from the J815 ADT product description. Audio, display, USB, camera, GPU and radios stay undescribed. Their J815 wiring has not been checked, and the speaker layout differs from J813's. Not tested on J815 hardware. Signed-off-by: Diljit Singh --- .../devicetree/bindings/arm/apple.yaml | 2 +- arch/arm64/boot/dts/apple/t8142-j815.dts | 122 +++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/apple.yaml b/Documentation/devicetree/bindings/arm/apple.yaml index 691716f025522..c1ba1ac03780b 100644 --- a/Documentation/devicetree/bindings/arm/apple.yaml +++ b/Documentation/devicetree/bindings/arm/apple.yaml @@ -368,7 +368,7 @@ properties: - enum: - apple,j704 # MacBook Pro (14-inch, M5, 2025) - apple,j813 # MacBook Air (13-inch, M5, 2026) - - apple,j815 # MacBook Air (J815) + - apple,j815 # MacBook Air (15-inch, M5) - const: apple,t8142 - const: apple,arm-platform diff --git a/arch/arm64/boot/dts/apple/t8142-j815.dts b/arch/arm64/boot/dts/apple/t8142-j815.dts index 383ad27316095..d7ef154a20c6c 100644 --- a/arch/arm64/boot/dts/apple/t8142-j815.dts +++ b/arch/arm64/boot/dts/apple/t8142-j815.dts @@ -1,12 +1,132 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple MacBook Air (15-inch, M5), J815. + * + * Boots on the T8142 inventory with the resources its ADT (25G83) shares + * with J813: CPUs, timer, AIC, DockChannel UART, PMGR, CPU performance + * states, PMC, SMC, the MTP keyboard and trackpad, ANS NVMe, watchdog and + * PMU. The loader supplies usable memory, CPU release addresses and + * framebuffer geometry. Audio, display, USB, camera, GPU and radios are not + * described yet: their J815 wiring has not been checked. + */ /dts-v1/; #include "t8142.dtsi" / { - model = "Apple MacBook Air (J815)"; compatible = "apple,j815", "apple,t8142", "apple,arm-platform"; + model = "Apple MacBook Air (15-inch, M5)"; chassis-type = "laptop"; + + aliases { + serial0 = &dockchannel; + serial1 = &serial0; + }; + + chosen { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + stdout-path = "serial0:1500000n8"; + + framebuffer0: framebuffer@0 { + compatible = "apple,simple-framebuffer", "simple-framebuffer"; + reg = <0 0 0 0>; /* Filled by the loader. */ + status = "disabled"; + }; + }; +}; + +&cpu0 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu1 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu2 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu3 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu4 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu5 { + operating-points-v2 = <&ecluster_opp>; + performance-domains = <&cpufreq_e>; + status = "okay"; +}; + +&cpu6 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu7 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu8 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&cpu9 { + operating-points-v2 = <&pcluster_opp>; + performance-domains = <&cpufreq_p>; + status = "okay"; +}; + +&{/timer} { + status = "okay"; +}; + +&aic { + status = "okay"; +}; + +&dockchannel { + status = "okay"; +}; + +&pmgr { + status = "okay"; +}; + +&mtp_dart { + /* Keep host allocations clear of firmware's low IOVA mappings. */ + apple,dma-range = <0 0x02000000 0 0x10000000>; + status = "okay"; +}; + +#include "t8142-j813-j815.dtsi" + +&mtp_hid { + multi-touch { + /* ADT hid-merge-personality C1FD3,3 (J813: C1FD1,4). */ + firmware-name = "apple/tpmtfw-j815.bin"; + }; }; /* Unexposed chassis port instances remain described and disabled. */ From 11cbadb66413b29e9376bb80ddb38f43d0cc723a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 04:17:12 +1100 Subject: [PATCH 314/342] arm64: dts: apple: t600x-j314-j316: add CPU temperatures and thermal zones The M1 Pro and M1 Max MacBook Pros expose no CPU temperature, though their SMC reports one per CPU sensor site and macOS reads them. Add the SoC die maximum (TCMz) and the E cluster (Te00-Te02) and P cluster (Tp00-Tp0c) keys as hwmon channels, after the existing ones so their numbers stay. The keys were mapped on a J316s by loading each cluster in turn: Tp00-Tp0I follow the first P cluster, Tp0K-Tp0c the second and Te00-Te02 the E cluster. Each site has a reading, the same plus a fixed offset, and a hotspot estimate; TCMz is the hottest hotspot key. Make the SMC hwmon a thermal sensor provider and the CPUs cooling devices, and give each site a passive power allocator zone on its hotspot key that throttles only its own cluster: on at 75 C (85 C for the E site, which also warms with the P clusters), control at 105 C. A 180 s load on every CPU peaks at 95 C without throttling. There is no hot or critical trip; the SMC drives the fans and keeps its own protection. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../arm64/boot/dts/apple/t600x-j314-j316.dtsi | 592 ++++++++++++++++++ 1 file changed, 592 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi index 9a5f76f4fb069..50643249ddb5a 100644 --- a/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi @@ -10,6 +10,7 @@ */ #include +#include / { chassis-type = "laptop"; @@ -1028,6 +1029,597 @@ apple,no-data-below-millicelsius = <15000>; }; }; + +/* + * CPU temperatures, after the channels above so their numbers do not + * change. Each sensor site has three keys: the reading (TpX0), the same + * plus a fixed offset (TpX1: 9 C, Te01: 13.4 C), and a hotspot estimate + * (TpX2) above both. TCMz is the hottest of the hotspot keys. Under + * load on one cluster at a time, Tp00-Tp0I follow the first P cluster, + * Tp0K-Tp0c the second, and Te00-Te02 the E cluster. + */ +&smc_hwmon { + #thermal-sensor-cells = <1>; + + temperature-TCMz { + apple,key-id = "TCMz"; + label = "SoC Die Temperature"; + }; + + temperature-Te00 { + apple,key-id = "Te00"; + label = "E-cluster Te00"; + }; + + temperature-Te01 { + apple,key-id = "Te01"; + label = "E-cluster Te01"; + }; + + temperature-Te02 { + apple,key-id = "Te02"; + label = "E-cluster Te02"; + }; + + temperature-Tp00 { + apple,key-id = "Tp00"; + label = "P0-cluster Tp00"; + }; + + temperature-Tp01 { + apple,key-id = "Tp01"; + label = "P0-cluster Tp01"; + }; + + temperature-Tp02 { + apple,key-id = "Tp02"; + label = "P0-cluster Tp02"; + }; + + temperature-Tp04 { + apple,key-id = "Tp04"; + label = "P0-cluster Tp04"; + }; + + temperature-Tp05 { + apple,key-id = "Tp05"; + label = "P0-cluster Tp05"; + }; + + temperature-Tp06 { + apple,key-id = "Tp06"; + label = "P0-cluster Tp06"; + }; + + temperature-Tp08 { + apple,key-id = "Tp08"; + label = "P0-cluster Tp08"; + }; + + temperature-Tp09 { + apple,key-id = "Tp09"; + label = "P0-cluster Tp09"; + }; + + temperature-Tp0A { + apple,key-id = "Tp0A"; + label = "P0-cluster Tp0A"; + }; + + temperature-Tp0C { + apple,key-id = "Tp0C"; + label = "P0-cluster Tp0C"; + }; + + temperature-Tp0D { + apple,key-id = "Tp0D"; + label = "P0-cluster Tp0D"; + }; + + temperature-Tp0E { + apple,key-id = "Tp0E"; + label = "P0-cluster Tp0E"; + }; + + temperature-Tp0G { + apple,key-id = "Tp0G"; + label = "P0-cluster Tp0G"; + }; + + temperature-Tp0H { + apple,key-id = "Tp0H"; + label = "P0-cluster Tp0H"; + }; + + temperature-Tp0I { + apple,key-id = "Tp0I"; + label = "P0-cluster Tp0I"; + }; + + temperature-Tp0K { + apple,key-id = "Tp0K"; + label = "P1-cluster Tp0K"; + }; + + temperature-Tp0L { + apple,key-id = "Tp0L"; + label = "P1-cluster Tp0L"; + }; + + temperature-Tp0M { + apple,key-id = "Tp0M"; + label = "P1-cluster Tp0M"; + }; + + temperature-Tp0O { + apple,key-id = "Tp0O"; + label = "P1-cluster Tp0O"; + }; + + temperature-Tp0P { + apple,key-id = "Tp0P"; + label = "P1-cluster Tp0P"; + }; + + temperature-Tp0Q { + apple,key-id = "Tp0Q"; + label = "P1-cluster Tp0Q"; + }; + + temperature-Tp0S { + apple,key-id = "Tp0S"; + label = "P1-cluster Tp0S"; + }; + + temperature-Tp0T { + apple,key-id = "Tp0T"; + label = "P1-cluster Tp0T"; + }; + + temperature-Tp0U { + apple,key-id = "Tp0U"; + label = "P1-cluster Tp0U"; + }; + + temperature-Tp0W { + apple,key-id = "Tp0W"; + label = "P1-cluster Tp0W"; + }; + + temperature-Tp0X { + apple,key-id = "Tp0X"; + label = "P1-cluster Tp0X"; + }; + + temperature-Tp0Y { + apple,key-id = "Tp0Y"; + label = "P1-cluster Tp0Y"; + }; + + temperature-Tp0a { + apple,key-id = "Tp0a"; + label = "P1-cluster Tp0a"; + }; + + temperature-Tp0b { + apple,key-id = "Tp0b"; + label = "P1-cluster Tp0b"; + }; + + temperature-Tp0c { + apple,key-id = "Tp0c"; + label = "P1-cluster Tp0c"; + }; +}; + +/* The zones below throttle the clusters through cpufreq. */ +&cpu_e00 { + #cooling-cells = <2>; +}; + +&cpu_e01 { + #cooling-cells = <2>; +}; + +&cpu_p00 { + #cooling-cells = <2>; +}; + +&cpu_p01 { + #cooling-cells = <2>; +}; + +&cpu_p02 { + #cooling-cells = <2>; +}; + +&cpu_p03 { + #cooling-cells = <2>; +}; + +&cpu_p10 { + #cooling-cells = <2>; +}; + +&cpu_p11 { + #cooling-cells = <2>; +}; + +&cpu_p12 { + #cooling-cells = <2>; +}; + +&cpu_p13 { + #cooling-cells = <2>; +}; + +/ { + /* + * One zone per sensor site on its hotspot key, throttling only the + * cluster the site sits on. The power allocator starts at 75 C, above + * the 46-66 C idle readings, and controls at 105 C. The E site also + * warms with the P clusters, so its zone starts at 85 C: the governor + * grants no power to an idle cluster and would park E at its lowest + * speed. A 180 s load on every CPU, with the fans under SMC control, + * peaks at 95 C on the hottest site and 87 C on the E site without + * any throttling, so these zones are a backstop. There is no hot or + * critical trip: the SMC drives the fans and keeps its own + * protection. sustainable-power is the energy model's four cores at + * 2448 MHz per P cluster and both cores at full speed for E. + */ + thermal-zones { + cpu-e0-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <800>; + thermal-sensors = <&smc_hwmon 11>; /* Te02 */ + + trips { + cpu_e0_switch_on: trip-switch-on { + temperature = <85000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_e0_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_e0_control>; + cooling-device = + <&cpu_e00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_e01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p00-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 14>; /* Tp02 */ + + trips { + cpu_p00_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p00_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p00_control>; + cooling-device = + <&cpu_p00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p02 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p03 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p01-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 17>; /* Tp06 */ + + trips { + cpu_p01_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p01_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p01_control>; + cooling-device = + <&cpu_p00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p02 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p03 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p02-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 20>; /* Tp0A */ + + trips { + cpu_p02_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p02_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p02_control>; + cooling-device = + <&cpu_p00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p02 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p03 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p03-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 23>; /* Tp0E */ + + trips { + cpu_p03_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p03_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p03_control>; + cooling-device = + <&cpu_p00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p02 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p03 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p04-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 26>; /* Tp0I */ + + trips { + cpu_p04_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p04_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p04_control>; + cooling-device = + <&cpu_p00 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p01 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p02 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p03 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p10-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 29>; /* Tp0M */ + + trips { + cpu_p10_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p10_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p10_control>; + cooling-device = + <&cpu_p10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p13 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p11-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 32>; /* Tp0Q */ + + trips { + cpu_p11_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p11_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p11_control>; + cooling-device = + <&cpu_p10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p13 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p12-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 35>; /* Tp0U */ + + trips { + cpu_p12_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p12_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p12_control>; + cooling-device = + <&cpu_p10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p13 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p13-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 38>; /* Tp0Y */ + + trips { + cpu_p13_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p13_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p13_control>; + cooling-device = + <&cpu_p10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p13 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + + cpu-p14-thermal { + polling-delay-passive = <1000>; + polling-delay = <1000>; + sustainable-power = <11600>; + thermal-sensors = <&smc_hwmon 41>; /* Tp0c */ + + trips { + cpu_p14_switch_on: trip-switch-on { + temperature = <75000>; + hysteresis = <2000>; + type = "passive"; + }; + + cpu_p14_control: trip-control { + temperature = <105000>; + hysteresis = <2000>; + type = "passive"; + }; + }; + + cooling-maps { + map0 { + trip = <&cpu_p14_control>; + cooling-device = + <&cpu_p10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p12 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>, + <&cpu_p13 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; + }; + }; + }; + }; +}; + #include "isp-imx558.dtsi" &isp { From 3a9734ec2d4e5b914e48a8973f88a8552101c47f Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 04:28:03 +1100 Subject: [PATCH 315/342] arm64: configs: asahi: build the Apple debug and register views as modules Enable CONFIG_APPLE_DBGVIEW and CONFIG_APPLE_REGVIEW as modules. Both drivers only expose root-only, read-only debugfs files (AIC timebase, debug dock status, memory cache controller registers) and nothing loads them by default, so building them changes nothing on a running system until someone loads the module to inspect the hardware. Assisted-by: LLM --- arch/arm64/configs/asahi.config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 76919c3e257d8..126f60eee6c74 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -105,6 +105,8 @@ CONFIG_COMMON_CLK_APPLE_NCO=m CONFIG_APPLE_DART=y CONFIG_APPLE_DART_J713_DCP=y CONFIG_APPLE_DOCKCHANNEL=m +CONFIG_APPLE_DBGVIEW=m +CONFIG_APPLE_REGVIEW=m CONFIG_SERIAL_APPLE_DOCKCHANNEL=y CONFIG_SERIAL_APPLE_DOCKCHANNEL_EARLYCON=y CONFIG_APPLE_MAILBOX=y From 397dfec2c3cf3b260ea95106774e9cd324423568 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 12:42:25 -0500 Subject: [PATCH 316/342] arm64: dts: apple: t6050-j714s: Run the PMP and report the GPU to it Enable the PMP on J714s with its boot arguments and firmware properties (J714sAP ADT), its report, and the PMC's agent 0, which the PMC now honours once the PMP runs. Add the GPU's request (AGX, soc-device 16) to the T6050 report on the GPU's power state, and let the GPU take it as its domain, as T6041 does; the GPU and the report are enabled together so the GPU never waits on a disabled report. With the report the PMP drops iBoot's static vote (DCS 5, fabric 1) to 0 and acknowledges every request. Told the GPU is on, it votes DCS 5 and the fabric 1-3 while the GPU works and 0 when it idles; the PMC takes the higher of its vote and the CLPC's. Signed-off-by: Diljit Singh --- .../dts/apple/t6050-j714s-pmp-tunables.dtsi | 157 ++++++++++++++++++ arch/arm64/boot/dts/apple/t6050-j714s.dts | 59 ++++++- .../boot/dts/apple/t6050-peripherals.dtsi | 14 ++ 3 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t6050-j714s-pmp-tunables.dtsi diff --git a/arch/arm64/boot/dts/apple/t6050-j714s-pmp-tunables.dtsi b/arch/arm64/boot/dts/apple/t6050-j714s-pmp-tunables.dtsi new file mode 100644 index 0000000000000..030479030c80f --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-j714s-pmp-tunables.dtsi @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J714s PMP firmware properties: the ADT /arm-io/pmp0/iop-pmp0-nub values the + * firmware queries by name at boot (pmp.rs serves apple,tunable-). + * From the J714sAP 27.0 ADT; raw ADT bytes. + */ + +&pmp0 { + apple,tunable-afc-turbo-enable = [00 00 00 00]; + apple,tunable-afi-bw-enable = [01 00 00 00]; + apple,tunable-afi-bw-threshold = [3d 0a 57 00 00 00 00 00 00 00 00 00 03 00 00 00 cc 4c ae 00 00 00 00 00 3d 0a 56 00 03 00 00 00 00 00 ff ff 00 00 00 00 cc 4c ad 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-afi-sld-bw-threshold = [66 66 26 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 25 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-agx-af-bw-constraint = [00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00]; + apple,tunable-agx-af-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-af-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-af-bw-enable = [01 00 00 00]; + apple,tunable-agx-af-bw-threshold = [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 eb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 42 01 00 00 00 00 5c cf 07 01 00 00 00 00 00 00 ff ff 00 00 00 00 00 40 6a 01 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 c0 ad 00 00 00 00 00 00 00 00 00 06 00 00 00 00 80 42 01 00 00 00 00 f5 e8 c2 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 40 6a 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 80 70 00 00 00 00 00 00 00 00 00 06 00 00 00 00 80 42 01 00 00 00 00 00 00 7e 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 40 6a 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 5e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 d2 00 00 00 00 00 a3 30 69 00 06 00 00 00 00 00 ff ff 00 00 00 00 a3 b0 eb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 80 07 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 d2 00 00 00 00 00 47 e1 07 00 06 00 00 00 00 00 ff ff 00 00 00 00 a3 b0 eb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 d2 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 a3 b0 eb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 d2 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 a3 b0 eb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 d2 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 a3 b0 eb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 af 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 5c 4f c4 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00]; + apple,tunable-agx-af-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-af-lat-enable = [00 00 00 00]; + apple,tunable-agx-afr-bw-constraint = [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 01 00 00 00 01 00 00 00 0c 00 00 00 02 00 00 00 02 00 00 00 0c 00 00 00 03 00 00 00 03 00 00 00 0c 00 00 00 04 00 00 00 04 00 00 00 0c 00 00 00 05 00 00 00 05 00 00 00 0c 00 00 00 06 00 00 00 06 00 00 00 0c 00 00 00 07 00 00 00 07 00 00 00 0c 00 00 00 08 00 00 00 08 00 00 00 0c 00 00 00 09 00 00 00 09 00 00 00 0c 00 00 00 0a 00 00 00 0a 00 00 00 0c 00 00 00 0b 00 00 00 0b 00 00 00 0c 00 00 00 0c 00 00 00 0c 00 00 00 0c 00 00 00]; + apple,tunable-agx-afr-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-afr-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-afr-bw-enable = [01 00 00 00]; + apple,tunable-agx-afr-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ae 47 4b 00 00 00 00 00 00 00 00 00 00 00 00 00 33 f3 74 00 00 00 00 00 ae c7 4a 00 00 00 00 00 a3 70 a4 00 00 00 00 00 33 73 74 00 00 00 00 00 7a 14 dc 00 00 00 00 00 a3 f0 a3 00 00 00 00 00 14 6e 05 01 00 00 00 00 7a 94 db 00 00 00 00 00 eb 91 34 01 00 00 00 00 14 ee 04 01 00 00 00 00 e1 fa 65 01 00 00 00 00 eb 11 34 01 00 00 00 00 ae 87 9b 01 00 00 00 00 e1 7a 65 01 00 00 00 00 99 d9 d3 01 00 00 00 00 ae 07 9b 01 00 00 00 00 b8 9e 0f 02 00 00 00 00 99 59 d3 01 00 00 00 00 eb d1 4e 02 00 00 00 00 b8 1e 0f 02 00 00 00 00 8f 82 96 02 00 00 00 00 eb 51 4e 02 00 00 00 00 00 00 ff ff 00 00 00 00 8f 02 96 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 8f 82 68 00 00 00 00 00 00 00 00 00 00 00 00 00 f5 28 94 00 00 00 00 00 8f 02 68 00 00 00 00 00 33 b3 c7 00 00 00 00 00 f5 a8 93 00 00 00 00 00 a3 b0 ee 00 00 00 00 00 33 33 c7 00 00 00 00 00 ae 47 1b 01 00 00 00 00 a3 30 ee 00 00 00 00 00 e1 3a 4a 01 00 00 00 00 ae c7 1a 01 00 00 00 00 1e 45 7d 01 00 00 00 00 e1 ba 49 01 00 00 00 00 47 21 b3 01 00 00 00 00 1e c5 7c 01 00 00 00 00 a3 70 ec 01 00 00 00 00 47 a1 b2 01 00 00 00 00 a3 30 29 02 00 00 00 00 a3 f0 eb 01 00 00 00 00 28 1c 6e 02 00 00 00 00 a3 b0 28 02 00 00 00 00 00 00 ff ff 00 00 00 00 28 9c 6d 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 d7 63 8a 00 00 00 00 00 00 00 00 00 00 00 00 00 51 78 bb 00 00 00 00 00 d7 e3 89 00 00 00 00 00 cc 0c e1 00 00 00 00 00 51 f8 ba 00 00 00 00 00 99 19 0c 01 00 00 00 00 cc 8c e0 00 00 00 00 00 7a 94 39 01 00 00 00 00 99 99 0b 01 00 00 00 00 28 1c 6b 01 00 00 00 00 7a 14 39 01 00 00 00 00 00 80 9f 01 00 00 00 00 28 9c 6a 01 00 00 00 00 0a 57 d7 01 00 00 00 00 00 00 9f 01 00 00 00 00 28 9c 12 02 00 00 00 00 0a d7 d6 01 00 00 00 00 b8 de 55 02 00 00 00 00 28 1c 12 02 00 00 00 00 00 00 ff ff 00 00 00 00 b8 5e 55 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 eb 51 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 c2 f5 d7 00 00 00 00 00 eb d1 b2 00 00 00 00 00 70 fd 01 01 00 00 00 00 c2 75 d7 00 00 00 00 00 e1 7a 2e 01 00 00 00 00 70 7d 01 01 00 00 00 00 8f 02 5f 01 00 00 00 00 e1 fa 2d 01 00 00 00 00 85 6b 92 01 00 00 00 00 8f 82 5e 01 00 00 00 00 1e 45 c9 01 00 00 00 00 85 eb 91 01 00 00 00 00 5c 8f 03 02 00 00 00 00 1e c5 c8 01 00 00 00 00 c2 b5 45 02 00 00 00 00 5c 0f 03 02 00 00 00 00 00 00 ff ff 00 00 00 00 c2 35 45 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 c2 f5 d7 00 00 00 00 00 00 00 00 00 00 00 00 00 70 fd 01 01 00 00 00 00 c2 75 d7 00 00 00 00 00 e1 7a 2e 01 00 00 00 00 70 7d 01 01 00 00 00 00 8f 02 5f 01 00 00 00 00 e1 fa 2d 01 00 00 00 00 85 6b 92 01 00 00 00 00 8f 82 5e 01 00 00 00 00 1e 45 c9 01 00 00 00 00 85 eb 91 01 00 00 00 00 5c 8f 03 02 00 00 00 00 1e c5 c8 01 00 00 00 00 c2 b5 45 02 00 00 00 00 5c 0f 03 02 00 00 00 00 00 00 ff ff 00 00 00 00 c2 35 45 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 b8 de f7 00 00 00 00 00 00 00 00 00 00 00 00 00 47 61 23 01 00 00 00 00 b8 5e f7 00 00 00 00 00 66 e6 52 01 00 00 00 00 47 e1 22 01 00 00 00 00 7a 54 85 01 00 00 00 00 66 66 52 01 00 00 00 00 33 33 bb 01 00 00 00 00 7a d4 84 01 00 00 00 00 8f 82 f4 01 00 00 00 00 33 b3 ba 01 00 00 00 00 5c 8f 35 02 00 00 00 00 8f 02 f4 01 00 00 00 00 00 00 ff ff 00 00 00 00 5c 0f 35 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ae 47 18 01 00 00 00 00 00 00 00 00 00 00 00 00 cc cc 46 01 00 00 00 00 ae c7 17 01 00 00 00 00 70 3d 78 01 00 00 00 00 cc 4c 46 01 00 00 00 00 47 21 ad 01 00 00 00 00 70 bd 77 01 00 00 00 00 33 73 e5 01 00 00 00 00 47 a1 ac 01 00 00 00 00 66 66 25 02 00 00 00 00 33 f3 e4 01 00 00 00 00 00 00 ff ff 00 00 00 00 66 e6 24 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 33 b3 3a 01 00 00 00 00 00 00 00 00 00 00 00 00 f5 28 6b 01 00 00 00 00 33 33 3a 01 00 00 00 00 5c 0f 9f 01 00 00 00 00 f5 a8 6a 01 00 00 00 00 66 66 d6 01 00 00 00 00 5c 8f 9e 01 00 00 00 00 70 3d 15 02 00 00 00 00 66 e6 d5 01 00 00 00 00 00 00 ff ff 00 00 00 00 70 bd 14 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 eb 11 5e 01 00 00 00 00 00 00 00 00 00 00 00 00 70 fd 90 01 00 00 00 00 eb 91 5d 01 00 00 00 00 99 59 c7 01 00 00 00 00 70 7d 90 01 00 00 00 00 7a 14 05 02 00 00 00 00 99 d9 c6 01 00 00 00 00 00 00 ff ff 00 00 00 00 7a 94 04 02 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 85 eb 82 01 00 00 00 00 00 00 00 00 00 00 00 00 3d 4a b8 01 00 00 00 00 85 6b 82 01 00 00 00 00 85 eb f4 01 00 00 00 00 3d ca b7 01 00 00 00 00 00 00 ff ff 00 00 00 00 85 6b f4 01 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 f5 a8 92 01 00 00 00 00 00 00 00 00 00 00 00 00 1e 85 cc 01 00 00 00 00 f5 28 92 01 00 00 00 00 00 00 ff ff 00 00 00 00 1e 05 cc 01 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 47 21 a4 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 47 a1 a3 01 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00]; + apple,tunable-agx-afr-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-afr-lat-enable = [00 00 00 00]; + apple,tunable-agx-dcs-bw-constraint = [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 02 00 00 00 02 00 00 00 06 00 00 00 03 00 00 00 03 00 00 00 06 00 00 00 04 00 00 00 04 00 00 00 06 00 00 00 04 00 00 00 04 00 00 00 06 00 00 00 05 00 00 00 05 00 00 00 06 00 00 00 05 00 00 00 05 00 00 00 06 00 00 00]; + apple,tunable-agx-dcs-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-dcs-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-dcs-bw-enable = [01 00 00 00]; + apple,tunable-agx-dcs-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 80 22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 80 21 00 00 00 00 00 00 00 69 00 00 00 00 00 00 00 47 00 00 00 00 00 66 e6 a3 00 00 00 00 00 00 00 68 00 00 00 00 00 00 00 ff ff 00 00 00 00 66 e6 a2 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 16 00 06 00 00 00 00 00 69 00 00 00 00 00 00 00 47 00 06 00 00 00 66 e6 a3 00 00 00 00 00 00 00 68 00 06 00 00 00 00 00 ff ff 00 00 00 00 66 e6 a2 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 5f 00 00 00 00 00 00 00 47 00 06 00 00 00 66 e6 a3 00 00 00 00 00 00 00 5e 00 06 00 00 00 00 00 c7 00 00 00 00 00 66 e6 a2 00 06 00 00 00 00 80 e3 00 00 00 00 00 00 00 c6 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 e2 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 5f 00 00 00 00 00 00 00 47 00 06 00 00 00 66 e6 a3 00 00 00 00 00 00 00 5e 00 06 00 00 00 00 00 c7 00 00 00 00 00 66 e6 a2 00 06 00 00 00 00 80 e3 00 00 00 00 00 00 00 c6 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 e2 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 43 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 50 00 00 00 00 00 00 00 42 00 06 00 00 00 66 e6 a3 00 00 00 00 00 00 00 4f 00 06 00 00 00 00 00 c7 00 00 00 00 00 66 e6 a2 00 06 00 00 00 00 80 e3 00 00 00 00 00 00 00 c6 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 e2 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 04 00 06 00 00 00 70 7d 8c 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 c1 00 00 00 00 00 70 7d 8b 00 06 00 00 00 00 80 e3 00 00 00 00 00 00 00 c0 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 e2 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 04 00 06 00 00 00 70 7d 8c 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 c1 00 00 00 00 00 70 7d 8b 00 06 00 00 00 00 80 e3 00 00 00 00 00 00 00 c0 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 e2 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 80 34 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 47 00 00 00 00 00 00 80 33 00 06 00 00 00 00 80 5c 00 00 00 00 00 00 00 46 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 5b 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 3d 00 00 00 00 00 00 00 04 00 06 00 00 00 00 80 51 00 00 00 00 00 00 00 3c 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 80 50 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 46 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 45 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 46 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 45 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 04 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 04 00 06 00 00 00]; + apple,tunable-agx-dcs-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-dcs-lat-enable = [00 00 00 00]; + apple,tunable-agx-dvfs-state-voltages = [7d 00 00 00 5d 02 00 00 7b 02 00 00 8f 02 00 00 c1 02 00 00 cb 02 00 00 e9 02 00 00 02 03 00 00 20 03 00 00 48 03 00 00 70 03 00 00 9d 03 00 00 e8 03 00 00 10 04 00 00 7d 00 00 00 7d 00 00 00]; + apple,tunable-ane-af-bw-enable = [00 00 00 00]; + apple,tunable-ane-af-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-dcs-bw-enable = [01 00 00 00]; + apple,tunable-ane-dcs-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 1d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 46 00 00 00 00 00 00 00 13 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 45 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 46 00 00 00 00 00 00 00 13 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 45 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 1d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 1d 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 1d 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 1d 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 47 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 1d 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 13 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 13 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 13 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 13 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 13 00 06 00 00 00 00 00 48 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 55 00 00 00 00 00 00 00 47 00 06 00 00 00 00 00 60 00 00 00 00 00 00 00 54 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5f 00 06 00 00 00]; + apple,tunable-ane-lnk0-af-bw-threshold = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk0-af-bw-threshold-a = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 99 19 39 00 00 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 14 2e 21 00 00 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk1-af-bw-threshold = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk1-af-bw-threshold-a = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 99 19 39 00 00 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 14 2e 21 00 00 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ans-dcs-bw-enable = [01 00 00 00]; + apple,tunable-ans-dcs-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 99 19 00 00 05 00 00 00 5c 0f 00 00 03 00 00 00 99 19 00 00 05 00 00 00 5c 0f 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 5c 0f 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-dma-af-bw-enable = [01 00 00 00]; + apple,tunable-ans-dma-af-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-dma-af-bw-threshold-a = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-nand-af-bw-enable = [01 00 00 00]; + apple,tunable-ans-nand-af-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-nand-af-bw-threshold-a = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc0-af-bw-enable = [01 00 00 00]; + apple,tunable-atc0-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc0-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc1-af-bw-enable = [01 00 00 00]; + apple,tunable-atc1-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc1-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc2-af-bw-enable = [01 00 00 00]; + apple,tunable-atc2-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc2-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc3-af-bw-enable = [01 00 00 00]; + apple,tunable-atc3-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc3-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-auss-af-bw-enable = [01 00 00 00]; + apple,tunable-auss-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-auss-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave0-af-bw-enable = [00 00 00 00]; + apple,tunable-ave0-af-bw-threshold = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave0-af-bw-threshold-a = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave1-af-bw-enable = [00 00 00 00]; + apple,tunable-ave1-af-bw-threshold = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave1-af-bw-threshold-a = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-bwr-catch-up-factor = [00 00 01 00]; + apple,tunable-controller = [01 00 00 00 10 00 00 00 1b 00 00 00 00 00 00 00 00 00 00 00 44 49 45 2d 54 45 4d 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 46 49 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 41 46 52 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 30 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 31 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 32 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 33 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 34 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 35 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 36 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 37 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 38 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 39 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 4c 4e 4b 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 4c 4e 4b 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00 0f 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 4d 45 4d 2d 43 41 43 48 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 4e 41 4e 44 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 44 4d 41 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 32 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 33 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 55 53 53 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4a 50 45 47 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 46 49 2d 53 4c 44 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 00 00 00 20 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 4c 49 46 45 54 49 4d 45 2d 53 45 52 56 4f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]; + apple,tunable-coredump-enable = [40 00 00 00]; + apple,tunable-dcs-bw-enable = [01 00 00 00]; + apple,tunable-dcs-bw-threshold = [47 e1 27 00 01 00 00 00 00 00 00 00 00 00 00 00 ae c7 4f 00 02 00 00 00 47 e1 26 00 00 00 00 00 3d 0a 74 00 03 00 00 00 ae c7 4e 00 00 00 00 00 7a 14 ae 00 04 00 00 00 3d 0a 73 00 00 00 00 00 7a 14 cb 00 05 00 00 00 7a 14 ad 00 00 00 00 00 99 19 e8 00 06 00 00 00 7a 14 ca 00 00 00 00 00 00 00 ff ff 07 00 00 00 99 19 e7 00 00 00 00 00]; + apple,tunable-disable-vlpm-feature = [01 00 00 00]; + apple,tunable-dvfs-domain = [01 00 00 00 07 00 00 00 00 00 00 00 44 43 53 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 0d 00 00 00 21 00 00 00 41 46 52 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 00 00 00 00 53 4f 43 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 49 4e 54 00 00 00 00 00 00 00 00 05 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 45 58 54 00 00 00 00 00 00 00 00]; + apple,tunable-dvfs-domain-afc-bin = [01 00 00 00 07 00 00 00 00 00 00 00 44 43 53 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 0d 00 00 00 21 00 00 00 41 46 52 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 05 00 00 00 00 00 00 00 53 4f 43 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 49 4e 54 00 00 00 00 00 00 00 00 05 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 45 58 54 00 00 00 00 00 00 00 00]; + apple,tunable-fast-die-ctrl-ce-map = [01 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 5f 41 4e 45 00 00 00 00 00 00 00 00]; + apple,tunable-fast-die-ctrl-ts = [00 00 05 00]; + apple,tunable-fast-die-ctrl-ts-avg-temp = [00 00 64 00]; + apple,tunable-firmware-name = [74 36 30 35 30 70 6d 70 00]; + apple,tunable-jpeg-af-bw-enable = [00 00 00 00]; + apple,tunable-jpeg-af-bw-threshold = [99 99 03 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 99 99 02 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-jpeg-af-bw-threshold-a = [99 99 03 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 99 99 02 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-lts-acsk-tddb-config = [01 00 00 00 69 00 00 00 10 14 24 00 00 00 00 00 95 c2 0f 00 1a 04 00 00 56 04 00 00 00 00 00 00]; + apple,tunable-lts-clpc-voltage = [01 00 00 00 d2 03 00 00 00 00 66 00 33 33 66 00 00 00 00 00 50 41 43 43 00 00 00 00]; + apple,tunable-lts-config = [03 00 00 00 69 00 00 00 c3 1c 15 00 00 00 00 00 0f dc 0f 00 6e 00 00 00 68 00 00 00 00 00 11 00 33 b3 00 00 2f bd 48 01 03 00 00 00 69 00 00 00 c3 1c 15 00 00 00 00 00 0f dc 0f 00 6e 00 00 00 68 00 00 00 00 00 11 00 33 b3 00 00 2f bd 48 01 01 00 00 00 69 00 00 00 bf d9 01 00 00 00 00 00 da fc 0f 00 6e 00 00 00 66 00 00 00 00 00 11 00 33 b3 00 00 f9 fe c3 00 02 00 00 00 3b 01 00 00 cd f1 09 00 00 00 00 00 12 ef 0f 00 6e 00 00 00 69 00 00 00 00 00 11 00 33 b3 00 00 2b 87 4f 00]; + apple,tunable-lts-ctrl-loop = [01 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 50 55 00 00 00 00 00 00 00 00 00 00 00 00 00]; + apple,tunable-lts-ctrl-ts = [00 00 05 00]; + apple,tunable-lts-voltage = [01 00 00 00 03 00 00 00 0d 00 00 00 09 00 00 00 4d 41 43 43 30 00 00 00 02 00 00 00 03 00 00 00 0e 00 00 00 0a 00 00 00 4d 41 43 43 31 00 00 00 03 00 00 00 03 00 00 00 0f 00 00 00 02 00 00 00 50 41 43 43 00 00 00 00 04 00 00 00 01 00 00 00 11 00 00 00 00 00 00 00 41 4e 45 00 00 00 00 00 05 00 00 00 03 00 00 00 10 00 00 00 04 00 00 00 41 47 58 00 00 00 00 00]; + apple,tunable-mc_cmd_ack_ptd_count = [01 00 00 00]; + apple,tunable-mc_cmd_ptd_count = [02 00 00 00]; + apple,tunable-mc_quota_req_ptd_count = [08 00 00 00]; + apple,tunable-mc_quota_rsp_ptd_count = [08 00 00 00]; + apple,tunable-mcache-stream = [1e 00 00 00 03 00 00 00 01 00 00 00 02 00 00 00 02 00 00 00 0c 00 00 00 0c 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2b 00 00 00 03 00 00 00 01 00 00 00 02 00 00 00 02 00 00 00 0e 00 00 00 0e 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 05 00 00 00 01 00 00 00 01 00 00 00 07 00 00 00 07 00 00 00 20 00 00 00 20 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 06 00 00 00 02 00 00 00 01 00 00 00 08 00 00 00 08 00 00 00 24 00 00 00 24 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 0b 00 00 00 05 00 00 00 01 00 00 00 0b 00 00 00 0b 00 00 00 30 00 00 00 30 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 0e 00 00 00 04 00 00 00 01 00 00 00 0d 00 00 00 0d 00 00 00 38 00 00 00 38 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 11 00 00 00 04 00 00 00 01 00 00 00 0e 00 00 00 0e 00 00 00 3c 00 00 00 3c 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1b 00 00 00 04 00 00 00 01 00 00 00 0e 00 00 00 0e 00 00 00 3d 00 00 00 3d 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 13 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 40 00 00 00 40 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 24 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 41 00 00 00 41 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1c 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 42 00 00 00 42 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 04 00 00 00 01 00 00 00 10 00 00 00 10 00 00 00 44 00 00 00 44 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 01 00 00 00 11 00 00 00 11 00 00 00 48 00 00 00 48 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 13 00 00 00 13 00 00 00 50 00 00 00 50 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 15 00 00 00 15 00 00 00 58 00 00 00 5a 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 10 00 00 00 04 00 00 00 01 00 00 00 1f 00 00 00 1f 00 00 00 80 00 00 00 bf 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 20 00 00 00 03 00 00 00 02 00 00 00 03 00 00 00 06 00 00 00 10 00 00 00 1f 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 1f 00 00 00 03 00 00 00 02 00 00 00 1e 00 00 00 1e 00 00 00 7c 00 00 00 7c 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 12 00 00 00 05 00 00 00 02 00 00 00 09 00 00 00 09 00 00 00 28 00 00 00 28 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0a 00 00 00 05 00 00 00 02 00 00 00 0c 00 00 00 0c 00 00 00 34 00 00 00 34 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 15 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5d 00 00 00 5d 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 36 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5e 00 00 00 5e 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 37 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5f 00 00 00 5f 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0d 00 00 00 0b 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 0c 00 00 00 0b 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 09 00 00 00 09 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 19 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1a 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 29 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 06 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2a 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 07 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2c 00 00 00 03 00 00 00 03 00 00 00 18 00 00 00 18 00 00 00 64 00 00 00 64 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 2d 00 00 00 0c 00 00 00 03 00 00 00 18 00 00 00 18 00 00 00 65 00 00 00 65 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 2f 00 00 00 02 00 00 00 03 00 00 00 1a 00 00 00 1a 00 00 00 6c 00 00 00 6c 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 26 00 00 00 05 00 00 00 03 00 00 00 1c 00 00 00 1c 00 00 00 74 00 00 00 74 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 14 00 00 00 04 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 0a 00 00 00 0a 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 27 00 00 00 04 00 00 00 03 00 00 00 1d 00 00 00 1d 00 00 00 78 00 00 00 78 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 23 00 00 00 00 00 00 00 03 00 00 00 14 00 00 00 14 00 00 00 54 00 00 00 54 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00 00 00 00 00 03 00 00 00 1b 00 00 00 1b 00 00 00 70 00 00 00 70 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 30 00 00 00 0e 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 61 00 00 00 61 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 31 00 00 00 0f 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 60 00 00 00 60 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 35 00 00 00 09 00 00 00 03 00 00 00 19 00 00 00 19 00 00 00 68 00 00 00 68 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 1d 00 00 00 09 00 00 00 03 00 00 00 19 00 00 00 19 00 00 00 69 00 00 00 6b 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 33 00 00 00 11 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 62 00 00 00 62 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 34 00 00 00 12 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 63 00 00 00 63 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 16 00 00 00 0b 00 00 00 03 00 00 00 ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00]; + apple,tunable-no-shutdown = [01 00 00 00]; + apple,tunable-pm-ptd-ranges = [01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 28 00 00 00 09 00 00 00 0a 00 00 00 0b 00 00 00 0c 00 00 00 0d 00 00 00 0e 00 00 00]; + apple,tunable-pre-loaded = [01 00 00 00]; + apple,tunable-ptd-driver-version = [01 00 00 00]; + apple,tunable-ptd-range = [01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 4e 55 4c 4c 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00 50 4d 50 2d 53 54 41 54 55 53 00 00 00 00 00 00 03 00 00 00 08 00 00 00 04 00 00 00 00 00 00 00 44 56 46 53 2d 53 54 41 54 45 00 00 00 00 00 00 04 00 00 00 0c 00 00 00 04 00 00 00 00 00 00 00 50 4d 50 54 4f 4f 4c 00 00 00 00 00 00 00 00 00 05 00 00 00 10 00 00 00 08 00 00 00 00 00 00 00 50 4d 53 2d 50 4d 47 52 2d 50 4b 54 00 00 00 00 06 00 00 00 18 00 00 00 20 00 00 00 00 00 00 00 50 4d 53 2d 44 50 45 2d 50 4b 54 00 00 00 00 00 07 00 00 00 38 00 00 00 48 00 00 00 00 00 00 00 50 4d 53 2d 44 45 56 43 2d 50 4b 54 00 00 00 00 08 00 00 00 80 00 00 00 10 00 00 00 00 00 00 00 50 4d 53 2d 50 57 52 53 2d 50 4b 54 00 00 00 00 09 00 00 00 90 00 00 00 50 01 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 4b 54 00 00 00 00 00 0a 00 00 00 e0 01 00 00 08 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 53 2d 52 45 51 00 00 0b 00 00 00 e8 01 00 00 08 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 53 2d 41 43 4b 00 00 0c 00 00 00 f0 01 00 00 30 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 44 56 46 53 00 00 00 00 0d 00 00 00 20 02 00 00 1a 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 42 57 52 00 00 00 00 00 0e 00 00 00 3a 02 00 00 02 00 00 00 00 00 00 00 44 56 46 53 2d 44 49 45 2d 54 4f 2d 44 49 45 00 0f 00 00 00 3c 02 00 00 0a 00 00 00 00 00 00 00 4d 43 2d 44 52 56 2d 54 4f 2d 43 54 52 4c 00 00 10 00 00 00 58 02 00 00 02 00 00 00 0c 00 00 00 46 41 53 54 2d 44 49 45 2d 43 45 00 00 00 00 00 11 00 00 00 5a 02 00 00 07 00 00 00 0d 00 00 00 53 4d 43 2d 54 4f 2d 50 50 4d 00 00 00 00 00 00 12 00 00 00 61 02 00 00 09 00 00 00 00 00 00 00 4d 43 2d 43 54 52 4c 2d 54 4f 2d 44 52 56 00 00 13 00 00 00 6a 02 00 00 01 00 00 00 0a 00 00 00 4c 54 53 2d 56 4f 4c 54 2d 43 41 50 00 00 00 00 18 00 00 00 70 02 00 00 05 00 00 00 0e 00 00 00 50 50 4d 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 19 00 00 00 75 02 00 00 05 00 00 00 0f 00 00 00 43 4c 50 43 2d 54 4f 2d 53 4d 43 00 00 00 00 00 1a 00 00 00 7a 02 00 00 20 00 00 00 00 00 00 00 47 46 58 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 1b 00 00 00 9a 02 00 00 09 00 00 00 00 00 00 00 46 41 53 54 2d 44 49 45 2d 54 4f 2d 53 4d 43 00 1c 00 00 00 a3 02 00 00 01 00 00 00 00 00 00 00 4d 43 2d 43 54 52 4c 2d 54 4f 2d 53 4d 43 00 00 1d 00 00 00 a4 02 00 00 08 00 00 00 00 00 00 00 41 4e 45 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 20 00 00 00 b4 02 00 00 01 00 00 00 00 00 00 00 4c 54 53 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 21 00 00 00 b5 02 00 00 01 00 00 00 0b 00 00 00 50 4d 50 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 22 00 00 00 b6 02 00 00 08 00 00 00 00 00 00 00 50 4d 55 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 28 00 00 00 20 03 00 00 14 00 00 00 00 00 00 00 50 4d 53 2d 56 49 52 54 2d 43 4e 54 52 00 00 00]; + apple,tunable-region-base = [00 00 50 84 02 00 00 00]; + apple,tunable-region-size = [00 00 10 00 00 00 00 00]; + apple,tunable-segment-names = [5f 5f 54 45 58 54 3b 5f 5f 44 41 54 41 3b 5f 5f 45 54 45 58 54 00]; + apple,tunable-segment-ranges = [00 00 50 84 02 00 00 00 00 00 00 01 00 00 00 00 00 00 50 84 02 00 00 00 00 80 05 00 03 00 00 00 00 80 55 84 02 00 00 00 00 80 05 01 00 00 00 00 00 80 55 84 02 00 00 00 00 b0 09 00 06 00 00 00 00 80 d0 01 00 01 00 00 00 00 10 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 01 00 00 00]; + apple,tunable-soc-chip-variant = [00 00 00 00]; + apple,tunable-soc-device = [01 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 43 53 00 00 00 00 00 02 00 00 00 45 4e 4f 4e 01 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4d 43 43 00 00 00 00 03 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 30 00 04 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 31 00 05 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 32 00 06 00 00 00 45 4e 4f 4e 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 33 00 07 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 34 00 08 00 00 00 45 4e 4f 4e 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 35 00 09 00 00 00 45 4e 4f 4e 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 36 00 0a 00 00 00 45 4e 4f 4e 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 37 00 0b 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 38 00 0c 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 39 00 0d 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 0e 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 0f 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 00 00 00 00 10 00 00 00 5f 58 46 47 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 00 00 00 00 00 11 00 00 00 45 4e 4f 4e 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 00 00 00 00 00 12 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49 53 50 00 00 00 00 00 13 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 49 4e 54 00 14 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 30 15 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 31 16 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 32 17 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 33 18 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 30 00 00 00 00 19 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 31 00 00 00 00 1a 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 44 00 00 00 00 00 1b 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 53 52 30 00 00 00 00 1c 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 53 52 31 00 00 00 00 1d 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4a 50 45 47 00 00 00 00 1e 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 43 4f 44 45 43 00 00 1f 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 52 4f 52 45 53 00 00 20 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 30 00 00 00 00 21 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 31 00 00 00 00 22 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 32 00 00 00 00 23 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 33 00 00 00 00 24 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 55 53 53 00 00 00 00 25 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 00 00 00 00 00]; + apple,tunable-soc-device-ps-group = [00 f0 ff ff ff 01 00 00]; + apple,tunable-soc-ni0-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni0-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni0-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni0-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni1-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni1-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni1-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni1-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni2-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni2-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni2-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni2-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni3-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni3-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni3-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni3-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni4-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni4-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni4-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni4-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni5-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni5-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni5-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni5-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni6-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni6-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni6-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni6-push-thr = [24 00 00 00]; + apple,tunable-soc-ni7-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni7-bw-threshold = [00 00 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 00 00 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni7-bw-threshold-a = [00 00 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 00 00 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni7-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni8-bw-enable = [00 00 00 00]; + apple,tunable-soc-ni8-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni8-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni8-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni9-bw-enable = [00 00 00 00]; + apple,tunable-soc-ni9-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni9-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni9-push-thr = [f5 06 00 00]; + apple,tunable-sochot-sensors = [01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0a 00 00 00 0b 00 00 00 0c 00 00 00 0d 00 00 00 0e 00 00 00 0f 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 13 00 00 00 14 00 00 00 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 19 00 00 00 1a 00 00 00 1b 00 00 00 1c 00 00 00 1d 00 00 00 1e 00 00 00 1f 00 00 00 20 00 00 00 21 00 00 00 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 26 00 00 00 27 00 00 00 28 00 00 00 29 00 00 00 2a 00 00 00 2b 00 00 00 2c 00 00 00 2d 00 00 00 2e 00 00 00 2f 00 00 00 30 00 00 00 31 00 00 00 32 00 00 00 33 00 00 00 34 00 00 00 35 00 00 00 36 00 00 00 37 00 00 00 38 00 00 00 39 00 00 00 3a 00 00 00 3b 00 00 00 3c 00 00 00 3d 00 00 00 3e 00 00 00 3f 00 00 00 40 00 00 00 41 00 00 00 42 00 00 00 43 00 00 00 44 00 00 00 45 00 00 00]; + apple,tunable-sram-index = [01 00 00 00]; + apple,tunable-temp-sensor = [01 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 30 69 00 00 00 00 00 00 00 00 00 00 02 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 31 69 00 00 00 00 00 00 00 00 00 00 03 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 32 69 00 00 00 00 00 00 00 00 00 00 04 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 35 69 00 00 00 00 00 00 00 00 00 00 05 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 36 69 00 00 00 00 00 00 00 00 00 00 06 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 37 69 00 00 00 00 00 00 00 00 00 00 07 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 63 69 00 00 00 00 00 00 00 00 00 00 08 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 64 69 00 00 00 00 00 00 00 00 00 00 09 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 30 69 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 31 69 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 66 69 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 67 69 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 33 69 00 00 00 00 00 00 00 00 00 00 0e 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 34 69 00 00 00 00 00 00 00 00 00 00 0f 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 65 69 00 00 00 00 00 00 00 00 00 00 10 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 32 69 00 00 00 00 00 00 00 00 00 00 11 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 68 69 00 00 00 00 00 00 00 00 00 00 12 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 35 69 00 00 00 00 00 00 00 00 00 00 13 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 80 01 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6c 69 00 00 00 00 00 00 00 00 00 00 14 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 00 80 01 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6d 69 00 00 00 00 00 00 00 00 00 00 15 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 06 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6f 69 00 00 00 00 00 00 00 00 00 00 16 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 70 69 00 00 00 00 00 00 00 00 00 00 17 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 0a 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 73 69 00 00 00 00 00 00 00 00 00 00 18 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 39 69 00 00 00 00 00 00 00 00 00 00 19 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 61 69 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 36 69 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 37 69 00 00 00 00 00 00 00 00 00 00 1c 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 62 69 00 00 00 00 00 00 00 00 00 00 1d 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 38 69 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 33 69 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 34 69 00 00 00 00 00 00 00 00 00 00 20 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 30 69 00 00 00 00 00 00 00 00 00 00 21 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 31 69 00 00 00 00 00 00 00 00 00 00 22 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 36 69 00 00 00 00 00 00 00 00 00 00 23 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 37 69 00 00 00 00 00 00 00 00 00 00 24 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 35 69 00 00 00 00 00 00 00 00 00 00 25 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 32 69 00 00 00 00 00 00 00 00 00 00 26 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 38 69 00 00 00 00 00 00 00 00 00 00 27 00 00 00 08 00 00 00 0d 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 6c 69 00 00 00 00 00 00 00 00 00 00 28 00 00 00 08 00 00 00 0d 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 6d 69 00 00 00 00 00 00 00 00 00 00 29 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 39 69 00 00 00 00 00 00 00 00 00 00 2a 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 61 69 00 00 00 00 00 00 00 00 00 00 2b 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 63 69 00 00 00 00 00 00 00 00 00 00 2c 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 64 69 00 00 00 00 00 00 00 00 00 00 2d 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 66 69 00 00 00 00 00 00 00 00 00 00 2e 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 67 69 00 00 00 00 00 00 00 00 00 00 2f 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 62 69 00 00 00 00 00 00 00 00 00 00 30 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 65 69 00 00 00 00 00 00 00 00 00 00 31 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 68 69 00 00 00 00 00 00 00 00 00 00 32 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 33 69 00 00 00 00 00 00 00 00 00 00 33 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 34 69 00 00 00 00 00 00 00 00 00 00 34 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 30 69 00 00 00 00 00 00 00 00 00 00 35 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 31 69 00 00 00 00 00 00 00 00 00 00 36 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 36 69 00 00 00 00 00 00 00 00 00 00 37 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 37 69 00 00 00 00 00 00 00 00 00 00 38 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 35 69 00 00 00 00 00 00 00 00 00 00 39 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 32 69 00 00 00 00 00 00 00 00 00 00 3a 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 38 69 00 00 00 00 00 00 00 00 00 00 3b 00 00 00 08 00 00 00 0e 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 6c 69 00 00 00 00 00 00 00 00 00 00 3c 00 00 00 08 00 00 00 0e 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 6d 69 00 00 00 00 00 00 00 00 00 00 3d 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 39 69 00 00 00 00 00 00 00 00 00 00 3e 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 61 69 00 00 00 00 00 00 00 00 00 00 3f 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 63 69 00 00 00 00 00 00 00 00 00 00 40 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 64 69 00 00 00 00 00 00 00 00 00 00 41 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 66 69 00 00 00 00 00 00 00 00 00 00 42 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 67 69 00 00 00 00 00 00 00 00 00 00 43 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 62 69 00 00 00 00 00 00 00 00 00 00 44 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 65 69 00 00 00 00 00 00 00 00 00 00 45 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 68 69 00 00 00 00 00 00 00 00 00 00 46 00 00 00 01 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6d 00 00 00 6d 00 00 00 4d 54 52 5f 54 4f 50 5f 41 47 58 00 00 00 00 00]; + apple,tunable-user-power-managed = [01 00 00 00]; + apple,tunable-uuid = [45 39 31 38 44 44 31 39 2d 37 41 42 46 2d 33 46 41 39 2d 41 38 45 45 2d 45 33 35 42 36 37 39 46 30 44 46 45 00]; + apple,tunable-vlpm-threshold = [55 01 00 00]; + apple,tunable-vlpm-timer-limit = [64 00 00 00]; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-j714s.dts b/arch/arm64/boot/dts/apple/t6050-j714s.dts index b95609c723f32..6fc1b66157762 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714s.dts @@ -4,9 +4,9 @@ * * target-type: J714s * - * One T6050 die (t6050-max.dtsi). Nobody has booted Linux on this board - * yet: beyond the SoC this file only adds the board's hardware inventory - * (t6050-peripherals.dtsi), all of it disabled, from the board's ADT. + * One T6050 die (t6050-max.dtsi). Beyond the SoC this file adds the board's + * hardware inventory (t6050-peripherals.dtsi) from the board's ADT, disabled + * except for the PMP below. * * Copyright The Asahi Linux Contributors */ @@ -47,5 +47,58 @@ #define T6050_J714S #include "t6050-peripherals.dtsi" +/* + * The PMP (ADT pmp0, /chosen, /arm-io/pmgr). iBoot loads its firmware and the driver starts it + * with these boot arguments and the firmware properties below. Its report tells it which devices + * are on; it then votes DCS and the fabric for GPU load itself, and the PMC honours that next + * to the CLPC. The report, the PMP's vote and the GPU's request are enabled together, so the + * GPU never waits on a disabled report. + */ +&ps_pms { + status = "okay"; +}; + +&ps_pmp { + status = "okay"; +}; + +&ps_pms_sram { + status = "okay"; +}; + +&pmp0_dart { + status = "okay"; +}; + +&pmp0_mbox { + status = "okay"; +}; + +&pmp0 { + /* ADT /chosen board-id, dram-vendor-id */ + apple,board-id = <8>; + apple,dram-vendor-id = <255>; + /* ADT /arm-io/pmgr pmc, pmc-pmgr */ + apple,pmc = <1>; + apple,pmc-pmgr = <63>; + status = "okay"; +}; + +&pmp0_report { + status = "okay"; +}; + +&pmc { + /* PMP, CLPC and AP agents, once the PMP runs */ + apple,static-voters = <0 1 3>; + apple,pmp = <&pmp0>; +}; + +&sgx { + power-domains = <&pmp0_gfx>; +}; + +#include "t6050-j714s-pmp-tunables.dtsi" + /* The same T6050 camera as J716c (J714sAP ADT); the loader sets the J714s sensor type. */ #include "t6050-j716c-isp.dtsi" diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index 2c82b0024ebe4..d3524080347f6 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2249,6 +2249,20 @@ apple,always-on; }; + /* + * The GPU (AGX), on the GPU's own power state, so the PMP is told the GPU is on only + * while it is powered (a request with the GPU off crashes the T6041 PMP). The GPU takes + * this domain on a board that enables the report. + */ + pmp0_gfx: report@f { + compatible = "apple,t6050-pmp-v2-report-entry", + "apple,t6000-pmp-v2-report-entry"; + reg = <0xf>; + label = "pmp-gfx"; + #power-domain-cells = <0>; + power-domains = <&ps_gfx>; + }; + /* The internal display (DISPINT) */ report@12 { compatible = "apple,t6050-pmp-v2-report-entry", From 7f6562857f7070531954058d0af9043595823576 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 04:51:10 +1100 Subject: [PATCH 317/342] arm64: dts: apple: t8112-j413: add the remaining CPU temperatures The J413 describes five of its CPU temperature keys (TCMz, Te05 and the offset keys of four P sensor sites), but its SMC reports 31, and the hottest site, Tp0o, is not among them. Add the other 26 as read-only hwmon channels after the GPU ones, so no existing channel or thermal zone index moves: TCMb, Te04 and Te06 for the E cluster and every Tp key for the P cluster. They were mapped by loading each cluster in turn: Te04-Te06 rise 8 C with the E cluster, the Tp keys 15-22 C with the P cluster. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t8112-j413.dts | 140 +++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8112-j413.dts b/arch/arm64/boot/dts/apple/t8112-j413.dts index f9b4883ec2c96..28d8d8e75bb3c 100644 --- a/arch/arm64/boot/dts/apple/t8112-j413.dts +++ b/arch/arm64/boot/dts/apple/t8112-j413.dts @@ -321,6 +321,146 @@ apple,no-data-below-millicelsius = <10000>; }; }; + +/* + * The other CPU temperatures, read-only, after the GPU channels. Each + * sensor site has a reading, the same plus a fixed offset and a hotspot + * estimate; the zones above use the offset keys of four P sites and Te05. + * Te04-Te06 follow the E cluster, every Tp key the P cluster, TCMz is the + * hottest hotspot key and TCMb the hottest offset key. + */ +&smc_hwmon { + temperature-TCMb { + apple,key-id = "TCMb"; + label = "SoC Die TCMb"; + }; + + temperature-Te04 { + apple,key-id = "Te04"; + label = "E-cluster Te04"; + }; + + temperature-Te06 { + apple,key-id = "Te06"; + label = "E-cluster Te06"; + }; + + temperature-Tp00 { + apple,key-id = "Tp00"; + label = "P-cluster Tp00"; + }; + + temperature-Tp02 { + apple,key-id = "Tp02"; + label = "P-cluster Tp02"; + }; + + temperature-Tp04 { + apple,key-id = "Tp04"; + label = "P-cluster Tp04"; + }; + + temperature-Tp06 { + apple,key-id = "Tp06"; + label = "P-cluster Tp06"; + }; + + temperature-Tp08 { + apple,key-id = "Tp08"; + label = "P-cluster Tp08"; + }; + + temperature-Tp0A { + apple,key-id = "Tp0A"; + label = "P-cluster Tp0A"; + }; + + temperature-Tp0C { + apple,key-id = "Tp0C"; + label = "P-cluster Tp0C"; + }; + + temperature-Tp0E { + apple,key-id = "Tp0E"; + label = "P-cluster Tp0E"; + }; + + temperature-Tp0a { + apple,key-id = "Tp0a"; + label = "P-cluster Tp0a"; + }; + + temperature-Tp0b { + apple,key-id = "Tp0b"; + label = "P-cluster Tp0b"; + }; + + temperature-Tp0c { + apple,key-id = "Tp0c"; + label = "P-cluster Tp0c"; + }; + + temperature-Tp0e { + apple,key-id = "Tp0e"; + label = "P-cluster Tp0e"; + }; + + temperature-Tp0f { + apple,key-id = "Tp0f"; + label = "P-cluster Tp0f"; + }; + + temperature-Tp0g { + apple,key-id = "Tp0g"; + label = "P-cluster Tp0g"; + }; + + temperature-Tp0i { + apple,key-id = "Tp0i"; + label = "P-cluster Tp0i"; + }; + + temperature-Tp0j { + apple,key-id = "Tp0j"; + label = "P-cluster Tp0j"; + }; + + temperature-Tp0k { + apple,key-id = "Tp0k"; + label = "P-cluster Tp0k"; + }; + + temperature-Tp0m { + apple,key-id = "Tp0m"; + label = "P-cluster Tp0m"; + }; + + temperature-Tp0n { + apple,key-id = "Tp0n"; + label = "P-cluster Tp0n"; + }; + + temperature-Tp0o { + apple,key-id = "Tp0o"; + label = "P-cluster Tp0o"; + }; + + temperature-Tp0q { + apple,key-id = "Tp0q"; + label = "P-cluster Tp0q"; + }; + + temperature-Tp0r { + apple,key-id = "Tp0r"; + label = "P-cluster Tp0r"; + }; + + temperature-Tp0s { + apple,key-id = "Tp0s"; + label = "P-cluster Tp0s"; + }; +}; + /* * Mesa fingerprint sensor on spi2. The J413 platform device tree * (/arm-io/spi2/mesa) describes it as J415's does: power on AP GPIO 178, From ca707626b31e353b3f9bb5ceb39cd1f511512fe3 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 12:16:36 -0500 Subject: [PATCH 318/342] Remove the APIF platform drivers APIF is old SPTM support that doesn't need to be in tree. Drop the APIF MMIO transport, its DART and SART providers, the APIF mailbox profile, its config fragment and selftests, and the headers only APIF consumers used. SART goes back to its MMIO path. Signed-off-by: Diljit Singh --- arch/arm64/configs/aurora-apif.config | 6 - drivers/firmware/Kconfig | 10 - drivers/firmware/Makefile | 2 - drivers/firmware/aurora-apif-mmio.c | 255 -- drivers/iommu/Kconfig | 12 - drivers/iommu/Makefile | 2 - drivers/iommu/apple-dart-apif.c | 2077 ----------------- drivers/soc/apple/Kconfig | 10 - drivers/soc/apple/Makefile | 2 - drivers/soc/apple/apple-sart-apif.c | 167 -- drivers/soc/apple/mailbox.c | 27 - drivers/soc/apple/sart-backend.h | 21 - drivers/soc/apple/sart.c | 32 - include/linux/apple-dart-apif.h | 18 - include/linux/pci-apple-apif.h | 16 - .../linux/soc/apple/display-event-debugfs.h | 85 - include/linux/soc/apple/display-event-log.h | 213 -- include/linux/soc/aurora/apif-mmio.h | 66 - tools/testing/selftests/Makefile | 1 - tools/testing/selftests/aurora-apif/Makefile | 5 - .../selftests/aurora-apif/apif_mmio.py | 409 ---- tools/testing/selftests/aurora-apif/common.py | 19 - .../selftests/aurora-apif/dart_retained.py | 53 - 23 files changed, 3508 deletions(-) delete mode 100644 arch/arm64/configs/aurora-apif.config delete mode 100644 drivers/firmware/aurora-apif-mmio.c delete mode 100644 drivers/iommu/apple-dart-apif.c delete mode 100644 drivers/soc/apple/apple-sart-apif.c delete mode 100644 drivers/soc/apple/sart-backend.h delete mode 100644 include/linux/apple-dart-apif.h delete mode 100644 include/linux/pci-apple-apif.h delete mode 100644 include/linux/soc/apple/display-event-debugfs.h delete mode 100644 include/linux/soc/apple/display-event-log.h delete mode 100644 include/linux/soc/aurora/apif-mmio.h delete mode 100644 tools/testing/selftests/aurora-apif/Makefile delete mode 100755 tools/testing/selftests/aurora-apif/apif_mmio.py delete mode 100644 tools/testing/selftests/aurora-apif/common.py delete mode 100755 tools/testing/selftests/aurora-apif/dart_retained.py diff --git a/arch/arm64/configs/aurora-apif.config b/arch/arm64/configs/aurora-apif.config deleted file mode 100644 index dbc1e64573992..0000000000000 --- a/arch/arm64/configs/aurora-apif.config +++ /dev/null @@ -1,6 +0,0 @@ -# Common T6050 APIF providers. Add the platform-wiring PR for all consumers. -CONFIG_ARM64_16K_PAGES=y -CONFIG_AURORA_APIF_MMIO=y -CONFIG_APPLE_DART_APIF=y -CONFIG_APPLE_SART=y -CONFIG_APPLE_SART_APIF=y diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index c4f9285d3f362..b7cc11e4fbfa6 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -6,16 +6,6 @@ menu "Firmware Drivers" -config AURORA_APIF_MMIO - tristate "Aurora platform MMIO interface" - depends on ARM64 && OF - help - Submit synchronous, batched platform operations to an Aura monitor. - The interface forwards native SPTM selectors, arguments and results - without interpreting peripheral policy. Clients own their buffers. - Submission is synchronous and supports atomic-context consumers. - - source "drivers/firmware/arm_scmi/Kconfig" config ARM_SCPI_PROTOCOL diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 8d5c56e4cfbf2..be46f1e1dc77f 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -39,5 +39,3 @@ obj-y += samsung/ obj-y += smccc/ obj-y += tegra/ obj-y += xilinx/ - -obj-$(CONFIG_AURORA_APIF_MMIO) += aurora-apif-mmio.o diff --git a/drivers/firmware/aurora-apif-mmio.c b/drivers/firmware/aurora-apif-mmio.c deleted file mode 100644 index aa6ec65c6248c..0000000000000 --- a/drivers/firmware/aurora-apif-mmio.c +++ /dev/null @@ -1,255 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Aurora Platform Interface over Memory-Mapped I/O. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define APIF_MAGIC 0x4f494d4d46495041ULL -#define APIF_VERSION 2 -#define APIF_REG_MAGIC 0x000 -#define APIF_REG_VERSION 0x008 -#define APIF_REG_MAX_OPS 0x010 -#define APIF_REG_FEATURES 0x018 -#define APIF_REG_DOORBELL 0x100 -#define APIF_FEAT_NATIVE BIT_ULL(0) -#define APIF_BATCH_BYTES SZ_16K - -struct apif_batch { - u32 count, flags; - s32 status; - u32 done; - struct aurora_apif_op ops[]; -}; - -#define APIF_BATCH_MAX \ - ((APIF_BATCH_BYTES - sizeof(struct apif_batch)) / \ - sizeof(struct aurora_apif_op)) - -struct apif_provider { - void __iomem *regs; - u32 max_ops; -}; - -struct aurora_apif { - struct kref refs; - raw_spinlock_t lock; - bool live; - void __iomem *doorbell; - struct apif_batch *batch; - u32 max_ops; -}; - -static struct platform_driver apif_driver; -static_assert(sizeof(struct apif_batch) == 16); -static_assert(sizeof(struct aurora_apif_op) == 64); -static_assert(sizeof(struct aurora_apif_boot_iommu) == 64); - -/* SPTM redispatch restores SP_EL1 from its exception-stack contract. Keep the - * Linux stack in a preserved GPR across the trapping store. The monitor must - * preserve all GPRs, including x9, and return synchronously after the batch. - */ -static void apif_ring(struct aurora_apif *apif) -{ - u64 pa = virt_to_phys(apif->batch); - - /* Publish the request before its synchronous doorbell. */ - wmb(); - asm volatile("mov x9, sp\n" - "str %x[pa], [%[db]]\n" - "mov sp, x9\n" - : - : [pa] "r"(pa), [db] "r"(apif->doorbell) - : "x9", "memory"); - /* Observe completion and returned fields after redispatch. */ - rmb(); -} - -int aurora_apif_submit(struct aurora_apif *apif, struct aurora_apif_op *ops, - u32 count, u32 *done) -{ - unsigned long flags; - u32 total = 0; - int ret = 0; - - if (done) - *done = 0; - if (!apif || (count && !ops)) - return -EINVAL; - raw_spin_lock_irqsave(&apif->lock, flags); - if (!apif->live) { - ret = -ENODEV; - goto out; - } - while (total < count) { - u32 n = min(count - total, apif->max_ops); - u32 reported; - - apif->batch->count = n; - apif->batch->flags = 0; - apif->batch->status = -EINPROGRESS; - apif->batch->done = 0; - memcpy(apif->batch->ops, ops + total, n * sizeof(*ops)); - apif_ring(apif); - reported = READ_ONCE(apif->batch->done); - if (reported > n) { - ret = -EIO; - break; - } - memcpy(ops + total, apif->batch->ops, n * sizeof(*ops)); - total += reported; - ret = READ_ONCE(apif->batch->status); - if (ret || reported != n) { - if (ret >= 0 || ret == -EINPROGRESS) - ret = -EIO; - break; - } - } -out: - raw_spin_unlock_irqrestore(&apif->lock, flags); - if (done) - *done = total; - return ret; -} -EXPORT_SYMBOL_GPL(aurora_apif_submit); - -static void apif_free(struct kref *refs) -{ - kfree(container_of(refs, struct aurora_apif, refs)); -} - -void aurora_apif_put(struct aurora_apif *apif) -{ - kref_put(&apif->refs, apif_free); -} -EXPORT_SYMBOL_GPL(aurora_apif_put); - -static void apif_revoke(void *data) -{ - struct aurora_apif *apif = data; - unsigned long flags; - - raw_spin_lock_irqsave(&apif->lock, flags); - apif->live = false; - apif->doorbell = NULL; - apif->batch = NULL; - raw_spin_unlock_irqrestore(&apif->lock, flags); - aurora_apif_put(apif); -} - -struct aurora_apif *aurora_apif_get(struct device *dev) -{ - struct device_node *node; - struct platform_device *supplier; - struct apif_provider *provider; - struct aurora_apif *apif; - struct device_link *link; - int ret; - - node = of_parse_phandle(dev->of_node, "aurora,apif", 0); - if (!node) - return ERR_PTR(-ENODEV); - supplier = of_find_device_by_node(node); - of_node_put(node); - if (!supplier) - return ERR_PTR(-EPROBE_DEFER); - if (supplier->dev.driver != &apif_driver.driver) { - ret = -EPROBE_DEFER; - goto put_device; - } - link = device_link_add(dev, &supplier->dev, - DL_FLAG_AUTOREMOVE_CONSUMER); - if (!link) { - ret = -ENOMEM; - goto put_device; - } - provider = platform_get_drvdata(supplier); - if (!provider) { - ret = -EPROBE_DEFER; - goto remove_link; - } - apif = kzalloc(sizeof(*apif), GFP_KERNEL); - if (!apif) { - ret = -ENOMEM; - goto remove_link; - } - kref_init(&apif->refs); - raw_spin_lock_init(&apif->lock); - apif->batch = devm_kzalloc(dev, APIF_BATCH_BYTES, GFP_KERNEL); - if (!apif->batch) { - ret = -ENOMEM; - aurora_apif_put(apif); - goto remove_link; - } - apif->max_ops = provider->max_ops; - apif->doorbell = provider->regs + APIF_REG_DOORBELL; - apif->live = true; - kref_get(&apif->refs); - ret = devm_add_action_or_reset(dev, apif_revoke, apif); - if (ret) { - aurora_apif_put(apif); - goto remove_link; - } - put_device(&supplier->dev); - return apif; -remove_link: - device_link_del(link); -put_device: - put_device(&supplier->dev); - return ERR_PTR(ret); -} -EXPORT_SYMBOL_GPL(aurora_apif_get); - -static int apif_probe(struct platform_device *pdev) -{ - struct apif_provider *provider; - struct resource *resource; - u64 max_ops; - - resource = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!resource || - resource_size(resource) < APIF_REG_DOORBELL + sizeof(u64)) - return -EINVAL; - provider = devm_kzalloc(&pdev->dev, sizeof(*provider), GFP_KERNEL); - if (!provider) - return -ENOMEM; - provider->regs = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(provider->regs)) - return PTR_ERR(provider->regs); - if (readq(provider->regs + APIF_REG_MAGIC) != APIF_MAGIC || - readq(provider->regs + APIF_REG_VERSION) != APIF_VERSION || - !(readq(provider->regs + APIF_REG_FEATURES) & APIF_FEAT_NATIVE)) - return dev_err_probe(&pdev->dev, -ENODEV, - "unsupported APIF interface\n"); - max_ops = readq(provider->regs + APIF_REG_MAX_OPS); - if (!max_ops) - return -EINVAL; - provider->max_ops = min_t(u64, max_ops, APIF_BATCH_MAX); - platform_set_drvdata(pdev, provider); - return 0; -} - -static const struct of_device_id apif_of_match[] = { - { .compatible = "aurora,apif-mmio" }, - {} -}; -MODULE_DEVICE_TABLE(of, apif_of_match); - -static struct platform_driver apif_driver = { - .driver = { - .name = "aurora-apif-mmio", - .of_match_table = apif_of_match, - }, - .probe = apif_probe, -}; -module_platform_driver(apif_driver); - -MODULE_DESCRIPTION("Aurora Platform Interface over Memory-Mapped I/O"); -MODULE_LICENSE("GPL"); diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index dd2dd23043b54..4233b253b06e2 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -329,18 +329,6 @@ config APPLE_DART_J713_DCP Leave this disabled for ordinary DART use, including APPLE_DART=m. -config APPLE_DART_APIF - bool "Apple DART over the Aurora platform interface" - depends on ARM64_16K_PAGES && OF - depends on ARCH_APPLE || COMPILE_TEST - select AURORA_APIF_MMIO - select IOMMU_API - help - Apple DART backend for a trusted Linux guest under Aura and SPTM. - Native mapping and retyping policy lives in Linux; the monitor - provides call transport, frame ownership and bootstrap metadata. - Existing raw-MMIO DART drivers continue to serve other systems. - config APPLE_DART_KUNIT_TEST bool "KUnit tests for Apple DART domains and commands" if !KUNIT_ALL_TESTS depends on APPLE_DART=y && KUNIT=y diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 43893f2c03dbd..2f05725eaab18 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -38,5 +38,3 @@ obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o obj-$(CONFIG_APPLE_DART) += apple-dart.o obj-$(CONFIG_VSI_IOMMU) += vsi-iommu.o obj-$(CONFIG_IOMMU_DEBUG_PAGEALLOC) += iommu-debug-pagealloc.o - -obj-$(CONFIG_APPLE_DART_APIF) += apple-dart-apif.o diff --git a/drivers/iommu/apple-dart-apif.c b/drivers/iommu/apple-dart-apif.c deleted file mode 100644 index 8b5792c1efd7e..0000000000000 --- a/drivers/iommu/apple-dart-apif.c +++ /dev/null @@ -1,2077 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* Apple DART IOMMU backend using Aura's native SPTM call transport. - * Linux owns stream topology, translation-table setup, DMA apertures and - * transactional mapping bookkeeping. Aura forwards native selectors 1:1. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dma-iommu.h" - -/* Internal operations used by the IOMMU bookkeeping; not the APIF wire ABI. */ -#define APIF_DART_INIT 1 /* () INIT + POWERUP */ -#define APIF_DART_ATTACH 2 /* (sid, dva, level) */ -#define APIF_DART_MAP 3 /* (sid, dva, ipa, size, prot) */ -#define APIF_DART_UNMAP 4 /* (sid, dva, size) */ -#define APIF_DART_ENABLE 5 /* (sid) */ -#define APIF_DART_DISABLE 6 /* (sid) */ - -#define APIF_DART_RETAINED_INFO 9 -#define APIF_DART_RETAINED_RUN 10 - -struct apif_op { - u32 op; - u32 flags; - u64 arg[6]; - u64 ret; -}; - -struct apif_batch { - u32 count; - u32 flags; - s32 status; - u32 done; - struct apif_op op[]; -}; - -#define DART_APIF_PAGE_SHIFT 14 -#define DART_APIF_PAGE_SIZE (1UL << DART_APIF_PAGE_SHIFT) /* 16 KiB */ -/* apif's DART MAP forwards one contiguous run within a single 32 MiB leaf-table - * span, so every MAP op must stay inside one aligned block. - */ -#define DART_APIF_BLOCK_SHIFT 25 -#define DART_APIF_BLOCK_SIZE (1UL << DART_APIF_BLOCK_SHIFT) /* 32 MiB */ - -#define DART_APIF_MAX_STREAMS 256 -#define DART_APIF_APERTURE_END (SZ_4G - 1) -#define DART_APIF_NATIVE_APERTURE_END GENMASK_ULL(41, 0) - -/* Preserve batched per-block operations and the existing rollback accounting. */ -#define APIF_BATCH_MAX_OPS \ - ((PAGE_SIZE - sizeof(struct apif_batch)) / sizeof(struct apif_op)) - -static const struct iommu_ops apple_dart_apif_ops; - -struct apif_retained_run { - u64 dva, ipa, size; -}; -struct apif_retained_sid { - unsigned int root_level, count; - struct apif_retained_run *runs; -}; - -struct apple_dart_apif { - struct device *dev; - struct iommu_device iommu; - struct aurora_apif *apif; - struct aurora_apif_op *native_ops; - struct aurora_apif_boot_iommu *boot_info; - u64 *page_lists[APIF_BATCH_MAX_OPS]; - u64 page_list_pa[APIF_BATCH_MAX_OPS]; - u32 dart_id; - u32 num_streams; - u64 iova_force; /* Native address force mask, hidden from DMA API/device addresses. */ - u64 dma_min, dma_max; - bool reserve_last_page; - bool inited; - bool boot_mappings; /* U-Boot retained the running MTP's DMA tables. */ - bool ownership_uncertain; /* A table operation needs a fresh boot after lost completion. */ - struct apif_retained_sid *retained[DART_APIF_MAX_STREAMS]; - struct mutex init_lock; /* serialises one-time init */ - /* Protected by apple_dart_apif_groups_lock; group-owned lifetime. */ - struct iommu_group *sid2group[DART_APIF_MAX_STREAMS]; - - struct apif_batch *batch; /* internal mapping-operation buffer */ - spinlock_t batch_lock; /* protects operation buffers and stream updates */ -}; - -/* Match the native DART driver's capacity for shared display DMA domains. */ -#define APIF_MAX_DARTS 8 - -struct apif_stream_map { - struct apple_dart_apif *dart; - DECLARE_BITMAP(sids, DART_APIF_MAX_STREAMS); -}; - -struct apple_dart_apif_master { - unsigned int num_darts; - struct apif_stream_map streams[APIF_MAX_DARTS]; -}; - -struct apple_dart_apif_domain { - struct iommu_domain domain; - unsigned int num_darts; - struct apif_stream_map streams[APIF_MAX_DARTS]; - struct mutex lock; /* serialises domain attachments */ - /* Mapping calls may run concurrently on distinct ranges. An attachment - * must replay a stable mapping set before publishing its new streams. - */ - rwlock_t streams_lock; - /* Key: dart-id:8, sid:8, block:40. SPTM tables cannot be attached twice. */ - struct xarray l2_attached; - bool has_retained; - /* One canonical mapping set and IOVA allocator for every DART. */ - struct xarray mappings; -}; - -static struct apif_stream_map * -apif_find_stream(struct apple_dart_apif_domain *dom, - struct apple_dart_apif *dart) -{ - if (dom) - for (unsigned int i = 0; i < dom->num_darts; i++) - if (dom->streams[i].dart == dart) - return &dom->streams[i]; - return NULL; -} - -/* Domain topology is fixed before the first attachment. Later devices can - * add SIDs on these DARTs, but cannot change an active allocator's aperture. - */ -static int apif_domain_configure(struct apple_dart_apif_domain *dom, - const struct apple_dart_apif_master *master) -{ - u64 start = 0, end = DART_APIF_NATIVE_APERTURE_END; - - if (!master || !master->num_darts) - return -ENODEV; - if (dom->num_darts) { - for (unsigned int i = 0; i < master->num_darts; i++) - if (!apif_find_stream(dom, master->streams[i].dart)) - return -EINVAL; - return 0; - } - for (unsigned int i = 0; i < master->num_darts; i++) { - start = max(start, master->streams[i].dart->dma_min); - end = min(end, master->streams[i].dart->dma_max); - } - if (start > end) - return -EINVAL; - for (unsigned int i = 0; i < master->num_darts; i++) - dom->streams[i].dart = master->streams[i].dart; - dom->domain.geometry.aperture_start = start; - dom->domain.geometry.aperture_end = end; - dom->num_darts = master->num_darts; - return 0; -} - -static struct apple_dart_apif_domain *to_apif_domain(struct iommu_domain *dom) -{ - return container_of(dom, struct apple_dart_apif_domain, domain); -} - -/* The native DMA address space strips the force bits before returning a device DMA address - * and restores it for DART operations. Translate only the bounded transport - * batch; all live-map bookkeeping and the DMA aperture remain device-visible. - * The force bits are disjoint from the validated low-4-GiB aperture. - */ -static void apif_force_iovas(struct apple_dart_apif *dart, bool restore) -{ - if (!dart->iova_force) - return; - for (u32 i = 0; i < dart->batch->count; i++) { - struct apif_op *op = &dart->batch->op[i]; - - switch (op->op) { - case APIF_DART_ATTACH: - case APIF_DART_MAP: - case APIF_DART_UNMAP: - if (restore) - op->arg[1] &= ~dart->iova_force; - else - op->arg[1] |= dart->iova_force; - break; - } - } -} - -static void apif_put_transport(void *data) -{ - aurora_apif_put(data); -} - -static void apif_free_page_lists(void *data) -{ - struct apple_dart_apif *dart = data; - - for (unsigned int i = 0; i < APIF_BATCH_MAX_OPS; i++) - kfree(dart->page_lists[i]); -} - -static int apif_one(struct apple_dart_apif *dart, struct aurora_apif_op *op) -{ - return aurora_apif_submit(dart->apif, op, 1, NULL); -} - -static int apif_prepare_table(struct apple_dart_apif *dart, u64 sid, u64 dva, - u64 level) -{ - u64 base = level ? round_down(dva, 1ULL << (level == 1 ? 36 : 25)) : 0; - u64 owner = 0x4441525400000000ULL | ((u64)dart->dart_id << 16) | - (sid << 8) | level; - struct aurora_apif_op op = { - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_BOOT_TABLE), - .arg = { AURORA_APIF_BOOT_DART, dart->dart_id, sid, dva, - level }, - }; - u64 pa; - int ret; - - if (sid >= dart->num_streams || level > 2) - return -EINVAL; - if (level == 2 && dart->retained[sid] && - !dart->retained[sid]->root_level) { - ret = apif_prepare_table(dart, sid, dva, 1); - if (ret) - return ret; - } - ret = apif_one(dart, &op); - if (ret || op.ret) - return ret; - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_FIND_FRAME), - .arg = { owner, base }, - }; - ret = apif_one(dart, &op); - if (ret || op.ret) - return ret; - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_ALLOC_FRAME), - }; - ret = apif_one(dart, &op); - if (ret) - return ret; - pa = op.ret; - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(0, 1), /* RETYPE */ - .arg = { pa, 11, 24, - (((level << 16) | (sid << 8) | dart->dart_id) << 32) | - 5 }, - }; - ret = apif_one(dart, &op); - if (ret) { - dart->ownership_uncertain = true; - return ret; /* Retain the frame until a fresh boot. */ - } - if (!op.ret) { - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR( - AURORA_APIF_SERVICE, AURORA_APIF_FREE_FRAME), - .arg = { pa }, - }; - apif_one(dart, &op); - return -EIO; - } - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(3, 0), /* DART MAP_TABLE */ - .arg = { dart->dart_id, sid, dva, level, pa }, - }; - ret = apif_one(dart, &op); - if (ret) { - dart->ownership_uncertain = true; - return ret; - } - /* Publish the opaque ownership key only after the table is attached. */ - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_TAG_FRAME), - .arg = { pa, owner, base }, - }; - ret = apif_one(dart, &op); - if (ret) - dart->ownership_uncertain = true; - return ret; -} - -static int apif_boot_query(struct apple_dart_apif *dart, - struct apif_op *request) -{ - struct apif_retained_sid *r = request->arg[0] < dart->num_streams ? - dart->retained[request->arg[0]] : NULL; - - if (dart->boot_mappings && r) { - if (request->op == APIF_DART_RETAINED_INFO) { - request->arg[1] = r->root_level; - request->arg[2] = r->count; - request->arg[3] = dart->dma_min; - request->arg[4] = dart->dma_max - dart->dma_min + 1; - request->arg[5] = 1; - } else { - const struct apif_retained_run *run; - - if (request->arg[1] >= r->count) - return -EINVAL; - run = &r->runs[request->arg[1]]; - request->arg[2] = run->dva; - request->arg[3] = run->ipa; - request->arg[4] = run->size; - request->arg[5] = 0; - } - return 0; - } - - struct aurora_apif_boot_iommu *info = dart->boot_info; - struct aurora_apif_op op = { - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_BOOT_IOMMU), - .arg = { AURORA_APIF_BOOT_DART, dart->dart_id, request->arg[0], - request->op == APIF_DART_RETAINED_INFO ? - U64_MAX : - request->arg[1], - virt_to_phys(info), sizeof(*info) }, - }; - int ret = apif_one(dart, &op); - - if (ret) - return ret; - if (request->op == APIF_DART_RETAINED_INFO) { - request->arg[1] = info->level; - request->arg[2] = info->count; - request->arg[3] = info->base; - request->arg[4] = info->size; - request->arg[5] = 1; - } else { - request->arg[2] = info->base; - request->arg[3] = info->ipa; - request->arg[4] = info->size; - request->arg[5] = info->attrs; - } - return 0; -} - -/* Build native calls in Linux, including address lists and permission flags. - * Address translations form a separate batch, so failure cannot send a MAP - * with an untranslated pointer. Mapping batches keep the original capacity - * and prefix-completion accounting used by rollback. Caller holds batch_lock. - */ -static int apif_ring(struct apple_dart_apif *dart) -{ - struct aurora_apif_op *native = dart->native_ops; - u32 count = dart->batch->count, n = 0, translated = 0, done = 0; - u32 ends[APIF_BATCH_MAX_OPS]; - int ret = 0; - - dart->batch->done = 0; - if (dart->ownership_uncertain) { - dart->batch->status = -EIO; - return -EIO; - } - if (count > APIF_BATCH_MAX_OPS) - return -EINVAL; - apif_force_iovas(dart, false); - for (u32 i = 0; i < count; i++) { - struct apif_op *op = &dart->batch->op[i]; - - if (op->flags) { - ret = -EINVAL; - goto out; - } - if (op->op == APIF_DART_MAP) { - if (op->arg[4] & - ~(IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE | - IOMMU_NOEXEC | IOMMU_MMIO)) { - ret = -EINVAL; - goto out; - } - if (!dart->page_lists[i]) - dart->page_lists[i] = - kmalloc(SZ_16K, GFP_ATOMIC); - if (!dart->page_lists[i]) { - ret = -ENOMEM; - goto out; - } - native[translated++] = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR( - AURORA_APIF_SERVICE, - AURORA_APIF_TRANSLATE), - .arg = { op->arg[2], op->arg[3] }, - }; - native[translated++] = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR( - AURORA_APIF_SERVICE, - AURORA_APIF_TRANSLATE), - .arg = { virt_to_phys(dart->page_lists[i]), - SZ_16K }, - }; - } - } - if (translated) { - ret = aurora_apif_submit(dart->apif, native, translated, NULL); - if (ret) - goto out; - translated = 0; - for (u32 i = 0; i < count; i++) - if (dart->batch->op[i].op == APIF_DART_MAP) { - dart->batch->op[i].arg[5] = - native[translated++].ret; - dart->page_list_pa[i] = - native[translated++].ret; - } - } - for (u32 i = 0; i < count; i++) { - struct apif_op *op = &dart->batch->op[i]; - u64 *a = op->arg; - struct aurora_apif_op call = {}; - - call.arg[0] = dart->dart_id; - call.arg[1] = a[0]; - op->ret = 0; - switch (op->op) { - case APIF_DART_INIT: { - if (dart->boot_mappings) - break; - struct aurora_apif_op query = { - .selector = AURORA_APIF_SELECTOR( - AURORA_APIF_SERVICE, - AURORA_APIF_BOOT_TABLE), - .arg = { AURORA_APIF_BOOT_DART, dart->dart_id, - 0, 0, U64_MAX }, - }; - - ret = apif_one(dart, &query); - if (ret) - goto out; - if (!query.ret) { - call.selector = - AURORA_APIF_SELECTOR(3, 6); /* INIT */ - native[n++] = call; - call.selector = AURORA_APIF_SELECTOR( - 3, 5); /* POWERUP */ - native[n++] = call; - } - break; - } - case APIF_DART_ATTACH: - ret = apif_prepare_table(dart, a[0], a[1], a[2]); - if (ret) - goto out; - break; - case APIF_DART_RETAINED_INFO: - case APIF_DART_RETAINED_RUN: - ret = apif_boot_query(dart, op); - if (ret) - goto out; - break; - case APIF_DART_MAP: { - u64 pa = a[5], size = a[3]; - - if (!size || size > DART_APIF_BLOCK_SIZE || - ((a[1] | pa | size) & (DART_APIF_PAGE_SIZE - 1)) || - (a[1] >> 25) != ((a[1] + size - 1) >> 25)) { - ret = -EINVAL; - goto out; - } - for (u64 p = 0; p < size / DART_APIF_PAGE_SIZE; p++) - dart->page_lists[i][p] = - pa + p * DART_APIF_PAGE_SIZE; - call.selector = AURORA_APIF_SELECTOR(3, 2); /* MAP */ - call.arg[2] = a[1]; - call.arg[3] = dart->page_list_pa[i]; - call.arg[4] = size; - call.arg[5] = (~a[4]) & 7; - native[n++] = call; - break; - } - case APIF_DART_UNMAP: - call.selector = AURORA_APIF_SELECTOR(3, 3); - call.arg[2] = a[1]; - call.arg[3] = a[2]; - call.arg[4] = 2; - native[n++] = call; - break; - case APIF_DART_ENABLE: - case APIF_DART_DISABLE: - if (a[0] >= dart->num_streams) { - ret = -EINVAL; - goto out; - } - /* Live firmware retains stream state across Linux domain - * attachment and teardown, just as for power transitions. - */ - if (dart->retained[a[0]]) - break; - call.selector = AURORA_APIF_SELECTOR( - 3, op->op == APIF_DART_ENABLE ? 8 : 7); - native[n++] = call; - break; - case 7: /* POWERUP */ - case 8: /* POWERDOWN */ - for (u32 sid = 0; sid < dart->num_streams; sid++) - if (dart->retained[sid]) { - if (op->op == 8) { - ret = -EBUSY; - goto out; - } - goto prepared; - } - call.selector = - AURORA_APIF_SELECTOR(3, op->op == 7 ? 5 : 4); - native[n++] = call; - break; - default: - ret = -EINVAL; - goto out; - } -prepared: - ends[i] = n; - } - ret = aurora_apif_submit(dart->apif, native, n, &done); - for (u32 i = 0; i < count && ends[i] <= done; i++) - dart->batch->done = i + 1; -out: - apif_force_iovas(dart, true); - dart->batch->status = ret; - return ret; -} - -/* Setup-only host queries. Firmware-owned mappings are reserved, never replayed - * through MAP, and never inserted in the Linux-owned mappings xarray. - */ -static int apif_load_boot_mappings(struct apple_dart_apif *dart) -{ - struct device_node *np = dart->dev->of_node; - struct apif_retained_sid *r; - u64 cells[32], sid, previous = 0; - int count, ret; - - if (!of_find_property(np, "apple,apif-boot-mappings", NULL)) - return 0; - count = of_property_count_u64_elems(np, "apple,apif-boot-mappings"); - if (count < 4 || count > ARRAY_SIZE(cells) || count % 4 || dart->iova_force) - return -EINVAL; - ret = of_property_read_u64_array(np, "apple,apif-boot-mappings", cells, count); - if (ret) - return ret; - sid = cells[0]; - if (sid >= dart->num_streams || dart->retained[sid]) - return -EINVAL; - r = devm_kzalloc(dart->dev, sizeof(*r), GFP_KERNEL); - if (!r) - return -ENOMEM; - r->root_level = 1; - r->count = count / 4; - r->runs = devm_kcalloc(dart->dev, r->count, sizeof(*r->runs), GFP_KERNEL); - if (!r->runs) - return -ENOMEM; - for (unsigned int i = 0; i < r->count; i++) { - struct apif_retained_run *run = &r->runs[i]; - - run->dva = cells[i * 4 + 1]; - run->ipa = cells[i * 4 + 2]; - run->size = cells[i * 4 + 3]; - if (cells[i * 4] != sid || !run->size || - (run->dva | run->ipa | run->size) & (DART_APIF_PAGE_SIZE - 1) || - run->dva < dart->dma_min || run->dva > dart->dma_max || - run->size - 1 > dart->dma_max - run->dva || - run->size > U64_MAX - run->ipa || (i && run->dva < previous)) - return -EINVAL; - previous = run->dva + run->size; - } - dart->retained[sid] = r; - dart->boot_mappings = true; - dev_info(dart->dev, "retaining %u boot DMA mappings on stream %llu\n", r->count, sid); - return 0; -} - -static int apif_load_retained(struct apple_dart_apif *dart) -{ - struct device_node *np = dart->dev->of_node; - int count = of_property_count_u32_elems(np, "apple,apif-retained-sids"); - int ret; - - if (!of_find_property(np, "apple,apif-retained-sids", NULL)) - return 0; - if (count < 1 || count > dart->num_streams || dart->iova_force) - return -EINVAL; - for (int i = 0; i < count; i++) { - struct apif_retained_sid *r; - u32 sid; - u64 previous = 0; - struct apif_op *op = &dart->batch->op[0]; - - if (of_property_read_u32_index(np, "apple,apif-retained-sids", - i, &sid) || - sid >= dart->num_streams || dart->retained[sid]) - return -EINVAL; - dart->batch->count = 1; - *op = (struct apif_op){ .op = APIF_DART_RETAINED_INFO, - .arg = { sid } }; - ret = apif_ring(dart); - if (ret) - return ret; - if (op->arg[1] > 1 || op->arg[2] > 131072 || op->arg[5] != 1 || - op->arg[3] != dart->dma_min || - op->arg[4] != dart->dma_max - dart->dma_min + 1) - return -EINVAL; - r = devm_kzalloc(dart->dev, sizeof(*r), GFP_KERNEL); - if (!r) - return -ENOMEM; - r->root_level = op->arg[1]; - r->count = op->arg[2]; - r->runs = devm_kcalloc(dart->dev, r->count, sizeof(*r->runs), - GFP_KERNEL); - if (r->count && !r->runs) - return -ENOMEM; - for (u64 j = 0; j < r->count; j++) { - struct apif_retained_run *run = &r->runs[j]; - - *op = (struct apif_op){ .op = APIF_DART_RETAINED_RUN, - .arg = { sid, j } }; - ret = apif_ring(dart); - if (ret) - return ret; - run->dva = op->arg[2]; - run->ipa = op->arg[3]; - run->size = op->arg[4]; - if (!run->size || - (run->dva | run->size) & - (DART_APIF_PAGE_SIZE - 1) || - run->dva < dart->dma_min || - run->dva > dart->dma_max || - run->size - 1 > dart->dma_max - run->dva || - (j && run->dva < previous) || - (run->ipa != U64_MAX && - ((run->ipa & (DART_APIF_PAGE_SIZE - 1)) || - run->size > U64_MAX - run->ipa))) - return -EINVAL; - previous = run->dva + run->size; - } - dart->retained[sid] = r; - } - return 0; -} - -static const struct apif_retained_run * -apif_retained_lookup(const struct apif_retained_sid *r, u64 dva, u64 size) -{ - unsigned int low = 0, high = r->count; - - while (low < high) { - unsigned int mid = low + (high - low) / 2; - const struct apif_retained_run *run = &r->runs[mid]; - - if (run->dva + run->size <= dva) - low = mid + 1; - else - high = mid; - } - return low < r->count && r->runs[low].dva < dva + size ? &r->runs[low] : - NULL; -} - -static bool apif_retained_overlap(struct apple_dart_apif_domain *dom, u64 dva, - u64 size) -{ - unsigned int sid; - - if (!dom->has_retained) - return false; - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) { - struct apif_retained_sid *r = - stream->dart->retained[sid]; - - if (r && apif_retained_lookup(r, dva, size)) - return true; - } - } - return false; -} - -static phys_addr_t apif_retained_translate(struct apple_dart_apif_domain *dom, - u64 dva) -{ - unsigned int sid; - u64 result = 0; - - if (!dom->has_retained) - return 0; - /* Firmware may retain different mappings on different display engines. - * Only a unanimous translation is meaningful for their shared domain. - */ - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) { - struct apif_retained_sid *r = - stream->dart->retained[sid]; - const struct apif_retained_run *run = - r ? apif_retained_lookup(r, dva, 1) : NULL; - u64 pa; - - if (!run || dva < run->dva || run->ipa == U64_MAX) - return 0; - pa = run->ipa + dva - run->dva; - if (result && result != pa) - return 0; - result = pa; - } - } - return result; -} - -/* Bring the DART up in SPTM exactly once, before any stream is enabled. */ -static int apple_dart_apif_ensure_init(struct apple_dart_apif *dart) -{ - int ret = 0; - - mutex_lock(&dart->init_lock); - if (!dart->inited) { - unsigned long flags; - - spin_lock_irqsave(&dart->batch_lock, flags); - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ .op = APIF_DART_INIT }; - ret = apif_ring(dart); - spin_unlock_irqrestore(&dart->batch_lock, flags); - if (ret) - ret = -EIO; - else - dart->inited = true; - } - mutex_unlock(&dart->init_lock); - return ret; -} - -/* Live mappings are indexed by IOVA page. Normal map/unmap only touches the - * requested range; a complete walk is needed solely when adding a new SID. - * Zero tagged values reserve XArray storage before any hardware mapping. - */ -#define APIF_MAP_PROT_BITS 8 - -static unsigned long apif_mapping_value(phys_addr_t pa, int prot) -{ - return ((pa >> DART_APIF_PAGE_SHIFT) << APIF_MAP_PROT_BITS) | prot; -} - -static int apif_reserve_mappings(struct apple_dart_apif_domain *dom, - unsigned long iova, size_t size, gfp_t gfp) -{ - unsigned long first = iova >> DART_APIF_PAGE_SHIFT; - unsigned long pages = size >> DART_APIF_PAGE_SHIFT; - unsigned long page; - int ret; - - for (page = 0; page < pages; page++) { - ret = xa_insert(&dom->mappings, first + page, xa_mk_value(0), - gfp); - if (ret) - goto undo; - } - return 0; -undo: - while (page) - xa_erase(&dom->mappings, first + --page); - return ret; -} - -static void apif_release_reservations(struct apple_dart_apif_domain *dom, - unsigned long iova, size_t size) -{ - unsigned long first = iova >> DART_APIF_PAGE_SHIFT; - unsigned long pages = size >> DART_APIF_PAGE_SHIFT; - - for (unsigned long page = 0; page < pages; page++) - if (xa_load(&dom->mappings, first + page) == xa_mk_value(0)) - xa_erase(&dom->mappings, first + page); -} - -static void apif_record_mapping(struct apple_dart_apif_domain *dom, u64 iova, - u64 pa, size_t size, int prot) -{ - for (size_t off = 0; off < size; off += DART_APIF_PAGE_SIZE) { - unsigned long index = (iova + off) >> DART_APIF_PAGE_SHIFT; - void *entry = xa_mk_value(apif_mapping_value(pa + off, prot)); - - /* Reserved entries retain their nodes, so replacing a reservation - * requires no allocation, even in this IRQ-disabled section. - */ - WARN_ON(xa_err( - xa_store(&dom->mappings, index, entry, GFP_NOWAIT))); - } -} - -static void apif_forget_mapping(struct apple_dart_apif_domain *dom, u64 iova, - size_t size) -{ - for (size_t off = 0; off < size; off += DART_APIF_PAGE_SIZE) - xa_erase(&dom->mappings, (iova + off) >> DART_APIF_PAGE_SHIFT); -} - -static int apif_prepare_leaf(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, unsigned int sid, - u64 iova) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned long key = ((unsigned long)dart->dart_id << 48) | - ((unsigned long)sid << 40) | - (iova >> DART_APIF_BLOCK_SHIFT); - int ret; - - if (xa_load(&dom->l2_attached, key)) - return 0; - ret = xa_insert(&dom->l2_attached, key, xa_mk_value(0), GFP_ATOMIC); - if (ret) - return ret; - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ - .op = APIF_DART_ATTACH, - .arg = { sid, iova, 2 }, - }; - ret = apif_ring(dart); - if (ret) { - xa_erase(&dom->l2_attached, key); - return ret; - } - WARN_ON(xa_err( - xa_store(&dom->l2_attached, key, xa_mk_value(1), GFP_NOWAIT))); - return 0; -} - -/* Return the next physically contiguous, same-protection run, stopping at a - * leaf-table boundary. Reservations are not yet live and are skipped. - */ -static bool apif_next_mapping(struct apple_dart_apif_domain *dom, - unsigned long *cursor, struct apif_op *op, - unsigned int sid) -{ - unsigned long index = *cursor, value, first; - void *entry; - u64 iova, pa; - size_t size; - int prot; - - for (;;) { - entry = xa_find(&dom->mappings, &index, ULONG_MAX, XA_PRESENT); - if (!entry) - return false; - value = xa_to_value(entry); - if (value) - break; - index++; - } - first = index; - prot = value & ((1UL << APIF_MAP_PROT_BITS) - 1); - pa = (value >> APIF_MAP_PROT_BITS) << DART_APIF_PAGE_SHIFT; - iova = (u64)first << DART_APIF_PAGE_SHIFT; - size = DART_APIF_PAGE_SIZE; - while ((iova + size) & (DART_APIF_BLOCK_SIZE - 1)) { - entry = xa_load(&dom->mappings, index + 1); - if (entry != xa_mk_value(apif_mapping_value(pa + size, prot))) - break; - index++; - size += DART_APIF_PAGE_SIZE; - } - *cursor = index + 1; - *op = (struct apif_op){ - .op = APIF_DART_MAP, - .arg = { sid, iova, pa, size, prot }, - }; - return true; -} - -static int apif_undo_replay(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, unsigned int sid, - u64 mapped_end) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned long cursor = 0; - struct apif_op op; - - while (apif_next_mapping(dom, &cursor, &op, sid) && - op.arg[1] < mapped_end) { - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ - .op = APIF_DART_UNMAP, - .arg = { sid, op.arg[1], - min_t(u64, op.arg[3], - mapped_end - op.arg[1]) }, - }; - if (apif_ring(dart)) { - dev_err(dart->dev, "failed to undo SID %u replay\n", - sid); - return -EIO; - } - } - return 0; -} - -/* New SID is disabled throughout replay. On failure, keep it disabled and - * remove the successful replay prefix. Existing SIDs/maps stay untouched. - */ -static int apif_replay_sid(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, unsigned int sid) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned long cursor = 0; - struct apif_op op; - u64 mapped_end = 0; - u32 n = 0; - int ret; - - while (apif_next_mapping(dom, &cursor, &op, sid)) { - if (dart->retained[sid] && - apif_retained_lookup(dart->retained[sid], op.arg[1], - op.arg[3])) - return -EBUSY; - ret = apif_prepare_leaf(dom, stream, sid, op.arg[1]); - if (ret) - return ret; - } - cursor = 0; - for (;;) { - bool have = apif_next_mapping(dom, &cursor, &op, sid); - - if (have) - dart->batch->op[n++] = op; - if (n == APIF_BATCH_MAX_OPS || (!have && n)) { - dart->batch->count = n; - ret = apif_ring(dart); - for (u32 i = 0; i < min(dart->batch->done, n); i++) - mapped_end = dart->batch->op[i].arg[1] + - dart->batch->op[i].arg[3]; - if (ret) - goto undo; - n = 0; - } - if (!have) - return 0; - } -undo: - apif_undo_replay(dom, stream, sid, mapped_end); - return ret; -} - -static int apple_dart_apif_attach_dev(struct iommu_domain *domain, - struct device *dev, - struct iommu_domain *old) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - struct apple_dart_apif_domain *dom = to_apif_domain(domain); - struct apple_dart_apif_domain *prior = NULL; - unsigned long added[APIF_MAX_DARTS] - [BITS_TO_LONGS(DART_APIF_MAX_STREAMS)] = {}; - unsigned long moved[APIF_MAX_DARTS] - [BITS_TO_LONGS(DART_APIF_MAX_STREAMS)] = {}; - unsigned long flags; - unsigned int sid; - int ret; - - if (!master || !master->num_darts) - return -ENODEV; - for (unsigned int i = 0; i < master->num_darts; i++) { - ret = apple_dart_apif_ensure_init(master->streams[i].dart); - if (ret) - return ret; - } - if (old && old != domain && old->owner == &apple_dart_apif_ops && - old->ops == apple_dart_apif_ops.default_domain_ops) - prior = to_apif_domain(old); - if (prior && (unsigned long)prior < (unsigned long)dom) { - mutex_lock(&prior->lock); - mutex_lock_nested(&dom->lock, SINGLE_DEPTH_NESTING); - } else { - mutex_lock(&dom->lock); - if (prior) - mutex_lock_nested(&prior->lock, SINGLE_DEPTH_NESTING); - } - ret = apif_domain_configure(dom, master); - if (ret) - goto unlock_mutex; - - local_irq_save(flags); - if (prior && (unsigned long)prior < (unsigned long)dom) { - write_lock(&prior->streams_lock); - write_lock_nested(&dom->streams_lock, SINGLE_DEPTH_NESTING); - } else { - write_lock(&dom->streams_lock); - if (prior) - write_lock_nested(&prior->streams_lock, - SINGLE_DEPTH_NESTING); - } - for (unsigned int i = 0; i < master->num_darts && !ret; i++) { - struct apple_dart_apif *dart = master->streams[i].dart; - struct apif_stream_map *stream = apif_find_stream(dom, dart); - struct apif_stream_map *before = apif_find_stream(prior, dart); - - spin_lock(&dart->batch_lock); - for_each_set_bit(sid, master->streams[i].sids, - dart->num_streams) { - if (test_bit(sid, stream->sids)) - continue; - if (dart->retained[sid] && before && - test_bit(sid, before->sids)) { - set_bit(sid, moved[i]); - ret = apif_undo_replay(prior, before, sid, - U64_MAX); - if (ret) - break; - } - dart->batch->count = dart->retained[sid] ? 1 : 2; - dart->batch->op[0] = (struct apif_op){ - .op = dart->retained[sid] ? - APIF_DART_RETAINED_INFO : - APIF_DART_DISABLE, - .arg = { sid }, - }; - if (!dart->retained[sid]) - dart->batch->op[1] = (struct apif_op){ - .op = APIF_DART_ATTACH, - .arg = { sid, dart->dma_min, 1 }, - }; - ret = apif_ring(dart); - if (ret) - break; - ret = apif_replay_sid(dom, stream, sid); - if (ret) - break; - /* Include this SID in unwind even when ENABLE's completion fails. */ - set_bit(sid, added[i]); - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ - .op = dart->retained[sid] ? - APIF_DART_RETAINED_INFO : - APIF_DART_ENABLE, - .arg = { sid }, - }; - ret = apif_ring(dart); - if (ret) - break; - dom->has_retained |= !!dart->retained[sid]; - set_bit(sid, stream->sids); - } - spin_unlock(&dart->batch_lock); - } - - /* Attach is one transaction across all of the master's DARTs. */ - for (unsigned int i = 0; i < master->num_darts; i++) { - struct apple_dart_apif *dart = master->streams[i].dart; - struct apif_stream_map *stream = apif_find_stream(dom, dart); - struct apif_stream_map *before = apif_find_stream(prior, dart); - - spin_lock(&dart->batch_lock); - if (ret) { - for_each_set_bit(sid, added[i], dart->num_streams) { - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ - .op = dart->retained[sid] ? - APIF_DART_RETAINED_INFO : - APIF_DART_DISABLE, - .arg = { sid }, - }; - if (apif_ring(dart)) - dev_err(dart->dev, - "failed to disable SID %u during attach unwind\n", - sid); - apif_undo_replay(dom, stream, sid, U64_MAX); - clear_bit(sid, stream->sids); - } - } - for_each_set_bit(sid, moved[i], dart->num_streams) { - if (ret) { - if (apif_replay_sid(prior, before, sid)) - dev_err(dart->dev, - "failed to restore previous domain SID %u\n", - sid); - } else { - clear_bit(sid, before->sids); - } - } - spin_unlock(&dart->batch_lock); - } - if (prior) - write_unlock(&prior->streams_lock); - write_unlock(&dom->streams_lock); - local_irq_restore(flags); -unlock_mutex: - if (prior) - mutex_unlock(&prior->lock); - mutex_unlock(&dom->lock); - return ret; -} - -struct apif_map_progress { - size_t mapped; - unsigned int streams; - struct apif_op partial; -}; - -/* Track only fully installed stream cohorts. The batch may split one cohort - * without reducing batching; keep its progress across doorbells. - */ -static int apif_flush_maps(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, - struct apif_map_progress *progress) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned int total_streams = - bitmap_weight(stream->sids, dart->num_streams); - int ret = apif_ring(dart); - - for (u32 i = 0; i < min(dart->batch->done, dart->batch->count); i++) { - struct apif_op *op = &dart->batch->op[i]; - - progress->partial = *op; - if (++progress->streams == total_streams) { - progress->mapped += op->arg[3]; - progress->streams = 0; - } - } - if (ret && progress->streams) { - unsigned int sid; - u32 n = 0; - - for_each_set_bit(sid, stream->sids, dart->num_streams) { - if (n == progress->streams) - break; - dart->batch->op[n++] = (struct apif_op){ - .op = APIF_DART_UNMAP, - .arg = { sid, progress->partial.arg[1], - progress->partial.arg[3] }, - }; - } - dart->batch->count = n; - if (apif_ring(dart)) - dev_err(dart->dev, "failed to undo partial DART map\n"); - } - return ret; -} - -static int apif_map_streams(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, unsigned long iova, - phys_addr_t paddr, size_t pgsize, size_t pgcount, - int prot, gfp_t gfp, size_t *mapped) -{ - struct apple_dart_apif *dart = stream->dart; - struct apif_map_progress progress = {}; - size_t total; - unsigned long flags; - u32 n = 0; - int ret; - - *mapped = 0; - if (!dart || bitmap_empty(stream->sids, dart->num_streams)) - return -ENODEV; - if (pgsize != DART_APIF_PAGE_SIZE || !pgcount || - check_mul_overflow(pgsize, pgcount, &total) || - (iova | paddr) & (DART_APIF_PAGE_SIZE - 1) || - prot & ~(IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE | IOMMU_NOEXEC | - IOMMU_MMIO) || - !paddr || iova < dart->dma_min || iova > dart->dma_max || - total - 1 > dart->dma_max - iova || - iova + total > DART_APIF_NATIVE_APERTURE_END) - return -EINVAL; - spin_lock_irqsave(&dart->batch_lock, flags); - /* Install all leaf tables before accumulating the mapping batch. */ - for (size_t pos = 0; pos < total;) { - u64 cur = iova + pos; - size_t chunk = - min_t(size_t, total - pos, - DART_APIF_BLOCK_SIZE - - (cur & (DART_APIF_BLOCK_SIZE - 1))); - unsigned int sid; - - for_each_set_bit(sid, stream->sids, dart->num_streams) { - ret = apif_prepare_leaf(dom, stream, sid, cur); - if (ret) - goto out; - } - pos += chunk; - } - for (size_t pos = 0; pos < total;) { - u64 cur = iova + pos; - size_t chunk = - min_t(size_t, total - pos, - DART_APIF_BLOCK_SIZE - - (cur & (DART_APIF_BLOCK_SIZE - 1))); - unsigned int sid; - - for_each_set_bit(sid, stream->sids, dart->num_streams) { - dart->batch->op[n++] = (struct apif_op){ - .op = APIF_DART_MAP, - .arg = { sid, cur, paddr + pos, chunk, prot }, - }; - if (n == APIF_BATCH_MAX_OPS) { - dart->batch->count = n; - ret = apif_flush_maps(dom, stream, &progress); - if (ret) - goto out; - n = 0; - } - } - pos += chunk; - } - if (n) { - dart->batch->count = n; - ret = apif_flush_maps(dom, stream, &progress); - } -out: - spin_unlock_irqrestore(&dart->batch_lock, flags); - *mapped = progress.mapped; - return ret ? -EIO : 0; -} - -static int apif_restore_partial_unmap(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, - const struct apif_op *partial, - unsigned int streams) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned long cursor = partial->arg[1] >> DART_APIF_PAGE_SHIFT; - u64 end = partial->arg[1] + partial->arg[2]; - struct apif_op op; - u32 n = 0; - - while (apif_next_mapping(dom, &cursor, &op, 0) && op.arg[1] < end) { - unsigned int sid, count = 0; - - op.arg[3] = min_t(u64, op.arg[3], end - op.arg[1]); - for_each_set_bit(sid, stream->sids, dart->num_streams) { - if (count++ == streams) - break; - op.arg[0] = sid; - dart->batch->op[n++] = op; - if (n == APIF_BATCH_MAX_OPS) { - dart->batch->count = n; - if (apif_ring(dart)) - return -EIO; - n = 0; - } - } - } - if (!n) - return 0; - dart->batch->count = n; - return apif_ring(dart); -} - -static int apif_flush_unmaps(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, - struct apif_map_progress *progress) -{ - struct apple_dart_apif *dart = stream->dart; - unsigned int total_streams = - bitmap_weight(stream->sids, dart->num_streams); - int ret = apif_ring(dart); - - for (u32 i = 0; i < min(dart->batch->done, dart->batch->count); i++) { - struct apif_op *op = &dart->batch->op[i]; - - progress->partial = *op; - if (++progress->streams == total_streams) { - progress->mapped += op->arg[2]; - progress->streams = 0; - } - } - if (ret && progress->streams && - apif_restore_partial_unmap(dom, stream, &progress->partial, - progress->streams)) - dev_err(dart->dev, "failed to restore partial DART unmap\n"); - return ret; -} - -static size_t apif_unmap_streams(struct apple_dart_apif_domain *dom, - struct apif_stream_map *stream, - unsigned long iova, size_t pgsize, - size_t pgcount, - struct iommu_iotlb_gather *gather) -{ - struct apple_dart_apif *dart = stream->dart; - struct apif_map_progress progress = {}; - size_t total; - unsigned long flags; - u32 n = 0; - - if (!dart || bitmap_empty(stream->sids, dart->num_streams) || - pgsize != DART_APIF_PAGE_SIZE || !pgcount || - check_mul_overflow(pgsize, pgcount, &total) || - (iova & (DART_APIF_PAGE_SIZE - 1)) || iova < dart->dma_min || - iova > dart->dma_max || total - 1 > dart->dma_max - iova) - return 0; - spin_lock_irqsave(&dart->batch_lock, flags); - for (size_t pos = 0; pos < total;) { - u64 cur = iova + pos; - size_t chunk = - min_t(size_t, total - pos, - DART_APIF_BLOCK_SIZE - - (cur & (DART_APIF_BLOCK_SIZE - 1))); - unsigned int sid; - - for_each_set_bit(sid, stream->sids, dart->num_streams) { - dart->batch->op[n++] = (struct apif_op){ - .op = APIF_DART_UNMAP, - .arg = { sid, cur, chunk }, - }; - if (n == APIF_BATCH_MAX_OPS) { - dart->batch->count = n; - if (apif_flush_unmaps(dom, stream, &progress)) - goto out; - n = 0; - } - } - pos += chunk; - } - if (n) { - dart->batch->count = n; - apif_flush_unmaps(dom, stream, &progress); - } -out: - spin_unlock_irqrestore(&dart->batch_lock, flags); - return progress.mapped; -} - -/* A buffer has one IOVA and one software mapping, regardless of how many - * display engines can scan it out. Forward whole batches to each DART; do - * not split them into per-page or per-stream transactions. - */ -static int apple_dart_apif_map_pages(struct iommu_domain *domain, - unsigned long iova, phys_addr_t paddr, - size_t pgsize, size_t pgcount, int prot, - gfp_t gfp, size_t *mapped) -{ - struct apple_dart_apif_domain *dom = to_apif_domain(domain); - size_t done[APIF_MAX_DARTS] = {}, total; - unsigned long flags; - unsigned int active = 0; - int ret; - - *mapped = 0; - if (!dom->num_darts) - return -ENODEV; - if (pgsize != DART_APIF_PAGE_SIZE || !pgcount || - check_mul_overflow(pgsize, pgcount, &total) || - (iova | paddr) & (DART_APIF_PAGE_SIZE - 1) || !paddr || - total - 1 > U64_MAX - paddr || - prot & ~(IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE | IOMMU_NOEXEC | - IOMMU_MMIO) || - iova < domain->geometry.aperture_start || - iova > domain->geometry.aperture_end || - total - 1 > domain->geometry.aperture_end - iova || - iova + total > DART_APIF_NATIVE_APERTURE_END) - return -EINVAL; - ret = apif_reserve_mappings(dom, iova, total, gfp); - if (ret) - return ret; - read_lock_irqsave(&dom->streams_lock, flags); - if (apif_retained_overlap(dom, iova, total)) { - ret = -EBUSY; - goto out; - } - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - - if (bitmap_empty(stream->sids, stream->dart->num_streams)) - continue; - active++; - ret = apif_map_streams(dom, stream, iova, paddr, pgsize, - pgcount, prot, gfp, &done[i]); - if (ret) - break; - } - if (!active) - ret = -ENODEV; - if (!ret) { - apif_record_mapping(dom, iova, paddr, total, prot); - *mapped = total; - } else { - /* A later DART failed. Undo the successful prefixes on every - * engine before letting the DMA layer reuse this IOVA. - */ - for (unsigned int i = 0; i < dom->num_darts; i++) - if (done[i] && - apif_unmap_streams(dom, &dom->streams[i], iova, - pgsize, done[i] / pgsize, - NULL) != done[i]) - dev_err(dom->streams[i].dart->dev, - "failed to unwind multi-DART mapping\n"); - } -out: - read_unlock_irqrestore(&dom->streams_lock, flags); - if (ret) - apif_release_reservations(dom, iova, total); - return ret; -} - -static size_t apple_dart_apif_unmap_pages(struct iommu_domain *domain, - unsigned long iova, size_t pgsize, - size_t pgcount, - struct iommu_iotlb_gather *gather) -{ - struct apple_dart_apif_domain *dom = to_apif_domain(domain); - size_t done[APIF_MAX_DARTS] = {}, total, common; - unsigned long flags; - unsigned int active = 0; - - if (!dom->num_darts || pgsize != DART_APIF_PAGE_SIZE || !pgcount || - check_mul_overflow(pgsize, pgcount, &total) || - (iova & (DART_APIF_PAGE_SIZE - 1)) || - iova < domain->geometry.aperture_start || - iova > domain->geometry.aperture_end || - total - 1 > domain->geometry.aperture_end - iova) - return 0; - read_lock_irqsave(&dom->streams_lock, flags); - if (apif_retained_overlap(dom, iova, total)) { - common = 0; - goto out; - } - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - - if (bitmap_empty(stream->sids, stream->dart->num_streams)) - continue; - active++; - done[i] = apif_unmap_streams(dom, stream, iova, pgsize, pgcount, - gather); - if (done[i] != total) - break; - } - common = active ? total : 0; - for (unsigned int i = 0; i < dom->num_darts; i++) - if (!bitmap_empty(dom->streams[i].sids, - dom->streams[i].dart->num_streams)) - common = min(common, done[i]); - /* Preserve the canonical mapping until all engines have agreed. On - * failure restore the suffix removed from earlier engines, retaining - * their existing leaf tables and full-sized transport batches. - */ - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - struct apple_dart_apif *dart = stream->dart; - struct apif_op suffix = { - .arg = { 0, iova + common, done[i] - common }, - }; - - if (done[i] <= common) - continue; - spin_lock(&dart->batch_lock); - if (apif_restore_partial_unmap( - dom, stream, &suffix, - bitmap_weight(stream->sids, dart->num_streams))) - dev_err(dart->dev, - "failed to restore multi-DART unmap suffix\n"); - spin_unlock(&dart->batch_lock); - } - apif_forget_mapping(dom, iova, common); -out: - read_unlock_irqrestore(&dom->streams_lock, flags); - return common; -} - -static void apple_dart_apif_iotlb_sync(struct iommu_domain *domain, - struct iommu_iotlb_gather *gather) -{ - /* apif invalidates inside every MAP/UNMAP it forwards to SPTM, so a - * separate flush is a no-op. - */ -} - -static phys_addr_t apple_dart_apif_iova_to_phys(struct iommu_domain *domain, - dma_addr_t iova) -{ - struct apple_dart_apif_domain *dom = to_apif_domain(domain); - void *entry = xa_load(&dom->mappings, iova >> DART_APIF_PAGE_SHIFT); - unsigned long value = entry ? xa_to_value(entry) : 0; - - if (!value) - return apif_retained_translate(dom, iova); - return ((value >> APIF_MAP_PROT_BITS) << DART_APIF_PAGE_SHIFT) | - (iova & (DART_APIF_PAGE_SIZE - 1)); -} - -static void apple_dart_apif_domain_free(struct iommu_domain *domain) -{ - struct apple_dart_apif_domain *dom = to_apif_domain(domain); - - if (dom->has_retained) { - for (unsigned int i = 0; i < dom->num_darts; i++) { - struct apif_stream_map *stream = &dom->streams[i]; - unsigned int sid; - unsigned long flags; - - spin_lock_irqsave(&stream->dart->batch_lock, flags); - for_each_set_bit(sid, stream->sids, - stream->dart->num_streams) - apif_undo_replay(dom, stream, sid, U64_MAX); - spin_unlock_irqrestore(&stream->dart->batch_lock, - flags); - } - } - xa_destroy(&dom->l2_attached); - xa_destroy(&dom->mappings); - kfree(dom); -} - -static struct iommu_domain * -apple_dart_apif_domain_alloc_paging(struct device *dev) -{ - struct apple_dart_apif_domain *dom; - int ret; - - dom = kzalloc_obj(*dom); - if (!dom) - return NULL; - mutex_init(&dom->lock); - rwlock_init(&dom->streams_lock); - xa_init(&dom->l2_attached); - xa_init(&dom->mappings); - dom->domain.pgsize_bitmap = DART_APIF_PAGE_SIZE; - dom->domain.geometry.aperture_end = DART_APIF_APERTURE_END; - dom->domain.geometry.force_aperture = true; - if (dev && dev_iommu_priv_get(dev)) { - ret = apif_domain_configure(dom, dev_iommu_priv_get(dev)); - if (ret) { - kfree(dom); - return ERR_PTR(ret); - } - } - return &dom->domain; -} - -/* - * The core attaches this before release_device(), so a released device no - * longer uses the domain that is about to be freed. Its SIDs leave that - * domain disabled, with the domain's mappings undone, as an attach unwind - * does. Without it the SIDs stayed enabled on the freed domain's tables, and - * the next attach of the same SIDs met that stale state. Retained SIDs keep - * their current handling. - */ -static int apple_dart_apif_release_attach(struct iommu_domain *domain, - struct device *dev, - struct iommu_domain *old) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - struct apple_dart_apif_domain *prior; - unsigned long flags; - unsigned int sid; - - if (!master || !old || old->owner != &apple_dart_apif_ops || - old->ops != apple_dart_apif_ops.default_domain_ops) - return 0; - prior = to_apif_domain(old); - mutex_lock(&prior->lock); - write_lock_irqsave(&prior->streams_lock, flags); - for (unsigned int i = 0; i < master->num_darts; i++) { - struct apple_dart_apif *dart = master->streams[i].dart; - struct apif_stream_map *before = apif_find_stream(prior, dart); - - if (!before) - continue; - spin_lock(&dart->batch_lock); - for_each_set_bit(sid, master->streams[i].sids, - dart->num_streams) { - if (dart->retained[sid] || !test_bit(sid, before->sids)) - continue; - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ - .op = APIF_DART_DISABLE, - .arg = { sid }, - }; - if (apif_ring(dart)) - dev_err(dart->dev, - "failed to disable SID %u at release\n", - sid); - apif_undo_replay(prior, before, sid, U64_MAX); - clear_bit(sid, before->sids); - } - spin_unlock(&dart->batch_lock); - } - write_unlock_irqrestore(&prior->streams_lock, flags); - mutex_unlock(&prior->lock); - return 0; -} - -static struct iommu_domain apple_dart_apif_release_domain = { - .type = IOMMU_DOMAIN_BLOCKED, - .ops = &(const struct iommu_domain_ops){ - .attach_dev = apple_dart_apif_release_attach, - }, -}; - -static struct iommu_device *apple_dart_apif_probe_device(struct device *dev) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - - if (!dev_iommu_fwspec_get(dev) || !master || !master->num_darts) - return ERR_PTR(-ENODEV); - for (unsigned int i = 0; i < master->num_darts; i++) - device_link_add(dev, master->streams[i].dart->dev, - DL_FLAG_PM_RUNTIME | - DL_FLAG_AUTOREMOVE_SUPPLIER); - return &master->streams[0].dart->iommu; -} - -static void apple_dart_apif_release_device(struct device *dev) -{ - kfree(dev_iommu_priv_get(dev)); -} - -static int apple_dart_apif_of_xlate(struct device *dev, - const struct of_phandle_args *args) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - struct platform_device *iommu_pdev; - struct apple_dart_apif *dart; - u32 sid; - - if (args->args_count != 1) - return -EINVAL; - sid = args->args[0]; - if (sid >= DART_APIF_MAX_STREAMS) - return -EINVAL; - - iommu_pdev = of_find_device_by_node(args->np); - if (!iommu_pdev) - return -ENODEV; - dart = platform_get_drvdata(iommu_pdev); - put_device(&iommu_pdev->dev); - if (!dart) - return -ENODEV; - - if (sid >= dart->num_streams) - return -EINVAL; - if (!master) { - master = kzalloc_obj(*master); - if (!master) - return -ENOMEM; - dev_iommu_priv_set(dev, master); - } - for (unsigned int i = 0; i < master->num_darts; i++) { - if (master->streams[i].dart == dart) { - set_bit(sid, master->streams[i].sids); - return 0; - } - } - if (master->num_darts == APIF_MAX_DARTS) - return -EINVAL; - master->streams[master->num_darts].dart = dart; - set_bit(sid, master->streams[master->num_darts].sids); - master->num_darts++; - return 0; -} - -/* Devices sharing a stream cannot have independent IOVA allocators. PCI - * multifunction/topology grouping is also required even with distinct SIDs. - * Mirrors the native Apple DART lifetime model: the group owns its SID union, - * and its release callback clears the reverse lookup before freeing it. - */ -static DEFINE_MUTEX(apple_dart_apif_groups_lock); - -static void apple_dart_apif_release_group(void *data) -{ - struct apple_dart_apif_master *group_master = data; - unsigned int sid; - - mutex_lock(&apple_dart_apif_groups_lock); - for (unsigned int i = 0; i < group_master->num_darts; i++) { - struct apif_stream_map *stream = &group_master->streams[i]; - - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) - stream->dart->sid2group[sid] = NULL; - } - mutex_unlock(&apple_dart_apif_groups_lock); - kfree(group_master); -} - -static int apif_merge_master(struct apple_dart_apif_master *dst, - const struct apple_dart_apif_master *src) -{ - struct apple_dart_apif_master merged = *dst; - - for (unsigned int i = 0; i < src->num_darts; i++) { - const struct apif_stream_map *from = &src->streams[i]; - unsigned int j; - - for (j = 0; j < merged.num_darts; j++) - if (merged.streams[j].dart == from->dart) - break; - if (j == merged.num_darts) { - if (j == APIF_MAX_DARTS) - return -EINVAL; - merged.streams[j] = *from; - merged.num_darts++; - } else { - bitmap_or(merged.streams[j].sids, - merged.streams[j].sids, from->sids, - from->dart->num_streams); - } - } - *dst = merged; - return 0; -} - -static struct iommu_group *apple_dart_apif_device_group(struct device *dev) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - struct apple_dart_apif_master *group_master; - struct iommu_group *group = NULL, *put_group = NULL; - struct iommu_group *result = ERR_PTR(-EINVAL); - unsigned int sid; - - if (!master || !master->num_darts) - return result; - mutex_lock(&apple_dart_apif_groups_lock); - for (unsigned int i = 0; i < master->num_darts; i++) { - struct apif_stream_map *stream = &master->streams[i]; - - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) { - struct iommu_group *existing = - stream->dart->sid2group[sid]; - - if (!existing) - continue; - if (group && existing != group) - goto out; - group = existing; - } - } - if (group) { - group = iommu_group_ref_get(group); - } else { -#ifdef CONFIG_PCI - if (dev_is_pci(dev)) - group = pci_device_group(dev); - else -#endif - group = generic_device_group(dev); - } - if (IS_ERR(group)) { - result = group; - goto out; - } - if (!group) { - result = ERR_PTR(-ENOMEM); - goto out; - } - group_master = iommu_group_get_iommudata(group); - if (!group_master) { - group_master = kmemdup(master, sizeof(*master), GFP_KERNEL); - if (!group_master) { - result = ERR_PTR(-ENOMEM); - put_group = group; - goto out; - } - iommu_group_set_iommudata(group, group_master, - apple_dart_apif_release_group); - } else if (apif_merge_master(group_master, master)) { - put_group = group; - goto out; - } - for (unsigned int i = 0; i < master->num_darts; i++) { - struct apif_stream_map *stream = &master->streams[i]; - - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) - stream->dart->sid2group[sid] = group; - } - result = group; -out: - mutex_unlock(&apple_dart_apif_groups_lock); - /* Dropping the last reference can invoke release_group: do it unlocked. */ - if (put_group) - iommu_group_put(put_group); - return result; -} - -static bool apple_dart_apif_capable(struct device *dev, enum iommu_cap cap) -{ - return cap == IOMMU_CAP_CACHE_COHERENCY; -} - -/* PCIe captures the MSI doorbell before DART translation. Advertise the - * identity MSI page to the DMA layer so it never tries to map this non-RAM - * address through the SPTM transport. Other devices retain normal reservations. - * This follows apple-dart.c's hardware MSI reservation (Asahi contributors). - */ -static void apple_dart_apif_get_resv_regions(struct device *dev, - struct list_head *head) -{ - struct apple_dart_apif_master *master = dev_iommu_priv_get(dev); - unsigned int sid; - - for (unsigned int i = 0; master && i < master->num_darts; i++) { - struct apif_stream_map *stream = &master->streams[i]; - - /* Reserve the exclusive-end granule when required by the aperture. - * Narrower native apertures declare that restriction in DT. - */ - if (stream->dart->dma_max == DART_APIF_NATIVE_APERTURE_END || - stream->dart->reserve_last_page) { - struct iommu_resv_region *region = - iommu_alloc_resv_region( - stream->dart->dma_max + 1 - - DART_APIF_PAGE_SIZE, - DART_APIF_PAGE_SIZE, 0, - IOMMU_RESV_RESERVED, GFP_KERNEL); - - if (region) - list_add_tail(®ion->list, head); - } - for_each_set_bit(sid, stream->sids, stream->dart->num_streams) { - struct apif_retained_sid *r = - stream->dart->retained[sid]; - if (!r) - continue; - for (unsigned int i = 0; i < r->count; i++) { - struct iommu_resv_region *region = - iommu_alloc_resv_region( - r->runs[i].dva, r->runs[i].size, - 0, IOMMU_RESV_RESERVED, - GFP_KERNEL); - if (region) - list_add_tail(®ion->list, head); - } - } - } - if (dev_is_pci(dev)) { - struct pci_host_bridge *bridge = - pci_find_host_bridge(to_pci_dev(dev)->bus); - struct device_node *np = bridge->dev.parent->of_node; - struct iommu_resv_region *region; - u64 address; - - if (of_device_is_compatible(np, "apple,apif-pcie") && - !of_property_read_u64(np, "apple,msi-address", &address)) { - region = iommu_alloc_resv_region( - address & PAGE_MASK, PAGE_SIZE, - IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO, - IOMMU_RESV_MSI, GFP_KERNEL); - if (region) - list_add_tail(®ion->list, head); - } - } - iommu_dma_get_resv_regions(dev, head); -} - -static const struct iommu_ops apple_dart_apif_ops = { - .get_resv_regions = apple_dart_apif_get_resv_regions, - .capable = apple_dart_apif_capable, - .domain_alloc_paging = apple_dart_apif_domain_alloc_paging, - .probe_device = apple_dart_apif_probe_device, - .release_device = apple_dart_apif_release_device, - .release_domain = &apple_dart_apif_release_domain, - .device_group = apple_dart_apif_device_group, - .of_xlate = apple_dart_apif_of_xlate, - .owner = THIS_MODULE, - .default_domain_ops = - &(const struct iommu_domain_ops){ - .attach_dev = apple_dart_apif_attach_dev, - .map_pages = apple_dart_apif_map_pages, - .unmap_pages = apple_dart_apif_unmap_pages, - .iotlb_sync = apple_dart_apif_iotlb_sync, - .iova_to_phys = apple_dart_apif_iova_to_phys, - .free = apple_dart_apif_domain_free, - }, -}; - -/* Used only after the PCI host has stopped every endpoint on this DART. - * Native POWERDOWN/POWERUP retains the SPTM-owned tables and live mappings. - */ -static int apif_other_group_device(struct device *member, void *data) -{ - return member == data ? 0 : -EBUSY; -} - -int apple_dart_apif_set_power(struct device *dev, bool on) -{ - struct apple_dart_apif_master *master; - struct apple_dart_apif *dart; - struct iommu_group *group; - unsigned long flags; - int ret; - - if (!dev->iommu || !dev->iommu->iommu_dev || - dev->iommu->iommu_dev->ops != &apple_dart_apif_ops) - return -ENODEV; - master = dev_iommu_priv_get(dev); - if (!master || master->num_darts != 1) - return -ENODEV; - dart = master->streams[0].dart; - group = iommu_group_get(dev); - if (!group) - return -ENODEV; - ret = iommu_group_for_each_dev(group, dev, apif_other_group_device); - if (ret) - goto put_group; - mutex_lock(&apple_dart_apif_groups_lock); - /* Native DISABLE affects the entire unit. Retained firmware streams or - * another Linux group must never be stopped by one endpoint's reset. - */ - for (unsigned int sid = 0; sid < dart->num_streams; sid++) { - if (dart->retained[sid] || - (dart->sid2group[sid] && dart->sid2group[sid] != group)) { - ret = -EBUSY; - goto unlock_groups; - } - } - mutex_lock(&dart->init_lock); - if (!dart->inited || dart->ownership_uncertain) { - ret = -EINVAL; - goto out; - } - spin_lock_irqsave(&dart->batch_lock, flags); - dart->batch->count = 1; - dart->batch->op[0] = (struct apif_op){ .op = on ? 7 : 8 }; - ret = apif_ring(dart); - spin_unlock_irqrestore(&dart->batch_lock, flags); -out: - mutex_unlock(&dart->init_lock); -unlock_groups: - mutex_unlock(&apple_dart_apif_groups_lock); -put_group: - iommu_group_put(group); - return ret; -} -EXPORT_SYMBOL_GPL(apple_dart_apif_set_power); - -static int apple_dart_apif_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct apple_dart_apif *dart; - int ret; - - dart = devm_kzalloc(dev, sizeof(*dart), GFP_KERNEL); - if (!dart) - return -ENOMEM; - - dart->dev = dev; - mutex_init(&dart->init_lock); - spin_lock_init(&dart->batch_lock); - - dart->apif = aurora_apif_get(dev); - if (IS_ERR(dart->apif)) - return dev_err_probe(dev, PTR_ERR(dart->apif), - "APIF transport unavailable\n"); - ret = devm_add_action_or_reset(dev, apif_put_transport, dart->apif); - if (ret) - return ret; - dart->native_ops = devm_kcalloc(dev, 2 * APIF_BATCH_MAX_OPS, - sizeof(*dart->native_ops), GFP_KERNEL); - if (!dart->native_ops) - return -ENOMEM; - dart->boot_info = - devm_kzalloc(dev, sizeof(*dart->boot_info), GFP_KERNEL); - if (!dart->boot_info) - return -ENOMEM; - if (of_property_read_u32(dev->of_node, "apple,apif-dart-id", - &dart->dart_id)) - return dev_err_probe(dev, -EINVAL, - "missing apple,apif-dart-id\n"); - if (dart->dart_id > 0xff) - return dev_err_probe(dev, -EINVAL, "dart-id out of range\n"); - - dart->dma_max = DART_APIF_APERTURE_END; - if (of_find_property(dev->of_node, "apple,dma-range", NULL)) { - u64 range[2], end; - - if (of_property_read_u64_array(dev->of_node, "apple,dma-range", - range, 2) || - !range[1] || - (range[0] | range[1]) & (DART_APIF_PAGE_SIZE - 1) || - check_add_overflow(range[0], range[1] - 1, &end) || - end > DART_APIF_NATIVE_APERTURE_END) - return dev_err_probe(dev, -EINVAL, "bad DMA range\n"); - dart->dma_min = range[0]; - dart->dma_max = end; - } - if (of_find_property(dev->of_node, "apple,apif-iova-force", NULL)) { - if (of_property_read_u64(dev->of_node, "apple,apif-iova-force", - &dart->iova_force) || - (dart->iova_force && dart->iova_force != BIT_ULL(40))) - return dev_err_probe(dev, -EINVAL, - "unsupported IOVA force mask\n"); - /* A native DVA aperture already contains its high address bits. - * Hidden force bits are only valid for the low-address device view. - */ - if (dart->iova_force && dart->dma_max >= dart->iova_force) - return dev_err_probe( - dev, -EINVAL, - "IOVA force overlaps DMA aperture\n"); - } - - dart->reserve_last_page = of_property_read_bool( - dev->of_node, "apple,apif-reserve-last-page"); - dart->num_streams = DART_APIF_MAX_STREAMS; - of_property_read_u32(dev->of_node, "apple,apif-num-streams", - &dart->num_streams); - if (!dart->num_streams || dart->num_streams > DART_APIF_MAX_STREAMS) - return dev_err_probe(dev, -EINVAL, "bad stream count\n"); - - dart->batch = devm_kzalloc(dev, PAGE_SIZE, GFP_KERNEL); - if (!dart->batch) - return -ENOMEM; - ret = apif_load_retained(dart); - if (ret) - return dev_err_probe(dev, ret, - "retained DART discovery failed\n"); - ret = apif_load_boot_mappings(dart); - if (ret) - return dev_err_probe(dev, ret, "invalid boot DMA mappings\n"); - - ret = devm_add_action_or_reset(dev, apif_free_page_lists, dart); - if (ret) - return ret; - platform_set_drvdata(pdev, dart); - - ret = iommu_device_sysfs_add(&dart->iommu, dev, NULL, - "apple-dart-apif.%s", dev_name(dev)); - if (ret) - return ret; - - ret = iommu_device_register(&dart->iommu, &apple_dart_apif_ops, dev); - if (ret) - goto err_sysfs; - - return 0; - -err_sysfs: - iommu_device_sysfs_remove(&dart->iommu); - return ret; -} - -static void apple_dart_apif_remove(struct platform_device *pdev) -{ - struct apple_dart_apif *dart = platform_get_drvdata(pdev); - - iommu_device_unregister(&dart->iommu); - iommu_device_sysfs_remove(&dart->iommu); -} - -static const struct of_device_id apple_dart_apif_of_match[] = { - { .compatible = "apple,dart-apif" }, - {}, -}; -MODULE_DEVICE_TABLE(of, apple_dart_apif_of_match); - -static struct platform_driver apple_dart_apif_driver = { - .driver = { - .name = "apple-dart-apif", - .suppress_bind_attrs = true, - .of_match_table = apple_dart_apif_of_match, - }, - .probe = apple_dart_apif_probe, - .remove = apple_dart_apif_remove, -}; -module_platform_driver(apple_dart_apif_driver); - -MODULE_DESCRIPTION("Apple DART IOMMU over the Aurora platform interface"); -MODULE_LICENSE("GPL"); diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index dbf3bff72cadd..113e09aea5c47 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -116,16 +116,6 @@ config APPLE_SART Say 'y' here if you have an Apple SoC. -config APPLE_SART_APIF - bool "Apple SART over the Aurora platform interface" - depends on ARM64 && OF && APPLE_SART=y - select AURORA_APIF_MMIO - help - SART provider for a trusted Linux guest under Aura and SPTM. - Consumers retain the existing Apple SART API. Native call selection, - region tracking and completion interpretation stay in this backend. - Existing raw-MMIO SART providers continue to serve other systems. - config APPLE_TUNABLE tristate depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 9ab327c4ec817..5ef85752f160d 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -61,5 +61,3 @@ obj-$(CONFIG_APPLE_CLPC) += clpc.o obj-$(CONFIG_APPLE_REGVIEW) += apple-regview.o apple-regview-y := regview.o - -obj-$(CONFIG_APPLE_SART_APIF) += apple-sart-apif.o diff --git a/drivers/soc/apple/apple-sart-apif.c b/drivers/soc/apple/apple-sart-apif.c deleted file mode 100644 index 3bbdaea969840..0000000000000 --- a/drivers/soc/apple/apple-sart-apif.c +++ /dev/null @@ -1,167 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* SART policy stays in Linux; native table-5 calls use the common APIF client. */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sart-backend.h" - -#define SART_APIF_MAX_REGIONS 16 - -struct sart_apif { - struct device *dev; - struct aurora_apif *apif; - struct mutex lock; - bool active; - struct { - phys_addr_t address; - size_t size; - } regions[SART_APIF_MAX_REGIONS]; -}; - -static int sart_apif_region(struct apple_sart *sart, phys_addr_t address, - size_t size, bool map) -{ - struct sart_apif *state = apple_sart_backend_data(sart); - struct aurora_apif_op op; - u64 pa; - int i, ret; - - if (!size || ((address | size) & (SZ_16K - 1)) || - address > PHYS_ADDR_MAX - (size - 1)) - return -EINVAL; - mutex_lock(&state->lock); - for (i = 0; i < SART_APIF_MAX_REGIONS; i++) - if (map ? !state->regions[i].size : - state->regions[i].address == address && - state->regions[i].size == size) - break; - if (i == SART_APIF_MAX_REGIONS) { - ret = map ? -EBUSY : -ENOENT; - goto out; - } - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, - AURORA_APIF_TRANSLATE), - .arg = { dma_to_phys(state->dev, address), size }, - }; - ret = aurora_apif_submit(state->apif, &op, 1, NULL); - if (ret) - goto out; - pa = op.ret; - if (!state->active) { - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR( - 5, 0), /* SET_STATE, void result */ - .arg = { 1 }, - }; - ret = aurora_apif_submit(state->apif, &op, 1, NULL); - if (ret) - goto out; - state->active = true; - } - op = (struct aurora_apif_op){ - .selector = AURORA_APIF_SELECTOR(5, map ? 1 : 2), - .arg = { pa, size, map, map }, - }; - ret = aurora_apif_submit(state->apif, &op, 1, NULL); - /* MAP is void; UNMAP returns status. A refused unmap keeps the region - * live so the consumer cannot treat its DMA backing as released. - */ - if (!ret && !map && op.ret) - ret = -EIO; - if (!ret) { - state->regions[i].address = map ? address : 0; - state->regions[i].size = map ? size : 0; - } -out: - mutex_unlock(&state->lock); - return ret; -} - -static int sart_apif_add(struct apple_sart *sart, phys_addr_t address, - size_t size) -{ - return sart_apif_region(sart, address, size, true); -} - -static int sart_apif_remove(struct apple_sart *sart, phys_addr_t address, - size_t size) -{ - return sart_apif_region(sart, address, size, false); -} - -static const struct apple_sart_backend sart_apif_backend = { - .add = sart_apif_add, - .remove = sart_apif_remove, -}; - -static void sart_apif_put(void *data) -{ - aurora_apif_put(data); -} - -static int sart_apif_probe(struct platform_device *pdev) -{ - struct device *dev = &pdev->dev; - struct sart_apif *state; - struct apple_sart *sart; - int ret; - - state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL); - if (!state) - return -ENOMEM; - state->dev = dev; - mutex_init(&state->lock); - state->apif = aurora_apif_get(dev); - if (IS_ERR(state->apif)) - return dev_err_probe(dev, PTR_ERR(state->apif), - "APIF transport unavailable\n"); - ret = devm_add_action_or_reset(dev, sart_apif_put, state->apif); - if (ret) - return ret; - sart = apple_sart_create_backend(dev, &sart_apif_backend, state); - if (IS_ERR(sart)) - return PTR_ERR(sart); - platform_set_drvdata(pdev, sart); - return 0; -} - -static void sart_apif_shutdown(struct platform_device *pdev) -{ - struct apple_sart *sart = platform_get_drvdata(pdev); - struct sart_apif *state = apple_sart_backend_data(sart); - - /* Supplier ordering stops consumers before their Linux-owned grants. */ - for (unsigned int i = 0; i < SART_APIF_MAX_REGIONS; i++) - if (state->regions[i].size && - sart_apif_remove(sart, state->regions[i].address, - state->regions[i].size)) - dev_err(state->dev, - "failed to release DMA region at shutdown\n"); -} - -static const struct of_device_id sart_apif_of_match[] = { - { .compatible = "apple,sart-apif" }, - {} -}; -MODULE_DEVICE_TABLE(of, sart_apif_of_match); - -static struct platform_driver sart_apif_driver = { - .driver = { - .name = "apple-sart-apif", - .of_match_table = sart_apif_of_match, - .suppress_bind_attrs = true, - }, - .probe = sart_apif_probe, - .shutdown = sart_apif_shutdown, -}; -module_platform_driver(sart_apif_driver); - -MODULE_DESCRIPTION("Apple SART over the Aurora platform interface"); -MODULE_LICENSE("GPL"); diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 6cfc08e15fce2..f4f674f548c5d 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -1688,15 +1688,6 @@ static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_j775d_ascwr APPLE_J775D_GFX1_WRAPPER_BASE, APPLE_J775D_GFX1_IOP_VBAR_BASE }, }; -static const struct apple_mbox_ascwrap_v6_role_desc apple_mbox_t6050_apif_ascwrap_v6_roles[] = { - { "GFX", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX, - APPLE_T8140_GFX_WRAPPER_BASE, - APPLE_T8140_GFX_IOP_VBAR_BASE + APPLE_T6050_ASCWRAP_BASE_DELTA }, - { "GFX1", APPLE_MBOX_ASCWRAP_V6_ROLE_GFX1, - APPLE_T8140_GFX1_WRAPPER_BASE, - APPLE_T8140_GFX1_IOP_VBAR_BASE + APPLE_T6050_ASCWRAP_BASE_DELTA }, -}; - static const struct apple_mbox_hw apple_mbox_t6050_ascwrap_v6_hw = { .reg_offset = APPLE_ASCWRAP_V6_MBOX_OFFSET, .is_ascwrap_v6 = true, @@ -1729,23 +1720,6 @@ static const struct apple_mbox_hw apple_mbox_t6050_j775d_ascwrap_v6_hw = { .has_irq_controls = false, }; -/* Retained compatibility profile: unshifted wrapper aliases, native VBAR. */ -static const struct apple_mbox_hw apple_mbox_t6050_apif_ascwrap_v6_hw = { - .reg_offset = APPLE_ASCWRAP_V6_MBOX_OFFSET, - .is_ascwrap_v6 = true, - .ascwrap_v6_roles = apple_mbox_t6050_apif_ascwrap_v6_roles, - .num_ascwrap_v6_roles = ARRAY_SIZE(apple_mbox_t6050_apif_ascwrap_v6_roles), - .control_full = APPLE_ASC_MBOX_CONTROL_FULL, - .control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY, - .a2i_control = APPLE_ASC_MBOX_A2I_CONTROL, - .a2i_send0 = APPLE_ASC_MBOX_A2I_SEND0, - .a2i_send1 = APPLE_ASC_MBOX_A2I_SEND1, - .i2a_control = APPLE_ASC_MBOX_I2A_CONTROL, - .i2a_recv0 = APPLE_ASC_MBOX_I2A_RECV0, - .i2a_recv1 = APPLE_ASC_MBOX_I2A_RECV1, - .has_irq_controls = false, -}; - /* * T8152 SMC post-office mailbox: counted FIFOs share the status register. * Interrupt masking is provided by the interrupt controller, not the mailbox. @@ -1771,7 +1745,6 @@ static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t6040-ascwrap-v6", .data = &apple_mbox_t6040_ascwrap_v6_hw }, { .compatible = "apple,t8140-ascwrap-v6", .data = &apple_mbox_t8140_ascwrap_v6_hw }, { .compatible = "apple,t8142-ascwrap-v6", .data = &apple_mbox_t8142_ascwrap_v6_hw }, - { .compatible = "apple,t6050-apif-ascwrap-v6", .data = &apple_mbox_t6050_apif_ascwrap_v6_hw }, { .compatible = "apple,t6050-ascwrap-v6", .data = &apple_mbox_t6050_ascwrap_v6_hw }, { .compatible = "apple,t6050-x1n1-ascwrap-v6", .data = &apple_mbox_t6050_ascwrap_v6_hw }, { .compatible = "apple,t6050-j775d-ascwrap-v6", diff --git a/drivers/soc/apple/sart-backend.h b/drivers/soc/apple/sart-backend.h deleted file mode 100644 index 8a130fa48ccba..0000000000000 --- a/drivers/soc/apple/sart-backend.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef APPLE_SART_BACKEND_H -#define APPLE_SART_BACKEND_H - -#include - -/* Alternate providers retain the existing consumer API. */ -struct apple_sart_backend { - int (*add)(struct apple_sart *sart, phys_addr_t address, size_t size); - int (*remove)(struct apple_sart *sart, phys_addr_t address, - size_t size); - bool (*inherited)(struct apple_sart *sart, phys_addr_t address, - size_t size); -}; - -struct apple_sart * -apple_sart_create_backend(struct device *dev, - const struct apple_sart_backend *backend, void *data); -void *apple_sart_backend_data(struct apple_sart *sart); - -#endif diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index 8270a5a731f2c..f9e79924e53a6 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -24,7 +24,6 @@ #include #include #include -#include "sart-backend.h" #define APPLE_SART_MAX_ENTRIES 16 @@ -91,33 +90,8 @@ struct apple_sart { unsigned long protected_entries; unsigned long used_entries; - const struct apple_sart_backend *backend; - void *backend_data; }; -struct apple_sart *apple_sart_create_backend(struct device *dev, - const struct apple_sart_backend *backend, void *data) -{ - struct apple_sart *sart; - - if (!backend || !backend->add || !backend->remove) - return ERR_PTR(-EINVAL); - sart = devm_kzalloc(dev, sizeof(*sart), GFP_KERNEL); - if (!sart) - return ERR_PTR(-ENOMEM); - sart->dev = dev; - sart->backend = backend; - sart->backend_data = data; - return sart; -} -EXPORT_SYMBOL_GPL(apple_sart_create_backend); - -void *apple_sart_backend_data(struct apple_sart *sart) -{ - return sart->backend_data; -} -EXPORT_SYMBOL_GPL(apple_sart_backend_data); - static void sart0_get_entry(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size) { @@ -304,8 +278,6 @@ bool apple_sart_is_inherited_region(struct apple_sart *sart, phys_addr_t paddr, { int i; - if (sart->backend) - return sart->backend->inherited && sart->backend->inherited(sart, paddr, size); if (!size || paddr > PHYS_ADDR_MAX - (size - 1)) return false; for (i = 0; i < APPLE_SART_MAX_ENTRIES; i++) { @@ -348,8 +320,6 @@ int apple_sart_add_allowed_region(struct apple_sart *sart, phys_addr_t paddr, { int i, ret; - if (sart->backend) - return sart->backend->add(sart, paddr, size); for (i = 0; i < APPLE_SART_MAX_ENTRIES; ++i) { if (test_bit(i, &sart->protected_entries)) continue; @@ -384,8 +354,6 @@ int apple_sart_remove_allowed_region(struct apple_sart *sart, phys_addr_t paddr, { int i; - if (sart->backend) - return sart->backend->remove(sart, paddr, size); dev_dbg(sart->dev, "will remove [paddr: %pa, size: 0x%zx] from allowed regions\n", &paddr, size); diff --git a/include/linux/apple-dart-apif.h b/include/linux/apple-dart-apif.h deleted file mode 100644 index 814b2a91aba94..0000000000000 --- a/include/linux/apple-dart-apif.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _LINUX_APPLE_DART_APIF_H -#define _LINUX_APPLE_DART_APIF_H -#include -#include -#include -#if IS_REACHABLE(CONFIG_APPLE_DART_APIF) -/* Caller must quiesce every device on this DART before powering it down. - * Tables and mappings survive the native SPTM power transition. - */ -int apple_dart_apif_set_power(struct device *dev, bool on); -#else -static inline int apple_dart_apif_set_power(struct device *dev, bool on) -{ - return -EOPNOTSUPP; -} -#endif -#endif diff --git a/include/linux/pci-apple-apif.h b/include/linux/pci-apple-apif.h deleted file mode 100644 index d3094cc976a8f..0000000000000 --- a/include/linux/pci-apple-apif.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _LINUX_PCI_APPLE_APIF_H -#define _LINUX_PCI_APPLE_APIF_H -#include -#include -struct pci_dev; -#if IS_REACHABLE(CONFIG_PCIE_APPLE_APIF) -/* Preboot N1 transition only, before radio function enumeration or DMA. */ -int apple_apif_pcie_cycle(struct pci_dev *pdev); -#else -static inline int apple_apif_pcie_cycle(struct pci_dev *pdev) -{ - return -EOPNOTSUPP; -} -#endif -#endif diff --git a/include/linux/soc/apple/display-event-debugfs.h b/include/linux/soc/apple/display-event-debugfs.h deleted file mode 100644 index 81322e64bf02f..0000000000000 --- a/include/linux/soc/apple/display-event-debugfs.h +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ -#ifndef _LINUX_APPLE_DISPLAY_EVENT_DEBUGFS_H -#define _LINUX_APPLE_DISPLAY_EVENT_DEBUGFS_H -#include -#include -#include -#include -#include -#include -#include - -static int apple_display_events_show(struct seq_file *s, void *unused) -{ - const struct apple_display_event_snapshot *p = s->private; - u32 i, j; - - seq_printf(s, "apple-display-events version=1 name=%s capacity=512 clock=mono_fast\n", p->name); - seq_printf(s, "snapshot ns=%llu/%llu seq=%llu/%llu count=%u copied=%u gaps=%u complete=%u\n", - p->start_ns, p->end_ns, p->seq_start, p->seq_end, - p->record_count, p->copied, p->gaps, p->complete); - seq_printf(s, "before committed=%llu attempts=%llu busy=%llu sequence=%llu overwritten=%llu\n", - p->start.committed, p->start.attempts, p->start.busy_drops, - p->start.sequence_drops, p->start.overwritten); - seq_printf(s, "after committed=%llu attempts=%llu busy=%llu sequence=%llu overwritten=%llu\n", - p->end.committed, p->end.attempts, p->end.busy_drops, - p->end.sequence_drops, p->end.overwritten); - for (i = 0; i < p->record_count; i++) { - const struct apple_display_event_record *r = &p->records[i]; - - if (!p->valid[i]) { - seq_printf(s, "gap index=%u\n", i); - continue; - } - seq_printf(s, "event seq=%llu ns=%llu type=%u flags=%#x result=%d data=", - r->sequence, r->timestamp_ns, r->type, r->flags, r->result); - for (j = 0; j < 9; j++) - seq_printf(s, "%s%016llx", j ? "," : "", r->data[j]); - seq_putc(s, '\n'); - } - return 0; -} - -static int apple_display_events_open(struct inode *inode, struct file *file) -{ - struct apple_display_event_snapshot *snapshot; - struct dentry *dentry = file->f_path.dentry; - int ret; - - /* No owner pointer is read until debugfs removal protection is held. */ - snapshot = kvzalloc(sizeof(*snapshot), GFP_KERNEL); - if (!snapshot) - return -ENOMEM; - ret = debugfs_file_get(dentry); - if (ret) - goto free; - ret = apple_display_event_snapshot_copy(inode->i_private, snapshot); - debugfs_file_put(dentry); - if (ret) - goto free; - /* Only standalone bytes remain: formatting may outlive the device. */ - ret = single_open(file, apple_display_events_show, snapshot); - if (ret) - goto free; - return 0; -free: - kvfree(snapshot); - return ret; -} - -static int apple_display_events_release(struct inode *inode, struct file *file) -{ - struct seq_file *s = file->private_data; - - kvfree(s->private); - return single_release(inode, file); -} - -static const struct file_operations apple_display_events_fops = { - .owner = THIS_MODULE, - .open = apple_display_events_open, - .read = seq_read, - .llseek = seq_lseek, - .release = apple_display_events_release, -}; -#endif diff --git a/include/linux/soc/apple/display-event-log.h b/include/linux/soc/apple/display-event-log.h deleted file mode 100644 index 9d7cdee5c7551..0000000000000 --- a/include/linux/soc/apple/display-event-log.h +++ /dev/null @@ -1,213 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _LINUX_SOC_APPLE_DISPLAY_EVENT_LOG_H -#define _LINUX_SOC_APPLE_DISPLAY_EVENT_LOG_H - -#include -#include -#include -#include -#include -#include -#include - -#define APPLE_DISPLAY_EVENT_CAPACITY 512U -#define APPLE_DISPLAY_EVENT_CHUNK 8U -#define APPLE_DISPLAY_EVENT_SCHEMA 1U - -struct apple_display_event_record { - u64 timestamp_ns; - u64 sequence; - u16 type; - u16 flags; - s32 result; - u64 data[9]; -}; -static_assert(sizeof(struct apple_display_event_record) == 96); - -/* Atomics count attempted calls, including callers which cannot take lock. */ -struct apple_display_event_log { - raw_spinlock_t lock; - char name[64]; - atomic64_t attempts; - atomic64_t busy_drops; - atomic64_t sequence_drops; - u64 committed; - struct apple_display_event_record records[APPLE_DISPLAY_EVENT_CAPACITY]; -}; - -/* Atomic counters are individually sampled, not one atomic transaction. */ -struct apple_display_event_counters { - u64 committed; - u64 attempts; - u64 busy_drops; - u64 sequence_drops; - u64 overwritten; -}; - -/* Standalone storage: no device, ring, lock or callback pointer survives copy. */ -struct apple_display_event_snapshot { - char name[64]; - struct apple_display_event_counters start; - struct apple_display_event_counters end; - u64 seq_start; - u64 seq_end; - u64 start_ns; - u64 end_ns; - u32 record_count; - u32 copied; - u32 gaps; - bool complete; - u8 valid[APPLE_DISPLAY_EVENT_CAPACITY]; - struct apple_display_event_record records[APPLE_DISPLAY_EVENT_CAPACITY]; -}; - -/* Owner allocates/initializes before publishing, and quiesces before freeing. */ -static inline void apple_display_event_log_init(struct apple_display_event_log *log, - const char *name) -{ - memset(log, 0, sizeof(*log)); - raw_spin_lock_init(&log->lock); - atomic64_set(&log->attempts, 0); - atomic64_set(&log->busy_drops, 0); - atomic64_set(&log->sequence_drops, 0); - strscpy(log->name, name, sizeof(log->name)); -} - -static inline void __apple_display_event_record(struct apple_display_event_log *log, - u16 type, s32 result, u16 flags, - const u64 data[9]) -{ - struct apple_display_event_record *record; - unsigned long irqflags; - u64 sequence; - - atomic64_inc(&log->attempts); - if (!raw_spin_trylock_irqsave(&log->lock, irqflags)) { - atomic64_inc(&log->busy_drops); - return; - } - /* Never wrap to sequence zero or relabel old records after exhaustion. */ - if (log->committed == ~(u64)0) { - atomic64_inc(&log->sequence_drops); - raw_spin_unlock_irqrestore(&log->lock, irqflags); - return; - } - sequence = log->committed + 1; - record = &log->records[(sequence - 1) % APPLE_DISPLAY_EVENT_CAPACITY]; - record->timestamp_ns = ktime_get_mono_fast_ns(); - record->sequence = sequence; - record->type = type; - record->flags = flags; - record->result = result; - memcpy(record->data, data, sizeof(record->data)); - log->committed = sequence; - raw_spin_unlock_irqrestore(&log->lock, irqflags); -} - -/* Disabled means no payload evaluation, clock read, lock or counter access. - * Payload expressions must still be POD observations, never hardware helpers. - */ -#define APPLE_DISPLAY_EVENT_RECORD(log_, type_, result_, flags_, \ - a_, b_, c_, d_, e_, f_, g_, h_, i_) do { \ - struct apple_display_event_log *__event_log = (log_); \ - if (__event_log) { \ - const u64 __event_data[9] = { (a_), (b_), (c_), (d_), (e_), \ - (f_), (g_), (h_), (i_) }; \ - __apple_display_event_record(__event_log, (type_), (result_), \ - (flags_), __event_data); \ - } \ -} while (0) - -/* Caller holds the recorder lock; no hardware or owner state is accessed. */ -static inline void __apple_display_event_counters(struct apple_display_event_log *log, - struct apple_display_event_counters *out) -{ - out->committed = log->committed; - out->attempts = (u64)atomic64_read(&log->attempts); - out->busy_drops = (u64)atomic64_read(&log->busy_drops); - out->sequence_drops = (u64)atomic64_read(&log->sequence_drops); - out->overwritten = log->committed > APPLE_DISPLAY_EVENT_CAPACITY ? - log->committed - APPLE_DISPLAY_EVENT_CAPACITY : 0; -} - -/* Allocate snapshot before acquiring any owner reference/lock. EAGAIN is not - * retried here: a reader must never spin waiting for a producer or vice versa. - */ -static inline int apple_display_event_snapshot_begin(struct apple_display_event_log *log, - struct apple_display_event_snapshot *out) -{ - unsigned long irqflags; - - memset(out, 0, sizeof(*out)); - out->start_ns = ktime_get_mono_fast_ns(); - if (!raw_spin_trylock_irqsave(&log->lock, irqflags)) - return -EAGAIN; - memcpy(out->name, log->name, sizeof(out->name)); - __apple_display_event_counters(log, &out->start); - out->seq_end = log->committed; - out->record_count = log->committed < APPLE_DISPLAY_EVENT_CAPACITY ? - log->committed : APPLE_DISPLAY_EVENT_CAPACITY; - out->seq_start = out->record_count ? - out->seq_end - out->record_count + 1 : 0; - raw_spin_unlock_irqrestore(&log->lock, irqflags); - return 0; -} - -/* Return 1 for more chunks, 0 when complete, or EAGAIN without blocking. - * The fixed begin bounds never expand to include later writes. Each requested - * sequence is checked under lock; an overwrite is explicitly retained as a gap. - */ -static inline int apple_display_event_snapshot_next(struct apple_display_event_log *log, - struct apple_display_event_snapshot *out) -{ - unsigned long irqflags; - u32 limit, i; - bool finished; - - if (out->complete) - return 0; - if (!raw_spin_trylock_irqsave(&log->lock, irqflags)) - return -EAGAIN; - limit = out->record_count - out->copied; - if (limit > APPLE_DISPLAY_EVENT_CHUNK) - limit = APPLE_DISPLAY_EVENT_CHUNK; - for (i = 0; i < limit; i++) { - u32 index = out->copied++; - u64 sequence = out->seq_start + index; - struct apple_display_event_record *source = - &log->records[(sequence - 1) % APPLE_DISPLAY_EVENT_CAPACITY]; - - if (source->sequence == sequence) { - out->records[index] = *source; - out->valid[index] = 1; - } else { - /* Cleared by begin: do not expose the replacement payload. */ - out->records[index].sequence = sequence; - out->gaps++; - } - } - finished = out->copied == out->record_count; - if (finished) - __apple_display_event_counters(log, &out->end); - raw_spin_unlock_irqrestore(&log->lock, irqflags); - if (finished) { - out->end_ns = ktime_get_mono_fast_ns(); - out->complete = true; - } - return finished ? 0 : 1; -} - -static inline int apple_display_event_snapshot_copy(struct apple_display_event_log *log, - struct apple_display_event_snapshot *out) -{ - int ret = apple_display_event_snapshot_begin(log, out); - - if (ret) - return ret; - do { - ret = apple_display_event_snapshot_next(log, out); - } while (ret > 0); - return ret; -} - -#endif /* _LINUX_SOC_APPLE_DISPLAY_EVENT_LOG_H */ diff --git a/include/linux/soc/aurora/apif-mmio.h b/include/linux/soc/aurora/apif-mmio.h deleted file mode 100644 index fbf865f3a24c6..0000000000000 --- a/include/linux/soc/aurora/apif-mmio.h +++ /dev/null @@ -1,66 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _LINUX_SOC_AURORA_APIF_MMIO_H -#define _LINUX_SOC_AURORA_APIF_MMIO_H - -#include -#include -#include - -struct device; -struct aurora_apif; - -#define AURORA_APIF_SELECTOR(table, endpoint) \ - (((u64)(table) << 32) | (endpoint)) -#define AURORA_APIF_SERVICE 0xffffffffU -#define AURORA_APIF_TRANSLATE 1 -#define AURORA_APIF_ALLOC_FRAME 2 -#define AURORA_APIF_FREE_FRAME 3 -#define AURORA_APIF_MAP_IO 4 -#define AURORA_APIF_GUEST_ROOT 5 -#define AURORA_APIF_BOOT_IOMMU 6 -#define AURORA_APIF_BOOT_TABLE 7 -#define AURORA_APIF_FIND_FRAME 8 -#define AURORA_APIF_TAG_FRAME 9 -#define AURORA_APIF_BOOT_DART 0 - -struct aurora_apif_op { - u64 selector; - u64 arg[6]; - u64 ret; -}; - -struct aurora_apif_boot_iommu { - u64 level, count, base, size, pa, ipa, attrs, reserved; -}; - -/* Each client owns a buffer. Submission is synchronous and atomic-context - * safe. Unbind drains the client and subsequent calls return -ENODEV. - */ -#if IS_REACHABLE(CONFIG_AURORA_APIF_MMIO) -struct aurora_apif *aurora_apif_get(struct device *dev); -void aurora_apif_put(struct aurora_apif *apif); -/* @done counts executed operations. The transport does not interpret native - * results; endpoint-specific status and ownership belong to the caller. - */ -int aurora_apif_submit(struct aurora_apif *apif, struct aurora_apif_op *ops, - u32 count, u32 *done); - -#else -static inline struct aurora_apif *aurora_apif_get(struct device *dev) -{ - return ERR_PTR(-ENODEV); -} -static inline void aurora_apif_put(struct aurora_apif *apif) -{ -} -static inline int aurora_apif_submit(struct aurora_apif *apif, - struct aurora_apif_op *ops, u32 count, - u32 *done) -{ - if (done) - *done = 0; - return -ENODEV; -} -#endif - -#endif diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 1f2c4b5b33fa8..6fb32e0396fa9 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -4,7 +4,6 @@ TARGETS += alloc_tag TARGETS += alsa TARGETS += amd-pstate TARGETS += arm64 -TARGETS += aurora-apif TARGETS += bpf TARGETS += breakpoints TARGETS += cachestat diff --git a/tools/testing/selftests/aurora-apif/Makefile b/tools/testing/selftests/aurora-apif/Makefile deleted file mode 100644 index fba0d147f9246..0000000000000 --- a/tools/testing/selftests/aurora-apif/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# Each sibling PR contributes its own tests to the shared base. -TEST_PROGS := $(filter-out common.py,$(wildcard *.py)) -TEST_FILES := common.py -include ../lib.mk diff --git a/tools/testing/selftests/aurora-apif/apif_mmio.py b/tools/testing/selftests/aurora-apif/apif_mmio.py deleted file mode 100755 index 8cc3484814f48..0000000000000 --- a/tools/testing/selftests/aurora-apif/apif_mmio.py +++ /dev/null @@ -1,409 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-only -"""Host fault injection against production APIF functions; no firmware calls.""" -import os -from pathlib import Path -import re -import shlex -import subprocess -import tempfile - -ROOT = Path(__file__).resolve().parents[4] - - -def function(path, name): - source = (ROOT / path).read_text() - match = re.search(r"^.*\b" + name + r"\([^;]*?\)\n\{", source, re.M) - if not match: - raise RuntimeError(f"missing production function {name}") - start = match.start() - pos = match.end() - 1 - depth = 0 - for end in range(pos, len(source)): - if source[end] == "{": - depth += 1 - elif source[end] == "}": - depth -= 1 - if not depth: - return source[start:end + 1] - raise RuntimeError(f"unterminated function {name}") - - -HEADER = r''' -#include -#include -#include -#include -#include -#include -#include -typedef uint16_t u16; -typedef uint32_t u32; -typedef int32_t s32; -typedef uint64_t u64; -typedef uintptr_t phys_addr_t; -#define __packed __attribute__((packed)) -#define U64_MAX UINT64_MAX -#define PHYS_ADDR_MAX UINTPTR_MAX -#define SZ_16K 16384UL -#define SZ_4G (1ULL << 32) -#define PAGE_SIZE SZ_16K -#define IOMMU_READ 1 -#define IOMMU_WRITE 2 -#define IOMMU_CACHE 4 -#define IOMMU_NOEXEC 8 -#define IOMMU_MMIO 16 -#define GENMASK_ULL(h,l) ((~0ULL << (l)) & (~0ULL >> (63-(h)))) -#define IS_REACHABLE(x) 1 -#define GFP_ATOMIC 0 -#define kmalloc(n,flags) malloc(n) -#define virt_to_phys(p) ((u64)(uintptr_t)(p)) -#define round_down(v,a) ((v) & ~((a)-1)) -#define min(a,b) ((a)<(b)?(a):(b)) -#define READ_ONCE(v) (v) -#define raw_spin_lock_irqsave(lock,flags) ((void)(lock), (flags)=0) -#define raw_spin_unlock_irqrestore(lock,flags) ((void)(lock), (void)(flags)) -#define mutex_lock(lock) ((void)(lock)) -#define mutex_unlock(lock) ((void)(lock)) -''' -api = (ROOT / "include/linux/soc/aurora/apif-mmio.h").read_text() -api = "\n".join(line for line in api.splitlines() if not line.startswith("#include")) -HEADER += api + "\n" - - -def transport_test(): - submit = function("drivers/firmware/aurora-apif-mmio.c", "aurora_apif_submit") - return HEADER + r''' -struct apif_batch { u32 count, flags; s32 status; u32 done; struct aurora_apif_op ops[3]; }; -struct aurora_apif { int lock; bool live; struct apif_batch *batch; u32 max_ops; }; -static unsigned rings; -static int mode; -static void apif_ring(struct aurora_apif *apif) -{ - rings++; - apif->batch->done = apif->batch->count; - apif->batch->status = 0; - for (u32 i = 0; i < apif->batch->count; i++) apif->batch->ops[i].ret = U64_MAX; - if (mode == 1) { apif->batch->done = 1; apif->batch->status = -EINVAL; } - if (mode == 2) apif->batch->done++; - if (mode == 3) { apif->batch->done = 0; apif->batch->status = -EINPROGRESS; } - if (mode == 4) { apif->batch->done = 0; apif->batch->status = 1; } - if (mode == 5) { apif->batch->done = 1; } -} -''' + submit + r''' -int main(void) -{ - struct apif_batch batch = {}; - struct aurora_apif client = { .live = true, .batch = &batch, .max_ops = 3 }; - struct aurora_apif_op ops[8] = {}; - u32 done; - assert(!aurora_apif_submit(&client, ops, 8, &done)); - assert(done == 8 && rings == 3 && ops[7].ret == U64_MAX); - assert(!aurora_apif_submit(&client, NULL, 0, &done) && !done && rings == 3); - assert(aurora_apif_submit(&client, NULL, 1, &done) == -EINVAL && !done); - mode = 1; - assert(aurora_apif_submit(&client, ops, 8, &done) == -EINVAL && done == 1); - mode = 2; - assert(aurora_apif_submit(&client, ops, 8, &done) == -EIO && !done); - mode = 3; - assert(aurora_apif_submit(&client, ops, 8, &done) == -EIO && !done); - mode = 4; - assert(aurora_apif_submit(&client, ops, 8, &done) == -EIO && !done); - mode = 5; - assert(aurora_apif_submit(&client, ops, 8, &done) == -EIO && done == 1); - client.live = false; - assert(aurora_apif_submit(&client, ops, 1, &done) == -ENODEV && !done); - return 0; -} -''' - - -def dart_test(): - path = "drivers/iommu/apple-dart-apif.c" - source = (ROOT / path).read_text() - constants = source[source.index("#define APIF_DART_INIT"):source.index("static const struct iommu_ops")] - funcs = "\n".join(function(path, name) for name in - ["apif_force_iovas", "apif_one", "apif_prepare_table", "apif_boot_query", "apif_ring"]) - return HEADER + constants + r''' -struct apif_retained_run { u64 dva, ipa, size; }; -struct apif_retained_sid { unsigned root_level; u32 count; struct apif_retained_run *runs; }; -struct apple_dart_apif { - struct aurora_apif *apif; - struct aurora_apif_op native_ops[2 * APIF_BATCH_MAX_OPS]; - struct aurora_apif_boot_iommu *boot_info; - u64 *page_lists[APIF_BATCH_MAX_OPS], page_list_pa[APIF_BATCH_MAX_OPS]; - u32 dart_id, num_streams; - u64 iova_force, dma_min, dma_max; - bool boot_mappings; - bool ownership_uncertain; - struct apif_retained_sid *retained[DART_APIF_MAX_STREAMS]; - struct apif_batch *batch; -}; -static struct aurora_apif_op calls[2048]; -static unsigned ncalls; -static u64 boot_table, found_table, retype_result = 1, fail_selector; -static int fail_status; -static int native_done = -1; -int aurora_apif_submit(struct aurora_apif *client, struct aurora_apif_op *ops, u32 count, u32 *done) -{ - (void)client; - if (done) *done = 0; - for (u32 i = 0; i < count; i++) { - struct aurora_apif_op *op = &ops[i]; - calls[ncalls++] = *op; - if (fail_selector && op->selector == fail_selector) return fail_status; - if (native_done >= 0 && (op->selector >> 32) != AURORA_APIF_SERVICE && i >= (u32)native_done) - return -EIO; - op->ret = 0; - if (op->selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_TRANSLATE)) - op->ret = op->arg[0] + SZ_4G; - if (op->selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_BOOT_TABLE)) - op->ret = boot_table; - if (op->selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_FIND_FRAME)) - op->ret = found_table; - if (op->selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_ALLOC_FRAME)) - op->ret = 0x90000000; - if (op->selector == AURORA_APIF_SELECTOR(0, 1)) op->ret = retype_result; - /* A void endpoint is allowed to return nonzero. */ - if (op->selector == AURORA_APIF_SELECTOR(3, 0)) op->ret = U64_MAX; - if (done) *done = i + 1; - } - return 0; -} -''' + funcs + r''' -int main(void) -{ - struct apple_dart_apif dart = { .dart_id = 5, .num_streams = 16 }; - struct aurora_apif_boot_iommu info = {}; - dart.boot_info = &info; - dart.batch = calloc(1, PAGE_SIZE); - assert(dart.batch); - boot_table = 0x80000000; - assert(!apif_prepare_table(&dart, 3, 0x2000000, 2) && ncalls == 1); - boot_table = 0; found_table = 0x80000000; ncalls = 0; - assert(!apif_prepare_table(&dart, 3, 0x2000000, 2) && ncalls == 2); - found_table = 0; ncalls = 0; - assert(!apif_prepare_table(&dart, 3, 0x2000000, 2) && ncalls == 6); - assert(calls[3].selector == AURORA_APIF_SELECTOR(0, 1)); - assert(calls[3].arg[0] == 0x90000000 && calls[3].arg[1] == 11 && calls[3].arg[2] == 24); - assert(calls[4].selector == AURORA_APIF_SELECTOR(3, 0)); - assert(calls[4].arg[0] == 5 && calls[4].arg[1] == 3 && calls[4].arg[4] == 0x90000000); - assert(calls[5].selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_TAG_FRAME)); - retype_result = 0; ncalls = 0; - assert(apif_prepare_table(&dart, 3, 0, 2) == -EIO && ncalls == 5); - assert(calls[4].selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_FREE_FRAME)); - retype_result = 1; ncalls = 0; - fail_selector = AURORA_APIF_SELECTOR(3, 0); fail_status = -ETIMEDOUT; - assert(apif_prepare_table(&dart, 3, 0, 2) == -ETIMEDOUT && dart.ownership_uncertain); - assert(apif_ring(&dart) == -EIO && !dart.batch->done); - dart.ownership_uncertain = false; fail_selector = 0; ncalls = 0; - dart.iova_force = 1ULL << 40; - dart.batch->count = 2; - for (unsigned i = 0; i < 2; i++) { - dart.batch->op[i] = (struct apif_op){ .op = APIF_DART_MAP, - .arg = { 3, i * 0x4000, 0x800000 + i * 0x4000, 0x4000, 3 | IOMMU_NOEXEC } }; - } - assert(!apif_ring(&dart) && dart.batch->done == 2 && ncalls == 6); - assert(calls[4].selector == AURORA_APIF_SELECTOR(3, 2)); - assert(calls[4].arg[2] == (1ULL << 40)); - assert(calls[4].arg[3] == virt_to_phys(dart.page_lists[0]) + SZ_4G); - assert(dart.page_lists[0][0] == 0x100800000ULL); - assert(calls[4].arg[5] == 4 && dart.batch->op[0].arg[1] == 0); - ncalls = 0; native_done = 1; - assert(apif_ring(&dart) == -EIO && dart.batch->done == 1); - assert(dart.batch->op[0].arg[1] == 0 && dart.batch->op[1].arg[1] == 0x4000); - native_done = -1; ncalls = 0; - dart.batch->op[0].arg[4] = 256; - assert(apif_ring(&dart) == -EINVAL && !ncalls && !dart.batch->done); - for (unsigned i = 0; i < APIF_BATCH_MAX_OPS; i++) free(dart.page_lists[i]); - free(dart.batch); - return 0; -} -''' - - -def sart_test(): - return HEADER + r''' -struct device {}; -struct mutex { int unused; }; -struct sart_apif { - struct device *dev; - struct aurora_apif *apif; - struct mutex lock; - bool active; - struct { phys_addr_t address; size_t size; } regions[16]; -}; -struct apple_sart { struct sart_apif *state; }; -#define SART_APIF_MAX_REGIONS 16 -#define apple_sart_backend_data(sart) ((sart)->state) -#define dma_to_phys(dev,address) (address) -static struct aurora_apif_op calls[8]; -static unsigned ncalls; -static u64 unmap_result; -int aurora_apif_submit(struct aurora_apif *client, struct aurora_apif_op *ops, u32 count, u32 *done) -{ - (void)client; (void)done; - assert(count == 1); - calls[ncalls++] = *ops; - ops->ret = U64_MAX; - if (ops->selector == AURORA_APIF_SELECTOR(AURORA_APIF_SERVICE, AURORA_APIF_TRANSLATE)) - ops->ret = ops->arg[0] + SZ_4G; - if (ops->selector == AURORA_APIF_SELECTOR(5, 2)) ops->ret = unmap_result; - return 0; -} -''' + function("drivers/soc/apple/apple-sart-apif.c", "sart_apif_region") + r''' -int main(void) -{ - struct sart_apif state = {}; - struct apple_sart sart = { &state }; - assert(sart_apif_region(&sart, 0, 0, true) == -EINVAL); - assert(sart_apif_region(&sart, 1, SZ_16K, true) == -EINVAL); - assert(!sart_apif_region(&sart, 0x800000, SZ_16K, true)); - assert(ncalls == 3 && state.active && state.regions[0].size == SZ_16K); - assert(calls[2].selector == AURORA_APIF_SELECTOR(5, 1) && calls[2].arg[0] == 0x100800000ULL); - ncalls = 0; unmap_result = 1; - assert(sart_apif_region(&sart, 0x800000, SZ_16K, false) == -EIO); - assert(state.regions[0].size == SZ_16K); - ncalls = 0; unmap_result = 0; - assert(!sart_apif_region(&sart, 0x800000, SZ_16K, false) && !state.regions[0].size); - assert(sart_apif_region(&sart, 0x800000, SZ_16K, false) == -ENOENT); - return 0; -} -''' - - -def nvme_test(): - helpers = "\n".join(function("drivers/nvme/host/apple-apif.h", name) for name in - ["apple_nvme_apif_translate", "apple_nvme_apif_request"]) - return HEADER + r''' -#define SZ_4K 4096UL -#define APPLE_NVME_APIF_PAGES 257 -#define APPLE_NVME_APIF_LIST_SIZE SZ_4K -#define DIV_ROUND_UP(n,d) (((n)+(d)-1)/(d)) -#define IS_ALIGNED(n,a) (!((n)&((a)-1))) -#define lockdep_assert_held(p) ((void)(p)) -#define dma_wmb() ((void)0) -#define cpu_to_le16(v) (v) -#define le64_to_cpu(v) (v) -typedef uint64_t __le64; -struct command { struct { struct {u64 prp1, prp2;} dptr; u32 command_id; } common; }; -struct apple_nvmmu_tcb { u32 pad; unsigned short length; char rest[122]; }; -struct apple_nvme_iod { struct command cmd; bool apif_registered; __le64 *prps; }; -struct request { struct apple_nvme_iod iod; u32 bytes; }; -struct apple_nvme_hw { u32 max_queue_depth; }; -struct apple_nvme { void *dev; int lock; struct aurora_apif *apif; struct apple_nvme_hw *hw; - struct aurora_apif_op *apif_ops; void *apif_scratch; u64 apif_scratch_dma; bool apif_uncertain; }; -struct apple_nvme_queue { struct apple_nvme *anv; bool is_adminq; struct apple_nvmmu_tcb tcbs[64]; }; -static struct apple_nvme *queue_to_apple_nvme(struct apple_nvme_queue *q) {return q->anv;} -static struct apple_nvme_iod *blk_mq_rq_to_pdu(struct request *r) {return &r->iod;} -static u32 nvme_tag_from_cid(u32 tag) {return tag;} -static u32 blk_rq_payload_bytes(struct request *r) {return r->bytes;} -static void **apple_nvme_iod_list(struct request *r) {return (void **)&r->iod.prps;} -static u64 dma_to_phys(void *dev, u64 p) {(void)dev; return p;} -static int map_calls, translate_calls, mode; -static struct aurora_apif_op mapped; -int aurora_apif_submit(struct aurora_apif *apif, struct aurora_apif_op *ops, u32 n, u32 *done) { - (void)apif; if(done) *done=n; - for(u32 i=0;ilength==255); - assert(translate_calls>=257); - return 0; -} -''' - - -def pcie_test(): - layout = (ROOT / "drivers/pci/controller/apple-apif/t6050_pcie_sequence.h").read_text() - gpio = (ROOT / "drivers/pci/controller/apple-apif/t6050_pcie_gpio.h").read_text() - layout = "\n".join(x for x in (layout + gpio).splitlines() if not x.startswith("#include")) - helpers = "\n".join(function("drivers/pci/controller/apple-apif/" + file, name) for file, name in - [("t6050_pcie_msi.c", "t6050_pcie_configure_msi_port0"), - ("t6050_pcie_gpio.c", "t6050_pcie_gpio_perst"), - ("t6050_pcie_disable.c", "update"), - ("t6050_pcie_disable.c", "t6050_pcie_disable_port0")]) - return HEADER + layout + "\n" + helpers + r''' -static u32 pad, address_lo, address_hi; -static int writes, fail_write, power_calls, polls; -static int fake_read(void *ctx,unsigned reg,unsigned off,u32 *v) { - (void)ctx;(void)reg;(void)off;*v=0;return 0; -} -static int fake_write(void *ctx,unsigned reg,unsigned off,u32 v) { - (void)ctx;assert(reg==T6050_PCIE_PORT0);writes++; - if(fail_write==writes) return -EIO; - if(off==0x16c) address_lo=v; - if(off==0x170) address_hi=v; - return 0; -} -static int fake_poll(void *ctx,unsigned reg,unsigned off,u32 mask,u32 value,unsigned timeout) { - (void)ctx;(void)reg;(void)off;(void)mask;(void)value; - assert(timeout>0 && timeout<=250000);polls++;return -ETIMEDOUT; -} -static void fake_delay(void *ctx,unsigned us) {(void)ctx;assert(us<=100000);} -static int power(void *ctx,bool on) {(void)ctx;assert(!on);power_calls++;return -EBUSY;} -static int pad_read(void *ctx,u32 *v) {(void)ctx;*v=pad;return 0;} -static int pad_write(void *ctx,u32 v) {(void)ctx;pad=v;writes++;return 0;} -int main(void) { - struct t6050_pcie_io io={.read=fake_read,.write=fake_write,.poll=fake_poll,.delay=fake_delay}; - assert(!t6050_pcie_configure_msi_port0(&io,0x1fffff000ULL,64)); - assert(writes==67 && address_hi==1 && address_lo==0xfffff000); - writes=0;fail_write=2; - assert(t6050_pcie_configure_msi_port0(&io,0xfffff000,32)==-EIO && writes==2); - writes=0;assert(t6050_pcie_configure_msi_port0(&io,1,32)==-EINVAL && !writes); - assert(t6050_pcie_configure_msi_port0(&io,0xfffff000,257)==-EINVAL); - assert(t6050_pcie_disable_port0(&io,power,250000)==-EBUSY); - assert(power_calls==1 && !writes && !polls); - struct t6050_gpio_pad_io g={.read=pad_read,.write=pad_write}; - pad=1U<<21;assert(t6050_pcie_gpio_perst(&g,true)==-EIO && !writes); - pad=0;assert(!t6050_pcie_gpio_perst(&g,true) && (pad&0x27f)==0x202); - assert(!t6050_pcie_gpio_perst(&g,false) && (pad&0x27f)==0x203); - return 0; -} -''' - - -def run_tests(tests): - compiler = shlex.split(os.environ.get("HOSTCC", "cc")) - print(f"TAP version 13\n1..{len(tests)}", flush=True) - with tempfile.TemporaryDirectory(prefix="apif-selftest-") as directory: - for i, (name, test) in enumerate(tests, 1): - path = Path(directory) / name - path.with_suffix(".c").write_text(test()) - subprocess.run(compiler + ["-std=gnu11", "-Wall", "-Wextra", "-Werror", - str(path.with_suffix(".c")), "-o", str(path)], check=True) - subprocess.run([str(path)], check=True) - print(f"ok {i} - {name} production function", flush=True) - - -if __name__ == "__main__": - run_tests([("transport", transport_test), ("dart", dart_test), ("sart", sart_test)]) diff --git a/tools/testing/selftests/aurora-apif/common.py b/tools/testing/selftests/aurora-apif/common.py deleted file mode 100644 index 3476376b8026d..0000000000000 --- a/tools/testing/selftests/aurora-apif/common.py +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -"""Production-source extraction shared by the APIF host tests.""" -import re - -def block(source, pattern): - match = re.search(pattern, source, re.M) - if not match: - raise RuntimeError(f"missing production block {pattern}") - start = match.start() - brace = source.index("{", match.end()) - depth = 0 - for pos in range(brace, len(source)): - if source[pos] == "{": - depth += 1 - elif source[pos] == "}": - depth -= 1 - if not depth: - return source[start:pos + 1] - raise RuntimeError("unterminated production block") diff --git a/tools/testing/selftests/aurora-apif/dart_retained.py b/tools/testing/selftests/aurora-apif/dart_retained.py deleted file mode 100755 index a7c6f3c4d560b..0000000000000 --- a/tools/testing/selftests/aurora-apif/dart_retained.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0-only -"""Execute the production DART stream-state operation builder with retained SIDs.""" -from pathlib import Path -import subprocess,tempfile,sys -root=Path(__file__).resolve().parents[4] -p=Path(sys.argv[1]) if len(sys.argv)>1 else root/'drivers/iommu/apple-dart-apif.c' -s=p.read_text();start=s.index('\t\tcase APIF_DART_ENABLE:');end=s.index('\t\tcase 7:',start);fragment=s[start:end] -code=r''' -#include -#include -#include -#include -typedef uint64_t u64; -#define APIF_DART_ENABLE 5 -#define APIF_DART_DISABLE 6 -#define AURORA_APIF_SELECTOR(t,e) (((u64)(t)<<32)|(e)) -#define EINVAL 22 -struct apple_dart_apif { unsigned dart_id,num_streams;void *retained[256]; }; -struct apif_op { unsigned op;u64 arg[6]; }; -struct aurora_apif_op { u64 selector,arg[6],ret; }; -static int build(struct apple_dart_apif *dart,unsigned opcode,u64 sid,unsigned *count,struct aurora_apif_op *native) { - struct apif_op request={.op=opcode,.arg={sid}};struct apif_op *op=&request;u64 *a=op->arg; - struct aurora_apif_op call={.arg={dart->dart_id,sid}};unsigned n=0;int ret=0; - switch(op->op) { -''' + fragment + r''' - default:assert(false); - } -out:*count=n;return ret; -} -int main(void) { - const unsigned sizes[]={1,16,256};unsigned checked=0; - for(unsigned k=0;k<3;k++) { - struct apple_dart_apif d={.dart_id=16,.num_streams=sizes[k]}; - for(unsigned sid=0;sid Date: Mon, 9 Nov 2026 12:16:43 -0500 Subject: [PATCH 319/342] dt-bindings: Drop the APIF bindings Remove the APIF MMIO, DART and SART bindings and the APIF ASCWrap v6 compatible, and the APIF host wording in the N1 Control binding. Signed-off-by: Diljit Singh --- .../bindings/firmware/aurora,apif-mmio.yaml | 36 -------- .../bindings/iommu/apple,dart-apif.yaml | 84 ------------------- .../bindings/mailbox/apple,ascwrap-v6.yaml | 1 - .../bindings/soc/apple/apple,sart-apif.yaml | 35 -------- 4 files changed, 156 deletions(-) delete mode 100644 Documentation/devicetree/bindings/firmware/aurora,apif-mmio.yaml delete mode 100644 Documentation/devicetree/bindings/iommu/apple,dart-apif.yaml delete mode 100644 Documentation/devicetree/bindings/soc/apple/apple,sart-apif.yaml diff --git a/Documentation/devicetree/bindings/firmware/aurora,apif-mmio.yaml b/Documentation/devicetree/bindings/firmware/aurora,apif-mmio.yaml deleted file mode 100644 index c154786a0593c..0000000000000 --- a/Documentation/devicetree/bindings/firmware/aurora,apif-mmio.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/firmware/aurora,apif-mmio.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Aurora Platform Interface over Memory-Mapped I/O - -maintainers: - - Dj - -description: | - Synthetic MMIO transport supplied by Aura's EL2-resident monitor. Version 2 - forwards native SPTM selectors and arguments and provides memory-ownership - services. Peripheral policy belongs to consumers, which reference this node - through the aurora,apif phandle. The register page must be absent from the - guest stage-2 mappings so accesses reach Aura. - -properties: - compatible: - const: aurora,apif-mmio - reg: - maxItems: 1 - -required: - - compatible - - reg - -additionalProperties: false - -examples: - - | - apif: firmware@61ff0000 { - compatible = "aurora,apif-mmio"; - reg = <0x61ff0000 0x4000>; - }; diff --git a/Documentation/devicetree/bindings/iommu/apple,dart-apif.yaml b/Documentation/devicetree/bindings/iommu/apple,dart-apif.yaml deleted file mode 100644 index dbf1169dae26b..0000000000000 --- a/Documentation/devicetree/bindings/iommu/apple,dart-apif.yaml +++ /dev/null @@ -1,84 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/iommu/apple,dart-apif.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple DART mediated through Aura APIF - -maintainers: - - Dj - -description: | - A DART instance accessed through native SPTM calls rather than guest MMIO. - Linux owns stream grouping, table setup, mapping rollback and DMA apertures. - Firmware-owned streams are adopted without replacing their roots or replaying - retained mappings. Unit identifiers are firmware metadata, not chip IDs. - -properties: - compatible: - const: apple,dart-apif - '#iommu-cells': - const: 1 - description: Stream identifier. - aurora,apif: - $ref: /schemas/types.yaml#/definitions/phandle - description: APIF version-2 transport provider. - power-domains: - maxItems: 1 - description: | - Native register-clock dependency needed before the first APIF DART call. - The provider must be powered independently of consumer probe ordering. - For T6050 ATC2 USB DART this is the ATC2_USB domain shared with DWC3. - apple,apif-dart-id: - $ref: /schemas/types.yaml#/definitions/uint32 - maximum: 255 - description: Native SPTM DART unit identifier. - apple,apif-num-streams: - $ref: /schemas/types.yaml#/definitions/uint32 - minimum: 1 - maximum: 256 - default: 256 - description: Number of streams supported by this unit. - apple,apif-retained-sids: - $ref: /schemas/types.yaml#/definitions/uint32-array - minItems: 1 - maxItems: 256 - uniqueItems: true - items: - maximum: 255 - description: Firmware-owned stream IDs which Aura adopted at bootstrap. - apple,apif-iova-force: - $ref: /schemas/types.yaml#/definitions/uint64 - enum: [0, 1099511627776] - description: | - Optional native bit-40 force mask for a low-address device DMA view. - Must not overlap apple,dma-range. Omit for a native DVA aperture. - apple,apif-reserve-last-page: - type: boolean - description: Native aperture forbids allocating its final 16 KiB granule. - apple,dma-range: - $ref: /schemas/types.yaml#/definitions/uint64-array - minItems: 2 - maxItems: 2 - description: | - Device-visible DMA aperture base and size, aligned to 16 KiB and within - 42 bits. Defaults to the low 4 GiB. This is not a CPU mapping. - -required: - - compatible - - '#iommu-cells' - - aurora,apif - - apple,apif-dart-id - -additionalProperties: false - -examples: - - | - iommu { - compatible = "apple,dart-apif"; - #iommu-cells = <1>; - aurora,apif = <&apif>; - apple,apif-dart-id = <5>; - apple,apif-num-streams = <16>; - }; diff --git a/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml b/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml index a08c3224e7b1e..349d6930d07e0 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,ascwrap-v6.yaml @@ -24,7 +24,6 @@ properties: - apple,t6040-ascwrap-v6 - apple,t8140-ascwrap-v6 - apple,t8142-ascwrap-v6 - - apple,t6050-apif-ascwrap-v6 - apple,t6050-ascwrap-v6 - apple,t6050-x1n1-ascwrap-v6 - apple,t6050-j775d-ascwrap-v6 diff --git a/Documentation/devicetree/bindings/soc/apple/apple,sart-apif.yaml b/Documentation/devicetree/bindings/soc/apple/apple,sart-apif.yaml deleted file mode 100644 index 4e5ece8bebaf5..0000000000000 --- a/Documentation/devicetree/bindings/soc/apple/apple,sart-apif.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/soc/apple/apple,sart-apif.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple SART mediated through Aura APIF - -maintainers: - - Dj - -description: | - SART provider using native SPTM table-5 calls. Existing consumers reference - this provider through their apple,sart phandle. Linux tracks only its own - regions; unknown firmware grants are not reported as inherited regions. - -properties: - compatible: - const: apple,sart-apif - aurora,apif: - $ref: /schemas/types.yaml#/definitions/phandle - description: APIF version-2 transport provider. - -required: - - compatible - - aurora,apif - -additionalProperties: false - -examples: - - | - sart { - compatible = "apple,sart-apif"; - aurora,apif = <&apif>; - }; From 9310f7631c1867f10c5b253fa77c8f7357b95367 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 12:16:43 -0500 Subject: [PATCH 320/342] Documentation: Drop the APIF documentation Remove the APIF platform, driver and N1 transport pages, their index entries and the APIF MAINTAINERS entries. Signed-off-by: Diljit Singh --- .../arch/arm64/aurora-apif-centauri.rst | 78 ------------- .../arch/arm64/aurora-apif-platform.rst | 109 ------------------ Documentation/arch/arm64/index.rst | 7 -- .../firmware/aurora-apif-display.rst | 99 ---------------- .../driver-api/firmware/aurora-apif-nvme.rst | 39 ------- .../driver-api/firmware/aurora-apif-pcie.rst | 30 ----- .../driver-api/firmware/aurora-apif-pmp.rst | 35 ------ .../driver-api/firmware/aurora-apif.rst | 100 ---------------- Documentation/driver-api/firmware/index.rst | 4 - MAINTAINERS | 23 ---- 10 files changed, 524 deletions(-) delete mode 100644 Documentation/arch/arm64/aurora-apif-centauri.rst delete mode 100644 Documentation/arch/arm64/aurora-apif-platform.rst delete mode 100644 Documentation/driver-api/firmware/aurora-apif-display.rst delete mode 100644 Documentation/driver-api/firmware/aurora-apif-nvme.rst delete mode 100644 Documentation/driver-api/firmware/aurora-apif-pcie.rst delete mode 100644 Documentation/driver-api/firmware/aurora-apif-pmp.rst delete mode 100644 Documentation/driver-api/firmware/aurora-apif.rst diff --git a/Documentation/arch/arm64/aurora-apif-centauri.rst b/Documentation/arch/arm64/aurora-apif-centauri.rst deleted file mode 100644 index c24f4d6fb7cb9..0000000000000 --- a/Documentation/arch/arm64/aurora-apif-centauri.rst +++ /dev/null @@ -1,78 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -N1 firmware and PCI transport -============================= - -The Control function owns the firmware bootstrap and its DMA allocations. -Alpha and Beta use their own PCI-function DMA mappings. The driver requires -an APIF host with the supported isolated Gen3 x1 reset layout. All endpoint -DMA/MSI must be quiesced and the endpoint left in the stopped ROM personality; -live sessions cannot be adopted by this interface. - -The Control PCI DT node supplies ``firmware-name``, -``apple,centauri-platform-id`` and ``apple,centauri-protocol = <27>``. The -platform identifier and personalized FTAB must agree with the actual device. -These are firmware inputs supplied by the boot producer, rather than a -machine-name lookup in the driver. No firmware or calibration data is shipped -in this series. The driver loads the firmware directly and starts asynchronously; -a missing file or failed phase requires correcting the input and reprobe. - -The host's native DART reset requires exclusive Linux ownership and no retained -firmware streams on that unit. The boot producer must resolve ownership before -handoff. This driver cannot discard retained streams to make a reset succeed. -A failed link transition prevents further endpoint accesses. Published DMA and -vectors remain pinned when shutdown cannot be proved; a platform reset is then -required. This is an error path, not a supported live-session handoff. - -Bootstrap command rings are bounded and used once. Radio data-plane ring sizes -and batching are separate from bootstrap. The transport builds without the -Wi-Fi consumer; it still starts the shared firmware for the later Alpha/Beta -consumers. Wi-Fi and Bluetooth are separate follow-up changes. Hardware -qualification of this cleaned series, including suspend/resume, remains pending. - -Wi-Fi station consumer ----------------------- - -``CONFIG_APPLE_CENTAURI_WIFI`` adds the Alpha cfg80211/netdev consumer within -this transport module. It supports the protocol-27 command profile, active -2.4/5 GHz scanning and WPA2-PSK/CCMP station connections with firmware handshake -offload. The matched profile uses a raw 32-byte PMK supplied by cfg80211; -there is no separate passphrase interface. Unknown profiles are rejected by -the Control driver. Passive scan encoding is not established, so disabled and -NO_IR channels are excluded from active scans. WPA3, 6 GHz, roaming and wider -security/radio qualification remain outside the established driver scope. - -Data uses the original 2,048-entry rings and coalesced completions. IRQs and -queued packets schedule the consumer; no periodic data poller or diagnostic -packet flow is added. Malformed frames and completion spans cannot index beyond -the coherent window. A lost command completion poisons further commands and -stops new transmission. Its key payload is cleared only after the transfer-ring -tail proves consumption; uncertain ownership keeps backing memory pinned. -Safe IPC teardown scrubs buffers after verified DMA shutdown. The cleaned -consumer still needs hardware traffic and suspend/resume qualification. - -Bluetooth consumer ------------------- - -``CONFIG_BT_HCICENTAURI`` adds the Beta HCI/ACL PCI driver. A managed device -link requires the Control supplier to have established shared firmware and -orders removal and suspend against it. The Beta DT node supplies the factory -``local-mac-address`` in network byte order; no board-name or temporary-address -fallback selects initialization behavior. - -Protocol-27 initialization provisions the address, completes firmware setup -and supplies a fresh random seed. The connection-command adaptation is enabled -only after the firmware's capability bit confirms support. Status and connection -completion events are normalized to the standard HCI command being tracked. -The firmware duplicate filter is reset in the HCI command-sync path before -filtered scanning starts; other drivers without that callback keep their -existing behavior. Standard report lengths are checked before applying the -matched legacy scan-response fixup. - -The driver uses IRQ-triggered work and the original ring geometry. Diagnostic -capture, unrelated auxiliary rings, manual mode switches and success logging -are excluded. SCO and ISO delivery are not implemented. Coordinated firmware -teardown remains unqualified: a published Beta arena stays pinned on detach, -and rebinding requires a fresh shared-firmware boot. This is not a reset of the -Wi-Fi function. The cleaned driver still needs hardware HCI/ACL, repeated-scan -and suspend/resume qualification. diff --git a/Documentation/arch/arm64/aurora-apif-platform.rst b/Documentation/arch/arm64/aurora-apif-platform.rst deleted file mode 100644 index af062d4c09a57..0000000000000 --- a/Documentation/arch/arm64/aurora-apif-platform.rst +++ /dev/null @@ -1,109 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -M5 Pro non-GPU platform series -============================= - -The APIF platform series separates transport/provider support from device -consumers. The shared ``t6050/base`` PR targets ``integration/aurora`` on -Linux 7.3; every other PR targets ``t6050/base``. Consumer dependencies are -recorded separately, so the review branches do not form a linear chain. -The source snapshot is ``t6050-gpu`` at ``ee68abb105200``. This review map -covers its non-GPU platform changes; hardware qualification of the rebased -combination remains separate. - -.. list-table:: Review branches - :header-rows: 1 - - * - Area - - Branch - * - APIF transport, DART and SART - - `t6050/base `_ - * - Native ANS/NVMe queues - - `t6050/nvme `_ - * - Preinitialized PCIe and MSI - - `t6050/pcie `_ - * - PMP firmware registry - - `t6050/pmp `_ - * - Guest DT conversion - - `t6050/guest-wiring `_ - * - Generation-4 SPMI - - `t6050/spmi `_ - * - SPMI PMU RTC - - `t6050/pmu-rtc `_ - * - SMC consumers and pcIO GPIO - - `t6050/smc `_ - * - DP/USB combo PHY and crossbar - - `t6050/display-phy `_ - * - CPU frequency profile - - `t6050/cpufreq `_ - * - N1 firmware and PCI lifetime - - `t6050/centauri-core `_ - * - N1 Wi-Fi - - `t6050/centauri-wifi `_ - * - N1 Bluetooth - - `t6050/centauri-bluetooth `_ - * - Firmware-27 AFK, DCP and DPTX - - `t6050/dcp `_ - * - Host GPIO interrupt groups - - `t6050/gpio-irqs `_ - * - Initial SPMI Type-C events - - `t6050/typec-events `_ - * - DWC3 controller - - `t6050/usb `_ - * - Power-domain handoff - - `t6050/pmgr `_ - * - MTP keyboard reports - - `t6050/mtp `_ - * - Composed platform configuration - - `t6050/platform-wiring `_ - -CPU identification, idle register preservation and delay handling are -already represented by the base. Existing public interrupt-controller, -USB, I2C/SPI, DockChannel HID, MTP helper and standard platform drivers are -preserved rather than replaced with older copies. The fragment enables -their dependencies alongside the new providers and consumers. - -AGX acceleration, its dedicated mailbox transports and diagnostic system -register probes are outside this series. Firmware binaries, board -calibration data and factory addresses are not included. - -Configuration -------------- - -Apply aurora-apif.config after defconfig and asahi.config, then run -olddefconfig. The fragment makes the selected platform consumers built-in; -firmware and loader metadata are still required. - -The existing HID interface uses explicit apple,power-method and -apple,firmware-managed-reset properties. The latter is valid only for a -power-method-2 multi-touch interface with firmware-owned reset. The loader -must describe the actual ownership; no board-name or firmware-filename -guess selects it. - -Loader and qualification requirements -------------------------------------- - -* NVMe needs a stopped RTKit session and four distinct, reserved queue - pages. The new profile does not adopt an unqualified live queue session. -* N1 cold bootstrap needs its packed platform identifier, protocol 27, - factory Bluetooth address and an exclusively owned PCIe/DART unit. - Unqualified live-session adoption is not enabled. -* CPU frequency control requires an explicit, qualified firmware thermal - ownership claim covering every exposed OPP, including after PMP setup. - The DT conversion tool does not invent that claim. -* DCP needs a running firmware-27 session, inherited framebuffer region, - ordered provider clock table and the coprocessor physical register view - when guest resource addresses differ. -* GPIO interrupt groups and HID reset ownership must match the loader's - retained firmware ownership. - -The conversion tool validates supplied metadata; it cannot establish that -firmware has stopped using a queue, stream, reset line or clock policy. - -Validation ----------- - -The series has native driver builds and host protocol/bounds tests. -Hardware qualification must separately cover boot, storage I/O, network -traffic, physical Type-C attach/detach, display, brightness and suspend. -Retained firmware/DMA state is not reset as a fallback after a timeout. diff --git a/Documentation/arch/arm64/index.rst b/Documentation/arch/arm64/index.rst index cd82b573e7bfd..72e1fa881a94a 100644 --- a/Documentation/arch/arm64/index.rst +++ b/Documentation/arch/arm64/index.rst @@ -9,13 +9,6 @@ ARM64 Architecture acpi_object_usage amu - ../../driver-api/firmware/aurora-apif - ../../driver-api/firmware/aurora-apif-nvme - ../../driver-api/firmware/aurora-apif-pcie - ../../driver-api/firmware/aurora-apif-pmp - ../../driver-api/firmware/aurora-apif-display - aurora-apif-centauri - aurora-apif-platform apple-j813 apple-m6-cpu arm-acpi diff --git a/Documentation/driver-api/firmware/aurora-apif-display.rst b/Documentation/driver-api/firmware/aurora-apif-display.rst deleted file mode 100644 index 8da1054cc8c78..0000000000000 --- a/Documentation/driver-api/firmware/aurora-apif-display.rst +++ /dev/null @@ -1,99 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -DCP display in an Aura guest -=========================== - -The firmware-27 display profile uses the normal IOMFB shared-memory -transport and compact AFK framing. It supplies a separate method/callback -table and present serializer. The existing queued present, framebuffer -retention, backlight policy, Type-C routing and suspend drain are shared -with the public driver. - -This is display-controller support. It does not add AGX acceleration. - -Loader contract ---------------- - -The loader leaves each coprocessor running with its firmware translations -intact. The driver negotiates RTKit without writing its CPU run state or -restarting the coprocessor. A missing running session or a firmware ABI -other than the explicit apple,firmware-compat = <27 0 0> is rejected. - -The internal and external providers use apple,t6050-dcp and -apple,t6050-dcpext respectively. The profile uses a 41-bit DMA -aperture for the coprocessor CPU; scanout and PIODMA retain their independent apertures. - -Each provider describes its inherited framebuffer region using -memory-region and the framebuffer entry in memory-region-names. -Default-surface allocation uses firmware-reported geometry, format and -compression. Unsupported layouts or allocations larger than that region -are rejected. - -apple,clock-ids describes the ordered firmware provider clock table. -Its entry count must match clocks. An explicitly empty property is -accepted for a provider with no clocks; a missing property is rejected. -A callback clock index selects the corresponding Linux clock. - -Display register callbacks normally use resource physical addresses. -If Linux resources are translated guest addresses, the loader supplies -apple,firmware-physical-regs in complete register-table order, -including the bandwidth scratch and optional doorbell apertures. These -addresses are returned to the coprocessor, not dereferenced by Linux. - -The loader must also grant the reserved firmware buffers needed by AFK -through the corresponding IOMMU provider. Remote requests remain bounded -and fail if their device addresses cannot be translated. - -Direct DisplayPort routes -------------------------- - -Protocol-27 DPTX uses endpoint 0x2c and its own drive-settings records. -The explicit service unit takes precedence over the transport interface -identifier. Drive requests validate lane count and voltage/pre-emphasis -before changing the PHY. - -The PHY reports its live clock and coding mode to the crossbar consumer. -A missing required provider or conflicting clock configuration fails the -link operation. Other PHY types retain their existing routing behavior. - -Session lifetime ----------------- - -An adopted session has no confirmed DMA stop boundary. Failed probes and -unbind therefore retain published buffers, mappings and device/domain -references until a fresh firmware boot. Rebinding a retained session is -unsupported. No timeout falls back to resetting a live coprocessor. - -Validation ----------- - -Native arm64 display-driver builds and host tests cover the present wire -layout and framebuffer sizing/bounds. These checks do not establish boot, -physical hotplug, brightness or suspend behavior on hardware. - -Paired firmware-27 scanout -------------------------- - -The T6050 peer allocator consumes reported endpoint capacity and explicit -firmware tiling metadata. It may reserve only an idle, otherwise unrouted -peer on the same DRM device and display die. Physical Type-C routes remain -owned by their normal allocator. The current qualification gates are -``appledrm.peer_allocation_probe=1`` and ``appledrm.peer_scanout=1``; they -match the private baseline's explicit configuration and remain off until -the cleaned combination is qualified. ``appledrm.show_notch=1`` is independent. - -Both wire records are serialized from the primary's logical atomic input -without mutating it. Cross-endpoint start replies, errors and combined -completion watermarks are copied to a bounded callback queue on the owning -IOMFB worker. They never take another endpoint's IOMFB lock from a receive -callback. Normal command/transaction ordering and retained-framebuffer -ownership remain in the common IOMFB implementation. One physical engine's -completion cannot retire the pair. A failed peer submission may follow -acceptance by the primary, so it retains the active transaction and scanout -references as a crashed session rather than treating the error as retirement. - -The background-only paired probe also uses one tracked transaction per -endpoint and cannot run while the paired production completion owner is active. -Host checks cover copied callback dispatch, stop/cancellation, paired completion -coverage and split-wire serialization. Build/host evidence does not replace -physical display, hotplug, DPMS, sleep or paired-frame qualification. diff --git a/Documentation/driver-api/firmware/aurora-apif-nvme.rst b/Documentation/driver-api/firmware/aurora-apif-nvme.rst deleted file mode 100644 index ab4e9b7088bad..0000000000000 --- a/Documentation/driver-api/firmware/aurora-apif-nvme.rst +++ /dev/null @@ -1,39 +0,0 @@ -Resident ANS over APIF -====================== - -``apple,nvme-apif`` selects the native table-6 queue ABI. It keeps the -existing Apple NVMe queue depth, batching, crypto fields, recovery ownership -and synchronous post-M4 flush policy. Linux builds and translates the TCB -and physical page list; Aura forwards selectors and arguments unchanged. -No payload copying or monitor-side NVMe policy is required. - -The boot producer must quiesce RTKit and stop controller DMA before Linux -starts. It supplies ``asahi,rtkit-quiesced`` and four distinct reserved-memory -pages named ``admin-sq``, ``admin-cq``, ``io-sq`` and ``io-cq``. Each is coherent, -16 KiB aligned, 16 KiB sized and ``no-map``. Their guest addresses must map to -the native physical pages already registered with the firmware. Linux clears -and reuses those pages; it does not substitute new queue addresses. They stay -reserved after unbind because the native queue registrations survive it. - -This profile requires an identity DMA aperture. It checks each request's -physical translation against the DMA address in its command and PRP chain. -An offset aperture is rejected before native request registration. Native -metadata addresses are independently translated, including the scratch TCB -and page list. Queue-control and MAP endpoints return void; UNMAP must return -one before a request's backing can be reused. - -A lost MAP response retains that request and prevents new registration until -recovery has stopped the controller and explicitly invalidated every retained -tag. Failed invalidation quarantines the controller and retains its DMA, -requests and APIF client until platform reset. SART unmap failures also retain -Linux-owned backing. These are ownership failures, not successful I/O. - -Live RTKit adoption is deliberately excluded from this new profile: controller -CC.EN/RDY alone cannot prove a live mailbox session or authorize inherited -buffers outside guest RAM. Existing raw-controller profiles keep their existing -validated adoption path. The guest producer must provide the stopped handoff -above; a version-1 live-session DT is not a drop-in replacement. - -Build and host fault tests do not qualify this path on hardware. Boot, -read/write/flush durability, controller reset and teardown must be tested with -the matching Aura version-2 monitor and generated handoff description. diff --git a/Documentation/driver-api/firmware/aurora-apif-pcie.rst b/Documentation/driver-api/firmware/aurora-apif-pcie.rst deleted file mode 100644 index fd366c73ef77f..0000000000000 --- a/Documentation/driver-api/firmware/aurora-apif-pcie.rst +++ /dev/null @@ -1,30 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -Preinitialized PCIe guests -========================= - -``apple,apif-pcie`` admits an ECAM host whose producer has already configured -its clocks, PHY, link, address windows and RID-to-SID routes. The producer -must stop endpoint DMA and MSI before transferring ownership. Linux allocates -MSI vectors from the single native four-cell AIC edge range in ``msi-ranges``; -the doorbell is supplied by ``apple,msi-address``. Vector counts and addresses -are checked before the routing tables are touched. No polling interrupt path -or fixed IRQ assignment per function is introduced. - -A second compatible, ``apple,t6050-pcie-apif``, selects the known port-0 -register layout and supplies port, PHY, PERST and interrupt-to-AXI resources. -It restores explicit ``apple,rid-to-sid`` tuples and the same declared MSI -range after a controlled preboot cycle. Tunables come from the boot producer. -Unknown layouts use only ECAM/MSI; they cannot enter the T6050 reset sequence. - -``apple_apif_pcie_cycle()`` is for the isolated N1 ROM/preboot function before -radio functions are enumerated or have live DMA. The caller must quiesce all -activity on that unit. PCI topology locking excludes sibling functions, and -DART transitions refuse other Linux groups or retained firmware streams. -Timeouts are bounded. A partial transition leaves bus mastering and bridge -decoding stopped; it does not attempt a speculative DMA restart. This is not -a general PCI bus reset API and does not add N1 Wi-Fi/Bluetooth drivers. - -The generic host and its matched port sequence require hardware qualification -with the matching Aura monitor and boot description. Host sequence tests and -native builds do not establish link recovery or radio firmware behavior. diff --git a/Documentation/driver-api/firmware/aurora-apif-pmp.rst b/Documentation/driver-api/firmware/aurora-apif-pmp.rst deleted file mode 100644 index e15e69bf07ee8..0000000000000 --- a/Documentation/driver-api/firmware/aurora-apif-pmp.rst +++ /dev/null @@ -1,35 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -Registry-v2 PMP guests -====================== - -The matched ``apple,t6050-pmp-v2`` firmware ABI uses 88-byte registry -descriptors, firmware-assigned 16-bit IDs, negotiated value buffers, and -update opcode ``0x36``. Linux validates descriptor sizes and names, rejects -duplicate live IDs, and bounds every shared-buffer copy. Boot arguments are -validated completely before any patch is written back. Board and calibration -values come from the boot description; no machine-name policy is embedded. - -The existing T6000 protocol and T8140 42-bit DMA mask remain unchanged. -Registry-v2 configures a 48-bit mailbox DMA address mask and requires an -attached IOMMU domain before starting the processor. Its APIF DART description -must retain the firmware streams, aperture and final-page guard reported by -the producer. A missing provider must not permit direct-DMA fallback. - -Probe accepts only the known cold context marker with the CPU stopped and no -retained DMA context. Unbind and reboot request RTKit idle, verify the matched -context-save marker/version and save counter, then clear CPU_RUN and check -its readback. Firmware allocations cannot be freed merely because RTKit -acknowledged a power state. A failed stop drains callbacks but retains both -shared RTKit backing and the PMP allocation owner until platform reset; it -also leaves the cold-reprobe check unable to admit the retained context. - -The driver owns registry-v2 RTKit outside the callback context, avoiding an -Arc ownership cycle. The notifier is removed and drained before the RTKit -handle or context is released. Probe failure after firmware start follows -the same stop-or-retain ownership path. Endpoint-7 auxiliary buffers are -session-owned; identical requests reuse them rather than replacing live DMA. - -This is support for the inspected firmware ABI, not a generic promise that -later PMP layouts use the same context registers. Hardware cold boot, -registry exchange, idle/save, reboot and unbind qualification remain pending. diff --git a/Documentation/driver-api/firmware/aurora-apif.rst b/Documentation/driver-api/firmware/aurora-apif.rst deleted file mode 100644 index 1622f49dd426e..0000000000000 --- a/Documentation/driver-api/firmware/aurora-apif.rst +++ /dev/null @@ -1,100 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0-only - -=============================================== -Aurora Platform Interface over Memory-Mapped I/O -=============================================== - -Aura is Aurora's EL2-resident monitor for Apple Silicon, providing SPTM -mediation and nested virtualization. APIF is a synchronous, trusted-kernel -transport. Linux supplies native selectors and endpoint arguments; Aura -forwards them unchanged. Invalid native calls can stop the machine. This -interface does not isolate an untrusted kernel. - -Wire contract -============= - -The version-2 synthetic register page occupies 16 KiB at guest IPA 0x61ff0000. -Registers are little-endian 64-bit fields: magic at 0x000 is -0x4f494d4d46495041 (APIFMMIO), version at 0x008 is 2, maximum operations at -0x010, and feature flags at 0x018 (bit 0 native, bit 1 memory, bit 2 I/O). -A 64-bit write at 0x100 supplies a 16-byte-aligned guest IPA for the batch. -The entire buffer must fit within one guest RAM bank. The register page is -unmapped at guest stage 2; Aura handles its data aborts. - -A batch has a 16-byte header (u32 count, u32 flags, s32 status, u32 done), -then count 64-byte operations (u64 selector, u64 arg[6], u64 ret). Flags are -zero. Selector upper/lower halves give native table/endpoint (x16); arguments -are native x0-x5 and ret is native x0, unchanged. Transport status does not -interpret native results. Void and boolean endpoints need different caller -handling. A failed Aura service stops the batch; done is the completed prefix. - -Each client owns a physically contiguous buffer and serializes its submissions -with IRQs masked. The transport orders memory around the trapping store and -preserves the Linux stack in x9 across the synchronous redispatch contract. -Device links order supplier lifetime; client revocation drains submissions and -subsequent calls return ENODEV. It is safe to call from atomic context. Provider -and consumers must be described together in the guest DT; this series does not -rewrite existing board DTs or enable the backend on an existing boot. - -Ownership services -================== - -Table 0xffffffff supplies Aura services (other tables are native selectors): - -* 1 TRANSLATE(guest IPA, size): native PA for a contiguous guest range. -* 2 ALLOC_FRAME(owner, address): zeroed 16 KiB native frame, CPU alias removed. -* 3 FREE_FRAME(PA): restore Aura's alias after detachment and retype to type 11. -* 4 MAP_IO(guest IPA, PA, size, readonly): map bounded page-aligned device I/O. -* 5 GUEST_ROOT(): guest stage-2 root PA. -* 6 BOOT_IOMMU(kind, unit, SID, index, output IPA, size): bootstrap snapshot. -* 7 BOOT_TABLE(kind, unit, SID, address, level): existing bootstrap table PA. -* 8 FIND_FRAME(owner, address): registered lent frame PA or zero. -* 9 TAG_FRAME(PA, owner, address): register a unique opaque key after attachment. - -Unused arguments are zero. Frame keys are bookkeeping, not an ownership -transition. The pool is capped at 1024 frames. Never free attached or uncertain -frames. MAP_IO does not roll back a partially successful mapping; a failed -mapping requires recovery before its address range can be reused. Initialize -batch status to EINPROGRESS so a missing completion cannot be mistaken for -success. Lost table-operation completion stops further DART transactions. - -BOOT_IOMMU kind 0 means DART. Index U64_MAX returns root level, run count and -DVA aperture; another index returns a retained mapping. The 64-byte output is -u64 level, count, base, size, pa, ipa, attrs, reserved. An unavailable IPA is -U64_MAX. BOOT_TABLE levels 0-2 return existing bootstrap tables, while U64_MAX -returns the bootstrap initialized flag. Bootstrap queries never replay maps. - -DART and SART providers -======================= - -APPLE_DART_APIF supplies an IOMMU provider for apple,dart-apif. It preserves -stream groups, shared IOVA allocation, retained mappings, bounded batches and -partial-prefix rollback. Linux builds native physical page lists, complements -IOMMU allow bits into native deny bits, and sets up typed tables. Both DMA -backing and list-buffer pointers are translated before native calls. Retained -streams remain reserved and are excluded from ordinary power-down. - -APPLE_SART_APIF supplies apple,sart-apif through the existing apple_sart API. -The raw MMIO provider continues using its current operations. The APIF provider -tracks Linux-owned regions and respects endpoint-specific return semantics; -unknown firmware grants are not advertised as inherited. Neither provider -prints routine successful calls or runs probe-time mapping self-tests. - -The existing arm64 TSO task interface discovers guest ACTLR support through -its toggle/readback probe; APIF does not add a second TSO protocol. The Apple -WFI preservation quirk also covers captured T6050 parts 0x064/0x065. These -parts also avoid unsafe timed waits in arbitrary delay callers. The current -boot-time idle quirk and existing CPU handling are preserved. This does not claim future Ultra support. - -Validation -========== - -Build the providers and run the production-function host tests with:: - - make ARCH=arm64 LLVM=1 Image - make -C tools/testing/selftests/aurora-apif run_tests - -Host tests exercise framing, prefix completion, ownership ordering, list -translation and endpoint return handling. Hardware validation of this cleaned -version-2 integration is pending. GPU backend changes are outside this series; -legacy version-1 Aura aliases remain available to existing clients. diff --git a/Documentation/driver-api/firmware/index.rst b/Documentation/driver-api/firmware/index.rst index ada189185094c..86a3dd4bc3f8a 100644 --- a/Documentation/driver-api/firmware/index.rst +++ b/Documentation/driver-api/firmware/index.rst @@ -4,10 +4,6 @@ Linux Firmware API .. toctree:: - aurora-apif - aurora-apif-nvme - aurora-apif-pcie - aurora-apif-pmp introduction core efi/index diff --git a/MAINTAINERS b/MAINTAINERS index fc20e250d5476..b13c1507cf391 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4566,35 +4566,12 @@ AURORA N1 CENTAURI TRANSPORT M: Dj L: linux-wireless@vger.kernel.org S: Maintained -F: Documentation/arch/arm64/aurora-apif-centauri.rst F: Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml F: Documentation/devicetree/bindings/net/bluetooth/apple,centauri.yaml F: drivers/bluetooth/btcentauri.c F: include/linux/apple-centauri.h F: drivers/net/wireless/apple/ -AURORA PLATFORM MMIO INTERFACE -M: Dj -S: Maintained -F: Documentation/devicetree/bindings/firmware/aurora,apif-mmio.yaml -F: Documentation/devicetree/bindings/iommu/apple,dart-apif.yaml -F: Documentation/devicetree/bindings/soc/apple/apple,sart-apif.yaml -F: Documentation/driver-api/firmware/aurora-apif*.rst -F: Documentation/devicetree/bindings/nvme/apple,nvme-apif.yaml -F: Documentation/devicetree/bindings/pci/apple,apif-pcie.yaml -F: arch/arm64/configs/aurora-apif.config -F: drivers/nvme/host/apple-apif.h -F: drivers/pci/controller/apple-apif/ -F: include/linux/pci-apple-apif.h -F: tools/aurora-apif/ -F: drivers/firmware/aurora-apif-mmio.c -F: drivers/iommu/apple-dart-apif.c -F: drivers/soc/apple/apple-sart-apif.c -F: drivers/soc/apple/sart-backend.h -F: include/linux/apple-dart-apif.h -F: include/linux/soc/aurora/apif-mmio.h -F: tools/testing/selftests/aurora-apif/ - AUXILIARY DISPLAY DRIVERS M: Andy Shevchenko R: Geert Uytterhoeven From 0bcf5e810ab60d0868ee3e96fdce013b47587736 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 05:59:04 +1100 Subject: [PATCH 321/342] soc: apple: add probe-only S8000 AES diagnostics (#1328) * dt-bindings: crypto: describe Apple S8000-family AES engines Describe the two- and three-aperture layouts, per-SoC compatibles, AES power domain and SIO DART streams. Keep key-disable register layout selection tied to the SoC compatible. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> * soc: apple: add probe-only SIO AES diagnostics Read the readiness and hardware-key disable words once under runtime PM, then expose the cached snapshot in a root-readable debugfs file. Report the revision from compatible data and leave unverified bitfields undecoded. Do not enable the engine, request interrupts, access the command FIFO or DKEY aperture, allocate DMA buffers, or register a crypto or userspace device interface. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> * arm64: dts: apple: describe disabled SIO AES engines Add AES nodes for T6000, T8112, T6041 and T8140 with named apertures, power domains and SIO DART stream 1. Describe the missing T8140 SIO DART provider as disabled as well. All new nodes remain opt-in. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> * soc: apple: use existing AES register resource order Map engine and key-disable resources by index as ordered by apple,aes.yaml so reg-names are not required. Continue to leave the optional DKEY bank and IRQ untouched, and retain the SoC-specific matches and probe-only read path. Update the module author address. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --------- Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/soc/apple/Kconfig | 14 +++ drivers/soc/apple/Makefile | 2 + drivers/soc/apple/apple-sio-aes.c | 194 ++++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 drivers/soc/apple/apple-sio-aes.c diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 113e09aea5c47..9001a709fb6e7 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -4,6 +4,20 @@ if ARCH_APPLE || COMPILE_TEST menu "Apple SoC drivers" +config APPLE_SIO_AES + tristate "Apple SIO AES probe-time diagnostics" + depends on OF && HAS_IOMEM && PM && IOMMU_API + help + Capture the S8000-family AES readiness and hardware-key disable + state once at probe on T6000, T8112, T6041 and T8140. The snapshot + is logged and available in a root-readable debugfs state file. + Revision is reported from the SoC compatible; register words are + raw diagnostics, not a claim that a hardware key is usable. + + This does not enable the engine, submit commands, handle interrupts, + register crypto algorithms or provide a device node. Keep the DT + node disabled except during an explicitly enabled diagnostic boot. + config APPLE_DBGVIEW tristate "Apple SoC read-only debug register views" depends on ARCH_APPLE || COMPILE_TEST diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 5ef85752f160d..34ede633d2165 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_APPLE_SIO_AES) += apple-sio-aes.o + obj-$(CONFIG_APPLE_DBGVIEW) += apple-dbgview.o apple-dbgview-y = dbgview.o diff --git a/drivers/soc/apple/apple-sio-aes.c b/drivers/soc/apple/apple-sio-aes.c new file mode 100644 index 0000000000000..4432f2976ee77 --- /dev/null +++ b/drivers/soc/apple/apple-sio-aes.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Probe-time diagnostics for the Apple S8000-family SIO AES engine. + * Only the readiness word and key-disable state are read. In particular, + * do not initialise the engine, acknowledge interrupts or touch the FIFO. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_SIO_AES_READINESS 0x0c + +struct apple_sio_aes_data { + u32 revision; + /* Revision 3 has a shared word; revision 5 has per-slot words. */ + bool shared_disable; + u32 uid_offset; + u32 gid0_offset; + u32 gid1_offset; +}; + +struct apple_sio_aes { + const struct apple_sio_aes_data *data; + u32 readiness; + u32 disable; + u32 uid_disable; + u32 gid0_disable; + u32 gid1_disable; +}; + +static int apple_sio_aes_state_show(struct seq_file *s, void *unused) +{ + const struct apple_sio_aes *aes = s->private; + + seq_puts(s, "snapshot: probe\n"); + seq_printf(s, "revision_from_compatible: %u\n", aes->data->revision); + seq_printf(s, "readiness_raw: %#010x\n", aes->readiness); + seq_printf(s, "disable_raw: %#010x\n", aes->disable); + if (aes->data->shared_disable) { + seq_puts(s, "uid_gid_disable: shared word, slot bits undecoded\n"); + } else { + seq_printf(s, "uid_disable_raw: %#010x\n", aes->uid_disable); + seq_printf(s, "gid0_disable_raw: %#010x\n", aes->gid0_disable); + seq_printf(s, "gid1_disable_raw: %#010x\n", aes->gid1_disable); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(apple_sio_aes_state); + +static void apple_sio_aes_debugfs_remove(void *dir) +{ + debugfs_remove_recursive(dir); +} + +static void __iomem *apple_sio_aes_map(struct platform_device *pdev, + unsigned int index, resource_size_t min_size) +{ + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, index); + if (!res || resource_size(res) < min_size) + return IOMEM_ERR_PTR(-EINVAL); + + return devm_ioremap_resource(&pdev->dev, res); +} + +static int apple_sio_aes_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + const struct apple_sio_aes_data *data; + void __iomem *engine, *disable; + struct apple_sio_aes *aes; + struct dentry *dir; + char *name; + int ret; + + data = of_device_get_match_data(dev); + if (!data) + return -ENODEV; + + /* The platform bus attaches the single power domain and SIO DART. */ + if (!dev->pm_domain || !of_property_present(dev->of_node, "power-domains")) + return dev_err_probe(dev, -EINVAL, "Missing AES power domain\n"); + if (!of_property_present(dev->of_node, "iommus") || + !iommu_get_domain_for_dev(dev)) + return dev_err_probe(dev, -ENODEV, "Missing SIO DART domain\n"); + + aes = devm_kzalloc(dev, sizeof(*aes), GFP_KERNEL); + if (!aes) + return -ENOMEM; + aes->data = data; + + /* apple,aes orders the banks as engine, key-disable, then optional DKEY. */ + engine = apple_sio_aes_map(pdev, 0, APPLE_SIO_AES_READINESS + 4); + if (IS_ERR(engine)) + return dev_err_probe(dev, PTR_ERR(engine), "Invalid engine aperture\n"); + disable = apple_sio_aes_map(pdev, 1, data->gid1_offset + 4); + if (IS_ERR(disable)) + return dev_err_probe(dev, PTR_ERR(disable), "Invalid key-disable aperture\n"); + + /* The DKEY aperture and IRQ are described by DT but never accessed. */ + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to power AES for snapshot\n"); + + /* No polling or decoding of unverified readiness/disable bitfields. */ + aes->readiness = readl(engine + APPLE_SIO_AES_READINESS); + aes->disable = readl(disable); + if (!data->shared_disable) { + aes->uid_disable = readl(disable + data->uid_offset); + aes->gid0_disable = readl(disable + data->gid0_offset); + aes->gid1_disable = readl(disable + data->gid1_offset); + } + + ret = pm_runtime_put_sync_suspend(dev); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to release AES power\n"); + + if (data->shared_disable) + dev_info(dev, + "probe snapshot: revision %u (compatible), readiness %#010x, shared UID/GID disable %#010x (undecoded)\n", + data->revision, aes->readiness, aes->disable); + else + dev_info(dev, + "probe snapshot: revision %u (compatible), readiness %#010x, disable %#010x, UID %#010x, GID0 %#010x, GID1 %#010x (raw)\n", + data->revision, aes->readiness, aes->disable, + aes->uid_disable, aes->gid0_disable, aes->gid1_disable); + + name = devm_kasprintf(dev, GFP_KERNEL, "apple-sio-aes-%s", dev_name(dev)); + if (!name) + return -ENOMEM; + dir = debugfs_create_dir(name, NULL); + if (IS_ERR(dir)) + return 0; + ret = devm_add_action_or_reset(dev, apple_sio_aes_debugfs_remove, dir); + if (ret) + return ret; + debugfs_create_file("state", 0400, dir, aes, &apple_sio_aes_state_fops); + + return 0; +} + +static const struct apple_sio_aes_data apple_sio_aes_v3 = { + .revision = 3, + .shared_disable = true, +}; + +static const struct apple_sio_aes_data apple_sio_aes_t6041 = { + .revision = 5, + .uid_offset = 0x04, + .gid0_offset = 0x08, + .gid1_offset = 0x0c, +}; + +static const struct apple_sio_aes_data apple_sio_aes_t8140 = { + .revision = 5, + .uid_offset = 0x40, + .gid0_offset = 0x44, + .gid1_offset = 0x48, +}; + +static const struct of_device_id apple_sio_aes_of_match[] = { + { .compatible = "apple,t6000-aes", .data = &apple_sio_aes_v3 }, + { .compatible = "apple,t8112-aes", .data = &apple_sio_aes_v3 }, + { .compatible = "apple,t6041-aes", .data = &apple_sio_aes_t6041 }, + { .compatible = "apple,t8140-aes", .data = &apple_sio_aes_t8140 }, + { } +}; +MODULE_DEVICE_TABLE(of, apple_sio_aes_of_match); + +static struct platform_driver apple_sio_aes_driver = { + .probe = apple_sio_aes_probe, + .driver = { + .name = "apple-sio-aes", + .of_match_table = apple_sio_aes_of_match, + }, +}; +module_platform_driver(apple_sio_aes_driver); + +MODULE_DESCRIPTION("Apple SIO AES probe-time read-only diagnostics"); +MODULE_AUTHOR("Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>"); +MODULE_LICENSE("GPL"); From 26d61797c7aec2f82758f24512b92461d4a1be67 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 05:59:23 +1100 Subject: [PATCH 322/342] Revert "arm64: dts: apple: attach the Neo internal PCIe host to its full power chain" This reverts commit 5c96ab0a5f97a. The Neo change has not been tested on hardware yet; it comes back as its own change once it has. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8140.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8140.dtsi b/arch/arm64/boot/dts/apple/t8140.dtsi index 4242e655a3af7..b781dd756a2d2 100644 --- a/arch/arm64/boot/dts/apple/t8140.dtsi +++ b/arch/arm64/boot/dts/apple/t8140.dtsi @@ -1206,7 +1206,7 @@ #size-cells = <2>; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; - power-domains = <&ps_apcie_phy_sw>; + power-domains = <&ps_apcie_gp>; status = "disabled"; pcie0_port0: pci@0,0 { From 0cc9479d28ae508a5bea6e849434ec2b12701f5a Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 07:01:56 +1100 Subject: [PATCH 323/342] tools/asahi: tbnet-refill: Model the login retry and login answer worker tbnet_connect_failed_locked() now starts a new login after TBNET_LOGIN_DELAY and tbnet_stop() cancels the login answer worker. Give the fixture the new struct tbnet members and constants, and count a login retry apart from the Rx refill retry, whose 100 ms delay the fixture still checks. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/asahi/tbnet-refill-fixture.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/asahi/tbnet-refill-fixture.h b/tools/asahi/tbnet-refill-fixture.h index d9dee1baab9b2..aa2218f8af8c7 100644 --- a/tools/asahi/tbnet-refill-fixture.h +++ b/tools/asahi/tbnet-refill-fixture.h @@ -16,6 +16,8 @@ #define TBNET_RX_PAGE_SIZE (PAGE_SIZE<work.fn=(f)) static _Thread_local int heldmutex; @@ -92,7 +96,7 @@ static bool fake_softirq; static bool in_softirq(void){return fake_softirq;} static int smp_processor_id(void){return 0;} static void schedule_work(struct work_struct *w){} -static bool queue_delayed_work(int wq,struct delayed_work *w,unsigned long delay){assert(delay==100);pthread_mutex_lock(&gate);bool new=!w->pending;if(new){w->pending=true;retry_queues++;retry_delay=delay;}pthread_mutex_unlock(&gate);return new;} +static bool queue_delayed_work(int wq,struct delayed_work *w,unsigned long delay){if(delay==TBNET_LOGIN_DELAY){assert(w==&container_of(w,struct tbnet,login_work)->login_work);login_queues++;return true;}assert(delay==100);pthread_mutex_lock(&gate);bool new=!w->pending;if(new){w->pending=true;retry_queues++;retry_delay=delay;}pthread_mutex_unlock(&gate);return new;} static void cancel_delayed_work_sync(struct delayed_work *w) { pthread_mutex_lock(&gate); From 960e1634f86683c3a413dd1a308086d06c595e75 Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 07:26:47 +1100 Subject: [PATCH 324/342] selftests: apple-dcp: Expect CD321x to watch a router present at probe CD321x now watches for the USB4/Thunderbolt router to register a new switch also when the router is already there at probe, so that it takes the new switch after an unbind and bind. Update the typec-probe case: a port probed with its router holds the watch until it is unregistered, and a watch that cannot start leaves the port probed with the router it has. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- tools/testing/selftests/drivers/gpu/apple-dcp/pm.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/pm.py b/tools/testing/selftests/drivers/gpu/apple-dcp/pm.py index 8cae88d722d88..92ccae9ed052f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/pm.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/pm.py @@ -747,8 +747,14 @@ def function(text, name): assert(cd321x_register_port(&c.tps,&connector)==0&&c.state_valid&&!c.tbt_switch); assert(!watches&&!c.tbt_watch_registered&&!c.tbt_fwnode); cd321x_unregister_port(&c.tps);balanced(); - /* A router present at probe needs no watch. */ - reset(&c);assert(cd321x_register_port(&c.tps,&connector)==0&&c.tbt_switch&&!watches); + /* A router present at probe is watched too: it can unbind and bind again with a new switch. */ + reset(&c);assert(cd321x_register_port(&c.tps,&connector)==0&&c.tbt_switch); + assert(watches==1&&c.tbt_watch_registered&&c.tbt_fwnode==&connector); + cd321x_unregister_port(&c.tps);balanced(); + /* Without that watch the port still probes with the router it has. */ + reset(&c);watch_error=-ENOMEM; + assert(cd321x_register_port(&c.tps,&connector)==0&&c.tbt_switch); + assert(!watches&&!c.tbt_watch_registered&&!c.tbt_fwnode); cd321x_unregister_port(&c.tps);balanced(); ''', 1) From e39c9000c3395ea83139c5c313103e3b86c4b837 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 15:53:50 -0500 Subject: [PATCH 325/342] dt-bindings: soc: apple: pmp: Type the firmware's segment names as a string The ADT's iop-pmp nub carries segment-names as a NUL-terminated string ("__TEXT;__DATA" on J813, "__TEXT;__DATA;__ETEXT" on J714s). A DTB has no types, so dt-validate decodes those bytes as a string and the uint8-array pattern rejects them on every board that carries the value (t8142-j813 today). Give the property its own string type and keep it out of the opaque-bytes pattern; the bytes in the DTB do not change. Signed-off-by: Diljit Singh --- .../devicetree/bindings/soc/apple/apple,pmp.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml index 4ae4380167632..7eeca76b274ed 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml @@ -114,8 +114,14 @@ properties: minItems: 2 description: Host physical address and size pairs mapped into firmware PIO space. + apple,tunable-segment-names: + $ref: /schemas/types.yaml#/definitions/string + description: + The firmware's segment names from the Apple device tree, separated by + semicolons. The firmware reads them as the raw string. + patternProperties: - '^apple,tunable-': + '^apple,tunable-(?!segment-names$)': $ref: /schemas/types.yaml#/definitions/uint8-array description: Opaque firmware calibration copied from the Apple device tree. From ce19002def96ef7a4f3f0546dcf1a3b1d030c79f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 15:53:50 -0500 Subject: [PATCH 326/342] arm64: dts: apple: t6050: Name the PMP DART's regions The binding requires reg-names when a DART has a second region. The ADT dart-pmp0 instance list names them DART and DAPF (it also carries dapf-instance-0), so call them "dart" and "dapf". No driver looks them up by name. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-peripherals.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index d3524080347f6..8063b37f816db 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -2286,8 +2286,10 @@ pmp0_dart: iommu@2841a0000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; + /* ADT dart-pmp0 instance: DART, then DAPF */ reg = <0x2 0x841a0000 0x0 0xc000>, <0x2 0x841b0000 0x0 0x4000>; + reg-names = "dart", "dapf"; interrupts = ; #iommu-cells = <1>; /* ADT dart-pmp0 vm-base, vm-size */ From 3e440ed4d1f712d51499a5e919bce8b73d6b230e Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 09:23:14 +1100 Subject: [PATCH 327/342] arm64: dts: apple: t6000: add the SMC rail voltages The M1 Pro MacBook Pros expose no CPU, GPU or SoC rail voltage, though their SMC reports every output of the cluster, GPU and SoC voltage regulators on the CLVR SPMI buses, and macOS reads the same keys. Add them as hwmon voltage channels: VC10-VC13 (CPU P clusters), VC20-VC23 (GPU) and VC30-VC33 (SoC), plus the two main PMU bucks that follow the E cluster (VP0b, VP2b). The keys were mapped on a J316s by holding every cluster at its lowest step and loading one at a time: VC10/VC11 follow the second P cluster (571-906 mV and 770-1060 mV from the lowest to the highest step), VC12/VC13 the first (566-906 mV, 768-1058 mV), VP0b/VP2b the E cluster (547-834 mV, 768-924 mV). VC20-VC23 read 0 mV while the GPU is power-gated and 700-800 mV under load; VC32/VC33 rise with GPU load, VC30/VC31 stay flat. Linux sends nothing on the CLVR buses; the channels are SMC key reads. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../boot/dts/apple/t6000-hwmon-rails.dtsi | 88 +++++++++++++++++++ arch/arm64/boot/dts/apple/t6000-j314s.dts | 1 + arch/arm64/boot/dts/apple/t6000-j316s.dts | 1 + 3 files changed, 90 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t6000-hwmon-rails.dtsi diff --git a/arch/arm64/boot/dts/apple/t6000-hwmon-rails.dtsi b/arch/arm64/boot/dts/apple/t6000-hwmon-rails.dtsi new file mode 100644 index 0000000000000..7d1070efb8ccc --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6000-hwmon-rails.dtsi @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * T6000 rail voltages published by the SMC. + * + * The three CLVR SPMI buses (clvr-spmi0-2) connect the SMC to the cluster, + * GPU and SoC voltage regulators. Linux leaves those buses to the SMC and + * reads the SMC's VCxy keys instead (x = bus + 1, y = regulator output). + * With the other clusters held at their lowest step, one cluster under load + * moves only its own keys: + * P0 cluster (cpu2-5): VC12 566-906 mV, VC13 768-1058 mV + * P1 cluster (cpu6-9): VC10 571-906 mV, VC11 770-1060 mV + * GPU: VC20-VC23, 0 mV while power-gated, 700-800 mV under load + * SoC (clvr-spmi2): VC30/VC31 stay flat, VC32/VC33 rise with GPU load + * The E cluster (cpu0-1) is fed by the main PMU: VP0b 547-834 mV and + * VP2b 768-924 mV. + */ + +&smc_hwmon { + voltage-VC10 { + apple,key-id = "VC10"; + label = "P1-cluster VC10"; + }; + + voltage-VC11 { + apple,key-id = "VC11"; + label = "P1-cluster VC11"; + }; + + voltage-VC12 { + apple,key-id = "VC12"; + label = "P0-cluster VC12"; + }; + + voltage-VC13 { + apple,key-id = "VC13"; + label = "P0-cluster VC13"; + }; + + voltage-VC20 { + apple,key-id = "VC20"; + label = "GPU VC20"; + }; + + voltage-VC21 { + apple,key-id = "VC21"; + label = "GPU VC21"; + }; + + voltage-VC22 { + apple,key-id = "VC22"; + label = "GPU VC22"; + }; + + voltage-VC23 { + apple,key-id = "VC23"; + label = "GPU VC23"; + }; + + voltage-VC30 { + apple,key-id = "VC30"; + label = "SoC VC30"; + }; + + voltage-VC31 { + apple,key-id = "VC31"; + label = "SoC VC31"; + }; + + voltage-VC32 { + apple,key-id = "VC32"; + label = "SoC VC32"; + }; + + voltage-VC33 { + apple,key-id = "VC33"; + label = "SoC VC33"; + }; + + voltage-VP0b { + apple,key-id = "VP0b"; + label = "E-cluster VP0b"; + }; + + voltage-VP2b { + apple,key-id = "VP2b"; + label = "E-cluster VP2b"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6000-j314s.dts b/arch/arm64/boot/dts/apple/t6000-j314s.dts index 2286e31c8f59a..01108aa644dca 100644 --- a/arch/arm64/boot/dts/apple/t6000-j314s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j314s.dts @@ -18,6 +18,7 @@ #include "t6000.dtsi" #include "t600x-j314-j316.dtsi" +#include "t6000-hwmon-rails.dtsi" / { compatible = "apple,j314s", "apple,t6000", "apple,arm-platform"; diff --git a/arch/arm64/boot/dts/apple/t6000-j316s.dts b/arch/arm64/boot/dts/apple/t6000-j316s.dts index 51e615c5ccf0d..13a6826ae5374 100644 --- a/arch/arm64/boot/dts/apple/t6000-j316s.dts +++ b/arch/arm64/boot/dts/apple/t6000-j316s.dts @@ -17,6 +17,7 @@ #include "t6000.dtsi" #include "t600x-j314-j316.dtsi" +#include "t6000-hwmon-rails.dtsi" / { compatible = "apple,j316s", "apple,t6000", "apple,arm-platform"; From e7f996f17c2c4b33f3c0903aa72b249e776f7417 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:42:38 -0600 Subject: [PATCH 328/342] arm64: dts: apple: t6050-j714c: Run the PMP and enable the right USB-C port (#1391) * arm64: dts: apple: t6050-j714c: Run the PMP and report the GPU to it Enable the PMP on the M5 Max 14-inch the way the J714s does since #1376: the PMP with its boot arguments, mailbox, DART and power states, the PMP report, the PMC's agent 0 and the GPU's request in the report. They stay enabled together, so the GPU never waits on a disabled report. The CLPC keeps its vote; the PMC takes the higher of the two. The values come from ADTs of the same silicon, not from a J714c unit: - apple,board-id is 10, the J714c's board ID (0x0a; the N1 platform ID above has it too). - apple,dram-vendor-id is 255 and pmc/pmc-pmgr are 1/63, as a J716c reports them. They are only fallbacks: the boot loader copies /chosen and the PMGR's values over them. - t6050-max-pmp-tunables.dtsi is the 173 iop-pmp0-nub properties of a J716cAP 27.0 ADT, raw bytes, in the format of the J714s file. The J714cAP and J716cAP firmware ADTs have identical PMP nodes (props and all 29 variant sub-nodes), and the h17c-family variant tables of that firmware ADT reproduce 166 of the 173 values; the other seven (the AGX DVFS voltages, the segment ranges and names, pre-loaded and three variant picks) are runtime values iBoot fills in. Not run on a J714c. * arm64: dts: apple: t6050-j716c: Move the right USB-C port into t6050-max-atc2.dtsi The J714cAP and J716cAP firmware ADTs carry identical nodes for the right USB-C port: the HPM on nub-spmi-a1, ATC2's PHY, USB controller and DARTs, the USB4/Thunderbolt router and the PCIe tunnel. Move the J716c's description of them into t6050-max-atc2.dtsi so the J714c can include it instead of a second copy. The host DROM (apple,thunderbolt-drom) stays in the board file: this J716c unit's DROM carries a router UUID from an earlier boot. No change to the J716c: its DTB is byte-identical before and after, and so are the other ten T6050 board DTBs. * arm64: dts: apple: t6050-j714c: Enable the right USB-C port Include t6050-max-atc2.dtsi on the J714c: the right USB-C port's PD controller (nub-spmi-a1, hpm2), ATC2's PHY, USB controller and DARTs, the USB4/Thunderbolt router and the PCIe tunnel. The J714cAP firmware ADT describes them with the same values as the J716cAP one. The ADT also has the PD controllers hpm0 and hpm1 on nub-spmi-a0 and an hpm5; this commit does not describe them or the ports behind them (ATC0, ATC1, ATC3). The nodes the J714c board did not reach are now in t6050-max.dtsi's J714c-and-J716c blocks (ATC2, ACIO2, APCIEC2 and nub-spmi-a1), and t6050-peripherals.dtsi stops adding its own staged nub-spmi-a1 and apciec2_dart for the J714c. apple,thunderbolt-drom is the template value of the J714cAP ADT, not a unit's UUID; the boot loader replaces it. Not run on a J714c. Checked offline: all 11 T6050 board DTBs build with dtc, and the ten other than the J714c are byte-identical to the base tree. dt-validate of the J714c DTB has one warning, the PCIe "port0" in the apciec2 node, which the J716c DTB has already; the J714c had none before. --- arch/arm64/boot/dts/apple/t6050-j714c.dts | 68 ++- arch/arm64/boot/dts/apple/t6050-j716c.dts | 390 +---------------- arch/arm64/boot/dts/apple/t6050-max-atc2.dtsi | 398 ++++++++++++++++++ .../dts/apple/t6050-max-pmp-tunables.dtsi | 184 ++++++++ arch/arm64/boot/dts/apple/t6050-max.dtsi | 4 +- .../boot/dts/apple/t6050-peripherals.dtsi | 4 +- 6 files changed, 655 insertions(+), 393 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t6050-max-atc2.dtsi create mode 100644 arch/arm64/boot/dts/apple/t6050-max-pmp-tunables.dtsi diff --git a/arch/arm64/boot/dts/apple/t6050-j714c.dts b/arch/arm64/boot/dts/apple/t6050-j714c.dts index bfc2e21e909e6..bd4ea3fc0d288 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714c.dts @@ -14,6 +14,7 @@ /dts-v1/; +#define T6050_J714C #include "t6050-max.dtsi" / { @@ -220,5 +221,70 @@ }; }; -#define T6050_J714C #include "t6050-peripherals.dtsi" + +/* + * The PMP (ADT pmp0, /chosen, /arm-io/pmgr), as on the J714s. iBoot loads its firmware and the + * driver starts it with these boot arguments and the firmware properties below. Its report + * tells it which devices are on; it then votes DCS and the fabric for GPU load itself, and the + * PMC honours that next to the CLPC. The report, the PMP's vote and the GPU's request are + * enabled together, so the GPU never waits on a disabled report. + */ +&ps_pms { + status = "okay"; +}; + +&ps_pmp { + status = "okay"; +}; + +&ps_pms_sram { + status = "okay"; +}; + +&pmp0_dart { + status = "okay"; +}; + +&pmp0_mbox { + status = "okay"; +}; + +&pmp0 { + /* The J714c's board ID (0x0a, as in the N1 platform ID above) and the dram-vendor-id a J716c reports */ + apple,board-id = <10>; + apple,dram-vendor-id = <255>; + /* ADT /arm-io/pmgr pmc, pmc-pmgr, as read on a J716c */ + apple,pmc = <1>; + apple,pmc-pmgr = <63>; + status = "okay"; +}; + +&pmp0_report { + status = "okay"; +}; + +&pmc { + /* PMP, CLPC and AP agents, once the PMP runs */ + apple,static-voters = <0 1 3>; + apple,pmp = <&pmp0>; +}; + +&sgx { + power-domains = <&pmp0_gfx>; +}; + +#include "t6050-max-pmp-tunables.dtsi" + +#include "t6050-max-atc2.dtsi" + +/* The host DROM from the J714cAP ADT (/arm-io/acio2 thunderbolt-drom); the boot loader replaces it */ +&acio2_nhi { + apple,thunderbolt-drom = [fd 02 00 00 00 00 00 00 00 90 19 c3 8c 00 5c 00 + 00 00 00 00 00 00 08 81 82 02 82 00 00 00 08 82 + 92 01 82 00 00 00 03 83 20 08 84 00 00 00 00 00 + 00 08 85 00 00 00 00 00 00 05 86 09 01 00 08 87 + 00 00 00 00 00 00 05 88 09 01 00 05 89 09 01 00 + 05 8a 09 01 00 0e 01 41 70 70 6c 65 2c 20 49 6e + 63 2e 00 06 02 69 4f 53 00 00 00 00]; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-j716c.dts b/arch/arm64/boot/dts/apple/t6050-j716c.dts index 25ba638862ca0..1ff75c278ce84 100644 --- a/arch/arm64/boot/dts/apple/t6050-j716c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j716c.dts @@ -223,338 +223,10 @@ #include "t6050-peripherals.dtsi" -/* - * ==== The right USB-C port (ATC2) ==== - * - * ADT /arm-io/nub-spmi-a1/hpm2 (SN201202x, SPMI address 0xc, port-number 3, port-location - * "right", acio-parent acio2), atc-phy2, usb-drd2 and dart-usb2. The HPM is on its own bus, - * nub-spmi-a1, and nothing hands the port off, so the chain is enabled outright. Aura's - * kboot_setup_atc() fills the PHY's tunables through the atcphy2 alias. - */ -/ { - aliases { - atcphy2 = &atc2_phy; - }; -}; - -&ps_atc2_common { - status = "okay"; -}; - -&ps_atc2_usb_aon { - status = "okay"; -}; - -&ps_atc2_phymxwrap { - status = "okay"; -}; - -&ps_atc2_usb { - status = "okay"; -}; - -&atc2_phy_mbox { - status = "okay"; -}; - -&atc2_phy { - status = "okay"; - - port { - atc2_phy_ep: endpoint { - remote-endpoint = <&hpm2_ss>; - }; - }; -}; - -&usb_drd2 { - status = "okay"; - - port { - usb_drd2_hs: endpoint { - remote-endpoint = <&hpm2_hs>; - }; - }; -}; - -&usb_drd2_dart_0 { - status = "okay"; -}; - -&usb_drd2_dart_1 { - status = "okay"; -}; - -/* - * dcpext0's Type-C route stays off with dcpext0: a mode-switch endpoint whose mux is never - * registered would defer the PD controller forever. - */ -&dcpext0 { - typec-routes { - route@0 { - status = "disabled"; - - port { - dcpext0_typec: endpoint { - remote-endpoint = <&hpm2_dp>; - }; - }; - }; - }; -}; - -&nub_spmi_a1 { - hpm2: usb-pd@c { - compatible = "apple,sn201202x"; - reg = <0xc SPMI_USID>; - - connector { - compatible = "usb-c-connector"; - label = "USB-C Right"; - power-role = "dual"; - data-role = "dual"; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@0 { - reg = <0>; - hpm2_hs: endpoint { - remote-endpoint = <&usb_drd2_hs>; - }; - }; - - port@1 { - reg = <1>; - hpm2_ss: endpoint { - remote-endpoint = <&atc2_phy_ep>; - }; - }; - - port@2 { - reg = <2>; - hpm2_dp: endpoint { - remote-endpoint = <&dcpext0_typec>; - }; - }; - }; - }; - }; -}; - -/* - * ==== The right USB-C port's USB4/Thunderbolt router (ATC2) ==== - * - * Until the boot loader fills them, the router, NHI, PHY CIO and DART tunables and the host - * DROM are this board's, from its ADT (the DROM's router UUID from an earlier boot). - */ -/* ATC2_CIO_AUSS's other parent; kept as the boot loader leaves it */ -&ps_auss { - status = "okay"; -}; - -/* The CIO reconfig request, port 2 (clock gate CIO2_RECONFIG_V) */ -&cio_reconfig0 { - status = "okay"; -}; - -/* The PHY's CIO80 RX_TOP tunables (ADT tunable_LN0/LN1_RX_TOP_CIO_DFLT); the other three are empty */ -&atc2_phy { - apple,tunable-lane0-rx-top-cio = <0x35c 0xe00 0x0>; - apple,tunable-lane1-rx-top-cio = <0x35c 0xe00 0x0>; -}; - -/* Only the router's LSTX pin (81) of the AOP GPIO controller is exposed. */ -&pinctrl_aop { - gpio-reserved-ranges = <0 81>, <82 3>; - status = "okay"; -}; - -&hpm2 { - connector { - ports { - port@3 { - reg = <3>; - hpm2_usb4: endpoint { - remote-endpoint = <&acio2_tbt>; - }; - }; - }; - }; -}; - -&acio2 { - apple,tunable-rc = <0x0 0xfff0 0x4020>, - <0x2c 0x4 0x0>, - <0x4004 0x1ff01ff 0x1000100>, - <0x4008 0x801f 0x4>, - <0x4010 0x7f 0x40>, - <0x4014 0x801f 0x4>, - <0x401c 0x7f 0x40>, - <0x4024 0x801f 0x4>, - <0x402c 0x7f 0x40>, - <0x4030 0x801f 0x4>, - <0x4038 0xffffffff 0x1010101>, - <0x403c 0xffff 0x101>, - <0x4040 0x1 0x1>, - <0x4044 0xffffffff 0x1010101>, - <0x4048 0x1 0x1>, - <0x404c 0x801f 0x4>, - <0x8004 0x70007 0x40004>, - <0x8008 0x801f 0x4>, - <0x8010 0x70007 0x40004>, - <0x8018 0x801f 0x4>, - <0x8020 0x70007 0x40004>, - <0x8028 0x801f 0x4>, - <0x8030 0x801f 0x4>, - <0x8038 0x801f 0x4>, - <0x8040 0x801f 0x4>, - <0x8048 0x801f 0x4>, - <0x8050 0x801f 0x4>, - <0x8058 0x801f 0x4>, - <0x8060 0x801f 0x4>; - apple,tunable-pcie-adapter = <0x1008 0x6 0x6>; - apple,tunable-router-ap-fw = <0x8 0xff2 0x482>; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@1 { - reg = <1>; - acio2_tbt: endpoint { - remote-endpoint = <&hpm2_usb4>; - }; - }; - }; -}; - -&acio2_dart { - apple,tunable = <0x20c 0x80000121 0x80000121>, - <0x220 0xf0f 0xf0f>, - <0x224 0xffff 0x909>, - <0x300 0x1f31 0x1>, - <0x308 0x3ffffffc 0x10000000>, - <0x310 0x3ffffffc 0x3ffffffc>, - <0x800 0xf003f 0x10000>, - <0x804 0xf003f 0x10002>, - <0x808 0xf003f 0x10004>, - <0x80c 0xf003f 0x20006>, - <0x810 0xf003f 0x2000a>, - <0x814 0xf003f 0x2000e>, - <0x818 0xf003f 0x20012>, - <0x81c 0xf003f 0x20016>, - <0x820 0xf003f 0x2001a>, - <0x824 0xf003f 0x2001e>, - <0x828 0xf003f 0x20022>, - <0x82c 0xf003f 0x20026>, - <0x830 0xf003f 0x2002a>, - <0x834 0xf003f 0x2002e>, - <0x838 0xf003f 0x20032>, - <0x83c 0xf003f 0x10036>; -}; +#include "t6050-max-atc2.dtsi" +/* This unit's host DROM (router UUID from an earlier boot) */ &acio2_nhi { - apple,tunable-nhi = <0xf8004 0xff 0x80>, - <0xf8008 0x801f 0x4>, - <0xf8010 0x3f 0x20>, - <0xf8014 0x801f 0x4>, - <0xf801c 0x1f 0x10>, - <0xf8020 0x801f 0x4>, - <0xf8028 0xff 0x80>, - <0xf802c 0x801f 0x4>, - <0xf8034 0xff 0x80>, - <0xf8038 0x801f 0x4>, - <0xf8040 0x3f 0x20>, - <0xf8044 0x801f 0x4>, - <0xf804c 0x8007 0x1>, - <0xfc004 0x3 0x2>, - <0xfc008 0x801f 0x4>, - <0xfc010 0x7 0x4>, - <0xfc014 0x801f 0x4>, - <0xfc01c 0x7 0x4>, - <0xfc020 0x801f 0x4>, - <0xfc028 0x7 0x4>, - <0xfc02c 0x801f 0x4>, - <0xfc034 0x7 0x4>, - <0xfc038 0x801f 0x4>, - <0xfc040 0x3 0x2>, - <0xfc044 0x801f 0x4>, - <0xfc04c 0x8007 0x1>, - <0x4000 0x1000000f 0x10000002>, - <0x4004 0x1000000f 0x10000002>, - <0x4008 0x1000000f 0x10000002>, - <0x400c 0x1000000f 0x10000002>, - <0x4010 0x1000000f 0x10000002>, - <0x4014 0x1000000f 0x10000002>, - <0x4018 0x1000000f 0x10000002>, - <0x401c 0x1000000f 0x10000002>, - <0x4020 0x1000000f 0x10000002>, - <0x4024 0x1000000f 0x10000002>, - <0x4028 0x1000000f 0x10000002>, - <0x402c 0x1000000f 0x10000002>, - <0x4040 0x1000000f 0x10000002>, - <0x4044 0x1000000f 0x10000002>, - <0x4048 0x1000000f 0x10000002>, - <0x404c 0x1000000f 0x10000002>, - <0x4050 0x1000000f 0x10000002>, - <0x4054 0x1000000f 0x10000002>, - <0x4058 0x1000000f 0x10000002>, - <0x405c 0x1000000f 0x10000002>, - <0x4060 0x1000000f 0x10000002>, - <0x4064 0x1000000f 0x10000002>, - <0x4068 0x1000000f 0x10000002>, - <0x406c 0x1000000f 0x10000002>, - <0x4080 0x1000000f 0x10000002>, - <0x4084 0x1000000f 0x10000002>, - <0x4088 0x1000000f 0x10000002>, - <0x408c 0x1000000f 0x10000002>, - <0x4090 0x1000000f 0x10000002>, - <0x4094 0x1000000f 0x10000002>, - <0x4098 0x1000000f 0x10000002>, - <0x409c 0x1000000f 0x10000002>, - <0x40a0 0x1000000f 0x10000002>, - <0x40a4 0x1000000f 0x10000002>, - <0x40a8 0x1000000f 0x10000002>, - <0x40ac 0x1000000f 0x10000002>, - <0x40c0 0x1000000f 0x10000002>, - <0x40c4 0x1000000f 0x10000002>, - <0x40c8 0x1000000f 0x10000002>, - <0x40cc 0x1000000f 0x10000002>, - <0x40d0 0x1000000f 0x10000002>, - <0x40d4 0x1000000f 0x10000002>, - <0x40d8 0x1000000f 0x10000002>, - <0x40dc 0x1000000f 0x10000002>, - <0x40e0 0x1000000f 0x10000002>, - <0x40e4 0x1000000f 0x10000002>, - <0x40e8 0x1000000f 0x10000002>, - <0x40ec 0x1000000f 0x10000002>, - <0x4100 0x1000000f 0x10000002>, - <0x4104 0x1000000f 0x10000002>, - <0x4108 0x1000000f 0x10000002>, - <0x410c 0x1000000f 0x10000002>, - <0x4110 0x1000000f 0x10000002>, - <0x4114 0x1000000f 0x10000002>, - <0x4118 0x1000000f 0x10000002>, - <0x411c 0x1000000f 0x10000002>, - <0x4120 0x1000000f 0x10000002>, - <0x4124 0x1000000f 0x10000002>, - <0x4128 0x1000000f 0x10000002>, - <0x412c 0x1000000f 0x10000002>, - <0x4140 0x1000000f 0x10000002>, - <0x4144 0x1000000f 0x10000002>, - <0x4148 0x1000000f 0x10000002>, - <0x414c 0x1000000f 0x10000002>, - <0x4150 0x1000000f 0x10000002>, - <0x4154 0x1000000f 0x10000002>, - <0x4158 0x1000000f 0x10000002>, - <0x415c 0x1000000f 0x10000002>, - <0x4160 0x1000000f 0x10000002>, - <0x4164 0x1000000f 0x10000002>, - <0x4168 0x1000000f 0x10000002>, - <0x416c 0x1000000f 0x10000002>, - <0x43e4 0x7 0x7>; apple,thunderbolt-drom = [ff 92 e6 6e ee 18 7c ac 05 90 19 c3 8c 00 5c 00 00 00 00 00 00 00 08 81 82 02 82 00 00 00 08 82 92 01 82 00 00 00 03 83 20 08 84 00 00 00 00 00 @@ -564,62 +236,4 @@ 63 2e 00 06 02 69 4f 53 00 00 00 00]; }; -/* ==== The right USB-C port's PCIe tunnel (ATC2): this board's tunables ==== */ -&apciec2_dart { - apple,tunable = <0x20c 0x80000121 0x80000121>, - <0x220 0xf0f 0xf0f>, - <0x224 0xffff 0x909>, - <0x300 0x1f31 0x1>, - <0x308 0x3ffffffc 0x10000000>, - <0x310 0x3ffffffc 0x3ffffffc>; -}; - -&apciec2 { - apple,tunable-debug = <0x1000 0x1 0x0>; - apple,tunable-rc = <0x78 0x7000 0x0>, - <0x718 0x7c000 0x0>, - <0x814 0xffffffff 0x2020f060>, - <0x8bc 0x1 0x0>; - apple,tunable-fabric = <0x4 0x3f003f 0x240024>, - <0x8 0x1 0x1>, - <0xc 0x1 0x1>, - <0x10 0x801f 0x4>, - <0x18 0x1ff 0x1e0>, - <0x1c 0x1 0x1>, - <0x20 0x801f 0x4>, - <0x28 0x1f 0x10>, - <0x2c 0x801f 0x4>, - <0x34 0x3f 0x20>, - <0x38 0x801f 0x4>, - <0x40 0x3f 0x20>, - <0x44 0x801f 0x4>, - <0x4c 0x10001 0x10001>, - <0x50 0x1 0x1>, - <0x54 0x1 0x1>, - <0x58 0x801f 0x4>, - <0x60 0x7f007f 0x450045>, - <0x64 0x801f 0x4>, - <0x6c 0x1f001f 0x100010>, - <0x70 0xf1 0x1>, - <0x74 0x801f 0x4>, - <0x7c 0x801f 0x4>, - <0x84 0x1 0x1>, - <0x88 0x1 0x1>, - <0x8c 0x801f 0x4>, - <0x94 0x1 0x1>, - <0x98 0x801f 0x4>, - <0xa0 0x1 0x1>, - <0xa4 0x801f 0x4>, - <0xac 0x1 0x1>, - <0xb0 0x1 0x1>, - <0xb4 0x801f 0x4>, - <0xbc 0x801f 0x4>, - <0xc4 0x801f 0x4>; -}; - -&apciec2_port { - apple,tunable = <0x140 0x1 0x1>, - <0x2a0 0x7e 0xa>; -}; - #include "t6050-j716c-isp.dtsi" diff --git a/arch/arm64/boot/dts/apple/t6050-max-atc2.dtsi b/arch/arm64/boot/dts/apple/t6050-max-atc2.dtsi new file mode 100644 index 0000000000000..40bcd58cd843f --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-max-atc2.dtsi @@ -0,0 +1,398 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * The M5 Max MacBook Pros' right USB-C port (ATC2): USB 2/3, the PD controller and the + * USB4/Thunderbolt router. A board file includes this after t6050-peripherals.dtsi and sets its + * own host DROM (apple,thunderbolt-drom) on &acio2_nhi; the boot loader replaces it. + */ + +/* + * ==== The right USB-C port (ATC2) ==== + * + * ADT /arm-io/nub-spmi-a1/hpm2 (SN201202x, SPMI address 0xc, port-number 3, port-location + * "right", acio-parent acio2), atc-phy2, usb-drd2 and dart-usb2. The HPM is on its own bus, + * nub-spmi-a1, and nothing hands the port off, so the chain is enabled outright. Aura's + * kboot_setup_atc() fills the PHY's tunables through the atcphy2 alias. + */ +/ { + aliases { + atcphy2 = &atc2_phy; + }; +}; + +&ps_atc2_common { + status = "okay"; +}; + +&ps_atc2_usb_aon { + status = "okay"; +}; + +&ps_atc2_phymxwrap { + status = "okay"; +}; + +&ps_atc2_usb { + status = "okay"; +}; + +&atc2_phy_mbox { + status = "okay"; +}; + +&atc2_phy { + status = "okay"; + + port { + atc2_phy_ep: endpoint { + remote-endpoint = <&hpm2_ss>; + }; + }; +}; + +&usb_drd2 { + status = "okay"; + + port { + usb_drd2_hs: endpoint { + remote-endpoint = <&hpm2_hs>; + }; + }; +}; + +&usb_drd2_dart_0 { + status = "okay"; +}; + +&usb_drd2_dart_1 { + status = "okay"; +}; + +/* + * dcpext0's Type-C route stays off with dcpext0: a mode-switch endpoint whose mux is never + * registered would defer the PD controller forever. + */ +&dcpext0 { + typec-routes { + route@0 { + status = "disabled"; + + port { + dcpext0_typec: endpoint { + remote-endpoint = <&hpm2_dp>; + }; + }; + }; + }; +}; + +&nub_spmi_a1 { + hpm2: usb-pd@c { + compatible = "apple,sn201202x"; + reg = <0xc SPMI_USID>; + + connector { + compatible = "usb-c-connector"; + label = "USB-C Right"; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + hpm2_hs: endpoint { + remote-endpoint = <&usb_drd2_hs>; + }; + }; + + port@1 { + reg = <1>; + hpm2_ss: endpoint { + remote-endpoint = <&atc2_phy_ep>; + }; + }; + + port@2 { + reg = <2>; + hpm2_dp: endpoint { + remote-endpoint = <&dcpext0_typec>; + }; + }; + }; + }; + }; +}; + +/* + * ==== The right USB-C port's USB4/Thunderbolt router (ATC2) ==== + * + * Until the boot loader fills them, the router, NHI, PHY CIO and DART tunables and the host + * DROM are this board's, from its ADT (the DROM's router UUID from an earlier boot). + */ +/* ATC2_CIO_AUSS's other parent; kept as the boot loader leaves it */ +&ps_auss { + status = "okay"; +}; + +/* The CIO reconfig request, port 2 (clock gate CIO2_RECONFIG_V) */ +&cio_reconfig0 { + status = "okay"; +}; + +/* The PHY's CIO80 RX_TOP tunables (ADT tunable_LN0/LN1_RX_TOP_CIO_DFLT); the other three are empty */ +&atc2_phy { + apple,tunable-lane0-rx-top-cio = <0x35c 0xe00 0x0>; + apple,tunable-lane1-rx-top-cio = <0x35c 0xe00 0x0>; +}; + +/* Only the router's LSTX pin (81) of the AOP GPIO controller is exposed. */ +&pinctrl_aop { + gpio-reserved-ranges = <0 81>, <82 3>; + status = "okay"; +}; + +&hpm2 { + connector { + ports { + port@3 { + reg = <3>; + hpm2_usb4: endpoint { + remote-endpoint = <&acio2_tbt>; + }; + }; + }; + }; +}; + +&acio2 { + apple,tunable-rc = <0x0 0xfff0 0x4020>, + <0x2c 0x4 0x0>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0x70007 0x40004>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = <0x8 0xff2 0x482>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + acio2_tbt: endpoint { + remote-endpoint = <&hpm2_usb4>; + }; + }; + }; +}; + +&acio2_dart { + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>; +}; + +&acio2_nhi { + apple,tunable-nhi = <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x3 0x2>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x3 0x2>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; +}; + +/* ==== The right USB-C port's PCIe tunnel (ATC2): this board's tunables ==== */ +&apciec2_dart { + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>; +}; + +&apciec2 { + apple,tunable-debug = <0x1000 0x1 0x0>; + apple,tunable-rc = <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2020f060>, + <0x8bc 0x1 0x0>; + apple,tunable-fabric = <0x4 0x3f003f 0x240024>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x1e0>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0xf1 0x1>, + <0x74 0x801f 0x4>, + <0x7c 0x801f 0x4>, + <0x84 0x1 0x1>, + <0x88 0x1 0x1>, + <0x8c 0x801f 0x4>, + <0x94 0x1 0x1>, + <0x98 0x801f 0x4>, + <0xa0 0x1 0x1>, + <0xa4 0x801f 0x4>, + <0xac 0x1 0x1>, + <0xb0 0x1 0x1>, + <0xb4 0x801f 0x4>, + <0xbc 0x801f 0x4>, + <0xc4 0x801f 0x4>; +}; + +&apciec2_port { + apple,tunable = <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-max-pmp-tunables.dtsi b/arch/arm64/boot/dts/apple/t6050-max-pmp-tunables.dtsi new file mode 100644 index 0000000000000..3fd6ff7c7b7ad --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-max-pmp-tunables.dtsi @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * M5 Max PMP firmware properties: the ADT /arm-io/pmp0/iop-pmp0-nub values the + * firmware queries by name at boot (pmp.rs serves apple,tunable-). + * Raw bytes from a J716cAP 27.0 ADT, where iBoot has merged the h17c-family + * variant tables into the nub. The J714cAP and J716cAP firmware ADTs carry + * identical PMP nodes, so the J714c uses the same set. + */ + +&pmp0 { + apple,tunable-afc-turbo-enable = [01 00 00 00]; + apple,tunable-afi-bw-a-enable = [01 00 00 00]; + apple,tunable-afi-bw-enable = [01 00 00 00]; + apple,tunable-afi-bw-threshold = [47 21 58 00 00 00 00 00 00 00 00 00 03 00 00 00 cc 4c ae 00 00 00 00 00 47 21 57 00 03 00 00 00 66 66 e8 00 00 00 00 00 cc 4c ad 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 e7 00 03 00 00 00]; + apple,tunable-afi-bw-threshold-a = [47 21 58 00 00 00 00 00 00 00 00 00 03 00 00 00 cc 4c ae 00 00 00 00 00 47 21 57 00 03 00 00 00 66 66 e8 00 00 00 00 00 cc 4c ad 00 03 00 00 00 66 66 e8 00 00 00 00 00 66 66 e7 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 e7 00 03 00 00 00]; + apple,tunable-agx-af-bw-a-enable = [00 00 00 00]; + apple,tunable-agx-af-bw-constraint = [00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 03 00 00 00 02 00 00 00 02 00 00 00 03 00 00 00 02 00 00 00 02 00 00 00 03 00 00 00 02 00 00 00 02 00 00 00 03 00 00 00 02 00 00 00 02 00 00 00 03 00 00 00]; + apple,tunable-agx-af-bw-constraint-a = [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 04 00 00 00 02 00 00 00 02 00 00 00 04 00 00 00 02 00 00 00 02 00 00 00 04 00 00 00 02 00 00 00 02 00 00 00 04 00 00 00 02 00 00 00 02 00 00 00 04 00 00 00]; + apple,tunable-agx-af-bw-constraint-a-enable = [01 00 00 00]; + apple,tunable-agx-af-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-af-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-af-bw-enable = [01 00 00 00]; + apple,tunable-agx-af-bw-threshold = [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d6 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 85 02 00 00 00 00 00 00 d5 01 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 80 5b 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 85 02 00 00 00 00 00 80 5a 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 e1 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 85 02 00 00 00 00 00 00 e0 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 bc 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 bb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 0e 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 5e 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5d 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00]; + apple,tunable-agx-af-bw-threshold-a = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 d6 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 85 02 00 00 00 00 00 00 d5 01 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 80 5b 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 85 02 00 00 00 00 00 80 5a 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 e1 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 85 02 00 00 00 00 00 00 e0 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 84 02 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 bc 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 bb 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 0e 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a4 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a3 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 5e 01 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 5d 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00]; + apple,tunable-agx-af-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-af-lat-enable = [00 00 00 00]; + apple,tunable-agx-afr-bw-constraint = [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 01 00 00 00 01 00 00 00 0c 00 00 00 02 00 00 00 02 00 00 00 0c 00 00 00 03 00 00 00 03 00 00 00 0c 00 00 00 04 00 00 00 04 00 00 00 0c 00 00 00 05 00 00 00 05 00 00 00 0c 00 00 00 06 00 00 00 06 00 00 00 0c 00 00 00 07 00 00 00 07 00 00 00 0c 00 00 00 08 00 00 00 08 00 00 00 0c 00 00 00 09 00 00 00 09 00 00 00 0c 00 00 00 0a 00 00 00 0a 00 00 00 0c 00 00 00 0b 00 00 00 0b 00 00 00 0c 00 00 00 0c 00 00 00 0c 00 00 00 0c 00 00 00]; + apple,tunable-agx-afr-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-afr-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-afr-bw-enable = [01 00 00 00]; + apple,tunable-agx-afr-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 5c 8f 96 00 00 00 00 00 00 00 00 00 00 00 00 00 66 e6 e9 00 00 00 00 00 5c 8f 95 00 00 00 00 00 d7 e3 48 01 00 00 00 00 66 e6 e8 00 00 00 00 00 f5 28 b8 01 00 00 00 00 d7 e3 47 01 00 00 00 00 99 d9 0a 02 00 00 00 00 f5 28 b7 01 00 00 00 00 d7 23 69 02 00 00 00 00 99 d9 09 02 00 00 00 00 c2 f5 cb 02 00 00 00 00 d7 23 68 02 00 00 00 00 cc 0c 37 03 00 00 00 00 c2 f5 ca 02 00 00 00 00 33 b3 a7 03 00 00 00 00 cc 0c 36 03 00 00 00 00 e1 3a 1f 04 00 00 00 00 33 b3 a6 03 00 00 00 00 d7 a3 9d 04 00 00 00 00 e1 3a 1e 04 00 00 00 00 1e 05 2d 05 00 00 00 00 d7 a3 9c 04 00 00 00 00 00 00 ff ff 00 00 00 00 1e 05 2c 05 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 1e 05 d1 00 00 00 00 00 00 00 00 00 06 00 00 00 7a 54 28 01 00 00 00 00 1e 05 d0 00 06 00 00 00 66 66 8f 01 00 00 00 00 7a 54 27 01 06 00 00 00 d7 63 dd 01 00 00 00 00 66 66 8e 01 06 00 00 00 5c 8f 36 02 00 00 00 00 d7 63 dc 01 06 00 00 00 c2 75 94 02 00 00 00 00 5c 8f 35 02 06 00 00 00 ae 87 fa 02 00 00 00 00 c2 75 93 02 06 00 00 00 1e 45 66 03 00 00 00 00 ae 87 f9 02 06 00 00 00 47 e1 d8 03 00 00 00 00 1e 45 65 03 06 00 00 00 47 61 52 04 00 00 00 00 47 e1 d7 03 06 00 00 00 51 38 dc 04 00 00 00 00 47 61 51 04 06 00 00 00 00 00 ff ff 00 00 00 00 51 38 db 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 3d ca 14 01 00 00 00 00 00 00 00 00 06 00 00 00 33 f3 76 01 00 00 00 00 3d ca 13 01 06 00 00 00 28 1c c2 01 00 00 00 00 33 f3 75 01 06 00 00 00 c2 35 18 02 00 00 00 00 28 1c c1 01 06 00 00 00 f5 28 73 02 00 00 00 00 c2 35 17 02 06 00 00 00 51 38 d6 02 00 00 00 00 f5 28 72 02 06 00 00 00 8f 02 3f 03 00 00 00 00 51 38 d5 02 06 00 00 00 85 ab ae 03 00 00 00 00 8f 02 3e 03 06 00 00 00 51 38 25 04 00 00 00 00 85 ab ad 03 06 00 00 00 00 c0 ab 04 00 00 00 00 51 38 24 04 06 00 00 00 00 00 ff ff 00 00 00 00 00 c0 aa 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 66 a6 66 01 00 00 00 00 00 00 00 00 06 00 00 00 85 eb af 01 00 00 00 00 66 a6 65 01 06 00 00 00 51 f8 03 02 00 00 00 00 85 eb ae 01 06 00 00 00 c2 f5 5c 02 00 00 00 00 51 f8 02 02 06 00 00 00 8f 02 be 02 00 00 00 00 c2 f5 5b 02 06 00 00 00 7a d4 24 03 00 00 00 00 8f 02 bd 02 06 00 00 00 ae 87 92 03 00 00 00 00 7a d4 23 03 06 00 00 00 b8 1e 07 04 00 00 00 00 ae 87 91 03 06 00 00 00 14 6e 8b 04 00 00 00 00 b8 1e 06 04 06 00 00 00 00 00 ff ff 00 00 00 00 14 6e 8a 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 85 eb af 01 00 00 00 00 00 00 00 00 06 00 00 00 51 f8 03 02 00 00 00 00 85 eb ae 01 06 00 00 00 c2 f5 5c 02 00 00 00 00 51 f8 02 02 06 00 00 00 8f 02 be 02 00 00 00 00 c2 f5 5b 02 06 00 00 00 7a d4 24 03 00 00 00 00 8f 02 bd 02 06 00 00 00 ae 87 92 03 00 00 00 00 7a d4 23 03 06 00 00 00 b8 1e 07 04 00 00 00 00 ae 87 91 03 06 00 00 00 14 6e 8b 04 00 00 00 00 b8 1e 06 04 06 00 00 00 00 00 ff ff 00 00 00 00 14 6e 8a 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 70 bd ef 01 00 00 00 00 00 00 00 00 06 00 00 00 8f c2 46 02 00 00 00 00 70 bd ee 01 06 00 00 00 5c cf a5 02 00 00 00 00 8f c2 45 02 06 00 00 00 f5 a8 0a 03 00 00 00 00 5c cf a4 02 06 00 00 00 d7 63 76 03 00 00 00 00 f5 a8 09 03 06 00 00 00 8f 02 e9 03 00 00 00 00 d7 63 75 03 06 00 00 00 28 1c 6b 04 00 00 00 00 8f 02 e8 03 06 00 00 00 00 00 ff ff 00 00 00 00 28 1c 6a 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 5c 8f 30 02 00 00 00 00 00 00 00 00 06 00 00 00 99 99 8d 02 00 00 00 00 5c 8f 2f 02 06 00 00 00 70 7d f0 02 00 00 00 00 99 99 8c 02 06 00 00 00 8f 42 5a 03 00 00 00 00 70 7d ef 02 06 00 00 00 f5 e8 ca 03 00 00 00 00 8f 42 59 03 06 00 00 00 3d ca 4a 04 00 00 00 00 f5 e8 c9 03 06 00 00 00 00 00 ff ff 00 00 00 00 3d ca 49 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 d7 63 75 02 00 00 00 00 00 00 00 00 06 00 00 00 5c 4f d6 02 00 00 00 00 d7 63 74 02 06 00 00 00 b8 1e 3e 03 00 00 00 00 5c 4f d5 02 06 00 00 00 cc cc ac 03 00 00 00 00 b8 1e 3d 03 06 00 00 00 e1 7a 2a 04 00 00 00 00 cc cc ab 03 06 00 00 00 00 00 ff ff 00 00 00 00 e1 7a 29 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 d7 23 bc 02 00 00 00 00 00 00 00 00 06 00 00 00 e1 fa 21 03 00 00 00 00 d7 23 bb 02 06 00 00 00 a3 b0 8e 03 00 00 00 00 e1 fa 20 03 06 00 00 00 f5 28 0a 04 00 00 00 00 a3 b0 8d 03 06 00 00 00 00 00 ff ff 00 00 00 00 f5 28 09 04 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a d7 05 03 00 00 00 00 00 00 00 00 06 00 00 00 0a 97 70 03 00 00 00 00 0a d7 04 03 06 00 00 00 0a d7 e9 03 00 00 00 00 0a 97 6f 03 06 00 00 00 00 00 ff ff 00 00 00 00 0a d7 e8 03 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 eb 51 25 03 00 00 00 00 00 00 00 00 06 00 00 00 cc 0c 99 03 00 00 00 00 eb 51 24 03 06 00 00 00 00 00 ff ff 00 00 00 00 cc 0c 98 03 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 40 48 03 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 40 47 03 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00]; + apple,tunable-agx-afr-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-afr-lat-enable = [00 00 00 00]; + apple,tunable-agx-dcs-bw-constraint = [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 01 00 00 00 01 00 00 00 06 00 00 00 02 00 00 00 02 00 00 00 06 00 00 00 03 00 00 00 03 00 00 00 06 00 00 00 04 00 00 00 04 00 00 00 06 00 00 00 04 00 00 00 04 00 00 00 06 00 00 00 05 00 00 00 05 00 00 00 06 00 00 00 05 00 00 00 05 00 00 00 06 00 00 00]; + apple,tunable-agx-dcs-bw-constraint-enable = [01 00 00 00]; + apple,tunable-agx-dcs-bw-dvfs-filter = [fe ff ff ff]; + apple,tunable-agx-dcs-bw-enable = [01 00 00 00]; + apple,tunable-agx-dcs-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 d2 00 00 00 00 00 00 00 8f 00 00 00 00 00 cc cc 47 01 00 00 00 00 00 00 d1 00 00 00 00 00 00 00 ff ff 00 00 00 00 cc cc 46 01 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 2e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 90 00 00 00 00 00 00 00 2d 00 06 00 00 00 00 00 d2 00 00 00 00 00 00 00 8f 00 06 00 00 00 cc cc 47 01 00 00 00 00 00 00 d1 00 06 00 00 00 00 00 ff ff 00 00 00 00 cc cc 46 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 90 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 be 00 00 00 00 00 00 00 8f 00 06 00 00 00 cc cc 47 01 00 00 00 00 00 00 bd 00 06 00 00 00 00 00 8e 01 00 00 00 00 cc cc 46 01 06 00 00 00 00 00 c7 01 00 00 00 00 00 00 8d 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 c6 01 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 90 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 be 00 00 00 00 00 00 00 8f 00 06 00 00 00 cc cc 47 01 00 00 00 00 00 00 bd 00 06 00 00 00 00 00 8e 01 00 00 00 00 cc cc 46 01 06 00 00 00 00 00 c7 01 00 00 00 00 00 00 8d 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 c6 01 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 86 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 a0 00 00 00 00 00 00 00 85 00 06 00 00 00 cc cc 47 01 00 00 00 00 00 00 9f 00 06 00 00 00 00 00 8e 01 00 00 00 00 cc cc 46 01 06 00 00 00 00 00 c7 01 00 00 00 00 00 00 8d 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 c6 01 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 09 00 06 00 00 00 51 f8 18 01 00 00 00 00 00 00 13 00 06 00 00 00 00 00 82 01 00 00 00 00 51 f8 17 01 06 00 00 00 00 00 c7 01 00 00 00 00 00 00 81 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 c6 01 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 14 00 00 00 00 00 00 00 09 00 06 00 00 00 51 f8 18 01 00 00 00 00 00 00 13 00 06 00 00 00 00 00 82 01 00 00 00 00 51 f8 17 01 06 00 00 00 00 00 c7 01 00 00 00 00 00 00 81 01 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 c6 01 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 69 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 8e 00 00 00 00 00 00 00 68 00 06 00 00 00 00 00 b9 00 00 00 00 00 00 00 8d 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 b8 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 7a 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 a3 00 00 00 00 00 00 00 79 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 a2 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 8c 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 8b 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 8c 00 00 00 00 00 00 00 09 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 8b 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 06 00 00 00]; + apple,tunable-agx-dcs-lat-constraint-enable = [01 00 00 00]; + apple,tunable-agx-dcs-lat-enable = [00 00 00 00]; + apple,tunable-agx-dvfs-state-voltages = [7d 00 00 00 53 02 00 00 8a 02 00 00 b2 02 00 00 e4 02 00 00 ee 02 00 00 07 03 00 00 20 03 00 00 34 03 00 00 57 03 00 00 7f 03 00 00 a7 03 00 00 f7 03 00 00 1a 04 00 00 7d 00 00 00 7d 00 00 00]; + apple,tunable-ane-af-bw-a-enable = [01 00 00 00]; + apple,tunable-ane-af-bw-enable = [00 00 00 00]; + apple,tunable-ane-af-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-af-bw-threshold-a = [00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 0d 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 0d 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 0d 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 0d 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 0e 00 00 00 00 00 00 00 04 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 0d 00 06 00 00 00 00 00 32 00 00 00 00 00 00 00 31 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 06 00 00 00]; + apple,tunable-ane-dcs-bw-enable = [01 00 00 00]; + apple,tunable-ane-dcs-bw-threshold = [00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 45 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 31 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00]; + apple,tunable-ane-lnk0-af-bw-threshold = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk0-af-bw-threshold-a = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 99 19 39 00 00 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 14 2e 21 00 00 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk1-af-bw-threshold = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ane-lnk1-af-bw-threshold-a = [00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 09 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 03 00 00 00 47 a1 19 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 47 a1 18 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 06 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 00 00 00 00 06 00 00 00 99 19 3a 00 00 00 00 00 99 19 39 00 00 00 00 00 00 00 ff ff 00 00 00 00 99 19 39 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 00 00 00 00 06 00 00 00 14 2e 22 00 00 00 00 00 14 2e 21 00 00 00 00 00 00 00 ff ff 00 00 00 00 14 2e 21 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 00 00 00 00 06 00 00 00 0a 17 11 00 00 00 00 00 0a 17 10 00 00 00 00 00 00 00 ff ff 00 00 00 00 0a 17 10 00 06 00 00 00]; + apple,tunable-ans-dcs-bw-enable = [01 00 00 00]; + apple,tunable-ans-dcs-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 5c 0f 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-dma-af-bw-a-enable = [01 00 00 00]; + apple,tunable-ans-dma-af-bw-enable = [01 00 00 00]; + apple,tunable-ans-dma-af-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-dma-af-bw-threshold-a = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-nand-af-bw-a-enable = [01 00 00 00]; + apple,tunable-ans-nand-af-bw-enable = [01 00 00 00]; + apple,tunable-ans-nand-af-bw-threshold = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ans-nand-af-bw-threshold-a = [99 19 00 00 05 00 00 00 00 00 00 00 03 00 00 00 00 00 05 00 05 00 00 00 3d 0a 00 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 04 00 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 05 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc0-af-bw-a-enable = [01 00 00 00]; + apple,tunable-atc0-af-bw-enable = [01 00 00 00]; + apple,tunable-atc0-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc0-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc1-af-bw-a-enable = [01 00 00 00]; + apple,tunable-atc1-af-bw-enable = [01 00 00 00]; + apple,tunable-atc1-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc1-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc2-af-bw-a-enable = [01 00 00 00]; + apple,tunable-atc2-af-bw-enable = [01 00 00 00]; + apple,tunable-atc2-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc2-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc3-af-bw-a-enable = [01 00 00 00]; + apple,tunable-atc3-af-bw-enable = [01 00 00 00]; + apple,tunable-atc3-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-atc3-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-auss-af-bw-a-enable = [01 00 00 00]; + apple,tunable-auss-af-bw-enable = [01 00 00 00]; + apple,tunable-auss-af-bw-threshold = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-auss-af-bw-threshold-a = [51 b8 09 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 51 b8 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave0-af-bw-a-enable = [00 00 00 00]; + apple,tunable-ave0-af-bw-enable = [00 00 00 00]; + apple,tunable-ave0-af-bw-threshold = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave0-af-bw-threshold-a = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave1-af-bw-a-enable = [00 00 00 00]; + apple,tunable-ave1-af-bw-enable = [00 00 00 00]; + apple,tunable-ave1-af-bw-threshold = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-ave1-af-bw-threshold-a = [99 99 09 00 00 00 00 00 00 00 00 00 03 00 00 00 66 66 0e 00 00 00 00 00 99 99 08 00 03 00 00 00 00 00 ff ff 00 00 00 00 66 66 0d 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-bwr-catch-up-factor = [00 00 01 00]; + apple,tunable-controller = [01 00 00 00 10 00 00 00 1b 00 00 00 00 00 00 00 00 00 00 00 44 49 45 2d 54 45 4d 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 46 49 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 2d 41 46 52 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 30 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 31 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 32 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 33 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 34 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 35 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 36 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 37 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 38 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 39 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 4c 4e 4b 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 4c 4e 4b 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00 0f 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 4d 45 4d 2d 43 41 43 48 45 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 4e 41 4e 44 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 44 4d 41 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 32 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 33 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 30 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 31 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 55 53 53 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4a 50 45 47 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 41 46 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 2d 44 43 53 2d 42 57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 56 4c 50 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 00 00 00 20 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 4c 49 46 45 54 49 4d 45 2d 53 45 52 56 4f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00]; + apple,tunable-coredump-enable = [40 00 00 00]; + apple,tunable-dcs-bw-enable = [01 00 00 00]; + apple,tunable-dcs-bw-threshold = [00 c0 4f 00 01 00 00 00 00 00 00 00 00 00 00 00 5c 8f 9f 00 02 00 00 00 00 c0 4e 00 00 00 00 00 eb 11 e8 00 03 00 00 00 5c 8f 9e 00 00 00 00 00 f5 28 5c 01 04 00 00 00 eb 11 e7 00 00 00 00 00 66 26 96 01 05 00 00 00 f5 28 5b 01 00 00 00 00 33 33 d0 01 06 00 00 00 66 26 95 01 00 00 00 00 00 00 ff ff 07 00 00 00 33 33 cf 01 00 00 00 00]; + apple,tunable-disable-vlpm-feature = [00 00 00 00]; + apple,tunable-dvfs-domain = [01 00 00 00 07 00 00 00 00 00 00 00 44 43 53 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 0d 00 00 00 21 00 00 00 41 46 52 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 05 00 00 00 00 00 00 00 53 4f 43 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 49 4e 54 00 00 00 00 00 00 00 00 05 00 00 00 04 00 00 00 00 00 00 00 44 49 53 50 5f 45 58 54 00 00 00 00 00 00 00 00]; + apple,tunable-fast-die-ctrl-ce-map = [01 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 5f 41 4e 45 00 00 00 00 00 00 00 00]; + apple,tunable-fast-die-ctrl-ts = [00 00 05 00]; + apple,tunable-fast-die-ctrl-ts-avg-temp = [00 00 64 00]; + apple,tunable-firmware-name = [74 36 30 35 30 70 6d 70 00]; + apple,tunable-jpeg-af-bw-a-enable = [00 00 00 00]; + apple,tunable-jpeg-af-bw-enable = [00 00 00 00]; + apple,tunable-jpeg-af-bw-threshold = [99 99 03 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 99 99 02 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-jpeg-af-bw-threshold-a = [99 99 03 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ff ff 00 00 00 00 99 99 02 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-lts-acsk-tddb-config = [01 00 00 00 69 00 00 00 10 14 24 00 00 00 00 00 95 c2 0f 00 1a 04 00 00 56 04 00 00 00 00 00 00]; + apple,tunable-lts-clpc-voltage = [01 00 00 00 d2 03 00 00 00 00 66 00 33 33 66 00 00 00 00 00 50 41 43 43 00 00 00 00]; + apple,tunable-lts-config = [03 00 00 00 69 00 00 00 c3 1c 15 00 00 00 00 00 0f dc 0f 00 6e 00 00 00 68 00 00 00 00 00 11 00 33 b3 00 00 2f bd 48 01 03 00 00 00 69 00 00 00 c3 1c 15 00 00 00 00 00 0f dc 0f 00 6e 00 00 00 68 00 00 00 00 00 11 00 33 b3 00 00 2f bd 48 01 01 00 00 00 69 00 00 00 bf d9 01 00 00 00 00 00 da fc 0f 00 6e 00 00 00 66 00 00 00 00 00 11 00 33 b3 00 00 f9 fe c3 00 02 00 00 00 3b 01 00 00 a6 79 0a 00 00 00 00 00 2b ee 0f 00 6e 00 00 00 69 00 00 00 00 00 11 00 33 b3 00 00 97 6e 39 00]; + apple,tunable-lts-ctrl-loop = [01 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 50 55 00 00 00 00 00 00 00 00 00 00 00 00 00]; + apple,tunable-lts-ctrl-ts = [00 00 05 00]; + apple,tunable-lts-voltage = [01 00 00 00 03 00 00 00 0d 00 00 00 09 00 00 00 4d 41 43 43 30 00 00 00 02 00 00 00 03 00 00 00 0e 00 00 00 0a 00 00 00 4d 41 43 43 31 00 00 00 03 00 00 00 03 00 00 00 0f 00 00 00 02 00 00 00 50 41 43 43 00 00 00 00 04 00 00 00 01 00 00 00 11 00 00 00 00 00 00 00 41 4e 45 00 00 00 00 00 05 00 00 00 03 00 00 00 10 00 00 00 04 00 00 00 41 47 58 00 00 00 00 00]; + apple,tunable-mc_cmd_ack_ptd_count = [01 00 00 00]; + apple,tunable-mc_cmd_ptd_count = [02 00 00 00]; + apple,tunable-mc_quota_req_ptd_count = [08 00 00 00]; + apple,tunable-mc_quota_rsp_ptd_count = [08 00 00 00]; + apple,tunable-mcache-stream = [1e 00 00 00 03 00 00 00 01 00 00 00 02 00 00 00 02 00 00 00 0c 00 00 00 0c 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2b 00 00 00 03 00 00 00 01 00 00 00 02 00 00 00 02 00 00 00 0e 00 00 00 0e 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 05 00 00 00 01 00 00 00 01 00 00 00 07 00 00 00 07 00 00 00 20 00 00 00 20 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 06 00 00 00 02 00 00 00 01 00 00 00 08 00 00 00 08 00 00 00 24 00 00 00 24 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 0b 00 00 00 05 00 00 00 01 00 00 00 0b 00 00 00 0b 00 00 00 30 00 00 00 30 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 0e 00 00 00 04 00 00 00 01 00 00 00 0d 00 00 00 0d 00 00 00 38 00 00 00 38 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 11 00 00 00 04 00 00 00 01 00 00 00 0e 00 00 00 0e 00 00 00 3c 00 00 00 3c 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1b 00 00 00 04 00 00 00 01 00 00 00 0e 00 00 00 0e 00 00 00 3d 00 00 00 3d 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 13 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 40 00 00 00 40 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 24 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 41 00 00 00 41 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1c 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 0f 00 00 00 42 00 00 00 42 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0f 00 00 00 04 00 00 00 01 00 00 00 10 00 00 00 10 00 00 00 44 00 00 00 44 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 01 00 00 00 11 00 00 00 11 00 00 00 48 00 00 00 48 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 13 00 00 00 13 00 00 00 50 00 00 00 50 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 15 00 00 00 15 00 00 00 58 00 00 00 5a 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 10 00 00 00 04 00 00 00 01 00 00 00 1f 00 00 00 1f 00 00 00 80 00 00 00 bf 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 20 00 00 00 03 00 00 00 02 00 00 00 03 00 00 00 06 00 00 00 10 00 00 00 1f 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 01 00 00 00 1f 00 00 00 03 00 00 00 02 00 00 00 1e 00 00 00 1e 00 00 00 7c 00 00 00 7c 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 12 00 00 00 05 00 00 00 02 00 00 00 09 00 00 00 09 00 00 00 28 00 00 00 28 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0a 00 00 00 05 00 00 00 02 00 00 00 0c 00 00 00 0c 00 00 00 34 00 00 00 34 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 15 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5d 00 00 00 5d 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 36 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5e 00 00 00 5e 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 37 00 00 00 07 00 00 00 02 00 00 00 16 00 00 00 16 00 00 00 5f 00 00 00 5f 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 0d 00 00 00 0b 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 0c 00 00 00 0b 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 09 00 00 00 09 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 19 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 1a 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 29 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 06 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2a 00 00 00 08 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 07 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 2c 00 00 00 03 00 00 00 03 00 00 00 18 00 00 00 18 00 00 00 64 00 00 00 64 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 2d 00 00 00 0c 00 00 00 03 00 00 00 18 00 00 00 18 00 00 00 65 00 00 00 65 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 2f 00 00 00 02 00 00 00 03 00 00 00 1a 00 00 00 1a 00 00 00 6c 00 00 00 6c 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 26 00 00 00 05 00 00 00 03 00 00 00 1c 00 00 00 1c 00 00 00 74 00 00 00 74 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 14 00 00 00 04 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 0a 00 00 00 0a 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 27 00 00 00 04 00 00 00 03 00 00 00 1d 00 00 00 1d 00 00 00 78 00 00 00 78 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 23 00 00 00 00 00 00 00 03 00 00 00 14 00 00 00 14 00 00 00 54 00 00 00 54 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 28 00 00 00 00 00 00 00 03 00 00 00 1b 00 00 00 1b 00 00 00 70 00 00 00 70 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 30 00 00 00 0e 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 61 00 00 00 61 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 31 00 00 00 0f 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 60 00 00 00 60 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 35 00 00 00 09 00 00 00 03 00 00 00 19 00 00 00 19 00 00 00 68 00 00 00 68 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 1d 00 00 00 09 00 00 00 03 00 00 00 19 00 00 00 19 00 00 00 69 00 00 00 6b 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 33 00 00 00 11 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 62 00 00 00 62 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 34 00 00 00 12 00 00 00 03 00 00 00 17 00 00 00 17 00 00 00 63 00 00 00 63 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 16 00 00 00 0b 00 00 00 03 00 00 00 ff ff 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00]; + apple,tunable-no-shutdown = [01 00 00 00]; + apple,tunable-pm-ptd-ranges = [01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 28 00 00 00 09 00 00 00 0a 00 00 00 0b 00 00 00 0c 00 00 00 0d 00 00 00 0e 00 00 00]; + apple,tunable-pre-loaded = [01 00 00 00]; + apple,tunable-ptd-driver-version = [01 00 00 00]; + apple,tunable-ptd-range = [01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 4e 55 4c 4c 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 10 00 00 00 50 4d 50 2d 53 54 41 54 55 53 00 00 00 00 00 00 03 00 00 00 08 00 00 00 04 00 00 00 00 00 00 00 44 56 46 53 2d 53 54 41 54 45 00 00 00 00 00 00 04 00 00 00 0c 00 00 00 04 00 00 00 00 00 00 00 50 4d 50 54 4f 4f 4c 00 00 00 00 00 00 00 00 00 05 00 00 00 10 00 00 00 08 00 00 00 00 00 00 00 50 4d 53 2d 50 4d 47 52 2d 50 4b 54 00 00 00 00 06 00 00 00 18 00 00 00 20 00 00 00 00 00 00 00 50 4d 53 2d 44 50 45 2d 50 4b 54 00 00 00 00 00 07 00 00 00 38 00 00 00 48 00 00 00 00 00 00 00 50 4d 53 2d 44 45 56 43 2d 50 4b 54 00 00 00 00 08 00 00 00 80 00 00 00 10 00 00 00 00 00 00 00 50 4d 53 2d 50 57 52 53 2d 50 4b 54 00 00 00 00 09 00 00 00 90 00 00 00 50 01 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 4b 54 00 00 00 00 00 0a 00 00 00 e0 01 00 00 08 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 53 2d 52 45 51 00 00 0b 00 00 00 e8 01 00 00 08 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 50 53 2d 41 43 4b 00 00 0c 00 00 00 f0 01 00 00 30 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 44 56 46 53 00 00 00 00 0d 00 00 00 20 02 00 00 1a 00 00 00 00 00 00 00 53 4f 43 2d 44 45 56 2d 42 57 52 00 00 00 00 00 0e 00 00 00 3a 02 00 00 02 00 00 00 00 00 00 00 44 56 46 53 2d 44 49 45 2d 54 4f 2d 44 49 45 00 0f 00 00 00 3c 02 00 00 0a 00 00 00 00 00 00 00 4d 43 2d 44 52 56 2d 54 4f 2d 43 54 52 4c 00 00 10 00 00 00 58 02 00 00 02 00 00 00 0c 00 00 00 46 41 53 54 2d 44 49 45 2d 43 45 00 00 00 00 00 11 00 00 00 5a 02 00 00 07 00 00 00 0d 00 00 00 53 4d 43 2d 54 4f 2d 50 50 4d 00 00 00 00 00 00 12 00 00 00 61 02 00 00 09 00 00 00 00 00 00 00 4d 43 2d 43 54 52 4c 2d 54 4f 2d 44 52 56 00 00 13 00 00 00 6a 02 00 00 01 00 00 00 0a 00 00 00 4c 54 53 2d 56 4f 4c 54 2d 43 41 50 00 00 00 00 18 00 00 00 70 02 00 00 05 00 00 00 0e 00 00 00 50 50 4d 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 19 00 00 00 75 02 00 00 05 00 00 00 0f 00 00 00 43 4c 50 43 2d 54 4f 2d 53 4d 43 00 00 00 00 00 1a 00 00 00 7a 02 00 00 20 00 00 00 00 00 00 00 47 46 58 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 1b 00 00 00 9a 02 00 00 09 00 00 00 00 00 00 00 46 41 53 54 2d 44 49 45 2d 54 4f 2d 53 4d 43 00 1c 00 00 00 a3 02 00 00 01 00 00 00 00 00 00 00 4d 43 2d 43 54 52 4c 2d 54 4f 2d 53 4d 43 00 00 1d 00 00 00 a4 02 00 00 08 00 00 00 00 00 00 00 41 4e 45 2d 54 4f 2d 53 4d 43 00 00 00 00 00 00 20 00 00 00 b4 02 00 00 01 00 00 00 00 00 00 00 4c 54 53 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 21 00 00 00 b5 02 00 00 01 00 00 00 0b 00 00 00 50 4d 50 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 22 00 00 00 b6 02 00 00 08 00 00 00 00 00 00 00 50 4d 55 2d 54 4f 2d 47 46 58 00 00 00 00 00 00 28 00 00 00 20 03 00 00 14 00 00 00 00 00 00 00 50 4d 53 2d 56 49 52 54 2d 43 4e 54 52 00 00 00]; + apple,tunable-region-base = [00 00 50 84 02 00 00 00]; + apple,tunable-region-size = [00 00 10 00 00 00 00 00]; + apple,tunable-segment-names = [5f 5f 54 45 58 54 3b 5f 5f 44 41 54 41 3b 5f 5f 45 54 45 58 54 00]; + apple,tunable-segment-ranges = [00 00 50 84 02 00 00 00 00 00 00 01 00 00 00 00 00 00 50 84 02 00 00 00 00 80 05 00 03 00 00 00 00 80 55 84 02 00 00 00 00 80 05 01 00 00 00 00 00 80 55 84 02 00 00 00 00 b0 09 00 06 00 00 00 00 c0 e5 01 00 01 00 00 00 00 10 01 00 00 00 00 00 00 00 00 00 01 00 00 00 00 01 00 01 00 00 00]; + apple,tunable-soc-chip-variant = [01 00 00 00]; + apple,tunable-soc-device = [01 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 43 53 00 00 00 00 00 02 00 00 00 45 4e 4f 4e 01 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4d 43 43 00 00 00 00 03 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 30 00 04 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 31 00 05 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 32 00 06 00 00 00 45 4e 4f 4e 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 33 00 07 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 34 00 08 00 00 00 45 4e 4f 4e 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 35 00 09 00 00 00 45 4e 4f 4e 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 36 00 0a 00 00 00 45 4e 4f 4e 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 37 00 0b 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 38 00 0c 00 00 00 45 4e 4f 4e 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 4f 43 2d 4e 49 39 00 0d 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 30 00 00 00 0e 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 41 43 43 31 00 00 00 0f 00 00 00 45 4e 4f 4e 03 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 41 43 43 00 00 00 00 10 00 00 00 5f 58 46 47 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 47 58 00 00 00 00 00 11 00 00 00 45 4e 4f 4e 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 45 00 00 00 00 00 12 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49 53 50 00 00 00 00 00 13 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 49 4e 54 00 14 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 30 15 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 31 16 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 32 17 00 00 00 45 4e 4f 4e 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 49 53 50 45 58 54 33 18 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 30 00 00 00 00 19 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 45 31 00 00 00 00 1a 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 56 44 00 00 00 00 00 1b 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 53 52 30 00 00 00 00 1c 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4d 53 52 31 00 00 00 00 1d 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 4a 50 45 47 00 00 00 00 1e 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 43 4f 44 45 43 00 00 1f 00 00 00 45 4e 4f 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 50 52 4f 52 45 53 00 00 20 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 30 00 00 00 00 21 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 31 00 00 00 00 22 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 32 00 00 00 00 23 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 54 43 33 00 00 00 00 24 00 00 00 45 4e 4f 4e 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 55 53 53 00 00 00 00 25 00 00 00 45 4e 4f 4e 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 4e 53 00 00 00 00 00]; + apple,tunable-soc-device-ps-group = [00 f0 ff ff ff 01 00 00]; + apple,tunable-soc-ni0-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni0-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni0-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni0-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni0-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni1-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni1-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni1-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni1-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni1-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni2-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni2-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni2-bw-threshold = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni2-bw-threshold-a = [8f c2 15 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 8f c2 14 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni2-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni3-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni3-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni3-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni3-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni3-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni4-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni4-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni4-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni4-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni4-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni5-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni5-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni5-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni5-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni5-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni6-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni6-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni6-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni6-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni6-push-thr = [24 00 00 00]; + apple,tunable-soc-ni7-bw-a-enable = [01 00 00 00]; + apple,tunable-soc-ni7-bw-enable = [01 00 00 00]; + apple,tunable-soc-ni7-bw-threshold = [00 00 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 00 00 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni7-bw-threshold-a = [00 00 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 00 00 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni7-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni8-bw-a-enable = [00 00 00 00]; + apple,tunable-soc-ni8-bw-enable = [00 00 00 00]; + apple,tunable-soc-ni8-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni8-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni8-push-thr = [f5 06 00 00]; + apple,tunable-soc-ni9-bw-a-enable = [00 00 00 00]; + apple,tunable-soc-ni9-bw-enable = [00 00 00 00]; + apple,tunable-soc-ni9-bw-threshold = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni9-bw-threshold-a = [ae 07 16 00 00 00 00 00 00 00 00 00 03 00 00 00 eb 91 2b 00 00 00 00 00 ae 07 15 00 03 00 00 00 00 00 ff ff 00 00 00 00 eb 91 2a 00 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00 00 00 ff ff 00 00 00 00 00 00 fe ff 03 00 00 00]; + apple,tunable-soc-ni9-push-thr = [f5 06 00 00]; + apple,tunable-sochot-sensors = [01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 0a 00 00 00 0b 00 00 00 0c 00 00 00 0d 00 00 00 0e 00 00 00 0f 00 00 00 10 00 00 00 11 00 00 00 12 00 00 00 13 00 00 00 14 00 00 00 15 00 00 00 16 00 00 00 17 00 00 00 18 00 00 00 19 00 00 00 1a 00 00 00 1b 00 00 00 1c 00 00 00 1d 00 00 00 1e 00 00 00 1f 00 00 00 20 00 00 00 21 00 00 00 22 00 00 00 23 00 00 00 24 00 00 00 25 00 00 00 26 00 00 00 27 00 00 00 28 00 00 00 29 00 00 00 2a 00 00 00 2b 00 00 00 2c 00 00 00 2d 00 00 00 2e 00 00 00 2f 00 00 00 30 00 00 00 31 00 00 00 32 00 00 00 33 00 00 00 34 00 00 00 35 00 00 00 36 00 00 00 37 00 00 00 38 00 00 00 39 00 00 00 3a 00 00 00 3b 00 00 00 3c 00 00 00 3d 00 00 00 3e 00 00 00 3f 00 00 00 40 00 00 00 41 00 00 00 42 00 00 00 43 00 00 00 44 00 00 00 45 00 00 00]; + apple,tunable-sram-index = [01 00 00 00]; + apple,tunable-temp-sensor = [01 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 30 69 00 00 00 00 00 00 00 00 00 00 02 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 31 69 00 00 00 00 00 00 00 00 00 00 03 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 32 69 00 00 00 00 00 00 00 00 00 00 04 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 35 69 00 00 00 00 00 00 00 00 00 00 05 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 36 69 00 00 00 00 00 00 00 00 00 00 06 00 00 00 08 00 00 00 11 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 80 06 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 61 30 30 37 69 00 00 00 00 00 00 00 00 00 00 07 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 63 69 00 00 00 00 00 00 00 00 00 00 08 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 64 69 00 00 00 00 00 00 00 00 00 00 09 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 30 69 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 31 69 00 00 00 00 00 00 00 00 00 00 0b 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 66 69 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 67 69 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 33 69 00 00 00 00 00 00 00 00 00 00 0e 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 34 69 00 00 00 00 00 00 00 00 00 00 0f 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 65 69 00 00 00 00 00 00 00 00 00 00 10 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 32 69 00 00 00 00 00 00 00 00 00 00 11 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 68 69 00 00 00 00 00 00 00 00 00 00 12 00 00 00 08 00 00 00 0f 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 35 69 00 00 00 00 00 00 00 00 00 00 13 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 00 80 01 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6c 69 00 00 00 00 00 00 00 00 00 00 14 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 00 80 01 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6d 69 00 00 00 00 00 00 00 00 00 00 15 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 06 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 6f 69 00 00 00 00 00 00 00 00 00 00 16 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 70 69 00 00 00 00 00 00 00 00 00 00 17 00 00 00 08 00 00 00 0f 00 00 00 01 00 00 00 0a 00 00 00 00 00 00 00 66 e6 04 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 73 69 00 00 00 00 00 00 00 00 00 00 18 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 39 69 00 00 00 00 00 00 00 00 00 00 19 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 61 69 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 36 69 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 70 30 30 37 69 00 00 00 00 00 00 00 00 00 00 1c 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 62 69 00 00 00 00 00 00 00 00 00 00 1d 00 00 00 08 00 00 00 0f 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 70 30 30 38 69 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 33 69 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 34 69 00 00 00 00 00 00 00 00 00 00 20 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 30 69 00 00 00 00 00 00 00 00 00 00 21 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 31 69 00 00 00 00 00 00 00 00 00 00 22 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 36 69 00 00 00 00 00 00 00 00 00 00 23 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 37 69 00 00 00 00 00 00 00 00 00 00 24 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 35 69 00 00 00 00 00 00 00 00 00 00 25 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 32 69 00 00 00 00 00 00 00 00 00 00 26 00 00 00 08 00 00 00 0d 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 38 69 00 00 00 00 00 00 00 00 00 00 27 00 00 00 08 00 00 00 0d 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 6c 69 00 00 00 00 00 00 00 00 00 00 28 00 00 00 08 00 00 00 0d 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 6d 69 00 00 00 00 00 00 00 00 00 00 29 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 39 69 00 00 00 00 00 00 00 00 00 00 2a 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 61 69 00 00 00 00 00 00 00 00 00 00 2b 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 63 69 00 00 00 00 00 00 00 00 00 00 2c 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 64 69 00 00 00 00 00 00 00 00 00 00 2d 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 66 69 00 00 00 00 00 00 00 00 00 00 2e 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 67 69 00 00 00 00 00 00 00 00 00 00 2f 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 62 69 00 00 00 00 00 00 00 00 00 00 30 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 65 69 00 00 00 00 00 00 00 00 00 00 31 00 00 00 08 00 00 00 0d 00 00 00 02 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 30 68 69 00 00 00 00 00 00 00 00 00 00 32 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 33 69 00 00 00 00 00 00 00 00 00 00 33 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 34 69 00 00 00 00 00 00 00 00 00 00 34 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 30 69 00 00 00 00 00 00 00 00 00 00 35 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 31 69 00 00 00 00 00 00 00 00 00 00 36 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 36 69 00 00 00 00 00 00 00 00 00 00 37 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 37 69 00 00 00 00 00 00 00 00 00 00 38 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 35 69 00 00 00 00 00 00 00 00 00 00 39 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 32 69 00 00 00 00 00 00 00 00 00 00 3a 00 00 00 08 00 00 00 0e 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 38 69 00 00 00 00 00 00 00 00 00 00 3b 00 00 00 08 00 00 00 0e 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 6c 69 00 00 00 00 00 00 00 00 00 00 3c 00 00 00 08 00 00 00 0e 00 00 00 01 00 00 00 04 00 00 00 00 00 00 00 cc cc 03 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 6d 69 00 00 00 00 00 00 00 00 00 00 3d 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 39 69 00 00 00 00 00 00 00 00 00 00 3e 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 01 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 61 69 00 00 00 00 00 00 00 00 00 00 3f 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 63 69 00 00 00 00 00 00 00 00 00 00 40 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 03 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 64 69 00 00 00 00 00 00 00 00 00 00 41 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 04 00 00 00 00 00 00 00 00 00 0a 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 66 69 00 00 00 00 00 00 00 00 00 00 42 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 05 00 00 00 00 00 00 00 00 00 0e 00 47 a1 03 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 67 69 00 00 00 00 00 00 00 00 00 00 43 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 06 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 62 69 00 00 00 00 00 00 00 00 00 00 44 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 07 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 65 69 00 00 00 00 00 00 00 00 00 00 45 00 00 00 08 00 00 00 0e 00 00 00 02 00 00 00 08 00 00 00 00 00 00 00 00 00 0e 00 47 61 05 00 6e 00 00 00 7d 00 00 00 54 6d 30 31 68 69 00 00 00 00 00 00 00 00 00 00 46 00 00 00 01 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6d 00 00 00 6d 00 00 00 4d 54 52 5f 54 4f 50 5f 41 47 58 00 00 00 00 00]; + apple,tunable-user-power-managed = [01 00 00 00]; + apple,tunable-vlpm-threshold = [55 01 00 00]; + apple,tunable-vlpm-timer-limit = [64 00 00 00]; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index c04b66519953c..628004394bc33 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -116,7 +116,7 @@ #interrupt-cells = <2>; }; -#ifdef T6050_J716C +#if defined(T6050_J714C) || defined(T6050_J716C) /* * /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, generation 4, a bus of USB-C PD controllers (the * board's). They are polled, as on nub-spmi-a0, so the bus takes no interrupt. @@ -130,7 +130,7 @@ #endif }; -#ifdef T6050_J716C +#if defined(T6050_J714C) || defined(T6050_J716C) /* * ATC2's USB4/Thunderbolt router (ADT /arm-io/acio2, acio-cpu2 and dart-acio2), powered per * connection: the PHY enters CIO mode, then the router's domains come on (ATC2_CIO, _PCIE, _USB, diff --git a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi index 8063b37f816db..fea335f3693a6 100644 --- a/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-peripherals.dtsi @@ -1321,7 +1321,7 @@ }; #endif -#if defined(T6050_J714C) || defined(T6050_J714S) || defined(T6050_K114C) || defined(T6050_K114S) || defined(T6050_K116C) || defined(T6050_K116S) +#if defined(T6050_J714S) || defined(T6050_K114C) || defined(T6050_K114S) || defined(T6050_K116C) || defined(T6050_K116S) nub_spmi_a1: spmi@28a1a8000 { compatible = "apple,t6050-spmi", "apple,t8142-spmi"; reg = <0x2 0x8a1a8000 0x0 0x4000>, @@ -1471,7 +1471,7 @@ status = "disabled"; }; -#ifndef T6050_J716C +#if !defined(T6050_J714C) && !defined(T6050_J716C) apciec2_dart: iommu@384000000 { compatible = "apple,t6050-dart", "apple,t8110-dart"; reg = <0x3 0x84000000 0x0 0x20000>; From cbc8563f7bb946e1f487fd07ebf0c716a30957a5 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:13:49 +1100 Subject: [PATCH 329/342] arm64: dts: apple: t8140: expose the debug dock and firmware UARTs (#1396) Enable the debug dock connection status register (read through the apple,debug-dock debugfs view). On J700, enable uart4 and uart5, which carry the Wi-Fi and Bluetooth firmware debug output, with their receive pins muxed. Neither is a console; the ports stay closed until a user opens them. The PMGR clock provider is not enabled on T8140 yet, so both are clocked from the 24 MHz reference. dtc W=1 and CHECK_DTBS report nothing for the changed nodes. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8140-j700.dts | 28 +++++++++++++++++++ .../boot/dts/apple/t8140-peripherals.dtsi | 3 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index 4b21c9b2401af..ba91829924008 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -2047,6 +2047,34 @@ pcie0_clkreq: pcie0-clkreq-pins { pinmux = ; }; + + uart4_rx: uart4-rx-pins { + pinmux = ; + }; + + uart5_rx: uart5-rx-pins { + pinmux = ; + }; +}; + +/* + * Wi-Fi (uart4) and Bluetooth (uart5) firmware debug output. Only the + * receive line is routed; the ports stay closed unless a user opens them. + */ +&uart4 { + pinctrl-0 = <&uart4_rx>; + pinctrl-names = "default"; + /* The PMGR clock provider is not enabled on this SoC yet. */ + clocks = <&clkref>, <&clkref>; + status = "okay"; +}; + +&uart5 { + pinctrl-0 = <&uart5_rx>; + pinctrl-names = "default"; + /* The PMGR clock provider is not enabled on this SoC yet. */ + clocks = <&clkref>, <&clkref>; + status = "okay"; }; /* SID17 bootstrap; the arena stays owned until a full reset. */ diff --git a/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi index f73a86c0f4326..f1d24c8d495f3 100644 --- a/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8140-peripherals.dtsi @@ -505,14 +505,13 @@ status = "disabled"; }; - /* ADT /dock-connect; no qualified host transport/ownership contract. */ + /* ADT /dock-connect: debug dock connection status, read only. */ debug_dock: debug-dock@3082d8008 { compatible = "apple,t8140-debug-dock", "apple,debug-dock"; reg = <0x3 0x082d8008 0x0 0x4>; interrupt-parent = <&aic>; interrupts = , ; - status = "disabled"; }; /* ADT /arm-io/eic named MMIO apertures are absolute addresses. */ From c880586efacb808b1cf5406d6079b76bf07d8722 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:20:36 +1100 Subject: [PATCH 330/342] arm64: dts: apple: attach the Neo internal PCIe host to its full power chain (#1397) The T8140 ADT gates APCIE_GP, APCIE_SYS_GP, APCIE_ST, APCIE_SYS_ST, ANS and APCIE_PHY_SW for apcie0. APCIE_PHY_SW already has all of the other domains as ancestors, so attach the host to that leaf instead of APCIE_GP alone. This removes its dependency on NVMe keeping the storage and PHY chain on. The host retains this chain during suspend-to-idle while the radio wake path leaves the internal link running. Assisted-by: LLM Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t8140.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8140.dtsi b/arch/arm64/boot/dts/apple/t8140.dtsi index b781dd756a2d2..4242e655a3af7 100644 --- a/arch/arm64/boot/dts/apple/t8140.dtsi +++ b/arch/arm64/boot/dts/apple/t8140.dtsi @@ -1206,7 +1206,7 @@ #size-cells = <2>; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; - power-domains = <&ps_apcie_gp>; + power-domains = <&ps_apcie_phy_sw>; status = "disabled"; pcie0_port0: pci@0,0 { From 68c10dd872afe361fa38f98100059f19ce66714a Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 19:33:37 -0500 Subject: [PATCH 331/342] arm64: dts: apple: t6050: Describe the CPU clusters The T6050 Max CPU nodes had no cpu-map, so Linux sees eighteen CPUs in one package with no clusters. parse_dt_topology() also reads each CPU's capacity-dmips-mhz only while it walks cpu-map, so without one no capacity reaches the scheduler. Describe the three clusters as the ADT does: MPIDR Aff1 0 and 1 are the M clusters, 2 the P cluster, each with its own L2. The boot loader prunes the entries of cores it did not start. The two-die description keeps its flat layout for now. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-max.dtsi | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6050-max.dtsi b/arch/arm64/boot/dts/apple/t6050-max.dtsi index 628004394bc33..203155df9ceb9 100644 --- a/arch/arm64/boot/dts/apple/t6050-max.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-max.dtsi @@ -45,6 +45,75 @@ T6050_P_CPU(cpu15, 10203, cpufreq_pc); T6050_P_CPU(cpu16, 10204, cpufreq_pc); T6050_P_CPU(cpu17, 10205, cpufreq_pc); + + /* + * The clusters are MPIDR Aff1 (M0, M1, then P), each with its own L2. The boot + * loader prunes the entries of cores it did not start. + */ + cpu-map { + cluster0 { + core0 { + cpu = <&cpu0>; + }; + core1 { + cpu = <&cpu1>; + }; + core2 { + cpu = <&cpu2>; + }; + core3 { + cpu = <&cpu3>; + }; + core4 { + cpu = <&cpu4>; + }; + core5 { + cpu = <&cpu5>; + }; + }; + + cluster1 { + core0 { + cpu = <&cpu6>; + }; + core1 { + cpu = <&cpu7>; + }; + core2 { + cpu = <&cpu8>; + }; + core3 { + cpu = <&cpu9>; + }; + core4 { + cpu = <&cpu10>; + }; + core5 { + cpu = <&cpu11>; + }; + }; + + cluster2 { + core0 { + cpu = <&cpu12>; + }; + core1 { + cpu = <&cpu13>; + }; + core2 { + cpu = <&cpu14>; + }; + core3 { + cpu = <&cpu15>; + }; + core4 { + cpu = <&cpu16>; + }; + core5 { + cpu = <&cpu17>; + }; + }; + }; }; }; From 28784bf850534c294a361a1c2ce90c36c4604f4f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 19:33:37 -0500 Subject: [PATCH 332/342] arm64: dts: apple: t6050: Give the M and P cores their capacities Without capacity-dmips-mhz every T6050 CPU reports a capacity of 1024, so the scheduler treats the six P cores (apple,everest, CPUs 12-17) like the twelve M cores and an unpinned single heavy thread lands on an M core most of the time (4 of 5 runs on J714sAP). Measured on J714sAP with every cluster pinned to 4284 MHz, which both OPP tables have, and each core's clock read with a dependent-add chain: per MHz an M core runs zstd -3 compression at 0.736, decompression at 0.871 and a Python dict loop at 0.728 of a P core (geometric mean 0.776). Small L1-resident integer, branch, sort, hash and FP loops run at 0.92-1.01, which shows the execution units match but not how general code runs. So M 794 and P 1024; with the 4380 and 4608 MHz tops the M cores' capacity is 754. The values take effect through the cpu-map the previous commit adds. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6050-base.dtsi | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-base.dtsi b/arch/arm64/boot/dts/apple/t6050-base.dtsi index 1be5e14cb12fe..f77f1d641051c 100644 --- a/arch/arm64/boot/dts/apple/t6050-base.dtsi +++ b/arch/arm64/boot/dts/apple/t6050-base.dtsi @@ -41,7 +41,7 @@ * number the cores 18 * d + 6 * c + n. The boot loader removes the nodes of * the cores it did not start. */ -#define T6050_CPU(label, mpidr, type, opp, cluster) \ +#define T6050_CPU(label, mpidr, type, opp, cluster, cpu_cap) \ label: cpu@mpidr { \ compatible = type; \ device_type = "cpu"; \ @@ -49,13 +49,20 @@ enable-method = "spin-table"; \ operating-points-v2 = <&opp>; \ performance-domains = <&cluster>; \ + capacity-dmips-mhz = ; \ cpu-release-addr = <0 0>; /* to be filled by the loader */ \ } +/* + * capacity-dmips-mhz from pinned single-thread throughput with every cluster at 4284 MHz (in + * both OPP tables), normalised by each core's measured clock (J714sAP): per MHz an M core runs + * zstd -3 compression at 0.736, decompression at 0.871 and a Python dict loop at 0.728 of a P + * core, geometric mean 0.776, so M 794 and P 1024. Small L1-resident loops run at 0.92-1.01. + */ #define T6050_M_CPU(label, mpidr, cluster) \ - T6050_CPU(label, mpidr, "apple,sawtooth", mcluster_opp, cluster) + T6050_CPU(label, mpidr, "apple,sawtooth", mcluster_opp, cluster, 794) #define T6050_P_CPU(label, mpidr, cluster) \ - T6050_CPU(label, mpidr, "apple,everest", pcluster_opp, cluster) + T6050_CPU(label, mpidr, "apple,everest", pcluster_opp, cluster, 1024) / { compatible = "apple,t6050", "apple,arm-platform"; From aa8e96db997f91b21f453d774f4bd84c7569deb1 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:50:55 +1100 Subject: [PATCH 333/342] drm/asahi: g17: back off between refused render capacity attempts (#1400) wait_render_capacity() retried at once whenever reclaim reported that it returned something. Under lower-window starvation reclaim keeps reporting returns (vacated pools the firmware has not released yet, or backing that another refused publisher takes first), so a publisher could make millions of placement attempts, each vacating idle pools and notifying the firmware, until its 2 s deadline. Each reclaim also notified the render domain, which ended the other refused publishers' waits at once. Allow one immediate retry after a returning reclaim per pause, and make every later refused attempt sleep for at least a backoff pause, starting at 50 us and doubling up to 2 ms, even when a notification ends the domain wait sooner. The 2 s bound is unchanged; a starved wait now makes about 3,000 attempts instead of one per reclaim. g17-capacity-backoff-tests.py runs the production wait against a fake clock: a reclaim storm and a quiet domain both end with EBUSY at 2.000 s (3,028 and 401 attempts), a release 5 ms in is placed at 5.0 ms, and the pre-change retry rule and an unpaused wake both fail it. Assisted-by: LLM Signed-off-by: Ryan Murray --- .../drm/asahi/g17/runtime/render/submit.rs | 89 +++++++++++- tools/asahi/g17-capacity-backoff-tests.py | 133 ++++++++++++++++++ tools/asahi/run-host-tests.py | 1 + 3 files changed, 219 insertions(+), 4 deletions(-) create mode 100755 tools/asahi/g17-capacity-backoff-tests.py diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs index 970035547dfee..c6c6b615ecd1a 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs @@ -8,7 +8,11 @@ use crate::g17::{ queue::admission::{RenderLease, Request}, }; use core::sync::atomic::Ordering; -use kernel::{prelude::*, sync::Arc}; +use kernel::{ + prelude::*, + sync::Arc, + time::{delay::fsleep, Delta}, +}; /// Internal result of a publication attempted from the submitting ioctl that /// met contention before anything became visible: the scheduler publishes the @@ -275,6 +279,13 @@ impl Backend { /// Render capacity is short: return what idle owners hold, then block until /// a pair, lease or owner returns. No packet is firmware-visible here, and /// neither the device mutex nor a preparation lease is held while waiting. + /// + /// A reclaim that returned something retries at once, but only once per + /// pause: reclaim can keep reporting returns (vacated pools the firmware has + /// not released yet, or backing another refused publisher takes first) + /// while the refusal persists. Every later refusal sleeps for at least the + /// clock's backoff pause, even when a notification (often another refused + /// publisher's own reclaim) ends the domain wait sooner. fn wait_render_capacity( &self, observed: &mut Option, @@ -284,7 +295,7 @@ impl Backend { if !sleep { return Err(FALLBACK); } - if self.reclaim_render_capacity()? { + if self.reclaim_render_capacity()? && clock.fast_retry() { *observed = None; return Ok(()); } @@ -294,15 +305,22 @@ impl Backend { }; self.shared.queue_events(); self.admission_open()?; + let started = super::super::now_ns(); let remaining = self .wait_deadline(clock, super::super::WORK_RING_WAIT_NS)? - .saturating_sub(super::super::now_ns()); + .saturating_sub(started); if remaining == 0 { return Err(EBUSY); } + let pause = clock.pause_ns(remaining); self.shared .renders - .block(sample, remaining.div_ceil(1_000_000).min(10) as u32, false) + .block(sample, remaining.div_ceil(1_000_000).min(10) as u32, false)?; + let left = pause.saturating_sub(super::super::now_ns().saturating_sub(started)); + if left != 0 { + fsleep(Delta::from_nanos(left as i64)); + } + Ok(()) } /// Gives idle render backing back under capacity pressure. Returns whether @@ -742,11 +760,21 @@ fn recovery_wait_ns() -> u64 { u64::from(crate::g17::timeout::RECOVERY_WAIT_MS) * 1_000_000 } +/// First pause of a render capacity wait (WaitClock::pause_ns). +const CAPACITY_PAUSE_MIN_NS: u64 = 50_000; +/// Longest pause of a render capacity wait: a 2 s wait makes at most about +/// a thousand attempts. +const CAPACITY_PAUSE_MAX_NS: u64 = 2_000_000; + /// One bounded wait (Backend::wait_deadline). #[derive(Default)] struct WaitClock { first: Option, calm: u64, + /// Pauses this wait has slept (pause_ns). + pauses: u32, + /// The immediate retry after a reclaim is used up until the next pause. + retried: bool, } impl WaitClock { @@ -760,6 +788,24 @@ impl WaitClock { .saturating_add(recovery_wait_ns()) .min(self.calm.saturating_add(bound_ns)) } + + /// Whether a refusal after a reclaim that returned something retries at + /// once: the first time, and again only after a pause. + fn fast_retry(&mut self) -> bool { + !core::mem::replace(&mut self.retried, true) + } + + /// The least time the next refused attempt sleeps: CAPACITY_PAUSE_MIN_NS, + /// doubling per pause up to CAPACITY_PAUSE_MAX_NS, never past `remaining`. + fn pause_ns(&mut self, remaining: u64) -> u64 { + let pause = CAPACITY_PAUSE_MIN_NS + .checked_shl(self.pauses) + .filter(|pause| *pause <= CAPACITY_PAUSE_MAX_NS) + .unwrap_or(CAPACITY_PAUSE_MAX_NS); + self.pauses = self.pauses.saturating_add(1); + self.retried = false; + pause.min(remaining) + } } #[kunit_tests(asahi_g17_wait_clock)] @@ -790,4 +836,39 @@ mod tests { let limit = 100 + recovery_wait_ns(); assert_eq!(clock.deadline(limit - 1, true, BOUND), limit); } + + #[test] + fn a_reclaim_retries_at_once_only_once_per_pause() { + let mut clock = WaitClock::default(); + assert!(clock.fast_retry()); + assert!(!clock.fast_retry()); + clock.pause_ns(BOUND); + assert!(clock.fast_retry()); + assert!(!clock.fast_retry()); + } + + #[test] + fn pauses_double_up_to_the_cap_and_stop_at_the_deadline() { + let mut clock = WaitClock::default(); + assert_eq!(clock.pause_ns(BOUND), CAPACITY_PAUSE_MIN_NS); + assert_eq!(clock.pause_ns(BOUND), 2 * CAPACITY_PAUSE_MIN_NS); + for _ in 0..80 { + assert!(clock.pause_ns(BOUND) <= CAPACITY_PAUSE_MAX_NS); + } + assert_eq!(clock.pause_ns(BOUND), CAPACITY_PAUSE_MAX_NS); + assert_eq!(clock.pause_ns(1_000), 1_000); + } + + #[test] + fn a_wait_that_always_wakes_makes_bounded_attempts() { + let mut clock = WaitClock::default(); + let (mut now, mut attempts) = (0, 0); + while now < BOUND { + attempts += 1; + if !clock.fast_retry() { + now += clock.pause_ns(BOUND - now); + } + } + assert!(attempts <= 2 * (BOUND / CAPACITY_PAUSE_MAX_NS + 16)); + } } diff --git a/tools/asahi/g17-capacity-backoff-tests.py b/tools/asahi/g17-capacity-backoff-tests.py new file mode 100755 index 0000000000000..9510927abd674 --- /dev/null +++ b/tools/asahi/g17-capacity-backoff-tests.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Run the production render capacity wait against a deterministic clock. + +Storm: every reclaim reports a return and notifies the render domain, and the +refusal never clears (the starvation case). Quiet: nothing is returned and +nothing notifies. Release: capacity appears after 5 ms. Each attempt costs +200 ns of fake CPU time. This tests the retry schedule, not firmware. +""" +from pathlib import Path +import os +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] / 'drivers/gpu/drm/asahi/g17' + + +def item(source, signature): + start = source.index(signature) + begin = source.index('{', start) + depth, end = 1, begin + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[start:end] + + +def const(source, name): + start = source.index('const ' + name) + return source[start:source.index(';', start) + 1] + + +def fixture(source): + parts = [const(source, 'CAPACITY_PAUSE_MIN_NS'), const(source, 'CAPACITY_PAUSE_MAX_NS'), + '#[derive(Default)]\n' + item(source, 'struct WaitClock'), item(source, 'impl WaitClock'), + 'impl Backend {\n' + item(source, 'fn wait_render_capacity(') + '\n}'] + code = '\n'.join(parts).replace('super::super::', 'rt::') + return r''' +#![allow(dead_code)] +use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +type Result = std::result::Result; +const EBUSY:i32=-16; const FALLBACK:i32=-115; +static NOW:AtomicU64=AtomicU64::new(0); +static GEN:AtomicU64=AtomicU64::new(0); +static ATTEMPTS:AtomicUsize=AtomicUsize::new(0); +static MODE:AtomicUsize=AtomicUsize::new(0); +const STORM:usize=0; const QUIET:usize=1; const RELEASE:usize=2; +const RELEASE_AT:u64=5_000_000; +fn recovery_wait_ns()->u64 {10_000_000_000} +mod rt {pub fn now_ns()->u64 {crate::NOW.load(crate::Ordering::SeqCst)} pub const WORK_RING_WAIT_NS:u64=2_000_000_000;} +struct Delta(i64); +impl Delta {fn from_nanos(n:i64)->Self {Delta(n)}} +fn fsleep(d:Delta) {assert!(d.0>0); NOW.fetch_add(d.0 as u64,Ordering::SeqCst);} +struct Renders; +impl Renders { + fn observe(&self)->u64 {GEN.load(Ordering::SeqCst)} + fn block(&self,sample:u64,ms:u32,_:bool)->Result { + assert!(ms>=1 && ms<=10); + if GEN.load(Ordering::SeqCst)!=sample {return Ok(());} + let now=NOW.load(Ordering::SeqCst); let mut until=now+u64::from(ms)*1_000_000; + if MODE.load(Ordering::SeqCst)==RELEASE && nowResult { + if MODE.load(Ordering::SeqCst)==STORM {GEN.fetch_add(1,Ordering::SeqCst); return Ok(true);} + Ok(false) + } + fn admission_open(&self)->Result {Ok(())} + fn wait_deadline(&self,clock:&mut WaitClock,bound:u64)->Result {Ok(clock.deadline(rt::now_ns(),false,bound))} +} +''' + code + r''' +fn run(mode:usize)->(Result,u64,usize) { + NOW.store(0,Ordering::SeqCst); GEN.store(0,Ordering::SeqCst); ATTEMPTS.store(0,Ordering::SeqCst); MODE.store(mode,Ordering::SeqCst); + let b=Backend{shared:Shared{renders:Renders}}; + let (mut observed,mut clock)=(None,WaitClock::default()); + let deadline=rt::WORK_RING_WAIT_NS; + let result=loop { + // One refused placement attempt of the caller's loop. + NOW.fetch_add(200,Ordering::SeqCst); + assert!(ATTEMPTS.fetch_add(1,Ordering::SeqCst)<200_000,"capacity wait spins"); + if rt::now_ns()>=deadline {break Err(EBUSY);} + if mode==RELEASE && rt::now_ns()>=RELEASE_AT {break Ok(());} + if let Err(e)=b.wait_render_capacity(&mut observed,&mut clock,true) {break Err(e);} + }; + (result,rt::now_ns(),ATTEMPTS.load(Ordering::SeqCst)) +} +fn main() { + let (r,t,n)=run(STORM); + assert_eq!(r,Err(EBUSY)); assert!(t>=2_000_000_000 && t<2_003_000_000,"storm ends at {t}"); assert!(n<=3_200,"storm attempts {n}"); + println!("storm: EBUSY at {:.3} s after {} attempts",t as f64/1e9,n); + let (r,t,n)=run(QUIET); + assert_eq!(r,Err(EBUSY)); assert!(t>=2_000_000_000 && t<2_011_000_000); assert!(n<=420,"quiet attempts {n}"); + println!("quiet: EBUSY at {:.3} s after {} attempts",t as f64/1e9,n); + let (r,t,n)=run(RELEASE); + assert_eq!(r,Ok(())); assert!(tResult {let b=Backend{shared:Shared{renders:Renders}}; b.wait_render_capacity(&mut None,&mut WaitClock::default(),false)} +''' + + +def main(): + source = (ROOT / 'runtime/render/submit.rs').read_text() + fixed = fixture(source) + cases = [('fixed', fixed), + ('retry-after-every-reclaim', fixed.replace('&& clock.fast_retry()', '')), + ('no-pause-after-wake', fixed.replace('if left != 0 {', 'if false {'))] + with tempfile.TemporaryDirectory(prefix='g17-capacity-backoff-') as tmp: + for name, code in cases: + assert name == 'fixed' or code != fixed, name + path = Path(tmp) / (name.replace('-', '_') + '.rs') + path.write_text(code) + binary = path.with_suffix('') + subprocess.run([os.environ.get('RUSTC', 'rustc'), '--edition=2021', '-O', str(path), '-o', str(binary)], check=True) + result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=30) + if name == 'fixed': + assert result.returncode == 0, result.stderr + print(result.stdout.strip()) + else: + assert result.returncode != 0, name + print('PASS negative control:', name) + + +if __name__ == '__main__': + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index c59c064f7f07e..5250d0337cf2d 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -127,6 +127,7 @@ def mutations(flag, names, base, expect=KILL): 'quarantine', 'epoch', 'cutoff', 'whole-batch', 'legacy-format', 'read-drain'), out()), 'g17-admission-deadline-tests.py': [([], PASS)], 'g17-admission-order-tests.py': [([], PASS)], + 'g17-capacity-backoff-tests.py': [([], PASS)], 'g17-capacity-fault-tests.py': [([], PASS)], 'g17-compute-constructor-tests.py': [([], PASS)], 'g17-compute-deadline-tests.py': [([], PASS)], From b84f5655f2ee380e57211e26cc09bb88ede28f2b Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 20:45:00 -0500 Subject: [PATCH 334/342] soc: apple: clpc: Hold T6050 CPU load at DCS 5 and fabric 2 A busy T6050 cluster in the upper half of its range asked for the top DCS and fabric states, 6 and 3, even for a loop that touches no memory. macOS's CLPC votes one state lower on each: traced on J714sAP under macOS 26A428, its voter word reads 0x25 (DCS 5, fabric 2) for 99% of an 18-thread CPU loop, 0 for 89% of idle and mostly 0 with one busy thread. Map the top two quartiles to DCS 5 and fabric 2. GPU work keeps both top states: the GPU driver's input now takes the higher of the map's top and the SoC's gpu states, which only T6050 sets, because bandwidth-bound GPU work runs about 11% slower at DCS 5. Signed-off-by: Diljit Singh --- drivers/soc/apple/clpc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index 1c590aa538f23..7a062b7af400c 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -679,7 +679,8 @@ static void apple_clpc_gpu_floor_count(struct apple_clpc *clpc, bool released) /* * The GPU driver's input, where it drives demand instead of the GFX power - * state: every rail at its top state while the driver reports work. + * state: every rail at the top of @map, or at @gpu where that is higher, + * while the driver reports work. */ static bool apple_clpc_gpu_input_demand(const struct apple_clpc_hw *hw, struct apple_clpc_gpu *gpu, @@ -692,7 +693,8 @@ static bool apple_clpc_gpu_input_demand(const struct apple_clpc_hw *hw, !apple_clpc_gpu_active(gpu, &updated, &sequence)) return false; for (rail = 0; rail < APPLE_CLPC_RAILS; rail++) - demand[rail] = max(demand[rail], hw->map[rail][APPLE_CLPC_LEVELS - 1]); + demand[rail] = max3(demand[rail], hw->map[rail][APPLE_CLPC_LEVELS - 1], + hw->gpu[rail]); return true; } @@ -1675,16 +1677,19 @@ static const struct apple_clpc_hw apple_clpc_hw_t8152 = { * The boot loader enables no agent on either rail, so without this floor * the DRAM controller and the fabric stay at state 0: CPU memcpy caps at * about 34 GB/s on the M5 Pro. A busy cluster in the upper half of its range - * asks for the top states; three busy samples in a row (12 ms) are needed, - * as on T6040. The GPU driver reports its work in flight and gets the top - * of the map while it has some. + * asks for DCS 5 and fabric 2, the floor macOS's CLPC holds through an + * 18-thread CPU loop (J714sAP, 26A428: 0x25 on its voter 99% of the time); + * three busy samples in a row (12 ms) are needed, as on T6040. The GPU driver + * reports its work in flight and gets both top states, DCS 6 and fabric 3, + * while it has some: bandwidth-bound GPU work runs about 11% slower at DCS 5. */ static const struct apple_clpc_hw apple_clpc_hw_t6050 = { .rail = { [APPLE_CLPC_DCS] = 0, [APPLE_CLPC_SOC] = 1 }, .map = { - [APPLE_CLPC_DCS] = { 2, 4, 6, 6 }, - [APPLE_CLPC_SOC] = { 1, 2, 3, 3 }, + [APPLE_CLPC_DCS] = { 2, 4, 5, 5 }, + [APPLE_CLPC_SOC] = { 1, 2, 2, 2 }, }, + .gpu = { [APPLE_CLPC_DCS] = 6, [APPLE_CLPC_SOC] = 3 }, .sustain = 3, .gpu_input = true, }; From b2783e0fa0c122ece1fba5045f40d5bbe3e717db Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 11:56:37 +1100 Subject: [PATCH 335/342] usb: typec: tipd: Wait for the power role swap to settle tps6598x_pr_set() reads STATUS as soon as the SWSk or SWSr task completes and returns -EPROTO unless the port role has already changed. The task completes when the PR_Swap has been accepted, but the port role changes only after the power supply transition that follows. On a MacBook Air (M2) with its port linked to another Mac, echo sink > /sys/class/typec/port1/power_role fails with "Protocol error", yet the swap completes: a moment later the port reads sink, the battery charges again and the link stays up. Poll STATUS until the port role matches, for at most the time the PR_Swap timers allow the two PS_RDY messages, and report -EPROTO only if it never does. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- drivers/usb/typec/tipd/core.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 3121d95142c47..fed6ea4097662 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -460,12 +461,21 @@ static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role) return ret; } +/* + * After a PR_Swap is accepted, the initial sink waits up to tPSSourceOff + * (920 ms) for the initial source's PS_RDY, and the initial source then + * waits up to tPSSourceOn (480 ms) for the new source's PS_RDY (USB Power + * Delivery, PR_Swap timers). + */ +#define TPS_PR_SWAP_TIMEOUT_US (1400 * USEC_PER_MSEC) +#define TPS_PR_SWAP_POLL_US (10 * USEC_PER_MSEC) + static int tps6598x_pr_set(struct typec_port *port, enum typec_role role) { const char *cmd = (role == TYPEC_SINK) ? "SWSk" : "SWSr"; struct tps6598x *tps = typec_get_drvdata(port); u32 status; - int ret; + int ret, err; mutex_lock(&tps->lock); @@ -473,11 +483,18 @@ static int tps6598x_pr_set(struct typec_port *port, enum typec_role role) if (ret) goto out_unlock; - ret = tps6598x_read32(tps, TPS_REG_STATUS, &status); + /* + * The task completes once the swap has been accepted, but the port + * role in STATUS changes only after the power supply transition that + * follows, so wait for it before calling the swap a failure. + */ + err = read_poll_timeout(tps6598x_read32, ret, + ret || TPS_STATUS_TO_TYPEC_PORTROLE(status) == role, + TPS_PR_SWAP_POLL_US, TPS_PR_SWAP_TIMEOUT_US, false, + tps, TPS_REG_STATUS, &status); if (ret) goto out_unlock; - - if (role != TPS_STATUS_TO_TYPEC_PORTROLE(status)) { + if (err) { ret = -EPROTO; goto out_unlock; } From a34f50bad4fea82ad5e2731ed9116db98e592a21 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 9 Nov 2026 21:56:21 -0500 Subject: [PATCH 336/342] soc: apple: clpc: Take the GPU floor with max(), not max3() The host test that builds the CLPC demand code outside the kernel has no max3() in its shim. Nest max() instead, as the line did before. Signed-off-by: Diljit Singh --- drivers/soc/apple/clpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index 7a062b7af400c..96fc0550bc027 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -693,8 +693,8 @@ static bool apple_clpc_gpu_input_demand(const struct apple_clpc_hw *hw, !apple_clpc_gpu_active(gpu, &updated, &sequence)) return false; for (rail = 0; rail < APPLE_CLPC_RAILS; rail++) - demand[rail] = max3(demand[rail], hw->map[rail][APPLE_CLPC_LEVELS - 1], - hw->gpu[rail]); + demand[rail] = max(demand[rail], + max(hw->map[rail][APPLE_CLPC_LEVELS - 1], hw->gpu[rail])); return true; } From 7d3d4e60de0bb3ba784e36c7a9a02db789e6c08d Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:57:44 -0600 Subject: [PATCH 337/342] arm64: dts: apple: t6050-j714c: Describe the left-front USB-C port (#1403) Enable the ATC1 template of t6050-dieX.dtsi on the J714c and link it to the port's PD controller: usb-pd@a on nub-spmi-a0, an SN201202x at SPMI address 0xa. The J714cAP ADT names it hpm1, port-number 2, port-location "left-front", acio-parent acio1, with atc-phy1, usb-drd1 and dart-usb1. The board file no longer disables nub-spmi-a0, atc1_phy, atc1_phy_mbox, usb_drd1 and its two DARTs. The atcphy1 alias lets the boot loader fill the PHY tunables. The left-back port (ATC0, hpm0) is not described. The combo PHY binding and driver exclude port index 0, the debug port that carries the boot link, on purpose. The port's USB4/Thunderbolt router (acio1) and its DisplayPort routes are not described; the PHY runs in USB mode. The other ten T6050 board DTBs are byte-identical. --- arch/arm64/boot/dts/apple/t6050-j714c.dts | 93 +++++++++++++++++------ 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j714c.dts b/arch/arm64/boot/dts/apple/t6050-j714c.dts index bd4ea3fc0d288..2afe054d92c03 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714c.dts @@ -109,35 +109,11 @@ }; }; -/* ATC1, ATC3 and the PD controller buses nub-spmi-a0 and -a2: not yet described for this board */ -&nub_spmi_a0 { - status = "disabled"; -}; - +/* ATC3 and the PD controller bus nub-spmi-a2: not on this board's ports */ &nub_spmi_a2 { status = "disabled"; }; -&atc1_phy_mbox { - status = "disabled"; -}; - -&atc1_phy { - status = "disabled"; -}; - -&usb_drd1 { - status = "disabled"; -}; - -&usb_drd1_dart_0 { - status = "disabled"; -}; - -&usb_drd1_dart_1 { - status = "disabled"; -}; - &atc3_phy_mbox { status = "disabled"; }; @@ -278,6 +254,73 @@ #include "t6050-max-atc2.dtsi" +/* + * ==== The left-front USB-C port (ATC1) ==== + * + * ADT /arm-io/nub-spmi-a0/hpm1 (SN201202x, SPMI address 0xa, port-number 2, port-location + * "left-front", acio-parent acio1), with atc-phy1, usb-drd1 and dart-usb1. The PHY, the DWC3 and + * their DARTs and mailbox are the ATC1 template of t6050-dieX.dtsi; only the links to the PD + * controller are the board's. The port's USB4/Thunderbolt router (/arm-io/acio1) and its + * DisplayPort routes are not described yet; the PHY runs in USB mode. + * + * The left-back port (ATC0, hpm0) is the boot link's debug port. The combo PHY binding and + * driver exclude it on purpose (apple,port-index 0), so it is not described either. + */ +/ { + aliases { + atcphy1 = &atc1_phy; + }; +}; + +&atc1_phy { + port { + atc1_phy_ep: endpoint { + remote-endpoint = <&hpm1_ss>; + }; + }; +}; + +&usb_drd1 { + port { + usb_drd1_hs: endpoint { + remote-endpoint = <&hpm1_hs>; + }; + }; +}; + +&nub_spmi_a0 { + hpm1: usb-pd@a { + compatible = "apple,sn201202x"; + reg = <0xa SPMI_USID>; + + connector { + compatible = "usb-c-connector"; + label = "USB-C Left Front"; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + hpm1_hs: endpoint { + remote-endpoint = <&usb_drd1_hs>; + }; + }; + + port@1 { + reg = <1>; + hpm1_ss: endpoint { + remote-endpoint = <&atc1_phy_ep>; + }; + }; + }; + }; + }; +}; + /* The host DROM from the J714cAP ADT (/arm-io/acio2 thunderbolt-drom); the boot loader replaces it */ &acio2_nhi { apple,thunderbolt-drom = [fd 02 00 00 00 00 00 00 00 90 19 c3 8c 00 5c 00 From 8e44895ce96f7b796f9ef06ea9a98f7b9553a5b7 Mon Sep 17 00:00:00 2001 From: Ryan <81541646+RyanTheTide@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:16:30 +1100 Subject: [PATCH 338/342] arm64: dts: apple: t8140-j700: reserve the configured AOP and always-on GPIO lines (#1407) The AOP and always-on GPIO banks are enabled with no consumer. Some of their lines are already configured by the firmware when Linux boots (non-reset mode, pulls or drive strength, one output driven high) and nothing says what they are for. Mark those lines in gpio-reserved-ranges so gpiolib never hands them out and the driver's register map leaves their pad registers alone. Lines still in the reset state stay available. Assisted-by: LLM Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8140-j700.dts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8140-j700.dts b/arch/arm64/boot/dts/apple/t8140-j700.dts index ba91829924008..ce94f916ff754 100644 --- a/arch/arm64/boot/dts/apple/t8140-j700.dts +++ b/arch/arm64/boot/dts/apple/t8140-j700.dts @@ -716,9 +716,12 @@ /* * The AOP's GPIO bank. The AOP keeps interrupt groups 0-3; the AP's are 4-6 - * (AIC 384-386). No consumer requests a line yet. + * (AIC 384-386). No consumer requests a line yet. The reserved lines are the + * ones the firmware has already configured away from the bank's reset state + * by the time Linux boots; their users are not known, so they stay off limits. */ &pinctrl_aop { + gpio-reserved-ranges = <18 1>, <21 1>, <27 9>, <46 2>, <50 7>; interrupts = , , ; @@ -728,10 +731,12 @@ /* * The always-on GPIO bank, as on the J616s: the AP takes none of its - * interrupts. Line 20 is the secure-repair enable and is never requested. + * interrupts. Line 20 is the secure-repair enable and is never requested; + * the other reserved lines are configured by the firmware before Linux + * boots (line 27 is driven high) and have no known user. */ &pinctrl_nub { - gpio-reserved-ranges = <20 1>; + gpio-reserved-ranges = <5 1>, <10 1>, <20 1>, <23 1>, <27 3>; status = "okay"; /delete-property/ interrupt-controller; /delete-property/ #interrupt-cells; From 50e5f040ba07a32c0df012559f054b593caa3c65 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:23:45 -0600 Subject: [PATCH 339/342] arm64: dts: apple: t6050-j714c: Describe the six speaker amplifiers (#1408) * arm64: dts: apple: t6050-j714c: Describe the six speaker amplifiers Enable i2c1 and i2c3 on the J714c and describe the six SN012776 speaker amplifiers from the J714cAP ADT: left woofer 1, left woofer 2 and left tweeter on i2c1 at 0x38, 0x39 and 0x3a, right woofer 1, right woofer 2 and right tweeter on i2c3 at 0x3b, 0x3c and 0x3d. The amplifiers share one shutdown line, AP pin 107 (function-reset of the first), described as the speaker_sdz fixed regulator with apple,sdz-group-fail-closed, and one fault interrupt, pin 106. Each amplifier's sense slots come from the ADT speaker-config, where the transmit slot N belongs to speakerN: voltage sense in slot 4N, current sense in slot 4N+2. ps_i2c3 has no described parent (SIO), as for i2c1 and i2c2. Pins 106 and 107 join pin 80 in the exposed range of pinctrl_ap. There is no sound card, no jack codec and no AOP audio change. The other ten T6050 board DTBs are byte-identical. * arm64: dts: apple: t6050-j714c: Clock i2c3 from the reference clock The i2c3 stub of t6050-peripherals.dtsi takes <&peripheral_clocks 4>. No driver in the tree provides apple,pmgr-clocks, so i2c3 and the three amplifiers on it would never probe. The ADT gives i2c1, i2c2 and i2c3 the same clock-ids (4), and i2c1 and i2c2 take <&clkref>, so the J714c does the same for i2c3. The other ten T6050 board DTBs are byte-identical. --- arch/arm64/boot/dts/apple/t6050-j714c.dts | 114 +++++++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6050-j714c.dts b/arch/arm64/boot/dts/apple/t6050-j714c.dts index 2afe054d92c03..89b4c00d310a2 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714c.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714c.dts @@ -134,8 +134,64 @@ status = "disabled"; }; +/* + * The six speaker amplifiers (ADT /arm-io/i2c1/audio-speaker* and /arm-io/i2c3/audio-speaker*, + * SN012776) share one shutdown line, AP pin 107 (function-reset of the first), and one fault + * interrupt, pin 106. The ADT's speaker-config gives each amp a transmit slot N with its + * voltage sense in slot 4N and current sense in 4N+2, and names the amps by speakerN: + * 0 left woofer 1, 1 right woofer 1, 2 left woofer 2, 3 right woofer 2, 4 left tweeter, + * 5 right tweeter. + * + * There is no sound card yet: the AOP audio driver is not on this branch, and the jack codec + * (i2c2) is not described. The amps stay in shutdown until a stream asks for them. + */ +/ { + speaker_sdz: regulator-sn012776-sdz { + compatible = "regulator-fixed"; + regulator-name = "sn012776-sdz"; + gpios = <&pinctrl_ap 107 GPIO_ACTIVE_HIGH>; + enable-active-high; + }; +}; + &i2c1 { - status = "disabled"; + status = "okay"; + + speaker_left_woof1: codec@38 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x38>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Woofer 1"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <2>; + ti,vmon-slot-no = <0>; + }; + + speaker_left_woof2: codec@39 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x39>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Woofer 2"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <10>; + ti,vmon-slot-no = <8>; + }; + + speaker_left_tweet: codec@3a { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3a>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Left Tweeter"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <18>; + ti,vmon-slot-no = <16>; + }; }; &i2c2 { @@ -144,10 +200,11 @@ /* * Only the pins a node here names are exposed, as on the J716c: pin 112's register - * takes an SError when read. 80 is PCIe port 0's PERST#. + * takes an SError when read. 80 is PCIe port 0's PERST#, 106 the amps' fault interrupt and + * 107 their shutdown line. */ &pinctrl_ap { - gpio-reserved-ranges = <0 80>, <81 140>; + gpio-reserved-ranges = <0 80>, <81 25>, <108 113>; }; /* This board's SMC fan and power keys are not yet checked */ @@ -254,6 +311,57 @@ #include "t6050-max-atc2.dtsi" +/* The I2C power states have no described parent (SIO), as for i2c1 and i2c2 */ +&ps_i2c3 { + /delete-property/ power-domains; + status = "okay"; +}; + +&i2c3 { + /* + * The stub's pmgr clock controller has no driver. The ADT gives i2c1, i2c2 and i2c3 the same + * clock-ids (4), so i2c3 takes the reference clock as i2c1 and i2c2 do. + */ + clocks = <&clkref>; + status = "okay"; + + speaker_right_woof1: codec@3b { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3b>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Woofer 1"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <6>; + ti,vmon-slot-no = <4>; + }; + + speaker_right_woof2: codec@3c { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3c>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Woofer 2"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <14>; + ti,vmon-slot-no = <12>; + }; + + speaker_right_tweet: codec@3d { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x3d>; + SDZ-supply = <&speaker_sdz>; + apple,sdz-group-fail-closed; + #sound-dai-cells = <0>; + sound-name-prefix = "Right Tweeter"; + interrupts-extended = <&pinctrl_ap 106 IRQ_TYPE_LEVEL_LOW>; + ti,imon-slot-no = <22>; + ti,vmon-slot-no = <20>; + }; +}; + /* * ==== The left-front USB-C port (ATC1) ==== * From b51ebfcf0a91f4145ad4a06d9097fa1717c25ee7 Mon Sep 17 00:00:00 2001 From: Adam Harris Date: Thu, 29 Oct 2026 13:36:32 -0600 Subject: [PATCH 340/342] arm64: dts: apple: t6030: give the SEP DART its window and spi2 the Touch ID sensor The SEP, its DART and mailbox, and spi2 are already described (disabled) in t6030-coprocessors.dtsi and t6030-peripheral-buses.dtsi. Touch ID needs two things more, as the J514s ADT (system firmware 27.0) records them: - The SEP DART only accepts IOVAs in the window iBoot programmed: vm-base 0x10000004000, vm-size 0xffff0000, the same BIT(40) aperture as on T8122. Describe it with apple,dma-range and apple,dma-offset. - The Mesa sensor sits on spi2, chip select 0, at 8 MHz with CPHA. Add it as spi2's child. Everything stays disabled: apple_sep enables the SEP and its DART when it loads, and boards enable the mailbox, the bus and the sensor. Assisted-by: LLM Signed-off-by: Adam Harris Co-Authored-By: Claude Opus 5.5 --- arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi | 9 +++++++++ .../boot/dts/apple/t6030-peripheral-buses.dtsi | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi b/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi index 8ffda682587ef..bf1ff9bb89e71 100644 --- a/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi +++ b/arch/arm64/boot/dts/apple/t6030-coprocessors.dtsi @@ -2,12 +2,21 @@ /* Disabled coprocessor interfaces; firmware handoff remains a loader job. */ &soc { + /* + * iBoot hands over a running SEP (ADT sepfw-load-at-boot). Keep Linux + * off its DART at boot; apple_sep enables it when the driver binds. The + * SEP only accepts IOVAs in the window iBoot programmed (ADT vm-base + * 0x10000004000, vm-size 0xffff0000), which carries the BIT(40) alias + * the DART translates. + */ sep_dart: iommu@29cac0000 { compatible = "apple,t6030-dart", "apple,t8110-dart"; reg = <0x2 0x9cac0000 0 0x4000>; interrupt-parent = <&aic>; interrupts = ; #iommu-cells = <1>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,dma-offset = /bits/ 64 <0x0>; status = "disabled"; }; diff --git a/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi b/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi index b03254c622758..691f07f160880 100644 --- a/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi +++ b/arch/arm64/boot/dts/apple/t6030-peripheral-buses.dtsi @@ -2,6 +2,11 @@ /* Unclaimed T6030 peripheral buses. */ &soc { + /* + * Touch ID (J514s ADT /arm-io/spi2). iBoot leaves the pads muxed and + * the controller uses its native chip select, so there is no pinctrl + * here. + */ spi2: spi@289108000 { compatible = "apple,t6030-spi", "apple,t8103-spi"; reg = <0x2 0x89108000 0 0x4000>; @@ -12,6 +17,14 @@ #address-cells = <1>; #size-cells = <0>; status = "disabled"; + + mesa: fingerprint@0 { + compatible = "apple,mesa-fingerprint"; + reg = <0>; + spi-max-frequency = <8000000>; + spi-cpha; + status = "disabled"; + }; }; spi4: spi@289110000 { From fd1e1c12cabf88dbe3703b59bbaf29b8a6460842 Mon Sep 17 00:00:00 2001 From: Adam Harris Date: Thu, 29 Oct 2026 13:36:32 -0600 Subject: [PATCH 341/342] arm64: dts: apple: t6030-j514s: enable Touch ID Enable the SEP mailbox, spi2 and the Mesa sensor (0x3352) on the 14" M3 Pro. Per the J514s ADT, the sensor is powered from NUB GPIO 33, active high. As on J613, its data-ready line (AP GPIO 200) is left out and the driver polls. The calibration comes from this Mac's own iBoot system container as apple/mesacal-j514s.bin. J516s shares the SoC, but its sensor wiring is unchecked, so it stays off. Assisted-by: LLM Signed-off-by: Adam Harris Co-Authored-By: Claude Opus 5.5 --- arch/arm64/boot/dts/apple/t6030-j514s.dts | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6030-j514s.dts b/arch/arm64/boot/dts/apple/t6030-j514s.dts index 1ccf2f1294d6b..cc1070d099267 100644 --- a/arch/arm64/boot/dts/apple/t6030-j514s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j514s.dts @@ -18,6 +18,10 @@ compatible = "apple,j514s", "apple,t6030", "apple,arm-platform"; model = "Apple MacBook Pro (14-inch, M3 Pro, Nov 2023)"; + aliases { + sep = &sep; + }; + chosen { asahi,t6030-dispext = "1"; }; @@ -115,3 +119,27 @@ status = "disabled"; }; }; + +/* apple_sep enables the SEP and its DART when it loads. */ +&sep_mbox { + status = "okay"; +}; + +/* + * Touch ID sensor (Mesa 0x3352, J514s ADT /arm-io/spi2/mesa): power on + * NUB GPIO 33, active high. As on J613, the data-ready line (AP GPIO 200) + * is left out, so the driver polls until its trigger is confirmed. Native + * chip select only. + */ +&spi2 { + status = "okay"; +}; + +&mesa { + status = "okay"; + enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; + spi-cs-setup-delay-ns = <20>; + spi-cs-hold-delay-ns = <20>; + /* Per-device factory data from this Mac's own iBoot system container. */ + firmware-name = "apple/mesacal-j514s.bin"; +}; From fd840c994b94111939ab6867f031cf38f1723717 Mon Sep 17 00:00:00 2001 From: Adam Harris Date: Thu, 29 Oct 2026 13:36:33 -0600 Subject: [PATCH 342/342] soc: apple: sep: add a T6030/J514s profile The J514s SEP is pre-booted by iBoot and speaks the variant-5 key store, and its sensor is the same 0x3352 part T8122 carries, in SPI mode 1. So J514s takes the T8122 profile with its own spi2 base, including the wide DMA mask and xART guard level 1 from the first boot. Only J514s is matched; the other T6030 Mac (J516s) has not had its ADT read. Add a test that checks the J514s device tree against the ADT values and that J516s leaves the SEP and the sensor off. Tested on J514s, system firmware 27.0, with macOS on the same disk: - the SEP attaches warm and advertises 12 endpoints - the keybag is provisioned; the guard protects all 10 existing macOS session records and has refused nothing - the sensor answers 18 ms after power-on and registers its serial - enrolment and a match work, and a match still works after a reboot and after suspend - macOS Touch ID still works afterwards Assisted-by: LLM Signed-off-by: Adam Harris Co-Authored-By: Claude Opus 5.5 --- drivers/soc/apple/profile.rs | 34 +++++- drivers/soc/apple/xart_guard.rs | 1 + tools/aurora-sep/tests/test_t6030_sep.py | 132 +++++++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 tools/aurora-sep/tests/test_t6030_sep.py diff --git a/drivers/soc/apple/profile.rs b/drivers/soc/apple/profile.rs index 5accaf70cb404..7059cb34e1c28 100644 --- a/drivers/soc/apple/profile.rs +++ b/drivers/soc/apple/profile.rs @@ -430,6 +430,26 @@ pub(crate) const T8122: PlatformProfile = PlatformProfile { ..T8112 }; +/// MacBook Pro 14" M3 Pro (J514s). The J514s ADT (system firmware 27.0) records +/// a pre-booted SEP (`sepfw-load-at-boot`), an `iop-sep,ascwrap-v6` SEP and +/// its DART at the same addresses as T8122's, with the same BIT(40) aperture +/// (`vm-base` 0x10000004000, `vm-size` 0xffff0000). The Mesa sensor is the +/// `0x3352` part T8122 carries, on spi2 at `0x289108000`, 8 MHz, chip select +/// 0. Its power is NUB GPIO 33 and its data-ready line AP GPIO 200. +/// `/defaults` carries `cpx-encryption-mode = 2`. +/// +/// Otherwise T8122's warm-registration profile. J514s on system firmware 27.0 +/// attaches, provisions the keybag, enrols, matches, and still matches after a +/// reboot and after suspend; macOS Touch ID keeps working alongside it. +pub(crate) const T6030: PlatformProfile = PlatformProfile { + name: "T6030/J514s", + sensor: SensorProfile { + controller_base: 0x2_8910_8000, + ..T8122.sensor + }, + ..T8122 +}; + /// MacBook Pro 16" M4 Pro (J616s). The J616s ADT (26.6.2, 25G83) records a /// pre-booted SEP (`sepfw-load-at-boot`), an `iop-sep,ascwrap-v6` SEP whose /// DART aperture starts at the BIT(40) alias (`vm-base` 0x10000004000), and @@ -513,6 +533,9 @@ static_assert!(T8112.sensor.controller_base == T8103.sensor.controller_base); static_assert!(T8122.shmem_capacity == T8112.shmem_capacity); static_assert!(T8122.sensor.controller_base == 0x2a1108000); static_assert!(T8122.wide_dma_mask); +static_assert!(T6030.sensor.controller_base == 0x289108000); +static_assert!(T6030.sensor.expected_id == T8122.sensor.expected_id); +static_assert!(T6030.wide_dma_mask); static_assert!(T6040.sensor.controller_base == 0x429108000); static_assert!(T6040.sensor.expected_id == T8140.sensor.expected_id); static_assert!(T8132.sensor.controller_base == 0x3ad108000); @@ -673,6 +696,11 @@ fn select( if has(b"apple,t8122") && (has(b"apple,j613") || has(b"apple,j615")) { return Ok(&T8122); } + // Only the board whose ADT was read: J514s. The 16" M3 Pro (J516s) + // shares the SoC but its sensor wiring is unchecked. + if has(b"apple,t6030") && has(b"apple,j514s") { + return Ok(&T6030); + } // The T6040 profile is tested on J614s and J616s. if has(b"apple,t6040") && (has(b"apple,j616s") || has(b"apple,j614s")) { return Ok(&T6040); @@ -760,6 +788,9 @@ mod tests { assert_eq!(picked(&[b"apple,j713", b"apple,t8122"]), None); assert_eq!(picked(&[b"apple,j613", b"apple,t8122"]), Some(T8122.name)); assert_eq!(picked(&[b"apple,j700", b"apple,t8140"]), Some(T8140.name)); + assert_eq!(picked(&[b"apple,j514s", b"apple,t6030"]), Some(T6030.name)); + assert_eq!(picked(&[b"apple,j516s", b"apple,t6030"]), None); + assert_eq!(picked(&[b"apple,t6030"]), None); assert_eq!(picked(&[b"apple,j616s", b"apple,t6040"]), Some(T6040.name)); assert_eq!(picked(&[b"apple,t6040"]), None); assert_eq!(picked(&[b"apple,j614s", b"apple,t6040"]), Some(T6040.name)); @@ -777,7 +808,7 @@ mod tests { /// profile naming one of the known Mesa revisions. #[test] fn every_touch_id_mac_gets_a_sensor_the_shared_path_decodes() { - let macs: [&[&[u8]]; 15] = [ + let macs: [&[&[u8]]; 16] = [ &[b"apple,j313", b"apple,t8103"], &[b"apple,j316s", b"apple,t6000"], &[b"apple,j316c", b"apple,t6001"], @@ -787,6 +818,7 @@ mod tests { &[b"apple,j415", b"apple,t8112"], &[b"apple,j613", b"apple,t8122"], &[b"apple,j615", b"apple,t8122"], + &[b"apple,j514s", b"apple,t6030"], &[b"apple,j614s", b"apple,t6040"], &[b"apple,j616s", b"apple,t6040"], &[b"apple,j616c", b"apple,t6041"], diff --git a/drivers/soc/apple/xart_guard.rs b/drivers/soc/apple/xart_guard.rs index 5fe73719e3e33..9c2033b7497a9 100644 --- a/drivers/soc/apple/xart_guard.rs +++ b/drivers/soc/apple/xart_guard.rs @@ -1069,6 +1069,7 @@ mod tests { assert_eq!(level(-1, profile::T6020_SEPOS13.xart_guard), Some(1)); assert_eq!(level(-1, profile::T8112.xart_guard), Some(1)); assert_eq!(level(-1, profile::T8122.xart_guard), Some(1)); + assert_eq!(level(-1, profile::T6030.xart_guard), Some(1)); // Off on the Neo, whose Linux records predate the list. assert_eq!(level(-1, profile::T8140.xart_guard), None); assert_eq!(level(i8::MIN, 1), Some(1)); diff --git a/tools/aurora-sep/tests/test_t6030_sep.py b/tools/aurora-sep/tests/test_t6030_sep.py new file mode 100644 index 0000000000000..9b2aa99bc9211 --- /dev/null +++ b/tools/aurora-sep/tests/test_t6030_sep.py @@ -0,0 +1,132 @@ +"""T6030 (MacBook Pro 14" M3 Pro, J514s) SEP and Mesa sensor device tree and profile. + +Set DTC to this kernel's built scripts/dtc/dtc for Apple floating-point cells. +""" + +from pathlib import Path +import os +import re +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[3] +DTS = ROOT / "arch/arm64/boot/dts/apple" +DTC = os.environ.get("DTC", "dtc") +PROFILE = (ROOT / "drivers/soc/apple/profile.rs").read_text() + +SEP_DART = "/soc/iommu@29cac0000" +SEP = "/soc/sep@29e400000" +BUS = "/soc/spi@289108000" +SENSOR = BUS + "/fingerprint@0" +PINCTRL_NUB = "/soc/pinctrl@3641f0000" +MBOX = "/soc/mailbox@29e408000" +# AIC_IRQ cells: , IRQ_TYPE_LEVEL_HIGH = 4. +LEVEL_HIGH = 4 + + +@unittest.skipUnless(all(shutil.which(tool) for tool in ("cpp", DTC, "fdtget")), + "requires cpp, dtc and fdtget") +class T6030SepTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.temp = tempfile.TemporaryDirectory(prefix="aurora-t6030-sep-") + cls.addClassCleanup(cls.temp.cleanup) + cls.out = Path(cls.temp.name) + + def compile_board(self, board): + pp = subprocess.run(["cpp", "-nostdinc", "-undef", "-D__DTS__", "-x", + "assembler-with-cpp", "-I", str(ROOT / "include"), + "-I", str(DTS), str(DTS / f"t6030-{board}.dts")], + check=True, capture_output=True) + output = self.out / f"{board}.dtb" + subprocess.run([DTC, "-q", "-I", "dts", "-O", "dtb", "-o", str(output)], + input=pp.stdout, check=True, capture_output=True) + return output + + def prop(self, dtb, node, name, kind="x"): + return subprocess.run(["fdtget", "-t", kind, str(dtb), node, name], + check=True, capture_output=True, text=True).stdout.split() + + def props(self, dtb, node): + return subprocess.run(["fdtget", "-p", str(dtb), node], + check=True, capture_output=True, text=True).stdout.split() + + def cells(self, dtb, node, name): + return [int(cell, 16) for cell in self.prop(dtb, node, name)] + + def irqs(self, dtb, node): + cells = self.cells(dtb, node, "interrupts") + self.assertEqual(len(cells) % 3, 0) + triples = [cells[i:i + 3] for i in range(0, len(cells), 3)] + for kind, _, flags in triples: + self.assertEqual((kind, flags), (0, LEVEL_HIGH)) + return [irq for _, irq, _ in triples] + + def test_j514s_describes_sep_and_sensor(self): + dtb = self.compile_board("j514s") + # apple_sep enables the SEP and its DART at module load. + self.assertEqual(self.prop(dtb, SEP_DART, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, SEP, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, MBOX, "status", "s"), ["okay"]) + # ADT vm-base 0x10000004000, vm-size 0xffff0000, as on t8122. + self.assertEqual(self.cells(dtb, SEP_DART, "apple,dma-range"), + [0x100, 0x4000, 0, 0xffff0000]) + self.assertEqual(self.cells(dtb, SEP_DART, "apple,dma-offset"), [0, 0]) + self.assertEqual(self.prop(dtb, "/aliases", "sep", "s"), [SEP]) + + self.assertEqual(self.prop(dtb, BUS, "status", "s"), ["okay"]) + self.assertEqual(self.prop(dtb, SENSOR, "status", "s"), ["okay"]) + self.assertEqual(self.prop(dtb, SENSOR, "firmware-name", "s"), + ["apple/mesacal-j514s.bin"]) + nub = int(self.prop(dtb, PINCTRL_NUB, "phandle")[0], 16) + self.assertEqual(self.cells(dtb, SENSOR, "enable-gpios"), [nub, 33, 0]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-max-frequency", "u"), ["8000000"]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-cs-setup-delay-ns", "u"), ["20"]) + self.assertEqual(self.prop(dtb, SENSOR, "spi-cs-hold-delay-ns", "u"), ["20"]) + properties = self.props(dtb, SENSOR) + self.assertIn("spi-cpha", properties) + self.assertNotIn("spi-cpol", properties) + self.assertNotIn("interrupts", properties) + self.assertNotIn("cs-gpios", self.props(dtb, BUS)) + + def test_addresses_and_interrupts_match_the_adt(self): + # The J514s ADT values (system firmware 27.0), /arm-io base 0x210000000 added. + dtb = self.compile_board("j514s") + self.assertEqual(self.cells(dtb, SEP_DART, "reg"), [0x2, 0x9cac0000, 0, 0x4000]) + self.assertEqual(self.irqs(dtb, SEP_DART), [372]) + self.assertEqual(self.cells(dtb, SEP, "reg")[:4], [0x2, 0x9e400000, 0, 0x6c000]) + self.assertEqual(self.cells(dtb, MBOX, "reg"), [0x2, 0x9e408000, 0, 0x4000]) + self.assertEqual(self.prop(dtb, MBOX, "interrupt-names", "s"), + ["send-empty", "send-not-empty", "recv-empty", "recv-not-empty"]) + self.assertEqual(self.irqs(dtb, MBOX), [366, 367, 368, 369]) + mbox = int(self.prop(dtb, MBOX, "phandle")[0], 16) + dart = int(self.prop(dtb, SEP_DART, "phandle")[0], 16) + self.assertEqual(self.cells(dtb, SEP, "mboxes"), [mbox]) + self.assertEqual(self.cells(dtb, SEP, "iommus"), [dart, 0]) + self.assertEqual(self.cells(dtb, BUS, "reg"), [0x2, 0x89108000, 0, 0x4000]) + self.assertEqual(self.irqs(dtb, BUS), [876]) + self.assertEqual(self.cells(dtb, SENSOR, "reg"), [0]) + + def test_j516s_leaves_sep_and_sensor_off(self): + dtb = self.compile_board("j516s") + self.assertNotIn("sep", self.props(dtb, "/aliases")) + self.assertEqual(self.prop(dtb, MBOX, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, BUS, "status", "s"), ["disabled"]) + self.assertEqual(self.prop(dtb, SENSOR, "status", "s"), ["disabled"]) + + def test_profile_selected_only_on_j514s(self): + select = PROFILE.split("fn select(", 1)[1] + line = next(line for line in select.splitlines() if 'b"apple,t6030"' in line) + self.assertIn('b"apple,j514s"', line) + profile = re.search(r"const T6030: PlatformProfile = PlatformProfile \{(.*?)\n\};", + PROFILE, re.S).group(1) + self.assertIn("..T8122", profile) + # The diagnostic controller base is spi2's, not T8122's. + self.assertIn("controller_base: 0x2_8910_8000", profile) + + +if __name__ == "__main__": + unittest.main()