pci_alphabook1.c revision 1.16 1 1.16 matt /* $NetBSD: pci_alphabook1.c,v 1.16 2012/02/06 02:14:15 matt Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej *
20 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
31 1.1 thorpej */
32 1.1 thorpej
33 1.1 thorpej /*
34 1.1 thorpej * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35 1.1 thorpej * All rights reserved.
36 1.1 thorpej *
37 1.1 thorpej * Authors: Jeffrey Hsu and Chris G. Demetriou
38 1.16 matt *
39 1.1 thorpej * Permission to use, copy, modify and distribute this software and
40 1.1 thorpej * its documentation is hereby granted, provided that both the copyright
41 1.1 thorpej * notice and this permission notice appear in all copies of the
42 1.1 thorpej * software, derivative works or modified versions, and any portions
43 1.1 thorpej * thereof, and that both notices appear in supporting documentation.
44 1.16 matt *
45 1.16 matt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 1.16 matt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 1.1 thorpej * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 1.16 matt *
49 1.1 thorpej * Carnegie Mellon requests users of this software to return to
50 1.1 thorpej *
51 1.1 thorpej * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
52 1.1 thorpej * School of Computer Science
53 1.1 thorpej * Carnegie Mellon University
54 1.1 thorpej * Pittsburgh PA 15213-3890
55 1.1 thorpej *
56 1.1 thorpej * any improvements or extensions that they make and grant Carnegie the
57 1.1 thorpej * rights to redistribute these changes.
58 1.1 thorpej */
59 1.1 thorpej
60 1.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
61 1.1 thorpej
62 1.16 matt __KERNEL_RCSID(0, "$NetBSD: pci_alphabook1.c,v 1.16 2012/02/06 02:14:15 matt Exp $");
63 1.1 thorpej
64 1.1 thorpej #include <sys/types.h>
65 1.1 thorpej #include <sys/param.h>
66 1.1 thorpej #include <sys/time.h>
67 1.1 thorpej #include <sys/systm.h>
68 1.1 thorpej #include <sys/errno.h>
69 1.1 thorpej #include <sys/device.h>
70 1.5 mrg
71 1.1 thorpej #include <machine/intr.h>
72 1.1 thorpej
73 1.1 thorpej #include <dev/isa/isavar.h>
74 1.1 thorpej #include <dev/pci/pcireg.h>
75 1.1 thorpej #include <dev/pci/pcivar.h>
76 1.1 thorpej
77 1.1 thorpej #include <alpha/pci/lcavar.h>
78 1.1 thorpej
79 1.1 thorpej #include <alpha/pci/pci_alphabook1.h>
80 1.1 thorpej #include <alpha/pci/siovar.h>
81 1.1 thorpej #include <alpha/pci/sioreg.h>
82 1.1 thorpej
83 1.1 thorpej #include "sio.h"
84 1.1 thorpej
85 1.15 dyoung int dec_alphabook1_intr_map(const struct pci_attach_args *,
86 1.15 dyoung pci_intr_handle_t *);
87 1.10 dsl const char *dec_alphabook1_intr_string(void *, pci_intr_handle_t);
88 1.10 dsl const struct evcnt *dec_alphabook1_intr_evcnt(void *, pci_intr_handle_t);
89 1.10 dsl void *dec_alphabook1_intr_establish(void *, pci_intr_handle_t,
90 1.10 dsl int, int (*func)(void *), void *);
91 1.10 dsl void dec_alphabook1_intr_disestablish(void *, void *);
92 1.1 thorpej
93 1.1 thorpej #define LCA_SIO_DEVICE 7 /* XXX */
94 1.1 thorpej
95 1.1 thorpej void
96 1.11 dsl pci_alphabook1_pickintr(struct lca_config *lcp)
97 1.1 thorpej {
98 1.1 thorpej bus_space_tag_t iot = &lcp->lc_iot;
99 1.1 thorpej pci_chipset_tag_t pc = &lcp->lc_pc;
100 1.1 thorpej pcireg_t sioclass;
101 1.1 thorpej int sioII;
102 1.1 thorpej
103 1.1 thorpej /* XXX MAGIC NUMBER */
104 1.1 thorpej sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, LCA_SIO_DEVICE, 0),
105 1.1 thorpej PCI_CLASS_REG);
106 1.16 matt sioII = (sioclass & 0xff) >= 3;
107 1.1 thorpej
108 1.1 thorpej if (!sioII)
109 1.1 thorpej printf("WARNING: SIO NOT SIO II... NO BETS...\n");
110 1.1 thorpej
111 1.1 thorpej pc->pc_intr_v = lcp;
112 1.1 thorpej pc->pc_intr_map = dec_alphabook1_intr_map;
113 1.1 thorpej pc->pc_intr_string = dec_alphabook1_intr_string;
114 1.3 cgd pc->pc_intr_evcnt = dec_alphabook1_intr_evcnt;
115 1.1 thorpej pc->pc_intr_establish = dec_alphabook1_intr_establish;
116 1.1 thorpej pc->pc_intr_disestablish = dec_alphabook1_intr_disestablish;
117 1.1 thorpej
118 1.1 thorpej /* Not supported on AlphaBook. */
119 1.1 thorpej pc->pc_pciide_compat_intr_establish = NULL;
120 1.1 thorpej
121 1.1 thorpej #if NSIO
122 1.1 thorpej sio_intr_setup(pc, iot);
123 1.1 thorpej #else
124 1.1 thorpej panic("pci_alphabook1_pickintr: no I/O interrupt handler (no sio)");
125 1.1 thorpej #endif
126 1.1 thorpej }
127 1.1 thorpej
128 1.1 thorpej int
129 1.15 dyoung dec_alphabook1_intr_map(const struct pci_attach_args *pa,
130 1.15 dyoung pci_intr_handle_t *ihp)
131 1.1 thorpej {
132 1.6 sommerfe pcitag_t bustag = pa->pa_intrtag;
133 1.6 sommerfe int buspin = pa->pa_intrpin;
134 1.6 sommerfe pci_chipset_tag_t pc = pa->pa_pc;
135 1.1 thorpej int device, irq;
136 1.1 thorpej
137 1.1 thorpej if (buspin == 0) {
138 1.1 thorpej /* No IRQ used. */
139 1.1 thorpej return 1;
140 1.1 thorpej }
141 1.1 thorpej if (buspin > 4) {
142 1.1 thorpej printf("dec_alphabook1_intr_map: bad interrupt pin %d\n",
143 1.1 thorpej buspin);
144 1.1 thorpej return 1;
145 1.1 thorpej }
146 1.1 thorpej
147 1.8 thorpej pci_decompose_tag(pc, bustag, NULL, &device, NULL);
148 1.1 thorpej
149 1.1 thorpej /*
150 1.1 thorpej * There is only one interrupting PCI device on the AlphaBook: an
151 1.1 thorpej * NCR SCSI at device 6. Devices 7 and 8 are the SIO and a
152 1.1 thorpej * Cirrus PD6729 PCMCIA controller. There are no option slots
153 1.1 thorpej * available.
154 1.1 thorpej *
155 1.1 thorpej * NOTE! Apparently, there was a later AlphaBook which uses
156 1.1 thorpej * a different interrupt scheme, and has a built-in Tulip Ethernet
157 1.1 thorpej * interface! We do not handle that here!
158 1.1 thorpej */
159 1.1 thorpej
160 1.1 thorpej switch (device) {
161 1.1 thorpej case 6: /* NCR SCSI */
162 1.1 thorpej irq = 14;
163 1.1 thorpej break;
164 1.1 thorpej
165 1.1 thorpej default:
166 1.16 matt printf("dec_alphabook1_intr_map: weird device number %d\n",
167 1.1 thorpej device);
168 1.16 matt return 1;
169 1.1 thorpej }
170 1.1 thorpej
171 1.1 thorpej *ihp = irq;
172 1.1 thorpej return (0);
173 1.1 thorpej }
174 1.1 thorpej
175 1.1 thorpej const char *
176 1.11 dsl dec_alphabook1_intr_string(void *lcv, pci_intr_handle_t ih)
177 1.1 thorpej {
178 1.1 thorpej #if 0
179 1.1 thorpej struct lca_config *lcp = lcv;
180 1.1 thorpej #endif
181 1.1 thorpej
182 1.1 thorpej return sio_intr_string(NULL /*XXX*/, ih);
183 1.3 cgd }
184 1.3 cgd
185 1.3 cgd const struct evcnt *
186 1.11 dsl dec_alphabook1_intr_evcnt(void *lcv, pci_intr_handle_t ih)
187 1.3 cgd {
188 1.3 cgd #if 0
189 1.3 cgd struct lca_config *lcp = lcv;
190 1.3 cgd #endif
191 1.3 cgd
192 1.3 cgd return sio_intr_evcnt(NULL /*XXX*/, ih);
193 1.1 thorpej }
194 1.1 thorpej
195 1.1 thorpej void *
196 1.13 dsl dec_alphabook1_intr_establish(void *lcv, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg)
197 1.1 thorpej {
198 1.1 thorpej #if 0
199 1.1 thorpej struct lca_config *lcp = lcv;
200 1.1 thorpej #endif
201 1.1 thorpej
202 1.1 thorpej return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
203 1.1 thorpej arg);
204 1.1 thorpej }
205 1.1 thorpej
206 1.1 thorpej void
207 1.12 dsl dec_alphabook1_intr_disestablish(void *lcv, void *cookie)
208 1.1 thorpej {
209 1.1 thorpej #if 0
210 1.1 thorpej struct lca_config *lcp = lcv;
211 1.1 thorpej #endif
212 1.1 thorpej
213 1.1 thorpej sio_intr_disestablish(NULL /*XXX*/, cookie);
214 1.1 thorpej }
215