Naveen Ramaraj | 8973895 | 2013-02-13 15:24:57 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 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 | #include <linux/slab.h> |
| 14 | #include <mach/ocmem_priv.h> |
| 15 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 16 | static DEFINE_MUTEX(ocmem_eviction_lock); |
| 17 | static DECLARE_BITMAP(evicted, OCMEM_CLIENT_MAX); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 18 | |
| 19 | static struct ocmem_handle *generate_handle(void) |
| 20 | { |
| 21 | struct ocmem_handle *handle = NULL; |
| 22 | |
| 23 | handle = kzalloc(sizeof(struct ocmem_handle), GFP_KERNEL); |
| 24 | if (!handle) { |
| 25 | pr_err("ocmem: Unable to generate buffer handle\n"); |
| 26 | return NULL; |
| 27 | } |
| 28 | mutex_init(&handle->handle_mutex); |
| 29 | return handle; |
| 30 | } |
| 31 | |
| 32 | static int free_handle(struct ocmem_handle *handle) |
| 33 | { |
| 34 | if (!handle) |
| 35 | return -EINVAL; |
| 36 | |
| 37 | mutex_destroy(&handle->handle_mutex); |
| 38 | kfree(handle); |
| 39 | handle = NULL; |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int __ocmem_free(int id, struct ocmem_buf *buf) |
| 44 | { |
| 45 | int ret = 0; |
| 46 | struct ocmem_handle *handle = buffer_to_handle(buf); |
| 47 | |
| 48 | if (!handle) |
| 49 | return -EINVAL; |
| 50 | |
| 51 | mutex_lock(&handle->handle_mutex); |
| 52 | ret = process_free(id, handle); |
| 53 | mutex_unlock(&handle->handle_mutex); |
| 54 | |
Naveen Ramaraj | 8973895 | 2013-02-13 15:24:57 -0800 | [diff] [blame] | 55 | if (ret) { |
| 56 | pr_err("ocmem: Free failed for client %s\n", get_name(id)); |
| 57 | return ret; |
| 58 | } |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 59 | free_handle(handle); |
| 60 | return 0; |
| 61 | } |
| 62 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 63 | static int __ocmem_shrink(int id, struct ocmem_buf *buf, unsigned long len) |
| 64 | { |
| 65 | int ret = 0; |
| 66 | struct ocmem_handle *handle = buffer_to_handle(buf); |
| 67 | |
| 68 | if (!handle) |
| 69 | return -EINVAL; |
| 70 | |
| 71 | mutex_lock(&handle->handle_mutex); |
| 72 | ret = process_shrink(id, handle, len); |
| 73 | mutex_unlock(&handle->handle_mutex); |
| 74 | |
| 75 | if (ret) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 81 | static struct ocmem_buf *__ocmem_allocate_range(int id, unsigned long min, |
| 82 | unsigned long max, unsigned long step, bool block, bool wait) |
| 83 | { |
| 84 | struct ocmem_handle *handle = NULL; |
| 85 | int ret = 0; |
| 86 | |
| 87 | handle = generate_handle(); |
| 88 | if (!handle) { |
| 89 | pr_err("ocmem: Unable to generate handle\n"); |
| 90 | return NULL; |
| 91 | } |
| 92 | |
| 93 | mutex_lock(&handle->handle_mutex); |
| 94 | ret = process_allocate(id, handle, min, max, step, block, wait); |
| 95 | mutex_unlock(&handle->handle_mutex); |
| 96 | if (ret) { |
| 97 | pr_err("ocmem allocation failed\n"); |
| 98 | free_handle(handle); |
| 99 | return NULL; |
| 100 | } else |
| 101 | return handle_to_buffer(handle); |
| 102 | } |
| 103 | |
| 104 | struct ocmem_buf *ocmem_allocate(int client_id, unsigned long size) |
| 105 | { |
| 106 | bool can_block = false; |
| 107 | bool can_wait = true; |
| 108 | |
| 109 | if (!check_id(client_id)) { |
| 110 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 111 | return NULL; |
| 112 | } |
| 113 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 114 | if (!zone_active(client_id)) { |
| 115 | pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n", |
| 116 | get_name(client_id), client_id); |
| 117 | return NULL; |
| 118 | } |
| 119 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 120 | if (size < OCMEM_MIN_ALLOC) { |
| 121 | pr_err("ocmem: requested size %lx must be at least %x\n", |
| 122 | size, OCMEM_MIN_ALLOC); |
| 123 | return NULL; |
| 124 | } |
| 125 | |
| 126 | if (!IS_ALIGNED(size, OCMEM_MIN_ALIGN)) { |
| 127 | pr_err("ocmem: Invalid alignment, size must be %x aligned\n", |
| 128 | OCMEM_MIN_ALIGN); |
| 129 | return NULL; |
| 130 | } |
| 131 | |
| 132 | return __ocmem_allocate_range(client_id, size, size, |
| 133 | size, can_block, can_wait); |
| 134 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 135 | EXPORT_SYMBOL(ocmem_allocate); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 136 | |
| 137 | struct ocmem_buf *ocmem_allocate_nowait(int client_id, unsigned long size) |
| 138 | { |
| 139 | bool can_block = false; |
| 140 | bool can_wait = false; |
| 141 | |
| 142 | if (!check_id(client_id)) { |
| 143 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 144 | return NULL; |
| 145 | } |
| 146 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 147 | if (!zone_active(client_id)) { |
| 148 | pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n", |
| 149 | get_name(client_id), client_id); |
| 150 | return NULL; |
| 151 | } |
| 152 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 153 | if (size < OCMEM_MIN_ALLOC) { |
| 154 | pr_err("ocmem: requested size %lx must be at least %x\n", |
| 155 | size, OCMEM_MIN_ALLOC); |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | if (!IS_ALIGNED(size, OCMEM_MIN_ALIGN)) { |
| 160 | pr_err("ocmem: Invalid alignment, size must be %x aligned\n", |
| 161 | OCMEM_MIN_ALIGN); |
| 162 | return NULL; |
| 163 | } |
| 164 | return __ocmem_allocate_range(client_id, size, size, |
| 165 | size, can_block, can_wait); |
| 166 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 167 | EXPORT_SYMBOL(ocmem_allocate_nowait); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 168 | |
| 169 | struct ocmem_buf *ocmem_allocate_range(int client_id, unsigned long min, |
| 170 | unsigned long goal, unsigned long step) |
| 171 | { |
| 172 | bool can_block = true; |
| 173 | bool can_wait = false; |
| 174 | |
| 175 | if (!check_id(client_id)) { |
| 176 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 177 | return NULL; |
| 178 | } |
| 179 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 180 | if (!zone_active(client_id)) { |
| 181 | pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n", |
| 182 | get_name(client_id), client_id); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 186 | /* Asynchronous API requires notifier registration */ |
| 187 | if (!check_notifier(client_id)) { |
| 188 | pr_err("ocmem: No notifier registered for client %d\n", |
| 189 | client_id); |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | if (min < OCMEM_MIN_ALLOC) { |
| 194 | pr_err("ocmem: requested min size %lx must be at least %x\n", |
| 195 | min, OCMEM_MIN_ALLOC); |
| 196 | return NULL; |
| 197 | } |
| 198 | |
| 199 | if (!IS_ALIGNED(min | goal | step, OCMEM_MIN_ALIGN)) { |
| 200 | pr_err("ocmem: Invalid alignment, args must be %x aligned\n", |
| 201 | OCMEM_MIN_ALIGN); |
| 202 | return NULL; |
| 203 | } |
| 204 | |
| 205 | return __ocmem_allocate_range(client_id, min, goal, |
| 206 | step, can_block, can_wait); |
| 207 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 208 | EXPORT_SYMBOL(ocmem_allocate_range); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 209 | |
| 210 | struct ocmem_buf *ocmem_allocate_nb(int client_id, unsigned long size) |
| 211 | { |
| 212 | bool can_block = true; |
| 213 | bool can_wait = false; |
| 214 | |
| 215 | if (!check_id(client_id)) { |
| 216 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | /* Asynchronous API requires notifier registration */ |
| 221 | if (!check_notifier(client_id)) { |
| 222 | pr_err("ocmem: No notifier registered for client %d\n", |
| 223 | client_id); |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 227 | if (!zone_active(client_id)) { |
| 228 | pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n", |
| 229 | get_name(client_id), client_id); |
| 230 | return NULL; |
| 231 | } |
| 232 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 233 | if (size < OCMEM_MIN_ALLOC) { |
| 234 | pr_err("ocmem: requested size %lx must be at least %x\n", |
| 235 | size, OCMEM_MIN_ALLOC); |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | if (!IS_ALIGNED(size, OCMEM_MIN_ALIGN)) { |
| 240 | pr_err("ocmem: Invalid alignment, args must be %x aligned\n", |
| 241 | OCMEM_MIN_ALIGN); |
| 242 | return NULL; |
| 243 | } |
| 244 | |
| 245 | return __ocmem_allocate_range(client_id, 0, size, size, |
| 246 | can_block, can_wait); |
| 247 | |
| 248 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 249 | EXPORT_SYMBOL(ocmem_allocate_nb); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 250 | |
| 251 | int ocmem_free(int client_id, struct ocmem_buf *buffer) |
| 252 | { |
| 253 | if (!check_id(client_id)) { |
| 254 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 258 | if (!zone_active(client_id)) { |
| 259 | pr_err("ocmem: Client %s (id: %d) not allowed to use OCMEM\n", |
| 260 | get_name(client_id), client_id); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 264 | if (!buffer) { |
| 265 | pr_err("ocmem: Invalid buffer\n"); |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
| 269 | return __ocmem_free(client_id, buffer); |
| 270 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 271 | EXPORT_SYMBOL(ocmem_free); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 272 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 273 | int ocmem_shrink(int client_id, struct ocmem_buf *buffer, unsigned long len) |
| 274 | { |
| 275 | if (!buffer) |
| 276 | return -EINVAL; |
| 277 | if (len >= buffer->len) |
| 278 | return -EINVAL; |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 279 | |
| 280 | if (!zone_active(client_id)) { |
| 281 | pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n", |
| 282 | get_name(client_id), client_id); |
| 283 | return -EINVAL; |
| 284 | } |
| 285 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 286 | return __ocmem_shrink(client_id, buffer, len); |
| 287 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 288 | EXPORT_SYMBOL(ocmem_shrink); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 289 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 290 | int pre_validate_chunk_list(struct ocmem_map_list *list) |
| 291 | { |
| 292 | int i = 0; |
| 293 | struct ocmem_chunk *chunks; |
| 294 | |
| 295 | if (!list) |
| 296 | return -EINVAL; |
| 297 | |
| 298 | if (list->num_chunks > OCMEM_MAX_CHUNKS || list->num_chunks == 0) |
| 299 | return -EINVAL; |
| 300 | |
| 301 | chunks = list->chunks; |
| 302 | |
| 303 | if (!chunks) |
| 304 | return -EINVAL; |
| 305 | |
| 306 | for (i = 0; i < list->num_chunks; i++) { |
| 307 | if (!chunks[i].ddr_paddr || |
Naveen Ramaraj | 6652259 | 2012-11-19 11:33:09 -0800 | [diff] [blame] | 308 | !IS_ALIGNED(chunks[i].ddr_paddr, MIN_CHUNK_SIZE) || |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 309 | chunks[i].size < MIN_CHUNK_SIZE || |
| 310 | !IS_ALIGNED(chunks[i].size, MIN_CHUNK_SIZE)) { |
| 311 | pr_err("Invalid ocmem chunk at index %d (p: %lx, size %lx)\n", |
| 312 | i, chunks[i].ddr_paddr, chunks[i].size); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 313 | return -EINVAL; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 314 | } |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | int ocmem_map(int client_id, struct ocmem_buf *buffer, |
| 320 | struct ocmem_map_list *list) |
| 321 | { |
| 322 | int ret = 0; |
| 323 | struct ocmem_handle *handle = NULL; |
| 324 | |
| 325 | if (!check_id(client_id)) { |
| 326 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 330 | if (!zone_active(client_id)) { |
| 331 | pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n", |
| 332 | get_name(client_id), client_id); |
| 333 | return -EINVAL; |
| 334 | } |
| 335 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 336 | /* Asynchronous API requires notifier registration */ |
| 337 | if (!check_notifier(client_id)) { |
| 338 | pr_err("ocmem: No notifier registered for client %d\n", |
| 339 | client_id); |
| 340 | return -EINVAL; |
| 341 | } |
| 342 | |
| 343 | if (!buffer) { |
| 344 | pr_err("ocmem: Invalid buffer\n"); |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 348 | if (pre_validate_chunk_list(list) != 0) |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 349 | return -EINVAL; |
| 350 | |
| 351 | handle = buffer_to_handle(buffer); |
| 352 | |
| 353 | if (!handle) |
| 354 | return -EINVAL; |
| 355 | |
| 356 | mutex_lock(&handle->handle_mutex); |
| 357 | ret = process_xfer(client_id, handle, list, TO_OCMEM); |
| 358 | mutex_unlock(&handle->handle_mutex); |
| 359 | return ret; |
| 360 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 361 | EXPORT_SYMBOL(ocmem_map); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 362 | |
| 363 | int ocmem_unmap(int client_id, struct ocmem_buf *buffer, |
| 364 | struct ocmem_map_list *list) |
| 365 | { |
| 366 | |
| 367 | int ret = 0; |
| 368 | struct ocmem_handle *handle = NULL; |
| 369 | |
| 370 | if (!check_id(client_id)) { |
| 371 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 375 | if (!zone_active(client_id)) { |
| 376 | pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n", |
| 377 | get_name(client_id), client_id); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 381 | /* Asynchronous API requires notifier registration */ |
| 382 | if (!check_notifier(client_id)) { |
| 383 | pr_err("ocmem: No notifier registered for client %d\n", |
| 384 | client_id); |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | |
| 388 | if (!buffer) { |
| 389 | pr_err("ocmem: Invalid buffer\n"); |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 393 | if (pre_validate_chunk_list(list) != 0) |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 394 | return -EINVAL; |
| 395 | |
| 396 | handle = buffer_to_handle(buffer); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 397 | mutex_lock(&handle->handle_mutex); |
| 398 | ret = process_xfer(client_id, handle, list, TO_DDR); |
| 399 | mutex_unlock(&handle->handle_mutex); |
| 400 | return ret; |
| 401 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 402 | EXPORT_SYMBOL(ocmem_unmap); |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 403 | |
Neeti Desai | dad1d8e | 2013-01-09 19:42:06 -0800 | [diff] [blame] | 404 | int ocmem_drop(int client_id, struct ocmem_buf *buffer, |
| 405 | struct ocmem_map_list *list) |
| 406 | { |
| 407 | int ret = 0; |
| 408 | struct ocmem_handle *handle = NULL; |
| 409 | |
| 410 | if (!check_id(client_id)) { |
| 411 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | if (!zone_active(client_id)) { |
| 416 | pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n", |
| 417 | get_name(client_id), client_id); |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | |
| 421 | if (!buffer) { |
| 422 | pr_err("ocmem: Invalid buffer\n"); |
| 423 | return -EINVAL; |
| 424 | } |
| 425 | |
| 426 | if (pre_validate_chunk_list(list) != 0) |
| 427 | return -EINVAL; |
| 428 | |
| 429 | handle = buffer_to_handle(buffer); |
| 430 | mutex_lock(&handle->handle_mutex); |
| 431 | ret = process_drop(client_id, handle, list); |
| 432 | mutex_unlock(&handle->handle_mutex); |
| 433 | return ret; |
| 434 | } |
| 435 | EXPORT_SYMBOL(ocmem_drop); |
| 436 | |
| 437 | |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 438 | int ocmem_dump(int client_id, struct ocmem_buf *buffer, |
| 439 | unsigned long dst_phys_addr) |
| 440 | { |
| 441 | int ret = 0; |
| 442 | struct ocmem_handle *handle = NULL; |
| 443 | |
| 444 | if (!check_id(client_id)) { |
| 445 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
| 449 | if (!zone_active(client_id)) { |
| 450 | pr_err("ocmem: Client id: %s (id: %d) not allowed to use OCMEM\n", |
| 451 | get_name(client_id), client_id); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | |
| 455 | if (!buffer) { |
| 456 | pr_err("ocmem: Invalid buffer\n"); |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | |
| 460 | handle = buffer_to_handle(buffer); |
| 461 | mutex_lock(&handle->handle_mutex); |
| 462 | ret = process_dump(client_id, handle, dst_phys_addr); |
| 463 | mutex_unlock(&handle->handle_mutex); |
| 464 | return ret; |
| 465 | } |
| 466 | EXPORT_SYMBOL(ocmem_dump); |
| 467 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 468 | unsigned long get_max_quota(int client_id) |
| 469 | { |
| 470 | if (!check_id(client_id)) { |
| 471 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 472 | return 0x0; |
| 473 | } |
| 474 | return process_quota(client_id); |
| 475 | } |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 476 | |
| 477 | /* Synchronous eviction/restore calls */ |
| 478 | /* Only a single eviction or restoration is allowed */ |
| 479 | /* Evictions/Restorations cannot be concurrent with other maps */ |
| 480 | int ocmem_evict(int client_id) |
| 481 | { |
| 482 | int ret = 0; |
| 483 | |
| 484 | if (!check_id(client_id)) { |
| 485 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 486 | return -EINVAL; |
| 487 | } |
| 488 | |
| 489 | mutex_lock(&ocmem_eviction_lock); |
| 490 | if (test_bit(client_id, evicted)) { |
| 491 | pr_err("ocmem: Previous eviction was not restored by %d\n", |
| 492 | client_id); |
| 493 | mutex_unlock(&ocmem_eviction_lock); |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | ret = process_evict(client_id); |
| 498 | if (ret == 0) |
| 499 | set_bit(client_id, evicted); |
| 500 | |
| 501 | mutex_unlock(&ocmem_eviction_lock); |
| 502 | return ret; |
| 503 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 504 | EXPORT_SYMBOL(ocmem_evict); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 505 | |
| 506 | int ocmem_restore(int client_id) |
| 507 | { |
| 508 | int ret = 0; |
| 509 | |
| 510 | if (!check_id(client_id)) { |
| 511 | pr_err("ocmem: Invalid client id: %d\n", client_id); |
| 512 | return -EINVAL; |
| 513 | } |
| 514 | |
| 515 | mutex_lock(&ocmem_eviction_lock); |
| 516 | if (!test_bit(client_id, evicted)) { |
| 517 | pr_err("ocmem: No previous eviction by %d\n", client_id); |
| 518 | mutex_unlock(&ocmem_eviction_lock); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | ret = process_restore(client_id); |
| 522 | clear_bit(client_id, evicted); |
| 523 | mutex_unlock(&ocmem_eviction_lock); |
| 524 | return ret; |
| 525 | } |
Naveen Ramaraj | fdfb0cc | 2012-09-06 23:16:48 -0700 | [diff] [blame] | 526 | EXPORT_SYMBOL(ocmem_restore); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 527 | |
| 528 | /* Wrappers until power control is transitioned to clients */ |
| 529 | enum ocmem_power_state ocmem_get_power_state(int client_id, |
| 530 | struct ocmem_buf *buffer) |
| 531 | { |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | int ocmem_set_power_state(int client_id, struct ocmem_buf *buffer, |
| 536 | enum ocmem_power_state new_state) |
| 537 | { |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | struct ocmem_vectors *ocmem_get_vectors(int client_id, |
| 542 | struct ocmem_buf *buffer) |
| 543 | { |
| 544 | return NULL; |
| 545 | } |