1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Intel Corporation
4 #include <linux/device.h>
7 #include "ipu3-css-pool.h"
8 #include "ipu3-dmamap.h"
10 int ipu3_css_dma_buffer_resize(struct imgu_device *imgu,
11 struct ipu3_css_map *map, size_t size)
13 if (map->size < size && map->vaddr) {
14 dev_warn(&imgu->pci_dev->dev, "dma buf resized from %zu to %zu",
17 ipu3_dmamap_free(imgu, map);
18 if (!ipu3_dmamap_alloc(imgu, map, size))
25 void ipu3_css_pool_cleanup(struct imgu_device *imgu, struct ipu3_css_pool *pool)
29 for (i = 0; i < IPU3_CSS_POOL_SIZE; i++)
30 ipu3_dmamap_free(imgu, &pool->entry[i].param);
33 int ipu3_css_pool_init(struct imgu_device *imgu, struct ipu3_css_pool *pool,
38 for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) {
39 pool->entry[i].valid = false;
41 pool->entry[i].param.vaddr = NULL;
45 if (!ipu3_dmamap_alloc(imgu, &pool->entry[i].param, size))
49 pool->last = IPU3_CSS_POOL_SIZE;
54 ipu3_css_pool_cleanup(imgu, pool);
59 * Allocate a new parameter via recycling the oldest entry in the pool.
61 void ipu3_css_pool_get(struct ipu3_css_pool *pool)
63 /* Get the oldest entry */
64 u32 n = (pool->last + 1) % IPU3_CSS_POOL_SIZE;
66 pool->entry[n].valid = true;
71 * Undo, for all practical purposes, the effect of pool_get().
73 void ipu3_css_pool_put(struct ipu3_css_pool *pool)
75 pool->entry[pool->last].valid = false;
76 pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE;
80 * ipu3_css_pool_last - Retrieve the nth pool entry from last
82 * @pool: a pointer to &struct ipu3_css_pool.
83 * @n: the distance to the last index.
86 * The nth entry from last or null map to indicate no frame stored.
88 const struct ipu3_css_map *
89 ipu3_css_pool_last(struct ipu3_css_pool *pool, unsigned int n)
91 static const struct ipu3_css_map null_map = { 0 };
92 int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE;
94 WARN_ON(n >= IPU3_CSS_POOL_SIZE);
96 if (!pool->entry[i].valid)
99 return &pool->entry[i].param;