psb_drv.h 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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. void *vbt;
  225. int enabled;
  226. };
  227. struct sdvo_device_mapping {
  228. u8 initialized;
  229. u8 dvo_port;
  230. u8 slave_addr;
  231. u8 dvo_wiring;
  232. u8 i2c_pin;
  233. u8 i2c_speed;
  234. u8 ddc_pin;
  235. };
  236. struct intel_gmbus {
  237. struct i2c_adapter adapter;
  238. struct i2c_adapter *force_bit;
  239. u32 reg0;
  240. };
  241. /*
  242. * Register save state. This is used to hold the context when the
  243. * device is powered off. In the case of Oaktrail this can (but does not
  244. * yet) include screen blank. Operations occuring during the save
  245. * update the register cache instead.
  246. */
  247. struct psb_state {
  248. uint32_t saveDSPACNTR;
  249. uint32_t saveDSPBCNTR;
  250. uint32_t savePIPEACONF;
  251. uint32_t savePIPEBCONF;
  252. uint32_t savePIPEASRC;
  253. uint32_t savePIPEBSRC;
  254. uint32_t saveFPA0;
  255. uint32_t saveFPA1;
  256. uint32_t saveDPLL_A;
  257. uint32_t saveDPLL_A_MD;
  258. uint32_t saveHTOTAL_A;
  259. uint32_t saveHBLANK_A;
  260. uint32_t saveHSYNC_A;
  261. uint32_t saveVTOTAL_A;
  262. uint32_t saveVBLANK_A;
  263. uint32_t saveVSYNC_A;
  264. uint32_t saveDSPASTRIDE;
  265. uint32_t saveDSPASIZE;
  266. uint32_t saveDSPAPOS;
  267. uint32_t saveDSPABASE;
  268. uint32_t saveDSPASURF;
  269. uint32_t saveDSPASTATUS;
  270. uint32_t saveFPB0;
  271. uint32_t saveFPB1;
  272. uint32_t saveDPLL_B;
  273. uint32_t saveDPLL_B_MD;
  274. uint32_t saveHTOTAL_B;
  275. uint32_t saveHBLANK_B;
  276. uint32_t saveHSYNC_B;
  277. uint32_t saveVTOTAL_B;
  278. uint32_t saveVBLANK_B;
  279. uint32_t saveVSYNC_B;
  280. uint32_t saveDSPBSTRIDE;
  281. uint32_t saveDSPBSIZE;
  282. uint32_t saveDSPBPOS;
  283. uint32_t saveDSPBBASE;
  284. uint32_t saveDSPBSURF;
  285. uint32_t saveDSPBSTATUS;
  286. uint32_t saveVCLK_DIVISOR_VGA0;
  287. uint32_t saveVCLK_DIVISOR_VGA1;
  288. uint32_t saveVCLK_POST_DIV;
  289. uint32_t saveVGACNTRL;
  290. uint32_t saveADPA;
  291. uint32_t saveLVDS;
  292. uint32_t saveDVOA;
  293. uint32_t saveDVOB;
  294. uint32_t saveDVOC;
  295. uint32_t savePP_ON;
  296. uint32_t savePP_OFF;
  297. uint32_t savePP_CONTROL;
  298. uint32_t savePP_CYCLE;
  299. uint32_t savePFIT_CONTROL;
  300. uint32_t savePaletteA[256];
  301. uint32_t savePaletteB[256];
  302. uint32_t saveCLOCKGATING;
  303. uint32_t saveDSPARB;
  304. uint32_t saveDSPATILEOFF;
  305. uint32_t saveDSPBTILEOFF;
  306. uint32_t saveDSPAADDR;
  307. uint32_t saveDSPBADDR;
  308. uint32_t savePFIT_AUTO_RATIOS;
  309. uint32_t savePFIT_PGM_RATIOS;
  310. uint32_t savePP_ON_DELAYS;
  311. uint32_t savePP_OFF_DELAYS;
  312. uint32_t savePP_DIVISOR;
  313. uint32_t saveBCLRPAT_A;
  314. uint32_t saveBCLRPAT_B;
  315. uint32_t saveDSPALINOFF;
  316. uint32_t saveDSPBLINOFF;
  317. uint32_t savePERF_MODE;
  318. uint32_t saveDSPFW1;
  319. uint32_t saveDSPFW2;
  320. uint32_t saveDSPFW3;
  321. uint32_t saveDSPFW4;
  322. uint32_t saveDSPFW5;
  323. uint32_t saveDSPFW6;
  324. uint32_t saveCHICKENBIT;
  325. uint32_t saveDSPACURSOR_CTRL;
  326. uint32_t saveDSPBCURSOR_CTRL;
  327. uint32_t saveDSPACURSOR_BASE;
  328. uint32_t saveDSPBCURSOR_BASE;
  329. uint32_t saveDSPACURSOR_POS;
  330. uint32_t saveDSPBCURSOR_POS;
  331. uint32_t save_palette_a[256];
  332. uint32_t save_palette_b[256];
  333. uint32_t saveOV_OVADD;
  334. uint32_t saveOV_OGAMC0;
  335. uint32_t saveOV_OGAMC1;
  336. uint32_t saveOV_OGAMC2;
  337. uint32_t saveOV_OGAMC3;
  338. uint32_t saveOV_OGAMC4;
  339. uint32_t saveOV_OGAMC5;
  340. uint32_t saveOVC_OVADD;
  341. uint32_t saveOVC_OGAMC0;
  342. uint32_t saveOVC_OGAMC1;
  343. uint32_t saveOVC_OGAMC2;
  344. uint32_t saveOVC_OGAMC3;
  345. uint32_t saveOVC_OGAMC4;
  346. uint32_t saveOVC_OGAMC5;
  347. /* DPST register save */
  348. uint32_t saveHISTOGRAM_INT_CONTROL_REG;
  349. uint32_t saveHISTOGRAM_LOGIC_CONTROL_REG;
  350. uint32_t savePWM_CONTROL_LOGIC;
  351. };
  352. struct medfield_state {
  353. uint32_t saveDPLL_A;
  354. uint32_t saveFPA0;
  355. uint32_t savePIPEACONF;
  356. uint32_t saveHTOTAL_A;
  357. uint32_t saveHBLANK_A;
  358. uint32_t saveHSYNC_A;
  359. uint32_t saveVTOTAL_A;
  360. uint32_t saveVBLANK_A;
  361. uint32_t saveVSYNC_A;
  362. uint32_t savePIPEASRC;
  363. uint32_t saveDSPASTRIDE;
  364. uint32_t saveDSPALINOFF;
  365. uint32_t saveDSPATILEOFF;
  366. uint32_t saveDSPASIZE;
  367. uint32_t saveDSPAPOS;
  368. uint32_t saveDSPASURF;
  369. uint32_t saveDSPACNTR;
  370. uint32_t saveDSPASTATUS;
  371. uint32_t save_palette_a[256];
  372. uint32_t saveMIPI;
  373. uint32_t saveDPLL_B;
  374. uint32_t saveFPB0;
  375. uint32_t savePIPEBCONF;
  376. uint32_t saveHTOTAL_B;
  377. uint32_t saveHBLANK_B;
  378. uint32_t saveHSYNC_B;
  379. uint32_t saveVTOTAL_B;
  380. uint32_t saveVBLANK_B;
  381. uint32_t saveVSYNC_B;
  382. uint32_t savePIPEBSRC;
  383. uint32_t saveDSPBSTRIDE;
  384. uint32_t saveDSPBLINOFF;
  385. uint32_t saveDSPBTILEOFF;
  386. uint32_t saveDSPBSIZE;
  387. uint32_t saveDSPBPOS;
  388. uint32_t saveDSPBSURF;
  389. uint32_t saveDSPBCNTR;
  390. uint32_t saveDSPBSTATUS;
  391. uint32_t save_palette_b[256];
  392. uint32_t savePIPECCONF;
  393. uint32_t saveHTOTAL_C;
  394. uint32_t saveHBLANK_C;
  395. uint32_t saveHSYNC_C;
  396. uint32_t saveVTOTAL_C;
  397. uint32_t saveVBLANK_C;
  398. uint32_t saveVSYNC_C;
  399. uint32_t savePIPECSRC;
  400. uint32_t saveDSPCSTRIDE;
  401. uint32_t saveDSPCLINOFF;
  402. uint32_t saveDSPCTILEOFF;
  403. uint32_t saveDSPCSIZE;
  404. uint32_t saveDSPCPOS;
  405. uint32_t saveDSPCSURF;
  406. uint32_t saveDSPCCNTR;
  407. uint32_t saveDSPCSTATUS;
  408. uint32_t save_palette_c[256];
  409. uint32_t saveMIPI_C;
  410. uint32_t savePFIT_CONTROL;
  411. uint32_t savePFIT_PGM_RATIOS;
  412. uint32_t saveHDMIPHYMISCCTL;
  413. uint32_t saveHDMIB_CONTROL;
  414. };
  415. struct cdv_state {
  416. uint32_t saveDSPCLK_GATE_D;
  417. uint32_t saveRAMCLK_GATE_D;
  418. uint32_t saveDSPARB;
  419. uint32_t saveDSPFW[6];
  420. uint32_t saveADPA;
  421. uint32_t savePP_CONTROL;
  422. uint32_t savePFIT_PGM_RATIOS;
  423. uint32_t saveLVDS;
  424. uint32_t savePFIT_CONTROL;
  425. uint32_t savePP_ON_DELAYS;
  426. uint32_t savePP_OFF_DELAYS;
  427. uint32_t savePP_CYCLE;
  428. uint32_t saveVGACNTRL;
  429. uint32_t saveIER;
  430. uint32_t saveIMR;
  431. u8 saveLBB;
  432. };
  433. struct psb_save_area {
  434. uint32_t saveBSM;
  435. uint32_t saveVBT;
  436. union {
  437. struct psb_state psb;
  438. struct medfield_state mdfld;
  439. struct cdv_state cdv;
  440. };
  441. uint32_t saveBLC_PWM_CTL2;
  442. uint32_t saveBLC_PWM_CTL;
  443. };
  444. struct psb_ops;
  445. #define PSB_NUM_PIPE 3
  446. struct drm_psb_private {
  447. struct drm_device *dev;
  448. const struct psb_ops *ops;
  449. struct child_device_config *child_dev;
  450. int child_dev_num;
  451. struct psb_gtt gtt;
  452. /* GTT Memory manager */
  453. struct psb_gtt_mm *gtt_mm;
  454. struct page *scratch_page;
  455. u32 *gtt_map;
  456. uint32_t stolen_base;
  457. void *vram_addr;
  458. unsigned long vram_stolen_size;
  459. int gtt_initialized;
  460. u16 gmch_ctrl; /* Saved GTT setup */
  461. u32 pge_ctl;
  462. struct mutex gtt_mutex;
  463. struct resource *gtt_mem; /* Our PCI resource */
  464. struct psb_mmu_driver *mmu;
  465. struct psb_mmu_pd *pf_pd;
  466. /*
  467. * Register base
  468. */
  469. uint8_t *sgx_reg;
  470. uint8_t *vdc_reg;
  471. uint32_t gatt_free_offset;
  472. /*
  473. * Fencing / irq.
  474. */
  475. uint32_t vdc_irq_mask;
  476. uint32_t pipestat[PSB_NUM_PIPE];
  477. spinlock_t irqmask_lock;
  478. /*
  479. * Power
  480. */
  481. bool suspended;
  482. bool display_power;
  483. int display_count;
  484. /*
  485. * Modesetting
  486. */
  487. struct psb_intel_mode_device mode_dev;
  488. struct drm_crtc *plane_to_crtc_mapping[PSB_NUM_PIPE];
  489. struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE];
  490. uint32_t num_pipe;
  491. /*
  492. * OSPM info (Power management base) (can go ?)
  493. */
  494. uint32_t ospm_base;
  495. /*
  496. * Sizes info
  497. */
  498. u32 fuse_reg_value;
  499. u32 video_device_fuse;
  500. /* PCI revision ID for B0:D2:F0 */
  501. uint8_t platform_rev_id;
  502. /* gmbus */
  503. struct intel_gmbus *gmbus;
  504. /* Used by SDVO */
  505. int crt_ddc_pin;
  506. /* FIXME: The mappings should be parsed from bios but for now we can
  507. pretend there are no mappings available */
  508. struct sdvo_device_mapping sdvo_mappings[2];
  509. u32 hotplug_supported_mask;
  510. struct drm_property *broadcast_rgb_property;
  511. struct drm_property *force_audio_property;
  512. /*
  513. * LVDS info
  514. */
  515. int backlight_duty_cycle; /* restore backlight to this value */
  516. bool panel_wants_dither;
  517. struct drm_display_mode *panel_fixed_mode;
  518. struct drm_display_mode *lfp_lvds_vbt_mode;
  519. struct drm_display_mode *sdvo_lvds_vbt_mode;
  520. struct bdb_lvds_backlight *lvds_bl; /* LVDS backlight info from VBT */
  521. struct psb_intel_i2c_chan *lvds_i2c_bus; /* FIXME: Remove this? */
  522. /* Feature bits from the VBIOS */
  523. unsigned int int_tv_support:1;
  524. unsigned int lvds_dither:1;
  525. unsigned int lvds_vbt:1;
  526. unsigned int int_crt_support:1;
  527. unsigned int lvds_use_ssc:1;
  528. int lvds_ssc_freq;
  529. bool is_lvds_on;
  530. bool is_mipi_on;
  531. u32 mipi_ctrl_display;
  532. unsigned int core_freq;
  533. uint32_t iLVDS_enable;
  534. /* Runtime PM state */
  535. int rpm_enabled;
  536. /* MID specific */
  537. struct oaktrail_vbt vbt_data;
  538. struct oaktrail_gct_data gct_data;
  539. /* Oaktrail HDMI state */
  540. struct oaktrail_hdmi_dev *hdmi_priv;
  541. /*
  542. * Register state
  543. */
  544. struct psb_save_area regs;
  545. /* MSI reg save */
  546. uint32_t msi_addr;
  547. uint32_t msi_data;
  548. /*
  549. * LID-Switch
  550. */
  551. spinlock_t lid_lock;
  552. struct timer_list lid_timer;
  553. struct psb_intel_opregion opregion;
  554. u32 *lid_state;
  555. u32 lid_last_state;
  556. /*
  557. * Watchdog
  558. */
  559. uint32_t apm_reg;
  560. uint16_t apm_base;
  561. /*
  562. * Used for modifying backlight from
  563. * xrandr -- consider removing and using HAL instead
  564. */
  565. struct backlight_device *backlight_device;
  566. struct drm_property *backlight_property;
  567. uint32_t blc_adj1;
  568. uint32_t blc_adj2;
  569. void *fbdev;
  570. /* 2D acceleration */
  571. spinlock_t lock_2d;
  572. /*
  573. * Panel brightness
  574. */
  575. int brightness;
  576. int brightness_adjusted;
  577. bool dsr_enable;
  578. u32 dsr_fb_update;
  579. bool dpi_panel_on[3];
  580. void *dsi_configs[2];
  581. u32 bpp;
  582. u32 bpp2;
  583. u32 pipeconf[3];
  584. u32 dspcntr[3];
  585. int mdfld_panel_id;
  586. bool dplla_96mhz; /* DPLL data from the VBT */
  587. };
  588. /*
  589. * Operations for each board type
  590. */
  591. struct psb_ops {
  592. const char *name;
  593. unsigned int accel_2d:1;
  594. int pipes; /* Number of output pipes */
  595. int crtcs; /* Number of CRTCs */
  596. int sgx_offset; /* Base offset of SGX device */
  597. int hdmi_mask; /* Mask of HDMI CRTCs */
  598. int lvds_mask; /* Mask of LVDS CRTCs */
  599. /* Sub functions */
  600. struct drm_crtc_helper_funcs const *crtc_helper;
  601. struct drm_crtc_funcs const *crtc_funcs;
  602. /* Setup hooks */
  603. int (*chip_setup)(struct drm_device *dev);
  604. void (*chip_teardown)(struct drm_device *dev);
  605. /* Optional helper caller after modeset */
  606. void (*errata)(struct drm_device *dev);
  607. /* Display management hooks */
  608. int (*output_init)(struct drm_device *dev);
  609. /* Power management hooks */
  610. void (*init_pm)(struct drm_device *dev);
  611. int (*save_regs)(struct drm_device *dev);
  612. int (*restore_regs)(struct drm_device *dev);
  613. int (*power_up)(struct drm_device *dev);
  614. int (*power_down)(struct drm_device *dev);
  615. void (*lvds_bl_power)(struct drm_device *dev, bool on);
  616. #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
  617. /* Backlight */
  618. int (*backlight_init)(struct drm_device *dev);
  619. #endif
  620. int i2c_bus; /* I2C bus identifier for Moorestown */
  621. };
  622. struct psb_mmu_driver;
  623. extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int);
  624. extern int drm_pick_crtcs(struct drm_device *dev);
  625. static inline struct drm_psb_private *psb_priv(struct drm_device *dev)
  626. {
  627. return (struct drm_psb_private *) dev->dev_private;
  628. }
  629. /*
  630. * MMU stuff.
  631. */
  632. extern struct psb_mmu_driver *psb_mmu_driver_init(uint8_t __iomem * registers,
  633. int trap_pagefaults,
  634. int invalid_type,
  635. struct drm_psb_private *dev_priv);
  636. extern void psb_mmu_driver_takedown(struct psb_mmu_driver *driver);
  637. extern struct psb_mmu_pd *psb_mmu_get_default_pd(struct psb_mmu_driver
  638. *driver);
  639. extern void psb_mmu_mirror_gtt(struct psb_mmu_pd *pd, uint32_t mmu_offset,
  640. uint32_t gtt_start, uint32_t gtt_pages);
  641. extern struct psb_mmu_pd *psb_mmu_alloc_pd(struct psb_mmu_driver *driver,
  642. int trap_pagefaults,
  643. int invalid_type);
  644. extern void psb_mmu_free_pagedir(struct psb_mmu_pd *pd);
  645. extern void psb_mmu_flush(struct psb_mmu_driver *driver, int rc_prot);
  646. extern void psb_mmu_remove_pfn_sequence(struct psb_mmu_pd *pd,
  647. unsigned long address,
  648. uint32_t num_pages);
  649. extern int psb_mmu_insert_pfn_sequence(struct psb_mmu_pd *pd,
  650. uint32_t start_pfn,
  651. unsigned long address,
  652. uint32_t num_pages, int type);
  653. extern int psb_mmu_virtual_to_pfn(struct psb_mmu_pd *pd, uint32_t virtual,
  654. unsigned long *pfn);
  655. /*
  656. * Enable / disable MMU for different requestors.
  657. */
  658. extern void psb_mmu_set_pd_context(struct psb_mmu_pd *pd, int hw_context);
  659. extern int psb_mmu_insert_pages(struct psb_mmu_pd *pd, struct page **pages,
  660. unsigned long address, uint32_t num_pages,
  661. uint32_t desired_tile_stride,
  662. uint32_t hw_tile_stride, int type);
  663. extern void psb_mmu_remove_pages(struct psb_mmu_pd *pd,
  664. unsigned long address, uint32_t num_pages,
  665. uint32_t desired_tile_stride,
  666. uint32_t hw_tile_stride);
  667. /*
  668. *psb_irq.c
  669. */
  670. extern irqreturn_t psb_irq_handler(DRM_IRQ_ARGS);
  671. extern int psb_irq_enable_dpst(struct drm_device *dev);
  672. extern int psb_irq_disable_dpst(struct drm_device *dev);
  673. extern void psb_irq_preinstall(struct drm_device *dev);
  674. extern int psb_irq_postinstall(struct drm_device *dev);
  675. extern void psb_irq_uninstall(struct drm_device *dev);
  676. extern void psb_irq_turn_on_dpst(struct drm_device *dev);
  677. extern void psb_irq_turn_off_dpst(struct drm_device *dev);
  678. extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands);
  679. extern int psb_vblank_wait2(struct drm_device *dev, unsigned int *sequence);
  680. extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence);
  681. extern int psb_enable_vblank(struct drm_device *dev, int crtc);
  682. extern void psb_disable_vblank(struct drm_device *dev, int crtc);
  683. void
  684. psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
  685. void
  686. psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask);
  687. extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc);
  688. /*
  689. * intel_opregion.c
  690. */
  691. extern int gma_intel_opregion_init(struct drm_device *dev);
  692. extern int gma_intel_opregion_exit(struct drm_device *dev);
  693. /*
  694. * framebuffer.c
  695. */
  696. extern int psbfb_probed(struct drm_device *dev);
  697. extern int psbfb_remove(struct drm_device *dev,
  698. struct drm_framebuffer *fb);
  699. /*
  700. * accel_2d.c
  701. */
  702. extern void psbfb_copyarea(struct fb_info *info,
  703. const struct fb_copyarea *region);
  704. extern int psbfb_sync(struct fb_info *info);
  705. extern void psb_spank(struct drm_psb_private *dev_priv);
  706. /*
  707. * psb_reset.c
  708. */
  709. extern void psb_lid_timer_init(struct drm_psb_private *dev_priv);
  710. extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv);
  711. extern void psb_print_pagefault(struct drm_psb_private *dev_priv);
  712. /* modesetting */
  713. extern void psb_modeset_init(struct drm_device *dev);
  714. extern void psb_modeset_cleanup(struct drm_device *dev);
  715. extern int psb_fbdev_init(struct drm_device *dev);
  716. /* backlight.c */
  717. int gma_backlight_init(struct drm_device *dev);
  718. void gma_backlight_exit(struct drm_device *dev);
  719. /* oaktrail_crtc.c */
  720. extern const struct drm_crtc_helper_funcs oaktrail_helper_funcs;
  721. /* oaktrail_lvds.c */
  722. extern void oaktrail_lvds_init(struct drm_device *dev,
  723. struct psb_intel_mode_device *mode_dev);
  724. /* psb_intel_display.c */
  725. extern const struct drm_crtc_helper_funcs psb_intel_helper_funcs;
  726. extern const struct drm_crtc_funcs psb_intel_crtc_funcs;
  727. /* psb_intel_lvds.c */
  728. extern const struct drm_connector_helper_funcs
  729. psb_intel_lvds_connector_helper_funcs;
  730. extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
  731. /* gem.c */
  732. extern int psb_gem_init_object(struct drm_gem_object *obj);
  733. extern void psb_gem_free_object(struct drm_gem_object *obj);
  734. extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
  735. struct drm_file *file);
  736. extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  737. struct drm_mode_create_dumb *args);
  738. extern int psb_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
  739. uint32_t handle);
  740. extern int psb_gem_dumb_map_gtt(struct drm_file *file, struct drm_device *dev,
  741. uint32_t handle, uint64_t *offset);
  742. extern int psb_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  743. extern int psb_gem_create_ioctl(struct drm_device *dev, void *data,
  744. struct drm_file *file);
  745. extern int psb_gem_mmap_ioctl(struct drm_device *dev, void *data,
  746. struct drm_file *file);
  747. /* psb_device.c */
  748. extern const struct psb_ops psb_chip_ops;
  749. /* oaktrail_device.c */
  750. extern const struct psb_ops oaktrail_chip_ops;
  751. /* mdlfd_device.c */
  752. extern const struct psb_ops mdfld_chip_ops;
  753. /* cdv_device.c */
  754. extern const struct psb_ops cdv_chip_ops;
  755. /*
  756. * Debug print bits setting
  757. */
  758. #define PSB_D_GENERAL (1 << 0)
  759. #define PSB_D_INIT (1 << 1)
  760. #define PSB_D_IRQ (1 << 2)
  761. #define PSB_D_ENTRY (1 << 3)
  762. /* debug the get H/V BP/FP count */
  763. #define PSB_D_HV (1 << 4)
  764. #define PSB_D_DBI_BF (1 << 5)
  765. #define PSB_D_PM (1 << 6)
  766. #define PSB_D_RENDER (1 << 7)
  767. #define PSB_D_REG (1 << 8)
  768. #define PSB_D_MSVDX (1 << 9)
  769. #define PSB_D_TOPAZ (1 << 10)
  770. extern int drm_psb_no_fb;
  771. extern int drm_idle_check_interval;
  772. /*
  773. * Utilities
  774. */
  775. static inline u32 MRST_MSG_READ32(uint port, uint offset)
  776. {
  777. int mcr = (0xD0<<24) | (port << 16) | (offset << 8);
  778. uint32_t ret_val = 0;
  779. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  780. pci_write_config_dword(pci_root, 0xD0, mcr);
  781. pci_read_config_dword(pci_root, 0xD4, &ret_val);
  782. pci_dev_put(pci_root);
  783. return ret_val;
  784. }
  785. static inline void MRST_MSG_WRITE32(uint port, uint offset, u32 value)
  786. {
  787. int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0;
  788. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  789. pci_write_config_dword(pci_root, 0xD4, value);
  790. pci_write_config_dword(pci_root, 0xD0, mcr);
  791. pci_dev_put(pci_root);
  792. }
  793. static inline u32 MDFLD_MSG_READ32(uint port, uint offset)
  794. {
  795. int mcr = (0x10<<24) | (port << 16) | (offset << 8);
  796. uint32_t ret_val = 0;
  797. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  798. pci_write_config_dword(pci_root, 0xD0, mcr);
  799. pci_read_config_dword(pci_root, 0xD4, &ret_val);
  800. pci_dev_put(pci_root);
  801. return ret_val;
  802. }
  803. static inline void MDFLD_MSG_WRITE32(uint port, uint offset, u32 value)
  804. {
  805. int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0;
  806. struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0);
  807. pci_write_config_dword(pci_root, 0xD4, value);
  808. pci_write_config_dword(pci_root, 0xD0, mcr);
  809. pci_dev_put(pci_root);
  810. }
  811. static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg)
  812. {
  813. struct drm_psb_private *dev_priv = dev->dev_private;
  814. return ioread32(dev_priv->vdc_reg + reg);
  815. }
  816. #define REG_READ(reg) REGISTER_READ(dev, (reg))
  817. static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg,
  818. uint32_t val)
  819. {
  820. struct drm_psb_private *dev_priv = dev->dev_private;
  821. iowrite32((val), dev_priv->vdc_reg + (reg));
  822. }
  823. #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val))
  824. static inline void REGISTER_WRITE16(struct drm_device *dev,
  825. uint32_t reg, uint32_t val)
  826. {
  827. struct drm_psb_private *dev_priv = dev->dev_private;
  828. iowrite16((val), dev_priv->vdc_reg + (reg));
  829. }
  830. #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val))
  831. static inline void REGISTER_WRITE8(struct drm_device *dev,
  832. uint32_t reg, uint32_t val)
  833. {
  834. struct drm_psb_private *dev_priv = dev->dev_private;
  835. iowrite8((val), dev_priv->vdc_reg + (reg));
  836. }
  837. #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val))
  838. #define PSB_WVDC32(_val, _offs) iowrite32(_val, dev_priv->vdc_reg + (_offs))
  839. #define PSB_RVDC32(_offs) ioread32(dev_priv->vdc_reg + (_offs))
  840. /* #define TRAP_SGX_PM_FAULT 1 */
  841. #ifdef TRAP_SGX_PM_FAULT
  842. #define PSB_RSGX32(_offs) \
  843. ({ \
  844. if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \
  845. printk(KERN_ERR \
  846. "access sgx when it's off!! (READ) %s, %d\n", \
  847. __FILE__, __LINE__); \
  848. melay(1000); \
  849. } \
  850. ioread32(dev_priv->sgx_reg + (_offs)); \
  851. })
  852. #else
  853. #define PSB_RSGX32(_offs) ioread32(dev_priv->sgx_reg + (_offs))
  854. #endif
  855. #define PSB_WSGX32(_val, _offs) iowrite32(_val, dev_priv->sgx_reg + (_offs))
  856. #define MSVDX_REG_DUMP 0
  857. #define PSB_WMSVDX32(_val, _offs) iowrite32(_val, dev_priv->msvdx_reg + (_offs))
  858. #define PSB_RMSVDX32(_offs) ioread32(dev_priv->msvdx_reg + (_offs))
  859. #endif