Deleted Added
full compact
i915_drv.c (278146) i915_drv.c (280183)
1/* i915_drv.c -- Intel i915 driver -*- linux-c -*-
2 * Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com
3 */
4/*-
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a

--- 16 unchanged lines hidden (view full) ---

25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Gareth Hughes <gareth@valinux.com>
29 *
30 */
31
32#include <sys/cdefs.h>
1/* i915_drv.c -- Intel i915 driver -*- linux-c -*-
2 * Created: Wed Feb 14 17:10:04 2001 by gareth@valinux.com
3 */
4/*-
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a

--- 16 unchanged lines hidden (view full) ---

25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Gareth Hughes <gareth@valinux.com>
29 *
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/dev/drm2/i915/i915_drv.c 278146 2015-02-03 10:30:41Z kib $");
33__FBSDID("$FreeBSD: head/sys/dev/drm2/i915/i915_drv.c 280183 2015-03-17 18:50:33Z dumbbell $");
34
35#include <dev/drm2/drmP.h>
36#include <dev/drm2/drm.h>
37#include <dev/drm2/drm_mm.h>
38#include <dev/drm2/i915/i915_drm.h>
39#include <dev/drm2/i915/i915_drv.h>
40#include <dev/drm2/drm_pciids.h>
41#include <dev/drm2/i915/intel_drv.h>

--- 251 unchanged lines hidden (view full) ---

293
294 dev_priv = dev->dev_private;
295 drm_kms_helper_poll_disable(dev);
296
297#if 0
298 pci_save_state(dev->pdev);
299#endif
300
34
35#include <dev/drm2/drmP.h>
36#include <dev/drm2/drm.h>
37#include <dev/drm2/drm_mm.h>
38#include <dev/drm2/i915/i915_drm.h>
39#include <dev/drm2/i915/i915_drv.h>
40#include <dev/drm2/drm_pciids.h>
41#include <dev/drm2/i915/intel_drv.h>

--- 251 unchanged lines hidden (view full) ---

293
294 dev_priv = dev->dev_private;
295 drm_kms_helper_poll_disable(dev);
296
297#if 0
298 pci_save_state(dev->pdev);
299#endif
300
301 DRM_LOCK(dev);
302 /* If KMS is active, we do the leavevt stuff here */
303 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
301 /* If KMS is active, we do the leavevt stuff here */
302 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
304 error = -i915_gem_idle(dev);
303 error = i915_gem_idle(dev);
305 if (error) {
304 if (error) {
306 DRM_UNLOCK(dev);
307 device_printf(dev->device,
305 device_printf(dev->dev,
308 "GEM idle failed, resume might fail\n");
309 return (error);
310 }
311 drm_irq_uninstall(dev);
312 }
313
314 i915_save_state(dev);
315
316 intel_opregion_fini(dev);
317
318 /* Modeset on resume, not lid events */
319 dev_priv->modeset_on_lid = 0;
306 "GEM idle failed, resume might fail\n");
307 return (error);
308 }
309 drm_irq_uninstall(dev);
310 }
311
312 i915_save_state(dev);
313
314 intel_opregion_fini(dev);
315
316 /* Modeset on resume, not lid events */
317 dev_priv->modeset_on_lid = 0;
320 DRM_UNLOCK(dev);
321
322 return 0;
323}
324
325static int
326i915_suspend(device_t kdev)
327{
328 struct drm_device *dev;
329 int error;
330
331 dev = device_get_softc(kdev);
332 if (dev == NULL || dev->dev_private == NULL) {
333 DRM_ERROR("DRM not initialized, aborting suspend.\n");
318
319 return 0;
320}
321
322static int
323i915_suspend(device_t kdev)
324{
325 struct drm_device *dev;
326 int error;
327
328 dev = device_get_softc(kdev);
329 if (dev == NULL || dev->dev_private == NULL) {
330 DRM_ERROR("DRM not initialized, aborting suspend.\n");
334 return -ENODEV;
331 return ENODEV;
335 }
336
337 DRM_DEBUG_KMS("starting suspend\n");
338 error = i915_drm_freeze(dev);
339 if (error)
332 }
333
334 DRM_DEBUG_KMS("starting suspend\n");
335 error = i915_drm_freeze(dev);
336 if (error)
340 return (error);
337 return (-error);
341
342 error = bus_generic_suspend(kdev);
343 DRM_DEBUG_KMS("finished suspend %d\n", error);
344 return (error);
345}
346
347static int i915_drm_thaw(struct drm_device *dev)
348{
349 struct drm_i915_private *dev_priv = dev->dev_private;
350 int error = 0;
351
338
339 error = bus_generic_suspend(kdev);
340 DRM_DEBUG_KMS("finished suspend %d\n", error);
341 return (error);
342}
343
344static int i915_drm_thaw(struct drm_device *dev)
345{
346 struct drm_i915_private *dev_priv = dev->dev_private;
347 int error = 0;
348
352 DRM_LOCK(dev);
353 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
349 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
350 DRM_LOCK(dev);
354 i915_gem_restore_gtt_mappings(dev);
351 i915_gem_restore_gtt_mappings(dev);
352 DRM_UNLOCK(dev);
355 }
356
357 i915_restore_state(dev);
358 intel_opregion_setup(dev);
359
360 /* KMS EnterVT equivalent */
361 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
362 if (HAS_PCH_SPLIT(dev))
363 ironlake_init_pch_refclk(dev);
364
353 }
354
355 i915_restore_state(dev);
356 intel_opregion_setup(dev);
357
358 /* KMS EnterVT equivalent */
359 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
360 if (HAS_PCH_SPLIT(dev))
361 ironlake_init_pch_refclk(dev);
362
363 DRM_LOCK(dev);
365 dev_priv->mm.suspended = 0;
366
367 error = i915_gem_init_hw(dev);
368 DRM_UNLOCK(dev);
369
370 intel_modeset_init_hw(dev);
371 sx_xlock(&dev->mode_config.mutex);
372 drm_mode_config_reset(dev);
373 sx_xunlock(&dev->mode_config.mutex);
374 drm_irq_install(dev);
375
376 sx_xlock(&dev->mode_config.mutex);
377 /* Resume the modeset for every activated CRTC */
378 drm_helper_resume_force_mode(dev);
379 sx_xunlock(&dev->mode_config.mutex);
364 dev_priv->mm.suspended = 0;
365
366 error = i915_gem_init_hw(dev);
367 DRM_UNLOCK(dev);
368
369 intel_modeset_init_hw(dev);
370 sx_xlock(&dev->mode_config.mutex);
371 drm_mode_config_reset(dev);
372 sx_xunlock(&dev->mode_config.mutex);
373 drm_irq_install(dev);
374
375 sx_xlock(&dev->mode_config.mutex);
376 /* Resume the modeset for every activated CRTC */
377 drm_helper_resume_force_mode(dev);
378 sx_xunlock(&dev->mode_config.mutex);
380 DRM_LOCK(dev);
381 }
382
383 intel_opregion_init(dev);
384
385 dev_priv->modeset_on_lid = 0;
386
379 }
380
381 intel_opregion_init(dev);
382
383 dev_priv->modeset_on_lid = 0;
384
387 DRM_UNLOCK(dev);
388
389 return error;
390}
391
392static int
393i915_resume(device_t kdev)
394{
395 struct drm_device *dev;
396 int ret;
397
398 dev = device_get_softc(kdev);
399 DRM_DEBUG_KMS("starting resume\n");
400#if 0
401 if (pci_enable_device(dev->pdev))
402 return -EIO;
403
404 pci_set_master(dev->pdev);
405#endif
406
385 return error;
386}
387
388static int
389i915_resume(device_t kdev)
390{
391 struct drm_device *dev;
392 int ret;
393
394 dev = device_get_softc(kdev);
395 DRM_DEBUG_KMS("starting resume\n");
396#if 0
397 if (pci_enable_device(dev->pdev))
398 return -EIO;
399
400 pci_set_master(dev->pdev);
401#endif
402
407 ret = -i915_drm_thaw(dev);
403 ret = i915_drm_thaw(dev);
408 if (ret != 0)
404 if (ret != 0)
409 return (ret);
405 return (-ret);
410
411 drm_kms_helper_poll_enable(dev);
412 ret = bus_generic_resume(kdev);
413 DRM_DEBUG_KMS("finished resume %d\n", ret);
414 return (ret);
415}
416
417static int
418i915_probe(device_t kdev)
419{
420 const struct intel_device_info *info;
421 int error;
422
406
407 drm_kms_helper_poll_enable(dev);
408 ret = bus_generic_resume(kdev);
409 DRM_DEBUG_KMS("finished resume %d\n", ret);
410 return (ret);
411}
412
413static int
414i915_probe(device_t kdev)
415{
416 const struct intel_device_info *info;
417 int error;
418
423 error = drm_probe(kdev, i915_pciidlist);
419 error = drm_probe_helper(kdev, i915_pciidlist);
424 if (error != 0)
420 if (error != 0)
425 return (error);
421 return (-error);
426 info = i915_get_device_id(pci_get_device(kdev));
427 if (info == NULL)
428 return (ENXIO);
429 return (0);
430}
431
432int i915_modeset;
433
434static int
435i915_attach(device_t kdev)
436{
422 info = i915_get_device_id(pci_get_device(kdev));
423 if (info == NULL)
424 return (ENXIO);
425 return (0);
426}
427
428int i915_modeset;
429
430static int
431i915_attach(device_t kdev)
432{
437 struct drm_device *dev;
438
433
439 dev = device_get_softc(kdev);
440 if (i915_modeset == 1)
441 i915_driver_info.driver_features |= DRIVER_MODESET;
434 if (i915_modeset == 1)
435 i915_driver_info.driver_features |= DRIVER_MODESET;
442 dev->driver = &i915_driver_info;
443 return (drm_attach(kdev, i915_pciidlist));
436 return (-drm_attach_helper(kdev, i915_pciidlist, &i915_driver_info));
444}
445
446static struct fb_info *
447i915_fb_helper_getinfo(device_t kdev)
448{
449 struct intel_fbdev *ifbdev;
450 drm_i915_private_t *dev_priv;
451 struct drm_device *dev;

--- 26 unchanged lines hidden (view full) ---

478}
479
480static device_method_t i915_methods[] = {
481 /* Device interface */
482 DEVMETHOD(device_probe, i915_probe),
483 DEVMETHOD(device_attach, i915_attach),
484 DEVMETHOD(device_suspend, i915_suspend),
485 DEVMETHOD(device_resume, i915_resume),
437}
438
439static struct fb_info *
440i915_fb_helper_getinfo(device_t kdev)
441{
442 struct intel_fbdev *ifbdev;
443 drm_i915_private_t *dev_priv;
444 struct drm_device *dev;

--- 26 unchanged lines hidden (view full) ---

471}
472
473static device_method_t i915_methods[] = {
474 /* Device interface */
475 DEVMETHOD(device_probe, i915_probe),
476 DEVMETHOD(device_attach, i915_attach),
477 DEVMETHOD(device_suspend, i915_suspend),
478 DEVMETHOD(device_resume, i915_resume),
486 DEVMETHOD(device_detach, drm_detach),
479 DEVMETHOD(device_detach, drm_generic_detach),
487
488 /* Framebuffer service methods */
489 DEVMETHOD(fb_getinfo, i915_fb_helper_getinfo),
490
491 DEVMETHOD_END
492};
493
494static driver_t i915_driver = {

--- 273 unchanged lines hidden (view full) ---

768 return 0;
769}
770
771static int
772i965_reset_complete(struct drm_device *dev)
773{
774 u8 gdrst;
775
480
481 /* Framebuffer service methods */
482 DEVMETHOD(fb_getinfo, i915_fb_helper_getinfo),
483
484 DEVMETHOD_END
485};
486
487static driver_t i915_driver = {

--- 273 unchanged lines hidden (view full) ---

761 return 0;
762}
763
764static int
765i965_reset_complete(struct drm_device *dev)
766{
767 u8 gdrst;
768
776 gdrst = pci_read_config(dev->device, I965_GDRST, 1);
769 gdrst = pci_read_config(dev->dev, I965_GDRST, 1);
777 return (gdrst & GRDOM_RESET_ENABLE) == 0;
778}
779
780static int
781i965_do_reset(struct drm_device *dev)
782{
783 int ret;
784 u8 gdrst;
785
786 /*
787 * Set the domains we want to reset (GRDOM/bits 2 and 3) as
788 * well as the reset bit (GR/bit 0). Setting the GR bit
789 * triggers the reset; when done, the hardware will clear it.
790 */
770 return (gdrst & GRDOM_RESET_ENABLE) == 0;
771}
772
773static int
774i965_do_reset(struct drm_device *dev)
775{
776 int ret;
777 u8 gdrst;
778
779 /*
780 * Set the domains we want to reset (GRDOM/bits 2 and 3) as
781 * well as the reset bit (GR/bit 0). Setting the GR bit
782 * triggers the reset; when done, the hardware will clear it.
783 */
791 gdrst = pci_read_config(dev->device, I965_GDRST, 1);
792 pci_write_config(dev->device, I965_GDRST,
784 gdrst = pci_read_config(dev->dev, I965_GDRST, 1);
785 pci_write_config(dev->dev, I965_GDRST,
793 gdrst | GRDOM_RENDER | GRDOM_RESET_ENABLE, 1);
794
795 ret = wait_for(i965_reset_complete(dev), 500);
796 if (ret)
797 return ret;
798
799 /* We can't reset render&media without also resetting display ... */
786 gdrst | GRDOM_RENDER | GRDOM_RESET_ENABLE, 1);
787
788 ret = wait_for(i965_reset_complete(dev), 500);
789 if (ret)
790 return ret;
791
792 /* We can't reset render&media without also resetting display ... */
800 gdrst = pci_read_config(dev->device, I965_GDRST, 1);
801 pci_write_config(dev->device, I965_GDRST,
793 gdrst = pci_read_config(dev->dev, I965_GDRST, 1);
794 pci_write_config(dev->dev, I965_GDRST,
802 gdrst | GRDOM_MEDIA | GRDOM_RESET_ENABLE, 1);
803
804 return wait_for(i965_reset_complete(dev), 500);
805}
806
807static int
808ironlake_do_reset(struct drm_device *dev)
809{

--- 134 unchanged lines hidden (view full) ---

944 i915_gem_context_init(dev);
945 i915_gem_init_ppgtt(dev);
946
947 DRM_UNLOCK(dev);
948
949 if (drm_core_check_feature(dev, DRIVER_MODESET))
950 intel_modeset_init_hw(dev);
951
795 gdrst | GRDOM_MEDIA | GRDOM_RESET_ENABLE, 1);
796
797 return wait_for(i965_reset_complete(dev), 500);
798}
799
800static int
801ironlake_do_reset(struct drm_device *dev)
802{

--- 134 unchanged lines hidden (view full) ---

937 i915_gem_context_init(dev);
938 i915_gem_init_ppgtt(dev);
939
940 DRM_UNLOCK(dev);
941
942 if (drm_core_check_feature(dev, DRIVER_MODESET))
943 intel_modeset_init_hw(dev);
944
952 DRM_LOCK(dev);
953 drm_irq_uninstall(dev);
945 drm_irq_uninstall(dev);
954 DRM_UNLOCK(dev);
955 drm_irq_install(dev);
956 } else
957 DRM_UNLOCK(dev);
958
959 return (0);
960}
961
962/* We give fast paths for the really cool registers */

--- 47 unchanged lines hidden ---
946 drm_irq_install(dev);
947 } else
948 DRM_UNLOCK(dev);
949
950 return (0);
951}
952
953/* We give fast paths for the really cool registers */

--- 47 unchanged lines hidden ---