]> CyberLeo.Net >> Repos - FreeBSD/releng/10.3.git/blob - sys/arm/allwinner/a20/a20_mp.c
- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
[FreeBSD/releng/10.3.git] / sys / arm / allwinner / a20 / a20_mp.c
1 /*-
2  * Copyright (c) 2014 Ganbold Tsagaankhuu <ganbold@freebsd.org>
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 ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/kernel.h>
33 #include <sys/lock.h>
34 #include <sys/mutex.h>
35 #include <sys/smp.h>
36
37 #include <machine/smp.h>
38 #include <machine/fdt.h>
39 #include <machine/intr.h>
40
41 #define CPUCFG_BASE             0x01c25c00
42 #define CPUCFG_SIZE             0x400
43
44 #define CPU0_RST_CTL            0x40
45 #define CPU0_CTL                0x44
46 #define CPU0_STATUS             0x48
47 #define CPU1_RST_CTL            0x80
48 #define CPU1_CTL                0x84
49 #define CPU1_STATUS             0x88
50 #define CPUCFG_GENCTL           0x184
51 #define CPUCFG_P_REG0           0x1a4
52 #define CPU1_PWR_CLAMP          0x1b0
53 #define CPU1_PWROFF_REG         0x1b4
54 #define CPUCFG_DBGCTL0          0x1e0
55 #define CPUCFG_DBGCTL1          0x1e4
56
57 void
58 platform_mp_init_secondary(void)
59 {
60
61         gic_init_secondary();
62 }
63
64 void
65 platform_mp_setmaxid(void)
66 {
67         int ncpu;
68
69         if (mp_ncpus != 0)
70                 return;
71
72         /* Read the number of cores from the CP15 L2 Control Register. */
73         __asm __volatile("mrc p15, 1, %0, c9, c0, 2" : "=r" (ncpu));
74         ncpu = ((ncpu >> 24) & 0x3) + 1;
75
76         mp_ncpus = ncpu;
77         mp_maxid = ncpu - 1;
78 }
79
80 int
81 platform_mp_probe(void)
82 {
83
84         if (mp_ncpus == 0)
85                 platform_mp_setmaxid();
86
87         return (mp_ncpus > 1);
88 }
89
90 void
91 platform_mp_start_ap(void)
92 {
93         bus_space_handle_t cpucfg;
94
95         uint32_t val;
96
97         if (bus_space_map(fdtbus_bs_tag, CPUCFG_BASE, CPUCFG_SIZE, 0,
98             &cpucfg) != 0)
99                 panic("Couldn't map the CPUCFG\n");
100
101         cpu_idcache_wbinv_all();
102         cpu_l2cache_wbinv_all();
103
104         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPUCFG_P_REG0,
105             pmap_kextract((vm_offset_t)mpentry));
106
107         /*
108          * Assert nCOREPORESET low and set L1RSTDISABLE low.
109          * Ensure DBGPWRDUP is set to LOW to prevent any external
110          * debug access to the processor.
111          */
112         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_RST_CTL, 0);
113
114         /* Set L1RSTDISABLE low */
115         val = bus_space_read_4(fdtbus_bs_tag, cpucfg, CPUCFG_GENCTL);
116         val &= ~(1 << 1);
117         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPUCFG_GENCTL, val);
118
119         /* Set DBGPWRDUP low */
120         val = bus_space_read_4(fdtbus_bs_tag, cpucfg, CPUCFG_DBGCTL1);
121         val &= ~(1 << 1);
122         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPUCFG_DBGCTL1, val);
123
124         /* Release power clamp */
125         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0xff);
126         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x7f);
127         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x3f);
128         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x1f);
129         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x0f);
130         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x07);
131         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x03);
132         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x01);
133         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWR_CLAMP, 0x00);
134         DELAY(10000);
135
136         /* Clear power-off gating */
137         val = bus_space_read_4(fdtbus_bs_tag, cpucfg, CPU1_PWROFF_REG);
138         val &= ~(1 << 0);
139         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_PWROFF_REG, val);
140         DELAY(1000);
141
142         /* De-assert cpu core reset */
143         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPU1_RST_CTL, 3);
144
145         /* Assert DBGPWRDUP signal */
146         val = bus_space_read_4(fdtbus_bs_tag, cpucfg, CPUCFG_DBGCTL1);
147         val |= (1 << 1);
148         bus_space_write_4(fdtbus_bs_tag, cpucfg, CPUCFG_DBGCTL1, val);
149
150         armv7_sev();
151         bus_space_unmap(fdtbus_bs_tag, cpucfg, CPUCFG_SIZE);
152 }
153
154 void
155 platform_ipi_send(cpuset_t cpus, u_int ipi)
156 {
157
158         pic_ipi_send(cpus, ipi);
159 }