xref: /openbmc/linux/drivers/gpu/drm/gma500/psb_drv.c (revision af3a2cfbd132a0556f0e5e457817337047ebcb4c)
15c49fd3aSAlan Cox /**************************************************************************
25c49fd3aSAlan Cox  * Copyright (c) 2007-2011, Intel Corporation.
35c49fd3aSAlan Cox  * All Rights Reserved.
45c49fd3aSAlan Cox  * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA.
55c49fd3aSAlan Cox  * All Rights Reserved.
65c49fd3aSAlan Cox  *
75c49fd3aSAlan Cox  * This program is free software; you can redistribute it and/or modify it
85c49fd3aSAlan Cox  * under the terms and conditions of the GNU General Public License,
95c49fd3aSAlan Cox  * version 2, as published by the Free Software Foundation.
105c49fd3aSAlan Cox  *
115c49fd3aSAlan Cox  * This program is distributed in the hope it will be useful, but WITHOUT
125c49fd3aSAlan Cox  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135c49fd3aSAlan Cox  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
145c49fd3aSAlan Cox  * more details.
155c49fd3aSAlan Cox  *
165c49fd3aSAlan Cox  * You should have received a copy of the GNU General Public License along with
175c49fd3aSAlan Cox  * this program; if not, write to the Free Software Foundation, Inc.,
185c49fd3aSAlan Cox  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
195c49fd3aSAlan Cox  *
205c49fd3aSAlan Cox  **************************************************************************/
215c49fd3aSAlan Cox 
225c49fd3aSAlan Cox #include <drm/drmP.h>
235c49fd3aSAlan Cox #include <drm/drm.h>
245c49fd3aSAlan Cox #include "psb_drm.h"
255c49fd3aSAlan Cox #include "psb_drv.h"
265c49fd3aSAlan Cox #include "framebuffer.h"
275c49fd3aSAlan Cox #include "psb_reg.h"
285c49fd3aSAlan Cox #include "psb_intel_reg.h"
295c49fd3aSAlan Cox #include "intel_bios.h"
305c49fd3aSAlan Cox #include "mid_bios.h"
315c49fd3aSAlan Cox #include <drm/drm_pciids.h>
325c49fd3aSAlan Cox #include "power.h"
335c49fd3aSAlan Cox #include <linux/cpu.h>
345c49fd3aSAlan Cox #include <linux/notifier.h>
355c49fd3aSAlan Cox #include <linux/spinlock.h>
365c49fd3aSAlan Cox #include <linux/pm_runtime.h>
375c49fd3aSAlan Cox #include <acpi/video.h>
38*af3a2cfbSDave Airlie #include <linux/module.h>
395c49fd3aSAlan Cox 
405c49fd3aSAlan Cox static int drm_psb_trap_pagefaults;
415c49fd3aSAlan Cox 
425c49fd3aSAlan Cox int drm_psb_no_fb;
435c49fd3aSAlan Cox 
445c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
455c49fd3aSAlan Cox 
465c49fd3aSAlan Cox MODULE_PARM_DESC(no_fb, "Disable FBdev");
475c49fd3aSAlan Cox MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults");
485c49fd3aSAlan Cox module_param_named(no_fb, drm_psb_no_fb, int, 0600);
495c49fd3aSAlan Cox module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600);
505c49fd3aSAlan Cox 
515c49fd3aSAlan Cox 
525c49fd3aSAlan Cox static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
535c49fd3aSAlan Cox 	{ 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
545c49fd3aSAlan Cox 	{ 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
555c49fd3aSAlan Cox #if defined(CONFIG_DRM_OAKTRAIL)
565c49fd3aSAlan Cox 	{ 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
575c49fd3aSAlan Cox 	{ 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
585c49fd3aSAlan Cox 	{ 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
595c49fd3aSAlan Cox 	{ 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
605c49fd3aSAlan Cox 	{ 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
615c49fd3aSAlan Cox 	{ 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
625c49fd3aSAlan Cox 	{ 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
635c49fd3aSAlan Cox 	{ 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
645c49fd3aSAlan Cox #endif
655c49fd3aSAlan Cox #if defined(CONFIG_DRM_CDV)
665c49fd3aSAlan Cox 	{ 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
675c49fd3aSAlan Cox 	{ 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
685c49fd3aSAlan Cox 	{ 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
695c49fd3aSAlan Cox 	{ 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
705c49fd3aSAlan Cox 	{ 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
715c49fd3aSAlan Cox 	{ 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
725c49fd3aSAlan Cox 	{ 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
735c49fd3aSAlan Cox 	{ 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
745c49fd3aSAlan Cox #endif
755c49fd3aSAlan Cox 	{ 0, 0, 0}
765c49fd3aSAlan Cox };
775c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist);
785c49fd3aSAlan Cox 
795c49fd3aSAlan Cox /*
805c49fd3aSAlan Cox  * Standard IOCTLs.
815c49fd3aSAlan Cox  */
825c49fd3aSAlan Cox 
835c49fd3aSAlan Cox #define DRM_IOCTL_PSB_SIZES	\
845c49fd3aSAlan Cox 		DRM_IOR(DRM_PSB_SIZES + DRM_COMMAND_BASE, \
855c49fd3aSAlan Cox 			struct drm_psb_sizes_arg)
865c49fd3aSAlan Cox #define DRM_IOCTL_PSB_FUSE_REG	\
875c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_FUSE_REG + DRM_COMMAND_BASE, uint32_t)
885c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DC_STATE	\
895c49fd3aSAlan Cox 		DRM_IOW(DRM_PSB_DC_STATE + DRM_COMMAND_BASE, \
905c49fd3aSAlan Cox 			struct drm_psb_dc_state_arg)
915c49fd3aSAlan Cox #define DRM_IOCTL_PSB_ADB	\
925c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_ADB + DRM_COMMAND_BASE, uint32_t)
935c49fd3aSAlan Cox #define DRM_IOCTL_PSB_MODE_OPERATION	\
945c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_MODE_OPERATION + DRM_COMMAND_BASE, \
955c49fd3aSAlan Cox 			 struct drm_psb_mode_operation_arg)
965c49fd3aSAlan Cox #define DRM_IOCTL_PSB_STOLEN_MEMORY	\
975c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_STOLEN_MEMORY + DRM_COMMAND_BASE, \
985c49fd3aSAlan Cox 			 struct drm_psb_stolen_memory_arg)
995c49fd3aSAlan Cox #define DRM_IOCTL_PSB_REGISTER_RW	\
1005c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_REGISTER_RW + DRM_COMMAND_BASE, \
1015c49fd3aSAlan Cox 			 struct drm_psb_register_rw_arg)
1025c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DPST	\
1035c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_DPST + DRM_COMMAND_BASE, \
1045c49fd3aSAlan Cox 			 uint32_t)
1055c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GAMMA	\
1065c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_GAMMA + DRM_COMMAND_BASE, \
1075c49fd3aSAlan Cox 			 struct drm_psb_dpst_lut_arg)
1085c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DPST_BL	\
1095c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_DPST_BL + DRM_COMMAND_BASE, \
1105c49fd3aSAlan Cox 			 uint32_t)
1115c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID	\
1125c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
1135c49fd3aSAlan Cox 			 struct drm_psb_get_pipe_from_crtc_id_arg)
1145c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_CREATE	\
1155c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_GEM_CREATE + DRM_COMMAND_BASE, \
1165c49fd3aSAlan Cox 			 struct drm_psb_gem_create)
1175c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_MMAP	\
1185c49fd3aSAlan Cox 		DRM_IOWR(DRM_PSB_GEM_MMAP + DRM_COMMAND_BASE, \
1195c49fd3aSAlan Cox 			 struct drm_psb_gem_mmap)
1205c49fd3aSAlan Cox 
1215c49fd3aSAlan Cox static int psb_sizes_ioctl(struct drm_device *dev, void *data,
1225c49fd3aSAlan Cox 			   struct drm_file *file_priv);
1235c49fd3aSAlan Cox static int psb_dc_state_ioctl(struct drm_device *dev, void * data,
1245c49fd3aSAlan Cox 			      struct drm_file *file_priv);
1255c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data,
1265c49fd3aSAlan Cox 			 struct drm_file *file_priv);
1275c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
1285c49fd3aSAlan Cox 				    struct drm_file *file_priv);
1295c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
1305c49fd3aSAlan Cox 				   struct drm_file *file_priv);
1315c49fd3aSAlan Cox static int psb_register_rw_ioctl(struct drm_device *dev, void *data,
1325c49fd3aSAlan Cox 				 struct drm_file *file_priv);
1335c49fd3aSAlan Cox static int psb_dpst_ioctl(struct drm_device *dev, void *data,
1345c49fd3aSAlan Cox 			  struct drm_file *file_priv);
1355c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data,
1365c49fd3aSAlan Cox 			   struct drm_file *file_priv);
1375c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
1385c49fd3aSAlan Cox 			     struct drm_file *file_priv);
1395c49fd3aSAlan Cox 
1405c49fd3aSAlan Cox #define PSB_IOCTL_DEF(ioctl, func, flags) \
1415c49fd3aSAlan Cox 	[DRM_IOCTL_NR(ioctl) - DRM_COMMAND_BASE] = {ioctl, flags, func}
1425c49fd3aSAlan Cox 
1435c49fd3aSAlan Cox static struct drm_ioctl_desc psb_ioctls[] = {
1445c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_SIZES, psb_sizes_ioctl, DRM_AUTH),
1455c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_DC_STATE, psb_dc_state_ioctl, DRM_AUTH),
1465c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_ADB, psb_adb_ioctl, DRM_AUTH),
1475c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_MODE_OPERATION, psb_mode_operation_ioctl,
1485c49fd3aSAlan Cox 		      DRM_AUTH),
1495c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_STOLEN_MEMORY, psb_stolen_memory_ioctl,
1505c49fd3aSAlan Cox 		      DRM_AUTH),
1515c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_REGISTER_RW, psb_register_rw_ioctl,
1525c49fd3aSAlan Cox 		      DRM_AUTH),
1535c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST, psb_dpst_ioctl, DRM_AUTH),
1545c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA, psb_gamma_ioctl, DRM_AUTH),
1555c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
1565c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID,
1575c49fd3aSAlan Cox 					psb_intel_get_pipe_from_crtc_id, 0),
1585c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_CREATE, psb_gem_create_ioctl,
1595c49fd3aSAlan Cox 						DRM_UNLOCKED | DRM_AUTH),
1605c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_MMAP, psb_gem_mmap_ioctl,
1615c49fd3aSAlan Cox 						DRM_UNLOCKED | DRM_AUTH),
1625c49fd3aSAlan Cox };
1635c49fd3aSAlan Cox 
1645c49fd3aSAlan Cox static void psb_lastclose(struct drm_device *dev)
1655c49fd3aSAlan Cox {
1665c49fd3aSAlan Cox 	return;
1675c49fd3aSAlan Cox }
1685c49fd3aSAlan Cox 
1695c49fd3aSAlan Cox static void psb_do_takedown(struct drm_device *dev)
1705c49fd3aSAlan Cox {
1715c49fd3aSAlan Cox 	/* FIXME: do we need to clean up the gtt here ? */
1725c49fd3aSAlan Cox }
1735c49fd3aSAlan Cox 
1745c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev)
1755c49fd3aSAlan Cox {
1765c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
1775c49fd3aSAlan Cox 	struct psb_gtt *pg = &dev_priv->gtt;
1785c49fd3aSAlan Cox 
1795c49fd3aSAlan Cox 	uint32_t stolen_gtt;
1805c49fd3aSAlan Cox 
1815c49fd3aSAlan Cox 	int ret = -ENOMEM;
1825c49fd3aSAlan Cox 
1835c49fd3aSAlan Cox 	if (pg->mmu_gatt_start & 0x0FFFFFFF) {
1845c49fd3aSAlan Cox 		dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
1855c49fd3aSAlan Cox 		ret = -EINVAL;
1865c49fd3aSAlan Cox 		goto out_err;
1875c49fd3aSAlan Cox 	}
1885c49fd3aSAlan Cox 
1895c49fd3aSAlan Cox 
1905c49fd3aSAlan Cox 	stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
1915c49fd3aSAlan Cox 	stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
1925c49fd3aSAlan Cox 	stolen_gtt =
1935c49fd3aSAlan Cox 	    (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
1945c49fd3aSAlan Cox 
1955c49fd3aSAlan Cox 	dev_priv->gatt_free_offset = pg->mmu_gatt_start +
1965c49fd3aSAlan Cox 	    (stolen_gtt << PAGE_SHIFT) * 1024;
1975c49fd3aSAlan Cox 
1985c49fd3aSAlan Cox 	if (1 || drm_debug) {
1995c49fd3aSAlan Cox 		uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID);
2005c49fd3aSAlan Cox 		uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION);
2015c49fd3aSAlan Cox 		DRM_INFO("SGX core id = 0x%08x\n", core_id);
2025c49fd3aSAlan Cox 		DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n",
2035c49fd3aSAlan Cox 			 (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >>
2045c49fd3aSAlan Cox 			 _PSB_CC_REVISION_MAJOR_SHIFT,
2055c49fd3aSAlan Cox 			 (core_rev & _PSB_CC_REVISION_MINOR_MASK) >>
2065c49fd3aSAlan Cox 			 _PSB_CC_REVISION_MINOR_SHIFT);
2075c49fd3aSAlan Cox 		DRM_INFO
2085c49fd3aSAlan Cox 		    ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n",
2095c49fd3aSAlan Cox 		     (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >>
2105c49fd3aSAlan Cox 		     _PSB_CC_REVISION_MAINTENANCE_SHIFT,
2115c49fd3aSAlan Cox 		     (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >>
2125c49fd3aSAlan Cox 		     _PSB_CC_REVISION_DESIGNER_SHIFT);
2135c49fd3aSAlan Cox 	}
2145c49fd3aSAlan Cox 
2155c49fd3aSAlan Cox 
2165c49fd3aSAlan Cox 	spin_lock_init(&dev_priv->irqmask_lock);
2175c49fd3aSAlan Cox 	mutex_init(&dev_priv->mutex_2d);
2185c49fd3aSAlan Cox 
2195c49fd3aSAlan Cox 	PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
2205c49fd3aSAlan Cox 	PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
2215c49fd3aSAlan Cox 	PSB_RSGX32(PSB_CR_BIF_BANK1);
2225c49fd3aSAlan Cox 	PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
2235c49fd3aSAlan Cox 							PSB_CR_BIF_CTRL);
2245c49fd3aSAlan Cox 	psb_spank(dev_priv);
2255c49fd3aSAlan Cox 
2265c49fd3aSAlan Cox 	/* mmu_gatt ?? */
2275c49fd3aSAlan Cox 	PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
2285c49fd3aSAlan Cox 	return 0;
2295c49fd3aSAlan Cox out_err:
2305c49fd3aSAlan Cox 	psb_do_takedown(dev);
2315c49fd3aSAlan Cox 	return ret;
2325c49fd3aSAlan Cox }
2335c49fd3aSAlan Cox 
2345c49fd3aSAlan Cox static int psb_driver_unload(struct drm_device *dev)
2355c49fd3aSAlan Cox {
2365c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
2375c49fd3aSAlan Cox 
2385c49fd3aSAlan Cox 	/* Kill vblank etc here */
2395c49fd3aSAlan Cox 
2405c49fd3aSAlan Cox 	gma_backlight_exit(dev);
2415c49fd3aSAlan Cox 
2425c49fd3aSAlan Cox 	if (drm_psb_no_fb == 0)
2435c49fd3aSAlan Cox 		psb_modeset_cleanup(dev);
2445c49fd3aSAlan Cox 
2455c49fd3aSAlan Cox 	if (dev_priv) {
2465c49fd3aSAlan Cox 		psb_lid_timer_takedown(dev_priv);
2475c49fd3aSAlan Cox 		gma_intel_opregion_exit(dev);
2485c49fd3aSAlan Cox 
2495c49fd3aSAlan Cox 		if (dev_priv->ops->chip_teardown)
2505c49fd3aSAlan Cox 			dev_priv->ops->chip_teardown(dev);
2515c49fd3aSAlan Cox 		psb_do_takedown(dev);
2525c49fd3aSAlan Cox 
2535c49fd3aSAlan Cox 
2545c49fd3aSAlan Cox 		if (dev_priv->pf_pd) {
2555c49fd3aSAlan Cox 			psb_mmu_free_pagedir(dev_priv->pf_pd);
2565c49fd3aSAlan Cox 			dev_priv->pf_pd = NULL;
2575c49fd3aSAlan Cox 		}
2585c49fd3aSAlan Cox 		if (dev_priv->mmu) {
2595c49fd3aSAlan Cox 			struct psb_gtt *pg = &dev_priv->gtt;
2605c49fd3aSAlan Cox 
2615c49fd3aSAlan Cox 			down_read(&pg->sem);
2625c49fd3aSAlan Cox 			psb_mmu_remove_pfn_sequence(
2635c49fd3aSAlan Cox 				psb_mmu_get_default_pd
2645c49fd3aSAlan Cox 				(dev_priv->mmu),
2655c49fd3aSAlan Cox 				pg->mmu_gatt_start,
2665c49fd3aSAlan Cox 				dev_priv->vram_stolen_size >> PAGE_SHIFT);
2675c49fd3aSAlan Cox 			up_read(&pg->sem);
2685c49fd3aSAlan Cox 			psb_mmu_driver_takedown(dev_priv->mmu);
2695c49fd3aSAlan Cox 			dev_priv->mmu = NULL;
2705c49fd3aSAlan Cox 		}
2715c49fd3aSAlan Cox 		psb_gtt_takedown(dev);
2725c49fd3aSAlan Cox 		if (dev_priv->scratch_page) {
2735c49fd3aSAlan Cox 			__free_page(dev_priv->scratch_page);
2745c49fd3aSAlan Cox 			dev_priv->scratch_page = NULL;
2755c49fd3aSAlan Cox 		}
2765c49fd3aSAlan Cox 		if (dev_priv->vdc_reg) {
2775c49fd3aSAlan Cox 			iounmap(dev_priv->vdc_reg);
2785c49fd3aSAlan Cox 			dev_priv->vdc_reg = NULL;
2795c49fd3aSAlan Cox 		}
2805c49fd3aSAlan Cox 		if (dev_priv->sgx_reg) {
2815c49fd3aSAlan Cox 			iounmap(dev_priv->sgx_reg);
2825c49fd3aSAlan Cox 			dev_priv->sgx_reg = NULL;
2835c49fd3aSAlan Cox 		}
2845c49fd3aSAlan Cox 
2855c49fd3aSAlan Cox 		kfree(dev_priv);
2865c49fd3aSAlan Cox 		dev->dev_private = NULL;
2875c49fd3aSAlan Cox 
2885c49fd3aSAlan Cox 		/*destroy VBT data*/
2895c49fd3aSAlan Cox 		psb_intel_destroy_bios(dev);
2905c49fd3aSAlan Cox 	}
2915c49fd3aSAlan Cox 
2925c49fd3aSAlan Cox 	gma_power_uninit(dev);
2935c49fd3aSAlan Cox 
2945c49fd3aSAlan Cox 	return 0;
2955c49fd3aSAlan Cox }
2965c49fd3aSAlan Cox 
2975c49fd3aSAlan Cox 
2985c49fd3aSAlan Cox static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
2995c49fd3aSAlan Cox {
3005c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv;
3015c49fd3aSAlan Cox 	unsigned long resource_start;
3025c49fd3aSAlan Cox 	struct psb_gtt *pg;
3035c49fd3aSAlan Cox 	unsigned long irqflags;
3045c49fd3aSAlan Cox 	int ret = -ENOMEM;
3055c49fd3aSAlan Cox 	uint32_t tt_pages;
3065c49fd3aSAlan Cox 	struct drm_connector *connector;
3075c49fd3aSAlan Cox 	struct psb_intel_output *psb_intel_output;
3085c49fd3aSAlan Cox 
3095c49fd3aSAlan Cox 	dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
3105c49fd3aSAlan Cox 	if (dev_priv == NULL)
3115c49fd3aSAlan Cox 		return -ENOMEM;
3125c49fd3aSAlan Cox 
3135c49fd3aSAlan Cox 	dev_priv->ops = (struct psb_ops *)chipset;
3145c49fd3aSAlan Cox 	dev_priv->dev = dev;
3155c49fd3aSAlan Cox 	dev->dev_private = (void *) dev_priv;
3165c49fd3aSAlan Cox 
3175c49fd3aSAlan Cox 	dev_priv->num_pipe = dev_priv->ops->pipes;
3185c49fd3aSAlan Cox 
3195c49fd3aSAlan Cox 	resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
3205c49fd3aSAlan Cox 
3215c49fd3aSAlan Cox 	dev_priv->vdc_reg =
3225c49fd3aSAlan Cox 	    ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
3235c49fd3aSAlan Cox 	if (!dev_priv->vdc_reg)
3245c49fd3aSAlan Cox 		goto out_err;
3255c49fd3aSAlan Cox 
3265c49fd3aSAlan Cox 	dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
3275c49fd3aSAlan Cox 							PSB_SGX_SIZE);
3285c49fd3aSAlan Cox 	if (!dev_priv->sgx_reg)
3295c49fd3aSAlan Cox 		goto out_err;
3305c49fd3aSAlan Cox 
3315c49fd3aSAlan Cox 	ret = dev_priv->ops->chip_setup(dev);
3325c49fd3aSAlan Cox 	if (ret)
3335c49fd3aSAlan Cox 		goto out_err;
3345c49fd3aSAlan Cox 
3355c49fd3aSAlan Cox 	/* Init OSPM support */
3365c49fd3aSAlan Cox 	gma_power_init(dev);
3375c49fd3aSAlan Cox 
3385c49fd3aSAlan Cox 	ret = -ENOMEM;
3395c49fd3aSAlan Cox 
3405c49fd3aSAlan Cox 	dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
3415c49fd3aSAlan Cox 	if (!dev_priv->scratch_page)
3425c49fd3aSAlan Cox 		goto out_err;
3435c49fd3aSAlan Cox 
3445c49fd3aSAlan Cox 	set_pages_uc(dev_priv->scratch_page, 1);
3455c49fd3aSAlan Cox 
3465c49fd3aSAlan Cox 	ret = psb_gtt_init(dev, 0);
3475c49fd3aSAlan Cox 	if (ret)
3485c49fd3aSAlan Cox 		goto out_err;
3495c49fd3aSAlan Cox 
3505c49fd3aSAlan Cox 	dev_priv->mmu = psb_mmu_driver_init((void *)0,
3515c49fd3aSAlan Cox 					drm_psb_trap_pagefaults, 0,
3525c49fd3aSAlan Cox 					dev_priv);
3535c49fd3aSAlan Cox 	if (!dev_priv->mmu)
3545c49fd3aSAlan Cox 		goto out_err;
3555c49fd3aSAlan Cox 
3565c49fd3aSAlan Cox 	pg = &dev_priv->gtt;
3575c49fd3aSAlan Cox 
3585c49fd3aSAlan Cox 	tt_pages = (pg->gatt_pages < PSB_TT_PRIV0_PLIMIT) ?
3595c49fd3aSAlan Cox 		(pg->gatt_pages) : PSB_TT_PRIV0_PLIMIT;
3605c49fd3aSAlan Cox 
3615c49fd3aSAlan Cox 
3625c49fd3aSAlan Cox 	dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
3635c49fd3aSAlan Cox 	if (!dev_priv->pf_pd)
3645c49fd3aSAlan Cox 		goto out_err;
3655c49fd3aSAlan Cox 
3665c49fd3aSAlan Cox 	psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
3675c49fd3aSAlan Cox 	psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
3685c49fd3aSAlan Cox 
3695c49fd3aSAlan Cox 	ret = psb_do_init(dev);
3705c49fd3aSAlan Cox 	if (ret)
3715c49fd3aSAlan Cox 		return ret;
3725c49fd3aSAlan Cox 
3735c49fd3aSAlan Cox 	PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
3745c49fd3aSAlan Cox 	PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
3755c49fd3aSAlan Cox 
3765c49fd3aSAlan Cox /*	igd_opregion_init(&dev_priv->opregion_dev); */
3775c49fd3aSAlan Cox 	acpi_video_register();
3785c49fd3aSAlan Cox 	if (dev_priv->lid_state)
3795c49fd3aSAlan Cox 		psb_lid_timer_init(dev_priv);
3805c49fd3aSAlan Cox 
3815c49fd3aSAlan Cox 	ret = drm_vblank_init(dev, dev_priv->num_pipe);
3825c49fd3aSAlan Cox 	if (ret)
3835c49fd3aSAlan Cox 		goto out_err;
3845c49fd3aSAlan Cox 
3855c49fd3aSAlan Cox 	/*
3865c49fd3aSAlan Cox 	 * Install interrupt handlers prior to powering off SGX or else we will
3875c49fd3aSAlan Cox 	 * crash.
3885c49fd3aSAlan Cox 	 */
3895c49fd3aSAlan Cox 	dev_priv->vdc_irq_mask = 0;
3905c49fd3aSAlan Cox 	dev_priv->pipestat[0] = 0;
3915c49fd3aSAlan Cox 	dev_priv->pipestat[1] = 0;
3925c49fd3aSAlan Cox 	dev_priv->pipestat[2] = 0;
3935c49fd3aSAlan Cox 	spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
3945c49fd3aSAlan Cox 	PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
3955c49fd3aSAlan Cox 	PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
3965c49fd3aSAlan Cox 	PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
3975c49fd3aSAlan Cox 	spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
3985c49fd3aSAlan Cox 	if (drm_core_check_feature(dev, DRIVER_MODESET))
3995c49fd3aSAlan Cox 		drm_irq_install(dev);
4005c49fd3aSAlan Cox 
4015c49fd3aSAlan Cox 	dev->vblank_disable_allowed = 1;
4025c49fd3aSAlan Cox 
4035c49fd3aSAlan Cox 	dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
4045c49fd3aSAlan Cox 
4055c49fd3aSAlan Cox 	dev->driver->get_vblank_counter = psb_get_vblank_counter;
4065c49fd3aSAlan Cox 
4075c49fd3aSAlan Cox 	if (drm_psb_no_fb == 0) {
4085c49fd3aSAlan Cox 		psb_modeset_init(dev);
4095c49fd3aSAlan Cox 		psb_fbdev_init(dev);
4105c49fd3aSAlan Cox 		drm_kms_helper_poll_init(dev);
4115c49fd3aSAlan Cox 	}
4125c49fd3aSAlan Cox 
4135c49fd3aSAlan Cox 	/* Only add backlight support if we have LVDS output */
4145c49fd3aSAlan Cox 	list_for_each_entry(connector, &dev->mode_config.connector_list,
4155c49fd3aSAlan Cox 			    head) {
4165c49fd3aSAlan Cox 		psb_intel_output = to_psb_intel_output(connector);
4175c49fd3aSAlan Cox 
4185c49fd3aSAlan Cox 		switch (psb_intel_output->type) {
4195c49fd3aSAlan Cox 		case INTEL_OUTPUT_LVDS:
4205c49fd3aSAlan Cox 		case INTEL_OUTPUT_MIPI:
4215c49fd3aSAlan Cox 			ret = gma_backlight_init(dev);
4225c49fd3aSAlan Cox 			break;
4235c49fd3aSAlan Cox 		}
4245c49fd3aSAlan Cox 	}
4255c49fd3aSAlan Cox 
4265c49fd3aSAlan Cox 	if (ret)
4275c49fd3aSAlan Cox 		return ret;
4285c49fd3aSAlan Cox #if 0
4295c49fd3aSAlan Cox 	/*enable runtime pm at last*/
4305c49fd3aSAlan Cox 	pm_runtime_enable(&dev->pdev->dev);
4315c49fd3aSAlan Cox 	pm_runtime_set_active(&dev->pdev->dev);
4325c49fd3aSAlan Cox #endif
4335c49fd3aSAlan Cox 	/*Intel drm driver load is done, continue doing pvr load*/
4345c49fd3aSAlan Cox 	return 0;
4355c49fd3aSAlan Cox out_err:
4365c49fd3aSAlan Cox 	psb_driver_unload(dev);
4375c49fd3aSAlan Cox 	return ret;
4385c49fd3aSAlan Cox }
4395c49fd3aSAlan Cox 
4405c49fd3aSAlan Cox int psb_driver_device_is_agp(struct drm_device *dev)
4415c49fd3aSAlan Cox {
4425c49fd3aSAlan Cox 	return 0;
4435c49fd3aSAlan Cox }
4445c49fd3aSAlan Cox 
4455c49fd3aSAlan Cox 
4465c49fd3aSAlan Cox static int psb_sizes_ioctl(struct drm_device *dev, void *data,
4475c49fd3aSAlan Cox 			   struct drm_file *file_priv)
4485c49fd3aSAlan Cox {
4495c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
4505c49fd3aSAlan Cox 	struct drm_psb_sizes_arg *arg =
4515c49fd3aSAlan Cox 		(struct drm_psb_sizes_arg *) data;
4525c49fd3aSAlan Cox 
4535c49fd3aSAlan Cox 	*arg = dev_priv->sizes;
4545c49fd3aSAlan Cox 	return 0;
4555c49fd3aSAlan Cox }
4565c49fd3aSAlan Cox 
4575c49fd3aSAlan Cox static int psb_dc_state_ioctl(struct drm_device *dev, void * data,
4585c49fd3aSAlan Cox 				struct drm_file *file_priv)
4595c49fd3aSAlan Cox {
4605c49fd3aSAlan Cox 	uint32_t flags;
4615c49fd3aSAlan Cox 	uint32_t obj_id;
4625c49fd3aSAlan Cox 	struct drm_mode_object *obj;
4635c49fd3aSAlan Cox 	struct drm_connector *connector;
4645c49fd3aSAlan Cox 	struct drm_crtc *crtc;
4655c49fd3aSAlan Cox 	struct drm_psb_dc_state_arg *arg = data;
4665c49fd3aSAlan Cox 
4675c49fd3aSAlan Cox 
4685c49fd3aSAlan Cox 	/* Double check MRST case */
4695c49fd3aSAlan Cox 	if (IS_MRST(dev) || IS_MFLD(dev))
4705c49fd3aSAlan Cox 		return -EOPNOTSUPP;
4715c49fd3aSAlan Cox 
4725c49fd3aSAlan Cox 	flags = arg->flags;
4735c49fd3aSAlan Cox 	obj_id = arg->obj_id;
4745c49fd3aSAlan Cox 
4755c49fd3aSAlan Cox 	if (flags & PSB_DC_CRTC_MASK) {
4765c49fd3aSAlan Cox 		obj = drm_mode_object_find(dev, obj_id,
4775c49fd3aSAlan Cox 				DRM_MODE_OBJECT_CRTC);
4785c49fd3aSAlan Cox 		if (!obj) {
4795c49fd3aSAlan Cox 			dev_dbg(dev->dev, "Invalid CRTC object.\n");
4805c49fd3aSAlan Cox 			return -EINVAL;
4815c49fd3aSAlan Cox 		}
4825c49fd3aSAlan Cox 
4835c49fd3aSAlan Cox 		crtc = obj_to_crtc(obj);
4845c49fd3aSAlan Cox 
4855c49fd3aSAlan Cox 		mutex_lock(&dev->mode_config.mutex);
4865c49fd3aSAlan Cox 		if (drm_helper_crtc_in_use(crtc)) {
4875c49fd3aSAlan Cox 			if (flags & PSB_DC_CRTC_SAVE)
4885c49fd3aSAlan Cox 				crtc->funcs->save(crtc);
4895c49fd3aSAlan Cox 			else
4905c49fd3aSAlan Cox 				crtc->funcs->restore(crtc);
4915c49fd3aSAlan Cox 		}
4925c49fd3aSAlan Cox 		mutex_unlock(&dev->mode_config.mutex);
4935c49fd3aSAlan Cox 
4945c49fd3aSAlan Cox 		return 0;
4955c49fd3aSAlan Cox 	} else if (flags & PSB_DC_OUTPUT_MASK) {
4965c49fd3aSAlan Cox 		obj = drm_mode_object_find(dev, obj_id,
4975c49fd3aSAlan Cox 				DRM_MODE_OBJECT_CONNECTOR);
4985c49fd3aSAlan Cox 		if (!obj) {
4995c49fd3aSAlan Cox 			dev_dbg(dev->dev, "Invalid connector id.\n");
5005c49fd3aSAlan Cox 			return -EINVAL;
5015c49fd3aSAlan Cox 		}
5025c49fd3aSAlan Cox 
5035c49fd3aSAlan Cox 		connector = obj_to_connector(obj);
5045c49fd3aSAlan Cox 		if (flags & PSB_DC_OUTPUT_SAVE)
5055c49fd3aSAlan Cox 			connector->funcs->save(connector);
5065c49fd3aSAlan Cox 		else
5075c49fd3aSAlan Cox 			connector->funcs->restore(connector);
5085c49fd3aSAlan Cox 
5095c49fd3aSAlan Cox 		return 0;
5105c49fd3aSAlan Cox 	}
5115c49fd3aSAlan Cox 	return -EINVAL;
5125c49fd3aSAlan Cox }
5135c49fd3aSAlan Cox 
5145c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd)
5155c49fd3aSAlan Cox {
5165c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
5175c49fd3aSAlan Cox 	if (bd) {
5185c49fd3aSAlan Cox 		bd->props.brightness = bd->ops->get_brightness(bd);
5195c49fd3aSAlan Cox 		backlight_update_status(bd);
5205c49fd3aSAlan Cox 	}
5215c49fd3aSAlan Cox #endif
5225c49fd3aSAlan Cox }
5235c49fd3aSAlan Cox 
5245c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
5255c49fd3aSAlan Cox 		       struct drm_file *file_priv)
5265c49fd3aSAlan Cox {
5275c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
5285c49fd3aSAlan Cox 	uint32_t *arg = data;
5295c49fd3aSAlan Cox 
5305c49fd3aSAlan Cox 	dev_priv->blc_adj2 = *arg;
5315c49fd3aSAlan Cox 	get_brightness(dev_priv->backlight_device);
5325c49fd3aSAlan Cox 	return 0;
5335c49fd3aSAlan Cox }
5345c49fd3aSAlan Cox 
5355c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data,
5365c49fd3aSAlan Cox 			struct drm_file *file_priv)
5375c49fd3aSAlan Cox {
5385c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
5395c49fd3aSAlan Cox 	uint32_t *arg = data;
5405c49fd3aSAlan Cox 
5415c49fd3aSAlan Cox 	dev_priv->blc_adj1 = *arg;
5425c49fd3aSAlan Cox 	get_brightness(dev_priv->backlight_device);
5435c49fd3aSAlan Cox 	return 0;
5445c49fd3aSAlan Cox }
5455c49fd3aSAlan Cox 
5465c49fd3aSAlan Cox /* return the current mode to the dpst module */
5475c49fd3aSAlan Cox static int psb_dpst_ioctl(struct drm_device *dev, void *data,
5485c49fd3aSAlan Cox 			  struct drm_file *file_priv)
5495c49fd3aSAlan Cox {
5505c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
5515c49fd3aSAlan Cox 	uint32_t *arg = data;
5525c49fd3aSAlan Cox 	uint32_t x;
5535c49fd3aSAlan Cox 	uint32_t y;
5545c49fd3aSAlan Cox 	uint32_t reg;
5555c49fd3aSAlan Cox 
5565c49fd3aSAlan Cox 	if (!gma_power_begin(dev, 0))
5575c49fd3aSAlan Cox 		return -EIO;
5585c49fd3aSAlan Cox 
5595c49fd3aSAlan Cox 	reg = PSB_RVDC32(PIPEASRC);
5605c49fd3aSAlan Cox 
5615c49fd3aSAlan Cox 	gma_power_end(dev);
5625c49fd3aSAlan Cox 
5635c49fd3aSAlan Cox 	/* horizontal is the left 16 bits */
5645c49fd3aSAlan Cox 	x = reg >> 16;
5655c49fd3aSAlan Cox 	/* vertical is the right 16 bits */
5665c49fd3aSAlan Cox 	y = reg & 0x0000ffff;
5675c49fd3aSAlan Cox 
5685c49fd3aSAlan Cox 	/* the values are the image size minus one */
5695c49fd3aSAlan Cox 	x++;
5705c49fd3aSAlan Cox 	y++;
5715c49fd3aSAlan Cox 
5725c49fd3aSAlan Cox 	*arg = (x << 16) | y;
5735c49fd3aSAlan Cox 
5745c49fd3aSAlan Cox 	return 0;
5755c49fd3aSAlan Cox }
5765c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data,
5775c49fd3aSAlan Cox 			   struct drm_file *file_priv)
5785c49fd3aSAlan Cox {
5795c49fd3aSAlan Cox 	struct drm_psb_dpst_lut_arg *lut_arg = data;
5805c49fd3aSAlan Cox 	struct drm_mode_object *obj;
5815c49fd3aSAlan Cox 	struct drm_crtc *crtc;
5825c49fd3aSAlan Cox 	struct drm_connector *connector;
5835c49fd3aSAlan Cox 	struct psb_intel_crtc *psb_intel_crtc;
5845c49fd3aSAlan Cox 	int i = 0;
5855c49fd3aSAlan Cox 	int32_t obj_id;
5865c49fd3aSAlan Cox 
5875c49fd3aSAlan Cox 	obj_id = lut_arg->output_id;
5885c49fd3aSAlan Cox 	obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
5895c49fd3aSAlan Cox 	if (!obj) {
5905c49fd3aSAlan Cox 		dev_dbg(dev->dev, "Invalid Connector object.\n");
5915c49fd3aSAlan Cox 		return -EINVAL;
5925c49fd3aSAlan Cox 	}
5935c49fd3aSAlan Cox 
5945c49fd3aSAlan Cox 	connector = obj_to_connector(obj);
5955c49fd3aSAlan Cox 	crtc = connector->encoder->crtc;
5965c49fd3aSAlan Cox 	psb_intel_crtc = to_psb_intel_crtc(crtc);
5975c49fd3aSAlan Cox 
5985c49fd3aSAlan Cox 	for (i = 0; i < 256; i++)
5995c49fd3aSAlan Cox 		psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
6005c49fd3aSAlan Cox 
6015c49fd3aSAlan Cox 	psb_intel_crtc_load_lut(crtc);
6025c49fd3aSAlan Cox 
6035c49fd3aSAlan Cox 	return 0;
6045c49fd3aSAlan Cox }
6055c49fd3aSAlan Cox 
6065c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
6075c49fd3aSAlan Cox 				struct drm_file *file_priv)
6085c49fd3aSAlan Cox {
6095c49fd3aSAlan Cox 	uint32_t obj_id;
6105c49fd3aSAlan Cox 	uint16_t op;
6115c49fd3aSAlan Cox 	struct drm_mode_modeinfo *umode;
6125c49fd3aSAlan Cox 	struct drm_display_mode *mode = NULL;
6135c49fd3aSAlan Cox 	struct drm_psb_mode_operation_arg *arg;
6145c49fd3aSAlan Cox 	struct drm_mode_object *obj;
6155c49fd3aSAlan Cox 	struct drm_connector *connector;
6165c49fd3aSAlan Cox 	struct drm_framebuffer *drm_fb;
6175c49fd3aSAlan Cox 	struct psb_framebuffer *psb_fb;
6185c49fd3aSAlan Cox 	struct drm_connector_helper_funcs *connector_funcs;
6195c49fd3aSAlan Cox 	int ret = 0;
6205c49fd3aSAlan Cox 	int resp = MODE_OK;
6215c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
6225c49fd3aSAlan Cox 
6235c49fd3aSAlan Cox 	arg = (struct drm_psb_mode_operation_arg *)data;
6245c49fd3aSAlan Cox 	obj_id = arg->obj_id;
6255c49fd3aSAlan Cox 	op = arg->operation;
6265c49fd3aSAlan Cox 
6275c49fd3aSAlan Cox 	switch (op) {
6285c49fd3aSAlan Cox 	case PSB_MODE_OPERATION_SET_DC_BASE:
6295c49fd3aSAlan Cox 		obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_FB);
6305c49fd3aSAlan Cox 		if (!obj) {
6315c49fd3aSAlan Cox 			dev_dbg(dev->dev, "Invalid FB id %d\n", obj_id);
6325c49fd3aSAlan Cox 			return -EINVAL;
6335c49fd3aSAlan Cox 		}
6345c49fd3aSAlan Cox 
6355c49fd3aSAlan Cox 		drm_fb = obj_to_fb(obj);
6365c49fd3aSAlan Cox 		psb_fb = to_psb_fb(drm_fb);
6375c49fd3aSAlan Cox 
6385c49fd3aSAlan Cox 		if (gma_power_begin(dev, 0)) {
6395c49fd3aSAlan Cox 			REG_WRITE(DSPASURF, psb_fb->gtt->offset);
6405c49fd3aSAlan Cox 			REG_READ(DSPASURF);
6415c49fd3aSAlan Cox 			gma_power_end(dev);
6425c49fd3aSAlan Cox 		} else {
6435c49fd3aSAlan Cox 			dev_priv->saveDSPASURF = psb_fb->gtt->offset;
6445c49fd3aSAlan Cox 		}
6455c49fd3aSAlan Cox 
6465c49fd3aSAlan Cox 		return 0;
6475c49fd3aSAlan Cox 	case PSB_MODE_OPERATION_MODE_VALID:
6485c49fd3aSAlan Cox 		umode = &arg->mode;
6495c49fd3aSAlan Cox 
6505c49fd3aSAlan Cox 		mutex_lock(&dev->mode_config.mutex);
6515c49fd3aSAlan Cox 
6525c49fd3aSAlan Cox 		obj = drm_mode_object_find(dev, obj_id,
6535c49fd3aSAlan Cox 					DRM_MODE_OBJECT_CONNECTOR);
6545c49fd3aSAlan Cox 		if (!obj) {
6555c49fd3aSAlan Cox 			ret = -EINVAL;
6565c49fd3aSAlan Cox 			goto mode_op_out;
6575c49fd3aSAlan Cox 		}
6585c49fd3aSAlan Cox 
6595c49fd3aSAlan Cox 		connector = obj_to_connector(obj);
6605c49fd3aSAlan Cox 
6615c49fd3aSAlan Cox 		mode = drm_mode_create(dev);
6625c49fd3aSAlan Cox 		if (!mode) {
6635c49fd3aSAlan Cox 			ret = -ENOMEM;
6645c49fd3aSAlan Cox 			goto mode_op_out;
6655c49fd3aSAlan Cox 		}
6665c49fd3aSAlan Cox 
6675c49fd3aSAlan Cox 		/* drm_crtc_convert_umode(mode, umode); */
6685c49fd3aSAlan Cox 		{
6695c49fd3aSAlan Cox 			mode->clock = umode->clock;
6705c49fd3aSAlan Cox 			mode->hdisplay = umode->hdisplay;
6715c49fd3aSAlan Cox 			mode->hsync_start = umode->hsync_start;
6725c49fd3aSAlan Cox 			mode->hsync_end = umode->hsync_end;
6735c49fd3aSAlan Cox 			mode->htotal = umode->htotal;
6745c49fd3aSAlan Cox 			mode->hskew = umode->hskew;
6755c49fd3aSAlan Cox 			mode->vdisplay = umode->vdisplay;
6765c49fd3aSAlan Cox 			mode->vsync_start = umode->vsync_start;
6775c49fd3aSAlan Cox 			mode->vsync_end = umode->vsync_end;
6785c49fd3aSAlan Cox 			mode->vtotal = umode->vtotal;
6795c49fd3aSAlan Cox 			mode->vscan = umode->vscan;
6805c49fd3aSAlan Cox 			mode->vrefresh = umode->vrefresh;
6815c49fd3aSAlan Cox 			mode->flags = umode->flags;
6825c49fd3aSAlan Cox 			mode->type = umode->type;
6835c49fd3aSAlan Cox 			strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
6845c49fd3aSAlan Cox 			mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
6855c49fd3aSAlan Cox 		}
6865c49fd3aSAlan Cox 
6875c49fd3aSAlan Cox 		connector_funcs = (struct drm_connector_helper_funcs *)
6885c49fd3aSAlan Cox 				   connector->helper_private;
6895c49fd3aSAlan Cox 
6905c49fd3aSAlan Cox 		if (connector_funcs->mode_valid) {
6915c49fd3aSAlan Cox 			resp = connector_funcs->mode_valid(connector, mode);
6925c49fd3aSAlan Cox 			arg->data = (void *)resp;
6935c49fd3aSAlan Cox 		}
6945c49fd3aSAlan Cox 
6955c49fd3aSAlan Cox 		/*do some clean up work*/
6965c49fd3aSAlan Cox 		if (mode)
6975c49fd3aSAlan Cox 			drm_mode_destroy(dev, mode);
6985c49fd3aSAlan Cox mode_op_out:
6995c49fd3aSAlan Cox 		mutex_unlock(&dev->mode_config.mutex);
7005c49fd3aSAlan Cox 		return ret;
7015c49fd3aSAlan Cox 
7025c49fd3aSAlan Cox 	default:
7035c49fd3aSAlan Cox 		dev_dbg(dev->dev, "Unsupported psb mode operation\n");
7045c49fd3aSAlan Cox 		return -EOPNOTSUPP;
7055c49fd3aSAlan Cox 	}
7065c49fd3aSAlan Cox 
7075c49fd3aSAlan Cox 	return 0;
7085c49fd3aSAlan Cox }
7095c49fd3aSAlan Cox 
7105c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
7115c49fd3aSAlan Cox 				   struct drm_file *file_priv)
7125c49fd3aSAlan Cox {
7135c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
7145c49fd3aSAlan Cox 	struct drm_psb_stolen_memory_arg *arg = data;
7155c49fd3aSAlan Cox 
7165c49fd3aSAlan Cox 	arg->base = dev_priv->stolen_base;
7175c49fd3aSAlan Cox 	arg->size = dev_priv->vram_stolen_size;
7185c49fd3aSAlan Cox 
7195c49fd3aSAlan Cox 	return 0;
7205c49fd3aSAlan Cox }
7215c49fd3aSAlan Cox 
7225c49fd3aSAlan Cox /* FIXME: needs Medfield changes */
7235c49fd3aSAlan Cox static int psb_register_rw_ioctl(struct drm_device *dev, void *data,
7245c49fd3aSAlan Cox 				 struct drm_file *file_priv)
7255c49fd3aSAlan Cox {
7265c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
7275c49fd3aSAlan Cox 	struct drm_psb_register_rw_arg *arg = data;
7285c49fd3aSAlan Cox 	bool usage = arg->b_force_hw_on ? true : false;
7295c49fd3aSAlan Cox 
7305c49fd3aSAlan Cox 	if (arg->display_write_mask != 0) {
7315c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
7325c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS)
7335c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.pfit_controls,
7345c49fd3aSAlan Cox 					   PFIT_CONTROL);
7355c49fd3aSAlan Cox 			if (arg->display_write_mask &
7365c49fd3aSAlan Cox 			    REGRWBITS_PFIT_AUTOSCALE_RATIOS)
7375c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.pfit_autoscale_ratios,
7385c49fd3aSAlan Cox 					   PFIT_AUTO_RATIOS);
7395c49fd3aSAlan Cox 			if (arg->display_write_mask &
7405c49fd3aSAlan Cox 			    REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS)
7415c49fd3aSAlan Cox 				PSB_WVDC32(
7425c49fd3aSAlan Cox 				   arg->display.pfit_programmed_scale_ratios,
7435c49fd3aSAlan Cox 				   PFIT_PGM_RATIOS);
7445c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PIPEASRC)
7455c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.pipeasrc,
7465c49fd3aSAlan Cox 					   PIPEASRC);
7475c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PIPEBSRC)
7485c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.pipebsrc,
7495c49fd3aSAlan Cox 					   PIPEBSRC);
7505c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_VTOTAL_A)
7515c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.vtotal_a,
7525c49fd3aSAlan Cox 					   VTOTAL_A);
7535c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_VTOTAL_B)
7545c49fd3aSAlan Cox 				PSB_WVDC32(arg->display.vtotal_b,
7555c49fd3aSAlan Cox 					   VTOTAL_B);
7565c49fd3aSAlan Cox 			gma_power_end(dev);
7575c49fd3aSAlan Cox 		} else {
7585c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS)
7595c49fd3aSAlan Cox 				dev_priv->savePFIT_CONTROL =
7605c49fd3aSAlan Cox 						arg->display.pfit_controls;
7615c49fd3aSAlan Cox 			if (arg->display_write_mask &
7625c49fd3aSAlan Cox 			    REGRWBITS_PFIT_AUTOSCALE_RATIOS)
7635c49fd3aSAlan Cox 				dev_priv->savePFIT_AUTO_RATIOS =
7645c49fd3aSAlan Cox 					arg->display.pfit_autoscale_ratios;
7655c49fd3aSAlan Cox 			if (arg->display_write_mask &
7665c49fd3aSAlan Cox 			    REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS)
7675c49fd3aSAlan Cox 				dev_priv->savePFIT_PGM_RATIOS =
7685c49fd3aSAlan Cox 				   arg->display.pfit_programmed_scale_ratios;
7695c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PIPEASRC)
7705c49fd3aSAlan Cox 				dev_priv->savePIPEASRC = arg->display.pipeasrc;
7715c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_PIPEBSRC)
7725c49fd3aSAlan Cox 				dev_priv->savePIPEBSRC = arg->display.pipebsrc;
7735c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_VTOTAL_A)
7745c49fd3aSAlan Cox 				dev_priv->saveVTOTAL_A = arg->display.vtotal_a;
7755c49fd3aSAlan Cox 			if (arg->display_write_mask & REGRWBITS_VTOTAL_B)
7765c49fd3aSAlan Cox 				dev_priv->saveVTOTAL_B = arg->display.vtotal_b;
7775c49fd3aSAlan Cox 		}
7785c49fd3aSAlan Cox 	}
7795c49fd3aSAlan Cox 
7805c49fd3aSAlan Cox 	if (arg->display_read_mask != 0) {
7815c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
7825c49fd3aSAlan Cox 			if (arg->display_read_mask &
7835c49fd3aSAlan Cox 			    REGRWBITS_PFIT_CONTROLS)
7845c49fd3aSAlan Cox 				arg->display.pfit_controls =
7855c49fd3aSAlan Cox 						PSB_RVDC32(PFIT_CONTROL);
7865c49fd3aSAlan Cox 			if (arg->display_read_mask &
7875c49fd3aSAlan Cox 			    REGRWBITS_PFIT_AUTOSCALE_RATIOS)
7885c49fd3aSAlan Cox 				arg->display.pfit_autoscale_ratios =
7895c49fd3aSAlan Cox 						PSB_RVDC32(PFIT_AUTO_RATIOS);
7905c49fd3aSAlan Cox 			if (arg->display_read_mask &
7915c49fd3aSAlan Cox 			    REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS)
7925c49fd3aSAlan Cox 				arg->display.pfit_programmed_scale_ratios =
7935c49fd3aSAlan Cox 						PSB_RVDC32(PFIT_PGM_RATIOS);
7945c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_PIPEASRC)
7955c49fd3aSAlan Cox 				arg->display.pipeasrc = PSB_RVDC32(PIPEASRC);
7965c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_PIPEBSRC)
7975c49fd3aSAlan Cox 				arg->display.pipebsrc = PSB_RVDC32(PIPEBSRC);
7985c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_VTOTAL_A)
7995c49fd3aSAlan Cox 				arg->display.vtotal_a = PSB_RVDC32(VTOTAL_A);
8005c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_VTOTAL_B)
8015c49fd3aSAlan Cox 				arg->display.vtotal_b = PSB_RVDC32(VTOTAL_B);
8025c49fd3aSAlan Cox 			gma_power_end(dev);
8035c49fd3aSAlan Cox 		} else {
8045c49fd3aSAlan Cox 			if (arg->display_read_mask &
8055c49fd3aSAlan Cox 			    REGRWBITS_PFIT_CONTROLS)
8065c49fd3aSAlan Cox 				arg->display.pfit_controls =
8075c49fd3aSAlan Cox 						dev_priv->savePFIT_CONTROL;
8085c49fd3aSAlan Cox 			if (arg->display_read_mask &
8095c49fd3aSAlan Cox 			    REGRWBITS_PFIT_AUTOSCALE_RATIOS)
8105c49fd3aSAlan Cox 				arg->display.pfit_autoscale_ratios =
8115c49fd3aSAlan Cox 						dev_priv->savePFIT_AUTO_RATIOS;
8125c49fd3aSAlan Cox 			if (arg->display_read_mask &
8135c49fd3aSAlan Cox 			    REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS)
8145c49fd3aSAlan Cox 				arg->display.pfit_programmed_scale_ratios =
8155c49fd3aSAlan Cox 						dev_priv->savePFIT_PGM_RATIOS;
8165c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_PIPEASRC)
8175c49fd3aSAlan Cox 				arg->display.pipeasrc = dev_priv->savePIPEASRC;
8185c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_PIPEBSRC)
8195c49fd3aSAlan Cox 				arg->display.pipebsrc = dev_priv->savePIPEBSRC;
8205c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_VTOTAL_A)
8215c49fd3aSAlan Cox 				arg->display.vtotal_a = dev_priv->saveVTOTAL_A;
8225c49fd3aSAlan Cox 			if (arg->display_read_mask & REGRWBITS_VTOTAL_B)
8235c49fd3aSAlan Cox 				arg->display.vtotal_b = dev_priv->saveVTOTAL_B;
8245c49fd3aSAlan Cox 		}
8255c49fd3aSAlan Cox 	}
8265c49fd3aSAlan Cox 
8275c49fd3aSAlan Cox 	if (arg->overlay_write_mask != 0) {
8285c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
8295c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) {
8305c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC5, OV_OGAMC5);
8315c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC4, OV_OGAMC4);
8325c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC3, OV_OGAMC3);
8335c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC2, OV_OGAMC2);
8345c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC1, OV_OGAMC1);
8355c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC0, OV_OGAMC0);
8365c49fd3aSAlan Cox 			}
8375c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OVC_REGRWBITS_OGAM_ALL) {
8385c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC5, OVC_OGAMC5);
8395c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC4, OVC_OGAMC4);
8405c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC3, OVC_OGAMC3);
8415c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC2, OVC_OGAMC2);
8425c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC1, OVC_OGAMC1);
8435c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OGAMC0, OVC_OGAMC0);
8445c49fd3aSAlan Cox 			}
8455c49fd3aSAlan Cox 
8465c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OV_REGRWBITS_OVADD) {
8475c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OVADD, OV_OVADD);
8485c49fd3aSAlan Cox 
8495c49fd3aSAlan Cox 				if (arg->overlay.b_wait_vblank) {
8505c49fd3aSAlan Cox 					/* Wait for 20ms.*/
8515c49fd3aSAlan Cox 					unsigned long vblank_timeout = jiffies
8525c49fd3aSAlan Cox 								+ HZ/50;
8535c49fd3aSAlan Cox 					uint32_t temp;
8545c49fd3aSAlan Cox 					while (time_before_eq(jiffies,
8555c49fd3aSAlan Cox 							vblank_timeout)) {
8565c49fd3aSAlan Cox 						temp = PSB_RVDC32(OV_DOVASTA);
8575c49fd3aSAlan Cox 						if ((temp & (0x1 << 31)) != 0)
8585c49fd3aSAlan Cox 							break;
8595c49fd3aSAlan Cox 						cpu_relax();
8605c49fd3aSAlan Cox 					}
8615c49fd3aSAlan Cox 				}
8625c49fd3aSAlan Cox 			}
8635c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OVC_REGRWBITS_OVADD) {
8645c49fd3aSAlan Cox 				PSB_WVDC32(arg->overlay.OVADD, OVC_OVADD);
8655c49fd3aSAlan Cox 				if (arg->overlay.b_wait_vblank) {
8665c49fd3aSAlan Cox 					/* Wait for 20ms.*/
8675c49fd3aSAlan Cox 					unsigned long vblank_timeout =
8685c49fd3aSAlan Cox 							jiffies + HZ/50;
8695c49fd3aSAlan Cox 					uint32_t temp;
8705c49fd3aSAlan Cox 					while (time_before_eq(jiffies,
8715c49fd3aSAlan Cox 							vblank_timeout)) {
8725c49fd3aSAlan Cox 						temp = PSB_RVDC32(OVC_DOVCSTA);
8735c49fd3aSAlan Cox 						if ((temp & (0x1 << 31)) != 0)
8745c49fd3aSAlan Cox 							break;
8755c49fd3aSAlan Cox 						cpu_relax();
8765c49fd3aSAlan Cox 					}
8775c49fd3aSAlan Cox 				}
8785c49fd3aSAlan Cox 			}
8795c49fd3aSAlan Cox 			gma_power_end(dev);
8805c49fd3aSAlan Cox 		} else {
8815c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) {
8825c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC5 = arg->overlay.OGAMC5;
8835c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC4 = arg->overlay.OGAMC4;
8845c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC3 = arg->overlay.OGAMC3;
8855c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC2 = arg->overlay.OGAMC2;
8865c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC1 = arg->overlay.OGAMC1;
8875c49fd3aSAlan Cox 				dev_priv->saveOV_OGAMC0 = arg->overlay.OGAMC0;
8885c49fd3aSAlan Cox 			}
8895c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OVC_REGRWBITS_OGAM_ALL) {
8905c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC5 = arg->overlay.OGAMC5;
8915c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC4 = arg->overlay.OGAMC4;
8925c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC3 = arg->overlay.OGAMC3;
8935c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC2 = arg->overlay.OGAMC2;
8945c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC1 = arg->overlay.OGAMC1;
8955c49fd3aSAlan Cox 				dev_priv->saveOVC_OGAMC0 = arg->overlay.OGAMC0;
8965c49fd3aSAlan Cox 			}
8975c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OV_REGRWBITS_OVADD)
8985c49fd3aSAlan Cox 				dev_priv->saveOV_OVADD = arg->overlay.OVADD;
8995c49fd3aSAlan Cox 			if (arg->overlay_write_mask & OVC_REGRWBITS_OVADD)
9005c49fd3aSAlan Cox 				dev_priv->saveOVC_OVADD = arg->overlay.OVADD;
9015c49fd3aSAlan Cox 		}
9025c49fd3aSAlan Cox 	}
9035c49fd3aSAlan Cox 
9045c49fd3aSAlan Cox 	if (arg->overlay_read_mask != 0) {
9055c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
9065c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) {
9075c49fd3aSAlan Cox 				arg->overlay.OGAMC5 = PSB_RVDC32(OV_OGAMC5);
9085c49fd3aSAlan Cox 				arg->overlay.OGAMC4 = PSB_RVDC32(OV_OGAMC4);
9095c49fd3aSAlan Cox 				arg->overlay.OGAMC3 = PSB_RVDC32(OV_OGAMC3);
9105c49fd3aSAlan Cox 				arg->overlay.OGAMC2 = PSB_RVDC32(OV_OGAMC2);
9115c49fd3aSAlan Cox 				arg->overlay.OGAMC1 = PSB_RVDC32(OV_OGAMC1);
9125c49fd3aSAlan Cox 				arg->overlay.OGAMC0 = PSB_RVDC32(OV_OGAMC0);
9135c49fd3aSAlan Cox 			}
9145c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OVC_REGRWBITS_OGAM_ALL) {
9155c49fd3aSAlan Cox 				arg->overlay.OGAMC5 = PSB_RVDC32(OVC_OGAMC5);
9165c49fd3aSAlan Cox 				arg->overlay.OGAMC4 = PSB_RVDC32(OVC_OGAMC4);
9175c49fd3aSAlan Cox 				arg->overlay.OGAMC3 = PSB_RVDC32(OVC_OGAMC3);
9185c49fd3aSAlan Cox 				arg->overlay.OGAMC2 = PSB_RVDC32(OVC_OGAMC2);
9195c49fd3aSAlan Cox 				arg->overlay.OGAMC1 = PSB_RVDC32(OVC_OGAMC1);
9205c49fd3aSAlan Cox 				arg->overlay.OGAMC0 = PSB_RVDC32(OVC_OGAMC0);
9215c49fd3aSAlan Cox 			}
9225c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OV_REGRWBITS_OVADD)
9235c49fd3aSAlan Cox 				arg->overlay.OVADD = PSB_RVDC32(OV_OVADD);
9245c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OVC_REGRWBITS_OVADD)
9255c49fd3aSAlan Cox 				arg->overlay.OVADD = PSB_RVDC32(OVC_OVADD);
9265c49fd3aSAlan Cox 			gma_power_end(dev);
9275c49fd3aSAlan Cox 		} else {
9285c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) {
9295c49fd3aSAlan Cox 				arg->overlay.OGAMC5 = dev_priv->saveOV_OGAMC5;
9305c49fd3aSAlan Cox 				arg->overlay.OGAMC4 = dev_priv->saveOV_OGAMC4;
9315c49fd3aSAlan Cox 				arg->overlay.OGAMC3 = dev_priv->saveOV_OGAMC3;
9325c49fd3aSAlan Cox 				arg->overlay.OGAMC2 = dev_priv->saveOV_OGAMC2;
9335c49fd3aSAlan Cox 				arg->overlay.OGAMC1 = dev_priv->saveOV_OGAMC1;
9345c49fd3aSAlan Cox 				arg->overlay.OGAMC0 = dev_priv->saveOV_OGAMC0;
9355c49fd3aSAlan Cox 			}
9365c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OVC_REGRWBITS_OGAM_ALL) {
9375c49fd3aSAlan Cox 				arg->overlay.OGAMC5 = dev_priv->saveOVC_OGAMC5;
9385c49fd3aSAlan Cox 				arg->overlay.OGAMC4 = dev_priv->saveOVC_OGAMC4;
9395c49fd3aSAlan Cox 				arg->overlay.OGAMC3 = dev_priv->saveOVC_OGAMC3;
9405c49fd3aSAlan Cox 				arg->overlay.OGAMC2 = dev_priv->saveOVC_OGAMC2;
9415c49fd3aSAlan Cox 				arg->overlay.OGAMC1 = dev_priv->saveOVC_OGAMC1;
9425c49fd3aSAlan Cox 				arg->overlay.OGAMC0 = dev_priv->saveOVC_OGAMC0;
9435c49fd3aSAlan Cox 			}
9445c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OV_REGRWBITS_OVADD)
9455c49fd3aSAlan Cox 				arg->overlay.OVADD = dev_priv->saveOV_OVADD;
9465c49fd3aSAlan Cox 			if (arg->overlay_read_mask & OVC_REGRWBITS_OVADD)
9475c49fd3aSAlan Cox 				arg->overlay.OVADD = dev_priv->saveOVC_OVADD;
9485c49fd3aSAlan Cox 		}
9495c49fd3aSAlan Cox 	}
9505c49fd3aSAlan Cox 
9515c49fd3aSAlan Cox 	if (arg->sprite_enable_mask != 0) {
9525c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
9535c49fd3aSAlan Cox 			PSB_WVDC32(0x1F3E, DSPARB);
9545c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspa_control
9555c49fd3aSAlan Cox 					| PSB_RVDC32(DSPACNTR), DSPACNTR);
9565c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspa_key_value, DSPAKEYVAL);
9575c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspa_key_mask, DSPAKEYMASK);
9585c49fd3aSAlan Cox 			PSB_WVDC32(PSB_RVDC32(DSPASURF), DSPASURF);
9595c49fd3aSAlan Cox 			PSB_RVDC32(DSPASURF);
9605c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_control, DSPCCNTR);
9615c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_stride, DSPCSTRIDE);
9625c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_position, DSPCPOS);
9635c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_linear_offset, DSPCLINOFF);
9645c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_size, DSPCSIZE);
9655c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF);
9665c49fd3aSAlan Cox 			PSB_RVDC32(DSPCSURF);
9675c49fd3aSAlan Cox 			gma_power_end(dev);
9685c49fd3aSAlan Cox 		}
9695c49fd3aSAlan Cox 	}
9705c49fd3aSAlan Cox 
9715c49fd3aSAlan Cox 	if (arg->sprite_disable_mask != 0) {
9725c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
9735c49fd3aSAlan Cox 			PSB_WVDC32(0x3F3E, DSPARB);
9745c49fd3aSAlan Cox 			PSB_WVDC32(0x0, DSPCCNTR);
9755c49fd3aSAlan Cox 			PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF);
9765c49fd3aSAlan Cox 			PSB_RVDC32(DSPCSURF);
9775c49fd3aSAlan Cox 			gma_power_end(dev);
9785c49fd3aSAlan Cox 		}
9795c49fd3aSAlan Cox 	}
9805c49fd3aSAlan Cox 
9815c49fd3aSAlan Cox 	if (arg->subpicture_enable_mask != 0) {
9825c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
9835c49fd3aSAlan Cox 			uint32_t temp;
9845c49fd3aSAlan Cox 			if (arg->subpicture_enable_mask & REGRWBITS_DSPACNTR) {
9855c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPACNTR);
9865c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
9875c49fd3aSAlan Cox 				temp &= ~DISPPLANE_BOTTOM;
9885c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP;
9895c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPACNTR);
9905c49fd3aSAlan Cox 
9915c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPABASE);
9925c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPABASE);
9935c49fd3aSAlan Cox 				PSB_RVDC32(DSPABASE);
9945c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPASURF);
9955c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPASURF);
9965c49fd3aSAlan Cox 				PSB_RVDC32(DSPASURF);
9975c49fd3aSAlan Cox 			}
9985c49fd3aSAlan Cox 			if (arg->subpicture_enable_mask & REGRWBITS_DSPBCNTR) {
9995c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBCNTR);
10005c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
10015c49fd3aSAlan Cox 				temp &= ~DISPPLANE_BOTTOM;
10025c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP;
10035c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBCNTR);
10045c49fd3aSAlan Cox 
10055c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBBASE);
10065c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBBASE);
10075c49fd3aSAlan Cox 				PSB_RVDC32(DSPBBASE);
10085c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBSURF);
10095c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBSURF);
10105c49fd3aSAlan Cox 				PSB_RVDC32(DSPBSURF);
10115c49fd3aSAlan Cox 			}
10125c49fd3aSAlan Cox 			if (arg->subpicture_enable_mask & REGRWBITS_DSPCCNTR) {
10135c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCCNTR);
10145c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
10155c49fd3aSAlan Cox 				temp &= ~DISPPLANE_BOTTOM;
10165c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP;
10175c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCCNTR);
10185c49fd3aSAlan Cox 
10195c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCBASE);
10205c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCBASE);
10215c49fd3aSAlan Cox 				PSB_RVDC32(DSPCBASE);
10225c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCSURF);
10235c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCSURF);
10245c49fd3aSAlan Cox 				PSB_RVDC32(DSPCSURF);
10255c49fd3aSAlan Cox 			}
10265c49fd3aSAlan Cox 			gma_power_end(dev);
10275c49fd3aSAlan Cox 		}
10285c49fd3aSAlan Cox 	}
10295c49fd3aSAlan Cox 
10305c49fd3aSAlan Cox 	if (arg->subpicture_disable_mask != 0) {
10315c49fd3aSAlan Cox 		if (gma_power_begin(dev, usage)) {
10325c49fd3aSAlan Cox 			uint32_t temp;
10335c49fd3aSAlan Cox 			if (arg->subpicture_disable_mask & REGRWBITS_DSPACNTR) {
10345c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPACNTR);
10355c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
10365c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP_NO_ALPHA;
10375c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPACNTR);
10385c49fd3aSAlan Cox 
10395c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPABASE);
10405c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPABASE);
10415c49fd3aSAlan Cox 				PSB_RVDC32(DSPABASE);
10425c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPASURF);
10435c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPASURF);
10445c49fd3aSAlan Cox 				PSB_RVDC32(DSPASURF);
10455c49fd3aSAlan Cox 			}
10465c49fd3aSAlan Cox 			if (arg->subpicture_disable_mask & REGRWBITS_DSPBCNTR) {
10475c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBCNTR);
10485c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
10495c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP_NO_ALPHA;
10505c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBCNTR);
10515c49fd3aSAlan Cox 
10525c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBBASE);
10535c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBBASE);
10545c49fd3aSAlan Cox 				PSB_RVDC32(DSPBBASE);
10555c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPBSURF);
10565c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPBSURF);
10575c49fd3aSAlan Cox 				PSB_RVDC32(DSPBSURF);
10585c49fd3aSAlan Cox 			}
10595c49fd3aSAlan Cox 			if (arg->subpicture_disable_mask & REGRWBITS_DSPCCNTR) {
10605c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCCNTR);
10615c49fd3aSAlan Cox 				temp &= ~DISPPLANE_PIXFORMAT_MASK;
10625c49fd3aSAlan Cox 				temp |= DISPPLANE_32BPP_NO_ALPHA;
10635c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCCNTR);
10645c49fd3aSAlan Cox 
10655c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCBASE);
10665c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCBASE);
10675c49fd3aSAlan Cox 				PSB_RVDC32(DSPCBASE);
10685c49fd3aSAlan Cox 				temp =  PSB_RVDC32(DSPCSURF);
10695c49fd3aSAlan Cox 				PSB_WVDC32(temp, DSPCSURF);
10705c49fd3aSAlan Cox 				PSB_RVDC32(DSPCSURF);
10715c49fd3aSAlan Cox 			}
10725c49fd3aSAlan Cox 			gma_power_end(dev);
10735c49fd3aSAlan Cox 		}
10745c49fd3aSAlan Cox 	}
10755c49fd3aSAlan Cox 
10765c49fd3aSAlan Cox 	return 0;
10775c49fd3aSAlan Cox }
10785c49fd3aSAlan Cox 
10795c49fd3aSAlan Cox static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
10805c49fd3aSAlan Cox {
10815c49fd3aSAlan Cox 	return 0;
10825c49fd3aSAlan Cox }
10835c49fd3aSAlan Cox 
10845c49fd3aSAlan Cox static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
10855c49fd3aSAlan Cox {
10865c49fd3aSAlan Cox }
10875c49fd3aSAlan Cox 
10885c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
10895c49fd3aSAlan Cox 			       unsigned long arg)
10905c49fd3aSAlan Cox {
10915c49fd3aSAlan Cox 	struct drm_file *file_priv = filp->private_data;
10925c49fd3aSAlan Cox 	struct drm_device *dev = file_priv->minor->dev;
10935c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
10945c49fd3aSAlan Cox 	static unsigned int runtime_allowed;
10955c49fd3aSAlan Cox 
10965c49fd3aSAlan Cox 	if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
10975c49fd3aSAlan Cox 		runtime_allowed++;
10985c49fd3aSAlan Cox 		pm_runtime_allow(&dev->pdev->dev);
10995c49fd3aSAlan Cox 		dev_priv->rpm_enabled = 1;
11005c49fd3aSAlan Cox 	}
11015c49fd3aSAlan Cox 	return drm_ioctl(filp, cmd, arg);
11025c49fd3aSAlan Cox 	/* FIXME: do we need to wrap the other side of this */
11035c49fd3aSAlan Cox }
11045c49fd3aSAlan Cox 
11055c49fd3aSAlan Cox 
11065c49fd3aSAlan Cox /* When a client dies:
11075c49fd3aSAlan Cox  *    - Check for and clean up flipped page state
11085c49fd3aSAlan Cox  */
11095c49fd3aSAlan Cox void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
11105c49fd3aSAlan Cox {
11115c49fd3aSAlan Cox }
11125c49fd3aSAlan Cox 
11135c49fd3aSAlan Cox static void psb_remove(struct pci_dev *pdev)
11145c49fd3aSAlan Cox {
11155c49fd3aSAlan Cox 	struct drm_device *dev = pci_get_drvdata(pdev);
11165c49fd3aSAlan Cox 	drm_put_dev(dev);
11175c49fd3aSAlan Cox }
11185c49fd3aSAlan Cox 
11195c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = {
11205c49fd3aSAlan Cox 	.resume = gma_power_resume,
11215c49fd3aSAlan Cox 	.suspend = gma_power_suspend,
11225c49fd3aSAlan Cox 	.runtime_suspend = psb_runtime_suspend,
11235c49fd3aSAlan Cox 	.runtime_resume = psb_runtime_resume,
11245c49fd3aSAlan Cox 	.runtime_idle = psb_runtime_idle,
11255c49fd3aSAlan Cox };
11265c49fd3aSAlan Cox 
11275c49fd3aSAlan Cox static struct vm_operations_struct psb_gem_vm_ops = {
11285c49fd3aSAlan Cox 	.fault = psb_gem_fault,
11295c49fd3aSAlan Cox 	.open = drm_gem_vm_open,
11305c49fd3aSAlan Cox 	.close = drm_gem_vm_close,
11315c49fd3aSAlan Cox };
11325c49fd3aSAlan Cox 
11335c49fd3aSAlan Cox static struct drm_driver driver = {
11345c49fd3aSAlan Cox 	.driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
11355c49fd3aSAlan Cox 			   DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
11365c49fd3aSAlan Cox 	.load = psb_driver_load,
11375c49fd3aSAlan Cox 	.unload = psb_driver_unload,
11385c49fd3aSAlan Cox 
11395c49fd3aSAlan Cox 	.ioctls = psb_ioctls,
11405c49fd3aSAlan Cox 	.num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
11415c49fd3aSAlan Cox 	.device_is_agp = psb_driver_device_is_agp,
11425c49fd3aSAlan Cox 	.irq_preinstall = psb_irq_preinstall,
11435c49fd3aSAlan Cox 	.irq_postinstall = psb_irq_postinstall,
11445c49fd3aSAlan Cox 	.irq_uninstall = psb_irq_uninstall,
11455c49fd3aSAlan Cox 	.irq_handler = psb_irq_handler,
11465c49fd3aSAlan Cox 	.enable_vblank = psb_enable_vblank,
11475c49fd3aSAlan Cox 	.disable_vblank = psb_disable_vblank,
11485c49fd3aSAlan Cox 	.get_vblank_counter = psb_get_vblank_counter,
11495c49fd3aSAlan Cox 	.lastclose = psb_lastclose,
11505c49fd3aSAlan Cox 	.open = psb_driver_open,
11515c49fd3aSAlan Cox 	.preclose = psb_driver_preclose,
11525c49fd3aSAlan Cox 	.postclose = psb_driver_close,
11535c49fd3aSAlan Cox 	.reclaim_buffers = drm_core_reclaim_buffers,
11545c49fd3aSAlan Cox 
11555c49fd3aSAlan Cox 	.gem_init_object = psb_gem_init_object,
11565c49fd3aSAlan Cox 	.gem_free_object = psb_gem_free_object,
11575c49fd3aSAlan Cox 	.gem_vm_ops = &psb_gem_vm_ops,
11585c49fd3aSAlan Cox 	.dumb_create = psb_gem_dumb_create,
11595c49fd3aSAlan Cox 	.dumb_map_offset = psb_gem_dumb_map_gtt,
11605c49fd3aSAlan Cox 	.dumb_destroy = psb_gem_dumb_destroy,
11615c49fd3aSAlan Cox 
11625c49fd3aSAlan Cox 	.fops = {
11635c49fd3aSAlan Cox 		 .owner = THIS_MODULE,
11645c49fd3aSAlan Cox 		 .open = drm_open,
11655c49fd3aSAlan Cox 		 .release = drm_release,
11665c49fd3aSAlan Cox 		 .unlocked_ioctl = psb_unlocked_ioctl,
11675c49fd3aSAlan Cox 		 .mmap = drm_gem_mmap,
11685c49fd3aSAlan Cox 		 .poll = drm_poll,
11695c49fd3aSAlan Cox 		 .fasync = drm_fasync,
11705c49fd3aSAlan Cox 		 .read = drm_read,
11715c49fd3aSAlan Cox 	 },
11725c49fd3aSAlan Cox 	.name = DRIVER_NAME,
11735c49fd3aSAlan Cox 	.desc = DRIVER_DESC,
11745c49fd3aSAlan Cox 	.date = PSB_DRM_DRIVER_DATE,
11755c49fd3aSAlan Cox 	.major = PSB_DRM_DRIVER_MAJOR,
11765c49fd3aSAlan Cox 	.minor = PSB_DRM_DRIVER_MINOR,
11775c49fd3aSAlan Cox 	.patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
11785c49fd3aSAlan Cox };
11795c49fd3aSAlan Cox 
11805c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = {
11815c49fd3aSAlan Cox 	.name = DRIVER_NAME,
11825c49fd3aSAlan Cox 	.id_table = pciidlist,
11835c49fd3aSAlan Cox 	.probe = psb_probe,
11845c49fd3aSAlan Cox 	.remove = psb_remove,
11855c49fd3aSAlan Cox 	.driver.pm = &psb_pm_ops,
11865c49fd3aSAlan Cox };
11875c49fd3aSAlan Cox 
11885c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11895c49fd3aSAlan Cox {
11905c49fd3aSAlan Cox 	/* MLD Added this from Inaky's patch */
11915c49fd3aSAlan Cox 	if (pci_enable_msi(pdev))
11925c49fd3aSAlan Cox 		dev_warn(&pdev->dev, "Enable MSI failed!\n");
11935c49fd3aSAlan Cox 	return drm_get_pci_dev(pdev, ent, &driver);
11945c49fd3aSAlan Cox }
11955c49fd3aSAlan Cox 
11965c49fd3aSAlan Cox static int __init psb_init(void)
11975c49fd3aSAlan Cox {
11985c49fd3aSAlan Cox 	return drm_pci_init(&driver, &psb_pci_driver);
11995c49fd3aSAlan Cox }
12005c49fd3aSAlan Cox 
12015c49fd3aSAlan Cox static void __exit psb_exit(void)
12025c49fd3aSAlan Cox {
12035c49fd3aSAlan Cox 	drm_pci_exit(&driver, &psb_pci_driver);
12045c49fd3aSAlan Cox }
12055c49fd3aSAlan Cox 
12065c49fd3aSAlan Cox late_initcall(psb_init);
12075c49fd3aSAlan Cox module_exit(psb_exit);
12085c49fd3aSAlan Cox 
12095c49fd3aSAlan Cox MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
12105c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC);
12115c49fd3aSAlan Cox MODULE_LICENSE("GPL");
1212