blob: 1680a543cc6f6bc3ef50410caaa0e9457e136f06 [file] [log] [blame]
Alan Cox5c49fd32011-11-03 18:22:04 +00001/**************************************************************************
2 * Copyright (c) 2007-2011, Intel Corporation.
3 * All Rights Reserved.
4 * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA.
5 * All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 **************************************************************************/
21
22#include <drm/drmP.h>
23#include <drm/drm.h>
Alan Cox838fa582011-11-16 22:39:45 +000024#include "gma_drm.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000025#include "psb_drv.h"
26#include "framebuffer.h"
27#include "psb_reg.h"
28#include "psb_intel_reg.h"
29#include "intel_bios.h"
30#include "mid_bios.h"
31#include <drm/drm_pciids.h>
32#include "power.h"
33#include <linux/cpu.h>
34#include <linux/notifier.h>
35#include <linux/spinlock.h>
36#include <linux/pm_runtime.h>
37#include <acpi/video.h>
Dave Airlieaf3a2cf2011-11-16 12:13:30 +000038#include <linux/module.h>
Alan Cox5c49fd32011-11-03 18:22:04 +000039
40static int drm_psb_trap_pagefaults;
41
Alan Cox5c49fd32011-11-03 18:22:04 +000042static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
43
Alan Cox5c49fd32011-11-03 18:22:04 +000044MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults");
Alan Cox5c49fd32011-11-03 18:22:04 +000045module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600);
46
47
48static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
49 { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
50 { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
Alan Cox0cecdd82011-12-19 21:06:35 +000051#if defined(CONFIG_DRM_GMA600)
Alan Cox5c49fd32011-11-03 18:22:04 +000052 { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
53 { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
54 { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
55 { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
56 { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
57 { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
58 { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
59 { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
Alan Cox56125db2011-12-28 15:16:07 +000060 /* Atom E620 */
61 { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
Alan Cox5c49fd32011-11-03 18:22:04 +000062#endif
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000063#if defined(CONFIG_DRM_MEDFIELD)
64 {0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
65 {0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
66 {0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
67 {0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
68 {0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
69 {0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
70 {0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
71 {0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
72#endif
Alan Coxb6195aa2011-12-29 14:37:03 +000073#if defined(CONFIG_DRM_GMA3600)
Alan Cox5c49fd32011-11-03 18:22:04 +000074 { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
75 { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
76 { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
77 { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
78 { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
79 { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
80 { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
81 { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
Alan Cox9aa65a22012-05-11 11:32:46 +010082 { 0x8086, 0x0be8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
83 { 0x8086, 0x0be9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
84 { 0x8086, 0x0bea, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
85 { 0x8086, 0x0beb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
86 { 0x8086, 0x0bec, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
87 { 0x8086, 0x0bed, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
88 { 0x8086, 0x0bee, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
89 { 0x8086, 0x0bef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
Alan Cox5c49fd32011-11-03 18:22:04 +000090#endif
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +000091 { 0, }
Alan Cox5c49fd32011-11-03 18:22:04 +000092};
93MODULE_DEVICE_TABLE(pci, pciidlist);
94
95/*
96 * Standard IOCTLs.
97 */
98
Kirill A. Shutemov670c0442012-03-08 16:04:32 +000099#define DRM_IOCTL_GMA_ADB \
Alan Cox770179d2011-11-16 22:39:18 +0000100 DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000101#define DRM_IOCTL_GMA_MODE_OPERATION \
Alan Cox770179d2011-11-16 22:39:18 +0000102 DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000103 struct drm_psb_mode_operation_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000104#define DRM_IOCTL_GMA_STOLEN_MEMORY \
Alan Cox770179d2011-11-16 22:39:18 +0000105 DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000106 struct drm_psb_stolen_memory_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000107#define DRM_IOCTL_GMA_GAMMA \
Alan Cox770179d2011-11-16 22:39:18 +0000108 DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000109 struct drm_psb_dpst_lut_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000110#define DRM_IOCTL_GMA_DPST_BL \
Alan Cox770179d2011-11-16 22:39:18 +0000111 DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000112 uint32_t)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000113#define DRM_IOCTL_GMA_GET_PIPE_FROM_CRTC_ID \
Alan Cox770179d2011-11-16 22:39:18 +0000114 DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000115 struct drm_psb_get_pipe_from_crtc_id_arg)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000116#define DRM_IOCTL_GMA_GEM_CREATE \
Alan Cox770179d2011-11-16 22:39:18 +0000117 DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000118 struct drm_psb_gem_create)
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000119#define DRM_IOCTL_GMA_GEM_MMAP \
Alan Cox770179d2011-11-16 22:39:18 +0000120 DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \
Alan Cox5c49fd32011-11-03 18:22:04 +0000121 struct drm_psb_gem_mmap)
122
Alan Cox5c49fd32011-11-03 18:22:04 +0000123static int psb_adb_ioctl(struct drm_device *dev, void *data,
124 struct drm_file *file_priv);
125static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
126 struct drm_file *file_priv);
127static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
128 struct drm_file *file_priv);
Alan Cox5c49fd32011-11-03 18:22:04 +0000129static int psb_gamma_ioctl(struct drm_device *dev, void *data,
130 struct drm_file *file_priv);
131static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
132 struct drm_file *file_priv);
133
Alan Cox5c49fd32011-11-03 18:22:04 +0000134static struct drm_ioctl_desc psb_ioctls[] = {
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000135 DRM_IOCTL_DEF_DRV(GMA_ADB, psb_adb_ioctl, DRM_AUTH),
136 DRM_IOCTL_DEF_DRV(GMA_MODE_OPERATION, psb_mode_operation_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000137 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000138 DRM_IOCTL_DEF_DRV(GMA_STOLEN_MEMORY, psb_stolen_memory_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000139 DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000140 DRM_IOCTL_DEF_DRV(GMA_GAMMA, psb_gamma_ioctl, DRM_AUTH),
141 DRM_IOCTL_DEF_DRV(GMA_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
142 DRM_IOCTL_DEF_DRV(GMA_GET_PIPE_FROM_CRTC_ID,
Alan Cox5c49fd32011-11-03 18:22:04 +0000143 psb_intel_get_pipe_from_crtc_id, 0),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000144 DRM_IOCTL_DEF_DRV(GMA_GEM_CREATE, psb_gem_create_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000145 DRM_UNLOCKED | DRM_AUTH),
Kirill A. Shutemov670c0442012-03-08 16:04:32 +0000146 DRM_IOCTL_DEF_DRV(GMA_GEM_MMAP, psb_gem_mmap_ioctl,
Alan Cox5c49fd32011-11-03 18:22:04 +0000147 DRM_UNLOCKED | DRM_AUTH),
148};
149
150static void psb_lastclose(struct drm_device *dev)
151{
152 return;
153}
154
155static void psb_do_takedown(struct drm_device *dev)
156{
Alan Cox5c49fd32011-11-03 18:22:04 +0000157}
158
159static int psb_do_init(struct drm_device *dev)
160{
161 struct drm_psb_private *dev_priv = dev->dev_private;
162 struct psb_gtt *pg = &dev_priv->gtt;
163
164 uint32_t stolen_gtt;
165
166 int ret = -ENOMEM;
167
168 if (pg->mmu_gatt_start & 0x0FFFFFFF) {
169 dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
170 ret = -EINVAL;
171 goto out_err;
172 }
173
174
175 stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
176 stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
177 stolen_gtt =
178 (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
179
180 dev_priv->gatt_free_offset = pg->mmu_gatt_start +
181 (stolen_gtt << PAGE_SHIFT) * 1024;
182
Alan Cox5c49fd32011-11-03 18:22:04 +0000183 spin_lock_init(&dev_priv->irqmask_lock);
Alan Cox9242fe22011-11-29 22:27:10 +0000184 spin_lock_init(&dev_priv->lock_2d);
Alan Cox5c49fd32011-11-03 18:22:04 +0000185
186 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
187 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
188 PSB_RSGX32(PSB_CR_BIF_BANK1);
189 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
190 PSB_CR_BIF_CTRL);
191 psb_spank(dev_priv);
192
193 /* mmu_gatt ?? */
194 PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
195 return 0;
196out_err:
197 psb_do_takedown(dev);
198 return ret;
199}
200
201static int psb_driver_unload(struct drm_device *dev)
202{
203 struct drm_psb_private *dev_priv = dev->dev_private;
204
205 /* Kill vblank etc here */
206
207 gma_backlight_exit(dev);
Alan Coxf9f23a72011-12-29 14:38:07 +0000208 psb_modeset_cleanup(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000209
210 if (dev_priv) {
Alan Coxd839ede2012-05-03 15:06:18 +0100211 psb_intel_opregion_fini(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000212 psb_lid_timer_takedown(dev_priv);
Alan Cox5c49fd32011-11-03 18:22:04 +0000213
214 if (dev_priv->ops->chip_teardown)
215 dev_priv->ops->chip_teardown(dev);
216 psb_do_takedown(dev);
217
218
219 if (dev_priv->pf_pd) {
220 psb_mmu_free_pagedir(dev_priv->pf_pd);
221 dev_priv->pf_pd = NULL;
222 }
223 if (dev_priv->mmu) {
224 struct psb_gtt *pg = &dev_priv->gtt;
225
226 down_read(&pg->sem);
227 psb_mmu_remove_pfn_sequence(
228 psb_mmu_get_default_pd
229 (dev_priv->mmu),
230 pg->mmu_gatt_start,
231 dev_priv->vram_stolen_size >> PAGE_SHIFT);
232 up_read(&pg->sem);
233 psb_mmu_driver_takedown(dev_priv->mmu);
234 dev_priv->mmu = NULL;
235 }
236 psb_gtt_takedown(dev);
237 if (dev_priv->scratch_page) {
Alan Cox18963442012-04-25 14:36:13 +0100238 set_pages_wb(dev_priv->scratch_page, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000239 __free_page(dev_priv->scratch_page);
240 dev_priv->scratch_page = NULL;
241 }
242 if (dev_priv->vdc_reg) {
243 iounmap(dev_priv->vdc_reg);
244 dev_priv->vdc_reg = NULL;
245 }
246 if (dev_priv->sgx_reg) {
247 iounmap(dev_priv->sgx_reg);
248 dev_priv->sgx_reg = NULL;
249 }
250
251 kfree(dev_priv);
252 dev->dev_private = NULL;
253
254 /*destroy VBT data*/
255 psb_intel_destroy_bios(dev);
256 }
257
258 gma_power_uninit(dev);
259
260 return 0;
261}
262
263
264static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
265{
266 struct drm_psb_private *dev_priv;
267 unsigned long resource_start;
Alan Cox5c49fd32011-11-03 18:22:04 +0000268 unsigned long irqflags;
269 int ret = -ENOMEM;
Alan Cox5c49fd32011-11-03 18:22:04 +0000270 struct drm_connector *connector;
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000271 struct psb_intel_encoder *psb_intel_encoder;
Alan Cox5c49fd32011-11-03 18:22:04 +0000272
273 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
274 if (dev_priv == NULL)
275 return -ENOMEM;
276
277 dev_priv->ops = (struct psb_ops *)chipset;
278 dev_priv->dev = dev;
279 dev->dev_private = (void *) dev_priv;
280
Dave Airlie466e69b2011-12-19 11:15:29 +0000281 pci_set_master(dev->pdev);
282
Patrik Jakobsson84b08fe2011-11-29 22:20:20 +0000283 if (!IS_PSB(dev)) {
284 if (pci_enable_msi(dev->pdev))
285 dev_warn(dev->dev, "Enabling MSI failed!\n");
286 }
287
Alan Cox5c49fd32011-11-03 18:22:04 +0000288 dev_priv->num_pipe = dev_priv->ops->pipes;
289
290 resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
291
292 dev_priv->vdc_reg =
293 ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
294 if (!dev_priv->vdc_reg)
295 goto out_err;
296
297 dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
298 PSB_SGX_SIZE);
299 if (!dev_priv->sgx_reg)
300 goto out_err;
301
Alan Coxd839ede2012-05-03 15:06:18 +0100302 psb_intel_opregion_setup(dev);
303
Alan Cox5c49fd32011-11-03 18:22:04 +0000304 ret = dev_priv->ops->chip_setup(dev);
305 if (ret)
306 goto out_err;
307
308 /* Init OSPM support */
309 gma_power_init(dev);
310
311 ret = -ENOMEM;
312
313 dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
314 if (!dev_priv->scratch_page)
315 goto out_err;
316
317 set_pages_uc(dev_priv->scratch_page, 1);
318
319 ret = psb_gtt_init(dev, 0);
320 if (ret)
321 goto out_err;
322
323 dev_priv->mmu = psb_mmu_driver_init((void *)0,
324 drm_psb_trap_pagefaults, 0,
325 dev_priv);
326 if (!dev_priv->mmu)
327 goto out_err;
328
Alan Cox5c49fd32011-11-03 18:22:04 +0000329 dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
330 if (!dev_priv->pf_pd)
331 goto out_err;
332
333 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
334 psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
335
336 ret = psb_do_init(dev);
337 if (ret)
338 return ret;
339
340 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
341 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
342
Alan Coxd839ede2012-05-03 15:06:18 +0100343 acpi_video_register();
Alan Cox25933dd2012-05-03 15:07:13 +0100344 if (dev_priv->opregion.lid_state)
Alan Cox5c49fd32011-11-03 18:22:04 +0000345 psb_lid_timer_init(dev_priv);
346
347 ret = drm_vblank_init(dev, dev_priv->num_pipe);
348 if (ret)
349 goto out_err;
350
351 /*
352 * Install interrupt handlers prior to powering off SGX or else we will
353 * crash.
354 */
355 dev_priv->vdc_irq_mask = 0;
356 dev_priv->pipestat[0] = 0;
357 dev_priv->pipestat[1] = 0;
358 dev_priv->pipestat[2] = 0;
359 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
360 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
361 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
362 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
363 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
Patrik Jakobssone036ba52011-11-29 22:20:07 +0000364 if (IS_PSB(dev) && drm_core_check_feature(dev, DRIVER_MODESET))
Alan Cox5c49fd32011-11-03 18:22:04 +0000365 drm_irq_install(dev);
366
367 dev->vblank_disable_allowed = 1;
368
369 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
370
371 dev->driver->get_vblank_counter = psb_get_vblank_counter;
372
Alan Coxf9f23a72011-12-29 14:38:07 +0000373 psb_modeset_init(dev);
374 psb_fbdev_init(dev);
375 drm_kms_helper_poll_init(dev);
Alan Cox5c49fd32011-11-03 18:22:04 +0000376
377 /* Only add backlight support if we have LVDS output */
378 list_for_each_entry(connector, &dev->mode_config.connector_list,
379 head) {
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000380 psb_intel_encoder = psb_intel_attached_encoder(connector);
Alan Cox5c49fd32011-11-03 18:22:04 +0000381
Patrik Jakobsson1730f892011-12-19 21:40:33 +0000382 switch (psb_intel_encoder->type) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000383 case INTEL_OUTPUT_LVDS:
384 case INTEL_OUTPUT_MIPI:
385 ret = gma_backlight_init(dev);
386 break;
387 }
388 }
389
390 if (ret)
391 return ret;
392#if 0
393 /*enable runtime pm at last*/
394 pm_runtime_enable(&dev->pdev->dev);
395 pm_runtime_set_active(&dev->pdev->dev);
396#endif
397 /*Intel drm driver load is done, continue doing pvr load*/
398 return 0;
399out_err:
400 psb_driver_unload(dev);
401 return ret;
402}
403
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000404static int psb_driver_device_is_agp(struct drm_device *dev)
Alan Cox5c49fd32011-11-03 18:22:04 +0000405{
406 return 0;
407}
408
Alan Cox5c49fd32011-11-03 18:22:04 +0000409static inline void get_brightness(struct backlight_device *bd)
410{
411#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
412 if (bd) {
413 bd->props.brightness = bd->ops->get_brightness(bd);
414 backlight_update_status(bd);
415 }
416#endif
417}
418
419static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
420 struct drm_file *file_priv)
421{
422 struct drm_psb_private *dev_priv = psb_priv(dev);
423 uint32_t *arg = data;
424
425 dev_priv->blc_adj2 = *arg;
426 get_brightness(dev_priv->backlight_device);
427 return 0;
428}
429
430static int psb_adb_ioctl(struct drm_device *dev, void *data,
431 struct drm_file *file_priv)
432{
433 struct drm_psb_private *dev_priv = psb_priv(dev);
434 uint32_t *arg = data;
435
436 dev_priv->blc_adj1 = *arg;
437 get_brightness(dev_priv->backlight_device);
438 return 0;
439}
440
Alan Cox5c49fd32011-11-03 18:22:04 +0000441static int psb_gamma_ioctl(struct drm_device *dev, void *data,
442 struct drm_file *file_priv)
443{
444 struct drm_psb_dpst_lut_arg *lut_arg = data;
445 struct drm_mode_object *obj;
446 struct drm_crtc *crtc;
447 struct drm_connector *connector;
448 struct psb_intel_crtc *psb_intel_crtc;
449 int i = 0;
450 int32_t obj_id;
451
452 obj_id = lut_arg->output_id;
453 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
454 if (!obj) {
455 dev_dbg(dev->dev, "Invalid Connector object.\n");
456 return -EINVAL;
457 }
458
459 connector = obj_to_connector(obj);
460 crtc = connector->encoder->crtc;
461 psb_intel_crtc = to_psb_intel_crtc(crtc);
462
463 for (i = 0; i < 256; i++)
464 psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
465
466 psb_intel_crtc_load_lut(crtc);
467
468 return 0;
469}
470
471static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
472 struct drm_file *file_priv)
473{
474 uint32_t obj_id;
475 uint16_t op;
476 struct drm_mode_modeinfo *umode;
477 struct drm_display_mode *mode = NULL;
478 struct drm_psb_mode_operation_arg *arg;
479 struct drm_mode_object *obj;
480 struct drm_connector *connector;
Alan Cox5c49fd32011-11-03 18:22:04 +0000481 struct drm_connector_helper_funcs *connector_funcs;
482 int ret = 0;
483 int resp = MODE_OK;
Alan Cox5c49fd32011-11-03 18:22:04 +0000484
485 arg = (struct drm_psb_mode_operation_arg *)data;
486 obj_id = arg->obj_id;
487 op = arg->operation;
488
489 switch (op) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000490 case PSB_MODE_OPERATION_MODE_VALID:
491 umode = &arg->mode;
492
493 mutex_lock(&dev->mode_config.mutex);
494
495 obj = drm_mode_object_find(dev, obj_id,
496 DRM_MODE_OBJECT_CONNECTOR);
497 if (!obj) {
498 ret = -EINVAL;
499 goto mode_op_out;
500 }
501
502 connector = obj_to_connector(obj);
503
504 mode = drm_mode_create(dev);
505 if (!mode) {
506 ret = -ENOMEM;
507 goto mode_op_out;
508 }
509
510 /* drm_crtc_convert_umode(mode, umode); */
511 {
512 mode->clock = umode->clock;
513 mode->hdisplay = umode->hdisplay;
514 mode->hsync_start = umode->hsync_start;
515 mode->hsync_end = umode->hsync_end;
516 mode->htotal = umode->htotal;
517 mode->hskew = umode->hskew;
518 mode->vdisplay = umode->vdisplay;
519 mode->vsync_start = umode->vsync_start;
520 mode->vsync_end = umode->vsync_end;
521 mode->vtotal = umode->vtotal;
522 mode->vscan = umode->vscan;
523 mode->vrefresh = umode->vrefresh;
524 mode->flags = umode->flags;
525 mode->type = umode->type;
526 strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
527 mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
528 }
529
530 connector_funcs = (struct drm_connector_helper_funcs *)
531 connector->helper_private;
532
533 if (connector_funcs->mode_valid) {
534 resp = connector_funcs->mode_valid(connector, mode);
Alan Cox61bedf72011-11-16 22:38:42 +0000535 arg->data = resp;
Alan Cox5c49fd32011-11-03 18:22:04 +0000536 }
537
538 /*do some clean up work*/
539 if (mode)
540 drm_mode_destroy(dev, mode);
541mode_op_out:
542 mutex_unlock(&dev->mode_config.mutex);
543 return ret;
544
545 default:
546 dev_dbg(dev->dev, "Unsupported psb mode operation\n");
547 return -EOPNOTSUPP;
548 }
549
550 return 0;
551}
552
553static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
554 struct drm_file *file_priv)
555{
556 struct drm_psb_private *dev_priv = psb_priv(dev);
557 struct drm_psb_stolen_memory_arg *arg = data;
558
559 arg->base = dev_priv->stolen_base;
560 arg->size = dev_priv->vram_stolen_size;
561
562 return 0;
563}
564
Alan Cox5c49fd32011-11-03 18:22:04 +0000565static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
566{
567 return 0;
568}
569
570static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
571{
572}
573
574static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
575 unsigned long arg)
576{
577 struct drm_file *file_priv = filp->private_data;
578 struct drm_device *dev = file_priv->minor->dev;
579 struct drm_psb_private *dev_priv = dev->dev_private;
580 static unsigned int runtime_allowed;
581
582 if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
583 runtime_allowed++;
584 pm_runtime_allow(&dev->pdev->dev);
585 dev_priv->rpm_enabled = 1;
586 }
587 return drm_ioctl(filp, cmd, arg);
588 /* FIXME: do we need to wrap the other side of this */
589}
590
591
592/* When a client dies:
593 * - Check for and clean up flipped page state
594 */
Kirill A. Shutemov15308e22012-03-08 16:08:45 +0000595static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
Alan Cox5c49fd32011-11-03 18:22:04 +0000596{
597}
598
599static void psb_remove(struct pci_dev *pdev)
600{
601 struct drm_device *dev = pci_get_drvdata(pdev);
602 drm_put_dev(dev);
603}
604
605static const struct dev_pm_ops psb_pm_ops = {
606 .resume = gma_power_resume,
607 .suspend = gma_power_suspend,
608 .runtime_suspend = psb_runtime_suspend,
609 .runtime_resume = psb_runtime_resume,
610 .runtime_idle = psb_runtime_idle,
611};
612
613static struct vm_operations_struct psb_gem_vm_ops = {
614 .fault = psb_gem_fault,
615 .open = drm_gem_vm_open,
616 .close = drm_gem_vm_close,
617};
618
Ilija Hadzic1595c562011-11-27 11:08:33 -0500619static const struct file_operations psb_gem_fops = {
620 .owner = THIS_MODULE,
621 .open = drm_open,
622 .release = drm_release,
623 .unlocked_ioctl = psb_unlocked_ioctl,
624 .mmap = drm_gem_mmap,
625 .poll = drm_poll,
626 .fasync = drm_fasync,
627 .read = drm_read,
628};
629
Alan Cox5c49fd32011-11-03 18:22:04 +0000630static struct drm_driver driver = {
631 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
632 DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
633 .load = psb_driver_load,
634 .unload = psb_driver_unload,
635
636 .ioctls = psb_ioctls,
637 .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
638 .device_is_agp = psb_driver_device_is_agp,
639 .irq_preinstall = psb_irq_preinstall,
640 .irq_postinstall = psb_irq_postinstall,
641 .irq_uninstall = psb_irq_uninstall,
642 .irq_handler = psb_irq_handler,
643 .enable_vblank = psb_enable_vblank,
644 .disable_vblank = psb_disable_vblank,
645 .get_vblank_counter = psb_get_vblank_counter,
646 .lastclose = psb_lastclose,
647 .open = psb_driver_open,
648 .preclose = psb_driver_preclose,
649 .postclose = psb_driver_close,
650 .reclaim_buffers = drm_core_reclaim_buffers,
651
652 .gem_init_object = psb_gem_init_object,
653 .gem_free_object = psb_gem_free_object,
654 .gem_vm_ops = &psb_gem_vm_ops,
655 .dumb_create = psb_gem_dumb_create,
656 .dumb_map_offset = psb_gem_dumb_map_gtt,
657 .dumb_destroy = psb_gem_dumb_destroy,
Ilija Hadzic1595c562011-11-27 11:08:33 -0500658 .fops = &psb_gem_fops,
Alan Cox5c49fd32011-11-03 18:22:04 +0000659 .name = DRIVER_NAME,
660 .desc = DRIVER_DESC,
661 .date = PSB_DRM_DRIVER_DATE,
662 .major = PSB_DRM_DRIVER_MAJOR,
663 .minor = PSB_DRM_DRIVER_MINOR,
664 .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
665};
666
667static struct pci_driver psb_pci_driver = {
668 .name = DRIVER_NAME,
669 .id_table = pciidlist,
670 .probe = psb_probe,
671 .remove = psb_remove,
Kirill A. Shutemovaa53f532012-03-08 16:09:19 +0000672 .driver = {
673 .pm = &psb_pm_ops,
674 }
Alan Cox5c49fd32011-11-03 18:22:04 +0000675};
676
677static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
678{
Alan Cox5c49fd32011-11-03 18:22:04 +0000679 return drm_get_pci_dev(pdev, ent, &driver);
680}
681
682static int __init psb_init(void)
683{
684 return drm_pci_init(&driver, &psb_pci_driver);
685}
686
687static void __exit psb_exit(void)
688{
689 drm_pci_exit(&driver, &psb_pci_driver);
690}
691
692late_initcall(psb_init);
693module_exit(psb_exit);
694
695MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
696MODULE_DESCRIPTION(DRIVER_DESC);
697MODULE_LICENSE("GPL");