Pārlūkot izejas kodu

msm: camera: common: Add hw mgr intf query cap v2

Add switch case to handle query cap v2 ioctl, and add query cap
v2 hw mgr intf function pointer to handle query cap v2.

CRs-Fixed: 3364267
Change-Id: I1f992982f8d06755c977839ee61ee450306d65a5
Signed-off-by: Petar Ivanov <[email protected]>
Signed-off-by: Sokchetra Eung <[email protected]>
Petar Ivanov 2 gadi atpakaļ
vecāks
revīzija
d82dbbff8a

+ 4 - 1
drivers/cam_core/cam_hw_mgr_intf.h

@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #ifndef _CAM_HW_MGR_INTF_H_
@@ -624,6 +624,8 @@ struct cam_hw_inject_evt_param {
  * @hw_mgr_priv:               HW manager object
  * @hw_get_caps:               Function pointer for get hw caps
  *                               args = cam_query_cap_cmd
+ * @hw_get_caps_v2:            Function pointer for get hw caps v2
+ *                               args = cam_query_cap_cmd_v2
  * @hw_acquire:                Function poniter for acquire hw resources
  *                               args = cam_hw_acquire_args
  * @hw_release:                Function pointer for release hw device resource
@@ -655,6 +657,7 @@ struct cam_hw_mgr_intf {
 	void *hw_mgr_priv;
 
 	int (*hw_get_caps)(void *hw_priv, void *hw_caps_args);
+	int (*hw_get_caps_v2)(void *hw_priv, void *hw_caps_args);
 	int (*hw_acquire)(void *hw_priv, void *hw_acquire_args);
 	int (*hw_release)(void *hw_priv, void *hw_release_args);
 	int (*hw_start)(void *hw_priv, void *hw_start_args);

+ 30 - 11
drivers/cam_core/cam_node.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/debugfs.h>
@@ -68,19 +68,37 @@ void cam_node_put_ctxt_to_free_list(struct kref *ref)
 	mutex_unlock(&node->list_mutex);
 }
 
-static int __cam_node_handle_query_cap(struct cam_node *node,
-	struct cam_query_cap_cmd *query)
+static int __cam_node_handle_query_cap(uint32_t version,
+	struct cam_node *node, struct cam_query_cap_cmd *query)
 {
-	int rc = -EFAULT;
+	struct cam_hw_mgr_intf *hw_mgr_intf = &node->hw_mgr_intf;
+	int rc = 0;
 
 	if (!query) {
 		CAM_ERR(CAM_CORE, "Invalid params");
 		return -EINVAL;
 	}
 
-	if (node->hw_mgr_intf.hw_get_caps) {
-		rc = node->hw_mgr_intf.hw_get_caps(
-			node->hw_mgr_intf.hw_mgr_priv, query);
+	switch (version) {
+	case CAM_QUERY_CAP:
+		if (!hw_mgr_intf->hw_get_caps) {
+			CAM_ERR(CAM_CORE, "Node %s query cap version: %u get hw cap intf is NULL",
+				node->name, version);
+			return -EINVAL;
+		}
+		rc = hw_mgr_intf->hw_get_caps(hw_mgr_intf->hw_mgr_priv, query);
+		break;
+	case CAM_QUERY_CAP_V2:
+		if (!hw_mgr_intf->hw_get_caps_v2) {
+			CAM_ERR(CAM_CORE, "Node %s query cap version: %u get hw cap intf is NULL",
+				node->name, version);
+			return -EINVAL;
+		}
+		rc = hw_mgr_intf->hw_get_caps_v2(hw_mgr_intf->hw_mgr_priv, query);
+		break;
+	default:
+		CAM_ERR(CAM_CORE, "Invalid version number %u", version);
+		return -EINVAL;
 	}
 
 	return rc;
@@ -752,7 +770,9 @@ int cam_node_handle_ioctl(struct cam_node *node, struct cam_control *cmd)
 	CAM_DBG(CAM_CORE, "handle cmd %d", cmd->op_code);
 
 	switch (cmd->op_code) {
-	case CAM_QUERY_CAP: {
+	case CAM_QUERY_CAP:
+		fallthrough;
+	case CAM_QUERY_CAP_V2: {
 		struct cam_query_cap_cmd query;
 
 		if (copy_from_user(&query, u64_to_user_ptr(cmd->handle),
@@ -761,15 +781,14 @@ int cam_node_handle_ioctl(struct cam_node *node, struct cam_control *cmd)
 			break;
 		}
 
-		rc = __cam_node_handle_query_cap(node, &query);
+		rc = __cam_node_handle_query_cap(cmd->op_code, node, &query);
 		if (rc) {
 			CAM_ERR(CAM_CORE, "querycap is failed(rc = %d)",
 				rc);
 			break;
 		}
 
-		if (copy_to_user(u64_to_user_ptr(cmd->handle), &query,
-			sizeof(query)))
+		if (copy_to_user(u64_to_user_ptr(cmd->handle), &query, sizeof(query)))
 			rc = -EFAULT;
 
 		break;

+ 8 - 1
drivers/cam_cre/cam_cre_hw_mgr/cam_cre_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/mutex.h>
@@ -1668,6 +1668,13 @@ static int cam_cre_mgr_get_hw_caps(void *hw_priv, void *hw_caps_args)
 		return -EINVAL;
 	}
 
+	if (sizeof(struct cam_cre_query_cap_cmd) != query_cap->size) {
+		CAM_ERR(CAM_CRE,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query_cap->size, sizeof(struct cam_cre_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	hw_mgr = hw_priv;
 	mutex_lock(&hw_mgr->hw_mgr_mutex);
 	if (copy_from_user(&hw_mgr->cre_caps,

+ 9 - 3
drivers/cam_cust/cam_custom_hw_mgr/cam_custom_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/slab.h>
@@ -26,8 +26,7 @@
 
 static struct cam_custom_hw_mgr g_custom_hw_mgr;
 
-static int cam_custom_mgr_get_hw_caps(void *hw_mgr_priv,
-	void *hw_caps_args)
+static int cam_custom_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args)
 {
 	int rc = 0;
 	struct cam_custom_hw_mgr          *hw_mgr = hw_mgr_priv;
@@ -36,6 +35,13 @@ static int cam_custom_mgr_get_hw_caps(void *hw_mgr_priv,
 	struct cam_hw_info                *cam_custom_hw;
 	struct cam_hw_soc_info            *soc_info_hw;
 
+	if (sizeof(struct cam_custom_query_cap_cmd) != query->size) {
+		CAM_ERR(CAM_CUSTOM,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query->size, sizeof(struct cam_custom_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	cam_custom_hw = (struct cam_hw_info *)
 		g_custom_hw_mgr.custom_hw[0]->hw_priv;
 	if (cam_custom_hw)

+ 8 - 1
drivers/cam_fd/fd_hw_mgr/cam_fd_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -1116,6 +1116,13 @@ static int cam_fd_mgr_hw_get_caps(void *hw_mgr_priv, void *hw_get_caps_args)
 	void __user *caps_handle =
 		u64_to_user_ptr(query->caps_handle);
 
+	if (sizeof(struct cam_fd_query_cap_cmd) != query->size) {
+		CAM_ERR(CAM_FD,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query->size, sizeof(struct cam_fd_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	if (copy_from_user(&query_fd, caps_handle,
 		sizeof(struct cam_fd_query_cap_cmd))) {
 		CAM_ERR(CAM_FD, "Failed in copy from user, rc=%d", rc);

+ 8 - 0
drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c

@@ -7146,6 +7146,13 @@ static int cam_icp_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args)
 		return -EINVAL;
 	}
 
+	if (sizeof(struct cam_icp_query_cap_cmd) != query_cap->size) {
+		CAM_ERR(CAM_ICP,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query_cap->size, sizeof(struct cam_icp_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	mutex_lock(&hw_mgr->hw_mgr_mutex);
 	if (copy_from_user(&hw_mgr->icp_caps,
 		u64_to_user_ptr(query_cap->caps_handle),
@@ -7689,6 +7696,7 @@ int cam_icp_hw_mgr_init(struct device_node *of_node, uint64_t *hw_mgr_hdl,
 			of_node, hw_mgr_intf);
 		return -EINVAL;
 	}
+	memset(hw_mgr_intf, 0, sizeof(struct cam_hw_mgr_intf));
 
 	hw_mgr = &icp_hw_mgr[device_idx];
 	hw_mgr->hw_mgr_id = device_idx;

+ 8 - 2
drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c

@@ -537,8 +537,7 @@ static inline void cam_ife_mgr_free_cdm_cmd(
 	*cdm_cmd = NULL;
 }
 
-static int cam_ife_mgr_get_hw_caps(void *hw_mgr_priv,
-	void *hw_caps_args)
+static int cam_ife_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args)
 {
 	int rc = 0;
 	int i;
@@ -553,6 +552,13 @@ static int cam_ife_mgr_get_hw_caps(void *hw_mgr_priv,
 
 	CAM_DBG(CAM_ISP, "enter");
 
+	if (sizeof(struct cam_isp_query_cap_cmd) != query->size) {
+		CAM_ERR(CAM_ISP,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query->size, sizeof(struct cam_isp_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	if (copy_from_user(&query_isp,
 		u64_to_user_ptr(query->caps_handle),
 		sizeof(struct cam_isp_query_cap_cmd))) {

+ 9 - 3
drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/slab.h>
@@ -174,8 +174,7 @@ static int cam_tfe_mgr_handle_reg_dump(struct cam_tfe_hw_mgr_ctx *ctx,
 	return rc;
 }
 
-static int cam_tfe_mgr_get_hw_caps(void *hw_mgr_priv,
-	void *hw_caps_args)
+static int cam_tfe_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args)
 {
 	int rc = 0;
 	int i;
@@ -186,6 +185,13 @@ static int cam_tfe_mgr_get_hw_caps(void *hw_mgr_priv,
 
 	CAM_DBG(CAM_ISP, "enter");
 
+	if (sizeof(struct cam_isp_tfe_query_cap_cmd) != query->size) {
+		CAM_ERR(CAM_ISP,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query->size, sizeof(struct cam_isp_tfe_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	if (copy_from_user(&query_isp,
 		u64_to_user_ptr(query->caps_handle),
 		sizeof(struct cam_isp_tfe_query_cap_cmd))) {

+ 8 - 1
drivers/cam_jpeg/jpeg_hw/cam_jpeg_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/uaccess.h>
@@ -1560,6 +1560,13 @@ static int cam_jpeg_mgr_get_hw_caps(void *hw_mgr_priv, void *hw_caps_args)
 		return -EINVAL;
 	}
 
+	if (sizeof(struct cam_jpeg_query_cap_cmd) != query_cap->size) {
+		CAM_ERR(CAM_JPEG,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query_cap->size, sizeof(struct cam_jpeg_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	mutex_lock(&hw_mgr->hw_mgr_mutex);
 
 	if (copy_to_user(u64_to_user_ptr(query_cap->caps_handle),

+ 8 - 1
drivers/cam_ope/ope_hw_mgr/cam_ope_hw_mgr.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/uaccess.h>
@@ -2547,6 +2547,13 @@ static int cam_ope_mgr_get_hw_caps(void *hw_priv, void *hw_caps_args)
 		return -EINVAL;
 	}
 
+	if (sizeof(struct ope_query_cap_cmd) != query_cap->size) {
+		CAM_ERR(CAM_OPE,
+			"Input query cap size:%u does not match expected query cap size: %u",
+			query_cap->size, sizeof(struct ope_query_cap_cmd));
+		return -EFAULT;
+	}
+
 	hw_mgr = hw_priv;
 	mutex_lock(&hw_mgr->hw_mgr_mutex);
 	if (copy_from_user(&hw_mgr->ope_caps,