Home | History | Annotate | Line # | Download | only in pci
pci_subr.c revision 1.4
      1 /*	$NetBSD: pci_subr.c,v 1.4 1994/11/03 22:15:25 mycroft Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Charles Hannum.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * PCI autoconfiguration support
     34  */
     35 
     36 #include <sys/types.h>
     37 #include <sys/param.h>
     38 #include <sys/device.h>
     39 
     40 #include <i386/pci/pcivar.h>
     41 #include <i386/pci/pcireg.h>
     42 
     43 int pciprobe __P((struct device *, void *, void *));
     44 void pciattach __P((struct device *, struct device *, void *));
     45 
     46 struct cfdriver pcicd = {
     47 	NULL, "pci", pciprobe, pciattach, DV_DULL, sizeof(struct device)
     48 };
     49 
     50 int
     51 pciprobe(parent, match, aux)
     52 	struct device *parent;
     53 	void *match, *aux;
     54 {
     55 
     56 #ifdef i386
     57 	if (pci_mode_detect() == 0)
     58 		return 0;
     59 #endif
     60 	return 1;
     61 }
     62 
     63 int
     64 pciprint(aux, pci)
     65 	void *aux;
     66 	char *pci;
     67 {
     68 	register struct pci_attach_args *pa = aux;
     69 
     70 	printf("%s bus %d device %d", pci ? pci : "", pa->pa_bus,
     71 	    pa->pa_device);
     72 	if (pci)
     73 		printf(": identifier %08x class %08x", pa->pa_id,
     74 		    pa->pa_class);
     75 	return UNCONF;
     76 }
     77 
     78 void
     79 pciattach(parent, self, aux)
     80 	struct device *parent, *self;
     81 	void *aux;
     82 {
     83 	int bus, device;
     84 
     85 #ifdef i386
     86 	printf(": configuration mode %d\n", pci_mode);
     87 #else
     88 	printf("\n");
     89 #endif
     90 
     91 #if 0
     92 	for (bus = 0; bus <= 255; bus++) {
     93 #else
     94 	/*
     95 	 * XXX
     96 	 * Some current chipsets do wacky things with bus numbers > 0.
     97 	 * This seems like a violation of protocol, but the PCI BIOS does
     98 	 * allow one to query the maximum bus number, and eventually we
     99 	 * should do so.
    100 	 */
    101 	for (bus = 0; bus <= 0; bus++) {
    102 #endif
    103 #ifdef i386
    104 		for (device = 0; device <= (pci_mode == 2 ? 15 : 31);
    105 		    device++) {
    106 #else
    107 		for (device = 0; device <= 31; device++) {
    108 #endif
    109 			pcitag_t tag = pci_make_tag(bus, device, 0);
    110 			pcireg_t id = pci_conf_read(tag, PCI_ID_REG),
    111 				 class = pci_conf_read(tag, PCI_CLASS_REG);
    112 			struct pci_attach_args pa;
    113 
    114 			if (id == 0 || id == 0xffffffff)
    115 				continue;
    116 
    117 			pa.pa_bus = bus;
    118 			pa.pa_device = device;
    119 			pa.pa_tag = tag;
    120 			pa.pa_id = id;
    121 			pa.pa_class = class;
    122 
    123 			(void)config_found(self, (void *)&pa, pciprint);
    124 		}
    125 	}
    126 }
    127 
    128 int
    129 pci_targmatch(cf, pa)
    130 	struct cfdata *cf;
    131 	struct pci_attach_args *pa;
    132 {
    133 
    134 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
    135 		return 0;
    136 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
    137 		return 0;
    138 	return 1;
    139 }
    140