1a61127c2SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 25c49fd3aSAlan Cox /************************************************************************** 35c49fd3aSAlan Cox * Copyright (c) 2007-2011, Intel Corporation. 45c49fd3aSAlan Cox * All Rights Reserved. 55c49fd3aSAlan Cox * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA. 65c49fd3aSAlan Cox * All Rights Reserved. 75c49fd3aSAlan Cox * 85c49fd3aSAlan Cox **************************************************************************/ 95c49fd3aSAlan Cox 100c7b178aSSam Ravnborg #include <linux/cpu.h> 110c7b178aSSam Ravnborg #include <linux/module.h> 120c7b178aSSam Ravnborg #include <linux/notifier.h> 130c7b178aSSam Ravnborg #include <linux/pm_runtime.h> 140c7b178aSSam Ravnborg #include <linux/spinlock.h> 150c7b178aSSam Ravnborg 160c7b178aSSam Ravnborg #include <asm/set_memory.h> 170c7b178aSSam Ravnborg 180c7b178aSSam Ravnborg #include <acpi/video.h> 190c7b178aSSam Ravnborg 205c49fd3aSAlan Cox #include <drm/drm.h> 210c7b178aSSam Ravnborg #include <drm/drm_drv.h> 226b7ce2c4SThomas Zimmermann #include <drm/drm_fb_helper.h> 230c7b178aSSam Ravnborg #include <drm/drm_file.h> 240c7b178aSSam Ravnborg #include <drm/drm_ioctl.h> 250c7b178aSSam Ravnborg #include <drm/drm_irq.h> 260c7b178aSSam Ravnborg #include <drm/drm_pciids.h> 270c7b178aSSam Ravnborg #include <drm/drm_vblank.h> 280c7b178aSSam Ravnborg 295c49fd3aSAlan Cox #include "framebuffer.h" 305c49fd3aSAlan Cox #include "intel_bios.h" 315c49fd3aSAlan Cox #include "mid_bios.h" 325c49fd3aSAlan Cox #include "power.h" 330c7b178aSSam Ravnborg #include "psb_drv.h" 340c7b178aSSam Ravnborg #include "psb_intel_reg.h" 350c7b178aSSam Ravnborg #include "psb_reg.h" 365c49fd3aSAlan Cox 3770a59dd8SDaniel Vetter static const struct drm_driver driver; 38f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 395c49fd3aSAlan Cox 409083eb38SArthur Borsboom /* 419083eb38SArthur Borsboom * The table below contains a mapping of the PCI vendor ID and the PCI Device ID 429083eb38SArthur Borsboom * to the different groups of PowerVR 5-series chip designs 439083eb38SArthur Borsboom * 449083eb38SArthur Borsboom * 0x8086 = Intel Corporation 459083eb38SArthur Borsboom * 469083eb38SArthur Borsboom * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx 479083eb38SArthur Borsboom * PowerVR SGX535 - Moorestown - Intel GMA 600 489083eb38SArthur Borsboom * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx 499083eb38SArthur Borsboom * PowerVR SGX540 - Medfield - Intel Atom Z2460 509083eb38SArthur Borsboom * PowerVR SGX544MP2 - Medfield - 519083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600 529083eb38SArthur Borsboom * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700, 539083eb38SArthur Borsboom * N2800 549083eb38SArthur Borsboom */ 559baa3c34SBenoit Taine static const struct pci_device_id pciidlist[] = { 565c49fd3aSAlan Cox { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 575c49fd3aSAlan Cox { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 580cecdd81SAlan Cox #if defined(CONFIG_DRM_GMA600) 595c49fd3aSAlan Cox { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 605c49fd3aSAlan Cox { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 615c49fd3aSAlan Cox { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 625c49fd3aSAlan Cox { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 635c49fd3aSAlan Cox { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 645c49fd3aSAlan Cox { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 655c49fd3aSAlan Cox { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 665c49fd3aSAlan Cox { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 6756125db1SAlan Cox { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, 685c49fd3aSAlan Cox #endif 69026abc33SKirill A. Shutemov #if defined(CONFIG_DRM_MEDFIELD) 70026abc33SKirill A. Shutemov { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 71026abc33SKirill A. Shutemov { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 72026abc33SKirill A. Shutemov { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 73026abc33SKirill A. Shutemov { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 74026abc33SKirill A. Shutemov { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 75026abc33SKirill A. Shutemov { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 76026abc33SKirill A. Shutemov { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 77026abc33SKirill A. Shutemov { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, 78026abc33SKirill A. Shutemov #endif 79b6195aabSAlan Cox #if defined(CONFIG_DRM_GMA3600) 805c49fd3aSAlan Cox { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 815c49fd3aSAlan Cox { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 825c49fd3aSAlan Cox { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 835c49fd3aSAlan Cox { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 845c49fd3aSAlan Cox { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 855c49fd3aSAlan Cox { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 865c49fd3aSAlan Cox { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 875c49fd3aSAlan Cox { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 889aa65a2bSAlan Cox { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 899aa65a2bSAlan Cox { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 909aa65a2bSAlan Cox { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 919aa65a2bSAlan Cox { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 929aa65a2bSAlan Cox { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 939aa65a2bSAlan Cox { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 949aa65a2bSAlan Cox { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 959aa65a2bSAlan Cox { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, 965c49fd3aSAlan Cox #endif 97aa53f533SKirill A. Shutemov { 0, } 985c49fd3aSAlan Cox }; 995c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist); 1005c49fd3aSAlan Cox 1015c49fd3aSAlan Cox /* 1025c49fd3aSAlan Cox * Standard IOCTLs. 1035c49fd3aSAlan Cox */ 104baa70943SRob Clark static const struct drm_ioctl_desc psb_ioctls[] = { 1055c49fd3aSAlan Cox }; 1065c49fd3aSAlan Cox 1075c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev) 1085c49fd3aSAlan Cox { 1095c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1105c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1115c49fd3aSAlan Cox 1125c49fd3aSAlan Cox uint32_t stolen_gtt; 1135c49fd3aSAlan Cox 1145c49fd3aSAlan Cox if (pg->mmu_gatt_start & 0x0FFFFFFF) { 1155c49fd3aSAlan Cox dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); 116af3765c7SArthur Borsboom return -EINVAL; 1175c49fd3aSAlan Cox } 1185c49fd3aSAlan Cox 1195c49fd3aSAlan Cox stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; 1205c49fd3aSAlan Cox stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; 121f90cd811SArthur Borsboom stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; 1225c49fd3aSAlan Cox 1235c49fd3aSAlan Cox dev_priv->gatt_free_offset = pg->mmu_gatt_start + 1245c49fd3aSAlan Cox (stolen_gtt << PAGE_SHIFT) * 1024; 1255c49fd3aSAlan Cox 1265c49fd3aSAlan Cox spin_lock_init(&dev_priv->irqmask_lock); 1275c49fd3aSAlan Cox 1285c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); 1295c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); 1305c49fd3aSAlan Cox PSB_RSGX32(PSB_CR_BIF_BANK1); 131ae012bdcSPatrik Jakobsson 132ae012bdcSPatrik Jakobsson /* Do not bypass any MMU access, let them pagefault instead */ 133ae012bdcSPatrik Jakobsson PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK), 1345c49fd3aSAlan Cox PSB_CR_BIF_CTRL); 135ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_CTRL); 136ae012bdcSPatrik Jakobsson 1375c49fd3aSAlan Cox psb_spank(dev_priv); 1385c49fd3aSAlan Cox 1395c49fd3aSAlan Cox /* mmu_gatt ?? */ 1405c49fd3aSAlan Cox PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); 141ae012bdcSPatrik Jakobsson PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */ 142ae012bdcSPatrik Jakobsson 1435c49fd3aSAlan Cox return 0; 1445c49fd3aSAlan Cox } 1455c49fd3aSAlan Cox 14611b3c20bSGabriel Krisman Bertazi static void psb_driver_unload(struct drm_device *dev) 1475c49fd3aSAlan Cox { 1485c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1495c49fd3aSAlan Cox 1509083eb38SArthur Borsboom /* TODO: Kill vblank etc here */ 1515c49fd3aSAlan Cox 1525c49fd3aSAlan Cox if (dev_priv) { 1534ab2c7f1SAlan Cox if (dev_priv->backlight_device) 1544ab2c7f1SAlan Cox gma_backlight_exit(dev); 1554ab2c7f1SAlan Cox psb_modeset_cleanup(dev); 1565c49fd3aSAlan Cox 1575c49fd3aSAlan Cox if (dev_priv->ops->chip_teardown) 1585c49fd3aSAlan Cox dev_priv->ops->chip_teardown(dev); 1596607e024SAlan Cox 1606607e024SAlan Cox psb_intel_opregion_fini(dev); 1615c49fd3aSAlan Cox 1625c49fd3aSAlan Cox if (dev_priv->pf_pd) { 1635c49fd3aSAlan Cox psb_mmu_free_pagedir(dev_priv->pf_pd); 1645c49fd3aSAlan Cox dev_priv->pf_pd = NULL; 1655c49fd3aSAlan Cox } 1665c49fd3aSAlan Cox if (dev_priv->mmu) { 1675c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 1685c49fd3aSAlan Cox 1695c49fd3aSAlan Cox down_read(&pg->sem); 1705c49fd3aSAlan Cox psb_mmu_remove_pfn_sequence( 1715c49fd3aSAlan Cox psb_mmu_get_default_pd 1725c49fd3aSAlan Cox (dev_priv->mmu), 1735c49fd3aSAlan Cox pg->mmu_gatt_start, 1745c49fd3aSAlan Cox dev_priv->vram_stolen_size >> PAGE_SHIFT); 1755c49fd3aSAlan Cox up_read(&pg->sem); 1765c49fd3aSAlan Cox psb_mmu_driver_takedown(dev_priv->mmu); 1775c49fd3aSAlan Cox dev_priv->mmu = NULL; 1785c49fd3aSAlan Cox } 1795c49fd3aSAlan Cox psb_gtt_takedown(dev); 1805c49fd3aSAlan Cox if (dev_priv->scratch_page) { 1811896344bSAlan Cox set_pages_wb(dev_priv->scratch_page, 1); 1825c49fd3aSAlan Cox __free_page(dev_priv->scratch_page); 1835c49fd3aSAlan Cox dev_priv->scratch_page = NULL; 1845c49fd3aSAlan Cox } 1855c49fd3aSAlan Cox if (dev_priv->vdc_reg) { 1865c49fd3aSAlan Cox iounmap(dev_priv->vdc_reg); 1875c49fd3aSAlan Cox dev_priv->vdc_reg = NULL; 1885c49fd3aSAlan Cox } 1895c49fd3aSAlan Cox if (dev_priv->sgx_reg) { 1905c49fd3aSAlan Cox iounmap(dev_priv->sgx_reg); 1915c49fd3aSAlan Cox dev_priv->sgx_reg = NULL; 1925c49fd3aSAlan Cox } 1932657929dSPatrik Jakobsson if (dev_priv->aux_reg) { 1942657929dSPatrik Jakobsson iounmap(dev_priv->aux_reg); 1952657929dSPatrik Jakobsson dev_priv->aux_reg = NULL; 1962657929dSPatrik Jakobsson } 1972657929dSPatrik Jakobsson pci_dev_put(dev_priv->aux_pdev); 1985a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 1995c49fd3aSAlan Cox 2004ab2c7f1SAlan Cox /* Destroy VBT data */ 2014ab2c7f1SAlan Cox psb_intel_destroy_bios(dev); 2024ab2c7f1SAlan Cox 2035c49fd3aSAlan Cox kfree(dev_priv); 2045c49fd3aSAlan Cox dev->dev_private = NULL; 2055c49fd3aSAlan Cox } 2065c49fd3aSAlan Cox gma_power_uninit(dev); 2075c49fd3aSAlan Cox } 2085c49fd3aSAlan Cox 209f90cd811SArthur Borsboom static int psb_driver_load(struct drm_device *dev, unsigned long flags) 2105c49fd3aSAlan Cox { 2115c49fd3aSAlan Cox struct drm_psb_private *dev_priv; 2122657929dSPatrik Jakobsson unsigned long resource_start, resource_len; 2135c49fd3aSAlan Cox unsigned long irqflags; 2145c49fd3aSAlan Cox int ret = -ENOMEM; 2155c49fd3aSAlan Cox struct drm_connector *connector; 216367e4408SPatrik Jakobsson struct gma_encoder *gma_encoder; 217ae012bdcSPatrik Jakobsson struct psb_gtt *pg; 2185c49fd3aSAlan Cox 2199083eb38SArthur Borsboom /* allocating and initializing driver private data */ 2205c49fd3aSAlan Cox dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 2215c49fd3aSAlan Cox if (dev_priv == NULL) 2225c49fd3aSAlan Cox return -ENOMEM; 2235c49fd3aSAlan Cox 224f90cd811SArthur Borsboom dev_priv->ops = (struct psb_ops *)flags; 2255c49fd3aSAlan Cox dev_priv->dev = dev; 2265c49fd3aSAlan Cox dev->dev_private = (void *) dev_priv; 2275c49fd3aSAlan Cox 228ae012bdcSPatrik Jakobsson pg = &dev_priv->gtt; 229ae012bdcSPatrik Jakobsson 230466e69b8SDave Airlie pci_set_master(dev->pdev); 231466e69b8SDave Airlie 2325c49fd3aSAlan Cox dev_priv->num_pipe = dev_priv->ops->pipes; 2335c49fd3aSAlan Cox 2345c49fd3aSAlan Cox resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); 2355c49fd3aSAlan Cox 2365c49fd3aSAlan Cox dev_priv->vdc_reg = 2375c49fd3aSAlan Cox ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); 2385c49fd3aSAlan Cox if (!dev_priv->vdc_reg) 2395c49fd3aSAlan Cox goto out_err; 2405c49fd3aSAlan Cox 2415c49fd3aSAlan Cox dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, 2425c49fd3aSAlan Cox PSB_SGX_SIZE); 2435c49fd3aSAlan Cox if (!dev_priv->sgx_reg) 2445c49fd3aSAlan Cox goto out_err; 2455c49fd3aSAlan Cox 2462657929dSPatrik Jakobsson if (IS_MRST(dev)) { 247ba99d834SSinan Kaya int domain = pci_domain_nr(dev->pdev->bus); 248ba99d834SSinan Kaya 249ba99d834SSinan Kaya dev_priv->aux_pdev = 250ba99d834SSinan Kaya pci_get_domain_bus_and_slot(domain, 0, 251ba99d834SSinan Kaya PCI_DEVFN(3, 0)); 2522657929dSPatrik Jakobsson 2532657929dSPatrik Jakobsson if (dev_priv->aux_pdev) { 2542657929dSPatrik Jakobsson resource_start = pci_resource_start(dev_priv->aux_pdev, 2552657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2562657929dSPatrik Jakobsson resource_len = pci_resource_len(dev_priv->aux_pdev, 2572657929dSPatrik Jakobsson PSB_AUX_RESOURCE); 2584bdc0d67SChristoph Hellwig dev_priv->aux_reg = ioremap(resource_start, 2592657929dSPatrik Jakobsson resource_len); 2602657929dSPatrik Jakobsson if (!dev_priv->aux_reg) 2612657929dSPatrik Jakobsson goto out_err; 2622657929dSPatrik Jakobsson 2632657929dSPatrik Jakobsson DRM_DEBUG_KMS("Found aux vdc"); 2642657929dSPatrik Jakobsson } else { 2652657929dSPatrik Jakobsson /* Couldn't find the aux vdc so map to primary vdc */ 2662657929dSPatrik Jakobsson dev_priv->aux_reg = dev_priv->vdc_reg; 2672657929dSPatrik Jakobsson DRM_DEBUG_KMS("Couldn't find aux pci device"); 2682657929dSPatrik Jakobsson } 2692657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->aux_reg; 2705a52b1f2SJan Safrata 271ba99d834SSinan Kaya dev_priv->lpc_pdev = 272ba99d834SSinan Kaya pci_get_domain_bus_and_slot(domain, 0, 273ba99d834SSinan Kaya PCI_DEVFN(31, 0)); 2745a52b1f2SJan Safrata if (dev_priv->lpc_pdev) { 2755a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2765a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2775a52b1f2SJan Safrata pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA, 2785a52b1f2SJan Safrata (u32)dev_priv->lpc_gpio_base | (1L<<31)); 2795a52b1f2SJan Safrata pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, 2805a52b1f2SJan Safrata &dev_priv->lpc_gpio_base); 2815a52b1f2SJan Safrata dev_priv->lpc_gpio_base &= 0xffc0; 2825a52b1f2SJan Safrata if (dev_priv->lpc_gpio_base) 2835a52b1f2SJan Safrata DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n", 2845a52b1f2SJan Safrata dev_priv->lpc_gpio_base); 2855a52b1f2SJan Safrata else { 2865a52b1f2SJan Safrata pci_dev_put(dev_priv->lpc_pdev); 2875a52b1f2SJan Safrata dev_priv->lpc_pdev = NULL; 2885a52b1f2SJan Safrata } 2895a52b1f2SJan Safrata } 2902657929dSPatrik Jakobsson } else { 2912657929dSPatrik Jakobsson dev_priv->gmbus_reg = dev_priv->vdc_reg; 2922657929dSPatrik Jakobsson } 2932657929dSPatrik Jakobsson 294d839ede4SAlan Cox psb_intel_opregion_setup(dev); 295d839ede4SAlan Cox 2965c49fd3aSAlan Cox ret = dev_priv->ops->chip_setup(dev); 2975c49fd3aSAlan Cox if (ret) 2985c49fd3aSAlan Cox goto out_err; 2995c49fd3aSAlan Cox 3005c49fd3aSAlan Cox /* Init OSPM support */ 3015c49fd3aSAlan Cox gma_power_init(dev); 3025c49fd3aSAlan Cox 3035c49fd3aSAlan Cox ret = -ENOMEM; 3045c49fd3aSAlan Cox 3055c49fd3aSAlan Cox dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); 3065c49fd3aSAlan Cox if (!dev_priv->scratch_page) 3075c49fd3aSAlan Cox goto out_err; 3085c49fd3aSAlan Cox 3095c49fd3aSAlan Cox set_pages_uc(dev_priv->scratch_page, 1); 3105c49fd3aSAlan Cox 3115c49fd3aSAlan Cox ret = psb_gtt_init(dev, 0); 3125c49fd3aSAlan Cox if (ret) 3135c49fd3aSAlan Cox goto out_err; 3145c49fd3aSAlan Cox 315*6926872aSJialin Zhang ret = -ENOMEM; 316*6926872aSJialin Zhang 3178f394872SPatrik Jakobsson dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0); 3185c49fd3aSAlan Cox if (!dev_priv->mmu) 3195c49fd3aSAlan Cox goto out_err; 3205c49fd3aSAlan Cox 3215c49fd3aSAlan Cox dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); 3225c49fd3aSAlan Cox if (!dev_priv->pf_pd) 3235c49fd3aSAlan Cox goto out_err; 3245c49fd3aSAlan Cox 3255c49fd3aSAlan Cox ret = psb_do_init(dev); 3265c49fd3aSAlan Cox if (ret) 3275c49fd3aSAlan Cox return ret; 3285c49fd3aSAlan Cox 329ae012bdcSPatrik Jakobsson /* Add stolen memory to SGX MMU */ 330ae012bdcSPatrik Jakobsson down_read(&pg->sem); 331ae012bdcSPatrik Jakobsson ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu), 332ae012bdcSPatrik Jakobsson dev_priv->stolen_base >> PAGE_SHIFT, 333ae012bdcSPatrik Jakobsson pg->gatt_start, 334ae012bdcSPatrik Jakobsson pg->stolen_size >> PAGE_SHIFT, 0); 335ae012bdcSPatrik Jakobsson up_read(&pg->sem); 336ae012bdcSPatrik Jakobsson 337ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); 338ae012bdcSPatrik Jakobsson psb_mmu_set_pd_context(dev_priv->pf_pd, 1); 339ae012bdcSPatrik Jakobsson 3405c49fd3aSAlan Cox PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); 3415c49fd3aSAlan Cox PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); 3425c49fd3aSAlan Cox 343d839ede4SAlan Cox acpi_video_register(); 3445c49fd3aSAlan Cox 3459083eb38SArthur Borsboom /* Setup vertical blanking handling */ 3465c49fd3aSAlan Cox ret = drm_vblank_init(dev, dev_priv->num_pipe); 3475c49fd3aSAlan Cox if (ret) 3485c49fd3aSAlan Cox goto out_err; 3495c49fd3aSAlan Cox 3505c49fd3aSAlan Cox /* 3515c49fd3aSAlan Cox * Install interrupt handlers prior to powering off SGX or else we will 3525c49fd3aSAlan Cox * crash. 3535c49fd3aSAlan Cox */ 3545c49fd3aSAlan Cox dev_priv->vdc_irq_mask = 0; 3555c49fd3aSAlan Cox dev_priv->pipestat[0] = 0; 3565c49fd3aSAlan Cox dev_priv->pipestat[1] = 0; 3575c49fd3aSAlan Cox dev_priv->pipestat[2] = 0; 3585c49fd3aSAlan Cox spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 3595c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 3605c49fd3aSAlan Cox PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); 3615c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); 3625c49fd3aSAlan Cox spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); 36362363a48SAlan Cox 364bb0f1b5cSDaniel Vetter drm_irq_install(dev, dev->pdev->irq); 3655c49fd3aSAlan Cox 3665c49fd3aSAlan Cox dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 3675c49fd3aSAlan Cox 3685c49fd3aSAlan Cox psb_modeset_init(dev); 3695c49fd3aSAlan Cox psb_fbdev_init(dev); 3705c49fd3aSAlan Cox drm_kms_helper_poll_init(dev); 3715c49fd3aSAlan Cox 3725c49fd3aSAlan Cox /* Only add backlight support if we have LVDS output */ 3735c49fd3aSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 3745c49fd3aSAlan Cox head) { 375367e4408SPatrik Jakobsson gma_encoder = gma_attached_encoder(connector); 3765c49fd3aSAlan Cox 377367e4408SPatrik Jakobsson switch (gma_encoder->type) { 3785c49fd3aSAlan Cox case INTEL_OUTPUT_LVDS: 3795c49fd3aSAlan Cox case INTEL_OUTPUT_MIPI: 3805c49fd3aSAlan Cox ret = gma_backlight_init(dev); 3815c49fd3aSAlan Cox break; 3825c49fd3aSAlan Cox } 3835c49fd3aSAlan Cox } 3845c49fd3aSAlan Cox 3855c49fd3aSAlan Cox if (ret) 3865c49fd3aSAlan Cox return ret; 387166973e5SAlan Cox psb_intel_opregion_enable_asle(dev); 3885c49fd3aSAlan Cox #if 0 3899083eb38SArthur Borsboom /* Enable runtime pm at last */ 3905c49fd3aSAlan Cox pm_runtime_enable(&dev->pdev->dev); 3915c49fd3aSAlan Cox pm_runtime_set_active(&dev->pdev->dev); 3925c49fd3aSAlan Cox #endif 3935c49fd3aSAlan Cox /* Intel drm driver load is done, continue doing pvr load */ 3945c49fd3aSAlan Cox return 0; 3955c49fd3aSAlan Cox out_err: 3965c49fd3aSAlan Cox psb_driver_unload(dev); 3975c49fd3aSAlan Cox return ret; 3985c49fd3aSAlan Cox } 3995c49fd3aSAlan Cox 4005c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd) 4015c49fd3aSAlan Cox { 4025c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE 4035c49fd3aSAlan Cox if (bd) { 4045c49fd3aSAlan Cox bd->props.brightness = bd->ops->get_brightness(bd); 4055c49fd3aSAlan Cox backlight_update_status(bd); 4065c49fd3aSAlan Cox } 4075c49fd3aSAlan Cox #endif 4085c49fd3aSAlan Cox } 4095c49fd3aSAlan Cox 4105c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, 4115c49fd3aSAlan Cox unsigned long arg) 4125c49fd3aSAlan Cox { 4135c49fd3aSAlan Cox struct drm_file *file_priv = filp->private_data; 4145c49fd3aSAlan Cox struct drm_device *dev = file_priv->minor->dev; 4155c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 4165c49fd3aSAlan Cox static unsigned int runtime_allowed; 4175c49fd3aSAlan Cox 4185c49fd3aSAlan Cox if (runtime_allowed == 1 && dev_priv->is_lvds_on) { 4195c49fd3aSAlan Cox runtime_allowed++; 4205c49fd3aSAlan Cox pm_runtime_allow(&dev->pdev->dev); 4215c49fd3aSAlan Cox dev_priv->rpm_enabled = 1; 4225c49fd3aSAlan Cox } 4235c49fd3aSAlan Cox return drm_ioctl(filp, cmd, arg); 4245c49fd3aSAlan Cox /* FIXME: do we need to wrap the other side of this */ 4255c49fd3aSAlan Cox } 4265c49fd3aSAlan Cox 427f90cd811SArthur Borsboom static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 428f90cd811SArthur Borsboom { 42950cbe0e3SThomas Zimmermann struct drm_device *dev; 43050cbe0e3SThomas Zimmermann int ret; 43150cbe0e3SThomas Zimmermann 43250cbe0e3SThomas Zimmermann ret = pci_enable_device(pdev); 43350cbe0e3SThomas Zimmermann if (ret) 43450cbe0e3SThomas Zimmermann return ret; 43550cbe0e3SThomas Zimmermann 43650cbe0e3SThomas Zimmermann dev = drm_dev_alloc(&driver, &pdev->dev); 43750cbe0e3SThomas Zimmermann if (IS_ERR(dev)) { 43850cbe0e3SThomas Zimmermann ret = PTR_ERR(dev); 43950cbe0e3SThomas Zimmermann goto err_pci_disable_device; 440f90cd811SArthur Borsboom } 441f90cd811SArthur Borsboom 44250cbe0e3SThomas Zimmermann dev->pdev = pdev; 44350cbe0e3SThomas Zimmermann pci_set_drvdata(pdev, dev); 44450cbe0e3SThomas Zimmermann 44550cbe0e3SThomas Zimmermann ret = psb_driver_load(dev, ent->driver_data); 44650cbe0e3SThomas Zimmermann if (ret) 44750cbe0e3SThomas Zimmermann goto err_drm_dev_put; 44850cbe0e3SThomas Zimmermann 44950cbe0e3SThomas Zimmermann ret = drm_dev_register(dev, ent->driver_data); 45050cbe0e3SThomas Zimmermann if (ret) 45150cbe0e3SThomas Zimmermann goto err_psb_driver_unload; 45250cbe0e3SThomas Zimmermann 45350cbe0e3SThomas Zimmermann return 0; 45450cbe0e3SThomas Zimmermann 45550cbe0e3SThomas Zimmermann err_psb_driver_unload: 45650cbe0e3SThomas Zimmermann psb_driver_unload(dev); 45750cbe0e3SThomas Zimmermann err_drm_dev_put: 45850cbe0e3SThomas Zimmermann drm_dev_put(dev); 45950cbe0e3SThomas Zimmermann err_pci_disable_device: 46050cbe0e3SThomas Zimmermann pci_disable_device(pdev); 46150cbe0e3SThomas Zimmermann return ret; 46250cbe0e3SThomas Zimmermann } 463f90cd811SArthur Borsboom 464f90cd811SArthur Borsboom static void psb_pci_remove(struct pci_dev *pdev) 4655c49fd3aSAlan Cox { 4665c49fd3aSAlan Cox struct drm_device *dev = pci_get_drvdata(pdev); 46750cbe0e3SThomas Zimmermann 46850cbe0e3SThomas Zimmermann drm_dev_unregister(dev); 46950cbe0e3SThomas Zimmermann psb_driver_unload(dev); 47050cbe0e3SThomas Zimmermann drm_dev_put(dev); 4715c49fd3aSAlan Cox } 4725c49fd3aSAlan Cox 4735c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = { 4745c49fd3aSAlan Cox .resume = gma_power_resume, 4755c49fd3aSAlan Cox .suspend = gma_power_suspend, 476888eef2eSPatrik Jakobsson .thaw = gma_power_thaw, 477888eef2eSPatrik Jakobsson .freeze = gma_power_freeze, 478888eef2eSPatrik Jakobsson .restore = gma_power_restore, 4795c49fd3aSAlan Cox .runtime_suspend = psb_runtime_suspend, 4805c49fd3aSAlan Cox .runtime_resume = psb_runtime_resume, 4815c49fd3aSAlan Cox .runtime_idle = psb_runtime_idle, 4825c49fd3aSAlan Cox }; 4835c49fd3aSAlan Cox 4841595c568SIlija Hadzic static const struct file_operations psb_gem_fops = { 4851595c568SIlija Hadzic .owner = THIS_MODULE, 4861595c568SIlija Hadzic .open = drm_open, 4871595c568SIlija Hadzic .release = drm_release, 4881595c568SIlija Hadzic .unlocked_ioctl = psb_unlocked_ioctl, 4890a97c81aSPatrik Jakobsson .compat_ioctl = drm_compat_ioctl, 4901595c568SIlija Hadzic .mmap = drm_gem_mmap, 4911595c568SIlija Hadzic .poll = drm_poll, 4921595c568SIlija Hadzic .read = drm_read, 4931595c568SIlija Hadzic }; 4941595c568SIlija Hadzic 49570a59dd8SDaniel Vetter static const struct drm_driver driver = { 4961ff49481SDaniel Vetter .driver_features = DRIVER_MODESET | DRIVER_GEM, 497cdc13f68SNoralf Trønnes .lastclose = drm_fb_helper_lastclose, 4985c49fd3aSAlan Cox 499f95aeb17SDamien Lespiau .num_ioctls = ARRAY_SIZE(psb_ioctls), 5005c49fd3aSAlan Cox .irq_preinstall = psb_irq_preinstall, 5015c49fd3aSAlan Cox .irq_postinstall = psb_irq_postinstall, 5025c49fd3aSAlan Cox .irq_uninstall = psb_irq_uninstall, 5035c49fd3aSAlan Cox .irq_handler = psb_irq_handler, 5045c49fd3aSAlan Cox 5055c49fd3aSAlan Cox .dumb_create = psb_gem_dumb_create, 506f90cd811SArthur Borsboom .ioctls = psb_ioctls, 5071595c568SIlija Hadzic .fops = &psb_gem_fops, 5085c49fd3aSAlan Cox .name = DRIVER_NAME, 5095c49fd3aSAlan Cox .desc = DRIVER_DESC, 510f90cd811SArthur Borsboom .date = DRIVER_DATE, 511f90cd811SArthur Borsboom .major = DRIVER_MAJOR, 512f90cd811SArthur Borsboom .minor = DRIVER_MINOR, 513f90cd811SArthur Borsboom .patchlevel = DRIVER_PATCHLEVEL 5145c49fd3aSAlan Cox }; 5155c49fd3aSAlan Cox 5165c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = { 5175c49fd3aSAlan Cox .name = DRIVER_NAME, 5185c49fd3aSAlan Cox .id_table = pciidlist, 519f90cd811SArthur Borsboom .probe = psb_pci_probe, 520f90cd811SArthur Borsboom .remove = psb_pci_remove, 521f90cd811SArthur Borsboom .driver.pm = &psb_pm_ops, 5225c49fd3aSAlan Cox }; 5235c49fd3aSAlan Cox 5245c49fd3aSAlan Cox static int __init psb_init(void) 5255c49fd3aSAlan Cox { 52610631d72SDaniel Vetter return pci_register_driver(&psb_pci_driver); 5275c49fd3aSAlan Cox } 5285c49fd3aSAlan Cox 5295c49fd3aSAlan Cox static void __exit psb_exit(void) 5305c49fd3aSAlan Cox { 53110631d72SDaniel Vetter pci_unregister_driver(&psb_pci_driver); 5325c49fd3aSAlan Cox } 5335c49fd3aSAlan Cox 5345c49fd3aSAlan Cox late_initcall(psb_init); 5355c49fd3aSAlan Cox module_exit(psb_exit); 5365c49fd3aSAlan Cox 537f90cd811SArthur Borsboom MODULE_AUTHOR(DRIVER_AUTHOR); 5385c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC); 5390df12b3fSGreg Kroah-Hartman MODULE_LICENSE("GPL"); 540