Stelian Pop wrote:
> Le vendredi 15 septembre 2006 à 18:40 +0200, Jan Kiszka a écrit :
> 
>> In case no one comes up with an easy, portable way to detect remapped
>> memory as well: What about some flags the caller of rtdm_mmap_to_user
>> has to pass, telling what kind of memory it is? Would simplify the RTDM
>> part, and the user normally knows quite well where the memory came from.
>> And I love to break APIs. :)
> 
> This would be perfect. We could even reuse the prot field for that
> (PROT_READ | PROT_WRITE | PROT_VMALLOC | PROT_IOREMAP). Not the cleanest
> solution, but it won't break the API this way.

It would not change the function signature, but its argument semantics.
We should better make a clean cut which signals via compiler errors that
something changed.

> 
> Or maybe we should lower the API level a little bit, and let the user
> specify the physical address of the mapping instead of the virtual
> one....

How would this help? You still need the virtual address for VMA blocks
in order to collect the pages.

I really think a separate mem-type argument is what we should do. And
here comes a first patch in this direction. Only compile-tested so far,
feedback is welcome.

Jan
Index: include/rtdm/rtdm_driver.h
===================================================================
--- include/rtdm/rtdm_driver.h  (revision 1648)
+++ include/rtdm/rtdm_driver.h  (working copy)
@@ -1021,6 +1021,25 @@ int rtdm_mutex_timedlock(rtdm_mutex_t *m
 
 /* --- utility functions --- */
 
+/*!
+ * @addtogroup util
+ * @{
+ */
+
+/*!
+ * @anchor RTDM_MEMTYPE_xxx @name Memory Types
+ * Flags defining the type of a memory region
+ * @{
+ */
+/** Allocated with kmalloc() */
+#define RTDM_MEMTYPE_KMALLOC        0x00
+/** Remapped physical memory */
+#define RTDM_MEMTYPE_IOREMAP        0x01
+/** Allocated with vmalloc() */
+#define RTDM_MEMTYPE_VMALLOC        0x02
+/** @} Memory Types */
+/** @} util */
+
 #define rtdm_printk(format, ...)    printk(format, ##__VA_ARGS__)
 
 #ifndef DOXYGEN_CPP /* Avoid static inline tags for RTDM in doxygen */
@@ -1036,7 +1055,7 @@ static inline void rtdm_free(void *ptr)
 
 #ifdef CONFIG_XENO_OPT_PERVASIVE
 int rtdm_mmap_to_user(rtdm_user_info_t *user_info, void *src_addr, size_t len,
-                      int prot, void **pptr,
+                      int mem_type, int prot, void **pptr,
                       struct vm_operations_struct *vm_ops,
                       void *vm_private_data);
 int rtdm_munmap(rtdm_user_info_t *user_info, void *ptr, size_t len);
Index: ksrc/skins/rtdm/drvlib.c
===================================================================
--- ksrc/skins/rtdm/drvlib.c    (revision 1648)
+++ ksrc/skins/rtdm/drvlib.c    (working copy)
@@ -1369,6 +1369,7 @@ void rtdm_nrtsig_pend(rtdm_nrtsig_t *nrt
 #if defined(CONFIG_XENO_OPT_PERVASIVE) || defined(DOXYGEN_CPP)
 struct rtdm_mmap_data {
     void *src_addr;
+    int mem_type;
     struct vm_operations_struct *vm_ops;
     void *vm_private_data;
 };
@@ -1386,7 +1387,7 @@ static int rtdm_mmap_buffer(struct file 
     size  = vma->vm_end - vma->vm_start;
 
 #ifdef CONFIG_MMU
-    if ((vaddr >= VMALLOC_START) && (vaddr < VMALLOC_END)) {
+    if (mmap_data->mem_type == RTDM_MEMTYPE_VMALLOC) {
         unsigned long mapped_size = 0;
 
         XENO_ASSERT(RTDM, (vaddr == PAGE_ALIGN(vaddr)), return -EINVAL);
@@ -1419,6 +1420,8 @@ static struct file_operations rtdm_mmap_
  * device operation handler
  * @param[in] src_addr Kernel address to be mapped
  * @param[in] len Length of the memory range
+ * @param[in] mem_type Type of the passed memory range, see
+ * @ref RTDM_MEMTYPE_xxx
  * @param[in] prot Protection flags for the user's memory range, typically
  * either PROT_READ or PROT_READ|PROT_WRITE
  * @param[in,out] pptr Address of a pointer containing the desired user
@@ -1463,11 +1466,12 @@ static struct file_operations rtdm_mmap_
  * Rescheduling: possible.
  */
 int rtdm_mmap_to_user(rtdm_user_info_t *user_info, void *src_addr, size_t len,
-                      int prot, void **pptr,
+                      int mem_type, int prot, void **pptr,
                       struct vm_operations_struct *vm_ops,
                       void *vm_private_data)
 {
-    struct rtdm_mmap_data   mmap_data = {src_addr, vm_ops, vm_private_data};
+    struct rtdm_mmap_data   mmap_data = { src_addr, mem_type, vm_ops,
+                                          vm_private_data };
     struct file             *filp;
     const struct file_operations    *old_fops;
     void                    *old_priv_data;

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to