summaryrefslogtreecommitdiffstats
path: root/sys/dev/ppbus/ppi.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-10-21 18:30:10 +0000
committerjhb <jhb@FreeBSD.org>2008-10-21 18:30:10 +0000
commit03f7a1b892756cd78ff85f138ffdb94cd4216670 (patch)
tree7de1b18022c6338570a93ecf78a487c8a9820918 /sys/dev/ppbus/ppi.c
parentddfa987b872f81817a11a48d9b97c719ef1e48d3 (diff)
downloadFreeBSD-src-03f7a1b892756cd78ff85f138ffdb94cd4216670.zip
FreeBSD-src-03f7a1b892756cd78ff85f138ffdb94cd4216670.tar.gz
Several cleanups to remove the need for explicit unit numbers and a few
other fixes: - Add pointers back to device_t objects in softc structures instead of storing the unit and using devclass_get_device(). - Add 'lpbb', 'pcf', 'pps', and 'vpo' child devices to every 'ppbus' device instead of just the first one. - Store softc pointers in si_drv1 of character devices instead of pulling the unit number from the minor number and using devclass_get_softc() and devclass_get_device(). - Store the LP_BYPASS flag in si_drv2 instead of encoding it in the minor number. - Destroy character devices for lpt(4) when detaching the device. - Use bus_print_child_footer() instead of duplicating it in ppbus_print_child() and fix ppbus_print_child()'s return value. - Remove unused AVM ivar from ppbus. - Don't store the 'mode' ivar in the ppbus ivars since we always fetch it from the parent anyway. - Try to detach all the child devices before deleting them in ppbus_detach(). - Use pause() instead of a tsleep() on a dummy address when polling the ppbus. - Use if_printf() and device_printf() instead of explicit names with unit numbers. Silence on: current@
Diffstat (limited to 'sys/dev/ppbus/ppi.c')
-rw-r--r--sys/dev/ppbus/ppi.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/sys/dev/ppbus/ppi.c b/sys/dev/ppbus/ppi.c
index e3e329f..e28b3cd 100644
--- a/sys/dev/ppbus/ppi.c
+++ b/sys/dev/ppbus/ppi.c
@@ -59,8 +59,8 @@ __FBSDID("$FreeBSD$");
#define BUFSIZE 512
struct ppi_data {
-
- int ppi_unit;
+ device_t ppi_device;
+ struct cdev *ppi_cdev;
int ppi_flags;
#define HAVE_PPBUS (1<<0)
#define HAD_PPBUS (1<<1)
@@ -77,10 +77,6 @@ struct ppi_data {
#define DEVTOSOFTC(dev) \
((struct ppi_data *)device_get_softc(dev))
-#define UNITOSOFTC(unit) \
- ((struct ppi_data *)devclass_get_softc(ppi_devclass, (unit)))
-#define UNITODEVICE(unit) \
- (devclass_get_device(ppi_devclass, (unit)))
static devclass_t ppi_devclass;
@@ -162,18 +158,24 @@ ppi_probe(device_t dev)
static int
ppi_attach(device_t dev)
{
+ struct ppi_data *ppi = DEVTOSOFTC(dev);
#ifdef PERIPH_1284
int rid = 0;
- struct ppi_data *ppi = DEVTOSOFTC(dev);
/* declare our interrupt handler */
ppi->intr_resource = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
RF_ACTIVE);
#endif /* PERIPH_1284 */
- make_dev(&ppi_cdevsw, device_get_unit(dev), /* XXX cleanup */
+ ppi->ppi_cdev = make_dev(&ppi_cdevsw, device_get_unit(dev),
UID_ROOT, GID_WHEEL,
0600, "ppi%d", device_get_unit(dev));
+ if (ppi->ppi_cdev == NULL) {
+ device_printf("Failed to create character device\n");
+ return (ENXIO);
+ }
+ ppi->ppi_cdev->si_drv1 = ppi;
+ ppi->ppi_device = dev;
return (0);
}
@@ -252,15 +254,11 @@ ppiintr(void *arg)
static int
ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int res;
- if (!ppi)
- return (ENXIO);
-
if (!(ppi->ppi_flags & HAVE_PPBUS)) {
if ((res = ppb_request_bus(ppbus, ppidev,
(flags & O_NONBLOCK) ? PPB_DONTWAIT :
@@ -286,9 +284,8 @@ ppiopen(struct cdev *dev, int flags, int fmt, struct thread *td)
static int
ppiclose(struct cdev *dev, int flags, int fmt, struct thread *td)
{
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
ppi->ppi_count --;
@@ -329,9 +326,8 @@ static int
ppiread(struct cdev *dev, struct uio *uio, int ioflag)
{
#ifdef PERIPH_1284
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int len, error = 0;
@@ -413,9 +409,8 @@ static int
ppiwrite(struct cdev *dev, struct uio *uio, int ioflag)
{
#ifdef PERIPH_1284
- u_int unit = dev2unit(dev);
- struct ppi_data *ppi = UNITOSOFTC(unit);
- device_t ppidev = UNITODEVICE(unit);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
device_t ppbus = device_get_parent(ppidev);
int len, error = 0, sent;
@@ -499,9 +494,8 @@ error:
static int
ppiioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags, struct thread *td)
{
- u_int unit = dev2unit(dev);
- device_t ppidev = UNITODEVICE(unit);
- device_t ppbus = device_get_parent(ppidev);
+ struct ppi_data *ppi = dev->si_drv1;
+ device_t ppidev = ppi->ppi_device;
int error = 0;
u_int8_t *val = (u_int8_t *)data;
OpenPOWER on IntegriCloud