Naveen Ramaraj | e4cc462 | 2012-10-29 17:28:57 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, 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 | |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 13 | #ifndef _ARCH_ARM_MACH_MSM_OCMEM_PRIV_H |
| 14 | #define _ARCH_ARM_MACH_MSM_OCMEM_PRIV_H |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 15 | |
| 16 | /** All interfaces in this header should only be used by OCMEM driver |
| 17 | * Client drivers should use wrappers available in ocmem.h |
| 18 | **/ |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 20 | #include <linux/clk.h> |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 21 | #include <asm/io.h> |
| 22 | #include <mach/msm_iomap.h> |
| 23 | #include "ocmem.h" |
| 24 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 25 | |
| 26 | #define OCMEM_PHYS_BASE 0xFEC00000 |
| 27 | #define OCMEM_PHYS_SIZE 0x180000 |
| 28 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 29 | #define TO_OCMEM 0x0 |
| 30 | #define TO_DDR 0x1 |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 31 | |
Naveen Ramaraj | e4cc462 | 2012-10-29 17:28:57 -0700 | [diff] [blame] | 32 | #define OCMEM_SVC_ID 15 |
| 33 | #define OCMEM_LOCK_CMD_ID 0x1 |
| 34 | #define OCMEM_UNLOCK_CMD_ID 0x2 |
| 35 | #define OCMEM_ENABLE_DUMP_CMD_ID 0x3 |
| 36 | #define OCMEM_DISABLE_DUMP_CMD_ID 0x4 |
| 37 | |
| 38 | #define OCMEM_SECURE_SVC_ID 12 |
| 39 | #define OCMEM_SECURE_CFG_ID 0x2 |
| 40 | #define OCMEM_SECURE_DEV_ID 0x5 |
| 41 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 42 | struct ocmem_zone; |
| 43 | |
| 44 | struct ocmem_zone_ops { |
Neeti Desai | 64ea8f4 | 2013-05-17 15:05:29 -0700 | [diff] [blame] | 45 | int (*allocate) (struct ocmem_zone *, unsigned long, unsigned long *); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 46 | int (*free) (struct ocmem_zone *, unsigned long, unsigned long); |
| 47 | }; |
| 48 | |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 49 | /* OCMEM Zone specific counters */ |
| 50 | /* Must be in sync with zstat_names */ |
| 51 | enum ocmem_zstat_item { |
| 52 | NR_REQUESTS = 0x0, |
| 53 | NR_SYNC_ALLOCATIONS, |
| 54 | NR_RANGE_ALLOCATIONS, |
| 55 | NR_ASYNC_ALLOCATIONS, |
| 56 | NR_ALLOCATION_FAILS, |
| 57 | NR_GROWTHS, |
| 58 | NR_FREES, |
| 59 | NR_SHRINKS, |
| 60 | NR_MAPS, |
| 61 | NR_MAP_FAILS, |
| 62 | NR_UNMAPS, |
| 63 | NR_UNMAP_FAILS, |
| 64 | NR_TRANSFERS_TO_OCMEM, |
| 65 | NR_TRANSFERS_TO_DDR, |
| 66 | NR_TRANSFER_FAILS, |
| 67 | NR_EVICTIONS, |
| 68 | NR_RESTORES, |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 69 | NR_DUMP_REQUESTS, |
| 70 | NR_DUMP_COMPLETE, |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 71 | NR_OCMEM_ZSTAT_ITEMS, |
| 72 | }; |
| 73 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 74 | struct ocmem_zone { |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 75 | bool active; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 76 | int owner; |
| 77 | int active_regions; |
| 78 | int max_regions; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 79 | struct list_head req_list; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 80 | unsigned long z_start; |
| 81 | unsigned long z_end; |
| 82 | unsigned long z_head; |
| 83 | unsigned long z_tail; |
| 84 | unsigned long z_free; |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 85 | atomic_long_t z_stat[NR_OCMEM_ZSTAT_ITEMS]; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 86 | struct gen_pool *z_pool; |
| 87 | struct ocmem_zone_ops *z_ops; |
Neeti Desai | f69aa13 | 2013-02-28 17:25:01 -0800 | [diff] [blame] | 88 | unsigned int max_alloc_time; |
| 89 | unsigned int min_alloc_time; |
| 90 | u64 total_alloc_time; |
| 91 | unsigned int max_free_time; |
| 92 | unsigned int min_free_time; |
| 93 | u64 total_free_time; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 96 | enum op_code { |
| 97 | SCHED_NOP = 0x0, |
| 98 | SCHED_ALLOCATE, |
| 99 | SCHED_FREE, |
| 100 | SCHED_GROW, |
| 101 | SCHED_SHRINK, |
| 102 | SCHED_MAP, |
| 103 | SCHED_UNMAP, |
| 104 | SCHED_EVICT, |
| 105 | SCHED_RESTORE, |
| 106 | SCHED_DUMP, |
| 107 | }; |
| 108 | |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 109 | /* Operational modes of each region */ |
| 110 | enum region_mode { |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 111 | MODE_NOT_SET = 0x0, |
| 112 | WIDE_MODE, |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 113 | THIN_MODE, |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 114 | MODE_DEFAULT = MODE_NOT_SET, |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 117 | struct ocmem_plat_data { |
| 118 | void __iomem *vbase; |
| 119 | unsigned long size; |
| 120 | unsigned long base; |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 121 | struct clk *core_clk; |
| 122 | struct clk *iface_clk; |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 123 | struct clk *br_clk; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 124 | struct ocmem_partition *parts; |
| 125 | int nr_parts; |
| 126 | void __iomem *reg_base; |
| 127 | void __iomem *br_base; |
| 128 | void __iomem *dm_base; |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 129 | struct dentry *debug_node; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 130 | unsigned nr_regions; |
| 131 | unsigned nr_macros; |
| 132 | unsigned nr_ports; |
| 133 | int ocmem_irq; |
| 134 | int dm_irq; |
| 135 | bool interleaved; |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 136 | bool rpm_pwr_ctrl; |
| 137 | unsigned rpm_rsc_type; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 140 | struct ocmem_eviction_data { |
| 141 | struct completion completion; |
| 142 | struct list_head victim_list; |
| 143 | struct list_head req_list; |
| 144 | struct work_struct work; |
| 145 | int prio; |
Naveen Ramaraj | 0cd880a | 2012-10-16 17:38:06 -0700 | [diff] [blame] | 146 | atomic_t pending; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 147 | bool passive; |
| 148 | }; |
| 149 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 150 | struct ocmem_req { |
| 151 | struct rw_semaphore rw_sem; |
| 152 | /* Chain in sched queue */ |
| 153 | struct list_head sched_list; |
| 154 | /* Chain in zone list */ |
| 155 | struct list_head zone_list; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 156 | /* Chain in eviction list */ |
| 157 | struct list_head eviction_list; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 158 | int owner; |
| 159 | int prio; |
| 160 | uint32_t req_id; |
| 161 | unsigned long req_min; |
| 162 | unsigned long req_max; |
| 163 | unsigned long req_step; |
| 164 | /* reverse pointers */ |
| 165 | struct ocmem_zone *zone; |
| 166 | struct ocmem_buf *buffer; |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 167 | struct ocmem_map_list *mlist; |
| 168 | enum op_code op; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 169 | unsigned long state; |
| 170 | /* Request assignments */ |
| 171 | unsigned long req_start; |
| 172 | unsigned long req_end; |
| 173 | unsigned long req_sz; |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 174 | /* Request Power State */ |
| 175 | unsigned power_state; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 176 | struct ocmem_eviction_data *edata; |
Neeti Desai | dcd464d | 2013-06-29 09:50:58 -0700 | [diff] [blame] | 177 | /* Eviction data of the request being evicted */ |
| 178 | struct ocmem_eviction_data *eviction_info; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | struct ocmem_handle { |
| 182 | struct ocmem_buf buffer; |
| 183 | struct mutex handle_mutex; |
| 184 | struct ocmem_req *req; |
| 185 | }; |
| 186 | |
Naveen Ramaraj | 3b6c5a9 | 2012-08-19 18:50:44 -0700 | [diff] [blame] | 187 | struct ocmem_buf *handle_to_buffer(struct ocmem_handle *); |
| 188 | struct ocmem_handle *buffer_to_handle(struct ocmem_buf *); |
| 189 | struct ocmem_req *handle_to_req(struct ocmem_handle *); |
| 190 | struct ocmem_handle *req_to_handle(struct ocmem_req *); |
| 191 | int ocmem_read(void *); |
| 192 | int ocmem_write(unsigned long, void *); |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 193 | void inc_ocmem_stat(struct ocmem_zone *, enum ocmem_zstat_item); |
| 194 | unsigned long get_ocmem_stat(struct ocmem_zone *z, |
| 195 | enum ocmem_zstat_item item); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 196 | struct ocmem_zone *get_zone(unsigned); |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 197 | int zone_active(int); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 198 | unsigned long offset_to_phys(unsigned long); |
| 199 | unsigned long phys_to_offset(unsigned long); |
Neeti Desai | 64ea8f4 | 2013-05-17 15:05:29 -0700 | [diff] [blame] | 200 | int allocate_head(struct ocmem_zone *, unsigned long, unsigned long *); |
Naveen Ramaraj | 959d37f | 2012-04-23 11:59:01 -0700 | [diff] [blame] | 201 | int free_head(struct ocmem_zone *, unsigned long, unsigned long); |
Neeti Desai | 64ea8f4 | 2013-05-17 15:05:29 -0700 | [diff] [blame] | 202 | int allocate_tail(struct ocmem_zone *, unsigned long, unsigned long *); |
Naveen Ramaraj | 135cd67 | 2012-04-23 12:13:28 -0700 | [diff] [blame] | 203 | int free_tail(struct ocmem_zone *, unsigned long, unsigned long); |
Naveen Ramaraj | bdf4dfe | 2012-04-23 14:09:50 -0700 | [diff] [blame] | 204 | |
| 205 | int ocmem_notifier_init(void); |
| 206 | int check_notifier(int); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 207 | const char *get_name(int); |
Naveen Ramaraj | e4cc462 | 2012-10-29 17:28:57 -0700 | [diff] [blame] | 208 | int get_tz_id(int); |
| 209 | int ocmem_enable_sec_program(int); |
| 210 | int ocmem_enable_dump(enum ocmem_client, unsigned long, unsigned long); |
| 211 | int ocmem_disable_dump(enum ocmem_client, unsigned long, unsigned long); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 212 | int check_id(int); |
Naveen Ramaraj | bdf4dfe | 2012-04-23 14:09:50 -0700 | [diff] [blame] | 213 | int dispatch_notification(int, enum ocmem_notif_type, struct ocmem_buf *); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 214 | |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 215 | int ocmem_sched_init(struct platform_device *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 216 | int ocmem_rdm_init(struct platform_device *); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 217 | int ocmem_core_init(struct platform_device *); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 218 | int process_allocate(int, struct ocmem_handle *, unsigned long, unsigned long, |
| 219 | unsigned long, bool, bool); |
| 220 | int process_free(int, struct ocmem_handle *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 221 | int process_xfer(int, struct ocmem_handle *, struct ocmem_map_list *, int); |
Neeti Desai | dad1d8e | 2013-01-09 19:42:06 -0800 | [diff] [blame] | 222 | int process_drop(int, struct ocmem_handle *, struct ocmem_map_list *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 223 | int process_evict(int); |
| 224 | int process_restore(int); |
| 225 | int process_shrink(int, struct ocmem_handle *, unsigned long); |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 226 | int process_dump(int, struct ocmem_handle *, unsigned long); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 227 | int ocmem_rdm_transfer(int, struct ocmem_map_list *, |
| 228 | unsigned long, int); |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 229 | int ocmem_clear(unsigned long, unsigned long); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 230 | unsigned long process_quota(int); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 231 | int ocmem_memory_off(int, unsigned long, unsigned long); |
| 232 | int ocmem_memory_on(int, unsigned long, unsigned long); |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 233 | int ocmem_enable_core_clock(void); |
| 234 | int ocmem_enable_iface_clock(void); |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 235 | int ocmem_enable_br_clock(void); |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 236 | void ocmem_disable_core_clock(void); |
| 237 | void ocmem_disable_iface_clock(void); |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 238 | void ocmem_disable_br_clock(void); |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 239 | int ocmem_lock(enum ocmem_client, unsigned long, unsigned long, |
| 240 | enum region_mode); |
| 241 | int ocmem_unlock(enum ocmem_client, unsigned long, unsigned long); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 242 | #endif |