rmixl_pcie.c revision 1.1.2.20 1 1.1.2.20 matt /* $NetBSD: rmixl_pcie.c,v 1.1.2.20 2011/12/31 08:20:43 matt Exp $ */
2 1.1.2.1 cliff
3 1.1.2.1 cliff /*
4 1.1.2.1 cliff * Copyright (c) 2001 Wasabi Systems, Inc.
5 1.1.2.1 cliff * All rights reserved.
6 1.1.2.1 cliff *
7 1.1.2.1 cliff * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.2.1 cliff *
9 1.1.2.1 cliff * Redistribution and use in source and binary forms, with or without
10 1.1.2.1 cliff * modification, are permitted provided that the following conditions
11 1.1.2.1 cliff * are met:
12 1.1.2.1 cliff * 1. Redistributions of source code must retain the above copyright
13 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer.
14 1.1.2.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer in the
16 1.1.2.1 cliff * documentation and/or other materials provided with the distribution.
17 1.1.2.1 cliff * 3. All advertising materials mentioning features or use of this software
18 1.1.2.1 cliff * must display the following acknowledgement:
19 1.1.2.1 cliff * This product includes software developed for the NetBSD Project by
20 1.1.2.1 cliff * Wasabi Systems, Inc.
21 1.1.2.1 cliff * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.1 cliff * or promote products derived from this software without specific prior
23 1.1.2.1 cliff * written permission.
24 1.1.2.1 cliff *
25 1.1.2.1 cliff * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.1 cliff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.1 cliff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.1 cliff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.1 cliff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.1 cliff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.1 cliff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.1 cliff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.1 cliff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.1 cliff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.1 cliff * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.1 cliff */
37 1.1.2.1 cliff
38 1.1.2.1 cliff /*
39 1.1.2.1 cliff * PCI configuration support for RMI XLS SoC
40 1.1.2.1 cliff */
41 1.1.2.1 cliff
42 1.1.2.1 cliff #include <sys/cdefs.h>
43 1.1.2.20 matt __KERNEL_RCSID(0, "$NetBSD: rmixl_pcie.c,v 1.1.2.20 2011/12/31 08:20:43 matt Exp $");
44 1.1.2.1 cliff
45 1.1.2.1 cliff #include "opt_pci.h"
46 1.1.2.1 cliff #include "pci.h"
47 1.1.2.1 cliff
48 1.1.2.1 cliff #include <sys/cdefs.h>
49 1.1.2.1 cliff
50 1.1.2.1 cliff #include <sys/param.h>
51 1.1.2.1 cliff #include <sys/systm.h>
52 1.1.2.1 cliff #include <sys/device.h>
53 1.1.2.1 cliff #include <sys/extent.h>
54 1.1.2.1 cliff #include <sys/malloc.h>
55 1.1.2.16 cliff #include <sys/kernel.h> /* for 'hz' */
56 1.1.2.16 cliff #include <sys/cpu.h>
57 1.1.2.1 cliff
58 1.1.2.1 cliff #include <uvm/uvm_extern.h>
59 1.1.2.1 cliff
60 1.1.2.1 cliff #include <machine/bus.h>
61 1.1.2.1 cliff #include <machine/intr.h>
62 1.1.2.1 cliff
63 1.1.2.1 cliff #include <mips/rmi/rmixlreg.h>
64 1.1.2.1 cliff #include <mips/rmi/rmixlvar.h>
65 1.1.2.9 cliff #include <mips/rmi/rmixl_intr.h>
66 1.1.2.1 cliff #include <mips/rmi/rmixl_pcievar.h>
67 1.1.2.1 cliff
68 1.1.2.1 cliff #include <mips/rmi/rmixl_obiovar.h>
69 1.1.2.1 cliff
70 1.1.2.1 cliff #include <dev/pci/pcivar.h>
71 1.1.2.1 cliff #include <dev/pci/pcidevs.h>
72 1.1.2.1 cliff #include <dev/pci/pciconf.h>
73 1.1.2.1 cliff
74 1.1.2.1 cliff #ifdef PCI_NETBSD_CONFIGURE
75 1.1.2.1 cliff #include <mips/cache.h>
76 1.1.2.1 cliff #endif
77 1.1.2.1 cliff
78 1.1.2.1 cliff #include <machine/pci_machdep.h>
79 1.1.2.1 cliff
80 1.1.2.1 cliff #ifdef PCI_DEBUG
81 1.1.2.1 cliff int rmixl_pcie_debug = PCI_DEBUG;
82 1.1.2.1 cliff # define DPRINTF(x) do { if (rmixl_pcie_debug) printf x ; } while (0)
83 1.1.2.1 cliff #else
84 1.1.2.1 cliff # define DPRINTF(x)
85 1.1.2.1 cliff #endif
86 1.1.2.1 cliff
87 1.1.2.1 cliff #ifndef DDB
88 1.1.2.1 cliff # define STATIC static
89 1.1.2.1 cliff #else
90 1.1.2.1 cliff # define STATIC
91 1.1.2.1 cliff #endif
92 1.1.2.1 cliff
93 1.1.2.1 cliff
94 1.1.2.1 cliff /*
95 1.1.2.1 cliff * XLS PCIe Extended Configuration Registers
96 1.1.2.1 cliff */
97 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_UESR 0x104 /* Uncorrectable Error Status Reg */
98 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_UEMR 0x108 /* Uncorrectable Error Mask Reg */
99 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_UEVR 0x10c /* Uncorrectable Error seVerity Reg */
100 1.1.2.1 cliff #define PCIE_ECFG_UEVR_DFLT \
101 1.1.2.1 cliff (__BITS(18,17) | __BIT(31) | __BITS(5,4) | __BIT(0))
102 1.1.2.1 cliff #define PCIE_ECFG_UExR_RESV (__BITS(31,21) | __BITS(11,6) | __BITS(3,1))
103 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_CESR 0x110 /* Correctable Error Status Reg */
104 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_CEMR 0x114 /* Correctable Error Mask Reg */
105 1.1.2.1 cliff #define PCIE_ECFG_CExR_RESV (__BITS(31,14) | __BITS(11,9) | __BITS(5,1))
106 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_ACCR 0x118 /* Adv. Capabilities Control Reg */
107 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_HLRn(n) (0x11c + ((n) * 4)) /* Header Log Regs */
108 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_RECR 0x12c /* Root Error Command Reg */
109 1.1.2.1 cliff #define PCIE_ECFG_RECR_RESV __BITS(31,3)
110 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_RESR 0x130 /* Root Error Status Reg */
111 1.1.2.1 cliff #define PCIE_ECFG_RESR_RESV __BITS(26,7)
112 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_ESI 0x134 /* Error Source Identification Reg */
113 1.1.2.1 cliff #define RMIXL_PCIE_ECFG_DSNCR 0x140 /* Dev Serial Number Capability Regs */
114 1.1.2.1 cliff
115 1.1.2.1 cliff static const struct {
116 1.1.2.1 cliff u_int offset;
117 1.1.2.1 cliff u_int32_t rw1c;
118 1.1.2.1 cliff } pcie_ecfg_errs_tab[] = {
119 1.1.2.1 cliff { RMIXL_PCIE_ECFG_UESR, (__BITS(20,12) | __BIT(4)) },
120 1.1.2.1 cliff { RMIXL_PCIE_ECFG_CESR, (__BITS(20,12) | __BIT(4)) },
121 1.1.2.1 cliff { RMIXL_PCIE_ECFG_HLRn(0), 0 },
122 1.1.2.1 cliff { RMIXL_PCIE_ECFG_HLRn(1), 0 },
123 1.1.2.1 cliff { RMIXL_PCIE_ECFG_HLRn(2), 0 },
124 1.1.2.1 cliff { RMIXL_PCIE_ECFG_HLRn(3), 0 },
125 1.1.2.1 cliff { RMIXL_PCIE_ECFG_RESR, __BITS(6,0) },
126 1.1.2.1 cliff { RMIXL_PCIE_ECFG_ESI, 0 },
127 1.1.2.1 cliff };
128 1.1.2.1 cliff #define PCIE_ECFG_ERRS_OFFTAB_NENTRIES \
129 1.1.2.1 cliff (sizeof(pcie_ecfg_errs_tab)/sizeof(pcie_ecfg_errs_tab[0]))
130 1.1.2.1 cliff
131 1.1.2.8 cliff typedef struct rmixl_pcie_int_csr {
132 1.1.2.8 cliff uint r0;
133 1.1.2.8 cliff uint r1;
134 1.1.2.8 cliff } rmixl_pcie_int_csr_t;
135 1.1.2.8 cliff
136 1.1.2.8 cliff static const rmixl_pcie_int_csr_t int_enb_offset[4] = {
137 1.1.2.8 cliff { RMIXL_PCIE_LINK0_INT_ENABLE0, RMIXL_PCIE_LINK0_INT_ENABLE1 },
138 1.1.2.8 cliff { RMIXL_PCIE_LINK1_INT_ENABLE0, RMIXL_PCIE_LINK1_INT_ENABLE1 },
139 1.1.2.8 cliff { RMIXL_PCIE_LINK2_INT_ENABLE0, RMIXL_PCIE_LINK2_INT_ENABLE1 },
140 1.1.2.8 cliff { RMIXL_PCIE_LINK3_INT_ENABLE0, RMIXL_PCIE_LINK3_INT_ENABLE1 },
141 1.1.2.8 cliff };
142 1.1.2.8 cliff
143 1.1.2.8 cliff static const rmixl_pcie_int_csr_t int_sts_offset[4] = {
144 1.1.2.8 cliff { RMIXL_PCIE_LINK0_INT_STATUS0, RMIXL_PCIE_LINK0_INT_STATUS1 },
145 1.1.2.8 cliff { RMIXL_PCIE_LINK1_INT_STATUS0, RMIXL_PCIE_LINK1_INT_STATUS1 },
146 1.1.2.8 cliff { RMIXL_PCIE_LINK2_INT_STATUS0, RMIXL_PCIE_LINK2_INT_STATUS1 },
147 1.1.2.8 cliff { RMIXL_PCIE_LINK3_INT_STATUS0, RMIXL_PCIE_LINK3_INT_STATUS1 },
148 1.1.2.8 cliff };
149 1.1.2.8 cliff
150 1.1.2.8 cliff static const u_int msi_enb_offset[4] = {
151 1.1.2.8 cliff RMIXL_PCIE_LINK0_MSI_ENABLE,
152 1.1.2.8 cliff RMIXL_PCIE_LINK1_MSI_ENABLE,
153 1.1.2.8 cliff RMIXL_PCIE_LINK2_MSI_ENABLE,
154 1.1.2.8 cliff RMIXL_PCIE_LINK3_MSI_ENABLE
155 1.1.2.8 cliff };
156 1.1.2.8 cliff
157 1.1.2.8 cliff #define RMIXL_PCIE_LINK_STATUS0_ERRORS __BITS(6,4)
158 1.1.2.8 cliff #define RMIXL_PCIE_LINK_STATUS1_ERRORS __BITS(10,0)
159 1.1.2.8 cliff #define RMIXL_PCIE_LINK_STATUS_ERRORS \
160 1.1.2.8 cliff ((((uint64_t)RMIXL_PCIE_LINK_STATUS1_ERRORS) << 32) | \
161 1.1.2.8 cliff (uint64_t)RMIXL_PCIE_LINK_STATUS0_ERRORS)
162 1.1.2.8 cliff
163 1.1.2.16 cliff #define RMIXL_PCIE_EVCNT(sc, link, bitno, cpu) \
164 1.1.2.16 cliff &(sc)->sc_evcnts[link][(bitno) * (ncpu) + (cpu)]
165 1.1.2.16 cliff
166 1.1.2.1 cliff static int rmixl_pcie_match(device_t, cfdata_t, void *);
167 1.1.2.1 cliff static void rmixl_pcie_attach(device_t, device_t, void *);
168 1.1.2.1 cliff static void rmixl_pcie_init(struct rmixl_pcie_softc *);
169 1.1.2.1 cliff static void rmixl_pcie_init_ecfg(struct rmixl_pcie_softc *);
170 1.1.2.1 cliff static void rmixl_pcie_attach_hook(struct device *, struct device *,
171 1.1.2.1 cliff struct pcibus_attach_args *);
172 1.1.2.18 matt static void rmixl_pcie_lnkcfg_xls4xx(rmixl_pcie_lnktab_t *, uint32_t);
173 1.1.2.18 matt static void rmixl_pcie_lnkcfg_xls408Lite(rmixl_pcie_lnktab_t *, uint32_t);
174 1.1.2.18 matt static void rmixl_pcie_lnkcfg_xls2xx(rmixl_pcie_lnktab_t *, uint32_t);
175 1.1.2.18 matt static void rmixl_pcie_lnkcfg_xls1xx(rmixl_pcie_lnktab_t *, uint32_t);
176 1.1.2.1 cliff static void rmixl_pcie_lnkcfg(struct rmixl_pcie_softc *);
177 1.1.2.8 cliff static void rmixl_pcie_intcfg(struct rmixl_pcie_softc *);
178 1.1.2.1 cliff static void rmixl_pcie_errata(struct rmixl_pcie_softc *);
179 1.1.2.1 cliff static void rmixl_conf_interrupt(void *, int, int, int, int, int *);
180 1.1.2.1 cliff static int rmixl_pcie_bus_maxdevs(void *, int);
181 1.1.2.18 matt static pcitag_t rmixl_tag_ecfg_to_cfg(pcitag_t);
182 1.1.2.1 cliff static pcitag_t rmixl_pcie_make_tag(void *, int, int, int);
183 1.1.2.1 cliff static void rmixl_pcie_decompose_tag(void *, pcitag_t, int *, int *, int *);
184 1.1.2.1 cliff void rmixl_pcie_tag_print(const char *restrict, void *, pcitag_t, int, vaddr_t, u_long);
185 1.1.2.3 cliff static int rmixl_pcie_conf_setup(struct rmixl_pcie_softc *,
186 1.1.2.3 cliff pcitag_t, int *, bus_space_tag_t *,
187 1.1.2.3 cliff bus_space_handle_t *);
188 1.1.2.1 cliff static pcireg_t rmixl_pcie_conf_read(void *, pcitag_t, int);
189 1.1.2.1 cliff static void rmixl_pcie_conf_write(void *, pcitag_t, int, pcireg_t);
190 1.1.2.18 matt #ifdef __PCI_DEV_FUNCORDER
191 1.1.2.18 matt static bool rmixl_pcie_dev_funcorder(void *, int, int, int, char *);
192 1.1.2.18 matt #endif
193 1.1.2.1 cliff
194 1.1.2.1 cliff static int rmixl_pcie_intr_map(struct pci_attach_args *,
195 1.1.2.1 cliff pci_intr_handle_t *);
196 1.1.2.1 cliff static const char *
197 1.1.2.1 cliff rmixl_pcie_intr_string(void *, pci_intr_handle_t);
198 1.1.2.1 cliff static const struct evcnt *
199 1.1.2.1 cliff rmixl_pcie_intr_evcnt(void *, pci_intr_handle_t);
200 1.1.2.8 cliff static pci_intr_handle_t
201 1.1.2.8 cliff rmixl_pcie_make_pih(u_int, u_int, u_int);
202 1.1.2.8 cliff static void rmixl_pcie_decompose_pih(pci_intr_handle_t, u_int *, u_int *, u_int *);
203 1.1.2.8 cliff static void rmixl_pcie_intr_disestablish(void *, void *);
204 1.1.2.1 cliff static void *rmixl_pcie_intr_establish(void *, pci_intr_handle_t,
205 1.1.2.1 cliff int, int (*)(void *), void *);
206 1.1.2.16 cliff static rmixl_pcie_link_intr_t *
207 1.1.2.16 cliff rmixl_pcie_lip_add_1(rmixl_pcie_softc_t *, u_int, int, int);
208 1.1.2.16 cliff static void rmixl_pcie_lip_free_callout(rmixl_pcie_link_intr_t *);
209 1.1.2.16 cliff static void rmixl_pcie_lip_free(void *);
210 1.1.2.8 cliff static int rmixl_pcie_intr(void *);
211 1.1.2.8 cliff static void rmixl_pcie_link_error_intr(u_int, uint32_t, uint32_t);
212 1.1.2.1 cliff #if defined(DEBUG) || defined(DDB)
213 1.1.2.1 cliff int rmixl_pcie_error_check(void);
214 1.1.2.1 cliff #endif
215 1.1.2.1 cliff static int _rmixl_pcie_error_check(void *);
216 1.1.2.1 cliff static int rmixl_pcie_error_intr(void *);
217 1.1.2.1 cliff
218 1.1.2.18 matt static void rmixl_physaddr_add(struct extent *, const char *,
219 1.1.2.18 matt struct rmixl_region *, bus_addr_t, bus_size_t);
220 1.1.2.1 cliff
221 1.1.2.18 matt #define RMIXL_PCIE_BAR_INIT(rp, reg, bar, size, align) { \
222 1.1.2.1 cliff struct extent *ext = rmixl_configuration.rc_phys_ex; \
223 1.1.2.1 cliff u_long region_start; \
224 1.1.2.1 cliff int err; \
225 1.1.2.1 cliff \
226 1.1.2.1 cliff err = extent_alloc(ext, (size), (align), 0UL, EX_NOWAIT, \
227 1.1.2.18 matt ®ion_start); \
228 1.1.2.1 cliff if (err != 0) \
229 1.1.2.1 cliff panic("%s: extent_alloc(%p, %#lx, %#lx, %#lx, %#x, %p)",\
230 1.1.2.18 matt __func__, ext, size, align, 0UL, EX_NOWAIT, \
231 1.1.2.18 matt ®ion_start); \
232 1.1.2.18 matt const uint64_t pbase = (uint64_t)region_start << 20; \
233 1.1.2.18 matt bar = RMIXL_PCIE_##reg##_BAR(pbase, 1); \
234 1.1.2.18 matt DPRINTF(("%s: PCIE_%s_BAR was not enabled by firmware\n" \
235 1.1.2.18 matt "%s enabling PCIE_%s_BAR at phys %#" PRIxBUSADDR \
236 1.1.2.18 matt ", size %luMB\n", \
237 1.1.2.18 matt __func__, __STRING(reg), \
238 1.1.2.18 matt __func__, __STRING(reg), pbase, size)); \
239 1.1.2.18 matt RMIXL_IOREG_WRITE(RMIXL_IO_DEV_BRIDGE \
240 1.1.2.18 matt + RMIXLS_SBC_PCIE_##reg##_BAR, bar); \
241 1.1.2.18 matt bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE \
242 1.1.2.18 matt + RMIXLS_SBC_PCIE_##reg##_BAR); \
243 1.1.2.1 cliff DPRINTF(("%s: %s BAR %#x\n", __func__, __STRING(reg), bar)); \
244 1.1.2.18 matt (rp)->r_pbase = pbase; \
245 1.1.2.18 matt (rp)->r_size = (size) << 20; \
246 1.1.2.1 cliff }
247 1.1.2.1 cliff
248 1.1.2.1 cliff
249 1.1.2.1 cliff #if defined(DEBUG) || defined(DDB)
250 1.1.2.1 cliff static void *rmixl_pcie_v;
251 1.1.2.1 cliff #endif
252 1.1.2.1 cliff
253 1.1.2.1 cliff CFATTACH_DECL_NEW(rmixl_pcie, sizeof(struct rmixl_pcie_softc),
254 1.1.2.1 cliff rmixl_pcie_match, rmixl_pcie_attach, NULL, NULL);
255 1.1.2.1 cliff
256 1.1.2.18 matt static bool rmixl_pcie_found;
257 1.1.2.1 cliff
258 1.1.2.1 cliff static int
259 1.1.2.1 cliff rmixl_pcie_match(device_t parent, cfdata_t cf, void *aux)
260 1.1.2.1 cliff {
261 1.1.2.1 cliff uint32_t r;
262 1.1.2.1 cliff
263 1.1.2.11 cliff /*
264 1.1.2.18 matt * A PCIe interface exists only on XLS chips.
265 1.1.2.11 cliff */
266 1.1.2.11 cliff if (! cpu_rmixls(mips_options.mips_cpu))
267 1.1.2.11 cliff return 0;
268 1.1.2.11 cliff
269 1.1.2.18 matt /*
270 1.1.2.18 matt * There is only one PCIe Interface on chip
271 1.1.2.1 cliff */
272 1.1.2.1 cliff if (rmixl_pcie_found)
273 1.1.2.1 cliff return 0;
274 1.1.2.1 cliff
275 1.1.2.1 cliff /* read GPIO Reset Configuration register */
276 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
277 1.1.2.1 cliff r >>= 26;
278 1.1.2.1 cliff r &= 3;
279 1.1.2.1 cliff if (r != 0)
280 1.1.2.1 cliff return 0; /* strapped for SRIO */
281 1.1.2.1 cliff
282 1.1.2.1 cliff return 1;
283 1.1.2.1 cliff }
284 1.1.2.1 cliff
285 1.1.2.1 cliff static void
286 1.1.2.1 cliff rmixl_pcie_attach(device_t parent, device_t self, void *aux)
287 1.1.2.1 cliff {
288 1.1.2.1 cliff struct rmixl_pcie_softc *sc = device_private(self);
289 1.1.2.1 cliff struct obio_attach_args *obio = aux;
290 1.1.2.1 cliff struct rmixl_config *rcp = &rmixl_configuration;
291 1.1.2.1 cliff struct pcibus_attach_args pba;
292 1.1.2.1 cliff uint32_t bar;
293 1.1.2.1 cliff
294 1.1.2.18 matt rmixl_pcie_found = true;
295 1.1.2.1 cliff sc->sc_dev = self;
296 1.1.2.1 cliff
297 1.1.2.18 matt aprint_normal(": RMI XLS PCIe Interface\n");
298 1.1.2.1 cliff
299 1.1.2.16 cliff mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_HIGH);
300 1.1.2.16 cliff
301 1.1.2.1 cliff rmixl_pcie_lnkcfg(sc);
302 1.1.2.1 cliff
303 1.1.2.8 cliff rmixl_pcie_intcfg(sc);
304 1.1.2.8 cliff
305 1.1.2.1 cliff rmixl_pcie_errata(sc);
306 1.1.2.1 cliff
307 1.1.2.18 matt sc->sc_dmat29 = obio->obio_dmat29;
308 1.1.2.18 matt sc->sc_dmat32 = obio->obio_dmat32;
309 1.1.2.18 matt sc->sc_dmat64 = obio->obio_dmat64;
310 1.1.2.18 matt sc->sc_pc = &rcp->rc_pci_chipset;
311 1.1.2.9 cliff
312 1.1.2.1 cliff /*
313 1.1.2.1 cliff * get PCI config space base addr from SBC PCIe CFG BAR
314 1.1.2.1 cliff * initialize it if necessary
315 1.1.2.1 cliff */
316 1.1.2.11 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLS_SBC_PCIE_CFG_BAR);
317 1.1.2.1 cliff DPRINTF(("%s: PCIE_CFG_BAR %#x\n", __func__, bar));
318 1.1.2.1 cliff if ((bar & RMIXL_PCIE_CFG_BAR_ENB) == 0) {
319 1.1.2.1 cliff u_long n = RMIXL_PCIE_CFG_SIZE / (1024 * 1024);
320 1.1.2.18 matt RMIXL_PCIE_BAR_INIT(&rcp->rc_pci_cfg, CFG, bar, n, n);
321 1.1.2.1 cliff }
322 1.1.2.1 cliff
323 1.1.2.1 cliff /*
324 1.1.2.1 cliff * get PCIE Extended config space base addr from SBC PCIe ECFG BAR
325 1.1.2.1 cliff * initialize it if necessary
326 1.1.2.1 cliff */
327 1.1.2.11 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLS_SBC_PCIE_ECFG_BAR);
328 1.1.2.1 cliff DPRINTF(("%s: PCIE_ECFG_BAR %#x\n", __func__, bar));
329 1.1.2.1 cliff if ((bar & RMIXL_PCIE_ECFG_BAR_ENB) == 0) {
330 1.1.2.1 cliff u_long n = RMIXL_PCIE_ECFG_SIZE / (1024 * 1024);
331 1.1.2.18 matt RMIXL_PCIE_BAR_INIT(&rcp->rc_pci_ecfg, ECFG, bar, n, n);
332 1.1.2.1 cliff }
333 1.1.2.1 cliff
334 1.1.2.1 cliff /*
335 1.1.2.1 cliff * get PCI MEM space base [addr, size] from SBC PCIe MEM BAR
336 1.1.2.1 cliff * initialize it if necessary
337 1.1.2.1 cliff */
338 1.1.2.11 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLS_SBC_PCIE_MEM_BAR);
339 1.1.2.1 cliff DPRINTF(("%s: PCIE_MEM_BAR %#x\n", __func__, bar));
340 1.1.2.1 cliff if ((bar & RMIXL_PCIE_MEM_BAR_ENB) == 0) {
341 1.1.2.1 cliff u_long n = 256; /* 256 MB */
342 1.1.2.18 matt RMIXL_PCIE_BAR_INIT(&rcp->rc_pci_mem, MEM, bar, n, n);
343 1.1.2.1 cliff }
344 1.1.2.1 cliff
345 1.1.2.1 cliff /*
346 1.1.2.1 cliff * get PCI IO space base [addr, size] from SBC PCIe IO BAR
347 1.1.2.1 cliff * initialize it if necessary
348 1.1.2.1 cliff */
349 1.1.2.11 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLS_SBC_PCIE_IO_BAR);
350 1.1.2.1 cliff DPRINTF(("%s: PCIE_IO_BAR %#x\n", __func__, bar));
351 1.1.2.1 cliff if ((bar & RMIXL_PCIE_IO_BAR_ENB) == 0) {
352 1.1.2.1 cliff u_long n = 32; /* 32 MB */
353 1.1.2.18 matt RMIXL_PCIE_BAR_INIT(&rcp->rc_pci_io, IO, bar, n, n);
354 1.1.2.1 cliff }
355 1.1.2.1 cliff
356 1.1.2.1 cliff /*
357 1.1.2.3 cliff * initialize the PCI CFG, ECFG bus space tags
358 1.1.2.3 cliff */
359 1.1.2.11 cliff sc->sc_pci_cfg_memt = &rcp->rc_pci_cfg_memt;
360 1.1.2.18 matt rmixl_pci_cfg_el_bus_mem_init(sc->sc_pci_cfg_memt, rcp);
361 1.1.2.18 matt
362 1.1.2.18 matt /*
363 1.1.2.18 matt * This should be in KSEG1 and has no extent tracking.
364 1.1.2.18 matt * (bit 24 controls little (0) or big (1) endian access).
365 1.1.2.18 matt */
366 1.1.2.18 matt if (bus_space_map(sc->sc_pci_cfg_memt, 0, rcp->rc_pci_cfg.r_size / 2,
367 1.1.2.18 matt 0, &rcp->rc_pci_cfg_memh))
368 1.1.2.18 matt panic("%s: failed to map pci CFG registers "
369 1.1.2.18 matt "(base=%#"PRIxBUSADDR" size=%#"PRIxBUSSIZE")",
370 1.1.2.18 matt __func__, rcp->rc_pci_cfg.r_pbase,
371 1.1.2.18 matt rcp->rc_pci_cfg.r_size / 2);
372 1.1.2.3 cliff
373 1.1.2.18 matt sc->sc_pci_cfg_memh = rcp->rc_pci_cfg_memh;
374 1.1.2.18 matt
375 1.1.2.18 matt sc->sc_pci_ecfg_memt = &rcp->rc_pci_ecfg_el_memt;
376 1.1.2.18 matt rmixl_pci_ecfg_el_bus_mem_init(sc->sc_pci_ecfg_memt, rcp);
377 1.1.2.18 matt
378 1.1.2.18 matt /*
379 1.1.2.18 matt * This is too big to in KSEG1 but is accessible via XKPHYS
380 1.1.2.18 matt * and has no extent tracking.
381 1.1.2.18 matt * (bit 28 controls little (0) or big (1) endian access).
382 1.1.2.18 matt */
383 1.1.2.18 matt #ifdef _LP64
384 1.1.2.18 matt if (bus_space_map(sc->sc_pci_ecfg_memt, 0, rcp->rc_pci_ecfg.r_size / 2,
385 1.1.2.18 matt 0, &rcp->rc_pci_ecfg_el_memh))
386 1.1.2.18 matt panic("%s: failed to map pci ECFG LE registers "
387 1.1.2.18 matt "(base=%#"PRIxBUSADDR" size=%#"PRIxBUSSIZE")",
388 1.1.2.18 matt __func__, rcp->rc_pci_ecfg.r_pbase,
389 1.1.2.18 matt rcp->rc_pci_ecfg.r_size / 2);
390 1.1.2.18 matt
391 1.1.2.19 matt sc->sc_pci_ecfg_memh = rcp->rc_pci_ecfg_el_memh;
392 1.1.2.18 matt #else
393 1.1.2.18 matt printf("%s: skipping mapping of pci ECFG LE registers "
394 1.1.2.18 matt "(base=%#"PRIxBUSADDR" size=%#"PRIxBUSSIZE")\n",
395 1.1.2.18 matt __func__, rcp->rc_pci_ecfg.r_pbase,
396 1.1.2.18 matt rcp->rc_pci_ecfg.r_size / 2);
397 1.1.2.18 matt #endif
398 1.1.2.3 cliff
399 1.1.2.3 cliff /*
400 1.1.2.3 cliff * initialize the PCI MEM and IO bus space tags
401 1.1.2.1 cliff */
402 1.1.2.11 cliff rmixl_pci_bus_mem_init(&rcp->rc_pci_memt, rcp);
403 1.1.2.11 cliff rmixl_pci_bus_io_init(&rcp->rc_pci_iot, rcp);
404 1.1.2.1 cliff
405 1.1.2.1 cliff /*
406 1.1.2.1 cliff * initialize the extended configuration regs
407 1.1.2.1 cliff */
408 1.1.2.1 cliff rmixl_pcie_init_ecfg(sc);
409 1.1.2.1 cliff
410 1.1.2.1 cliff /*
411 1.1.2.1 cliff * initialize the PCI chipset tag
412 1.1.2.1 cliff */
413 1.1.2.1 cliff rmixl_pcie_init(sc);
414 1.1.2.1 cliff
415 1.1.2.1 cliff /*
416 1.1.2.1 cliff * attach the PCI bus
417 1.1.2.1 cliff */
418 1.1.2.1 cliff memset(&pba, 0, sizeof(pba));
419 1.1.2.1 cliff pba.pba_memt = &rcp->rc_pci_memt;
420 1.1.2.1 cliff pba.pba_iot = &rcp->rc_pci_iot;
421 1.1.2.18 matt pba.pba_dmat = sc->sc_dmat32;
422 1.1.2.18 matt pba.pba_dmat64 = sc->sc_dmat64;
423 1.1.2.18 matt pba.pba_pc = sc->sc_pc;
424 1.1.2.1 cliff pba.pba_bus = 0;
425 1.1.2.1 cliff pba.pba_bridgetag = NULL;
426 1.1.2.1 cliff pba.pba_intrswiz = 0;
427 1.1.2.1 cliff pba.pba_intrtag = 0;
428 1.1.2.1 cliff pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
429 1.1.2.1 cliff PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
430 1.1.2.1 cliff
431 1.1.2.1 cliff (void) config_found_ia(self, "pcibus", &pba, pcibusprint);
432 1.1.2.1 cliff }
433 1.1.2.1 cliff
434 1.1.2.1 cliff /*
435 1.1.2.18 matt * rmixl_pcie_lnkcfg_xls4xx - link configs for XLS4xx and XLS6xx
436 1.1.2.1 cliff * use IO_AD[11] and IO_AD[10], observable in
437 1.1.2.1 cliff * Bits[21:20] of the GPIO Reset Configuration register
438 1.1.2.1 cliff */
439 1.1.2.1 cliff static void
440 1.1.2.18 matt rmixl_pcie_lnkcfg_xls4xx(rmixl_pcie_lnktab_t *ltp, uint32_t grcr)
441 1.1.2.1 cliff {
442 1.1.2.1 cliff u_int index;
443 1.1.2.18 matt static const rmixl_pcie_lnkcfg_t lnktab_xls4xx[4][4] = {
444 1.1.2.1 cliff {{ LCFG_EP, 4}, {LCFG_NO, 0}, {LCFG_NO, 0}, {LCFG_NO, 0}},
445 1.1.2.1 cliff {{ LCFG_RC, 4}, {LCFG_NO, 0}, {LCFG_NO, 0}, {LCFG_NO, 0}},
446 1.1.2.1 cliff {{ LCFG_EP, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}},
447 1.1.2.1 cliff {{ LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}},
448 1.1.2.1 cliff };
449 1.1.2.18 matt static const char * const lnkstr_xls4xx[4] = {
450 1.1.2.8 cliff "1EPx4",
451 1.1.2.8 cliff "1RCx4",
452 1.1.2.8 cliff "1EPx1, 3RCx1",
453 1.1.2.8 cliff "4RCx1"
454 1.1.2.1 cliff };
455 1.1.2.1 cliff index = (grcr >> 20) & 3;
456 1.1.2.1 cliff ltp->ncfgs = 4;
457 1.1.2.18 matt ltp->cfg = lnktab_xls4xx[index];
458 1.1.2.18 matt ltp->str = lnkstr_xls4xx[index];
459 1.1.2.1 cliff }
460 1.1.2.1 cliff
461 1.1.2.1 cliff /*
462 1.1.2.18 matt * rmixl_pcie_lnkcfg_xls408Lite - link configs for XLS408Lite and XLS04A
463 1.1.2.1 cliff * use IO_AD[11] and IO_AD[10], observable in
464 1.1.2.1 cliff * Bits[21:20] of the GPIO Reset Configuration register
465 1.1.2.1 cliff */
466 1.1.2.1 cliff static void
467 1.1.2.18 matt rmixl_pcie_lnkcfg_xls408Lite(rmixl_pcie_lnktab_t *ltp, uint32_t grcr)
468 1.1.2.1 cliff {
469 1.1.2.1 cliff u_int index;
470 1.1.2.18 matt static const rmixl_pcie_lnkcfg_t lnktab_xls408Lite[4][2] = {
471 1.1.2.1 cliff {{ LCFG_EP, 4}, {LCFG_NO, 0}},
472 1.1.2.1 cliff {{ LCFG_RC, 4}, {LCFG_NO, 0}},
473 1.1.2.1 cliff {{ LCFG_EP, 1}, {LCFG_RC, 1}},
474 1.1.2.1 cliff {{ LCFG_RC, 1}, {LCFG_RC, 1}},
475 1.1.2.1 cliff };
476 1.1.2.18 matt static const char * const lnkstr_xls408Lite[4] = {
477 1.1.2.8 cliff "4EPx4",
478 1.1.2.8 cliff "1RCx4",
479 1.1.2.8 cliff "1EPx1, 1RCx1",
480 1.1.2.8 cliff "2RCx1"
481 1.1.2.1 cliff };
482 1.1.2.1 cliff
483 1.1.2.1 cliff index = (grcr >> 20) & 3;
484 1.1.2.1 cliff ltp->ncfgs = 2;
485 1.1.2.18 matt ltp->cfg = lnktab_xls408Lite[index];
486 1.1.2.18 matt ltp->str = lnkstr_xls408Lite[index];
487 1.1.2.1 cliff }
488 1.1.2.1 cliff
489 1.1.2.1 cliff /*
490 1.1.2.18 matt * rmixl_pcie_lnkcfg_xls2xx - link configs for XLS2xx
491 1.1.2.1 cliff * use IO_AD[10], observable in Bit[20] of the
492 1.1.2.1 cliff * GPIO Reset Configuration register
493 1.1.2.1 cliff */
494 1.1.2.1 cliff static void
495 1.1.2.18 matt rmixl_pcie_lnkcfg_xls2xx(rmixl_pcie_lnktab_t *ltp, uint32_t grcr)
496 1.1.2.1 cliff {
497 1.1.2.1 cliff u_int index;
498 1.1.2.18 matt static const rmixl_pcie_lnkcfg_t lnktab_xls2xx[2][4] = {
499 1.1.2.1 cliff {{ LCFG_EP, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}},
500 1.1.2.1 cliff {{ LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}, {LCFG_RC, 1}}
501 1.1.2.1 cliff };
502 1.1.2.18 matt static const char * const lnkstr_xls2xx[2] = {
503 1.1.2.8 cliff "1EPx1, 3RCx1",
504 1.1.2.8 cliff "4RCx1",
505 1.1.2.1 cliff };
506 1.1.2.1 cliff
507 1.1.2.1 cliff index = (grcr >> 20) & 1;
508 1.1.2.1 cliff ltp->ncfgs = 4;
509 1.1.2.18 matt ltp->cfg = lnktab_xls2xx[index];
510 1.1.2.18 matt ltp->str = lnkstr_xls2xx[index];
511 1.1.2.1 cliff }
512 1.1.2.1 cliff
513 1.1.2.1 cliff /*
514 1.1.2.18 matt * rmixl_pcie_lnkcfg_xls1xx - link configs for XLS1xx
515 1.1.2.1 cliff * use IO_AD[10], observable in Bit[20] of the
516 1.1.2.1 cliff * GPIO Reset Configuration register
517 1.1.2.1 cliff */
518 1.1.2.1 cliff static void
519 1.1.2.18 matt rmixl_pcie_lnkcfg_xls1xx(rmixl_pcie_lnktab_t *ltp, uint32_t grcr)
520 1.1.2.1 cliff {
521 1.1.2.1 cliff u_int index;
522 1.1.2.18 matt static const rmixl_pcie_lnkcfg_t lnktab_xls1xx[2][2] = {
523 1.1.2.1 cliff {{ LCFG_EP, 1}, {LCFG_RC, 1}},
524 1.1.2.1 cliff {{ LCFG_RC, 1}, {LCFG_RC, 1}}
525 1.1.2.1 cliff };
526 1.1.2.18 matt static const char * const lnkstr_xls1xx[2] = {
527 1.1.2.8 cliff "1EPx1, 1RCx1",
528 1.1.2.8 cliff "2RCx1",
529 1.1.2.1 cliff };
530 1.1.2.1 cliff
531 1.1.2.1 cliff index = (grcr >> 20) & 1;
532 1.1.2.1 cliff ltp->ncfgs = 2;
533 1.1.2.18 matt ltp->cfg = lnktab_xls1xx[index];
534 1.1.2.18 matt ltp->str = lnkstr_xls1xx[index];
535 1.1.2.1 cliff }
536 1.1.2.1 cliff
537 1.1.2.1 cliff /*
538 1.1.2.1 cliff * rmixl_pcie_lnkcfg - determine PCI Express Link Configuration
539 1.1.2.1 cliff */
540 1.1.2.1 cliff static void
541 1.1.2.1 cliff rmixl_pcie_lnkcfg(struct rmixl_pcie_softc *sc)
542 1.1.2.1 cliff {
543 1.1.2.1 cliff uint32_t r;
544 1.1.2.1 cliff
545 1.1.2.1 cliff /* read GPIO Reset Configuration register */
546 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_GPIO + RMIXL_GPIO_RESET_CFG);
547 1.1.2.1 cliff DPRINTF(("%s: GPIO RCR %#x\n", __func__, r));
548 1.1.2.1 cliff
549 1.1.2.7 matt switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
550 1.1.2.1 cliff case MIPS_XLS104:
551 1.1.2.1 cliff case MIPS_XLS108:
552 1.1.2.18 matt rmixl_pcie_lnkcfg_xls1xx(&sc->sc_pcie_lnktab, r);
553 1.1.2.1 cliff break;
554 1.1.2.1 cliff case MIPS_XLS204:
555 1.1.2.1 cliff case MIPS_XLS208:
556 1.1.2.18 matt rmixl_pcie_lnkcfg_xls2xx(&sc->sc_pcie_lnktab, r);
557 1.1.2.1 cliff break;
558 1.1.2.1 cliff case MIPS_XLS404LITE:
559 1.1.2.1 cliff case MIPS_XLS408LITE:
560 1.1.2.18 matt rmixl_pcie_lnkcfg_xls408Lite(&sc->sc_pcie_lnktab, r);
561 1.1.2.1 cliff break;
562 1.1.2.1 cliff case MIPS_XLS404:
563 1.1.2.1 cliff case MIPS_XLS408:
564 1.1.2.1 cliff case MIPS_XLS416:
565 1.1.2.1 cliff case MIPS_XLS608:
566 1.1.2.1 cliff case MIPS_XLS616:
567 1.1.2.1 cliff /* 6xx uses same table as 4xx */
568 1.1.2.18 matt rmixl_pcie_lnkcfg_xls4xx(&sc->sc_pcie_lnktab, r);
569 1.1.2.1 cliff break;
570 1.1.2.1 cliff default:
571 1.1.2.1 cliff panic("%s: unknown RMI PRID IMPL", __func__);
572 1.1.2.1 cliff }
573 1.1.2.1 cliff
574 1.1.2.18 matt aprint_normal_dev(sc->sc_dev, "link config %s\n",
575 1.1.2.18 matt sc->sc_pcie_lnktab.str);
576 1.1.2.1 cliff }
577 1.1.2.1 cliff
578 1.1.2.8 cliff /*
579 1.1.2.8 cliff * rmixl_pcie_intcfg - init PCIe Link interrupt enables
580 1.1.2.8 cliff */
581 1.1.2.8 cliff static void
582 1.1.2.8 cliff rmixl_pcie_intcfg(struct rmixl_pcie_softc *sc)
583 1.1.2.8 cliff {
584 1.1.2.8 cliff int link;
585 1.1.2.16 cliff size_t size;
586 1.1.2.16 cliff rmixl_pcie_evcnt_t *ev;
587 1.1.2.8 cliff
588 1.1.2.8 cliff DPRINTF(("%s: disable all link interrupts\n", __func__));
589 1.1.2.8 cliff for (link=0; link < sc->sc_pcie_lnktab.ncfgs; link++) {
590 1.1.2.8 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_LE + int_enb_offset[link].r0,
591 1.1.2.8 cliff RMIXL_PCIE_LINK_STATUS0_ERRORS);
592 1.1.2.8 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_LE + int_enb_offset[link].r1,
593 1.1.2.8 cliff RMIXL_PCIE_LINK_STATUS1_ERRORS);
594 1.1.2.8 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_LE + msi_enb_offset[link], 0);
595 1.1.2.16 cliff sc->sc_link_intr[link] = NULL;
596 1.1.2.16 cliff
597 1.1.2.16 cliff /*
598 1.1.2.16 cliff * allocate per-cpu, per-pin interrupt event counters
599 1.1.2.16 cliff */
600 1.1.2.16 cliff size = ncpu * PCI_INTERRUPT_PIN_MAX * sizeof(rmixl_pcie_evcnt_t);
601 1.1.2.16 cliff ev = malloc(size, M_DEVBUF, M_NOWAIT);
602 1.1.2.16 cliff if (ev == NULL)
603 1.1.2.16 cliff panic("%s: cannot malloc evcnts\n", __func__);
604 1.1.2.16 cliff sc->sc_evcnts[link] = ev;
605 1.1.2.16 cliff for (int pin=PCI_INTERRUPT_PIN_A; pin <= PCI_INTERRUPT_PIN_MAX; pin++) {
606 1.1.2.16 cliff for (int cpu=0; cpu < ncpu; cpu++) {
607 1.1.2.16 cliff ev = RMIXL_PCIE_EVCNT(sc, link, pin - 1, cpu);
608 1.1.2.16 cliff snprintf(ev->name, sizeof(ev->name),
609 1.1.2.16 cliff "cpu%d, link %d, pin %d", cpu, link, pin);
610 1.1.2.16 cliff evcnt_attach_dynamic(&ev->evcnt, EVCNT_TYPE_INTR,
611 1.1.2.16 cliff NULL, "rmixl_pcie", ev->name);
612 1.1.2.16 cliff }
613 1.1.2.16 cliff }
614 1.1.2.8 cliff }
615 1.1.2.8 cliff }
616 1.1.2.8 cliff
617 1.1.2.1 cliff static void
618 1.1.2.1 cliff rmixl_pcie_errata(struct rmixl_pcie_softc *sc)
619 1.1.2.1 cliff {
620 1.1.2.7 matt const mips_prid_t cpu_id = mips_options.mips_cpu_id;
621 1.1.2.1 cliff u_int rev;
622 1.1.2.1 cliff u_int lanes;
623 1.1.2.1 cliff bool e391 = false;
624 1.1.2.1 cliff
625 1.1.2.1 cliff /*
626 1.1.2.1 cliff * 3.9.1 PCIe Link-0 Registers Reset to Incorrect Values
627 1.1.2.1 cliff * check if it allies to this CPU implementation and revision
628 1.1.2.1 cliff */
629 1.1.2.1 cliff rev = MIPS_PRID_REV(cpu_id);
630 1.1.2.1 cliff switch (MIPS_PRID_IMPL(cpu_id)) {
631 1.1.2.1 cliff case MIPS_XLS104:
632 1.1.2.1 cliff case MIPS_XLS108:
633 1.1.2.1 cliff break;
634 1.1.2.1 cliff case MIPS_XLS204:
635 1.1.2.1 cliff case MIPS_XLS208:
636 1.1.2.1 cliff /* stepping A0 is affected */
637 1.1.2.1 cliff if (rev == 0)
638 1.1.2.1 cliff e391 = true;
639 1.1.2.1 cliff break;
640 1.1.2.1 cliff case MIPS_XLS404LITE:
641 1.1.2.1 cliff case MIPS_XLS408LITE:
642 1.1.2.1 cliff break;
643 1.1.2.1 cliff case MIPS_XLS404:
644 1.1.2.1 cliff case MIPS_XLS408:
645 1.1.2.1 cliff case MIPS_XLS416:
646 1.1.2.1 cliff /* steppings A0 and A1 are affected */
647 1.1.2.1 cliff if ((rev == 0) || (rev == 1))
648 1.1.2.1 cliff e391 = true;
649 1.1.2.1 cliff break;
650 1.1.2.1 cliff case MIPS_XLS608:
651 1.1.2.1 cliff case MIPS_XLS616:
652 1.1.2.1 cliff break;
653 1.1.2.1 cliff default:
654 1.1.2.1 cliff panic("unknown RMI PRID IMPL");
655 1.1.2.1 cliff }
656 1.1.2.1 cliff
657 1.1.2.1 cliff /*
658 1.1.2.1 cliff * for XLS we only need to check entry #0
659 1.1.2.1 cliff * this may need to change for later XL family chips
660 1.1.2.1 cliff */
661 1.1.2.1 cliff lanes = sc->sc_pcie_lnktab.cfg[0].lanes;
662 1.1.2.1 cliff
663 1.1.2.1 cliff if ((e391 != false) && ((lanes == 2) || (lanes == 4))) {
664 1.1.2.1 cliff /*
665 1.1.2.1 cliff * attempt work around for errata 3.9.1
666 1.1.2.1 cliff * "PCIe Link-0 Registers Reset to Incorrect Values"
667 1.1.2.1 cliff * the registers are write-once: if the firmware already wrote,
668 1.1.2.1 cliff * then our writes are ignored; hope they did it right.
669 1.1.2.1 cliff */
670 1.1.2.1 cliff uint32_t queuectrl;
671 1.1.2.1 cliff uint32_t bufdepth;
672 1.1.2.1 cliff #ifdef DIAGNOSTIC
673 1.1.2.1 cliff uint32_t r;
674 1.1.2.1 cliff #endif
675 1.1.2.1 cliff
676 1.1.2.1 cliff aprint_normal("%s: attempt work around for errata 3.9.1",
677 1.1.2.1 cliff device_xname(sc->sc_dev));
678 1.1.2.1 cliff if (lanes == 4) {
679 1.1.2.1 cliff queuectrl = 0x00018074;
680 1.1.2.1 cliff bufdepth = 0x001901D1;
681 1.1.2.1 cliff } else {
682 1.1.2.1 cliff queuectrl = 0x00018036;
683 1.1.2.1 cliff bufdepth = 0x001900D9;
684 1.1.2.1 cliff }
685 1.1.2.1 cliff
686 1.1.2.1 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_BE +
687 1.1.2.1 cliff RMIXL_VC0_POSTED_RX_QUEUE_CTRL, queuectrl);
688 1.1.2.1 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_BE +
689 1.1.2.1 cliff RMIXL_VC0_POSTED_BUFFER_DEPTH, bufdepth);
690 1.1.2.1 cliff
691 1.1.2.1 cliff #ifdef DIAGNOSTIC
692 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_BE +
693 1.1.2.1 cliff RMIXL_VC0_POSTED_RX_QUEUE_CTRL);
694 1.1.2.1 cliff printf("\nVC0_POSTED_RX_QUEUE_CTRL %#x\n", r);
695 1.1.2.1 cliff
696 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_BE +
697 1.1.2.1 cliff RMIXL_VC0_POSTED_BUFFER_DEPTH);
698 1.1.2.1 cliff printf("VC0_POSTED_BUFFER_DEPTH %#x\n", r);
699 1.1.2.1 cliff #endif
700 1.1.2.1 cliff }
701 1.1.2.1 cliff }
702 1.1.2.1 cliff
703 1.1.2.1 cliff static void
704 1.1.2.1 cliff rmixl_pcie_init(struct rmixl_pcie_softc *sc)
705 1.1.2.1 cliff {
706 1.1.2.18 matt pci_chipset_tag_t pc = sc->sc_pc;
707 1.1.2.1 cliff #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
708 1.1.2.1 cliff struct extent *ioext, *memext;
709 1.1.2.1 cliff #endif
710 1.1.2.1 cliff
711 1.1.2.1 cliff pc->pc_conf_v = (void *)sc;
712 1.1.2.1 cliff pc->pc_attach_hook = rmixl_pcie_attach_hook;
713 1.1.2.1 cliff pc->pc_bus_maxdevs = rmixl_pcie_bus_maxdevs;
714 1.1.2.1 cliff pc->pc_make_tag = rmixl_pcie_make_tag;
715 1.1.2.1 cliff pc->pc_decompose_tag = rmixl_pcie_decompose_tag;
716 1.1.2.1 cliff pc->pc_conf_read = rmixl_pcie_conf_read;
717 1.1.2.1 cliff pc->pc_conf_write = rmixl_pcie_conf_write;
718 1.1.2.18 matt #ifdef __PCI_DEV_FUNCORDER
719 1.1.2.18 matt pc->pc_dev_funcorder = rmixl_pcie_dev_funcorder;
720 1.1.2.18 matt #endif
721 1.1.2.1 cliff
722 1.1.2.1 cliff pc->pc_intr_v = (void *)sc;
723 1.1.2.1 cliff pc->pc_intr_map = rmixl_pcie_intr_map;
724 1.1.2.1 cliff pc->pc_intr_string = rmixl_pcie_intr_string;
725 1.1.2.1 cliff pc->pc_intr_evcnt = rmixl_pcie_intr_evcnt;
726 1.1.2.1 cliff pc->pc_intr_establish = rmixl_pcie_intr_establish;
727 1.1.2.1 cliff pc->pc_intr_disestablish = rmixl_pcie_intr_disestablish;
728 1.1.2.1 cliff pc->pc_conf_interrupt = rmixl_conf_interrupt;
729 1.1.2.1 cliff
730 1.1.2.1 cliff #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
731 1.1.2.1 cliff /*
732 1.1.2.1 cliff * Configure the PCI bus.
733 1.1.2.1 cliff */
734 1.1.2.1 cliff struct rmixl_config *rcp = &rmixl_configuration;
735 1.1.2.1 cliff
736 1.1.2.18 matt aprint_normal_dev(sc->sc_dev, "configuring PCI bus\n");
737 1.1.2.1 cliff
738 1.1.2.1 cliff ioext = extent_create("pciio",
739 1.1.2.18 matt rcp->rc_pci_io.r_pbase,
740 1.1.2.18 matt rcp->rc_pci_io.r_pbase + rcp->rc_pci_io.r_size - 1,
741 1.1.2.1 cliff M_DEVBUF, NULL, 0, EX_NOWAIT);
742 1.1.2.1 cliff
743 1.1.2.1 cliff memext = extent_create("pcimem",
744 1.1.2.18 matt rcp->rc_pci_mem.r_pbase,
745 1.1.2.18 matt rcp->rc_pci_mem.r_pbase + rcp->rc_pci_mem.r_size - 1,
746 1.1.2.1 cliff M_DEVBUF, NULL, 0, EX_NOWAIT);
747 1.1.2.1 cliff
748 1.1.2.7 matt pci_configure_bus(pc, ioext, memext, NULL, 0,
749 1.1.2.7 matt mips_cache_info.mci_dcache_align);
750 1.1.2.1 cliff
751 1.1.2.1 cliff extent_destroy(ioext);
752 1.1.2.1 cliff extent_destroy(memext);
753 1.1.2.1 cliff #endif
754 1.1.2.1 cliff }
755 1.1.2.1 cliff
756 1.1.2.1 cliff static void
757 1.1.2.1 cliff rmixl_pcie_init_ecfg(struct rmixl_pcie_softc *sc)
758 1.1.2.1 cliff {
759 1.1.2.1 cliff void *v;
760 1.1.2.1 cliff pcitag_t tag;
761 1.1.2.1 cliff pcireg_t r;
762 1.1.2.1 cliff
763 1.1.2.1 cliff v = sc;
764 1.1.2.1 cliff tag = rmixl_pcie_make_tag(v, 0, 0, 0);
765 1.1.2.1 cliff
766 1.1.2.1 cliff #ifdef PCI_DEBUG
767 1.1.2.1 cliff int i, offset;
768 1.1.2.1 cliff static const int offtab[] =
769 1.1.2.1 cliff { 0, 4, 8, 0xc, 0x10, 0x14, 0x18, 0x1c,
770 1.1.2.1 cliff 0x2c, 0x30, 0x34 };
771 1.1.2.1 cliff for (i=0; i < sizeof(offtab)/sizeof(offtab[0]); i++) {
772 1.1.2.1 cliff offset = 0x100 + offtab[i];
773 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, offset);
774 1.1.2.1 cliff printf("%s: %#x: %#x\n", __func__, offset, r);
775 1.1.2.1 cliff }
776 1.1.2.1 cliff #endif
777 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, 0x100);
778 1.1.2.1 cliff if (r == -1)
779 1.1.2.1 cliff return; /* cannot access */
780 1.1.2.1 cliff
781 1.1.2.1 cliff /* check pre-existing uncorrectable errs */
782 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_UESR);
783 1.1.2.1 cliff r &= ~PCIE_ECFG_UExR_RESV;
784 1.1.2.1 cliff if (r != 0)
785 1.1.2.1 cliff panic("%s: Uncorrectable Error Status: %#x\n",
786 1.1.2.1 cliff __func__, r);
787 1.1.2.1 cliff
788 1.1.2.1 cliff /* unmask all uncorrectable errs */
789 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_UEMR);
790 1.1.2.1 cliff r &= ~PCIE_ECFG_UExR_RESV;
791 1.1.2.1 cliff rmixl_pcie_conf_write(v, tag, RMIXL_PCIE_ECFG_UEMR, r);
792 1.1.2.1 cliff
793 1.1.2.1 cliff /* ensure default uncorrectable err severity confniguration */
794 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_UEVR);
795 1.1.2.1 cliff r &= ~PCIE_ECFG_UExR_RESV;
796 1.1.2.1 cliff r |= PCIE_ECFG_UEVR_DFLT;
797 1.1.2.1 cliff rmixl_pcie_conf_write(v, tag, RMIXL_PCIE_ECFG_UEVR, r);
798 1.1.2.1 cliff
799 1.1.2.1 cliff /* check pre-existing correctable errs */
800 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_CESR);
801 1.1.2.1 cliff r &= ~PCIE_ECFG_CExR_RESV;
802 1.1.2.1 cliff #ifdef DIAGNOSTIC
803 1.1.2.1 cliff if (r != 0)
804 1.1.2.1 cliff aprint_normal("%s: Correctable Error Status: %#x\n",
805 1.1.2.1 cliff device_xname(sc->sc_dev), r);
806 1.1.2.1 cliff #endif
807 1.1.2.1 cliff
808 1.1.2.1 cliff /* unmask all correctable errs */
809 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_CEMR);
810 1.1.2.1 cliff r &= ~PCIE_ECFG_CExR_RESV;
811 1.1.2.1 cliff rmixl_pcie_conf_write(v, tag, RMIXL_PCIE_ECFG_UEMR, r);
812 1.1.2.1 cliff
813 1.1.2.1 cliff /* check pre-existing Root Error Status */
814 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, RMIXL_PCIE_ECFG_RESR);
815 1.1.2.1 cliff r &= ~PCIE_ECFG_RESR_RESV;
816 1.1.2.1 cliff if (r != 0)
817 1.1.2.1 cliff panic("%s: Root Error Status: %#x\n", __func__, r);
818 1.1.2.1 cliff /* XXX TMP FIXME */
819 1.1.2.1 cliff
820 1.1.2.1 cliff /* enable all Root errs */
821 1.1.2.1 cliff r = (pcireg_t)(~PCIE_ECFG_RECR_RESV);
822 1.1.2.1 cliff rmixl_pcie_conf_write(v, tag, RMIXL_PCIE_ECFG_RECR, r);
823 1.1.2.1 cliff
824 1.1.2.8 cliff /*
825 1.1.2.8 cliff * establish ISR for PCIE Fatal Error interrupt
826 1.1.2.8 cliff * - for XLS4xxLite, XLS2xx, XLS1xx only
827 1.1.2.8 cliff */
828 1.1.2.8 cliff switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
829 1.1.2.8 cliff case MIPS_XLS104:
830 1.1.2.8 cliff case MIPS_XLS108:
831 1.1.2.8 cliff case MIPS_XLS204:
832 1.1.2.8 cliff case MIPS_XLS208:
833 1.1.2.8 cliff case MIPS_XLS404LITE:
834 1.1.2.8 cliff case MIPS_XLS408LITE:
835 1.1.2.20 matt sc->sc_fatal_ih = rmixl_intr_establish(29, IPL_HIGH,
836 1.1.2.20 matt IST_LEVEL_HIGH, rmixl_pcie_error_intr, v, false);
837 1.1.2.8 cliff break;
838 1.1.2.8 cliff default:
839 1.1.2.8 cliff break;
840 1.1.2.1 cliff }
841 1.1.2.8 cliff
842 1.1.2.1 cliff #if defined(DEBUG) || defined(DDB)
843 1.1.2.1 cliff rmixl_pcie_v = v;
844 1.1.2.1 cliff #endif
845 1.1.2.1 cliff }
846 1.1.2.1 cliff
847 1.1.2.1 cliff void
848 1.1.2.1 cliff rmixl_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
849 1.1.2.1 cliff {
850 1.1.2.1 cliff DPRINTF(("%s: %p, %d, %d, %d, %d, %p\n",
851 1.1.2.1 cliff __func__, v, bus, dev, ipin, swiz, iline));
852 1.1.2.1 cliff }
853 1.1.2.1 cliff
854 1.1.2.1 cliff void
855 1.1.2.1 cliff rmixl_pcie_attach_hook(struct device *parent, struct device *self,
856 1.1.2.1 cliff struct pcibus_attach_args *pba)
857 1.1.2.1 cliff {
858 1.1.2.1 cliff DPRINTF(("%s: pba_bus %d, pba_bridgetag %p, pc_conf_v %p\n",
859 1.1.2.1 cliff __func__, pba->pba_bus, pba->pba_bridgetag,
860 1.1.2.1 cliff pba->pba_pc->pc_conf_v));
861 1.1.2.1 cliff }
862 1.1.2.1 cliff
863 1.1.2.1 cliff int
864 1.1.2.1 cliff rmixl_pcie_bus_maxdevs(void *v, int busno)
865 1.1.2.1 cliff {
866 1.1.2.1 cliff return (32); /* XXX depends on the family of XLS SoC */
867 1.1.2.1 cliff }
868 1.1.2.1 cliff
869 1.1.2.1 cliff /*
870 1.1.2.18 matt * rmixl_tag_ecfg_to_cfg - convert ecfg address to cfg (generic tag) address
871 1.1.2.3 cliff *
872 1.1.2.18 matt * ecfg cfg
873 1.1.2.18 matt * 39:29 39:25 (reserved)
874 1.1.2.18 matt * 28 24 Swap (0=little, 1=big endian)
875 1.1.2.18 matt * 27:20 23:16 Bus number
876 1.1.2.18 matt * 19:15 15:11 Device number
877 1.1.2.18 matt * 14:12 10:8 Function number
878 1.1.2.18 matt * 11:0 7:0 Register number
879 1.1.2.3 cliff */
880 1.1.2.18 matt static inline pcitag_t
881 1.1.2.18 matt rmixl_tag_ecfg_to_cfg(pcitag_t tag)
882 1.1.2.3 cliff {
883 1.1.2.18 matt KASSERT(_RMIXL_PCITAG_OFFSET(tag) == 0);
884 1.1.2.18 matt return tag >> 4;
885 1.1.2.3 cliff }
886 1.1.2.3 cliff
887 1.1.2.3 cliff /*
888 1.1.2.18 matt * XLS pci (extended) tag is a 40 bit address composed thusly:
889 1.1.2.18 matt * 39:29 (reserved)
890 1.1.2.18 matt * 28 Swap (0=little, 1=big endian)
891 1.1.2.18 matt * 27:20 Bus number
892 1.1.2.18 matt * 19:15 Device number
893 1.1.2.18 matt * 14:12 Function number
894 1.1.2.18 matt * 11:0 Register number
895 1.1.2.3 cliff *
896 1.1.2.3 cliff * Note: this is the "native" composition for addressing CFG space, but not for ECFG space.
897 1.1.2.1 cliff */
898 1.1.2.1 cliff pcitag_t
899 1.1.2.3 cliff rmixl_pcie_make_tag(void *v, int bus, int dev, int fun)
900 1.1.2.1 cliff {
901 1.1.2.18 matt return _RMIXL_PCITAG(bus, dev, fun);
902 1.1.2.1 cliff }
903 1.1.2.1 cliff
904 1.1.2.1 cliff void
905 1.1.2.1 cliff rmixl_pcie_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
906 1.1.2.1 cliff {
907 1.1.2.1 cliff if (bp != NULL)
908 1.1.2.18 matt *bp = _RMIXL_PCITAG_BUS(tag);
909 1.1.2.1 cliff if (dp != NULL)
910 1.1.2.18 matt *dp = _RMIXL_PCITAG_DEV(tag);
911 1.1.2.1 cliff if (fp != NULL)
912 1.1.2.18 matt *fp = _RMIXL_PCITAG_FUNC(tag);
913 1.1.2.1 cliff }
914 1.1.2.1 cliff
915 1.1.2.1 cliff void
916 1.1.2.1 cliff rmixl_pcie_tag_print(const char *restrict s, void *v, pcitag_t tag, int offset,
917 1.1.2.1 cliff vaddr_t va, u_long r)
918 1.1.2.1 cliff {
919 1.1.2.1 cliff int bus, dev, fun;
920 1.1.2.1 cliff
921 1.1.2.1 cliff rmixl_pcie_decompose_tag(v, tag, &bus, &dev, &fun);
922 1.1.2.18 matt printf("%s: %lx: %d/%d/%d/%d - %#" PRIxVADDR ":%#lx\n",
923 1.1.2.18 matt s, tag, bus, dev, fun, offset, va, r);
924 1.1.2.1 cliff }
925 1.1.2.1 cliff
926 1.1.2.3 cliff static int
927 1.1.2.3 cliff rmixl_pcie_conf_setup(struct rmixl_pcie_softc *sc,
928 1.1.2.3 cliff pcitag_t tag, int *offp, bus_space_tag_t *bstp,
929 1.1.2.3 cliff bus_space_handle_t *bshp)
930 1.1.2.3 cliff {
931 1.1.2.3 cliff bus_space_tag_t bst;
932 1.1.2.3 cliff bus_space_handle_t bsh;
933 1.1.2.3 cliff
934 1.1.2.18 matt #ifdef _LP64
935 1.1.2.18 matt bst = sc->sc_pci_ecfg_memt;
936 1.1.2.18 matt bus_space_subregion(bst, sc->sc_pci_ecfg_memh, tag, 0x1000, &bsh);
937 1.1.2.18 matt #else
938 1.1.2.3 cliff /*
939 1.1.2.3 cliff * bus space depends on offset
940 1.1.2.3 cliff */
941 1.1.2.3 cliff if ((*offp >= 0) && (*offp < 0x100)) {
942 1.1.2.11 cliff bst = sc->sc_pci_cfg_memt;
943 1.1.2.18 matt tag = rmixl_tag_ecfg_to_cfg(tag); /* convert to CFG format */
944 1.1.2.18 matt bus_space_subregion(bst, sc->sc_pci_cfg_memh, tag, 0x100, &bsh);
945 1.1.2.3 cliff } else if ((*offp >= 0x100) && (*offp <= 0x700)) {
946 1.1.2.18 matt static bus_space_handle_t ecfg_bsh;
947 1.1.2.18 matt static bus_addr_t ecfg_oba = -1;
948 1.1.2.18 matt const pcitag_t mask = __BITS(14,0); /* all fnctns of a device */
949 1.1.2.11 cliff bst = sc->sc_pci_ecfg_memt;
950 1.1.2.18 matt const bus_addr_t ba = (tag & ~mask);
951 1.1.2.3 cliff *offp += (tag & mask);
952 1.1.2.3 cliff if (ba != ecfg_oba) {
953 1.1.2.18 matt bus_size_t size = (bus_size_t)(mask + 1);
954 1.1.2.3 cliff if (ecfg_oba != -1)
955 1.1.2.3 cliff bus_space_unmap(bst, ecfg_bsh, size);
956 1.1.2.18 matt int err = bus_space_map(bst, ba, size, 0, &ecfg_bsh);
957 1.1.2.3 cliff if (err != 0) {
958 1.1.2.18 matt ecfg_oba = -1;
959 1.1.2.5 cliff #ifdef DEBUG
960 1.1.2.18 matt panic("%s: ECFG: "
961 1.1.2.18 matt "bus_space_map(%p, %#"PRIxBUSADDR
962 1.1.2.18 matt ", %#"PRIxBUSSIZE", 0, %p): %d",
963 1.1.2.18 matt __func__, bst, ba, size, &ecfg_bsh, err);
964 1.1.2.3 cliff #endif
965 1.1.2.3 cliff return -1;
966 1.1.2.3 cliff }
967 1.1.2.3 cliff ecfg_oba = ba;
968 1.1.2.3 cliff }
969 1.1.2.3 cliff bsh = ecfg_bsh;
970 1.1.2.3 cliff } else {
971 1.1.2.3 cliff #ifdef DEBUG
972 1.1.2.3 cliff panic("%s: offset %#x: unknown", __func__, *offp);
973 1.1.2.3 cliff #endif
974 1.1.2.3 cliff return -1;
975 1.1.2.3 cliff }
976 1.1.2.18 matt #endif /* _LP64 */
977 1.1.2.3 cliff
978 1.1.2.3 cliff *bstp = bst;
979 1.1.2.3 cliff *bshp = bsh;
980 1.1.2.3 cliff
981 1.1.2.3 cliff return 0;
982 1.1.2.3 cliff }
983 1.1.2.3 cliff
984 1.1.2.1 cliff pcireg_t
985 1.1.2.1 cliff rmixl_pcie_conf_read(void *v, pcitag_t tag, int offset)
986 1.1.2.1 cliff {
987 1.1.2.1 cliff struct rmixl_pcie_softc *sc = v;
988 1.1.2.3 cliff static bus_space_handle_t bsh;
989 1.1.2.3 cliff bus_space_tag_t bst;
990 1.1.2.1 cliff pcireg_t rv;
991 1.1.2.1 cliff uint64_t cfg0;
992 1.1.2.1 cliff
993 1.1.2.16 cliff mutex_enter(&sc->sc_mutex);
994 1.1.2.1 cliff
995 1.1.2.3 cliff if (rmixl_pcie_conf_setup(sc, tag, &offset, &bst, &bsh) == 0) {
996 1.1.2.3 cliff cfg0 = rmixl_cache_err_dis();
997 1.1.2.3 cliff rv = bus_space_read_4(bst, bsh, (bus_size_t)offset);
998 1.1.2.3 cliff if (rmixl_cache_err_check() != 0) {
999 1.1.2.1 cliff #ifdef DIAGNOSTIC
1000 1.1.2.3 cliff int bus, dev, fun;
1001 1.1.2.1 cliff
1002 1.1.2.3 cliff rmixl_pcie_decompose_tag(v, tag, &bus, &dev, &fun);
1003 1.1.2.3 cliff printf("%s: %d/%d/%d, offset %#x: bad address\n",
1004 1.1.2.3 cliff __func__, bus, dev, fun, offset);
1005 1.1.2.1 cliff #endif
1006 1.1.2.3 cliff rv = (pcireg_t) -1;
1007 1.1.2.3 cliff }
1008 1.1.2.3 cliff rmixl_cache_err_restore(cfg0);
1009 1.1.2.3 cliff } else {
1010 1.1.2.3 cliff rv = -1;
1011 1.1.2.1 cliff }
1012 1.1.2.1 cliff
1013 1.1.2.16 cliff mutex_exit(&sc->sc_mutex);
1014 1.1.2.16 cliff
1015 1.1.2.1 cliff return rv;
1016 1.1.2.1 cliff }
1017 1.1.2.1 cliff
1018 1.1.2.1 cliff void
1019 1.1.2.1 cliff rmixl_pcie_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
1020 1.1.2.1 cliff {
1021 1.1.2.1 cliff struct rmixl_pcie_softc *sc = v;
1022 1.1.2.3 cliff static bus_space_handle_t bsh;
1023 1.1.2.3 cliff bus_space_tag_t bst;
1024 1.1.2.1 cliff uint64_t cfg0;
1025 1.1.2.1 cliff
1026 1.1.2.16 cliff mutex_enter(&sc->sc_mutex);
1027 1.1.2.1 cliff
1028 1.1.2.3 cliff if (rmixl_pcie_conf_setup(sc, tag, &offset, &bst, &bsh) == 0) {
1029 1.1.2.3 cliff cfg0 = rmixl_cache_err_dis();
1030 1.1.2.3 cliff bus_space_write_4(bst, bsh, (bus_size_t)offset, val);
1031 1.1.2.3 cliff if (rmixl_cache_err_check() != 0) {
1032 1.1.2.1 cliff #ifdef DIAGNOSTIC
1033 1.1.2.3 cliff int bus, dev, fun;
1034 1.1.2.1 cliff
1035 1.1.2.3 cliff rmixl_pcie_decompose_tag(v, tag, &bus, &dev, &fun);
1036 1.1.2.3 cliff printf("%s: %d/%d/%d, offset %#x: bad address\n",
1037 1.1.2.3 cliff __func__, bus, dev, fun, offset);
1038 1.1.2.1 cliff #endif
1039 1.1.2.3 cliff }
1040 1.1.2.3 cliff rmixl_cache_err_restore(cfg0);
1041 1.1.2.3 cliff }
1042 1.1.2.1 cliff
1043 1.1.2.16 cliff mutex_exit(&sc->sc_mutex);
1044 1.1.2.1 cliff }
1045 1.1.2.1 cliff
1046 1.1.2.18 matt #ifdef __PCI_DEV_FUNCORDER
1047 1.1.2.18 matt bool
1048 1.1.2.18 matt rmixl_pcie_dev_funcorder(void *v, int bus, int device, int nfunctions,
1049 1.1.2.18 matt char *funcs)
1050 1.1.2.18 matt {
1051 1.1.2.18 matt return false;
1052 1.1.2.18 matt }
1053 1.1.2.18 matt #endif
1054 1.1.2.18 matt
1055 1.1.2.1 cliff int
1056 1.1.2.1 cliff rmixl_pcie_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *pih)
1057 1.1.2.1 cliff {
1058 1.1.2.14 matt int device;
1059 1.1.2.8 cliff u_int link;
1060 1.1.2.1 cliff u_int irq;
1061 1.1.2.1 cliff
1062 1.1.2.14 matt /*
1063 1.1.2.14 matt * The bus is unimportant since it can change depending on the
1064 1.1.2.14 matt * configuration. We are tied to device # of PCIe bridge we are
1065 1.1.2.14 matt * ultimately attached to.
1066 1.1.2.14 matt */
1067 1.1.2.14 matt pci_decompose_tag(pa->pa_pc, pa->pa_intrtag,
1068 1.1.2.14 matt NULL, &device, NULL);
1069 1.1.2.14 matt
1070 1.1.2.1 cliff #ifdef DEBUG
1071 1.1.2.1 cliff DPRINTF(("%s: ps_bus %d, pa_intrswiz %#x, pa_intrtag %#lx,"
1072 1.1.2.1 cliff " pa_intrpin %d, pa_intrline %d, pa_rawintrpin %d\n",
1073 1.1.2.1 cliff __func__, pa->pa_bus, pa->pa_intrswiz, pa->pa_intrtag,
1074 1.1.2.1 cliff pa->pa_intrpin, pa->pa_intrline, pa->pa_rawintrpin));
1075 1.1.2.1 cliff #endif
1076 1.1.2.1 cliff
1077 1.1.2.1 cliff /*
1078 1.1.2.8 cliff * PCIe Link INT irq assignment is cpu implementation specific
1079 1.1.2.1 cliff */
1080 1.1.2.7 matt switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
1081 1.1.2.8 cliff case MIPS_XLS104:
1082 1.1.2.8 cliff case MIPS_XLS108:
1083 1.1.2.8 cliff case MIPS_XLS404LITE:
1084 1.1.2.1 cliff case MIPS_XLS408LITE:
1085 1.1.2.14 matt if (device > 1)
1086 1.1.2.14 matt panic("%s: bad bus %d", __func__, device);
1087 1.1.2.14 matt link = device;
1088 1.1.2.14 matt irq = device + 26;
1089 1.1.2.1 cliff break;
1090 1.1.2.13 cliff case MIPS_XLS204:
1091 1.1.2.14 matt case MIPS_XLS208: {
1092 1.1.2.14 matt if (device > 3)
1093 1.1.2.14 matt panic("%s: bad bus %d", __func__, device);
1094 1.1.2.14 matt link = device;
1095 1.1.2.14 matt irq = device + (device & 2 ? 21 : 26);
1096 1.1.2.13 cliff break;
1097 1.1.2.14 matt }
1098 1.1.2.8 cliff case MIPS_XLS404:
1099 1.1.2.8 cliff case MIPS_XLS408:
1100 1.1.2.1 cliff case MIPS_XLS416:
1101 1.1.2.8 cliff case MIPS_XLS608:
1102 1.1.2.1 cliff case MIPS_XLS616:
1103 1.1.2.14 matt if (device > 3)
1104 1.1.2.14 matt panic("%s: bad bus %d", __func__, device);
1105 1.1.2.14 matt link = device;
1106 1.1.2.14 matt irq = device + 26;
1107 1.1.2.1 cliff break;
1108 1.1.2.1 cliff default:
1109 1.1.2.1 cliff panic("%s: cpu IMPL %#x not supported\n",
1110 1.1.2.14 matt __func__, MIPS_PRID_IMPL(mips_options.mips_cpu_id));
1111 1.1.2.1 cliff }
1112 1.1.2.1 cliff
1113 1.1.2.8 cliff if (pa->pa_intrpin != PCI_INTERRUPT_PIN_NONE)
1114 1.1.2.8 cliff *pih = rmixl_pcie_make_pih(link, pa->pa_intrpin - 1, irq);
1115 1.1.2.8 cliff else
1116 1.1.2.8 cliff *pih = ~0;
1117 1.1.2.1 cliff
1118 1.1.2.1 cliff return 0;
1119 1.1.2.1 cliff }
1120 1.1.2.1 cliff
1121 1.1.2.1 cliff const char *
1122 1.1.2.1 cliff rmixl_pcie_intr_string(void *v, pci_intr_handle_t pih)
1123 1.1.2.1 cliff {
1124 1.1.2.1 cliff const char *name = "(illegal)";
1125 1.1.2.11 cliff u_int link, bitno, irq;
1126 1.1.2.11 cliff
1127 1.1.2.11 cliff rmixl_pcie_decompose_pih(pih, &link, &bitno, &irq);
1128 1.1.2.1 cliff
1129 1.1.2.7 matt switch (MIPS_PRID_IMPL(mips_options.mips_cpu_id)) {
1130 1.1.2.8 cliff case MIPS_XLS104:
1131 1.1.2.8 cliff case MIPS_XLS108:
1132 1.1.2.8 cliff case MIPS_XLS404LITE:
1133 1.1.2.1 cliff case MIPS_XLS408LITE:
1134 1.1.2.1 cliff switch (irq) {
1135 1.1.2.1 cliff case 26:
1136 1.1.2.1 cliff case 27:
1137 1.1.2.18 matt name = rmixl_irt_string(irq);
1138 1.1.2.1 cliff break;
1139 1.1.2.1 cliff }
1140 1.1.2.1 cliff break;
1141 1.1.2.13 cliff case MIPS_XLS204:
1142 1.1.2.13 cliff case MIPS_XLS208:
1143 1.1.2.13 cliff switch (irq) {
1144 1.1.2.13 cliff case 23:
1145 1.1.2.13 cliff case 24:
1146 1.1.2.13 cliff case 26:
1147 1.1.2.13 cliff case 27:
1148 1.1.2.18 matt name = rmixl_irt_string(irq);
1149 1.1.2.13 cliff break;
1150 1.1.2.13 cliff }
1151 1.1.2.13 cliff break;
1152 1.1.2.8 cliff case MIPS_XLS404:
1153 1.1.2.8 cliff case MIPS_XLS408:
1154 1.1.2.8 cliff case MIPS_XLS416:
1155 1.1.2.8 cliff case MIPS_XLS608:
1156 1.1.2.1 cliff case MIPS_XLS616:
1157 1.1.2.1 cliff switch (irq) {
1158 1.1.2.1 cliff case 26:
1159 1.1.2.1 cliff case 27:
1160 1.1.2.1 cliff case 28:
1161 1.1.2.1 cliff case 29:
1162 1.1.2.18 matt name = rmixl_irt_string(irq);
1163 1.1.2.1 cliff break;
1164 1.1.2.1 cliff }
1165 1.1.2.1 cliff break;
1166 1.1.2.8 cliff default:
1167 1.1.2.8 cliff panic("%s: cpu IMPL %#x not supported\n",
1168 1.1.2.8 cliff __func__, MIPS_PRID_IMPL(mips_options.mips_cpu_id));
1169 1.1.2.1 cliff }
1170 1.1.2.1 cliff
1171 1.1.2.1 cliff return name;
1172 1.1.2.1 cliff }
1173 1.1.2.1 cliff
1174 1.1.2.1 cliff const struct evcnt *
1175 1.1.2.1 cliff rmixl_pcie_intr_evcnt(void *v, pci_intr_handle_t pih)
1176 1.1.2.1 cliff {
1177 1.1.2.1 cliff return NULL;
1178 1.1.2.1 cliff }
1179 1.1.2.1 cliff
1180 1.1.2.8 cliff static pci_intr_handle_t
1181 1.1.2.8 cliff rmixl_pcie_make_pih(u_int link, u_int bitno, u_int irq)
1182 1.1.2.1 cliff {
1183 1.1.2.8 cliff pci_intr_handle_t pih;
1184 1.1.2.8 cliff
1185 1.1.2.11 cliff KASSERT(link < RMIXL_PCIE_NLINKS_MAX);
1186 1.1.2.11 cliff KASSERT(bitno < 64);
1187 1.1.2.11 cliff KASSERT(irq < 32);
1188 1.1.2.8 cliff
1189 1.1.2.8 cliff pih = (irq << 10);
1190 1.1.2.8 cliff pih |= (bitno << 4);
1191 1.1.2.8 cliff pih |= link;
1192 1.1.2.8 cliff
1193 1.1.2.8 cliff return pih;
1194 1.1.2.1 cliff }
1195 1.1.2.1 cliff
1196 1.1.2.8 cliff static void
1197 1.1.2.8 cliff rmixl_pcie_decompose_pih(pci_intr_handle_t pih, u_int *link, u_int *bitno, u_int *irq)
1198 1.1.2.8 cliff {
1199 1.1.2.8 cliff *link = (u_int)(pih & 0xf);
1200 1.1.2.11 cliff *bitno = (u_int)((pih >> 4) & 0x3f);
1201 1.1.2.8 cliff *irq = (u_int)(pih >> 10);
1202 1.1.2.8 cliff
1203 1.1.2.11 cliff KASSERT(*link < RMIXL_PCIE_NLINKS_MAX);
1204 1.1.2.11 cliff KASSERT(*bitno < 64);
1205 1.1.2.11 cliff KASSERT(*irq < 32);
1206 1.1.2.8 cliff }
1207 1.1.2.8 cliff
1208 1.1.2.8 cliff static void
1209 1.1.2.8 cliff rmixl_pcie_intr_disestablish(void *v, void *ih)
1210 1.1.2.8 cliff {
1211 1.1.2.8 cliff rmixl_pcie_softc_t *sc = v;
1212 1.1.2.8 cliff rmixl_pcie_link_dispatch_t *dip = ih;
1213 1.1.2.16 cliff rmixl_pcie_link_intr_t *lip = sc->sc_link_intr[dip->link];
1214 1.1.2.8 cliff uint32_t r;
1215 1.1.2.8 cliff uint32_t bit;
1216 1.1.2.8 cliff u_int offset;
1217 1.1.2.8 cliff u_int other;
1218 1.1.2.16 cliff bool busy;
1219 1.1.2.8 cliff
1220 1.1.2.9 cliff DPRINTF(("%s: link=%d pin=%d irq=%d\n",
1221 1.1.2.9 cliff __func__, dip->link, dip->bitno + 1, dip->irq));
1222 1.1.2.8 cliff
1223 1.1.2.16 cliff mutex_enter(&sc->sc_mutex);
1224 1.1.2.8 cliff
1225 1.1.2.16 cliff dip->func = NULL; /* mark unused, prevent further dispatch */
1226 1.1.2.8 cliff
1227 1.1.2.8 cliff /*
1228 1.1.2.16 cliff * if no other dispatch handle is using this interrupt,
1229 1.1.2.16 cliff * we can disable it
1230 1.1.2.8 cliff */
1231 1.1.2.16 cliff busy = false;
1232 1.1.2.16 cliff for (int i=0; i < lip->dispatch_count; i++) {
1233 1.1.2.16 cliff rmixl_pcie_link_dispatch_t *d = &lip->dispatch_data[i];
1234 1.1.2.16 cliff if (d == dip)
1235 1.1.2.16 cliff continue;
1236 1.1.2.16 cliff if (d->bitno == dip->bitno) {
1237 1.1.2.16 cliff busy = true;
1238 1.1.2.16 cliff break;
1239 1.1.2.8 cliff }
1240 1.1.2.8 cliff }
1241 1.1.2.16 cliff if (! busy) {
1242 1.1.2.16 cliff if (dip->bitno < 32) {
1243 1.1.2.16 cliff bit = 1 << dip->bitno;
1244 1.1.2.16 cliff offset = int_enb_offset[dip->link].r0;
1245 1.1.2.16 cliff other = int_enb_offset[dip->link].r1;
1246 1.1.2.16 cliff } else {
1247 1.1.2.16 cliff bit = 1 << (dip->bitno - 32);
1248 1.1.2.16 cliff offset = int_enb_offset[dip->link].r1;
1249 1.1.2.16 cliff other = int_enb_offset[dip->link].r0;
1250 1.1.2.16 cliff }
1251 1.1.2.16 cliff
1252 1.1.2.16 cliff /* disable this interrupt in the PCIe bridge */
1253 1.1.2.16 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_LE + offset);
1254 1.1.2.16 cliff r &= ~bit;
1255 1.1.2.16 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_LE + offset, r);
1256 1.1.2.16 cliff
1257 1.1.2.16 cliff /*
1258 1.1.2.16 cliff * if both ENABLE0 and ENABLE1 are 0
1259 1.1.2.16 cliff * disable the link interrupt
1260 1.1.2.16 cliff */
1261 1.1.2.16 cliff if (r == 0) {
1262 1.1.2.16 cliff /* check the other reg */
1263 1.1.2.16 cliff if (RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_LE + other) == 0) {
1264 1.1.2.16 cliff DPRINTF(("%s: disable link %d\n", __func__, lip->link));
1265 1.1.2.16 cliff
1266 1.1.2.16 cliff /* tear down interrupt on this link */
1267 1.1.2.16 cliff rmixl_intr_disestablish(lip->ih);
1268 1.1.2.8 cliff
1269 1.1.2.16 cliff /* commit NULL interrupt set */
1270 1.1.2.16 cliff sc->sc_link_intr[dip->link] = NULL;
1271 1.1.2.8 cliff
1272 1.1.2.16 cliff /* schedule delayed free of the old link interrupt set */
1273 1.1.2.16 cliff rmixl_pcie_lip_free_callout(lip);
1274 1.1.2.16 cliff }
1275 1.1.2.16 cliff }
1276 1.1.2.16 cliff }
1277 1.1.2.8 cliff
1278 1.1.2.16 cliff mutex_exit(&sc->sc_mutex);
1279 1.1.2.8 cliff }
1280 1.1.2.8 cliff
1281 1.1.2.8 cliff static void *
1282 1.1.2.8 cliff rmixl_pcie_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
1283 1.1.2.8 cliff int (*func)(void *), void *arg)
1284 1.1.2.8 cliff {
1285 1.1.2.8 cliff rmixl_pcie_softc_t *sc = v;
1286 1.1.2.8 cliff u_int link, bitno, irq;
1287 1.1.2.8 cliff uint32_t r;
1288 1.1.2.8 cliff rmixl_pcie_link_intr_t *lip;
1289 1.1.2.15 rmind rmixl_pcie_link_dispatch_t *dip = NULL;
1290 1.1.2.8 cliff uint32_t bit;
1291 1.1.2.8 cliff u_int offset;
1292 1.1.2.8 cliff
1293 1.1.2.8 cliff if (pih == ~0) {
1294 1.1.2.8 cliff DPRINTF(("%s: bad pih=%#lx, implies PCI_INTERRUPT_PIN_NONE\n",
1295 1.1.2.8 cliff __func__, pih));
1296 1.1.2.8 cliff return NULL;
1297 1.1.2.8 cliff }
1298 1.1.2.8 cliff
1299 1.1.2.8 cliff rmixl_pcie_decompose_pih(pih, &link, &bitno, &irq);
1300 1.1.2.16 cliff DPRINTF(("%s: link=%d pin=%d irq=%d\n",
1301 1.1.2.16 cliff __func__, link, bitno + 1, irq));
1302 1.1.2.8 cliff
1303 1.1.2.16 cliff mutex_enter(&sc->sc_mutex);
1304 1.1.2.8 cliff
1305 1.1.2.16 cliff lip = rmixl_pcie_lip_add_1(sc, link, irq, ipl);
1306 1.1.2.16 cliff if (lip == NULL)
1307 1.1.2.16 cliff return NULL;
1308 1.1.2.8 cliff
1309 1.1.2.8 cliff /*
1310 1.1.2.16 cliff * initializae our new interrupt, the last element in dispatch_data[]
1311 1.1.2.8 cliff */
1312 1.1.2.16 cliff dip = &lip->dispatch_data[lip->dispatch_count - 1];
1313 1.1.2.8 cliff dip->link = link;
1314 1.1.2.8 cliff dip->bitno = bitno;
1315 1.1.2.8 cliff dip->irq = irq;
1316 1.1.2.8 cliff dip->func = func;
1317 1.1.2.8 cliff dip->arg = arg;
1318 1.1.2.16 cliff dip->counts = RMIXL_PCIE_EVCNT(sc, link, bitno, 0);
1319 1.1.2.8 cliff
1320 1.1.2.8 cliff if (bitno < 32) {
1321 1.1.2.8 cliff offset = int_enb_offset[link].r0;
1322 1.1.2.8 cliff bit = 1 << bitno;
1323 1.1.2.8 cliff } else {
1324 1.1.2.8 cliff offset = int_enb_offset[link].r1;
1325 1.1.2.8 cliff bit = 1 << (bitno - 32);
1326 1.1.2.8 cliff }
1327 1.1.2.8 cliff
1328 1.1.2.16 cliff /* commit the new link interrupt set */
1329 1.1.2.16 cliff sc->sc_link_intr[link] = lip;
1330 1.1.2.16 cliff
1331 1.1.2.8 cliff /* enable this interrupt in the PCIe bridge */
1332 1.1.2.8 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_LE + offset);
1333 1.1.2.8 cliff r |= bit;
1334 1.1.2.8 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_PCIE_LE + offset, r);
1335 1.1.2.8 cliff
1336 1.1.2.16 cliff mutex_exit(&sc->sc_mutex);
1337 1.1.2.16 cliff return dip;
1338 1.1.2.16 cliff }
1339 1.1.2.16 cliff
1340 1.1.2.16 cliff rmixl_pcie_link_intr_t *
1341 1.1.2.16 cliff rmixl_pcie_lip_add_1(rmixl_pcie_softc_t *sc, u_int link, int irq, int ipl)
1342 1.1.2.16 cliff {
1343 1.1.2.16 cliff rmixl_pcie_link_intr_t *lip_old = sc->sc_link_intr[link];
1344 1.1.2.16 cliff rmixl_pcie_link_intr_t *lip_new;
1345 1.1.2.16 cliff u_int dispatch_count;
1346 1.1.2.16 cliff size_t size;
1347 1.1.2.16 cliff
1348 1.1.2.16 cliff dispatch_count = 1;
1349 1.1.2.16 cliff size = sizeof(rmixl_pcie_link_intr_t);
1350 1.1.2.16 cliff if (lip_old != NULL) {
1351 1.1.2.16 cliff /*
1352 1.1.2.16 cliff * count only those dispatch elements still in use
1353 1.1.2.16 cliff * unused ones will be pruned during copy
1354 1.1.2.16 cliff * i.e. we are "lazy" there is no rmixl_pcie_lip_sub_1
1355 1.1.2.16 cliff */
1356 1.1.2.16 cliff for (int i=0; i < lip_old->dispatch_count; i++) {
1357 1.1.2.16 cliff if (lip_old->dispatch_data[i].func != NULL) {
1358 1.1.2.16 cliff dispatch_count++;
1359 1.1.2.16 cliff size += sizeof(rmixl_pcie_link_intr_t);
1360 1.1.2.16 cliff }
1361 1.1.2.16 cliff }
1362 1.1.2.16 cliff }
1363 1.1.2.16 cliff
1364 1.1.2.16 cliff /*
1365 1.1.2.16 cliff * allocate and initialize link intr struct
1366 1.1.2.16 cliff * with one or more dispatch handles
1367 1.1.2.16 cliff */
1368 1.1.2.16 cliff lip_new = malloc(size, M_DEVBUF, M_NOWAIT);
1369 1.1.2.16 cliff if (lip_new == NULL) {
1370 1.1.2.16 cliff #ifdef DIAGNOSTIC
1371 1.1.2.16 cliff printf("%s: cannot malloc\n", __func__);
1372 1.1.2.16 cliff #endif
1373 1.1.2.16 cliff return NULL;
1374 1.1.2.16 cliff }
1375 1.1.2.16 cliff
1376 1.1.2.16 cliff if (lip_old == NULL) {
1377 1.1.2.16 cliff /* initialize the link interrupt struct */
1378 1.1.2.16 cliff lip_new->sc = sc;
1379 1.1.2.16 cliff lip_new->link = link;
1380 1.1.2.16 cliff lip_new->ipl = ipl;
1381 1.1.2.20 matt lip_new->ih = rmixl_intr_establish(irq, ipl, IST_LEVEL_HIGH,
1382 1.1.2.16 cliff rmixl_pcie_intr, lip_new, false);
1383 1.1.2.16 cliff if (lip_new->ih == NULL)
1384 1.1.2.11 cliff panic("%s: cannot establish irq %d", __func__, irq);
1385 1.1.2.16 cliff } else {
1386 1.1.2.16 cliff /*
1387 1.1.2.16 cliff * all intrs on a link get same ipl and sc
1388 1.1.2.16 cliff * first intr established sets the standard
1389 1.1.2.16 cliff */
1390 1.1.2.16 cliff KASSERT(sc == lip_old->sc);
1391 1.1.2.16 cliff if (sc != lip_old->sc) {
1392 1.1.2.16 cliff printf("%s: sc %p mismatch\n", __func__, sc);
1393 1.1.2.16 cliff free(lip_new, M_DEVBUF);
1394 1.1.2.16 cliff return NULL;
1395 1.1.2.16 cliff }
1396 1.1.2.16 cliff KASSERT (ipl == lip_old->ipl);
1397 1.1.2.16 cliff if (ipl != lip_old->ipl) {
1398 1.1.2.16 cliff printf("%s: ipl %d mismatch\n", __func__, ipl);
1399 1.1.2.16 cliff free(lip_new, M_DEVBUF);
1400 1.1.2.16 cliff return NULL;
1401 1.1.2.16 cliff }
1402 1.1.2.16 cliff /*
1403 1.1.2.16 cliff * copy lip_old to lip_new, skipping unused dispatch elemets
1404 1.1.2.16 cliff */
1405 1.1.2.16 cliff memcpy(lip_new, lip_old, sizeof(rmixl_pcie_link_intr_t));
1406 1.1.2.16 cliff for (int j=0, i=0; i < lip_old->dispatch_count; i++) {
1407 1.1.2.16 cliff if (lip_old->dispatch_data[i].func != NULL) {
1408 1.1.2.16 cliff memcpy(&lip_new->dispatch_data[j],
1409 1.1.2.16 cliff &lip_old->dispatch_data[i],
1410 1.1.2.16 cliff sizeof(rmixl_pcie_link_dispatch_t));
1411 1.1.2.16 cliff j++;
1412 1.1.2.16 cliff }
1413 1.1.2.16 cliff }
1414 1.1.2.8 cliff
1415 1.1.2.16 cliff /*
1416 1.1.2.16 cliff * schedule delayed free of old link interrupt set
1417 1.1.2.16 cliff */
1418 1.1.2.16 cliff rmixl_pcie_lip_free_callout(lip_old);
1419 1.1.2.8 cliff }
1420 1.1.2.16 cliff lip_new->dispatch_count = dispatch_count;
1421 1.1.2.8 cliff
1422 1.1.2.16 cliff return lip_new;
1423 1.1.2.16 cliff }
1424 1.1.2.16 cliff
1425 1.1.2.16 cliff /*
1426 1.1.2.16 cliff * delay free of the old link interrupt set
1427 1.1.2.16 cliff * to allow anyone still using it to do so safely
1428 1.1.2.16 cliff * XXX 2 seconds should be plenty?
1429 1.1.2.16 cliff */
1430 1.1.2.16 cliff static void
1431 1.1.2.16 cliff rmixl_pcie_lip_free_callout(rmixl_pcie_link_intr_t *lip)
1432 1.1.2.16 cliff {
1433 1.1.2.16 cliff callout_init(&lip->callout, 0);
1434 1.1.2.16 cliff callout_reset(&lip->callout, 2 * hz, rmixl_pcie_lip_free, lip);
1435 1.1.2.16 cliff }
1436 1.1.2.16 cliff
1437 1.1.2.16 cliff static void
1438 1.1.2.16 cliff rmixl_pcie_lip_free(void *arg)
1439 1.1.2.16 cliff {
1440 1.1.2.16 cliff rmixl_pcie_link_intr_t *lip = arg;
1441 1.1.2.16 cliff
1442 1.1.2.16 cliff callout_destroy(&lip->callout);
1443 1.1.2.16 cliff free(lip, M_DEVBUF);
1444 1.1.2.8 cliff }
1445 1.1.2.8 cliff
1446 1.1.2.8 cliff static int
1447 1.1.2.8 cliff rmixl_pcie_intr(void *arg)
1448 1.1.2.8 cliff {
1449 1.1.2.8 cliff rmixl_pcie_link_intr_t *lip = arg;
1450 1.1.2.8 cliff u_int link = lip->link;
1451 1.1.2.8 cliff int rv = 0;
1452 1.1.2.8 cliff
1453 1.1.2.8 cliff uint32_t status0 = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_LE + int_sts_offset[link].r0);
1454 1.1.2.8 cliff uint32_t status1 = RMIXL_IOREG_READ(RMIXL_IO_DEV_PCIE_LE + int_sts_offset[link].r1);
1455 1.1.2.8 cliff uint64_t status = ((uint64_t)status1 << 32) | status0;
1456 1.1.2.8 cliff DPRINTF(("%s: %d:%#"PRIx64"\n", __func__, link, status));
1457 1.1.2.8 cliff
1458 1.1.2.8 cliff if (status != 0) {
1459 1.1.2.8 cliff rmixl_pcie_link_dispatch_t *dip;
1460 1.1.2.8 cliff
1461 1.1.2.8 cliff if (status & RMIXL_PCIE_LINK_STATUS_ERRORS)
1462 1.1.2.8 cliff rmixl_pcie_link_error_intr(link, status0, status1);
1463 1.1.2.8 cliff
1464 1.1.2.16 cliff for (u_int i=0; i < lip->dispatch_count; i++) {
1465 1.1.2.16 cliff dip = &lip->dispatch_data[i];
1466 1.1.2.16 cliff int (*func)(void *) = dip->func;
1467 1.1.2.16 cliff if (func != NULL) {
1468 1.1.2.16 cliff uint64_t bit = 1 << dip->bitno;
1469 1.1.2.16 cliff if ((status & bit) != 0) {
1470 1.1.2.16 cliff (void)(*func)(dip->arg);
1471 1.1.2.16 cliff dip->counts[cpu_index(curcpu())].evcnt.ev_count++;
1472 1.1.2.16 cliff rv = 1;
1473 1.1.2.16 cliff }
1474 1.1.2.8 cliff }
1475 1.1.2.8 cliff }
1476 1.1.2.8 cliff }
1477 1.1.2.8 cliff
1478 1.1.2.8 cliff return rv;
1479 1.1.2.8 cliff }
1480 1.1.2.8 cliff
1481 1.1.2.8 cliff static void
1482 1.1.2.8 cliff rmixl_pcie_link_error_intr(u_int link, uint32_t status0, uint32_t status1)
1483 1.1.2.8 cliff {
1484 1.1.2.8 cliff printf("%s: mask %#"PRIx64"\n",
1485 1.1.2.8 cliff __func__, RMIXL_PCIE_LINK_STATUS_ERRORS);
1486 1.1.2.8 cliff printf("%s: PCIe Link Error: link=%d status0=%#x status1=%#x\n",
1487 1.1.2.8 cliff __func__, link, status0, status1);
1488 1.1.2.8 cliff #if defined(DDB) && defined(DEBUG)
1489 1.1.2.8 cliff Debugger();
1490 1.1.2.8 cliff #endif
1491 1.1.2.8 cliff }
1492 1.1.2.8 cliff
1493 1.1.2.1 cliff #if defined(DEBUG) || defined(DDB)
1494 1.1.2.1 cliff /* this function exists to facilitate call from ddb */
1495 1.1.2.1 cliff int
1496 1.1.2.1 cliff rmixl_pcie_error_check(void)
1497 1.1.2.1 cliff {
1498 1.1.2.1 cliff if (rmixl_pcie_v != 0)
1499 1.1.2.1 cliff return _rmixl_pcie_error_check(rmixl_pcie_v);
1500 1.1.2.1 cliff return -1;
1501 1.1.2.1 cliff }
1502 1.1.2.1 cliff #endif
1503 1.1.2.1 cliff
1504 1.1.2.1 cliff STATIC int
1505 1.1.2.1 cliff _rmixl_pcie_error_check(void *v)
1506 1.1.2.1 cliff {
1507 1.1.2.1 cliff int i, offset;
1508 1.1.2.1 cliff pcireg_t r;
1509 1.1.2.1 cliff pcitag_t tag;
1510 1.1.2.1 cliff int err=0;
1511 1.1.2.1 cliff #ifdef DIAGNOSTIC
1512 1.1.2.1 cliff pcireg_t regs[PCIE_ECFG_ERRS_OFFTAB_NENTRIES];
1513 1.1.2.1 cliff #endif
1514 1.1.2.1 cliff
1515 1.1.2.1 cliff tag = rmixl_pcie_make_tag(v, 0, 0, 0); /* XXX */
1516 1.1.2.1 cliff
1517 1.1.2.1 cliff for (i=0; i < PCIE_ECFG_ERRS_OFFTAB_NENTRIES; i++) {
1518 1.1.2.1 cliff offset = pcie_ecfg_errs_tab[i].offset;
1519 1.1.2.1 cliff r = rmixl_pcie_conf_read(v, tag, offset);
1520 1.1.2.1 cliff #ifdef DIAGNOSTIC
1521 1.1.2.1 cliff regs[i] = r;
1522 1.1.2.1 cliff #endif
1523 1.1.2.1 cliff if (r != 0) {
1524 1.1.2.1 cliff pcireg_t rw1c = r & pcie_ecfg_errs_tab[i].rw1c;
1525 1.1.2.1 cliff if (rw1c != 0) {
1526 1.1.2.1 cliff /* attempt to clear the error */
1527 1.1.2.1 cliff rmixl_pcie_conf_write(v, tag, offset, rw1c);
1528 1.1.2.1 cliff };
1529 1.1.2.1 cliff if (offset == RMIXL_PCIE_ECFG_CESR)
1530 1.1.2.1 cliff err |= 1; /* correctable */
1531 1.1.2.1 cliff else
1532 1.1.2.1 cliff err |= 2; /* uncorrectable */
1533 1.1.2.1 cliff }
1534 1.1.2.1 cliff }
1535 1.1.2.1 cliff #ifdef DIAGNOSTIC
1536 1.1.2.1 cliff if (err != 0) {
1537 1.1.2.1 cliff for (i=0; i < PCIE_ECFG_ERRS_OFFTAB_NENTRIES; i++) {
1538 1.1.2.1 cliff offset = pcie_ecfg_errs_tab[i].offset;
1539 1.1.2.1 cliff printf("%s: %#x: %#x\n", __func__, offset, regs[i]);
1540 1.1.2.1 cliff }
1541 1.1.2.1 cliff }
1542 1.1.2.1 cliff #endif
1543 1.1.2.1 cliff
1544 1.1.2.1 cliff return err;
1545 1.1.2.1 cliff }
1546 1.1.2.1 cliff
1547 1.1.2.1 cliff static int
1548 1.1.2.1 cliff rmixl_pcie_error_intr(void *v)
1549 1.1.2.1 cliff {
1550 1.1.2.1 cliff if (_rmixl_pcie_error_check(v) < 2)
1551 1.1.2.1 cliff return 0; /* correctable */
1552 1.1.2.1 cliff
1553 1.1.2.1 cliff /* uncorrectable */
1554 1.1.2.1 cliff #if DDB
1555 1.1.2.1 cliff Debugger();
1556 1.1.2.1 cliff #endif
1557 1.1.2.1 cliff
1558 1.1.2.1 cliff /* XXX reset and recover? */
1559 1.1.2.1 cliff
1560 1.1.2.1 cliff panic("%s\n", __func__);
1561 1.1.2.1 cliff }
1562 1.1.2.10 cliff
1563 1.1.2.10 cliff /*
1564 1.1.2.10 cliff * rmixl_physaddr_init_pcie:
1565 1.1.2.10 cliff * called from rmixl_physaddr_init to get region addrs & sizes
1566 1.1.2.10 cliff * from PCIE CFG, ECFG, IO, MEM BARs
1567 1.1.2.10 cliff */
1568 1.1.2.10 cliff void
1569 1.1.2.10 cliff rmixl_physaddr_init_pcie(struct extent *ext)
1570 1.1.2.10 cliff {
1571 1.1.2.18 matt struct rmixl_config * const rcp = &rmixl_configuration;
1572 1.1.2.10 cliff uint32_t r;
1573 1.1.2.10 cliff
1574 1.1.2.11 cliff r = RMIXL_IOREG_READ(RMIXLS_SBC_PCIE_CFG_BAR);
1575 1.1.2.10 cliff if ((r & RMIXL_PCIE_CFG_BAR_ENB) != 0) {
1576 1.1.2.18 matt rmixl_physaddr_add(ext, "pcicfg", &rcp->rc_pci_cfg,
1577 1.1.2.18 matt (bus_addr_t)RMIXL_PCIE_CFG_BAR_TO_BA((uint64_t)r),
1578 1.1.2.18 matt (bus_size_t)RMIXL_PCIE_CFG_SIZE);
1579 1.1.2.18 matt DPRINTF(("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
1580 1.1.2.18 matt "pci-cfg", rcp->rc_pci_cfg.r_pbase,
1581 1.1.2.18 matt rcp->rc_pci_cfg.r_size >> 20));
1582 1.1.2.18 matt
1583 1.1.2.10 cliff }
1584 1.1.2.10 cliff
1585 1.1.2.11 cliff r = RMIXL_IOREG_READ(RMIXLS_SBC_PCIE_ECFG_BAR);
1586 1.1.2.10 cliff if ((r & RMIXL_PCIE_ECFG_BAR_ENB) != 0) {
1587 1.1.2.18 matt rmixl_physaddr_add(ext, "pciecfg", &rcp->rc_pci_ecfg,
1588 1.1.2.18 matt (bus_addr_t)RMIXL_PCIE_ECFG_BAR_TO_BA((uint64_t)r),
1589 1.1.2.18 matt (bus_size_t)RMIXL_PCIE_ECFG_SIZE);
1590 1.1.2.18 matt DPRINTF(("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
1591 1.1.2.18 matt "pci-ecfg", rcp->rc_pci_ecfg.r_pbase,
1592 1.1.2.18 matt rcp->rc_pci_ecfg.r_size >> 20));
1593 1.1.2.10 cliff }
1594 1.1.2.10 cliff
1595 1.1.2.11 cliff r = RMIXL_IOREG_READ(RMIXLS_SBC_PCIE_MEM_BAR);
1596 1.1.2.10 cliff if ((r & RMIXL_PCIE_MEM_BAR_ENB) != 0) {
1597 1.1.2.18 matt rmixl_physaddr_add(ext, "pcimem", &rcp->rc_pci_mem,
1598 1.1.2.18 matt (bus_addr_t)RMIXL_PCIE_MEM_BAR_TO_BA((uint64_t)r),
1599 1.1.2.18 matt (bus_size_t)RMIXL_PCIE_MEM_BAR_TO_SIZE((uint64_t)r));
1600 1.1.2.18 matt DPRINTF(("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
1601 1.1.2.18 matt "pci-mem", rcp->rc_pci_mem.r_pbase,
1602 1.1.2.18 matt rcp->rc_pci_mem.r_size >> 20));
1603 1.1.2.10 cliff }
1604 1.1.2.10 cliff
1605 1.1.2.11 cliff r = RMIXL_IOREG_READ(RMIXLS_SBC_PCIE_IO_BAR);
1606 1.1.2.10 cliff if ((r & RMIXL_PCIE_IO_BAR_ENB) != 0) {
1607 1.1.2.18 matt rmixl_physaddr_add(ext, "pciio", &rcp->rc_pci_io,
1608 1.1.2.18 matt (bus_addr_t)RMIXL_PCIE_IO_BAR_TO_BA((uint64_t)r),
1609 1.1.2.18 matt (bus_size_t)RMIXL_PCIE_IO_BAR_TO_SIZE((uint64_t)r));
1610 1.1.2.18 matt DPRINTF(("%s: %s: %#"PRIx64":%"PRIu64" MB\n", __func__,
1611 1.1.2.18 matt "pci-io", rcp->rc_pci_io.r_pbase,
1612 1.1.2.18 matt rcp->rc_pci_io.r_size >> 20));
1613 1.1.2.10 cliff }
1614 1.1.2.10 cliff }
1615