1 /* $Id: omap2_l3i.c,v 1.5 2008/11/21 17:13:07 matt Exp $ */
4 /* $NetBSD: omap2_l3i.c,v 1.4 2008/08/27 11:03:10 matt Exp $ */
8 * Autoconfiguration support for the Texas Instruments OMAP "On Board" I/O.
10 * Based on arm/omap/omap_emifs.c which in turn was derived
11 * Based on arm/xscale/pxa2x0.c which in turn was derived
12 * from arm/sa11x0/sa11x0.c
14 * Copyright (c) 2002, 2005 Genetec Corporation. All rights reserved.
15 * Written by Hiroyuki Bessho for Genetec Corporation.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. All advertising materials mentioning features or use of this software
26 * must display the following acknowledgement:
27 * This product includes software developed for the NetBSD Project by
28 * Genetec Corporation.
29 * 4. The name of Genetec Corporation may not be used to endorse or
30 * promote products derived from this software without specific prior
33 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
37 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
45 * Copyright (c) 1997, 1998, 2001, The NetBSD Foundation, Inc.
46 * All rights reserved.
48 * This code is derived from software contributed to The NetBSD Foundation
49 * by IWAMOTO Toshihiro, Ichiro FUKUHARA and Paul Kranenburg.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions
54 * 1. Redistributions of source code must retain the above copyright
55 * notice, this list of conditions and the following disclaimer.
56 * 2. Redistributions in binary form must reproduce the above copyright
57 * notice, this list of conditions and the following disclaimer in the
58 * documentation and/or other materials provided with the distribution.
60 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
61 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
62 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
64 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
65 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
66 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
67 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
68 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
70 * POSSIBILITY OF SUCH DAMAGE.
73 * Shin Takemura and PocketBSD Project. All rights reserved.
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by the PocketBSD project
86 * and its contributors.
87 * 4. Neither the name of the project nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
91 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
92 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 #include "opt_omap.h"
105 #include <sys/cdefs.h>
106 __KERNEL_RCSID(0, "$NetBSD: omap2_l3i.c,v 1.4 2008/08/27 11:03:10 matt Exp $");
108 #include "locators.h"
110 #include <sys/param.h>
111 #include <sys/systm.h>
112 #include <sys/device.h>
113 #include <sys/kernel.h>
114 #include <sys/reboot.h>
116 #include <machine/cpu.h>
117 #include <machine/bus.h>
119 #include <arm/cpufunc.h>
120 #include <arm/mainbus/mainbus.h>
121 #include <arm/omap/omap_var.h>
123 #if defined(OMAP2) || defined(OMAP3)
124 #include <arm/omap/omap2_reg.h>
126 #include <arm/omap/omap2_var.h>
130 * we have only used this with OMAP 2430 so far....
131 * some of the 2430 stuff may generalize to other OMAP implementations,
132 * or not. Either generalize the include files accordingly, or
133 * add your own implementation-specific includes.
135 # error unknown OMAP L3 Interconnect implementation
140 bus_dma_tag_t sc_dmac
;
141 bus_space_tag_t sc_iot
;
142 bus_space_handle_t sc_ioh
;
147 static int L3i_match(device_t
, cfdata_t
, void *);
148 static void L3i_attach(device_t
, device_t
, void *);
149 void L3i_target_agent_check(struct L3i_softc
*, bus_addr_t
, char *);
150 static void L3i_decode_ta_COMPONENT(uint32_t);
151 static void L3i_decode_ta_CORE(uint32_t);
152 static void L3i_decode_ta_AGENT_CONTROL(uint32_t);
153 static void L3i_decode_ta_AGENT_STATUS(uint32_t);
154 static void L3i_decode_ta_ERROR_LOG(uint32_t);
155 static void L3i_decode_ta_ERROR_LOG_ADDR(uint32_t);
157 static int L3i_search(device_t
, cfdata_t
,
158 const int *, void *);
159 static int L3i_print(void *, const char *);
162 #define TARGET_AGENT_REGS_ENTRY(reg) \
163 { .offset = OMAP2_TA_ ## reg, \
164 .decode = L3i_decode_ta_ ## reg, \
168 void (*decode
)(uint32_t);
170 } target_agent_regs
[] = {
171 TARGET_AGENT_REGS_ENTRY(COMPONENT
),
172 TARGET_AGENT_REGS_ENTRY(CORE
),
173 TARGET_AGENT_REGS_ENTRY(AGENT_CONTROL
),
174 TARGET_AGENT_REGS_ENTRY(AGENT_STATUS
),
175 TARGET_AGENT_REGS_ENTRY(ERROR_LOG
),
176 TARGET_AGENT_REGS_ENTRY(ERROR_LOG_ADDR
),
178 #define TARGET_AGENT_REGS_NENTRIES \
179 (sizeof(target_agent_regs) / sizeof(target_agent_regs[0]))
182 /* attach structures */
183 CFATTACH_DECL_NEW(L3i
, sizeof(struct L3i_softc
),
184 L3i_match
, L3i_attach
, NULL
, NULL
);
186 static int L3i_attached
; /* XXX assumes only 1 instance */
189 L3i_match(device_t parent
, cfdata_t match
, void *aux
)
191 if (L3i_attached
!= 0)
198 L3i_attach(device_t parent
, device_t self
, void *aux
)
200 struct L3i_softc
*sc
= device_private(self
);
203 sc
->sc_iot
= &omap_bs_tag
;
205 aprint_normal(": L3i Interconnect\n");
209 sc
->sc_dmac
= &omap_bus_dma_tag
;
215 L3i_target_agent_check(sc
, (bus_addr_t
)OMAP2_TA_L4_CORE
, "L4 core");
216 L3i_target_agent_check(sc
, (bus_addr_t
)OMAP2_TA_GPMC
, "GPMC");
221 * Attach all our devices
223 config_search_ia(L3i_search
, self
, "L3i", NULL
);
228 L3i_decode_ta_COMPONENT(uint32_t val
)
230 aprint_normal("\tCODE %#" PRIxMAX
"\n", TA_COMPONENT_CODE(val
));
231 aprint_normal("\tREV %#" PRIxMAX
"\n", TA_COMPONENT_REV(val
));
235 L3i_decode_ta_CORE(uint32_t val
)
237 aprint_normal("\tCODE %#" PRIxMAX
"\n", TA_AGENT_CORE_CODE(val
));
238 aprint_normal("\tREV %#" PRIxMAX
"\n", TA_AGENT_CORE_REV(val
));
242 L3i_decode_ta_AGENT_CONTROL(uint32_t val
)
244 const uint core_timeout_base_tab
[8] = {
245 0, 1, 2, 3, 4, -1, -1, -1
247 uint core_timeout_ix
;
249 core_timeout_ix
= (val
& TA_AGENT_CONTROL_CORE_TIMEOUT_BASE
)
250 >> TA_AGENT_CONTROL_CORE_TIMEOUT_BASE_SHFT
;
252 aprint_normal("\tCORE_REQ_TIMEOUT_REP %d\n",
253 ((val
& TA_AGENT_CONTROL_CORE_REQ_TIMEOUT_REP
) != 0));
254 aprint_normal("\tCORE_SERROR_REP %d\n",
255 ((val
& TA_AGENT_CONTROL_CORE_SERROR_REP
) != 0));
256 aprint_normal("\tCORE_TIMEOUT_BASE %d\n",
257 core_timeout_base_tab
[core_timeout_ix
]);
258 aprint_normal("\tCORE_REJECT %d\n",
259 ((val
& TA_AGENT_CONTROL_CORE_REJECT
) != 0));
260 aprint_normal("\tCORE_RESET %d\n",
261 ((val
& TA_AGENT_CONTROL_CORE_RESET
) != 0));
265 L3i_decode_ta_AGENT_STATUS(uint32_t val
)
267 aprint_normal("\tSERROR %d\n",
268 ((val
& TA_AGENT_STATUS_SERROR
) != 0));
269 aprint_normal("\tBURST_CLOSE %d\n",
270 ((val
& TA_AGENT_STATUS_BURST_CLOSE
) != 0));
271 aprint_normal("\tTA_AGENT_STATUS_TIMEBASE %" PRIdMAX
"\n",
272 ((val
& TA_AGENT_STATUS_TIMEBASE
) >> 12));
273 aprint_normal("\tREQ_TIMEOUT %d\n",
274 ((val
& TA_AGENT_STATUS_REQ_TIMEOUT
) != 0));
275 aprint_normal("\tREADEX %d\n",
276 ((val
& TA_AGENT_STATUS_READEX
) != 0));
277 aprint_normal("\tBURST %d\n",
278 ((val
& TA_AGENT_STATUS_BURST
) != 0));
279 aprint_normal("\tRESP_ACTIVE %d\n",
280 ((val
& TA_AGENT_STATUS_RESP_ACTIVE
) != 0));
281 aprint_normal("\tREQ_WAITING %d\n",
282 ((val
& TA_AGENT_STATUS_REQ_WAITING
) != 0));
283 aprint_normal("\tCORE_RESET %d\n",
284 ((val
& TA_AGENT_STATUS_CORE_RESET
) != 0));
288 L3i_decode_ta_ERROR_LOG(uint32_t val
)
290 aprint_normal("\tCMD %" PRIdMAX
"\n",
291 (val
& TA_ERROR_LOG_CMD
));
292 aprint_normal("\tINITID %" PRIdMAX
"\n",
293 (val
& TA_ERROR_LOG_INITID
) >> 8);
294 aprint_normal("\tCODE %" PRIdMAX
"\n",
295 (val
& TA_ERROR_LOG_CODE
) >> 24);
296 aprint_normal("\tMULTI %d\n",
297 ((val
& TA_ERROR_LOG_MULTI
) != 0));
301 L3i_decode_ta_ERROR_LOG_ADDR(uint32_t val
)
307 L3i_target_agent_check(struct L3i_softc
*sc
, bus_addr_t ba
, char *agent
)
309 bus_space_tag_t iot
= sc
->sc_iot
;
310 bus_space_handle_t ioh
;
315 err
= bus_space_map(sc
->sc_iot
, ba
, 1024, 0, &ioh
);
317 aprint_error("%s: cannot map L3 Target Agent %s at %#lx\n",
318 device_xname(sc
->sc_dev
), agent
, ba
);
322 for (i
=0; i
< TARGET_AGENT_REGS_NENTRIES
; i
++) {
323 r
= bus_space_read_4(iot
, ioh
, target_agent_regs
[i
].offset
);
324 aprint_normal("%s: Agent %s Reg %s: %#x\n",
325 device_xname(sc
->sc_dev
),
326 agent
, target_agent_regs
[i
].name
, r
);
327 target_agent_regs
[i
].decode(r
);
331 bus_space_unmap(sc
->sc_iot
, ioh
, 1024);
338 L3i_search(device_t parent
, cfdata_t cf
,
339 const int *ldesc
, void *aux
)
341 struct L3i_softc
*sc
= device_private(parent
);
342 struct L3i_attach_args aa
;
344 /* Set up the attach args. */
345 if (cf
->cf_loc
[L3iCF_NOBYTEACC
] == 1) {
346 if (cf
->cf_loc
[L3iCF_MULT
] == 1)
347 aa
.L3i_iot
= &nobyteacc_bs_tag
;
349 panic("nobyteacc specified for device with "
350 "non-byte multiplier\n");
352 switch (cf
->cf_loc
[L3iCF_MULT
]) {
354 aa
.L3i_iot
= &omap_bs_tag
;
357 aa
.L3i_iot
= &omap_a2x_bs_tag
;
360 aa
.L3i_iot
= &omap_a4x_bs_tag
;
363 panic("Unsupported EMIFS multiplier.");
368 aa
.L3i_dmac
= sc
->sc_dmac
;
369 aa
.L3i_addr
= cf
->cf_loc
[L3iCF_ADDR
];
370 aa
.L3i_size
= cf
->cf_loc
[L3iCF_SIZE
];
371 aa
.L3i_intr
= cf
->cf_loc
[L3iCF_INTR
];
374 if ((aa
.L3i_addr
>= OMAP2_L3i_BASE
)
375 && (aa
.L3i_addr
< (OMAP2_L4_CORE_BASE
+ OMAP2_L3i_SIZE
))) {
377 * if size was specified, then check it too
378 * otherwise just assume it is OK
380 if ((aa
.L3i_size
!= L3iCF_SIZE_DEFAULT
)
381 && ((aa
.L3i_addr
+ aa
.L3i_size
)
382 >= (OMAP2_L4_CORE_BASE
+ OMAP2_L3i_SIZE
)))
384 if (config_match(parent
, cf
, &aa
)) {
385 config_attach(parent
, cf
, &aa
, L3i_print
);
386 return 0; /* love it */
395 L3i_print(void *aux
, const char *name
)
397 struct L3i_attach_args
*sa
= (struct L3i_attach_args
*)aux
;
399 if (sa
->L3i_addr
!= L3iCF_ADDR_DEFAULT
) {
400 aprint_normal(" addr 0x%08lx", sa
->L3i_addr
);
401 if (sa
->L3i_size
!= L3iCF_SIZE_DEFAULT
)
402 aprint_normal("-0x%08lx",
403 sa
->L3i_addr
+ sa
->L3i_size
-1);
405 if (sa
->L3i_intr
!= L3iCF_INTR_DEFAULT
)
406 aprint_normal(" intr %d", sa
->L3i_intr
);