Home | History | Annotate | Line # | Download | only in via
      1 /*	$NetBSD: via_drv.c,v 1.9 2021/12/19 12:30:23 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
      5  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
      6  *
      7  * Permission is hereby granted, free of charge, to any person obtaining a
      8  * copy of this software and associated documentation files (the "Software"),
      9  * to deal in the Software without restriction, including without limitation
     10  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     11  * and/or sell copies of the Software, and to permit persons to whom the
     12  * Software is furnished to do so, subject to the following conditions:
     13  *
     14  * The above copyright notice and this permission notice (including the
     15  * next paragraph) shall be included in all copies or substantial portions
     16  * of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     21  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     24  * DEALINGS IN THE SOFTWARE.
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: via_drv.c,v 1.9 2021/12/19 12:30:23 riastradh Exp $");
     29 
     30 #include <linux/module.h>
     31 #include <linux/pci.h>
     32 
     33 #include <drm/drm_drv.h>
     34 #include <drm/drm_file.h>
     35 #include <drm/drm_pci.h>
     36 #include <drm/drm_pciids.h>
     37 #include <drm/via_drm.h>
     38 
     39 #include "via_drv.h"
     40 
     41 
     42 static int via_driver_open(struct drm_device *dev, struct drm_file *file)
     43 {
     44 	struct via_file_private *file_priv;
     45 
     46 	DRM_DEBUG_DRIVER("\n");
     47 	file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
     48 	if (!file_priv)
     49 		return -ENOMEM;
     50 
     51 	file->driver_priv = file_priv;
     52 
     53 	INIT_LIST_HEAD(&file_priv->obj_list);
     54 
     55 	return 0;
     56 }
     57 
     58 static void via_driver_postclose(struct drm_device *dev, struct drm_file *file)
     59 {
     60 	struct via_file_private *file_priv = file->driver_priv;
     61 
     62 	kfree(file_priv);
     63 }
     64 
     65 #ifndef __NetBSD__
     66 static struct pci_device_id pciidlist[] = {
     67 	viadrv_PCI_IDS
     68 };
     69 
     70 static const struct file_operations via_driver_fops = {
     71 	.owner = THIS_MODULE,
     72 	.open = drm_open,
     73 	.release = drm_release,
     74 	.unlocked_ioctl = drm_ioctl,
     75 	.mmap = drm_legacy_mmap,
     76 	.poll = drm_poll,
     77 	.compat_ioctl = drm_compat_ioctl,
     78 	.llseek = noop_llseek,
     79 };
     80 #endif
     81 
     82 static struct drm_driver driver = {
     83 	.driver_features =
     84 	    DRIVER_USE_AGP | DRIVER_HAVE_IRQ | DRIVER_LEGACY,
     85 	.load = via_driver_load,
     86 	.unload = via_driver_unload,
     87 	.open = via_driver_open,
     88 	.preclose = via_reclaim_buffers_locked,
     89 	.postclose = via_driver_postclose,
     90 	.context_dtor = via_final_context,
     91 	.get_vblank_counter = via_get_vblank_counter,
     92 	.enable_vblank = via_enable_vblank,
     93 	.disable_vblank = via_disable_vblank,
     94 	.irq_preinstall = via_driver_irq_preinstall,
     95 	.irq_postinstall = via_driver_irq_postinstall,
     96 	.irq_uninstall = via_driver_irq_uninstall,
     97 	.irq_handler = via_driver_irq_handler,
     98 #ifdef __NetBSD__
     99 	.request_irq = drm_pci_request_irq,
    100 	.free_irq = drm_pci_free_irq,
    101 #endif
    102 	.dma_quiescent = via_driver_dma_quiescent,
    103 	.lastclose = via_lastclose,
    104 	.ioctls = via_ioctls,
    105 #ifndef __NetBSD__
    106 	.fops = &via_driver_fops,
    107 #else
    108 	.mmap_object = drm_legacy_mmap_object,
    109 #endif
    110 	.name = DRIVER_NAME,
    111 	.desc = DRIVER_DESC,
    112 	.date = DRIVER_DATE,
    113 	.major = DRIVER_MAJOR,
    114 	.minor = DRIVER_MINOR,
    115 	.patchlevel = DRIVER_PATCHLEVEL,
    116 };
    117 
    118 #ifdef __NetBSD__
    119 struct drm_driver *const via_drm_driver = &driver;
    120 #endif
    121 
    122 #ifndef __NetBSD__
    123 static struct pci_driver via_pci_driver = {
    124 	.name = DRIVER_NAME,
    125 	.id_table = viadrm_pciidlist,
    126 };
    127 
    128 static int __init via_init(void)
    129 {
    130 	driver.num_ioctls = via_max_ioctl;
    131 	via_init_command_verifier();
    132 	return drm_legacy_pci_init(&driver, &via_pci_driver);
    133 }
    134 
    135 static void __exit via_exit(void)
    136 {
    137 	drm_legacy_pci_exit(&driver, &via_pci_driver);
    138 }
    139 #endif	/* __NetBSD__ */
    140 
    141 module_init(via_init);
    142 module_exit(via_exit);
    143 
    144 MODULE_AUTHOR(DRIVER_AUTHOR);
    145 MODULE_DESCRIPTION(DRIVER_DESC);
    146 MODULE_LICENSE("GPL and additional rights");
    147