Subversion Repositories Kolibri OS

Rev

Rev 2339 | Rev 2342 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 <linux/device.h>
  31. #include "drmP.h"
  32. #include "drm.h"
  33. #include "i915_drm.h"
  34. #include "i915_drv.h"
  35. #include "intel_drv.h"
  36.  
  37.  
  38. #include <linux/kernel.h>
  39. #include <linux/module.h>
  40. #include <linux/mod_devicetable.h>
  41. #include <errno-base.h>
  42. #include <linux/pci.h>
  43.  
  44. #include <syscall.h>
  45.  
  46. #define __read_mostly
  47.  
  48. int init_display_kms(struct drm_device *dev);
  49.  
  50. struct drm_device *main_device;
  51.  
  52. int i915_panel_ignore_lid __read_mostly         =  0;
  53.  
  54. unsigned int i915_powersave  __read_mostly      =  0;
  55.  
  56. unsigned int i915_enable_rc6 __read_mostly      =  0;
  57.  
  58. unsigned int i915_enable_fbc __read_mostly      =  0;
  59.  
  60. unsigned int i915_lvds_downclock  __read_mostly =  0;
  61.  
  62. unsigned int i915_panel_use_ssc __read_mostly   =  1;
  63.  
  64. int i915_vbt_sdvo_panel_type __read_mostly      = -1;
  65.  
  66. #define PCI_VENDOR_ID_INTEL        0x8086
  67.  
  68. #define INTEL_VGA_DEVICE(id, info) {        \
  69.     .class = PCI_CLASS_DISPLAY_VGA << 8,    \
  70.     .class_mask = 0xff0000,                 \
  71.     .vendor = 0x8086,                       \
  72.     .device = id,                           \
  73.     .subvendor = PCI_ANY_ID,                \
  74.     .subdevice = PCI_ANY_ID,                \
  75.     .driver_data = (unsigned long) info }
  76.  
  77. static const struct intel_device_info intel_i830_info = {
  78.         .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1,
  79.         .has_overlay = 1, .overlay_needs_physical = 1,
  80. };
  81.  
  82. static const struct intel_device_info intel_845g_info = {
  83.         .gen = 2,
  84.         .has_overlay = 1, .overlay_needs_physical = 1,
  85. };
  86.  
  87. static const struct intel_device_info intel_i85x_info = {
  88.         .gen = 2, .is_i85x = 1, .is_mobile = 1,
  89.         .cursor_needs_physical = 1,
  90.         .has_overlay = 1, .overlay_needs_physical = 1,
  91. };
  92.  
  93. static const struct intel_device_info intel_i865g_info = {
  94.         .gen = 2,
  95.         .has_overlay = 1, .overlay_needs_physical = 1,
  96. };
  97.  
  98. static const struct intel_device_info intel_i915g_info = {
  99.         .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1,
  100.         .has_overlay = 1, .overlay_needs_physical = 1,
  101. };
  102. static const struct intel_device_info intel_i915gm_info = {
  103.         .gen = 3, .is_mobile = 1,
  104.         .cursor_needs_physical = 1,
  105.         .has_overlay = 1, .overlay_needs_physical = 1,
  106.         .supports_tv = 1,
  107. };
  108. static const struct intel_device_info intel_i945g_info = {
  109.         .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1,
  110.         .has_overlay = 1, .overlay_needs_physical = 1,
  111. };
  112. static const struct intel_device_info intel_i945gm_info = {
  113.         .gen = 3, .is_i945gm = 1, .is_mobile = 1,
  114.         .has_hotplug = 1, .cursor_needs_physical = 1,
  115.         .has_overlay = 1, .overlay_needs_physical = 1,
  116.         .supports_tv = 1,
  117. };
  118.  
  119. static const struct intel_device_info intel_i965g_info = {
  120.         .gen = 4, .is_broadwater = 1,
  121.         .has_hotplug = 1,
  122.         .has_overlay = 1,
  123. };
  124.  
  125. static const struct intel_device_info intel_i965gm_info = {
  126.         .gen = 4, .is_crestline = 1,
  127.         .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
  128.         .has_overlay = 1,
  129.         .supports_tv = 1,
  130. };
  131.  
  132. static const struct intel_device_info intel_g33_info = {
  133.         .gen = 3, .is_g33 = 1,
  134.         .need_gfx_hws = 1, .has_hotplug = 1,
  135.         .has_overlay = 1,
  136. };
  137.  
  138. static const struct intel_device_info intel_g45_info = {
  139.         .gen = 4, .is_g4x = 1, .need_gfx_hws = 1,
  140.         .has_pipe_cxsr = 1, .has_hotplug = 1,
  141.         .has_bsd_ring = 1,
  142. };
  143.  
  144. static const struct intel_device_info intel_gm45_info = {
  145.         .gen = 4, .is_g4x = 1,
  146.         .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
  147.         .has_pipe_cxsr = 1, .has_hotplug = 1,
  148.         .supports_tv = 1,
  149.         .has_bsd_ring = 1,
  150. };
  151.  
  152. static const struct intel_device_info intel_pineview_info = {
  153.         .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1,
  154.         .need_gfx_hws = 1, .has_hotplug = 1,
  155.         .has_overlay = 1,
  156. };
  157.  
  158. static const struct intel_device_info intel_ironlake_d_info = {
  159.         .gen = 5,
  160.         .need_gfx_hws = 1, .has_pipe_cxsr = 1, .has_hotplug = 1,
  161.         .has_bsd_ring = 1,
  162. };
  163.  
  164. static const struct intel_device_info intel_ironlake_m_info = {
  165.         .gen = 5, .is_mobile = 1,
  166.         .need_gfx_hws = 1, .has_hotplug = 1,
  167.         .has_fbc = 1,
  168.         .has_bsd_ring = 1,
  169. };
  170.  
  171. static const struct intel_device_info intel_sandybridge_d_info = {
  172.     .gen = 6,
  173.         .need_gfx_hws = 1, .has_hotplug = 1,
  174.     .has_bsd_ring = 1,
  175.     .has_blt_ring = 1,
  176. };
  177.  
  178. static const struct intel_device_info intel_sandybridge_m_info = {
  179.         .gen = 6, .is_mobile = 1,
  180.         .need_gfx_hws = 1, .has_hotplug = 1,
  181.     .has_fbc      = 1,
  182.     .has_bsd_ring = 1,
  183.     .has_blt_ring = 1,
  184. };
  185.  
  186. static const struct intel_device_info intel_ivybridge_d_info = {
  187.         .is_ivybridge = 1, .gen = 7,
  188.         .need_gfx_hws = 1, .has_hotplug = 1,
  189.         .has_bsd_ring = 1,
  190.         .has_blt_ring = 1,
  191. };
  192.  
  193. static const struct intel_device_info intel_ivybridge_m_info = {
  194.         .is_ivybridge = 1, .gen = 7, .is_mobile = 1,
  195.         .need_gfx_hws = 1, .has_hotplug = 1,
  196.         .has_fbc = 0,   /* FBC is not enabled on Ivybridge mobile yet */
  197.         .has_bsd_ring = 1,
  198.         .has_blt_ring = 1,
  199. };
  200.  
  201. static const struct pci_device_id pciidlist[] = {       /* aka */
  202.         INTEL_VGA_DEVICE(0x2582, &intel_i915g_info),            /* I915_G */
  203.         INTEL_VGA_DEVICE(0x258a, &intel_i915g_info),            /* E7221_G */
  204.         INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info),           /* I915_GM */
  205.         INTEL_VGA_DEVICE(0x2772, &intel_i945g_info),            /* I945_G */
  206.         INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info),           /* I945_GM */
  207.         INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info),           /* I945_GME */
  208.         INTEL_VGA_DEVICE(0x2972, &intel_i965g_info),            /* I946_GZ */
  209.         INTEL_VGA_DEVICE(0x2982, &intel_i965g_info),            /* G35_G */
  210.         INTEL_VGA_DEVICE(0x2992, &intel_i965g_info),            /* I965_Q */
  211.         INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info),            /* I965_G */
  212.         INTEL_VGA_DEVICE(0x29b2, &intel_g33_info),              /* Q35_G */
  213.         INTEL_VGA_DEVICE(0x29c2, &intel_g33_info),              /* G33_G */
  214.         INTEL_VGA_DEVICE(0x29d2, &intel_g33_info),              /* Q33_G */
  215.         INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info),           /* I965_GM */
  216.         INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info),           /* I965_GME */
  217.         INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info),             /* GM45_G */
  218.         INTEL_VGA_DEVICE(0x2e02, &intel_g45_info),              /* IGD_E_G */
  219.         INTEL_VGA_DEVICE(0x2e12, &intel_g45_info),              /* Q45_G */
  220.         INTEL_VGA_DEVICE(0x2e22, &intel_g45_info),              /* G45_G */
  221.         INTEL_VGA_DEVICE(0x2e32, &intel_g45_info),              /* G41_G */
  222.         INTEL_VGA_DEVICE(0x2e42, &intel_g45_info),              /* B43_G */
  223.         INTEL_VGA_DEVICE(0x2e92, &intel_g45_info),              /* B43_G.1 */
  224.         INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
  225.         INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
  226.         INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
  227.         INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info),
  228.     INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info),
  229.     INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info),
  230.     INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info),
  231.     INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info),
  232.     INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info),
  233.     INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info),
  234.     INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info),
  235.         INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */
  236.         INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */
  237.         INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
  238.         INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
  239.         INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
  240.     {0, 0, 0}
  241. };
  242.  
  243. #define INTEL_PCH_DEVICE_ID_MASK        0xff00
  244. #define INTEL_PCH_IBX_DEVICE_ID_TYPE    0x3b00
  245. #define INTEL_PCH_CPT_DEVICE_ID_TYPE    0x1c00
  246. #define INTEL_PCH_PPT_DEVICE_ID_TYPE    0x1e00
  247.  
  248. void intel_detect_pch (struct drm_device *dev)
  249. {
  250.     struct drm_i915_private *dev_priv = dev->dev_private;
  251.     struct pci_dev *pch;
  252.  
  253.     /*
  254.      * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  255.      * make graphics device passthrough work easy for VMM, that only
  256.      * need to expose ISA bridge to let driver know the real hardware
  257.      * underneath. This is a requirement from virtualization team.
  258.      */
  259.     pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  260.     if (pch) {
  261.         if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  262.             int id;
  263.             id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  264.  
  265.             if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  266.                 dev_priv->pch_type = PCH_IBX;
  267.                 DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  268.             } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  269.                 dev_priv->pch_type = PCH_CPT;
  270.                 DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  271.             } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  272.                 /* PantherPoint is CPT compatible */
  273.                 dev_priv->pch_type = PCH_CPT;
  274.                 DRM_DEBUG_KMS("Found PatherPoint PCH\n");
  275.             }
  276.         }
  277.     }
  278. }
  279.  
  280. static void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  281. {
  282.     int count;
  283.  
  284.     count = 0;
  285.     while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
  286.         udelay(10);
  287.  
  288.     I915_WRITE_NOTRACE(FORCEWAKE, 1);
  289.     POSTING_READ(FORCEWAKE);
  290.  
  291.     count = 0;
  292.     while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1) == 0)
  293.         udelay(10);
  294. }
  295.  
  296. /*
  297.  * Generally this is called implicitly by the register read function. However,
  298.  * if some sequence requires the GT to not power down then this function should
  299.  * be called at the beginning of the sequence followed by a call to
  300.  * gen6_gt_force_wake_put() at the end of the sequence.
  301.  */
  302. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  303. {
  304. //    WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
  305.  
  306.     /* Forcewake is atomic in case we get in here without the lock */
  307.     if (atomic_add_return(1, &dev_priv->forcewake_count) == 1)
  308.         __gen6_gt_force_wake_get(dev_priv);
  309. }
  310.  
  311. static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  312. {
  313.     I915_WRITE_NOTRACE(FORCEWAKE, 0);
  314.     POSTING_READ(FORCEWAKE);
  315. }
  316.  
  317. /*
  318.  * see gen6_gt_force_wake_get()
  319.  */
  320. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  321. {
  322. //    WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
  323.  
  324.     if (atomic_dec_and_test(&dev_priv->forcewake_count))
  325.         __gen6_gt_force_wake_put(dev_priv);
  326. }
  327.  
  328. void __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
  329. {
  330.     if (dev_priv->gt_fifo_count < GT_FIFO_NUM_RESERVED_ENTRIES ) {
  331.         int loop = 500;
  332.         u32 fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  333.         while (fifo <= GT_FIFO_NUM_RESERVED_ENTRIES && loop--) {
  334.             udelay(10);
  335.             fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  336.         }
  337. //        WARN_ON(loop < 0 && fifo <= GT_FIFO_NUM_RESERVED_ENTRIES);
  338.         dev_priv->gt_fifo_count = fifo;
  339.     }
  340.     dev_priv->gt_fifo_count--;
  341. }
  342.  
  343.  
  344.  
  345.  
  346.  
  347. int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent);
  348.  
  349. int i915_init(void)
  350. {
  351.     static pci_dev_t device;
  352.     const struct pci_device_id  *ent;
  353.     int  err;
  354.  
  355.     if( init_agp() != 0)
  356.     {
  357.         DRM_ERROR("drm/i915 can't work without intel_agp module!\n");
  358.         return 0;
  359.     };
  360.  
  361.     ent = find_pci_device(&device, pciidlist);
  362.  
  363.     if( unlikely(ent == NULL) )
  364.     {
  365.         dbgprintf("device not found\n");
  366.         return 0;
  367.     };
  368.  
  369.     dbgprintf("device %x:%x\n", device.pci_dev.vendor,
  370.                                 device.pci_dev.device);
  371.  
  372.     err = drm_get_dev(&device.pci_dev, ent);
  373.  
  374.     return err;
  375. }
  376.  
  377. int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
  378. {
  379.     struct drm_device *dev;
  380.     int ret;
  381.  
  382.     ENTER();
  383.  
  384.     dev = kzalloc(sizeof(*dev), 0);
  385.     if (!dev)
  386.         return -ENOMEM;
  387.  
  388.  //   ret = pci_enable_device(pdev);
  389.  //   if (ret)
  390.  //       goto err_g1;
  391.  
  392.  //   pci_set_master(pdev);
  393.  
  394.  //   if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
  395.  //       printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
  396.  //       goto err_g2;
  397.  //   }
  398.  
  399.     dev->pdev = pdev;
  400.     dev->pci_device = pdev->device;
  401.     dev->pci_vendor = pdev->vendor;
  402.  
  403.     INIT_LIST_HEAD(&dev->filelist);
  404.     INIT_LIST_HEAD(&dev->ctxlist);
  405.     INIT_LIST_HEAD(&dev->vmalist);
  406.     INIT_LIST_HEAD(&dev->maplist);
  407.  
  408.     spin_lock_init(&dev->count_lock);
  409.     mutex_init(&dev->struct_mutex);
  410.     mutex_init(&dev->ctxlist_mutex);
  411.  
  412.     ret = i915_driver_load(dev, ent->driver_data );
  413.  
  414.     if (ret)
  415.         goto err_g4;
  416.  
  417.     ret = init_display_kms(dev);
  418.  
  419.     if (ret)
  420.         goto err_g4;
  421.  
  422.     main_device = dev;
  423.  
  424.     LEAVE();
  425.  
  426.     return 0;
  427.  
  428. err_g4:
  429. //    drm_put_minor(&dev->primary);
  430. //err_g3:
  431. //    if (drm_core_check_feature(dev, DRIVER_MODESET))
  432. //        drm_put_minor(&dev->control);
  433. //err_g2:
  434. //    pci_disable_device(pdev);
  435. //err_g1:
  436.     free(dev);
  437.  
  438.     LEAVE();
  439.  
  440.     return ret;
  441. }
  442.  
  443.  
  444.