1/* $NetBSD: pci_alphabook1.c,v 1.20 2021/06/25 13:38:21 thorpej Exp $ */
2
3/*-
4 * Copyright (c) 1998 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 of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
19 *
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.
31 */
32
33/*
34 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
35 * All rights reserved.
36 *
37 * Authors: Jeffrey Hsu and Chris G. Demetriou
38 *
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.
44 *
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.
48 *
49 * Carnegie Mellon requests users of this software to return to
50 *
51 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
52 *  School of Computer Science
53 *  Carnegie Mellon University
54 *  Pittsburgh PA 15213-3890
55 *
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
58 */
59
60#include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
61
62__KERNEL_RCSID(0, "$NetBSD: pci_alphabook1.c,v 1.20 2021/06/25 13:38:21 thorpej Exp $");
63
64#include <sys/types.h>
65#include <sys/param.h>
66#include <sys/time.h>
67#include <sys/systm.h>
68#include <sys/errno.h>
69#include <sys/device.h>
70
71#include <machine/intr.h>
72#include <machine/rpb.h>
73
74#include <dev/isa/isavar.h>
75#include <dev/pci/pcireg.h>
76#include <dev/pci/pcivar.h>
77
78#include <alpha/pci/lcavar.h>
79
80#include <alpha/pci/siovar.h>
81#include <alpha/pci/sioreg.h>
82
83#include "sio.h"
84
85static int	dec_alphabook1_intr_map(const struct pci_attach_args *,
86		    pci_intr_handle_t *);
87
88static void
89pci_alphabook1_pickintr(void *core, bus_space_tag_t iot, bus_space_tag_t memt,
90    pci_chipset_tag_t pc)
91{
92
93	pc->pc_intr_v = core;
94	pc->pc_intr_map = dec_alphabook1_intr_map;
95	pc->pc_intr_string = sio_pci_intr_string;
96	pc->pc_intr_evcnt = sio_pci_intr_evcnt;
97	pc->pc_intr_establish = sio_pci_intr_establish;
98	pc->pc_intr_disestablish = sio_pci_intr_disestablish;
99
100	/* Not supported on AlphaBook. */
101	pc->pc_pciide_compat_intr_establish = NULL;
102
103#if NSIO
104	sio_intr_setup(pc, iot);
105#else
106	panic("pci_alphabook1_pickintr: no I/O interrupt handler (no sio)");
107#endif
108}
109ALPHA_PCI_INTR_INIT(ST_ALPHABOOK1, pci_alphabook1_pickintr)
110
111int
112dec_alphabook1_intr_map(const struct pci_attach_args *pa,
113    pci_intr_handle_t *ihp)
114{
115	pcitag_t bustag = pa->pa_intrtag;
116	int buspin = pa->pa_intrpin;
117	pci_chipset_tag_t pc = pa->pa_pc;
118	int device, irq;
119
120	if (buspin == 0) {
121		/* No IRQ used. */
122		return 1;
123	}
124	if (buspin < 0 || buspin > 4) {
125		printf("dec_alphabook1_intr_map: bad interrupt pin %d\n",
126		    buspin);
127		return 1;
128	}
129
130	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
131
132	/*
133	 * There is only one interrupting PCI device on the AlphaBook: an
134	 * NCR SCSI at device 6.  Devices 7 and 8 are the SIO and a
135	 * Cirrus PD6729 PCMCIA controller.  There are no option slots
136	 * available.
137	 *
138	 * NOTE!  Apparently, there was a later AlphaBook which uses
139	 * a different interrupt scheme, and has a built-in Tulip Ethernet
140	 * interface!  We do not handle that here!
141	 */
142
143	switch (device) {
144	case 6:					/* NCR SCSI */
145		irq = 14;
146		break;
147
148	default:
149	        printf("dec_alphabook1_intr_map: weird device number %d\n",
150		    device);
151	        return 1;
152	}
153
154	alpha_pci_intr_handle_init(ihp, irq, 0);
155	return (0);
156}
157