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