11.2Sriastrad/*	$NetBSD: savage_drv.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $	*/
21.2Sriastrad
31.1Sriastrad/* savage_drv.c -- Savage driver for Linux
41.1Sriastrad *
51.1Sriastrad * Copyright 2004  Felix Kuehling
61.1Sriastrad * All Rights Reserved.
71.1Sriastrad *
81.1Sriastrad * Permission is hereby granted, free of charge, to any person obtaining a
91.1Sriastrad * copy of this software and associated documentation files (the "Software"),
101.1Sriastrad * to deal in the Software without restriction, including without limitation
111.1Sriastrad * the rights to use, copy, modify, merge, publish, distribute, sub license,
121.1Sriastrad * and/or sell copies of the Software, and to permit persons to whom the
131.1Sriastrad * Software is furnished to do so, subject to the following conditions:
141.1Sriastrad *
151.1Sriastrad * The above copyright notice and this permission notice (including the
161.1Sriastrad * next paragraph) shall be included in all copies or substantial portions
171.1Sriastrad * of the Software.
181.1Sriastrad *
191.1Sriastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
201.1Sriastrad * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
211.1Sriastrad * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
221.1Sriastrad * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR
231.1Sriastrad * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
241.1Sriastrad * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
251.1Sriastrad * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
261.1Sriastrad */
271.1Sriastrad
281.2Sriastrad#include <sys/cdefs.h>
291.2Sriastrad__KERNEL_RCSID(0, "$NetBSD: savage_drv.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $");
301.2Sriastrad
311.1Sriastrad#include <linux/module.h>
321.4Sriastrad#include <linux/pci.h>
331.4Sriastrad
341.4Sriastrad#include <drm/drm_drv.h>
351.4Sriastrad#include <drm/drm_file.h>
361.4Sriastrad#include <drm/drm_pciids.h>
371.1Sriastrad
381.1Sriastrad#include "savage_drv.h"
391.1Sriastrad
401.1Sriastradstatic struct pci_device_id pciidlist[] = {
411.1Sriastrad	savage_PCI_IDS
421.1Sriastrad};
431.1Sriastrad
441.1Sriastradstatic const struct file_operations savage_driver_fops = {
451.1Sriastrad	.owner = THIS_MODULE,
461.1Sriastrad	.open = drm_open,
471.1Sriastrad	.release = drm_release,
481.1Sriastrad	.unlocked_ioctl = drm_ioctl,
491.2Sriastrad	.mmap = drm_legacy_mmap,
501.1Sriastrad	.poll = drm_poll,
511.1Sriastrad	.compat_ioctl = drm_compat_ioctl,
521.1Sriastrad	.llseek = noop_llseek,
531.1Sriastrad};
541.1Sriastrad
551.1Sriastradstatic struct drm_driver driver = {
561.1Sriastrad	.driver_features =
571.4Sriastrad	    DRIVER_USE_AGP | DRIVER_HAVE_DMA | DRIVER_PCI_DMA | DRIVER_LEGACY,
581.1Sriastrad	.dev_priv_size = sizeof(drm_savage_buf_priv_t),
591.1Sriastrad	.load = savage_driver_load,
601.1Sriastrad	.firstopen = savage_driver_firstopen,
611.1Sriastrad	.preclose = savage_reclaim_buffers,
621.1Sriastrad	.lastclose = savage_driver_lastclose,
631.1Sriastrad	.unload = savage_driver_unload,
641.1Sriastrad	.ioctls = savage_ioctls,
651.1Sriastrad	.dma_ioctl = savage_bci_buffers,
661.1Sriastrad	.fops = &savage_driver_fops,
671.1Sriastrad	.name = DRIVER_NAME,
681.1Sriastrad	.desc = DRIVER_DESC,
691.1Sriastrad	.date = DRIVER_DATE,
701.1Sriastrad	.major = DRIVER_MAJOR,
711.1Sriastrad	.minor = DRIVER_MINOR,
721.1Sriastrad	.patchlevel = DRIVER_PATCHLEVEL,
731.1Sriastrad};
741.1Sriastrad
751.1Sriastradstatic struct pci_driver savage_pci_driver = {
761.1Sriastrad	.name = DRIVER_NAME,
771.1Sriastrad	.id_table = pciidlist,
781.1Sriastrad};
791.1Sriastrad
801.1Sriastradstatic int __init savage_init(void)
811.1Sriastrad{
821.1Sriastrad	driver.num_ioctls = savage_max_ioctl;
831.4Sriastrad	return drm_legacy_pci_init(&driver, &savage_pci_driver);
841.1Sriastrad}
851.1Sriastrad
861.1Sriastradstatic void __exit savage_exit(void)
871.1Sriastrad{
881.4Sriastrad	drm_legacy_pci_exit(&driver, &savage_pci_driver);
891.1Sriastrad}
901.1Sriastrad
911.1Sriastradmodule_init(savage_init);
921.1Sriastradmodule_exit(savage_exit);
931.1Sriastrad
941.1SriastradMODULE_AUTHOR(DRIVER_AUTHOR);
951.1SriastradMODULE_DESCRIPTION(DRIVER_DESC);
961.1SriastradMODULE_LICENSE("GPL and additional rights");
97