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> |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 41 | |
Thomas Zimmermann | 6848c29 | 2021-04-12 15:10:42 +0200 | [diff] [blame] | 42 | #include <drm/drm_aperture.h> |
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> |
Daniel Vetter | 7fb81e9 | 2020-03-23 15:49:07 +0100 | [diff] [blame] | 46 | #include <drm/drm_managed.h> |
Sam Ravnborg | d0e9359 | 2019-01-26 13:25:24 +0100 | [diff] [blame] | 47 | #include <drm/drm_probe_helper.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" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 50 | #include "display/intel_bw.h" |
| 51 | #include "display/intel_cdclk.h" |
Anusha Srivatsa | 32f9402 | 2021-05-18 14:34:44 -0700 | [diff] [blame] | 52 | #include "display/intel_dmc.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" |
Jani Nikula | 0bf1e5a | 2021-01-20 12:18:32 +0200 | [diff] [blame] | 59 | #include "display/intel_pps.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 60 | #include "display/intel_sprite.h" |
Jani Nikula | 4fb8783 | 2019-10-01 18:25:06 +0300 | [diff] [blame] | 61 | #include "display/intel_vga.h" |
Jani Nikula | 379bc10 | 2019-06-13 11:44:15 +0300 | [diff] [blame] | 62 | |
Chris Wilson | 10be98a | 2019-05-28 10:29:49 +0100 | [diff] [blame] | 63 | #include "gem/i915_gem_context.h" |
Chris Wilson | afa1308 | 2019-05-28 10:29:43 +0100 | [diff] [blame] | 64 | #include "gem/i915_gem_ioctls.h" |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 65 | #include "gem/i915_gem_mman.h" |
Chris Wilson | 29d8808 | 2021-01-23 14:55:43 +0000 | [diff] [blame] | 66 | #include "gem/i915_gem_pm.h" |
Tvrtko Ursulin | 24635c5 | 2019-06-21 08:07:41 +0100 | [diff] [blame] | 67 | #include "gt/intel_gt.h" |
Chris Wilson | 79ffac85 | 2019-04-24 21:07:17 +0100 | [diff] [blame] | 68 | #include "gt/intel_gt_pm.h" |
Imre Deak | 2248a28 | 2019-10-17 16:38:31 +0300 | [diff] [blame] | 69 | #include "gt/intel_rc6.h" |
Chris Wilson | 112ed2d | 2019-04-24 18:48:39 +0100 | [diff] [blame] | 70 | |
Jani Nikula | 2126d3e | 2019-05-02 18:02:43 +0300 | [diff] [blame] | 71 | #include "i915_debugfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include "i915_drv.h" |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 73 | #include "i915_ioc32.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 74 | #include "i915_irq.h" |
Jani Nikula | 9c9082b | 2019-08-08 16:42:47 +0300 | [diff] [blame] | 75 | #include "i915_memcpy.h" |
Jani Nikula | db94e9f | 2019-08-08 16:42:44 +0300 | [diff] [blame] | 76 | #include "i915_perf.h" |
Lionel Landwerlin | a446ae2 | 2018-03-06 12:28:56 +0000 | [diff] [blame] | 77 | #include "i915_query.h" |
Jani Nikula | bdd1510 | 2019-08-08 16:42:46 +0300 | [diff] [blame] | 78 | #include "i915_suspend.h" |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 79 | #include "i915_switcheroo.h" |
Jani Nikula | be68261 | 2019-08-08 16:42:45 +0300 | [diff] [blame] | 80 | #include "i915_sysfs.h" |
Jani Nikula | 331c201 | 2019-04-05 14:00:03 +0300 | [diff] [blame] | 81 | #include "i915_trace.h" |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 82 | #include "i915_vgpu.h" |
Jani Nikula | d28ae3b | 2020-02-25 13:15:07 +0200 | [diff] [blame] | 83 | #include "intel_dram.h" |
Jani Nikula | 6e482b9 | 2020-02-27 16:44:08 +0200 | [diff] [blame] | 84 | #include "intel_gvt.h" |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 85 | #include "intel_memory_region.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 86 | #include "intel_pm.h" |
Matt Roper | f9c730ed | 2020-09-30 23:39:17 -0700 | [diff] [blame] | 87 | #include "intel_sideband.h" |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 88 | #include "vlv_suspend.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Daniel Vetter | 70a59dd | 2020-11-04 11:04:24 +0100 | [diff] [blame] | 90 | static const struct drm_driver driver; |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 91 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 92 | static int i915_get_bridge_dev(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 93 | { |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 94 | int domain = pci_domain_nr(to_pci_dev(dev_priv->drm.dev)->bus); |
Sinan Kaya | 57b29646 | 2017-11-27 11:57:46 -0500 | [diff] [blame] | 95 | |
| 96 | dev_priv->bridge_dev = |
| 97 | pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 0)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 98 | if (!dev_priv->bridge_dev) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 99 | drm_err(&dev_priv->drm, "bridge device not found\n"); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 100 | return -1; |
| 101 | } |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | /* Allocate space for the MCH regs if needed, return nonzero on error */ |
| 106 | static int |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 107 | intel_alloc_mchbar_resource(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 108 | { |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 109 | int reg = GRAPHICS_VER(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 110 | u32 temp_lo, temp_hi = 0; |
| 111 | u64 mchbar_addr; |
| 112 | int ret; |
| 113 | |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 114 | if (GRAPHICS_VER(dev_priv) >= 4) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 115 | pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); |
| 116 | pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); |
| 117 | mchbar_addr = ((u64)temp_hi << 32) | temp_lo; |
| 118 | |
| 119 | /* If ACPI doesn't have it, assume we need to allocate it ourselves */ |
| 120 | #ifdef CONFIG_PNP |
| 121 | if (mchbar_addr && |
| 122 | pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) |
| 123 | return 0; |
| 124 | #endif |
| 125 | |
| 126 | /* Get some space for it */ |
| 127 | dev_priv->mch_res.name = "i915 MCHBAR"; |
| 128 | dev_priv->mch_res.flags = IORESOURCE_MEM; |
| 129 | ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, |
| 130 | &dev_priv->mch_res, |
| 131 | MCHBAR_SIZE, MCHBAR_SIZE, |
| 132 | PCIBIOS_MIN_MEM, |
| 133 | 0, pcibios_align_resource, |
| 134 | dev_priv->bridge_dev); |
| 135 | if (ret) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 136 | drm_dbg(&dev_priv->drm, "failed bus alloc: %d\n", ret); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 137 | dev_priv->mch_res.start = 0; |
| 138 | return ret; |
| 139 | } |
| 140 | |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 141 | if (GRAPHICS_VER(dev_priv) >= 4) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 142 | pci_write_config_dword(dev_priv->bridge_dev, reg + 4, |
| 143 | upper_32_bits(dev_priv->mch_res.start)); |
| 144 | |
| 145 | pci_write_config_dword(dev_priv->bridge_dev, reg, |
| 146 | lower_32_bits(dev_priv->mch_res.start)); |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* Setup MCHBAR if possible, return true if we should disable it again */ |
| 151 | static void |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 152 | intel_setup_mchbar(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 153 | { |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 154 | int mchbar_reg = GRAPHICS_VER(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 155 | u32 temp; |
| 156 | bool enabled; |
| 157 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 158 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 159 | return; |
| 160 | |
| 161 | dev_priv->mchbar_need_disable = false; |
| 162 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 163 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 164 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp); |
| 165 | enabled = !!(temp & DEVEN_MCHBAR_EN); |
| 166 | } else { |
| 167 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 168 | enabled = temp & 1; |
| 169 | } |
| 170 | |
| 171 | /* If it's already enabled, don't have to do anything */ |
| 172 | if (enabled) |
| 173 | return; |
| 174 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 175 | if (intel_alloc_mchbar_resource(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 176 | return; |
| 177 | |
| 178 | dev_priv->mchbar_need_disable = true; |
| 179 | |
| 180 | /* Space is allocated or reserved, so enable it. */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 181 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 182 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN, |
| 183 | temp | DEVEN_MCHBAR_EN); |
| 184 | } else { |
| 185 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); |
| 186 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | static void |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 191 | intel_teardown_mchbar(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 192 | { |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 193 | int mchbar_reg = GRAPHICS_VER(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 194 | |
| 195 | if (dev_priv->mchbar_need_disable) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 196 | if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 197 | u32 deven_val; |
| 198 | |
| 199 | pci_read_config_dword(dev_priv->bridge_dev, DEVEN, |
| 200 | &deven_val); |
| 201 | deven_val &= ~DEVEN_MCHBAR_EN; |
| 202 | pci_write_config_dword(dev_priv->bridge_dev, DEVEN, |
| 203 | deven_val); |
| 204 | } else { |
| 205 | u32 mchbar_val; |
| 206 | |
| 207 | pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, |
| 208 | &mchbar_val); |
| 209 | mchbar_val &= ~1; |
| 210 | pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, |
| 211 | mchbar_val); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if (dev_priv->mch_res.start) |
| 216 | release_resource(&dev_priv->mch_res); |
| 217 | } |
| 218 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 219 | static int i915_workqueues_init(struct drm_i915_private *dev_priv) |
| 220 | { |
| 221 | /* |
| 222 | * The i915 workqueue is primarily used for batched retirement of |
| 223 | * requests (and thus managing bo) once the task has been completed |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 224 | * by the GPU. i915_retire_requests() is called directly when we |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 225 | * need high-priority retirement, such as waiting for an explicit |
| 226 | * bo. |
| 227 | * |
| 228 | * It is also used for periodic low-priority events, such as |
| 229 | * idle-timers and recording error state. |
| 230 | * |
| 231 | * All tasks on the workqueue are expected to acquire the dev mutex |
| 232 | * so there is no point in running more than one instance of the |
| 233 | * workqueue at any time. Use an ordered one. |
| 234 | */ |
| 235 | dev_priv->wq = alloc_ordered_workqueue("i915", 0); |
| 236 | if (dev_priv->wq == NULL) |
| 237 | goto out_err; |
| 238 | |
| 239 | dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0); |
| 240 | if (dev_priv->hotplug.dp_wq == NULL) |
| 241 | goto out_free_wq; |
| 242 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 243 | return 0; |
| 244 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 245 | out_free_wq: |
| 246 | destroy_workqueue(dev_priv->wq); |
| 247 | out_err: |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 248 | drm_err(&dev_priv->drm, "Failed to allocate workqueues.\n"); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 249 | |
| 250 | return -ENOMEM; |
| 251 | } |
| 252 | |
| 253 | static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv) |
| 254 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 255 | destroy_workqueue(dev_priv->hotplug.dp_wq); |
| 256 | destroy_workqueue(dev_priv->wq); |
| 257 | } |
| 258 | |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 259 | /* |
| 260 | * We don't keep the workarounds for pre-production hardware, so we expect our |
| 261 | * driver to fail on these machines in one way or another. A little warning on |
| 262 | * dmesg may help both the user and the bug triagers. |
Chris Wilson | 6a7a6a9 | 2017-11-17 10:26:35 +0000 | [diff] [blame] | 263 | * |
| 264 | * Our policy for removing pre-production workarounds is to keep the |
| 265 | * current gen workarounds as a guide to the bring-up of the next gen |
| 266 | * (workarounds have a habit of persisting!). Anything older than that |
| 267 | * should be removed along with the complications they introduce. |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 268 | */ |
| 269 | static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv) |
| 270 | { |
Chris Wilson | 248a124 | 2017-01-30 10:44:56 +0000 | [diff] [blame] | 271 | bool pre = false; |
| 272 | |
| 273 | pre |= IS_HSW_EARLY_SDV(dev_priv); |
| 274 | pre |= IS_SKL_REVID(dev_priv, 0, SKL_REVID_F0); |
Chris Wilson | 0102ba1 | 2017-01-30 10:44:58 +0000 | [diff] [blame] | 275 | pre |= IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST); |
Jani Nikula | ef47b7a | 2021-03-26 15:21:34 +0200 | [diff] [blame] | 276 | pre |= IS_KBL_GT_STEP(dev_priv, 0, STEP_A0); |
Ville Syrjälä | 834c6bb | 2020-01-28 17:51:52 +0200 | [diff] [blame] | 277 | pre |= IS_GLK_REVID(dev_priv, 0, GLK_REVID_A2); |
Chris Wilson | 248a124 | 2017-01-30 10:44:56 +0000 | [diff] [blame] | 278 | |
Chris Wilson | 7c5ff4a | 2017-01-30 10:44:57 +0000 | [diff] [blame] | 279 | if (pre) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 280 | drm_err(&dev_priv->drm, "This is a pre-production stepping. " |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 281 | "It may not be fully functional.\n"); |
Chris Wilson | 7c5ff4a | 2017-01-30 10:44:57 +0000 | [diff] [blame] | 282 | add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK); |
| 283 | } |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 284 | } |
| 285 | |
Chris Wilson | 640b50f | 2019-12-28 11:12:55 +0000 | [diff] [blame] | 286 | static void sanitize_gpu(struct drm_i915_private *i915) |
| 287 | { |
| 288 | if (!INTEL_INFO(i915)->gpu_reset_clobbers_display) |
| 289 | __intel_gt_reset(&i915->gt, ALL_ENGINES); |
| 290 | } |
| 291 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 292 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 293 | * i915_driver_early_probe - setup state not requiring device access |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 294 | * @dev_priv: device private |
| 295 | * |
| 296 | * Initialize everything that is a "SW-only" state, that is state not |
| 297 | * requiring accessing the device or exposing the driver via kernel internal |
| 298 | * or userspace interfaces. Example steps belonging here: lock initialization, |
| 299 | * system memory allocation, setting up device specific attributes and |
| 300 | * function hooks not requiring accessing the device. |
| 301 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 302 | static int i915_driver_early_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 303 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 304 | int ret = 0; |
| 305 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 306 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 307 | return -ENODEV; |
| 308 | |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 309 | intel_device_info_subplatform_init(dev_priv); |
Jani Nikula | ef47b7a | 2021-03-26 15:21:34 +0200 | [diff] [blame] | 310 | intel_step_init(dev_priv); |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 311 | |
Daniele Ceraolo Spurio | 0a9b263 | 2019-08-09 07:31:16 +0100 | [diff] [blame] | 312 | intel_uncore_mmio_debug_init_early(&dev_priv->mmio_debug); |
Daniele Ceraolo Spurio | 0138575 | 2019-06-19 18:00:18 -0700 | [diff] [blame] | 313 | intel_uncore_init_early(&dev_priv->uncore, dev_priv); |
Daniele Ceraolo Spurio | 6cbe8830 | 2019-04-02 13:10:31 -0700 | [diff] [blame] | 314 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 315 | spin_lock_init(&dev_priv->irq_lock); |
| 316 | spin_lock_init(&dev_priv->gpu_error.lock); |
| 317 | mutex_init(&dev_priv->backlight_lock); |
Lyude | 317eaa9 | 2017-02-03 21:18:25 -0500 | [diff] [blame] | 318 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 319 | mutex_init(&dev_priv->sb_lock); |
Rafael J. Wysocki | 4d4dda4 | 2020-02-12 00:12:10 +0100 | [diff] [blame] | 320 | cpu_latency_qos_add_request(&dev_priv->sb_qos, PM_QOS_DEFAULT_VALUE); |
Chris Wilson | a75d035 | 2019-04-26 09:17:18 +0100 | [diff] [blame] | 321 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 322 | mutex_init(&dev_priv->av_mutex); |
| 323 | mutex_init(&dev_priv->wm.wm_mutex); |
| 324 | mutex_init(&dev_priv->pps_mutex); |
Ramalingam C | 9055aac | 2019-02-16 23:06:51 +0530 | [diff] [blame] | 325 | mutex_init(&dev_priv->hdcp_comp_mutex); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 326 | |
Chris Wilson | 0b1de5d | 2016-08-12 12:39:59 +0100 | [diff] [blame] | 327 | i915_memcpy_init_early(dev_priv); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 328 | intel_runtime_pm_init_early(&dev_priv->runtime_pm); |
Chris Wilson | 0b1de5d | 2016-08-12 12:39:59 +0100 | [diff] [blame] | 329 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 330 | ret = i915_workqueues_init(dev_priv); |
| 331 | if (ret < 0) |
Chris Wilson | f3bcb0c | 2019-07-18 08:00:10 +0100 | [diff] [blame] | 332 | return ret; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 333 | |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 334 | ret = vlv_suspend_init(dev_priv); |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 335 | if (ret < 0) |
| 336 | goto err_workqueues; |
| 337 | |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 338 | intel_wopcm_init_early(&dev_priv->wopcm); |
| 339 | |
Tvrtko Ursulin | 724e956 | 2019-06-21 08:07:42 +0100 | [diff] [blame] | 340 | intel_gt_init_early(&dev_priv->gt, dev_priv); |
Tvrtko Ursulin | 24635c5 | 2019-06-21 08:07:41 +0100 | [diff] [blame] | 341 | |
Matthew Auld | a3f356b | 2019-09-27 18:33:49 +0100 | [diff] [blame] | 342 | i915_gem_init_early(dev_priv); |
Michal Wajdeczko | a0de908 | 2018-03-23 12:34:49 +0000 | [diff] [blame] | 343 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 344 | /* This must be called before any calls to HAS_PCH_* */ |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 345 | intel_detect_pch(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 346 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 347 | intel_pm_setup(dev_priv); |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 348 | ret = intel_power_domains_init(dev_priv); |
| 349 | if (ret < 0) |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 350 | goto err_gem; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 351 | intel_irq_init(dev_priv); |
| 352 | intel_init_display_hooks(dev_priv); |
| 353 | intel_init_clock_gating_hooks(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 354 | |
Paulo Zanoni | 4fc7e84 | 2016-09-26 15:07:52 +0300 | [diff] [blame] | 355 | intel_detect_preproduction_hw(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 356 | |
| 357 | return 0; |
| 358 | |
Daniele Ceraolo Spurio | 6f76098 | 2019-07-31 17:57:08 -0700 | [diff] [blame] | 359 | err_gem: |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 360 | i915_gem_cleanup_early(dev_priv); |
Daniele Ceraolo Spurio | 6cf72db | 2019-07-31 17:57:07 -0700 | [diff] [blame] | 361 | intel_gt_driver_late_release(&dev_priv->gt); |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 362 | vlv_suspend_cleanup(dev_priv); |
Daniele Ceraolo Spurio | 1bcd868 | 2019-08-19 19:01:46 -0700 | [diff] [blame] | 363 | err_workqueues: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 364 | i915_workqueues_cleanup(dev_priv); |
| 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | /** |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 369 | * i915_driver_late_release - cleanup the setup done in |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 370 | * i915_driver_early_probe() |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 371 | * @dev_priv: device private |
| 372 | */ |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 373 | static void i915_driver_late_release(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 374 | { |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame] | 375 | intel_irq_fini(dev_priv); |
Imre Deak | f28ec6f | 2018-08-06 12:58:37 +0300 | [diff] [blame] | 376 | intel_power_domains_cleanup(dev_priv); |
Michal Wajdeczko | a0de908 | 2018-03-23 12:34:49 +0000 | [diff] [blame] | 377 | i915_gem_cleanup_early(dev_priv); |
Daniele Ceraolo Spurio | 6cf72db | 2019-07-31 17:57:07 -0700 | [diff] [blame] | 378 | intel_gt_driver_late_release(&dev_priv->gt); |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 379 | vlv_suspend_cleanup(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 380 | i915_workqueues_cleanup(dev_priv); |
Chris Wilson | a75d035 | 2019-04-26 09:17:18 +0100 | [diff] [blame] | 381 | |
Rafael J. Wysocki | 4d4dda4 | 2020-02-12 00:12:10 +0100 | [diff] [blame] | 382 | cpu_latency_qos_remove_request(&dev_priv->sb_qos); |
Chris Wilson | a75d035 | 2019-04-26 09:17:18 +0100 | [diff] [blame] | 383 | mutex_destroy(&dev_priv->sb_lock); |
Jani Nikula | 8a25c4b | 2020-06-18 18:04:02 +0300 | [diff] [blame] | 384 | |
| 385 | i915_params_free(&dev_priv->params); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 388 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 389 | * i915_driver_mmio_probe - setup device MMIO |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 390 | * @dev_priv: device private |
| 391 | * |
| 392 | * Setup minimal device state necessary for MMIO accesses later in the |
| 393 | * initialization sequence. The setup here should avoid any other device-wide |
| 394 | * side effects or exposing the driver via kernel internal or user space |
| 395 | * interfaces. |
| 396 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 397 | static int i915_driver_mmio_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 398 | { |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 399 | int ret; |
| 400 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 401 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 402 | return -ENODEV; |
| 403 | |
Tvrtko Ursulin | da5f53b | 2016-12-01 14:16:40 +0000 | [diff] [blame] | 404 | if (i915_get_bridge_dev(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 405 | return -EIO; |
| 406 | |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 407 | ret = intel_uncore_init_mmio(&dev_priv->uncore); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 408 | if (ret < 0) |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 409 | goto err_bridge; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 410 | |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 411 | /* Try to make sure MCHBAR is enabled before poking at it */ |
| 412 | intel_setup_mchbar(dev_priv); |
Chris Wilson | c864e9a | 2021-01-04 11:51:41 +0000 | [diff] [blame] | 413 | intel_device_info_runtime_init(dev_priv); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 414 | |
Daniele Ceraolo Spurio | d0eb686 | 2020-07-07 17:39:48 -0700 | [diff] [blame] | 415 | ret = intel_gt_init_mmio(&dev_priv->gt); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 416 | if (ret) |
| 417 | goto err_uncore; |
| 418 | |
Chris Wilson | 640b50f | 2019-12-28 11:12:55 +0000 | [diff] [blame] | 419 | /* As early as possible, scrub existing GPU state before clobbering */ |
| 420 | sanitize_gpu(dev_priv); |
| 421 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 422 | return 0; |
| 423 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 424 | err_uncore: |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 425 | intel_teardown_mchbar(dev_priv); |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 426 | intel_uncore_fini_mmio(&dev_priv->uncore); |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 427 | err_bridge: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 428 | pci_dev_put(dev_priv->bridge_dev); |
| 429 | |
| 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 434 | * 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] | 435 | * @dev_priv: device private |
| 436 | */ |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 437 | static void i915_driver_mmio_release(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 438 | { |
Daniele Ceraolo Spurio | 25286aa | 2019-03-19 11:35:40 -0700 | [diff] [blame] | 439 | intel_teardown_mchbar(dev_priv); |
Daniele Ceraolo Spurio | 3de6f85 | 2019-04-02 13:10:32 -0700 | [diff] [blame] | 440 | intel_uncore_fini_mmio(&dev_priv->uncore); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 441 | pci_dev_put(dev_priv->bridge_dev); |
| 442 | } |
| 443 | |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 444 | static void intel_sanitize_options(struct drm_i915_private *dev_priv) |
| 445 | { |
Chuanxiao Dong | 67b7f33 | 2017-05-27 17:44:17 +0800 | [diff] [blame] | 446 | intel_gvt_sanitize_options(dev_priv); |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 449 | /** |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 450 | * i915_set_dma_info - set all relevant PCI dma info as configured for the |
| 451 | * platform |
| 452 | * @i915: valid i915 instance |
| 453 | * |
| 454 | * Set the dma max segment size, device and coherent masks. The dma mask set |
| 455 | * needs to occur before i915_ggtt_probe_hw. |
| 456 | * |
| 457 | * A couple of platforms have special needs. Address them as well. |
| 458 | * |
| 459 | */ |
| 460 | static int i915_set_dma_info(struct drm_i915_private *i915) |
| 461 | { |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 462 | unsigned int mask_size = INTEL_INFO(i915)->dma_mask_size; |
| 463 | int ret; |
| 464 | |
| 465 | GEM_BUG_ON(!mask_size); |
| 466 | |
| 467 | /* |
| 468 | * We don't have a max segment size, so set it to the max so sg's |
| 469 | * debugging layer doesn't complain |
| 470 | */ |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 471 | dma_set_max_seg_size(i915->drm.dev, UINT_MAX); |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 472 | |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 473 | ret = dma_set_mask(i915->drm.dev, DMA_BIT_MASK(mask_size)); |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 474 | if (ret) |
| 475 | goto mask_err; |
| 476 | |
| 477 | /* overlay on gen2 is broken and can't address above 1G */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 478 | if (GRAPHICS_VER(i915) == 2) |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 479 | mask_size = 30; |
| 480 | |
| 481 | /* |
| 482 | * 965GM sometimes incorrectly writes to hardware status page (HWS) |
| 483 | * using 32bit addressing, overwriting memory if HWS is located |
| 484 | * above 4GB. |
| 485 | * |
| 486 | * The documentation also mentions an issue with undefined |
| 487 | * behaviour if any general state is accessed within a page above 4GB, |
| 488 | * which also needs to be handled carefully. |
| 489 | */ |
| 490 | if (IS_I965G(i915) || IS_I965GM(i915)) |
| 491 | mask_size = 32; |
| 492 | |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 493 | ret = dma_set_coherent_mask(i915->drm.dev, DMA_BIT_MASK(mask_size)); |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 494 | if (ret) |
| 495 | goto mask_err; |
| 496 | |
| 497 | return 0; |
| 498 | |
| 499 | mask_err: |
| 500 | drm_err(&i915->drm, "Can't set DMA mask/consistent mask (%d)\n", ret); |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | /** |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 505 | * i915_driver_hw_probe - setup state requiring device access |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 506 | * @dev_priv: device private |
| 507 | * |
| 508 | * Setup state that requires accessing the device, but doesn't require |
| 509 | * exposing the driver via kernel internal or userspace interfaces. |
| 510 | */ |
Janusz Krzysztofik | 0b61b8b | 2019-07-12 13:24:30 +0200 | [diff] [blame] | 511 | static int i915_driver_hw_probe(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 512 | { |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 513 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 514 | int ret; |
| 515 | |
Michal Wajdeczko | 50d8441 | 2019-08-02 18:40:50 +0000 | [diff] [blame] | 516 | if (i915_inject_probe_failure(dev_priv)) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 517 | return -ENODEV; |
| 518 | |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 519 | if (HAS_PPGTT(dev_priv)) { |
| 520 | if (intel_vgpu_active(dev_priv) && |
Chris Wilson | ca6ac68 | 2019-03-14 22:38:35 +0000 | [diff] [blame] | 521 | !intel_vgpu_has_full_ppgtt(dev_priv)) { |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 522 | i915_report_error(dev_priv, |
| 523 | "incompatible vGPU found, support for isolated ppGTT required\n"); |
| 524 | return -ENXIO; |
| 525 | } |
| 526 | } |
| 527 | |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 528 | if (HAS_EXECLISTS(dev_priv)) { |
| 529 | /* |
| 530 | * Older GVT emulation depends upon intercepting CSB mmio, |
| 531 | * which we no longer use, preferring to use the HWSP cache |
| 532 | * instead. |
| 533 | */ |
| 534 | if (intel_vgpu_active(dev_priv) && |
| 535 | !intel_vgpu_has_hwsp_emulation(dev_priv)) { |
| 536 | i915_report_error(dev_priv, |
| 537 | "old vGPU host found, support for HWSP emulation required\n"); |
| 538 | return -ENXIO; |
| 539 | } |
| 540 | } |
| 541 | |
Chris Wilson | 94b4f3b | 2016-07-05 10:40:20 +0100 | [diff] [blame] | 542 | intel_sanitize_options(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 543 | |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 544 | /* needs to be done before ggtt probe */ |
Jani Nikula | d28ae3b | 2020-02-25 13:15:07 +0200 | [diff] [blame] | 545 | intel_dram_edram_detect(dev_priv); |
Daniele Ceraolo Spurio | f6ac993 | 2019-03-28 10:45:32 -0700 | [diff] [blame] | 546 | |
Michael J. Ruhl | 31a02eb | 2020-04-17 15:51:07 -0400 | [diff] [blame] | 547 | ret = i915_set_dma_info(dev_priv); |
| 548 | if (ret) |
| 549 | return ret; |
| 550 | |
Lionel Landwerlin | 9f9b279 | 2017-10-27 15:59:31 +0100 | [diff] [blame] | 551 | i915_perf_init(dev_priv); |
| 552 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 553 | ret = i915_ggtt_probe_hw(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 554 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 555 | goto err_perf; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 556 | |
Thomas Zimmermann | 6848c29 | 2021-04-12 15:10:42 +0200 | [diff] [blame] | 557 | ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, "inteldrmfb"); |
Gerd Hoffmann | f2521f7 | 2019-08-22 11:06:45 +0200 | [diff] [blame] | 558 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 559 | goto err_ggtt; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 560 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 561 | ret = i915_ggtt_init_hw(dev_priv); |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 562 | if (ret) |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 563 | goto err_ggtt; |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 564 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 565 | ret = intel_memory_regions_hw_probe(dev_priv); |
| 566 | if (ret) |
| 567 | goto err_ggtt; |
| 568 | |
Chris Wilson | 797a615 | 2019-11-01 14:10:06 +0000 | [diff] [blame] | 569 | intel_gt_init_hw_early(&dev_priv->gt, &dev_priv->ggtt); |
Tvrtko Ursulin | d8a4424 | 2019-06-21 08:08:06 +0100 | [diff] [blame] | 570 | |
Matthew Auld | 2dfcc7f | 2021-01-27 13:14:10 +0000 | [diff] [blame] | 571 | ret = intel_gt_probe_lmem(&dev_priv->gt); |
| 572 | if (ret) |
| 573 | goto err_mem_regions; |
| 574 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 575 | ret = i915_ggtt_enable_hw(dev_priv); |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 576 | if (ret) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 577 | drm_err(&dev_priv->drm, "failed to enable GGTT\n"); |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 578 | goto err_mem_regions; |
Chris Wilson | 0088e52 | 2016-08-04 07:52:21 +0100 | [diff] [blame] | 579 | } |
| 580 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 581 | pci_set_master(pdev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 582 | |
Tvrtko Ursulin | 25d140f | 2018-12-03 13:33:19 +0000 | [diff] [blame] | 583 | intel_gt_init_workarounds(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 584 | |
| 585 | /* On the 945G/GM, the chipset reports the MSI capability on the |
| 586 | * integrated graphics even though the support isn't actually there |
| 587 | * according to the published specs. It doesn't appear to function |
| 588 | * correctly in testing on 945G. |
| 589 | * This may be a side effect of MSI having been made available for PEG |
| 590 | * and the registers being closely associated. |
| 591 | * |
| 592 | * According to chipset errata, on the 965GM, MSI interrupts may |
Ville Syrjälä | e38c2da | 2017-06-26 23:30:51 +0300 | [diff] [blame] | 593 | * be lost or delayed, and was defeatured. MSI interrupts seem to |
| 594 | * get lost on g4x as well, and interrupt delivery seems to stay |
| 595 | * properly dead afterwards. So we'll just disable them for all |
| 596 | * pre-gen5 chipsets. |
Lucas De Marchi | 8a29c77 | 2018-05-23 11:04:35 -0700 | [diff] [blame] | 597 | * |
| 598 | * dp aux and gmbus irq on gen4 seems to be able to generate legacy |
| 599 | * interrupts even when in MSI mode. This results in spurious |
| 600 | * interrupt warnings if the legacy irq no. is shared with another |
| 601 | * device. The kernel then disables that interrupt source and so |
| 602 | * prevents the other device from working properly. |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 603 | */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 604 | if (GRAPHICS_VER(dev_priv) >= 5) { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 605 | if (pci_enable_msi(pdev) < 0) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 606 | drm_dbg(&dev_priv->drm, "can't enable MSI"); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 609 | ret = intel_gvt_init(dev_priv); |
| 610 | if (ret) |
Chris Wilson | 7ab87ed | 2018-07-10 15:38:21 +0100 | [diff] [blame] | 611 | goto err_msi; |
| 612 | |
| 613 | intel_opregion_setup(dev_priv); |
José Roberto de Souza | 5d0c938 | 2021-01-28 08:43:11 -0800 | [diff] [blame] | 614 | |
| 615 | intel_pcode_init(dev_priv); |
| 616 | |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 617 | /* |
José Roberto de Souza | f0b2970 | 2021-01-28 08:43:10 -0800 | [diff] [blame] | 618 | * Fill the dram structure to get the system dram info. This will be |
| 619 | * used for memory latency calculation. |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 620 | */ |
Jani Nikula | d28ae3b | 2020-02-25 13:15:07 +0200 | [diff] [blame] | 621 | intel_dram_detect(dev_priv); |
Mahesh Kumar | cbfa59d | 2018-08-24 15:02:21 +0530 | [diff] [blame] | 622 | |
Ville Syrjälä | c457d9c | 2019-05-24 18:36:14 +0300 | [diff] [blame] | 623 | intel_bw_init_hw(dev_priv); |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 624 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 625 | return 0; |
| 626 | |
Chris Wilson | 7ab87ed | 2018-07-10 15:38:21 +0100 | [diff] [blame] | 627 | err_msi: |
| 628 | if (pdev->msi_enabled) |
| 629 | pci_disable_msi(pdev); |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 630 | err_mem_regions: |
| 631 | intel_memory_regions_driver_release(dev_priv); |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 632 | err_ggtt: |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 633 | i915_ggtt_driver_release(dev_priv); |
Chris Wilson | 9f172f6 | 2018-04-14 10:12:33 +0100 | [diff] [blame] | 634 | err_perf: |
| 635 | i915_perf_fini(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | /** |
Janusz Krzysztofik | 78dae1a | 2019-07-12 13:24:29 +0200 | [diff] [blame] | 640 | * 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] | 641 | * @dev_priv: device private |
| 642 | */ |
Janusz Krzysztofik | 78dae1a | 2019-07-12 13:24:29 +0200 | [diff] [blame] | 643 | static void i915_driver_hw_remove(struct drm_i915_private *dev_priv) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 644 | { |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 645 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 646 | |
Lionel Landwerlin | 9f9b279 | 2017-10-27 15:59:31 +0100 | [diff] [blame] | 647 | i915_perf_fini(dev_priv); |
| 648 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 649 | if (pdev->msi_enabled) |
| 650 | pci_disable_msi(pdev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
| 654 | * i915_driver_register - register the driver with the rest of the system |
| 655 | * @dev_priv: device private |
| 656 | * |
| 657 | * Perform any steps necessary to make the driver available via kernel |
| 658 | * internal or userspace interfaces. |
| 659 | */ |
| 660 | static void i915_driver_register(struct drm_i915_private *dev_priv) |
| 661 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 662 | struct drm_device *dev = &dev_priv->drm; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 663 | |
Chris Wilson | c29579d | 2019-08-06 13:42:59 +0100 | [diff] [blame] | 664 | i915_gem_driver_register(dev_priv); |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 665 | i915_pmu_register(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 666 | |
Jani Nikula | 9e859eb | 2020-02-27 16:44:06 +0200 | [diff] [blame] | 667 | intel_vgpu_register(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 668 | |
| 669 | /* Reveal our presence to userspace */ |
Lucas De Marchi | ec3e00b | 2021-02-12 20:27:53 -0800 | [diff] [blame] | 670 | if (drm_dev_register(dev, 0)) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 671 | drm_err(&dev_priv->drm, |
| 672 | "Failed to register driver for userspace access!\n"); |
Lucas De Marchi | ec3e00b | 2021-02-12 20:27:53 -0800 | [diff] [blame] | 673 | return; |
| 674 | } |
| 675 | |
| 676 | i915_debugfs_register(dev_priv); |
Lucas De Marchi | ec3e00b | 2021-02-12 20:27:53 -0800 | [diff] [blame] | 677 | i915_setup_sysfs(dev_priv); |
| 678 | |
| 679 | /* Depends on sysfs having been initialized */ |
| 680 | i915_perf_register(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 681 | |
Lucas De Marchi | ef7eff1 | 2021-02-12 20:27:54 -0800 | [diff] [blame] | 682 | intel_gt_driver_register(&dev_priv->gt); |
| 683 | |
Lucas De Marchi | 141b415 | 2021-02-12 20:27:55 -0800 | [diff] [blame] | 684 | intel_display_driver_register(dev_priv); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 685 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 686 | intel_power_domains_enable(dev_priv); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 687 | intel_runtime_pm_enable(&dev_priv->runtime_pm); |
Jani Nikula | 46edcdb | 2020-02-11 18:28:01 +0200 | [diff] [blame] | 688 | |
| 689 | intel_register_dsm_handler(); |
| 690 | |
| 691 | if (i915_switcheroo_register(dev_priv)) |
| 692 | drm_err(&dev_priv->drm, "Failed to register vga switcheroo!\n"); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | /** |
| 696 | * i915_driver_unregister - cleanup the registration done in i915_driver_regiser() |
| 697 | * @dev_priv: device private |
| 698 | */ |
| 699 | static void i915_driver_unregister(struct drm_i915_private *dev_priv) |
| 700 | { |
Jani Nikula | 46edcdb | 2020-02-11 18:28:01 +0200 | [diff] [blame] | 701 | i915_switcheroo_unregister(dev_priv); |
| 702 | |
| 703 | intel_unregister_dsm_handler(); |
| 704 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 705 | intel_runtime_pm_disable(&dev_priv->runtime_pm); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 706 | intel_power_domains_disable(dev_priv); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 707 | |
Lucas De Marchi | 141b415 | 2021-02-12 20:27:55 -0800 | [diff] [blame] | 708 | intel_display_driver_unregister(dev_priv); |
Chris Wilson | 448aa91 | 2017-11-28 11:01:47 +0000 | [diff] [blame] | 709 | |
Andi Shyti | 42014f6 | 2019-09-05 14:14:03 +0300 | [diff] [blame] | 710 | intel_gt_driver_unregister(&dev_priv->gt); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 711 | |
Robert Bragg | 442b8c0 | 2016-11-07 19:49:53 +0000 | [diff] [blame] | 712 | i915_perf_unregister(dev_priv); |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 713 | i915_pmu_unregister(dev_priv); |
Robert Bragg | 442b8c0 | 2016-11-07 19:49:53 +0000 | [diff] [blame] | 714 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 715 | i915_teardown_sysfs(dev_priv); |
Janusz Krzysztofik | d69990e | 2019-04-05 15:02:34 +0200 | [diff] [blame] | 716 | drm_dev_unplug(&dev_priv->drm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 717 | |
Chris Wilson | c29579d | 2019-08-06 13:42:59 +0100 | [diff] [blame] | 718 | i915_gem_driver_unregister(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 719 | } |
| 720 | |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 721 | static void i915_welcome_messages(struct drm_i915_private *dev_priv) |
| 722 | { |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 723 | if (drm_debug_enabled(DRM_UT_DRIVER)) { |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 724 | struct drm_printer p = drm_debug_printer("i915 device info:"); |
| 725 | |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 726 | 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] | 727 | INTEL_DEVID(dev_priv), |
| 728 | INTEL_REVID(dev_priv), |
| 729 | intel_platform_name(INTEL_INFO(dev_priv)->platform), |
Tvrtko Ursulin | 805446c | 2019-03-27 14:23:28 +0000 | [diff] [blame] | 730 | intel_subplatform(RUNTIME_INFO(dev_priv), |
| 731 | INTEL_INFO(dev_priv)->platform), |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 732 | GRAPHICS_VER(dev_priv)); |
Jani Nikula | 1787a98 | 2018-12-31 16:56:45 +0200 | [diff] [blame] | 733 | |
Chris Wilson | 7240497 | 2019-12-07 18:29:37 +0000 | [diff] [blame] | 734 | intel_device_info_print_static(INTEL_INFO(dev_priv), &p); |
| 735 | intel_device_info_print_runtime(RUNTIME_INFO(dev_priv), &p); |
Daniele Ceraolo Spurio | 792592e | 2020-07-07 17:39:47 -0700 | [diff] [blame] | 736 | intel_gt_info_print(&dev_priv->gt.info, &p); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG)) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 740 | drm_info(&dev_priv->drm, "DRM_I915_DEBUG enabled\n"); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 741 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 742 | drm_info(&dev_priv->drm, "DRM_I915_DEBUG_GEM enabled\n"); |
Imre Deak | 6dfc4a8 | 2018-08-16 22:34:14 +0300 | [diff] [blame] | 743 | if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 744 | drm_info(&dev_priv->drm, |
| 745 | "DRM_I915_DEBUG_RUNTIME_PM enabled\n"); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 746 | } |
| 747 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 748 | static struct drm_i915_private * |
| 749 | i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 750 | { |
| 751 | const struct intel_device_info *match_info = |
| 752 | (struct intel_device_info *)ent->driver_data; |
| 753 | struct intel_device_info *device_info; |
| 754 | struct drm_i915_private *i915; |
| 755 | |
Daniel Vetter | 274ed9e | 2020-04-15 09:40:13 +0200 | [diff] [blame] | 756 | i915 = devm_drm_dev_alloc(&pdev->dev, &driver, |
| 757 | struct drm_i915_private, drm); |
| 758 | if (IS_ERR(i915)) |
| 759 | return i915; |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 760 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 761 | pci_set_drvdata(pdev, i915); |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 762 | |
Jani Nikula | 8a25c4b | 2020-06-18 18:04:02 +0300 | [diff] [blame] | 763 | /* Device parameters start as a copy of module parameters. */ |
| 764 | i915_params_copy(&i915->params, &i915_modparams); |
| 765 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 766 | /* Setup the write-once "constant" device info */ |
| 767 | device_info = mkwrite_device_info(i915); |
| 768 | memcpy(device_info, match_info, sizeof(*device_info)); |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 769 | RUNTIME_INFO(i915)->device_id = pdev->device; |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 770 | |
Chris Wilson | 55ac5a1 | 2018-09-05 15:09:20 +0100 | [diff] [blame] | 771 | return i915; |
| 772 | } |
| 773 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 774 | /** |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 775 | * i915_driver_probe - setup chip and create an initial config |
Joonas Lahtinen | d2ad3ae | 2016-11-10 15:36:34 +0200 | [diff] [blame] | 776 | * @pdev: PCI device |
| 777 | * @ent: matching PCI ID entry |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 778 | * |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 779 | * The driver probe routine has to do several things: |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 780 | * - drive output discovery via intel_modeset_init() |
| 781 | * - initialize the memory manager |
| 782 | * - allocate initial config memory |
| 783 | * - setup the DRM framebuffer with the allocated memory |
| 784 | */ |
Janusz Krzysztofik | b01558e | 2019-07-12 13:24:26 +0200 | [diff] [blame] | 785 | 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] | 786 | { |
Maarten Lankhorst | 8d2b47d | 2017-02-02 08:41:42 +0100 | [diff] [blame] | 787 | const struct intel_device_info *match_info = |
| 788 | (struct intel_device_info *)ent->driver_data; |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 789 | struct drm_i915_private *i915; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 790 | int ret; |
| 791 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 792 | i915 = i915_driver_create(pdev, ent); |
| 793 | if (IS_ERR(i915)) |
| 794 | return PTR_ERR(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 795 | |
Ville Syrjälä | 1feb64c | 2018-09-13 16:16:22 +0300 | [diff] [blame] | 796 | /* Disable nuclear pageflip by default on pre-ILK */ |
Lucas De Marchi | 8802190 | 2021-04-12 22:09:59 -0700 | [diff] [blame] | 797 | if (!i915->params.nuclear_pageflip && match_info->graphics_ver < 5) |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 798 | i915->drm.driver_features &= ~DRIVER_ATOMIC; |
Ville Syrjälä | 1feb64c | 2018-09-13 16:16:22 +0300 | [diff] [blame] | 799 | |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 800 | /* |
| 801 | * Check if we support fake LMEM -- for now we only unleash this for |
| 802 | * the live selftests(test-and-exit). |
| 803 | */ |
Chris Wilson | 292a27b | 2019-11-01 09:51:47 +0000 | [diff] [blame] | 804 | #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 805 | if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)) { |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 806 | if (GRAPHICS_VER(i915) >= 9 && i915_selftest.live < 0 && |
Jani Nikula | 8a25c4b | 2020-06-18 18:04:02 +0300 | [diff] [blame] | 807 | i915->params.fake_lmem_start) { |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 808 | mkwrite_device_info(i915)->memory_regions = |
Matthew Auld | dc43040 | 2021-02-05 10:20:26 +0000 | [diff] [blame] | 809 | REGION_SMEM | REGION_LMEM | REGION_STOLEN_SMEM; |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 810 | GEM_BUG_ON(!HAS_LMEM(i915)); |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
Chris Wilson | 292a27b | 2019-11-01 09:51:47 +0000 | [diff] [blame] | 813 | #endif |
Matthew Auld | 1629224 | 2019-10-30 17:33:20 +0000 | [diff] [blame] | 814 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 815 | ret = pci_enable_device(pdev); |
| 816 | if (ret) |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 817 | goto out_fini; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 818 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 819 | ret = i915_driver_early_probe(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 820 | if (ret < 0) |
| 821 | goto out_pci_disable; |
| 822 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 823 | disable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 824 | |
Jani Nikula | 9e859eb | 2020-02-27 16:44:06 +0200 | [diff] [blame] | 825 | intel_vgpu_detect(i915); |
Daniele Ceraolo Spurio | 9e138ea | 2019-06-19 18:00:21 -0700 | [diff] [blame] | 826 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 827 | ret = i915_driver_mmio_probe(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 828 | if (ret < 0) |
| 829 | goto out_runtime_pm_put; |
| 830 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 831 | ret = i915_driver_hw_probe(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 832 | if (ret < 0) |
| 833 | goto out_cleanup_mmio; |
| 834 | |
Jani Nikula | d6843dd | 2020-09-02 17:30:23 +0300 | [diff] [blame] | 835 | ret = intel_modeset_init_noirq(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 836 | if (ret < 0) |
Daniel Vetter | baf5438 | 2017-06-21 10:28:41 +0200 | [diff] [blame] | 837 | goto out_cleanup_hw; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 838 | |
Jani Nikula | b664259 | 2020-02-19 15:37:56 +0200 | [diff] [blame] | 839 | ret = intel_irq_install(i915); |
| 840 | if (ret) |
| 841 | goto out_cleanup_modeset; |
| 842 | |
Jani Nikula | d6843dd | 2020-09-02 17:30:23 +0300 | [diff] [blame] | 843 | ret = intel_modeset_init_nogem(i915); |
| 844 | if (ret) |
Jani Nikula | b664259 | 2020-02-19 15:37:56 +0200 | [diff] [blame] | 845 | goto out_cleanup_irq; |
| 846 | |
Jani Nikula | d6843dd | 2020-09-02 17:30:23 +0300 | [diff] [blame] | 847 | ret = i915_gem_init(i915); |
| 848 | if (ret) |
| 849 | goto out_cleanup_modeset2; |
| 850 | |
| 851 | ret = intel_modeset_init(i915); |
| 852 | if (ret) |
| 853 | goto out_cleanup_gem; |
| 854 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 855 | i915_driver_register(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 856 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 857 | enable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 858 | |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 859 | i915_welcome_messages(i915); |
Michal Wajdeczko | 27d558a | 2017-12-21 21:57:35 +0000 | [diff] [blame] | 860 | |
Daniel Vetter | 7fb81e9 | 2020-03-23 15:49:07 +0100 | [diff] [blame] | 861 | i915->do_release = true; |
| 862 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 863 | return 0; |
| 864 | |
Jani Nikula | d6843dd | 2020-09-02 17:30:23 +0300 | [diff] [blame] | 865 | out_cleanup_gem: |
| 866 | i915_gem_suspend(i915); |
| 867 | i915_gem_driver_remove(i915); |
| 868 | i915_gem_driver_release(i915); |
| 869 | out_cleanup_modeset2: |
| 870 | /* FIXME clean up the error path */ |
| 871 | intel_modeset_driver_remove(i915); |
| 872 | intel_irq_uninstall(i915); |
| 873 | intel_modeset_driver_remove_noirq(i915); |
| 874 | goto out_cleanup_modeset; |
Jani Nikula | b664259 | 2020-02-19 15:37:56 +0200 | [diff] [blame] | 875 | out_cleanup_irq: |
| 876 | intel_irq_uninstall(i915); |
| 877 | out_cleanup_modeset: |
Jani Nikula | eb4612d | 2020-09-02 17:30:22 +0300 | [diff] [blame] | 878 | intel_modeset_driver_remove_nogem(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 879 | out_cleanup_hw: |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 880 | i915_driver_hw_remove(i915); |
| 881 | intel_memory_regions_driver_release(i915); |
| 882 | i915_ggtt_driver_release(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 883 | out_cleanup_mmio: |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 884 | i915_driver_mmio_release(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 885 | out_runtime_pm_put: |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 886 | enable_rpm_wakeref_asserts(&i915->runtime_pm); |
| 887 | i915_driver_late_release(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 888 | out_pci_disable: |
| 889 | pci_disable_device(pdev); |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 890 | out_fini: |
Jani Nikula | 8eecfb3 | 2020-02-11 18:28:02 +0200 | [diff] [blame] | 891 | i915_probe_error(i915, "Device initialization failed (%d)\n", ret); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 895 | void i915_driver_remove(struct drm_i915_private *i915) |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 896 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 897 | disable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | 07d8057 | 2018-08-16 15:37:56 +0300 | [diff] [blame] | 898 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 899 | i915_driver_unregister(i915); |
Daniel Vetter | 99c539b | 2017-07-15 00:46:56 +0200 | [diff] [blame] | 900 | |
Chris Wilson | 4a8ab5e | 2019-01-14 14:21:29 +0000 | [diff] [blame] | 901 | /* Flush any external code that still may be under the RCU lock */ |
| 902 | synchronize_rcu(); |
| 903 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 904 | i915_gem_suspend(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 905 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 906 | intel_gvt_driver_remove(i915); |
Zhenyu Wang | 26f837e | 2017-01-13 10:46:09 +0800 | [diff] [blame] | 907 | |
Jani Nikula | eb4612d | 2020-09-02 17:30:22 +0300 | [diff] [blame] | 908 | intel_modeset_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 909 | |
Jani Nikula | f20a60f | 2020-02-14 15:50:58 +0200 | [diff] [blame] | 910 | intel_irq_uninstall(i915); |
| 911 | |
José Roberto de Souza | c0ff9e5 | 2020-04-16 11:58:41 -0700 | [diff] [blame] | 912 | intel_modeset_driver_remove_noirq(i915); |
Jani Nikula | f20a60f | 2020-02-14 15:50:58 +0200 | [diff] [blame] | 913 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 914 | i915_reset_error_state(i915); |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 915 | i915_gem_driver_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 916 | |
Jani Nikula | eb4612d | 2020-09-02 17:30:22 +0300 | [diff] [blame] | 917 | intel_modeset_driver_remove_nogem(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 918 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 919 | i915_driver_hw_remove(i915); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 920 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 921 | enable_rpm_wakeref_asserts(&i915->runtime_pm); |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | static void i915_driver_release(struct drm_device *dev) |
| 925 | { |
| 926 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 927 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 928 | |
Daniel Vetter | 7fb81e9 | 2020-03-23 15:49:07 +0100 | [diff] [blame] | 929 | if (!dev_priv->do_release) |
| 930 | return; |
| 931 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 932 | disable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 933 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 934 | i915_gem_driver_release(dev_priv); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 935 | |
Chris Wilson | 3fc794f | 2019-10-26 21:20:32 +0100 | [diff] [blame] | 936 | intel_memory_regions_driver_release(dev_priv); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 937 | i915_ggtt_driver_release(dev_priv); |
Chris Wilson | 8935192 | 2020-07-29 17:42:18 +0100 | [diff] [blame] | 938 | i915_gem_drain_freed_objects(dev_priv); |
Daniele Ceraolo Spurio | 19e0a8d | 2019-06-19 18:00:17 -0700 | [diff] [blame] | 939 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 940 | i915_driver_mmio_release(dev_priv); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 941 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 942 | enable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 943 | intel_runtime_pm_driver_release(rpm); |
Janusz Krzysztofik | 47bc28d | 2019-05-30 15:31:05 +0200 | [diff] [blame] | 944 | |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 945 | i915_driver_late_release(dev_priv); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static int i915_driver_open(struct drm_device *dev, struct drm_file *file) |
| 949 | { |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 950 | struct drm_i915_private *i915 = to_i915(dev); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 951 | int ret; |
| 952 | |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 953 | ret = i915_gem_open(i915, file); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 954 | if (ret) |
| 955 | return ret; |
| 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * i915_driver_lastclose - clean up after all DRM clients have exited |
| 962 | * @dev: DRM device |
| 963 | * |
| 964 | * Take care of cleaning up after all DRM clients have exited. In the |
| 965 | * mode setting case, we want to restore the kernel's initial mode (just |
| 966 | * in case the last client left us in a bad state). |
| 967 | * |
| 968 | * Additionally, in the non-mode setting case, we'll tear down the GTT |
| 969 | * and DMA structures, since the kernel won't be using them, and clea |
| 970 | * up any GEM state. |
| 971 | */ |
| 972 | static void i915_driver_lastclose(struct drm_device *dev) |
| 973 | { |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 974 | struct drm_i915_private *i915 = to_i915(dev); |
| 975 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 976 | intel_fbdev_restore_mode(dev); |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 977 | |
| 978 | if (HAS_DISPLAY(i915)) |
| 979 | vga_switcheroo_process_delayed_switch(); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 980 | } |
| 981 | |
Daniel Vetter | 7d2ec88 | 2017-03-08 15:12:45 +0100 | [diff] [blame] | 982 | 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] | 983 | { |
Daniel Vetter | 7d2ec88 | 2017-03-08 15:12:45 +0100 | [diff] [blame] | 984 | struct drm_i915_file_private *file_priv = file->driver_priv; |
| 985 | |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 986 | i915_gem_context_close(file); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 987 | |
Chris Wilson | 7771590 | 2019-08-23 19:14:55 +0100 | [diff] [blame] | 988 | kfree_rcu(file_priv, rcu); |
Chris Wilson | 515b8b7 | 2019-08-02 22:21:37 +0100 | [diff] [blame] | 989 | |
| 990 | /* Catch up with all the deferred frees from "this" client */ |
| 991 | i915_gem_flush_free_objects(to_i915(dev)); |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 994 | static void intel_suspend_encoders(struct drm_i915_private *dev_priv) |
| 995 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 996 | struct drm_device *dev = &dev_priv->drm; |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 997 | struct intel_encoder *encoder; |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 998 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 999 | if (!HAS_DISPLAY(dev_priv)) |
| 1000 | return; |
| 1001 | |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 1002 | drm_modeset_lock_all(dev); |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 1003 | for_each_intel_encoder(dev, encoder) |
| 1004 | if (encoder->suspend) |
| 1005 | encoder->suspend(encoder); |
Imre Deak | 07f9cd0 | 2014-08-18 14:42:45 +0300 | [diff] [blame] | 1006 | drm_modeset_unlock_all(dev); |
| 1007 | } |
| 1008 | |
Ville Syrjälä | 100fe4c | 2020-10-01 18:16:36 +0300 | [diff] [blame] | 1009 | static void intel_shutdown_encoders(struct drm_i915_private *dev_priv) |
| 1010 | { |
| 1011 | struct drm_device *dev = &dev_priv->drm; |
| 1012 | struct intel_encoder *encoder; |
| 1013 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1014 | if (!HAS_DISPLAY(dev_priv)) |
| 1015 | return; |
| 1016 | |
Ville Syrjälä | 100fe4c | 2020-10-01 18:16:36 +0300 | [diff] [blame] | 1017 | drm_modeset_lock_all(dev); |
| 1018 | for_each_intel_encoder(dev, encoder) |
| 1019 | if (encoder->shutdown) |
| 1020 | encoder->shutdown(encoder); |
| 1021 | drm_modeset_unlock_all(dev); |
| 1022 | } |
| 1023 | |
Ville Syrjälä | fe0f1e3 | 2020-10-01 18:16:35 +0300 | [diff] [blame] | 1024 | void i915_driver_shutdown(struct drm_i915_private *i915) |
| 1025 | { |
Chris Wilson | 19fe4ac | 2021-01-04 20:39:05 +0000 | [diff] [blame] | 1026 | disable_rpm_wakeref_asserts(&i915->runtime_pm); |
Imre Deak | 7962893 | 2021-01-27 20:19:09 +0200 | [diff] [blame] | 1027 | intel_runtime_pm_disable(&i915->runtime_pm); |
| 1028 | intel_power_domains_disable(i915); |
Chris Wilson | 19fe4ac | 2021-01-04 20:39:05 +0000 | [diff] [blame] | 1029 | |
Ville Syrjälä | fe0f1e3 | 2020-10-01 18:16:35 +0300 | [diff] [blame] | 1030 | i915_gem_suspend(i915); |
| 1031 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1032 | if (HAS_DISPLAY(i915)) { |
| 1033 | drm_kms_helper_poll_disable(&i915->drm); |
Ville Syrjälä | fe0f1e3 | 2020-10-01 18:16:35 +0300 | [diff] [blame] | 1034 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1035 | drm_atomic_helper_shutdown(&i915->drm); |
| 1036 | } |
Ville Syrjälä | fe0f1e3 | 2020-10-01 18:16:35 +0300 | [diff] [blame] | 1037 | |
| 1038 | intel_dp_mst_suspend(i915); |
| 1039 | |
| 1040 | intel_runtime_pm_disable_interrupts(i915); |
| 1041 | intel_hpd_cancel_work(i915); |
| 1042 | |
| 1043 | intel_suspend_encoders(i915); |
Ville Syrjälä | 100fe4c | 2020-10-01 18:16:36 +0300 | [diff] [blame] | 1044 | intel_shutdown_encoders(i915); |
Chris Wilson | 19fe4ac | 2021-01-04 20:39:05 +0000 | [diff] [blame] | 1045 | |
Anusha Srivatsa | 74ff150 | 2021-05-18 14:34:43 -0700 | [diff] [blame] | 1046 | intel_dmc_ucode_suspend(i915); |
Imre Deak | d339ef1c | 2021-03-11 16:45:29 +0200 | [diff] [blame] | 1047 | |
Imre Deak | 7962893 | 2021-01-27 20:19:09 +0200 | [diff] [blame] | 1048 | /* |
| 1049 | * The only requirement is to reboot with display DC states disabled, |
| 1050 | * for now leaving all display power wells in the INIT power domain |
Imre Deak | d339ef1c | 2021-03-11 16:45:29 +0200 | [diff] [blame] | 1051 | * enabled. |
| 1052 | * |
| 1053 | * TODO: |
| 1054 | * - unify the pci_driver::shutdown sequence here with the |
| 1055 | * pci_driver.driver.pm.poweroff,poweroff_late sequence. |
| 1056 | * - unify the driver remove and system/runtime suspend sequences with |
| 1057 | * the above unified shutdown/poweroff sequence. |
Imre Deak | 7962893 | 2021-01-27 20:19:09 +0200 | [diff] [blame] | 1058 | */ |
| 1059 | intel_power_domains_driver_remove(i915); |
Chris Wilson | 19fe4ac | 2021-01-04 20:39:05 +0000 | [diff] [blame] | 1060 | enable_rpm_wakeref_asserts(&i915->runtime_pm); |
Imre Deak | 7962893 | 2021-01-27 20:19:09 +0200 | [diff] [blame] | 1061 | |
| 1062 | intel_runtime_pm_driver_release(&i915->runtime_pm); |
Ville Syrjälä | fe0f1e3 | 2020-10-01 18:16:35 +0300 | [diff] [blame] | 1063 | } |
| 1064 | |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1065 | static bool suspend_to_idle(struct drm_i915_private *dev_priv) |
| 1066 | { |
| 1067 | #if IS_ENABLED(CONFIG_ACPI_SLEEP) |
| 1068 | if (acpi_target_system_state() < ACPI_STATE_S3) |
| 1069 | return true; |
| 1070 | #endif |
| 1071 | return false; |
| 1072 | } |
Sagar Kamble | ebc3282 | 2014-08-13 23:07:05 +0530 | [diff] [blame] | 1073 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1074 | static int i915_drm_prepare(struct drm_device *dev) |
| 1075 | { |
| 1076 | struct drm_i915_private *i915 = to_i915(dev); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1077 | |
| 1078 | /* |
| 1079 | * NB intel_display_suspend() may issue new requests after we've |
| 1080 | * ostensibly marked the GPU as ready-to-sleep here. We need to |
| 1081 | * split out that work and pull it forward so that after point, |
| 1082 | * the GPU is not woken again. |
| 1083 | */ |
Chris Wilson | 5861b01 | 2019-03-08 09:36:54 +0000 | [diff] [blame] | 1084 | i915_gem_suspend(i915); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1085 | |
Chris Wilson | 5861b01 | 2019-03-08 09:36:54 +0000 | [diff] [blame] | 1086 | return 0; |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1087 | } |
| 1088 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1089 | static int i915_drm_suspend(struct drm_device *dev) |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1090 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1091 | struct drm_i915_private *dev_priv = to_i915(dev); |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 1092 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Jesse Barnes | e5747e3 | 2014-06-12 08:35:47 -0700 | [diff] [blame] | 1093 | pci_power_t opregion_target_state; |
Rafael J. Wysocki | 61caf87 | 2010-02-18 23:06:27 +0100 | [diff] [blame] | 1094 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1095 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1096 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 1097 | /* We do a lot of poking in a lot of registers, make sure they work |
| 1098 | * properly. */ |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1099 | intel_power_domains_disable(dev_priv); |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1100 | if (HAS_DISPLAY(dev_priv)) |
| 1101 | drm_kms_helper_poll_disable(dev); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1102 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1103 | pci_save_state(pdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1104 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 1105 | intel_display_suspend(dev); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1106 | |
Ville Syrjälä | 1a4313d | 2018-07-05 19:43:52 +0300 | [diff] [blame] | 1107 | intel_dp_mst_suspend(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1108 | |
| 1109 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 1110 | intel_hpd_cancel_work(dev_priv); |
| 1111 | |
| 1112 | intel_suspend_encoders(dev_priv); |
| 1113 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 1114 | intel_suspend_hw(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1115 | |
Chris Wilson | e986209 | 2020-01-30 18:17:09 +0000 | [diff] [blame] | 1116 | i915_ggtt_suspend(&dev_priv->ggtt); |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 1117 | |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 1118 | i915_save_display(dev_priv); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1119 | |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1120 | opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold; |
Chris Wilson | a950adc | 2018-10-30 11:05:54 +0000 | [diff] [blame] | 1121 | intel_opregion_suspend(dev_priv, opregion_target_state); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1122 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 1123 | intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true); |
Dave Airlie | 3fa016a | 2012-03-28 10:48:49 +0100 | [diff] [blame] | 1124 | |
Mika Kuoppala | 62d5d69 | 2014-02-25 17:11:28 +0200 | [diff] [blame] | 1125 | dev_priv->suspend_count++; |
| 1126 | |
Anusha Srivatsa | 74ff150 | 2021-05-18 14:34:43 -0700 | [diff] [blame] | 1127 | intel_dmc_ucode_suspend(dev_priv); |
Imre Deak | f514c2d | 2015-10-28 23:59:06 +0200 | [diff] [blame] | 1128 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1129 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1130 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1131 | return 0; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1134 | static enum i915_drm_suspend_mode |
| 1135 | get_suspend_mode(struct drm_i915_private *dev_priv, bool hibernate) |
| 1136 | { |
| 1137 | if (hibernate) |
| 1138 | return I915_DRM_SUSPEND_HIBERNATE; |
| 1139 | |
| 1140 | if (suspend_to_idle(dev_priv)) |
| 1141 | return I915_DRM_SUSPEND_IDLE; |
| 1142 | |
| 1143 | return I915_DRM_SUSPEND_MEM; |
| 1144 | } |
| 1145 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1146 | static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1147 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1148 | struct drm_i915_private *dev_priv = to_i915(dev); |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 1149 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1150 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1151 | int ret; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1152 | |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1153 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1154 | |
Chris Wilson | ec92ad0 | 2018-05-31 09:22:46 +0100 | [diff] [blame] | 1155 | i915_gem_suspend_late(dev_priv); |
| 1156 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1157 | intel_uncore_suspend(&dev_priv->uncore); |
Imre Deak | 4c494a5 | 2016-10-13 14:34:06 +0300 | [diff] [blame] | 1158 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1159 | intel_power_domains_suspend(dev_priv, |
| 1160 | get_suspend_mode(dev_priv, hibernation)); |
Imre Deak | 73dfc22 | 2015-11-17 17:33:53 +0200 | [diff] [blame] | 1161 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1162 | intel_display_power_suspend_late(dev_priv); |
| 1163 | |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1164 | ret = vlv_suspend_complete(dev_priv); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1165 | if (ret) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1166 | drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1167 | intel_power_domains_resume(dev_priv); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1168 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1169 | goto out; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1170 | } |
| 1171 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1172 | pci_disable_device(pdev); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1173 | /* |
Imre Deak | 5487557 | 2015-06-30 17:06:47 +0300 | [diff] [blame] | 1174 | * During hibernation on some platforms the BIOS may try to access |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1175 | * the device even though it's already in D3 and hang the machine. So |
| 1176 | * 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] | 1177 | * power down the device properly. The issue was seen on multiple old |
| 1178 | * GENs with different BIOS vendors, so having an explicit blacklist |
| 1179 | * is inpractical; apply the workaround on everything pre GEN6. The |
| 1180 | * platforms where the issue was seen: |
| 1181 | * Lenovo Thinkpad X301, X61s, X60, T60, X41 |
| 1182 | * Fujitsu FSC S7110 |
| 1183 | * Acer Aspire 1830T |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1184 | */ |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 1185 | if (!(hibernation && GRAPHICS_VER(dev_priv) < 6)) |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1186 | pci_set_power_state(pdev, PCI_D3hot); |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1187 | |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1188 | out: |
Daniele Ceraolo Spurio | 69c6635 | 2019-06-13 16:21:53 -0700 | [diff] [blame] | 1189 | enable_rpm_wakeref_asserts(rpm); |
Daniele Ceraolo Spurio | 0a9b263 | 2019-08-09 07:31:16 +0100 | [diff] [blame] | 1190 | if (!dev_priv->uncore.user_forcewake_count) |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1191 | intel_runtime_pm_driver_release(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1192 | |
| 1193 | return ret; |
Imre Deak | c3c09c9 | 2014-10-23 19:23:15 +0300 | [diff] [blame] | 1194 | } |
| 1195 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 1196 | 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] | 1197 | { |
| 1198 | int error; |
| 1199 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 1200 | if (drm_WARN_ON_ONCE(&i915->drm, state.event != PM_EVENT_SUSPEND && |
| 1201 | state.event != PM_EVENT_FREEZE)) |
Imre Deak | 0b14cbd | 2014-09-10 18:16:55 +0300 | [diff] [blame] | 1202 | return -EINVAL; |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1203 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1204 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1205 | return 0; |
Chris Wilson | 6eecba3 | 2010-09-08 09:45:11 +0100 | [diff] [blame] | 1206 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1207 | error = i915_drm_suspend(&i915->drm); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1208 | if (error) |
| 1209 | return error; |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1210 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1211 | return i915_drm_suspend_late(&i915->drm, false); |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1212 | } |
| 1213 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1214 | static int i915_drm_resume(struct drm_device *dev) |
Jesse Barnes | ba8bbcf | 2007-11-22 14:14:14 +1000 | [diff] [blame] | 1215 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1216 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | ac840ae | 2016-05-06 21:35:55 +0300 | [diff] [blame] | 1217 | int ret; |
Matthew Garrett | 8ee1c3d | 2008-08-05 19:37:25 +0100 | [diff] [blame] | 1218 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1219 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1220 | |
Chris Wilson | 640b50f | 2019-12-28 11:12:55 +0000 | [diff] [blame] | 1221 | sanitize_gpu(dev_priv); |
| 1222 | |
Chris Wilson | 97d6d7a | 2016-08-04 07:52:22 +0100 | [diff] [blame] | 1223 | ret = i915_ggtt_enable_hw(dev_priv); |
Ville Syrjälä | ac840ae | 2016-05-06 21:35:55 +0300 | [diff] [blame] | 1224 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1225 | drm_err(&dev_priv->drm, "failed to re-enable GGTT\n"); |
Ville Syrjälä | ac840ae | 2016-05-06 21:35:55 +0300 | [diff] [blame] | 1226 | |
Chris Wilson | e986209 | 2020-01-30 18:17:09 +0000 | [diff] [blame] | 1227 | i915_ggtt_resume(&dev_priv->ggtt); |
Chris Wilson | cec5ca0 | 2019-09-09 12:00:08 +0100 | [diff] [blame] | 1228 | |
Anusha Srivatsa | 74ff150 | 2021-05-18 14:34:43 -0700 | [diff] [blame] | 1229 | intel_dmc_ucode_resume(dev_priv); |
Imre Deak | f74ed08 | 2016-04-18 14:48:21 +0300 | [diff] [blame] | 1230 | |
Ville Syrjälä | 0f8d2a2 | 2020-10-05 20:14:41 +0300 | [diff] [blame] | 1231 | i915_restore_display(dev_priv); |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 1232 | intel_pps_unlock_regs_wa(dev_priv); |
Rafael J. Wysocki | 61caf87 | 2010-02-18 23:06:27 +0100 | [diff] [blame] | 1233 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 1234 | intel_init_pch_refclk(dev_priv); |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 1235 | |
Peter Antoine | 364aece | 2015-05-11 08:50:45 +0100 | [diff] [blame] | 1236 | /* |
| 1237 | * Interrupts have to be enabled before any batches are run. If not the |
| 1238 | * GPU will hang. i915_gem_init_hw() will initiate batches to |
| 1239 | * update/restore the context. |
| 1240 | * |
Imre Deak | 908764f | 2016-11-29 21:40:29 +0200 | [diff] [blame] | 1241 | * drm_mode_config_reset() needs AUX interrupts. |
| 1242 | * |
Peter Antoine | 364aece | 2015-05-11 08:50:45 +0100 | [diff] [blame] | 1243 | * Modeset enabling in intel_modeset_init_hw() also needs working |
| 1244 | * interrupts. |
| 1245 | */ |
| 1246 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 1247 | |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1248 | if (HAS_DISPLAY(dev_priv)) |
| 1249 | drm_mode_config_reset(dev); |
Imre Deak | 908764f | 2016-11-29 21:40:29 +0200 | [diff] [blame] | 1250 | |
Chris Wilson | 37cd330 | 2017-11-12 11:27:38 +0000 | [diff] [blame] | 1251 | i915_gem_resume(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1252 | |
Jani Nikula | 6cd02e7 | 2019-09-20 21:54:21 +0300 | [diff] [blame] | 1253 | intel_modeset_init_hw(dev_priv); |
Ville Syrjälä | 675f7ff | 2017-11-16 18:02:15 +0200 | [diff] [blame] | 1254 | intel_init_clock_gating(dev_priv); |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1255 | intel_hpd_init(dev_priv); |
Daniel Vetter | d581893 | 2015-02-23 12:03:26 +0100 | [diff] [blame] | 1256 | |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1257 | /* MST sideband requires HPD interrupts enabled */ |
Ville Syrjälä | 1a4313d | 2018-07-05 19:43:52 +0300 | [diff] [blame] | 1258 | intel_dp_mst_resume(dev_priv); |
Lyude | a16b765 | 2016-03-11 10:57:01 -0500 | [diff] [blame] | 1259 | intel_display_resume(dev); |
| 1260 | |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1261 | intel_hpd_poll_disable(dev_priv); |
José Roberto de Souza | 5df7bd1 | 2021-04-08 13:31:50 -0700 | [diff] [blame] | 1262 | if (HAS_DISPLAY(dev_priv)) |
| 1263 | drm_kms_helper_poll_enable(dev); |
Lyude | e0b7006 | 2016-11-01 21:06:30 -0400 | [diff] [blame] | 1264 | |
Chris Wilson | a950adc | 2018-10-30 11:05:54 +0000 | [diff] [blame] | 1265 | intel_opregion_resume(dev_priv); |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1266 | |
Chris Wilson | 82e3b8c | 2014-08-13 13:09:46 +0100 | [diff] [blame] | 1267 | intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false); |
Jesse Barnes | 073f34d | 2012-11-02 11:13:59 -0700 | [diff] [blame] | 1268 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1269 | intel_power_domains_enable(dev_priv); |
| 1270 | |
Colin Xu | 385fc38 | 2020-10-27 12:54:06 +0800 | [diff] [blame] | 1271 | intel_gvt_resume(dev_priv); |
| 1272 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1273 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1274 | |
Chris Wilson | 074c6ad | 2014-04-09 09:19:43 +0100 | [diff] [blame] | 1275 | return 0; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1276 | } |
| 1277 | |
Imre Deak | 5e365c3 | 2014-10-23 19:23:25 +0300 | [diff] [blame] | 1278 | static int i915_drm_resume_early(struct drm_device *dev) |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1279 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1280 | struct drm_i915_private *dev_priv = to_i915(dev); |
Thomas Zimmermann | 8ff5446 | 2021-01-28 14:31:23 +0100 | [diff] [blame] | 1281 | struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1282 | int ret; |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1283 | |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1284 | /* |
| 1285 | * We have a resume ordering issue with the snd-hda driver also |
| 1286 | * requiring our device to be power up. Due to the lack of a |
| 1287 | * parent/child relationship we currently solve this with an early |
| 1288 | * resume hook. |
| 1289 | * |
| 1290 | * FIXME: This should be solved with a special hdmi sink device or |
| 1291 | * similar so that power domains can be employed. |
| 1292 | */ |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1293 | |
| 1294 | /* |
| 1295 | * Note that we need to set the power state explicitly, since we |
| 1296 | * powered off the device during freeze and the PCI core won't power |
| 1297 | * it back up for us during thaw. Powering off the device during |
| 1298 | * freeze is not a hard requirement though, and during the |
| 1299 | * suspend/resume phases the PCI core makes sure we get here with the |
| 1300 | * device powered on. So in case we change our freeze logic and keep |
| 1301 | * the device powered we can also remove the following set power state |
| 1302 | * call. |
| 1303 | */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1304 | ret = pci_set_power_state(pdev, PCI_D0); |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1305 | if (ret) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1306 | drm_err(&dev_priv->drm, |
| 1307 | "failed to set PCI D0 power state (%d)\n", ret); |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1308 | return ret; |
Imre Deak | 44410cd | 2016-04-18 14:45:54 +0300 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | /* |
| 1312 | * Note that pci_enable_device() first enables any parent bridge |
| 1313 | * device and only then sets the power state for this device. The |
| 1314 | * bridge enabling is a nop though, since bridge devices are resumed |
| 1315 | * first. The order of enabling power and enabling the device is |
| 1316 | * imposed by the PCI core as described above, so here we preserve the |
| 1317 | * same order for the freeze/thaw phases. |
| 1318 | * |
| 1319 | * TODO: eventually we should remove pci_disable_device() / |
| 1320 | * pci_enable_enable_device() from suspend/resume. Due to how they |
| 1321 | * depend on the device enable refcount we can't anyway depend on them |
| 1322 | * disabling/enabling the device. |
| 1323 | */ |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1324 | if (pci_enable_device(pdev)) |
| 1325 | return -EIO; |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1326 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 1327 | pci_set_master(pdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1328 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1329 | disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1330 | |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1331 | ret = vlv_resume_prepare(dev_priv, false); |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1332 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1333 | drm_err(&dev_priv->drm, |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1334 | "Resume prepare failed: %d, continuing anyway\n", ret); |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1335 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1336 | intel_uncore_resume_early(&dev_priv->uncore); |
| 1337 | |
Tvrtko Ursulin | eaf522f | 2019-06-21 08:07:44 +0100 | [diff] [blame] | 1338 | intel_gt_check_and_clear_faults(&dev_priv->gt); |
Paulo Zanoni | efee833 | 2014-10-27 17:54:33 -0200 | [diff] [blame] | 1339 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1340 | intel_display_power_resume_early(dev_priv); |
Paulo Zanoni | efee833 | 2014-10-27 17:54:33 -0200 | [diff] [blame] | 1341 | |
Imre Deak | 2cd9a68 | 2018-08-16 15:37:57 +0300 | [diff] [blame] | 1342 | intel_power_domains_resume(dev_priv); |
Imre Deak | bc87229 | 2015-11-18 17:32:30 +0200 | [diff] [blame] | 1343 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1344 | enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); |
Imre Deak | 6e35e8a | 2016-04-18 10:04:19 +0300 | [diff] [blame] | 1345 | |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1346 | return ret; |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1347 | } |
| 1348 | |
Jani Nikula | 63bf830 | 2019-10-04 15:20:18 +0300 | [diff] [blame] | 1349 | int i915_resume_switcheroo(struct drm_i915_private *i915) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1350 | { |
Imre Deak | 50a0072 | 2014-10-23 19:23:17 +0300 | [diff] [blame] | 1351 | int ret; |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1352 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1353 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 1354 | return 0; |
| 1355 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1356 | ret = i915_drm_resume_early(&i915->drm); |
Imre Deak | 50a0072 | 2014-10-23 19:23:17 +0300 | [diff] [blame] | 1357 | if (ret) |
| 1358 | return ret; |
| 1359 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1360 | return i915_drm_resume(&i915->drm); |
Imre Deak | 5a17514 | 2014-10-23 19:23:18 +0300 | [diff] [blame] | 1361 | } |
| 1362 | |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1363 | static int i915_pm_prepare(struct device *kdev) |
| 1364 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1365 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1366 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1367 | if (!i915) { |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1368 | dev_err(kdev, "DRM not initialized, aborting suspend.\n"); |
| 1369 | return -ENODEV; |
| 1370 | } |
| 1371 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1372 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1373 | return 0; |
| 1374 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1375 | return i915_drm_prepare(&i915->drm); |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1376 | } |
| 1377 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1378 | static int i915_pm_suspend(struct device *kdev) |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1379 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1380 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1381 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1382 | if (!i915) { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1383 | dev_err(kdev, "DRM not initialized, aborting suspend.\n"); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1384 | return -ENODEV; |
| 1385 | } |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1386 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1387 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 1388 | return 0; |
| 1389 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1390 | return i915_drm_suspend(&i915->drm); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1391 | } |
| 1392 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1393 | static int i915_pm_suspend_late(struct device *kdev) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1394 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1395 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1396 | |
| 1397 | /* |
Damien Lespiau | c965d995 | 2015-05-18 19:53:48 +0100 | [diff] [blame] | 1398 | * We have a suspend ordering issue with the snd-hda driver also |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1399 | * requiring our device to be power up. Due to the lack of a |
| 1400 | * parent/child relationship we currently solve this with an late |
| 1401 | * suspend hook. |
| 1402 | * |
| 1403 | * FIXME: This should be solved with a special hdmi sink device or |
| 1404 | * similar so that power domains can be employed. |
| 1405 | */ |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1406 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1407 | return 0; |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 1408 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1409 | return i915_drm_suspend_late(&i915->drm, false); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1412 | static int i915_pm_poweroff_late(struct device *kdev) |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1413 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1414 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1415 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1416 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1417 | return 0; |
| 1418 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1419 | return i915_drm_suspend_late(&i915->drm, true); |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 1420 | } |
| 1421 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1422 | static int i915_pm_resume_early(struct device *kdev) |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1423 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1424 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1425 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1426 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 1427 | return 0; |
| 1428 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1429 | return i915_drm_resume_early(&i915->drm); |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1430 | } |
| 1431 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1432 | static int i915_pm_resume(struct device *kdev) |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 1433 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1434 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Rafael J. Wysocki | 84b79f8 | 2010-02-07 21:48:24 +0100 | [diff] [blame] | 1435 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1436 | if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) |
Imre Deak | 097dd83 | 2014-10-23 19:23:19 +0300 | [diff] [blame] | 1437 | return 0; |
| 1438 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1439 | return i915_drm_resume(&i915->drm); |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 1440 | } |
| 1441 | |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1442 | /* freeze: before creating the hibernation_image */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1443 | static int i915_pm_freeze(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1444 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1445 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 1446 | int ret; |
| 1447 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1448 | if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) { |
| 1449 | ret = i915_drm_suspend(&i915->drm); |
Imre Deak | dd9f31c | 2017-08-16 17:46:07 +0300 | [diff] [blame] | 1450 | if (ret) |
| 1451 | return ret; |
| 1452 | } |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 1453 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1454 | ret = i915_gem_freeze(i915); |
Chris Wilson | 6a800ea | 2016-09-21 14:51:07 +0100 | [diff] [blame] | 1455 | if (ret) |
| 1456 | return ret; |
| 1457 | |
| 1458 | return 0; |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1461 | static int i915_pm_freeze_late(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1462 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1463 | struct drm_i915_private *i915 = kdev_to_i915(kdev); |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 1464 | int ret; |
| 1465 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1466 | if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) { |
| 1467 | ret = i915_drm_suspend_late(&i915->drm, true); |
Imre Deak | dd9f31c | 2017-08-16 17:46:07 +0300 | [diff] [blame] | 1468 | if (ret) |
| 1469 | return ret; |
| 1470 | } |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 1471 | |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1472 | ret = i915_gem_freeze_late(i915); |
Chris Wilson | 461fb99 | 2016-05-14 07:26:33 +0100 | [diff] [blame] | 1473 | if (ret) |
| 1474 | return ret; |
| 1475 | |
| 1476 | return 0; |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | /* thaw: called after creating the hibernation image, but before turning off. */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1480 | static int i915_pm_thaw_early(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1481 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1482 | return i915_pm_resume_early(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1485 | static int i915_pm_thaw(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1486 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1487 | return i915_pm_resume(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /* restore: called after loading the hibernation image. */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1491 | static int i915_pm_restore_early(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1492 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1493 | return i915_pm_resume_early(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1496 | static int i915_pm_restore(struct device *kdev) |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1497 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1498 | return i915_pm_resume(kdev); |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1501 | static int intel_runtime_suspend(struct device *kdev) |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1502 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1503 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Daniele Ceraolo Spurio | 1bf676c | 2019-06-13 16:21:52 -0700 | [diff] [blame] | 1504 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1505 | int ret; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1506 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 1507 | if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv))) |
Imre Deak | 604effb | 2014-08-26 13:26:56 +0300 | [diff] [blame] | 1508 | return -ENODEV; |
| 1509 | |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1510 | drm_dbg_kms(&dev_priv->drm, "Suspending device\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1511 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1512 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1513 | |
Imre Deak | d610297 | 2014-05-07 19:57:49 +0300 | [diff] [blame] | 1514 | /* |
| 1515 | * We are safe here against re-faults, since the fault handler takes |
| 1516 | * an RPM reference. |
| 1517 | */ |
Chris Wilson | 7c108fd | 2016-10-24 13:42:18 +0100 | [diff] [blame] | 1518 | i915_gem_runtime_suspend(dev_priv); |
Imre Deak | d610297 | 2014-05-07 19:57:49 +0300 | [diff] [blame] | 1519 | |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 1520 | intel_gt_runtime_suspend(&dev_priv->gt); |
Alex Dai | a1c4199 | 2015-09-30 09:46:37 -0700 | [diff] [blame] | 1521 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 1522 | intel_runtime_pm_disable_interrupts(dev_priv); |
Imre Deak | b5478bc | 2014-04-14 20:24:37 +0300 | [diff] [blame] | 1523 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1524 | intel_uncore_suspend(&dev_priv->uncore); |
Hans de Goede | 01c799c | 2017-11-14 14:55:18 +0100 | [diff] [blame] | 1525 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1526 | intel_display_power_suspend(dev_priv); |
| 1527 | |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1528 | ret = vlv_suspend_complete(dev_priv); |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1529 | if (ret) { |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1530 | drm_err(&dev_priv->drm, |
| 1531 | "Runtime suspend failed, disabling it (%d)\n", ret); |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1532 | intel_uncore_runtime_resume(&dev_priv->uncore); |
Hans de Goede | 01c799c | 2017-11-14 14:55:18 +0100 | [diff] [blame] | 1533 | |
Daniel Vetter | b963291 | 2014-09-30 10:56:44 +0200 | [diff] [blame] | 1534 | intel_runtime_pm_enable_interrupts(dev_priv); |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1535 | |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 1536 | intel_gt_runtime_resume(&dev_priv->gt); |
Sagar Arun Kamble | 1ed21cb | 2018-01-24 21:16:57 +0530 | [diff] [blame] | 1537 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1538 | enable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1539 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1540 | return ret; |
| 1541 | } |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 1542 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1543 | enable_rpm_wakeref_asserts(rpm); |
Janusz Krzysztofik | 3b58a94 | 2019-07-12 13:24:28 +0200 | [diff] [blame] | 1544 | intel_runtime_pm_driver_release(rpm); |
Mika Kuoppala | 55ec45c | 2015-12-15 16:25:08 +0200 | [diff] [blame] | 1545 | |
Daniele Ceraolo Spurio | 2cf7bf6 | 2019-03-25 14:49:34 -0700 | [diff] [blame] | 1546 | if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore)) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1547 | drm_err(&dev_priv->drm, |
| 1548 | "Unclaimed access detected prior to suspending\n"); |
Mika Kuoppala | 55ec45c | 2015-12-15 16:25:08 +0200 | [diff] [blame] | 1549 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1550 | rpm->suspended = true; |
Kristen Carlson Accardi | 1fb2362 | 2014-01-14 15:36:15 -0800 | [diff] [blame] | 1551 | |
| 1552 | /* |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 1553 | * FIXME: We really should find a document that references the arguments |
| 1554 | * used below! |
Kristen Carlson Accardi | 1fb2362 | 2014-01-14 15:36:15 -0800 | [diff] [blame] | 1555 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 1556 | if (IS_BROADWELL(dev_priv)) { |
Paulo Zanoni | d37ae19 | 2015-07-30 18:20:29 -0300 | [diff] [blame] | 1557 | /* |
| 1558 | * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop |
| 1559 | * being detected, and the call we do at intel_runtime_resume() |
| 1560 | * won't be able to restore them. Since PCI_D3hot matches the |
| 1561 | * actual specification and appears to be working, use it. |
| 1562 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 1563 | intel_opregion_notify_adapter(dev_priv, PCI_D3hot); |
Paulo Zanoni | d37ae19 | 2015-07-30 18:20:29 -0300 | [diff] [blame] | 1564 | } else { |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 1565 | /* |
| 1566 | * current versions of firmware which depend on this opregion |
| 1567 | * notification have repurposed the D1 definition to mean |
| 1568 | * "runtime suspended" vs. what you would normally expect (D3) |
| 1569 | * to distinguish it from notifications that might be sent via |
| 1570 | * the suspend path. |
| 1571 | */ |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 1572 | intel_opregion_notify_adapter(dev_priv, PCI_D1); |
Paulo Zanoni | c8a0bd4 | 2014-08-21 17:09:38 -0300 | [diff] [blame] | 1573 | } |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1574 | |
Daniele Ceraolo Spurio | f568eee | 2019-03-19 11:35:35 -0700 | [diff] [blame] | 1575 | assert_forcewakes_inactive(&dev_priv->uncore); |
Chris Wilson | dc9fb09 | 2015-01-16 11:34:34 +0200 | [diff] [blame] | 1576 | |
Ander Conselvan de Oliveira | 21d6e0b | 2017-01-20 16:28:43 +0200 | [diff] [blame] | 1577 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1578 | intel_hpd_poll_enable(dev_priv); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 1579 | |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1580 | drm_dbg_kms(&dev_priv->drm, "Device suspended\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1581 | return 0; |
| 1582 | } |
| 1583 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 1584 | static int intel_runtime_resume(struct device *kdev) |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1585 | { |
Chris Wilson | 361f9dc | 2019-08-06 08:42:19 +0100 | [diff] [blame] | 1586 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Daniele Ceraolo Spurio | 1bf676c | 2019-06-13 16:21:52 -0700 | [diff] [blame] | 1587 | struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1588 | int ret; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1589 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 1590 | if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv))) |
Imre Deak | 604effb | 2014-08-26 13:26:56 +0300 | [diff] [blame] | 1591 | return -ENODEV; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1592 | |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1593 | drm_dbg_kms(&dev_priv->drm, "Resuming device\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1594 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 1595 | drm_WARN_ON_ONCE(&dev_priv->drm, atomic_read(&rpm->wakeref_count)); |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1596 | disable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1597 | |
Chris Wilson | 6f9f4b7 | 2016-05-23 15:08:09 +0100 | [diff] [blame] | 1598 | intel_opregion_notify_adapter(dev_priv, PCI_D0); |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1599 | rpm->suspended = false; |
Daniele Ceraolo Spurio | 2cf7bf6 | 2019-03-25 14:49:34 -0700 | [diff] [blame] | 1600 | if (intel_uncore_unclaimed_mmio(&dev_priv->uncore)) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1601 | drm_dbg(&dev_priv->drm, |
| 1602 | "Unclaimed access during suspend, bios?\n"); |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1603 | |
Rodrigo Vivi | 071b68c | 2019-08-06 15:22:08 +0300 | [diff] [blame] | 1604 | intel_display_power_resume(dev_priv); |
| 1605 | |
Jani Nikula | fb5f432 | 2020-02-12 16:40:57 +0200 | [diff] [blame] | 1606 | ret = vlv_resume_prepare(dev_priv, true); |
Paulo Zanoni | 1a5df18 | 2014-10-27 17:54:32 -0200 | [diff] [blame] | 1607 | |
Daniele Ceraolo Spurio | f7de502 | 2019-03-19 11:35:37 -0700 | [diff] [blame] | 1608 | intel_uncore_runtime_resume(&dev_priv->uncore); |
Hans de Goede | bedf4d7 | 2017-11-14 14:55:17 +0100 | [diff] [blame] | 1609 | |
Sagar Arun Kamble | 1ed21cb | 2018-01-24 21:16:57 +0530 | [diff] [blame] | 1610 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 1611 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1612 | /* |
| 1613 | * No point of rolling back things in case of an error, as the best |
| 1614 | * we can do is to hope that things will still work (and disable RPM). |
| 1615 | */ |
Daniele Ceraolo Spurio | 9dfe345 | 2019-07-31 17:57:09 -0700 | [diff] [blame] | 1616 | intel_gt_runtime_resume(&dev_priv->gt); |
Imre Deak | 92b806d | 2014-04-14 20:24:39 +0300 | [diff] [blame] | 1617 | |
Ville Syrjälä | 08d8a23 | 2015-08-27 23:56:08 +0300 | [diff] [blame] | 1618 | /* |
| 1619 | * On VLV/CHV display interrupts are part of the display |
| 1620 | * power well, so hpd is reinitialized from there. For |
| 1621 | * everyone else do it here. |
| 1622 | */ |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1623 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 08d8a23 | 2015-08-27 23:56:08 +0300 | [diff] [blame] | 1624 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 4c8d465 | 2020-10-13 21:11:37 +0300 | [diff] [blame] | 1625 | intel_hpd_poll_disable(dev_priv); |
| 1626 | } |
Ville Syrjälä | 08d8a23 | 2015-08-27 23:56:08 +0300 | [diff] [blame] | 1627 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 1628 | intel_enable_ipc(dev_priv); |
| 1629 | |
Daniele Ceraolo Spurio | 9102650 | 2019-06-13 16:21:51 -0700 | [diff] [blame] | 1630 | enable_rpm_wakeref_asserts(rpm); |
Imre Deak | 1f814da | 2015-12-16 02:52:19 +0200 | [diff] [blame] | 1631 | |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1632 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1633 | drm_err(&dev_priv->drm, |
| 1634 | "Runtime resume failed, disabling it (%d)\n", ret); |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1635 | else |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 1636 | drm_dbg_kms(&dev_priv->drm, "Device resumed\n"); |
Imre Deak | 0ab9cfe | 2014-04-15 16:39:45 +0300 | [diff] [blame] | 1637 | |
| 1638 | return ret; |
Paulo Zanoni | 8a18745 | 2013-12-06 20:32:13 -0200 | [diff] [blame] | 1639 | } |
| 1640 | |
Chris Wilson | 42f5551 | 2016-06-24 14:00:26 +0100 | [diff] [blame] | 1641 | const struct dev_pm_ops i915_pm_ops = { |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 1642 | /* |
| 1643 | * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND, |
| 1644 | * PMSG_RESUME] |
| 1645 | */ |
Chris Wilson | 73b66f8 | 2018-05-25 10:26:29 +0100 | [diff] [blame] | 1646 | .prepare = i915_pm_prepare, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1647 | .suspend = i915_pm_suspend, |
Imre Deak | 76c4b25 | 2014-04-01 19:55:22 +0300 | [diff] [blame] | 1648 | .suspend_late = i915_pm_suspend_late, |
| 1649 | .resume_early = i915_pm_resume_early, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1650 | .resume = i915_pm_resume, |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 1651 | |
| 1652 | /* |
| 1653 | * S4 event handlers |
| 1654 | * @freeze, @freeze_late : called (1) before creating the |
| 1655 | * hibernation image [PMSG_FREEZE] and |
| 1656 | * (2) after rebooting, before restoring |
| 1657 | * the image [PMSG_QUIESCE] |
| 1658 | * @thaw, @thaw_early : called (1) after creating the hibernation |
| 1659 | * image, before writing it [PMSG_THAW] |
| 1660 | * and (2) after failing to create or |
| 1661 | * restore the image [PMSG_RECOVER] |
| 1662 | * @poweroff, @poweroff_late: called after writing the hibernation |
| 1663 | * image, before rebooting [PMSG_HIBERNATE] |
| 1664 | * @restore, @restore_early : called after rebooting and restoring the |
| 1665 | * hibernation image [PMSG_RESTORE] |
| 1666 | */ |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1667 | .freeze = i915_pm_freeze, |
| 1668 | .freeze_late = i915_pm_freeze_late, |
| 1669 | .thaw_early = i915_pm_thaw_early, |
| 1670 | .thaw = i915_pm_thaw, |
Imre Deak | 36d61e6 | 2014-10-23 19:23:24 +0300 | [diff] [blame] | 1671 | .poweroff = i915_pm_suspend, |
Imre Deak | ab3be73 | 2015-03-02 13:04:41 +0200 | [diff] [blame] | 1672 | .poweroff_late = i915_pm_poweroff_late, |
Chris Wilson | 1f19ac2 | 2016-05-14 07:26:32 +0100 | [diff] [blame] | 1673 | .restore_early = i915_pm_restore_early, |
| 1674 | .restore = i915_pm_restore, |
Imre Deak | 5545dbb | 2014-10-23 19:23:28 +0300 | [diff] [blame] | 1675 | |
| 1676 | /* S0ix (via runtime suspend) event handlers */ |
Paulo Zanoni | 97bea20 | 2014-03-07 20:12:33 -0300 | [diff] [blame] | 1677 | .runtime_suspend = intel_runtime_suspend, |
| 1678 | .runtime_resume = intel_runtime_resume, |
Zhenyu Wang | cbda12d | 2009-12-16 13:36:10 +0800 | [diff] [blame] | 1679 | }; |
| 1680 | |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1681 | static const struct file_operations i915_driver_fops = { |
| 1682 | .owner = THIS_MODULE, |
| 1683 | .open = drm_open, |
Chris Wilson | 7a2c65dd | 2020-01-24 12:56:26 +0000 | [diff] [blame] | 1684 | .release = drm_release_noglobal, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1685 | .unlocked_ioctl = drm_ioctl, |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 1686 | .mmap = i915_gem_mmap, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1687 | .poll = drm_poll, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1688 | .read = drm_read, |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 1689 | .compat_ioctl = i915_ioc32_compat_ioctl, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1690 | .llseek = noop_llseek, |
| 1691 | }; |
| 1692 | |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1693 | static int |
| 1694 | i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data, |
| 1695 | struct drm_file *file) |
| 1696 | { |
| 1697 | return -ENODEV; |
| 1698 | } |
| 1699 | |
| 1700 | static const struct drm_ioctl_desc i915_ioctls[] = { |
| 1701 | DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1702 | DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH), |
| 1703 | DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH), |
| 1704 | DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH), |
| 1705 | DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH), |
| 1706 | DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 1707 | DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1708 | DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1709 | DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH), |
| 1710 | DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH), |
| 1711 | DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1712 | DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH), |
| 1713 | DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1714 | DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1715 | DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH), |
| 1716 | DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH), |
| 1717 | DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1718 | DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
Jason Ekstrand | b5b6f6a6 | 2021-03-17 18:40:10 -0500 | [diff] [blame] | 1719 | DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, drm_invalid_op, DRM_AUTH), |
Christian König | b972fff | 2019-04-17 13:25:24 +0200 | [diff] [blame] | 1720 | 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] | 1721 | DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), |
| 1722 | 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] | 1723 | 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] | 1724 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW), |
| 1725 | 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] | 1726 | 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] | 1727 | DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1728 | DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 1729 | DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW), |
| 1730 | DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW), |
| 1731 | DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW), |
| 1732 | 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] | 1733 | 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] | 1734 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW), |
| 1735 | 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] | 1736 | DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW), |
| 1737 | 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] | 1738 | 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] | 1739 | 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] | 1740 | 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] | 1741 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER), |
| 1742 | DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER), |
| 1743 | DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER), |
| 1744 | 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] | 1745 | 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] | 1746 | 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] | 1747 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW), |
| 1748 | DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW), |
| 1749 | DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW), |
| 1750 | DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW), |
| 1751 | DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW), |
| 1752 | 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] | 1753 | 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] | 1754 | DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW), |
| 1755 | DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW), |
| 1756 | DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW), |
Chris Wilson | 7f3f317a | 2019-05-21 22:11:25 +0100 | [diff] [blame] | 1757 | DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW), |
| 1758 | 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] | 1759 | }; |
| 1760 | |
Daniel Vetter | 70a59dd | 2020-11-04 11:04:24 +0100 | [diff] [blame] | 1761 | static const struct drm_driver driver = { |
Michael Witten | 0c54781 | 2011-08-25 17:55:54 +0000 | [diff] [blame] | 1762 | /* Don't use MTRRs here; the Xserver or userspace app should |
| 1763 | * deal with them for Intel hardware. |
Dave Airlie | 792d2b9 | 2005-11-11 23:30:27 +1100 | [diff] [blame] | 1764 | */ |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1765 | .driver_features = |
Daniel Vetter | 0424fda | 2019-06-17 17:39:24 +0200 | [diff] [blame] | 1766 | DRIVER_GEM | |
Lionel Landwerlin | 13149e8 | 2020-08-04 11:59:54 +0300 | [diff] [blame] | 1767 | DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ | |
| 1768 | DRIVER_SYNCOBJ_TIMELINE, |
Chris Wilson | cad3688 | 2017-02-10 16:35:21 +0000 | [diff] [blame] | 1769 | .release = i915_driver_release, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1770 | .open = i915_driver_open, |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1771 | .lastclose = i915_driver_lastclose, |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1772 | .postclose = i915_driver_postclose, |
Rafael J. Wysocki | d8e2920 | 2010-01-09 00:45:33 +0100 | [diff] [blame] | 1773 | |
Daniel Vetter | 1286ff7 | 2012-05-10 15:25:09 +0200 | [diff] [blame] | 1774 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 1775 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
Daniel Vetter | 1286ff7 | 2012-05-10 15:25:09 +0200 | [diff] [blame] | 1776 | .gem_prime_import = i915_gem_prime_import, |
| 1777 | |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 1778 | .dumb_create = i915_gem_dumb_create, |
Abdiel Janulgue | cc66212 | 2019-12-04 12:00:32 +0000 | [diff] [blame] | 1779 | .dumb_map_offset = i915_gem_dumb_mmap_offset, |
| 1780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | .ioctls = i915_ioctls, |
Chris Wilson | 0673ad4 | 2016-06-24 14:00:22 +0100 | [diff] [blame] | 1782 | .num_ioctls = ARRAY_SIZE(i915_ioctls), |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 1783 | .fops = &i915_driver_fops, |
Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 1784 | .name = DRIVER_NAME, |
| 1785 | .desc = DRIVER_DESC, |
| 1786 | .date = DRIVER_DATE, |
| 1787 | .major = DRIVER_MAJOR, |
| 1788 | .minor = DRIVER_MINOR, |
| 1789 | .patchlevel = DRIVER_PATCHLEVEL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | }; |