[Xenomai-git] Gilles Chanteperdrix : cobalt/rtdm: base named devices on nucleus registry

2014-05-16 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: f5d9edb7f95405311b1e66a3a56cca9fe767007a
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f5d9edb7f95405311b1e66a3a56cca9fe767007a

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Jan 26 23:47:24 2014 +0100

cobalt/rtdm: base named devices on nucleus registry

---

 include/cobalt/kernel/rtdm/driver.h |   12 ++--
 kernel/cobalt/rtdm/device.c |  124 ++-
 kernel/cobalt/rtdm/internal.h   |2 +-
 kernel/cobalt/rtdm/proc.c   |   94 --
 4 files changed, 70 insertions(+), 162 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 27cddcb..0815246 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -447,8 +447,12 @@ rtdm_private_to_context(void *dev_private)
 }
 
 struct rtdm_dev_reserved {
+   unsigned magic;
union {
-   struct list_head entry;
+   struct {
+   struct list_head entry;
+   xnhandle_t handle;
+   };
struct xnid id;
};
atomic_t refcount;
@@ -463,6 +467,9 @@ struct rtdm_dev_reserved {
  * not reside in write-protected memory.
  */
 struct rtdm_device {
+   /** Data stored by RTDM inside a registered device (internal use only) 
*/
+   struct rtdm_dev_reserved reserved;
+
/** Revision number of this structure, see
 *  @ref drv_versioning Driver Versioning defines */
int struct_version;
@@ -531,9 +538,6 @@ struct rtdm_device {
int device_id;
/** Driver definable device data */
void *device_data;
-
-   /** Data stored by RTDM inside a registered device (internal use only) 
*/
-   struct rtdm_dev_reserved reserved;
 };
 /** @} devregister */
 
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index e6d7bfe..2a9dd82 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -32,6 +32,8 @@
 #include rtdm/internal.h
 #include trace/events/cobalt-rtdm.h
 
+#define RTDM_DEVICE_MAGIC  0x82846877
+
 #define SET_DEFAULT_OP(device, operation)  \
(device).operation##_rt  = (void *)rtdm_no_support; \
(device).operation##_nrt = (void *)rtdm_no_support
@@ -45,13 +47,7 @@
 #define ANY_HANDLER(device, operation) \
((device).operation##_rt || (device).operation##_nrt)
 
-unsigned int devname_hashtab_size = DEF_DEVNAME_HASHTAB_SIZE;
-module_param(devname_hashtab_size, uint, 0400);
-MODULE_PARM_DESC(devname_hashtab_size,
-Size of hash table for named devices (must be power of 2));
-
-struct list_head *rtdm_named_devices;  /* hash table */
-static int name_hashkey_mask;
+struct list_head rtdm_named_devices;   /* hash table */
 struct rb_root rtdm_protocol_devices;
 
 int rtdm_apc;
@@ -75,18 +71,6 @@ int rtdm_select_bind_no_support(struct rtdm_dev_context 
*context,
return -EBADF;
 }
 
-static inline int get_name_hash(const char *str, int limit, int hashkey_mask)
-{
-   int hash = 0;
-
-   while (*str != 0) {
-   hash += *str++;
-   if (--limit == 0)
-   break;
-   }
-   return hash  hashkey_mask;
-}
-
 static inline unsigned long long get_proto_id(int pf, int type)
 {
unsigned long long llpf = (unsigned)pf;
@@ -100,30 +84,28 @@ static inline void rtdm_reference_device(struct 
rtdm_device *device)
 
 struct rtdm_device *get_named_device(const char *name)
 {
-   struct list_head *entry;
struct rtdm_device *device;
-   int hashkey;
+   xnhandle_t handle;
+   int err;
spl_t s;
 
-   hashkey = get_name_hash(name, RTDM_MAX_DEVNAME_LEN, name_hashkey_mask);
+   err = xnregistry_bind(name, XN_NONBLOCK, XN_RELATIVE, handle);
+   if (err == -EWOULDBLOCK)
+   return NULL;
 
xnlock_get_irqsave(rt_dev_lock, s);
 
-   list_for_each(entry, rtdm_named_devices[hashkey]) {
-   device = list_entry(entry, struct rtdm_device, reserved.entry);
-
-   if (strcmp(name, device-device_name) == 0) {
+   device = xnregistry_lookup(handle, NULL);
+   if (device) {
+   if (device-reserved.magic != RTDM_DEVICE_MAGIC)
+   device = NULL;
+   else
rtdm_reference_device(device);
-
-   xnlock_put_irqrestore(rt_dev_lock, s);
-
-   return device;
-   }
}
 
xnlock_put_irqrestore(rt_dev_lock, s);
 
-   return NULL;
+   return device;
 }
 
 struct rtdm_device *get_protocol_device(int protocol_family, int socket_type)
@@ -185,10 +167,7 @@ struct rtdm_device *get_protocol_device(int 
protocol_family, int socket_type)
 int rtdm_dev_register(struct rtdm_device *device)

[Xenomai-git] Gilles Chanteperdrix : cobalt/rtdm: base named devices on nucleus registry

2014-05-16 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: f5d9edb7f95405311b1e66a3a56cca9fe767007a
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=f5d9edb7f95405311b1e66a3a56cca9fe767007a

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Jan 26 23:47:24 2014 +0100

cobalt/rtdm: base named devices on nucleus registry

---

 include/cobalt/kernel/rtdm/driver.h |   12 ++--
 kernel/cobalt/rtdm/device.c |  124 ++-
 kernel/cobalt/rtdm/internal.h   |2 +-
 kernel/cobalt/rtdm/proc.c   |   94 --
 4 files changed, 70 insertions(+), 162 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 27cddcb..0815246 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -447,8 +447,12 @@ rtdm_private_to_context(void *dev_private)
 }
 
 struct rtdm_dev_reserved {
+   unsigned magic;
union {
-   struct list_head entry;
+   struct {
+   struct list_head entry;
+   xnhandle_t handle;
+   };
struct xnid id;
};
atomic_t refcount;
@@ -463,6 +467,9 @@ struct rtdm_dev_reserved {
  * not reside in write-protected memory.
  */
 struct rtdm_device {
+   /** Data stored by RTDM inside a registered device (internal use only) 
*/
+   struct rtdm_dev_reserved reserved;
+
/** Revision number of this structure, see
 *  @ref drv_versioning Driver Versioning defines */
int struct_version;
@@ -531,9 +538,6 @@ struct rtdm_device {
int device_id;
/** Driver definable device data */
void *device_data;
-
-   /** Data stored by RTDM inside a registered device (internal use only) 
*/
-   struct rtdm_dev_reserved reserved;
 };
 /** @} devregister */
 
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index e6d7bfe..2a9dd82 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -32,6 +32,8 @@
 #include rtdm/internal.h
 #include trace/events/cobalt-rtdm.h
 
+#define RTDM_DEVICE_MAGIC  0x82846877
+
 #define SET_DEFAULT_OP(device, operation)  \
(device).operation##_rt  = (void *)rtdm_no_support; \
(device).operation##_nrt = (void *)rtdm_no_support
@@ -45,13 +47,7 @@
 #define ANY_HANDLER(device, operation) \
((device).operation##_rt || (device).operation##_nrt)
 
-unsigned int devname_hashtab_size = DEF_DEVNAME_HASHTAB_SIZE;
-module_param(devname_hashtab_size, uint, 0400);
-MODULE_PARM_DESC(devname_hashtab_size,
-Size of hash table for named devices (must be power of 2));
-
-struct list_head *rtdm_named_devices;  /* hash table */
-static int name_hashkey_mask;
+struct list_head rtdm_named_devices;   /* hash table */
 struct rb_root rtdm_protocol_devices;
 
 int rtdm_apc;
@@ -75,18 +71,6 @@ int rtdm_select_bind_no_support(struct rtdm_dev_context 
*context,
return -EBADF;
 }
 
-static inline int get_name_hash(const char *str, int limit, int hashkey_mask)
-{
-   int hash = 0;
-
-   while (*str != 0) {
-   hash += *str++;
-   if (--limit == 0)
-   break;
-   }
-   return hash  hashkey_mask;
-}
-
 static inline unsigned long long get_proto_id(int pf, int type)
 {
unsigned long long llpf = (unsigned)pf;
@@ -100,30 +84,28 @@ static inline void rtdm_reference_device(struct 
rtdm_device *device)
 
 struct rtdm_device *get_named_device(const char *name)
 {
-   struct list_head *entry;
struct rtdm_device *device;
-   int hashkey;
+   xnhandle_t handle;
+   int err;
spl_t s;
 
-   hashkey = get_name_hash(name, RTDM_MAX_DEVNAME_LEN, name_hashkey_mask);
+   err = xnregistry_bind(name, XN_NONBLOCK, XN_RELATIVE, handle);
+   if (err == -EWOULDBLOCK)
+   return NULL;
 
xnlock_get_irqsave(rt_dev_lock, s);
 
-   list_for_each(entry, rtdm_named_devices[hashkey]) {
-   device = list_entry(entry, struct rtdm_device, reserved.entry);
-
-   if (strcmp(name, device-device_name) == 0) {
+   device = xnregistry_lookup(handle, NULL);
+   if (device) {
+   if (device-reserved.magic != RTDM_DEVICE_MAGIC)
+   device = NULL;
+   else
rtdm_reference_device(device);
-
-   xnlock_put_irqrestore(rt_dev_lock, s);
-
-   return device;
-   }
}
 
xnlock_put_irqrestore(rt_dev_lock, s);
 
-   return NULL;
+   return device;
 }
 
 struct rtdm_device *get_protocol_device(int protocol_family, int socket_type)
@@ -185,10 +167,7 @@ struct rtdm_device *get_protocol_device(int 
protocol_family, int socket_type)
 int rtdm_dev_register(struct rtdm_device 

[Xenomai-git] Gilles Chanteperdrix : cobalt/rtdm: base named devices on nucleus registry

2014-02-10 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 010d8a8c78f16e3d8f81e9d57741b9abeb50a401
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=010d8a8c78f16e3d8f81e9d57741b9abeb50a401

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Jan 26 23:47:24 2014 +0100

cobalt/rtdm: base named devices on nucleus registry

---

 include/cobalt/kernel/rtdm/driver.h |6 +-
 kernel/cobalt/rtdm/device.c |  115 +++
 kernel/cobalt/rtdm/internal.h   |2 +-
 kernel/cobalt/rtdm/proc.c   |   94 
 4 files changed, 66 insertions(+), 151 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 881f517..1fe74e6 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -445,7 +445,10 @@ rtdm_private_to_context(void *dev_private)
 
 struct rtdm_dev_reserved {
union {
-   struct list_head entry;
+   struct {
+   struct list_head entry;
+   xnhandle_t handle;
+   };
struct xnid id;
};
atomic_t refcount;
@@ -460,6 +463,7 @@ struct rtdm_dev_reserved {
  * not reside in write-protected memory.
  */
 struct rtdm_device {
+   unsigned magic;
/** Revision number of this structure, see
 *  @ref drv_versioning Driver Versioning defines */
int struct_version;
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 38353ee..aca34f7 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -31,6 +31,8 @@
 #include cobalt/kernel/apc.h
 #include rtdm/internal.h
 
+#define RTDM_DEVICE_MAGIC  0x82846877
+
 #define SET_DEFAULT_OP(device, operation)  \
(device).operation##_rt  = (void *)rtdm_no_support; \
(device).operation##_nrt = (void *)rtdm_no_support
@@ -44,13 +46,7 @@
 #define ANY_HANDLER(device, operation) \
((device).operation##_rt || (device).operation##_nrt)
 
-unsigned int devname_hashtab_size = DEF_DEVNAME_HASHTAB_SIZE;
-module_param(devname_hashtab_size, uint, 0400);
-MODULE_PARM_DESC(devname_hashtab_size,
-Size of hash table for named devices (must be power of 2));
-
-struct list_head *rtdm_named_devices;  /* hash table */
-static int name_hashkey_mask;
+struct list_head rtdm_named_devices;   /* hash table */
 struct rb_root rtdm_protocol_devices;
 
 int rtdm_apc;
@@ -74,18 +70,6 @@ int rtdm_select_bind_no_support(struct rtdm_dev_context 
*context,
return -EBADF;
 }
 
-static inline int get_name_hash(const char *str, int limit, int hashkey_mask)
-{
-   int hash = 0;
-
-   while (*str != 0) {
-   hash += *str++;
-   if (--limit == 0)
-   break;
-   }
-   return hash  hashkey_mask;
-}
-
 static inline unsigned long long get_proto_id(int pf, int type)
 {
unsigned long long llpf = (unsigned)pf;
@@ -99,30 +83,28 @@ static inline void rtdm_reference_device(struct rtdm_device 
*device)
 
 struct rtdm_device *get_named_device(const char *name)
 {
-   struct list_head *entry;
struct rtdm_device *device;
-   int hashkey;
+   xnhandle_t handle;
+   int err;
spl_t s;
 
-   hashkey = get_name_hash(name, RTDM_MAX_DEVNAME_LEN, name_hashkey_mask);
+   err = xnregistry_bind(name, XN_NONBLOCK, XN_RELATIVE, handle);
+   if (err == -EWOULDBLOCK)
+   return NULL;
 
xnlock_get_irqsave(rt_dev_lock, s);
 
-   list_for_each(entry, rtdm_named_devices[hashkey]) {
-   device = list_entry(entry, struct rtdm_device, reserved.entry);
-
-   if (strcmp(name, device-device_name) == 0) {
+   device = xnregistry_fetch(handle);
+   if (device) {
+   if (device-magic != RTDM_DEVICE_MAGIC)
+   device = NULL;
+   else
rtdm_reference_device(device);
-
-   xnlock_put_irqrestore(rt_dev_lock, s);
-
-   return device;
-   }
}
 
xnlock_put_irqrestore(rt_dev_lock, s);
 
-   return NULL;
+   return device;
 }
 
 struct rtdm_device *get_protocol_device(int protocol_family, int socket_type)
@@ -184,10 +166,7 @@ struct rtdm_device *get_protocol_device(int 
protocol_family, int socket_type)
 int rtdm_dev_register(struct rtdm_device *device)
 {
unsigned long long id;
-   int hashkey;
spl_t s;
-   struct list_head *entry;
-   struct rtdm_device *existing_dev;
int ret;
 
/* Catch unsuccessful initialisation */
@@ -281,6 +260,8 @@ int rtdm_dev_register(struct rtdm_device *device)
 
down(nrt_dev_lock);
 
+   device-magic = RTDM_DEVICE_MAGIC;
+
if ((device-device_flags  RTDM_DEVICE_TYPE_MASK) == 
RTDM_NAMED_DEVICE) {

[Xenomai-git] Gilles Chanteperdrix : cobalt/rtdm: base named devices on nucleus registry

2014-02-04 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 8e016c952c8d3495493944addc777504630deb94
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=8e016c952c8d3495493944addc777504630deb94

Author: Gilles Chanteperdrix gilles.chanteperd...@xenomai.org
Date:   Sun Jan 26 23:47:24 2014 +0100

cobalt/rtdm: base named devices on nucleus registry

---

 include/cobalt/kernel/rtdm/driver.h |6 +-
 kernel/cobalt/rtdm/device.c |  115 +++
 kernel/cobalt/rtdm/internal.h   |2 +-
 kernel/cobalt/rtdm/proc.c   |   94 
 4 files changed, 66 insertions(+), 151 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 881f517..1fe74e6 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -445,7 +445,10 @@ rtdm_private_to_context(void *dev_private)
 
 struct rtdm_dev_reserved {
union {
-   struct list_head entry;
+   struct {
+   struct list_head entry;
+   xnhandle_t handle;
+   };
struct xnid id;
};
atomic_t refcount;
@@ -460,6 +463,7 @@ struct rtdm_dev_reserved {
  * not reside in write-protected memory.
  */
 struct rtdm_device {
+   unsigned magic;
/** Revision number of this structure, see
 *  @ref drv_versioning Driver Versioning defines */
int struct_version;
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 38353ee..aca34f7 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -31,6 +31,8 @@
 #include cobalt/kernel/apc.h
 #include rtdm/internal.h
 
+#define RTDM_DEVICE_MAGIC  0x82846877
+
 #define SET_DEFAULT_OP(device, operation)  \
(device).operation##_rt  = (void *)rtdm_no_support; \
(device).operation##_nrt = (void *)rtdm_no_support
@@ -44,13 +46,7 @@
 #define ANY_HANDLER(device, operation) \
((device).operation##_rt || (device).operation##_nrt)
 
-unsigned int devname_hashtab_size = DEF_DEVNAME_HASHTAB_SIZE;
-module_param(devname_hashtab_size, uint, 0400);
-MODULE_PARM_DESC(devname_hashtab_size,
-Size of hash table for named devices (must be power of 2));
-
-struct list_head *rtdm_named_devices;  /* hash table */
-static int name_hashkey_mask;
+struct list_head rtdm_named_devices;   /* hash table */
 struct rb_root rtdm_protocol_devices;
 
 int rtdm_apc;
@@ -74,18 +70,6 @@ int rtdm_select_bind_no_support(struct rtdm_dev_context 
*context,
return -EBADF;
 }
 
-static inline int get_name_hash(const char *str, int limit, int hashkey_mask)
-{
-   int hash = 0;
-
-   while (*str != 0) {
-   hash += *str++;
-   if (--limit == 0)
-   break;
-   }
-   return hash  hashkey_mask;
-}
-
 static inline unsigned long long get_proto_id(int pf, int type)
 {
unsigned long long llpf = (unsigned)pf;
@@ -99,30 +83,28 @@ static inline void rtdm_reference_device(struct rtdm_device 
*device)
 
 struct rtdm_device *get_named_device(const char *name)
 {
-   struct list_head *entry;
struct rtdm_device *device;
-   int hashkey;
+   xnhandle_t handle;
+   int err;
spl_t s;
 
-   hashkey = get_name_hash(name, RTDM_MAX_DEVNAME_LEN, name_hashkey_mask);
+   err = xnregistry_bind(name, XN_NONBLOCK, XN_RELATIVE, handle);
+   if (err == -EWOULDBLOCK)
+   return NULL;
 
xnlock_get_irqsave(rt_dev_lock, s);
 
-   list_for_each(entry, rtdm_named_devices[hashkey]) {
-   device = list_entry(entry, struct rtdm_device, reserved.entry);
-
-   if (strcmp(name, device-device_name) == 0) {
+   device = xnregistry_fetch(handle);
+   if (device) {
+   if (device-magic != RTDM_DEVICE_MAGIC)
+   device = NULL;
+   else
rtdm_reference_device(device);
-
-   xnlock_put_irqrestore(rt_dev_lock, s);
-
-   return device;
-   }
}
 
xnlock_put_irqrestore(rt_dev_lock, s);
 
-   return NULL;
+   return device;
 }
 
 struct rtdm_device *get_protocol_device(int protocol_family, int socket_type)
@@ -184,10 +166,7 @@ struct rtdm_device *get_protocol_device(int 
protocol_family, int socket_type)
 int rtdm_dev_register(struct rtdm_device *device)
 {
unsigned long long id;
-   int hashkey;
spl_t s;
-   struct list_head *entry;
-   struct rtdm_device *existing_dev;
int ret;
 
/* Catch unsuccessful initialisation */
@@ -281,6 +260,8 @@ int rtdm_dev_register(struct rtdm_device *device)
 
down(nrt_dev_lock);
 
+   device-magic = RTDM_DEVICE_MAGIC;
+
if ((device-device_flags  RTDM_DEVICE_TYPE_MASK) == 
RTDM_NAMED_DEVICE) {