From 79a68a08e9cde853e912aa4eaea3d27e7372823c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 28 Nov 2026 11:05:35 -0600 Subject: [PATCH] camerad: an ISP IOMMU handle of 0 is valid (#39376) --- openpilot/system/camerad/cameras/spectra.cc | 15 +++++++-------- openpilot/system/camerad/cameras/spectra.h | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/openpilot/system/camerad/cameras/spectra.cc b/openpilot/system/camerad/cameras/spectra.cc index a89a6be70f..a831c1dbad 100644 --- a/openpilot/system/camerad/cameras/spectra.cc +++ b/openpilot/system/camerad/cameras/spectra.cc @@ -97,13 +97,12 @@ void *alloc_w_mmu_hdl(int video0_fd, int len, uint32_t *handle, int align, int f mem_mgr_alloc_cmd.align = align; mem_mgr_alloc_cmd.flags = flags; mem_mgr_alloc_cmd.num_hdl = 0; - if (mmu_hdl != 0) { - mem_mgr_alloc_cmd.mmu_hdls[0] = mmu_hdl; - mem_mgr_alloc_cmd.num_hdl++; - } - if (mmu_hdl2 != 0) { - mem_mgr_alloc_cmd.mmu_hdls[1] = mmu_hdl2; - mem_mgr_alloc_cmd.num_hdl++; + // -1 is the only invalid IOMMU handle: the kernel makes them (context bank index << 16) | 16 random bits, and the + // ISP's bank is index 0, so its handle is 0 on 1 boot in 65536 + for (int hdl : {mmu_hdl, mmu_hdl2}) { + if (hdl != -1) { + mem_mgr_alloc_cmd.mmu_hdls[mem_mgr_alloc_cmd.num_hdl++] = hdl; + } } do_cam_control(video0_fd, CAM_REQ_MGR_ALLOC_BUF, &mem_mgr_alloc_cmd, sizeof(mem_mgr_alloc_cmd)); @@ -1221,7 +1220,7 @@ void SpectraCamera::configICP() { release(m->video0_fd, cfg_handle); // BPS has a lot of buffers to init - bps_cmd.init(m, 464, 0x20, true, m->icp_device_iommu, 0, ife_buf_depth); + bps_cmd.init(m, 464, 0x20, true, m->icp_device_iommu, -1, ife_buf_depth); // BPSIQSettings struct uint32_t settings_size = sizeof(bps_settings[0]) / sizeof(bps_settings[0][0]); diff --git a/openpilot/system/camerad/cameras/spectra.h b/openpilot/system/camerad/cameras/spectra.h index acb2000313..23d5c3b889 100644 --- a/openpilot/system/camerad/cameras/spectra.h +++ b/openpilot/system/camerad/cameras/spectra.h @@ -58,7 +58,7 @@ int device_config(int fd, int32_t session_handle, int32_t dev_handle, uint64_t p int device_control(int fd, int op_code, int session_handle, int dev_handle); int do_cam_control(int fd, int op_code, void *handle, int size); void *alloc_w_mmu_hdl(int video0_fd, int len, uint32_t *handle, int align = 8, int flags = CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, - int mmu_hdl = 0, int mmu_hdl2 = 0); + int mmu_hdl = -1, int mmu_hdl2 = -1); void release(int video0_fd, uint32_t handle); class MemoryManager { @@ -106,7 +106,7 @@ public: } } - void init(SpectraMaster *m, int s, int a, bool shared_access, int mmu_hdl = 0, int mmu_hdl2 = 0, int count = 1) { + void init(SpectraMaster *m, int s, int a, bool shared_access, int mmu_hdl = -1, int mmu_hdl2 = -1, int count = 1) { video_fd = m->video0_fd; size = s; alignment = a;