psb_drv.h 26 KB

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