15c49fd3aSAlan Cox /************************************************************************** 25c49fd3aSAlan Cox * Copyright (c) 2007-2011, Intel Corporation. 35c49fd3aSAlan Cox * All Rights Reserved. 45c49fd3aSAlan Cox * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA. 55c49fd3aSAlan Cox * All Rights Reserved. 65c49fd3aSAlan Cox * 75c49fd3aSAlan Cox * This program is free software; you can redistribute it and/or modify it 85c49fd3aSAlan Cox * under the terms and conditions of the GNU General Public License, 95c49fd3aSAlan Cox * version 2, as published by the Free Software Foundation. 105c49fd3aSAlan Cox * 115c49fd3aSAlan Cox * This program is distributed in the hope it will be useful, but WITHOUT 125c49fd3aSAlan Cox * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 135c49fd3aSAlan Cox * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 145c49fd3aSAlan Cox * more details. 155c49fd3aSAlan Cox * 165c49fd3aSAlan Cox * You should have received a copy of the GNU General Public License along with 175c49fd3aSAlan Cox * this program; if not, write to the Free Software Foundation, Inc., 185c49fd3aSAlan Cox * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 195c49fd3aSAlan Cox * 205c49fd3aSAlan Cox **************************************************************************/ 215c49fd3aSAlan Cox 225c49fd3aSAlan Cox #include <drm/drmP.h> 235c49fd3aSAlan Cox #include <drm/drm.h> 245c49fd3aSAlan Cox #include "psb_drv.h" 255c49fd3aSAlan Cox #include "framebuffer.h" 265c49fd3aSAlan Cox #include "psb_reg.h" 275c49fd3aSAlan Cox #include "psb_intel_reg.h" 285c49fd3aSAlan Cox #include "intel_bios.h" 295c49fd3aSAlan Cox #include "mid_bios.h" 305c49fd3aSAlan Cox #include <drm/drm_pciids.h> 315c49fd3aSAlan Cox #include "power.h" 325c49fd3aSAlan Cox #include <linux/cpu.h> 335c49fd3aSAlan Cox #include <linux/notifier.h> 345c49fd3aSAlan Cox #include <linux/spinlock.h> 355c49fd3aSAlan Cox #include <linux/pm_runtime.h> 365c49fd3aSAlan Cox #include <acpi/video.h> 37af3a2cfbSDave Airlie #include <linux/module.h> 385c49fd3aSAlan Cox 395c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 405c49fd3aSAlan Cox 415c49fd3aSAlan Cox static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { 425c49fd3aSAlan Cox { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 435c49fd3aSAlan Cox { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 440cecdd81SAlan Cox #if defined(CONFIG_DRM_GMA600) 455c49fd3aSAlan Cox { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 465c49fd3aSAlan Cox { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 475c49fd3aSAlan Cox { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 485c49fd3aSAlan Cox { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 495c49fd3aSAlan Cox { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 505c49fd3aSAlan Cox { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 515c49fd3aSAlan Cox { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 525c49fd3aSAlan Cox { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 5356125db1SAlan Cox /* Atom E620 */ 5456125db1SAlan Cox { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 555c49fd3aSAlan Cox #endif 56026abc33SKirill A. Shutemov #if defined(CONFIG_DRM_MEDFIELD) 57026abc33SKirill A. Shutemov {0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 58026abc33SKirill A. Shutemov {0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 59026abc33SKirill A. Shutemov {0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 60026abc33SKirill A. Shutemov {0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 61026abc33SKirill A. Shutemov {0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 62026abc33SKirill A. Shutemov {0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 63026abc33SKirill A. Shutemov {0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 64026abc33SKirill A. Shutemov {0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops}, 65026abc33SKirill A. Shutemov #endif 66b6195aabSAlan Cox #if defined(CONFIG_DRM_GMA3600) 675c49fd3aSAlan Cox { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 685c49fd3aSAlan Cox { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 695c49fd3aSAlan Cox { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 705c49fd3aSAlan Cox { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 715c49fd3aSAlan Cox { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 725c49fd3aSAlan Cox { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 735c49fd3aSAlan Cox { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 745c49fd3aSAlan Cox { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 759aa65a2bSAlan Cox { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 769aa65a2bSAlan Cox { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 779aa65a2bSAlan Cox { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 789aa65a2bSAlan Cox { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 799aa65a2bSAlan Cox { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 809aa65a2bSAlan Cox { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 819aa65a2bSAlan Cox { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 829aa65a2bSAlan Cox { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 835c49fd3aSAlan Cox #endif 84aa53f533SKirill A. Shutemov { 0, } 855c49fd3aSAlan Cox }; 865c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist); 875c49fd3aSAlan Cox 885c49fd3aSAlan Cox /* 895c49fd3aSAlan Cox * Standard IOCTLs. 905c49fd3aSAlan Cox */ 91baa70943SRob Clark static const struct drm_ioctl_desc psb_ioctls[] = { 925c49fd3aSAlan Cox }; 935c49fd3aSAlan Cox 945c49fd3aSAlan Cox static void psb_lastclose(struct drm_device *dev) 955c49fd3aSAlan Cox { 967147573aSDaniel Vetter int ret; 977147573aSDaniel Vetter struct drm_psb_private *dev_priv = dev->dev_private; 987147573aSDaniel Vetter struct psb_fbdev *fbdev = dev_priv->fbdev; 997147573aSDaniel Vetter 1000a819515SDaniel Vetter drm_modeset_lock_all(dev); 1017147573aSDaniel Vetter ret = drm_fb_helper_restore_fbdev_mode(&fbdev->psb_fb_helper); 1027147573aSDaniel Vetter if (ret) 1037147573aSDaniel Vetter DRM_DEBUG("failed to restore crtc mode\n"); 1040a819515SDaniel Vetter drm_modeset_unlock_all(dev); 1057147573aSDaniel Vetter 1065c49fd3aSAlan Cox return; 1075c49fd3aSAlan Cox } 1085c49fd3aSAlan Cox 1095c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev) 1105c49fd3aSAlan Cox { 1115c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1125c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1135c49fd3aSAlan Cox 1145c49fd3aSAlan Cox uint32_t stolen_gtt; 1155c49fd3aSAlan Cox 1165c49fd3aSAlan Cox if (pg->mmu_gatt_start & 0x0FFFFFFF) { 1175c49fd3aSAlan Cox dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); 118*af3765c7SArthur Borsboom return -EINVAL; 1195c49fd3aSAlan Cox } 1205c49fd3aSAlan Cox 1215c49fd3aSAlan Cox 1225c49fd3aSAlan Cox stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; 1235c49fd3aSAlan Cox stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; 1245c49fd3aSAlan Cox stolen_gtt = 1255c49fd3aSAlan Cox (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; 1265c49fd3aSAlan Cox 1275c49fd3aSAlan Cox dev_priv->gatt_free_offset = pg->mmu_gatt_start + 1285c49fd3aSAlan Cox (stolen_gtt << PAGE_SHIFT) * 1024; 1295c49fd3aSAlan Cox 1305c49fd3aSAlan Cox spin_lock_init(&dev_priv->irqmask_lock); 1319242fe23SAlan Cox spin_lock_init(&dev_priv->lock_2d); 1325c49fd3aSAlan Cox 1335c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); 1345c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); 1355c49fd3aSAlan Cox PSB_RSGX32(PSB_CR_BIF_BANK1); 136ae012bdcSPatrik Jakobsson 137ae012bdcSPatrik Jakobsson /* Do not bypass any MMU access, let them pagefault instead */ 138ae012bdcSPatrik Jakobsson PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK), 1395c49fd3aSAlan Cox PSB_CR_BIF_CTRL); 140ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_CTRL); 141ae012bdcSPatrik Jakobsson 1425c49fd3aSAlan Cox psb_spank(dev_priv); 1435c49fd3aSAlan Cox 1445c49fd3aSAlan Cox /* mmu_gatt ?? */ 1455c49fd3aSAlan Cox PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); 146ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */ 147ae012bdcSPatrik Jakobsson 1485c49fd3aSAlan Cox return 0; 1495c49fd3aSAlan Cox } 1505c49fd3aSAlan Cox 1515c49fd3aSAlan Cox static int psb_driver_unload(struct drm_device *dev) 1525c49fd3aSAlan Cox { 1535c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1545c49fd3aSAlan Cox 1555c49fd3aSAlan Cox /* Kill vblank etc here */ 1565c49fd3aSAlan Cox 1575c49fd3aSAlan Cox 1585c49fd3aSAlan Cox if (dev_priv) { 1594ab2c7f1SAlan Cox if (dev_priv->backlight_device) 1604ab2c7f1SAlan Cox gma_backlight_exit(dev); 1614ab2c7f1SAlan Cox psb_modeset_cleanup(dev); 1625c49fd3aSAlan Cox 1635c49fd3aSAlan Cox if (dev_priv->ops->chip_teardown) 1645c49fd3aSAlan Cox dev_priv->ops->chip_teardown(dev); 1656607e024SAlan Cox 1666607e024SAlan Cox psb_intel_opregion_fini(dev); 1675c49fd3aSAlan Cox 1685c49fd3aSAlan Cox if (dev_priv->pf_pd) { 1695c49fd3aSAlan Cox psb_mmu_free_pagedir(dev_priv->pf_pd); 1705c49fd3aSAlan Cox dev_priv->pf_pd = NULL; 1715c49fd3aSAlan Cox } 1725c49fd3aSAlan Cox if (dev_priv->mmu) { 1735c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1745c49fd3aSAlan Cox 1755c49fd3aSAlan Cox down_read(&pg->sem); 1765c49fd3aSAlan Cox psb_mmu_remove_pfn_sequence( 1775c49fd3aSAlan Cox psb_mmu_get_default_pd 1785c49fd3aSAlan Cox (dev_priv->mmu), 1795c49fd3aSAlan Cox pg->mmu_gatt_start, 1805c49fd3aSAlan Cox dev_priv->vram_stolen_size >> PAGE_SHIFT); 1815c49fd3aSAlan Cox up_read(&pg->sem); 1825c49fd3aSAlan Cox psb_mmu_driver_takedown(dev_priv->mmu); 1835c49fd3aSAlan Cox dev_priv->mmu = NULL; 1845c49fd3aSAlan Cox } 1855c49fd3aSAlan Cox psb_gtt_takedown(dev); 1865c49fd3aSAlan Cox if (dev_priv->scratch_page) { 1871896344bSAlan Cox set_pages_wb(dev_priv->scratch_page, 1); 1885c49fd3aSAlan Cox __free_page(dev_priv->scratch_page); 1895c49fd3aSAlan Cox dev_priv->scratch_page = NULL; 1905c49fd3aSAlan Cox } 1915c49fd3aSAlan Cox if (dev_priv->vdc_reg) { 1925c49fd3aSAlan Cox iounmap(dev_priv->vdc_reg); 1935c49fd3aSAlan Cox dev_priv->vdc_reg = NULL; 1945c49fd3aSAlan Cox } 1955c49fd3aSAlan Cox if (dev_priv->sgx_reg) { 1965c49fd3aSAlan Cox iounmap(dev_priv->sgx_reg); 1975c49fd3aSAlan Cox dev_priv->sgx_reg = NULL; 1985c49fd3aSAlan Cox } 1992657929dSPatrik Jakobsson if (dev_priv->aux_reg) { 2002657929dSPatrik Jakobsson iounmap(dev_priv->aux_reg); 2012657929dSPatrik Jakobsson dev_priv->aux_reg = NULL; 2022657929dSPatrik Jakobsson } 2032657929dSPatrik Jakobsson if (dev_priv->aux_pdev) 2042657929dSPatrik Jakobsson pci_dev_put(dev_priv->aux_pdev); 2055c49fd3aSAlan Cox 2064ab2c7f1SAlan Cox /* Destroy VBT data */ 2074ab2c7f1SAlan Cox psb_intel_destroy_bios(dev); 2084ab2c7f1SAlan Cox 2095c49fd3aSAlan Cox kfree(dev_priv); 2105c49fd3aSAlan Cox dev->dev_private = NULL; 2115c49fd3aSAlan Cox } 2125c49fd3aSAlan Cox gma_power_uninit(dev); 2135c49fd3aSAlan Cox return 0; 2145c49fd3aSAlan Cox } 2155c49fd3aSAlan Cox 2165c49fd3aSAlan Cox 2175c49fd3aSAlan Cox static int psb_driver_load(struct drm_device *dev, unsigned long chipset) 2185c49fd3aSAlan Cox { 2195c49fd3aSAlan Cox struct drm_psb_private *dev_priv; 2202657929dSPatrik Jakobsson unsigned long resource_start, resource_len; 2215c49fd3aSAlan Cox unsigned long irqflags; 2225c49fd3aSAlan Cox int ret = -ENOMEM; 2235c49fd3aSAlan Cox struct drm_connector *connector; 224367e4408SPatrik Jakobsson struct gma_encoder *gma_encoder; 225ae012bdcSPatrik Jakobsson struct psb_gtt *pg; 2265c49fd3aSAlan Cox 2275c49fd3aSAlan Cox dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 2285c49fd3aSAlan Cox if (dev_priv == NULL) 2295c49fd3aSAlan Cox return -ENOMEM; 2305c49fd3aSAlan Cox 2315c49fd3aSAlan Cox dev_priv->ops = (struct psb_ops *)chipset; 2325c49fd3aSAlan Cox dev_priv->dev = dev; 2335c49fd3aSAlan Cox dev->dev_private = (void *) dev_priv; 2345c49fd3aSAlan Cox 235ae012bdcSPatrik Jakobsson pg = &dev_priv->gtt; 236ae012bdcSPatrik Jakobsson 237466e69b8SDave Airlie pci_set_master(dev->pdev); 238466e69b8SDave Airlie 2395c49fd3aSAlan Cox dev_priv->num_pipe = dev_priv->ops->pipes; 2405c49fd3aSAlan Cox 2415c49fd3aSAlan Cox resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); 2425c49fd3aSAlan Cox 2435c49fd3aSAlan Cox dev_priv->vdc_reg = 2445c49fd3aSAlan Cox ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); 2455c49fd3aSAlan Cox if (!dev_priv->vdc_reg) 2465c49fd3aSAlan Cox goto out_err; 2475c49fd3aSAlan Cox 2485c49fd3aSAlan Cox dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, 2495c49fd3aSAlan Cox PSB_SGX_SIZE); 2505c49fd3aSAlan Cox if (!dev_priv->sgx_reg) 2515c49fd3aSAlan Cox goto out_err; 2525c49fd3aSAlan Cox 2532657929dSPatrik Jakobsson if (IS_MRST(dev)) { 2542657929dSPatrik Jakobsson dev_priv->aux_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(3, 0)); 2552657929dSPatrik Jakobsson 2562657929dSPatrik Jakobsson if (dev_priv->aux_pdev) { 2572657929dSPatrik Jakobsson resource_start = pci_resource_start(dev_priv->aux_pdev, 2582657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2592657929dSPatrik Jakobsson resource_len = pci_resource_len(dev_priv->aux_pdev, 2602657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2612657929dSPatrik Jakobsson dev_priv->aux_reg = ioremap_nocache(resource_start, 2622657929dSPatrik Jakobsson resource_len); 2632657929dSPatrik Jakobsson if (!dev_priv->aux_reg) 2642657929dSPatrik Jakobsson goto out_err; 2652657929dSPatrik Jakobsson 2662657929dSPatrik Jakobsson DRM_DEBUG_KMS("Found aux vdc"); 2672657929dSPatrik Jakobsson } else { 2682657929dSPatrik Jakobsson /* Couldn't find the aux vdc so map to primary vdc */ 2692657929dSPatrik Jakobsson dev_priv->aux_reg = dev_priv->vdc_reg; 2702657929dSPatrik Jakobsson DRM_DEBUG_KMS("Couldn't find aux pci device"); 2712657929dSPatrik Jakobsson } 2722657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->aux_reg; 2732657929dSPatrik Jakobsson } else { 2742657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->vdc_reg; 2752657929dSPatrik Jakobsson } 2762657929dSPatrik Jakobsson 277d839ede4SAlan Cox psb_intel_opregion_setup(dev); 278d839ede4SAlan Cox 2795c49fd3aSAlan Cox ret = dev_priv->ops->chip_setup(dev); 2805c49fd3aSAlan Cox if (ret) 2815c49fd3aSAlan Cox goto out_err; 2825c49fd3aSAlan Cox 2835c49fd3aSAlan Cox /* Init OSPM support */ 2845c49fd3aSAlan Cox gma_power_init(dev); 2855c49fd3aSAlan Cox 2865c49fd3aSAlan Cox ret = -ENOMEM; 2875c49fd3aSAlan Cox 2885c49fd3aSAlan Cox dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); 2895c49fd3aSAlan Cox if (!dev_priv->scratch_page) 2905c49fd3aSAlan Cox goto out_err; 2915c49fd3aSAlan Cox 2925c49fd3aSAlan Cox set_pages_uc(dev_priv->scratch_page, 1); 2935c49fd3aSAlan Cox 2945c49fd3aSAlan Cox ret = psb_gtt_init(dev, 0); 2955c49fd3aSAlan Cox if (ret) 2965c49fd3aSAlan Cox goto out_err; 2975c49fd3aSAlan Cox 2988f394872SPatrik Jakobsson dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0); 2995c49fd3aSAlan Cox if (!dev_priv->mmu) 3005c49fd3aSAlan Cox goto out_err; 3015c49fd3aSAlan Cox 3025c49fd3aSAlan Cox dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); 3035c49fd3aSAlan Cox if (!dev_priv->pf_pd) 3045c49fd3aSAlan Cox goto out_err; 3055c49fd3aSAlan Cox 3065c49fd3aSAlan Cox ret = psb_do_init(dev); 3075c49fd3aSAlan Cox if (ret) 3085c49fd3aSAlan Cox return ret; 3095c49fd3aSAlan Cox 310ae012bdcSPatrik Jakobsson /* Add stolen memory to SGX MMU */ 311ae012bdcSPatrik Jakobsson down_read(&pg->sem); 312ae012bdcSPatrik Jakobsson ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu), 313ae012bdcSPatrik Jakobsson dev_priv->stolen_base >> PAGE_SHIFT, 314ae012bdcSPatrik Jakobsson pg->gatt_start, 315ae012bdcSPatrik Jakobsson pg->stolen_size >> PAGE_SHIFT, 0); 316ae012bdcSPatrik Jakobsson up_read(&pg->sem); 317ae012bdcSPatrik Jakobsson 318ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); 319ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(dev_priv->pf_pd, 1); 320ae012bdcSPatrik Jakobsson 3215c49fd3aSAlan Cox PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); 3225c49fd3aSAlan Cox PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); 3235c49fd3aSAlan Cox 324d839ede4SAlan Cox acpi_video_register(); 3255c49fd3aSAlan Cox 3265c49fd3aSAlan Cox ret = drm_vblank_init(dev, dev_priv->num_pipe); 3275c49fd3aSAlan Cox if (ret) 3285c49fd3aSAlan Cox goto out_err; 3295c49fd3aSAlan Cox 3305c49fd3aSAlan Cox /* 3315c49fd3aSAlan Cox * Install interrupt handlers prior to powering off SGX or else we will 3325c49fd3aSAlan Cox * crash. 3335c49fd3aSAlan Cox */ 3345c49fd3aSAlan Cox dev_priv->vdc_irq_mask = 0; 3355c49fd3aSAlan Cox dev_priv->pipestat[0] = 0; 3365c49fd3aSAlan Cox dev_priv->pipestat[1] = 0; 3375c49fd3aSAlan Cox dev_priv->pipestat[2] = 0; 3385c49fd3aSAlan Cox spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 3395c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 3405c49fd3aSAlan Cox PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); 3415c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); 3425c49fd3aSAlan Cox spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); 34362363a48SAlan Cox 3445c49fd3aSAlan Cox drm_irq_install(dev); 3455c49fd3aSAlan Cox 346ba0bf120SVille Syrjälä dev->vblank_disable_allowed = true; 3475c49fd3aSAlan Cox 3485c49fd3aSAlan Cox dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3495c49fd3aSAlan Cox 3505c49fd3aSAlan Cox dev->driver->get_vblank_counter = psb_get_vblank_counter; 3515c49fd3aSAlan Cox 3525c49fd3aSAlan Cox psb_modeset_init(dev); 3535c49fd3aSAlan Cox psb_fbdev_init(dev); 3545c49fd3aSAlan Cox drm_kms_helper_poll_init(dev); 3555c49fd3aSAlan Cox 3565c49fd3aSAlan Cox /* Only add backlight support if we have LVDS output */ 3575c49fd3aSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 3585c49fd3aSAlan Cox head) { 359367e4408SPatrik Jakobsson gma_encoder = gma_attached_encoder(connector); 3605c49fd3aSAlan Cox 361367e4408SPatrik Jakobsson switch (gma_encoder->type) { 3625c49fd3aSAlan Cox case INTEL_OUTPUT_LVDS: 3635c49fd3aSAlan Cox case INTEL_OUTPUT_MIPI: 3645c49fd3aSAlan Cox ret = gma_backlight_init(dev); 3655c49fd3aSAlan Cox break; 3665c49fd3aSAlan Cox } 3675c49fd3aSAlan Cox } 3685c49fd3aSAlan Cox 3695c49fd3aSAlan Cox if (ret) 3705c49fd3aSAlan Cox return ret; 371166973e5SAlan Cox psb_intel_opregion_enable_asle(dev); 3725c49fd3aSAlan Cox #if 0 3735c49fd3aSAlan Cox /*enable runtime pm at last*/ 3745c49fd3aSAlan Cox pm_runtime_enable(&dev->pdev->dev); 3755c49fd3aSAlan Cox pm_runtime_set_active(&dev->pdev->dev); 3765c49fd3aSAlan Cox #endif 3775c49fd3aSAlan Cox /*Intel drm driver load is done, continue doing pvr load*/ 3785c49fd3aSAlan Cox return 0; 3795c49fd3aSAlan Cox out_err: 3805c49fd3aSAlan Cox psb_driver_unload(dev); 3815c49fd3aSAlan Cox return ret; 3825c49fd3aSAlan Cox } 3835c49fd3aSAlan Cox 38415308e23SKirill A. Shutemov static int psb_driver_device_is_agp(struct drm_device *dev) 3855c49fd3aSAlan Cox { 3865c49fd3aSAlan Cox return 0; 3875c49fd3aSAlan Cox } 3885c49fd3aSAlan Cox 3895c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd) 3905c49fd3aSAlan Cox { 3915c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE 3925c49fd3aSAlan Cox if (bd) { 3935c49fd3aSAlan Cox bd->props.brightness = bd->ops->get_brightness(bd); 3945c49fd3aSAlan Cox backlight_update_status(bd); 3955c49fd3aSAlan Cox } 3965c49fd3aSAlan Cox #endif 3975c49fd3aSAlan Cox } 3985c49fd3aSAlan Cox 3995c49fd3aSAlan Cox static int psb_driver_open(struct drm_device *dev, struct drm_file *priv) 4005c49fd3aSAlan Cox { 4015c49fd3aSAlan Cox return 0; 4025c49fd3aSAlan Cox } 4035c49fd3aSAlan Cox 4045c49fd3aSAlan Cox static void psb_driver_close(struct drm_device *dev, struct drm_file *priv) 4055c49fd3aSAlan Cox { 4065c49fd3aSAlan Cox } 4075c49fd3aSAlan Cox 4085c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, 4095c49fd3aSAlan Cox unsigned long arg) 4105c49fd3aSAlan Cox { 4115c49fd3aSAlan Cox struct drm_file *file_priv = filp->private_data; 4125c49fd3aSAlan Cox struct drm_device *dev = file_priv->minor->dev; 4135c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 4145c49fd3aSAlan Cox static unsigned int runtime_allowed; 4155c49fd3aSAlan Cox 4165c49fd3aSAlan Cox if (runtime_allowed == 1 && dev_priv->is_lvds_on) { 4175c49fd3aSAlan Cox runtime_allowed++; 4185c49fd3aSAlan Cox pm_runtime_allow(&dev->pdev->dev); 4195c49fd3aSAlan Cox dev_priv->rpm_enabled = 1; 4205c49fd3aSAlan Cox } 4215c49fd3aSAlan Cox return drm_ioctl(filp, cmd, arg); 4225c49fd3aSAlan Cox /* FIXME: do we need to wrap the other side of this */ 4235c49fd3aSAlan Cox } 4245c49fd3aSAlan Cox 4255c49fd3aSAlan Cox 4265c49fd3aSAlan Cox /* When a client dies: 4275c49fd3aSAlan Cox * - Check for and clean up flipped page state 4285c49fd3aSAlan Cox */ 42915308e23SKirill A. Shutemov static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv) 4305c49fd3aSAlan Cox { 4315c49fd3aSAlan Cox } 4325c49fd3aSAlan Cox 4335c49fd3aSAlan Cox static void psb_remove(struct pci_dev *pdev) 4345c49fd3aSAlan Cox { 4355c49fd3aSAlan Cox struct drm_device *dev = pci_get_drvdata(pdev); 4365c49fd3aSAlan Cox drm_put_dev(dev); 4375c49fd3aSAlan Cox } 4385c49fd3aSAlan Cox 4395c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = { 4405c49fd3aSAlan Cox .resume = gma_power_resume, 4415c49fd3aSAlan Cox .suspend = gma_power_suspend, 442888eef2eSPatrik Jakobsson .thaw = gma_power_thaw, 443888eef2eSPatrik Jakobsson .freeze = gma_power_freeze, 444888eef2eSPatrik Jakobsson .restore = gma_power_restore, 4455c49fd3aSAlan Cox .runtime_suspend = psb_runtime_suspend, 4465c49fd3aSAlan Cox .runtime_resume = psb_runtime_resume, 4475c49fd3aSAlan Cox .runtime_idle = psb_runtime_idle, 4485c49fd3aSAlan Cox }; 4495c49fd3aSAlan Cox 45078b68556SLaurent Pinchart static const struct vm_operations_struct psb_gem_vm_ops = { 4515c49fd3aSAlan Cox .fault = psb_gem_fault, 4525c49fd3aSAlan Cox .open = drm_gem_vm_open, 4535c49fd3aSAlan Cox .close = drm_gem_vm_close, 4545c49fd3aSAlan Cox }; 4555c49fd3aSAlan Cox 4561595c568SIlija Hadzic static const struct file_operations psb_gem_fops = { 4571595c568SIlija Hadzic .owner = THIS_MODULE, 4581595c568SIlija Hadzic .open = drm_open, 4591595c568SIlija Hadzic .release = drm_release, 4601595c568SIlija Hadzic .unlocked_ioctl = psb_unlocked_ioctl, 4611595c568SIlija Hadzic .mmap = drm_gem_mmap, 4621595c568SIlija Hadzic .poll = drm_poll, 4631595c568SIlija Hadzic .read = drm_read, 4641595c568SIlija Hadzic }; 4651595c568SIlija Hadzic 4665c49fd3aSAlan Cox static struct drm_driver driver = { 4675c49fd3aSAlan Cox .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ 46874867e3dSDaniel Vetter DRIVER_MODESET | DRIVER_GEM , 4695c49fd3aSAlan Cox .load = psb_driver_load, 4705c49fd3aSAlan Cox .unload = psb_driver_unload, 4715c49fd3aSAlan Cox 4725c49fd3aSAlan Cox .ioctls = psb_ioctls, 4735c49fd3aSAlan Cox .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls), 4745c49fd3aSAlan Cox .device_is_agp = psb_driver_device_is_agp, 4755c49fd3aSAlan Cox .irq_preinstall = psb_irq_preinstall, 4765c49fd3aSAlan Cox .irq_postinstall = psb_irq_postinstall, 4775c49fd3aSAlan Cox .irq_uninstall = psb_irq_uninstall, 4785c49fd3aSAlan Cox .irq_handler = psb_irq_handler, 4795c49fd3aSAlan Cox .enable_vblank = psb_enable_vblank, 4805c49fd3aSAlan Cox .disable_vblank = psb_disable_vblank, 4815c49fd3aSAlan Cox .get_vblank_counter = psb_get_vblank_counter, 4825c49fd3aSAlan Cox .lastclose = psb_lastclose, 4835c49fd3aSAlan Cox .open = psb_driver_open, 4845c49fd3aSAlan Cox .preclose = psb_driver_preclose, 4855c49fd3aSAlan Cox .postclose = psb_driver_close, 4865c49fd3aSAlan Cox 4875c49fd3aSAlan Cox .gem_free_object = psb_gem_free_object, 4885c49fd3aSAlan Cox .gem_vm_ops = &psb_gem_vm_ops, 4895c49fd3aSAlan Cox .dumb_create = psb_gem_dumb_create, 4905c49fd3aSAlan Cox .dumb_map_offset = psb_gem_dumb_map_gtt, 49143387b37SDaniel Vetter .dumb_destroy = drm_gem_dumb_destroy, 4921595c568SIlija Hadzic .fops = &psb_gem_fops, 4935c49fd3aSAlan Cox .name = DRIVER_NAME, 4945c49fd3aSAlan Cox .desc = DRIVER_DESC, 4955c49fd3aSAlan Cox .date = PSB_DRM_DRIVER_DATE, 4965c49fd3aSAlan Cox .major = PSB_DRM_DRIVER_MAJOR, 4975c49fd3aSAlan Cox .minor = PSB_DRM_DRIVER_MINOR, 4985c49fd3aSAlan Cox .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL 4995c49fd3aSAlan Cox }; 5005c49fd3aSAlan Cox 5015c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = { 5025c49fd3aSAlan Cox .name = DRIVER_NAME, 5035c49fd3aSAlan Cox .id_table = pciidlist, 5045c49fd3aSAlan Cox .probe = psb_probe, 5055c49fd3aSAlan Cox .remove = psb_remove, 506aa53f533SKirill A. Shutemov .driver = { 507aa53f533SKirill A. Shutemov .pm = &psb_pm_ops, 508aa53f533SKirill A. Shutemov } 5095c49fd3aSAlan Cox }; 5105c49fd3aSAlan Cox 5115c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 5125c49fd3aSAlan Cox { 5135c49fd3aSAlan Cox return drm_get_pci_dev(pdev, ent, &driver); 5145c49fd3aSAlan Cox } 5155c49fd3aSAlan Cox 5165c49fd3aSAlan Cox static int __init psb_init(void) 5175c49fd3aSAlan Cox { 5185c49fd3aSAlan Cox return drm_pci_init(&driver, &psb_pci_driver); 5195c49fd3aSAlan Cox } 5205c49fd3aSAlan Cox 5215c49fd3aSAlan Cox static void __exit psb_exit(void) 5225c49fd3aSAlan Cox { 5235c49fd3aSAlan Cox drm_pci_exit(&driver, &psb_pci_driver); 5245c49fd3aSAlan Cox } 5255c49fd3aSAlan Cox 5265c49fd3aSAlan Cox late_initcall(psb_init); 5275c49fd3aSAlan Cox module_exit(psb_exit); 5285c49fd3aSAlan Cox 5295c49fd3aSAlan Cox MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others"); 5305c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC); 5315c49fd3aSAlan Cox MODULE_LICENSE("GPL"); 532