aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-msm/scm-io.c
blob: a21ec36990a75fcaee04df9852f8fd9551903667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/io.h>

#include <mach/msm_iomap.h>
#include <mach/scm.h>
#include <mach/scm-io.h>

#define SCM_IO_READ	0x1
#define SCM_IO_WRITE	0x2

#define BETWEEN(p, st, sz) ((p) >= (void __iomem *)(st) && \
				(p) < ((void __iomem *)(st) + (sz)))
#define XLATE(p, pst, vst) ((u32)((p) - (vst)) + (pst))

static u32 __secure_readl(u32 addr)
{
	u32 r;
	r = scm_call_atomic1(SCM_SVC_IO, SCM_IO_READ, addr);
	__iormb();
	return r;
}

u32 secure_readl(void __iomem *c)
{
	if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
		return __secure_readl(XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
					MSM_MMSS_CLK_CTL_BASE));
	else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
		return __secure_readl(XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
	return readl(c);
}
EXPORT_SYMBOL(secure_readl);

static void __secure_writel(u32 v, u32 addr)
{
	__iowmb();
	scm_call_atomic2(SCM_SVC_IO, SCM_IO_WRITE, addr, v);
}

void secure_writel(u32 v, void __iomem *c)
{
	if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
		__secure_writel(v, XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
					MSM_MMSS_CLK_CTL_BASE));
	else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
		__secure_writel(v, XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
	else
		writel(v, c);
}
EXPORT_SYMBOL(secure_writel);