Skip to content

Commit

Permalink
BACKPORT: drm/virtio: Drop deprecated load/unload initialization
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
(cherry picked from commit d516e75c71c9853ef70a9c476d11a97b69380147)
Bug: 153580313
Signed-off-by: Alistair Delva <[email protected]>
Change-Id: I3ad8b26ab1a9c7dc6e0a5686845ccb9dc37c49da
  • Loading branch information
ezequielgarcia authored and adelva1984 committed Apr 18, 2020
1 parent bc48c50 commit 5f6439c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 140 deletions.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/virtio/virtgpu_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
121 changes: 0 additions & 121 deletions drivers/gpu/drm/virtio/virtgpu_drm_bus.c

This file was deleted.

97 changes: 93 additions & 4 deletions drivers/gpu/drm/virtio/virtgpu_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
goto err_free;

ret = drm_dev_register(dev, 0);
if (ret)
return 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);
}

Expand Down Expand Up @@ -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,

Expand Down
9 changes: 3 additions & 6 deletions drivers/gpu/drm/virtio/virtgpu_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 */
Expand Down
9 changes: 3 additions & 6 deletions drivers/gpu/drm/virtio/virtgpu_kms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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;

Expand Down

0 comments on commit 5f6439c

Please sign in to comment.