gma500: polish for completion of this phase
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / gma500 / psb_drv.h
blobc0468ee25a47a37a6bf519832d106d9e06d27c5c
1 /**************************************************************************
2 * Copyright (c) 2007-2011, 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 enum {
39 CHIP_PSB_8108 = 0, /* Poulsbo */
40 CHIP_PSB_8109 = 1, /* Poulsbo */
41 CHIP_MRST_4100 = 2, /* Moorestown/Oaktrail */
44 #define IS_MRST(dev) (((dev)->pci_device & 0xfffc) == 0x4100)
47 * Driver definitions
50 #define DRIVER_NAME "gma500"
51 #define DRIVER_DESC "DRM driver for the Intel GMA500"
53 #define PSB_DRM_DRIVER_DATE "2011-06-06"
54 #define PSB_DRM_DRIVER_MAJOR 1
55 #define PSB_DRM_DRIVER_MINOR 0
56 #define PSB_DRM_DRIVER_PATCHLEVEL 0
59 * Hardware offsets
61 #define PSB_VDC_OFFSET 0x00000000
62 #define PSB_VDC_SIZE 0x000080000
63 #define MRST_MMIO_SIZE 0x0000C0000
64 #define MDFLD_MMIO_SIZE 0x000100000
65 #define PSB_SGX_SIZE 0x8000
66 #define PSB_SGX_OFFSET 0x00040000
67 #define MRST_SGX_OFFSET 0x00080000
69 * PCI resource identifiers
71 #define PSB_MMIO_RESOURCE 0
72 #define PSB_GATT_RESOURCE 2
73 #define PSB_GTT_RESOURCE 3
75 * PCI configuration
77 #define PSB_GMCH_CTRL 0x52
78 #define PSB_BSM 0x5C
79 #define _PSB_GMCH_ENABLED 0x4
80 #define PSB_PGETBL_CTL 0x2020
81 #define _PSB_PGETBL_ENABLED 0x00000001
82 #define PSB_SGX_2D_SLAVE_PORT 0x4000
84 /* To get rid of */
85 #define PSB_TT_PRIV0_LIMIT (256*1024*1024)
86 #define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT)
89 * SGX side MMU definitions (these can probably go)
93 * 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 */
99 * PTE's and PDE's
101 #define PSB_PDE_MASK 0x003FFFFF
102 #define PSB_PDE_SHIFT 22
103 #define PSB_PTE_SHIFT 12
105 * Cache control
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 * OSPM info (Power management base) (can go ?)
294 uint32_t ospm_base;
297 * Sizes info
300 struct drm_psb_sizes_arg sizes;
302 u32 fuse_reg_value;
303 u32 video_device_fuse;
305 /* PCI revision ID for B0:D2:F0 */
306 uint8_t platform_rev_id;
309 * LVDS info
311 int backlight_duty_cycle; /* restore backlight to this value */
312 bool panel_wants_dither;
313 struct drm_display_mode *panel_fixed_mode;
314 struct drm_display_mode *lfp_lvds_vbt_mode;
315 struct drm_display_mode *sdvo_lvds_vbt_mode;
317 struct bdb_lvds_backlight *lvds_bl; /* LVDS backlight info from VBT */
318 struct psb_intel_i2c_chan *lvds_i2c_bus;
320 /* Feature bits from the VBIOS */
321 unsigned int int_tv_support:1;
322 unsigned int lvds_dither:1;
323 unsigned int lvds_vbt:1;
324 unsigned int int_crt_support:1;
325 unsigned int lvds_use_ssc:1;
326 int lvds_ssc_freq;
327 bool is_lvds_on;
328 bool is_mipi_on;
330 unsigned int core_freq;
331 uint32_t iLVDS_enable;
333 /* Runtime PM state */
334 int rpm_enabled;
336 /* Moorestown specific */
337 struct mrst_vbt vbt_data;
338 struct mrst_gct_data gct_data;
340 /* Moorestown pipe config register value cache */
341 uint32_t pipeconf;
342 uint32_t pipeconf1;
343 uint32_t pipeconf2;
345 /* Moorestown plane control register value cache */
346 uint32_t dspcntr;
347 uint32_t dspcntr1;
348 uint32_t dspcntr2;
351 * Register state
353 uint32_t saveDSPACNTR;
354 uint32_t saveDSPBCNTR;
355 uint32_t savePIPEACONF;
356 uint32_t savePIPEBCONF;
357 uint32_t savePIPEASRC;
358 uint32_t savePIPEBSRC;
359 uint32_t saveFPA0;
360 uint32_t saveFPA1;
361 uint32_t saveDPLL_A;
362 uint32_t saveDPLL_A_MD;
363 uint32_t saveHTOTAL_A;
364 uint32_t saveHBLANK_A;
365 uint32_t saveHSYNC_A;
366 uint32_t saveVTOTAL_A;
367 uint32_t saveVBLANK_A;
368 uint32_t saveVSYNC_A;
369 uint32_t saveDSPASTRIDE;
370 uint32_t saveDSPASIZE;
371 uint32_t saveDSPAPOS;
372 uint32_t saveDSPABASE;
373 uint32_t saveDSPASURF;
374 uint32_t saveFPB0;
375 uint32_t saveFPB1;
376 uint32_t saveDPLL_B;
377 uint32_t saveDPLL_B_MD;
378 uint32_t saveHTOTAL_B;
379 uint32_t saveHBLANK_B;
380 uint32_t saveHSYNC_B;
381 uint32_t saveVTOTAL_B;
382 uint32_t saveVBLANK_B;
383 uint32_t saveVSYNC_B;
384 uint32_t saveDSPBSTRIDE;
385 uint32_t saveDSPBSIZE;
386 uint32_t saveDSPBPOS;
387 uint32_t saveDSPBBASE;
388 uint32_t saveDSPBSURF;
389 uint32_t saveVCLK_DIVISOR_VGA0;
390 uint32_t saveVCLK_DIVISOR_VGA1;
391 uint32_t saveVCLK_POST_DIV;
392 uint32_t saveVGACNTRL;
393 uint32_t saveADPA;
394 uint32_t saveLVDS;
395 uint32_t saveDVOA;
396 uint32_t saveDVOB;
397 uint32_t saveDVOC;
398 uint32_t savePP_ON;
399 uint32_t savePP_OFF;
400 uint32_t savePP_CONTROL;
401 uint32_t savePP_CYCLE;
402 uint32_t savePFIT_CONTROL;
403 uint32_t savePaletteA[256];
404 uint32_t savePaletteB[256];
405 uint32_t saveBLC_PWM_CTL2;
406 uint32_t saveBLC_PWM_CTL;
407 uint32_t saveCLOCKGATING;
408 uint32_t saveDSPARB;
409 uint32_t saveDSPATILEOFF;
410 uint32_t saveDSPBTILEOFF;
411 uint32_t saveDSPAADDR;
412 uint32_t saveDSPBADDR;
413 uint32_t savePFIT_AUTO_RATIOS;
414 uint32_t savePFIT_PGM_RATIOS;
415 uint32_t savePP_ON_DELAYS;
416 uint32_t savePP_OFF_DELAYS;
417 uint32_t savePP_DIVISOR;
418 uint32_t saveBSM;
419 uint32_t saveVBT;
420 uint32_t saveBCLRPAT_A;
421 uint32_t saveBCLRPAT_B;
422 uint32_t saveDSPALINOFF;
423 uint32_t saveDSPBLINOFF;
424 uint32_t savePERF_MODE;
425 uint32_t saveDSPFW1;
426 uint32_t saveDSPFW2;
427 uint32_t saveDSPFW3;
428 uint32_t saveDSPFW4;
429 uint32_t saveDSPFW5;
430 uint32_t saveDSPFW6;
431 uint32_t saveCHICKENBIT;
432 uint32_t saveDSPACURSOR_CTRL;
433 uint32_t saveDSPBCURSOR_CTRL;
434 uint32_t saveDSPACURSOR_BASE;
435 uint32_t saveDSPBCURSOR_BASE;
436 uint32_t saveDSPACURSOR_POS;
437 uint32_t saveDSPBCURSOR_POS;
438 uint32_t save_palette_a[256];
439 uint32_t save_palette_b[256];
440 uint32_t saveOV_OVADD;
441 uint32_t saveOV_OGAMC0;
442 uint32_t saveOV_OGAMC1;
443 uint32_t saveOV_OGAMC2;
444 uint32_t saveOV_OGAMC3;
445 uint32_t saveOV_OGAMC4;
446 uint32_t saveOV_OGAMC5;
447 uint32_t saveOVC_OVADD;
448 uint32_t saveOVC_OGAMC0;
449 uint32_t saveOVC_OGAMC1;
450 uint32_t saveOVC_OGAMC2;
451 uint32_t saveOVC_OGAMC3;
452 uint32_t saveOVC_OGAMC4;
453 uint32_t saveOVC_OGAMC5;
455 /* MSI reg save */
456 uint32_t msi_addr;
457 uint32_t msi_data;
460 * LID-Switch
462 spinlock_t lid_lock;
463 struct timer_list lid_timer;
464 struct psb_intel_opregion opregion;
465 u32 *lid_state;
466 u32 lid_last_state;
469 * Watchdog
472 uint32_t apm_reg;
473 uint16_t apm_base;
476 * Used for modifying backlight from
477 * xrandr -- consider removing and using HAL instead
479 struct drm_property *backlight_property;
480 uint32_t blc_adj1;
481 uint32_t blc_adj2;
483 void * fbdev;
487 struct psb_mmu_driver;
489 extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int);
490 extern int drm_pick_crtcs(struct drm_device *dev);
492 static inline struct drm_psb_private *psb_priv(struct drm_device *dev)
494 return (struct drm_psb_private *) dev->dev_private;
498 * MMU stuff.
501 extern struct psb_mmu_driver *psb_mmu_driver_init(uint8_t __iomem * registers,
502 int trap_pagefaults,
503 int invalid_type,
504 struct drm_psb_private *dev_priv);
505 extern void psb_mmu_driver_takedown(struct psb_mmu_driver *driver);
506 extern struct psb_mmu_pd *psb_mmu_get_default_pd(struct psb_mmu_driver
507 *driver);
508 extern void psb_mmu_mirror_gtt(struct psb_mmu_pd *pd, uint32_t mmu_offset,
509 uint32_t gtt_start, uint32_t gtt_pages);
510 extern struct psb_mmu_pd *psb_mmu_alloc_pd(struct psb_mmu_driver *driver,
511 int trap_pagefaults,
512 int invalid_type);
513 extern void psb_mmu_free_pagedir(struct psb_mmu_pd *pd);
514 extern void psb_mmu_flush(struct psb_mmu_driver *driver, int rc_prot);
515 extern void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd *pd,
516 unsigned long address,
517 uint32_t num_pages);
518 extern int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd *pd,
519 uint32_t start_pfn,
520 unsigned long address,
521 uint32_t num_pages, int type);
522 extern int psb_mmu_virtual_to_pfn(struct psb_mmu_pd *pd, uint32_t virtual,
523 unsigned long *pfn);
526 * Enable / disable MMU for different requestors.
530 extern void psb_mmu_set_pd_context(struct psb_mmu_pd *pd, int hw_context);
531 extern int psb_mmu_insert_pages(struct psb_mmu_pd *pd, struct page **pages,
532 unsigned long address, uint32_t num_pages,
533 uint32_t desired_tile_stride,
534 uint32_t hw_tile_stride, int type);
535 extern void psb_mmu_remove_pages(struct psb_mmu_pd *pd,
536 unsigned long address, uint32_t num_pages,
537 uint32_t desired_tile_stride,
538 uint32_t hw_tile_stride);
540 *psb_irq.c
543 extern irqreturn_t psb_irq_handler(DRM_IRQ_ARGS);
544 extern int psb_irq_enable_dpst(struct drm_device *dev);
545 extern int psb_irq_disable_dpst(struct drm_device *dev);
546 extern void psb_irq_preinstall(struct drm_device *dev);
547 extern int psb_irq_postinstall(struct drm_device *dev);
548 extern void psb_irq_uninstall(struct drm_device *dev);
549 extern void psb_irq_turn_on_dpst(struct drm_device *dev);
550 extern void psb_irq_turn_off_dpst(struct drm_device *dev);
552 extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
553 extern int psb_vblank_wait2(struct drm_device *dev,unsigned int *sequence);
554 extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
555 extern int psb_enable_vblank(struct drm_device *dev, int crtc);
556 extern void psb_disable_vblank(struct drm_device *dev, int crtc);
557 void
558 psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
560 void
561 psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
563 extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc);
566 * psb_opregion.c
568 extern int psb_intel_opregion_init(struct drm_device *dev);
571 *psb_fb.c
573 extern int psbfb_probed(struct drm_device *dev);
574 extern int psbfb_remove(struct drm_device *dev,
575 struct drm_framebuffer *fb);
576 extern int psbfb_kms_off_ioctl(struct drm_device *dev, void *data,
577 struct drm_file *file_priv);
578 extern int psbfb_kms_on_ioctl(struct drm_device *dev, void *data,
579 struct drm_file *file_priv);
580 extern void *psbfb_vdc_reg(struct drm_device* dev);
583 * psb_2d.c
585 extern void psbfb_fillrect(struct fb_info *info,
586 const struct fb_fillrect *rect);
587 extern void psbfb_copyarea(struct fb_info *info,
588 const struct fb_copyarea *region);
589 extern void psbfb_imageblit(struct fb_info *info,
590 const struct fb_image *image);
591 extern int psbfb_sync(struct fb_info *info);
593 extern void psb_spank(struct drm_psb_private *dev_priv);
595 extern int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf,
596 unsigned size);
599 * psb_reset.c
602 extern void psb_lid_timer_init(struct drm_psb_private *dev_priv);
603 extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
604 extern void psb_print_pagefault(struct drm_psb_private *dev_priv);
606 /* modesetting */
607 extern void psb_modeset_init(struct drm_device *dev);
608 extern void psb_modeset_cleanup(struct drm_device *dev);
609 extern int psb_fbdev_init(struct drm_device * dev);
611 /* psb_bl.c */
612 int psb_backlight_init(struct drm_device *dev);
613 void psb_backlight_exit(void);
614 int psb_set_brightness(struct backlight_device *bd);
615 int psb_get_brightness(struct backlight_device *bd);
616 struct backlight_device * psb_get_backlight_device(void);
618 /* mrst_crtc.c */
619 extern const struct drm_crtc_helper_funcs mrst_helper_funcs;
621 /* mrst_lvds.c */
622 extern void mrst_lvds_init(struct drm_device *dev,
623 struct psb_intel_mode_device *mode_dev);
625 /* psb_intel_lvds.c */
626 extern void psb_intel_lvds_prepare(struct drm_encoder *encoder);
627 extern void psb_intel_lvds_commit(struct drm_encoder *encoder);
628 extern const struct drm_connector_helper_funcs
629 psb_intel_lvds_connector_helper_funcs;
630 extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
632 /* psb_gem.c */
633 extern int psb_gem_init_object(struct drm_gem_object *obj);
634 extern void psb_gem_free_object(struct drm_gem_object *obj);
635 extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
636 struct drm_file *file);
637 extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
638 struct drm_mode_create_dumb *args);
639 extern int psb_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
640 uint32_t handle);
641 extern int psb_gem_dumb_map_gtt(struct drm_file *file, struct drm_device *dev,
642 uint32_t handle, uint64_t *offset);
643 extern int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
647 * Debug print bits setting
649 #define PSB_D_GENERAL (1 << 0)
650 #define PSB_D_INIT (1 << 1)
651 #define PSB_D_IRQ (1 << 2)
652 #define PSB_D_ENTRY (1 << 3)
653 /* debug the get H/V BP/FP count */
654 #define PSB_D_HV (1 << 4)
655 #define PSB_D_DBI_BF (1 << 5)
656 #define PSB_D_PM (1 << 6)
657 #define PSB_D_RENDER (1 << 7)
658 #define PSB_D_REG (1 << 8)
659 #define PSB_D_MSVDX (1 << 9)
660 #define PSB_D_TOPAZ (1 << 10)
662 #ifndef DRM_DEBUG_CODE
663 /* To enable debug printout, set drm_psb_debug in psb_drv.c
664 * to any combination of above print flags.
666 /* #define DRM_DEBUG_CODE 2 */
667 #endif
669 extern int drm_psb_debug;
670 extern int drm_psb_no_fb;
671 extern int drm_idle_check_interval;
673 #define PSB_DEBUG_GENERAL(_fmt, _arg...) \
674 PSB_DEBUG(PSB_D_GENERAL, _fmt, ##_arg)
675 #define PSB_DEBUG_INIT(_fmt, _arg...) \
676 PSB_DEBUG(PSB_D_INIT, _fmt, ##_arg)
677 #define PSB_DEBUG_IRQ(_fmt, _arg...) \
678 PSB_DEBUG(PSB_D_IRQ, _fmt, ##_arg)
679 #define PSB_DEBUG_ENTRY(_fmt, _arg...) \
680 PSB_DEBUG(PSB_D_ENTRY, _fmt, ##_arg)
681 #define PSB_DEBUG_HV(_fmt, _arg...) \
682 PSB_DEBUG(PSB_D_HV, _fmt, ##_arg)
683 #define PSB_DEBUG_DBI_BF(_fmt, _arg...) \
684 PSB_DEBUG(PSB_D_DBI_BF, _fmt, ##_arg)
685 #define PSB_DEBUG_PM(_fmt, _arg...) \
686 PSB_DEBUG(PSB_D_PM, _fmt, ##_arg)
687 #define PSB_DEBUG_RENDER(_fmt, _arg...) \
688 PSB_DEBUG(PSB_D_RENDER, _fmt, ##_arg)
689 #define PSB_DEBUG_REG(_fmt, _arg...) \
690 PSB_DEBUG(PSB_D_REG, _fmt, ##_arg)
691 #define PSB_DEBUG_MSVDX(_fmt, _arg...) \
692 PSB_DEBUG(PSB_D_MSVDX, _fmt, ##_arg)
693 #define PSB_DEBUG_TOPAZ(_fmt, _arg...) \
694 PSB_DEBUG(PSB_D_TOPAZ, _fmt, ##_arg)
696 #if DRM_DEBUG_CODE
697 #define PSB_DEBUG(_flag, _fmt, _arg...) \
698 do { \
699 if (unlikely((_flag) & drm_psb_debug)) \
700 printk(KERN_DEBUG \
701 "[psb:0x%02x:%s] " _fmt , _flag, \
702 __func__ , ##_arg); \
703 } while (0)
704 #else
705 #define PSB_DEBUG(_fmt, _arg...) do { } while (0)
706 #endif
709 *Utilities
712 static inline u32 MRST_MSG_READ32(uint port, uint offset)
714 int mcr = (0xD0<<24) | (port << 16) | (offset << 8);
715 uint32_t ret_val = 0;
716 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
717 pci_write_config_dword (pci_root, 0xD0, mcr);
718 pci_read_config_dword (pci_root, 0xD4, &ret_val);
719 pci_dev_put(pci_root);
720 return ret_val;
722 static inline void MRST_MSG_WRITE32(uint port, uint offset, u32 value)
724 int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0;
725 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
726 pci_write_config_dword (pci_root, 0xD4, value);
727 pci_write_config_dword (pci_root, 0xD0, mcr);
728 pci_dev_put(pci_root);
730 static inline u32 MDFLD_MSG_READ32(uint port, uint offset)
732 int mcr = (0x10<<24) | (port << 16) | (offset << 8);
733 uint32_t ret_val = 0;
734 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
735 pci_write_config_dword (pci_root, 0xD0, mcr);
736 pci_read_config_dword (pci_root, 0xD4, &ret_val);
737 pci_dev_put(pci_root);
738 return ret_val;
740 static inline void MDFLD_MSG_WRITE32(uint port, uint offset, u32 value)
742 int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0;
743 struct pci_dev *pci_root = pci_get_bus_and_slot (0, 0);
744 pci_write_config_dword (pci_root, 0xD4, value);
745 pci_write_config_dword (pci_root, 0xD0, mcr);
746 pci_dev_put(pci_root);
749 static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg)
751 struct drm_psb_private *dev_priv = dev->dev_private;
752 int reg_val = ioread32(dev_priv->vdc_reg + (reg));
753 PSB_DEBUG_REG("reg = 0x%x. reg_val = 0x%x. \n", reg, reg_val);
754 return reg_val;
757 #define REG_READ(reg) REGISTER_READ(dev, (reg))
758 static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg,
759 uint32_t val)
761 struct drm_psb_private *dev_priv = dev->dev_private;
762 if ((reg < 0x70084 || reg >0x70088) && (reg < 0xa000 || reg >0xa3ff))
763 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
765 iowrite32((val), dev_priv->vdc_reg + (reg));
768 #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
770 static inline void REGISTER_WRITE16(struct drm_device *dev,
771 uint32_t reg, uint32_t val)
773 struct drm_psb_private *dev_priv = dev->dev_private;
775 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
777 iowrite16((val), dev_priv->vdc_reg + (reg));
780 #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
782 static inline void REGISTER_WRITE8(struct drm_device *dev,
783 uint32_t reg, uint32_t val)
785 struct drm_psb_private *dev_priv = dev->dev_private;
787 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg, val);
789 iowrite8((val), dev_priv->vdc_reg + (reg));
792 #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
794 #define PSB_ALIGN_TO(_val, _align) \
795 (((_val) + ((_align) - 1)) & ~((_align) - 1))
796 #define PSB_WVDC32(_val, _offs) \
797 iowrite32(_val, dev_priv->vdc_reg + (_offs))
798 #define PSB_RVDC32(_offs) \
799 ioread32(dev_priv->vdc_reg + (_offs))
801 /* #define TRAP_SGX_PM_FAULT 1 */
802 #ifdef TRAP_SGX_PM_FAULT
803 #define PSB_RSGX32(_offs) \
804 ({ \
805 if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
806 printk(KERN_ERR "access sgx when it's off!! (READ) %s, %d\n", \
807 __FILE__, __LINE__); \
808 mdelay(1000); \
810 ioread32(dev_priv->sgx_reg + (_offs)); \
812 #else
813 #define PSB_RSGX32(_offs) \
814 ioread32(dev_priv->sgx_reg + (_offs))
815 #endif
816 #define PSB_WSGX32(_val, _offs) \
817 iowrite32(_val, dev_priv->sgx_reg + (_offs))
819 #define MSVDX_REG_DUMP 0
820 #if MSVDX_REG_DUMP
822 #define PSB_WMSVDX32(_val, _offs) \
823 printk("MSVDX: write %08x to reg 0x%08x\n", (unsigned int)(_val), (unsigned int)(_offs));\
824 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
825 #define PSB_RMSVDX32(_offs) \
826 ioread32(dev_priv->msvdx_reg + (_offs))
828 #else
830 #define PSB_WMSVDX32(_val, _offs) \
831 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
832 #define PSB_RMSVDX32(_offs) \
833 ioread32(dev_priv->msvdx_reg + (_offs))
835 #endif
837 #define PSB_ALPL(_val, _base) \
838 (((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT))
839 #define PSB_ALPLM(_val, _base) \
840 ((((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT)) & (_base ## _MASK))
842 #endif