1 /* $NetBSD: sis_drv.c,v 1.4 2021/12/18 23:45:44 riastradh Exp $ */
2
3 /* sis.c -- sis driver -*- linux-c -*-
4 *
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: sis_drv.c,v 1.4 2021/12/18 23:45:44 riastradh Exp $");
32
33 #include <linux/module.h>
34 #include <linux/pci.h>
35
36 #include <drm/drm_drv.h>
37 #include <drm/drm_file.h>
38 #include <drm/drm_pciids.h>
39 #include <drm/sis_drm.h>
40
41 #include "sis_drv.h"
42
43 static struct pci_device_id pciidlist[] = {
44 sisdrv_PCI_IDS
45 };
46
sis_driver_load(struct drm_device * dev,unsigned long chipset)47 static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
48 {
49 drm_sis_private_t *dev_priv;
50
51 pci_set_master(dev->pdev);
52
53 dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL);
54 if (dev_priv == NULL)
55 return -ENOMEM;
56
57 idr_init(&dev_priv->object_idr);
58 dev->dev_private = (void *)dev_priv;
59 dev_priv->chipset = chipset;
60
61 return 0;
62 }
63
sis_driver_unload(struct drm_device * dev)64 static void sis_driver_unload(struct drm_device *dev)
65 {
66 drm_sis_private_t *dev_priv = dev->dev_private;
67
68 idr_destroy(&dev_priv->object_idr);
69
70 kfree(dev_priv);
71 }
72
73 static const struct file_operations sis_driver_fops = {
74 .owner = THIS_MODULE,
75 .open = drm_open,
76 .release = drm_release,
77 .unlocked_ioctl = drm_ioctl,
78 .mmap = drm_legacy_mmap,
79 .poll = drm_poll,
80 .compat_ioctl = drm_compat_ioctl,
81 .llseek = noop_llseek,
82 };
83
sis_driver_open(struct drm_device * dev,struct drm_file * file)84 static int sis_driver_open(struct drm_device *dev, struct drm_file *file)
85 {
86 struct sis_file_private *file_priv;
87
88 DRM_DEBUG_DRIVER("\n");
89 file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
90 if (!file_priv)
91 return -ENOMEM;
92
93 file->driver_priv = file_priv;
94
95 INIT_LIST_HEAD(&file_priv->obj_list);
96
97 return 0;
98 }
99
sis_driver_postclose(struct drm_device * dev,struct drm_file * file)100 static void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
101 {
102 struct sis_file_private *file_priv = file->driver_priv;
103
104 kfree(file_priv);
105 }
106
107 static struct drm_driver driver = {
108 .driver_features = DRIVER_USE_AGP | DRIVER_LEGACY,
109 .load = sis_driver_load,
110 .unload = sis_driver_unload,
111 .open = sis_driver_open,
112 .preclose = sis_reclaim_buffers_locked,
113 .postclose = sis_driver_postclose,
114 .dma_quiescent = sis_idle,
115 .lastclose = sis_lastclose,
116 .ioctls = sis_ioctls,
117 .fops = &sis_driver_fops,
118 .name = DRIVER_NAME,
119 .desc = DRIVER_DESC,
120 .date = DRIVER_DATE,
121 .major = DRIVER_MAJOR,
122 .minor = DRIVER_MINOR,
123 .patchlevel = DRIVER_PATCHLEVEL,
124 };
125
126 static struct pci_driver sis_pci_driver = {
127 .name = DRIVER_NAME,
128 .id_table = pciidlist,
129 };
130
sis_init(void)131 static int __init sis_init(void)
132 {
133 driver.num_ioctls = sis_max_ioctl;
134 return drm_legacy_pci_init(&driver, &sis_pci_driver);
135 }
136
sis_exit(void)137 static void __exit sis_exit(void)
138 {
139 drm_legacy_pci_exit(&driver, &sis_pci_driver);
140 }
141
142 module_init(sis_init);
143 module_exit(sis_exit);
144
145 MODULE_AUTHOR(DRIVER_AUTHOR);
146 MODULE_DESCRIPTION(DRIVER_DESC);
147 MODULE_LICENSE("GPL and additional rights");
148