blob: 7498e7f7cf13fa36ae50f8738b2f5f600b06f958 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
Duy Truong790f06d2013-02-13 16:38:12 -08002 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/spinlock.h>
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040015#include <linux/module.h>
Stephen Boyd387ac2e2011-09-28 10:29:43 -070016#include <asm/mach-types.h>
Matt Wagantalld1fd5662012-06-08 13:49:43 -070017#include <asm/cputype.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018
19DEFINE_RAW_SPINLOCK(l2_access_lock);
20
21u32 set_get_l2_indirect_reg(u32 reg_addr, u32 val)
22{
23 unsigned long flags;
24 u32 ret_val;
Matt Wagantalld1fd5662012-06-08 13:49:43 -070025
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026 raw_spin_lock_irqsave(&l2_access_lock, flags);
Stephen Boyd387ac2e2011-09-28 10:29:43 -070027 mb();
28 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080029 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070030 "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080031 "isb\n\t"
32 "mrc p15, 3, %[l2cpdr_read], c15, c0, 7\n\t"
33 : [l2cpdr_read]"=r" (ret_val)
Stephen Boyd387ac2e2011-09-28 10:29:43 -070034 : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val)
35 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
37
38 return ret_val;
39}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040040EXPORT_SYMBOL(set_get_l2_indirect_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041
42void set_l2_indirect_reg(u32 reg_addr, u32 val)
43{
44 unsigned long flags;
Matt Wagantalld1fd5662012-06-08 13:49:43 -070045
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046 raw_spin_lock_irqsave(&l2_access_lock, flags);
Stephen Boyd387ac2e2011-09-28 10:29:43 -070047 mb();
48 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080049 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070050 "mcr p15, 3, %[l2cpdr], c15, c0, 7\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080051 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070052 :
53 : [l2cpselr]"r" (reg_addr), [l2cpdr]"r" (val)
54 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
56}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040057EXPORT_SYMBOL(set_l2_indirect_reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058
59u32 get_l2_indirect_reg(u32 reg_addr)
60{
61 u32 val;
62 unsigned long flags;
63
64 raw_spin_lock_irqsave(&l2_access_lock, flags);
Stephen Boyd387ac2e2011-09-28 10:29:43 -070065 asm volatile ("mcr p15, 3, %[l2cpselr], c15, c0, 6\n\t"
Stepan Moskovchenko4d055612012-03-08 12:22:22 -080066 "isb\n\t"
Stephen Boyd387ac2e2011-09-28 10:29:43 -070067 "mrc p15, 3, %[l2cpdr], c15, c0, 7\n\t"
68 : [l2cpdr]"=r" (val)
69 : [l2cpselr]"r" (reg_addr)
70 );
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071 raw_spin_unlock_irqrestore(&l2_access_lock, flags);
72
73 return val;
74}
Suren Eda Naarayana Kulothungan88d37fb2011-10-21 11:33:06 -040075EXPORT_SYMBOL(get_l2_indirect_reg);