Add accessor functions for the device_t type. Make device_lookup() a

real function, rather than a macro.
This commit is contained in:
thorpej 2006-02-19 15:01:21 +00:00
parent a9beff9534
commit c37edf541c
2 changed files with 107 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_autoconf.c,v 1.106 2006/02/18 19:40:42 martin Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.107 2006/02/19 15:01:21 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.106 2006/02/18 19:40:42 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.107 2006/02/19 15:01:21 thorpej Exp $");
#include "opt_ddb.h"
@ -1538,3 +1538,84 @@ devprop_copy(device_t from, device_t to, int wait)
return (prop_copy(dev_propdb, from, to, wait));
}
/*
* device_lookup:
*
* Look up a device instance for a given driver.
*/
void *
device_lookup(cfdriver_t cd, int unit)
{
if (unit < 0 || unit >= cd->cd_ndevs)
return (NULL);
return (cd->cd_devs[unit]);
}
/*
* Accessor functions for the device_t type.
*/
devclass_t
device_class(device_t dev)
{
return (dev->dv_class);
}
cfdata_t
device_cfdata(device_t dev)
{
return (dev->dv_cfdata);
}
cfdriver_t
device_cfdriver(device_t dev)
{
return (dev->dv_cfdriver);
}
cfattach_t
device_cfattach(device_t dev)
{
return (dev->dv_cfattach);
}
int
device_unit(device_t dev)
{
return (dev->dv_unit);
}
const char *
device_xname(device_t dev)
{
return (dev->dv_xname);
}
device_t
device_parent(device_t dev)
{
return (dev->dv_parent);
}
boolean_t
device_is_active(device_t dev)
{
return ((dev->dv_flags & DVF_ACTIVE) != 0);
}
int *
device_locators(device_t dev)
{
return (dev->dv_locators);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: device.h,v 1.85 2006/02/18 05:04:13 thorpej Exp $ */
/* $NetBSD: device.h,v 1.86 2006/02/19 15:01:21 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -103,6 +103,8 @@ typedef enum devact {
} devact_t;
typedef struct cfdata *cfdata_t;
typedef struct cfdriver *cfdriver_t;
typedef struct cfattach *cfattach_t;
typedef struct device *device_t;
struct device {
@ -110,14 +112,14 @@ struct device {
TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */
cfdata_t dv_cfdata; /* config data that found us
(NULL if pseudo-device) */
struct cfdriver *dv_cfdriver; /* our cfdriver */
struct cfattach *dv_cfattach; /* our cfattach */
int dv_unit; /* device unit number */
char dv_xname[16]; /* external name (name + unit) */
device_t dv_parent; /* pointer to parent device
cfdriver_t dv_cfdriver; /* our cfdriver */
cfattach_t dv_cfattach; /* our cfattach */
int dv_unit; /* device unit number */
char dv_xname[16]; /* external name (name + unit) */
device_t dv_parent; /* pointer to parent device
(NULL if pesudo- or root node) */
int dv_flags; /* misc. flags; see below */
int *dv_locators; /* our actual locators (optional) */
int dv_flags; /* misc. flags; see below */
int *dv_locators; /* our actual locators (optional) */
};
/* dv_flags */
@ -348,19 +350,26 @@ void config_pending_decr(void);
int config_finalize_register(device_t, int (*)(device_t));
void config_finalize(void);
#ifdef __HAVE_DEVICE_REGISTER
void device_register(device_t, void *);
#endif
int devprop_set(device_t, const char *, void *, size_t, int, int);
size_t devprop_list(device_t, char *, size_t);
size_t devprop_get(device_t, const char *, void *, size_t, int *);
int devprop_delete(device_t, const char *);
int devprop_copy(device_t, device_t, int);
/* convenience definitions */
#define device_lookup(cfd, unit) \
(((unit) < (cfd)->cd_ndevs) ? (cfd)->cd_devs[(unit)] : NULL)
void *device_lookup(cfdriver_t, int);
#ifdef __HAVE_DEVICE_REGISTER
void device_register(device_t, void *);
#endif
devclass_t device_class(device_t);
cfdata_t device_cfdata(device_t);
cfdriver_t device_cfdriver(device_t);
cfattach_t device_cfattach(device_t);
int device_unit(device_t);
const char *device_xname(device_t);
device_t device_parent(device_t);
boolean_t device_is_active(device_t);
int *device_locators(device_t);
#endif /* _KERNEL */