Home | History | Annotate | Line # | Download | only in pci
pcib.c revision 1.2
      1 /*	$NetBSD: pcib.c,v 1.2 2007/12/09 20:27:49 jmcneill 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.2 2007/12/09 20:27:49 jmcneill 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 struct pcib_softc {
     59 	pci_chipset_tag_t	sc_pc;
     60 	pcitag_t		sc_tag;
     61 };
     62 
     63 int	pcibmatch(struct device *, struct cfdata *, void *);
     64 void	pcibattach(struct device *, struct device *, void *);
     65 
     66 CFATTACH_DECL_NEW(pcib, sizeof(struct pcib_softc),
     67     pcibmatch, pcibattach, NULL, NULL);
     68 
     69 void	pcib_callback(struct device *);
     70 
     71 int
     72 pcibmatch(struct device *parent, struct cfdata *match, void *aux)
     73 {
     74 	struct pci_attach_args *pa = aux;
     75 
     76 #if 0
     77 	/*
     78 	 * PCI-ISA bridges are matched on class/subclass.
     79 	 * This list contains only the bridges where correct
     80 	 * (or incorrect) behaviour is not yet confirmed.
     81 	 */
     82 	switch (PCI_VENDOR(pa->pa_id)) {
     83 	case PCI_VENDOR_INTEL:
     84 		switch (PCI_PRODUCT(pa->pa_id)) {
     85 		case PCI_PRODUCT_INTEL_82426EX:
     86 		case PCI_PRODUCT_INTEL_82380AB:
     87 			return (1);
     88 		}
     89 		break;
     90 
     91 	case PCI_VENDOR_UMC:
     92 		switch (PCI_PRODUCT(pa->pa_id)) {
     93 		case PCI_PRODUCT_UMC_UM8886F:
     94 		case PCI_PRODUCT_UMC_UM82C886:
     95 			return (1);
     96 		}
     97 		break;
     98 	case PCI_VENDOR_ALI:
     99 		switch (PCI_PRODUCT(pa->pa_id)) {
    100 		case PCI_PRODUCT_ALI_M1449:
    101 		case PCI_PRODUCT_ALI_M1543:
    102 			return (1);
    103 		}
    104 		break;
    105 	case PCI_VENDOR_COMPAQ:
    106 		switch (PCI_PRODUCT(pa->pa_id)) {
    107 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
    108 			return (1);
    109 		}
    110 		break;
    111 	case PCI_VENDOR_VIATECH:
    112 		switch (PCI_PRODUCT(pa->pa_id)) {
    113 		case PCI_PRODUCT_VIATECH_VT82C570MV:
    114 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    115 			return (1);
    116 		}
    117 		break;
    118 	}
    119 #endif
    120 
    121 	/*
    122 	 * some special cases:
    123 	 */
    124 	switch (PCI_VENDOR(pa->pa_id)) {
    125 	case PCI_VENDOR_INTEL:
    126 		switch (PCI_PRODUCT(pa->pa_id)) {
    127 		case PCI_PRODUCT_INTEL_SIO:
    128 			/*
    129 			 * The Intel SIO identifies itself as a
    130 			 * miscellaneous prehistoric.
    131 			 */
    132 		case PCI_PRODUCT_INTEL_82371MX:
    133 			/*
    134 			 * The Intel 82371MX identifies itself erroneously as a
    135 			 * miscellaneous bridge.
    136 			 */
    137 		case PCI_PRODUCT_INTEL_82371AB_ISA:
    138 			/*
    139 			 * Some Intel 82371AB PCI-ISA bridge identifies
    140 			 * itself as miscellaneous bridge.
    141 			 */
    142 			return (1);
    143 		}
    144 		break;
    145 	case PCI_VENDOR_SIS:
    146 		switch (PCI_PRODUCT(pa->pa_id)) {
    147 		case PCI_PRODUCT_SIS_85C503:
    148 			/*
    149 			 * The SIS 85C503 identifies itself as a
    150 			 * miscellaneous prehistoric.
    151 			 */
    152 			return (1);
    153 		}
    154 		break;
    155 	case PCI_VENDOR_VIATECH:
    156 		switch (PCI_PRODUCT(pa->pa_id)) {
    157 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
    158 			/*
    159 			 * The VIA VT82C686A SMBus Controller itself as
    160 			 * ISA bridge, but it's wrong !
    161 			 */
    162 			return (0);
    163 		}
    164 	/*
    165 	 * The Cyrix cs5530 PCI host bridge does not have a broken
    166 	 * latch on the i8254 clock core, unlike its predecessors
    167 	 * the cs5510 and cs5520. This reverses the setting from
    168 	 * i386/i386/identcpu.c where it arguably should not have
    169 	 * been set in the first place. XXX
    170 	 */
    171 	case PCI_VENDOR_CYRIX:
    172 		switch (PCI_PRODUCT(pa->pa_id)) {
    173 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
    174 			{
    175 				extern int clock_broken_latch;
    176 
    177 				clock_broken_latch = 0;
    178 			}
    179 			return(1);
    180 		}
    181 		break;
    182 	}
    183 
    184 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    185 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    186 		return (1);
    187 	}
    188 
    189 	return (0);
    190 }
    191 
    192 void
    193 pcibattach(struct device *parent, struct device *self, void *aux)
    194 {
    195 	struct pcib_softc *sc = device_private(self);
    196 	struct pci_attach_args *pa = aux;
    197 	char devinfo[256];
    198 
    199 	aprint_naive("\n");
    200 	aprint_normal("\n");
    201 
    202 	/*
    203 	 * Just print out a description and defer configuration
    204 	 * until all PCI devices have been attached.
    205 	 */
    206 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    207 	aprint_normal("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
    208 	    PCI_REVISION(pa->pa_class));
    209 
    210 	sc->sc_pc = pa->pa_pc;
    211 	sc->sc_tag = pa->pa_tag;
    212 
    213 	/* If a more specific pcib implementation has already registered a
    214 	 * power handler, don't overwrite it.
    215 	 */
    216  	if (!device_pmf_is_registered(self)) {
    217  		if (!pmf_device_register(self, NULL, NULL))
    218  	    		aprint_error_dev(self, "couldn't establish power handler\n");
    219 	}
    220 
    221 	config_defer(self, pcib_callback);
    222 }
    223 
    224 void
    225 pcib_callback(struct device *self)
    226 {
    227 	struct isabus_attach_args iba;
    228 
    229 	/*
    230 	 * Attach the ISA bus behind this bridge.
    231 	 */
    232 	memset(&iba, 0, sizeof(iba));
    233 	iba.iba_iot = X86_BUS_SPACE_IO;
    234 	iba.iba_memt = X86_BUS_SPACE_MEM;
    235 #if NISA > 0
    236 	iba.iba_dmat = &isa_bus_dma_tag;
    237 #endif
    238 	config_found_ia(self, "isabus", &iba, isabusprint);
    239 }
    240