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 | 838fa58 | 2011-11-16 22:39:45 +0000 | [diff] [blame] | 24 | #include "gma_drm.h" |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 25 | #include "psb_drv.h" |
| 26 | #include "framebuffer.h" |
| 27 | #include "psb_reg.h" |
| 28 | #include "psb_intel_reg.h" |
| 29 | #include "intel_bios.h" |
| 30 | #include "mid_bios.h" |
| 31 | #include <drm/drm_pciids.h> |
| 32 | #include "power.h" |
| 33 | #include <linux/cpu.h> |
| 34 | #include <linux/notifier.h> |
| 35 | #include <linux/spinlock.h> |
| 36 | #include <linux/pm_runtime.h> |
| 37 | #include <acpi/video.h> |
Dave Airlie | af3a2cf | 2011-11-16 12:13:30 +0000 | [diff] [blame] | 38 | #include <linux/module.h> |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 39 | |
| 40 | static int drm_psb_trap_pagefaults; |
| 41 | |
| 42 | int drm_psb_no_fb; |
| 43 | |
| 44 | static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 45 | |
| 46 | MODULE_PARM_DESC(no_fb, "Disable FBdev"); |
| 47 | MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults"); |
| 48 | module_param_named(no_fb, drm_psb_no_fb, int, 0600); |
| 49 | module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600); |
| 50 | |
| 51 | |
| 52 | static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { |
| 53 | { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, |
| 54 | { 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^] | 55 | #if defined(CONFIG_DRM_GMA600) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 56 | { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 57 | { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 58 | { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 59 | { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 60 | { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 61 | { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 62 | { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 63 | { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, |
| 64 | #endif |
| 65 | #if defined(CONFIG_DRM_CDV) |
| 66 | { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 67 | { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 68 | { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 69 | { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 70 | { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 71 | { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 72 | { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 73 | { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, |
| 74 | #endif |
| 75 | { 0, 0, 0} |
| 76 | }; |
| 77 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 78 | |
| 79 | /* |
| 80 | * Standard IOCTLs. |
| 81 | */ |
| 82 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 83 | #define DRM_IOCTL_PSB_ADB \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 84 | DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 85 | #define DRM_IOCTL_PSB_MODE_OPERATION \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 86 | DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 87 | struct drm_psb_mode_operation_arg) |
| 88 | #define DRM_IOCTL_PSB_STOLEN_MEMORY \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 89 | DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 90 | struct drm_psb_stolen_memory_arg) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 91 | #define DRM_IOCTL_PSB_GAMMA \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 92 | DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 93 | struct drm_psb_dpst_lut_arg) |
| 94 | #define DRM_IOCTL_PSB_DPST_BL \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 95 | DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 96 | uint32_t) |
| 97 | #define DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 98 | DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 99 | struct drm_psb_get_pipe_from_crtc_id_arg) |
| 100 | #define DRM_IOCTL_PSB_GEM_CREATE \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 101 | DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 102 | struct drm_psb_gem_create) |
| 103 | #define DRM_IOCTL_PSB_GEM_MMAP \ |
Alan Cox | 770179d | 2011-11-16 22:39:18 +0000 | [diff] [blame] | 104 | DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \ |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 105 | struct drm_psb_gem_mmap) |
| 106 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 107 | static int psb_adb_ioctl(struct drm_device *dev, void *data, |
| 108 | struct drm_file *file_priv); |
| 109 | static int psb_mode_operation_ioctl(struct drm_device *dev, void *data, |
| 110 | struct drm_file *file_priv); |
| 111 | static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data, |
| 112 | struct drm_file *file_priv); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 113 | static int psb_gamma_ioctl(struct drm_device *dev, void *data, |
| 114 | struct drm_file *file_priv); |
| 115 | static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data, |
| 116 | struct drm_file *file_priv); |
| 117 | |
| 118 | #define PSB_IOCTL_DEF(ioctl, func, flags) \ |
| 119 | [DRM_IOCTL_NR(ioctl) - DRM_COMMAND_BASE] = {ioctl, flags, func} |
| 120 | |
| 121 | static struct drm_ioctl_desc psb_ioctls[] = { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 122 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_ADB, psb_adb_ioctl, DRM_AUTH), |
| 123 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_MODE_OPERATION, psb_mode_operation_ioctl, |
| 124 | DRM_AUTH), |
| 125 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_STOLEN_MEMORY, psb_stolen_memory_ioctl, |
| 126 | DRM_AUTH), |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 127 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA, psb_gamma_ioctl, DRM_AUTH), |
| 128 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH), |
| 129 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID, |
| 130 | psb_intel_get_pipe_from_crtc_id, 0), |
| 131 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_CREATE, psb_gem_create_ioctl, |
| 132 | DRM_UNLOCKED | DRM_AUTH), |
| 133 | PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_MMAP, psb_gem_mmap_ioctl, |
| 134 | DRM_UNLOCKED | DRM_AUTH), |
| 135 | }; |
| 136 | |
| 137 | static void psb_lastclose(struct drm_device *dev) |
| 138 | { |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | static void psb_do_takedown(struct drm_device *dev) |
| 143 | { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static int psb_do_init(struct drm_device *dev) |
| 147 | { |
| 148 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 149 | struct psb_gtt *pg = &dev_priv->gtt; |
| 150 | |
| 151 | uint32_t stolen_gtt; |
| 152 | |
| 153 | int ret = -ENOMEM; |
| 154 | |
| 155 | if (pg->mmu_gatt_start & 0x0FFFFFFF) { |
| 156 | dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); |
| 157 | ret = -EINVAL; |
| 158 | goto out_err; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; |
| 163 | stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 164 | stolen_gtt = |
| 165 | (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; |
| 166 | |
| 167 | dev_priv->gatt_free_offset = pg->mmu_gatt_start + |
| 168 | (stolen_gtt << PAGE_SHIFT) * 1024; |
| 169 | |
| 170 | if (1 || drm_debug) { |
| 171 | uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID); |
| 172 | uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION); |
| 173 | DRM_INFO("SGX core id = 0x%08x\n", core_id); |
| 174 | DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n", |
| 175 | (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >> |
| 176 | _PSB_CC_REVISION_MAJOR_SHIFT, |
| 177 | (core_rev & _PSB_CC_REVISION_MINOR_MASK) >> |
| 178 | _PSB_CC_REVISION_MINOR_SHIFT); |
| 179 | DRM_INFO |
| 180 | ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n", |
| 181 | (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >> |
| 182 | _PSB_CC_REVISION_MAINTENANCE_SHIFT, |
| 183 | (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >> |
| 184 | _PSB_CC_REVISION_DESIGNER_SHIFT); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | spin_lock_init(&dev_priv->irqmask_lock); |
Alan Cox | 9242fe2 | 2011-11-29 22:27:10 +0000 | [diff] [blame] | 189 | spin_lock_init(&dev_priv->lock_2d); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 190 | |
| 191 | PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); |
| 192 | PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); |
| 193 | PSB_RSGX32(PSB_CR_BIF_BANK1); |
| 194 | PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK, |
| 195 | PSB_CR_BIF_CTRL); |
| 196 | psb_spank(dev_priv); |
| 197 | |
| 198 | /* mmu_gatt ?? */ |
| 199 | PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); |
| 200 | return 0; |
| 201 | out_err: |
| 202 | psb_do_takedown(dev); |
| 203 | return ret; |
| 204 | } |
| 205 | |
| 206 | static int psb_driver_unload(struct drm_device *dev) |
| 207 | { |
| 208 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 209 | |
| 210 | /* Kill vblank etc here */ |
| 211 | |
| 212 | gma_backlight_exit(dev); |
| 213 | |
| 214 | if (drm_psb_no_fb == 0) |
| 215 | psb_modeset_cleanup(dev); |
| 216 | |
| 217 | if (dev_priv) { |
| 218 | psb_lid_timer_takedown(dev_priv); |
| 219 | gma_intel_opregion_exit(dev); |
| 220 | |
| 221 | if (dev_priv->ops->chip_teardown) |
| 222 | dev_priv->ops->chip_teardown(dev); |
| 223 | psb_do_takedown(dev); |
| 224 | |
| 225 | |
| 226 | if (dev_priv->pf_pd) { |
| 227 | psb_mmu_free_pagedir(dev_priv->pf_pd); |
| 228 | dev_priv->pf_pd = NULL; |
| 229 | } |
| 230 | if (dev_priv->mmu) { |
| 231 | struct psb_gtt *pg = &dev_priv->gtt; |
| 232 | |
| 233 | down_read(&pg->sem); |
| 234 | psb_mmu_remove_pfn_sequence( |
| 235 | psb_mmu_get_default_pd |
| 236 | (dev_priv->mmu), |
| 237 | pg->mmu_gatt_start, |
| 238 | dev_priv->vram_stolen_size >> PAGE_SHIFT); |
| 239 | up_read(&pg->sem); |
| 240 | psb_mmu_driver_takedown(dev_priv->mmu); |
| 241 | dev_priv->mmu = NULL; |
| 242 | } |
| 243 | psb_gtt_takedown(dev); |
| 244 | if (dev_priv->scratch_page) { |
| 245 | __free_page(dev_priv->scratch_page); |
| 246 | dev_priv->scratch_page = NULL; |
| 247 | } |
| 248 | if (dev_priv->vdc_reg) { |
| 249 | iounmap(dev_priv->vdc_reg); |
| 250 | dev_priv->vdc_reg = NULL; |
| 251 | } |
| 252 | if (dev_priv->sgx_reg) { |
| 253 | iounmap(dev_priv->sgx_reg); |
| 254 | dev_priv->sgx_reg = NULL; |
| 255 | } |
| 256 | |
| 257 | kfree(dev_priv); |
| 258 | dev->dev_private = NULL; |
| 259 | |
| 260 | /*destroy VBT data*/ |
| 261 | psb_intel_destroy_bios(dev); |
| 262 | } |
| 263 | |
| 264 | gma_power_uninit(dev); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | |
| 270 | static int psb_driver_load(struct drm_device *dev, unsigned long chipset) |
| 271 | { |
| 272 | struct drm_psb_private *dev_priv; |
| 273 | unsigned long resource_start; |
| 274 | struct psb_gtt *pg; |
| 275 | unsigned long irqflags; |
| 276 | int ret = -ENOMEM; |
| 277 | uint32_t tt_pages; |
| 278 | struct drm_connector *connector; |
Patrik Jakobsson | 1730f89 | 2011-12-19 21:40:33 +0000 | [diff] [blame] | 279 | struct psb_intel_encoder *psb_intel_encoder; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 280 | |
| 281 | dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); |
| 282 | if (dev_priv == NULL) |
| 283 | return -ENOMEM; |
| 284 | |
| 285 | dev_priv->ops = (struct psb_ops *)chipset; |
| 286 | dev_priv->dev = dev; |
| 287 | dev->dev_private = (void *) dev_priv; |
| 288 | |
Patrik Jakobsson | 84b08fe | 2011-11-29 22:20:20 +0000 | [diff] [blame] | 289 | if (!IS_PSB(dev)) { |
| 290 | if (pci_enable_msi(dev->pdev)) |
| 291 | dev_warn(dev->dev, "Enabling MSI failed!\n"); |
| 292 | } |
| 293 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 294 | dev_priv->num_pipe = dev_priv->ops->pipes; |
| 295 | |
| 296 | resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); |
| 297 | |
| 298 | dev_priv->vdc_reg = |
| 299 | ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); |
| 300 | if (!dev_priv->vdc_reg) |
| 301 | goto out_err; |
| 302 | |
| 303 | dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, |
| 304 | PSB_SGX_SIZE); |
| 305 | if (!dev_priv->sgx_reg) |
| 306 | goto out_err; |
| 307 | |
| 308 | ret = dev_priv->ops->chip_setup(dev); |
| 309 | if (ret) |
| 310 | goto out_err; |
| 311 | |
| 312 | /* Init OSPM support */ |
| 313 | gma_power_init(dev); |
| 314 | |
| 315 | ret = -ENOMEM; |
| 316 | |
| 317 | dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); |
| 318 | if (!dev_priv->scratch_page) |
| 319 | goto out_err; |
| 320 | |
| 321 | set_pages_uc(dev_priv->scratch_page, 1); |
| 322 | |
| 323 | ret = psb_gtt_init(dev, 0); |
| 324 | if (ret) |
| 325 | goto out_err; |
| 326 | |
| 327 | dev_priv->mmu = psb_mmu_driver_init((void *)0, |
| 328 | drm_psb_trap_pagefaults, 0, |
| 329 | dev_priv); |
| 330 | if (!dev_priv->mmu) |
| 331 | goto out_err; |
| 332 | |
| 333 | pg = &dev_priv->gtt; |
| 334 | |
| 335 | tt_pages = (pg->gatt_pages < PSB_TT_PRIV0_PLIMIT) ? |
| 336 | (pg->gatt_pages) : PSB_TT_PRIV0_PLIMIT; |
| 337 | |
| 338 | |
| 339 | dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); |
| 340 | if (!dev_priv->pf_pd) |
| 341 | goto out_err; |
| 342 | |
| 343 | psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); |
| 344 | psb_mmu_set_pd_context(dev_priv->pf_pd, 1); |
| 345 | |
| 346 | ret = psb_do_init(dev); |
| 347 | if (ret) |
| 348 | return ret; |
| 349 | |
| 350 | PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); |
| 351 | PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); |
| 352 | |
| 353 | /* igd_opregion_init(&dev_priv->opregion_dev); */ |
| 354 | acpi_video_register(); |
| 355 | if (dev_priv->lid_state) |
| 356 | psb_lid_timer_init(dev_priv); |
| 357 | |
| 358 | ret = drm_vblank_init(dev, dev_priv->num_pipe); |
| 359 | if (ret) |
| 360 | goto out_err; |
| 361 | |
| 362 | /* |
| 363 | * Install interrupt handlers prior to powering off SGX or else we will |
| 364 | * crash. |
| 365 | */ |
| 366 | dev_priv->vdc_irq_mask = 0; |
| 367 | dev_priv->pipestat[0] = 0; |
| 368 | dev_priv->pipestat[1] = 0; |
| 369 | dev_priv->pipestat[2] = 0; |
| 370 | spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); |
| 371 | PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); |
| 372 | PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); |
| 373 | PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); |
| 374 | spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); |
Patrik Jakobsson | e036ba5 | 2011-11-29 22:20:07 +0000 | [diff] [blame] | 375 | if (IS_PSB(dev) && drm_core_check_feature(dev, DRIVER_MODESET)) |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 376 | drm_irq_install(dev); |
| 377 | |
| 378 | dev->vblank_disable_allowed = 1; |
| 379 | |
| 380 | dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ |
| 381 | |
| 382 | dev->driver->get_vblank_counter = psb_get_vblank_counter; |
| 383 | |
| 384 | if (drm_psb_no_fb == 0) { |
| 385 | psb_modeset_init(dev); |
| 386 | psb_fbdev_init(dev); |
| 387 | drm_kms_helper_poll_init(dev); |
| 388 | } |
| 389 | |
| 390 | /* Only add backlight support if we have LVDS output */ |
| 391 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 392 | head) { |
Patrik Jakobsson | 1730f89 | 2011-12-19 21:40:33 +0000 | [diff] [blame] | 393 | psb_intel_encoder = psb_intel_attached_encoder(connector); |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 394 | |
Patrik Jakobsson | 1730f89 | 2011-12-19 21:40:33 +0000 | [diff] [blame] | 395 | switch (psb_intel_encoder->type) { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 396 | case INTEL_OUTPUT_LVDS: |
| 397 | case INTEL_OUTPUT_MIPI: |
| 398 | ret = gma_backlight_init(dev); |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | #if 0 |
| 406 | /*enable runtime pm at last*/ |
| 407 | pm_runtime_enable(&dev->pdev->dev); |
| 408 | pm_runtime_set_active(&dev->pdev->dev); |
| 409 | #endif |
| 410 | /*Intel drm driver load is done, continue doing pvr load*/ |
| 411 | return 0; |
| 412 | out_err: |
| 413 | psb_driver_unload(dev); |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | int psb_driver_device_is_agp(struct drm_device *dev) |
| 418 | { |
| 419 | return 0; |
| 420 | } |
| 421 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 422 | static inline void get_brightness(struct backlight_device *bd) |
| 423 | { |
| 424 | #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE |
| 425 | if (bd) { |
| 426 | bd->props.brightness = bd->ops->get_brightness(bd); |
| 427 | backlight_update_status(bd); |
| 428 | } |
| 429 | #endif |
| 430 | } |
| 431 | |
| 432 | static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data, |
| 433 | struct drm_file *file_priv) |
| 434 | { |
| 435 | struct drm_psb_private *dev_priv = psb_priv(dev); |
| 436 | uint32_t *arg = data; |
| 437 | |
| 438 | dev_priv->blc_adj2 = *arg; |
| 439 | get_brightness(dev_priv->backlight_device); |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int psb_adb_ioctl(struct drm_device *dev, void *data, |
| 444 | struct drm_file *file_priv) |
| 445 | { |
| 446 | struct drm_psb_private *dev_priv = psb_priv(dev); |
| 447 | uint32_t *arg = data; |
| 448 | |
| 449 | dev_priv->blc_adj1 = *arg; |
| 450 | get_brightness(dev_priv->backlight_device); |
| 451 | return 0; |
| 452 | } |
| 453 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 454 | static int psb_gamma_ioctl(struct drm_device *dev, void *data, |
| 455 | struct drm_file *file_priv) |
| 456 | { |
| 457 | struct drm_psb_dpst_lut_arg *lut_arg = data; |
| 458 | struct drm_mode_object *obj; |
| 459 | struct drm_crtc *crtc; |
| 460 | struct drm_connector *connector; |
| 461 | struct psb_intel_crtc *psb_intel_crtc; |
| 462 | int i = 0; |
| 463 | int32_t obj_id; |
| 464 | |
| 465 | obj_id = lut_arg->output_id; |
| 466 | obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR); |
| 467 | if (!obj) { |
| 468 | dev_dbg(dev->dev, "Invalid Connector object.\n"); |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | |
| 472 | connector = obj_to_connector(obj); |
| 473 | crtc = connector->encoder->crtc; |
| 474 | psb_intel_crtc = to_psb_intel_crtc(crtc); |
| 475 | |
| 476 | for (i = 0; i < 256; i++) |
| 477 | psb_intel_crtc->lut_adj[i] = lut_arg->lut[i]; |
| 478 | |
| 479 | psb_intel_crtc_load_lut(crtc); |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static int psb_mode_operation_ioctl(struct drm_device *dev, void *data, |
| 485 | struct drm_file *file_priv) |
| 486 | { |
| 487 | uint32_t obj_id; |
| 488 | uint16_t op; |
| 489 | struct drm_mode_modeinfo *umode; |
| 490 | struct drm_display_mode *mode = NULL; |
| 491 | struct drm_psb_mode_operation_arg *arg; |
| 492 | struct drm_mode_object *obj; |
| 493 | struct drm_connector *connector; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 494 | struct drm_connector_helper_funcs *connector_funcs; |
| 495 | int ret = 0; |
| 496 | int resp = MODE_OK; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 497 | |
| 498 | arg = (struct drm_psb_mode_operation_arg *)data; |
| 499 | obj_id = arg->obj_id; |
| 500 | op = arg->operation; |
| 501 | |
| 502 | switch (op) { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 503 | case PSB_MODE_OPERATION_MODE_VALID: |
| 504 | umode = &arg->mode; |
| 505 | |
| 506 | mutex_lock(&dev->mode_config.mutex); |
| 507 | |
| 508 | obj = drm_mode_object_find(dev, obj_id, |
| 509 | DRM_MODE_OBJECT_CONNECTOR); |
| 510 | if (!obj) { |
| 511 | ret = -EINVAL; |
| 512 | goto mode_op_out; |
| 513 | } |
| 514 | |
| 515 | connector = obj_to_connector(obj); |
| 516 | |
| 517 | mode = drm_mode_create(dev); |
| 518 | if (!mode) { |
| 519 | ret = -ENOMEM; |
| 520 | goto mode_op_out; |
| 521 | } |
| 522 | |
| 523 | /* drm_crtc_convert_umode(mode, umode); */ |
| 524 | { |
| 525 | mode->clock = umode->clock; |
| 526 | mode->hdisplay = umode->hdisplay; |
| 527 | mode->hsync_start = umode->hsync_start; |
| 528 | mode->hsync_end = umode->hsync_end; |
| 529 | mode->htotal = umode->htotal; |
| 530 | mode->hskew = umode->hskew; |
| 531 | mode->vdisplay = umode->vdisplay; |
| 532 | mode->vsync_start = umode->vsync_start; |
| 533 | mode->vsync_end = umode->vsync_end; |
| 534 | mode->vtotal = umode->vtotal; |
| 535 | mode->vscan = umode->vscan; |
| 536 | mode->vrefresh = umode->vrefresh; |
| 537 | mode->flags = umode->flags; |
| 538 | mode->type = umode->type; |
| 539 | strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN); |
| 540 | mode->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
| 541 | } |
| 542 | |
| 543 | connector_funcs = (struct drm_connector_helper_funcs *) |
| 544 | connector->helper_private; |
| 545 | |
| 546 | if (connector_funcs->mode_valid) { |
| 547 | resp = connector_funcs->mode_valid(connector, mode); |
Alan Cox | 61bedf7 | 2011-11-16 22:38:42 +0000 | [diff] [blame] | 548 | arg->data = resp; |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /*do some clean up work*/ |
| 552 | if (mode) |
| 553 | drm_mode_destroy(dev, mode); |
| 554 | mode_op_out: |
| 555 | mutex_unlock(&dev->mode_config.mutex); |
| 556 | return ret; |
| 557 | |
| 558 | default: |
| 559 | dev_dbg(dev->dev, "Unsupported psb mode operation\n"); |
| 560 | return -EOPNOTSUPP; |
| 561 | } |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data, |
| 567 | struct drm_file *file_priv) |
| 568 | { |
| 569 | struct drm_psb_private *dev_priv = psb_priv(dev); |
| 570 | struct drm_psb_stolen_memory_arg *arg = data; |
| 571 | |
| 572 | arg->base = dev_priv->stolen_base; |
| 573 | arg->size = dev_priv->vram_stolen_size; |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 578 | static int psb_driver_open(struct drm_device *dev, struct drm_file *priv) |
| 579 | { |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static void psb_driver_close(struct drm_device *dev, struct drm_file *priv) |
| 584 | { |
| 585 | } |
| 586 | |
| 587 | static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, |
| 588 | unsigned long arg) |
| 589 | { |
| 590 | struct drm_file *file_priv = filp->private_data; |
| 591 | struct drm_device *dev = file_priv->minor->dev; |
| 592 | struct drm_psb_private *dev_priv = dev->dev_private; |
| 593 | static unsigned int runtime_allowed; |
| 594 | |
| 595 | if (runtime_allowed == 1 && dev_priv->is_lvds_on) { |
| 596 | runtime_allowed++; |
| 597 | pm_runtime_allow(&dev->pdev->dev); |
| 598 | dev_priv->rpm_enabled = 1; |
| 599 | } |
| 600 | return drm_ioctl(filp, cmd, arg); |
| 601 | /* FIXME: do we need to wrap the other side of this */ |
| 602 | } |
| 603 | |
| 604 | |
| 605 | /* When a client dies: |
| 606 | * - Check for and clean up flipped page state |
| 607 | */ |
| 608 | void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv) |
| 609 | { |
| 610 | } |
| 611 | |
| 612 | static void psb_remove(struct pci_dev *pdev) |
| 613 | { |
| 614 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 615 | drm_put_dev(dev); |
| 616 | } |
| 617 | |
| 618 | static const struct dev_pm_ops psb_pm_ops = { |
| 619 | .resume = gma_power_resume, |
| 620 | .suspend = gma_power_suspend, |
| 621 | .runtime_suspend = psb_runtime_suspend, |
| 622 | .runtime_resume = psb_runtime_resume, |
| 623 | .runtime_idle = psb_runtime_idle, |
| 624 | }; |
| 625 | |
| 626 | static struct vm_operations_struct psb_gem_vm_ops = { |
| 627 | .fault = psb_gem_fault, |
| 628 | .open = drm_gem_vm_open, |
| 629 | .close = drm_gem_vm_close, |
| 630 | }; |
| 631 | |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 632 | static const struct file_operations psb_gem_fops = { |
| 633 | .owner = THIS_MODULE, |
| 634 | .open = drm_open, |
| 635 | .release = drm_release, |
| 636 | .unlocked_ioctl = psb_unlocked_ioctl, |
| 637 | .mmap = drm_gem_mmap, |
| 638 | .poll = drm_poll, |
| 639 | .fasync = drm_fasync, |
| 640 | .read = drm_read, |
| 641 | }; |
| 642 | |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 643 | static struct drm_driver driver = { |
| 644 | .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ |
| 645 | DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM , |
| 646 | .load = psb_driver_load, |
| 647 | .unload = psb_driver_unload, |
| 648 | |
| 649 | .ioctls = psb_ioctls, |
| 650 | .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls), |
| 651 | .device_is_agp = psb_driver_device_is_agp, |
| 652 | .irq_preinstall = psb_irq_preinstall, |
| 653 | .irq_postinstall = psb_irq_postinstall, |
| 654 | .irq_uninstall = psb_irq_uninstall, |
| 655 | .irq_handler = psb_irq_handler, |
| 656 | .enable_vblank = psb_enable_vblank, |
| 657 | .disable_vblank = psb_disable_vblank, |
| 658 | .get_vblank_counter = psb_get_vblank_counter, |
| 659 | .lastclose = psb_lastclose, |
| 660 | .open = psb_driver_open, |
| 661 | .preclose = psb_driver_preclose, |
| 662 | .postclose = psb_driver_close, |
| 663 | .reclaim_buffers = drm_core_reclaim_buffers, |
| 664 | |
| 665 | .gem_init_object = psb_gem_init_object, |
| 666 | .gem_free_object = psb_gem_free_object, |
| 667 | .gem_vm_ops = &psb_gem_vm_ops, |
| 668 | .dumb_create = psb_gem_dumb_create, |
| 669 | .dumb_map_offset = psb_gem_dumb_map_gtt, |
| 670 | .dumb_destroy = psb_gem_dumb_destroy, |
Ilija Hadzic | 1595c56 | 2011-11-27 11:08:33 -0500 | [diff] [blame] | 671 | .fops = &psb_gem_fops, |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 672 | .name = DRIVER_NAME, |
| 673 | .desc = DRIVER_DESC, |
| 674 | .date = PSB_DRM_DRIVER_DATE, |
| 675 | .major = PSB_DRM_DRIVER_MAJOR, |
| 676 | .minor = PSB_DRM_DRIVER_MINOR, |
| 677 | .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL |
| 678 | }; |
| 679 | |
| 680 | static struct pci_driver psb_pci_driver = { |
| 681 | .name = DRIVER_NAME, |
| 682 | .id_table = pciidlist, |
| 683 | .probe = psb_probe, |
| 684 | .remove = psb_remove, |
| 685 | .driver.pm = &psb_pm_ops, |
| 686 | }; |
| 687 | |
| 688 | static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 689 | { |
Alan Cox | 5c49fd3 | 2011-11-03 18:22:04 +0000 | [diff] [blame] | 690 | return drm_get_pci_dev(pdev, ent, &driver); |
| 691 | } |
| 692 | |
| 693 | static int __init psb_init(void) |
| 694 | { |
| 695 | return drm_pci_init(&driver, &psb_pci_driver); |
| 696 | } |
| 697 | |
| 698 | static void __exit psb_exit(void) |
| 699 | { |
| 700 | drm_pci_exit(&driver, &psb_pci_driver); |
| 701 | } |
| 702 | |
| 703 | late_initcall(psb_init); |
| 704 | module_exit(psb_exit); |
| 705 | |
| 706 | MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others"); |
| 707 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 708 | MODULE_LICENSE("GPL"); |