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