Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45e84a87 authored by Jeyaprakash Soundrapandian's avatar Jeyaprakash Soundrapandian Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: camera: util: Add support for generic blob command buffer" into dev/msm-4.9-camx

parents a32fc7b4 966dbf6f
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
@@ -182,3 +182,78 @@ int cam_packet_util_process_patches(struct cam_packet *packet,
	return rc;
}

int cam_packet_util_process_generic_cmd_buffer(
	struct cam_cmd_buf_desc *cmd_buf,
	cam_packet_generic_blob_handler blob_handler_cb, void *user_data)
{
	int       rc;
	uint64_t  cpu_addr;
	size_t    buf_size;
	uint32_t *blob_ptr;
	uint32_t  blob_type, blob_size, blob_block_size, len_read;

	if (!cmd_buf || !blob_handler_cb) {
		CAM_ERR(CAM_UTIL, "Invalid args %pK %pK",
			cmd_buf, blob_handler_cb);
		return -EINVAL;
	}

	if (!cmd_buf->length || !cmd_buf->size) {
		CAM_ERR(CAM_UTIL, "Invalid cmd buf size %d %d",
			cmd_buf->length, cmd_buf->size);
		return -EINVAL;
	}

	rc = cam_mem_get_cpu_buf(cmd_buf->mem_handle, &cpu_addr, &buf_size);
	if (rc || !cpu_addr || (buf_size == 0)) {
		CAM_ERR(CAM_UTIL, "Failed in Get cpu addr, rc=%d, cpu_addr=%pK",
			rc, cpu_addr);
		return rc;
	}

	blob_ptr = (uint32_t *)((uint8_t *)cpu_addr + cmd_buf->offset);

	CAM_DBG(CAM_UTIL,
		"GenericCmdBuffer cpuaddr=%pK, blobptr=%pK, len=%d",
		cpu_addr, blob_ptr, cmd_buf->length);

	len_read = 0;
	while (len_read < cmd_buf->length) {
		blob_type =
			((*blob_ptr) & CAM_GENERIC_BLOB_CMDBUFFER_TYPE_MASK) >>
			CAM_GENERIC_BLOB_CMDBUFFER_TYPE_SHIFT;
		blob_size =
			((*blob_ptr) & CAM_GENERIC_BLOB_CMDBUFFER_SIZE_MASK) >>
			CAM_GENERIC_BLOB_CMDBUFFER_SIZE_SHIFT;

		blob_block_size = sizeof(uint32_t) +
			(((blob_size + sizeof(uint32_t) - 1) /
			sizeof(uint32_t)) * sizeof(uint32_t));

		CAM_DBG(CAM_UTIL,
			"Blob type=%d size=%d block_size=%d len_read=%d total=%d",
			blob_type, blob_size, blob_block_size, len_read,
			cmd_buf->length);

		if (len_read + blob_block_size > cmd_buf->length) {
			CAM_ERR(CAM_UTIL, "Invalid Blob %d %d %d %d",
				blob_type, blob_size, len_read,
				cmd_buf->length);
			return -EINVAL;
		}

		len_read += blob_block_size;

		rc = blob_handler_cb(user_data, blob_type, blob_size,
			(uint8_t *)(blob_ptr + 1));
		if (rc) {
			CAM_ERR(CAM_UTIL, "Error in handling blob type %d %d",
				blob_type, blob_size);
			return rc;
		}

		blob_ptr += (blob_block_size / sizeof(uint32_t));
	}

	return 0;
}
+24 −0
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ struct cam_kmd_buf_info {
	uint32_t   used_bytes;
};

/* Generic Cmd Buffer blob callback function type */
typedef int (*cam_packet_generic_blob_handler)(void *user_data,
	uint32_t blob_type, uint32_t blob_size, uint8_t *blob_data);

/**
 * cam_packet_util_validate_packet()
 *
@@ -86,4 +90,24 @@ int cam_packet_util_get_kmd_buffer(struct cam_packet *packet,
int cam_packet_util_process_patches(struct cam_packet *packet,
	int32_t iommu_hdl);

/**
 * cam_packet_util_process_generic_cmd_buffer()
 *
 * @brief:              Process Generic Blob command buffer. This utility
 *                      function process the command buffer and calls the
 *                      blob_handle_cb callback for each blob that exists
 *                      in the command buffer.
 *
 * @cmd_buf:            Generic Blob Cmd Buffer handle
 * @blob_handler_cb:    Callback pointer to call for each blob exists in the
 *                      command buffer
 * @user_data:          User data to be passed while callback
 *
 * @return:             0: Success
 *                      Negative: Failure
 */
int cam_packet_util_process_generic_cmd_buffer(
	struct cam_cmd_buf_desc *cmd_buf,
	cam_packet_generic_blob_handler blob_handler_cb, void *user_data);

#endif /* _CAM_PACKET_UTIL_H_ */
+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,12 @@
#define CAM_HANDLE_USER_POINTER                 1
#define CAM_HANDLE_MEM_HANDLE                   2

/* Generic Blob CmdBuffer header properties */
#define CAM_GENERIC_BLOB_CMDBUFFER_SIZE_MASK    0xFFFFFF00
#define CAM_GENERIC_BLOB_CMDBUFFER_SIZE_SHIFT   8
#define CAM_GENERIC_BLOB_CMDBUFFER_TYPE_MASK    0xFF
#define CAM_GENERIC_BLOB_CMDBUFFER_TYPE_SHIFT   0

/**
 * struct cam_control - Structure used by ioctl control for camera
 *