DDI_ADD_EVENT_HANDLER(9F) Kernel Functions for Drivers DDI_ADD_EVENT_HANDLER(9F)

ddi_add_event_handleradd an NDI event service callback handler

#include <sys/dditypes.h>
#include <sys/sunddi.h>

int
ddi_add_event_handler(dev_info_t *dip, ddi_eventcookie_t cookie, void (*handler)(dev_info_t *dip, ddi_eventcookie_t cookie, void *arg, void *bus), void *arg, ddi_callback_id_t *id);

illumos DDI specific (illumos DDI).

dip
Device node registering the callback.
cookie
Cookie returned from call to ddi_get_eventcookie(9F).
handler
Callback handler responsible for handling an NDI event service notification. Its first void * argument corresponds to arg. The second is bus-specific data.
arg
Pointer to opaque data supplied by the caller. Typically, this would be a pointer to the driver's softstate structure.
id
Pointer to a callback ID. The callback ID will be filled in when this function is called and serves as a unique identifier for this particular event handler. This ID must be saved so it can be used in a later call to ddi_remove_event_handler(9F) to remove the callback.

The () function adds a callback handler to be invoked in the face of the event specified by cookie. The process of adding a callback handler is also known as subscribing to an event. Upon successful subscription, the handler will be invoked by the system when the event occurs. The handler can be unregistered by using ddi_remove_event_handler(9F).

An instance of a driver can register multiple handlers for an event or a single handler for multiple events. Callback order is not defined and should assumed to be random.

The callback. handler will be invoked with the following arguments:

dev_info_t *dip
Device node requesting the notification.
ddi_eventcookie_t cookie
Structure describing event that occurred.
void *arg
Opaque data pointer provided, by the driver, during callback registration.
void *bus
Pointer to event specific data defined by the framework which invokes the callback function.

The ddi_add_event_handler() and handler() function can be called from user and kernel contexts only.

Upon successful completion, the ddi_add_event_handler() function returns DDI_SUCCESS and the callback handler is successfully registered. Otherwise, DDI_FAILURE is returned and the callback handler failed to register. Possible reasons include lack of resources or a bad cookie.

attributes(7), ddi_get_eventcookie(9F), ddi_remove_event_handler(9F)

Writing Device Drivers.

Drivers must remove all registered callback handlers for a device instance by calling ddi_remove_event_handler(9F) before detach(9E) completes.

September 15, 2024 OmniOS