1 /**************************************************************************
2 * Copyright (c) 2007, Intel Corporation.
4 * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA.
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.
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
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.
20 **************************************************************************/
28 #include "psb_intel_reg.h"
29 #include "psb_intel_bios.h"
30 #include <drm/drm_pciids.h>
31 #include "psb_powermgmt.h"
32 #include <linux/cpu.h>
33 #include <linux/notifier.h>
34 #include <linux/spinlock.h>
35 #include <linux/pm_runtime.h>
36 #include <acpi/video.h>
39 static int drm_psb_trap_pagefaults
;
43 static int psb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
);
45 MODULE_PARM_DESC(debug
, "Enable debug output");
46 MODULE_PARM_DESC(no_fb
, "Disable FBdev");
47 MODULE_PARM_DESC(trap_pagefaults
, "Error and reset on MMU pagefaults");
48 module_param_named(debug
, drm_psb_debug
, int, 0600);
49 module_param_named(no_fb
, drm_psb_no_fb
, int, 0600);
50 module_param_named(trap_pagefaults
, drm_psb_trap_pagefaults
, int, 0600);
53 static struct pci_device_id pciidlist
[] = {
54 { 0x8086, 0x8108, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_PSB_8108
},
55 { 0x8086, 0x8109, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_PSB_8109
},
56 { 0x8086, 0x4100, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
57 { 0x8086, 0x4101, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
58 { 0x8086, 0x4102, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
59 { 0x8086, 0x4103, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
60 { 0x8086, 0x4104, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
61 { 0x8086, 0x4105, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
62 { 0x8086, 0x4106, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
63 { 0x8086, 0x4107, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, CHIP_MRST_4100
},
66 MODULE_DEVICE_TABLE(pci
, pciidlist
);
72 #define DRM_IOCTL_PSB_KMS_OFF \
73 DRM_IO(DRM_PSB_KMS_OFF + DRM_COMMAND_BASE)
74 #define DRM_IOCTL_PSB_KMS_ON \
75 DRM_IO(DRM_PSB_KMS_ON + DRM_COMMAND_BASE)
76 #define DRM_IOCTL_PSB_SIZES \
77 DRM_IOR(DRM_PSB_SIZES + DRM_COMMAND_BASE, \
78 struct drm_psb_sizes_arg)
79 #define DRM_IOCTL_PSB_FUSE_REG \
80 DRM_IOWR(DRM_PSB_FUSE_REG + DRM_COMMAND_BASE, uint32_t)
81 #define DRM_IOCTL_PSB_DC_STATE \
82 DRM_IOW(DRM_PSB_DC_STATE + DRM_COMMAND_BASE, \
83 struct drm_psb_dc_state_arg)
84 #define DRM_IOCTL_PSB_ADB \
85 DRM_IOWR(DRM_PSB_ADB + DRM_COMMAND_BASE, uint32_t)
86 #define DRM_IOCTL_PSB_MODE_OPERATION \
87 DRM_IOWR(DRM_PSB_MODE_OPERATION + DRM_COMMAND_BASE, \
88 struct drm_psb_mode_operation_arg)
89 #define DRM_IOCTL_PSB_STOLEN_MEMORY \
90 DRM_IOWR(DRM_PSB_STOLEN_MEMORY + DRM_COMMAND_BASE, \
91 struct drm_psb_stolen_memory_arg)
92 #define DRM_IOCTL_PSB_REGISTER_RW \
93 DRM_IOWR(DRM_PSB_REGISTER_RW + DRM_COMMAND_BASE, \
94 struct drm_psb_register_rw_arg)
95 #define DRM_IOCTL_PSB_DPST \
96 DRM_IOWR(DRM_PSB_DPST + DRM_COMMAND_BASE, \
98 #define DRM_IOCTL_PSB_GAMMA \
99 DRM_IOWR(DRM_PSB_GAMMA + DRM_COMMAND_BASE, \
100 struct drm_psb_dpst_lut_arg)
101 #define DRM_IOCTL_PSB_DPST_BL \
102 DRM_IOWR(DRM_PSB_DPST_BL + DRM_COMMAND_BASE, \
104 #define DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID \
105 DRM_IOWR(DRM_PSB_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
106 struct drm_psb_get_pipe_from_crtc_id_arg)
108 static int psb_sizes_ioctl(struct drm_device
*dev
, void *data
,
109 struct drm_file
*file_priv
);
110 static int psb_dc_state_ioctl(struct drm_device
*dev
, void * data
,
111 struct drm_file
*file_priv
);
112 static int psb_adb_ioctl(struct drm_device
*dev
, void *data
,
113 struct drm_file
*file_priv
);
114 static int psb_mode_operation_ioctl(struct drm_device
*dev
, void *data
,
115 struct drm_file
*file_priv
);
116 static int psb_stolen_memory_ioctl(struct drm_device
*dev
, void *data
,
117 struct drm_file
*file_priv
);
118 static int psb_register_rw_ioctl(struct drm_device
*dev
, void *data
,
119 struct drm_file
*file_priv
);
120 static int psb_dpst_ioctl(struct drm_device
*dev
, void *data
,
121 struct drm_file
*file_priv
);
122 static int psb_gamma_ioctl(struct drm_device
*dev
, void *data
,
123 struct drm_file
*file_priv
);
124 static int psb_dpst_bl_ioctl(struct drm_device
*dev
, void *data
,
125 struct drm_file
*file_priv
);
127 #define PSB_IOCTL_DEF(ioctl, func, flags) \
128 [DRM_IOCTL_NR(ioctl) - DRM_COMMAND_BASE] = {ioctl, flags, func}
130 static struct drm_ioctl_desc psb_ioctls
[] = {
131 PSB_IOCTL_DEF(DRM_IOCTL_PSB_KMS_OFF
, psbfb_kms_off_ioctl
,
133 PSB_IOCTL_DEF(DRM_IOCTL_PSB_KMS_ON
,
136 PSB_IOCTL_DEF(DRM_IOCTL_PSB_SIZES
, psb_sizes_ioctl
, DRM_AUTH
),
137 PSB_IOCTL_DEF(DRM_IOCTL_PSB_DC_STATE
, psb_dc_state_ioctl
, DRM_AUTH
),
138 PSB_IOCTL_DEF(DRM_IOCTL_PSB_ADB
, psb_adb_ioctl
, DRM_AUTH
),
139 PSB_IOCTL_DEF(DRM_IOCTL_PSB_MODE_OPERATION
, psb_mode_operation_ioctl
,
141 PSB_IOCTL_DEF(DRM_IOCTL_PSB_STOLEN_MEMORY
, psb_stolen_memory_ioctl
,
143 PSB_IOCTL_DEF(DRM_IOCTL_PSB_REGISTER_RW
, psb_register_rw_ioctl
,
145 PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST
, psb_dpst_ioctl
, DRM_AUTH
),
146 PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA
, psb_gamma_ioctl
, DRM_AUTH
),
147 PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL
, psb_dpst_bl_ioctl
, DRM_AUTH
),
148 PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID
,
149 psb_intel_get_pipe_from_crtc_id
, 0),
153 static void psb_lastclose(struct drm_device
*dev
)
158 static void psb_do_takedown(struct drm_device
*dev
)
160 /* FIXME: do we need to clean up the gtt here ? */
163 void mrst_get_fuse_settings(struct drm_device
*dev
)
165 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
166 struct pci_dev
*pci_root
= pci_get_bus_and_slot(0, 0);
167 uint32_t fuse_value
= 0;
168 uint32_t fuse_value_tmp
= 0;
170 #define FB_REG06 0xD0810600
171 #define FB_MIPI_DISABLE (1 << 11)
172 #define FB_REG09 0xD0810900
173 #define FB_REG09 0xD0810900
174 #define FB_SKU_MASK 0x7000
175 #define FB_SKU_SHIFT 12
177 #define FB_SKU_100L 1
179 pci_write_config_dword(pci_root
, 0xD0, FB_REG06
);
180 pci_read_config_dword(pci_root
, 0xD4, &fuse_value
);
182 dev_priv
->iLVDS_enable
= fuse_value
& FB_MIPI_DISABLE
;
184 DRM_INFO("internal display is %s\n",
185 dev_priv
->iLVDS_enable
? "LVDS display" : "MIPI display");
187 /*prevent Runtime suspend at start*/
188 if (dev_priv
->iLVDS_enable
) {
189 dev_priv
->is_lvds_on
= true;
190 dev_priv
->is_mipi_on
= false;
193 dev_priv
->is_mipi_on
= true;
194 dev_priv
->is_lvds_on
= false;
197 dev_priv
->video_device_fuse
= fuse_value
;
199 pci_write_config_dword(pci_root
, 0xD0, FB_REG09
);
200 pci_read_config_dword(pci_root
, 0xD4, &fuse_value
);
202 DRM_INFO("SKU values is 0x%x. \n", fuse_value
);
203 fuse_value_tmp
= (fuse_value
& FB_SKU_MASK
) >> FB_SKU_SHIFT
;
205 dev_priv
->fuse_reg_value
= fuse_value
;
207 switch (fuse_value_tmp
) {
209 dev_priv
->core_freq
= 200;
212 dev_priv
->core_freq
= 100;
215 dev_priv
->core_freq
= 166;
218 DRM_ERROR("Invalid SKU values, SKU value = 0x%08x\n", fuse_value_tmp
);
219 dev_priv
->core_freq
= 0;
221 DRM_INFO("LNC core clk is %dMHz.\n", dev_priv
->core_freq
);
222 pci_dev_put(pci_root
);
225 void mid_get_pci_revID (struct drm_psb_private
*dev_priv
)
227 uint32_t platform_rev_id
= 0;
228 struct pci_dev
*pci_gfx_root
= pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
230 /*get the revison ID, B0:D2:F0;0x08 */
231 pci_read_config_dword(pci_gfx_root
, 0x08, &platform_rev_id
);
232 dev_priv
->platform_rev_id
= (uint8_t) platform_rev_id
;
233 pci_dev_put(pci_gfx_root
);
234 PSB_DEBUG_ENTRY("platform_rev_id is %x\n", dev_priv
->platform_rev_id
);
237 void mrst_get_vbt_data(struct drm_psb_private
*dev_priv
)
239 struct mrst_vbt
*vbt
= &dev_priv
->vbt_data
;
240 u32 platform_config_address
;
245 struct mrst_timing_info
*dp_ti
= &dev_priv
->gct_data
.DTD
;
246 struct gct_r10_timing_info ti
;
248 struct pci_dev
*pci_gfx_root
= pci_get_bus_and_slot(0, PCI_DEVFN(2, 0));
250 /*get the address of the platform config vbt, B0:D2:F0;0xFC */
251 pci_read_config_dword(pci_gfx_root
, 0xFC, &platform_config_address
);
252 pci_dev_put(pci_gfx_root
);
253 DRM_INFO("drm platform config address is %x\n",
254 platform_config_address
);
256 /* check for platform config address == 0. */
257 /* this means fw doesn't support vbt */
259 if (platform_config_address
== 0) {
264 /* get the virtual address of the vbt */
265 vbt_virtual
= ioremap(platform_config_address
, sizeof(*vbt
));
267 memcpy(vbt
, vbt_virtual
, sizeof(*vbt
));
268 iounmap(vbt_virtual
); /* Free virtual address space */
270 printk(KERN_ALERT
"GCT revision is %x\n", vbt
->revision
);
272 switch (vbt
->revision
) {
274 vbt
->mrst_gct
= NULL
;
276 ioremap(platform_config_address
+ sizeof(*vbt
) - 4,
277 vbt
->size
- sizeof(*vbt
) + 4);
278 pGCT
= vbt
->mrst_gct
;
279 bpi
= ((struct mrst_gct_v1
*)pGCT
)->PD
.BootPanelIndex
;
280 dev_priv
->gct_data
.bpi
= bpi
;
281 dev_priv
->gct_data
.pt
=
282 ((struct mrst_gct_v1
*)pGCT
)->PD
.PanelType
;
283 memcpy(&dev_priv
->gct_data
.DTD
,
284 &((struct mrst_gct_v1
*)pGCT
)->panel
[bpi
].DTD
,
285 sizeof(struct mrst_timing_info
));
286 dev_priv
->gct_data
.Panel_Port_Control
=
287 ((struct mrst_gct_v1
*)pGCT
)->panel
[bpi
].Panel_Port_Control
;
288 dev_priv
->gct_data
.Panel_MIPI_Display_Descriptor
=
289 ((struct mrst_gct_v1
*)pGCT
)->panel
[bpi
].Panel_MIPI_Display_Descriptor
;
292 vbt
->mrst_gct
= NULL
;
294 ioremap(platform_config_address
+ sizeof(*vbt
) - 4,
295 vbt
->size
- sizeof(*vbt
) + 4);
296 pGCT
= vbt
->mrst_gct
;
297 bpi
= ((struct mrst_gct_v2
*)pGCT
)->PD
.BootPanelIndex
;
298 dev_priv
->gct_data
.bpi
= bpi
;
299 dev_priv
->gct_data
.pt
=
300 ((struct mrst_gct_v2
*)pGCT
)->PD
.PanelType
;
301 memcpy(&dev_priv
->gct_data
.DTD
,
302 &((struct mrst_gct_v2
*)pGCT
)->panel
[bpi
].DTD
,
303 sizeof(struct mrst_timing_info
));
304 dev_priv
->gct_data
.Panel_Port_Control
=
305 ((struct mrst_gct_v2
*)pGCT
)->panel
[bpi
].Panel_Port_Control
;
306 dev_priv
->gct_data
.Panel_MIPI_Display_Descriptor
=
307 ((struct mrst_gct_v2
*)pGCT
)->panel
[bpi
].Panel_MIPI_Display_Descriptor
;
310 /*header definition changed from rev 01 (v2) to rev 10h. */
311 /*so, some values have changed location*/
312 new_size
= vbt
->checksum
; /*checksum contains lo size byte*/
313 /*LSB of mrst_gct contains hi size byte*/
314 new_size
|= ((0xff & (unsigned int)vbt
->mrst_gct
)) << 8;
316 vbt
->checksum
= vbt
->size
; /*size contains the checksum*/
318 vbt
->size
= 0xff; /*restrict size to 255*/
320 vbt
->size
= new_size
;
322 /* number of descriptors defined in the GCT */
323 number_desc
= ((0xff00 & (unsigned int)vbt
->mrst_gct
)) >> 8;
324 bpi
= ((0xff0000 & (unsigned int)vbt
->mrst_gct
)) >> 16;
325 vbt
->mrst_gct
= NULL
;
327 ioremap(platform_config_address
+ GCT_R10_HEADER_SIZE
,
328 GCT_R10_DISPLAY_DESC_SIZE
* number_desc
);
329 pGCT
= vbt
->mrst_gct
;
330 pGCT
= (u8
*)pGCT
+ (bpi
*GCT_R10_DISPLAY_DESC_SIZE
);
331 dev_priv
->gct_data
.bpi
= bpi
; /*save boot panel id*/
333 /*copy the GCT display timings into a temp structure*/
334 memcpy(&ti
, pGCT
, sizeof(struct gct_r10_timing_info
));
336 /*now copy the temp struct into the dev_priv->gct_data*/
337 dp_ti
->pixel_clock
= ti
.pixel_clock
;
338 dp_ti
->hactive_hi
= ti
.hactive_hi
;
339 dp_ti
->hactive_lo
= ti
.hactive_lo
;
340 dp_ti
->hblank_hi
= ti
.hblank_hi
;
341 dp_ti
->hblank_lo
= ti
.hblank_lo
;
342 dp_ti
->hsync_offset_hi
= ti
.hsync_offset_hi
;
343 dp_ti
->hsync_offset_lo
= ti
.hsync_offset_lo
;
344 dp_ti
->hsync_pulse_width_hi
= ti
.hsync_pulse_width_hi
;
345 dp_ti
->hsync_pulse_width_lo
= ti
.hsync_pulse_width_lo
;
346 dp_ti
->vactive_hi
= ti
.vactive_hi
;
347 dp_ti
->vactive_lo
= ti
.vactive_lo
;
348 dp_ti
->vblank_hi
= ti
.vblank_hi
;
349 dp_ti
->vblank_lo
= ti
.vblank_lo
;
350 dp_ti
->vsync_offset_hi
= ti
.vsync_offset_hi
;
351 dp_ti
->vsync_offset_lo
= ti
.vsync_offset_lo
;
352 dp_ti
->vsync_pulse_width_hi
= ti
.vsync_pulse_width_hi
;
353 dp_ti
->vsync_pulse_width_lo
= ti
.vsync_pulse_width_lo
;
355 /*mov the MIPI_Display_Descriptor data from GCT to dev priv*/
356 dev_priv
->gct_data
.Panel_MIPI_Display_Descriptor
=
357 *((u8
*)pGCT
+ 0x0d);
358 dev_priv
->gct_data
.Panel_MIPI_Display_Descriptor
|=
359 (*((u8
*)pGCT
+ 0x0e)) << 8;
362 printk(KERN_ERR
"Unknown revision of GCT!\n");
367 static void psb_get_core_freq(struct drm_device
*dev
)
370 struct pci_dev
*pci_root
= pci_get_bus_and_slot(0, 0);
371 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
373 /*pci_write_config_dword(pci_root, 0xD4, 0x00C32004);*/
374 /*pci_write_config_dword(pci_root, 0xD0, 0xE0033000);*/
376 pci_write_config_dword(pci_root
, 0xD0, 0xD0050300);
377 pci_read_config_dword(pci_root
, 0xD4, &clock
);
378 pci_dev_put(pci_root
);
380 switch (clock
& 0x07) {
382 dev_priv
->core_freq
= 100;
385 dev_priv
->core_freq
= 133;
388 dev_priv
->core_freq
= 150;
391 dev_priv
->core_freq
= 178;
394 dev_priv
->core_freq
= 200;
399 dev_priv
->core_freq
= 266;
401 dev_priv
->core_freq
= 0;
405 static int psb_do_init(struct drm_device
*dev
)
407 struct drm_psb_private
*dev_priv
=
408 (struct drm_psb_private
*) dev
->dev_private
;
409 struct psb_gtt
*pg
= dev_priv
->pg
;
417 if (pg
->mmu_gatt_start
& 0x0FFFFFFF) {
418 DRM_ERROR("Gatt must be 256M aligned. This is a bug.\n");
424 stolen_gtt
= (pg
->stolen_size
>> PAGE_SHIFT
) * 4;
425 stolen_gtt
= (stolen_gtt
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
427 (stolen_gtt
< pg
->gtt_pages
) ? stolen_gtt
: pg
->gtt_pages
;
429 dev_priv
->gatt_free_offset
= pg
->mmu_gatt_start
+
430 (stolen_gtt
<< PAGE_SHIFT
) * 1024;
432 if (1 || drm_debug
) {
433 uint32_t core_id
= PSB_RSGX32(PSB_CR_CORE_ID
);
434 uint32_t core_rev
= PSB_RSGX32(PSB_CR_CORE_REVISION
);
435 DRM_INFO("SGX core id = 0x%08x\n", core_id
);
436 DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n",
437 (core_rev
& _PSB_CC_REVISION_MAJOR_MASK
) >>
438 _PSB_CC_REVISION_MAJOR_SHIFT
,
439 (core_rev
& _PSB_CC_REVISION_MINOR_MASK
) >>
440 _PSB_CC_REVISION_MINOR_SHIFT
);
442 ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n",
443 (core_rev
& _PSB_CC_REVISION_MAINTENANCE_MASK
) >>
444 _PSB_CC_REVISION_MAINTENANCE_SHIFT
,
445 (core_rev
& _PSB_CC_REVISION_DESIGNER_MASK
) >>
446 _PSB_CC_REVISION_DESIGNER_SHIFT
);
450 spin_lock_init(&dev_priv
->irqmask_lock
);
452 tt_pages
= (pg
->gatt_pages
< PSB_TT_PRIV0_PLIMIT
) ?
453 pg
->gatt_pages
: PSB_TT_PRIV0_PLIMIT
;
454 tt_start
= dev_priv
->gatt_free_offset
- pg
->mmu_gatt_start
;
455 tt_pages
-= tt_start
>> PAGE_SHIFT
;
456 /* FIXME: can we kill ta_mem_size ? */
457 dev_priv
->sizes
.ta_mem_size
= 0;
459 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0
);
460 PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1
);
461 PSB_RSGX32(PSB_CR_BIF_BANK1
);
462 PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL
) | _PSB_MMU_ER_MASK
,
467 PSB_WSGX32(pg
->gatt_start
, PSB_CR_BIF_TWOD_REQ_BASE
);
471 psb_do_takedown(dev
);
475 static int psb_driver_unload(struct drm_device
*dev
)
477 struct drm_psb_private
*dev_priv
=
478 (struct drm_psb_private
*) dev
->dev_private
;
480 /* Kill vblank etc here */
482 psb_backlight_exit(); /*writes minimum value to backlight HW reg */
484 if (drm_psb_no_fb
== 0)
485 psb_modeset_cleanup(dev
);
488 psb_lid_timer_takedown(dev_priv
);
490 psb_do_takedown(dev
);
493 if (dev_priv
->pf_pd
) {
494 psb_mmu_free_pagedir(dev_priv
->pf_pd
);
495 dev_priv
->pf_pd
= NULL
;
498 struct psb_gtt
*pg
= dev_priv
->pg
;
501 psb_mmu_remove_pfn_sequence(
502 psb_mmu_get_default_pd
505 dev_priv
->vram_stolen_size
>> PAGE_SHIFT
);
507 psb_mmu_driver_takedown(dev_priv
->mmu
);
508 dev_priv
->mmu
= NULL
;
510 psb_gtt_takedown(dev
);
511 if (dev_priv
->scratch_page
) {
512 __free_page(dev_priv
->scratch_page
);
513 dev_priv
->scratch_page
= NULL
;
515 if (dev_priv
->vdc_reg
) {
516 iounmap(dev_priv
->vdc_reg
);
517 dev_priv
->vdc_reg
= NULL
;
519 if (dev_priv
->sgx_reg
) {
520 iounmap(dev_priv
->sgx_reg
);
521 dev_priv
->sgx_reg
= NULL
;
525 dev
->dev_private
= NULL
;
528 psb_intel_destroy_bios(dev
);
531 gma_power_uninit(dev
);
537 static int psb_driver_load(struct drm_device
*dev
, unsigned long chipset
)
539 struct drm_psb_private
*dev_priv
;
540 unsigned long resource_start
;
542 unsigned long irqflags
;
545 struct drm_connector
*connector
;
546 struct psb_intel_output
*psb_intel_output
;
548 dev_priv
= kzalloc(sizeof(*dev_priv
), GFP_KERNEL
);
549 if (dev_priv
== NULL
)
553 dev_priv
->num_pipe
= 1;
555 dev_priv
->num_pipe
= 2;
559 dev
->dev_private
= (void *) dev_priv
;
560 dev_priv
->chipset
= chipset
;
562 PSB_DEBUG_INIT("Mapping MMIO\n");
563 resource_start
= pci_resource_start(dev
->pdev
, PSB_MMIO_RESOURCE
);
566 ioremap(resource_start
+ PSB_VDC_OFFSET
, PSB_VDC_SIZE
);
567 if (!dev_priv
->vdc_reg
)
571 dev_priv
->sgx_reg
= ioremap(resource_start
+ MRST_SGX_OFFSET
,
574 dev_priv
->sgx_reg
= ioremap(resource_start
+ PSB_SGX_OFFSET
,
577 if (!dev_priv
->sgx_reg
)
581 mrst_get_fuse_settings(dev
);
582 mrst_get_vbt_data(dev_priv
);
583 mid_get_pci_revID(dev_priv
);
585 psb_get_core_freq(dev
);
586 psb_intel_opregion_init(dev
);
587 psb_intel_init_bios(dev
);
590 /* Init OSPM support */
595 dev_priv
->scratch_page
= alloc_page(GFP_DMA32
| __GFP_ZERO
);
596 if (!dev_priv
->scratch_page
)
599 set_pages_uc(dev_priv
->scratch_page
, 1);
601 ret
= psb_gtt_init(dev
, 0);
605 dev_priv
->mmu
= psb_mmu_driver_init((void *)0,
606 drm_psb_trap_pagefaults
, 0,
613 tt_pages
= (pg
->gatt_pages
< PSB_TT_PRIV0_PLIMIT
) ?
614 (pg
->gatt_pages
) : PSB_TT_PRIV0_PLIMIT
;
617 dev_priv
->pf_pd
= psb_mmu_alloc_pd(dev_priv
->mmu
, 1, 0);
618 if (!dev_priv
->pf_pd
)
621 psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv
->mmu
), 0);
622 psb_mmu_set_pd_context(dev_priv
->pf_pd
, 1);
624 ret
= psb_do_init(dev
);
628 PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE
);
629 PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE
);
631 /* igd_opregion_init(&dev_priv->opregion_dev); */
632 acpi_video_register();
633 if (dev_priv
->lid_state
)
634 psb_lid_timer_init(dev_priv
);
636 ret
= drm_vblank_init(dev
, dev_priv
->num_pipe
);
641 * Install interrupt handlers prior to powering off SGX or else we will
644 dev_priv
->vdc_irq_mask
= 0;
645 dev_priv
->pipestat
[0] = 0;
646 dev_priv
->pipestat
[1] = 0;
647 dev_priv
->pipestat
[2] = 0;
648 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
649 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
650 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R
);
651 PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R
);
652 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
653 if (drm_core_check_feature(dev
, DRIVER_MODESET
))
654 drm_irq_install(dev
);
656 dev
->vblank_disable_allowed
= 1;
658 dev
->max_vblank_count
= 0xffffff; /* only 24 bits of frame count */
660 dev
->driver
->get_vblank_counter
= psb_get_vblank_counter
;
662 if (drm_psb_no_fb
== 0) {
663 psb_modeset_init(dev
);
665 drm_kms_helper_poll_init(dev
);
668 /* Only add backlight support if we have LVDS output */
669 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
,
671 psb_intel_output
= to_psb_intel_output(connector
);
673 switch (psb_intel_output
->type
) {
674 case INTEL_OUTPUT_LVDS
:
675 ret
= psb_backlight_init(dev
);
683 /*enable runtime pm at last*/
684 pm_runtime_enable(&dev
->pdev
->dev
);
685 pm_runtime_set_active(&dev
->pdev
->dev
);
687 /*Intel drm driver load is done, continue doing pvr load*/
688 DRM_DEBUG("Pvr driver load\n");
691 psb_driver_unload(dev
);
695 int psb_driver_device_is_agp(struct drm_device
*dev
)
701 static int psb_sizes_ioctl(struct drm_device
*dev
, void *data
,
702 struct drm_file
*file_priv
)
704 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
705 struct drm_psb_sizes_arg
*arg
=
706 (struct drm_psb_sizes_arg
*) data
;
708 *arg
= dev_priv
->sizes
;
712 static int psb_dc_state_ioctl(struct drm_device
*dev
, void * data
,
713 struct drm_file
*file_priv
)
717 struct drm_mode_object
*obj
;
718 struct drm_connector
*connector
;
719 struct drm_crtc
*crtc
;
720 struct drm_psb_dc_state_arg
*arg
=
721 (struct drm_psb_dc_state_arg
*)data
;
724 obj_id
= arg
->obj_id
;
726 if (flags
& PSB_DC_CRTC_MASK
) {
727 obj
= drm_mode_object_find(dev
, obj_id
,
728 DRM_MODE_OBJECT_CRTC
);
730 DRM_DEBUG("Invalid CRTC object.\n");
734 crtc
= obj_to_crtc(obj
);
736 mutex_lock(&dev
->mode_config
.mutex
);
737 if (drm_helper_crtc_in_use(crtc
)) {
738 if (flags
& PSB_DC_CRTC_SAVE
)
739 crtc
->funcs
->save(crtc
);
741 crtc
->funcs
->restore(crtc
);
743 mutex_unlock(&dev
->mode_config
.mutex
);
746 } else if (flags
& PSB_DC_OUTPUT_MASK
) {
747 obj
= drm_mode_object_find(dev
, obj_id
,
748 DRM_MODE_OBJECT_CONNECTOR
);
750 DRM_DEBUG("Invalid connector id.\n");
754 connector
= obj_to_connector(obj
);
755 if (flags
& PSB_DC_OUTPUT_SAVE
)
756 connector
->funcs
->save(connector
);
758 connector
->funcs
->restore(connector
);
763 DRM_DEBUG("Bad flags 0x%x\n", flags
);
767 static int psb_dpst_bl_ioctl(struct drm_device
*dev
, void *data
,
768 struct drm_file
*file_priv
)
770 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
771 uint32_t *arg
= data
;
772 struct backlight_device bd
;
773 dev_priv
->blc_adj2
= *arg
;
775 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
776 bd
.props
.brightness
= psb_get_brightness(&bd
);
777 psb_set_brightness(&bd
);
782 static int psb_adb_ioctl(struct drm_device
*dev
, void *data
,
783 struct drm_file
*file_priv
)
785 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
786 uint32_t *arg
= data
;
787 struct backlight_device bd
;
788 dev_priv
->blc_adj1
= *arg
;
790 #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
791 bd
.props
.brightness
= psb_get_brightness(&bd
);
792 psb_set_brightness(&bd
);
797 /* return the current mode to the dpst module */
798 static int psb_dpst_ioctl(struct drm_device
*dev
, void *data
,
799 struct drm_file
*file_priv
)
801 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
802 uint32_t *arg
= data
;
807 if (!gma_power_begin(dev
, 0))
810 reg
= PSB_RVDC32(PIPEASRC
);
814 /* horizontal is the left 16 bits */
816 /* vertical is the right 16 bits */
817 y
= reg
& 0x0000ffff;
819 /* the values are the image size minus one */
823 *arg
= (x
<< 16) | y
;
827 static int psb_gamma_ioctl(struct drm_device
*dev
, void *data
,
828 struct drm_file
*file_priv
)
830 struct drm_psb_dpst_lut_arg
*lut_arg
= data
;
831 struct drm_mode_object
*obj
;
832 struct drm_crtc
*crtc
;
833 struct drm_connector
*connector
;
834 struct psb_intel_crtc
*psb_intel_crtc
;
838 obj_id
= lut_arg
->output_id
;
839 obj
= drm_mode_object_find(dev
, obj_id
, DRM_MODE_OBJECT_CONNECTOR
);
841 DRM_DEBUG("Invalid Connector object.\n");
845 connector
= obj_to_connector(obj
);
846 crtc
= connector
->encoder
->crtc
;
847 psb_intel_crtc
= to_psb_intel_crtc(crtc
);
849 for (i
= 0; i
< 256; i
++)
850 psb_intel_crtc
->lut_adj
[i
] = lut_arg
->lut
[i
];
852 psb_intel_crtc_load_lut(crtc
);
857 static int psb_mode_operation_ioctl(struct drm_device
*dev
, void *data
,
858 struct drm_file
*file_priv
)
862 struct drm_mode_modeinfo
*umode
;
863 struct drm_display_mode
*mode
= NULL
;
864 struct drm_psb_mode_operation_arg
*arg
;
865 struct drm_mode_object
*obj
;
866 struct drm_connector
*connector
;
867 struct drm_framebuffer
*drm_fb
;
868 struct psb_framebuffer
*psb_fb
;
869 struct drm_connector_helper_funcs
*connector_funcs
;
872 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
874 arg
= (struct drm_psb_mode_operation_arg
*)data
;
875 obj_id
= arg
->obj_id
;
879 case PSB_MODE_OPERATION_SET_DC_BASE
:
880 obj
= drm_mode_object_find(dev
, obj_id
, DRM_MODE_OBJECT_FB
);
882 DRM_ERROR("Invalid FB id %d\n", obj_id
);
886 drm_fb
= obj_to_fb(obj
);
887 psb_fb
= to_psb_fb(drm_fb
);
889 if (gma_power_begin(dev
, 0)) {
890 REG_WRITE(DSPASURF
, psb_fb
->gtt
->offset
);
894 dev_priv
->saveDSPASURF
= psb_fb
->gtt
->offset
;
898 case PSB_MODE_OPERATION_MODE_VALID
:
901 mutex_lock(&dev
->mode_config
.mutex
);
903 obj
= drm_mode_object_find(dev
, obj_id
,
904 DRM_MODE_OBJECT_CONNECTOR
);
910 connector
= obj_to_connector(obj
);
912 mode
= drm_mode_create(dev
);
918 /* drm_crtc_convert_umode(mode, umode); */
920 mode
->clock
= umode
->clock
;
921 mode
->hdisplay
= umode
->hdisplay
;
922 mode
->hsync_start
= umode
->hsync_start
;
923 mode
->hsync_end
= umode
->hsync_end
;
924 mode
->htotal
= umode
->htotal
;
925 mode
->hskew
= umode
->hskew
;
926 mode
->vdisplay
= umode
->vdisplay
;
927 mode
->vsync_start
= umode
->vsync_start
;
928 mode
->vsync_end
= umode
->vsync_end
;
929 mode
->vtotal
= umode
->vtotal
;
930 mode
->vscan
= umode
->vscan
;
931 mode
->vrefresh
= umode
->vrefresh
;
932 mode
->flags
= umode
->flags
;
933 mode
->type
= umode
->type
;
934 strncpy(mode
->name
, umode
->name
, DRM_DISPLAY_MODE_LEN
);
935 mode
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
938 connector_funcs
= (struct drm_connector_helper_funcs
*)
939 connector
->helper_private
;
941 if (connector_funcs
->mode_valid
) {
942 resp
= connector_funcs
->mode_valid(connector
, mode
);
943 arg
->data
= (void *)resp
;
946 /*do some clean up work*/
948 drm_mode_destroy(dev
, mode
);
950 mutex_unlock(&dev
->mode_config
.mutex
);
954 DRM_DEBUG("Unsupported psb mode operation");
961 static int psb_stolen_memory_ioctl(struct drm_device
*dev
, void *data
,
962 struct drm_file
*file_priv
)
964 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
965 struct drm_psb_stolen_memory_arg
*arg
= data
;
967 arg
->base
= dev_priv
->stolen_base
;
968 arg
->size
= dev_priv
->vram_stolen_size
;
973 static int psb_register_rw_ioctl(struct drm_device
*dev
, void *data
,
974 struct drm_file
*file_priv
)
976 struct drm_psb_private
*dev_priv
= psb_priv(dev
);
977 struct drm_psb_register_rw_arg
*arg
= data
;
978 bool usage
= arg
->b_force_hw_on
? true : false;
980 if (arg
->display_write_mask
!= 0) {
981 if (gma_power_begin(dev
, usage
)) {
982 if (arg
->display_write_mask
& REGRWBITS_PFIT_CONTROLS
)
983 PSB_WVDC32(arg
->display
.pfit_controls
,
985 if (arg
->display_write_mask
&
986 REGRWBITS_PFIT_AUTOSCALE_RATIOS
)
987 PSB_WVDC32(arg
->display
.pfit_autoscale_ratios
,
989 if (arg
->display_write_mask
&
990 REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS
)
992 arg
->display
.pfit_programmed_scale_ratios
,
994 if (arg
->display_write_mask
& REGRWBITS_PIPEASRC
)
995 PSB_WVDC32(arg
->display
.pipeasrc
,
997 if (arg
->display_write_mask
& REGRWBITS_PIPEBSRC
)
998 PSB_WVDC32(arg
->display
.pipebsrc
,
1000 if (arg
->display_write_mask
& REGRWBITS_VTOTAL_A
)
1001 PSB_WVDC32(arg
->display
.vtotal_a
,
1003 if (arg
->display_write_mask
& REGRWBITS_VTOTAL_B
)
1004 PSB_WVDC32(arg
->display
.vtotal_b
,
1008 if (arg
->display_write_mask
& REGRWBITS_PFIT_CONTROLS
)
1009 dev_priv
->savePFIT_CONTROL
=
1010 arg
->display
.pfit_controls
;
1011 if (arg
->display_write_mask
&
1012 REGRWBITS_PFIT_AUTOSCALE_RATIOS
)
1013 dev_priv
->savePFIT_AUTO_RATIOS
=
1014 arg
->display
.pfit_autoscale_ratios
;
1015 if (arg
->display_write_mask
&
1016 REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS
)
1017 dev_priv
->savePFIT_PGM_RATIOS
=
1018 arg
->display
.pfit_programmed_scale_ratios
;
1019 if (arg
->display_write_mask
& REGRWBITS_PIPEASRC
)
1020 dev_priv
->savePIPEASRC
= arg
->display
.pipeasrc
;
1021 if (arg
->display_write_mask
& REGRWBITS_PIPEBSRC
)
1022 dev_priv
->savePIPEBSRC
= arg
->display
.pipebsrc
;
1023 if (arg
->display_write_mask
& REGRWBITS_VTOTAL_A
)
1024 dev_priv
->saveVTOTAL_A
= arg
->display
.vtotal_a
;
1025 if (arg
->display_write_mask
& REGRWBITS_VTOTAL_B
)
1026 dev_priv
->saveVTOTAL_B
= arg
->display
.vtotal_b
;
1030 if (arg
->display_read_mask
!= 0) {
1031 if (gma_power_begin(dev
, usage
)) {
1032 if (arg
->display_read_mask
&
1033 REGRWBITS_PFIT_CONTROLS
)
1034 arg
->display
.pfit_controls
=
1035 PSB_RVDC32(PFIT_CONTROL
);
1036 if (arg
->display_read_mask
&
1037 REGRWBITS_PFIT_AUTOSCALE_RATIOS
)
1038 arg
->display
.pfit_autoscale_ratios
=
1039 PSB_RVDC32(PFIT_AUTO_RATIOS
);
1040 if (arg
->display_read_mask
&
1041 REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS
)
1042 arg
->display
.pfit_programmed_scale_ratios
=
1043 PSB_RVDC32(PFIT_PGM_RATIOS
);
1044 if (arg
->display_read_mask
& REGRWBITS_PIPEASRC
)
1045 arg
->display
.pipeasrc
= PSB_RVDC32(PIPEASRC
);
1046 if (arg
->display_read_mask
& REGRWBITS_PIPEBSRC
)
1047 arg
->display
.pipebsrc
= PSB_RVDC32(PIPEBSRC
);
1048 if (arg
->display_read_mask
& REGRWBITS_VTOTAL_A
)
1049 arg
->display
.vtotal_a
= PSB_RVDC32(VTOTAL_A
);
1050 if (arg
->display_read_mask
& REGRWBITS_VTOTAL_B
)
1051 arg
->display
.vtotal_b
= PSB_RVDC32(VTOTAL_B
);
1054 if (arg
->display_read_mask
&
1055 REGRWBITS_PFIT_CONTROLS
)
1056 arg
->display
.pfit_controls
=
1057 dev_priv
->savePFIT_CONTROL
;
1058 if (arg
->display_read_mask
&
1059 REGRWBITS_PFIT_AUTOSCALE_RATIOS
)
1060 arg
->display
.pfit_autoscale_ratios
=
1061 dev_priv
->savePFIT_AUTO_RATIOS
;
1062 if (arg
->display_read_mask
&
1063 REGRWBITS_PFIT_PROGRAMMED_SCALE_RATIOS
)
1064 arg
->display
.pfit_programmed_scale_ratios
=
1065 dev_priv
->savePFIT_PGM_RATIOS
;
1066 if (arg
->display_read_mask
& REGRWBITS_PIPEASRC
)
1067 arg
->display
.pipeasrc
= dev_priv
->savePIPEASRC
;
1068 if (arg
->display_read_mask
& REGRWBITS_PIPEBSRC
)
1069 arg
->display
.pipebsrc
= dev_priv
->savePIPEBSRC
;
1070 if (arg
->display_read_mask
& REGRWBITS_VTOTAL_A
)
1071 arg
->display
.vtotal_a
= dev_priv
->saveVTOTAL_A
;
1072 if (arg
->display_read_mask
& REGRWBITS_VTOTAL_B
)
1073 arg
->display
.vtotal_b
= dev_priv
->saveVTOTAL_B
;
1077 if (arg
->overlay_write_mask
!= 0) {
1078 if (gma_power_begin(dev
, usage
)) {
1079 if (arg
->overlay_write_mask
& OV_REGRWBITS_OGAM_ALL
) {
1080 PSB_WVDC32(arg
->overlay
.OGAMC5
, OV_OGAMC5
);
1081 PSB_WVDC32(arg
->overlay
.OGAMC4
, OV_OGAMC4
);
1082 PSB_WVDC32(arg
->overlay
.OGAMC3
, OV_OGAMC3
);
1083 PSB_WVDC32(arg
->overlay
.OGAMC2
, OV_OGAMC2
);
1084 PSB_WVDC32(arg
->overlay
.OGAMC1
, OV_OGAMC1
);
1085 PSB_WVDC32(arg
->overlay
.OGAMC0
, OV_OGAMC0
);
1087 if (arg
->overlay_write_mask
& OVC_REGRWBITS_OGAM_ALL
) {
1088 PSB_WVDC32(arg
->overlay
.OGAMC5
, OVC_OGAMC5
);
1089 PSB_WVDC32(arg
->overlay
.OGAMC4
, OVC_OGAMC4
);
1090 PSB_WVDC32(arg
->overlay
.OGAMC3
, OVC_OGAMC3
);
1091 PSB_WVDC32(arg
->overlay
.OGAMC2
, OVC_OGAMC2
);
1092 PSB_WVDC32(arg
->overlay
.OGAMC1
, OVC_OGAMC1
);
1093 PSB_WVDC32(arg
->overlay
.OGAMC0
, OVC_OGAMC0
);
1096 if (arg
->overlay_write_mask
& OV_REGRWBITS_OVADD
) {
1097 PSB_WVDC32(arg
->overlay
.OVADD
, OV_OVADD
);
1099 if (arg
->overlay
.b_wait_vblank
) {
1101 unsigned long vblank_timeout
= jiffies
1104 while (time_before_eq(jiffies
,
1106 temp
= PSB_RVDC32(OV_DOVASTA
);
1107 if ((temp
& (0x1 << 31)) != 0)
1113 if (arg
->overlay_write_mask
& OVC_REGRWBITS_OVADD
) {
1114 PSB_WVDC32(arg
->overlay
.OVADD
, OVC_OVADD
);
1115 if (arg
->overlay
.b_wait_vblank
) {
1117 unsigned long vblank_timeout
=
1120 while (time_before_eq(jiffies
,
1122 temp
= PSB_RVDC32(OVC_DOVCSTA
);
1123 if ((temp
& (0x1 << 31)) != 0)
1131 if (arg
->overlay_write_mask
& OV_REGRWBITS_OGAM_ALL
) {
1132 dev_priv
->saveOV_OGAMC5
= arg
->overlay
.OGAMC5
;
1133 dev_priv
->saveOV_OGAMC4
= arg
->overlay
.OGAMC4
;
1134 dev_priv
->saveOV_OGAMC3
= arg
->overlay
.OGAMC3
;
1135 dev_priv
->saveOV_OGAMC2
= arg
->overlay
.OGAMC2
;
1136 dev_priv
->saveOV_OGAMC1
= arg
->overlay
.OGAMC1
;
1137 dev_priv
->saveOV_OGAMC0
= arg
->overlay
.OGAMC0
;
1139 if (arg
->overlay_write_mask
& OVC_REGRWBITS_OGAM_ALL
) {
1140 dev_priv
->saveOVC_OGAMC5
= arg
->overlay
.OGAMC5
;
1141 dev_priv
->saveOVC_OGAMC4
= arg
->overlay
.OGAMC4
;
1142 dev_priv
->saveOVC_OGAMC3
= arg
->overlay
.OGAMC3
;
1143 dev_priv
->saveOVC_OGAMC2
= arg
->overlay
.OGAMC2
;
1144 dev_priv
->saveOVC_OGAMC1
= arg
->overlay
.OGAMC1
;
1145 dev_priv
->saveOVC_OGAMC0
= arg
->overlay
.OGAMC0
;
1147 if (arg
->overlay_write_mask
& OV_REGRWBITS_OVADD
)
1148 dev_priv
->saveOV_OVADD
= arg
->overlay
.OVADD
;
1149 if (arg
->overlay_write_mask
& OVC_REGRWBITS_OVADD
)
1150 dev_priv
->saveOVC_OVADD
= arg
->overlay
.OVADD
;
1154 if (arg
->overlay_read_mask
!= 0) {
1155 if (gma_power_begin(dev
, usage
)) {
1156 if (arg
->overlay_read_mask
& OV_REGRWBITS_OGAM_ALL
) {
1157 arg
->overlay
.OGAMC5
= PSB_RVDC32(OV_OGAMC5
);
1158 arg
->overlay
.OGAMC4
= PSB_RVDC32(OV_OGAMC4
);
1159 arg
->overlay
.OGAMC3
= PSB_RVDC32(OV_OGAMC3
);
1160 arg
->overlay
.OGAMC2
= PSB_RVDC32(OV_OGAMC2
);
1161 arg
->overlay
.OGAMC1
= PSB_RVDC32(OV_OGAMC1
);
1162 arg
->overlay
.OGAMC0
= PSB_RVDC32(OV_OGAMC0
);
1164 if (arg
->overlay_read_mask
& OVC_REGRWBITS_OGAM_ALL
) {
1165 arg
->overlay
.OGAMC5
= PSB_RVDC32(OVC_OGAMC5
);
1166 arg
->overlay
.OGAMC4
= PSB_RVDC32(OVC_OGAMC4
);
1167 arg
->overlay
.OGAMC3
= PSB_RVDC32(OVC_OGAMC3
);
1168 arg
->overlay
.OGAMC2
= PSB_RVDC32(OVC_OGAMC2
);
1169 arg
->overlay
.OGAMC1
= PSB_RVDC32(OVC_OGAMC1
);
1170 arg
->overlay
.OGAMC0
= PSB_RVDC32(OVC_OGAMC0
);
1172 if (arg
->overlay_read_mask
& OV_REGRWBITS_OVADD
)
1173 arg
->overlay
.OVADD
= PSB_RVDC32(OV_OVADD
);
1174 if (arg
->overlay_read_mask
& OVC_REGRWBITS_OVADD
)
1175 arg
->overlay
.OVADD
= PSB_RVDC32(OVC_OVADD
);
1178 if (arg
->overlay_read_mask
& OV_REGRWBITS_OGAM_ALL
) {
1179 arg
->overlay
.OGAMC5
= dev_priv
->saveOV_OGAMC5
;
1180 arg
->overlay
.OGAMC4
= dev_priv
->saveOV_OGAMC4
;
1181 arg
->overlay
.OGAMC3
= dev_priv
->saveOV_OGAMC3
;
1182 arg
->overlay
.OGAMC2
= dev_priv
->saveOV_OGAMC2
;
1183 arg
->overlay
.OGAMC1
= dev_priv
->saveOV_OGAMC1
;
1184 arg
->overlay
.OGAMC0
= dev_priv
->saveOV_OGAMC0
;
1186 if (arg
->overlay_read_mask
& OVC_REGRWBITS_OGAM_ALL
) {
1187 arg
->overlay
.OGAMC5
= dev_priv
->saveOVC_OGAMC5
;
1188 arg
->overlay
.OGAMC4
= dev_priv
->saveOVC_OGAMC4
;
1189 arg
->overlay
.OGAMC3
= dev_priv
->saveOVC_OGAMC3
;
1190 arg
->overlay
.OGAMC2
= dev_priv
->saveOVC_OGAMC2
;
1191 arg
->overlay
.OGAMC1
= dev_priv
->saveOVC_OGAMC1
;
1192 arg
->overlay
.OGAMC0
= dev_priv
->saveOVC_OGAMC0
;
1194 if (arg
->overlay_read_mask
& OV_REGRWBITS_OVADD
)
1195 arg
->overlay
.OVADD
= dev_priv
->saveOV_OVADD
;
1196 if (arg
->overlay_read_mask
& OVC_REGRWBITS_OVADD
)
1197 arg
->overlay
.OVADD
= dev_priv
->saveOVC_OVADD
;
1201 if (arg
->sprite_enable_mask
!= 0) {
1202 if (gma_power_begin(dev
, usage
)) {
1203 PSB_WVDC32(0x1F3E, DSPARB
);
1204 PSB_WVDC32(arg
->sprite
.dspa_control
1205 | PSB_RVDC32(DSPACNTR
), DSPACNTR
);
1206 PSB_WVDC32(arg
->sprite
.dspa_key_value
, DSPAKEYVAL
);
1207 PSB_WVDC32(arg
->sprite
.dspa_key_mask
, DSPAKEYMASK
);
1208 PSB_WVDC32(PSB_RVDC32(DSPASURF
), DSPASURF
);
1209 PSB_RVDC32(DSPASURF
);
1210 PSB_WVDC32(arg
->sprite
.dspc_control
, DSPCCNTR
);
1211 PSB_WVDC32(arg
->sprite
.dspc_stride
, DSPCSTRIDE
);
1212 PSB_WVDC32(arg
->sprite
.dspc_position
, DSPCPOS
);
1213 PSB_WVDC32(arg
->sprite
.dspc_linear_offset
, DSPCLINOFF
);
1214 PSB_WVDC32(arg
->sprite
.dspc_size
, DSPCSIZE
);
1215 PSB_WVDC32(arg
->sprite
.dspc_surface
, DSPCSURF
);
1216 PSB_RVDC32(DSPCSURF
);
1221 if (arg
->sprite_disable_mask
!= 0) {
1222 if (gma_power_begin(dev
, usage
)) {
1223 PSB_WVDC32(0x3F3E, DSPARB
);
1224 PSB_WVDC32(0x0, DSPCCNTR
);
1225 PSB_WVDC32(arg
->sprite
.dspc_surface
, DSPCSURF
);
1226 PSB_RVDC32(DSPCSURF
);
1231 if (arg
->subpicture_enable_mask
!= 0) {
1232 if (gma_power_begin(dev
, usage
)) {
1234 if (arg
->subpicture_enable_mask
& REGRWBITS_DSPACNTR
) {
1235 temp
= PSB_RVDC32(DSPACNTR
);
1236 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1237 temp
&= ~DISPPLANE_BOTTOM
;
1238 temp
|= DISPPLANE_32BPP
;
1239 PSB_WVDC32(temp
, DSPACNTR
);
1241 temp
= PSB_RVDC32(DSPABASE
);
1242 PSB_WVDC32(temp
, DSPABASE
);
1243 PSB_RVDC32(DSPABASE
);
1244 temp
= PSB_RVDC32(DSPASURF
);
1245 PSB_WVDC32(temp
, DSPASURF
);
1246 PSB_RVDC32(DSPASURF
);
1248 if (arg
->subpicture_enable_mask
& REGRWBITS_DSPBCNTR
) {
1249 temp
= PSB_RVDC32(DSPBCNTR
);
1250 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1251 temp
&= ~DISPPLANE_BOTTOM
;
1252 temp
|= DISPPLANE_32BPP
;
1253 PSB_WVDC32(temp
, DSPBCNTR
);
1255 temp
= PSB_RVDC32(DSPBBASE
);
1256 PSB_WVDC32(temp
, DSPBBASE
);
1257 PSB_RVDC32(DSPBBASE
);
1258 temp
= PSB_RVDC32(DSPBSURF
);
1259 PSB_WVDC32(temp
, DSPBSURF
);
1260 PSB_RVDC32(DSPBSURF
);
1262 if (arg
->subpicture_enable_mask
& REGRWBITS_DSPCCNTR
) {
1263 temp
= PSB_RVDC32(DSPCCNTR
);
1264 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1265 temp
&= ~DISPPLANE_BOTTOM
;
1266 temp
|= DISPPLANE_32BPP
;
1267 PSB_WVDC32(temp
, DSPCCNTR
);
1269 temp
= PSB_RVDC32(DSPCBASE
);
1270 PSB_WVDC32(temp
, DSPCBASE
);
1271 PSB_RVDC32(DSPCBASE
);
1272 temp
= PSB_RVDC32(DSPCSURF
);
1273 PSB_WVDC32(temp
, DSPCSURF
);
1274 PSB_RVDC32(DSPCSURF
);
1280 if (arg
->subpicture_disable_mask
!= 0) {
1281 if (gma_power_begin(dev
, usage
)) {
1283 if (arg
->subpicture_disable_mask
& REGRWBITS_DSPACNTR
) {
1284 temp
= PSB_RVDC32(DSPACNTR
);
1285 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1286 temp
|= DISPPLANE_32BPP_NO_ALPHA
;
1287 PSB_WVDC32(temp
, DSPACNTR
);
1289 temp
= PSB_RVDC32(DSPABASE
);
1290 PSB_WVDC32(temp
, DSPABASE
);
1291 PSB_RVDC32(DSPABASE
);
1292 temp
= PSB_RVDC32(DSPASURF
);
1293 PSB_WVDC32(temp
, DSPASURF
);
1294 PSB_RVDC32(DSPASURF
);
1296 if (arg
->subpicture_disable_mask
& REGRWBITS_DSPBCNTR
) {
1297 temp
= PSB_RVDC32(DSPBCNTR
);
1298 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1299 temp
|= DISPPLANE_32BPP_NO_ALPHA
;
1300 PSB_WVDC32(temp
, DSPBCNTR
);
1302 temp
= PSB_RVDC32(DSPBBASE
);
1303 PSB_WVDC32(temp
, DSPBBASE
);
1304 PSB_RVDC32(DSPBBASE
);
1305 temp
= PSB_RVDC32(DSPBSURF
);
1306 PSB_WVDC32(temp
, DSPBSURF
);
1307 PSB_RVDC32(DSPBSURF
);
1309 if (arg
->subpicture_disable_mask
& REGRWBITS_DSPCCNTR
) {
1310 temp
= PSB_RVDC32(DSPCCNTR
);
1311 temp
&= ~DISPPLANE_PIXFORMAT_MASK
;
1312 temp
|= DISPPLANE_32BPP_NO_ALPHA
;
1313 PSB_WVDC32(temp
, DSPCCNTR
);
1315 temp
= PSB_RVDC32(DSPCBASE
);
1316 PSB_WVDC32(temp
, DSPCBASE
);
1317 PSB_RVDC32(DSPCBASE
);
1318 temp
= PSB_RVDC32(DSPCSURF
);
1319 PSB_WVDC32(temp
, DSPCSURF
);
1320 PSB_RVDC32(DSPCSURF
);
1329 static int psb_driver_open(struct drm_device
*dev
, struct drm_file
*priv
)
1334 static void psb_driver_close(struct drm_device
*dev
, struct drm_file
*priv
)
1338 static long psb_unlocked_ioctl(struct file
*filp
, unsigned int cmd
,
1341 struct drm_file
*file_priv
= filp
->private_data
;
1342 struct drm_device
*dev
= file_priv
->minor
->dev
;
1343 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
1344 static unsigned int runtime_allowed
;
1345 unsigned int nr
= DRM_IOCTL_NR(cmd
);
1347 DRM_DEBUG("cmd = %x, nr = %x\n", cmd
, nr
);
1349 if (runtime_allowed
== 1 && dev_priv
->is_lvds_on
) {
1351 pm_runtime_allow(&dev
->pdev
->dev
);
1352 dev_priv
->rpm_enabled
= 1;
1354 return drm_ioctl(filp
, cmd
, arg
);
1356 /* FIXME: do we need to wrap the other side of this */
1360 /* When a client dies:
1361 * - Check for and clean up flipped page state
1363 void psb_driver_preclose(struct drm_device
*dev
, struct drm_file
*priv
)
1367 static void psb_remove(struct pci_dev
*pdev
)
1369 struct drm_device
*dev
= pci_get_drvdata(pdev
);
1373 static const struct dev_pm_ops psb_pm_ops
= {
1374 .runtime_suspend
= psb_runtime_suspend
,
1375 .runtime_resume
= psb_runtime_resume
,
1376 .runtime_idle
= psb_runtime_idle
,
1379 static struct vm_operations_struct psb_gem_vm_ops
= {
1380 .fault
= psb_gem_fault
,
1381 .open
= drm_gem_vm_open
,
1382 .close
= drm_gem_vm_close
,
1385 static struct drm_driver driver
= {
1386 .driver_features
= DRIVER_HAVE_IRQ
| DRIVER_IRQ_SHARED
| \
1387 DRIVER_IRQ_VBL
| DRIVER_MODESET
| DRIVER_GEM
,
1388 .load
= psb_driver_load
,
1389 .unload
= psb_driver_unload
,
1391 .ioctls
= psb_ioctls
,
1392 .num_ioctls
= DRM_ARRAY_SIZE(psb_ioctls
),
1393 .device_is_agp
= psb_driver_device_is_agp
,
1394 .irq_preinstall
= psb_irq_preinstall
,
1395 .irq_postinstall
= psb_irq_postinstall
,
1396 .irq_uninstall
= psb_irq_uninstall
,
1397 .irq_handler
= psb_irq_handler
,
1398 .enable_vblank
= psb_enable_vblank
,
1399 .disable_vblank
= psb_disable_vblank
,
1400 .get_vblank_counter
= psb_get_vblank_counter
,
1401 .lastclose
= psb_lastclose
,
1402 .open
= psb_driver_open
,
1403 .preclose
= psb_driver_preclose
,
1404 .postclose
= psb_driver_close
,
1405 .reclaim_buffers
= drm_core_reclaim_buffers
,
1407 .gem_init_object
= psb_gem_init_object
,
1408 .gem_free_object
= psb_gem_free_object
,
1409 .gem_vm_ops
= &psb_gem_vm_ops
,
1410 .dumb_create
= psb_gem_dumb_create
,
1411 .dumb_map_offset
= psb_gem_dumb_map_gtt
,
1412 .dumb_destroy
= psb_gem_dumb_destroy
,
1415 .owner
= THIS_MODULE
,
1417 .release
= drm_release
,
1418 .unlocked_ioctl
= psb_unlocked_ioctl
,
1419 .mmap
= drm_gem_mmap
,
1421 .fasync
= drm_fasync
,
1424 .name
= DRIVER_NAME
,
1425 .desc
= DRIVER_DESC
,
1426 .date
= PSB_DRM_DRIVER_DATE
,
1427 .major
= PSB_DRM_DRIVER_MAJOR
,
1428 .minor
= PSB_DRM_DRIVER_MINOR
,
1429 .patchlevel
= PSB_DRM_DRIVER_PATCHLEVEL
1432 static struct pci_driver psb_pci_driver
= {
1433 .name
= DRIVER_NAME
,
1434 .id_table
= pciidlist
,
1435 .resume
= gma_power_resume
,
1436 .suspend
= gma_power_suspend
,
1438 .remove
= psb_remove
,
1440 .driver
.pm
= &psb_pm_ops
,
1444 static int psb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
1446 /* MLD Added this from Inaky's patch */
1447 if (pci_enable_msi(pdev
))
1448 DRM_ERROR("Enable MSI failed!\n");
1449 return drm_get_pci_dev(pdev
, ent
, &driver
);
1452 static int __init
psb_init(void)
1454 return drm_pci_init(&driver
, &psb_pci_driver
);
1457 static void __exit
psb_exit(void)
1459 drm_pci_exit(&driver
, &psb_pci_driver
);
1462 late_initcall(psb_init
);
1463 module_exit(psb_exit
);
1465 MODULE_AUTHOR(DRIVER_AUTHOR
);
1466 MODULE_DESCRIPTION(DRIVER_DESC
);
1467 MODULE_LICENSE("GPL");