Subversion Repositories Kolibri OS

Rev

Rev 3480 | Rev 3746 | 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 <drm/drmP.h>
  32. #include <drm/i915_drm.h>
  33. #include "i915_drv.h"
  34. #include "intel_drv.h"
  35.  
  36. #include <linux/kernel.h>
  37. #include <linux/module.h>
  38. #include <linux/mod_devicetable.h>
  39. #include <errno-base.h>
  40. #include <linux/pci.h>
  41.  
  42. #include <drm/drm_crtc_helper.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. struct drm_file *drm_file_handlers[256];
  53.  
  54. static int i915_modeset __read_mostly = 1;
  55. module_param_named(modeset, i915_modeset, int, 0400);
  56. MODULE_PARM_DESC(modeset,
  57.                 "Use kernel modesetting [KMS] (0=DRM_I915_KMS from .config, "
  58.                 "1=on, -1=force vga console preference [default])");
  59.  
  60.  
  61. int i915_panel_ignore_lid __read_mostly         =  1;
  62. module_param_named(panel_ignore_lid, i915_panel_ignore_lid, int, 0600);
  63. MODULE_PARM_DESC(panel_ignore_lid,
  64.                 "Override lid status (0=autodetect, 1=autodetect disabled [default], "
  65.                 "-1=force lid closed, -2=force lid open)");
  66.  
  67. unsigned int i915_powersave __read_mostly = 1;
  68. module_param_named(powersave, i915_powersave, int, 0600);
  69. MODULE_PARM_DESC(powersave,
  70.                 "Enable powersavings, fbc, downclocking, etc. (default: true)");
  71.  
  72. int i915_semaphores __read_mostly = -1;
  73. module_param_named(semaphores, i915_semaphores, int, 0600);
  74. MODULE_PARM_DESC(semaphores,
  75.                 "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))");
  76.  
  77. int i915_enable_rc6 __read_mostly = -1;
  78. module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0400);
  79. MODULE_PARM_DESC(i915_enable_rc6,
  80.                 "Enable power-saving render C-state 6. "
  81.                 "Different stages can be selected via bitmask values "
  82.                 "(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
  83.                 "For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
  84.                 "default: -1 (use per-chip default)");
  85.  
  86. int i915_enable_fbc __read_mostly = -1;
  87. module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
  88. MODULE_PARM_DESC(i915_enable_fbc,
  89.                 "Enable frame buffer compression for power savings "
  90.                 "(default: -1 (use per-chip default))");
  91.  
  92. unsigned int i915_lvds_downclock  __read_mostly =  0;
  93. module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400);
  94. MODULE_PARM_DESC(lvds_downclock,
  95.                 "Use panel (LVDS/eDP) downclocking for power savings "
  96.                 "(default: false)");
  97.  
  98. int i915_lvds_channel_mode __read_mostly;
  99. module_param_named(lvds_channel_mode, i915_lvds_channel_mode, int, 0600);
  100. MODULE_PARM_DESC(lvds_channel_mode,
  101.                  "Specify LVDS channel mode "
  102.                  "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)");
  103.  
  104. int i915_panel_use_ssc __read_mostly = -1;
  105. module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600);
  106. MODULE_PARM_DESC(lvds_use_ssc,
  107.                 "Use Spread Spectrum Clock with panels [LVDS/eDP] "
  108.                 "(default: auto from VBT)");
  109.  
  110. int i915_vbt_sdvo_panel_type __read_mostly      = -1;
  111. module_param_named(vbt_sdvo_panel_type, i915_vbt_sdvo_panel_type, int, 0600);
  112. MODULE_PARM_DESC(vbt_sdvo_panel_type,
  113.                 "Override/Ignore selection of SDVO panel mode in the VBT "
  114.                 "(-2=ignore, -1=auto [default], index in VBT BIOS table)");
  115.  
  116. static bool i915_try_reset __read_mostly = true;
  117. module_param_named(reset, i915_try_reset, bool, 0600);
  118. MODULE_PARM_DESC(reset, "Attempt GPU resets (default: true)");
  119.  
  120. bool i915_enable_hangcheck __read_mostly = false;
  121. module_param_named(enable_hangcheck, i915_enable_hangcheck, bool, 0644);
  122. MODULE_PARM_DESC(enable_hangcheck,
  123.                 "Periodically check GPU activity for detecting hangs. "
  124.                 "WARNING: Disabling this can cause system wide hangs. "
  125.                 "(default: true)");
  126.  
  127. int i915_enable_ppgtt __read_mostly = false;
  128. module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, int, 0600);
  129. MODULE_PARM_DESC(i915_enable_ppgtt,
  130.                 "Enable PPGTT (default: true)");
  131.  
  132. unsigned int i915_preliminary_hw_support __read_mostly = true;
  133. module_param_named(preliminary_hw_support, i915_preliminary_hw_support, int, 0600);
  134. MODULE_PARM_DESC(preliminary_hw_support,
  135.                 "Enable preliminary hardware support. "
  136.                 "Enable Haswell and ValleyView Support. "
  137.                 "(default: false)");
  138.  
  139. int i915_disable_power_well __read_mostly = 0;
  140. module_param_named(disable_power_well, i915_disable_power_well, int, 0600);
  141. MODULE_PARM_DESC(disable_power_well,
  142.                  "Disable the power well when possible (default: false)");
  143.  
  144. #define PCI_VENDOR_ID_INTEL        0x8086
  145.  
  146. #define INTEL_VGA_DEVICE(id, info) {        \
  147.         .class = PCI_BASE_CLASS_DISPLAY << 16,  \
  148.     .class_mask = 0xff0000,                 \
  149.     .vendor = 0x8086,                       \
  150.     .device = id,                           \
  151.     .subvendor = PCI_ANY_ID,                \
  152.     .subdevice = PCI_ANY_ID,                \
  153.     .driver_data = (unsigned long) info }
  154.  
  155.  
  156. static const struct intel_device_info intel_i915g_info = {
  157.         .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1,
  158.         .has_overlay = 1, .overlay_needs_physical = 1,
  159. };
  160. static const struct intel_device_info intel_i915gm_info = {
  161.         .gen = 3, .is_mobile = 1,
  162.         .cursor_needs_physical = 1,
  163.         .has_overlay = 1, .overlay_needs_physical = 1,
  164.         .supports_tv = 1,
  165. };
  166. static const struct intel_device_info intel_i945g_info = {
  167.         .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1,
  168.         .has_overlay = 1, .overlay_needs_physical = 1,
  169. };
  170. static const struct intel_device_info intel_i945gm_info = {
  171.         .gen = 3, .is_i945gm = 1, .is_mobile = 1,
  172.         .has_hotplug = 1, .cursor_needs_physical = 1,
  173.         .has_overlay = 1, .overlay_needs_physical = 1,
  174.         .supports_tv = 1,
  175. };
  176.  
  177. static const struct intel_device_info intel_i965g_info = {
  178.         .gen = 4, .is_broadwater = 1,
  179.         .has_hotplug = 1,
  180.         .has_overlay = 1,
  181. };
  182.  
  183. static const struct intel_device_info intel_i965gm_info = {
  184.         .gen = 4, .is_crestline = 1,
  185.         .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
  186.         .has_overlay = 1,
  187.         .supports_tv = 1,
  188. };
  189.  
  190. static const struct intel_device_info intel_g33_info = {
  191.         .gen = 3, .is_g33 = 1,
  192.         .need_gfx_hws = 1, .has_hotplug = 1,
  193.         .has_overlay = 1,
  194. };
  195.  
  196. static const struct intel_device_info intel_g45_info = {
  197.         .gen = 4, .is_g4x = 1, .need_gfx_hws = 1,
  198.         .has_pipe_cxsr = 1, .has_hotplug = 1,
  199.         .has_bsd_ring = 1,
  200. };
  201.  
  202. static const struct intel_device_info intel_gm45_info = {
  203.         .gen = 4, .is_g4x = 1,
  204.         .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
  205.         .has_pipe_cxsr = 1, .has_hotplug = 1,
  206.         .supports_tv = 1,
  207.         .has_bsd_ring = 1,
  208. };
  209.  
  210. static const struct intel_device_info intel_pineview_info = {
  211.         .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1,
  212.         .need_gfx_hws = 1, .has_hotplug = 1,
  213.         .has_overlay = 1,
  214. };
  215.  
  216. static const struct intel_device_info intel_ironlake_d_info = {
  217.         .gen = 5,
  218.         .need_gfx_hws = 1, .has_hotplug = 1,
  219.         .has_bsd_ring = 1,
  220. };
  221.  
  222. static const struct intel_device_info intel_ironlake_m_info = {
  223.         .gen = 5, .is_mobile = 1,
  224.         .need_gfx_hws = 1, .has_hotplug = 1,
  225.         .has_fbc = 1,
  226.         .has_bsd_ring = 1,
  227. };
  228.  
  229. static const struct intel_device_info intel_sandybridge_d_info = {
  230.     .gen = 6,
  231.         .need_gfx_hws = 1, .has_hotplug = 1,
  232.     .has_bsd_ring = 1,
  233.     .has_blt_ring = 1,
  234.         .has_llc = 1,
  235.         .has_force_wake = 1,
  236. };
  237.  
  238. static const struct intel_device_info intel_sandybridge_m_info = {
  239.         .gen = 6, .is_mobile = 1,
  240.         .need_gfx_hws = 1, .has_hotplug = 1,
  241.     .has_fbc      = 1,
  242.     .has_bsd_ring = 1,
  243.     .has_blt_ring = 1,
  244.         .has_llc = 1,
  245.         .has_force_wake = 1,
  246. };
  247.  
  248. static const struct intel_device_info intel_ivybridge_d_info = {
  249.         .is_ivybridge = 1, .gen = 7,
  250.         .need_gfx_hws = 1, .has_hotplug = 1,
  251.         .has_bsd_ring = 1,
  252.         .has_blt_ring = 1,
  253.         .has_llc = 1,
  254.         .has_force_wake = 1,
  255. };
  256.  
  257. static const struct intel_device_info intel_ivybridge_m_info = {
  258.         .is_ivybridge = 1, .gen = 7, .is_mobile = 1,
  259.         .need_gfx_hws = 1, .has_hotplug = 1,
  260.         .has_fbc = 0,   /* FBC is not enabled on Ivybridge mobile yet */
  261.         .has_bsd_ring = 1,
  262.         .has_blt_ring = 1,
  263.         .has_llc = 1,
  264.         .has_force_wake = 1,
  265. };
  266.  
  267. static const struct intel_device_info intel_valleyview_m_info = {
  268.         .gen = 7, .is_mobile = 1,
  269.         .need_gfx_hws = 1, .has_hotplug = 1,
  270.         .has_fbc = 0,
  271.         .has_bsd_ring = 1,
  272.         .has_blt_ring = 1,
  273.         .is_valleyview = 1,
  274.         .display_mmio_offset = VLV_DISPLAY_BASE,
  275. };
  276.  
  277. static const struct intel_device_info intel_valleyview_d_info = {
  278.         .gen = 7,
  279.         .need_gfx_hws = 1, .has_hotplug = 1,
  280.         .has_fbc = 0,
  281.         .has_bsd_ring = 1,
  282.         .has_blt_ring = 1,
  283.         .is_valleyview = 1,
  284.         .display_mmio_offset = VLV_DISPLAY_BASE,
  285. };
  286.  
  287. static const struct intel_device_info intel_haswell_d_info = {
  288.         .is_haswell = 1, .gen = 7,
  289.         .need_gfx_hws = 1, .has_hotplug = 1,
  290.         .has_bsd_ring = 1,
  291.         .has_blt_ring = 1,
  292.         .has_llc = 1,
  293.         .has_force_wake = 1,
  294. };
  295.  
  296. static const struct intel_device_info intel_haswell_m_info = {
  297.         .is_haswell = 1, .gen = 7, .is_mobile = 1,
  298.         .need_gfx_hws = 1, .has_hotplug = 1,
  299.         .has_bsd_ring = 1,
  300.         .has_blt_ring = 1,
  301.         .has_llc = 1,
  302.         .has_force_wake = 1,
  303. };
  304.  
  305. static const struct pci_device_id pciidlist[] = {       /* aka */
  306.         INTEL_VGA_DEVICE(0x2582, &intel_i915g_info),            /* I915_G */
  307.         INTEL_VGA_DEVICE(0x258a, &intel_i915g_info),            /* E7221_G */
  308.         INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info),           /* I915_GM */
  309.         INTEL_VGA_DEVICE(0x2772, &intel_i945g_info),            /* I945_G */
  310.         INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info),           /* I945_GM */
  311.         INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info),           /* I945_GME */
  312.         INTEL_VGA_DEVICE(0x2972, &intel_i965g_info),            /* I946_GZ */
  313.         INTEL_VGA_DEVICE(0x2982, &intel_i965g_info),            /* G35_G */
  314.         INTEL_VGA_DEVICE(0x2992, &intel_i965g_info),            /* I965_Q */
  315.         INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info),            /* I965_G */
  316.         INTEL_VGA_DEVICE(0x29b2, &intel_g33_info),              /* Q35_G */
  317.         INTEL_VGA_DEVICE(0x29c2, &intel_g33_info),              /* G33_G */
  318.         INTEL_VGA_DEVICE(0x29d2, &intel_g33_info),              /* Q33_G */
  319.         INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info),           /* I965_GM */
  320.         INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info),           /* I965_GME */
  321.         INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info),             /* GM45_G */
  322.         INTEL_VGA_DEVICE(0x2e02, &intel_g45_info),              /* IGD_E_G */
  323.         INTEL_VGA_DEVICE(0x2e12, &intel_g45_info),              /* Q45_G */
  324.         INTEL_VGA_DEVICE(0x2e22, &intel_g45_info),              /* G45_G */
  325.         INTEL_VGA_DEVICE(0x2e32, &intel_g45_info),              /* G41_G */
  326.         INTEL_VGA_DEVICE(0x2e42, &intel_g45_info),              /* B43_G */
  327.         INTEL_VGA_DEVICE(0x2e92, &intel_g45_info),              /* B43_G.1 */
  328.         INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
  329.         INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
  330.         INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
  331.         INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info),
  332.     INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info),
  333.     INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info),
  334.     INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info),
  335.     INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info),
  336.     INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info),
  337.     INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info),
  338.     INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info),
  339.         INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */
  340.         INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */
  341.         INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
  342.         INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
  343.         INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
  344.         INTEL_VGA_DEVICE(0x016a, &intel_ivybridge_d_info), /* GT2 server */
  345.         INTEL_VGA_DEVICE(0x0402, &intel_haswell_d_info), /* GT1 desktop */
  346.         INTEL_VGA_DEVICE(0x0412, &intel_haswell_d_info), /* GT2 desktop */
  347.         INTEL_VGA_DEVICE(0x0422, &intel_haswell_d_info), /* GT2 desktop */
  348.         INTEL_VGA_DEVICE(0x040a, &intel_haswell_d_info), /* GT1 server */
  349.         INTEL_VGA_DEVICE(0x041a, &intel_haswell_d_info), /* GT2 server */
  350.         INTEL_VGA_DEVICE(0x042a, &intel_haswell_d_info), /* GT2 server */
  351.         INTEL_VGA_DEVICE(0x0406, &intel_haswell_m_info), /* GT1 mobile */
  352.         INTEL_VGA_DEVICE(0x0416, &intel_haswell_m_info), /* GT2 mobile */
  353.         INTEL_VGA_DEVICE(0x0426, &intel_haswell_m_info), /* GT2 mobile */
  354.         INTEL_VGA_DEVICE(0x0C02, &intel_haswell_d_info), /* SDV GT1 desktop */
  355.         INTEL_VGA_DEVICE(0x0C12, &intel_haswell_d_info), /* SDV GT2 desktop */
  356.         INTEL_VGA_DEVICE(0x0C22, &intel_haswell_d_info), /* SDV GT2 desktop */
  357.         INTEL_VGA_DEVICE(0x0C0A, &intel_haswell_d_info), /* SDV GT1 server */
  358.         INTEL_VGA_DEVICE(0x0C1A, &intel_haswell_d_info), /* SDV GT2 server */
  359.         INTEL_VGA_DEVICE(0x0C2A, &intel_haswell_d_info), /* SDV GT2 server */
  360.         INTEL_VGA_DEVICE(0x0C06, &intel_haswell_m_info), /* SDV GT1 mobile */
  361.         INTEL_VGA_DEVICE(0x0C16, &intel_haswell_m_info), /* SDV GT2 mobile */
  362.         INTEL_VGA_DEVICE(0x0C26, &intel_haswell_m_info), /* SDV GT2 mobile */
  363.         INTEL_VGA_DEVICE(0x0A02, &intel_haswell_d_info), /* ULT GT1 desktop */
  364.         INTEL_VGA_DEVICE(0x0A12, &intel_haswell_d_info), /* ULT GT2 desktop */
  365.         INTEL_VGA_DEVICE(0x0A22, &intel_haswell_d_info), /* ULT GT2 desktop */
  366.         INTEL_VGA_DEVICE(0x0A0A, &intel_haswell_d_info), /* ULT GT1 server */
  367.         INTEL_VGA_DEVICE(0x0A1A, &intel_haswell_d_info), /* ULT GT2 server */
  368.         INTEL_VGA_DEVICE(0x0A2A, &intel_haswell_d_info), /* ULT GT2 server */
  369.         INTEL_VGA_DEVICE(0x0A06, &intel_haswell_m_info), /* ULT GT1 mobile */
  370.         INTEL_VGA_DEVICE(0x0A16, &intel_haswell_m_info), /* ULT GT2 mobile */
  371.         INTEL_VGA_DEVICE(0x0A26, &intel_haswell_m_info), /* ULT GT2 mobile */
  372.         INTEL_VGA_DEVICE(0x0D02, &intel_haswell_d_info), /* CRW GT1 desktop */
  373.         INTEL_VGA_DEVICE(0x0D12, &intel_haswell_d_info), /* CRW GT2 desktop */
  374.         INTEL_VGA_DEVICE(0x0D22, &intel_haswell_d_info), /* CRW GT2 desktop */
  375.         INTEL_VGA_DEVICE(0x0D0A, &intel_haswell_d_info), /* CRW GT1 server */
  376.         INTEL_VGA_DEVICE(0x0D1A, &intel_haswell_d_info), /* CRW GT2 server */
  377.         INTEL_VGA_DEVICE(0x0D2A, &intel_haswell_d_info), /* CRW GT2 server */
  378.         INTEL_VGA_DEVICE(0x0D06, &intel_haswell_m_info), /* CRW GT1 mobile */
  379.         INTEL_VGA_DEVICE(0x0D16, &intel_haswell_m_info), /* CRW GT2 mobile */
  380.         INTEL_VGA_DEVICE(0x0D26, &intel_haswell_m_info), /* CRW GT2 mobile */
  381.         INTEL_VGA_DEVICE(0x0f30, &intel_valleyview_m_info),
  382.         INTEL_VGA_DEVICE(0x0157, &intel_valleyview_m_info),
  383.         INTEL_VGA_DEVICE(0x0155, &intel_valleyview_d_info),
  384.     {0, 0, 0}
  385. };
  386.  
  387. #define INTEL_PCH_DEVICE_ID_MASK        0xff00
  388. #define INTEL_PCH_IBX_DEVICE_ID_TYPE    0x3b00
  389. #define INTEL_PCH_CPT_DEVICE_ID_TYPE    0x1c00
  390. #define INTEL_PCH_PPT_DEVICE_ID_TYPE    0x1e00
  391. #define INTEL_PCH_LPT_DEVICE_ID_TYPE    0x8c00
  392.  
  393. void intel_detect_pch(struct drm_device *dev)
  394. {
  395.     struct drm_i915_private *dev_priv = dev->dev_private;
  396.     struct pci_dev *pch;
  397.  
  398.     /*
  399.      * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  400.      * make graphics device passthrough work easy for VMM, that only
  401.      * need to expose ISA bridge to let driver know the real hardware
  402.      * underneath. This is a requirement from virtualization team.
  403.      */
  404.     pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  405.     if (pch) {
  406.         if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  407.                         unsigned short id;
  408.             id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  409.                         dev_priv->pch_id = id;
  410.  
  411.             if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  412.                 dev_priv->pch_type = PCH_IBX;
  413.                                 dev_priv->num_pch_pll = 2;
  414.                 DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  415.                                 WARN_ON(!IS_GEN5(dev));
  416.             } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  417.                 dev_priv->pch_type = PCH_CPT;
  418.                                 dev_priv->num_pch_pll = 2;
  419.                 DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  420.                                 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  421.             } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  422.                 /* PantherPoint is CPT compatible */
  423.                 dev_priv->pch_type = PCH_CPT;
  424.                                 dev_priv->num_pch_pll = 2;
  425.                 DRM_DEBUG_KMS("Found PatherPoint PCH\n");
  426.                                 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  427.                         } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
  428.                                 dev_priv->pch_type = PCH_LPT;
  429.                                 dev_priv->num_pch_pll = 0;
  430.                                 DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  431.                                 WARN_ON(!IS_HASWELL(dev));
  432.                         } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  433.                                 dev_priv->pch_type = PCH_LPT;
  434.                                 dev_priv->num_pch_pll = 0;
  435.                                 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
  436.                                 WARN_ON(!IS_HASWELL(dev));
  437.             }
  438.                         BUG_ON(dev_priv->num_pch_pll > I915_NUM_PLLS);
  439.         }
  440.     }
  441. }
  442.  
  443. bool i915_semaphore_is_enabled(struct drm_device *dev)
  444. {
  445.         if (INTEL_INFO(dev)->gen < 6)
  446.                 return 0;
  447.  
  448.         if (i915_semaphores >= 0)
  449.                 return i915_semaphores;
  450.  
  451. #ifdef CONFIG_INTEL_IOMMU
  452.         /* Enable semaphores on SNB when IO remapping is off */
  453.         if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
  454.                 return false;
  455. #endif
  456.  
  457.         return 1;
  458. }
  459.  
  460.  
  461.  
  462.  
  463.  
  464. int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent);
  465.  
  466. int i915_init(void)
  467. {
  468.     static pci_dev_t device;
  469.     const struct pci_device_id  *ent;
  470.     int  err;
  471.  
  472.     ent = find_pci_device(&device, pciidlist);
  473.     if( unlikely(ent == NULL) )
  474.     {
  475.         dbgprintf("device not found\n");
  476.         return -ENODEV;
  477.     };
  478.  
  479.     struct intel_device_info *intel_info =
  480.         (struct intel_device_info *) ent->driver_data;
  481.  
  482.         if (intel_info->is_valleyview)
  483.         if(!i915_preliminary_hw_support) {
  484.             DRM_ERROR("Preliminary hardware support disabled\n");
  485.             return -ENODEV;
  486.         }
  487.  
  488.     DRM_INFO("device %x:%x\n", device.pci_dev.vendor,
  489.                                 device.pci_dev.device);
  490.  
  491.     if (intel_info->gen != 3) {
  492.  
  493.     } else if (init_agp() != 0) {
  494.         DRM_ERROR("drm/i915 can't work without intel_agp module!\n");
  495.         return -ENODEV;
  496.     }
  497.  
  498.     err = drm_get_dev(&device.pci_dev, ent);
  499.  
  500.     return err;
  501. }
  502.  
  503.  
  504.  
  505. static struct drm_driver driver = {
  506.     /* Don't use MTRRs here; the Xserver or userspace app should
  507.      * deal with them for Intel hardware.
  508.      */
  509.     .driver_features =
  510.         DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
  511.         DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_MODESET,
  512. //    .load = i915_driver_load,
  513. //    .unload = i915_driver_unload,
  514.       .open = i915_driver_open,
  515. //    .lastclose = i915_driver_lastclose,
  516. //    .preclose = i915_driver_preclose,
  517. //    .postclose = i915_driver_postclose,
  518.  
  519.     /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
  520. //    .suspend = i915_suspend,
  521. //    .resume = i915_resume,
  522.  
  523. //    .device_is_agp = i915_driver_device_is_agp,
  524. //    .master_create = i915_master_create,
  525. //    .master_destroy = i915_master_destroy,
  526.     .gem_init_object = i915_gem_init_object,
  527.     .gem_free_object = i915_gem_free_object,
  528. //    .gem_vm_ops = &i915_gem_vm_ops,
  529.  
  530. //    .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  531. //    .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  532. //    .gem_prime_export = i915_gem_prime_export,
  533. //    .gem_prime_import = i915_gem_prime_import,
  534.  
  535. //    .dumb_create = i915_gem_dumb_create,
  536. //    .dumb_map_offset = i915_gem_mmap_gtt,
  537. //    .dumb_destroy = i915_gem_dumb_destroy,
  538. //    .ioctls = i915_ioctls,
  539. //    .fops = &i915_driver_fops,
  540. //    .name = DRIVER_NAME,
  541. //    .desc = DRIVER_DESC,
  542. //    .date = DRIVER_DATE,
  543. //    .major = DRIVER_MAJOR,
  544. //    .minor = DRIVER_MINOR,
  545. //    .patchlevel = DRIVER_PATCHLEVEL,
  546. };
  547.  
  548.  
  549. int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent)
  550. {
  551.     static struct drm_device drm_dev;
  552.     static struct drm_file   drm_file;
  553.  
  554.     struct drm_device *dev;
  555.     struct drm_file   *priv;
  556.  
  557.     int ret;
  558.  
  559.     dev  = &drm_dev;
  560.     priv = &drm_file;
  561.  
  562.     drm_file_handlers[0] = priv;
  563.  
  564.  //   ret = pci_enable_device(pdev);
  565.  //   if (ret)
  566.  //       goto err_g1;
  567.  
  568.     pci_set_master(pdev);
  569.  
  570.  //   if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
  571.  //       printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
  572.  //       goto err_g2;
  573.  //   }
  574.  
  575.     dev->pdev = pdev;
  576.     dev->pci_device = pdev->device;
  577.     dev->pci_vendor = pdev->vendor;
  578.  
  579.     INIT_LIST_HEAD(&dev->filelist);
  580.     INIT_LIST_HEAD(&dev->ctxlist);
  581.     INIT_LIST_HEAD(&dev->vmalist);
  582.     INIT_LIST_HEAD(&dev->maplist);
  583.  
  584.     spin_lock_init(&dev->count_lock);
  585.     mutex_init(&dev->struct_mutex);
  586.     mutex_init(&dev->ctxlist_mutex);
  587.  
  588.     INIT_LIST_HEAD(&priv->lhead);
  589.     INIT_LIST_HEAD(&priv->fbs);
  590.     INIT_LIST_HEAD(&priv->event_list);
  591.     init_waitqueue_head(&priv->event_wait);
  592.     priv->event_space = 4096; /* set aside 4k for event buffer */
  593.  
  594.     idr_init(&priv->object_idr);
  595.     spin_lock_init(&priv->table_lock);
  596.  
  597.     dev->driver = &driver;
  598.  
  599.     if (dev->driver->open) {
  600.         ret = dev->driver->open(dev, priv);
  601.         if (ret < 0)
  602.             goto err_g4;
  603.     }
  604.  
  605.     ret = i915_driver_load(dev, ent->driver_data );
  606.  
  607.     if (ret)
  608.         goto err_g4;
  609.  
  610.     ret = init_display_kms(dev);
  611.  
  612.     if (ret)
  613.         goto err_g4;
  614.  
  615.     return 0;
  616.  
  617. err_g4:
  618. //err_g3:
  619. //    if (drm_core_check_feature(dev, DRIVER_MODESET))
  620. //        drm_put_minor(&dev->control);
  621. //err_g2:
  622. //    pci_disable_device(pdev);
  623. //err_g1:
  624.  
  625.     return ret;
  626. }
  627.  
  628. /* We give fast paths for the really cool registers */
  629. #define NEEDS_FORCE_WAKE(dev_priv, reg) \
  630.         ((HAS_FORCE_WAKE((dev_priv)->dev)) && \
  631.          ((reg) < 0x40000) &&            \
  632.          ((reg) != FORCEWAKE))
  633.  
  634. static bool IS_DISPLAYREG(u32 reg)
  635. {
  636.         /*
  637.          * This should make it easier to transition modules over to the
  638.          * new register block scheme, since we can do it incrementally.
  639.          */
  640.         if (reg >= VLV_DISPLAY_BASE)
  641.                 return false;
  642.  
  643.         if (reg >= RENDER_RING_BASE &&
  644.             reg < RENDER_RING_BASE + 0xff)
  645.                 return false;
  646.         if (reg >= GEN6_BSD_RING_BASE &&
  647.             reg < GEN6_BSD_RING_BASE + 0xff)
  648.                 return false;
  649.         if (reg >= BLT_RING_BASE &&
  650.             reg < BLT_RING_BASE + 0xff)
  651.                 return false;
  652.  
  653.         if (reg == PGTBL_ER)
  654.                 return false;
  655.  
  656.         if (reg >= IPEIR_I965 &&
  657.             reg < HWSTAM)
  658.                 return false;
  659.  
  660.         if (reg == MI_MODE)
  661.                 return false;
  662.  
  663.         if (reg == GFX_MODE_GEN7)
  664.                 return false;
  665.  
  666.         if (reg == RENDER_HWS_PGA_GEN7 ||
  667.             reg == BSD_HWS_PGA_GEN7 ||
  668.             reg == BLT_HWS_PGA_GEN7)
  669.                 return false;
  670.  
  671.         if (reg == GEN6_BSD_SLEEP_PSMI_CONTROL ||
  672.             reg == GEN6_BSD_RNCID)
  673.                 return false;
  674.  
  675.         if (reg == GEN6_BLITTER_ECOSKPD)
  676.                 return false;
  677.  
  678.         if (reg >= 0x4000c &&
  679.             reg <= 0x4002c)
  680.                 return false;
  681.  
  682.         if (reg >= 0x4f000 &&
  683.             reg <= 0x4f08f)
  684.                 return false;
  685.  
  686.         if (reg >= 0x4f100 &&
  687.             reg <= 0x4f11f)
  688.                 return false;
  689.  
  690.         if (reg >= VLV_MASTER_IER &&
  691.             reg <= GEN6_PMIER)
  692.                 return false;
  693.  
  694.         if (reg >= FENCE_REG_SANDYBRIDGE_0 &&
  695.             reg < (FENCE_REG_SANDYBRIDGE_0 + (16*8)))
  696.                 return false;
  697.  
  698.         if (reg >= VLV_IIR_RW &&
  699.             reg <= VLV_ISR)
  700.                 return false;
  701.  
  702.         if (reg == FORCEWAKE_VLV ||
  703.             reg == FORCEWAKE_ACK_VLV)
  704.                 return false;
  705.  
  706.         if (reg == GEN6_GDRST)
  707.                 return false;
  708.  
  709.         switch (reg) {
  710.         case _3D_CHICKEN3:
  711.         case IVB_CHICKEN3:
  712.         case GEN7_COMMON_SLICE_CHICKEN1:
  713.         case GEN7_L3CNTLREG1:
  714.         case GEN7_L3_CHICKEN_MODE_REGISTER:
  715.         case GEN7_ROW_CHICKEN2:
  716.         case GEN7_L3SQCREG4:
  717.         case GEN7_SQ_CHICKEN_MBCUNIT_CONFIG:
  718.         case GEN7_HALF_SLICE_CHICKEN1:
  719.         case GEN6_MBCTL:
  720.         case GEN6_UCGCTL2:
  721.                 return false;
  722.         default:
  723.                 break;
  724.         }
  725.  
  726.         return true;
  727. }
  728.  
  729. static void
  730. ilk_dummy_write(struct drm_i915_private *dev_priv)
  731. {
  732.         /* WaIssueDummyWriteToWakeupFromRC6: Issue a dummy write to wake up the
  733.          * chip from rc6 before touching it for real. MI_MODE is masked, hence
  734.          * harmless to write 0 into. */
  735.         I915_WRITE_NOTRACE(MI_MODE, 0);
  736. }
  737.  
  738. #define __i915_read(x, y) \
  739. u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
  740.         u##x val = 0; \
  741.         if (IS_GEN5(dev_priv->dev)) \
  742.                 ilk_dummy_write(dev_priv); \
  743.         if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  744.                 unsigned long irqflags; \
  745.                 spin_lock_irqsave(&dev_priv->gt_lock, irqflags); \
  746.                 if (dev_priv->forcewake_count == 0) \
  747.                         dev_priv->gt.force_wake_get(dev_priv); \
  748.                 val = read##y(dev_priv->regs + reg); \
  749.                 if (dev_priv->forcewake_count == 0) \
  750.                         dev_priv->gt.force_wake_put(dev_priv); \
  751.                 spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags); \
  752.         } else { \
  753.                 val = read##y(dev_priv->regs + reg); \
  754.         } \
  755.         return val; \
  756. }
  757.  
  758. __i915_read(8, b)
  759. __i915_read(16, w)
  760. __i915_read(32, l)
  761. __i915_read(64, q)
  762. #undef __i915_read
  763.  
  764. #define __i915_write(x, y) \
  765. void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val) { \
  766.         u32 __fifo_ret = 0; \
  767.         trace_i915_reg_rw(true, reg, val, sizeof(val)); \
  768.         if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  769.                 __fifo_ret = __gen6_gt_wait_for_fifo(dev_priv); \
  770.         } \
  771.         if (IS_GEN5(dev_priv->dev)) \
  772.                 ilk_dummy_write(dev_priv); \
  773.         if (IS_HASWELL(dev_priv->dev) && (I915_READ_NOTRACE(GEN7_ERR_INT) & ERR_INT_MMIO_UNCLAIMED)) { \
  774.                 DRM_ERROR("Unknown unclaimed register before writing to %x\n", reg); \
  775.                 I915_WRITE_NOTRACE(GEN7_ERR_INT, ERR_INT_MMIO_UNCLAIMED); \
  776.         } \
  777.         write##y(val, dev_priv->regs + reg); \
  778.         if (unlikely(__fifo_ret)) { \
  779.                 gen6_gt_check_fifodbg(dev_priv); \
  780.         } \
  781.         if (IS_HASWELL(dev_priv->dev) && (I915_READ_NOTRACE(GEN7_ERR_INT) & ERR_INT_MMIO_UNCLAIMED)) { \
  782.                 DRM_ERROR("Unclaimed write to %x\n", reg); \
  783.                 writel(ERR_INT_MMIO_UNCLAIMED, dev_priv->regs + GEN7_ERR_INT);  \
  784.         } \
  785. }
  786. __i915_write(8, b)
  787. __i915_write(16, w)
  788. __i915_write(32, l)
  789. __i915_write(64, q)
  790. #undef __i915_write
  791.