1 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
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.
33 #include "intel_drv.h"
36 #include "drm_pciids.h"
38 static struct pci_device_id pciidlist[] = {
42 unsigned int i915_modeset = 0;
43 module_param_named(modeset, i915_modeset, int, 0400);
45 unsigned int i915_fbpercrtc = 0;
46 module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
48 unsigned int i915_rightof = 1;
49 module_param_named(i915_rightof, i915_rightof, int, 0400);
51 #if defined(I915_HAVE_FENCE) && defined(I915_TTM)
52 extern struct drm_fence_driver i915_fence_driver;
55 #if defined(I915_HAVE_BUFFER) && defined(I915_TTM)
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};
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,
71 .ttm_cache_flush = i915_flush_ttm,
72 .command_stream_barrier = NULL,
76 static int i915_suspend(struct drm_device *dev, pm_message_t state)
78 struct drm_i915_private *dev_priv = dev->dev_private;
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");
86 if (state.event == PM_EVENT_PRETHAW)
89 pci_save_state(dev->pdev);
93 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
94 intel_opregion_free(dev);
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);
106 static int i915_resume(struct drm_device *dev)
108 pci_set_power_state(dev->pdev, PCI_D0);
109 pci_restore_state(dev->pdev);
110 if (pci_enable_device(dev->pdev))
112 pci_set_master(dev->pdev);
114 i915_restore_state(dev);
116 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
117 intel_opregion_init(dev);
123 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent);
124 static void remove(struct pci_dev *pdev);
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.
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,
161 .owner = THIS_MODULE,
163 .release = drm_release,
167 .fasync = drm_fasync,
168 #if defined(CONFIG_COMPAT) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
169 .compat_ioctl = i915_compat_ioctl,
174 .id_table = pciidlist,
178 #if defined(I915_HAVE_FENCE) && defined(I915_TTM)
179 .fence_driver = &i915_fence_driver,
181 #if defined(I915_HAVE_BUFFER) && defined(I915_TTM)
182 .bo_driver = &i915_bo_driver,
187 .major = DRIVER_MAJOR,
188 .minor = DRIVER_MINOR,
189 .patchlevel = DRIVER_PATCHLEVEL,
192 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
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.
203 if (pdev->device != 0x2772 && pdev->device != 0x27A2)
204 (void )pci_enable_msi(pdev);
206 ret = drm_get_dev(pdev, ent, &driver);
207 if (ret && pdev->msi_enabled)
208 pci_disable_msi(pdev);
211 static void remove(struct pci_dev *pdev)
213 drm_cleanup_pci(pdev);
214 if (pdev->msi_enabled)
215 pci_disable_msi(pdev);
218 static int __init i915_init(void)
220 driver.num_ioctls = i915_max_ioctl;
221 if (i915_modeset == 1)
222 driver.driver_features |= DRIVER_MODESET;
224 return drm_init(&driver, pciidlist);
227 static void __exit i915_exit(void)
232 module_init(i915_init);
233 module_exit(i915_exit);
235 MODULE_AUTHOR(DRIVER_AUTHOR);
236 MODULE_DESCRIPTION(DRIVER_DESC);
237 MODULE_LICENSE("GPL and additional rights");