/drivers/gpu/msm/kgsl_sharedmem.h
C Header | 122 lines | 70 code | 21 blank | 31 comment | 1 complexity | bccff7584f9beb5662bbd87a19ef0f6d MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
1/* Copyright (c) 2002,2007-2010, Code Aurora Forum. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#ifndef __GSL_SHAREDMEM_H
30#define __GSL_SHAREDMEM_H
31
32#include <linux/dma-mapping.h>
33
34#define KGSL_PAGESIZE 0x1000
35#define KGSL_PAGESIZE_SHIFT 12
36#define KGSL_PAGEMASK (~(KGSL_PAGESIZE - 1))
37
38struct kgsl_pagetable;
39
40/* Memflags for caching operations */
41#define KGSL_MEMFLAGS_CACHE_INV 0x00000001
42#define KGSL_MEMFLAGS_CACHE_FLUSH 0x00000002
43#define KGSL_MEMFLAGS_CACHE_CLEAN 0x00000004
44#define KGSL_MEMFLAGS_CACHE_MASK 0x0000000F
45
46/* Flags to differentiate memory types */
47#define KGSL_MEMFLAGS_CONPHYS 0x00001000
48#define KGSL_MEMFLAGS_VMALLOC_MEM 0x00002000
49#define KGSL_MEMFLAGS_HOSTADDR 0x00004000
50
51#define KGSL_MEMFLAGS_ALIGNANY 0x00000000
52#define KGSL_MEMFLAGS_ALIGN32 0x00000000
53#define KGSL_MEMFLAGS_ALIGN64 0x00060000
54#define KGSL_MEMFLAGS_ALIGN128 0x00070000
55#define KGSL_MEMFLAGS_ALIGN256 0x00080000
56#define KGSL_MEMFLAGS_ALIGN512 0x00090000
57#define KGSL_MEMFLAGS_ALIGN1K 0x000A0000
58#define KGSL_MEMFLAGS_ALIGN2K 0x000B0000
59#define KGSL_MEMFLAGS_ALIGN4K 0x000C0000
60#define KGSL_MEMFLAGS_ALIGN8K 0x000D0000
61#define KGSL_MEMFLAGS_ALIGN16K 0x000E0000
62#define KGSL_MEMFLAGS_ALIGN32K 0x000F0000
63#define KGSL_MEMFLAGS_ALIGN64K 0x00100000
64#define KGSL_MEMFLAGS_ALIGNPAGE KGSL_MEMFLAGS_ALIGN4K
65
66
67#define KGSL_MEMFLAGS_ALIGN_MASK 0x00FF0000
68#define KGSL_MEMFLAGS_ALIGN_SHIFT 16
69
70
71/* shared memory allocation */
72struct kgsl_memdesc {
73 struct kgsl_pagetable *pagetable;
74 void *hostptr;
75 unsigned int gpuaddr;
76 unsigned int physaddr;
77 unsigned int size;
78 unsigned int priv;
79};
80
81int kgsl_sharedmem_vmalloc(struct kgsl_memdesc *memdesc,
82 struct kgsl_pagetable *pagetable, size_t size);
83
84static inline int
85kgsl_sharedmem_alloc_coherent(struct kgsl_memdesc *memdesc, size_t size)
86{
87 size = ALIGN(size, KGSL_PAGESIZE);
88
89 memdesc->hostptr = dma_alloc_coherent(NULL, size, &memdesc->physaddr,
90 GFP_KERNEL);
91 if (!memdesc->hostptr)
92 return -ENOMEM;
93 memdesc->size = size;
94 memdesc->priv = KGSL_MEMFLAGS_CONPHYS;
95 return 0;
96}
97
98void kgsl_sharedmem_free(struct kgsl_memdesc *memdesc);
99
100int kgsl_sharedmem_readl(const struct kgsl_memdesc *memdesc,
101 uint32_t *dst,
102 unsigned int offsetbytes);
103
104int kgsl_sharedmem_read(const struct kgsl_memdesc *memdesc, void *dst,
105 unsigned int offsetbytes, unsigned int sizebytes);
106
107int kgsl_sharedmem_writel(const struct kgsl_memdesc *memdesc,
108 unsigned int offsetbytes,
109 uint32_t src);
110
111int kgsl_sharedmem_write(const struct kgsl_memdesc *memdesc,
112 unsigned int offsetbytes,
113 void *src, unsigned int sizebytes);
114
115int kgsl_sharedmem_set(const struct kgsl_memdesc *memdesc,
116 unsigned int offsetbytes, unsigned int value,
117 unsigned int sizebytes);
118
119void kgsl_cache_range_op(unsigned long addr, int size,
120 unsigned int flags);
121
122#endif /* __GSL_SHAREDMEM_H */