static int buffer_prepare(struct vb2_buffer *vb) { struct cx23885_dev *dev = vb->vb2_queue->drv_priv; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); unsigned lines = VBI_PAL_LINE_COUNT; int ret; if (dev->tvnorm & V4L2_STD_525_60) lines = VBI_NTSC_LINE_COUNT; if (vb2_plane_size(vb, 0) < lines * VBI_LINE_LENGTH * 2) return -EINVAL; vb2_set_plane_payload(vb, 0, lines * VBI_LINE_LENGTH * 2); ret = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); if (!ret) return -EIO; cx23885_risc_vbibuffer(dev->pci, &buf->risc, sgt->sgl, 0, VBI_LINE_LENGTH * lines, VBI_LINE_LENGTH, 0, lines); return 0; }
static int video_buf_init(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); struct camss_video *video = vb2_get_drv_priv(vb->vb2_queue); struct camss_buffer *buffer = container_of(vbuf, struct camss_buffer, vb); const struct v4l2_pix_format_mplane *format = &video->active_fmt.fmt.pix_mp; struct sg_table *sgt; unsigned int i; for (i = 0; i < format->num_planes; i++) { sgt = vb2_dma_sg_plane_desc(vb, i); if (!sgt) return -EFAULT; buffer->addr[i] = sg_dma_address(sgt->sgl); } if (format->pixelformat == V4L2_PIX_FMT_NV12 || format->pixelformat == V4L2_PIX_FMT_NV21 || format->pixelformat == V4L2_PIX_FMT_NV16 || format->pixelformat == V4L2_PIX_FMT_NV61) buffer->addr[1] = buffer->addr[0] + format->plane_fmt[0].bytesperline * format->height; return 0; }
unsigned long saa7134_buffer_base(struct saa7134_buf *buf) { unsigned long base; struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); base = saa7134_buffer_startpage(buf) * 4096; base += dma->sgl[0].offset; return base; }
static int fthd_buffer_prepare(struct vb2_buffer *vb) { struct fthd_private *dev_priv = vb2_get_drv_priv(vb->vb2_queue); struct sg_table *sgtable; struct h2t_buf_ctx *ctx = NULL; struct dma_descriptor_list *dma_list; int i; pr_debug("%p\n", vb); for(i = 0; i < FTHD_BUFFERS; i++) { if (dev_priv->h2t_bufs[i].state == BUF_FREE || (dev_priv->h2t_bufs[i].state == BUF_ALLOC && dev_priv->h2t_bufs[i].vb == vb)) { ctx = dev_priv->h2t_bufs + i; break; } } if (!ctx) return -ENOBUFS; if (ctx->state == BUF_FREE) { pr_debug("allocating new entry\n"); ctx->dma_desc_obj = isp_mem_create(dev_priv, FTHD_MEM_BUFFER, 0x180); if (!ctx->dma_desc_obj) return -ENOMEM; ctx->vb = vb; ctx->state = BUF_ALLOC; for(i = 0; i < dev_priv->fmt.planes; i++) { sgtable = vb2_dma_sg_plane_desc(vb, i); ctx->plane[i] = iommu_allocate_sgtable(dev_priv, sgtable); if(!ctx->plane[i]) return -ENOMEM; } } vb2_set_plane_payload(vb, 0, dev_priv->fmt.fmt.sizeimage); dma_list = &ctx->dma_desc_list; memset(dma_list, 0, 0x180); dma_list->field0 = 1; dma_list->count = 1; dma_list->desc[0].count = 1; dma_list->desc[0].pool = 0x02; dma_list->desc[0].addr0 = (ctx->plane[0]->offset << 12) | 0xc0000000; if (dev_priv->fmt.planes >= 2) dma_list->desc[0].addr1 = (ctx->plane[1]->offset << 12) | 0xc0000000; if (dev_priv->fmt.planes >= 3) dma_list->desc[0].addr2 = (ctx->plane[2]->offset << 12) | 0xc0000000; dma_list->desc[0].tag = (u64)ctx; init_waitqueue_head(&ctx->wq); return 0; }
static void buffer_finish(struct vb2_buffer *vb) { struct cx23885_dev *dev = vb->vb2_queue->drv_priv; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); cx23885_free_buffer(vb->vb2_queue->drv_priv, buf); dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); }
static int buffer_prepare(struct vb2_buffer *vb) { struct cx8800_dev *dev = vb->vb2_queue->drv_priv; struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); unsigned int lines; unsigned int size; if (dev->core->tvnorm & V4L2_STD_525_60) lines = VBI_LINE_NTSC_COUNT; else lines = VBI_LINE_PAL_COUNT; size = lines * VBI_LINE_LENGTH * 2; if (vb2_plane_size(vb, 0) < size) return -EINVAL; vb2_set_plane_payload(vb, 0, size); cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl, 0, VBI_LINE_LENGTH * lines, VBI_LINE_LENGTH, 0, lines); return 0; }