Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*- |
| 2 | */ |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 3 | /* |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 6 | * All Rights Reserved. |
Dave Airlie | bc54fd1 | 2005-06-23 22:46:46 +1000 | [diff] [blame] | 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 | * |
Dave Airlie | 0d6aa60 | 2006-01-02 20:14:23 +1100 | [diff] [blame] | 28 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Jesse Barnes | e5747e3 | 2014-06-12 08:35:47 -0700 | [diff] [blame] | 30 | #include <linux/acpi.h> |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 31 | #include <linux/device.h> |
| 32 | #include <linux/oom.h> |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/pm.h> |
| 36 | #include <linux/pm_runtime.h> |
| 37 | #include <linux/pnp.h> |
| 38 | #include <linux/slab.h> |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 39 | #include <linux/vga_switcheroo.h> |
| 40 | #include <linux/vt.h> |
| 41 | #include <acpi/video.h> |
| 42 | |
Maarten Lankhorst | a667fb4 | 2016-12-15 15:29:44 +0100 | [diff] [blame] | 43 | #include <drm/drm_atomic_helper.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 44 | #include <drm/drm_ioctl.h> |
| 45 | #include <drm/drm_irq.h> |
| 46 | #include <drm/drm_probe_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 47 | #include <drm/i915_drm.h> |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 48 | |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 49 | #include "display/intel_acpi.h" |
| 50 | #include "display/intel_audio.h" |
| 51 | #include "display/intel_bw.h" |
| 52 | #include "display/intel_cdclk.h" |
Jani Nikula | 1d455f8 | 2019-08-06 14:39:33 +0300 | [diff] [blame] | 53 | #include "display/intel_display_types.h" |
Jani Nikula | 379bc10 | 2019-06-13 11:44:15 +0300 | [diff] [blame] | 54 | #include "display/intel_dp.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 55 | #include "display/intel_fbdev.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 56 | #include "display/intel_hotplug.h" |
| 57 | #include "display/intel_overlay.h" |
| 58 | #include "display/intel_pipe_crc.h" |
| 59 | #include "display/intel_sprite.h" |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 60 | #include "display/intel_vga.h" |
Jani Nikula | 379bc10 | 2019-06-13 11:44:15 +0300 | [diff] [blame] | 61 | |
Chris Wilson | 10be98a | 2019-05-28 10:29:49 +0100 | [diff] [blame] | 62 | #include "gem/i915_gem_context.h" |
Chris Wilson | afa1308 | 2019-05-28 10:29:43 +0100 | [diff] [blame] | 63 | #include "gem/i915_gem_ioctls.h" |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 64 | #include "gem/i915_gem_mman.h" |
Tvrtko Ursulin | 24635c5 | 2019-06-21 08:07:41 +0100 | [diff] [blame] | 65 | #include "gt/intel_gt.h" |
Chris Wilson | 79ffac85 | 2019-04-24 21:07:17 +0100 | [diff] [blame] | 66 | #include "gt/intel_gt_pm.h" |
Imre Deak | 2248a28 | 2019-10-17 16:38:31 +0300 | [diff] [blame] | 67 | #include "gt/intel_rc6.h" |
Chris Wilson | 112ed2d | 2019-04-24 18:48:39 +0100 | [diff] [blame] | 68 | |
Jani Nikula | 2126d3e | 2019-05-02 18:02:43 +0300 | [diff] [blame] | 69 | #include "i915_debugfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #include "i915_drv.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 71 | #include "i915_irq.h" |
Jani Nikula | 9c9082b | 2019-08-08 16:42:47 +0300 | [diff] [blame] | 72 | #include "i915_memcpy.h" |
Jani Nikula | db94e9f | 2019-08-08 16:42:44 +0300 | [diff] [blame] | 73 | #include "i915_perf.h" |
Lionel Landwerlin | a446ae2 | 2018-03-06 12:28:56 +0000 | [diff] [blame] | 74 | #include "i915_query.h" |
Jani Nikula | bdd1510 | 2019-08-08 16:42:46 +0300 | [diff] [blame] | 75 | #include "i915_suspend.h" |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 76 | #include "i915_switcheroo.h" |
Jani Nikula | be68261 | 2019-08-08 16:42:45 +0300 | [diff] [blame] | 77 | #include "i915_sysfs.h" |
Jani Nikula | 331c201 | 2019-04-05 14:00:03 +0300 | [diff] [blame] | 78 | #include "i915_trace.h" |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 79 | #include "i915_vgpu.h" |
Jani Nikula | 174594d | 2019-04-05 14:00:07 +0300 | [diff] [blame] | 80 | #include "intel_csr.h" |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 81 | #include "intel_memory_region.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 82 | #include "intel_pm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 84 | static struct drm_driver driver; |
| 85 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 86 | struct vlv_s0ix_state { |
| 87 | /* GAM */ |
| 88 | u32 wr_watermark; |
| 89 | u32 gfx_prio_ctrl; |
| 90 | u32 arb_mode; |
| 91 | u32 gfx_pend_tlb0; |
| 92 | u32 gfx_pend_tlb1; |
| 93 | u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM]; |
| 94 | u32 media_max_req_count; |
| 95 | u32 gfx_max_req_count; |
| 96 | u32 render_hwsp; |
| 97 | u32 ecochk; |
| 98 | u32 bsd_hwsp; |
| 99 | u32 blt_hwsp; |
| 100 | u32 tlb_rd_addr; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 101 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 102 | /* MBC */ |
| 103 | u32 g3dctl; |
| 104 | u32 gsckgctl; |
| 105 | u32 mbctl; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 106 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 107 | /* GCP */ |
| 108 | u32 ucgctl1; |
| 109 | u32 ucgctl3; |
| 110 | u32 rcgctl1; |
| 111 | u32 rcgctl2; |
| 112 | u32 rstctl; |
| 113 | u32 misccpctl; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 114 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 115 | /* GPM */ |
| 116 | u32 gfxpause; |
| 117 | u32 rpdeuhwtc; |
| 118 | u32 rpdeuc; |
| 119 | u32 ecobus; |
| 120 | u32 pwrdwnupctl; |
| 121 | u32 rp_down_timeout; |
| 122 | u32 rp_deucsw; |
| 123 | u32 rcubmabdtmr; |
| 124 | u32 rcedata; |
| 125 | u32 spare2gh; |
Chris Wilson | 51c18bf | 2018-06-09 12:10:58 +0100 | [diff] [blame] | 126 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 127 | /* Display 1 CZ domain */ |
| 128 | u32 gt_imr; |
| 129 | u32 gt_ier; |
| 130 | u32 pm_imr; |
| 131 | u32 pm_ier; |
| 132 | u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM]; |
Chris Wilson | 51c18bf | 2018-06-09 12:10:58 +0100 | [diff] [blame] | 133 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 134 | /* GT SA CZ domain */ |
| 135 | u32 tilectl; |
| 136 | u32 gt_fifoctl; |
| 137 | u32 gtlc_wake_ctrl; |
| 138 | u32 gtlc_survive; |
| 139 | u32 pmwgicz; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 140 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 141 | /* Display 2 CZ domain */ |
| 142 | u32 gu_ctl0; |
| 143 | u32 gu_ctl1; |
| 144 | u32 pcbr; |
| 145 | u32 clock_gate_dis2; |
| 146 | }; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 147 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 148 | static int i915_get_bridge_dev(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 149 | { |
Sinan Kaya | 57b29646 | 2017-11-27 11:57:46 -0500 | [diff] [blame] | 150 | int domain = pci_domain_nr(dev_priv->drm.pdev->bus); |
| 151 | |
| 152 | dev_priv->bridge_dev = |
| 153 | pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 0)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 154 | if (!dev_priv->bridge_dev) { |
| 155 | DRM_ERROR("bridge device not found\n"); |
| 156 | return -1; |
| 157 | } |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | /* Allocate space for the MCH regs if needed, return nonzero on error */ |
| 162 | static int |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 163 | intel_alloc_mchbar_resource(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 164 | { |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 165 | int reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 166 | u32 temp_lo, temp_hi = 0; |
| 167 | u64 mchbar_addr; |
| 168 | int ret; |
| 169 | |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 170 | if (INTEL_GEN(dev_priv) >= 4) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 171 | pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); |
| 172 | pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); |
| 173 | mchbar_addr = ((u64)temp_hi << 32) | temp_lo; |
| 174 | |
| 175 | /* If ACPI doesn't have it, assume we need to allocate it ourselves */ |
| 176 | #ifdef CONFIG_PNP |
| 177 | if (mchbar_addr && |
| 178 | pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) |
| 179 | return 0; |
| 180 | #endif |
| 181 | |
| 182 | /* Get some space for it */ |
| 183 | dev_priv->mch_res.name = "i915 MCHBAR"; |
| 184 | dev_priv->mch_res.flags = IORESOURCE_MEM; |
| 185 | ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, |
| 186 | &dev_priv->mch_res, |
| 187 | MCHBAR_SIZE, MCHBAR_SIZE, |
| 188 | PCIBIOS_MIN_MEM, |
| 189 | 0, pcibios_align_resource, |
| 190 | dev_priv->bridge_dev); |
| 191 | if (ret) { |
| 192 | DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret); |
| 193 | dev_priv->mch_res.start = 0; |
| 194 | return ret; |
| 195 | } |
| 196 | |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 197 | if (INTEL_GEN(dev_priv) >= 4) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 198 | pci_write_config_dword(dev_priv->bridge_dev, reg + 4, |
| 199 | upper_32_bits(dev_priv->mch_res.start)); |
| 200 | |
| 201 | pci_write_config_dword(dev_priv->bridge_dev, reg, |
| 202 | lower_32_bits(dev_priv->mch_res.start)); |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | /* Setup MCHBAR if possible, return true if we should disable it again */ |
| 207 | static void |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 208 | intel_setup_mchbar(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 209 | { |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 210 | int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 211 | u32 temp; |
| 212 | bool enabled; |
| 213 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 214 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 215 | return; |
| 216 | |
| 217 | dev_priv->mchbar_need_disable = false; |
| 218 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 219 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 220 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp); |
| 221 | enabled = !!(temp & DEVEN_MCHBAR_EN); |
| 222 | } else { |
| 223 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 224 | enabled = temp & 1; |
| 225 | } |
| 226 | |
| 227 | /* If it's already enabled, don't have to do anything */ |
| 228 | if (enabled) |
| 229 | return; |
| 230 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 231 | if (intel_alloc_mchbar_resource(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 232 | return; |
| 233 | |
| 234 | dev_priv->mchbar_need_disable = true; |
| 235 | |
| 236 | /* Space is allocated or reserved, so enable it. */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 237 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 238 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN, |
| 239 | temp | DEVEN_MCHBAR_EN); |
| 240 | } else { |
| 241 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 242 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | static void |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 247 | intel_teardown_mchbar(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 248 | { |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 249 | int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 250 | |
| 251 | if (dev_priv->mchbar_need_disable) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 252 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 253 | u32 deven_val; |
| 254 | |
| 255 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN, |
| 256 | &deven_val); |
| 257 | deven_val &= ~DEVEN_MCHBAR_EN; |
| 258 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN, |
| 259 | deven_val); |
| 260 | } else { |
| 261 | u32 mchbar_val; |
| 262 | |
| 263 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, |
| 264 | &mchbar_val); |
| 265 | mchbar_val &= ~1; |
| 266 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, |
| 267 | mchbar_val); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (dev_priv->mch_res.start) |
| 272 | release_resource(&dev_priv->mch_res); |
| 273 | } |
| 274 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 275 | static int i915_driver_modeset_probe(struct drm_i915_private *i915) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 276 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 277 | int ret; |
| 278 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 279 | if (i915_inject_probe_failure(i915)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 280 | return -ENODEV; |
| 281 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 282 | if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) { |
| 283 | ret = drm_vblank_init(&i915->drm, |
| 284 | INTEL_NUM_PIPES(i915)); |
José Roberto de Souza | 8d3bf1a | 2018-11-07 16:16:44 -0800 | [diff] [blame] | 285 | if (ret) |
| 286 | goto out; |
| 287 | } |
| 288 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 289 | intel_bios_init(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 290 | |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 291 | ret = intel_vga_register(i915); |
| 292 | if (ret) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 293 | goto out; |
| 294 | |
| 295 | intel_register_dsm_handler(); |
| 296 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 297 | ret = i915_switcheroo_register(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 298 | if (ret) |
| 299 | goto cleanup_vga_client; |
| 300 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 301 | intel_power_domains_init_hw(i915, false); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 302 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 303 | intel_csr_ucode_init(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 304 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 305 | ret = intel_irq_install(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 306 | if (ret) |
| 307 | goto cleanup_csr; |
| 308 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 309 | /* Important: The output setup functions called by modeset_init need |
| 310 | * working irqs for e.g. gmbus and dp aux transfers. */ |
Jani Nikula | 6cd02e7 | 2019-09-20 21:54:21 +0300 | [diff] [blame] | 311 | ret = intel_modeset_init(i915); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 312 | if (ret) |
| 313 | goto cleanup_irq; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 314 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 315 | ret = i915_gem_init(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 316 | if (ret) |
Chris Wilson | 73bad7c | 2018-07-10 10:44:21 +0100 | [diff] [blame] | 317 | goto cleanup_modeset; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 318 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 319 | intel_overlay_setup(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 320 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 321 | if (!HAS_DISPLAY(i915) || !INTEL_DISPLAY_ENABLED(i915)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 322 | return 0; |
| 323 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 324 | ret = intel_fbdev_init(&i915->drm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 325 | if (ret) |
| 326 | goto cleanup_gem; |
| 327 | |
| 328 | /* Only enable hotplug handling once the fbdev is fully set up. */ |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 329 | intel_hpd_init(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 330 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 331 | intel_init_ipc(i915); |
José Roberto de Souza | a8147d0 | 2018-11-07 16:16:46 -0800 | [diff] [blame] | 332 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 333 | return 0; |
| 334 | |
| 335 | cleanup_gem: |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 336 | i915_gem_suspend(i915); |
| 337 | i915_gem_driver_remove(i915); |
| 338 | i915_gem_driver_release(i915); |
Chris Wilson | 73bad7c | 2018-07-10 10:44:21 +0100 | [diff] [blame] | 339 | cleanup_modeset: |
Jani Nikula | 9980c3c | 2019-09-20 21:54:18 +0300 | [diff] [blame] | 340 | intel_modeset_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 341 | cleanup_irq: |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 342 | intel_irq_uninstall(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 343 | cleanup_csr: |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 344 | intel_csr_ucode_fini(i915); |
| 345 | intel_power_domains_driver_remove(i915); |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 346 | i915_switcheroo_unregister(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 347 | cleanup_vga_client: |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 348 | intel_vga_unregister(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 349 | out: |
| 350 | return ret; |
| 351 | } |
| 352 | |
Jani Nikula | 2d6f6f3 | 2019-09-20 21:54:16 +0300 | [diff] [blame] | 353 | static void i915_driver_modeset_remove(struct drm_i915_private *i915) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 354 | { |
Jani Nikula | 9980c3c | 2019-09-20 21:54:18 +0300 | [diff] [blame] | 355 | intel_modeset_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 356 | |
Janusz Krzysztofik | 789fa87 | 2019-10-18 12:07:10 +0200 | [diff] [blame] | 357 | intel_irq_uninstall(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 358 | |
Jani Nikula | 2d6f6f3 | 2019-09-20 21:54:16 +0300 | [diff] [blame] | 359 | intel_bios_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 360 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 361 | i915_switcheroo_unregister(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 362 | |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 363 | intel_vga_unregister(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 364 | |
Jani Nikula | 2d6f6f3 | 2019-09-20 21:54:16 +0300 | [diff] [blame] | 365 | intel_csr_ucode_fini(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 366 | } |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 367 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 368 | static void intel_init_dpio(struct drm_i915_private *dev_priv) |
| 369 | { |
| 370 | /* |
| 371 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 372 | * CHV x1 PHY (DP/HDMI D) |
| 373 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 374 | */ |
| 375 | if (IS_CHERRYVIEW(dev_priv)) { |
| 376 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 377 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 378 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 379 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static int i915_workqueues_init(struct drm_i915_private *dev_priv) |
| 384 | { |
| 385 | /* |
| 386 | * The i915 workqueue is primarily used for batched retirement of |
| 387 | * requests (and thus managing bo) once the task has been completed |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 388 | * by the GPU. i915_retire_requests() is called directly when we |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 389 | * need high-priority retirement, such as waiting for an explicit |
| 390 | * bo. |
| 391 | * |
| 392 | * It is also used for periodic low-priority events, such as |
| 393 | * idle-timers and recording error state. |
| 394 | * |
| 395 | * All tasks on the workqueue are expected to acquire the dev mutex |
| 396 | * so there is no point in running more than one instance of the |
| 397 | * workqueue at any time. Use an ordered one. |
| 398 | */ |
| 399 | dev_priv->wq = alloc_ordered_workqueue("i915", 0); |
| 400 | if (dev_priv->wq == NULL) |
| 401 | goto out_err; |
| 402 | |
| 403 | dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0); |
| 404 | if (dev_priv->hotplug.dp_wq == NULL) |
| 405 | goto out_free_wq; |
| 406 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 407 | return 0; |
| 408 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 409 | out_free_wq: |
| 410 | destroy_workqueue(dev_priv->wq); |
| 411 | out_err: |
| 412 | DRM_ERROR("Failed to allocate workqueues.\n"); |
| 413 | |
| 414 | return -ENOMEM; |
| 415 | } |
| 416 | |
| 417 | static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv) |
| 418 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 419 | destroy_workqueue(dev_priv->hotplug.dp_wq); |
| 420 | destroy_workqueue(dev_priv->wq); |
| 421 | } |
| 422 | |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 423 | /* |
| 424 | * We don't keep the workarounds for pre-production hardware, so we expect our |
| 425 | * driver to fail on these machines in one way or another. A little warning on |
| 426 | * dmesg may help both the user and the bug triagers. |
Chris Wilson | 6a7a6a9 | 2017-11-17 10:26:35 +0000 | [diff] [blame] | 427 | * |
| 428 | * Our policy for removing pre-production workarounds is to keep the |
| 429 | * current gen workarounds as a guide to the bring-up of the next gen |
| 430 | * (workarounds have a habit of persisting!). Anything older than that |
| 431 | * should be removed along with the complications they introduce. |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 432 | */ |
| 433 | static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv) |
| 434 | { |
Chris Wilson | 248a124 | 2017-01-30 10:44:56 +0000 | [diff] [blame] | 435 | bool pre = false; |
| 436 | |
| 437 | pre |= IS_HSW_EARLY_SDV(dev_priv); |
| 438 | pre |= IS_SKL_REVID(dev_priv, 0, SKL_REVID_F0); |
Chris Wilson | 0102ba1 | 2017-01-30 10:44:58 +0000 | [diff] [blame] | 439 | pre |= IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST); |
Chris Wilson | 1aca96c | 2018-11-28 13:53:25 +0000 | [diff] [blame] | 440 | pre |= IS_KBL_REVID(dev_priv, 0, KBL_REVID_A0); |
Chris Wilson | 248a124 | 2017-01-30 10:44:56 +0000 | [diff] [blame] | 441 | |
Chris Wilson | 7c5ff4a | 2017-01-30 10:44:57 +0000 | [diff] [blame] | 442 | if (pre) { |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 443 | DRM_ERROR("This is a pre-production stepping. " |
| 444 | "It may not be fully functional.\n"); |
Chris Wilson | 7c5ff4a | 2017-01-30 10:44:57 +0000 | [diff] [blame] | 445 | add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK); |
| 446 | } |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 447 | } |
| 448 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 449 | static int vlv_alloc_s0ix_state(struct drm_i915_private *i915) |
| 450 | { |
| 451 | if (!IS_VALLEYVIEW(i915)) |
| 452 | return 0; |
| 453 | |
| 454 | /* we write all the values in the struct, so no need to zero it out */ |
| 455 | i915->vlv_s0ix_state = kmalloc(sizeof(*i915->vlv_s0ix_state), |
| 456 | GFP_KERNEL); |
| 457 | if (!i915->vlv_s0ix_state) |
| 458 | return -ENOMEM; |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static void vlv_free_s0ix_state(struct drm_i915_private *i915) |
| 464 | { |
| 465 | if (!i915->vlv_s0ix_state) |
| 466 | return; |
| 467 | |
| 468 | kfree(i915->vlv_s0ix_state); |
| 469 | i915->vlv_s0ix_state = NULL; |
| 470 | } |
| 471 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 472 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 473 | * i915_driver_early_probe - setup state not requiring device access |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 474 | * @dev_priv: device private |
| 475 | * |
| 476 | * Initialize everything that is a "SW-only" state, that is state not |
| 477 | * requiring accessing the device or exposing the driver via kernel internal |
| 478 | * or userspace interfaces. Example steps belonging here: lock initialization, |
| 479 | * system memory allocation, setting up device specific attributes and |
| 480 | * function hooks not requiring accessing the device. |
| 481 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 482 | static int i915_driver_early_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 483 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 484 | int ret = 0; |
| 485 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 486 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 487 | return -ENODEV; |
| 488 | |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 489 | intel_device_info_subplatform_init(dev_priv); |
| 490 | |
Daniele Ceraolo Spurio | 0a9b263 | 2019-08-09 07:31:16 +0100 | [diff] [blame] | 491 | intel_uncore_mmio_debug_init_early(&dev_priv->mmio_debug); |
Daniele Ceraolo Spurio | 0138575 | 2019-06-19 18:00:18 -0700 | [diff] [blame] | 492 | intel_uncore_init_early(&dev_priv->uncore, dev_priv); |
Daniele Ceraolo Spurio | 6cbe8830 | 2019-04-02 13:10:31 -0700 | [diff] [blame] | 493 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 494 | spin_lock_init(&dev_priv->irq_lock); |
| 495 | spin_lock_init(&dev_priv->gpu_error.lock); |
| 496 | mutex_init(&dev_priv->backlight_lock); |
Lyude | 317eaa9 | 2017-02-03 21:18:25 -0500 | [diff] [blame] | 497 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 498 | mutex_init(&dev_priv->sb_lock); |
Chris Wilson | a75d035 | 2019-04-26 09:17:18 +0100 | [diff] [blame] | 499 | pm_qos_add_request(&dev_priv->sb_qos, |
| 500 | PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
| 501 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 502 | mutex_init(&dev_priv->av_mutex); |
| 503 | mutex_init(&dev_priv->wm.wm_mutex); |
| 504 | mutex_init(&dev_priv->pps_mutex); |
Ramalingam C | 9055aac | 2019-02-16 23:06:51 +0530 | [diff] [blame] | 505 | mutex_init(&dev_priv->hdcp_comp_mutex); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 506 | |
Chris Wilson | 0b1de5d | 2016-08-12 12:39:59 +0100 | [diff] [blame] | 507 | i915_memcpy_init_early(dev_priv); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 508 | intel_runtime_pm_init_early(&dev_priv->runtime_pm); |
Chris Wilson | 0b1de5d | 2016-08-12 12:39:59 +0100 | [diff] [blame] | 509 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 510 | ret = i915_workqueues_init(dev_priv); |
| 511 | if (ret < 0) |
Chris Wilson | f3bcb0c | 2019-07-18 08:00:10 +0100 | [diff] [blame] | 512 | return ret; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 513 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 514 | ret = vlv_alloc_s0ix_state(dev_priv); |
| 515 | if (ret < 0) |
| 516 | goto err_workqueues; |
| 517 | |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 518 | intel_wopcm_init_early(&dev_priv->wopcm); |
| 519 | |
Tvrtko Ursulin | 724e956 | 2019-06-21 08:07:42 +0100 | [diff] [blame] | 520 | intel_gt_init_early(&dev_priv->gt, dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 521 | |
Matthew Auld | a3f356b | 2019-09-27 18:33:49 +0100 | [diff] [blame] | 522 | i915_gem_init_early(dev_priv); |
Michal Wajdeczko | a0de908 | 2018-03-23 12:34:49 +0000 | [diff] [blame] | 523 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 524 | /* This must be called before any calls to HAS_PCH_* */ |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 525 | intel_detect_pch(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 526 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 527 | intel_pm_setup(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 528 | intel_init_dpio(dev_priv); |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 529 | ret = intel_power_domains_init(dev_priv); |
| 530 | if (ret < 0) |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 531 | goto err_gem; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 532 | intel_irq_init(dev_priv); |
| 533 | intel_init_display_hooks(dev_priv); |
| 534 | intel_init_clock_gating_hooks(dev_priv); |
| 535 | intel_init_audio_hooks(dev_priv); |
David Weinehall | 36cdd01 | 2016-08-22 13:59:31 +0300 | [diff] [blame] | 536 | intel_display_crc_init(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 537 | |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 538 | intel_detect_preproduction_hw(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 539 | |
| 540 | return 0; |
| 541 | |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 542 | err_gem: |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 543 | i915_gem_cleanup_early(dev_priv); |
Daniele Ceraolo Spurio | 6cf72db | 2019-07-31 17:57:07 -0700 | [diff] [blame] | 544 | intel_gt_driver_late_release(&dev_priv->gt); |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 545 | vlv_free_s0ix_state(dev_priv); |
Michal Wajdeczko | a0de908 | 2018-03-23 12:34:49 +0000 | [diff] [blame] | 546 | err_workqueues: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 547 | i915_workqueues_cleanup(dev_priv); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | /** |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 552 | * i915_driver_late_release - cleanup the setup done in |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 553 | * i915_driver_early_probe() |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 554 | * @dev_priv: device private |
| 555 | */ |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 556 | static void i915_driver_late_release(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 557 | { |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame] | 558 | intel_irq_fini(dev_priv); |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 559 | intel_power_domains_cleanup(dev_priv); |
Michal Wajdeczko | a0de908 | 2018-03-23 12:34:49 +0000 | [diff] [blame] | 560 | i915_gem_cleanup_early(dev_priv); |
Daniele Ceraolo Spurio | 6cf72db | 2019-07-31 17:57:07 -0700 | [diff] [blame] | 561 | intel_gt_driver_late_release(&dev_priv->gt); |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 562 | vlv_free_s0ix_state(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 563 | i915_workqueues_cleanup(dev_priv); |
Chris Wilson | a75d035 | 2019-04-26 09:17:18 +0100 | [diff] [blame] | 564 | |
| 565 | pm_qos_remove_request(&dev_priv->sb_qos); |
| 566 | mutex_destroy(&dev_priv->sb_lock); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 569 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 570 | * i915_driver_mmio_probe - setup device MMIO |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 571 | * @dev_priv: device private |
| 572 | * |
| 573 | * Setup minimal device state necessary for MMIO accesses later in the |
| 574 | * initialization sequence. The setup here should avoid any other device-wide |
| 575 | * side effects or exposing the driver via kernel internal or user space |
| 576 | * interfaces. |
| 577 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 578 | static int i915_driver_mmio_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 579 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 580 | int ret; |
| 581 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 582 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 583 | return -ENODEV; |
| 584 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 585 | if (i915_get_bridge_dev(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 586 | return -EIO; |
| 587 | |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 588 | ret = intel_uncore_init_mmio(&dev_priv->uncore); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 589 | if (ret < 0) |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 590 | goto err_bridge; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 591 | |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 592 | /* Try to make sure MCHBAR is enabled before poking at it */ |
| 593 | intel_setup_mchbar(dev_priv); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 594 | |
Oscar Mateo | 26376a7 | 2018-03-16 14:14:49 +0200 | [diff] [blame] | 595 | intel_device_info_init_mmio(dev_priv); |
| 596 | |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 597 | intel_uncore_prune_mmio_domains(&dev_priv->uncore); |
Oscar Mateo | 26376a7 | 2018-03-16 14:14:49 +0200 | [diff] [blame] | 598 | |
Daniele Ceraolo Spurio | ca7b2c1 | 2019-07-13 11:00:13 +0100 | [diff] [blame] | 599 | intel_uc_init_mmio(&dev_priv->gt.uc); |
Sagar Arun Kamble | 1fc556f | 2017-10-04 15:33:24 +0000 | [diff] [blame] | 600 | |
Tvrtko Ursulin | adcb526 | 2019-10-22 10:47:15 +0100 | [diff] [blame] | 601 | ret = intel_engines_init_mmio(&dev_priv->gt); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 602 | if (ret) |
| 603 | goto err_uncore; |
| 604 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 605 | return 0; |
| 606 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 607 | err_uncore: |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 608 | intel_teardown_mchbar(dev_priv); |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 609 | intel_uncore_fini_mmio(&dev_priv->uncore); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 610 | err_bridge: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 611 | pci_dev_put(dev_priv->bridge_dev); |
| 612 | |
| 613 | return ret; |
| 614 | } |
| 615 | |
| 616 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 617 | * i915_driver_mmio_release - cleanup the setup done in i915_driver_mmio_probe() |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 618 | * @dev_priv: device private |
| 619 | */ |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 620 | static void i915_driver_mmio_release(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 621 | { |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 622 | intel_teardown_mchbar(dev_priv); |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 623 | intel_uncore_fini_mmio(&dev_priv->uncore); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 624 | pci_dev_put(dev_priv->bridge_dev); |
| 625 | } |
| 626 | |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 627 | static void intel_sanitize_options(struct drm_i915_private *dev_priv) |
| 628 | { |
Chuanxiao Dong | 67b7f33 | 2017-05-27 17:44:17 +0800 | [diff] [blame] | 629 | intel_gvt_sanitize_options(dev_priv); |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 632 | #define DRAM_TYPE_STR(type) [INTEL_DRAM_ ## type] = #type |
| 633 | |
| 634 | static const char *intel_dram_type_str(enum intel_dram_type type) |
| 635 | { |
| 636 | static const char * const str[] = { |
| 637 | DRAM_TYPE_STR(UNKNOWN), |
| 638 | DRAM_TYPE_STR(DDR3), |
| 639 | DRAM_TYPE_STR(DDR4), |
| 640 | DRAM_TYPE_STR(LPDDR3), |
| 641 | DRAM_TYPE_STR(LPDDR4), |
| 642 | }; |
| 643 | |
| 644 | if (type >= ARRAY_SIZE(str)) |
| 645 | type = INTEL_DRAM_UNKNOWN; |
| 646 | |
| 647 | return str[type]; |
| 648 | } |
| 649 | |
| 650 | #undef DRAM_TYPE_STR |
| 651 | |
Ville Syrjälä | 54561b2 | 2019-03-06 22:35:42 +0200 | [diff] [blame] | 652 | static int intel_dimm_num_devices(const struct dram_dimm_info *dimm) |
| 653 | { |
| 654 | return dimm->ranks * 64 / (dimm->width ?: 1); |
| 655 | } |
| 656 | |
Ville Syrjälä | ea411e6 | 2019-03-06 22:35:41 +0200 | [diff] [blame] | 657 | /* Returns total GB for the whole DIMM */ |
| 658 | static int skl_get_dimm_size(u16 val) |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 659 | { |
Ville Syrjälä | ea411e6 | 2019-03-06 22:35:41 +0200 | [diff] [blame] | 660 | return val & SKL_DRAM_SIZE_MASK; |
| 661 | } |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 662 | |
Ville Syrjälä | ea411e6 | 2019-03-06 22:35:41 +0200 | [diff] [blame] | 663 | static int skl_get_dimm_width(u16 val) |
| 664 | { |
| 665 | if (skl_get_dimm_size(val) == 0) |
| 666 | return 0; |
| 667 | |
| 668 | switch (val & SKL_DRAM_WIDTH_MASK) { |
| 669 | case SKL_DRAM_WIDTH_X8: |
| 670 | case SKL_DRAM_WIDTH_X16: |
| 671 | case SKL_DRAM_WIDTH_X32: |
| 672 | val = (val & SKL_DRAM_WIDTH_MASK) >> SKL_DRAM_WIDTH_SHIFT; |
| 673 | return 8 << val; |
| 674 | default: |
| 675 | MISSING_CASE(val); |
| 676 | return 0; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | static int skl_get_dimm_ranks(u16 val) |
| 681 | { |
| 682 | if (skl_get_dimm_size(val) == 0) |
| 683 | return 0; |
| 684 | |
| 685 | val = (val & SKL_DRAM_RANK_MASK) >> SKL_DRAM_RANK_SHIFT; |
| 686 | |
| 687 | return val + 1; |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 688 | } |
| 689 | |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 690 | /* Returns total GB for the whole DIMM */ |
| 691 | static int cnl_get_dimm_size(u16 val) |
| 692 | { |
| 693 | return (val & CNL_DRAM_SIZE_MASK) / 2; |
| 694 | } |
| 695 | |
| 696 | static int cnl_get_dimm_width(u16 val) |
| 697 | { |
| 698 | if (cnl_get_dimm_size(val) == 0) |
| 699 | return 0; |
| 700 | |
| 701 | switch (val & CNL_DRAM_WIDTH_MASK) { |
| 702 | case CNL_DRAM_WIDTH_X8: |
| 703 | case CNL_DRAM_WIDTH_X16: |
| 704 | case CNL_DRAM_WIDTH_X32: |
| 705 | val = (val & CNL_DRAM_WIDTH_MASK) >> CNL_DRAM_WIDTH_SHIFT; |
| 706 | return 8 << val; |
| 707 | default: |
| 708 | MISSING_CASE(val); |
| 709 | return 0; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | static int cnl_get_dimm_ranks(u16 val) |
| 714 | { |
| 715 | if (cnl_get_dimm_size(val) == 0) |
| 716 | return 0; |
| 717 | |
| 718 | val = (val & CNL_DRAM_RANK_MASK) >> CNL_DRAM_RANK_SHIFT; |
| 719 | |
| 720 | return val + 1; |
| 721 | } |
| 722 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 723 | static bool |
Ville Syrjälä | 54561b2 | 2019-03-06 22:35:42 +0200 | [diff] [blame] | 724 | skl_is_16gb_dimm(const struct dram_dimm_info *dimm) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 725 | { |
Ville Syrjälä | 54561b2 | 2019-03-06 22:35:42 +0200 | [diff] [blame] | 726 | /* Convert total GB to Gb per DRAM device */ |
| 727 | return 8 * dimm->size / (intel_dimm_num_devices(dimm) ?: 1) == 16; |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 728 | } |
| 729 | |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 730 | static void |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 731 | skl_dram_get_dimm_info(struct drm_i915_private *dev_priv, |
| 732 | struct dram_dimm_info *dimm, |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 733 | int channel, char dimm_name, u16 val) |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 734 | { |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 735 | if (INTEL_GEN(dev_priv) >= 10) { |
| 736 | dimm->size = cnl_get_dimm_size(val); |
| 737 | dimm->width = cnl_get_dimm_width(val); |
| 738 | dimm->ranks = cnl_get_dimm_ranks(val); |
| 739 | } else { |
| 740 | dimm->size = skl_get_dimm_size(val); |
| 741 | dimm->width = skl_get_dimm_width(val); |
| 742 | dimm->ranks = skl_get_dimm_ranks(val); |
| 743 | } |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 744 | |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 745 | DRM_DEBUG_KMS("CH%u DIMM %c size: %u GB, width: X%u, ranks: %u, 16Gb DIMMs: %s\n", |
| 746 | channel, dimm_name, dimm->size, dimm->width, dimm->ranks, |
| 747 | yesno(skl_is_16gb_dimm(dimm))); |
| 748 | } |
Ville Syrjälä | ea411e6 | 2019-03-06 22:35:41 +0200 | [diff] [blame] | 749 | |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 750 | static int |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 751 | skl_dram_get_channel_info(struct drm_i915_private *dev_priv, |
| 752 | struct dram_channel_info *ch, |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 753 | int channel, u32 val) |
| 754 | { |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 755 | skl_dram_get_dimm_info(dev_priv, &ch->dimm_l, |
| 756 | channel, 'L', val & 0xffff); |
| 757 | skl_dram_get_dimm_info(dev_priv, &ch->dimm_s, |
| 758 | channel, 'S', val >> 16); |
Ville Syrjälä | ea411e6 | 2019-03-06 22:35:41 +0200 | [diff] [blame] | 759 | |
Ville Syrjälä | 1d55967 | 2019-03-06 22:35:48 +0200 | [diff] [blame] | 760 | if (ch->dimm_l.size == 0 && ch->dimm_s.size == 0) { |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 761 | DRM_DEBUG_KMS("CH%u not populated\n", channel); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 762 | return -EINVAL; |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 763 | } |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 764 | |
Ville Syrjälä | 1d55967 | 2019-03-06 22:35:48 +0200 | [diff] [blame] | 765 | if (ch->dimm_l.ranks == 2 || ch->dimm_s.ranks == 2) |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 766 | ch->ranks = 2; |
Ville Syrjälä | 1d55967 | 2019-03-06 22:35:48 +0200 | [diff] [blame] | 767 | else if (ch->dimm_l.ranks == 1 && ch->dimm_s.ranks == 1) |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 768 | ch->ranks = 2; |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 769 | else |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 770 | ch->ranks = 1; |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 771 | |
Ville Syrjälä | 54561b2 | 2019-03-06 22:35:42 +0200 | [diff] [blame] | 772 | ch->is_16gb_dimm = |
Ville Syrjälä | 1d55967 | 2019-03-06 22:35:48 +0200 | [diff] [blame] | 773 | skl_is_16gb_dimm(&ch->dimm_l) || |
| 774 | skl_is_16gb_dimm(&ch->dimm_s); |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 775 | |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 776 | DRM_DEBUG_KMS("CH%u ranks: %u, 16Gb DIMMs: %s\n", |
| 777 | channel, ch->ranks, yesno(ch->is_16gb_dimm)); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
Mahesh Kumar | 8a6c544 | 2018-08-24 15:02:25 +0530 | [diff] [blame] | 782 | static bool |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 783 | intel_is_dram_symmetric(const struct dram_channel_info *ch0, |
| 784 | const struct dram_channel_info *ch1) |
Mahesh Kumar | 8a6c544 | 2018-08-24 15:02:25 +0530 | [diff] [blame] | 785 | { |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 786 | return !memcmp(ch0, ch1, sizeof(*ch0)) && |
Ville Syrjälä | 1d55967 | 2019-03-06 22:35:48 +0200 | [diff] [blame] | 787 | (ch0->dimm_s.size == 0 || |
| 788 | !memcmp(&ch0->dimm_l, &ch0->dimm_s, sizeof(ch0->dimm_l))); |
Mahesh Kumar | 8a6c544 | 2018-08-24 15:02:25 +0530 | [diff] [blame] | 789 | } |
| 790 | |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 791 | static int |
| 792 | skl_dram_get_channels_info(struct drm_i915_private *dev_priv) |
| 793 | { |
| 794 | struct dram_info *dram_info = &dev_priv->dram_info; |
Ville Syrjälä | 198b8dd | 2019-03-06 22:35:46 +0200 | [diff] [blame] | 795 | struct dram_channel_info ch0 = {}, ch1 = {}; |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 796 | u32 val; |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 797 | int ret; |
| 798 | |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 799 | val = I915_READ(SKL_MAD_DIMM_CH0_0_0_0_MCHBAR_MCMAIN); |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 800 | ret = skl_dram_get_channel_info(dev_priv, &ch0, 0, val); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 801 | if (ret == 0) |
| 802 | dram_info->num_channels++; |
| 803 | |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 804 | val = I915_READ(SKL_MAD_DIMM_CH1_0_0_0_MCHBAR_MCMAIN); |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 805 | ret = skl_dram_get_channel_info(dev_priv, &ch1, 1, val); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 806 | if (ret == 0) |
| 807 | dram_info->num_channels++; |
| 808 | |
| 809 | if (dram_info->num_channels == 0) { |
| 810 | DRM_INFO("Number of memory channels is zero\n"); |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | * If any of the channel is single rank channel, worst case output |
| 816 | * will be same as if single rank memory, so consider single rank |
| 817 | * memory. |
| 818 | */ |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 819 | if (ch0.ranks == 1 || ch1.ranks == 1) |
| 820 | dram_info->ranks = 1; |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 821 | else |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 822 | dram_info->ranks = max(ch0.ranks, ch1.ranks); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 823 | |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 824 | if (dram_info->ranks == 0) { |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 825 | DRM_INFO("couldn't get memory rank information\n"); |
| 826 | return -EINVAL; |
| 827 | } |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 828 | |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 829 | dram_info->is_16gb_dimm = ch0.is_16gb_dimm || ch1.is_16gb_dimm; |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 830 | |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 831 | dram_info->symmetric_memory = intel_is_dram_symmetric(&ch0, &ch1); |
Mahesh Kumar | 8a6c544 | 2018-08-24 15:02:25 +0530 | [diff] [blame] | 832 | |
Ville Syrjälä | d75434b | 2019-03-06 22:35:47 +0200 | [diff] [blame] | 833 | DRM_DEBUG_KMS("Memory configuration is symmetric? %s\n", |
| 834 | yesno(dram_info->symmetric_memory)); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 835 | return 0; |
| 836 | } |
| 837 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 838 | static enum intel_dram_type |
| 839 | skl_get_dram_type(struct drm_i915_private *dev_priv) |
| 840 | { |
| 841 | u32 val; |
| 842 | |
| 843 | val = I915_READ(SKL_MAD_INTER_CHANNEL_0_0_0_MCHBAR_MCMAIN); |
| 844 | |
| 845 | switch (val & SKL_DRAM_DDR_TYPE_MASK) { |
| 846 | case SKL_DRAM_DDR_TYPE_DDR3: |
| 847 | return INTEL_DRAM_DDR3; |
| 848 | case SKL_DRAM_DDR_TYPE_DDR4: |
| 849 | return INTEL_DRAM_DDR4; |
| 850 | case SKL_DRAM_DDR_TYPE_LPDDR3: |
| 851 | return INTEL_DRAM_LPDDR3; |
| 852 | case SKL_DRAM_DDR_TYPE_LPDDR4: |
| 853 | return INTEL_DRAM_LPDDR4; |
| 854 | default: |
| 855 | MISSING_CASE(val); |
| 856 | return INTEL_DRAM_UNKNOWN; |
| 857 | } |
| 858 | } |
| 859 | |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 860 | static int |
| 861 | skl_get_dram_info(struct drm_i915_private *dev_priv) |
| 862 | { |
| 863 | struct dram_info *dram_info = &dev_priv->dram_info; |
| 864 | u32 mem_freq_khz, val; |
| 865 | int ret; |
| 866 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 867 | dram_info->type = skl_get_dram_type(dev_priv); |
| 868 | DRM_DEBUG_KMS("DRAM type: %s\n", intel_dram_type_str(dram_info->type)); |
| 869 | |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 870 | ret = skl_dram_get_channels_info(dev_priv); |
| 871 | if (ret) |
| 872 | return ret; |
| 873 | |
| 874 | val = I915_READ(SKL_MC_BIOS_DATA_0_0_0_MCHBAR_PCU); |
| 875 | mem_freq_khz = DIV_ROUND_UP((val & SKL_REQ_DATA_MASK) * |
| 876 | SKL_MEMORY_FREQ_MULTIPLIER_HZ, 1000); |
| 877 | |
| 878 | dram_info->bandwidth_kbps = dram_info->num_channels * |
| 879 | mem_freq_khz * 8; |
| 880 | |
| 881 | if (dram_info->bandwidth_kbps == 0) { |
| 882 | DRM_INFO("Couldn't get system memory bandwidth\n"); |
| 883 | return -EINVAL; |
| 884 | } |
| 885 | |
| 886 | dram_info->valid = true; |
| 887 | return 0; |
| 888 | } |
| 889 | |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 890 | /* Returns Gb per DRAM device */ |
| 891 | static int bxt_get_dimm_size(u32 val) |
| 892 | { |
| 893 | switch (val & BXT_DRAM_SIZE_MASK) { |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 894 | case BXT_DRAM_SIZE_4GBIT: |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 895 | return 4; |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 896 | case BXT_DRAM_SIZE_6GBIT: |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 897 | return 6; |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 898 | case BXT_DRAM_SIZE_8GBIT: |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 899 | return 8; |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 900 | case BXT_DRAM_SIZE_12GBIT: |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 901 | return 12; |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 902 | case BXT_DRAM_SIZE_16GBIT: |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 903 | return 16; |
| 904 | default: |
| 905 | MISSING_CASE(val); |
| 906 | return 0; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | static int bxt_get_dimm_width(u32 val) |
| 911 | { |
| 912 | if (!bxt_get_dimm_size(val)) |
| 913 | return 0; |
| 914 | |
| 915 | val = (val & BXT_DRAM_WIDTH_MASK) >> BXT_DRAM_WIDTH_SHIFT; |
| 916 | |
| 917 | return 8 << val; |
| 918 | } |
| 919 | |
| 920 | static int bxt_get_dimm_ranks(u32 val) |
| 921 | { |
| 922 | if (!bxt_get_dimm_size(val)) |
| 923 | return 0; |
| 924 | |
| 925 | switch (val & BXT_DRAM_RANK_MASK) { |
| 926 | case BXT_DRAM_RANK_SINGLE: |
| 927 | return 1; |
| 928 | case BXT_DRAM_RANK_DUAL: |
| 929 | return 2; |
| 930 | default: |
| 931 | MISSING_CASE(val); |
| 932 | return 0; |
| 933 | } |
| 934 | } |
| 935 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 936 | static enum intel_dram_type bxt_get_dimm_type(u32 val) |
| 937 | { |
| 938 | if (!bxt_get_dimm_size(val)) |
| 939 | return INTEL_DRAM_UNKNOWN; |
| 940 | |
| 941 | switch (val & BXT_DRAM_TYPE_MASK) { |
| 942 | case BXT_DRAM_TYPE_DDR3: |
| 943 | return INTEL_DRAM_DDR3; |
| 944 | case BXT_DRAM_TYPE_LPDDR3: |
| 945 | return INTEL_DRAM_LPDDR3; |
| 946 | case BXT_DRAM_TYPE_DDR4: |
| 947 | return INTEL_DRAM_DDR4; |
| 948 | case BXT_DRAM_TYPE_LPDDR4: |
| 949 | return INTEL_DRAM_LPDDR4; |
| 950 | default: |
| 951 | MISSING_CASE(val); |
| 952 | return INTEL_DRAM_UNKNOWN; |
| 953 | } |
| 954 | } |
| 955 | |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 956 | static void bxt_get_dimm_info(struct dram_dimm_info *dimm, |
| 957 | u32 val) |
| 958 | { |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 959 | dimm->width = bxt_get_dimm_width(val); |
| 960 | dimm->ranks = bxt_get_dimm_ranks(val); |
Ville Syrjälä | 8860343 | 2019-03-06 22:35:44 +0200 | [diff] [blame] | 961 | |
| 962 | /* |
| 963 | * Size in register is Gb per DRAM device. Convert to total |
| 964 | * GB to match the way we report this for non-LP platforms. |
| 965 | */ |
| 966 | dimm->size = bxt_get_dimm_size(val) * intel_dimm_num_devices(dimm) / 8; |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 967 | } |
| 968 | |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 969 | static int |
| 970 | bxt_get_dram_info(struct drm_i915_private *dev_priv) |
| 971 | { |
| 972 | struct dram_info *dram_info = &dev_priv->dram_info; |
| 973 | u32 dram_channels; |
| 974 | u32 mem_freq_khz, val; |
| 975 | u8 num_active_channels; |
| 976 | int i; |
| 977 | |
| 978 | val = I915_READ(BXT_P_CR_MC_BIOS_REQ_0_0_0); |
| 979 | mem_freq_khz = DIV_ROUND_UP((val & BXT_REQ_DATA_MASK) * |
| 980 | BXT_MEMORY_FREQ_MULTIPLIER_HZ, 1000); |
| 981 | |
| 982 | dram_channels = val & BXT_DRAM_CHANNEL_ACTIVE_MASK; |
| 983 | num_active_channels = hweight32(dram_channels); |
| 984 | |
| 985 | /* Each active bit represents 4-byte channel */ |
| 986 | dram_info->bandwidth_kbps = (mem_freq_khz * num_active_channels * 4); |
| 987 | |
| 988 | if (dram_info->bandwidth_kbps == 0) { |
| 989 | DRM_INFO("Couldn't get system memory bandwidth\n"); |
| 990 | return -EINVAL; |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | * Now read each DUNIT8/9/10/11 to check the rank of each dimms. |
| 995 | */ |
| 996 | for (i = BXT_D_CR_DRP0_DUNIT_START; i <= BXT_D_CR_DRP0_DUNIT_END; i++) { |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 997 | struct dram_dimm_info dimm; |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 998 | enum intel_dram_type type; |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 999 | |
| 1000 | val = I915_READ(BXT_D_CR_DRP0_DUNIT(i)); |
| 1001 | if (val == 0xFFFFFFFF) |
| 1002 | continue; |
| 1003 | |
| 1004 | dram_info->num_channels++; |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1005 | |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 1006 | bxt_get_dimm_info(&dimm, val); |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 1007 | type = bxt_get_dimm_type(val); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1008 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 1009 | WARN_ON(type != INTEL_DRAM_UNKNOWN && |
| 1010 | dram_info->type != INTEL_DRAM_UNKNOWN && |
| 1011 | dram_info->type != type); |
| 1012 | |
| 1013 | DRM_DEBUG_KMS("CH%u DIMM size: %u GB, width: X%u, ranks: %u, type: %s\n", |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 1014 | i - BXT_D_CR_DRP0_DUNIT_START, |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 1015 | dimm.size, dimm.width, dimm.ranks, |
| 1016 | intel_dram_type_str(type)); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1017 | |
| 1018 | /* |
| 1019 | * If any of the channel is single rank channel, |
| 1020 | * worst case output will be same as if single rank |
| 1021 | * memory, so consider single rank memory. |
| 1022 | */ |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 1023 | if (dram_info->ranks == 0) |
Ville Syrjälä | a62819a | 2019-03-06 22:35:43 +0200 | [diff] [blame] | 1024 | dram_info->ranks = dimm.ranks; |
| 1025 | else if (dimm.ranks == 1) |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 1026 | dram_info->ranks = 1; |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 1027 | |
| 1028 | if (type != INTEL_DRAM_UNKNOWN) |
| 1029 | dram_info->type = type; |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1030 | } |
| 1031 | |
Ville Syrjälä | b185a35 | 2019-03-06 22:35:51 +0200 | [diff] [blame] | 1032 | if (dram_info->type == INTEL_DRAM_UNKNOWN || |
| 1033 | dram_info->ranks == 0) { |
| 1034 | DRM_INFO("couldn't get memory information\n"); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1035 | return -EINVAL; |
| 1036 | } |
| 1037 | |
| 1038 | dram_info->valid = true; |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | static void |
| 1043 | intel_get_dram_info(struct drm_i915_private *dev_priv) |
| 1044 | { |
| 1045 | struct dram_info *dram_info = &dev_priv->dram_info; |
| 1046 | int ret; |
| 1047 | |
Ville Syrjälä | 5d6f36b | 2018-10-23 21:21:02 +0300 | [diff] [blame] | 1048 | /* |
| 1049 | * Assume 16Gb DIMMs are present until proven otherwise. |
| 1050 | * This is only used for the level 0 watermark latency |
| 1051 | * w/a which does not apply to bxt/glk. |
| 1052 | */ |
| 1053 | dram_info->is_16gb_dimm = !IS_GEN9_LP(dev_priv); |
| 1054 | |
Stuart Summers | e7862f4 | 2019-11-19 16:45:05 -0800 | [diff] [blame] | 1055 | if (INTEL_GEN(dev_priv) < 9 || !HAS_DISPLAY(dev_priv)) |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1056 | return; |
| 1057 | |
Ville Syrjälä | 331ecde | 2019-03-06 22:35:45 +0200 | [diff] [blame] | 1058 | if (IS_GEN9_LP(dev_priv)) |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 1059 | ret = bxt_get_dram_info(dev_priv); |
Mahesh Kumar | 5771caf | 2018-08-24 15:02:22 +0530 | [diff] [blame] | 1060 | else |
Ville Syrjälä | 6d9c1e9 | 2019-03-06 22:35:50 +0200 | [diff] [blame] | 1061 | ret = skl_get_dram_info(dev_priv); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1062 | if (ret) |
| 1063 | return; |
| 1064 | |
Ville Syrjälä | 30a533e | 2019-03-06 22:35:49 +0200 | [diff] [blame] | 1065 | DRM_DEBUG_KMS("DRAM bandwidth: %u kBps, channels: %u\n", |
| 1066 | dram_info->bandwidth_kbps, |
| 1067 | dram_info->num_channels); |
| 1068 | |
Ville Syrjälä | 54561b2 | 2019-03-06 22:35:42 +0200 | [diff] [blame] | 1069 | DRM_DEBUG_KMS("DRAM ranks: %u, 16Gb DIMMs: %s\n", |
Ville Syrjälä | 80373fb | 2019-03-06 22:35:40 +0200 | [diff] [blame] | 1070 | dram_info->ranks, yesno(dram_info->is_16gb_dimm)); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1071 | } |
| 1072 | |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 1073 | static u32 gen9_edram_size_mb(struct drm_i915_private *dev_priv, u32 cap) |
| 1074 | { |
Ville Syrjälä | 2edb3de | 2019-10-10 17:51:23 +0300 | [diff] [blame] | 1075 | static const u8 ways[8] = { 4, 8, 12, 16, 16, 16, 16, 16 }; |
| 1076 | static const u8 sets[4] = { 1, 1, 2, 2 }; |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 1077 | |
| 1078 | return EDRAM_NUM_BANKS(cap) * |
| 1079 | ways[EDRAM_WAYS_IDX(cap)] * |
| 1080 | sets[EDRAM_SETS_IDX(cap)]; |
| 1081 | } |
| 1082 | |
| 1083 | static void edram_detect(struct drm_i915_private *dev_priv) |
| 1084 | { |
| 1085 | u32 edram_cap = 0; |
| 1086 | |
| 1087 | if (!(IS_HASWELL(dev_priv) || |
| 1088 | IS_BROADWELL(dev_priv) || |
| 1089 | INTEL_GEN(dev_priv) >= 9)) |
| 1090 | return; |
| 1091 | |
| 1092 | edram_cap = __raw_uncore_read32(&dev_priv->uncore, HSW_EDRAM_CAP); |
| 1093 | |
| 1094 | /* NB: We can't write IDICR yet because we don't have gt funcs set up */ |
| 1095 | |
| 1096 | if (!(edram_cap & EDRAM_ENABLED)) |
| 1097 | return; |
| 1098 | |
| 1099 | /* |
| 1100 | * The needed capability bits for size calculation are not there with |
| 1101 | * pre gen9 so return 128MB always. |
| 1102 | */ |
| 1103 | if (INTEL_GEN(dev_priv) < 9) |
| 1104 | dev_priv->edram_size_mb = 128; |
| 1105 | else |
| 1106 | dev_priv->edram_size_mb = |
| 1107 | gen9_edram_size_mb(dev_priv, edram_cap); |
| 1108 | |
Chris Wilson | 88f8065 | 2019-08-15 10:36:04 +0100 | [diff] [blame] | 1109 | dev_info(dev_priv->drm.dev, |
| 1110 | "Found %uMB of eDRAM\n", dev_priv->edram_size_mb); |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1113 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 1114 | * i915_driver_hw_probe - setup state requiring device access |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1115 | * @dev_priv: device private |
| 1116 | * |
| 1117 | * Setup state that requires accessing the device, but doesn't require |
| 1118 | * exposing the driver via kernel internal or userspace interfaces. |
| 1119 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 1120 | static int i915_driver_hw_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1121 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1122 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1123 | int ret; |
| 1124 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 1125 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1126 | return -ENODEV; |
| 1127 | |
Jani Nikula | 1400cc7 | 2018-12-31 16:56:43 +0200 | [diff] [blame] | 1128 | intel_device_info_runtime_init(dev_priv); |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 1129 | |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 1130 | if (HAS_PPGTT(dev_priv)) { |
| 1131 | if (intel_vgpu_active(dev_priv) && |
Chris Wilson | ca6ac68 | 2019-03-14 22:38:35 +0000 | [diff] [blame] | 1132 | !intel_vgpu_has_full_ppgtt(dev_priv)) { |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 1133 | i915_report_error(dev_priv, |
| 1134 | "incompatible vGPU found, support for isolated ppGTT required\n"); |
| 1135 | return -ENXIO; |
| 1136 | } |
| 1137 | } |
| 1138 | |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 1139 | if (HAS_EXECLISTS(dev_priv)) { |
| 1140 | /* |
| 1141 | * Older GVT emulation depends upon intercepting CSB mmio, |
| 1142 | * which we no longer use, preferring to use the HWSP cache |
| 1143 | * instead. |
| 1144 | */ |
| 1145 | if (intel_vgpu_active(dev_priv) && |
| 1146 | !intel_vgpu_has_hwsp_emulation(dev_priv)) { |
| 1147 | i915_report_error(dev_priv, |
| 1148 | "old vGPU host found, support for HWSP emulation required\n"); |
| 1149 | return -ENXIO; |
| 1150 | } |
| 1151 | } |
| 1152 | |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 1153 | intel_sanitize_options(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1154 | |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 1155 | /* needs to be done before ggtt probe */ |
| 1156 | edram_detect(dev_priv); |
| 1157 | |
Lionel Landwerlin | 9f9b279 | 2017-10-27 15:59:31 +0100 | [diff] [blame] | 1158 | i915_perf_init(dev_priv); |
| 1159 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 1160 | ret = i915_ggtt_probe_hw(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1161 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 1162 | goto err_perf; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1163 | |
Gerd Hoffmann | f2521f7 | 2019-08-22 11:06:45 +0200 | [diff] [blame] | 1164 | ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "inteldrmfb"); |
| 1165 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 1166 | goto err_ggtt; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1167 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 1168 | ret = i915_ggtt_init_hw(dev_priv); |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 1169 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 1170 | goto err_ggtt; |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 1171 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1172 | ret = intel_memory_regions_hw_probe(dev_priv); |
| 1173 | if (ret) |
| 1174 | goto err_ggtt; |
| 1175 | |
Chris Wilson | fd6fe08 | 2019-11-01 14:10:06 +0000 | [diff] [blame] | 1176 | intel_gt_init_hw_early(&dev_priv->gt, &dev_priv->ggtt); |
Tvrtko Ursulin | d8a4424 | 2019-06-21 08:08:06 +0100 | [diff] [blame] | 1177 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 1178 | ret = i915_ggtt_enable_hw(dev_priv); |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 1179 | if (ret) { |
| 1180 | DRM_ERROR("failed to enable GGTT\n"); |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1181 | goto err_mem_regions; |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 1182 | } |
| 1183 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1184 | pci_set_master(pdev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1185 | |
Lyude Paul | 32f0a98 | 2019-08-23 16:52:51 -0400 | [diff] [blame] | 1186 | /* |
| 1187 | * We don't have a max segment size, so set it to the max so sg's |
| 1188 | * debugging layer doesn't complain |
| 1189 | */ |
| 1190 | dma_set_max_seg_size(&pdev->dev, UINT_MAX); |
| 1191 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1192 | /* overlay on gen2 is broken and can't address above 1G */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1193 | if (IS_GEN(dev_priv, 2)) { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1194 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(30)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1195 | if (ret) { |
| 1196 | DRM_ERROR("failed to set DMA mask\n"); |
| 1197 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1198 | goto err_mem_regions; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1202 | /* 965GM sometimes incorrectly writes to hardware status page (HWS) |
| 1203 | * using 32bit addressing, overwriting memory if HWS is located |
| 1204 | * above 4GB. |
| 1205 | * |
| 1206 | * The documentation also mentions an issue with undefined |
| 1207 | * behaviour if any general state is accessed within a page above 4GB, |
| 1208 | * which also needs to be handled carefully. |
| 1209 | */ |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 1210 | if (IS_I965G(dev_priv) || IS_I965GM(dev_priv)) { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1211 | ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1212 | |
| 1213 | if (ret) { |
| 1214 | DRM_ERROR("failed to set DMA mask\n"); |
| 1215 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1216 | goto err_mem_regions; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1220 | pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, |
| 1221 | PM_QOS_DEFAULT_VALUE); |
| 1222 | |
Tvrtko Ursulin | 25d140f | 2018-12-03 13:33:19 +0000 | [diff] [blame] | 1223 | intel_gt_init_workarounds(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1224 | |
| 1225 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 1226 | * integrated graphics even though the support isn't actually there |
| 1227 | * according to the published specs. It doesn't appear to function |
| 1228 | * correctly in testing on 945G. |
| 1229 | * This may be a side effect of MSI having been made available for PEG |
| 1230 | * and the registers being closely associated. |
| 1231 | * |
| 1232 | * According to chipset errata, on the 965GM, MSI interrupts may |
Ville Syrjälä | e38c2da | 2017-06-26 23:30:51 +0300 | [diff] [blame] | 1233 | * be lost or delayed, and was defeatured. MSI interrupts seem to |
| 1234 | * get lost on g4x as well, and interrupt delivery seems to stay |
| 1235 | * properly dead afterwards. So we'll just disable them for all |
| 1236 | * pre-gen5 chipsets. |
Lucas De Marchi | 8a29c77 | 2018-05-23 11:04:35 -0700 | [diff] [blame] | 1237 | * |
| 1238 | * dp aux and gmbus irq on gen4 seems to be able to generate legacy |
| 1239 | * interrupts even when in MSI mode. This results in spurious |
| 1240 | * interrupt warnings if the legacy irq no. is shared with another |
| 1241 | * device. The kernel then disables that interrupt source and so |
| 1242 | * prevents the other device from working properly. |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1243 | */ |
Ville Syrjälä | e38c2da | 2017-06-26 23:30:51 +0300 | [diff] [blame] | 1244 | if (INTEL_GEN(dev_priv) >= 5) { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1245 | if (pci_enable_msi(pdev) < 0) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1246 | DRM_DEBUG_DRIVER("can't enable MSI"); |
| 1247 | } |
| 1248 | |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 1249 | ret = intel_gvt_init(dev_priv); |
| 1250 | if (ret) |
Chris Wilson | 7ab87ed | 2018-07-10 15:38:21 +0100 | [diff] [blame] | 1251 | goto err_msi; |
| 1252 | |
| 1253 | intel_opregion_setup(dev_priv); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 1254 | /* |
| 1255 | * Fill the dram structure to get the system raw bandwidth and |
| 1256 | * dram info. This will be used for memory latency calculation. |
| 1257 | */ |
| 1258 | intel_get_dram_info(dev_priv); |
| 1259 | |
Ville Syrjälä | c457d9c | 2019-05-24 18:36:14 +0300 | [diff] [blame] | 1260 | intel_bw_init_hw(dev_priv); |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 1261 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1262 | return 0; |
| 1263 | |
Chris Wilson | 7ab87ed | 2018-07-10 15:38:21 +0100 | [diff] [blame] | 1264 | err_msi: |
| 1265 | if (pdev->msi_enabled) |
| 1266 | pci_disable_msi(pdev); |
| 1267 | pm_qos_remove_request(&dev_priv->pm_qos); |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1268 | err_mem_regions: |
| 1269 | intel_memory_regions_driver_release(dev_priv); |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 1270 | err_ggtt: |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1271 | i915_ggtt_driver_release(dev_priv); |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 1272 | err_perf: |
| 1273 | i915_perf_fini(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1274 | return ret; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
Janusz Krzysztofik | 78dae1a | 2019-07-12 13:24:29 +0200 | [diff] [blame] | 1278 | * i915_driver_hw_remove - cleanup the setup done in i915_driver_hw_probe() |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1279 | * @dev_priv: device private |
| 1280 | */ |
Janusz Krzysztofik | 78dae1a | 2019-07-12 13:24:29 +0200 | [diff] [blame] | 1281 | static void i915_driver_hw_remove(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1282 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1283 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1284 | |
Lionel Landwerlin | 9f9b279 | 2017-10-27 15:59:31 +0100 | [diff] [blame] | 1285 | i915_perf_fini(dev_priv); |
| 1286 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1287 | if (pdev->msi_enabled) |
| 1288 | pci_disable_msi(pdev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1289 | |
| 1290 | pm_qos_remove_request(&dev_priv->pm_qos); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * i915_driver_register - register the driver with the rest of the system |
| 1295 | * @dev_priv: device private |
| 1296 | * |
| 1297 | * Perform any steps necessary to make the driver available via kernel |
| 1298 | * internal or userspace interfaces. |
| 1299 | */ |
| 1300 | static void i915_driver_register(struct drm_i915_private *dev_priv) |
| 1301 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1302 | struct drm_device *dev = &dev_priv->drm; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1303 | |
Chris Wilson | c29579d | 2019-08-06 13:42:59 +0100 | [diff] [blame] | 1304 | i915_gem_driver_register(dev_priv); |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 1305 | i915_pmu_register(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1306 | |
| 1307 | /* |
| 1308 | * Notify a valid surface after modesetting, |
| 1309 | * when running inside a VM. |
| 1310 | */ |
| 1311 | if (intel_vgpu_active(dev_priv)) |
| 1312 | I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY); |
| 1313 | |
| 1314 | /* Reveal our presence to userspace */ |
| 1315 | if (drm_dev_register(dev, 0) == 0) { |
| 1316 | i915_debugfs_register(dev_priv); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 1317 | i915_setup_sysfs(dev_priv); |
Robert Bragg | 442b8c0 | 2016-11-07 19:49:53 +0000 | [diff] [blame] | 1318 | |
| 1319 | /* Depends on sysfs having been initialized */ |
| 1320 | i915_perf_register(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1321 | } else |
| 1322 | DRM_ERROR("Failed to register driver for userspace access!\n"); |
| 1323 | |
Jani Nikula | a2b69ea | 2019-09-13 13:04:07 +0300 | [diff] [blame] | 1324 | if (HAS_DISPLAY(dev_priv) && INTEL_DISPLAY_ENABLED(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1325 | /* Must be done after probing outputs */ |
| 1326 | intel_opregion_register(dev_priv); |
| 1327 | acpi_video_register(); |
| 1328 | } |
| 1329 | |
Andi Shyti | 42014f6 | 2019-09-05 14:14:03 +0300 | [diff] [blame] | 1330 | intel_gt_driver_register(&dev_priv->gt); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1331 | |
Jerome Anand | eef5732 | 2017-01-25 04:27:49 +0530 | [diff] [blame] | 1332 | intel_audio_init(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1333 | |
| 1334 | /* |
| 1335 | * Some ports require correctly set-up hpd registers for detection to |
| 1336 | * work properly (leading to ghost connected connector status), e.g. VGA |
| 1337 | * on gm45. Hence we can only set up the initial fbdev config after hpd |
| 1338 | * irqs are fully enabled. We do it last so that the async config |
| 1339 | * cannot run before the connectors are registered. |
| 1340 | */ |
| 1341 | intel_fbdev_initial_config_async(dev); |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 1342 | |
| 1343 | /* |
| 1344 | * We need to coordinate the hotplugs with the asynchronous fbdev |
| 1345 | * configuration, for which we use the fbdev->async_cookie. |
| 1346 | */ |
Jani Nikula | a2b69ea | 2019-09-13 13:04:07 +0300 | [diff] [blame] | 1347 | if (HAS_DISPLAY(dev_priv) && INTEL_DISPLAY_ENABLED(dev_priv)) |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 1348 | drm_kms_helper_poll_init(dev); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 1349 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1350 | intel_power_domains_enable(dev_priv); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1351 | intel_runtime_pm_enable(&dev_priv->runtime_pm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * i915_driver_unregister - cleanup the registration done in i915_driver_regiser() |
| 1356 | * @dev_priv: device private |
| 1357 | */ |
| 1358 | static void i915_driver_unregister(struct drm_i915_private *dev_priv) |
| 1359 | { |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1360 | intel_runtime_pm_disable(&dev_priv->runtime_pm); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1361 | intel_power_domains_disable(dev_priv); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 1362 | |
Daniel Vetter | 4f256d8 | 2017-07-15 00:46:55 +0200 | [diff] [blame] | 1363 | intel_fbdev_unregister(dev_priv); |
Jerome Anand | eef5732 | 2017-01-25 04:27:49 +0530 | [diff] [blame] | 1364 | intel_audio_deinit(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1365 | |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 1366 | /* |
| 1367 | * After flushing the fbdev (incl. a late async config which will |
| 1368 | * have delayed queuing of a hotplug event), then flush the hotplug |
| 1369 | * events. |
| 1370 | */ |
| 1371 | drm_kms_helper_poll_fini(&dev_priv->drm); |
| 1372 | |
Andi Shyti | 42014f6 | 2019-09-05 14:14:03 +0300 | [diff] [blame] | 1373 | intel_gt_driver_unregister(&dev_priv->gt); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1374 | acpi_video_unregister(); |
| 1375 | intel_opregion_unregister(dev_priv); |
| 1376 | |
Robert Bragg | 442b8c0 | 2016-11-07 19:49:53 +0000 | [diff] [blame] | 1377 | i915_perf_unregister(dev_priv); |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 1378 | i915_pmu_unregister(dev_priv); |
Robert Bragg | 442b8c0 | 2016-11-07 19:49:53 +0000 | [diff] [blame] | 1379 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 1380 | i915_teardown_sysfs(dev_priv); |
Janusz Krzysztofik | d69990e | 2019-04-05 15:02:34 +0200 | [diff] [blame] | 1381 | drm_dev_unplug(&dev_priv->drm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1382 | |
Chris Wilson | c29579d | 2019-08-06 13:42:59 +0100 | [diff] [blame] | 1383 | i915_gem_driver_unregister(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 1386 | static void i915_welcome_messages(struct drm_i915_private *dev_priv) |
| 1387 | { |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 1388 | if (drm_debug_enabled(DRM_UT_DRIVER)) { |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 1389 | struct drm_printer p = drm_debug_printer("i915 device info:"); |
| 1390 | |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 1391 | drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n", |
Jani Nikula | 1787a98 | 2018-12-31 16:56:45 +0200 | [diff] [blame] | 1392 | INTEL_DEVID(dev_priv), |
| 1393 | INTEL_REVID(dev_priv), |
| 1394 | intel_platform_name(INTEL_INFO(dev_priv)->platform), |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 1395 | intel_subplatform(RUNTIME_INFO(dev_priv), |
| 1396 | INTEL_INFO(dev_priv)->platform), |
Jani Nikula | 1787a98 | 2018-12-31 16:56:45 +0200 | [diff] [blame] | 1397 | INTEL_GEN(dev_priv)); |
| 1398 | |
Chris Wilson | 7240497 | 2019-12-07 18:29:37 +0000 | [diff] [blame] | 1399 | intel_device_info_print_static(INTEL_INFO(dev_priv), &p); |
| 1400 | intel_device_info_print_runtime(RUNTIME_INFO(dev_priv), &p); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG)) |
| 1404 | DRM_INFO("DRM_I915_DEBUG enabled\n"); |
| 1405 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) |
| 1406 | DRM_INFO("DRM_I915_DEBUG_GEM enabled\n"); |
Imre Deak | 6dfc4a8 | 2018-08-16 22:34:14 +0300 | [diff] [blame] | 1407 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) |
| 1408 | DRM_INFO("DRM_I915_DEBUG_RUNTIME_PM enabled\n"); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1411 | static struct drm_i915_private * |
| 1412 | i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1413 | { |
| 1414 | const struct intel_device_info *match_info = |
| 1415 | (struct intel_device_info *)ent->driver_data; |
| 1416 | struct intel_device_info *device_info; |
| 1417 | struct drm_i915_private *i915; |
Andi Shyti | 2ddcc98 | 2018-10-02 12:20:47 +0300 | [diff] [blame] | 1418 | int err; |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1419 | |
| 1420 | i915 = kzalloc(sizeof(*i915), GFP_KERNEL); |
| 1421 | if (!i915) |
Andi Shyti | 2ddcc98 | 2018-10-02 12:20:47 +0300 | [diff] [blame] | 1422 | return ERR_PTR(-ENOMEM); |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1423 | |
Andi Shyti | 2ddcc98 | 2018-10-02 12:20:47 +0300 | [diff] [blame] | 1424 | err = drm_dev_init(&i915->drm, &driver, &pdev->dev); |
| 1425 | if (err) { |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1426 | kfree(i915); |
Andi Shyti | 2ddcc98 | 2018-10-02 12:20:47 +0300 | [diff] [blame] | 1427 | return ERR_PTR(err); |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1430 | i915->drm.dev_private = i915; |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1431 | |
| 1432 | i915->drm.pdev = pdev; |
| 1433 | pci_set_drvdata(pdev, i915); |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1434 | |
| 1435 | /* Setup the write-once "constant" device info */ |
| 1436 | device_info = mkwrite_device_info(i915); |
| 1437 | memcpy(device_info, match_info, sizeof(*device_info)); |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 1438 | RUNTIME_INFO(i915)->device_id = pdev->device; |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1439 | |
Chris Wilson | 74f6e18 | 2018-09-26 11:47:07 +0100 | [diff] [blame] | 1440 | BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask)); |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1441 | |
| 1442 | return i915; |
| 1443 | } |
| 1444 | |
Chris Wilson | 31962ca | 2018-09-05 15:09:21 +0100 | [diff] [blame] | 1445 | static void i915_driver_destroy(struct drm_i915_private *i915) |
| 1446 | { |
| 1447 | struct pci_dev *pdev = i915->drm.pdev; |
| 1448 | |
| 1449 | drm_dev_fini(&i915->drm); |
| 1450 | kfree(i915); |
| 1451 | |
| 1452 | /* And make sure we never chase our dangling pointer from pci_dev */ |
| 1453 | pci_set_drvdata(pdev, NULL); |
| 1454 | } |
| 1455 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1456 | /** |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 1457 | * i915_driver_probe - setup chip and create an initial config |
Joonas Lahtinen | d2ad3ae | 2016-11-10 15:36:34 +0200 | [diff] [blame] | 1458 | * @pdev: PCI device |
| 1459 | * @ent: matching PCI ID entry |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1460 | * |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 1461 | * The driver probe routine has to do several things: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1462 | * - drive output discovery via intel_modeset_init() |
| 1463 | * - initialize the memory manager |
| 1464 | * - allocate initial config memory |
| 1465 | * - setup the DRM framebuffer with the allocated memory |
| 1466 | */ |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 1467 | int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1468 | { |
Maarten Lankhorst | 8d2b47d | 2017-02-02 08:41:42 +0100 | [diff] [blame] | 1469 | const struct intel_device_info *match_info = |
| 1470 | (struct intel_device_info *)ent->driver_data; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1471 | struct drm_i915_private *dev_priv; |
| 1472 | int ret; |
| 1473 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 1474 | dev_priv = i915_driver_create(pdev, ent); |
Andi Shyti | 2ddcc98 | 2018-10-02 12:20:47 +0300 | [diff] [blame] | 1475 | if (IS_ERR(dev_priv)) |
| 1476 | return PTR_ERR(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1477 | |
Ville Syrjälä | 1feb64c | 2018-09-13 16:16:22 +0300 | [diff] [blame] | 1478 | /* Disable nuclear pageflip by default on pre-ILK */ |
| 1479 | if (!i915_modparams.nuclear_pageflip && match_info->gen < 5) |
| 1480 | dev_priv->drm.driver_features &= ~DRIVER_ATOMIC; |
| 1481 | |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 1482 | /* |
| 1483 | * Check if we support fake LMEM -- for now we only unleash this for |
| 1484 | * the live selftests(test-and-exit). |
| 1485 | */ |
Chris Wilson | 292a27b | 2019-11-01 09:51:47 +0000 | [diff] [blame] | 1486 | #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 1487 | if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)) { |
| 1488 | if (INTEL_GEN(dev_priv) >= 9 && i915_selftest.live < 0 && |
| 1489 | i915_modparams.fake_lmem_start) { |
| 1490 | mkwrite_device_info(dev_priv)->memory_regions = |
| 1491 | REGION_SMEM | REGION_LMEM | REGION_STOLEN; |
| 1492 | mkwrite_device_info(dev_priv)->is_dgfx = true; |
| 1493 | GEM_BUG_ON(!HAS_LMEM(dev_priv)); |
| 1494 | GEM_BUG_ON(!IS_DGFX(dev_priv)); |
| 1495 | } |
| 1496 | } |
Chris Wilson | 292a27b | 2019-11-01 09:51:47 +0000 | [diff] [blame] | 1497 | #endif |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 1498 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1499 | ret = pci_enable_device(pdev); |
| 1500 | if (ret) |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 1501 | goto out_fini; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1502 | |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 1503 | ret = i915_driver_early_probe(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1504 | if (ret < 0) |
| 1505 | goto out_pci_disable; |
| 1506 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1507 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1508 | |
Daniele Ceraolo Spurio | 9e138ea | 2019-06-19 18:00:21 -0700 | [diff] [blame] | 1509 | i915_detect_vgpu(dev_priv); |
| 1510 | |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 1511 | ret = i915_driver_mmio_probe(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1512 | if (ret < 0) |
| 1513 | goto out_runtime_pm_put; |
| 1514 | |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 1515 | ret = i915_driver_hw_probe(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1516 | if (ret < 0) |
| 1517 | goto out_cleanup_mmio; |
| 1518 | |
Jani Nikula | 5bcd53a | 2019-09-20 21:54:17 +0300 | [diff] [blame] | 1519 | ret = i915_driver_modeset_probe(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1520 | if (ret < 0) |
Daniel Vetter | baf5438 | 2017-06-21 10:28:41 +0200 | [diff] [blame] | 1521 | goto out_cleanup_hw; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1522 | |
| 1523 | i915_driver_register(dev_priv); |
| 1524 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1525 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1526 | |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 1527 | i915_welcome_messages(dev_priv); |
| 1528 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1529 | return 0; |
| 1530 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1531 | out_cleanup_hw: |
Janusz Krzysztofik | 78dae1a | 2019-07-12 13:24:29 +0200 | [diff] [blame] | 1532 | i915_driver_hw_remove(dev_priv); |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1533 | intel_memory_regions_driver_release(dev_priv); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1534 | i915_ggtt_driver_release(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1535 | out_cleanup_mmio: |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1536 | i915_driver_mmio_release(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1537 | out_runtime_pm_put: |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1538 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1539 | i915_driver_late_release(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1540 | out_pci_disable: |
| 1541 | pci_disable_device(pdev); |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 1542 | out_fini: |
Janusz Krzysztofik | f2db53f | 2019-07-12 13:24:27 +0200 | [diff] [blame] | 1543 | i915_probe_error(dev_priv, "Device initialization failed (%d)\n", ret); |
Chris Wilson | 31962ca | 2018-09-05 15:09:21 +0100 | [diff] [blame] | 1544 | i915_driver_destroy(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1545 | return ret; |
| 1546 | } |
| 1547 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1548 | void i915_driver_remove(struct drm_i915_private *i915) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1549 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1550 | disable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 1551 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1552 | i915_driver_unregister(i915); |
Daniel Vetter | 99c539b | 2017-07-15 00:46:56 +0200 | [diff] [blame] | 1553 | |
Janusz Krzysztofik | 141f376 | 2019-04-06 11:40:34 +0100 | [diff] [blame] | 1554 | /* |
| 1555 | * After unregistering the device to prevent any new users, cancel |
| 1556 | * all in-flight requests so that we can quickly unbind the active |
| 1557 | * resources. |
| 1558 | */ |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1559 | intel_gt_set_wedged(&i915->gt); |
Janusz Krzysztofik | 141f376 | 2019-04-06 11:40:34 +0100 | [diff] [blame] | 1560 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 1561 | /* Flush any external code that still may be under the RCU lock */ |
| 1562 | synchronize_rcu(); |
| 1563 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1564 | i915_gem_suspend(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1565 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1566 | drm_atomic_helper_shutdown(&i915->drm); |
Maarten Lankhorst | a667fb4 | 2016-12-15 15:29:44 +0100 | [diff] [blame] | 1567 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1568 | intel_gvt_driver_remove(i915); |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 1569 | |
Jani Nikula | 2d6f6f3 | 2019-09-20 21:54:16 +0300 | [diff] [blame] | 1570 | i915_driver_modeset_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1571 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1572 | i915_reset_error_state(i915); |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1573 | i915_gem_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1574 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1575 | intel_power_domains_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1576 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1577 | i915_driver_hw_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1578 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1579 | enable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | static void i915_driver_release(struct drm_device *dev) |
| 1583 | { |
| 1584 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1585 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1586 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1587 | disable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 1588 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1589 | i915_gem_driver_release(dev_priv); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 1590 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 1591 | intel_memory_regions_driver_release(dev_priv); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1592 | i915_ggtt_driver_release(dev_priv); |
Daniele Ceraolo Spurio | 19e0a8d | 2019-06-19 18:00:17 -0700 | [diff] [blame] | 1593 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1594 | i915_driver_mmio_release(dev_priv); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 1595 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1596 | enable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1597 | intel_runtime_pm_driver_release(rpm); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 1598 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1599 | i915_driver_late_release(dev_priv); |
Chris Wilson | 31962ca | 2018-09-05 15:09:21 +0100 | [diff] [blame] | 1600 | i915_driver_destroy(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | static int i915_driver_open(struct drm_device *dev, struct drm_file *file) |
| 1604 | { |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 1605 | struct drm_i915_private *i915 = to_i915(dev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1606 | int ret; |
| 1607 | |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 1608 | ret = i915_gem_open(i915, file); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1609 | if (ret) |
| 1610 | return ret; |
| 1611 | |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
| 1615 | /** |
| 1616 | * i915_driver_lastclose - clean up after all DRM clients have exited |
| 1617 | * @dev: DRM device |
| 1618 | * |
| 1619 | * Take care of cleaning up after all DRM clients have exited. In the |
| 1620 | * mode setting case, we want to restore the kernel's initial mode (just |
| 1621 | * in case the last client left us in a bad state). |
| 1622 | * |
| 1623 | * Additionally, in the non-mode setting case, we'll tear down the GTT |
| 1624 | * and DMA structures, since the kernel won't be using them, and clea |
| 1625 | * up any GEM state. |
| 1626 | */ |
| 1627 | static void i915_driver_lastclose(struct drm_device *dev) |
| 1628 | { |
| 1629 | intel_fbdev_restore_mode(dev); |
| 1630 | vga_switcheroo_process_delayed_switch(); |
| 1631 | } |
| 1632 | |
Daniel Vetter | 7d2ec88 | 2017-03-08 15:12:45 +0100 | [diff] [blame] | 1633 | static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1634 | { |
Daniel Vetter | 7d2ec88 | 2017-03-08 15:12:45 +0100 | [diff] [blame] | 1635 | struct drm_i915_file_private *file_priv = file->driver_priv; |
| 1636 | |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 1637 | i915_gem_context_close(file); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1638 | i915_gem_release(dev, file); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1639 | |
Chris Wilson | 7771590 | 2019-08-23 19:14:55 +0100 | [diff] [blame] | 1640 | kfree_rcu(file_priv, rcu); |
Chris Wilson | 515b8b7 | 2019-08-02 22:21:37 +0100 | [diff] [blame] | 1641 | |
| 1642 | /* Catch up with all the deferred frees from "this" client */ |
| 1643 | i915_gem_flush_free_objects(to_i915(dev)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 1646 | static void intel_suspend_encoders(struct drm_i915_private *dev_priv) |
| 1647 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1648 | struct drm_device *dev = &dev_priv->drm; |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 1649 | struct intel_encoder *encoder; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 1650 | |
| 1651 | drm_modeset_lock_all(dev); |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 1652 | for_each_intel_encoder(dev, encoder) |
| 1653 | if (encoder->suspend) |
| 1654 | encoder->suspend(encoder); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 1655 | drm_modeset_unlock_all(dev); |
| 1656 | } |
| 1657 | |
Paulo Zanoni | 1a5df18 | 2014-10-27 17:54:32 -0200 | [diff] [blame] | 1658 | static int vlv_resume_prepare(struct drm_i915_private *dev_priv, |
| 1659 | bool rpm_resume); |
Imre Deak | 507e126 | 2016-04-20 20:27:54 +0300 | [diff] [blame] | 1660 | static int vlv_suspend_complete(struct drm_i915_private *dev_priv); |
Suketu Shah | f75a198 | 2015-04-16 14:22:11 +0530 | [diff] [blame] | 1661 | |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1662 | static bool suspend_to_idle(struct drm_i915_private *dev_priv) |
| 1663 | { |
| 1664 | #if IS_ENABLED(CONFIG_ACPI_SLEEP) |
| 1665 | if (acpi_target_system_state() < ACPI_STATE_S3) |
| 1666 | return true; |
| 1667 | #endif |
| 1668 | return false; |
| 1669 | } |
Sagar Kamble | ebc3282 | 2014-08-13 23:07:05 +0530 | [diff] [blame] | 1670 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1671 | static int i915_drm_prepare(struct drm_device *dev) |
| 1672 | { |
| 1673 | struct drm_i915_private *i915 = to_i915(dev); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1674 | |
| 1675 | /* |
| 1676 | * NB intel_display_suspend() may issue new requests after we've |
| 1677 | * ostensibly marked the GPU as ready-to-sleep here. We need to |
| 1678 | * split out that work and pull it forward so that after point, |
| 1679 | * the GPU is not woken again. |
| 1680 | */ |
Chris Wilson | 5861b01 | 2019-03-08 09:36:54 +0000 | [diff] [blame] | 1681 | i915_gem_suspend(i915); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1682 | |
Chris Wilson | 5861b01 | 2019-03-08 09:36:54 +0000 | [diff] [blame] | 1683 | return 0; |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1684 | } |
| 1685 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1686 | static int i915_drm_suspend(struct drm_device *dev) |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1687 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1688 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1689 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | e5747e3 | 2014-06-12 08:35:47 -0700 | [diff] [blame] | 1690 | pci_power_t opregion_target_state; |
Rafael J. Wysocki | 61caf87 | 2010-02-18 23:06:27 +0100 | [diff] [blame] | 1691 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1692 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1693 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 1694 | /* We do a lot of poking in a lot of registers, make sure they work |
| 1695 | * properly. */ |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1696 | intel_power_domains_disable(dev_priv); |
Paulo Zanoni | cb10799 | 2013-01-25 16:59:15 -0200 | [diff] [blame] | 1697 | |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1698 | drm_kms_helper_poll_disable(dev); |
| 1699 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1700 | pci_save_state(pdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1701 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 1702 | intel_display_suspend(dev); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1703 | |
Ville Syrjälä | 1a4313d | 2018-07-05 19:43:52 +0300 | [diff] [blame] | 1704 | intel_dp_mst_suspend(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1705 | |
| 1706 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 1707 | intel_hpd_cancel_work(dev_priv); |
| 1708 | |
| 1709 | intel_suspend_encoders(dev_priv); |
| 1710 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 1711 | intel_suspend_hw(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1712 | |
Tvrtko Ursulin | 275a991 | 2016-11-16 08:55:34 +0000 | [diff] [blame] | 1713 | i915_gem_suspend_gtt_mappings(dev_priv); |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 1714 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 1715 | i915_save_state(dev_priv); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1716 | |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1717 | opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold; |
Chris Wilson | a950adc | 2018-10-30 11:05:54 +0000 | [diff] [blame] | 1718 | intel_opregion_suspend(dev_priv, opregion_target_state); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1719 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 1720 | intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true); |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 1721 | |
Mika Kuoppala | 62d5d69 | 2014-02-25 17:11:28 +0200 | [diff] [blame] | 1722 | dev_priv->suspend_count++; |
| 1723 | |
Imre Deak | f74ed08 | 2016-04-18 14:48:21 +0300 | [diff] [blame] | 1724 | intel_csr_ucode_suspend(dev_priv); |
Imre Deak | f514c2d | 2015-10-28 23:59:06 +0200 | [diff] [blame] | 1725 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1726 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1727 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1728 | return 0; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1729 | } |
| 1730 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1731 | static enum i915_drm_suspend_mode |
| 1732 | get_suspend_mode(struct drm_i915_private *dev_priv, bool hibernate) |
| 1733 | { |
| 1734 | if (hibernate) |
| 1735 | return I915_DRM_SUSPEND_HIBERNATE; |
| 1736 | |
| 1737 | if (suspend_to_idle(dev_priv)) |
| 1738 | return I915_DRM_SUSPEND_IDLE; |
| 1739 | |
| 1740 | return I915_DRM_SUSPEND_MEM; |
| 1741 | } |
| 1742 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1743 | static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1744 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1745 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1746 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1747 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1748 | int ret = 0; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1749 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1750 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1751 | |
Chris Wilson | ec92ad0 | 2018-05-31 09:22:46 +0100 | [diff] [blame] | 1752 | i915_gem_suspend_late(dev_priv); |
| 1753 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1754 | intel_uncore_suspend(&dev_priv->uncore); |
Imre Deak | 4c494a5 | 2016-10-13 14:34:06 +0300 | [diff] [blame] | 1755 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1756 | intel_power_domains_suspend(dev_priv, |
| 1757 | get_suspend_mode(dev_priv, hibernation)); |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 1758 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1759 | intel_display_power_suspend_late(dev_priv); |
| 1760 | |
| 1761 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Imre Deak | 507e126 | 2016-04-20 20:27:54 +0300 | [diff] [blame] | 1762 | ret = vlv_suspend_complete(dev_priv); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1763 | |
| 1764 | if (ret) { |
| 1765 | DRM_ERROR("Suspend complete failed: %d\n", ret); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1766 | intel_power_domains_resume(dev_priv); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1767 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1768 | goto out; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1769 | } |
| 1770 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1771 | pci_disable_device(pdev); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1772 | /* |
Imre Deak | 5487557 | 2015-06-30 17:06:47 +0300 | [diff] [blame] | 1773 | * During hibernation on some platforms the BIOS may try to access |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1774 | * the device even though it's already in D3 and hang the machine. So |
| 1775 | * leave the device in D0 on those platforms and hope the BIOS will |
Imre Deak | 5487557 | 2015-06-30 17:06:47 +0300 | [diff] [blame] | 1776 | * power down the device properly. The issue was seen on multiple old |
| 1777 | * GENs with different BIOS vendors, so having an explicit blacklist |
| 1778 | * is inpractical; apply the workaround on everything pre GEN6. The |
| 1779 | * platforms where the issue was seen: |
| 1780 | * Lenovo Thinkpad X301, X61s, X60, T60, X41 |
| 1781 | * Fujitsu FSC S7110 |
| 1782 | * Acer Aspire 1830T |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1783 | */ |
Tvrtko Ursulin | 514e1d6 | 2016-11-04 14:42:48 +0000 | [diff] [blame] | 1784 | if (!(hibernation && INTEL_GEN(dev_priv) < 6)) |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1785 | pci_set_power_state(pdev, PCI_D3hot); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1786 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1787 | out: |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1788 | enable_rpm_wakeref_asserts(rpm); |
Daniele Ceraolo Spurio | 0a9b263 | 2019-08-09 07:31:16 +0100 | [diff] [blame] | 1789 | if (!dev_priv->uncore.user_forcewake_count) |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1790 | intel_runtime_pm_driver_release(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1791 | |
| 1792 | return ret; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1793 | } |
| 1794 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 1795 | int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state) |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1796 | { |
| 1797 | int error; |
| 1798 | |
Imre Deak | 0b14cbd | 2014-09-10 18:16:55 +0300 | [diff] [blame] | 1799 | if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND && |
| 1800 | state.event != PM_EVENT_FREEZE)) |
| 1801 | return -EINVAL; |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1802 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1803 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1804 | return 0; |
Chris Wilson | 6eecba3 | 2010-09-08 09:45:11 +0100 | [diff] [blame] | 1805 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1806 | error = i915_drm_suspend(&i915->drm); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1807 | if (error) |
| 1808 | return error; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1809 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1810 | return i915_drm_suspend_late(&i915->drm, false); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1811 | } |
| 1812 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1813 | static int i915_drm_resume(struct drm_device *dev) |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1814 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1815 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | ac840ae | 2016-05-06 21:35:55 +0300 | [diff] [blame] | 1816 | int ret; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1817 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1818 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1819 | |
Chris Wilson | fd6fe08 | 2019-11-01 14:10:06 +0000 | [diff] [blame] | 1820 | intel_gt_sanitize(&dev_priv->gt, true); |
Chris Wilson | 1288786 | 2018-06-14 10:40:59 +0100 | [diff] [blame] | 1821 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 1822 | ret = i915_ggtt_enable_hw(dev_priv); |
Ville Syrjälä | ac840ae | 2016-05-06 21:35:55 +0300 | [diff] [blame] | 1823 | if (ret) |
| 1824 | DRM_ERROR("failed to re-enable GGTT\n"); |
| 1825 | |
Chris Wilson | 6c76a93 | 2019-09-09 12:00:08 +0100 | [diff] [blame] | 1826 | i915_gem_restore_gtt_mappings(dev_priv); |
Chris Wilson | e9d4c92 | 2019-10-16 15:32:33 +0100 | [diff] [blame] | 1827 | i915_gem_restore_fences(&dev_priv->ggtt); |
Chris Wilson | 6c76a93 | 2019-09-09 12:00:08 +0100 | [diff] [blame] | 1828 | |
Imre Deak | f74ed08 | 2016-04-18 14:48:21 +0300 | [diff] [blame] | 1829 | intel_csr_ucode_resume(dev_priv); |
| 1830 | |
Tvrtko Ursulin | af6dc74 | 2016-12-01 14:16:44 +0000 | [diff] [blame] | 1831 | i915_restore_state(dev_priv); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 1832 | intel_pps_unlock_regs_wa(dev_priv); |
Rafael J. Wysocki | 61caf87 | 2010-02-18 23:06:27 +0100 | [diff] [blame] | 1833 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 1834 | intel_init_pch_refclk(dev_priv); |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 1835 | |
Peter Antoine | 364aece | 2015-05-11 08:50:45 +0100 | [diff] [blame] | 1836 | /* |
| 1837 | * Interrupts have to be enabled before any batches are run. If not the |
| 1838 | * GPU will hang. i915_gem_init_hw() will initiate batches to |
| 1839 | * update/restore the context. |
| 1840 | * |
Imre Deak | 908764f | 2016-11-29 21:40:29 +0200 | [diff] [blame] | 1841 | * drm_mode_config_reset() needs AUX interrupts. |
| 1842 | * |
Peter Antoine | 364aece | 2015-05-11 08:50:45 +0100 | [diff] [blame] | 1843 | * Modeset enabling in intel_modeset_init_hw() also needs working |
| 1844 | * interrupts. |
| 1845 | */ |
| 1846 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 1847 | |
Imre Deak | 908764f | 2016-11-29 21:40:29 +0200 | [diff] [blame] | 1848 | drm_mode_config_reset(dev); |
| 1849 | |
Chris Wilson | 37cd330 | 2017-11-12 11:27:38 +0000 | [diff] [blame] | 1850 | i915_gem_resume(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1851 | |
Jani Nikula | 6cd02e7 | 2019-09-20 21:54:21 +0300 | [diff] [blame] | 1852 | intel_modeset_init_hw(dev_priv); |
Ville Syrjälä | 675f7ff | 2017-11-16 18:02:15 +0200 | [diff] [blame] | 1853 | intel_init_clock_gating(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1854 | |
| 1855 | spin_lock_irq(&dev_priv->irq_lock); |
| 1856 | if (dev_priv->display.hpd_irq_setup) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 1857 | dev_priv->display.hpd_irq_setup(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1858 | spin_unlock_irq(&dev_priv->irq_lock); |
| 1859 | |
Ville Syrjälä | 1a4313d | 2018-07-05 19:43:52 +0300 | [diff] [blame] | 1860 | intel_dp_mst_resume(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1861 | |
Lyude | a16b765 | 2016-03-11 10:57:01 -0500 | [diff] [blame] | 1862 | intel_display_resume(dev); |
| 1863 | |
Lyude | e0b7006 | 2016-11-01 21:06:30 -0400 | [diff] [blame] | 1864 | drm_kms_helper_poll_enable(dev); |
| 1865 | |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1866 | /* |
| 1867 | * ... but also need to make sure that hotplug processing |
| 1868 | * doesn't cause havoc. Like in the driver load code we don't |
Gwan-gyeong Mun | c444ad7 | 2018-08-03 19:41:50 +0300 | [diff] [blame] | 1869 | * bother with the tiny race here where we might lose hotplug |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1870 | * notifications. |
| 1871 | * */ |
| 1872 | intel_hpd_init(dev_priv); |
Jesse Barnes | 1daed3f | 2011-01-05 12:01:25 -0800 | [diff] [blame] | 1873 | |
Chris Wilson | a950adc | 2018-10-30 11:05:54 +0000 | [diff] [blame] | 1874 | intel_opregion_resume(dev_priv); |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1875 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 1876 | intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false); |
Jesse Barnes | 073f34d | 2012-11-02 11:13:59 -0700 | [diff] [blame] | 1877 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1878 | intel_power_domains_enable(dev_priv); |
| 1879 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1880 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1881 | |
Chris Wilson | 074c6ad | 2014-04-09 09:19:43 +0100 | [diff] [blame] | 1882 | return 0; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1883 | } |
| 1884 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1885 | static int i915_drm_resume_early(struct drm_device *dev) |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1886 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1887 | struct drm_i915_private *dev_priv = to_i915(dev); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1888 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1889 | int ret; |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1890 | |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1891 | /* |
| 1892 | * We have a resume ordering issue with the snd-hda driver also |
| 1893 | * requiring our device to be power up. Due to the lack of a |
| 1894 | * parent/child relationship we currently solve this with an early |
| 1895 | * resume hook. |
| 1896 | * |
| 1897 | * FIXME: This should be solved with a special hdmi sink device or |
| 1898 | * similar so that power domains can be employed. |
| 1899 | */ |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1900 | |
| 1901 | /* |
| 1902 | * Note that we need to set the power state explicitly, since we |
| 1903 | * powered off the device during freeze and the PCI core won't power |
| 1904 | * it back up for us during thaw. Powering off the device during |
| 1905 | * freeze is not a hard requirement though, and during the |
| 1906 | * suspend/resume phases the PCI core makes sure we get here with the |
| 1907 | * device powered on. So in case we change our freeze logic and keep |
| 1908 | * the device powered we can also remove the following set power state |
| 1909 | * call. |
| 1910 | */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1911 | ret = pci_set_power_state(pdev, PCI_D0); |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1912 | if (ret) { |
| 1913 | DRM_ERROR("failed to set PCI D0 power state (%d)\n", ret); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1914 | return ret; |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /* |
| 1918 | * Note that pci_enable_device() first enables any parent bridge |
| 1919 | * device and only then sets the power state for this device. The |
| 1920 | * bridge enabling is a nop though, since bridge devices are resumed |
| 1921 | * first. The order of enabling power and enabling the device is |
| 1922 | * imposed by the PCI core as described above, so here we preserve the |
| 1923 | * same order for the freeze/thaw phases. |
| 1924 | * |
| 1925 | * TODO: eventually we should remove pci_disable_device() / |
| 1926 | * pci_enable_enable_device() from suspend/resume. Due to how they |
| 1927 | * depend on the device enable refcount we can't anyway depend on them |
| 1928 | * disabling/enabling the device. |
| 1929 | */ |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1930 | if (pci_enable_device(pdev)) |
| 1931 | return -EIO; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1932 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1933 | pci_set_master(pdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1934 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1935 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1936 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1937 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Paulo Zanoni | 1a5df18 | 2014-10-27 17:54:32 -0200 | [diff] [blame] | 1938 | ret = vlv_resume_prepare(dev_priv, false); |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1939 | if (ret) |
Damien Lespiau | ff0b187 | 2015-05-20 14:45:15 +0100 | [diff] [blame] | 1940 | DRM_ERROR("Resume prepare failed: %d, continuing anyway\n", |
| 1941 | ret); |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1942 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1943 | intel_uncore_resume_early(&dev_priv->uncore); |
| 1944 | |
Tvrtko Ursulin | eaf522f | 2019-06-21 08:07:44 +0100 | [diff] [blame] | 1945 | intel_gt_check_and_clear_faults(&dev_priv->gt); |
Paulo Zanoni | efee833 | 2014-10-27 17:54:33 -0200 | [diff] [blame] | 1946 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1947 | intel_display_power_resume_early(dev_priv); |
Paulo Zanoni | efee833 | 2014-10-27 17:54:33 -0200 | [diff] [blame] | 1948 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1949 | intel_power_domains_resume(dev_priv); |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1950 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1951 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 6e35e8a | 2016-04-18 10:04:19 +0300 | [diff] [blame] | 1952 | |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1953 | return ret; |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1954 | } |
| 1955 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 1956 | int i915_resume_switcheroo(struct drm_i915_private *i915) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1957 | { |
Imre Deak | 50a0072 | 2014-10-23 19:23:17 +0300 | [diff] [blame] | 1958 | int ret; |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1959 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1960 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 1961 | return 0; |
| 1962 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1963 | ret = i915_drm_resume_early(&i915->drm); |
Imre Deak | 50a0072 | 2014-10-23 19:23:17 +0300 | [diff] [blame] | 1964 | if (ret) |
| 1965 | return ret; |
| 1966 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1967 | return i915_drm_resume(&i915->drm); |
Imre Deak | 5a17514 | 2014-10-23 19:23:18 +0300 | [diff] [blame] | 1968 | } |
| 1969 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1970 | static int i915_pm_prepare(struct device *kdev) |
| 1971 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1972 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1973 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1974 | if (!i915) { |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1975 | dev_err(kdev, "DRM not initialized, aborting suspend.\n"); |
| 1976 | return -ENODEV; |
| 1977 | } |
| 1978 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1979 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1980 | return 0; |
| 1981 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1982 | return i915_drm_prepare(&i915->drm); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1985 | static int i915_pm_suspend(struct device *kdev) |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1986 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1987 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1988 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1989 | if (!i915) { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1990 | dev_err(kdev, "DRM not initialized, aborting suspend.\n"); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1991 | return -ENODEV; |
| 1992 | } |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1993 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1994 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1995 | return 0; |
| 1996 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1997 | return i915_drm_suspend(&i915->drm); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1998 | } |
| 1999 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2000 | static int i915_pm_suspend_late(struct device *kdev) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2001 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2002 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2003 | |
| 2004 | /* |
Damien Lespiau | c965d995 | 2015-05-18 19:53:48 +0100 | [diff] [blame] | 2005 | * We have a suspend ordering issue with the snd-hda driver also |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2006 | * requiring our device to be power up. Due to the lack of a |
| 2007 | * parent/child relationship we currently solve this with an late |
| 2008 | * suspend hook. |
| 2009 | * |
| 2010 | * FIXME: This should be solved with a special hdmi sink device or |
| 2011 | * similar so that power domains can be employed. |
| 2012 | */ |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2013 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2014 | return 0; |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 2015 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2016 | return i915_drm_suspend_late(&i915->drm, false); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2019 | static int i915_pm_poweroff_late(struct device *kdev) |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 2020 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2021 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 2022 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2023 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 2024 | return 0; |
| 2025 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2026 | return i915_drm_suspend_late(&i915->drm, true); |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 2027 | } |
| 2028 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2029 | static int i915_pm_resume_early(struct device *kdev) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2030 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2031 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2032 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2033 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 2034 | return 0; |
| 2035 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2036 | return i915_drm_resume_early(&i915->drm); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2037 | } |
| 2038 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2039 | static int i915_pm_resume(struct device *kdev) |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 2040 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2041 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 2042 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2043 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 2044 | return 0; |
| 2045 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2046 | return i915_drm_resume(&i915->drm); |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 2047 | } |
| 2048 | |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2049 | /* freeze: before creating the hibernation_image */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2050 | static int i915_pm_freeze(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2051 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2052 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 2053 | int ret; |
| 2054 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2055 | if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) { |
| 2056 | ret = i915_drm_suspend(&i915->drm); |
Imre Deak | dd9f31c | 2017-08-16 17:46:07 +0300 | [diff] [blame] | 2057 | if (ret) |
| 2058 | return ret; |
| 2059 | } |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 2060 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2061 | ret = i915_gem_freeze(i915); |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 2062 | if (ret) |
| 2063 | return ret; |
| 2064 | |
| 2065 | return 0; |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2068 | static int i915_pm_freeze_late(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2069 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2070 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 2071 | int ret; |
| 2072 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2073 | if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) { |
| 2074 | ret = i915_drm_suspend_late(&i915->drm, true); |
Imre Deak | dd9f31c | 2017-08-16 17:46:07 +0300 | [diff] [blame] | 2075 | if (ret) |
| 2076 | return ret; |
| 2077 | } |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 2078 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2079 | ret = i915_gem_freeze_late(i915); |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 2080 | if (ret) |
| 2081 | return ret; |
| 2082 | |
| 2083 | return 0; |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | /* thaw: called after creating the hibernation image, but before turning off. */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2087 | static int i915_pm_thaw_early(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2088 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2089 | return i915_pm_resume_early(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2090 | } |
| 2091 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2092 | static int i915_pm_thaw(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2093 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2094 | return i915_pm_resume(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | /* restore: called after loading the hibernation image. */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2098 | static int i915_pm_restore_early(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2099 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2100 | return i915_pm_resume_early(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2101 | } |
| 2102 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2103 | static int i915_pm_restore(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2104 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2105 | return i915_pm_resume(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2108 | /* |
| 2109 | * Save all Gunit registers that may be lost after a D3 and a subsequent |
| 2110 | * S0i[R123] transition. The list of registers needing a save/restore is |
| 2111 | * defined in the VLV2_S0IXRegs document. This documents marks all Gunit |
| 2112 | * registers in the following way: |
| 2113 | * - Driver: saved/restored by the driver |
| 2114 | * - Punit : saved/restored by the Punit firmware |
| 2115 | * - No, w/o marking: no need to save/restore, since the register is R/O or |
| 2116 | * used internally by the HW in a way that doesn't depend |
| 2117 | * keeping the content across a suspend/resume. |
| 2118 | * - Debug : used for debugging |
| 2119 | * |
| 2120 | * We save/restore all registers marked with 'Driver', with the following |
| 2121 | * exceptions: |
| 2122 | * - Registers out of use, including also registers marked with 'Debug'. |
| 2123 | * These have no effect on the driver's operation, so we don't save/restore |
| 2124 | * them to reduce the overhead. |
| 2125 | * - Registers that are fully setup by an initialization function called from |
| 2126 | * the resume path. For example many clock gating and RPS/RC6 registers. |
| 2127 | * - Registers that provide the right functionality with their reset defaults. |
| 2128 | * |
| 2129 | * TODO: Except for registers that based on the above 3 criteria can be safely |
| 2130 | * ignored, we save/restore all others, practically treating the HW context as |
| 2131 | * a black-box for the driver. Further investigation is needed to reduce the |
| 2132 | * saved/restored registers even further, by following the same 3 criteria. |
| 2133 | */ |
| 2134 | static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv) |
| 2135 | { |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2136 | struct vlv_s0ix_state *s = dev_priv->vlv_s0ix_state; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2137 | int i; |
| 2138 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2139 | if (!s) |
| 2140 | return; |
| 2141 | |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2142 | /* GAM 0x4000-0x4770 */ |
| 2143 | s->wr_watermark = I915_READ(GEN7_WR_WATERMARK); |
| 2144 | s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL); |
| 2145 | s->arb_mode = I915_READ(ARB_MODE); |
| 2146 | s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0); |
| 2147 | s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1); |
| 2148 | |
| 2149 | for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++) |
Ville Syrjälä | 22dfe79 | 2015-09-18 20:03:16 +0300 | [diff] [blame] | 2150 | s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS(i)); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2151 | |
| 2152 | s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT); |
Imre Deak | b5f1c97 | 2015-04-15 16:52:30 -0700 | [diff] [blame] | 2153 | s->gfx_max_req_count = I915_READ(GEN7_GFX_MAX_REQ_COUNT); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2154 | |
| 2155 | s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7); |
| 2156 | s->ecochk = I915_READ(GAM_ECOCHK); |
| 2157 | s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7); |
| 2158 | s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7); |
| 2159 | |
| 2160 | s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR); |
| 2161 | |
| 2162 | /* MBC 0x9024-0x91D0, 0x8500 */ |
| 2163 | s->g3dctl = I915_READ(VLV_G3DCTL); |
| 2164 | s->gsckgctl = I915_READ(VLV_GSCKGCTL); |
| 2165 | s->mbctl = I915_READ(GEN6_MBCTL); |
| 2166 | |
| 2167 | /* GCP 0x9400-0x9424, 0x8100-0x810C */ |
| 2168 | s->ucgctl1 = I915_READ(GEN6_UCGCTL1); |
| 2169 | s->ucgctl3 = I915_READ(GEN6_UCGCTL3); |
| 2170 | s->rcgctl1 = I915_READ(GEN6_RCGCTL1); |
| 2171 | s->rcgctl2 = I915_READ(GEN6_RCGCTL2); |
| 2172 | s->rstctl = I915_READ(GEN6_RSTCTL); |
| 2173 | s->misccpctl = I915_READ(GEN7_MISCCPCTL); |
| 2174 | |
| 2175 | /* GPM 0xA000-0xAA84, 0x8000-0x80FC */ |
| 2176 | s->gfxpause = I915_READ(GEN6_GFXPAUSE); |
| 2177 | s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC); |
| 2178 | s->rpdeuc = I915_READ(GEN6_RPDEUC); |
| 2179 | s->ecobus = I915_READ(ECOBUS); |
| 2180 | s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL); |
| 2181 | s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT); |
| 2182 | s->rp_deucsw = I915_READ(GEN6_RPDEUCSW); |
| 2183 | s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR); |
| 2184 | s->rcedata = I915_READ(VLV_RCEDATA); |
| 2185 | s->spare2gh = I915_READ(VLV_SPAREG2H); |
| 2186 | |
| 2187 | /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */ |
| 2188 | s->gt_imr = I915_READ(GTIMR); |
| 2189 | s->gt_ier = I915_READ(GTIER); |
| 2190 | s->pm_imr = I915_READ(GEN6_PMIMR); |
| 2191 | s->pm_ier = I915_READ(GEN6_PMIER); |
| 2192 | |
| 2193 | for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++) |
Ville Syrjälä | 22dfe79 | 2015-09-18 20:03:16 +0300 | [diff] [blame] | 2194 | s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH(i)); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2195 | |
| 2196 | /* GT SA CZ domain, 0x100000-0x138124 */ |
| 2197 | s->tilectl = I915_READ(TILECTL); |
| 2198 | s->gt_fifoctl = I915_READ(GTFIFOCTL); |
| 2199 | s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL); |
| 2200 | s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG); |
| 2201 | s->pmwgicz = I915_READ(VLV_PMWGICZ); |
| 2202 | |
| 2203 | /* Gunit-Display CZ domain, 0x182028-0x1821CF */ |
| 2204 | s->gu_ctl0 = I915_READ(VLV_GU_CTL0); |
| 2205 | s->gu_ctl1 = I915_READ(VLV_GU_CTL1); |
Jesse Barnes | 9c25210 | 2015-04-01 14:22:57 -0700 | [diff] [blame] | 2206 | s->pcbr = I915_READ(VLV_PCBR); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2207 | s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2); |
| 2208 | |
| 2209 | /* |
| 2210 | * Not saving any of: |
| 2211 | * DFT, 0x9800-0x9EC0 |
| 2212 | * SARB, 0xB000-0xB1FC |
| 2213 | * GAC, 0x5208-0x524C, 0x14000-0x14C000 |
| 2214 | * PCI CFG |
| 2215 | */ |
| 2216 | } |
| 2217 | |
| 2218 | static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv) |
| 2219 | { |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2220 | struct vlv_s0ix_state *s = dev_priv->vlv_s0ix_state; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2221 | u32 val; |
| 2222 | int i; |
| 2223 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2224 | if (!s) |
| 2225 | return; |
| 2226 | |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2227 | /* GAM 0x4000-0x4770 */ |
| 2228 | I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark); |
| 2229 | I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl); |
| 2230 | I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16)); |
| 2231 | I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0); |
| 2232 | I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1); |
| 2233 | |
| 2234 | for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++) |
Ville Syrjälä | 22dfe79 | 2015-09-18 20:03:16 +0300 | [diff] [blame] | 2235 | I915_WRITE(GEN7_LRA_LIMITS(i), s->lra_limits[i]); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2236 | |
| 2237 | I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count); |
Imre Deak | b5f1c97 | 2015-04-15 16:52:30 -0700 | [diff] [blame] | 2238 | I915_WRITE(GEN7_GFX_MAX_REQ_COUNT, s->gfx_max_req_count); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2239 | |
| 2240 | I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp); |
| 2241 | I915_WRITE(GAM_ECOCHK, s->ecochk); |
| 2242 | I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp); |
| 2243 | I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp); |
| 2244 | |
| 2245 | I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr); |
| 2246 | |
| 2247 | /* MBC 0x9024-0x91D0, 0x8500 */ |
| 2248 | I915_WRITE(VLV_G3DCTL, s->g3dctl); |
| 2249 | I915_WRITE(VLV_GSCKGCTL, s->gsckgctl); |
| 2250 | I915_WRITE(GEN6_MBCTL, s->mbctl); |
| 2251 | |
| 2252 | /* GCP 0x9400-0x9424, 0x8100-0x810C */ |
| 2253 | I915_WRITE(GEN6_UCGCTL1, s->ucgctl1); |
| 2254 | I915_WRITE(GEN6_UCGCTL3, s->ucgctl3); |
| 2255 | I915_WRITE(GEN6_RCGCTL1, s->rcgctl1); |
| 2256 | I915_WRITE(GEN6_RCGCTL2, s->rcgctl2); |
| 2257 | I915_WRITE(GEN6_RSTCTL, s->rstctl); |
| 2258 | I915_WRITE(GEN7_MISCCPCTL, s->misccpctl); |
| 2259 | |
| 2260 | /* GPM 0xA000-0xAA84, 0x8000-0x80FC */ |
| 2261 | I915_WRITE(GEN6_GFXPAUSE, s->gfxpause); |
| 2262 | I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc); |
| 2263 | I915_WRITE(GEN6_RPDEUC, s->rpdeuc); |
| 2264 | I915_WRITE(ECOBUS, s->ecobus); |
| 2265 | I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl); |
| 2266 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout); |
| 2267 | I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw); |
| 2268 | I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr); |
| 2269 | I915_WRITE(VLV_RCEDATA, s->rcedata); |
| 2270 | I915_WRITE(VLV_SPAREG2H, s->spare2gh); |
| 2271 | |
| 2272 | /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */ |
| 2273 | I915_WRITE(GTIMR, s->gt_imr); |
| 2274 | I915_WRITE(GTIER, s->gt_ier); |
| 2275 | I915_WRITE(GEN6_PMIMR, s->pm_imr); |
| 2276 | I915_WRITE(GEN6_PMIER, s->pm_ier); |
| 2277 | |
| 2278 | for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++) |
Ville Syrjälä | 22dfe79 | 2015-09-18 20:03:16 +0300 | [diff] [blame] | 2279 | I915_WRITE(GEN7_GT_SCRATCH(i), s->gt_scratch[i]); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2280 | |
| 2281 | /* GT SA CZ domain, 0x100000-0x138124 */ |
| 2282 | I915_WRITE(TILECTL, s->tilectl); |
| 2283 | I915_WRITE(GTFIFOCTL, s->gt_fifoctl); |
| 2284 | /* |
| 2285 | * Preserve the GT allow wake and GFX force clock bit, they are not |
| 2286 | * be restored, as they are used to control the s0ix suspend/resume |
| 2287 | * sequence by the caller. |
| 2288 | */ |
| 2289 | val = I915_READ(VLV_GTLC_WAKE_CTRL); |
| 2290 | val &= VLV_GTLC_ALLOWWAKEREQ; |
| 2291 | val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ; |
| 2292 | I915_WRITE(VLV_GTLC_WAKE_CTRL, val); |
| 2293 | |
| 2294 | val = I915_READ(VLV_GTLC_SURVIVABILITY_REG); |
| 2295 | val &= VLV_GFX_CLK_FORCE_ON_BIT; |
| 2296 | val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT; |
| 2297 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val); |
| 2298 | |
| 2299 | I915_WRITE(VLV_PMWGICZ, s->pmwgicz); |
| 2300 | |
| 2301 | /* Gunit-Display CZ domain, 0x182028-0x1821CF */ |
| 2302 | I915_WRITE(VLV_GU_CTL0, s->gu_ctl0); |
| 2303 | I915_WRITE(VLV_GU_CTL1, s->gu_ctl1); |
Jesse Barnes | 9c25210 | 2015-04-01 14:22:57 -0700 | [diff] [blame] | 2304 | I915_WRITE(VLV_PCBR, s->pcbr); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2305 | I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2); |
| 2306 | } |
| 2307 | |
Tvrtko Ursulin | 5a31d30 | 2019-06-11 11:45:47 +0100 | [diff] [blame] | 2308 | static int vlv_wait_for_pw_status(struct drm_i915_private *i915, |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2309 | u32 mask, u32 val) |
| 2310 | { |
Ville Syrjälä | 39806c3f | 2019-02-04 23:16:44 +0200 | [diff] [blame] | 2311 | i915_reg_t reg = VLV_GTLC_PW_STATUS; |
| 2312 | u32 reg_value; |
| 2313 | int ret; |
| 2314 | |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2315 | /* The HW does not like us polling for PW_STATUS frequently, so |
| 2316 | * use the sleeping loop rather than risk the busy spin within |
| 2317 | * intel_wait_for_register(). |
| 2318 | * |
| 2319 | * Transitioning between RC6 states should be at most 2ms (see |
| 2320 | * valleyview_enable_rps) so use a 3ms timeout. |
| 2321 | */ |
Tvrtko Ursulin | 5a31d30 | 2019-06-11 11:45:47 +0100 | [diff] [blame] | 2322 | ret = wait_for(((reg_value = |
| 2323 | intel_uncore_read_notrace(&i915->uncore, reg)) & mask) |
| 2324 | == val, 3); |
Ville Syrjälä | 39806c3f | 2019-02-04 23:16:44 +0200 | [diff] [blame] | 2325 | |
| 2326 | /* just trace the final value */ |
| 2327 | trace_i915_reg_rw(false, reg, reg_value, sizeof(reg_value), true); |
| 2328 | |
| 2329 | return ret; |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 2332 | int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on) |
| 2333 | { |
| 2334 | u32 val; |
| 2335 | int err; |
| 2336 | |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 2337 | val = I915_READ(VLV_GTLC_SURVIVABILITY_REG); |
| 2338 | val &= ~VLV_GFX_CLK_FORCE_ON_BIT; |
| 2339 | if (force_on) |
| 2340 | val |= VLV_GFX_CLK_FORCE_ON_BIT; |
| 2341 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val); |
| 2342 | |
| 2343 | if (!force_on) |
| 2344 | return 0; |
| 2345 | |
Daniele Ceraolo Spurio | 97a04e0 | 2019-03-25 14:49:39 -0700 | [diff] [blame] | 2346 | err = intel_wait_for_register(&dev_priv->uncore, |
Chris Wilson | c6ddc5f | 2016-06-30 15:32:46 +0100 | [diff] [blame] | 2347 | VLV_GTLC_SURVIVABILITY_REG, |
| 2348 | VLV_GFX_CLK_STATUS_BIT, |
| 2349 | VLV_GFX_CLK_STATUS_BIT, |
| 2350 | 20); |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 2351 | if (err) |
| 2352 | DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n", |
| 2353 | I915_READ(VLV_GTLC_SURVIVABILITY_REG)); |
| 2354 | |
| 2355 | return err; |
Imre Deak | 650ad97 | 2014-04-18 16:35:02 +0300 | [diff] [blame] | 2356 | } |
| 2357 | |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2358 | static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow) |
| 2359 | { |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2360 | u32 mask; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2361 | u32 val; |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2362 | int err; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2363 | |
| 2364 | val = I915_READ(VLV_GTLC_WAKE_CTRL); |
| 2365 | val &= ~VLV_GTLC_ALLOWWAKEREQ; |
| 2366 | if (allow) |
| 2367 | val |= VLV_GTLC_ALLOWWAKEREQ; |
| 2368 | I915_WRITE(VLV_GTLC_WAKE_CTRL, val); |
| 2369 | POSTING_READ(VLV_GTLC_WAKE_CTRL); |
| 2370 | |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2371 | mask = VLV_GTLC_ALLOWWAKEACK; |
| 2372 | val = allow ? mask : 0; |
| 2373 | |
| 2374 | err = vlv_wait_for_pw_status(dev_priv, mask, val); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2375 | if (err) |
| 2376 | DRM_ERROR("timeout disabling GT waking\n"); |
Chris Wilson | b273669 | 2016-06-30 15:32:47 +0100 | [diff] [blame] | 2377 | |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2378 | return err; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2379 | } |
| 2380 | |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2381 | static void vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv, |
| 2382 | bool wait_for_on) |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2383 | { |
| 2384 | u32 mask; |
| 2385 | u32 val; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2386 | |
| 2387 | mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK; |
| 2388 | val = wait_for_on ? mask : 0; |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2389 | |
| 2390 | /* |
| 2391 | * RC6 transitioning can be delayed up to 2 msec (see |
| 2392 | * valleyview_enable_rps), use 3 msec for safety. |
Chris Wilson | e01569a | 2018-04-09 10:49:05 +0100 | [diff] [blame] | 2393 | * |
| 2394 | * This can fail to turn off the rc6 if the GPU is stuck after a failed |
| 2395 | * reset and we are trying to force the machine to sleep. |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2396 | */ |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2397 | if (vlv_wait_for_pw_status(dev_priv, mask, val)) |
Chris Wilson | e01569a | 2018-04-09 10:49:05 +0100 | [diff] [blame] | 2398 | DRM_DEBUG_DRIVER("timeout waiting for GT wells to go %s\n", |
| 2399 | onoff(wait_for_on)); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv) |
| 2403 | { |
| 2404 | if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR)) |
| 2405 | return; |
| 2406 | |
Daniel Vetter | 6fa283b | 2016-01-19 21:00:56 +0100 | [diff] [blame] | 2407 | DRM_DEBUG_DRIVER("GT register access while GT waking disabled\n"); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2408 | I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR); |
| 2409 | } |
| 2410 | |
Sagar Kamble | ebc3282 | 2014-08-13 23:07:05 +0530 | [diff] [blame] | 2411 | static int vlv_suspend_complete(struct drm_i915_private *dev_priv) |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2412 | { |
| 2413 | u32 mask; |
| 2414 | int err; |
| 2415 | |
| 2416 | /* |
| 2417 | * Bspec defines the following GT well on flags as debug only, so |
| 2418 | * don't treat them as hard failures. |
| 2419 | */ |
Chris Wilson | 3dd14c0 | 2017-04-21 14:58:15 +0100 | [diff] [blame] | 2420 | vlv_wait_for_gt_wells(dev_priv, false); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2421 | |
| 2422 | mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS; |
| 2423 | WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask); |
| 2424 | |
| 2425 | vlv_check_no_gt_access(dev_priv); |
| 2426 | |
| 2427 | err = vlv_force_gfx_clock(dev_priv, true); |
| 2428 | if (err) |
| 2429 | goto err1; |
| 2430 | |
| 2431 | err = vlv_allow_gt_wake(dev_priv, false); |
| 2432 | if (err) |
| 2433 | goto err2; |
Deepak S | 9871116 | 2014-12-12 14:18:16 +0530 | [diff] [blame] | 2434 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2435 | vlv_save_gunit_s0ix_state(dev_priv); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2436 | |
| 2437 | err = vlv_force_gfx_clock(dev_priv, false); |
| 2438 | if (err) |
| 2439 | goto err2; |
| 2440 | |
| 2441 | return 0; |
| 2442 | |
| 2443 | err2: |
| 2444 | /* For safety always re-enable waking and disable gfx clock forcing */ |
| 2445 | vlv_allow_gt_wake(dev_priv, true); |
| 2446 | err1: |
| 2447 | vlv_force_gfx_clock(dev_priv, false); |
| 2448 | |
| 2449 | return err; |
| 2450 | } |
| 2451 | |
Sagar Kamble | 016970b | 2014-08-13 23:07:06 +0530 | [diff] [blame] | 2452 | static int vlv_resume_prepare(struct drm_i915_private *dev_priv, |
| 2453 | bool rpm_resume) |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2454 | { |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2455 | int err; |
| 2456 | int ret; |
| 2457 | |
| 2458 | /* |
| 2459 | * If any of the steps fail just try to continue, that's the best we |
| 2460 | * can do at this point. Return the first error code (which will also |
| 2461 | * leave RPM permanently disabled). |
| 2462 | */ |
| 2463 | ret = vlv_force_gfx_clock(dev_priv, true); |
| 2464 | |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 2465 | vlv_restore_gunit_s0ix_state(dev_priv); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2466 | |
| 2467 | err = vlv_allow_gt_wake(dev_priv, true); |
| 2468 | if (!ret) |
| 2469 | ret = err; |
| 2470 | |
| 2471 | err = vlv_force_gfx_clock(dev_priv, false); |
| 2472 | if (!ret) |
| 2473 | ret = err; |
| 2474 | |
| 2475 | vlv_check_no_gt_access(dev_priv); |
| 2476 | |
Chris Wilson | 7c108fd | 2016-10-24 13:42:18 +0100 | [diff] [blame] | 2477 | if (rpm_resume) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 2478 | intel_init_clock_gating(dev_priv); |
Imre Deak | ddeea5b | 2014-05-05 15:19:56 +0300 | [diff] [blame] | 2479 | |
| 2480 | return ret; |
| 2481 | } |
| 2482 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2483 | static int intel_runtime_suspend(struct device *kdev) |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2484 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2485 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Daniele Ceraolo Spurio | 1bf676c | 2019-06-13 16:21:52 -0700 | [diff] [blame] | 2486 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 2487 | int ret = 0; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2488 | |
Tvrtko Ursulin | 6772ffe | 2016-10-13 11:02:55 +0100 | [diff] [blame] | 2489 | if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev_priv))) |
Imre Deak | 604effb | 2014-08-26 13:26:56 +0300 | [diff] [blame] | 2490 | return -ENODEV; |
| 2491 | |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2492 | DRM_DEBUG_KMS("Suspending device\n"); |
| 2493 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2494 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2495 | |
Imre Deak | d610297 | 2014-05-07 19:57:49 +0300 | [diff] [blame] | 2496 | /* |
| 2497 | * We are safe here against re-faults, since the fault handler takes |
| 2498 | * an RPM reference. |
| 2499 | */ |
Chris Wilson | 7c108fd | 2016-10-24 13:42:18 +0100 | [diff] [blame] | 2500 | i915_gem_runtime_suspend(dev_priv); |
Imre Deak | d610297 | 2014-05-07 19:57:49 +0300 | [diff] [blame] | 2501 | |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 2502 | intel_gt_runtime_suspend(&dev_priv->gt); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 2503 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 2504 | intel_runtime_pm_disable_interrupts(dev_priv); |
Imre Deak | b5478bc | 2014-04-14 20:24:37 +0300 | [diff] [blame] | 2505 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 2506 | intel_uncore_suspend(&dev_priv->uncore); |
Hans de Goede | 01c799c | 2017-11-14 14:55:18 +0100 | [diff] [blame] | 2507 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 2508 | intel_display_power_suspend(dev_priv); |
| 2509 | |
| 2510 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Imre Deak | 507e126 | 2016-04-20 20:27:54 +0300 | [diff] [blame] | 2511 | ret = vlv_suspend_complete(dev_priv); |
Imre Deak | 507e126 | 2016-04-20 20:27:54 +0300 | [diff] [blame] | 2512 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 2513 | if (ret) { |
| 2514 | DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret); |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 2515 | intel_uncore_runtime_resume(&dev_priv->uncore); |
Hans de Goede | 01c799c | 2017-11-14 14:55:18 +0100 | [diff] [blame] | 2516 | |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 2517 | intel_runtime_pm_enable_interrupts(dev_priv); |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 2518 | |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 2519 | intel_gt_runtime_resume(&dev_priv->gt); |
Sagar Arun Kamble | 1ed21cb | 2018-01-24 21:16:57 +0530 | [diff] [blame] | 2520 | |
Chris Wilson | e9d4c92 | 2019-10-16 15:32:33 +0100 | [diff] [blame] | 2521 | i915_gem_restore_fences(&dev_priv->ggtt); |
Sagar Arun Kamble | 1ed21cb | 2018-01-24 21:16:57 +0530 | [diff] [blame] | 2522 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2523 | enable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2524 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 2525 | return ret; |
| 2526 | } |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 2527 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2528 | enable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 2529 | intel_runtime_pm_driver_release(rpm); |
Mika Kuoppala | 55ec45c | 2015-12-15 16:25:08 +0200 | [diff] [blame] | 2530 | |
Daniele Ceraolo Spurio | 2cf7bf6 | 2019-03-25 14:49:34 -0700 | [diff] [blame] | 2531 | if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore)) |
Mika Kuoppala | 55ec45c | 2015-12-15 16:25:08 +0200 | [diff] [blame] | 2532 | DRM_ERROR("Unclaimed access detected prior to suspending\n"); |
| 2533 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2534 | rpm->suspended = true; |
Kristen Carlson Accardi | 1fb2362 | 2014-01-14 15:36:15 -0800 | [diff] [blame] | 2535 | |
| 2536 | /* |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 2537 | * FIXME: We really should find a document that references the arguments |
| 2538 | * used below! |
Kristen Carlson Accardi | 1fb2362 | 2014-01-14 15:36:15 -0800 | [diff] [blame] | 2539 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 2540 | if (IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d37ae19 | 2015-07-30 18:20:29 -0300 | [diff] [blame] | 2541 | /* |
| 2542 | * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop |
| 2543 | * being detected, and the call we do at intel_runtime_resume() |
| 2544 | * won't be able to restore them. Since PCI_D3hot matches the |
| 2545 | * actual specification and appears to be working, use it. |
| 2546 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 2547 | intel_opregion_notify_adapter(dev_priv, PCI_D3hot); |
Paulo Zanoni | d37ae19 | 2015-07-30 18:20:29 -0300 | [diff] [blame] | 2548 | } else { |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 2549 | /* |
| 2550 | * current versions of firmware which depend on this opregion |
| 2551 | * notification have repurposed the D1 definition to mean |
| 2552 | * "runtime suspended" vs. what you would normally expect (D3) |
| 2553 | * to distinguish it from notifications that might be sent via |
| 2554 | * the suspend path. |
| 2555 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 2556 | intel_opregion_notify_adapter(dev_priv, PCI_D1); |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 2557 | } |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2558 | |
Daniele Ceraolo Spurio | f568eee | 2019-03-19 11:35:35 -0700 | [diff] [blame] | 2559 | assert_forcewakes_inactive(&dev_priv->uncore); |
Chris Wilson | dc9fb09 | 2015-01-16 11:34:34 +0200 | [diff] [blame] | 2560 | |
Ander Conselvan de Oliveira | 21d6e0b | 2017-01-20 16:28:43 +0200 | [diff] [blame] | 2561 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 2562 | intel_hpd_poll_init(dev_priv); |
| 2563 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 2564 | DRM_DEBUG_KMS("Device suspended\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2565 | return 0; |
| 2566 | } |
| 2567 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 2568 | static int intel_runtime_resume(struct device *kdev) |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2569 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 2570 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Daniele Ceraolo Spurio | 1bf676c | 2019-06-13 16:21:52 -0700 | [diff] [blame] | 2571 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Paulo Zanoni | 1a5df18 | 2014-10-27 17:54:32 -0200 | [diff] [blame] | 2572 | int ret = 0; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2573 | |
Tvrtko Ursulin | 6772ffe | 2016-10-13 11:02:55 +0100 | [diff] [blame] | 2574 | if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev_priv))) |
Imre Deak | 604effb | 2014-08-26 13:26:56 +0300 | [diff] [blame] | 2575 | return -ENODEV; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2576 | |
| 2577 | DRM_DEBUG_KMS("Resuming device\n"); |
| 2578 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2579 | WARN_ON_ONCE(atomic_read(&rpm->wakeref_count)); |
| 2580 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2581 | |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 2582 | intel_opregion_notify_adapter(dev_priv, PCI_D0); |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2583 | rpm->suspended = false; |
Daniele Ceraolo Spurio | 2cf7bf6 | 2019-03-25 14:49:34 -0700 | [diff] [blame] | 2584 | if (intel_uncore_unclaimed_mmio(&dev_priv->uncore)) |
Mika Kuoppala | 55ec45c | 2015-12-15 16:25:08 +0200 | [diff] [blame] | 2585 | DRM_DEBUG_DRIVER("Unclaimed access during suspend, bios?\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2586 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 2587 | intel_display_power_resume(dev_priv); |
| 2588 | |
| 2589 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Paulo Zanoni | 1a5df18 | 2014-10-27 17:54:32 -0200 | [diff] [blame] | 2590 | ret = vlv_resume_prepare(dev_priv, true); |
| 2591 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 2592 | intel_uncore_runtime_resume(&dev_priv->uncore); |
Hans de Goede | bedf4d7 | 2017-11-14 14:55:17 +0100 | [diff] [blame] | 2593 | |
Sagar Arun Kamble | 1ed21cb | 2018-01-24 21:16:57 +0530 | [diff] [blame] | 2594 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 2595 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 2596 | /* |
| 2597 | * No point of rolling back things in case of an error, as the best |
| 2598 | * we can do is to hope that things will still work (and disable RPM). |
| 2599 | */ |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 2600 | intel_gt_runtime_resume(&dev_priv->gt); |
Chris Wilson | e9d4c92 | 2019-10-16 15:32:33 +0100 | [diff] [blame] | 2601 | i915_gem_restore_fences(&dev_priv->ggtt); |
Imre Deak | 92b806d | 2014-04-14 20:24:39 +0300 | [diff] [blame] | 2602 | |
Ville Syrjälä | 08d8a23 | 2015-08-27 23:56:08 +0300 | [diff] [blame] | 2603 | /* |
| 2604 | * On VLV/CHV display interrupts are part of the display |
| 2605 | * power well, so hpd is reinitialized from there. For |
| 2606 | * everyone else do it here. |
| 2607 | */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2608 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 08d8a23 | 2015-08-27 23:56:08 +0300 | [diff] [blame] | 2609 | intel_hpd_init(dev_priv); |
| 2610 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 2611 | intel_enable_ipc(dev_priv); |
| 2612 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 2613 | enable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 2614 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 2615 | if (ret) |
| 2616 | DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret); |
| 2617 | else |
| 2618 | DRM_DEBUG_KMS("Device resumed\n"); |
| 2619 | |
| 2620 | return ret; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 2621 | } |
| 2622 | |
Chris Wilson | 42f5551 | 2016-06-24 14:00:26 +0100 | [diff] [blame] | 2623 | const struct dev_pm_ops i915_pm_ops = { |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 2624 | /* |
| 2625 | * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND, |
| 2626 | * PMSG_RESUME] |
| 2627 | */ |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 2628 | .prepare = i915_pm_prepare, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2629 | .suspend = i915_pm_suspend, |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 2630 | .suspend_late = i915_pm_suspend_late, |
| 2631 | .resume_early = i915_pm_resume_early, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2632 | .resume = i915_pm_resume, |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 2633 | |
| 2634 | /* |
| 2635 | * S4 event handlers |
| 2636 | * @freeze, @freeze_late : called (1) before creating the |
| 2637 | * hibernation image [PMSG_FREEZE] and |
| 2638 | * (2) after rebooting, before restoring |
| 2639 | * the image [PMSG_QUIESCE] |
| 2640 | * @thaw, @thaw_early : called (1) after creating the hibernation |
| 2641 | * image, before writing it [PMSG_THAW] |
| 2642 | * and (2) after failing to create or |
| 2643 | * restore the image [PMSG_RECOVER] |
| 2644 | * @poweroff, @poweroff_late: called after writing the hibernation |
| 2645 | * image, before rebooting [PMSG_HIBERNATE] |
| 2646 | * @restore, @restore_early : called after rebooting and restoring the |
| 2647 | * hibernation image [PMSG_RESTORE] |
| 2648 | */ |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2649 | .freeze = i915_pm_freeze, |
| 2650 | .freeze_late = i915_pm_freeze_late, |
| 2651 | .thaw_early = i915_pm_thaw_early, |
| 2652 | .thaw = i915_pm_thaw, |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 2653 | .poweroff = i915_pm_suspend, |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 2654 | .poweroff_late = i915_pm_poweroff_late, |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 2655 | .restore_early = i915_pm_restore_early, |
| 2656 | .restore = i915_pm_restore, |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 2657 | |
| 2658 | /* S0ix (via runtime suspend) event handlers */ |
Paulo Zanoni | 97bea20 | 2014-03-07 20:12:33 -0300 | [diff] [blame] | 2659 | .runtime_suspend = intel_runtime_suspend, |
| 2660 | .runtime_resume = intel_runtime_resume, |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 2661 | }; |
| 2662 | |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2663 | static const struct file_operations i915_driver_fops = { |
| 2664 | .owner = THIS_MODULE, |
| 2665 | .open = drm_open, |
Chris Wilson | 7a2c65dd | 2020-01-24 12:56:26 +0000 | [diff] [blame^] | 2666 | .release = drm_release_noglobal, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2667 | .unlocked_ioctl = drm_ioctl, |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 2668 | .mmap = i915_gem_mmap, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2669 | .poll = drm_poll, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2670 | .read = drm_read, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2671 | .compat_ioctl = i915_compat_ioctl, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2672 | .llseek = noop_llseek, |
| 2673 | }; |
| 2674 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2675 | static int |
| 2676 | i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data, |
| 2677 | struct drm_file *file) |
| 2678 | { |
| 2679 | return -ENODEV; |
| 2680 | } |
| 2681 | |
| 2682 | static const struct drm_ioctl_desc i915_ioctls[] = { |
| 2683 | DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2684 | DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH), |
| 2685 | DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH), |
| 2686 | DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH), |
| 2687 | DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH), |
| 2688 | DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 2689 | DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2690 | DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2691 | DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH), |
| 2692 | DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH), |
| 2693 | DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2694 | DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH), |
| 2695 | DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2696 | DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2697 | DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH), |
| 2698 | DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH), |
| 2699 | DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2700 | DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 2701 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer_ioctl, DRM_AUTH), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 2702 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR, i915_gem_execbuffer2_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2703 | DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 2704 | DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 2705 | DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2706 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW), |
| 2707 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 2708 | DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2709 | DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2710 | DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 2711 | DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW), |
| 2712 | DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW), |
| 2713 | DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW), |
| 2714 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW), |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 2715 | DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_OFFSET, i915_gem_mmap_offset_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2716 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW), |
| 2717 | DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 111dbca | 2017-01-10 12:10:44 +0000 | [diff] [blame] | 2718 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW), |
| 2719 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2720 | DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW), |
Ville Syrjälä | 6a20fe7 | 2018-02-07 18:48:41 +0200 | [diff] [blame] | 2721 | DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id_ioctl, 0), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2722 | DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW), |
Daniel Vetter | 0cd54b0 | 2018-04-20 08:51:57 +0200 | [diff] [blame] | 2723 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER), |
| 2724 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER), |
| 2725 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER), |
| 2726 | DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 2727 | DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | b917154 | 2019-03-22 09:23:24 +0000 | [diff] [blame] | 2728 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE_EXT, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2729 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW), |
| 2730 | DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW), |
| 2731 | DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW), |
| 2732 | DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW), |
| 2733 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW), |
| 2734 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW), |
Robert Bragg | eec688e | 2016-11-07 19:49:47 +0000 | [diff] [blame] | 2735 | DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW), |
Emil Velikov | b4023756 | 2019-05-22 16:47:01 +0100 | [diff] [blame] | 2736 | DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW), |
| 2737 | DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW), |
| 2738 | DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 7f3f317a | 2019-05-21 22:11:25 +0100 | [diff] [blame] | 2739 | DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW), |
| 2740 | DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2741 | }; |
| 2742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | static struct drm_driver driver = { |
Michael Witten | 0c54781 | 2011-08-25 17:55:54 +0000 | [diff] [blame] | 2744 | /* Don't use MTRRs here; the Xserver or userspace app should |
| 2745 | * deal with them for Intel hardware. |
Dave Airlie | 792d2b9 | 2005-11-11 23:30:27 +1100 | [diff] [blame] | 2746 | */ |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2747 | .driver_features = |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 2748 | DRIVER_GEM | |
Jason Ekstrand | cf6e7ba | 2017-08-15 15:57:33 +0100 | [diff] [blame] | 2749 | DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ, |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 2750 | .release = i915_driver_release, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2751 | .open = i915_driver_open, |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2752 | .lastclose = i915_driver_lastclose, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 2753 | .postclose = i915_driver_postclose, |
Rafael J. Wysocki | d8e2920 | 2010-01-09 00:45:33 +0100 | [diff] [blame] | 2754 | |
Chris Wilson | b1f788c | 2016-08-04 07:52:45 +0100 | [diff] [blame] | 2755 | .gem_close_object = i915_gem_close_object, |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 2756 | .gem_free_object_unlocked = i915_gem_free_object, |
Daniel Vetter | 1286ff7 | 2012-05-10 15:25:09 +0200 | [diff] [blame] | 2757 | |
| 2758 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 2759 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 2760 | .gem_prime_export = i915_gem_prime_export, |
| 2761 | .gem_prime_import = i915_gem_prime_import, |
| 2762 | |
Ville Syrjälä | 7d23e59 | 2019-06-19 20:08:42 +0300 | [diff] [blame] | 2763 | .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos, |
| 2764 | .get_scanout_position = i915_get_crtc_scanoutpos, |
| 2765 | |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 2766 | .dumb_create = i915_gem_dumb_create, |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 2767 | .dumb_map_offset = i915_gem_dumb_mmap_offset, |
| 2768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | .ioctls = i915_ioctls, |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 2770 | .num_ioctls = ARRAY_SIZE(i915_ioctls), |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 2771 | .fops = &i915_driver_fops, |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 2772 | .name = DRIVER_NAME, |
| 2773 | .desc = DRIVER_DESC, |
| 2774 | .date = DRIVER_DATE, |
| 2775 | .major = DRIVER_MAJOR, |
| 2776 | .minor = DRIVER_MINOR, |
| 2777 | .patchlevel = DRIVER_PATCHLEVEL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | }; |