make PCI bus match/attach and sub-device attachment machine-independent.
This commit is contained in:
parent
92d99153a3
commit
f1f9317dfb
172
sys/dev/pci/pci.c
Normal file
172
sys/dev/pci/pci.c
Normal file
@ -0,0 +1,172 @@
|
||||
/* $NetBSD: pci.c,v 1.10 1996/02/28 01:44:41 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1996 Christopher G. Demetriou. All rights reserved.
|
||||
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Charles Hannum.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PCI bus autoconfiguration.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/device.h>
|
||||
|
||||
#include <dev/pci/pcireg.h>
|
||||
#include <dev/pci/pcivar.h>
|
||||
|
||||
struct pci_softc {
|
||||
struct device sc_dev;
|
||||
|
||||
int sc_bus;
|
||||
};
|
||||
|
||||
int pcimatch __P((struct device *, void *, void *));
|
||||
void pciattach __P((struct device *, struct device *, void *));
|
||||
|
||||
struct cfdriver pcicd = {
|
||||
NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct pci_softc)
|
||||
};
|
||||
|
||||
int pciprint __P((void *, char *));
|
||||
int pcisubmatch __P((struct device *, void *, void *));
|
||||
|
||||
int
|
||||
pcimatch(parent, match, aux)
|
||||
struct device *parent;
|
||||
void *match, *aux;
|
||||
{
|
||||
struct cfdata *cf = match;
|
||||
struct pcibus_attach_args *pba = aux;
|
||||
|
||||
if (strcmp(pba->pba_busname, cf->cf_driver->cd_name))
|
||||
return (0);
|
||||
|
||||
/* Check the locators */
|
||||
#ifdef i386 /* XXX should not be attached at root, but is on i386 */
|
||||
if (parent != NULL)
|
||||
#endif /* i386 XXX */
|
||||
if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pba->pba_bus)
|
||||
return (0);
|
||||
|
||||
/* sanity */
|
||||
if (pba->pba_bus < 0 || pba->pba_bus > 255)
|
||||
return (0);
|
||||
if (pba->pba_maxndevs < 0 || pba->pba_maxndevs > 32)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* XXX check other (hardware?) indicators
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
pciattach(parent, self, aux)
|
||||
struct device *parent, *self;
|
||||
void *aux;
|
||||
{
|
||||
struct pci_softc *sc = (struct pci_softc *)self;
|
||||
struct pcibus_attach_args *pba = aux;
|
||||
int maxndevs, device, function, nfunctions;
|
||||
|
||||
#ifdef i386 /* XXX should not be attached at root, but is on i386 */
|
||||
if (parent == NULL)
|
||||
printf(": bus %d, configuration mode %d", pba->pba_bus,
|
||||
pci_mode);
|
||||
#endif /* XXX */
|
||||
printf("\n");
|
||||
|
||||
sc->sc_bus = pba->pba_bus;
|
||||
|
||||
maxndevs = pba->pba_maxndevs;
|
||||
|
||||
for (device = 0; device < maxndevs; device++) {
|
||||
pcitag_t tag;
|
||||
pcireg_t id, class;
|
||||
struct pci_attach_args pa;
|
||||
struct cfdata *cf;
|
||||
int supported;
|
||||
|
||||
tag = pci_make_tag(sc->sc_bus, device, function);
|
||||
id = pci_conf_read(tag, PCI_ID_REG);
|
||||
if (id == 0 || id == 0xffffffff)
|
||||
continue;
|
||||
|
||||
nfunctions = 1; /* XXX */
|
||||
|
||||
for (function = 0; function < nfunctions; function++) {
|
||||
tag = pci_make_tag(sc->sc_bus, device, function);
|
||||
id = pci_conf_read(tag, PCI_ID_REG);
|
||||
if (id == 0 || id == 0xffffffff)
|
||||
continue;
|
||||
class = pci_conf_read(tag, PCI_CLASS_REG);
|
||||
|
||||
pa.pa_device = device;
|
||||
pa.pa_function = function;
|
||||
pa.pa_tag = tag;
|
||||
pa.pa_id = id;
|
||||
pa.pa_class = class;
|
||||
|
||||
config_found_sm(self, &pa, pciprint, pcisubmatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
pciprint(aux, pnp)
|
||||
void *aux;
|
||||
char *pnp;
|
||||
{
|
||||
register struct pci_attach_args *pa = aux;
|
||||
char devinfo[256];
|
||||
|
||||
if (pnp) {
|
||||
pci_devinfo(pa->pa_id, pa->pa_class, 1, devinfo);
|
||||
printf("%s at %s", devinfo, pnp);
|
||||
}
|
||||
printf(" dev %d function %d", pa->pa_device, pa->pa_function);
|
||||
return (UNCONF);
|
||||
}
|
||||
|
||||
int
|
||||
pcisubmatch(parent, match, aux)
|
||||
struct device *parent;
|
||||
void *match, *aux;
|
||||
{
|
||||
struct cfdata *cf = match;
|
||||
struct pci_attach_args *pa = aux;
|
||||
|
||||
if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_device)
|
||||
return 0;
|
||||
if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_function)
|
||||
return 0;
|
||||
return ((*cf->cf_driver->cd_match)(parent, match, aux));
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pci_subr.c,v 1.13 1996/01/22 21:08:10 cgd Exp $ */
|
||||
/* $NetBSD: pci_subr.c,v 1.14 1996/02/28 01:44:43 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1996 Christopher G. Demetriou. All rights reserved.
|
||||
@ -44,78 +44,6 @@
|
||||
#include <dev/pci/pcidevs.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
pciprint(aux, pci)
|
||||
void *aux;
|
||||
char *pci;
|
||||
{
|
||||
register struct pci_attach_args *pa = aux;
|
||||
|
||||
printf(" bus %d device %d", pa->pa_bus, pa->pa_device);
|
||||
return (UNCONF);
|
||||
}
|
||||
|
||||
int
|
||||
pcisubmatch(parent, match, aux)
|
||||
struct device *parent;
|
||||
void *match, *aux;
|
||||
{
|
||||
struct cfdata *cf = match;
|
||||
struct pci_attach_args *pa = aux;
|
||||
|
||||
if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
|
||||
return 0;
|
||||
if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
|
||||
return 0;
|
||||
return ((*cf->cf_driver->cd_match)(parent, match, aux));
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find and attach the PCI device at the give bus and device number.
|
||||
* Return 1 if successful, 0 if unsuccessful.
|
||||
*/
|
||||
int
|
||||
pci_attach_subdev(pcidev, bus, device)
|
||||
struct device *pcidev;
|
||||
int bus, device;
|
||||
{
|
||||
pcitag_t tag;
|
||||
pcireg_t id, class;
|
||||
struct pci_attach_args pa;
|
||||
struct cfdata *cf;
|
||||
int supported;
|
||||
char devinfo[256];
|
||||
|
||||
tag = pci_make_tag(bus, device, 0);
|
||||
id = pci_conf_read(tag, PCI_ID_REG);
|
||||
if (id == 0 || id == 0xffffffff)
|
||||
return (0);
|
||||
class = pci_conf_read(tag, PCI_CLASS_REG);
|
||||
|
||||
pa.pa_bus = bus;
|
||||
pa.pa_device = device;
|
||||
pa.pa_tag = tag;
|
||||
pa.pa_id = id;
|
||||
pa.pa_class = class;
|
||||
|
||||
#if defined(PCIVERBOSE) && 0 /* _too_ verbose */
|
||||
pci_devinfo(id, class, devinfo, NULL);
|
||||
printf("%s bus %d device %d: %s\n", pcidev->dv_xname, bus,
|
||||
device, devinfo);
|
||||
#endif /* _too_ verbose */
|
||||
|
||||
if ((cf = config_search(pcisubmatch, pcidev, &pa)) != NULL)
|
||||
config_attach(pcidev, cf, &pa, pciprint);
|
||||
else {
|
||||
pci_devinfo(id, class, 1, devinfo);
|
||||
printf("%s bus %d device %d: %s not configured\n",
|
||||
pcidev->dv_xname, bus, device, devinfo);
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Descriptions of known PCI classes and subclasses.
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pcivar.h,v 1.10 1996/01/22 21:08:16 cgd Exp $ */
|
||||
/* $NetBSD: pcivar.h,v 1.11 1996/02/28 01:44:44 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
||||
@ -49,11 +49,24 @@ ERROR: COMPILING FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
|
||||
#include <i386/pci/pci_machdep.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PCI bus attach arguments.
|
||||
*/
|
||||
struct pcibus_attach_args {
|
||||
char *pba_busname; /* XXX should be common */
|
||||
|
||||
int pba_bus; /* PCI bus number */
|
||||
int pba_maxndevs; /* max # of devs on bus [0..n-1] */
|
||||
};
|
||||
|
||||
/*
|
||||
* PCI device attach arguments.
|
||||
*/
|
||||
struct pci_attach_args {
|
||||
int pa_bus;
|
||||
int pa_device;
|
||||
pcitag_t pa_tag;
|
||||
pcireg_t pa_id, pa_class;
|
||||
int pa_device;
|
||||
int pa_function;
|
||||
pcitag_t pa_tag;
|
||||
pcireg_t pa_id, pa_class;
|
||||
};
|
||||
|
||||
pcireg_t pci_conf_read __P((pcitag_t, int));
|
||||
@ -62,5 +75,3 @@ void pci_devinfo __P((pcireg_t, pcireg_t, int, char *));
|
||||
pcitag_t pci_make_tag __P((int, int, int));
|
||||
void *pci_map_int __P((pcitag_t, int, int (*)(void *), void *));
|
||||
int pci_map_mem __P((pcitag_t, int, vm_offset_t *, vm_offset_t *));
|
||||
|
||||
int pci_attach_subdev __P((struct device *, int, int));
|
||||
|
Loading…
Reference in New Issue
Block a user