media: atomisp: get rid of the hrt/hive_isp_css_mm_hrt abstraction layer
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 25 May 2020 08:53:20 +0000 (10:53 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 11 Jun 2020 16:03:43 +0000 (18:03 +0200)
Simplify the code by removing this extra memory management
abstraction layer.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
14 files changed:
drivers/staging/media/atomisp/Makefile
drivers/staging/media/atomisp/pci/atomisp_acc.c
drivers/staging/media/atomisp/pci/atomisp_cmd.c
drivers/staging/media/atomisp/pci/atomisp_compat.h
drivers/staging/media/atomisp/pci/atomisp_compat_css20.c
drivers/staging/media/atomisp/pci/atomisp_fops.c
drivers/staging/media/atomisp/pci/atomisp_ioctl.c
drivers/staging/media/atomisp/pci/atomisp_v4l2.c
drivers/staging/media/atomisp/pci/hive_isp_css_include/memory_access/memory_access.h
drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.c [deleted file]
drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.h [deleted file]
drivers/staging/media/atomisp/pci/ia_css_frame_public.h
drivers/staging/media/atomisp/pci/ia_css_memory_access.c
drivers/staging/media/atomisp/pci/runtime/frame/src/frame.c

index b48eb7946a58646fbfd502e3b9993dcea07f8795..889227dcebfe06b0c03b0d480c31f7d048b7891e 100644 (file)
@@ -53,7 +53,6 @@ atomisp-objs += \
        pci/hmm/hmm_dynamic_pool.o \
        pci/hmm/hmm.o \
        pci/hmm/hmm_reserved_pool.o \
-       pci/hrt/hive_isp_css_mm_hrt.o \
        pci/ia_css_device_access.o \
        pci/ia_css_memory_access.o \
        pci/isp/kernels/aa/aa_2/ia_css_aa2.host.o \
index bb1f60fab786edf0507c47ec1fd40357e23ce577..5e7f4cd47c8f26cfd0bba61f85032dcbcf5299ec 100644 (file)
@@ -28,7 +28,6 @@
 #include "atomisp_compat.h"
 #include "atomisp_cmd.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
 #include "memory_access/memory_access.h"
 #include "ia_css.h"
 
@@ -353,16 +352,23 @@ int atomisp_acc_map(struct atomisp_sub_device *asd, struct atomisp_acc_map *map)
                }
 
                pgnr = DIV_ROUND_UP(map->length, PAGE_SIZE);
-               cssptr = hrt_isp_css_mm_alloc_user_ptr(map->length,
-                                                      map->user_ptr,
-                                                      pgnr,
-                                                      (map->flags & ATOMISP_MAP_FLAG_CACHED));
+               if (pgnr < ((PAGE_ALIGN(map->length)) >> PAGE_SHIFT)) {
+                       dev_err(atomisp_dev,
+                               "user space memory size is less than the expected size..\n");
+                       return -ENOMEM;
+               } else if (pgnr > ((PAGE_ALIGN(map->length)) >> PAGE_SHIFT)) {
+                       dev_err(atomisp_dev,
+                               "user space memory size is large than the expected size..\n");
+                       return -ENOMEM;
+               }
+
+               cssptr = hmm_alloc(map->length, HMM_BO_USER, 0, map->user_ptr,
+                                  map->flags & ATOMISP_MAP_FLAG_CACHED);
+
        } else {
                /* Allocate private buffer. */
-               if (map->flags & ATOMISP_MAP_FLAG_CACHED)
-                       cssptr = hrt_isp_css_mm_calloc_cached(map->length);
-               else
-                       cssptr = hrt_isp_css_mm_calloc(map->length);
+               cssptr = hmm_alloc(map->length, HMM_BO_PRIVATE, 0, NULL,
+                                  map->flags & ATOMISP_MAP_FLAG_CACHED);
        }
 
        if (!cssptr)
index 900f1ccc25fe153c29a69993f197acc9967567fd..4913469df2bbd5ee74c259bf5e7d6a7d6baaddb9 100644 (file)
@@ -44,7 +44,7 @@
 #include "atomisp_subdev.h"
 #include "atomisp_dfs_tables.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
+#include <hmm/hmm.h>
 
 #include "sh_css_hrt.h"
 #include "sh_css_defs.h"
index 8847e104bb6577f106ce84978859ae173c36791e..8693f228a875f57e19cf63c7e01477972269032d 100644 (file)
@@ -261,7 +261,7 @@ void atomisp_css_frame_free(struct ia_css_frame *frame);
 int atomisp_css_frame_map(struct ia_css_frame **frame,
                          const struct ia_css_frame_info *info,
                          const void __user *data, uint16_t attribute,
-                         void *context);
+                         unsigned int pgnr);
 
 int atomisp_css_set_black_frame(struct atomisp_sub_device *asd,
                                const struct ia_css_frame *raw_black_frame);
index 06aba734194a150c357214860de67cba2a63c76d..c2d6eae7e214f3857bb8ce8402c9614e170f676a 100644 (file)
@@ -32,8 +32,6 @@
 #include "atomisp_ioctl.h"
 #include "atomisp_acc.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
-
 #include <asm/intel-mid.h>
 
 #include "ia_css_debug.h"
@@ -2187,9 +2185,9 @@ void atomisp_css_frame_free(struct ia_css_frame *frame)
 int atomisp_css_frame_map(struct ia_css_frame **frame,
                          const struct ia_css_frame_info *info,
                          const void __user *data, uint16_t attribute,
-                         void *context)
+                         unsigned int pgnr)
 {
-       if (ia_css_frame_map(frame, info, data, attribute, context)
+       if (ia_css_frame_map(frame, info, data, attribute, pgnr)
            != IA_CSS_SUCCESS)
                return -ENOMEM;
 
index 0ed1142e69fcabcd0b48a2598c0c918066693720..fc3043bded4631b887b30be5c36efb1f1a4ed37b 100644 (file)
@@ -34,8 +34,6 @@
 #include "atomisp-regs.h"
 #include "hmm/hmm.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
-
 #include "type_support.h"
 #include "device_access/device_access.h"
 #include "memory_access/memory_access.h"
index 8aea90ecd50850671cb86a03f874f11ec7c717ee..8783d4b59f6da0d94c7e55770c8488f211970361 100644 (file)
@@ -39,8 +39,6 @@
 #include "device_access.h"
 #include "irq.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
-
 static const char *DRIVER = "atomisp"; /* max size 15 */
 static const char *CARD = "ATOM ISP";  /* max size 31 */
 
@@ -1183,8 +1181,6 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
         * address and reprograme out page table properly
         */
        if (buf->memory == V4L2_MEMORY_USERPTR) {
-               struct hrt_userbuffer_attr attributes;
-
                vb = pipe->capq.bufs[buf->index];
                vm_mem = vb->priv;
                if (!vm_mem) {
@@ -1204,10 +1200,9 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
                        goto error;
                }
 
-               attributes.pgnr = pgnr;
                ret = atomisp_css_frame_map(&handle, &frame_info,
                                            (void __user *)buf->m.userptr,
-                                           0, &attributes);
+                                           0, pgnr);
                if (ret) {
                        dev_err(isp->dev, "Failed to map user buffer\n");
                        goto error;
index 5dc84c45965ce62a5a9e3535bc6effde5377e18b..d795fe49130ca3b3b07f55cc62ffa7d594fb3ba7 100644 (file)
@@ -42,8 +42,6 @@
 #include "hmm/hmm.h"
 #include "atomisp_trace_event.h"
 
-#include "hrt/hive_isp_css_mm_hrt.h"
-
 #include "device_access.h"
 
 /* Timeouts to wait for all subdevs to be registered */
index dc63ff0c9c6aee00bf9249fd8e208e4cc52c0e68..cdba741dfdf2ea03b2e09a0f83a2d49d07d6f290 100644 (file)
@@ -140,7 +140,7 @@ hrt_vaddress mmgr_mmap(
     const void __user *ptr,
     const size_t size,
     u16 attribute,
-    void *context);
+    unsigned int pgnr);
 
 /*! Zero initialise an allocation in memory
 
diff --git a/drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.c b/drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.c
deleted file mode 100644 (file)
index 14e02fd..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Support for Medifield PNW Camera Imaging ISP subsystem.
- *
- * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
- *
- * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- *
- */
-
-#include "atomisp_internal.h"
-
-#include "hive_isp_css_mm_hrt.h"
-#include "hmm/hmm.h"
-
-#define __page_align(size)     (((size) + (PAGE_SIZE - 1)) & (~(PAGE_SIZE - 1)))
-
-ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes)
-{
-       return hmm_alloc(bytes, HMM_BO_PRIVATE, 0, NULL, false);
-}
-
-ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes,
-       const void __user *userptr,
-       unsigned int num_pages,
-       bool cached)
-{
-       if (num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
-               dev_err(atomisp_dev,
-                       "user space memory size is less than the expected size..\n");
-       else if (num_pages > ((__page_align(bytes))
-                               >> PAGE_SHIFT))
-               dev_err(atomisp_dev,
-                       "user space memory size is large than the expected size..\n");
-
-       return hmm_alloc(bytes, HMM_BO_USER, 0,
-                           userptr, cached);
-}
-
-ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes)
-{
-       return hmm_alloc(bytes, HMM_BO_PRIVATE, 0, NULL,
-                                HMM_CACHED);
-}
-
-ia_css_ptr hrt_isp_css_mm_calloc(size_t bytes)
-{
-       ia_css_ptr ptr = hrt_isp_css_mm_alloc(bytes);
-
-       if (ptr)
-               hmm_set(ptr, 0, bytes);
-       return ptr;
-}
-
-ia_css_ptr hrt_isp_css_mm_calloc_cached(size_t bytes)
-{
-       ia_css_ptr ptr = hrt_isp_css_mm_alloc_cached(bytes);
-
-       if (ptr)
-               hmm_set(ptr, 0, bytes);
-       return ptr;
-}
diff --git a/drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.h b/drivers/staging/media/atomisp/pci/hrt/hive_isp_css_mm_hrt.h
deleted file mode 100644 (file)
index e4c90c2..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Support for Medfield PNW Camera Imaging ISP subsystem.
- *
- * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
- *
- * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- *
- */
-
-#ifndef _hive_isp_css_mm_hrt_h_
-#define _hive_isp_css_mm_hrt_h_
-
-#include <hmm/hmm.h>
-#include <hrt/hive_isp_css_custom_host_hrt.h>
-
-#define HRT_BUF_FLAG_CACHED BIT(0)
-
-struct hrt_userbuffer_attr {
-       unsigned int            pgnr;
-};
-
-/* Allocate memory, returns a virtual address */
-ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes);
-ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes,
-       const void __user *userptr,
-       unsigned int num_pages,
-       bool cached);
-ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes);
-
-/* allocate memory and initialize with zeros,
-   returns a virtual address */
-ia_css_ptr hrt_isp_css_mm_calloc(size_t bytes);
-ia_css_ptr hrt_isp_css_mm_calloc_cached(size_t bytes);
-
-#endif /* _hive_isp_css_mm_hrt_h_ */
index 69e9143e5418a1843f544fdc9d19da90d9864a74..ac7ed6c2e6fddbe9150f4cf9babc0be8e4a46fcf 100644 (file)
@@ -336,7 +336,7 @@ ia_css_frame_map(struct ia_css_frame **frame,
                 const struct ia_css_frame_info *info,
                 const void __user *data,
                 u16 attribute,
-                void *context);
+                unsigned int pgnr);
 
 /* @brief Unmap a CSS frame structure.
  *
index 6084d54acac3e034f11d7e9e4087d1764f2721c4..ae9d453aed00e501be06d214eacdc8bde3256122 100644 (file)
@@ -17,7 +17,8 @@
 #include <assert_support.h>
 #include <memory_access.h>
 #include <ia_css_env.h>
-#include <hrt/hive_isp_css_mm_hrt.h>
+
+#include "atomisp_internal.h"
 
 const hrt_vaddress mmgr_NULL = (hrt_vaddress)0;
 const hrt_vaddress mmgr_EXCEPTION = (hrt_vaddress)-1;
@@ -31,20 +32,20 @@ mmgr_malloc(const size_t size)
 hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attrs)
 {
        u16 masked_attrs = attrs & MMGR_ATTRIBUTE_MASK;
+       ia_css_ptr data;
 
        WARN_ON(attrs & MMGR_ATTRIBUTE_CONTIGUOUS);
 
-       if (masked_attrs & MMGR_ATTRIBUTE_CLEARED) {
-               if (masked_attrs & MMGR_ATTRIBUTE_CACHED)
-                       return (ia_css_ptr) hrt_isp_css_mm_calloc_cached(size);
-               else
-                       return (ia_css_ptr) hrt_isp_css_mm_calloc(size);
-       } else {
-               if (masked_attrs & MMGR_ATTRIBUTE_CACHED)
-                       return (ia_css_ptr) hrt_isp_css_mm_alloc_cached(size);
-               else
-                       return (ia_css_ptr) hrt_isp_css_mm_alloc(size);
-       }
+       data = hmm_alloc(size, HMM_BO_PRIVATE, 0, NULL,
+                        masked_attrs & MMGR_ATTRIBUTE_CACHED);
+
+       if (!data)
+               return 0;
+
+       if (masked_attrs & MMGR_ATTRIBUTE_CLEARED)
+               hmm_set(data, 0, size);
+
+       return (ia_css_ptr)data;
 }
 
 hrt_vaddress
@@ -74,11 +75,19 @@ mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size)
 
 hrt_vaddress
 mmgr_mmap(const void __user *ptr, const size_t size,
-         u16 attribute, void *context)
+         u16 attribute, unsigned int pgnr)
 {
-       struct hrt_userbuffer_attr *userbuffer_attr = context;
+       if (pgnr < ((PAGE_ALIGN(size)) >> PAGE_SHIFT)) {
+               dev_err(atomisp_dev,
+                       "user space memory size is less than the expected size..\n");
+               return -ENOMEM;
+       } else if (pgnr > ((PAGE_ALIGN(size)) >> PAGE_SHIFT)) {
+               dev_err(atomisp_dev,
+                       "user space memory size is large than the expected size..\n");
+               return -ENOMEM;
+       }
+
+       return hmm_alloc(size, HMM_BO_USER, 0, ptr,
+                        attribute & MMGR_ATTRIBUTE_CACHED);
 
-       return hrt_isp_css_mm_alloc_user_ptr(
-                  size, ptr, userbuffer_attr->pgnr,
-                  attribute & HRT_BUF_FLAG_CACHED);
 }
index fcd8b06034f28e87087cd1f6eafbe73d8c57439a..0c1e30f2923b168c1a48435a214406c3c592ca1f 100644 (file)
@@ -152,7 +152,7 @@ enum ia_css_err ia_css_frame_map(struct ia_css_frame **frame,
                                 const struct ia_css_frame_info *info,
                                 const void __user *data,
                                 u16 attribute,
-                                void *context)
+                                unsigned int pgnr)
 {
        enum ia_css_err err = IA_CSS_SUCCESS;
        struct ia_css_frame *me;
@@ -169,7 +169,7 @@ enum ia_css_err ia_css_frame_map(struct ia_css_frame **frame,
                /* use mmgr_mmap to map */
                me->data = (ia_css_ptr) mmgr_mmap(data,
                                                  me->data_bytes,
-                                                 attribute, context);
+                                                 attribute, pgnr);
                if (me->data == mmgr_NULL)
                        err = IA_CSS_ERR_INVALID_ARGUMENTS;
        }