1*5c49fd3aSAlan Cox /************************************************************************** 2*5c49fd3aSAlan Cox * Copyright (c) 2007-2011, Intel Corporation. 3*5c49fd3aSAlan Cox * All Rights Reserved. 4*5c49fd3aSAlan Cox * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA. 5*5c49fd3aSAlan Cox * All Rights Reserved. 6*5c49fd3aSAlan Cox * 7*5c49fd3aSAlan Cox * This program is free software; you can redistribute it and/or modify it 8*5c49fd3aSAlan Cox * under the terms and conditions of the GNU General Public License, 9*5c49fd3aSAlan Cox * version 2, as published by the Free Software Foundation. 10*5c49fd3aSAlan Cox * 11*5c49fd3aSAlan Cox * This program is distributed in the hope it will be useful, but WITHOUT 12*5c49fd3aSAlan Cox * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*5c49fd3aSAlan Cox * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14*5c49fd3aSAlan Cox * more details. 15*5c49fd3aSAlan Cox * 16*5c49fd3aSAlan Cox * You should have received a copy of the GNU General Public License along with 17*5c49fd3aSAlan Cox * this program; if not, write to the Free Software Foundation, Inc., 18*5c49fd3aSAlan Cox * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 19*5c49fd3aSAlan Cox * 20*5c49fd3aSAlan Cox **************************************************************************/ 21*5c49fd3aSAlan Cox 22*5c49fd3aSAlan Cox #include <drm/drmP.h> 23*5c49fd3aSAlan Cox #include <drm/drm.h> 24*5c49fd3aSAlan Cox #include "psb_drm.h" 25*5c49fd3aSAlan Cox #include "psb_drv.h" 26*5c49fd3aSAlan Cox #include "framebuffer.h" 27*5c49fd3aSAlan Cox #include "psb_reg.h" 28*5c49fd3aSAlan Cox #include "psb_intel_reg.h" 29*5c49fd3aSAlan Cox #include "intel_bios.h" 30*5c49fd3aSAlan Cox #include "mid_bios.h" 31*5c49fd3aSAlan Cox #include <drm/drm_pciids.h> 32*5c49fd3aSAlan Cox #include "power.h" 33*5c49fd3aSAlan Cox #include <linux/cpu.h> 34*5c49fd3aSAlan Cox #include <linux/notifier.h> 35*5c49fd3aSAlan Cox #include <linux/spinlock.h> 36*5c49fd3aSAlan Cox #include <linux/pm_runtime.h> 37*5c49fd3aSAlan Cox #include <acpi/video.h> 38*5c49fd3aSAlan Cox 39*5c49fd3aSAlan Cox static int drm_psb_trap_pagefaults; 40*5c49fd3aSAlan Cox 41*5c49fd3aSAlan Cox int drm_psb_no_fb; 42*5c49fd3aSAlan Cox 43*5c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 44*5c49fd3aSAlan Cox 45*5c49fd3aSAlan Cox MODULE_PARM_DESC(no_fb, "Disable FBdev"); 46*5c49fd3aSAlan Cox MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults"); 47*5c49fd3aSAlan Cox module_param_named(no_fb, drm_psb_no_fb, int, 0600); 48*5c49fd3aSAlan Cox module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600); 49*5c49fd3aSAlan Cox 50*5c49fd3aSAlan Cox 51*5c49fd3aSAlan Cox static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { 52*5c49fd3aSAlan Cox { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 53*5c49fd3aSAlan Cox { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops }, 54*5c49fd3aSAlan Cox #if defined(CONFIG_DRM_OAKTRAIL) 55*5c49fd3aSAlan Cox { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 56*5c49fd3aSAlan Cox { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 57*5c49fd3aSAlan Cox { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 58*5c49fd3aSAlan Cox { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 59*5c49fd3aSAlan Cox { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 60*5c49fd3aSAlan Cox { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 61*5c49fd3aSAlan Cox { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 62*5c49fd3aSAlan Cox { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops}, 63*5c49fd3aSAlan Cox #endif 64*5c49fd3aSAlan Cox #if defined(CONFIG_DRM_CDV) 65*5c49fd3aSAlan Cox { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 66*5c49fd3aSAlan Cox { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 67*5c49fd3aSAlan Cox { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 68*5c49fd3aSAlan Cox { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 69*5c49fd3aSAlan Cox { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 70*5c49fd3aSAlan Cox { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 71*5c49fd3aSAlan Cox { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 72*5c49fd3aSAlan Cox { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops}, 73*5c49fd3aSAlan Cox #endif 74*5c49fd3aSAlan Cox { 0, 0, 0} 75*5c49fd3aSAlan Cox }; 76*5c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist); 77*5c49fd3aSAlan Cox 78*5c49fd3aSAlan Cox /* 79*5c49fd3aSAlan Cox * Standard IOCTLs. 80*5c49fd3aSAlan Cox */ 81*5c49fd3aSAlan Cox 82*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_SIZES \ 83*5c49fd3aSAlan Cox DRM_IOR(DRM_PSB_SIZES + DRM_COMMAND_BASE, \ 84*5c49fd3aSAlan Cox struct drm_psb_sizes_arg) 85*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_FUSE_REG \ 86*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_FUSE_REG + DRM_COMMAND_BASE, uint32_t) 87*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DC_STATE \ 88*5c49fd3aSAlan Cox DRM_IOW(DRM_PSB_DC_STATE + DRM_COMMAND_BASE, \ 89*5c49fd3aSAlan Cox struct drm_psb_dc_state_arg) 90*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_ADB \ 91*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_ADB + DRM_COMMAND_BASE, uint32_t) 92*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_MODE_OPERATION \ 93*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_MODE_OPERATION + DRM_COMMAND_BASE, \ 94*5c49fd3aSAlan Cox struct drm_psb_mode_operation_arg) 95*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_STOLEN_MEMORY \ 96*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_STOLEN_MEMORY + DRM_COMMAND_BASE, \ 97*5c49fd3aSAlan Cox struct drm_psb_stolen_memory_arg) 98*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_REGISTER_RW \ 99*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_REGISTER_RW + DRM_COMMAND_BASE, \ 100*5c49fd3aSAlan Cox struct drm_psb_register_rw_arg) 101*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DPST \ 102*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_DPST + DRM_COMMAND_BASE, \ 103*5c49fd3aSAlan Cox uint32_t) 104*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GAMMA \ 105*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_GAMMA + DRM_COMMAND_BASE, \ 106*5c49fd3aSAlan Cox struct drm_psb_dpst_lut_arg) 107*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DPST_BL \ 108*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_DPST_BL + DRM_COMMAND_BASE, \ 109*5c49fd3aSAlan Cox uint32_t) 110*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID \ 111*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \ 112*5c49fd3aSAlan Cox struct drm_psb_get_pipe_from_crtc_id_arg) 113*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_CREATE \ 114*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_GEM_CREATE + DRM_COMMAND_BASE, \ 115*5c49fd3aSAlan Cox struct drm_psb_gem_create) 116*5c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_MMAP \ 117*5c49fd3aSAlan Cox DRM_IOWR(DRM_PSB_GEM_MMAP + DRM_COMMAND_BASE, \ 118*5c49fd3aSAlan Cox struct drm_psb_gem_mmap) 119*5c49fd3aSAlan Cox 120*5c49fd3aSAlan Cox static int psb_sizes_ioctl(struct drm_device *dev, void *data, 121*5c49fd3aSAlan Cox struct drm_file *file_priv); 122*5c49fd3aSAlan Cox static int psb_dc_state_ioctl(struct drm_device *dev, void * data, 123*5c49fd3aSAlan Cox struct drm_file *file_priv); 124*5c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data, 125*5c49fd3aSAlan Cox struct drm_file *file_priv); 126*5c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data, 127*5c49fd3aSAlan Cox struct drm_file *file_priv); 128*5c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data, 129*5c49fd3aSAlan Cox struct drm_file *file_priv); 130*5c49fd3aSAlan Cox static int psb_register_rw_ioctl(struct drm_device *dev, void *data, 131*5c49fd3aSAlan Cox struct drm_file *file_priv); 132*5c49fd3aSAlan Cox static int psb_dpst_ioctl(struct drm_device *dev, void *data, 133*5c49fd3aSAlan Cox struct drm_file *file_priv); 134*5c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data, 135*5c49fd3aSAlan Cox struct drm_file *file_priv); 136*5c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data, 137*5c49fd3aSAlan Cox struct drm_file *file_priv); 138*5c49fd3aSAlan Cox 139*5c49fd3aSAlan Cox #define PSB_IOCTL_DEF(ioctl, func, flags) \ 140*5c49fd3aSAlan Cox [DRM_IOCTL_NR(ioctl) - DRM_COMMAND_BASE] = {ioctl, flags, func} 141*5c49fd3aSAlan Cox 142*5c49fd3aSAlan Cox static struct drm_ioctl_desc psb_ioctls[] = { 143*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_SIZES, psb_sizes_ioctl, DRM_AUTH), 144*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_DC_STATE, psb_dc_state_ioctl, DRM_AUTH), 145*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_ADB, psb_adb_ioctl, DRM_AUTH), 146*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_MODE_OPERATION, psb_mode_operation_ioctl, 147*5c49fd3aSAlan Cox DRM_AUTH), 148*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_STOLEN_MEMORY, psb_stolen_memory_ioctl, 149*5c49fd3aSAlan Cox DRM_AUTH), 150*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_REGISTER_RW, psb_register_rw_ioctl, 151*5c49fd3aSAlan Cox DRM_AUTH), 152*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST, psb_dpst_ioctl, DRM_AUTH), 153*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA, psb_gamma_ioctl, DRM_AUTH), 154*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH), 155*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID, 156*5c49fd3aSAlan Cox psb_intel_get_pipe_from_crtc_id, 0), 157*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_CREATE, psb_gem_create_ioctl, 158*5c49fd3aSAlan Cox DRM_UNLOCKED | DRM_AUTH), 159*5c49fd3aSAlan Cox PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_MMAP, psb_gem_mmap_ioctl, 160*5c49fd3aSAlan Cox DRM_UNLOCKED | DRM_AUTH), 161*5c49fd3aSAlan Cox }; 162*5c49fd3aSAlan Cox 163*5c49fd3aSAlan Cox static void psb_lastclose(struct drm_device *dev) 164*5c49fd3aSAlan Cox { 165*5c49fd3aSAlan Cox return; 166*5c49fd3aSAlan Cox } 167*5c49fd3aSAlan Cox 168*5c49fd3aSAlan Cox static void psb_do_takedown(struct drm_device *dev) 169*5c49fd3aSAlan Cox { 170*5c49fd3aSAlan Cox /* FIXME: do we need to clean up the gtt here ? */ 171*5c49fd3aSAlan Cox } 172*5c49fd3aSAlan Cox 173*5c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev) 174*5c49fd3aSAlan Cox { 175*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 176*5c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 177*5c49fd3aSAlan Cox 178*5c49fd3aSAlan Cox uint32_t stolen_gtt; 179*5c49fd3aSAlan Cox 180*5c49fd3aSAlan Cox int ret = -ENOMEM; 181*5c49fd3aSAlan Cox 182*5c49fd3aSAlan Cox if (pg->mmu_gatt_start & 0x0FFFFFFF) { 183*5c49fd3aSAlan Cox dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n"); 184*5c49fd3aSAlan Cox ret = -EINVAL; 185*5c49fd3aSAlan Cox goto out_err; 186*5c49fd3aSAlan Cox } 187*5c49fd3aSAlan Cox 188*5c49fd3aSAlan Cox 189*5c49fd3aSAlan Cox stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4; 190*5c49fd3aSAlan Cox stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT; 191*5c49fd3aSAlan Cox stolen_gtt = 192*5c49fd3aSAlan Cox (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages; 193*5c49fd3aSAlan Cox 194*5c49fd3aSAlan Cox dev_priv->gatt_free_offset = pg->mmu_gatt_start + 195*5c49fd3aSAlan Cox (stolen_gtt << PAGE_SHIFT) * 1024; 196*5c49fd3aSAlan Cox 197*5c49fd3aSAlan Cox if (1 || drm_debug) { 198*5c49fd3aSAlan Cox uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID); 199*5c49fd3aSAlan Cox uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION); 200*5c49fd3aSAlan Cox DRM_INFO("SGX core id = 0x%08x\n", core_id); 201*5c49fd3aSAlan Cox DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n", 202*5c49fd3aSAlan Cox (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >> 203*5c49fd3aSAlan Cox _PSB_CC_REVISION_MAJOR_SHIFT, 204*5c49fd3aSAlan Cox (core_rev & _PSB_CC_REVISION_MINOR_MASK) >> 205*5c49fd3aSAlan Cox _PSB_CC_REVISION_MINOR_SHIFT); 206*5c49fd3aSAlan Cox DRM_INFO 207*5c49fd3aSAlan Cox ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n", 208*5c49fd3aSAlan Cox (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >> 209*5c49fd3aSAlan Cox _PSB_CC_REVISION_MAINTENANCE_SHIFT, 210*5c49fd3aSAlan Cox (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >> 211*5c49fd3aSAlan Cox _PSB_CC_REVISION_DESIGNER_SHIFT); 212*5c49fd3aSAlan Cox } 213*5c49fd3aSAlan Cox 214*5c49fd3aSAlan Cox 215*5c49fd3aSAlan Cox spin_lock_init(&dev_priv->irqmask_lock); 216*5c49fd3aSAlan Cox mutex_init(&dev_priv->mutex_2d); 217*5c49fd3aSAlan Cox 218*5c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); 219*5c49fd3aSAlan Cox PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1); 220*5c49fd3aSAlan Cox PSB_RSGX32(PSB_CR_BIF_BANK1); 221*5c49fd3aSAlan Cox PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK, 222*5c49fd3aSAlan Cox PSB_CR_BIF_CTRL); 223*5c49fd3aSAlan Cox psb_spank(dev_priv); 224*5c49fd3aSAlan Cox 225*5c49fd3aSAlan Cox /* mmu_gatt ?? */ 226*5c49fd3aSAlan Cox PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); 227*5c49fd3aSAlan Cox return 0; 228*5c49fd3aSAlan Cox out_err: 229*5c49fd3aSAlan Cox psb_do_takedown(dev); 230*5c49fd3aSAlan Cox return ret; 231*5c49fd3aSAlan Cox } 232*5c49fd3aSAlan Cox 233*5c49fd3aSAlan Cox static int psb_driver_unload(struct drm_device *dev) 234*5c49fd3aSAlan Cox { 235*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 236*5c49fd3aSAlan Cox 237*5c49fd3aSAlan Cox /* Kill vblank etc here */ 238*5c49fd3aSAlan Cox 239*5c49fd3aSAlan Cox gma_backlight_exit(dev); 240*5c49fd3aSAlan Cox 241*5c49fd3aSAlan Cox if (drm_psb_no_fb == 0) 242*5c49fd3aSAlan Cox psb_modeset_cleanup(dev); 243*5c49fd3aSAlan Cox 244*5c49fd3aSAlan Cox if (dev_priv) { 245*5c49fd3aSAlan Cox psb_lid_timer_takedown(dev_priv); 246*5c49fd3aSAlan Cox gma_intel_opregion_exit(dev); 247*5c49fd3aSAlan Cox 248*5c49fd3aSAlan Cox if (dev_priv->ops->chip_teardown) 249*5c49fd3aSAlan Cox dev_priv->ops->chip_teardown(dev); 250*5c49fd3aSAlan Cox psb_do_takedown(dev); 251*5c49fd3aSAlan Cox 252*5c49fd3aSAlan Cox 253*5c49fd3aSAlan Cox if (dev_priv->pf_pd) { 254*5c49fd3aSAlan Cox psb_mmu_free_pagedir(dev_priv->pf_pd); 255*5c49fd3aSAlan Cox dev_priv->pf_pd = NULL; 256*5c49fd3aSAlan Cox } 257*5c49fd3aSAlan Cox if (dev_priv->mmu) { 258*5c49fd3aSAlan Cox struct psb_gtt *pg = &dev_priv->gtt; 259*5c49fd3aSAlan Cox 260*5c49fd3aSAlan Cox down_read(&pg->sem); 261*5c49fd3aSAlan Cox psb_mmu_remove_pfn_sequence( 262*5c49fd3aSAlan Cox psb_mmu_get_default_pd 263*5c49fd3aSAlan Cox (dev_priv->mmu), 264*5c49fd3aSAlan Cox pg->mmu_gatt_start, 265*5c49fd3aSAlan Cox dev_priv->vram_stolen_size >> PAGE_SHIFT); 266*5c49fd3aSAlan Cox up_read(&pg->sem); 267*5c49fd3aSAlan Cox psb_mmu_driver_takedown(dev_priv->mmu); 268*5c49fd3aSAlan Cox dev_priv->mmu = NULL; 269*5c49fd3aSAlan Cox } 270*5c49fd3aSAlan Cox psb_gtt_takedown(dev); 271*5c49fd3aSAlan Cox if (dev_priv->scratch_page) { 272*5c49fd3aSAlan Cox __free_page(dev_priv->scratch_page); 273*5c49fd3aSAlan Cox dev_priv->scratch_page = NULL; 274*5c49fd3aSAlan Cox } 275*5c49fd3aSAlan Cox if (dev_priv->vdc_reg) { 276*5c49fd3aSAlan Cox iounmap(dev_priv->vdc_reg); 277*5c49fd3aSAlan Cox dev_priv->vdc_reg = NULL; 278*5c49fd3aSAlan Cox } 279*5c49fd3aSAlan Cox if (dev_priv->sgx_reg) { 280*5c49fd3aSAlan Cox iounmap(dev_priv->sgx_reg); 281*5c49fd3aSAlan Cox dev_priv->sgx_reg = NULL; 282*5c49fd3aSAlan Cox } 283*5c49fd3aSAlan Cox 284*5c49fd3aSAlan Cox kfree(dev_priv); 285*5c49fd3aSAlan Cox dev->dev_private = NULL; 286*5c49fd3aSAlan Cox 287*5c49fd3aSAlan Cox /*destroy VBT data*/ 288*5c49fd3aSAlan Cox psb_intel_destroy_bios(dev); 289*5c49fd3aSAlan Cox } 290*5c49fd3aSAlan Cox 291*5c49fd3aSAlan Cox gma_power_uninit(dev); 292*5c49fd3aSAlan Cox 293*5c49fd3aSAlan Cox return 0; 294*5c49fd3aSAlan Cox } 295*5c49fd3aSAlan Cox 296*5c49fd3aSAlan Cox 297*5c49fd3aSAlan Cox static int psb_driver_load(struct drm_device *dev, unsigned long chipset) 298*5c49fd3aSAlan Cox { 299*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv; 300*5c49fd3aSAlan Cox unsigned long resource_start; 301*5c49fd3aSAlan Cox struct psb_gtt *pg; 302*5c49fd3aSAlan Cox unsigned long irqflags; 303*5c49fd3aSAlan Cox int ret = -ENOMEM; 304*5c49fd3aSAlan Cox uint32_t tt_pages; 305*5c49fd3aSAlan Cox struct drm_connector *connector; 306*5c49fd3aSAlan Cox struct psb_intel_output *psb_intel_output; 307*5c49fd3aSAlan Cox 308*5c49fd3aSAlan Cox dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 309*5c49fd3aSAlan Cox if (dev_priv == NULL) 310*5c49fd3aSAlan Cox return -ENOMEM; 311*5c49fd3aSAlan Cox 312*5c49fd3aSAlan Cox dev_priv->ops = (struct psb_ops *)chipset; 313*5c49fd3aSAlan Cox dev_priv->dev = dev; 314*5c49fd3aSAlan Cox dev->dev_private = (void *) dev_priv; 315*5c49fd3aSAlan Cox 316*5c49fd3aSAlan Cox dev_priv->num_pipe = dev_priv->ops->pipes; 317*5c49fd3aSAlan Cox 318*5c49fd3aSAlan Cox resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); 319*5c49fd3aSAlan Cox 320*5c49fd3aSAlan Cox dev_priv->vdc_reg = 321*5c49fd3aSAlan Cox ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE); 322*5c49fd3aSAlan Cox if (!dev_priv->vdc_reg) 323*5c49fd3aSAlan Cox goto out_err; 324*5c49fd3aSAlan Cox 325*5c49fd3aSAlan Cox dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset, 326*5c49fd3aSAlan Cox PSB_SGX_SIZE); 327*5c49fd3aSAlan Cox if (!dev_priv->sgx_reg) 328*5c49fd3aSAlan Cox goto out_err; 329*5c49fd3aSAlan Cox 330*5c49fd3aSAlan Cox ret = dev_priv->ops->chip_setup(dev); 331*5c49fd3aSAlan Cox if (ret) 332*5c49fd3aSAlan Cox goto out_err; 333*5c49fd3aSAlan Cox 334*5c49fd3aSAlan Cox /* Init OSPM support */ 335*5c49fd3aSAlan Cox gma_power_init(dev); 336*5c49fd3aSAlan Cox 337*5c49fd3aSAlan Cox ret = -ENOMEM; 338*5c49fd3aSAlan Cox 339*5c49fd3aSAlan Cox dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO); 340*5c49fd3aSAlan Cox if (!dev_priv->scratch_page) 341*5c49fd3aSAlan Cox goto out_err; 342*5c49fd3aSAlan Cox 343*5c49fd3aSAlan Cox set_pages_uc(dev_priv->scratch_page, 1); 344*5c49fd3aSAlan Cox 345*5c49fd3aSAlan Cox ret = psb_gtt_init(dev, 0); 346*5c49fd3aSAlan Cox if (ret) 347*5c49fd3aSAlan Cox goto out_err; 348*5c49fd3aSAlan Cox 349*5c49fd3aSAlan Cox dev_priv->mmu = psb_mmu_driver_init((void *)0, 350*5c49fd3aSAlan Cox drm_psb_trap_pagefaults, 0, 351*5c49fd3aSAlan Cox dev_priv); 352*5c49fd3aSAlan Cox if (!dev_priv->mmu) 353*5c49fd3aSAlan Cox goto out_err; 354*5c49fd3aSAlan Cox 355*5c49fd3aSAlan Cox pg = &dev_priv->gtt; 356*5c49fd3aSAlan Cox 357*5c49fd3aSAlan Cox tt_pages = (pg->gatt_pages < PSB_TT_PRIV0_PLIMIT) ? 358*5c49fd3aSAlan Cox (pg->gatt_pages) : PSB_TT_PRIV0_PLIMIT; 359*5c49fd3aSAlan Cox 360*5c49fd3aSAlan Cox 361*5c49fd3aSAlan Cox dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); 362*5c49fd3aSAlan Cox if (!dev_priv->pf_pd) 363*5c49fd3aSAlan Cox goto out_err; 364*5c49fd3aSAlan Cox 365*5c49fd3aSAlan Cox psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); 366*5c49fd3aSAlan Cox psb_mmu_set_pd_context(dev_priv->pf_pd, 1); 367*5c49fd3aSAlan Cox 368*5c49fd3aSAlan Cox ret = psb_do_init(dev); 369*5c49fd3aSAlan Cox if (ret) 370*5c49fd3aSAlan Cox return ret; 371*5c49fd3aSAlan Cox 372*5c49fd3aSAlan Cox PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); 373*5c49fd3aSAlan Cox PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); 374*5c49fd3aSAlan Cox 375*5c49fd3aSAlan Cox /* igd_opregion_init(&dev_priv->opregion_dev); */ 376*5c49fd3aSAlan Cox acpi_video_register(); 377*5c49fd3aSAlan Cox if (dev_priv->lid_state) 378*5c49fd3aSAlan Cox psb_lid_timer_init(dev_priv); 379*5c49fd3aSAlan Cox 380*5c49fd3aSAlan Cox ret = drm_vblank_init(dev, dev_priv->num_pipe); 381*5c49fd3aSAlan Cox if (ret) 382*5c49fd3aSAlan Cox goto out_err; 383*5c49fd3aSAlan Cox 384*5c49fd3aSAlan Cox /* 385*5c49fd3aSAlan Cox * Install interrupt handlers prior to powering off SGX or else we will 386*5c49fd3aSAlan Cox * crash. 387*5c49fd3aSAlan Cox */ 388*5c49fd3aSAlan Cox dev_priv->vdc_irq_mask = 0; 389*5c49fd3aSAlan Cox dev_priv->pipestat[0] = 0; 390*5c49fd3aSAlan Cox dev_priv->pipestat[1] = 0; 391*5c49fd3aSAlan Cox dev_priv->pipestat[2] = 0; 392*5c49fd3aSAlan Cox spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); 393*5c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); 394*5c49fd3aSAlan Cox PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R); 395*5c49fd3aSAlan Cox PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R); 396*5c49fd3aSAlan Cox spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); 397*5c49fd3aSAlan Cox if (drm_core_check_feature(dev, DRIVER_MODESET)) 398*5c49fd3aSAlan Cox drm_irq_install(dev); 399*5c49fd3aSAlan Cox 400*5c49fd3aSAlan Cox dev->vblank_disable_allowed = 1; 401*5c49fd3aSAlan Cox 402*5c49fd3aSAlan Cox dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ 403*5c49fd3aSAlan Cox 404*5c49fd3aSAlan Cox dev->driver->get_vblank_counter = psb_get_vblank_counter; 405*5c49fd3aSAlan Cox 406*5c49fd3aSAlan Cox if (drm_psb_no_fb == 0) { 407*5c49fd3aSAlan Cox psb_modeset_init(dev); 408*5c49fd3aSAlan Cox psb_fbdev_init(dev); 409*5c49fd3aSAlan Cox drm_kms_helper_poll_init(dev); 410*5c49fd3aSAlan Cox } 411*5c49fd3aSAlan Cox 412*5c49fd3aSAlan Cox /* Only add backlight support if we have LVDS output */ 413*5c49fd3aSAlan Cox list_for_each_entry(connector, &dev->mode_config.connector_list, 414*5c49fd3aSAlan Cox head) { 415*5c49fd3aSAlan Cox psb_intel_output = to_psb_intel_output(connector); 416*5c49fd3aSAlan Cox 417*5c49fd3aSAlan Cox switch (psb_intel_output->type) { 418*5c49fd3aSAlan Cox case INTEL_OUTPUT_LVDS: 419*5c49fd3aSAlan Cox case INTEL_OUTPUT_MIPI: 420*5c49fd3aSAlan Cox ret = gma_backlight_init(dev); 421*5c49fd3aSAlan Cox break; 422*5c49fd3aSAlan Cox } 423*5c49fd3aSAlan Cox } 424*5c49fd3aSAlan Cox 425*5c49fd3aSAlan Cox if (ret) 426*5c49fd3aSAlan Cox return ret; 427*5c49fd3aSAlan Cox #if 0 428*5c49fd3aSAlan Cox /*enable runtime pm at last*/ 429*5c49fd3aSAlan Cox pm_runtime_enable(&dev->pdev->dev); 430*5c49fd3aSAlan Cox pm_runtime_set_active(&dev->pdev->dev); 431*5c49fd3aSAlan Cox #endif 432*5c49fd3aSAlan Cox /*Intel drm driver load is done, continue doing pvr load*/ 433*5c49fd3aSAlan Cox return 0; 434*5c49fd3aSAlan Cox out_err: 435*5c49fd3aSAlan Cox psb_driver_unload(dev); 436*5c49fd3aSAlan Cox return ret; 437*5c49fd3aSAlan Cox } 438*5c49fd3aSAlan Cox 439*5c49fd3aSAlan Cox int psb_driver_device_is_agp(struct drm_device *dev) 440*5c49fd3aSAlan Cox { 441*5c49fd3aSAlan Cox return 0; 442*5c49fd3aSAlan Cox } 443*5c49fd3aSAlan Cox 444*5c49fd3aSAlan Cox 445*5c49fd3aSAlan Cox static int psb_sizes_ioctl(struct drm_device *dev, void *data, 446*5c49fd3aSAlan Cox struct drm_file *file_priv) 447*5c49fd3aSAlan Cox { 448*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 449*5c49fd3aSAlan Cox struct drm_psb_sizes_arg *arg = 450*5c49fd3aSAlan Cox (struct drm_psb_sizes_arg *) data; 451*5c49fd3aSAlan Cox 452*5c49fd3aSAlan Cox *arg = dev_priv->sizes; 453*5c49fd3aSAlan Cox return 0; 454*5c49fd3aSAlan Cox } 455*5c49fd3aSAlan Cox 456*5c49fd3aSAlan Cox static int psb_dc_state_ioctl(struct drm_device *dev, void * data, 457*5c49fd3aSAlan Cox struct drm_file *file_priv) 458*5c49fd3aSAlan Cox { 459*5c49fd3aSAlan Cox uint32_t flags; 460*5c49fd3aSAlan Cox uint32_t obj_id; 461*5c49fd3aSAlan Cox struct drm_mode_object *obj; 462*5c49fd3aSAlan Cox struct drm_connector *connector; 463*5c49fd3aSAlan Cox struct drm_crtc *crtc; 464*5c49fd3aSAlan Cox struct drm_psb_dc_state_arg *arg = data; 465*5c49fd3aSAlan Cox 466*5c49fd3aSAlan Cox 467*5c49fd3aSAlan Cox /* Double check MRST case */ 468*5c49fd3aSAlan Cox if (IS_MRST(dev) || IS_MFLD(dev)) 469*5c49fd3aSAlan Cox return -EOPNOTSUPP; 470*5c49fd3aSAlan Cox 471*5c49fd3aSAlan Cox flags = arg->flags; 472*5c49fd3aSAlan Cox obj_id = arg->obj_id; 473*5c49fd3aSAlan Cox 474*5c49fd3aSAlan Cox if (flags & PSB_DC_CRTC_MASK) { 475*5c49fd3aSAlan Cox obj = drm_mode_object_find(dev, obj_id, 476*5c49fd3aSAlan Cox DRM_MODE_OBJECT_CRTC); 477*5c49fd3aSAlan Cox if (!obj) { 478*5c49fd3aSAlan Cox dev_dbg(dev->dev, "Invalid CRTC object.\n"); 479*5c49fd3aSAlan Cox return -EINVAL; 480*5c49fd3aSAlan Cox } 481*5c49fd3aSAlan Cox 482*5c49fd3aSAlan Cox crtc = obj_to_crtc(obj); 483*5c49fd3aSAlan Cox 484*5c49fd3aSAlan Cox mutex_lock(&dev->mode_config.mutex); 485*5c49fd3aSAlan Cox if (drm_helper_crtc_in_use(crtc)) { 486*5c49fd3aSAlan Cox if (flags & PSB_DC_CRTC_SAVE) 487*5c49fd3aSAlan Cox crtc->funcs->save(crtc); 488*5c49fd3aSAlan Cox else 489*5c49fd3aSAlan Cox crtc->funcs->restore(crtc); 490*5c49fd3aSAlan Cox } 491*5c49fd3aSAlan Cox mutex_unlock(&dev->mode_config.mutex); 492*5c49fd3aSAlan Cox 493*5c49fd3aSAlan Cox return 0; 494*5c49fd3aSAlan Cox } else if (flags & PSB_DC_OUTPUT_MASK) { 495*5c49fd3aSAlan Cox obj = drm_mode_object_find(dev, obj_id, 496*5c49fd3aSAlan Cox DRM_MODE_OBJECT_CONNECTOR); 497*5c49fd3aSAlan Cox if (!obj) { 498*5c49fd3aSAlan Cox dev_dbg(dev->dev, "Invalid connector id.\n"); 499*5c49fd3aSAlan Cox return -EINVAL; 500*5c49fd3aSAlan Cox } 501*5c49fd3aSAlan Cox 502*5c49fd3aSAlan Cox connector = obj_to_connector(obj); 503*5c49fd3aSAlan Cox if (flags & PSB_DC_OUTPUT_SAVE) 504*5c49fd3aSAlan Cox connector->funcs->save(connector); 505*5c49fd3aSAlan Cox else 506*5c49fd3aSAlan Cox connector->funcs->restore(connector); 507*5c49fd3aSAlan Cox 508*5c49fd3aSAlan Cox return 0; 509*5c49fd3aSAlan Cox } 510*5c49fd3aSAlan Cox return -EINVAL; 511*5c49fd3aSAlan Cox } 512*5c49fd3aSAlan Cox 513*5c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd) 514*5c49fd3aSAlan Cox { 515*5c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE 516*5c49fd3aSAlan Cox if (bd) { 517*5c49fd3aSAlan Cox bd->props.brightness = bd->ops->get_brightness(bd); 518*5c49fd3aSAlan Cox backlight_update_status(bd); 519*5c49fd3aSAlan Cox } 520*5c49fd3aSAlan Cox #endif 521*5c49fd3aSAlan Cox } 522*5c49fd3aSAlan Cox 523*5c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data, 524*5c49fd3aSAlan Cox struct drm_file *file_priv) 525*5c49fd3aSAlan Cox { 526*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 527*5c49fd3aSAlan Cox uint32_t *arg = data; 528*5c49fd3aSAlan Cox 529*5c49fd3aSAlan Cox dev_priv->blc_adj2 = *arg; 530*5c49fd3aSAlan Cox get_brightness(dev_priv->backlight_device); 531*5c49fd3aSAlan Cox return 0; 532*5c49fd3aSAlan Cox } 533*5c49fd3aSAlan Cox 534*5c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data, 535*5c49fd3aSAlan Cox struct drm_file *file_priv) 536*5c49fd3aSAlan Cox { 537*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 538*5c49fd3aSAlan Cox uint32_t *arg = data; 539*5c49fd3aSAlan Cox 540*5c49fd3aSAlan Cox dev_priv->blc_adj1 = *arg; 541*5c49fd3aSAlan Cox get_brightness(dev_priv->backlight_device); 542*5c49fd3aSAlan Cox return 0; 543*5c49fd3aSAlan Cox } 544*5c49fd3aSAlan Cox 545*5c49fd3aSAlan Cox /* return the current mode to the dpst module */ 546*5c49fd3aSAlan Cox static int psb_dpst_ioctl(struct drm_device *dev, void *data, 547*5c49fd3aSAlan Cox struct drm_file *file_priv) 548*5c49fd3aSAlan Cox { 549*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 550*5c49fd3aSAlan Cox uint32_t *arg = data; 551*5c49fd3aSAlan Cox uint32_t x; 552*5c49fd3aSAlan Cox uint32_t y; 553*5c49fd3aSAlan Cox uint32_t reg; 554*5c49fd3aSAlan Cox 555*5c49fd3aSAlan Cox if (!gma_power_begin(dev, 0)) 556*5c49fd3aSAlan Cox return -EIO; 557*5c49fd3aSAlan Cox 558*5c49fd3aSAlan Cox reg = PSB_RVDC32(PIPEASRC); 559*5c49fd3aSAlan Cox 560*5c49fd3aSAlan Cox gma_power_end(dev); 561*5c49fd3aSAlan Cox 562*5c49fd3aSAlan Cox /* horizontal is the left 16 bits */ 563*5c49fd3aSAlan Cox x = reg >> 16; 564*5c49fd3aSAlan Cox /* vertical is the right 16 bits */ 565*5c49fd3aSAlan Cox y = reg & 0x0000ffff; 566*5c49fd3aSAlan Cox 567*5c49fd3aSAlan Cox /* the values are the image size minus one */ 568*5c49fd3aSAlan Cox x++; 569*5c49fd3aSAlan Cox y++; 570*5c49fd3aSAlan Cox 571*5c49fd3aSAlan Cox *arg = (x << 16) | y; 572*5c49fd3aSAlan Cox 573*5c49fd3aSAlan Cox return 0; 574*5c49fd3aSAlan Cox } 575*5c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data, 576*5c49fd3aSAlan Cox struct drm_file *file_priv) 577*5c49fd3aSAlan Cox { 578*5c49fd3aSAlan Cox struct drm_psb_dpst_lut_arg *lut_arg = data; 579*5c49fd3aSAlan Cox struct drm_mode_object *obj; 580*5c49fd3aSAlan Cox struct drm_crtc *crtc; 581*5c49fd3aSAlan Cox struct drm_connector *connector; 582*5c49fd3aSAlan Cox struct psb_intel_crtc *psb_intel_crtc; 583*5c49fd3aSAlan Cox int i = 0; 584*5c49fd3aSAlan Cox int32_t obj_id; 585*5c49fd3aSAlan Cox 586*5c49fd3aSAlan Cox obj_id = lut_arg->output_id; 587*5c49fd3aSAlan Cox obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR); 588*5c49fd3aSAlan Cox if (!obj) { 589*5c49fd3aSAlan Cox dev_dbg(dev->dev, "Invalid Connector object.\n"); 590*5c49fd3aSAlan Cox return -EINVAL; 591*5c49fd3aSAlan Cox } 592*5c49fd3aSAlan Cox 593*5c49fd3aSAlan Cox connector = obj_to_connector(obj); 594*5c49fd3aSAlan Cox crtc = connector->encoder->crtc; 595*5c49fd3aSAlan Cox psb_intel_crtc = to_psb_intel_crtc(crtc); 596*5c49fd3aSAlan Cox 597*5c49fd3aSAlan Cox for (i = 0; i < 256; i++) 598*5c49fd3aSAlan Cox psb_intel_crtc->lut_adj[i] = lut_arg->lut[i]; 599*5c49fd3aSAlan Cox 600*5c49fd3aSAlan Cox psb_intel_crtc_load_lut(crtc); 601*5c49fd3aSAlan Cox 602*5c49fd3aSAlan Cox return 0; 603*5c49fd3aSAlan Cox } 604*5c49fd3aSAlan Cox 605*5c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data, 606*5c49fd3aSAlan Cox struct drm_file *file_priv) 607*5c49fd3aSAlan Cox { 608*5c49fd3aSAlan Cox uint32_t obj_id; 609*5c49fd3aSAlan Cox uint16_t op; 610*5c49fd3aSAlan Cox struct drm_mode_modeinfo *umode; 611*5c49fd3aSAlan Cox struct drm_display_mode *mode = NULL; 612*5c49fd3aSAlan Cox struct drm_psb_mode_operation_arg *arg; 613*5c49fd3aSAlan Cox struct drm_mode_object *obj; 614*5c49fd3aSAlan Cox struct drm_connector *connector; 615*5c49fd3aSAlan Cox struct drm_framebuffer *drm_fb; 616*5c49fd3aSAlan Cox struct psb_framebuffer *psb_fb; 617*5c49fd3aSAlan Cox struct drm_connector_helper_funcs *connector_funcs; 618*5c49fd3aSAlan Cox int ret = 0; 619*5c49fd3aSAlan Cox int resp = MODE_OK; 620*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 621*5c49fd3aSAlan Cox 622*5c49fd3aSAlan Cox arg = (struct drm_psb_mode_operation_arg *)data; 623*5c49fd3aSAlan Cox obj_id = arg->obj_id; 624*5c49fd3aSAlan Cox op = arg->operation; 625*5c49fd3aSAlan Cox 626*5c49fd3aSAlan Cox switch (op) { 627*5c49fd3aSAlan Cox case PSB_MODE_OPERATION_SET_DC_BASE: 628*5c49fd3aSAlan Cox obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_FB); 629*5c49fd3aSAlan Cox if (!obj) { 630*5c49fd3aSAlan Cox dev_dbg(dev->dev, "Invalid FB id %d\n", obj_id); 631*5c49fd3aSAlan Cox return -EINVAL; 632*5c49fd3aSAlan Cox } 633*5c49fd3aSAlan Cox 634*5c49fd3aSAlan Cox drm_fb = obj_to_fb(obj); 635*5c49fd3aSAlan Cox psb_fb = to_psb_fb(drm_fb); 636*5c49fd3aSAlan Cox 637*5c49fd3aSAlan Cox if (gma_power_begin(dev, 0)) { 638*5c49fd3aSAlan Cox REG_WRITE(DSPASURF, psb_fb->gtt->offset); 639*5c49fd3aSAlan Cox REG_READ(DSPASURF); 640*5c49fd3aSAlan Cox gma_power_end(dev); 641*5c49fd3aSAlan Cox } else { 642*5c49fd3aSAlan Cox dev_priv->saveDSPASURF = psb_fb->gtt->offset; 643*5c49fd3aSAlan Cox } 644*5c49fd3aSAlan Cox 645*5c49fd3aSAlan Cox return 0; 646*5c49fd3aSAlan Cox case PSB_MODE_OPERATION_MODE_VALID: 647*5c49fd3aSAlan Cox umode = &arg->mode; 648*5c49fd3aSAlan Cox 649*5c49fd3aSAlan Cox mutex_lock(&dev->mode_config.mutex); 650*5c49fd3aSAlan Cox 651*5c49fd3aSAlan Cox obj = drm_mode_object_find(dev, obj_id, 652*5c49fd3aSAlan Cox DRM_MODE_OBJECT_CONNECTOR); 653*5c49fd3aSAlan Cox if (!obj) { 654*5c49fd3aSAlan Cox ret = -EINVAL; 655*5c49fd3aSAlan Cox goto mode_op_out; 656*5c49fd3aSAlan Cox } 657*5c49fd3aSAlan Cox 658*5c49fd3aSAlan Cox connector = obj_to_connector(obj); 659*5c49fd3aSAlan Cox 660*5c49fd3aSAlan Cox mode = drm_mode_create(dev); 661*5c49fd3aSAlan Cox if (!mode) { 662*5c49fd3aSAlan Cox ret = -ENOMEM; 663*5c49fd3aSAlan Cox goto mode_op_out; 664*5c49fd3aSAlan Cox } 665*5c49fd3aSAlan Cox 666*5c49fd3aSAlan Cox /* drm_crtc_convert_umode(mode, umode); */ 667*5c49fd3aSAlan Cox { 668*5c49fd3aSAlan Cox mode->clock = umode->clock; 669*5c49fd3aSAlan Cox mode->hdisplay = umode->hdisplay; 670*5c49fd3aSAlan Cox mode->hsync_start = umode->hsync_start; 671*5c49fd3aSAlan Cox mode->hsync_end = umode->hsync_end; 672*5c49fd3aSAlan Cox mode->htotal = umode->htotal; 673*5c49fd3aSAlan Cox mode->hskew = umode->hskew; 674*5c49fd3aSAlan Cox mode->vdisplay = umode->vdisplay; 675*5c49fd3aSAlan Cox mode->vsync_start = umode->vsync_start; 676*5c49fd3aSAlan Cox mode->vsync_end = umode->vsync_end; 677*5c49fd3aSAlan Cox mode->vtotal = umode->vtotal; 678*5c49fd3aSAlan Cox mode->vscan = umode->vscan; 679*5c49fd3aSAlan Cox mode->vrefresh = umode->vrefresh; 680*5c49fd3aSAlan Cox mode->flags = umode->flags; 681*5c49fd3aSAlan Cox mode->type = umode->type; 682*5c49fd3aSAlan Cox strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN); 683*5c49fd3aSAlan Cox mode->name[DRM_DISPLAY_MODE_LEN-1] = 0; 684*5c49fd3aSAlan Cox } 685*5c49fd3aSAlan Cox 686*5c49fd3aSAlan Cox connector_funcs = (struct drm_connector_helper_funcs *) 687*5c49fd3aSAlan Cox connector->helper_private; 688*5c49fd3aSAlan Cox 689*5c49fd3aSAlan Cox if (connector_funcs->mode_valid) { 690*5c49fd3aSAlan Cox resp = connector_funcs->mode_valid(connector, mode); 691*5c49fd3aSAlan Cox arg->data = (void *)resp; 692*5c49fd3aSAlan Cox } 693*5c49fd3aSAlan Cox 694*5c49fd3aSAlan Cox /*do some clean up work*/ 695*5c49fd3aSAlan Cox if (mode) 696*5c49fd3aSAlan Cox drm_mode_destroy(dev, mode); 697*5c49fd3aSAlan Cox mode_op_out: 698*5c49fd3aSAlan Cox mutex_unlock(&dev->mode_config.mutex); 699*5c49fd3aSAlan Cox return ret; 700*5c49fd3aSAlan Cox 701*5c49fd3aSAlan Cox default: 702*5c49fd3aSAlan Cox dev_dbg(dev->dev, "Unsupported psb mode operation\n"); 703*5c49fd3aSAlan Cox return -EOPNOTSUPP; 704*5c49fd3aSAlan Cox } 705*5c49fd3aSAlan Cox 706*5c49fd3aSAlan Cox return 0; 707*5c49fd3aSAlan Cox } 708*5c49fd3aSAlan Cox 709*5c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data, 710*5c49fd3aSAlan Cox struct drm_file *file_priv) 711*5c49fd3aSAlan Cox { 712*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 713*5c49fd3aSAlan Cox struct drm_psb_stolen_memory_arg *arg = data; 714*5c49fd3aSAlan Cox 715*5c49fd3aSAlan Cox arg->base = dev_priv->stolen_base; 716*5c49fd3aSAlan Cox arg->size = dev_priv->vram_stolen_size; 717*5c49fd3aSAlan Cox 718*5c49fd3aSAlan Cox return 0; 719*5c49fd3aSAlan Cox } 720*5c49fd3aSAlan Cox 721*5c49fd3aSAlan Cox /* FIXME: needs Medfield changes */ 722*5c49fd3aSAlan Cox static int psb_register_rw_ioctl(struct drm_device *dev, void *data, 723*5c49fd3aSAlan Cox struct drm_file *file_priv) 724*5c49fd3aSAlan Cox { 725*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = psb_priv(dev); 726*5c49fd3aSAlan Cox struct drm_psb_register_rw_arg *arg = data; 727*5c49fd3aSAlan Cox bool usage = arg->b_force_hw_on ? true : false; 728*5c49fd3aSAlan Cox 729*5c49fd3aSAlan Cox if (arg->display_write_mask != 0) { 730*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 731*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS) 732*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.pfit_controls, 733*5c49fd3aSAlan Cox PFIT_CONTROL); 734*5c49fd3aSAlan Cox if (arg->display_write_mask & 735*5c49fd3aSAlan Cox REGRWBITS_PFIT_AUTOSCALE_RATIOS) 736*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.pfit_autoscale_ratios, 737*5c49fd3aSAlan Cox PFIT_AUTO_RATIOS); 738*5c49fd3aSAlan Cox if (arg->display_write_mask & 739*5c49fd3aSAlan Cox REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS) 740*5c49fd3aSAlan Cox PSB_WVDC32( 741*5c49fd3aSAlan Cox arg->display.pfit_programmed_scale_ratios, 742*5c49fd3aSAlan Cox PFIT_PGM_RATIOS); 743*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PIPEASRC) 744*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.pipeasrc, 745*5c49fd3aSAlan Cox PIPEASRC); 746*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PIPEBSRC) 747*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.pipebsrc, 748*5c49fd3aSAlan Cox PIPEBSRC); 749*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_VTOTAL_A) 750*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.vtotal_a, 751*5c49fd3aSAlan Cox VTOTAL_A); 752*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_VTOTAL_B) 753*5c49fd3aSAlan Cox PSB_WVDC32(arg->display.vtotal_b, 754*5c49fd3aSAlan Cox VTOTAL_B); 755*5c49fd3aSAlan Cox gma_power_end(dev); 756*5c49fd3aSAlan Cox } else { 757*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS) 758*5c49fd3aSAlan Cox dev_priv->savePFIT_CONTROL = 759*5c49fd3aSAlan Cox arg->display.pfit_controls; 760*5c49fd3aSAlan Cox if (arg->display_write_mask & 761*5c49fd3aSAlan Cox REGRWBITS_PFIT_AUTOSCALE_RATIOS) 762*5c49fd3aSAlan Cox dev_priv->savePFIT_AUTO_RATIOS = 763*5c49fd3aSAlan Cox arg->display.pfit_autoscale_ratios; 764*5c49fd3aSAlan Cox if (arg->display_write_mask & 765*5c49fd3aSAlan Cox REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS) 766*5c49fd3aSAlan Cox dev_priv->savePFIT_PGM_RATIOS = 767*5c49fd3aSAlan Cox arg->display.pfit_programmed_scale_ratios; 768*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PIPEASRC) 769*5c49fd3aSAlan Cox dev_priv->savePIPEASRC = arg->display.pipeasrc; 770*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_PIPEBSRC) 771*5c49fd3aSAlan Cox dev_priv->savePIPEBSRC = arg->display.pipebsrc; 772*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_VTOTAL_A) 773*5c49fd3aSAlan Cox dev_priv->saveVTOTAL_A = arg->display.vtotal_a; 774*5c49fd3aSAlan Cox if (arg->display_write_mask & REGRWBITS_VTOTAL_B) 775*5c49fd3aSAlan Cox dev_priv->saveVTOTAL_B = arg->display.vtotal_b; 776*5c49fd3aSAlan Cox } 777*5c49fd3aSAlan Cox } 778*5c49fd3aSAlan Cox 779*5c49fd3aSAlan Cox if (arg->display_read_mask != 0) { 780*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 781*5c49fd3aSAlan Cox if (arg->display_read_mask & 782*5c49fd3aSAlan Cox REGRWBITS_PFIT_CONTROLS) 783*5c49fd3aSAlan Cox arg->display.pfit_controls = 784*5c49fd3aSAlan Cox PSB_RVDC32(PFIT_CONTROL); 785*5c49fd3aSAlan Cox if (arg->display_read_mask & 786*5c49fd3aSAlan Cox REGRWBITS_PFIT_AUTOSCALE_RATIOS) 787*5c49fd3aSAlan Cox arg->display.pfit_autoscale_ratios = 788*5c49fd3aSAlan Cox PSB_RVDC32(PFIT_AUTO_RATIOS); 789*5c49fd3aSAlan Cox if (arg->display_read_mask & 790*5c49fd3aSAlan Cox REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS) 791*5c49fd3aSAlan Cox arg->display.pfit_programmed_scale_ratios = 792*5c49fd3aSAlan Cox PSB_RVDC32(PFIT_PGM_RATIOS); 793*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_PIPEASRC) 794*5c49fd3aSAlan Cox arg->display.pipeasrc = PSB_RVDC32(PIPEASRC); 795*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_PIPEBSRC) 796*5c49fd3aSAlan Cox arg->display.pipebsrc = PSB_RVDC32(PIPEBSRC); 797*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_VTOTAL_A) 798*5c49fd3aSAlan Cox arg->display.vtotal_a = PSB_RVDC32(VTOTAL_A); 799*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_VTOTAL_B) 800*5c49fd3aSAlan Cox arg->display.vtotal_b = PSB_RVDC32(VTOTAL_B); 801*5c49fd3aSAlan Cox gma_power_end(dev); 802*5c49fd3aSAlan Cox } else { 803*5c49fd3aSAlan Cox if (arg->display_read_mask & 804*5c49fd3aSAlan Cox REGRWBITS_PFIT_CONTROLS) 805*5c49fd3aSAlan Cox arg->display.pfit_controls = 806*5c49fd3aSAlan Cox dev_priv->savePFIT_CONTROL; 807*5c49fd3aSAlan Cox if (arg->display_read_mask & 808*5c49fd3aSAlan Cox REGRWBITS_PFIT_AUTOSCALE_RATIOS) 809*5c49fd3aSAlan Cox arg->display.pfit_autoscale_ratios = 810*5c49fd3aSAlan Cox dev_priv->savePFIT_AUTO_RATIOS; 811*5c49fd3aSAlan Cox if (arg->display_read_mask & 812*5c49fd3aSAlan Cox REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS) 813*5c49fd3aSAlan Cox arg->display.pfit_programmed_scale_ratios = 814*5c49fd3aSAlan Cox dev_priv->savePFIT_PGM_RATIOS; 815*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_PIPEASRC) 816*5c49fd3aSAlan Cox arg->display.pipeasrc = dev_priv->savePIPEASRC; 817*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_PIPEBSRC) 818*5c49fd3aSAlan Cox arg->display.pipebsrc = dev_priv->savePIPEBSRC; 819*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_VTOTAL_A) 820*5c49fd3aSAlan Cox arg->display.vtotal_a = dev_priv->saveVTOTAL_A; 821*5c49fd3aSAlan Cox if (arg->display_read_mask & REGRWBITS_VTOTAL_B) 822*5c49fd3aSAlan Cox arg->display.vtotal_b = dev_priv->saveVTOTAL_B; 823*5c49fd3aSAlan Cox } 824*5c49fd3aSAlan Cox } 825*5c49fd3aSAlan Cox 826*5c49fd3aSAlan Cox if (arg->overlay_write_mask != 0) { 827*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 828*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) { 829*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC5, OV_OGAMC5); 830*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC4, OV_OGAMC4); 831*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC3, OV_OGAMC3); 832*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC2, OV_OGAMC2); 833*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC1, OV_OGAMC1); 834*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC0, OV_OGAMC0); 835*5c49fd3aSAlan Cox } 836*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OVC_REGRWBITS_OGAM_ALL) { 837*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC5, OVC_OGAMC5); 838*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC4, OVC_OGAMC4); 839*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC3, OVC_OGAMC3); 840*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC2, OVC_OGAMC2); 841*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC1, OVC_OGAMC1); 842*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OGAMC0, OVC_OGAMC0); 843*5c49fd3aSAlan Cox } 844*5c49fd3aSAlan Cox 845*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OV_REGRWBITS_OVADD) { 846*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OVADD, OV_OVADD); 847*5c49fd3aSAlan Cox 848*5c49fd3aSAlan Cox if (arg->overlay.b_wait_vblank) { 849*5c49fd3aSAlan Cox /* Wait for 20ms.*/ 850*5c49fd3aSAlan Cox unsigned long vblank_timeout = jiffies 851*5c49fd3aSAlan Cox + HZ/50; 852*5c49fd3aSAlan Cox uint32_t temp; 853*5c49fd3aSAlan Cox while (time_before_eq(jiffies, 854*5c49fd3aSAlan Cox vblank_timeout)) { 855*5c49fd3aSAlan Cox temp = PSB_RVDC32(OV_DOVASTA); 856*5c49fd3aSAlan Cox if ((temp & (0x1 << 31)) != 0) 857*5c49fd3aSAlan Cox break; 858*5c49fd3aSAlan Cox cpu_relax(); 859*5c49fd3aSAlan Cox } 860*5c49fd3aSAlan Cox } 861*5c49fd3aSAlan Cox } 862*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OVC_REGRWBITS_OVADD) { 863*5c49fd3aSAlan Cox PSB_WVDC32(arg->overlay.OVADD, OVC_OVADD); 864*5c49fd3aSAlan Cox if (arg->overlay.b_wait_vblank) { 865*5c49fd3aSAlan Cox /* Wait for 20ms.*/ 866*5c49fd3aSAlan Cox unsigned long vblank_timeout = 867*5c49fd3aSAlan Cox jiffies + HZ/50; 868*5c49fd3aSAlan Cox uint32_t temp; 869*5c49fd3aSAlan Cox while (time_before_eq(jiffies, 870*5c49fd3aSAlan Cox vblank_timeout)) { 871*5c49fd3aSAlan Cox temp = PSB_RVDC32(OVC_DOVCSTA); 872*5c49fd3aSAlan Cox if ((temp & (0x1 << 31)) != 0) 873*5c49fd3aSAlan Cox break; 874*5c49fd3aSAlan Cox cpu_relax(); 875*5c49fd3aSAlan Cox } 876*5c49fd3aSAlan Cox } 877*5c49fd3aSAlan Cox } 878*5c49fd3aSAlan Cox gma_power_end(dev); 879*5c49fd3aSAlan Cox } else { 880*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) { 881*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC5 = arg->overlay.OGAMC5; 882*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC4 = arg->overlay.OGAMC4; 883*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC3 = arg->overlay.OGAMC3; 884*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC2 = arg->overlay.OGAMC2; 885*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC1 = arg->overlay.OGAMC1; 886*5c49fd3aSAlan Cox dev_priv->saveOV_OGAMC0 = arg->overlay.OGAMC0; 887*5c49fd3aSAlan Cox } 888*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OVC_REGRWBITS_OGAM_ALL) { 889*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC5 = arg->overlay.OGAMC5; 890*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC4 = arg->overlay.OGAMC4; 891*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC3 = arg->overlay.OGAMC3; 892*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC2 = arg->overlay.OGAMC2; 893*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC1 = arg->overlay.OGAMC1; 894*5c49fd3aSAlan Cox dev_priv->saveOVC_OGAMC0 = arg->overlay.OGAMC0; 895*5c49fd3aSAlan Cox } 896*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OV_REGRWBITS_OVADD) 897*5c49fd3aSAlan Cox dev_priv->saveOV_OVADD = arg->overlay.OVADD; 898*5c49fd3aSAlan Cox if (arg->overlay_write_mask & OVC_REGRWBITS_OVADD) 899*5c49fd3aSAlan Cox dev_priv->saveOVC_OVADD = arg->overlay.OVADD; 900*5c49fd3aSAlan Cox } 901*5c49fd3aSAlan Cox } 902*5c49fd3aSAlan Cox 903*5c49fd3aSAlan Cox if (arg->overlay_read_mask != 0) { 904*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 905*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) { 906*5c49fd3aSAlan Cox arg->overlay.OGAMC5 = PSB_RVDC32(OV_OGAMC5); 907*5c49fd3aSAlan Cox arg->overlay.OGAMC4 = PSB_RVDC32(OV_OGAMC4); 908*5c49fd3aSAlan Cox arg->overlay.OGAMC3 = PSB_RVDC32(OV_OGAMC3); 909*5c49fd3aSAlan Cox arg->overlay.OGAMC2 = PSB_RVDC32(OV_OGAMC2); 910*5c49fd3aSAlan Cox arg->overlay.OGAMC1 = PSB_RVDC32(OV_OGAMC1); 911*5c49fd3aSAlan Cox arg->overlay.OGAMC0 = PSB_RVDC32(OV_OGAMC0); 912*5c49fd3aSAlan Cox } 913*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OVC_REGRWBITS_OGAM_ALL) { 914*5c49fd3aSAlan Cox arg->overlay.OGAMC5 = PSB_RVDC32(OVC_OGAMC5); 915*5c49fd3aSAlan Cox arg->overlay.OGAMC4 = PSB_RVDC32(OVC_OGAMC4); 916*5c49fd3aSAlan Cox arg->overlay.OGAMC3 = PSB_RVDC32(OVC_OGAMC3); 917*5c49fd3aSAlan Cox arg->overlay.OGAMC2 = PSB_RVDC32(OVC_OGAMC2); 918*5c49fd3aSAlan Cox arg->overlay.OGAMC1 = PSB_RVDC32(OVC_OGAMC1); 919*5c49fd3aSAlan Cox arg->overlay.OGAMC0 = PSB_RVDC32(OVC_OGAMC0); 920*5c49fd3aSAlan Cox } 921*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OV_REGRWBITS_OVADD) 922*5c49fd3aSAlan Cox arg->overlay.OVADD = PSB_RVDC32(OV_OVADD); 923*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OVC_REGRWBITS_OVADD) 924*5c49fd3aSAlan Cox arg->overlay.OVADD = PSB_RVDC32(OVC_OVADD); 925*5c49fd3aSAlan Cox gma_power_end(dev); 926*5c49fd3aSAlan Cox } else { 927*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) { 928*5c49fd3aSAlan Cox arg->overlay.OGAMC5 = dev_priv->saveOV_OGAMC5; 929*5c49fd3aSAlan Cox arg->overlay.OGAMC4 = dev_priv->saveOV_OGAMC4; 930*5c49fd3aSAlan Cox arg->overlay.OGAMC3 = dev_priv->saveOV_OGAMC3; 931*5c49fd3aSAlan Cox arg->overlay.OGAMC2 = dev_priv->saveOV_OGAMC2; 932*5c49fd3aSAlan Cox arg->overlay.OGAMC1 = dev_priv->saveOV_OGAMC1; 933*5c49fd3aSAlan Cox arg->overlay.OGAMC0 = dev_priv->saveOV_OGAMC0; 934*5c49fd3aSAlan Cox } 935*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OVC_REGRWBITS_OGAM_ALL) { 936*5c49fd3aSAlan Cox arg->overlay.OGAMC5 = dev_priv->saveOVC_OGAMC5; 937*5c49fd3aSAlan Cox arg->overlay.OGAMC4 = dev_priv->saveOVC_OGAMC4; 938*5c49fd3aSAlan Cox arg->overlay.OGAMC3 = dev_priv->saveOVC_OGAMC3; 939*5c49fd3aSAlan Cox arg->overlay.OGAMC2 = dev_priv->saveOVC_OGAMC2; 940*5c49fd3aSAlan Cox arg->overlay.OGAMC1 = dev_priv->saveOVC_OGAMC1; 941*5c49fd3aSAlan Cox arg->overlay.OGAMC0 = dev_priv->saveOVC_OGAMC0; 942*5c49fd3aSAlan Cox } 943*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OV_REGRWBITS_OVADD) 944*5c49fd3aSAlan Cox arg->overlay.OVADD = dev_priv->saveOV_OVADD; 945*5c49fd3aSAlan Cox if (arg->overlay_read_mask & OVC_REGRWBITS_OVADD) 946*5c49fd3aSAlan Cox arg->overlay.OVADD = dev_priv->saveOVC_OVADD; 947*5c49fd3aSAlan Cox } 948*5c49fd3aSAlan Cox } 949*5c49fd3aSAlan Cox 950*5c49fd3aSAlan Cox if (arg->sprite_enable_mask != 0) { 951*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 952*5c49fd3aSAlan Cox PSB_WVDC32(0x1F3E, DSPARB); 953*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspa_control 954*5c49fd3aSAlan Cox | PSB_RVDC32(DSPACNTR), DSPACNTR); 955*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspa_key_value, DSPAKEYVAL); 956*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspa_key_mask, DSPAKEYMASK); 957*5c49fd3aSAlan Cox PSB_WVDC32(PSB_RVDC32(DSPASURF), DSPASURF); 958*5c49fd3aSAlan Cox PSB_RVDC32(DSPASURF); 959*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_control, DSPCCNTR); 960*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_stride, DSPCSTRIDE); 961*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_position, DSPCPOS); 962*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_linear_offset, DSPCLINOFF); 963*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_size, DSPCSIZE); 964*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF); 965*5c49fd3aSAlan Cox PSB_RVDC32(DSPCSURF); 966*5c49fd3aSAlan Cox gma_power_end(dev); 967*5c49fd3aSAlan Cox } 968*5c49fd3aSAlan Cox } 969*5c49fd3aSAlan Cox 970*5c49fd3aSAlan Cox if (arg->sprite_disable_mask != 0) { 971*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 972*5c49fd3aSAlan Cox PSB_WVDC32(0x3F3E, DSPARB); 973*5c49fd3aSAlan Cox PSB_WVDC32(0x0, DSPCCNTR); 974*5c49fd3aSAlan Cox PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF); 975*5c49fd3aSAlan Cox PSB_RVDC32(DSPCSURF); 976*5c49fd3aSAlan Cox gma_power_end(dev); 977*5c49fd3aSAlan Cox } 978*5c49fd3aSAlan Cox } 979*5c49fd3aSAlan Cox 980*5c49fd3aSAlan Cox if (arg->subpicture_enable_mask != 0) { 981*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 982*5c49fd3aSAlan Cox uint32_t temp; 983*5c49fd3aSAlan Cox if (arg->subpicture_enable_mask & REGRWBITS_DSPACNTR) { 984*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPACNTR); 985*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 986*5c49fd3aSAlan Cox temp &= ~DISPPLANE_BOTTOM; 987*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP; 988*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPACNTR); 989*5c49fd3aSAlan Cox 990*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPABASE); 991*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPABASE); 992*5c49fd3aSAlan Cox PSB_RVDC32(DSPABASE); 993*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPASURF); 994*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPASURF); 995*5c49fd3aSAlan Cox PSB_RVDC32(DSPASURF); 996*5c49fd3aSAlan Cox } 997*5c49fd3aSAlan Cox if (arg->subpicture_enable_mask & REGRWBITS_DSPBCNTR) { 998*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBCNTR); 999*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 1000*5c49fd3aSAlan Cox temp &= ~DISPPLANE_BOTTOM; 1001*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP; 1002*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBCNTR); 1003*5c49fd3aSAlan Cox 1004*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBBASE); 1005*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBBASE); 1006*5c49fd3aSAlan Cox PSB_RVDC32(DSPBBASE); 1007*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBSURF); 1008*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBSURF); 1009*5c49fd3aSAlan Cox PSB_RVDC32(DSPBSURF); 1010*5c49fd3aSAlan Cox } 1011*5c49fd3aSAlan Cox if (arg->subpicture_enable_mask & REGRWBITS_DSPCCNTR) { 1012*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCCNTR); 1013*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 1014*5c49fd3aSAlan Cox temp &= ~DISPPLANE_BOTTOM; 1015*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP; 1016*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCCNTR); 1017*5c49fd3aSAlan Cox 1018*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCBASE); 1019*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCBASE); 1020*5c49fd3aSAlan Cox PSB_RVDC32(DSPCBASE); 1021*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCSURF); 1022*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCSURF); 1023*5c49fd3aSAlan Cox PSB_RVDC32(DSPCSURF); 1024*5c49fd3aSAlan Cox } 1025*5c49fd3aSAlan Cox gma_power_end(dev); 1026*5c49fd3aSAlan Cox } 1027*5c49fd3aSAlan Cox } 1028*5c49fd3aSAlan Cox 1029*5c49fd3aSAlan Cox if (arg->subpicture_disable_mask != 0) { 1030*5c49fd3aSAlan Cox if (gma_power_begin(dev, usage)) { 1031*5c49fd3aSAlan Cox uint32_t temp; 1032*5c49fd3aSAlan Cox if (arg->subpicture_disable_mask & REGRWBITS_DSPACNTR) { 1033*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPACNTR); 1034*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 1035*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP_NO_ALPHA; 1036*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPACNTR); 1037*5c49fd3aSAlan Cox 1038*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPABASE); 1039*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPABASE); 1040*5c49fd3aSAlan Cox PSB_RVDC32(DSPABASE); 1041*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPASURF); 1042*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPASURF); 1043*5c49fd3aSAlan Cox PSB_RVDC32(DSPASURF); 1044*5c49fd3aSAlan Cox } 1045*5c49fd3aSAlan Cox if (arg->subpicture_disable_mask & REGRWBITS_DSPBCNTR) { 1046*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBCNTR); 1047*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 1048*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP_NO_ALPHA; 1049*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBCNTR); 1050*5c49fd3aSAlan Cox 1051*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBBASE); 1052*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBBASE); 1053*5c49fd3aSAlan Cox PSB_RVDC32(DSPBBASE); 1054*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPBSURF); 1055*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPBSURF); 1056*5c49fd3aSAlan Cox PSB_RVDC32(DSPBSURF); 1057*5c49fd3aSAlan Cox } 1058*5c49fd3aSAlan Cox if (arg->subpicture_disable_mask & REGRWBITS_DSPCCNTR) { 1059*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCCNTR); 1060*5c49fd3aSAlan Cox temp &= ~DISPPLANE_PIXFORMAT_MASK; 1061*5c49fd3aSAlan Cox temp |= DISPPLANE_32BPP_NO_ALPHA; 1062*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCCNTR); 1063*5c49fd3aSAlan Cox 1064*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCBASE); 1065*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCBASE); 1066*5c49fd3aSAlan Cox PSB_RVDC32(DSPCBASE); 1067*5c49fd3aSAlan Cox temp = PSB_RVDC32(DSPCSURF); 1068*5c49fd3aSAlan Cox PSB_WVDC32(temp, DSPCSURF); 1069*5c49fd3aSAlan Cox PSB_RVDC32(DSPCSURF); 1070*5c49fd3aSAlan Cox } 1071*5c49fd3aSAlan Cox gma_power_end(dev); 1072*5c49fd3aSAlan Cox } 1073*5c49fd3aSAlan Cox } 1074*5c49fd3aSAlan Cox 1075*5c49fd3aSAlan Cox return 0; 1076*5c49fd3aSAlan Cox } 1077*5c49fd3aSAlan Cox 1078*5c49fd3aSAlan Cox static int psb_driver_open(struct drm_device *dev, struct drm_file *priv) 1079*5c49fd3aSAlan Cox { 1080*5c49fd3aSAlan Cox return 0; 1081*5c49fd3aSAlan Cox } 1082*5c49fd3aSAlan Cox 1083*5c49fd3aSAlan Cox static void psb_driver_close(struct drm_device *dev, struct drm_file *priv) 1084*5c49fd3aSAlan Cox { 1085*5c49fd3aSAlan Cox } 1086*5c49fd3aSAlan Cox 1087*5c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, 1088*5c49fd3aSAlan Cox unsigned long arg) 1089*5c49fd3aSAlan Cox { 1090*5c49fd3aSAlan Cox struct drm_file *file_priv = filp->private_data; 1091*5c49fd3aSAlan Cox struct drm_device *dev = file_priv->minor->dev; 1092*5c49fd3aSAlan Cox struct drm_psb_private *dev_priv = dev->dev_private; 1093*5c49fd3aSAlan Cox static unsigned int runtime_allowed; 1094*5c49fd3aSAlan Cox 1095*5c49fd3aSAlan Cox if (runtime_allowed == 1 && dev_priv->is_lvds_on) { 1096*5c49fd3aSAlan Cox runtime_allowed++; 1097*5c49fd3aSAlan Cox pm_runtime_allow(&dev->pdev->dev); 1098*5c49fd3aSAlan Cox dev_priv->rpm_enabled = 1; 1099*5c49fd3aSAlan Cox } 1100*5c49fd3aSAlan Cox return drm_ioctl(filp, cmd, arg); 1101*5c49fd3aSAlan Cox /* FIXME: do we need to wrap the other side of this */ 1102*5c49fd3aSAlan Cox } 1103*5c49fd3aSAlan Cox 1104*5c49fd3aSAlan Cox 1105*5c49fd3aSAlan Cox /* When a client dies: 1106*5c49fd3aSAlan Cox * - Check for and clean up flipped page state 1107*5c49fd3aSAlan Cox */ 1108*5c49fd3aSAlan Cox void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv) 1109*5c49fd3aSAlan Cox { 1110*5c49fd3aSAlan Cox } 1111*5c49fd3aSAlan Cox 1112*5c49fd3aSAlan Cox static void psb_remove(struct pci_dev *pdev) 1113*5c49fd3aSAlan Cox { 1114*5c49fd3aSAlan Cox struct drm_device *dev = pci_get_drvdata(pdev); 1115*5c49fd3aSAlan Cox drm_put_dev(dev); 1116*5c49fd3aSAlan Cox } 1117*5c49fd3aSAlan Cox 1118*5c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = { 1119*5c49fd3aSAlan Cox .resume = gma_power_resume, 1120*5c49fd3aSAlan Cox .suspend = gma_power_suspend, 1121*5c49fd3aSAlan Cox .runtime_suspend = psb_runtime_suspend, 1122*5c49fd3aSAlan Cox .runtime_resume = psb_runtime_resume, 1123*5c49fd3aSAlan Cox .runtime_idle = psb_runtime_idle, 1124*5c49fd3aSAlan Cox }; 1125*5c49fd3aSAlan Cox 1126*5c49fd3aSAlan Cox static struct vm_operations_struct psb_gem_vm_ops = { 1127*5c49fd3aSAlan Cox .fault = psb_gem_fault, 1128*5c49fd3aSAlan Cox .open = drm_gem_vm_open, 1129*5c49fd3aSAlan Cox .close = drm_gem_vm_close, 1130*5c49fd3aSAlan Cox }; 1131*5c49fd3aSAlan Cox 1132*5c49fd3aSAlan Cox static struct drm_driver driver = { 1133*5c49fd3aSAlan Cox .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ 1134*5c49fd3aSAlan Cox DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM , 1135*5c49fd3aSAlan Cox .load = psb_driver_load, 1136*5c49fd3aSAlan Cox .unload = psb_driver_unload, 1137*5c49fd3aSAlan Cox 1138*5c49fd3aSAlan Cox .ioctls = psb_ioctls, 1139*5c49fd3aSAlan Cox .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls), 1140*5c49fd3aSAlan Cox .device_is_agp = psb_driver_device_is_agp, 1141*5c49fd3aSAlan Cox .irq_preinstall = psb_irq_preinstall, 1142*5c49fd3aSAlan Cox .irq_postinstall = psb_irq_postinstall, 1143*5c49fd3aSAlan Cox .irq_uninstall = psb_irq_uninstall, 1144*5c49fd3aSAlan Cox .irq_handler = psb_irq_handler, 1145*5c49fd3aSAlan Cox .enable_vblank = psb_enable_vblank, 1146*5c49fd3aSAlan Cox .disable_vblank = psb_disable_vblank, 1147*5c49fd3aSAlan Cox .get_vblank_counter = psb_get_vblank_counter, 1148*5c49fd3aSAlan Cox .lastclose = psb_lastclose, 1149*5c49fd3aSAlan Cox .open = psb_driver_open, 1150*5c49fd3aSAlan Cox .preclose = psb_driver_preclose, 1151*5c49fd3aSAlan Cox .postclose = psb_driver_close, 1152*5c49fd3aSAlan Cox .reclaim_buffers = drm_core_reclaim_buffers, 1153*5c49fd3aSAlan Cox 1154*5c49fd3aSAlan Cox .gem_init_object = psb_gem_init_object, 1155*5c49fd3aSAlan Cox .gem_free_object = psb_gem_free_object, 1156*5c49fd3aSAlan Cox .gem_vm_ops = &psb_gem_vm_ops, 1157*5c49fd3aSAlan Cox .dumb_create = psb_gem_dumb_create, 1158*5c49fd3aSAlan Cox .dumb_map_offset = psb_gem_dumb_map_gtt, 1159*5c49fd3aSAlan Cox .dumb_destroy = psb_gem_dumb_destroy, 1160*5c49fd3aSAlan Cox 1161*5c49fd3aSAlan Cox .fops = { 1162*5c49fd3aSAlan Cox .owner = THIS_MODULE, 1163*5c49fd3aSAlan Cox .open = drm_open, 1164*5c49fd3aSAlan Cox .release = drm_release, 1165*5c49fd3aSAlan Cox .unlocked_ioctl = psb_unlocked_ioctl, 1166*5c49fd3aSAlan Cox .mmap = drm_gem_mmap, 1167*5c49fd3aSAlan Cox .poll = drm_poll, 1168*5c49fd3aSAlan Cox .fasync = drm_fasync, 1169*5c49fd3aSAlan Cox .read = drm_read, 1170*5c49fd3aSAlan Cox }, 1171*5c49fd3aSAlan Cox .name = DRIVER_NAME, 1172*5c49fd3aSAlan Cox .desc = DRIVER_DESC, 1173*5c49fd3aSAlan Cox .date = PSB_DRM_DRIVER_DATE, 1174*5c49fd3aSAlan Cox .major = PSB_DRM_DRIVER_MAJOR, 1175*5c49fd3aSAlan Cox .minor = PSB_DRM_DRIVER_MINOR, 1176*5c49fd3aSAlan Cox .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL 1177*5c49fd3aSAlan Cox }; 1178*5c49fd3aSAlan Cox 1179*5c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = { 1180*5c49fd3aSAlan Cox .name = DRIVER_NAME, 1181*5c49fd3aSAlan Cox .id_table = pciidlist, 1182*5c49fd3aSAlan Cox .probe = psb_probe, 1183*5c49fd3aSAlan Cox .remove = psb_remove, 1184*5c49fd3aSAlan Cox .driver.pm = &psb_pm_ops, 1185*5c49fd3aSAlan Cox }; 1186*5c49fd3aSAlan Cox 1187*5c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1188*5c49fd3aSAlan Cox { 1189*5c49fd3aSAlan Cox /* MLD Added this from Inaky's patch */ 1190*5c49fd3aSAlan Cox if (pci_enable_msi(pdev)) 1191*5c49fd3aSAlan Cox dev_warn(&pdev->dev, "Enable MSI failed!\n"); 1192*5c49fd3aSAlan Cox return drm_get_pci_dev(pdev, ent, &driver); 1193*5c49fd3aSAlan Cox } 1194*5c49fd3aSAlan Cox 1195*5c49fd3aSAlan Cox static int __init psb_init(void) 1196*5c49fd3aSAlan Cox { 1197*5c49fd3aSAlan Cox return drm_pci_init(&driver, &psb_pci_driver); 1198*5c49fd3aSAlan Cox } 1199*5c49fd3aSAlan Cox 1200*5c49fd3aSAlan Cox static void __exit psb_exit(void) 1201*5c49fd3aSAlan Cox { 1202*5c49fd3aSAlan Cox drm_pci_exit(&driver, &psb_pci_driver); 1203*5c49fd3aSAlan Cox } 1204*5c49fd3aSAlan Cox 1205*5c49fd3aSAlan Cox late_initcall(psb_init); 1206*5c49fd3aSAlan Cox module_exit(psb_exit); 1207*5c49fd3aSAlan Cox 1208*5c49fd3aSAlan Cox MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others"); 1209*5c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC); 1210*5c49fd3aSAlan Cox MODULE_LICENSE("GPL"); 1211