Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * Copyright (c) 2007-2011, Intel Corporation. |
| 3 | * All Rights Reserved. |
| 4 | * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA. |
| 5 | * All Rights Reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms and conditions of the GNU General Public License, |
| 9 | * version 2, as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | **************************************************************************/ |
| 21 | |
| 22 | #include <drm/drmP.h> |
| 23 | #include <drm/drm.h> |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 24 | #include "psb_drv.h" |
| 25 | #include "framebuffer.h" |
| 26 | #include "psb_reg.h" |
| 27 | #include "psb_intel_reg.h" |
| 28 | #include "intel_bios.h" |
| 29 | #include "mid_bios.h" |
| 30 | #include <drm/drm_pciids.h> |
| 31 | #include "power.h" |
| 32 | #include <linux/cpu.h> |
| 33 | #include <linux/notifier.h> |
| 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/pm_runtime.h> |
| 36 | #include <acpi/video.h> |
Dave Airlie | af3a2cf | 2011-11-16 12:13:30 +0000 | [diff] [blame] | 37 | #include <linux/module.h> |
Laura Abbott | ed3ba07 | 2017-05-08 15:58:17 -0700 | [diff] [blame] | 38 | #include <asm/set_memory.h> |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 39 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 40 | static struct drm_driver driver; |
| 41 | static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 42 | |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 43 | /* |
| 44 | * The table below contains a mapping of the PCI vendor ID and the PCI Device ID |
| 45 | * to the different groups of PowerVR 5-series chip designs |
| 46 | * |
| 47 | * 0x8086 = Intel Corporation |
| 48 | * |
| 49 | * PowerVR SGX535 - Poulsbo - Intel GMA 500, Intel Atom Z5xx |
| 50 | * PowerVR SGX535 - Moorestown - Intel GMA 600 |
| 51 | * PowerVR SGX535 - Oaktrail - Intel GMA 600, Intel Atom Z6xx, E6xx |
| 52 | * PowerVR SGX540 - Medfield - Intel Atom Z2460 |
| 53 | * PowerVR SGX544MP2 - Medfield - |
| 54 | * PowerVR SGX545 - Cedartrail - Intel GMA 3600, Intel Atom D2500, N2600 |
| 55 | * PowerVR SGX545 - Cedartrail - Intel GMA 3650, Intel Atom D2550, D2700, |
| 56 | * N2800 |
| 57 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 58 | static const struct pci_device_id pciidlist[] = { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 59 | { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, |
| 60 | { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, |
Alan Cox | 0cecdd8 | 2011-12-19 21:06:35 +0000 | [diff] [blame] | 61 | #if defined(CONFIG_DRM_GMA600) |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 62 | { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 63 | { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 64 | { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 65 | { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 66 | { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 67 | { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 68 | { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 69 | { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
| 70 | { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops }, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 71 | #endif |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 72 | #if defined(CONFIG_DRM_MEDFIELD) |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 73 | { 0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 74 | { 0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 75 | { 0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 76 | { 0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 77 | { 0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 78 | { 0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 79 | { 0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
| 80 | { 0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops }, |
Kirill A. Shutemov | 026abc3 | 2012-03-08 16:02:20 +0000 | [diff] [blame] | 81 | #endif |
Alan Cox | b6195aa | 2011-12-29 14:37:03 +0000 | [diff] [blame] | 82 | #if defined(CONFIG_DRM_GMA3600) |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 83 | { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 84 | { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 85 | { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 86 | { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 87 | { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 88 | { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 89 | { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 90 | { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 91 | { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 92 | { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 93 | { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 94 | { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 95 | { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 96 | { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 97 | { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
| 98 | { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops }, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 99 | #endif |
Kirill A. Shutemov | aa53f53 | 2012-03-08 16:09:19 +0000 | [diff] [blame] | 100 | { 0, } |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 101 | }; |
| 102 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 103 | |
| 104 | /* |
| 105 | * Standard IOCTLs. |
| 106 | */ |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 107 | static const struct drm_ioctl_desc psb_ioctls[] = { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 110 | static void psb_driver_lastclose(struct drm_device *dev) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 111 | { |
Daniel Vetter | 7147573 | 2012-12-02 21:55:41 +0100 | [diff] [blame] | 112 | int ret; |
| 113 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 114 | struct psb_fbdev *fbdev = dev_priv->fbdev; |
| 115 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 116 | ret = drm_fb_helper_restore_fbdev_mode_unlocked(&fbdev->psb_fb_helper); |
Daniel Vetter | 7147573 | 2012-12-02 21:55:41 +0100 | [diff] [blame] | 117 | if (ret) |
| 118 | DRM_DEBUG("failed to restore crtc mode\n"); |
Daniel Vetter | 7147573 | 2012-12-02 21:55:41 +0100 | [diff] [blame] | 119 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 120 | return; |
| 121 | } |
| 122 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 123 | static int psb_do_init(struct drm_device *dev) |
| 124 | { |
| 125 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 126 | struct psb_gtt *pg = &dev_priv->gtt; |
| 127 | |
| 128 | uint32_t stolen_gtt; |
| 129 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 130 | if (pg->mmu_gatt_start & 0x0FFFFFFF) { |
| 131 | dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); |
Arthur Borsboom | af3765c | 2014-03-15 22:12:16 +0100 | [diff] [blame] | 132 | return -EINVAL; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 135 | stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; |
| 136 | stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 137 | stolen_gtt = (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 138 | |
| 139 | dev_priv->gatt_free_offset = pg->mmu_gatt_start + |
| 140 | (stolen_gtt << PAGE_SHIFT) * 1024; |
| 141 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 142 | spin_lock_init(&dev_priv->irqmask_lock); |
Alan Cox | 9242fe2 | 2011-11-29 22:27:10 +0000 | [diff] [blame] | 143 | spin_lock_init(&dev_priv->lock_2d); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 144 | |
| 145 | PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); |
| 146 | PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); |
| 147 | PSB_RSGX32(PSB_CR_BIF_BANK1); |
Patrik Jakobsson | ae012bd | 2014-01-04 22:11:17 +0100 | [diff] [blame] | 148 | |
| 149 | /* Do not bypass any MMU access, let them pagefault instead */ |
| 150 | PSB_WSGX32((PSB_RSGX32(PSB_CR_BIF_CTRL) & ~_PSB_MMU_ER_MASK), |
| 151 | PSB_CR_BIF_CTRL); |
| 152 | PSB_RSGX32(PSB_CR_BIF_CTRL); |
| 153 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 154 | psb_spank(dev_priv); |
| 155 | |
| 156 | /* mmu_gatt ?? */ |
| 157 | PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); |
Patrik Jakobsson | ae012bd | 2014-01-04 22:11:17 +0100 | [diff] [blame] | 158 | PSB_RSGX32(PSB_CR_BIF_TWOD_REQ_BASE); /* Post */ |
| 159 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 160 | return 0; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Gabriel Krisman Bertazi | 11b3c20 | 2017-01-06 15:57:31 -0200 | [diff] [blame] | 163 | static void psb_driver_unload(struct drm_device *dev) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 164 | { |
| 165 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 166 | |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 167 | /* TODO: Kill vblank etc here */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 168 | |
| 169 | if (dev_priv) { |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 170 | if (dev_priv->backlight_device) |
| 171 | gma_backlight_exit(dev); |
| 172 | psb_modeset_cleanup(dev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 173 | |
| 174 | if (dev_priv->ops->chip_teardown) |
| 175 | dev_priv->ops->chip_teardown(dev); |
Alan Cox | 6607e02 | 2012-05-14 12:03:34 +0100 | [diff] [blame] | 176 | |
| 177 | psb_intel_opregion_fini(dev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 178 | |
| 179 | if (dev_priv->pf_pd) { |
| 180 | psb_mmu_free_pagedir(dev_priv->pf_pd); |
| 181 | dev_priv->pf_pd = NULL; |
| 182 | } |
| 183 | if (dev_priv->mmu) { |
| 184 | struct psb_gtt *pg = &dev_priv->gtt; |
| 185 | |
| 186 | down_read(&pg->sem); |
| 187 | psb_mmu_remove_pfn_sequence( |
| 188 | psb_mmu_get_default_pd |
| 189 | (dev_priv->mmu), |
| 190 | pg->mmu_gatt_start, |
| 191 | dev_priv->vram_stolen_size >> PAGE_SHIFT); |
| 192 | up_read(&pg->sem); |
| 193 | psb_mmu_driver_takedown(dev_priv->mmu); |
| 194 | dev_priv->mmu = NULL; |
| 195 | } |
| 196 | psb_gtt_takedown(dev); |
| 197 | if (dev_priv->scratch_page) { |
Alan Cox | 1896344 | 2012-04-25 14:36:13 +0100 | [diff] [blame] | 198 | set_pages_wb(dev_priv->scratch_page, 1); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 199 | __free_page(dev_priv->scratch_page); |
| 200 | dev_priv->scratch_page = NULL; |
| 201 | } |
| 202 | if (dev_priv->vdc_reg) { |
| 203 | iounmap(dev_priv->vdc_reg); |
| 204 | dev_priv->vdc_reg = NULL; |
| 205 | } |
| 206 | if (dev_priv->sgx_reg) { |
| 207 | iounmap(dev_priv->sgx_reg); |
| 208 | dev_priv->sgx_reg = NULL; |
| 209 | } |
Patrik Jakobsson | 2657929 | 2013-09-16 18:02:40 +0200 | [diff] [blame] | 210 | if (dev_priv->aux_reg) { |
| 211 | iounmap(dev_priv->aux_reg); |
| 212 | dev_priv->aux_reg = NULL; |
| 213 | } |
Markus Elfring | 44fb4b8 | 2016-07-22 10:30:30 +0200 | [diff] [blame] | 214 | pci_dev_put(dev_priv->aux_pdev); |
| 215 | pci_dev_put(dev_priv->lpc_pdev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 216 | |
Alan Cox | 4ab2c7f | 2012-05-14 12:04:00 +0100 | [diff] [blame] | 217 | /* Destroy VBT data */ |
| 218 | psb_intel_destroy_bios(dev); |
| 219 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 220 | kfree(dev_priv); |
| 221 | dev->dev_private = NULL; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 222 | } |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 223 | gma_power_uninit(dev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 226 | static int psb_driver_load(struct drm_device *dev, unsigned long flags) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 227 | { |
| 228 | struct drm_psb_private *dev_priv; |
Patrik Jakobsson | 2657929 | 2013-09-16 18:02:40 +0200 | [diff] [blame] | 229 | unsigned long resource_start, resource_len; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 230 | unsigned long irqflags; |
| 231 | int ret = -ENOMEM; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 232 | struct drm_connector *connector; |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 233 | struct gma_encoder *gma_encoder; |
Patrik Jakobsson | ae012bd | 2014-01-04 22:11:17 +0100 | [diff] [blame] | 234 | struct psb_gtt *pg; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 235 | |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 236 | /* allocating and initializing driver private data */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 237 | dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); |
| 238 | if (dev_priv == NULL) |
| 239 | return -ENOMEM; |
| 240 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 241 | dev_priv->ops = (struct psb_ops *)flags; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 242 | dev_priv->dev = dev; |
| 243 | dev->dev_private = (void *) dev_priv; |
| 244 | |
Patrik Jakobsson | ae012bd | 2014-01-04 22:11:17 +0100 | [diff] [blame] | 245 | pg = &dev_priv->gtt; |
| 246 | |
Dave Airlie | 466e69b | 2011-12-19 11:15:29 +0000 | [diff] [blame] | 247 | pci_set_master(dev->pdev); |
| 248 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 249 | dev_priv->num_pipe = dev_priv->ops->pipes; |
| 250 | |
| 251 | resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); |
| 252 | |
| 253 | dev_priv->vdc_reg = |
| 254 | ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); |
| 255 | if (!dev_priv->vdc_reg) |
| 256 | goto out_err; |
| 257 | |
| 258 | dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, |
| 259 | PSB_SGX_SIZE); |
| 260 | if (!dev_priv->sgx_reg) |
| 261 | goto out_err; |
| 262 | |
Patrik Jakobsson | 2657929 | 2013-09-16 18:02:40 +0200 | [diff] [blame] | 263 | if (IS_MRST(dev)) { |
| 264 | dev_priv->aux_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(3, 0)); |
| 265 | |
| 266 | if (dev_priv->aux_pdev) { |
| 267 | resource_start = pci_resource_start(dev_priv->aux_pdev, |
| 268 | PSB_AUX_RESOURCE); |
| 269 | resource_len = pci_resource_len(dev_priv->aux_pdev, |
| 270 | PSB_AUX_RESOURCE); |
| 271 | dev_priv->aux_reg = ioremap_nocache(resource_start, |
| 272 | resource_len); |
| 273 | if (!dev_priv->aux_reg) |
| 274 | goto out_err; |
| 275 | |
| 276 | DRM_DEBUG_KMS("Found aux vdc"); |
| 277 | } else { |
| 278 | /* Couldn't find the aux vdc so map to primary vdc */ |
| 279 | dev_priv->aux_reg = dev_priv->vdc_reg; |
| 280 | DRM_DEBUG_KMS("Couldn't find aux pci device"); |
| 281 | } |
| 282 | dev_priv->gmbus_reg = dev_priv->aux_reg; |
Jan Safrata | 5a52b1f | 2014-09-26 10:40:29 +0200 | [diff] [blame] | 283 | |
| 284 | dev_priv->lpc_pdev = pci_get_bus_and_slot(0, PCI_DEVFN(31, 0)); |
| 285 | if (dev_priv->lpc_pdev) { |
| 286 | pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, |
| 287 | &dev_priv->lpc_gpio_base); |
| 288 | pci_write_config_dword(dev_priv->lpc_pdev, PSB_LPC_GBA, |
| 289 | (u32)dev_priv->lpc_gpio_base | (1L<<31)); |
| 290 | pci_read_config_word(dev_priv->lpc_pdev, PSB_LPC_GBA, |
| 291 | &dev_priv->lpc_gpio_base); |
| 292 | dev_priv->lpc_gpio_base &= 0xffc0; |
| 293 | if (dev_priv->lpc_gpio_base) |
| 294 | DRM_DEBUG_KMS("Found LPC GPIO at 0x%04x\n", |
| 295 | dev_priv->lpc_gpio_base); |
| 296 | else { |
| 297 | pci_dev_put(dev_priv->lpc_pdev); |
| 298 | dev_priv->lpc_pdev = NULL; |
| 299 | } |
| 300 | } |
Patrik Jakobsson | 2657929 | 2013-09-16 18:02:40 +0200 | [diff] [blame] | 301 | } else { |
| 302 | dev_priv->gmbus_reg = dev_priv->vdc_reg; |
| 303 | } |
| 304 | |
Alan Cox | d839ede | 2012-05-03 15:06:18 +0100 | [diff] [blame] | 305 | psb_intel_opregion_setup(dev); |
| 306 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 307 | ret = dev_priv->ops->chip_setup(dev); |
| 308 | if (ret) |
| 309 | goto out_err; |
| 310 | |
| 311 | /* Init OSPM support */ |
| 312 | gma_power_init(dev); |
| 313 | |
| 314 | ret = -ENOMEM; |
| 315 | |
| 316 | dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); |
| 317 | if (!dev_priv->scratch_page) |
| 318 | goto out_err; |
| 319 | |
| 320 | set_pages_uc(dev_priv->scratch_page, 1); |
| 321 | |
| 322 | ret = psb_gtt_init(dev, 0); |
| 323 | if (ret) |
| 324 | goto out_err; |
| 325 | |
Patrik Jakobsson | 8f39487 | 2014-01-05 00:27:51 +0100 | [diff] [blame] | 326 | dev_priv->mmu = psb_mmu_driver_init(dev, 1, 0, 0); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 327 | if (!dev_priv->mmu) |
| 328 | goto out_err; |
| 329 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 330 | dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); |
| 331 | if (!dev_priv->pf_pd) |
| 332 | goto out_err; |
| 333 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 334 | ret = psb_do_init(dev); |
| 335 | if (ret) |
| 336 | return ret; |
| 337 | |
Patrik Jakobsson | ae012bd | 2014-01-04 22:11:17 +0100 | [diff] [blame] | 338 | /* Add stolen memory to SGX MMU */ |
| 339 | down_read(&pg->sem); |
| 340 | ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd(dev_priv->mmu), |
| 341 | dev_priv->stolen_base >> PAGE_SHIFT, |
| 342 | pg->gatt_start, |
| 343 | pg->stolen_size >> PAGE_SHIFT, 0); |
| 344 | up_read(&pg->sem); |
| 345 | |
| 346 | psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); |
| 347 | psb_mmu_set_pd_context(dev_priv->pf_pd, 1); |
| 348 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 349 | PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); |
| 350 | PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); |
| 351 | |
Alan Cox | d839ede | 2012-05-03 15:06:18 +0100 | [diff] [blame] | 352 | acpi_video_register(); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 353 | |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 354 | /* Setup vertical blanking handling */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 355 | ret = drm_vblank_init(dev, dev_priv->num_pipe); |
| 356 | if (ret) |
| 357 | goto out_err; |
| 358 | |
| 359 | /* |
| 360 | * Install interrupt handlers prior to powering off SGX or else we will |
| 361 | * crash. |
| 362 | */ |
| 363 | dev_priv->vdc_irq_mask = 0; |
| 364 | dev_priv->pipestat[0] = 0; |
| 365 | dev_priv->pipestat[1] = 0; |
| 366 | dev_priv->pipestat[2] = 0; |
| 367 | spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); |
| 368 | PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); |
| 369 | PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); |
| 370 | PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); |
| 371 | spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); |
Alan Cox | 62363a4 | 2012-05-11 11:33:17 +0100 | [diff] [blame] | 372 | |
Daniel Vetter | bb0f1b5 | 2013-11-03 21:09:27 +0100 | [diff] [blame] | 373 | drm_irq_install(dev, dev->pdev->irq); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 374 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 375 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 376 | dev->driver->get_vblank_counter = psb_get_vblank_counter; |
| 377 | |
Alan Cox | f9f23a7 | 2011-12-29 14:38:07 +0000 | [diff] [blame] | 378 | psb_modeset_init(dev); |
| 379 | psb_fbdev_init(dev); |
| 380 | drm_kms_helper_poll_init(dev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 381 | |
| 382 | /* Only add backlight support if we have LVDS output */ |
| 383 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 384 | head) { |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 385 | gma_encoder = gma_attached_encoder(connector); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 386 | |
Patrik Jakobsson | 367e440 | 2013-07-22 17:45:26 +0200 | [diff] [blame] | 387 | switch (gma_encoder->type) { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 388 | case INTEL_OUTPUT_LVDS: |
| 389 | case INTEL_OUTPUT_MIPI: |
| 390 | ret = gma_backlight_init(dev); |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | if (ret) |
| 396 | return ret; |
Alan Cox | 166973e | 2012-07-16 17:52:45 +0100 | [diff] [blame] | 397 | psb_intel_opregion_enable_asle(dev); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 398 | #if 0 |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 399 | /* Enable runtime pm at last */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 400 | pm_runtime_enable(&dev->pdev->dev); |
| 401 | pm_runtime_set_active(&dev->pdev->dev); |
| 402 | #endif |
Arthur Borsboom | 9083eb3 | 2014-03-15 22:12:18 +0100 | [diff] [blame] | 403 | /* Intel drm driver load is done, continue doing pvr load */ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 404 | return 0; |
| 405 | out_err: |
| 406 | psb_driver_unload(dev); |
| 407 | return ret; |
| 408 | } |
| 409 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 410 | static inline void get_brightness(struct backlight_device *bd) |
| 411 | { |
| 412 | #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE |
| 413 | if (bd) { |
| 414 | bd->props.brightness = bd->ops->get_brightness(bd); |
| 415 | backlight_update_status(bd); |
| 416 | } |
| 417 | #endif |
| 418 | } |
| 419 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 420 | static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, |
| 421 | unsigned long arg) |
| 422 | { |
| 423 | struct drm_file *file_priv = filp->private_data; |
| 424 | struct drm_device *dev = file_priv->minor->dev; |
| 425 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 426 | static unsigned int runtime_allowed; |
| 427 | |
| 428 | if (runtime_allowed == 1 && dev_priv->is_lvds_on) { |
| 429 | runtime_allowed++; |
| 430 | pm_runtime_allow(&dev->pdev->dev); |
| 431 | dev_priv->rpm_enabled = 1; |
| 432 | } |
| 433 | return drm_ioctl(filp, cmd, arg); |
| 434 | /* FIXME: do we need to wrap the other side of this */ |
| 435 | } |
| 436 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 437 | static int psb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 438 | { |
| 439 | return drm_get_pci_dev(pdev, ent, &driver); |
| 440 | } |
| 441 | |
| 442 | |
| 443 | static void psb_pci_remove(struct pci_dev *pdev) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 444 | { |
| 445 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 446 | drm_put_dev(dev); |
| 447 | } |
| 448 | |
| 449 | static const struct dev_pm_ops psb_pm_ops = { |
| 450 | .resume = gma_power_resume, |
| 451 | .suspend = gma_power_suspend, |
Patrik Jakobsson | 888eef2 | 2013-04-06 00:45:22 +0200 | [diff] [blame] | 452 | .thaw = gma_power_thaw, |
| 453 | .freeze = gma_power_freeze, |
| 454 | .restore = gma_power_restore, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 455 | .runtime_suspend = psb_runtime_suspend, |
| 456 | .runtime_resume = psb_runtime_resume, |
| 457 | .runtime_idle = psb_runtime_idle, |
| 458 | }; |
| 459 | |
Laurent Pinchart | 78b6855 | 2012-05-17 13:27:22 +0200 | [diff] [blame] | 460 | static const struct vm_operations_struct psb_gem_vm_ops = { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 461 | .fault = psb_gem_fault, |
| 462 | .open = drm_gem_vm_open, |
| 463 | .close = drm_gem_vm_close, |
| 464 | }; |
| 465 | |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 466 | static const struct file_operations psb_gem_fops = { |
| 467 | .owner = THIS_MODULE, |
| 468 | .open = drm_open, |
| 469 | .release = drm_release, |
| 470 | .unlocked_ioctl = psb_unlocked_ioctl, |
Patrik Jakobsson | 0a97c81 | 2016-11-01 15:43:15 +0100 | [diff] [blame] | 471 | .compat_ioctl = drm_compat_ioctl, |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 472 | .mmap = drm_gem_mmap, |
| 473 | .poll = drm_poll, |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 474 | .read = drm_read, |
| 475 | }; |
| 476 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 477 | static struct drm_driver driver = { |
| 478 | .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 479 | DRIVER_MODESET | DRIVER_GEM, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 480 | .load = psb_driver_load, |
| 481 | .unload = psb_driver_unload, |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 482 | .lastclose = psb_driver_lastclose, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 483 | |
Damien Lespiau | f95aeb1 | 2014-06-09 14:39:49 +0100 | [diff] [blame] | 484 | .num_ioctls = ARRAY_SIZE(psb_ioctls), |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 485 | .irq_preinstall = psb_irq_preinstall, |
| 486 | .irq_postinstall = psb_irq_postinstall, |
| 487 | .irq_uninstall = psb_irq_uninstall, |
| 488 | .irq_handler = psb_irq_handler, |
| 489 | .enable_vblank = psb_enable_vblank, |
| 490 | .disable_vblank = psb_disable_vblank, |
| 491 | .get_vblank_counter = psb_get_vblank_counter, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 492 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 493 | .gem_free_object = psb_gem_free_object, |
| 494 | .gem_vm_ops = &psb_gem_vm_ops, |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 495 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 496 | .dumb_create = psb_gem_dumb_create, |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 497 | .ioctls = psb_ioctls, |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 498 | .fops = &psb_gem_fops, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 499 | .name = DRIVER_NAME, |
| 500 | .desc = DRIVER_DESC, |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 501 | .date = DRIVER_DATE, |
| 502 | .major = DRIVER_MAJOR, |
| 503 | .minor = DRIVER_MINOR, |
| 504 | .patchlevel = DRIVER_PATCHLEVEL |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 505 | }; |
| 506 | |
| 507 | static struct pci_driver psb_pci_driver = { |
| 508 | .name = DRIVER_NAME, |
| 509 | .id_table = pciidlist, |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 510 | .probe = psb_pci_probe, |
| 511 | .remove = psb_pci_remove, |
| 512 | .driver.pm = &psb_pm_ops, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 513 | }; |
| 514 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 515 | static int __init psb_init(void) |
| 516 | { |
Daniel Vetter | 10631d7 | 2017-05-24 16:51:40 +0200 | [diff] [blame] | 517 | return pci_register_driver(&psb_pci_driver); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void __exit psb_exit(void) |
| 521 | { |
Daniel Vetter | 10631d7 | 2017-05-24 16:51:40 +0200 | [diff] [blame] | 522 | pci_unregister_driver(&psb_pci_driver); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | late_initcall(psb_init); |
| 526 | module_exit(psb_exit); |
| 527 | |
Arthur Borsboom | f90cd81 | 2014-03-15 22:12:17 +0100 | [diff] [blame] | 528 | MODULE_AUTHOR(DRIVER_AUTHOR); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 529 | MODULE_DESCRIPTION(DRIVER_DESC); |
Greg Kroah-Hartman | 0df12b3 | 2017-11-17 15:16:32 +0100 | [diff] [blame] | 530 | MODULE_LICENSE("GPL"); |