Stefan Bosch | 95e9a8e | 2020-07-10 19:07:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2016 Nexell |
| 4 | * Youngbok, Park <park@nexell.co.kr> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/types.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/nexell.h> |
| 10 | #include <asm/arch/sec_reg.h> |
| 11 | #include <linux/linkage.h> |
| 12 | |
| 13 | #define NEXELL_SMC_BASE 0x82000000 |
| 14 | |
| 15 | #define NEXELL_SMC_FN(n) (NEXELL_SMC_BASE + (n)) |
| 16 | |
| 17 | #define NEXELL_SMC_SEC_REG_WRITE NEXELL_SMC_FN(0x0) |
| 18 | #define NEXELL_SMC_SEC_REG_READ NEXELL_SMC_FN(0x1) |
| 19 | |
| 20 | #define SECURE_ID_SHIFT 8 |
| 21 | |
| 22 | #define SEC_4K_OFFSET ((4 * 1024) - 1) |
| 23 | #define SEC_64K_OFFSET ((64 * 1024) - 1) |
| 24 | |
| 25 | asmlinkage int __invoke_nexell_fn_smc(u32, u32, u32, u32); |
| 26 | |
| 27 | int write_sec_reg_by_id(void __iomem *reg, int val, int id) |
| 28 | { |
| 29 | int ret = 0; |
| 30 | u32 off = 0; |
| 31 | |
| 32 | switch (id) { |
| 33 | case NEXELL_L2C_SEC_ID: |
| 34 | case NEXELL_MIPI_SEC_ID: |
| 35 | case NEXELL_TOFF_SEC_ID: |
| 36 | off = (u32)reg & SEC_4K_OFFSET; |
| 37 | break; |
| 38 | case NEXELL_MALI_SEC_ID: |
| 39 | off = (u32)reg & SEC_64K_OFFSET; |
| 40 | break; |
| 41 | } |
| 42 | ret = __invoke_nexell_fn_smc(NEXELL_SMC_SEC_REG_WRITE | |
| 43 | ((1 << SECURE_ID_SHIFT) + id), off, val, 0); |
| 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | int read_sec_reg_by_id(void __iomem *reg, int id) |
| 48 | { |
| 49 | int ret = 0; |
| 50 | u32 off = 0; |
| 51 | |
| 52 | switch (id) { |
| 53 | case NEXELL_L2C_SEC_ID: |
| 54 | case NEXELL_MIPI_SEC_ID: |
| 55 | case NEXELL_TOFF_SEC_ID: |
| 56 | off = (u32)reg & SEC_4K_OFFSET; |
| 57 | break; |
| 58 | case NEXELL_MALI_SEC_ID: |
| 59 | off = (u32)reg & SEC_64K_OFFSET; |
| 60 | break; |
| 61 | } |
| 62 | ret = __invoke_nexell_fn_smc(NEXELL_SMC_SEC_REG_READ | |
| 63 | ((1 << SECURE_ID_SHIFT) + id), off, 0, 0); |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | int write_sec_reg(void __iomem *reg, int val) |
| 68 | { |
| 69 | int ret = 0; |
| 70 | |
| 71 | ret = __invoke_nexell_fn_smc(NEXELL_SMC_SEC_REG_WRITE, |
| 72 | (u32)reg, val, 0); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | int read_sec_reg(void __iomem *reg) |
| 77 | { |
| 78 | int ret = 0; |
| 79 | |
| 80 | ret = __invoke_nexell_fn_smc(NEXELL_SMC_SEC_REG_READ, (u32)reg, 0, 0); |
| 81 | return ret; |
| 82 | } |