1 /* $NetBSD: pci_eb66.c,v 1.19 2009/03/14 21:04:02 dsl Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
62 __KERNEL_RCSID(0, "$NetBSD: pci_eb66.c,v 1.19 2009/03/14 21:04:02 dsl Exp $");
64 #include <sys/types.h>
65 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/errno.h>
69 #include <sys/malloc.h>
70 #include <sys/device.h>
71 #include <sys/syslog.h>
73 #include <uvm/uvm_extern.h>
75 #include <machine/autoconf.h>
77 #include <dev/pci/pcireg.h>
78 #include <dev/pci/pcivar.h>
80 #include <alpha/pci/lcareg.h>
81 #include <alpha/pci/lcavar.h>
83 #include <alpha/pci/pci_eb66.h>
87 #include <alpha/pci/siovar.h>
90 int dec_eb66_intr_map(struct pci_attach_args
*,
92 const char *dec_eb66_intr_string(void *, pci_intr_handle_t
);
93 const struct evcnt
*dec_eb66_intr_evcnt(void *, pci_intr_handle_t
);
94 void *dec_eb66_intr_establish(void *, pci_intr_handle_t
,
95 int, int (*func
)(void *), void *);
96 void dec_eb66_intr_disestablish(void *, void *);
98 #define EB66_MAX_IRQ 32
99 #define PCI_STRAY_MAX 5
101 struct alpha_shared_intr
*eb66_pci_intr
;
103 bus_space_tag_t eb66_intrgate_iot
;
104 bus_space_handle_t eb66_intrgate_ioh
;
106 void eb66_iointr(void *arg
, unsigned long vec
);
107 extern void eb66_intr_enable(int irq
); /* pci_eb66_intr.S */
108 extern void eb66_intr_disable(int irq
); /* pci_eb66_intr.S */
111 pci_eb66_pickintr(struct lca_config
*lcp
)
113 bus_space_tag_t iot
= &lcp
->lc_iot
;
114 pci_chipset_tag_t pc
= &lcp
->lc_pc
;
119 pc
->pc_intr_map
= dec_eb66_intr_map
;
120 pc
->pc_intr_string
= dec_eb66_intr_string
;
121 pc
->pc_intr_evcnt
= dec_eb66_intr_evcnt
;
122 pc
->pc_intr_establish
= dec_eb66_intr_establish
;
123 pc
->pc_intr_disestablish
= dec_eb66_intr_disestablish
;
125 /* Not supported on the EB66. */
126 pc
->pc_pciide_compat_intr_establish
= NULL
;
128 eb66_intrgate_iot
= iot
;
129 if (bus_space_map(eb66_intrgate_iot
, 0x804, 3, 0,
130 &eb66_intrgate_ioh
) != 0)
131 panic("pci_eb66_pickintr: couldn't map interrupt PLD");
132 for (i
= 0; i
< EB66_MAX_IRQ
; i
++)
133 eb66_intr_disable(i
);
135 eb66_pci_intr
= alpha_shared_intr_alloc(EB66_MAX_IRQ
, 8);
136 for (i
= 0; i
< EB66_MAX_IRQ
; i
++) {
137 alpha_shared_intr_set_maxstrays(eb66_pci_intr
, i
,
140 cp
= alpha_shared_intr_string(eb66_pci_intr
, i
);
141 sprintf(cp
, "irq %d", i
);
142 evcnt_attach_dynamic(alpha_shared_intr_evcnt(
143 eb66_pci_intr
, i
), EVCNT_TYPE_INTR
, NULL
,
148 sio_intr_setup(pc
, iot
);
153 dec_eb66_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
155 pcitag_t bustag
= pa
->pa_intrtag
;
156 int buspin
= pa
->pa_intrpin
, line
= pa
->pa_intrline
;
157 pci_chipset_tag_t pc
= pa
->pa_pc
;
158 int bus
, device
, function
;
165 printf("dec_eb66_intr_map: bad interrupt pin %d\n", buspin
);
169 pci_decompose_tag(pc
, bustag
, &bus
, &device
, &function
);
172 * The console places the interrupt mapping in the "line" value.
173 * A value of (char)-1 indicates there is no mapping.
176 printf("dec_eb66_intr_map: no mapping for %d/%d/%d\n",
177 bus
, device
, function
);
181 if (line
>= EB66_MAX_IRQ
)
182 panic("dec_eb66_intr_map: eb66 irq too large (%d)",
190 dec_eb66_intr_string(void *lcv
, pci_intr_handle_t ih
)
192 static char irqstr
[15]; /* 11 + 2 + NULL + sanity */
194 if (ih
>= EB66_MAX_IRQ
)
195 panic("dec_eb66_intr_string: bogus eb66 IRQ 0x%lx", ih
);
196 sprintf(irqstr
, "eb66 irq %ld", ih
);
201 dec_eb66_intr_evcnt(void *lcv
, pci_intr_handle_t ih
)
204 if (ih
>= EB66_MAX_IRQ
)
205 panic("dec_eb66_intr_string: bogus eb66 IRQ 0x%lx", ih
);
206 return (alpha_shared_intr_evcnt(eb66_pci_intr
, ih
));
210 dec_eb66_intr_establish(void *lcv
, pci_intr_handle_t ih
, int level
, int (*func
)(void *), void *arg
)
214 if (ih
>= EB66_MAX_IRQ
)
215 panic("dec_eb66_intr_establish: bogus eb66 IRQ 0x%lx", ih
);
217 cookie
= alpha_shared_intr_establish(eb66_pci_intr
, ih
, IST_LEVEL
,
218 level
, func
, arg
, "eb66 irq");
220 if (cookie
!= NULL
&&
221 alpha_shared_intr_firstactive(eb66_pci_intr
, ih
)) {
222 scb_set(0x900 + SCB_IDXTOVEC(ih
), eb66_iointr
, NULL
,
224 eb66_intr_enable(ih
);
230 dec_eb66_intr_disestablish(void *lcv
, void *cookie
)
232 struct alpha_shared_intrhand
*ih
= cookie
;
233 unsigned int irq
= ih
->ih_num
;
238 alpha_shared_intr_disestablish(eb66_pci_intr
, cookie
,
240 if (alpha_shared_intr_isactive(eb66_pci_intr
, irq
) == 0) {
241 eb66_intr_disable(irq
);
242 alpha_shared_intr_set_dfltsharetype(eb66_pci_intr
, irq
,
244 scb_free(0x900 + SCB_IDXTOVEC(irq
));
251 eb66_iointr(void *arg
, unsigned long vec
)
255 irq
= SCB_VECTOIDX(vec
- 0x900);
257 if (!alpha_shared_intr_dispatch(eb66_pci_intr
, irq
)) {
258 alpha_shared_intr_stray(eb66_pci_intr
, irq
,
260 if (ALPHA_SHARED_INTR_DISABLE(eb66_pci_intr
, irq
))
261 eb66_intr_disable(irq
);
263 alpha_shared_intr_reset_strays(eb66_pci_intr
, irq
);
266 #if 0 /* THIS DOES NOT WORK! see pci_eb66_intr.S. */
267 u_int8_t eb66_intr_mask
[3] = { 0xff, 0xff, 0xff };
270 eb66_intr_enable(int irq
)
272 int byte
= (irq
/ 8), bit
= (irq
% 8);
275 printf("eb66_intr_enable: enabling %d (%d:%d)\n", irq
, byte
, bit
);
277 eb66_intr_mask
[byte
] &= ~(1 << bit
);
279 bus_space_write_1(eb66_intrgate_iot
, eb66_intrgate_ioh
, byte
,
280 eb66_intr_mask
[byte
]);
284 eb66_intr_disable(int irq
)
286 int byte
= (irq
/ 8), bit
= (irq
% 8);
289 printf("eb66_intr_disable: disabling %d (%d:%d)\n", irq
, byte
, bit
);
291 eb66_intr_mask
[byte
] |= (1 << bit
);
293 bus_space_write_1(eb66_intrgate_iot
, eb66_intrgate_ioh
, byte
,
294 eb66_intr_mask
[byte
]);