Skip to content

media: apple: isp: read per-module lens shading data from sensor NVM - #3929

Merged
DjDeveloperr merged 1 commit into
mainfrom
camera-all-v2/lsc-nvm
Dec 2, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
camera-all-v2/lsc-nvm

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Each camera module carries its own lens shading measurement in the sensor NVM, and the ISP firmware hands it out on request. Read and cache it during sensor detection, for the follow-up that uses it:

  • isp_cmd_send_data() sends a command whose reply is larger than the IPC command area through isp->data_surf; the shared send path moves from isp_cmd_send_chan() into isp_cmd_send_buf().
  • CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET (0x0507) and ..._GRID_GET (0x0511) for the legacy (0x10/0xb0-byte header, 8-bit samples) and H17 (0x14/0x114-byte header, 8..16-bit samples) ABIs; the grid is validated and cached. A module without the data is not an error; an IPC transport failure is.
  • tools/asahi/isp-tests.py: extract isp_cmd_send_buf() too and aim the overwrite control at the lowest sender, which now holds the latch (fixes the 5 host-test jobs that failed on media: apple: isp: query per-module lens shading calibration from sensor NVM #3901).

Where the reply layouts come from
Our own Linux dumps of the raw 0x0507/0x0511 replies (debug print added locally on top of this code, zero-reboot module swap, stock module restored after):

  • H17, J713 (M4 Air): INFO 0x14 bytes: grid width +0xc, height +0xd, data size +0xe (1292 = 19x17x4), bit depth +0x10. GRID: valid +0xc, binary32 knot positions in [0,1] from +0x10, y positions from +0x7c (so 27 x slots), samples from +0x114 (so 38 y slots), four planes one after another.
  • Legacy, J615 (M3 Air): INFO 0x10 bytes, same first fields, no bit-depth byte (900 = 15x15x4). GRID: x from +0x10, y from +0x6c (23 x slots), samples from +0xb0 (17 y slots).
  • The size limits follow from the slot counts: 1564 = 23x17x4 (8-bit), 0x2010 = 27x38x4x2 (16-bit). 16-bit samples have not been seen on our Macs yet.
  • The command IDs are the existing ones in isp-cmd.h.

Nothing reads the grid yet, so image output does not change.

Replaces #3901, without the ideal-percentage command.

Tested: K114s T6050 (7.3.0-k114sstack9) at 26def99 pass: per-module LSC 19x17 (8-bit) read, setfile unchanged, 40/40 1920x1080 NV12 frames, 0 firmware errors, stock module restored. ARM64 KUnit apple-isp* 60/60 pass at this head and 62/62 on the combined tree (CONFIG_WERROR=y); W=1 build adds no warnings over main; ISP host tests: session/buffers/receive/returns/queue pass, send/overwrite/stop/reset controls fail as they must; checkpatch --strict clean.
Risk: two-way · every Mac with an Apple ISP camera: two extra firmware queries at sensor detection, no image change.

Legacy ABI: J615 (7.3.0-aurora-edge) ran this code (with #3928/#3930 and the local debug print on top) with 0 errors: per-module LSC 15x15 (8-bit), 10/10 frames, stock module restored. Not a byte-exact head row; the same two queries also ran with 0 errors on J413, J615, J713, J616s, Neo and K114s at the replaced PR's heads.

Each camera module carries its own lens shading measurement in the
sensor NVM, and the ISP firmware hands it out on request. Read and cache
it during sensor detection so a later change can use it:

- Add isp_cmd_send_data() for commands whose reply is larger than the
  IPC command area; it sends through isp->data_surf. Factor the shared
  send path out of isp_cmd_send_chan() into isp_cmd_send_buf().
- Add CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET (0x0507) and
  CISP_CMD_CH_SENSOR_PERMODULE_LSC_GRID_GET (0x0511) for the legacy
  (0x10/0xb0-byte header, 8-bit samples) and H17 (0x14/0x114-byte
  header, 8..16-bit samples) firmware ABIs, and cache the validated grid.
  A module without the data is not an error; an IPC transport failure
  is.

Nothing consumes the grid yet, so image output does not change.

tools/asahi/isp-tests.py: extract isp_cmd_send_buf() too and aim the
overwrite control at the lowest sender, which now holds the latch.

Add KUnit wire-layout tests for both ABIs.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide requested review from a team and DjDeveloperr as code owners December 2, 2026 12:10
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Merge readiness at 26def99b: not ready yet

Check Detail
CI at head running running: apple-build, KUnit plan
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at 26def99b
Conflicts ok none
PR text ok Risk: two-way · every Mac with an Apple ISP camera: two extra firmware queries at sensor detection, no image change. Legacy ABI: J615 (7.3.0-aurora-edge) ran this code (with #3928/#3930 and the local debug print on top) with 0 errors: per-module LSC 15x15 (8-bit), 10/10 frames, stock module restored. Not a byte-exact head row; the same two queries also ran with 0 errors on J413, J615, J713, J616s, Neo and K114s at the replaced PR's heads.

Areas: area:gpu, area:media

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH, then merge at 26def99

Blockers:

  • CI at head 26def99b4e38 is still queued (apple-build, host-tests, KUnit plan, readiness). Ready to approve as soon as CI finishes green (especially verifying the updated tools/asahi/isp-tests.py host-tests).

Checked:

  • Full 514-line diff across isp-drv.h, isp-cmd.h, isp-cmd.c, isp-cam.c, isp-cam-test.c, tools/asahi/isp-tests.py, and tools/asahi/isp/session.c — no code blockers found.
  • isp_cmd_send_buf() cleanly factors out the shared command-channel send path with ipc_error latching intact, and isp_cmd_send_data() checks isp->ipc_error, !isp->data_surf, and both insize/outsize against isp->data_surf->size before copying the reply back into args.
  • Wire structs (cmd_ch_sensor_lsc_info_{legacy,h17} and cmd_ch_sensor_lsc_grid_{legacy,h17}) are __packed with exact static_assert sizes (0x10, 0x14, 0xb0, 0x114); isp_cmd_ch_sensor_lsc_info_get() validates num_x, num_y, bit_depth, and data_size bounds before isp_cmd_ch_sensor_lsc_grid_get() allocates hdr_size + lsc->data_size and copies coordinates/payload.
  • isp_ch_cache_permodule_lsc() clears prior lsc->valid/lsc->data before querying, treats absent module LSC as non-fatal while propagating READ_ONCE(isp->ipc_error) on IPC transport failure, and leaves image output unchanged.
  • tools/asahi/isp-tests.py extracts isp_cmd_send_buf and aims the overwrite negative control at the lowest sender, and isp_test_permodule_lsc_wire verifies both legacy and H17 wire layouts. Exact-head K114s (26def99b4e38) PASS row is in the PR body.
Evidence
  • Diff reviewed: aurora-silicon/linux#3929 @ 26def99b4e38ab371ad4efdbe240ec492c301c63 (7 files, +351/-10).
  • CI status checked: pr-text SUCCESS; apple-build, host-tests, KUnit plan, readiness QUEUED.
  • Exact-head hardware row in PR body: K114s T6050 at 26def99b4e38 PASS (per-module LSC 19x17 (8-bit) read, 40/40 frames, 0 firmware errors).

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Dec 2, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Local CI at 26def99b4e38 while the Actions apple-build and KUnit plan jobs are still queued:

  • arm64 KUnit apple-isp* (clang 22, CONFIG_WERROR=y, qemu): 60/60 pass, including the new isp_test_permodule_lsc_wire.
  • W=1 build of drivers/media/platform/apple/isp against the fleet94 tree: 0 new warnings vs main 0bc45c54.
  • host-tests: green on Actions (the updated isp-tests.py extraction included).

Reply layouts: the PR body now says where each field comes from (raw reply dumps on J713 for H17 and J615 for legacy).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J615 (M3 Air), 27.2.0 ISP on saved aurora-edge-933f8226: built the ISP module with the exact driver delta from 26def99b4e38ab371ad4efdbe240ec492c301c63 on the running edge kernel's build tree. The four touched runtime source files matched the PR parent before the patch. GStreamer reached EOS for 12 requested 1920×1080 NV12 buffers, and the driver reported per-module LSC 15x15 (8-bit) on the legacy reply layout. Restored the stock module on the same boot, SELinux Enforcing, zero failed units. This verifies the grid query and stream; image application belongs to the separate shading change.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J713 (M4 Air) hardware row for 26def99b4e38ab371ad4efdbe240ec492c301c63, building the ISP module from the PR head against saved fleet94. The live ISP reported 27.2.0. During a 12-buffer 1920×1080 NV12 GStreamer stream, the driver read a 19×17 8-bit per-module grid on the H17 layout and acknowledged shared setfile upload. The stock module was restored on the same boot with SELinux Enforcing and zero failed units. No frames were retained.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 26def99 (once queued Actions apple-build and KUnit finish green)

Full diff audited earlier with no code blockers; Actions host-tests (including the updated tools/asahi/isp-tests.py extraction) is green, local arm64 KUnit (60/60) and W=1 build receipts are posted, and exact-head hardware rows now cover both reply layouts (K114s and J713 H17 19x17 8-bit, plus J615 legacy 15x15 8-bit). Clearing the review gate now so merge can proceed as soon as the queued Actions build/KUnit jobs complete.

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Local PC qualification for 26def99b4e38 merged with main ba787ac215ad (tree cfb052979d97).

Ran ~/bin/aurora-build ./linux-build/build kernel --profile asahi linux-pc-edge-pr3943-5b22d796 -- -j8 W=1 drivers/media/platform/apple/isp/ on main and on the candidate, with CONFIG_VIDEO_APPLE_ISP=m. Both built and linked apple-isp.o. The only compiler diagnostic was the same existing apple_isp_hw_t6040 unused-variable warning on both.

Hosted host-tests passed. The author reported 60/60 Arm64 ISP KUnit cases at this head. The K114s target result and the J615 legacy and J713 H17 results cover both grid layouts. KUnit result · J615 · J713

@DjDeveloperr
DjDeveloperr merged commit d5b9a41 into main Dec 2, 2026
11 of 13 checks passed
@DjDeveloperr
DjDeveloperr deleted the camera-all-v2/lsc-nvm branch December 2, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants