psb_drv.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. /**************************************************************************
  2. * Copyright (c) 2007-2011, Intel Corporation.
  3. * All Rights Reserved.
  4. *
  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.
  8. *
  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.
  13. *
  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.
  17. *
  18. **************************************************************************/
  19. #ifndef _PSB_DRV_H_
  20. #define _PSB_DRV_H_
  21. #include <linux/kref.h>
  22. #include <drm/drmP.h>
  23. #include "drm_global.h"
  24. #include "gem_glue.h"
  25. #include "gma_drm.h"
  26. #include "psb_reg.h"
  27. #include "psb_intel_drv.h"
  28. #include "gtt.h"
  29. #include "power.h"
  30. #include "oaktrail.h"
  31. /* Append new drm mode definition here, align with libdrm definition */
  32. #define DRM_MODE_SCALE_NO_SCALE 2
  33. enum {
  34. CHIP_PSB_8108 = 0, /* Poulsbo */
  35. CHIP_PSB_8109 = 1, /* Poulsbo */
  36. CHIP_MRST_4100 = 2, /* Moorestown/Oaktrail */
  37. CHIP_MFLD_0130 = 3, /* Medfield */
  38. };
  39. #define IS_PSB(dev) (((dev)->pci_device & 0xfffe) == 0x8108)
  40. #define IS_MRST(dev) (((dev)->pci_device & 0xfffc) == 0x4100)
  41. #define IS_MFLD(dev) (((dev)->pci_device & 0xfff8) == 0x0130)
  42. /*
  43. * Driver definitions
  44. */
  45. #define DRIVER_NAME "gma500"
  46. #define DRIVER_DESC "DRM driver for the Intel GMA500"
  47. #define PSB_DRM_DRIVER_DATE "2011-06-06"
  48. #define PSB_DRM_DRIVER_MAJOR 1
  49. #define PSB_DRM_DRIVER_MINOR 0
  50. #define PSB_DRM_DRIVER_PATCHLEVEL 0
  51. /*
  52. * Hardware offsets
  53. */
  54. #define PSB_VDC_OFFSET 0x00000000
  55. #define PSB_VDC_SIZE 0x000080000
  56. #define MRST_MMIO_SIZE 0x0000C0000
  57. #define MDFLD_MMIO_SIZE 0x000100000
  58. #define PSB_SGX_SIZE 0x8000
  59. #define PSB_SGX_OFFSET 0x00040000
  60. #define MRST_SGX_OFFSET 0x00080000
  61. /*
  62. * PCI resource identifiers
  63. */
  64. #define PSB_MMIO_RESOURCE 0
  65. #define PSB_GATT_RESOURCE 2
  66. #define PSB_GTT_RESOURCE 3
  67. /*
  68. * PCI configuration
  69. */
  70. #define PSB_GMCH_CTRL 0x52
  71. #define PSB_BSM 0x5C
  72. #define _PSB_GMCH_ENABLED 0x4
  73. #define PSB_PGETBL_CTL 0x2020
  74. #define _PSB_PGETBL_ENABLED 0x00000001
  75. #define PSB_SGX_2D_SLAVE_PORT 0x4000
  76. /* To get rid of */
  77. #define PSB_TT_PRIV0_LIMIT (256*1024*1024)
  78. #define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT)
  79. /*
  80. * SGX side MMU definitions (these can probably go)
  81. */
  82. /*
  83. * Flags for external memory type field.
  84. */
  85. #define PSB_MMU_CACHED_MEMORY 0x0001 /* Bind to MMU only */
  86. #define PSB_MMU_RO_MEMORY 0x0002 /* MMU RO memory */
  87. #define PSB_MMU_WO_MEMORY 0x0004 /* MMU WO memory */
  88. /*
  89. * PTE's and PDE's
  90. */
  91. #define PSB_PDE_MASK 0x003FFFFF
  92. #define PSB_PDE_SHIFT 22
  93. #define PSB_PTE_SHIFT 12
  94. /*
  95. * Cache control
  96. */
  97. #define PSB_PTE_VALID 0x0001 /* PTE / PDE valid */
  98. #define PSB_PTE_WO 0x0002 /* Write only */
  99. #define PSB_PTE_RO 0x0004 /* Read only */
  100. #define PSB_PTE_CACHED 0x0008 /* CPU cache coherent */
  101. /*
  102. * VDC registers and bits
  103. */
  104. #define PSB_MSVDX_CLOCKGATING 0x2064
  105. #define PSB_TOPAZ_CLOCKGATING 0x2068
  106. #define PSB_HWSTAM 0x2098
  107. #define PSB_INSTPM 0x20C0
  108. #define PSB_INT_IDENTITY_R 0x20A4
  109. #define _MDFLD_PIPEC_EVENT_FLAG (1<<2)
  110. #define _MDFLD_PIPEC_VBLANK_FLAG (1<<3)
  111. #define _PSB_DPST_PIPEB_FLAG (1<<4)
  112. #define _MDFLD_PIPEB_EVENT_FLAG (1<<4)
  113. #define _PSB_VSYNC_PIPEB_FLAG (1<<5)
  114. #define _PSB_DPST_PIPEA_FLAG (1<<6)
  115. #define _PSB_PIPEA_EVENT_FLAG (1<<6)
  116. #define _PSB_VSYNC_PIPEA_FLAG (1<<7)
  117. #define _MDFLD_MIPIA_FLAG (1<<16)
  118. #define _MDFLD_MIPIC_FLAG (1<<17)
  119. #define _PSB_IRQ_SGX_FLAG (1<<18)
  120. #define _PSB_IRQ_MSVDX_FLAG (1<<19)
  121. #define _LNC_IRQ_TOPAZ_FLAG (1<<20)
  122. #define _PSB_PIPE_EVENT_FLAG (_PSB_VSYNC_PIPEA_FLAG | \
  123. _PSB_VSYNC_PIPEB_FLAG)
  124. /* This flag includes all the display IRQ bits excepts the vblank irqs. */
  125. #define _MDFLD_DISP_ALL_IRQ_FLAG (_MDFLD_PIPEC_EVENT_FLAG | \
  126. _MDFLD_PIPEB_EVENT_FLAG | \
  127. _PSB_PIPEA_EVENT_FLAG | \
  128. _PSB_VSYNC_PIPEA_FLAG | \
  129. _MDFLD_MIPIA_FLAG | \
  130. _MDFLD_MIPIC_FLAG)
  131. #define PSB_INT_IDENTITY_R 0x20A4
  132. #define PSB_INT_MASK_R 0x20A8
  133. #define PSB_INT_ENABLE_R 0x20A0
  134. #define _PSB_MMU_ER_MASK 0x0001FF00
  135. #define _PSB_MMU_ER_HOST (1 << 16)
  136. #define GPIOA 0x5010
  137. #define GPIOB 0x5014
  138. #define GPIOC 0x5018
  139. #define GPIOD 0x501c
  140. #define GPIOE 0x5020
  141. #define GPIOF 0x5024
  142. #define GPIOG 0x5028
  143. #define GPIOH 0x502c
  144. #define GPIO_CLOCK_DIR_MASK (1 << 0)
  145. #define GPIO_CLOCK_DIR_IN (0 << 1)
  146. #define GPIO_CLOCK_DIR_OUT (1 << 1)
  147. #define GPIO_CLOCK_VAL_MASK (1 << 2)
  148. #define GPIO_CLOCK_VAL_OUT (1 << 3)
  149. #define GPIO_CLOCK_VAL_IN (1 << 4)
  150. #define GPIO_CLOCK_PULLUP_DISABLE (1 << 5)
  151. #define GPIO_DATA_DIR_MASK (1 << 8)
  152. #define GPIO_DATA_DIR_IN (0 << 9)
  153. #define GPIO_DATA_DIR_OUT (1 << 9)
  154. #define GPIO_DATA_VAL_MASK (1 << 10)
  155. #define GPIO_DATA_VAL_OUT (1 << 11)
  156. #define GPIO_DATA_VAL_IN (1 << 12)
  157. #define GPIO_DATA_PULLUP_DISABLE (1 << 13)
  158. #define VCLK_DIVISOR_VGA0 0x6000
  159. #define VCLK_DIVISOR_VGA1 0x6004
  160. #define VCLK_POST_DIV 0x6010
  161. #define PSB_COMM_2D (PSB_ENGINE_2D << 4)
  162. #define PSB_COMM_3D (PSB_ENGINE_3D << 4)
  163. #define PSB_COMM_TA (PSB_ENGINE_TA << 4)
  164. #define PSB_COMM_HP (PSB_ENGINE_HP << 4)
  165. #define PSB_COMM_USER_IRQ (1024 >> 2)
  166. #define PSB_COMM_USER_IRQ_LOST (PSB_COMM_USER_IRQ + 1)
  167. #define PSB_COMM_FW (2048 >> 2)
  168. #define PSB_UIRQ_VISTEST 1
  169. #define PSB_UIRQ_OOM_REPLY 2
  170. #define PSB_UIRQ_FIRE_TA_REPLY 3
  171. #define PSB_UIRQ_FIRE_RASTER_REPLY 4
  172. #define PSB_2D_SIZE (256*1024*1024)
  173. #define PSB_MAX_RELOC_PAGES 1024
  174. #define PSB_LOW_REG_OFFS 0x0204
  175. #define PSB_HIGH_REG_OFFS 0x0600
  176. #define PSB_NUM_VBLANKS 2
  177. #define PSB_2D_SIZE (256*1024*1024)
  178. #define PSB_MAX_RELOC_PAGES 1024
  179. #define PSB_LOW_REG_OFFS 0x0204
  180. #define PSB_HIGH_REG_OFFS 0x0600
  181. #define PSB_NUM_VBLANKS 2
  182. #define PSB_WATCHDOG_DELAY (DRM_HZ * 2)
  183. #define PSB_LID_DELAY (DRM_HZ / 10)
  184. #define MDFLD_PNW_B0 0x04
  185. #define MDFLD_PNW_C0 0x08
  186. #define MDFLD_DSR_2D_3D_0 (1 << 0)
  187. #define MDFLD_DSR_2D_3D_2 (1 << 1)
  188. #define MDFLD_DSR_CURSOR_0 (1 << 2)
  189. #define MDFLD_DSR_CURSOR_2 (1 << 3)
  190. #define MDFLD_DSR_OVERLAY_0 (1 << 4)
  191. #define MDFLD_DSR_OVERLAY_2 (1 << 5)
  192. #define MDFLD_DSR_MIPI_CONTROL (1 << 6)
  193. #define MDFLD_DSR_DAMAGE_MASK_0 ((1 << 0) | (1 << 2) | (1 << 4))
  194. #define MDFLD_DSR_DAMAGE_MASK_2 ((1 << 1) | (1 << 3) | (1 << 5))
  195. #define MDFLD_DSR_2D_3D (MDFLD_DSR_2D_3D_0 | MDFLD_DSR_2D_3D_2)
  196. #define MDFLD_DSR_RR 45
  197. #define MDFLD_DPU_ENABLE (1 << 31)
  198. #define MDFLD_DSR_FULLSCREEN (1 << 30)
  199. #define MDFLD_DSR_DELAY (DRM_HZ / MDFLD_DSR_RR)
  200. #define PSB_PWR_STATE_ON 1
  201. #define PSB_PWR_STATE_OFF 2
  202. #define PSB_PMPOLICY_NOPM 0
  203. #define PSB_PMPOLICY_CLOCKGATING 1
  204. #define PSB_PMPOLICY_POWERDOWN 2
  205. #define PSB_PMSTATE_POWERUP 0
  206. #define PSB_PMSTATE_CLOCKGATED 1
  207. #define PSB_PMSTATE_POWERDOWN 2
  208. #define PSB_PCIx_MSI_ADDR_LOC 0x94
  209. #define PSB_PCIx_MSI_DATA_LOC 0x98
  210. /* Medfield crystal settings */
  211. #define KSEL_CRYSTAL_19 1
  212. #define KSEL_BYPASS_19 5
  213. #define KSEL_BYPASS_25 6
  214. #define KSEL_BYPASS_83_100 7
  215. struct opregion_header;
  216. struct opregion_acpi;
  217. struct opregion_swsci;
  218. struct opregion_asle;
  219. struct psb_intel_opregion {
  220. struct opregion_header *header;
  221. struct opregion_acpi *acpi;
  222. struct opregion_swsci *swsci;
  223. struct opregion_asle *asle;
  224. int enabled;
  225. };
  226. struct sdvo_device_mapping {
  227. u8 initialized;
  228. u8 dvo_port;
  229. u8 slave_addr;
  230. u8 dvo_wiring;
  231. u8 i2c_pin;
  232. u8 i2c_speed;
  233. u8 ddc_pin;
  234. };
  235. struct intel_gmbus {
  236. struct i2c_adapter adapter;
  237. struct i2c_adapter *force_bit;
  238. u32 reg0;
  239. };
  240. struct psb_ops;
  241. #define PSB_NUM_PIPE 3
  242. struct drm_psb_private {
  243. struct drm_device *dev;
  244. const struct psb_ops *ops;
  245. struct psb_gtt gtt;
  246. /* GTT Memory manager */
  247. struct psb_gtt_mm *gtt_mm;
  248. struct page *scratch_page;
  249. u32 *gtt_map;
  250. uint32_t stolen_base;
  251. void *vram_addr;
  252. unsigned long vram_stolen_size;
  253. int gtt_initialized;
  254. u16 gmch_ctrl; /* Saved GTT setup */
  255. u32 pge_ctl;
  256. struct mutex gtt_mutex;
  257. struct resource *gtt_mem; /* Our PCI resource */
  258. struct psb_mmu_driver *mmu;
  259. struct psb_mmu_pd *pf_pd;
  260. /*
  261. * Register base
  262. */
  263. uint8_t *sgx_reg;
  264. uint8_t *vdc_reg;
  265. uint32_t gatt_free_offset;
  266. /*
  267. * Fencing / irq.
  268. */
  269. uint32_t vdc_irq_mask;
  270. uint32_t pipestat[PSB_NUM_PIPE];
  271. spinlock_t irqmask_lock;
  272. /*
  273. * Power
  274. */
  275. bool suspended;
  276. bool display_power;
  277. int display_count;
  278. /*
  279. * Modesetting
  280. */
  281. struct psb_intel_mode_device mode_dev;
  282. struct drm_crtc *plane_to_crtc_mapping[PSB_NUM_PIPE];
  283. struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE];
  284. uint32_t num_pipe;
  285. /*
  286. * OSPM info (Power management base) (can go ?)
  287. */
  288. uint32_t ospm_base;
  289. /*
  290. * Sizes info
  291. */
  292. u32 fuse_reg_value;
  293. u32 video_device_fuse;
  294. /* PCI revision ID for B0:D2:F0 */
  295. uint8_t platform_rev_id;
  296. /* gmbus */
  297. struct intel_gmbus *gmbus;
  298. /* Used by SDVO */
  299. int crt_ddc_pin;
  300. /* FIXME: The mappings should be parsed from bios but for now we can
  301. pretend there are no mappings available */
  302. struct sdvo_device_mapping sdvo_mappings[2];
  303. u32 hotplug_supported_mask;
  304. struct drm_property *broadcast_rgb_property;
  305. struct drm_property *force_audio_property;
  306. /*
  307. * LVDS info
  308. */
  309. int backlight_duty_cycle; /* restore backlight to this value */
  310. bool panel_wants_dither;
  311. struct drm_display_mode *panel_fixed_mode;
  312. struct drm_display_mode *lfp_lvds_vbt_mode;
  313. 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; /* FIXME: Remove this? */
  316. /* Feature bits from the VBIOS */
  317. unsigned int int_tv_support:1;
  318. unsigned int lvds_dither:1;
  319. unsigned int lvds_vbt:1;
  320. unsigned int int_crt_support:1;
  321. unsigned int lvds_use_ssc:1;
  322. int lvds_ssc_freq;
  323. bool is_lvds_on;
  324. bool is_mipi_on;
  325. u32 mipi_ctrl_display;
  326. unsigned int core_freq;
  327. uint32_t iLVDS_enable;
  328. /* Runtime PM state */
  329. int rpm_enabled;
  330. /* MID specific */
  331. struct oaktrail_vbt vbt_data;
  332. struct oaktrail_gct_data gct_data;
  333. /* MIPI Panel type etc */
  334. int panel_id;
  335. bool dual_mipi; /* dual display - DPI & DBI */
  336. bool dpi_panel_on; /* The DPI panel power is on */
  337. bool dpi_panel_on2; /* The DPI panel power is on */
  338. bool dbi_panel_on; /* The DBI panel power is on */
  339. bool dbi_panel_on2; /* The DBI panel power is on */
  340. u32 dsr_fb_update; /* DSR FB update counter */
  341. /* Moorestown HDMI state */
  342. struct oaktrail_hdmi_dev *hdmi_priv;
  343. /* Moorestown pipe config register value cache */
  344. uint32_t pipeconf;
  345. uint32_t pipeconf1;
  346. uint32_t pipeconf2;
  347. /* Moorestown plane control register value cache */
  348. uint32_t dspcntr;
  349. uint32_t dspcntr1;
  350. uint32_t dspcntr2;
  351. /* Moorestown MM backlight cache */
  352. uint8_t saveBKLTCNT;
  353. uint8_t saveBKLTREQ;
  354. uint8_t saveBKLTBRTL;
  355. /*
  356. * Register state
  357. */
  358. uint32_t saveDSPACNTR;
  359. uint32_t saveDSPBCNTR;
  360. uint32_t savePIPEACONF;
  361. uint32_t savePIPEBCONF;
  362. uint32_t savePIPEASRC;
  363. uint32_t savePIPEBSRC;
  364. uint32_t saveFPA0;
  365. uint32_t saveFPA1;
  366. uint32_t saveDPLL_A;
  367. uint32_t saveDPLL_A_MD;
  368. uint32_t saveHTOTAL_A;
  369. uint32_t saveHBLANK_A;
  370. uint32_t saveHSYNC_A;
  371. uint32_t saveVTOTAL_A;
  372. uint32_t saveVBLANK_A;
  373. uint32_t saveVSYNC_A;
  374. uint32_t saveDSPASTRIDE;
  375. uint32_t saveDSPASIZE;
  376. uint32_t saveDSPAPOS;
  377. uint32_t saveDSPABASE;
  378. uint32_t saveDSPASURF;
  379. uint32_t saveDSPASTATUS;
  380. uint32_t saveFPB0;
  381. uint32_t saveFPB1;
  382. uint32_t saveDPLL_B;
  383. uint32_t saveDPLL_B_MD;
  384. uint32_t saveHTOTAL_B;
  385. uint32_t saveHBLANK_B;
  386. uint32_t saveHSYNC_B;
  387. uint32_t saveVTOTAL_B;
  388. uint32_t saveVBLANK_B;
  389. uint32_t saveVSYNC_B;
  390. uint32_t saveDSPBSTRIDE;
  391. uint32_t saveDSPBSIZE;
  392. uint32_t saveDSPBPOS;
  393. uint32_t saveDSPBBASE;
  394. uint32_t saveDSPBSURF;
  395. uint32_t saveDSPBSTATUS;
  396. uint32_t saveVCLK_DIVISOR_VGA0;
  397. uint32_t saveVCLK_DIVISOR_VGA1;
  398. uint32_t saveVCLK_POST_DIV;
  399. uint32_t saveVGACNTRL;
  400. uint32_t saveADPA;
  401. uint32_t saveLVDS;
  402. uint32_t saveDVOA;
  403. uint32_t saveDVOB;
  404. uint32_t saveDVOC;
  405. uint32_t savePP_ON;
  406. uint32_t savePP_OFF;
  407. uint32_t savePP_CONTROL;
  408. uint32_t savePP_CYCLE;
  409. uint32_t savePFIT_CONTROL;
  410. uint32_t savePaletteA[256];
  411. uint32_t savePaletteB[256];
  412. uint32_t saveBLC_PWM_CTL2;
  413. uint32_t saveBLC_PWM_CTL;
  414. uint32_t saveCLOCKGATING;
  415. uint32_t saveDSPARB;
  416. uint32_t saveDSPATILEOFF;
  417. uint32_t saveDSPBTILEOFF;
  418. uint32_t saveDSPAADDR;
  419. uint32_t saveDSPBADDR;
  420. uint32_t savePFIT_AUTO_RATIOS;
  421. uint32_t savePFIT_PGM_RATIOS;
  422. uint32_t savePP_ON_DELAYS;
  423. uint32_t savePP_OFF_DELAYS;
  424. uint32_t savePP_DIVISOR;
  425. uint32_t saveBSM;
  426. uint32_t saveVBT;
  427. uint32_t saveBCLRPAT_A;
  428. uint32_t saveBCLRPAT_B;
  429. uint32_t saveDSPALINOFF;
  430. uint32_t saveDSPBLINOFF;
  431. uint32_t savePERF_MODE;
  432. uint32_t saveDSPFW1;
  433. uint32_t saveDSPFW2;
  434. uint32_t saveDSPFW3;
  435. uint32_t saveDSPFW4;
  436. uint32_t saveDSPFW5;
  437. uint32_t saveDSPFW6;
  438. uint32_t saveCHICKENBIT;
  439. uint32_t saveDSPACURSOR_CTRL;
  440. uint32_t saveDSPBCURSOR_CTRL;
  441. uint32_t saveDSPACURSOR_BASE;
  442. uint32_t saveDSPBCURSOR_BASE;
  443. uint32_t saveDSPACURSOR_POS;
  444. uint32_t saveDSPBCURSOR_POS;
  445. uint32_t save_palette_a[256];
  446. uint32_t save_palette_b[256];
  447. uint32_t saveOV_OVADD;
  448. uint32_t saveOV_OGAMC0;
  449. uint32_t saveOV_OGAMC1;
  450. uint32_t saveOV_OGAMC2;
  451. uint32_t saveOV_OGAMC3;
  452. uint32_t saveOV_OGAMC4;
  453. uint32_t saveOV_OGAMC5;
  454. uint32_t saveOVC_OVADD;
  455. uint32_t saveOVC_OGAMC0;
  456. uint32_t saveOVC_OGAMC1;
  457. uint32_t saveOVC_OGAMC2;
  458. uint32_t saveOVC_OGAMC3;
  459. uint32_t saveOVC_OGAMC4;
  460. uint32_t saveOVC_OGAMC5;
  461. /* MSI reg save */
  462. uint32_t msi_addr;
  463. uint32_t msi_data;
  464. /* Medfield specific register save state */
  465. uint32_t saveHDMIPHYMISCCTL;
  466. uint32_t saveHDMIB_CONTROL;
  467. uint32_t saveDSPCCNTR;
  468. uint32_t savePIPECCONF;
  469. uint32_t savePIPECSRC;
  470. uint32_t saveHTOTAL_C;
  471. uint32_t saveHBLANK_C;
  472. uint32_t saveHSYNC_C;
  473. uint32_t saveVTOTAL_C;
  474. uint32_t saveVBLANK_C;
  475. uint32_t saveVSYNC_C;
  476. uint32_t saveDSPCSTRIDE;
  477. uint32_t saveDSPCSIZE;
  478. uint32_t saveDSPCPOS;
  479. uint32_t saveDSPCSURF;
  480. uint32_t saveDSPCSTATUS;
  481. uint32_t saveDSPCLINOFF;
  482. uint32_t saveDSPCTILEOFF;
  483. uint32_t saveDSPCCURSOR_CTRL;
  484. uint32_t saveDSPCCURSOR_BASE;
  485. uint32_t saveDSPCCURSOR_POS;
  486. uint32_t save_palette_c[256];
  487. uint32_t saveOV_OVADD_C;
  488. uint32_t saveOV_OGAMC0_C;
  489. uint32_t saveOV_OGAMC1_C;
  490. uint32_t saveOV_OGAMC2_C;
  491. uint32_t saveOV_OGAMC3_C;
  492. uint32_t saveOV_OGAMC4_C;
  493. uint32_t saveOV_OGAMC5_C;
  494. /* DSI register save */
  495. uint32_t saveDEVICE_READY_REG;
  496. uint32_t saveINTR_EN_REG;
  497. uint32_t saveDSI_FUNC_PRG_REG;
  498. uint32_t saveHS_TX_TIMEOUT_REG;
  499. uint32_t saveLP_RX_TIMEOUT_REG;
  500. uint32_t saveTURN_AROUND_TIMEOUT_REG;
  501. uint32_t saveDEVICE_RESET_REG;
  502. uint32_t saveDPI_RESOLUTION_REG;
  503. uint32_t saveHORIZ_SYNC_PAD_COUNT_REG;
  504. uint32_t saveHORIZ_BACK_PORCH_COUNT_REG;
  505. uint32_t saveHORIZ_FRONT_PORCH_COUNT_REG;
  506. uint32_t saveHORIZ_ACTIVE_AREA_COUNT_REG;
  507. uint32_t saveVERT_SYNC_PAD_COUNT_REG;
  508. uint32_t saveVERT_BACK_PORCH_COUNT_REG;
  509. uint32_t saveVERT_FRONT_PORCH_COUNT_REG;
  510. uint32_t saveHIGH_LOW_SWITCH_COUNT_REG;
  511. uint32_t saveINIT_COUNT_REG;
  512. uint32_t saveMAX_RET_PAK_REG;
  513. uint32_t saveVIDEO_FMT_REG;
  514. uint32_t saveEOT_DISABLE_REG;
  515. uint32_t saveLP_BYTECLK_REG;
  516. uint32_t saveHS_LS_DBI_ENABLE_REG;
  517. uint32_t saveTXCLKESC_REG;
  518. uint32_t saveDPHY_PARAM_REG;
  519. uint32_t saveMIPI_CONTROL_REG;
  520. uint32_t saveMIPI;
  521. uint32_t saveMIPI_C;
  522. /* DPST register save */
  523. uint32_t saveHISTOGRAM_INT_CONTROL_REG;
  524. uint32_t saveHISTOGRAM_LOGIC_CONTROL_REG;
  525. uint32_t savePWM_CONTROL_LOGIC;
  526. /*
  527. * DSI info.
  528. */
  529. void * dbi_dsr_info;
  530. void * dbi_dpu_info;
  531. void * dsi_configs[2];
  532. /*
  533. * LID-Switch
  534. */
  535. spinlock_t lid_lock;
  536. struct timer_list lid_timer;
  537. struct psb_intel_opregion opregion;
  538. u32 *lid_state;
  539. u32 lid_last_state;
  540. /*
  541. * Watchdog
  542. */
  543. uint32_t apm_reg;
  544. uint16_t apm_base;
  545. /*
  546. * Used for modifying backlight from
  547. * xrandr -- consider removing and using HAL instead
  548. */
  549. struct backlight_device *backlight_device;
  550. struct drm_property *backlight_property;
  551. uint32_t blc_adj1;
  552. uint32_t blc_adj2;
  553. void *fbdev;
  554. /* 2D acceleration */
  555. spinlock_t lock_2d;
  556. };
  557. /*
  558. * Operations for each board type
  559. */
  560. struct psb_ops {
  561. const char *name;
  562. unsigned int accel_2d:1;
  563. int pipes; /* Number of output pipes */
  564. int crtcs; /* Number of CRTCs */
  565. int sgx_offset; /* Base offset of SGX device */
  566. /* Sub functions */
  567. struct drm_crtc_helper_funcs const *crtc_helper;
  568. struct drm_crtc_funcs const *crtc_funcs;
  569. /* Setup hooks */
  570. int (*chip_setup)(struct drm_device *dev);
  571. void (*chip_teardown)(struct drm_device *dev);
  572. /* Display management hooks */
  573. int (*output_init)(struct drm_device *dev);
  574. /* Power management hooks */
  575. void (*init_pm)(struct drm_device *dev);
  576. int (*save_regs)(struct drm_device *dev);
  577. int (*restore_regs)(struct drm_device *dev);
  578. int (*power_up)(struct drm_device *dev);
  579. int (*power_down)(struct drm_device *dev);
  580. void (*lvds_bl_power)(struct drm_device *dev, bool on);
  581. #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
  582. /* Backlight */
  583. int (*backlight_init)(struct drm_device *dev);
  584. #endif
  585. int i2c_bus; /* I2C bus identifier for Moorestown */
  586. };
  587. struct psb_mmu_driver;
  588. extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int);
  589. extern int drm_pick_crtcs(struct drm_device *dev);
  590. static inline struct drm_psb_private *psb_priv(struct drm_device *dev)
  591. {
  592. return (struct drm_psb_private *) dev->dev_private;
  593. }
  594. /*
  595. * MMU stuff.
  596. */
  597. extern struct psb_mmu_driver *psb_mmu_driver_init(uint8_t __iomem * registers,
  598. int trap_pagefaults,
  599. int invalid_type,
  600. struct drm_psb_private *dev_priv);
  601. extern void psb_mmu_driver_takedown(struct psb_mmu_driver *driver);
  602. extern struct psb_mmu_pd *psb_mmu_get_default_pd(struct psb_mmu_driver
  603. *driver);
  604. extern void psb_mmu_mirror_gtt(struct psb_mmu_pd *pd, uint32_t mmu_offset,
  605. uint32_t gtt_start, uint32_t gtt_pages);
  606. extern struct psb_mmu_pd *psb_mmu_alloc_pd(struct psb_mmu_driver *driver,
  607. int trap_pagefaults,
  608. int invalid_type);
  609. extern void psb_mmu_free_pagedir(struct psb_mmu_pd *pd);
  610. extern void psb_mmu_flush(struct psb_mmu_driver *driver, int rc_prot);
  611. extern void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd *pd,
  612. unsigned long address,
  613. uint32_t num_pages);
  614. extern int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd *pd,
  615. uint32_t start_pfn,
  616. unsigned long address,
  617. uint32_t num_pages, int type);
  618. extern int psb_mmu_virtual_to_pfn(struct psb_mmu_pd *pd, uint32_t virtual,
  619. unsigned long *pfn);
  620. /*
  621. * Enable / disable MMU for different requestors.
  622. */
  623. extern void psb_mmu_set_pd_context(struct psb_mmu_pd *pd, int hw_context);
  624. extern int psb_mmu_insert_pages(struct psb_mmu_pd *pd, struct page **pages,
  625. unsigned long address, uint32_t num_pages,
  626. uint32_t desired_tile_stride,
  627. uint32_t hw_tile_stride, int type);
  628. extern void psb_mmu_remove_pages(struct psb_mmu_pd *pd,
  629. unsigned long address, uint32_t num_pages,
  630. uint32_t desired_tile_stride,
  631. uint32_t hw_tile_stride);
  632. /*
  633. *psb_irq.c
  634. */
  635. extern irqreturn_t psb_irq_handler(DRM_IRQ_ARGS);
  636. extern int psb_irq_enable_dpst(struct drm_device *dev);
  637. extern int psb_irq_disable_dpst(struct drm_device *dev);
  638. extern void psb_irq_preinstall(struct drm_device *dev);
  639. extern int psb_irq_postinstall(struct drm_device *dev);
  640. extern void psb_irq_uninstall(struct drm_device *dev);
  641. extern void psb_irq_turn_on_dpst(struct drm_device *dev);
  642. extern void psb_irq_turn_off_dpst(struct drm_device *dev);
  643. extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
  644. extern int psb_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
  645. extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
  646. extern int psb_enable_vblank(struct drm_device *dev, int crtc);
  647. extern void psb_disable_vblank(struct drm_device *dev, int crtc);
  648. void
  649. psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
  650. void
  651. psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
  652. extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc);
  653. /*
  654. * intel_opregion.c
  655. */
  656. extern int gma_intel_opregion_init(struct drm_device *dev);
  657. extern int gma_intel_opregion_exit(struct drm_device *dev);
  658. /*
  659. * framebuffer.c
  660. */
  661. extern int psbfb_probed(struct drm_device *dev);
  662. extern int psbfb_remove(struct drm_device *dev,
  663. struct drm_framebuffer *fb);
  664. /*
  665. * accel_2d.c
  666. */
  667. extern void psbfb_copyarea(struct fb_info *info,
  668. const struct fb_copyarea *region);
  669. extern int psbfb_sync(struct fb_info *info);
  670. extern void psb_spank(struct drm_psb_private *dev_priv);
  671. /*
  672. * psb_reset.c
  673. */
  674. extern void psb_lid_timer_init(struct drm_psb_private *dev_priv);
  675. extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
  676. extern void psb_print_pagefault(struct drm_psb_private *dev_priv);
  677. /* modesetting */
  678. extern void psb_modeset_init(struct drm_device *dev);
  679. extern void psb_modeset_cleanup(struct drm_device *dev);
  680. extern int psb_fbdev_init(struct drm_device *dev);
  681. /* backlight.c */
  682. int gma_backlight_init(struct drm_device *dev);
  683. void gma_backlight_exit(struct drm_device *dev);
  684. /* oaktrail_crtc.c */
  685. extern const struct drm_crtc_helper_funcs oaktrail_helper_funcs;
  686. /* oaktrail_lvds.c */
  687. extern void oaktrail_lvds_init(struct drm_device *dev,
  688. struct psb_intel_mode_device *mode_dev);
  689. /* psb_intel_display.c */
  690. extern const struct drm_crtc_helper_funcs psb_intel_helper_funcs;
  691. extern const struct drm_crtc_funcs psb_intel_crtc_funcs;
  692. /* psb_intel_lvds.c */
  693. extern const struct drm_connector_helper_funcs
  694. psb_intel_lvds_connector_helper_funcs;
  695. extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
  696. /* gem.c */
  697. extern int psb_gem_init_object(struct drm_gem_object *obj);
  698. extern void psb_gem_free_object(struct drm_gem_object *obj);
  699. extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
  700. struct drm_file *file);
  701. extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  702. struct drm_mode_create_dumb *args);
  703. extern int psb_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
  704. uint32_t handle);
  705. extern int psb_gem_dumb_map_gtt(struct drm_file *file, struct drm_device *dev,
  706. uint32_t handle, uint64_t *offset);
  707. extern int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  708. extern int psb_gem_create_ioctl(struct drm_device *dev, void *data,
  709. struct drm_file *file);
  710. extern int psb_gem_mmap_ioctl(struct drm_device *dev, void *data,
  711. struct drm_file *file);
  712. /* psb_device.c */
  713. extern const struct psb_ops psb_chip_ops;
  714. /* oaktrail_device.c */
  715. extern const struct psb_ops oaktrail_chip_ops;
  716. /* cdv_device.c */
  717. extern const struct psb_ops cdv_chip_ops;
  718. /*
  719. * Debug print bits setting
  720. */
  721. #define PSB_D_GENERAL (1 << 0)
  722. #define PSB_D_INIT (1 << 1)
  723. #define PSB_D_IRQ (1 << 2)
  724. #define PSB_D_ENTRY (1 << 3)
  725. /* debug the get H/V BP/FP count */
  726. #define PSB_D_HV (1 << 4)
  727. #define PSB_D_DBI_BF (1 << 5)
  728. #define PSB_D_PM (1 << 6)
  729. #define PSB_D_RENDER (1 << 7)
  730. #define PSB_D_REG (1 << 8)
  731. #define PSB_D_MSVDX (1 << 9)
  732. #define PSB_D_TOPAZ (1 << 10)
  733. extern int drm_psb_no_fb;
  734. extern int drm_idle_check_interval;
  735. /*
  736. * Utilities
  737. */
  738. static inline u32 MRST_MSG_READ32(uint port, uint offset)
  739. {
  740. int mcr = (0xD0<<24) | (port << 16) | (offset << 8);
  741. uint32_t ret_val = 0;
  742. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  743. pci_write_config_dword(pci_root, 0xD0, mcr);
  744. pci_read_config_dword(pci_root, 0xD4, &ret_val);
  745. pci_dev_put(pci_root);
  746. return ret_val;
  747. }
  748. static inline void MRST_MSG_WRITE32(uint port, uint offset, u32 value)
  749. {
  750. int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0;
  751. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  752. pci_write_config_dword(pci_root, 0xD4, value);
  753. pci_write_config_dword(pci_root, 0xD0, mcr);
  754. pci_dev_put(pci_root);
  755. }
  756. static inline u32 MDFLD_MSG_READ32(uint port, uint offset)
  757. {
  758. int mcr = (0x10<<24) | (port << 16) | (offset << 8);
  759. uint32_t ret_val = 0;
  760. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  761. pci_write_config_dword(pci_root, 0xD0, mcr);
  762. pci_read_config_dword(pci_root, 0xD4, &ret_val);
  763. pci_dev_put(pci_root);
  764. return ret_val;
  765. }
  766. static inline void MDFLD_MSG_WRITE32(uint port, uint offset, u32 value)
  767. {
  768. int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0;
  769. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  770. pci_write_config_dword(pci_root, 0xD4, value);
  771. pci_write_config_dword(pci_root, 0xD0, mcr);
  772. pci_dev_put(pci_root);
  773. }
  774. static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg)
  775. {
  776. struct drm_psb_private *dev_priv = dev->dev_private;
  777. return ioread32(dev_priv->vdc_reg + reg);
  778. }
  779. #define REG_READ(reg) REGISTER_READ(dev, (reg))
  780. static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg,
  781. uint32_t val)
  782. {
  783. struct drm_psb_private *dev_priv = dev->dev_private;
  784. iowrite32((val), dev_priv->vdc_reg + (reg));
  785. }
  786. #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
  787. static inline void REGISTER_WRITE16(struct drm_device *dev,
  788. uint32_t reg, uint32_t val)
  789. {
  790. struct drm_psb_private *dev_priv = dev->dev_private;
  791. iowrite16((val), dev_priv->vdc_reg + (reg));
  792. }
  793. #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
  794. static inline void REGISTER_WRITE8(struct drm_device *dev,
  795. uint32_t reg, uint32_t val)
  796. {
  797. struct drm_psb_private *dev_priv = dev->dev_private;
  798. iowrite8((val), dev_priv->vdc_reg + (reg));
  799. }
  800. #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
  801. #define PSB_WVDC32(_val, _offs) iowrite32(_val, dev_priv->vdc_reg + (_offs))
  802. #define PSB_RVDC32(_offs) ioread32(dev_priv->vdc_reg + (_offs))
  803. /* #define TRAP_SGX_PM_FAULT 1 */
  804. #ifdef TRAP_SGX_PM_FAULT
  805. #define PSB_RSGX32(_offs) \
  806. ({ \
  807. if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
  808. printk(KERN_ERR \
  809. "access sgx when it's off!! (READ) %s, %d\n", \
  810. __FILE__, __LINE__); \
  811. melay(1000); \
  812. } \
  813. ioread32(dev_priv->sgx_reg + (_offs)); \
  814. })
  815. #else
  816. #define PSB_RSGX32(_offs) ioread32(dev_priv->sgx_reg + (_offs))
  817. #endif
  818. #define PSB_WSGX32(_val, _offs) iowrite32(_val, dev_priv->sgx_reg + (_offs))
  819. #define MSVDX_REG_DUMP 0
  820. #define PSB_WMSVDX32(_val, _offs) iowrite32(_val, dev_priv->msvdx_reg + (_offs))
  821. #define PSB_RMSVDX32(_offs) ioread32(dev_priv->msvdx_reg + (_offs))
  822. #endif