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 { |
| 45 | unsigned long (*allocate) (struct ocmem_zone *, unsigned long); |
| 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; |
| 88 | }; |
| 89 | |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 90 | enum op_code { |
| 91 | SCHED_NOP = 0x0, |
| 92 | SCHED_ALLOCATE, |
| 93 | SCHED_FREE, |
| 94 | SCHED_GROW, |
| 95 | SCHED_SHRINK, |
| 96 | SCHED_MAP, |
| 97 | SCHED_UNMAP, |
| 98 | SCHED_EVICT, |
| 99 | SCHED_RESTORE, |
| 100 | SCHED_DUMP, |
| 101 | }; |
| 102 | |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 103 | /* Operational modes of each region */ |
| 104 | enum region_mode { |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 105 | MODE_NOT_SET = 0x0, |
| 106 | WIDE_MODE, |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 107 | THIN_MODE, |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 108 | MODE_DEFAULT = MODE_NOT_SET, |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 111 | struct ocmem_plat_data { |
| 112 | void __iomem *vbase; |
| 113 | unsigned long size; |
| 114 | unsigned long base; |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 115 | struct clk *core_clk; |
| 116 | struct clk *iface_clk; |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 117 | struct clk *br_clk; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 118 | struct ocmem_partition *parts; |
| 119 | int nr_parts; |
| 120 | void __iomem *reg_base; |
| 121 | void __iomem *br_base; |
| 122 | void __iomem *dm_base; |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 123 | struct dentry *debug_node; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 124 | unsigned nr_regions; |
| 125 | unsigned nr_macros; |
| 126 | unsigned nr_ports; |
| 127 | int ocmem_irq; |
| 128 | int dm_irq; |
| 129 | bool interleaved; |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 130 | bool rpm_pwr_ctrl; |
| 131 | unsigned rpm_rsc_type; |
Naveen Ramaraj | 8ad6360 | 2012-05-09 20:50:39 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 134 | struct ocmem_eviction_data { |
| 135 | struct completion completion; |
| 136 | struct list_head victim_list; |
| 137 | struct list_head req_list; |
| 138 | struct work_struct work; |
| 139 | int prio; |
Naveen Ramaraj | 0cd880a | 2012-10-16 17:38:06 -0700 | [diff] [blame] | 140 | atomic_t pending; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 141 | bool passive; |
| 142 | }; |
| 143 | |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 144 | struct ocmem_req { |
| 145 | struct rw_semaphore rw_sem; |
| 146 | /* Chain in sched queue */ |
| 147 | struct list_head sched_list; |
| 148 | /* Chain in zone list */ |
| 149 | struct list_head zone_list; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 150 | /* Chain in eviction list */ |
| 151 | struct list_head eviction_list; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 152 | int owner; |
| 153 | int prio; |
| 154 | uint32_t req_id; |
| 155 | unsigned long req_min; |
| 156 | unsigned long req_max; |
| 157 | unsigned long req_step; |
| 158 | /* reverse pointers */ |
| 159 | struct ocmem_zone *zone; |
| 160 | struct ocmem_buf *buffer; |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 161 | struct ocmem_map_list *mlist; |
| 162 | enum op_code op; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 163 | unsigned long state; |
| 164 | /* Request assignments */ |
| 165 | unsigned long req_start; |
| 166 | unsigned long req_end; |
| 167 | unsigned long req_sz; |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 168 | /* Request Power State */ |
| 169 | unsigned power_state; |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 170 | struct ocmem_eviction_data *edata; |
Naveen Ramaraj | 8973895 | 2013-02-13 15:24:57 -0800 | [diff] [blame] | 171 | /* Request that triggered eviction */ |
| 172 | struct ocmem_req *e_handle; |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | struct ocmem_handle { |
| 176 | struct ocmem_buf buffer; |
| 177 | struct mutex handle_mutex; |
| 178 | struct ocmem_req *req; |
| 179 | }; |
| 180 | |
Naveen Ramaraj | 3b6c5a9 | 2012-08-19 18:50:44 -0700 | [diff] [blame] | 181 | struct ocmem_buf *handle_to_buffer(struct ocmem_handle *); |
| 182 | struct ocmem_handle *buffer_to_handle(struct ocmem_buf *); |
| 183 | struct ocmem_req *handle_to_req(struct ocmem_handle *); |
| 184 | struct ocmem_handle *req_to_handle(struct ocmem_req *); |
| 185 | int ocmem_read(void *); |
| 186 | int ocmem_write(unsigned long, void *); |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 187 | void inc_ocmem_stat(struct ocmem_zone *, enum ocmem_zstat_item); |
| 188 | unsigned long get_ocmem_stat(struct ocmem_zone *z, |
| 189 | enum ocmem_zstat_item item); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 190 | struct ocmem_zone *get_zone(unsigned); |
Naveen Ramaraj | 4d5e354 | 2012-08-12 21:55:49 -0700 | [diff] [blame] | 191 | int zone_active(int); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 192 | unsigned long offset_to_phys(unsigned long); |
| 193 | unsigned long phys_to_offset(unsigned long); |
Naveen Ramaraj | 959d37f | 2012-04-23 11:59:01 -0700 | [diff] [blame] | 194 | unsigned long allocate_head(struct ocmem_zone *, unsigned long); |
| 195 | int free_head(struct ocmem_zone *, unsigned long, unsigned long); |
Naveen Ramaraj | 135cd67 | 2012-04-23 12:13:28 -0700 | [diff] [blame] | 196 | unsigned long allocate_tail(struct ocmem_zone *, unsigned long); |
| 197 | int free_tail(struct ocmem_zone *, unsigned long, unsigned long); |
Naveen Ramaraj | bdf4dfe | 2012-04-23 14:09:50 -0700 | [diff] [blame] | 198 | |
| 199 | int ocmem_notifier_init(void); |
| 200 | int check_notifier(int); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 201 | const char *get_name(int); |
Naveen Ramaraj | e4cc462 | 2012-10-29 17:28:57 -0700 | [diff] [blame] | 202 | int get_tz_id(int); |
| 203 | int ocmem_enable_sec_program(int); |
| 204 | int ocmem_enable_dump(enum ocmem_client, unsigned long, unsigned long); |
| 205 | int ocmem_disable_dump(enum ocmem_client, unsigned long, unsigned long); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 206 | int check_id(int); |
Naveen Ramaraj | bdf4dfe | 2012-04-23 14:09:50 -0700 | [diff] [blame] | 207 | int dispatch_notification(int, enum ocmem_notif_type, struct ocmem_buf *); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 208 | |
Naveen Ramaraj | 6a92b26 | 2012-07-30 17:36:24 -0700 | [diff] [blame] | 209 | int ocmem_sched_init(struct platform_device *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 210 | int ocmem_rdm_init(struct platform_device *); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 211 | int ocmem_core_init(struct platform_device *); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 212 | int process_allocate(int, struct ocmem_handle *, unsigned long, unsigned long, |
| 213 | unsigned long, bool, bool); |
| 214 | int process_free(int, struct ocmem_handle *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 215 | int process_xfer(int, struct ocmem_handle *, struct ocmem_map_list *, int); |
Neeti Desai | dad1d8e | 2013-01-09 19:42:06 -0800 | [diff] [blame^] | 216 | int process_drop(int, struct ocmem_handle *, struct ocmem_map_list *); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 217 | int process_evict(int); |
| 218 | int process_restore(int); |
| 219 | int process_shrink(int, struct ocmem_handle *, unsigned long); |
Naveen Ramaraj | 55ed890 | 2012-09-26 13:18:06 -0700 | [diff] [blame] | 220 | int process_dump(int, struct ocmem_handle *, unsigned long); |
Naveen Ramaraj | cc4ec15 | 2012-05-14 09:55:29 -0700 | [diff] [blame] | 221 | int ocmem_rdm_transfer(int, struct ocmem_map_list *, |
| 222 | unsigned long, int); |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 223 | int ocmem_clear(unsigned long, unsigned long); |
Naveen Ramaraj | b9da0578 | 2012-05-07 09:07:35 -0700 | [diff] [blame] | 224 | unsigned long process_quota(int); |
Naveen Ramaraj | 99b0756 | 2012-05-28 20:57:09 -0700 | [diff] [blame] | 225 | int ocmem_memory_off(int, unsigned long, unsigned long); |
| 226 | int ocmem_memory_on(int, unsigned long, unsigned long); |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 227 | int ocmem_enable_core_clock(void); |
| 228 | int ocmem_enable_iface_clock(void); |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 229 | int ocmem_enable_br_clock(void); |
Naveen Ramaraj | bea2d5d | 2012-08-15 17:26:43 -0700 | [diff] [blame] | 230 | void ocmem_disable_core_clock(void); |
| 231 | void ocmem_disable_iface_clock(void); |
Naveen Ramaraj | 5da5454 | 2012-08-21 13:26:17 -0700 | [diff] [blame] | 232 | void ocmem_disable_br_clock(void); |
Naveen Ramaraj | e43d9bb | 2012-08-20 14:41:13 -0700 | [diff] [blame] | 233 | int ocmem_lock(enum ocmem_client, unsigned long, unsigned long, |
| 234 | enum region_mode); |
| 235 | int ocmem_unlock(enum ocmem_client, unsigned long, unsigned long); |
Naveen Ramaraj | 51f5e8b | 2012-04-09 15:58:40 -0700 | [diff] [blame] | 236 | #endif |