blob: 155b1fddca8e6466b678c7c82886ecdfb91dd389 [file] [log] [blame]
Lucas Stachea1f5722017-01-16 16:09:51 +01001/*
2 * Copyright (C) 2017 Etnaviv Project
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "etnaviv_cmdbuf.h"
18#include "etnaviv_gpu.h"
19#include "etnaviv_mmu.h"
20
21struct etnaviv_cmdbuf *etnaviv_cmdbuf_new(struct etnaviv_gpu *gpu, u32 size,
22 size_t nr_bos)
23{
24 struct etnaviv_cmdbuf *cmdbuf;
25 size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]),
26 sizeof(*cmdbuf));
27
28 cmdbuf = kzalloc(sz, GFP_KERNEL);
29 if (!cmdbuf)
30 return NULL;
31
32 if (gpu->mmu->version == ETNAVIV_IOMMU_V2)
33 size = ALIGN(size, SZ_4K);
34
35 cmdbuf->vaddr = dma_alloc_wc(gpu->dev, size, &cmdbuf->paddr,
36 GFP_KERNEL);
37 if (!cmdbuf->vaddr) {
38 kfree(cmdbuf);
39 return NULL;
40 }
41
42 cmdbuf->gpu = gpu;
43 cmdbuf->size = size;
44
45 return cmdbuf;
46}
47
48void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf)
49{
50 etnaviv_iommu_put_cmdbuf_va(cmdbuf->gpu, cmdbuf);
51 dma_free_wc(cmdbuf->gpu->dev, cmdbuf->size, cmdbuf->vaddr,
52 cmdbuf->paddr);
53 kfree(cmdbuf);
54}
Lucas Stachc3ef4b82017-01-16 16:52:44 +010055
56u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf)
57{
58 return etnaviv_iommu_get_cmdbuf_va(buf->gpu, buf);
59}