pci_up1000.c revision 1.16 1 /* $NetBSD: pci_up1000.c,v 1.16 2020/09/22 15:24:02 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33
34 __KERNEL_RCSID(0, "$NetBSD: pci_up1000.c,v 1.16 2020/09/22 15:24:02 thorpej Exp $");
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/device.h>
42
43 #include <machine/autoconf.h>
44 #include <sys/bus.h>
45 #include <machine/intr.h>
46
47 #include <dev/isa/isavar.h>
48
49 #include <dev/pci/pcireg.h>
50 #include <dev/pci/pcivar.h>
51 #include <dev/pci/pciidereg.h>
52 #include <dev/pci/pciidevar.h>
53
54 #include <alpha/pci/irongatevar.h>
55
56 #include <alpha/pci/pci_up1000.h>
57 #include <alpha/pci/siovar.h>
58 #include <alpha/pci/sioreg.h>
59
60 #include "sio.h"
61
62 static int api_up1000_intr_map(const struct pci_attach_args *,
63 pci_intr_handle_t *);
64
65 void
66 pci_up1000_pickintr(struct irongate_config *icp)
67 {
68 #if NSIO
69 bus_space_tag_t iot = &icp->ic_iot;
70 pci_chipset_tag_t pc = &icp->ic_pc;
71
72 pc->pc_intr_v = icp;
73 pc->pc_intr_map = api_up1000_intr_map;
74 pc->pc_intr_string = sio_pci_intr_string;
75 pc->pc_intr_evcnt = sio_pci_intr_evcnt;
76 pc->pc_intr_establish = sio_pci_intr_establish;
77 pc->pc_intr_disestablish = sio_pci_intr_disestablish;
78
79 pc->pc_pciide_compat_intr_establish =
80 sio_pciide_compat_intr_establish;
81
82 sio_intr_setup(pc, iot);
83 #else
84 panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
85 #endif
86 }
87
88 static int
89 api_up1000_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
90 {
91 pci_chipset_tag_t pc = pa->pa_pc;
92 int buspin = pa->pa_intrpin;
93 int bustag = pa->pa_intrtag;
94 int line = pa->pa_intrline;
95 int bus, device, function;
96
97 if (buspin == 0) {
98 /* No IRQ used. */
99 return 1;
100 }
101 if (buspin < 0 || buspin > 4) {
102 printf("%s: bad interrupt pin %d\n", __func__, buspin);
103 return 1;
104 }
105
106 pci_decompose_tag(pc, bustag, &bus, &device, &function);
107
108 /*
109 * The console places the interrupt mapping in the "line" value.
110 * A value of (char)-1 indicates there is no mapping.
111 */
112 if (line == 0xff) {
113 printf("%s: no mapping for %d/%d/%d\n", __func__,
114 bus, device, function);
115 return (1);
116 }
117
118 if (line < 0 || line > 15) {
119 printf("%s: bad ISA IRQ (%d)\n", __func__, line);
120 return (1);
121 }
122 if (line == 2) {
123 printf("%s: changed IRQ 2 to IRQ 9\n", __func__);
124 line = 9;
125 }
126
127 alpha_pci_intr_handle_init(ihp, line, 0);
128 return (0);
129 }
130