device_if.m (139804) | device_if.m (222253) |
---|---|
1#- 2# Copyright (c) 1998-2004 Doug Rabson 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24# SUCH DAMAGE. 25# | 1#- 2# Copyright (c) 1998-2004 Doug Rabson 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24# SUCH DAMAGE. 25# |
26# $FreeBSD: head/sys/kern/device_if.m 139804 2005-01-06 23:35:40Z imp $ | 26# $FreeBSD: head/sys/kern/device_if.m 222253 2011-05-24 13:22:40Z jhb $ |
27# 28 29#include <sys/bus.h> 30 31/** 32 * @defgroup DEVICE device - KObj methods for all device drivers 33 * @brief A basic set of methods required for all device drivers. 34 * --- 49 unchanged lines hidden (view full) --- 84 * device and a more specific driver which works for a subset 85 * of devices). Because of this, a driver should not assume 86 * that it will be the driver that attaches to the device even 87 * if it returns a success status from DEVICE_PROBE(). In particular, 88 * a driver must free any resources which it allocated during 89 * the probe before returning. The return value of DEVICE_PROBE() 90 * is used to elect which driver is used - the driver which returns 91 * the largest non-error value wins the election and attaches to | 27# 28 29#include <sys/bus.h> 30 31/** 32 * @defgroup DEVICE device - KObj methods for all device drivers 33 * @brief A basic set of methods required for all device drivers. 34 * --- 49 unchanged lines hidden (view full) --- 84 * device and a more specific driver which works for a subset 85 * of devices). Because of this, a driver should not assume 86 * that it will be the driver that attaches to the device even 87 * if it returns a success status from DEVICE_PROBE(). In particular, 88 * a driver must free any resources which it allocated during 89 * the probe before returning. The return value of DEVICE_PROBE() 90 * is used to elect which driver is used - the driver which returns 91 * the largest non-error value wins the election and attaches to |
92 * the device. | 92 * the device. Common non-error values are described in the 93 * DEVICE_PROBE(9) manual page. |
93 * 94 * If a driver matches the hardware, it should set the device 95 * description string using device_set_desc() or | 94 * 95 * If a driver matches the hardware, it should set the device 96 * description string using device_set_desc() or |
96 * device_set_desc_copy(). This string is 97 * used to generate an informative message when DEVICE_ATTACH() 98 * is called. | 97 * device_set_desc_copy(). This string is used to generate an 98 * informative message when DEVICE_ATTACH() is called. |
99 * 100 * As a special case, if a driver returns zero, the driver election 101 * is cut short and that driver will attach to the device | 99 * 100 * As a special case, if a driver returns zero, the driver election 101 * is cut short and that driver will attach to the device |
102 * immediately. | 102 * immediately. This should rarely be used. |
103 * | 103 * |
104 * For example, a probe method for a pci device driver might look | 104 * For example, a probe method for a PCI device driver might look |
105 * like this: 106 * 107 * @code | 105 * like this: 106 * 107 * @code |
108 * int foo_probe(device_t dev) | 108 * int 109 * foo_probe(device_t dev) |
109 * { 110 * if (pci_get_vendor(dev) == FOOVENDOR && 111 * pci_get_device(dev) == FOODEVICE) { 112 * device_set_desc(dev, "Foo device"); | 110 * { 111 * if (pci_get_vendor(dev) == FOOVENDOR && 112 * pci_get_device(dev) == FOODEVICE) { 113 * device_set_desc(dev, "Foo device"); |
113 * return (0); | 114 * return (BUS_PROBE_DEFAULT); |
114 * } 115 * return (ENXIO); 116 * } 117 * @endcode 118 * 119 * To include this method in a device driver, use a line like this 120 * in the driver's method list: 121 * 122 * @code 123 * KOBJMETHOD(device_probe, foo_probe) 124 * @endcode 125 * 126 * @param dev the device to probe 127 * | 115 * } 116 * return (ENXIO); 117 * } 118 * @endcode 119 * 120 * To include this method in a device driver, use a line like this 121 * in the driver's method list: 122 * 123 * @code 124 * KOBJMETHOD(device_probe, foo_probe) 125 * @endcode 126 * 127 * @param dev the device to probe 128 * |
128 * @retval 0 if the driver strongly matches this device | 129 * @retval 0 if this is the only possible driver for this 130 * device |
129 * @retval negative if the driver can match this device - the 130 * least negative value is used to select the 131 * driver 132 * @retval ENXIO if the driver does not match the device 133 * @retval positive if some kind of error was detected during 134 * the probe, a regular unix error code should 135 * be returned to indicate the type of error 136 * @see DEVICE_ATTACH(), pci_get_vendor(), pci_get_device() --- 180 unchanged lines hidden --- | 131 * @retval negative if the driver can match this device - the 132 * least negative value is used to select the 133 * driver 134 * @retval ENXIO if the driver does not match the device 135 * @retval positive if some kind of error was detected during 136 * the probe, a regular unix error code should 137 * be returned to indicate the type of error 138 * @see DEVICE_ATTACH(), pci_get_vendor(), pci_get_device() --- 180 unchanged lines hidden --- |