Add AMD ISP4 driver
Subsystems (2)
Bin Du
maintainerv6 cover Add AMD ISP4 driver
Hello,
AMD ISP4 is the AMD image processing gen 4 which can be found in HP ZBook Ultra G1a 14 inch Mobile Workstation PC (Ryzen AI Max 300 Series)
(https://ubuntu.com/certified/202411-36043)
This patch series introduces the initial driver support for the AMD ISP4.
Patch summary:
- Powers up/off and initializes ISP HW
- Configures and kicks off ISP FW
- Interacts with APP using standard V4l2 interface by video node
- Controls ISP HW and interacts with ISP FW to do image processing
- Supports enum/set output image format and resolution
- Supports queueing buffer from app and dequeuing ISP filled buffer to App
- It is verified on qv4l2, cheese and qcam
- It is verified together with following patches
platform/x86: Add AMD ISP platform config (https://lore.kernel.org/all/[email protected]/) pinctrl: amd: isp411: Add amdisp GPIO pinctrl (https://github.com/torvalds/linux/commit/e97435ab09f3ad7b6a588dd7c4e45a96699bbb4a) drm/amd/amdgpu: Add GPIO resources required for amdisp (https://gitlab.freedesktop.org/agd5f/linux/-/commit/ad0f5966ed8297aa47b3184192b00b7379ae0758) drm/amd/amdgpu: Declare isp firmware binary file (https://gitlab.freedesktop.org/agd5f/linux/-/commit/35345917bc9f7c86152b270d9d93c220230b667f)
AMD ISP4 Key features:
- Processes bayer raw data from the connected sensor and output them to different YUV formats
- Downscale input image to different output image resolution
- Pipeline to do image processing on the input image including demosaic, denoise, 3A, etc.
----------
Changes v5 -> v6:
- Lowered FW mempool buffer size from 200M to 100M (actual usage).
- Added an irq_enabled member to the ISP subdev for proper IRQ disable handling in both normal and error cases.
- Removed unnecessary .owner assignment from isp4_capture_drv definition
- Updated IRQ handling to enable and disable interrupts via the ISP register for improved performance.
- Revised ring buffer management in isp4if_f2h_resp(), addressing safety checks to ensure the read pointer is validated before memcpy operations, reducing the risk of out-of-bounds access. The ring buffer logic was also streamlined significantly.
- Modified ring buffer handling in isp4if_is_cmdq_rb_full(), correcting an off-by-one error in safety checks that previously allowed rd_ptr to equal wr_ptr when the buffer was full.
- Refactored ring buffer handling in isp4if_insert_isp_fw_cmd(), simplifying overall logic.
- Resolved a regression from v4 to v5 where isp4if_dequeue_buffer() did not protect list_del with bufq_lock.
- Addressed a subtle use-after-free issue that could occur if a timeout on a synchronous command coincided with completion.
- Added missing pm_runtime_disable() calls to isp4_capture_remove() and to the error path in isp4_capture_probe().
- Removed stray semicolons following closing curly braces.
- Improved and clarified macro definitions in isp4_interface.h.
- Eliminated unnecessary (u8 *) casts.
- Added missing memset for firmware command structures in isp4sd_stop_stream().
- Excluded streams 2 and 3 from ISP4IF_FW_RESP_RB_IRQ_EN_MASK, preventing their activation in the interrupt enable register.
- Enhanced error handling to clean up kthreads in the event of startup failure.
- Corrected a race condition during kthread creation where waitqueue head initialization could be delayed, as it was performed by the kthread itself.
- Removed status checks in isp4sd_pwroff_and_deinit() that were always false.
- Ensured isp4sd_init_stream() is only invoked once per stream start and reordered corresponding status checks in isp4sd_start_stream().
- Improved error handling in isp4sd_start_stream() to propagate errors from failed functions.
- Relocated debugging messages in isp4sd_stop_stream() to execute under lock protection due to access to output_info->start_status.
- Eliminated redundant GET_REG_BASE() macros.
- Removed isp4sd_is_stream_running() function.
- Corrected error message in isp4sd_init_stream() caused by copy/paste.
- Refined struct isp4_interface to remove firmware ring buffer configurations.
- Removed obsolete isp4sd_is_stream_running function.
- Removed pdev member from struct isp4_device, as it is unnecessary.
- Fixed typo in 'isp_mmip' parameter name within isp4if_init().
- Removed gap in struct isp4_subdev definition.
- Performed extensive dead code removal and minor style improvements throughout the codebase.
Changes v4 -> v5:
- Transitioned VIDEOBUF2_V4L2 from 'depends' to 'select' within Kconfig.
- Standardized object file naming conventions in the Makefile and sorted entries alphabetically.
- Removed the unused macro definition to_isp4_device.
- Eliminated unused members mem_domain and mem_align from struct isp4if_gpu_mem_info.
- Deleted unused fields mc_addr and gpu_pkg from struct isp4if_cmd_element.
- Removed obsolete pltf_data, i2c_nb, and notifier elements from struct isp4_device.
- Updated platform_get_irq failure handling to return its actual result rather than -ENODEV.
- Refined inclusion of header files for clarity and efficiency.
- Appended comments following #endif statements in header files.
- Improved implementation of isp4if_gpu_mem_free and isp4if_dealloc_fw_gpumem.
- Removed isp4if_append_cmd_2_cmdq and revised isp4if_send_fw_cmd accordingly.
- Enhanced isp4if_clear_cmdq and isp4if_clear_bufq by eliminating unnecessary list_del operations.
- Adopted completion mechanism instead of wait queue and condition for command completion notifications.
- Employed memset to ensure proper zeroing of padding bits in structures shared between ISP driver and firmware.
- Streamlined IRQs, reducing total from four to two, retaining only essential ones.
- Optimized IRQ handler logic using a while loop for greater efficiency.
- Introduced dynamic IRQ enable/disable functionality based on camera status (open/close).
- Applied distinct identifiers to differentiate multiple threads and IRQs.
- Removed unnecessary initialization of local variables.
- Refined camera start/stop workflow to mitigate potential synchronization concerns.
- Replaced all remaining mutex with guard mutex.
- Enhanced command and buffer queue performance by substituting mutexes with spinlocks.
- Removed redundant isp4sd_init_meta_buf function and its references.
- Limited firmware logging activities to the stream1 thread.
- Relocated v4l2_device_unregister_subdev() and media_entity_cleanup() calls from isp4_capture_remove to isp4sd_deinit.
- Resolved media device registration sequence issues.
- Modified stream processing thread behavior to await IRQ without a timeout.
- Addressed cleanup procedures in video device initialization and deinitialization routines.
- Corrected typos and made other cosmetic improvements.
Changes v3 -> v4:
- Replace one mutex with guard mutex.
- Remove unnecessary bus_info initialization of v4l2_capability.
- Drop V4L2_CAP_IO_MC from capabilities of v4l2_capability.
- Modify document with better SOC description.
- Fix Test x86 failure in Media CI test https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/83470456/artifacts/report.htm
- Modify some commit messages by describing changes in imperative mood.
- Add media-ctl output in cover letter.
- Create separated dedicated amdgpu patch to add declaration MODULE_FIRMWARE("amdgpu/isp_4_1_1.bin");
- Fix typo errors and other cosmetic issues.
- Add DRM_AMD_ISP dependency in Kconfig.
Changes v2 -> v3:
- All the dependent patches in other modules (drm/amd/amdgpu, platform/x86, pinctrl/amd) merged on upstream mainline kernel (https://github.com/torvalds/linux) v6.17.
- Removed usage of amdgpu structs in ISP driver. Added helper functions in amdgpu accepting opaque params from ISP driver to allocate and release ISP GART buffers.
- Moved sensor and MIPI phy control entirely into ISP FW instead of the previous hybrid approach controlling sensor from both FW and x86 (sensor driver).
- Removed phy configuration and sensor binding as x86 (sensor driver) had relinquished the sensor control for ISP FW. With this approach the driver will be exposed as web camera like interface.
- New FW with built-in sensor driver is submitted on upstream linux-firmware repo (https://gitlab.com/kernel-firmware/linux-firmware/).
- Please note the new FW submitted is not directly compatible with OEM Kernel ISP4.0 (https://github.com/amd/Linux_ISP_Kernel/tree/4.0) and the previous ISP V2 patch series.
- If intend to use the new FW, please rebuild OEM ISP4.0 Kernel with CONFIG_VIDEO_OV05C10=N and CONFIG_PINCTRL_AMDISP=Y.
- Included critical fixes from Sultan Alsawaf branch (https://github.com/kerneltoast/kernel_x86_laptop.git) related to managing lifetime of isp buffers.
media: amd: isp4: Add missing refcount tracking to mmap memop
media: amd: isp4: Don't put or unmap the dmabuf when detaching
media: amd: isp4: Don't increment refcount when dmabuf export fails
media: amd: isp4: Fix possible use-after-free in isp4vid_vb2_put()
media: amd: isp4: Always export a new dmabuf from get_dmabuf memop
media: amd: isp4: Fix implicit dmabuf lifetime tracking
media: amd: isp4: Fix possible use-after-free when putting implicit dmabuf
media: amd: isp4: Simplify isp4vid_get_dmabuf() arguments
media: amd: isp4: Move up buf->vaddr check in isp4vid_get_dmabuf()
media: amd: isp4: Remove unused userptr memops
media: amd: isp4: Add missing cleanup on error in isp4vid_vb2_alloc()
media: amd: isp4: Release queued buffers on error in start_streaming
- Addressed all code related upstream comments
- Fix typo errors and other cosmetic issues.
Changes v1 -> v2:
- Fix media CI test errors and valid warnings
- Reduce patch number in the series from 9 to 8 by merging MAINTAINERS adding patch to the first patch
- In patch 5
- do modification to use remote endpoint instead of local endpoint
- use link frequency and port number as start phy parameter instead of extra added phy-id and phy-bit-rate property of endpoint
----------
It passes v4l2 compliance test, the test reports for:
(a) amd_isp_capture device /dev/video0
Compliance test for amd_isp_capture device /dev/video0:
-------------------------------------------------------
atg@atg-HP-PV:~/bin$ ./v4l2-compliance -d /dev/video0 v4l2-compliance 1.29.0-5348, 64 bits, 64-bit time_t v4l2-compliance SHA: 75e3f0e2c2cb 2025-03-17 18:12:17
Compliance test for amd_isp_capture device /dev/video0:
Driver Info:
Driver name : amd_isp_capture
Card type : amd_isp_capture
Bus info : platform:amd_isp_capture
Driver version : 6.14.0
Capabilities : 0xa4200001 Video Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x24200001
Video Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:
Driver name : amd_isp_capture
Model : amd_isp41_mdev
Serial :
Bus info : platform:amd_isp_capture
Media version : 6.14.0
Hardware revision: 0x00000000 (0)
Driver version : 6.14.0Interface Info:
ID : 0x03000005
Type : V4L Video
Entity Info:
ID : 0x00000003 (3)
Name : Preview
Function : V4L2 I/O
Pad 0x01000004 : 0: Sink
Link 0x02000007: from remote pad 0x1000002 of entity 'amd isp4' (Image Signal Processor): Data, Enabled, ImmutableRequired ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK
Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK
Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)
Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0
Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0
Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)
Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0
Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)
Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)
Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OK
Total for amd_isp_capture device /dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0
The media-ctl output of media device /dev/media0:
-------------------------------------------------------
atg@atg-HP-PV:~$ media-ctl -p -d /dev/media0 Media controller API version 6.17.0
Media device information
------------------------
driver amd_isp_capture
model amd_isp41_mdev
serial
bus info platform:amd_isp_capture hw revision 0x0 driver version 6.17.0
Device topology
- entity 1: amd isp4 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "Preview":0 [ENABLED,IMMUTABLE]
- entity 3: Preview (1 pad, 1 link)
type Node subtype V4L flags 0 device node name /dev/video0
pad0: Sink
<- "amd isp4":0 [ENABLED,IMMUTABLE]
Please review and provide feedback.
Many thanks,
Bin Du (7):
media: platform: amd: Introduce amd isp4 capture driver
media: platform: amd: low level support for isp4 firmware
media: platform: amd: Add isp4 fw and hw interface
media: platform: amd: isp4 subdev and firmware loading handling added
media: platform: amd: isp4 video node and buffers handling added
media: platform: amd: isp4 debug fs logging and more descriptive
errors
Documentation: add documentation of AMD isp 4 driver
Documentation/admin-guide/media/amdisp4-1.rst | 63 + Documentation/admin-guide/media/amdisp4.dot | 6 + .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 25 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 + drivers/media/platform/amd/isp4/Makefile | 10 + drivers/media/platform/amd/isp4/isp4.c | 234 ++++ drivers/media/platform/amd/isp4/isp4.h | 20 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++ drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++ .../media/platform/amd/isp4/isp4_interface.c | 787 +++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++ drivers/media/platform/amd/isp4/isp4_subdev.c | 1087 ++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 130 ++ drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 22 files changed, 4498 insertions(+) create mode 100644 Documentation/admin-guide/media/amdisp4-1.rst create mode 100644 Documentation/admin-guide/media/amdisp4.dot create mode 100644 drivers/media/platform/amd/Kconfig create mode 100644 drivers/media/platform/amd/Makefile create mode 100644 drivers/media/platform/amd/isp4/Kconfig create mode 100644 drivers/media/platform/amd/isp4/Makefile create mode 100644 drivers/media/platform/amd/isp4/isp4.c create mode 100644 drivers/media/platform/amd/isp4/isp4.h create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.c create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.h create mode 100644 drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h create mode 100644 drivers/media/platform/amd/isp4/isp4_hw_reg.h create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.c create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.h create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.c create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.h create mode 100644 drivers/media/platform/amd/isp4/isp4_video.c create mode 100644 drivers/media/platform/amd/isp4/isp4_video.h
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 1/7 media: platform: amd: Introduce amd isp4 capture driver
AMD isp4 capture is a v4l2 media device which implements media controller interface. It has one sub-device (AMD ISP4 sub-device) endpoint which can be connected to a remote CSI2 TX endpoint. It supports only one physical interface for now. Also add ISP4 driver related entry info into the MAINTAINERS file
--- MAINTAINERS | 13 +++ drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 +++ drivers/media/platform/amd/isp4/Makefile | 6 ++ drivers/media/platform/amd/isp4/isp4.c | 132 +++++++++++++++++++++++ drivers/media/platform/amd/isp4/isp4.h | 17 +++ 9 files changed, 190 insertions(+) create mode 100644 drivers/media/platform/amd/Kconfig create mode 100644 drivers/media/platform/amd/Makefile create mode 100644 drivers/media/platform/amd/isp4/Kconfig create mode 100644 drivers/media/platform/amd/isp4/Makefile create mode 100644 drivers/media/platform/amd/isp4/isp4.c create mode 100644 drivers/media/platform/amd/isp4/isp4.h
MAINTAINERS +13 -0
@@ -1133,6 +1133,19 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git F: drivers/iommu/amd/ F: include/linux/amd-iommu.h +AMD ISP4 DRIVER +M: Bin Du <[email protected]> +M: Nirujogi Pratap <[email protected]> +L: [email protected] +S: Maintained +T: git git://linuxtv.org/media.git +F: drivers/media/platform/amd/Kconfig +F: drivers/media/platform/amd/Makefile +F: drivers/media/platform/amd/isp4/Kconfig +F: drivers/media/platform/amd/isp4/Makefile +F: drivers/media/platform/amd/isp4/isp4.c +F: drivers/media/platform/amd/isp4/isp4.h + AMD KFD M: Felix Kuehling <[email protected]> L: [email protected]
drivers/media/platform/Kconfig +1 -0
@@ -63,6 +63,7 @@ config VIDEO_MUX # Platform drivers - Please keep it alphabetically sorted source "drivers/media/platform/allegro-dvt/Kconfig" +source "drivers/media/platform/amd/Kconfig" source "drivers/media/platform/amlogic/Kconfig" source "drivers/media/platform/amphion/Kconfig" source "drivers/media/platform/aspeed/Kconfig"
drivers/media/platform/Makefile +1 -0
@@ -6,6 +6,7 @@ # Place here, alphabetically sorted by directory # (e. g. LC_ALL=C sort Makefile) obj-y += allegro-dvt/ +obj-y += amd/ obj-y += amlogic/ obj-y += amphion/ obj-y += aspeed/
drivers/media/platform/amd/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +source "drivers/media/platform/amd/isp4/Kconfig"
drivers/media/platform/amd/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += isp4/
drivers/media/platform/amd/isp4/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0+ + +config AMD_ISP4 + tristate "AMD ISP4 and camera driver" + depends on DRM_AMD_ISP && VIDEO_DEV + select VIDEOBUF2_CORE + select VIDEOBUF2_MEMOPS + select VIDEOBUF2_V4L2 + select VIDEO_V4L2_SUBDEV_API + help + This is support for AMD ISP4 and camera subsystem driver. + Say Y here to enable the ISP4 and camera device for video capture. + To compile this driver as a module, choose M here. The module will + be called amd_capture.
drivers/media/platform/amd/isp4/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2025 Advanced Micro Devices, Inc. + +obj-$(CONFIG_AMD_ISP4) += amd_capture.o +amd_capture-objs := isp4.o
drivers/media/platform/amd/isp4/isp4.c new file +132 -0
132 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2025 Advanced Micro Devices, Inc. +*/ + +#ifndef _ISP4_H_ +#define _ISP4_H_ + +#include <media/v4l2-device.h> +#include <media/videobuf2-memops.h> + +struct isp4_device { +struct v4l2_device v4l2_dev; +struct media_device mdev; +}; + +#endif /* _ISP4_H_ */
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 2/7 media: platform: amd: low level support for isp4 firmware
In reply to Bin DuLow level functions for accessing the registers and mapping to their ranges. This change also includes register definitions for ring buffer used to communicate with ISP Firmware. Ring buffer is the communication interface between driver and ISP Firmware. Command and responses are exchanged through the ring buffer.
--- MAINTAINERS | 1 + drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 drivers/media/platform/amd/isp4/isp4_hw_reg.h
MAINTAINERS +1 -0
@@ -1145,6 +1145,7 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_hw_reg.h AMD KFD M: Felix Kuehling <[email protected]>
drivers/media/platform/amd/isp4/isp4_hw_reg.h new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 3/7 media: platform: amd: Add isp4 fw and hw interface
In reply to Bin DuISP firmware controls ISP HW pipeline using dedicated embedded processor called ccpu. The communication between ISP FW and driver is using commands and response messages sent through the ring buffer. Command buffers support either global setting that is not specific to the steam and support stream specific parameters. Response buffers contain ISP FW notification information such as frame buffer done and command done. IRQ is used for receiving response buffer from ISP firmware, which is handled in the main isp4 media device. ISP ccpu is booted up through the firmware loading helper function prior to stream start. Memory used for command buffer and response buffer needs to be allocated from amdgpu buffer manager because isp4 is a child device of amdgpu.
--- MAINTAINERS | 3 + drivers/media/platform/amd/isp4/Makefile | 3 +- .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++++ .../media/platform/amd/isp4/isp4_interface.c | 784 ++++++++++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++++ 5 files changed, 1243 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.c create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.h
MAINTAINERS +3 -0
@@ -1145,7 +1145,10 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h +F: drivers/media/platform/amd/isp4/isp4_interface.c +F: drivers/media/platform/amd/isp4/isp4_interface.h AMD KFD M: Felix Kuehling <[email protected]>
drivers/media/platform/amd/isp4/Makefile +2 -1
@@ -3,4 +3,5 @@ # Copyright (C) 2025 Advanced Micro Devices, Inc. obj-$(CONFIG_AMD_ISP4) += amd_capture.o -amd_capture-objs := isp4.o +amd_capture-objs := isp4.o \ + isp4_interface.o
drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h new file +314 -0
314 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_interface.c new file +784 -0
784 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_interface.h new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 4/7 media: platform: amd: isp4 subdev and firmware loading handling added
In reply to Bin DuIsp4 sub-device is implementing v4l2 sub-device interface. It has one capture video node, and supports only preview stream. It manages firmware states, stream configuration. Add interrupt handling and notification for isp firmware to isp-subdevice.
--- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 3 +- drivers/media/platform/amd/isp4/isp4.c | 98 +- drivers/media/platform/amd/isp4/isp4.h | 7 +- drivers/media/platform/amd/isp4/isp4_subdev.c | 1004 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 123 ++ 6 files changed, 1229 insertions(+), 8 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.c create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.h
MAINTAINERS +2 -0
@@ -1149,6 +1149,8 @@ F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h F: drivers/media/platform/amd/isp4/isp4_interface.c F: drivers/media/platform/amd/isp4/isp4_interface.h +F: drivers/media/platform/amd/isp4/isp4_subdev.c +F: drivers/media/platform/amd/isp4/isp4_subdev.h AMD KFD M: Felix Kuehling <[email protected]>
drivers/media/platform/amd/isp4/Makefile +2 -1
@@ -4,4 +4,5 @@ obj-$(CONFIG_AMD_ISP4) += amd_capture.o amd_capture-objs := isp4.o \ - isp4_interface.o + isp4_interface.o \ + isp4_subdev.o
drivers/media/platform/amd/isp4/isp4.c +93 -5
166 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4.h +5 -2
@@ -6,12 +6,15 @@#ifndef _ISP4_H_#define _ISP4_H_ -#include <media/v4l2-device.h> -#include <media/videobuf2-memops.h> +#include <drm/amd/isp.h> +#include "isp4_subdev.h" struct isp4_device {struct v4l2_device v4l2_dev; +struct isp4_subdev isp_subdev;struct media_device mdev; }; +void isp4_intr_enable (struct isp4_subdev *isp_subdev,u32 index,bool enable); +#endif /* _ISP4_H_ */
drivers/media/platform/amd/isp4/isp4_subdev.c new file +1004 -0
1,004 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_subdev.h new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 5/7 media: platform: amd: isp4 video node and buffers handling added
In reply to Bin DuIsp video implements v4l2 video interface and supports NV12 and YUYV. It manages buffers, pipeline power and state. Cherry-picked Sultan's DMA buffer related fix from branch v6.16-drm-tip-isp4-for-amd on
https://github.com/kerneltoast/kernel_x86_laptop.git
--- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 3 +- drivers/media/platform/amd/isp4/isp4.c | 10 + drivers/media/platform/amd/isp4/isp4_subdev.c | 81 +- drivers/media/platform/amd/isp4/isp4_subdev.h | 2 + drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 7 files changed, 1316 insertions(+), 5 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_video.c create mode 100644 drivers/media/platform/amd/isp4/isp4_video.h
MAINTAINERS +2 -0
@@ -1151,6 +1151,8 @@ F: drivers/media/platform/amd/isp4/isp4_interface.c F: drivers/media/platform/amd/isp4/isp4_interface.h F: drivers/media/platform/amd/isp4/isp4_subdev.c F: drivers/media/platform/amd/isp4/isp4_subdev.h +F: drivers/media/platform/amd/isp4/isp4_video.c +F: drivers/media/platform/amd/isp4/isp4_video.h AMD KFD M: Felix Kuehling <[email protected]>
drivers/media/platform/amd/isp4/Makefile +2 -1
@@ -5,4 +5,5 @@ obj-$(CONFIG_AMD_ISP4) += amd_capture.o amd_capture-objs := isp4.o \ isp4_interface.o \ - isp4_subdev.o + isp4_subdev.o \ + isp4_video.o
drivers/media/platform/amd/isp4/isp4.c +10 -0
@@ -168,6 +168,16 @@ static int isp4_capture_probe(struct platform_device *pdev) goto err_pm_disable; } + ret =media_create_pad_link (&isp_dev->isp_subdev.sdev.entity, +0 , &isp_dev->isp_subdev.isp_vdev.vdev.entity, +0 , +MEDIA_LNK_FL_ENABLED | +MEDIA_LNK_FL_IMMUTABLE ); +if (ret) { +dev_err_probe (dev, ret,"fail to create pad link\n" ); + goto err_isp4_deinit; + } + ret =media_device_register (&isp_dev->mdev);if (ret) {dev_err_probe (dev, ret,"fail to register media device\n" );
drivers/media/platform/amd/isp4/isp4_subdev.c +77 -4
119 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_subdev.h +2 -0
@@ -17,6 +17,7 @@#include "isp4_fw_cmd_resp.h" #include "isp4_hw_reg.h" #include "isp4_interface.h" +#include "isp4_video.h" /* * one is for none sesnor specefic response which is not used now
@@ -93,6 +94,7 @@ struct isp4_subdev_thread_param {struct isp4_subdev {struct v4l2_subdev sdev;struct isp4_interface ispif; +struct isp4vid_dev isp_vdev;struct media_pad sdev_pad;
drivers/media/platform/amd/isp4/isp4_video.c new file +1158 -0
1,158 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_video.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 6/7 media: platform: amd: isp4 debug fs logging and more descriptive errors
In reply to Bin DuAdd debug fs for isp4 driver and add more detailed descriptive error info to some of the log message
--- MAINTAINERS | 2 + drivers/media/platform/amd/isp4/Makefile | 1 + drivers/media/platform/amd/isp4/isp4.c | 4 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++++++++++++++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 +++ .../media/platform/amd/isp4/isp4_interface.c | 21 +- drivers/media/platform/amd/isp4/isp4_subdev.c | 30 +- drivers/media/platform/amd/isp4/isp4_subdev.h | 5 + 8 files changed, 356 insertions(+), 19 deletions(-) create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.c create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.h
MAINTAINERS +2 -0
@@ -1145,6 +1145,8 @@ F: drivers/media/platform/amd/isp4/Kconfig F: drivers/media/platform/amd/isp4/Makefile F: drivers/media/platform/amd/isp4/isp4.c F: drivers/media/platform/amd/isp4/isp4.h +F: drivers/media/platform/amd/isp4/isp4_debug.c +F: drivers/media/platform/amd/isp4/isp4_debug.h F: drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h F: drivers/media/platform/amd/isp4/isp4_hw_reg.h F: drivers/media/platform/amd/isp4/isp4_interface.c
drivers/media/platform/amd/isp4/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_AMD_ISP4) += amd_capture.o amd_capture-objs := isp4.o \ + isp4_debug.o \ isp4_interface.o \ isp4_subdev.o \ isp4_video.o
drivers/media/platform/amd/isp4/isp4.c +4 -0
@@ -10,6 +10,7 @@#include <media/v4l2-ioctl.h> #include "isp4.h" +#include "isp4_debug.h" #include "isp4_hw_reg.h" #define ISP4_DRV_NAME "amd_isp_capture"
@@ -185,6 +186,7 @@ static int isp4_capture_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, isp_dev); +isp_debugfs_create (isp_dev);return 0 ;
@@ -204,6 +206,8 @@ static void isp4_capture_remove(struct platform_device *pdev)struct isp4_device *isp_dev =platform_get_drvdata (pdev);struct device *dev = &pdev->dev; +isp_debugfs_remove (isp_dev); +media_device_unregister (&isp_dev->mdev);isp4sd_deinit (&isp_dev->isp_subdev);v4l2_device_unregister (&isp_dev->v4l2_dev);
drivers/media/platform/amd/isp4/isp4_debug.c new file +271 -0
271 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_debug.h new file +41 -0
41 lines not on this page · raw message
drivers/media/platform/amd/isp4/isp4_interface.c +12 -9
@@ -5,6 +5,7 @@#include <linux/iopoll.h> +#include "isp4_debug.h" #include "isp4_fw_cmd_resp.h" #include "isp4_hw_reg.h" #include "isp4_interface.h"
@@ -297,8 +298,8 @@ static int isp4if_insert_isp_fw_cmd(struct isp4_interface *ispif, enum isp4if_st rd_ptr =isp4hw_rreg (ispif->mmio, rreg); wr_ptr =isp4hw_rreg (ispif->mmio, wreg);if (rd_ptr >= len || wr_ptr >= len) { -dev_err (dev,"rb invalid: stream=%u, rd=%u, wr=%u, len=%u, cmd_sz=%u\n" , - stream, rd_ptr, wr_ptr, len, cmd_sz); +dev_err (dev,"rb invalid: stream=%u(%s), rd=%u, wr=%u, len=%u, cmd_sz=%u\n" , + stream,isp4dbg_get_if_stream_str (stream), rd_ptr, wr_ptr, len, cmd_sz);return -EINVAL ; }
@@ -379,7 +380,8 @@ static int isp4if_send_fw_cmd(struct isp4_interface *ispif, u32 cmd_id, const vou32 wr_ptr =isp4hw_rreg (ispif->mmio, rb_config->reg_wptr);dev_err (dev, -"failed to get free cmdq slot, stream (%d),rd %u, wr %u\n" , +"failed to get free cmdq slot, stream %s(%d),rd %u, wr %u\n" , +isp4dbg_get_if_stream_str (stream), stream, rd_ptr, wr_ptr); ret = -ETIMEDOUT ; goto free_ele;
@@ -403,7 +405,8 @@ static int isp4if_send_fw_cmd(struct isp4_interface *ispif, u32 cmd_id, const vo ret =isp4if_insert_isp_fw_cmd (ispif, stream, &cmd);if (ret) { -dev_err (dev,"fail for insert_isp_fw_cmd cmd_id (0x%08x)\n" , cmd_id); +dev_err (dev,"fail for insert_isp_fw_cmd cmd_id %s(0x%08x)\n" , +isp4dbg_get_cmd_str (cmd_id), cmd_id); goto err_dequeue_ele; } }
@@ -648,17 +651,17 @@ int isp4if_f2h_resp(struct isp4_interface *ispif, enum isp4if_stream_id stream,if (checksum != resp->resp_check_sum) {dev_err (dev,"resp checksum 0x%x,should 0x%x,rptr %u,wptr %u\n" , checksum, resp->resp_check_sum, rd_ptr, wr_ptr); -dev_err (dev,"(%u), seqNo %u, resp_id (0x%x)\n" , - stream, resp->resp_seq_num, - resp->resp_id); +dev_err (dev,"%s(%u), seqNo %u, resp_id %s(0x%x)\n" , +isp4dbg_get_if_stream_str (stream), stream, resp->resp_seq_num, +isp4dbg_get_resp_str (resp->resp_id), resp->resp_id);return -EINVAL ; }return 0 ; err_rb_invalid: -dev_err (dev,"rb invalid: stream=%u, rd=%u, wr=%u, len=%u, resp_sz=%u\n" , - stream, rd_ptr, wr_ptr, len, resp_sz); +dev_err (dev,"rb invalid: stream=%u(%s), rd=%u, wr=%u, len=%u, resp_sz=%u\n" , + stream,isp4dbg_get_if_stream_str (stream), rd_ptr, wr_ptr, len, resp_sz);return -EINVAL ; }
drivers/media/platform/amd/isp4/isp4_subdev.c +20 -10
@@ -6,6 +6,7 @@#include <linux/pm_domain.h> #include <linux/units.h> +#include "isp4_debug.h" #include "isp4_fw_cmd_resp.h" #include "isp4_interface.h" #include "isp4.h"
@@ -255,9 +256,9 @@ static int isp4sd_setup_output(struct isp4_subdev *isp_subdev,return -EINVAL ; } -dev_dbg (dev,"channel:%d,fmt %d,w:h=%u:%u,lp:%u,cp%u\n" , - cmd_ch_prop.ch, - cmd_ch_prop.image_prop.image_format, +dev_dbg (dev,"channel:%s,fmt %s,w:h=%u:%u,lp:%u,cp%u\n" , +isp4dbg_get_out_ch_str (cmd_ch_prop.ch), +isp4dbg_get_img_fmt_str (cmd_ch_prop.image_prop.image_format), cmd_ch_prop.image_prop.width, cmd_ch_prop.image_prop.height, cmd_ch_prop.image_prop.luma_pitch, cmd_ch_prop.image_prop.chroma_pitch);
@@ -285,7 +286,7 @@ static int isp4sd_setup_output(struct isp4_subdev *isp_subdev,return ret; } -dev_dbg (dev,"enable channel %d\n" , cmd_ch_en.ch); +dev_dbg (dev,"enable channel %s\n" ,isp4dbg_get_out_ch_str (cmd_ch_en.ch));if (!sensor_info->start_stream_cmd_sent) { ret = isp4sd_kickoff_stream(isp_subdev,
@@ -392,8 +393,9 @@ static void isp4sd_fw_resp_cmd_done(struct isp4_subdev *isp_subdev,isp4if_rm_cmd_from_cmdq (ispif, para->cmd_seq_num, para->cmd_id);struct device *dev = isp_subdev->dev; -dev_dbg (dev,"stream %d,cmd (0x%08x)(%d),seq %u, ele %p\n" , +dev_dbg (dev,"stream %d,cmd %s(0x%08x)(%d),seq %u, ele %p\n" , stream_id, +isp4dbg_get_cmd_str (para->cmd_id), para->cmd_id, para->cmd_status, para->cmd_seq_num, ele);
@@ -468,9 +470,10 @@ static void isp4sd_fw_resp_frame_done(struct isp4_subdev *isp_subdev,return ; } -dev_dbg (dev,"ts:%llu,streamId:%d,poc:%u,preview_en:%u,(%i)\n" , +dev_dbg (dev,"ts:%llu,streamId:%d,poc:%u,preview_en:%u,%s(%i)\n" ,ktime_get_ns (), stream_id, meta->poc, meta->preview.enabled, +isp4dbg_get_buf_done_str (meta->preview.status), meta->preview.status); if (meta->preview.enabled &&
@@ -479,6 +482,8 @@ static void isp4sd_fw_resp_frame_done(struct isp4_subdev *isp_subdev, meta->preview.status == BUFFER_STATUS_DIRTY)) { prev =isp4if_dequeue_buffer (ispif);if (prev) { +isp4dbg_show_bufmeta_info (dev,"prev" , &meta->preview, + &prev->buf_info);isp4vid_handle_frame_done (&isp_subdev->isp_vdev, &prev->buf_info);isp4if_dealloc_buffer_node (prev);
@@ -486,8 +491,9 @@ static void isp4sd_fw_resp_frame_done(struct isp4_subdev *isp_subdev,dev_err (dev,"fail null prev buf\n" ); } }else if (meta->preview.enabled) { -dev_err (dev,"fail bad preview status %u\n" , - meta->preview.status); +dev_err (dev,"fail bad preview status %u(%s)\n" , + meta->preview.status, +isp4dbg_get_buf_done_str (meta->preview.status)); }if (isp_subdev->sensor_info.status ==ISP4SD_START_STATUS_STARTED )
@@ -504,6 +510,9 @@ static void isp4sd_fw_resp_func(struct isp4_subdev *isp_subdev,struct device *dev = isp_subdev->dev;struct isp4fw_resp resp; +if (stream_id ==ISP4IF_STREAM_ID_1 ) +isp_fw_log_print (isp_subdev); +while (true) {if (isp4if_f2h_resp (ispif, stream_id, &resp)) {/* Re-enable the interrupt */
@@ -532,7 +541,9 @@ static void isp4sd_fw_resp_func(struct isp4_subdev *isp_subdev, &resp.param.frame_done);break ;default : -dev_err (dev,"-><- fail respid (0x%x)\n" , resp.resp_id); +dev_err (dev,"-><- fail respid %s(0x%x)\n" , +isp4dbg_get_resp_str (resp.resp_id), + resp.resp_id);break ; } }
@@ -880,7 +891,6 @@ static int isp4sd_ioc_send_img_buf(struct v4l2_subdev *sd, error_release_buf_node:isp4if_dealloc_buffer_node (buf_node); -return ret; }
drivers/media/platform/amd/isp4/isp4_subdev.h +5 -0
@@ -116,6 +116,11 @@ struct isp4_subdev {int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM ];bool irq_enabled;spinlock_t irq_lock; +#ifdef CONFIG_DEBUG_FS +bool enable_fw_log; +struct dentry *debugfs_dir; +char *fw_log_output; +#endif }; int isp4sd_init(struct isp4_subdev *isp_subdev, struct v4l2_device *v4l2_dev,
Signature · 1 line
2.34.1
Bin Du
maintainerPATCH v6 7/7 Documentation: add documentation of AMD isp 4 driver
In reply to Bin DuAdd documentation for AMD ISP 4 and describe the main components
--- Documentation/admin-guide/media/amdisp4-1.rst | 63 +++++++++++++++++++ Documentation/admin-guide/media/amdisp4.dot | 6 ++ .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 2 + 4 files changed, 72 insertions(+) create mode 100644 Documentation/admin-guide/media/amdisp4-1.rst create mode 100644 Documentation/admin-guide/media/amdisp4.dot
Documentation/admin-guide/media/amdisp4-1.rst new file +63 -0
@@ -0,0 +1,63 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. include:: <isonum.txt> + +==================================== +AMD Image Signal Processor (amdisp4) +==================================== + +Introduction +============ + +This file documents the driver for the AMD ISP4 that is part of +AMD Ryzen AI Max 300 Series. + +The driver is located under drivers/media/platform/amd/isp4 and uses +the Media-Controller API. + +The driver exposes one video capture device to userspace and provide +web camera like interface. Internally the video device is connected +to the isp4 sub-device responsible for communication with the CCPU FW. + +Topology +======== + +.. _amdisp4_topology_graph: + +.. kernel-figure:: amdisp4.dot + :alt: Diagram of the media pipeline topology + :align: center + + + +The driver has 1 sub-device: Representing isp4 image signal processor. +The driver has 1 video device: Capture device for retrieving images. + +- ISP4 Image Signal Processing Subdevice Node + +--------------------------------------------- + +The isp4 is represented as a single V4L2 subdev, the sub-device does not +provide interface to the user space. The sub-device is connected to one video node +(isp4_capture) with immutable active link. The sub-device represents ISP with +connected sensor similar to smart cameras (sensors with integrated ISP). +sub-device has only one link to the video device for capturing the frames. +The sub-device communicates with CCPU FW for streaming configuration and +buffer management. + + +- isp4_capture - Frames Capture Video Node + +------------------------------------------ + +Isp4_capture is a capture device to capture frames to memory. +The entity is connected to isp4 sub-device. The video device +provides web camera like interface to userspace. It supports +mmap and dma buf types of memory. + +Capturing Video Frames Example +============================== + +.. code-block:: bash + + v4l2-ctl "-d" "/dev/video0" "--set-fmt-video=width=1920,height=1080,pixelformat=NV12" "--stream-mmap" "--stream-count=10"
Documentation/admin-guide/media/amdisp4.dot new file +6 -0
@@ -0,0 +1,6 @@ +digraph board { + rankdir=TB + n00000001 [label="{{} | amd isp4\n | {<port0> 0}}", shape=Mrecord, style=filled, fillcolor=green] + n00000001:port0 -> n00000003 [style=bold] + n00000003 [label="Preview\n/dev/video0", shape=box, style=filled, fillcolor=yellow] +}
Documentation/admin-guide/media/v4l-drivers.rst +1 -0
@@ -9,6 +9,7 @@ Video4Linux (V4L) driver-specific documentation .. toctree:: :maxdepth: 2 + amdisp4-1 bttv c3-isp cafe_ccic
MAINTAINERS +2 -0
@@ -1139,6 +1139,8 @@ M: Nirujogi Pratap <[email protected]> L: [email protected] S: Maintained T: git git://linuxtv.org/media.git +F: Documentation/admin-guide/media/amdisp4-1.rst +F: Documentation/admin-guide/media/amdisp4.dot F: drivers/media/platform/amd/Kconfig F: drivers/media/platform/amd/Makefile F: drivers/media/platform/amd/isp4/Kconfig
Signature · 1 line
2.34.1
Quoted 339 lines · Bin Du
Hello,
AMD ISP4 is the AMD image processing gen 4 which can be found in HP ZBook Ultra G1a 14 inch Mobile Workstation PC (Ryzen AI Max 300 Series)
(https://ubuntu.com/certified/202411-36043)
This patch series introduces the initial driver support for the AMD ISP4.Patch summary:
- Powers up/off and initializes ISP HW
- Configures and kicks off ISP FW
- Interacts with APP using standard V4l2 interface by video node
- Controls ISP HW and interacts with ISP FW to do image processing
- Supports enum/set output image format and resolution
- Supports queueing buffer from app and dequeuing ISP filled buffer to App
- It is verified on qv4l2, cheese and qcam
- It is verified together with following patchesplatform/x86: Add AMD ISP platform config (https://lore.kernel.org/all/[email protected]/) pinctrl: amd: isp411: Add amdisp GPIO pinctrl (https://github.com/torvalds/linux/commit/e97435ab09f3ad7b6a588dd7c4e45a96699bbb4a) drm/amd/amdgpu: Add GPIO resources required for amdisp (https://gitlab.freedesktop.org/agd5f/linux/-/commit/ad0f5966ed8297aa47b3184192b00b7379ae0758) drm/amd/amdgpu: Declare isp firmware binary file (https://gitlab.freedesktop.org/agd5f/linux/-/commit/35345917bc9f7c86152b270d9d93c220230b667f)AMD ISP4 Key features:
- Processes bayer raw data from the connected sensor and output them to different YUV formats
- Downscale input image to different output image resolution
- Pipeline to do image processing on the input image including demosaic, denoise, 3A, etc.----------
Changes v5 -> v6:
- Lowered FW mempool buffer size from 200M to 100M (actual usage).
- Added anirq_enabledmember to the ISP subdev for proper IRQ disable handling in both normal and error cases.
- Removed unnecessary .owner assignment fromisp4_capture_drvdefinition
- Updated IRQ handling to enable and disable interrupts via the ISP register for improved performance.
- Revised ring buffer management inisp4if_f2h_resp(), addressing safety checks to ensure the read pointer is validated before memcpy operations, reducing the risk of out-of-bounds access. The ring buffer logic was also streamlined significantly.
- Modified ring buffer handling inisp4if_is_cmdq_rb_full(), correcting an off-by-one error in safety checks that previously allowedrd_ptrto equalwr_ptrwhen the buffer was full.
- Refactored ring buffer handling inisp4if_insert_isp_fw_cmd(), simplifying overall logic.
- Resolved a regression from v4 to v5 whereisp4if_dequeue_buffer()did not protectlist_delwithbufq_lock.
- Addressed a subtle use-after-free issue that could occur if a timeout on a synchronous command coincided with completion.
- Added missingpm_runtime_disable()calls toisp4_capture_remove()and to the error path inisp4_capture_probe().
- Removed stray semicolons following closing curly braces.
- Improved and clarified macro definitions inisp4_interface.h.
- Eliminated unnecessary (u8 *) casts.
- Added missing memset for firmware command structures inisp4sd_stop_stream().
- Excluded streams 2 and 3 fromISP4IF_FW_RESP_RB_IRQ_EN_MASK, preventing their activation in the interrupt enable register.
- Enhanced error handling to clean up kthreads in the event of startup failure.
- Corrected a race condition during kthread creation where waitqueue head initialization could be delayed, as it was performed by the kthread itself.
- Removed status checks inisp4sd_pwroff_and_deinit()that were always false.
- Ensuredisp4sd_init_stream()is only invoked once per stream start and reordered corresponding status checks inisp4sd_start_stream().
- Improved error handling inisp4sd_start_stream()to propagate errors from failed functions.
- Relocated debugging messages inisp4sd_stop_stream()to execute under lock protection due to access tooutput_info->start_status.
- Eliminated redundantGET_REG_BASE()macros.
- Removedisp4sd_is_stream_running()function.
- Corrected error message inisp4sd_init_stream()caused by copy/paste.
- Refined structisp4_interfaceto remove firmware ring buffer configurations.
- Removed obsoleteisp4sd_is_stream_runningfunction.
- Removed pdev member from structisp4_device, as it is unnecessary.
- Fixed typo in 'isp_mmip' parameter name withinisp4if_init().
- Removed gap in structisp4_subdevdefinition.
- Performed extensive dead code removal and minor style improvements throughout the codebase.Changes v4 -> v5:
- Transitioned
VIDEOBUF2_V4L2from 'depends' to 'select' withinKconfig.
- Standardized object file naming conventions in theMakefileand sorted entries alphabetically.
- Removed the unused macro definitionto_isp4_device.
- Eliminated unused membersmem_domainandmem_alignfrom structisp4if_gpu_mem_info.
- Deleted unused fieldsmc_addrandgpu_pkgfrom structisp4if_cmd_element.
- Removed obsoletepltf_data,i2c_nb, and notifier elements from structisp4_device.
- Updatedplatform_get_irqfailure handling to return its actual result rather than-ENODEV.
- Refined inclusion of header files for clarity and efficiency.
- Appended comments following #endif statements in header files.
- Improved implementation ofisp4if_gpu_mem_freeandisp4if_dealloc_fw_gpumem.
- Removedisp4if_append_cmd_2_cmdqand revisedisp4if_send_fw_cmdaccordingly.
- Enhancedisp4if_clear_cmdqandisp4if_clear_bufqby eliminating unnecessarylist_deloperations.
- Adopted completion mechanism instead of wait queue and condition for command completion notifications.
- Employed memset to ensure proper zeroing of padding bits in structures shared between ISP driver and firmware.
- Streamlined IRQs, reducing total from four to two, retaining only essential ones.
- Optimized IRQ handler logic using a while loop for greater efficiency.
- Introduced dynamic IRQ enable/disable functionality based on camera status (open/close).
- Applied distinct identifiers to differentiate multiple threads and IRQs.
- Removed unnecessary initialization of local variables.
- Refined camera start/stop workflow to mitigate potential synchronization concerns.
- Replaced all remaining mutex with guard mutex.
- Enhanced command and buffer queue performance by substituting mutexes with spinlocks.
- Removed redundantisp4sd_init_meta_buffunction and its references.
- Limited firmware logging activities to the stream1 thread.
- Relocatedv4l2_device_unregister_subdev()andmedia_entity_cleanup()calls fromisp4_capture_removetoisp4sd_deinit.
- Resolved media device registration sequence issues.
- Modified stream processing thread behavior to await IRQ without a timeout.
- Addressed cleanup procedures in video device initialization and deinitialization routines.
- Corrected typos and made other cosmetic improvements.Changes v3 -> v4:
- Replace one mutex with guard mutex.
- Remove unnecessarybus_infoinitialization ofv4l2_capability.
- DropV4L2_CAP_IO_MCfrom capabilities ofv4l2_capability.
- Modify document with better SOC description.
- Fix Test x86 failure in Media CI test https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/83470456/artifacts/report.htm
- Modify some commit messages by describing changes in imperative mood.
- Add media-ctl output in cover letter.
- Create separated dedicated amdgpu patch to add declarationMODULE_FIRMWARE("amdgpu/isp_4_1_1.bin");
- Fix typo errors and other cosmetic issues.
- AddDRM_AMD_ISPdependency inKconfig.Changes v2 -> v3:
- All the dependent patches in other modules (drm/amd/amdgpu, platform/x86, pinctrl/amd) merged on upstream mainline kernel (https://github.com/torvalds/linux) v6.17.
- Removed usage of amdgpu structs in ISP driver. Added helper functions in amdgpu accepting opaque params from ISP driver to allocate and release ISP GART buffers.
- Moved sensor and MIPI phy control entirely into ISP FW instead of the previous hybrid approach controlling sensor from both FW and x86 (sensor driver).
- Removed phy configuration and sensor binding as x86 (sensor driver) had relinquished the sensor control for ISP FW. With this approach the driver will be exposed as web camera like interface.
- New FW with built-in sensor driver is submitted on upstream linux-firmware repo (https://gitlab.com/kernel-firmware/linux-firmware/).
- Please note the new FW submitted is not directly compatible with OEM Kernel ISP4.0 (https://github.com/amd/Linux_ISP_Kernel/tree/4.0) and the previous ISP V2 patch series.
- If intend to use the new FW, please rebuild OEM ISP4.0 Kernel withCONFIG_VIDEO_OV05C10=NandCONFIG_PINCTRL_AMDISP=Y.
- Included critical fixes from Sultan Alsawaf branch (https://github.com/kerneltoast/kernel_x86_laptop.git) related to managing lifetime of isp buffers.
media: amd: isp4: Add missing refcount tracking to mmap memop
media: amd: isp4: Don't put or unmap the dmabuf when detaching
media: amd: isp4: Don't increment refcount when dmabuf export fails
media: amd: isp4: Fix possible use-after-free inisp4vid_vb2_put()
media: amd: isp4: Always export a new dmabuf fromget_dmabufmemop
media: amd: isp4: Fix implicit dmabuf lifetime tracking
media: amd: isp4: Fix possible use-after-free when putting implicit dmabuf
media: amd: isp4: Simplifyisp4vid_get_dmabuf()arguments
media: amd: isp4: Move upbuf->vaddrcheck inisp4vid_get_dmabuf()
media: amd: isp4: Remove unused userptr memops
media: amd: isp4: Add missing cleanup on error inisp4vid_vb2_alloc()
media: amd: isp4: Release queued buffers on error instart_streaming
- Addressed all code related upstream comments
- Fix typo errors and other cosmetic issues.Changes v1 -> v2:
- Fix media CI test errors and valid warnings
- Reduce patch number in the series from 9 to 8 by mergingMAINTAINERSadding patch to the first patch
- In patch 5
- do modification to use remote endpoint instead of local endpoint
- use link frequency and port number as start phy parameter instead of extra added phy-id and phy-bit-rate property of endpoint----------
It passes v4l2 compliance test, the test reports for:
(a)
amd_isp_capturedevice/dev/video0Compliance test for
amd_isp_capturedevice/dev/video0:
-------------------------------------------------------atg@atg-HP-PV:~/bin$ ./v4l2-compliance -d /dev/video0 v4l2-compliance 1.29.0-5348, 64 bits, 64-bit time_t v4l2-compliance SHA: 75e3f0e2c2cb 2025-03-17 18:12:17Compliance test for
amd_isp_capturedevice/dev/video0:Driver Info:
Driver name : amd_isp_capture Card type : amd_isp_capture Bus info : platform:amd_isp_capture Driver version : 6.14.0 Capabilities : 0xa4200001Video Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps :0x24200001
Video Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:Driver name : amd_isp_capture Model : amd_isp41_mdev Serial : Bus info : platform:amd_isp_capture Media version : 6.14.0 Hardware revision: 0x00000000 (0) Driver version : 6.14.0Interface Info:
ID :0x03000005
Type : V4L Video
Entity Info:ID : 0x00000003 (3) Name : Preview Function : V4L2 I/O Pad 0x01000004 : 0: Sink Link 0x02000007: from remote pad 0x1000002 of entity 'amd isp4' (Image Signal Processor): Data, Enabled, ImmutableRequired ioctls:
test MC information (see 'Media Driver Info' above): OK testVIDIOC_QUERYCAP: OK
test invalid ioctls: OKAllow for multiple opens:
test second/dev/video0open: OK
testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_LOG_STATUS: OK (Not Supported)Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) testVIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
testVIDIOC_G_FBUF: OK (Not Supported) testVIDIOC_G_FMT: OK
testVIDIOC_TRY_FMT: OK
testVIDIOC_S_FMT: OK
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK testCREATE_BUFSmaximum buffers: OK testVIDIOC_REMOVE_BUFS: OK
testVIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OKTotal for
amd_isp_capturedevice/dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0The media-ctl output of media device
/dev/media0:
-------------------------------------------------------atg@atg-HP-PV:~$ media-ctl -p -d /dev/media0 Media controller API version 6.17.0Media device information
------------------------
driveramd_isp_capture
modelamd_isp41_mdev
serialbus info platform:amd_isp_capture hw revision 0x0 driver version 6.17.0Device topology
- entity 1: amd isp4 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "Preview":0 [ENABLED,IMMUTABLE]- entity 3: Preview (1 pad, 1 link)
type Node subtype V4L flags 0 device node name/dev/video0
pad0: Sink
<- "amd isp4":0 [ENABLED,IMMUTABLE]Please review and provide feedback.
Many thanks,
Bin Du (7):
media: platform: amd: Introduce amd isp4 capture driver
media: platform: amd: low level support for isp4 firmware
media: platform: amd: Add isp4 fw and hw interface
media: platform: amd: isp4 subdev and firmware loading handling added
media: platform: amd: isp4 video node and buffers handling added
media: platform: amd: isp4 debug fs logging and more descriptive
errors
Documentation: add documentation of AMD isp 4 driverDocumentation/admin-guide/media/amdisp4-1.rst | 63 + Documentation/admin-guide/media/amdisp4.dot | 6 + .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 25 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 + drivers/media/platform/amd/isp4/Makefile | 10 + drivers/media/platform/amd/isp4/isp4.c | 234 ++++ drivers/media/platform/amd/isp4/isp4.h | 20 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++ drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++ .../media/platform/amd/isp4/isp4_interface.c | 787 +++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++ drivers/media/platform/amd/isp4/isp4_subdev.c | 1087 ++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 130 ++ drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 22 files changed, 4498 insertions(+) create mode 100644 Documentation/admin-guide/media/amdisp4-1.rst create mode 100644 Documentation/admin-guide/media/amdisp4.dot create mode 100644 drivers/media/platform/amd/Kconfig create mode 100644 drivers/media/platform/amd/Makefile create mode 100644 drivers/media/platform/amd/isp4/Kconfig create mode 100644 drivers/media/platform/amd/isp4/Makefile create mode 100644 drivers/media/platform/amd/isp4/isp4.c create mode 100644 drivers/media/platform/amd/isp4/isp4.h create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.c create mode 100644 drivers/media/platform/amd/isp4/isp4_debug.h
Quoted 12 lines
create mode 100644 drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.h create mode 100644 drivers/media/platform/amd/isp4/isp4_hw_reg.h create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.c create mode 100644 drivers/media/platform/amd/isp4/isp4_interface.h create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.c create mode 100644 drivers/media/platform/amd/isp4/isp4_subdev.h create mode 100644 drivers/media/platform/amd/isp4/isp4_video.c create mode 100644 drivers/media/platform/amd/isp4/isp4_video.hSignature · 1 line
2.34.1
Hi Bin,
I have attached a small patch with a fix for an old issue I noticed now while reading the v6 code and some remaining style nitpicks addressed. And some duplicated code on stream stop removed.
This is the last change from me, I promise. :)
Otherwise, v6 is looking very good! Good catches with the error handling too, with the irq_enabled flag and v4l2_device_register() error cleanup.
Thanks,
Sultan
From ccd92ac77ba5875ca25e9928d12858232fce17ba Mon Sep 17 00:00:00 2001
From: Sultan Alsawaf <[email protected]>
Date: Fri, 28 Nov 2025 18:40:33 -0800
Subject: [PATCH] media: platform: amd: Small subdev changes on top of v6
driver
-Fixed buf_sent_cnt not getting reset when the stream is stopped, even
though start_stream_cmd_sent would get reset
-Removed duplicate start_stream_cmd_sent and buf_sent_cnt reset in
isp4sd_pwron_and_init(), the same two lines appear lower in the function and the duplication isn't needed
-Removed duplicate call to isp4sd_reset_stream_info() when the stream is
stopped. Achieved this and removed duplicate status setting in the process by rolling isp4sd_reset_stream_info() and isp4sd_reset_camera_info() into isp4sd_uninit_stream()
-Removed always-false status check in isp4sd_uninit_stream()
-A few small style cleanups
--- drivers/media/platform/amd/isp4/isp4_subdev.c | 70 +++++-------------- 1 file changed, 19 insertions(+), 51 deletions(-)
drivers/media/platform/amd/isp4/isp4_subdev.c +19 -51
@@ -60,7 +60,7 @@ static int isp4sd_setup_fw_mem_pool(struct isp4_subdev *isp_subdev)isp4if_split_addr64 (ispif->fw_mem_pool->gpu_mc_addr, &buf_type.buffer.buf_base_a_lo, &buf_type.buffer.buf_base_a_hi); - buf_type.buffer.buf_size_a = (u32 )ispif->fw_mem_pool->mem_size; + buf_type.buffer.buf_size_a = ispif->fw_mem_pool->mem_size; ret =isp4if_send_command (ispif,CMD_ID_SEND_BUFFER , &buf_type,sizeof (buf_type));
@@ -124,10 +124,10 @@ static int isp4sd_send_meta_buf(struct isp4_subdev *isp_subdev) } buf_type.buffer_type =BUFFER_TYPE_META_INFO ; buf_type.buffer.vmid_space.bit.space =ADDR_SPACE_TYPE_GPU_VA ; -isp4if_split_addr64 (isp_subdev->ispif.meta_info_buf[i]->gpu_mc_addr, +isp4if_split_addr64 (meta_info_buf->gpu_mc_addr, &buf_type.buffer.buf_base_a_lo, &buf_type.buffer.buf_base_a_hi); - buf_type.buffer.buf_size_a = (u32 )isp_subdev->ispif.meta_info_buf[i]->mem_size; + buf_type.buffer.buf_size_a = meta_info_buf->mem_size; ret =isp4if_send_command (ispif,CMD_ID_SEND_BUFFER , &buf_type,sizeof (buf_type));if (ret) {
@@ -205,8 +205,7 @@ static int isp4sd_kickoff_stream(struct isp4_subdev *isp_subdev, u32 w, u32 h) sensor_info->status =ISP4SD_START_STATUS_OFF ;if (!sensor_info->start_stream_cmd_sent && - sensor_info->buf_sent_cnt >= -ISP4SD_MIN_BUF_CNT_BEF_START_STREAM ) { + sensor_info->buf_sent_cnt >=ISP4SD_MIN_BUF_CNT_BEF_START_STREAM ) {int ret =isp4if_send_command (ispif,CMD_ID_START_STREAM ,NULL ,0 );if (ret) {
@@ -324,7 +323,7 @@ static int isp4sd_init_stream(struct isp4_subdev *isp_subdev)struct device *dev = isp_subdev->dev;int ret; - ret =isp4sd_setup_fw_mem_pool (isp_subdev); + ret =isp4sd_setup_fw_mem_pool (isp_subdev);if (ret) {dev_err (dev,"fail to setup fw mem pool\n" );return ret;
@@ -339,10 +338,12 @@ static int isp4sd_init_stream(struct isp4_subdev *isp_subdev)return 0 ; } -static void isp4sd_reset_stream_info (struct isp4_subdev *isp_subdev, -struct v4l2_subdev_state *state,u32 pad) +static void isp4sd_uninit_stream (struct isp4_subdev *isp_subdev, +struct v4l2_subdev_state *state,u32 pad) {struct isp4sd_sensor_info *sensor_info = &isp_subdev->sensor_info; +struct isp4sd_output_info *output_info = &sensor_info->output_info; +struct isp4_interface *ispif = &isp_subdev->ispif;struct v4l2_mbus_framefmt *format; format =v4l2_subdev_state_get_format (state, pad,0 );
@@ -353,35 +354,14 @@ static void isp4sd_reset_stream_info(struct isp4_subdev *isp_subdev, format->code =MEDIA_BUS_FMT_YUYV8_1_5X8 ; } - sensor_info->output_info.start_status =ISP4SD_START_STATUS_OFF ; -} - -static void isp4sd_reset_camera_info (struct isp4_subdev *isp_subdev, -struct v4l2_subdev_state *state,u32 pad) -{ -struct isp4sd_sensor_info *sensor_info = &isp_subdev->sensor_info; - - sensor_info->status =ISP4SD_START_STATUS_OFF ; -isp4sd_reset_stream_info (isp_subdev, state, pad); +isp4if_clear_bufq (ispif); +isp4if_clear_cmdq (ispif); sensor_info->start_stream_cmd_sent = false; -} - -static int isp4sd_uninit_stream (struct isp4_subdev *isp_subdev, -struct v4l2_subdev_state *state,u32 pad) -{ -struct isp4sd_output_info *output_info = &isp_subdev->sensor_info.output_info; -struct isp4_interface *ispif = &isp_subdev->ispif; -struct device *dev = isp_subdev->dev; - -if (output_info->start_status ==ISP4SD_START_STATUS_STARTED ) { -dev_dbg (dev,"fail for stream is still running\n" ); -return -EINVAL ; - } + sensor_info->buf_sent_cnt =0 ; -isp4sd_reset_camera_info (isp_subdev, state, pad); -isp4if_clear_cmdq (ispif); -return 0 ; + sensor_info->status =ISP4SD_START_STATUS_OFF ; + output_info->start_status =ISP4SD_START_STATUS_OFF ; } static void isp4sd_fw_resp_cmd_done(struct isp4_subdev *isp_subdev,
@@ -461,7 +441,7 @@ static void isp4sd_fw_resp_frame_done(struct isp4_subdev *isp_subdev,struct device *dev = isp_subdev->dev;struct isp4if_img_buf_node *prev;struct isp4fw_meta_info *meta; -u64 mc =0 ; +u64 mc; mc =isp4if_join_addr64 (para->package_addr_lo, para->package_addr_hi); meta =isp4sd_get_meta_by_mc (isp_subdev, mc);
@@ -685,9 +665,6 @@ static int isp4sd_pwron_and_init(struct isp4_subdev *isp_subdev)isp4sd_module_enable (isp_subdev, true); - isp_subdev->sensor_info.start_stream_cmd_sent = false; - isp_subdev->sensor_info.buf_sent_cnt =0 ; -if (ispif->status <ISP4IF_STATUS_PWR_ON ) {unsigned int perf_state =ISP4SD_PERFORMANCE_STATE_HIGH ;
@@ -739,17 +716,17 @@ static int isp4sd_pwron_and_init(struct isp4_subdev *isp_subdev)static int isp4sd_stop_stream (struct isp4_subdev *isp_subdev,struct v4l2_subdev_state *state,u32 pad) { -struct isp4sd_output_info *output_info = - &isp_subdev->sensor_info.output_info; +struct isp4sd_sensor_info *sensor_info = &isp_subdev->sensor_info; +struct isp4sd_output_info *output_info = &sensor_info->output_info;struct isp4_interface *ispif = &isp_subdev->ispif;struct device *dev = isp_subdev->dev; -int ret =0 ;guard (mutex)(&isp_subdev->ops_mutex);dev_dbg (dev,"status %i\n" , output_info->start_status);if (output_info->start_status ==ISP4SD_START_STATUS_STARTED ) {struct isp4fw_cmd_enable_out_ch cmd_ch_disable; +int ret;/* * The struct will be shared with ISP FW, use memset() to guarantee
@@ -774,11 +751,6 @@ static int isp4sd_stop_stream(struct isp4_subdev *isp_subdev,dev_dbg (dev,"wait stop stream suc\n" ); } -isp4if_clear_bufq (ispif); - - output_info->start_status =ISP4SD_START_STATUS_OFF ; -isp4sd_reset_stream_info (isp_subdev, state, pad); -isp4sd_uninit_stream (isp_subdev, state, pad);/*
@@ -870,7 +842,6 @@ static int isp4sd_ioc_send_img_buf(struct v4l2_subdev *sd, ISP4SD_MIN_BUF_CNT_BEF_START_STREAM) { ret =isp4if_send_command (ispif,CMD_ID_START_STREAM ,NULL ,0 ); -if (ret) {dev_err (dev,"fail to START_STREAM" ); goto error_release_buf_node;
@@ -1000,8 +971,8 @@ static const struct isp4vid_ops isp4sd_isp4vid_ops = {int isp4sd_init (struct isp4_subdev *isp_subdev,struct v4l2_device *v4l2_dev,int irq[ISP4SD_MAX_FW_RESP_STREAM_NUM ]) { +struct isp4sd_sensor_info *sensor_info = &isp_subdev->sensor_info;struct isp4_interface *ispif = &isp_subdev->ispif; -struct isp4sd_sensor_info *sensor_info;struct device *dev = v4l2_dev->dev;int ret;
@@ -1034,12 +1005,9 @@ int isp4sd_init(struct isp4_subdev *isp_subdev, struct v4l2_device *v4l2_dev, goto err_media_clean_up; } - sensor_info = &isp_subdev->sensor_info; -isp4if_init (ispif, dev, isp_subdev->mmio);mutex_init (&isp_subdev->ops_mutex); - sensor_info->start_stream_cmd_sent = false; sensor_info->status =ISP4SD_START_STATUS_OFF ;/* create ISP enable gpio control */
Signature · 1 line
2.52.0
Du, Bin
maintainerQuoted 353 lines · Sultan Alsawaf
Quoted 339 lines · Bin Du
Hello,
AMD ISP4 is the AMD image processing gen 4 which can be found in HP ZBook Ultra G1a 14 inch Mobile Workstation PC (Ryzen AI Max 300 Series)
(https://ubuntu.com/certified/202411-36043)
This patch series introduces the initial driver support for the AMD ISP4.Patch summary:
- Powers up/off and initializes ISP HW
- Configures and kicks off ISP FW
- Interacts with APP using standard V4l2 interface by video node
- Controls ISP HW and interacts with ISP FW to do image processing
- Supports enum/set output image format and resolution
- Supports queueing buffer from app and dequeuing ISP filled buffer to App
- It is verified on qv4l2, cheese and qcam
- It is verified together with following patchesplatform/x86: Add AMD ISP platform config (https://lore.kernel.org/all/[email protected]/) pinctrl: amd: isp411: Add amdisp GPIO pinctrl (https://github.com/torvalds/linux/commit/e97435ab09f3ad7b6a588dd7c4e45a96699bbb4a) drm/amd/amdgpu: Add GPIO resources required for amdisp (https://gitlab.freedesktop.org/agd5f/linux/-/commit/ad0f5966ed8297aa47b3184192b00b7379ae0758) drm/amd/amdgpu: Declare isp firmware binary file (https://gitlab.freedesktop.org/agd5f/linux/-/commit/35345917bc9f7c86152b270d9d93c220230b667f)AMD ISP4 Key features:
- Processes bayer raw data from the connected sensor and output them to different YUV formats
- Downscale input image to different output image resolution
- Pipeline to do image processing on the input image including demosaic, denoise, 3A, etc.----------
Changes v5 -> v6:
- Lowered FW mempool buffer size from 200M to 100M (actual usage).
- Added anirq_enabledmember to the ISP subdev for proper IRQ disable handling in both normal and error cases.
- Removed unnecessary .owner assignment fromisp4_capture_drvdefinition
- Updated IRQ handling to enable and disable interrupts via the ISP register for improved performance.
- Revised ring buffer management inisp4if_f2h_resp(), addressing safety checks to ensure the read pointer is validated before memcpy operations, reducing the risk of out-of-bounds access. The ring buffer logic was also streamlined significantly.
- Modified ring buffer handling inisp4if_is_cmdq_rb_full(), correcting an off-by-one error in safety checks that previously allowedrd_ptrto equalwr_ptrwhen the buffer was full.
- Refactored ring buffer handling inisp4if_insert_isp_fw_cmd(), simplifying overall logic.
- Resolved a regression from v4 to v5 whereisp4if_dequeue_buffer()did not protectlist_delwithbufq_lock.
- Addressed a subtle use-after-free issue that could occur if a timeout on a synchronous command coincided with completion.
- Added missingpm_runtime_disable()calls toisp4_capture_remove()and to the error path inisp4_capture_probe().
- Removed stray semicolons following closing curly braces.
- Improved and clarified macro definitions inisp4_interface.h.
- Eliminated unnecessary (u8 *) casts.
- Added missing memset for firmware command structures inisp4sd_stop_stream().
- Excluded streams 2 and 3 fromISP4IF_FW_RESP_RB_IRQ_EN_MASK, preventing their activation in the interrupt enable register.
- Enhanced error handling to clean up kthreads in the event of startup failure.
- Corrected a race condition during kthread creation where waitqueue head initialization could be delayed, as it was performed by the kthread itself.
- Removed status checks inisp4sd_pwroff_and_deinit()that were always false.
- Ensuredisp4sd_init_stream()is only invoked once per stream start and reordered corresponding status checks inisp4sd_start_stream().
- Improved error handling inisp4sd_start_stream()to propagate errors from failed functions.
- Relocated debugging messages inisp4sd_stop_stream()to execute under lock protection due to access tooutput_info->start_status.
- Eliminated redundantGET_REG_BASE()macros.
- Removedisp4sd_is_stream_running()function.
- Corrected error message inisp4sd_init_stream()caused by copy/paste.
- Refined structisp4_interfaceto remove firmware ring buffer configurations.
- Removed obsoleteisp4sd_is_stream_runningfunction.
- Removed pdev member from structisp4_device, as it is unnecessary.
- Fixed typo in 'isp_mmip' parameter name withinisp4if_init().
- Removed gap in structisp4_subdevdefinition.
- Performed extensive dead code removal and minor style improvements throughout the codebase.Changes v4 -> v5:
- Transitioned
VIDEOBUF2_V4L2from 'depends' to 'select' withinKconfig.
- Standardized object file naming conventions in theMakefileand sorted entries alphabetically.
- Removed the unused macro definitionto_isp4_device.
- Eliminated unused membersmem_domainandmem_alignfrom structisp4if_gpu_mem_info.
- Deleted unused fieldsmc_addrandgpu_pkgfrom structisp4if_cmd_element.
- Removed obsoletepltf_data,i2c_nb, and notifier elements from structisp4_device.
- Updatedplatform_get_irqfailure handling to return its actual result rather than-ENODEV.
- Refined inclusion of header files for clarity and efficiency.
- Appended comments following #endif statements in header files.
- Improved implementation ofisp4if_gpu_mem_freeandisp4if_dealloc_fw_gpumem.
- Removedisp4if_append_cmd_2_cmdqand revisedisp4if_send_fw_cmdaccordingly.
- Enhancedisp4if_clear_cmdqandisp4if_clear_bufqby eliminating unnecessarylist_deloperations.
- Adopted completion mechanism instead of wait queue and condition for command completion notifications.
- Employed memset to ensure proper zeroing of padding bits in structures shared between ISP driver and firmware.
- Streamlined IRQs, reducing total from four to two, retaining only essential ones.
- Optimized IRQ handler logic using a while loop for greater efficiency.
- Introduced dynamic IRQ enable/disable functionality based on camera status (open/close).
- Applied distinct identifiers to differentiate multiple threads and IRQs.
- Removed unnecessary initialization of local variables.
- Refined camera start/stop workflow to mitigate potential synchronization concerns.
- Replaced all remaining mutex with guard mutex.
- Enhanced command and buffer queue performance by substituting mutexes with spinlocks.
- Removed redundantisp4sd_init_meta_buffunction and its references.
- Limited firmware logging activities to the stream1 thread.
- Relocatedv4l2_device_unregister_subdev()andmedia_entity_cleanup()calls fromisp4_capture_removetoisp4sd_deinit.
- Resolved media device registration sequence issues.
- Modified stream processing thread behavior to await IRQ without a timeout.
- Addressed cleanup procedures in video device initialization and deinitialization routines.
- Corrected typos and made other cosmetic improvements.Changes v3 -> v4:
- Replace one mutex with guard mutex.
- Remove unnecessarybus_infoinitialization ofv4l2_capability.
- DropV4L2_CAP_IO_MCfrom capabilities ofv4l2_capability.
- Modify document with better SOC description.
- Fix Test x86 failure in Media CI test https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/83470456/artifacts/report.htm
- Modify some commit messages by describing changes in imperative mood.
- Add media-ctl output in cover letter.
- Create separated dedicated amdgpu patch to add declarationMODULE_FIRMWARE("amdgpu/isp_4_1_1.bin");
- Fix typo errors and other cosmetic issues.
- AddDRM_AMD_ISPdependency inKconfig.Changes v2 -> v3:
- All the dependent patches in other modules (drm/amd/amdgpu, platform/x86, pinctrl/amd) merged on upstream mainline kernel (https://github.com/torvalds/linux) v6.17.
- Removed usage of amdgpu structs in ISP driver. Added helper functions in amdgpu accepting opaque params from ISP driver to allocate and release ISP GART buffers.
- Moved sensor and MIPI phy control entirely into ISP FW instead of the previous hybrid approach controlling sensor from both FW and x86 (sensor driver).
- Removed phy configuration and sensor binding as x86 (sensor driver) had relinquished the sensor control for ISP FW. With this approach the driver will be exposed as web camera like interface.
- New FW with built-in sensor driver is submitted on upstream linux-firmware repo (https://gitlab.com/kernel-firmware/linux-firmware/).
- Please note the new FW submitted is not directly compatible with OEM Kernel ISP4.0 (https://github.com/amd/Linux_ISP_Kernel/tree/4.0) and the previous ISP V2 patch series.
- If intend to use the new FW, please rebuild OEM ISP4.0 Kernel withCONFIG_VIDEO_OV05C10=NandCONFIG_PINCTRL_AMDISP=Y.
- Included critical fixes from Sultan Alsawaf branch (https://github.com/kerneltoast/kernel_x86_laptop.git) related to managing lifetime of isp buffers.
media: amd: isp4: Add missing refcount tracking to mmap memop
media: amd: isp4: Don't put or unmap the dmabuf when detaching
media: amd: isp4: Don't increment refcount when dmabuf export fails
media: amd: isp4: Fix possible use-after-free inisp4vid_vb2_put()
media: amd: isp4: Always export a new dmabuf fromget_dmabufmemop
media: amd: isp4: Fix implicit dmabuf lifetime tracking
media: amd: isp4: Fix possible use-after-free when putting implicit dmabuf
media: amd: isp4: Simplifyisp4vid_get_dmabuf()arguments
media: amd: isp4: Move upbuf->vaddrcheck inisp4vid_get_dmabuf()
media: amd: isp4: Remove unused userptr memops
media: amd: isp4: Add missing cleanup on error inisp4vid_vb2_alloc()
media: amd: isp4: Release queued buffers on error instart_streaming
- Addressed all code related upstream comments
- Fix typo errors and other cosmetic issues.Changes v1 -> v2:
- Fix media CI test errors and valid warnings
- Reduce patch number in the series from 9 to 8 by mergingMAINTAINERSadding patch to the first patch
- In patch 5
- do modification to use remote endpoint instead of local endpoint
- use link frequency and port number as start phy parameter instead of extra added phy-id and phy-bit-rate property of endpoint----------
It passes v4l2 compliance test, the test reports for:
(a)
amd_isp_capturedevice/dev/video0Compliance test for
amd_isp_capturedevice/dev/video0:
-------------------------------------------------------atg@atg-HP-PV:~/bin$ ./v4l2-compliance -d /dev/video0 v4l2-compliance 1.29.0-5348, 64 bits, 64-bit time_t v4l2-compliance SHA: 75e3f0e2c2cb 2025-03-17 18:12:17Compliance test for
amd_isp_capturedevice/dev/video0:Driver Info:
Driver name : amd_isp_capture Card type : amd_isp_capture Bus info : platform:amd_isp_capture Driver version : 6.14.0 Capabilities : 0xa4200001Video Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps :0x24200001
Video Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:Driver name : amd_isp_capture Model : amd_isp41_mdev Serial : Bus info : platform:amd_isp_capture Media version : 6.14.0 Hardware revision: 0x00000000 (0) Driver version : 6.14.0Interface Info:
ID :0x03000005
Type : V4L Video
Entity Info:ID : 0x00000003 (3) Name : Preview Function : V4L2 I/O Pad 0x01000004 : 0: Sink Link 0x02000007: from remote pad 0x1000002 of entity 'amd isp4' (Image Signal Processor): Data, Enabled, ImmutableRequired ioctls:
test MC information (see 'Media Driver Info' above): OK testVIDIOC_QUERYCAP: OK
test invalid ioctls: OKAllow for multiple opens:
test second/dev/video0open: OK testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_LOG_STATUS: OK (Not Supported)Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) testVIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
testVIDIOC_G_FBUF: OK (Not Supported) testVIDIOC_G_FMT: OK
testVIDIOC_TRY_FMT: OK
testVIDIOC_S_FMT: OK
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK testCREATE_BUFSmaximum buffers: OK testVIDIOC_REMOVE_BUFS: OK
testVIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OKTotal for
amd_isp_capturedevice/dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0The media-ctl output of media device
/dev/media0:
-------------------------------------------------------atg@atg-HP-PV:~$ media-ctl -p -d /dev/media0 Media controller API version 6.17.0Media device information
------------------------
driveramd_isp_capture
modelamd_isp41_mdev
serialbus info platform:amd_isp_capture hw revision 0x0 driver version 6.17.0Device topology
- entity 1: amd isp4 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "Preview":0 [ENABLED,IMMUTABLE]- entity 3: Preview (1 pad, 1 link)
type Node subtype V4L flags 0 device node name/dev/video0
pad0: Sink
<- "amd isp4":0 [ENABLED,IMMUTABLE]Please review and provide feedback.
Many thanks,
Bin Du (7):
media: platform: amd: Introduce amd isp4 capture driver
media: platform: amd: low level support for isp4 firmware
media: platform: amd: Add isp4 fw and hw interface
media: platform: amd: isp4 subdev and firmware loading handling added
media: platform: amd: isp4 video node and buffers handling added
media: platform: amd: isp4 debug fs logging and more descriptive
errors
Documentation: add documentation of AMD isp 4 driverDocumentation/admin-guide/media/amdisp4-1.rst | 63 + Documentation/admin-guide/media/amdisp4.dot | 6 + .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 25 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 + drivers/media/platform/amd/isp4/Makefile | 10 + drivers/media/platform/amd/isp4/isp4.c | 234 ++++ drivers/media/platform/amd/isp4/isp4.h | 20 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++ drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++ .../media/platform/amd/isp4/isp4_interface.c | 787 +++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++ drivers/media/platform/amd/isp4/isp4_subdev.c | 1087 ++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 130 ++ drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 22 files changed, 4498 insertions(+)create mode 100644
Documentation/admin-guide/media/amdisp4-1.rstcreate mode 100644Documentation/admin-guide/media/amdisp4.dotcreate mode 100644drivers/media/platform/amd/Kconfigcreate mode 100644drivers/media/platform/amd/Makefilecreate mode 100644drivers/media/platform/amd/isp4/Kconfigcreate mode 100644drivers/media/platform/amd/isp4/Makefilecreate mode 100644drivers/media/platform/amd/isp4/isp4.ccreate mode 100644drivers/media/platform/amd/isp4/isp4.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.hQuoted 12 lines
create mode 100644
drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_hw_reg.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_video.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_video.hSignature · 1 line
2.34.1
Quoted 8 lines
Hi Bin,
I have attached a small patch with a fix for an old issue I noticed now while reading the v6 code and some remaining style nitpicks addressed. And some duplicated code on stream stop removed.
This is the last change from me, I promise. :)
Alright, I'll trust you the last time, LOL :) Never mind, they are small changes and every single one brings the code closer to perfection. I'll wait for feedback from other reviewers so I can incorporate them all into next version.
Quoted 3 lines
Otherwise, v6 is looking very good! Good catches with the error handling too, with the
irq_enabledflag andv4l2_device_register()error cleanup.
Yes, I believe so. I received two warnings from the Media CI checks; however, it appears that the issue is related to the CI system itself.
# Test static:test-smatchdrivers/media/platform/amd/isp4/isp4_interface.c:439 isp4if_send_fw_cmd() warn: '&ele->list' not removed from list
# Test static:test-coccinelle
./platform/amd/isp4/isp4_subdev.c:404:6-25: WARNING: atomic_dec_and_test variation before object free at line 405. ./i2c/ds90ub953.c:779:44-51: WARNING: Consider using %pe to print PTR_ERR()
...
If you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all
to this message.
Quoted 2 lines
Thanks,
Sultan
Signature · 2 lines
Regards, Bin
Quoted 362 lines · Bin
Quoted 359 lines · Sultan Alsawaf
Quoted 339 lines · Bin Du
Hello,
AMD ISP4 is the AMD image processing gen 4 which can be found in HP ZBook Ultra G1a 14 inch Mobile Workstation PC (Ryzen AI Max 300 Series)
(https://ubuntu.com/certified/202411-36043)
This patch series introduces the initial driver support for the AMD ISP4.Patch summary:
- Powers up/off and initializes ISP HW
- Configures and kicks off ISP FW
- Interacts with APP using standard V4l2 interface by video node
- Controls ISP HW and interacts with ISP FW to do image processing
- Supports enum/set output image format and resolution
- Supports queueing buffer from app and dequeuing ISP filled buffer to App
- It is verified on qv4l2, cheese and qcam
- It is verified together with following patchesplatform/x86: Add AMD ISP platform config (https://lore.kernel.org/all/[email protected]/) pinctrl: amd: isp411: Add amdisp GPIO pinctrl (https://github.com/torvalds/linux/commit/e97435ab09f3ad7b6a588dd7c4e45a96699bbb4a) drm/amd/amdgpu: Add GPIO resources required for amdisp (https://gitlab.freedesktop.org/agd5f/linux/-/commit/ad0f5966ed8297aa47b3184192b00b7379ae0758) drm/amd/amdgpu: Declare isp firmware binary file (https://gitlab.freedesktop.org/agd5f/linux/-/commit/35345917bc9f7c86152b270d9d93c220230b667f)AMD ISP4 Key features:
- Processes bayer raw data from the connected sensor and output them to different YUV formats
- Downscale input image to different output image resolution
- Pipeline to do image processing on the input image including demosaic, denoise, 3A, etc.----------
Changes v5 -> v6:
- Lowered FW mempool buffer size from 200M to 100M (actual usage).
- Added anirq_enabledmember to the ISP subdev for proper IRQ disable handling in both normal and error cases.
- Removed unnecessary .owner assignment fromisp4_capture_drvdefinition
- Updated IRQ handling to enable and disable interrupts via the ISP register for improved performance.
- Revised ring buffer management inisp4if_f2h_resp(), addressing safety checks to ensure the read pointer is validated before memcpy operations, reducing the risk of out-of-bounds access. The ring buffer logic was also streamlined significantly.
- Modified ring buffer handling inisp4if_is_cmdq_rb_full(), correcting an off-by-one error in safety checks that previously allowedrd_ptrto equalwr_ptrwhen the buffer was full.
- Refactored ring buffer handling inisp4if_insert_isp_fw_cmd(), simplifying overall logic.
- Resolved a regression from v4 to v5 whereisp4if_dequeue_buffer()did not protectlist_delwithbufq_lock.
- Addressed a subtle use-after-free issue that could occur if a timeout on a synchronous command coincided with completion.
- Added missingpm_runtime_disable()calls toisp4_capture_remove()and to the error path inisp4_capture_probe().
- Removed stray semicolons following closing curly braces.
- Improved and clarified macro definitions inisp4_interface.h.
- Eliminated unnecessary (u8 *) casts.
- Added missing memset for firmware command structures inisp4sd_stop_stream().
- Excluded streams 2 and 3 fromISP4IF_FW_RESP_RB_IRQ_EN_MASK, preventing their activation in the interrupt enable register.
- Enhanced error handling to clean up kthreads in the event of startup failure.
- Corrected a race condition during kthread creation where waitqueue head initialization could be delayed, as it was performed by the kthread itself.
- Removed status checks inisp4sd_pwroff_and_deinit()that were always false.
- Ensuredisp4sd_init_stream()is only invoked once per stream start and reordered corresponding status checks inisp4sd_start_stream().
- Improved error handling inisp4sd_start_stream()to propagate errors from failed functions.
- Relocated debugging messages inisp4sd_stop_stream()to execute under lock protection due to access tooutput_info->start_status.
- Eliminated redundantGET_REG_BASE()macros.
- Removedisp4sd_is_stream_running()function.
- Corrected error message inisp4sd_init_stream()caused by copy/paste.
- Refined structisp4_interfaceto remove firmware ring buffer configurations.
- Removed obsoleteisp4sd_is_stream_runningfunction.
- Removed pdev member from structisp4_device, as it is unnecessary.
- Fixed typo in 'isp_mmip' parameter name withinisp4if_init().
- Removed gap in structisp4_subdevdefinition.
- Performed extensive dead code removal and minor style improvements throughout the codebase.Changes v4 -> v5:
- Transitioned
VIDEOBUF2_V4L2from 'depends' to 'select' withinKconfig.
- Standardized object file naming conventions in theMakefileand sorted entries alphabetically.
- Removed the unused macro definitionto_isp4_device.
- Eliminated unused membersmem_domainandmem_alignfrom structisp4if_gpu_mem_info.
- Deleted unused fieldsmc_addrandgpu_pkgfrom structisp4if_cmd_element.
- Removed obsoletepltf_data,i2c_nb, and notifier elements from structisp4_device.
- Updatedplatform_get_irqfailure handling to return its actual result rather than-ENODEV.
- Refined inclusion of header files for clarity and efficiency.
- Appended comments following #endif statements in header files.
- Improved implementation ofisp4if_gpu_mem_freeandisp4if_dealloc_fw_gpumem.
- Removedisp4if_append_cmd_2_cmdqand revisedisp4if_send_fw_cmdaccordingly.
- Enhancedisp4if_clear_cmdqandisp4if_clear_bufqby eliminating unnecessarylist_deloperations.
- Adopted completion mechanism instead of wait queue and condition for command completion notifications.
- Employed memset to ensure proper zeroing of padding bits in structures shared between ISP driver and firmware.
- Streamlined IRQs, reducing total from four to two, retaining only essential ones.
- Optimized IRQ handler logic using a while loop for greater efficiency.
- Introduced dynamic IRQ enable/disable functionality based on camera status (open/close).
- Applied distinct identifiers to differentiate multiple threads and IRQs.
- Removed unnecessary initialization of local variables.
- Refined camera start/stop workflow to mitigate potential synchronization concerns.
- Replaced all remaining mutex with guard mutex.
- Enhanced command and buffer queue performance by substituting mutexes with spinlocks.
- Removed redundantisp4sd_init_meta_buffunction and its references.
- Limited firmware logging activities to the stream1 thread.
- Relocatedv4l2_device_unregister_subdev()andmedia_entity_cleanup()calls fromisp4_capture_removetoisp4sd_deinit.
- Resolved media device registration sequence issues.
- Modified stream processing thread behavior to await IRQ without a timeout.
- Addressed cleanup procedures in video device initialization and deinitialization routines.
- Corrected typos and made other cosmetic improvements.Changes v3 -> v4:
- Replace one mutex with guard mutex.
- Remove unnecessarybus_infoinitialization ofv4l2_capability.
- DropV4L2_CAP_IO_MCfrom capabilities ofv4l2_capability.
- Modify document with better SOC description.
- Fix Test x86 failure in Media CI test https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/83470456/artifacts/report.htm
- Modify some commit messages by describing changes in imperative mood.
- Add media-ctl output in cover letter.
- Create separated dedicated amdgpu patch to add declarationMODULE_FIRMWARE("amdgpu/isp_4_1_1.bin");
- Fix typo errors and other cosmetic issues.
- AddDRM_AMD_ISPdependency inKconfig.Changes v2 -> v3:
- All the dependent patches in other modules (drm/amd/amdgpu, platform/x86, pinctrl/amd) merged on upstream mainline kernel (https://github.com/torvalds/linux) v6.17.
- Removed usage of amdgpu structs in ISP driver. Added helper functions in amdgpu accepting opaque params from ISP driver to allocate and release ISP GART buffers.
- Moved sensor and MIPI phy control entirely into ISP FW instead of the previous hybrid approach controlling sensor from both FW and x86 (sensor driver).
- Removed phy configuration and sensor binding as x86 (sensor driver) had relinquished the sensor control for ISP FW. With this approach the driver will be exposed as web camera like interface.
- New FW with built-in sensor driver is submitted on upstream linux-firmware repo (https://gitlab.com/kernel-firmware/linux-firmware/).
- Please note the new FW submitted is not directly compatible with OEM Kernel ISP4.0 (https://github.com/amd/Linux_ISP_Kernel/tree/4.0) and the previous ISP V2 patch series.
- If intend to use the new FW, please rebuild OEM ISP4.0 Kernel withCONFIG_VIDEO_OV05C10=NandCONFIG_PINCTRL_AMDISP=Y.
- Included critical fixes from Sultan Alsawaf branch (https://github.com/kerneltoast/kernel_x86_laptop.git) related to managing lifetime of isp buffers.
media: amd: isp4: Add missing refcount tracking to mmap memop
media: amd: isp4: Don't put or unmap the dmabuf when detaching
media: amd: isp4: Don't increment refcount when dmabuf export fails
media: amd: isp4: Fix possible use-after-free inisp4vid_vb2_put()
media: amd: isp4: Always export a new dmabuf fromget_dmabufmemop
media: amd: isp4: Fix implicit dmabuf lifetime tracking
media: amd: isp4: Fix possible use-after-free when putting implicit dmabuf
media: amd: isp4: Simplifyisp4vid_get_dmabuf()arguments
media: amd: isp4: Move upbuf->vaddrcheck inisp4vid_get_dmabuf()
media: amd: isp4: Remove unused userptr memops
media: amd: isp4: Add missing cleanup on error inisp4vid_vb2_alloc()
media: amd: isp4: Release queued buffers on error instart_streaming
- Addressed all code related upstream comments
- Fix typo errors and other cosmetic issues.Changes v1 -> v2:
- Fix media CI test errors and valid warnings
- Reduce patch number in the series from 9 to 8 by mergingMAINTAINERSadding patch to the first patch
- In patch 5
- do modification to use remote endpoint instead of local endpoint
- use link frequency and port number as start phy parameter instead of extra added phy-id and phy-bit-rate property of endpoint----------
It passes v4l2 compliance test, the test reports for:
(a)
amd_isp_capturedevice/dev/video0Compliance test for
amd_isp_capturedevice/dev/video0:
-------------------------------------------------------atg@atg-HP-PV:~/bin$ ./v4l2-compliance -d /dev/video0 v4l2-compliance 1.29.0-5348, 64 bits, 64-bit time_t v4l2-compliance SHA: 75e3f0e2c2cb 2025-03-17 18:12:17Compliance test for
amd_isp_capturedevice/dev/video0:Driver Info:
Driver name : amd_isp_capture Card type : amd_isp_capture Bus info : platform:amd_isp_capture Driver version : 6.14.0 Capabilities : 0xa4200001Video Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps :0x24200001
Video Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:Driver name : amd_isp_capture Model : amd_isp41_mdev Serial : Bus info : platform:amd_isp_capture Media version : 6.14.0 Hardware revision: 0x00000000 (0) Driver version : 6.14.0Interface Info:
ID :0x03000005
Type : V4L Video
Entity Info:ID : 0x00000003 (3) Name : Preview Function : V4L2 I/O Pad 0x01000004 : 0: Sink Link 0x02000007: from remote pad 0x1000002 of entity 'amd isp4' (Image Signal Processor): Data, Enabled, ImmutableRequired ioctls:
test MC information (see 'Media Driver Info' above): OK testVIDIOC_QUERYCAP: OK
test invalid ioctls: OKAllow for multiple opens:
test second/dev/video0open: OK testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_LOG_STATUS: OK (Not Supported)Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) testVIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
testVIDIOC_G_FBUF: OK (Not Supported) testVIDIOC_G_FMT: OK
testVIDIOC_TRY_FMT: OK
testVIDIOC_S_FMT: OK
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK testCREATE_BUFSmaximum buffers: OK testVIDIOC_REMOVE_BUFS: OK
testVIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OKTotal for
amd_isp_capturedevice/dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0The media-ctl output of media device
/dev/media0:
-------------------------------------------------------atg@atg-HP-PV:~$ media-ctl -p -d /dev/media0 Media controller API version 6.17.0Media device information
------------------------
driveramd_isp_capture
modelamd_isp41_mdev
serialbus info platform:amd_isp_capture hw revision 0x0 driver version 6.17.0Device topology
- entity 1: amd isp4 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "Preview":0 [ENABLED,IMMUTABLE]- entity 3: Preview (1 pad, 1 link)
type Node subtype V4L flags 0 device node name/dev/video0
pad0: Sink
<- "amd isp4":0 [ENABLED,IMMUTABLE]Please review and provide feedback.
Many thanks,
Bin Du (7):
media: platform: amd: Introduce amd isp4 capture driver
media: platform: amd: low level support for isp4 firmware
media: platform: amd: Add isp4 fw and hw interface
media: platform: amd: isp4 subdev and firmware loading handling added
media: platform: amd: isp4 video node and buffers handling added
media: platform: amd: isp4 debug fs logging and more descriptive
errors
Documentation: add documentation of AMD isp 4 driverDocumentation/admin-guide/media/amdisp4-1.rst | 63 + Documentation/admin-guide/media/amdisp4.dot | 6 + .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 25 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 + drivers/media/platform/amd/isp4/Makefile | 10 + drivers/media/platform/amd/isp4/isp4.c | 234 ++++ drivers/media/platform/amd/isp4/isp4.h | 20 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++ drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++ .../media/platform/amd/isp4/isp4_interface.c | 787 +++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++ drivers/media/platform/amd/isp4/isp4_subdev.c | 1087 ++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 130 ++ drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 22 files changed, 4498 insertions(+)create mode 100644
Documentation/admin-guide/media/amdisp4-1.rstcreate mode 100644Documentation/admin-guide/media/amdisp4.dotcreate mode 100644drivers/media/platform/amd/Kconfigcreate mode 100644drivers/media/platform/amd/Makefilecreate mode 100644drivers/media/platform/amd/isp4/Kconfigcreate mode 100644drivers/media/platform/amd/isp4/Makefilecreate mode 100644drivers/media/platform/amd/isp4/isp4.ccreate mode 100644drivers/media/platform/amd/isp4/isp4.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.hQuoted 12 lines
create mode 100644
drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_hw_reg.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_video.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_video.hSignature · 1 line
2.34.1Hi Bin,
I have attached a small patch with a fix for an old issue I noticed now while reading the v6 code and some remaining style nitpicks addressed. And some duplicated code on stream stop removed.
Quoted 7 lines
Quoted 2 lines
This is the last change from me, I promise. :)
Alright, I'll trust you the last time, LOL :) Never mind, they are small changes and every single one brings the code closer to perfection. I'll wait for feedback from other reviewers so I can incorporate them all into next version.
Great, then maybe I'm not getting coal for xmas! :)
BTW, there is something else I noticed while making that patch: the min buffers handling seems a bit odd. q->min_queued_buffers is set to 2, but then there is ISP4SD_MIN_BUF_CNT_BEF_START_STREAM set to 4. Why isn't q->min_queued_buffers just set to 4 instead of using the macro?
And then what seems weirder is that isp4sd_ioc_send_img_buf() sends CMD_ID_START_STREAM once 4 buffers are queued. But isp4sd_ioc_send_img_buf() is called from the buf_queue callback, not the enable_streams callback, so why is it sending the stream start command to FW?
It looks like isp4sd_start_stream() will send CMD_ID_START_STREAM unless it was already done by isp4sd_ioc_send_img_buf(), so I'm wondering why isp4sd_ioc_send_img_buf() needs to do it at all, especially before the start_streaming callback (which is what indirectly calls enable_streams).
Also, when isp4sd_ioc_send_img_buf() is the one to send CMD_ID_START_STREAM, isp4sd_init_stream() and isp4sd_setup_output() will be skipped in isp4sd_start_stream(). Is it okay for those to be skipped? :\
Quoted 11 lines
Quoted 3 lines
Otherwise, v6 is looking very good! Good catches with the error handling too, with the
irq_enabledflag andv4l2_device_register()error cleanup.Yes, I believe so. I received two warnings from the Media CI checks; however, it appears that the issue is related to the CI system itself.
# Test static:test-smatch
drivers/media/platform/amd/isp4/isp4_interface.c:439isp4if_send_fw_cmd()
warn: '&ele->list' not removed from list
Quoted 8 lines
# Test static:test-coccinelle ./platform/amd/isp4/isp4_subdev.c:404:6-25: WARNING:
atomic_dec_and_testvariation before object free at line 405. ./i2c/ds90ub953.c:779:44-51: WARNING: Consider using %pe to printPTR_ERR()
...
If you believe that the CI is wrong, kindly open an issue at
/-/issues or reply-all
to this message.
Yes, both of those are false positives. The atomic_dec_and_test one is funny actually because it's just a refcount before freeing the object, which is a very normal thing, heh.
Thanks,
Sultan
Du, Bin
maintainerQuoted 366 lines · Sultan Alsawaf
Quoted 365 lines · Bin
Quoted 361 lines · Sultan Alsawaf
Quoted 339 lines · Bin Du
Hello,
AMD ISP4 is the AMD image processing gen 4 which can be found in HP ZBook Ultra G1a 14 inch Mobile Workstation PC (Ryzen AI Max 300 Series)
(https://ubuntu.com/certified/202411-36043)
This patch series introduces the initial driver support for the AMD ISP4.Patch summary:
- Powers up/off and initializes ISP HW
- Configures and kicks off ISP FW
- Interacts with APP using standard V4l2 interface by video node
- Controls ISP HW and interacts with ISP FW to do image processing
- Supports enum/set output image format and resolution
- Supports queueing buffer from app and dequeuing ISP filled buffer to App
- It is verified on qv4l2, cheese and qcam
- It is verified together with following patchesplatform/x86: Add AMD ISP platform config (https://lore.kernel.org/all/[email protected]/) pinctrl: amd: isp411: Add amdisp GPIO pinctrl (https://github.com/torvalds/linux/commit/e97435ab09f3ad7b6a588dd7c4e45a96699bbb4a) drm/amd/amdgpu: Add GPIO resources required for amdisp (https://gitlab.freedesktop.org/agd5f/linux/-/commit/ad0f5966ed8297aa47b3184192b00b7379ae0758) drm/amd/amdgpu: Declare isp firmware binary file (https://gitlab.freedesktop.org/agd5f/linux/-/commit/35345917bc9f7c86152b270d9d93c220230b667f)AMD ISP4 Key features:
- Processes bayer raw data from the connected sensor and output them to different YUV formats
- Downscale input image to different output image resolution
- Pipeline to do image processing on the input image including demosaic, denoise, 3A, etc.----------
Changes v5 -> v6:
- Lowered FW mempool buffer size from 200M to 100M (actual usage).
- Added anirq_enabledmember to the ISP subdev for proper IRQ disable handling in both normal and error cases.
- Removed unnecessary .owner assignment fromisp4_capture_drvdefinition
- Updated IRQ handling to enable and disable interrupts via the ISP register for improved performance.
- Revised ring buffer management inisp4if_f2h_resp(), addressing safety checks to ensure the read pointer is validated before memcpy operations, reducing the risk of out-of-bounds access. The ring buffer logic was also streamlined significantly.
- Modified ring buffer handling inisp4if_is_cmdq_rb_full(), correcting an off-by-one error in safety checks that previously allowedrd_ptrto equalwr_ptrwhen the buffer was full.
- Refactored ring buffer handling inisp4if_insert_isp_fw_cmd(), simplifying overall logic.
- Resolved a regression from v4 to v5 whereisp4if_dequeue_buffer()did not protectlist_delwithbufq_lock.
- Addressed a subtle use-after-free issue that could occur if a timeout on a synchronous command coincided with completion.
- Added missingpm_runtime_disable()calls toisp4_capture_remove()and to the error path inisp4_capture_probe().
- Removed stray semicolons following closing curly braces.
- Improved and clarified macro definitions inisp4_interface.h.
- Eliminated unnecessary (u8 *) casts.
- Added missing memset for firmware command structures inisp4sd_stop_stream().
- Excluded streams 2 and 3 fromISP4IF_FW_RESP_RB_IRQ_EN_MASK, preventing their activation in the interrupt enable register.
- Enhanced error handling to clean up kthreads in the event of startup failure.
- Corrected a race condition during kthread creation where waitqueue head initialization could be delayed, as it was performed by the kthread itself.
- Removed status checks inisp4sd_pwroff_and_deinit()that were always false.
- Ensuredisp4sd_init_stream()is only invoked once per stream start and reordered corresponding status checks inisp4sd_start_stream().
- Improved error handling inisp4sd_start_stream()to propagate errors from failed functions.
- Relocated debugging messages inisp4sd_stop_stream()to execute under lock protection due to access tooutput_info->start_status.
- Eliminated redundantGET_REG_BASE()macros.
- Removedisp4sd_is_stream_running()function.
- Corrected error message inisp4sd_init_stream()caused by copy/paste.
- Refined structisp4_interfaceto remove firmware ring buffer configurations.
- Removed obsoleteisp4sd_is_stream_runningfunction.
- Removed pdev member from structisp4_device, as it is unnecessary.
- Fixed typo in 'isp_mmip' parameter name withinisp4if_init().
- Removed gap in structisp4_subdevdefinition.
- Performed extensive dead code removal and minor style improvements throughout the codebase.Changes v4 -> v5:
- Transitioned
VIDEOBUF2_V4L2from 'depends' to 'select' withinKconfig.
- Standardized object file naming conventions in theMakefileand sorted entries alphabetically.
- Removed the unused macro definitionto_isp4_device.
- Eliminated unused membersmem_domainandmem_alignfrom structisp4if_gpu_mem_info.
- Deleted unused fieldsmc_addrandgpu_pkgfrom structisp4if_cmd_element.
- Removed obsoletepltf_data,i2c_nb, and notifier elements from structisp4_device.
- Updatedplatform_get_irqfailure handling to return its actual result rather than-ENODEV.
- Refined inclusion of header files for clarity and efficiency.
- Appended comments following #endif statements in header files.
- Improved implementation ofisp4if_gpu_mem_freeandisp4if_dealloc_fw_gpumem.
- Removedisp4if_append_cmd_2_cmdqand revisedisp4if_send_fw_cmdaccordingly.
- Enhancedisp4if_clear_cmdqandisp4if_clear_bufqby eliminating unnecessarylist_deloperations.
- Adopted completion mechanism instead of wait queue and condition for command completion notifications.
- Employed memset to ensure proper zeroing of padding bits in structures shared between ISP driver and firmware.
- Streamlined IRQs, reducing total from four to two, retaining only essential ones.
- Optimized IRQ handler logic using a while loop for greater efficiency.
- Introduced dynamic IRQ enable/disable functionality based on camera status (open/close).
- Applied distinct identifiers to differentiate multiple threads and IRQs.
- Removed unnecessary initialization of local variables.
- Refined camera start/stop workflow to mitigate potential synchronization concerns.
- Replaced all remaining mutex with guard mutex.
- Enhanced command and buffer queue performance by substituting mutexes with spinlocks.
- Removed redundantisp4sd_init_meta_buffunction and its references.
- Limited firmware logging activities to the stream1 thread.
- Relocatedv4l2_device_unregister_subdev()andmedia_entity_cleanup()calls fromisp4_capture_removetoisp4sd_deinit.
- Resolved media device registration sequence issues.
- Modified stream processing thread behavior to await IRQ without a timeout.
- Addressed cleanup procedures in video device initialization and deinitialization routines.
- Corrected typos and made other cosmetic improvements.Changes v3 -> v4:
- Replace one mutex with guard mutex.
- Remove unnecessarybus_infoinitialization ofv4l2_capability.
- DropV4L2_CAP_IO_MCfrom capabilities ofv4l2_capability.
- Modify document with better SOC description.
- Fix Test x86 failure in Media CI test https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/83470456/artifacts/report.htm
- Modify some commit messages by describing changes in imperative mood.
- Add media-ctl output in cover letter.
- Create separated dedicated amdgpu patch to add declarationMODULE_FIRMWARE("amdgpu/isp_4_1_1.bin");
- Fix typo errors and other cosmetic issues.
- AddDRM_AMD_ISPdependency inKconfig.Changes v2 -> v3:
- All the dependent patches in other modules (drm/amd/amdgpu, platform/x86, pinctrl/amd) merged on upstream mainline kernel (https://github.com/torvalds/linux) v6.17.
- Removed usage of amdgpu structs in ISP driver. Added helper functions in amdgpu accepting opaque params from ISP driver to allocate and release ISP GART buffers.
- Moved sensor and MIPI phy control entirely into ISP FW instead of the previous hybrid approach controlling sensor from both FW and x86 (sensor driver).
- Removed phy configuration and sensor binding as x86 (sensor driver) had relinquished the sensor control for ISP FW. With this approach the driver will be exposed as web camera like interface.
- New FW with built-in sensor driver is submitted on upstream linux-firmware repo (https://gitlab.com/kernel-firmware/linux-firmware/).
- Please note the new FW submitted is not directly compatible with OEM Kernel ISP4.0 (https://github.com/amd/Linux_ISP_Kernel/tree/4.0) and the previous ISP V2 patch series.
- If intend to use the new FW, please rebuild OEM ISP4.0 Kernel withCONFIG_VIDEO_OV05C10=NandCONFIG_PINCTRL_AMDISP=Y.
- Included critical fixes from Sultan Alsawaf branch (https://github.com/kerneltoast/kernel_x86_laptop.git) related to managing lifetime of isp buffers.
media: amd: isp4: Add missing refcount tracking to mmap memop
media: amd: isp4: Don't put or unmap the dmabuf when detaching
media: amd: isp4: Don't increment refcount when dmabuf export fails
media: amd: isp4: Fix possible use-after-free inisp4vid_vb2_put()
media: amd: isp4: Always export a new dmabuf fromget_dmabufmemop
media: amd: isp4: Fix implicit dmabuf lifetime tracking
media: amd: isp4: Fix possible use-after-free when putting implicit dmabuf
media: amd: isp4: Simplifyisp4vid_get_dmabuf()arguments
media: amd: isp4: Move upbuf->vaddrcheck inisp4vid_get_dmabuf()
media: amd: isp4: Remove unused userptr memops
media: amd: isp4: Add missing cleanup on error inisp4vid_vb2_alloc()
media: amd: isp4: Release queued buffers on error instart_streaming
- Addressed all code related upstream comments
- Fix typo errors and other cosmetic issues.Changes v1 -> v2:
- Fix media CI test errors and valid warnings
- Reduce patch number in the series from 9 to 8 by mergingMAINTAINERSadding patch to the first patch
- In patch 5
- do modification to use remote endpoint instead of local endpoint
- use link frequency and port number as start phy parameter instead of extra added phy-id and phy-bit-rate property of endpoint----------
It passes v4l2 compliance test, the test reports for:
(a)
amd_isp_capturedevice/dev/video0Compliance test for
amd_isp_capturedevice/dev/video0:
-------------------------------------------------------atg@atg-HP-PV:~/bin$ ./v4l2-compliance -d /dev/video0 v4l2-compliance 1.29.0-5348, 64 bits, 64-bit time_t v4l2-compliance SHA: 75e3f0e2c2cb 2025-03-17 18:12:17Compliance test for
amd_isp_capturedevice/dev/video0:Driver Info:
Driver name : amd_isp_capture Card type : amd_isp_capture Bus info : platform:amd_isp_capture Driver version : 6.14.0 Capabilities : 0xa4200001Video Capture
I/O MC
Streaming
Extended Pix Format
Device Capabilities
Device Caps :0x24200001
Video Capture
I/O MC
Streaming
Extended Pix Format
Media Driver Info:Driver name : amd_isp_capture Model : amd_isp41_mdev Serial : Bus info : platform:amd_isp_capture Media version : 6.14.0 Hardware revision: 0x00000000 (0) Driver version : 6.14.0Interface Info:
ID :0x03000005
Type : V4L Video
Entity Info:ID : 0x00000003 (3) Name : Preview Function : V4L2 I/O Pad 0x01000004 : 0: Sink Link 0x02000007: from remote pad 0x1000002 of entity 'amd isp4' (Image Signal Processor): Data, Enabled, ImmutableRequired ioctls:
test MC information (see 'Media Driver Info' above): OK testVIDIOC_QUERYCAP: OK
test invalid ioctls: OKAllow for multiple opens:
test second/dev/video0open: OK testVIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OKDebug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) testVIDIOC_LOG_STATUS: OK (Not Supported)Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) testVIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) testVIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) testVIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)Control ioctls (Input 0):
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) testVIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0Format ioctls (Input 0):
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
testVIDIOC_G_FBUF: OK (Not Supported) testVIDIOC_G_FMT: OK
testVIDIOC_TRY_FMT: OK
testVIDIOC_S_FMT: OK
testVIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)Codec ioctls (Input 0):
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) testVIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)Buffer ioctls (Input 0):
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK testCREATE_BUFSmaximum buffers: OK testVIDIOC_REMOVE_BUFS: OK
testVIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OKTotal for
amd_isp_capturedevice/dev/video0: 49, Succeeded: 49, Failed: 0, Warnings: 0The media-ctl output of media device
/dev/media0:
-------------------------------------------------------atg@atg-HP-PV:~$ media-ctl -p -d /dev/media0 Media controller API version 6.17.0Media device information
------------------------
driveramd_isp_capture
modelamd_isp41_mdev
serialbus info platform:amd_isp_capture hw revision 0x0 driver version 6.17.0Device topology
- entity 1: amd isp4 (1 pad, 1 link, 0 routes) type V4L2 subdev subtype Unknown flags 0
pad0: Source
-> "Preview":0 [ENABLED,IMMUTABLE]- entity 3: Preview (1 pad, 1 link)
type Node subtype V4L flags 0 device node name/dev/video0
pad0: Sink
<- "amd isp4":0 [ENABLED,IMMUTABLE]Please review and provide feedback.
Many thanks,
Bin Du (7):
media: platform: amd: Introduce amd isp4 capture driver
media: platform: amd: low level support for isp4 firmware
media: platform: amd: Add isp4 fw and hw interface
media: platform: amd: isp4 subdev and firmware loading handling added
media: platform: amd: isp4 video node and buffers handling added
media: platform: amd: isp4 debug fs logging and more descriptive
errors
Documentation: add documentation of AMD isp 4 driverDocumentation/admin-guide/media/amdisp4-1.rst | 63 + Documentation/admin-guide/media/amdisp4.dot | 6 + .../admin-guide/media/v4l-drivers.rst | 1 + MAINTAINERS | 25 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/amd/Kconfig | 3 + drivers/media/platform/amd/Makefile | 3 + drivers/media/platform/amd/isp4/Kconfig | 14 + drivers/media/platform/amd/isp4/Makefile | 10 + drivers/media/platform/amd/isp4/isp4.c | 234 ++++ drivers/media/platform/amd/isp4/isp4.h | 20 + drivers/media/platform/amd/isp4/isp4_debug.c | 271 ++++ drivers/media/platform/amd/isp4/isp4_debug.h | 41 + .../platform/amd/isp4/isp4_fw_cmd_resp.h | 314 +++++ drivers/media/platform/amd/isp4/isp4_hw_reg.h | 124 ++ .../media/platform/amd/isp4/isp4_interface.c | 787 +++++++++++ .../media/platform/amd/isp4/isp4_interface.h | 140 ++ drivers/media/platform/amd/isp4/isp4_subdev.c | 1087 ++++++++++++++++ drivers/media/platform/amd/isp4/isp4_subdev.h | 130 ++ drivers/media/platform/amd/isp4/isp4_video.c | 1158 +++++++++++++++++ drivers/media/platform/amd/isp4/isp4_video.h | 65 + 22 files changed, 4498 insertions(+)create mode 100644
Documentation/admin-guide/media/amdisp4-1.rstcreate mode 100644Documentation/admin-guide/media/amdisp4.dotcreate mode 100644drivers/media/platform/amd/Kconfigcreate mode 100644drivers/media/platform/amd/Makefilecreate mode 100644drivers/media/platform/amd/isp4/Kconfigcreate mode 100644drivers/media/platform/amd/isp4/Makefilecreate mode 100644drivers/media/platform/amd/isp4/isp4.ccreate mode 100644drivers/media/platform/amd/isp4/isp4.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_debug.hQuoted 12 lines
create mode 100644
drivers/media/platform/amd/isp4/isp4_fw_cmd_resp.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_hw_reg.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_interface.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_subdev.hcreate mode 100644drivers/media/platform/amd/isp4/isp4_video.ccreate mode 100644drivers/media/platform/amd/isp4/isp4_video.hSignature · 1 line
2.34.1Hi Bin,
I have attached a small patch with a fix for an old issue I noticed now while reading the v6 code and some remaining style nitpicks addressed. And some duplicated code on stream stop removed.
This is the last change from me, I promise. :)
Quoted 7 lines
Quoted 4 lines
Alright, I'll trust you the last time, LOL :) Never mind, they are small changes and every single one brings the code closer to perfection. I'll wait for feedback from other reviewers so I can incorporate them all into next version.
Great, then maybe I'm not getting coal for xmas! :)
Of course you won't, you've earned toys and candy to enjoy the holiday:)
Quoted 5 lines
BTW, there is something else I noticed while making that patch: the min buffers handling seems a bit odd.
q->min_queued_buffersis set to 2, but then there isISP4SD_MIN_BUF_CNT_BEF_START_STREAMset to 4. Why isn'tq->min_queued_buffersjust set to 4 instead of using the macro?
According to the description of min_queued_buffers, the minimum number of queued buffers needed before @start_streaming can be called. VIDIOC_REQBUFS will ensure at least @min_queued_buffers + 1 buffers will be allocated. Since the ISP driver manages the buffering and streaming initiation process, the specific value of min_queued_buffers is not critical. Furthermore, given that ISP4SD_MIN_BUF_CNT_BEF_START_STREAM represents the minimum buffer count necessary for ISP FW functionality, the maximum value for min_queued_buffers is ISP4SD_MIN_BUF_CNT_BEF_START_STREAM - 1 (or 3). Therefore, min_queued_buffers can be set anywhere from 0 to 3; a median value of 2 has been selected. The actual buffer count is determined by isp4vid_qops_queue_setup.
Quoted 5 lines
And then what seems weirder is that
isp4sd_ioc_send_img_buf()sendsCMD_ID_START_STREAMonce 4 buffers are queued. Butisp4sd_ioc_send_img_buf()is called from thebuf_queuecallback, not theenable_streamscallback, so why is it sending the stream start command to FW?
Since ISP firmware requires 4 buffers to be sent before CMD_ID_START_STREAM, but the APP may send buffers and start streaming in any order, e.g. start stream->send buffer 0, 1, 2 ... or send buffer 0, 1, 2, ... -> start stream or send buffer 0 -> start stream->send buffer 1, 2 ..., or any more combinations, the ISP driver needs to handle all possible sequences. To ensure compatibility, isp4sd_ioc_send_img_buf is called both in isp4vid_qops_buffer_queue and isp4vid_qops_start_streaming(you might miss this).
Quoted 5 lines
It looks like
isp4sd_start_stream()will sendCMD_ID_START_STREAMunless it was already done byisp4sd_ioc_send_img_buf(), so I'm wondering whyisp4sd_ioc_send_img_buf()needs to do it at all, especially before thestart_streamingcallback (which is what indirectly callsenable_streams).
Please see the details below.
Quoted 4 lines
Also, when
isp4sd_ioc_send_img_buf()is the one to sendCMD_ID_START_STREAM,isp4sd_init_stream()andisp4sd_setup_output()will be skipped inisp4sd_start_stream(). Is it okay for those to be skipped? :\
No, isp4sd_init_stream() and isp4sd_setup_output() are always called. Let's consider the two simplest scenarios,
- APP sends buffer before starting stream
When ISP driver receives the buffers, isp4vid_qops_buffer_queue callback() is called, it just pushes the buffers to internal queue isp_vdev->buf_list without sending them to ISP FW because flag isp_vdev->stream_started is false
When ISP driver receives the start stream, isp4vid_qops_start_streaming() callback is called, inside it, v4l2_subdev_call(subdev, video, s_stream, 1); is called and causes isp4sd_enable_streams() to be called and in turn isp4sd_start_stream(), isp4sd_init_stream(), isp4sd_setup_output() are all called, after that, inside isp4vid_qops_start_streaming(), all queued buffers in isp_vdev->buf_list will be sent to ISP FW by send_buffer callback, inside send_buffer callback, when sent buffer count gets to ISP4SD_MIN_BUF_CNT_BEF_START_STREAM, CMD_ID_START_STREAM will be sent to ISP FW, after all buffers in isp_vdev->buf_list are sent, isp4vid_qops_start_streaming() will set isp_vdev->stream_started to true
- APP start stream before sending buffersisp4vid_qops_start_streaming()-> isp4sd_enable_streams()-> isp4sd_start_stream()-> isp4sd_init_stream()-> isp4sd_setup_output()-> set flag isp_vdev->stream_started to trueisp4vid_qops_buffer_queue()->directly send buffers to FW by send_buffer callback because isp_vdev->stream_started flag is true (if count gets to ISP4SD_MIN_BUF_CNT_BEF_START_STREAM, send CMD_ID_START_STREAM)->add buffer to queue isp_vdev->buf_list.
The logic is little complicated, I hope I make it clear, the basic idea is to ensure the required sequence to the ISP FW regardless of the order in which the APP sends buffers or starts the stream.
Quoted 20 lines
Quoted 11 lines
Quoted 3 lines
Otherwise, v6 is looking very good! Good catches with the error handling too, with the
irq_enabledflag andv4l2_device_register()error cleanup.Yes, I believe so. I received two warnings from the Media CI checks; however, it appears that the issue is related to the CI system itself.
# Test static:test-smatch
drivers/media/platform/amd/isp4/isp4_interface.c:439isp4if_send_fw_cmd()
warn: '&ele->list' not removed from listQuoted 8 lines
# Test static:test-coccinelle ./platform/amd/isp4/isp4_subdev.c:404:6-25: WARNING:
atomic_dec_and_testvariation before object free at line 405. ./i2c/ds90ub953.c:779:44-51: WARNING: Consider using %pe to printPTR_ERR()
...
If you believe that the CI is wrong, kindly open an issue at
/-/issues or reply-all
to this message.
Quoted 4 lines
Yes, both of those are false positives. The
atomic_dec_and_testone is funny actually because it's just a refcount before freeing the object, which is a very normal thing, heh.
Thanks for the confirmation!
Quoted 2 lines
Thanks,
Sultan
Signature · 2 lines
Regards, Bin