11.2Sriastrad/*	$NetBSD: mga_drv.c,v 1.5 2021/12/18 23:45:32 riastradh Exp $	*/
21.2Sriastrad
31.1Sriastrad/* mga_drv.c -- Matrox G200/G400 driver -*- linux-c -*-
41.1Sriastrad * Created: Mon Dec 13 01:56:22 1999 by jhartmann@precisioninsight.com
51.1Sriastrad *
61.1Sriastrad * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
71.1Sriastrad * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
81.1Sriastrad * All Rights Reserved.
91.1Sriastrad *
101.1Sriastrad * Permission is hereby granted, free of charge, to any person obtaining a
111.1Sriastrad * copy of this software and associated documentation files (the "Software"),
121.1Sriastrad * to deal in the Software without restriction, including without limitation
131.1Sriastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense,
141.1Sriastrad * and/or sell copies of the Software, and to permit persons to whom the
151.1Sriastrad * Software is furnished to do so, subject to the following conditions:
161.1Sriastrad *
171.1Sriastrad * The above copyright notice and this permission notice (including the next
181.1Sriastrad * paragraph) shall be included in all copies or substantial portions of the
191.1Sriastrad * Software.
201.1Sriastrad *
211.1Sriastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
221.1Sriastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
231.1Sriastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
241.1Sriastrad * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
251.1Sriastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
261.1Sriastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
271.1Sriastrad * OTHER DEALINGS IN THE SOFTWARE.
281.1Sriastrad *
291.1Sriastrad * Authors:
301.1Sriastrad *    Rickard E. (Rik) Faith <faith@valinux.com>
311.1Sriastrad *    Gareth Hughes <gareth@valinux.com>
321.1Sriastrad */
331.1Sriastrad
341.2Sriastrad#include <sys/cdefs.h>
351.2Sriastrad__KERNEL_RCSID(0, "$NetBSD: mga_drv.c,v 1.5 2021/12/18 23:45:32 riastradh Exp $");
361.2Sriastrad
371.1Sriastrad#include <linux/module.h>
381.1Sriastrad
391.5Sriastrad#include <drm/drm_drv.h>
401.1Sriastrad#include <drm/drm_pciids.h>
411.1Sriastrad
421.5Sriastrad#include "mga_drv.h"
431.1Sriastrad
441.1Sriastradstatic struct pci_device_id pciidlist[] = {
451.1Sriastrad	mga_PCI_IDS
461.1Sriastrad};
471.1Sriastrad
481.1Sriastradstatic const struct file_operations mga_driver_fops = {
491.1Sriastrad	.owner = THIS_MODULE,
501.1Sriastrad	.open = drm_open,
511.1Sriastrad	.release = drm_release,
521.1Sriastrad	.unlocked_ioctl = drm_ioctl,
531.2Sriastrad	.mmap = drm_legacy_mmap,
541.1Sriastrad	.poll = drm_poll,
551.1Sriastrad#ifdef CONFIG_COMPAT
561.1Sriastrad	.compat_ioctl = mga_compat_ioctl,
571.1Sriastrad#endif
581.1Sriastrad	.llseek = noop_llseek,
591.1Sriastrad};
601.1Sriastrad
611.1Sriastradstatic struct drm_driver driver = {
621.1Sriastrad	.driver_features =
631.5Sriastrad	    DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_LEGACY |
641.5Sriastrad	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ,
651.1Sriastrad	.dev_priv_size = sizeof(drm_mga_buf_priv_t),
661.1Sriastrad	.load = mga_driver_load,
671.1Sriastrad	.unload = mga_driver_unload,
681.1Sriastrad	.lastclose = mga_driver_lastclose,
691.1Sriastrad	.dma_quiescent = mga_driver_dma_quiescent,
701.1Sriastrad	.get_vblank_counter = mga_get_vblank_counter,
711.1Sriastrad	.enable_vblank = mga_enable_vblank,
721.1Sriastrad	.disable_vblank = mga_disable_vblank,
731.1Sriastrad	.irq_preinstall = mga_driver_irq_preinstall,
741.1Sriastrad	.irq_postinstall = mga_driver_irq_postinstall,
751.1Sriastrad	.irq_uninstall = mga_driver_irq_uninstall,
761.1Sriastrad	.irq_handler = mga_driver_irq_handler,
771.3Sriastrad#ifdef __NetBSD__
781.3Sriastrad	.request_irq = drm_pci_request_irq,
791.3Sriastrad	.free_irq = drm_pci_free_irq,
801.3Sriastrad#endif
811.1Sriastrad	.ioctls = mga_ioctls,
821.1Sriastrad	.dma_ioctl = mga_dma_buffers,
831.1Sriastrad	.fops = &mga_driver_fops,
841.1Sriastrad	.name = DRIVER_NAME,
851.1Sriastrad	.desc = DRIVER_DESC,
861.1Sriastrad	.date = DRIVER_DATE,
871.1Sriastrad	.major = DRIVER_MAJOR,
881.1Sriastrad	.minor = DRIVER_MINOR,
891.1Sriastrad	.patchlevel = DRIVER_PATCHLEVEL,
901.1Sriastrad};
911.1Sriastrad
921.1Sriastradstatic struct pci_driver mga_pci_driver = {
931.1Sriastrad	.name = DRIVER_NAME,
941.1Sriastrad	.id_table = pciidlist,
951.1Sriastrad};
961.1Sriastrad
971.1Sriastradstatic int __init mga_init(void)
981.1Sriastrad{
991.1Sriastrad	driver.num_ioctls = mga_max_ioctl;
1001.5Sriastrad	return drm_legacy_pci_init(&driver, &mga_pci_driver);
1011.1Sriastrad}
1021.1Sriastrad
1031.1Sriastradstatic void __exit mga_exit(void)
1041.1Sriastrad{
1051.5Sriastrad	drm_legacy_pci_exit(&driver, &mga_pci_driver);
1061.1Sriastrad}
1071.1Sriastrad
1081.1Sriastradmodule_init(mga_init);
1091.1Sriastradmodule_exit(mga_exit);
1101.1Sriastrad
1111.1SriastradMODULE_AUTHOR(DRIVER_AUTHOR);
1121.1SriastradMODULE_DESCRIPTION(DRIVER_DESC);
1131.1SriastradMODULE_LICENSE("GPL and additional rights");
114