Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 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 Boyd | e201660 | 2011-07-18 10:36:54 -0700 | [diff] [blame^] | 17 | #include <mach/scm.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <mach/scm-io.h> |
| 19 | |
Stephen Boyd | e201660 | 2011-07-18 10:36:54 -0700 | [diff] [blame^] | 20 | #define SCM_IO_READ 0x1 |
| 21 | #define SCM_IO_WRITE 0x2 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | |
| 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 | |
| 27 | static u32 __secure_readl(u32 addr) |
| 28 | { |
Stephen Boyd | e201660 | 2011-07-18 10:36:54 -0700 | [diff] [blame^] | 29 | u32 r; |
| 30 | r = scm_call_atomic1(SCM_SVC_IO, SCM_IO_READ, addr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | __iormb(); |
Stephen Boyd | e201660 | 2011-07-18 10:36:54 -0700 | [diff] [blame^] | 32 | return r; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | u32 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 | } |
| 44 | EXPORT_SYMBOL(secure_readl); |
| 45 | |
| 46 | static void __secure_writel(u32 v, u32 addr) |
| 47 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | __iowmb(); |
Stephen Boyd | e201660 | 2011-07-18 10:36:54 -0700 | [diff] [blame^] | 49 | scm_call_atomic2(SCM_SVC_IO, SCM_IO_WRITE, addr, v); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void 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 | } |
| 62 | EXPORT_SYMBOL(secure_writel); |