diff mbox series

[2/5] drm/gem: Provide drm_gem_fb_{vmap,vunmap}()

Message ID 20210715180133.3675-3-tzimmermann@suse.de (mailing list archive)
State New, archived
Headers show
Series drm: Provide framebuffer vmap helpers | expand

Commit Message

Thomas Zimmermann July 15, 2021, 6:01 p.m. UTC
Move framebuffer vmap code from shadow-buffered plane state into the new
interfaces drm_gem_fb_vmap() and drm_gem_fb_vunmap(). These functions
provide mappings of a framebuffer's BOs into kernel address space. No
functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_gem_atomic_helper.c      | 37 +----------
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 70 ++++++++++++++++++++
 include/drm/drm_gem_atomic_helper.h          |  1 +
 include/drm/drm_gem_framebuffer_helper.h     |  5 ++
 4 files changed, 79 insertions(+), 34 deletions(-)

Comments

kernel test robot July 15, 2021, 10:31 p.m. UTC | #1
Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on 4d00e2309398147acdbfefbe1deb4b0e78868466]

url:    https://github.com/0day-ci/linux/commits/Thomas-Zimmermann/drm-Provide-framebuffer-vmap-helpers/20210716-020508
base:   4d00e2309398147acdbfefbe1deb4b0e78868466
config: nios2-randconfig-s032-20210715 (attached as .config)
compiler: nios2-linux-gcc (GCC) 10.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/8a0708f4cf232e7fbc4eb6f58cf782200be8912e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/drm-Provide-framebuffer-vmap-helpers/20210716-020508
        git checkout 8a0708f4cf232e7fbc4eb6f58cf782200be8912e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/gpu/drm/arm/display/komeda/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c:11:
>> include/drm/drm_gem_framebuffer_helper.h:39:72: error: 'DRM_FORMAT_MAX_PLANES' undeclared here (not in a function)
      39 | int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
         |                                                                        ^~~~~~~~~~~~~~~~~~~~~
   include/drm/drm_gem_framebuffer_helper.h:40:75: error: 'DRM_FORMAT_MAX_PLANES' undeclared here (not in a function)
      40 | void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
         |                                                                           ^~~~~~~~~~~~~~~~~~~~~


vim +/DRM_FORMAT_MAX_PLANES +39 include/drm/drm_gem_framebuffer_helper.h

    16	
    17	struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
    18						  unsigned int plane);
    19	void drm_gem_fb_destroy(struct drm_framebuffer *fb);
    20	int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
    21				     unsigned int *handle);
    22	
    23	int drm_gem_fb_init_with_funcs(struct drm_device *dev,
    24				       struct drm_framebuffer *fb,
    25				       struct drm_file *file,
    26				       const struct drm_mode_fb_cmd2 *mode_cmd,
    27				       const struct drm_framebuffer_funcs *funcs);
    28	struct drm_framebuffer *
    29	drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
    30				     const struct drm_mode_fb_cmd2 *mode_cmd,
    31				     const struct drm_framebuffer_funcs *funcs);
    32	struct drm_framebuffer *
    33	drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
    34			  const struct drm_mode_fb_cmd2 *mode_cmd);
    35	struct drm_framebuffer *
    36	drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
    37				     const struct drm_mode_fb_cmd2 *mode_cmd);
    38	
  > 39	int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
    40	void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
    41	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot July 16, 2021, 12:52 a.m. UTC | #2
Hi Thomas,

I love your patch! Yet something to improve:

[auto build test ERROR on 4d00e2309398147acdbfefbe1deb4b0e78868466]

url:    https://github.com/0day-ci/linux/commits/Thomas-Zimmermann/drm-Provide-framebuffer-vmap-helpers/20210716-020508
base:   4d00e2309398147acdbfefbe1deb4b0e78868466
config: arm64-randconfig-r035-20210715 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 0e49c54a8cbd3e779e5526a5888c683c01cc3c50)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # https://github.com/0day-ci/linux/commit/8a0708f4cf232e7fbc4eb6f58cf782200be8912e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Thomas-Zimmermann/drm-Provide-framebuffer-vmap-helpers/20210716-020508
        git checkout 8a0708f4cf232e7fbc4eb6f58cf782200be8912e
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/gpu/drm/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c:11:
>> include/drm/drm_gem_framebuffer_helper.h:39:72: error: use of undeclared identifier 'DRM_FORMAT_MAX_PLANES'
   int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
                                                                          ^
   include/drm/drm_gem_framebuffer_helper.h:40:75: error: use of undeclared identifier 'DRM_FORMAT_MAX_PLANES'
   void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
                                                                             ^
   2 errors generated.


vim +/DRM_FORMAT_MAX_PLANES +39 include/drm/drm_gem_framebuffer_helper.h

    16	
    17	struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
    18						  unsigned int plane);
    19	void drm_gem_fb_destroy(struct drm_framebuffer *fb);
    20	int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
    21				     unsigned int *handle);
    22	
    23	int drm_gem_fb_init_with_funcs(struct drm_device *dev,
    24				       struct drm_framebuffer *fb,
    25				       struct drm_file *file,
    26				       const struct drm_mode_fb_cmd2 *mode_cmd,
    27				       const struct drm_framebuffer_funcs *funcs);
    28	struct drm_framebuffer *
    29	drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
    30				     const struct drm_mode_fb_cmd2 *mode_cmd,
    31				     const struct drm_framebuffer_funcs *funcs);
    32	struct drm_framebuffer *
    33	drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
    34			  const struct drm_mode_fb_cmd2 *mode_cmd);
    35	struct drm_framebuffer *
    36	drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
    37				     const struct drm_mode_fb_cmd2 *mode_cmd);
    38	
  > 39	int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
    40	void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
    41	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem_atomic_helper.c b/drivers/gpu/drm/drm_gem_atomic_helper.c
index 26af09b959d4..b1cc19e47165 100644
--- a/drivers/gpu/drm/drm_gem_atomic_helper.c
+++ b/drivers/gpu/drm/drm_gem_atomic_helper.c
@@ -330,10 +330,7 @@  int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *p
 {
 	struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(plane_state);
 	struct drm_framebuffer *fb = plane_state->fb;
-	struct drm_gem_object *obj;
-	struct dma_buf_map map;
 	int ret;
-	size_t i;
 
 	if (!fb)
 		return 0;
@@ -342,27 +339,7 @@  int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *p
 	if (ret)
 		return ret;
 
-	for (i = 0; i < ARRAY_SIZE(shadow_plane_state->map); ++i) {
-		obj = drm_gem_fb_get_obj(fb, i);
-		if (!obj)
-			continue;
-		ret = drm_gem_vmap(obj, &map);
-		if (ret)
-			goto err_drm_gem_vunmap;
-		shadow_plane_state->map[i] = map;
-	}
-
-	return 0;
-
-err_drm_gem_vunmap:
-	while (i) {
-		--i;
-		obj = drm_gem_fb_get_obj(fb, i);
-		if (!obj)
-			continue;
-		drm_gem_vunmap(obj, &shadow_plane_state->map[i]);
-	}
-	return ret;
+	return drm_gem_fb_vmap(fb, shadow_plane_state->map);
 }
 EXPORT_SYMBOL(drm_gem_prepare_shadow_fb);
 
@@ -374,25 +351,17 @@  EXPORT_SYMBOL(drm_gem_prepare_shadow_fb);
  * This function implements struct &drm_plane_helper_funcs.cleanup_fb.
  * This function unmaps all buffer objects of the plane's framebuffer.
  *
- * See drm_gem_prepare_shadow_fb() for more inforamtion.
+ * See drm_gem_prepare_shadow_fb() for more information.
  */
 void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state)
 {
 	struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(plane_state);
 	struct drm_framebuffer *fb = plane_state->fb;
-	size_t i = ARRAY_SIZE(shadow_plane_state->map);
-	struct drm_gem_object *obj;
 
 	if (!fb)
 		return;
 
-	while (i) {
-		--i;
-		obj = drm_gem_fb_get_obj(fb, i);
-		if (!obj)
-			continue;
-		drm_gem_vunmap(obj, &shadow_plane_state->map[i]);
-	}
+	drm_gem_fb_vunmap(fb, shadow_plane_state->map);
 }
 EXPORT_SYMBOL(drm_gem_cleanup_shadow_fb);
 
diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index 975a3df0561e..cc4465100cc2 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -15,6 +15,8 @@ 
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_modeset_helper.h>
 
+#include "drm_internal.h"
+
 #define AFBC_HEADER_SIZE		16
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HDR_ALIGN			64
@@ -308,6 +310,74 @@  drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_dirty);
 
+/**
+ * drm_gem_fb_vmap - maps all framebuffer BOs into kernel address space
+ * @fb: the framebuffer
+ * @map: returns the mapping's address for each BO
+ *
+ * This function maps all buffer objects of the given framebuffer into
+ * kernel address space and stores them in struct dma_buf_map. If the
+ * mapping operation fails for one of the BOs, the function unmaps the
+ * already established mappings automatically.
+ *
+ * See drm_gem_fb_vunmap() for unmapping.
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise.
+ */
+int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES])
+{
+	struct drm_gem_object *obj;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < DRM_FORMAT_MAX_PLANES; ++i) {
+		obj = drm_gem_fb_get_obj(fb, i);
+		if (!obj)
+			continue;
+		ret = drm_gem_vmap(obj, &map[i]);
+		if (ret)
+			goto err_drm_gem_vunmap;
+	}
+
+	return 0;
+
+err_drm_gem_vunmap:
+	while (i) {
+		--i;
+		obj = drm_gem_fb_get_obj(fb, i);
+		if (!obj)
+			continue;
+		drm_gem_vunmap(obj, &map[i]);
+	}
+	return ret;
+}
+EXPORT_SYMBOL(drm_gem_fb_vmap);
+
+/**
+ * drm_gem_fb_vunmap - unmaps framebuffer BOs from kernel address space
+ * @fb: the framebuffer
+ * @map: mapping addresses as returned by drm_gem_fb_vmap()
+ *
+ * This function unmaps all buffer objects of the given framebuffer.
+ *
+ * See drm_gem_fb_vmap() for more information.
+ */
+void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES])
+{
+	unsigned int i = DRM_FORMAT_MAX_PLANES;
+	struct drm_gem_object *obj;
+
+	while (i) {
+		--i;
+		obj = drm_gem_fb_get_obj(fb, i);
+		if (!obj)
+			continue;
+		drm_gem_vunmap(obj, &map[i]);
+	}
+}
+EXPORT_SYMBOL(drm_gem_fb_vunmap);
+
 static __u32 drm_gem_afbc_get_bpp(struct drm_device *dev,
 				  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
diff --git a/include/drm/drm_gem_atomic_helper.h b/include/drm/drm_gem_atomic_helper.h
index b2b441361051..f9f8b6f0494a 100644
--- a/include/drm/drm_gem_atomic_helper.h
+++ b/include/drm/drm_gem_atomic_helper.h
@@ -5,6 +5,7 @@ 
 
 #include <linux/dma-buf-map.h>
 
+#include <drm/drm_fourcc.h>
 #include <drm/drm_plane.h>
 
 struct drm_simple_display_pipe;
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index 6bdffc7aa124..485617b54221 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -1,6 +1,8 @@ 
 #ifndef __DRM_GEM_FB_HELPER_H__
 #define __DRM_GEM_FB_HELPER_H__
 
+#include <linux/dma-buf-map.h>
+
 struct drm_afbc_framebuffer;
 struct drm_device;
 struct drm_fb_helper_surface_size;
@@ -34,6 +36,9 @@  struct drm_framebuffer *
 drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
 			     const struct drm_mode_fb_cmd2 *mode_cmd);
 
+int drm_gem_fb_vmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
+void drm_gem_fb_vunmap(struct drm_framebuffer *fb, struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]);
+
 #define drm_is_afbc(modifier) \
 	(((modifier) & AFBC_VENDOR_AND_TYPE_MASK) == DRM_FORMAT_MOD_ARM_AFBC(0))