platform: tegra: rtcpu: Implement camera diagnostics driver

This commit expands the camera-diagnostics driver to add
support for ISP PFSD tests. The implementation:

- Adds diagnostics IVC communication between kernel and RCE firmware
- Implements ISP SDL test vector loading, verification, and execution
- Provides proper memory allocation and IOMMU mapping across devices
- Supports multiple ISP instances with chip-specific configurations
  (T234/ISP6 and T264/ISP7)
- Creates sysfs interface for diagnostic status reporting
- Adds proper error handling and resources cleanup
- Implements CRC validation for test vectors

The driver enables hardware safety diagnostics for camera subsystems
to ensure reliability and functional safety of the camera pipeline.

New header files:
- camrtc-diag-messages.h: Defines messages for IVC communication
- camrtc-diag.h: Contains common diagnostic data structures

Jira CAMERASW-32042

Change-Id: I9a892b40891cffc3d460723d9fdc92854c6cda85
Signed-off-by: Mohit Ingale <mohiti@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3313001
Reviewed-by: Vincent Chung <vincentc@nvidia.com>
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Semi Malinen <smalinen@nvidia.com>
Reviewed-by: Frank Chen <frankc@nvidia.com>
Reviewed-by: Bhushan Rayrikar <brayrikar@nvidia.com>
This commit is contained in:
Mohit Ingale
2025-03-03 22:55:14 +00:00
committed by Jon Hunter
parent 39392014e5
commit 0f10f5e639
3 changed files with 1667 additions and 28 deletions

View File

@@ -0,0 +1,281 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
/**
* @file camrtc-diag-messages.h
*
* @brief Diagnostic IVC messages
*/
#ifndef INCLUDE_CAMRTC_DIAG_MESSAGES_H
#define INCLUDE_CAMRTC_DIAG_MESSAGES_H
#include "soc/tegra/camrtc-common.h"
#include "soc/tegra/camrtc-capture.h"
#include "soc/tegra/camrtc-diag.h"
#pragma GCC diagnostic error "-Wpadded"
/**
* @defgroup DiagMsgType Message types for RCE diagnostics channel
* @{
*/
/**
* @brief ISP PFSD diagnostics setup request.
*
* This is a @ref DiagMsgType "diagnostic message" to
* set up ISP PFSD diagnostics and associated resources.
*
* @pre The @em diag IVC channel has been set up during
* boot using the @ref CAMRTC_HSP_CH_SETUP command.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ
* - @ref camrtc_diag_msg::transaction_id "transaction_id" = <em>unique ID</em>
*
* @par Payload
* - @ref camrtc_diag_isp5_sdl_setup_req
*
* @par Response
* - @ref CAMRTC_DIAG_ISP5_SDL_SETUP_RESP
*/
#define CAMRTC_DIAG_ISP5_SDL_SETUP_REQ MK_U32(0x01)
/**
* @brief ISP PFSD diagnostics setup response.
*
* This is a @ref DiaglMsgType "diagnostic message" received in
* response to a @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ message.
*
* @pre A @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ message has been sent.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_SETUP_RESP
* - @ref camrtc_diag_msg::transaction_id "transaction_id" =
* @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ@b::@ref camrtc_diag_msg " camrtc_diag_msg"@b::@ref camrtc_diag_msg::transaction_id "transaction_id"
*
* @par Payload
* - @ref camrtc_diag_isp5_sdl_setup_resp
*/
#define CAMRTC_DIAG_ISP5_SDL_SETUP_RESP MK_U32(0x02)
/**
* @brief ISP PFSD diagnostics release request.
*
* This is a @ref DiagMsgType "diagnostic message" to stop the
* ISP PFSD diagnostics and release the associated resources.
*
* @pre The ISP PFSD diagnostics has been set up with
* @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_REQ
* - @ref camrtc_diag_msg::transaction_id "transaction_id" = <em>unique ID</em>
*
* @par Payload
* - None
*
* @par Response
* - @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_RESP
*/
#define CAMRTC_DIAG_ISP5_SDL_RELEASE_REQ MK_U32(0x03)
/**
* @brief ISP PFSD diagnostics release response.
*
* This is a @ref DiaglMsgType "diagnostic message" received in
* response to a @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_REQ message.
*
* @pre A @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_REQ message has been sent.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_RESP
* - @ref camrtc_diag_msg::transaction_id "transaction_id" =
* @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_REQ@b::@ref camrtc_diag_msg " camrtc_diag_msg"@b::@ref camrtc_diag_msg::transaction_id "transaction_id"
*
* @par Payload
* - @ref camrtc_diag_isp5_sdl_release_resp
*/
#define CAMRTC_DIAG_ISP5_SDL_RELEASE_RESP MK_U32(0x04)
/**
* @brief ISP PFSD diagnostics status request.
*
* This is a @ref DiagMsgType "diagnostic message" to
* query the diagnostic status.
*
* @pre The ISP PFSD diagnostics has been set up with
* @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_STATUS_REQ
* - @ref camrtc_diag_msg::transaction_id "transaction_id" = <em>unique ID</em>
*
* @par Payload
* - None
*
* @par Response
* - @ref CAMRTC_DIAG_ISP5_SDL_STATUS_RESP
*/
#define CAMRTC_DIAG_ISP5_SDL_STATUS_REQ MK_U32(0x05)
/**
* @brief ISP PFSD diagnostics status response.
*
* This is a @ref DiaglMsgType "diagnostic message" received in
* response to a @ref CAMRTC_DIAG_ISP5_SDL_STATUS_REQ message.
*
* @pre A @ref CAMRTC_DIAG_ISP5_SDL_STATUS_REQ message has been sent.
*
* @par Header
* - @ref camrtc_diag_msg::msg_type "msg_type" = @ref CAMRTC_DIAG_ISP5_SDL_STATUS_RESP
* - @ref camrtc_diag_msg::transaction_id "transaction_id" =
* @ref CAMRTC_DIAG_ISP5_SDL_STATUS_REQ@b::@ref camrtc_diag_msg " camrtc_diag_msg"@b::@ref camrtc_diag_msg::transaction_id "transaction_id"
*
* @par Payload
* - @ref camrtc_diag_isp5_sdl_status_resp
*/
#define CAMRTC_DIAG_ISP5_SDL_STATUS_RESP MK_U32(0x06)
/**@}*/
/**
* @defgroup DiagResultCodes Diagnostics channel Result codes
* @{
*/
/** No errors detected. */
#define CAMRTC_DIAG_SUCCESS MK_U32(0x00)
/** Invalid argument. */
#define CAMRTC_DIAG_ERROR_INVAL MK_U32(0x01)
/** Action not supported. */
#define CAMRTC_DIAG_ERROR_NOTSUP MK_U32(0x02)
/** Device or resource busy. */
#define CAMRTC_DIAG_ERROR_BUSY MK_U32(0x03)
/** Timeout error. */
#define CAMRTC_DIAG_ERROR_TIMEOUT MK_U32(0x04)
/** Unknown error. */
#define CAMRTC_DIAG_ERROR_UNKNOWN MK_U32(0xFF)
/**@}*/
/** @brief Message data for @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ message */
struct camrtc_diag_isp5_sdl_setup_req {
/**
* Diagnostic test binary IOVA for RCE. See @ref isp5_sdl_header
* "Diagnostic test binary header". Must be non-zero and
* a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
iova_t rce_iova;
/**
* Diagnostic test binary IOVA for ISP. See @ref isp5_sdl_header
* "Diagnostic test binary header". Must be non-zero and
* a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
iova_t isp_iova;
/**
* Diagnostic test binary size.
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
uint32_t size;
/**
* Diagnostic Test Interval (ms) [1, UINT32_MAX].
* Should be set to FDTI/2.
*/
uint32_t period;
} CAMRTC_DIAG_IVC_ALIGN;
/** @brief Message data for @ref CAMRTC_DIAG_ISP5_SDL_SETUP_RESP message */
struct camrtc_diag_isp5_sdl_setup_resp {
/** @ref DiagResultCodes "Diagnostic request result code". */
uint32_t result;
/** Reserved. */
uint32_t pad32_[1];
} CAMRTC_DIAG_IVC_ALIGN;
/** @brief Message data for @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_RESP message */
struct camrtc_diag_isp5_sdl_release_resp {
/** @ref DiagResultCodes "Diagnostic request result code". */
uint32_t result;
/** Reserved. */
uint32_t pad32_[1];
} CAMRTC_DIAG_IVC_ALIGN;
/** @brief Message data for @ref CAMRTC_DIAG_ISP5_SDL_STATUS_RESP message */
struct camrtc_diag_isp5_sdl_status_resp {
/** @ref DiagResultCodes "Diagnostic request result code". */
uint32_t result;
/** Nonzero if PFSD tests are being scheduled. */
uint32_t running;
/** Number of tests that have been scheduled. */
uint64_t scheduled;
/** Number of tests that have been executed. */
uint64_t executed;
/** Number of tests that have been passed. */
uint64_t passed;
/** Number of CRC failures in tests. (Counter stops at UINT32_MAX.) */
uint32_t crc_failed;
/** Explicit padding */
uint32_t pad32_[1];
} CAMRTC_DIAG_IVC_ALIGN;
/**
* @brief Common message format for all diagnostic IVC messages.
*/
struct camrtc_diag_msg {
/** @ref MessageType "Message type". */
uint32_t msg_type;
/**
* Transaction ID associated with a request [0, UINT32_MAX]. The
* transaction in a response message must match the transaction ID
* of the associated request.
*/
uint32_t transaction_id;
union {
/** @anon_union_member */
/** Message data for @ref CAMRTC_DIAG_ISP5_SDL_SETUP_REQ message */
struct camrtc_diag_isp5_sdl_setup_req isp5_sdl_setup_req;
/** @anon_union_member */
/** Message data for @ref CAMRTC_DIAG_ISP5_SDL_SETUP_RESP message */
struct camrtc_diag_isp5_sdl_setup_resp isp5_sdl_setup_resp;
/** @anon_union_member */
/** Message data for @ref CAMRTC_DIAG_ISP5_SDL_RELEASE_RESP message */
struct camrtc_diag_isp5_sdl_release_resp isp5_sdl_release_resp;
/** @anon_union_member */
/** Message data for @ref CAMRTC_DIAG_ISP5_SDL_STATUS_RESP message */
struct camrtc_diag_isp5_sdl_status_resp isp5_sdl_status_resp;
};
} CAMRTC_DIAG_IVC_ALIGN;
#pragma GCC diagnostic ignored "-Wpadded"
#endif /* INCLUDE_CAMRTC_DIAG_MESSAGES_H */

View File

@@ -0,0 +1,171 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
/**
* @file camrtc-diag.h
*
* @brief Diagnostic channel definitions.
*/
#ifndef INCLUDE_CAMRTC_DIAG_H
#define INCLUDE_CAMRTC_DIAG_H
#include <soc/tegra/camrtc-common.h>
#pragma GCC diagnostic error "-Wpadded"
/** Diagnostic DMA alignment requirement */
#define CAMRTC_DIAG_DMA_ALIGN_BYTES 64
/** Diagnostic IVC message alignment */
#define CAMRTC_DIAG_IVC_ALIGNOF MK_ALIGN(8)
/** Diagnostic DMA alignment */
#define CAMRTC_DIAG_DMA_ALIGNOF MK_ALIGN(CAMRTC_DIAG_DMA_ALIGN_BYTES)
/** Diagnostic IVC message alignment specifier */
#define CAMRTC_DIAG_IVC_ALIGN CAMRTC_ALIGN(CAMRTC_DIAG_IVC_ALIGNOF)
/** Diagnostic DMA alignment specifier */
#define CAMRTC_DIAG_DMA_ALIGN CAMRTC_ALIGN(CAMRTC_DIAG_DMA_ALIGNOF)
/** Parameter unspecified. */
#define ISP5_SDL_PARAM_UNSPECIFIED MK_U32(0xFFFFFFFF)
/**
* @defgroup IspPfsdVersions "ISP PFSD test binary version numbers.
* @{
*/
/** Version number of the ISP5 PFSD test vector binary. */
#define CAMRTC_DIAG_IS5P_PFSD_VERSION MK_U32(1553727808)
/** Version number of the ISP6 PFSD test vector binary. */
#define CAMRTC_DIAG_ISP6_PFSD_VERSION MK_U32(1630655840)
/** @} */
/** Maximum number of diagnostic test vectors */
#define CAMRTC_DIAG_MAX_ISP_PFSDF_NUM_VECTORS MK_U32(40)
/**
* @brief Header of an ISP PFSD test binary in shared memory.
*
* The header structure describes the version and the contents of the
* test binary. The header is immediately followed by one or more
* @ref isp5_sdl_test_descriptor "test descriptors", input images, and
* finally memory allocations for various buffers. The offsets for each
* separate memory region are given in the header.
*/
struct isp5_sdl_header {
/** @ref IspPfsdVersions "ISP PFSD test binary version number" */
uint32_t version;
/**
* Number of test descriptors following this header
* [1, @ref CAMRTC_DIAG_MAX_ISP_PFSDF_NUM_VECTORS].
*/
uint32_t num_vectors;
/** CRC32 on binary payload [0, UINT32_MAX]. */
uint32_t payload_crc32;
/**
* Byte offset into the test payload after the header
* (includes header size) [sizeof(@ref isp5_sdl_header),
* @ref camrtc_diag_isp5_sdl_setup_req::size).
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
uint32_t payload_offset;
/**
* Byte offset from start of test payload to start of input images
* [sizeof(@ref isp5_sdl_test_descriptor) * @ref num_vectors,
* @ref camrtc_diag_isp5_sdl_setup_req::size - @ref payload_offset].
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
uint32_t input_base_offset;
/**
* Byte offset from start of test payload to start of pushbuffer2
* allocation [sizeof(@ref isp5_sdl_test_descriptor) * @ref num_vectors,
* @ref camrtc_diag_isp5_sdl_setup_req::size - @ref payload_offset].
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
uint32_t push_buffer2_offset;
/**
* Byte offset from start of test payload to start of memory buffers
* for the MW[0/1/2] output surfaces
* [sizeof(@ref isp5_sdl_test_descriptor) * @ref num_vectors,
* @ref camrtc_diag_isp5_sdl_setup_req::size - @ref payload_offset].
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
*/
uint32_t output_buffers_offset;
/** Reserved. */
uint32_t reserved__[9];
} CAMRTC_DIAG_DMA_ALIGN;
/**
* @brief isp5_sdl_test_descriptor - ISP5 SDL binary test descriptor
*/
struct isp5_sdl_test_descriptor {
/** Zero-index test number [0, @ref num_vectors-1]. */
uint32_t test_index;
/**
* Input image width in pixels (same for all inputs)
* [@ref ISP_MIN_STRIP_WIDTH, @ref ISP_MAX_STRIP_WIDTH].
*/
uint16_t input_width;
/**
* Input image height in pixels (same for all inputs)
* [@ref ISP_MIN_SLICE_HEIGHT, @ref ISP_MAX_SLICE_HEIGHT].
*/
uint16_t input_height;
/**
* Array of offsets to the test vector input images relative to
* @ref isp5_sdl_header::input_base_offset
* [0, @ref camrtc_diag_isp5_sdl_setup_req::size -
* @ref isp5_sdl_header::payload_offset -
* @ref isp5_sdl_header::input_base_offset].
* Must be a multiple of @ref CAMRTC_DIAG_DMA_ALIGN_BYTES.
* Offsets for surfaces 1 and 2 may also be set to
* @ref ISP5_SDL_PARAM_UNSPECIFIED.
*/
uint32_t input_offset[3];
/** Golden CRC32 values for MW0, MW1 and MW2 output [0, UINT32_MAX]. */
uint32_t output_crc32[3];
/** Reserved. */
uint32_t reserved__[7];
/**
* Populated ISP push buffer 1 size in dwords [0, 4096]
* (see @ref push_buffer1).
*/
uint32_t push_buffer1_size;
/** ISP push buffer 1 */
uint32_t push_buffer1[4096] CAMRTC_DIAG_DMA_ALIGN;
/** ISP config buffer. */
uint8_t config_buffer[128] CAMRTC_DIAG_DMA_ALIGN;
} CAMRTC_DIAG_DMA_ALIGN;
#pragma GCC diagnostic ignored "-Wpadded"
#endif /* INCLUDE_CAMRTC_DIAG_H */