blob: abb565373a5adedc2125edacb0d0d8aaac3bb6c5 [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 {
45 unsigned long (*allocate) (struct ocmem_zone *, unsigned long);
46 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;
88};
89
Naveen Ramarajb9da05782012-05-07 09:07:35 -070090enum 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 Ramaraj99b07562012-05-28 20:57:09 -0700103/* Operational modes of each region */
104enum region_mode {
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700105 MODE_NOT_SET = 0x0,
106 WIDE_MODE,
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700107 THIN_MODE,
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700108 MODE_DEFAULT = MODE_NOT_SET,
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700109};
110
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700111struct ocmem_plat_data {
112 void __iomem *vbase;
113 unsigned long size;
114 unsigned long base;
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700115 struct clk *core_clk;
116 struct clk *iface_clk;
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700117 struct clk *br_clk;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700118 struct ocmem_partition *parts;
119 int nr_parts;
120 void __iomem *reg_base;
121 void __iomem *br_base;
122 void __iomem *dm_base;
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700123 struct dentry *debug_node;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700124 unsigned nr_regions;
125 unsigned nr_macros;
126 unsigned nr_ports;
127 int ocmem_irq;
128 int dm_irq;
129 bool interleaved;
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700130 bool rpm_pwr_ctrl;
131 unsigned rpm_rsc_type;
Naveen Ramaraj8ad63602012-05-09 20:50:39 -0700132};
133
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700134struct 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 Ramaraj0cd880a2012-10-16 17:38:06 -0700140 atomic_t pending;
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700141 bool passive;
142};
143
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700144struct 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 Ramarajcc4ec152012-05-14 09:55:29 -0700150 /* Chain in eviction list */
151 struct list_head eviction_list;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700152 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 Ramarajb9da05782012-05-07 09:07:35 -0700161 struct ocmem_map_list *mlist;
162 enum op_code op;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700163 unsigned long state;
164 /* Request assignments */
165 unsigned long req_start;
166 unsigned long req_end;
167 unsigned long req_sz;
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700168 /* Request Power State */
169 unsigned power_state;
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700170 struct ocmem_eviction_data *edata;
Naveen Ramaraj89738952013-02-13 15:24:57 -0800171 /* Request that triggered eviction */
172 struct ocmem_req *e_handle;
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700173};
174
175struct ocmem_handle {
176 struct ocmem_buf buffer;
177 struct mutex handle_mutex;
178 struct ocmem_req *req;
179};
180
Naveen Ramaraj3b6c5a92012-08-19 18:50:44 -0700181struct ocmem_buf *handle_to_buffer(struct ocmem_handle *);
182struct ocmem_handle *buffer_to_handle(struct ocmem_buf *);
183struct ocmem_req *handle_to_req(struct ocmem_handle *);
184struct ocmem_handle *req_to_handle(struct ocmem_req *);
185int ocmem_read(void *);
186int ocmem_write(unsigned long, void *);
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700187void inc_ocmem_stat(struct ocmem_zone *, enum ocmem_zstat_item);
188unsigned long get_ocmem_stat(struct ocmem_zone *z,
189 enum ocmem_zstat_item item);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700190struct ocmem_zone *get_zone(unsigned);
Naveen Ramaraj4d5e3542012-08-12 21:55:49 -0700191int zone_active(int);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700192unsigned long offset_to_phys(unsigned long);
193unsigned long phys_to_offset(unsigned long);
Naveen Ramaraj959d37f2012-04-23 11:59:01 -0700194unsigned long allocate_head(struct ocmem_zone *, unsigned long);
195int free_head(struct ocmem_zone *, unsigned long, unsigned long);
Naveen Ramaraj135cd672012-04-23 12:13:28 -0700196unsigned long allocate_tail(struct ocmem_zone *, unsigned long);
197int free_tail(struct ocmem_zone *, unsigned long, unsigned long);
Naveen Ramarajbdf4dfe2012-04-23 14:09:50 -0700198
199int ocmem_notifier_init(void);
200int check_notifier(int);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700201const char *get_name(int);
Naveen Ramaraje4cc4622012-10-29 17:28:57 -0700202int get_tz_id(int);
203int ocmem_enable_sec_program(int);
204int ocmem_enable_dump(enum ocmem_client, unsigned long, unsigned long);
205int ocmem_disable_dump(enum ocmem_client, unsigned long, unsigned long);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700206int check_id(int);
Naveen Ramarajbdf4dfe2012-04-23 14:09:50 -0700207int dispatch_notification(int, enum ocmem_notif_type, struct ocmem_buf *);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700208
Naveen Ramaraj6a92b262012-07-30 17:36:24 -0700209int ocmem_sched_init(struct platform_device *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700210int ocmem_rdm_init(struct platform_device *);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700211int ocmem_core_init(struct platform_device *);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700212int process_allocate(int, struct ocmem_handle *, unsigned long, unsigned long,
213 unsigned long, bool, bool);
214int process_free(int, struct ocmem_handle *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700215int process_xfer(int, struct ocmem_handle *, struct ocmem_map_list *, int);
Neeti Desaidad1d8e2013-01-09 19:42:06 -0800216int process_drop(int, struct ocmem_handle *, struct ocmem_map_list *);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700217int process_evict(int);
218int process_restore(int);
219int process_shrink(int, struct ocmem_handle *, unsigned long);
Naveen Ramaraj55ed8902012-09-26 13:18:06 -0700220int process_dump(int, struct ocmem_handle *, unsigned long);
Naveen Ramarajcc4ec152012-05-14 09:55:29 -0700221int ocmem_rdm_transfer(int, struct ocmem_map_list *,
222 unsigned long, int);
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700223int ocmem_clear(unsigned long, unsigned long);
Naveen Ramarajb9da05782012-05-07 09:07:35 -0700224unsigned long process_quota(int);
Naveen Ramaraj99b07562012-05-28 20:57:09 -0700225int ocmem_memory_off(int, unsigned long, unsigned long);
226int ocmem_memory_on(int, unsigned long, unsigned long);
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700227int ocmem_enable_core_clock(void);
228int ocmem_enable_iface_clock(void);
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700229int ocmem_enable_br_clock(void);
Naveen Ramarajbea2d5d2012-08-15 17:26:43 -0700230void ocmem_disable_core_clock(void);
231void ocmem_disable_iface_clock(void);
Naveen Ramaraj5da54542012-08-21 13:26:17 -0700232void ocmem_disable_br_clock(void);
Naveen Ramaraje43d9bb2012-08-20 14:41:13 -0700233int ocmem_lock(enum ocmem_client, unsigned long, unsigned long,
234 enum region_mode);
235int ocmem_unlock(enum ocmem_client, unsigned long, unsigned long);
Naveen Ramaraj51f5e8b2012-04-09 15:58:40 -0700236#endif