1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

Encapsulate the old PCI compatability support and APIs completely under

"options COMPAT_OLDPCI".  This option already existed, but now also tidies
up the declarations in #include <pci/pci*.h>.  It is amazing how much stuff
was using the old pre-FreeBSD 3.x names and going silently undetected.
This commit is contained in:
Peter Wemm 2000-05-28 16:35:57 +00:00
parent 0a8e3ce8a5
commit 30d1c11e3a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=61047
8 changed files with 142 additions and 251 deletions

View File

@ -842,7 +842,8 @@ pci/ncr.c optional ncr
pci/ohci_pci.c optional ohci
pci/pccbb.c optional pccbb cardbus
pci/pci.c optional pci
pci/pci_compat.c optional pci
pci/pci_compat.c optional pci compat_oldpci \
warning "Old PCI driver compatability shims present."
pci/pcic_p.c optional pcic pci
pci/pcisupport.c optional pci
pci/pci_if.m optional pci

View File

@ -52,9 +52,9 @@
#include <machine/resource.h>
#include <machine/md_var.h> /* For the Alpha */
#include <sys/pciio.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
#include <sys/pciio.h>
#ifdef __alpha__
#include <machine/rpb.h>
@ -86,13 +86,6 @@ struct pci_quirk pci_quirks[] = {
#define PCI_MAPMEMP 0x02 /* prefetchable memory map */
#define PCI_MAPPORT 0x04 /* port map */
struct pci_devinfo {
STAILQ_ENTRY(pci_devinfo) pci_links;
struct resource_list resources;
pcicfgregs cfg;
struct pci_conf conf;
};
static STAILQ_HEAD(devlist, pci_devinfo) pci_devq;
u_int32_t pci_numdevs = 0;
static u_int32_t pci_generation = 0;
@ -857,101 +850,6 @@ static struct cdevsw pcicdev = {
#include "pci_if.h"
static devclass_t pci_devclass;
#ifdef COMPAT_OLDPCI
/*
* A simple driver to wrap the old pci driver mechanism for back-compat.
*/
static int
pci_compat_probe(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
const char *name;
int error;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
/*
* Do the wrapped probe.
*/
error = ENXIO;
if (dvp && dvp->pd_probe) {
name = dvp->pd_probe(cfg, (cfg->device << 16) + cfg->vendor);
if (name) {
device_set_desc_copy(dev, name);
/* Allow newbus drivers to match "better" */
error = -200;
}
}
return error;
}
static int
pci_compat_attach(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
int unit;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
unit = device_get_unit(dev);
if (unit > *dvp->pd_count)
*dvp->pd_count = unit;
if (dvp->pd_attach)
dvp->pd_attach(cfg, unit);
device_printf(dev, "driver is using old-style compatability shims\n");
return 0;
}
static device_method_t pci_compat_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, pci_compat_probe),
DEVMETHOD(device_attach, pci_compat_attach),
{ 0, 0 }
};
/*
* Create a new style driver around each old pci driver.
*/
int
compat_pci_handler(module_t mod, int type, void *data)
{
struct pci_device *dvp = (struct pci_device *)data;
driver_t *driver;
switch (type) {
case MOD_LOAD:
driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT);
if (!driver)
return ENOMEM;
bzero(driver, sizeof(driver_t));
driver->name = dvp->pd_name;
driver->methods = pci_compat_methods;
driver->size = sizeof(struct pci_devinfo *);
driver->priv = dvp;
devclass_add_driver(pci_devclass, driver);
break;
case MOD_UNLOAD:
printf("%s: module unload not supported!\n", dvp->pd_name);
return EOPNOTSUPP;
default:
break;
}
return 0;
}
#endif
/*
* New style pci driver. Parent device is either a pci-host-bridge or a
@ -1504,5 +1402,5 @@ static driver_t pci_driver = {
pci_methods,
1, /* no softc */
};
static devclass_t pci_devclass;
DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);

View File

@ -1,6 +1,3 @@
#ifndef PCI_COMPAT
#define PCI_COMPAT
#endif
/*
* Copyright (c) 1997, Stefan Esser <se@freebsd.org>
* All rights reserved.
@ -234,9 +231,13 @@
#define PCID_INTEL_SATURN 0x0483
#define PCID_INTEL_ORION 0x84c4
/* for compatibility to FreeBSD-2.2 version of PCI code */
/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */
#ifdef PCI_COMPAT
#if defined(_KERNEL) && !defined(KLD_MODULE)
#include "opt_compat_oldpci.h"
#endif
#ifdef COMPAT_OLDPCI
#define PCI_ID_REG 0x00
#define PCI_COMMAND_STATUS_REG 0x04
@ -257,4 +258,4 @@
#define PCI_MAP_IO 0x00000001
#define PCI_INTERRUPT_REG 0x3c
#endif /* PCI_COMPAT */
#endif /* COMPAT_OLDPCI */

View File

@ -30,10 +30,6 @@
#ifndef _PCIVAR_H_
#define _PCIVAR_H_
#ifndef PCI_COMPAT
#define PCI_COMPAT
#endif
#include <sys/queue.h>
/* some PCI bus constants */
@ -139,6 +135,15 @@ typedef struct {
extern u_int32_t pci_numdevs;
/* Only if the prerequisites are present */
#if defined(_SYS_BUS_H_) && defined(_SYS_PCIIO_H_)
struct pci_devinfo {
STAILQ_ENTRY(pci_devinfo) pci_links;
struct resource_list resources;
pcicfgregs cfg;
struct pci_conf conf;
};
#endif
/* externally visible functions */
@ -265,14 +270,14 @@ PCIB_ACCESSOR(hose, HOSE, u_int32_t)
#endif
/* for compatibility to FreeBSD-2.2 version of PCI code */
#ifdef PCI_COMPAT
/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */
#if defined(_KERNEL) && !defined(KLD_MODULE)
#include "opt_compat_oldpci.h"
#endif
#ifdef COMPAT_OLDPCI
/* all this is going some day */
typedef pcicfgregs *pcici_t;
@ -283,7 +288,6 @@ typedef void pci_inthand_t(void *arg);
/* just copied from old PCI code for now ... */
#ifdef COMPAT_OLDPCI
struct pci_device {
char* pd_name;
const char* (*pd_probe ) (pcici_t tag, pcidi_t type);
@ -291,7 +295,6 @@ struct pci_device {
u_long *pd_count;
int (*pd_shutdown) (int, int);
};
#endif
#ifdef __i386__
typedef u_short pci_port_t;
@ -312,7 +315,6 @@ int pci_unmap_int (pcici_t tag);
pcici_t pci_get_parent_from_tag(pcici_t tag);
int pci_get_bus_from_tag(pcici_t tag);
#ifdef COMPAT_OLDPCI
struct module;
int compat_pci_handler (struct module *, int, void *);
#define COMPAT_PCI_DRIVER(name, pcidata) \
@ -322,8 +324,6 @@ static moduledata_t name##_mod = { \
&pcidata \
}; \
DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
#endif
#endif /* COMPAT_OLDPCI */
#endif /* PCI_COMPAT */
#endif /* _PCIVAR_H_ */

View File

@ -52,9 +52,9 @@
#include <machine/resource.h>
#include <machine/md_var.h> /* For the Alpha */
#include <sys/pciio.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
#include <sys/pciio.h>
#ifdef __alpha__
#include <machine/rpb.h>
@ -86,13 +86,6 @@ struct pci_quirk pci_quirks[] = {
#define PCI_MAPMEMP 0x02 /* prefetchable memory map */
#define PCI_MAPPORT 0x04 /* port map */
struct pci_devinfo {
STAILQ_ENTRY(pci_devinfo) pci_links;
struct resource_list resources;
pcicfgregs cfg;
struct pci_conf conf;
};
static STAILQ_HEAD(devlist, pci_devinfo) pci_devq;
u_int32_t pci_numdevs = 0;
static u_int32_t pci_generation = 0;
@ -857,101 +850,6 @@ static struct cdevsw pcicdev = {
#include "pci_if.h"
static devclass_t pci_devclass;
#ifdef COMPAT_OLDPCI
/*
* A simple driver to wrap the old pci driver mechanism for back-compat.
*/
static int
pci_compat_probe(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
const char *name;
int error;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
/*
* Do the wrapped probe.
*/
error = ENXIO;
if (dvp && dvp->pd_probe) {
name = dvp->pd_probe(cfg, (cfg->device << 16) + cfg->vendor);
if (name) {
device_set_desc_copy(dev, name);
/* Allow newbus drivers to match "better" */
error = -200;
}
}
return error;
}
static int
pci_compat_attach(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
int unit;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
unit = device_get_unit(dev);
if (unit > *dvp->pd_count)
*dvp->pd_count = unit;
if (dvp->pd_attach)
dvp->pd_attach(cfg, unit);
device_printf(dev, "driver is using old-style compatability shims\n");
return 0;
}
static device_method_t pci_compat_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, pci_compat_probe),
DEVMETHOD(device_attach, pci_compat_attach),
{ 0, 0 }
};
/*
* Create a new style driver around each old pci driver.
*/
int
compat_pci_handler(module_t mod, int type, void *data)
{
struct pci_device *dvp = (struct pci_device *)data;
driver_t *driver;
switch (type) {
case MOD_LOAD:
driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT);
if (!driver)
return ENOMEM;
bzero(driver, sizeof(driver_t));
driver->name = dvp->pd_name;
driver->methods = pci_compat_methods;
driver->size = sizeof(struct pci_devinfo *);
driver->priv = dvp;
devclass_add_driver(pci_devclass, driver);
break;
case MOD_UNLOAD:
printf("%s: module unload not supported!\n", dvp->pd_name);
return EOPNOTSUPP;
default:
break;
}
return 0;
}
#endif
/*
* New style pci driver. Parent device is either a pci-host-bridge or a
@ -1504,5 +1402,5 @@ static driver_t pci_driver = {
pci_methods,
1, /* no softc */
};
static devclass_t pci_devclass;
DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);

View File

@ -29,10 +29,12 @@
#include "opt_bus.h"
/* for compatibility to FreeBSD-2.2 version of PCI code */
/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@ -43,6 +45,7 @@
#include <sys/rman.h>
#include <machine/resource.h>
#include <sys/pciio.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
@ -55,8 +58,6 @@
#endif
#ifdef PCI_COMPAT
/* ------------------------------------------------------------------------- */
u_long
@ -235,4 +236,95 @@ pci_get_bus_from_tag(pcici_t tag)
return tag->bus;
}
#endif /* PCI_COMPAT */
/*
* A simple driver to wrap the old pci driver mechanism for back-compat.
*/
static int
pci_compat_probe(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
const char *name;
int error;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
/*
* Do the wrapped probe.
*/
error = ENXIO;
if (dvp && dvp->pd_probe) {
name = dvp->pd_probe(cfg, (cfg->device << 16) + cfg->vendor);
if (name) {
device_set_desc_copy(dev, name);
/* Allow newbus drivers to match "better" */
error = -200;
}
}
return error;
}
static int
pci_compat_attach(device_t dev)
{
struct pci_device *dvp;
struct pci_devinfo *dinfo;
pcicfgregs *cfg;
int unit;
dinfo = device_get_ivars(dev);
cfg = &dinfo->cfg;
dvp = device_get_driver(dev)->priv;
unit = device_get_unit(dev);
if (unit > *dvp->pd_count)
*dvp->pd_count = unit;
if (dvp->pd_attach)
dvp->pd_attach(cfg, unit);
device_printf(dev, "driver is using old-style compatability shims\n");
return 0;
}
static device_method_t pci_compat_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, pci_compat_probe),
DEVMETHOD(device_attach, pci_compat_attach),
{ 0, 0 }
};
/*
* Create a new style driver around each old pci driver.
*/
int
compat_pci_handler(module_t mod, int type, void *data)
{
struct pci_device *dvp = (struct pci_device *)data;
driver_t *driver;
devclass_t pci_devclass = devclass_find("pci");
switch (type) {
case MOD_LOAD:
driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT);
if (!driver)
return ENOMEM;
bzero(driver, sizeof(driver_t));
driver->name = dvp->pd_name;
driver->methods = pci_compat_methods;
driver->size = sizeof(struct pci_devinfo *);
driver->priv = dvp;
devclass_add_driver(pci_devclass, driver);
break;
case MOD_UNLOAD:
printf("%s: module unload not supported!\n", dvp->pd_name);
return EOPNOTSUPP;
default:
break;
}
return 0;
}

View File

@ -1,6 +1,3 @@
#ifndef PCI_COMPAT
#define PCI_COMPAT
#endif
/*
* Copyright (c) 1997, Stefan Esser <se@freebsd.org>
* All rights reserved.
@ -234,9 +231,13 @@
#define PCID_INTEL_SATURN 0x0483
#define PCID_INTEL_ORION 0x84c4
/* for compatibility to FreeBSD-2.2 version of PCI code */
/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */
#ifdef PCI_COMPAT
#if defined(_KERNEL) && !defined(KLD_MODULE)
#include "opt_compat_oldpci.h"
#endif
#ifdef COMPAT_OLDPCI
#define PCI_ID_REG 0x00
#define PCI_COMMAND_STATUS_REG 0x04
@ -257,4 +258,4 @@
#define PCI_MAP_IO 0x00000001
#define PCI_INTERRUPT_REG 0x3c
#endif /* PCI_COMPAT */
#endif /* COMPAT_OLDPCI */

View File

@ -30,10 +30,6 @@
#ifndef _PCIVAR_H_
#define _PCIVAR_H_
#ifndef PCI_COMPAT
#define PCI_COMPAT
#endif
#include <sys/queue.h>
/* some PCI bus constants */
@ -139,6 +135,15 @@ typedef struct {
extern u_int32_t pci_numdevs;
/* Only if the prerequisites are present */
#if defined(_SYS_BUS_H_) && defined(_SYS_PCIIO_H_)
struct pci_devinfo {
STAILQ_ENTRY(pci_devinfo) pci_links;
struct resource_list resources;
pcicfgregs cfg;
struct pci_conf conf;
};
#endif
/* externally visible functions */
@ -265,14 +270,14 @@ PCIB_ACCESSOR(hose, HOSE, u_int32_t)
#endif
/* for compatibility to FreeBSD-2.2 version of PCI code */
#ifdef PCI_COMPAT
/* for compatibility to FreeBSD-2.2 and 3.x versions of PCI code */
#if defined(_KERNEL) && !defined(KLD_MODULE)
#include "opt_compat_oldpci.h"
#endif
#ifdef COMPAT_OLDPCI
/* all this is going some day */
typedef pcicfgregs *pcici_t;
@ -283,7 +288,6 @@ typedef void pci_inthand_t(void *arg);
/* just copied from old PCI code for now ... */
#ifdef COMPAT_OLDPCI
struct pci_device {
char* pd_name;
const char* (*pd_probe ) (pcici_t tag, pcidi_t type);
@ -291,7 +295,6 @@ struct pci_device {
u_long *pd_count;
int (*pd_shutdown) (int, int);
};
#endif
#ifdef __i386__
typedef u_short pci_port_t;
@ -312,7 +315,6 @@ int pci_unmap_int (pcici_t tag);
pcici_t pci_get_parent_from_tag(pcici_t tag);
int pci_get_bus_from_tag(pcici_t tag);
#ifdef COMPAT_OLDPCI
struct module;
int compat_pci_handler (struct module *, int, void *);
#define COMPAT_PCI_DRIVER(name, pcidata) \
@ -322,8 +324,6 @@ static moduledata_t name##_mod = { \
&pcidata \
}; \
DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
#endif
#endif /* COMPAT_OLDPCI */
#endif /* PCI_COMPAT */
#endif /* _PCIVAR_H_ */