Home | History | Annotate | Line # | Download | only in pci
pcib.c revision 1.1.12.2
      1 /*	$NetBSD: pcib.c,v 1.1.12.2 2007/12/03 19:04:30 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.1.12.2 2007/12/03 19:04:30 ad Exp $");
     41 
     42 #include <sys/types.h>
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 
     47 #include <machine/bus.h>
     48 
     49 #include <dev/isa/isavar.h>
     50 
     51 #include <dev/pci/pcivar.h>
     52 #include <dev/pci/pcireg.h>
     53 
     54 #include <dev/pci/pcidevs.h>
     55 
     56 #include "isa.h"
     57 
     58 int	pcibmatch(struct device *, struct cfdata *, void *);
     59 void	pcibattach(struct device *, struct device *, void *);
     60 
     61 CFATTACH_DECL(pcib, sizeof(struct device),
     62     pcibmatch, pcibattach, NULL, NULL);
     63 
     64 void	pcib_callback(struct device *);
     65 
     66 int
     67 pcibmatch(struct device *parent, struct cfdata *match, void *aux)
     68 {
     69 	struct pci_attach_args *pa = aux;
     70 
     71 #if 0
     72 	/*
     73 	 * PCI-ISA bridges are matched on class/subclass.
     74 	 * This list contains only the bridges where correct
     75 	 * (or incorrect) behaviour is not yet confirmed.
     76 	 */
     77 	switch (PCI_VENDOR(pa->pa_id)) {
     78 	case PCI_VENDOR_INTEL:
     79 		switch (PCI_PRODUCT(pa->pa_id)) {
     80 		case PCI_PRODUCT_INTEL_82426EX:
     81 		case PCI_PRODUCT_INTEL_82380AB:
     82 			return (1);
     83 		}
     84 		break;
     85 
     86 	case PCI_VENDOR_UMC:
     87 		switch (PCI_PRODUCT(pa->pa_id)) {
     88 		case PCI_PRODUCT_UMC_UM8886F:
     89 		case PCI_PRODUCT_UMC_UM82C886:
     90 			return (1);
     91 		}
     92 		break;
     93 	case PCI_VENDOR_ALI:
     94 		switch (PCI_PRODUCT(pa->pa_id)) {
     95 		case PCI_PRODUCT_ALI_M1449:
     96 		case PCI_PRODUCT_ALI_M1543:
     97 			return (1);
     98 		}
     99 		break;
    100 	case PCI_VENDOR_COMPAQ:
    101 		switch (PCI_PRODUCT(pa->pa_id)) {
    102 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
    103 			return (1);
    104 		}
    105 		break;
    106 	case PCI_VENDOR_VIATECH:
    107 		switch (PCI_PRODUCT(pa->pa_id)) {
    108 		case PCI_PRODUCT_VIATECH_VT82C570MV:
    109 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    110 			return (1);
    111 		}
    112 		break;
    113 	}
    114 #endif
    115 
    116 	/*
    117 	 * some special cases:
    118 	 */
    119 	switch (PCI_VENDOR(pa->pa_id)) {
    120 	case PCI_VENDOR_INTEL:
    121 		switch (PCI_PRODUCT(pa->pa_id)) {
    122 		case PCI_PRODUCT_INTEL_SIO:
    123 			/*
    124 			 * The Intel SIO identifies itself as a
    125 			 * miscellaneous prehistoric.
    126 			 */
    127 		case PCI_PRODUCT_INTEL_82371MX:
    128 			/*
    129 			 * The Intel 82371MX identifies itself erroneously as a
    130 			 * miscellaneous bridge.
    131 			 */
    132 		case PCI_PRODUCT_INTEL_82371AB_ISA:
    133 			/*
    134 			 * Some Intel 82371AB PCI-ISA bridge identifies
    135 			 * itself as miscellaneous bridge.
    136 			 */
    137 			return (1);
    138 		}
    139 		break;
    140 	case PCI_VENDOR_SIS:
    141 		switch (PCI_PRODUCT(pa->pa_id)) {
    142 		case PCI_PRODUCT_SIS_85C503:
    143 			/*
    144 			 * The SIS 85C503 identifies itself as a
    145 			 * miscellaneous prehistoric.
    146 			 */
    147 			return (1);
    148 		}
    149 		break;
    150 	case PCI_VENDOR_VIATECH:
    151 		switch (PCI_PRODUCT(pa->pa_id)) {
    152 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
    153 			/*
    154 			 * The VIA VT82C686A SMBus Controller itself as
    155 			 * ISA bridge, but it's wrong !
    156 			 */
    157 			return (0);
    158 		}
    159 	/*
    160 	 * The Cyrix cs5530 PCI host bridge does not have a broken
    161 	 * latch on the i8254 clock core, unlike its predecessors
    162 	 * the cs5510 and cs5520. This reverses the setting from
    163 	 * i386/i386/identcpu.c where it arguably should not have
    164 	 * been set in the first place. XXX
    165 	 */
    166 	case PCI_VENDOR_CYRIX:
    167 		switch (PCI_PRODUCT(pa->pa_id)) {
    168 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
    169 			{
    170 				extern int clock_broken_latch;
    171 
    172 				clock_broken_latch = 0;
    173 			}
    174 			return(1);
    175 		}
    176 		break;
    177 	}
    178 
    179 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    180 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    181 		return (1);
    182 	}
    183 
    184 	return (0);
    185 }
    186 
    187 void
    188 pcibattach(struct device *parent, struct device *self, void *aux)
    189 {
    190 	struct pci_attach_args *pa = aux;
    191 	char devinfo[256];
    192 
    193 	aprint_naive("\n");
    194 	aprint_normal("\n");
    195 
    196 	/*
    197 	 * Just print out a description and defer configuration
    198 	 * until all PCI devices have been attached.
    199 	 */
    200 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    201 	aprint_normal("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
    202 	    PCI_REVISION(pa->pa_class));
    203 
    204 	config_defer(self, pcib_callback);
    205 }
    206 
    207 void
    208 pcib_callback(struct device *self)
    209 {
    210 	struct isabus_attach_args iba;
    211 
    212 	/*
    213 	 * Attach the ISA bus behind this bridge.
    214 	 */
    215 	memset(&iba, 0, sizeof(iba));
    216 	iba.iba_iot = X86_BUS_SPACE_IO;
    217 	iba.iba_memt = X86_BUS_SPACE_MEM;
    218 #if NISA > 0
    219 	iba.iba_dmat = &isa_bus_dma_tag;
    220 #endif
    221 	config_found_ia(self, "isabus", &iba, isabusprint);
    222 }
    223 /*	$NetBSD: pcib.c,v 1.1.12.2 2007/12/03 19:04:30 ad Exp $	*/
    224 
    225 /*-
    226  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
    227  * All rights reserved.
    228  *
    229  * This code is derived from software contributed to The NetBSD Foundation
    230  * by Jason R. Thorpe.
    231  *
    232  * Redistribution and use in source and binary forms, with or without
    233  * modification, are permitted provided that the following conditions
    234  * are met:
    235  * 1. Redistributions of source code must retain the above copyright
    236  *    notice, this list of conditions and the following disclaimer.
    237  * 2. Redistributions in binary form must reproduce the above copyright
    238  *    notice, this list of conditions and the following disclaimer in the
    239  *    documentation and/or other materials provided with the distribution.
    240  * 3. All advertising materials mentioning features or use of this software
    241  *    must display the following acknowledgement:
    242  *        This product includes software developed by the NetBSD
    243  *        Foundation, Inc. and its contributors.
    244  * 4. Neither the name of The NetBSD Foundation nor the names of its
    245  *    contributors may be used to endorse or promote products derived
    246  *    from this software without specific prior written permission.
    247  *
    248  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
    249  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    250  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    251  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
    252  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    253  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    254  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    255  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    256  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    257  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    258  * POSSIBILITY OF SUCH DAMAGE.
    259  */
    260 
    261 #include <sys/cdefs.h>
    262 __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.1.12.2 2007/12/03 19:04:30 ad Exp $");
    263 
    264 #include <sys/types.h>
    265 #include <sys/param.h>
    266 #include <sys/systm.h>
    267 #include <sys/device.h>
    268 
    269 #include <machine/bus.h>
    270 
    271 #include <dev/isa/isavar.h>
    272 
    273 #include <dev/pci/pcivar.h>
    274 #include <dev/pci/pcireg.h>
    275 
    276 #include <dev/pci/pcidevs.h>
    277 
    278 #include "isa.h"
    279 
    280 int	pcibmatch(struct device *, struct cfdata *, void *);
    281 void	pcibattach(struct device *, struct device *, void *);
    282 
    283 CFATTACH_DECL(pcib, sizeof(struct device),
    284     pcibmatch, pcibattach, NULL, NULL);
    285 
    286 void	pcib_callback(struct device *);
    287 
    288 int
    289 pcibmatch(struct device *parent, struct cfdata *match, void *aux)
    290 {
    291 	struct pci_attach_args *pa = aux;
    292 
    293 #if 0
    294 	/*
    295 	 * PCI-ISA bridges are matched on class/subclass.
    296 	 * This list contains only the bridges where correct
    297 	 * (or incorrect) behaviour is not yet confirmed.
    298 	 */
    299 	switch (PCI_VENDOR(pa->pa_id)) {
    300 	case PCI_VENDOR_INTEL:
    301 		switch (PCI_PRODUCT(pa->pa_id)) {
    302 		case PCI_PRODUCT_INTEL_82426EX:
    303 		case PCI_PRODUCT_INTEL_82380AB:
    304 			return (1);
    305 		}
    306 		break;
    307 
    308 	case PCI_VENDOR_UMC:
    309 		switch (PCI_PRODUCT(pa->pa_id)) {
    310 		case PCI_PRODUCT_UMC_UM8886F:
    311 		case PCI_PRODUCT_UMC_UM82C886:
    312 			return (1);
    313 		}
    314 		break;
    315 	case PCI_VENDOR_ALI:
    316 		switch (PCI_PRODUCT(pa->pa_id)) {
    317 		case PCI_PRODUCT_ALI_M1449:
    318 		case PCI_PRODUCT_ALI_M1543:
    319 			return (1);
    320 		}
    321 		break;
    322 	case PCI_VENDOR_COMPAQ:
    323 		switch (PCI_PRODUCT(pa->pa_id)) {
    324 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
    325 			return (1);
    326 		}
    327 		break;
    328 	case PCI_VENDOR_VIATECH:
    329 		switch (PCI_PRODUCT(pa->pa_id)) {
    330 		case PCI_PRODUCT_VIATECH_VT82C570MV:
    331 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    332 			return (1);
    333 		}
    334 		break;
    335 	}
    336 #endif
    337 
    338 	/*
    339 	 * some special cases:
    340 	 */
    341 	switch (PCI_VENDOR(pa->pa_id)) {
    342 	case PCI_VENDOR_INTEL:
    343 		switch (PCI_PRODUCT(pa->pa_id)) {
    344 		case PCI_PRODUCT_INTEL_SIO:
    345 			/*
    346 			 * The Intel SIO identifies itself as a
    347 			 * miscellaneous prehistoric.
    348 			 */
    349 		case PCI_PRODUCT_INTEL_82371MX:
    350 			/*
    351 			 * The Intel 82371MX identifies itself erroneously as a
    352 			 * miscellaneous bridge.
    353 			 */
    354 		case PCI_PRODUCT_INTEL_82371AB_ISA:
    355 			/*
    356 			 * Some Intel 82371AB PCI-ISA bridge identifies
    357 			 * itself as miscellaneous bridge.
    358 			 */
    359 			return (1);
    360 		}
    361 		break;
    362 	case PCI_VENDOR_SIS:
    363 		switch (PCI_PRODUCT(pa->pa_id)) {
    364 		case PCI_PRODUCT_SIS_85C503:
    365 			/*
    366 			 * The SIS 85C503 identifies itself as a
    367 			 * miscellaneous prehistoric.
    368 			 */
    369 			return (1);
    370 		}
    371 		break;
    372 	case PCI_VENDOR_VIATECH:
    373 		switch (PCI_PRODUCT(pa->pa_id)) {
    374 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
    375 			/*
    376 			 * The VIA VT82C686A SMBus Controller itself as
    377 			 * ISA bridge, but it's wrong !
    378 			 */
    379 			return (0);
    380 		}
    381 	/*
    382 	 * The Cyrix cs5530 PCI host bridge does not have a broken
    383 	 * latch on the i8254 clock core, unlike its predecessors
    384 	 * the cs5510 and cs5520. This reverses the setting from
    385 	 * i386/i386/identcpu.c where it arguably should not have
    386 	 * been set in the first place. XXX
    387 	 */
    388 	case PCI_VENDOR_CYRIX:
    389 		switch (PCI_PRODUCT(pa->pa_id)) {
    390 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
    391 			{
    392 				extern int clock_broken_latch;
    393 
    394 				clock_broken_latch = 0;
    395 			}
    396 			return(1);
    397 		}
    398 		break;
    399 	}
    400 
    401 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    402 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    403 		return (1);
    404 	}
    405 
    406 	return (0);
    407 }
    408 
    409 void
    410 pcibattach(struct device *parent, struct device *self, void *aux)
    411 {
    412 	struct pci_attach_args *pa = aux;
    413 	char devinfo[256];
    414 
    415 	aprint_naive("\n");
    416 	aprint_normal("\n");
    417 
    418 	/*
    419 	 * Just print out a description and defer configuration
    420 	 * until all PCI devices have been attached.
    421 	 */
    422 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    423 	aprint_normal("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
    424 	    PCI_REVISION(pa->pa_class));
    425 
    426 	config_defer(self, pcib_callback);
    427 }
    428 
    429 void
    430 pcib_callback(struct device *self)
    431 {
    432 	struct isabus_attach_args iba;
    433 
    434 	/*
    435 	 * Attach the ISA bus behind this bridge.
    436 	 */
    437 	memset(&iba, 0, sizeof(iba));
    438 	iba.iba_iot = X86_BUS_SPACE_IO;
    439 	iba.iba_memt = X86_BUS_SPACE_MEM;
    440 #if NISA > 0
    441 	iba.iba_dmat = &isa_bus_dma_tag;
    442 #endif
    443 	config_found_ia(self, "isabus", &iba, isabusprint);
    444 }
    445