OSDN Git Service

drm/msm: add DRM_IOCTL_MSM_RMFB2
authorLloyd Atkinson <latkinso@codeaurora.org>
Mon, 30 Jan 2017 22:30:55 +0000 (17:30 -0500)
committerYunyun Cao <yunyunc@codeaurora.org>
Mon, 13 Aug 2018 03:57:37 +0000 (11:57 +0800)
Add new remove framebuffer ioctl that simply unreferences the
given framebuffer instead of triggering a shutdown of the CRTC
if the buffer is in active use. This allows the user space to
proactively unref the buffer without triggering an unwanted
shutdown.

Change-Id: Iac06985d069989b28affcf620d4e3feba6d07644
Signed-off-by: Lloyd Atkinson <latkinso@codeaurora.org>
Signed-off-by: Yunyun Cao <yunyunc@codeaurora.org>
drivers/gpu/drm/msm/msm_drv.c
include/uapi/drm/msm_drm.h

index f1bd996..c2f5621 100644 (file)
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+/*
+ * Copyright (c) 2016 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
 
 #include <linux/of_address.h>
 #include "msm_drv.h"
@@ -1845,6 +1866,54 @@ int msm_release(struct inode *inode, struct file *filp)
        return drm_release(inode, filp);
 }
 
+/**
+ * msm_ioctl_rmfb2 - remove an FB from the configuration
+ * @dev: drm device for the ioctl
+ * @data: data pointer for the ioctl
+ * @file_priv: drm file for the ioctl call
+ *
+ * Remove the FB specified by the user.
+ *
+ * Called by the user via ioctl.
+ *
+ * Returns:
+ * Zero on success, negative errno on failure.
+ */
+static int msm_ioctl_rmfb2(struct drm_device *dev, void *data,
+                   struct drm_file *file_priv)
+{
+       struct drm_framebuffer *fb = NULL;
+       struct drm_framebuffer *fbl = NULL;
+       uint32_t *id = data;
+       int found = 0;
+
+       if (!drm_core_check_feature(dev, DRIVER_MODESET))
+               return -EINVAL;
+
+       fb = drm_framebuffer_lookup(dev, *id);
+       if (!fb)
+               return -ENOENT;
+
+       /* drop extra ref from traversing drm_framebuffer_lookup */
+       drm_framebuffer_unreference(fb);
+
+       mutex_lock(&file_priv->fbs_lock);
+       list_for_each_entry(fbl, &file_priv->fbs, filp_head)
+               if (fb == fbl)
+                       found = 1;
+       if (!found) {
+               mutex_unlock(&file_priv->fbs_lock);
+               return -ENOENT;
+       }
+
+       list_del_init(&fb->filp_head);
+       mutex_unlock(&file_priv->fbs_lock);
+
+       drm_framebuffer_unreference(fb);
+
+       return 0;
+}
+
 static const struct drm_ioctl_desc msm_ioctls[] = {
        DRM_IOCTL_DEF_DRV(MSM_GET_PARAM,    msm_ioctl_get_param,    DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(MSM_GEM_NEW,      msm_ioctl_gem_new,      DRM_AUTH|DRM_RENDER_ALLOW),
@@ -1874,6 +1943,8 @@ static const struct drm_ioctl_desc msm_ioctls[] = {
                          DRM_AUTH|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query,
                          DRM_AUTH|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF_DRV(MSM_RMFB2, msm_ioctl_rmfb2,
+                         DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 };
 
 static const struct vm_operations_struct vm_ops = {
index 30ae8c3..30dbd1c 100644 (file)
@@ -466,6 +466,7 @@ struct drm_msm_submitqueue_query {
 #define DRM_MSM_COUNTER_PUT            0x44
 #define DRM_MSM_COUNTER_READ           0x45
 #define DRM_MSM_GEM_SYNC               0x46
+#define DRM_MSM_RMFB2                  0x47
 
 /**
  * Currently DRM framework supports only VSYNC event.
@@ -509,6 +510,8 @@ struct drm_msm_submitqueue_query {
 #define DRM_IOCTL_MSM_SUBMITQUEUE_QUERY \
        DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_QUERY, \
                struct drm_msm_submitqueue_query)
+#define DRM_IOCTL_MSM_RMFB2 DRM_IOW((DRM_COMMAND_BASE + \
+                       DRM_MSM_RMFB2), unsigned int)
 
 #if defined(__cplusplus)
 }