BACKPORT: drm/virtio: Drop deprecated load/unload initialization

Move the code around so the driver is probed the bus
.probe and removed from the bus .remove callbacks.
This commit is just a cleanup and shouldn't affect
functionality.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190108145930.15080-1-ezequiel@collabora.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit d516e75c71c9853ef70a9c476d11a97b69380147)
Bug: 153580313
Signed-off-by: Alistair Delva <adelva@google.com>
Change-Id: I3ad8b26ab1a9c7dc6e0a5686845ccb9dc37c49da
This commit is contained in:
Ezequiel Garcia 2019-01-08 11:59:30 -03:00 committed by Alistair Delva
parent bc48c50063
commit 5f6439cbf2
6 changed files with 101 additions and 140 deletions

View file

@ -3,7 +3,7 @@
# Makefile for the drm device driver. This driver provides support for the
# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_drm_bus.o virtgpu_gem.o \
virtio-gpu-y := virtgpu_drv.o virtgpu_kms.o virtgpu_gem.o \
virtgpu_fb.o virtgpu_display.o virtgpu_vq.o virtgpu_ttm.o \
virtgpu_fence.o virtgpu_object.o virtgpu_debugfs.o virtgpu_plane.o \
virtgpu_ioctl.o virtgpu_prime.o virtgpu_trace_points.o

View file

@ -354,7 +354,7 @@ static const struct drm_mode_config_funcs virtio_gpu_mode_funcs = {
.atomic_commit = drm_atomic_helper_commit,
};
int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
void virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
{
int i;
@ -372,7 +372,6 @@ int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
vgdev_output_init(vgdev, i);
drm_mode_config_reset(vgdev->ddev);
return 0;
}
void virtio_gpu_modeset_fini(struct virtio_gpu_device *vgdev)

View file

@ -1,121 +0,0 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <linux/pci.h>
#include <drm/drm_fb_helper.h>
#include "virtgpu_drv.h"
static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
{
struct apertures_struct *ap;
bool primary;
ap = alloc_apertures(1);
if (!ap)
return;
ap->ranges[0].base = pci_resource_start(pci_dev, 0);
ap->ranges[0].size = pci_resource_len(pci_dev, 0);
primary = pci_dev->resource[PCI_ROM_RESOURCE].flags
& IORESOURCE_ROM_SHADOW;
drm_fb_helper_remove_conflicting_framebuffers(ap, "virtiodrmfb", primary);
kfree(ap);
}
int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
{
struct drm_device *dev;
int ret;
dev = drm_dev_alloc(driver, &vdev->dev);
if (IS_ERR(dev))
return PTR_ERR(dev);
vdev->priv = dev;
if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) {
struct pci_dev *pdev = to_pci_dev(vdev->dev.parent);
const char *pname = dev_name(&pdev->dev);
bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
char unique[20];
DRM_INFO("pci: %s detected at %s\n",
vga ? "virtio-vga" : "virtio-gpu-pci",
pname);
dev->pdev = pdev;
if (vga)
virtio_pci_kick_out_firmware_fb(pdev);
/*
* Normally the drm_dev_set_unique() call is done by core DRM.
* The following comment covers, why virtio cannot rely on it.
*
* Unlike the other virtual GPU drivers, virtio abstracts the
* underlying bus type by using struct virtio_device.
*
* Hence the dev_is_pci() check, used in core DRM, will fail
* and the unique returned will be the virtio_device "virtio0",
* while a "pci:..." one is required.
*
* A few other ideas were considered:
* - Extend the dev_is_pci() check [in drm_set_busid] to
* consider virtio.
* Seems like a bigger hack than what we have already.
*
* - Point drm_device::dev to the parent of the virtio_device
* Semantic changes:
* * Using the wrong device for i2c, framebuffer_alloc and
* prime import.
* Visual changes:
* * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer,
* will print the wrong information.
*
* We could address the latter issues, by introducing
* drm_device::bus_dev, ... which would be used solely for this.
*
* So for the moment keep things as-is, with a bulky comment
* for the next person who feels like removing this
* drm_dev_set_unique() quirk.
*/
snprintf(unique, sizeof(unique), "pci:%s", pname);
ret = drm_dev_set_unique(dev, unique);
if (ret)
goto err_free;
}
ret = drm_dev_register(dev, 0);
if (ret)
goto err_free;
return 0;
err_free:
drm_dev_put(dev);
return ret;
}

View file

@ -40,8 +40,78 @@ static int virtio_gpu_modeset = -1;
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
module_param_named(modeset, virtio_gpu_modeset, int, 0400);
static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
{
struct apertures_struct *ap;
bool primary;
ap = alloc_apertures(1);
if (!ap)
return;
ap->ranges[0].base = pci_resource_start(pci_dev, 0);
ap->ranges[0].size = pci_resource_len(pci_dev, 0);
primary = pci_dev->resource[PCI_ROM_RESOURCE].flags
& IORESOURCE_ROM_SHADOW;
drm_fb_helper_remove_conflicting_framebuffers(ap, "virtiodrmfb", primary);
kfree(ap);
}
static int virtio_gpu_pci_quirk(struct drm_device *dev, struct virtio_device *vdev)
{
struct pci_dev *pdev = to_pci_dev(vdev->dev.parent);
const char *pname = dev_name(&pdev->dev);
bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
char unique[20];
DRM_INFO("pci: %s detected at %s\n",
vga ? "virtio-vga" : "virtio-gpu-pci",
pname);
dev->pdev = pdev;
if (vga)
virtio_pci_kick_out_firmware_fb(pdev);
/*
* Normally the drm_dev_set_unique() call is done by core DRM.
* The following comment covers, why virtio cannot rely on it.
*
* Unlike the other virtual GPU drivers, virtio abstracts the
* underlying bus type by using struct virtio_device.
*
* Hence the dev_is_pci() check, used in core DRM, will fail
* and the unique returned will be the virtio_device "virtio0",
* while a "pci:..." one is required.
*
* A few other ideas were considered:
* - Extend the dev_is_pci() check [in drm_set_busid] to
* consider virtio.
* Seems like a bigger hack than what we have already.
*
* - Point drm_device::dev to the parent of the virtio_device
* Semantic changes:
* * Using the wrong device for i2c, framebuffer_alloc and
* prime import.
* Visual changes:
* * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer,
* will print the wrong information.
*
* We could address the latter issues, by introducing
* drm_device::bus_dev, ... which would be used solely for this.
*
* So for the moment keep things as-is, with a bulky comment
* for the next person who feels like removing this
* drm_dev_set_unique() quirk.
*/
snprintf(unique, sizeof(unique), "pci:%s", pname);
return drm_dev_set_unique(dev, unique);
}
static int virtio_gpu_probe(struct virtio_device *vdev)
{
struct drm_device *dev;
int ret;
if (vgacon_text_force() && virtio_gpu_modeset == -1)
@ -50,18 +120,39 @@ static int virtio_gpu_probe(struct virtio_device *vdev)
if (virtio_gpu_modeset == 0)
return -EINVAL;
ret = drm_virtio_init(&driver, vdev);
dev = drm_dev_alloc(&driver, &vdev->dev);
if (IS_ERR(dev))
return PTR_ERR(dev);
vdev->priv = dev;
if (!strcmp(vdev->dev.parent->bus->name, "pci")) {
ret = virtio_gpu_pci_quirk(dev, vdev);
if (ret)
goto err_free;
}
ret = virtio_gpu_init(dev);
if (ret)
return ret;
goto err_free;
ret = drm_dev_register(dev, 0);
if (ret)
goto err_free;
drm_fbdev_generic_setup(vdev->priv, 32);
return 0;
err_free:
drm_dev_put(dev);
return ret;
}
static void virtio_gpu_remove(struct virtio_device *vdev)
{
struct drm_device *dev = vdev->priv;
drm_dev_unregister(dev);
virtio_gpu_deinit(dev);
drm_put_dev(dev);
}
@ -123,8 +214,6 @@ static const struct file_operations virtio_gpu_driver_fops = {
static struct drm_driver driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_RENDER | DRIVER_ATOMIC,
.load = virtio_gpu_driver_load,
.unload = virtio_gpu_driver_unload,
.open = virtio_gpu_driver_open,
.postclose = virtio_gpu_driver_postclose,

View file

@ -50,9 +50,6 @@
#define DRIVER_MINOR 1
#define DRIVER_PATCHLEVEL 0
/* virtgpu_drm_bus.c */
int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev);
struct virtio_gpu_object_params {
uint32_t format;
uint32_t width;
@ -231,8 +228,8 @@ int virtio_gpu_object_list_validate(struct ww_acquire_ctx *ticket,
void virtio_gpu_unref_list(struct list_head *head);
/* virtio_kms.c */
int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags);
void virtio_gpu_driver_unload(struct drm_device *dev);
int virtio_gpu_init(struct drm_device *dev);
void virtio_gpu_deinit(struct drm_device *dev);
int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file);
void virtio_gpu_driver_postclose(struct drm_device *dev, struct drm_file *file);
@ -343,7 +340,7 @@ int virtio_gpu_framebuffer_init(struct drm_device *dev,
struct virtio_gpu_framebuffer *vgfb,
const struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_object *obj);
int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev);
void virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev);
void virtio_gpu_modeset_fini(struct virtio_gpu_device *vgdev);
/* virtio_gpu_plane.c */

View file

@ -106,7 +106,7 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
vgdev->num_capsets = num_capsets;
}
int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
int virtio_gpu_init(struct drm_device *dev)
{
static vq_callback_t *callbacks[] = {
virtio_gpu_ctrl_ack, virtio_gpu_cursor_ack
@ -193,9 +193,7 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
num_capsets, &num_capsets);
DRM_INFO("number of cap sets: %d\n", num_capsets);
ret = virtio_gpu_modeset_init(vgdev);
if (ret)
goto err_modeset;
virtio_gpu_modeset_init(vgdev);
virtio_device_ready(vgdev->vdev);
vgdev->vqs_ready = true;
@ -209,7 +207,6 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
5 * HZ);
return 0;
err_modeset:
err_scanouts:
virtio_gpu_ttm_fini(vgdev);
err_ttm:
@ -231,7 +228,7 @@ static void virtio_gpu_cleanup_cap_cache(struct virtio_gpu_device *vgdev)
}
}
void virtio_gpu_driver_unload(struct drm_device *dev)
void virtio_gpu_deinit(struct drm_device *dev)
{
struct virtio_gpu_device *vgdev = dev->dev_private;