]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/samsung/exynos/exynos5_mp.c
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305575, and update
[FreeBSD/FreeBSD.git] / sys / arm / samsung / exynos / exynos5_mp.c
1 /*-
2  * Copyright (c) 2013-2014 Ruslan Bukin <br@bsdpad.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/lock.h>
33 #include <sys/mutex.h>
34 #include <sys/smp.h>
35
36 #include <vm/vm.h>
37 #include <vm/pmap.h>
38
39 #include <machine/cpu.h>
40 #include <machine/smp.h>
41 #include <machine/fdt.h>
42 #include <machine/intr.h>
43 #include <machine/platformvar.h>
44
45 #include <arm/samsung/exynos/exynos5_mp.h>
46
47 #define EXYNOS_CHIPID           0x10000000
48
49 #define EXYNOS5250_SOC_ID       0x43520000
50 #define EXYNOS5420_SOC_ID       0xE5420000
51 #define EXYNOS5_SOC_ID_MASK     0xFFFFF000
52
53 #define EXYNOS_SYSRAM           0x02020000
54 #define EXYNOS5420_SYSRAM_NS    (EXYNOS_SYSRAM + 0x53000 + 0x1c)
55
56 #define EXYNOS_PMU_BASE         0x10040000
57 #define CORE_CONFIG(n)          (0x2000 + (0x80 * (n)))
58 #define CORE_STATUS(n)          (CORE_CONFIG(n) + 0x4)
59 #define CORE_PWR_EN             0x3
60
61 static int
62 exynos_get_soc_id(void)
63 {
64         bus_addr_t chipid;
65         int reg;
66
67         if (bus_space_map(fdtbus_bs_tag, EXYNOS_CHIPID,
68                 0x1000, 0, &chipid) != 0)
69                 panic("Couldn't map chipid\n");
70         reg = bus_space_read_4(fdtbus_bs_tag, chipid, 0x0);
71         bus_space_unmap(fdtbus_bs_tag, chipid, 0x1000);
72
73         return (reg & EXYNOS5_SOC_ID_MASK);
74 }
75
76 void
77 exynos5_mp_setmaxid(platform_t plat)
78 {
79
80         if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
81                 mp_ncpus = 4;
82         else
83                 mp_ncpus = 2;
84
85         mp_maxid = mp_ncpus - 1;
86 }
87
88 void
89 exynos5_mp_start_ap(platform_t plat)
90 {
91         bus_addr_t sysram, pmu;
92         int err, i, j;
93         int status;
94         int reg;
95
96         err = bus_space_map(fdtbus_bs_tag, EXYNOS_PMU_BASE, 0x20000, 0, &pmu);
97         if (err != 0)
98                 panic("Couldn't map pmu\n");
99
100         if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
101                 reg = EXYNOS5420_SYSRAM_NS;
102         else
103                 reg = EXYNOS_SYSRAM;
104
105         err = bus_space_map(fdtbus_bs_tag, reg, 0x100, 0, &sysram);
106         if (err != 0)
107                 panic("Couldn't map sysram\n");
108
109         /* Give power to CPUs */
110         for (i = 1; i < mp_ncpus; i++) {
111                 bus_space_write_4(fdtbus_bs_tag, pmu, CORE_CONFIG(i),
112                     CORE_PWR_EN);
113
114                 for (j = 10; j >= 0; j--) {
115                         status = bus_space_read_4(fdtbus_bs_tag, pmu,
116                             CORE_STATUS(i));
117                         if ((status & CORE_PWR_EN) == CORE_PWR_EN)
118                                 break;
119                         DELAY(10);
120                         if (j == 0)
121                                 printf("Can't power on CPU%d\n", i);
122                 }
123         }
124
125         bus_space_write_4(fdtbus_bs_tag, sysram, 0x0,
126             pmap_kextract((vm_offset_t)mpentry));
127
128         dcache_wbinv_poc_all();
129
130         dsb();
131         sev();
132         bus_space_unmap(fdtbus_bs_tag, sysram, 0x100);
133         bus_space_unmap(fdtbus_bs_tag, pmu, 0x20000);
134 }