2019-05-31 16:09:37 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-04-17 22:01:25 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Red Hat
|
|
|
|
*
|
|
|
|
* Authors: Matthew Garrett
|
|
|
|
* Dave Airlie
|
|
|
|
*/
|
2019-06-23 18:35:42 +08:00
|
|
|
|
2012-04-17 22:01:25 +08:00
|
|
|
#include <linux/console.h>
|
2019-12-05 17:02:52 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
2012-04-17 22:01:25 +08:00
|
|
|
|
2019-06-23 18:35:42 +08:00
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_ioctl.h>
|
2012-10-03 01:01:07 +08:00
|
|
|
#include <drm/drm_pciids.h>
|
2012-04-17 22:01:25 +08:00
|
|
|
|
2019-06-23 18:35:42 +08:00
|
|
|
#include "mgag200_drv.h"
|
|
|
|
|
2020-05-15 16:32:33 +08:00
|
|
|
int mgag200_modeset = -1;
|
2012-04-17 22:01:25 +08:00
|
|
|
MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
|
|
|
|
module_param_named(modeset, mgag200_modeset, int, 0400);
|
|
|
|
|
2020-06-05 21:57:57 +08:00
|
|
|
/*
|
|
|
|
* DRM driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEFINE_DRM_GEM_FOPS(mgag200_driver_fops);
|
|
|
|
|
2020-06-05 21:57:58 +08:00
|
|
|
static struct drm_driver mgag200_driver = {
|
2020-06-05 21:57:57 +08:00
|
|
|
.driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
|
|
|
|
.fops = &mgag200_driver_fops,
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.desc = DRIVER_DESC,
|
|
|
|
.date = DRIVER_DATE,
|
|
|
|
.major = DRIVER_MAJOR,
|
|
|
|
.minor = DRIVER_MINOR,
|
|
|
|
.patchlevel = DRIVER_PATCHLEVEL,
|
|
|
|
DRM_GEM_SHMEM_DRIVER_OPS,
|
|
|
|
};
|
|
|
|
|
2020-06-05 21:57:59 +08:00
|
|
|
/*
|
|
|
|
* DRM device
|
|
|
|
*/
|
|
|
|
|
2020-06-05 21:58:00 +08:00
|
|
|
static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
|
2020-06-05 21:57:59 +08:00
|
|
|
{
|
2020-06-05 21:58:00 +08:00
|
|
|
struct drm_device *dev = mdev->dev;
|
2020-06-05 21:57:59 +08:00
|
|
|
int ret, option;
|
|
|
|
|
|
|
|
mdev->flags = mgag200_flags_from_driver_data(flags);
|
|
|
|
mdev->type = mgag200_type_from_driver_data(flags);
|
|
|
|
|
|
|
|
pci_read_config_dword(dev->pdev, PCI_MGA_OPTION, &option);
|
|
|
|
mdev->has_sdram = !(option & (1 << 14));
|
|
|
|
|
|
|
|
/* BAR 0 is the framebuffer, BAR 1 contains registers */
|
|
|
|
mdev->rmmio_base = pci_resource_start(dev->pdev, 1);
|
|
|
|
mdev->rmmio_size = pci_resource_len(dev->pdev, 1);
|
|
|
|
|
|
|
|
if (!devm_request_mem_region(dev->dev, mdev->rmmio_base,
|
|
|
|
mdev->rmmio_size, "mgadrmfb_mmio")) {
|
|
|
|
drm_err(dev, "can't reserve mmio registers\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdev->rmmio = pcim_iomap(dev->pdev, 1, 0);
|
|
|
|
if (mdev->rmmio == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* stash G200 SE model number for later use */
|
|
|
|
if (IS_G200_SE(mdev)) {
|
|
|
|
mdev->unique_rev_id = RREG32(0x1e24);
|
|
|
|
drm_dbg(dev, "G200 SE unique revision id is 0x%x\n",
|
|
|
|
mdev->unique_rev_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = mgag200_mm_init(mdev);
|
|
|
|
if (ret)
|
2020-06-05 21:58:00 +08:00
|
|
|
return ret;
|
2020-06-05 21:57:59 +08:00
|
|
|
|
|
|
|
ret = mgag200_modeset_init(mdev);
|
|
|
|
if (ret) {
|
|
|
|
drm_err(dev, "Fatal error during modeset init: %d\n", ret);
|
2020-06-05 21:58:00 +08:00
|
|
|
return ret;
|
2020-06-05 21:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2020-06-05 21:58:00 +08:00
|
|
|
}
|
|
|
|
|
2020-06-05 21:58:01 +08:00
|
|
|
static struct mga_device *
|
|
|
|
mgag200_driver_load(struct pci_dev *pdev, unsigned long flags)
|
2020-06-05 21:58:00 +08:00
|
|
|
{
|
2020-06-05 21:58:01 +08:00
|
|
|
struct drm_device *dev;
|
2020-06-05 21:58:00 +08:00
|
|
|
struct mga_device *mdev;
|
|
|
|
int ret;
|
|
|
|
|
2020-06-05 21:58:01 +08:00
|
|
|
dev = drm_dev_alloc(&mgag200_driver, &pdev->dev);
|
|
|
|
if (IS_ERR(dev))
|
|
|
|
return ERR_CAST(dev);
|
|
|
|
|
|
|
|
dev->pdev = pdev;
|
|
|
|
pci_set_drvdata(pdev, dev);
|
|
|
|
|
2020-06-05 21:58:00 +08:00
|
|
|
mdev = devm_kzalloc(dev->dev, sizeof(struct mga_device), GFP_KERNEL);
|
|
|
|
if (mdev == NULL)
|
2020-06-05 21:58:01 +08:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2020-06-05 21:58:00 +08:00
|
|
|
dev->dev_private = (void *)mdev;
|
|
|
|
mdev->dev = dev;
|
|
|
|
|
|
|
|
ret = mgag200_device_init(mdev, flags);
|
|
|
|
if (ret)
|
2020-06-05 21:58:01 +08:00
|
|
|
goto err_drm_dev_put;
|
2020-06-05 21:58:00 +08:00
|
|
|
|
2020-06-05 21:58:01 +08:00
|
|
|
return mdev;
|
2020-06-05 21:57:59 +08:00
|
|
|
|
2020-06-05 21:58:01 +08:00
|
|
|
err_drm_dev_put:
|
|
|
|
drm_dev_put(dev);
|
2020-06-05 21:57:59 +08:00
|
|
|
dev->dev_private = NULL;
|
2020-06-05 21:58:01 +08:00
|
|
|
return ERR_PTR(ret);
|
2020-06-05 21:57:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mgag200_driver_unload(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct mga_device *mdev = to_mga_device(dev);
|
|
|
|
|
|
|
|
if (mdev == NULL)
|
|
|
|
return;
|
|
|
|
dev->dev_private = NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-05 21:57:57 +08:00
|
|
|
/*
|
|
|
|
* PCI driver
|
|
|
|
*/
|
2012-04-17 22:01:25 +08:00
|
|
|
|
2020-06-05 21:57:58 +08:00
|
|
|
static const struct pci_device_id mgag200_pciidlist[] = {
|
2019-12-06 16:19:01 +08:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
|
2019-11-26 18:15:29 +08:00
|
|
|
G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
|
2012-04-17 22:01:25 +08: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 21:24:05 +08:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
|
2016-10-22 00:47:07 +08:00
|
|
|
{ PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
|
2012-04-17 22:01:25 +08:00
|
|
|
{0,}
|
|
|
|
};
|
|
|
|
|
2020-06-05 21:57:58 +08:00
|
|
|
MODULE_DEVICE_TABLE(pci, mgag200_pciidlist);
|
2012-04-17 22:01:25 +08:00
|
|
|
|
2020-06-05 21:57:58 +08:00
|
|
|
static int
|
|
|
|
mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
2012-04-17 22:01:25 +08:00
|
|
|
{
|
2020-06-05 21:58:01 +08:00
|
|
|
struct mga_device *mdev;
|
2019-12-05 17:02:52 +08:00
|
|
|
struct drm_device *dev;
|
|
|
|
int ret;
|
|
|
|
|
2019-08-22 17:06:44 +08:00
|
|
|
drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb");
|
2012-06-01 18:12:39 +08:00
|
|
|
|
2020-06-05 21:57:52 +08:00
|
|
|
ret = pcim_enable_device(pdev);
|
2019-12-05 17:02:52 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-06-05 21:58:01 +08:00
|
|
|
mdev = mgag200_driver_load(pdev, ent->driver_data);
|
|
|
|
if (IS_ERR(mdev))
|
|
|
|
return PTR_ERR(mdev);
|
|
|
|
dev = mdev->dev;
|
2019-12-05 17:02:52 +08:00
|
|
|
|
|
|
|
ret = drm_dev_register(dev, ent->driver_data);
|
|
|
|
if (ret)
|
|
|
|
goto err_mgag200_driver_unload;
|
|
|
|
|
2020-04-08 16:26:37 +08:00
|
|
|
drm_fbdev_generic_setup(dev, 0);
|
|
|
|
|
2019-12-05 17:02:52 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_mgag200_driver_unload:
|
|
|
|
mgag200_driver_unload(dev);
|
|
|
|
drm_dev_put(dev);
|
|
|
|
return ret;
|
2012-04-17 22:01:25 +08:00
|
|
|
}
|
|
|
|
|
2020-06-05 21:57:58 +08:00
|
|
|
static void mgag200_pci_remove(struct pci_dev *pdev)
|
2012-04-17 22:01:25 +08:00
|
|
|
{
|
|
|
|
struct drm_device *dev = pci_get_drvdata(pdev);
|
|
|
|
|
2019-12-05 17:02:52 +08:00
|
|
|
drm_dev_unregister(dev);
|
|
|
|
mgag200_driver_unload(dev);
|
|
|
|
drm_dev_put(dev);
|
2012-04-17 22:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_driver mgag200_pci_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2020-06-05 21:57:58 +08:00
|
|
|
.id_table = mgag200_pciidlist,
|
|
|
|
.probe = mgag200_pci_probe,
|
|
|
|
.remove = mgag200_pci_remove,
|
2012-04-17 22:01:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mgag200_init(void)
|
|
|
|
{
|
|
|
|
if (vgacon_text_force() && mgag200_modeset == -1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (mgag200_modeset == 0)
|
|
|
|
return -EINVAL;
|
2017-05-24 22:51:40 +08:00
|
|
|
|
|
|
|
return pci_register_driver(&mgag200_pci_driver);
|
2012-04-17 22:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mgag200_exit(void)
|
|
|
|
{
|
2017-05-24 22:51:40 +08:00
|
|
|
pci_unregister_driver(&mgag200_pci_driver);
|
2012-04-17 22:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mgag200_init);
|
|
|
|
module_exit(mgag200_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|