blob: 53552150162c634e387c1c90b551abbcf1e8efdc [file] [log] [blame]
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -07001/* Copyright (c) 2012, 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 _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
Naveen Ramaraj55ed8902012-09-26 13:18:06 -0700139int ocmem_dump(int client_id, struct ocmem_buf *buffer,
140 unsigned long dst_phys_addr);
141
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700142/* Priority Enforcement APIs */
143int ocmem_evict(int client_id);
144
145int ocmem_restore(int client_id);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700146
147/* Power Control APIs */
148int ocmem_set_power_state(int client_id, struct ocmem_buf *buf,
149 enum ocmem_power_state new_state);
150
151enum ocmem_power_state ocmem_get_power_state(int client_id,
152 struct ocmem_buf *buf);
153
154struct ocmem_vectors *ocmem_get_vectors(int client_id,
155 struct ocmem_buf *buf);
Neeti Desaifecb8582012-11-12 12:15:14 -0800156
157#else
158/* Notification APIs */
159static inline struct ocmem_notifier *ocmem_notifier_register
160 (int client_id, struct notifier_block *nb)
161{
162 return ERR_PTR(-ENODEV);
163}
164
165static inline int ocmem_notifier_unregister(struct ocmem_notifier *notif_hndl,
166 struct notifier_block *nb)
167{
168 return -ENODEV;
169}
170
171/* Obtain the maximum quota for the client */
172static inline unsigned long get_max_quota(int client_id)
173{
174 return 0;
175}
176
177/* Allocation APIs */
178static inline struct ocmem_buf *ocmem_allocate(int client_id,
179 unsigned long size)
180{
181 return ERR_PTR(-ENODEV);
182}
183
184static inline struct ocmem_buf *ocmem_allocate_nowait(int client_id,
185 unsigned long size)
186{
187 return ERR_PTR(-ENODEV);
188}
189
190static inline struct ocmem_buf *ocmem_allocate_nb(int client_id,
191 unsigned long size)
192{
193 return ERR_PTR(-ENODEV);
194}
195
196static inline struct ocmem_buf *ocmem_allocate_range(int client_id,
197 unsigned long min, unsigned long goal, unsigned long step)
198{
199 return ERR_PTR(-ENODEV);
200}
201
202/* Free APIs */
203static inline int ocmem_free(int client_id, struct ocmem_buf *buf)
204{
205 return -ENODEV;
206}
207
208/* Dynamic Resize APIs */
209static inline int ocmem_shrink(int client_id, struct ocmem_buf *buf,
210 unsigned long new_size)
211{
212 return -ENODEV;
213}
214
215/* Transfer APIs */
216static inline int ocmem_map(int client_id, struct ocmem_buf *buffer,
217 struct ocmem_map_list *list)
218{
219 return -ENODEV;
220}
221
222static inline int ocmem_unmap(int client_id, struct ocmem_buf *buffer,
223 struct ocmem_map_list *list)
224{
225 return -ENODEV;
226}
227
228static inline int ocmem_dump(int client_id, struct ocmem_buf *buffer,
229 unsigned long dst_phys_addr)
230{
231 return -ENODEV;
232}
233
234/* Priority Enforcement APIs */
235static inline int ocmem_evict(int client_id)
236{
237 return -ENODEV;
238}
239
240static inline int ocmem_restore(int client_id)
241{
242 return -ENODEV;
243}
244
245/* Power Control APIs */
246static inline int ocmem_set_power_state(int client_id,
247 struct ocmem_buf *buf, enum ocmem_power_state new_state)
248{
249 return -ENODEV;
250}
251
252static inline enum ocmem_power_state ocmem_get_power_state(int client_id,
253 struct ocmem_buf *buf)
254{
255 return -ENODEV;
256}
257static inline struct ocmem_vectors *ocmem_get_vectors(int client_id,
258 struct ocmem_buf *buf)
259{
260 return ERR_PTR(-ENODEV);
261}
262#endif
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700263#endif