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