Some newbus-inspired tidy-ups. Use device_identify() rather than scanning

the resource table to locate children.  The 'at ppbus?' can go again.
Remove a few #if Nxxx > 0' type things, config arranges this for us.
Move the newbus method glue next to the DRIVER_MODULE() stuff so we
don't need extra prototypes.
Don't set device descriptions until after the possibility of the probe
returning an error.
Remove all cdevsw_add() calls, all the drivers that did this also use
make_dev() correctly, so it's not required.
A couple of other minor nits.
This commit is contained in:
Peter Wemm 2000-01-23 14:41:04 +00:00
parent 37973e862d
commit 0f063508d7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=56455
8 changed files with 196 additions and 256 deletions

View file

@ -77,9 +77,6 @@
/*
* Update for ppbus, PLIP support only - Nicolas Souchu
*/
#include "plip.h"
#if NPLIP > 0
#include "opt_plip.h"
@ -170,9 +167,6 @@ static u_char *ctxmith;
#define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
/* Functions for the lp# interface */
static int lp_probe(device_t dev);
static int lp_attach(device_t dev);
static int lpinittables(void);
static int lpioctl(struct ifnet *, u_long, caddr_t);
static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
@ -188,20 +182,12 @@ static void lp_intr(void *);
static devclass_t lp_devclass;
static device_method_t lp_methods[] = {
/* device interface */
DEVMETHOD(device_probe, lp_probe),
DEVMETHOD(device_attach, lp_attach),
{ 0, 0 }
};
static driver_t lp_driver = {
"plip",
lp_methods,
sizeof(struct lp_data),
};
static void
lp_identify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, "plip", 0);
}
/*
* lpprobe()
*/
@ -785,6 +771,19 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
return 0;
}
DRIVER_MODULE(plip, ppbus, lp_driver, lp_devclass, 0, 0);
static device_method_t lp_methods[] = {
/* device interface */
DEVMETHOD(device_identify, lp_identify),
DEVMETHOD(device_probe, lp_probe),
DEVMETHOD(device_attach, lp_attach),
#endif /* NPLIP > 0 */
{ 0, 0 }
};
static driver_t lp_driver = {
"plip",
lp_methods,
sizeof(struct lp_data),
};
DRIVER_MODULE(plip, ppbus, lp_driver, lp_devclass, 0, 0);

View file

@ -54,53 +54,25 @@
#include "iicbb_if.h"
struct lpbb_softc {
int dummy;
};
static int lpbb_detect(device_t dev);
static int lpbb_probe(device_t);
static int lpbb_attach(device_t);
static void
lpbb_identify(driver_t *driver, device_t parent)
{
static int lpbb_callback(device_t, int, caddr_t *);
static void lpbb_setlines(device_t, int, int);
static int lpbb_getdataline(device_t);
static int lpbb_reset(device_t, u_char, u_char, u_char *);
static devclass_t lpbb_devclass;
static device_method_t lpbb_methods[] = {
/* device interface */
DEVMETHOD(device_probe, lpbb_probe),
DEVMETHOD(device_attach, lpbb_attach),
/* bus interface */
DEVMETHOD(bus_print_child, bus_generic_print_child),
/* iicbb interface */
DEVMETHOD(iicbb_callback, lpbb_callback),
DEVMETHOD(iicbb_setlines, lpbb_setlines),
DEVMETHOD(iicbb_getdataline, lpbb_getdataline),
DEVMETHOD(iicbb_reset, lpbb_reset),
{ 0, 0 }
};
static driver_t lpbb_driver = {
"lpbb",
lpbb_methods,
sizeof(struct lpbb_softc),
};
BUS_ADD_CHILD(parent, 0, "lpbb", 0);
}
static int
lpbb_probe(device_t dev)
{
device_set_desc(dev, "Parallel I2C bit-banging interface");
/* Perhaps call this during identify instead? */
if (!lpbb_detect(dev))
return (ENXIO);
device_set_desc(dev, "Parallel I2C bit-banging interface");
return (0);
}
@ -234,4 +206,30 @@ lpbb_getdataline(device_t dev)
return (getSDA(ppbus));
}
static devclass_t lpbb_devclass;
static device_method_t lpbb_methods[] = {
/* device interface */
DEVMETHOD(device_identify, lpbb_identify),
DEVMETHOD(device_probe, lpbb_probe),
DEVMETHOD(device_attach, lpbb_attach),
/* bus interface */
DEVMETHOD(bus_print_child, bus_generic_print_child),
/* iicbb interface */
DEVMETHOD(iicbb_callback, lpbb_callback),
DEVMETHOD(iicbb_setlines, lpbb_setlines),
DEVMETHOD(iicbb_getdataline, lpbb_getdataline),
DEVMETHOD(iicbb_reset, lpbb_reset),
{ 0, 0 }
};
static driver_t lpbb_driver = {
"lpbb",
lpbb_methods,
1,
};
DRIVER_MODULE(lpbb, ppbus, lpbb_driver, lpbb_devclass, 0, 0);

View file

@ -60,11 +60,6 @@
* Updated for ppbus by Nicolas Souchu
* [Mon Jul 28 1997]
*/
#include "lpt.h"
#if NLPT > 0
#ifdef _KERNEL
#include "opt_lpt.h"
@ -84,7 +79,6 @@
#include <sys/rman.h>
#include <machine/lpt.h>
#endif
#include <dev/ppbus/ppbconf.h>
#include <dev/ppbus/ppb_1284.h>
@ -156,27 +150,11 @@ static int lpt_detect(device_t dev);
#define UNITODEVICE(unit) \
(devclass_get_device(lpt_devclass, (unit)))
static int lpt_probe(device_t dev);
static int lpt_attach(device_t dev);
static void lptintr(device_t dev);
static void lpt_intr(void *arg); /* without spls */
static devclass_t lpt_devclass;
static device_method_t lpt_methods[] = {
/* device interface */
DEVMETHOD(device_probe, lpt_probe),
DEVMETHOD(device_attach, lpt_attach),
{ 0, 0 }
};
static driver_t lpt_driver = {
"lpt",
lpt_methods,
sizeof(struct lpt_data),
};
/* bits for state */
#define OPEN (1<<0) /* device is open */
@ -365,6 +343,13 @@ lpt_detect(device_t dev)
return (status);
}
static void
lpt_identify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, LPT_NAME, 0);
}
/*
* lpt_probe()
*/
@ -372,11 +357,7 @@ static int
lpt_probe(device_t dev)
{
struct lpt_data *sc;
static int once;
if (!once++)
cdevsw_add(&lpt_cdevsw);
sc = DEVTOSOFTC(dev);
bzero(sc, sizeof(struct lpt_data));
@ -972,7 +953,19 @@ lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
return(error);
}
static device_method_t lpt_methods[] = {
/* device interface */
DEVMETHOD(device_identify, lpt_identify),
DEVMETHOD(device_probe, lpt_probe),
DEVMETHOD(device_attach, lpt_attach),
{ 0, 0 }
};
static driver_t lpt_driver = {
LPT_NAME,
lpt_methods,
sizeof(struct lpt_data),
};
DRIVER_MODULE(lpt, ppbus, lpt_driver, lpt_devclass, 0, 0);
#endif

View file

@ -25,10 +25,6 @@
*
*/
#include "pcfclock.h"
#if NPCFCLOCK > 0
#include "opt_pcfclock.h"
#include <sys/param.h>
@ -68,23 +64,6 @@ struct pcfclock_data {
static devclass_t pcfclock_devclass;
static int pcfclock_probe(device_t);
static int pcfclock_attach(device_t);
static device_method_t pcfclock_methods[] = {
/* device interface */
DEVMETHOD(device_probe, pcfclock_probe),
DEVMETHOD(device_attach, pcfclock_attach),
{ 0, 0 }
};
static driver_t pcfclock_driver = {
PCFCLOCK_NAME,
pcfclock_methods,
sizeof(struct pcfclock_data),
};
static d_open_t pcfclock_open;
static d_close_t pcfclock_close;
static d_read_t pcfclock_read;
@ -144,17 +123,20 @@ static struct cdevsw pcfclock_cdevsw = {
#define PCFCLOCK_CMD_TIME 0 /* send current time */
#define PCFCLOCK_CMD_COPY 7 /* copy received signal to PC */
static void
pcfclock_identify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, PCFCLOCK_NAME, 0);
}
static int
pcfclock_probe(device_t dev)
{
struct pcfclock_data *sc;
static int once;
device_set_desc(dev, "PCF-1.0");
if (!once++)
cdevsw_add(&pcfclock_cdevsw);
sc = DEVTOSOFTC(dev);
bzero(sc, sizeof(struct pcfclock_data));
@ -343,6 +325,19 @@ pcfclock_read(dev_t dev, struct uio *uio, int ioflag)
return (error);
}
DRIVER_MODULE(pcfclock, ppbus, pcfclock_driver, pcfclock_devclass, 0, 0);
static device_method_t pcfclock_methods[] = {
/* device interface */
DEVMETHOD(device_identify, pcfclock_identify),
DEVMETHOD(device_probe, pcfclock_probe),
DEVMETHOD(device_attach, pcfclock_attach),
#endif /* NPCFCLOCK */
{ 0, 0 }
};
static driver_t pcfclock_driver = {
PCFCLOCK_NAME,
pcfclock_methods,
sizeof(struct pcfclock_data),
};
DRIVER_MODULE(pcfclock, ppbus, pcfclock_driver, pcfclock_devclass, 0, 0);

View file

@ -44,42 +44,11 @@
MALLOC_DEFINE(M_PPBUSDEV, "ppbusdev", "Parallel Port bus device");
static devclass_t ppbus_devclass;
/*
* Device methods
*/
static int ppbus_probe(device_t);
static int ppbus_attach(device_t);
static void ppbus_print_child(device_t bus, device_t dev);
static int ppbus_read_ivar(device_t, device_t, int, uintptr_t *);
static int ppbus_write_ivar(device_t, device_t, int, u_long);
static int ppbus_setup_intr(device_t, device_t, struct resource *, int,
void (*)(void *), void *, void **);
static int ppbus_teardown_intr(device_t, device_t, struct resource *, void *);
static device_method_t ppbus_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ppbus_probe),
DEVMETHOD(device_attach, ppbus_attach),
/* bus interface */
DEVMETHOD(bus_print_child, ppbus_print_child),
DEVMETHOD(bus_read_ivar, ppbus_read_ivar),
DEVMETHOD(bus_write_ivar, ppbus_write_ivar),
DEVMETHOD(bus_setup_intr, ppbus_setup_intr),
DEVMETHOD(bus_teardown_intr, ppbus_teardown_intr),
DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
{ 0, 0 }
};
static driver_t ppbus_driver = {
"ppbus",
ppbus_methods,
sizeof(struct ppb_data),
};
static void
ppbus_print_child(device_t bus, device_t dev)
{
@ -106,12 +75,12 @@ ppbus_probe(device_t dev)
}
/*
* ppb_add_device()
* ppbus_add_child()
*
* Add a ppbus device, allocate/initialize the ivars
*/
static void
ppbus_add_device(device_t dev, const char *name, int unit)
static device_t
ppbus_add_child(device_t dev, int order, const char *name, int unit)
{
struct ppb_device *ppbdev;
device_t child;
@ -119,7 +88,7 @@ ppbus_add_device(device_t dev, const char *name, int unit)
/* allocate ivars for the new ppbus child */
ppbdev = malloc(sizeof(struct ppb_device), M_PPBUSDEV, M_NOWAIT);
if (!ppbdev)
return;
return NULL;
bzero(ppbdev, sizeof *ppbdev);
/* initialize the ivars */
@ -127,15 +96,15 @@ ppbus_add_device(device_t dev, const char *name, int unit)
/* add the device as a child to the ppbus bus with the allocated
* ivars */
child = device_add_child(dev, name, unit);
child = device_add_child_ordered(dev, order, name, unit);
device_set_ivars(child, ppbdev);
return;
return child;
}
static int
ppbus_read_ivar(device_t bus, device_t dev, int index, uintptr_t* val)
{
{
struct ppb_device *ppbdev = (struct ppb_device *)device_get_ivars(dev);
switch (index) {
@ -421,39 +390,9 @@ ppb_scan_bus(device_t bus)
static int
ppbus_attach(device_t dev)
{
int i;
int unit, disabled;
char *name;
/*
* Add all devices configured to be attached to ppbus0.
*/
for (i = resource_query_string(-1, "at", "ppbus0");
i != -1;
i = resource_query_string(i, "at", "ppbus0")) {
unit = resource_query_unit(i);
name = resource_query_name(i);
if (resource_int_value(name, unit, "disabled", &disabled) == 0) {
if (disabled)
continue;
}
ppbus_add_device(dev, name, unit);
}
/*
* and ppbus?
*/
for (i = resource_query_string(-1, "at", "ppbus");
i != -1;
i = resource_query_string(i, "at", "ppbus")) {
unit = resource_query_unit(i);
name = resource_query_name(i);
if (resource_int_value(name, unit, "disabled", &disabled) == 0) {
if (disabled)
continue;
}
ppbus_add_device(dev, name, unit);
}
/* Locate our children */
bus_generic_probe(dev);
#ifndef DONTPROBE_1284
/* detect IEEE1284 compliant devices */
@ -601,4 +540,28 @@ ppb_release_bus(device_t bus, device_t dev)
return (0);
}
static devclass_t ppbus_devclass;
static device_method_t ppbus_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ppbus_probe),
DEVMETHOD(device_attach, ppbus_attach),
/* bus interface */
DEVMETHOD(bus_add_child, ppbus_add_child),
DEVMETHOD(bus_print_child, ppbus_print_child),
DEVMETHOD(bus_read_ivar, ppbus_read_ivar),
DEVMETHOD(bus_write_ivar, ppbus_write_ivar),
DEVMETHOD(bus_setup_intr, ppbus_setup_intr),
DEVMETHOD(bus_teardown_intr, ppbus_teardown_intr),
DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
{ 0, 0 }
};
static driver_t ppbus_driver = {
"ppbus",
ppbus_methods,
sizeof(struct ppb_data),
};
DRIVER_MODULE(ppbus, ppc, ppbus_driver, ppbus_devclass, 0, 0);

View file

@ -26,10 +26,6 @@
* $FreeBSD$
*
*/
#include "ppi.h"
#if NPPI > 0
#include "opt_ppb_1284.h"
#include <sys/param.h>
@ -83,26 +79,8 @@ struct ppi_data {
#define UNITODEVICE(unit) \
(devclass_get_device(ppi_devclass, (unit)))
static int ppi_probe(device_t);
static int ppi_attach(device_t);
static void ppiintr(void *arg);
static devclass_t ppi_devclass;
static device_method_t ppi_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ppi_probe),
DEVMETHOD(device_attach, ppi_attach),
{ 0, 0 }
};
static driver_t ppi_driver = {
"ppi",
ppi_methods,
sizeof(struct ppi_data),
};
static d_open_t ppiopen;
static d_close_t ppiclose;
static d_ioctl_t ppiioctl;
@ -155,6 +133,13 @@ ppi_disable_intr(device_t ppidev)
#endif /* PERIPH_1284 */
static void
ppi_identify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, "ppi", 0);
}
/*
* ppi_probe()
*/
@ -162,14 +147,10 @@ static int
ppi_probe(device_t dev)
{
struct ppi_data *ppi;
static int once;
/* probe is always ok */
device_set_desc(dev, "Parallel I/O");
if (!once++)
cdevsw_add(&ppi_cdevsw);
ppi = DEVTOSOFTC(dev);
bzero(ppi, sizeof(struct ppi_data));
@ -574,6 +555,18 @@ ppiioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
return (error);
}
DRIVER_MODULE(ppi, ppbus, ppi_driver, ppi_devclass, 0, 0);
static device_method_t ppi_methods[] = {
/* device interface */
DEVMETHOD(device_identify, ppi_identify),
DEVMETHOD(device_probe, ppi_probe),
DEVMETHOD(device_attach, ppi_attach),
#endif /* NPPI */
{ 0, 0 }
};
static driver_t ppi_driver = {
"ppi",
ppi_methods,
sizeof(struct ppi_data),
};
DRIVER_MODULE(ppi, ppbus, ppi_driver, ppi_devclass, 0, 0);

View file

@ -43,8 +43,6 @@ struct pps_data {
void *intr_cookie; /* interrupt registration cookie */
};
static int ppsprobe(device_t dev);
static int ppsattach(device_t dev);
static void ppsintr(void *arg);
#define DEVTOSOFTC(dev) \
@ -56,20 +54,6 @@ static void ppsintr(void *arg);
static devclass_t pps_devclass;
static device_method_t pps_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ppsprobe),
DEVMETHOD(device_attach, ppsattach),
{ 0, 0 }
};
static driver_t pps_driver = {
PPS_NAME,
pps_methods,
sizeof(struct pps_data),
};
static d_open_t ppsopen;
static d_close_t ppsclose;
static d_ioctl_t ppsioctl;
@ -92,17 +76,20 @@ static struct cdevsw pps_cdevsw = {
/* bmaj */ -1
};
static void
ppsidentify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, PPS_NAME, 0);
}
static int
ppsprobe(device_t ppsdev)
{
struct pps_data *sc;
static int once;
dev_t dev;
int unit;
if (!once++)
cdevsw_add(&pps_cdevsw);
sc = DEVTOSOFTC(ppsdev);
bzero(sc, sizeof(struct pps_data));
@ -216,4 +203,18 @@ ppsioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
return (pps_ioctl(cmd, data, &sc->pps));
}
static device_method_t pps_methods[] = {
/* device interface */
DEVMETHOD(device_identify, ppsidentify),
DEVMETHOD(device_probe, ppsprobe),
DEVMETHOD(device_attach, ppsattach),
{ 0, 0 }
};
static driver_t pps_driver = {
PPS_NAME,
pps_methods,
sizeof(struct pps_data),
};
DRIVER_MODULE(pps, ppbus, pps_driver, pps_devclass, 0, 0);

View file

@ -24,10 +24,8 @@
* SUCH DAMAGE.
*
* $FreeBSD$
*
*/
#ifdef _KERNEL
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>
@ -35,8 +33,6 @@
#include <machine/clock.h>
#endif /* _KERNEL */
#include <cam/cam.h>
#include <cam/cam_ccb.h>
#include <cam/cam_sim.h>
@ -47,9 +43,7 @@
#include <cam/scsi/scsi_message.h>
#include <cam/scsi/scsi_da.h>
#ifdef _KERNEL
#include <sys/kernel.h>
#endif
#include "opt_vpo.h"
@ -81,32 +75,20 @@ struct vpo_data {
struct vpoio_data vpo_io; /* interface to low level functions */
};
static int vpo_probe(device_t);
static int vpo_attach(device_t);
#define DEVTOSOFTC(dev) \
((struct vpo_data *)device_get_softc(dev))
static devclass_t vpo_devclass;
static device_method_t vpo_methods[] = {
/* device interface */
DEVMETHOD(device_probe, vpo_probe),
DEVMETHOD(device_attach, vpo_attach),
{ 0, 0 }
};
static driver_t vpo_driver = {
"vpo",
vpo_methods,
sizeof(struct vpo_data),
};
/* cam related functions */
static void vpo_action(struct cam_sim *sim, union ccb *ccb);
static void vpo_poll(struct cam_sim *sim);
static void
vpo_identify(driver_t *driver, device_t parent)
{
BUS_ADD_CHILD(parent, 0, "vpo", 0);
}
/*
* vpo_probe()
*/
@ -437,4 +419,20 @@ vpo_poll(struct cam_sim *sim)
return;
}
static devclass_t vpo_devclass;
static device_method_t vpo_methods[] = {
/* device interface */
DEVMETHOD(device_identify, vpo_identify),
DEVMETHOD(device_probe, vpo_probe),
DEVMETHOD(device_attach, vpo_attach),
{ 0, 0 }
};
static driver_t vpo_driver = {
"vpo",
vpo_methods,
sizeof(struct vpo_data),
};
DRIVER_MODULE(vpo, ppbus, vpo_driver, vpo_devclass, 0, 0);