Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics. |
| 3 | * Kyungmin Park <kyungmin.park@samsung.com> |
| 4 | * Tomasz Figa <t.figa@samsung.com> |
| 5 | * |
| 6 | * This program is free software,you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <linux/of_address.h> |
| 16 | |
| 17 | #include <asm/firmware.h> |
| 18 | |
| 19 | #include <mach/map.h> |
| 20 | |
Sachin Kamat | b3205de | 2014-05-13 07:13:44 +0900 | [diff] [blame] | 21 | #include "common.h" |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 22 | #include "smc.h" |
| 23 | |
| 24 | static int exynos_do_idle(void) |
| 25 | { |
| 26 | exynos_smc(SMC_CMD_SLEEP, 0, 0, 0); |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static int exynos_cpu_boot(int cpu) |
| 31 | { |
Kyungmin Park | 989ff3f | 2014-05-09 06:19:18 +0900 | [diff] [blame] | 32 | /* |
Chanwoo Choi | 6457158 | 2014-05-26 04:12:32 +0900 | [diff] [blame] | 33 | * Exynos3250 doesn't need to send smc command for secondary CPU boot |
| 34 | * because Exynos3250 removes WFE in secure mode. |
| 35 | */ |
| 36 | if (soc_is_exynos3250()) |
| 37 | return 0; |
| 38 | |
| 39 | /* |
Kyungmin Park | 989ff3f | 2014-05-09 06:19:18 +0900 | [diff] [blame] | 40 | * The second parameter of SMC_CMD_CPU1BOOT command means CPU id. |
| 41 | * But, Exynos4212 has only one secondary CPU so second parameter |
| 42 | * isn't used for informing secure firmware about CPU id. |
| 43 | */ |
| 44 | if (soc_is_exynos4212()) |
| 45 | cpu = 0; |
| 46 | |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 47 | exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr) |
| 52 | { |
Sachin Kamat | b3205de | 2014-05-13 07:13:44 +0900 | [diff] [blame] | 53 | void __iomem *boot_reg; |
| 54 | |
| 55 | if (!sysram_ns_base_addr) |
| 56 | return -ENODEV; |
| 57 | |
Olof Johansson | fe388fa | 2014-05-30 21:44:32 -0700 | [diff] [blame] | 58 | boot_reg = sysram_ns_base_addr + 0x1c; |
Kyungmin Park | 989ff3f | 2014-05-09 06:19:18 +0900 | [diff] [blame] | 59 | |
Sachin Kamat | 35e7564 | 2014-07-08 08:03:49 +0900 | [diff] [blame^] | 60 | /* |
| 61 | * Almost all Exynos-series of SoCs that run in secure mode don't need |
| 62 | * additional offset for every CPU, with Exynos4412 being the only |
| 63 | * exception. |
| 64 | */ |
| 65 | if (soc_is_exynos4412()) |
| 66 | boot_reg += 4 * cpu; |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 67 | |
| 68 | __raw_writel(boot_addr, boot_reg); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static const struct firmware_ops exynos_firmware_ops = { |
| 73 | .do_idle = exynos_do_idle, |
| 74 | .set_cpu_boot_addr = exynos_set_cpu_boot_addr, |
| 75 | .cpu_boot = exynos_cpu_boot, |
| 76 | }; |
| 77 | |
| 78 | void __init exynos_firmware_init(void) |
| 79 | { |
Tomasz Figa | 4ee1cc7 | 2013-06-15 09:13:25 +0900 | [diff] [blame] | 80 | struct device_node *nd; |
| 81 | const __be32 *addr; |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 82 | |
Tomasz Figa | 4ee1cc7 | 2013-06-15 09:13:25 +0900 | [diff] [blame] | 83 | nd = of_find_compatible_node(NULL, NULL, |
| 84 | "samsung,secure-firmware"); |
| 85 | if (!nd) |
| 86 | return; |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 87 | |
Tomasz Figa | 4ee1cc7 | 2013-06-15 09:13:25 +0900 | [diff] [blame] | 88 | addr = of_get_address(nd, 0, NULL, NULL); |
| 89 | if (!addr) { |
| 90 | pr_err("%s: No address specified.\n", __func__); |
| 91 | return; |
Tomasz Figa | bca28f8 | 2012-12-11 13:58:43 +0900 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | pr_info("Running under secure firmware.\n"); |
| 95 | |
| 96 | register_firmware_ops(&exynos_firmware_ops); |
| 97 | } |