Module: xenomai-forge
Branch: next
Commit: 3b243670bf62d27be79b628a85f37740c98471c2
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=3b243670bf62d27be79b628a85f37740c98471c2

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Sep 18 14:56:04 2014 +0200

cobalt/rtdm: allow fixing device minor in description

Some RTDM device creation process could depend on an external
enumeration loop which might advertise devices in pseudo-random order,
at least not by monotonically increasing unit ids.

For these devices, we may still want the hardware unit id to match the
logical minor number though, for the sake of consistency. Passing
RTDM_FIXED_MINOR in the device class flags will cause the value stored
in the rtdm_device.minor field at registration time to be read and
used verbatim.

Otherwise (i.e. flag absent), the RTDM core will automatically assign
minor numbers to devices in order of registration within the class
they belong to, storing the resulting values into this field.

---

 include/cobalt/kernel/rtdm/driver.h |   24 +++++++++++++++++++++++-
 kernel/cobalt/rtdm/core.c           |    5 +----
 kernel/cobalt/rtdm/device.c         |    9 ++++++---
 3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 1366746..0b4a70c 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -70,6 +70,14 @@ enum rtdm_selecttype;
  *  application. */
 #define RTDM_EXCLUSIVE                 0x0001
 
+/**
+ * Use fixed minor provided in the rtdm_device description for
+ * registering. If this flag is absent, the RTDM core assigns minor
+ * numbers to devices in order of registration within the class they
+ * belong to.
+ */
+#define RTDM_FIXED_MINOR               0x0002
+
 /** If set, the device is addressed via a clear-text name. */
 #define RTDM_NAMED_DEVICE              0x0010
 
@@ -308,6 +316,21 @@ struct rtdm_device {
         * hotplug-enabled device filesystems (DEVTMPFS).
         */
        const char *label;
+       /**
+        * Minor number of the device. If RTDM_FIXED_MINOR is present
+        * in the device class flags, the value stored in this field
+        * at registration time is read and used verbatim. Otherwise,
+        * the RTDM core automatically assigns minor numbers to
+        * devices in order of registration within the class they
+        * belong to, storing the resulting values into this field.
+        *
+        * Device nodes created for named devices in the Linux /dev
+        * hierarchy are assigned this minor number.
+        *
+        * The minor number of the current device handling an I/O
+        * request can be retreived by a call to rtdm_fd_minor().
+        */
+       int minor;
        /** Reserved area. */
        struct {
                unsigned int magic;
@@ -316,7 +339,6 @@ struct rtdm_device {
                        struct {
                                struct list_head entry;
                                xnhandle_t handle;
-                               int minor;
                        } named;
                        struct {
                                struct xnid id;
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 3bf9778..4601dad 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -164,10 +164,7 @@ int __rt_dev_open(struct xnsys_ppd *p, int ufd, const char 
*path, int oflag)
                goto cleanup_out;
 
        ufd = ret;
-       if (device->class->device_flags & RTDM_NAMED_DEVICE)
-               context->fd.minor = device->named.minor;
-       else
-               context->fd.minor = 0;
+       context->fd.minor = device->minor;
 
        trace_cobalt_fd_open(current, &context->fd, ufd, oflag);
 
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index a28699f..9825b93 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -275,10 +275,13 @@ int rtdm_dev_register(struct rtdm_device *device)
 
        device->magic = RTDM_DEVICE_MAGIC;
 
+       if (class->device_flags & RTDM_FIXED_MINOR)
+               minor = device->minor;
+       else
+               device->minor = minor = pos;
+
        if (class->device_flags & RTDM_NAMED_DEVICE) {
                major = class->named.major;
-               minor = pos;
-               device->named.minor = minor;
                device->name = kasformat(device->label, minor);
                if (device->name == NULL) {
                        ret = -ENOMEM;
@@ -413,7 +416,7 @@ int rtdm_dev_unregister(struct rtdm_device *device, 
unsigned int poll_delay)
                xnregistry_remove(handle);
                device_destroy(class->named.kclass,
                               MKDEV(class->named.major,
-                                    device->named.minor));
+                                    device->minor));
        }
 
        unregister_device_class(class);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to