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