| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bcm283x_platform.c,v 1.4 2018/04/01 04:35:03 ryo Exp $ */ | | 1 | /* $NetBSD: bcm283x_platform.c,v 1.5 2018/06/08 18:09:43 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * 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 | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.4 2018/04/01 04:35:03 ryo Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.5 2018/06/08 18:09:43 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include "opt_arm_debug.h" | | 32 | #include "opt_arm_debug.h" |
33 | #include "opt_bcm283x.h" | | 33 | #include "opt_bcm283x.h" |
34 | #include "opt_cpuoptions.h" | | 34 | #include "opt_cpuoptions.h" |
35 | #include "opt_ddb.h" | | 35 | #include "opt_ddb.h" |
36 | #include "opt_evbarm_boardtype.h" | | 36 | #include "opt_evbarm_boardtype.h" |
37 | #include "opt_kgdb.h" | | 37 | #include "opt_kgdb.h" |
38 | #include "opt_fdt.h" | | 38 | #include "opt_fdt.h" |
39 | #include "opt_rpi.h" | | 39 | #include "opt_rpi.h" |
40 | #include "opt_vcprop.h" | | 40 | #include "opt_vcprop.h" |
41 | | | 41 | |
42 | #include "sdhc.h" | | 42 | #include "sdhc.h" |
43 | #include "bcmsdhost.h" | | 43 | #include "bcmsdhost.h" |
| @@ -126,61 +126,92 @@ extern struct bus_space arm_generic_a4x_ | | | @@ -126,61 +126,92 @@ extern struct bus_space arm_generic_a4x_ |
126 | bs_protos(arm_generic); | | 126 | bs_protos(arm_generic); |
127 | bs_protos(arm_generic_a4x); | | 127 | bs_protos(arm_generic_a4x); |
128 | bs_protos(bcm2835); | | 128 | bs_protos(bcm2835); |
129 | bs_protos(bcm2835_a4x); | | 129 | bs_protos(bcm2835_a4x); |
130 | bs_protos(bcm2836); | | 130 | bs_protos(bcm2836); |
131 | bs_protos(bcm2836_a4x); | | 131 | bs_protos(bcm2836_a4x); |
132 | | | 132 | |
133 | struct bus_space bcm2835_bs_tag; | | 133 | struct bus_space bcm2835_bs_tag; |
134 | struct bus_space bcm2835_a4x_bs_tag; | | 134 | struct bus_space bcm2835_a4x_bs_tag; |
135 | struct bus_space bcm2836_bs_tag; | | 135 | struct bus_space bcm2836_bs_tag; |
136 | struct bus_space bcm2836_a4x_bs_tag; | | 136 | struct bus_space bcm2836_a4x_bs_tag; |
137 | | | 137 | |
138 | int bcm283x_bs_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *); | | 138 | int bcm283x_bs_map(void *, bus_addr_t, bus_size_t, int, bus_space_handle_t *); |
| | | 139 | paddr_t bcm283x_bs_mmap(void *, bus_addr_t, off_t, int, int); |
| | | 140 | paddr_t bcm283x_a4x_bs_mmap(void *, bus_addr_t, off_t, int, int); |
139 | | | 141 | |
140 | int | | 142 | int |
141 | bcm283x_bs_map(void *t, bus_addr_t ba, bus_size_t size, int flag, | | 143 | bcm283x_bs_map(void *t, bus_addr_t ba, bus_size_t size, int flag, |
142 | bus_space_handle_t *bshp) | | 144 | bus_space_handle_t *bshp) |
143 | { | | 145 | { |
144 | u_long startpa, endpa, pa; | | 146 | u_long startpa, endpa, pa; |
145 | vaddr_t va; | | 147 | vaddr_t va; |
146 | | | 148 | |
147 | /* Convert BA to PA */ | | 149 | /* Convert BA to PA */ |
148 | pa = ba & ~BCM2835_BUSADDR_CACHE_MASK; | | 150 | pa = ba & ~BCM2835_BUSADDR_CACHE_MASK; |
149 | | | 151 | |
150 | startpa = trunc_page(pa); | | 152 | startpa = trunc_page(pa); |
151 | endpa = round_page(pa + size); | | 153 | endpa = round_page(pa + size); |
152 | | | 154 | |
153 | /* XXX use extent manager to check duplicate mapping */ | | 155 | /* XXX use extent manager to check duplicate mapping */ |
154 | | | 156 | |
155 | va = uvm_km_alloc(kernel_map, endpa - startpa, 0, | | 157 | va = uvm_km_alloc(kernel_map, endpa - startpa, 0, |
156 | UVM_KMF_VAONLY | UVM_KMF_NOWAIT | UVM_KMF_COLORMATCH); | | 158 | UVM_KMF_VAONLY | UVM_KMF_NOWAIT | UVM_KMF_COLORMATCH); |
157 | if (!va) | | 159 | if (!va) |
158 | return ENOMEM; | | 160 | return ENOMEM; |
159 | | | 161 | |
160 | *bshp = (bus_space_handle_t)(va + (pa - startpa)); | | 162 | *bshp = (bus_space_handle_t)(va + (pa - startpa)); |
161 | | | 163 | |
162 | const int pmapflags = | | 164 | int pmapflags; |
163 | (flag & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE)) | | 165 | if (flag & BUS_SPACE_MAP_PREFETCHABLE) |
164 | ? 0 | | 166 | pmapflags = PMAP_WRITE_COMBINE; |
165 | : PMAP_NOCACHE; | | 167 | else if (flag & BUS_SPACE_MAP_CACHEABLE) |
| | | 168 | pmapflags = 0; |
| | | 169 | else |
| | | 170 | pmapflags = PMAP_NOCACHE; |
166 | for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { | | 171 | for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { |
167 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); | | 172 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); |
168 | } | | 173 | } |
169 | pmap_update(pmap_kernel()); | | 174 | pmap_update(pmap_kernel()); |
170 | | | 175 | |
171 | return 0; | | 176 | return 0; |
172 | } | | 177 | } |
173 | | | 178 | |
| | | 179 | paddr_t |
| | | 180 | bcm283x_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags) |
| | | 181 | { |
| | | 182 | /* Convert BA to PA */ |
| | | 183 | const paddr_t pa = bpa & ~BCM2835_BUSADDR_CACHE_MASK; |
| | | 184 | paddr_t bus_flags = 0; |
| | | 185 | |
| | | 186 | if (flags & BUS_SPACE_MAP_PREFETCHABLE) |
| | | 187 | bus_flags |= ARM_MMAP_WRITECOMBINE; |
| | | 188 | |
| | | 189 | return arm_btop(pa + offset) | bus_flags; |
| | | 190 | } |
| | | 191 | |
| | | 192 | paddr_t |
| | | 193 | bcm283x_a4x_bs_mmap(void *t, bus_addr_t bpa, off_t offset, int prot, int flags) |
| | | 194 | { |
| | | 195 | /* Convert BA to PA */ |
| | | 196 | const paddr_t pa = bpa & ~BCM2835_BUSADDR_CACHE_MASK; |
| | | 197 | paddr_t bus_flags = 0; |
| | | 198 | |
| | | 199 | if (flags & BUS_SPACE_MAP_PREFETCHABLE) |
| | | 200 | bus_flags |= ARM_MMAP_WRITECOMBINE; |
| | | 201 | |
| | | 202 | return arm_btop(pa + 4 * offset) | bus_flags; |
| | | 203 | } |
| | | 204 | |
174 | int | | 205 | int |
175 | bcm2835_bs_map(void *t, bus_addr_t ba, bus_size_t size, int flag, | | 206 | bcm2835_bs_map(void *t, bus_addr_t ba, bus_size_t size, int flag, |
176 | bus_space_handle_t *bshp) | | 207 | bus_space_handle_t *bshp) |
177 | { | | 208 | { |
178 | const struct pmap_devmap *pd; | | 209 | const struct pmap_devmap *pd; |
179 | bool match = false; | | 210 | bool match = false; |
180 | u_long pa; | | 211 | u_long pa; |
181 | | | 212 | |
182 | /* Attempt to find the PA device mapping */ | | 213 | /* Attempt to find the PA device mapping */ |
183 | if (ba >= BCM2835_PERIPHERALS_BASE_BUS && | | 214 | if (ba >= BCM2835_PERIPHERALS_BASE_BUS && |
184 | ba < BCM2835_PERIPHERALS_BASE_BUS + BCM2835_PERIPHERALS_SIZE) { | | 215 | ba < BCM2835_PERIPHERALS_BASE_BUS + BCM2835_PERIPHERALS_SIZE) { |
185 | match = true; | | 216 | match = true; |
186 | pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(ba); | | 217 | pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(ba); |
| @@ -1153,46 +1184,50 @@ SYSCTL_SETUP(sysctl_machdep_rpi, "sysctl | | | @@ -1153,46 +1184,50 @@ SYSCTL_SETUP(sysctl_machdep_rpi, "sysctl |
1153 | CTLTYPE_QUAD, "serial", NULL, NULL, 0, | | 1184 | CTLTYPE_QUAD, "serial", NULL, NULL, 0, |
1154 | &vb.vbt_serial.sn, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL); | | 1185 | &vb.vbt_serial.sn, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL); |
1155 | } | | 1186 | } |
1156 | | | 1187 | |
1157 | #if defined(SOC_BCM2835) | | 1188 | #if defined(SOC_BCM2835) |
1158 | static void | | 1189 | static void |
1159 | bcm2835_platform_bootstrap(void) | | 1190 | bcm2835_platform_bootstrap(void) |
1160 | { | | 1191 | { |
1161 | | | 1192 | |
1162 | bcm2835_bs_tag = arm_generic_bs_tag; | | 1193 | bcm2835_bs_tag = arm_generic_bs_tag; |
1163 | bcm2835_a4x_bs_tag = arm_generic_a4x_bs_tag; | | 1194 | bcm2835_a4x_bs_tag = arm_generic_a4x_bs_tag; |
1164 | | | 1195 | |
1165 | bcm2835_bs_tag.bs_map = bcm2835_bs_map; | | 1196 | bcm2835_bs_tag.bs_map = bcm2835_bs_map; |
| | | 1197 | bcm2835_bs_tag.bs_mmap = bcm283x_bs_mmap; |
1166 | bcm2835_a4x_bs_tag.bs_map = bcm2835_bs_map; | | 1198 | bcm2835_a4x_bs_tag.bs_map = bcm2835_bs_map; |
| | | 1199 | bcm2835_a4x_bs_tag.bs_mmap = bcm283x_a4x_bs_mmap; |
1167 | | | 1200 | |
1168 | fdtbus_set_decoderegprop(false); | | 1201 | fdtbus_set_decoderegprop(false); |
1169 | | | 1202 | |
1170 | bcm2835_uartinit(); | | 1203 | bcm2835_uartinit(); |
1171 | | | 1204 | |
1172 | bcm2835_bootparams(); | | 1205 | bcm2835_bootparams(); |
1173 | } | | 1206 | } |
1174 | #endif | | 1207 | #endif |
1175 | | | 1208 | |
1176 | #if defined(SOC_BCM2836) | | 1209 | #if defined(SOC_BCM2836) |
1177 | static void | | 1210 | static void |
1178 | bcm2836_platform_bootstrap(void) | | 1211 | bcm2836_platform_bootstrap(void) |
1179 | { | | 1212 | { |
1180 | | | 1213 | |
1181 | bcm2836_bs_tag = arm_generic_bs_tag; | | 1214 | bcm2836_bs_tag = arm_generic_bs_tag; |
1182 | bcm2836_a4x_bs_tag = arm_generic_a4x_bs_tag; | | 1215 | bcm2836_a4x_bs_tag = arm_generic_a4x_bs_tag; |
1183 | | | 1216 | |
1184 | bcm2836_bs_tag.bs_map = bcm2836_bs_map; | | 1217 | bcm2836_bs_tag.bs_map = bcm2836_bs_map; |
| | | 1218 | bcm2836_bs_tag.bs_mmap = bcm283x_bs_mmap; |
1185 | bcm2836_a4x_bs_tag.bs_map = bcm2836_bs_map; | | 1219 | bcm2836_a4x_bs_tag.bs_map = bcm2836_bs_map; |
| | | 1220 | bcm2836_a4x_bs_tag.bs_mmap = bcm283x_a4x_bs_mmap; |
1186 | | | 1221 | |
1187 | fdtbus_set_decoderegprop(false); | | 1222 | fdtbus_set_decoderegprop(false); |
1188 | | | 1223 | |
1189 | bcm2836_uartinit(); | | 1224 | bcm2836_uartinit(); |
1190 | | | 1225 | |
1191 | bcm2836_bootparams(); | | 1226 | bcm2836_bootparams(); |
1192 | | | 1227 | |
1193 | bcm2836_bootstrap(); | | 1228 | bcm2836_bootstrap(); |
1194 | } | | 1229 | } |
1195 | #endif | | 1230 | #endif |
1196 | | | 1231 | |
1197 | #if defined(SOC_BCM2835) | | 1232 | #if defined(SOC_BCM2835) |
1198 | static void | | 1233 | static void |