rmixl_pcix.c revision 1.1.2.1 1 1.1.2.1 cliff /* $NetBSD: rmixl_pcix.c,v 1.1.2.1 2010/04/07 19:25:48 cliff 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 XLR 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.1 cliff __KERNEL_RCSID(0, "$NetBSD: rmixl_pcix.c,v 1.1.2.1 2010/04/07 19:25:48 cliff 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.1 cliff
56 1.1.2.1 cliff #include <uvm/uvm_extern.h>
57 1.1.2.1 cliff
58 1.1.2.1 cliff #include <machine/bus.h>
59 1.1.2.1 cliff #include <machine/intr.h>
60 1.1.2.1 cliff
61 1.1.2.1 cliff #include <mips/rmi/rmixlreg.h>
62 1.1.2.1 cliff #include <mips/rmi/rmixlvar.h>
63 1.1.2.1 cliff #include <mips/rmi/rmixl_intr.h>
64 1.1.2.1 cliff #include <mips/rmi/rmixl_pcixvar.h>
65 1.1.2.1 cliff
66 1.1.2.1 cliff #include <mips/rmi/rmixl_obiovar.h>
67 1.1.2.1 cliff
68 1.1.2.1 cliff #include <dev/pci/pcivar.h>
69 1.1.2.1 cliff #include <dev/pci/pcidevs.h>
70 1.1.2.1 cliff #include <dev/pci/pciconf.h>
71 1.1.2.1 cliff
72 1.1.2.1 cliff #ifdef PCI_NETBSD_CONFIGURE
73 1.1.2.1 cliff #include <mips/cache.h>
74 1.1.2.1 cliff #endif
75 1.1.2.1 cliff
76 1.1.2.1 cliff #include <machine/pci_machdep.h>
77 1.1.2.1 cliff
78 1.1.2.1 cliff #ifdef PCI_DEBUG
79 1.1.2.1 cliff int rmixl_pcix_debug = PCI_DEBUG;
80 1.1.2.1 cliff # define DPRINTF(x) do { if (rmixl_pcix_debug) printf x ; } while (0)
81 1.1.2.1 cliff #else
82 1.1.2.1 cliff # define DPRINTF(x)
83 1.1.2.1 cliff #endif
84 1.1.2.1 cliff
85 1.1.2.1 cliff #ifndef DDB
86 1.1.2.1 cliff # define STATIC static
87 1.1.2.1 cliff #else
88 1.1.2.1 cliff # define STATIC
89 1.1.2.1 cliff #endif
90 1.1.2.1 cliff
91 1.1.2.1 cliff
92 1.1.2.1 cliff /*
93 1.1.2.1 cliff * XLR PCI-X Extended Configuration Registers
94 1.1.2.1 cliff * Note:
95 1.1.2.1 cliff * - MSI-related regs are omitted
96 1.1.2.1 cliff * - Device mode regs are omitted
97 1.1.2.1 cliff */
98 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR0_ADDR 0x100 /* Host BAR0 Address */
99 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR1_ADDR 0x104 /* Host BAR1 Address */
100 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR2_ADDR 0x108 /* Host BAR2 Address */
101 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR3_ADDR 0x10c /* Host BAR3 Address */
102 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR4_ADDR 0x110 /* Host BAR4 Address */
103 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR5_ADDR 0x114 /* Host BAR5 Address */
104 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR0_SIZE 0x118 /* Host BAR0 Size */
105 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR1_SIZE 0x11c /* Host BAR1 Size */
106 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR2_SIZE 0x120 /* Host BAR2 Size */
107 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR3_SIZE 0x124 /* Host BAR3 Size */
108 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR4_SIZE 0x128 /* Host BAR4 Size */
109 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_BAR5_SIZE 0x12c /* Host BAR5 Size */
110 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_MATCH_BIT_ADDR 0x130 /* Match Bit Address BAR */
111 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_MATCH_BIT_SIZE 0x134 /* Match Bit Size BAR */
112 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_XLR_CONTROL 0x138 /* XLR Control reg */
113 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_INTR_CONTROL 0x13c /* Interrupt Control reg */
114 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_INTR_STATUS 0x140 /* Interrupt Status reg */
115 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_INTR_ERR_STATUS 0x144 /* Interrupt Error Status reg */
116 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_MODE_STS 0x178 /* Host Mode Status */
117 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_XLR_MBLE 0x17c /* XLR Match Byte Lane Enable */
118 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_XROM_ADDR 0x180 /* Host Expansion ROM Address */
119 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_XROM_SIZE 0x184 /* Host Expansion ROM Size */
120 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_HOST_MODE_CTL 0x18c /* Host Mode Control */
121 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_TXCAL_CTL 0x1a0 /* TX Calibration Preset Control */
122 1.1.2.1 cliff #define RMIXL_PCIX_ECFG_TXCAL_COUNT 0x1a4 /* TX Calibration Preset Count */
123 1.1.2.1 cliff
124 1.1.2.1 cliff /*
125 1.1.2.1 cliff * RMIXL_PCIX_ECFG_INTR_CONTROL bit defines
126 1.1.2.1 cliff */
127 1.1.2.1 cliff #define PCIX_INTR_CONTROL_RESV __BITS(31,8)
128 1.1.2.1 cliff #define PCIX_INTR_CONTROL_MSI1_MASK __BIT(7)
129 1.1.2.1 cliff #define PCIX_INTR_CONTROL_MSI0_MASK __BIT(6)
130 1.1.2.1 cliff #define PCIX_INTR_CONTROL_INTD_MASK __BIT(5)
131 1.1.2.1 cliff #define PCIX_INTR_CONTROL_INTC_MASK __BIT(4)
132 1.1.2.1 cliff #define PCIX_INTR_CONTROL_INTB_MASK __BIT(3)
133 1.1.2.1 cliff #define PCIX_INTR_CONTROL_INTA_MASK __BIT(2)
134 1.1.2.1 cliff #define PCIX_INTR_CONTROL_TMSI __BIT(1) /* Trigger MSI Interrupt */
135 1.1.2.1 cliff #define PCIX_INTR_CONTROL_DIA __BIT(0) /* Device Interrupt through INTA Pin */
136 1.1.2.1 cliff #define PCIX_INTR_CONTROL_MASK_ALL \
137 1.1.2.1 cliff (PCIX_INTR_CONTROL_MSI1_MASK|PCIX_INTR_CONTROL_MSI0_MASK \
138 1.1.2.1 cliff |PCIX_INTR_CONTROL_INTD_MASK|PCIX_INTR_CONTROL_INTC_MASK \
139 1.1.2.1 cliff |PCIX_INTR_CONTROL_INTB_MASK|PCIX_INTR_CONTROL_INTA_MASK)
140 1.1.2.1 cliff
141 1.1.2.1 cliff /*
142 1.1.2.1 cliff * RMIXL_PCIX_ECFG_INTR_STATUS bit defines
143 1.1.2.1 cliff */
144 1.1.2.1 cliff #define PCIX_INTR_STATUS_RESV __BITS(31,6)
145 1.1.2.1 cliff #define PCIX_INTR_STATUS_MSI1 __BIT(5)
146 1.1.2.1 cliff #define PCIX_INTR_STATUS_MSI0 __BIT(4)
147 1.1.2.1 cliff #define PCIX_INTR_STATUS_INTD __BIT(3)
148 1.1.2.1 cliff #define PCIX_INTR_STATUS_INTC __BIT(2)
149 1.1.2.1 cliff #define PCIX_INTR_STATUS_INTB __BIT(1)
150 1.1.2.1 cliff #define PCIX_INTR_STATUS_INTA __BIT(0)
151 1.1.2.1 cliff
152 1.1.2.1 cliff /*
153 1.1.2.1 cliff * RMIXL_PCIX_ECFG_INTR_ERR_STATUS bit defines
154 1.1.2.1 cliff */
155 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_RESa __BITS(31,5)
156 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_SERR __BIT(4) /* System Error */
157 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_RESb __BIT(3)
158 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_TE __BIT(2) /* Target Error */
159 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_IE __BIT(1) /* Initiator Error */
160 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_RCE __BIT(0) /* Retry Count Expired */
161 1.1.2.1 cliff #define PCIX_INTR_ERR_STATUS_RESV \
162 1.1.2.1 cliff (PCIX_INTR_ERR_STATUS_RESa|PCIX_INTR_ERR_STATUS_RESb)
163 1.1.2.1 cliff
164 1.1.2.1 cliff
165 1.1.2.1 cliff
166 1.1.2.1 cliff #if BYTE_ORDER == BIG_ENDIAN
167 1.1.2.1 cliff # define RMIXL_PCIXREG_BASE RMIXL_IO_DEV_PCIX_EB
168 1.1.2.1 cliff #else
169 1.1.2.1 cliff # define RMIXL_PCIXREG_BASE RMIXL_IO_DEV_PCIX_EL
170 1.1.2.1 cliff #endif
171 1.1.2.1 cliff
172 1.1.2.1 cliff #define RMIXL_PCIXREG_VADDR(o) \
173 1.1.2.1 cliff (volatile uint32_t *)MIPS_PHYS_TO_KSEG1( \
174 1.1.2.1 cliff rmixl_configuration.rc_io_pbase \
175 1.1.2.1 cliff + RMIXL_PCIXREG_BASE + (o))
176 1.1.2.1 cliff
177 1.1.2.1 cliff #define RMIXL_PCIXREG_READ(o) (*RMIXL_PCIXREG_VADDR(o))
178 1.1.2.1 cliff #define RMIXL_PCIXREG_WRITE(o,v) *RMIXL_PCIXREG_VADDR(o) = (v)
179 1.1.2.1 cliff
180 1.1.2.1 cliff /*
181 1.1.2.1 cliff * XXX use locks
182 1.1.2.1 cliff */
183 1.1.2.1 cliff #define PCI_CONF_LOCK(s) (s) = splhigh()
184 1.1.2.1 cliff #define PCI_CONF_UNLOCK(s) splx((s))
185 1.1.2.1 cliff
186 1.1.2.1 cliff
187 1.1.2.1 cliff #define RMIXL_PCIX_CONCAT3(a,b,c) a ## b ## c
188 1.1.2.1 cliff #define RMIXL_PCIX_BAR_INIT(reg, bar, size, align) { \
189 1.1.2.1 cliff struct extent *ext = rmixl_configuration.rc_phys_ex; \
190 1.1.2.1 cliff u_long region_start; \
191 1.1.2.1 cliff uint64_t ba; \
192 1.1.2.1 cliff int err; \
193 1.1.2.1 cliff \
194 1.1.2.1 cliff err = extent_alloc(ext, (size), (align), 0UL, EX_NOWAIT, \
195 1.1.2.1 cliff ®ion_start); \
196 1.1.2.1 cliff if (err != 0) \
197 1.1.2.1 cliff panic("%s: extent_alloc(%p, %#lx, %#lx, %#lx, %#x, %p)",\
198 1.1.2.1 cliff __func__, ext, size, align, 0UL, EX_NOWAIT, \
199 1.1.2.1 cliff ®ion_start); \
200 1.1.2.1 cliff ba = (uint64_t)region_start; \
201 1.1.2.1 cliff ba *= (1024 * 1024); \
202 1.1.2.1 cliff bar = RMIXL_PCIX_CONCAT3(RMIXL_PCIX_,reg,_BAR)(ba, 1); \
203 1.1.2.1 cliff DPRINTF(("PCIX %s BAR was not enabled by firmware\n" \
204 1.1.2.1 cliff "enabling %s at phys %#" PRIxBUSADDR ", size %lu MB\n", \
205 1.1.2.1 cliff __STRING(reg), __STRING(reg), ba, size)); \
206 1.1.2.1 cliff RMIXL_IOREG_WRITE(RMIXL_IO_DEV_BRIDGE + \
207 1.1.2.1 cliff RMIXL_PCIX_CONCAT3(RMIXLR_SBC_PCIX_,reg,_BAR), bar); \
208 1.1.2.1 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + \
209 1.1.2.1 cliff RMIXL_PCIX_CONCAT3(RMIXLR_SBC_PCIX_,reg,_BAR)); \
210 1.1.2.1 cliff DPRINTF(("%s: %s BAR %#x\n", __func__, __STRING(reg), bar)); \
211 1.1.2.1 cliff }
212 1.1.2.1 cliff
213 1.1.2.1 cliff static int rmixl_pcix_match(device_t, cfdata_t, void *);
214 1.1.2.1 cliff static void rmixl_pcix_attach(device_t, device_t, void *);
215 1.1.2.1 cliff static void rmixl_pcix_init(rmixl_pcix_softc_t *);
216 1.1.2.1 cliff static void rmixl_pcix_init_errors(rmixl_pcix_softc_t *);
217 1.1.2.1 cliff static void rmixl_pcix_attach_hook(struct device *, struct device *,
218 1.1.2.1 cliff struct pcibus_attach_args *);
219 1.1.2.1 cliff static void rmixl_pcix_intcfg(rmixl_pcix_softc_t *);
220 1.1.2.1 cliff static void rmixl_pcix_errata(rmixl_pcix_softc_t *);
221 1.1.2.1 cliff static void rmixl_conf_interrupt(void *, int, int, int, int, int *);
222 1.1.2.1 cliff static int rmixl_pcix_bus_maxdevs(void *, int);
223 1.1.2.1 cliff static pcitag_t rmixl_pcix_make_tag(void *, int, int, int);
224 1.1.2.1 cliff static void rmixl_pcix_decompose_tag(void *, pcitag_t, int *, int *, int *);
225 1.1.2.1 cliff void rmixl_pcix_tag_print(const char *restrict, void *, pcitag_t, int, vaddr_t, u_long);
226 1.1.2.1 cliff static int rmixl_pcix_conf_setup(rmixl_pcix_softc_t *,
227 1.1.2.1 cliff pcitag_t, int *, bus_space_tag_t *,
228 1.1.2.1 cliff bus_space_handle_t *);
229 1.1.2.1 cliff static pcireg_t rmixl_pcix_conf_read(void *, pcitag_t, int);
230 1.1.2.1 cliff static void rmixl_pcix_conf_write(void *, pcitag_t, int, pcireg_t);
231 1.1.2.1 cliff
232 1.1.2.1 cliff static int rmixl_pcix_intr_map(struct pci_attach_args *,
233 1.1.2.1 cliff pci_intr_handle_t *);
234 1.1.2.1 cliff static const char *
235 1.1.2.1 cliff rmixl_pcix_intr_string(void *, pci_intr_handle_t);
236 1.1.2.1 cliff static const struct evcnt *
237 1.1.2.1 cliff rmixl_pcix_intr_evcnt(void *, pci_intr_handle_t);
238 1.1.2.1 cliff static pci_intr_handle_t
239 1.1.2.1 cliff rmixl_pcix_make_pih(u_int, u_int);
240 1.1.2.1 cliff static void rmixl_pcix_decompose_pih(pci_intr_handle_t, u_int *, u_int *);
241 1.1.2.1 cliff static void rmixl_pcix_intr_disestablish(void *, void *);
242 1.1.2.1 cliff static void *rmixl_pcix_intr_establish(void *, pci_intr_handle_t,
243 1.1.2.1 cliff int, int (*)(void *), void *);
244 1.1.2.1 cliff static int rmixl_pcix_intr(void *);
245 1.1.2.1 cliff static int rmixl_pcix_error_intr(void *);
246 1.1.2.1 cliff
247 1.1.2.1 cliff
248 1.1.2.1 cliff CFATTACH_DECL_NEW(rmixl_pcix, sizeof(rmixl_pcix_softc_t),
249 1.1.2.1 cliff rmixl_pcix_match, rmixl_pcix_attach, NULL, NULL);
250 1.1.2.1 cliff
251 1.1.2.1 cliff
252 1.1.2.1 cliff static int rmixl_pcix_found;
253 1.1.2.1 cliff
254 1.1.2.1 cliff #if defined(DIAGNOSTIC) || defined(DEBUG) || defined(DDB)
255 1.1.2.1 cliff static rmixl_pcix_softc_t *rmixl_pcix_sc;
256 1.1.2.1 cliff #endif
257 1.1.2.1 cliff
258 1.1.2.1 cliff
259 1.1.2.1 cliff static int
260 1.1.2.1 cliff rmixl_pcix_match(device_t parent, cfdata_t cf, void *aux)
261 1.1.2.1 cliff {
262 1.1.2.1 cliff uint32_t r;
263 1.1.2.1 cliff
264 1.1.2.1 cliff /*
265 1.1.2.1 cliff * PCI-X interface exists on XLR chips only
266 1.1.2.1 cliff */
267 1.1.2.1 cliff if (! cpu_rmixlr(mips_options.mips_cpu))
268 1.1.2.1 cliff return 0;
269 1.1.2.1 cliff
270 1.1.2.1 cliff /* XXX
271 1.1.2.1 cliff * for now there is only one PCI-X Interface on chip
272 1.1.2.1 cliff * and only one chip in the system
273 1.1.2.1 cliff * this could change with furture RMI XL family designs
274 1.1.2.1 cliff * or when we have multi-chip systems.
275 1.1.2.1 cliff */
276 1.1.2.1 cliff if (rmixl_pcix_found)
277 1.1.2.1 cliff return 0;
278 1.1.2.1 cliff
279 1.1.2.1 cliff /* read Host Mode Control register */
280 1.1.2.1 cliff r = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_HOST_MODE_CTL);
281 1.1.2.1 cliff r &= __BIT(1); /* XXX HDMStat */
282 1.1.2.1 cliff if (r == 0)
283 1.1.2.1 cliff return 0; /* strapped for Device Mode */
284 1.1.2.1 cliff
285 1.1.2.1 cliff return 1;
286 1.1.2.1 cliff }
287 1.1.2.1 cliff
288 1.1.2.1 cliff static void
289 1.1.2.1 cliff rmixl_pcix_attach(device_t parent, device_t self, void *aux)
290 1.1.2.1 cliff {
291 1.1.2.1 cliff rmixl_pcix_softc_t *sc = device_private(self);
292 1.1.2.1 cliff struct obio_attach_args *obio = aux;
293 1.1.2.1 cliff struct rmixl_config *rcp = &rmixl_configuration;
294 1.1.2.1 cliff struct pcibus_attach_args pba;
295 1.1.2.1 cliff uint32_t bar;
296 1.1.2.1 cliff
297 1.1.2.1 cliff rmixl_pcix_found = 1;
298 1.1.2.1 cliff #ifdef DIAGNOSTIC
299 1.1.2.1 cliff rmixl_pcix_sc = sc;
300 1.1.2.1 cliff #endif
301 1.1.2.1 cliff sc->sc_dev = self;
302 1.1.2.1 cliff sc->sc_29bit_dmat = obio->obio_29bit_dmat;
303 1.1.2.1 cliff sc->sc_32bit_dmat = obio->obio_32bit_dmat;
304 1.1.2.1 cliff sc->sc_64bit_dmat = obio->obio_64bit_dmat;
305 1.1.2.1 cliff sc->sc_tmsk = obio->obio_tmsk;
306 1.1.2.1 cliff
307 1.1.2.1 cliff aprint_normal(" RMI XLR PCI-X Interface\n");
308 1.1.2.1 cliff
309 1.1.2.1 cliff rmixl_pcix_intcfg(sc);
310 1.1.2.1 cliff
311 1.1.2.1 cliff rmixl_pcix_errata(sc);
312 1.1.2.1 cliff
313 1.1.2.1 cliff /*
314 1.1.2.1 cliff * check XLR Control Register
315 1.1.2.1 cliff */
316 1.1.2.1 cliff uint32_t xlr_control;
317 1.1.2.1 cliff xlr_control = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_XLR_CONTROL);
318 1.1.2.1 cliff printf("%s: XLR_CONTROL=%#x\n", __func__, xlr_control);
319 1.1.2.1 cliff
320 1.1.2.1 cliff /*
321 1.1.2.1 cliff * check HBAR[0..7]
322 1.1.2.1 cliff */
323 1.1.2.1 cliff uint32_t hbar_addr, hbar_size;
324 1.1.2.1 cliff u_int addr_off = RMIXL_PCIX_ECFG_HOST_BAR0_ADDR;
325 1.1.2.1 cliff u_int size_off = RMIXL_PCIX_ECFG_HOST_BAR0_SIZE;
326 1.1.2.1 cliff for (int i=0; i < 7; i++) {
327 1.1.2.1 cliff hbar_addr = RMIXL_PCIXREG_READ(addr_off);
328 1.1.2.1 cliff hbar_size = RMIXL_PCIXREG_READ(size_off);
329 1.1.2.1 cliff addr_off += 4;
330 1.1.2.1 cliff size_off += 4;
331 1.1.2.1 cliff printf("%s: HBAR[%d]=%#x @ %#x\n", __func__, i, hbar_size, hbar_addr);
332 1.1.2.1 cliff }
333 1.1.2.1 cliff
334 1.1.2.1 cliff /*
335 1.1.2.1 cliff * check PCI-X interface byteswap setup
336 1.1.2.1 cliff * ensure 'Match Byte Lane' is disabled
337 1.1.2.1 cliff */
338 1.1.2.1 cliff uint32_t mble, mba, mbs;
339 1.1.2.1 cliff mble = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_XLR_MBLE);
340 1.1.2.1 cliff mba = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_MATCH_BIT_ADDR);
341 1.1.2.1 cliff mbs = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_MATCH_BIT_SIZE);
342 1.1.2.1 cliff printf("%s: MBLE=%#x, MBA=%#x, MBS=%#x\n", __func__, mble, mba, mbs);
343 1.1.2.1 cliff if ((mble & __BIT(40)) != 0)
344 1.1.2.1 cliff RMIXL_PCIXREG_WRITE(RMIXL_PCIX_ECFG_XLR_MBLE, 0);
345 1.1.2.1 cliff
346 1.1.2.1 cliff /*
347 1.1.2.1 cliff * get PCI config space base addr from SBC PCIe CFG BAR
348 1.1.2.1 cliff * initialize it if necessary
349 1.1.2.1 cliff */
350 1.1.2.1 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLR_SBC_PCIX_CFG_BAR);
351 1.1.2.1 cliff DPRINTF(("%s: PCIX_CFG_BAR %#x\n", __func__, bar));
352 1.1.2.1 cliff if ((bar & RMIXL_PCIX_CFG_BAR_ENB) == 0) {
353 1.1.2.1 cliff u_long n = RMIXL_PCIX_CFG_SIZE / (1024 * 1024);
354 1.1.2.1 cliff RMIXL_PCIX_BAR_INIT(CFG, bar, n, n);
355 1.1.2.1 cliff }
356 1.1.2.1 cliff rcp->rc_pci_cfg_pbase = (bus_addr_t)RMIXL_PCIX_CFG_BAR_TO_BA(bar);
357 1.1.2.1 cliff rcp->rc_pci_cfg_size = (bus_size_t)RMIXL_PCIX_CFG_SIZE;
358 1.1.2.1 cliff
359 1.1.2.1 cliff /*
360 1.1.2.1 cliff * get PCI MEM space base [addr, size] from SBC PCIe MEM BAR
361 1.1.2.1 cliff * initialize it if necessary
362 1.1.2.1 cliff */
363 1.1.2.1 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLR_SBC_PCIX_MEM_BAR);
364 1.1.2.1 cliff DPRINTF(("%s: PCIX_MEM_BAR %#x\n", __func__, bar));
365 1.1.2.1 cliff if ((bar & RMIXL_PCIX_MEM_BAR_ENB) == 0) {
366 1.1.2.1 cliff u_long n = 256; /* 256 MB */
367 1.1.2.1 cliff RMIXL_PCIX_BAR_INIT(MEM, bar, n, n);
368 1.1.2.1 cliff }
369 1.1.2.1 cliff rcp->rc_pci_mem_pbase = (bus_addr_t)RMIXL_PCIX_MEM_BAR_TO_BA(bar);
370 1.1.2.1 cliff rcp->rc_pci_mem_size = (bus_size_t)RMIXL_PCIX_MEM_BAR_TO_SIZE(bar);
371 1.1.2.1 cliff printf("%s: rc_pci_mem_pbase %#"PRIxBUSADDR", rc_pci_mem_size %#"PRIxBUSSIZE"\n",
372 1.1.2.1 cliff __func__, rcp->rc_pci_mem_pbase, rcp->rc_pci_mem_size);
373 1.1.2.1 cliff
374 1.1.2.1 cliff /*
375 1.1.2.1 cliff * get PCI IO space base [addr, size] from SBC PCIe IO BAR
376 1.1.2.1 cliff * initialize it if necessary
377 1.1.2.1 cliff */
378 1.1.2.1 cliff bar = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLR_SBC_PCIX_IO_BAR);
379 1.1.2.1 cliff DPRINTF(("%s: PCIX_IO_BAR %#x\n", __func__, bar));
380 1.1.2.1 cliff if ((bar & RMIXL_PCIX_IO_BAR_ENB) == 0) {
381 1.1.2.1 cliff u_long n = 32; /* 32 MB */
382 1.1.2.1 cliff RMIXL_PCIX_BAR_INIT(IO, bar, n, n);
383 1.1.2.1 cliff }
384 1.1.2.1 cliff rcp->rc_pci_io_pbase = (bus_addr_t)RMIXL_PCIX_IO_BAR_TO_BA(bar);
385 1.1.2.1 cliff rcp->rc_pci_io_size = (bus_size_t)RMIXL_PCIX_IO_BAR_TO_SIZE(bar);
386 1.1.2.1 cliff
387 1.1.2.1 cliff /*
388 1.1.2.1 cliff * initialize the PCI CFG bus space tag
389 1.1.2.1 cliff */
390 1.1.2.1 cliff rmixl_pci_cfg_bus_mem_init(&rcp->rc_pci_cfg_memt, rcp);
391 1.1.2.1 cliff sc->sc_pci_cfg_memt = &rcp->rc_pci_cfg_memt;
392 1.1.2.1 cliff
393 1.1.2.1 cliff /*
394 1.1.2.1 cliff * initialize the PCI MEM and IO bus space tags
395 1.1.2.1 cliff */
396 1.1.2.1 cliff rmixl_pci_bus_mem_init(&rcp->rc_pci_memt, rcp);
397 1.1.2.1 cliff rmixl_pci_bus_io_init(&rcp->rc_pci_iot, rcp);
398 1.1.2.1 cliff
399 1.1.2.1 cliff /*
400 1.1.2.1 cliff * initialize the extended configuration regs
401 1.1.2.1 cliff */
402 1.1.2.1 cliff rmixl_pcix_init_errors(sc);
403 1.1.2.1 cliff
404 1.1.2.1 cliff /*
405 1.1.2.1 cliff * initialize the PCI chipset tag
406 1.1.2.1 cliff */
407 1.1.2.1 cliff rmixl_pcix_init(sc);
408 1.1.2.1 cliff
409 1.1.2.1 cliff /*
410 1.1.2.1 cliff * attach the PCI bus
411 1.1.2.1 cliff */
412 1.1.2.1 cliff memset(&pba, 0, sizeof(pba));
413 1.1.2.1 cliff pba.pba_memt = &rcp->rc_pci_memt;
414 1.1.2.1 cliff pba.pba_iot = &rcp->rc_pci_iot;
415 1.1.2.1 cliff pba.pba_dmat = sc->sc_32bit_dmat;
416 1.1.2.1 cliff pba.pba_dmat64 = sc->sc_64bit_dmat;
417 1.1.2.1 cliff pba.pba_pc = &sc->sc_pci_chipset;
418 1.1.2.1 cliff pba.pba_bus = 0;
419 1.1.2.1 cliff pba.pba_bridgetag = NULL;
420 1.1.2.1 cliff pba.pba_intrswiz = 0;
421 1.1.2.1 cliff pba.pba_intrtag = 0;
422 1.1.2.1 cliff pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
423 1.1.2.1 cliff PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
424 1.1.2.1 cliff
425 1.1.2.1 cliff (void) config_found_ia(self, "pcibus", &pba, pcibusprint);
426 1.1.2.1 cliff }
427 1.1.2.1 cliff
428 1.1.2.1 cliff /*
429 1.1.2.1 cliff * rmixl_pcix_intcfg - init PCI-X interrupt control
430 1.1.2.1 cliff */
431 1.1.2.1 cliff static void
432 1.1.2.1 cliff rmixl_pcix_intcfg(rmixl_pcix_softc_t *sc)
433 1.1.2.1 cliff {
434 1.1.2.1 cliff DPRINTF(("%s\n", __func__));
435 1.1.2.1 cliff
436 1.1.2.1 cliff /* mask all interrupts until they are established */
437 1.1.2.1 cliff RMIXL_PCIXREG_WRITE(RMIXL_PCIX_ECFG_INTR_CONTROL,
438 1.1.2.1 cliff PCIX_INTR_CONTROL_MASK_ALL);
439 1.1.2.1 cliff
440 1.1.2.1 cliff /*
441 1.1.2.1 cliff * read-to-clear any pre-existing interrupts
442 1.1.2.1 cliff * XXX MSI bits in STATUS are also documented as write 1 to clear in PRM
443 1.1.2.1 cliff */
444 1.1.2.1 cliff (void)RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_STATUS);
445 1.1.2.1 cliff (void)RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_ERR_STATUS);
446 1.1.2.1 cliff
447 1.1.2.1 cliff /* initialize the dispatch handles */
448 1.1.2.1 cliff for (int i=0; i < RMIXL_PCIX_NINTR; i++) {
449 1.1.2.1 cliff rmixl_pcix_intr_t *ih = &sc->sc_intr[i];
450 1.1.2.1 cliff LIST_INIT(&ih->dispatch);
451 1.1.2.1 cliff ih->ih = NULL;
452 1.1.2.1 cliff ih->intrpin = i;
453 1.1.2.1 cliff ih->enabled = false;
454 1.1.2.1 cliff }
455 1.1.2.1 cliff
456 1.1.2.1 cliff sc->sc_ih = rmixl_intr_establish(16, sc->sc_tmsk,
457 1.1.2.1 cliff IPL_VM, RMIXL_TRIG_LEVEL, RMIXL_POLR_HIGH,
458 1.1.2.1 cliff rmixl_pcix_intr, sc);
459 1.1.2.1 cliff if (sc->sc_ih == NULL)
460 1.1.2.1 cliff panic("%s: cannot establish irq %d", __func__, 16);
461 1.1.2.1 cliff
462 1.1.2.1 cliff sc->sc_fatal_ih = rmixl_intr_establish(24, sc->sc_tmsk,
463 1.1.2.1 cliff IPL_VM, RMIXL_TRIG_LEVEL, RMIXL_POLR_HIGH,
464 1.1.2.1 cliff rmixl_pcix_error_intr, sc);
465 1.1.2.1 cliff if (sc->sc_fatal_ih == NULL)
466 1.1.2.1 cliff panic("%s: cannot establish irq %d", __func__, 24);
467 1.1.2.1 cliff
468 1.1.2.1 cliff sc->sc_intr_init_done = true;
469 1.1.2.1 cliff }
470 1.1.2.1 cliff
471 1.1.2.1 cliff static void
472 1.1.2.1 cliff rmixl_pcix_errata(rmixl_pcix_softc_t *sc)
473 1.1.2.1 cliff {
474 1.1.2.1 cliff /* nothing */
475 1.1.2.1 cliff }
476 1.1.2.1 cliff
477 1.1.2.1 cliff static void
478 1.1.2.1 cliff rmixl_pcix_init(rmixl_pcix_softc_t *sc)
479 1.1.2.1 cliff {
480 1.1.2.1 cliff pci_chipset_tag_t pc = &sc->sc_pci_chipset;
481 1.1.2.1 cliff #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
482 1.1.2.1 cliff struct extent *ioext, *memext;
483 1.1.2.1 cliff #endif
484 1.1.2.1 cliff
485 1.1.2.1 cliff pc->pc_conf_v = (void *)sc;
486 1.1.2.1 cliff pc->pc_attach_hook = rmixl_pcix_attach_hook;
487 1.1.2.1 cliff pc->pc_bus_maxdevs = rmixl_pcix_bus_maxdevs;
488 1.1.2.1 cliff pc->pc_make_tag = rmixl_pcix_make_tag;
489 1.1.2.1 cliff pc->pc_decompose_tag = rmixl_pcix_decompose_tag;
490 1.1.2.1 cliff pc->pc_conf_read = rmixl_pcix_conf_read;
491 1.1.2.1 cliff pc->pc_conf_write = rmixl_pcix_conf_write;
492 1.1.2.1 cliff
493 1.1.2.1 cliff pc->pc_intr_v = (void *)sc;
494 1.1.2.1 cliff pc->pc_intr_map = rmixl_pcix_intr_map;
495 1.1.2.1 cliff pc->pc_intr_string = rmixl_pcix_intr_string;
496 1.1.2.1 cliff pc->pc_intr_evcnt = rmixl_pcix_intr_evcnt;
497 1.1.2.1 cliff pc->pc_intr_establish = rmixl_pcix_intr_establish;
498 1.1.2.1 cliff pc->pc_intr_disestablish = rmixl_pcix_intr_disestablish;
499 1.1.2.1 cliff pc->pc_conf_interrupt = rmixl_conf_interrupt;
500 1.1.2.1 cliff
501 1.1.2.1 cliff #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
502 1.1.2.1 cliff /*
503 1.1.2.1 cliff * Configure the PCI bus.
504 1.1.2.1 cliff */
505 1.1.2.1 cliff struct rmixl_config *rcp = &rmixl_configuration;
506 1.1.2.1 cliff
507 1.1.2.1 cliff aprint_normal("%s: configuring PCI bus\n",
508 1.1.2.1 cliff device_xname(sc->sc_dev));
509 1.1.2.1 cliff
510 1.1.2.1 cliff ioext = extent_create("pciio",
511 1.1.2.1 cliff rcp->rc_pci_io_pbase,
512 1.1.2.1 cliff rcp->rc_pci_io_pbase + rcp->rc_pci_io_size - 1,
513 1.1.2.1 cliff M_DEVBUF, NULL, 0, EX_NOWAIT);
514 1.1.2.1 cliff
515 1.1.2.1 cliff memext = extent_create("pcimem",
516 1.1.2.1 cliff rcp->rc_pci_mem_pbase,
517 1.1.2.1 cliff rcp->rc_pci_mem_pbase + rcp->rc_pci_mem_size - 1,
518 1.1.2.1 cliff M_DEVBUF, NULL, 0, EX_NOWAIT);
519 1.1.2.1 cliff
520 1.1.2.1 cliff pci_configure_bus(pc, ioext, memext, NULL, 0,
521 1.1.2.1 cliff mips_cache_info.mci_dcache_align);
522 1.1.2.1 cliff
523 1.1.2.1 cliff extent_destroy(ioext);
524 1.1.2.1 cliff extent_destroy(memext);
525 1.1.2.1 cliff #endif
526 1.1.2.1 cliff }
527 1.1.2.1 cliff
528 1.1.2.1 cliff static void
529 1.1.2.1 cliff rmixl_pcix_init_errors(rmixl_pcix_softc_t *sc)
530 1.1.2.1 cliff {
531 1.1.2.1 cliff /* nothing */
532 1.1.2.1 cliff }
533 1.1.2.1 cliff
534 1.1.2.1 cliff void
535 1.1.2.1 cliff rmixl_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
536 1.1.2.1 cliff {
537 1.1.2.1 cliff DPRINTF(("%s: %p, %d, %d, %d, %d, %p\n",
538 1.1.2.1 cliff __func__, v, bus, dev, ipin, swiz, iline));
539 1.1.2.1 cliff }
540 1.1.2.1 cliff
541 1.1.2.1 cliff void
542 1.1.2.1 cliff rmixl_pcix_attach_hook(struct device *parent, struct device *self,
543 1.1.2.1 cliff struct pcibus_attach_args *pba)
544 1.1.2.1 cliff {
545 1.1.2.1 cliff DPRINTF(("%s: pba_bus %d, pba_bridgetag %p, pc_conf_v %p\n",
546 1.1.2.1 cliff __func__, pba->pba_bus, pba->pba_bridgetag,
547 1.1.2.1 cliff pba->pba_pc->pc_conf_v));
548 1.1.2.1 cliff }
549 1.1.2.1 cliff
550 1.1.2.1 cliff int
551 1.1.2.1 cliff rmixl_pcix_bus_maxdevs(void *v, int busno)
552 1.1.2.1 cliff {
553 1.1.2.1 cliff return (32); /* XXX depends on the family of XLS SoC */
554 1.1.2.1 cliff }
555 1.1.2.1 cliff
556 1.1.2.1 cliff /*
557 1.1.2.1 cliff * XLS pci tag is a 40 bit address composed thusly:
558 1.1.2.1 cliff * 39:25 (reserved)
559 1.1.2.1 cliff * 24 Swap (0=little, 1=big endian)
560 1.1.2.1 cliff * 23:16 Bus number
561 1.1.2.1 cliff * 15:11 Device number
562 1.1.2.1 cliff * 10:8 Function number
563 1.1.2.1 cliff * 7:0 Register number
564 1.1.2.1 cliff *
565 1.1.2.1 cliff * Note: this is the "native" composition for addressing CFG space, but not for ECFG space.
566 1.1.2.1 cliff */
567 1.1.2.1 cliff pcitag_t
568 1.1.2.1 cliff rmixl_pcix_make_tag(void *v, int bus, int dev, int fun)
569 1.1.2.1 cliff {
570 1.1.2.1 cliff return ((bus << 16) | (dev << 11) | (fun << 8));
571 1.1.2.1 cliff }
572 1.1.2.1 cliff
573 1.1.2.1 cliff void
574 1.1.2.1 cliff rmixl_pcix_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
575 1.1.2.1 cliff {
576 1.1.2.1 cliff if (bp != NULL)
577 1.1.2.1 cliff *bp = (tag >> 16) & 0xff;
578 1.1.2.1 cliff if (dp != NULL)
579 1.1.2.1 cliff *dp = (tag >> 11) & 0x1f;
580 1.1.2.1 cliff if (fp != NULL)
581 1.1.2.1 cliff *fp = (tag >> 8) & 0x7;
582 1.1.2.1 cliff }
583 1.1.2.1 cliff
584 1.1.2.1 cliff void
585 1.1.2.1 cliff rmixl_pcix_tag_print(const char *restrict s, void *v, pcitag_t tag, int offset,
586 1.1.2.1 cliff vaddr_t va, u_long r)
587 1.1.2.1 cliff {
588 1.1.2.1 cliff int bus, dev, fun;
589 1.1.2.1 cliff
590 1.1.2.1 cliff rmixl_pcix_decompose_tag(v, tag, &bus, &dev, &fun);
591 1.1.2.1 cliff printf("%s: %d/%d/%d/%d - %#" PRIxVADDR ":%#lx\n",
592 1.1.2.1 cliff s, bus, dev, fun, offset, va, r);
593 1.1.2.1 cliff }
594 1.1.2.1 cliff
595 1.1.2.1 cliff static int
596 1.1.2.1 cliff rmixl_pcix_conf_setup(rmixl_pcix_softc_t *sc,
597 1.1.2.1 cliff pcitag_t tag, int *offp, bus_space_tag_t *bstp,
598 1.1.2.1 cliff bus_space_handle_t *bshp)
599 1.1.2.1 cliff {
600 1.1.2.1 cliff struct rmixl_config *rcp = &rmixl_configuration;
601 1.1.2.1 cliff bus_space_tag_t bst;
602 1.1.2.1 cliff bus_space_handle_t bsh;
603 1.1.2.1 cliff bus_size_t size;
604 1.1.2.1 cliff pcitag_t mask;
605 1.1.2.1 cliff bus_addr_t ba;
606 1.1.2.1 cliff int err;
607 1.1.2.1 cliff static bus_space_handle_t cfg_bsh;
608 1.1.2.1 cliff static bus_addr_t cfg_oba = -1;
609 1.1.2.1 cliff
610 1.1.2.1 cliff /*
611 1.1.2.1 cliff * bus space depends on offset
612 1.1.2.1 cliff */
613 1.1.2.1 cliff if ((*offp >= 0) && (*offp < 0x100)) {
614 1.1.2.1 cliff mask = __BITS(15,0);
615 1.1.2.1 cliff bst = sc->sc_pci_cfg_memt;
616 1.1.2.1 cliff ba = rcp->rc_pci_cfg_pbase;
617 1.1.2.1 cliff ba += (tag & ~mask);
618 1.1.2.1 cliff *offp += (tag & mask);
619 1.1.2.1 cliff if (ba != cfg_oba) {
620 1.1.2.1 cliff size = (bus_size_t)(mask + 1);
621 1.1.2.1 cliff if (cfg_oba != -1)
622 1.1.2.1 cliff bus_space_unmap(bst, cfg_bsh, size);
623 1.1.2.1 cliff err = bus_space_map(bst, ba, size, 0, &cfg_bsh);
624 1.1.2.1 cliff if (err != 0) {
625 1.1.2.1 cliff #ifdef DEBUG
626 1.1.2.1 cliff panic("%s: bus_space_map err %d, CFG space",
627 1.1.2.1 cliff __func__, err); /* XXX */
628 1.1.2.1 cliff #endif
629 1.1.2.1 cliff return -1;
630 1.1.2.1 cliff }
631 1.1.2.1 cliff cfg_oba = ba;
632 1.1.2.1 cliff }
633 1.1.2.1 cliff bsh = cfg_bsh;
634 1.1.2.1 cliff } else {
635 1.1.2.1 cliff #ifdef DEBUG
636 1.1.2.1 cliff panic("%s: offset %#x: unknown", __func__, *offp);
637 1.1.2.1 cliff #endif
638 1.1.2.1 cliff return -1;
639 1.1.2.1 cliff }
640 1.1.2.1 cliff
641 1.1.2.1 cliff *bstp = bst;
642 1.1.2.1 cliff *bshp = bsh;
643 1.1.2.1 cliff
644 1.1.2.1 cliff return 0;
645 1.1.2.1 cliff }
646 1.1.2.1 cliff
647 1.1.2.1 cliff pcireg_t
648 1.1.2.1 cliff rmixl_pcix_conf_read(void *v, pcitag_t tag, int offset)
649 1.1.2.1 cliff {
650 1.1.2.1 cliff rmixl_pcix_softc_t *sc = v;
651 1.1.2.1 cliff static bus_space_handle_t bsh;
652 1.1.2.1 cliff bus_space_tag_t bst;
653 1.1.2.1 cliff pcireg_t rv;
654 1.1.2.1 cliff uint64_t cfg0;
655 1.1.2.1 cliff u_int s;
656 1.1.2.1 cliff
657 1.1.2.1 cliff PCI_CONF_LOCK(s);
658 1.1.2.1 cliff
659 1.1.2.1 cliff if (rmixl_pcix_conf_setup(sc, tag, &offset, &bst, &bsh) == 0) {
660 1.1.2.1 cliff cfg0 = rmixl_cache_err_dis();
661 1.1.2.1 cliff rv = bus_space_read_4(bst, bsh, (bus_size_t)offset);
662 1.1.2.1 cliff if (rmixl_cache_err_check() != 0) {
663 1.1.2.1 cliff #ifdef DIAGNOSTIC
664 1.1.2.1 cliff int bus, dev, fun;
665 1.1.2.1 cliff
666 1.1.2.1 cliff rmixl_pcix_decompose_tag(v, tag, &bus, &dev, &fun);
667 1.1.2.1 cliff printf("%s: %d/%d/%d, offset %#x: bad address\n",
668 1.1.2.1 cliff __func__, bus, dev, fun, offset);
669 1.1.2.1 cliff #endif
670 1.1.2.1 cliff rv = (pcireg_t) -1;
671 1.1.2.1 cliff }
672 1.1.2.1 cliff rmixl_cache_err_restore(cfg0);
673 1.1.2.1 cliff } else {
674 1.1.2.1 cliff rv = -1;
675 1.1.2.1 cliff }
676 1.1.2.1 cliff
677 1.1.2.1 cliff PCI_CONF_UNLOCK(s);
678 1.1.2.1 cliff return rv;
679 1.1.2.1 cliff }
680 1.1.2.1 cliff
681 1.1.2.1 cliff void
682 1.1.2.1 cliff rmixl_pcix_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
683 1.1.2.1 cliff {
684 1.1.2.1 cliff rmixl_pcix_softc_t *sc = v;
685 1.1.2.1 cliff static bus_space_handle_t bsh;
686 1.1.2.1 cliff bus_space_tag_t bst;
687 1.1.2.1 cliff uint64_t cfg0;
688 1.1.2.1 cliff u_int s;
689 1.1.2.1 cliff
690 1.1.2.1 cliff PCI_CONF_LOCK(s);
691 1.1.2.1 cliff
692 1.1.2.1 cliff if (rmixl_pcix_conf_setup(sc, tag, &offset, &bst, &bsh) == 0) {
693 1.1.2.1 cliff cfg0 = rmixl_cache_err_dis();
694 1.1.2.1 cliff bus_space_write_4(bst, bsh, (bus_size_t)offset, val);
695 1.1.2.1 cliff if (rmixl_cache_err_check() != 0) {
696 1.1.2.1 cliff #ifdef DIAGNOSTIC
697 1.1.2.1 cliff int bus, dev, fun;
698 1.1.2.1 cliff
699 1.1.2.1 cliff rmixl_pcix_decompose_tag(v, tag, &bus, &dev, &fun);
700 1.1.2.1 cliff printf("%s: %d/%d/%d, offset %#x: bad address\n",
701 1.1.2.1 cliff __func__, bus, dev, fun, offset);
702 1.1.2.1 cliff #endif
703 1.1.2.1 cliff }
704 1.1.2.1 cliff rmixl_cache_err_restore(cfg0);
705 1.1.2.1 cliff }
706 1.1.2.1 cliff
707 1.1.2.1 cliff PCI_CONF_UNLOCK(s);
708 1.1.2.1 cliff }
709 1.1.2.1 cliff
710 1.1.2.1 cliff int
711 1.1.2.1 cliff rmixl_pcix_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *pih)
712 1.1.2.1 cliff {
713 1.1.2.1 cliff const u_int irq = 16; /* PCIX index in IRT */
714 1.1.2.1 cliff
715 1.1.2.1 cliff #ifdef DEBUG
716 1.1.2.1 cliff DPRINTF(("%s: ps_bus %d, pa_intrswiz %#x, pa_intrtag %#lx,"
717 1.1.2.1 cliff " pa_intrpin %d, pa_intrline %d, pa_rawintrpin %d\n",
718 1.1.2.1 cliff __func__, pa->pa_bus, pa->pa_intrswiz, pa->pa_intrtag,
719 1.1.2.1 cliff pa->pa_intrpin, pa->pa_intrline, pa->pa_rawintrpin));
720 1.1.2.1 cliff #endif
721 1.1.2.1 cliff
722 1.1.2.1 cliff if (pa->pa_intrpin != PCI_INTERRUPT_PIN_NONE)
723 1.1.2.1 cliff *pih = rmixl_pcix_make_pih(pa->pa_intrpin - 1, irq);
724 1.1.2.1 cliff else
725 1.1.2.1 cliff *pih = ~0;
726 1.1.2.1 cliff
727 1.1.2.1 cliff return 0;
728 1.1.2.1 cliff }
729 1.1.2.1 cliff
730 1.1.2.1 cliff const char *
731 1.1.2.1 cliff rmixl_pcix_intr_string(void *v, pci_intr_handle_t pih)
732 1.1.2.1 cliff {
733 1.1.2.1 cliff u_int bitno, irq;
734 1.1.2.1 cliff
735 1.1.2.1 cliff rmixl_pcix_decompose_pih(pih, &bitno, &irq);
736 1.1.2.1 cliff
737 1.1.2.1 cliff if (! cpu_rmixlr(mips_options.mips_cpu))
738 1.1.2.1 cliff panic("%s: cpu %#x not supported\n",
739 1.1.2.1 cliff __func__, mips_options.mips_cpu_id);
740 1.1.2.1 cliff
741 1.1.2.1 cliff return rmixl_intr_string(irq);
742 1.1.2.1 cliff }
743 1.1.2.1 cliff
744 1.1.2.1 cliff const struct evcnt *
745 1.1.2.1 cliff rmixl_pcix_intr_evcnt(void *v, pci_intr_handle_t pih)
746 1.1.2.1 cliff {
747 1.1.2.1 cliff return NULL;
748 1.1.2.1 cliff }
749 1.1.2.1 cliff
750 1.1.2.1 cliff static pci_intr_handle_t
751 1.1.2.1 cliff rmixl_pcix_make_pih(u_int bitno, u_int irq)
752 1.1.2.1 cliff {
753 1.1.2.1 cliff pci_intr_handle_t pih;
754 1.1.2.1 cliff
755 1.1.2.1 cliff KASSERT(bitno < 64);
756 1.1.2.1 cliff KASSERT(irq < 32);
757 1.1.2.1 cliff
758 1.1.2.1 cliff pih = (irq << 6);
759 1.1.2.1 cliff pih |= bitno;
760 1.1.2.1 cliff
761 1.1.2.1 cliff return pih;
762 1.1.2.1 cliff }
763 1.1.2.1 cliff
764 1.1.2.1 cliff static void
765 1.1.2.1 cliff rmixl_pcix_decompose_pih(pci_intr_handle_t pih, u_int *bitno, u_int *irq)
766 1.1.2.1 cliff {
767 1.1.2.1 cliff *bitno = (u_int)(pih & 0x3f);
768 1.1.2.1 cliff *irq = (u_int)(pih >> 6);
769 1.1.2.1 cliff
770 1.1.2.1 cliff KASSERT(*bitno < 64);
771 1.1.2.1 cliff KASSERT(*irq < 31);
772 1.1.2.1 cliff }
773 1.1.2.1 cliff
774 1.1.2.1 cliff static void
775 1.1.2.1 cliff rmixl_pcix_intr_disestablish(void *v, void *ih)
776 1.1.2.1 cliff {
777 1.1.2.1 cliff rmixl_pcix_softc_t *sc = v;
778 1.1.2.1 cliff rmixl_pcix_dispatch_t *dip = ih;
779 1.1.2.1 cliff rmixl_pcix_intr_t *pip = &sc->sc_intr[dip->bitno];;
780 1.1.2.1 cliff
781 1.1.2.1 cliff DPRINTF(("%s: pin=%d irq=%d\n",
782 1.1.2.1 cliff __func__, dip->bitno + 1, dip->irq));
783 1.1.2.1 cliff KASSERT(dip->bitno < RMIXL_PCIX_NINTR);
784 1.1.2.1 cliff
785 1.1.2.1 cliff LIST_REMOVE(dip, next);
786 1.1.2.1 cliff evcnt_detach(&dip->count);
787 1.1.2.1 cliff free(dip, M_DEVBUF);
788 1.1.2.1 cliff
789 1.1.2.1 cliff if (LIST_EMPTY(&pip->dispatch)) {
790 1.1.2.1 cliff uint32_t bit = 1 << (dip->bitno + 2);
791 1.1.2.1 cliff uint32_t r;
792 1.1.2.1 cliff
793 1.1.2.1 cliff r = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_CONTROL);
794 1.1.2.1 cliff r |= bit; /* set mask */
795 1.1.2.1 cliff RMIXL_PCIXREG_WRITE(RMIXL_PCIX_ECFG_INTR_CONTROL, r);
796 1.1.2.1 cliff DPRINTF(("%s: disabled pin %d\n", __func__, dip->bitno + 1));
797 1.1.2.1 cliff
798 1.1.2.1 cliff pip->enabled = false;
799 1.1.2.1 cliff }
800 1.1.2.1 cliff }
801 1.1.2.1 cliff
802 1.1.2.1 cliff static void *
803 1.1.2.1 cliff rmixl_pcix_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
804 1.1.2.1 cliff int (*func)(void *), void *arg)
805 1.1.2.1 cliff {
806 1.1.2.1 cliff rmixl_pcix_softc_t *sc = v;
807 1.1.2.1 cliff u_int bitno, irq;
808 1.1.2.1 cliff rmixl_pcix_intr_t *pip;
809 1.1.2.1 cliff rmixl_pcix_dispatch_t *dip;
810 1.1.2.1 cliff int s;
811 1.1.2.1 cliff
812 1.1.2.1 cliff if (pih == ~0) {
813 1.1.2.1 cliff DPRINTF(("%s: bad pih=%#lx, implies PCI_INTERRUPT_PIN_NONE\n",
814 1.1.2.1 cliff __func__, pih));
815 1.1.2.1 cliff return NULL;
816 1.1.2.1 cliff }
817 1.1.2.1 cliff
818 1.1.2.1 cliff rmixl_pcix_decompose_pih(pih, &bitno, &irq);
819 1.1.2.1 cliff DPRINTF(("%s: pin=%d irq=%d\n", __func__, bitno + 1, irq));
820 1.1.2.1 cliff
821 1.1.2.1 cliff KASSERT(bitno < RMIXL_PCIX_NINTR);
822 1.1.2.1 cliff pip = &sc->sc_intr[bitno];
823 1.1.2.1 cliff
824 1.1.2.1 cliff s = splhigh();
825 1.1.2.1 cliff
826 1.1.2.1 cliff /*
827 1.1.2.1 cliff * all PCI-X device intrs get same ipl and sc
828 1.1.2.1 cliff */
829 1.1.2.1 cliff KASSERT(sc == rmixl_pcix_sc);
830 1.1.2.1 cliff KASSERT(ipl == IPL_VM);
831 1.1.2.1 cliff
832 1.1.2.1 cliff /*
833 1.1.2.1 cliff * allocate and initialize a dispatch handle
834 1.1.2.1 cliff */
835 1.1.2.1 cliff dip = malloc(sizeof(*dip), M_DEVBUF, M_NOWAIT);
836 1.1.2.1 cliff if (dip == NULL) {
837 1.1.2.1 cliff printf("%s: cannot malloc dispatch handle\n", __func__);
838 1.1.2.1 cliff goto out;
839 1.1.2.1 cliff }
840 1.1.2.1 cliff
841 1.1.2.1 cliff dip->bitno = bitno;
842 1.1.2.1 cliff dip->irq = irq;
843 1.1.2.1 cliff dip->func = func;
844 1.1.2.1 cliff dip->arg = arg;
845 1.1.2.1 cliff snprintf(dip->count_name, sizeof(dip->count_name),
846 1.1.2.1 cliff "pin %d", bitno + 1);
847 1.1.2.1 cliff evcnt_attach_dynamic(&dip->count, EVCNT_TYPE_INTR, NULL,
848 1.1.2.1 cliff "rmixl_pcix", dip->count_name);
849 1.1.2.1 cliff
850 1.1.2.1 cliff if (pip->enabled == false) {
851 1.1.2.1 cliff uint32_t bit = 1 << (bitno + 2);
852 1.1.2.1 cliff uint32_t r;
853 1.1.2.1 cliff
854 1.1.2.1 cliff r = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_CONTROL);
855 1.1.2.1 cliff r &= ~bit; /* clear mask */
856 1.1.2.1 cliff RMIXL_PCIXREG_WRITE(RMIXL_PCIX_ECFG_INTR_CONTROL, r);
857 1.1.2.1 cliff
858 1.1.2.1 cliff pip->sc = sc;
859 1.1.2.1 cliff pip->ipl = ipl;
860 1.1.2.1 cliff pip->enabled = true;
861 1.1.2.1 cliff DPRINTF(("%s: enabled pin %d\n", __func__, bitno + 1));
862 1.1.2.1 cliff }
863 1.1.2.1 cliff
864 1.1.2.1 cliff LIST_INSERT_HEAD(&pip->dispatch, dip, next);
865 1.1.2.1 cliff
866 1.1.2.1 cliff out:
867 1.1.2.1 cliff splx(s);
868 1.1.2.1 cliff return dip;
869 1.1.2.1 cliff }
870 1.1.2.1 cliff
871 1.1.2.1 cliff static int
872 1.1.2.1 cliff rmixl_pcix_intr(void *arg)
873 1.1.2.1 cliff {
874 1.1.2.1 cliff rmixl_pcix_softc_t *sc = arg;
875 1.1.2.1 cliff int rv = 0;
876 1.1.2.1 cliff
877 1.1.2.1 cliff uint32_t status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_STATUS);
878 1.1.2.1 cliff DPRINTF(("%s: %#x\n", __func__, status));
879 1.1.2.1 cliff
880 1.1.2.1 cliff if (status != 0) {
881 1.1.2.1 cliff for (int i=0; i < RMIXL_PCIX_NINTR; i++) {
882 1.1.2.1 cliff uint32_t bit = 1 << i;
883 1.1.2.1 cliff if ((status & bit) != 0) {
884 1.1.2.1 cliff rmixl_pcix_intr_t *pip = &sc->sc_intr[i];
885 1.1.2.1 cliff rmixl_pcix_dispatch_t *dip;
886 1.1.2.1 cliff LIST_FOREACH(dip, &pip->dispatch, next) {
887 1.1.2.1 cliff (void)(*dip->func)(dip->arg);
888 1.1.2.1 cliff dip->count.ev_count++;
889 1.1.2.1 cliff rv = 1;
890 1.1.2.1 cliff }
891 1.1.2.1 cliff }
892 1.1.2.1 cliff }
893 1.1.2.1 cliff }
894 1.1.2.1 cliff return rv;
895 1.1.2.1 cliff }
896 1.1.2.1 cliff
897 1.1.2.1 cliff static int
898 1.1.2.1 cliff rmixl_pcix_error_intr(void *arg)
899 1.1.2.1 cliff {
900 1.1.2.1 cliff rmixl_pcix_softc_t *sc = arg;
901 1.1.2.1 cliff uint32_t error_status;
902 1.1.2.1 cliff
903 1.1.2.1 cliff error_status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_ERR_STATUS);
904 1.1.2.1 cliff
905 1.1.2.1 cliff #ifdef DIAGNOSTIC
906 1.1.2.1 cliff printf("%s: error status %#x\n", __func__, error_status);
907 1.1.2.1 cliff #endif
908 1.1.2.1 cliff
909 1.1.2.1 cliff #if DDB
910 1.1.2.1 cliff Debugger();
911 1.1.2.1 cliff #endif
912 1.1.2.1 cliff
913 1.1.2.1 cliff /* XXX reset and recover? */
914 1.1.2.1 cliff
915 1.1.2.1 cliff panic("%s: error %#x\n", device_xname(sc->sc_dev), error_status);
916 1.1.2.1 cliff }
917 1.1.2.1 cliff
918 1.1.2.1 cliff /*
919 1.1.2.1 cliff * rmixl_physaddr_init_pcix:
920 1.1.2.1 cliff * called from rmixl_physaddr_init to get region addrs & sizes
921 1.1.2.1 cliff * from PCIX CFG, ECFG, IO, MEM BARs
922 1.1.2.1 cliff */
923 1.1.2.1 cliff void
924 1.1.2.1 cliff rmixl_physaddr_init_pcix(struct extent *ext)
925 1.1.2.1 cliff {
926 1.1.2.1 cliff u_long base;
927 1.1.2.1 cliff u_long size;
928 1.1.2.1 cliff uint32_t r;
929 1.1.2.1 cliff
930 1.1.2.1 cliff r = RMIXL_PCIXREG_READ(RMIXLR_SBC_PCIX_CFG_BAR);
931 1.1.2.1 cliff if ((r & RMIXL_PCIX_CFG_BAR_ENB) != 0) {
932 1.1.2.1 cliff base = (u_long)(RMIXL_PCIX_CFG_BAR_TO_BA((uint64_t)r)
933 1.1.2.1 cliff / (1024 * 1024));
934 1.1.2.1 cliff size = (u_long)RMIXL_PCIX_CFG_SIZE / (1024 * 1024);
935 1.1.2.1 cliff DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
936 1.1.2.1 cliff __LINE__, "CFG", r, base * 1024 * 1024, size));
937 1.1.2.1 cliff if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
938 1.1.2.1 cliff panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
939 1.1.2.1 cliff "failed", __func__, ext, base, size, EX_NOWAIT);
940 1.1.2.1 cliff }
941 1.1.2.1 cliff
942 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLR_SBC_PCIX_MEM_BAR);
943 1.1.2.1 cliff if ((r & RMIXL_PCIX_MEM_BAR_ENB) != 0) {
944 1.1.2.1 cliff base = (u_long)(RMIXL_PCIX_MEM_BAR_TO_BA((uint64_t)r)
945 1.1.2.1 cliff / (1024 * 1024));
946 1.1.2.1 cliff size = (u_long)(RMIXL_PCIX_MEM_BAR_TO_SIZE((uint64_t)r)
947 1.1.2.1 cliff / (1024 * 1024));
948 1.1.2.1 cliff DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
949 1.1.2.1 cliff __LINE__, "MEM", r, base * 1024 * 1024, size));
950 1.1.2.1 cliff if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
951 1.1.2.1 cliff panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
952 1.1.2.1 cliff "failed", __func__, ext, base, size, EX_NOWAIT);
953 1.1.2.1 cliff }
954 1.1.2.1 cliff
955 1.1.2.1 cliff r = RMIXL_IOREG_READ(RMIXL_IO_DEV_BRIDGE + RMIXLR_SBC_PCIX_IO_BAR);
956 1.1.2.1 cliff if ((r & RMIXL_PCIX_IO_BAR_ENB) != 0) {
957 1.1.2.1 cliff base = (u_long)(RMIXL_PCIX_IO_BAR_TO_BA((uint64_t)r)
958 1.1.2.1 cliff / (1024 * 1024));
959 1.1.2.1 cliff size = (u_long)(RMIXL_PCIX_IO_BAR_TO_SIZE((uint64_t)r)
960 1.1.2.1 cliff / (1024 * 1024));
961 1.1.2.1 cliff DPRINTF(("%s: %d: %s: 0x%08x -- 0x%010lx:%ld MB\n", __func__,
962 1.1.2.1 cliff __LINE__, "IO", r, base * 1024 * 1024, size));
963 1.1.2.1 cliff if (extent_alloc_region(ext, base, size, EX_NOWAIT) != 0)
964 1.1.2.1 cliff panic("%s: extent_alloc_region(%p, %#lx, %#lx, %#x) "
965 1.1.2.1 cliff "failed", __func__, ext, base, size, EX_NOWAIT);
966 1.1.2.1 cliff }
967 1.1.2.1 cliff }
968 1.1.2.1 cliff
969 1.1.2.1 cliff #ifdef DDB
970 1.1.2.1 cliff int rmixl_pcix_intr_chk(void);
971 1.1.2.1 cliff int
972 1.1.2.1 cliff rmixl_pcix_intr_chk(void)
973 1.1.2.1 cliff {
974 1.1.2.1 cliff uint32_t control, status, error_status;
975 1.1.2.1 cliff
976 1.1.2.1 cliff control = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_CONTROL);
977 1.1.2.1 cliff status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_STATUS);
978 1.1.2.1 cliff error_status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_ERR_STATUS);
979 1.1.2.1 cliff
980 1.1.2.1 cliff printf("%s: %#x, %#x, %#x\n", __func__, control, status, error_status);
981 1.1.2.1 cliff
982 1.1.2.1 cliff control |= PCIX_INTR_CONTROL_DIA;
983 1.1.2.1 cliff RMIXL_PCIXREG_WRITE(RMIXL_PCIX_ECFG_INTR_CONTROL, control);
984 1.1.2.1 cliff
985 1.1.2.1 cliff control = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_CONTROL);
986 1.1.2.1 cliff status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_STATUS);
987 1.1.2.1 cliff error_status = RMIXL_PCIXREG_READ(RMIXL_PCIX_ECFG_INTR_ERR_STATUS);
988 1.1.2.1 cliff
989 1.1.2.1 cliff printf("%s: %#x, %#x, %#x\n", __func__, control, status, error_status);
990 1.1.2.1 cliff
991 1.1.2.1 cliff return 0;
992 1.1.2.1 cliff }
993 1.1.2.1 cliff #endif
994