xref: /openbsd/sys/arch/i386/pci/pcib.c (revision 898184e3)
1 /*	$OpenBSD: pcib.c,v 1.23 2010/07/08 20:17:54 deraadt 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  *
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 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 
37 #include <machine/bus.h>
38 #include <dev/isa/isavar.h>
39 
40 #include <dev/pci/pcivar.h>
41 #include <dev/pci/pcireg.h>
42 
43 #include <dev/pci/pcidevs.h>
44 
45 #include "isa.h"
46 #include "pcibios.h"
47 #if NPCIBIOS > 0
48 #include <i386/pci/pcibiosvar.h>
49 #endif
50 
51 int	pcibmatch(struct device *, void *, void *);
52 void	pcibattach(struct device *, struct device *, void *);
53 void	pcib_callback(struct device *);
54 int	pcib_print(void *, const char *);
55 
56 struct cfattach pcib_ca = {
57 	sizeof(struct device), pcibmatch, pcibattach, NULL,
58 	config_activate_children
59 };
60 
61 struct cfdriver pcib_cd = {
62 	NULL, "pcib", DV_DULL
63 };
64 
65 int
66 pcibmatch(struct device *parent, void *match, void *aux)
67 {
68 	struct pci_attach_args *pa = aux;
69 
70 	switch (PCI_VENDOR(pa->pa_id)) {
71 	case PCI_VENDOR_INTEL:
72 		switch (PCI_PRODUCT(pa->pa_id)) {
73 		case PCI_PRODUCT_INTEL_SIO:
74 		case PCI_PRODUCT_INTEL_82371MX:
75 		case PCI_PRODUCT_INTEL_82371AB_ISA:
76 		case PCI_PRODUCT_INTEL_82440MX_ISA:
77 			/* The above bridges mis-identify themselves */
78 			return (1);
79 		}
80 		break;
81 	case PCI_VENDOR_SIS:
82 		switch (PCI_PRODUCT(pa->pa_id)) {
83 		case PCI_PRODUCT_SIS_85C503:
84 			/* mis-identifies itself as a miscellaneous prehistoric */
85 			return (1);
86 		}
87 		break;
88 	case PCI_VENDOR_VIATECH:
89 		switch (PCI_PRODUCT(pa->pa_id)) {
90 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
91 			/* mis-identifies itself as a ISA bridge */
92 			return (0);
93 		}
94 		break;
95 	}
96 
97 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
98 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA)
99 		return (1);
100 
101 	return (0);
102 }
103 
104 void
105 pcibattach(struct device *parent, struct device *self, void *aux)
106 {
107 	/*
108 	 * Cannot attach isa bus now; must postpone for various reasons
109 	 */
110 	printf("\n");
111 
112 	config_defer(self, pcib_callback);
113 }
114 
115 void
116 pcib_callback(struct device *self)
117 {
118 	struct isabus_attach_args iba;
119 
120 #if NPCIBIOS > 0
121 	pci_intr_post_fixup();
122 #endif
123 
124 	/*
125 	 * Attach the ISA bus behind this bridge.
126 	 */
127 	memset(&iba, 0, sizeof(iba));
128 	iba.iba_busname = "isa";
129 	iba.iba_iot = I386_BUS_SPACE_IO;
130 	iba.iba_memt = I386_BUS_SPACE_MEM;
131 #if NISADMA > 0
132 	iba.iba_dmat = &isa_bus_dma_tag;
133 #endif
134 	config_found(self, &iba, pcib_print);
135 }
136 
137 int
138 pcib_print(void *aux, const char *pnp)
139 {
140 	/* Only ISAs can attach to pcib's; easy. */
141 	if (pnp)
142 		printf("isa at %s", pnp);
143 	return (UNCONF);
144 }
145