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