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