Skip to content

media: apple: isp: query per-module lens shading calibration from sensor NVM - #3901

Closed
RyanTheTide wants to merge 2 commits into
mainfrom
camera-all/per-module-lsc-nvm
Closed

RyanTheTide wants to merge 2 commits into
mainfrom
camera-all/per-module-lsc-nvm

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Replaced by #3929 (same work, cleaned up: Signed-off-by on every commit, host-test fix, values limited to what our own measurements support). Closing this one.

…sor NVM

Add IPC commands and caching for per-module lens shading calibration stored
in the camera module's NVM:

- Add isp_cmd_send_data() to send commands whose payload exceeds the IPC
  command area over isp->data_surf.
- Implement CISP_CMD_CH_SENSOR_PERMODULE_LSC_INFO_GET (0x0507) and
  CISP_CMD_CH_SENSOR_PERMODULE_LSC_GRID_GET (0x0511) for both legacy
  (0x10/0xb0 header, 8-bit grid) and H17 (0x14/0x114 header, 8..16-bit
  grid) firmware ABIs, caching the validated grid during sensor detection.
- Implement CISP_CMD_CH_LSC_IDEAL_PCT_SET (0x0a4e) and send the sensor's
  target corner illumination percentage before loading the setfile.

Add KUnit wire-layout tests covering both legacy and H17 ABI command sizes
and reply parsing.
@RyanTheTide
RyanTheTide requested review from a team as code owners December 2, 2026 08:44
@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (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 8b5758f3: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no review verdict FINISH at 8b5758f3
Hardware row at head ok in the PR body at 8b5758f3
Conflicts ok not computed yet
PR text ok Risk: two-way · Macs with Apple ISP front cameras (J413, J615, J713, J616s, J700, K114s)
Hold no labelled hold by a maintainer

Areas: area:media

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

Return READ_ONCE(isp->ipc_error) from isp_ch_cache_permodule_lsc() when a
query fails due to a poisoned IPC transport (e.g. timeout), while keeping
missing/unpopulated NVM responses non-fatal. Free any prior cached buffer
via devm_kfree() before re-querying.
@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 2, 2026

@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 8b5758f345c1

Blockers:

  1. CI still pending at 8b5758f345c1: apple-build, host-tests, and KUnit plan are still queued (pr-readiness: CI at head: running). Code and exact-head J713 hardware row look ready to approve as soon as CI finishes green.

Checked: Audited isp-drv.h, isp-cmd.h, isp-cmd.c, isp-cam.c, and isp-cam-test.c. isp_cmd_send_data() checks READ_ONCE(isp->ipc_error) and isp->data_surf->size bounds, and is only called during isp_ch_cache_sensor_info() (before isp_ch_load_setfile() uses data_surf). isp_cmd_ch_sensor_lsc_info_get() validates legacy (0x10) and H17 (0x14) wire layouts (num_x/num_y bounds, bit_depth in 8..16, data_size upper and lower bounds); isp_cmd_ch_sensor_lsc_grid_get() checks valid and duplicates into devm_kmemdup() while isp_ch_cache_permodule_lsc() frees any prior lsc->data via devm_kfree() and propagates READ_ONCE(isp->ipc_error) on transport poisoning. isp_cmd_ch_lsc_ideal_pct_set() sends via isp->cmd_virt without clobbering data_surf. Exact-head J713 M4 Air hardware row and ARM64 KUnit 54/54 PASS (isp_test_permodule_lsc_wire) are present at 8b5758f345c1.

Evidence
  • Checked isp_ch_cache_sensor_info() callers: only called once for isp->current_ch, matching the single isp->lsc slot.
  • Checked isp_cmd_ch_lsc_ideal_pct_set() placement in isp_ch_load_setfile(): uses CISP_SEND_IN on isp->cmd_virt, leaving isp->data_surf->virt intact, and any IPC error is caught immediately on the following isp_cmd_ch_set_file_load().
  • Pending checks on 8b5758f345c1: apple-build, host-tests, KUnit plan (queued).

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

Copy link
Copy Markdown
Contributor

Local CI run (hosted CI is still queued): host-tests fail at 8b5758f345c1 when it is merged with current main 105e3fbc6adc (merge tree 38921bf0bae6). The build, KUnit and checkpatch results are below.

What fails: tools/asahi/isp-tests.py --suite session and its four negative controls, 5 jobs in all. This PR moves the body of isp_cmd_send_chan() (including the ipc_error guard) into the new isp_cmd_send_buf(). The test still extracts only isp_cmd_send_chan and isp_cmd_send from isp-cmd.c (isp-tests.py lines 46-55). So the extracted session.c calls an undeclared isp_cmd_send_buf, and the overwrite control no longer finds the guard in isp_cmd_send_chan:

FAIL isp-tests --suite session (0.1s): exit 1
FAIL isp-tests --suite session --control send (0.1s): exit 1 without a control failure
FAIL isp-tests --suite session --control overwrite (0.0s): exit 1 without a control failure
FAIL isp-tests --suite session --control stop (0.1s): exit 1 without a control failure
FAIL isp-tests --suite session --control reset (0.1s): exit 1 without a control failure
out/session.c:453:9: error: call to undeclared function 'isp_cmd_send_buf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
RuntimeError: overwrite negative control no longer matches isp_cmd_send_chan

On the same main, these jobs pass: main alone, 31/31 in the --only isp subset; main + #3900, 31/31. The full suite on main + #3900 + #3902 (which carries this PR) gives 947/952, and its only failures are these 5. A likely fix: when isp_cmd_send_buf exists, also extract it, and apply the overwrite control to it.

Other checks on the same merge:

Check Command Result
apple-build (Apple media dir) arm64 defconfig + merge_config.sh -m asahi.config + olddefconfig, LLVM=1, Rust; make W=1 modules_prepare drivers/media/platform/apple/ pass. The one W=1 warning in isp/ is also on main (isp-drv.c:1343 unused apple_isp_hw_t6040), so nothing new
KUnit plan scripts/ci/apple-kunit.py maps drivers/media/platform/apple/isp/ to the isp suite isp
KUnit isp, arm64 build kunit.py build --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/media/platform/apple/isp builds, 0 warnings
KUnit isp, run the same suite on UML, because our build hosts don't use QEMU: kunit.py run --make_options LLVM=1 --kunitconfig=drivers/media/platform/apple/isp --kconfig_add CONFIG_WERROR=n 58/60. isp_test_permodule_lsc_wire passes. The 2 failures are isp_test_dapf_program and isp_test_dapf_program_t6050, which fail the same way on main under UML (57/59): UML drops MMIO writes to the test's kmalloc'd register bank. This PR doesn't touch those tests
host-tests (ISP subset) run-host-tests.py --jobs 8 --only isp in a container with the workflow's pins (Ubuntu 24.04, clang 18, gcc 13, rust 1.96.0, Python 3.14), --network=none 26/31, 5 failures above
checkpatch scripts/checkpatch.pl --strict on 18de246fd3e6 and 8b5758f345c1 0 warnings, 0 checks. 1 error on each commit: Missing Signed-off-by: line(s)

Also, this PR and #3900 conflict textually. In isp_ch_load_setfile() in isp-cam.c, both PRs change the declarations at the top of the function. In isp-cam-test.c, both add a test function and a KUNIT_CASE at the same spot. Keeping both sides builds, and the tests pass (see #3902). Whichever PR merges second needs a rebase.

@DjDeveloperr DjDeveloperr added the hold Held on purpose; skipped by the PR digest label Dec 2, 2026
@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 2, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Replaced by #3929 (same work, cleaned up: Signed-off-by on every commit, host-test fix, values limited to what our own measurements support). Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) hold Held on purpose; skipped by the PR digest needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants