11.2Sriastrad/*	$NetBSD: r128_drv.c,v 1.5 2021/12/18 23:45:42 riastradh Exp $	*/
21.2Sriastrad
31.1Sriastrad/* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
41.1Sriastrad * Created: Mon Dec 13 09:47:27 1999 by faith@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: r128_drv.c,v 1.5 2021/12/18 23:45:42 riastradh Exp $");
361.2Sriastrad
371.1Sriastrad#include <linux/module.h>
381.5Sriastrad#include <linux/pci.h>
391.1Sriastrad
401.5Sriastrad#include <drm/drm_drv.h>
411.5Sriastrad#include <drm/drm_file.h>
421.5Sriastrad#include <drm/drm_pciids.h>
431.5Sriastrad#include <drm/drm_vblank.h>
441.1Sriastrad#include <drm/r128_drm.h>
451.5Sriastrad
461.1Sriastrad#include "r128_drv.h"
471.1Sriastrad
481.1Sriastradstatic struct pci_device_id pciidlist[] = {
491.1Sriastrad	r128_PCI_IDS
501.1Sriastrad};
511.1Sriastrad
521.1Sriastradstatic const struct file_operations r128_driver_fops = {
531.1Sriastrad	.owner = THIS_MODULE,
541.1Sriastrad	.open = drm_open,
551.1Sriastrad	.release = drm_release,
561.1Sriastrad	.unlocked_ioctl = drm_ioctl,
571.2Sriastrad	.mmap = drm_legacy_mmap,
581.1Sriastrad	.poll = drm_poll,
591.1Sriastrad#ifdef CONFIG_COMPAT
601.1Sriastrad	.compat_ioctl = r128_compat_ioctl,
611.1Sriastrad#endif
621.1Sriastrad	.llseek = noop_llseek,
631.1Sriastrad};
641.1Sriastrad
651.1Sriastradstatic struct drm_driver driver = {
661.1Sriastrad	.driver_features =
671.5Sriastrad	    DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | DRIVER_LEGACY |
681.5Sriastrad	    DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ,
691.1Sriastrad	.dev_priv_size = sizeof(drm_r128_buf_priv_t),
701.1Sriastrad	.load = r128_driver_load,
711.1Sriastrad	.preclose = r128_driver_preclose,
721.1Sriastrad	.lastclose = r128_driver_lastclose,
731.1Sriastrad	.get_vblank_counter = r128_get_vblank_counter,
741.1Sriastrad	.enable_vblank = r128_enable_vblank,
751.1Sriastrad	.disable_vblank = r128_disable_vblank,
761.1Sriastrad	.irq_preinstall = r128_driver_irq_preinstall,
771.1Sriastrad	.irq_postinstall = r128_driver_irq_postinstall,
781.1Sriastrad	.irq_uninstall = r128_driver_irq_uninstall,
791.1Sriastrad	.irq_handler = r128_driver_irq_handler,
801.3Sriastrad#ifdef __NetBSD__
811.3Sriastrad	.request_irq = drm_pci_request_irq,
821.3Sriastrad	.free_irq = drm_pci_free_irq,
831.3Sriastrad#endif
841.1Sriastrad	.ioctls = r128_ioctls,
851.1Sriastrad	.dma_ioctl = r128_cce_buffers,
861.1Sriastrad	.fops = &r128_driver_fops,
871.1Sriastrad	.name = DRIVER_NAME,
881.1Sriastrad	.desc = DRIVER_DESC,
891.1Sriastrad	.date = DRIVER_DATE,
901.1Sriastrad	.major = DRIVER_MAJOR,
911.1Sriastrad	.minor = DRIVER_MINOR,
921.1Sriastrad	.patchlevel = DRIVER_PATCHLEVEL,
931.1Sriastrad};
941.1Sriastrad
951.1Sriastradint r128_driver_load(struct drm_device *dev, unsigned long flags)
961.1Sriastrad{
971.1Sriastrad	pci_set_master(dev->pdev);
981.1Sriastrad	return drm_vblank_init(dev, 1);
991.1Sriastrad}
1001.1Sriastrad
1011.1Sriastradstatic struct pci_driver r128_pci_driver = {
1021.1Sriastrad	.name = DRIVER_NAME,
1031.1Sriastrad	.id_table = pciidlist,
1041.1Sriastrad};
1051.1Sriastrad
1061.1Sriastradstatic int __init r128_init(void)
1071.1Sriastrad{
1081.1Sriastrad	driver.num_ioctls = r128_max_ioctl;
1091.1Sriastrad
1101.5Sriastrad	return drm_legacy_pci_init(&driver, &r128_pci_driver);
1111.1Sriastrad}
1121.1Sriastrad
1131.1Sriastradstatic void __exit r128_exit(void)
1141.1Sriastrad{
1151.5Sriastrad	drm_legacy_pci_exit(&driver, &r128_pci_driver);
1161.1Sriastrad}
1171.1Sriastrad
1181.1Sriastradmodule_init(r128_init);
1191.1Sriastradmodule_exit(r128_exit);
1201.1Sriastrad
1211.1SriastradMODULE_AUTHOR(DRIVER_AUTHOR);
1221.1SriastradMODULE_DESCRIPTION(DRIVER_DESC);
1231.1SriastradMODULE_LICENSE("GPL and additional rights");
124