Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright 2012 Red Hat
  4 *
 
 
 
 
  5 * Authors: Matthew Garrett
  6 *          Dave Airlie
  7 */
  8
  9#include <linux/module.h>
 10#include <linux/console.h>
 11
 12#include <drm/drm_drv.h>
 13#include <drm/drm_file.h>
 14#include <drm/drm_ioctl.h>
 15#include <drm/drm_pci.h>
 16#include <drm/drm_pciids.h>
 17
 18#include "mgag200_drv.h"
 19
 
 
 20/*
 21 * This is the generic driver code. This binds the driver to the drm core,
 22 * which then performs further device association and calls our graphics init
 23 * functions
 24 */
 25int mgag200_modeset = -1;
 26
 27MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
 28module_param_named(modeset, mgag200_modeset, int, 0400);
 29
 30static struct drm_driver driver;
 31
 32static const struct pci_device_id pciidlist[] = {
 33	{ PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
 34	{ PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
 35	{ PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
 36	{ PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
 37	{ PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
 38	{ PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
 39	{ PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
 40	{ PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
 41	{0,}
 42};
 43
 44MODULE_DEVICE_TABLE(pci, pciidlist);
 45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 46
 47static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 48{
 49	drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
 50
 51	return drm_get_pci_dev(pdev, ent, &driver);
 52}
 53
 54static void mga_pci_remove(struct pci_dev *pdev)
 55{
 56	struct drm_device *dev = pci_get_drvdata(pdev);
 57
 58	drm_put_dev(dev);
 59}
 60
 61static const struct file_operations mgag200_driver_fops = {
 62	.owner = THIS_MODULE,
 63	DRM_VRAM_MM_FILE_OPERATIONS
 
 
 
 
 
 
 64};
 65
 66static struct drm_driver driver = {
 67	.driver_features = DRIVER_GEM | DRIVER_MODESET,
 68	.load = mgag200_driver_load,
 69	.unload = mgag200_driver_unload,
 
 70	.fops = &mgag200_driver_fops,
 71	.name = DRIVER_NAME,
 72	.desc = DRIVER_DESC,
 73	.date = DRIVER_DATE,
 74	.major = DRIVER_MAJOR,
 75	.minor = DRIVER_MINOR,
 76	.patchlevel = DRIVER_PATCHLEVEL,
 77	DRM_GEM_VRAM_DRIVER
 
 
 
 
 78};
 79
 80static struct pci_driver mgag200_pci_driver = {
 81	.name = DRIVER_NAME,
 82	.id_table = pciidlist,
 83	.probe = mga_pci_probe,
 84	.remove = mga_pci_remove,
 85};
 86
 87static int __init mgag200_init(void)
 88{
 89	if (vgacon_text_force() && mgag200_modeset == -1)
 90		return -EINVAL;
 91
 92	if (mgag200_modeset == 0)
 93		return -EINVAL;
 94
 95	return pci_register_driver(&mgag200_pci_driver);
 96}
 97
 98static void __exit mgag200_exit(void)
 99{
100	pci_unregister_driver(&mgag200_pci_driver);
101}
102
103module_init(mgag200_init);
104module_exit(mgag200_exit);
105
106MODULE_AUTHOR(DRIVER_AUTHOR);
107MODULE_DESCRIPTION(DRIVER_DESC);
108MODULE_LICENSE("GPL");
v4.10.11
 
  1/*
  2 * Copyright 2012 Red Hat
  3 *
  4 * This file is subject to the terms and conditions of the GNU General
  5 * Public License version 2. See the file COPYING in the main
  6 * directory of this archive for more details.
  7 *
  8 * Authors: Matthew Garrett
  9 *          Dave Airlie
 10 */
 
 11#include <linux/module.h>
 12#include <linux/console.h>
 13#include <drm/drmP.h>
 
 
 
 
 
 14
 15#include "mgag200_drv.h"
 16
 17#include <drm/drm_pciids.h>
 18
 19/*
 20 * This is the generic driver code. This binds the driver to the drm core,
 21 * which then performs further device association and calls our graphics init
 22 * functions
 23 */
 24int mgag200_modeset = -1;
 25
 26MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
 27module_param_named(modeset, mgag200_modeset, int, 0400);
 28
 29static struct drm_driver driver;
 30
 31static const struct pci_device_id pciidlist[] = {
 32	{ PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
 33	{ PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
 34	{ PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
 35	{ PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
 36	{ PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
 37	{ PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
 38	{ PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
 
 39	{0,}
 40};
 41
 42MODULE_DEVICE_TABLE(pci, pciidlist);
 43
 44static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
 45{
 46	struct apertures_struct *ap;
 47	bool primary = false;
 48
 49	ap = alloc_apertures(1);
 50	if (!ap)
 51		return;
 52
 53	ap->ranges[0].base = pci_resource_start(pdev, 0);
 54	ap->ranges[0].size = pci_resource_len(pdev, 0);
 55
 56#ifdef CONFIG_X86
 57	primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
 58#endif
 59	drm_fb_helper_remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
 60	kfree(ap);
 61}
 62
 63
 64static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 65{
 66	mgag200_kick_out_firmware_fb(pdev);
 67
 68	return drm_get_pci_dev(pdev, ent, &driver);
 69}
 70
 71static void mga_pci_remove(struct pci_dev *pdev)
 72{
 73	struct drm_device *dev = pci_get_drvdata(pdev);
 74
 75	drm_put_dev(dev);
 76}
 77
 78static const struct file_operations mgag200_driver_fops = {
 79	.owner = THIS_MODULE,
 80	.open = drm_open,
 81	.release = drm_release,
 82	.unlocked_ioctl = drm_ioctl,
 83	.mmap = mgag200_mmap,
 84	.poll = drm_poll,
 85	.compat_ioctl = drm_compat_ioctl,
 86	.read = drm_read,
 87};
 88
 89static struct drm_driver driver = {
 90	.driver_features = DRIVER_GEM | DRIVER_MODESET,
 91	.load = mgag200_driver_load,
 92	.unload = mgag200_driver_unload,
 93	.set_busid = drm_pci_set_busid,
 94	.fops = &mgag200_driver_fops,
 95	.name = DRIVER_NAME,
 96	.desc = DRIVER_DESC,
 97	.date = DRIVER_DATE,
 98	.major = DRIVER_MAJOR,
 99	.minor = DRIVER_MINOR,
100	.patchlevel = DRIVER_PATCHLEVEL,
101
102	.gem_free_object_unlocked = mgag200_gem_free_object,
103	.dumb_create = mgag200_dumb_create,
104	.dumb_map_offset = mgag200_dumb_mmap_offset,
105	.dumb_destroy = drm_gem_dumb_destroy,
106};
107
108static struct pci_driver mgag200_pci_driver = {
109	.name = DRIVER_NAME,
110	.id_table = pciidlist,
111	.probe = mga_pci_probe,
112	.remove = mga_pci_remove,
113};
114
115static int __init mgag200_init(void)
116{
117	if (vgacon_text_force() && mgag200_modeset == -1)
118		return -EINVAL;
119
120	if (mgag200_modeset == 0)
121		return -EINVAL;
122	return drm_pci_init(&driver, &mgag200_pci_driver);
 
123}
124
125static void __exit mgag200_exit(void)
126{
127	drm_pci_exit(&driver, &mgag200_pci_driver);
128}
129
130module_init(mgag200_init);
131module_exit(mgag200_exit);
132
133MODULE_AUTHOR(DRIVER_AUTHOR);
134MODULE_DESCRIPTION(DRIVER_DESC);
135MODULE_LICENSE("GPL");