1 /* $NetBSD: pci_kn8ae.c,v 1.23 2009/03/14 15:35:59 dsl Exp $ */
4 * Copyright (c) 1997 by Matthew Jacob
5 * NASA AMES Research Center.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35 __KERNEL_RCSID(0, "$NetBSD: pci_kn8ae.c,v 1.23 2009/03/14 15:35:59 dsl Exp $");
37 #include <sys/types.h>
38 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/errno.h>
42 #include <sys/malloc.h>
43 #include <sys/device.h>
44 #include <sys/syslog.h>
46 #include <uvm/uvm_extern.h>
48 #include <machine/autoconf.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcivar.h>
53 #include <alpha/pci/dwlpxreg.h>
54 #include <alpha/pci/dwlpxvar.h>
55 #include <alpha/pci/pci_kn8ae.h>
57 int dec_kn8ae_intr_map(struct pci_attach_args
*,
59 const char *dec_kn8ae_intr_string(void *, pci_intr_handle_t
);
60 const struct evcnt
*dec_kn8ae_intr_evcnt(void *, pci_intr_handle_t
);
61 void *dec_kn8ae_intr_establish(void *, pci_intr_handle_t
,
62 int, int (*func
)(void *), void *);
63 void dec_kn8ae_intr_disestablish(void *, void *);
65 static u_int32_t imaskcache
[DWLPX_NIONODE
][DWLPX_NHOSE
][NHPC
];
67 void kn8ae_spurious(void *, u_long
);
68 void kn8ae_enadis_intr(struct dwlpx_config
*, pci_intr_handle_t
, int);
71 pci_kn8ae_pickintr(struct dwlpx_config
*ccp
, int first
)
74 pci_chipset_tag_t pc
= &ccp
->cc_pc
;
77 pc
->pc_intr_map
= dec_kn8ae_intr_map
;
78 pc
->pc_intr_string
= dec_kn8ae_intr_string
;
79 pc
->pc_intr_evcnt
= dec_kn8ae_intr_evcnt
;
80 pc
->pc_intr_establish
= dec_kn8ae_intr_establish
;
81 pc
->pc_intr_disestablish
= dec_kn8ae_intr_disestablish
;
83 /* Not supported on KN8AE. */
84 pc
->pc_pciide_compat_intr_establish
= NULL
;
90 for (io
= 0; io
< DWLPX_NIONODE
; io
++) {
91 for (hose
= 0; hose
< DWLPX_NHOSE
; hose
++) {
92 for (dev
= 0; dev
< NHPC
; dev
++) {
93 imaskcache
[io
][hose
][dev
] = DWLPX_IMASK_DFLT
;
99 #define IH_MAKE(vec, dev, pin) \
100 ((vec) | ((dev) << 16) | ((pin) << 24))
102 #define IH_VEC(ih) ((ih) & 0xffff)
103 #define IH_DEV(ih) (((ih) >> 16) & 0xff)
104 #define IH_PIN(ih) (((ih) >> 24) & 0xff)
107 dec_kn8ae_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
109 pcitag_t bustag
= pa
->pa_intrtag
;
110 int buspin
= pa
->pa_intrpin
;
111 pci_chipset_tag_t pc
= pa
->pa_pc
;
120 printf("dec_kn8ae_intr_map: bad interrupt pin %d\n", buspin
);
123 pci_decompose_tag(pc
, bustag
, NULL
, &device
, NULL
);
125 vec
= scb_alloc(kn8ae_spurious
, NULL
);
126 if (vec
== SCB_ALLOC_FAILED
) {
127 printf("dec_kn8ae_intr_map: no vector available for "
128 "device %d pin %d\n", device
, buspin
);
132 *ihp
= IH_MAKE(vec
, device
, buspin
);
138 dec_kn8ae_intr_string(void *ccv
, pci_intr_handle_t ih
)
140 static char irqstr
[64];
142 sprintf(irqstr
, "vector 0x%lx", IH_VEC(ih
));
148 dec_kn8ae_intr_evcnt(void *ccv
, pci_intr_handle_t ih
)
151 /* XXX for now, no evcnt parent reported */
156 dec_kn8ae_intr_establish(ccv
, ih
, level
, func
, arg
)
158 pci_intr_handle_t ih
;
163 struct dwlpx_config
*ccp
= ccv
;
167 int pin
, device
, hpc
;
173 scb
= &scb_iovectab
[SCB_VECTOIDX(vec
- SCB_IOVECBASE
)];
175 if (scb
->scb_func
!= kn8ae_spurious
) {
176 printf("dec_kn8ae_intr_establish: vector 0x%lx not mapped\n",
182 * NOTE: The PCIA hardware doesn't support interrupt sharing,
183 * so we don't have to worry about it (in theory, at least).
188 scb
->scb_func
= (void (*)(void *, u_long
))func
;
193 } else if (device
< 8) {
200 REGVAL(PCIA_DEVVEC(hpc
, device
, pin
) + ccp
->cc_sysbase
) = vec
;
202 kn8ae_enadis_intr(ccp
, ih
, 1);
204 cookie
= (void *) ih
;
210 dec_kn8ae_intr_disestablish(void *ccv
, void *cookie
)
212 struct dwlpx_config
*ccp
= ccv
;
213 pci_intr_handle_t ih
= (u_long
) cookie
;
219 scb
= &scb_iovectab
[SCB_VECTOIDX(vec
- SCB_IOVECBASE
)];
221 kn8ae_enadis_intr(ccp
, ih
, 0);
227 kn8ae_spurious(void *arg
, u_long vec
)
229 printf("Spurious interrupt on temporary interrupt vector 0x%lx\n", vec
);
233 kn8ae_enadis_intr(struct dwlpx_config
*ccp
, pci_intr_handle_t irq
, int onoff
)
235 struct dwlpx_softc
*sc
= ccp
->cc_sc
;
238 int ionode
, hose
, device
, hpc
, busp
, s
;
240 ionode
= sc
->dwlpx_node
- 4;
241 hose
= sc
->dwlpx_hosenum
;
243 device
= IH_DEV(irq
);
244 busp
= (1 << (IH_PIN(irq
) - 1));
247 paddr
|= (unsigned long) ionode
<< 36;
248 paddr
|= (unsigned long) hose
<< 34;
252 } else if (device
< 8) {
259 busp
<<= (device
<< 2);
260 val
= imaskcache
[ionode
][hose
][hpc
];
265 imaskcache
[ionode
][hose
][hpc
] = val
;
267 printf("kn8ae_%s_intr: irq %lx imsk 0x%x hpc %d TLSB node %d hose %d\n",
268 onoff
? "enable" : "disable", irq
, val
, hpc
, ionode
+ 4, hose
);
271 REGVAL(PCIA_IMASK(hpc
) + paddr
) = val
;