summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/pci/pci_axppci_33.c
blob: 3f606fd16f82a68acad75c1444aec90f45a4bea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*	$NetBSD: pci_axppci_33.c,v 1.2 1995/12/24 02:29:43 mycroft Exp $	*/

/*
 * Copyright (c) 1995 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Jeffrey Hsu
 * 
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 * 
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 * 
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/device.h>
#include <vm/vm.h>

#include <dev/isa/isavar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>

#include <alpha/pci/lcavar.h>

#include <alpha/pci/pci_axppci_33.h>

#include <alpha/pci/siovar.h>

#include "sio.h"

void    *dec_axppci_33_pci_map_int __P((void *, pci_conftag_t,
	    pci_intr_pin_t, pci_intr_line_t, int,
	    int (*func)(void *), void *));
void    dec_axppci_33_pci_unmap_int __P((void *, void *));

__const struct pci_intr_fns dec_axppci_33_pci_intr_fns = {
        dec_axppci_33_pci_map_int,
        dec_axppci_33_pci_unmap_int,
};

void *
dec_axppci_33_pci_map_int(lcv, tag, pin, line, level, func, arg)
	void *lcv;
        pci_conftag_t tag;
	pci_intr_pin_t pin;
	pci_intr_line_t line;
        int level;
        int (*func) __P((void *));
        void *arg;
{
	struct lca_config *lcp = lcv;
	int bus, device, pirq;
	pci_confreg_t irreg, pirqreg;
	u_int8_t pirqline;

        if (pin == 0) {
                /* No IRQ used. */
                return 0;
        }
        if (pin > 4) {
                printf("dec_axppci_33_map_int: bad interrupt pin %d\n", pin);
                return NULL;
        }

	device = PCI_TAG_DEVICE(tag);

	switch (device) {
	case 6:					/* NCR SCSI */
		pirq = 3;
		break;

	case 11:				/* slot 1 */
		switch (pin) {
		case PCI_INTERRUPT_PIN_A:
		case PCI_INTERRUPT_PIN_D:
			pirq = 0;
			break;
		case PCI_INTERRUPT_PIN_B:
			pirq = 2;
			break;
		case PCI_INTERRUPT_PIN_C:
			pirq = 1;
			break;
		};
		break;

	case 12:				/* slot 2 */
		switch (pin) {
		case PCI_INTERRUPT_PIN_A:
		case PCI_INTERRUPT_PIN_D:
			pirq = 1;
			break;
		case PCI_INTERRUPT_PIN_B:
			pirq = 0;
			break;
		case PCI_INTERRUPT_PIN_C:
			pirq = 2;
			break;
		};
		break;

	case 8:				/* slot 3 */
		switch (pin) {
		case PCI_INTERRUPT_PIN_A:
		case PCI_INTERRUPT_PIN_D:
			pirq = 2;
			break;
		case PCI_INTERRUPT_PIN_B:
			pirq = 1;
			break;
		case PCI_INTERRUPT_PIN_C:
			pirq = 0;
			break;
		};
		break;
	default:
		printf("dec_axppci_33_pci_map_int: unknown device %d\n",
			device);
		panic("dec_axppci_33_pci_map_int: bad device number");
	}

#define LCA_SIO_DEVICE 7		/* XXX */

	pirqreg = PCI_CONF_READ(lcp->lc_conffns, lcp->lc_confarg,
	    PCI_MAKE_TAG(0, LCA_SIO_DEVICE, 0), 0x60); /* XXX */
#if 0
	printf("dec_pci_axppci_33_map_int: device %d pin %c: pirq %d, reg = %x\n",
		device, '@' + pin, pirq, pirqreg);
#endif
	pirqline = (pirqreg >> (pirq * 8)) & 0xff;
	if ((pirqline & 0x80) != 0)
		return 0;			/* not routed? */
	pirqline &= 0xf;

#if 0
	printf("dec_pci_axppci_33_map_int: device %d pin %c: mapped to line %d\n",
	    device, '@' + pin, pirqline);
#endif

#if NSIO
	return ISA_INTR_ESTABLISH(&sio_isa_intr_fns, NULL,	/* XXX */
	    pirqline, IST_LEVEL, level, func, arg);
#else
	panic("dec_axppci_33_pci_map_int: no sio!");
#endif
}

void
dec_axppci_33_pci_unmap_int(pifa, cookie)
	void *pifa;
	void *cookie;
{

	panic("dec_axppci_33_pci_unmap_int not implemented");	/* XXX */
}

void
pci_axppci_33_pickintr(pcf, pcfa, ppf, ppfa, pifp, pifap)
        __const struct pci_conf_fns *pcf;
        __const struct pci_pio_fns *ppf;
        void *pcfa, *ppfa;
        __const struct pci_intr_fns **pifp;
        void **pifap;
{
	pci_confreg_t sioclass;
	int sioII;

	/* XXX MAGIC NUMBER */
	sioclass = PCI_CONF_READ(pcf, pcfa, PCI_MAKE_TAG(0, LCA_SIO_DEVICE, 0),
	    PCI_CLASS_REG);
        sioII = (sioclass & 0xff) >= 3;

	if (!sioII)
		printf("WARNING: SIO NOT SIO II... NO BETS...\n");

	*pifp = &dec_axppci_33_pci_intr_fns;
	*pifap = pcfa;			/* XXX assumes apecs_config ptr */
#if NSIO
        sio_intr_setup(ppf, ppfa);
	set_iointr(&sio_iointr);
#else
	panic("pci_axppci_33_pickintr: no I/O interrupt handler (no sio)");
#endif
}