sis_drv.c revision 1.2
1/*	$NetBSD: sis_drv.c,v 1.2 2018/08/27 04:58:36 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.2 2018/08/27 04:58:36 riastradh Exp $");
32
33#include <linux/module.h>
34
35#include <drm/drmP.h>
36#include <drm/sis_drm.h>
37#include "sis_drv.h"
38
39#include <drm/drm_pciids.h>
40
41static struct pci_device_id pciidlist[] = {
42	sisdrv_PCI_IDS
43};
44
45static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
46{
47	drm_sis_private_t *dev_priv;
48
49	pci_set_master(dev->pdev);
50
51	dev_priv = kzalloc(sizeof(drm_sis_private_t), GFP_KERNEL);
52	if (dev_priv == NULL)
53		return -ENOMEM;
54
55	idr_init(&dev_priv->object_idr);
56	dev->dev_private = (void *)dev_priv;
57	dev_priv->chipset = chipset;
58
59	return 0;
60}
61
62static int sis_driver_unload(struct drm_device *dev)
63{
64	drm_sis_private_t *dev_priv = dev->dev_private;
65
66	idr_destroy(&dev_priv->object_idr);
67
68	kfree(dev_priv);
69
70	return 0;
71}
72
73static 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#ifdef CONFIG_COMPAT
81	.compat_ioctl = drm_compat_ioctl,
82#endif
83	.llseek = noop_llseek,
84};
85
86static int sis_driver_open(struct drm_device *dev, struct drm_file *file)
87{
88	struct sis_file_private *file_priv;
89
90	DRM_DEBUG_DRIVER("\n");
91	file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
92	if (!file_priv)
93		return -ENOMEM;
94
95	file->driver_priv = file_priv;
96
97	INIT_LIST_HEAD(&file_priv->obj_list);
98
99	return 0;
100}
101
102static void sis_driver_postclose(struct drm_device *dev, struct drm_file *file)
103{
104	struct sis_file_private *file_priv = file->driver_priv;
105
106	kfree(file_priv);
107}
108
109static struct drm_driver driver = {
110	.driver_features = DRIVER_USE_AGP,
111	.load = sis_driver_load,
112	.unload = sis_driver_unload,
113	.open = sis_driver_open,
114	.preclose = sis_reclaim_buffers_locked,
115	.postclose = sis_driver_postclose,
116	.set_busid = drm_pci_set_busid,
117	.dma_quiescent = sis_idle,
118	.lastclose = sis_lastclose,
119	.ioctls = sis_ioctls,
120	.fops = &sis_driver_fops,
121	.name = DRIVER_NAME,
122	.desc = DRIVER_DESC,
123	.date = DRIVER_DATE,
124	.major = DRIVER_MAJOR,
125	.minor = DRIVER_MINOR,
126	.patchlevel = DRIVER_PATCHLEVEL,
127};
128
129static struct pci_driver sis_pci_driver = {
130	.name = DRIVER_NAME,
131	.id_table = pciidlist,
132};
133
134static int __init sis_init(void)
135{
136	driver.num_ioctls = sis_max_ioctl;
137	return drm_pci_init(&driver, &sis_pci_driver);
138}
139
140static void __exit sis_exit(void)
141{
142	drm_pci_exit(&driver, &sis_pci_driver);
143}
144
145module_init(sis_init);
146module_exit(sis_exit);
147
148MODULE_AUTHOR(DRIVER_AUTHOR);
149MODULE_DESCRIPTION(DRIVER_DESC);
150MODULE_LICENSE("GPL and additional rights");
151