OSDN Git Service

Merge commit 'origin/drm-gem' into modesetting-gem
[android-x86/external-libdrm.git] / linux-core / i915_drv.c
1 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2  */
3 /*
4  *
5  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sub license, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  */
29
30 #include "drmP.h"
31 #include "drm.h"
32 #include "i915_drm.h"
33 #include "intel_drv.h"
34 #include "i915_drv.h"
35
36 #include "drm_pciids.h"
37
38 static struct pci_device_id pciidlist[] = {
39         i915_PCI_IDS
40 };
41
42 unsigned int i915_modeset = 0;
43 module_param_named(modeset, i915_modeset, int, 0400);
44
45 unsigned int i915_fbpercrtc = 0;
46 module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
47
48 unsigned int i915_rightof = 1;
49 module_param_named(i915_rightof, i915_rightof, int, 0400);
50
51 #if defined(I915_HAVE_FENCE) && defined(I915_TTM)
52 extern struct drm_fence_driver i915_fence_driver;
53 #endif
54
55 #if defined(I915_HAVE_BUFFER) && defined(I915_TTM)
56
57 static uint32_t i915_mem_prios[] = {DRM_BO_MEM_VRAM, DRM_BO_MEM_TT, DRM_BO_MEM_LOCAL};
58 static uint32_t i915_busy_prios[] = {DRM_BO_MEM_TT, DRM_BO_MEM_VRAM, DRM_BO_MEM_LOCAL};
59
60 static struct drm_bo_driver i915_bo_driver = {
61         .mem_type_prio = i915_mem_prios,
62         .mem_busy_prio = i915_busy_prios,
63         .num_mem_type_prio = sizeof(i915_mem_prios)/sizeof(uint32_t),
64         .num_mem_busy_prio = sizeof(i915_busy_prios)/sizeof(uint32_t),
65         .create_ttm_backend_entry = i915_create_ttm_backend_entry,
66         .fence_type = i915_fence_type,
67         .invalidate_caches = i915_invalidate_caches,
68         .init_mem_type = i915_init_mem_type,
69         .evict_flags = i915_evict_flags,
70         .move = i915_move,
71         .ttm_cache_flush = i915_flush_ttm,
72         .command_stream_barrier = NULL,
73 };
74 #endif /* ttm */
75
76 static int i915_suspend(struct drm_device *dev, pm_message_t state)
77 {
78         struct drm_i915_private *dev_priv = dev->dev_private;
79
80         if (!dev || !dev_priv) {
81                 printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv);
82                 printk(KERN_ERR "DRM not initialized, aborting suspend.\n");
83                 return -ENODEV;
84         }
85
86         if (state.event == PM_EVENT_PRETHAW)
87                 return 0;
88
89         pci_save_state(dev->pdev);
90
91         i915_save_state(dev);
92
93 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
94         intel_opregion_free(dev);
95 #endif
96
97         if (state.event == PM_EVENT_SUSPEND) {
98                 /* Shut down the device */
99                 pci_disable_device(dev->pdev);
100                 pci_set_power_state(dev->pdev, PCI_D3hot);
101         }
102
103         return 0;
104 }
105
106 static int i915_resume(struct drm_device *dev)
107 {
108         pci_set_power_state(dev->pdev, PCI_D0);
109         pci_restore_state(dev->pdev);
110         if (pci_enable_device(dev->pdev))
111                 return -1;
112         pci_set_master(dev->pdev);
113
114         i915_restore_state(dev);
115
116 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
117         intel_opregion_init(dev);
118 #endif
119
120         return 0;
121 }
122
123 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent);
124 static void remove(struct pci_dev *pdev);
125
126 static struct drm_driver driver = {
127         /* don't use mtrr's here, the Xserver or user space app should
128          * deal with them for intel hardware.
129          */
130         .driver_features =
131             DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR | */
132             DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM,
133         .load = i915_driver_load,
134         .unload = i915_driver_unload,
135         .firstopen = i915_driver_firstopen,
136         .open = i915_driver_open,
137         .lastclose = i915_driver_lastclose,
138         .preclose = i915_driver_preclose,
139         .postclose = i915_driver_postclose,
140         .suspend = i915_suspend,
141         .resume = i915_resume,
142         .device_is_agp = i915_driver_device_is_agp,
143         .get_vblank_counter = i915_get_vblank_counter,
144         .enable_vblank = i915_enable_vblank,
145         .disable_vblank = i915_disable_vblank,
146         .irq_preinstall = i915_driver_irq_preinstall,
147         .irq_postinstall = i915_driver_irq_postinstall,
148         .irq_uninstall = i915_driver_irq_uninstall,
149         .irq_handler = i915_driver_irq_handler,
150         .reclaim_buffers = drm_core_reclaim_buffers,
151         .get_map_ofs = drm_core_get_map_ofs,
152         .get_reg_ofs = drm_core_get_reg_ofs,
153         .master_create = i915_master_create,
154         .master_destroy = i915_master_destroy,
155         .proc_init = i915_gem_proc_init,
156         .proc_cleanup = i915_gem_proc_cleanup,
157         .ioctls = i915_ioctls,
158         .gem_init_object = i915_gem_init_object,
159         .gem_free_object = i915_gem_free_object,
160         .fops = {
161                 .owner = THIS_MODULE,
162                 .open = drm_open,
163                 .release = drm_release,
164                 .ioctl = drm_ioctl,
165                 .mmap = drm_mmap,
166                 .poll = drm_poll,
167                 .fasync = drm_fasync,
168 #if defined(CONFIG_COMPAT) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
169                 .compat_ioctl = i915_compat_ioctl,
170 #endif
171                 },
172         .pci_driver = {
173                 .name = DRIVER_NAME,
174                 .id_table = pciidlist,
175                 .probe = probe,
176                 .remove = remove,
177                 },
178 #if defined(I915_HAVE_FENCE) && defined(I915_TTM)
179         .fence_driver = &i915_fence_driver,
180 #endif
181 #if defined(I915_HAVE_BUFFER) && defined(I915_TTM)
182         .bo_driver = &i915_bo_driver,
183 #endif
184         .name = DRIVER_NAME,
185         .desc = DRIVER_DESC,
186         .date = DRIVER_DATE,
187         .major = DRIVER_MAJOR,
188         .minor = DRIVER_MINOR,
189         .patchlevel = DRIVER_PATCHLEVEL,
190 };
191
192 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
193 {
194         int ret;
195
196         /* On the 945G/GM, the chipset reports the MSI capability on the
197          * integrated graphics even though the support isn't actually there
198          * according to the published specs.  It doesn't appear to function
199          * correctly in testing on 945G.
200          * This may be a side effect of MSI having been made available for PEG
201          * and the registers being closely associated.
202          */
203         if (pdev->device != 0x2772 && pdev->device != 0x27A2)
204                 (void )pci_enable_msi(pdev);
205
206         ret = drm_get_dev(pdev, ent, &driver);
207         if (ret && pdev->msi_enabled)
208                 pci_disable_msi(pdev);
209         return ret;
210 }
211 static void remove(struct pci_dev *pdev)
212 {
213         drm_cleanup_pci(pdev);
214         if (pdev->msi_enabled)
215                 pci_disable_msi(pdev);
216 }
217
218 static int __init i915_init(void)
219 {
220         driver.num_ioctls = i915_max_ioctl;
221         if (i915_modeset == 1)
222                 driver.driver_features |= DRIVER_MODESET;
223
224         return drm_init(&driver, pciidlist);
225 }
226
227 static void __exit i915_exit(void)
228 {
229         drm_exit(&driver);
230 }
231
232 module_init(i915_init);
233 module_exit(i915_exit);
234
235 MODULE_AUTHOR(DRIVER_AUTHOR);
236 MODULE_DESCRIPTION(DRIVER_DESC);
237 MODULE_LICENSE("GPL and additional rights");