Home | History | Annotate | Line # | Download | only in pci
pci.c revision 1.6
      1  1.6  mycroft /*	$NetBSD: pci.c,v 1.6 1994/11/04 09:42:22 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.5  mycroft int pcimatch __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.5  mycroft 	NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct device)
     48  1.1  mycroft };
     49  1.1  mycroft 
     50  1.1  mycroft int
     51  1.1  mycroft pciprint(aux, pci)
     52  1.1  mycroft 	void *aux;
     53  1.1  mycroft 	char *pci;
     54  1.1  mycroft {
     55  1.1  mycroft 	register struct pci_attach_args *pa = aux;
     56  1.1  mycroft 
     57  1.6  mycroft 	printf(" bus %d device %d", pa->pa_bus, pa->pa_device);
     58  1.6  mycroft 	return (UNCONF);
     59  1.6  mycroft }
     60  1.6  mycroft 
     61  1.6  mycroft int
     62  1.6  mycroft pcisubmatch(parent, match, aux)
     63  1.6  mycroft 	struct device *parent;
     64  1.6  mycroft 	void *match, *aux;
     65  1.6  mycroft {
     66  1.6  mycroft 	struct cfdata *cf = match;
     67  1.6  mycroft 	struct pci_attach_args *pa = aux;
     68  1.6  mycroft 
     69  1.6  mycroft 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
     70  1.6  mycroft 		return 0;
     71  1.6  mycroft 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
     72  1.6  mycroft 		return 0;
     73  1.6  mycroft 	return ((*cf->cf_driver->cd_match)(parent, match, aux));
     74  1.1  mycroft }
     75  1.1  mycroft 
     76  1.1  mycroft void
     77  1.1  mycroft pciattach(parent, self, aux)
     78  1.1  mycroft 	struct device *parent, *self;
     79  1.1  mycroft 	void *aux;
     80  1.1  mycroft {
     81  1.1  mycroft 	int bus, device;
     82  1.1  mycroft 
     83  1.1  mycroft #ifdef i386
     84  1.1  mycroft 	printf(": configuration mode %d\n", pci_mode);
     85  1.1  mycroft #else
     86  1.1  mycroft 	printf("\n");
     87  1.1  mycroft #endif
     88  1.1  mycroft 
     89  1.1  mycroft #if 0
     90  1.1  mycroft 	for (bus = 0; bus <= 255; bus++) {
     91  1.1  mycroft #else
     92  1.1  mycroft 	/*
     93  1.1  mycroft 	 * XXX
     94  1.1  mycroft 	 * Some current chipsets do wacky things with bus numbers > 0.
     95  1.2  mycroft 	 * This seems like a violation of protocol, but the PCI BIOS does
     96  1.2  mycroft 	 * allow one to query the maximum bus number, and eventually we
     97  1.2  mycroft 	 * should do so.
     98  1.1  mycroft 	 */
     99  1.1  mycroft 	for (bus = 0; bus <= 0; bus++) {
    100  1.1  mycroft #endif
    101  1.1  mycroft #ifdef i386
    102  1.1  mycroft 		for (device = 0; device <= (pci_mode == 2 ? 15 : 31);
    103  1.1  mycroft 		    device++) {
    104  1.1  mycroft #else
    105  1.1  mycroft 		for (device = 0; device <= 31; device++) {
    106  1.1  mycroft #endif
    107  1.1  mycroft 			pcitag_t tag = pci_make_tag(bus, device, 0);
    108  1.1  mycroft 			pcireg_t id = pci_conf_read(tag, PCI_ID_REG),
    109  1.1  mycroft 				 class = pci_conf_read(tag, PCI_CLASS_REG);
    110  1.1  mycroft 			struct pci_attach_args pa;
    111  1.6  mycroft 			struct cfdata *cf;
    112  1.1  mycroft 
    113  1.1  mycroft 			if (id == 0 || id == 0xffffffff)
    114  1.1  mycroft 				continue;
    115  1.1  mycroft 
    116  1.1  mycroft 			pa.pa_bus = bus;
    117  1.1  mycroft 			pa.pa_device = device;
    118  1.1  mycroft 			pa.pa_tag = tag;
    119  1.1  mycroft 			pa.pa_id = id;
    120  1.1  mycroft 			pa.pa_class = class;
    121  1.1  mycroft 
    122  1.6  mycroft 			if ((cf = config_search(pcisubmatch, self, &pa)) != NULL)
    123  1.6  mycroft 				config_attach(self, cf, &pa, pciprint);
    124  1.6  mycroft 			else
    125  1.6  mycroft 				printf("%s bus %d device %d: identifier %08x class %08x%s",
    126  1.6  mycroft 				    self->dv_xname, bus, device, id, class,
    127  1.6  mycroft 				    " not configured\n");
    128  1.1  mycroft 		}
    129  1.1  mycroft 	}
    130  1.1  mycroft }
    131