2 * Copyright (c) 2013-2014 Ruslan Bukin <br@bsdpad.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/systm.h>
33 #include <sys/mutex.h>
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>
45 #include <arm/samsung/exynos/exynos5_mp.h>
47 #define EXYNOS_CHIPID 0x10000000
49 #define EXYNOS5250_SOC_ID 0x43520000
50 #define EXYNOS5420_SOC_ID 0xE5420000
51 #define EXYNOS5_SOC_ID_MASK 0xFFFFF000
53 #define EXYNOS_SYSRAM 0x02020000
54 #define EXYNOS5420_SYSRAM_NS (EXYNOS_SYSRAM + 0x53000 + 0x1c)
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
62 exynos_get_soc_id(void)
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);
73 return (reg & EXYNOS5_SOC_ID_MASK);
77 exynos5_mp_setmaxid(platform_t plat)
80 if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
85 mp_maxid = mp_ncpus - 1;
89 exynos5_mp_start_ap(platform_t plat)
91 bus_addr_t sysram, pmu;
96 err = bus_space_map(fdtbus_bs_tag, EXYNOS_PMU_BASE, 0x20000, 0, &pmu);
98 panic("Couldn't map pmu\n");
100 if (exynos_get_soc_id() == EXYNOS5420_SOC_ID)
101 reg = EXYNOS5420_SYSRAM_NS;
105 err = bus_space_map(fdtbus_bs_tag, reg, 0x100, 0, &sysram);
107 panic("Couldn't map sysram\n");
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),
114 for (j = 10; j >= 0; j--) {
115 status = bus_space_read_4(fdtbus_bs_tag, pmu,
117 if ((status & CORE_PWR_EN) == CORE_PWR_EN)
121 printf("Can't power on CPU%d\n", i);
125 bus_space_write_4(fdtbus_bs_tag, sysram, 0x0,
126 pmap_kextract((vm_offset_t)mpentry));
128 dcache_wbinv_poc_all();
132 bus_space_unmap(fdtbus_bs_tag, sysram, 0x100);
133 bus_space_unmap(fdtbus_bs_tag, pmu, 0x20000);