blob: 9e57e78c061dbf00c069809bde8ed7792ae264f1 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2002,2007-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#ifndef __KGSL_SHAREDMEM_H
14#define __KGSL_SHAREDMEM_H
15
16#include <linux/dma-mapping.h>
17
18struct kgsl_device;
19struct kgsl_process_private;
20
21#define KGSL_CACHE_OP_INV 0x01
22#define KGSL_CACHE_OP_FLUSH 0x02
23#define KGSL_CACHE_OP_CLEAN 0x03
24
25/** Set if the memdesc describes cached memory */
26#define KGSL_MEMFLAGS_CACHED 0x00000001
27
28struct kgsl_memdesc_ops {
29 unsigned long (*physaddr)(struct kgsl_memdesc *, unsigned int);
30 void (*outer_cache)(struct kgsl_memdesc *, int);
31 int (*vmflags)(struct kgsl_memdesc *);
32 int (*vmfault)(struct kgsl_memdesc *, struct vm_area_struct *,
33 struct vm_fault *);
34 void (*free)(struct kgsl_memdesc *memdesc);
35};
36
37extern struct kgsl_memdesc_ops kgsl_vmalloc_ops;
38extern struct kgsl_memdesc_ops kgsl_contiguous_ops;
39extern struct kgsl_memdesc_ops kgsl_userptr_ops;
40
41int kgsl_sharedmem_vmalloc(struct kgsl_memdesc *memdesc,
42 struct kgsl_pagetable *pagetable, size_t size);
43
44int kgsl_sharedmem_vmalloc_user(struct kgsl_memdesc *memdesc,
45 struct kgsl_pagetable *pagetable,
46 size_t size, int flags);
47
48int kgsl_sharedmem_alloc_coherent(struct kgsl_memdesc *memdesc, size_t size);
49
50int kgsl_sharedmem_ebimem_user(struct kgsl_memdesc *memdesc,
51 struct kgsl_pagetable *pagetable,
52 size_t size, int flags);
53
54int kgsl_sharedmem_ebimem(struct kgsl_memdesc *memdesc,
55 struct kgsl_pagetable *pagetable,
56 size_t size);
57
58void kgsl_sharedmem_free(struct kgsl_memdesc *memdesc);
59
60int kgsl_sharedmem_readl(const struct kgsl_memdesc *memdesc,
61 uint32_t *dst,
62 unsigned int offsetbytes);
63
64int kgsl_sharedmem_writel(const struct kgsl_memdesc *memdesc,
65 unsigned int offsetbytes,
66 uint32_t src);
67
68int kgsl_sharedmem_set(const struct kgsl_memdesc *memdesc,
69 unsigned int offsetbytes, unsigned int value,
70 unsigned int sizebytes);
71
72void kgsl_cache_range_op(struct kgsl_memdesc *memdesc, int op);
73
74void kgsl_process_init_sysfs(struct kgsl_process_private *private);
75void kgsl_process_uninit_sysfs(struct kgsl_process_private *private);
76
77int kgsl_sharedmem_init_sysfs(void);
78void kgsl_sharedmem_uninit_sysfs(void);
79
80static inline int
81kgsl_allocate(struct kgsl_memdesc *memdesc,
82 struct kgsl_pagetable *pagetable, size_t size)
83{
84#ifdef CONFIG_MSM_KGSL_MMU
85 return kgsl_sharedmem_vmalloc(memdesc, pagetable, size);
86#else
87 return kgsl_sharedmem_ebimem(memdesc, pagetable, size);
88#endif
89}
90
91static inline int
92kgsl_allocate_user(struct kgsl_memdesc *memdesc,
93 struct kgsl_pagetable *pagetable,
94 size_t size, unsigned int flags)
95{
96#ifdef CONFIG_MSM_KGSL_MMU
97 return kgsl_sharedmem_vmalloc_user(memdesc, pagetable, size, flags);
98#else
99 return kgsl_sharedmem_ebimem_user(memdesc, pagetable, size, flags);
100#endif
101}
102
103static inline int
104kgsl_allocate_contiguous(struct kgsl_memdesc *memdesc, size_t size)
105{
106 int ret = kgsl_sharedmem_alloc_coherent(memdesc, size);
107#ifndef CONFIG_MSM_KGSL_MMU
108 if (!ret)
109 memdesc->gpuaddr = memdesc->physaddr;
110#endif
111 return ret;
112}
113
114#endif /* __KGSL_SHAREDMEM_H */