1998-06-10 10:57:29 +00:00
|
|
|
/*-
|
2017-11-27 15:20:12 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-10-16 09:16:28 +00:00
|
|
|
* Copyright (c) 1997,1998,2003 Doug Rabson
|
1998-06-10 10:57:29 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-10-11 15:19:12 +00:00
|
|
|
#include "opt_bus.h"
|
2016-11-13 00:46:11 +00:00
|
|
|
#include "opt_ddb.h"
|
1999-10-11 15:19:12 +00:00
|
|
|
|
1998-06-10 10:57:29 +00:00
|
|
|
#include <sys/param.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/conf.h>
|
2018-01-07 18:06:30 +00:00
|
|
|
#include <sys/eventhandler.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/filio.h>
|
|
|
|
#include <sys/lock.h>
|
1998-06-10 10:57:29 +00:00
|
|
|
#include <sys/kernel.h>
|
2000-04-08 14:17:18 +00:00
|
|
|
#include <sys/kobj.h>
|
2009-11-12 00:52:14 +00:00
|
|
|
#include <sys/limits.h>
|
2002-09-11 07:13:28 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/poll.h>
|
2015-02-06 16:09:01 +00:00
|
|
|
#include <sys/priv.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/condvar.h>
|
2002-09-11 07:13:28 +00:00
|
|
|
#include <sys/queue.h>
|
1999-05-22 14:57:15 +00:00
|
|
|
#include <machine/bus.h>
|
2013-10-08 11:05:26 +00:00
|
|
|
#include <sys/random.h>
|
1999-05-22 14:57:15 +00:00
|
|
|
#include <sys/rman.h>
|
2018-06-27 04:10:48 +00:00
|
|
|
#include <sys/sbuf.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/selinfo.h>
|
|
|
|
#include <sys/signalvar.h>
|
2016-05-09 20:50:21 +00:00
|
|
|
#include <sys/smp.h>
|
2002-09-11 07:13:28 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/systm.h>
|
2002-10-07 23:17:44 +00:00
|
|
|
#include <sys/uio.h>
|
2002-10-02 09:34:29 +00:00
|
|
|
#include <sys/bus.h>
|
2014-10-09 05:33:25 +00:00
|
|
|
#include <sys/cpuset.h>
|
2002-09-11 07:13:28 +00:00
|
|
|
|
2013-07-15 01:32:55 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
2013-10-08 11:05:26 +00:00
|
|
|
#include <machine/cpu.h>
|
2002-09-11 07:13:28 +00:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
#include <vm/uma.h>
|
2016-05-20 17:57:47 +00:00
|
|
|
#include <vm/vm.h>
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2016-11-13 00:46:11 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
2002-11-30 00:49:43 +00:00
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW, NULL, NULL);
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_ROOT_NODE(OID_AUTO, dev, CTLFLAG_RW, NULL, NULL);
|
2002-11-30 00:49:43 +00:00
|
|
|
|
2002-10-02 09:34:29 +00:00
|
|
|
/*
|
|
|
|
* Used to attach drivers to devclasses.
|
|
|
|
*/
|
|
|
|
typedef struct driverlink *driverlink_t;
|
|
|
|
struct driverlink {
|
2003-10-16 09:16:28 +00:00
|
|
|
kobj_class_t driver;
|
|
|
|
TAILQ_ENTRY(driverlink) link; /* list of drivers in devclass */
|
2009-06-09 14:26:23 +00:00
|
|
|
int pass;
|
2018-08-23 05:05:47 +00:00
|
|
|
int flags;
|
|
|
|
#define DL_DEFERRED_PROBE 1 /* Probe deferred on this */
|
2009-06-09 14:26:23 +00:00
|
|
|
TAILQ_ENTRY(driverlink) passlink;
|
2002-10-02 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward declarations
|
|
|
|
*/
|
|
|
|
typedef TAILQ_HEAD(devclass_list, devclass) devclass_list_t;
|
|
|
|
typedef TAILQ_HEAD(driver_list, driverlink) driver_list_t;
|
|
|
|
typedef TAILQ_HEAD(device_list, device) device_list_t;
|
|
|
|
|
|
|
|
struct devclass {
|
|
|
|
TAILQ_ENTRY(devclass) link;
|
2003-10-16 09:16:28 +00:00
|
|
|
devclass_t parent; /* parent in devclass hierarchy */
|
2002-10-02 09:34:29 +00:00
|
|
|
driver_list_t drivers; /* bus devclasses store drivers for bus */
|
|
|
|
char *name;
|
|
|
|
device_t *devices; /* array of devices indexed by unit */
|
|
|
|
int maxunit; /* size of devices array */
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
int flags;
|
|
|
|
#define DC_HAS_CHILDREN 1
|
2004-06-04 10:23:00 +00:00
|
|
|
|
|
|
|
struct sysctl_ctx_list sysctl_ctx;
|
|
|
|
struct sysctl_oid *sysctl_tree;
|
2002-10-02 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Implementation of device.
|
2002-10-02 09:34:29 +00:00
|
|
|
*/
|
|
|
|
struct device {
|
|
|
|
/*
|
|
|
|
* A device is a kernel object. The first field must be the
|
|
|
|
* current ops table for the object.
|
|
|
|
*/
|
|
|
|
KOBJ_FIELDS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device hierarchy.
|
|
|
|
*/
|
2004-07-18 16:30:31 +00:00
|
|
|
TAILQ_ENTRY(device) link; /**< list of devices in parent */
|
|
|
|
TAILQ_ENTRY(device) devlink; /**< global device list membership */
|
|
|
|
device_t parent; /**< parent of this device */
|
|
|
|
device_list_t children; /**< list of child devices */
|
2002-10-02 09:34:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Details of this device.
|
|
|
|
*/
|
2004-07-18 16:30:31 +00:00
|
|
|
driver_t *driver; /**< current driver */
|
|
|
|
devclass_t devclass; /**< current device class */
|
|
|
|
int unit; /**< current unit number */
|
|
|
|
char* nameunit; /**< name+unit e.g. foodev0 */
|
|
|
|
char* desc; /**< driver specific description */
|
|
|
|
int busy; /**< count of calls to device_busy() */
|
|
|
|
device_state_t state; /**< current device state */
|
2010-06-21 09:55:56 +00:00
|
|
|
uint32_t devflags; /**< api level flags for device_get_flags() */
|
2010-09-04 17:28:29 +00:00
|
|
|
u_int flags; /**< internal device flags */
|
|
|
|
u_int order; /**< order from device_add_child_ordered() */
|
2004-07-18 16:30:31 +00:00
|
|
|
void *ivars; /**< instance variables */
|
|
|
|
void *softc; /**< current driver's variables */
|
2002-10-02 09:34:29 +00:00
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
struct sysctl_ctx_list sysctl_ctx; /**< state for sysctl variables */
|
|
|
|
struct sysctl_oid *sysctl_tree; /**< state for sysctl variables */
|
2002-10-02 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
2000-12-08 20:09:00 +00:00
|
|
|
static MALLOC_DEFINE(M_BUS, "bus", "Bus data structures");
|
2003-10-14 06:22:07 +00:00
|
|
|
static MALLOC_DEFINE(M_BUS_SC, "bus-sc", "Bus data structures, softc");
|
1999-09-10 21:11:23 +00:00
|
|
|
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_LIST_DEFINE(device_attach);
|
|
|
|
EVENTHANDLER_LIST_DEFINE(device_detach);
|
|
|
|
EVENTHANDLER_LIST_DEFINE(dev_lookup);
|
|
|
|
|
2015-02-06 16:09:01 +00:00
|
|
|
static void devctl2_init(void);
|
2018-08-23 05:05:47 +00:00
|
|
|
static bool device_frozen;
|
2015-02-06 16:09:01 +00:00
|
|
|
|
2016-11-13 00:46:11 +00:00
|
|
|
#define DRIVERNAME(d) ((d)? d->name : "no driver")
|
|
|
|
#define DEVCLANAME(d) ((d)? d->name : "no devclass")
|
|
|
|
|
1998-10-27 09:21:43 +00:00
|
|
|
#ifdef BUS_DEBUG
|
2000-05-03 17:45:04 +00:00
|
|
|
|
|
|
|
static int bus_debug = 1;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, bus_debug, CTLFLAG_RWTUN, &bus_debug, 0,
|
|
|
|
"Bus debug level");
|
2000-05-03 17:45:04 +00:00
|
|
|
|
2002-10-15 18:56:13 +00:00
|
|
|
#define PDEBUG(a) if (bus_debug) {printf("%s:%d: ", __func__, __LINE__), printf a; printf("\n");}
|
1998-10-27 09:21:43 +00:00
|
|
|
#define DEVICENAME(d) ((d)? device_get_name(d): "no device")
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* Produce the indenting, indent*2 spaces plus a '.' ahead of that to
|
1998-10-27 09:21:43 +00:00
|
|
|
* prevent syslog from deleting initial spaces
|
|
|
|
*/
|
2001-01-05 07:29:54 +00:00
|
|
|
#define indentprintf(p) do { int iJ; printf("."); for (iJ=0; iJ<indent; iJ++) printf(" "); printf p ; } while (0)
|
1998-10-27 09:21:43 +00:00
|
|
|
|
|
|
|
static void print_device_short(device_t dev, int indent);
|
|
|
|
static void print_device(device_t dev, int indent);
|
|
|
|
void print_device_tree_short(device_t dev, int indent);
|
|
|
|
void print_device_tree(device_t dev, int indent);
|
|
|
|
static void print_driver_short(driver_t *driver, int indent);
|
|
|
|
static void print_driver(driver_t *driver, int indent);
|
|
|
|
static void print_driver_list(driver_list_t drivers, int indent);
|
|
|
|
static void print_devclass_short(devclass_t dc, int indent);
|
|
|
|
static void print_devclass(devclass_t dc, int indent);
|
|
|
|
void print_devclass_list_short(void);
|
|
|
|
void print_devclass_list(void);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* Make the compiler ignore the function calls */
|
|
|
|
#define PDEBUG(a) /* nop */
|
|
|
|
#define DEVICENAME(d) /* nop */
|
|
|
|
|
|
|
|
#define print_device_short(d,i) /* nop */
|
|
|
|
#define print_device(d,i) /* nop */
|
|
|
|
#define print_device_tree_short(d,i) /* nop */
|
|
|
|
#define print_device_tree(d,i) /* nop */
|
|
|
|
#define print_driver_short(d,i) /* nop */
|
|
|
|
#define print_driver(d,i) /* nop */
|
|
|
|
#define print_driver_list(d,i) /* nop */
|
|
|
|
#define print_devclass_short(d,i) /* nop */
|
|
|
|
#define print_devclass(d,i) /* nop */
|
|
|
|
#define print_devclass_list_short() /* nop */
|
|
|
|
#define print_devclass_list() /* nop */
|
|
|
|
#endif
|
|
|
|
|
2004-05-25 12:06:26 +00:00
|
|
|
/*
|
|
|
|
* dev sysctl tree
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum {
|
2004-06-04 10:23:00 +00:00
|
|
|
DEVCLASS_SYSCTL_PARENT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
devclass_sysctl_handler(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
devclass_t dc = (devclass_t)arg1;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
switch (arg2) {
|
|
|
|
case DEVCLASS_SYSCTL_PARENT:
|
2004-06-05 11:39:05 +00:00
|
|
|
value = dc->parent ? dc->parent->name : "";
|
2004-06-04 10:23:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2015-03-14 21:40:01 +00:00
|
|
|
return (SYSCTL_OUT_STR(req, value));
|
2004-06-04 10:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
devclass_sysctl_init(devclass_t dc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (dc->sysctl_tree != NULL)
|
|
|
|
return;
|
|
|
|
sysctl_ctx_init(&dc->sysctl_ctx);
|
|
|
|
dc->sysctl_tree = SYSCTL_ADD_NODE(&dc->sysctl_ctx,
|
|
|
|
SYSCTL_STATIC_CHILDREN(_dev), OID_AUTO, dc->name,
|
2009-02-11 04:54:02 +00:00
|
|
|
CTLFLAG_RD, NULL, "");
|
2004-06-04 10:23:00 +00:00
|
|
|
SYSCTL_ADD_PROC(&dc->sysctl_ctx, SYSCTL_CHILDREN(dc->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%parent", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-06-04 10:23:00 +00:00
|
|
|
dc, DEVCLASS_SYSCTL_PARENT, devclass_sysctl_handler, "A",
|
|
|
|
"parent class");
|
|
|
|
}
|
|
|
|
|
|
|
|
enum {
|
2004-05-25 12:06:26 +00:00
|
|
|
DEVICE_SYSCTL_DESC,
|
|
|
|
DEVICE_SYSCTL_DRIVER,
|
|
|
|
DEVICE_SYSCTL_LOCATION,
|
|
|
|
DEVICE_SYSCTL_PNPINFO,
|
2004-06-02 22:43:35 +00:00
|
|
|
DEVICE_SYSCTL_PARENT,
|
2004-05-25 12:06:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
device_sysctl_handler(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
device_t dev = (device_t)arg1;
|
|
|
|
const char *value;
|
|
|
|
char *buf;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
switch (arg2) {
|
|
|
|
case DEVICE_SYSCTL_DESC:
|
2004-06-05 11:39:05 +00:00
|
|
|
value = dev->desc ? dev->desc : "";
|
2004-05-25 12:06:26 +00:00
|
|
|
break;
|
|
|
|
case DEVICE_SYSCTL_DRIVER:
|
2004-06-05 11:39:05 +00:00
|
|
|
value = dev->driver ? dev->driver->name : "";
|
2004-05-25 12:06:26 +00:00
|
|
|
break;
|
|
|
|
case DEVICE_SYSCTL_LOCATION:
|
|
|
|
value = buf = malloc(1024, M_BUS, M_WAITOK | M_ZERO);
|
|
|
|
bus_child_location_str(dev, buf, 1024);
|
|
|
|
break;
|
|
|
|
case DEVICE_SYSCTL_PNPINFO:
|
|
|
|
value = buf = malloc(1024, M_BUS, M_WAITOK | M_ZERO);
|
|
|
|
bus_child_pnpinfo_str(dev, buf, 1024);
|
|
|
|
break;
|
2004-06-02 22:43:35 +00:00
|
|
|
case DEVICE_SYSCTL_PARENT:
|
2004-06-05 11:39:05 +00:00
|
|
|
value = dev->parent ? dev->parent->nameunit : "";
|
2004-06-02 22:43:35 +00:00
|
|
|
break;
|
2004-05-25 12:06:26 +00:00
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2015-03-14 21:40:01 +00:00
|
|
|
error = SYSCTL_OUT_STR(req, value);
|
2004-05-25 12:06:26 +00:00
|
|
|
if (buf != NULL)
|
|
|
|
free(buf, M_BUS);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_sysctl_init(device_t dev)
|
|
|
|
{
|
2004-06-04 10:23:00 +00:00
|
|
|
devclass_t dc = dev->devclass;
|
2014-11-24 19:55:45 +00:00
|
|
|
int domain;
|
2004-05-25 12:06:26 +00:00
|
|
|
|
2004-06-02 22:43:35 +00:00
|
|
|
if (dev->sysctl_tree != NULL)
|
2004-05-25 12:06:26 +00:00
|
|
|
return;
|
2004-06-04 10:23:00 +00:00
|
|
|
devclass_sysctl_init(dc);
|
2004-05-25 12:06:26 +00:00
|
|
|
sysctl_ctx_init(&dev->sysctl_ctx);
|
2016-12-14 13:03:01 +00:00
|
|
|
dev->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&dev->sysctl_ctx,
|
2004-06-04 10:23:00 +00:00
|
|
|
SYSCTL_CHILDREN(dc->sysctl_tree), OID_AUTO,
|
|
|
|
dev->nameunit + strlen(dc->name),
|
2016-12-14 13:03:01 +00:00
|
|
|
CTLFLAG_RD, NULL, "", "device_index");
|
2004-05-25 12:06:26 +00:00
|
|
|
SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%desc", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-05-25 12:06:26 +00:00
|
|
|
dev, DEVICE_SYSCTL_DESC, device_sysctl_handler, "A",
|
|
|
|
"device description");
|
|
|
|
SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%driver", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-05-25 12:06:26 +00:00
|
|
|
dev, DEVICE_SYSCTL_DRIVER, device_sysctl_handler, "A",
|
|
|
|
"device driver name");
|
|
|
|
SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%location", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-05-25 12:06:26 +00:00
|
|
|
dev, DEVICE_SYSCTL_LOCATION, device_sysctl_handler, "A",
|
|
|
|
"device location relative to parent");
|
|
|
|
SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%pnpinfo", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-05-25 12:06:26 +00:00
|
|
|
dev, DEVICE_SYSCTL_PNPINFO, device_sysctl_handler, "A",
|
|
|
|
"device identification");
|
2004-06-02 22:43:35 +00:00
|
|
|
SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree),
|
2011-01-18 21:14:18 +00:00
|
|
|
OID_AUTO, "%parent", CTLTYPE_STRING | CTLFLAG_RD,
|
2004-06-02 22:43:35 +00:00
|
|
|
dev, DEVICE_SYSCTL_PARENT, device_sysctl_handler, "A",
|
2004-06-04 10:23:00 +00:00
|
|
|
"parent device");
|
2014-11-24 19:55:45 +00:00
|
|
|
if (bus_get_domain(dev, &domain) == 0)
|
|
|
|
SYSCTL_ADD_INT(&dev->sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(dev->sysctl_tree), OID_AUTO, "%domain",
|
|
|
|
CTLFLAG_RD, NULL, domain, "NUMA domain");
|
2004-05-25 12:06:26 +00:00
|
|
|
}
|
|
|
|
|
2007-11-30 21:30:14 +00:00
|
|
|
static void
|
|
|
|
device_sysctl_update(device_t dev)
|
|
|
|
{
|
|
|
|
devclass_t dc = dev->devclass;
|
|
|
|
|
|
|
|
if (dev->sysctl_tree == NULL)
|
|
|
|
return;
|
|
|
|
sysctl_rename_oid(dev->sysctl_tree, dev->nameunit + strlen(dc->name));
|
|
|
|
}
|
|
|
|
|
2004-05-25 12:06:26 +00:00
|
|
|
static void
|
|
|
|
device_sysctl_fini(device_t dev)
|
|
|
|
{
|
|
|
|
if (dev->sysctl_tree == NULL)
|
|
|
|
return;
|
|
|
|
sysctl_ctx_free(&dev->sysctl_ctx);
|
|
|
|
dev->sysctl_tree = NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-07 23:17:44 +00:00
|
|
|
/*
|
|
|
|
* /dev/devctl implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This design allows only one reader for /dev/devctl. This is not desirable
|
|
|
|
* in the long run, but will get a lot of hair out of this implementation.
|
|
|
|
* Maybe we should make this device a clonable device.
|
|
|
|
*
|
|
|
|
* Also note: we specifically do not attach a device to the device_t tree
|
|
|
|
* to avoid potential chicken and egg problems. One could argue that all
|
|
|
|
* of this belongs to the root node. One could also further argue that the
|
2003-01-01 18:49:04 +00:00
|
|
|
* sysctl interface that we have not might more properly be an ioctl
|
|
|
|
* interface, but at this stage of the game, I'm not inclined to rock that
|
2002-10-07 23:17:44 +00:00
|
|
|
* boat.
|
|
|
|
*
|
|
|
|
* I'm also not sure that the SIGIO support is done correctly or not, as
|
|
|
|
* I copied it from a driver that had SIGIO support that likely hasn't been
|
|
|
|
* tested since 3.4 or 2.2.8!
|
|
|
|
*/
|
|
|
|
|
2014-04-28 20:38:08 +00:00
|
|
|
/* Deprecated way to adjust queue length */
|
|
|
|
static int sysctl_devctl_disable(SYSCTL_HANDLER_ARGS);
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_disable, CTLTYPE_INT | CTLFLAG_RWTUN |
|
2014-04-28 20:38:08 +00:00
|
|
|
CTLFLAG_MPSAFE, NULL, 0, sysctl_devctl_disable, "I",
|
|
|
|
"devctl disable -- deprecated");
|
|
|
|
|
2009-08-25 06:25:59 +00:00
|
|
|
#define DEVCTL_DEFAULT_QUEUE_LEN 1000
|
|
|
|
static int sysctl_devctl_queue(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int devctl_queue_length = DEVCTL_DEFAULT_QUEUE_LEN;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_queue, CTLTYPE_INT | CTLFLAG_RWTUN |
|
2014-03-25 03:28:58 +00:00
|
|
|
CTLFLAG_MPSAFE, NULL, 0, sysctl_devctl_queue, "I", "devctl queue length");
|
2002-11-30 00:49:43 +00:00
|
|
|
|
2002-10-07 23:17:44 +00:00
|
|
|
static d_open_t devopen;
|
|
|
|
static d_close_t devclose;
|
|
|
|
static d_read_t devread;
|
|
|
|
static d_ioctl_t devioctl;
|
|
|
|
static d_poll_t devpoll;
|
2014-04-10 02:30:51 +00:00
|
|
|
static d_kqfilter_t devkqfilter;
|
2002-10-07 23:17:44 +00:00
|
|
|
|
|
|
|
static struct cdevsw dev_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = devopen,
|
|
|
|
.d_close = devclose,
|
|
|
|
.d_read = devread,
|
|
|
|
.d_ioctl = devioctl,
|
|
|
|
.d_poll = devpoll,
|
2014-04-10 02:30:51 +00:00
|
|
|
.d_kqfilter = devkqfilter,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_name = "devctl",
|
2002-10-07 23:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dev_event_info
|
|
|
|
{
|
|
|
|
char *dei_data;
|
|
|
|
TAILQ_ENTRY(dev_event_info) dei_link;
|
|
|
|
};
|
|
|
|
|
|
|
|
TAILQ_HEAD(devq, dev_event_info);
|
|
|
|
|
2003-04-30 12:57:40 +00:00
|
|
|
static struct dev_softc
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
|
|
|
int inuse;
|
2004-02-24 19:31:30 +00:00
|
|
|
int nonblock;
|
2009-08-25 06:25:59 +00:00
|
|
|
int queued;
|
2014-04-04 12:31:13 +00:00
|
|
|
int async;
|
2002-10-07 23:17:44 +00:00
|
|
|
struct mtx mtx;
|
|
|
|
struct cv cv;
|
|
|
|
struct selinfo sel;
|
|
|
|
struct devq devq;
|
2014-04-04 12:31:13 +00:00
|
|
|
struct sigio *sigio;
|
2002-10-07 23:17:44 +00:00
|
|
|
} devsoftc;
|
|
|
|
|
2014-04-10 02:30:51 +00:00
|
|
|
static void filt_devctl_detach(struct knote *kn);
|
|
|
|
static int filt_devctl_read(struct knote *kn, long hint);
|
|
|
|
|
|
|
|
struct filterops devctl_rfiltops = {
|
|
|
|
.f_isfd = 1,
|
|
|
|
.f_detach = filt_devctl_detach,
|
|
|
|
.f_event = filt_devctl_read,
|
|
|
|
};
|
|
|
|
|
2004-06-16 09:47:26 +00:00
|
|
|
static struct cdev *devctl_dev;
|
2002-10-07 23:17:44 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
devinit(void)
|
|
|
|
{
|
2011-01-04 10:59:38 +00:00
|
|
|
devctl_dev = make_dev_credf(MAKEDEV_ETERNAL, &dev_cdevsw, 0, NULL,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "devctl");
|
2002-10-07 23:17:44 +00:00
|
|
|
mtx_init(&devsoftc.mtx, "dev mtx", "devd", MTX_DEF);
|
|
|
|
cv_init(&devsoftc.cv, "dev cv");
|
|
|
|
TAILQ_INIT(&devsoftc.devq);
|
2014-04-10 02:30:51 +00:00
|
|
|
knlist_init_mtx(&devsoftc.sel.si_note, &devsoftc.mtx);
|
2015-02-06 16:09:01 +00:00
|
|
|
devctl2_init();
|
2002-10-07 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 16:58:16 +00:00
|
|
|
devopen(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
2014-03-25 03:28:58 +00:00
|
|
|
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
|
|
|
if (devsoftc.inuse) {
|
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
2002-10-07 23:17:44 +00:00
|
|
|
/* move to init */
|
|
|
|
devsoftc.inuse = 1;
|
2014-03-25 03:28:58 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
2002-10-07 23:17:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 16:58:16 +00:00
|
|
|
devclose(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
2014-03-25 03:28:58 +00:00
|
|
|
|
2002-10-07 23:17:44 +00:00
|
|
|
mtx_lock(&devsoftc.mtx);
|
2014-03-25 03:28:58 +00:00
|
|
|
devsoftc.inuse = 0;
|
2014-07-12 15:35:04 +00:00
|
|
|
devsoftc.nonblock = 0;
|
|
|
|
devsoftc.async = 0;
|
2002-10-07 23:17:44 +00:00
|
|
|
cv_broadcast(&devsoftc.cv);
|
2014-04-04 12:31:13 +00:00
|
|
|
funsetown(&devsoftc.sigio);
|
2002-10-07 23:17:44 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The read channel for this device is used to report changes to
|
|
|
|
* userland in realtime. We are required to free the data as well as
|
|
|
|
* the n1 object because we allocate them separately. Also note that
|
|
|
|
* we return one record at a time. If you try to read this device a
|
2006-08-04 07:56:35 +00:00
|
|
|
* character at a time, you will lose the rest of the data. Listening
|
2002-10-07 23:17:44 +00:00
|
|
|
* programs are expected to cope.
|
|
|
|
*/
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
devread(struct cdev *dev, struct uio *uio, int ioflag)
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
|
|
|
struct dev_event_info *n1;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
|
|
|
while (TAILQ_EMPTY(&devsoftc.devq)) {
|
|
|
|
if (devsoftc.nonblock) {
|
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
return (EAGAIN);
|
|
|
|
}
|
|
|
|
rv = cv_wait_sig(&devsoftc.cv, &devsoftc.mtx);
|
|
|
|
if (rv) {
|
|
|
|
/*
|
|
|
|
* Need to translate ERESTART to EINTR here? -- jake
|
|
|
|
*/
|
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n1 = TAILQ_FIRST(&devsoftc.devq);
|
|
|
|
TAILQ_REMOVE(&devsoftc.devq, n1, dei_link);
|
2009-08-25 06:25:59 +00:00
|
|
|
devsoftc.queued--;
|
2002-10-07 23:17:44 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
rv = uiomove(n1->dei_data, strlen(n1->dei_data), uio);
|
|
|
|
free(n1->dei_data, M_BUS);
|
|
|
|
free(n1, M_BUS);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 16:58:16 +00:00
|
|
|
devioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case FIONBIO:
|
|
|
|
if (*(int*)data)
|
|
|
|
devsoftc.nonblock = 1;
|
|
|
|
else
|
|
|
|
devsoftc.nonblock = 0;
|
|
|
|
return (0);
|
|
|
|
case FIOASYNC:
|
2002-11-30 00:49:43 +00:00
|
|
|
if (*(int*)data)
|
2014-04-04 12:31:13 +00:00
|
|
|
devsoftc.async = 1;
|
2002-11-30 00:49:43 +00:00
|
|
|
else
|
2014-04-04 12:31:13 +00:00
|
|
|
devsoftc.async = 0;
|
|
|
|
return (0);
|
|
|
|
case FIOSETOWN:
|
|
|
|
return fsetown(*(int *)data, &devsoftc.sigio);
|
|
|
|
case FIOGETOWN:
|
|
|
|
*(int *)data = fgetown(&devsoftc.sigio);
|
2002-10-07 23:17:44 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* (un)Support for other fcntl() calls. */
|
|
|
|
case FIOCLEX:
|
|
|
|
case FIONCLEX:
|
|
|
|
case FIONREAD:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-05-20 16:58:16 +00:00
|
|
|
devpoll(struct cdev *dev, int events, struct thread *td)
|
2002-10-07 23:17:44 +00:00
|
|
|
{
|
|
|
|
int revents = 0;
|
|
|
|
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
2003-04-21 05:58:51 +00:00
|
|
|
if (events & (POLLIN | POLLRDNORM)) {
|
2002-10-07 23:17:44 +00:00
|
|
|
if (!TAILQ_EMPTY(&devsoftc.devq))
|
2003-04-21 05:58:51 +00:00
|
|
|
revents = events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(td, &devsoftc.sel);
|
|
|
|
}
|
2002-10-07 23:17:44 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
2014-04-10 02:30:51 +00:00
|
|
|
static int
|
|
|
|
devkqfilter(struct cdev *dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (kn->kn_filter == EVFILT_READ) {
|
|
|
|
kn->kn_fop = &devctl_rfiltops;
|
|
|
|
knlist_add(&devsoftc.sel.si_note, kn, 0);
|
|
|
|
error = 0;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
filt_devctl_detach(struct knote *kn)
|
|
|
|
{
|
|
|
|
|
|
|
|
knlist_remove(&devsoftc.sel.si_note, kn, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_devctl_read(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
kn->kn_data = devsoftc.queued;
|
|
|
|
return (kn->kn_data != 0);
|
|
|
|
}
|
|
|
|
|
2008-01-27 16:06:37 +00:00
|
|
|
/**
|
|
|
|
* @brief Return whether the userland process is running
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
devctl_process_running(void)
|
|
|
|
{
|
2008-05-18 13:55:51 +00:00
|
|
|
return (devsoftc.inuse == 1);
|
2008-01-27 16:06:37 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Queue data to be read from the devctl device
|
|
|
|
*
|
2003-10-24 22:41:54 +00:00
|
|
|
* Generic interface to queue data to the devctl device. It is
|
2004-07-18 16:30:31 +00:00
|
|
|
* assumed that @p data is properly formatted. It is further assumed
|
|
|
|
* that @p data is allocated using the M_BUS malloc type.
|
2003-10-24 22:41:54 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-06-12 13:20:38 +00:00
|
|
|
devctl_queue_data_f(char *data, int flags)
|
2003-10-24 22:41:54 +00:00
|
|
|
{
|
2009-08-25 06:25:59 +00:00
|
|
|
struct dev_event_info *n1 = NULL, *n2 = NULL;
|
2003-10-24 22:41:54 +00:00
|
|
|
|
2009-03-23 01:13:34 +00:00
|
|
|
if (strlen(data) == 0)
|
2010-04-20 20:39:42 +00:00
|
|
|
goto out;
|
2009-08-25 06:25:59 +00:00
|
|
|
if (devctl_queue_length == 0)
|
2010-04-20 20:39:42 +00:00
|
|
|
goto out;
|
2010-06-12 13:20:38 +00:00
|
|
|
n1 = malloc(sizeof(*n1), M_BUS, flags);
|
2003-10-24 22:41:54 +00:00
|
|
|
if (n1 == NULL)
|
2010-04-20 20:39:42 +00:00
|
|
|
goto out;
|
2003-10-24 22:41:54 +00:00
|
|
|
n1->dei_data = data;
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
2009-08-25 06:25:59 +00:00
|
|
|
if (devctl_queue_length == 0) {
|
2010-04-20 20:39:42 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
2009-08-25 06:25:59 +00:00
|
|
|
free(n1->dei_data, M_BUS);
|
|
|
|
free(n1, M_BUS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Leave at least one spot in the queue... */
|
|
|
|
while (devsoftc.queued > devctl_queue_length - 1) {
|
|
|
|
n2 = TAILQ_FIRST(&devsoftc.devq);
|
|
|
|
TAILQ_REMOVE(&devsoftc.devq, n2, dei_link);
|
|
|
|
free(n2->dei_data, M_BUS);
|
|
|
|
free(n2, M_BUS);
|
|
|
|
devsoftc.queued--;
|
|
|
|
}
|
2004-02-24 19:31:30 +00:00
|
|
|
TAILQ_INSERT_TAIL(&devsoftc.devq, n1, dei_link);
|
2009-08-25 06:25:59 +00:00
|
|
|
devsoftc.queued++;
|
2003-10-24 22:41:54 +00:00
|
|
|
cv_broadcast(&devsoftc.cv);
|
2014-04-10 02:30:51 +00:00
|
|
|
KNOTE_LOCKED(&devsoftc.sel.si_note, 0);
|
2003-10-24 22:41:54 +00:00
|
|
|
mtx_unlock(&devsoftc.mtx);
|
|
|
|
selwakeup(&devsoftc.sel);
|
2014-04-04 12:31:13 +00:00
|
|
|
if (devsoftc.async && devsoftc.sigio != NULL)
|
|
|
|
pgsigio(&devsoftc.sigio, SIGIO, 0);
|
2010-04-20 20:39:42 +00:00
|
|
|
return;
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* We have to free data on all error paths since the caller
|
|
|
|
* assumes it will be free'd when this item is dequeued.
|
|
|
|
*/
|
|
|
|
free(data, M_BUS);
|
|
|
|
return;
|
2003-10-24 22:41:54 +00:00
|
|
|
}
|
|
|
|
|
2010-06-12 13:20:38 +00:00
|
|
|
void
|
|
|
|
devctl_queue_data(char *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
devctl_queue_data_f(data, M_NOWAIT);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Send a 'notification' to userland, using standard ways
|
2003-10-24 22:41:54 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-06-12 13:20:38 +00:00
|
|
|
devctl_notify_f(const char *system, const char *subsystem, const char *type,
|
|
|
|
const char *data, int flags)
|
2003-10-24 22:41:54 +00:00
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
if (system == NULL)
|
|
|
|
return; /* BOGUS! Must specify system. */
|
|
|
|
if (subsystem == NULL)
|
|
|
|
return; /* BOGUS! Must specify subsystem. */
|
|
|
|
if (type == NULL)
|
|
|
|
return; /* BOGUS! Must specify type. */
|
|
|
|
len += strlen(" system=") + strlen(system);
|
|
|
|
len += strlen(" subsystem=") + strlen(subsystem);
|
|
|
|
len += strlen(" type=") + strlen(type);
|
|
|
|
/* add in the data message plus newline. */
|
|
|
|
if (data != NULL)
|
|
|
|
len += strlen(data);
|
|
|
|
len += 3; /* '!', '\n', and NUL */
|
2010-06-12 13:20:38 +00:00
|
|
|
msg = malloc(len, M_BUS, flags);
|
2003-10-24 22:41:54 +00:00
|
|
|
if (msg == NULL)
|
|
|
|
return; /* Drop it on the floor */
|
2005-10-04 22:25:14 +00:00
|
|
|
if (data != NULL)
|
|
|
|
snprintf(msg, len, "!system=%s subsystem=%s type=%s %s\n",
|
|
|
|
system, subsystem, type, data);
|
|
|
|
else
|
|
|
|
snprintf(msg, len, "!system=%s subsystem=%s type=%s\n",
|
|
|
|
system, subsystem, type);
|
2010-06-12 13:20:38 +00:00
|
|
|
devctl_queue_data_f(msg, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
devctl_notify(const char *system, const char *subsystem, const char *type,
|
|
|
|
const char *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
devctl_notify_f(system, subsystem, type, data, M_NOWAIT);
|
2003-10-24 22:41:54 +00:00
|
|
|
}
|
|
|
|
|
2002-10-07 23:17:44 +00:00
|
|
|
/*
|
|
|
|
* Common routine that tries to make sending messages as easy as possible.
|
|
|
|
* We allocate memory for the data, copy strings into that, but do not
|
|
|
|
* free it unless there's an error. The dequeue part of the driver should
|
2014-04-28 20:38:08 +00:00
|
|
|
* free the data. We don't send data when the device is disabled. We do
|
|
|
|
* send data, even when we have no listeners, because we wish to avoid
|
|
|
|
* races relating to startup and restart of listening applications.
|
2004-08-29 18:11:10 +00:00
|
|
|
*
|
|
|
|
* devaddq is designed to string together the type of event, with the
|
|
|
|
* object of that event, plus the plug and play info and location info
|
|
|
|
* for that event. This is likely most useful for devices, but less
|
|
|
|
* useful for other consumers of this interface. Those should use
|
|
|
|
* the devctl_queue_data() interface instead.
|
2002-10-07 23:17:44 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
devaddq(const char *type, const char *what, device_t dev)
|
|
|
|
{
|
|
|
|
char *data = NULL;
|
2004-08-29 18:11:10 +00:00
|
|
|
char *loc = NULL;
|
|
|
|
char *pnp = NULL;
|
2002-10-07 23:17:44 +00:00
|
|
|
const char *parstr;
|
|
|
|
|
2009-08-25 06:25:59 +00:00
|
|
|
if (!devctl_queue_length)/* Rare race, but lost races safely discard */
|
2002-10-07 23:17:44 +00:00
|
|
|
return;
|
|
|
|
data = malloc(1024, M_BUS, M_NOWAIT);
|
|
|
|
if (data == NULL)
|
|
|
|
goto bad;
|
2004-08-29 18:11:10 +00:00
|
|
|
|
|
|
|
/* get the bus specific location of this device */
|
2002-10-07 23:17:44 +00:00
|
|
|
loc = malloc(1024, M_BUS, M_NOWAIT);
|
|
|
|
if (loc == NULL)
|
|
|
|
goto bad;
|
|
|
|
*loc = '\0';
|
|
|
|
bus_child_location_str(dev, loc, 1024);
|
2004-08-29 18:11:10 +00:00
|
|
|
|
|
|
|
/* Get the bus specific pnp info of this device */
|
|
|
|
pnp = malloc(1024, M_BUS, M_NOWAIT);
|
|
|
|
if (pnp == NULL)
|
|
|
|
goto bad;
|
|
|
|
*pnp = '\0';
|
|
|
|
bus_child_pnpinfo_str(dev, pnp, 1024);
|
|
|
|
|
|
|
|
/* Get the parent of this device, or / if high enough in the tree. */
|
2002-10-07 23:17:44 +00:00
|
|
|
if (device_get_parent(dev) == NULL)
|
|
|
|
parstr = "."; /* Or '/' ? */
|
|
|
|
else
|
|
|
|
parstr = device_get_nameunit(device_get_parent(dev));
|
2004-08-29 18:11:10 +00:00
|
|
|
/* String it all together. */
|
|
|
|
snprintf(data, 1024, "%s%s at %s %s on %s\n", type, what, loc, pnp,
|
|
|
|
parstr);
|
2002-10-07 23:17:44 +00:00
|
|
|
free(loc, M_BUS);
|
2004-08-29 18:11:10 +00:00
|
|
|
free(pnp, M_BUS);
|
2003-10-24 22:41:54 +00:00
|
|
|
devctl_queue_data(data);
|
2002-10-07 23:17:44 +00:00
|
|
|
return;
|
2003-10-24 22:41:54 +00:00
|
|
|
bad:
|
2004-08-29 18:11:10 +00:00
|
|
|
free(pnp, M_BUS);
|
|
|
|
free(loc, M_BUS);
|
2002-10-07 23:17:44 +00:00
|
|
|
free(data, M_BUS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A device was added to the tree. We are called just after it successfully
|
|
|
|
* attaches (that is, probe and attach success for this device). No call
|
|
|
|
* is made if a device is merely parented into the tree. See devnomatch
|
|
|
|
* if probe fails. If attach fails, no notification is sent (but maybe
|
|
|
|
* we should have a different message for this).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
devadded(device_t dev)
|
|
|
|
{
|
2010-11-30 05:54:21 +00:00
|
|
|
devaddq("+", device_get_nameunit(dev), dev);
|
2002-10-07 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A device was removed from the tree. We are called just before this
|
|
|
|
* happens.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
devremoved(device_t dev)
|
|
|
|
{
|
2010-12-02 04:28:01 +00:00
|
|
|
devaddq("-", device_get_nameunit(dev), dev);
|
2002-10-07 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when there's no match for this device. This is only called
|
2009-05-20 17:19:30 +00:00
|
|
|
* the first time that no match happens, so we don't keep getting this
|
2002-10-07 23:17:44 +00:00
|
|
|
* message. Should that prove to be undesirable, we can change it.
|
|
|
|
* This is called when all drivers that can attach to a given bus
|
2010-02-07 18:00:13 +00:00
|
|
|
* decline to accept this device. Other errors may not be detected.
|
2002-10-07 23:17:44 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
devnomatch(device_t dev)
|
|
|
|
{
|
2004-08-29 18:11:10 +00:00
|
|
|
devaddq("?", "", dev);
|
2002-10-07 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
2014-04-28 20:38:08 +00:00
|
|
|
static int
|
|
|
|
sysctl_devctl_disable(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct dev_event_info *n1;
|
|
|
|
int dis, error;
|
|
|
|
|
2014-06-28 03:56:17 +00:00
|
|
|
dis = (devctl_queue_length == 0);
|
2014-04-28 20:38:08 +00:00
|
|
|
error = sysctl_handle_int(oidp, &dis, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
2014-06-28 03:56:17 +00:00
|
|
|
if (mtx_initialized(&devsoftc.mtx))
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
2014-04-28 20:38:08 +00:00
|
|
|
if (dis) {
|
|
|
|
while (!TAILQ_EMPTY(&devsoftc.devq)) {
|
|
|
|
n1 = TAILQ_FIRST(&devsoftc.devq);
|
|
|
|
TAILQ_REMOVE(&devsoftc.devq, n1, dei_link);
|
|
|
|
free(n1->dei_data, M_BUS);
|
|
|
|
free(n1, M_BUS);
|
|
|
|
}
|
|
|
|
devsoftc.queued = 0;
|
|
|
|
devctl_queue_length = 0;
|
|
|
|
} else {
|
|
|
|
devctl_queue_length = DEVCTL_DEFAULT_QUEUE_LEN;
|
|
|
|
}
|
2014-06-28 03:56:17 +00:00
|
|
|
if (mtx_initialized(&devsoftc.mtx))
|
|
|
|
mtx_unlock(&devsoftc.mtx);
|
2014-04-28 20:38:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-08-25 06:25:59 +00:00
|
|
|
static int
|
|
|
|
sysctl_devctl_queue(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct dev_event_info *n1;
|
|
|
|
int q, error;
|
|
|
|
|
|
|
|
q = devctl_queue_length;
|
|
|
|
error = sysctl_handle_int(oidp, &q, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
if (q < 0)
|
|
|
|
return (EINVAL);
|
2014-06-28 03:56:17 +00:00
|
|
|
if (mtx_initialized(&devsoftc.mtx))
|
|
|
|
mtx_lock(&devsoftc.mtx);
|
2009-08-25 06:25:59 +00:00
|
|
|
devctl_queue_length = q;
|
|
|
|
while (devsoftc.queued > devctl_queue_length) {
|
|
|
|
n1 = TAILQ_FIRST(&devsoftc.devq);
|
|
|
|
TAILQ_REMOVE(&devsoftc.devq, n1, dei_link);
|
|
|
|
free(n1->dei_data, M_BUS);
|
|
|
|
free(n1, M_BUS);
|
|
|
|
devsoftc.queued--;
|
2002-11-30 00:49:43 +00:00
|
|
|
}
|
2014-06-28 03:56:17 +00:00
|
|
|
if (mtx_initialized(&devsoftc.mtx))
|
|
|
|
mtx_unlock(&devsoftc.mtx);
|
2002-11-30 00:49:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2018-06-27 04:10:48 +00:00
|
|
|
/**
|
|
|
|
* @brief safely quotes strings that might have double quotes in them.
|
|
|
|
*
|
|
|
|
* The devctl protocol relies on quoted strings having matching quotes.
|
|
|
|
* This routine quotes any internal quotes so the resulting string
|
|
|
|
* is safe to pass to snprintf to construct, for example pnp info strings.
|
|
|
|
* Strings are always terminated with a NUL, but may be truncated if longer
|
|
|
|
* than @p len bytes after quotes.
|
|
|
|
*
|
|
|
|
* @param sb sbuf to place the characters into
|
|
|
|
* @param src Original buffer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
devctl_safe_quote_sb(struct sbuf *sb, const char *src)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (*src != '\0') {
|
|
|
|
if (*src == '"' || *src == '\\')
|
|
|
|
sbuf_putc(sb, '\\');
|
|
|
|
sbuf_putc(sb, *src++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-07 23:17:44 +00:00
|
|
|
/* End of /dev/devctl code */
|
|
|
|
|
2009-02-03 00:10:21 +00:00
|
|
|
static TAILQ_HEAD(,device) bus_data_devices;
|
2000-11-09 10:21:23 +00:00
|
|
|
static int bus_data_generation = 1;
|
|
|
|
|
2009-02-03 00:10:21 +00:00
|
|
|
static kobj_method_t null_methods[] = {
|
2009-02-11 04:54:02 +00:00
|
|
|
KOBJMETHOD_END
|
1998-06-14 13:46:10 +00:00
|
|
|
};
|
|
|
|
|
2000-04-08 14:17:18 +00:00
|
|
|
DEFINE_CLASS(null, null_methods, 0);
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2009-06-09 14:26:23 +00:00
|
|
|
/*
|
|
|
|
* Bus pass implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
static driver_list_t passes = TAILQ_HEAD_INITIALIZER(passes);
|
|
|
|
int bus_current_pass = BUS_PASS_ROOT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Register the pass level of a new driver attachment
|
|
|
|
*
|
|
|
|
* Register a new driver attachment's pass level. If no driver
|
|
|
|
* attachment with the same pass level has been added, then @p new
|
|
|
|
* will be added to the global passes list.
|
|
|
|
*
|
|
|
|
* @param new the new driver attachment
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
driver_register_pass(struct driverlink *new)
|
|
|
|
{
|
|
|
|
struct driverlink *dl;
|
|
|
|
|
|
|
|
/* We only consider pass numbers during boot. */
|
|
|
|
if (bus_current_pass == BUS_PASS_DEFAULT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk the passes list. If we already know about this pass
|
|
|
|
* then there is nothing to do. If we don't, then insert this
|
|
|
|
* driver link into the list.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(dl, &passes, passlink) {
|
|
|
|
if (dl->pass < new->pass)
|
|
|
|
continue;
|
|
|
|
if (dl->pass == new->pass)
|
|
|
|
return;
|
|
|
|
TAILQ_INSERT_BEFORE(dl, new, passlink);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&passes, new, passlink);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Raise the current bus pass
|
|
|
|
*
|
|
|
|
* Raise the current bus pass level to @p pass. Call the BUS_NEW_PASS()
|
|
|
|
* method on the root bus to kick off a new device tree scan for each
|
|
|
|
* new pass level that has at least one driver.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bus_set_pass(int pass)
|
|
|
|
{
|
|
|
|
struct driverlink *dl;
|
|
|
|
|
|
|
|
if (bus_current_pass > pass)
|
|
|
|
panic("Attempt to lower bus pass level");
|
|
|
|
|
|
|
|
TAILQ_FOREACH(dl, &passes, passlink) {
|
|
|
|
/* Skip pass values below the current pass level. */
|
|
|
|
if (dl->pass <= bus_current_pass)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bail once we hit a driver with a pass level that is
|
|
|
|
* too high.
|
|
|
|
*/
|
|
|
|
if (dl->pass > pass)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Raise the pass level to the next level and rescan
|
|
|
|
* the tree.
|
|
|
|
*/
|
|
|
|
bus_current_pass = dl->pass;
|
|
|
|
BUS_NEW_PASS(root_bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there isn't a driver registered for the requested pass,
|
|
|
|
* then bus_current_pass might still be less than 'pass'. Set
|
|
|
|
* it to 'pass' in that case.
|
|
|
|
*/
|
|
|
|
if (bus_current_pass < pass)
|
|
|
|
bus_current_pass = pass;
|
|
|
|
KASSERT(bus_current_pass == pass, ("Failed to update bus pass level"));
|
|
|
|
}
|
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
/*
|
|
|
|
* Devclass implementation
|
|
|
|
*/
|
|
|
|
|
1998-10-27 09:21:43 +00:00
|
|
|
static devclass_list_t devclasses = TAILQ_HEAD_INITIALIZER(devclasses);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Find or create a device class
|
|
|
|
*
|
|
|
|
* If a device class with the name @p classname exists, return it,
|
|
|
|
* otherwise if @p create is non-zero create and return a new device
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* If @p parentname is non-NULL, the parent of the devclass is set to
|
|
|
|
* the devclass of that name.
|
|
|
|
*
|
|
|
|
* @param classname the devclass name to find or create
|
|
|
|
* @param parentname the parent devclass name or @c NULL
|
|
|
|
* @param create non-zero to create a devclass
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
static devclass_t
|
2003-10-16 09:16:28 +00:00
|
|
|
devclass_find_internal(const char *classname, const char *parentname,
|
|
|
|
int create)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("looking for %s", classname));
|
|
|
|
if (!classname)
|
|
|
|
return (NULL);
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dc, &devclasses, link) {
|
|
|
|
if (!strcmp(dc->name, classname))
|
2003-10-16 09:16:28 +00:00
|
|
|
break;
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
if (create && !dc) {
|
|
|
|
PDEBUG(("creating %s", classname));
|
2001-01-05 07:29:54 +00:00
|
|
|
dc = malloc(sizeof(struct devclass) + strlen(classname) + 1,
|
2009-08-25 06:25:59 +00:00
|
|
|
M_BUS, M_NOWAIT | M_ZERO);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!dc)
|
|
|
|
return (NULL);
|
2003-10-16 09:16:28 +00:00
|
|
|
dc->parent = NULL;
|
2001-01-05 07:29:54 +00:00
|
|
|
dc->name = (char*) (dc + 1);
|
|
|
|
strcpy(dc->name, classname);
|
|
|
|
TAILQ_INIT(&dc->drivers);
|
|
|
|
TAILQ_INSERT_TAIL(&devclasses, dc, link);
|
|
|
|
|
|
|
|
bus_data_generation_update();
|
|
|
|
}
|
2006-01-20 21:59:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a parent class is specified, then set that as our parent so
|
|
|
|
* that this devclass will support drivers for the parent class as
|
|
|
|
* well. If the parent class has the same name don't do this though
|
|
|
|
* as it creates a cycle that can trigger an infinite loop in
|
|
|
|
* device_probe_child() if a device exists for which there is no
|
|
|
|
* suitable driver.
|
|
|
|
*/
|
|
|
|
if (parentname && dc && !dc->parent &&
|
|
|
|
strcmp(classname, parentname) != 0) {
|
2009-03-25 17:02:05 +00:00
|
|
|
dc->parent = devclass_find_internal(parentname, NULL, TRUE);
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
dc->parent->flags |= DC_HAS_CHILDREN;
|
2003-10-16 09:16:28 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dc);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Create a device class
|
|
|
|
*
|
|
|
|
* If a device class with the name @p classname exists, return it,
|
|
|
|
* otherwise create and return a new device class.
|
|
|
|
*
|
|
|
|
* @param classname the devclass name to find or create
|
|
|
|
*/
|
1999-05-30 10:27:11 +00:00
|
|
|
devclass_t
|
|
|
|
devclass_create(const char *classname)
|
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
return (devclass_find_internal(classname, NULL, TRUE));
|
1999-05-30 10:27:11 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find a device class
|
|
|
|
*
|
|
|
|
* If a device class with the name @p classname exists, return it,
|
|
|
|
* otherwise return @c NULL.
|
|
|
|
*
|
|
|
|
* @param classname the devclass name to find
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
devclass_t
|
|
|
|
devclass_find(const char *classname)
|
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
return (devclass_find_internal(classname, NULL, FALSE));
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Register that a device driver has been added to a devclass
|
|
|
|
*
|
|
|
|
* Register that a device driver has been added to a devclass. This
|
|
|
|
* is called by devclass_add_driver to accomplish the recursive
|
|
|
|
* notification of all the children classes of dc, as well as dc.
|
|
|
|
* Each layer will have BUS_DRIVER_ADDED() called for all instances of
|
2011-03-01 14:43:37 +00:00
|
|
|
* the devclass.
|
|
|
|
*
|
|
|
|
* We do a full search here of the devclass list at each iteration
|
|
|
|
* level to save storing children-lists in the devclass structure. If
|
|
|
|
* we ever move beyond a few dozen devices doing this, we may need to
|
|
|
|
* reevaluate...
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
*
|
|
|
|
* @param dc the devclass to edit
|
|
|
|
* @param driver the driver that was just added
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
devclass_driver_added(devclass_t dc, driver_t *driver)
|
|
|
|
{
|
|
|
|
devclass_t parent;
|
2009-03-11 08:19:31 +00:00
|
|
|
int i;
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
|
|
|
|
/*
|
2017-01-15 17:54:01 +00:00
|
|
|
* Call BUS_DRIVER_ADDED for any existing buses in this class.
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
*/
|
|
|
|
for (i = 0; i < dc->maxunit; i++)
|
2009-09-24 17:03:32 +00:00
|
|
|
if (dc->devices[i] && device_is_attached(dc->devices[i]))
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
BUS_DRIVER_ADDED(dc->devices[i], driver);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk through the children classes. Since we only keep a
|
|
|
|
* single parent pointer around, we walk the entire list of
|
|
|
|
* devclasses looking for children. We set the
|
|
|
|
* DC_HAS_CHILDREN flag when a child devclass is created on
|
2009-03-11 08:19:31 +00:00
|
|
|
* the parent, so we only walk the list for those devclasses
|
Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced. If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices. However, there had been one exception: kldload
wouldn't work.
The problem is in devclass_add_driver. In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine. However, since
cardbus bus instances had a different devclass, none of them were
called.
The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded. Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches. Since just done a kldload time, this isn't as
bad as it sounds. In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag. We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.
This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.
# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
|
|
|
* that have children.
|
|
|
|
*/
|
|
|
|
if (!(dc->flags & DC_HAS_CHILDREN))
|
|
|
|
return;
|
|
|
|
parent = dc;
|
|
|
|
TAILQ_FOREACH(dc, &devclasses, link) {
|
|
|
|
if (dc->parent == parent)
|
|
|
|
devclass_driver_added(dc, driver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Add a device driver to a device class
|
|
|
|
*
|
|
|
|
* Add a device driver to a devclass. This is normally called
|
|
|
|
* automatically by DRIVER_MODULE(). The BUS_DRIVER_ADDED() method of
|
|
|
|
* all devices in the devclass will be called to allow them to attempt
|
|
|
|
* to re-probe any unmatched children.
|
|
|
|
*
|
|
|
|
* @param dc the devclass to edit
|
|
|
|
* @param driver the driver to register
|
|
|
|
*/
|
2011-03-21 09:40:01 +00:00
|
|
|
int
|
2009-10-22 14:53:44 +00:00
|
|
|
devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
driverlink_t dl;
|
2009-10-22 14:53:44 +00:00
|
|
|
const char *parentname;
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s", DRIVERNAME(driver)));
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2009-06-09 14:26:23 +00:00
|
|
|
/* Don't allow invalid pass values. */
|
|
|
|
if (pass <= BUS_PASS_ROOT)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
dl = malloc(sizeof *dl, M_BUS, M_NOWAIT|M_ZERO);
|
|
|
|
if (!dl)
|
|
|
|
return (ENOMEM);
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
/*
|
|
|
|
* Compile the driver's methods. Also increase the reference count
|
|
|
|
* so that the class doesn't get freed when the last instance
|
|
|
|
* goes. This means we can safely use static methods and avoids a
|
|
|
|
* double-free in devclass_delete_driver.
|
|
|
|
*/
|
|
|
|
kobj_class_compile((kobj_class_t) driver);
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
/*
|
2009-10-22 14:53:44 +00:00
|
|
|
* If the driver has any base classes, make the
|
|
|
|
* devclass inherit from the devclass of the driver's
|
|
|
|
* first base class. This will allow the system to
|
|
|
|
* search for drivers in both devclasses for children
|
|
|
|
* of a device using this driver.
|
2001-01-05 07:29:54 +00:00
|
|
|
*/
|
2009-10-22 14:53:44 +00:00
|
|
|
if (driver->baseclasses)
|
|
|
|
parentname = driver->baseclasses[0]->name;
|
|
|
|
else
|
|
|
|
parentname = NULL;
|
|
|
|
*dcp = devclass_find_internal(driver->name, parentname, TRUE);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
dl->driver = driver;
|
|
|
|
TAILQ_INSERT_TAIL(&dc->drivers, dl, link);
|
2005-03-31 22:49:31 +00:00
|
|
|
driver->refs++; /* XXX: kobj_mtx */
|
2009-06-09 14:26:23 +00:00
|
|
|
dl->pass = pass;
|
|
|
|
driver_register_pass(dl);
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2018-08-23 05:05:47 +00:00
|
|
|
if (device_frozen) {
|
|
|
|
dl->flags |= DL_DEFERRED_PROBE;
|
|
|
|
} else {
|
|
|
|
devclass_driver_added(dc, driver);
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 14:43:37 +00:00
|
|
|
/**
|
|
|
|
* @brief Register that a device driver has been deleted from a devclass
|
|
|
|
*
|
|
|
|
* Register that a device driver has been removed from a devclass.
|
|
|
|
* This is called by devclass_delete_driver to accomplish the
|
|
|
|
* recursive notification of all the children classes of busclass, as
|
|
|
|
* well as busclass. Each layer will attempt to detach the driver
|
|
|
|
* from any devices that are children of the bus's devclass. The function
|
|
|
|
* will return an error if a device fails to detach.
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2011-03-01 14:43:37 +00:00
|
|
|
* We do a full search here of the devclass list at each iteration
|
|
|
|
* level to save storing children-lists in the devclass structure. If
|
|
|
|
* we ever move beyond a few dozen devices doing this, we may need to
|
|
|
|
* reevaluate...
|
|
|
|
*
|
|
|
|
* @param busclass the devclass of the parent bus
|
|
|
|
* @param dc the devclass of the driver being deleted
|
|
|
|
* @param driver the driver being deleted
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
devclass_driver_deleted(devclass_t busclass, devclass_t dc, driver_t *driver)
|
|
|
|
{
|
|
|
|
devclass_t parent;
|
|
|
|
device_t dev;
|
|
|
|
int error, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disassociate from any devices. We iterate through all the
|
|
|
|
* devices in the devclass of the driver and detach any which are
|
|
|
|
* using the driver and which have a parent in the devclass which
|
|
|
|
* we are deleting from.
|
|
|
|
*
|
|
|
|
* Note that since a driver can be in multiple devclasses, we
|
|
|
|
* should not detach devices which are not children of devices in
|
|
|
|
* the affected devclass.
|
2018-08-23 05:05:47 +00:00
|
|
|
*
|
|
|
|
* If we're frozen, we don't generate NOMATCH events. Mark to
|
|
|
|
* generate later.
|
2011-03-01 14:43:37 +00:00
|
|
|
*/
|
|
|
|
for (i = 0; i < dc->maxunit; i++) {
|
|
|
|
if (dc->devices[i]) {
|
|
|
|
dev = dc->devices[i];
|
|
|
|
if (dev->driver == driver && dev->parent &&
|
|
|
|
dev->parent->devclass == busclass) {
|
|
|
|
if ((error = device_detach(dev)) != 0)
|
|
|
|
return (error);
|
2018-08-23 05:05:47 +00:00
|
|
|
if (device_frozen) {
|
|
|
|
dev->flags &= ~DF_DONENOMATCH;
|
|
|
|
dev->flags |= DF_NEEDNOMATCH;
|
|
|
|
} else {
|
|
|
|
BUS_PROBE_NOMATCH(dev->parent, dev);
|
|
|
|
devnomatch(dev);
|
|
|
|
dev->flags |= DF_DONENOMATCH;
|
|
|
|
}
|
2011-03-01 14:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk through the children classes. Since we only keep a
|
|
|
|
* single parent pointer around, we walk the entire list of
|
|
|
|
* devclasses looking for children. We set the
|
|
|
|
* DC_HAS_CHILDREN flag when a child devclass is created on
|
|
|
|
* the parent, so we only walk the list for those devclasses
|
|
|
|
* that have children.
|
|
|
|
*/
|
|
|
|
if (!(busclass->flags & DC_HAS_CHILDREN))
|
|
|
|
return (0);
|
|
|
|
parent = busclass;
|
|
|
|
TAILQ_FOREACH(busclass, &devclasses, link) {
|
|
|
|
if (busclass->parent == parent) {
|
|
|
|
error = devclass_driver_deleted(busclass, dc, driver);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Delete a device driver from a device class
|
|
|
|
*
|
|
|
|
* Delete a device driver from a devclass. This is normally called
|
|
|
|
* automatically by DRIVER_MODULE().
|
|
|
|
*
|
|
|
|
* If the driver is currently attached to any devices,
|
|
|
|
* devclass_delete_driver() will first attempt to detach from each
|
|
|
|
* device. If one of the detach calls fails, the driver will not be
|
|
|
|
* deleted.
|
|
|
|
*
|
|
|
|
* @param dc the devclass to edit
|
|
|
|
* @param driver the driver to unregister
|
|
|
|
*/
|
2011-03-21 09:40:01 +00:00
|
|
|
int
|
1998-10-27 09:21:43 +00:00
|
|
|
devclass_delete_driver(devclass_t busclass, driver_t *driver)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc = devclass_find(driver->name);
|
|
|
|
driverlink_t dl;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
|
|
|
|
|
|
|
|
if (!dc)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the link structure in the bus' list of drivers.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(dl, &busclass->drivers, link) {
|
|
|
|
if (dl->driver == driver)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dl) {
|
|
|
|
PDEBUG(("%s not found in %s list", driver->name,
|
|
|
|
busclass->name));
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
2011-03-01 14:43:37 +00:00
|
|
|
error = devclass_driver_deleted(busclass, dc, driver);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2001-01-05 07:29:54 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&busclass->drivers, dl, link);
|
|
|
|
free(dl, M_BUS);
|
|
|
|
|
2005-03-31 22:49:31 +00:00
|
|
|
/* XXX: kobj_mtx */
|
2001-01-05 07:29:54 +00:00
|
|
|
driver->refs--;
|
|
|
|
if (driver->refs == 0)
|
|
|
|
kobj_class_free((kobj_class_t) driver);
|
|
|
|
|
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 20:47:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Quiesces a set of device drivers from a device class
|
|
|
|
*
|
|
|
|
* Quiesce a device driver from a devclass. This is normally called
|
|
|
|
* automatically by DRIVER_MODULE().
|
|
|
|
*
|
|
|
|
* If the driver is currently attached to any devices,
|
|
|
|
* devclass_quiesece_driver() will first attempt to quiesce each
|
|
|
|
* device.
|
|
|
|
*
|
|
|
|
* @param dc the devclass to edit
|
|
|
|
* @param driver the driver to unregister
|
|
|
|
*/
|
2009-06-09 23:24:04 +00:00
|
|
|
static int
|
2004-12-31 20:47:51 +00:00
|
|
|
devclass_quiesce_driver(devclass_t busclass, driver_t *driver)
|
|
|
|
{
|
|
|
|
devclass_t dc = devclass_find(driver->name);
|
|
|
|
driverlink_t dl;
|
|
|
|
device_t dev;
|
|
|
|
int i;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
|
|
|
|
|
|
|
|
if (!dc)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the link structure in the bus' list of drivers.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(dl, &busclass->drivers, link) {
|
|
|
|
if (dl->driver == driver)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dl) {
|
|
|
|
PDEBUG(("%s not found in %s list", driver->name,
|
|
|
|
busclass->name));
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quiesce all devices. We iterate through all the devices in
|
|
|
|
* the devclass of the driver and quiesce any which are using
|
|
|
|
* the driver and which have a parent in the devclass which we
|
|
|
|
* are quiescing.
|
|
|
|
*
|
|
|
|
* Note that since a driver can be in multiple devclasses, we
|
|
|
|
* should not quiesce devices which are not children of
|
|
|
|
* devices in the affected devclass.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < dc->maxunit; i++) {
|
|
|
|
if (dc->devices[i]) {
|
|
|
|
dev = dc->devices[i];
|
|
|
|
if (dev->driver == driver && dev->parent &&
|
|
|
|
dev->parent->devclass == busclass) {
|
|
|
|
if ((error = device_quiesce(dev)) != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
static driverlink_t
|
|
|
|
devclass_find_driver_internal(devclass_t dc, const char *classname)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
driverlink_t dl;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s in devclass %s", classname, DEVCLANAME(dc)));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link) {
|
|
|
|
if (!strcmp(dl->driver->name, classname))
|
|
|
|
return (dl);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("not found"));
|
|
|
|
return (NULL);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the name of the devclass
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
const char *
|
|
|
|
devclass_get_name(devclass_t dc)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dc->name);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find a device given a unit number
|
|
|
|
*
|
|
|
|
* @param dc the devclass to search
|
|
|
|
* @param unit the unit number to search for
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the device with the given unit number or @c
|
|
|
|
* NULL if there is no such device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
device_t
|
|
|
|
devclass_get_device(devclass_t dc, int unit)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dc == NULL || unit < 0 || unit >= dc->maxunit)
|
|
|
|
return (NULL);
|
|
|
|
return (dc->devices[unit]);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find the softc field of a device given a unit number
|
|
|
|
*
|
|
|
|
* @param dc the devclass to search
|
|
|
|
* @param unit the unit number to search for
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the softc field of the device with the given
|
|
|
|
* unit number or @c NULL if there is no such
|
|
|
|
* device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void *
|
|
|
|
devclass_get_softc(devclass_t dc, int unit)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t dev;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
dev = devclass_get_device(dc, unit);
|
|
|
|
if (!dev)
|
|
|
|
return (NULL);
|
1999-11-30 07:06:03 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (device_get_softc(dev));
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Get a list of devices in the devclass
|
|
|
|
*
|
|
|
|
* An array containing a list of all the devices in the given devclass
|
|
|
|
* is allocated and returned in @p *devlistp. The number of devices
|
|
|
|
* in the array is returned in @p *devcountp. The caller should free
|
2005-05-20 05:04:22 +00:00
|
|
|
* the array using @c free(p, M_TEMP), even if @p *devcountp is 0.
|
2004-07-18 16:30:31 +00:00
|
|
|
*
|
|
|
|
* @param dc the devclass to examine
|
|
|
|
* @param devlistp points at location for array pointer return
|
|
|
|
* value
|
|
|
|
* @param devcountp points at location for array size return value
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENOMEM the array allocation failed
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp)
|
|
|
|
{
|
2004-12-08 02:39:56 +00:00
|
|
|
int count, i;
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t *list;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2004-12-08 02:39:56 +00:00
|
|
|
count = devclass_get_count(dc);
|
2018-01-21 15:42:36 +00:00
|
|
|
list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!list)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < dc->maxunit; i++) {
|
|
|
|
if (dc->devices[i]) {
|
|
|
|
list[count] = dc->devices[i];
|
|
|
|
count++;
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
*devlistp = list;
|
|
|
|
*devcountp = count;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 15:26:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Get a list of drivers in the devclass
|
|
|
|
*
|
|
|
|
* An array containing a list of pointers to all the drivers in the
|
|
|
|
* given devclass is allocated and returned in @p *listp. The number
|
|
|
|
* of drivers in the array is returned in @p *countp. The caller should
|
|
|
|
* free the array using @c free(p, M_TEMP).
|
|
|
|
*
|
|
|
|
* @param dc the devclass to examine
|
|
|
|
* @param listp gives location for array pointer return value
|
|
|
|
* @param countp gives location for number of array elements
|
|
|
|
* return value
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENOMEM the array allocation failed
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
devclass_get_drivers(devclass_t dc, driver_t ***listp, int *countp)
|
|
|
|
{
|
|
|
|
driverlink_t dl;
|
|
|
|
driver_t **list;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link)
|
|
|
|
count++;
|
|
|
|
list = malloc(count * sizeof(driver_t *), M_TEMP, M_NOWAIT);
|
|
|
|
if (list == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link) {
|
|
|
|
list[count] = dl->driver;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
*listp = list;
|
|
|
|
*countp = count;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-12-08 02:39:56 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the number of devices in a devclass
|
|
|
|
*
|
|
|
|
* @param dc the devclass to examine
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
devclass_get_count(devclass_t dc)
|
|
|
|
{
|
|
|
|
int count, i;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < dc->maxunit; i++)
|
|
|
|
if (dc->devices[i])
|
|
|
|
count++;
|
|
|
|
return (count);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the maximum unit number used in a devclass
|
|
|
|
*
|
2005-04-04 15:37:59 +00:00
|
|
|
* Note that this is one greater than the highest currently-allocated
|
2007-12-19 22:05:07 +00:00
|
|
|
* unit. If a null devclass_t is passed in, -1 is returned to indicate
|
|
|
|
* that not even the devclass has been allocated yet.
|
2005-04-04 15:37:59 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param dc the devclass to examine
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
devclass_get_maxunit(devclass_t dc)
|
|
|
|
{
|
2007-12-19 22:05:07 +00:00
|
|
|
if (dc == NULL)
|
|
|
|
return (-1);
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dc->maxunit);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find a free unit number in a devclass
|
|
|
|
*
|
|
|
|
* This function searches for the first unused unit number greater
|
|
|
|
* that or equal to @p unit.
|
|
|
|
*
|
|
|
|
* @param dc the devclass to examine
|
|
|
|
* @param unit the first unit number to check
|
|
|
|
*/
|
2001-11-01 05:07:28 +00:00
|
|
|
int
|
|
|
|
devclass_find_free_unit(devclass_t dc, int unit)
|
|
|
|
{
|
|
|
|
if (dc == NULL)
|
|
|
|
return (unit);
|
|
|
|
while (unit < dc->maxunit && dc->devices[unit] != NULL)
|
|
|
|
unit++;
|
|
|
|
return (unit);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the parent of a devclass
|
|
|
|
*
|
|
|
|
* The parent class is normally initialised automatically by
|
|
|
|
* DRIVER_MODULE().
|
|
|
|
*
|
|
|
|
* @param dc the devclass to edit
|
|
|
|
* @param pdc the new parent devclass
|
|
|
|
*/
|
2003-10-16 09:16:28 +00:00
|
|
|
void
|
|
|
|
devclass_set_parent(devclass_t dc, devclass_t pdc)
|
|
|
|
{
|
|
|
|
dc->parent = pdc;
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the parent of a devclass
|
|
|
|
*
|
|
|
|
* @param dc the devclass to examine
|
|
|
|
*/
|
2003-10-16 09:16:28 +00:00
|
|
|
devclass_t
|
|
|
|
devclass_get_parent(devclass_t dc)
|
|
|
|
{
|
|
|
|
return (dc->parent);
|
|
|
|
}
|
|
|
|
|
2004-06-04 10:23:00 +00:00
|
|
|
struct sysctl_ctx_list *
|
|
|
|
devclass_get_sysctl_ctx(devclass_t dc)
|
|
|
|
{
|
|
|
|
return (&dc->sysctl_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sysctl_oid *
|
|
|
|
devclass_get_sysctl_tree(devclass_t dc)
|
|
|
|
{
|
|
|
|
return (dc->sysctl_tree);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Allocate a unit number
|
|
|
|
*
|
|
|
|
* On entry, @p *unitp is the desired unit number (or @c -1 if any
|
|
|
|
* will do). The allocated unit number is returned in @p *unitp.
|
|
|
|
|
|
|
|
* @param dc the devclass to allocate from
|
|
|
|
* @param unitp points at the location for the allocated unit
|
|
|
|
* number
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval EEXIST the requested unit number is already allocated
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
static int
|
2008-11-18 21:01:54 +00:00
|
|
|
devclass_alloc_unit(devclass_t dc, device_t dev, int *unitp)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2008-11-18 21:01:54 +00:00
|
|
|
const char *s;
|
2001-01-05 07:29:54 +00:00
|
|
|
int unit = *unitp;
|
|
|
|
|
|
|
|
PDEBUG(("unit %d in devclass %s", unit, DEVCLANAME(dc)));
|
|
|
|
|
2008-11-18 21:01:54 +00:00
|
|
|
/* Ask the parent bus if it wants to wire this device. */
|
|
|
|
if (unit == -1)
|
|
|
|
BUS_HINT_DEVICE_UNIT(device_get_parent(dev), dev, dc->name,
|
|
|
|
&unit);
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
/* If we were given a wired unit number, check for existing device */
|
|
|
|
/* XXX imp XXX */
|
|
|
|
if (unit != -1) {
|
2002-02-26 16:17:45 +00:00
|
|
|
if (unit >= 0 && unit < dc->maxunit &&
|
|
|
|
dc->devices[unit] != NULL) {
|
2002-02-26 10:38:33 +00:00
|
|
|
if (bootverbose)
|
2002-02-26 16:17:45 +00:00
|
|
|
printf("%s: %s%d already exists; skipping it\n",
|
|
|
|
dc->name, dc->name, *unitp);
|
2001-10-28 23:32:35 +00:00
|
|
|
return (EEXIST);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Unwired device, find the next available slot for it */
|
|
|
|
unit = 0;
|
2008-11-18 21:01:54 +00:00
|
|
|
for (unit = 0;; unit++) {
|
|
|
|
/* If there is an "at" hint for a unit then skip it. */
|
|
|
|
if (resource_string_value(dc->name, unit, "at", &s) ==
|
|
|
|
0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If this device slot is already in use, skip it. */
|
|
|
|
if (unit < dc->maxunit && dc->devices[unit] != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've selected a unit beyond the length of the table, so let's
|
|
|
|
* extend the table to make room for all units up to and including
|
|
|
|
* this one.
|
|
|
|
*/
|
|
|
|
if (unit >= dc->maxunit) {
|
Close, but not eliminate, a race condition. It is one that properly
designed drivers would never hit, but was exposed in diving into
another problem...
When expanding the devclass array, free the old memory after updating
the pointer to the new memory. For the following single race case,
this helps:
allocate new memory
copy to new memory
free old memory
<interrupt> read pointer to freed memory
update pointer to new memory
Now we do
allocate new memory
copy to new memory
update pointer to new memory
free old memory
Which closes this problem, but doesn't even begin to address the
multicpu races, which all should be covered by Giant at the moment,
but likely aren't completely.
Note: reviewers were ok with this fix, but suggested the use case
wasn't one we wanted to encourage.
Reviewed by: jhb, scottl.
2008-10-10 17:49:47 +00:00
|
|
|
device_t *newlist, *oldlist;
|
2001-01-05 07:29:54 +00:00
|
|
|
int newsize;
|
|
|
|
|
Close, but not eliminate, a race condition. It is one that properly
designed drivers would never hit, but was exposed in diving into
another problem...
When expanding the devclass array, free the old memory after updating
the pointer to the new memory. For the following single race case,
this helps:
allocate new memory
copy to new memory
free old memory
<interrupt> read pointer to freed memory
update pointer to new memory
Now we do
allocate new memory
copy to new memory
update pointer to new memory
free old memory
Which closes this problem, but doesn't even begin to address the
multicpu races, which all should be covered by Giant at the moment,
but likely aren't completely.
Note: reviewers were ok with this fix, but suggested the use case
wasn't one we wanted to encourage.
Reviewed by: jhb, scottl.
2008-10-10 17:49:47 +00:00
|
|
|
oldlist = dc->devices;
|
2001-01-05 07:29:54 +00:00
|
|
|
newsize = roundup((unit + 1), MINALLOCSIZE / sizeof(device_t));
|
2018-01-21 15:42:36 +00:00
|
|
|
newlist = malloc(sizeof(device_t) * newsize, M_BUS, M_NOWAIT);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!newlist)
|
|
|
|
return (ENOMEM);
|
Close, but not eliminate, a race condition. It is one that properly
designed drivers would never hit, but was exposed in diving into
another problem...
When expanding the devclass array, free the old memory after updating
the pointer to the new memory. For the following single race case,
this helps:
allocate new memory
copy to new memory
free old memory
<interrupt> read pointer to freed memory
update pointer to new memory
Now we do
allocate new memory
copy to new memory
update pointer to new memory
free old memory
Which closes this problem, but doesn't even begin to address the
multicpu races, which all should be covered by Giant at the moment,
but likely aren't completely.
Note: reviewers were ok with this fix, but suggested the use case
wasn't one we wanted to encourage.
Reviewed by: jhb, scottl.
2008-10-10 17:49:47 +00:00
|
|
|
if (oldlist != NULL)
|
|
|
|
bcopy(oldlist, newlist, sizeof(device_t) * dc->maxunit);
|
2001-01-05 07:29:54 +00:00
|
|
|
bzero(newlist + dc->maxunit,
|
|
|
|
sizeof(device_t) * (newsize - dc->maxunit));
|
|
|
|
dc->devices = newlist;
|
|
|
|
dc->maxunit = newsize;
|
Close, but not eliminate, a race condition. It is one that properly
designed drivers would never hit, but was exposed in diving into
another problem...
When expanding the devclass array, free the old memory after updating
the pointer to the new memory. For the following single race case,
this helps:
allocate new memory
copy to new memory
free old memory
<interrupt> read pointer to freed memory
update pointer to new memory
Now we do
allocate new memory
copy to new memory
update pointer to new memory
free old memory
Which closes this problem, but doesn't even begin to address the
multicpu races, which all should be covered by Giant at the moment,
but likely aren't completely.
Note: reviewers were ok with this fix, but suggested the use case
wasn't one we wanted to encourage.
Reviewed by: jhb, scottl.
2008-10-10 17:49:47 +00:00
|
|
|
if (oldlist != NULL)
|
|
|
|
free(oldlist, M_BUS);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
|
|
|
PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));
|
|
|
|
|
|
|
|
*unitp = unit;
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Add a device to a devclass
|
|
|
|
*
|
|
|
|
* A unit number is allocated for the device (using the device's
|
|
|
|
* preferred unit number if any) and the device is registered in the
|
|
|
|
* devclass. This allows the device to be looked up by its unit
|
|
|
|
* number, e.g. by decoding a dev_t minor number.
|
|
|
|
*
|
|
|
|
* @param dc the devclass to add to
|
|
|
|
* @param dev the device to add
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval EEXIST the requested unit number is already allocated
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
static int
|
|
|
|
devclass_add_device(devclass_t dc, device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
int buflen, error;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2009-11-12 00:52:14 +00:00
|
|
|
buflen = snprintf(NULL, 0, "%s%d$", dc->name, INT_MAX);
|
2002-03-06 11:34:02 +00:00
|
|
|
if (buflen < 0)
|
|
|
|
return (ENOMEM);
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->nameunit = malloc(buflen, M_BUS, M_NOWAIT|M_ZERO);
|
|
|
|
if (!dev->nameunit)
|
|
|
|
return (ENOMEM);
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2008-11-18 21:01:54 +00:00
|
|
|
if ((error = devclass_alloc_unit(dc, dev, &dev->unit)) != 0) {
|
2001-01-05 07:29:54 +00:00
|
|
|
free(dev->nameunit, M_BUS);
|
|
|
|
dev->nameunit = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
dc->devices[dev->unit] = dev;
|
|
|
|
dev->devclass = dc;
|
|
|
|
snprintf(dev->nameunit, buflen, "%s%d", dc->name, dev->unit);
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Delete a device from a devclass
|
|
|
|
*
|
|
|
|
* The device is removed from the devclass's device list and its unit
|
|
|
|
* number is freed.
|
|
|
|
|
|
|
|
* @param dc the devclass to delete from
|
|
|
|
* @param dev the device to delete
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
static int
|
|
|
|
devclass_delete_device(devclass_t dc, device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!dc || !dev)
|
|
|
|
return (0);
|
1998-11-15 18:11:21 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->devclass != dc || dc->devices[dev->unit] != dev)
|
|
|
|
panic("devclass_delete_device: inconsistent device class");
|
|
|
|
dc->devices[dev->unit] = NULL;
|
|
|
|
if (dev->flags & DF_WILDCARD)
|
|
|
|
dev->unit = -1;
|
|
|
|
dev->devclass = NULL;
|
|
|
|
free(dev->nameunit, M_BUS);
|
|
|
|
dev->nameunit = NULL;
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Make a new device and add it as a child of @p parent
|
|
|
|
*
|
|
|
|
* @param parent the parent of the new device
|
|
|
|
* @param name the devclass name of the new device or @c NULL
|
|
|
|
* to leave the devclass unspecified
|
|
|
|
* @parem unit the unit number of the new device of @c -1 to
|
|
|
|
* leave the unit number unspecified
|
|
|
|
*
|
|
|
|
* @returns the new device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
static device_t
|
1999-12-03 08:41:24 +00:00
|
|
|
make_device(device_t parent, const char *name, int unit)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t dev;
|
|
|
|
devclass_t dc;
|
|
|
|
|
|
|
|
PDEBUG(("%s at %s as unit %d", name, DEVICENAME(parent), unit));
|
|
|
|
|
|
|
|
if (name) {
|
2007-02-26 19:28:18 +00:00
|
|
|
dc = devclass_find_internal(name, NULL, TRUE);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!dc) {
|
|
|
|
printf("make_device: can't find device class %s\n",
|
|
|
|
name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dc = NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-09 19:32:06 +00:00
|
|
|
dev = malloc(sizeof(*dev), M_BUS, M_NOWAIT|M_ZERO);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!dev)
|
2001-10-28 23:32:35 +00:00
|
|
|
return (NULL);
|
2001-01-05 07:29:54 +00:00
|
|
|
|
|
|
|
dev->parent = parent;
|
|
|
|
TAILQ_INIT(&dev->children);
|
|
|
|
kobj_init((kobj_t) dev, &null_class);
|
|
|
|
dev->driver = NULL;
|
|
|
|
dev->devclass = NULL;
|
|
|
|
dev->unit = unit;
|
|
|
|
dev->nameunit = NULL;
|
|
|
|
dev->desc = NULL;
|
|
|
|
dev->busy = 0;
|
|
|
|
dev->devflags = 0;
|
|
|
|
dev->flags = DF_ENABLED;
|
|
|
|
dev->order = 0;
|
|
|
|
if (unit == -1)
|
|
|
|
dev->flags |= DF_WILDCARD;
|
|
|
|
if (name) {
|
|
|
|
dev->flags |= DF_FIXEDCLASS;
|
2001-10-28 23:32:35 +00:00
|
|
|
if (devclass_add_device(dc, dev)) {
|
|
|
|
kobj_delete((kobj_t) dev, M_BUS);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
2018-05-07 21:09:08 +00:00
|
|
|
if (parent != NULL && device_has_quiet_children(parent))
|
|
|
|
dev->flags |= DF_QUIET | DF_QUIET_CHILDREN;
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->ivars = NULL;
|
|
|
|
dev->softc = NULL;
|
|
|
|
|
|
|
|
dev->state = DS_NOTPRESENT;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&bus_data_devices, dev, devlink);
|
|
|
|
bus_data_generation_update();
|
|
|
|
|
|
|
|
return (dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @brief Print a description of a device.
|
|
|
|
*/
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1998-06-14 13:46:10 +00:00
|
|
|
device_print_child(device_t dev, device_t child)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
int retval = 0;
|
1999-07-29 01:03:04 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (device_is_alive(child))
|
|
|
|
retval += BUS_PRINT_CHILD(dev, child);
|
|
|
|
else
|
|
|
|
retval += device_printf(child, " not found\n");
|
1999-07-29 01:03:04 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (retval);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Create a new device
|
|
|
|
*
|
|
|
|
* This creates a new device and adds it as a child of an existing
|
|
|
|
* parent device. The new device will be added after the last existing
|
|
|
|
* child with order zero.
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param dev the device which will be the parent of the
|
|
|
|
* new child device
|
|
|
|
* @param name devclass name for new device or @c NULL if not
|
|
|
|
* specified
|
|
|
|
* @param unit unit number for new device or @c -1 if not
|
|
|
|
* specified
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the new device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
device_t
|
1999-12-03 08:41:24 +00:00
|
|
|
device_add_child(device_t dev, const char *name, int unit)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (device_add_child_ordered(dev, 0, name, unit));
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Create a new device
|
|
|
|
*
|
|
|
|
* This creates a new device and adds it as a child of an existing
|
|
|
|
* parent device. The new device will be added after the last existing
|
|
|
|
* child with the same order.
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param dev the device which will be the parent of the
|
|
|
|
* new child device
|
|
|
|
* @param order a value which is used to partially sort the
|
|
|
|
* children of @p dev - devices created using
|
|
|
|
* lower values of @p order appear first in @p
|
|
|
|
* dev's list of children
|
|
|
|
* @param name devclass name for new device or @c NULL if not
|
|
|
|
* specified
|
|
|
|
* @param unit unit number for new device or @c -1 if not
|
|
|
|
* specified
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the new device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
device_t
|
2010-09-04 17:28:29 +00:00
|
|
|
device_add_child_ordered(device_t dev, u_int order, const char *name, int unit)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t child;
|
|
|
|
device_t place;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2010-09-04 17:28:29 +00:00
|
|
|
PDEBUG(("%s at %s with order %u as unit %d",
|
1999-12-03 08:41:24 +00:00
|
|
|
name, DEVICENAME(dev), order, unit));
|
2012-05-25 07:32:26 +00:00
|
|
|
KASSERT(name != NULL || unit == -1,
|
|
|
|
("child device with wildcard name and specific unit number"));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
child = make_device(dev, name, unit);
|
|
|
|
if (child == NULL)
|
|
|
|
return (child);
|
|
|
|
child->order = order;
|
1999-05-28 09:25:16 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(place, &dev->children, link) {
|
|
|
|
if (place->order > order)
|
|
|
|
break;
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (place) {
|
|
|
|
/*
|
|
|
|
* The device 'place' is the first device whose order is
|
|
|
|
* greater than the new child.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_BEFORE(place, child, link);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The new child's order is greater or equal to the order of
|
|
|
|
* any existing device. Add the child to the tail of the list.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(&dev->children, child, link);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (child);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Delete a device
|
|
|
|
*
|
|
|
|
* This function deletes a device along with all of its children. If
|
|
|
|
* the device currently has a driver attached to it, the device is
|
|
|
|
* detached first using device_detach().
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param dev the parent device
|
|
|
|
* @param child the device to delete
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval non-zero a unit error code describing the error
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
1998-06-14 13:46:10 +00:00
|
|
|
device_delete_child(device_t dev, device_t child)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
int error;
|
|
|
|
device_t grandchild;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2016-10-17 10:20:38 +00:00
|
|
|
/* detach parent before deleting children, if any */
|
|
|
|
if ((error = device_detach(child)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* remove children second */
|
2011-11-22 21:53:19 +00:00
|
|
|
while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) {
|
2001-01-05 07:29:54 +00:00
|
|
|
error = device_delete_child(child, grandchild);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-11-13 09:39:37 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (child->devclass)
|
|
|
|
devclass_delete_device(child->devclass, child);
|
2012-08-21 18:13:09 +00:00
|
|
|
if (child->parent)
|
|
|
|
BUS_CHILD_DELETED(dev, child);
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_REMOVE(&dev->children, child, link);
|
|
|
|
TAILQ_REMOVE(&bus_data_devices, child, devlink);
|
2003-01-15 14:58:07 +00:00
|
|
|
kobj_delete((kobj_t) child, M_BUS);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
2011-11-19 10:11:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delete all children devices of the given device, if any.
|
|
|
|
*
|
|
|
|
* This function deletes all children devices of the given device, if
|
|
|
|
* any, using the device_delete_child() function for each device it
|
|
|
|
* finds. If a child device cannot be deleted, this function will
|
|
|
|
* return an error code.
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2011-11-19 10:11:50 +00:00
|
|
|
* @param dev the parent device
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval non-zero a device would not detach
|
|
|
|
*/
|
|
|
|
int
|
2011-11-22 21:56:55 +00:00
|
|
|
device_delete_children(device_t dev)
|
2011-11-19 10:11:50 +00:00
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
PDEBUG(("Deleting all children of %s", DEVICENAME(dev)));
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
2011-11-22 21:53:19 +00:00
|
|
|
while ((child = TAILQ_FIRST(&dev->children)) != NULL) {
|
2011-11-19 10:11:50 +00:00
|
|
|
error = device_delete_child(dev, child);
|
|
|
|
if (error) {
|
|
|
|
PDEBUG(("Failed deleting %s", DEVICENAME(child)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find a device given a unit number
|
|
|
|
*
|
|
|
|
* This is similar to devclass_get_devices() but only searches for
|
|
|
|
* devices which have @p dev as a parent.
|
|
|
|
*
|
|
|
|
* @param dev the parent device to search
|
2005-02-08 18:00:29 +00:00
|
|
|
* @param unit the unit number to search for. If the unit is -1,
|
|
|
|
* return the first child of @p dev which has name
|
|
|
|
* @p classname (that is, the one with the lowest unit.)
|
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the device with the given unit number or @c
|
|
|
|
* NULL if there is no such device
|
1998-06-10 10:57:29 +00:00
|
|
|
*/
|
|
|
|
device_t
|
1998-06-14 13:46:10 +00:00
|
|
|
device_find_child(device_t dev, const char *classname, int unit)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc;
|
|
|
|
device_t child;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
dc = devclass_find(classname);
|
|
|
|
if (!dc)
|
|
|
|
return (NULL);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2005-02-08 18:00:29 +00:00
|
|
|
if (unit != -1) {
|
|
|
|
child = devclass_get_device(dc, unit);
|
|
|
|
if (child && child->parent == dev)
|
|
|
|
return (child);
|
|
|
|
} else {
|
2005-04-03 22:23:18 +00:00
|
|
|
for (unit = 0; unit < devclass_get_maxunit(dc); unit++) {
|
2005-02-08 18:00:29 +00:00
|
|
|
child = devclass_get_device(dc, unit);
|
|
|
|
if (child && child->parent == dev)
|
|
|
|
return (child);
|
|
|
|
}
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
return (NULL);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
static driverlink_t
|
1998-06-10 10:57:29 +00:00
|
|
|
first_matching_driver(devclass_t dc, device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->devclass)
|
|
|
|
return (devclass_find_driver_internal(dc, dev->devclass->name));
|
|
|
|
return (TAILQ_FIRST(&dc->drivers));
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
static driverlink_t
|
|
|
|
next_matching_driver(devclass_t dc, device_t dev, driverlink_t last)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->devclass) {
|
|
|
|
driverlink_t dl;
|
|
|
|
for (dl = TAILQ_NEXT(last, link); dl; dl = TAILQ_NEXT(dl, link))
|
|
|
|
if (!strcmp(dev->devclass->name, dl->driver->name))
|
|
|
|
return (dl);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
return (TAILQ_NEXT(last, link));
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2005-09-18 01:32:09 +00:00
|
|
|
int
|
1998-06-14 13:46:10 +00:00
|
|
|
device_probe_child(device_t dev, device_t child)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc;
|
2007-02-26 19:28:18 +00:00
|
|
|
driverlink_t best = NULL;
|
2001-01-05 07:29:54 +00:00
|
|
|
driverlink_t dl;
|
|
|
|
int result, pri = 0;
|
2009-02-03 00:10:21 +00:00
|
|
|
int hasclass = (child->devclass != NULL);
|
1999-05-10 17:06:14 +00:00
|
|
|
|
2009-08-20 19:17:53 +00:00
|
|
|
GIANT_REQUIRED;
|
2004-12-05 07:55:30 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
dc = dev->devclass;
|
|
|
|
if (!dc)
|
|
|
|
panic("device_probe_child: parent device has no devclass");
|
1999-05-10 17:06:14 +00:00
|
|
|
|
2004-08-29 18:25:21 +00:00
|
|
|
/*
|
|
|
|
* If the state is already probed, then return. However, don't
|
|
|
|
* return if we can rebid this object.
|
|
|
|
*/
|
|
|
|
if (child->state == DS_ALIVE && (child->flags & DF_REBID) == 0)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
for (; dc; dc = dc->parent) {
|
|
|
|
for (dl = first_matching_driver(dc, child);
|
|
|
|
dl;
|
|
|
|
dl = next_matching_driver(dc, child, dl)) {
|
2009-06-09 14:26:23 +00:00
|
|
|
/* If this driver's pass is too high, then ignore it. */
|
|
|
|
if (dl->pass > bus_current_pass)
|
|
|
|
continue;
|
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
PDEBUG(("Trying %s", DRIVERNAME(dl->driver)));
|
2011-12-02 21:19:14 +00:00
|
|
|
result = device_set_driver(child, dl->driver);
|
|
|
|
if (result == ENOMEM)
|
|
|
|
return (result);
|
|
|
|
else if (result != 0)
|
|
|
|
continue;
|
2009-02-10 23:22:29 +00:00
|
|
|
if (!hasclass) {
|
2011-12-02 22:03:27 +00:00
|
|
|
if (device_set_devclass(child,
|
|
|
|
dl->driver->name) != 0) {
|
2012-01-15 07:09:18 +00:00
|
|
|
char const * devname =
|
|
|
|
device_get_name(child);
|
|
|
|
if (devname == NULL)
|
|
|
|
devname = "(unknown)";
|
2011-12-02 22:03:27 +00:00
|
|
|
printf("driver bug: Unable to set "
|
2012-01-15 07:09:18 +00:00
|
|
|
"devclass (class: %s "
|
|
|
|
"devname: %s)\n",
|
|
|
|
dl->driver->name,
|
|
|
|
devname);
|
2011-12-02 21:19:14 +00:00
|
|
|
(void)device_set_driver(child, NULL);
|
2009-02-10 23:22:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2004-10-14 17:14:56 +00:00
|
|
|
|
|
|
|
/* Fetch any flags for the device before probing. */
|
|
|
|
resource_int_value(dl->driver->name, child->unit,
|
|
|
|
"flags", &child->devflags);
|
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
result = DEVICE_PROBE(child);
|
2004-10-14 17:14:56 +00:00
|
|
|
|
|
|
|
/* Reset flags and devclass before the next probe. */
|
|
|
|
child->devflags = 0;
|
2003-10-16 09:16:28 +00:00
|
|
|
if (!hasclass)
|
2011-12-02 21:19:14 +00:00
|
|
|
(void)device_set_devclass(child, NULL);
|
2001-01-05 07:29:54 +00:00
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
/*
|
|
|
|
* If the driver returns SUCCESS, there can be
|
|
|
|
* no higher match for this device.
|
|
|
|
*/
|
|
|
|
if (result == 0) {
|
|
|
|
best = dl;
|
|
|
|
pri = 0;
|
|
|
|
break;
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
|
2016-09-12 18:06:42 +00:00
|
|
|
/*
|
|
|
|
* Reset DF_QUIET in case this driver doesn't
|
|
|
|
* end up as the best driver.
|
|
|
|
*/
|
|
|
|
device_verbose(child);
|
|
|
|
|
2015-04-15 16:22:05 +00:00
|
|
|
/*
|
|
|
|
* Probes that return BUS_PROBE_NOWILDCARD or lower
|
|
|
|
* only match on devices whose driver was explicitly
|
|
|
|
* specified.
|
|
|
|
*/
|
|
|
|
if (result <= BUS_PROBE_NOWILDCARD &&
|
|
|
|
!(child->flags & DF_FIXEDCLASS)) {
|
|
|
|
result = ENXIO;
|
|
|
|
}
|
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
/*
|
|
|
|
* The driver returned an error so it
|
|
|
|
* certainly doesn't match.
|
|
|
|
*/
|
|
|
|
if (result > 0) {
|
2011-12-02 21:19:14 +00:00
|
|
|
(void)device_set_driver(child, NULL);
|
2003-10-16 09:16:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
|
2003-10-16 09:16:28 +00:00
|
|
|
/*
|
|
|
|
* A priority lower than SUCCESS, remember the
|
|
|
|
* best matching driver. Initialise the value
|
|
|
|
* of pri for the first match.
|
|
|
|
*/
|
2007-02-26 19:28:18 +00:00
|
|
|
if (best == NULL || result > pri) {
|
2003-10-16 09:16:28 +00:00
|
|
|
best = dl;
|
|
|
|
pri = result;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
/*
|
2003-10-16 09:16:28 +00:00
|
|
|
* If we have an unambiguous match in this devclass,
|
|
|
|
* don't look in the parent.
|
2001-01-05 07:29:54 +00:00
|
|
|
*/
|
2003-10-16 09:16:28 +00:00
|
|
|
if (best && pri == 0)
|
|
|
|
break;
|
2000-02-29 09:36:25 +00:00
|
|
|
}
|
1999-05-10 17:06:14 +00:00
|
|
|
|
|
|
|
/*
|
2001-01-05 07:29:54 +00:00
|
|
|
* If we found a driver, change state and initialise the devclass.
|
1999-05-10 17:06:14 +00:00
|
|
|
*/
|
2004-08-29 18:25:21 +00:00
|
|
|
/* XXX What happens if we rebid and got no best? */
|
2001-01-05 07:29:54 +00:00
|
|
|
if (best) {
|
2004-08-29 18:25:21 +00:00
|
|
|
/*
|
2012-02-27 16:08:18 +00:00
|
|
|
* If this device was attached, and we were asked to
|
2004-08-29 18:25:21 +00:00
|
|
|
* rescan, and it is a different driver, then we have
|
|
|
|
* to detach the old driver and reattach this new one.
|
|
|
|
* Note, we don't have to check for DF_REBID here
|
|
|
|
* because if the state is > DS_ALIVE, we know it must
|
|
|
|
* be.
|
|
|
|
*
|
|
|
|
* This assumes that all DF_REBID drivers can have
|
|
|
|
* their probe routine called at any time and that
|
|
|
|
* they are idempotent as well as completely benign in
|
|
|
|
* normal operations.
|
|
|
|
*
|
|
|
|
* We also have to make sure that the detach
|
|
|
|
* succeeded, otherwise we fail the operation (or
|
|
|
|
* maybe it should just fail silently? I'm torn).
|
|
|
|
*/
|
|
|
|
if (child->state > DS_ALIVE && best->driver != child->driver)
|
|
|
|
if ((result = device_detach(dev)) != 0)
|
|
|
|
return (result);
|
2004-10-14 17:14:56 +00:00
|
|
|
|
|
|
|
/* Set the winning driver, devclass, and flags. */
|
2009-02-10 23:22:29 +00:00
|
|
|
if (!child->devclass) {
|
|
|
|
result = device_set_devclass(child, best->driver->name);
|
|
|
|
if (result != 0)
|
|
|
|
return (result);
|
|
|
|
}
|
2011-12-02 21:19:14 +00:00
|
|
|
result = device_set_driver(child, best->driver);
|
|
|
|
if (result != 0)
|
|
|
|
return (result);
|
2004-10-14 17:14:56 +00:00
|
|
|
resource_int_value(best->driver->name, child->unit,
|
|
|
|
"flags", &child->devflags);
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (pri < 0) {
|
|
|
|
/*
|
|
|
|
* A bit bogus. Call the probe method again to make
|
|
|
|
* sure that we have the right description.
|
|
|
|
*/
|
|
|
|
DEVICE_PROBE(child);
|
2004-08-29 18:25:21 +00:00
|
|
|
#if 0
|
|
|
|
child->flags |= DF_REBID;
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
child->flags &= ~DF_REBID;
|
2001-01-05 07:29:54 +00:00
|
|
|
child->state = DS_ALIVE;
|
2000-11-09 10:21:23 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (ENXIO);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the parent of a device
|
|
|
|
*/
|
1998-06-14 13:46:10 +00:00
|
|
|
device_t
|
1998-06-10 10:57:29 +00:00
|
|
|
device_get_parent(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->parent);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Get a list of children of a device
|
|
|
|
*
|
|
|
|
* An array containing a list of all the children of the given device
|
|
|
|
* is allocated and returned in @p *devlistp. The number of devices
|
|
|
|
* in the array is returned in @p *devcountp. The caller should free
|
|
|
|
* the array using @c free(p, M_TEMP).
|
|
|
|
*
|
|
|
|
* @param dev the device to examine
|
|
|
|
* @param devlistp points at location for array pointer return
|
|
|
|
* value
|
|
|
|
* @param devcountp points at location for array size return value
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENOMEM the array allocation failed
|
|
|
|
*/
|
1999-01-16 17:44:09 +00:00
|
|
|
int
|
|
|
|
device_get_children(device_t dev, device_t **devlistp, int *devcountp)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
int count;
|
|
|
|
device_t child;
|
|
|
|
device_t *list;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
|
|
|
count++;
|
|
|
|
}
|
2011-10-09 21:21:37 +00:00
|
|
|
if (count == 0) {
|
|
|
|
*devlistp = NULL;
|
|
|
|
*devcountp = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
1999-01-16 17:44:09 +00:00
|
|
|
|
2018-01-21 15:42:36 +00:00
|
|
|
list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!list)
|
|
|
|
return (ENOMEM);
|
1999-01-16 17:44:09 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
count = 0;
|
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
|
|
|
list[count] = child;
|
|
|
|
count++;
|
|
|
|
}
|
1999-01-16 17:44:09 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
*devlistp = list;
|
|
|
|
*devcountp = count;
|
1999-01-16 17:44:09 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1999-01-16 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the current driver for the device or @c NULL if there
|
|
|
|
* is no driver currently attached
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
driver_t *
|
|
|
|
device_get_driver(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->driver);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the current devclass for the device or @c NULL if
|
|
|
|
* there is none.
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
devclass_t
|
|
|
|
device_get_devclass(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->devclass);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the name of the device's devclass or @c NULL if there
|
|
|
|
* is none.
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
const char *
|
|
|
|
device_get_name(device_t dev)
|
|
|
|
{
|
2003-03-13 06:29:44 +00:00
|
|
|
if (dev != NULL && dev->devclass)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (devclass_get_name(dev->devclass));
|
|
|
|
return (NULL);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return a string containing the device's devclass name
|
|
|
|
* followed by an ascii representation of the device's unit number
|
|
|
|
* (e.g. @c "foo2").
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
const char *
|
|
|
|
device_get_nameunit(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->nameunit);
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the device's unit number.
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_get_unit(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->unit);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the device's description string
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
const char *
|
|
|
|
device_get_desc(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->desc);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the device's flags
|
|
|
|
*/
|
2010-06-21 09:55:56 +00:00
|
|
|
uint32_t
|
1999-09-07 08:42:49 +00:00
|
|
|
device_get_flags(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->devflags);
|
1999-09-07 08:42:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-25 12:06:26 +00:00
|
|
|
struct sysctl_ctx_list *
|
|
|
|
device_get_sysctl_ctx(device_t dev)
|
|
|
|
{
|
|
|
|
return (&dev->sysctl_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sysctl_oid *
|
|
|
|
device_get_sysctl_tree(device_t dev)
|
|
|
|
{
|
|
|
|
return (dev->sysctl_tree);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Print the name of the device followed by a colon and a space
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
1999-07-24 09:34:12 +00:00
|
|
|
int
|
1998-11-14 21:58:51 +00:00
|
|
|
device_print_prettyname(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
const char *name = device_get_name(dev);
|
1998-11-14 21:58:51 +00:00
|
|
|
|
2009-02-03 00:10:21 +00:00
|
|
|
if (name == NULL)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (printf("unknown: "));
|
|
|
|
return (printf("%s%d: ", name, device_get_unit(dev)));
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Print the name of the device followed by a colon, a space
|
|
|
|
* and the result of calling vprintf() with the value of @p fmt and
|
|
|
|
* the following arguments.
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
1999-07-24 09:34:12 +00:00
|
|
|
int
|
1999-01-16 17:44:09 +00:00
|
|
|
device_printf(device_t dev, const char * fmt, ...)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
va_list ap;
|
|
|
|
int retval;
|
1999-01-16 17:44:09 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
retval = device_print_prettyname(dev);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
retval += vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return (retval);
|
1999-01-16 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
static void
|
|
|
|
device_set_desc_internal(device_t dev, const char* desc, int copy)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->desc && (dev->flags & DF_DESCMALLOCED)) {
|
|
|
|
free(dev->desc, M_BUS);
|
|
|
|
dev->flags &= ~DF_DESCMALLOCED;
|
|
|
|
dev->desc = NULL;
|
|
|
|
}
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (copy && desc) {
|
|
|
|
dev->desc = malloc(strlen(desc) + 1, M_BUS, M_NOWAIT);
|
|
|
|
if (dev->desc) {
|
|
|
|
strcpy(dev->desc, desc);
|
|
|
|
dev->flags |= DF_DESCMALLOCED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Avoid a -Wcast-qual warning */
|
|
|
|
dev->desc = (char *)(uintptr_t) desc;
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the device's description
|
|
|
|
*
|
|
|
|
* The value of @c desc should be a string constant that will not
|
|
|
|
* change (at least until the description is changed in a subsequent
|
|
|
|
* call to device_set_desc() or device_set_desc_copy()).
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
|
|
|
device_set_desc(device_t dev, const char* desc)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_set_desc_internal(dev, desc, FALSE);
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the device's description
|
|
|
|
*
|
|
|
|
* The string pointed to by @c desc is copied. Use this function if
|
|
|
|
* the device description is generated, (e.g. with sprintf()).
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
void
|
|
|
|
device_set_desc_copy(device_t dev, const char* desc)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_set_desc_internal(dev, desc, TRUE);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the device's flags
|
|
|
|
*/
|
1999-09-07 08:42:49 +00:00
|
|
|
void
|
2010-06-21 09:55:56 +00:00
|
|
|
device_set_flags(device_t dev, uint32_t flags)
|
1999-09-07 08:42:49 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->devflags = flags;
|
1999-09-07 08:42:49 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the device's softc field
|
|
|
|
*
|
|
|
|
* The softc is allocated and zeroed when a driver is attached, based
|
|
|
|
* on the size field of the driver.
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void *
|
|
|
|
device_get_softc(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->softc);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the device's softc field
|
|
|
|
*
|
|
|
|
* Most drivers do not need to use this since the softc is allocated
|
|
|
|
* automatically when the driver is attached.
|
|
|
|
*/
|
2000-07-03 13:06:29 +00:00
|
|
|
void
|
|
|
|
device_set_softc(device_t dev, void *softc)
|
|
|
|
{
|
2012-08-15 15:42:57 +00:00
|
|
|
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC))
|
|
|
|
free(dev->softc, M_BUS_SC);
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->softc = softc;
|
|
|
|
if (dev->softc)
|
|
|
|
dev->flags |= DF_EXTERNALSOFTC;
|
|
|
|
else
|
|
|
|
dev->flags &= ~DF_EXTERNALSOFTC;
|
2000-07-03 13:06:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 15:42:57 +00:00
|
|
|
/**
|
|
|
|
* @brief Free claimed softc
|
|
|
|
*
|
|
|
|
* Most drivers do not need to use this since the softc is freed
|
|
|
|
* automatically when the driver is detached.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
device_free_softc(void *softc)
|
|
|
|
{
|
|
|
|
free(softc, M_BUS_SC);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Claim softc
|
|
|
|
*
|
|
|
|
* This function can be used to let the driver free the automatically
|
|
|
|
* allocated softc using "device_free_softc()". This function is
|
|
|
|
* useful when the driver is refcounting the softc and the softc
|
|
|
|
* cannot be freed when the "device_detach" method is called.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
device_claim_softc(device_t dev)
|
|
|
|
{
|
|
|
|
if (dev->softc)
|
|
|
|
dev->flags |= DF_EXTERNALSOFTC;
|
|
|
|
else
|
|
|
|
dev->flags &= ~DF_EXTERNALSOFTC;
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Get the device's ivars field
|
|
|
|
*
|
|
|
|
* The ivars field is used by the parent device to store per-device
|
|
|
|
* state (e.g. the physical location of the device or a list of
|
|
|
|
* resources).
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void *
|
|
|
|
device_get_ivars(device_t dev)
|
|
|
|
{
|
2002-10-15 18:56:13 +00:00
|
|
|
|
|
|
|
KASSERT(dev != NULL, ("device_get_ivars(NULL, ...)"));
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->ivars);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the device's ivars field
|
|
|
|
*/
|
1999-12-03 08:41:24 +00:00
|
|
|
void
|
|
|
|
device_set_ivars(device_t dev, void * ivars)
|
|
|
|
{
|
|
|
|
|
2002-10-15 18:56:13 +00:00
|
|
|
KASSERT(dev != NULL, ("device_set_ivars(NULL, ...)"));
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->ivars = ivars;
|
1999-12-03 08:41:24 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return the device's state
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
device_state_t
|
|
|
|
device_get_state(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (dev->state);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the DF_ENABLED flag for the device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
|
|
|
device_enable(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->flags |= DF_ENABLED;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Clear the DF_ENABLED flag for the device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
|
|
|
device_disable(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->flags &= ~DF_ENABLED;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Increment the busy counter for the device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
|
|
|
device_busy(device_t dev)
|
|
|
|
{
|
2012-04-11 20:57:41 +00:00
|
|
|
if (dev->state < DS_ATTACHING)
|
2001-01-05 07:29:54 +00:00
|
|
|
panic("device_busy: called for unattached device");
|
|
|
|
if (dev->busy == 0 && dev->parent)
|
|
|
|
device_busy(dev->parent);
|
|
|
|
dev->busy++;
|
2012-04-11 20:57:41 +00:00
|
|
|
if (dev->state == DS_ATTACHED)
|
|
|
|
dev->state = DS_BUSY;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Decrement the busy counter for the device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
|
|
|
device_unbusy(device_t dev)
|
|
|
|
{
|
2012-04-11 20:57:41 +00:00
|
|
|
if (dev->busy != 0 && dev->state != DS_BUSY &&
|
|
|
|
dev->state != DS_ATTACHING)
|
2004-12-05 20:58:56 +00:00
|
|
|
panic("device_unbusy: called for non-busy device %s",
|
|
|
|
device_get_nameunit(dev));
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->busy--;
|
|
|
|
if (dev->busy == 0) {
|
|
|
|
if (dev->parent)
|
|
|
|
device_unbusy(dev->parent);
|
2012-04-11 20:57:41 +00:00
|
|
|
if (dev->state == DS_BUSY)
|
|
|
|
dev->state = DS_ATTACHED;
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the DF_QUIET flag for the device
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
void
|
|
|
|
device_quiet(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->flags |= DF_QUIET;
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 21:09:08 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the DF_QUIET_CHILDREN flag for the device
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
device_quiet_children(device_t dev)
|
|
|
|
{
|
|
|
|
dev->flags |= DF_QUIET_CHILDREN;
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Clear the DF_QUIET flag for the device
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
void
|
|
|
|
device_verbose(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->flags &= ~DF_QUIET;
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 21:09:08 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the DF_QUIET_CHIDLREN flag is set on the device
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
device_has_quiet_children(device_t dev)
|
|
|
|
{
|
|
|
|
return ((dev->flags & DF_QUIET_CHILDREN) != 0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the DF_QUIET flag is set on the device
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
int
|
|
|
|
device_is_quiet(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return ((dev->flags & DF_QUIET) != 0);
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the DF_ENABLED flag is set on the device
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_is_enabled(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return ((dev->flags & DF_ENABLED) != 0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the device was successfully probed
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_is_alive(device_t dev)
|
|
|
|
{
|
2004-06-28 03:40:23 +00:00
|
|
|
return (dev->state >= DS_ALIVE);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the device currently has a driver
|
|
|
|
* attached to it
|
|
|
|
*/
|
2003-04-21 18:19:08 +00:00
|
|
|
int
|
|
|
|
device_is_attached(device_t dev)
|
|
|
|
{
|
2004-06-28 03:40:23 +00:00
|
|
|
return (dev->state >= DS_ATTACHED);
|
2003-04-21 18:19:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-06 16:09:01 +00:00
|
|
|
/**
|
|
|
|
* @brief Return non-zero if the device is currently suspended.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
device_is_suspended(device_t dev)
|
|
|
|
{
|
|
|
|
return ((dev->flags & DF_SUSPENDED) != 0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the devclass of a device
|
|
|
|
* @see devclass_add_device().
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_set_devclass(device_t dev, const char *classname)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc;
|
2004-10-14 17:14:56 +00:00
|
|
|
int error;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!classname) {
|
|
|
|
if (dev->devclass)
|
|
|
|
devclass_delete_device(dev->devclass, dev);
|
|
|
|
return (0);
|
|
|
|
}
|
1999-12-24 16:21:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->devclass) {
|
|
|
|
printf("device_set_devclass: device class already set\n");
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2007-02-26 19:28:18 +00:00
|
|
|
dc = devclass_find_internal(classname, NULL, TRUE);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!dc)
|
|
|
|
return (ENOMEM);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
error = devclass_add_device(dc, dev);
|
2000-11-09 10:21:23 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (error);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 23:27:13 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the devclass of a device and mark the devclass fixed.
|
|
|
|
* @see device_set_devclass()
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
device_set_devclass_fixed(device_t dev, const char *classname)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (classname == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
error = device_set_devclass(dev, classname);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
dev->flags |= DF_FIXEDCLASS;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the driver of a device
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval EBUSY the device already has a driver attached
|
|
|
|
* @retval ENOMEM a memory allocation failure occurred
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_set_driver(device_t dev, driver_t *driver)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->state >= DS_ATTACHED)
|
|
|
|
return (EBUSY);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->driver == driver)
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2012-08-15 15:42:57 +00:00
|
|
|
if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
|
|
|
|
free(dev->softc, M_BUS_SC);
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->softc = NULL;
|
|
|
|
}
|
2012-02-27 16:08:18 +00:00
|
|
|
device_set_desc(dev, NULL);
|
2007-02-26 19:28:18 +00:00
|
|
|
kobj_delete((kobj_t) dev, NULL);
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->driver = driver;
|
|
|
|
if (driver) {
|
|
|
|
kobj_init((kobj_t) dev, (kobj_class_t) driver);
|
2002-04-23 15:48:23 +00:00
|
|
|
if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) {
|
2003-10-14 06:22:07 +00:00
|
|
|
dev->softc = malloc(driver->size, M_BUS_SC,
|
2001-01-05 07:29:54 +00:00
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (!dev->softc) {
|
2007-02-26 19:28:18 +00:00
|
|
|
kobj_delete((kobj_t) dev, NULL);
|
2001-01-05 07:29:54 +00:00
|
|
|
kobj_init((kobj_t) dev, &null_class);
|
|
|
|
dev->driver = NULL;
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kobj_init((kobj_t) dev, &null_class);
|
|
|
|
}
|
2000-11-09 10:21:23 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
2008-06-20 16:58:15 +00:00
|
|
|
* @brief Probe a device, and return this status.
|
2004-07-18 16:30:31 +00:00
|
|
|
*
|
|
|
|
* This function is the core of the device autoconfiguration
|
|
|
|
* system. Its purpose is to select a suitable driver for a device and
|
|
|
|
* then call that driver to initialise the hardware appropriately. The
|
|
|
|
* driver is selected by calling the DEVICE_PROBE() method of a set of
|
|
|
|
* candidate drivers and then choosing the driver which returned the
|
|
|
|
* best value. This driver is then attached to the device using
|
|
|
|
* device_attach().
|
|
|
|
*
|
|
|
|
* The set of suitable drivers is taken from the list of drivers in
|
|
|
|
* the parent device's devclass. If the device was originally created
|
|
|
|
* with a specific class name (see device_add_child()), only drivers
|
|
|
|
* with that name are probed, otherwise all drivers in the devclass
|
|
|
|
* are probed. If no drivers return successful probe values in the
|
|
|
|
* parent devclass, the search continues in the parent of that
|
|
|
|
* devclass (see devclass_get_parent()) if any.
|
|
|
|
*
|
|
|
|
* @param dev the device to initialise
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENXIO no driver was found
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
* @retval non-zero some other unix error code
|
2008-06-20 16:58:15 +00:00
|
|
|
* @retval -1 Device already attached
|
2004-07-18 16:30:31 +00:00
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
2008-06-20 16:58:15 +00:00
|
|
|
device_probe(device_t dev)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2004-05-25 12:06:26 +00:00
|
|
|
int error;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2009-08-20 19:17:53 +00:00
|
|
|
GIANT_REQUIRED;
|
2004-12-05 07:55:30 +00:00
|
|
|
|
2004-08-29 18:25:21 +00:00
|
|
|
if (dev->state >= DS_ALIVE && (dev->flags & DF_REBID) == 0)
|
2008-06-20 16:58:15 +00:00
|
|
|
return (-1);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2004-05-25 12:06:26 +00:00
|
|
|
if (!(dev->flags & DF_ENABLED)) {
|
2004-11-03 09:06:45 +00:00
|
|
|
if (bootverbose && device_get_name(dev) != NULL) {
|
2001-01-05 07:29:54 +00:00
|
|
|
device_print_prettyname(dev);
|
|
|
|
printf("not probed (disabled)\n");
|
|
|
|
}
|
2008-06-20 16:58:15 +00:00
|
|
|
return (-1);
|
2004-05-25 12:06:26 +00:00
|
|
|
}
|
2015-01-05 20:50:44 +00:00
|
|
|
if ((error = device_probe_child(dev->parent, dev)) != 0) {
|
2009-06-09 14:26:23 +00:00
|
|
|
if (bus_current_pass == BUS_PASS_DEFAULT &&
|
|
|
|
!(dev->flags & DF_DONENOMATCH)) {
|
2004-05-25 12:06:26 +00:00
|
|
|
BUS_PROBE_NOMATCH(dev->parent, dev);
|
|
|
|
devnomatch(dev);
|
|
|
|
dev->flags |= DF_DONENOMATCH;
|
|
|
|
}
|
|
|
|
return (error);
|
2000-02-15 19:23:34 +00:00
|
|
|
}
|
2008-06-20 16:58:15 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2008-06-20 16:58:15 +00:00
|
|
|
/**
|
|
|
|
* @brief Probe a device and attach a driver if possible
|
|
|
|
*
|
|
|
|
* calls device_probe() and attaches if that was successful.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
device_probe_and_attach(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2009-08-20 19:17:53 +00:00
|
|
|
GIANT_REQUIRED;
|
2008-06-20 16:58:15 +00:00
|
|
|
|
|
|
|
error = device_probe(dev);
|
|
|
|
if (error == -1)
|
|
|
|
return (0);
|
|
|
|
else if (error != 0)
|
|
|
|
return (error);
|
2013-07-15 01:32:55 +00:00
|
|
|
|
|
|
|
CURVNET_SET_QUIET(vnet0);
|
|
|
|
error = device_attach(dev);
|
|
|
|
CURVNET_RESTORE();
|
|
|
|
return error;
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Attach a device driver to a device
|
|
|
|
*
|
|
|
|
* This function is a wrapper around the DEVICE_ATTACH() driver
|
|
|
|
* method. In addition to calling DEVICE_ATTACH(), it initialises the
|
|
|
|
* device's sysctl tree, optionally prints a description of the device
|
|
|
|
* and queues a notification event for user-based device management
|
|
|
|
* services.
|
|
|
|
*
|
|
|
|
* Normally this function is only called internally from
|
|
|
|
* device_probe_and_attach().
|
|
|
|
*
|
|
|
|
* @param dev the device to initialise
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENXIO no driver was found
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
* @retval non-zero some other unix error code
|
|
|
|
*/
|
2004-05-25 12:06:26 +00:00
|
|
|
int
|
|
|
|
device_attach(device_t dev)
|
|
|
|
{
|
2013-10-08 11:05:26 +00:00
|
|
|
uint64_t attachtime;
|
2018-08-26 12:51:46 +00:00
|
|
|
uint16_t attachentropy;
|
2004-05-25 12:06:26 +00:00
|
|
|
int error;
|
|
|
|
|
2012-10-02 03:33:41 +00:00
|
|
|
if (resource_disabled(dev->driver->name, dev->unit)) {
|
|
|
|
device_disable(dev);
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "disabled via hints entry\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2004-05-25 12:06:26 +00:00
|
|
|
device_sysctl_init(dev);
|
|
|
|
if (!device_is_quiet(dev))
|
|
|
|
device_print_child(dev->parent, dev);
|
2013-10-08 11:05:26 +00:00
|
|
|
attachtime = get_cyclecount();
|
2012-04-11 20:57:41 +00:00
|
|
|
dev->state = DS_ATTACHING;
|
2004-05-25 12:06:26 +00:00
|
|
|
if ((error = DEVICE_ATTACH(dev)) != 0) {
|
|
|
|
printf("device_attach: %s%d attach returned %d\n",
|
|
|
|
dev->driver->name, dev->unit, error);
|
2012-02-28 19:16:02 +00:00
|
|
|
if (!(dev->flags & DF_FIXEDCLASS))
|
|
|
|
devclass_delete_device(dev->devclass, dev);
|
2011-12-02 21:19:14 +00:00
|
|
|
(void)device_set_driver(dev, NULL);
|
2004-05-25 12:06:26 +00:00
|
|
|
device_sysctl_fini(dev);
|
2012-04-11 20:57:41 +00:00
|
|
|
KASSERT(dev->busy == 0, ("attach failed but busy"));
|
2004-05-25 12:06:26 +00:00
|
|
|
dev->state = DS_NOTPRESENT;
|
|
|
|
return (error);
|
|
|
|
}
|
2018-08-23 05:06:16 +00:00
|
|
|
dev->flags |= DF_ATTACHED_ONCE;
|
2018-08-26 12:51:46 +00:00
|
|
|
/* We only need the low bits of this time, but ranges from tens to thousands
|
|
|
|
* have been seen, so keep 2 bytes' worth.
|
2013-10-08 11:05:26 +00:00
|
|
|
*/
|
2018-08-26 12:51:46 +00:00
|
|
|
attachentropy = (uint16_t)(get_cyclecount() - attachtime);
|
|
|
|
random_harvest_direct(&attachentropy, sizeof(attachentropy), RANDOM_ATTACH);
|
2007-11-30 21:30:14 +00:00
|
|
|
device_sysctl_update(dev);
|
2012-04-11 20:57:41 +00:00
|
|
|
if (dev->busy)
|
|
|
|
dev->state = DS_BUSY;
|
|
|
|
else
|
|
|
|
dev->state = DS_ATTACHED;
|
2010-06-07 18:47:53 +00:00
|
|
|
dev->flags &= ~DF_DONENOMATCH;
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(device_attach, dev);
|
2004-05-25 12:06:26 +00:00
|
|
|
devadded(dev);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Detach a driver from a device
|
|
|
|
*
|
|
|
|
* This function is a wrapper around the DEVICE_DETACH() driver
|
|
|
|
* method. If the call to DEVICE_DETACH() succeeds, it calls
|
|
|
|
* BUS_CHILD_DETACHED() for the parent of @p dev, queues a
|
|
|
|
* notification event for user-based device management services and
|
|
|
|
* cleans up the device's sysctl tree.
|
|
|
|
*
|
|
|
|
* @param dev the device to un-initialise
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENXIO no driver was found
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
* @retval non-zero some other unix error code
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_detach(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
int error;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2009-08-20 19:17:53 +00:00
|
|
|
GIANT_REQUIRED;
|
2004-12-05 07:55:30 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("%s", DEVICENAME(dev)));
|
|
|
|
if (dev->state == DS_BUSY)
|
|
|
|
return (EBUSY);
|
|
|
|
if (dev->state != DS_ATTACHED)
|
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(device_detach, dev, EVHDEV_DETACH_BEGIN);
|
2017-10-08 17:33:49 +00:00
|
|
|
if ((error = DEVICE_DETACH(dev)) != 0) {
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(device_detach, dev,
|
|
|
|
EVHDEV_DETACH_FAILED);
|
2001-01-05 07:29:54 +00:00
|
|
|
return (error);
|
2017-10-08 17:33:49 +00:00
|
|
|
} else {
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(device_detach, dev,
|
|
|
|
EVHDEV_DETACH_COMPLETE);
|
2017-10-08 17:33:49 +00:00
|
|
|
}
|
2002-10-07 23:17:44 +00:00
|
|
|
devremoved(dev);
|
2008-11-13 21:46:19 +00:00
|
|
|
if (!device_is_quiet(dev))
|
|
|
|
device_printf(dev, "detached\n");
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->parent)
|
|
|
|
BUS_CHILD_DETACHED(dev->parent, dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!(dev->flags & DF_FIXEDCLASS))
|
|
|
|
devclass_delete_device(dev->devclass, dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2016-09-12 18:06:42 +00:00
|
|
|
device_verbose(dev);
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->state = DS_NOTPRESENT;
|
2011-12-02 21:19:14 +00:00
|
|
|
(void)device_set_driver(dev, NULL);
|
2004-05-25 12:06:26 +00:00
|
|
|
device_sysctl_fini(dev);
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 20:47:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Tells a driver to quiesce itself.
|
|
|
|
*
|
|
|
|
* This function is a wrapper around the DEVICE_QUIESCE() driver
|
|
|
|
* method. If the call to DEVICE_QUIESCE() succeeds.
|
|
|
|
*
|
|
|
|
* @param dev the device to quiesce
|
|
|
|
*
|
|
|
|
* @retval 0 success
|
|
|
|
* @retval ENXIO no driver was found
|
|
|
|
* @retval ENOMEM memory allocation failure
|
|
|
|
* @retval non-zero some other unix error code
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
device_quiesce(device_t dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
PDEBUG(("%s", DEVICENAME(dev)));
|
|
|
|
if (dev->state == DS_BUSY)
|
|
|
|
return (EBUSY);
|
|
|
|
if (dev->state != DS_ATTACHED)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (DEVICE_QUIESCE(dev));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Notify a device of system shutdown
|
|
|
|
*
|
|
|
|
* This function calls the DEVICE_SHUTDOWN() driver method if the
|
|
|
|
* device currently has an attached driver.
|
|
|
|
*
|
|
|
|
* @returns the value returned by DEVICE_SHUTDOWN()
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
|
|
|
device_shutdown(device_t dev)
|
|
|
|
{
|
2009-09-13 15:08:19 +00:00
|
|
|
if (dev->state < DS_ATTACHED)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
|
|
|
return (DEVICE_SHUTDOWN(dev));
|
1998-06-14 13:46:10 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Set the unit number of a device
|
|
|
|
*
|
|
|
|
* This function can be used to override the unit number used for a
|
|
|
|
* device (e.g. to wire a device to a pre-configured unit number).
|
|
|
|
*/
|
2000-04-01 06:06:37 +00:00
|
|
|
int
|
|
|
|
device_set_unit(device_t dev, int unit)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
dc = device_get_devclass(dev);
|
|
|
|
if (unit < dc->maxunit && dc->devices[unit])
|
|
|
|
return (EBUSY);
|
|
|
|
err = devclass_delete_device(dc, dev);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
dev->unit = unit;
|
|
|
|
err = devclass_add_device(dc, dev);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
1999-03-29 08:54:20 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_data_generation_update();
|
|
|
|
return (0);
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
1999-04-16 21:22:55 +00:00
|
|
|
/*======================================*/
|
1998-06-14 13:46:10 +00:00
|
|
|
/*
|
|
|
|
* Some useful method implementations to make life easier for bus drivers.
|
|
|
|
*/
|
1999-05-14 11:22:47 +00:00
|
|
|
|
2016-05-20 17:57:47 +00:00
|
|
|
void
|
|
|
|
resource_init_map_request_impl(struct resource_map_request *args, size_t sz)
|
|
|
|
{
|
|
|
|
|
|
|
|
bzero(args, sz);
|
|
|
|
args->size = sz;
|
|
|
|
args->memattr = VM_MEMATTR_UNCACHEABLE;
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Initialise a resource list.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to initialise
|
|
|
|
*/
|
2001-06-12 09:40:04 +00:00
|
|
|
void
|
1999-05-22 14:57:15 +00:00
|
|
|
resource_list_init(struct resource_list *rl)
|
|
|
|
{
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_INIT(rl);
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Reclaim memory used by a resource list.
|
|
|
|
*
|
|
|
|
* This function frees the memory for all resource entries on the list
|
|
|
|
* (if any).
|
|
|
|
*
|
2015-01-05 20:50:44 +00:00
|
|
|
* @param rl the resource list to free
|
2004-07-18 16:30:31 +00:00
|
|
|
*/
|
1999-05-22 14:57:15 +00:00
|
|
|
void
|
|
|
|
resource_list_free(struct resource_list *rl)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource_list_entry *rle;
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2005-03-18 05:19:50 +00:00
|
|
|
while ((rle = STAILQ_FIRST(rl)) != NULL) {
|
2001-01-05 07:29:54 +00:00
|
|
|
if (rle->res)
|
|
|
|
panic("resource_list_free: resource entry is busy");
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_REMOVE_HEAD(rl, link);
|
2001-01-05 07:29:54 +00:00
|
|
|
free(rle, M_BUS);
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Add a resource entry.
|
|
|
|
*
|
|
|
|
* This function adds a resource entry using the given @p type, @p
|
|
|
|
* start, @p end and @p count values. A rid value is chosen by
|
|
|
|
* searching sequentially for the first unused rid starting at zero.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to edit
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param start the start address of the resource
|
|
|
|
* @param end the end address of the resource
|
|
|
|
* @param count XXX end-start+1
|
|
|
|
*/
|
2002-03-29 06:42:54 +00:00
|
|
|
int
|
2016-01-27 02:23:54 +00:00
|
|
|
resource_list_add_next(struct resource_list *rl, int type, rman_res_t start,
|
|
|
|
rman_res_t end, rman_res_t count)
|
2002-03-29 06:42:54 +00:00
|
|
|
{
|
2002-09-12 13:45:38 +00:00
|
|
|
int rid;
|
2002-03-29 06:42:54 +00:00
|
|
|
|
|
|
|
rid = 0;
|
2002-09-12 13:45:38 +00:00
|
|
|
while (resource_list_find(rl, type, rid) != NULL)
|
|
|
|
rid++;
|
2002-03-29 06:42:54 +00:00
|
|
|
resource_list_add(rl, type, rid, start, end, count);
|
|
|
|
return (rid);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Add or modify a resource entry.
|
|
|
|
*
|
|
|
|
* If an existing entry exists with the same type and rid, it will be
|
|
|
|
* modified using the given values of @p start, @p end and @p
|
|
|
|
* count. If no entry exists, a new one will be created using the
|
2005-04-12 04:22:17 +00:00
|
|
|
* given values. The resource list entry that matches is then returned.
|
2004-07-18 16:30:31 +00:00
|
|
|
*
|
|
|
|
* @param rl the resource list to edit
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param rid the resource identifier
|
|
|
|
* @param start the start address of the resource
|
|
|
|
* @param end the end address of the resource
|
|
|
|
* @param count XXX end-start+1
|
|
|
|
*/
|
2005-04-12 04:22:17 +00:00
|
|
|
struct resource_list_entry *
|
2001-01-05 07:29:54 +00:00
|
|
|
resource_list_add(struct resource_list *rl, int type, int rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start, rman_res_t end, rman_res_t count)
|
1999-05-22 14:57:15 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource_list_entry *rle;
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (!rle) {
|
|
|
|
rle = malloc(sizeof(struct resource_list_entry), M_BUS,
|
|
|
|
M_NOWAIT);
|
|
|
|
if (!rle)
|
|
|
|
panic("resource_list_add: can't record entry");
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_INSERT_TAIL(rl, rle, link);
|
2001-01-05 07:29:54 +00:00
|
|
|
rle->type = type;
|
|
|
|
rle->rid = rid;
|
|
|
|
rle->res = NULL;
|
2009-12-09 21:52:53 +00:00
|
|
|
rle->flags = 0;
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (rle->res)
|
|
|
|
panic("resource_list_add: resource entry is busy");
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle->start = start;
|
|
|
|
rle->end = end;
|
|
|
|
rle->count = count;
|
2005-04-12 04:22:17 +00:00
|
|
|
return (rle);
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 21:52:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Determine if a resource entry is busy.
|
|
|
|
*
|
|
|
|
* Returns true if a resource entry is busy meaning that it has an
|
|
|
|
* associated resource that is not an unallocated "reserved" resource.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to search
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param rid the resource identifier
|
|
|
|
*
|
|
|
|
* @returns Non-zero if the entry is busy, zero otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
resource_list_busy(struct resource_list *rl, int type, int rid)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (rle == NULL || rle->res == NULL)
|
|
|
|
return (0);
|
2009-12-30 19:44:31 +00:00
|
|
|
if ((rle->flags & (RLE_RESERVED | RLE_ALLOCATED)) == RLE_RESERVED) {
|
|
|
|
KASSERT(!(rman_get_flags(rle->res) & RF_ACTIVE),
|
|
|
|
("reserved resource is active"));
|
2009-12-09 21:52:53 +00:00
|
|
|
return (0);
|
2009-12-30 19:44:31 +00:00
|
|
|
}
|
2009-12-09 21:52:53 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2010-11-17 22:28:04 +00:00
|
|
|
/**
|
|
|
|
* @brief Determine if a resource entry is reserved.
|
|
|
|
*
|
|
|
|
* Returns true if a resource entry is reserved meaning that it has an
|
|
|
|
* associated "reserved" resource. The resource can either be
|
|
|
|
* allocated or unallocated.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to search
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param rid the resource identifier
|
|
|
|
*
|
|
|
|
* @returns Non-zero if the entry is reserved, zero otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
resource_list_reserved(struct resource_list *rl, int type, int rid)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (rle != NULL && rle->flags & RLE_RESERVED)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Find a resource entry by type and rid.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to search
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param rid the resource identifier
|
|
|
|
*
|
|
|
|
* @returns the resource entry pointer or NULL if there is no such
|
|
|
|
* entry.
|
|
|
|
*/
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource_list_entry *
|
|
|
|
resource_list_find(struct resource_list *rl, int type, int rid)
|
1999-05-22 14:57:15 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource_list_entry *rle;
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_FOREACH(rle, rl, link) {
|
2001-01-05 07:29:54 +00:00
|
|
|
if (rle->type == type && rle->rid == rid)
|
|
|
|
return (rle);
|
|
|
|
}
|
|
|
|
return (NULL);
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Delete a resource entry.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to edit
|
|
|
|
* @param type the resource entry type (e.g. SYS_RES_MEMORY)
|
|
|
|
* @param rid the resource identifier
|
|
|
|
*/
|
1999-05-22 14:57:15 +00:00
|
|
|
void
|
2001-01-05 07:29:54 +00:00
|
|
|
resource_list_delete(struct resource_list *rl, int type, int rid)
|
1999-05-22 14:57:15 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource_list_entry *rle = resource_list_find(rl, type, rid);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (rle) {
|
|
|
|
if (rle->res != NULL)
|
|
|
|
panic("resource_list_delete: resource has not been released");
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_REMOVE(rl, rle, resource_list_entry, link);
|
2001-01-05 07:29:54 +00:00
|
|
|
free(rle, M_BUS);
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 21:52:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Allocate a reserved resource
|
|
|
|
*
|
2017-01-15 17:54:01 +00:00
|
|
|
* This can be used by buses to force the allocation of resources
|
2009-12-09 21:52:53 +00:00
|
|
|
* that are always active in the system even if they are not allocated
|
|
|
|
* by a driver (e.g. PCI BARs). This function is usually called when
|
|
|
|
* adding a new child to the bus. The resource is allocated from the
|
|
|
|
* parent bus when it is reserved. The resource list entry is marked
|
|
|
|
* with RLE_RESERVED to note that it is a reserved resource.
|
|
|
|
*
|
|
|
|
* Subsequent attempts to allocate the resource with
|
|
|
|
* resource_list_alloc() will succeed the first time and will set
|
|
|
|
* RLE_ALLOCATED to note that it has been allocated. When a reserved
|
|
|
|
* resource that has been allocated is released with
|
|
|
|
* resource_list_release() the resource RLE_ALLOCATED is cleared, but
|
|
|
|
* the actual resource remains allocated. The resource can be released to
|
|
|
|
* the parent bus by calling resource_list_unreserve().
|
|
|
|
*
|
|
|
|
* @param rl the resource list to allocate from
|
|
|
|
* @param bus the parent device of @p child
|
|
|
|
* @param child the device for which the resource is being reserved
|
|
|
|
* @param type the type of resource to allocate
|
|
|
|
* @param rid a pointer to the resource identifier
|
|
|
|
* @param start hint at the start of the resource range - pass
|
2016-03-03 05:07:35 +00:00
|
|
|
* @c 0 for any start address
|
2009-12-09 21:52:53 +00:00
|
|
|
* @param end hint at the end of the resource range - pass
|
2016-03-03 05:07:35 +00:00
|
|
|
* @c ~0 for any end address
|
2009-12-09 21:52:53 +00:00
|
|
|
* @param count hint at the size of range required - pass @c 1
|
|
|
|
* for any size
|
|
|
|
* @param flags any extra flags to control the resource
|
|
|
|
* allocation - see @c RF_XXX flags in
|
|
|
|
* <sys/rman.h> for details
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2009-12-09 21:52:53 +00:00
|
|
|
* @returns the resource which was allocated or @c NULL if no
|
|
|
|
* resource could be allocated
|
|
|
|
*/
|
|
|
|
struct resource *
|
|
|
|
resource_list_reserve(struct resource_list *rl, device_t bus, device_t child,
|
2016-01-27 02:23:54 +00:00
|
|
|
int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
|
2009-12-09 21:52:53 +00:00
|
|
|
{
|
|
|
|
struct resource_list_entry *rle = NULL;
|
|
|
|
int passthrough = (device_get_parent(child) != bus);
|
|
|
|
struct resource *r;
|
|
|
|
|
|
|
|
if (passthrough)
|
|
|
|
panic(
|
|
|
|
"resource_list_reserve() should only be called for direct children");
|
|
|
|
if (flags & RF_ACTIVE)
|
|
|
|
panic(
|
|
|
|
"resource_list_reserve() should only reserve inactive resources");
|
|
|
|
|
|
|
|
r = resource_list_alloc(rl, bus, child, type, rid, start, end, count,
|
|
|
|
flags);
|
|
|
|
if (r != NULL) {
|
|
|
|
rle = resource_list_find(rl, type, *rid);
|
|
|
|
rle->flags |= RLE_RESERVED;
|
|
|
|
}
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_ALLOC_RESOURCE()
|
|
|
|
*
|
|
|
|
* Implement BUS_ALLOC_RESOURCE() by looking up a resource from the list
|
|
|
|
* and passing the allocation up to the parent of @p bus. This assumes
|
|
|
|
* that the first entry of @c device_get_ivars(child) is a struct
|
|
|
|
* resource_list. This also handles 'passthrough' allocations where a
|
|
|
|
* child is a remote descendant of bus by passing the allocation up to
|
|
|
|
* the parent of bus.
|
|
|
|
*
|
|
|
|
* Typically, a bus driver would store a list of child resources
|
|
|
|
* somewhere in the child device's ivars (see device_get_ivars()) and
|
|
|
|
* its implementation of BUS_ALLOC_RESOURCE() would find that list and
|
|
|
|
* then call resource_list_alloc() to perform the allocation.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to allocate from
|
|
|
|
* @param bus the parent device of @p child
|
|
|
|
* @param child the device which is requesting an allocation
|
|
|
|
* @param type the type of resource to allocate
|
|
|
|
* @param rid a pointer to the resource identifier
|
|
|
|
* @param start hint at the start of the resource range - pass
|
2016-03-03 05:07:35 +00:00
|
|
|
* @c 0 for any start address
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param end hint at the end of the resource range - pass
|
2016-03-03 05:07:35 +00:00
|
|
|
* @c ~0 for any end address
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param count hint at the size of range required - pass @c 1
|
|
|
|
* for any size
|
|
|
|
* @param flags any extra flags to control the resource
|
|
|
|
* allocation - see @c RF_XXX flags in
|
|
|
|
* <sys/rman.h> for details
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the resource which was allocated or @c NULL if no
|
|
|
|
* resource could be allocated
|
|
|
|
*/
|
1999-05-22 14:57:15 +00:00
|
|
|
struct resource *
|
2001-01-05 07:29:54 +00:00
|
|
|
resource_list_alloc(struct resource_list *rl, device_t bus, device_t child,
|
2016-01-27 02:23:54 +00:00
|
|
|
int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
|
1999-05-22 14:57:15 +00:00
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
struct resource_list_entry *rle = NULL;
|
2001-01-05 07:29:54 +00:00
|
|
|
int passthrough = (device_get_parent(child) != bus);
|
2016-02-20 01:32:58 +00:00
|
|
|
int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (passthrough) {
|
|
|
|
return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
|
|
|
|
type, rid, start, end, count, flags));
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle = resource_list_find(rl, type, *rid);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!rle)
|
|
|
|
return (NULL); /* no resource of that type/rid */
|
2000-11-09 10:21:23 +00:00
|
|
|
|
2009-12-09 21:52:53 +00:00
|
|
|
if (rle->res) {
|
|
|
|
if (rle->flags & RLE_RESERVED) {
|
|
|
|
if (rle->flags & RLE_ALLOCATED)
|
|
|
|
return (NULL);
|
2009-12-30 22:37:28 +00:00
|
|
|
if ((flags & RF_ACTIVE) &&
|
2009-12-09 21:52:53 +00:00
|
|
|
bus_activate_resource(child, type, *rid,
|
|
|
|
rle->res) != 0)
|
|
|
|
return (NULL);
|
2009-12-30 22:37:28 +00:00
|
|
|
rle->flags |= RLE_ALLOCATED;
|
|
|
|
return (rle->res);
|
2009-12-09 21:52:53 +00:00
|
|
|
}
|
2014-09-26 18:37:49 +00:00
|
|
|
device_printf(bus,
|
|
|
|
"resource entry %#x type %d for child %s is busy\n", *rid,
|
|
|
|
type, device_get_nameunit(child));
|
|
|
|
return (NULL);
|
2009-12-09 21:52:53 +00:00
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (isdefault) {
|
|
|
|
start = rle->start;
|
2001-12-21 21:45:09 +00:00
|
|
|
count = ulmax(count, rle->count);
|
|
|
|
end = ulmax(rle->end, start + count - 1);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
|
|
|
|
type, rid, start, end, count, flags);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
/*
|
|
|
|
* Record the new range.
|
|
|
|
*/
|
|
|
|
if (rle->res) {
|
|
|
|
rle->start = rman_get_start(rle->res);
|
|
|
|
rle->end = rman_get_end(rle->res);
|
|
|
|
rle->count = count;
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (rle->res);
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_RELEASE_RESOURCE()
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* Implement BUS_RELEASE_RESOURCE() using a resource list. Normally
|
|
|
|
* used with resource_list_alloc().
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param rl the resource list which was allocated from
|
|
|
|
* @param bus the parent device of @p child
|
|
|
|
* @param child the device which is requesting a release
|
2009-12-09 21:52:53 +00:00
|
|
|
* @param type the type of resource to release
|
2004-07-18 16:30:31 +00:00
|
|
|
* @param rid the resource identifier
|
|
|
|
* @param res the resource to release
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @retval 0 success
|
|
|
|
* @retval non-zero a standard unix error code indicating what
|
|
|
|
* error condition prevented the operation
|
|
|
|
*/
|
1999-05-22 14:57:15 +00:00
|
|
|
int
|
2001-01-05 07:29:54 +00:00
|
|
|
resource_list_release(struct resource_list *rl, device_t bus, device_t child,
|
|
|
|
int type, int rid, struct resource *res)
|
1999-05-22 14:57:15 +00:00
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
struct resource_list_entry *rle = NULL;
|
2001-01-05 07:29:54 +00:00
|
|
|
int passthrough = (device_get_parent(child) != bus);
|
|
|
|
int error;
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (passthrough) {
|
|
|
|
return (BUS_RELEASE_RESOURCE(device_get_parent(bus), child,
|
|
|
|
type, rid, res));
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle = resource_list_find(rl, type, rid);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!rle)
|
|
|
|
panic("resource_list_release: can't find resource");
|
|
|
|
if (!rle->res)
|
|
|
|
panic("resource_list_release: resource entry is not busy");
|
2009-12-09 21:52:53 +00:00
|
|
|
if (rle->flags & RLE_RESERVED) {
|
|
|
|
if (rle->flags & RLE_ALLOCATED) {
|
|
|
|
if (rman_get_flags(res) & RF_ACTIVE) {
|
|
|
|
error = bus_deactivate_resource(child, type,
|
|
|
|
rid, res);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
rle->flags &= ~RLE_ALLOCATED;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
error = BUS_RELEASE_RESOURCE(device_get_parent(bus), child,
|
|
|
|
type, rid, res);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
1999-05-22 14:57:15 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
rle->res = NULL;
|
|
|
|
return (0);
|
1999-05-22 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 20:21:54 +00:00
|
|
|
/**
|
|
|
|
* @brief Release all active resources of a given type
|
|
|
|
*
|
|
|
|
* Release all active resources of a specified type. This is intended
|
|
|
|
* to be used to cleanup resources leaked by a driver after detach or
|
|
|
|
* a failed attach.
|
|
|
|
*
|
|
|
|
* @param rl the resource list which was allocated from
|
|
|
|
* @param bus the parent device of @p child
|
|
|
|
* @param child the device whose active resources are being released
|
|
|
|
* @param type the type of resources to release
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2013-06-27 20:21:54 +00:00
|
|
|
* @retval 0 success
|
|
|
|
* @retval EBUSY at least one resource was active
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
resource_list_release_active(struct resource_list *rl, device_t bus,
|
|
|
|
device_t child, int type)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
int error, retval;
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
STAILQ_FOREACH(rle, rl, link) {
|
|
|
|
if (rle->type != type)
|
|
|
|
continue;
|
|
|
|
if (rle->res == NULL)
|
|
|
|
continue;
|
|
|
|
if ((rle->flags & (RLE_RESERVED | RLE_ALLOCATED)) ==
|
|
|
|
RLE_RESERVED)
|
|
|
|
continue;
|
|
|
|
retval = EBUSY;
|
|
|
|
error = resource_list_release(rl, bus, child, type,
|
|
|
|
rman_get_rid(rle->res), rle->res);
|
|
|
|
if (error != 0)
|
|
|
|
device_printf(bus,
|
|
|
|
"Failed to release active resource: %d\n", error);
|
|
|
|
}
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-09 21:52:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Fully release a reserved resource
|
|
|
|
*
|
2013-01-23 14:37:05 +00:00
|
|
|
* Fully releases a resource reserved via resource_list_reserve().
|
2009-12-09 21:52:53 +00:00
|
|
|
*
|
|
|
|
* @param rl the resource list which was allocated from
|
|
|
|
* @param bus the parent device of @p child
|
|
|
|
* @param child the device whose reserved resource is being released
|
|
|
|
* @param type the type of resource to release
|
|
|
|
* @param rid the resource identifier
|
|
|
|
* @param res the resource to release
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2009-12-09 21:52:53 +00:00
|
|
|
* @retval 0 success
|
|
|
|
* @retval non-zero a standard unix error code indicating what
|
|
|
|
* error condition prevented the operation
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
resource_list_unreserve(struct resource_list *rl, device_t bus, device_t child,
|
|
|
|
int type, int rid)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle = NULL;
|
|
|
|
int passthrough = (device_get_parent(child) != bus);
|
|
|
|
|
|
|
|
if (passthrough)
|
|
|
|
panic(
|
|
|
|
"resource_list_unreserve() should only be called for direct children");
|
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
|
|
|
|
if (!rle)
|
|
|
|
panic("resource_list_unreserve: can't find resource");
|
|
|
|
if (!(rle->flags & RLE_RESERVED))
|
|
|
|
return (EINVAL);
|
|
|
|
if (rle->flags & RLE_ALLOCATED)
|
|
|
|
return (EBUSY);
|
|
|
|
rle->flags &= ~RLE_RESERVED;
|
|
|
|
return (resource_list_release(rl, bus, child, type, rid, rle->res));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Print a description of resources in a resource list
|
|
|
|
*
|
|
|
|
* Print all resources of a specified type, for use in BUS_PRINT_CHILD().
|
|
|
|
* The name is printed if at least one resource of the given type is available.
|
|
|
|
* The format is used to print resource start and end.
|
|
|
|
*
|
|
|
|
* @param rl the resource list to print
|
|
|
|
* @param name the name of @p type, e.g. @c "memory"
|
|
|
|
* @param type type type of resource entry to print
|
|
|
|
* @param format printf(9) format string to print resource
|
|
|
|
* start and end values
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
2001-12-21 21:45:09 +00:00
|
|
|
int
|
|
|
|
resource_list_print_type(struct resource_list *rl, const char *name, int type,
|
|
|
|
const char *format)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
int printed, retval;
|
|
|
|
|
|
|
|
printed = 0;
|
|
|
|
retval = 0;
|
|
|
|
/* Yes, this is kinda cheating */
|
2005-03-18 05:19:50 +00:00
|
|
|
STAILQ_FOREACH(rle, rl, link) {
|
2001-12-21 21:45:09 +00:00
|
|
|
if (rle->type == type) {
|
|
|
|
if (printed == 0)
|
|
|
|
retval += printf(" %s ", name);
|
|
|
|
else
|
|
|
|
retval += printf(",");
|
|
|
|
printed++;
|
|
|
|
retval += printf(format, rle->start);
|
|
|
|
if (rle->count > 1) {
|
|
|
|
retval += printf("-");
|
|
|
|
retval += printf(format, rle->start +
|
|
|
|
rle->count - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-28 18:32:13 +00:00
|
|
|
return (retval);
|
2001-12-21 21:45:09 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 15:20:36 +00:00
|
|
|
/**
|
|
|
|
* @brief Releases all the resources in a list.
|
|
|
|
*
|
|
|
|
* @param rl The resource list to purge.
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2005-04-12 15:20:36 +00:00
|
|
|
* @returns nothing
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
resource_list_purge(struct resource_list *rl)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
2006-01-14 09:41:35 +00:00
|
|
|
while ((rle = STAILQ_FIRST(rl)) != NULL) {
|
2005-04-12 15:20:36 +00:00
|
|
|
if (rle->res)
|
|
|
|
bus_release_resource(rman_get_device(rle->res),
|
|
|
|
rle->type, rle->rid, rle->res);
|
|
|
|
STAILQ_REMOVE_HEAD(rl, link);
|
|
|
|
free(rle, M_BUS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-11 19:41:31 +00:00
|
|
|
device_t
|
2010-09-10 11:19:03 +00:00
|
|
|
bus_generic_add_child(device_t dev, u_int order, const char *name, int unit)
|
2006-09-11 19:41:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (device_add_child_ordered(dev, order, name, unit));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_PROBE()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_PROBE() for
|
|
|
|
* a bus (i.e. a device which has other devices attached to it). It
|
|
|
|
* calls the DEVICE_IDENTIFY() method of each driver in the device's
|
|
|
|
* devclass.
|
1999-05-14 11:22:47 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_probe(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
devclass_t dc = dev->devclass;
|
|
|
|
driverlink_t dl;
|
1999-05-14 11:22:47 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link) {
|
2009-06-09 14:26:23 +00:00
|
|
|
/*
|
|
|
|
* If this driver's pass is too high, then ignore it.
|
|
|
|
* For most drivers in the default pass, this will
|
|
|
|
* never be true. For early-pass drivers they will
|
|
|
|
* only call the identify routines of eligible drivers
|
|
|
|
* when this routine is called. Drivers for later
|
|
|
|
* passes should have their identify routines called
|
2017-01-15 17:54:01 +00:00
|
|
|
* on early-pass buses during BUS_NEW_PASS().
|
2009-06-09 14:26:23 +00:00
|
|
|
*/
|
|
|
|
if (dl->pass > bus_current_pass)
|
2010-08-12 19:26:27 +00:00
|
|
|
continue;
|
2001-01-05 07:29:54 +00:00
|
|
|
DEVICE_IDENTIFY(dl->driver, dev);
|
|
|
|
}
|
1999-05-14 11:22:47 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1999-05-14 11:22:47 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_ATTACH()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_ATTACH() for
|
|
|
|
* a bus. It calls device_probe_and_attach() for each of the device's
|
|
|
|
* children.
|
|
|
|
*/
|
1998-06-14 13:46:10 +00:00
|
|
|
int
|
|
|
|
bus_generic_attach(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t child;
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
|
|
|
device_probe_and_attach(child);
|
|
|
|
}
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-14 13:46:10 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_DETACH()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_DETACH() for
|
|
|
|
* a bus. It calls device_detach() for each of the device's
|
|
|
|
* children.
|
|
|
|
*/
|
1998-06-14 13:46:10 +00:00
|
|
|
int
|
|
|
|
bus_generic_detach(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t child;
|
|
|
|
int error;
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (dev->state != DS_ATTACHED)
|
|
|
|
return (EBUSY);
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2018-05-05 05:19:32 +00:00
|
|
|
/*
|
|
|
|
* Detach children in the reverse order.
|
|
|
|
* See bus_generic_suspend for details.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH_REVERSE(child, &dev->children, device_list, link) {
|
2001-01-05 07:29:54 +00:00
|
|
|
if ((error = device_detach(child)) != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-14 13:46:10 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_SHUTDOWN()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_SHUTDOWN()
|
|
|
|
* for a bus. It calls device_shutdown() for each of the device's
|
|
|
|
* children.
|
|
|
|
*/
|
1998-06-14 13:46:10 +00:00
|
|
|
int
|
|
|
|
bus_generic_shutdown(device_t dev)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t child;
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2018-05-05 05:19:32 +00:00
|
|
|
/*
|
|
|
|
* Shut down children in the reverse order.
|
|
|
|
* See bus_generic_suspend for details.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH_REVERSE(child, &dev->children, device_list, link) {
|
2001-01-05 07:29:54 +00:00
|
|
|
device_shutdown(child);
|
|
|
|
}
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 02:56:40 +00:00
|
|
|
/**
|
|
|
|
* @brief Default function for suspending a child device.
|
|
|
|
*
|
|
|
|
* This function is to be used by a bus's DEVICE_SUSPEND_CHILD().
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_suspend_child(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = DEVICE_SUSPEND(child);
|
|
|
|
|
|
|
|
if (error == 0)
|
2015-02-05 22:24:22 +00:00
|
|
|
child->flags |= DF_SUSPENDED;
|
2014-09-23 02:56:40 +00:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default function for resuming a child device.
|
|
|
|
*
|
|
|
|
* This function is to be used by a bus's DEVICE_RESUME_CHILD().
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_resume_child(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
|
|
|
|
DEVICE_RESUME(child);
|
2015-02-05 22:24:22 +00:00
|
|
|
child->flags &= ~DF_SUSPENDED;
|
2014-09-23 02:56:40 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_SUSPEND()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_SUSPEND()
|
|
|
|
* for a bus. It calls DEVICE_SUSPEND() for each of the device's
|
|
|
|
* children. If any call to DEVICE_SUSPEND() fails, the suspend
|
|
|
|
* operation is aborted and any devices which were suspended are
|
|
|
|
* resumed immediately by calling their DEVICE_RESUME() methods.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_generic_suspend(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
2018-05-05 05:19:32 +00:00
|
|
|
device_t child;
|
1998-11-14 21:58:51 +00:00
|
|
|
|
2018-05-05 05:19:32 +00:00
|
|
|
/*
|
|
|
|
* Suspend children in the reverse order.
|
|
|
|
* For most buses all children are equal, so the order does not matter.
|
|
|
|
* Other buses, such as acpi, carefully order their child devices to
|
|
|
|
* express implicit dependencies between them. For such buses it is
|
|
|
|
* safer to bring down devices in the reverse order.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH_REVERSE(child, &dev->children, device_list, link) {
|
2014-09-23 02:56:40 +00:00
|
|
|
error = BUS_SUSPEND_CHILD(dev, child);
|
2018-05-05 05:19:32 +00:00
|
|
|
if (error != 0) {
|
|
|
|
child = TAILQ_NEXT(child, link);
|
|
|
|
if (child != NULL) {
|
|
|
|
TAILQ_FOREACH_FROM(child, &dev->children, link)
|
|
|
|
BUS_RESUME_CHILD(dev, child);
|
|
|
|
}
|
1998-11-14 21:58:51 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing DEVICE_RESUME()
|
|
|
|
*
|
|
|
|
* This function can be used to help implement the DEVICE_RESUME() for
|
|
|
|
* a bus. It calls DEVICE_RESUME() on each of the device's children.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_generic_resume(device_t dev)
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
2014-09-23 02:56:40 +00:00
|
|
|
BUS_RESUME_CHILD(dev, child);
|
1998-11-14 21:58:51 +00:00
|
|
|
/* if resume fails, there's nothing we can usefully do... */
|
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_PRINT_CHILD().
|
|
|
|
*
|
|
|
|
* This function prints the first part of the ascii representation of
|
|
|
|
* @p child, including its name, unit and description (if any - see
|
|
|
|
* device_set_desc()).
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
1999-07-29 01:03:04 +00:00
|
|
|
int
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_print_child_header(device_t dev, device_t child)
|
1999-07-29 01:03:04 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
if (device_get_desc(child)) {
|
|
|
|
retval += device_printf(child, "<%s>", device_get_desc(child));
|
1999-07-29 01:03:04 +00:00
|
|
|
} else {
|
1999-07-29 01:51:49 +00:00
|
|
|
retval += printf("%s", device_get_nameunit(child));
|
1999-07-29 01:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_PRINT_CHILD().
|
|
|
|
*
|
|
|
|
* This function prints the last part of the ascii representation of
|
|
|
|
* @p child, which consists of the string @c " on " followed by the
|
|
|
|
* name and unit of the @p dev.
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
1999-07-29 01:03:04 +00:00
|
|
|
int
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_print_child_footer(device_t dev, device_t child)
|
1999-07-29 01:03:04 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (printf(" on %s\n", device_get_nameunit(dev)));
|
1999-07-29 01:03:04 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 05:33:25 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_PRINT_CHILD().
|
|
|
|
*
|
|
|
|
* This function prints out the VM domain for the given device.
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_print_child_domain(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
int domain;
|
|
|
|
|
|
|
|
/* No domain? Don't print anything */
|
|
|
|
if (BUS_GET_DOMAIN(dev, child, &domain) != 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (printf(" numa-domain %d", domain));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_PRINT_CHILD().
|
|
|
|
*
|
|
|
|
* This function simply calls bus_print_child_header() followed by
|
|
|
|
* bus_print_child_footer().
|
|
|
|
*
|
|
|
|
* @returns the number of characters printed
|
|
|
|
*/
|
1999-07-29 01:03:04 +00:00
|
|
|
int
|
1998-06-14 13:46:10 +00:00
|
|
|
bus_generic_print_child(device_t dev, device_t child)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
1999-07-29 01:03:04 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(dev, child);
|
2014-10-09 05:33:25 +00:00
|
|
|
retval += bus_print_child_domain(dev, child);
|
1999-07-29 01:03:04 +00:00
|
|
|
retval += bus_print_child_footer(dev, child);
|
|
|
|
|
|
|
|
return (retval);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Stub function for implementing BUS_READ_IVAR().
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns ENOENT
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_generic_read_ivar(device_t dev, device_t child, int index,
|
|
|
|
uintptr_t * result)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (ENOENT);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Stub function for implementing BUS_WRITE_IVAR().
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns ENOENT
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_generic_write_ivar(device_t dev, device_t child, int index,
|
|
|
|
uintptr_t value)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (ENOENT);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Stub function for implementing BUS_GET_RESOURCE_LIST().
|
2015-01-05 20:50:44 +00:00
|
|
|
*
|
2004-07-18 16:30:31 +00:00
|
|
|
* @returns NULL
|
|
|
|
*/
|
2000-11-28 06:49:15 +00:00
|
|
|
struct resource_list *
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_get_resource_list(device_t dev, device_t child)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (NULL);
|
2000-10-18 05:15:40 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_DRIVER_ADDED().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_DRIVER_ADDED() simply calls the driver's
|
|
|
|
* DEVICE_IDENTIFY() method to allow it to add new children to the bus
|
|
|
|
* and then calls device_probe_and_attach() for each unattached child.
|
|
|
|
*/
|
1999-04-16 21:22:55 +00:00
|
|
|
void
|
|
|
|
bus_generic_driver_added(device_t dev, driver_t *driver)
|
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
device_t child;
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
DEVICE_IDENTIFY(driver, dev);
|
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
2004-08-29 18:25:21 +00:00
|
|
|
if (child->state == DS_NOTPRESENT ||
|
|
|
|
(child->flags & DF_REBID))
|
2001-01-05 07:29:54 +00:00
|
|
|
device_probe_and_attach(child);
|
|
|
|
}
|
1999-04-16 21:22:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 14:26:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_NEW_PASS().
|
|
|
|
*
|
|
|
|
* This implementing of BUS_NEW_PASS() first calls the identify
|
|
|
|
* routines for any drivers that probe at the current pass. Then it
|
|
|
|
* walks the list of devices for this bus. If a device is already
|
|
|
|
* attached, then it calls BUS_NEW_PASS() on that device. If the
|
|
|
|
* device is not already attached, it attempts to attach a driver to
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bus_generic_new_pass(device_t dev)
|
|
|
|
{
|
|
|
|
driverlink_t dl;
|
|
|
|
devclass_t dc;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
dc = dev->devclass;
|
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link) {
|
|
|
|
if (dl->pass == bus_current_pass)
|
|
|
|
DEVICE_IDENTIFY(dl->driver, dev);
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
|
|
|
if (child->state >= DS_ATTACHED)
|
|
|
|
BUS_NEW_PASS(child);
|
|
|
|
else if (child->state == DS_NOTPRESENT)
|
|
|
|
device_probe_and_attach(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_SETUP_INTR().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_SETUP_INTR() simply calls the
|
|
|
|
* BUS_SETUP_INTR() method of the parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
2001-01-05 07:29:54 +00:00
|
|
|
bus_generic_setup_intr(device_t dev, device_t child, struct resource *irq,
|
2015-01-05 20:50:44 +00:00
|
|
|
int flags, driver_filter_t *filter, driver_intr_t *intr, void *arg,
|
2007-02-23 12:19:07 +00:00
|
|
|
void **cookiep)
|
1998-07-12 16:20:52 +00:00
|
|
|
{
|
1998-11-14 21:58:51 +00:00
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
1999-05-08 21:59:43 +00:00
|
|
|
return (BUS_SETUP_INTR(dev->parent, child, irq, flags,
|
2007-02-23 12:19:07 +00:00
|
|
|
filter, intr, arg, cookiep));
|
2001-01-05 07:29:54 +00:00
|
|
|
return (EINVAL);
|
1998-07-12 16:20:52 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_TEARDOWN_INTR().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_TEARDOWN_INTR() simply calls the
|
|
|
|
* BUS_TEARDOWN_INTR() method of the parent of @p dev.
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
1998-11-14 21:58:51 +00:00
|
|
|
bus_generic_teardown_intr(device_t dev, device_t child, struct resource *irq,
|
2001-01-05 07:29:54 +00:00
|
|
|
void *cookie)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
1998-11-14 21:58:51 +00:00
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
1999-01-16 17:44:09 +00:00
|
|
|
return (BUS_TEARDOWN_INTR(dev->parent, child, irq, cookie));
|
2001-01-05 07:29:54 +00:00
|
|
|
return (EINVAL);
|
1999-01-16 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
2011-04-29 21:36:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_ADJUST_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_ADJUST_RESOURCE() simply calls the
|
|
|
|
* BUS_ADJUST_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_adjust_resource(device_t dev, device_t child, int type,
|
2016-01-27 02:23:54 +00:00
|
|
|
struct resource *r, rman_res_t start, rman_res_t end)
|
2011-04-29 21:36:45 +00:00
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_ADJUST_RESOURCE(dev->parent, child, type, r, start,
|
|
|
|
end));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_ALLOC_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_ALLOC_RESOURCE() simply calls the
|
|
|
|
* BUS_ALLOC_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
1999-01-16 17:44:09 +00:00
|
|
|
struct resource *
|
|
|
|
bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
|
1999-01-16 17:44:09 +00:00
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (BUS_ALLOC_RESOURCE(dev->parent, child, type, rid,
|
|
|
|
start, end, count, flags));
|
|
|
|
return (NULL);
|
1999-01-16 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_RELEASE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_RELEASE_RESOURCE() simply calls the
|
|
|
|
* BUS_RELEASE_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
1999-01-16 17:44:09 +00:00
|
|
|
int
|
|
|
|
bus_generic_release_resource(device_t dev, device_t child, int type, int rid,
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource *r)
|
1999-01-16 17:44:09 +00:00
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (BUS_RELEASE_RESOURCE(dev->parent, child, type, rid,
|
|
|
|
r));
|
|
|
|
return (EINVAL);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_ACTIVATE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_ACTIVATE_RESOURCE() simply calls the
|
|
|
|
* BUS_ACTIVATE_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_generic_activate_resource(device_t dev, device_t child, int type, int rid,
|
2001-01-05 07:29:54 +00:00
|
|
|
struct resource *r)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
1998-11-14 21:58:51 +00:00
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (BUS_ACTIVATE_RESOURCE(dev->parent, child, type, rid,
|
|
|
|
r));
|
|
|
|
return (EINVAL);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_DEACTIVATE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_DEACTIVATE_RESOURCE() simply calls the
|
|
|
|
* BUS_DEACTIVATE_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_generic_deactivate_resource(device_t dev, device_t child, int type,
|
2001-01-05 07:29:54 +00:00
|
|
|
int rid, struct resource *r)
|
1998-11-14 21:58:51 +00:00
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_DEACTIVATE_RESOURCE(dev->parent, child, type, rid,
|
2001-01-05 07:29:54 +00:00
|
|
|
r));
|
|
|
|
return (EINVAL);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 17:57:47 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_MAP_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_MAP_RESOURCE() simply calls the
|
|
|
|
* BUS_MAP_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_map_resource(device_t dev, device_t child, int type,
|
|
|
|
struct resource *r, struct resource_map_request *args,
|
|
|
|
struct resource_map *map)
|
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_MAP_RESOURCE(dev->parent, child, type, r, args,
|
|
|
|
map));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_UNMAP_RESOURCE().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_UNMAP_RESOURCE() simply calls the
|
|
|
|
* BUS_UNMAP_RESOURCE() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_unmap_resource(device_t dev, device_t child, int type,
|
|
|
|
struct resource *r, struct resource_map *map)
|
|
|
|
{
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_UNMAP_RESOURCE(dev->parent, child, type, r, map));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2008-03-20 21:24:32 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_BIND_INTR().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_BIND_INTR() simply calls the
|
|
|
|
* BUS_BIND_INTR() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_bind_intr(device_t dev, device_t child, struct resource *irq,
|
|
|
|
int cpu)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_BIND_INTR(dev->parent, child, irq, cpu));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_CONFIG_INTR().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_CONFIG_INTR() simply calls the
|
|
|
|
* BUS_CONFIG_INTR() method of the parent of @p dev.
|
|
|
|
*/
|
2003-09-10 21:37:10 +00:00
|
|
|
int
|
|
|
|
bus_generic_config_intr(device_t dev, int irq, enum intr_trigger trig,
|
|
|
|
enum intr_polarity pol)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_CONFIG_INTR(dev->parent, irq, trig, pol));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2009-10-15 14:54:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_DESCRIBE_INTR().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_DESCRIBE_INTR() simply calls the
|
|
|
|
* BUS_DESCRIBE_INTR() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_describe_intr(device_t dev, device_t child, struct resource *irq,
|
|
|
|
void *cookie, const char *descr)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_DESCRIBE_INTR(dev->parent, child, irq, cookie,
|
|
|
|
descr));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2016-05-09 20:50:21 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_GET_CPUS().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_GET_CPUS() simply calls the
|
|
|
|
* BUS_GET_CPUS() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_generic_get_cpus(device_t dev, device_t child, enum cpu_sets op,
|
|
|
|
size_t setsize, cpuset_t *cpuset)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent != NULL)
|
|
|
|
return (BUS_GET_CPUS(dev->parent, child, op, setsize, cpuset));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2006-09-03 00:27:42 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_GET_DMA_TAG().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_GET_DMA_TAG() simply calls the
|
|
|
|
* BUS_GET_DMA_TAG() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
bus_dma_tag_t
|
|
|
|
bus_generic_get_dma_tag(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent != NULL)
|
|
|
|
return (BUS_GET_DMA_TAG(dev->parent, child));
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-18 13:00:04 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_GET_BUS_TAG().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_GET_BUS_TAG() simply calls the
|
|
|
|
* BUS_GET_BUS_TAG() method of the parent of @p dev.
|
|
|
|
*/
|
|
|
|
bus_space_tag_t
|
|
|
|
bus_generic_get_bus_tag(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Propagate up the bus hierarchy until someone handles it. */
|
|
|
|
if (dev->parent != NULL)
|
|
|
|
return (BUS_GET_BUS_TAG(dev->parent, child));
|
2016-02-18 15:44:45 +00:00
|
|
|
return ((bus_space_tag_t)0);
|
2016-02-18 13:00:04 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_GET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_GET_RESOURCE() uses the
|
|
|
|
* resource_list_find() function to do most of the work. It calls
|
|
|
|
* BUS_GET_RESOURCE_LIST() to find a suitable resource list to
|
|
|
|
* search.
|
|
|
|
*/
|
2000-10-18 05:15:40 +00:00
|
|
|
int
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_rl_get_resource(device_t dev, device_t child, int type, int rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t *startp, rman_res_t *countp)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
|
|
|
struct resource_list * rl = NULL;
|
|
|
|
struct resource_list_entry * rle = NULL;
|
|
|
|
|
2000-11-28 06:49:15 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
|
|
|
if (!rl)
|
|
|
|
return (EINVAL);
|
2000-10-18 05:15:40 +00:00
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
2001-01-05 07:29:54 +00:00
|
|
|
if (!rle)
|
|
|
|
return (ENOENT);
|
2000-10-18 05:15:40 +00:00
|
|
|
|
|
|
|
if (startp)
|
|
|
|
*startp = rle->start;
|
|
|
|
if (countp)
|
|
|
|
*countp = rle->count;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_SET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_SET_RESOURCE() uses the
|
|
|
|
* resource_list_add() function to do most of the work. It calls
|
|
|
|
* BUS_GET_RESOURCE_LIST() to find a suitable resource list to
|
|
|
|
* edit.
|
|
|
|
*/
|
2000-10-18 05:15:40 +00:00
|
|
|
int
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_rl_set_resource(device_t dev, device_t child, int type, int rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start, rman_res_t count)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
|
|
|
struct resource_list * rl = NULL;
|
|
|
|
|
2000-11-28 06:49:15 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
|
|
|
if (!rl)
|
|
|
|
return (EINVAL);
|
2000-10-18 05:15:40 +00:00
|
|
|
|
|
|
|
resource_list_add(rl, type, rid, start, (start + count - 1), count);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_DELETE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_DELETE_RESOURCE() uses the
|
|
|
|
* resource_list_delete() function to do most of the work. It calls
|
|
|
|
* BUS_GET_RESOURCE_LIST() to find a suitable resource list to
|
|
|
|
* edit.
|
|
|
|
*/
|
2000-10-18 05:15:40 +00:00
|
|
|
void
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_rl_delete_resource(device_t dev, device_t child, int type, int rid)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
|
|
|
struct resource_list * rl = NULL;
|
|
|
|
|
2000-11-28 06:49:15 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
|
|
|
if (!rl)
|
2000-10-18 05:15:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
resource_list_delete(rl, type, rid);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_RELEASE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_RELEASE_RESOURCE() uses the
|
|
|
|
* resource_list_release() function to do most of the work. It calls
|
|
|
|
* BUS_GET_RESOURCE_LIST() to find a suitable resource list.
|
|
|
|
*/
|
2000-10-18 05:15:40 +00:00
|
|
|
int
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_rl_release_resource(device_t dev, device_t child, int type,
|
2001-01-05 07:29:54 +00:00
|
|
|
int rid, struct resource *r)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
|
|
|
struct resource_list * rl = NULL;
|
|
|
|
|
2009-12-30 19:44:31 +00:00
|
|
|
if (device_get_parent(child) != dev)
|
|
|
|
return (BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
|
|
|
|
type, rid, r));
|
|
|
|
|
2000-11-28 06:49:15 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
|
|
|
if (!rl)
|
|
|
|
return (EINVAL);
|
2000-10-18 05:15:40 +00:00
|
|
|
|
|
|
|
return (resource_list_release(rl, dev, child, type, rid, r));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_ALLOC_RESOURCE().
|
|
|
|
*
|
|
|
|
* This implementation of BUS_ALLOC_RESOURCE() uses the
|
|
|
|
* resource_list_alloc() function to do most of the work. It calls
|
|
|
|
* BUS_GET_RESOURCE_LIST() to find a suitable resource list.
|
|
|
|
*/
|
2000-10-18 05:15:40 +00:00
|
|
|
struct resource *
|
2003-11-05 06:14:48 +00:00
|
|
|
bus_generic_rl_alloc_resource(device_t dev, device_t child, int type,
|
2016-01-27 02:23:54 +00:00
|
|
|
int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
|
2000-10-18 05:15:40 +00:00
|
|
|
{
|
|
|
|
struct resource_list * rl = NULL;
|
|
|
|
|
2009-12-30 19:44:31 +00:00
|
|
|
if (device_get_parent(child) != dev)
|
|
|
|
return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
|
|
|
|
type, rid, start, end, count, flags));
|
|
|
|
|
2000-11-28 06:49:15 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
|
|
|
if (!rl)
|
|
|
|
return (NULL);
|
2000-10-18 05:15:40 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (resource_list_alloc(rl, dev, child, type, rid,
|
|
|
|
start, end, count, flags));
|
2000-10-18 05:15:40 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_CHILD_PRESENT().
|
|
|
|
*
|
|
|
|
* This simple implementation of BUS_CHILD_PRESENT() simply calls the
|
|
|
|
* BUS_CHILD_PRESENT() method of the parent of @p dev.
|
|
|
|
*/
|
2002-07-21 03:28:43 +00:00
|
|
|
int
|
2004-07-18 16:30:31 +00:00
|
|
|
bus_generic_child_present(device_t dev, device_t child)
|
2002-07-21 03:28:43 +00:00
|
|
|
{
|
2004-07-18 16:30:31 +00:00
|
|
|
return (BUS_CHILD_PRESENT(device_get_parent(dev), dev));
|
2002-07-21 03:28:43 +00:00
|
|
|
}
|
|
|
|
|
2014-10-09 05:33:25 +00:00
|
|
|
int
|
|
|
|
bus_generic_get_domain(device_t dev, device_t child, int *domain)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (dev->parent)
|
|
|
|
return (BUS_GET_DOMAIN(dev->parent, dev, domain));
|
|
|
|
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
|
2016-04-27 17:49:42 +00:00
|
|
|
/**
|
|
|
|
* @brief Helper function for implementing BUS_RESCAN().
|
|
|
|
*
|
|
|
|
* This null implementation of BUS_RESCAN() always fails to indicate
|
|
|
|
* the bus does not support rescanning.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_null_rescan(device_t dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
1998-11-14 21:58:51 +00:00
|
|
|
/*
|
|
|
|
* Some convenience functions to make it easier for drivers to use the
|
|
|
|
* resource-management functions. All these really do is hide the
|
|
|
|
* indirection through the parent's method table, making for slightly
|
|
|
|
* less-wordy code. In the future, it might make sense for this code
|
|
|
|
* to maintain some sort of a list of resources allocated by each device.
|
|
|
|
*/
|
2004-07-18 16:30:31 +00:00
|
|
|
|
2005-09-24 19:31:10 +00:00
|
|
|
int
|
|
|
|
bus_alloc_resources(device_t dev, struct resource_spec *rs,
|
|
|
|
struct resource **res)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; rs[i].type != -1; i++)
|
|
|
|
res[i] = NULL;
|
|
|
|
for (i = 0; rs[i].type != -1; i++) {
|
|
|
|
res[i] = bus_alloc_resource_any(dev,
|
|
|
|
rs[i].type, &rs[i].rid, rs[i].flags);
|
|
|
|
if (res[i] == NULL && !(rs[i].flags & RF_OPTIONAL)) {
|
|
|
|
bus_release_resources(dev, rs, res);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-04-20 01:44:16 +00:00
|
|
|
bus_release_resources(device_t dev, const struct resource_spec *rs,
|
2005-09-24 19:31:10 +00:00
|
|
|
struct resource **res)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; rs[i].type != -1; i++)
|
2006-04-20 01:44:16 +00:00
|
|
|
if (res[i] != NULL) {
|
2005-09-24 19:31:10 +00:00
|
|
|
bus_release_resource(
|
|
|
|
dev, rs[i].type, rs[i].rid, res[i]);
|
2006-04-20 01:44:16 +00:00
|
|
|
res[i] = NULL;
|
|
|
|
}
|
2005-09-24 19:31:10 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_ALLOC_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_ALLOC_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
struct resource *
|
(1) Add a new bus method to get a mapping data for an interrupt.
BUS_MAP_INTR() is used to get an interrupt mapping data according
to provided hints. The hints could be modified afterwards, but only
if mapping data was allocated. This method is intended to be called
before BUS_ALLOC_RESOURCE().
An interrupt mapping data describes an interrupt - hardware number,
type, configuration, cpu binding, and whatever is needed to setup it.
(2) Introduce a method which allows storing of an additional data
in struct resource to be available for bus drivers. This method is
convenient in two ways:
- there is no need to rework existing bus drivers as they can simply
be extended to provide an additional data,
- there is no need to modify any existing bus methods as struct
resource is already passed to them as argument and thus stored data
is simply accessible by other bus drivers.
For now, implement this method only for INTRNG.
This is motivated by needs of modern SOCs where hardware initialization
is not straightforward and resources descriptions are complex, opaque
for everyone but provider, and may vary from SOC to SOC. Typical
situation is that one bus driver can fetch a resource description for
its child device, but it's opaque for this driver. Another bus driver
knows a provider for this kind of resource and can pass this resource
description to it. In fact, something like device IVARS would be
perfect for that if implemented generally enough. Unfortunatelly, IVARS
are usable only by their owners now. Only owner knows its IVARS layout,
thus other bus drivers are not able to use them.
Differential Revision: https://reviews.freebsd.org/D6632
2016-06-05 16:07:57 +00:00
|
|
|
bus_alloc_resource(device_t dev, int type, int *rid, rman_res_t start,
|
|
|
|
rman_res_t end, rman_res_t count, u_int flags)
|
1998-11-14 21:58:51 +00:00
|
|
|
{
|
(1) Add a new bus method to get a mapping data for an interrupt.
BUS_MAP_INTR() is used to get an interrupt mapping data according
to provided hints. The hints could be modified afterwards, but only
if mapping data was allocated. This method is intended to be called
before BUS_ALLOC_RESOURCE().
An interrupt mapping data describes an interrupt - hardware number,
type, configuration, cpu binding, and whatever is needed to setup it.
(2) Introduce a method which allows storing of an additional data
in struct resource to be available for bus drivers. This method is
convenient in two ways:
- there is no need to rework existing bus drivers as they can simply
be extended to provide an additional data,
- there is no need to modify any existing bus methods as struct
resource is already passed to them as argument and thus stored data
is simply accessible by other bus drivers.
For now, implement this method only for INTRNG.
This is motivated by needs of modern SOCs where hardware initialization
is not straightforward and resources descriptions are complex, opaque
for everyone but provider, and may vary from SOC to SOC. Typical
situation is that one bus driver can fetch a resource description for
its child device, but it's opaque for this driver. Another bus driver
knows a provider for this kind of resource and can pass this resource
description to it. In fact, something like device IVARS would be
perfect for that if implemented generally enough. Unfortunatelly, IVARS
are usable only by their owners now. Only owner knows its IVARS layout,
thus other bus drivers are not able to use them.
Differential Revision: https://reviews.freebsd.org/D6632
2016-06-05 16:07:57 +00:00
|
|
|
struct resource *res;
|
|
|
|
|
2007-02-26 19:28:18 +00:00
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (NULL);
|
(1) Add a new bus method to get a mapping data for an interrupt.
BUS_MAP_INTR() is used to get an interrupt mapping data according
to provided hints. The hints could be modified afterwards, but only
if mapping data was allocated. This method is intended to be called
before BUS_ALLOC_RESOURCE().
An interrupt mapping data describes an interrupt - hardware number,
type, configuration, cpu binding, and whatever is needed to setup it.
(2) Introduce a method which allows storing of an additional data
in struct resource to be available for bus drivers. This method is
convenient in two ways:
- there is no need to rework existing bus drivers as they can simply
be extended to provide an additional data,
- there is no need to modify any existing bus methods as struct
resource is already passed to them as argument and thus stored data
is simply accessible by other bus drivers.
For now, implement this method only for INTRNG.
This is motivated by needs of modern SOCs where hardware initialization
is not straightforward and resources descriptions are complex, opaque
for everyone but provider, and may vary from SOC to SOC. Typical
situation is that one bus driver can fetch a resource description for
its child device, but it's opaque for this driver. Another bus driver
knows a provider for this kind of resource and can pass this resource
description to it. In fact, something like device IVARS would be
perfect for that if implemented generally enough. Unfortunatelly, IVARS
are usable only by their owners now. Only owner knows its IVARS layout,
thus other bus drivers are not able to use them.
Differential Revision: https://reviews.freebsd.org/D6632
2016-06-05 16:07:57 +00:00
|
|
|
res = BUS_ALLOC_RESOURCE(dev->parent, dev, type, rid, start, end,
|
|
|
|
count, flags);
|
|
|
|
return (res);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2011-04-29 21:36:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_ADJUST_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_ADJUST_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-27 02:23:54 +00:00
|
|
|
bus_adjust_resource(device_t dev, int type, struct resource *r, rman_res_t start,
|
|
|
|
rman_res_t end)
|
2011-04-29 21:36:45 +00:00
|
|
|
{
|
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_ADJUST_RESOURCE(dev->parent, dev, type, r, start, end));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_ACTIVATE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_ACTIVATE_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_activate_resource(device_t dev, int type, int rid, struct resource *r)
|
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
if (dev->parent == NULL)
|
1998-11-14 21:58:51 +00:00
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_ACTIVATE_RESOURCE(dev->parent, dev, type, rid, r));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_DEACTIVATE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_DEACTIVATE_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_deactivate_resource(device_t dev, int type, int rid, struct resource *r)
|
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
if (dev->parent == NULL)
|
1998-11-14 21:58:51 +00:00
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_DEACTIVATE_RESOURCE(dev->parent, dev, type, rid, r));
|
|
|
|
}
|
|
|
|
|
2016-05-20 17:57:47 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_MAP_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_MAP_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_map_resource(device_t dev, int type, struct resource *r,
|
|
|
|
struct resource_map_request *args, struct resource_map *map)
|
|
|
|
{
|
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_MAP_RESOURCE(dev->parent, dev, type, r, args, map));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_UNMAP_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_UNMAP_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_unmap_resource(device_t dev, int type, struct resource *r,
|
|
|
|
struct resource_map *map)
|
|
|
|
{
|
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_UNMAP_RESOURCE(dev->parent, dev, type, r, map));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_RELEASE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_RELEASE_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1998-11-14 21:58:51 +00:00
|
|
|
int
|
|
|
|
bus_release_resource(device_t dev, int type, int rid, struct resource *r)
|
|
|
|
{
|
(1) Add a new bus method to get a mapping data for an interrupt.
BUS_MAP_INTR() is used to get an interrupt mapping data according
to provided hints. The hints could be modified afterwards, but only
if mapping data was allocated. This method is intended to be called
before BUS_ALLOC_RESOURCE().
An interrupt mapping data describes an interrupt - hardware number,
type, configuration, cpu binding, and whatever is needed to setup it.
(2) Introduce a method which allows storing of an additional data
in struct resource to be available for bus drivers. This method is
convenient in two ways:
- there is no need to rework existing bus drivers as they can simply
be extended to provide an additional data,
- there is no need to modify any existing bus methods as struct
resource is already passed to them as argument and thus stored data
is simply accessible by other bus drivers.
For now, implement this method only for INTRNG.
This is motivated by needs of modern SOCs where hardware initialization
is not straightforward and resources descriptions are complex, opaque
for everyone but provider, and may vary from SOC to SOC. Typical
situation is that one bus driver can fetch a resource description for
its child device, but it's opaque for this driver. Another bus driver
knows a provider for this kind of resource and can pass this resource
description to it. In fact, something like device IVARS would be
perfect for that if implemented generally enough. Unfortunatelly, IVARS
are usable only by their owners now. Only owner knows its IVARS layout,
thus other bus drivers are not able to use them.
Differential Revision: https://reviews.freebsd.org/D6632
2016-06-05 16:07:57 +00:00
|
|
|
int rv;
|
|
|
|
|
2007-02-26 19:28:18 +00:00
|
|
|
if (dev->parent == NULL)
|
1998-11-14 21:58:51 +00:00
|
|
|
return (EINVAL);
|
(1) Add a new bus method to get a mapping data for an interrupt.
BUS_MAP_INTR() is used to get an interrupt mapping data according
to provided hints. The hints could be modified afterwards, but only
if mapping data was allocated. This method is intended to be called
before BUS_ALLOC_RESOURCE().
An interrupt mapping data describes an interrupt - hardware number,
type, configuration, cpu binding, and whatever is needed to setup it.
(2) Introduce a method which allows storing of an additional data
in struct resource to be available for bus drivers. This method is
convenient in two ways:
- there is no need to rework existing bus drivers as they can simply
be extended to provide an additional data,
- there is no need to modify any existing bus methods as struct
resource is already passed to them as argument and thus stored data
is simply accessible by other bus drivers.
For now, implement this method only for INTRNG.
This is motivated by needs of modern SOCs where hardware initialization
is not straightforward and resources descriptions are complex, opaque
for everyone but provider, and may vary from SOC to SOC. Typical
situation is that one bus driver can fetch a resource description for
its child device, but it's opaque for this driver. Another bus driver
knows a provider for this kind of resource and can pass this resource
description to it. In fact, something like device IVARS would be
perfect for that if implemented generally enough. Unfortunatelly, IVARS
are usable only by their owners now. Only owner knows its IVARS layout,
thus other bus drivers are not able to use them.
Differential Revision: https://reviews.freebsd.org/D6632
2016-06-05 16:07:57 +00:00
|
|
|
rv = BUS_RELEASE_RESOURCE(dev->parent, dev, type, rid, r);
|
|
|
|
return (rv);
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_SETUP_INTR().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_SETUP_INTR() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
int
|
1999-05-08 21:59:43 +00:00
|
|
|
bus_setup_intr(device_t dev, struct resource *r, int flags,
|
2007-02-23 12:19:07 +00:00
|
|
|
driver_filter_t filter, driver_intr_t handler, void *arg, void **cookiep)
|
1999-03-29 08:54:20 +00:00
|
|
|
{
|
2003-09-05 22:51:18 +00:00
|
|
|
int error;
|
|
|
|
|
2008-03-10 01:48:25 +00:00
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
error = BUS_SETUP_INTR(dev->parent, dev, r, flags, filter, handler,
|
|
|
|
arg, cookiep);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
if (handler != NULL && !(flags & INTR_MPSAFE))
|
|
|
|
device_printf(dev, "[GIANT-LOCKED]\n");
|
|
|
|
return (0);
|
1999-03-29 08:54:20 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_TEARDOWN_INTR().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_TEARDOWN_INTR() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
1999-03-29 08:54:20 +00:00
|
|
|
int
|
|
|
|
bus_teardown_intr(device_t dev, struct resource *r, void *cookie)
|
|
|
|
{
|
2007-02-26 19:28:18 +00:00
|
|
|
if (dev->parent == NULL)
|
1999-03-29 08:54:20 +00:00
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_TEARDOWN_INTR(dev->parent, dev, r, cookie));
|
|
|
|
}
|
|
|
|
|
2008-03-20 21:24:32 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_BIND_INTR().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_BIND_INTR() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_bind_intr(device_t dev, struct resource *r, int cpu)
|
|
|
|
{
|
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_BIND_INTR(dev->parent, dev, r, cpu));
|
|
|
|
}
|
|
|
|
|
2009-10-15 14:54:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_DESCRIBE_INTR().
|
|
|
|
*
|
|
|
|
* This function first formats the requested description into a
|
|
|
|
* temporary buffer and then calls the BUS_DESCRIBE_INTR() method of
|
|
|
|
* the parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_describe_intr(device_t dev, struct resource *irq, void *cookie,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2009-10-23 15:14:54 +00:00
|
|
|
char descr[MAXCOMLEN + 1];
|
2009-10-15 14:54:35 +00:00
|
|
|
|
|
|
|
if (dev->parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(descr, sizeof(descr), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return (BUS_DESCRIBE_INTR(dev->parent, dev, irq, cookie, descr));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_SET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_SET_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
int
|
|
|
|
bus_set_resource(device_t dev, int type, int rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start, rman_res_t count)
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
{
|
2001-12-28 18:32:13 +00:00
|
|
|
return (BUS_SET_RESOURCE(device_get_parent(dev), dev, type, rid,
|
|
|
|
start, count));
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
int
|
|
|
|
bus_get_resource(device_t dev, int type, int rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t *startp, rman_res_t *countp)
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
return (BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
|
|
|
|
startp, countp));
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_RESOURCE() method of the
|
|
|
|
* parent of @p dev and returns the start value.
|
|
|
|
*/
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
bus_get_resource_start(device_t dev, int type, int rid)
|
|
|
|
{
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start;
|
|
|
|
rman_res_t count;
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
|
2001-01-05 07:29:54 +00:00
|
|
|
&start, &count);
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
if (error)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
|
|
|
return (start);
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_RESOURCE() method of the
|
|
|
|
* parent of @p dev and returns the count value.
|
|
|
|
*/
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
bus_get_resource_count(device_t dev, int type, int rid)
|
|
|
|
{
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start;
|
|
|
|
rman_res_t count;
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
|
2001-01-05 07:29:54 +00:00
|
|
|
&start, &count);
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
if (error)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
|
|
|
return (count);
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_DELETE_RESOURCE().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_DELETE_RESOURCE() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
void
|
|
|
|
bus_delete_resource(device_t dev, int type, int rid)
|
|
|
|
{
|
|
|
|
BUS_DELETE_RESOURCE(device_get_parent(dev), dev, type, rid);
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_CHILD_PRESENT().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_CHILD_PRESENT() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
2002-07-21 03:28:43 +00:00
|
|
|
int
|
2002-10-07 07:08:00 +00:00
|
|
|
bus_child_present(device_t child)
|
2002-07-21 03:28:43 +00:00
|
|
|
{
|
2002-10-07 07:08:00 +00:00
|
|
|
return (BUS_CHILD_PRESENT(device_get_parent(child), child));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_CHILD_PNPINFO_STR().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_CHILD_PNPINFO_STR() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
2002-10-07 07:08:00 +00:00
|
|
|
int
|
|
|
|
bus_child_pnpinfo_str(device_t child, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
device_t parent;
|
2004-02-24 19:31:30 +00:00
|
|
|
|
2002-10-07 07:08:00 +00:00
|
|
|
parent = device_get_parent(child);
|
|
|
|
if (parent == NULL) {
|
|
|
|
*buf = '\0';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (BUS_CHILD_PNPINFO_STR(parent, child, buf, buflen));
|
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_CHILD_LOCATION_STR().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_CHILD_LOCATION_STR() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
2002-10-07 07:08:00 +00:00
|
|
|
int
|
|
|
|
bus_child_location_str(device_t child, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
device_t parent;
|
2004-02-24 19:31:30 +00:00
|
|
|
|
2002-10-07 07:08:00 +00:00
|
|
|
parent = device_get_parent(child);
|
|
|
|
if (parent == NULL) {
|
|
|
|
*buf = '\0';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (BUS_CHILD_LOCATION_STR(parent, child, buf, buflen));
|
2002-07-21 03:28:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:50:21 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_CPUS().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_CPUS() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_get_cpus(device_t dev, enum cpu_sets op, size_t setsize, cpuset_t *cpuset)
|
|
|
|
{
|
|
|
|
device_t parent;
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
if (parent == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
return (BUS_GET_CPUS(parent, dev, op, setsize, cpuset));
|
|
|
|
}
|
|
|
|
|
2006-09-03 00:27:42 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_DMA_TAG().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_DMA_TAG() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
bus_dma_tag_t
|
|
|
|
bus_get_dma_tag(device_t dev)
|
|
|
|
{
|
|
|
|
device_t parent;
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
if (parent == NULL)
|
|
|
|
return (NULL);
|
|
|
|
return (BUS_GET_DMA_TAG(parent, dev));
|
|
|
|
}
|
|
|
|
|
2016-02-18 13:00:04 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_BUS_TAG().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_BUS_TAG() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
bus_space_tag_t
|
|
|
|
bus_get_bus_tag(device_t dev)
|
|
|
|
{
|
|
|
|
device_t parent;
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
if (parent == NULL)
|
2016-02-18 15:44:45 +00:00
|
|
|
return ((bus_space_tag_t)0);
|
2016-02-18 13:00:04 +00:00
|
|
|
return (BUS_GET_BUS_TAG(parent, dev));
|
|
|
|
}
|
|
|
|
|
2014-11-24 19:55:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Wrapper function for BUS_GET_DOMAIN().
|
|
|
|
*
|
|
|
|
* This function simply calls the BUS_GET_DOMAIN() method of the
|
|
|
|
* parent of @p dev.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
bus_get_domain(device_t dev, int *domain)
|
|
|
|
{
|
|
|
|
return (BUS_GET_DOMAIN(device_get_parent(dev), dev, domain));
|
|
|
|
}
|
|
|
|
|
2006-01-22 01:06:25 +00:00
|
|
|
/* Resume all devices and then notify userland that we're up again. */
|
|
|
|
static int
|
|
|
|
root_resume(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = bus_generic_resume(dev);
|
|
|
|
if (error == 0)
|
|
|
|
devctl_notify("kern", "power", "resume", NULL);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-07-29 01:03:04 +00:00
|
|
|
static int
|
1999-01-16 17:44:09 +00:00
|
|
|
root_print_child(device_t dev, device_t child)
|
|
|
|
{
|
2000-08-28 21:08:12 +00:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(dev, child);
|
|
|
|
retval += printf("\n");
|
|
|
|
|
|
|
|
return (retval);
|
1999-01-16 17:44:09 +00:00
|
|
|
}
|
|
|
|
|
1998-11-14 21:58:51 +00:00
|
|
|
static int
|
2009-02-11 04:54:02 +00:00
|
|
|
root_setup_intr(device_t dev, device_t child, struct resource *irq, int flags,
|
|
|
|
driver_filter_t *filter, driver_intr_t *intr, void *arg, void **cookiep)
|
1998-11-14 21:58:51 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If an interrupt mapping gets to here something bad has happened.
|
|
|
|
*/
|
|
|
|
panic("root_setup_intr");
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2002-07-21 03:28:43 +00:00
|
|
|
/*
|
2016-04-29 22:15:33 +00:00
|
|
|
* If we get here, assume that the device is permanent and really is
|
2002-07-21 03:28:43 +00:00
|
|
|
* present in the system. Removable bus drivers are expected to intercept
|
|
|
|
* this call long before it gets here. We return -1 so that drivers that
|
|
|
|
* really care can check vs -1 or some ERRNO returned higher in the food
|
|
|
|
* chain.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
root_child_present(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2016-05-09 20:50:21 +00:00
|
|
|
static int
|
|
|
|
root_get_cpus(device_t dev, device_t child, enum cpu_sets op, size_t setsize,
|
|
|
|
cpuset_t *cpuset)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case INTR_CPUS:
|
|
|
|
/* Default to returning the set of all CPUs. */
|
|
|
|
if (setsize != sizeof(cpuset_t))
|
|
|
|
return (EINVAL);
|
|
|
|
*cpuset = all_cpus;
|
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-08 14:17:18 +00:00
|
|
|
static kobj_method_t root_methods[] = {
|
1998-11-14 21:58:51 +00:00
|
|
|
/* Device interface */
|
2000-04-08 14:17:18 +00:00
|
|
|
KOBJMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
KOBJMETHOD(device_suspend, bus_generic_suspend),
|
2006-01-22 01:06:25 +00:00
|
|
|
KOBJMETHOD(device_resume, root_resume),
|
1998-11-14 21:58:51 +00:00
|
|
|
|
1998-06-14 13:46:10 +00:00
|
|
|
/* Bus interface */
|
2000-04-08 14:17:18 +00:00
|
|
|
KOBJMETHOD(bus_print_child, root_print_child),
|
|
|
|
KOBJMETHOD(bus_read_ivar, bus_generic_read_ivar),
|
|
|
|
KOBJMETHOD(bus_write_ivar, bus_generic_write_ivar),
|
|
|
|
KOBJMETHOD(bus_setup_intr, root_setup_intr),
|
2002-07-21 03:28:43 +00:00
|
|
|
KOBJMETHOD(bus_child_present, root_child_present),
|
2016-05-09 20:50:21 +00:00
|
|
|
KOBJMETHOD(bus_get_cpus, root_get_cpus),
|
1998-06-14 13:46:10 +00:00
|
|
|
|
2009-02-11 04:54:02 +00:00
|
|
|
KOBJMETHOD_END
|
1998-06-14 13:46:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t root_driver = {
|
|
|
|
"root",
|
|
|
|
root_methods,
|
|
|
|
1, /* no softc */
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
|
1998-11-14 21:58:51 +00:00
|
|
|
device_t root_bus;
|
|
|
|
devclass_t root_devclass;
|
1998-06-10 10:57:29 +00:00
|
|
|
|
|
|
|
static int
|
1998-11-14 21:58:51 +00:00
|
|
|
root_bus_module_handler(module_t mod, int what, void* arg)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
2001-01-05 07:29:54 +00:00
|
|
|
switch (what) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
TAILQ_INIT(&bus_data_devices);
|
|
|
|
kobj_class_compile((kobj_class_t) &root_driver);
|
|
|
|
root_bus = make_device(NULL, "root", 0);
|
|
|
|
root_bus->desc = "System root bus";
|
|
|
|
kobj_init((kobj_t) root_bus, (kobj_class_t) &root_driver);
|
|
|
|
root_bus->driver = &root_driver;
|
|
|
|
root_bus->state = DS_ATTACHED;
|
2007-02-26 19:28:18 +00:00
|
|
|
root_devclass = devclass_find_internal("root", NULL, FALSE);
|
2002-10-07 23:17:44 +00:00
|
|
|
devinit();
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1999-04-16 21:22:55 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
case MOD_SHUTDOWN:
|
|
|
|
device_shutdown(root_bus);
|
|
|
|
return (0);
|
2004-07-15 08:26:07 +00:00
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t root_bus_mod = {
|
|
|
|
"rootbus",
|
|
|
|
root_bus_module_handler,
|
2009-02-03 00:10:21 +00:00
|
|
|
NULL
|
1998-06-10 10:57:29 +00:00
|
|
|
};
|
|
|
|
DECLARE_MODULE(rootbus, root_bus_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Automatically configure devices
|
|
|
|
*
|
|
|
|
* This function begins the autoconfiguration process by calling
|
|
|
|
* device_probe_and_attach() for each child of the @c root0 device.
|
2015-01-05 20:50:44 +00:00
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
void
|
1998-11-14 21:58:51 +00:00
|
|
|
root_bus_configure(void)
|
1998-06-10 10:57:29 +00:00
|
|
|
{
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
PDEBUG(("."));
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2009-06-09 14:26:23 +00:00
|
|
|
/* Eventually this will be split up, but this is sufficient for now. */
|
|
|
|
bus_set_pass(BUS_PASS_DEFAULT);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
|
|
|
|
2004-07-18 16:30:31 +00:00
|
|
|
/**
|
|
|
|
* @brief Module handler for registering device drivers
|
|
|
|
*
|
|
|
|
* This module handler is used to automatically register device
|
|
|
|
* drivers when modules are loaded. If @p what is MOD_LOAD, it calls
|
|
|
|
* devclass_add_driver() for the driver described by the
|
|
|
|
* driver_module_data structure pointed to by @p arg
|
|
|
|
*/
|
1998-06-10 10:57:29 +00:00
|
|
|
int
|
1998-11-14 21:58:51 +00:00
|
|
|
driver_module_handler(module_t mod, int what, void *arg)
|
|
|
|
{
|
|
|
|
struct driver_module_data *dmd;
|
|
|
|
devclass_t bus_devclass;
|
2003-10-16 09:16:28 +00:00
|
|
|
kobj_class_t driver;
|
2009-06-09 14:26:23 +00:00
|
|
|
int error, pass;
|
1998-11-14 21:58:51 +00:00
|
|
|
|
|
|
|
dmd = (struct driver_module_data *)arg;
|
2007-02-26 19:28:18 +00:00
|
|
|
bus_devclass = devclass_find_internal(dmd->dmd_busname, NULL, TRUE);
|
2009-08-20 19:17:53 +00:00
|
|
|
error = 0;
|
1998-11-14 21:58:51 +00:00
|
|
|
|
2009-08-16 19:55:53 +00:00
|
|
|
switch (what) {
|
1998-11-14 21:58:51 +00:00
|
|
|
case MOD_LOAD:
|
1999-08-16 21:44:14 +00:00
|
|
|
if (dmd->dmd_chainevh)
|
|
|
|
error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
|
|
|
|
|
2009-06-09 14:26:23 +00:00
|
|
|
pass = dmd->dmd_pass;
|
2003-10-16 09:16:28 +00:00
|
|
|
driver = dmd->dmd_driver;
|
2009-06-09 14:26:23 +00:00
|
|
|
PDEBUG(("Loading module: driver %s on bus %s (pass %d)",
|
|
|
|
DRIVERNAME(driver), dmd->dmd_busname, pass));
|
2009-10-22 14:53:44 +00:00
|
|
|
error = devclass_add_driver(bus_devclass, driver, pass,
|
|
|
|
dmd->dmd_devclass);
|
1998-11-14 21:58:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
2003-10-16 09:16:28 +00:00
|
|
|
PDEBUG(("Unloading module: driver %s from bus %s",
|
|
|
|
DRIVERNAME(dmd->dmd_driver),
|
|
|
|
dmd->dmd_busname));
|
|
|
|
error = devclass_delete_driver(bus_devclass,
|
|
|
|
dmd->dmd_driver);
|
1999-08-16 21:44:14 +00:00
|
|
|
|
2004-12-31 20:47:51 +00:00
|
|
|
if (!error && dmd->dmd_chainevh)
|
|
|
|
error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
|
|
|
|
break;
|
|
|
|
case MOD_QUIESCE:
|
|
|
|
PDEBUG(("Quiesce module: driver %s from bus %s",
|
|
|
|
DRIVERNAME(dmd->dmd_driver),
|
|
|
|
dmd->dmd_busname));
|
|
|
|
error = devclass_quiesce_driver(bus_devclass,
|
|
|
|
dmd->dmd_driver);
|
|
|
|
|
1999-08-16 21:44:14 +00:00
|
|
|
if (!error && dmd->dmd_chainevh)
|
|
|
|
error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
|
1998-11-14 21:58:51 +00:00
|
|
|
break;
|
2004-07-15 08:26:07 +00:00
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
1998-11-14 21:58:51 +00:00
|
|
|
}
|
1998-06-10 10:57:29 +00:00
|
|
|
|
1998-11-14 21:58:51 +00:00
|
|
|
return (error);
|
1998-06-10 10:57:29 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2006-07-08 17:06:15 +00:00
|
|
|
/**
|
|
|
|
* @brief Enumerate all hinted devices for this bus.
|
|
|
|
*
|
2007-05-23 17:28:21 +00:00
|
|
|
* Walks through the hints for this bus and calls the bus_hinted_child
|
2006-07-08 17:06:15 +00:00
|
|
|
* routine for each one it fines. It searches first for the specific
|
|
|
|
* bus that's being probed for hinted children (eg isa0), and then for
|
|
|
|
* generic children (eg isa).
|
|
|
|
*
|
|
|
|
* @param dev bus device to enumerate
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bus_enumerate_hinted_children(device_t bus)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
const char *dname, *busname;
|
|
|
|
int dunit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enumerate all devices on the specific bus
|
|
|
|
*/
|
|
|
|
busname = device_get_nameunit(bus);
|
|
|
|
i = 0;
|
|
|
|
while (resource_find_match(&i, &dname, &dunit, "at", busname) == 0)
|
|
|
|
BUS_HINTED_CHILD(bus, dname, dunit);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and all the generic ones.
|
|
|
|
*/
|
|
|
|
busname = device_get_name(bus);
|
|
|
|
i = 0;
|
|
|
|
while (resource_find_match(&i, &dname, &dunit, "at", busname) == 0)
|
|
|
|
BUS_HINTED_CHILD(bus, dname, dunit);
|
|
|
|
}
|
|
|
|
|
1998-10-27 09:21:43 +00:00
|
|
|
#ifdef BUS_DEBUG
|
|
|
|
|
|
|
|
/* the _short versions avoid iteration by not calling anything that prints
|
|
|
|
* more than oneliners. I love oneliners.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_device_short(device_t dev, int indent)
|
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
2018-01-29 02:29:08 +00:00
|
|
|
indentprintf(("device %d: <%s> %sparent,%schildren,%s%s%s%s%s%s,%sivars,%ssoftc,busy=%d\n",
|
2001-01-05 07:29:54 +00:00
|
|
|
dev->unit, dev->desc,
|
|
|
|
(dev->parent? "":"no "),
|
|
|
|
(TAILQ_EMPTY(&dev->children)? "no ":""),
|
|
|
|
(dev->flags&DF_ENABLED? "enabled,":"disabled,"),
|
|
|
|
(dev->flags&DF_FIXEDCLASS? "fixed,":""),
|
|
|
|
(dev->flags&DF_WILDCARD? "wildcard,":""),
|
|
|
|
(dev->flags&DF_DESCMALLOCED? "descmalloced,":""),
|
2004-08-29 18:25:21 +00:00
|
|
|
(dev->flags&DF_REBID? "rebiddable,":""),
|
2018-01-28 05:13:17 +00:00
|
|
|
(dev->flags&DF_SUSPENDED? "suspended,":""),
|
2001-01-05 07:29:54 +00:00
|
|
|
(dev->ivars? "":"no "),
|
|
|
|
(dev->softc? "":"no "),
|
|
|
|
dev->busy));
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_device(device_t dev, int indent)
|
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_device_short(dev, indent);
|
|
|
|
|
|
|
|
indentprintf(("Parent:\n"));
|
|
|
|
print_device_short(dev->parent, indent+1);
|
|
|
|
indentprintf(("Driver:\n"));
|
|
|
|
print_driver_short(dev->driver, indent+1);
|
|
|
|
indentprintf(("Devclass:\n"));
|
|
|
|
print_devclass_short(dev->devclass, indent+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_device_tree_short(device_t dev, int indent)
|
|
|
|
/* print the device and all its children (indented) */
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_device_short(dev, indent);
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
1998-10-27 09:21:43 +00:00
|
|
|
print_device_tree_short(child, indent+1);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_device_tree(device_t dev, int indent)
|
|
|
|
/* print the device and all its children (indented) */
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_device(dev, indent);
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
1998-10-27 09:21:43 +00:00
|
|
|
print_device_tree(child, indent+1);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_driver_short(driver_t *driver, int indent)
|
|
|
|
{
|
|
|
|
if (!driver)
|
|
|
|
return;
|
|
|
|
|
2002-11-07 22:38:04 +00:00
|
|
|
indentprintf(("driver %s: softc size = %zd\n",
|
2001-01-05 07:29:54 +00:00
|
|
|
driver->name, driver->size));
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_driver(driver_t *driver, int indent)
|
|
|
|
{
|
|
|
|
if (!driver)
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_driver_short(driver, indent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_driver_list(driver_list_t drivers, int indent)
|
|
|
|
{
|
1999-08-11 22:55:39 +00:00
|
|
|
driverlink_t driver;
|
1998-10-27 09:21:43 +00:00
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(driver, &drivers, link) {
|
1999-08-11 22:55:39 +00:00
|
|
|
print_driver(driver->driver, indent);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_devclass_short(devclass_t dc, int indent)
|
|
|
|
{
|
|
|
|
if ( !dc )
|
|
|
|
return;
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
indentprintf(("devclass %s: max units = %d\n", dc->name, dc->maxunit));
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_devclass(devclass_t dc, int indent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( !dc )
|
|
|
|
return;
|
|
|
|
|
|
|
|
print_devclass_short(dc, indent);
|
|
|
|
indentprintf(("Drivers:\n"));
|
|
|
|
print_driver_list(dc->drivers, indent+1);
|
|
|
|
|
|
|
|
indentprintf(("Devices:\n"));
|
|
|
|
for (i = 0; i < dc->maxunit; i++)
|
|
|
|
if (dc->devices[i])
|
|
|
|
print_device(dc->devices[i], indent+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_devclass_list_short(void)
|
|
|
|
{
|
|
|
|
devclass_t dc;
|
|
|
|
|
|
|
|
printf("Short listing of devclasses, drivers & devices:\n");
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dc, &devclasses, link) {
|
1998-10-27 09:21:43 +00:00
|
|
|
print_devclass_short(dc, 0);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_devclass_list(void)
|
|
|
|
{
|
|
|
|
devclass_t dc;
|
|
|
|
|
|
|
|
printf("Full listing of devclasses, drivers & devices:\n");
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dc, &devclasses, link) {
|
1998-10-27 09:21:43 +00:00
|
|
|
print_devclass(dc, 0);
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
1998-10-27 09:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User-space access to the device tree.
|
|
|
|
*
|
|
|
|
* We implement a small set of nodes:
|
|
|
|
*
|
2001-01-05 07:29:54 +00:00
|
|
|
* hw.bus Single integer read method to obtain the
|
2000-11-09 10:21:23 +00:00
|
|
|
* current generation count.
|
|
|
|
* hw.bus.devices Reads the entire device tree in flat space.
|
|
|
|
* hw.bus.rman Resource manager interface
|
|
|
|
*
|
|
|
|
* We might like to add the ability to scan devclasses and/or drivers to
|
|
|
|
* determine what else is currently loaded/available.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_bus(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct u_businfo ubus;
|
|
|
|
|
|
|
|
ubus.ub_version = BUS_USER_VERSION;
|
|
|
|
ubus.ub_generation = bus_data_generation;
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
return (SYSCTL_OUT(req, &ubus, sizeof(ubus)));
|
2000-11-09 10:21:23 +00:00
|
|
|
}
|
2001-01-05 07:29:54 +00:00
|
|
|
SYSCTL_NODE(_hw_bus, OID_AUTO, info, CTLFLAG_RW, sysctl_bus,
|
|
|
|
"bus-related data");
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_devices(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int *name = (int *)arg1;
|
|
|
|
u_int namelen = arg2;
|
|
|
|
int index;
|
2016-08-09 19:32:06 +00:00
|
|
|
device_t dev;
|
2018-05-31 02:57:58 +00:00
|
|
|
struct u_device *udev;
|
2000-11-09 10:21:23 +00:00
|
|
|
int error;
|
2018-05-31 02:57:58 +00:00
|
|
|
char *walker, *ep;
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
if (namelen != 2)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (EINVAL);
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
if (bus_data_generation_check(name[0]))
|
2001-01-05 07:29:54 +00:00
|
|
|
return (EINVAL);
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
index = name[1];
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
/*
|
2000-11-09 10:21:23 +00:00
|
|
|
* Scan the list of devices, looking for the requested index.
|
|
|
|
*/
|
2001-01-05 07:29:54 +00:00
|
|
|
TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
|
2000-11-09 10:21:23 +00:00
|
|
|
if (index-- == 0)
|
|
|
|
break;
|
2001-01-05 07:29:54 +00:00
|
|
|
}
|
2000-11-09 10:21:23 +00:00
|
|
|
if (dev == NULL)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (ENOENT);
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
/*
|
2018-05-31 02:57:58 +00:00
|
|
|
* Populate the return item, careful not to overflow the buffer.
|
2000-11-09 10:21:23 +00:00
|
|
|
*/
|
2018-05-31 02:57:58 +00:00
|
|
|
udev = malloc(sizeof(*udev), M_BUS, M_WAITOK | M_ZERO);
|
|
|
|
if (udev == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
udev->dv_handle = (uintptr_t)dev;
|
|
|
|
udev->dv_parent = (uintptr_t)dev->parent;
|
|
|
|
udev->dv_devflags = dev->devflags;
|
|
|
|
udev->dv_flags = dev->flags;
|
|
|
|
udev->dv_state = dev->state;
|
|
|
|
walker = udev->dv_fields;
|
|
|
|
ep = walker + sizeof(udev->dv_fields);
|
|
|
|
#define CP(src) \
|
|
|
|
if ((src) == NULL) \
|
|
|
|
*walker++ = '\0'; \
|
|
|
|
else { \
|
|
|
|
strlcpy(walker, (src), ep - walker); \
|
|
|
|
walker += strlen(walker) + 1; \
|
|
|
|
} \
|
|
|
|
if (walker >= ep) \
|
|
|
|
break;
|
|
|
|
|
|
|
|
do {
|
|
|
|
CP(dev->nameunit);
|
|
|
|
CP(dev->desc);
|
|
|
|
CP(dev->driver != NULL ? dev->driver->name : NULL);
|
|
|
|
bus_child_pnpinfo_str(dev, walker, ep - walker);
|
|
|
|
walker += strlen(walker) + 1;
|
|
|
|
if (walker >= ep)
|
|
|
|
break;
|
|
|
|
bus_child_location_str(dev, walker, ep - walker);
|
|
|
|
walker += strlen(walker) + 1;
|
|
|
|
if (walker >= ep)
|
|
|
|
break;
|
|
|
|
*walker++ = '\0';
|
|
|
|
} while (0);
|
|
|
|
#undef CP
|
|
|
|
error = SYSCTL_OUT(req, udev, sizeof(*udev));
|
|
|
|
free(udev, M_BUS);
|
2001-01-05 07:29:54 +00:00
|
|
|
return (error);
|
2000-11-09 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
2001-01-05 07:29:54 +00:00
|
|
|
SYSCTL_NODE(_hw_bus, OID_AUTO, devices, CTLFLAG_RD, sysctl_devices,
|
|
|
|
"system device tree");
|
2000-11-09 10:21:23 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
bus_data_generation_check(int generation)
|
|
|
|
{
|
|
|
|
if (generation != bus_data_generation)
|
2001-01-05 07:29:54 +00:00
|
|
|
return (1);
|
|
|
|
|
2000-11-09 10:21:23 +00:00
|
|
|
/* XXX generate optimised lists here? */
|
2001-01-05 07:29:54 +00:00
|
|
|
return (0);
|
2000-11-09 10:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bus_data_generation_update(void)
|
|
|
|
{
|
|
|
|
bus_data_generation++;
|
|
|
|
}
|
2005-01-19 06:52:19 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
bus_free_resource(device_t dev, int type, struct resource *r)
|
|
|
|
{
|
|
|
|
if (r == NULL)
|
|
|
|
return (0);
|
|
|
|
return (bus_release_resource(dev, type, rman_get_rid(r), r));
|
|
|
|
}
|
2015-02-06 16:09:01 +00:00
|
|
|
|
2016-04-10 05:05:02 +00:00
|
|
|
device_t
|
|
|
|
device_lookup_by_name(const char *name)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
|
|
|
|
if (dev->nameunit != NULL && strcmp(dev->nameunit, name) == 0)
|
|
|
|
return (dev);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2015-02-06 16:09:01 +00:00
|
|
|
/*
|
|
|
|
* /dev/devctl2 implementation. The existing /dev/devctl device has
|
|
|
|
* implicit semantics on open, so it could not be reused for this.
|
|
|
|
* Another option would be to call this /dev/bus?
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
find_device(struct devreq *req, device_t *devp)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, ensure that the name is nul terminated.
|
|
|
|
*/
|
|
|
|
if (memchr(req->dr_name, '\0', sizeof(req->dr_name)) == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Second, try to find an attached device whose name matches
|
|
|
|
* 'name'.
|
|
|
|
*/
|
2016-04-10 05:05:02 +00:00
|
|
|
dev = device_lookup_by_name(req->dr_name);
|
|
|
|
if (dev != NULL) {
|
|
|
|
*devp = dev;
|
|
|
|
return (0);
|
2015-02-06 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, give device enumerators a chance. */
|
|
|
|
dev = NULL;
|
2018-01-07 18:06:30 +00:00
|
|
|
EVENTHANDLER_DIRECT_INVOKE(dev_lookup, req->dr_name, &dev);
|
2015-02-06 16:09:01 +00:00
|
|
|
if (dev == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
*devp = dev;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2016-05-04 23:31:52 +00:00
|
|
|
driver_exists(device_t bus, const char *driver)
|
2015-02-06 16:09:01 +00:00
|
|
|
{
|
|
|
|
devclass_t dc;
|
|
|
|
|
|
|
|
for (dc = bus->devclass; dc != NULL; dc = dc->parent) {
|
|
|
|
if (devclass_find_driver_internal(dc, driver) != NULL)
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
2018-08-23 05:05:47 +00:00
|
|
|
static void
|
|
|
|
device_gen_nomatch(device_t dev)
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
if (dev->flags & DF_NEEDNOMATCH &&
|
|
|
|
dev->state == DS_NOTPRESENT) {
|
|
|
|
BUS_PROBE_NOMATCH(dev->parent, dev);
|
|
|
|
devnomatch(dev);
|
|
|
|
dev->flags |= DF_DONENOMATCH;
|
|
|
|
}
|
|
|
|
dev->flags &= ~DF_NEEDNOMATCH;
|
|
|
|
TAILQ_FOREACH(child, &dev->children, link) {
|
|
|
|
device_gen_nomatch(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_do_deferred_actions(void)
|
|
|
|
{
|
|
|
|
devclass_t dc;
|
|
|
|
driverlink_t dl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk through the devclasses to find all the drivers we've tagged as
|
|
|
|
* deferred during the freeze and call the driver added routines. They
|
|
|
|
* have already been added to the lists in the background, so the driver
|
|
|
|
* added routines that trigger a probe will have all the right bidders
|
|
|
|
* for the probe auction.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(dc, &devclasses, link) {
|
|
|
|
TAILQ_FOREACH(dl, &dc->drivers, link) {
|
|
|
|
if (dl->flags & DL_DEFERRED_PROBE) {
|
|
|
|
devclass_driver_added(dc, dl->driver);
|
|
|
|
dl->flags &= ~DL_DEFERRED_PROBE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We also defer no-match events during a freeze. Walk the tree and
|
|
|
|
* generate all the pent-up events that are still relevant.
|
|
|
|
*/
|
|
|
|
device_gen_nomatch(root_bus);
|
|
|
|
bus_data_generation_update();
|
|
|
|
}
|
|
|
|
|
2015-02-06 16:09:01 +00:00
|
|
|
static int
|
|
|
|
devctl2_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int fflag,
|
|
|
|
struct thread *td)
|
|
|
|
{
|
|
|
|
struct devreq *req;
|
|
|
|
device_t dev;
|
|
|
|
int error, old;
|
|
|
|
|
|
|
|
/* Locate the device to control. */
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
req = (struct devreq *)data;
|
|
|
|
switch (cmd) {
|
|
|
|
case DEV_ATTACH:
|
|
|
|
case DEV_DETACH:
|
|
|
|
case DEV_ENABLE:
|
|
|
|
case DEV_DISABLE:
|
|
|
|
case DEV_SUSPEND:
|
|
|
|
case DEV_RESUME:
|
|
|
|
case DEV_SET_DRIVER:
|
2016-08-29 22:48:36 +00:00
|
|
|
case DEV_CLEAR_DRIVER:
|
2016-04-27 16:29:03 +00:00
|
|
|
case DEV_RESCAN:
|
2016-04-27 16:33:17 +00:00
|
|
|
case DEV_DELETE:
|
2015-02-06 16:09:01 +00:00
|
|
|
error = priv_check(td, PRIV_DRIVER);
|
|
|
|
if (error == 0)
|
|
|
|
error = find_device(req, &dev);
|
|
|
|
break;
|
2018-08-23 05:05:47 +00:00
|
|
|
case DEV_FREEZE:
|
|
|
|
case DEV_THAW:
|
|
|
|
error = priv_check(td, PRIV_DRIVER);
|
|
|
|
break;
|
2015-02-06 16:09:01 +00:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform the requested operation. */
|
|
|
|
switch (cmd) {
|
|
|
|
case DEV_ATTACH:
|
|
|
|
if (device_is_attached(dev) && (dev->flags & DF_REBID) == 0)
|
|
|
|
error = EBUSY;
|
|
|
|
else if (!device_is_enabled(dev))
|
|
|
|
error = ENXIO;
|
|
|
|
else
|
|
|
|
error = device_probe_and_attach(dev);
|
|
|
|
break;
|
|
|
|
case DEV_DETACH:
|
|
|
|
if (!device_is_attached(dev)) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(req->dr_flags & DEVF_FORCE_DETACH)) {
|
|
|
|
error = device_quiesce(dev);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = device_detach(dev);
|
|
|
|
break;
|
|
|
|
case DEV_ENABLE:
|
|
|
|
if (device_is_enabled(dev)) {
|
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the device has been probed but not attached (e.g.
|
|
|
|
* when it has been disabled by a loader hint), just
|
|
|
|
* attach the device rather than doing a full probe.
|
|
|
|
*/
|
|
|
|
device_enable(dev);
|
|
|
|
if (device_is_alive(dev)) {
|
|
|
|
/*
|
|
|
|
* If the device was disabled via a hint, clear
|
|
|
|
* the hint.
|
|
|
|
*/
|
|
|
|
if (resource_disabled(dev->driver->name, dev->unit))
|
|
|
|
resource_unset_value(dev->driver->name,
|
|
|
|
dev->unit, "disabled");
|
|
|
|
error = device_attach(dev);
|
|
|
|
} else
|
|
|
|
error = device_probe_and_attach(dev);
|
|
|
|
break;
|
|
|
|
case DEV_DISABLE:
|
|
|
|
if (!device_is_enabled(dev)) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(req->dr_flags & DEVF_FORCE_DETACH)) {
|
|
|
|
error = device_quiesce(dev);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force DF_FIXEDCLASS on around detach to preserve
|
|
|
|
* the existing name.
|
|
|
|
*/
|
|
|
|
old = dev->flags;
|
|
|
|
dev->flags |= DF_FIXEDCLASS;
|
|
|
|
error = device_detach(dev);
|
|
|
|
if (!(old & DF_FIXEDCLASS))
|
|
|
|
dev->flags &= ~DF_FIXEDCLASS;
|
|
|
|
if (error == 0)
|
|
|
|
device_disable(dev);
|
|
|
|
break;
|
|
|
|
case DEV_SUSPEND:
|
|
|
|
if (device_is_suspended(dev)) {
|
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (device_get_parent(dev) == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = BUS_SUSPEND_CHILD(device_get_parent(dev), dev);
|
|
|
|
break;
|
|
|
|
case DEV_RESUME:
|
|
|
|
if (!device_is_suspended(dev)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (device_get_parent(dev) == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = BUS_RESUME_CHILD(device_get_parent(dev), dev);
|
|
|
|
break;
|
|
|
|
case DEV_SET_DRIVER: {
|
|
|
|
devclass_t dc;
|
|
|
|
char driver[128];
|
|
|
|
|
|
|
|
error = copyinstr(req->dr_data, driver, sizeof(driver), NULL);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (driver[0] == '\0') {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dev->devclass != NULL &&
|
|
|
|
strcmp(driver, dev->devclass->name) == 0)
|
|
|
|
/* XXX: Could possibly force DF_FIXEDCLASS on? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan drivers for this device's bus looking for at
|
|
|
|
* least one matching driver.
|
|
|
|
*/
|
|
|
|
if (dev->parent == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!driver_exists(dev->parent, driver)) {
|
|
|
|
error = ENOENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dc = devclass_create(driver);
|
|
|
|
if (dc == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach device if necessary. */
|
|
|
|
if (device_is_attached(dev)) {
|
|
|
|
if (req->dr_flags & DEVF_SET_DRIVER_DETACH)
|
|
|
|
error = device_detach(dev);
|
|
|
|
else
|
|
|
|
error = EBUSY;
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any previously-fixed device class and unit. */
|
|
|
|
if (dev->flags & DF_FIXEDCLASS)
|
|
|
|
devclass_delete_device(dev->devclass, dev);
|
|
|
|
dev->flags |= DF_WILDCARD;
|
|
|
|
dev->unit = -1;
|
|
|
|
|
|
|
|
/* Force the new device class. */
|
|
|
|
error = devclass_add_device(dc, dev);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
dev->flags |= DF_FIXEDCLASS;
|
|
|
|
error = device_probe_and_attach(dev);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-29 22:48:36 +00:00
|
|
|
case DEV_CLEAR_DRIVER:
|
|
|
|
if (!(dev->flags & DF_FIXEDCLASS)) {
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (device_is_attached(dev)) {
|
|
|
|
if (req->dr_flags & DEVF_CLEAR_DRIVER_DETACH)
|
|
|
|
error = device_detach(dev);
|
|
|
|
else
|
|
|
|
error = EBUSY;
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->flags &= ~DF_FIXEDCLASS;
|
|
|
|
dev->flags |= DF_WILDCARD;
|
|
|
|
devclass_delete_device(dev->devclass, dev);
|
|
|
|
error = device_probe_and_attach(dev);
|
|
|
|
break;
|
2016-04-27 16:29:03 +00:00
|
|
|
case DEV_RESCAN:
|
|
|
|
if (!device_is_attached(dev)) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = BUS_RESCAN(dev);
|
|
|
|
break;
|
2016-04-27 16:33:17 +00:00
|
|
|
case DEV_DELETE: {
|
|
|
|
device_t parent;
|
|
|
|
|
|
|
|
parent = device_get_parent(dev);
|
|
|
|
if (parent == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!(req->dr_flags & DEVF_FORCE_DELETE)) {
|
|
|
|
if (bus_child_present(dev) != 0) {
|
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error = device_delete_child(parent, dev);
|
|
|
|
break;
|
|
|
|
}
|
2018-08-23 05:05:47 +00:00
|
|
|
case DEV_FREEZE:
|
|
|
|
if (device_frozen)
|
|
|
|
error = EBUSY;
|
|
|
|
else
|
|
|
|
device_frozen = true;
|
|
|
|
break;
|
|
|
|
case DEV_THAW:
|
|
|
|
if (!device_frozen)
|
|
|
|
error = EBUSY;
|
|
|
|
else {
|
|
|
|
device_do_deferred_actions();
|
|
|
|
device_frozen = false;
|
|
|
|
}
|
|
|
|
break;
|
2015-02-06 16:09:01 +00:00
|
|
|
}
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cdevsw devctl2_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_ioctl = devctl2_ioctl,
|
|
|
|
.d_name = "devctl2",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
devctl2_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
make_dev_credf(MAKEDEV_ETERNAL, &devctl2_cdevsw, 0, NULL,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "devctl2");
|
|
|
|
}
|
2016-11-13 00:46:11 +00:00
|
|
|
|
Create deprecation management functions.
gone_in(majar, msg); If we're running in FreeBSD major, tell
the user this code may be deleted soon.
If we're running in FreeBSD major - 1,
the the user is deprecated and will
be gone in major.
Otherwise say nothing.
gone_in_dev(dev, major, msg) Just like gone_in, except use device_printf.
New tunable / sysctl debug.oboslete_panic: 0 - don't panic,
1 - panic in major or newer , 2 - panic in major - 1 or newer
default: 0
if NO_OBSOLETE_CODE is defined, then both of these turn into compile
time errors when building for major. Add options NO_OBSOLETE_CODE to
kernel build system.
This lets us tag code that's going away so users know it will be gone,
as well as automatically manage things.
Differential Review: https://reviews.freebsd.org/D13818
2018-01-29 00:14:39 +00:00
|
|
|
/*
|
|
|
|
* APIs to manage deprecation and obsolescence.
|
|
|
|
*/
|
|
|
|
static int obsolete_panic = 0;
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, obsolete_panic, CTLFLAG_RWTUN, &obsolete_panic, 0,
|
|
|
|
"Bus debug level");
|
|
|
|
/* 0 - don't panic, 1 - panic if already obsolete, 2 - panic if deprecated */
|
|
|
|
static void
|
|
|
|
gone_panic(int major, int running, const char *msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (obsolete_panic)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
if (running < major)
|
|
|
|
return;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
|
|
|
panic("%s", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gone_in(int major, const char *msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
|
|
|
|
if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
|
|
|
|
printf("Obsolete code will removed soon: %s\n", msg);
|
|
|
|
else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major)
|
|
|
|
printf("Deprecated code (to be removed in FreeBSD %d): %s\n",
|
|
|
|
major, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gone_in_dev(device_t dev, int major, const char *msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
|
|
|
|
if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
|
|
|
|
device_printf(dev,
|
|
|
|
"Obsolete code will removed soon: %s\n", msg);
|
|
|
|
else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major)
|
|
|
|
device_printf(dev,
|
|
|
|
"Deprecated code (to be removed in FreeBSD %d): %s\n",
|
|
|
|
major, msg);
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:46:11 +00:00
|
|
|
#ifdef DDB
|
|
|
|
DB_SHOW_COMMAND(device, db_show_device)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
if (!have_addr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev = (device_t)addr;
|
|
|
|
|
|
|
|
db_printf("name: %s\n", device_get_nameunit(dev));
|
|
|
|
db_printf(" driver: %s\n", DRIVERNAME(dev->driver));
|
|
|
|
db_printf(" class: %s\n", DEVCLANAME(dev->devclass));
|
|
|
|
db_printf(" addr: %p\n", dev);
|
|
|
|
db_printf(" parent: %p\n", dev->parent);
|
|
|
|
db_printf(" softc: %p\n", dev->softc);
|
|
|
|
db_printf(" ivars: %p\n", dev->ivars);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB_SHOW_ALL_COMMAND(devices, db_show_all_devices)
|
|
|
|
{
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(dev, &bus_data_devices, devlink) {
|
|
|
|
db_show_device((db_expr_t)dev, true, count, modif);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|