xref: /openbmc/linux/drivers/gpu/drm/gma500/psb_drv.c (revision 026abc333205c1fff80138b8c2cac3d0347685f4)
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>
24838fa588SAlan Cox #include "gma_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>
38af3a2cfbSDave Airlie #include <linux/module.h>
395c49fd3aSAlan Cox 
405c49fd3aSAlan Cox static int drm_psb_trap_pagefaults;
415c49fd3aSAlan Cox 
425c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
435c49fd3aSAlan Cox 
445c49fd3aSAlan Cox MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults");
455c49fd3aSAlan Cox module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600);
465c49fd3aSAlan Cox 
475c49fd3aSAlan Cox 
485c49fd3aSAlan Cox static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
495c49fd3aSAlan Cox 	{ 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
505c49fd3aSAlan Cox 	{ 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
510cecdd81SAlan Cox #if defined(CONFIG_DRM_GMA600)
525c49fd3aSAlan Cox 	{ 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
535c49fd3aSAlan Cox 	{ 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
545c49fd3aSAlan Cox 	{ 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
555c49fd3aSAlan Cox 	{ 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
565c49fd3aSAlan Cox 	{ 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
575c49fd3aSAlan Cox 	{ 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
585c49fd3aSAlan Cox 	{ 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
595c49fd3aSAlan Cox 	{ 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
6056125db1SAlan Cox 	/* Atom E620 */
6156125db1SAlan Cox 	{ 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
625c49fd3aSAlan Cox #endif
63*026abc33SKirill A. Shutemov #if defined(CONFIG_DRM_MEDFIELD)
64*026abc33SKirill A. Shutemov 	{0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
65*026abc33SKirill A. Shutemov 	{0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
66*026abc33SKirill A. Shutemov 	{0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
67*026abc33SKirill A. Shutemov 	{0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
68*026abc33SKirill A. Shutemov 	{0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
69*026abc33SKirill A. Shutemov 	{0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
70*026abc33SKirill A. Shutemov 	{0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
71*026abc33SKirill A. Shutemov 	{0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
72*026abc33SKirill A. Shutemov #endif
73b6195aabSAlan Cox #if defined(CONFIG_DRM_GMA3600)
745c49fd3aSAlan Cox 	{ 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
755c49fd3aSAlan Cox 	{ 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
765c49fd3aSAlan Cox 	{ 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
775c49fd3aSAlan Cox 	{ 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
785c49fd3aSAlan Cox 	{ 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
795c49fd3aSAlan Cox 	{ 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
805c49fd3aSAlan Cox 	{ 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
815c49fd3aSAlan Cox 	{ 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
825c49fd3aSAlan Cox #endif
835c49fd3aSAlan Cox 	{ 0, 0, 0}
845c49fd3aSAlan Cox };
855c49fd3aSAlan Cox MODULE_DEVICE_TABLE(pci, pciidlist);
865c49fd3aSAlan Cox 
875c49fd3aSAlan Cox /*
885c49fd3aSAlan Cox  * Standard IOCTLs.
895c49fd3aSAlan Cox  */
905c49fd3aSAlan Cox 
915c49fd3aSAlan Cox #define DRM_IOCTL_PSB_ADB	\
92770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t)
935c49fd3aSAlan Cox #define DRM_IOCTL_PSB_MODE_OPERATION	\
94770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \
955c49fd3aSAlan Cox 			 struct drm_psb_mode_operation_arg)
965c49fd3aSAlan Cox #define DRM_IOCTL_PSB_STOLEN_MEMORY	\
97770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \
985c49fd3aSAlan Cox 			 struct drm_psb_stolen_memory_arg)
995c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GAMMA	\
100770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \
1015c49fd3aSAlan Cox 			 struct drm_psb_dpst_lut_arg)
1025c49fd3aSAlan Cox #define DRM_IOCTL_PSB_DPST_BL	\
103770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \
1045c49fd3aSAlan Cox 			 uint32_t)
1055c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID	\
106770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
1075c49fd3aSAlan Cox 			 struct drm_psb_get_pipe_from_crtc_id_arg)
1085c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_CREATE	\
109770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \
1105c49fd3aSAlan Cox 			 struct drm_psb_gem_create)
1115c49fd3aSAlan Cox #define DRM_IOCTL_PSB_GEM_MMAP	\
112770179d5SAlan Cox 		DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \
1135c49fd3aSAlan Cox 			 struct drm_psb_gem_mmap)
1145c49fd3aSAlan Cox 
1155c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data,
1165c49fd3aSAlan Cox 			 struct drm_file *file_priv);
1175c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
1185c49fd3aSAlan Cox 				    struct drm_file *file_priv);
1195c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
1205c49fd3aSAlan Cox 				   struct drm_file *file_priv);
1215c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data,
1225c49fd3aSAlan Cox 			   struct drm_file *file_priv);
1235c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
1245c49fd3aSAlan Cox 			     struct drm_file *file_priv);
1255c49fd3aSAlan Cox 
1265c49fd3aSAlan Cox #define PSB_IOCTL_DEF(ioctl, func, flags) \
1275c49fd3aSAlan Cox 	[DRM_IOCTL_NR(ioctl) - DRM_COMMAND_BASE] = {ioctl, flags, func}
1285c49fd3aSAlan Cox 
1295c49fd3aSAlan Cox static struct drm_ioctl_desc psb_ioctls[] = {
1305c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_ADB, psb_adb_ioctl, DRM_AUTH),
1315c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_MODE_OPERATION, psb_mode_operation_ioctl,
1325c49fd3aSAlan Cox 		      DRM_AUTH),
1335c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_STOLEN_MEMORY, psb_stolen_memory_ioctl,
1345c49fd3aSAlan Cox 		      DRM_AUTH),
1355c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA, psb_gamma_ioctl, DRM_AUTH),
1365c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
1375c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID,
1385c49fd3aSAlan Cox 					psb_intel_get_pipe_from_crtc_id, 0),
1395c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_CREATE, psb_gem_create_ioctl,
1405c49fd3aSAlan Cox 						DRM_UNLOCKED | DRM_AUTH),
1415c49fd3aSAlan Cox 	PSB_IOCTL_DEF(DRM_IOCTL_PSB_GEM_MMAP, psb_gem_mmap_ioctl,
1425c49fd3aSAlan Cox 						DRM_UNLOCKED | DRM_AUTH),
1435c49fd3aSAlan Cox };
1445c49fd3aSAlan Cox 
1455c49fd3aSAlan Cox static void psb_lastclose(struct drm_device *dev)
1465c49fd3aSAlan Cox {
1475c49fd3aSAlan Cox 	return;
1485c49fd3aSAlan Cox }
1495c49fd3aSAlan Cox 
1505c49fd3aSAlan Cox static void psb_do_takedown(struct drm_device *dev)
1515c49fd3aSAlan Cox {
1525c49fd3aSAlan Cox }
1535c49fd3aSAlan Cox 
1545c49fd3aSAlan Cox static int psb_do_init(struct drm_device *dev)
1555c49fd3aSAlan Cox {
1565c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
1575c49fd3aSAlan Cox 	struct psb_gtt *pg = &dev_priv->gtt;
1585c49fd3aSAlan Cox 
1595c49fd3aSAlan Cox 	uint32_t stolen_gtt;
1605c49fd3aSAlan Cox 
1615c49fd3aSAlan Cox 	int ret = -ENOMEM;
1625c49fd3aSAlan Cox 
1635c49fd3aSAlan Cox 	if (pg->mmu_gatt_start & 0x0FFFFFFF) {
1645c49fd3aSAlan Cox 		dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
1655c49fd3aSAlan Cox 		ret = -EINVAL;
1665c49fd3aSAlan Cox 		goto out_err;
1675c49fd3aSAlan Cox 	}
1685c49fd3aSAlan Cox 
1695c49fd3aSAlan Cox 
1705c49fd3aSAlan Cox 	stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
1715c49fd3aSAlan Cox 	stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
1725c49fd3aSAlan Cox 	stolen_gtt =
1735c49fd3aSAlan Cox 	    (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
1745c49fd3aSAlan Cox 
1755c49fd3aSAlan Cox 	dev_priv->gatt_free_offset = pg->mmu_gatt_start +
1765c49fd3aSAlan Cox 	    (stolen_gtt << PAGE_SHIFT) * 1024;
1775c49fd3aSAlan Cox 
1785c49fd3aSAlan Cox 	if (1 || drm_debug) {
1795c49fd3aSAlan Cox 		uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID);
1805c49fd3aSAlan Cox 		uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION);
1815c49fd3aSAlan Cox 		DRM_INFO("SGX core id = 0x%08x\n", core_id);
1825c49fd3aSAlan Cox 		DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n",
1835c49fd3aSAlan Cox 			 (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >>
1845c49fd3aSAlan Cox 			 _PSB_CC_REVISION_MAJOR_SHIFT,
1855c49fd3aSAlan Cox 			 (core_rev & _PSB_CC_REVISION_MINOR_MASK) >>
1865c49fd3aSAlan Cox 			 _PSB_CC_REVISION_MINOR_SHIFT);
1875c49fd3aSAlan Cox 		DRM_INFO
1885c49fd3aSAlan Cox 		    ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n",
1895c49fd3aSAlan Cox 		     (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >>
1905c49fd3aSAlan Cox 		     _PSB_CC_REVISION_MAINTENANCE_SHIFT,
1915c49fd3aSAlan Cox 		     (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >>
1925c49fd3aSAlan Cox 		     _PSB_CC_REVISION_DESIGNER_SHIFT);
1935c49fd3aSAlan Cox 	}
1945c49fd3aSAlan Cox 
1955c49fd3aSAlan Cox 
1965c49fd3aSAlan Cox 	spin_lock_init(&dev_priv->irqmask_lock);
1979242fe23SAlan Cox 	spin_lock_init(&dev_priv->lock_2d);
1985c49fd3aSAlan Cox 
1995c49fd3aSAlan Cox 	PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
2005c49fd3aSAlan Cox 	PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
2015c49fd3aSAlan Cox 	PSB_RSGX32(PSB_CR_BIF_BANK1);
2025c49fd3aSAlan Cox 	PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
2035c49fd3aSAlan Cox 							PSB_CR_BIF_CTRL);
2045c49fd3aSAlan Cox 	psb_spank(dev_priv);
2055c49fd3aSAlan Cox 
2065c49fd3aSAlan Cox 	/* mmu_gatt ?? */
2075c49fd3aSAlan Cox 	PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
2085c49fd3aSAlan Cox 	return 0;
2095c49fd3aSAlan Cox out_err:
2105c49fd3aSAlan Cox 	psb_do_takedown(dev);
2115c49fd3aSAlan Cox 	return ret;
2125c49fd3aSAlan Cox }
2135c49fd3aSAlan Cox 
2145c49fd3aSAlan Cox static int psb_driver_unload(struct drm_device *dev)
2155c49fd3aSAlan Cox {
2165c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
2175c49fd3aSAlan Cox 
2185c49fd3aSAlan Cox 	/* Kill vblank etc here */
2195c49fd3aSAlan Cox 
2205c49fd3aSAlan Cox 	gma_backlight_exit(dev);
2215c49fd3aSAlan Cox 
2225c49fd3aSAlan Cox 	psb_modeset_cleanup(dev);
2235c49fd3aSAlan Cox 
2245c49fd3aSAlan Cox 	if (dev_priv) {
2255c49fd3aSAlan Cox 		psb_lid_timer_takedown(dev_priv);
2265c49fd3aSAlan Cox 		gma_intel_opregion_exit(dev);
2275c49fd3aSAlan Cox 
2285c49fd3aSAlan Cox 		if (dev_priv->ops->chip_teardown)
2295c49fd3aSAlan Cox 			dev_priv->ops->chip_teardown(dev);
2305c49fd3aSAlan Cox 		psb_do_takedown(dev);
2315c49fd3aSAlan Cox 
2325c49fd3aSAlan Cox 
2335c49fd3aSAlan Cox 		if (dev_priv->pf_pd) {
2345c49fd3aSAlan Cox 			psb_mmu_free_pagedir(dev_priv->pf_pd);
2355c49fd3aSAlan Cox 			dev_priv->pf_pd = NULL;
2365c49fd3aSAlan Cox 		}
2375c49fd3aSAlan Cox 		if (dev_priv->mmu) {
2385c49fd3aSAlan Cox 			struct psb_gtt *pg = &dev_priv->gtt;
2395c49fd3aSAlan Cox 
2405c49fd3aSAlan Cox 			down_read(&pg->sem);
2415c49fd3aSAlan Cox 			psb_mmu_remove_pfn_sequence(
2425c49fd3aSAlan Cox 				psb_mmu_get_default_pd
2435c49fd3aSAlan Cox 				(dev_priv->mmu),
2445c49fd3aSAlan Cox 				pg->mmu_gatt_start,
2455c49fd3aSAlan Cox 				dev_priv->vram_stolen_size >> PAGE_SHIFT);
2465c49fd3aSAlan Cox 			up_read(&pg->sem);
2475c49fd3aSAlan Cox 			psb_mmu_driver_takedown(dev_priv->mmu);
2485c49fd3aSAlan Cox 			dev_priv->mmu = NULL;
2495c49fd3aSAlan Cox 		}
2505c49fd3aSAlan Cox 		psb_gtt_takedown(dev);
2515c49fd3aSAlan Cox 		if (dev_priv->scratch_page) {
2525c49fd3aSAlan Cox 			__free_page(dev_priv->scratch_page);
2535c49fd3aSAlan Cox 			dev_priv->scratch_page = NULL;
2545c49fd3aSAlan Cox 		}
2555c49fd3aSAlan Cox 		if (dev_priv->vdc_reg) {
2565c49fd3aSAlan Cox 			iounmap(dev_priv->vdc_reg);
2575c49fd3aSAlan Cox 			dev_priv->vdc_reg = NULL;
2585c49fd3aSAlan Cox 		}
2595c49fd3aSAlan Cox 		if (dev_priv->sgx_reg) {
2605c49fd3aSAlan Cox 			iounmap(dev_priv->sgx_reg);
2615c49fd3aSAlan Cox 			dev_priv->sgx_reg = NULL;
2625c49fd3aSAlan Cox 		}
2635c49fd3aSAlan Cox 
2645c49fd3aSAlan Cox 		kfree(dev_priv);
2655c49fd3aSAlan Cox 		dev->dev_private = NULL;
2665c49fd3aSAlan Cox 
2675c49fd3aSAlan Cox 		/*destroy VBT data*/
2685c49fd3aSAlan Cox 		psb_intel_destroy_bios(dev);
2695c49fd3aSAlan Cox 	}
2705c49fd3aSAlan Cox 
2715c49fd3aSAlan Cox 	gma_power_uninit(dev);
2725c49fd3aSAlan Cox 
2735c49fd3aSAlan Cox 	return 0;
2745c49fd3aSAlan Cox }
2755c49fd3aSAlan Cox 
2765c49fd3aSAlan Cox 
2775c49fd3aSAlan Cox static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
2785c49fd3aSAlan Cox {
2795c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv;
2805c49fd3aSAlan Cox 	unsigned long resource_start;
2815c49fd3aSAlan Cox 	struct psb_gtt *pg;
2825c49fd3aSAlan Cox 	unsigned long irqflags;
2835c49fd3aSAlan Cox 	int ret = -ENOMEM;
2845c49fd3aSAlan Cox 	uint32_t tt_pages;
2855c49fd3aSAlan Cox 	struct drm_connector *connector;
2861730f89bSPatrik Jakobsson 	struct psb_intel_encoder *psb_intel_encoder;
2875c49fd3aSAlan Cox 
2885c49fd3aSAlan Cox 	dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
2895c49fd3aSAlan Cox 	if (dev_priv == NULL)
2905c49fd3aSAlan Cox 		return -ENOMEM;
2915c49fd3aSAlan Cox 
2925c49fd3aSAlan Cox 	dev_priv->ops = (struct psb_ops *)chipset;
2935c49fd3aSAlan Cox 	dev_priv->dev = dev;
2945c49fd3aSAlan Cox 	dev->dev_private = (void *) dev_priv;
2955c49fd3aSAlan Cox 
296466e69b8SDave Airlie 	pci_set_master(dev->pdev);
297466e69b8SDave Airlie 
29884b08fe6SPatrik Jakobsson 	if (!IS_PSB(dev)) {
29984b08fe6SPatrik Jakobsson 		if (pci_enable_msi(dev->pdev))
30084b08fe6SPatrik Jakobsson 			dev_warn(dev->dev, "Enabling MSI failed!\n");
30184b08fe6SPatrik Jakobsson 	}
30284b08fe6SPatrik Jakobsson 
3035c49fd3aSAlan Cox 	dev_priv->num_pipe = dev_priv->ops->pipes;
3045c49fd3aSAlan Cox 
3055c49fd3aSAlan Cox 	resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
3065c49fd3aSAlan Cox 
3075c49fd3aSAlan Cox 	dev_priv->vdc_reg =
3085c49fd3aSAlan Cox 	    ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
3095c49fd3aSAlan Cox 	if (!dev_priv->vdc_reg)
3105c49fd3aSAlan Cox 		goto out_err;
3115c49fd3aSAlan Cox 
3125c49fd3aSAlan Cox 	dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
3135c49fd3aSAlan Cox 							PSB_SGX_SIZE);
3145c49fd3aSAlan Cox 	if (!dev_priv->sgx_reg)
3155c49fd3aSAlan Cox 		goto out_err;
3165c49fd3aSAlan Cox 
3175c49fd3aSAlan Cox 	ret = dev_priv->ops->chip_setup(dev);
3185c49fd3aSAlan Cox 	if (ret)
3195c49fd3aSAlan Cox 		goto out_err;
3205c49fd3aSAlan Cox 
3215c49fd3aSAlan Cox 	/* Init OSPM support */
3225c49fd3aSAlan Cox 	gma_power_init(dev);
3235c49fd3aSAlan Cox 
3245c49fd3aSAlan Cox 	ret = -ENOMEM;
3255c49fd3aSAlan Cox 
3265c49fd3aSAlan Cox 	dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
3275c49fd3aSAlan Cox 	if (!dev_priv->scratch_page)
3285c49fd3aSAlan Cox 		goto out_err;
3295c49fd3aSAlan Cox 
3305c49fd3aSAlan Cox 	set_pages_uc(dev_priv->scratch_page, 1);
3315c49fd3aSAlan Cox 
3325c49fd3aSAlan Cox 	ret = psb_gtt_init(dev, 0);
3335c49fd3aSAlan Cox 	if (ret)
3345c49fd3aSAlan Cox 		goto out_err;
3355c49fd3aSAlan Cox 
3365c49fd3aSAlan Cox 	dev_priv->mmu = psb_mmu_driver_init((void *)0,
3375c49fd3aSAlan Cox 					drm_psb_trap_pagefaults, 0,
3385c49fd3aSAlan Cox 					dev_priv);
3395c49fd3aSAlan Cox 	if (!dev_priv->mmu)
3405c49fd3aSAlan Cox 		goto out_err;
3415c49fd3aSAlan Cox 
3425c49fd3aSAlan Cox 	pg = &dev_priv->gtt;
3435c49fd3aSAlan Cox 
3445c49fd3aSAlan Cox 	tt_pages = (pg->gatt_pages < PSB_TT_PRIV0_PLIMIT) ?
3455c49fd3aSAlan Cox 		(pg->gatt_pages) : PSB_TT_PRIV0_PLIMIT;
3465c49fd3aSAlan Cox 
3475c49fd3aSAlan Cox 
3485c49fd3aSAlan Cox 	dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
3495c49fd3aSAlan Cox 	if (!dev_priv->pf_pd)
3505c49fd3aSAlan Cox 		goto out_err;
3515c49fd3aSAlan Cox 
3525c49fd3aSAlan Cox 	psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
3535c49fd3aSAlan Cox 	psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
3545c49fd3aSAlan Cox 
3555c49fd3aSAlan Cox 	ret = psb_do_init(dev);
3565c49fd3aSAlan Cox 	if (ret)
3575c49fd3aSAlan Cox 		return ret;
3585c49fd3aSAlan Cox 
3595c49fd3aSAlan Cox 	PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
3605c49fd3aSAlan Cox 	PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
3615c49fd3aSAlan Cox 
3625c49fd3aSAlan Cox /*	igd_opregion_init(&dev_priv->opregion_dev); */
3635c49fd3aSAlan Cox 	acpi_video_register();
3645c49fd3aSAlan Cox 	if (dev_priv->lid_state)
3655c49fd3aSAlan Cox 		psb_lid_timer_init(dev_priv);
3665c49fd3aSAlan Cox 
3675c49fd3aSAlan Cox 	ret = drm_vblank_init(dev, dev_priv->num_pipe);
3685c49fd3aSAlan Cox 	if (ret)
3695c49fd3aSAlan Cox 		goto out_err;
3705c49fd3aSAlan Cox 
3715c49fd3aSAlan Cox 	/*
3725c49fd3aSAlan Cox 	 * Install interrupt handlers prior to powering off SGX or else we will
3735c49fd3aSAlan Cox 	 * crash.
3745c49fd3aSAlan Cox 	 */
3755c49fd3aSAlan Cox 	dev_priv->vdc_irq_mask = 0;
3765c49fd3aSAlan Cox 	dev_priv->pipestat[0] = 0;
3775c49fd3aSAlan Cox 	dev_priv->pipestat[1] = 0;
3785c49fd3aSAlan Cox 	dev_priv->pipestat[2] = 0;
3795c49fd3aSAlan Cox 	spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
3805c49fd3aSAlan Cox 	PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
3815c49fd3aSAlan Cox 	PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
3825c49fd3aSAlan Cox 	PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
3835c49fd3aSAlan Cox 	spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
384e036ba59SPatrik Jakobsson 	if (IS_PSB(dev) && drm_core_check_feature(dev, DRIVER_MODESET))
3855c49fd3aSAlan Cox 		drm_irq_install(dev);
3865c49fd3aSAlan Cox 
3875c49fd3aSAlan Cox 	dev->vblank_disable_allowed = 1;
3885c49fd3aSAlan Cox 
3895c49fd3aSAlan Cox 	dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
3905c49fd3aSAlan Cox 
3915c49fd3aSAlan Cox 	dev->driver->get_vblank_counter = psb_get_vblank_counter;
3925c49fd3aSAlan Cox 
3935c49fd3aSAlan Cox 	psb_modeset_init(dev);
3945c49fd3aSAlan Cox 	psb_fbdev_init(dev);
3955c49fd3aSAlan Cox 	drm_kms_helper_poll_init(dev);
3965c49fd3aSAlan Cox 
3975c49fd3aSAlan Cox 	/* Only add backlight support if we have LVDS output */
3985c49fd3aSAlan Cox 	list_for_each_entry(connector, &dev->mode_config.connector_list,
3995c49fd3aSAlan Cox 			    head) {
4001730f89bSPatrik Jakobsson 		psb_intel_encoder = psb_intel_attached_encoder(connector);
4015c49fd3aSAlan Cox 
4021730f89bSPatrik Jakobsson 		switch (psb_intel_encoder->type) {
4035c49fd3aSAlan Cox 		case INTEL_OUTPUT_LVDS:
4045c49fd3aSAlan Cox 		case INTEL_OUTPUT_MIPI:
4055c49fd3aSAlan Cox 			ret = gma_backlight_init(dev);
4065c49fd3aSAlan Cox 			break;
4075c49fd3aSAlan Cox 		}
4085c49fd3aSAlan Cox 	}
4095c49fd3aSAlan Cox 
4105c49fd3aSAlan Cox 	if (ret)
4115c49fd3aSAlan Cox 		return ret;
4125c49fd3aSAlan Cox #if 0
4135c49fd3aSAlan Cox 	/*enable runtime pm at last*/
4145c49fd3aSAlan Cox 	pm_runtime_enable(&dev->pdev->dev);
4155c49fd3aSAlan Cox 	pm_runtime_set_active(&dev->pdev->dev);
4165c49fd3aSAlan Cox #endif
4175c49fd3aSAlan Cox 	/*Intel drm driver load is done, continue doing pvr load*/
4185c49fd3aSAlan Cox 	return 0;
4195c49fd3aSAlan Cox out_err:
4205c49fd3aSAlan Cox 	psb_driver_unload(dev);
4215c49fd3aSAlan Cox 	return ret;
4225c49fd3aSAlan Cox }
4235c49fd3aSAlan Cox 
4245c49fd3aSAlan Cox int psb_driver_device_is_agp(struct drm_device *dev)
4255c49fd3aSAlan Cox {
4265c49fd3aSAlan Cox 	return 0;
4275c49fd3aSAlan Cox }
4285c49fd3aSAlan Cox 
4295c49fd3aSAlan Cox static inline void get_brightness(struct backlight_device *bd)
4305c49fd3aSAlan Cox {
4315c49fd3aSAlan Cox #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
4325c49fd3aSAlan Cox 	if (bd) {
4335c49fd3aSAlan Cox 		bd->props.brightness = bd->ops->get_brightness(bd);
4345c49fd3aSAlan Cox 		backlight_update_status(bd);
4355c49fd3aSAlan Cox 	}
4365c49fd3aSAlan Cox #endif
4375c49fd3aSAlan Cox }
4385c49fd3aSAlan Cox 
4395c49fd3aSAlan Cox static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
4405c49fd3aSAlan Cox 		       struct drm_file *file_priv)
4415c49fd3aSAlan Cox {
4425c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
4435c49fd3aSAlan Cox 	uint32_t *arg = data;
4445c49fd3aSAlan Cox 
4455c49fd3aSAlan Cox 	dev_priv->blc_adj2 = *arg;
4465c49fd3aSAlan Cox 	get_brightness(dev_priv->backlight_device);
4475c49fd3aSAlan Cox 	return 0;
4485c49fd3aSAlan Cox }
4495c49fd3aSAlan Cox 
4505c49fd3aSAlan Cox static int psb_adb_ioctl(struct drm_device *dev, void *data,
4515c49fd3aSAlan Cox 			struct drm_file *file_priv)
4525c49fd3aSAlan Cox {
4535c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
4545c49fd3aSAlan Cox 	uint32_t *arg = data;
4555c49fd3aSAlan Cox 
4565c49fd3aSAlan Cox 	dev_priv->blc_adj1 = *arg;
4575c49fd3aSAlan Cox 	get_brightness(dev_priv->backlight_device);
4585c49fd3aSAlan Cox 	return 0;
4595c49fd3aSAlan Cox }
4605c49fd3aSAlan Cox 
4615c49fd3aSAlan Cox static int psb_gamma_ioctl(struct drm_device *dev, void *data,
4625c49fd3aSAlan Cox 			   struct drm_file *file_priv)
4635c49fd3aSAlan Cox {
4645c49fd3aSAlan Cox 	struct drm_psb_dpst_lut_arg *lut_arg = data;
4655c49fd3aSAlan Cox 	struct drm_mode_object *obj;
4665c49fd3aSAlan Cox 	struct drm_crtc *crtc;
4675c49fd3aSAlan Cox 	struct drm_connector *connector;
4685c49fd3aSAlan Cox 	struct psb_intel_crtc *psb_intel_crtc;
4695c49fd3aSAlan Cox 	int i = 0;
4705c49fd3aSAlan Cox 	int32_t obj_id;
4715c49fd3aSAlan Cox 
4725c49fd3aSAlan Cox 	obj_id = lut_arg->output_id;
4735c49fd3aSAlan Cox 	obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
4745c49fd3aSAlan Cox 	if (!obj) {
4755c49fd3aSAlan Cox 		dev_dbg(dev->dev, "Invalid Connector object.\n");
4765c49fd3aSAlan Cox 		return -EINVAL;
4775c49fd3aSAlan Cox 	}
4785c49fd3aSAlan Cox 
4795c49fd3aSAlan Cox 	connector = obj_to_connector(obj);
4805c49fd3aSAlan Cox 	crtc = connector->encoder->crtc;
4815c49fd3aSAlan Cox 	psb_intel_crtc = to_psb_intel_crtc(crtc);
4825c49fd3aSAlan Cox 
4835c49fd3aSAlan Cox 	for (i = 0; i < 256; i++)
4845c49fd3aSAlan Cox 		psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
4855c49fd3aSAlan Cox 
4865c49fd3aSAlan Cox 	psb_intel_crtc_load_lut(crtc);
4875c49fd3aSAlan Cox 
4885c49fd3aSAlan Cox 	return 0;
4895c49fd3aSAlan Cox }
4905c49fd3aSAlan Cox 
4915c49fd3aSAlan Cox static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
4925c49fd3aSAlan Cox 				struct drm_file *file_priv)
4935c49fd3aSAlan Cox {
4945c49fd3aSAlan Cox 	uint32_t obj_id;
4955c49fd3aSAlan Cox 	uint16_t op;
4965c49fd3aSAlan Cox 	struct drm_mode_modeinfo *umode;
4975c49fd3aSAlan Cox 	struct drm_display_mode *mode = NULL;
4985c49fd3aSAlan Cox 	struct drm_psb_mode_operation_arg *arg;
4995c49fd3aSAlan Cox 	struct drm_mode_object *obj;
5005c49fd3aSAlan Cox 	struct drm_connector *connector;
5015c49fd3aSAlan Cox 	struct drm_connector_helper_funcs *connector_funcs;
5025c49fd3aSAlan Cox 	int ret = 0;
5035c49fd3aSAlan Cox 	int resp = MODE_OK;
5045c49fd3aSAlan Cox 
5055c49fd3aSAlan Cox 	arg = (struct drm_psb_mode_operation_arg *)data;
5065c49fd3aSAlan Cox 	obj_id = arg->obj_id;
5075c49fd3aSAlan Cox 	op = arg->operation;
5085c49fd3aSAlan Cox 
5095c49fd3aSAlan Cox 	switch (op) {
5105c49fd3aSAlan Cox 	case PSB_MODE_OPERATION_MODE_VALID:
5115c49fd3aSAlan Cox 		umode = &arg->mode;
5125c49fd3aSAlan Cox 
5135c49fd3aSAlan Cox 		mutex_lock(&dev->mode_config.mutex);
5145c49fd3aSAlan Cox 
5155c49fd3aSAlan Cox 		obj = drm_mode_object_find(dev, obj_id,
5165c49fd3aSAlan Cox 					DRM_MODE_OBJECT_CONNECTOR);
5175c49fd3aSAlan Cox 		if (!obj) {
5185c49fd3aSAlan Cox 			ret = -EINVAL;
5195c49fd3aSAlan Cox 			goto mode_op_out;
5205c49fd3aSAlan Cox 		}
5215c49fd3aSAlan Cox 
5225c49fd3aSAlan Cox 		connector = obj_to_connector(obj);
5235c49fd3aSAlan Cox 
5245c49fd3aSAlan Cox 		mode = drm_mode_create(dev);
5255c49fd3aSAlan Cox 		if (!mode) {
5265c49fd3aSAlan Cox 			ret = -ENOMEM;
5275c49fd3aSAlan Cox 			goto mode_op_out;
5285c49fd3aSAlan Cox 		}
5295c49fd3aSAlan Cox 
5305c49fd3aSAlan Cox 		/* drm_crtc_convert_umode(mode, umode); */
5315c49fd3aSAlan Cox 		{
5325c49fd3aSAlan Cox 			mode->clock = umode->clock;
5335c49fd3aSAlan Cox 			mode->hdisplay = umode->hdisplay;
5345c49fd3aSAlan Cox 			mode->hsync_start = umode->hsync_start;
5355c49fd3aSAlan Cox 			mode->hsync_end = umode->hsync_end;
5365c49fd3aSAlan Cox 			mode->htotal = umode->htotal;
5375c49fd3aSAlan Cox 			mode->hskew = umode->hskew;
5385c49fd3aSAlan Cox 			mode->vdisplay = umode->vdisplay;
5395c49fd3aSAlan Cox 			mode->vsync_start = umode->vsync_start;
5405c49fd3aSAlan Cox 			mode->vsync_end = umode->vsync_end;
5415c49fd3aSAlan Cox 			mode->vtotal = umode->vtotal;
5425c49fd3aSAlan Cox 			mode->vscan = umode->vscan;
5435c49fd3aSAlan Cox 			mode->vrefresh = umode->vrefresh;
5445c49fd3aSAlan Cox 			mode->flags = umode->flags;
5455c49fd3aSAlan Cox 			mode->type = umode->type;
5465c49fd3aSAlan Cox 			strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
5475c49fd3aSAlan Cox 			mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
5485c49fd3aSAlan Cox 		}
5495c49fd3aSAlan Cox 
5505c49fd3aSAlan Cox 		connector_funcs = (struct drm_connector_helper_funcs *)
5515c49fd3aSAlan Cox 				   connector->helper_private;
5525c49fd3aSAlan Cox 
5535c49fd3aSAlan Cox 		if (connector_funcs->mode_valid) {
5545c49fd3aSAlan Cox 			resp = connector_funcs->mode_valid(connector, mode);
55561bedf70SAlan Cox 			arg->data = resp;
5565c49fd3aSAlan Cox 		}
5575c49fd3aSAlan Cox 
5585c49fd3aSAlan Cox 		/*do some clean up work*/
5595c49fd3aSAlan Cox 		if (mode)
5605c49fd3aSAlan Cox 			drm_mode_destroy(dev, mode);
5615c49fd3aSAlan Cox mode_op_out:
5625c49fd3aSAlan Cox 		mutex_unlock(&dev->mode_config.mutex);
5635c49fd3aSAlan Cox 		return ret;
5645c49fd3aSAlan Cox 
5655c49fd3aSAlan Cox 	default:
5665c49fd3aSAlan Cox 		dev_dbg(dev->dev, "Unsupported psb mode operation\n");
5675c49fd3aSAlan Cox 		return -EOPNOTSUPP;
5685c49fd3aSAlan Cox 	}
5695c49fd3aSAlan Cox 
5705c49fd3aSAlan Cox 	return 0;
5715c49fd3aSAlan Cox }
5725c49fd3aSAlan Cox 
5735c49fd3aSAlan Cox static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
5745c49fd3aSAlan Cox 				   struct drm_file *file_priv)
5755c49fd3aSAlan Cox {
5765c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = psb_priv(dev);
5775c49fd3aSAlan Cox 	struct drm_psb_stolen_memory_arg *arg = data;
5785c49fd3aSAlan Cox 
5795c49fd3aSAlan Cox 	arg->base = dev_priv->stolen_base;
5805c49fd3aSAlan Cox 	arg->size = dev_priv->vram_stolen_size;
5815c49fd3aSAlan Cox 
5825c49fd3aSAlan Cox 	return 0;
5835c49fd3aSAlan Cox }
5845c49fd3aSAlan Cox 
5855c49fd3aSAlan Cox static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
5865c49fd3aSAlan Cox {
5875c49fd3aSAlan Cox 	return 0;
5885c49fd3aSAlan Cox }
5895c49fd3aSAlan Cox 
5905c49fd3aSAlan Cox static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
5915c49fd3aSAlan Cox {
5925c49fd3aSAlan Cox }
5935c49fd3aSAlan Cox 
5945c49fd3aSAlan Cox static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
5955c49fd3aSAlan Cox 			       unsigned long arg)
5965c49fd3aSAlan Cox {
5975c49fd3aSAlan Cox 	struct drm_file *file_priv = filp->private_data;
5985c49fd3aSAlan Cox 	struct drm_device *dev = file_priv->minor->dev;
5995c49fd3aSAlan Cox 	struct drm_psb_private *dev_priv = dev->dev_private;
6005c49fd3aSAlan Cox 	static unsigned int runtime_allowed;
6015c49fd3aSAlan Cox 
6025c49fd3aSAlan Cox 	if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
6035c49fd3aSAlan Cox 		runtime_allowed++;
6045c49fd3aSAlan Cox 		pm_runtime_allow(&dev->pdev->dev);
6055c49fd3aSAlan Cox 		dev_priv->rpm_enabled = 1;
6065c49fd3aSAlan Cox 	}
6075c49fd3aSAlan Cox 	return drm_ioctl(filp, cmd, arg);
6085c49fd3aSAlan Cox 	/* FIXME: do we need to wrap the other side of this */
6095c49fd3aSAlan Cox }
6105c49fd3aSAlan Cox 
6115c49fd3aSAlan Cox 
6125c49fd3aSAlan Cox /* When a client dies:
6135c49fd3aSAlan Cox  *    - Check for and clean up flipped page state
6145c49fd3aSAlan Cox  */
6155c49fd3aSAlan Cox void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
6165c49fd3aSAlan Cox {
6175c49fd3aSAlan Cox }
6185c49fd3aSAlan Cox 
6195c49fd3aSAlan Cox static void psb_remove(struct pci_dev *pdev)
6205c49fd3aSAlan Cox {
6215c49fd3aSAlan Cox 	struct drm_device *dev = pci_get_drvdata(pdev);
6225c49fd3aSAlan Cox 	drm_put_dev(dev);
6235c49fd3aSAlan Cox }
6245c49fd3aSAlan Cox 
6255c49fd3aSAlan Cox static const struct dev_pm_ops psb_pm_ops = {
6265c49fd3aSAlan Cox 	.resume = gma_power_resume,
6275c49fd3aSAlan Cox 	.suspend = gma_power_suspend,
6285c49fd3aSAlan Cox 	.runtime_suspend = psb_runtime_suspend,
6295c49fd3aSAlan Cox 	.runtime_resume = psb_runtime_resume,
6305c49fd3aSAlan Cox 	.runtime_idle = psb_runtime_idle,
6315c49fd3aSAlan Cox };
6325c49fd3aSAlan Cox 
6335c49fd3aSAlan Cox static struct vm_operations_struct psb_gem_vm_ops = {
6345c49fd3aSAlan Cox 	.fault = psb_gem_fault,
6355c49fd3aSAlan Cox 	.open = drm_gem_vm_open,
6365c49fd3aSAlan Cox 	.close = drm_gem_vm_close,
6375c49fd3aSAlan Cox };
6385c49fd3aSAlan Cox 
6391595c568SIlija Hadzic static const struct file_operations psb_gem_fops = {
6401595c568SIlija Hadzic 	.owner = THIS_MODULE,
6411595c568SIlija Hadzic 	.open = drm_open,
6421595c568SIlija Hadzic 	.release = drm_release,
6431595c568SIlija Hadzic 	.unlocked_ioctl = psb_unlocked_ioctl,
6441595c568SIlija Hadzic 	.mmap = drm_gem_mmap,
6451595c568SIlija Hadzic 	.poll = drm_poll,
6461595c568SIlija Hadzic 	.fasync = drm_fasync,
6471595c568SIlija Hadzic 	.read = drm_read,
6481595c568SIlija Hadzic };
6491595c568SIlija Hadzic 
6505c49fd3aSAlan Cox static struct drm_driver driver = {
6515c49fd3aSAlan Cox 	.driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
6525c49fd3aSAlan Cox 			   DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
6535c49fd3aSAlan Cox 	.load = psb_driver_load,
6545c49fd3aSAlan Cox 	.unload = psb_driver_unload,
6555c49fd3aSAlan Cox 
6565c49fd3aSAlan Cox 	.ioctls = psb_ioctls,
6575c49fd3aSAlan Cox 	.num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
6585c49fd3aSAlan Cox 	.device_is_agp = psb_driver_device_is_agp,
6595c49fd3aSAlan Cox 	.irq_preinstall = psb_irq_preinstall,
6605c49fd3aSAlan Cox 	.irq_postinstall = psb_irq_postinstall,
6615c49fd3aSAlan Cox 	.irq_uninstall = psb_irq_uninstall,
6625c49fd3aSAlan Cox 	.irq_handler = psb_irq_handler,
6635c49fd3aSAlan Cox 	.enable_vblank = psb_enable_vblank,
6645c49fd3aSAlan Cox 	.disable_vblank = psb_disable_vblank,
6655c49fd3aSAlan Cox 	.get_vblank_counter = psb_get_vblank_counter,
6665c49fd3aSAlan Cox 	.lastclose = psb_lastclose,
6675c49fd3aSAlan Cox 	.open = psb_driver_open,
6685c49fd3aSAlan Cox 	.preclose = psb_driver_preclose,
6695c49fd3aSAlan Cox 	.postclose = psb_driver_close,
6705c49fd3aSAlan Cox 	.reclaim_buffers = drm_core_reclaim_buffers,
6715c49fd3aSAlan Cox 
6725c49fd3aSAlan Cox 	.gem_init_object = psb_gem_init_object,
6735c49fd3aSAlan Cox 	.gem_free_object = psb_gem_free_object,
6745c49fd3aSAlan Cox 	.gem_vm_ops = &psb_gem_vm_ops,
6755c49fd3aSAlan Cox 	.dumb_create = psb_gem_dumb_create,
6765c49fd3aSAlan Cox 	.dumb_map_offset = psb_gem_dumb_map_gtt,
6775c49fd3aSAlan Cox 	.dumb_destroy = psb_gem_dumb_destroy,
6781595c568SIlija Hadzic 	.fops = &psb_gem_fops,
6795c49fd3aSAlan Cox 	.name = DRIVER_NAME,
6805c49fd3aSAlan Cox 	.desc = DRIVER_DESC,
6815c49fd3aSAlan Cox 	.date = PSB_DRM_DRIVER_DATE,
6825c49fd3aSAlan Cox 	.major = PSB_DRM_DRIVER_MAJOR,
6835c49fd3aSAlan Cox 	.minor = PSB_DRM_DRIVER_MINOR,
6845c49fd3aSAlan Cox 	.patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
6855c49fd3aSAlan Cox };
6865c49fd3aSAlan Cox 
6875c49fd3aSAlan Cox static struct pci_driver psb_pci_driver = {
6885c49fd3aSAlan Cox 	.name = DRIVER_NAME,
6895c49fd3aSAlan Cox 	.id_table = pciidlist,
6905c49fd3aSAlan Cox 	.probe = psb_probe,
6915c49fd3aSAlan Cox 	.remove = psb_remove,
6925c49fd3aSAlan Cox 	.driver.pm = &psb_pm_ops,
6935c49fd3aSAlan Cox };
6945c49fd3aSAlan Cox 
6955c49fd3aSAlan Cox static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6965c49fd3aSAlan Cox {
6975c49fd3aSAlan Cox 	return drm_get_pci_dev(pdev, ent, &driver);
6985c49fd3aSAlan Cox }
6995c49fd3aSAlan Cox 
7005c49fd3aSAlan Cox static int __init psb_init(void)
7015c49fd3aSAlan Cox {
7025c49fd3aSAlan Cox 	return drm_pci_init(&driver, &psb_pci_driver);
7035c49fd3aSAlan Cox }
7045c49fd3aSAlan Cox 
7055c49fd3aSAlan Cox static void __exit psb_exit(void)
7065c49fd3aSAlan Cox {
7075c49fd3aSAlan Cox 	drm_pci_exit(&driver, &psb_pci_driver);
7085c49fd3aSAlan Cox }
7095c49fd3aSAlan Cox 
7105c49fd3aSAlan Cox late_initcall(psb_init);
7115c49fd3aSAlan Cox module_exit(psb_exit);
7125c49fd3aSAlan Cox 
7135c49fd3aSAlan Cox MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
7145c49fd3aSAlan Cox MODULE_DESCRIPTION(DRIVER_DESC);
7155c49fd3aSAlan Cox MODULE_LICENSE("GPL");
716