Repository navigation
media: apple: isp: T8140 (J700) camera support and ISP driver fixes (reworked) - #12
Merged
Merged
Conversation
RyanTheTide
force-pushed
the
series/neo-prerequisites-20260924
branch
from
September 24, 2026 03:06
ee76ce3 to
021cafc
Compare
RyanTheTide
force-pushed
the
series/neo-isp-20260924
branch
from
September 24, 2026 03:06
3007ce5 to
fb22821
Compare
RyanTheTide
force-pushed
the
series/neo-prerequisites-20260924
branch
from
September 25, 2026 14:54
021cafc to
2903144
Compare
RyanTheTide
changed the base branch from
series/neo-prerequisites-20260924
to
aurora-wip
September 25, 2026 14:54
apple_isp_power_up_domains() takes a runtime PM reference on each auxiliary power domain, index 1 and up; index 0 follows the ISP device through its device link. When one of them fails to resume, the unwind loop `while (--i != 1)` releases the wrong set of references: a failure on domain 2 releases nothing and leaks domain 1, a failure on domain 3 releases domain 2 and leaks domain 1, and a failure on domain 1 releases domain 0, which was never taken here, and then keeps going below zero, indexing pd_dev[-1] and beyond. pm_runtime_get_sync() also leaves the usage count of the domain that failed incremented. Release every domain from i - 1 down to 1, and use pm_runtime_resume_and_get(), which drops the reference of the domain that failed to resume. Compile-tested only; not run on hardware. Fixes: b11332c ("media: apple: isp: Make sub-pmdomain handling explicit") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
Boot stage 1 powers up the auxiliary power domains, resets the coprocessor, starts it and waits for the first firmware handshake. When the reset or the handshake fails, isp_firmware_boot_stage1() returns without undoing any of that, and isp_firmware_boot() does not call isp_firmware_shutdown_stage1() for the stage that failed. The domains stay powered with pds_active set, and after a handshake timeout the coprocessor is left running with its control register at 0x10. Nothing turns either off until a later boot succeeds and is shut down. Undo stage 1 on its own error paths: stop the coprocessor and power the domains down. Compile-tested only; not run on hardware. Fixes: b11332c ("media: apple: isp: Make sub-pmdomain handling explicit") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
iommu_map_sgtable() returns the number of bytes it mapped or a negative error code. isp_surf_iommu_map() stores the result in an unsigned long, and apple_isp_iommu_map_sgt() compares the ssize_t against the u64 surface size. Either way a negative error becomes a huge value that passes the "mapped < size" check, so the failure is treated as success, and apple_isp_iommu_map_sgt() records the error code as the surface size that apple_isp_iommu_unmap_sgt() later unmaps. Treat a negative return as an error and propagate it. Should a short mapping ever be returned, unmap it before failing. Compile-tested only; not run on hardware. Fixes: 329bf83 ("media: apple: Add Apple ISP driver") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
In boot stage 2 the firmware reports through GPIO 1 where in the IPC surface the host should place the boot arguments. The driver adds that offset to the surface's IOVA and to its kernel mapping without any check, writes the 0x180-byte boot arguments there and places the command area, which every later command and buffer batch uses, right behind them. A bad offset makes the host write outside the IPC surface's vmap. Before writing anything, check that the boot arguments and the start of the command area lie inside the IPC surface, and fail the boot otherwise. The command area must hold at least the 0x280 bytes the firmware reads for a buffer batch, which is more than any command needs. Compile-tested only; not run on hardware. Fixes: 5eca30d ("media: apple: isp: Remove ioread/iowrite and stop doing raw address translation") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
After the second handshake the firmware publishes a table of channel descriptors in the IPC surface, and isp_fill_channel_info() trusts it: - desc.num * ISP_IPC_MESSAGE_SIZE is computed in 32 bits, so a large message count wraps to a small ring size that passes the bounds check in apple_isp_ipc_translate(), and boot stage 3 then writes desc.num 64-byte messages past the IPC surface's vmap; - desc.num == 0 makes chan_update_cursor() compare the cursor against num - 1 == UINT_MAX, so the cursor walks out of the ring; - 1 << desc.src is undefined for a source of 32 or more; - kstrdup() reads the 64-byte name field up to a NUL the firmware does not have to provide, and a failed allocation leaves a NULL name that isp_get_chan_index() hands to strcasecmp(); - the channel count read from GPIO 0 in stage 2 is stored in an int and only checked against zero. Accept at most 32 channels, one per doorbell bit, compute the ring size in 64 bits, require at least one message slot and a source below 32, copy at most the 64 bytes of the name field and check that allocation. Check the channel type before translating the ring, return -EIO instead of -ENOMEM for a malformed table, and make isp_free_channel_info() cope with a failed allocation of the channel array. Compile-tested only; not run on hardware. Fixes: 329bf83 ("media: apple: Add Apple ISP driver") Fixes: 5eca30d ("media: apple: isp: Remove ioread/iowrite and stop doing raw address translation") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The firmware chooses the size of two kinds of host allocations: the extra heap it asks for through GPIO 3 in boot stage 2, and the surfaces it requests on the SHAREDMALLOC channel. __isp_alloc_surface() accepts any u64 for them. A zero size produces an empty surface, and a size whose page count does not fit the u32 page counter truncates it, after which the page array and the scatterlist built from it no longer describe the size that is reserved and mapped. Reject a zero size and any size larger than the ISP's IOVA range, which no allocation could satisfy anyway; this also keeps the page count within 32 bits. The limit applies to the driver's own allocations as well, all of which are far smaller. Compile-tested only; not run on hardware. Fixes: 329bf83 ("media: apple: Add Apple ISP driver") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
ipc_bt_handle() parses the list of returned buffers that the firmware sends on the BUF_T2H channel. It does not check whether apple_isp_translate() found the list, so an address outside the buffer surface, or a buffer surface that was never identified, leads to a NULL dereference. Its bound on the number of entries subtracts the size of struct isp_buffer, the host's vb2 buffer wrapper, instead of the 16-byte list header; for lists shorter than that wrapper the subtraction wraps and every count passes, and the loop reads descriptors past the list and past the surface. The 64-bit count is also truncated to 32 bits before the check. Check the length against the buffer surface and the translation result against NULL, derive the bound from the list header, and keep the count in 64 bits. Compile-tested only; not run on hardware. Fixes: 903629a ("media: apple: isp: Rework meta surface handling & buffer return") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
isp_submit_buffers() builds each BUF_H2T batch in the command area behind the boot arguments: a 16-byte header, then one 64-byte descriptor for every metadata surface the firmware does not hold and one for every pending capture buffer. Nothing limits the number of pending buffers here, since vb2 can hold more than the 16 buffers the driver asks for through VIDIOC_CREATE_BUFS, and nothing checks that the batch fits in the IPC surface, so a long pending list is written past its end. Metadata descriptors are also only partly written, so their unused planes, flags and tag keep whatever an earlier command or batch left in the command area. Define the command area as the largest batch the driver builds, all metadata surfaces plus one rendered pool of ISP_MAX_BUFFERS, and make boot stage 2 require that much room in the IPC surface. Put at most ISP_MAX_BUFFERS capture buffers into a batch and leave the rest pending for the next one, and clear the batch before filling it. Compile-tested only; not run on hardware. Fixes: 903629a ("media: apple: isp: Rework meta surface handling & buffer return") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
isp_ch_cache_sensor_info() allocates the CH_INFO_GET reply buffer and frees it on the common exit path, but returns -ENODEV directly when the sensor is unknown or not supported, leaking the buffer. Take the common exit path. Compile-tested only; not run on hardware. Fixes: 329bf83 ("media: apple: Add Apple ISP driver") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
apple_isp_video_suspend() hands every buffer the driver holds back to vb2 with VB2_BUF_STATE_QUEUED before stopping the stream. Outside of start_streaming that state requeues nothing: vb2 marks the buffers as queued but never passes them to the driver again, so the stream that apple_isp_video_resume() restarts has no capture buffers, no frame is ever completed and VIDIOC_DQBUF blocks forever. The resume path also ignores a failed restart, which leaves the queue in the same state, and a later VIDIOC_STREAMOFF then stops a stream that is not running: it sends CH_STOP to a firmware that was shut down, through the channel structures that were freed with it. Keep the buffers with the driver across sleep. Before stopping, move the buffers given to the firmware to the pending list, so that the buffer return for the stop does not complete them, and submit them again when the stream restarts on resume. If the restart fails, complete them with VB2_BUF_STATE_ERROR and flag the queue with vb2_queue_error(), so that userspace gets -EIO instead of waiting. Only stop the firmware stream from stop_streaming when it is running, and hold the video lock in the sleep callbacks as the vb2 callbacks do. Compile-tested only; not run on hardware. Fixes: a2a90c2 ("media: apple: isp: Support system sleep") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
Every probe prints the raw CONFIG_GET and CH_INFO_GET replies as hex dumps at KERN_INFO, the latter including the camera module's serial number, and then sends CH_CAMERA_CONFIG_GET for each preset the firmware reports, only to hex-dump the replies. The driver uses none of it; it is bring-up output. The probe also announces itself and prints the IOVAs of the IPC and data surfaces at info level. Remove the dumps and the preset queries, together with isp_cmd_ch_camera_config_get(), which has no other user. Log the sensor version at debug level and without the serial number, and demote the surface addresses to debug. On every SoC this removes one firmware command per preset from probe. Those commands only read state, so the firmware's configuration is not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The firmware sends its log output on the TERMINAL channel. The handler only decodes it when APPLE_ISP_DEBUG is defined in isp-drv.h at build time, and that define also turns every isp_dbg() message into an unconditional info message; without it the text is dropped. Always decode the log text and print it with dev_dbg(), so that it can be enabled at runtime through dynamic debug, and remove APPLE_ISP_DEBUG. Print the text directly from the log surface instead of copying it to the stack first, and cut lines at 512 bytes rather than dropping them. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The per-sensor setfile carries the camera module's calibration and is optional: without it the driver streams uncalibrated. Yet every stream start without the file logs three messages: the firmware loader's warning, "failed to request setfile" and "calibration data not loaded". Request the file with firmware_request_nowarn() and warn once, naming the file. A setfile that is present but too short or has the wrong magic is still an error each time, and now says which file and magic it found. Read the magic with get_unaligned_be32() rather than through a cast, and refuse a table entry larger than the data surface instead of copying past it. Document the file name and search path in the Kconfig help, which the driver did not have. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The coprocessor reset and the four firmware handshakes poll their registers with mdelay(1), up to 1000 times each, so a firmware that does not answer keeps a CPU spinning for a second per wait. That happens on every failed boot, and a boot that fails during probe is retried through deferred probing. All of these waits run in process context. Use readl_poll_timeout(), which sleeps between reads, with the same 1 ms interval and one second limit. The two short read loops on the reset acknowledge registers do not delay and stay as they are. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
Firmware messages arrive continuously while the camera streams. A malformed one makes apple_isp_translate(), a channel handler, the buffer return parser or the surface allocator print an error, and a firmware that keeps sending such messages floods the log at the frame rate. Use the rate-limited variants for these messages, and drop the stray parenthesis from the handler failure message. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The bootloader describes the ISP firmware with the apple,firmware-version and apple,firmware-compat properties. When it provides neither, probe prints "could not parse" with the -EINVAL of the property lookup for each of them, followed by an info line with two unknown versions. Stay quiet about an absent property in isp_read_fw_version(), which still warns about values it cannot parse or does not know, and warn once from isp_check_firmware_version() when the compatibility version, the one the driver uses to pick its command layouts, is missing. The firmware version itself is only informative and is not reported. Demote the summary line to debug level. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The sensor presets come from the device tree, and the driver passes their apple,config-index to CH_CAMERA_CONFIG_SELECT unchecked. CH_INFO_GET reports how many presets the firmware has for the sensor, numbered from zero, so an index at or beyond that count names a preset the firmware does not have, and selecting it can only fail when a stream starts. Ignore such presets at probe, with a warning, and fail the probe if none is left. A firmware that reports no presets at all is not checked, as before. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
isp_firmware_shutdown() asks the firmware to suspend, then frees the channel state and the extra heap, and only then stops the coprocessor and powers its domains down in stage 1. It ignores the result of the suspend request, so a firmware that did not acknowledge it keeps running while memory it uses is released. The pages are unmapped from the DART before they are freed, so late accesses fault instead of reaching freed memory, but they need not happen at all. Stop the coprocessor and power its domains down right after releasing the interrupt, before any memory is freed, and warn when this happens without the firmware having acknowledged the suspend request. The DART stays powered through the ISP's own runtime PM reference until the surfaces are unmapped. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
On T8140 the ISP DARTs translate 36-bit addresses, and the firmware reports the addresses it hands to the host with its vm-base, bit 40, set: the channel table and ring addresses after boot, the addresses in command acknowledgements, log messages and buffer return lists. The DART ignores the upper bits, and the host allocates its surfaces at the low addresses, so these values have to be masked before the driver compares them or translates them to its own mappings. Add a per-SoC mask of the address bits the DART translates, apply it wherever the driver takes an address from the firmware, and leave the addresses unmasked on SoCs that do not set it, which are all of them so far. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
On the ISP17a in T8140 the doorbell and acknowledge registers are not a window of their own: they sit at offset 0x410 of the interrupt block that the binding describes as "mbox", which is why the T8140 binding has no "mbox2" entry. The interrupt block also has two more enable words, at 0x18 and 0x38, and an interrupt routing word at 0x73c, which are set together with the enable word at 0x8. The coprocessor control register moved from 0x1400044 to 0x1600044. Add match data for these differences: the offset of the doorbell block inside the "mbox" window, checked against the window's size; a flag for the additional interrupt words, which are set to the values observed while the firmware runs on this SoC and cleared with the enable word; and the offset of the control register. SoCs that set none of them behave as before. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The T8140 firmware accesses registers of other blocks through its DART at their physical addresses: the DSID broadcast-clear windows of the memory fabric, the PMGR scratch registers the driver names in PMP_CTRL_SET, some ISP power-state registers in the PMGR, and a few more. They are the ranges the bootloader programs into the DART's address filter for the ISP, rounded out to the 16 KiB DART page size. Add a per-SoC table of such windows to the match data and map them 1:1 into the ISP's IOMMU domain along with the rest of its address space, unmapping them on teardown. They are mapped cacheable: with the DART's no-cache attribute the ISP took an SError on its first write to the PMP scratch register when a stream started. A window that overlaps the range the driver allocates its surfaces from is refused. The windows are SoC constants, like the PMU, DSID and PMP scratch addresses the driver already keeps in its match data and passes to the firmware, so they are not described in the device tree; the T8140 ISP binding covers only the ISP's own registers. Mapping whole pages exposes more than the firmware needs: each window gives the ISP DMA access to every register in its pages, and a window can be much wider than the registers the firmware is known to use. The DART cannot restrict it further. The mappings are also not reserved in the DMA API's IOVA allocator for the device; the driver does not use that allocator for them, and on T8140 it hands out addresses downwards from the 32 GiB end of the ISP's DART aperture, far above the windows. SoCs without a table are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
T8140 has an ISP17a coprocessor and runs the H17 generation of the ISP firmware. Both boot differently from the existing SoCs: - The reset request in EDPRCR is followed by all-ones writes to four fabric words at 0x748, 0x848, 0x948 and 0xa50, the last of which breaks the stride of the others in the observed sequence, and to four interrupt mask words from 0x1600a00 to 0x1600a0c. Then come eight alternating reads of the reset acknowledge words at 0x1600818 and 0x160081c, with a 50 ms wait after the reset request clears and another after the reads. This is the sequence observed when the firmware boots on this SoC. Only the reset request bit is known to signal completion, so it is the only one polled; the acknowledge words change between reads, but no condition on them is known, and the coprocessor status is not polled for WFI. Which of the steps are required has not been established. - There is no clock enable word at GPIO offset 0x20. - GPIO 6 is a boot mode field, and the boot the driver performs uses mode 1. - At the first handshake the firmware sets bit 1 of GPIO 2 to request a 0x290-byte boot descriptor instead of the 0x180-byte boot arguments. The IPC queue size at 0x50 is 64 bits wide and holds the boot argument offset plus one, the word at 0x68 is 0x40, the shared span is 0xee000000 bytes from the heap top, and of the 0x200-byte connection descriptor at 0x70 only the flag at its offset 0xb0, which says that there is no optical device card, is set. These are the values the firmware boots with; how they derive from the rest of the setup is not known. Select the reset sequence by the ISP generation and the boot descriptor by a firmware interface field in the match data, which also takes the boot mode. When the H17 interface is selected, refuse to boot firmware that does not request the H16 descriptor rather than give it a layout it did not ask for, and do not warn about a missing apple,firmware-compat property, which that interface does not use. The existing boot arguments move to a helper, unchanged. Existing SoCs are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The H17 firmware on T8140 differs from the older firmware in three commands the driver sends while booting it and detecting the sensor: - After PRINT_ENABLE it takes no SET_ISP_PMU_BASE, and it takes its single DSID broadcast-clear window through SET_DSID_CLR_MULTI_BC_REG_BASE (0x3206), a count followed by the window, instead of SET_DSID_CLR_REG_BASE. - CH_INFO_GET exchanges 0x190 bytes. The first 0x118 match the older reply; in them the word at 0x68 is the size of the per-frame metadata record. - CH_SET_FILE_LOAD uses the 64-bit layout and returns the 0x18-byte record. Send these forms when the match data selects the H17 interface. Refuse a firmware whose metadata size differs from the one the driver allocates its metadata buffers for, since it would write past them; the older firmware reports a different value in that word, so it is only checked for H17. What the SET_FILE_LOAD reply contains is not known, and it is not checked. The PMU base and DSID setup move to a helper, unchanged for the older firmware. Existing SoCs are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The H17 firmware on T8140 expects a different channel configuration from the older firmware: - The frame rate limits and all buffer pools are configured before the preview stream is enabled, and the rendered pool configuration carries the plane sizes and strides of the output buffers, in the places of the metadata sizes and of the first two reserved words, with two data blocks. - CH_LOCAL_RAW_BUFFER_ENABLE is required: the sensor data takes the ISP-local raw path, and without the local buffers the firmware waits for a raw pool from the host. - APPLE_CH_AE_FD_SCENE_METERING_CONFIG_SET with the constants the older firmware takes makes this firmware fault, so it is not sent. - The configuration ends with CH_MASTER_SLAVE_SYNC_MODE_SET(0). - The IMX558 module needs the setfile with header version 0x21, isp_1925_03XX.dat; the firmware faults while parsing the lens shading data of the version 0x20 files the other SoCs use. The file holds 0xcba6 bytes, and the firmware is given 0xcbc0, the length rounded up to 64 bytes, with the tail cleared. Add the local raw buffer, master/slave sync and rendered pool commands, the latter with its own structure rather than reusing the metadata fields, and follow the H17 order when the match data selects that interface. The order for the older firmware does not change: the frame rate and pool steps move into helpers that both orders share. The setfile table gains an optional length of the file's contents; the other setfiles still have to be present in full. Existing SoCs are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
Besides the per-frame metadata buffers, the H17 firmware on T8140 uses a pool of capture metadata buffers. CH_INFO_GET reports their size, 0x29fc0 bytes, and the pool is configured as CISP_POOL_TYPE_META_CAPTURE with that size rather than the metadata size the older firmware takes there. The firmware is given the metadata buffers before CH_START and the capture metadata and capture buffers right after it, the order it was run with when streaming worked. When the match data gives a capture metadata size: - configure the capture metadata pool with it, and refuse a firmware that reports a different size, as for the metadata size; - allocate eight capture metadata buffers, as many as the firmware was run with, without a kernel mapping, since only the firmware accesses them; - send the metadata buffers in a batch of their own before CH_START and the capture metadata and capture buffers after it, and count the capture metadata buffers in the largest batch, which boot stage 2 requires the command area to hold; SoCs without the pool keep the requirement they had; - recognise returned capture metadata buffers. In the buffer lists the driver tags these buffers with pool type 2 and recognises returned ones by that tag, as the code the firmware was first brought up with did, although the pool is configured as type 8. Why the two differ is not known. Existing SoCs are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
On T8140 the ISP firmware gates the image on a watchdog outside the ISP, the window the binding names "wdt". While that watchdog is not serviced, the firmware keeps running but replaces every frame with a flat fill. Servicing it means writing 0 to its clear register at 0xc, 0x244140 to its reload register at 0x8 and 1 to its kick register at 0x0, every 33 ms, from before CH_START until the channel is stopped and its buffers are returned: the sequence and rate observed on macOS. macOS services this watchdog only while its camera-in-use indicator is shown, which makes it a privacy interlock: frames carry an image only while the user can see that the camera is on. That indicator is drawn by the display pipeline for secure firmware that Linux does not run, and no indicator the driver could drive instead is known, so the driver cannot tie the watchdog to one. It services the watchdog whenever it captures; the stream, as seen by userspace, is then the only sign that the camera is on. Map the "wdt" window when the device tree provides one and service it from an hrtimer while capturing. writel() already orders the three writes, so no barrier follows them. The timer does not need the hard interrupt mode: a late kick can only mask frames. Other SoCs have no "wdt" window and are not affected. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The T8140 firmware is loaded by the bootloader and cannot be started a second time: once it has been stopped with CISP_CMD_SUSPEND, the coprocessor reset and its power domains cycled, it never completes the first handshake of another boot. The driver boots and stops the firmware for every stream and for the camera detection at probe, so on T8140 only the detection would ever work. Add a match data flag for such resident firmware, and track the firmware state explicitly as off, running or dead: - Resident firmware is booted once, for the detection at probe, and keeps running between streams. Every stream configures the channel again, including its buffer pools, so metadata buffers still marked as submitted are reset, under the buffer lock, when a stream starts. - Resident firmware that has been stopped, or that failed to boot, is dead. Starting a stream then fails at once with -EIO instead of running the reset and waiting for a handshake that cannot come, and a stream that was running at system sleep fails its restart, which flags the vb2 queue. - A failed boot at probe returns its error instead of -EPROBE_DEFER, because a deferred retry would fail the same way. - Unbind stops the firmware after the video device is unregistered and before the metadata surfaces are freed, and a probe failure after the boot stops it as well. For system sleep the firmware is stopped cleanly before the system sleeps, not kept alive. Keeping it alive would need the ISP power domains to stay on, which genpd only does for a device on an awake path whose domain allows it, and would need the ISP DARTs to keep their state, while the DART driver resets unlocked DARTs on resume. Neither has been tried with the firmware running, and firmware that loses power without being told may have DMA in flight. Stopping it first keeps the ISP quiet while its DARTs and domains go down; the price is that the camera is unavailable after the first system sleep until the next boot, which the driver reports. While the driver is bound, resident firmware holds the runtime PM reference, and with it the ISP power domains, because it has to keep running. SHAREDMALLOC surfaces the firmware releases are still only reclaimed when it stops, which for resident firmware means at unbind. Existing SoCs still boot their firmware for each stream. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
Add the match data for the ISP of the A18 Pro (T8140), which runs the camera of the MacBook Neo (J700), and match the apple,t8140-isp compatible: - an ISP17a coprocessor with resident H17 firmware, which takes the 0x290-byte boot descriptor with boot mode 1 and gates its frames on the capture watchdog that the device tree describes as "wdt"; - no PMU base, one DSID broadcast-clear window of 0x2fc bytes at 0x220114000, and the PMP clock and bandwidth scratch registers at 0x3003d0ca0 and 0x302824000, both 8 bytes wide; - metadata records of 0x4d00 bytes and capture metadata records of 0x29fc0 bytes, the sizes CH_INFO_GET reports; - the doorbell block at offset 0x410 of the "mbox" window, the interrupt enable word at 0x8 together with the additional enable and routing words, and the coprocessor control register at 0x1600044; - 36-bit DART addresses, which the firmware reports with its vm-base, bit 40, set; - twelve MMIO windows the firmware accesses at their physical addresses. These are the values the firmware was booted and streamed with on J700. The windows are the bootloader's DART address filter ranges for the ISP rounded out to 16 KiB pages, and several of them are much wider than the registers the firmware is known to use: the 160 KiB window at 0x3003c0000 contains the PMP clock scratch word among other PMGR registers, and the page at 0x300704000 holds the ISP power-state registers and the rest of that 16 KiB of the PMGR. The ISP can write every register in these pages. Compile-tested only; not run on hardware. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
force-pushed
the
series/neo-isp-20260924
branch
from
September 25, 2026 16:08
fb22821 to
cc9846c
Compare
RyanTheTide
marked this pull request as ready for review
September 25, 2026 16:09
cb2206
pushed a commit
to cb2206/linux
that referenced
this pull request
Oct 5, 2026
…rse-damage Preserve sparse external-display damage across retained buffers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
media: apple: isp: T8140 (J700) camera support, and fixes for the ISP driver
This replaces the single commit fb22821 ("media: apple: isp: support
T8140 resident-firmware capture") with a 28-patch series on top of the merged
aurora-wip(the reworked#10, #21, #22 and #23). It addresses the audit of #12: the
generic fixes are separated out with
Fixes:tags, the cleanups stand ontheir own, and the T8140 enablement is split into patches that do nothing on
the existing SoCs until the last one adds the match data.
Everything is compile-tested only. Nothing in this series has been run on
hardware, neither on J700 nor on an earlier SoC.
Series
Fixes for bugs that affect every SoC (each with
Fixes:):pd_dev[-1])iommu_map_sgtable()for errorsnum == 0,src >= 32, unterminated name)resume, a failed restart hung DQBUF, STREAMOFF then used freed channels)
Cleanups (behaviour changes on every SoC):
T8140 (no-ops elsewhere until patch 28):
Changes since fb22821
audit found gaps (channel table, surface sizes, buffer batches) and each fix
names the commit that introduced the bug.
VB2_DMABUF(the import path usedsg_phys()on the importer'stable) and
MEDIA_ENT_FL_DEFAULT; both are follow-ups.firmware makes STREAMON fail at once with -EIO instead of resetting the ISP
and waiting a second for a handshake that cannot come; a failed boot of
resident firmware at probe returns its error instead of deferring; a stream
that cannot be restarted after resume flags the vb2 queue.
(the camera is then unavailable until the next boot, and the driver says so)
instead of being kept alive; keeping it alive depends on genpd and DART
behaviour that has not been tried. Reasoning in patch 27.
stops the coprocessor before any memory is released even if the firmware
ignores the suspend request.
metadata and capture metadata sizes, and the sensor presets, are checked
against what the firmware reports.
dsb(sy)removed; the watchdog runs from an hrtimer in the default (nothard-interrupt) mode. Its comment and commit message explain that macOS
services it only while the camera indicator is shown, and that no
indicator Linux could drive is known.
the order for the existing SoCs is unchanged.
gen == ISP_GEN_T8140checks are replaced by named match data(
fw_abi,resident_fw,capture_meta_size,mbox2_offset,coproc_control,mbox_irq_route,boot_mode,fw_iova_mask,fw_mmio)and the optional "wdt" window from the device tree.
readl_poll_timeout(); the probe prints no hex dumpsor serial numbers and warns at most once about firmware versions.
[email protected]; messages describe the hardware and firmware
behaviour.
Checks run
For every commit of the series:
make W=1 C=1with sparse on all seven apple-isp objects(arm64, LLVM=1, J700 config with
VIDEO_APPLE_ISP=y): no diagnostics indrivers/media/platform/apple/isp at any commit.
scripts/checkpatch.pl --strict --codespell: 0 errors; the only warningsare the known trailer notes (
Assisted-byformat,Co-authored-by) and"Unknown commit id" for the
Fixes:commits, which are in aurora-wip butnot in the shallow review clone. codespell was not installed, so only
checkpatch's own spelling list was used.
arm64-only primitives (the
dsb()is gone).Not tested
every preset, streaming without the setfile, unbind/bind (bind is expected
to fail once, quickly), suspend/resume idle and while streaming,
v4l2-compliance -s.least one earlier SoC (t8103/t8112/t600x/t602x): probe, stream cycles,
suspend/resume while streaming, unbind/bind,
v4l2-compliance -s.🤖 Generated with Claude Code