Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -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 | #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 Desai | fecb858 | 2012-11-12 12:15:14 -0800 | [diff] [blame] | 19 | #include <linux/err.h> |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 20 | |
| 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 Ramaraj | 6652259 | 2012-11-19 11:33:09 -0800 | [diff] [blame] | 26 | #define MIN_CHUNK_SIZE SZ_4K |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 27 | |
Naveen Ramaraj | 6b88265 | 2012-06-28 16:07:09 -0700 | [diff] [blame] | 28 | struct ocmem_notifier; |
| 29 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 30 | struct ocmem_buf { |
| 31 | unsigned long addr; |
| 32 | unsigned long len; |
| 33 | }; |
| 34 | |
| 35 | struct ocmem_buf_attr { |
| 36 | unsigned long paddr; |
| 37 | unsigned long len; |
| 38 | }; |
| 39 | |
| 40 | struct ocmem_chunk { |
| 41 | bool ro; |
| 42 | unsigned long ddr_paddr; |
| 43 | unsigned long size; |
| 44 | }; |
| 45 | |
| 46 | struct ocmem_map_list { |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 47 | unsigned num_chunks; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 48 | struct ocmem_chunk chunks[OCMEM_MAX_CHUNKS]; |
| 49 | }; |
| 50 | |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 51 | enum ocmem_power_state { |
| 52 | OCMEM_OFF = 0x0, |
| 53 | OCMEM_RETENTION, |
| 54 | OCMEM_ON, |
| 55 | OCMEM_MAX = OCMEM_ON, |
| 56 | }; |
| 57 | |
| 58 | struct ocmem_resource { |
| 59 | unsigned resource_id; |
| 60 | unsigned num_keys; |
| 61 | unsigned int *keys; |
| 62 | }; |
| 63 | |
| 64 | struct ocmem_vectors { |
| 65 | unsigned num_resources; |
| 66 | struct ocmem_resource *r; |
| 67 | }; |
| 68 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 69 | /* List of clients that allocate/interact with OCMEM */ |
| 70 | /* Must be in sync with client_names */ |
| 71 | enum 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 Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 83 | OCMEM_OTHER_OS, |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 84 | 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 | **/ |
| 92 | enum 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 Desai | fecb858 | 2012-11-12 12:15:14 -0800 | [diff] [blame] | 103 | #ifdef CONFIG_MSM_OCMEM |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 104 | /* Notification APIs */ |
Naveen Ramaraj | 6b88265 | 2012-06-28 16:07:09 -0700 | [diff] [blame] | 105 | struct ocmem_notifier *ocmem_notifier_register(int client_id, |
| 106 | struct notifier_block *nb); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 107 | |
Naveen Ramaraj | 6b88265 | 2012-06-28 16:07:09 -0700 | [diff] [blame] | 108 | int ocmem_notifier_unregister(struct ocmem_notifier *notif_hndl, |
| 109 | struct notifier_block *nb); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 110 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 111 | /* Obtain the maximum quota for the client */ |
| 112 | unsigned long get_max_quota(int client_id); |
| 113 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 114 | /* Allocation APIs */ |
| 115 | struct ocmem_buf *ocmem_allocate(int client_id, unsigned long size); |
| 116 | |
Naveen Ramaraj | 0f5e7ab | 2012-04-24 19:10:23 -0700 | [diff] [blame] | 117 | struct ocmem_buf *ocmem_allocate_nowait(int client_id, unsigned long size); |
| 118 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 119 | struct ocmem_buf *ocmem_allocate_nb(int client_id, unsigned long size); |
| 120 | |
| 121 | struct ocmem_buf *ocmem_allocate_range(int client_id, unsigned long min, |
| 122 | unsigned long goal, unsigned long step); |
| 123 | |
| 124 | /* Free APIs */ |
| 125 | int ocmem_free(int client_id, struct ocmem_buf *buf); |
| 126 | |
| 127 | /* Dynamic Resize APIs */ |
| 128 | int ocmem_shrink(int client_id, struct ocmem_buf *buf, |
| 129 | unsigned long new_size); |
| 130 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 131 | /* Transfer APIs */ |
| 132 | int ocmem_map(int client_id, struct ocmem_buf *buffer, |
| 133 | struct ocmem_map_list *list); |
| 134 | |
| 135 | |
| 136 | int ocmem_unmap(int client_id, struct ocmem_buf *buffer, |
| 137 | struct ocmem_map_list *list); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 138 | |
Neeti Desai | dad1d8e | 2013-01-09 19:42:06 -0800 | [diff] [blame] | 139 | int ocmem_drop(int client_id, struct ocmem_buf *buffer, |
| 140 | struct ocmem_map_list *list); |
| 141 | |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 142 | int ocmem_dump(int client_id, struct ocmem_buf *buffer, |
| 143 | unsigned long dst_phys_addr); |
| 144 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 145 | /* Priority Enforcement APIs */ |
| 146 | int ocmem_evict(int client_id); |
| 147 | |
| 148 | int ocmem_restore(int client_id); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 149 | |
| 150 | /* Power Control APIs */ |
| 151 | int ocmem_set_power_state(int client_id, struct ocmem_buf *buf, |
| 152 | enum ocmem_power_state new_state); |
| 153 | |
| 154 | enum ocmem_power_state ocmem_get_power_state(int client_id, |
| 155 | struct ocmem_buf *buf); |
| 156 | |
| 157 | struct ocmem_vectors *ocmem_get_vectors(int client_id, |
| 158 | struct ocmem_buf *buf); |
Neeti Desai | fecb858 | 2012-11-12 12:15:14 -0800 | [diff] [blame] | 159 | |
| 160 | #else |
| 161 | /* Notification APIs */ |
| 162 | static inline struct ocmem_notifier *ocmem_notifier_register |
| 163 | (int client_id, struct notifier_block *nb) |
| 164 | { |
| 165 | return ERR_PTR(-ENODEV); |
| 166 | } |
| 167 | |
| 168 | static 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 */ |
| 175 | static inline unsigned long get_max_quota(int client_id) |
| 176 | { |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | /* Allocation APIs */ |
| 181 | static inline struct ocmem_buf *ocmem_allocate(int client_id, |
| 182 | unsigned long size) |
| 183 | { |
| 184 | return ERR_PTR(-ENODEV); |
| 185 | } |
| 186 | |
| 187 | static inline struct ocmem_buf *ocmem_allocate_nowait(int client_id, |
| 188 | unsigned long size) |
| 189 | { |
| 190 | return ERR_PTR(-ENODEV); |
| 191 | } |
| 192 | |
| 193 | static inline struct ocmem_buf *ocmem_allocate_nb(int client_id, |
| 194 | unsigned long size) |
| 195 | { |
| 196 | return ERR_PTR(-ENODEV); |
| 197 | } |
| 198 | |
| 199 | static 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 */ |
| 206 | static inline int ocmem_free(int client_id, struct ocmem_buf *buf) |
| 207 | { |
| 208 | return -ENODEV; |
| 209 | } |
| 210 | |
| 211 | /* Dynamic Resize APIs */ |
| 212 | static 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 */ |
| 219 | static inline int ocmem_map(int client_id, struct ocmem_buf *buffer, |
| 220 | struct ocmem_map_list *list) |
| 221 | { |
| 222 | return -ENODEV; |
| 223 | } |
| 224 | |
| 225 | static inline int ocmem_unmap(int client_id, struct ocmem_buf *buffer, |
| 226 | struct ocmem_map_list *list) |
| 227 | { |
| 228 | return -ENODEV; |
| 229 | } |
| 230 | |
| 231 | static 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 */ |
| 238 | static inline int ocmem_evict(int client_id) |
| 239 | { |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | |
| 243 | static inline int ocmem_restore(int client_id) |
| 244 | { |
| 245 | return -ENODEV; |
| 246 | } |
| 247 | |
| 248 | /* Power Control APIs */ |
| 249 | static 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 | |
| 255 | static inline enum ocmem_power_state ocmem_get_power_state(int client_id, |
| 256 | struct ocmem_buf *buf) |
| 257 | { |
| 258 | return -ENODEV; |
| 259 | } |
| 260 | static 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 Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 266 | #endif |