Path: blob/master/drivers/gpu/drm/nouveau/nouveau_drv.c
15112 views
/*1* Copyright 2005 Stephane Marchesin.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR19* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR21* OTHER DEALINGS IN THE SOFTWARE.22*/2324#include <linux/console.h>2526#include "drmP.h"27#include "drm.h"28#include "drm_crtc_helper.h"29#include "nouveau_drv.h"30#include "nouveau_hw.h"31#include "nouveau_fb.h"32#include "nouveau_fbcon.h"33#include "nouveau_pm.h"34#include "nv50_display.h"3536#include "drm_pciids.h"3738MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)");39int nouveau_agpmode = -1;40module_param_named(agpmode, nouveau_agpmode, int, 0400);4142MODULE_PARM_DESC(modeset, "Enable kernel modesetting");43static int nouveau_modeset = -1; /* kms */44module_param_named(modeset, nouveau_modeset, int, 0400);4546MODULE_PARM_DESC(vbios, "Override default VBIOS location");47char *nouveau_vbios;48module_param_named(vbios, nouveau_vbios, charp, 0400);4950MODULE_PARM_DESC(vram_pushbuf, "Force DMA push buffers to be in VRAM");51int nouveau_vram_pushbuf;52module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400);5354MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM");55int nouveau_vram_notify = 0;56module_param_named(vram_notify, nouveau_vram_notify, int, 0400);5758MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)");59int nouveau_duallink = 1;60module_param_named(duallink, nouveau_duallink, int, 0400);6162MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)");63int nouveau_uscript_lvds = -1;64module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400);6566MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)");67int nouveau_uscript_tmds = -1;68module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400);6970MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");71int nouveau_ignorelid = 0;72module_param_named(ignorelid, nouveau_ignorelid, int, 0400);7374MODULE_PARM_DESC(noaccel, "Disable all acceleration");75int nouveau_noaccel = 0;76module_param_named(noaccel, nouveau_noaccel, int, 0400);7778MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");79int nouveau_nofbaccel = 0;80module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);8182MODULE_PARM_DESC(force_post, "Force POST");83int nouveau_force_post = 0;84module_param_named(force_post, nouveau_force_post, int, 0400);8586MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type");87int nouveau_override_conntype = 0;88module_param_named(override_conntype, nouveau_override_conntype, int, 0400);8990MODULE_PARM_DESC(tv_disable, "Disable TV-out detection\n");91int nouveau_tv_disable = 0;92module_param_named(tv_disable, nouveau_tv_disable, int, 0400);9394MODULE_PARM_DESC(tv_norm, "Default TV norm.\n"95"\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n"96"\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n"97"\t\tDefault: PAL\n"98"\t\t*NOTE* Ignored for cards with external TV encoders.");99char *nouveau_tv_norm;100module_param_named(tv_norm, nouveau_tv_norm, charp, 0400);101102MODULE_PARM_DESC(reg_debug, "Register access debug bitmask:\n"103"\t\t0x1 mc, 0x2 video, 0x4 fb, 0x8 extdev,\n"104"\t\t0x10 crtc, 0x20 ramdac, 0x40 vgacrtc, 0x80 rmvio,\n"105"\t\t0x100 vgaattr, 0x200 EVO (G80+). ");106int nouveau_reg_debug;107module_param_named(reg_debug, nouveau_reg_debug, int, 0600);108109MODULE_PARM_DESC(perflvl, "Performance level (default: boot)\n");110char *nouveau_perflvl;111module_param_named(perflvl, nouveau_perflvl, charp, 0400);112113MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)\n");114int nouveau_perflvl_wr;115module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400);116117MODULE_PARM_DESC(msi, "Enable MSI (default: off)\n");118int nouveau_msi;119module_param_named(msi, nouveau_msi, int, 0400);120121int nouveau_fbpercrtc;122#if 0123module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);124#endif125126static struct pci_device_id pciidlist[] = {127{128PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),129.class = PCI_BASE_CLASS_DISPLAY << 16,130.class_mask = 0xff << 16,131},132{133PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),134.class = PCI_BASE_CLASS_DISPLAY << 16,135.class_mask = 0xff << 16,136},137{}138};139140MODULE_DEVICE_TABLE(pci, pciidlist);141142static struct drm_driver driver;143144static int __devinit145nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)146{147return drm_get_pci_dev(pdev, ent, &driver);148}149150static void151nouveau_pci_remove(struct pci_dev *pdev)152{153struct drm_device *dev = pci_get_drvdata(pdev);154155drm_put_dev(dev);156}157158int159nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)160{161struct drm_device *dev = pci_get_drvdata(pdev);162struct drm_nouveau_private *dev_priv = dev->dev_private;163struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;164struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;165struct nouveau_channel *chan;166struct drm_crtc *crtc;167int ret, i, e;168169if (pm_state.event == PM_EVENT_PRETHAW)170return 0;171172if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)173return 0;174175NV_INFO(dev, "Disabling fbcon acceleration...\n");176nouveau_fbcon_save_disable_accel(dev);177178NV_INFO(dev, "Unpinning framebuffer(s)...\n");179list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {180struct nouveau_framebuffer *nouveau_fb;181182nouveau_fb = nouveau_framebuffer(crtc->fb);183if (!nouveau_fb || !nouveau_fb->nvbo)184continue;185186nouveau_bo_unpin(nouveau_fb->nvbo);187}188189list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {190struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);191192nouveau_bo_unmap(nv_crtc->cursor.nvbo);193nouveau_bo_unpin(nv_crtc->cursor.nvbo);194}195196NV_INFO(dev, "Evicting buffers...\n");197ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);198199NV_INFO(dev, "Idling channels...\n");200for (i = 0; i < pfifo->channels; i++) {201chan = dev_priv->channels.ptr[i];202203if (chan && chan->pushbuf_bo)204nouveau_channel_idle(chan);205}206207pfifo->reassign(dev, false);208pfifo->disable(dev);209pfifo->unload_context(dev);210211for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) {212if (dev_priv->eng[e]) {213ret = dev_priv->eng[e]->fini(dev, e);214if (ret)215goto out_abort;216}217}218219ret = pinstmem->suspend(dev);220if (ret) {221NV_ERROR(dev, "... failed: %d\n", ret);222goto out_abort;223}224225NV_INFO(dev, "Suspending GPU objects...\n");226ret = nouveau_gpuobj_suspend(dev);227if (ret) {228NV_ERROR(dev, "... failed: %d\n", ret);229pinstmem->resume(dev);230goto out_abort;231}232233NV_INFO(dev, "And we're gone!\n");234pci_save_state(pdev);235if (pm_state.event == PM_EVENT_SUSPEND) {236pci_disable_device(pdev);237pci_set_power_state(pdev, PCI_D3hot);238}239240console_lock();241nouveau_fbcon_set_suspend(dev, 1);242console_unlock();243nouveau_fbcon_restore_accel(dev);244return 0;245246out_abort:247NV_INFO(dev, "Re-enabling acceleration..\n");248for (e = e + 1; e < NVOBJ_ENGINE_NR; e++) {249if (dev_priv->eng[e])250dev_priv->eng[e]->init(dev, e);251}252pfifo->enable(dev);253pfifo->reassign(dev, true);254return ret;255}256257int258nouveau_pci_resume(struct pci_dev *pdev)259{260struct drm_device *dev = pci_get_drvdata(pdev);261struct drm_nouveau_private *dev_priv = dev->dev_private;262struct nouveau_engine *engine = &dev_priv->engine;263struct drm_crtc *crtc;264int ret, i;265266if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)267return 0;268269nouveau_fbcon_save_disable_accel(dev);270271NV_INFO(dev, "We're back, enabling device...\n");272pci_set_power_state(pdev, PCI_D0);273pci_restore_state(pdev);274if (pci_enable_device(pdev))275return -1;276pci_set_master(dev->pdev);277278/* Make sure the AGP controller is in a consistent state */279if (dev_priv->gart_info.type == NOUVEAU_GART_AGP)280nouveau_mem_reset_agp(dev);281282/* Make the CRTCs accessible */283engine->display.early_init(dev);284285NV_INFO(dev, "POSTing device...\n");286ret = nouveau_run_vbios_init(dev);287if (ret)288return ret;289290nouveau_pm_resume(dev);291292if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {293ret = nouveau_mem_init_agp(dev);294if (ret) {295NV_ERROR(dev, "error reinitialising AGP: %d\n", ret);296return ret;297}298}299300NV_INFO(dev, "Restoring GPU objects...\n");301nouveau_gpuobj_resume(dev);302303NV_INFO(dev, "Reinitialising engines...\n");304engine->instmem.resume(dev);305engine->mc.init(dev);306engine->timer.init(dev);307engine->fb.init(dev);308for (i = 0; i < NVOBJ_ENGINE_NR; i++) {309if (dev_priv->eng[i])310dev_priv->eng[i]->init(dev, i);311}312engine->fifo.init(dev);313314nouveau_irq_postinstall(dev);315316/* Re-write SKIPS, they'll have been lost over the suspend */317if (nouveau_vram_pushbuf) {318struct nouveau_channel *chan;319int j;320321for (i = 0; i < dev_priv->engine.fifo.channels; i++) {322chan = dev_priv->channels.ptr[i];323if (!chan || !chan->pushbuf_bo)324continue;325326for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)327nouveau_bo_wr32(chan->pushbuf_bo, i, 0);328}329}330331NV_INFO(dev, "Restoring mode...\n");332list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {333struct nouveau_framebuffer *nouveau_fb;334335nouveau_fb = nouveau_framebuffer(crtc->fb);336if (!nouveau_fb || !nouveau_fb->nvbo)337continue;338339nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);340}341342list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {343struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);344345ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);346if (!ret)347ret = nouveau_bo_map(nv_crtc->cursor.nvbo);348if (ret)349NV_ERROR(dev, "Could not pin/map cursor.\n");350}351352engine->display.init(dev);353354list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {355struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);356u32 offset = nv_crtc->cursor.nvbo->bo.mem.start << PAGE_SHIFT;357358nv_crtc->cursor.set_offset(nv_crtc, offset);359nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,360nv_crtc->cursor_saved_y);361}362363/* Force CLUT to get re-loaded during modeset */364list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {365struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);366367nv_crtc->lut.depth = 0;368}369370console_lock();371nouveau_fbcon_set_suspend(dev, 0);372console_unlock();373374nouveau_fbcon_zfill_all(dev);375376drm_helper_resume_force_mode(dev);377378nouveau_fbcon_restore_accel(dev);379return 0;380}381382static struct drm_driver driver = {383.driver_features =384DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |385DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |386DRIVER_MODESET,387.load = nouveau_load,388.firstopen = nouveau_firstopen,389.lastclose = nouveau_lastclose,390.unload = nouveau_unload,391.preclose = nouveau_preclose,392#if defined(CONFIG_DRM_NOUVEAU_DEBUG)393.debugfs_init = nouveau_debugfs_init,394.debugfs_cleanup = nouveau_debugfs_takedown,395#endif396.irq_preinstall = nouveau_irq_preinstall,397.irq_postinstall = nouveau_irq_postinstall,398.irq_uninstall = nouveau_irq_uninstall,399.irq_handler = nouveau_irq_handler,400.get_vblank_counter = drm_vblank_count,401.enable_vblank = nouveau_vblank_enable,402.disable_vblank = nouveau_vblank_disable,403.reclaim_buffers = drm_core_reclaim_buffers,404.ioctls = nouveau_ioctls,405.fops = {406.owner = THIS_MODULE,407.open = drm_open,408.release = drm_release,409.unlocked_ioctl = drm_ioctl,410.mmap = nouveau_ttm_mmap,411.poll = drm_poll,412.fasync = drm_fasync,413.read = drm_read,414#if defined(CONFIG_COMPAT)415.compat_ioctl = nouveau_compat_ioctl,416#endif417.llseek = noop_llseek,418},419420.gem_init_object = nouveau_gem_object_new,421.gem_free_object = nouveau_gem_object_del,422423.name = DRIVER_NAME,424.desc = DRIVER_DESC,425#ifdef GIT_REVISION426.date = GIT_REVISION,427#else428.date = DRIVER_DATE,429#endif430.major = DRIVER_MAJOR,431.minor = DRIVER_MINOR,432.patchlevel = DRIVER_PATCHLEVEL,433};434435static struct pci_driver nouveau_pci_driver = {436.name = DRIVER_NAME,437.id_table = pciidlist,438.probe = nouveau_pci_probe,439.remove = nouveau_pci_remove,440.suspend = nouveau_pci_suspend,441.resume = nouveau_pci_resume442};443444static int __init nouveau_init(void)445{446driver.num_ioctls = nouveau_max_ioctl;447448if (nouveau_modeset == -1) {449#ifdef CONFIG_VGA_CONSOLE450if (vgacon_text_force())451nouveau_modeset = 0;452else453#endif454nouveau_modeset = 1;455}456457if (!nouveau_modeset)458return 0;459460nouveau_register_dsm_handler();461return drm_pci_init(&driver, &nouveau_pci_driver);462}463464static void __exit nouveau_exit(void)465{466if (!nouveau_modeset)467return;468469drm_pci_exit(&driver, &nouveau_pci_driver);470nouveau_unregister_dsm_handler();471}472473module_init(nouveau_init);474module_exit(nouveau_exit);475476MODULE_AUTHOR(DRIVER_AUTHOR);477MODULE_DESCRIPTION(DRIVER_DESC);478MODULE_LICENSE("GPL and additional rights");479480481