Home | History | Annotate | Line # | Download | only in pci
pcib.c revision 1.2.10.1
      1  1.2.10.1       mjf /*	$NetBSD: pcib.c,v 1.2.10.1 2008/04/03 12:42:30 mjf Exp $	*/
      2       1.1   xtraeme 
      3       1.1   xtraeme /*-
      4       1.1   xtraeme  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
      5       1.1   xtraeme  * All rights reserved.
      6       1.1   xtraeme  *
      7       1.1   xtraeme  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   xtraeme  * by Jason R. Thorpe.
      9       1.1   xtraeme  *
     10       1.1   xtraeme  * Redistribution and use in source and binary forms, with or without
     11       1.1   xtraeme  * modification, are permitted provided that the following conditions
     12       1.1   xtraeme  * are met:
     13       1.1   xtraeme  * 1. Redistributions of source code must retain the above copyright
     14       1.1   xtraeme  *    notice, this list of conditions and the following disclaimer.
     15       1.1   xtraeme  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   xtraeme  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   xtraeme  *    documentation and/or other materials provided with the distribution.
     18       1.1   xtraeme  * 3. All advertising materials mentioning features or use of this software
     19       1.1   xtraeme  *    must display the following acknowledgement:
     20       1.1   xtraeme  *        This product includes software developed by the NetBSD
     21       1.1   xtraeme  *        Foundation, Inc. and its contributors.
     22       1.1   xtraeme  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   xtraeme  *    contributors may be used to endorse or promote products derived
     24       1.1   xtraeme  *    from this software without specific prior written permission.
     25       1.1   xtraeme  *
     26       1.1   xtraeme  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   xtraeme  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   xtraeme  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   xtraeme  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   xtraeme  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   xtraeme  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   xtraeme  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   xtraeme  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   xtraeme  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   xtraeme  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   xtraeme  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   xtraeme  */
     38       1.1   xtraeme 
     39       1.1   xtraeme #include <sys/cdefs.h>
     40  1.2.10.1       mjf __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.2.10.1 2008/04/03 12:42:30 mjf Exp $");
     41       1.1   xtraeme 
     42       1.1   xtraeme #include <sys/types.h>
     43       1.1   xtraeme #include <sys/param.h>
     44       1.1   xtraeme #include <sys/systm.h>
     45       1.1   xtraeme #include <sys/device.h>
     46       1.1   xtraeme 
     47       1.1   xtraeme #include <machine/bus.h>
     48       1.1   xtraeme 
     49       1.1   xtraeme #include <dev/isa/isavar.h>
     50       1.1   xtraeme 
     51       1.1   xtraeme #include <dev/pci/pcivar.h>
     52       1.1   xtraeme #include <dev/pci/pcireg.h>
     53       1.1   xtraeme 
     54       1.1   xtraeme #include <dev/pci/pcidevs.h>
     55       1.1   xtraeme 
     56       1.1   xtraeme #include "isa.h"
     57       1.1   xtraeme 
     58       1.2  jmcneill struct pcib_softc {
     59       1.2  jmcneill 	pci_chipset_tag_t	sc_pc;
     60       1.2  jmcneill 	pcitag_t		sc_tag;
     61       1.2  jmcneill };
     62       1.2  jmcneill 
     63  1.2.10.1       mjf int	pcibmatch(device_t, struct cfdata *, void *);
     64  1.2.10.1       mjf void	pcibattach(device_t, device_t, void *);
     65  1.2.10.1       mjf int	pcibdetach(device_t, int);
     66  1.2.10.1       mjf void	pcibchilddet(device_t, device_t);
     67       1.1   xtraeme 
     68  1.2.10.1       mjf CFATTACH_DECL2_NEW(pcib, sizeof(struct pcib_softc),
     69  1.2.10.1       mjf     pcibmatch, pcibattach, pcibdetach, NULL, NULL, pcibchilddet);
     70       1.1   xtraeme 
     71  1.2.10.1       mjf void	pcib_callback(device_t);
     72       1.1   xtraeme 
     73       1.1   xtraeme int
     74  1.2.10.1       mjf pcibmatch(device_t parent, struct cfdata *match, void *aux)
     75       1.1   xtraeme {
     76       1.1   xtraeme 	struct pci_attach_args *pa = aux;
     77       1.1   xtraeme 
     78       1.1   xtraeme #if 0
     79       1.1   xtraeme 	/*
     80       1.1   xtraeme 	 * PCI-ISA bridges are matched on class/subclass.
     81       1.1   xtraeme 	 * This list contains only the bridges where correct
     82       1.1   xtraeme 	 * (or incorrect) behaviour is not yet confirmed.
     83       1.1   xtraeme 	 */
     84       1.1   xtraeme 	switch (PCI_VENDOR(pa->pa_id)) {
     85       1.1   xtraeme 	case PCI_VENDOR_INTEL:
     86       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     87       1.1   xtraeme 		case PCI_PRODUCT_INTEL_82426EX:
     88       1.1   xtraeme 		case PCI_PRODUCT_INTEL_82380AB:
     89       1.1   xtraeme 			return (1);
     90       1.1   xtraeme 		}
     91       1.1   xtraeme 		break;
     92       1.1   xtraeme 
     93       1.1   xtraeme 	case PCI_VENDOR_UMC:
     94       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     95       1.1   xtraeme 		case PCI_PRODUCT_UMC_UM8886F:
     96       1.1   xtraeme 		case PCI_PRODUCT_UMC_UM82C886:
     97       1.1   xtraeme 			return (1);
     98       1.1   xtraeme 		}
     99       1.1   xtraeme 		break;
    100       1.1   xtraeme 	case PCI_VENDOR_ALI:
    101       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    102       1.1   xtraeme 		case PCI_PRODUCT_ALI_M1449:
    103       1.1   xtraeme 		case PCI_PRODUCT_ALI_M1543:
    104       1.1   xtraeme 			return (1);
    105       1.1   xtraeme 		}
    106       1.1   xtraeme 		break;
    107       1.1   xtraeme 	case PCI_VENDOR_COMPAQ:
    108       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    109       1.1   xtraeme 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
    110       1.1   xtraeme 			return (1);
    111       1.1   xtraeme 		}
    112       1.1   xtraeme 		break;
    113       1.1   xtraeme 	case PCI_VENDOR_VIATECH:
    114       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    115       1.1   xtraeme 		case PCI_PRODUCT_VIATECH_VT82C570MV:
    116       1.1   xtraeme 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    117       1.1   xtraeme 			return (1);
    118       1.1   xtraeme 		}
    119       1.1   xtraeme 		break;
    120       1.1   xtraeme 	}
    121       1.1   xtraeme #endif
    122       1.1   xtraeme 
    123       1.1   xtraeme 	/*
    124       1.1   xtraeme 	 * some special cases:
    125       1.1   xtraeme 	 */
    126       1.1   xtraeme 	switch (PCI_VENDOR(pa->pa_id)) {
    127       1.1   xtraeme 	case PCI_VENDOR_INTEL:
    128       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    129       1.1   xtraeme 		case PCI_PRODUCT_INTEL_SIO:
    130       1.1   xtraeme 			/*
    131       1.1   xtraeme 			 * The Intel SIO identifies itself as a
    132       1.1   xtraeme 			 * miscellaneous prehistoric.
    133       1.1   xtraeme 			 */
    134       1.1   xtraeme 		case PCI_PRODUCT_INTEL_82371MX:
    135       1.1   xtraeme 			/*
    136       1.1   xtraeme 			 * The Intel 82371MX identifies itself erroneously as a
    137       1.1   xtraeme 			 * miscellaneous bridge.
    138       1.1   xtraeme 			 */
    139       1.1   xtraeme 		case PCI_PRODUCT_INTEL_82371AB_ISA:
    140       1.1   xtraeme 			/*
    141       1.1   xtraeme 			 * Some Intel 82371AB PCI-ISA bridge identifies
    142       1.1   xtraeme 			 * itself as miscellaneous bridge.
    143       1.1   xtraeme 			 */
    144       1.1   xtraeme 			return (1);
    145       1.1   xtraeme 		}
    146       1.1   xtraeme 		break;
    147       1.1   xtraeme 	case PCI_VENDOR_SIS:
    148       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    149       1.1   xtraeme 		case PCI_PRODUCT_SIS_85C503:
    150       1.1   xtraeme 			/*
    151       1.1   xtraeme 			 * The SIS 85C503 identifies itself as a
    152       1.1   xtraeme 			 * miscellaneous prehistoric.
    153       1.1   xtraeme 			 */
    154       1.1   xtraeme 			return (1);
    155       1.1   xtraeme 		}
    156       1.1   xtraeme 		break;
    157       1.1   xtraeme 	case PCI_VENDOR_VIATECH:
    158       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    159       1.1   xtraeme 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
    160       1.1   xtraeme 			/*
    161       1.1   xtraeme 			 * The VIA VT82C686A SMBus Controller itself as
    162       1.1   xtraeme 			 * ISA bridge, but it's wrong !
    163       1.1   xtraeme 			 */
    164       1.1   xtraeme 			return (0);
    165       1.1   xtraeme 		}
    166       1.1   xtraeme 	/*
    167       1.1   xtraeme 	 * The Cyrix cs5530 PCI host bridge does not have a broken
    168       1.1   xtraeme 	 * latch on the i8254 clock core, unlike its predecessors
    169       1.1   xtraeme 	 * the cs5510 and cs5520. This reverses the setting from
    170       1.1   xtraeme 	 * i386/i386/identcpu.c where it arguably should not have
    171       1.1   xtraeme 	 * been set in the first place. XXX
    172       1.1   xtraeme 	 */
    173       1.1   xtraeme 	case PCI_VENDOR_CYRIX:
    174       1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    175       1.1   xtraeme 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
    176       1.1   xtraeme 			{
    177       1.1   xtraeme 				extern int clock_broken_latch;
    178       1.1   xtraeme 
    179       1.1   xtraeme 				clock_broken_latch = 0;
    180       1.1   xtraeme 			}
    181       1.1   xtraeme 			return(1);
    182       1.1   xtraeme 		}
    183       1.1   xtraeme 		break;
    184       1.1   xtraeme 	}
    185       1.1   xtraeme 
    186       1.1   xtraeme 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    187       1.1   xtraeme 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    188       1.1   xtraeme 		return (1);
    189       1.1   xtraeme 	}
    190       1.1   xtraeme 
    191       1.1   xtraeme 	return (0);
    192       1.1   xtraeme }
    193       1.1   xtraeme 
    194       1.1   xtraeme void
    195  1.2.10.1       mjf pcibattach(device_t parent, device_t self, void *aux)
    196       1.1   xtraeme {
    197       1.2  jmcneill 	struct pcib_softc *sc = device_private(self);
    198       1.1   xtraeme 	struct pci_attach_args *pa = aux;
    199       1.1   xtraeme 	char devinfo[256];
    200       1.1   xtraeme 
    201       1.1   xtraeme 	aprint_naive("\n");
    202       1.1   xtraeme 	aprint_normal("\n");
    203       1.1   xtraeme 
    204       1.1   xtraeme 	/*
    205       1.1   xtraeme 	 * Just print out a description and defer configuration
    206       1.1   xtraeme 	 * until all PCI devices have been attached.
    207       1.1   xtraeme 	 */
    208       1.1   xtraeme 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    209  1.2.10.1       mjf 	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
    210       1.1   xtraeme 	    PCI_REVISION(pa->pa_class));
    211       1.1   xtraeme 
    212       1.2  jmcneill 	sc->sc_pc = pa->pa_pc;
    213       1.2  jmcneill 	sc->sc_tag = pa->pa_tag;
    214       1.2  jmcneill 
    215       1.2  jmcneill 	/* If a more specific pcib implementation has already registered a
    216       1.2  jmcneill 	 * power handler, don't overwrite it.
    217       1.2  jmcneill 	 */
    218       1.2  jmcneill  	if (!device_pmf_is_registered(self)) {
    219       1.2  jmcneill  		if (!pmf_device_register(self, NULL, NULL))
    220       1.2  jmcneill  	    		aprint_error_dev(self, "couldn't establish power handler\n");
    221       1.2  jmcneill 	}
    222       1.2  jmcneill 
    223       1.1   xtraeme 	config_defer(self, pcib_callback);
    224       1.1   xtraeme }
    225       1.1   xtraeme 
    226  1.2.10.1       mjf int
    227  1.2.10.1       mjf pcibdetach(device_t self, int flags)
    228  1.2.10.1       mjf {
    229  1.2.10.1       mjf 	int rc;
    230  1.2.10.1       mjf 
    231  1.2.10.1       mjf 	if ((rc = config_detach_children(self, flags)) != 0)
    232  1.2.10.1       mjf 		return rc;
    233  1.2.10.1       mjf 	pmf_device_deregister(self);
    234  1.2.10.1       mjf 	return 0;
    235  1.2.10.1       mjf }
    236  1.2.10.1       mjf 
    237  1.2.10.1       mjf void
    238  1.2.10.1       mjf pcibchilddet(device_t self, device_t child)
    239  1.2.10.1       mjf {
    240  1.2.10.1       mjf 	/* we keep no references to children, so do nothing */
    241  1.2.10.1       mjf }
    242  1.2.10.1       mjf 
    243       1.1   xtraeme void
    244  1.2.10.1       mjf pcib_callback(device_t self)
    245       1.1   xtraeme {
    246       1.1   xtraeme 	struct isabus_attach_args iba;
    247       1.1   xtraeme 
    248       1.1   xtraeme 	/*
    249       1.1   xtraeme 	 * Attach the ISA bus behind this bridge.
    250       1.1   xtraeme 	 */
    251       1.1   xtraeme 	memset(&iba, 0, sizeof(iba));
    252       1.1   xtraeme 	iba.iba_iot = X86_BUS_SPACE_IO;
    253       1.1   xtraeme 	iba.iba_memt = X86_BUS_SPACE_MEM;
    254       1.1   xtraeme #if NISA > 0
    255       1.1   xtraeme 	iba.iba_dmat = &isa_bus_dma_tag;
    256       1.1   xtraeme #endif
    257       1.1   xtraeme 	config_found_ia(self, "isabus", &iba, isabusprint);
    258       1.1   xtraeme }
    259