Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: rockchip/vpu: Cleanup JPEG bounce buffer management

In order to make the code more generic, introduce a pair of start/stop
codec operations, and use them to allocate and release the JPEG bounce
buffer.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
9d4e1f74 92cd4307

+84 -29
+2
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw.c
··· 98 98 [RK_VPU_MODE_JPEG_ENC] = { 99 99 .run = rk3288_vpu_jpeg_enc_run, 100 100 .reset = rk3288_vpu_enc_reset, 101 + .init = rockchip_vpu_jpeg_enc_init, 102 + .exit = rockchip_vpu_jpeg_enc_exit, 101 103 }, 102 104 }; 103 105
+2 -2
drivers/staging/media/rockchip/vpu/rk3288_vpu_hw_jpeg_enc.c
··· 37 37 38 38 WARN_ON(pix_fmt->num_planes > 3); 39 39 40 - vepu_write_relaxed(vpu, ctx->bounce_dma_addr, 40 + vepu_write_relaxed(vpu, ctx->jpeg_enc.bounce_buffer.dma, 41 41 VEPU_REG_ADDR_OUTPUT_STREAM); 42 - vepu_write_relaxed(vpu, ctx->bounce_size, 42 + vepu_write_relaxed(vpu, ctx->jpeg_enc.bounce_buffer.size, 43 43 VEPU_REG_STR_BUF_LIMIT); 44 44 45 45 if (pix_fmt->num_planes == 1) {
+2
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw.c
··· 98 98 [RK_VPU_MODE_JPEG_ENC] = { 99 99 .run = rk3399_vpu_jpeg_enc_run, 100 100 .reset = rk3399_vpu_enc_reset, 101 + .init = rockchip_vpu_jpeg_enc_init, 102 + .exit = rockchip_vpu_jpeg_enc_exit, 101 103 }, 102 104 }; 103 105
+2 -2
drivers/staging/media/rockchip/vpu/rk3399_vpu_hw_jpeg_enc.c
··· 69 69 70 70 WARN_ON(pix_fmt->num_planes > 3); 71 71 72 - vepu_write_relaxed(vpu, ctx->bounce_dma_addr, 72 + vepu_write_relaxed(vpu, ctx->jpeg_enc.bounce_buffer.dma, 73 73 VEPU_REG_ADDR_OUTPUT_STREAM); 74 - vepu_write_relaxed(vpu, ctx->bounce_size, 74 + vepu_write_relaxed(vpu, ctx->jpeg_enc.bounce_buffer.size, 75 75 VEPU_REG_STR_BUF_LIMIT); 76 76 77 77 if (pix_fmt->num_planes == 1) {
+5 -7
drivers/staging/media/rockchip/vpu/rockchip_vpu.h
··· 124 124 * @jpeg_quality: User-specified JPEG compression quality. 125 125 * 126 126 * @codec_ops: Set of operations related to codec mode. 127 - * 128 - * @bounce_dma_addr: Bounce buffer bus address. 129 - * @bounce_buf: Bounce buffer pointer. 130 - * @bounce_size: Bounce buffer size. 127 + * @jpeg_enc: JPEG-encoding context. 131 128 */ 132 129 struct rockchip_vpu_ctx { 133 130 struct rockchip_vpu_dev *dev; ··· 143 146 144 147 const struct rockchip_vpu_codec_ops *codec_ops; 145 148 146 - dma_addr_t bounce_dma_addr; 147 - void *bounce_buf; 148 - size_t bounce_size; 149 + /* Specific for particular codec modes. */ 150 + union { 151 + struct rockchip_vpu_jpeg_enc_hw_ctx jpeg_enc; 152 + }; 149 153 }; 150 154 151 155 /**
+7 -2
drivers/staging/media/rockchip/vpu/rockchip_vpu_drv.c
··· 63 63 avail_size = vb2_plane_size(&dst->vb2_buf, 0) - 64 64 ctx->vpu_dst_fmt->header_size; 65 65 if (bytesused <= avail_size) { 66 - if (ctx->bounce_buf) { 66 + /* 67 + * The bounce buffer is only for the JPEG encoder. 68 + * TODO: Rework the JPEG encoder to eliminate the need 69 + * for a bounce buffer. 70 + */ 71 + if (ctx->jpeg_enc.bounce_buffer.cpu) { 67 72 memcpy(vb2_plane_vaddr(&dst->vb2_buf, 0) + 68 73 ctx->vpu_dst_fmt->header_size, 69 - ctx->bounce_buf, bytesused); 74 + ctx->jpeg_enc.bounce_buffer.cpu, bytesused); 70 75 } 71 76 dst->vb2_buf.planes[0].bytesused = 72 77 ctx->vpu_dst_fmt->header_size + bytesused;
+7 -16
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c
··· 515 515 { 516 516 struct rockchip_vpu_ctx *ctx = vb2_get_drv_priv(q); 517 517 enum rockchip_vpu_codec_mode codec_mode; 518 + int ret = 0; 518 519 519 520 if (V4L2_TYPE_IS_OUTPUT(q->type)) 520 521 ctx->sequence_out = 0; ··· 528 527 vpu_debug(4, "Codec mode = %d\n", codec_mode); 529 528 ctx->codec_ops = &ctx->dev->variant->codec_ops[codec_mode]; 530 529 531 - /* A bounce buffer is needed for the JPEG payload */ 532 - if (!V4L2_TYPE_IS_OUTPUT(q->type)) { 533 - ctx->bounce_size = ctx->dst_fmt.plane_fmt[0].sizeimage - 534 - ctx->vpu_dst_fmt->header_size; 535 - ctx->bounce_buf = dma_alloc_attrs(ctx->dev->dev, 536 - ctx->bounce_size, 537 - &ctx->bounce_dma_addr, 538 - GFP_KERNEL, 539 - DMA_ATTR_ALLOC_SINGLE_PAGES); 540 - } 541 - return 0; 530 + if (!V4L2_TYPE_IS_OUTPUT(q->type)) 531 + if (ctx->codec_ops && ctx->codec_ops->init) 532 + ret = ctx->codec_ops->init(ctx); 533 + return ret; 542 534 } 543 535 544 536 static void rockchip_vpu_stop_streaming(struct vb2_queue *q) ··· 539 545 struct rockchip_vpu_ctx *ctx = vb2_get_drv_priv(q); 540 546 541 547 if (!V4L2_TYPE_IS_OUTPUT(q->type)) 542 - dma_free_attrs(ctx->dev->dev, 543 - ctx->bounce_size, 544 - ctx->bounce_buf, 545 - ctx->bounce_dma_addr, 546 - DMA_ATTR_ALLOC_SINGLE_PAGES); 548 + if (ctx->codec_ops && ctx->codec_ops->exit) 549 + ctx->codec_ops->exit(ctx); 547 550 548 551 /* 549 552 * The mem2mem framework calls v4l2_m2m_cancel_job before
+28
drivers/staging/media/rockchip/vpu/rockchip_vpu_hw.h
··· 19 19 struct rockchip_vpu_variant; 20 20 21 21 /** 22 + * struct rockchip_vpu_aux_buf - auxiliary DMA buffer for hardware data 23 + * @cpu: CPU pointer to the buffer. 24 + * @dma: DMA address of the buffer. 25 + * @size: Size of the buffer. 26 + */ 27 + struct rockchip_vpu_aux_buf { 28 + void *cpu; 29 + dma_addr_t dma; 30 + size_t size; 31 + }; 32 + 33 + /** 34 + * struct rockchip_vpu_jpeg_enc_hw_ctx 35 + * @bounce_buffer: Bounce buffer 36 + */ 37 + struct rockchip_vpu_jpeg_enc_hw_ctx { 38 + struct rockchip_vpu_aux_buf bounce_buffer; 39 + }; 40 + 41 + /** 22 42 * struct rockchip_vpu_codec_ops - codec mode specific operations 23 43 * 44 + * @init: If needed, can be used for initialization. 45 + * Optional and called from process context. 46 + * @exit: If needed, can be used to undo the .init phase. 47 + * Optional and called from process context. 24 48 * @run: Start single {en,de)coding job. Called from atomic context 25 49 * to indicate that a pair of buffers is ready and the hardware 26 50 * should be programmed and started. ··· 52 28 * @reset: Reset the hardware in case of a timeout. 53 29 */ 54 30 struct rockchip_vpu_codec_ops { 31 + int (*init)(struct rockchip_vpu_ctx *ctx); 32 + void (*exit)(struct rockchip_vpu_ctx *ctx); 55 33 void (*run)(struct rockchip_vpu_ctx *ctx); 56 34 void (*done)(struct rockchip_vpu_ctx *ctx, enum vb2_buffer_state); 57 35 void (*reset)(struct rockchip_vpu_ctx *ctx); ··· 80 54 81 55 void rk3288_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx); 82 56 void rk3399_vpu_jpeg_enc_run(struct rockchip_vpu_ctx *ctx); 57 + int rockchip_vpu_jpeg_enc_init(struct rockchip_vpu_ctx *ctx); 58 + void rockchip_vpu_jpeg_enc_exit(struct rockchip_vpu_ctx *ctx); 83 59 84 60 #endif /* ROCKCHIP_VPU_HW_H_ */
+29
drivers/staging/media/rockchip/vpu/rockchip_vpu_jpeg.c
··· 6 6 * Copyright (C) Jean-Francois Moine (http://moinejf.free.fr) 7 7 * Copyright (C) 2014 Philipp Zabel, Pengutronix 8 8 */ 9 + #include <linux/dma-mapping.h> 9 10 #include <linux/kernel.h> 10 11 #include <linux/string.h> 11 12 #include "rockchip_vpu_jpeg.h" 13 + #include "rockchip_vpu.h" 12 14 13 15 #define LUMA_QUANT_OFF 7 14 16 #define CHROMA_QUANT_OFF 72 ··· 289 287 sizeof(chroma_ac_table)); 290 288 291 289 jpeg_set_quality(buf, ctx->quality); 290 + } 291 + 292 + int rockchip_vpu_jpeg_enc_init(struct rockchip_vpu_ctx *ctx) 293 + { 294 + ctx->jpeg_enc.bounce_buffer.size = 295 + ctx->dst_fmt.plane_fmt[0].sizeimage - 296 + ctx->vpu_dst_fmt->header_size; 297 + 298 + ctx->jpeg_enc.bounce_buffer.cpu = 299 + dma_alloc_attrs(ctx->dev->dev, 300 + ctx->jpeg_enc.bounce_buffer.size, 301 + &ctx->jpeg_enc.bounce_buffer.dma, 302 + GFP_KERNEL, 303 + DMA_ATTR_ALLOC_SINGLE_PAGES); 304 + if (!ctx->jpeg_enc.bounce_buffer.cpu) 305 + return -ENOMEM; 306 + 307 + return 0; 308 + } 309 + 310 + void rockchip_vpu_jpeg_enc_exit(struct rockchip_vpu_ctx *ctx) 311 + { 312 + dma_free_attrs(ctx->dev->dev, 313 + ctx->jpeg_enc.bounce_buffer.size, 314 + ctx->jpeg_enc.bounce_buffer.cpu, 315 + ctx->jpeg_enc.bounce_buffer.dma, 316 + DMA_ATTR_ALLOC_SINGLE_PAGES); 292 317 }