2019-05-31 15:09:37 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-04-17 21:01:25 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Red Hat
|
|
|
|
*
|
|
|
|
* Authors: Matthew Garrett
|
|
|
|
* Dave Airlie
|
|
|
|
*/
|
2019-06-23 17:35:42 +07:00
|
|
|
|
2012-04-17 21:01:25 +07:00
|
|
|
#include <linux/console.h>
|
2019-12-05 16:02:52 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
2012-04-17 21:01:25 +07:00
|
|
|
|
2019-06-23 17:35:42 +07:00
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_ioctl.h>
|
2012-10-03 00:01:07 +07:00
|
|
|
#include <drm/drm_pciids.h>
|
2012-04-17 21:01:25 +07:00
|
|
|
|
2019-06-23 17:35:42 +07:00
|
|
|
#include "mgag200_drv.h"
|
|
|
|
|
2012-04-17 21:01:25 +07: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
|
|
|
|
*/
|
|
|
|
int mgag200_modeset = -1;
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
|
|
|
|
module_param_named(modeset, mgag200_modeset, int, 0400);
|
|
|
|
|
2019-11-26 17:19:50 +07:00
|
|
|
int mgag200_hw_bug_no_startadd = -1;
|
|
|
|
MODULE_PARM_DESC(modeset, "HW does not interpret scanout-buffer start address correctly");
|
|
|
|
module_param_named(hw_bug_no_startadd, mgag200_hw_bug_no_startadd, int, 0400);
|
|
|
|
|
2012-04-17 21:01:25 +07:00
|
|
|
static struct drm_driver driver;
|
|
|
|
|
2014-08-08 20:56:03 +07:00
|
|
|
static const struct pci_device_id pciidlist[] = {
|
2019-12-06 15:19:01 +07:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
|
2019-11-26 17:15:29 +07:00
|
|
|
G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
|
2012-04-17 21:01:25 +07:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
|
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
|
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
|
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
|
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
|
2015-08-21 20:24:05 +07:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
|
2016-10-21 23:47:07 +07:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
|
2012-04-17 21:01:25 +07:00
|
|
|
{0,}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, pciidlist);
|
|
|
|
|
2012-06-01 17:12:39 +07:00
|
|
|
|
2012-12-22 06:09:25 +07:00
|
|
|
static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2012-04-17 21:01:25 +07:00
|
|
|
{
|
2019-12-05 16:02:52 +07:00
|
|
|
struct drm_device *dev;
|
|
|
|
int ret;
|
|
|
|
|
2019-08-22 16:06:44 +07:00
|
|
|
drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb");
|
2012-06-01 17:12:39 +07:00
|
|
|
|
2019-12-05 16:02:52 +07:00
|
|
|
ret = pci_enable_device(pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
dev = drm_dev_alloc(&driver, &pdev->dev);
|
|
|
|
if (IS_ERR(dev)) {
|
|
|
|
ret = PTR_ERR(dev);
|
|
|
|
goto err_pci_disable_device;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->pdev = pdev;
|
|
|
|
pci_set_drvdata(pdev, dev);
|
|
|
|
|
|
|
|
ret = mgag200_driver_load(dev, ent->driver_data);
|
|
|
|
if (ret)
|
|
|
|
goto err_drm_dev_put;
|
|
|
|
|
|
|
|
ret = drm_dev_register(dev, ent->driver_data);
|
|
|
|
if (ret)
|
|
|
|
goto err_mgag200_driver_unload;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_mgag200_driver_unload:
|
|
|
|
mgag200_driver_unload(dev);
|
|
|
|
err_drm_dev_put:
|
|
|
|
drm_dev_put(dev);
|
|
|
|
err_pci_disable_device:
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
return ret;
|
2012-04-17 21:01:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mga_pci_remove(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
|
2019-12-05 16:02:52 +07:00
|
|
|
drm_dev_unregister(dev);
|
|
|
|
mgag200_driver_unload(dev);
|
|
|
|
drm_dev_put(dev);
|
2012-04-17 21:01:25 +07:00
|
|
|
}
|
|
|
|
|
2019-10-16 18:52:03 +07:00
|
|
|
DEFINE_DRM_GEM_FOPS(mgag200_driver_fops);
|
2012-04-17 21:01:25 +07:00
|
|
|
|
2019-11-26 17:15:29 +07:00
|
|
|
static bool mgag200_pin_bo_at_0(const struct mga_device *mdev)
|
|
|
|
{
|
2019-11-26 17:19:50 +07:00
|
|
|
if (mgag200_hw_bug_no_startadd > 0) {
|
|
|
|
DRM_WARN_ONCE("Option hw_bug_no_startradd is enabled. Please "
|
|
|
|
"report the output of 'lspci -vvnn' to "
|
|
|
|
"<dri-devel@lists.freedesktop.org> if this "
|
|
|
|
"option is required to make mgag200 work "
|
|
|
|
"correctly on your system.\n");
|
|
|
|
return true;
|
|
|
|
} else if (!mgag200_hw_bug_no_startadd) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-26 17:15:29 +07:00
|
|
|
return mdev->flags & MGAG200_FLAG_HW_BUG_NO_STARTADD;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mgag200_driver_dumb_create(struct drm_file *file,
|
|
|
|
struct drm_device *dev,
|
|
|
|
struct drm_mode_create_dumb *args)
|
|
|
|
{
|
|
|
|
struct mga_device *mdev = dev->dev_private;
|
|
|
|
unsigned long pg_align;
|
|
|
|
|
|
|
|
if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized"))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pg_align = 0ul;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Aligning scanout buffers to the size of the video ram forces
|
|
|
|
* placement at offset 0. Works around a bug where HW does not
|
|
|
|
* respect 'startadd' field.
|
|
|
|
*/
|
|
|
|
if (mgag200_pin_bo_at_0(mdev))
|
|
|
|
pg_align = PFN_UP(mdev->mc.vram_size);
|
|
|
|
|
2020-01-06 19:57:44 +07:00
|
|
|
return drm_gem_vram_fill_create_dumb(file, dev, pg_align, 0, args);
|
2019-11-26 17:15:29 +07:00
|
|
|
}
|
|
|
|
|
2012-04-17 21:01:25 +07: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 20:41:27 +07:00
|
|
|
.driver_features = DRIVER_GEM | DRIVER_MODESET,
|
2012-04-17 21:01:25 +07:00
|
|
|
.fops = &mgag200_driver_fops,
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.desc = DRIVER_DESC,
|
|
|
|
.date = DRIVER_DATE,
|
|
|
|
.major = DRIVER_MAJOR,
|
|
|
|
.minor = DRIVER_MINOR,
|
|
|
|
.patchlevel = DRIVER_PATCHLEVEL,
|
2019-11-26 17:15:29 +07:00
|
|
|
.debugfs_init = drm_vram_mm_debugfs_init,
|
|
|
|
.dumb_create = mgag200_driver_dumb_create,
|
|
|
|
.dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
|
|
|
|
.gem_prime_mmap = drm_gem_prime_mmap,
|
2012-04-17 21:01:25 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver mgag200_pci_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = pciidlist,
|
|
|
|
.probe = mga_pci_probe,
|
|
|
|
.remove = mga_pci_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mgag200_init(void)
|
|
|
|
{
|
|
|
|
if (vgacon_text_force() && mgag200_modeset == -1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (mgag200_modeset == 0)
|
|
|
|
return -EINVAL;
|
2017-05-24 21:51:40 +07:00
|
|
|
|
|
|
|
return pci_register_driver(&mgag200_pci_driver);
|
2012-04-17 21:01:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mgag200_exit(void)
|
|
|
|
{
|
2017-05-24 21:51:40 +07:00
|
|
|
pci_unregister_driver(&mgag200_pci_driver);
|
2012-04-17 21:01:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mgag200_init);
|
|
|
|
module_exit(mgag200_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|