示例#1
0
文件: ispvideo.c 项目: borkmann/kasan
static int isp_video_buffer_prepare(struct isp_video_buffer *buf)
{
    struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
    struct isp_buffer *buffer = to_isp_buffer(buf);
    struct isp_video *video = vfh->video;
    unsigned long addr;

    /* Refuse to prepare the buffer is the video node has registered an
     * error. We don't need to take any lock here as the operation is
     * inherently racy. The authoritative check will be performed in the
     * queue handler, which can't return an error, this check is just a best
     * effort to notify userspace as early as possible.
     */
    if (unlikely(video->error))
        return -EIO;

    addr = ispmmu_vmap(video->isp, buf->sglist, buf->sglen);
    if (IS_ERR_VALUE(addr))
        return -EIO;

    if (!IS_ALIGNED(addr, 32)) {
        dev_dbg(video->isp->dev, "Buffer address must be "
                "aligned to 32 bytes boundary.\n");
        ispmmu_vunmap(video->isp, buffer->isp_addr);
        return -EINVAL;
    }

    buf->vbuf.bytesused = vfh->format.fmt.pix.sizeimage;
    buffer->isp_addr = addr;
    return 0;
}
static void isp_video_buffer_cleanup(struct isp_video_buffer *buf)
{
    struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
    struct isp_buffer *buffer = to_isp_buffer(buf);
    struct isp_video *video = vfh->video;

    if (buffer->isp_addr) {
        ispmmu_vunmap(video->isp, buffer->isp_addr);
        buffer->isp_addr = 0;
    }
}
示例#3
0
/**
 * prev2resz_vbq_release - Videobuffer queue release
 */
static void prev2resz_vbq_release(struct videobuf_queue *q,
				  struct videobuf_buffer *vb)
{
	struct prev2resz_fhdl *fhdl = q->priv_data;

	if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
		ispmmu_vunmap(fhdl->isp, fhdl->dst_buff_addr);
		fhdl->dst_buff_addr = 0;
		spin_lock(&fhdl->dst_vbq_lock);
		vb->state = VIDEOBUF_NEEDS_INIT;
		spin_unlock(&fhdl->dst_vbq_lock);
	} else if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
		ispmmu_vunmap(fhdl->isp, fhdl->src_buff_addr);
		fhdl->src_buff_addr = 0;
		spin_lock(&fhdl->src_vbq_lock);
		vb->state = VIDEOBUF_NEEDS_INIT;
		spin_unlock(&fhdl->src_vbq_lock);
	}

	if (vb->memory != V4L2_MEMORY_MMAP) {
		videobuf_dma_unmap(q, videobuf_to_dma(vb));
		videobuf_dma_free(videobuf_to_dma(vb));
	}
}
示例#4
0
/**
 * unmap_buffers_from_kernel - Unmaps memory from isp and kernel address space.
 * @ibuffer: Pointer to internal buffer to be unmapped.
 *
 * No return value.
 **/
void unmap_buffer_from_kernel(struct hp3a_internal_buffer *ibuffer)
{
	if (ibuffer->isp_addr) {
#if defined(CONFIG_VIDEO_OLDOMAP3)
		if (ispmmu_unmap(ibuffer->isp_addr) != 0) {
			printk(KERN_ERR "Error unmapping from ispmmu (0x%x)!",
				(unsigned int)ibuffer->isp_addr);
		}
#else
		ispmmu_vunmap(ibuffer->isp_addr);
#endif
		ibuffer->isp_addr = 0;
	}

	if (ibuffer->pages != NULL && ibuffer->buffer_size > 0) {
		unmap_user_memory(ibuffer->pages, NR_PAGES(ibuffer->user_addr,
				ibuffer->buffer_size));
		kfree(ibuffer->pages);
		ibuffer->pages = NULL;
	}
}
static int isp_video_buffer_prepare(struct isp_video_buffer *buf)
{
    struct isp_video_fh *vfh = isp_video_queue_to_isp_video_fh(buf->queue);
    struct isp_buffer *buffer = to_isp_buffer(buf);
    struct isp_video *video = vfh->video;
    unsigned long addr;

    addr = ispmmu_vmap(video->isp, buf->sglist, buf->sglen);
    if (IS_ERR_VALUE(addr))
        return -EIO;

    if (!IS_ALIGNED(addr, 32)) {
        dev_dbg(video->isp->dev, "Buffer address must be "
                "aligned to 32 bytes boundary.\n");
        ispmmu_vunmap(video->isp, buffer->isp_addr);
        return -EINVAL;
    }

    buf->vbuf.bytesused = vfh->format.fmt.pix.sizeimage;
    buffer->isp_addr = addr;
    return 0;
}
int isp_resize_mem_data(struct isp_mem_resize_data *data)
{
	int i;
	int ret = -1;
	struct isp_mem_resize_data *presizer_user = \
		(struct isp_mem_resize_data *)data;
	u32 input_buffer_size, output_buffer_size;
	u32 input_nr_pages, output_nr_pages;
	struct page **input_pages = NULL;
	struct page **output_pages = NULL;
	unsigned long isp_addr_in = 0;
	unsigned long  isp_addr_out = 0;
	struct isp_mem_resize_data resizer_param;
	unsigned long timeout;

	if (presizer_user == NULL) {
		printk(KERN_ERR "ISP_RESZ_ERR : Invalid user data\n");
		return -EINVAL;
	}

	memcpy(&resizer_param, presizer_user, \
		sizeof(struct isp_mem_resize_data));

	DPRINTK_ISPPROC("\nRSZ input(%d-%d) - output(%d-%d)\n",
		resizer_param.input_width,
		resizer_param.input_height,
		resizer_param.output_width,
		resizer_param.output_height);

	DPRINTK_ISPPROC("RSZ start(%d-%d) - end(%d-%d)\n",
		resizer_param.left,
		resizer_param.top,
		resizer_param.crop_width,
		resizer_param.crop_height);

	if (presizer_user->datain == 0 || presizer_user->dataout == 0)
		return -EINVAL;

	ispresizer_enable(0);
	timeout = jiffies + msecs_to_jiffies(200);
	while (ispresizer_busy()) {
		if (time_after(jiffies, timeout))
			return -EINVAL;
		msleep(1);
	}

	ispresizer_save_context();
	ispresizer_free();
	ispresizer_request();

	/* set data path before configuring modules. */
	ispresizer_config_datapath(RSZ_MEM_YUV, 0);

	input_buffer_size = ALIGN_TO(presizer_user->input_width* \
		presizer_user->input_height*2 , 0x100);
	input_pages = map_user_memory_to_kernel(presizer_user->datain,
		input_buffer_size, &input_nr_pages);
	if (input_pages == NULL) {
		ret = -EINVAL;
		printk(KERN_ERR "ISP_RESZ_ERR: memory allocation failed\n");
		goto exit_cleanup;
	}

	output_buffer_size = ALIGN_TO(presizer_user->output_width* \
		presizer_user->output_height*2, 0x1000);
	output_pages = map_user_memory_to_kernel(presizer_user->dataout,
		output_buffer_size, &output_nr_pages);
	if (output_pages == NULL) {
		ret = -EINVAL;
		printk(KERN_ERR "ISP_RESZ_ERR: memory allocation failed\n");
		goto exit_cleanup;
	}
	for (i = 0; i < output_nr_pages; ++i)
		flush_dcache_page(output_pages[i]);

	isp_addr_in = ispmmu_vmap_pages(input_pages, input_nr_pages);
	if (IS_ERR((void *)isp_addr_in)) {
		isp_addr_in = 0;
		ret = -EINVAL;
		printk(KERN_ERR "ISP_RESZ_ERR: isp mmu map failed\n");
		goto exit_cleanup;
	}
	isp_addr_out = ispmmu_vmap_pages(output_pages, output_nr_pages);
	if (IS_ERR((void *)isp_addr_out)) {
		isp_addr_out = 0;
		ret = -EINVAL;
		printk(KERN_ERR "ISP_RESZ_ERR:  isp mmu map failed\n");
		goto exit_cleanup;
	}

	if ((resizer_param.left == 0) && (resizer_param.top == 0)) {
		ret = ispresizer_try_size(&resizer_param.input_width,
					&resizer_param.input_height,
					&resizer_param.output_width,
					&resizer_param.output_height);

		ret = ispresizer_config_size(resizer_param.input_width,
					resizer_param.input_height,
					resizer_param.output_width,
					resizer_param.output_height);

		ispresizer_set_inaddr(isp_addr_in);
	} else {
		ispresizer_trycrop(resizer_param.left,
					resizer_param.top,
					resizer_param.crop_width,
					resizer_param.crop_height,
					resizer_param.output_width,
					resizer_param.output_height);

		ispresizer_applycrop();

		/*pixel alignment in 32bit space, vertical must be 0 per TRM */
		isp_reg_writel(((resizer_param.left%16) <<
				ISPRSZ_IN_START_HORZ_ST_SHIFT) |
				(0 <<
				ISPRSZ_IN_START_VERT_ST_SHIFT),
				OMAP3_ISP_IOMEM_RESZ,
				ISPRSZ_IN_START);

		/* Align input address for cropping, per TRM  */
		ispresizer_set_inaddr(isp_addr_in +
			(resizer_param.top*resizer_param.input_width*2)
			+ ((resizer_param.left/16)*32));
	}

	ispresizer_set_inaddr(isp_addr_in);
	ispresizer_set_outaddr(isp_addr_out);
	ispresizer_config_ycpos(0);
	ispresizer_config_inlineoffset(
		ALIGN_TO(presizer_user->input_width*2, 32));

	isp_set_callback(CBK_RESZ_DONE, rsz_isr, (void *) NULL, (void *)NULL);
	isp_reg_writel(0xFFFFFFFF, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
	isp_wfc.done = 0;
	/* start resizer engine. */
	ispresizer_enable(1);

	ret = wait_for_completion_timeout(&isp_wfc, msecs_to_jiffies(1000));
	if (!ret)
		ispresizer_enable(0);

	timeout = jiffies + msecs_to_jiffies(50);
	while (ispresizer_busy()) {
		msleep(5);
		if (time_after(jiffies, timeout)) {
			printk(KERN_ERR "ISP_RESZ_ERR: Resizer still busy");
			break;
		}
	}

	isp_reg_writel(0xFFFFFFFF, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
	isp_unset_callback(CBK_RESZ_DONE);
	ret = 0;

exit_cleanup:
	ispresizer_restore_context();

	if (isp_addr_in != 0)
		ispmmu_vunmap(isp_addr_in);
	if (isp_addr_out != 0)
		ispmmu_vunmap(isp_addr_out);
	if (input_pages != NULL) {
		unmap_user_memory_from_kernel(input_pages, input_nr_pages);
		kfree(input_pages);
	}
	if (output_pages != NULL) {
		unmap_user_memory_from_kernel(output_pages, output_nr_pages);
		kfree(output_pages);
	}

	DPRINTK_ISPPROC("resizer exit.\n");

	return ret;
}
int isp_process_mem_data(struct isp_mem_data *data)
{
	int i;
	int ret = -1;
	struct isp_mem_data *ppreview_user = \
		(struct isp_mem_data *)data;
	struct isp_mem_data preview_param;
	u32 input_buffer_size, output_buffer_size;
	u32 input_nr_pages, output_nr_pages;
	struct page **input_pages = NULL;
	struct page **output_pages = NULL;
	unsigned long isp_addr_in = 0;
	unsigned long  isp_addr_out = 0;
	unsigned long  isp_addr_tmp = 0;
	unsigned long timeout;
	struct isp_mem_resize_data resizer_param;
	u16 cropadjust = 0;

	if (ppreview_user == NULL) {
		printk(KERN_ERR "ISP_PROC_ERR: Invalid user data!\n");
		return -EINVAL;
	}

	memcpy(&preview_param, ppreview_user, \
		sizeof(struct isp_mem_data));

	DPRINTK_ISPPROC("input(%d-%d) - output(%d-%d)\n",
		preview_param.input_width,
		preview_param.input_height,
		preview_param.output_width,
		preview_param.output_height);

	DPRINTK_ISPPROC("start(%d-%d) - end(%d-%d)\n",
		preview_param.left,
		preview_param.top,
		preview_param.crop_width,
		preview_param.crop_height);

	if (ppreview_user->datain == 0 || ppreview_user->dataout == 0)
		return -EINVAL;

	isppreview_enable(0);
	ispresizer_enable(0);
	timeout = jiffies + msecs_to_jiffies(200);
	while (isppreview_busy() ||
			ispresizer_busy()) {
		if (time_after(jiffies, timeout))
			return -EINVAL;
		msleep(1);
	}

	isppreview_save_context();
	ispresizer_save_context();
	isppreview_free();
	ispresizer_free();
	isppreview_request();
	ispresizer_request();

	/* set data path before configuring modules. */
	isppreview_update_datapath(PRV_RAW_MEM, PREVIEW_MEM);
	ispresizer_config_datapath(RSZ_MEM_YUV, 0);

	ret = isppreview_try_size(preview_param.input_width,
		preview_param.input_height,
		&preview_param.output_width,
		&preview_param.output_height);
	if (ret < 0)
		goto exit_cleanup;
	ret = isppreview_config_size(preview_param.input_width,
		preview_param.input_height,
		preview_param.output_width,
		preview_param.output_height);
	if (ret < 0)
		goto exit_cleanup;

	input_buffer_size = ALIGN_TO(ppreview_user->input_width* \
		ppreview_user->input_height*2 , 0x100);
	input_pages = map_user_memory_to_kernel(preview_param.datain,
		input_buffer_size, &input_nr_pages);
	if (input_pages == NULL) {
		ret = -EINVAL;
		printk(KERN_ERR "ISP_PROC_ERR: memory allocation failed\n");
		goto exit_cleanup;
	}

	output_buffer_size = ALIGN_TO(ppreview_user->output_width* \
		ppreview_user->output_height*2, 0x1000);
	output_pages = map_user_memory_to_kernel(preview_param.dataout,
		output_buffer_size, &output_nr_pages);
	if (output_pages == NULL) {
		ret = -EINVAL;
		printk(KERN_ERR "ISP_PROC_ERR: memory allocation failed\n");
		goto exit_cleanup;
	}
	for (i = 0; i < output_nr_pages; ++i)
		flush_dcache_page(output_pages[i]);

	isp_addr_in = ispmmu_vmap_pages(input_pages, input_nr_pages);
	if (IS_ERR((void *)isp_addr_in)) {
		isp_addr_in = 0;
		ret = -EINVAL;
		printk(KERN_ERR "ISP_PROC_ERR: isp mmu map failed\n");
		goto exit_cleanup;
	}
	isp_addr_out = ispmmu_vmap_pages(output_pages, output_nr_pages);
	if (IS_ERR((void *)isp_addr_out)) {
		isp_addr_out = 0;
		ret = -EINVAL;
		printk(KERN_ERR "ISP_PROC_ERR: isp mmu map failed\n");
		goto exit_cleanup;
	}

	/* This buffer must be allocated and mapped to
		the ISP MMU previously. */
	isp_addr_tmp = isp_tmp_buf_addr();
	if (isp_addr_tmp == 0) {
		printk(KERN_ERR "ISP_PROC_ERR: Invalid isp tmp buffer address!\n");
		goto exit_cleanup;
	}

	isppreview_config_inlineoffset(ppreview_user->input_width * 2);
	isppreview_set_inaddr(isp_addr_in);
	isppreview_set_outaddr(isp_addr_tmp);

	resizer_param.input_width = preview_param.output_width;
	resizer_param.input_height = preview_param.output_height;
	resizer_param.output_width = ppreview_user->output_width;
	resizer_param.output_height = ppreview_user->output_height;

	if ((preview_param.left == 0) && (preview_param.top == 0)) {
		ret = ispresizer_try_size(&resizer_param.input_width,
				&resizer_param.input_height,
				&resizer_param.output_width,
				&resizer_param.output_height);
		if (ret < 0)
			goto exit_cleanup;
		ret = ispresizer_config_size(resizer_param.input_width,
				resizer_param.input_height,
				resizer_param.output_width,
				resizer_param.output_height);
		if (ret < 0)
			goto exit_cleanup;
		ispresizer_set_inaddr(isp_addr_tmp);
	} else {
		ispresizer_trycrop(preview_param.left,
				preview_param.top,
				preview_param.crop_width,
				preview_param.crop_height,
				resizer_param.output_width,
				resizer_param.output_height);

		ispresizer_applycrop();

		/* account for pixel loss when using crop*/
		if ((preview_param.input_height > preview_param.output_height)
				&& (preview_param.top > 16))
			cropadjust = 8;
		else
			cropadjust = 0;

		/* pixel alignment in 32bit space, vertical must be 0 per TRM */
		isp_reg_writel(((preview_param.left%16) <<
					ISPRSZ_IN_START_HORZ_ST_SHIFT) |
					(0 <<
					ISPRSZ_IN_START_VERT_ST_SHIFT),
					OMAP3_ISP_IOMEM_RESZ,
					ISPRSZ_IN_START);

		/* Align input address for cropping, per TRM  */
		ispresizer_set_inaddr(isp_addr_tmp -
				(resizer_param.input_width*2*cropadjust) +
				(preview_param.top*resizer_param.input_width*2)
				+ ((preview_param.left/16)*32));
	}

	ispresizer_set_outaddr(isp_addr_out);
	ispresizer_config_inlineoffset(
		ALIGN_TO(resizer_param.input_width*2, 32));

	if (isp_set_callback(CBK_PREV_DONE, prv_isr,
			(void *) NULL, (void *)NULL) != 0) {
		printk(KERN_ERR "ISP_PROC_ERR: Error setting PRV callback.\n");
		goto exit_cleanup;
	}

	if (isp_set_callback(CBK_RESZ_DONE, rsz_isr,
			(void *) NULL, (void *)NULL) != 0) {
		printk(KERN_ERR "ISP_PROC_ERR: Error setting RSZ callback.\n");
		goto exit_cleanup;
	}

	isp_reg_writel(0xFFFFFFFF, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
	isp_wfc.done = 0;

	/* start preview engine. */
	isppreview_enable(1);

	ret = wait_for_completion_timeout(&isp_wfc, msecs_to_jiffies(1000));
	if (!ret) {
		isppreview_enable(0);
		ispresizer_enable(0);
	}

	timeout = jiffies + msecs_to_jiffies(50);
	while (ispresizer_busy()) {
		msleep(5);
		if (time_after(jiffies, timeout)) {
			printk(KERN_ERR "ISP_RESZ_ERR: Resizer still busy");
			break;
		}
	}

	isp_reg_writel(0xFFFFFFFF, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
	isp_unset_callback(CBK_PREV_DONE);
	isp_unset_callback(CBK_RESZ_DONE);

exit_cleanup:
	isppreview_restore_context();
	ispresizer_restore_context();

	if (isp_addr_in != 0)
		ispmmu_vunmap(isp_addr_in);
	if (isp_addr_out != 0)
		ispmmu_vunmap(isp_addr_out);
	if (input_pages != NULL) {
		unmap_user_memory_from_kernel(input_pages, input_nr_pages);
		kfree(input_pages);
	}
	if (output_pages != NULL) {
		unmap_user_memory_from_kernel(output_pages, output_nr_pages);
		kfree(output_pages);
	}

	DPRINTK_ISPPROC("exit.\n");

	return ret;
}