blob: a21ec36990a75fcaee04df9852f8fd9551903667 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -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#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/io.h>
15
16#include <mach/msm_iomap.h>
Stephen Boyde2016602011-07-18 10:36:54 -070017#include <mach/scm.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018#include <mach/scm-io.h>
19
Stephen Boyde2016602011-07-18 10:36:54 -070020#define SCM_IO_READ 0x1
21#define SCM_IO_WRITE 0x2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022
23#define BETWEEN(p, st, sz) ((p) >= (void __iomem *)(st) && \
24 (p) < ((void __iomem *)(st) + (sz)))
25#define XLATE(p, pst, vst) ((u32)((p) - (vst)) + (pst))
26
27static u32 __secure_readl(u32 addr)
28{
Stephen Boyde2016602011-07-18 10:36:54 -070029 u32 r;
30 r = scm_call_atomic1(SCM_SVC_IO, SCM_IO_READ, addr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031 __iormb();
Stephen Boyde2016602011-07-18 10:36:54 -070032 return r;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033}
34
35u32 secure_readl(void __iomem *c)
36{
37 if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
38 return __secure_readl(XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
39 MSM_MMSS_CLK_CTL_BASE));
40 else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
41 return __secure_readl(XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
42 return readl(c);
43}
44EXPORT_SYMBOL(secure_readl);
45
46static void __secure_writel(u32 v, u32 addr)
47{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048 __iowmb();
Stephen Boyde2016602011-07-18 10:36:54 -070049 scm_call_atomic2(SCM_SVC_IO, SCM_IO_WRITE, addr, v);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050}
51
52void secure_writel(u32 v, void __iomem *c)
53{
54 if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
55 __secure_writel(v, XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
56 MSM_MMSS_CLK_CTL_BASE));
57 else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
58 __secure_writel(v, XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
59 else
60 writel(v, c);
61}
62EXPORT_SYMBOL(secure_writel);