Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 1 | /* 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 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 | |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 139 | int ocmem_dump(int client_id, struct ocmem_buf *buffer, |
| 140 | unsigned long dst_phys_addr); |
| 141 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 142 | /* Priority Enforcement APIs */ |
| 143 | int ocmem_evict(int client_id); |
| 144 | |
| 145 | int ocmem_restore(int client_id); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 146 | |
| 147 | /* Power Control APIs */ |
| 148 | int ocmem_set_power_state(int client_id, struct ocmem_buf *buf, |
| 149 | enum ocmem_power_state new_state); |
| 150 | |
| 151 | enum ocmem_power_state ocmem_get_power_state(int client_id, |
| 152 | struct ocmem_buf *buf); |
| 153 | |
| 154 | struct ocmem_vectors *ocmem_get_vectors(int client_id, |
| 155 | struct ocmem_buf *buf); |
Neeti Desai | fecb858 | 2012-11-12 12:15:14 -0800 | [diff] [blame^] | 156 | |
| 157 | #else |
| 158 | /* Notification APIs */ |
| 159 | static inline struct ocmem_notifier *ocmem_notifier_register |
| 160 | (int client_id, struct notifier_block *nb) |
| 161 | { |
| 162 | return ERR_PTR(-ENODEV); |
| 163 | } |
| 164 | |
| 165 | static 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 */ |
| 172 | static inline unsigned long get_max_quota(int client_id) |
| 173 | { |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /* Allocation APIs */ |
| 178 | static inline struct ocmem_buf *ocmem_allocate(int client_id, |
| 179 | unsigned long size) |
| 180 | { |
| 181 | return ERR_PTR(-ENODEV); |
| 182 | } |
| 183 | |
| 184 | static inline struct ocmem_buf *ocmem_allocate_nowait(int client_id, |
| 185 | unsigned long size) |
| 186 | { |
| 187 | return ERR_PTR(-ENODEV); |
| 188 | } |
| 189 | |
| 190 | static inline struct ocmem_buf *ocmem_allocate_nb(int client_id, |
| 191 | unsigned long size) |
| 192 | { |
| 193 | return ERR_PTR(-ENODEV); |
| 194 | } |
| 195 | |
| 196 | static 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 */ |
| 203 | static inline int ocmem_free(int client_id, struct ocmem_buf *buf) |
| 204 | { |
| 205 | return -ENODEV; |
| 206 | } |
| 207 | |
| 208 | /* Dynamic Resize APIs */ |
| 209 | static 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 */ |
| 216 | static inline int ocmem_map(int client_id, struct ocmem_buf *buffer, |
| 217 | struct ocmem_map_list *list) |
| 218 | { |
| 219 | return -ENODEV; |
| 220 | } |
| 221 | |
| 222 | static inline int ocmem_unmap(int client_id, struct ocmem_buf *buffer, |
| 223 | struct ocmem_map_list *list) |
| 224 | { |
| 225 | return -ENODEV; |
| 226 | } |
| 227 | |
| 228 | static 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 */ |
| 235 | static inline int ocmem_evict(int client_id) |
| 236 | { |
| 237 | return -ENODEV; |
| 238 | } |
| 239 | |
| 240 | static inline int ocmem_restore(int client_id) |
| 241 | { |
| 242 | return -ENODEV; |
| 243 | } |
| 244 | |
| 245 | /* Power Control APIs */ |
| 246 | static 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 | |
| 252 | static inline enum ocmem_power_state ocmem_get_power_state(int client_id, |
| 253 | struct ocmem_buf *buf) |
| 254 | { |
| 255 | return -ENODEV; |
| 256 | } |
| 257 | static 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 Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 263 | #endif |