Home | History | Annotate | Line # | Download | only in pci
pcib.c revision 1.3.2.1
      1 /*	$NetBSD: pcib.c,v 1.3.2.1 2008/05/18 12:33:04 yamt 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.3.2.1 2008/05/18 12:33:04 yamt Exp $");
     34 
     35 #include <sys/types.h>
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <machine/bus.h>
     41 
     42 #include <dev/isa/isavar.h>
     43 
     44 #include <dev/pci/pcivar.h>
     45 #include <dev/pci/pcireg.h>
     46 
     47 #include <dev/pci/pcidevs.h>
     48 
     49 #include "isa.h"
     50 
     51 struct pcib_softc {
     52 	pci_chipset_tag_t	sc_pc;
     53 	pcitag_t		sc_tag;
     54 };
     55 
     56 int	pcibmatch(device_t, struct cfdata *, void *);
     57 void	pcibattach(device_t, device_t, void *);
     58 int	pcibdetach(device_t, int);
     59 void	pcibchilddet(device_t, device_t);
     60 
     61 CFATTACH_DECL2_NEW(pcib, sizeof(struct pcib_softc),
     62     pcibmatch, pcibattach, pcibdetach, NULL, NULL, pcibchilddet);
     63 
     64 void	pcib_callback(device_t);
     65 
     66 int
     67 pcibmatch(device_t 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(device_t parent, device_t self, void *aux)
    189 {
    190 	struct pcib_softc *sc = device_private(self);
    191 	struct pci_attach_args *pa = aux;
    192 	char devinfo[256];
    193 
    194 	aprint_naive("\n");
    195 	aprint_normal("\n");
    196 
    197 	/*
    198 	 * Just print out a description and defer configuration
    199 	 * until all PCI devices have been attached.
    200 	 */
    201 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    202 	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
    203 	    PCI_REVISION(pa->pa_class));
    204 
    205 	sc->sc_pc = pa->pa_pc;
    206 	sc->sc_tag = pa->pa_tag;
    207 
    208 	/* If a more specific pcib implementation has already registered a
    209 	 * power handler, don't overwrite it.
    210 	 */
    211  	if (!device_pmf_is_registered(self)) {
    212  		if (!pmf_device_register(self, NULL, NULL))
    213  	    		aprint_error_dev(self, "couldn't establish power handler\n");
    214 	}
    215 
    216 	config_defer(self, pcib_callback);
    217 }
    218 
    219 int
    220 pcibdetach(device_t self, int flags)
    221 {
    222 	int rc;
    223 
    224 	if ((rc = config_detach_children(self, flags)) != 0)
    225 		return rc;
    226 	pmf_device_deregister(self);
    227 	return 0;
    228 }
    229 
    230 void
    231 pcibchilddet(device_t self, device_t child)
    232 {
    233 	/* we keep no references to children, so do nothing */
    234 }
    235 
    236 void
    237 pcib_callback(device_t self)
    238 {
    239 	struct isabus_attach_args iba;
    240 
    241 	/*
    242 	 * Attach the ISA bus behind this bridge.
    243 	 */
    244 	memset(&iba, 0, sizeof(iba));
    245 	iba.iba_iot = X86_BUS_SPACE_IO;
    246 	iba.iba_memt = X86_BUS_SPACE_MEM;
    247 #if NISA > 0
    248 	iba.iba_dmat = &isa_bus_dma_tag;
    249 #endif
    250 	config_found_ia(self, "isabus", &iba, isabusprint);
    251 }
    252