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