2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013-2014 Ruslan Bukin <br@bsdpad.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
35 #include <sys/mutex.h>
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>
47 #include <arm/samsung/exynos/exynos5_mp.h>
49 #define EXYNOS_CHIPID 0x10000000
51 #define EXYNOS5250_SOC_ID 0x43520000
52 #define EXYNOS5420_SOC_ID 0xE5420000
53 #define EXYNOS5_SOC_ID_MASK 0xFFFFF000
55 #define EXYNOS_SYSRAM 0x02020000
56 #define EXYNOS5420_SYSRAM_NS (EXYNOS_SYSRAM + 0x53000 + 0x1c)
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
64 exynos_get_soc_id(void)
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);
75 return (reg & EXYNOS5_SOC_ID_MASK);
79 exynos5_mp_setmaxid(platform_t plat)
82 if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
87 mp_maxid = mp_ncpus - 1;
91 exynos5_mp_start_ap(platform_t plat)
93 bus_addr_t sysram, pmu;
98 err = bus_space_map(fdtbus_bs_tag, EXYNOS_PMU_BASE, 0x20000, 0, &pmu);
100 panic("Couldn't map pmu\n");
102 if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
103 reg = EXYNOS5420_SYSRAM_NS;
107 err = bus_space_map(fdtbus_bs_tag, reg, 0x100, 0, &sysram);
109 panic("Couldn't map sysram\n");
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),
116 for (j = 10; j >= 0; j--) {
117 status = bus_space_read_4(fdtbus_bs_tag, pmu,
119 if ((status & CORE_PWR_EN) == CORE_PWR_EN)
123 printf("Can't power on CPU%d\n", i);
127 bus_space_write_4(fdtbus_bs_tag, sysram, 0x0,
128 pmap_kextract((vm_offset_t)mpentry));
130 dcache_wbinv_poc_all();
134 bus_space_unmap(fdtbus_bs_tag, sysram, 0x100);
135 bus_space_unmap(fdtbus_bs_tag, pmu, 0x20000);