xref: /openbsd-src/sys/arch/i386/pci/pcib.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: pcib.c,v 1.8 2001/01/27 04:59:40 mickey Exp $	*/
2 /*	$NetBSD: pcib.c,v 1.6 1997/06/06 23:29:16 thorpej Exp $	*/
3 
4 /*-
5  * Copyright (c) 1996 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe.
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  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44 
45 #include <machine/bus.h>
46 #include <dev/isa/isavar.h>
47 
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
50 
51 #include <dev/pci/pcidevs.h>
52 
53 #include "isa.h"
54 #include "pcibios.h"
55 #if NPCIBIOS > 0
56 #include <i386/pci/pcibiosvar.h>
57 #endif
58 
59 int	pcibmatch __P((struct device *, void *, void *));
60 void	pcibattach __P((struct device *, struct device *, void *));
61 void	pcib_callback __P((struct device *));
62 int	pcib_print __P((void *, const char *));
63 
64 struct cfattach pcib_ca = {
65 	sizeof(struct device), pcibmatch, pcibattach
66 };
67 
68 struct cfdriver pcib_cd = {
69 	NULL, "pcib", DV_DULL
70 };
71 
72 int
73 pcibmatch(parent, match, aux)
74 	struct device *parent;
75 	void *match, *aux;
76 {
77 	struct pci_attach_args *pa = aux;
78 
79 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
80 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA)
81 		return (1);
82 
83 	switch (PCI_VENDOR(pa->pa_id)) {
84 	case PCI_VENDOR_INTEL:
85 		switch (PCI_PRODUCT(pa->pa_id)) {
86 		case PCI_PRODUCT_INTEL_SIO:
87 		case PCI_PRODUCT_INTEL_82371MX:
88 		case PCI_PRODUCT_INTEL_82371AB_ISA:
89 			/* The above bridges mis-identify themselves */
90 			return (1);
91 		}
92 	case PCI_VENDOR_SIS:
93 		switch (PCI_PRODUCT(pa->pa_id)) {
94 		case PCI_PRODUCT_SIS_85C503:
95 			/* mis-identifies itself as a miscellaneous prehistoric */
96 			return (1);
97 		}
98 	}
99 
100 	return (0);
101 }
102 
103 void
104 pcibattach(parent, self, aux)
105 	struct device *parent, *self;
106 	void *aux;
107 {
108 	/*
109 	 * Cannot attach isa bus now; must postpone for various reasons
110 	 */
111 	printf("\n");
112 
113 	config_defer(self, pcib_callback);
114 }
115 
116 void
117 pcib_callback(self)
118 	struct device *self;
119 {
120 	struct isabus_attach_args iba;
121 
122 #if NPCIBIOS > 0
123 	pci_intr_post_fixup();
124 #endif
125 
126 	/*
127 	 * Attach the ISA bus behind this bridge.
128 	 */
129 	memset(&iba, 0, sizeof(iba));
130 	iba.iba_busname = "isa";
131 	iba.iba_iot = I386_BUS_SPACE_IO;
132 	iba.iba_memt = I386_BUS_SPACE_MEM;
133 #if NISADMA > 0
134 	iba.iba_dmat = &isa_bus_dma_tag;
135 #endif
136 	config_found(self, &iba, pcib_print);
137 }
138 
139 int
140 pcib_print(aux, pnp)
141 	void *aux;
142 	const char *pnp;
143 {
144 	/* Only ISAs can attach to pcib's; easy. */
145 	if (pnp)
146 		printf("isa at %s", pnp);
147 	return (UNCONF);
148 }
149