gma500: Add support for inserting and removing pages from the GART
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / gma500 / psb_drv.h
blob4c983ff653606f885ec984f5cf678d372081da3d
1 /**************************************************************************
2 * Copyright (c) 2007-2008, Intel Corporation.
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 **************************************************************************/
20 #ifndef _PSB_DRV_H_
21 #define _PSB_DRV_H_
23 #include <linux/version.h>
24 #include <linux/kref.h>
26 #include <drm/drmP.h>
27 #include "drm_global.h"
28 #include "psb_drm.h"
29 #include "psb_reg.h"
30 #include "psb_intel_drv.h"
31 #include "psb_gtt.h"
32 #include "psb_powermgmt.h"
33 #include "mrst.h"
35 /*Append new drm mode definition here, align with libdrm definition*/
36 #define DRM_MODE_SCALE_NO_SCALE 2
38 extern struct ttm_bo_driver psb_ttm_bo_driver;
40 enum {
41 CHIP_PSB_8108 = 0,
42 CHIP_PSB_8109 = 1,
43 CHIP_MRST_4100 = 2,
46 #define IS_MRST(dev) (((dev)->pci_device & 0xfffc) == 0x4100)
49 *Hardware bugfixes
52 #define DRIVER_NAME "pvrsrvkm"
53 #define DRIVER_DESC "drm driver for the Intel GMA500"
54 #define DRIVER_AUTHOR "Intel Corporation"
56 #define PSB_DRM_DRIVER_DATE "2009-03-10"
57 #define PSB_DRM_DRIVER_MAJOR 8
58 #define PSB_DRM_DRIVER_MINOR 1
59 #define PSB_DRM_DRIVER_PATCHLEVEL 0
62 *TTM driver private offsets.
65 #define DRM_PSB_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
67 #define PSB_OBJECT_HASH_ORDER 13
68 #define PSB_FILE_OBJECT_HASH_ORDER 12
69 #define PSB_BO_HASH_ORDER 12
71 #define PSB_VDC_OFFSET 0x00000000
72 #define PSB_VDC_SIZE 0x000080000
73 #define MRST_MMIO_SIZE 0x0000C0000
74 #define MDFLD_MMIO_SIZE 0x000100000
75 #define PSB_SGX_SIZE 0x8000
76 #define PSB_SGX_OFFSET 0x00040000
77 #define MRST_SGX_OFFSET 0x00080000
78 #define PSB_MMIO_RESOURCE 0
79 #define PSB_GATT_RESOURCE 2
80 #define PSB_GTT_RESOURCE 3
81 #define PSB_GMCH_CTRL 0x52
82 #define PSB_BSM 0x5C
83 #define _PSB_GMCH_ENABLED 0x4
84 #define PSB_PGETBL_CTL 0x2020
85 #define _PSB_PGETBL_ENABLED 0x00000001
86 #define PSB_SGX_2D_SLAVE_PORT 0x4000
87 #define PSB_TT_PRIV0_LIMIT (256*1024*1024)
88 #define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT)
89 #define PSB_NUM_VALIDATE_BUFFERS 2048
92 *Flags for external memory type field.
95 #define PSB_MMU_CACHED_MEMORY 0x0001 /* Bind to MMU only */
96 #define PSB_MMU_RO_MEMORY 0x0002 /* MMU RO memory */
97 #define PSB_MMU_WO_MEMORY 0x0004 /* MMU WO memory */
100 *PTE's and PDE's
103 #define PSB_PDE_MASK 0x003FFFFF
104 #define PSB_PDE_SHIFT 22
105 #define PSB_PTE_SHIFT 12
107 #define PSB_PTE_VALID 0x0001 /* PTE / PDE valid */
108 #define PSB_PTE_WO 0x0002 /* Write only */
109 #define PSB_PTE_RO 0x0004 /* Read only */
110 #define PSB_PTE_CACHED 0x0008 /* CPU cache coherent */
113 *VDC registers and bits
115 #define PSB_MSVDX_CLOCKGATING 0x2064
116 #define PSB_TOPAZ_CLOCKGATING 0x2068
117 #define PSB_HWSTAM 0x2098
118 #define PSB_INSTPM 0x20C0
119 #define PSB_INT_IDENTITY_R 0x20A4
120 #define _MDFLD_PIPEC_EVENT_FLAG (1<<2)
121 #define _MDFLD_PIPEC_VBLANK_FLAG (1<<3)
122 #define _PSB_DPST_PIPEB_FLAG (1<<4)
123 #define _MDFLD_PIPEB_EVENT_FLAG (1<<4)
124 #define _PSB_VSYNC_PIPEB_FLAG (1<<5)
125 #define _PSB_DPST_PIPEA_FLAG (1<<6)
126 #define _PSB_PIPEA_EVENT_FLAG (1<<6)
127 #define _PSB_VSYNC_PIPEA_FLAG (1<<7)
128 #define _MDFLD_MIPIA_FLAG (1<<16)
129 #define _MDFLD_MIPIC_FLAG (1<<17)
130 #define _PSB_IRQ_SGX_FLAG (1<<18)
131 #define _PSB_IRQ_MSVDX_FLAG (1<<19)
132 #define _LNC_IRQ_TOPAZ_FLAG (1<<20)
134 /* This flag includes all the display IRQ bits excepts the vblank irqs. */
135 #define _MDFLD_DISP_ALL_IRQ_FLAG (_MDFLD_PIPEC_EVENT_FLAG | _MDFLD_PIPEB_EVENT_FLAG | \
136 _PSB_PIPEA_EVENT_FLAG | _PSB_VSYNC_PIPEA_FLAG | _MDFLD_MIPIA_FLAG | _MDFLD_MIPIC_FLAG)
137 #define PSB_INT_IDENTITY_R 0x20A4
138 #define PSB_INT_MASK_R 0x20A8
139 #define PSB_INT_ENABLE_R 0x20A0
141 #define _PSB_MMU_ER_MASK 0x0001FF00
142 #define _PSB_MMU_ER_HOST (1 << 16)
143 #define GPIOA 0x5010
144 #define GPIOB 0x5014
145 #define GPIOC 0x5018
146 #define GPIOD 0x501c
147 #define GPIOE 0x5020
148 #define GPIOF 0x5024
149 #define GPIOG 0x5028
150 #define GPIOH 0x502c
151 #define GPIO_CLOCK_DIR_MASK (1 << 0)
152 #define GPIO_CLOCK_DIR_IN (0 << 1)
153 #define GPIO_CLOCK_DIR_OUT (1 << 1)
154 #define GPIO_CLOCK_VAL_MASK (1 << 2)
155 #define GPIO_CLOCK_VAL_OUT (1 << 3)
156 #define GPIO_CLOCK_VAL_IN (1 << 4)
157 #define GPIO_CLOCK_PULLUP_DISABLE (1 << 5)
158 #define GPIO_DATA_DIR_MASK (1 << 8)
159 #define GPIO_DATA_DIR_IN (0 << 9)
160 #define GPIO_DATA_DIR_OUT (1 << 9)
161 #define GPIO_DATA_VAL_MASK (1 << 10)
162 #define GPIO_DATA_VAL_OUT (1 << 11)
163 #define GPIO_DATA_VAL_IN (1 << 12)
164 #define GPIO_DATA_PULLUP_DISABLE (1 << 13)
166 #define VCLK_DIVISOR_VGA0 0x6000
167 #define VCLK_DIVISOR_VGA1 0x6004
168 #define VCLK_POST_DIV 0x6010
170 #define PSB_COMM_2D (PSB_ENGINE_2D << 4)
171 #define PSB_COMM_3D (PSB_ENGINE_3D << 4)
172 #define PSB_COMM_TA (PSB_ENGINE_TA << 4)
173 #define PSB_COMM_HP (PSB_ENGINE_HP << 4)
174 #define PSB_COMM_USER_IRQ (1024 >> 2)
175 #define PSB_COMM_USER_IRQ_LOST (PSB_COMM_USER_IRQ + 1)
176 #define PSB_COMM_FW (2048 >> 2)
178 #define PSB_UIRQ_VISTEST 1
179 #define PSB_UIRQ_OOM_REPLY 2
180 #define PSB_UIRQ_FIRE_TA_REPLY 3
181 #define PSB_UIRQ_FIRE_RASTER_REPLY 4
183 #define PSB_2D_SIZE (256*1024*1024)
184 #define PSB_MAX_RELOC_PAGES 1024
186 #define PSB_LOW_REG_OFFS 0x0204
187 #define PSB_HIGH_REG_OFFS 0x0600
189 #define PSB_NUM_VBLANKS 2
192 #define PSB_2D_SIZE (256*1024*1024)
193 #define PSB_MAX_RELOC_PAGES 1024
195 #define PSB_LOW_REG_OFFS 0x0204
196 #define PSB_HIGH_REG_OFFS 0x0600
198 #define PSB_NUM_VBLANKS 2
199 #define PSB_WATCHDOG_DELAY (DRM_HZ * 2)
200 #define PSB_LID_DELAY (DRM_HZ / 10)
202 #define MDFLD_PNW_A0 0x00
203 #define MDFLD_PNW_B0 0x04
204 #define MDFLD_PNW_C0 0x08
206 #define PSB_PWR_STATE_ON 1
207 #define PSB_PWR_STATE_OFF 2
209 #define PSB_PMPOLICY_NOPM 0
210 #define PSB_PMPOLICY_CLOCKGATING 1
211 #define PSB_PMPOLICY_POWERDOWN 2
213 #define PSB_PMSTATE_POWERUP 0
214 #define PSB_PMSTATE_CLOCKGATED 1
215 #define PSB_PMSTATE_POWERDOWN 2
216 #define PSB_PCIx_MSI_ADDR_LOC 0x94
217 #define PSB_PCIx_MSI_DATA_LOC 0x98
219 struct opregion_header;
220 struct opregion_acpi;
221 struct opregion_swsci;
222 struct opregion_asle;
224 struct psb_intel_opregion {
225 struct opregion_header *header;
226 struct opregion_acpi *acpi;
227 struct opregion_swsci *swsci;
228 struct opregion_asle *asle;
229 int enabled;
233 struct drm_psb_private {
234 struct drm_device *dev;
236 unsigned long chipset;
238 struct psb_gtt *pg;
240 /* GTT Memory manager */
241 struct psb_gtt_mm *gtt_mm;
242 struct page *scratch_page;
243 u32 *gtt_map;
244 uint32_t stolen_base;
245 void *vram_addr;
246 unsigned long vram_stolen_size;
247 int gtt_initialized;
248 u16 gmch_ctrl; /* Saved GTT setup */
249 u32 pge_ctl;
251 struct mutex gtt_mutex;
252 struct resource *gtt_mem; /* Our PCI resource */
254 struct psb_mmu_driver *mmu;
255 struct psb_mmu_pd *pf_pd;
258 * Register base
261 uint8_t *sgx_reg;
262 uint8_t *vdc_reg;
263 uint32_t gatt_free_offset;
266 * Fencing / irq.
269 uint32_t vdc_irq_mask;
270 uint32_t pipestat[PSB_NUM_PIPE];
272 spinlock_t irqmask_lock;
275 * Power
278 bool suspended;
279 bool display_power;
280 int display_count;
283 *Modesetting
285 struct psb_intel_mode_device mode_dev;
287 struct drm_crtc *plane_to_crtc_mapping[PSB_NUM_PIPE];
288 struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE];
289 uint32_t num_pipe;
292 *Memory managers
296 *OSPM info
298 uint32_t ospm_base;
301 * Sizes info
304 struct drm_psb_sizes_arg sizes;
306 u32 fuse_reg_value;
307 u32 video_device_fuse;
309 /* pci revision id for B0:D2:F0 */
310 uint8_t platform_rev_id;
313 *LVDS info
315 int backlight_duty_cycle; /* restore backlight to this value */
316 bool panel_wants_dither;
317 struct drm_display_mode *panel_fixed_mode;
318 struct drm_display_mode *lfp_lvds_vbt_mode;
319 struct drm_display_mode *sdvo_lvds_vbt_mode;
321 struct bdb_lvds_backlight *lvds_bl; /*LVDS backlight info from VBT*/
322 struct psb_intel_i2c_chan *lvds_i2c_bus;
324 /* Feature bits from the VBIOS*/
325 unsigned int int_tv_support:1;
326 unsigned int lvds_dither:1;
327 unsigned int lvds_vbt:1;
328 unsigned int int_crt_support:1;
329 unsigned int lvds_use_ssc:1;
330 int lvds_ssc_freq;
331 bool is_lvds_on;
332 bool is_mipi_on;
334 unsigned int core_freq;
335 uint32_t iLVDS_enable;
337 /*runtime PM state*/
338 int rpm_enabled;
340 /* Moorestown specific */
341 struct mrst_vbt vbt_data;
342 struct mrst_gct_data gct_data;
344 /* Moorestown pipe config register value cache */
345 uint32_t pipeconf;
346 uint32_t pipeconf1;
347 uint32_t pipeconf2;
349 /* Moorestown plane control register value cache */
350 uint32_t dspcntr;
351 uint32_t dspcntr1;
352 uint32_t dspcntr2;
355 *Register state
357 uint32_t saveDSPACNTR;
358 uint32_t saveDSPBCNTR;
359 uint32_t savePIPEACONF;
360 uint32_t savePIPEBCONF;
361 uint32_t savePIPEASRC;
362 uint32_t savePIPEBSRC;
363 uint32_t saveFPA0;
364 uint32_t saveFPA1;
365 uint32_t saveDPLL_A;
366 uint32_t saveDPLL_A_MD;
367 uint32_t saveHTOTAL_A;
368 uint32_t saveHBLANK_A;
369 uint32_t saveHSYNC_A;
370 uint32_t saveVTOTAL_A;
371 uint32_t saveVBLANK_A;
372 uint32_t saveVSYNC_A;
373 uint32_t saveDSPASTRIDE;
374 uint32_t saveDSPASIZE;
375 uint32_t saveDSPAPOS;
376 uint32_t saveDSPABASE;
377 uint32_t saveDSPASURF;
378 uint32_t saveFPB0;
379 uint32_t saveFPB1;
380 uint32_t saveDPLL_B;
381 uint32_t saveDPLL_B_MD;
382 uint32_t saveHTOTAL_B;
383 uint32_t saveHBLANK_B;
384 uint32_t saveHSYNC_B;
385 uint32_t saveVTOTAL_B;
386 uint32_t saveVBLANK_B;
387 uint32_t saveVSYNC_B;
388 uint32_t saveDSPBSTRIDE;
389 uint32_t saveDSPBSIZE;
390 uint32_t saveDSPBPOS;
391 uint32_t saveDSPBBASE;
392 uint32_t saveDSPBSURF;
393 uint32_t saveVCLK_DIVISOR_VGA0;
394 uint32_t saveVCLK_DIVISOR_VGA1;
395 uint32_t saveVCLK_POST_DIV;
396 uint32_t saveVGACNTRL;
397 uint32_t saveADPA;
398 uint32_t saveLVDS;
399 uint32_t saveDVOA;
400 uint32_t saveDVOB;
401 uint32_t saveDVOC;
402 uint32_t savePP_ON;
403 uint32_t savePP_OFF;
404 uint32_t savePP_CONTROL;
405 uint32_t savePP_CYCLE;
406 uint32_t savePFIT_CONTROL;
407 uint32_t savePaletteA[256];
408 uint32_t savePaletteB[256];
409 uint32_t saveBLC_PWM_CTL2;
410 uint32_t saveBLC_PWM_CTL;
411 uint32_t saveCLOCKGATING;
412 uint32_t saveDSPARB;
413 uint32_t saveDSPATILEOFF;
414 uint32_t saveDSPBTILEOFF;
415 uint32_t saveDSPAADDR;
416 uint32_t saveDSPBADDR;
417 uint32_t savePFIT_AUTO_RATIOS;
418 uint32_t savePFIT_PGM_RATIOS;
419 uint32_t savePP_ON_DELAYS;
420 uint32_t savePP_OFF_DELAYS;
421 uint32_t savePP_DIVISOR;
422 uint32_t saveBSM;
423 uint32_t saveVBT;
424 uint32_t saveBCLRPAT_A;
425 uint32_t saveBCLRPAT_B;
426 uint32_t saveDSPALINOFF;
427 uint32_t saveDSPBLINOFF;
428 uint32_t savePERF_MODE;
429 uint32_t saveDSPFW1;
430 uint32_t saveDSPFW2;
431 uint32_t saveDSPFW3;
432 uint32_t saveDSPFW4;
433 uint32_t saveDSPFW5;
434 uint32_t saveDSPFW6;
435 uint32_t saveCHICKENBIT;
436 uint32_t saveDSPACURSOR_CTRL;
437 uint32_t saveDSPBCURSOR_CTRL;
438 uint32_t saveDSPACURSOR_BASE;
439 uint32_t saveDSPBCURSOR_BASE;
440 uint32_t saveDSPACURSOR_POS;
441 uint32_t saveDSPBCURSOR_POS;
442 uint32_t save_palette_a[256];
443 uint32_t save_palette_b[256];
444 uint32_t saveOV_OVADD;
445 uint32_t saveOV_OGAMC0;
446 uint32_t saveOV_OGAMC1;
447 uint32_t saveOV_OGAMC2;
448 uint32_t saveOV_OGAMC3;
449 uint32_t saveOV_OGAMC4;
450 uint32_t saveOV_OGAMC5;
451 uint32_t saveOVC_OVADD;
452 uint32_t saveOVC_OGAMC0;
453 uint32_t saveOVC_OGAMC1;
454 uint32_t saveOVC_OGAMC2;
455 uint32_t saveOVC_OGAMC3;
456 uint32_t saveOVC_OGAMC4;
457 uint32_t saveOVC_OGAMC5;
459 /* MSI reg save */
460 uint32_t msi_addr;
461 uint32_t msi_data;
464 * LID-Switch
466 spinlock_t lid_lock;
467 struct timer_list lid_timer;
468 struct psb_intel_opregion opregion;
469 u32 *lid_state;
470 u32 lid_last_state;
473 *Watchdog
476 uint32_t apm_reg;
477 uint16_t apm_base;
480 * Used for modifying backlight from
481 * xrandr -- consider removing and using HAL instead
483 struct drm_property *backlight_property;
484 uint32_t blc_adj1;
485 uint32_t blc_adj2;
487 void * fbdev;
491 struct psb_mmu_driver;
493 extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int);
494 extern int drm_pick_crtcs(struct drm_device *dev);
496 static inline struct drm_psb_private *psb_priv(struct drm_device *dev)
498 return (struct drm_psb_private *) dev->dev_private;
502 *MMU stuff.
505 extern struct psb_mmu_driver *psb_mmu_driver_init(uint8_t __iomem * registers,
506 int trap_pagefaults,
507 int invalid_type,
508 struct drm_psb_private *dev_priv);
509 extern void psb_mmu_driver_takedown(struct psb_mmu_driver *driver);
510 extern struct psb_mmu_pd *psb_mmu_get_default_pd(struct psb_mmu_driver
511 *driver);
512 extern void psb_mmu_mirror_gtt(struct psb_mmu_pd *pd, uint32_t mmu_offset,
513 uint32_t gtt_start, uint32_t gtt_pages);
514 extern struct psb_mmu_pd *psb_mmu_alloc_pd(struct psb_mmu_driver *driver,
515 int trap_pagefaults,
516 int invalid_type);
517 extern void psb_mmu_free_pagedir(struct psb_mmu_pd *pd);
518 extern void psb_mmu_flush(struct psb_mmu_driver *driver, int rc_prot);
519 extern void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd *pd,
520 unsigned long address,
521 uint32_t num_pages);
522 extern int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd *pd,
523 uint32_t start_pfn,
524 unsigned long address,
525 uint32_t num_pages, int type);
526 extern int psb_mmu_virtual_to_pfn(struct psb_mmu_pd *pd, uint32_t virtual,
527 unsigned long *pfn);
530 *Enable / disable MMU for different requestors.
534 extern void psb_mmu_set_pd_context(struct psb_mmu_pd *pd, int hw_context);
535 extern int psb_mmu_insert_pages(struct psb_mmu_pd *pd, struct page **pages,
536 unsigned long address, uint32_t num_pages,
537 uint32_t desired_tile_stride,
538 uint32_t hw_tile_stride, int type);
539 extern void psb_mmu_remove_pages(struct psb_mmu_pd *pd,
540 unsigned long address, uint32_t num_pages,
541 uint32_t desired_tile_stride,
542 uint32_t hw_tile_stride);
544 *psb_irq.c
547 extern irqreturn_t psb_irq_handler(DRM_IRQ_ARGS);
548 extern int psb_irq_enable_dpst(struct drm_device *dev);
549 extern int psb_irq_disable_dpst(struct drm_device *dev);
550 extern void psb_irq_preinstall(struct drm_device *dev);
551 extern int psb_irq_postinstall(struct drm_device *dev);
552 extern void psb_irq_uninstall(struct drm_device *dev);
553 extern void psb_irq_turn_on_dpst(struct drm_device *dev);
554 extern void psb_irq_turn_off_dpst(struct drm_device *dev);
556 extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
557 extern int psb_vblank_wait2(struct drm_device *dev,unsigned int *sequence);
558 extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
559 extern int psb_enable_vblank(struct drm_device *dev, int crtc);
560 extern void psb_disable_vblank(struct drm_device *dev, int crtc);
561 void
562 psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
564 void
565 psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
567 extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc);
570 * psb_opregion.c
572 extern int psb_intel_opregion_init(struct drm_device *dev);
575 *psb_fb.c
577 extern int psbfb_probed(struct drm_device *dev);
578 extern int psbfb_remove(struct drm_device *dev,
579 struct drm_framebuffer *fb);
580 extern int psbfb_kms_off_ioctl(struct drm_device *dev, void *data,
581 struct drm_file *file_priv);
582 extern int psbfb_kms_on_ioctl(struct drm_device *dev, void *data,
583 struct drm_file *file_priv);
584 extern void *psbfb_vdc_reg(struct drm_device* dev);
587 * psb_2d.c
589 extern void psbfb_fillrect(struct fb_info *info,
590 const struct fb_fillrect *rect);
591 extern void psbfb_copyarea(struct fb_info *info,
592 const struct fb_copyarea *region);
593 extern void psbfb_imageblit(struct fb_info *info,
594 const struct fb_image *image);
595 extern int psbfb_sync(struct fb_info *info);
597 extern void psb_spank(struct drm_psb_private *dev_priv);
599 extern int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf,
600 unsigned size);
603 *psb_reset.c
606 extern void psb_lid_timer_init(struct drm_psb_private *dev_priv);
607 extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
608 extern void psb_print_pagefault(struct drm_psb_private *dev_priv);
610 /* modesetting */
611 extern void psb_modeset_init(struct drm_device *dev);
612 extern void psb_modeset_cleanup(struct drm_device *dev);
613 extern int psb_fbdev_init(struct drm_device * dev);
615 /* psb_bl.c */
616 int psb_backlight_init(struct drm_device *dev);
617 void psb_backlight_exit(void);
618 int psb_set_brightness(struct backlight_device *bd);
619 int psb_get_brightness(struct backlight_device *bd);
620 struct backlight_device * psb_get_backlight_device(void);
622 /* mrst_crtc.c */
623 extern const struct drm_crtc_helper_funcs mrst_helper_funcs;
625 /* mrst_lvds.c */
626 extern void mrst_lvds_init(struct drm_device *dev,
627 struct psb_intel_mode_device *mode_dev);
629 /* psb_intel_lvds.c */
630 extern void psb_intel_lvds_prepare(struct drm_encoder *encoder);
631 extern void psb_intel_lvds_commit(struct drm_encoder *encoder);
632 extern const struct drm_connector_helper_funcs
633 psb_intel_lvds_connector_helper_funcs;
634 extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
636 /* psb_gem.c */
637 extern int psb_gem_init_object(struct drm_gem_object *obj);
638 extern void psb_gem_free_object(struct drm_gem_object *obj);
639 extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
640 struct drm_file *file);
641 extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
642 struct drm_mode_create_dumb *args);
643 extern int psb_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
644 uint32_t handle);
645 extern int psb_gem_dumb_map_gtt(struct drm_file *file, struct drm_device *dev,
646 uint32_t handle, uint64_t *offset);
647 extern int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
651 * Debug print bits setting
653 #define PSB_D_GENERAL (1 << 0)
654 #define PSB_D_INIT (1 << 1)
655 #define PSB_D_IRQ (1 << 2)
656 #define PSB_D_ENTRY (1 << 3)
657 /* debug the get H/V BP/FP count */
658 #define PSB_D_HV (1 << 4)
659 #define PSB_D_DBI_BF (1 << 5)
660 #define PSB_D_PM (1 << 6)
661 #define PSB_D_RENDER (1 << 7)
662 #define PSB_D_REG (1 << 8)
663 #define PSB_D_MSVDX (1 << 9)
664 #define PSB_D_TOPAZ (1 << 10)
666 #ifndef DRM_DEBUG_CODE
667 /* To enable debug printout, set drm_psb_debug in psb_drv.c
668 * to any combination of above print flags.
670 /* #define DRM_DEBUG_CODE 2 */
671 #endif
673 extern int drm_psb_debug;
674 extern int drm_psb_no_fb;
675 extern int drm_idle_check_interval;
677 #define PSB_DEBUG_GENERAL(_fmt, _arg...) \
678 PSB_DEBUG(PSB_D_GENERAL, _fmt, ##_arg)
679 #define PSB_DEBUG_INIT(_fmt, _arg...) \
680 PSB_DEBUG(PSB_D_INIT, _fmt, ##_arg)
681 #define PSB_DEBUG_IRQ(_fmt, _arg...) \
682 PSB_DEBUG(PSB_D_IRQ, _fmt, ##_arg)
683 #define PSB_DEBUG_ENTRY(_fmt, _arg...) \
684 PSB_DEBUG(PSB_D_ENTRY, _fmt, ##_arg)
685 #define PSB_DEBUG_HV(_fmt, _arg...) \
686 PSB_DEBUG(PSB_D_HV, _fmt, ##_arg)
687 #define PSB_DEBUG_DBI_BF(_fmt, _arg...) \
688 PSB_DEBUG(PSB_D_DBI_BF, _fmt, ##_arg)
689 #define PSB_DEBUG_PM(_fmt, _arg...) \
690 PSB_DEBUG(PSB_D_PM, _fmt, ##_arg)
691 #define PSB_DEBUG_RENDER(_fmt, _arg...) \
692 PSB_DEBUG(PSB_D_RENDER, _fmt, ##_arg)
693 #define PSB_DEBUG_REG(_fmt, _arg...) \
694 PSB_DEBUG(PSB_D_REG, _fmt, ##_arg)
695 #define PSB_DEBUG_MSVDX(_fmt, _arg...) \
696 PSB_DEBUG(PSB_D_MSVDX, _fmt, ##_arg)
697 #define PSB_DEBUG_TOPAZ(_fmt, _arg...) \
698 PSB_DEBUG(PSB_D_TOPAZ, _fmt, ##_arg)
700 #if DRM_DEBUG_CODE
701 #define PSB_DEBUG(_flag, _fmt, _arg...) \
702 do { \
703 if (unlikely((_flag) & drm_psb_debug)) \
704 printk(KERN_DEBUG \
705 "[psb:0x%02x:%s] " _fmt , _flag, \
706 __func__ , ##_arg); \
707 } while (0)
708 #else
709 #define PSB_DEBUG(_fmt, _arg...) do { } while (0)
710 #endif
713 *Utilities
715 #define DRM_DRIVER_PRIVATE_T struct drm_psb_private
717 static inline u32 MRST_MSG_READ32(uint port, uint offset)
719 int mcr = (0xD0<<24) | (port << 16) | (offset << 8);
720 uint32_t ret_val = 0;
721 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
722 pci_write_config_dword (pci_root, 0xD0, mcr);
723 pci_read_config_dword (pci_root, 0xD4, &ret_val);
724 pci_dev_put(pci_root);
725 return ret_val;
727 static inline void MRST_MSG_WRITE32(uint port, uint offset, u32 value)
729 int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0;
730 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
731 pci_write_config_dword (pci_root, 0xD4, value);
732 pci_write_config_dword (pci_root, 0xD0, mcr);
733 pci_dev_put(pci_root);
735 static inline u32 MDFLD_MSG_READ32(uint port, uint offset)
737 int mcr = (0x10<<24) | (port << 16) | (offset << 8);
738 uint32_t ret_val = 0;
739 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
740 pci_write_config_dword (pci_root, 0xD0, mcr);
741 pci_read_config_dword (pci_root, 0xD4, &ret_val);
742 pci_dev_put(pci_root);
743 return ret_val;
745 static inline void MDFLD_MSG_WRITE32(uint port, uint offset, u32 value)
747 int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0;
748 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
749 pci_write_config_dword (pci_root, 0xD4, value);
750 pci_write_config_dword (pci_root, 0xD0, mcr);
751 pci_dev_put(pci_root);
754 static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg)
756 struct drm_psb_private *dev_priv = dev->dev_private;
757 int reg_val = ioread32(dev_priv->vdc_reg + (reg));
758 PSB_DEBUG_REG("reg = 0x%x. reg_val = 0x%x. \n", reg, reg_val);
759 return reg_val;
762 #define REG_READ(reg) REGISTER_READ(dev, (reg))
763 static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg,
764 uint32_t val)
766 struct drm_psb_private *dev_priv = dev->dev_private;
767 if ((reg < 0x70084 || reg >0x70088) && (reg < 0xa000 || reg >0xa3ff))
768 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
770 iowrite32((val), dev_priv->vdc_reg + (reg));
773 #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
775 static inline void REGISTER_WRITE16(struct drm_device *dev,
776 uint32_t reg, uint32_t val)
778 struct drm_psb_private *dev_priv = dev->dev_private;
780 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
782 iowrite16((val), dev_priv->vdc_reg + (reg));
785 #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
787 static inline void REGISTER_WRITE8(struct drm_device *dev,
788 uint32_t reg, uint32_t val)
790 struct drm_psb_private *dev_priv = dev->dev_private;
792 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
794 iowrite8((val), dev_priv->vdc_reg + (reg));
797 #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
799 #define PSB_ALIGN_TO(_val, _align) \
800 (((_val) + ((_align) - 1)) & ~((_align) - 1))
801 #define PSB_WVDC32(_val, _offs) \
802 iowrite32(_val, dev_priv->vdc_reg + (_offs))
803 #define PSB_RVDC32(_offs) \
804 ioread32(dev_priv->vdc_reg + (_offs))
806 /* #define TRAP_SGX_PM_FAULT 1 */
807 #ifdef TRAP_SGX_PM_FAULT
808 #define PSB_RSGX32(_offs) \
809 ({ \
810 if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
811 printk(KERN_ERR "access sgx when it's off!! (READ) %s, %d\n", \
812 __FILE__, __LINE__); \
813 mdelay(1000); \
815 ioread32(dev_priv->sgx_reg + (_offs)); \
817 #else
818 #define PSB_RSGX32(_offs) \
819 ioread32(dev_priv->sgx_reg + (_offs))
820 #endif
821 #define PSB_WSGX32(_val, _offs) \
822 iowrite32(_val, dev_priv->sgx_reg + (_offs))
824 #define MSVDX_REG_DUMP 0
825 #if MSVDX_REG_DUMP
827 #define PSB_WMSVDX32(_val, _offs) \
828 printk("MSVDX: write %08x to reg 0x%08x\n", (unsigned int)(_val), (unsigned int)(_offs));\
829 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
830 #define PSB_RMSVDX32(_offs) \
831 ioread32(dev_priv->msvdx_reg + (_offs))
833 #else
835 #define PSB_WMSVDX32(_val, _offs) \
836 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
837 #define PSB_RMSVDX32(_offs) \
838 ioread32(dev_priv->msvdx_reg + (_offs))
840 #endif
842 #define PSB_ALPL(_val, _base) \
843 (((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT))
844 #define PSB_ALPLM(_val, _base) \
845 ((((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT)) & (_base ## _MASK))
847 #endif