/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
*/ /* * * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*/
staticint i915_workqueues_init(struct drm_i915_private *dev_priv)
{ /* * The i915 workqueue is primarily used for batched retirement of * requests (and thus managing bo) once the task has been completed * by the GPU. i915_retire_requests() is called directly when we * need high-priority retirement, such as waiting for an explicit * bo. * * It is also used for periodic low-priority events, such as * idle-timers and recording error state. * * All tasks on the workqueue are expected to acquire the dev mutex * so there is no point in running more than one instance of the * workqueue at any time. Use an ordered one.
*/
dev_priv->wq = alloc_ordered_workqueue("i915", 0); if (dev_priv->wq == NULL) goto out_err;
/* * The unordered i915 workqueue should be used for all work * scheduling that do not require running in order, which used * to be scheduled on the system_wq before moving to a driver * instance due deprecation of flush_scheduled_work().
*/
dev_priv->unordered_wq = alloc_workqueue("i915-unordered", 0, 0); if (dev_priv->unordered_wq == NULL) goto out_free_wq;
return 0;
out_free_wq:
destroy_workqueue(dev_priv->wq);
out_err:
drm_err(&dev_priv->drm, "Failed to allocate workqueues.\n");
/* * We don't keep the workarounds for pre-production hardware, so we expect our * driver to fail on these machines in one way or another. A little warning on * dmesg may help both the user and the bug triagers. * * Our policy for removing pre-production workarounds is to keep the * current gen workarounds as a guide to the bring-up of the next gen * (workarounds have a habit of persisting!). Anything older than that * should be removed along with the complications they introduce.
*/ staticvoid intel_detect_preproduction_hw(struct drm_i915_private *dev_priv)
{ bool pre = false;
pre |= IS_HASWELL_EARLY_SDV(dev_priv);
pre |= IS_SKYLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x6;
pre |= IS_BROXTON(dev_priv) && INTEL_REVID(dev_priv) < 0xA;
pre |= IS_KABYLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
pre |= IS_GEMINILAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x3;
pre |= IS_ICELAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x7;
pre |= IS_TIGERLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
pre |= IS_DG1(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
pre |= IS_DG2_G10(dev_priv) && INTEL_REVID(dev_priv) < 0x8;
pre |= IS_DG2_G11(dev_priv) && INTEL_REVID(dev_priv) < 0x5;
pre |= IS_DG2_G12(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
if (pre) {
drm_err(&dev_priv->drm, "This is a pre-production stepping. " "It may not be fully functional.\n");
add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
}
}
/** * i915_driver_early_probe - setup state not requiring device access * @dev_priv: device private * * Initialize everything that is a "SW-only" state, that is state not * requiring accessing the device or exposing the driver via kernel internal * or userspace interfaces. Example steps belonging here: lock initialization, * system memory allocation, setting up device specific attributes and * function hooks not requiring accessing the device.
*/ staticint i915_driver_early_probe(struct drm_i915_private *dev_priv)
{ struct intel_display *display = dev_priv->display; int ret = 0;
if (i915_inject_probe_failure(dev_priv)) return -ENODEV;
/** * i915_driver_mmio_probe - setup device MMIO * @dev_priv: device private * * Setup minimal device state necessary for MMIO accesses later in the * initialization sequence. The setup here should avoid any other device-wide * side effects or exposing the driver via kernel internal or user space * interfaces.
*/ staticint i915_driver_mmio_probe(struct drm_i915_private *dev_priv)
{ struct intel_display *display = dev_priv->display; struct intel_gt *gt; int ret, i;
if (i915_inject_probe_failure(dev_priv)) return -ENODEV;
ret = intel_gmch_bridge_setup(dev_priv); if (ret < 0) return ret;
for_each_gt(gt, dev_priv, i) {
ret = intel_uncore_init_mmio(gt->uncore); if (ret) return ret;
ret = drmm_add_action_or_reset(&dev_priv->drm,
intel_uncore_fini_mmio,
gt->uncore); if (ret) return ret;
}
/* Try to make sure MCHBAR is enabled before poking at it */
intel_gmch_bar_setup(dev_priv);
intel_device_info_runtime_init(dev_priv);
intel_display_device_info_runtime_init(display);
for_each_gt(gt, dev_priv, i) {
ret = intel_gt_init_mmio(gt); if (ret) goto err_uncore;
}
/* As early as possible, scrub existing GPU state before clobbering */
sanitize_gpu(dev_priv);
/** * i915_set_dma_info - set all relevant PCI dma info as configured for the * platform * @i915: valid i915 instance * * Set the dma max segment size, device and coherent masks. The dma mask set * needs to occur before i915_ggtt_probe_hw. * * A couple of platforms have special needs. Address them as well. *
*/ staticint i915_set_dma_info(struct drm_i915_private *i915)
{ unsignedint mask_size = INTEL_INFO(i915)->dma_mask_size; int ret;
GEM_BUG_ON(!mask_size);
/* * We don't have a max segment size, so set it to the max so sg's * debugging layer doesn't complain
*/
dma_set_max_seg_size(i915->drm.dev, UINT_MAX);
ret = dma_set_mask(i915->drm.dev, DMA_BIT_MASK(mask_size)); if (ret) goto mask_err;
/* overlay on gen2 is broken and can't address above 1G */ if (GRAPHICS_VER(i915) == 2)
mask_size = 30;
/* * 965GM sometimes incorrectly writes to hardware status page (HWS) * using 32bit addressing, overwriting memory if HWS is located * above 4GB. * * The documentation also mentions an issue with undefined * behaviour if any general state is accessed within a page above 4GB, * which also needs to be handled carefully.
*/ if (IS_I965G(i915) || IS_I965GM(i915))
mask_size = 32;
ret = dma_set_coherent_mask(i915->drm.dev, DMA_BIT_MASK(mask_size)); if (ret) goto mask_err;
for_each_gt(gt, i915, id) {
ret = intel_pcode_init(gt->uncore); if (ret) {
gt_err(gt, "intel_pcode_init failed %d\n", ret); return ret;
}
}
i915_enable_g8(i915); return 0;
}
/** * i915_driver_hw_probe - setup state requiring device access * @dev_priv: device private * * Setup state that requires accessing the device, but doesn't require * exposing the driver via kernel internal or userspace interfaces.
*/ staticint i915_driver_hw_probe(struct drm_i915_private *dev_priv)
{ struct intel_display *display = dev_priv->display; struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); int ret;
if (i915_inject_probe_failure(dev_priv)) return -ENODEV;
if (HAS_PPGTT(dev_priv)) { if (intel_vgpu_active(dev_priv) &&
!intel_vgpu_has_full_ppgtt(dev_priv)) {
drm_err(&dev_priv->drm, "incompatible vGPU found, support for isolated ppGTT required\n"); return -ENXIO;
}
}
if (HAS_EXECLISTS(dev_priv)) { /* * Older GVT emulation depends upon intercepting CSB mmio, * which we no longer use, preferring to use the HWSP cache * instead.
*/ if (intel_vgpu_active(dev_priv) &&
!intel_vgpu_has_hwsp_emulation(dev_priv)) {
drm_err(&dev_priv->drm, "old vGPU host found, support for HWSP emulation required\n"); return -ENXIO;
}
}
/* needs to be done before ggtt probe */
intel_dram_edram_detect(dev_priv);
ret = i915_set_dma_info(dev_priv); if (ret) return ret;
ret = i915_perf_init(dev_priv); if (ret) return ret;
ret = i915_ggtt_probe_hw(dev_priv); if (ret) goto err_perf;
ret = aperture_remove_conflicting_pci_devices(pdev, dev_priv->drm.driver->name); if (ret) goto err_ggtt;
ret = i915_ggtt_init_hw(dev_priv); if (ret) goto err_ggtt;
/* * Make sure we probe lmem before we probe stolen-lmem. The BAR size * might be different due to bar resizing.
*/
ret = intel_gt_tiles_init(dev_priv); if (ret) goto err_ggtt;
ret = intel_memory_regions_hw_probe(dev_priv); if (ret) goto err_ggtt;
ret = i915_ggtt_enable_hw(dev_priv); if (ret) {
drm_err(&dev_priv->drm, "failed to enable GGTT\n"); goto err_mem_regions;
}
pci_set_master(pdev);
/* On the 945G/GM, the chipset reports the MSI capability on the * integrated graphics even though the support isn't actually there * according to the published specs. It doesn't appear to function * correctly in testing on 945G. * This may be a side effect of MSI having been made available for PEG * and the registers being closely associated. * * According to chipset errata, on the 965GM, MSI interrupts may * be lost or delayed, and was defeatured. MSI interrupts seem to * get lost on g4x as well, and interrupt delivery seems to stay * properly dead afterwards. So we'll just disable them for all * pre-gen5 chipsets. * * dp aux and gmbus irq on gen4 seems to be able to generate legacy * interrupts even when in MSI mode. This results in spurious * interrupt warnings if the legacy irq no. is shared with another * device. The kernel then disables that interrupt source and so * prevents the other device from working properly.
*/ if (GRAPHICS_VER(dev_priv) >= 5) { if (pci_enable_msi(pdev) < 0)
drm_dbg(&dev_priv->drm, "can't enable MSI");
}
ret = intel_gvt_init(dev_priv); if (ret) goto err_msi;
intel_opregion_setup(display);
ret = i915_pcode_init(dev_priv); if (ret) goto err_opregion;
/* * Fill the dram structure to get the system dram info. This will be * used for memory latency calculation.
*/
ret = intel_dram_detect(dev_priv); if (ret) goto err_opregion;
/** * i915_driver_register - register the driver with the rest of the system * @dev_priv: device private * * Perform any steps necessary to make the driver available via kernel * internal or userspace interfaces.
*/ staticint i915_driver_register(struct drm_i915_private *dev_priv)
{ struct intel_display *display = dev_priv->display; struct intel_gt *gt; unsignedint i; int ret;
/* * The only requirement is to reboot with display DC states disabled, * for now leaving all display power wells in the INIT power domain * enabled. * * TODO: * - unify the pci_driver::shutdown sequence here with the * pci_driver.driver.pm.poweroff,poweroff_late sequence. * - unify the driver remove and system/runtime suspend sequences with * the above unified shutdown/poweroff sequence.
*/
intel_power_domains_driver_remove(display);
enable_rpm_wakeref_asserts(&i915->runtime_pm);
/* * NB intel_display_driver_suspend() may issue new requests after we've * ostensibly marked the GPU as ready-to-sleep here. We need to * split out that work and pull it forward so that after point, * the GPU is not woken again.
*/ return i915_gem_backup_suspend(i915);
}
/* We do a lot of poking in a lot of registers, make sure they work
* properly. */
intel_power_domains_disable(display);
drm_client_dev_suspend(dev, false); if (HAS_DISPLAY(dev_priv)) {
drm_kms_helper_poll_disable(dev);
intel_display_driver_disable_user_access(display);
}
ret = vlv_suspend_complete(dev_priv); if (ret) {
drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret);
intel_display_power_resume_early(display);
goto out;
}
pci_disable_device(pdev); /* * During hibernation on some platforms the BIOS may try to access * the device even though it's already in D3 and hang the machine. So * leave the device in D0 on those platforms and hope the BIOS will * power down the device properly. The issue was seen on multiple old * GENs with different BIOS vendors, so having an explicit blacklist * is impractical; apply the workaround on everything pre GEN6. The * platforms where the issue was seen: * Lenovo Thinkpad X301, X61s, X60, T60, X41 * Fujitsu FSC S7110 * Acer Aspire 1830T
*/ if (!(hibernation && GRAPHICS_VER(dev_priv) < 6))
pci_set_power_state(pdev, PCI_D3hot);
out:
enable_rpm_wakeref_asserts(rpm); if (!dev_priv->uncore.user_forcewake_count)
intel_runtime_pm_driver_release(rpm);
return ret;
}
int i915_driver_suspend_switcheroo(struct drm_i915_private *i915,
pm_message_t state)
{ int error;
ret = i915_pcode_init(dev_priv); if (ret) return ret;
sanitize_gpu(dev_priv);
ret = i915_ggtt_enable_hw(dev_priv); if (ret)
drm_err(&dev_priv->drm, "failed to re-enable GGTT\n");
i915_ggtt_resume(to_gt(dev_priv)->ggtt);
for_each_gt(gt, dev_priv, i) if (GRAPHICS_VER(gt->i915) >= 8)
setup_private_pat(gt);
/* Must be called after GGTT is resumed. */
intel_dpt_resume(display);
intel_dmc_resume(display);
i9xx_display_sr_restore(display);
intel_gmbus_reset(display);
intel_pps_unlock_regs_wa(display);
intel_init_pch_refclk(display);
/* * Interrupts have to be enabled before any batches are run. If not the * GPU will hang. i915_gem_init_hw() will initiate batches to * update/restore the context. * * drm_mode_config_reset() needs AUX interrupts. * * Modeset enabling in intel_display_driver_init_hw() also needs working * interrupts.
*/
intel_irq_resume(dev_priv);
if (HAS_DISPLAY(dev_priv))
drm_mode_config_reset(dev);
i915_gem_resume(dev_priv);
intel_display_driver_init_hw(display);
intel_clock_gating_init(dev_priv);
if (HAS_DISPLAY(dev_priv))
intel_display_driver_resume_access(display);
intel_hpd_init(display);
intel_display_driver_resume(display);
if (HAS_DISPLAY(dev_priv)) {
intel_display_driver_enable_user_access(display);
drm_kms_helper_poll_enable(dev);
}
intel_hpd_poll_disable(display);
/* * We have a resume ordering issue with the snd-hda driver also * requiring our device to be power up. Due to the lack of a * parent/child relationship we currently solve this with an early * resume hook. * * FIXME: This should be solved with a special hdmi sink device or * similar so that power domains can be employed.
*/
/* * Note that we need to set the power state explicitly, since we * powered off the device during freeze and the PCI core won't power * it back up for us during thaw. Powering off the device during * freeze is not a hard requirement though, and during the * suspend/resume phases the PCI core makes sure we get here with the * device powered on. So in case we change our freeze logic and keep * the device powered we can also remove the following set power state * call.
*/
ret = pci_set_power_state(pdev, PCI_D0); if (ret) {
drm_err(&dev_priv->drm, "failed to set PCI D0 power state (%d)\n", ret); return ret;
}
/* * Note that pci_enable_device() first enables any parent bridge * device and only then sets the power state for this device. The * bridge enabling is a nop though, since bridge devices are resumed * first. The order of enabling power and enabling the device is * imposed by the PCI core as described above, so here we preserve the * same order for the freeze/thaw phases. * * TODO: eventually we should remove pci_disable_device() / * pci_enable_enable_device() from suspend/resume. Due to how they * depend on the device enable refcount we can't anyway depend on them * disabling/enabling the device.
*/ if (pci_enable_device(pdev)) return -EIO;
/* * We have a suspend ordering issue with the snd-hda driver also * requiring our device to be power up. Due to the lack of a * parent/child relationship we currently solve this with an late * suspend hook. * * FIXME: This should be solved with a special hdmi sink device or * similar so that power domains can be employed.
*/ if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) return 0;
if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
ret = i915_drm_suspend_late(&i915->drm, true); if (ret) return ret;
}
ret = i915_gem_freeze_late(i915); if (ret) return ret;
return 0;
}
/* thaw: called after creating the hibernation image, but before turning off. */ staticint i915_pm_thaw_early(struct device *kdev)
{ return i915_pm_resume_early(kdev);
}
ret = vlv_suspend_complete(dev_priv); if (ret) {
drm_err(&dev_priv->drm, "Runtime suspend failed, disabling it (%d)\n", ret);
intel_uncore_runtime_resume(&dev_priv->uncore);
if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore))
drm_err(&dev_priv->drm, "Unclaimed access detected prior to suspending\n");
/* * FIXME: Temporary hammer to avoid freezing the machine on our DGFX * This should be totally removed when we handle the pci states properly * on runtime PM.
*/
root_pdev = pcie_find_root_port(pdev); if (root_pdev)
pci_d3cold_disable(root_pdev);
/* * FIXME: We really should find a document that references the arguments * used below!
*/ if (IS_BROADWELL(dev_priv)) { /* * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop * being detected, and the call we do at intel_runtime_resume() * won't be able to restore them. Since PCI_D3hot matches the * actual specification and appears to be working, use it.
*/
intel_opregion_notify_adapter(display, PCI_D3hot);
} else { /* * current versions of firmware which depend on this opregion * notification have repurposed the D1 definition to mean * "runtime suspended" vs. what you would normally expect (D3) * to distinguish it from notifications that might be sent via * the suspend path.
*/
intel_opregion_notify_adapter(display, PCI_D1);
}
assert_forcewakes_inactive(&dev_priv->uncore);
if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
intel_hpd_poll_enable(display);
/* * No point of rolling back things in case of an error, as the best * we can do is to hope that things will still work (and disable RPM).
*/
for_each_gt(gt, dev_priv, i)
intel_gt_runtime_resume(gt);
intel_pxp_runtime_resume(dev_priv->pxp);
/* * On VLV/CHV display interrupts are part of the display * power well, so hpd is reinitialized from there. For * everyone else do it here.
*/ if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
intel_hpd_init(display);
intel_hpd_poll_disable(display);
}
skl_watermark_ipc_update(display);
enable_rpm_wakeref_asserts(rpm);
if (ret)
drm_err(&dev_priv->drm, "Runtime resume failed, disabling it (%d)\n", ret); else
drm_dbg(&dev_priv->drm, "Device resumed\n");
/* * S4 event handlers * @freeze, @freeze_late : called (1) before creating the * hibernation image [PMSG_FREEZE] and * (2) after rebooting, before restoring * the image [PMSG_QUIESCE] * @thaw, @thaw_early : called (1) after creating the hibernation * image, before writing it [PMSG_THAW] * and (2) after failing to create or * restore the image [PMSG_RECOVER] * @poweroff, @poweroff_late: called after writing the hibernation * image, before rebooting [PMSG_HIBERNATE] * @restore, @restore_early : called after rebooting and restoring the * hibernation image [PMSG_RESTORE]
*/
.freeze = i915_pm_freeze,
.freeze_late = i915_pm_freeze_late,
.thaw_early = i915_pm_thaw_early,
.thaw = i915_pm_thaw,
.poweroff = i915_pm_suspend,
.poweroff_late = i915_pm_poweroff_late,
.restore_early = i915_pm_restore_early,
.restore = i915_pm_restore,
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.