Beispiel #1
0
static int ispstat_bufs_alloc(struct ispstat *stat, u32 size)
{
	unsigned long flags;

	spin_lock_irqsave(&stat->isp->stat_lock, flags);

	BUG_ON(stat->locked_buf != NULL);

	/* Are the old buffers big enough? */
	if (stat->buf_alloc_size >= size) {
		spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
		return 0;
	}

	if (stat->state != ISPSTAT_DISABLED || stat->buf_processing) {
		dev_info(stat->isp->dev,
			 "%s: trying to allocate memory when busy\n",
			 stat->subdev.name);
		spin_unlock_irqrestore(&stat->isp->stat_lock, flags);
		return -EBUSY;
	}

	spin_unlock_irqrestore(&stat->isp->stat_lock, flags);

	ispstat_bufs_free(stat);

	if (IS_COHERENT_BUF(stat))
		return ispstat_bufs_alloc_dma(stat, size);
	else
		return ispstat_bufs_alloc_iommu(stat, size);
}
Beispiel #2
0
static int ispstat_bufs_alloc_dma(struct ispstat *stat, unsigned int size)
{
	int i;

	stat->buf_alloc_size = size;

	for (i = 0; i < STAT_MAX_BUFS; i++) {
		struct ispstat_buffer *buf = &stat->buf[i];

		WARN_ON(buf->iommu_addr);
		buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size,
					&buf->dma_addr, GFP_KERNEL | GFP_DMA);

		if (!buf->virt_addr || !buf->dma_addr) {
			dev_info(stat->isp->dev,
				 "%s: Can't acquire memory for "
				 "DMA buffer %d\n", stat->subdev.name, i);
			ispstat_bufs_free(stat);
			return -ENOMEM;
		}
		buf->empty = 1;

		dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated."
			"dma_addr=0x%08lx virt_addr=0x%08lx\n",
			stat->subdev.name, i, (unsigned long)buf->dma_addr,
			(unsigned long)buf->virt_addr);
	}

	return 0;
}
Beispiel #3
0
static int ispstat_bufs_alloc_dma(struct ispstat *stat, unsigned int size)
{
	int i;

	/* dma_alloc_coherent() size is PAGE_ALIGNED */
	size = PAGE_ALIGN(size);
	stat->buf_alloc_size = size;

	for (i = 0; i < stat->nbufs; i++) {
		struct ispstat_buffer *buf = &stat->buf[i];

		WARN_ON(buf->iommu_addr);
		buf->virt_addr = dma_alloc_coherent(stat->dev, size,
					&buf->dma_addr, GFP_KERNEL | GFP_DMA);

		if (!buf->virt_addr || !buf->dma_addr) {
			dev_info(stat->dev,
				 "%s stat: Can't acquire memory for "
				 "DMA buffer %d\n", stat->tag, i);
			ispstat_bufs_free(stat);
			return -ENOMEM;
		}
		buf->frame_number = stat->max_frame;
	}
	stat->dma_buf = 1;

	return 0;
}
Beispiel #4
0
static int ispstat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size)
{
	struct isp_device *isp = dev_get_drvdata(stat->dev);
	int i;

	stat->buf_alloc_size = size;

	for (i = 0; i < stat->nbufs; i++) {
		struct ispstat_buffer *buf = &stat->buf[i];

		WARN_ON(buf->dma_addr);
		buf->iommu_addr = iommu_vmalloc(isp->iommu, 0, size,
						IOMMU_FLAG);
		if (buf->iommu_addr == 0) {
			dev_err(stat->dev,
				 "%s stat: Can't acquire memory for "
				 "buffer %d\n", stat->tag, i);
			ispstat_bufs_free(stat);
			return -ENOMEM;
		}
		buf->virt_addr = da_to_va(isp->iommu, (u32)buf->iommu_addr);
		buf->frame_number = stat->max_frame;
	}
	stat->dma_buf = 0;

	return 0;
}
Beispiel #5
0
static int ispstat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size)
{
	struct isp_device *isp = dev_get_drvdata(stat->isp->dev);
	int i;

	stat->buf_alloc_size = size;

	for (i = 0; i < STAT_MAX_BUFS; i++) {
		struct ispstat_buffer *buf = &stat->buf[i];
		struct iovm_struct *iovm;

		WARN_ON(buf->dma_addr);
		buf->iommu_addr = iommu_vmalloc(isp->iommu, 0, size,
						IOMMU_FLAG);
		if (IS_ERR((void *)buf->iommu_addr)) {
			dev_err(stat->isp->dev,
				 "%s: Can't acquire memory for "
				 "buffer %d\n", stat->subdev.name, i);
			ispstat_bufs_free(stat);
			return -ENOMEM;
		}

		iovm = find_iovm_area(isp->iommu, buf->iommu_addr);
		if (!iovm ||
		    !dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents,
				DMA_FROM_DEVICE)) {
			ispstat_bufs_free(stat);
			return -ENOMEM;
		}
		buf->iovm = iovm;

		buf->virt_addr = da_to_va(stat->isp->iommu,
					  (u32)buf->iommu_addr);
		buf->empty = 1;
		dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated."
			"iommu_addr=0x%08lx virt_addr=0x%08lx",
			stat->subdev.name, i, buf->iommu_addr,
			(unsigned long)buf->virt_addr);
	}

	return 0;
}
Beispiel #6
0
int ispstat_bufs_alloc(struct ispstat *stat,
		       unsigned int size, int dma_buf)
{
	struct isp_device *isp = dev_get_drvdata(stat->dev);
	unsigned long flags;
	int ret = 0;
	int i;

	spin_lock_irqsave(&stat->lock, flags);

	BUG_ON(stat->locked_buf != NULL);

	dma_buf = dma_buf ? 1 : 0;

	/* Are the old buffers big enough? */
	if ((stat->buf_alloc_size >= size) && (stat->dma_buf == dma_buf)) {
		for (i = 0; i < stat->nbufs; i++)
			stat->buf[i].frame_number = stat->max_frame;
		spin_unlock_irqrestore(&stat->lock, flags);
		goto out;
	}

	if (isp->running != ISP_STOPPED) {
		dev_info(stat->dev,
			 "%s stat: trying to configure when busy\n",
			 stat->tag);
		spin_unlock_irqrestore(&stat->lock, flags);
		return -EBUSY;
	}

	spin_unlock_irqrestore(&stat->lock, flags);

	ispstat_bufs_free(stat);

	if (dma_buf)
		ret = ispstat_bufs_alloc_dma(stat, size);
	else
		ret = ispstat_bufs_alloc_iommu(stat, size);
	if (ret)
		size = 0;

out:
	stat->buf_size = size;
	stat->active_buf = NULL;

	return ret;
}
Beispiel #7
0
void ispstat_free(struct ispstat *stat)
{
	ispstat_bufs_free(stat);
	kfree(stat->buf);
}