drm/qxl: Don't use drm_device->dev_private
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 15 Apr 2020 07:40:02 +0000 (09:40 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 28 Apr 2020 18:04:01 +0000 (20:04 +0200)
Upcasting using a container_of macro is more typesafe, faster and
easier for the compiler to optimize.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: spice-devel@lists.freedesktop.org
Link: https://patchwork.freedesktop.org/patch/msgid/20200415074034.175360-28-daniel.vetter@ffwll.ch
12 files changed:
drivers/gpu/drm/qxl/qxl_debugfs.c
drivers/gpu/drm/qxl/qxl_display.c
drivers/gpu/drm/qxl/qxl_drv.c
drivers/gpu/drm/qxl/qxl_drv.h
drivers/gpu/drm/qxl/qxl_dumb.c
drivers/gpu/drm/qxl/qxl_gem.c
drivers/gpu/drm/qxl/qxl_ioctl.c
drivers/gpu/drm/qxl/qxl_irq.c
drivers/gpu/drm/qxl/qxl_kms.c
drivers/gpu/drm/qxl/qxl_object.c
drivers/gpu/drm/qxl/qxl_release.c
drivers/gpu/drm/qxl/qxl_ttm.c

index 88123047fdd46b709f10ba4fd04db99bd30c5b37..524d35b648d885045eecfb25bec0bbb7f8a5b569 100644 (file)
@@ -39,7 +39,7 @@ static int
 qxl_debugfs_irq_received(struct seq_file *m, void *data)
 {
        struct drm_info_node *node = (struct drm_info_node *) m->private;
-       struct qxl_device *qdev = node->minor->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(node->minor->dev);
 
        seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
        seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
@@ -53,7 +53,7 @@ static int
 qxl_debugfs_buffers_info(struct seq_file *m, void *data)
 {
        struct drm_info_node *node = (struct drm_info_node *) m->private;
-       struct qxl_device *qdev = node->minor->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(node->minor->dev);
        struct qxl_bo *bo;
 
        list_for_each_entry(bo, &qdev->gem.objects, list) {
@@ -83,8 +83,7 @@ void
 qxl_debugfs_init(struct drm_minor *minor)
 {
 #if defined(CONFIG_DEBUG_FS)
-       struct qxl_device *dev =
-               (struct qxl_device *) minor->dev->dev_private;
+       struct qxl_device *dev = to_qxl(minor->dev);
 
        drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
                                 minor->debugfs_root, minor);
index 09583a08e1414381e759f91cb1c70d0ee26251f8..1082cd5d2fd47c20aeff3ecf10d079ff4c3c385b 100644 (file)
@@ -221,7 +221,7 @@ static int qxl_add_mode(struct drm_connector *connector,
                        bool preferred)
 {
        struct drm_device *dev = connector->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_display_mode *mode = NULL;
        int rc;
 
@@ -242,7 +242,7 @@ static int qxl_add_mode(struct drm_connector *connector,
 static int qxl_add_monitors_config_modes(struct drm_connector *connector)
 {
        struct drm_device *dev = connector->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct qxl_output *output = drm_connector_to_qxl_output(connector);
        int h = output->index;
        struct qxl_head *head;
@@ -310,7 +310,7 @@ static void qxl_crtc_update_monitors_config(struct drm_crtc *crtc,
                                            const char *reason)
 {
        struct drm_device *dev = crtc->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct qxl_crtc *qcrtc = to_qxl_crtc(crtc);
        struct qxl_head head;
        int oldcount, i = qcrtc->index;
@@ -400,7 +400,7 @@ static int qxl_framebuffer_surface_dirty(struct drm_framebuffer *fb,
                                         unsigned int num_clips)
 {
        /* TODO: vmwgfx where this was cribbed from had locking. Why? */
-       struct qxl_device *qdev = fb->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(fb->dev);
        struct drm_clip_rect norect;
        struct qxl_bo *qobj;
        bool is_primary;
@@ -462,7 +462,7 @@ static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = {
 static int qxl_primary_atomic_check(struct drm_plane *plane,
                                    struct drm_plane_state *state)
 {
-       struct qxl_device *qdev = plane->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(plane->dev);
        struct qxl_bo *bo;
 
        if (!state->crtc || !state->fb)
@@ -476,7 +476,7 @@ static int qxl_primary_atomic_check(struct drm_plane *plane,
 static int qxl_primary_apply_cursor(struct drm_plane *plane)
 {
        struct drm_device *dev = plane->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_framebuffer *fb = plane->state->fb;
        struct qxl_crtc *qcrtc = to_qxl_crtc(plane->state->crtc);
        struct qxl_cursor_cmd *cmd;
@@ -523,7 +523,7 @@ out_free_release:
 static void qxl_primary_atomic_update(struct drm_plane *plane,
                                      struct drm_plane_state *old_state)
 {
-       struct qxl_device *qdev = plane->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(plane->dev);
        struct qxl_bo *bo = gem_to_qxl_bo(plane->state->fb->obj[0]);
        struct qxl_bo *primary;
        struct drm_clip_rect norect = {
@@ -554,7 +554,7 @@ static void qxl_primary_atomic_update(struct drm_plane *plane,
 static void qxl_primary_atomic_disable(struct drm_plane *plane,
                                       struct drm_plane_state *old_state)
 {
-       struct qxl_device *qdev = plane->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(plane->dev);
 
        if (old_state->fb) {
                struct qxl_bo *bo = gem_to_qxl_bo(old_state->fb->obj[0]);
@@ -570,7 +570,7 @@ static void qxl_cursor_atomic_update(struct drm_plane *plane,
                                     struct drm_plane_state *old_state)
 {
        struct drm_device *dev = plane->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_framebuffer *fb = plane->state->fb;
        struct qxl_crtc *qcrtc = to_qxl_crtc(plane->state->crtc);
        struct qxl_release *release;
@@ -679,7 +679,7 @@ out_free_release:
 static void qxl_cursor_atomic_disable(struct drm_plane *plane,
                                      struct drm_plane_state *old_state)
 {
-       struct qxl_device *qdev = plane->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(plane->dev);
        struct qxl_release *release;
        struct qxl_cursor_cmd *cmd;
        int ret;
@@ -762,7 +762,7 @@ static void qxl_calc_dumb_shadow(struct qxl_device *qdev,
 static int qxl_plane_prepare_fb(struct drm_plane *plane,
                                struct drm_plane_state *new_state)
 {
-       struct qxl_device *qdev = plane->dev->dev_private;
+       struct qxl_device *qdev = to_qxl(plane->dev);
        struct drm_gem_object *obj;
        struct qxl_bo *user_bo;
        struct qxl_surface surf;
@@ -923,7 +923,7 @@ static int qdev_crtc_init(struct drm_device *dev, int crtc_id)
 {
        struct qxl_crtc *qxl_crtc;
        struct drm_plane *primary, *cursor;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        int r;
 
        qxl_crtc = kzalloc(sizeof(struct qxl_crtc), GFP_KERNEL);
@@ -965,7 +965,7 @@ free_mem:
 static int qxl_conn_get_modes(struct drm_connector *connector)
 {
        struct drm_device *dev = connector->dev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct qxl_output *output = drm_connector_to_qxl_output(connector);
        unsigned int pwidth = 1024;
        unsigned int pheight = 768;
@@ -991,7 +991,7 @@ static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector,
                               struct drm_display_mode *mode)
 {
        struct drm_device *ddev = connector->dev;
-       struct qxl_device *qdev = ddev->dev_private;
+       struct qxl_device *qdev = to_qxl(ddev);
 
        if (qxl_check_mode(qdev, mode->hdisplay, mode->vdisplay) != 0)
                return MODE_BAD;
@@ -1021,7 +1021,7 @@ static enum drm_connector_status qxl_conn_detect(
        struct qxl_output *output =
                drm_connector_to_qxl_output(connector);
        struct drm_device *ddev = connector->dev;
-       struct qxl_device *qdev = ddev->dev_private;
+       struct qxl_device *qdev = to_qxl(ddev);
        bool connected = false;
 
        /* The first monitor is always connected */
@@ -1071,7 +1071,7 @@ static int qxl_mode_create_hotplug_mode_update_property(struct qxl_device *qdev)
 
 static int qdev_output_init(struct drm_device *dev, int num_output)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct qxl_output *qxl_output;
        struct drm_connector *connector;
        struct drm_encoder *encoder;
index 6b4ae4c5fb76abacefcf71e4f53cb72b32b5111e..13872b882775d00c2ffdae0547418625efb36d4f 100644 (file)
@@ -137,7 +137,7 @@ disable_pci:
 
 static void qxl_drm_release(struct drm_device *dev)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
 
        /*
         * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
@@ -164,7 +164,7 @@ DEFINE_DRM_GEM_FOPS(qxl_fops);
 static int qxl_drm_freeze(struct drm_device *dev)
 {
        struct pci_dev *pdev = dev->pdev;
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        int ret;
 
        ret = drm_mode_config_helper_suspend(dev);
@@ -186,7 +186,7 @@ static int qxl_drm_freeze(struct drm_device *dev)
 
 static int qxl_drm_resume(struct drm_device *dev, bool thaw)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
 
        qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
        if (!thaw) {
@@ -245,7 +245,7 @@ static int qxl_pm_restore(struct device *dev)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct drm_device *drm_dev = pci_get_drvdata(pdev);
-       struct qxl_device *qdev = drm_dev->dev_private;
+       struct qxl_device *qdev = to_qxl(drm_dev);
 
        qxl_io_reset(qdev);
        return qxl_drm_resume(drm_dev, false);
index 86ac191d92059970842595b38227c5463f120bc9..31e35f787df2c2a7bf23f54de16f7ac60b36a4b5 100644 (file)
@@ -192,8 +192,6 @@ struct qxl_debugfs {
 
 int qxl_debugfs_fence_init(struct qxl_device *rdev);
 
-struct qxl_device;
-
 struct qxl_device {
        struct drm_device ddev;
 
@@ -273,6 +271,8 @@ struct qxl_device {
        int monitors_config_height;
 };
 
+#define to_qxl(dev) container_of(dev, struct qxl_device, ddev)
+
 extern const struct drm_ioctl_desc qxl_ioctls[];
 extern int qxl_max_ioctl;
 
index 272d19b677d8f9a10ed118915d2c65b7dcc15696..24e903383aa17c22231a1b5e326a327f86c896f3 100644 (file)
@@ -32,7 +32,7 @@ int qxl_mode_dumb_create(struct drm_file *file_priv,
                            struct drm_device *dev,
                            struct drm_mode_create_dumb *args)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct qxl_bo *qobj;
        uint32_t handle;
        int r;
index 69f37db1027ad7852f7dbfefaf4e33b134c550ac..5ff6fa9b799c5a29122038f9a95106a2fea23a1c 100644 (file)
@@ -34,7 +34,7 @@ void qxl_gem_object_free(struct drm_gem_object *gobj)
        struct qxl_device *qdev;
        struct ttm_buffer_object *tbo;
 
-       qdev = (struct qxl_device *)gobj->dev->dev_private;
+       qdev = to_qxl(gobj->dev);
 
        qxl_surface_evict(qdev, qobj, false);
 
index 8117a45b36102192b3acd09e269faedfb06dc146..d9a583966949dfa5560438dd86f8f90cb61f27d5 100644 (file)
@@ -36,7 +36,7 @@
 static int qxl_alloc_ioctl(struct drm_device *dev, void *data,
                           struct drm_file *file_priv)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_alloc *qxl_alloc = data;
        int ret;
        struct qxl_bo *qobj;
@@ -64,7 +64,7 @@ static int qxl_alloc_ioctl(struct drm_device *dev, void *data,
 static int qxl_map_ioctl(struct drm_device *dev, void *data,
                         struct drm_file *file_priv)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_map *qxl_map = data;
 
        return qxl_mode_dumb_mmap(file_priv, &qdev->ddev, qxl_map->handle,
@@ -279,7 +279,7 @@ out_free_reloc:
 static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
                                struct drm_file *file_priv)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_execbuffer *execbuffer = data;
        struct drm_qxl_command user_cmd;
        int cmd_num;
@@ -304,7 +304,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
 static int qxl_update_area_ioctl(struct drm_device *dev, void *data,
                                 struct drm_file *file)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_update_area *update_area = data;
        struct qxl_rect area = {.left = update_area->left,
                                .top = update_area->top,
@@ -354,7 +354,7 @@ out:
 static int qxl_getparam_ioctl(struct drm_device *dev, void *data,
                       struct drm_file *file_priv)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_getparam *param = data;
 
        switch (param->param) {
@@ -373,7 +373,7 @@ static int qxl_getparam_ioctl(struct drm_device *dev, void *data,
 static int qxl_clientcap_ioctl(struct drm_device *dev, void *data,
                                  struct drm_file *file_priv)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_clientcap *param = data;
        int byte, idx;
 
@@ -394,7 +394,7 @@ static int qxl_clientcap_ioctl(struct drm_device *dev, void *data,
 static int qxl_alloc_surf_ioctl(struct drm_device *dev, void *data,
                                struct drm_file *file)
 {
-       struct qxl_device *qdev = dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        struct drm_qxl_alloc_surf *param = data;
        struct qxl_bo *qobj;
        int handle;
index 8435af108632c8a7a4ba04c472072f4a5ac486ca..1ba5a702d7636d862756b9b3cb2705ca16021d40 100644 (file)
@@ -32,7 +32,7 @@
 irqreturn_t qxl_irq_handler(int irq, void *arg)
 {
        struct drm_device *dev = (struct drm_device *) arg;
-       struct qxl_device *qdev = (struct qxl_device *)dev->dev_private;
+       struct qxl_device *qdev = to_qxl(dev);
        uint32_t pending;
 
        pending = xchg(&qdev->ram_header->int_pending, 0);
index 91a34dd835d7b3d849e2aab0b1342817b4825602..a6d873052cd409729dfadbeaaf0a104999b72395 100644 (file)
@@ -114,7 +114,6 @@ int qxl_device_init(struct qxl_device *qdev,
 
        qdev->ddev.pdev = pdev;
        pci_set_drvdata(pdev, &qdev->ddev);
-       qdev->ddev.dev_private = qdev;
 
        mutex_init(&qdev->gem.mutex);
        mutex_init(&qdev->update_area_mutex);
index ab72dc3476e9cfc6d0b486376a89dcdbfa01ddd6..edc8a9916872c76444022026f2967f5b34f17b1d 100644 (file)
@@ -33,7 +33,7 @@ static void qxl_ttm_bo_destroy(struct ttm_buffer_object *tbo)
        struct qxl_device *qdev;
 
        bo = to_qxl_bo(tbo);
-       qdev = (struct qxl_device *)bo->tbo.base.dev->dev_private;
+       qdev = to_qxl(bo->tbo.base.dev);
 
        qxl_surface_evict(qdev, bo, false);
        WARN_ON_ONCE(bo->map_count > 0);
index 2feca734c7b195fe385dea55417ad9c139c6655d..4fae3e393da14994723a458e78d6d9d4510e5211 100644 (file)
@@ -243,7 +243,7 @@ static int qxl_release_validate_bo(struct qxl_bo *bo)
                return ret;
 
        /* allocate a surface for reserved + validated buffers */
-       ret = qxl_bo_check_id(bo->tbo.base.dev->dev_private, bo);
+       ret = qxl_bo_check_id(to_qxl(bo->tbo.base.dev), bo);
        if (ret)
                return ret;
        return 0;
index 93a2eb14844ba77a686b1c6ba021554f6b606120..f09a712b1ed2fa2489a4210a4903467b23f4335a 100644 (file)
@@ -243,7 +243,7 @@ static void qxl_bo_move_notify(struct ttm_buffer_object *bo,
        if (!qxl_ttm_bo_is_qxl_bo(bo))
                return;
        qbo = to_qxl_bo(bo);
-       qdev = qbo->tbo.base.dev->dev_private;
+       qdev = to_qxl(qbo->tbo.base.dev);
 
        if (bo->mem.mem_type == TTM_PL_PRIV && qbo->surface_id)
                qxl_surface_evict(qdev, qbo, new_mem ? true : false);