Merge branch 'devel'
[linux-2.6] / drivers / gpu / drm / radeon / radeon_drv.c
1 /**
2  * \file radeon_drv.c
3  * ATI Radeon driver
4  *
5  * \author Gareth Hughes <gareth@valinux.com>
6  */
7
8 /*
9  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
10  * All Rights Reserved.
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice (including the next
20  * paragraph) shall be included in all copies or substantial portions of the
21  * Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29  * OTHER DEALINGS IN THE SOFTWARE.
30  */
31
32 #include "drmP.h"
33 #include "drm.h"
34 #include "radeon_drm.h"
35 #include "radeon_drv.h"
36
37 #include "drm_pciids.h"
38
39 int radeon_no_wb;
40
41 MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers");
42 module_param_named(no_wb, radeon_no_wb, int, 0444);
43
44 static int dri_library_name(struct drm_device *dev, char *buf)
45 {
46         drm_radeon_private_t *dev_priv = dev->dev_private;
47         int family = dev_priv->flags & RADEON_FAMILY_MASK;
48
49         return snprintf(buf, PAGE_SIZE, "%s\n",
50                         (family < CHIP_R200) ? "radeon" :
51                         ((family < CHIP_R300) ? "r200" :
52                         "r300"));
53 }
54
55 static int radeon_suspend(struct drm_device *dev, pm_message_t state)
56 {
57         drm_radeon_private_t *dev_priv = dev->dev_private;
58
59         /* Disable *all* interrupts */
60         if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS690)
61                 RADEON_WRITE(R500_DxMODE_INT_MASK, 0);
62         RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
63         return 0;
64 }
65
66 static int radeon_resume(struct drm_device *dev)
67 {
68         drm_radeon_private_t *dev_priv = dev->dev_private;
69
70         /* Restore interrupt registers */
71         if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS690)
72                 RADEON_WRITE(R500_DxMODE_INT_MASK, dev_priv->r500_disp_irq_reg);
73         RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg);
74         return 0;
75 }
76
77 static struct pci_device_id pciidlist[] = {
78         radeon_PCI_IDS
79 };
80
81 static struct drm_driver driver = {
82         .driver_features =
83             DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
84             DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED,
85         .dev_priv_size = sizeof(drm_radeon_buf_priv_t),
86         .load = radeon_driver_load,
87         .firstopen = radeon_driver_firstopen,
88         .open = radeon_driver_open,
89         .preclose = radeon_driver_preclose,
90         .postclose = radeon_driver_postclose,
91         .lastclose = radeon_driver_lastclose,
92         .unload = radeon_driver_unload,
93         .suspend = radeon_suspend,
94         .resume = radeon_resume,
95         .get_vblank_counter = radeon_get_vblank_counter,
96         .enable_vblank = radeon_enable_vblank,
97         .disable_vblank = radeon_disable_vblank,
98         .dri_library_name = dri_library_name,
99         .master_create = radeon_master_create,
100         .master_destroy = radeon_master_destroy,
101         .irq_preinstall = radeon_driver_irq_preinstall,
102         .irq_postinstall = radeon_driver_irq_postinstall,
103         .irq_uninstall = radeon_driver_irq_uninstall,
104         .irq_handler = radeon_driver_irq_handler,
105         .reclaim_buffers = drm_core_reclaim_buffers,
106         .get_map_ofs = drm_core_get_map_ofs,
107         .get_reg_ofs = drm_core_get_reg_ofs,
108         .ioctls = radeon_ioctls,
109         .dma_ioctl = radeon_cp_buffers,
110         .fops = {
111                  .owner = THIS_MODULE,
112                  .open = drm_open,
113                  .release = drm_release,
114                  .ioctl = drm_ioctl,
115                  .mmap = drm_mmap,
116                  .poll = drm_poll,
117                  .fasync = drm_fasync,
118 #ifdef CONFIG_COMPAT
119                  .compat_ioctl = radeon_compat_ioctl,
120 #endif
121         },
122
123         .pci_driver = {
124                  .name = DRIVER_NAME,
125                  .id_table = pciidlist,
126         },
127
128         .name = DRIVER_NAME,
129         .desc = DRIVER_DESC,
130         .date = DRIVER_DATE,
131         .major = DRIVER_MAJOR,
132         .minor = DRIVER_MINOR,
133         .patchlevel = DRIVER_PATCHLEVEL,
134 };
135
136 static int __init radeon_init(void)
137 {
138         driver.num_ioctls = radeon_max_ioctl;
139         return drm_init(&driver);
140 }
141
142 static void __exit radeon_exit(void)
143 {
144         drm_exit(&driver);
145 }
146
147 module_init(radeon_init);
148 module_exit(radeon_exit);
149
150 MODULE_AUTHOR(DRIVER_AUTHOR);
151 MODULE_DESCRIPTION(DRIVER_DESC);
152 MODULE_LICENSE("GPL and additional rights");