pcib.c revision 1.6
1/*	$NetBSD: pcib.c,v 1.6 2002/10/02 05:07:44 thorpej Exp $	*/
2
3/*
4 * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/types.h>
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/device.h>
32#include <sys/malloc.h>
33
34#include <machine/cpu.h>
35#include <machine/bus.h>
36#include <machine/autoconf.h>
37#include <machine/intr.h>
38#include <machine/intr_machdep.h>
39
40#include <dev/pci/pcivar.h>
41#include <dev/pci/pcireg.h>
42#include <dev/pci/pcidevs.h>
43
44#include <dev/isa/isareg.h>
45
46static int	pcib_match(struct device *, struct cfdata *, void *);
47static void	pcib_attach(struct device *, struct device *, void *);
48static int	icu_intr(void *);
49
50CFATTACH_DECL(pcib, sizeof(struct device),
51    pcib_match, pcib_attach, NULL, NULL);
52
53static struct cobalt_intr icu[IO_ICUSIZE];
54
55static int
56pcib_match(parent, match, aux)
57	struct device *parent;
58	struct cfdata *match;
59	void *aux;
60{
61	struct pci_attach_args *pa = aux;
62
63	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) &&
64	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA))
65		return 1;
66
67	return 0;
68}
69
70static void
71pcib_attach(parent, self, aux)
72	struct device *parent;
73	struct device *self;
74	void *aux;
75{
76	struct pci_attach_args *pa = aux;
77	char devinfo[256];
78
79	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
80	printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo,
81					PCI_REVISION(pa->pa_class));
82
83	/*
84	 * Initialize ICU. Since we block all these interrupts with
85	 * splbio(), we can just enable all of them all the time here.
86	 */
87	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10;
88	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff;
89	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10;
90	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff;
91	wbflush();
92
93	cpu_intr_establish(4, IPL_NONE, icu_intr, NULL);
94}
95
96void *
97icu_intr_establish(irq, type, level, func, arg)
98        int irq;
99        int type;
100        int level;
101        int (*func)(void *);
102        void *arg;
103{
104	int i;
105
106	for (i = 0; i < IO_ICUSIZE; i++) {
107		if (icu[i].func == NULL) {
108			icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU;
109			icu[i].func = func;
110			icu[i].arg = arg;
111			return &icu[i];
112		}
113	}
114
115	panic("too many IRQs");
116}
117
118void
119icu_intr_disestablish(cookie)
120	void *cookie;
121{
122	struct cobalt_intr *p = cookie;
123
124	if (p->cookie_type == COBALT_COOKIE_TYPE_ICU) {
125		p->func = NULL;
126		p->arg = NULL;
127	}
128}
129
130int
131icu_intr(arg)
132	void *arg;
133{
134	int i;
135
136	for (i = 0; i < IO_ICUSIZE; i++) {
137		if (icu[i].func == NULL)
138			return 0;
139
140		(*icu[i].func)(icu[i].arg);
141	}
142
143	return 0;
144}
145