pcib.c revision 1.2
1/*	$NetBSD: pcib.c,v 1.2 2000/03/31 14:51:55 soren 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
39#include <dev/pci/pcivar.h>
40#include <dev/pci/pcireg.h>
41#include <dev/pci/pcidevs.h>
42
43#include <dev/isa/isareg.h>
44
45static int	pcib_match(struct device *, struct cfdata *, void *);
46static void	pcib_attach(struct device *, struct device *, void *);
47static int	icu_intr(void *);
48
49struct cfattach pcib_ca = {
50	sizeof(struct device), pcib_match, pcib_attach
51};
52
53static struct {
54        int     (*func)(void *);
55        void    *arg;
56} icu[IO_ICUSIZE];
57
58static int
59pcib_match(parent, match, aux)
60	struct device *parent;
61	struct cfdata *match;
62	void *aux;
63{
64	struct pci_attach_args *pa = aux;
65
66	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) &&
67	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA))
68		return 1;
69
70	return 0;
71}
72
73static void
74pcib_attach(parent, self, aux)
75	struct device *parent;
76	struct device *self;
77	void *aux;
78{
79	struct pci_attach_args *pa = aux;
80	char devinfo[256];
81
82	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
83	printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo,
84					PCI_REVISION(pa->pa_class));
85
86	/*
87	 * Initialize ICU. Since we block all these interrupts with
88	 * splbio(), we can just enable all of them all the time here.
89	 */
90	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10;
91	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff;
92	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10;
93	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff;
94	wbflush();
95
96	cpu_intr_establish(4, IPL_NONE, icu_intr, NULL);
97}
98
99void *
100icu_intr_establish(irq, type, level, func, arg)
101        int irq;
102        int type;
103        int level;
104        int (*func)(void *);
105        void *arg;
106{
107	int i;
108
109	for (i = 0; i <= IO_ICUSIZE; i++) {
110		if (i == IO_ICUSIZE)
111			panic("too many IRQs");
112
113		if (icu[i].func != NULL)
114			continue;
115
116		icu[i].func = func;
117		icu[i].arg = arg;
118		break;
119	}
120
121	return (void *)-1;
122}
123
124int
125icu_intr(arg)
126	void *arg;
127{
128	int i;
129
130	for (i = 0; i < IO_ICUSIZE; i++) {
131		if (icu[i].func == NULL)
132			return 0;
133
134		(*icu[i].func)(icu[i].arg);
135	}
136
137	return 0;
138}
139