Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011, The Linux Foundation. All rights reserved. |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 2 | |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <reg.h> |
| 30 | #include <platform/clock.h> |
| 31 | #include <platform/scm-io.h> |
Subbaraman Narayanamurthy | 346bdcb | 2011-02-24 12:02:58 -0800 | [diff] [blame] | 32 | #include <platform/iomap.h> |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 33 | |
Ajay Dudani | 012f8f1 | 2011-01-26 11:49:47 -0800 | [diff] [blame] | 34 | #pragma GCC optimize ("O0") |
| 35 | |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 36 | #define SCM_IO_READ ((((0x5 << 10) | 0x1) << 12) | (0x2 << 8) | 0x1) |
| 37 | #define SCM_IO_WRITE ((((0x5 << 10) | 0x2) << 12) | (0x2 << 8) | 0x2) |
| 38 | |
| 39 | #define BETWEEN(p, st, sz) ((p) >= (void *)(st) && \ |
| 40 | (p) < ((void *)(st) + (sz))) |
| 41 | |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 42 | extern void dmb(void); |
| 43 | |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 44 | uint32_t secure_readl(uint32_t c) |
| 45 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 46 | if ((BETWEEN((void *)c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE)) |
| 47 | || (BETWEEN((void *)c, MSM_TCSR_BASE, MSM_TCSR_SIZE))) { |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 48 | uint32_t context_id; |
| 49 | register uint32_t r0 __asm__("r0") = SCM_IO_READ; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 50 | register uint32_t r1 __asm__("r1") = (uint32_t) & context_id; |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 51 | register uint32_t r2 __asm__("r2") = c; |
| 52 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 53 | __asm__("smc #0 @ switch to secure world\n":"=r"(r0) |
| 54 | : "r"(r0), "r"(r1), "r"(r2) |
| 55 | ); |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 56 | dmb(); |
| 57 | return r0; |
| 58 | } |
| 59 | return readl(c); |
| 60 | } |
| 61 | |
| 62 | void secure_writel(uint32_t v, uint32_t c) |
| 63 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 64 | if ((BETWEEN((void *)c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE)) |
| 65 | || (BETWEEN((void *)c, MSM_TCSR_BASE, MSM_TCSR_SIZE))) { |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 66 | uint32_t context_id; |
| 67 | register uint32_t r0 __asm__("r0") = SCM_IO_WRITE; |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 68 | register uint32_t r1 __asm__("r1") = (uint32_t) & context_id; |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 69 | register uint32_t r2 __asm__("r2") = c; |
| 70 | register uint32_t r3 __asm__("r3") = v; |
| 71 | dmb(); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 72 | __asm__("smc #0 @ switch to secure world\n": /* No return value */ |
| 73 | :"r"(r0), "r"(r1), "r"(r2), "r"(r3) |
| 74 | ); |
Ajay Dudani | 8534b1a | 2011-01-26 11:35:39 -0800 | [diff] [blame] | 75 | } else |
| 76 | writel(v, c); |
| 77 | } |