pcib.c revision 1.1 1 1.1 bouyer /* $NetBSD: pcib.c,v 1.1 2011/08/27 13:42:46 bouyer Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*-
4 1.1 bouyer * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5 1.1 bouyer * All rights reserved.
6 1.1 bouyer *
7 1.1 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.1 bouyer * by Jason R. Thorpe.
9 1.1 bouyer *
10 1.1 bouyer * Redistribution and use in source and binary forms, with or without
11 1.1 bouyer * modification, are permitted provided that the following conditions
12 1.1 bouyer * are met:
13 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.1 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.1 bouyer * documentation and/or other materials provided with the distribution.
18 1.1 bouyer *
19 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 bouyer * POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer */
31 1.1 bouyer
32 1.1 bouyer #include <sys/cdefs.h>
33 1.1 bouyer __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.1 2011/08/27 13:42:46 bouyer Exp $");
34 1.1 bouyer
35 1.1 bouyer #include <sys/param.h>
36 1.1 bouyer #include <sys/systm.h>
37 1.1 bouyer #include <sys/device.h>
38 1.1 bouyer
39 1.1 bouyer
40 1.1 bouyer #include <evbmips/loongson/autoconf.h>
41 1.1 bouyer
42 1.1 bouyer #include <dev/pci/pcireg.h>
43 1.1 bouyer #include <dev/pci/pcivar.h>
44 1.1 bouyer #include <dev/pci/pcidevs.h>
45 1.1 bouyer
46 1.1 bouyer #include <dev/isa/isavar.h>
47 1.1 bouyer
48 1.1 bouyer #include <evbmips/loongson/loongson_bus_defs.h>
49 1.1 bouyer #include <evbmips/loongson/dev/pcibvar.h>
50 1.1 bouyer
51 1.1 bouyer #include "isa.h"
52 1.1 bouyer
53 1.1 bouyer int pcibmatch(device_t, cfdata_t, void *);
54 1.1 bouyer void pcib_callback(device_t);
55 1.1 bouyer
56 1.1 bouyer CFATTACH_DECL3_NEW(pcib, sizeof(struct pcib_softc),
57 1.1 bouyer pcibmatch, pcibattach, pcibdetach, NULL, pcibrescan, pcibchilddet,
58 1.1 bouyer DVF_DETACH_SHUTDOWN);
59 1.1 bouyer
60 1.1 bouyer
61 1.1 bouyer int
62 1.1 bouyer pcibmatch(device_t parent, cfdata_t match, void *aux)
63 1.1 bouyer {
64 1.1 bouyer struct pci_attach_args *pa = aux;
65 1.1 bouyer
66 1.1 bouyer switch (PCI_VENDOR(pa->pa_id)) {
67 1.1 bouyer case PCI_VENDOR_INTEL:
68 1.1 bouyer switch (PCI_PRODUCT(pa->pa_id)) {
69 1.1 bouyer case PCI_PRODUCT_INTEL_SIO:
70 1.1 bouyer case PCI_PRODUCT_INTEL_82371MX:
71 1.1 bouyer case PCI_PRODUCT_INTEL_82371AB_ISA:
72 1.1 bouyer case PCI_PRODUCT_INTEL_82440MX_ISA:
73 1.1 bouyer /* The above bridges mis-identify themselves */
74 1.1 bouyer return (1);
75 1.1 bouyer }
76 1.1 bouyer break;
77 1.1 bouyer case PCI_VENDOR_SIS:
78 1.1 bouyer switch (PCI_PRODUCT(pa->pa_id)) {
79 1.1 bouyer case PCI_PRODUCT_SIS_85C503:
80 1.1 bouyer /* mis-identifies itself as a miscellaneous prehistoric */
81 1.1 bouyer return (1);
82 1.1 bouyer }
83 1.1 bouyer break;
84 1.1 bouyer case PCI_VENDOR_VIATECH:
85 1.1 bouyer switch (PCI_PRODUCT(pa->pa_id)) {
86 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
87 1.1 bouyer /* mis-identifies itself as a ISA bridge */
88 1.1 bouyer return (0);
89 1.1 bouyer }
90 1.1 bouyer break;
91 1.1 bouyer }
92 1.1 bouyer
93 1.1 bouyer if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
94 1.1 bouyer PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA)
95 1.1 bouyer return (1);
96 1.1 bouyer
97 1.1 bouyer return (0);
98 1.1 bouyer }
99 1.1 bouyer
100 1.1 bouyer void
101 1.1 bouyer pcibattach(device_t parent, device_t self, void *aux)
102 1.1 bouyer {
103 1.1 bouyer struct pcib_softc *sc = device_private(self);
104 1.1 bouyer struct pci_attach_args *pa = (struct pci_attach_args *)aux;
105 1.1 bouyer char devinfo[256];
106 1.1 bouyer
107 1.1 bouyer aprint_naive("\n");
108 1.1 bouyer
109 1.1 bouyer pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
110 1.1 bouyer aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
111 1.1 bouyer PCI_REVISION(pa->pa_class));
112 1.1 bouyer
113 1.1 bouyer /*
114 1.1 bouyer * Wait until all PCI devices are attached before attaching isa;
115 1.1 bouyer * otherwise this might mess the interrupt setup on some systems.
116 1.1 bouyer */
117 1.1 bouyer sc->sc_pc = pa->pa_pc;
118 1.1 bouyer sc->sc_tag = pa->pa_tag;
119 1.1 bouyer
120 1.1 bouyer if (!pmf_device_register(self, NULL, NULL))
121 1.1 bouyer aprint_error_dev(self, "couldn't establish power handler\n");
122 1.1 bouyer config_defer(self, pcib_callback);
123 1.1 bouyer }
124 1.1 bouyer
125 1.1 bouyer int
126 1.1 bouyer pcibdetach(device_t self, int flags)
127 1.1 bouyer {
128 1.1 bouyer int rc;
129 1.1 bouyer
130 1.1 bouyer if ((rc = config_detach_children(self, flags)) != 0)
131 1.1 bouyer return rc;
132 1.1 bouyer pmf_device_deregister(self);
133 1.1 bouyer return 0;
134 1.1 bouyer }
135 1.1 bouyer
136 1.1 bouyer void
137 1.1 bouyer pcibchilddet(device_t self, device_t child)
138 1.1 bouyer {
139 1.1 bouyer struct pcib_softc *sc = device_private(self);
140 1.1 bouyer
141 1.1 bouyer if (sc->sc_isabus == child)
142 1.1 bouyer sc->sc_isabus = NULL;
143 1.1 bouyer }
144 1.1 bouyer
145 1.1 bouyer int
146 1.1 bouyer pcibrescan(device_t self, const char *ifattr, const int *loc)
147 1.1 bouyer {
148 1.1 bouyer struct pcib_softc *sc = device_private(self);
149 1.1 bouyer struct isabus_attach_args iba;
150 1.1 bouyer
151 1.1 bouyer if (ifattr_match(ifattr, "isabus") && sc->sc_isabus == NULL) {
152 1.1 bouyer /*
153 1.1 bouyer * Attach the ISA bus behind this bridge.
154 1.1 bouyer */
155 1.1 bouyer memset(&iba, 0, sizeof(iba));
156 1.1 bouyer iba.iba_iot = &bonito_iot;
157 1.1 bouyer iba.iba_memt = &bonito_memt;
158 1.1 bouyer #if NISA > 0
159 1.1 bouyer iba.iba_dmat = &bonito_dmat;
160 1.1 bouyer #endif
161 1.1 bouyer iba.iba_ic = sys_platform->isa_chipset;
162 1.1 bouyer
163 1.1 bouyer if (iba.iba_ic != NULL)
164 1.1 bouyer sc->sc_isabus =
165 1.1 bouyer config_found_ia(self, "isabus", &iba, isabusprint);
166 1.1 bouyer }
167 1.1 bouyer return 0;
168 1.1 bouyer }
169 1.1 bouyer
170 1.1 bouyer
171 1.1 bouyer void
172 1.1 bouyer pcib_callback(device_t self)
173 1.1 bouyer {
174 1.1 bouyer pcibrescan(self, "isabus", NULL);
175 1.1 bouyer }
176