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