blob: 32d58d4fc1fd02afe684c3e9707f4225d72d02fa [file] [log] [blame]
Naveen Ramaraje4cc4622012-10-29 17:28:57 -07001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -07002 *
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 Ramaraj6a92b262012-07-30 17:36:24 -070013#ifndef _ARCH_ARM_MACH_MSM_OCMEM_PRIV_H
14#define _ARCH_ARM_MACH_MSM_OCMEM_PRIV_H
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070015
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 Ramarajcc4ec152012-05-14 09:55:29 -070019#include <linux/platform_device.h>
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -070020#include <linux/clk.h>
Naveen Ramaraj99b07562012-05-28 20:57:09 -070021#include <asm/io.h>
22#include <mach/msm_iomap.h>
23#include "ocmem.h"
24
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070025
26#define OCMEM_PHYS_BASE 0xFEC00000
27#define OCMEM_PHYS_SIZE 0x180000
28
Naveen Ramarajcc4ec152012-05-14 09:55:29 -070029#define TO_OCMEM 0x0
30#define TO_DDR 0x1
Naveen Ramarajb9da05782012-05-07 09:07:35 -070031
Naveen Ramaraje4cc4622012-10-29 17:28:57 -070032#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 Ramaraj51f5e8b2012-04-09 15:58:40 -070042struct ocmem_zone;
43
44struct ocmem_zone_ops {
Neeti Desai64ea8f42013-05-17 15:05:29 -070045 int (*allocate) (struct ocmem_zone *, unsigned long, unsigned long *);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070046 int (*free) (struct ocmem_zone *, unsigned long, unsigned long);
47};
48
Naveen Ramaraj6a92b262012-07-30 17:36:24 -070049/* OCMEM Zone specific counters */
50/* Must be in sync with zstat_names */
51enum 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 Ramaraj55ed8902012-09-26 13:18:06 -070069 NR_DUMP_REQUESTS,
70 NR_DUMP_COMPLETE,
Naveen Ramaraj6a92b262012-07-30 17:36:24 -070071 NR_OCMEM_ZSTAT_ITEMS,
72};
73
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070074struct ocmem_zone {
Naveen Ramaraj4d5e3542012-08-12 21:55:49 -070075 bool active;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070076 int owner;
77 int active_regions;
78 int max_regions;
Naveen Ramarajcc4ec152012-05-14 09:55:29 -070079 struct list_head req_list;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070080 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 Ramaraj6a92b262012-07-30 17:36:24 -070085 atomic_long_t z_stat[NR_OCMEM_ZSTAT_ITEMS];
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -070086 struct gen_pool *z_pool;
87 struct ocmem_zone_ops *z_ops;
Neeti Desaif69aa132013-02-28 17:25:01 -080088 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 Ramaraj51f5e8b2012-04-09 15:58:40 -070094};
95
Naveen Ramarajb9da05782012-05-07 09:07:35 -070096enum 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 Ramaraj99b07562012-05-28 20:57:09 -0700109/* Operational modes of each region */
110enum region_mode {
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700111 MODE_NOT_SET = 0x0,
112 WIDE_MODE,
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700113 THIN_MODE,
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700114 MODE_DEFAULT = MODE_NOT_SET,
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700115};
116
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700117struct ocmem_plat_data {
118 void __iomem *vbase;
119 unsigned long size;
120 unsigned long base;
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700121 struct clk *core_clk;
122 struct clk *iface_clk;
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700123 struct clk *br_clk;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700124 struct ocmem_partition *parts;
125 int nr_parts;
126 void __iomem *reg_base;
127 void __iomem *br_base;
128 void __iomem *dm_base;
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700129 struct dentry *debug_node;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700130 unsigned nr_regions;
131 unsigned nr_macros;
132 unsigned nr_ports;
133 int ocmem_irq;
134 int dm_irq;
135 bool interleaved;
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700136 bool rpm_pwr_ctrl;
137 unsigned rpm_rsc_type;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700138};
139
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700140struct 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 Ramaraj0cd880a2012-10-16 17:38:06 -0700146 atomic_t pending;
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700147 bool passive;
148};
149
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700150struct 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 Ramarajcc4ec152012-05-14 09:55:29 -0700156 /* Chain in eviction list */
157 struct list_head eviction_list;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700158 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 Ramarajb9da05782012-05-07 09:07:35 -0700167 struct ocmem_map_list *mlist;
168 enum op_code op;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700169 unsigned long state;
170 /* Request assignments */
171 unsigned long req_start;
172 unsigned long req_end;
173 unsigned long req_sz;
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700174 /* Request Power State */
175 unsigned power_state;
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700176 struct ocmem_eviction_data *edata;
Neeti Desaidcd464d2013-06-29 09:50:58 -0700177 /* Eviction data of the request being evicted */
178 struct ocmem_eviction_data *eviction_info;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700179};
180
181struct ocmem_handle {
182 struct ocmem_buf buffer;
183 struct mutex handle_mutex;
184 struct ocmem_req *req;
185};
186
Naveen Ramaraj3b6c5a92012-08-19 18:50:44 -0700187struct ocmem_buf *handle_to_buffer(struct ocmem_handle *);
188struct ocmem_handle *buffer_to_handle(struct ocmem_buf *);
189struct ocmem_req *handle_to_req(struct ocmem_handle *);
190struct ocmem_handle *req_to_handle(struct ocmem_req *);
191int ocmem_read(void *);
192int ocmem_write(unsigned long, void *);
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700193void inc_ocmem_stat(struct ocmem_zone *, enum ocmem_zstat_item);
194unsigned long get_ocmem_stat(struct ocmem_zone *z,
195 enum ocmem_zstat_item item);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700196struct ocmem_zone *get_zone(unsigned);
Naveen Ramaraj4d5e3542012-08-12 21:55:49 -0700197int zone_active(int);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700198unsigned long offset_to_phys(unsigned long);
199unsigned long phys_to_offset(unsigned long);
Neeti Desai64ea8f42013-05-17 15:05:29 -0700200int allocate_head(struct ocmem_zone *, unsigned long, unsigned long *);
Naveen Ramaraj959d37f2012-04-23 11:59:01 -0700201int free_head(struct ocmem_zone *, unsigned long, unsigned long);
Neeti Desai64ea8f42013-05-17 15:05:29 -0700202int allocate_tail(struct ocmem_zone *, unsigned long, unsigned long *);
Naveen Ramaraj135cd672012-04-23 12:13:28 -0700203int free_tail(struct ocmem_zone *, unsigned long, unsigned long);
Naveen Ramarajbdf4dfe2012-04-23 14:09:50 -0700204
205int ocmem_notifier_init(void);
206int check_notifier(int);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700207const char *get_name(int);
Naveen Ramaraje4cc4622012-10-29 17:28:57 -0700208int get_tz_id(int);
209int ocmem_enable_sec_program(int);
210int ocmem_enable_dump(enum ocmem_client, unsigned long, unsigned long);
211int ocmem_disable_dump(enum ocmem_client, unsigned long, unsigned long);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700212int check_id(int);
Naveen Ramarajbdf4dfe2012-04-23 14:09:50 -0700213int dispatch_notification(int, enum ocmem_notif_type, struct ocmem_buf *);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700214
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700215int ocmem_sched_init(struct platform_device *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700216int ocmem_rdm_init(struct platform_device *);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700217int ocmem_core_init(struct platform_device *);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700218int process_allocate(int, struct ocmem_handle *, unsigned long, unsigned long,
219 unsigned long, bool, bool);
220int process_free(int, struct ocmem_handle *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700221int process_xfer(int, struct ocmem_handle *, struct ocmem_map_list *, int);
Neeti Desaidad1d8e2013-01-09 19:42:06 -0800222int process_drop(int, struct ocmem_handle *, struct ocmem_map_list *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700223int process_evict(int);
224int process_restore(int);
225int process_shrink(int, struct ocmem_handle *, unsigned long);
Naveen Ramaraj55ed8902012-09-26 13:18:06 -0700226int process_dump(int, struct ocmem_handle *, unsigned long);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700227int ocmem_rdm_transfer(int, struct ocmem_map_list *,
228 unsigned long, int);
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700229int ocmem_clear(unsigned long, unsigned long);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700230unsigned long process_quota(int);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700231int ocmem_memory_off(int, unsigned long, unsigned long);
232int ocmem_memory_on(int, unsigned long, unsigned long);
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700233int ocmem_enable_core_clock(void);
234int ocmem_enable_iface_clock(void);
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700235int ocmem_enable_br_clock(void);
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700236void ocmem_disable_core_clock(void);
237void ocmem_disable_iface_clock(void);
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700238void ocmem_disable_br_clock(void);
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700239int ocmem_lock(enum ocmem_client, unsigned long, unsigned long,
240 enum region_mode);
241int ocmem_unlock(enum ocmem_client, unsigned long, unsigned long);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700242#endif