Home | History | Annotate | Line # | Download | only in pci
      1  1.21   thorpej /*	$NetBSD: pcib.c,v 1.21 2021/08/07 16:19:08 thorpej 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  *
     19   1.1   xtraeme  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1   xtraeme  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1   xtraeme  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1   xtraeme  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1   xtraeme  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1   xtraeme  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1   xtraeme  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1   xtraeme  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1   xtraeme  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1   xtraeme  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1   xtraeme  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1   xtraeme  */
     31   1.1   xtraeme 
     32   1.1   xtraeme #include <sys/cdefs.h>
     33  1.21   thorpej __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.21 2021/08/07 16:19:08 thorpej Exp $");
     34   1.1   xtraeme 
     35   1.1   xtraeme #include <sys/types.h>
     36   1.1   xtraeme #include <sys/param.h>
     37   1.1   xtraeme #include <sys/systm.h>
     38   1.1   xtraeme #include <sys/device.h>
     39   1.1   xtraeme 
     40  1.13    dyoung #include <sys/bus.h>
     41   1.1   xtraeme 
     42   1.1   xtraeme #include <dev/isa/isavar.h>
     43   1.1   xtraeme 
     44   1.1   xtraeme #include <dev/pci/pcivar.h>
     45   1.1   xtraeme #include <dev/pci/pcireg.h>
     46   1.1   xtraeme 
     47   1.1   xtraeme #include <dev/pci/pcidevs.h>
     48   1.1   xtraeme 
     49   1.1   xtraeme #include "isa.h"
     50   1.5    martin #include "pcibvar.h"
     51   1.2  jmcneill 
     52   1.7    cegger int	pcibmatch(device_t, cfdata_t, void *);
     53   1.1   xtraeme 
     54   1.8    dyoung CFATTACH_DECL3_NEW(pcib, sizeof(struct pcib_softc),
     55   1.9    dyoung     pcibmatch, pcibattach, pcibdetach, NULL, pcibrescan, pcibchilddet,
     56   1.8    dyoung     DVF_DETACH_SHUTDOWN);
     57   1.1   xtraeme 
     58   1.3    dyoung void	pcib_callback(device_t);
     59   1.1   xtraeme 
     60   1.1   xtraeme int
     61   1.7    cegger pcibmatch(device_t parent, cfdata_t match, void *aux)
     62   1.1   xtraeme {
     63   1.1   xtraeme 	struct pci_attach_args *pa = aux;
     64   1.1   xtraeme 
     65   1.1   xtraeme #if 0
     66   1.1   xtraeme 	/*
     67   1.1   xtraeme 	 * PCI-ISA bridges are matched on class/subclass.
     68   1.1   xtraeme 	 * This list contains only the bridges where correct
     69   1.1   xtraeme 	 * (or incorrect) behaviour is not yet confirmed.
     70   1.1   xtraeme 	 */
     71   1.1   xtraeme 	switch (PCI_VENDOR(pa->pa_id)) {
     72   1.1   xtraeme 	case PCI_VENDOR_INTEL:
     73   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     74   1.1   xtraeme 		case PCI_PRODUCT_INTEL_82426EX:
     75   1.1   xtraeme 		case PCI_PRODUCT_INTEL_82380AB:
     76   1.1   xtraeme 			return (1);
     77   1.1   xtraeme 		}
     78   1.1   xtraeme 		break;
     79   1.1   xtraeme 
     80   1.1   xtraeme 	case PCI_VENDOR_UMC:
     81   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     82   1.1   xtraeme 		case PCI_PRODUCT_UMC_UM8886F:
     83   1.1   xtraeme 		case PCI_PRODUCT_UMC_UM82C886:
     84   1.1   xtraeme 			return (1);
     85   1.1   xtraeme 		}
     86   1.1   xtraeme 		break;
     87   1.1   xtraeme 	case PCI_VENDOR_ALI:
     88   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     89   1.1   xtraeme 		case PCI_PRODUCT_ALI_M1449:
     90   1.1   xtraeme 		case PCI_PRODUCT_ALI_M1543:
     91   1.1   xtraeme 			return (1);
     92   1.1   xtraeme 		}
     93   1.1   xtraeme 		break;
     94   1.1   xtraeme 	case PCI_VENDOR_COMPAQ:
     95   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
     96   1.1   xtraeme 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
     97   1.1   xtraeme 			return (1);
     98   1.1   xtraeme 		}
     99   1.1   xtraeme 		break;
    100   1.1   xtraeme 	case PCI_VENDOR_VIATECH:
    101   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    102   1.1   xtraeme 		case PCI_PRODUCT_VIATECH_VT82C570MV:
    103   1.1   xtraeme 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
    104   1.1   xtraeme 			return (1);
    105   1.1   xtraeme 		}
    106   1.1   xtraeme 		break;
    107   1.1   xtraeme 	}
    108   1.1   xtraeme #endif
    109   1.1   xtraeme 
    110   1.1   xtraeme 	/*
    111   1.1   xtraeme 	 * some special cases:
    112   1.1   xtraeme 	 */
    113   1.1   xtraeme 	switch (PCI_VENDOR(pa->pa_id)) {
    114   1.1   xtraeme 	case PCI_VENDOR_INTEL:
    115   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    116   1.1   xtraeme 		case PCI_PRODUCT_INTEL_SIO:
    117   1.1   xtraeme 			/*
    118   1.1   xtraeme 			 * The Intel SIO identifies itself as a
    119   1.1   xtraeme 			 * miscellaneous prehistoric.
    120   1.1   xtraeme 			 */
    121   1.1   xtraeme 		case PCI_PRODUCT_INTEL_82371MX:
    122   1.1   xtraeme 			/*
    123   1.1   xtraeme 			 * The Intel 82371MX identifies itself erroneously as a
    124   1.1   xtraeme 			 * miscellaneous bridge.
    125   1.1   xtraeme 			 */
    126   1.1   xtraeme 		case PCI_PRODUCT_INTEL_82371AB_ISA:
    127   1.1   xtraeme 			/*
    128   1.1   xtraeme 			 * Some Intel 82371AB PCI-ISA bridge identifies
    129   1.1   xtraeme 			 * itself as miscellaneous bridge.
    130   1.1   xtraeme 			 */
    131   1.1   xtraeme 			return (1);
    132   1.1   xtraeme 		}
    133   1.1   xtraeme 		break;
    134   1.1   xtraeme 	case PCI_VENDOR_SIS:
    135   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    136   1.1   xtraeme 		case PCI_PRODUCT_SIS_85C503:
    137   1.1   xtraeme 			/*
    138   1.1   xtraeme 			 * The SIS 85C503 identifies itself as a
    139   1.1   xtraeme 			 * miscellaneous prehistoric.
    140   1.1   xtraeme 			 */
    141   1.1   xtraeme 			return (1);
    142   1.1   xtraeme 		}
    143   1.1   xtraeme 		break;
    144   1.1   xtraeme 	case PCI_VENDOR_VIATECH:
    145   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    146  1.16  jdolecek 		case PCI_PRODUCT_VIATECH_VT82C686A_PWR:
    147   1.1   xtraeme 			/*
    148  1.16  jdolecek 			 * The VIA VT82C686A Power Management Controller
    149  1.16  jdolecek 			 * identifies itself as ISA bridge, but it's wrong !
    150   1.1   xtraeme 			 */
    151   1.1   xtraeme 			return (0);
    152   1.1   xtraeme 		}
    153  1.19       mrg 		break;
    154   1.1   xtraeme 	/*
    155   1.1   xtraeme 	 * The Cyrix cs5530 PCI host bridge does not have a broken
    156   1.1   xtraeme 	 * latch on the i8254 clock core, unlike its predecessors
    157   1.1   xtraeme 	 * the cs5510 and cs5520. This reverses the setting from
    158   1.1   xtraeme 	 * i386/i386/identcpu.c where it arguably should not have
    159   1.1   xtraeme 	 * been set in the first place. XXX
    160   1.1   xtraeme 	 */
    161   1.1   xtraeme 	case PCI_VENDOR_CYRIX:
    162   1.1   xtraeme 		switch (PCI_PRODUCT(pa->pa_id)) {
    163   1.1   xtraeme 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
    164  1.17    cherry #if !defined(XENPV)
    165   1.1   xtraeme 			{
    166   1.1   xtraeme 				extern int clock_broken_latch;
    167   1.1   xtraeme 
    168   1.1   xtraeme 				clock_broken_latch = 0;
    169   1.1   xtraeme 			}
    170   1.6     joerg #endif
    171  1.18   msaitoh 			return (1);
    172   1.1   xtraeme 		}
    173   1.1   xtraeme 		break;
    174   1.1   xtraeme 	}
    175   1.1   xtraeme 
    176   1.1   xtraeme 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
    177   1.1   xtraeme 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
    178   1.1   xtraeme 		return (1);
    179   1.1   xtraeme 	}
    180   1.1   xtraeme 
    181   1.1   xtraeme 	return (0);
    182   1.1   xtraeme }
    183   1.1   xtraeme 
    184   1.1   xtraeme void
    185   1.3    dyoung pcibattach(device_t parent, device_t self, void *aux)
    186   1.1   xtraeme {
    187   1.2  jmcneill 	struct pcib_softc *sc = device_private(self);
    188   1.1   xtraeme 	struct pci_attach_args *pa = aux;
    189   1.1   xtraeme 
    190   1.1   xtraeme 	/*
    191   1.1   xtraeme 	 * Just print out a description and defer configuration
    192   1.1   xtraeme 	 * until all PCI devices have been attached.
    193   1.1   xtraeme 	 */
    194  1.14  drochner 	pci_aprint_devinfo(pa, NULL);
    195   1.1   xtraeme 
    196   1.2  jmcneill 	sc->sc_pc = pa->pa_pc;
    197   1.2  jmcneill 	sc->sc_tag = pa->pa_tag;
    198   1.2  jmcneill 
    199  1.15    plunky 	if (!pmf_device_register(self, NULL, NULL))
    200  1.15    plunky 		aprint_error_dev(self, "couldn't establish power handler\n");
    201   1.2  jmcneill 
    202   1.1   xtraeme 	config_defer(self, pcib_callback);
    203   1.1   xtraeme }
    204   1.1   xtraeme 
    205   1.3    dyoung int
    206   1.3    dyoung pcibdetach(device_t self, int flags)
    207   1.3    dyoung {
    208   1.3    dyoung 	int rc;
    209   1.3    dyoung 
    210   1.3    dyoung 	if ((rc = config_detach_children(self, flags)) != 0)
    211   1.3    dyoung 		return rc;
    212   1.3    dyoung 	pmf_device_deregister(self);
    213   1.3    dyoung 	return 0;
    214   1.3    dyoung }
    215   1.3    dyoung 
    216   1.3    dyoung void
    217   1.3    dyoung pcibchilddet(device_t self, device_t child)
    218   1.3    dyoung {
    219   1.9    dyoung 	struct pcib_softc *sc = device_private(self);
    220   1.9    dyoung 
    221   1.9    dyoung 	if (sc->sc_isabus == child)
    222   1.9    dyoung 		sc->sc_isabus = NULL;
    223   1.9    dyoung }
    224   1.9    dyoung 
    225   1.9    dyoung int
    226   1.9    dyoung pcibrescan(device_t self, const char *ifattr, const int *loc)
    227   1.1   xtraeme {
    228   1.9    dyoung 	struct pcib_softc *sc = device_private(self);
    229   1.1   xtraeme 	struct isabus_attach_args iba;
    230   1.1   xtraeme 
    231  1.20   thorpej 	/*
    232  1.20   thorpej 	 * Even though pcib only has a single "isabus" interface
    233  1.20   thorpej 	 * attribute, this function is referenced by other drivers
    234  1.20   thorpej 	 * that carry more, so we go ahead and filter.
    235  1.20   thorpej 	 */
    236   1.9    dyoung 	if (ifattr_match(ifattr, "isabus") && sc->sc_isabus == NULL) {
    237   1.9    dyoung 		/*
    238   1.9    dyoung 		 * Attach the ISA bus behind this bridge.
    239   1.9    dyoung 		 */
    240   1.9    dyoung 		memset(&iba, 0, sizeof(iba));
    241  1.12    dyoung 		iba.iba_iot = x86_bus_space_io;
    242  1.12    dyoung 		iba.iba_memt = x86_bus_space_mem;
    243   1.1   xtraeme #if NISA > 0
    244   1.9    dyoung 		iba.iba_dmat = &isa_bus_dma_tag;
    245   1.1   xtraeme #endif
    246   1.9    dyoung 		sc->sc_isabus =
    247  1.20   thorpej 		    config_found(self, &iba, isabusprint,
    248  1.21   thorpej 			CFARGS(.iattr = "isabus"));
    249   1.9    dyoung 	}
    250   1.9    dyoung 	return 0;
    251   1.9    dyoung }
    252   1.9    dyoung 
    253   1.9    dyoung void
    254   1.9    dyoung pcib_callback(device_t self)
    255   1.9    dyoung {
    256   1.9    dyoung 	pcibrescan(self, "isabus", NULL);
    257   1.1   xtraeme }
    258