cirrus_drv.c 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * Copyright 2012 Red Hat <mjg@redhat.com>
 *
 * This file is subject to the terms and conditions of the GNU General
 * Public License version 2. See the file COPYING in the main
 * directory of this archive for more details.
 *
 * Authors: Matthew Garrett
 *          Dave Airlie
 */
#include <linux/module.h>
#include <linux/console.h>
13
#include <drm/drmP.h>
14
#include <drm/drm_crtc_helper.h>
15 16 17 18

#include "cirrus_drv.h"

int cirrus_modeset = -1;
19
int cirrus_bpp = 24;
20 21 22

MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
module_param_named(modeset, cirrus_modeset, int, 0400);
23 24
MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:24)");
module_param_named(bpp, cirrus_bpp, int, 0400);
25 26 27 28 29 30 31 32 33 34

/*
 * This is the generic driver code. This binds the driver to the drm core,
 * which then performs further device association and calls our graphics init
 * functions
 */

static struct drm_driver driver;

/* only bind to the cirrus chip in qemu */
35
static const struct pci_device_id pciidlist[] = {
36 37
	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, 0x1af4, 0x1100, 0,
	  0, 0 },
38 39
	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, PCI_VENDOR_ID_XEN,
	  0x0001, 0, 0, 0 },
40 41 42
	{0,}
};

43

44
static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
45 46 47 48 49
{
	struct apertures_struct *ap;
	bool primary = false;

	ap = alloc_apertures(1);
50 51 52
	if (!ap)
		return -ENOMEM;

53 54 55 56 57 58 59 60
	ap->ranges[0].base = pci_resource_start(pdev, 0);
	ap->ranges[0].size = pci_resource_len(pdev, 0);

#ifdef CONFIG_X86
	primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
#endif
	remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
	kfree(ap);
61 62

	return 0;
63 64
}

65 66
static int cirrus_pci_probe(struct pci_dev *pdev,
			    const struct pci_device_id *ent)
67
{
68 69 70 71 72
	int ret;

	ret = cirrus_kick_out_firmware_fb(pdev);
	if (ret)
		return ret;
73

74 75 76 77 78 79 80 81 82 83
	return drm_get_pci_dev(pdev, ent, &driver);
}

static void cirrus_pci_remove(struct pci_dev *pdev)
{
	struct drm_device *dev = pci_get_drvdata(pdev);

	drm_put_dev(dev);
}

R
Russell King 已提交
84
#ifdef CONFIG_PM_SLEEP
85 86 87 88 89 90 91 92 93 94
static int cirrus_pm_suspend(struct device *dev)
{
	struct pci_dev *pdev = to_pci_dev(dev);
	struct drm_device *drm_dev = pci_get_drvdata(pdev);
	struct cirrus_device *cdev = drm_dev->dev_private;

	drm_kms_helper_poll_disable(drm_dev);

	if (cdev->mode_info.gfbdev) {
		console_lock();
95
		drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 1);
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
		console_unlock();
	}

	return 0;
}

static int cirrus_pm_resume(struct device *dev)
{
	struct pci_dev *pdev = to_pci_dev(dev);
	struct drm_device *drm_dev = pci_get_drvdata(pdev);
	struct cirrus_device *cdev = drm_dev->dev_private;

	drm_helper_resume_force_mode(drm_dev);

	if (cdev->mode_info.gfbdev) {
		console_lock();
112
		drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 0);
113 114 115 116 117 118
		console_unlock();
	}

	drm_kms_helper_poll_enable(drm_dev);
	return 0;
}
R
Russell King 已提交
119
#endif
120

121 122 123 124 125 126 127
static const struct file_operations cirrus_driver_fops = {
	.owner = THIS_MODULE,
	.open = drm_open,
	.release = drm_release,
	.unlocked_ioctl = drm_ioctl,
	.mmap = cirrus_mmap,
	.poll = drm_poll,
128 129 130
#ifdef CONFIG_COMPAT
	.compat_ioctl = drm_compat_ioctl,
#endif
131 132
};
static struct drm_driver driver = {
133
	.driver_features = DRIVER_MODESET | DRIVER_GEM,
134 135
	.load = cirrus_driver_load,
	.unload = cirrus_driver_unload,
136
	.set_busid = drm_pci_set_busid,
137 138 139 140 141 142 143 144 145 146
	.fops = &cirrus_driver_fops,
	.name = DRIVER_NAME,
	.desc = DRIVER_DESC,
	.date = DRIVER_DATE,
	.major = DRIVER_MAJOR,
	.minor = DRIVER_MINOR,
	.patchlevel = DRIVER_PATCHLEVEL,
	.gem_free_object = cirrus_gem_free_object,
	.dumb_create = cirrus_dumb_create,
	.dumb_map_offset = cirrus_dumb_mmap_offset,
147
	.dumb_destroy = drm_gem_dumb_destroy,
148 149
};

150 151 152 153 154
static const struct dev_pm_ops cirrus_pm_ops = {
	SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend,
				cirrus_pm_resume)
};

155 156 157 158 159
static struct pci_driver cirrus_pci_driver = {
	.name = DRIVER_NAME,
	.id_table = pciidlist,
	.probe = cirrus_pci_probe,
	.remove = cirrus_pci_remove,
160
	.driver.pm = &cirrus_pm_ops,
161 162 163 164
};

static int __init cirrus_init(void)
{
165
#ifdef CONFIG_VGA_CONSOLE
166 167
	if (vgacon_text_force() && cirrus_modeset == -1)
		return -EINVAL;
168
#endif
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

	if (cirrus_modeset == 0)
		return -EINVAL;
	return drm_pci_init(&driver, &cirrus_pci_driver);
}

static void __exit cirrus_exit(void)
{
	drm_pci_exit(&driver, &cirrus_pci_driver);
}

module_init(cirrus_init);
module_exit(cirrus_exit);

MODULE_DEVICE_TABLE(pci, pciidlist);
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");