0001
0002
0003
0004 #include <linux/device.h>
0005
0006 #include "ipu3.h"
0007 #include "ipu3-css-pool.h"
0008 #include "ipu3-dmamap.h"
0009
0010 int imgu_css_dma_buffer_resize(struct imgu_device *imgu,
0011 struct imgu_css_map *map, size_t size)
0012 {
0013 if (map->size < size && map->vaddr) {
0014 dev_warn(&imgu->pci_dev->dev, "dma buf resized from %zu to %zu",
0015 map->size, size);
0016
0017 imgu_dmamap_free(imgu, map);
0018 if (!imgu_dmamap_alloc(imgu, map, size))
0019 return -ENOMEM;
0020 }
0021
0022 return 0;
0023 }
0024
0025 void imgu_css_pool_cleanup(struct imgu_device *imgu, struct imgu_css_pool *pool)
0026 {
0027 unsigned int i;
0028
0029 for (i = 0; i < IPU3_CSS_POOL_SIZE; i++)
0030 imgu_dmamap_free(imgu, &pool->entry[i].param);
0031 }
0032
0033 int imgu_css_pool_init(struct imgu_device *imgu, struct imgu_css_pool *pool,
0034 size_t size)
0035 {
0036 unsigned int i;
0037
0038 for (i = 0; i < IPU3_CSS_POOL_SIZE; i++) {
0039 pool->entry[i].valid = false;
0040 if (size == 0) {
0041 pool->entry[i].param.vaddr = NULL;
0042 continue;
0043 }
0044
0045 if (!imgu_dmamap_alloc(imgu, &pool->entry[i].param, size))
0046 goto fail;
0047 }
0048
0049 pool->last = IPU3_CSS_POOL_SIZE;
0050
0051 return 0;
0052
0053 fail:
0054 imgu_css_pool_cleanup(imgu, pool);
0055 return -ENOMEM;
0056 }
0057
0058
0059
0060
0061 void imgu_css_pool_get(struct imgu_css_pool *pool)
0062 {
0063
0064 u32 n = (pool->last + 1) % IPU3_CSS_POOL_SIZE;
0065
0066 pool->entry[n].valid = true;
0067 pool->last = n;
0068 }
0069
0070
0071
0072
0073 void imgu_css_pool_put(struct imgu_css_pool *pool)
0074 {
0075 pool->entry[pool->last].valid = false;
0076 pool->last = (pool->last + IPU3_CSS_POOL_SIZE - 1) % IPU3_CSS_POOL_SIZE;
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 const struct imgu_css_map *
0089 imgu_css_pool_last(struct imgu_css_pool *pool, unsigned int n)
0090 {
0091 static const struct imgu_css_map null_map = { 0 };
0092 int i = (pool->last + IPU3_CSS_POOL_SIZE - n) % IPU3_CSS_POOL_SIZE;
0093
0094 WARN_ON(n >= IPU3_CSS_POOL_SIZE);
0095
0096 if (!pool->entry[i].valid)
0097 return &null_map;
0098
0099 return &pool->entry[i].param;
0100 }