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 bool i915_pipe_enabled(struct drm_device *dev, enum pipe pipe)
78 struct drm_i915_private *dev_priv = dev->dev_private;
81 return (I915_READ(DPLL_A) & DPLL_VCO_ENABLE);
83 return (I915_READ(DPLL_B) & DPLL_VCO_ENABLE);
86 static void i915_save_palette(struct drm_device *dev, enum pipe pipe)
88 struct drm_i915_private *dev_priv = dev->dev_private;
89 unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
93 if (!i915_pipe_enabled(dev, pipe))
97 array = dev_priv->save_palette_a;
99 array = dev_priv->save_palette_b;
101 for(i = 0; i < 256; i++)
102 array[i] = I915_READ(reg + (i << 2));
105 static void i915_restore_palette(struct drm_device *dev, enum pipe pipe)
107 struct drm_i915_private *dev_priv = dev->dev_private;
108 unsigned long reg = (pipe == PIPE_A ? PALETTE_A : PALETTE_B);
112 if (!i915_pipe_enabled(dev, pipe))
116 array = dev_priv->save_palette_a;
118 array = dev_priv->save_palette_b;
120 for(i = 0; i < 256; i++)
121 I915_WRITE(reg + (i << 2), array[i]);
124 static u8 i915_read_indexed(u16 index_port, u16 data_port, u8 reg)
126 outb(reg, index_port);
127 return inb(data_port);
130 static u8 i915_read_ar(u16 st01, u8 reg, u16 palette_enable)
133 outb(palette_enable | reg, VGA_AR_INDEX);
134 return inb(VGA_AR_DATA_READ);
137 static void i915_write_ar(u8 st01, u8 reg, u8 val, u16 palette_enable)
140 outb(palette_enable | reg, VGA_AR_INDEX);
141 outb(val, VGA_AR_DATA_WRITE);
144 static void i915_write_indexed(u16 index_port, u16 data_port, u8 reg, u8 val)
146 outb(reg, index_port);
147 outb(val, data_port);
150 static void i915_save_vga(struct drm_device *dev)
152 struct drm_i915_private *dev_priv = dev->dev_private;
154 u16 cr_index, cr_data, st01;
156 /* VGA color palette registers */
157 dev_priv->saveDACMASK = inb(VGA_DACMASK);
158 /* DACCRX automatically increments during read */
160 /* Read 3 bytes of color data from each index */
161 for (i = 0; i < 256 * 3; i++)
162 dev_priv->saveDACDATA[i] = inb(VGA_DACDATA);
165 dev_priv->saveMSR = inb(VGA_MSR_READ);
166 if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
167 cr_index = VGA_CR_INDEX_CGA;
168 cr_data = VGA_CR_DATA_CGA;
171 cr_index = VGA_CR_INDEX_MDA;
172 cr_data = VGA_CR_DATA_MDA;
176 /* CRT controller regs */
177 i915_write_indexed(cr_index, cr_data, 0x11,
178 i915_read_indexed(cr_index, cr_data, 0x11) &
180 for (i = 0; i <= 0x24; i++)
181 dev_priv->saveCR[i] =
182 i915_read_indexed(cr_index, cr_data, i);
183 /* Make sure we don't turn off CR group 0 writes */
184 dev_priv->saveCR[0x11] &= ~0x80;
186 /* Attribute controller registers */
188 dev_priv->saveAR_INDEX = inb(VGA_AR_INDEX);
189 for (i = 0; i <= 0x14; i++)
190 dev_priv->saveAR[i] = i915_read_ar(st01, i, 0);
192 outb(dev_priv->saveAR_INDEX, VGA_AR_INDEX);
195 /* Graphics controller registers */
196 for (i = 0; i < 9; i++)
197 dev_priv->saveGR[i] =
198 i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, i);
200 dev_priv->saveGR[0x10] =
201 i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10);
202 dev_priv->saveGR[0x11] =
203 i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11);
204 dev_priv->saveGR[0x18] =
205 i915_read_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18);
207 /* Sequencer registers */
208 for (i = 0; i < 8; i++)
209 dev_priv->saveSR[i] =
210 i915_read_indexed(VGA_SR_INDEX, VGA_SR_DATA, i);
213 static void i915_restore_vga(struct drm_device *dev)
215 struct drm_i915_private *dev_priv = dev->dev_private;
217 u16 cr_index, cr_data, st01;
220 outb(dev_priv->saveMSR, VGA_MSR_WRITE);
221 if (dev_priv->saveMSR & VGA_MSR_CGA_MODE) {
222 cr_index = VGA_CR_INDEX_CGA;
223 cr_data = VGA_CR_DATA_CGA;
226 cr_index = VGA_CR_INDEX_MDA;
227 cr_data = VGA_CR_DATA_MDA;
231 /* Sequencer registers, don't write SR07 */
232 for (i = 0; i < 7; i++)
233 i915_write_indexed(VGA_SR_INDEX, VGA_SR_DATA, i,
234 dev_priv->saveSR[i]);
236 /* CRT controller regs */
237 /* Enable CR group 0 writes */
238 i915_write_indexed(cr_index, cr_data, 0x11, dev_priv->saveCR[0x11]);
239 for (i = 0; i <= 0x24; i++)
240 i915_write_indexed(cr_index, cr_data, i, dev_priv->saveCR[i]);
242 /* Graphics controller regs */
243 for (i = 0; i < 9; i++)
244 i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, i,
245 dev_priv->saveGR[i]);
247 i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x10,
248 dev_priv->saveGR[0x10]);
249 i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x11,
250 dev_priv->saveGR[0x11]);
251 i915_write_indexed(VGA_GR_INDEX, VGA_GR_DATA, 0x18,
252 dev_priv->saveGR[0x18]);
254 /* Attribute controller registers */
255 inb(st01); /* switch back to index mode */
256 for (i = 0; i <= 0x14; i++)
257 i915_write_ar(st01, i, dev_priv->saveAR[i], 0);
258 inb(st01); /* switch back to index mode */
259 outb(dev_priv->saveAR_INDEX | 0x20, VGA_AR_INDEX);
262 /* VGA color palette registers */
263 outb(dev_priv->saveDACMASK, VGA_DACMASK);
264 /* DACCRX automatically increments during read */
266 /* Read 3 bytes of color data from each index */
267 for (i = 0; i < 256 * 3; i++)
268 outb(dev_priv->saveDACDATA[i], VGA_DACDATA);
272 static int i915_suspend(struct drm_device *dev, pm_message_t state)
274 struct drm_i915_private *dev_priv = dev->dev_private;
276 if (!dev || !dev_priv) {
277 printk(KERN_ERR "dev: %p, dev_priv: %p\n", dev, dev_priv);
278 printk(KERN_ERR "DRM not initialized, aborting suspend.\n");
282 if (state.event == PM_EVENT_PRETHAW)
285 pci_save_state(dev->pdev);
287 i915_save_state(dev);
289 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
290 intel_opregion_free(dev);
293 if (state.event == PM_EVENT_SUSPEND) {
294 /* Shut down the device */
295 pci_disable_device(dev->pdev);
296 pci_set_power_state(dev->pdev, PCI_D3hot);
302 static int i915_resume(struct drm_device *dev)
304 pci_set_power_state(dev->pdev, PCI_D0);
305 pci_restore_state(dev->pdev);
306 if (pci_enable_device(dev->pdev))
308 pci_set_master(dev->pdev);
310 i915_restore_state(dev);
312 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)
313 intel_opregion_init(dev);
319 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent);
320 static void remove(struct pci_dev *pdev);
322 static struct drm_driver driver = {
323 /* don't use mtrr's here, the Xserver or user space app should
324 * deal with them for intel hardware.
327 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR | */
328 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM,
329 .load = i915_driver_load,
330 .unload = i915_driver_unload,
331 .firstopen = i915_driver_firstopen,
332 .open = i915_driver_open,
333 .lastclose = i915_driver_lastclose,
334 .preclose = i915_driver_preclose,
335 .postclose = i915_driver_postclose,
336 .suspend = i915_suspend,
337 .resume = i915_resume,
338 .device_is_agp = i915_driver_device_is_agp,
339 .get_vblank_counter = i915_get_vblank_counter,
340 .enable_vblank = i915_enable_vblank,
341 .disable_vblank = i915_disable_vblank,
342 .irq_preinstall = i915_driver_irq_preinstall,
343 .irq_postinstall = i915_driver_irq_postinstall,
344 .irq_uninstall = i915_driver_irq_uninstall,
345 .irq_handler = i915_driver_irq_handler,
346 .reclaim_buffers = drm_core_reclaim_buffers,
347 .get_map_ofs = drm_core_get_map_ofs,
348 .get_reg_ofs = drm_core_get_reg_ofs,
349 .master_create = i915_master_create,
350 .master_destroy = i915_master_destroy,
351 .proc_init = i915_gem_proc_init,
352 .proc_cleanup = i915_gem_proc_cleanup,
353 .ioctls = i915_ioctls,
354 .gem_init_object = i915_gem_init_object,
355 .gem_free_object = i915_gem_free_object,
357 .owner = THIS_MODULE,
359 .release = drm_release,
363 .fasync = drm_fasync,
364 #if defined(CONFIG_COMPAT) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
365 .compat_ioctl = i915_compat_ioctl,
370 .id_table = pciidlist,
374 #if defined(I915_HAVE_FENCE) && defined(I915_TTM)
375 .fence_driver = &i915_fence_driver,
377 #if defined(I915_HAVE_BUFFER) && defined(I915_TTM)
378 .bo_driver = &i915_bo_driver,
383 .major = DRIVER_MAJOR,
384 .minor = DRIVER_MINOR,
385 .patchlevel = DRIVER_PATCHLEVEL,
388 static int probe(struct pci_dev *pdev, const struct pci_device_id *ent)
392 /* On the 945G/GM, the chipset reports the MSI capability on the
393 * integrated graphics even though the support isn't actually there
394 * according to the published specs. It doesn't appear to function
395 * correctly in testing on 945G.
396 * This may be a side effect of MSI having been made available for PEG
397 * and the registers being closely associated.
399 if (pdev->device != 0x2772 && pdev->device != 0x27A2)
400 (void )pci_enable_msi(pdev);
402 ret = drm_get_dev(pdev, ent, &driver);
403 if (ret && pdev->msi_enabled)
404 pci_disable_msi(pdev);
407 static void remove(struct pci_dev *pdev)
409 drm_cleanup_pci(pdev);
410 if (pdev->msi_enabled)
411 pci_disable_msi(pdev);
414 static int __init i915_init(void)
416 driver.num_ioctls = i915_max_ioctl;
417 if (i915_modeset == 1)
418 driver.driver_features |= DRIVER_MODESET;
420 return drm_init(&driver, pciidlist);
423 static void __exit i915_exit(void)
428 module_init(i915_init);
429 module_exit(i915_exit);
431 MODULE_AUTHOR(DRIVER_AUTHOR);
432 MODULE_DESCRIPTION(DRIVER_DESC);
433 MODULE_LICENSE("GPL and additional rights");