xref: /netbsd-src/sys/arch/alpha/pci/pci_up1000.c (revision f0deae8ee45a2e1d4e8d5f3359e2f8072eb64a36)
1 /* $NetBSD: pci_up1000.c,v 1.17 2021/06/19 16:59:07 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.17 2021/06/19 16:59:07 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 <machine/rpb.h>
45 #include <sys/bus.h>
46 #include <machine/intr.h>
47 
48 #include <dev/isa/isavar.h>
49 
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcivar.h>
52 #include <dev/pci/pciidereg.h>
53 #include <dev/pci/pciidevar.h>
54 
55 #include <alpha/pci/irongatevar.h>
56 
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 static void
pci_up1000_pickintr(void * core,bus_space_tag_t iot,bus_space_tag_t memt,pci_chipset_tag_t pc)66 pci_up1000_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
67     pci_chipset_tag_t pc)
68 {
69 #if NSIO
70 	pc->pc_intr_v = core;
71 	pc->pc_intr_map = api_up1000_intr_map;
72 	pc->pc_intr_string = sio_pci_intr_string;
73 	pc->pc_intr_evcnt = sio_pci_intr_evcnt;
74 	pc->pc_intr_establish = sio_pci_intr_establish;
75 	pc->pc_intr_disestablish = sio_pci_intr_disestablish;
76 
77 	pc->pc_pciide_compat_intr_establish =
78 	    sio_pciide_compat_intr_establish;
79 
80 	sio_intr_setup(pc, iot);
81 #else
82 	panic("pci_up1000_pickintr: no I/O interrupt handler (no sio)");
83 #endif
84 }
ALPHA_PCI_INTR_INIT(ST_API_NAUTILUS,pci_up1000_pickintr)85 ALPHA_PCI_INTR_INIT(ST_API_NAUTILUS, pci_up1000_pickintr)
86 
87 static int
88 api_up1000_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
89 {
90 	pci_chipset_tag_t pc = pa->pa_pc;
91 	int buspin = pa->pa_intrpin;
92 	int bustag = pa->pa_intrtag;
93 	int line = pa->pa_intrline;
94 	int bus, device, function;
95 
96 	if (buspin == 0) {
97 		/* No IRQ used. */
98 		return 1;
99 	}
100 	if (buspin < 0 || buspin > 4) {
101 		printf("%s: bad interrupt pin %d\n", __func__, buspin);
102 		return 1;
103 	}
104 
105 	pci_decompose_tag(pc, bustag, &bus, &device, &function);
106 
107 	/*
108 	 * The console places the interrupt mapping in the "line" value.
109 	 * A value of (char)-1 indicates there is no mapping.
110 	 */
111 	if (line == 0xff) {
112 		printf("%s: no mapping for %d/%d/%d\n", __func__,
113 		    bus, device, function);
114 		return (1);
115 	}
116 
117 	if (line < 0 || line > 15) {
118 		printf("%s: bad ISA IRQ (%d)\n", __func__, line);
119 		return (1);
120 	}
121 	if (line == 2) {
122 		printf("%s: changed IRQ 2 to IRQ 9\n", __func__);
123 		line = 9;
124 	}
125 
126 	alpha_pci_intr_handle_init(ihp, line, 0);
127 	return (0);
128 }
129