This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9d6e2b97fbd1747e646bd88a1ea30136698936bf
Author: Yanfeng Liu <[email protected]>
AuthorDate: Sun May 5 08:04:47 2024 +0800

    video/fb: add munmap support
    
    This adds support to user-space munmap() requests in kernel build.
    
    Signed-off-by: Yanfeng Liu <[email protected]>
---
 drivers/video/fb.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 456607ac00..a0a1df78fa 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -135,6 +135,12 @@ static int     fb_sem_wait(FAR struct fb_chardev_s *fb,
 static void    fb_sem_post(FAR struct fb_chardev_s *fb, int overlay);
 #endif
 
+#ifdef CONFIG_BUILD_KERNEL
+static int     fb_munmap(FAR struct task_group_s *group,
+                         FAR struct mm_map_entry_s *entry,
+                         FAR void *start, size_t length);
+#endif
+
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -1002,6 +1008,22 @@ static int fb_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
   return ret;
 }
 
+#ifdef CONFIG_BUILD_KERNEL
+static int fb_munmap(FAR struct task_group_s *group,
+                     FAR struct mm_map_entry_s *entry,
+                     FAR void *start, size_t length)
+{
+  if (group && entry)
+    {
+      ginfo("%p, len=%zu\n", entry->vaddr, entry->length);
+      vm_unmap_region(entry->vaddr, entry->length);
+      mm_map_remove(get_current_mm(), entry);
+    }
+
+  return OK;
+}
+#endif
+
 static int fb_mmap(FAR struct file *filep, FAR struct mm_map_entry_s *map)
 {
   FAR struct inode *inode;
@@ -1035,6 +1057,9 @@ static int fb_mmap(FAR struct file *filep, FAR struct 
mm_map_entry_s *map)
 #ifdef CONFIG_BUILD_KERNEL
       map->vaddr = vm_map_region((uintptr_t)panelinfo.fbmem + map->offset,
                                  panelinfo.fblen);
+      map->length = panelinfo.fblen;
+      map->munmap = fb_munmap;
+      mm_map_add(get_current_mm(), map);
 #else
       map->vaddr = (FAR char *)panelinfo.fbmem + map->offset;
 #endif

Reply via email to