All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Stelian Pop <stelian.pop@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-core] 	[PATCH, RFC] Make ioremap'ed memory available through	rtdm_mmap_to_user()
Date: Tue, 19 Sep 2006 17:34:14 +0200	[thread overview]
Message-ID: <45100DF6.8030209@domain.hid> (raw)
In-Reply-To: <1158613987.31164.9.camel@domain.hid>


[-- Attachment #1.1: Type: text/plain, Size: 1237 bytes --]

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

[-- Attachment #1.2: rtdm-mmap-ioremap.patch --]
[-- Type: text/plain, Size: 3420 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

  reply	other threads:[~2006-09-19 15:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-15 16:26 [Xenomai-core] [PATCH, RFC] Make ioremap'ed memory available through rtdm_mmap_to_user() Stelian Pop
2006-09-15 16:40 ` Jan Kiszka
2006-09-18 21:13   ` Stelian Pop
2006-09-19 15:34     ` Jan Kiszka [this message]
2006-09-22  8:35       ` Stelian Pop
2006-09-22  8:58         ` Jan Kiszka
2006-09-22 11:34           ` Stelian Pop
2006-09-22 14:41             ` Jan Kiszka
2006-09-22 14:53               ` Stelian Pop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45100DF6.8030209@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=stelian.pop@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.