1 /**************************************************************************
2 * Copyright (c) 2007-2008, Intel Corporation.
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
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 **************************************************************************/
23 #include <linux/version.h>
24 #include <linux/kref.h>
27 #include "drm_global.h"
30 #include "psb_intel_drv.h"
32 #include "psb_powermgmt.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
;
46 #define IS_MRST(dev) (((dev)->pci_device & 0xfffc) == 0x4100)
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
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 */
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)
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
;
233 struct drm_psb_private
{
234 struct drm_device
*dev
;
236 unsigned long chipset
;
240 /* GTT Memory manager */
241 struct psb_gtt_mm
*gtt_mm
;
242 struct page
*scratch_page
;
244 struct mutex gtt_mutex
;
245 struct resource
*gtt_mem
; /* Our PCI resource */
247 struct psb_mmu_driver
*mmu
;
248 struct psb_mmu_pd
*pf_pd
;
256 uint32_t gatt_free_offset
;
262 uint32_t vdc_irq_mask
;
263 uint32_t pipestat
[PSB_NUM_PIPE
];
265 spinlock_t irqmask_lock
;
278 struct psb_intel_mode_device mode_dev
;
280 struct drm_crtc
*plane_to_crtc_mapping
[PSB_NUM_PIPE
];
281 struct drm_crtc
*pipe_to_crtc_mapping
[PSB_NUM_PIPE
];
297 struct drm_psb_sizes_arg sizes
;
300 u32 video_device_fuse
;
302 /* pci revision id for B0:D2:F0 */
303 uint8_t platform_rev_id
;
308 int backlight_duty_cycle
; /* restore backlight to this value */
309 bool panel_wants_dither
;
310 struct drm_display_mode
*panel_fixed_mode
;
311 struct drm_display_mode
*lfp_lvds_vbt_mode
;
312 struct drm_display_mode
*sdvo_lvds_vbt_mode
;
314 struct bdb_lvds_backlight
*lvds_bl
; /*LVDS backlight info from VBT*/
315 struct psb_intel_i2c_chan
*lvds_i2c_bus
;
317 /* Feature bits from the VBIOS*/
318 unsigned int int_tv_support
:1;
319 unsigned int lvds_dither
:1;
320 unsigned int lvds_vbt
:1;
321 unsigned int int_crt_support
:1;
322 unsigned int lvds_use_ssc
:1;
327 unsigned int core_freq
;
328 uint32_t iLVDS_enable
;
333 /* Moorestown specific */
334 struct mrst_vbt vbt_data
;
335 struct mrst_gct_data gct_data
;
337 /* Moorestown pipe config register value cache */
342 /* Moorestown plane control register value cache */
350 uint32_t saveDSPACNTR
;
351 uint32_t saveDSPBCNTR
;
352 uint32_t savePIPEACONF
;
353 uint32_t savePIPEBCONF
;
354 uint32_t savePIPEASRC
;
355 uint32_t savePIPEBSRC
;
359 uint32_t saveDPLL_A_MD
;
360 uint32_t saveHTOTAL_A
;
361 uint32_t saveHBLANK_A
;
362 uint32_t saveHSYNC_A
;
363 uint32_t saveVTOTAL_A
;
364 uint32_t saveVBLANK_A
;
365 uint32_t saveVSYNC_A
;
366 uint32_t saveDSPASTRIDE
;
367 uint32_t saveDSPASIZE
;
368 uint32_t saveDSPAPOS
;
369 uint32_t saveDSPABASE
;
370 uint32_t saveDSPASURF
;
374 uint32_t saveDPLL_B_MD
;
375 uint32_t saveHTOTAL_B
;
376 uint32_t saveHBLANK_B
;
377 uint32_t saveHSYNC_B
;
378 uint32_t saveVTOTAL_B
;
379 uint32_t saveVBLANK_B
;
380 uint32_t saveVSYNC_B
;
381 uint32_t saveDSPBSTRIDE
;
382 uint32_t saveDSPBSIZE
;
383 uint32_t saveDSPBPOS
;
384 uint32_t saveDSPBBASE
;
385 uint32_t saveDSPBSURF
;
386 uint32_t saveVCLK_DIVISOR_VGA0
;
387 uint32_t saveVCLK_DIVISOR_VGA1
;
388 uint32_t saveVCLK_POST_DIV
;
389 uint32_t saveVGACNTRL
;
397 uint32_t savePP_CONTROL
;
398 uint32_t savePP_CYCLE
;
399 uint32_t savePFIT_CONTROL
;
400 uint32_t savePaletteA
[256];
401 uint32_t savePaletteB
[256];
402 uint32_t saveBLC_PWM_CTL2
;
403 uint32_t saveBLC_PWM_CTL
;
404 uint32_t saveCLOCKGATING
;
406 uint32_t saveDSPATILEOFF
;
407 uint32_t saveDSPBTILEOFF
;
408 uint32_t saveDSPAADDR
;
409 uint32_t saveDSPBADDR
;
410 uint32_t savePFIT_AUTO_RATIOS
;
411 uint32_t savePFIT_PGM_RATIOS
;
412 uint32_t savePP_ON_DELAYS
;
413 uint32_t savePP_OFF_DELAYS
;
414 uint32_t savePP_DIVISOR
;
417 uint32_t saveBCLRPAT_A
;
418 uint32_t saveBCLRPAT_B
;
419 uint32_t saveDSPALINOFF
;
420 uint32_t saveDSPBLINOFF
;
421 uint32_t savePERF_MODE
;
428 uint32_t saveCHICKENBIT
;
429 uint32_t saveDSPACURSOR_CTRL
;
430 uint32_t saveDSPBCURSOR_CTRL
;
431 uint32_t saveDSPACURSOR_BASE
;
432 uint32_t saveDSPBCURSOR_BASE
;
433 uint32_t saveDSPACURSOR_POS
;
434 uint32_t saveDSPBCURSOR_POS
;
435 uint32_t save_palette_a
[256];
436 uint32_t save_palette_b
[256];
437 uint32_t saveOV_OVADD
;
438 uint32_t saveOV_OGAMC0
;
439 uint32_t saveOV_OGAMC1
;
440 uint32_t saveOV_OGAMC2
;
441 uint32_t saveOV_OGAMC3
;
442 uint32_t saveOV_OGAMC4
;
443 uint32_t saveOV_OGAMC5
;
444 uint32_t saveOVC_OVADD
;
445 uint32_t saveOVC_OGAMC0
;
446 uint32_t saveOVC_OGAMC1
;
447 uint32_t saveOVC_OGAMC2
;
448 uint32_t saveOVC_OGAMC3
;
449 uint32_t saveOVC_OGAMC4
;
450 uint32_t saveOVC_OGAMC5
;
460 struct timer_list lid_timer
;
461 struct psb_intel_opregion opregion
;
473 * Used for modifying backlight from
474 * xrandr -- consider removing and using HAL instead
476 struct drm_property
*backlight_property
;
484 struct psb_mmu_driver
;
486 extern int drm_crtc_probe_output_modes(struct drm_device
*dev
, int, int);
487 extern int drm_pick_crtcs(struct drm_device
*dev
);
489 static inline struct drm_psb_private
*psb_priv(struct drm_device
*dev
)
491 return (struct drm_psb_private
*) dev
->dev_private
;
498 extern struct psb_mmu_driver
*psb_mmu_driver_init(uint8_t __iomem
* registers
,
501 struct drm_psb_private
*dev_priv
);
502 extern void psb_mmu_driver_takedown(struct psb_mmu_driver
*driver
);
503 extern struct psb_mmu_pd
*psb_mmu_get_default_pd(struct psb_mmu_driver
505 extern void psb_mmu_mirror_gtt(struct psb_mmu_pd
*pd
, uint32_t mmu_offset
,
506 uint32_t gtt_start
, uint32_t gtt_pages
);
507 extern struct psb_mmu_pd
*psb_mmu_alloc_pd(struct psb_mmu_driver
*driver
,
510 extern void psb_mmu_free_pagedir(struct psb_mmu_pd
*pd
);
511 extern void psb_mmu_flush(struct psb_mmu_driver
*driver
, int rc_prot
);
512 extern void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd
*pd
,
513 unsigned long address
,
515 extern int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd
*pd
,
517 unsigned long address
,
518 uint32_t num_pages
, int type
);
519 extern int psb_mmu_virtual_to_pfn(struct psb_mmu_pd
*pd
, uint32_t virtual,
523 *Enable / disable MMU for different requestors.
527 extern void psb_mmu_set_pd_context(struct psb_mmu_pd
*pd
, int hw_context
);
528 extern int psb_mmu_insert_pages(struct psb_mmu_pd
*pd
, struct page
**pages
,
529 unsigned long address
, uint32_t num_pages
,
530 uint32_t desired_tile_stride
,
531 uint32_t hw_tile_stride
, int type
);
532 extern void psb_mmu_remove_pages(struct psb_mmu_pd
*pd
,
533 unsigned long address
, uint32_t num_pages
,
534 uint32_t desired_tile_stride
,
535 uint32_t hw_tile_stride
);
540 extern irqreturn_t
psb_irq_handler(DRM_IRQ_ARGS
);
541 extern int psb_irq_enable_dpst(struct drm_device
*dev
);
542 extern int psb_irq_disable_dpst(struct drm_device
*dev
);
543 extern void psb_irq_preinstall(struct drm_device
*dev
);
544 extern int psb_irq_postinstall(struct drm_device
*dev
);
545 extern void psb_irq_uninstall(struct drm_device
*dev
);
546 extern void psb_irq_turn_on_dpst(struct drm_device
*dev
);
547 extern void psb_irq_turn_off_dpst(struct drm_device
*dev
);
549 extern void psb_irq_uninstall_islands(struct drm_device
*dev
, int hw_islands
);
550 extern int psb_vblank_wait2(struct drm_device
*dev
,unsigned int *sequence
);
551 extern int psb_vblank_wait(struct drm_device
*dev
, unsigned int *sequence
);
552 extern int psb_enable_vblank(struct drm_device
*dev
, int crtc
);
553 extern void psb_disable_vblank(struct drm_device
*dev
, int crtc
);
555 psb_enable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
);
558 psb_disable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
);
560 extern u32
psb_get_vblank_counter(struct drm_device
*dev
, int crtc
);
565 extern int psb_intel_opregion_init(struct drm_device
*dev
);
570 extern int psbfb_probed(struct drm_device
*dev
);
571 extern int psbfb_remove(struct drm_device
*dev
,
572 struct drm_framebuffer
*fb
);
573 extern int psbfb_kms_off_ioctl(struct drm_device
*dev
, void *data
,
574 struct drm_file
*file_priv
);
575 extern int psbfb_kms_on_ioctl(struct drm_device
*dev
, void *data
,
576 struct drm_file
*file_priv
);
577 extern void *psbfb_vdc_reg(struct drm_device
* dev
);
582 extern void psbfb_fillrect(struct fb_info
*info
,
583 const struct fb_fillrect
*rect
);
584 extern void psbfb_copyarea(struct fb_info
*info
,
585 const struct fb_copyarea
*region
);
586 extern void psbfb_imageblit(struct fb_info
*info
,
587 const struct fb_image
*image
);
588 extern int psbfb_sync(struct fb_info
*info
);
590 extern void psb_spank(struct drm_psb_private
*dev_priv
);
592 extern int psbfb_2d_submit(struct drm_psb_private
*dev_priv
, uint32_t *cmdbuf
,
599 extern void psb_lid_timer_init(struct drm_psb_private
*dev_priv
);
600 extern void psb_lid_timer_takedown(struct drm_psb_private
*dev_priv
);
601 extern void psb_print_pagefault(struct drm_psb_private
*dev_priv
);
604 extern void psb_modeset_init(struct drm_device
*dev
);
605 extern void psb_modeset_cleanup(struct drm_device
*dev
);
606 extern int psb_fbdev_init(struct drm_device
* dev
);
609 int psb_backlight_init(struct drm_device
*dev
);
610 void psb_backlight_exit(void);
611 int psb_set_brightness(struct backlight_device
*bd
);
612 int psb_get_brightness(struct backlight_device
*bd
);
613 struct backlight_device
* psb_get_backlight_device(void);
616 extern const struct drm_crtc_helper_funcs mrst_helper_funcs
;
619 extern void mrst_lvds_init(struct drm_device
*dev
,
620 struct psb_intel_mode_device
*mode_dev
);
622 /* psb_intel_lvds.c */
623 extern void psb_intel_lvds_prepare(struct drm_encoder
*encoder
);
624 extern void psb_intel_lvds_commit(struct drm_encoder
*encoder
);
625 extern const struct drm_connector_helper_funcs
626 psb_intel_lvds_connector_helper_funcs
;
627 extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs
;
630 extern int psb_gem_init_object(struct drm_gem_object
*obj
);
631 extern void psb_gem_free_object(struct drm_gem_object
*obj
);
632 extern int psb_gem_get_aperture(struct drm_device
*dev
, void *data
,
633 struct drm_file
*file
);
634 extern int psb_gem_dumb_create(struct drm_file
*file
, struct drm_device
*dev
,
635 struct drm_mode_create_dumb
*args
);
636 extern int psb_gem_dumb_destroy(struct drm_file
*file
, struct drm_device
*dev
,
638 extern int psb_gem_dumb_map_gtt(struct drm_file
*file
, struct drm_device
*dev
,
639 uint32_t handle
, uint64_t *offset
);
640 extern int psb_gem_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
);
644 * Debug print bits setting
646 #define PSB_D_GENERAL (1 << 0)
647 #define PSB_D_INIT (1 << 1)
648 #define PSB_D_IRQ (1 << 2)
649 #define PSB_D_ENTRY (1 << 3)
650 /* debug the get H/V BP/FP count */
651 #define PSB_D_HV (1 << 4)
652 #define PSB_D_DBI_BF (1 << 5)
653 #define PSB_D_PM (1 << 6)
654 #define PSB_D_RENDER (1 << 7)
655 #define PSB_D_REG (1 << 8)
656 #define PSB_D_MSVDX (1 << 9)
657 #define PSB_D_TOPAZ (1 << 10)
659 #ifndef DRM_DEBUG_CODE
660 /* To enable debug printout, set drm_psb_debug in psb_drv.c
661 * to any combination of above print flags.
663 /* #define DRM_DEBUG_CODE 2 */
666 extern int drm_psb_debug
;
667 extern int drm_psb_no_fb
;
668 extern int drm_idle_check_interval
;
670 #define PSB_DEBUG_GENERAL(_fmt, _arg...) \
671 PSB_DEBUG(PSB_D_GENERAL, _fmt, ##_arg)
672 #define PSB_DEBUG_INIT(_fmt, _arg...) \
673 PSB_DEBUG(PSB_D_INIT, _fmt, ##_arg)
674 #define PSB_DEBUG_IRQ(_fmt, _arg...) \
675 PSB_DEBUG(PSB_D_IRQ, _fmt, ##_arg)
676 #define PSB_DEBUG_ENTRY(_fmt, _arg...) \
677 PSB_DEBUG(PSB_D_ENTRY, _fmt, ##_arg)
678 #define PSB_DEBUG_HV(_fmt, _arg...) \
679 PSB_DEBUG(PSB_D_HV, _fmt, ##_arg)
680 #define PSB_DEBUG_DBI_BF(_fmt, _arg...) \
681 PSB_DEBUG(PSB_D_DBI_BF, _fmt, ##_arg)
682 #define PSB_DEBUG_PM(_fmt, _arg...) \
683 PSB_DEBUG(PSB_D_PM, _fmt, ##_arg)
684 #define PSB_DEBUG_RENDER(_fmt, _arg...) \
685 PSB_DEBUG(PSB_D_RENDER, _fmt, ##_arg)
686 #define PSB_DEBUG_REG(_fmt, _arg...) \
687 PSB_DEBUG(PSB_D_REG, _fmt, ##_arg)
688 #define PSB_DEBUG_MSVDX(_fmt, _arg...) \
689 PSB_DEBUG(PSB_D_MSVDX, _fmt, ##_arg)
690 #define PSB_DEBUG_TOPAZ(_fmt, _arg...) \
691 PSB_DEBUG(PSB_D_TOPAZ, _fmt, ##_arg)
694 #define PSB_DEBUG(_flag, _fmt, _arg...) \
696 if (unlikely((_flag) & drm_psb_debug)) \
698 "[psb:0x%02x:%s] " _fmt , _flag, \
699 __func__ , ##_arg); \
702 #define PSB_DEBUG(_fmt, _arg...) do { } while (0)
708 #define DRM_DRIVER_PRIVATE_T struct drm_psb_private
710 static inline u32
MRST_MSG_READ32(uint port
, uint offset
)
712 int mcr
= (0xD0<<24) | (port
<< 16) | (offset
<< 8);
713 uint32_t ret_val
= 0;
714 struct pci_dev
*pci_root
= pci_get_bus_and_slot (0, 0);
715 pci_write_config_dword (pci_root
, 0xD0, mcr
);
716 pci_read_config_dword (pci_root
, 0xD4, &ret_val
);
717 pci_dev_put(pci_root
);
720 static inline void MRST_MSG_WRITE32(uint port
, uint offset
, u32 value
)
722 int mcr
= (0xE0<<24) | (port
<< 16) | (offset
<< 8) | 0xF0;
723 struct pci_dev
*pci_root
= pci_get_bus_and_slot (0, 0);
724 pci_write_config_dword (pci_root
, 0xD4, value
);
725 pci_write_config_dword (pci_root
, 0xD0, mcr
);
726 pci_dev_put(pci_root
);
728 static inline u32
MDFLD_MSG_READ32(uint port
, uint offset
)
730 int mcr
= (0x10<<24) | (port
<< 16) | (offset
<< 8);
731 uint32_t ret_val
= 0;
732 struct pci_dev
*pci_root
= pci_get_bus_and_slot (0, 0);
733 pci_write_config_dword (pci_root
, 0xD0, mcr
);
734 pci_read_config_dword (pci_root
, 0xD4, &ret_val
);
735 pci_dev_put(pci_root
);
738 static inline void MDFLD_MSG_WRITE32(uint port
, uint offset
, u32 value
)
740 int mcr
= (0x11<<24) | (port
<< 16) | (offset
<< 8) | 0xF0;
741 struct pci_dev
*pci_root
= pci_get_bus_and_slot (0, 0);
742 pci_write_config_dword (pci_root
, 0xD4, value
);
743 pci_write_config_dword (pci_root
, 0xD0, mcr
);
744 pci_dev_put(pci_root
);
747 static inline uint32_t REGISTER_READ(struct drm_device
*dev
, uint32_t reg
)
749 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
750 int reg_val
= ioread32(dev_priv
->vdc_reg
+ (reg
));
751 PSB_DEBUG_REG("reg = 0x%x. reg_val = 0x%x. \n", reg
, reg_val
);
755 #define REG_READ(reg) REGISTER_READ(dev, (reg))
756 static inline void REGISTER_WRITE(struct drm_device
*dev
, uint32_t reg
,
759 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
760 if ((reg
< 0x70084 || reg
>0x70088) && (reg
< 0xa000 || reg
>0xa3ff))
761 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg
, val
);
763 iowrite32((val
), dev_priv
->vdc_reg
+ (reg
));
766 #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
768 static inline void REGISTER_WRITE16(struct drm_device
*dev
,
769 uint32_t reg
, uint32_t val
)
771 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
773 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg
, val
);
775 iowrite16((val
), dev_priv
->vdc_reg
+ (reg
));
778 #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
780 static inline void REGISTER_WRITE8(struct drm_device
*dev
,
781 uint32_t reg
, uint32_t val
)
783 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
785 PSB_DEBUG_REG("reg = 0x%x, val = 0x%x. \n", reg
, val
);
787 iowrite8((val
), dev_priv
->vdc_reg
+ (reg
));
790 #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
792 #define PSB_ALIGN_TO(_val, _align) \
793 (((_val) + ((_align) - 1)) & ~((_align) - 1))
794 #define PSB_WVDC32(_val, _offs) \
795 iowrite32(_val, dev_priv->vdc_reg + (_offs))
796 #define PSB_RVDC32(_offs) \
797 ioread32(dev_priv->vdc_reg + (_offs))
799 /* #define TRAP_SGX_PM_FAULT 1 */
800 #ifdef TRAP_SGX_PM_FAULT
801 #define PSB_RSGX32(_offs) \
803 if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
804 printk(KERN_ERR "access sgx when it's off!! (READ) %s, %d\n", \
805 __FILE__, __LINE__); \
808 ioread32(dev_priv->sgx_reg + (_offs)); \
811 #define PSB_RSGX32(_offs) \
812 ioread32(dev_priv->sgx_reg + (_offs))
814 #define PSB_WSGX32(_val, _offs) \
815 iowrite32(_val, dev_priv->sgx_reg + (_offs))
817 #define MSVDX_REG_DUMP 0
820 #define PSB_WMSVDX32(_val, _offs) \
821 printk("MSVDX: write %08x to reg 0x%08x\n", (unsigned int)(_val), (unsigned int)(_offs));\
822 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
823 #define PSB_RMSVDX32(_offs) \
824 ioread32(dev_priv->msvdx_reg + (_offs))
828 #define PSB_WMSVDX32(_val, _offs) \
829 iowrite32(_val, dev_priv->msvdx_reg + (_offs))
830 #define PSB_RMSVDX32(_offs) \
831 ioread32(dev_priv->msvdx_reg + (_offs))
835 #define PSB_ALPL(_val, _base) \
836 (((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT))
837 #define PSB_ALPLM(_val, _base) \
838 ((((_val) >> (_base ## _ALIGNSHIFT)) << (_base ## _SHIFT)) & (_base ## _MASK))