2012-04-17 07:12:29 -06:00
|
|
|
/*
|
|
|
|
* 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>
|
2012-10-02 11:01:07 -06:00
|
|
|
#include <drm/drmP.h>
|
2014-04-14 03:34:48 -06:00
|
|
|
#include <drm/drm_crtc_helper.h>
|
2012-04-17 07:12:29 -06:00
|
|
|
|
|
|
|
#include "cirrus_drv.h"
|
|
|
|
|
|
|
|
int cirrus_modeset = -1;
|
2015-02-03 09:51:23 -07:00
|
|
|
int cirrus_bpp = 24;
|
2012-04-17 07:12:29 -06:00
|
|
|
|
|
|
|
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
|
|
|
|
module_param_named(modeset, cirrus_modeset, int, 0400);
|
2015-02-03 09:51:23 -07:00
|
|
|
MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:24)");
|
|
|
|
module_param_named(bpp, cirrus_bpp, int, 0400);
|
2012-04-17 07:12:29 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
2014-08-08 07:56:03 -06:00
|
|
|
static const struct pci_device_id pciidlist[] = {
|
2016-03-06 15:02:30 -07:00
|
|
|
{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
|
|
|
|
PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU,
|
|
|
|
0, 0, 0 },
|
2014-04-11 00:56:23 -06:00
|
|
|
{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, PCI_VENDOR_ID_XEN,
|
|
|
|
0x0001, 0, 0, 0 },
|
2012-04-17 07:12:29 -06:00
|
|
|
{0,}
|
|
|
|
};
|
|
|
|
|
2012-06-01 04:11:09 -06:00
|
|
|
|
2012-11-09 02:19:35 -07:00
|
|
|
static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
|
2012-06-01 04:11:09 -06:00
|
|
|
{
|
|
|
|
struct apertures_struct *ap;
|
|
|
|
bool primary = false;
|
|
|
|
|
|
|
|
ap = alloc_apertures(1);
|
2012-11-09 02:19:35 -07:00
|
|
|
if (!ap)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-06-01 04:11:09 -06:00
|
|
|
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);
|
2012-11-09 02:19:35 -07:00
|
|
|
|
|
|
|
return 0;
|
2012-06-01 04:11:09 -06:00
|
|
|
}
|
|
|
|
|
2012-12-21 16:09:25 -07:00
|
|
|
static int cirrus_pci_probe(struct pci_dev *pdev,
|
|
|
|
const struct pci_device_id *ent)
|
2012-04-17 07:12:29 -06:00
|
|
|
{
|
2012-11-09 02:19:35 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = cirrus_kick_out_firmware_fb(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-06-01 04:11:09 -06:00
|
|
|
|
2012-04-17 07:12:29 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-07-12 04:01:43 -06:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2014-04-14 03:34:48 -06:00
|
|
|
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();
|
2015-07-31 04:51:44 -06:00
|
|
|
drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 1);
|
2014-04-14 03:34:48 -06:00
|
|
|
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();
|
2015-07-31 04:51:44 -06:00
|
|
|
drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 0);
|
2014-04-14 03:34:48 -06:00
|
|
|
console_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_kms_helper_poll_enable(drm_dev);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-07-12 04:01:43 -06:00
|
|
|
#endif
|
2014-04-14 03:34:48 -06:00
|
|
|
|
2012-04-17 07:12:29 -06:00
|
|
|
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,
|
2012-07-09 16:40:07 -06:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = drm_compat_ioctl,
|
|
|
|
#endif
|
2012-04-17 07:12:29 -06:00
|
|
|
};
|
|
|
|
static struct drm_driver driver = {
|
drm: rip out drm_core_has_MTRR checks
The new arch_phys_wc_add/del functions do the right thing both with
and without MTRR support in the kernel. So we can drop these
additional checks.
David Herrmann suggest to also kill the DRIVER_USE_MTRR flag since
it's now unused, which spurred me to do a bit a better audit of the
affected drivers. David helped a lot in that. Quoting our mail
discussion:
On Wed, Jul 10, 2013 at 5:41 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
> On Wed, Jul 10, 2013 at 5:22 PM, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
>> On Wed, Jul 10, 2013 at 3:51 PM, David Herrmann <dh.herrmann@gmail.com> wrote:
>>>> -#if __OS_HAS_MTRR
>>>> -static inline int drm_core_has_MTRR(struct drm_device *dev)
>>>> -{
>>>> - return drm_core_check_feature(dev, DRIVER_USE_MTRR);
>>>> -}
>>>> -#else
>>>> -#define drm_core_has_MTRR(dev) (0)
>>>> -#endif
>>>> -
>>>
>>> That was the last user of DRIVER_USE_MTRR (apart from drivers setting
>>> it in .driver_features). Any reason to keep it around?
>>
>> Yeah, I guess we could rip things out. Which will also force me to
>> properly audit drivers for the eventual behaviour change this could
>> entail (in case there's an x86 driver which did not ask for an mtrr,
>> but iirc there isn't).
>
> david@david-mb ~/dev/kernel/linux $ for i in drivers/gpu/drm/* ; do if
> test -d "$i" ; then if ! grep -q USE_MTRR -r $i ; then echo $i ; fi ;
> fi ; done
> drivers/gpu/drm/exynos
> drivers/gpu/drm/gma500
> drivers/gpu/drm/i2c
> drivers/gpu/drm/nouveau
> drivers/gpu/drm/omapdrm
> drivers/gpu/drm/qxl
> drivers/gpu/drm/rcar-du
> drivers/gpu/drm/shmobile
> drivers/gpu/drm/tilcdc
> drivers/gpu/drm/ttm
> drivers/gpu/drm/udl
> drivers/gpu/drm/vmwgfx
> david@david-mb ~/dev/kernel/linux $
>
> So for x86 gma500,nouveau,qxl,udl,vmwgfx don't set DRIVER_USE_MTRR.
> But I cannot tell whether they break if we call arch_phys_wc_add/del,
> anyway. At least nouveau seemed to work here, but it doesn't use AGP
> or drm_bufs, I guess.
Cool, thanks a lot for stitching together the list of drivers to look
at. So for real KMS drivers it's the drives responsibility to add an
mtrr if it needs one. nouvea, radeon, mgag200, i915 and vmwgfx do that
already. Somehow the savage driver also ends up doing that, I have no
idea why.
Note that gma500 as a pure KMS driver doesn't need MTRR setup since
the platforms that it supports all support PAT. So no MTRRs needed to
get wc iomappings.
The mtrr support in the drm core is all for legacy mappings of garts,
framebuffers and registers. All legacy drivers set the USE_MTRR flag,
so we're good there.
All in all I think we can really just ditch this
/endquote
v2: Also kill DRIVER_USE_MTRR as suggested by David Herrmann
v3: Rebase on top of David Herrmann's agp setup/cleanup changes.
Cc: David Herrmann <dh.herrmann@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Andy Lutomirski <luto@amacapital.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2013-08-08 07:41:27 -06:00
|
|
|
.driver_features = DRIVER_MODESET | DRIVER_GEM,
|
2012-04-17 07:12:29 -06:00
|
|
|
.load = cirrus_driver_load,
|
|
|
|
.unload = cirrus_driver_unload,
|
2014-08-29 04:12:43 -06:00
|
|
|
.set_busid = drm_pci_set_busid,
|
2012-04-17 07:12:29 -06:00
|
|
|
.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,
|
2013-07-16 01:12:04 -06:00
|
|
|
.dumb_destroy = drm_gem_dumb_destroy,
|
2012-04-17 07:12:29 -06:00
|
|
|
};
|
|
|
|
|
2014-04-14 03:34:48 -06:00
|
|
|
static const struct dev_pm_ops cirrus_pm_ops = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend,
|
|
|
|
cirrus_pm_resume)
|
|
|
|
};
|
|
|
|
|
2012-04-17 07:12:29 -06:00
|
|
|
static struct pci_driver cirrus_pci_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = pciidlist,
|
|
|
|
.probe = cirrus_pci_probe,
|
|
|
|
.remove = cirrus_pci_remove,
|
2014-04-14 03:34:48 -06:00
|
|
|
.driver.pm = &cirrus_pm_ops,
|
2012-04-17 07:12:29 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init cirrus_init(void)
|
|
|
|
{
|
|
|
|
if (vgacon_text_force() && cirrus_modeset == -1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
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");
|