blob: d2a96c2c02a3e64475f3c0c3426e6af1a0c9af17 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * SRAM allocator for Blackfin on-chip memory
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2004-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Robin Getz96f10502009-09-24 14:11:24 +00006 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07007 */
8
Bryan Wu1394f032007-05-06 14:50:22 -07009#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/types.h>
12#include <linux/miscdevice.h>
13#include <linux/ioport.h>
14#include <linux/fcntl.h>
15#include <linux/init.h>
16#include <linux/poll.h>
17#include <linux/proc_fs.h>
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +030018#include <linux/seq_file.h>
Bryan Wu1394f032007-05-06 14:50:22 -070019#include <linux/spinlock.h>
20#include <linux/rtc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Ingo Molnar589ee622017-02-04 00:16:44 +010022#include <linux/mm_types.h>
23
Bryan Wu1394f032007-05-06 14:50:22 -070024#include <asm/blackfin.h>
Graf Yangdbc895f2009-01-07 23:14:39 +080025#include <asm/mem_map.h>
Bryan Wu1394f032007-05-06 14:50:22 -070026#include "blackfin_sram.h"
27
Bryan Wu1394f032007-05-06 14:50:22 -070028/* the data structure for L1 scratchpad and DATA SRAM */
Sonic Zhang5d481f42008-07-19 14:51:31 +080029struct sram_piece {
Bryan Wu1394f032007-05-06 14:50:22 -070030 void *paddr;
31 int size;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +080032 pid_t pid;
Sonic Zhang5d481f42008-07-19 14:51:31 +080033 struct sram_piece *next;
Bryan Wu1394f032007-05-06 14:50:22 -070034};
35
Mike Frysinger81c969a2009-07-01 15:42:13 +000036static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1sram_lock);
Graf Yang8f658732008-11-18 17:48:22 +080037static DEFINE_PER_CPU(struct sram_piece, free_l1_ssram_head);
38static DEFINE_PER_CPU(struct sram_piece, used_l1_ssram_head);
Bryan Wu1394f032007-05-06 14:50:22 -070039
40#if L1_DATA_A_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +080041static DEFINE_PER_CPU(struct sram_piece, free_l1_data_A_sram_head);
42static DEFINE_PER_CPU(struct sram_piece, used_l1_data_A_sram_head);
Bryan Wu1394f032007-05-06 14:50:22 -070043#endif
44
45#if L1_DATA_B_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +080046static DEFINE_PER_CPU(struct sram_piece, free_l1_data_B_sram_head);
47static DEFINE_PER_CPU(struct sram_piece, used_l1_data_B_sram_head);
Bryan Wu1394f032007-05-06 14:50:22 -070048#endif
49
Mike Frysinger81c969a2009-07-01 15:42:13 +000050#if L1_DATA_A_LENGTH || L1_DATA_B_LENGTH
51static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1_data_sram_lock);
52#endif
53
Bryan Wu1394f032007-05-06 14:50:22 -070054#if L1_CODE_LENGTH != 0
Mike Frysinger81c969a2009-07-01 15:42:13 +000055static DEFINE_PER_CPU_SHARED_ALIGNED(spinlock_t, l1_inst_sram_lock);
Graf Yang8f658732008-11-18 17:48:22 +080056static DEFINE_PER_CPU(struct sram_piece, free_l1_inst_sram_head);
57static DEFINE_PER_CPU(struct sram_piece, used_l1_inst_sram_head);
Bryan Wu1394f032007-05-06 14:50:22 -070058#endif
59
Mike Frysinger07aa7be2008-08-13 16:16:11 +080060#if L2_LENGTH != 0
Mike Frysinger81c969a2009-07-01 15:42:13 +000061static spinlock_t l2_sram_lock ____cacheline_aligned_in_smp;
Sonic Zhang262c3822008-07-19 15:42:41 +080062static struct sram_piece free_l2_sram_head, used_l2_sram_head;
63#endif
64
Sonic Zhang5d481f42008-07-19 14:51:31 +080065static struct kmem_cache *sram_piece_cache;
Bryan Wu1394f032007-05-06 14:50:22 -070066
Sonic Zhang5d481f42008-07-19 14:51:31 +080067/* L1 Scratchpad SRAM initialization function */
68static void __init l1sram_init(void)
69{
Graf Yang8f658732008-11-18 17:48:22 +080070 unsigned int cpu;
Graf Yang89ecd502009-05-25 06:40:42 +000071 unsigned long reserve;
72
73#ifdef CONFIG_SMP
74 reserve = 0;
75#else
76 reserve = sizeof(struct l1_scratch_task_info);
77#endif
78
Graf Yang8f658732008-11-18 17:48:22 +080079 for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
80 per_cpu(free_l1_ssram_head, cpu).next =
81 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
82 if (!per_cpu(free_l1_ssram_head, cpu).next) {
83 printk(KERN_INFO "Fail to initialize Scratchpad data SRAM.\n");
84 return;
85 }
86
Graf Yang89ecd502009-05-25 06:40:42 +000087 per_cpu(free_l1_ssram_head, cpu).next->paddr = (void *)get_l1_scratch_start_cpu(cpu) + reserve;
88 per_cpu(free_l1_ssram_head, cpu).next->size = L1_SCRATCH_LENGTH - reserve;
Graf Yang8f658732008-11-18 17:48:22 +080089 per_cpu(free_l1_ssram_head, cpu).next->pid = 0;
90 per_cpu(free_l1_ssram_head, cpu).next->next = NULL;
91
92 per_cpu(used_l1_ssram_head, cpu).next = NULL;
93
94 /* mutex initialize */
95 spin_lock_init(&per_cpu(l1sram_lock, cpu));
96 printk(KERN_INFO "Blackfin Scratchpad data SRAM: %d KB\n",
97 L1_SCRATCH_LENGTH >> 10);
Sonic Zhang5d481f42008-07-19 14:51:31 +080098 }
Bryan Wu1394f032007-05-06 14:50:22 -070099}
100
Sonic Zhang5d481f42008-07-19 14:51:31 +0800101static void __init l1_data_sram_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700102{
Mike Frysinger0b82e272008-11-18 17:48:22 +0800103#if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800104 unsigned int cpu;
Mike Frysinger0b82e272008-11-18 17:48:22 +0800105#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700106#if L1_DATA_A_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800107 for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
108 per_cpu(free_l1_data_A_sram_head, cpu).next =
109 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
110 if (!per_cpu(free_l1_data_A_sram_head, cpu).next) {
111 printk(KERN_INFO "Fail to initialize L1 Data A SRAM.\n");
112 return;
113 }
114
115 per_cpu(free_l1_data_A_sram_head, cpu).next->paddr =
116 (void *)get_l1_data_a_start_cpu(cpu) + (_ebss_l1 - _sdata_l1);
117 per_cpu(free_l1_data_A_sram_head, cpu).next->size =
118 L1_DATA_A_LENGTH - (_ebss_l1 - _sdata_l1);
119 per_cpu(free_l1_data_A_sram_head, cpu).next->pid = 0;
120 per_cpu(free_l1_data_A_sram_head, cpu).next->next = NULL;
121
122 per_cpu(used_l1_data_A_sram_head, cpu).next = NULL;
123
124 printk(KERN_INFO "Blackfin L1 Data A SRAM: %d KB (%d KB free)\n",
125 L1_DATA_A_LENGTH >> 10,
126 per_cpu(free_l1_data_A_sram_head, cpu).next->size >> 10);
Sonic Zhang5d481f42008-07-19 14:51:31 +0800127 }
Bryan Wu1394f032007-05-06 14:50:22 -0700128#endif
129#if L1_DATA_B_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800130 for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
131 per_cpu(free_l1_data_B_sram_head, cpu).next =
132 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
133 if (!per_cpu(free_l1_data_B_sram_head, cpu).next) {
134 printk(KERN_INFO "Fail to initialize L1 Data B SRAM.\n");
135 return;
136 }
137
138 per_cpu(free_l1_data_B_sram_head, cpu).next->paddr =
139 (void *)get_l1_data_b_start_cpu(cpu) + (_ebss_b_l1 - _sdata_b_l1);
140 per_cpu(free_l1_data_B_sram_head, cpu).next->size =
141 L1_DATA_B_LENGTH - (_ebss_b_l1 - _sdata_b_l1);
142 per_cpu(free_l1_data_B_sram_head, cpu).next->pid = 0;
143 per_cpu(free_l1_data_B_sram_head, cpu).next->next = NULL;
144
145 per_cpu(used_l1_data_B_sram_head, cpu).next = NULL;
146
147 printk(KERN_INFO "Blackfin L1 Data B SRAM: %d KB (%d KB free)\n",
148 L1_DATA_B_LENGTH >> 10,
149 per_cpu(free_l1_data_B_sram_head, cpu).next->size >> 10);
150 /* mutex initialize */
Sonic Zhang5d481f42008-07-19 14:51:31 +0800151 }
Bryan Wu1394f032007-05-06 14:50:22 -0700152#endif
153
Graf Yang8f658732008-11-18 17:48:22 +0800154#if L1_DATA_A_LENGTH != 0 || L1_DATA_B_LENGTH != 0
155 for (cpu = 0; cpu < num_possible_cpus(); ++cpu)
156 spin_lock_init(&per_cpu(l1_data_sram_lock, cpu));
157#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700158}
159
Sonic Zhang5d481f42008-07-19 14:51:31 +0800160static void __init l1_inst_sram_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700161{
162#if L1_CODE_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800163 unsigned int cpu;
164 for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
165 per_cpu(free_l1_inst_sram_head, cpu).next =
166 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
167 if (!per_cpu(free_l1_inst_sram_head, cpu).next) {
168 printk(KERN_INFO "Failed to initialize L1 Instruction SRAM\n");
169 return;
170 }
171
172 per_cpu(free_l1_inst_sram_head, cpu).next->paddr =
173 (void *)get_l1_code_start_cpu(cpu) + (_etext_l1 - _stext_l1);
174 per_cpu(free_l1_inst_sram_head, cpu).next->size =
175 L1_CODE_LENGTH - (_etext_l1 - _stext_l1);
176 per_cpu(free_l1_inst_sram_head, cpu).next->pid = 0;
177 per_cpu(free_l1_inst_sram_head, cpu).next->next = NULL;
178
179 per_cpu(used_l1_inst_sram_head, cpu).next = NULL;
180
181 printk(KERN_INFO "Blackfin L1 Instruction SRAM: %d KB (%d KB free)\n",
182 L1_CODE_LENGTH >> 10,
183 per_cpu(free_l1_inst_sram_head, cpu).next->size >> 10);
184
185 /* mutex initialize */
186 spin_lock_init(&per_cpu(l1_inst_sram_lock, cpu));
Sonic Zhang5d481f42008-07-19 14:51:31 +0800187 }
Bryan Wu1394f032007-05-06 14:50:22 -0700188#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700189}
190
Bob Liub2cfc652012-05-16 18:18:27 +0800191#ifdef __ADSPBF60x__
192static irqreturn_t l2_ecc_err(int irq, void *dev_id)
193{
194 int status;
195
Masanari Iida744627e92012-11-05 23:30:40 +0900196 printk(KERN_ERR "L2 ecc error happened\n");
Bob Liub2cfc652012-05-16 18:18:27 +0800197 status = bfin_read32(L2CTL0_STAT);
198 if (status & 0x1)
199 printk(KERN_ERR "Core channel error type:0x%x, addr:0x%x\n",
200 bfin_read32(L2CTL0_ET0), bfin_read32(L2CTL0_EADDR0));
201 if (status & 0x2)
202 printk(KERN_ERR "System channel error type:0x%x, addr:0x%x\n",
203 bfin_read32(L2CTL0_ET1), bfin_read32(L2CTL0_EADDR1));
204
205 status = status >> 8;
206 if (status)
207 printk(KERN_ERR "L2 Bank%d error, addr:0x%x\n",
208 status, bfin_read32(L2CTL0_ERRADDR0 + status));
209
210 panic("L2 Ecc error");
211 return IRQ_HANDLED;
212}
213#endif
214
Sonic Zhang262c3822008-07-19 15:42:41 +0800215static void __init l2_sram_init(void)
216{
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800217#if L2_LENGTH != 0
Bob Liub2cfc652012-05-16 18:18:27 +0800218
219#ifdef __ADSPBF60x__
220 int ret;
221
222 ret = request_irq(IRQ_L2CTL0_ECC_ERR, l2_ecc_err, 0, "l2-ecc-err",
223 NULL);
224 if (unlikely(ret < 0)) {
225 printk(KERN_INFO "Fail to request l2 ecc error interrupt");
226 return;
227 }
228#endif
229
Sonic Zhang262c3822008-07-19 15:42:41 +0800230 free_l2_sram_head.next =
231 kmem_cache_alloc(sram_piece_cache, GFP_KERNEL);
232 if (!free_l2_sram_head.next) {
Graf Yang8f658732008-11-18 17:48:22 +0800233 printk(KERN_INFO "Fail to initialize L2 SRAM.\n");
Sonic Zhang262c3822008-07-19 15:42:41 +0800234 return;
235 }
236
Jie Zhangb2c2f302008-10-28 15:57:49 +0800237 free_l2_sram_head.next->paddr =
238 (void *)L2_START + (_ebss_l2 - _stext_l2);
239 free_l2_sram_head.next->size =
240 L2_LENGTH - (_ebss_l2 - _stext_l2);
Sonic Zhang262c3822008-07-19 15:42:41 +0800241 free_l2_sram_head.next->pid = 0;
242 free_l2_sram_head.next->next = NULL;
243
244 used_l2_sram_head.next = NULL;
245
246 printk(KERN_INFO "Blackfin L2 SRAM: %d KB (%d KB free)\n",
247 L2_LENGTH >> 10,
248 free_l2_sram_head.next->size >> 10);
Sonic Zhang262c3822008-07-19 15:42:41 +0800249
250 /* mutex initialize */
251 spin_lock_init(&l2_sram_lock);
Mike Frysinger81c969a2009-07-01 15:42:13 +0000252#endif
Sonic Zhang262c3822008-07-19 15:42:41 +0800253}
Graf Yang8f658732008-11-18 17:48:22 +0800254
Graf Yangc72aa072009-05-25 04:44:00 +0000255static int __init bfin_sram_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700256{
Sonic Zhang5d481f42008-07-19 14:51:31 +0800257 sram_piece_cache = kmem_cache_create("sram_piece_cache",
258 sizeof(struct sram_piece),
259 0, SLAB_PANIC, NULL);
Bryan Wu1394f032007-05-06 14:50:22 -0700260
Sonic Zhang5d481f42008-07-19 14:51:31 +0800261 l1sram_init();
262 l1_data_sram_init();
263 l1_inst_sram_init();
Sonic Zhang262c3822008-07-19 15:42:41 +0800264 l2_sram_init();
Graf Yangc72aa072009-05-25 04:44:00 +0000265
266 return 0;
Sonic Zhang5d481f42008-07-19 14:51:31 +0800267}
Graf Yangc72aa072009-05-25 04:44:00 +0000268pure_initcall(bfin_sram_init);
Sonic Zhang5d481f42008-07-19 14:51:31 +0800269
Sonic Zhang262c3822008-07-19 15:42:41 +0800270/* SRAM allocate function */
271static void *_sram_alloc(size_t size, struct sram_piece *pfree_head,
Sonic Zhang5d481f42008-07-19 14:51:31 +0800272 struct sram_piece *pused_head)
273{
274 struct sram_piece *pslot, *plast, *pavail;
275
276 if (size <= 0 || !pfree_head || !pused_head)
Bryan Wu1394f032007-05-06 14:50:22 -0700277 return NULL;
278
279 /* Align the size */
280 size = (size + 3) & ~3;
281
Sonic Zhang5d481f42008-07-19 14:51:31 +0800282 pslot = pfree_head->next;
283 plast = pfree_head;
284
285 /* search an available piece slot */
286 while (pslot != NULL && size > pslot->size) {
287 plast = pslot;
288 pslot = pslot->next;
Bryan Wu1394f032007-05-06 14:50:22 -0700289 }
Sonic Zhang5d481f42008-07-19 14:51:31 +0800290
291 if (!pslot)
Bryan Wu1394f032007-05-06 14:50:22 -0700292 return NULL;
293
Sonic Zhang5d481f42008-07-19 14:51:31 +0800294 if (pslot->size == size) {
295 plast->next = pslot->next;
296 pavail = pslot;
297 } else {
Mike Frysingereb5400b2010-05-11 04:43:19 +0000298 /* use atomic so our L1 allocator can be used atomically */
299 pavail = kmem_cache_alloc(sram_piece_cache, GFP_ATOMIC);
Sonic Zhang5d481f42008-07-19 14:51:31 +0800300
301 if (!pavail)
302 return NULL;
303
304 pavail->paddr = pslot->paddr;
305 pavail->size = size;
306 pslot->paddr += size;
307 pslot->size -= size;
Bryan Wu1394f032007-05-06 14:50:22 -0700308 }
309
Sonic Zhang5d481f42008-07-19 14:51:31 +0800310 pavail->pid = current->pid;
311
312 pslot = pused_head->next;
313 plast = pused_head;
314
315 /* insert new piece into used piece list !!! */
316 while (pslot != NULL && pavail->paddr < pslot->paddr) {
317 plast = pslot;
318 pslot = pslot->next;
319 }
320
321 pavail->next = pslot;
322 plast->next = pavail;
323
324 return pavail->paddr;
Bryan Wu1394f032007-05-06 14:50:22 -0700325}
326
327/* Allocate the largest available block. */
Sonic Zhang262c3822008-07-19 15:42:41 +0800328static void *_sram_alloc_max(struct sram_piece *pfree_head,
Sonic Zhang5d481f42008-07-19 14:51:31 +0800329 struct sram_piece *pused_head,
Bryan Wu1394f032007-05-06 14:50:22 -0700330 unsigned long *psize)
331{
Sonic Zhang5d481f42008-07-19 14:51:31 +0800332 struct sram_piece *pslot, *pmax;
Bryan Wu1394f032007-05-06 14:50:22 -0700333
Sonic Zhang5d481f42008-07-19 14:51:31 +0800334 if (!pfree_head || !pused_head)
Bryan Wu1394f032007-05-06 14:50:22 -0700335 return NULL;
Bryan Wu1394f032007-05-06 14:50:22 -0700336
Sonic Zhang5d481f42008-07-19 14:51:31 +0800337 pmax = pslot = pfree_head->next;
338
339 /* search an available piece slot */
340 while (pslot != NULL) {
341 if (pslot->size > pmax->size)
342 pmax = pslot;
343 pslot = pslot->next;
344 }
345
346 if (!pmax)
347 return NULL;
348
349 *psize = pmax->size;
350
Sonic Zhang262c3822008-07-19 15:42:41 +0800351 return _sram_alloc(*psize, pfree_head, pused_head);
Bryan Wu1394f032007-05-06 14:50:22 -0700352}
353
Sonic Zhang262c3822008-07-19 15:42:41 +0800354/* SRAM free function */
355static int _sram_free(const void *addr,
Sonic Zhang5d481f42008-07-19 14:51:31 +0800356 struct sram_piece *pfree_head,
357 struct sram_piece *pused_head)
Bryan Wu1394f032007-05-06 14:50:22 -0700358{
Sonic Zhang5d481f42008-07-19 14:51:31 +0800359 struct sram_piece *pslot, *plast, *pavail;
Bryan Wu1394f032007-05-06 14:50:22 -0700360
Sonic Zhang5d481f42008-07-19 14:51:31 +0800361 if (!pfree_head || !pused_head)
Bryan Wu1394f032007-05-06 14:50:22 -0700362 return -1;
363
Sonic Zhang5d481f42008-07-19 14:51:31 +0800364 /* search the relevant memory slot */
365 pslot = pused_head->next;
366 plast = pused_head;
Bryan Wu1394f032007-05-06 14:50:22 -0700367
Sonic Zhang5d481f42008-07-19 14:51:31 +0800368 /* search an available piece slot */
369 while (pslot != NULL && pslot->paddr != addr) {
370 plast = pslot;
371 pslot = pslot->next;
Bryan Wu1394f032007-05-06 14:50:22 -0700372 }
373
Sonic Zhang5d481f42008-07-19 14:51:31 +0800374 if (!pslot)
375 return -1;
376
377 plast->next = pslot->next;
378 pavail = pslot;
379 pavail->pid = 0;
380
381 /* insert free pieces back to the free list */
382 pslot = pfree_head->next;
383 plast = pfree_head;
384
385 while (pslot != NULL && addr > pslot->paddr) {
386 plast = pslot;
387 pslot = pslot->next;
388 }
389
390 if (plast != pfree_head && plast->paddr + plast->size == pavail->paddr) {
391 plast->size += pavail->size;
392 kmem_cache_free(sram_piece_cache, pavail);
393 } else {
Sonic Zhang225f7e12008-08-25 18:00:45 +0800394 pavail->next = plast->next;
Sonic Zhang5d481f42008-07-19 14:51:31 +0800395 plast->next = pavail;
396 plast = pavail;
397 }
398
399 if (pslot && plast->paddr + plast->size == pslot->paddr) {
400 plast->size += pslot->size;
401 plast->next = pslot->next;
402 kmem_cache_free(sram_piece_cache, pslot);
Bryan Wu1394f032007-05-06 14:50:22 -0700403 }
404
405 return 0;
406}
407
408int sram_free(const void *addr)
409{
Robin Getz5e953202008-10-08 17:22:49 +0800410
Bryan Wu1394f032007-05-06 14:50:22 -0700411#if L1_CODE_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800412 if (addr >= (void *)get_l1_code_start()
413 && addr < (void *)(get_l1_code_start() + L1_CODE_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700414 return l1_inst_sram_free(addr);
Robin Getz5e953202008-10-08 17:22:49 +0800415 else
Bryan Wu1394f032007-05-06 14:50:22 -0700416#endif
417#if L1_DATA_A_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800418 if (addr >= (void *)get_l1_data_a_start()
419 && addr < (void *)(get_l1_data_a_start() + L1_DATA_A_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700420 return l1_data_A_sram_free(addr);
Robin Getz5e953202008-10-08 17:22:49 +0800421 else
Bryan Wu1394f032007-05-06 14:50:22 -0700422#endif
423#if L1_DATA_B_LENGTH != 0
Graf Yang8f658732008-11-18 17:48:22 +0800424 if (addr >= (void *)get_l1_data_b_start()
425 && addr < (void *)(get_l1_data_b_start() + L1_DATA_B_LENGTH))
Bryan Wu1394f032007-05-06 14:50:22 -0700426 return l1_data_B_sram_free(addr);
Robin Getz5e953202008-10-08 17:22:49 +0800427 else
Bryan Wu1394f032007-05-06 14:50:22 -0700428#endif
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800429#if L2_LENGTH != 0
Robin Getz5e953202008-10-08 17:22:49 +0800430 if (addr >= (void *)L2_START
Sonic Zhang262c3822008-07-19 15:42:41 +0800431 && addr < (void *)(L2_START + L2_LENGTH))
432 return l2_sram_free(addr);
Bryan Wu1394f032007-05-06 14:50:22 -0700433 else
Robin Getz5e953202008-10-08 17:22:49 +0800434#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700435 return -1;
436}
437EXPORT_SYMBOL(sram_free);
438
439void *l1_data_A_sram_alloc(size_t size)
440{
Mike Frysinger81c969a2009-07-01 15:42:13 +0000441#if L1_DATA_A_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800442 unsigned long flags;
Mike Frysinger81c969a2009-07-01 15:42:13 +0000443 void *addr;
Graf Yang8f658732008-11-18 17:48:22 +0800444 unsigned int cpu;
Bryan Wu1394f032007-05-06 14:50:22 -0700445
Yi Li54536c52009-12-30 04:04:07 +0000446 cpu = smp_processor_id();
Bryan Wu1394f032007-05-06 14:50:22 -0700447 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800448 spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700449
Graf Yang8f658732008-11-18 17:48:22 +0800450 addr = _sram_alloc(size, &per_cpu(free_l1_data_A_sram_head, cpu),
451 &per_cpu(used_l1_data_A_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700452
453 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800454 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700455
456 pr_debug("Allocated address in l1_data_A_sram_alloc is 0x%lx+0x%lx\n",
457 (long unsigned int)addr, size);
458
459 return addr;
Mike Frysinger81c969a2009-07-01 15:42:13 +0000460#else
461 return NULL;
462#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700463}
464EXPORT_SYMBOL(l1_data_A_sram_alloc);
465
466int l1_data_A_sram_free(const void *addr)
467{
Mike Frysinger81c969a2009-07-01 15:42:13 +0000468#if L1_DATA_A_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800469 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700470 int ret;
Graf Yang8f658732008-11-18 17:48:22 +0800471 unsigned int cpu;
Bryan Wu1394f032007-05-06 14:50:22 -0700472
Yi Li54536c52009-12-30 04:04:07 +0000473 cpu = smp_processor_id();
Bryan Wu1394f032007-05-06 14:50:22 -0700474 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800475 spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700476
Graf Yang8f658732008-11-18 17:48:22 +0800477 ret = _sram_free(addr, &per_cpu(free_l1_data_A_sram_head, cpu),
478 &per_cpu(used_l1_data_A_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700479
480 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800481 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700482
483 return ret;
Mike Frysinger81c969a2009-07-01 15:42:13 +0000484#else
485 return -1;
486#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700487}
488EXPORT_SYMBOL(l1_data_A_sram_free);
489
490void *l1_data_B_sram_alloc(size_t size)
491{
492#if L1_DATA_B_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800493 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700494 void *addr;
Graf Yang8f658732008-11-18 17:48:22 +0800495 unsigned int cpu;
496
Yi Li54536c52009-12-30 04:04:07 +0000497 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800498 /* add mutex operation */
499 spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
500
501 addr = _sram_alloc(size, &per_cpu(free_l1_data_B_sram_head, cpu),
502 &per_cpu(used_l1_data_B_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700503
504 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800505 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700506
507 pr_debug("Allocated address in l1_data_B_sram_alloc is 0x%lx+0x%lx\n",
508 (long unsigned int)addr, size);
509
510 return addr;
511#else
512 return NULL;
513#endif
514}
515EXPORT_SYMBOL(l1_data_B_sram_alloc);
516
517int l1_data_B_sram_free(const void *addr)
518{
519#if L1_DATA_B_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800520 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700521 int ret;
Graf Yang8f658732008-11-18 17:48:22 +0800522 unsigned int cpu;
523
Yi Li54536c52009-12-30 04:04:07 +0000524 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800525 /* add mutex operation */
526 spin_lock_irqsave(&per_cpu(l1_data_sram_lock, cpu), flags);
527
528 ret = _sram_free(addr, &per_cpu(free_l1_data_B_sram_head, cpu),
529 &per_cpu(used_l1_data_B_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700530
531 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800532 spin_unlock_irqrestore(&per_cpu(l1_data_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700533
534 return ret;
535#else
536 return -1;
537#endif
538}
539EXPORT_SYMBOL(l1_data_B_sram_free);
540
541void *l1_data_sram_alloc(size_t size)
542{
543 void *addr = l1_data_A_sram_alloc(size);
544
545 if (!addr)
546 addr = l1_data_B_sram_alloc(size);
547
548 return addr;
549}
550EXPORT_SYMBOL(l1_data_sram_alloc);
551
552void *l1_data_sram_zalloc(size_t size)
553{
554 void *addr = l1_data_sram_alloc(size);
555
556 if (addr)
557 memset(addr, 0x00, size);
558
559 return addr;
560}
561EXPORT_SYMBOL(l1_data_sram_zalloc);
562
563int l1_data_sram_free(const void *addr)
564{
565 int ret;
566 ret = l1_data_A_sram_free(addr);
567 if (ret == -1)
568 ret = l1_data_B_sram_free(addr);
569 return ret;
570}
571EXPORT_SYMBOL(l1_data_sram_free);
572
573void *l1_inst_sram_alloc(size_t size)
574{
Meihui Fanc5b50df2008-04-23 08:55:26 +0800575#if L1_CODE_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800576 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700577 void *addr;
Graf Yang8f658732008-11-18 17:48:22 +0800578 unsigned int cpu;
579
Yi Li54536c52009-12-30 04:04:07 +0000580 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800581 /* add mutex operation */
582 spin_lock_irqsave(&per_cpu(l1_inst_sram_lock, cpu), flags);
583
584 addr = _sram_alloc(size, &per_cpu(free_l1_inst_sram_head, cpu),
585 &per_cpu(used_l1_inst_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700586
587 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800588 spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700589
590 pr_debug("Allocated address in l1_inst_sram_alloc is 0x%lx+0x%lx\n",
591 (long unsigned int)addr, size);
592
593 return addr;
594#else
595 return NULL;
596#endif
597}
598EXPORT_SYMBOL(l1_inst_sram_alloc);
599
600int l1_inst_sram_free(const void *addr)
601{
602#if L1_CODE_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800603 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700604 int ret;
Graf Yang8f658732008-11-18 17:48:22 +0800605 unsigned int cpu;
606
Yi Li54536c52009-12-30 04:04:07 +0000607 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800608 /* add mutex operation */
609 spin_lock_irqsave(&per_cpu(l1_inst_sram_lock, cpu), flags);
610
611 ret = _sram_free(addr, &per_cpu(free_l1_inst_sram_head, cpu),
612 &per_cpu(used_l1_inst_sram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700613
614 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800615 spin_unlock_irqrestore(&per_cpu(l1_inst_sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700616
617 return ret;
618#else
619 return -1;
620#endif
621}
622EXPORT_SYMBOL(l1_inst_sram_free);
623
624/* L1 Scratchpad memory allocate function */
625void *l1sram_alloc(size_t size)
626{
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800627 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700628 void *addr;
Graf Yang8f658732008-11-18 17:48:22 +0800629 unsigned int cpu;
630
Yi Li54536c52009-12-30 04:04:07 +0000631 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800632 /* add mutex operation */
633 spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
634
635 addr = _sram_alloc(size, &per_cpu(free_l1_ssram_head, cpu),
636 &per_cpu(used_l1_ssram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700637
638 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800639 spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700640
641 return addr;
642}
643
644/* L1 Scratchpad memory allocate function */
645void *l1sram_alloc_max(size_t *psize)
646{
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800647 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700648 void *addr;
Graf Yang8f658732008-11-18 17:48:22 +0800649 unsigned int cpu;
650
Yi Li54536c52009-12-30 04:04:07 +0000651 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800652 /* add mutex operation */
653 spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
654
655 addr = _sram_alloc_max(&per_cpu(free_l1_ssram_head, cpu),
656 &per_cpu(used_l1_ssram_head, cpu), psize);
Bryan Wu1394f032007-05-06 14:50:22 -0700657
658 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800659 spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700660
661 return addr;
662}
663
664/* L1 Scratchpad memory free function */
665int l1sram_free(const void *addr)
666{
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800667 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700668 int ret;
Graf Yang8f658732008-11-18 17:48:22 +0800669 unsigned int cpu;
670
Yi Li54536c52009-12-30 04:04:07 +0000671 cpu = smp_processor_id();
Graf Yang8f658732008-11-18 17:48:22 +0800672 /* add mutex operation */
673 spin_lock_irqsave(&per_cpu(l1sram_lock, cpu), flags);
674
675 ret = _sram_free(addr, &per_cpu(free_l1_ssram_head, cpu),
676 &per_cpu(used_l1_ssram_head, cpu));
Bryan Wu1394f032007-05-06 14:50:22 -0700677
678 /* add mutex operation */
Graf Yang8f658732008-11-18 17:48:22 +0800679 spin_unlock_irqrestore(&per_cpu(l1sram_lock, cpu), flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700680
681 return ret;
682}
683
Sonic Zhang262c3822008-07-19 15:42:41 +0800684void *l2_sram_alloc(size_t size)
685{
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800686#if L2_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800687 unsigned long flags;
Sonic Zhang262c3822008-07-19 15:42:41 +0800688 void *addr;
689
690 /* add mutex operation */
691 spin_lock_irqsave(&l2_sram_lock, flags);
692
693 addr = _sram_alloc(size, &free_l2_sram_head,
694 &used_l2_sram_head);
695
696 /* add mutex operation */
697 spin_unlock_irqrestore(&l2_sram_lock, flags);
698
699 pr_debug("Allocated address in l2_sram_alloc is 0x%lx+0x%lx\n",
700 (long unsigned int)addr, size);
701
702 return addr;
703#else
704 return NULL;
705#endif
706}
707EXPORT_SYMBOL(l2_sram_alloc);
708
709void *l2_sram_zalloc(size_t size)
710{
711 void *addr = l2_sram_alloc(size);
712
713 if (addr)
714 memset(addr, 0x00, size);
715
716 return addr;
717}
718EXPORT_SYMBOL(l2_sram_zalloc);
719
720int l2_sram_free(const void *addr)
721{
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800722#if L2_LENGTH != 0
Vegard Nossum226a6ec2008-08-28 17:28:46 +0800723 unsigned long flags;
Sonic Zhang262c3822008-07-19 15:42:41 +0800724 int ret;
725
726 /* add mutex operation */
727 spin_lock_irqsave(&l2_sram_lock, flags);
728
729 ret = _sram_free(addr, &free_l2_sram_head,
730 &used_l2_sram_head);
731
732 /* add mutex operation */
733 spin_unlock_irqrestore(&l2_sram_lock, flags);
734
735 return ret;
736#else
737 return -1;
738#endif
739}
740EXPORT_SYMBOL(l2_sram_free);
741
Bryan Wu1394f032007-05-06 14:50:22 -0700742int sram_free_with_lsl(const void *addr)
743{
744 struct sram_list_struct *lsl, **tmp;
745 struct mm_struct *mm = current->mm;
Mike Frysinger25f3ff22010-12-06 21:12:23 +0000746 int ret = -1;
Bryan Wu1394f032007-05-06 14:50:22 -0700747
748 for (tmp = &mm->context.sram_list; *tmp; tmp = &(*tmp)->next)
Mike Frysinger25f3ff22010-12-06 21:12:23 +0000749 if ((*tmp)->addr == addr) {
750 lsl = *tmp;
751 ret = sram_free(addr);
752 *tmp = lsl->next;
753 kfree(lsl);
754 break;
755 }
Bryan Wu1394f032007-05-06 14:50:22 -0700756
Mike Frysinger25f3ff22010-12-06 21:12:23 +0000757 return ret;
Bryan Wu1394f032007-05-06 14:50:22 -0700758}
759EXPORT_SYMBOL(sram_free_with_lsl);
760
Mike Frysingerf1db88d2009-06-02 08:46:35 +0000761/* Allocate memory and keep in L1 SRAM List (lsl) so that the resources are
762 * tracked. These are designed for userspace so that when a process exits,
763 * we can safely reap their resources.
764 */
Bryan Wu1394f032007-05-06 14:50:22 -0700765void *sram_alloc_with_lsl(size_t size, unsigned long flags)
766{
767 void *addr = NULL;
768 struct sram_list_struct *lsl = NULL;
769 struct mm_struct *mm = current->mm;
770
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700771 lsl = kzalloc(sizeof(struct sram_list_struct), GFP_KERNEL);
Bryan Wu1394f032007-05-06 14:50:22 -0700772 if (!lsl)
773 return NULL;
Bryan Wu1394f032007-05-06 14:50:22 -0700774
775 if (flags & L1_INST_SRAM)
776 addr = l1_inst_sram_alloc(size);
777
778 if (addr == NULL && (flags & L1_DATA_A_SRAM))
779 addr = l1_data_A_sram_alloc(size);
780
781 if (addr == NULL && (flags & L1_DATA_B_SRAM))
782 addr = l1_data_B_sram_alloc(size);
783
Sonic Zhang262c3822008-07-19 15:42:41 +0800784 if (addr == NULL && (flags & L2_SRAM))
785 addr = l2_sram_alloc(size);
786
Bryan Wu1394f032007-05-06 14:50:22 -0700787 if (addr == NULL) {
788 kfree(lsl);
789 return NULL;
790 }
791 lsl->addr = addr;
792 lsl->length = size;
793 lsl->next = mm->context.sram_list;
794 mm->context.sram_list = lsl;
795 return addr;
796}
797EXPORT_SYMBOL(sram_alloc_with_lsl);
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800798
799#ifdef CONFIG_PROC_FS
800/* Once we get a real allocator, we'll throw all of this away.
801 * Until then, we need some sort of visibility into the L1 alloc.
802 */
Mike Frysinger260d5d32008-07-14 16:34:05 +0800803/* Need to keep line of output the same. Currently, that is 44 bytes
804 * (including newline).
805 */
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300806static int _sram_proc_show(struct seq_file *m, const char *desc,
Sonic Zhang5d481f42008-07-19 14:51:31 +0800807 struct sram_piece *pfree_head,
808 struct sram_piece *pused_head)
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800809{
Sonic Zhang5d481f42008-07-19 14:51:31 +0800810 struct sram_piece *pslot;
811
812 if (!pfree_head || !pused_head)
813 return -1;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800814
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300815 seq_printf(m, "--- SRAM %-14s Size PID State \n", desc);
Sonic Zhang5d481f42008-07-19 14:51:31 +0800816
817 /* search the relevant memory slot */
818 pslot = pused_head->next;
819
820 while (pslot != NULL) {
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300821 seq_printf(m, "%p-%p %10i %5i %-10s\n",
Sonic Zhang5d481f42008-07-19 14:51:31 +0800822 pslot->paddr, pslot->paddr + pslot->size,
823 pslot->size, pslot->pid, "ALLOCATED");
824
825 pslot = pslot->next;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800826 }
Sonic Zhang5d481f42008-07-19 14:51:31 +0800827
828 pslot = pfree_head->next;
829
830 while (pslot != NULL) {
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300831 seq_printf(m, "%p-%p %10i %5i %-10s\n",
Sonic Zhang5d481f42008-07-19 14:51:31 +0800832 pslot->paddr, pslot->paddr + pslot->size,
833 pslot->size, pslot->pid, "FREE");
834
835 pslot = pslot->next;
836 }
837
838 return 0;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800839}
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300840static int sram_proc_show(struct seq_file *m, void *v)
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800841{
Graf Yang8f658732008-11-18 17:48:22 +0800842 unsigned int cpu;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800843
Graf Yang8f658732008-11-18 17:48:22 +0800844 for (cpu = 0; cpu < num_possible_cpus(); ++cpu) {
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300845 if (_sram_proc_show(m, "Scratchpad",
Graf Yang8f658732008-11-18 17:48:22 +0800846 &per_cpu(free_l1_ssram_head, cpu), &per_cpu(used_l1_ssram_head, cpu)))
847 goto not_done;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800848#if L1_DATA_A_LENGTH != 0
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300849 if (_sram_proc_show(m, "L1 Data A",
Graf Yang8f658732008-11-18 17:48:22 +0800850 &per_cpu(free_l1_data_A_sram_head, cpu),
851 &per_cpu(used_l1_data_A_sram_head, cpu)))
852 goto not_done;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800853#endif
854#if L1_DATA_B_LENGTH != 0
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300855 if (_sram_proc_show(m, "L1 Data B",
Graf Yang8f658732008-11-18 17:48:22 +0800856 &per_cpu(free_l1_data_B_sram_head, cpu),
857 &per_cpu(used_l1_data_B_sram_head, cpu)))
858 goto not_done;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800859#endif
860#if L1_CODE_LENGTH != 0
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300861 if (_sram_proc_show(m, "L1 Instruction",
Graf Yang8f658732008-11-18 17:48:22 +0800862 &per_cpu(free_l1_inst_sram_head, cpu),
863 &per_cpu(used_l1_inst_sram_head, cpu)))
864 goto not_done;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800865#endif
Graf Yang8f658732008-11-18 17:48:22 +0800866 }
Mike Frysinger07aa7be2008-08-13 16:16:11 +0800867#if L2_LENGTH != 0
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300868 if (_sram_proc_show(m, "L2", &free_l2_sram_head, &used_l2_sram_head))
Sonic Zhang262c3822008-07-19 15:42:41 +0800869 goto not_done;
870#endif
Mike Frysinger260d5d32008-07-14 16:34:05 +0800871 not_done:
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300872 return 0;
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800873}
874
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300875static int sram_proc_open(struct inode *inode, struct file *file)
876{
877 return single_open(file, sram_proc_show, NULL);
878}
879
880static const struct file_operations sram_proc_ops = {
881 .open = sram_proc_open,
882 .read = seq_read,
883 .llseek = seq_lseek,
884 .release = single_release,
885};
886
Sonic Zhang262c3822008-07-19 15:42:41 +0800887static int __init sram_proc_init(void)
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800888{
889 struct proc_dir_entry *ptr;
Alexey Dobriyan934fe05b2011-05-14 19:51:54 +0300890
891 ptr = proc_create("sram", S_IRUGO, NULL, &sram_proc_ops);
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800892 if (!ptr) {
893 printk(KERN_WARNING "unable to create /proc/sram\n");
894 return -1;
895 }
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800896 return 0;
897}
Sonic Zhang262c3822008-07-19 15:42:41 +0800898late_initcall(sram_proc_init);
Mike Frysingerbc61b4e2007-06-14 13:21:08 +0800899#endif