From patchwork Tue Feb 9 21:05:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Haixia Shi X-Patchwork-Id: 8265731 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DAE4BBEEE5 for ; Tue, 9 Feb 2016 21:05:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A244F20272 for ; Tue, 9 Feb 2016 21:05:54 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 764502026C for ; Tue, 9 Feb 2016 21:05:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB6146E0FA; Tue, 9 Feb 2016 13:05:51 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3F6446E0FA for ; Tue, 9 Feb 2016 13:05:50 -0800 (PST) Received: by mail-pa0-f54.google.com with SMTP id cy9so97214678pac.0 for ; Tue, 09 Feb 2016 13:05:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=EJaMU1bGe+Ps4SMXtM1NBnGdAkYUhQHaqgiQNUzRexg=; b=LUTd+vrbrw2Q3i5d+wAc5+5cz2HeyTe6ghmn/bVxHQDjpauE4KN5DfbTCrCB9OM6pn peoJgsaLTZTpZ0WcDjBmTQ+4VqsKKkoZvvOKDPQlfHI3cIdgabbq1FdvHSGcnOuyzVkQ 5dHpBoXES+kxp9QrXIrg+K49ym2rSRWQE9vds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=EJaMU1bGe+Ps4SMXtM1NBnGdAkYUhQHaqgiQNUzRexg=; b=LM3+yW3N1gt+4zesLor0QHGRuLk6DDeH94PV4CT6TQh/3OhzycIDVxLjc3/AwCS6k+ wsoiUMU5bIpMK25XqYcprf8zjEJkGOqplf5TOJwbw1YdRpPR+ue0OF6uRJ/BvRzFbS1E +lMNZ0wlBoZtaxzK/whD9OF6Yk3vSriJZNy/fhXL8R/hKLK5R7pGo1pL1fk5hKiWo3Qm +jFShwgY5rFCmZQrQXAfYn/7zShdXnb+IQ2BAACNl8t+hLK4edgbfNGpUz5X4JMHrYpH qxiTrz4DC0ERUCfbWpIgTg/MQizU3RwSgm7GMW1TW0ixS2l8TclEZnc+bKbrs/s7H+WM Qv6Q== X-Gm-Message-State: AG10YOTYrNhA0Q852NSC9DTq/KiATD/dhKO+ZnG1ZULY6WfQMDxuBx19w96OtvK9yKJ5IQ== X-Received: by 10.66.150.66 with SMTP id ug2mr54264573pab.114.1455051949601; Tue, 09 Feb 2016 13:05:49 -0800 (PST) Received: from localhost ([2620:0:1000:1600:8caa:444a:848f:6827]) by smtp.gmail.com with ESMTPSA id b63sm52679319pfj.25.2016.02.09.13.05.47 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 09 Feb 2016 13:05:48 -0800 (PST) From: Haixia Shi To: dri-devel@lists.freedesktop.org, dh.herrmann@gmail.com Subject: [PATCH 2/2] drm: make unplugged flag specific to udl driver Date: Tue, 9 Feb 2016 13:05:43 -0800 Message-Id: <1455051943-8291-1-git-send-email-hshi@chromium.org> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1454709464-2536-1-git-send-email-hshi@chromium.org> References: <1454709464-2536-1-git-send-email-hshi@chromium.org> MIME-Version: 1.0 Cc: Haixia Shi X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the general drm_device_is_unplugged() checks, and move the unplugged flag handling logic into drm/udl. In general we want to keep driver-specific logic out of common drm code. Signed-off-by: Haixia Shi Reviewed-by: Stéphane Marchesin --- drivers/gpu/drm/drm_drv.c | 6 ---- drivers/gpu/drm/drm_fops.c | 2 -- drivers/gpu/drm/drm_gem.c | 3 -- drivers/gpu/drm/drm_ioctl.c | 3 -- drivers/gpu/drm/drm_vm.c | 3 -- drivers/gpu/drm/udl/udl_connector.c | 2 +- drivers/gpu/drm/udl/udl_drv.c | 7 +++-- drivers/gpu/drm/udl/udl_drv.h | 6 ++++ drivers/gpu/drm/udl/udl_fb.c | 2 +- drivers/gpu/drm/udl/udl_gem.c | 5 +++ drivers/gpu/drm/udl/udl_main.c | 61 +++++++++++++++++++++++++++++++++++++ include/drm/drmP.h | 14 --------- 12 files changed, 78 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 167c8d3..f93ee12 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -376,9 +376,6 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) if (!minor) { return ERR_PTR(-ENODEV); - } else if (drm_device_is_unplugged(minor->dev)) { - drm_dev_unref(minor->dev); - return ERR_PTR(-ENODEV); } return minor; @@ -464,9 +461,6 @@ void drm_unplug_dev(struct drm_device *dev) drm_minor_unregister(dev, DRM_MINOR_CONTROL); mutex_lock(&drm_global_mutex); - - drm_device_set_unplugged(dev); - if (dev->open_count == 0) { drm_put_dev(dev); } diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 1ea8790..b4332d4 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -497,8 +497,6 @@ int drm_release(struct inode *inode, struct file *filp) if (!--dev->open_count) { retcode = drm_lastclose(dev); - if (drm_device_is_unplugged(dev)) - drm_put_dev(dev); } mutex_unlock(&drm_global_mutex); diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 2e8c77e..c622e32 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -900,9 +900,6 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) struct drm_vma_offset_node *node; int ret; - if (drm_device_is_unplugged(dev)) - return -ENODEV; - drm_vma_offset_lock_lookup(dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, vma->vm_pgoff, diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 8ce2a0c..f959074 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -695,9 +695,6 @@ long drm_ioctl(struct file *filp, dev = file_priv->minor->dev; - if (drm_device_is_unplugged(dev)) - return -ENODEV; - is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END; if (is_driver_ioctl) { diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c index f90bd5f..3a68be4 100644 --- a/drivers/gpu/drm/drm_vm.c +++ b/drivers/gpu/drm/drm_vm.c @@ -657,9 +657,6 @@ int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma) struct drm_device *dev = priv->minor->dev; int ret; - if (drm_device_is_unplugged(dev)) - return -ENODEV; - mutex_lock(&dev->struct_mutex); ret = drm_mmap_locked(filp, vma); mutex_unlock(&dev->struct_mutex); diff --git a/drivers/gpu/drm/udl/udl_connector.c b/drivers/gpu/drm/udl/udl_connector.c index 4709b54..b168f2c 100644 --- a/drivers/gpu/drm/udl/udl_connector.c +++ b/drivers/gpu/drm/udl/udl_connector.c @@ -96,7 +96,7 @@ static int udl_mode_valid(struct drm_connector *connector, static enum drm_connector_status udl_detect(struct drm_connector *connector, bool force) { - if (drm_device_is_unplugged(connector->dev)) + if (udl_device_is_unplugged(connector->dev)) return connector_status_disconnected; return connector_status_connected; } diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c index d5728ec..f5c2a97 100644 --- a/drivers/gpu/drm/udl/udl_drv.c +++ b/drivers/gpu/drm/udl/udl_drv.c @@ -24,12 +24,12 @@ static const struct vm_operations_struct udl_gem_vm_ops = { static const struct file_operations udl_driver_fops = { .owner = THIS_MODULE, - .open = drm_open, + .open = udl_drm_open, .mmap = udl_drm_gem_mmap, .poll = drm_poll, .read = drm_read, - .unlocked_ioctl = drm_ioctl, - .release = drm_release, + .unlocked_ioctl = udl_drm_ioctl, + .release = udl_drm_release, #ifdef CONFIG_COMPAT .compat_ioctl = drm_compat_ioctl, #endif @@ -97,6 +97,7 @@ static void udl_usb_disconnect(struct usb_interface *interface) drm_connector_unplug_all(dev); udl_fbdev_unplug(dev); udl_drop_usb(dev); + udl_device_set_unplugged(dev); drm_unplug_dev(dev); } diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h index 4a064ef..75aa91c 100644 --- a/drivers/gpu/drm/udl/udl_drv.h +++ b/drivers/gpu/drm/udl/udl_drv.h @@ -65,6 +65,7 @@ struct udl_device { atomic_t bytes_identical; /* saved effort with backbuffer comparison */ atomic_t bytes_sent; /* to usb, after compression including overhead */ atomic_t cpu_kcycles_used; /* transpired during pixel processing */ + atomic_t unplugged; /* device has been unplugged or gone away */ }; struct udl_gem_object { @@ -133,6 +134,9 @@ int udl_gem_get_pages(struct udl_gem_object *obj); void udl_gem_put_pages(struct udl_gem_object *obj); int udl_gem_vmap(struct udl_gem_object *obj); void udl_gem_vunmap(struct udl_gem_object *obj); +int udl_drm_open(struct inode *inode, struct file *filp); +int udl_drm_release(struct inode *inode, struct file *filp); +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); int udl_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); @@ -140,6 +144,8 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y, int width, int height); int udl_drop_usb(struct drm_device *dev); +void udl_device_set_unplugged(struct drm_device *dev); +int udl_device_is_unplugged(struct drm_device *dev); #define CMD_WRITE_RAW8 "\xAF\x60" /**< 8 bit raw write command. */ #define CMD_WRITE_RL8 "\xAF\x61" /**< 8 bit run length command. */ diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c index 200419d..df1d53e 100644 --- a/drivers/gpu/drm/udl/udl_fb.c +++ b/drivers/gpu/drm/udl/udl_fb.c @@ -325,7 +325,7 @@ static int udl_fb_open(struct fb_info *info, int user) struct udl_device *udl = dev->dev_private; /* If the USB device is gone, we don't accept new opens */ - if (drm_device_is_unplugged(udl->ddev)) + if (udl_device_is_unplugged(udl->ddev)) return -ENODEV; ufbdev->fb_count++; diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c index 2a0a784..33c302f 100644 --- a/drivers/gpu/drm/udl/udl_gem.c +++ b/drivers/gpu/drm/udl/udl_gem.c @@ -86,8 +86,13 @@ int udl_dumb_create(struct drm_file *file, int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) { + struct drm_file *priv = filp->private_data; + struct drm_device *dev = priv->minor->dev; int ret; + if (udl_device_is_unplugged(dev)) + return -ENODEV; + ret = drm_gem_mmap(filp, vma); if (ret) return ret; diff --git a/drivers/gpu/drm/udl/udl_main.c b/drivers/gpu/drm/udl/udl_main.c index 33dbfb2..2ba3ee3 100644 --- a/drivers/gpu/drm/udl/udl_main.c +++ b/drivers/gpu/drm/udl/udl_main.c @@ -350,3 +350,64 @@ int udl_driver_unload(struct drm_device *dev) kfree(udl); return 0; } + +int udl_drm_open(struct inode *inode, struct file *filp) +{ + struct drm_file *file_priv; + struct drm_minor *minor; + + int ret = drm_open(inode, filp); + if (ret) + return ret; + + file_priv = filp->private_data; + minor = file_priv->minor; + if (udl_device_is_unplugged(minor->dev)) { + drm_dev_unref(minor->dev); + return -ENODEV; + } + + return 0; +} + +int udl_drm_release(struct inode *inode, struct file *filp) +{ + struct drm_file *file_priv = filp->private_data; + struct drm_device *dev = file_priv->minor->dev; + + int ret = drm_release(inode, filp); + if (!dev->open_count && udl_device_is_unplugged(dev)) + drm_put_dev(dev); + + return ret; +} + +int udl_drm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct drm_file *file_priv = filp->private_data; + struct drm_device *dev = file_priv->minor->dev; + unsigned int nr = DRM_IOCTL_NR(cmd); + + if (udl_device_is_unplugged(dev) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_SETCRTC) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_RMFB) && + nr != DRM_IOCTL_NR(DRM_IOCTL_MODE_DESTROY_DUMB)) + return -ENODEV; + + return drm_ioctl(filp, cmd, arg); +} + +void udl_device_set_unplugged(struct drm_device *dev) +{ + struct udl_device *udl = dev->dev_private; + smp_wmb(); + atomic_set(&udl->unplugged, 1); +} + +int udl_device_is_unplugged(struct drm_device *dev) +{ + struct udl_device *udl = dev->dev_private; + int ret = atomic_read(&udl->unplugged); + smp_rmb(); + return ret; +} diff --git a/include/drm/drmP.h b/include/drm/drmP.h index d7162cf..40c6099 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -748,7 +748,6 @@ struct drm_device { struct drm_minor *control; /**< Control node */ struct drm_minor *primary; /**< Primary node */ struct drm_minor *render; /**< Render node */ - atomic_t unplugged; /**< Flag whether dev is dead */ struct inode *anon_inode; /**< inode for private address-space */ char *unique; /**< unique name of the device */ /*@} */ @@ -879,19 +878,6 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, return ((dev->driver->driver_features & feature) ? 1 : 0); } -static inline void drm_device_set_unplugged(struct drm_device *dev) -{ - smp_wmb(); - atomic_set(&dev->unplugged, 1); -} - -static inline int drm_device_is_unplugged(struct drm_device *dev) -{ - int ret = atomic_read(&dev->unplugged); - smp_rmb(); - return ret; -} - static inline bool drm_is_render_client(const struct drm_file *file_priv) { return file_priv->minor->type == DRM_MINOR_RENDER;