blob: 92ae6b675d130edbc7f027d4c824cee629b4dce7 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -07002 *
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 _ARCH_ARM_MACH_MSM_OCMEM_H
14#define _ARCH_ARM_MACH_MSM_OCMEM_H
15
16#include <asm/page.h>
17#include <linux/module.h>
18#include <linux/notifier.h>
Neeti Desaifecb8582012-11-12 12:15:14 -080019#include <linux/err.h>
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070020
21#define OCMEM_MIN_ALLOC SZ_64K
22#define OCMEM_MIN_ALIGN SZ_64K
23
24/* Maximum number of slots in DM */
25#define OCMEM_MAX_CHUNKS 32
Naveen Ramaraj66522592012-11-19 11:33:09 -080026#define MIN_CHUNK_SIZE SZ_4K
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070027
Naveen Ramaraj6b882652012-06-28 16:07:09 -070028struct ocmem_notifier;
29
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070030struct ocmem_buf {
31 unsigned long addr;
32 unsigned long len;
33};
34
35struct ocmem_buf_attr {
36 unsigned long paddr;
37 unsigned long len;
38};
39
40struct ocmem_chunk {
41 bool ro;
42 unsigned long ddr_paddr;
43 unsigned long size;
44};
45
46struct ocmem_map_list {
Naveen Ramaraj0f5e7ab2012-04-24 19:10:23 -070047 unsigned num_chunks;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070048 struct ocmem_chunk chunks[OCMEM_MAX_CHUNKS];
49};
50
Naveen Ramaraj99b07562012-05-28 20:57:09 -070051enum ocmem_power_state {
52 OCMEM_OFF = 0x0,
53 OCMEM_RETENTION,
54 OCMEM_ON,
55 OCMEM_MAX = OCMEM_ON,
56};
57
58struct ocmem_resource {
59 unsigned resource_id;
60 unsigned num_keys;
61 unsigned int *keys;
62};
63
64struct ocmem_vectors {
65 unsigned num_resources;
66 struct ocmem_resource *r;
67};
68
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070069/* List of clients that allocate/interact with OCMEM */
70/* Must be in sync with client_names */
71enum ocmem_client {
72 /* GMEM clients */
73 OCMEM_GRAPHICS = 0x0,
74 /* TCMEM clients */
75 OCMEM_VIDEO,
76 OCMEM_CAMERA,
77 /* Dummy Clients */
78 OCMEM_HP_AUDIO,
79 OCMEM_VOICE,
80 /* IMEM Clients */
81 OCMEM_LP_AUDIO,
82 OCMEM_SENSORS,
Naveen Ramarajcc4ec152012-05-14 09:55:29 -070083 OCMEM_OTHER_OS,
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070084 OCMEM_CLIENT_MAX,
85};
86
87/**
88 * List of OCMEM notification events which will be broadcasted
89 * to clients that optionally register for these notifications
90 * on a per allocation basis.
91 **/
92enum ocmem_notif_type {
93 OCMEM_MAP_DONE = 1,
94 OCMEM_MAP_FAIL,
95 OCMEM_UNMAP_DONE,
96 OCMEM_UNMAP_FAIL,
97 OCMEM_ALLOC_GROW,
98 OCMEM_ALLOC_SHRINK,
99 OCMEM_NOTIF_TYPE_COUNT,
100};
101
102/* APIS */
Neeti Desaifecb8582012-11-12 12:15:14 -0800103#ifdef CONFIG_MSM_OCMEM
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700104/* Notification APIs */
Naveen Ramaraj6b882652012-06-28 16:07:09 -0700105struct ocmem_notifier *ocmem_notifier_register(int client_id,
106 struct notifier_block *nb);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700107
Naveen Ramaraj6b882652012-06-28 16:07:09 -0700108int ocmem_notifier_unregister(struct ocmem_notifier *notif_hndl,
109 struct notifier_block *nb);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700110
Naveen Ramaraj0f5e7ab2012-04-24 19:10:23 -0700111/* Obtain the maximum quota for the client */
112unsigned long get_max_quota(int client_id);
113
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700114/* Allocation APIs */
115struct ocmem_buf *ocmem_allocate(int client_id, unsigned long size);
116
Naveen Ramaraj0f5e7ab2012-04-24 19:10:23 -0700117struct ocmem_buf *ocmem_allocate_nowait(int client_id, unsigned long size);
118
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700119struct ocmem_buf *ocmem_allocate_nb(int client_id, unsigned long size);
120
121struct ocmem_buf *ocmem_allocate_range(int client_id, unsigned long min,
122 unsigned long goal, unsigned long step);
123
124/* Free APIs */
125int ocmem_free(int client_id, struct ocmem_buf *buf);
126
127/* Dynamic Resize APIs */
128int ocmem_shrink(int client_id, struct ocmem_buf *buf,
129 unsigned long new_size);
130
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700131/* Transfer APIs */
132int ocmem_map(int client_id, struct ocmem_buf *buffer,
133 struct ocmem_map_list *list);
134
135
136int ocmem_unmap(int client_id, struct ocmem_buf *buffer,
137 struct ocmem_map_list *list);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700138
Neeti Desaidad1d8e2013-01-09 19:42:06 -0800139int ocmem_drop(int client_id, struct ocmem_buf *buffer,
140 struct ocmem_map_list *list);
141
Naveen Ramaraj55ed8902012-09-26 13:18:06 -0700142int ocmem_dump(int client_id, struct ocmem_buf *buffer,
143 unsigned long dst_phys_addr);
144
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700145/* Priority Enforcement APIs */
146int ocmem_evict(int client_id);
147
148int ocmem_restore(int client_id);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700149
150/* Power Control APIs */
151int ocmem_set_power_state(int client_id, struct ocmem_buf *buf,
152 enum ocmem_power_state new_state);
153
154enum ocmem_power_state ocmem_get_power_state(int client_id,
155 struct ocmem_buf *buf);
156
157struct ocmem_vectors *ocmem_get_vectors(int client_id,
158 struct ocmem_buf *buf);
Neeti Desaifecb8582012-11-12 12:15:14 -0800159
160#else
161/* Notification APIs */
162static inline struct ocmem_notifier *ocmem_notifier_register
163 (int client_id, struct notifier_block *nb)
164{
165 return ERR_PTR(-ENODEV);
166}
167
168static inline int ocmem_notifier_unregister(struct ocmem_notifier *notif_hndl,
169 struct notifier_block *nb)
170{
171 return -ENODEV;
172}
173
174/* Obtain the maximum quota for the client */
175static inline unsigned long get_max_quota(int client_id)
176{
177 return 0;
178}
179
180/* Allocation APIs */
181static inline struct ocmem_buf *ocmem_allocate(int client_id,
182 unsigned long size)
183{
184 return ERR_PTR(-ENODEV);
185}
186
187static inline struct ocmem_buf *ocmem_allocate_nowait(int client_id,
188 unsigned long size)
189{
190 return ERR_PTR(-ENODEV);
191}
192
193static inline struct ocmem_buf *ocmem_allocate_nb(int client_id,
194 unsigned long size)
195{
196 return ERR_PTR(-ENODEV);
197}
198
199static inline struct ocmem_buf *ocmem_allocate_range(int client_id,
200 unsigned long min, unsigned long goal, unsigned long step)
201{
202 return ERR_PTR(-ENODEV);
203}
204
205/* Free APIs */
206static inline int ocmem_free(int client_id, struct ocmem_buf *buf)
207{
208 return -ENODEV;
209}
210
211/* Dynamic Resize APIs */
212static inline int ocmem_shrink(int client_id, struct ocmem_buf *buf,
213 unsigned long new_size)
214{
215 return -ENODEV;
216}
217
218/* Transfer APIs */
219static inline int ocmem_map(int client_id, struct ocmem_buf *buffer,
220 struct ocmem_map_list *list)
221{
222 return -ENODEV;
223}
224
225static inline int ocmem_unmap(int client_id, struct ocmem_buf *buffer,
226 struct ocmem_map_list *list)
227{
228 return -ENODEV;
229}
230
231static inline int ocmem_dump(int client_id, struct ocmem_buf *buffer,
232 unsigned long dst_phys_addr)
233{
234 return -ENODEV;
235}
236
237/* Priority Enforcement APIs */
238static inline int ocmem_evict(int client_id)
239{
240 return -ENODEV;
241}
242
243static inline int ocmem_restore(int client_id)
244{
245 return -ENODEV;
246}
247
248/* Power Control APIs */
249static inline int ocmem_set_power_state(int client_id,
250 struct ocmem_buf *buf, enum ocmem_power_state new_state)
251{
252 return -ENODEV;
253}
254
255static inline enum ocmem_power_state ocmem_get_power_state(int client_id,
256 struct ocmem_buf *buf)
257{
258 return -ENODEV;
259}
260static inline struct ocmem_vectors *ocmem_get_vectors(int client_id,
261 struct ocmem_buf *buf)
262{
263 return ERR_PTR(-ENODEV);
264}
265#endif
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700266#endif