Xenomai API  2.6.5
Device Registration Services
Collaboration diagram for Device Registration Services:

Modules

 Synchronisation Services
 

Data Structures

struct  rtdm_operations
 Device operations. More...
 
struct  rtdm_dev_context
 Device context. More...
 
struct  rtdm_device
 RTDM device. More...
 

Functions

static void * rtdm_context_to_private (struct rtdm_dev_context *context)
 Locate the driver private area associated to a device context structure. More...
 
static struct rtdm_dev_contextrtdm_private_to_context (void *dev_private)
 Locate a device context structure from its driver private area. More...
 
int rtdm_dev_register (struct rtdm_device *device)
 Register a RTDM device. More...
 
int rtdm_dev_unregister (struct rtdm_device *device, unsigned int poll_delay)
 Unregisters a RTDM device. More...
 

Device Flags

Static flags describing a RTDM device

#define RTDM_EXCLUSIVE   0x0001
 If set, only a single instance of the device can be requested by an application. More...
 
#define RTDM_NAMED_DEVICE   0x0010
 If set, the device is addressed via a clear-text name. More...
 
#define RTDM_PROTOCOL_DEVICE   0x0020
 If set, the device is addressed via a combination of protocol ID and socket type. More...
 
#define RTDM_DEVICE_TYPE_MASK   0x00F0
 Mask selecting the device type. More...
 

Context Flags

Dynamic flags describing the state of an open RTDM device (bit numbers)

#define RTDM_CREATED_IN_NRT   0
 Set by RTDM if the device instance was created in non-real-time context. More...
 
#define RTDM_CLOSING   1
 Set by RTDM when the device is being closed. More...
 
#define RTDM_USER_CONTEXT_FLAG   8 /* first user-definable flag */
 Lowest bit number the driver developer can use freely.
 

Driver Versioning

Current revisions of RTDM structures, encoding of driver versions. See API Versioning for the interface revision.

#define RTDM_DEVICE_STRUCT_VER   5
 Version of struct rtdm_device.
 
#define RTDM_CONTEXT_STRUCT_VER   3
 Version of struct rtdm_dev_context.
 
#define RTDM_SECURE_DEVICE   0x80000000
 Flag indicating a secure variant of RTDM (not supported here)
 
#define RTDM_DRIVER_VER(major, minor, patch)   (((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF))
 Version code constructor for driver revisions.
 
#define RTDM_DRIVER_MAJOR_VER(ver)   (((ver) >> 16) & 0xFF)
 Get major version number from driver revision code.
 
#define RTDM_DRIVER_MINOR_VER(ver)   (((ver) >> 8) & 0xFF)
 Get minor version number from driver revision code.
 
#define RTDM_DRIVER_PATCH_VER(ver)   ((ver) & 0xFF)
 Get patch version number from driver revision code.
 

Operation Handler Prototypes

typedef int(* rtdm_open_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int oflag)
 Named device open handler. More...
 
typedef int(* rtdm_socket_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int protocol)
 Socket creation handler for protocol devices. More...
 
typedef int(* rtdm_close_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info)
 Close handler. More...
 
typedef int(* rtdm_ioctl_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, unsigned int request, void __user *arg)
 IOCTL handler. More...
 
typedef int(* rtdm_select_bind_handler_t) (struct rtdm_dev_context *context, rtdm_selector_t *selector, enum rtdm_selecttype type, unsigned fd_index)
 Select binding handler. More...
 
typedef ssize_t(* rtdm_read_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, void *buf, size_t nbyte)
 Read handler. More...
 
typedef ssize_t(* rtdm_write_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, const void *buf, size_t nbyte)
 Write handler. More...
 
typedef ssize_t(* rtdm_recvmsg_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, struct user_msghdr *msg, int flags)
 Receive message handler. More...
 
typedef ssize_t(* rtdm_sendmsg_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, const struct user_msghdr *msg, int flags)
 Transmit message handler. More...
 

Detailed Description

Macro Definition Documentation

#define RTDM_CLOSING   1

Set by RTDM when the device is being closed.

#define RTDM_CREATED_IN_NRT   0

Set by RTDM if the device instance was created in non-real-time context.

#define RTDM_DEVICE_TYPE_MASK   0x00F0

Mask selecting the device type.

Referenced by rtdm_dev_register(), and rtdm_dev_unregister().

#define RTDM_EXCLUSIVE   0x0001

If set, only a single instance of the device can be requested by an application.

Referenced by rtdm_dev_register().

#define RTDM_NAMED_DEVICE   0x0010

If set, the device is addressed via a clear-text name.

Referenced by rtdm_dev_register(), and rtdm_dev_unregister().

#define RTDM_PROTOCOL_DEVICE   0x0020

If set, the device is addressed via a combination of protocol ID and socket type.

Referenced by rtdm_dev_register().

Typedef Documentation

typedef int(* rtdm_close_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info)

Close handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode or deferred user mode call
Returns
0 on success. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, -EAGAIN to request a recall after a grace period, or a valid negative error code according to IEEE Std 1003.1.
Note
Drivers must be prepared for that case that the close handler is invoked more than once per open context (even if the handler already completed an earlier run successfully). The driver has to avoid releasing resources twice as well as returning false errors on successive close invocations.
See also
close() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef int(* rtdm_ioctl_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, unsigned int request, void __user *arg)

IOCTL handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in]requestRequest number as passed by the user
[in,out]argRequest argument as passed by the user
Returns
A positive value or 0 on success. On failure return either -ENOSYS, to request that the function be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
ioctl() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef int(* rtdm_open_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int oflag)

Named device open handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in]oflagOpen flags as passed by the user
Returns
0 on success. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
open() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef ssize_t(* rtdm_read_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, void *buf, size_t nbyte)

Read handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[out]bufInput buffer as passed by the user
[in]nbyteNumber of bytes the user requests to read
Returns
On success, the number of bytes read. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
read() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef ssize_t(* rtdm_recvmsg_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, struct user_msghdr *msg, int flags)

Receive message handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in,out]msgMessage descriptor as passed by the user, automatically mirrored to safe kernel memory in case of user mode call
[in]flagsMessage flags as passed by the user
Returns
On success, the number of bytes received. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
recvmsg() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef int(* rtdm_select_bind_handler_t) (struct rtdm_dev_context *context, rtdm_selector_t *selector, enum rtdm_selecttype type, unsigned fd_index)

Select binding handler.

Parameters
[in]contextContext structure associated with opened device instance
[in,out]selectorObject that shall be bound to the given event
[in]typeEvent type the selector is interested in
[in]fd_indexOpaque value, to be passed to rtdm_event_select_bind or rtdm_sem_select_bind unmodfied
Returns
0 on success. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
typedef ssize_t(* rtdm_sendmsg_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, const struct user_msghdr *msg, int flags)

Transmit message handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in]msgMessage descriptor as passed by the user, automatically mirrored to safe kernel memory in case of user mode call
[in]flagsMessage flags as passed by the user
Returns
On success, the number of bytes transmitted. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
sendmsg() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef int(* rtdm_socket_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int protocol)

Socket creation handler for protocol devices.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in]protocolProtocol number as passed by the user
Returns
0 on success. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
socket() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399
typedef ssize_t(* rtdm_write_handler_t) (struct rtdm_dev_context *context, rtdm_user_info_t *user_info, const void *buf, size_t nbyte)

Write handler.

Parameters
[in]contextContext structure associated with opened device instance
[in]user_infoOpaque pointer to information about user mode caller, NULL if kernel mode call
[in]bufOutput buffer as passed by the user
[in]nbyteNumber of bytes the user requests to write
Returns
On success, the number of bytes written. On failure return either -ENOSYS, to request that this handler be called again from the opposite realtime/non-realtime context, or another negative error code.
See also
write() in IEEE Std 1003.1, http://www.opengroup.org/onlinepubs/009695399

Function Documentation

static void* rtdm_context_to_private ( struct rtdm_dev_context context)
inlinestatic

Locate the driver private area associated to a device context structure.

Parameters
[in]contextContext structure associated with opened device instance
Returns
The address of the private driver area associated to context.

References rtdm_dev_context::dev_private.

int rtdm_dev_register ( struct rtdm_device device)

Register a RTDM device.

Parameters
[in]devicePointer to structure describing the new device.
Returns
0 is returned upon success. Otherwise:
  • -EINVAL is returned if the device structure contains invalid entries. Check kernel log in this case.
  • -ENOMEM is returned if the context for an exclusive device cannot be allocated.
  • -EEXIST is returned if the specified device name of protocol ID is already in use.
  • -EAGAIN is returned if some /proc entry cannot be created.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code

Rescheduling: never.

References rtdm_operations::close_nrt, rtdm_operations::close_rt, rtdm_device::context_size, rtdm_device::device_class, rtdm_device::device_flags, rtdm_device::device_name, rtdm_device::device_sub_class, rtdm_device::driver_version, rtdm_device::open_rt, rtdm_device::ops, rtdm_device::proc_name, rtdm_device::profile_version, rtdm_device::protocol_family, rtdm_device::reserved, RTDM_DEVICE_STRUCT_VER, RTDM_DEVICE_TYPE_MASK, RTDM_EXCLUSIVE, RTDM_NAMED_DEVICE, RTDM_PROTOCOL_DEVICE, rtdm_operations::select_bind, rtdm_device::socket_rt, rtdm_device::socket_type, and rtdm_device::struct_version.

int rtdm_dev_unregister ( struct rtdm_device device,
unsigned int  poll_delay 
)

Unregisters a RTDM device.

Parameters
[in]devicePointer to structure describing the device to be unregistered.
[in]poll_delayPolling delay in milliseconds to check repeatedly for open instances of device, or 0 for non-blocking mode.
Returns
0 is returned upon success. Otherwise:
  • -ENODEV is returned if the device was not registered.
  • -EAGAIN is returned if the device is busy with open instances and 0 has been passed for poll_delay.

Environments:

This service can be called from:

  • Kernel module initialization/cleanup code

Rescheduling: never.

References rtdm_device::device_flags, rtdm_device::device_name, rtdm_device::protocol_family, rtdm_device::reserved, RTDM_DEVICE_TYPE_MASK, RTDM_NAMED_DEVICE, and rtdm_device::socket_type.

static struct rtdm_dev_context* rtdm_private_to_context ( void *  dev_private)
static

Locate a device context structure from its driver private area.

Parameters
[in]dev_privateAddress of a private context area
Returns
The address of the device context structure defining dev_private.