1f9f848faSopenharmony_ci/* 2f9f848faSopenharmony_ci * This file is produced automatically. 3f9f848faSopenharmony_ci * Do not modify anything in here by hand. 4f9f848faSopenharmony_ci * 5f9f848faSopenharmony_ci * Created from source file 6f9f848faSopenharmony_ci * device_if.m 7f9f848faSopenharmony_ci * with 8f9f848faSopenharmony_ci * makeobjops.awk 9f9f848faSopenharmony_ci * 10f9f848faSopenharmony_ci * See the source file for legal information 11f9f848faSopenharmony_ci */ 12f9f848faSopenharmony_ci 13f9f848faSopenharmony_ci/** 14f9f848faSopenharmony_ci * @defgroup DEVICE device - KObj methods for all device drivers 15f9f848faSopenharmony_ci * @brief A basic set of methods required for all device drivers. 16f9f848faSopenharmony_ci * 17f9f848faSopenharmony_ci * The device interface is used to match devices to drivers during 18f9f848faSopenharmony_ci * autoconfiguration and provides methods to allow drivers to handle 19f9f848faSopenharmony_ci * system-wide events such as suspend, resume or shutdown. 20f9f848faSopenharmony_ci * @{ 21f9f848faSopenharmony_ci */ 22f9f848faSopenharmony_ci 23f9f848faSopenharmony_ci#ifndef _device_if_h_ 24f9f848faSopenharmony_ci#define _device_if_h_ 25f9f848faSopenharmony_ci 26f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_PROBE() method */ 27f9f848faSopenharmony_ciextern struct kobjop_desc device_probe_desc; 28f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_PROBE() method */ 29f9f848faSopenharmony_citypedef int device_probe_t(device_t dev); 30f9f848faSopenharmony_ci/** 31f9f848faSopenharmony_ci * @brief Probe to see if a device matches a driver. 32f9f848faSopenharmony_ci * 33f9f848faSopenharmony_ci * Users should not call this method directly. Normally, this 34f9f848faSopenharmony_ci * is called via device_probe_and_attach() to select a driver 35f9f848faSopenharmony_ci * calling the DEVICE_PROBE() of all candidate drivers and attach 36f9f848faSopenharmony_ci * the winning driver (if any) to the device. 37f9f848faSopenharmony_ci * 38f9f848faSopenharmony_ci * This function is used to match devices to device drivers. 39f9f848faSopenharmony_ci * Typically, the driver will examine the device to see if 40f9f848faSopenharmony_ci * it is suitable for this driver. This might include checking 41f9f848faSopenharmony_ci * the values of various device instance variables or reading 42f9f848faSopenharmony_ci * hardware registers. 43f9f848faSopenharmony_ci * 44f9f848faSopenharmony_ci * In some cases, there may be more than one driver available 45f9f848faSopenharmony_ci * which can be used for a device (for instance there might 46f9f848faSopenharmony_ci * be a generic driver which works for a set of many types of 47f9f848faSopenharmony_ci * device and a more specific driver which works for a subset 48f9f848faSopenharmony_ci * of devices). Because of this, a driver should not assume 49f9f848faSopenharmony_ci * that it will be the driver that attaches to the device even 50f9f848faSopenharmony_ci * if it returns a success status from DEVICE_PROBE(). In particular, 51f9f848faSopenharmony_ci * a driver must free any resources which it allocated during 52f9f848faSopenharmony_ci * the probe before returning. The return value of DEVICE_PROBE() 53f9f848faSopenharmony_ci * is used to elect which driver is used - the driver which returns 54f9f848faSopenharmony_ci * the largest non-error value wins the election and attaches to 55f9f848faSopenharmony_ci * the device. Common non-error values are described in the 56f9f848faSopenharmony_ci * DEVICE_PROBE(9) manual page. 57f9f848faSopenharmony_ci * 58f9f848faSopenharmony_ci * If a driver matches the hardware, it should set the device 59f9f848faSopenharmony_ci * description string using device_set_desc() or 60f9f848faSopenharmony_ci * device_set_desc_copy(). This string is used to generate an 61f9f848faSopenharmony_ci * informative message when DEVICE_ATTACH() is called. 62f9f848faSopenharmony_ci * 63f9f848faSopenharmony_ci * As a special case, if a driver returns zero, the driver election 64f9f848faSopenharmony_ci * is cut short and that driver will attach to the device 65f9f848faSopenharmony_ci * immediately. This should rarely be used. 66f9f848faSopenharmony_ci * 67f9f848faSopenharmony_ci * For example, a probe method for a PCI device driver might look 68f9f848faSopenharmony_ci * like this: 69f9f848faSopenharmony_ci * 70f9f848faSopenharmony_ci * @code 71f9f848faSopenharmony_ci * int 72f9f848faSopenharmony_ci * foo_probe(device_t dev) 73f9f848faSopenharmony_ci * { 74f9f848faSopenharmony_ci * if (pci_get_vendor(dev) == FOOVENDOR && 75f9f848faSopenharmony_ci * pci_get_device(dev) == FOODEVICE) { 76f9f848faSopenharmony_ci * device_set_desc(dev, "Foo device"); 77f9f848faSopenharmony_ci * return (BUS_PROBE_DEFAULT); 78f9f848faSopenharmony_ci * } 79f9f848faSopenharmony_ci * return (ENXIO); 80f9f848faSopenharmony_ci * } 81f9f848faSopenharmony_ci * @endcode 82f9f848faSopenharmony_ci * 83f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 84f9f848faSopenharmony_ci * in the driver's method list: 85f9f848faSopenharmony_ci * 86f9f848faSopenharmony_ci * @code 87f9f848faSopenharmony_ci * KOBJMETHOD(device_probe, foo_probe) 88f9f848faSopenharmony_ci * @endcode 89f9f848faSopenharmony_ci * 90f9f848faSopenharmony_ci * @param dev the device to probe 91f9f848faSopenharmony_ci * 92f9f848faSopenharmony_ci * @retval 0 if this is the only possible driver for this 93f9f848faSopenharmony_ci * device 94f9f848faSopenharmony_ci * @retval negative if the driver can match this device - the 95f9f848faSopenharmony_ci * least negative value is used to select the 96f9f848faSopenharmony_ci * driver 97f9f848faSopenharmony_ci * @retval ENXIO if the driver does not match the device 98f9f848faSopenharmony_ci * @retval positive if some kind of error was detected during 99f9f848faSopenharmony_ci * the probe, a regular unix error code should 100f9f848faSopenharmony_ci * be returned to indicate the type of error 101f9f848faSopenharmony_ci * @see DEVICE_ATTACH(), pci_get_vendor(), pci_get_device() 102f9f848faSopenharmony_ci */ 103f9f848faSopenharmony_ci 104f9f848faSopenharmony_cistatic __inline int DEVICE_PROBE(device_t dev) 105f9f848faSopenharmony_ci{ 106f9f848faSopenharmony_ci kobjop_t _m; 107f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_probe); 108f9f848faSopenharmony_ci return ((device_probe_t *) _m)(dev); 109f9f848faSopenharmony_ci} 110f9f848faSopenharmony_ci 111f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_IDENTIFY() method */ 112f9f848faSopenharmony_ciextern struct kobjop_desc device_identify_desc; 113f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_IDENTIFY() method */ 114f9f848faSopenharmony_citypedef void device_identify_t(driver_t *driver, device_t parent); 115f9f848faSopenharmony_ci/** 116f9f848faSopenharmony_ci * @brief Allow a device driver to detect devices not otherwise enumerated. 117f9f848faSopenharmony_ci * 118f9f848faSopenharmony_ci * The DEVICE_IDENTIFY() method is used by some drivers (e.g. the ISA 119f9f848faSopenharmony_ci * bus driver) to help populate the bus device with a useful set of 120f9f848faSopenharmony_ci * child devices, normally by calling the BUS_ADD_CHILD() method of 121f9f848faSopenharmony_ci * the parent device. For instance, the ISA bus driver uses several 122f9f848faSopenharmony_ci * special drivers, including the isahint driver and the pnp driver to 123f9f848faSopenharmony_ci * create child devices based on configuration hints and PnP bus 124f9f848faSopenharmony_ci * probes respectively. 125f9f848faSopenharmony_ci * 126f9f848faSopenharmony_ci * Many bus drivers which support true plug-and-play do not need to 127f9f848faSopenharmony_ci * use this method at all since child devices can be discovered 128f9f848faSopenharmony_ci * automatically without help from child drivers. 129f9f848faSopenharmony_ci * 130f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 131f9f848faSopenharmony_ci * in the driver's method list: 132f9f848faSopenharmony_ci * 133f9f848faSopenharmony_ci * @code 134f9f848faSopenharmony_ci * KOBJMETHOD(device_identify, foo_identify) 135f9f848faSopenharmony_ci * @endcode 136f9f848faSopenharmony_ci * 137f9f848faSopenharmony_ci * @param driver the driver whose identify method is being called 138f9f848faSopenharmony_ci * @param parent the parent device to use when adding new children 139f9f848faSopenharmony_ci */ 140f9f848faSopenharmony_ci 141f9f848faSopenharmony_cistatic __inline void DEVICE_IDENTIFY(driver_t *driver, device_t parent) 142f9f848faSopenharmony_ci{ 143f9f848faSopenharmony_ci kobjop_t _m; 144f9f848faSopenharmony_ci KOBJOPLOOKUP(driver->ops,device_identify); 145f9f848faSopenharmony_ci ((device_identify_t *) _m)(driver, parent); 146f9f848faSopenharmony_ci} 147f9f848faSopenharmony_ci 148f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_ATTACH() method */ 149f9f848faSopenharmony_ciextern struct kobjop_desc device_attach_desc; 150f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_ATTACH() method */ 151f9f848faSopenharmony_citypedef int device_attach_t(device_t dev); 152f9f848faSopenharmony_ci/** 153f9f848faSopenharmony_ci * @brief Attach a device to a device driver 154f9f848faSopenharmony_ci * 155f9f848faSopenharmony_ci * Normally only called via device_probe_and_attach(), this is called 156f9f848faSopenharmony_ci * when a driver has succeeded in probing against a device. 157f9f848faSopenharmony_ci * This method should initialise the hardware and allocate other 158f9f848faSopenharmony_ci * system resources (e.g. devfs entries) as required. 159f9f848faSopenharmony_ci * 160f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 161f9f848faSopenharmony_ci * in the driver's method list: 162f9f848faSopenharmony_ci * 163f9f848faSopenharmony_ci * @code 164f9f848faSopenharmony_ci * KOBJMETHOD(device_attach, foo_attach) 165f9f848faSopenharmony_ci * @endcode 166f9f848faSopenharmony_ci * 167f9f848faSopenharmony_ci * @param dev the device to probe 168f9f848faSopenharmony_ci * 169f9f848faSopenharmony_ci * @retval 0 success 170f9f848faSopenharmony_ci * @retval non-zero if some kind of error was detected during 171f9f848faSopenharmony_ci * the attach, a regular unix error code should 172f9f848faSopenharmony_ci * be returned to indicate the type of error 173f9f848faSopenharmony_ci * @see DEVICE_PROBE() 174f9f848faSopenharmony_ci */ 175f9f848faSopenharmony_ci 176f9f848faSopenharmony_cistatic __inline int DEVICE_ATTACH(device_t dev) 177f9f848faSopenharmony_ci{ 178f9f848faSopenharmony_ci kobjop_t _m; 179f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_attach); 180f9f848faSopenharmony_ci return ((device_attach_t *) _m)(dev); 181f9f848faSopenharmony_ci} 182f9f848faSopenharmony_ci 183f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_DETACH() method */ 184f9f848faSopenharmony_ciextern struct kobjop_desc device_detach_desc; 185f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_DETACH() method */ 186f9f848faSopenharmony_citypedef int device_detach_t(device_t dev); 187f9f848faSopenharmony_ci/** 188f9f848faSopenharmony_ci * @brief Detach a driver from a device. 189f9f848faSopenharmony_ci * 190f9f848faSopenharmony_ci * This can be called if the user is replacing the 191f9f848faSopenharmony_ci * driver software or if a device is about to be physically removed 192f9f848faSopenharmony_ci * from the system (e.g. for removable hardware such as USB or PCCARD). 193f9f848faSopenharmony_ci * 194f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 195f9f848faSopenharmony_ci * in the driver's method list: 196f9f848faSopenharmony_ci * 197f9f848faSopenharmony_ci * @code 198f9f848faSopenharmony_ci * KOBJMETHOD(device_detach, foo_detach) 199f9f848faSopenharmony_ci * @endcode 200f9f848faSopenharmony_ci * 201f9f848faSopenharmony_ci * @param dev the device to detach 202f9f848faSopenharmony_ci * 203f9f848faSopenharmony_ci * @retval 0 success 204f9f848faSopenharmony_ci * @retval non-zero the detach could not be performed, e.g. if the 205f9f848faSopenharmony_ci * driver does not support detaching. 206f9f848faSopenharmony_ci * 207f9f848faSopenharmony_ci * @see DEVICE_ATTACH() 208f9f848faSopenharmony_ci */ 209f9f848faSopenharmony_ci 210f9f848faSopenharmony_cistatic __inline int DEVICE_DETACH(device_t dev) 211f9f848faSopenharmony_ci{ 212f9f848faSopenharmony_ci kobjop_t _m; 213f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_detach); 214f9f848faSopenharmony_ci return ((device_detach_t *) _m)(dev); 215f9f848faSopenharmony_ci} 216f9f848faSopenharmony_ci 217f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_SHUTDOWN() method */ 218f9f848faSopenharmony_ciextern struct kobjop_desc device_shutdown_desc; 219f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_SHUTDOWN() method */ 220f9f848faSopenharmony_citypedef int device_shutdown_t(device_t dev); 221f9f848faSopenharmony_ci/** 222f9f848faSopenharmony_ci * @brief Called during system shutdown. 223f9f848faSopenharmony_ci * 224f9f848faSopenharmony_ci * This method allows drivers to detect when the system is being shut down. 225f9f848faSopenharmony_ci * Some drivers need to use this to place their hardware in a consistent 226f9f848faSopenharmony_ci * state before rebooting the computer. 227f9f848faSopenharmony_ci * 228f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 229f9f848faSopenharmony_ci * in the driver's method list: 230f9f848faSopenharmony_ci * 231f9f848faSopenharmony_ci * @code 232f9f848faSopenharmony_ci * KOBJMETHOD(device_shutdown, foo_shutdown) 233f9f848faSopenharmony_ci * @endcode 234f9f848faSopenharmony_ci */ 235f9f848faSopenharmony_ci 236f9f848faSopenharmony_cistatic __inline int DEVICE_SHUTDOWN(device_t dev) 237f9f848faSopenharmony_ci{ 238f9f848faSopenharmony_ci kobjop_t _m; 239f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_shutdown); 240f9f848faSopenharmony_ci return ((device_shutdown_t *) _m)(dev); 241f9f848faSopenharmony_ci} 242f9f848faSopenharmony_ci 243f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_SUSPEND() method */ 244f9f848faSopenharmony_ciextern struct kobjop_desc device_suspend_desc; 245f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_SUSPEND() method */ 246f9f848faSopenharmony_citypedef int device_suspend_t(device_t dev); 247f9f848faSopenharmony_ci/** 248f9f848faSopenharmony_ci * @brief This is called by the power-management subsystem when a 249f9f848faSopenharmony_ci * suspend has been requested by the user or by some automatic 250f9f848faSopenharmony_ci * mechanism. 251f9f848faSopenharmony_ci * 252f9f848faSopenharmony_ci * This gives drivers a chance to veto the suspend or save their 253f9f848faSopenharmony_ci * configuration before power is removed. 254f9f848faSopenharmony_ci * 255f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this in 256f9f848faSopenharmony_ci * the driver's method list: 257f9f848faSopenharmony_ci * 258f9f848faSopenharmony_ci * @code 259f9f848faSopenharmony_ci * KOBJMETHOD(device_suspend, foo_suspend) 260f9f848faSopenharmony_ci * @endcode 261f9f848faSopenharmony_ci * 262f9f848faSopenharmony_ci * @param dev the device being suspended 263f9f848faSopenharmony_ci * 264f9f848faSopenharmony_ci * @retval 0 success 265f9f848faSopenharmony_ci * @retval non-zero an error occurred while attempting to prepare the 266f9f848faSopenharmony_ci * device for suspension 267f9f848faSopenharmony_ci * 268f9f848faSopenharmony_ci * @see DEVICE_RESUME() 269f9f848faSopenharmony_ci */ 270f9f848faSopenharmony_ci 271f9f848faSopenharmony_cistatic __inline int DEVICE_SUSPEND(device_t dev) 272f9f848faSopenharmony_ci{ 273f9f848faSopenharmony_ci kobjop_t _m; 274f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_suspend); 275f9f848faSopenharmony_ci return ((device_suspend_t *) _m)(dev); 276f9f848faSopenharmony_ci} 277f9f848faSopenharmony_ci 278f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_RESUME() method */ 279f9f848faSopenharmony_ciextern struct kobjop_desc device_resume_desc; 280f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_RESUME() method */ 281f9f848faSopenharmony_citypedef int device_resume_t(device_t dev); 282f9f848faSopenharmony_ci/** 283f9f848faSopenharmony_ci * @brief This is called when the system resumes after a suspend. 284f9f848faSopenharmony_ci * 285f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 286f9f848faSopenharmony_ci * in the driver's method list: 287f9f848faSopenharmony_ci * 288f9f848faSopenharmony_ci * @code 289f9f848faSopenharmony_ci * KOBJMETHOD(device_resume, foo_resume) 290f9f848faSopenharmony_ci * @endcode 291f9f848faSopenharmony_ci * 292f9f848faSopenharmony_ci * @param dev the device being resumed 293f9f848faSopenharmony_ci * 294f9f848faSopenharmony_ci * @retval 0 success 295f9f848faSopenharmony_ci * @retval non-zero an error occurred while attempting to restore the 296f9f848faSopenharmony_ci * device from suspension 297f9f848faSopenharmony_ci * 298f9f848faSopenharmony_ci * @see DEVICE_SUSPEND() 299f9f848faSopenharmony_ci */ 300f9f848faSopenharmony_ci 301f9f848faSopenharmony_cistatic __inline int DEVICE_RESUME(device_t dev) 302f9f848faSopenharmony_ci{ 303f9f848faSopenharmony_ci kobjop_t _m; 304f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_resume); 305f9f848faSopenharmony_ci return ((device_resume_t *) _m)(dev); 306f9f848faSopenharmony_ci} 307f9f848faSopenharmony_ci 308f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_QUIESCE() method */ 309f9f848faSopenharmony_ciextern struct kobjop_desc device_quiesce_desc; 310f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_QUIESCE() method */ 311f9f848faSopenharmony_citypedef int device_quiesce_t(device_t dev); 312f9f848faSopenharmony_ci/** 313f9f848faSopenharmony_ci * @brief This is called when the driver is asked to quiesce itself. 314f9f848faSopenharmony_ci * 315f9f848faSopenharmony_ci * The driver should arrange for the orderly shutdown of this device. 316f9f848faSopenharmony_ci * All further access to the device should be curtailed. Soon there 317f9f848faSopenharmony_ci * will be a request to detach, but there won't necessarily be one. 318f9f848faSopenharmony_ci * 319f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 320f9f848faSopenharmony_ci * in the driver's method list: 321f9f848faSopenharmony_ci * 322f9f848faSopenharmony_ci * @code 323f9f848faSopenharmony_ci * KOBJMETHOD(device_quiesce, foo_quiesce) 324f9f848faSopenharmony_ci * @endcode 325f9f848faSopenharmony_ci * 326f9f848faSopenharmony_ci * @param dev the device being quiesced 327f9f848faSopenharmony_ci * 328f9f848faSopenharmony_ci * @retval 0 success 329f9f848faSopenharmony_ci * @retval non-zero an error occurred while attempting to quiesce the 330f9f848faSopenharmony_ci * device 331f9f848faSopenharmony_ci * 332f9f848faSopenharmony_ci * @see DEVICE_DETACH() 333f9f848faSopenharmony_ci */ 334f9f848faSopenharmony_ci 335f9f848faSopenharmony_cistatic __inline int DEVICE_QUIESCE(device_t dev) 336f9f848faSopenharmony_ci{ 337f9f848faSopenharmony_ci kobjop_t _m; 338f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_quiesce); 339f9f848faSopenharmony_ci return ((device_quiesce_t *) _m)(dev); 340f9f848faSopenharmony_ci} 341f9f848faSopenharmony_ci 342f9f848faSopenharmony_ci/** @brief Unique descriptor for the DEVICE_REGISTER() method */ 343f9f848faSopenharmony_ciextern struct kobjop_desc device_register_desc; 344f9f848faSopenharmony_ci/** @brief A function implementing the DEVICE_REGISTER() method */ 345f9f848faSopenharmony_citypedef void * device_register_t(device_t dev); 346f9f848faSopenharmony_ci/** 347f9f848faSopenharmony_ci * @brief This is called when the driver is asked to register handlers. 348f9f848faSopenharmony_ci * 349f9f848faSopenharmony_ci * 350f9f848faSopenharmony_ci * To include this method in a device driver, use a line like this 351f9f848faSopenharmony_ci * in the driver's method list: 352f9f848faSopenharmony_ci * 353f9f848faSopenharmony_ci * @code 354f9f848faSopenharmony_ci * KOBJMETHOD(device_register, foo_register) 355f9f848faSopenharmony_ci * @endcode 356f9f848faSopenharmony_ci * 357f9f848faSopenharmony_ci * @param dev the device for which handlers are being registered 358f9f848faSopenharmony_ci * 359f9f848faSopenharmony_ci * @retval NULL method not implemented 360f9f848faSopenharmony_ci * @retval non-NULL a pointer to implementation specific static driver state 361f9f848faSopenharmony_ci * 362f9f848faSopenharmony_ci */ 363f9f848faSopenharmony_ci 364f9f848faSopenharmony_cistatic __inline void * DEVICE_REGISTER(device_t dev) 365f9f848faSopenharmony_ci{ 366f9f848faSopenharmony_ci kobjop_t _m; 367f9f848faSopenharmony_ci KOBJOPLOOKUP(((kobj_t)dev)->ops,device_register); 368f9f848faSopenharmony_ci return ((device_register_t *) _m)(dev); 369f9f848faSopenharmony_ci} 370f9f848faSopenharmony_ci 371f9f848faSopenharmony_ci#endif /* _device_if_h_ */ 372