sbbrz_pci.c revision 1.1.6.2 1 1.1.6.1 rmind /* $NetBSD: sbbrz_pci.c,v 1.1.6.2 2011/04/21 01:41:14 rmind Exp $ */
2 1.1.6.1 rmind
3 1.1.6.1 rmind /*
4 1.1.6.1 rmind * Copyright 2000, 2001
5 1.1.6.1 rmind * Broadcom Corporation. All rights reserved.
6 1.1.6.1 rmind *
7 1.1.6.1 rmind * This software is furnished under license and may be used and copied only
8 1.1.6.1 rmind * in accordance with the following terms and conditions. Subject to these
9 1.1.6.1 rmind * conditions, you may download, copy, install, use, modify and distribute
10 1.1.6.1 rmind * modified or unmodified copies of this software in source and/or binary
11 1.1.6.1 rmind * form. No title or ownership is transferred hereby.
12 1.1.6.1 rmind *
13 1.1.6.1 rmind * 1) Any source code used, modified or distributed must reproduce and
14 1.1.6.1 rmind * retain this copyright notice and list of conditions as they appear in
15 1.1.6.1 rmind * the source file.
16 1.1.6.1 rmind *
17 1.1.6.1 rmind * 2) No right is granted to use any trade name, trademark, or logo of
18 1.1.6.1 rmind * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
19 1.1.6.1 rmind * trademark or logo of Broadcom Corporation may be used to endorse or
20 1.1.6.1 rmind * promote products derived from this software without the prior written
21 1.1.6.1 rmind * permission of Broadcom Corporation.
22 1.1.6.1 rmind *
23 1.1.6.1 rmind * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
24 1.1.6.1 rmind * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
25 1.1.6.1 rmind * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
26 1.1.6.1 rmind * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
27 1.1.6.1 rmind * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
28 1.1.6.1 rmind * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 1.1.6.1 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 1.1.6.1 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 1.1.6.1 rmind * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 1.1.6.1 rmind * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 1.1.6.1 rmind * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1.6.1 rmind */
35 1.1.6.1 rmind
36 1.1.6.1 rmind /* from: $NetBSD: apecs_pci.c,v 1.18 2000/06/29 08:58:45 mrg Exp */
37 1.1.6.1 rmind
38 1.1.6.1 rmind /*
39 1.1.6.1 rmind * Copyright (c) 1995, 1996 Carnegie-Mellon University.
40 1.1.6.1 rmind * All rights reserved.
41 1.1.6.1 rmind *
42 1.1.6.1 rmind * Author: Chris G. Demetriou
43 1.1.6.1 rmind *
44 1.1.6.1 rmind * Permission to use, copy, modify and distribute this software and
45 1.1.6.1 rmind * its documentation is hereby granted, provided that both the copyright
46 1.1.6.1 rmind * notice and this permission notice appear in all copies of the
47 1.1.6.1 rmind * software, derivative works or modified versions, and any portions
48 1.1.6.1 rmind * thereof, and that both notices appear in supporting documentation.
49 1.1.6.1 rmind *
50 1.1.6.1 rmind * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51 1.1.6.1 rmind * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
52 1.1.6.1 rmind * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
53 1.1.6.1 rmind *
54 1.1.6.1 rmind * Carnegie Mellon requests users of this software to return to
55 1.1.6.1 rmind *
56 1.1.6.1 rmind * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
57 1.1.6.1 rmind * School of Computer Science
58 1.1.6.1 rmind * Carnegie Mellon University
59 1.1.6.1 rmind * Pittsburgh PA 15213-3890
60 1.1.6.1 rmind *
61 1.1.6.1 rmind * any improvements or extensions that they make and grant Carnegie the
62 1.1.6.1 rmind * rights to redistribute these changes.
63 1.1.6.1 rmind */
64 1.1.6.1 rmind
65 1.1.6.1 rmind #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
66 1.1.6.1 rmind
67 1.1.6.1 rmind __KERNEL_RCSID(0, "$NetBSD: sbbrz_pci.c,v 1.1.6.2 2011/04/21 01:41:14 rmind Exp $");
68 1.1.6.1 rmind
69 1.1.6.1 rmind #include <sys/param.h>
70 1.1.6.1 rmind #include <sys/systm.h>
71 1.1.6.1 rmind #include <sys/kernel.h>
72 1.1.6.1 rmind #include <sys/device.h>
73 1.1.6.1 rmind #include <uvm/uvm_extern.h>
74 1.1.6.1 rmind
75 1.1.6.1 rmind #include <dev/pci/pcireg.h>
76 1.1.6.1 rmind #include <dev/pci/pcivar.h>
77 1.1.6.1 rmind
78 1.1.6.1 rmind #include <machine/locore.h>
79 1.1.6.1 rmind #include <mips/sibyte/include/sb1250_regs.h>
80 1.1.6.1 rmind #include <mips/sibyte/include/sb1250_scd.h>
81 1.1.6.1 rmind #include <mips/sibyte/include/sb1250_int.h>
82 1.1.6.1 rmind #include <mips/sibyte/pci/sbbrzvar.h>
83 1.1.6.1 rmind
84 1.1.6.1 rmind void sbbrz_pci_attach_hook(device_t, device_t,
85 1.1.6.1 rmind struct pcibus_attach_args *);
86 1.1.6.1 rmind static int sbbrz_pci_bus_maxdevs(void *, int);
87 1.1.6.1 rmind static pcitag_t sbbrz_pci_make_tag(void *, int, int, int);
88 1.1.6.1 rmind static void sbbrz_pci_decompose_tag(void *, pcitag_t, int *, int *, int *);
89 1.1.6.1 rmind
90 1.1.6.1 rmind static pcireg_t sbbrz_pci_conf_read(void *, pcitag_t, int);
91 1.1.6.1 rmind static void sbbrz_pci_conf_write(void *, pcitag_t, int, pcireg_t);
92 1.1.6.1 rmind #ifdef PCI_NETBSD_CONFIGURE
93 1.1.6.1 rmind static void sbbrz_pci_conf_interrupt(void *, int, int, int, int, int *);
94 1.1.6.1 rmind #endif
95 1.1.6.1 rmind
96 1.1.6.2 rmind static int sbbrz_pci_intr_map(const struct pci_attach_args *,
97 1.1.6.1 rmind pci_intr_handle_t *);
98 1.1.6.1 rmind static const char *
99 1.1.6.1 rmind sbbrz_pci_intr_string(void *, pci_intr_handle_t);
100 1.1.6.1 rmind static const struct evcnt *
101 1.1.6.1 rmind sbbrz_pci_intr_evcnt(void *, pci_intr_handle_t);
102 1.1.6.1 rmind static void * sbbrz_pci_intr_establish(void *, pci_intr_handle_t,
103 1.1.6.1 rmind int, int (*)(void *), void *);
104 1.1.6.1 rmind static void sbbrz_pci_intr_disestablish(void *, void *);
105 1.1.6.1 rmind
106 1.1.6.1 rmind
107 1.1.6.1 rmind void
108 1.1.6.1 rmind sbbrz_pci_init(pci_chipset_tag_t pc, void *v)
109 1.1.6.1 rmind {
110 1.1.6.1 rmind
111 1.1.6.1 rmind pc->pc_conf_v = v;
112 1.1.6.1 rmind pc->pc_attach_hook = sbbrz_pci_attach_hook;
113 1.1.6.1 rmind pc->pc_bus_maxdevs = sbbrz_pci_bus_maxdevs;
114 1.1.6.1 rmind pc->pc_make_tag = sbbrz_pci_make_tag;
115 1.1.6.1 rmind pc->pc_decompose_tag = sbbrz_pci_decompose_tag;
116 1.1.6.1 rmind pc->pc_conf_read = sbbrz_pci_conf_read;
117 1.1.6.1 rmind pc->pc_conf_write = sbbrz_pci_conf_write;
118 1.1.6.1 rmind pc->pc_intr_map = sbbrz_pci_intr_map;
119 1.1.6.1 rmind pc->pc_intr_string = sbbrz_pci_intr_string;
120 1.1.6.1 rmind pc->pc_intr_evcnt = sbbrz_pci_intr_evcnt;
121 1.1.6.1 rmind pc->pc_intr_establish = sbbrz_pci_intr_establish;
122 1.1.6.1 rmind pc->pc_intr_disestablish = sbbrz_pci_intr_disestablish;
123 1.1.6.1 rmind #ifdef PCI_NETBSD_CONFIGURE
124 1.1.6.1 rmind pc->pc_conf_interrupt = sbbrz_pci_conf_interrupt;
125 1.1.6.1 rmind #endif
126 1.1.6.1 rmind #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
127 1.1.6.1 rmind pc->pc_pciide_compat_intr_establish = sbbrz_pciide_compat_intr_establish;
128 1.1.6.1 rmind #endif
129 1.1.6.1 rmind }
130 1.1.6.1 rmind
131 1.1.6.1 rmind void
132 1.1.6.1 rmind sbbrz_pci_attach_hook(device_t parent, device_t self,
133 1.1.6.1 rmind struct pcibus_attach_args *pba)
134 1.1.6.1 rmind {
135 1.1.6.1 rmind }
136 1.1.6.1 rmind
137 1.1.6.1 rmind int
138 1.1.6.1 rmind sbbrz_pci_bus_maxdevs(void *cpv, int busno)
139 1.1.6.1 rmind {
140 1.1.6.1 rmind uint64_t regval;
141 1.1.6.1 rmind int host;
142 1.1.6.1 rmind
143 1.1.6.1 rmind /* If not the PCI bus directly off the 1250, always up to 32 devs. */
144 1.1.6.1 rmind if (busno != 0)
145 1.1.6.1 rmind return 32;
146 1.1.6.1 rmind
147 1.1.6.1 rmind /* If the PCI on the 1250, 32 devices if host mode, otherwise only 2. */
148 1.1.6.1 rmind regval = mips3_ld((void *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_CFG));
149 1.1.6.1 rmind host = (regval & M_SYS_PCI_HOST) != 0;
150 1.1.6.1 rmind
151 1.1.6.1 rmind return (host ? 32 : 2);
152 1.1.6.1 rmind }
153 1.1.6.1 rmind
154 1.1.6.1 rmind pcitag_t
155 1.1.6.1 rmind sbbrz_pci_make_tag(void *cpv, int b, int d, int f)
156 1.1.6.1 rmind {
157 1.1.6.1 rmind
158 1.1.6.1 rmind return (b << 16) | (d << 11) | (f << 8);
159 1.1.6.1 rmind }
160 1.1.6.1 rmind
161 1.1.6.1 rmind void
162 1.1.6.1 rmind sbbrz_pci_decompose_tag(void *cpv, pcitag_t tag,
163 1.1.6.1 rmind int *bp, int *dp, int *fp)
164 1.1.6.1 rmind {
165 1.1.6.1 rmind
166 1.1.6.1 rmind if (bp != NULL)
167 1.1.6.1 rmind *bp = (tag >> 16) & 0xff;
168 1.1.6.1 rmind if (dp != NULL)
169 1.1.6.1 rmind *dp = (tag >> 11) & 0x1f;
170 1.1.6.1 rmind if (fp != NULL)
171 1.1.6.1 rmind *fp = (tag >> 8) & 0x7;
172 1.1.6.1 rmind }
173 1.1.6.1 rmind
174 1.1.6.1 rmind pcireg_t
175 1.1.6.1 rmind sbbrz_pci_conf_read(void *cpv, pcitag_t tag, int offset)
176 1.1.6.1 rmind {
177 1.1.6.1 rmind uint64_t addr;
178 1.1.6.1 rmind
179 1.1.6.1 rmind #ifdef DIAGNOSTIC
180 1.1.6.1 rmind if ((offset & 0x3) != 0)
181 1.1.6.1 rmind panic ("pci_conf_read: misaligned");
182 1.1.6.1 rmind #endif
183 1.1.6.1 rmind
184 1.1.6.1 rmind addr = A_PHYS_LDTPCI_CFG_MATCH_BITS + tag + offset;
185 1.1.6.1 rmind addr = MIPS_PHYS_TO_XKPHYS(MIPS3_TLB_ATTR_UNCACHED, addr);
186 1.1.6.1 rmind
187 1.1.6.1 rmind __asm volatile("sync");
188 1.1.6.1 rmind
189 1.1.6.1 rmind if (badaddr64(addr, 4) != 0)
190 1.1.6.1 rmind return 0xffffffff;
191 1.1.6.1 rmind
192 1.1.6.1 rmind return mips3_lw_a64(addr);
193 1.1.6.1 rmind }
194 1.1.6.1 rmind
195 1.1.6.1 rmind void
196 1.1.6.1 rmind sbbrz_pci_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
197 1.1.6.1 rmind {
198 1.1.6.1 rmind uint64_t addr;
199 1.1.6.1 rmind
200 1.1.6.1 rmind #ifdef DIAGNOSTIC
201 1.1.6.1 rmind if ((offset & 0x3) != 0)
202 1.1.6.1 rmind panic ("pci_conf_write: misaligned");
203 1.1.6.1 rmind #endif
204 1.1.6.1 rmind
205 1.1.6.1 rmind addr = A_PHYS_LDTPCI_CFG_MATCH_BITS + tag + offset;
206 1.1.6.1 rmind addr = MIPS_PHYS_TO_XKPHYS(MIPS3_TLB_ATTR_UNCACHED, addr);
207 1.1.6.1 rmind
208 1.1.6.1 rmind return mips3_sw_a64(addr, data);
209 1.1.6.1 rmind }
210 1.1.6.1 rmind
211 1.1.6.1 rmind int
212 1.1.6.2 rmind sbbrz_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
213 1.1.6.1 rmind {
214 1.1.6.1 rmind int bus, device, func;
215 1.1.6.1 rmind sbbrz_pci_decompose_tag(NULL, pa->pa_intrtag, &bus, &device, &func);
216 1.1.6.1 rmind *ihp = 0;
217 1.1.6.1 rmind if (pa->pa_intrpin == PCI_INTERRUPT_PIN_NONE)
218 1.1.6.1 rmind return EINVAL;
219 1.1.6.1 rmind if (bus == 0) {
220 1.1.6.1 rmind *ihp = K_INT_PCI_INTA
221 1.1.6.1 rmind + (((device-5) + pa->pa_intrswiz + pa->pa_intrpin - PCI_INTERRUPT_PIN_A) % 4);
222 1.1.6.1 rmind return 0;
223 1.1.6.1 rmind }
224 1.1.6.1 rmind return EOPNOTSUPP;
225 1.1.6.1 rmind }
226 1.1.6.1 rmind
227 1.1.6.1 rmind const char *
228 1.1.6.1 rmind sbbrz_pci_intr_string(void *v, pci_intr_handle_t ih)
229 1.1.6.1 rmind {
230 1.1.6.1 rmind switch (ih) {
231 1.1.6.1 rmind default: return NULL;
232 1.1.6.1 rmind case K_INT_PCI_INTA: return "pci inta";
233 1.1.6.1 rmind case K_INT_PCI_INTB: return "pci intb";
234 1.1.6.1 rmind case K_INT_PCI_INTC: return "pci intc";
235 1.1.6.1 rmind case K_INT_PCI_INTD: return "pci intd";
236 1.1.6.1 rmind }
237 1.1.6.1 rmind }
238 1.1.6.1 rmind
239 1.1.6.1 rmind const struct evcnt *
240 1.1.6.1 rmind sbbrz_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
241 1.1.6.1 rmind {
242 1.1.6.1 rmind return NULL;
243 1.1.6.1 rmind }
244 1.1.6.1 rmind
245 1.1.6.1 rmind void *
246 1.1.6.1 rmind sbbrz_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
247 1.1.6.1 rmind int (*handler)(void *), void *arg)
248 1.1.6.1 rmind {
249 1.1.6.1 rmind return cpu_intr_establish(ih, level,
250 1.1.6.1 rmind (void (*)(void *, uint32_t, vaddr_t))handler, arg);
251 1.1.6.1 rmind }
252 1.1.6.1 rmind
253 1.1.6.1 rmind void
254 1.1.6.1 rmind sbbrz_pci_intr_disestablish(void *v, void *ih)
255 1.1.6.1 rmind {
256 1.1.6.1 rmind }
257