Loading drivers/media/platform/msm/vidc_3x/msm_smem.c +377 −424 File changed.Preview size limit exceeded, changes collapsed. Show changes drivers/media/platform/msm/vidc_3x/msm_vidc.c +49 −71 Original line number Diff line number Diff line Loading @@ -221,9 +221,8 @@ struct buffer_info *get_registered_buf(struct msm_vidc_inst *inst, *plane = 0; list_for_each_entry(temp, &inst->registeredbufs.list, list) { for (i = 0; i < min(temp->num_planes, VIDEO_MAX_PLANES); i++) { bool ion_hndl_matches = temp->handle[i] ? msm_smem_compare_buffers(inst->mem_client, fd, temp->handle[i]->smem_priv) : false; bool dma_matches = msm_smem_compare_buffers(fd, temp->smem[i].dma_buf); bool device_addr_matches = device_addr == temp->device_addr[i]; bool contains_within = CONTAINS(temp->buff_off[i], Loading @@ -233,7 +232,7 @@ struct buffer_info *get_registered_buf(struct msm_vidc_inst *inst, temp->buff_off[i], temp->size[i]); if (!temp->inactive && (ion_hndl_matches || device_addr_matches) && (dma_matches || device_addr_matches) && (contains_within || overlaps)) { dprintk(VIDC_DBG, "This memory region is already mapped\n"); Loading @@ -254,7 +253,6 @@ static struct msm_smem *get_same_fd_buffer(struct msm_vidc_inst *inst, int fd) { struct buffer_info *temp; struct msm_smem *same_fd_handle = NULL; int i; if (!fd) Loading @@ -268,14 +266,13 @@ static struct msm_smem *get_same_fd_buffer(struct msm_vidc_inst *inst, int fd) mutex_lock(&inst->registeredbufs.lock); list_for_each_entry(temp, &inst->registeredbufs.list, list) { for (i = 0; i < min(temp->num_planes, VIDEO_MAX_PLANES); i++) { bool ion_hndl_matches = temp->handle[i] ? msm_smem_compare_buffers(inst->mem_client, fd, temp->handle[i]->smem_priv) : false; if (ion_hndl_matches && temp->mapped[i]) { bool dma_matches = msm_smem_compare_buffers(fd, temp->smem[i].dma_buf); if (dma_matches && temp->mapped[i]) { temp->same_fd_ref[i]++; dprintk(VIDC_INFO, "Found same fd buffer\n"); same_fd_handle = temp->handle[i]; same_fd_handle = &temp->smem[i]; break; } } Loading Loading @@ -367,23 +364,6 @@ static inline void repopulate_v4l2_buffer(struct v4l2_buffer *b, } } static struct msm_smem *map_buffer(struct msm_vidc_inst *inst, struct v4l2_plane *p, enum hal_buffer buffer_type) { struct msm_smem *handle = NULL; handle = msm_comm_smem_user_to_kernel(inst, p->reserved[0], p->reserved[1], buffer_type); if (!handle) { dprintk(VIDC_ERR, "%s: Failed to get device buffer address\n", __func__); return NULL; } return handle; } static inline enum hal_buffer get_hal_buffer_type( struct msm_vidc_inst *inst, struct v4l2_buffer *b) { Loading Loading @@ -518,17 +498,27 @@ int map_and_register_buf(struct msm_vidc_inst *inst, struct v4l2_buffer *b) same_fd_handle->device_addr + binfo->buff_off[i]; b->m.planes[i].m.userptr = binfo->device_addr[i]; binfo->mapped[i] = false; binfo->handle[i] = same_fd_handle; binfo->smem[i] = *same_fd_handle; } else { binfo->handle[i] = map_buffer(inst, &b->m.planes[i], get_hal_buffer_type(inst, b)); if (!binfo->handle[i]) { rc = -EINVAL; binfo->smem[i].buffer_type = binfo->type; binfo->smem[i].fd = binfo->fd[i]; binfo->smem[i].offset = binfo->buff_off[i]; binfo->smem[i].size = binfo->size[i]; rc = msm_smem_map_dma_buf(inst, &binfo->smem[i]); if (rc) { dprintk(VIDC_ERR, "%s: map failed.\n", __func__); goto exit; } /* increase refcount as we get both fbd and rbr */ rc = msm_smem_map_dma_buf(inst, &binfo->smem[i]); if (rc) { dprintk(VIDC_ERR, "%s: map failed..\n", __func__); goto exit; } binfo->mapped[i] = true; binfo->device_addr[i] = binfo->handle[i]->device_addr + binfo->device_addr[i] = binfo->smem[i].device_addr + binfo->buff_off[i]; b->m.planes[i].m.userptr = binfo->device_addr[i]; } Loading @@ -541,7 +531,7 @@ int map_and_register_buf(struct msm_vidc_inst *inst, struct v4l2_buffer *b) } dprintk(VIDC_DBG, "%s: [MAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, binfo, i, binfo->handle[i], __func__, binfo, i, binfo->smem[i], &binfo->device_addr[i], binfo->fd[i], binfo->buff_off[i], binfo->mapped[i]); } Loading Loading @@ -594,7 +584,7 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, for (i = 0; i < temp->num_planes; i++) { dprintk(VIDC_DBG, "%s: [UNMAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, temp, i, temp->handle[i], __func__, temp, i, temp->smem[i], &temp->device_addr[i], temp->fd[i], temp->buff_off[i], temp->mapped[i]); /* Loading @@ -606,17 +596,19 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, * For buffers which share the same fd, do not unmap and keep * the buffer info in registered list. */ if (temp->handle[i] && temp->mapped[i] && !temp->same_fd_ref[i]) { if (temp->mapped[i] && !temp->same_fd_ref[i]) { if (msm_smem_unmap_dma_buf(inst, &temp->smem[i])) dprintk(VIDC_DBG, "unmap failed..\n"); msm_comm_smem_free(inst, temp->handle[i]); &temp->smem[i]); } if (temp->same_fd_ref[i]) keep_node = true; else { temp->fd[i] = 0; temp->handle[i] = 0; //temp->smem[i] = 0; temp->device_addr[i] = 0; temp->uvaddr[i] = 0; } Loading Loading @@ -679,18 +671,14 @@ int output_buffer_cache_invalidate(struct msm_vidc_inst *inst, for (i = 0; i < binfo->num_planes; i++) { if (binfo->handle[i]) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_INVALIDATE); &binfo->smem[i], SMEM_CACHE_INVALIDATE); if (rc) { dprintk(VIDC_ERR, "%s: Failed to clean caches: %d\n", __func__, rc); return -EINVAL; } } else dprintk(VIDC_DBG, "%s: NULL handle for plane %d\n", __func__, i); } return 0; } Loading Loading @@ -812,14 +800,14 @@ int msm_vidc_release_buffers(void *instance, int buffer_type) if (bi->type == buffer_type) { list_del(&bi->list); for (i = 0; i < bi->num_planes; i++) { if (bi->handle[i] && bi->mapped[i]) { if (bi->mapped[i]) { dprintk(VIDC_DBG, "%s: [UNMAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, bi, i, bi->handle[i], __func__, bi, i, bi->smem[i], &bi->device_addr[i], bi->fd[i], bi->buff_off[i], bi->mapped[i]); msm_comm_smem_free(inst, bi->handle[i]); &bi->smem[i]); } } kfree(bi); Loading Loading @@ -881,10 +869,10 @@ int msm_vidc_qbuf(void *instance, struct v4l2_buffer *b) &binfo->device_addr[i]); if (inst->fmts[OUTPUT_PORT].fourcc == V4L2_PIX_FMT_HEVC_HYBRID && binfo->handle[i] && V4L2_PIX_FMT_HEVC_HYBRID && b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_INVALIDATE); &binfo->smem[i], SMEM_CACHE_INVALIDATE); if (rc) { dprintk(VIDC_ERR, "Failed to inv caches: %d\n", rc); Loading @@ -892,10 +880,9 @@ int msm_vidc_qbuf(void *instance, struct v4l2_buffer *b) } } if (binfo->handle[i] && (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) { if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_CLEAN); &binfo->smem[i], SMEM_CACHE_CLEAN); if (rc) { dprintk(VIDC_ERR, "Failed to clean caches: %d\n", rc); Loading Loading @@ -1223,12 +1210,6 @@ void *msm_vidc_open(int core_id, int session_type) i <= SESSION_MSG_INDEX(SESSION_MSG_END); i++) { init_completion(&inst->completions[i]); } inst->mem_client = msm_smem_new_client(SMEM_DMA, &inst->core->resources, session_type); if (!inst->mem_client) { dprintk(VIDC_ERR, "Failed to create memory client\n"); goto fail_mem_client; } if (session_type == MSM_VIDC_DECODER) { msm_vdec_inst_init(inst); Loading Loading @@ -1292,8 +1273,6 @@ void *msm_vidc_open(int core_id, int session_type) vb2_queue_release(&inst->bufq[CAPTURE_PORT].vb2_bufq); fail_bufq_capture: msm_comm_ctrl_deinit(inst); msm_smem_delete_client(inst->mem_client); fail_mem_client: DEINIT_MSM_VIDC_LIST(&inst->eosbufs); kfree(inst); inst = NULL; Loading Loading @@ -1407,8 +1386,8 @@ int msm_vidc_close(void *instance) for (i = 0; i < min(bi->num_planes, VIDEO_MAX_PLANES); i++) { if (bi->handle[i] && bi->mapped[i]) msm_comm_smem_free(inst, bi->handle[i]); if (bi->mapped[i]) msm_comm_smem_free(inst, &bi->smem[i]); } kfree(bi); Loading @@ -1427,7 +1406,6 @@ int msm_vidc_close(void *instance) "Failed to move video instance to uninit state\n"); msm_comm_session_clean(inst); msm_smem_delete_client(inst->mem_client); kref_put(&inst->kref, close_helper); return 0; Loading drivers/media/platform/msm/vidc_3x/msm_vidc_common.c +78 −119 Original line number Diff line number Diff line Loading @@ -811,9 +811,9 @@ static void handle_session_release_buf_done(enum hal_command_response cmd, mutex_lock(&inst->scratchbufs.lock); list_for_each_safe(ptr, next, &inst->scratchbufs.list) { buf = list_entry(ptr, struct internal_buf, list); if (address == (u32)buf->handle->device_addr) { dprintk(VIDC_DBG, "releasing scratch: %pa\n", &buf->handle->device_addr); if (address == buf->smem.device_addr) { dprintk(VIDC_DBG, "releasing scratch: %x\n", buf->smem.device_addr); buf_found = true; } } Loading @@ -822,9 +822,9 @@ static void handle_session_release_buf_done(enum hal_command_response cmd, mutex_lock(&inst->persistbufs.lock); list_for_each_safe(ptr, next, &inst->persistbufs.list) { buf = list_entry(ptr, struct internal_buf, list); if (address == (u32)buf->handle->device_addr) { dprintk(VIDC_DBG, "releasing persist: %pa\n", &buf->handle->device_addr); if (address == buf->smem.device_addr) { dprintk(VIDC_DBG, "releasing persist: %x\n", buf->smem.device_addr); buf_found = true; } } Loading Loading @@ -1442,8 +1442,8 @@ void validate_output_buffers(struct msm_vidc_inst *inst) list_for_each_entry(binfo, &inst->outputbufs.list, list) { if (binfo->buffer_ownership != DRIVER) { dprintk(VIDC_DBG, "This buffer is with FW %pa\n", &binfo->handle->device_addr); "This buffer is with FW %x\n", binfo->smem.device_addr); continue; } buffers_owned_by_driver++; Loading @@ -1462,7 +1462,6 @@ int msm_comm_queue_output_buffers(struct msm_vidc_inst *inst) { struct internal_buf *binfo; struct hfi_device *hdev; struct msm_smem *handle; struct vidc_frame_data frame_data = {0}; struct hal_buffer_requirements *output_buf, *extra_buf; int rc = 0; Loading Loading @@ -1492,13 +1491,12 @@ int msm_comm_queue_output_buffers(struct msm_vidc_inst *inst) list_for_each_entry(binfo, &inst->outputbufs.list, list) { if (binfo->buffer_ownership != DRIVER) continue; handle = binfo->handle; frame_data.alloc_len = output_buf->buffer_size; frame_data.filled_len = 0; frame_data.offset = 0; frame_data.device_addr = handle->device_addr; frame_data.device_addr = binfo->smem.device_addr; frame_data.flags = 0; frame_data.extradata_addr = handle->device_addr + frame_data.extradata_addr = binfo->smem.device_addr + output_buf->buffer_size; frame_data.buffer_type = HAL_BUFFER_OUTPUT; frame_data.extradata_size = extra_buf ? Loading Loading @@ -1980,17 +1978,17 @@ static int handle_multi_stream_buffers(struct msm_vidc_inst *inst, phys_addr_t dev_addr) { struct internal_buf *binfo; struct msm_smem *handle; struct msm_smem *smem; bool found = false; mutex_lock(&inst->outputbufs.lock); list_for_each_entry(binfo, &inst->outputbufs.list, list) { handle = binfo->handle; if (handle && dev_addr == handle->device_addr) { smem = &binfo->smem; if (smem && dev_addr == smem->device_addr) { if (binfo->buffer_ownership == DRIVER) { dprintk(VIDC_ERR, "FW returned same buffer: %pa\n", &dev_addr); "FW returned same buffer: %x\n", dev_addr); break; } binfo->buffer_ownership = DRIVER; Loading @@ -2002,8 +2000,8 @@ static int handle_multi_stream_buffers(struct msm_vidc_inst *inst, if (!found) { dprintk(VIDC_ERR, "Failed to find output buffer in queued list: %pa\n", &dev_addr); "Failed to find output buffer in queued list: %x\n", dev_addr); } return 0; Loading Loading @@ -3069,9 +3067,8 @@ static int set_output_buffers(struct msm_vidc_inst *inst, enum hal_buffer buffer_type) { int rc = 0; struct msm_smem *handle; struct internal_buf *binfo; u32 smem_flags = 0, buffer_size; struct internal_buf *binfo = NULL; u32 smem_flags = SMEM_UNCACHED, buffer_size; struct hal_buffer_requirements *output_buf, *extradata_buf; int i; struct hfi_device *hdev; Loading Loading @@ -3117,33 +3114,25 @@ static int set_output_buffers(struct msm_vidc_inst *inst, if (output_buf->buffer_size) { for (i = 0; i < output_buf->buffer_count_actual; i++) { handle = msm_comm_smem_alloc(inst, buffer_size, 1, smem_flags, buffer_type, 0); if (!handle) { dprintk(VIDC_ERR, "Failed to allocate output memory\n"); rc = -ENOMEM; goto err_no_mem; } rc = msm_comm_smem_cache_operations(inst, handle, SMEM_CACHE_CLEAN); if (rc) { dprintk(VIDC_WARN, "Failed to clean cache may cause undefined behavior\n"); } binfo = kzalloc(sizeof(*binfo), GFP_KERNEL); if (!binfo) { dprintk(VIDC_ERR, "Out of memory\n"); rc = -ENOMEM; goto fail_kzalloc; } binfo->handle = handle; rc = msm_comm_smem_alloc(inst, buffer_size, 1, smem_flags, buffer_type, 0, &binfo->smem); if (rc) { dprintk(VIDC_ERR, "Failed to allocate output memory\n"); goto err_no_mem; } binfo->buffer_type = buffer_type; binfo->buffer_ownership = DRIVER; dprintk(VIDC_DBG, "Output buffer address: %pa\n", &handle->device_addr); dprintk(VIDC_DBG, "Output buffer address: %#x\n", binfo->smem.device_addr); if (inst->buffer_mode_set[CAPTURE_PORT] == HAL_BUFFER_MODE_STATIC) { Loading @@ -3154,9 +3143,9 @@ static int set_output_buffers(struct msm_vidc_inst *inst, buffer_info.buffer_type = buffer_type; buffer_info.num_buffers = 1; buffer_info.align_device_addr = handle->device_addr; binfo->smem.device_addr; buffer_info.extradata_addr = handle->device_addr + binfo->smem.device_addr + output_buf->buffer_size; if (extradata_buf) buffer_info.extradata_size = Loading @@ -3177,10 +3166,10 @@ static int set_output_buffers(struct msm_vidc_inst *inst, } return rc; fail_set_buffers: msm_comm_smem_free(inst, &binfo->smem); err_no_mem: kfree(binfo); fail_kzalloc: msm_comm_smem_free(inst, handle); err_no_mem: return rc; } Loading Loading @@ -3258,10 +3247,6 @@ static bool reuse_internal_buffers(struct msm_vidc_inst *inst, mutex_lock(&buf_list->lock); list_for_each_entry(buf, &buf_list->list, list) { if (!buf->handle) { reused = false; break; } if (buf->buffer_type != buffer_type) continue; Loading @@ -3278,7 +3263,7 @@ static bool reuse_internal_buffers(struct msm_vidc_inst *inst, && buffer_type != HAL_BUFFER_INTERNAL_PERSIST_1) { rc = set_internal_buf_on_fw(inst, buffer_type, buf->handle, true); &buf->smem, true); if (rc) { dprintk(VIDC_ERR, "%s: session_set_buffers failed\n", Loading @@ -3299,9 +3284,8 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, struct hal_buffer_requirements *internal_bufreq, struct msm_vidc_list *buf_list) { struct msm_smem *handle; struct internal_buf *binfo; u32 smem_flags = 0; u32 smem_flags = SMEM_UNCACHED; int rc = 0; int i = 0; Loading @@ -3315,27 +3299,25 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, smem_flags |= SMEM_SECURE; for (i = 0; i < internal_bufreq->buffer_count_actual; i++) { handle = msm_comm_smem_alloc(inst, internal_bufreq->buffer_size, 1, smem_flags, internal_bufreq->buffer_type, 0); if (!handle) { dprintk(VIDC_ERR, "Failed to allocate scratch memory\n"); rc = -ENOMEM; goto err_no_mem; } binfo = kzalloc(sizeof(*binfo), GFP_KERNEL); if (!binfo) { dprintk(VIDC_ERR, "Out of memory\n"); rc = -ENOMEM; goto fail_kzalloc; } rc = msm_comm_smem_alloc(inst, internal_bufreq->buffer_size, 1, smem_flags, internal_bufreq->buffer_type, 0, &binfo->smem); if (rc) { dprintk(VIDC_ERR, "Failed to allocate scratch memory\n"); goto err_no_mem; } binfo->handle = handle; binfo->buffer_type = internal_bufreq->buffer_type; rc = set_internal_buf_on_fw(inst, internal_bufreq->buffer_type, handle, false); &binfo->smem, false); if (rc) goto fail_set_buffers; Loading @@ -3346,10 +3328,10 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, return rc; fail_set_buffers: msm_comm_smem_free(inst, &binfo->smem); err_no_mem: kfree(binfo); fail_kzalloc: msm_comm_smem_free(inst, handle); err_no_mem: return rc; } Loading Loading @@ -3578,7 +3560,7 @@ int msm_vidc_comm_cmd(void *instance, union msm_v4l2_cmd *cmd) struct vidc_frame_data data = {0}; struct hfi_device *hdev = NULL; struct eos_buf *binfo = NULL; u32 smem_flags = 0; u32 smem_flags = SMEM_UNCACHED; if (inst->state != MSM_VIDC_START_DONE) { dprintk(VIDC_DBG, Loading @@ -3603,8 +3585,16 @@ int msm_vidc_comm_cmd(void *instance, union msm_v4l2_cmd *cmd) if (inst->flags & VIDC_SECURE) smem_flags |= SMEM_SECURE; msm_comm_smem_alloc(inst, SZ_4K, 1, smem_flags, HAL_BUFFER_INPUT, 0); rc = msm_comm_smem_alloc(inst, SZ_4K, 1, smem_flags, HAL_BUFFER_INPUT, 0, &binfo->smem); if (rc) { kfree(binfo); dprintk(VIDC_ERR, "Failed to allocate output memory\n"); rc = -ENOMEM; break; } mutex_lock(&inst->eosbufs.lock); list_add_tail(&binfo->list, &inst->eosbufs.list); Loading Loading @@ -4177,7 +4167,7 @@ int msm_comm_release_output_buffers(struct msm_vidc_inst *inst) } mutex_lock(&inst->outputbufs.lock); list_for_each_entry_safe(buf, dummy, &inst->outputbufs.list, list) { handle = buf->handle; handle = &buf->smem; if (!handle) { dprintk(VIDC_ERR, "%s - invalid handle\n", __func__); goto exit; Loading @@ -4203,7 +4193,7 @@ int msm_comm_release_output_buffers(struct msm_vidc_inst *inst) } list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, &buf->smem); kfree(buf); } Loading Loading @@ -4232,13 +4222,8 @@ static enum hal_buffer scratch_buf_sufficient(struct msm_vidc_inst *inst, mutex_lock(&inst->scratchbufs.lock); list_for_each_entry(buf, &inst->scratchbufs.list, list) { if (!buf->handle) { dprintk(VIDC_ERR, "%s: invalid buf handle\n", __func__); mutex_unlock(&inst->scratchbufs.lock); goto not_sufficient; } if (buf->buffer_type == buffer_type && buf->handle->size >= bufreq->buffer_size) buf->smem.size >= bufreq->buffer_size) count++; } mutex_unlock(&inst->scratchbufs.lock); Loading Loading @@ -4297,13 +4282,7 @@ int msm_comm_release_scratch_buffers(struct msm_vidc_inst *inst, mutex_lock(&inst->scratchbufs.lock); list_for_each_entry_safe(buf, dummy, &inst->scratchbufs.list, list) { if (!buf->handle) { dprintk(VIDC_ERR, "%s - buf->handle NULL\n", __func__); rc = -EINVAL; goto exit; } handle = buf->handle; handle = &buf->smem; buffer_info.buffer_size = handle->size; buffer_info.buffer_type = buf->buffer_type; buffer_info.num_buffers = 1; Loading Loading @@ -4335,11 +4314,10 @@ int msm_comm_release_scratch_buffers(struct msm_vidc_inst *inst, continue; list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, handle); kfree(buf); } exit: mutex_unlock(&inst->scratchbufs.lock); return rc; } Loading @@ -4357,9 +4335,9 @@ void msm_comm_release_eos_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->eosbufs.lock); list_for_each_entry_safe(buf, next, &inst->eosbufs.list, list) { list_del(&buf->list); msm_comm_smem_free(inst, &buf->smem); kfree(buf); } INIT_LIST_HEAD(&inst->eosbufs.list); mutex_unlock(&inst->eosbufs.lock); } Loading Loading @@ -4394,7 +4372,7 @@ int msm_comm_release_persist_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->persistbufs.lock); list_for_each_safe(ptr, next, &inst->persistbufs.list) { buf = list_entry(ptr, struct internal_buf, list); handle = buf->handle; handle = &buf->smem; buffer_info.buffer_size = handle->size; buffer_info.buffer_type = buf->buffer_type; buffer_info.num_buffers = 1; Loading @@ -4420,7 +4398,7 @@ int msm_comm_release_persist_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->persistbufs.lock); } list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, handle); kfree(buf); } mutex_unlock(&inst->persistbufs.lock); Loading Loading @@ -5158,19 +5136,20 @@ int msm_comm_kill_session(struct msm_vidc_inst *inst) return rc; } struct msm_smem *msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel) int msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel, struct msm_smem *smem) { struct msm_smem *m = NULL; int rc = 0; if (!inst || !inst->core) { dprintk(VIDC_ERR, "%s: invalid inst: %pK\n", __func__, inst); return NULL; return -EINVAL; } m = msm_smem_alloc(inst->mem_client, size, align, flags, buffer_type, map_kernel); return m; rc = msm_smem_alloc(size, align, flags, buffer_type, map_kernel, &(inst->core->resources), inst->session_type, smem); return rc; } void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem) Loading @@ -5180,7 +5159,7 @@ void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem) "%s: invalid params: %pK %pK\n", __func__, inst, mem); return; } msm_smem_free(inst->mem_client, mem); msm_smem_free(mem); } int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, Loading @@ -5191,28 +5170,8 @@ int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, "%s: invalid params: %pK %pK\n", __func__, inst, mem); return -EINVAL; } return msm_smem_cache_operations(inst->mem_client, mem, cache_ops); } struct msm_smem *msm_comm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, enum hal_buffer buffer_type) { struct msm_smem *m = NULL; if (!inst || !inst->core) { dprintk(VIDC_ERR, "%s: invalid inst: %pK\n", __func__, inst); return NULL; } if (inst->state == MSM_VIDC_CORE_INVALID) { dprintk(VIDC_ERR, "Core in Invalid state, returning from %s\n", __func__); return NULL; } m = msm_smem_user_to_kernel(inst->mem_client, fd, offset, buffer_type); return m; return msm_smem_cache_operations(mem->dma_buf, mem->offset, mem->size, cache_ops); } void msm_vidc_fw_unload_handler(struct work_struct *work) Loading drivers/media/platform/msm/vidc_3x/msm_vidc_common.h +3 −4 Original line number Diff line number Diff line Loading @@ -72,14 +72,13 @@ void msm_comm_session_clean(struct msm_vidc_inst *inst); int msm_comm_kill_session(struct msm_vidc_inst *inst); enum multi_stream msm_comm_get_stream_output_mode(struct msm_vidc_inst *inst); enum hal_buffer msm_comm_get_hal_output_buffer(struct msm_vidc_inst *inst); struct msm_smem *msm_comm_smem_alloc(struct msm_vidc_inst *inst, int msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel); enum hal_buffer buffer_type, int map_kernel, struct msm_smem *smem); void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem); int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, struct msm_smem *mem, enum smem_cache_ops cache_ops); struct msm_smem *msm_comm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, enum hal_buffer buffer_type); enum hal_video_codec get_hal_codec(int fourcc); enum hal_domain get_hal_domain(int session_type); int msm_comm_check_core_init(struct msm_vidc_core *core); Loading drivers/media/platform/msm/vidc_3x/msm_vidc_internal.h +20 −16 Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ struct eos_buf { struct internal_buf { struct list_head list; enum hal_buffer buffer_type; struct msm_smem *handle; struct msm_smem smem; enum buffer_owner buffer_ownership; }; Loading Loading @@ -282,7 +282,6 @@ struct msm_vidc_inst { struct msm_vidc_list eosbufs; struct msm_vidc_list registeredbufs; struct buffer_requirements buff_req; void *mem_client; struct v4l2_ctrl_handler ctrl_handler; struct completion completions[SESSION_MSG_END - SESSION_MSG_START + 1]; struct v4l2_ctrl **cluster; Loading Loading @@ -357,7 +356,7 @@ struct buffer_info { int size[VIDEO_MAX_PLANES]; unsigned long uvaddr[VIDEO_MAX_PLANES]; phys_addr_t device_addr[VIDEO_MAX_PLANES]; struct msm_smem *handle[VIDEO_MAX_PLANES]; struct msm_smem smem[VIDEO_MAX_PLANES]; enum v4l2_memory memory; u32 v4l2_index; bool pending_deletion; Loading @@ -382,20 +381,25 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, struct buffer_info *binfo); void msm_comm_handle_thermal_event(void); void *msm_smem_new_client(enum smem_type mtype, void *platform_resources, enum session_type stype); struct msm_smem *msm_smem_alloc(void *clt, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel); void msm_smem_free(void *clt, struct msm_smem *mem); void msm_smem_delete_client(void *clt); int msm_smem_cache_operations(void *clt, struct msm_smem *mem, enum smem_cache_ops); struct msm_smem *msm_smem_user_to_kernel(void *clt, int fd, u32 offset, int msm_smem_alloc(size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel, void *res, u32 session_type, struct msm_smem *smem); int msm_smem_free(struct msm_smem *mem); int msm_smem_cache_operations(struct dma_buf *dbuf, enum smem_cache_ops, unsigned long offset, unsigned long size); struct context_bank_info *msm_smem_get_context_bank(u32 session_type, bool is_secure, struct msm_vidc_platform_resources *res, enum hal_buffer buffer_type); struct context_bank_info *msm_smem_get_context_bank(void *clt, bool is_secure, enum hal_buffer buffer_type); int msm_smem_map_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem); int msm_smem_unmap_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem); struct dma_buf *msm_smem_get_dma_buf(int fd); void msm_smem_put_dma_buf(void *dma_buf); bool msm_smem_compare_buffers(int fd, void *dma_buf); struct msm_smem *msm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, u32 size, enum hal_buffer buffer_type); void msm_vidc_fw_unload_handler(struct work_struct *work); bool msm_smem_compare_buffers(void *clt, int fd, void *priv); /* XXX: normally should be in msm_vidc.h, but that's meant for public APIs, * whereas this is private */ Loading Loading
drivers/media/platform/msm/vidc_3x/msm_smem.c +377 −424 File changed.Preview size limit exceeded, changes collapsed. Show changes
drivers/media/platform/msm/vidc_3x/msm_vidc.c +49 −71 Original line number Diff line number Diff line Loading @@ -221,9 +221,8 @@ struct buffer_info *get_registered_buf(struct msm_vidc_inst *inst, *plane = 0; list_for_each_entry(temp, &inst->registeredbufs.list, list) { for (i = 0; i < min(temp->num_planes, VIDEO_MAX_PLANES); i++) { bool ion_hndl_matches = temp->handle[i] ? msm_smem_compare_buffers(inst->mem_client, fd, temp->handle[i]->smem_priv) : false; bool dma_matches = msm_smem_compare_buffers(fd, temp->smem[i].dma_buf); bool device_addr_matches = device_addr == temp->device_addr[i]; bool contains_within = CONTAINS(temp->buff_off[i], Loading @@ -233,7 +232,7 @@ struct buffer_info *get_registered_buf(struct msm_vidc_inst *inst, temp->buff_off[i], temp->size[i]); if (!temp->inactive && (ion_hndl_matches || device_addr_matches) && (dma_matches || device_addr_matches) && (contains_within || overlaps)) { dprintk(VIDC_DBG, "This memory region is already mapped\n"); Loading @@ -254,7 +253,6 @@ static struct msm_smem *get_same_fd_buffer(struct msm_vidc_inst *inst, int fd) { struct buffer_info *temp; struct msm_smem *same_fd_handle = NULL; int i; if (!fd) Loading @@ -268,14 +266,13 @@ static struct msm_smem *get_same_fd_buffer(struct msm_vidc_inst *inst, int fd) mutex_lock(&inst->registeredbufs.lock); list_for_each_entry(temp, &inst->registeredbufs.list, list) { for (i = 0; i < min(temp->num_planes, VIDEO_MAX_PLANES); i++) { bool ion_hndl_matches = temp->handle[i] ? msm_smem_compare_buffers(inst->mem_client, fd, temp->handle[i]->smem_priv) : false; if (ion_hndl_matches && temp->mapped[i]) { bool dma_matches = msm_smem_compare_buffers(fd, temp->smem[i].dma_buf); if (dma_matches && temp->mapped[i]) { temp->same_fd_ref[i]++; dprintk(VIDC_INFO, "Found same fd buffer\n"); same_fd_handle = temp->handle[i]; same_fd_handle = &temp->smem[i]; break; } } Loading Loading @@ -367,23 +364,6 @@ static inline void repopulate_v4l2_buffer(struct v4l2_buffer *b, } } static struct msm_smem *map_buffer(struct msm_vidc_inst *inst, struct v4l2_plane *p, enum hal_buffer buffer_type) { struct msm_smem *handle = NULL; handle = msm_comm_smem_user_to_kernel(inst, p->reserved[0], p->reserved[1], buffer_type); if (!handle) { dprintk(VIDC_ERR, "%s: Failed to get device buffer address\n", __func__); return NULL; } return handle; } static inline enum hal_buffer get_hal_buffer_type( struct msm_vidc_inst *inst, struct v4l2_buffer *b) { Loading Loading @@ -518,17 +498,27 @@ int map_and_register_buf(struct msm_vidc_inst *inst, struct v4l2_buffer *b) same_fd_handle->device_addr + binfo->buff_off[i]; b->m.planes[i].m.userptr = binfo->device_addr[i]; binfo->mapped[i] = false; binfo->handle[i] = same_fd_handle; binfo->smem[i] = *same_fd_handle; } else { binfo->handle[i] = map_buffer(inst, &b->m.planes[i], get_hal_buffer_type(inst, b)); if (!binfo->handle[i]) { rc = -EINVAL; binfo->smem[i].buffer_type = binfo->type; binfo->smem[i].fd = binfo->fd[i]; binfo->smem[i].offset = binfo->buff_off[i]; binfo->smem[i].size = binfo->size[i]; rc = msm_smem_map_dma_buf(inst, &binfo->smem[i]); if (rc) { dprintk(VIDC_ERR, "%s: map failed.\n", __func__); goto exit; } /* increase refcount as we get both fbd and rbr */ rc = msm_smem_map_dma_buf(inst, &binfo->smem[i]); if (rc) { dprintk(VIDC_ERR, "%s: map failed..\n", __func__); goto exit; } binfo->mapped[i] = true; binfo->device_addr[i] = binfo->handle[i]->device_addr + binfo->device_addr[i] = binfo->smem[i].device_addr + binfo->buff_off[i]; b->m.planes[i].m.userptr = binfo->device_addr[i]; } Loading @@ -541,7 +531,7 @@ int map_and_register_buf(struct msm_vidc_inst *inst, struct v4l2_buffer *b) } dprintk(VIDC_DBG, "%s: [MAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, binfo, i, binfo->handle[i], __func__, binfo, i, binfo->smem[i], &binfo->device_addr[i], binfo->fd[i], binfo->buff_off[i], binfo->mapped[i]); } Loading Loading @@ -594,7 +584,7 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, for (i = 0; i < temp->num_planes; i++) { dprintk(VIDC_DBG, "%s: [UNMAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, temp, i, temp->handle[i], __func__, temp, i, temp->smem[i], &temp->device_addr[i], temp->fd[i], temp->buff_off[i], temp->mapped[i]); /* Loading @@ -606,17 +596,19 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, * For buffers which share the same fd, do not unmap and keep * the buffer info in registered list. */ if (temp->handle[i] && temp->mapped[i] && !temp->same_fd_ref[i]) { if (temp->mapped[i] && !temp->same_fd_ref[i]) { if (msm_smem_unmap_dma_buf(inst, &temp->smem[i])) dprintk(VIDC_DBG, "unmap failed..\n"); msm_comm_smem_free(inst, temp->handle[i]); &temp->smem[i]); } if (temp->same_fd_ref[i]) keep_node = true; else { temp->fd[i] = 0; temp->handle[i] = 0; //temp->smem[i] = 0; temp->device_addr[i] = 0; temp->uvaddr[i] = 0; } Loading Loading @@ -679,18 +671,14 @@ int output_buffer_cache_invalidate(struct msm_vidc_inst *inst, for (i = 0; i < binfo->num_planes; i++) { if (binfo->handle[i]) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_INVALIDATE); &binfo->smem[i], SMEM_CACHE_INVALIDATE); if (rc) { dprintk(VIDC_ERR, "%s: Failed to clean caches: %d\n", __func__, rc); return -EINVAL; } } else dprintk(VIDC_DBG, "%s: NULL handle for plane %d\n", __func__, i); } return 0; } Loading Loading @@ -812,14 +800,14 @@ int msm_vidc_release_buffers(void *instance, int buffer_type) if (bi->type == buffer_type) { list_del(&bi->list); for (i = 0; i < bi->num_planes; i++) { if (bi->handle[i] && bi->mapped[i]) { if (bi->mapped[i]) { dprintk(VIDC_DBG, "%s: [UNMAP] binfo = %pK, handle[%d] = %pK, device_addr = %pa, fd = %d, offset = %d, mapped = %d\n", __func__, bi, i, bi->handle[i], __func__, bi, i, bi->smem[i], &bi->device_addr[i], bi->fd[i], bi->buff_off[i], bi->mapped[i]); msm_comm_smem_free(inst, bi->handle[i]); &bi->smem[i]); } } kfree(bi); Loading Loading @@ -881,10 +869,10 @@ int msm_vidc_qbuf(void *instance, struct v4l2_buffer *b) &binfo->device_addr[i]); if (inst->fmts[OUTPUT_PORT].fourcc == V4L2_PIX_FMT_HEVC_HYBRID && binfo->handle[i] && V4L2_PIX_FMT_HEVC_HYBRID && b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_INVALIDATE); &binfo->smem[i], SMEM_CACHE_INVALIDATE); if (rc) { dprintk(VIDC_ERR, "Failed to inv caches: %d\n", rc); Loading @@ -892,10 +880,9 @@ int msm_vidc_qbuf(void *instance, struct v4l2_buffer *b) } } if (binfo->handle[i] && (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) { if (b->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { rc = msm_comm_smem_cache_operations(inst, binfo->handle[i], SMEM_CACHE_CLEAN); &binfo->smem[i], SMEM_CACHE_CLEAN); if (rc) { dprintk(VIDC_ERR, "Failed to clean caches: %d\n", rc); Loading Loading @@ -1223,12 +1210,6 @@ void *msm_vidc_open(int core_id, int session_type) i <= SESSION_MSG_INDEX(SESSION_MSG_END); i++) { init_completion(&inst->completions[i]); } inst->mem_client = msm_smem_new_client(SMEM_DMA, &inst->core->resources, session_type); if (!inst->mem_client) { dprintk(VIDC_ERR, "Failed to create memory client\n"); goto fail_mem_client; } if (session_type == MSM_VIDC_DECODER) { msm_vdec_inst_init(inst); Loading Loading @@ -1292,8 +1273,6 @@ void *msm_vidc_open(int core_id, int session_type) vb2_queue_release(&inst->bufq[CAPTURE_PORT].vb2_bufq); fail_bufq_capture: msm_comm_ctrl_deinit(inst); msm_smem_delete_client(inst->mem_client); fail_mem_client: DEINIT_MSM_VIDC_LIST(&inst->eosbufs); kfree(inst); inst = NULL; Loading Loading @@ -1407,8 +1386,8 @@ int msm_vidc_close(void *instance) for (i = 0; i < min(bi->num_planes, VIDEO_MAX_PLANES); i++) { if (bi->handle[i] && bi->mapped[i]) msm_comm_smem_free(inst, bi->handle[i]); if (bi->mapped[i]) msm_comm_smem_free(inst, &bi->smem[i]); } kfree(bi); Loading @@ -1427,7 +1406,6 @@ int msm_vidc_close(void *instance) "Failed to move video instance to uninit state\n"); msm_comm_session_clean(inst); msm_smem_delete_client(inst->mem_client); kref_put(&inst->kref, close_helper); return 0; Loading
drivers/media/platform/msm/vidc_3x/msm_vidc_common.c +78 −119 Original line number Diff line number Diff line Loading @@ -811,9 +811,9 @@ static void handle_session_release_buf_done(enum hal_command_response cmd, mutex_lock(&inst->scratchbufs.lock); list_for_each_safe(ptr, next, &inst->scratchbufs.list) { buf = list_entry(ptr, struct internal_buf, list); if (address == (u32)buf->handle->device_addr) { dprintk(VIDC_DBG, "releasing scratch: %pa\n", &buf->handle->device_addr); if (address == buf->smem.device_addr) { dprintk(VIDC_DBG, "releasing scratch: %x\n", buf->smem.device_addr); buf_found = true; } } Loading @@ -822,9 +822,9 @@ static void handle_session_release_buf_done(enum hal_command_response cmd, mutex_lock(&inst->persistbufs.lock); list_for_each_safe(ptr, next, &inst->persistbufs.list) { buf = list_entry(ptr, struct internal_buf, list); if (address == (u32)buf->handle->device_addr) { dprintk(VIDC_DBG, "releasing persist: %pa\n", &buf->handle->device_addr); if (address == buf->smem.device_addr) { dprintk(VIDC_DBG, "releasing persist: %x\n", buf->smem.device_addr); buf_found = true; } } Loading Loading @@ -1442,8 +1442,8 @@ void validate_output_buffers(struct msm_vidc_inst *inst) list_for_each_entry(binfo, &inst->outputbufs.list, list) { if (binfo->buffer_ownership != DRIVER) { dprintk(VIDC_DBG, "This buffer is with FW %pa\n", &binfo->handle->device_addr); "This buffer is with FW %x\n", binfo->smem.device_addr); continue; } buffers_owned_by_driver++; Loading @@ -1462,7 +1462,6 @@ int msm_comm_queue_output_buffers(struct msm_vidc_inst *inst) { struct internal_buf *binfo; struct hfi_device *hdev; struct msm_smem *handle; struct vidc_frame_data frame_data = {0}; struct hal_buffer_requirements *output_buf, *extra_buf; int rc = 0; Loading Loading @@ -1492,13 +1491,12 @@ int msm_comm_queue_output_buffers(struct msm_vidc_inst *inst) list_for_each_entry(binfo, &inst->outputbufs.list, list) { if (binfo->buffer_ownership != DRIVER) continue; handle = binfo->handle; frame_data.alloc_len = output_buf->buffer_size; frame_data.filled_len = 0; frame_data.offset = 0; frame_data.device_addr = handle->device_addr; frame_data.device_addr = binfo->smem.device_addr; frame_data.flags = 0; frame_data.extradata_addr = handle->device_addr + frame_data.extradata_addr = binfo->smem.device_addr + output_buf->buffer_size; frame_data.buffer_type = HAL_BUFFER_OUTPUT; frame_data.extradata_size = extra_buf ? Loading Loading @@ -1980,17 +1978,17 @@ static int handle_multi_stream_buffers(struct msm_vidc_inst *inst, phys_addr_t dev_addr) { struct internal_buf *binfo; struct msm_smem *handle; struct msm_smem *smem; bool found = false; mutex_lock(&inst->outputbufs.lock); list_for_each_entry(binfo, &inst->outputbufs.list, list) { handle = binfo->handle; if (handle && dev_addr == handle->device_addr) { smem = &binfo->smem; if (smem && dev_addr == smem->device_addr) { if (binfo->buffer_ownership == DRIVER) { dprintk(VIDC_ERR, "FW returned same buffer: %pa\n", &dev_addr); "FW returned same buffer: %x\n", dev_addr); break; } binfo->buffer_ownership = DRIVER; Loading @@ -2002,8 +2000,8 @@ static int handle_multi_stream_buffers(struct msm_vidc_inst *inst, if (!found) { dprintk(VIDC_ERR, "Failed to find output buffer in queued list: %pa\n", &dev_addr); "Failed to find output buffer in queued list: %x\n", dev_addr); } return 0; Loading Loading @@ -3069,9 +3067,8 @@ static int set_output_buffers(struct msm_vidc_inst *inst, enum hal_buffer buffer_type) { int rc = 0; struct msm_smem *handle; struct internal_buf *binfo; u32 smem_flags = 0, buffer_size; struct internal_buf *binfo = NULL; u32 smem_flags = SMEM_UNCACHED, buffer_size; struct hal_buffer_requirements *output_buf, *extradata_buf; int i; struct hfi_device *hdev; Loading Loading @@ -3117,33 +3114,25 @@ static int set_output_buffers(struct msm_vidc_inst *inst, if (output_buf->buffer_size) { for (i = 0; i < output_buf->buffer_count_actual; i++) { handle = msm_comm_smem_alloc(inst, buffer_size, 1, smem_flags, buffer_type, 0); if (!handle) { dprintk(VIDC_ERR, "Failed to allocate output memory\n"); rc = -ENOMEM; goto err_no_mem; } rc = msm_comm_smem_cache_operations(inst, handle, SMEM_CACHE_CLEAN); if (rc) { dprintk(VIDC_WARN, "Failed to clean cache may cause undefined behavior\n"); } binfo = kzalloc(sizeof(*binfo), GFP_KERNEL); if (!binfo) { dprintk(VIDC_ERR, "Out of memory\n"); rc = -ENOMEM; goto fail_kzalloc; } binfo->handle = handle; rc = msm_comm_smem_alloc(inst, buffer_size, 1, smem_flags, buffer_type, 0, &binfo->smem); if (rc) { dprintk(VIDC_ERR, "Failed to allocate output memory\n"); goto err_no_mem; } binfo->buffer_type = buffer_type; binfo->buffer_ownership = DRIVER; dprintk(VIDC_DBG, "Output buffer address: %pa\n", &handle->device_addr); dprintk(VIDC_DBG, "Output buffer address: %#x\n", binfo->smem.device_addr); if (inst->buffer_mode_set[CAPTURE_PORT] == HAL_BUFFER_MODE_STATIC) { Loading @@ -3154,9 +3143,9 @@ static int set_output_buffers(struct msm_vidc_inst *inst, buffer_info.buffer_type = buffer_type; buffer_info.num_buffers = 1; buffer_info.align_device_addr = handle->device_addr; binfo->smem.device_addr; buffer_info.extradata_addr = handle->device_addr + binfo->smem.device_addr + output_buf->buffer_size; if (extradata_buf) buffer_info.extradata_size = Loading @@ -3177,10 +3166,10 @@ static int set_output_buffers(struct msm_vidc_inst *inst, } return rc; fail_set_buffers: msm_comm_smem_free(inst, &binfo->smem); err_no_mem: kfree(binfo); fail_kzalloc: msm_comm_smem_free(inst, handle); err_no_mem: return rc; } Loading Loading @@ -3258,10 +3247,6 @@ static bool reuse_internal_buffers(struct msm_vidc_inst *inst, mutex_lock(&buf_list->lock); list_for_each_entry(buf, &buf_list->list, list) { if (!buf->handle) { reused = false; break; } if (buf->buffer_type != buffer_type) continue; Loading @@ -3278,7 +3263,7 @@ static bool reuse_internal_buffers(struct msm_vidc_inst *inst, && buffer_type != HAL_BUFFER_INTERNAL_PERSIST_1) { rc = set_internal_buf_on_fw(inst, buffer_type, buf->handle, true); &buf->smem, true); if (rc) { dprintk(VIDC_ERR, "%s: session_set_buffers failed\n", Loading @@ -3299,9 +3284,8 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, struct hal_buffer_requirements *internal_bufreq, struct msm_vidc_list *buf_list) { struct msm_smem *handle; struct internal_buf *binfo; u32 smem_flags = 0; u32 smem_flags = SMEM_UNCACHED; int rc = 0; int i = 0; Loading @@ -3315,27 +3299,25 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, smem_flags |= SMEM_SECURE; for (i = 0; i < internal_bufreq->buffer_count_actual; i++) { handle = msm_comm_smem_alloc(inst, internal_bufreq->buffer_size, 1, smem_flags, internal_bufreq->buffer_type, 0); if (!handle) { dprintk(VIDC_ERR, "Failed to allocate scratch memory\n"); rc = -ENOMEM; goto err_no_mem; } binfo = kzalloc(sizeof(*binfo), GFP_KERNEL); if (!binfo) { dprintk(VIDC_ERR, "Out of memory\n"); rc = -ENOMEM; goto fail_kzalloc; } rc = msm_comm_smem_alloc(inst, internal_bufreq->buffer_size, 1, smem_flags, internal_bufreq->buffer_type, 0, &binfo->smem); if (rc) { dprintk(VIDC_ERR, "Failed to allocate scratch memory\n"); goto err_no_mem; } binfo->handle = handle; binfo->buffer_type = internal_bufreq->buffer_type; rc = set_internal_buf_on_fw(inst, internal_bufreq->buffer_type, handle, false); &binfo->smem, false); if (rc) goto fail_set_buffers; Loading @@ -3346,10 +3328,10 @@ static int allocate_and_set_internal_bufs(struct msm_vidc_inst *inst, return rc; fail_set_buffers: msm_comm_smem_free(inst, &binfo->smem); err_no_mem: kfree(binfo); fail_kzalloc: msm_comm_smem_free(inst, handle); err_no_mem: return rc; } Loading Loading @@ -3578,7 +3560,7 @@ int msm_vidc_comm_cmd(void *instance, union msm_v4l2_cmd *cmd) struct vidc_frame_data data = {0}; struct hfi_device *hdev = NULL; struct eos_buf *binfo = NULL; u32 smem_flags = 0; u32 smem_flags = SMEM_UNCACHED; if (inst->state != MSM_VIDC_START_DONE) { dprintk(VIDC_DBG, Loading @@ -3603,8 +3585,16 @@ int msm_vidc_comm_cmd(void *instance, union msm_v4l2_cmd *cmd) if (inst->flags & VIDC_SECURE) smem_flags |= SMEM_SECURE; msm_comm_smem_alloc(inst, SZ_4K, 1, smem_flags, HAL_BUFFER_INPUT, 0); rc = msm_comm_smem_alloc(inst, SZ_4K, 1, smem_flags, HAL_BUFFER_INPUT, 0, &binfo->smem); if (rc) { kfree(binfo); dprintk(VIDC_ERR, "Failed to allocate output memory\n"); rc = -ENOMEM; break; } mutex_lock(&inst->eosbufs.lock); list_add_tail(&binfo->list, &inst->eosbufs.list); Loading Loading @@ -4177,7 +4167,7 @@ int msm_comm_release_output_buffers(struct msm_vidc_inst *inst) } mutex_lock(&inst->outputbufs.lock); list_for_each_entry_safe(buf, dummy, &inst->outputbufs.list, list) { handle = buf->handle; handle = &buf->smem; if (!handle) { dprintk(VIDC_ERR, "%s - invalid handle\n", __func__); goto exit; Loading @@ -4203,7 +4193,7 @@ int msm_comm_release_output_buffers(struct msm_vidc_inst *inst) } list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, &buf->smem); kfree(buf); } Loading Loading @@ -4232,13 +4222,8 @@ static enum hal_buffer scratch_buf_sufficient(struct msm_vidc_inst *inst, mutex_lock(&inst->scratchbufs.lock); list_for_each_entry(buf, &inst->scratchbufs.list, list) { if (!buf->handle) { dprintk(VIDC_ERR, "%s: invalid buf handle\n", __func__); mutex_unlock(&inst->scratchbufs.lock); goto not_sufficient; } if (buf->buffer_type == buffer_type && buf->handle->size >= bufreq->buffer_size) buf->smem.size >= bufreq->buffer_size) count++; } mutex_unlock(&inst->scratchbufs.lock); Loading Loading @@ -4297,13 +4282,7 @@ int msm_comm_release_scratch_buffers(struct msm_vidc_inst *inst, mutex_lock(&inst->scratchbufs.lock); list_for_each_entry_safe(buf, dummy, &inst->scratchbufs.list, list) { if (!buf->handle) { dprintk(VIDC_ERR, "%s - buf->handle NULL\n", __func__); rc = -EINVAL; goto exit; } handle = buf->handle; handle = &buf->smem; buffer_info.buffer_size = handle->size; buffer_info.buffer_type = buf->buffer_type; buffer_info.num_buffers = 1; Loading Loading @@ -4335,11 +4314,10 @@ int msm_comm_release_scratch_buffers(struct msm_vidc_inst *inst, continue; list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, handle); kfree(buf); } exit: mutex_unlock(&inst->scratchbufs.lock); return rc; } Loading @@ -4357,9 +4335,9 @@ void msm_comm_release_eos_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->eosbufs.lock); list_for_each_entry_safe(buf, next, &inst->eosbufs.list, list) { list_del(&buf->list); msm_comm_smem_free(inst, &buf->smem); kfree(buf); } INIT_LIST_HEAD(&inst->eosbufs.list); mutex_unlock(&inst->eosbufs.lock); } Loading Loading @@ -4394,7 +4372,7 @@ int msm_comm_release_persist_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->persistbufs.lock); list_for_each_safe(ptr, next, &inst->persistbufs.list) { buf = list_entry(ptr, struct internal_buf, list); handle = buf->handle; handle = &buf->smem; buffer_info.buffer_size = handle->size; buffer_info.buffer_type = buf->buffer_type; buffer_info.num_buffers = 1; Loading @@ -4420,7 +4398,7 @@ int msm_comm_release_persist_buffers(struct msm_vidc_inst *inst) mutex_lock(&inst->persistbufs.lock); } list_del(&buf->list); msm_comm_smem_free(inst, buf->handle); msm_comm_smem_free(inst, handle); kfree(buf); } mutex_unlock(&inst->persistbufs.lock); Loading Loading @@ -5158,19 +5136,20 @@ int msm_comm_kill_session(struct msm_vidc_inst *inst) return rc; } struct msm_smem *msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel) int msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel, struct msm_smem *smem) { struct msm_smem *m = NULL; int rc = 0; if (!inst || !inst->core) { dprintk(VIDC_ERR, "%s: invalid inst: %pK\n", __func__, inst); return NULL; return -EINVAL; } m = msm_smem_alloc(inst->mem_client, size, align, flags, buffer_type, map_kernel); return m; rc = msm_smem_alloc(size, align, flags, buffer_type, map_kernel, &(inst->core->resources), inst->session_type, smem); return rc; } void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem) Loading @@ -5180,7 +5159,7 @@ void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem) "%s: invalid params: %pK %pK\n", __func__, inst, mem); return; } msm_smem_free(inst->mem_client, mem); msm_smem_free(mem); } int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, Loading @@ -5191,28 +5170,8 @@ int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, "%s: invalid params: %pK %pK\n", __func__, inst, mem); return -EINVAL; } return msm_smem_cache_operations(inst->mem_client, mem, cache_ops); } struct msm_smem *msm_comm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, enum hal_buffer buffer_type) { struct msm_smem *m = NULL; if (!inst || !inst->core) { dprintk(VIDC_ERR, "%s: invalid inst: %pK\n", __func__, inst); return NULL; } if (inst->state == MSM_VIDC_CORE_INVALID) { dprintk(VIDC_ERR, "Core in Invalid state, returning from %s\n", __func__); return NULL; } m = msm_smem_user_to_kernel(inst->mem_client, fd, offset, buffer_type); return m; return msm_smem_cache_operations(mem->dma_buf, mem->offset, mem->size, cache_ops); } void msm_vidc_fw_unload_handler(struct work_struct *work) Loading
drivers/media/platform/msm/vidc_3x/msm_vidc_common.h +3 −4 Original line number Diff line number Diff line Loading @@ -72,14 +72,13 @@ void msm_comm_session_clean(struct msm_vidc_inst *inst); int msm_comm_kill_session(struct msm_vidc_inst *inst); enum multi_stream msm_comm_get_stream_output_mode(struct msm_vidc_inst *inst); enum hal_buffer msm_comm_get_hal_output_buffer(struct msm_vidc_inst *inst); struct msm_smem *msm_comm_smem_alloc(struct msm_vidc_inst *inst, int msm_comm_smem_alloc(struct msm_vidc_inst *inst, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel); enum hal_buffer buffer_type, int map_kernel, struct msm_smem *smem); void msm_comm_smem_free(struct msm_vidc_inst *inst, struct msm_smem *mem); int msm_comm_smem_cache_operations(struct msm_vidc_inst *inst, struct msm_smem *mem, enum smem_cache_ops cache_ops); struct msm_smem *msm_comm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, enum hal_buffer buffer_type); enum hal_video_codec get_hal_codec(int fourcc); enum hal_domain get_hal_domain(int session_type); int msm_comm_check_core_init(struct msm_vidc_core *core); Loading
drivers/media/platform/msm/vidc_3x/msm_vidc_internal.h +20 −16 Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ struct eos_buf { struct internal_buf { struct list_head list; enum hal_buffer buffer_type; struct msm_smem *handle; struct msm_smem smem; enum buffer_owner buffer_ownership; }; Loading Loading @@ -282,7 +282,6 @@ struct msm_vidc_inst { struct msm_vidc_list eosbufs; struct msm_vidc_list registeredbufs; struct buffer_requirements buff_req; void *mem_client; struct v4l2_ctrl_handler ctrl_handler; struct completion completions[SESSION_MSG_END - SESSION_MSG_START + 1]; struct v4l2_ctrl **cluster; Loading Loading @@ -357,7 +356,7 @@ struct buffer_info { int size[VIDEO_MAX_PLANES]; unsigned long uvaddr[VIDEO_MAX_PLANES]; phys_addr_t device_addr[VIDEO_MAX_PLANES]; struct msm_smem *handle[VIDEO_MAX_PLANES]; struct msm_smem smem[VIDEO_MAX_PLANES]; enum v4l2_memory memory; u32 v4l2_index; bool pending_deletion; Loading @@ -382,20 +381,25 @@ int unmap_and_deregister_buf(struct msm_vidc_inst *inst, struct buffer_info *binfo); void msm_comm_handle_thermal_event(void); void *msm_smem_new_client(enum smem_type mtype, void *platform_resources, enum session_type stype); struct msm_smem *msm_smem_alloc(void *clt, size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel); void msm_smem_free(void *clt, struct msm_smem *mem); void msm_smem_delete_client(void *clt); int msm_smem_cache_operations(void *clt, struct msm_smem *mem, enum smem_cache_ops); struct msm_smem *msm_smem_user_to_kernel(void *clt, int fd, u32 offset, int msm_smem_alloc(size_t size, u32 align, u32 flags, enum hal_buffer buffer_type, int map_kernel, void *res, u32 session_type, struct msm_smem *smem); int msm_smem_free(struct msm_smem *mem); int msm_smem_cache_operations(struct dma_buf *dbuf, enum smem_cache_ops, unsigned long offset, unsigned long size); struct context_bank_info *msm_smem_get_context_bank(u32 session_type, bool is_secure, struct msm_vidc_platform_resources *res, enum hal_buffer buffer_type); struct context_bank_info *msm_smem_get_context_bank(void *clt, bool is_secure, enum hal_buffer buffer_type); int msm_smem_map_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem); int msm_smem_unmap_dma_buf(struct msm_vidc_inst *inst, struct msm_smem *smem); struct dma_buf *msm_smem_get_dma_buf(int fd); void msm_smem_put_dma_buf(void *dma_buf); bool msm_smem_compare_buffers(int fd, void *dma_buf); struct msm_smem *msm_smem_user_to_kernel(struct msm_vidc_inst *inst, int fd, u32 offset, u32 size, enum hal_buffer buffer_type); void msm_vidc_fw_unload_handler(struct work_struct *work); bool msm_smem_compare_buffers(void *clt, int fd, void *priv); /* XXX: normally should be in msm_vidc.h, but that's meant for public APIs, * whereas this is private */ Loading