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